1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2016 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 (at
11 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 "composite.h"
296 #include "keyboard.h"
300 #include "termchar.h"
301 #include "dispextern.h"
302 #include "character.h"
306 #include "commands.h"
309 #include "termhooks.h"
310 #include "termopts.h"
311 #include "intervals.h"
313 #include "region-cache.h"
316 #include "blockinput.h"
318 #ifdef HAVE_WINDOW_SYSTEM
320 #endif /* HAVE_WINDOW_SYSTEM */
322 #ifndef FRAME_X_OUTPUT
323 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
326 #define INFINITY 10000000
328 /* Holds the list (error). */
329 static Lisp_Object list_of_error
;
331 #ifdef HAVE_WINDOW_SYSTEM
333 /* Test if overflow newline into fringe. Called with iterator IT
334 at or past right window margin, and with IT->current_x set. */
336 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
337 (!NILP (Voverflow_newline_into_fringe) \
338 && FRAME_WINDOW_P ((IT)->f) \
339 && ((IT)->bidi_it.paragraph_dir == R2L \
340 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
341 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
342 && (IT)->current_x == (IT)->last_visible_x)
344 #else /* !HAVE_WINDOW_SYSTEM */
345 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) false
346 #endif /* HAVE_WINDOW_SYSTEM */
348 /* Test if the display element loaded in IT, or the underlying buffer
349 or string character, is a space or a TAB character. This is used
350 to determine where word wrapping can occur. */
352 #define IT_DISPLAYING_WHITESPACE(it) \
353 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
354 || ((STRINGP (it->string) \
355 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
356 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
358 && (it->s[IT_BYTEPOS (*it)] == ' ' \
359 || it->s[IT_BYTEPOS (*it)] == '\t')) \
360 || (IT_BYTEPOS (*it) < ZV_BYTE \
361 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
362 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
364 /* True means print newline to stdout before next mini-buffer message. */
366 bool noninteractive_need_newline
;
368 /* True means print newline to message log before next message. */
370 static bool message_log_need_newline
;
372 /* Three markers that message_dolog uses.
373 It could allocate them itself, but that causes trouble
374 in handling memory-full errors. */
375 static Lisp_Object message_dolog_marker1
;
376 static Lisp_Object message_dolog_marker2
;
377 static Lisp_Object message_dolog_marker3
;
379 /* The buffer position of the first character appearing entirely or
380 partially on the line of the selected window which contains the
381 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
382 redisplay optimization in redisplay_internal. */
384 static struct text_pos this_line_start_pos
;
386 /* Number of characters past the end of the line above, including the
387 terminating newline. */
389 static struct text_pos this_line_end_pos
;
391 /* The vertical positions and the height of this line. */
393 static int this_line_vpos
;
394 static int this_line_y
;
395 static int this_line_pixel_height
;
397 /* X position at which this display line starts. Usually zero;
398 negative if first character is partially visible. */
400 static int this_line_start_x
;
402 /* The smallest character position seen by move_it_* functions as they
403 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
404 hscrolled lines, see display_line. */
406 static struct text_pos this_line_min_pos
;
408 /* Buffer that this_line_.* variables are referring to. */
410 static struct buffer
*this_line_buffer
;
412 /* True if an overlay arrow has been displayed in this window. */
414 static bool overlay_arrow_seen
;
416 /* Vector containing glyphs for an ellipsis `...'. */
418 static Lisp_Object default_invis_vector
[3];
420 /* This is the window where the echo area message was displayed. It
421 is always a mini-buffer window, but it may not be the same window
422 currently active as a mini-buffer. */
424 Lisp_Object echo_area_window
;
426 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
427 pushes the current message and the value of
428 message_enable_multibyte on the stack, the function restore_message
429 pops the stack and displays MESSAGE again. */
431 static Lisp_Object Vmessage_stack
;
433 /* True means multibyte characters were enabled when the echo area
434 message was specified. */
436 static bool message_enable_multibyte
;
438 /* At each redisplay cycle, we should refresh everything there is to refresh.
439 To do that efficiently, we use many optimizations that try to make sure we
440 don't waste too much time updating things that haven't changed.
441 The coarsest such optimization is that, in the most common cases, we only
442 look at the selected-window.
444 To know whether other windows should be considered for redisplay, we use the
445 variable windows_or_buffers_changed: as long as it is 0, it means that we
446 have not noticed anything that should require updating anything else than
447 the selected-window. If it is set to REDISPLAY_SOME, it means that since
448 last redisplay, some changes have been made which could impact other
449 windows. To know which ones need redisplay, every buffer, window, and frame
450 has a `redisplay' bit, which (if true) means that this object needs to be
451 redisplayed. If windows_or_buffers_changed is 0, we know there's no point
452 looking for those `redisplay' bits (actually, there might be some such bits
453 set, but then only on objects which aren't displayed anyway).
455 OTOH if it's non-zero we wil have to loop through all windows and then check
456 the `redisplay' bit of the corresponding window, frame, and buffer, in order
457 to decide whether that window needs attention or not. Note that we can't
458 just look at the frame's redisplay bit to decide that the whole frame can be
459 skipped, since even if the frame's redisplay bit is unset, some of its
460 windows's redisplay bits may be set.
462 Mostly for historical reasons, windows_or_buffers_changed can also take
463 other non-zero values. In that case, the precise value doesn't matter (it
464 encodes the cause of the setting but is only used for debugging purposes),
465 and what it means is that we shouldn't pay attention to any `redisplay' bits
466 and we should simply try and redisplay every window out there. */
468 int windows_or_buffers_changed
;
470 /* Nonzero if we should redraw the mode lines on the next redisplay.
471 Similarly to `windows_or_buffers_changed', If it has value REDISPLAY_SOME,
472 then only redisplay the mode lines in those buffers/windows/frames where the
473 `redisplay' bit has been set.
474 For any other value, redisplay all mode lines (the number used is then only
475 used to track down the cause for this full-redisplay).
477 Since the frame title uses the same %-constructs as the mode line
478 (except %c and %l), if this variable is non-zero, we also consider
479 redisplaying the title of each frame, see x_consider_frame_title.
481 The `redisplay' bits are the same as those used for
482 windows_or_buffers_changed, and setting windows_or_buffers_changed also
483 causes recomputation of the mode lines of all those windows. IOW this
484 variable only has an effect if windows_or_buffers_changed is zero, in which
485 case we should only need to redisplay the mode-line of those objects with
486 a `redisplay' bit set but not the window's text content (tho we may still
487 need to refresh the text content of the selected-window). */
489 int update_mode_lines
;
491 /* True after display_mode_line if %l was used and it displayed a
494 static bool line_number_displayed
;
496 /* The name of the *Messages* buffer, a string. */
498 static Lisp_Object Vmessages_buffer_name
;
500 /* Current, index 0, and last displayed echo area message. Either
501 buffers from echo_buffers, or nil to indicate no message. */
503 Lisp_Object echo_area_buffer
[2];
505 /* The buffers referenced from echo_area_buffer. */
507 static Lisp_Object echo_buffer
[2];
509 /* A vector saved used in with_area_buffer to reduce consing. */
511 static Lisp_Object Vwith_echo_area_save_vector
;
513 /* True means display_echo_area should display the last echo area
514 message again. Set by redisplay_preserve_echo_area. */
516 static bool display_last_displayed_message_p
;
518 /* True if echo area is being used by print; false if being used by
521 static bool message_buf_print
;
523 /* Set to true in clear_message to make redisplay_internal aware
524 of an emptied echo area. */
526 static bool message_cleared_p
;
528 /* A scratch glyph row with contents used for generating truncation
529 glyphs. Also used in direct_output_for_insert. */
531 #define MAX_SCRATCH_GLYPHS 100
532 static struct glyph_row scratch_glyph_row
;
533 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
535 /* Ascent and height of the last line processed by move_it_to. */
537 static int last_height
;
539 /* True if there's a help-echo in the echo area. */
541 bool help_echo_showing_p
;
543 /* The maximum distance to look ahead for text properties. Values
544 that are too small let us call compute_char_face and similar
545 functions too often which is expensive. Values that are too large
546 let us call compute_char_face and alike too often because we
547 might not be interested in text properties that far away. */
549 #define TEXT_PROP_DISTANCE_LIMIT 100
551 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
552 iterator state and later restore it. This is needed because the
553 bidi iterator on bidi.c keeps a stacked cache of its states, which
554 is really a singleton. When we use scratch iterator objects to
555 move around the buffer, we can cause the bidi cache to be pushed or
556 popped, and therefore we need to restore the cache state when we
557 return to the original iterator. */
558 #define SAVE_IT(ITCOPY, ITORIG, CACHE) \
561 bidi_unshelve_cache (CACHE, true); \
563 CACHE = bidi_shelve_cache (); \
566 #define RESTORE_IT(pITORIG, pITCOPY, CACHE) \
568 if (pITORIG != pITCOPY) \
569 *(pITORIG) = *(pITCOPY); \
570 bidi_unshelve_cache (CACHE, false); \
574 /* Functions to mark elements as needing redisplay. */
575 enum { REDISPLAY_SOME
= 2}; /* Arbitrary choice. */
578 redisplay_other_windows (void)
580 if (!windows_or_buffers_changed
)
581 windows_or_buffers_changed
= REDISPLAY_SOME
;
585 wset_redisplay (struct window
*w
)
587 /* Beware: selected_window can be nil during early stages. */
588 if (!EQ (make_lisp_ptr (w
, Lisp_Vectorlike
), selected_window
))
589 redisplay_other_windows ();
594 fset_redisplay (struct frame
*f
)
596 redisplay_other_windows ();
601 bset_redisplay (struct buffer
*b
)
603 int count
= buffer_window_count (b
);
606 /* ... it's visible in other window than selected, */
607 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
608 redisplay_other_windows ();
609 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
610 so that if we later set windows_or_buffers_changed, this buffer will
612 b
->text
->redisplay
= true;
617 bset_update_mode_line (struct buffer
*b
)
619 if (!update_mode_lines
)
620 update_mode_lines
= REDISPLAY_SOME
;
621 b
->text
->redisplay
= true;
625 maybe_set_redisplay (Lisp_Object symbol
)
627 if (HASH_TABLE_P (Vredisplay__variables
)
628 && hash_lookup (XHASH_TABLE (Vredisplay__variables
), symbol
, NULL
) >= 0)
630 bset_update_mode_line (current_buffer
);
631 current_buffer
->prevent_redisplay_optimizations_p
= true;
637 /* True means print traces of redisplay if compiled with
638 GLYPH_DEBUG defined. */
640 bool trace_redisplay_p
;
642 #endif /* GLYPH_DEBUG */
644 #ifdef DEBUG_TRACE_MOVE
645 /* True means trace with TRACE_MOVE to stderr. */
646 static bool trace_move
;
648 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
650 #define TRACE_MOVE(x) (void) 0
653 /* Buffer being redisplayed -- for redisplay_window_error. */
655 static struct buffer
*displayed_buffer
;
657 /* Value returned from text property handlers (see below). */
662 HANDLED_RECOMPUTE_PROPS
,
663 HANDLED_OVERLAY_STRING_CONSUMED
,
667 /* A description of text properties that redisplay is interested
672 /* The symbol index of the name of the property. */
675 /* A unique index for the property. */
678 /* A handler function called to set up iterator IT from the property
679 at IT's current position. Value is used to steer handle_stop. */
680 enum prop_handled (*handler
) (struct it
*it
);
683 static enum prop_handled
handle_face_prop (struct it
*);
684 static enum prop_handled
handle_invisible_prop (struct it
*);
685 static enum prop_handled
handle_display_prop (struct it
*);
686 static enum prop_handled
handle_composition_prop (struct it
*);
687 static enum prop_handled
handle_overlay_change (struct it
*);
688 static enum prop_handled
handle_fontified_prop (struct it
*);
690 /* Properties handled by iterators. */
692 static struct props it_props
[] =
694 {SYMBOL_INDEX (Qfontified
), FONTIFIED_PROP_IDX
, handle_fontified_prop
},
695 /* Handle `face' before `display' because some sub-properties of
696 `display' need to know the face. */
697 {SYMBOL_INDEX (Qface
), FACE_PROP_IDX
, handle_face_prop
},
698 {SYMBOL_INDEX (Qdisplay
), DISPLAY_PROP_IDX
, handle_display_prop
},
699 {SYMBOL_INDEX (Qinvisible
), INVISIBLE_PROP_IDX
, handle_invisible_prop
},
700 {SYMBOL_INDEX (Qcomposition
), COMPOSITION_PROP_IDX
, handle_composition_prop
},
704 /* Value is the position described by X. If X is a marker, value is
705 the marker_position of X. Otherwise, value is X. */
707 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
709 /* Enumeration returned by some move_it_.* functions internally. */
713 /* Not used. Undefined value. */
716 /* Move ended at the requested buffer position or ZV. */
717 MOVE_POS_MATCH_OR_ZV
,
719 /* Move ended at the requested X pixel position. */
722 /* Move within a line ended at the end of a line that must be
726 /* Move within a line ended at the end of a line that would
727 be displayed truncated. */
730 /* Move within a line ended at a line end. */
734 /* This counter is used to clear the face cache every once in a while
735 in redisplay_internal. It is incremented for each redisplay.
736 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
739 #define CLEAR_FACE_CACHE_COUNT 500
740 static int clear_face_cache_count
;
742 /* Similarly for the image cache. */
744 #ifdef HAVE_WINDOW_SYSTEM
745 #define CLEAR_IMAGE_CACHE_COUNT 101
746 static int clear_image_cache_count
;
748 /* Null glyph slice */
749 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
752 /* True while redisplay_internal is in progress. */
756 /* If a string, XTread_socket generates an event to display that string.
757 (The display is done in read_char.) */
759 Lisp_Object help_echo_string
;
760 Lisp_Object help_echo_window
;
761 Lisp_Object help_echo_object
;
762 ptrdiff_t help_echo_pos
;
764 /* Temporary variable for XTread_socket. */
766 Lisp_Object previous_help_echo_string
;
768 /* Platform-independent portion of hourglass implementation. */
770 #ifdef HAVE_WINDOW_SYSTEM
772 /* True means an hourglass cursor is currently shown. */
773 static bool hourglass_shown_p
;
775 /* If non-null, an asynchronous timer that, when it expires, displays
776 an hourglass cursor on all frames. */
777 static struct atimer
*hourglass_atimer
;
779 #endif /* HAVE_WINDOW_SYSTEM */
781 /* Default number of seconds to wait before displaying an hourglass
783 #define DEFAULT_HOURGLASS_DELAY 1
785 #ifdef HAVE_WINDOW_SYSTEM
787 /* Default pixel width of `thin-space' display method. */
788 #define THIN_SPACE_WIDTH 1
790 #endif /* HAVE_WINDOW_SYSTEM */
792 /* Function prototypes. */
794 static void setup_for_ellipsis (struct it
*, int);
795 static void set_iterator_to_next (struct it
*, bool);
796 static void mark_window_display_accurate_1 (struct window
*, bool);
797 static bool row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
798 static bool cursor_row_p (struct glyph_row
*);
799 static int redisplay_mode_lines (Lisp_Object
, bool);
801 static void handle_line_prefix (struct it
*);
803 static void handle_stop_backwards (struct it
*, ptrdiff_t);
804 static void unwind_with_echo_area_buffer (Lisp_Object
);
805 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
806 static bool current_message_1 (ptrdiff_t, Lisp_Object
);
807 static bool truncate_message_1 (ptrdiff_t, Lisp_Object
);
808 static void set_message (Lisp_Object
);
809 static bool set_message_1 (ptrdiff_t, Lisp_Object
);
810 static bool display_echo_area_1 (ptrdiff_t, Lisp_Object
);
811 static bool resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
812 static void unwind_redisplay (void);
813 static void extend_face_to_end_of_line (struct it
*);
814 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
815 static void push_it (struct it
*, struct text_pos
*);
816 static void iterate_out_of_display_property (struct it
*);
817 static void pop_it (struct it
*);
818 static void redisplay_internal (void);
819 static void echo_area_display (bool);
820 static void redisplay_windows (Lisp_Object
);
821 static void redisplay_window (Lisp_Object
, bool);
822 static Lisp_Object
redisplay_window_error (Lisp_Object
);
823 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
824 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
825 static bool set_cursor_from_row (struct window
*, struct glyph_row
*,
826 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
828 static bool cursor_row_fully_visible_p (struct window
*, bool, bool);
829 static bool update_menu_bar (struct frame
*, bool, bool);
830 static bool try_window_reusing_current_matrix (struct window
*);
831 static int try_window_id (struct window
*);
832 static bool display_line (struct it
*);
833 static int display_mode_lines (struct window
*);
834 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
835 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
,
837 static int store_mode_line_string (const char *, Lisp_Object
, bool, int, int,
839 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
840 static void display_menu_bar (struct window
*);
841 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
843 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
844 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
845 static void compute_line_metrics (struct it
*);
846 static void run_redisplay_end_trigger_hook (struct it
*);
847 static bool get_overlay_strings (struct it
*, ptrdiff_t);
848 static bool get_overlay_strings_1 (struct it
*, ptrdiff_t, bool);
849 static void next_overlay_string (struct it
*);
850 static void reseat (struct it
*, struct text_pos
, bool);
851 static void reseat_1 (struct it
*, struct text_pos
, bool);
852 static bool next_element_from_display_vector (struct it
*);
853 static bool next_element_from_string (struct it
*);
854 static bool next_element_from_c_string (struct it
*);
855 static bool next_element_from_buffer (struct it
*);
856 static bool next_element_from_composition (struct it
*);
857 static bool next_element_from_image (struct it
*);
858 static bool next_element_from_stretch (struct it
*);
859 static bool next_element_from_xwidget (struct it
*);
860 static void load_overlay_strings (struct it
*, ptrdiff_t);
861 static bool get_next_display_element (struct it
*);
862 static enum move_it_result
863 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
864 enum move_operation_enum
);
865 static void get_visually_first_element (struct it
*);
866 static void compute_stop_pos (struct it
*);
867 static int face_before_or_after_it_pos (struct it
*, bool);
868 static ptrdiff_t next_overlay_change (ptrdiff_t);
869 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
870 Lisp_Object
, struct text_pos
*, ptrdiff_t, bool);
871 static int handle_single_display_spec (struct it
*, Lisp_Object
,
872 Lisp_Object
, Lisp_Object
,
873 struct text_pos
*, ptrdiff_t, int, bool);
874 static int underlying_face_id (struct it
*);
876 #define face_before_it_pos(IT) face_before_or_after_it_pos (IT, true)
877 #define face_after_it_pos(IT) face_before_or_after_it_pos (IT, false)
879 #ifdef HAVE_WINDOW_SYSTEM
881 static void update_tool_bar (struct frame
*, bool);
882 static void x_draw_bottom_divider (struct window
*w
);
883 static void notice_overwritten_cursor (struct window
*,
886 static int normal_char_height (struct font
*, int);
887 static void normal_char_ascent_descent (struct font
*, int, int *, int *);
889 static void append_stretch_glyph (struct it
*, Lisp_Object
,
892 static Lisp_Object
get_it_property (struct it
*, Lisp_Object
);
893 static Lisp_Object
calc_line_height_property (struct it
*, Lisp_Object
,
894 struct font
*, int, bool);
896 #endif /* HAVE_WINDOW_SYSTEM */
898 static void produce_special_glyphs (struct it
*, enum display_element_type
);
899 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
900 static bool coords_in_mouse_face_p (struct window
*, int, int);
904 /***********************************************************************
905 Window display dimensions
906 ***********************************************************************/
908 /* Return the bottom boundary y-position for text lines in window W.
909 This is the first y position at which a line cannot start.
910 It is relative to the top of the window.
912 This is the height of W minus the height of a mode line, if any. */
915 window_text_bottom_y (struct window
*w
)
917 int height
= WINDOW_PIXEL_HEIGHT (w
);
919 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
921 if (WINDOW_WANTS_MODELINE_P (w
))
922 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
924 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
929 /* Return the pixel width of display area AREA of window W.
930 ANY_AREA means return the total width of W, not including
931 fringes to the left and right of the window. */
934 window_box_width (struct window
*w
, enum glyph_row_area area
)
936 int width
= w
->pixel_width
;
938 if (!w
->pseudo_window_p
)
940 width
-= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
941 width
-= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
943 if (area
== TEXT_AREA
)
944 width
-= (WINDOW_MARGINS_WIDTH (w
)
945 + WINDOW_FRINGES_WIDTH (w
));
946 else if (area
== LEFT_MARGIN_AREA
)
947 width
= WINDOW_LEFT_MARGIN_WIDTH (w
);
948 else if (area
== RIGHT_MARGIN_AREA
)
949 width
= WINDOW_RIGHT_MARGIN_WIDTH (w
);
952 /* With wide margins, fringes, etc. we might end up with a negative
953 width, correct that here. */
954 return max (0, width
);
958 /* Return the pixel height of the display area of window W, not
959 including mode lines of W, if any. */
962 window_box_height (struct window
*w
)
964 struct frame
*f
= XFRAME (w
->frame
);
965 int height
= WINDOW_PIXEL_HEIGHT (w
);
967 eassert (height
>= 0);
969 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
970 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
972 /* Note: the code below that determines the mode-line/header-line
973 height is essentially the same as that contained in the macro
974 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
975 the appropriate glyph row has its `mode_line_p' flag set,
976 and if it doesn't, uses estimate_mode_line_height instead. */
978 if (WINDOW_WANTS_MODELINE_P (w
))
980 struct glyph_row
*ml_row
981 = (w
->current_matrix
&& w
->current_matrix
->rows
982 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
984 if (ml_row
&& ml_row
->mode_line_p
)
985 height
-= ml_row
->height
;
987 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
990 if (WINDOW_WANTS_HEADER_LINE_P (w
))
992 struct glyph_row
*hl_row
993 = (w
->current_matrix
&& w
->current_matrix
->rows
994 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
996 if (hl_row
&& hl_row
->mode_line_p
)
997 height
-= hl_row
->height
;
999 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1002 /* With a very small font and a mode-line that's taller than
1003 default, we might end up with a negative height. */
1004 return max (0, height
);
1007 /* Return the window-relative coordinate of the left edge of display
1008 area AREA of window W. ANY_AREA means return the left edge of the
1009 whole window, to the right of the left fringe of W. */
1012 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1016 if (w
->pseudo_window_p
)
1019 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1021 if (area
== TEXT_AREA
)
1022 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1023 + window_box_width (w
, LEFT_MARGIN_AREA
));
1024 else if (area
== RIGHT_MARGIN_AREA
)
1025 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1026 + window_box_width (w
, LEFT_MARGIN_AREA
)
1027 + window_box_width (w
, TEXT_AREA
)
1028 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1030 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1031 else if (area
== LEFT_MARGIN_AREA
1032 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1033 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1035 /* Don't return more than the window's pixel width. */
1036 return min (x
, w
->pixel_width
);
1040 /* Return the window-relative coordinate of the right edge of display
1041 area AREA of window W. ANY_AREA means return the right edge of the
1042 whole window, to the left of the right fringe of W. */
1045 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1047 /* Don't return more than the window's pixel width. */
1048 return min (window_box_left_offset (w
, area
) + window_box_width (w
, area
),
1052 /* Return the frame-relative coordinate of the left edge of display
1053 area AREA of window W. ANY_AREA means return the left edge of the
1054 whole window, to the right of the left fringe of W. */
1057 window_box_left (struct window
*w
, enum glyph_row_area area
)
1059 struct frame
*f
= XFRAME (w
->frame
);
1062 if (w
->pseudo_window_p
)
1063 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1065 x
= (WINDOW_LEFT_EDGE_X (w
)
1066 + window_box_left_offset (w
, area
));
1072 /* Return the frame-relative coordinate of the right edge of display
1073 area AREA of window W. ANY_AREA means return the right edge of the
1074 whole window, to the left of the right fringe of W. */
1077 window_box_right (struct window
*w
, enum glyph_row_area area
)
1079 return window_box_left (w
, area
) + window_box_width (w
, area
);
1082 /* Get the bounding box of the display area AREA of window W, without
1083 mode lines, in frame-relative coordinates. ANY_AREA means the
1084 whole window, not including the left and right fringes of
1085 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1086 coordinates of the upper-left corner of the box. Return in
1087 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1090 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1091 int *box_y
, int *box_width
, int *box_height
)
1094 *box_width
= window_box_width (w
, area
);
1096 *box_height
= window_box_height (w
);
1098 *box_x
= window_box_left (w
, area
);
1101 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1102 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1103 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1107 #ifdef HAVE_WINDOW_SYSTEM
1109 /* Get the bounding box of the display area AREA of window W, without
1110 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1111 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1112 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1113 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1117 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1118 int *bottom_right_x
, int *bottom_right_y
)
1120 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1121 bottom_right_x
, bottom_right_y
);
1122 *bottom_right_x
+= *top_left_x
;
1123 *bottom_right_y
+= *top_left_y
;
1126 #endif /* HAVE_WINDOW_SYSTEM */
1128 /***********************************************************************
1130 ***********************************************************************/
1132 /* Return the bottom y-position of the line the iterator IT is in.
1133 This can modify IT's settings. */
1136 line_bottom_y (struct it
*it
)
1138 int line_height
= it
->max_ascent
+ it
->max_descent
;
1139 int line_top_y
= it
->current_y
;
1141 if (line_height
== 0)
1144 line_height
= last_height
;
1145 else if (IT_CHARPOS (*it
) < ZV
)
1147 move_it_by_lines (it
, 1);
1148 line_height
= (it
->max_ascent
|| it
->max_descent
1149 ? it
->max_ascent
+ it
->max_descent
1154 struct glyph_row
*row
= it
->glyph_row
;
1156 /* Use the default character height. */
1157 it
->glyph_row
= NULL
;
1158 it
->what
= IT_CHARACTER
;
1161 PRODUCE_GLYPHS (it
);
1162 line_height
= it
->ascent
+ it
->descent
;
1163 it
->glyph_row
= row
;
1167 return line_top_y
+ line_height
;
1170 DEFUN ("line-pixel-height", Fline_pixel_height
,
1171 Sline_pixel_height
, 0, 0, 0,
1172 doc
: /* Return height in pixels of text line in the selected window.
1174 Value is the height in pixels of the line at point. */)
1179 struct window
*w
= XWINDOW (selected_window
);
1180 struct buffer
*old_buffer
= NULL
;
1183 if (XBUFFER (w
->contents
) != current_buffer
)
1185 old_buffer
= current_buffer
;
1186 set_buffer_internal_1 (XBUFFER (w
->contents
));
1188 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1189 start_display (&it
, w
, pt
);
1190 it
.vpos
= it
.current_y
= 0;
1192 result
= make_number (line_bottom_y (&it
));
1194 set_buffer_internal_1 (old_buffer
);
1199 /* Return the default pixel height of text lines in window W. The
1200 value is the canonical height of the W frame's default font, plus
1201 any extra space required by the line-spacing variable or frame
1204 Implementation note: this ignores any line-spacing text properties
1205 put on the newline characters. This is because those properties
1206 only affect the _screen_ line ending in the newline (i.e., in a
1207 continued line, only the last screen line will be affected), which
1208 means only a small number of lines in a buffer can ever use this
1209 feature. Since this function is used to compute the default pixel
1210 equivalent of text lines in a window, we can safely ignore those
1211 few lines. For the same reasons, we ignore the line-height
1214 default_line_pixel_height (struct window
*w
)
1216 struct frame
*f
= WINDOW_XFRAME (w
);
1217 int height
= FRAME_LINE_HEIGHT (f
);
1219 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1221 struct buffer
*b
= XBUFFER (w
->contents
);
1222 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1225 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1228 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1229 height
+= XFASTINT (val
);
1230 else if (FLOATP (val
))
1232 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1239 height
+= f
->extra_line_spacing
;
1245 /* Subroutine of pos_visible_p below. Extracts a display string, if
1246 any, from the display spec given as its argument. */
1248 string_from_display_spec (Lisp_Object spec
)
1252 while (CONSP (spec
))
1254 if (STRINGP (XCAR (spec
)))
1259 else if (VECTORP (spec
))
1263 for (i
= 0; i
< ASIZE (spec
); i
++)
1265 if (STRINGP (AREF (spec
, i
)))
1266 return AREF (spec
, i
);
1275 /* Limit insanely large values of W->hscroll on frame F to the largest
1276 value that will still prevent first_visible_x and last_visible_x of
1277 'struct it' from overflowing an int. */
1279 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1281 ptrdiff_t window_hscroll
= w
->hscroll
;
1282 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1283 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1285 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1286 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1288 return window_hscroll
;
1291 /* Return true if position CHARPOS is visible in window W.
1292 CHARPOS < 0 means return info about WINDOW_END position.
1293 If visible, set *X and *Y to pixel coordinates of top left corner.
1294 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1295 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1298 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1299 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1302 void *itdata
= bidi_shelve_cache ();
1303 struct text_pos top
;
1304 bool visible_p
= false;
1305 struct buffer
*old_buffer
= NULL
;
1308 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1311 if (XBUFFER (w
->contents
) != current_buffer
)
1313 old_buffer
= current_buffer
;
1314 set_buffer_internal_1 (XBUFFER (w
->contents
));
1317 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1318 /* Scrolling a minibuffer window via scroll bar when the echo area
1319 shows long text sometimes resets the minibuffer contents behind
1321 if (CHARPOS (top
) > ZV
)
1322 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1324 /* If the top of the window is after CHARPOS, the latter is surely
1326 if (charpos
>= 0 && CHARPOS (top
) > charpos
)
1329 /* Compute exact mode line heights. */
1330 if (WINDOW_WANTS_MODELINE_P (w
))
1332 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1333 BVAR (current_buffer
, mode_line_format
));
1335 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1336 w
->header_line_height
1337 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1338 BVAR (current_buffer
, header_line_format
));
1340 start_display (&it
, w
, top
);
1341 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1342 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1345 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
!= -1)
1346 && IT_CHARPOS (it
) >= charpos
)
1347 /* When scanning backwards under bidi iteration, move_it_to
1348 stops at or _before_ CHARPOS, because it stops at or to
1349 the _right_ of the character at CHARPOS. */
1350 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1351 && IT_CHARPOS (it
) <= charpos
)))
1353 /* We have reached CHARPOS, or passed it. How the call to
1354 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1355 or covered by a display property, move_it_to stops at the end
1356 of the invisible text, to the right of CHARPOS. (ii) If
1357 CHARPOS is in a display vector, move_it_to stops on its last
1359 int top_x
= it
.current_x
;
1360 int top_y
= it
.current_y
;
1361 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1364 void *save_it_data
= NULL
;
1366 /* Calling line_bottom_y may change it.method, it.position, etc. */
1367 SAVE_IT (save_it
, it
, save_it_data
);
1369 bottom_y
= line_bottom_y (&it
);
1370 if (top_y
< window_top_y
)
1371 visible_p
= bottom_y
> window_top_y
;
1372 else if (top_y
< it
.last_visible_y
)
1374 if (bottom_y
>= it
.last_visible_y
1375 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1376 && IT_CHARPOS (it
) < charpos
)
1378 /* When the last line of the window is scanned backwards
1379 under bidi iteration, we could be duped into thinking
1380 that we have passed CHARPOS, when in fact move_it_to
1381 simply stopped short of CHARPOS because it reached
1382 last_visible_y. To see if that's what happened, we call
1383 move_it_to again with a slightly larger vertical limit,
1384 and see if it actually moved vertically; if it did, we
1385 didn't really reach CHARPOS, which is beyond window end. */
1386 /* Why 10? because we don't know how many canonical lines
1387 will the height of the next line(s) be. So we guess. */
1388 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1390 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1391 MOVE_TO_POS
| MOVE_TO_Y
);
1392 if (it
.current_y
> top_y
)
1396 RESTORE_IT (&it
, &save_it
, save_it_data
);
1399 if (it
.method
== GET_FROM_DISPLAY_VECTOR
)
1401 /* We stopped on the last glyph of a display vector.
1402 Try and recompute. Hack alert! */
1403 if (charpos
< 2 || top
.charpos
>= charpos
)
1404 top_x
= it
.glyph_row
->x
;
1407 struct it it2
, it2_prev
;
1408 /* The idea is to get to the previous buffer
1409 position, consume the character there, and use
1410 the pixel coordinates we get after that. But if
1411 the previous buffer position is also displayed
1412 from a display vector, we need to consume all of
1413 the glyphs from that display vector. */
1414 start_display (&it2
, w
, top
);
1415 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1416 /* If we didn't get to CHARPOS - 1, there's some
1417 replacing display property at that position, and
1418 we stopped after it. That is exactly the place
1419 whose coordinates we want. */
1420 if (IT_CHARPOS (it2
) != charpos
- 1)
1424 /* Iterate until we get out of the display
1425 vector that displays the character at
1428 get_next_display_element (&it2
);
1429 PRODUCE_GLYPHS (&it2
);
1431 set_iterator_to_next (&it2
, true);
1432 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1433 && IT_CHARPOS (it2
) < charpos
);
1435 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1436 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1437 top_x
= it
.glyph_row
->x
;
1440 top_x
= it2_prev
.current_x
;
1441 top_y
= it2_prev
.current_y
;
1445 else if (IT_CHARPOS (it
) != charpos
)
1447 Lisp_Object cpos
= make_number (charpos
);
1448 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1449 Lisp_Object string
= string_from_display_spec (spec
);
1450 struct text_pos tpos
;
1451 bool newline_in_string
1453 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1455 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1456 bool replacing_spec_p
1458 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1459 charpos
, FRAME_WINDOW_P (it
.f
)));
1460 /* The tricky code below is needed because there's a
1461 discrepancy between move_it_to and how we set cursor
1462 when PT is at the beginning of a portion of text
1463 covered by a display property or an overlay with a
1464 display property, or the display line ends in a
1465 newline from a display string. move_it_to will stop
1466 _after_ such display strings, whereas
1467 set_cursor_from_row conspires with cursor_row_p to
1468 place the cursor on the first glyph produced from the
1471 /* We have overshoot PT because it is covered by a
1472 display property that replaces the text it covers.
1473 If the string includes embedded newlines, we are also
1474 in the wrong display line. Backtrack to the correct
1475 line, where the display property begins. */
1476 if (replacing_spec_p
)
1478 Lisp_Object startpos
, endpos
;
1479 EMACS_INT start
, end
;
1482 /* Find the first and the last buffer positions
1483 covered by the display string. */
1485 Fnext_single_char_property_change (cpos
, Qdisplay
,
1488 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1490 start
= XFASTINT (startpos
);
1491 end
= XFASTINT (endpos
);
1492 /* Move to the last buffer position before the
1493 display property. */
1494 start_display (&it3
, w
, top
);
1495 if (start
> CHARPOS (top
))
1496 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1497 /* Move forward one more line if the position before
1498 the display string is a newline or if it is the
1499 rightmost character on a line that is
1500 continued or word-wrapped. */
1501 if (it3
.method
== GET_FROM_BUFFER
1503 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1504 move_it_by_lines (&it3
, 1);
1505 else if (move_it_in_display_line_to (&it3
, -1,
1509 == MOVE_LINE_CONTINUED
)
1511 move_it_by_lines (&it3
, 1);
1512 /* When we are under word-wrap, the #$@%!
1513 move_it_by_lines moves 2 lines, so we need to
1515 if (it3
.line_wrap
== WORD_WRAP
)
1516 move_it_by_lines (&it3
, -1);
1519 /* Record the vertical coordinate of the display
1520 line where we wound up. */
1521 top_y
= it3
.current_y
;
1524 /* When characters are reordered for display,
1525 the character displayed to the left of the
1526 display string could be _after_ the display
1527 property in the logical order. Use the
1528 smallest vertical position of these two. */
1529 start_display (&it3
, w
, top
);
1530 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1531 if (it3
.current_y
< top_y
)
1532 top_y
= it3
.current_y
;
1534 /* Move from the top of the window to the beginning
1535 of the display line where the display string
1537 start_display (&it3
, w
, top
);
1538 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1539 /* If it3_moved stays false after the 'while' loop
1540 below, that means we already were at a newline
1541 before the loop (e.g., the display string begins
1542 with a newline), so we don't need to (and cannot)
1543 inspect the glyphs of it3.glyph_row, because
1544 PRODUCE_GLYPHS will not produce anything for a
1545 newline, and thus it3.glyph_row stays at its
1546 stale content it got at top of the window. */
1547 bool it3_moved
= false;
1548 /* Finally, advance the iterator until we hit the
1549 first display element whose character position is
1550 CHARPOS, or until the first newline from the
1551 display string, which signals the end of the
1553 while (get_next_display_element (&it3
))
1555 PRODUCE_GLYPHS (&it3
);
1556 if (IT_CHARPOS (it3
) == charpos
1557 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1560 set_iterator_to_next (&it3
, false);
1562 top_x
= it3
.current_x
- it3
.pixel_width
;
1563 /* Normally, we would exit the above loop because we
1564 found the display element whose character
1565 position is CHARPOS. For the contingency that we
1566 didn't, and stopped at the first newline from the
1567 display string, move back over the glyphs
1568 produced from the string, until we find the
1569 rightmost glyph not from the string. */
1571 && newline_in_string
1572 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1574 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1575 + it3
.glyph_row
->used
[TEXT_AREA
];
1577 while (EQ ((g
- 1)->object
, string
))
1580 top_x
-= g
->pixel_width
;
1582 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1583 + it3
.glyph_row
->used
[TEXT_AREA
]);
1589 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1590 *rtop
= max (0, window_top_y
- top_y
);
1591 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1592 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1593 - max (top_y
, window_top_y
)));
1595 if (it
.bidi_it
.paragraph_dir
== R2L
)
1601 /* Either we were asked to provide info about WINDOW_END, or
1602 CHARPOS is in the partially visible glyph row at end of
1605 void *it2data
= NULL
;
1607 SAVE_IT (it2
, it
, it2data
);
1608 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1609 move_it_by_lines (&it
, 1);
1610 if (charpos
< IT_CHARPOS (it
)
1611 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1614 RESTORE_IT (&it2
, &it2
, it2data
);
1615 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1617 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1618 *rtop
= max (0, -it2
.current_y
);
1619 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1620 - it
.last_visible_y
));
1621 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1623 - max (it2
.current_y
,
1624 WINDOW_HEADER_LINE_HEIGHT (w
))));
1626 if (it2
.bidi_it
.paragraph_dir
== R2L
)
1630 bidi_unshelve_cache (it2data
, true);
1632 bidi_unshelve_cache (itdata
, false);
1635 set_buffer_internal_1 (old_buffer
);
1641 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1642 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1643 /* For lines in an R2L paragraph, we need to mirror the X pixel
1644 coordinate wrt the text area. For the reasons, see the
1645 commentary in buffer_posn_from_coords and the explanation of
1646 the geometry used by the move_it_* functions at the end of
1647 the large commentary near the beginning of this file. */
1649 *x
= window_box_width (w
, TEXT_AREA
) - *x
- 1;
1653 /* Debugging code. */
1655 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1656 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1658 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1665 /* Return the next character from STR. Return in *LEN the length of
1666 the character. This is like STRING_CHAR_AND_LENGTH but never
1667 returns an invalid character. If we find one, we return a `?', but
1668 with the length of the invalid character. */
1671 string_char_and_length (const unsigned char *str
, int *len
)
1675 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1676 if (!CHAR_VALID_P (c
))
1677 /* We may not change the length here because other places in Emacs
1678 don't use this function, i.e. they silently accept invalid
1687 /* Given a position POS containing a valid character and byte position
1688 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1690 static struct text_pos
1691 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1693 eassert (STRINGP (string
) && nchars
>= 0);
1695 if (STRING_MULTIBYTE (string
))
1697 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1702 string_char_and_length (p
, &len
);
1705 BYTEPOS (pos
) += len
;
1709 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1715 /* Value is the text position, i.e. character and byte position,
1716 for character position CHARPOS in STRING. */
1718 static struct text_pos
1719 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1721 struct text_pos pos
;
1722 eassert (STRINGP (string
));
1723 eassert (charpos
>= 0);
1724 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1729 /* Value is a text position, i.e. character and byte position, for
1730 character position CHARPOS in C string S. MULTIBYTE_P
1731 means recognize multibyte characters. */
1733 static struct text_pos
1734 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1736 struct text_pos pos
;
1738 eassert (s
!= NULL
);
1739 eassert (charpos
>= 0);
1745 SET_TEXT_POS (pos
, 0, 0);
1748 string_char_and_length ((const unsigned char *) s
, &len
);
1751 BYTEPOS (pos
) += len
;
1755 SET_TEXT_POS (pos
, charpos
, charpos
);
1761 /* Value is the number of characters in C string S. MULTIBYTE_P
1762 means recognize multibyte characters. */
1765 number_of_chars (const char *s
, bool multibyte_p
)
1771 ptrdiff_t rest
= strlen (s
);
1773 const unsigned char *p
= (const unsigned char *) s
;
1775 for (nchars
= 0; rest
> 0; ++nchars
)
1777 string_char_and_length (p
, &len
);
1778 rest
-= len
, p
+= len
;
1782 nchars
= strlen (s
);
1788 /* Compute byte position NEWPOS->bytepos corresponding to
1789 NEWPOS->charpos. POS is a known position in string STRING.
1790 NEWPOS->charpos must be >= POS.charpos. */
1793 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1795 eassert (STRINGP (string
));
1796 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1798 if (STRING_MULTIBYTE (string
))
1799 *newpos
= string_pos_nchars_ahead (pos
, string
,
1800 CHARPOS (*newpos
) - CHARPOS (pos
));
1802 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1806 Return an estimation of the pixel height of mode or header lines on
1807 frame F. FACE_ID specifies what line's height to estimate. */
1810 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1812 #ifdef HAVE_WINDOW_SYSTEM
1813 if (FRAME_WINDOW_P (f
))
1815 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1817 /* This function is called so early when Emacs starts that the face
1818 cache and mode line face are not yet initialized. */
1819 if (FRAME_FACE_CACHE (f
))
1821 struct face
*face
= FACE_FROM_ID_OR_NULL (f
, face_id
);
1825 height
= normal_char_height (face
->font
, -1);
1826 if (face
->box_line_width
> 0)
1827 height
+= 2 * face
->box_line_width
;
1838 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1839 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1840 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP, do
1841 not force the value into range. */
1844 pixel_to_glyph_coords (struct frame
*f
, int pix_x
, int pix_y
, int *x
, int *y
,
1845 NativeRectangle
*bounds
, bool noclip
)
1848 #ifdef HAVE_WINDOW_SYSTEM
1849 if (FRAME_WINDOW_P (f
))
1851 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1852 even for negative values. */
1854 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1856 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1858 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1859 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1862 STORE_NATIVE_RECT (*bounds
,
1863 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1864 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1865 FRAME_COLUMN_WIDTH (f
) - 1,
1866 FRAME_LINE_HEIGHT (f
) - 1);
1868 /* PXW: Should we clip pixels before converting to columns/lines? */
1873 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1874 pix_x
= FRAME_TOTAL_COLS (f
);
1878 else if (pix_y
> FRAME_TOTAL_LINES (f
))
1879 pix_y
= FRAME_TOTAL_LINES (f
);
1889 /* Find the glyph under window-relative coordinates X/Y in window W.
1890 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1891 strings. Return in *HPOS and *VPOS the row and column number of
1892 the glyph found. Return in *AREA the glyph area containing X.
1893 Value is a pointer to the glyph found or null if X/Y is not on
1894 text, or we can't tell because W's current matrix is not up to
1897 static struct glyph
*
1898 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1899 int *dx
, int *dy
, int *area
)
1901 struct glyph
*glyph
, *end
;
1902 struct glyph_row
*row
= NULL
;
1905 /* Find row containing Y. Give up if some row is not enabled. */
1906 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1908 row
= MATRIX_ROW (w
->current_matrix
, i
);
1909 if (!row
->enabled_p
)
1911 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1918 /* Give up if Y is not in the window. */
1919 if (i
== w
->current_matrix
->nrows
)
1922 /* Get the glyph area containing X. */
1923 if (w
->pseudo_window_p
)
1930 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1932 *area
= LEFT_MARGIN_AREA
;
1933 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1935 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1938 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1942 *area
= RIGHT_MARGIN_AREA
;
1943 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1947 /* Find glyph containing X. */
1948 glyph
= row
->glyphs
[*area
];
1949 end
= glyph
+ row
->used
[*area
];
1951 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1953 x
-= glyph
->pixel_width
;
1963 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1966 *hpos
= glyph
- row
->glyphs
[*area
];
1970 /* Convert frame-relative x/y to coordinates relative to window W.
1971 Takes pseudo-windows into account. */
1974 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1976 if (w
->pseudo_window_p
)
1978 /* A pseudo-window is always full-width, and starts at the
1979 left edge of the frame, plus a frame border. */
1980 struct frame
*f
= XFRAME (w
->frame
);
1981 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1982 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1986 *x
-= WINDOW_LEFT_EDGE_X (w
);
1987 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1991 #ifdef HAVE_WINDOW_SYSTEM
1994 Return in RECTS[] at most N clipping rectangles for glyph string S.
1995 Return the number of stored rectangles. */
1998 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2005 if (s
->row
->full_width_p
)
2007 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2008 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2009 if (s
->row
->mode_line_p
)
2010 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
) - WINDOW_RIGHT_DIVIDER_WIDTH (s
->w
);
2012 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
);
2014 /* Unless displaying a mode or menu bar line, which are always
2015 fully visible, clip to the visible part of the row. */
2016 if (s
->w
->pseudo_window_p
)
2017 r
.height
= s
->row
->visible_height
;
2019 r
.height
= s
->height
;
2023 /* This is a text line that may be partially visible. */
2024 r
.x
= window_box_left (s
->w
, s
->area
);
2025 r
.width
= window_box_width (s
->w
, s
->area
);
2026 r
.height
= s
->row
->visible_height
;
2030 if (r
.x
< s
->clip_head
->x
)
2032 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2033 r
.width
-= s
->clip_head
->x
- r
.x
;
2036 r
.x
= s
->clip_head
->x
;
2039 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2041 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2042 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2047 /* If S draws overlapping rows, it's sufficient to use the top and
2048 bottom of the window for clipping because this glyph string
2049 intentionally draws over other lines. */
2050 if (s
->for_overlaps
)
2052 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2053 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2055 /* Alas, the above simple strategy does not work for the
2056 environments with anti-aliased text: if the same text is
2057 drawn onto the same place multiple times, it gets thicker.
2058 If the overlap we are processing is for the erased cursor, we
2059 take the intersection with the rectangle of the cursor. */
2060 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2062 XRectangle rc
, r_save
= r
;
2064 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2065 rc
.y
= s
->w
->phys_cursor
.y
;
2066 rc
.width
= s
->w
->phys_cursor_width
;
2067 rc
.height
= s
->w
->phys_cursor_height
;
2069 x_intersect_rectangles (&r_save
, &rc
, &r
);
2074 /* Don't use S->y for clipping because it doesn't take partially
2075 visible lines into account. For example, it can be negative for
2076 partially visible lines at the top of a window. */
2077 if (!s
->row
->full_width_p
2078 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2079 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2081 r
.y
= max (0, s
->row
->y
);
2084 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2086 /* If drawing the cursor, don't let glyph draw outside its
2087 advertised boundaries. Cleartype does this under some circumstances. */
2088 if (s
->hl
== DRAW_CURSOR
)
2090 struct glyph
*glyph
= s
->first_glyph
;
2095 if (r
.width
>= s
->x
- r
.x
)
2096 r
.width
-= s
->x
- r
.x
;
2097 else /* R2L hscrolled row with cursor outside text area */
2101 r
.width
= min (r
.width
, glyph
->pixel_width
);
2103 /* If r.y is below window bottom, ensure that we still see a cursor. */
2104 height
= min (glyph
->ascent
+ glyph
->descent
,
2105 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2106 max_y
= window_text_bottom_y (s
->w
) - height
;
2107 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2108 if (s
->ybase
- glyph
->ascent
> max_y
)
2115 /* Don't draw cursor glyph taller than our actual glyph. */
2116 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2117 if (height
< r
.height
)
2119 max_y
= r
.y
+ r
.height
;
2120 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2121 r
.height
= min (max_y
- r
.y
, height
);
2128 XRectangle r_save
= r
;
2130 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2134 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2135 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2137 #ifdef CONVERT_FROM_XRECT
2138 CONVERT_FROM_XRECT (r
, *rects
);
2146 /* If we are processing overlapping and allowed to return
2147 multiple clipping rectangles, we exclude the row of the glyph
2148 string from the clipping rectangle. This is to avoid drawing
2149 the same text on the environment with anti-aliasing. */
2150 #ifdef CONVERT_FROM_XRECT
2153 XRectangle
*rs
= rects
;
2155 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2157 if (s
->for_overlaps
& OVERLAPS_PRED
)
2160 if (r
.y
+ r
.height
> row_y
)
2163 rs
[i
].height
= row_y
- r
.y
;
2169 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2172 if (r
.y
< row_y
+ s
->row
->visible_height
)
2174 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2176 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2177 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2186 #ifdef CONVERT_FROM_XRECT
2187 for (i
= 0; i
< n
; i
++)
2188 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2195 Return in *NR the clipping rectangle for glyph string S. */
2198 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2200 get_glyph_string_clip_rects (s
, nr
, 1);
2205 Return the position and height of the phys cursor in window W.
2206 Set w->phys_cursor_width to width of phys cursor.
2210 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2211 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2213 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2214 int x
, y
, wd
, h
, h0
, y0
, ascent
;
2216 /* Compute the width of the rectangle to draw. If on a stretch
2217 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2218 rectangle as wide as the glyph, but use a canonical character
2220 wd
= glyph
->pixel_width
;
2222 x
= w
->phys_cursor
.x
;
2229 if (glyph
->type
== STRETCH_GLYPH
2230 && !x_stretch_cursor_p
)
2231 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2232 w
->phys_cursor_width
= wd
;
2234 /* Don't let the hollow cursor glyph descend below the glyph row's
2235 ascent value, lest the hollow cursor looks funny. */
2236 y
= w
->phys_cursor
.y
;
2237 ascent
= row
->ascent
;
2238 if (row
->ascent
< glyph
->ascent
)
2240 y
=- glyph
->ascent
- row
->ascent
;
2241 ascent
= glyph
->ascent
;
2244 /* If y is below window bottom, ensure that we still see a cursor. */
2245 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2247 h
= max (h0
, ascent
+ glyph
->descent
);
2248 h0
= min (h0
, ascent
+ glyph
->descent
);
2250 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2253 h
= max (h
- (y0
- y
) + 1, h0
);
2258 y0
= window_text_bottom_y (w
) - h0
;
2266 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2267 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2272 * Remember which glyph the mouse is over.
2276 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2280 struct glyph_row
*r
, *gr
, *end_row
;
2281 enum window_part part
;
2282 enum glyph_row_area area
;
2283 int x
, y
, width
, height
;
2285 /* Try to determine frame pixel position and size of the glyph under
2286 frame pixel coordinates X/Y on frame F. */
2288 if (window_resize_pixelwise
)
2293 else if (!f
->glyphs_initialized_p
2294 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, false),
2297 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2298 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2302 w
= XWINDOW (window
);
2303 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2304 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2306 x
= window_relative_x_coord (w
, part
, gx
);
2307 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2309 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2310 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2312 if (w
->pseudo_window_p
)
2315 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2321 case ON_LEFT_MARGIN
:
2322 area
= LEFT_MARGIN_AREA
;
2325 case ON_RIGHT_MARGIN
:
2326 area
= RIGHT_MARGIN_AREA
;
2329 case ON_HEADER_LINE
:
2331 gr
= (part
== ON_HEADER_LINE
2332 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2333 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2336 goto text_glyph_row_found
;
2343 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2344 if (r
->y
+ r
->height
> y
)
2350 text_glyph_row_found
:
2353 struct glyph
*g
= gr
->glyphs
[area
];
2354 struct glyph
*end
= g
+ gr
->used
[area
];
2356 height
= gr
->height
;
2357 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2358 if (gx
+ g
->pixel_width
> x
)
2363 if (g
->type
== IMAGE_GLYPH
)
2365 /* Don't remember when mouse is over image, as
2366 image may have hot-spots. */
2367 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2370 width
= g
->pixel_width
;
2374 /* Use nominal char spacing at end of line. */
2376 gx
+= (x
/ width
) * width
;
2379 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2381 gx
+= window_box_left_offset (w
, area
);
2382 /* Don't expand over the modeline to make sure the vertical
2383 drag cursor is shown early enough. */
2384 height
= min (height
,
2385 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2390 /* Use nominal line height at end of window. */
2391 gx
= (x
/ width
) * width
;
2393 gy
+= (y
/ height
) * height
;
2394 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2395 /* See comment above. */
2396 height
= min (height
,
2397 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2401 case ON_LEFT_FRINGE
:
2402 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2403 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2404 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2405 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2408 case ON_RIGHT_FRINGE
:
2409 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2410 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2411 : window_box_right_offset (w
, TEXT_AREA
));
2412 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
2413 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
2414 && !WINDOW_RIGHTMOST_P (w
))
2415 if (gx
< WINDOW_PIXEL_WIDTH (w
) - width
)
2416 /* Make sure the vertical border can get her own glyph to the
2417 right of the one we build here. */
2418 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
) - width
;
2420 width
= WINDOW_PIXEL_WIDTH (w
) - gx
;
2422 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2426 case ON_VERTICAL_BORDER
:
2427 gx
= WINDOW_PIXEL_WIDTH (w
) - width
;
2430 case ON_VERTICAL_SCROLL_BAR
:
2431 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2433 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2434 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2435 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2437 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2441 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2442 if (r
->y
+ r
->height
> y
)
2449 height
= gr
->height
;
2452 /* Use nominal line height at end of window. */
2454 gy
+= (y
/ height
) * height
;
2458 case ON_RIGHT_DIVIDER
:
2459 gx
= WINDOW_PIXEL_WIDTH (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2460 width
= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2462 /* The bottom divider prevails. */
2463 height
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2466 case ON_BOTTOM_DIVIDER
:
2468 width
= WINDOW_PIXEL_WIDTH (w
);
2469 gy
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2470 height
= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2476 /* If there is no glyph under the mouse, then we divide the screen
2477 into a grid of the smallest glyph in the frame, and use that
2480 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2481 round down even for negative values. */
2487 gx
= (gx
/ width
) * width
;
2488 gy
= (gy
/ height
) * height
;
2494 gx
+= WINDOW_LEFT_EDGE_X (w
);
2495 gy
+= WINDOW_TOP_EDGE_Y (w
);
2498 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2500 /* Visible feedback for debugging. */
2501 #if false && defined HAVE_X_WINDOWS
2502 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2503 f
->output_data
.x
->normal_gc
,
2504 gx
, gy
, width
, height
);
2509 #endif /* HAVE_WINDOW_SYSTEM */
2512 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2515 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2516 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2518 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2521 /***********************************************************************
2522 Lisp form evaluation
2523 ***********************************************************************/
2525 /* Error handler for safe_eval and safe_call. */
2528 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2530 add_to_log ("Error during redisplay: %S signaled %S",
2531 Flist (nargs
, args
), arg
);
2535 /* Call function FUNC with the rest of NARGS - 1 arguments
2536 following. Return the result, or nil if something went
2537 wrong. Prevent redisplay during the evaluation. */
2540 safe__call (bool inhibit_quit
, ptrdiff_t nargs
, Lisp_Object func
, va_list ap
)
2544 if (inhibit_eval_during_redisplay
)
2549 ptrdiff_t count
= SPECPDL_INDEX ();
2552 SAFE_ALLOCA_LISP (args
, nargs
);
2555 for (i
= 1; i
< nargs
; i
++)
2556 args
[i
] = va_arg (ap
, Lisp_Object
);
2558 specbind (Qinhibit_redisplay
, Qt
);
2560 specbind (Qinhibit_quit
, Qt
);
2561 /* Use Qt to ensure debugger does not run,
2562 so there is no possibility of wanting to redisplay. */
2563 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2566 val
= unbind_to (count
, val
);
2573 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2578 va_start (ap
, func
);
2579 retval
= safe__call (false, nargs
, func
, ap
);
2584 /* Call function FN with one argument ARG.
2585 Return the result, or nil if something went wrong. */
2588 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2590 return safe_call (2, fn
, arg
);
2594 safe__call1 (bool inhibit_quit
, Lisp_Object fn
, ...)
2600 retval
= safe__call (inhibit_quit
, 2, fn
, ap
);
2606 safe_eval (Lisp_Object sexpr
)
2608 return safe__call1 (false, Qeval
, sexpr
);
2612 safe__eval (bool inhibit_quit
, Lisp_Object sexpr
)
2614 return safe__call1 (inhibit_quit
, Qeval
, sexpr
);
2617 /* Call function FN with two arguments ARG1 and ARG2.
2618 Return the result, or nil if something went wrong. */
2621 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2623 return safe_call (3, fn
, arg1
, arg2
);
2628 /***********************************************************************
2630 ***********************************************************************/
2632 /* Define CHECK_IT to perform sanity checks on iterators.
2633 This is for debugging. It is too slow to do unconditionally. */
2636 CHECK_IT (struct it
*it
)
2639 if (it
->method
== GET_FROM_STRING
)
2641 eassert (STRINGP (it
->string
));
2642 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2646 eassert (IT_STRING_CHARPOS (*it
) < 0);
2647 if (it
->method
== GET_FROM_BUFFER
)
2649 /* Check that character and byte positions agree. */
2650 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2655 eassert (it
->current
.dpvec_index
>= 0);
2657 eassert (it
->current
.dpvec_index
< 0);
2662 /* Check that the window end of window W is what we expect it
2663 to be---the last row in the current matrix displaying text. */
2666 CHECK_WINDOW_END (struct window
*w
)
2668 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2669 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2671 struct glyph_row
*row
;
2672 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2674 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2675 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2680 /***********************************************************************
2681 Iterator initialization
2682 ***********************************************************************/
2684 /* Initialize IT for displaying current_buffer in window W, starting
2685 at character position CHARPOS. CHARPOS < 0 means that no buffer
2686 position is specified which is useful when the iterator is assigned
2687 a position later. BYTEPOS is the byte position corresponding to
2690 If ROW is not null, calls to produce_glyphs with IT as parameter
2691 will produce glyphs in that row.
2693 BASE_FACE_ID is the id of a base face to use. It must be one of
2694 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2695 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2696 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2698 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2699 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2700 will be initialized to use the corresponding mode line glyph row of
2701 the desired matrix of W. */
2704 init_iterator (struct it
*it
, struct window
*w
,
2705 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2706 struct glyph_row
*row
, enum face_id base_face_id
)
2708 enum face_id remapped_base_face_id
= base_face_id
;
2710 /* Some precondition checks. */
2711 eassert (w
!= NULL
&& it
!= NULL
);
2712 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2715 /* If face attributes have been changed since the last redisplay,
2716 free realized faces now because they depend on face definitions
2717 that might have changed. Don't free faces while there might be
2718 desired matrices pending which reference these faces. */
2719 if (!inhibit_free_realized_faces
)
2723 face_change
= false;
2724 free_all_realized_faces (Qnil
);
2726 else if (XFRAME (w
->frame
)->face_change
)
2728 XFRAME (w
->frame
)->face_change
= 0;
2729 free_all_realized_faces (w
->frame
);
2733 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2734 if (! NILP (Vface_remapping_alist
))
2735 remapped_base_face_id
2736 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2738 /* Use one of the mode line rows of W's desired matrix if
2742 if (base_face_id
== MODE_LINE_FACE_ID
2743 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2744 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2745 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2746 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2749 /* Clear IT, and set it->object and other IT's Lisp objects to Qnil.
2750 Other parts of redisplay rely on that. */
2751 memclear (it
, sizeof *it
);
2752 it
->current
.overlay_string_index
= -1;
2753 it
->current
.dpvec_index
= -1;
2754 it
->base_face_id
= remapped_base_face_id
;
2755 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2756 it
->paragraph_embedding
= L2R
;
2759 /* The window in which we iterate over current_buffer: */
2760 XSETWINDOW (it
->window
, w
);
2762 it
->f
= XFRAME (w
->frame
);
2766 /* Extra space between lines (on window systems only). */
2767 if (base_face_id
== DEFAULT_FACE_ID
2768 && FRAME_WINDOW_P (it
->f
))
2770 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2771 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2772 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2773 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2774 * FRAME_LINE_HEIGHT (it
->f
));
2775 else if (it
->f
->extra_line_spacing
> 0)
2776 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2779 /* If realized faces have been removed, e.g. because of face
2780 attribute changes of named faces, recompute them. When running
2781 in batch mode, the face cache of the initial frame is null. If
2782 we happen to get called, make a dummy face cache. */
2783 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2784 init_frame_faces (it
->f
);
2785 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2786 recompute_basic_faces (it
->f
);
2788 it
->override_ascent
= -1;
2790 /* Are control characters displayed as `^C'? */
2791 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2793 /* -1 means everything between a CR and the following line end
2794 is invisible. >0 means lines indented more than this value are
2796 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2798 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2800 : (!NILP (BVAR (current_buffer
, selective_display
))
2802 it
->selective_display_ellipsis_p
2803 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2805 /* Display table to use. */
2806 it
->dp
= window_display_table (w
);
2808 /* Are multibyte characters enabled in current_buffer? */
2809 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2811 /* Get the position at which the redisplay_end_trigger hook should
2812 be run, if it is to be run at all. */
2813 if (MARKERP (w
->redisplay_end_trigger
)
2814 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2815 it
->redisplay_end_trigger_charpos
2816 = marker_position (w
->redisplay_end_trigger
);
2817 else if (INTEGERP (w
->redisplay_end_trigger
))
2818 it
->redisplay_end_trigger_charpos
2819 = clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
),
2822 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2824 /* Are lines in the display truncated? */
2826 it
->line_wrap
= TRUNCATE
;
2827 if (base_face_id
== DEFAULT_FACE_ID
2829 && (WINDOW_FULL_WIDTH_P (it
->w
)
2830 || NILP (Vtruncate_partial_width_windows
)
2831 || (INTEGERP (Vtruncate_partial_width_windows
)
2832 /* PXW: Shall we do something about this? */
2833 && (XINT (Vtruncate_partial_width_windows
)
2834 <= WINDOW_TOTAL_COLS (it
->w
))))
2835 && NILP (BVAR (current_buffer
, truncate_lines
)))
2836 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2837 ? WINDOW_WRAP
: WORD_WRAP
;
2839 /* Get dimensions of truncation and continuation glyphs. These are
2840 displayed as fringe bitmaps under X, but we need them for such
2841 frames when the fringes are turned off. But leave the dimensions
2842 zero for tooltip frames, as these glyphs look ugly there and also
2843 sabotage calculations of tooltip dimensions in x-show-tip. */
2844 #ifdef HAVE_WINDOW_SYSTEM
2845 if (!(FRAME_WINDOW_P (it
->f
)
2846 && FRAMEP (tip_frame
)
2847 && it
->f
== XFRAME (tip_frame
)))
2850 if (it
->line_wrap
== TRUNCATE
)
2852 /* We will need the truncation glyph. */
2853 eassert (it
->glyph_row
== NULL
);
2854 produce_special_glyphs (it
, IT_TRUNCATION
);
2855 it
->truncation_pixel_width
= it
->pixel_width
;
2859 /* We will need the continuation glyph. */
2860 eassert (it
->glyph_row
== NULL
);
2861 produce_special_glyphs (it
, IT_CONTINUATION
);
2862 it
->continuation_pixel_width
= it
->pixel_width
;
2866 /* Reset these values to zero because the produce_special_glyphs
2867 above has changed them. */
2868 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2869 it
->phys_ascent
= it
->phys_descent
= 0;
2871 /* Set this after getting the dimensions of truncation and
2872 continuation glyphs, so that we don't produce glyphs when calling
2873 produce_special_glyphs, above. */
2874 it
->glyph_row
= row
;
2875 it
->area
= TEXT_AREA
;
2877 /* Get the dimensions of the display area. The display area
2878 consists of the visible window area plus a horizontally scrolled
2879 part to the left of the window. All x-values are relative to the
2880 start of this total display area. */
2881 if (base_face_id
!= DEFAULT_FACE_ID
)
2883 /* Mode lines, menu bar in terminal frames. */
2884 it
->first_visible_x
= 0;
2885 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2890 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2891 it
->last_visible_x
= (it
->first_visible_x
2892 + window_box_width (w
, TEXT_AREA
));
2894 /* If we truncate lines, leave room for the truncation glyph(s) at
2895 the right margin. Otherwise, leave room for the continuation
2896 glyph(s). Done only if the window has no right fringe. */
2897 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
2899 if (it
->line_wrap
== TRUNCATE
)
2900 it
->last_visible_x
-= it
->truncation_pixel_width
;
2902 it
->last_visible_x
-= it
->continuation_pixel_width
;
2905 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2906 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2909 /* Leave room for a border glyph. */
2910 if (!FRAME_WINDOW_P (it
->f
)
2911 && !WINDOW_RIGHTMOST_P (it
->w
))
2912 it
->last_visible_x
-= 1;
2914 it
->last_visible_y
= window_text_bottom_y (w
);
2916 /* For mode lines and alike, arrange for the first glyph having a
2917 left box line if the face specifies a box. */
2918 if (base_face_id
!= DEFAULT_FACE_ID
)
2922 it
->face_id
= remapped_base_face_id
;
2924 /* If we have a boxed mode line, make the first character appear
2925 with a left box line. */
2926 face
= FACE_FROM_ID_OR_NULL (it
->f
, remapped_base_face_id
);
2927 if (face
&& face
->box
!= FACE_NO_BOX
)
2928 it
->start_of_box_run_p
= true;
2931 /* If a buffer position was specified, set the iterator there,
2932 getting overlays and face properties from that position. */
2933 if (charpos
>= BUF_BEG (current_buffer
))
2935 it
->stop_charpos
= charpos
;
2936 it
->end_charpos
= ZV
;
2937 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2938 IT_CHARPOS (*it
) = charpos
;
2939 IT_BYTEPOS (*it
) = bytepos
;
2941 /* We will rely on `reseat' to set this up properly, via
2942 handle_face_prop. */
2943 it
->face_id
= it
->base_face_id
;
2945 it
->start
= it
->current
;
2946 /* Do we need to reorder bidirectional text? Not if this is a
2947 unibyte buffer: by definition, none of the single-byte
2948 characters are strong R2L, so no reordering is needed. And
2949 bidi.c doesn't support unibyte buffers anyway. Also, don't
2950 reorder while we are loading loadup.el, since the tables of
2951 character properties needed for reordering are not yet
2954 !redisplay__inhibit_bidi
2955 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2958 /* If we are to reorder bidirectional text, init the bidi
2962 /* Since we don't know at this point whether there will be
2963 any R2L lines in the window, we reserve space for
2964 truncation/continuation glyphs even if only the left
2965 fringe is absent. */
2966 if (base_face_id
== DEFAULT_FACE_ID
2967 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
2968 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
2970 if (it
->line_wrap
== TRUNCATE
)
2971 it
->last_visible_x
-= it
->truncation_pixel_width
;
2973 it
->last_visible_x
-= it
->continuation_pixel_width
;
2975 /* Note the paragraph direction that this buffer wants to
2977 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2979 it
->paragraph_embedding
= L2R
;
2980 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2982 it
->paragraph_embedding
= R2L
;
2984 it
->paragraph_embedding
= NEUTRAL_DIR
;
2985 bidi_unshelve_cache (NULL
, false);
2986 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2990 /* Compute faces etc. */
2991 reseat (it
, it
->current
.pos
, true);
2998 /* Initialize IT for the display of window W with window start POS. */
3001 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
3003 struct glyph_row
*row
;
3004 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
3006 row
= w
->desired_matrix
->rows
+ first_vpos
;
3007 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
3008 it
->first_vpos
= first_vpos
;
3010 /* Don't reseat to previous visible line start if current start
3011 position is in a string or image. */
3012 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
3014 int first_y
= it
->current_y
;
3016 /* If window start is not at a line start, skip forward to POS to
3017 get the correct continuation lines width. */
3018 bool start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3019 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3020 if (!start_at_line_beg_p
)
3024 reseat_at_previous_visible_line_start (it
);
3025 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3027 new_x
= it
->current_x
+ it
->pixel_width
;
3029 /* If lines are continued, this line may end in the middle
3030 of a multi-glyph character (e.g. a control character
3031 displayed as \003, or in the middle of an overlay
3032 string). In this case move_it_to above will not have
3033 taken us to the start of the continuation line but to the
3034 end of the continued line. */
3035 if (it
->current_x
> 0
3036 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3037 && (/* And glyph doesn't fit on the line. */
3038 new_x
> it
->last_visible_x
3039 /* Or it fits exactly and we're on a window
3041 || (new_x
== it
->last_visible_x
3042 && FRAME_WINDOW_P (it
->f
)
3043 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3044 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3045 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3047 if ((it
->current
.dpvec_index
>= 0
3048 || it
->current
.overlay_string_index
>= 0)
3049 /* If we are on a newline from a display vector or
3050 overlay string, then we are already at the end of
3051 a screen line; no need to go to the next line in
3052 that case, as this line is not really continued.
3053 (If we do go to the next line, C-e will not DTRT.) */
3056 set_iterator_to_next (it
, true);
3057 move_it_in_display_line_to (it
, -1, -1, 0);
3060 it
->continuation_lines_width
+= it
->current_x
;
3062 /* If the character at POS is displayed via a display
3063 vector, move_it_to above stops at the final glyph of
3064 IT->dpvec. To make the caller redisplay that character
3065 again (a.k.a. start at POS), we need to reset the
3066 dpvec_index to the beginning of IT->dpvec. */
3067 else if (it
->current
.dpvec_index
>= 0)
3068 it
->current
.dpvec_index
= 0;
3070 /* We're starting a new display line, not affected by the
3071 height of the continued line, so clear the appropriate
3072 fields in the iterator structure. */
3073 it
->max_ascent
= it
->max_descent
= 0;
3074 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3076 it
->current_y
= first_y
;
3078 it
->current_x
= it
->hpos
= 0;
3084 /* Return true if POS is a position in ellipses displayed for invisible
3085 text. W is the window we display, for text property lookup. */
3088 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3090 Lisp_Object prop
, window
;
3091 bool ellipses_p
= false;
3092 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3094 /* If POS specifies a position in a display vector, this might
3095 be for an ellipsis displayed for invisible text. We won't
3096 get the iterator set up for delivering that ellipsis unless
3097 we make sure that it gets aware of the invisible text. */
3098 if (pos
->dpvec_index
>= 0
3099 && pos
->overlay_string_index
< 0
3100 && CHARPOS (pos
->string_pos
) < 0
3102 && (XSETWINDOW (window
, w
),
3103 prop
= Fget_char_property (make_number (charpos
),
3104 Qinvisible
, window
),
3105 TEXT_PROP_MEANS_INVISIBLE (prop
) == 0))
3107 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3109 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3116 /* Initialize IT for stepping through current_buffer in window W,
3117 starting at position POS that includes overlay string and display
3118 vector/ control character translation position information. Value
3119 is false if there are overlay strings with newlines at POS. */
3122 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3124 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3126 bool overlay_strings_with_newlines
= false;
3128 /* If POS specifies a position in a display vector, this might
3129 be for an ellipsis displayed for invisible text. We won't
3130 get the iterator set up for delivering that ellipsis unless
3131 we make sure that it gets aware of the invisible text. */
3132 if (in_ellipses_for_invisible_text_p (pos
, w
))
3138 /* Keep in mind: the call to reseat in init_iterator skips invisible
3139 text, so we might end up at a position different from POS. This
3140 is only a problem when POS is a row start after a newline and an
3141 overlay starts there with an after-string, and the overlay has an
3142 invisible property. Since we don't skip invisible text in
3143 display_line and elsewhere immediately after consuming the
3144 newline before the row start, such a POS will not be in a string,
3145 but the call to init_iterator below will move us to the
3147 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3149 /* This only scans the current chunk -- it should scan all chunks.
3150 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3151 to 16 in 22.1 to make this a lesser problem. */
3152 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3154 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3155 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3157 while (s
< e
&& *s
!= '\n')
3162 overlay_strings_with_newlines
= true;
3167 /* If position is within an overlay string, set up IT to the right
3169 if (pos
->overlay_string_index
>= 0)
3173 /* If the first overlay string happens to have a `display'
3174 property for an image, the iterator will be set up for that
3175 image, and we have to undo that setup first before we can
3176 correct the overlay string index. */
3177 if (it
->method
== GET_FROM_IMAGE
)
3180 /* We already have the first chunk of overlay strings in
3181 IT->overlay_strings. Load more until the one for
3182 pos->overlay_string_index is in IT->overlay_strings. */
3183 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3185 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3186 it
->current
.overlay_string_index
= 0;
3189 load_overlay_strings (it
, 0);
3190 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3194 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3195 relative_index
= (it
->current
.overlay_string_index
3196 % OVERLAY_STRING_CHUNK_SIZE
);
3197 it
->string
= it
->overlay_strings
[relative_index
];
3198 eassert (STRINGP (it
->string
));
3199 it
->current
.string_pos
= pos
->string_pos
;
3200 it
->method
= GET_FROM_STRING
;
3201 it
->end_charpos
= SCHARS (it
->string
);
3202 /* Set up the bidi iterator for this overlay string. */
3205 it
->bidi_it
.string
.lstring
= it
->string
;
3206 it
->bidi_it
.string
.s
= NULL
;
3207 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3208 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3209 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3210 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3211 it
->bidi_it
.w
= it
->w
;
3212 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3213 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3215 /* Synchronize the state of the bidi iterator with
3216 pos->string_pos. For any string position other than
3217 zero, this will be done automagically when we resume
3218 iteration over the string and get_visually_first_element
3219 is called. But if string_pos is zero, and the string is
3220 to be reordered for display, we need to resync manually,
3221 since it could be that the iteration state recorded in
3222 pos ended at string_pos of 0 moving backwards in string. */
3223 if (CHARPOS (pos
->string_pos
) == 0)
3225 get_visually_first_element (it
);
3226 if (IT_STRING_CHARPOS (*it
) != 0)
3229 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3230 bidi_move_to_visually_next (&it
->bidi_it
);
3231 } while (it
->bidi_it
.charpos
!= 0);
3233 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3234 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3238 if (CHARPOS (pos
->string_pos
) >= 0)
3240 /* Recorded position is not in an overlay string, but in another
3241 string. This can only be a string from a `display' property.
3242 IT should already be filled with that string. */
3243 it
->current
.string_pos
= pos
->string_pos
;
3244 eassert (STRINGP (it
->string
));
3246 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3247 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3250 /* Restore position in display vector translations, control
3251 character translations or ellipses. */
3252 if (pos
->dpvec_index
>= 0)
3254 if (it
->dpvec
== NULL
)
3255 get_next_display_element (it
);
3256 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3257 it
->current
.dpvec_index
= pos
->dpvec_index
;
3261 return !overlay_strings_with_newlines
;
3265 /* Initialize IT for stepping through current_buffer in window W
3266 starting at ROW->start. */
3269 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3271 init_from_display_pos (it
, w
, &row
->start
);
3272 it
->start
= row
->start
;
3273 it
->continuation_lines_width
= row
->continuation_lines_width
;
3278 /* Initialize IT for stepping through current_buffer in window W
3279 starting in the line following ROW, i.e. starting at ROW->end.
3280 Value is false if there are overlay strings with newlines at ROW's
3284 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3286 bool success
= false;
3288 if (init_from_display_pos (it
, w
, &row
->end
))
3290 if (row
->continued_p
)
3291 it
->continuation_lines_width
3292 = row
->continuation_lines_width
+ row
->pixel_width
;
3303 /***********************************************************************
3305 ***********************************************************************/
3307 /* Called when IT reaches IT->stop_charpos. Handle text property and
3308 overlay changes. Set IT->stop_charpos to the next position where
3312 handle_stop (struct it
*it
)
3314 enum prop_handled handled
;
3315 bool handle_overlay_change_p
;
3319 it
->current
.dpvec_index
= -1;
3320 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3321 it
->ellipsis_p
= false;
3323 /* Use face of preceding text for ellipsis (if invisible) */
3324 if (it
->selective_display_ellipsis_p
)
3325 it
->saved_face_id
= it
->face_id
;
3327 /* Here's the description of the semantics of, and the logic behind,
3328 the various HANDLED_* statuses:
3330 HANDLED_NORMALLY means the handler did its job, and the loop
3331 should proceed to calling the next handler in order.
3333 HANDLED_RECOMPUTE_PROPS means the handler caused a significant
3334 change in the properties and overlays at current position, so the
3335 loop should be restarted, to re-invoke the handlers that were
3336 already called. This happens when fontification-functions were
3337 called by handle_fontified_prop, and actually fontified
3338 something. Another case where HANDLED_RECOMPUTE_PROPS is
3339 returned is when we discover overlay strings that need to be
3340 displayed right away. The loop below will continue for as long
3341 as the status is HANDLED_RECOMPUTE_PROPS.
3343 HANDLED_RETURN means return immediately to the caller, to
3344 continue iteration without calling any further handlers. This is
3345 used when we need to act on some property right away, for example
3346 when we need to display the ellipsis or a replacing display
3347 property, such as display string or image.
3349 HANDLED_OVERLAY_STRING_CONSUMED means an overlay string was just
3350 consumed, and the handler switched to the next overlay string.
3351 This signals the loop below to refrain from looking for more
3352 overlays before all the overlay strings of the current overlay
3355 Some of the handlers called by the loop push the iterator state
3356 onto the stack (see 'push_it'), and arrange for the iteration to
3357 continue with another object, such as an image, a display string,
3358 or an overlay string. In most such cases, it->stop_charpos is
3359 set to the first character of the string, so that when the
3360 iteration resumes, this function will immediately be called
3361 again, to examine the properties at the beginning of the string.
3363 When a display or overlay string is exhausted, the iterator state
3364 is popped (see 'pop_it'), and iteration continues with the
3365 previous object. Again, in many such cases this function is
3366 called again to find the next position where properties might
3371 handled
= HANDLED_NORMALLY
;
3373 /* Call text property handlers. */
3374 for (p
= it_props
; p
->handler
; ++p
)
3376 handled
= p
->handler (it
);
3378 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3380 else if (handled
== HANDLED_RETURN
)
3382 /* We still want to show before and after strings from
3383 overlays even if the actual buffer text is replaced. */
3384 if (!handle_overlay_change_p
3386 /* Don't call get_overlay_strings_1 if we already
3387 have overlay strings loaded, because doing so
3388 will load them again and push the iterator state
3389 onto the stack one more time, which is not
3390 expected by the rest of the code that processes
3392 || (it
->current
.overlay_string_index
< 0
3393 && !get_overlay_strings_1 (it
, 0, false)))
3396 setup_for_ellipsis (it
, 0);
3397 /* When handling a display spec, we might load an
3398 empty string. In that case, discard it here. We
3399 used to discard it in handle_single_display_spec,
3400 but that causes get_overlay_strings_1, above, to
3401 ignore overlay strings that we must check. */
3402 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3406 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3410 it
->string_from_display_prop_p
= false;
3411 it
->from_disp_prop_p
= false;
3412 handle_overlay_change_p
= false;
3414 handled
= HANDLED_RECOMPUTE_PROPS
;
3417 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3418 handle_overlay_change_p
= false;
3421 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3423 /* Don't check for overlay strings below when set to deliver
3424 characters from a display vector. */
3425 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3426 handle_overlay_change_p
= false;
3428 /* Handle overlay changes.
3429 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3430 if it finds overlays. */
3431 if (handle_overlay_change_p
)
3432 handled
= handle_overlay_change (it
);
3437 setup_for_ellipsis (it
, 0);
3441 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3443 /* Determine where to stop next. */
3444 if (handled
== HANDLED_NORMALLY
)
3445 compute_stop_pos (it
);
3449 /* Compute IT->stop_charpos from text property and overlay change
3450 information for IT's current position. */
3453 compute_stop_pos (struct it
*it
)
3455 register INTERVAL iv
, next_iv
;
3456 Lisp_Object object
, limit
, position
;
3457 ptrdiff_t charpos
, bytepos
;
3459 if (STRINGP (it
->string
))
3461 /* Strings are usually short, so don't limit the search for
3463 it
->stop_charpos
= it
->end_charpos
;
3464 object
= it
->string
;
3466 charpos
= IT_STRING_CHARPOS (*it
);
3467 bytepos
= IT_STRING_BYTEPOS (*it
);
3473 /* If end_charpos is out of range for some reason, such as a
3474 misbehaving display function, rationalize it (Bug#5984). */
3475 if (it
->end_charpos
> ZV
)
3476 it
->end_charpos
= ZV
;
3477 it
->stop_charpos
= it
->end_charpos
;
3479 /* If next overlay change is in front of the current stop pos
3480 (which is IT->end_charpos), stop there. Note: value of
3481 next_overlay_change is point-max if no overlay change
3483 charpos
= IT_CHARPOS (*it
);
3484 bytepos
= IT_BYTEPOS (*it
);
3485 pos
= next_overlay_change (charpos
);
3486 if (pos
< it
->stop_charpos
)
3487 it
->stop_charpos
= pos
;
3489 /* Set up variables for computing the stop position from text
3490 property changes. */
3491 XSETBUFFER (object
, current_buffer
);
3492 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3495 /* Get the interval containing IT's position. Value is a null
3496 interval if there isn't such an interval. */
3497 position
= make_number (charpos
);
3498 iv
= validate_interval_range (object
, &position
, &position
, false);
3501 Lisp_Object values_here
[LAST_PROP_IDX
];
3504 /* Get properties here. */
3505 for (p
= it_props
; p
->handler
; ++p
)
3506 values_here
[p
->idx
] = textget (iv
->plist
,
3507 builtin_lisp_symbol (p
->name
));
3509 /* Look for an interval following iv that has different
3511 for (next_iv
= next_interval (iv
);
3514 || XFASTINT (limit
) > next_iv
->position
));
3515 next_iv
= next_interval (next_iv
))
3517 for (p
= it_props
; p
->handler
; ++p
)
3519 Lisp_Object new_value
= textget (next_iv
->plist
,
3520 builtin_lisp_symbol (p
->name
));
3521 if (!EQ (values_here
[p
->idx
], new_value
))
3531 if (INTEGERP (limit
)
3532 && next_iv
->position
>= XFASTINT (limit
))
3533 /* No text property change up to limit. */
3534 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3536 /* Text properties change in next_iv. */
3537 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3541 if (it
->cmp_it
.id
< 0)
3543 ptrdiff_t stoppos
= it
->end_charpos
;
3545 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3547 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3548 stoppos
, it
->string
);
3551 eassert (STRINGP (it
->string
)
3552 || (it
->stop_charpos
>= BEGV
3553 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3557 /* Return the position of the next overlay change after POS in
3558 current_buffer. Value is point-max if no overlay change
3559 follows. This is like `next-overlay-change' but doesn't use
3563 next_overlay_change (ptrdiff_t pos
)
3565 ptrdiff_t i
, noverlays
;
3567 Lisp_Object
*overlays
;
3570 /* Get all overlays at the given position. */
3571 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, true);
3573 /* If any of these overlays ends before endpos,
3574 use its ending point instead. */
3575 for (i
= 0; i
< noverlays
; ++i
)
3580 oend
= OVERLAY_END (overlays
[i
]);
3581 oendpos
= OVERLAY_POSITION (oend
);
3582 endpos
= min (endpos
, oendpos
);
3589 /* How many characters forward to search for a display property or
3590 display string. Searching too far forward makes the bidi display
3591 sluggish, especially in small windows. */
3592 #define MAX_DISP_SCAN 250
3594 /* Return the character position of a display string at or after
3595 position specified by POSITION. If no display string exists at or
3596 after POSITION, return ZV. A display string is either an overlay
3597 with `display' property whose value is a string, or a `display'
3598 text property whose value is a string. STRING is data about the
3599 string to iterate; if STRING->lstring is nil, we are iterating a
3600 buffer. FRAME_WINDOW_P is true when we are displaying a window
3601 on a GUI frame. DISP_PROP is set to zero if we searched
3602 MAX_DISP_SCAN characters forward without finding any display
3603 strings, non-zero otherwise. It is set to 2 if the display string
3604 uses any kind of `(space ...)' spec that will produce a stretch of
3605 white space in the text area. */
3607 compute_display_string_pos (struct text_pos
*position
,
3608 struct bidi_string_data
*string
,
3610 bool frame_window_p
, int *disp_prop
)
3612 /* OBJECT = nil means current buffer. */
3613 Lisp_Object object
, object1
;
3614 Lisp_Object pos
, spec
, limpos
;
3615 bool string_p
= string
&& (STRINGP (string
->lstring
) || string
->s
);
3616 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3617 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3618 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3620 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3621 struct text_pos tpos
;
3624 if (string
&& STRINGP (string
->lstring
))
3625 object1
= object
= string
->lstring
;
3626 else if (w
&& !string_p
)
3628 XSETWINDOW (object
, w
);
3632 object1
= object
= Qnil
;
3637 /* We don't support display properties whose values are strings
3638 that have display string properties. */
3639 || string
->from_disp_str
3640 /* C strings cannot have display properties. */
3641 || (string
->s
&& !STRINGP (object
)))
3647 /* If the character at CHARPOS is where the display string begins,
3649 pos
= make_number (charpos
);
3650 if (STRINGP (object
))
3651 bufpos
= string
->bufpos
;
3655 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3657 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3660 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3668 /* Look forward for the first character with a `display' property
3669 that will replace the underlying text when displayed. */
3670 limpos
= make_number (lim
);
3672 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3673 CHARPOS (tpos
) = XFASTINT (pos
);
3674 if (CHARPOS (tpos
) >= lim
)
3679 if (STRINGP (object
))
3680 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3682 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3683 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3684 if (!STRINGP (object
))
3685 bufpos
= CHARPOS (tpos
);
3686 } while (NILP (spec
)
3687 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3688 bufpos
, frame_window_p
)));
3692 return CHARPOS (tpos
);
3695 /* Return the character position of the end of the display string that
3696 started at CHARPOS. If there's no display string at CHARPOS,
3697 return -1. A display string is either an overlay with `display'
3698 property whose value is a string or a `display' text property whose
3699 value is a string. */
3701 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3703 /* OBJECT = nil means current buffer. */
3704 Lisp_Object object
=
3705 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3706 Lisp_Object pos
= make_number (charpos
);
3708 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3710 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3713 /* It could happen that the display property or overlay was removed
3714 since we found it in compute_display_string_pos above. One way
3715 this can happen is if JIT font-lock was called (through
3716 handle_fontified_prop), and jit-lock-functions remove text
3717 properties or overlays from the portion of buffer that includes
3718 CHARPOS. Muse mode is known to do that, for example. In this
3719 case, we return -1 to the caller, to signal that no display
3720 string is actually present at CHARPOS. See bidi_fetch_char for
3721 how this is handled.
3723 An alternative would be to never look for display properties past
3724 it->stop_charpos. But neither compute_display_string_pos nor
3725 bidi_fetch_char that calls it know or care where the next
3727 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3730 /* Look forward for the first character where the `display' property
3732 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3734 return XFASTINT (pos
);
3739 /***********************************************************************
3741 ***********************************************************************/
3743 /* Handle changes in the `fontified' property of the current buffer by
3744 calling hook functions from Qfontification_functions to fontify
3747 static enum prop_handled
3748 handle_fontified_prop (struct it
*it
)
3750 Lisp_Object prop
, pos
;
3751 enum prop_handled handled
= HANDLED_NORMALLY
;
3753 if (!NILP (Vmemory_full
))
3756 /* Get the value of the `fontified' property at IT's current buffer
3757 position. (The `fontified' property doesn't have a special
3758 meaning in strings.) If the value is nil, call functions from
3759 Qfontification_functions. */
3760 if (!STRINGP (it
->string
)
3762 && !NILP (Vfontification_functions
)
3763 && !NILP (Vrun_hooks
)
3764 && (pos
= make_number (IT_CHARPOS (*it
)),
3765 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3766 /* Ignore the special cased nil value always present at EOB since
3767 no amount of fontifying will be able to change it. */
3768 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3770 ptrdiff_t count
= SPECPDL_INDEX ();
3772 struct buffer
*obuf
= current_buffer
;
3773 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3774 bool old_clip_changed
= current_buffer
->clip_changed
;
3776 val
= Vfontification_functions
;
3777 specbind (Qfontification_functions
, Qnil
);
3779 eassert (it
->end_charpos
== ZV
);
3781 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3782 safe_call1 (val
, pos
);
3785 Lisp_Object fns
, fn
;
3789 for (; CONSP (val
); val
= XCDR (val
))
3795 /* A value of t indicates this hook has a local
3796 binding; it means to run the global binding too.
3797 In a global value, t should not occur. If it
3798 does, we must ignore it to avoid an endless
3800 for (fns
= Fdefault_value (Qfontification_functions
);
3806 safe_call1 (fn
, pos
);
3810 safe_call1 (fn
, pos
);
3814 unbind_to (count
, Qnil
);
3816 /* Fontification functions routinely call `save-restriction'.
3817 Normally, this tags clip_changed, which can confuse redisplay
3818 (see discussion in Bug#6671). Since we don't perform any
3819 special handling of fontification changes in the case where
3820 `save-restriction' isn't called, there's no point doing so in
3821 this case either. So, if the buffer's restrictions are
3822 actually left unchanged, reset clip_changed. */
3823 if (obuf
== current_buffer
)
3825 if (begv
== BEGV
&& zv
== ZV
)
3826 current_buffer
->clip_changed
= old_clip_changed
;
3828 /* There isn't much we can reasonably do to protect against
3829 misbehaving fontification, but here's a fig leaf. */
3830 else if (BUFFER_LIVE_P (obuf
))
3831 set_buffer_internal_1 (obuf
);
3833 /* The fontification code may have added/removed text.
3834 It could do even a lot worse, but let's at least protect against
3835 the most obvious case where only the text past `pos' gets changed',
3836 as is/was done in grep.el where some escapes sequences are turned
3837 into face properties (bug#7876). */
3838 it
->end_charpos
= ZV
;
3840 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3841 something. This avoids an endless loop if they failed to
3842 fontify the text for which reason ever. */
3843 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3844 handled
= HANDLED_RECOMPUTE_PROPS
;
3852 /***********************************************************************
3854 ***********************************************************************/
3856 /* Set up iterator IT from face properties at its current position.
3857 Called from handle_stop. */
3859 static enum prop_handled
3860 handle_face_prop (struct it
*it
)
3863 ptrdiff_t next_stop
;
3865 if (!STRINGP (it
->string
))
3868 = face_at_buffer_position (it
->w
,
3872 + TEXT_PROP_DISTANCE_LIMIT
),
3873 false, it
->base_face_id
);
3875 /* Is this a start of a run of characters with box face?
3876 Caveat: this can be called for a freshly initialized
3877 iterator; face_id is -1 in this case. We know that the new
3878 face will not change until limit, i.e. if the new face has a
3879 box, all characters up to limit will have one. But, as
3880 usual, we don't know whether limit is really the end. */
3881 if (new_face_id
!= it
->face_id
)
3883 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3884 /* If it->face_id is -1, old_face below will be NULL, see
3885 the definition of FACE_FROM_ID_OR_NULL. This will happen
3886 if this is the initial call that gets the face. */
3887 struct face
*old_face
= FACE_FROM_ID_OR_NULL (it
->f
, it
->face_id
);
3889 /* If the value of face_id of the iterator is -1, we have to
3890 look in front of IT's position and see whether there is a
3891 face there that's different from new_face_id. */
3892 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3894 int prev_face_id
= face_before_it_pos (it
);
3896 old_face
= FACE_FROM_ID_OR_NULL (it
->f
, prev_face_id
);
3899 /* If the new face has a box, but the old face does not,
3900 this is the start of a run of characters with box face,
3901 i.e. this character has a shadow on the left side. */
3902 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3903 && (old_face
== NULL
|| !old_face
->box
));
3904 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3912 Lisp_Object from_overlay
3913 = (it
->current
.overlay_string_index
>= 0
3914 ? it
->string_overlays
[it
->current
.overlay_string_index
3915 % OVERLAY_STRING_CHUNK_SIZE
]
3918 /* See if we got to this string directly or indirectly from
3919 an overlay property. That includes the before-string or
3920 after-string of an overlay, strings in display properties
3921 provided by an overlay, their text properties, etc.
3923 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3924 if (! NILP (from_overlay
))
3925 for (i
= it
->sp
- 1; i
>= 0; i
--)
3927 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3929 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3930 % OVERLAY_STRING_CHUNK_SIZE
];
3931 else if (! NILP (it
->stack
[i
].from_overlay
))
3932 from_overlay
= it
->stack
[i
].from_overlay
;
3934 if (!NILP (from_overlay
))
3938 if (! NILP (from_overlay
))
3940 bufpos
= IT_CHARPOS (*it
);
3941 /* For a string from an overlay, the base face depends
3942 only on text properties and ignores overlays. */
3944 = face_for_overlay_string (it
->w
,
3948 + TEXT_PROP_DISTANCE_LIMIT
),
3956 /* For strings from a `display' property, use the face at
3957 IT's current buffer position as the base face to merge
3958 with, so that overlay strings appear in the same face as
3959 surrounding text, unless they specify their own faces.
3960 For strings from wrap-prefix and line-prefix properties,
3961 use the default face, possibly remapped via
3962 Vface_remapping_alist. */
3963 /* Note that the fact that we use the face at _buffer_
3964 position means that a 'display' property on an overlay
3965 string will not inherit the face of that overlay string,
3966 but will instead revert to the face of buffer text
3967 covered by the overlay. This is visible, e.g., when the
3968 overlay specifies a box face, but neither the buffer nor
3969 the display string do. This sounds like a design bug,
3970 but Emacs always did that since v21.1, so changing that
3971 might be a big deal. */
3972 base_face_id
= it
->string_from_prefix_prop_p
3973 ? (!NILP (Vface_remapping_alist
)
3974 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3976 : underlying_face_id (it
);
3979 new_face_id
= face_at_string_position (it
->w
,
3981 IT_STRING_CHARPOS (*it
),
3984 base_face_id
, false);
3986 /* Is this a start of a run of characters with box? Caveat:
3987 this can be called for a freshly allocated iterator; face_id
3988 is -1 is this case. We know that the new face will not
3989 change until the next check pos, i.e. if the new face has a
3990 box, all characters up to that position will have a
3991 box. But, as usual, we don't know whether that position
3992 is really the end. */
3993 if (new_face_id
!= it
->face_id
)
3995 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3996 struct face
*old_face
= FACE_FROM_ID_OR_NULL (it
->f
, it
->face_id
);
3998 /* If new face has a box but old face hasn't, this is the
3999 start of a run of characters with box, i.e. it has a
4000 shadow on the left side. */
4001 it
->start_of_box_run_p
4002 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
4003 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
4007 it
->face_id
= new_face_id
;
4008 return HANDLED_NORMALLY
;
4012 /* Return the ID of the face ``underlying'' IT's current position,
4013 which is in a string. If the iterator is associated with a
4014 buffer, return the face at IT's current buffer position.
4015 Otherwise, use the iterator's base_face_id. */
4018 underlying_face_id (struct it
*it
)
4020 int face_id
= it
->base_face_id
, i
;
4022 eassert (STRINGP (it
->string
));
4024 for (i
= it
->sp
- 1; i
>= 0; --i
)
4025 if (NILP (it
->stack
[i
].string
))
4026 face_id
= it
->stack
[i
].face_id
;
4032 /* Compute the face one character before or after the current position
4033 of IT, in the visual order. BEFORE_P means get the face
4034 in front (to the left in L2R paragraphs, to the right in R2L
4035 paragraphs) of IT's screen position. Value is the ID of the face. */
4038 face_before_or_after_it_pos (struct it
*it
, bool before_p
)
4041 ptrdiff_t next_check_charpos
;
4043 void *it_copy_data
= NULL
;
4045 eassert (it
->s
== NULL
);
4047 if (STRINGP (it
->string
))
4049 ptrdiff_t bufpos
, charpos
;
4052 /* No face change past the end of the string (for the case
4053 we are padding with spaces). No face change before the
4055 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
4056 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4061 /* Set charpos to the position before or after IT's current
4062 position, in the logical order, which in the non-bidi
4063 case is the same as the visual order. */
4065 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4066 else if (it
->what
== IT_COMPOSITION
)
4067 /* For composition, we must check the character after the
4069 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4071 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4077 /* With bidi iteration, the character before the current
4078 in the visual order cannot be found by simple
4079 iteration, because "reverse" reordering is not
4080 supported. Instead, we need to start from the string
4081 beginning and go all the way to the current string
4082 position, remembering the previous position. */
4083 /* Ignore face changes before the first visible
4084 character on this display line. */
4085 if (it
->current_x
<= it
->first_visible_x
)
4087 SAVE_IT (it_copy
, *it
, it_copy_data
);
4088 IT_STRING_CHARPOS (it_copy
) = 0;
4089 bidi_init_it (0, 0, FRAME_WINDOW_P (it_copy
.f
), &it_copy
.bidi_it
);
4093 charpos
= IT_STRING_CHARPOS (it_copy
);
4094 if (charpos
>= SCHARS (it
->string
))
4096 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4098 while (IT_STRING_CHARPOS (it_copy
) != IT_STRING_CHARPOS (*it
));
4100 RESTORE_IT (it
, it
, it_copy_data
);
4104 /* Set charpos to the string position of the character
4105 that comes after IT's current position in the visual
4107 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4111 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4113 charpos
= it_copy
.bidi_it
.charpos
;
4116 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4118 if (it
->current
.overlay_string_index
>= 0)
4119 bufpos
= IT_CHARPOS (*it
);
4123 base_face_id
= underlying_face_id (it
);
4125 /* Get the face for ASCII, or unibyte. */
4126 face_id
= face_at_string_position (it
->w
,
4130 &next_check_charpos
,
4131 base_face_id
, false);
4133 /* Correct the face for charsets different from ASCII. Do it
4134 for the multibyte case only. The face returned above is
4135 suitable for unibyte text if IT->string is unibyte. */
4136 if (STRING_MULTIBYTE (it
->string
))
4138 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4139 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4141 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4143 c
= string_char_and_length (p
, &len
);
4144 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4149 struct text_pos pos
;
4151 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4152 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4155 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4156 pos
= it
->current
.pos
;
4161 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4164 if (it
->what
== IT_COMPOSITION
)
4166 /* For composition, we must check the position after
4168 pos
.charpos
+= it
->cmp_it
.nchars
;
4169 pos
.bytepos
+= it
->len
;
4172 INC_TEXT_POS (pos
, it
->multibyte_p
);
4181 /* With bidi iteration, the character before the current
4182 in the visual order cannot be found by simple
4183 iteration, because "reverse" reordering is not
4184 supported. Instead, we need to use the move_it_*
4185 family of functions, and move to the previous
4186 character starting from the beginning of the visual
4188 /* Ignore face changes before the first visible
4189 character on this display line. */
4190 if (it
->current_x
<= it
->first_visible_x
)
4192 SAVE_IT (it_copy
, *it
, it_copy_data
);
4193 /* Implementation note: Since move_it_in_display_line
4194 works in the iterator geometry, and thinks the first
4195 character is always the leftmost, even in R2L lines,
4196 we don't need to distinguish between the R2L and L2R
4198 current_x
= it_copy
.current_x
;
4199 move_it_vertically_backward (&it_copy
, 0);
4200 move_it_in_display_line (&it_copy
, ZV
, current_x
- 1, MOVE_TO_X
);
4201 pos
= it_copy
.current
.pos
;
4202 RESTORE_IT (it
, it
, it_copy_data
);
4206 /* Set charpos to the buffer position of the character
4207 that comes after IT's current position in the visual
4209 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4213 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4216 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4219 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4221 /* Determine face for CHARSET_ASCII, or unibyte. */
4222 face_id
= face_at_buffer_position (it
->w
,
4224 &next_check_charpos
,
4227 /* Correct the face for charsets different from ASCII. Do it
4228 for the multibyte case only. The face returned above is
4229 suitable for unibyte text if current_buffer is unibyte. */
4230 if (it
->multibyte_p
)
4232 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4233 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4234 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4243 /***********************************************************************
4245 ***********************************************************************/
4247 /* Set up iterator IT from invisible properties at its current
4248 position. Called from handle_stop. */
4250 static enum prop_handled
4251 handle_invisible_prop (struct it
*it
)
4253 enum prop_handled handled
= HANDLED_NORMALLY
;
4257 if (STRINGP (it
->string
))
4259 Lisp_Object end_charpos
, limit
;
4261 /* Get the value of the invisible text property at the
4262 current position. Value will be nil if there is no such
4264 end_charpos
= make_number (IT_STRING_CHARPOS (*it
));
4265 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4266 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4268 if (invis
!= 0 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4270 /* Record whether we have to display an ellipsis for the
4272 bool display_ellipsis_p
= (invis
== 2);
4273 ptrdiff_t len
, endpos
;
4275 handled
= HANDLED_RECOMPUTE_PROPS
;
4277 /* Get the position at which the next visible text can be
4278 found in IT->string, if any. */
4279 endpos
= len
= SCHARS (it
->string
);
4280 XSETINT (limit
, len
);
4284 = Fnext_single_property_change (end_charpos
, Qinvisible
,
4286 /* Since LIMIT is always an integer, so should be the
4287 value returned by Fnext_single_property_change. */
4288 eassert (INTEGERP (end_charpos
));
4289 if (INTEGERP (end_charpos
))
4291 endpos
= XFASTINT (end_charpos
);
4292 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4293 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4295 display_ellipsis_p
= true;
4297 else /* Should never happen; but if it does, exit the loop. */
4300 while (invis
!= 0 && endpos
< len
);
4302 if (display_ellipsis_p
)
4303 it
->ellipsis_p
= true;
4307 /* Text at END_CHARPOS is visible. Move IT there. */
4308 struct text_pos old
;
4311 old
= it
->current
.string_pos
;
4312 oldpos
= CHARPOS (old
);
4315 if (it
->bidi_it
.first_elt
4316 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4317 bidi_paragraph_init (it
->paragraph_embedding
,
4318 &it
->bidi_it
, true);
4319 /* Bidi-iterate out of the invisible text. */
4322 bidi_move_to_visually_next (&it
->bidi_it
);
4324 while (oldpos
<= it
->bidi_it
.charpos
4325 && it
->bidi_it
.charpos
< endpos
);
4327 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4328 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4329 if (IT_CHARPOS (*it
) >= endpos
)
4330 it
->prev_stop
= endpos
;
4334 IT_STRING_CHARPOS (*it
) = endpos
;
4335 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4340 /* The rest of the string is invisible. If this is an
4341 overlay string, proceed with the next overlay string
4342 or whatever comes and return a character from there. */
4343 if (it
->current
.overlay_string_index
>= 0
4344 && !display_ellipsis_p
)
4346 next_overlay_string (it
);
4347 /* Don't check for overlay strings when we just
4348 finished processing them. */
4349 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4353 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4354 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4361 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4362 Lisp_Object pos
, overlay
;
4364 /* First of all, is there invisible text at this position? */
4365 tem
= start_charpos
= IT_CHARPOS (*it
);
4366 pos
= make_number (tem
);
4367 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4369 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4371 /* If we are on invisible text, skip over it. */
4372 if (invis
!= 0 && start_charpos
< it
->end_charpos
)
4374 /* Record whether we have to display an ellipsis for the
4376 bool display_ellipsis_p
= invis
== 2;
4378 handled
= HANDLED_RECOMPUTE_PROPS
;
4380 /* Loop skipping over invisible text. The loop is left at
4381 ZV or with IT on the first char being visible again. */
4384 /* Try to skip some invisible text. Return value is the
4385 position reached which can be equal to where we start
4386 if there is nothing invisible there. This skips both
4387 over invisible text properties and overlays with
4388 invisible property. */
4389 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4391 /* If we skipped nothing at all we weren't at invisible
4392 text in the first place. If everything to the end of
4393 the buffer was skipped, end the loop. */
4394 if (newpos
== tem
|| newpos
>= ZV
)
4398 /* We skipped some characters but not necessarily
4399 all there are. Check if we ended up on visible
4400 text. Fget_char_property returns the property of
4401 the char before the given position, i.e. if we
4402 get invis = 0, this means that the char at
4403 newpos is visible. */
4404 pos
= make_number (newpos
);
4405 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4406 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4409 /* If we ended up on invisible text, proceed to
4410 skip starting with next_stop. */
4414 /* If there are adjacent invisible texts, don't lose the
4415 second one's ellipsis. */
4417 display_ellipsis_p
= true;
4421 /* The position newpos is now either ZV or on visible text. */
4424 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4426 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4428 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4430 /* If the invisible text ends on a newline or on a
4431 character after a newline, we can avoid the costly,
4432 character by character, bidi iteration to NEWPOS, and
4433 instead simply reseat the iterator there. That's
4434 because all bidi reordering information is tossed at
4435 the newline. This is a big win for modes that hide
4436 complete lines, like Outline, Org, etc. */
4437 if (on_newline
|| after_newline
)
4439 struct text_pos tpos
;
4440 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4442 SET_TEXT_POS (tpos
, newpos
, bpos
);
4443 reseat_1 (it
, tpos
, false);
4444 /* If we reseat on a newline/ZV, we need to prep the
4445 bidi iterator for advancing to the next character
4446 after the newline/EOB, keeping the current paragraph
4447 direction (so that PRODUCE_GLYPHS does TRT wrt
4448 prepending/appending glyphs to a glyph row). */
4451 it
->bidi_it
.first_elt
= false;
4452 it
->bidi_it
.paragraph_dir
= pdir
;
4453 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4454 it
->bidi_it
.nchars
= 1;
4455 it
->bidi_it
.ch_len
= 1;
4458 else /* Must use the slow method. */
4460 /* With bidi iteration, the region of invisible text
4461 could start and/or end in the middle of a
4462 non-base embedding level. Therefore, we need to
4463 skip invisible text using the bidi iterator,
4464 starting at IT's current position, until we find
4465 ourselves outside of the invisible text.
4466 Skipping invisible text _after_ bidi iteration
4467 avoids affecting the visual order of the
4468 displayed text when invisible properties are
4469 added or removed. */
4470 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4472 /* If we were `reseat'ed to a new paragraph,
4473 determine the paragraph base direction. We
4474 need to do it now because
4475 next_element_from_buffer may not have a
4476 chance to do it, if we are going to skip any
4477 text at the beginning, which resets the
4479 bidi_paragraph_init (it
->paragraph_embedding
,
4480 &it
->bidi_it
, true);
4484 bidi_move_to_visually_next (&it
->bidi_it
);
4486 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4487 && it
->bidi_it
.charpos
< newpos
);
4488 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4489 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4490 /* If we overstepped NEWPOS, record its position in
4491 the iterator, so that we skip invisible text if
4492 later the bidi iteration lands us in the
4493 invisible region again. */
4494 if (IT_CHARPOS (*it
) >= newpos
)
4495 it
->prev_stop
= newpos
;
4500 IT_CHARPOS (*it
) = newpos
;
4501 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4504 if (display_ellipsis_p
)
4506 /* Make sure that the glyphs of the ellipsis will get
4507 correct `charpos' values. If we would not update
4508 it->position here, the glyphs would belong to the
4509 last visible character _before_ the invisible
4510 text, which confuses `set_cursor_from_row'.
4512 We use the last invisible position instead of the
4513 first because this way the cursor is always drawn on
4514 the first "." of the ellipsis, whenever PT is inside
4515 the invisible text. Otherwise the cursor would be
4516 placed _after_ the ellipsis when the point is after the
4517 first invisible character. */
4518 if (!STRINGP (it
->object
))
4520 it
->position
.charpos
= newpos
- 1;
4521 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4525 /* If there are before-strings at the start of invisible
4526 text, and the text is invisible because of a text
4527 property, arrange to show before-strings because 20.x did
4528 it that way. (If the text is invisible because of an
4529 overlay property instead of a text property, this is
4530 already handled in the overlay code.) */
4532 && get_overlay_strings (it
, it
->stop_charpos
))
4534 handled
= HANDLED_RECOMPUTE_PROPS
;
4537 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4538 /* The call to get_overlay_strings above recomputes
4539 it->stop_charpos, but it only considers changes
4540 in properties and overlays beyond iterator's
4541 current position. This causes us to miss changes
4542 that happen exactly where the invisible property
4543 ended. So we play it safe here and force the
4544 iterator to check for potential stop positions
4545 immediately after the invisible text. Note that
4546 if get_overlay_strings returns true, it
4547 normally also pushed the iterator stack, so we
4548 need to update the stop position in the slot
4549 below the current one. */
4550 it
->stack
[it
->sp
- 1].stop_charpos
4551 = CHARPOS (it
->stack
[it
->sp
- 1].current
.pos
);
4554 else if (display_ellipsis_p
)
4556 it
->ellipsis_p
= true;
4557 /* Let the ellipsis display before
4558 considering any properties of the following char.
4559 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4560 handled
= HANDLED_RETURN
;
4569 /* Make iterator IT return `...' next.
4570 Replaces LEN characters from buffer. */
4573 setup_for_ellipsis (struct it
*it
, int len
)
4575 /* Use the display table definition for `...'. Invalid glyphs
4576 will be handled by the method returning elements from dpvec. */
4577 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4579 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4580 it
->dpvec
= v
->contents
;
4581 it
->dpend
= v
->contents
+ v
->header
.size
;
4585 /* Default `...'. */
4586 it
->dpvec
= default_invis_vector
;
4587 it
->dpend
= default_invis_vector
+ 3;
4590 it
->dpvec_char_len
= len
;
4591 it
->current
.dpvec_index
= 0;
4592 it
->dpvec_face_id
= -1;
4594 /* Use IT->saved_face_id for the ellipsis, so that it has the same
4595 face as the preceding text. IT->saved_face_id was set in
4596 handle_stop to the face of the preceding character, and will be
4597 different from IT->face_id only if the invisible text skipped in
4598 handle_invisible_prop has some non-default face on its first
4599 character. We thus ignore the face of the invisible text when we
4600 display the ellipsis. IT's face is restored in set_iterator_to_next. */
4601 if (it
->saved_face_id
>= 0)
4602 it
->face_id
= it
->saved_face_id
;
4604 /* If the ellipsis represents buffer text, it means we advanced in
4605 the buffer, so we should no longer ignore overlay strings. */
4606 if (it
->method
== GET_FROM_BUFFER
)
4607 it
->ignore_overlay_strings_at_pos_p
= false;
4609 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4610 it
->ellipsis_p
= true;
4615 /***********************************************************************
4617 ***********************************************************************/
4619 /* Set up iterator IT from `display' property at its current position.
4620 Called from handle_stop.
4621 We return HANDLED_RETURN if some part of the display property
4622 overrides the display of the buffer text itself.
4623 Otherwise we return HANDLED_NORMALLY. */
4625 static enum prop_handled
4626 handle_display_prop (struct it
*it
)
4628 Lisp_Object propval
, object
, overlay
;
4629 struct text_pos
*position
;
4631 /* Nonzero if some property replaces the display of the text itself. */
4632 int display_replaced
= 0;
4634 if (STRINGP (it
->string
))
4636 object
= it
->string
;
4637 position
= &it
->current
.string_pos
;
4638 bufpos
= CHARPOS (it
->current
.pos
);
4642 XSETWINDOW (object
, it
->w
);
4643 position
= &it
->current
.pos
;
4644 bufpos
= CHARPOS (*position
);
4647 /* Reset those iterator values set from display property values. */
4648 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4649 it
->space_width
= Qnil
;
4650 it
->font_height
= Qnil
;
4653 /* We don't support recursive `display' properties, i.e. string
4654 values that have a string `display' property, that have a string
4655 `display' property etc. */
4656 if (!it
->string_from_display_prop_p
)
4657 it
->area
= TEXT_AREA
;
4659 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4660 Qdisplay
, object
, &overlay
);
4662 return HANDLED_NORMALLY
;
4663 /* Now OVERLAY is the overlay that gave us this property, or nil
4664 if it was a text property. */
4666 if (!STRINGP (it
->string
))
4667 object
= it
->w
->contents
;
4669 display_replaced
= handle_display_spec (it
, propval
, object
, overlay
,
4671 FRAME_WINDOW_P (it
->f
));
4672 return display_replaced
!= 0 ? HANDLED_RETURN
: HANDLED_NORMALLY
;
4675 /* Subroutine of handle_display_prop. Returns non-zero if the display
4676 specification in SPEC is a replacing specification, i.e. it would
4677 replace the text covered by `display' property with something else,
4678 such as an image or a display string. If SPEC includes any kind or
4679 `(space ...) specification, the value is 2; this is used by
4680 compute_display_string_pos, which see.
4682 See handle_single_display_spec for documentation of arguments.
4683 FRAME_WINDOW_P is true if the window being redisplayed is on a
4684 GUI frame; this argument is used only if IT is NULL, see below.
4686 IT can be NULL, if this is called by the bidi reordering code
4687 through compute_display_string_pos, which see. In that case, this
4688 function only examines SPEC, but does not otherwise "handle" it, in
4689 the sense that it doesn't set up members of IT from the display
4692 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4693 Lisp_Object overlay
, struct text_pos
*position
,
4694 ptrdiff_t bufpos
, bool frame_window_p
)
4699 /* Simple specifications. */
4700 && !EQ (XCAR (spec
), Qimage
)
4701 #ifdef HAVE_XWIDGETS
4702 && !EQ (XCAR (spec
), Qxwidget
)
4704 && !EQ (XCAR (spec
), Qspace
)
4705 && !EQ (XCAR (spec
), Qwhen
)
4706 && !EQ (XCAR (spec
), Qslice
)
4707 && !EQ (XCAR (spec
), Qspace_width
)
4708 && !EQ (XCAR (spec
), Qheight
)
4709 && !EQ (XCAR (spec
), Qraise
)
4710 /* Marginal area specifications. */
4711 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4712 && !EQ (XCAR (spec
), Qleft_fringe
)
4713 && !EQ (XCAR (spec
), Qright_fringe
)
4714 && !NILP (XCAR (spec
)))
4716 for (; CONSP (spec
); spec
= XCDR (spec
))
4718 int rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4719 overlay
, position
, bufpos
,
4720 replacing
, frame_window_p
);
4724 /* If some text in a string is replaced, `position' no
4725 longer points to the position of `object'. */
4726 if (!it
|| STRINGP (object
))
4731 else if (VECTORP (spec
))
4734 for (i
= 0; i
< ASIZE (spec
); ++i
)
4736 int rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4737 overlay
, position
, bufpos
,
4738 replacing
, frame_window_p
);
4742 /* If some text in a string is replaced, `position' no
4743 longer points to the position of `object'. */
4744 if (!it
|| STRINGP (object
))
4750 replacing
= handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4751 bufpos
, 0, frame_window_p
);
4755 /* Value is the position of the end of the `display' property starting
4756 at START_POS in OBJECT. */
4758 static struct text_pos
4759 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4762 struct text_pos end_pos
;
4764 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4765 Qdisplay
, object
, Qnil
);
4766 CHARPOS (end_pos
) = XFASTINT (end
);
4767 if (STRINGP (object
))
4768 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4770 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4776 /* Set up IT from a single `display' property specification SPEC. OBJECT
4777 is the object in which the `display' property was found. *POSITION
4778 is the position in OBJECT at which the `display' property was found.
4779 BUFPOS is the buffer position of OBJECT (different from POSITION if
4780 OBJECT is not a buffer). DISPLAY_REPLACED non-zero means that we
4781 previously saw a display specification which already replaced text
4782 display with something else, for example an image; we ignore such
4783 properties after the first one has been processed.
4785 OVERLAY is the overlay this `display' property came from,
4786 or nil if it was a text property.
4788 If SPEC is a `space' or `image' specification, and in some other
4789 cases too, set *POSITION to the position where the `display'
4792 If IT is NULL, only examine the property specification in SPEC, but
4793 don't set up IT. In that case, FRAME_WINDOW_P means SPEC
4794 is intended to be displayed in a window on a GUI frame.
4796 Value is non-zero if something was found which replaces the display
4797 of buffer or string text. */
4800 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4801 Lisp_Object overlay
, struct text_pos
*position
,
4802 ptrdiff_t bufpos
, int display_replaced
,
4803 bool frame_window_p
)
4806 Lisp_Object location
, value
;
4807 struct text_pos start_pos
= *position
;
4809 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4810 If the result is non-nil, use VALUE instead of SPEC. */
4812 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4821 if (!NILP (form
) && !EQ (form
, Qt
))
4823 ptrdiff_t count
= SPECPDL_INDEX ();
4825 /* Bind `object' to the object having the `display' property, a
4826 buffer or string. Bind `position' to the position in the
4827 object where the property was found, and `buffer-position'
4828 to the current position in the buffer. */
4831 XSETBUFFER (object
, current_buffer
);
4832 specbind (Qobject
, object
);
4833 specbind (Qposition
, make_number (CHARPOS (*position
)));
4834 specbind (Qbuffer_position
, make_number (bufpos
));
4835 form
= safe_eval (form
);
4836 unbind_to (count
, Qnil
);
4842 /* Handle `(height HEIGHT)' specifications. */
4844 && EQ (XCAR (spec
), Qheight
)
4845 && CONSP (XCDR (spec
)))
4849 if (!FRAME_WINDOW_P (it
->f
))
4852 it
->font_height
= XCAR (XCDR (spec
));
4853 if (!NILP (it
->font_height
))
4855 int new_height
= -1;
4857 if (CONSP (it
->font_height
)
4858 && (EQ (XCAR (it
->font_height
), Qplus
)
4859 || EQ (XCAR (it
->font_height
), Qminus
))
4860 && CONSP (XCDR (it
->font_height
))
4861 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4863 /* `(+ N)' or `(- N)' where N is an integer. */
4864 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4865 if (EQ (XCAR (it
->font_height
), Qplus
))
4867 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4869 else if (FUNCTIONP (it
->font_height
))
4871 /* Call function with current height as argument.
4872 Value is the new height. */
4873 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4875 height
= safe_call1 (it
->font_height
,
4876 face
->lface
[LFACE_HEIGHT_INDEX
]);
4877 if (NUMBERP (height
))
4878 new_height
= XFLOATINT (height
);
4880 else if (NUMBERP (it
->font_height
))
4882 /* Value is a multiple of the canonical char height. */
4885 f
= FACE_FROM_ID (it
->f
,
4886 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4887 new_height
= (XFLOATINT (it
->font_height
)
4888 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4892 /* Evaluate IT->font_height with `height' bound to the
4893 current specified height to get the new height. */
4894 ptrdiff_t count
= SPECPDL_INDEX ();
4895 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4897 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4898 value
= safe_eval (it
->font_height
);
4899 unbind_to (count
, Qnil
);
4901 if (NUMBERP (value
))
4902 new_height
= XFLOATINT (value
);
4906 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4913 /* Handle `(space-width WIDTH)'. */
4915 && EQ (XCAR (spec
), Qspace_width
)
4916 && CONSP (XCDR (spec
)))
4920 if (!FRAME_WINDOW_P (it
->f
))
4923 value
= XCAR (XCDR (spec
));
4924 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4925 it
->space_width
= value
;
4931 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4933 && EQ (XCAR (spec
), Qslice
))
4939 if (!FRAME_WINDOW_P (it
->f
))
4942 if (tem
= XCDR (spec
), CONSP (tem
))
4944 it
->slice
.x
= XCAR (tem
);
4945 if (tem
= XCDR (tem
), CONSP (tem
))
4947 it
->slice
.y
= XCAR (tem
);
4948 if (tem
= XCDR (tem
), CONSP (tem
))
4950 it
->slice
.width
= XCAR (tem
);
4951 if (tem
= XCDR (tem
), CONSP (tem
))
4952 it
->slice
.height
= XCAR (tem
);
4961 /* Handle `(raise FACTOR)'. */
4963 && EQ (XCAR (spec
), Qraise
)
4964 && CONSP (XCDR (spec
)))
4968 if (!FRAME_WINDOW_P (it
->f
))
4971 #ifdef HAVE_WINDOW_SYSTEM
4972 value
= XCAR (XCDR (spec
));
4973 if (NUMBERP (value
))
4975 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4976 it
->voffset
= - (XFLOATINT (value
)
4977 * (normal_char_height (face
->font
, -1)));
4979 #endif /* HAVE_WINDOW_SYSTEM */
4985 /* Don't handle the other kinds of display specifications
4986 inside a string that we got from a `display' property. */
4987 if (it
&& it
->string_from_display_prop_p
)
4990 /* Characters having this form of property are not displayed, so
4991 we have to find the end of the property. */
4994 start_pos
= *position
;
4995 *position
= display_prop_end (it
, object
, start_pos
);
4996 /* If the display property comes from an overlay, don't consider
4997 any potential stop_charpos values before the end of that
4998 overlay. Since display_prop_end will happily find another
4999 'display' property coming from some other overlay or text
5000 property on buffer positions before this overlay's end, we
5001 need to ignore them, or else we risk displaying this
5002 overlay's display string/image twice. */
5003 if (!NILP (overlay
))
5005 ptrdiff_t ovendpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5007 if (ovendpos
> CHARPOS (*position
))
5008 SET_TEXT_POS (*position
, ovendpos
, CHAR_TO_BYTE (ovendpos
));
5013 /* Stop the scan at that end position--we assume that all
5014 text properties change there. */
5016 it
->stop_charpos
= position
->charpos
;
5018 /* Handle `(left-fringe BITMAP [FACE])'
5019 and `(right-fringe BITMAP [FACE])'. */
5021 && (EQ (XCAR (spec
), Qleft_fringe
)
5022 || EQ (XCAR (spec
), Qright_fringe
))
5023 && CONSP (XCDR (spec
)))
5027 if (!FRAME_WINDOW_P (it
->f
))
5028 /* If we return here, POSITION has been advanced
5029 across the text with this property. */
5031 /* Synchronize the bidi iterator with POSITION. This is
5032 needed because we are not going to push the iterator
5033 on behalf of this display property, so there will be
5034 no pop_it call to do this synchronization for us. */
5037 it
->position
= *position
;
5038 iterate_out_of_display_property (it
);
5039 *position
= it
->position
;
5044 else if (!frame_window_p
)
5047 #ifdef HAVE_WINDOW_SYSTEM
5048 value
= XCAR (XCDR (spec
));
5049 int fringe_bitmap
= SYMBOLP (value
) ? lookup_fringe_bitmap (value
) : 0;
5050 if (! fringe_bitmap
)
5051 /* If we return here, POSITION has been advanced
5052 across the text with this property. */
5054 if (it
&& it
->bidi_p
)
5056 it
->position
= *position
;
5057 iterate_out_of_display_property (it
);
5058 *position
= it
->position
;
5065 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
5067 if (CONSP (XCDR (XCDR (spec
))))
5069 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
5070 int face_id2
= lookup_derived_face (it
->f
, face_name
,
5071 FRINGE_FACE_ID
, false);
5076 /* Save current settings of IT so that we can restore them
5077 when we are finished with the glyph property value. */
5078 push_it (it
, position
);
5080 it
->area
= TEXT_AREA
;
5081 it
->what
= IT_IMAGE
;
5082 it
->image_id
= -1; /* no image */
5083 it
->position
= start_pos
;
5084 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5085 it
->method
= GET_FROM_IMAGE
;
5086 it
->from_overlay
= Qnil
;
5087 it
->face_id
= face_id
;
5088 it
->from_disp_prop_p
= true;
5090 /* Say that we haven't consumed the characters with
5091 `display' property yet. The call to pop_it in
5092 set_iterator_to_next will clean this up. */
5093 *position
= start_pos
;
5095 if (EQ (XCAR (spec
), Qleft_fringe
))
5097 it
->left_user_fringe_bitmap
= fringe_bitmap
;
5098 it
->left_user_fringe_face_id
= face_id
;
5102 it
->right_user_fringe_bitmap
= fringe_bitmap
;
5103 it
->right_user_fringe_face_id
= face_id
;
5106 #endif /* HAVE_WINDOW_SYSTEM */
5110 /* Prepare to handle `((margin left-margin) ...)',
5111 `((margin right-margin) ...)' and `((margin nil) ...)'
5112 prefixes for display specifications. */
5113 location
= Qunbound
;
5114 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5118 value
= XCDR (spec
);
5120 value
= XCAR (value
);
5123 if (EQ (XCAR (tem
), Qmargin
)
5124 && (tem
= XCDR (tem
),
5125 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5127 || EQ (tem
, Qleft_margin
)
5128 || EQ (tem
, Qright_margin
))))
5132 if (EQ (location
, Qunbound
))
5138 /* After this point, VALUE is the property after any
5139 margin prefix has been stripped. It must be a string,
5140 an image specification, or `(space ...)'.
5142 LOCATION specifies where to display: `left-margin',
5143 `right-margin' or nil. */
5145 bool valid_p
= (STRINGP (value
)
5146 #ifdef HAVE_WINDOW_SYSTEM
5147 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5148 && valid_image_p (value
))
5149 #endif /* not HAVE_WINDOW_SYSTEM */
5150 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5151 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5152 && valid_xwidget_spec_p (value
)));
5154 if (valid_p
&& display_replaced
== 0)
5160 /* Callers need to know whether the display spec is any kind
5161 of `(space ...)' spec that is about to affect text-area
5163 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5168 /* Save current settings of IT so that we can restore them
5169 when we are finished with the glyph property value. */
5170 push_it (it
, position
);
5171 it
->from_overlay
= overlay
;
5172 it
->from_disp_prop_p
= true;
5174 if (NILP (location
))
5175 it
->area
= TEXT_AREA
;
5176 else if (EQ (location
, Qleft_margin
))
5177 it
->area
= LEFT_MARGIN_AREA
;
5179 it
->area
= RIGHT_MARGIN_AREA
;
5181 if (STRINGP (value
))
5184 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5185 it
->current
.overlay_string_index
= -1;
5186 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5187 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5188 it
->method
= GET_FROM_STRING
;
5189 it
->stop_charpos
= 0;
5191 it
->base_level_stop
= 0;
5192 it
->string_from_display_prop_p
= true;
5193 /* Say that we haven't consumed the characters with
5194 `display' property yet. The call to pop_it in
5195 set_iterator_to_next will clean this up. */
5196 if (BUFFERP (object
))
5197 *position
= start_pos
;
5199 /* Force paragraph direction to be that of the parent
5200 object. If the parent object's paragraph direction is
5201 not yet determined, default to L2R. */
5202 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5203 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5205 it
->paragraph_embedding
= L2R
;
5207 /* Set up the bidi iterator for this display string. */
5210 it
->bidi_it
.string
.lstring
= it
->string
;
5211 it
->bidi_it
.string
.s
= NULL
;
5212 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5213 it
->bidi_it
.string
.bufpos
= bufpos
;
5214 it
->bidi_it
.string
.from_disp_str
= true;
5215 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5216 it
->bidi_it
.w
= it
->w
;
5217 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5220 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5222 it
->method
= GET_FROM_STRETCH
;
5224 *position
= it
->position
= start_pos
;
5225 retval
= 1 + (it
->area
== TEXT_AREA
);
5227 else if (valid_xwidget_spec_p (value
))
5229 it
->what
= IT_XWIDGET
;
5230 it
->method
= GET_FROM_XWIDGET
;
5231 it
->position
= start_pos
;
5232 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5233 *position
= start_pos
;
5234 it
->xwidget
= lookup_xwidget (value
);
5236 #ifdef HAVE_WINDOW_SYSTEM
5239 it
->what
= IT_IMAGE
;
5240 it
->image_id
= lookup_image (it
->f
, value
);
5241 it
->position
= start_pos
;
5242 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5243 it
->method
= GET_FROM_IMAGE
;
5245 /* Say that we haven't consumed the characters with
5246 `display' property yet. The call to pop_it in
5247 set_iterator_to_next will clean this up. */
5248 *position
= start_pos
;
5250 #endif /* HAVE_WINDOW_SYSTEM */
5255 /* Invalid property or property not supported. Restore
5256 POSITION to what it was before. */
5257 *position
= start_pos
;
5261 /* Check if PROP is a display property value whose text should be
5262 treated as intangible. OVERLAY is the overlay from which PROP
5263 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5264 specify the buffer position covered by PROP. */
5267 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5268 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5270 bool frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5271 struct text_pos position
;
5273 SET_TEXT_POS (position
, charpos
, bytepos
);
5274 return (handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5275 &position
, charpos
, frame_window_p
)
5280 /* Return true if PROP is a display sub-property value containing STRING.
5282 Implementation note: this and the following function are really
5283 special cases of handle_display_spec and
5284 handle_single_display_spec, and should ideally use the same code.
5285 Until they do, these two pairs must be consistent and must be
5286 modified in sync. */
5289 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5291 if (EQ (string
, prop
))
5294 /* Skip over `when FORM'. */
5295 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5300 /* Actually, the condition following `when' should be eval'ed,
5301 like handle_single_display_spec does, and we should return
5302 false if it evaluates to nil. However, this function is
5303 called only when the buffer was already displayed and some
5304 glyph in the glyph matrix was found to come from a display
5305 string. Therefore, the condition was already evaluated, and
5306 the result was non-nil, otherwise the display string wouldn't
5307 have been displayed and we would have never been called for
5308 this property. Thus, we can skip the evaluation and assume
5309 its result is non-nil. */
5314 /* Skip over `margin LOCATION'. */
5315 if (EQ (XCAR (prop
), Qmargin
))
5326 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5330 /* Return true if STRING appears in the `display' property PROP. */
5333 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5336 && !EQ (XCAR (prop
), Qwhen
)
5337 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5339 /* A list of sub-properties. */
5340 while (CONSP (prop
))
5342 if (single_display_spec_string_p (XCAR (prop
), string
))
5347 else if (VECTORP (prop
))
5349 /* A vector of sub-properties. */
5351 for (i
= 0; i
< ASIZE (prop
); ++i
)
5352 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5356 return single_display_spec_string_p (prop
, string
);
5361 /* Look for STRING in overlays and text properties in the current
5362 buffer, between character positions FROM and TO (excluding TO).
5363 BACK_P means look back (in this case, TO is supposed to be
5365 Value is the first character position where STRING was found, or
5366 zero if it wasn't found before hitting TO.
5368 This function may only use code that doesn't eval because it is
5369 called asynchronously from note_mouse_highlight. */
5372 string_buffer_position_lim (Lisp_Object string
,
5373 ptrdiff_t from
, ptrdiff_t to
, bool back_p
)
5375 Lisp_Object limit
, prop
, pos
;
5378 pos
= make_number (max (from
, BEGV
));
5380 if (!back_p
) /* looking forward */
5382 limit
= make_number (min (to
, ZV
));
5383 while (!found
&& !EQ (pos
, limit
))
5385 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5386 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5389 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5393 else /* looking back */
5395 limit
= make_number (max (to
, BEGV
));
5396 while (!found
&& !EQ (pos
, limit
))
5398 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5399 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5402 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5407 return found
? XINT (pos
) : 0;
5410 /* Determine which buffer position in current buffer STRING comes from.
5411 AROUND_CHARPOS is an approximate position where it could come from.
5412 Value is the buffer position or 0 if it couldn't be determined.
5414 This function is necessary because we don't record buffer positions
5415 in glyphs generated from strings (to keep struct glyph small).
5416 This function may only use code that doesn't eval because it is
5417 called asynchronously from note_mouse_highlight. */
5420 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5422 const int MAX_DISTANCE
= 1000;
5423 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5424 around_charpos
+ MAX_DISTANCE
,
5428 found
= string_buffer_position_lim (string
, around_charpos
,
5429 around_charpos
- MAX_DISTANCE
, true);
5435 /***********************************************************************
5436 `composition' property
5437 ***********************************************************************/
5439 /* Set up iterator IT from `composition' property at its current
5440 position. Called from handle_stop. */
5442 static enum prop_handled
5443 handle_composition_prop (struct it
*it
)
5445 Lisp_Object prop
, string
;
5446 ptrdiff_t pos
, pos_byte
, start
, end
;
5448 if (STRINGP (it
->string
))
5452 pos
= IT_STRING_CHARPOS (*it
);
5453 pos_byte
= IT_STRING_BYTEPOS (*it
);
5454 string
= it
->string
;
5455 s
= SDATA (string
) + pos_byte
;
5456 it
->c
= STRING_CHAR (s
);
5460 pos
= IT_CHARPOS (*it
);
5461 pos_byte
= IT_BYTEPOS (*it
);
5463 it
->c
= FETCH_CHAR (pos_byte
);
5466 /* If there's a valid composition and point is not inside of the
5467 composition (in the case that the composition is from the current
5468 buffer), draw a glyph composed from the composition components. */
5469 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5470 && composition_valid_p (start
, end
, prop
)
5471 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5474 /* As we can't handle this situation (perhaps font-lock added
5475 a new composition), we just return here hoping that next
5476 redisplay will detect this composition much earlier. */
5477 return HANDLED_NORMALLY
;
5480 if (STRINGP (it
->string
))
5481 pos_byte
= string_char_to_byte (it
->string
, start
);
5483 pos_byte
= CHAR_TO_BYTE (start
);
5485 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5488 if (it
->cmp_it
.id
>= 0)
5491 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5492 it
->cmp_it
.nglyphs
= -1;
5496 return HANDLED_NORMALLY
;
5501 /***********************************************************************
5503 ***********************************************************************/
5505 /* The following structure is used to record overlay strings for
5506 later sorting in load_overlay_strings. */
5508 struct overlay_entry
5510 Lisp_Object overlay
;
5513 bool after_string_p
;
5517 /* Set up iterator IT from overlay strings at its current position.
5518 Called from handle_stop. */
5520 static enum prop_handled
5521 handle_overlay_change (struct it
*it
)
5523 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5524 return HANDLED_RECOMPUTE_PROPS
;
5526 return HANDLED_NORMALLY
;
5530 /* Set up the next overlay string for delivery by IT, if there is an
5531 overlay string to deliver. Called by set_iterator_to_next when the
5532 end of the current overlay string is reached. If there are more
5533 overlay strings to display, IT->string and
5534 IT->current.overlay_string_index are set appropriately here.
5535 Otherwise IT->string is set to nil. */
5538 next_overlay_string (struct it
*it
)
5540 ++it
->current
.overlay_string_index
;
5541 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5543 /* No more overlay strings. Restore IT's settings to what
5544 they were before overlay strings were processed, and
5545 continue to deliver from current_buffer. */
5547 it
->ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
5550 || (NILP (it
->string
)
5551 && it
->method
== GET_FROM_BUFFER
5552 && it
->stop_charpos
>= BEGV
5553 && it
->stop_charpos
<= it
->end_charpos
));
5554 it
->current
.overlay_string_index
= -1;
5555 it
->n_overlay_strings
= 0;
5556 /* If there's an empty display string on the stack, pop the
5557 stack, to resync the bidi iterator with IT's position. Such
5558 empty strings are pushed onto the stack in
5559 get_overlay_strings_1. */
5560 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5563 /* Since we've exhausted overlay strings at this buffer
5564 position, set the flag to ignore overlays until we move to
5565 another position. The flag is reset in
5566 next_element_from_buffer. */
5567 it
->ignore_overlay_strings_at_pos_p
= true;
5569 /* If we're at the end of the buffer, record that we have
5570 processed the overlay strings there already, so that
5571 next_element_from_buffer doesn't try it again. */
5572 if (NILP (it
->string
)
5573 && IT_CHARPOS (*it
) >= it
->end_charpos
5574 && it
->overlay_strings_charpos
>= it
->end_charpos
)
5575 it
->overlay_strings_at_end_processed_p
= true;
5576 /* Note: we reset overlay_strings_charpos only here, to make
5577 sure the just-processed overlays were indeed at EOB.
5578 Otherwise, overlays on text with invisible text property,
5579 which are processed with IT's position past the invisible
5580 text, might fool us into thinking the overlays at EOB were
5581 already processed (linum-mode can cause this, for
5583 it
->overlay_strings_charpos
= -1;
5587 /* There are more overlay strings to process. If
5588 IT->current.overlay_string_index has advanced to a position
5589 where we must load IT->overlay_strings with more strings, do
5590 it. We must load at the IT->overlay_strings_charpos where
5591 IT->n_overlay_strings was originally computed; when invisible
5592 text is present, this might not be IT_CHARPOS (Bug#7016). */
5593 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5595 if (it
->current
.overlay_string_index
&& i
== 0)
5596 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5598 /* Initialize IT to deliver display elements from the overlay
5600 it
->string
= it
->overlay_strings
[i
];
5601 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5602 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5603 it
->method
= GET_FROM_STRING
;
5604 it
->stop_charpos
= 0;
5605 it
->end_charpos
= SCHARS (it
->string
);
5606 if (it
->cmp_it
.stop_pos
>= 0)
5607 it
->cmp_it
.stop_pos
= 0;
5609 it
->base_level_stop
= 0;
5611 /* Set up the bidi iterator for this overlay string. */
5614 it
->bidi_it
.string
.lstring
= it
->string
;
5615 it
->bidi_it
.string
.s
= NULL
;
5616 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5617 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5618 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5619 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5620 it
->bidi_it
.w
= it
->w
;
5621 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5629 /* Compare two overlay_entry structures E1 and E2. Used as a
5630 comparison function for qsort in load_overlay_strings. Overlay
5631 strings for the same position are sorted so that
5633 1. All after-strings come in front of before-strings, except
5634 when they come from the same overlay.
5636 2. Within after-strings, strings are sorted so that overlay strings
5637 from overlays with higher priorities come first.
5639 2. Within before-strings, strings are sorted so that overlay
5640 strings from overlays with higher priorities come last.
5642 Value is analogous to strcmp. */
5646 compare_overlay_entries (const void *e1
, const void *e2
)
5648 struct overlay_entry
const *entry1
= e1
;
5649 struct overlay_entry
const *entry2
= e2
;
5652 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5654 /* Let after-strings appear in front of before-strings if
5655 they come from different overlays. */
5656 if (EQ (entry1
->overlay
, entry2
->overlay
))
5657 result
= entry1
->after_string_p
? 1 : -1;
5659 result
= entry1
->after_string_p
? -1 : 1;
5661 else if (entry1
->priority
!= entry2
->priority
)
5663 if (entry1
->after_string_p
)
5664 /* After-strings sorted in order of decreasing priority. */
5665 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5667 /* Before-strings sorted in order of increasing priority. */
5668 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5677 /* Load the vector IT->overlay_strings with overlay strings from IT's
5678 current buffer position, or from CHARPOS if that is > 0. Set
5679 IT->n_overlays to the total number of overlay strings found.
5681 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5682 a time. On entry into load_overlay_strings,
5683 IT->current.overlay_string_index gives the number of overlay
5684 strings that have already been loaded by previous calls to this
5687 IT->add_overlay_start contains an additional overlay start
5688 position to consider for taking overlay strings from, if non-zero.
5689 This position comes into play when the overlay has an `invisible'
5690 property, and both before and after-strings. When we've skipped to
5691 the end of the overlay, because of its `invisible' property, we
5692 nevertheless want its before-string to appear.
5693 IT->add_overlay_start will contain the overlay start position
5696 Overlay strings are sorted so that after-string strings come in
5697 front of before-string strings. Within before and after-strings,
5698 strings are sorted by overlay priority. See also function
5699 compare_overlay_entries. */
5702 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5704 Lisp_Object overlay
, window
, str
, invisible
;
5705 struct Lisp_Overlay
*ov
;
5706 ptrdiff_t start
, end
;
5707 ptrdiff_t n
= 0, i
, j
;
5709 struct overlay_entry entriesbuf
[20];
5710 ptrdiff_t size
= ARRAYELTS (entriesbuf
);
5711 struct overlay_entry
*entries
= entriesbuf
;
5715 charpos
= IT_CHARPOS (*it
);
5717 /* Append the overlay string STRING of overlay OVERLAY to vector
5718 `entries' which has size `size' and currently contains `n'
5719 elements. AFTER_P means STRING is an after-string of
5721 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5724 Lisp_Object priority; \
5728 struct overlay_entry *old = entries; \
5729 SAFE_NALLOCA (entries, 2, size); \
5730 memcpy (entries, old, size * sizeof *entries); \
5734 entries[n].string = (STRING); \
5735 entries[n].overlay = (OVERLAY); \
5736 priority = Foverlay_get ((OVERLAY), Qpriority); \
5737 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5738 entries[n].after_string_p = (AFTER_P); \
5743 /* Process overlay before the overlay center. */
5744 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5746 XSETMISC (overlay
, ov
);
5747 eassert (OVERLAYP (overlay
));
5748 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5749 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5754 /* Skip this overlay if it doesn't start or end at IT's current
5756 if (end
!= charpos
&& start
!= charpos
)
5759 /* Skip this overlay if it doesn't apply to IT->w. */
5760 window
= Foverlay_get (overlay
, Qwindow
);
5761 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5764 /* If the text ``under'' the overlay is invisible, both before-
5765 and after-strings from this overlay are visible; start and
5766 end position are indistinguishable. */
5767 invisible
= Foverlay_get (overlay
, Qinvisible
);
5768 invis
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5770 /* If overlay has a non-empty before-string, record it. */
5771 if ((start
== charpos
|| (end
== charpos
&& invis
!= 0))
5772 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5774 RECORD_OVERLAY_STRING (overlay
, str
, false);
5776 /* If overlay has a non-empty after-string, record it. */
5777 if ((end
== charpos
|| (start
== charpos
&& invis
!= 0))
5778 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5780 RECORD_OVERLAY_STRING (overlay
, str
, true);
5783 /* Process overlays after the overlay center. */
5784 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5786 XSETMISC (overlay
, ov
);
5787 eassert (OVERLAYP (overlay
));
5788 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5789 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5791 if (start
> charpos
)
5794 /* Skip this overlay if it doesn't start or end at IT's current
5796 if (end
!= charpos
&& start
!= charpos
)
5799 /* Skip this overlay if it doesn't apply to IT->w. */
5800 window
= Foverlay_get (overlay
, Qwindow
);
5801 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5804 /* If the text ``under'' the overlay is invisible, it has a zero
5805 dimension, and both before- and after-strings apply. */
5806 invisible
= Foverlay_get (overlay
, Qinvisible
);
5807 invis
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5809 /* If overlay has a non-empty before-string, record it. */
5810 if ((start
== charpos
|| (end
== charpos
&& invis
!= 0))
5811 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5813 RECORD_OVERLAY_STRING (overlay
, str
, false);
5815 /* If overlay has a non-empty after-string, record it. */
5816 if ((end
== charpos
|| (start
== charpos
&& invis
!= 0))
5817 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5819 RECORD_OVERLAY_STRING (overlay
, str
, true);
5822 #undef RECORD_OVERLAY_STRING
5826 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5828 /* Record number of overlay strings, and where we computed it. */
5829 it
->n_overlay_strings
= n
;
5830 it
->overlay_strings_charpos
= charpos
;
5832 /* IT->current.overlay_string_index is the number of overlay strings
5833 that have already been consumed by IT. Copy some of the
5834 remaining overlay strings to IT->overlay_strings. */
5836 j
= it
->current
.overlay_string_index
;
5837 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5839 it
->overlay_strings
[i
] = entries
[j
].string
;
5840 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5848 /* Get the first chunk of overlay strings at IT's current buffer
5849 position, or at CHARPOS if that is > 0. Value is true if at
5850 least one overlay string was found. */
5853 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, bool compute_stop_p
)
5855 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5856 process. This fills IT->overlay_strings with strings, and sets
5857 IT->n_overlay_strings to the total number of strings to process.
5858 IT->pos.overlay_string_index has to be set temporarily to zero
5859 because load_overlay_strings needs this; it must be set to -1
5860 when no overlay strings are found because a zero value would
5861 indicate a position in the first overlay string. */
5862 it
->current
.overlay_string_index
= 0;
5863 load_overlay_strings (it
, charpos
);
5865 /* If we found overlay strings, set up IT to deliver display
5866 elements from the first one. Otherwise set up IT to deliver
5867 from current_buffer. */
5868 if (it
->n_overlay_strings
)
5870 /* Make sure we know settings in current_buffer, so that we can
5871 restore meaningful values when we're done with the overlay
5874 compute_stop_pos (it
);
5875 eassert (it
->face_id
>= 0);
5877 /* Save IT's settings. They are restored after all overlay
5878 strings have been processed. */
5879 eassert (!compute_stop_p
|| it
->sp
== 0);
5881 /* When called from handle_stop, there might be an empty display
5882 string loaded. In that case, don't bother saving it. But
5883 don't use this optimization with the bidi iterator, since we
5884 need the corresponding pop_it call to resync the bidi
5885 iterator's position with IT's position, after we are done
5886 with the overlay strings. (The corresponding call to pop_it
5887 in case of an empty display string is in
5888 next_overlay_string.) */
5890 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5893 /* Set up IT to deliver display elements from the first overlay
5895 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5896 it
->string
= it
->overlay_strings
[0];
5897 it
->from_overlay
= Qnil
;
5898 it
->stop_charpos
= 0;
5899 eassert (STRINGP (it
->string
));
5900 it
->end_charpos
= SCHARS (it
->string
);
5902 it
->base_level_stop
= 0;
5903 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5904 it
->method
= GET_FROM_STRING
;
5905 it
->from_disp_prop_p
= 0;
5907 /* Force paragraph direction to be that of the parent
5909 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5910 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5912 it
->paragraph_embedding
= L2R
;
5914 /* Set up the bidi iterator for this overlay string. */
5917 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5919 it
->bidi_it
.string
.lstring
= it
->string
;
5920 it
->bidi_it
.string
.s
= NULL
;
5921 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5922 it
->bidi_it
.string
.bufpos
= pos
;
5923 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5924 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5925 it
->bidi_it
.w
= it
->w
;
5926 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5931 it
->current
.overlay_string_index
= -1;
5936 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5939 it
->method
= GET_FROM_BUFFER
;
5941 get_overlay_strings_1 (it
, charpos
, true);
5945 /* Value is true if we found at least one overlay string. */
5946 return STRINGP (it
->string
);
5951 /***********************************************************************
5952 Saving and restoring state
5953 ***********************************************************************/
5955 /* Save current settings of IT on IT->stack. Called, for example,
5956 before setting up IT for an overlay string, to be able to restore
5957 IT's settings to what they were after the overlay string has been
5958 processed. If POSITION is non-NULL, it is the position to save on
5959 the stack instead of IT->position. */
5962 push_it (struct it
*it
, struct text_pos
*position
)
5964 struct iterator_stack_entry
*p
;
5966 eassert (it
->sp
< IT_STACK_SIZE
);
5967 p
= it
->stack
+ it
->sp
;
5969 p
->stop_charpos
= it
->stop_charpos
;
5970 p
->prev_stop
= it
->prev_stop
;
5971 p
->base_level_stop
= it
->base_level_stop
;
5972 p
->cmp_it
= it
->cmp_it
;
5973 eassert (it
->face_id
>= 0);
5974 p
->face_id
= it
->face_id
;
5975 p
->string
= it
->string
;
5976 p
->method
= it
->method
;
5977 p
->from_overlay
= it
->from_overlay
;
5980 case GET_FROM_IMAGE
:
5981 p
->u
.image
.object
= it
->object
;
5982 p
->u
.image
.image_id
= it
->image_id
;
5983 p
->u
.image
.slice
= it
->slice
;
5985 case GET_FROM_STRETCH
:
5986 p
->u
.stretch
.object
= it
->object
;
5988 case GET_FROM_XWIDGET
:
5989 p
->u
.xwidget
.object
= it
->object
;
5991 case GET_FROM_BUFFER
:
5992 case GET_FROM_DISPLAY_VECTOR
:
5993 case GET_FROM_STRING
:
5994 case GET_FROM_C_STRING
:
5999 p
->position
= position
? *position
: it
->position
;
6000 p
->current
= it
->current
;
6001 p
->end_charpos
= it
->end_charpos
;
6002 p
->string_nchars
= it
->string_nchars
;
6004 p
->multibyte_p
= it
->multibyte_p
;
6005 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
6006 p
->space_width
= it
->space_width
;
6007 p
->font_height
= it
->font_height
;
6008 p
->voffset
= it
->voffset
;
6009 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
6010 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
6011 p
->display_ellipsis_p
= false;
6012 p
->line_wrap
= it
->line_wrap
;
6013 p
->bidi_p
= it
->bidi_p
;
6014 p
->paragraph_embedding
= it
->paragraph_embedding
;
6015 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
6018 /* Save the state of the bidi iterator as well. */
6020 bidi_push_it (&it
->bidi_it
);
6024 iterate_out_of_display_property (struct it
*it
)
6026 bool buffer_p
= !STRINGP (it
->string
);
6027 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
6028 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
6030 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
6032 /* Maybe initialize paragraph direction. If we are at the beginning
6033 of a new paragraph, next_element_from_buffer may not have a
6034 chance to do that. */
6035 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
6036 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
6037 /* prev_stop can be zero, so check against BEGV as well. */
6038 while (it
->bidi_it
.charpos
>= bob
6039 && it
->prev_stop
<= it
->bidi_it
.charpos
6040 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
6041 && it
->bidi_it
.charpos
< eob
)
6042 bidi_move_to_visually_next (&it
->bidi_it
);
6043 /* Record the stop_pos we just crossed, for when we cross it
6045 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
6046 it
->prev_stop
= CHARPOS (it
->position
);
6047 /* If we ended up not where pop_it put us, resync IT's
6048 positional members with the bidi iterator. */
6049 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
6050 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
6052 it
->current
.pos
= it
->position
;
6054 it
->current
.string_pos
= it
->position
;
6057 /* Restore IT's settings from IT->stack. Called, for example, when no
6058 more overlay strings must be processed, and we return to delivering
6059 display elements from a buffer, or when the end of a string from a
6060 `display' property is reached and we return to delivering display
6061 elements from an overlay string, or from a buffer. */
6064 pop_it (struct it
*it
)
6066 struct iterator_stack_entry
*p
;
6067 bool from_display_prop
= it
->from_disp_prop_p
;
6068 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
6070 eassert (it
->sp
> 0);
6072 p
= it
->stack
+ it
->sp
;
6073 it
->stop_charpos
= p
->stop_charpos
;
6074 it
->prev_stop
= p
->prev_stop
;
6075 it
->base_level_stop
= p
->base_level_stop
;
6076 it
->cmp_it
= p
->cmp_it
;
6077 it
->face_id
= p
->face_id
;
6078 it
->current
= p
->current
;
6079 it
->position
= p
->position
;
6080 it
->string
= p
->string
;
6081 it
->from_overlay
= p
->from_overlay
;
6082 if (NILP (it
->string
))
6083 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
6084 it
->method
= p
->method
;
6087 case GET_FROM_IMAGE
:
6088 it
->image_id
= p
->u
.image
.image_id
;
6089 it
->object
= p
->u
.image
.object
;
6090 it
->slice
= p
->u
.image
.slice
;
6092 case GET_FROM_XWIDGET
:
6093 it
->object
= p
->u
.xwidget
.object
;
6095 case GET_FROM_STRETCH
:
6096 it
->object
= p
->u
.stretch
.object
;
6098 case GET_FROM_BUFFER
:
6099 it
->object
= it
->w
->contents
;
6101 case GET_FROM_STRING
:
6103 struct face
*face
= FACE_FROM_ID_OR_NULL (it
->f
, it
->face_id
);
6105 /* Restore the face_box_p flag, since it could have been
6106 overwritten by the face of the object that we just finished
6109 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
6110 it
->object
= it
->string
;
6113 case GET_FROM_DISPLAY_VECTOR
:
6115 it
->method
= GET_FROM_C_STRING
;
6116 else if (STRINGP (it
->string
))
6117 it
->method
= GET_FROM_STRING
;
6120 it
->method
= GET_FROM_BUFFER
;
6121 it
->object
= it
->w
->contents
;
6124 case GET_FROM_C_STRING
:
6129 it
->end_charpos
= p
->end_charpos
;
6130 it
->string_nchars
= p
->string_nchars
;
6132 it
->multibyte_p
= p
->multibyte_p
;
6133 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
6134 it
->space_width
= p
->space_width
;
6135 it
->font_height
= p
->font_height
;
6136 it
->voffset
= p
->voffset
;
6137 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
6138 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
6139 it
->line_wrap
= p
->line_wrap
;
6140 it
->bidi_p
= p
->bidi_p
;
6141 it
->paragraph_embedding
= p
->paragraph_embedding
;
6142 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
6145 bidi_pop_it (&it
->bidi_it
);
6146 /* Bidi-iterate until we get out of the portion of text, if any,
6147 covered by a `display' text property or by an overlay with
6148 `display' property. (We cannot just jump there, because the
6149 internal coherency of the bidi iterator state can not be
6150 preserved across such jumps.) We also must determine the
6151 paragraph base direction if the overlay we just processed is
6152 at the beginning of a new paragraph. */
6153 if (from_display_prop
6154 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
6155 iterate_out_of_display_property (it
);
6157 eassert ((BUFFERP (it
->object
)
6158 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
6159 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6160 || (STRINGP (it
->object
)
6161 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
6162 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6163 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6165 /* If we move the iterator over text covered by a display property
6166 to a new buffer position, any info about previously seen overlays
6167 is no longer valid. */
6168 if (from_display_prop
&& it
->sp
== 0 && CHARPOS (it
->position
) != prev_pos
)
6169 it
->ignore_overlay_strings_at_pos_p
= false;
6174 /***********************************************************************
6176 ***********************************************************************/
6178 /* Set IT's current position to the previous line start. */
6181 back_to_previous_line_start (struct it
*it
)
6183 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6186 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6190 /* Move IT to the next line start.
6192 Value is true if a newline was found. Set *SKIPPED_P to true if
6193 we skipped over part of the text (as opposed to moving the iterator
6194 continuously over the text). Otherwise, don't change the value
6197 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6198 iterator on the newline, if it was found.
6200 Newlines may come from buffer text, overlay strings, or strings
6201 displayed via the `display' property. That's the reason we can't
6202 simply use find_newline_no_quit.
6204 Note that this function may not skip over invisible text that is so
6205 because of text properties and immediately follows a newline. If
6206 it would, function reseat_at_next_visible_line_start, when called
6207 from set_iterator_to_next, would effectively make invisible
6208 characters following a newline part of the wrong glyph row, which
6209 leads to wrong cursor motion. */
6212 forward_to_next_line_start (struct it
*it
, bool *skipped_p
,
6213 struct bidi_it
*bidi_it_prev
)
6215 ptrdiff_t old_selective
;
6216 bool newline_found_p
= false;
6218 const int MAX_NEWLINE_DISTANCE
= 500;
6220 /* If already on a newline, just consume it to avoid unintended
6221 skipping over invisible text below. */
6222 if (it
->what
== IT_CHARACTER
6224 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6226 if (it
->bidi_p
&& bidi_it_prev
)
6227 *bidi_it_prev
= it
->bidi_it
;
6228 set_iterator_to_next (it
, false);
6233 /* Don't handle selective display in the following. It's (a)
6234 unnecessary because it's done by the caller, and (b) leads to an
6235 infinite recursion because next_element_from_ellipsis indirectly
6236 calls this function. */
6237 old_selective
= it
->selective
;
6240 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6241 from buffer text. */
6243 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6244 n
+= !STRINGP (it
->string
))
6246 if (!get_next_display_element (it
))
6248 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6249 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6250 *bidi_it_prev
= it
->bidi_it
;
6251 set_iterator_to_next (it
, false);
6254 /* If we didn't find a newline near enough, see if we can use a
6256 if (!newline_found_p
)
6258 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6259 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6263 eassert (!STRINGP (it
->string
));
6265 /* If there isn't any `display' property in sight, and no
6266 overlays, we can just use the position of the newline in
6268 if (it
->stop_charpos
>= limit
6269 || ((pos
= Fnext_single_property_change (make_number (start
),
6271 make_number (limit
)),
6273 && next_overlay_change (start
) == ZV
))
6277 IT_CHARPOS (*it
) = limit
;
6278 IT_BYTEPOS (*it
) = bytepos
;
6282 struct bidi_it bprev
;
6284 /* Help bidi.c avoid expensive searches for display
6285 properties and overlays, by telling it that there are
6286 none up to `limit'. */
6287 if (it
->bidi_it
.disp_pos
< limit
)
6289 it
->bidi_it
.disp_pos
= limit
;
6290 it
->bidi_it
.disp_prop
= 0;
6293 bprev
= it
->bidi_it
;
6294 bidi_move_to_visually_next (&it
->bidi_it
);
6295 } while (it
->bidi_it
.charpos
!= limit
);
6296 IT_CHARPOS (*it
) = limit
;
6297 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6299 *bidi_it_prev
= bprev
;
6301 *skipped_p
= newline_found_p
= true;
6305 while (get_next_display_element (it
)
6306 && !newline_found_p
)
6308 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6309 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6310 *bidi_it_prev
= it
->bidi_it
;
6311 set_iterator_to_next (it
, false);
6316 it
->selective
= old_selective
;
6317 return newline_found_p
;
6321 /* Set IT's current position to the previous visible line start. Skip
6322 invisible text that is so either due to text properties or due to
6323 selective display. Caution: this does not change IT->current_x and
6327 back_to_previous_visible_line_start (struct it
*it
)
6329 while (IT_CHARPOS (*it
) > BEGV
)
6331 back_to_previous_line_start (it
);
6333 if (IT_CHARPOS (*it
) <= BEGV
)
6336 /* If selective > 0, then lines indented more than its value are
6338 if (it
->selective
> 0
6339 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6343 /* Check the newline before point for invisibility. */
6346 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6347 Qinvisible
, it
->window
);
6348 if (TEXT_PROP_MEANS_INVISIBLE (prop
) != 0)
6352 if (IT_CHARPOS (*it
) <= BEGV
)
6357 void *it2data
= NULL
;
6360 Lisp_Object val
, overlay
;
6362 SAVE_IT (it2
, *it
, it2data
);
6364 /* If newline is part of a composition, continue from start of composition */
6365 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6366 && beg
< IT_CHARPOS (*it
))
6369 /* If newline is replaced by a display property, find start of overlay
6370 or interval and continue search from that point. */
6371 pos
= --IT_CHARPOS (it2
);
6374 bidi_unshelve_cache (NULL
, false);
6375 it2
.string_from_display_prop_p
= false;
6376 it2
.from_disp_prop_p
= false;
6377 if (handle_display_prop (&it2
) == HANDLED_RETURN
6378 && !NILP (val
= get_char_property_and_overlay
6379 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6380 && (OVERLAYP (overlay
)
6381 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6382 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6384 RESTORE_IT (it
, it
, it2data
);
6388 /* Newline is not replaced by anything -- so we are done. */
6389 RESTORE_IT (it
, it
, it2data
);
6395 IT_CHARPOS (*it
) = beg
;
6396 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6400 it
->continuation_lines_width
= 0;
6402 eassert (IT_CHARPOS (*it
) >= BEGV
);
6403 eassert (IT_CHARPOS (*it
) == BEGV
6404 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6409 /* Reseat iterator IT at the previous visible line start. Skip
6410 invisible text that is so either due to text properties or due to
6411 selective display. At the end, update IT's overlay information,
6412 face information etc. */
6415 reseat_at_previous_visible_line_start (struct it
*it
)
6417 back_to_previous_visible_line_start (it
);
6418 reseat (it
, it
->current
.pos
, true);
6423 /* Reseat iterator IT on the next visible line start in the current
6424 buffer. ON_NEWLINE_P means position IT on the newline
6425 preceding the line start. Skip over invisible text that is so
6426 because of selective display. Compute faces, overlays etc at the
6427 new position. Note that this function does not skip over text that
6428 is invisible because of text properties. */
6431 reseat_at_next_visible_line_start (struct it
*it
, bool on_newline_p
)
6433 bool skipped_p
= false;
6434 struct bidi_it bidi_it_prev
;
6435 bool newline_found_p
6436 = forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6438 /* Skip over lines that are invisible because they are indented
6439 more than the value of IT->selective. */
6440 if (it
->selective
> 0)
6441 while (IT_CHARPOS (*it
) < ZV
6442 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6445 eassert (IT_BYTEPOS (*it
) == BEGV
6446 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6448 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6451 /* Position on the newline if that's what's requested. */
6452 if (on_newline_p
&& newline_found_p
)
6454 if (STRINGP (it
->string
))
6456 if (IT_STRING_CHARPOS (*it
) > 0)
6460 --IT_STRING_CHARPOS (*it
);
6461 --IT_STRING_BYTEPOS (*it
);
6465 /* We need to restore the bidi iterator to the state
6466 it had on the newline, and resync the IT's
6467 position with that. */
6468 it
->bidi_it
= bidi_it_prev
;
6469 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6470 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6474 else if (IT_CHARPOS (*it
) > BEGV
)
6483 /* We need to restore the bidi iterator to the state it
6484 had on the newline and resync IT with that. */
6485 it
->bidi_it
= bidi_it_prev
;
6486 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6487 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6489 reseat (it
, it
->current
.pos
, false);
6493 reseat (it
, it
->current
.pos
, false);
6500 /***********************************************************************
6501 Changing an iterator's position
6502 ***********************************************************************/
6504 /* Change IT's current position to POS in current_buffer.
6505 If FORCE_P, always check for text properties at the new position.
6506 Otherwise, text properties are only looked up if POS >=
6507 IT->check_charpos of a property. */
6510 reseat (struct it
*it
, struct text_pos pos
, bool force_p
)
6512 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6514 reseat_1 (it
, pos
, false);
6516 /* Determine where to check text properties. Avoid doing it
6517 where possible because text property lookup is very expensive. */
6519 || CHARPOS (pos
) > it
->stop_charpos
6520 || CHARPOS (pos
) < original_pos
)
6524 /* For bidi iteration, we need to prime prev_stop and
6525 base_level_stop with our best estimations. */
6526 /* Implementation note: Of course, POS is not necessarily a
6527 stop position, so assigning prev_pos to it is a lie; we
6528 should have called compute_stop_backwards. However, if
6529 the current buffer does not include any R2L characters,
6530 that call would be a waste of cycles, because the
6531 iterator will never move back, and thus never cross this
6532 "fake" stop position. So we delay that backward search
6533 until the time we really need it, in next_element_from_buffer. */
6534 if (CHARPOS (pos
) != it
->prev_stop
)
6535 it
->prev_stop
= CHARPOS (pos
);
6536 if (CHARPOS (pos
) < it
->base_level_stop
)
6537 it
->base_level_stop
= 0; /* meaning it's unknown */
6543 it
->prev_stop
= it
->base_level_stop
= 0;
6552 /* Change IT's buffer position to POS. SET_STOP_P means set
6553 IT->stop_pos to POS, also. */
6556 reseat_1 (struct it
*it
, struct text_pos pos
, bool set_stop_p
)
6558 /* Don't call this function when scanning a C string. */
6559 eassert (it
->s
== NULL
);
6561 /* POS must be a reasonable value. */
6562 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6564 it
->current
.pos
= it
->position
= pos
;
6565 it
->end_charpos
= ZV
;
6567 it
->current
.dpvec_index
= -1;
6568 it
->current
.overlay_string_index
= -1;
6569 IT_STRING_CHARPOS (*it
) = -1;
6570 IT_STRING_BYTEPOS (*it
) = -1;
6572 it
->method
= GET_FROM_BUFFER
;
6573 it
->object
= it
->w
->contents
;
6574 it
->area
= TEXT_AREA
;
6575 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6577 it
->string_from_display_prop_p
= false;
6578 it
->string_from_prefix_prop_p
= false;
6580 it
->from_disp_prop_p
= false;
6581 it
->face_before_selective_p
= false;
6584 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6586 bidi_unshelve_cache (NULL
, false);
6587 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6588 it
->bidi_it
.string
.s
= NULL
;
6589 it
->bidi_it
.string
.lstring
= Qnil
;
6590 it
->bidi_it
.string
.bufpos
= 0;
6591 it
->bidi_it
.string
.from_disp_str
= false;
6592 it
->bidi_it
.string
.unibyte
= false;
6593 it
->bidi_it
.w
= it
->w
;
6598 it
->stop_charpos
= CHARPOS (pos
);
6599 it
->base_level_stop
= CHARPOS (pos
);
6601 /* This make the information stored in it->cmp_it invalidate. */
6606 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6607 If S is non-null, it is a C string to iterate over. Otherwise,
6608 STRING gives a Lisp string to iterate over.
6610 If PRECISION > 0, don't return more then PRECISION number of
6611 characters from the string.
6613 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6614 characters have been returned. FIELD_WIDTH < 0 means an infinite
6617 MULTIBYTE = 0 means disable processing of multibyte characters,
6618 MULTIBYTE > 0 means enable it,
6619 MULTIBYTE < 0 means use IT->multibyte_p.
6621 IT must be initialized via a prior call to init_iterator before
6622 calling this function. */
6625 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6626 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6629 /* No text property checks performed by default, but see below. */
6630 it
->stop_charpos
= -1;
6632 /* Set iterator position and end position. */
6633 memset (&it
->current
, 0, sizeof it
->current
);
6634 it
->current
.overlay_string_index
= -1;
6635 it
->current
.dpvec_index
= -1;
6636 eassert (charpos
>= 0);
6638 /* If STRING is specified, use its multibyteness, otherwise use the
6639 setting of MULTIBYTE, if specified. */
6641 it
->multibyte_p
= multibyte
> 0;
6643 /* Bidirectional reordering of strings is controlled by the default
6644 value of bidi-display-reordering. Don't try to reorder while
6645 loading loadup.el, as the necessary character property tables are
6646 not yet available. */
6648 !redisplay__inhibit_bidi
6649 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6653 eassert (STRINGP (string
));
6654 it
->string
= string
;
6656 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6657 it
->method
= GET_FROM_STRING
;
6658 it
->current
.string_pos
= string_pos (charpos
, string
);
6662 it
->bidi_it
.string
.lstring
= string
;
6663 it
->bidi_it
.string
.s
= NULL
;
6664 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6665 it
->bidi_it
.string
.bufpos
= 0;
6666 it
->bidi_it
.string
.from_disp_str
= false;
6667 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6668 it
->bidi_it
.w
= it
->w
;
6669 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6670 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6675 it
->s
= (const unsigned char *) s
;
6678 /* Note that we use IT->current.pos, not it->current.string_pos,
6679 for displaying C strings. */
6680 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6681 if (it
->multibyte_p
)
6683 it
->current
.pos
= c_string_pos (charpos
, s
, true);
6684 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, true);
6688 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6689 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6694 it
->bidi_it
.string
.lstring
= Qnil
;
6695 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6696 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6697 it
->bidi_it
.string
.bufpos
= 0;
6698 it
->bidi_it
.string
.from_disp_str
= false;
6699 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6700 it
->bidi_it
.w
= it
->w
;
6701 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6704 it
->method
= GET_FROM_C_STRING
;
6707 /* PRECISION > 0 means don't return more than PRECISION characters
6709 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6711 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6713 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6716 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6717 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6718 FIELD_WIDTH < 0 means infinite field width. This is useful for
6719 padding with `-' at the end of a mode line. */
6720 if (field_width
< 0)
6721 field_width
= INFINITY
;
6722 /* Implementation note: We deliberately don't enlarge
6723 it->bidi_it.string.schars here to fit it->end_charpos, because
6724 the bidi iterator cannot produce characters out of thin air. */
6725 if (field_width
> it
->end_charpos
- charpos
)
6726 it
->end_charpos
= charpos
+ field_width
;
6728 /* Use the standard display table for displaying strings. */
6729 if (DISP_TABLE_P (Vstandard_display_table
))
6730 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6732 it
->stop_charpos
= charpos
;
6733 it
->prev_stop
= charpos
;
6734 it
->base_level_stop
= 0;
6737 it
->bidi_it
.first_elt
= true;
6738 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6739 it
->bidi_it
.disp_pos
= -1;
6741 if (s
== NULL
&& it
->multibyte_p
)
6743 ptrdiff_t endpos
= SCHARS (it
->string
);
6744 if (endpos
> it
->end_charpos
)
6745 endpos
= it
->end_charpos
;
6746 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6754 /***********************************************************************
6756 ***********************************************************************/
6758 /* Map enum it_method value to corresponding next_element_from_* function. */
6760 typedef bool (*next_element_function
) (struct it
*);
6762 static next_element_function
const get_next_element
[NUM_IT_METHODS
] =
6764 next_element_from_buffer
,
6765 next_element_from_display_vector
,
6766 next_element_from_string
,
6767 next_element_from_c_string
,
6768 next_element_from_image
,
6769 next_element_from_stretch
,
6770 next_element_from_xwidget
,
6773 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6776 /* Return true iff a character at CHARPOS (and BYTEPOS) is composed
6777 (possibly with the following characters). */
6779 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6780 ((IT)->cmp_it.id >= 0 \
6781 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6782 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6783 END_CHARPOS, (IT)->w, \
6784 FACE_FROM_ID_OR_NULL ((IT)->f, \
6789 /* Lookup the char-table Vglyphless_char_display for character C (-1
6790 if we want information for no-font case), and return the display
6791 method symbol. By side-effect, update it->what and
6792 it->glyphless_method. This function is called from
6793 get_next_display_element for each character element, and from
6794 x_produce_glyphs when no suitable font was found. */
6797 lookup_glyphless_char_display (int c
, struct it
*it
)
6799 Lisp_Object glyphless_method
= Qnil
;
6801 if (CHAR_TABLE_P (Vglyphless_char_display
)
6802 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6806 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6807 if (CONSP (glyphless_method
))
6808 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6809 ? XCAR (glyphless_method
)
6810 : XCDR (glyphless_method
);
6813 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6817 if (NILP (glyphless_method
))
6820 /* The default is to display the character by a proper font. */
6822 /* The default for the no-font case is to display an empty box. */
6823 glyphless_method
= Qempty_box
;
6825 if (EQ (glyphless_method
, Qzero_width
))
6828 return glyphless_method
;
6829 /* This method can't be used for the no-font case. */
6830 glyphless_method
= Qempty_box
;
6832 if (EQ (glyphless_method
, Qthin_space
))
6833 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6834 else if (EQ (glyphless_method
, Qempty_box
))
6835 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6836 else if (EQ (glyphless_method
, Qhex_code
))
6837 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6838 else if (STRINGP (glyphless_method
))
6839 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6842 /* Invalid value. We use the default method. */
6843 glyphless_method
= Qnil
;
6846 it
->what
= IT_GLYPHLESS
;
6847 return glyphless_method
;
6850 /* Merge escape glyph face and cache the result. */
6852 static struct frame
*last_escape_glyph_frame
= NULL
;
6853 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6854 static int last_escape_glyph_merged_face_id
= 0;
6857 merge_escape_glyph_face (struct it
*it
)
6861 if (it
->f
== last_escape_glyph_frame
6862 && it
->face_id
== last_escape_glyph_face_id
)
6863 face_id
= last_escape_glyph_merged_face_id
;
6866 /* Merge the `escape-glyph' face into the current face. */
6867 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6868 last_escape_glyph_frame
= it
->f
;
6869 last_escape_glyph_face_id
= it
->face_id
;
6870 last_escape_glyph_merged_face_id
= face_id
;
6875 /* Likewise for glyphless glyph face. */
6877 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6878 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6879 static int last_glyphless_glyph_merged_face_id
= 0;
6882 merge_glyphless_glyph_face (struct it
*it
)
6886 if (it
->f
== last_glyphless_glyph_frame
6887 && it
->face_id
== last_glyphless_glyph_face_id
)
6888 face_id
= last_glyphless_glyph_merged_face_id
;
6891 /* Merge the `glyphless-char' face into the current face. */
6892 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6893 last_glyphless_glyph_frame
= it
->f
;
6894 last_glyphless_glyph_face_id
= it
->face_id
;
6895 last_glyphless_glyph_merged_face_id
= face_id
;
6900 /* Forget the `escape-glyph' and `glyphless-char' faces. This should
6901 be called before redisplaying windows, and when the frame's face
6904 forget_escape_and_glyphless_faces (void)
6906 last_escape_glyph_frame
= NULL
;
6907 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6908 last_glyphless_glyph_frame
= NULL
;
6909 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6912 /* Load IT's display element fields with information about the next
6913 display element from the current position of IT. Value is false if
6914 end of buffer (or C string) is reached. */
6917 get_next_display_element (struct it
*it
)
6919 /* True means that we found a display element. False means that
6920 we hit the end of what we iterate over. Performance note: the
6921 function pointer `method' used here turns out to be faster than
6922 using a sequence of if-statements. */
6926 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6928 if (it
->what
== IT_CHARACTER
)
6930 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6931 and only if (a) the resolved directionality of that character
6933 /* FIXME: Do we need an exception for characters from display
6935 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
6936 && !inhibit_bidi_mirroring
)
6937 it
->c
= bidi_mirror_char (it
->c
);
6938 /* Map via display table or translate control characters.
6939 IT->c, IT->len etc. have been set to the next character by
6940 the function call above. If we have a display table, and it
6941 contains an entry for IT->c, translate it. Don't do this if
6942 IT->c itself comes from a display table, otherwise we could
6943 end up in an infinite recursion. (An alternative could be to
6944 count the recursion depth of this function and signal an
6945 error when a certain maximum depth is reached.) Is it worth
6947 if (success_p
&& it
->dpvec
== NULL
)
6950 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6951 bool nonascii_space_p
= false;
6952 bool nonascii_hyphen_p
= false;
6953 int c
= it
->c
; /* This is the character to display. */
6955 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6957 eassert (SINGLE_BYTE_CHAR_P (c
));
6958 if (unibyte_display_via_language_environment
)
6960 c
= DECODE_CHAR (unibyte
, c
);
6962 c
= BYTE8_TO_CHAR (it
->c
);
6965 c
= BYTE8_TO_CHAR (it
->c
);
6969 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6972 struct Lisp_Vector
*v
= XVECTOR (dv
);
6974 /* Return the first character from the display table
6975 entry, if not empty. If empty, don't display the
6976 current character. */
6979 it
->dpvec_char_len
= it
->len
;
6980 it
->dpvec
= v
->contents
;
6981 it
->dpend
= v
->contents
+ v
->header
.size
;
6982 it
->current
.dpvec_index
= 0;
6983 it
->dpvec_face_id
= -1;
6984 it
->saved_face_id
= it
->face_id
;
6985 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6986 it
->ellipsis_p
= false;
6990 set_iterator_to_next (it
, false);
6995 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6997 if (it
->what
== IT_GLYPHLESS
)
6999 /* Don't display this character. */
7000 set_iterator_to_next (it
, false);
7004 /* If `nobreak-char-display' is non-nil, we display
7005 non-ASCII spaces and hyphens specially. */
7006 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
7008 if (c
== NO_BREAK_SPACE
)
7009 nonascii_space_p
= true;
7010 else if (c
== SOFT_HYPHEN
|| c
== HYPHEN
7011 || c
== NON_BREAKING_HYPHEN
)
7012 nonascii_hyphen_p
= true;
7015 /* Translate control characters into `\003' or `^C' form.
7016 Control characters coming from a display table entry are
7017 currently not translated because we use IT->dpvec to hold
7018 the translation. This could easily be changed but I
7019 don't believe that it is worth doing.
7021 The characters handled by `nobreak-char-display' must be
7024 Non-printable characters and raw-byte characters are also
7025 translated to octal form. */
7026 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
7027 ? (it
->area
!= TEXT_AREA
7028 /* In mode line, treat \n, \t like other crl chars. */
7031 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
7032 || (c
!= '\n' && c
!= '\t'))
7034 || nonascii_hyphen_p
7036 || ! CHAR_PRINTABLE_P (c
))))
7038 /* C is a control character, non-ASCII space/hyphen,
7039 raw-byte, or a non-printable character which must be
7040 displayed either as '\003' or as `^C' where the '\\'
7041 and '^' can be defined in the display table. Fill
7042 IT->ctl_chars with glyphs for what we have to
7043 display. Then, set IT->dpvec to these glyphs. */
7050 /* Handle control characters with ^. */
7052 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
7056 g
= '^'; /* default glyph for Control */
7057 /* Set IT->ctl_chars[0] to the glyph for `^'. */
7059 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
7061 g
= GLYPH_CODE_CHAR (gc
);
7062 lface_id
= GLYPH_CODE_FACE (gc
);
7066 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
7067 : merge_escape_glyph_face (it
));
7069 XSETINT (it
->ctl_chars
[0], g
);
7070 XSETINT (it
->ctl_chars
[1], c
^ 0100);
7072 goto display_control
;
7075 /* Handle non-ascii space in the mode where it only gets
7078 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
7080 /* Merge `nobreak-space' into the current face. */
7081 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
7083 XSETINT (it
->ctl_chars
[0], ' ');
7085 goto display_control
;
7088 /* Handle non-ascii hyphens in the mode where it only
7089 gets highlighting. */
7091 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
7093 /* Merge `nobreak-space' into the current face. */
7094 face_id
= merge_faces (it
->f
, Qnobreak_hyphen
, 0,
7096 XSETINT (it
->ctl_chars
[0], '-');
7098 goto display_control
;
7101 /* Handle sequences that start with the "escape glyph". */
7103 /* the default escape glyph is \. */
7104 escape_glyph
= '\\';
7107 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
7109 escape_glyph
= GLYPH_CODE_CHAR (gc
);
7110 lface_id
= GLYPH_CODE_FACE (gc
);
7114 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
7115 : merge_escape_glyph_face (it
));
7117 /* Draw non-ASCII space/hyphen with escape glyph: */
7119 if (nonascii_space_p
|| nonascii_hyphen_p
)
7121 XSETINT (it
->ctl_chars
[0], escape_glyph
);
7122 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
7124 goto display_control
;
7131 if (CHAR_BYTE8_P (c
))
7132 /* Display \200 instead of \17777600. */
7133 c
= CHAR_TO_BYTE8 (c
);
7134 len
= sprintf (str
, "%03o", c
+ 0u);
7136 XSETINT (it
->ctl_chars
[0], escape_glyph
);
7137 for (i
= 0; i
< len
; i
++)
7138 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
7143 /* Set up IT->dpvec and return first character from it. */
7144 it
->dpvec_char_len
= it
->len
;
7145 it
->dpvec
= it
->ctl_chars
;
7146 it
->dpend
= it
->dpvec
+ ctl_len
;
7147 it
->current
.dpvec_index
= 0;
7148 it
->dpvec_face_id
= face_id
;
7149 it
->saved_face_id
= it
->face_id
;
7150 it
->method
= GET_FROM_DISPLAY_VECTOR
;
7151 it
->ellipsis_p
= false;
7154 it
->char_to_display
= c
;
7158 it
->char_to_display
= it
->c
;
7162 #ifdef HAVE_WINDOW_SYSTEM
7163 /* Adjust face id for a multibyte character. There are no multibyte
7164 character in unibyte text. */
7165 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
7168 && FRAME_WINDOW_P (it
->f
))
7170 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7172 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
7174 /* Automatic composition with glyph-string. */
7175 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
7177 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
7181 ptrdiff_t pos
= (it
->s
? -1
7182 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
7183 : IT_CHARPOS (*it
));
7186 if (it
->what
== IT_CHARACTER
)
7187 c
= it
->char_to_display
;
7190 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
7194 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7195 /* TAB in a composition means display glyphs with
7196 padding space on the left or right. */
7197 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7200 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7203 #endif /* HAVE_WINDOW_SYSTEM */
7206 /* Is this character the last one of a run of characters with
7207 box? If yes, set IT->end_of_box_run_p to true. */
7211 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7213 int face_id
= underlying_face_id (it
);
7214 struct face
*face
= FACE_FROM_ID_OR_NULL (it
->f
, face_id
);
7218 if (face
->box
== FACE_NO_BOX
)
7220 /* If the box comes from face properties in a
7221 display string, check faces in that string. */
7222 int string_face_id
= face_after_it_pos (it
);
7223 it
->end_of_box_run_p
7224 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7227 /* Otherwise, the box comes from the underlying face.
7228 If this is the last string character displayed, check
7229 the next buffer location. */
7230 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7231 /* n_overlay_strings is unreliable unless
7232 overlay_string_index is non-negative. */
7233 && ((it
->current
.overlay_string_index
>= 0
7234 && (it
->current
.overlay_string_index
7235 == it
->n_overlay_strings
- 1))
7236 /* A string from display property. */
7237 || it
->from_disp_prop_p
))
7241 bool text_from_string
= false;
7242 /* Normally, the next buffer location is stored in
7243 IT->current.pos... */
7244 struct text_pos pos
= it
->current
.pos
;
7246 /* ...but for a string from a display property, the
7247 next buffer position is stored in the 'position'
7248 member of the iteration stack slot below the
7249 current one, see handle_single_display_spec. By
7250 contrast, it->current.pos was not yet updated to
7251 point to that buffer position; that will happen
7252 in pop_it, after we finish displaying the current
7253 string. Note that we already checked above that
7254 it->sp is positive, so subtracting one from it is
7256 if (it
->from_disp_prop_p
)
7258 int stackp
= it
->sp
- 1;
7260 /* Find the stack level with data from buffer. */
7262 && STRINGP ((it
->stack
+ stackp
)->string
))
7266 /* If no stack slot was found for iterating
7267 a buffer, we are displaying text from a
7268 string, most probably the mode line or
7269 the header line, and that string has a
7270 display string on some of its
7272 text_from_string
= true;
7273 pos
= it
->stack
[it
->sp
- 1].position
;
7276 pos
= (it
->stack
+ stackp
)->position
;
7279 INC_TEXT_POS (pos
, it
->multibyte_p
);
7281 if (text_from_string
)
7283 Lisp_Object base_string
= it
->stack
[it
->sp
- 1].string
;
7285 if (CHARPOS (pos
) >= SCHARS (base_string
) - 1)
7286 it
->end_of_box_run_p
= true;
7290 = face_at_string_position (it
->w
, base_string
,
7292 &ignore
, face_id
, false);
7293 it
->end_of_box_run_p
7294 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7298 else if (CHARPOS (pos
) >= ZV
)
7299 it
->end_of_box_run_p
= true;
7303 face_at_buffer_position (it
->w
, CHARPOS (pos
), &ignore
,
7305 + TEXT_PROP_DISTANCE_LIMIT
,
7307 it
->end_of_box_run_p
7308 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7314 /* next_element_from_display_vector sets this flag according to
7315 faces of the display vector glyphs, see there. */
7316 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7318 int face_id
= face_after_it_pos (it
);
7319 it
->end_of_box_run_p
7320 = (face_id
!= it
->face_id
7321 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7324 /* If we reached the end of the object we've been iterating (e.g., a
7325 display string or an overlay string), and there's something on
7326 IT->stack, proceed with what's on the stack. It doesn't make
7327 sense to return false if there's unprocessed stuff on the stack,
7328 because otherwise that stuff will never be displayed. */
7329 if (!success_p
&& it
->sp
> 0)
7331 set_iterator_to_next (it
, false);
7332 success_p
= get_next_display_element (it
);
7335 /* Value is false if end of buffer or string reached. */
7340 /* Move IT to the next display element.
7342 RESEAT_P means if called on a newline in buffer text,
7343 skip to the next visible line start.
7345 Functions get_next_display_element and set_iterator_to_next are
7346 separate because I find this arrangement easier to handle than a
7347 get_next_display_element function that also increments IT's
7348 position. The way it is we can first look at an iterator's current
7349 display element, decide whether it fits on a line, and if it does,
7350 increment the iterator position. The other way around we probably
7351 would either need a flag indicating whether the iterator has to be
7352 incremented the next time, or we would have to implement a
7353 decrement position function which would not be easy to write. */
7356 set_iterator_to_next (struct it
*it
, bool reseat_p
)
7358 /* Reset flags indicating start and end of a sequence of characters
7359 with box. Reset them at the start of this function because
7360 moving the iterator to a new position might set them. */
7361 it
->start_of_box_run_p
= it
->end_of_box_run_p
= false;
7365 case GET_FROM_BUFFER
:
7366 /* The current display element of IT is a character from
7367 current_buffer. Advance in the buffer, and maybe skip over
7368 invisible lines that are so because of selective display. */
7369 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7370 reseat_at_next_visible_line_start (it
, false);
7371 else if (it
->cmp_it
.id
>= 0)
7373 /* We are currently getting glyphs from a composition. */
7376 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7377 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7383 /* Update IT's char/byte positions to point to the first
7384 character of the next grapheme cluster, or to the
7385 character visually after the current composition. */
7386 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7387 bidi_move_to_visually_next (&it
->bidi_it
);
7388 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7389 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7392 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7393 && it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7395 /* Composition created while scanning forward. Proceed
7396 to the next grapheme cluster. */
7397 it
->cmp_it
.from
= it
->cmp_it
.to
;
7399 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7400 && it
->cmp_it
.from
> 0)
7402 /* Composition created while scanning backward. Proceed
7403 to the previous grapheme cluster. */
7404 it
->cmp_it
.to
= it
->cmp_it
.from
;
7408 /* No more grapheme clusters in this composition.
7409 Find the next stop position. */
7410 ptrdiff_t stop
= it
->end_charpos
;
7412 if (it
->bidi_it
.scan_dir
< 0)
7413 /* Now we are scanning backward and don't know
7416 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7417 IT_BYTEPOS (*it
), stop
, Qnil
);
7422 eassert (it
->len
!= 0);
7426 IT_BYTEPOS (*it
) += it
->len
;
7427 IT_CHARPOS (*it
) += 1;
7431 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7432 /* If this is a new paragraph, determine its base
7433 direction (a.k.a. its base embedding level). */
7434 if (it
->bidi_it
.new_paragraph
)
7435 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
7437 bidi_move_to_visually_next (&it
->bidi_it
);
7438 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7439 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7440 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7442 /* As the scan direction was changed, we must
7443 re-compute the stop position for composition. */
7444 ptrdiff_t stop
= it
->end_charpos
;
7445 if (it
->bidi_it
.scan_dir
< 0)
7447 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7448 IT_BYTEPOS (*it
), stop
, Qnil
);
7451 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7455 case GET_FROM_C_STRING
:
7456 /* Current display element of IT is from a C string. */
7458 /* If the string position is beyond string's end, it means
7459 next_element_from_c_string is padding the string with
7460 blanks, in which case we bypass the bidi iterator,
7461 because it cannot deal with such virtual characters. */
7462 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7464 IT_BYTEPOS (*it
) += it
->len
;
7465 IT_CHARPOS (*it
) += 1;
7469 bidi_move_to_visually_next (&it
->bidi_it
);
7470 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7471 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7475 case GET_FROM_DISPLAY_VECTOR
:
7476 /* Current display element of IT is from a display table entry.
7477 Advance in the display table definition. Reset it to null if
7478 end reached, and continue with characters from buffers/
7480 ++it
->current
.dpvec_index
;
7482 /* Restore face of the iterator to what they were before the
7483 display vector entry (these entries may contain faces). */
7484 it
->face_id
= it
->saved_face_id
;
7486 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7488 bool recheck_faces
= it
->ellipsis_p
;
7491 it
->method
= GET_FROM_C_STRING
;
7492 else if (STRINGP (it
->string
))
7493 it
->method
= GET_FROM_STRING
;
7496 it
->method
= GET_FROM_BUFFER
;
7497 it
->object
= it
->w
->contents
;
7501 it
->current
.dpvec_index
= -1;
7503 /* Skip over characters which were displayed via IT->dpvec. */
7504 if (it
->dpvec_char_len
< 0)
7505 reseat_at_next_visible_line_start (it
, true);
7506 else if (it
->dpvec_char_len
> 0)
7508 it
->len
= it
->dpvec_char_len
;
7509 set_iterator_to_next (it
, reseat_p
);
7512 /* Maybe recheck faces after display vector. */
7515 if (it
->method
== GET_FROM_STRING
)
7516 it
->stop_charpos
= IT_STRING_CHARPOS (*it
);
7518 it
->stop_charpos
= IT_CHARPOS (*it
);
7523 case GET_FROM_STRING
:
7524 /* Current display element is a character from a Lisp string. */
7525 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7526 /* Don't advance past string end. These conditions are true
7527 when set_iterator_to_next is called at the end of
7528 get_next_display_element, in which case the Lisp string is
7529 already exhausted, and all we want is pop the iterator
7531 if (it
->current
.overlay_string_index
>= 0)
7533 /* This is an overlay string, so there's no padding with
7534 spaces, and the number of characters in the string is
7535 where the string ends. */
7536 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7537 goto consider_string_end
;
7541 /* Not an overlay string. There could be padding, so test
7542 against it->end_charpos. */
7543 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7544 goto consider_string_end
;
7546 if (it
->cmp_it
.id
>= 0)
7548 /* We are delivering display elements from a composition.
7549 Update the string position past the grapheme cluster
7550 we've just processed. */
7553 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7554 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7560 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7561 bidi_move_to_visually_next (&it
->bidi_it
);
7562 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7563 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7566 /* Did we exhaust all the grapheme clusters of this
7568 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7569 && (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
))
7571 /* Not all the grapheme clusters were processed yet;
7572 advance to the next cluster. */
7573 it
->cmp_it
.from
= it
->cmp_it
.to
;
7575 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7576 && it
->cmp_it
.from
> 0)
7578 /* Likewise: advance to the next cluster, but going in
7579 the reverse direction. */
7580 it
->cmp_it
.to
= it
->cmp_it
.from
;
7584 /* This composition was fully processed; find the next
7585 candidate place for checking for composed
7587 /* Always limit string searches to the string length;
7588 any padding spaces are not part of the string, and
7589 there cannot be any compositions in that padding. */
7590 ptrdiff_t stop
= SCHARS (it
->string
);
7592 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
7594 else if (it
->end_charpos
< stop
)
7596 /* Cf. PRECISION in reseat_to_string: we might be
7597 limited in how many of the string characters we
7599 stop
= it
->end_charpos
;
7601 composition_compute_stop_pos (&it
->cmp_it
,
7602 IT_STRING_CHARPOS (*it
),
7603 IT_STRING_BYTEPOS (*it
), stop
,
7610 /* If the string position is beyond string's end, it
7611 means next_element_from_string is padding the string
7612 with blanks, in which case we bypass the bidi
7613 iterator, because it cannot deal with such virtual
7615 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7617 IT_STRING_BYTEPOS (*it
) += it
->len
;
7618 IT_STRING_CHARPOS (*it
) += 1;
7622 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7624 bidi_move_to_visually_next (&it
->bidi_it
);
7625 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7626 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7627 /* If the scan direction changes, we may need to update
7628 the place where to check for composed characters. */
7629 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7631 ptrdiff_t stop
= SCHARS (it
->string
);
7633 if (it
->bidi_it
.scan_dir
< 0)
7635 else if (it
->end_charpos
< stop
)
7636 stop
= it
->end_charpos
;
7638 composition_compute_stop_pos (&it
->cmp_it
,
7639 IT_STRING_CHARPOS (*it
),
7640 IT_STRING_BYTEPOS (*it
), stop
,
7646 consider_string_end
:
7648 if (it
->current
.overlay_string_index
>= 0)
7650 /* IT->string is an overlay string. Advance to the
7651 next, if there is one. */
7652 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7654 it
->ellipsis_p
= false;
7655 next_overlay_string (it
);
7657 setup_for_ellipsis (it
, 0);
7662 /* IT->string is not an overlay string. If we reached
7663 its end, and there is something on IT->stack, proceed
7664 with what is on the stack. This can be either another
7665 string, this time an overlay string, or a buffer. */
7666 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7670 if (it
->method
== GET_FROM_STRING
)
7671 goto consider_string_end
;
7676 case GET_FROM_IMAGE
:
7677 case GET_FROM_STRETCH
:
7678 case GET_FROM_XWIDGET
:
7680 /* The position etc with which we have to proceed are on
7681 the stack. The position may be at the end of a string,
7682 if the `display' property takes up the whole string. */
7683 eassert (it
->sp
> 0);
7685 if (it
->method
== GET_FROM_STRING
)
7686 goto consider_string_end
;
7690 /* There are no other methods defined, so this should be a bug. */
7694 eassert (it
->method
!= GET_FROM_STRING
7695 || (STRINGP (it
->string
)
7696 && IT_STRING_CHARPOS (*it
) >= 0));
7699 /* Load IT's display element fields with information about the next
7700 display element which comes from a display table entry or from the
7701 result of translating a control character to one of the forms `^C'
7704 IT->dpvec holds the glyphs to return as characters.
7705 IT->saved_face_id holds the face id before the display vector--it
7706 is restored into IT->face_id in set_iterator_to_next. */
7709 next_element_from_display_vector (struct it
*it
)
7712 int prev_face_id
= it
->face_id
;
7716 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7718 it
->face_id
= it
->saved_face_id
;
7720 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7721 That seemed totally bogus - so I changed it... */
7722 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7724 if (GLYPH_CODE_P (gc
))
7726 struct face
*this_face
, *prev_face
, *next_face
;
7728 it
->c
= GLYPH_CODE_CHAR (gc
);
7729 it
->len
= CHAR_BYTES (it
->c
);
7731 /* The entry may contain a face id to use. Such a face id is
7732 the id of a Lisp face, not a realized face. A face id of
7733 zero means no face is specified. */
7734 if (it
->dpvec_face_id
>= 0)
7735 it
->face_id
= it
->dpvec_face_id
;
7738 int lface_id
= GLYPH_CODE_FACE (gc
);
7740 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7744 /* Glyphs in the display vector could have the box face, so we
7745 need to set the related flags in the iterator, as
7747 this_face
= FACE_FROM_ID_OR_NULL (it
->f
, it
->face_id
);
7748 prev_face
= FACE_FROM_ID_OR_NULL (it
->f
, prev_face_id
);
7750 /* Is this character the first character of a box-face run? */
7751 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7753 || prev_face
->box
== FACE_NO_BOX
));
7755 /* For the last character of the box-face run, we need to look
7756 either at the next glyph from the display vector, or at the
7757 face we saw before the display vector. */
7758 next_face_id
= it
->saved_face_id
;
7759 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7761 if (it
->dpvec_face_id
>= 0)
7762 next_face_id
= it
->dpvec_face_id
;
7766 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7769 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7773 next_face
= FACE_FROM_ID_OR_NULL (it
->f
, next_face_id
);
7774 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7776 || next_face
->box
== FACE_NO_BOX
));
7777 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7780 /* Display table entry is invalid. Return a space. */
7781 it
->c
= ' ', it
->len
= 1;
7783 /* Don't change position and object of the iterator here. They are
7784 still the values of the character that had this display table
7785 entry or was translated, and that's what we want. */
7786 it
->what
= IT_CHARACTER
;
7790 /* Get the first element of string/buffer in the visual order, after
7791 being reseated to a new position in a string or a buffer. */
7793 get_visually_first_element (struct it
*it
)
7795 bool string_p
= STRINGP (it
->string
) || it
->s
;
7796 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7797 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7799 if (STRINGP (it
->string
))
7801 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7802 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7806 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7807 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7810 if (it
->bidi_it
.charpos
== eob
)
7812 /* Nothing to do, but reset the FIRST_ELT flag, like
7813 bidi_paragraph_init does, because we are not going to
7815 it
->bidi_it
.first_elt
= false;
7817 else if (it
->bidi_it
.charpos
== bob
7819 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7820 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7822 /* If we are at the beginning of a line/string, we can produce
7823 the next element right away. */
7824 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7825 bidi_move_to_visually_next (&it
->bidi_it
);
7829 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7831 /* We need to prime the bidi iterator starting at the line's or
7832 string's beginning, before we will be able to produce the
7835 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7837 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7838 IT_BYTEPOS (*it
), -1,
7839 &it
->bidi_it
.bytepos
);
7840 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7843 /* Now return to buffer/string position where we were asked
7844 to get the next display element, and produce that. */
7845 bidi_move_to_visually_next (&it
->bidi_it
);
7847 while (it
->bidi_it
.bytepos
!= orig_bytepos
7848 && it
->bidi_it
.charpos
< eob
);
7851 /* Adjust IT's position information to where we ended up. */
7852 if (STRINGP (it
->string
))
7854 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7855 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7859 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7860 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7863 if (STRINGP (it
->string
) || !it
->s
)
7865 ptrdiff_t stop
, charpos
, bytepos
;
7867 if (STRINGP (it
->string
))
7870 stop
= SCHARS (it
->string
);
7871 if (stop
> it
->end_charpos
)
7872 stop
= it
->end_charpos
;
7873 charpos
= IT_STRING_CHARPOS (*it
);
7874 bytepos
= IT_STRING_BYTEPOS (*it
);
7878 stop
= it
->end_charpos
;
7879 charpos
= IT_CHARPOS (*it
);
7880 bytepos
= IT_BYTEPOS (*it
);
7882 if (it
->bidi_it
.scan_dir
< 0)
7884 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7889 /* Load IT with the next display element from Lisp string IT->string.
7890 IT->current.string_pos is the current position within the string.
7891 If IT->current.overlay_string_index >= 0, the Lisp string is an
7895 next_element_from_string (struct it
*it
)
7897 struct text_pos position
;
7899 eassert (STRINGP (it
->string
));
7900 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7901 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7902 position
= it
->current
.string_pos
;
7904 /* With bidi reordering, the character to display might not be the
7905 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT means
7906 that we were reseat()ed to a new string, whose paragraph
7907 direction is not known. */
7908 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7910 get_visually_first_element (it
);
7911 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7914 /* Time to check for invisible text? */
7915 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7917 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7920 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7921 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7923 /* With bidi non-linear iteration, we could find
7924 ourselves far beyond the last computed stop_charpos,
7925 with several other stop positions in between that we
7926 missed. Scan them all now, in buffer's logical
7927 order, until we find and handle the last stop_charpos
7928 that precedes our current position. */
7929 handle_stop_backwards (it
, it
->stop_charpos
);
7930 return GET_NEXT_DISPLAY_ELEMENT (it
);
7936 /* Take note of the stop position we just moved
7937 across, for when we will move back across it. */
7938 it
->prev_stop
= it
->stop_charpos
;
7939 /* If we are at base paragraph embedding level, take
7940 note of the last stop position seen at this
7942 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7943 it
->base_level_stop
= it
->stop_charpos
;
7947 /* Since a handler may have changed IT->method, we must
7949 return GET_NEXT_DISPLAY_ELEMENT (it
);
7953 /* If we are before prev_stop, we may have overstepped
7954 on our way backwards a stop_pos, and if so, we need
7955 to handle that stop_pos. */
7956 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7957 /* We can sometimes back up for reasons that have nothing
7958 to do with bidi reordering. E.g., compositions. The
7959 code below is only needed when we are above the base
7960 embedding level, so test for that explicitly. */
7961 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7963 /* If we lost track of base_level_stop, we have no better
7964 place for handle_stop_backwards to start from than string
7965 beginning. This happens, e.g., when we were reseated to
7966 the previous screenful of text by vertical-motion. */
7967 if (it
->base_level_stop
<= 0
7968 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7969 it
->base_level_stop
= 0;
7970 handle_stop_backwards (it
, it
->base_level_stop
);
7971 return GET_NEXT_DISPLAY_ELEMENT (it
);
7975 if (it
->current
.overlay_string_index
>= 0)
7977 /* Get the next character from an overlay string. In overlay
7978 strings, there is no field width or padding with spaces to
7980 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7985 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7986 IT_STRING_BYTEPOS (*it
),
7987 it
->bidi_it
.scan_dir
< 0
7989 : SCHARS (it
->string
))
7990 && next_element_from_composition (it
))
7994 else if (STRING_MULTIBYTE (it
->string
))
7996 const unsigned char *s
= (SDATA (it
->string
)
7997 + IT_STRING_BYTEPOS (*it
));
7998 it
->c
= string_char_and_length (s
, &it
->len
);
8002 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
8008 /* Get the next character from a Lisp string that is not an
8009 overlay string. Such strings come from the mode line, for
8010 example. We may have to pad with spaces, or truncate the
8011 string. See also next_element_from_c_string. */
8012 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
8017 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
8019 /* Pad with spaces. */
8020 it
->c
= ' ', it
->len
= 1;
8021 CHARPOS (position
) = BYTEPOS (position
) = -1;
8023 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
8024 IT_STRING_BYTEPOS (*it
),
8025 it
->bidi_it
.scan_dir
< 0
8027 : it
->string_nchars
)
8028 && next_element_from_composition (it
))
8032 else if (STRING_MULTIBYTE (it
->string
))
8034 const unsigned char *s
= (SDATA (it
->string
)
8035 + IT_STRING_BYTEPOS (*it
));
8036 it
->c
= string_char_and_length (s
, &it
->len
);
8040 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
8045 /* Record what we have and where it came from. */
8046 it
->what
= IT_CHARACTER
;
8047 it
->object
= it
->string
;
8048 it
->position
= position
;
8053 /* Load IT with next display element from C string IT->s.
8054 IT->string_nchars is the maximum number of characters to return
8055 from the string. IT->end_charpos may be greater than
8056 IT->string_nchars when this function is called, in which case we
8057 may have to return padding spaces. Value is false if end of string
8058 reached, including padding spaces. */
8061 next_element_from_c_string (struct it
*it
)
8063 bool success_p
= true;
8066 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
8067 it
->what
= IT_CHARACTER
;
8068 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
8069 it
->object
= make_number (0);
8071 /* With bidi reordering, the character to display might not be the
8072 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8073 we were reseated to a new string, whose paragraph direction is
8075 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8076 get_visually_first_element (it
);
8078 /* IT's position can be greater than IT->string_nchars in case a
8079 field width or precision has been specified when the iterator was
8081 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8083 /* End of the game. */
8087 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
8089 /* Pad with spaces. */
8090 it
->c
= ' ', it
->len
= 1;
8091 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
8093 else if (it
->multibyte_p
)
8094 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
8096 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
8102 /* Set up IT to return characters from an ellipsis, if appropriate.
8103 The definition of the ellipsis glyphs may come from a display table
8104 entry. This function fills IT with the first glyph from the
8105 ellipsis if an ellipsis is to be displayed. */
8108 next_element_from_ellipsis (struct it
*it
)
8110 if (it
->selective_display_ellipsis_p
)
8111 setup_for_ellipsis (it
, it
->len
);
8114 /* The face at the current position may be different from the
8115 face we find after the invisible text. Remember what it
8116 was in IT->saved_face_id, and signal that it's there by
8117 setting face_before_selective_p. */
8118 it
->saved_face_id
= it
->face_id
;
8119 it
->method
= GET_FROM_BUFFER
;
8120 it
->object
= it
->w
->contents
;
8121 reseat_at_next_visible_line_start (it
, true);
8122 it
->face_before_selective_p
= true;
8125 return GET_NEXT_DISPLAY_ELEMENT (it
);
8129 /* Deliver an image display element. The iterator IT is already
8130 filled with image information (done in handle_display_prop). Value
8135 next_element_from_image (struct it
*it
)
8137 it
->what
= IT_IMAGE
;
8142 next_element_from_xwidget (struct it
*it
)
8144 it
->what
= IT_XWIDGET
;
8149 /* Fill iterator IT with next display element from a stretch glyph
8150 property. IT->object is the value of the text property. Value is
8154 next_element_from_stretch (struct it
*it
)
8156 it
->what
= IT_STRETCH
;
8160 /* Scan backwards from IT's current position until we find a stop
8161 position, or until BEGV. This is called when we find ourself
8162 before both the last known prev_stop and base_level_stop while
8163 reordering bidirectional text. */
8166 compute_stop_pos_backwards (struct it
*it
)
8168 const int SCAN_BACK_LIMIT
= 1000;
8169 struct text_pos pos
;
8170 struct display_pos save_current
= it
->current
;
8171 struct text_pos save_position
= it
->position
;
8172 ptrdiff_t charpos
= IT_CHARPOS (*it
);
8173 ptrdiff_t where_we_are
= charpos
;
8174 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
8175 ptrdiff_t save_end_pos
= it
->end_charpos
;
8177 eassert (NILP (it
->string
) && !it
->s
);
8178 eassert (it
->bidi_p
);
8182 it
->end_charpos
= min (charpos
+ 1, ZV
);
8183 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
8184 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
8185 reseat_1 (it
, pos
, false);
8186 compute_stop_pos (it
);
8187 /* We must advance forward, right? */
8188 if (it
->stop_charpos
<= charpos
)
8191 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
8193 if (it
->stop_charpos
<= where_we_are
)
8194 it
->prev_stop
= it
->stop_charpos
;
8196 it
->prev_stop
= BEGV
;
8198 it
->current
= save_current
;
8199 it
->position
= save_position
;
8200 it
->stop_charpos
= save_stop_pos
;
8201 it
->end_charpos
= save_end_pos
;
8204 /* Scan forward from CHARPOS in the current buffer/string, until we
8205 find a stop position > current IT's position. Then handle the stop
8206 position before that. This is called when we bump into a stop
8207 position while reordering bidirectional text. CHARPOS should be
8208 the last previously processed stop_pos (or BEGV/0, if none were
8209 processed yet) whose position is less that IT's current
8213 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
8215 bool bufp
= !STRINGP (it
->string
);
8216 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
8217 struct display_pos save_current
= it
->current
;
8218 struct text_pos save_position
= it
->position
;
8219 struct text_pos pos1
;
8220 ptrdiff_t next_stop
;
8222 /* Scan in strict logical order. */
8223 eassert (it
->bidi_p
);
8227 it
->prev_stop
= charpos
;
8230 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
8231 reseat_1 (it
, pos1
, false);
8234 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
8235 compute_stop_pos (it
);
8236 /* We must advance forward, right? */
8237 if (it
->stop_charpos
<= it
->prev_stop
)
8239 charpos
= it
->stop_charpos
;
8241 while (charpos
<= where_we_are
);
8244 it
->current
= save_current
;
8245 it
->position
= save_position
;
8246 next_stop
= it
->stop_charpos
;
8247 it
->stop_charpos
= it
->prev_stop
;
8249 it
->stop_charpos
= next_stop
;
8252 /* Load IT with the next display element from current_buffer. Value
8253 is false if end of buffer reached. IT->stop_charpos is the next
8254 position at which to stop and check for text properties or buffer
8258 next_element_from_buffer (struct it
*it
)
8260 bool success_p
= true;
8262 eassert (IT_CHARPOS (*it
) >= BEGV
);
8263 eassert (NILP (it
->string
) && !it
->s
);
8264 eassert (!it
->bidi_p
8265 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8266 && it
->bidi_it
.string
.s
== NULL
));
8268 /* With bidi reordering, the character to display might not be the
8269 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8270 we were reseat()ed to a new buffer position, which is potentially
8271 a different paragraph. */
8272 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8274 get_visually_first_element (it
);
8275 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8278 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8280 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8282 bool overlay_strings_follow_p
;
8284 /* End of the game, except when overlay strings follow that
8285 haven't been returned yet. */
8286 if (it
->overlay_strings_at_end_processed_p
)
8287 overlay_strings_follow_p
= false;
8290 it
->overlay_strings_at_end_processed_p
= true;
8291 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8294 if (overlay_strings_follow_p
)
8295 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8299 it
->position
= it
->current
.pos
;
8303 else if (!(!it
->bidi_p
8304 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8305 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8307 /* With bidi non-linear iteration, we could find ourselves
8308 far beyond the last computed stop_charpos, with several
8309 other stop positions in between that we missed. Scan
8310 them all now, in buffer's logical order, until we find
8311 and handle the last stop_charpos that precedes our
8312 current position. */
8313 handle_stop_backwards (it
, it
->stop_charpos
);
8314 it
->ignore_overlay_strings_at_pos_p
= false;
8315 return GET_NEXT_DISPLAY_ELEMENT (it
);
8321 /* Take note of the stop position we just moved across,
8322 for when we will move back across it. */
8323 it
->prev_stop
= it
->stop_charpos
;
8324 /* If we are at base paragraph embedding level, take
8325 note of the last stop position seen at this
8327 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8328 it
->base_level_stop
= it
->stop_charpos
;
8331 it
->ignore_overlay_strings_at_pos_p
= false;
8332 return GET_NEXT_DISPLAY_ELEMENT (it
);
8336 /* If we are before prev_stop, we may have overstepped on
8337 our way backwards a stop_pos, and if so, we need to
8338 handle that stop_pos. */
8339 && IT_CHARPOS (*it
) < it
->prev_stop
8340 /* We can sometimes back up for reasons that have nothing
8341 to do with bidi reordering. E.g., compositions. The
8342 code below is only needed when we are above the base
8343 embedding level, so test for that explicitly. */
8344 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8346 if (it
->base_level_stop
<= 0
8347 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8349 /* If we lost track of base_level_stop, we need to find
8350 prev_stop by looking backwards. This happens, e.g., when
8351 we were reseated to the previous screenful of text by
8353 it
->base_level_stop
= BEGV
;
8354 compute_stop_pos_backwards (it
);
8355 handle_stop_backwards (it
, it
->prev_stop
);
8358 handle_stop_backwards (it
, it
->base_level_stop
);
8359 it
->ignore_overlay_strings_at_pos_p
= false;
8360 return GET_NEXT_DISPLAY_ELEMENT (it
);
8364 /* No face changes, overlays etc. in sight, so just return a
8365 character from current_buffer. */
8369 /* We moved to the next buffer position, so any info about
8370 previously seen overlays is no longer valid. */
8371 it
->ignore_overlay_strings_at_pos_p
= false;
8373 /* Maybe run the redisplay end trigger hook. Performance note:
8374 This doesn't seem to cost measurable time. */
8375 if (it
->redisplay_end_trigger_charpos
8377 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8378 run_redisplay_end_trigger_hook (it
);
8380 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8381 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8383 && next_element_from_composition (it
))
8388 /* Get the next character, maybe multibyte. */
8389 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8390 if (it
->multibyte_p
&& !ASCII_CHAR_P (*p
))
8391 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8393 it
->c
= *p
, it
->len
= 1;
8395 /* Record what we have and where it came from. */
8396 it
->what
= IT_CHARACTER
;
8397 it
->object
= it
->w
->contents
;
8398 it
->position
= it
->current
.pos
;
8400 /* Normally we return the character found above, except when we
8401 really want to return an ellipsis for selective display. */
8406 /* A value of selective > 0 means hide lines indented more
8407 than that number of columns. */
8408 if (it
->selective
> 0
8409 && IT_CHARPOS (*it
) + 1 < ZV
8410 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8411 IT_BYTEPOS (*it
) + 1,
8414 success_p
= next_element_from_ellipsis (it
);
8415 it
->dpvec_char_len
= -1;
8418 else if (it
->c
== '\r' && it
->selective
== -1)
8420 /* A value of selective == -1 means that everything from the
8421 CR to the end of the line is invisible, with maybe an
8422 ellipsis displayed for it. */
8423 success_p
= next_element_from_ellipsis (it
);
8424 it
->dpvec_char_len
= -1;
8429 /* Value is false if end of buffer reached. */
8430 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8435 /* Run the redisplay end trigger hook for IT. */
8438 run_redisplay_end_trigger_hook (struct it
*it
)
8440 /* IT->glyph_row should be non-null, i.e. we should be actually
8441 displaying something, or otherwise we should not run the hook. */
8442 eassert (it
->glyph_row
);
8444 ptrdiff_t charpos
= it
->redisplay_end_trigger_charpos
;
8445 it
->redisplay_end_trigger_charpos
= 0;
8447 /* Since we are *trying* to run these functions, don't try to run
8448 them again, even if they get an error. */
8449 wset_redisplay_end_trigger (it
->w
, Qnil
);
8450 CALLN (Frun_hook_with_args
, Qredisplay_end_trigger_functions
, it
->window
,
8451 make_number (charpos
));
8453 /* Notice if it changed the face of the character we are on. */
8454 handle_face_prop (it
);
8458 /* Deliver a composition display element. Unlike the other
8459 next_element_from_XXX, this function is not registered in the array
8460 get_next_element[]. It is called from next_element_from_buffer and
8461 next_element_from_string when necessary. */
8464 next_element_from_composition (struct it
*it
)
8466 it
->what
= IT_COMPOSITION
;
8467 it
->len
= it
->cmp_it
.nbytes
;
8468 if (STRINGP (it
->string
))
8472 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8473 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8476 it
->position
= it
->current
.string_pos
;
8477 it
->object
= it
->string
;
8478 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8479 IT_STRING_BYTEPOS (*it
), it
->string
);
8485 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8486 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8489 if (it
->bidi_it
.new_paragraph
)
8490 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
8492 /* Resync the bidi iterator with IT's new position.
8493 FIXME: this doesn't support bidirectional text. */
8494 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8495 bidi_move_to_visually_next (&it
->bidi_it
);
8499 it
->position
= it
->current
.pos
;
8500 it
->object
= it
->w
->contents
;
8501 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8502 IT_BYTEPOS (*it
), Qnil
);
8509 /***********************************************************************
8510 Moving an iterator without producing glyphs
8511 ***********************************************************************/
8513 /* Check if iterator is at a position corresponding to a valid buffer
8514 position after some move_it_ call. */
8516 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8517 ((it)->method != GET_FROM_STRING || IT_STRING_CHARPOS (*it) == 0)
8520 /* Move iterator IT to a specified buffer or X position within one
8521 line on the display without producing glyphs.
8523 OP should be a bit mask including some or all of these bits:
8524 MOVE_TO_X: Stop upon reaching x-position TO_X.
8525 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8526 Regardless of OP's value, stop upon reaching the end of the display line.
8528 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8529 This means, in particular, that TO_X includes window's horizontal
8532 The return value has several possible values that
8533 say what condition caused the scan to stop:
8535 MOVE_POS_MATCH_OR_ZV
8536 - when TO_POS or ZV was reached.
8539 -when TO_X was reached before TO_POS or ZV were reached.
8542 - when we reached the end of the display area and the line must
8546 - when we reached the end of the display area and the line is
8550 - when we stopped at a line end, i.e. a newline or a CR and selective
8553 static enum move_it_result
8554 move_it_in_display_line_to (struct it
*it
,
8555 ptrdiff_t to_charpos
, int to_x
,
8556 enum move_operation_enum op
)
8558 enum move_it_result result
= MOVE_UNDEFINED
;
8559 struct glyph_row
*saved_glyph_row
;
8560 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8561 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8562 void *ppos_data
= NULL
;
8563 bool may_wrap
= false;
8564 enum it_method prev_method
= it
->method
;
8565 ptrdiff_t closest_pos UNINIT
;
8566 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8567 bool saw_smaller_pos
= prev_pos
< to_charpos
;
8569 /* Don't produce glyphs in produce_glyphs. */
8570 saved_glyph_row
= it
->glyph_row
;
8571 it
->glyph_row
= NULL
;
8573 /* Use wrap_it to save a copy of IT wherever a word wrap could
8574 occur. Use atpos_it to save a copy of IT at the desired buffer
8575 position, if found, so that we can scan ahead and check if the
8576 word later overshoots the window edge. Use atx_it similarly, for
8582 /* Use ppos_it under bidi reordering to save a copy of IT for the
8583 initial position. We restore that position in IT when we have
8584 scanned the entire display line without finding a match for
8585 TO_CHARPOS and all the character positions are greater than
8586 TO_CHARPOS. We then restart the scan from the initial position,
8587 and stop at CLOSEST_POS, which is a position > TO_CHARPOS that is
8588 the closest to TO_CHARPOS. */
8591 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8593 SAVE_IT (ppos_it
, *it
, ppos_data
);
8594 closest_pos
= IT_CHARPOS (*it
);
8600 #define BUFFER_POS_REACHED_P() \
8601 ((op & MOVE_TO_POS) != 0 \
8602 && BUFFERP (it->object) \
8603 && (IT_CHARPOS (*it) == to_charpos \
8605 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8606 && IT_CHARPOS (*it) > to_charpos) \
8607 || (it->what == IT_COMPOSITION \
8608 && ((IT_CHARPOS (*it) > to_charpos \
8609 && to_charpos >= it->cmp_it.charpos) \
8610 || (IT_CHARPOS (*it) < to_charpos \
8611 && to_charpos <= it->cmp_it.charpos)))) \
8612 && (it->method == GET_FROM_BUFFER \
8613 || (it->method == GET_FROM_DISPLAY_VECTOR \
8614 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8616 /* If there's a line-/wrap-prefix, handle it. */
8617 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
)
8618 handle_line_prefix (it
);
8620 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8621 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8625 int x
, i
, ascent
= 0, descent
= 0;
8627 /* Utility macro to reset an iterator with x, ascent, and descent. */
8628 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8629 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8630 (IT)->max_descent = descent)
8632 /* Stop if we move beyond TO_CHARPOS (after an image or a
8633 display string or stretch glyph). */
8634 if ((op
& MOVE_TO_POS
) != 0
8635 && BUFFERP (it
->object
)
8636 && it
->method
== GET_FROM_BUFFER
8638 /* When the iterator is at base embedding level, we
8639 are guaranteed that characters are delivered for
8640 display in strictly increasing order of their
8641 buffer positions. */
8642 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8643 && IT_CHARPOS (*it
) > to_charpos
)
8645 && (prev_method
== GET_FROM_IMAGE
8646 || prev_method
== GET_FROM_STRETCH
8647 || prev_method
== GET_FROM_STRING
)
8648 /* Passed TO_CHARPOS from left to right. */
8649 && ((prev_pos
< to_charpos
8650 && IT_CHARPOS (*it
) > to_charpos
)
8651 /* Passed TO_CHARPOS from right to left. */
8652 || (prev_pos
> to_charpos
8653 && IT_CHARPOS (*it
) < to_charpos
)))))
8655 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8657 result
= MOVE_POS_MATCH_OR_ZV
;
8660 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8661 /* If wrap_it is valid, the current position might be in a
8662 word that is wrapped. So, save the iterator in
8663 atpos_it and continue to see if wrapping happens. */
8664 SAVE_IT (atpos_it
, *it
, atpos_data
);
8667 /* Stop when ZV reached.
8668 We used to stop here when TO_CHARPOS reached as well, but that is
8669 too soon if this glyph does not fit on this line. So we handle it
8670 explicitly below. */
8671 if (!get_next_display_element (it
))
8673 result
= MOVE_POS_MATCH_OR_ZV
;
8677 if (it
->line_wrap
== TRUNCATE
)
8679 if (BUFFER_POS_REACHED_P ())
8681 result
= MOVE_POS_MATCH_OR_ZV
;
8687 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
8689 if (IT_DISPLAYING_WHITESPACE (it
))
8693 /* We have reached a glyph that follows one or more
8694 whitespace characters. If the position is
8695 already found, we are done. */
8696 if (atpos_it
.sp
>= 0)
8698 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8699 result
= MOVE_POS_MATCH_OR_ZV
;
8704 RESTORE_IT (it
, &atx_it
, atx_data
);
8705 result
= MOVE_X_REACHED
;
8708 /* Otherwise, we can wrap here. */
8709 SAVE_IT (wrap_it
, *it
, wrap_data
);
8715 /* Remember the line height for the current line, in case
8716 the next element doesn't fit on the line. */
8717 ascent
= it
->max_ascent
;
8718 descent
= it
->max_descent
;
8720 /* The call to produce_glyphs will get the metrics of the
8721 display element IT is loaded with. Record the x-position
8722 before this display element, in case it doesn't fit on the
8726 PRODUCE_GLYPHS (it
);
8728 if (it
->area
!= TEXT_AREA
)
8730 prev_method
= it
->method
;
8731 if (it
->method
== GET_FROM_BUFFER
)
8732 prev_pos
= IT_CHARPOS (*it
);
8733 set_iterator_to_next (it
, true);
8734 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8735 SET_TEXT_POS (this_line_min_pos
,
8736 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8738 && (op
& MOVE_TO_POS
)
8739 && IT_CHARPOS (*it
) > to_charpos
8740 && IT_CHARPOS (*it
) < closest_pos
)
8741 closest_pos
= IT_CHARPOS (*it
);
8745 /* The number of glyphs we get back in IT->nglyphs will normally
8746 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8747 character on a terminal frame, or (iii) a line end. For the
8748 second case, IT->nglyphs - 1 padding glyphs will be present.
8749 (On X frames, there is only one glyph produced for a
8750 composite character.)
8752 The behavior implemented below means, for continuation lines,
8753 that as many spaces of a TAB as fit on the current line are
8754 displayed there. For terminal frames, as many glyphs of a
8755 multi-glyph character are displayed in the current line, too.
8756 This is what the old redisplay code did, and we keep it that
8757 way. Under X, the whole shape of a complex character must
8758 fit on the line or it will be completely displayed in the
8761 Note that both for tabs and padding glyphs, all glyphs have
8765 /* More than one glyph or glyph doesn't fit on line. All
8766 glyphs have the same width. */
8767 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8769 int x_before_this_char
= x
;
8770 int hpos_before_this_char
= it
->hpos
;
8772 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8774 new_x
= x
+ single_glyph_width
;
8776 /* We want to leave anything reaching TO_X to the caller. */
8777 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8779 if (BUFFER_POS_REACHED_P ())
8781 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8782 goto buffer_pos_reached
;
8783 if (atpos_it
.sp
< 0)
8785 SAVE_IT (atpos_it
, *it
, atpos_data
);
8786 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8791 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8794 result
= MOVE_X_REACHED
;
8799 SAVE_IT (atx_it
, *it
, atx_data
);
8800 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8805 if (/* Lines are continued. */
8806 it
->line_wrap
!= TRUNCATE
8807 && (/* And glyph doesn't fit on the line. */
8808 new_x
> it
->last_visible_x
8809 /* Or it fits exactly and we're on a window
8811 || (new_x
== it
->last_visible_x
8812 && FRAME_WINDOW_P (it
->f
)
8813 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8814 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8815 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8817 bool moved_forward
= false;
8819 if (/* IT->hpos == 0 means the very first glyph
8820 doesn't fit on the line, e.g. a wide image. */
8822 || (new_x
== it
->last_visible_x
8823 && FRAME_WINDOW_P (it
->f
)))
8826 it
->current_x
= new_x
;
8828 /* The character's last glyph just barely fits
8830 if (i
== it
->nglyphs
- 1)
8832 /* If this is the destination position,
8833 return a position *before* it in this row,
8834 now that we know it fits in this row. */
8835 if (BUFFER_POS_REACHED_P ())
8837 bool can_wrap
= true;
8839 /* If we are at a whitespace character
8840 that barely fits on this screen line,
8841 but the next character is also
8842 whitespace, we cannot wrap here. */
8843 if (it
->line_wrap
== WORD_WRAP
8846 && IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8849 void *tem_data
= NULL
;
8851 SAVE_IT (tem_it
, *it
, tem_data
);
8852 set_iterator_to_next (it
, true);
8853 if (get_next_display_element (it
)
8854 && IT_DISPLAYING_WHITESPACE (it
))
8856 RESTORE_IT (it
, &tem_it
, tem_data
);
8858 if (it
->line_wrap
!= WORD_WRAP
8860 /* If we've just found whitespace
8861 where we can wrap, effectively
8862 ignore the previous wrap point --
8863 it is no longer relevant, but we
8864 won't have an opportunity to
8865 update it, since we've reached
8866 the edge of this screen line. */
8867 || (may_wrap
&& can_wrap
8868 && IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8870 it
->hpos
= hpos_before_this_char
;
8871 it
->current_x
= x_before_this_char
;
8872 result
= MOVE_POS_MATCH_OR_ZV
;
8875 if (it
->line_wrap
== WORD_WRAP
8878 SAVE_IT (atpos_it
, *it
, atpos_data
);
8879 atpos_it
.current_x
= x_before_this_char
;
8880 atpos_it
.hpos
= hpos_before_this_char
;
8884 prev_method
= it
->method
;
8885 if (it
->method
== GET_FROM_BUFFER
)
8886 prev_pos
= IT_CHARPOS (*it
);
8887 set_iterator_to_next (it
, true);
8888 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8889 SET_TEXT_POS (this_line_min_pos
,
8890 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8891 /* On graphical terminals, newlines may
8892 "overflow" into the fringe if
8893 overflow-newline-into-fringe is non-nil.
8894 On text terminals, and on graphical
8895 terminals with no right margin, newlines
8896 may overflow into the last glyph on the
8898 if (!FRAME_WINDOW_P (it
->f
)
8900 && it
->bidi_it
.paragraph_dir
== R2L
)
8901 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8902 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8903 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8905 if (!get_next_display_element (it
))
8907 result
= MOVE_POS_MATCH_OR_ZV
;
8910 moved_forward
= true;
8911 if (BUFFER_POS_REACHED_P ())
8913 if (ITERATOR_AT_END_OF_LINE_P (it
))
8914 result
= MOVE_POS_MATCH_OR_ZV
;
8916 result
= MOVE_LINE_CONTINUED
;
8919 if (ITERATOR_AT_END_OF_LINE_P (it
)
8920 && (it
->line_wrap
!= WORD_WRAP
8922 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8924 result
= MOVE_NEWLINE_OR_CR
;
8931 IT_RESET_X_ASCENT_DESCENT (it
);
8933 /* If the screen line ends with whitespace, and we
8934 are under word-wrap, don't use wrap_it: it is no
8935 longer relevant, but we won't have an opportunity
8936 to update it, since we are done with this screen
8938 if (may_wrap
&& IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)
8939 /* If the character after the one which set the
8940 may_wrap flag is also whitespace, we can't
8941 wrap here, since the screen line cannot be
8942 wrapped in the middle of whitespace.
8943 Therefore, wrap_it _is_ relevant in that
8945 && !(moved_forward
&& IT_DISPLAYING_WHITESPACE (it
)))
8947 /* If we've found TO_X, go back there, as we now
8948 know the last word fits on this screen line. */
8949 if ((op
& MOVE_TO_X
) && new_x
== it
->last_visible_x
8952 RESTORE_IT (it
, &atx_it
, atx_data
);
8955 result
= MOVE_X_REACHED
;
8959 else if (wrap_it
.sp
>= 0)
8961 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8966 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8968 result
= MOVE_LINE_CONTINUED
;
8972 if (BUFFER_POS_REACHED_P ())
8974 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8975 goto buffer_pos_reached
;
8976 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8978 SAVE_IT (atpos_it
, *it
, atpos_data
);
8979 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8983 if (new_x
> it
->first_visible_x
)
8985 /* Glyph is visible. Increment number of glyphs that
8986 would be displayed. */
8991 if (result
!= MOVE_UNDEFINED
)
8994 else if (BUFFER_POS_REACHED_P ())
8997 IT_RESET_X_ASCENT_DESCENT (it
);
8998 result
= MOVE_POS_MATCH_OR_ZV
;
9001 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
9003 /* Stop when TO_X specified and reached. This check is
9004 necessary here because of lines consisting of a line end,
9005 only. The line end will not produce any glyphs and we
9006 would never get MOVE_X_REACHED. */
9007 eassert (it
->nglyphs
== 0);
9008 result
= MOVE_X_REACHED
;
9012 /* Is this a line end? If yes, we're done. */
9013 if (ITERATOR_AT_END_OF_LINE_P (it
))
9015 /* If we are past TO_CHARPOS, but never saw any character
9016 positions smaller than TO_CHARPOS, return
9017 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
9019 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
9021 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
9023 if (closest_pos
< ZV
)
9025 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9026 /* Don't recurse if closest_pos is equal to
9027 to_charpos, since we have just tried that. */
9028 if (closest_pos
!= to_charpos
)
9029 move_it_in_display_line_to (it
, closest_pos
, -1,
9031 result
= MOVE_POS_MATCH_OR_ZV
;
9034 goto buffer_pos_reached
;
9036 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
9037 && IT_CHARPOS (*it
) > to_charpos
)
9038 goto buffer_pos_reached
;
9040 result
= MOVE_NEWLINE_OR_CR
;
9043 result
= MOVE_NEWLINE_OR_CR
;
9044 /* If we've processed the newline, make sure this flag is
9045 reset, as it must only be set when the newline itself is
9047 if (result
== MOVE_NEWLINE_OR_CR
)
9048 it
->constrain_row_ascent_descent_p
= false;
9052 prev_method
= it
->method
;
9053 if (it
->method
== GET_FROM_BUFFER
)
9054 prev_pos
= IT_CHARPOS (*it
);
9055 /* The current display element has been consumed. Advance
9057 set_iterator_to_next (it
, true);
9058 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
9059 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
9060 if (IT_CHARPOS (*it
) < to_charpos
)
9061 saw_smaller_pos
= true;
9063 && (op
& MOVE_TO_POS
)
9064 && IT_CHARPOS (*it
) >= to_charpos
9065 && IT_CHARPOS (*it
) < closest_pos
)
9066 closest_pos
= IT_CHARPOS (*it
);
9068 /* Stop if lines are truncated and IT's current x-position is
9069 past the right edge of the window now. */
9070 if (it
->line_wrap
== TRUNCATE
9071 && it
->current_x
>= it
->last_visible_x
)
9073 if (!FRAME_WINDOW_P (it
->f
)
9074 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
9075 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
9076 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
9077 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
9079 bool at_eob_p
= false;
9081 if ((at_eob_p
= !get_next_display_element (it
))
9082 || BUFFER_POS_REACHED_P ()
9083 /* If we are past TO_CHARPOS, but never saw any
9084 character positions smaller than TO_CHARPOS,
9085 return MOVE_POS_MATCH_OR_ZV, like the
9086 unidirectional display did. */
9087 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
9089 && IT_CHARPOS (*it
) > to_charpos
))
9092 && !BUFFER_POS_REACHED_P ()
9093 && !at_eob_p
&& closest_pos
< ZV
)
9095 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9096 if (closest_pos
!= to_charpos
)
9097 move_it_in_display_line_to (it
, closest_pos
, -1,
9100 result
= MOVE_POS_MATCH_OR_ZV
;
9103 if (ITERATOR_AT_END_OF_LINE_P (it
))
9105 result
= MOVE_NEWLINE_OR_CR
;
9109 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
9111 && IT_CHARPOS (*it
) > to_charpos
)
9113 if (closest_pos
< ZV
)
9115 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9116 if (closest_pos
!= to_charpos
)
9117 move_it_in_display_line_to (it
, closest_pos
, -1,
9120 result
= MOVE_POS_MATCH_OR_ZV
;
9123 result
= MOVE_LINE_TRUNCATED
;
9126 #undef IT_RESET_X_ASCENT_DESCENT
9129 #undef BUFFER_POS_REACHED_P
9131 /* If we scanned beyond TO_POS, restore the saved iterator either to
9132 the wrap point (if found), or to atpos/atx location. We decide which
9133 data to use to restore the saved iterator state by their X coordinates,
9134 since buffer positions might increase non-monotonically with screen
9135 coordinates due to bidi reordering. */
9136 if (result
== MOVE_LINE_CONTINUED
9137 && it
->line_wrap
== WORD_WRAP
9139 && ((atpos_it
.sp
>= 0 && wrap_it
.current_x
< atpos_it
.current_x
)
9140 || (atx_it
.sp
>= 0 && wrap_it
.current_x
< atx_it
.current_x
)))
9141 RESTORE_IT (it
, &wrap_it
, wrap_data
);
9142 else if (atpos_it
.sp
>= 0)
9143 RESTORE_IT (it
, &atpos_it
, atpos_data
);
9144 else if (atx_it
.sp
>= 0)
9145 RESTORE_IT (it
, &atx_it
, atx_data
);
9150 bidi_unshelve_cache (atpos_data
, true);
9152 bidi_unshelve_cache (atx_data
, true);
9154 bidi_unshelve_cache (wrap_data
, true);
9156 bidi_unshelve_cache (ppos_data
, true);
9158 /* Restore the iterator settings altered at the beginning of this
9160 it
->glyph_row
= saved_glyph_row
;
9164 /* For external use. */
9166 move_it_in_display_line (struct it
*it
,
9167 ptrdiff_t to_charpos
, int to_x
,
9168 enum move_operation_enum op
)
9170 if (it
->line_wrap
== WORD_WRAP
9171 && (op
& MOVE_TO_X
))
9174 void *save_data
= NULL
;
9177 SAVE_IT (save_it
, *it
, save_data
);
9178 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9179 /* When word-wrap is on, TO_X may lie past the end
9180 of a wrapped line. Then it->current is the
9181 character on the next line, so backtrack to the
9182 space before the wrap point. */
9183 if (skip
== MOVE_LINE_CONTINUED
)
9185 int prev_x
= max (it
->current_x
- 1, 0);
9186 RESTORE_IT (it
, &save_it
, save_data
);
9187 move_it_in_display_line_to
9188 (it
, -1, prev_x
, MOVE_TO_X
);
9191 bidi_unshelve_cache (save_data
, true);
9194 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9198 /* Move IT forward until it satisfies one or more of the criteria in
9199 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
9201 OP is a bit-mask that specifies where to stop, and in particular,
9202 which of those four position arguments makes a difference. See the
9203 description of enum move_operation_enum.
9205 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
9206 screen line, this function will set IT to the next position that is
9207 displayed to the right of TO_CHARPOS on the screen.
9209 Return the maximum pixel length of any line scanned but never more
9210 than it.last_visible_x. */
9213 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
9215 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
9216 int line_height
, line_start_x
= 0, reached
= 0;
9217 int max_current_x
= 0;
9218 void *backup_data
= NULL
;
9222 if (op
& MOVE_TO_VPOS
)
9224 /* If no TO_CHARPOS and no TO_X specified, stop at the
9225 start of the line TO_VPOS. */
9226 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
9228 if (it
->vpos
== to_vpos
)
9234 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
9238 /* TO_VPOS >= 0 means stop at TO_X in the line at
9239 TO_VPOS, or at TO_POS, whichever comes first. */
9240 if (it
->vpos
== to_vpos
)
9246 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9248 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
9253 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
9255 /* We have reached TO_X but not in the line we want. */
9256 skip
= move_it_in_display_line_to (it
, to_charpos
,
9258 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9266 else if (op
& MOVE_TO_Y
)
9268 struct it it_backup
;
9270 if (it
->line_wrap
== WORD_WRAP
)
9271 SAVE_IT (it_backup
, *it
, backup_data
);
9273 /* TO_Y specified means stop at TO_X in the line containing
9274 TO_Y---or at TO_CHARPOS if this is reached first. The
9275 problem is that we can't really tell whether the line
9276 contains TO_Y before we have completely scanned it, and
9277 this may skip past TO_X. What we do is to first scan to
9280 If TO_X is not specified, use a TO_X of zero. The reason
9281 is to make the outcome of this function more predictable.
9282 If we didn't use TO_X == 0, we would stop at the end of
9283 the line which is probably not what a caller would expect
9285 skip
= move_it_in_display_line_to
9286 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
9287 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
9289 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
9290 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9292 else if (skip
== MOVE_X_REACHED
)
9294 /* If TO_X was reached, we want to know whether TO_Y is
9295 in the line. We know this is the case if the already
9296 scanned glyphs make the line tall enough. Otherwise,
9297 we must check by scanning the rest of the line. */
9298 line_height
= it
->max_ascent
+ it
->max_descent
;
9299 if (to_y
>= it
->current_y
9300 && to_y
< it
->current_y
+ line_height
)
9305 SAVE_IT (it_backup
, *it
, backup_data
);
9306 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
9307 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
9309 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
9310 line_height
= it
->max_ascent
+ it
->max_descent
;
9311 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9313 if (to_y
>= it
->current_y
9314 && to_y
< it
->current_y
+ line_height
)
9316 /* If TO_Y is in this line and TO_X was reached
9317 above, we scanned too far. We have to restore
9318 IT's settings to the ones before skipping. But
9319 keep the more accurate values of max_ascent and
9320 max_descent we've found while skipping the rest
9321 of the line, for the sake of callers, such as
9322 pos_visible_p, that need to know the line
9324 int max_ascent
= it
->max_ascent
;
9325 int max_descent
= it
->max_descent
;
9327 RESTORE_IT (it
, &it_backup
, backup_data
);
9328 it
->max_ascent
= max_ascent
;
9329 it
->max_descent
= max_descent
;
9335 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9341 /* Check whether TO_Y is in this line. */
9342 line_height
= it
->max_ascent
+ it
->max_descent
;
9343 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9345 if (to_y
>= it
->current_y
9346 && to_y
< it
->current_y
+ line_height
)
9348 if (to_y
> it
->current_y
)
9349 max_current_x
= max (it
->current_x
, max_current_x
);
9351 /* When word-wrap is on, TO_X may lie past the end
9352 of a wrapped line. Then it->current is the
9353 character on the next line, so backtrack to the
9354 space before the wrap point. */
9355 if (skip
== MOVE_LINE_CONTINUED
9356 && it
->line_wrap
== WORD_WRAP
)
9358 int prev_x
= max (it
->current_x
- 1, 0);
9359 RESTORE_IT (it
, &it_backup
, backup_data
);
9360 skip
= move_it_in_display_line_to
9361 (it
, -1, prev_x
, MOVE_TO_X
);
9370 max_current_x
= max (it
->current_x
, max_current_x
);
9374 else if (BUFFERP (it
->object
)
9375 && (it
->method
== GET_FROM_BUFFER
9376 || it
->method
== GET_FROM_STRETCH
)
9377 && IT_CHARPOS (*it
) >= to_charpos
9378 /* Under bidi iteration, a call to set_iterator_to_next
9379 can scan far beyond to_charpos if the initial
9380 portion of the next line needs to be reordered. In
9381 that case, give move_it_in_display_line_to another
9384 && it
->bidi_it
.scan_dir
== -1))
9385 skip
= MOVE_POS_MATCH_OR_ZV
;
9387 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9391 case MOVE_POS_MATCH_OR_ZV
:
9392 max_current_x
= max (it
->current_x
, max_current_x
);
9396 case MOVE_NEWLINE_OR_CR
:
9397 max_current_x
= max (it
->current_x
, max_current_x
);
9398 set_iterator_to_next (it
, true);
9399 it
->continuation_lines_width
= 0;
9402 case MOVE_LINE_TRUNCATED
:
9403 max_current_x
= it
->last_visible_x
;
9404 it
->continuation_lines_width
= 0;
9405 reseat_at_next_visible_line_start (it
, false);
9406 if ((op
& MOVE_TO_POS
) != 0
9407 && IT_CHARPOS (*it
) > to_charpos
)
9414 case MOVE_LINE_CONTINUED
:
9415 max_current_x
= it
->last_visible_x
;
9416 /* For continued lines ending in a tab, some of the glyphs
9417 associated with the tab are displayed on the current
9418 line. Since it->current_x does not include these glyphs,
9419 we use it->last_visible_x instead. */
9422 it
->continuation_lines_width
+= it
->last_visible_x
;
9423 /* When moving by vpos, ensure that the iterator really
9424 advances to the next line (bug#847, bug#969). Fixme:
9425 do we need to do this in other circumstances? */
9426 if (it
->current_x
!= it
->last_visible_x
9427 && (op
& MOVE_TO_VPOS
)
9428 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9430 line_start_x
= it
->current_x
+ it
->pixel_width
9431 - it
->last_visible_x
;
9432 if (FRAME_WINDOW_P (it
->f
))
9434 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
9435 struct font
*face_font
= face
->font
;
9437 /* When display_line produces a continued line
9438 that ends in a TAB, it skips a tab stop that
9439 is closer than the font's space character
9440 width (see x_produce_glyphs where it produces
9441 the stretch glyph which represents a TAB).
9442 We need to reproduce the same logic here. */
9443 eassert (face_font
);
9446 if (line_start_x
< face_font
->space_width
)
9448 += it
->tab_width
* face_font
->space_width
;
9451 set_iterator_to_next (it
, false);
9455 it
->continuation_lines_width
+= it
->current_x
;
9462 /* Reset/increment for the next run. */
9463 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9464 it
->current_x
= line_start_x
;
9467 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9469 last_height
= it
->max_ascent
+ it
->max_descent
;
9470 it
->max_ascent
= it
->max_descent
= 0;
9475 /* On text terminals, we may stop at the end of a line in the middle
9476 of a multi-character glyph. If the glyph itself is continued,
9477 i.e. it is actually displayed on the next line, don't treat this
9478 stopping point as valid; move to the next line instead (unless
9479 that brings us offscreen). */
9480 if (!FRAME_WINDOW_P (it
->f
)
9482 && IT_CHARPOS (*it
) == to_charpos
9483 && it
->what
== IT_CHARACTER
9485 && it
->line_wrap
== WINDOW_WRAP
9486 && it
->current_x
== it
->last_visible_x
- 1
9489 && it
->w
->window_end_valid
9490 && it
->vpos
< it
->w
->window_end_vpos
)
9492 it
->continuation_lines_width
+= it
->current_x
;
9493 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9494 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9496 last_height
= it
->max_ascent
+ it
->max_descent
;
9500 bidi_unshelve_cache (backup_data
, true);
9502 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9504 return max_current_x
;
9508 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9510 If DY > 0, move IT backward at least that many pixels. DY = 0
9511 means move IT backward to the preceding line start or BEGV. This
9512 function may move over more than DY pixels if IT->current_y - DY
9513 ends up in the middle of a line; in this case IT->current_y will be
9514 set to the top of the line moved to. */
9517 move_it_vertically_backward (struct it
*it
, int dy
)
9521 void *it2data
= NULL
, *it3data
= NULL
;
9522 ptrdiff_t start_pos
;
9524 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9525 ptrdiff_t pos_limit
;
9530 start_pos
= IT_CHARPOS (*it
);
9532 /* Estimate how many newlines we must move back. */
9533 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9534 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9537 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9539 /* Set the iterator's position that many lines back. But don't go
9540 back more than NLINES full screen lines -- this wins a day with
9541 buffers which have very long lines. */
9542 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9543 back_to_previous_visible_line_start (it
);
9545 /* Reseat the iterator here. When moving backward, we don't want
9546 reseat to skip forward over invisible text, set up the iterator
9547 to deliver from overlay strings at the new position etc. So,
9548 use reseat_1 here. */
9549 reseat_1 (it
, it
->current
.pos
, true);
9551 /* We are now surely at a line start. */
9552 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9553 reordering is in effect. */
9554 it
->continuation_lines_width
= 0;
9556 /* Move forward and see what y-distance we moved. First move to the
9557 start of the next line so that we get its height. We need this
9558 height to be able to tell whether we reached the specified
9560 SAVE_IT (it2
, *it
, it2data
);
9561 it2
.max_ascent
= it2
.max_descent
= 0;
9564 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9565 MOVE_TO_POS
| MOVE_TO_VPOS
);
9567 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9568 /* If we are in a display string which starts at START_POS,
9569 and that display string includes a newline, and we are
9570 right after that newline (i.e. at the beginning of a
9571 display line), exit the loop, because otherwise we will
9572 infloop, since move_it_to will see that it is already at
9573 START_POS and will not move. */
9574 || (it2
.method
== GET_FROM_STRING
9575 && IT_CHARPOS (it2
) == start_pos
9576 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9577 eassert (IT_CHARPOS (*it
) >= BEGV
);
9578 SAVE_IT (it3
, it2
, it3data
);
9580 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9581 eassert (IT_CHARPOS (*it
) >= BEGV
);
9582 /* H is the actual vertical distance from the position in *IT
9583 and the starting position. */
9584 h
= it2
.current_y
- it
->current_y
;
9585 /* NLINES is the distance in number of lines. */
9586 nlines
= it2
.vpos
- it
->vpos
;
9588 /* Correct IT's y and vpos position
9589 so that they are relative to the starting point. */
9595 /* DY == 0 means move to the start of the screen line. The
9596 value of nlines is > 0 if continuation lines were involved,
9597 or if the original IT position was at start of a line. */
9598 RESTORE_IT (it
, it
, it2data
);
9600 move_it_by_lines (it
, nlines
);
9601 /* The above code moves us to some position NLINES down,
9602 usually to its first glyph (leftmost in an L2R line), but
9603 that's not necessarily the start of the line, under bidi
9604 reordering. We want to get to the character position
9605 that is immediately after the newline of the previous
9608 && !it
->continuation_lines_width
9609 && !STRINGP (it
->string
)
9610 && IT_CHARPOS (*it
) > BEGV
9611 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9613 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9616 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9617 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9619 bidi_unshelve_cache (it3data
, true);
9623 /* The y-position we try to reach, relative to *IT.
9624 Note that H has been subtracted in front of the if-statement. */
9625 int target_y
= it
->current_y
+ h
- dy
;
9626 int y0
= it3
.current_y
;
9630 RESTORE_IT (&it3
, &it3
, it3data
);
9631 y1
= line_bottom_y (&it3
);
9632 line_height
= y1
- y0
;
9633 RESTORE_IT (it
, it
, it2data
);
9634 /* If we did not reach target_y, try to move further backward if
9635 we can. If we moved too far backward, try to move forward. */
9636 if (target_y
< it
->current_y
9637 /* This is heuristic. In a window that's 3 lines high, with
9638 a line height of 13 pixels each, recentering with point
9639 on the bottom line will try to move -39/2 = 19 pixels
9640 backward. Try to avoid moving into the first line. */
9641 && (it
->current_y
- target_y
9642 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9643 && IT_CHARPOS (*it
) > BEGV
)
9645 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9646 target_y
- it
->current_y
));
9647 dy
= it
->current_y
- target_y
;
9648 goto move_further_back
;
9650 else if (target_y
>= it
->current_y
+ line_height
9651 && IT_CHARPOS (*it
) < ZV
)
9653 /* Should move forward by at least one line, maybe more.
9655 Note: Calling move_it_by_lines can be expensive on
9656 terminal frames, where compute_motion is used (via
9657 vmotion) to do the job, when there are very long lines
9658 and truncate-lines is nil. That's the reason for
9659 treating terminal frames specially here. */
9661 if (!FRAME_WINDOW_P (it
->f
))
9662 move_it_vertically (it
, target_y
- it
->current_y
);
9667 move_it_by_lines (it
, 1);
9669 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9676 /* Move IT by a specified amount of pixel lines DY. DY negative means
9677 move backwards. DY = 0 means move to start of screen line. At the
9678 end, IT will be on the start of a screen line. */
9681 move_it_vertically (struct it
*it
, int dy
)
9684 move_it_vertically_backward (it
, -dy
);
9687 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9688 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9689 MOVE_TO_POS
| MOVE_TO_Y
);
9690 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9692 /* If buffer ends in ZV without a newline, move to the start of
9693 the line to satisfy the post-condition. */
9694 if (IT_CHARPOS (*it
) == ZV
9696 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9697 move_it_by_lines (it
, 0);
9702 /* Move iterator IT past the end of the text line it is in. */
9705 move_it_past_eol (struct it
*it
)
9707 enum move_it_result rc
;
9709 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9710 if (rc
== MOVE_NEWLINE_OR_CR
)
9711 set_iterator_to_next (it
, false);
9715 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9716 negative means move up. DVPOS == 0 means move to the start of the
9719 Optimization idea: If we would know that IT->f doesn't use
9720 a face with proportional font, we could be faster for
9721 truncate-lines nil. */
9724 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9727 /* The commented-out optimization uses vmotion on terminals. This
9728 gives bad results, because elements like it->what, on which
9729 callers such as pos_visible_p rely, aren't updated. */
9730 /* struct position pos;
9731 if (!FRAME_WINDOW_P (it->f))
9733 struct text_pos textpos;
9735 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9736 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9737 reseat (it, textpos, true);
9738 it->vpos += pos.vpos;
9739 it->current_y += pos.vpos;
9745 /* DVPOS == 0 means move to the start of the screen line. */
9746 move_it_vertically_backward (it
, 0);
9747 /* Let next call to line_bottom_y calculate real line height. */
9752 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9753 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9755 /* Only move to the next buffer position if we ended up in a
9756 string from display property, not in an overlay string
9757 (before-string or after-string). That is because the
9758 latter don't conceal the underlying buffer position, so
9759 we can ask to move the iterator to the exact position we
9760 are interested in. Note that, even if we are already at
9761 IT_CHARPOS (*it), the call below is not a no-op, as it
9762 will detect that we are at the end of the string, pop the
9763 iterator, and compute it->current_x and it->hpos
9765 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9766 -1, -1, -1, MOVE_TO_POS
);
9772 void *it2data
= NULL
;
9773 ptrdiff_t start_charpos
, i
;
9775 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9776 bool hit_pos_limit
= false;
9777 ptrdiff_t pos_limit
;
9779 /* Start at the beginning of the screen line containing IT's
9780 position. This may actually move vertically backwards,
9781 in case of overlays, so adjust dvpos accordingly. */
9783 move_it_vertically_backward (it
, 0);
9786 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9787 screen lines, and reseat the iterator there. */
9788 start_charpos
= IT_CHARPOS (*it
);
9789 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9792 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9794 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9795 back_to_previous_visible_line_start (it
);
9796 if (i
> 0 && IT_CHARPOS (*it
) <= pos_limit
)
9797 hit_pos_limit
= true;
9798 reseat (it
, it
->current
.pos
, true);
9800 /* Move further back if we end up in a string or an image. */
9801 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9803 /* First try to move to start of display line. */
9805 move_it_vertically_backward (it
, 0);
9807 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9809 /* If start of line is still in string or image,
9810 move further back. */
9811 back_to_previous_visible_line_start (it
);
9812 reseat (it
, it
->current
.pos
, true);
9816 it
->current_x
= it
->hpos
= 0;
9818 /* Above call may have moved too far if continuation lines
9819 are involved. Scan forward and see if it did. */
9820 SAVE_IT (it2
, *it
, it2data
);
9821 it2
.vpos
= it2
.current_y
= 0;
9822 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9823 it
->vpos
-= it2
.vpos
;
9824 it
->current_y
-= it2
.current_y
;
9825 it
->current_x
= it
->hpos
= 0;
9827 /* If we moved too far back, move IT some lines forward. */
9828 if (it2
.vpos
> -dvpos
)
9830 int delta
= it2
.vpos
+ dvpos
;
9832 RESTORE_IT (&it2
, &it2
, it2data
);
9833 SAVE_IT (it2
, *it
, it2data
);
9834 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9835 /* Move back again if we got too far ahead. */
9836 if (IT_CHARPOS (*it
) >= start_charpos
)
9837 RESTORE_IT (it
, &it2
, it2data
);
9839 bidi_unshelve_cache (it2data
, true);
9841 else if (hit_pos_limit
&& pos_limit
> BEGV
9842 && dvpos
< 0 && it2
.vpos
< -dvpos
)
9844 /* If we hit the limit, but still didn't make it far enough
9845 back, that means there's a display string with a newline
9846 covering a large chunk of text, and that caused
9847 back_to_previous_visible_line_start try to go too far.
9848 Punish those who commit such atrocities by going back
9849 until we've reached DVPOS, after lifting the limit, which
9850 could make it slow for very long lines. "If it hurts,
9853 RESTORE_IT (it
, it
, it2data
);
9854 for (i
= -dvpos
; i
> 0; --i
)
9856 back_to_previous_visible_line_start (it
);
9859 reseat_1 (it
, it
->current
.pos
, true);
9862 RESTORE_IT (it
, it
, it2data
);
9866 /* Return true if IT points into the middle of a display vector. */
9869 in_display_vector_p (struct it
*it
)
9871 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9872 && it
->current
.dpvec_index
> 0
9873 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9876 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9877 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9878 WINDOW must be a live window and defaults to the selected one. The
9879 return value is a cons of the maximum pixel-width of any text line and
9880 the maximum pixel-height of all text lines.
9882 The optional argument FROM, if non-nil, specifies the first text
9883 position and defaults to the minimum accessible position of the buffer.
9884 If FROM is t, use the minimum accessible position that starts a
9885 non-empty line. TO, if non-nil, specifies the last text position and
9886 defaults to the maximum accessible position of the buffer. If TO is t,
9887 use the maximum accessible position that ends a non-empty line.
9889 The optional argument X-LIMIT, if non-nil, specifies the maximum text
9890 width that can be returned. X-LIMIT nil or omitted, means to use the
9891 pixel-width of WINDOW's body; use this if you want to know how high
9892 WINDOW should be become in order to fit all of its buffer's text with
9893 the width of WINDOW unaltered. Use the maximum width WINDOW may assume
9894 if you intend to change WINDOW's width. In any case, text whose
9895 x-coordinate is beyond X-LIMIT is ignored. Since calculating the width
9896 of long lines can take some time, it's always a good idea to make this
9897 argument as small as possible; in particular, if the buffer contains
9898 long lines that shall be truncated anyway.
9900 The optional argument Y-LIMIT, if non-nil, specifies the maximum text
9901 height (excluding the height of the mode- or header-line, if any) that
9902 can be returned. Text lines whose y-coordinate is beyond Y-LIMIT are
9903 ignored. Since calculating the text height of a large buffer can take
9904 some time, it makes sense to specify this argument if the size of the
9905 buffer is large or unknown.
9907 Optional argument MODE-AND-HEADER-LINE nil or omitted means do not
9908 include the height of the mode- or header-line of WINDOW in the return
9909 value. If it is either the symbol `mode-line' or `header-line', include
9910 only the height of that line, if present, in the return value. If t,
9911 include the height of both, if present, in the return value. */)
9912 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
,
9913 Lisp_Object y_limit
, Lisp_Object mode_and_header_line
)
9915 struct window
*w
= decode_live_window (window
);
9916 Lisp_Object buffer
= w
->contents
;
9919 struct buffer
*old_b
= NULL
;
9920 ptrdiff_t start
, end
, pos
;
9921 struct text_pos startp
;
9922 void *itdata
= NULL
;
9923 int c
, max_x
= 0, max_y
= 0, x
= 0, y
= 0;
9925 CHECK_BUFFER (buffer
);
9926 b
= XBUFFER (buffer
);
9928 if (b
!= current_buffer
)
9930 old_b
= current_buffer
;
9931 set_buffer_internal (b
);
9936 else if (EQ (from
, Qt
))
9939 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9940 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9942 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9947 CHECK_NUMBER_COERCE_MARKER (from
);
9948 start
= min (max (XINT (from
), BEGV
), ZV
);
9953 else if (EQ (to
, Qt
))
9956 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9957 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9959 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9964 CHECK_NUMBER_COERCE_MARKER (to
);
9965 end
= max (start
, min (XINT (to
), ZV
));
9968 if (!NILP (x_limit
) && RANGED_INTEGERP (0, x_limit
, INT_MAX
))
9969 max_x
= XINT (x_limit
);
9973 else if (RANGED_INTEGERP (0, y_limit
, INT_MAX
))
9974 max_y
= XINT (y_limit
);
9976 itdata
= bidi_shelve_cache ();
9977 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9978 start_display (&it
, w
, startp
);
9981 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9984 it
.last_visible_x
= max_x
;
9985 /* Actually, we never want move_it_to stop at to_x. But to make
9986 sure that move_it_in_display_line_to always moves far enough,
9987 we set it to INT_MAX and specify MOVE_TO_X. */
9988 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9989 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9990 /* Don't return more than X-LIMIT. */
9995 /* Subtract height of header-line which was counted automatically by
9997 y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
9998 - WINDOW_HEADER_LINE_HEIGHT (w
);
9999 /* Don't return more than Y-LIMIT. */
10003 if (EQ (mode_and_header_line
, Qheader_line
)
10004 || EQ (mode_and_header_line
, Qt
))
10005 /* Re-add height of header-line as requested. */
10006 y
= y
+ WINDOW_HEADER_LINE_HEIGHT (w
);
10008 if (EQ (mode_and_header_line
, Qmode_line
)
10009 || EQ (mode_and_header_line
, Qt
))
10010 /* Add height of mode-line as requested. */
10011 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
10013 bidi_unshelve_cache (itdata
, false);
10016 set_buffer_internal (old_b
);
10018 return Fcons (make_number (x
), make_number (y
));
10021 /***********************************************************************
10023 ***********************************************************************/
10025 /* Return the number of arguments the format string FORMAT needs. */
10028 format_nargs (char const *format
)
10030 ptrdiff_t nargs
= 0;
10031 for (char const *p
= format
; (p
= strchr (p
, '%')); p
++)
10039 /* Add a message with format string FORMAT and formatted arguments
10043 add_to_log (const char *format
, ...)
10046 va_start (ap
, format
);
10047 vadd_to_log (format
, ap
);
10052 vadd_to_log (char const *format
, va_list ap
)
10054 ptrdiff_t form_nargs
= format_nargs (format
);
10055 ptrdiff_t nargs
= 1 + form_nargs
;
10056 Lisp_Object args
[10];
10057 eassert (nargs
<= ARRAYELTS (args
));
10058 AUTO_STRING (args0
, format
);
10060 for (ptrdiff_t i
= 1; i
<= nargs
; i
++)
10061 args
[i
] = va_arg (ap
, Lisp_Object
);
10062 Lisp_Object msg
= Qnil
;
10063 msg
= Fformat_message (nargs
, args
);
10065 ptrdiff_t len
= SBYTES (msg
) + 1;
10067 char *buffer
= SAFE_ALLOCA (len
);
10068 memcpy (buffer
, SDATA (msg
), len
);
10070 message_dolog (buffer
, len
- 1, true, STRING_MULTIBYTE (msg
));
10075 /* Output a newline in the *Messages* buffer if "needs" one. */
10078 message_log_maybe_newline (void)
10080 if (message_log_need_newline
)
10081 message_dolog ("", 0, true, false);
10085 /* Add a string M of length NBYTES to the message log, optionally
10086 terminated with a newline when NLFLAG is true. MULTIBYTE, if
10087 true, means interpret the contents of M as multibyte. This
10088 function calls low-level routines in order to bypass text property
10089 hooks, etc. which might not be safe to run.
10091 This may GC (insert may run before/after change hooks),
10092 so the buffer M must NOT point to a Lisp string. */
10095 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
10097 const unsigned char *msg
= (const unsigned char *) m
;
10099 if (!NILP (Vmemory_full
))
10102 if (!NILP (Vmessage_log_max
))
10104 struct buffer
*oldbuf
;
10105 Lisp_Object oldpoint
, oldbegv
, oldzv
;
10106 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
10107 ptrdiff_t point_at_end
= 0;
10108 ptrdiff_t zv_at_end
= 0;
10109 Lisp_Object old_deactivate_mark
;
10111 old_deactivate_mark
= Vdeactivate_mark
;
10112 oldbuf
= current_buffer
;
10114 /* Ensure the Messages buffer exists, and switch to it.
10115 If we created it, set the major-mode. */
10116 bool newbuffer
= NILP (Fget_buffer (Vmessages_buffer_name
));
10117 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
10119 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
10120 call0 (intern ("messages-buffer-mode"));
10122 bset_undo_list (current_buffer
, Qt
);
10123 bset_cache_long_scans (current_buffer
, Qnil
);
10125 oldpoint
= message_dolog_marker1
;
10126 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
10127 oldbegv
= message_dolog_marker2
;
10128 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
10129 oldzv
= message_dolog_marker3
;
10130 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
10138 BEGV_BYTE
= BEG_BYTE
;
10141 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10143 /* Insert the string--maybe converting multibyte to single byte
10144 or vice versa, so that all the text fits the buffer. */
10146 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10152 /* Convert a multibyte string to single-byte
10153 for the *Message* buffer. */
10154 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
10156 c
= string_char_and_length (msg
+ i
, &char_bytes
);
10157 work
[0] = CHAR_TO_BYTE8 (c
);
10158 insert_1_both (work
, 1, 1, true, false, false);
10161 else if (! multibyte
10162 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10166 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10167 /* Convert a single-byte string to multibyte
10168 for the *Message* buffer. */
10169 for (i
= 0; i
< nbytes
; i
++)
10172 MAKE_CHAR_MULTIBYTE (c
);
10173 char_bytes
= CHAR_STRING (c
, str
);
10174 insert_1_both ((char *) str
, 1, char_bytes
, true, false, false);
10178 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
,
10179 true, false, false);
10183 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
10186 insert_1_both ("\n", 1, 1, true, false, false);
10188 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, false);
10190 this_bol_byte
= PT_BYTE
;
10192 /* See if this line duplicates the previous one.
10193 If so, combine duplicates. */
10194 if (this_bol
> BEG
)
10196 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, false);
10198 prev_bol_byte
= PT_BYTE
;
10200 dups
= message_log_check_duplicate (prev_bol_byte
,
10204 del_range_both (prev_bol
, prev_bol_byte
,
10205 this_bol
, this_bol_byte
, false);
10208 char dupstr
[sizeof " [ times]"
10209 + INT_STRLEN_BOUND (printmax_t
)];
10211 /* If you change this format, don't forget to also
10212 change message_log_check_duplicate. */
10213 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
10214 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
10215 insert_1_both (dupstr
, duplen
, duplen
,
10216 true, false, true);
10221 /* If we have more than the desired maximum number of lines
10222 in the *Messages* buffer now, delete the oldest ones.
10223 This is safe because we don't have undo in this buffer. */
10225 if (NATNUMP (Vmessage_log_max
))
10227 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
10228 -XFASTINT (Vmessage_log_max
) - 1, false);
10229 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, false);
10232 BEGV
= marker_position (oldbegv
);
10233 BEGV_BYTE
= marker_byte_position (oldbegv
);
10242 ZV
= marker_position (oldzv
);
10243 ZV_BYTE
= marker_byte_position (oldzv
);
10247 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10249 /* We can't do Fgoto_char (oldpoint) because it will run some
10251 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
10252 marker_byte_position (oldpoint
));
10254 unchain_marker (XMARKER (oldpoint
));
10255 unchain_marker (XMARKER (oldbegv
));
10256 unchain_marker (XMARKER (oldzv
));
10258 /* We called insert_1_both above with its 5th argument (PREPARE)
10259 false, which prevents insert_1_both from calling
10260 prepare_to_modify_buffer, which in turns prevents us from
10261 incrementing windows_or_buffers_changed even if *Messages* is
10262 shown in some window. So we must manually set
10263 windows_or_buffers_changed here to make up for that. */
10264 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
10265 bset_redisplay (current_buffer
);
10267 set_buffer_internal (oldbuf
);
10269 message_log_need_newline
= !nlflag
;
10270 Vdeactivate_mark
= old_deactivate_mark
;
10275 /* We are at the end of the buffer after just having inserted a newline.
10276 (Note: We depend on the fact we won't be crossing the gap.)
10277 Check to see if the most recent message looks a lot like the previous one.
10278 Return 0 if different, 1 if the new one should just replace it, or a
10279 value N > 1 if we should also append " [N times]". */
10282 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
10285 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
10286 bool seen_dots
= false;
10287 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
10288 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
10290 for (i
= 0; i
< len
; i
++)
10292 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
10294 if (p1
[i
] != p2
[i
])
10300 if (*p1
++ == ' ' && *p1
++ == '[')
10303 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
10304 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
10311 /* Display an echo area message M with a specified length of NBYTES
10312 bytes. The string may include null characters. If M is not a
10313 string, clear out any existing message, and let the mini-buffer
10316 This function cancels echoing. */
10319 message3 (Lisp_Object m
)
10321 clear_message (true, true);
10324 /* First flush out any partial line written with print. */
10325 message_log_maybe_newline ();
10328 ptrdiff_t nbytes
= SBYTES (m
);
10329 bool multibyte
= STRING_MULTIBYTE (m
);
10332 SAFE_ALLOCA_STRING (buffer
, m
);
10333 message_dolog (buffer
, nbytes
, true, multibyte
);
10336 if (! inhibit_message
)
10337 message3_nolog (m
);
10340 /* Log the message M to stderr. Log an empty line if M is not a string. */
10343 message_to_stderr (Lisp_Object m
)
10345 if (noninteractive_need_newline
)
10347 noninteractive_need_newline
= false;
10348 fputc ('\n', stderr
);
10352 Lisp_Object coding_system
= Vlocale_coding_system
;
10355 if (!NILP (Vcoding_system_for_write
))
10356 coding_system
= Vcoding_system_for_write
;
10357 if (!NILP (coding_system
))
10358 s
= code_convert_string_norecord (m
, coding_system
, true);
10362 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
10364 if (!cursor_in_echo_area
)
10365 fputc ('\n', stderr
);
10369 /* The non-logging version of message3.
10370 This does not cancel echoing, because it is used for echoing.
10371 Perhaps we need to make a separate function for echoing
10372 and make this cancel echoing. */
10375 message3_nolog (Lisp_Object m
)
10377 struct frame
*sf
= SELECTED_FRAME ();
10379 if (FRAME_INITIAL_P (sf
))
10380 message_to_stderr (m
);
10381 /* Error messages get reported properly by cmd_error, so this must be just an
10382 informative message; if the frame hasn't really been initialized yet, just
10384 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
10386 /* Get the frame containing the mini-buffer
10387 that the selected frame is using. */
10388 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10389 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
10390 struct frame
*f
= XFRAME (frame
);
10392 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
10393 Fmake_frame_visible (frame
);
10395 if (STRINGP (m
) && SCHARS (m
) > 0)
10398 if (minibuffer_auto_raise
)
10399 Fraise_frame (frame
);
10400 /* Assume we are not echoing.
10401 (If we are, echo_now will override this.) */
10402 echo_message_buffer
= Qnil
;
10405 clear_message (true, true);
10407 do_pending_window_change (false);
10408 echo_area_display (true);
10409 do_pending_window_change (false);
10410 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
10411 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
10416 /* Display a null-terminated echo area message M. If M is 0, clear
10417 out any existing message, and let the mini-buffer text show through.
10419 The buffer M must continue to exist until after the echo area gets
10420 cleared or some other message gets displayed there. Do not pass
10421 text that is stored in a Lisp string. Do not pass text in a buffer
10422 that was alloca'd. */
10425 message1 (const char *m
)
10427 message3 (m
? build_unibyte_string (m
) : Qnil
);
10431 /* The non-logging counterpart of message1. */
10434 message1_nolog (const char *m
)
10436 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10439 /* Display a message M which contains a single %s
10440 which gets replaced with STRING. */
10443 message_with_string (const char *m
, Lisp_Object string
, bool log
)
10445 CHECK_STRING (string
);
10448 if (noninteractive
)
10449 need_message
= !!m
;
10450 else if (!INTERACTIVE
)
10451 need_message
= false;
10454 /* The frame whose minibuffer we're going to display the message on.
10455 It may be larger than the selected frame, so we need
10456 to use its buffer, not the selected frame's buffer. */
10457 Lisp_Object mini_window
;
10458 struct frame
*f
, *sf
= SELECTED_FRAME ();
10460 /* Get the frame containing the minibuffer
10461 that the selected frame is using. */
10462 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10463 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10465 /* Error messages get reported properly by cmd_error, so this must be
10466 just an informative message; if the frame hasn't really been
10467 initialized yet, just toss it. */
10468 need_message
= f
->glyphs_initialized_p
;
10473 AUTO_STRING (fmt
, m
);
10474 Lisp_Object msg
= CALLN (Fformat_message
, fmt
, string
);
10476 if (noninteractive
)
10477 message_to_stderr (msg
);
10483 message3_nolog (msg
);
10485 /* Print should start at the beginning of the message
10486 buffer next time. */
10487 message_buf_print
= false;
10493 /* Dump an informative message to the minibuf. If M is 0, clear out
10494 any existing message, and let the mini-buffer text show through.
10496 The message must be safe ASCII and the format must not contain ` or
10497 '. If your message and format do not fit into this category,
10498 convert your arguments to Lisp objects and use Fmessage instead. */
10500 static void ATTRIBUTE_FORMAT_PRINTF (1, 0)
10501 vmessage (const char *m
, va_list ap
)
10503 if (noninteractive
)
10507 if (noninteractive_need_newline
)
10508 putc ('\n', stderr
);
10509 noninteractive_need_newline
= false;
10510 vfprintf (stderr
, m
, ap
);
10511 if (!cursor_in_echo_area
)
10512 fprintf (stderr
, "\n");
10516 else if (INTERACTIVE
)
10518 /* The frame whose mini-buffer we're going to display the message
10519 on. It may be larger than the selected frame, so we need to
10520 use its buffer, not the selected frame's buffer. */
10521 Lisp_Object mini_window
;
10522 struct frame
*f
, *sf
= SELECTED_FRAME ();
10524 /* Get the frame containing the mini-buffer
10525 that the selected frame is using. */
10526 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10527 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10529 /* Error messages get reported properly by cmd_error, so this must be
10530 just an informative message; if the frame hasn't really been
10531 initialized yet, just toss it. */
10532 if (f
->glyphs_initialized_p
)
10537 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10539 char *message_buf
= SAFE_ALLOCA (maxsize
+ 1);
10541 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10543 message3 (make_string (message_buf
, len
));
10549 /* Print should start at the beginning of the message
10550 buffer next time. */
10551 message_buf_print
= false;
10557 message (const char *m
, ...)
10566 /* Display the current message in the current mini-buffer. This is
10567 only called from error handlers in process.c, and is not time
10571 update_echo_area (void)
10573 if (!NILP (echo_area_buffer
[0]))
10575 Lisp_Object string
;
10576 string
= Fcurrent_message ();
10582 /* Make sure echo area buffers in `echo_buffers' are live.
10583 If they aren't, make new ones. */
10586 ensure_echo_area_buffers (void)
10588 for (int i
= 0; i
< 2; i
++)
10589 if (!BUFFERP (echo_buffer
[i
])
10590 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10592 Lisp_Object old_buffer
= echo_buffer
[i
];
10593 static char const name_fmt
[] = " *Echo Area %d*";
10594 char name
[sizeof name_fmt
+ INT_STRLEN_BOUND (int)];
10595 AUTO_STRING_WITH_LEN (lname
, name
, sprintf (name
, name_fmt
, i
));
10596 echo_buffer
[i
] = Fget_buffer_create (lname
);
10597 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10598 /* to force word wrap in echo area -
10599 it was decided to postpone this*/
10600 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10602 for (int j
= 0; j
< 2; j
++)
10603 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10604 echo_area_buffer
[j
] = echo_buffer
[i
];
10609 /* Call FN with args A1..A2 with either the current or last displayed
10610 echo_area_buffer as current buffer.
10612 WHICH zero means use the current message buffer
10613 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10614 from echo_buffer[] and clear it.
10616 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10617 suitable buffer from echo_buffer[] and clear it.
10619 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10620 that the current message becomes the last displayed one, choose a
10621 suitable buffer for echo_area_buffer[0], and clear it.
10623 Value is what FN returns. */
10626 with_echo_area_buffer (struct window
*w
, int which
,
10627 bool (*fn
) (ptrdiff_t, Lisp_Object
),
10628 ptrdiff_t a1
, Lisp_Object a2
)
10630 Lisp_Object buffer
;
10631 bool this_one
, the_other
, clear_buffer_p
, rc
;
10632 ptrdiff_t count
= SPECPDL_INDEX ();
10634 /* If buffers aren't live, make new ones. */
10635 ensure_echo_area_buffers ();
10637 clear_buffer_p
= false;
10640 this_one
= false, the_other
= true;
10641 else if (which
> 0)
10642 this_one
= true, the_other
= false;
10645 this_one
= false, the_other
= true;
10646 clear_buffer_p
= true;
10648 /* We need a fresh one in case the current echo buffer equals
10649 the one containing the last displayed echo area message. */
10650 if (!NILP (echo_area_buffer
[this_one
])
10651 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10652 echo_area_buffer
[this_one
] = Qnil
;
10655 /* Choose a suitable buffer from echo_buffer[] if we don't
10657 if (NILP (echo_area_buffer
[this_one
]))
10659 echo_area_buffer
[this_one
]
10660 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10661 ? echo_buffer
[the_other
]
10662 : echo_buffer
[this_one
]);
10663 clear_buffer_p
= true;
10666 buffer
= echo_area_buffer
[this_one
];
10668 /* Don't get confused by reusing the buffer used for echoing
10669 for a different purpose. */
10670 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10673 record_unwind_protect (unwind_with_echo_area_buffer
,
10674 with_echo_area_buffer_unwind_data (w
));
10676 /* Make the echo area buffer current. Note that for display
10677 purposes, it is not necessary that the displayed window's buffer
10678 == current_buffer, except for text property lookup. So, let's
10679 only set that buffer temporarily here without doing a full
10680 Fset_window_buffer. We must also change w->pointm, though,
10681 because otherwise an assertions in unshow_buffer fails, and Emacs
10683 set_buffer_internal_1 (XBUFFER (buffer
));
10686 wset_buffer (w
, buffer
);
10687 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10688 set_marker_both (w
->old_pointm
, buffer
, BEG
, BEG_BYTE
);
10691 bset_undo_list (current_buffer
, Qt
);
10692 bset_read_only (current_buffer
, Qnil
);
10693 specbind (Qinhibit_read_only
, Qt
);
10694 specbind (Qinhibit_modification_hooks
, Qt
);
10696 if (clear_buffer_p
&& Z
> BEG
)
10697 del_range (BEG
, Z
);
10699 eassert (BEGV
>= BEG
);
10700 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10704 eassert (BEGV
>= BEG
);
10705 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10707 unbind_to (count
, Qnil
);
10712 /* Save state that should be preserved around the call to the function
10713 FN called in with_echo_area_buffer. */
10716 with_echo_area_buffer_unwind_data (struct window
*w
)
10719 Lisp_Object vector
, tmp
;
10721 /* Reduce consing by keeping one vector in
10722 Vwith_echo_area_save_vector. */
10723 vector
= Vwith_echo_area_save_vector
;
10724 Vwith_echo_area_save_vector
= Qnil
;
10727 vector
= Fmake_vector (make_number (11), Qnil
);
10729 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10730 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10731 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10735 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10736 ASET (vector
, i
, w
->contents
); ++i
;
10737 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10738 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10739 ASET (vector
, i
, make_number (marker_position (w
->old_pointm
))); ++i
;
10740 ASET (vector
, i
, make_number (marker_byte_position (w
->old_pointm
))); ++i
;
10741 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10742 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10747 for (; i
< end
; ++i
)
10748 ASET (vector
, i
, Qnil
);
10751 eassert (i
== ASIZE (vector
));
10756 /* Restore global state from VECTOR which was created by
10757 with_echo_area_buffer_unwind_data. */
10760 unwind_with_echo_area_buffer (Lisp_Object vector
)
10762 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10763 Vdeactivate_mark
= AREF (vector
, 1);
10764 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10766 if (WINDOWP (AREF (vector
, 3)))
10769 Lisp_Object buffer
;
10771 w
= XWINDOW (AREF (vector
, 3));
10772 buffer
= AREF (vector
, 4);
10774 wset_buffer (w
, buffer
);
10775 set_marker_both (w
->pointm
, buffer
,
10776 XFASTINT (AREF (vector
, 5)),
10777 XFASTINT (AREF (vector
, 6)));
10778 set_marker_both (w
->old_pointm
, buffer
,
10779 XFASTINT (AREF (vector
, 7)),
10780 XFASTINT (AREF (vector
, 8)));
10781 set_marker_both (w
->start
, buffer
,
10782 XFASTINT (AREF (vector
, 9)),
10783 XFASTINT (AREF (vector
, 10)));
10786 Vwith_echo_area_save_vector
= vector
;
10790 /* Set up the echo area for use by print functions. MULTIBYTE_P
10791 means we will print multibyte. */
10794 setup_echo_area_for_printing (bool multibyte_p
)
10796 /* If we can't find an echo area any more, exit. */
10797 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10798 Fkill_emacs (Qnil
);
10800 ensure_echo_area_buffers ();
10802 if (!message_buf_print
)
10804 /* A message has been output since the last time we printed.
10805 Choose a fresh echo area buffer. */
10806 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10807 echo_area_buffer
[0] = echo_buffer
[1];
10809 echo_area_buffer
[0] = echo_buffer
[0];
10811 /* Switch to that buffer and clear it. */
10812 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10813 bset_truncate_lines (current_buffer
, Qnil
);
10817 ptrdiff_t count
= SPECPDL_INDEX ();
10818 specbind (Qinhibit_read_only
, Qt
);
10819 /* Note that undo recording is always disabled. */
10820 del_range (BEG
, Z
);
10821 unbind_to (count
, Qnil
);
10823 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10825 /* Set up the buffer for the multibyteness we need. */
10827 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10828 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10830 /* Raise the frame containing the echo area. */
10831 if (minibuffer_auto_raise
)
10833 struct frame
*sf
= SELECTED_FRAME ();
10834 Lisp_Object mini_window
;
10835 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10836 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10839 message_log_maybe_newline ();
10840 message_buf_print
= true;
10844 if (NILP (echo_area_buffer
[0]))
10846 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10847 echo_area_buffer
[0] = echo_buffer
[1];
10849 echo_area_buffer
[0] = echo_buffer
[0];
10852 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10854 /* Someone switched buffers between print requests. */
10855 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10856 bset_truncate_lines (current_buffer
, Qnil
);
10862 /* Display an echo area message in window W. Value is true if W's
10863 height is changed. If display_last_displayed_message_p,
10864 display the message that was last displayed, otherwise
10865 display the current message. */
10868 display_echo_area (struct window
*w
)
10870 bool no_message_p
, window_height_changed_p
;
10872 /* Temporarily disable garbage collections while displaying the echo
10873 area. This is done because a GC can print a message itself.
10874 That message would modify the echo area buffer's contents while a
10875 redisplay of the buffer is going on, and seriously confuse
10877 ptrdiff_t count
= inhibit_garbage_collection ();
10879 /* If there is no message, we must call display_echo_area_1
10880 nevertheless because it resizes the window. But we will have to
10881 reset the echo_area_buffer in question to nil at the end because
10882 with_echo_area_buffer will sets it to an empty buffer. */
10883 bool i
= display_last_displayed_message_p
;
10884 /* According to the C99, C11 and C++11 standards, the integral value
10885 of a "bool" is always 0 or 1, so this array access is safe here,
10887 no_message_p
= NILP (echo_area_buffer
[i
]);
10889 window_height_changed_p
10890 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10891 display_echo_area_1
,
10892 (intptr_t) w
, Qnil
);
10895 echo_area_buffer
[i
] = Qnil
;
10897 unbind_to (count
, Qnil
);
10898 return window_height_changed_p
;
10902 /* Helper for display_echo_area. Display the current buffer which
10903 contains the current echo area message in window W, a mini-window,
10904 a pointer to which is passed in A1. A2..A4 are currently not used.
10905 Change the height of W so that all of the message is displayed.
10906 Value is true if height of W was changed. */
10909 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10912 struct window
*w
= (struct window
*) i1
;
10913 Lisp_Object window
;
10914 struct text_pos start
;
10916 /* We are about to enter redisplay without going through
10917 redisplay_internal, so we need to forget these faces by hand
10919 forget_escape_and_glyphless_faces ();
10921 /* Do this before displaying, so that we have a large enough glyph
10922 matrix for the display. If we can't get enough space for the
10923 whole text, display the last N lines. That works by setting w->start. */
10924 bool window_height_changed_p
= resize_mini_window (w
, false);
10926 /* Use the starting position chosen by resize_mini_window. */
10927 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10930 clear_glyph_matrix (w
->desired_matrix
);
10931 XSETWINDOW (window
, w
);
10932 try_window (window
, start
, 0);
10934 return window_height_changed_p
;
10938 /* Resize the echo area window to exactly the size needed for the
10939 currently displayed message, if there is one. If a mini-buffer
10940 is active, don't shrink it. */
10943 resize_echo_area_exactly (void)
10945 if (BUFFERP (echo_area_buffer
[0])
10946 && WINDOWP (echo_area_window
))
10948 struct window
*w
= XWINDOW (echo_area_window
);
10949 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10950 bool resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10951 (intptr_t) w
, resize_exactly
);
10954 windows_or_buffers_changed
= 42;
10955 update_mode_lines
= 30;
10956 redisplay_internal ();
10962 /* Callback function for with_echo_area_buffer, when used from
10963 resize_echo_area_exactly. A1 contains a pointer to the window to
10964 resize, EXACTLY non-nil means resize the mini-window exactly to the
10965 size of the text displayed. A3 and A4 are not used. Value is what
10966 resize_mini_window returns. */
10969 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10972 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10976 /* Resize mini-window W to fit the size of its contents. EXACT_P
10977 means size the window exactly to the size needed. Otherwise, it's
10978 only enlarged until W's buffer is empty.
10980 Set W->start to the right place to begin display. If the whole
10981 contents fit, start at the beginning. Otherwise, start so as
10982 to make the end of the contents appear. This is particularly
10983 important for y-or-n-p, but seems desirable generally.
10985 Value is true if the window height has been changed. */
10988 resize_mini_window (struct window
*w
, bool exact_p
)
10990 struct frame
*f
= XFRAME (w
->frame
);
10991 bool window_height_changed_p
= false;
10993 eassert (MINI_WINDOW_P (w
));
10995 /* By default, start display at the beginning. */
10996 set_marker_both (w
->start
, w
->contents
,
10997 BUF_BEGV (XBUFFER (w
->contents
)),
10998 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
11000 /* Don't resize windows while redisplaying a window; it would
11001 confuse redisplay functions when the size of the window they are
11002 displaying changes from under them. Such a resizing can happen,
11003 for instance, when which-func prints a long message while
11004 we are running fontification-functions. We're running these
11005 functions with safe_call which binds inhibit-redisplay to t. */
11006 if (!NILP (Vinhibit_redisplay
))
11009 /* Nil means don't try to resize. */
11010 if (NILP (Vresize_mini_windows
)
11011 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
11014 if (!FRAME_MINIBUF_ONLY_P (f
))
11017 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
11018 + WINDOW_PIXEL_HEIGHT (w
));
11019 int unit
= FRAME_LINE_HEIGHT (f
);
11020 int height
, max_height
;
11021 struct text_pos start
;
11022 struct buffer
*old_current_buffer
= NULL
;
11024 if (current_buffer
!= XBUFFER (w
->contents
))
11026 old_current_buffer
= current_buffer
;
11027 set_buffer_internal (XBUFFER (w
->contents
));
11030 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
11032 /* Compute the max. number of lines specified by the user. */
11033 if (FLOATP (Vmax_mini_window_height
))
11034 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
11035 else if (INTEGERP (Vmax_mini_window_height
))
11036 max_height
= XINT (Vmax_mini_window_height
) * unit
;
11038 max_height
= total_height
/ 4;
11040 /* Correct that max. height if it's bogus. */
11041 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
11043 /* Find out the height of the text in the window. */
11044 if (it
.line_wrap
== TRUNCATE
)
11049 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
11050 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
11051 height
= it
.current_y
+ last_height
;
11053 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
11054 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
11057 /* Compute a suitable window start. */
11058 if (height
> max_height
)
11060 height
= (max_height
/ unit
) * unit
;
11061 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
11062 move_it_vertically_backward (&it
, height
- unit
);
11063 start
= it
.current
.pos
;
11066 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
11067 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
11069 if (EQ (Vresize_mini_windows
, Qgrow_only
))
11071 /* Let it grow only, until we display an empty message, in which
11072 case the window shrinks again. */
11073 if (height
> WINDOW_PIXEL_HEIGHT (w
))
11075 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11077 FRAME_WINDOWS_FROZEN (f
) = true;
11078 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
11079 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11081 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
11082 && (exact_p
|| BEGV
== ZV
))
11084 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11086 FRAME_WINDOWS_FROZEN (f
) = false;
11087 shrink_mini_window (w
, true);
11088 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11093 /* Always resize to exact size needed. */
11094 if (height
> WINDOW_PIXEL_HEIGHT (w
))
11096 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11098 FRAME_WINDOWS_FROZEN (f
) = true;
11099 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
11100 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11102 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
11104 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11106 FRAME_WINDOWS_FROZEN (f
) = false;
11107 shrink_mini_window (w
, true);
11111 FRAME_WINDOWS_FROZEN (f
) = true;
11112 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
11115 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11119 if (old_current_buffer
)
11120 set_buffer_internal (old_current_buffer
);
11123 return window_height_changed_p
;
11127 /* Value is the current message, a string, or nil if there is no
11128 current message. */
11131 current_message (void)
11135 if (!BUFFERP (echo_area_buffer
[0]))
11139 with_echo_area_buffer (0, 0, current_message_1
,
11140 (intptr_t) &msg
, Qnil
);
11142 echo_area_buffer
[0] = Qnil
;
11150 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
11153 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
11156 *msg
= make_buffer_string (BEG
, Z
, true);
11163 /* Push the current message on Vmessage_stack for later restoration
11164 by restore_message. Value is true if the current message isn't
11165 empty. This is a relatively infrequent operation, so it's not
11166 worth optimizing. */
11169 push_message (void)
11171 Lisp_Object msg
= current_message ();
11172 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
11173 return STRINGP (msg
);
11177 /* Restore message display from the top of Vmessage_stack. */
11180 restore_message (void)
11182 eassert (CONSP (Vmessage_stack
));
11183 message3_nolog (XCAR (Vmessage_stack
));
11187 /* Handler for unwind-protect calling pop_message. */
11190 pop_message_unwind (void)
11192 /* Pop the top-most entry off Vmessage_stack. */
11193 eassert (CONSP (Vmessage_stack
));
11194 Vmessage_stack
= XCDR (Vmessage_stack
);
11198 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
11199 exits. If the stack is not empty, we have a missing pop_message
11203 check_message_stack (void)
11205 if (!NILP (Vmessage_stack
))
11210 /* Truncate to NCHARS what will be displayed in the echo area the next
11211 time we display it---but don't redisplay it now. */
11214 truncate_echo_area (ptrdiff_t nchars
)
11217 echo_area_buffer
[0] = Qnil
;
11218 else if (!noninteractive
11220 && !NILP (echo_area_buffer
[0]))
11222 struct frame
*sf
= SELECTED_FRAME ();
11223 /* Error messages get reported properly by cmd_error, so this must be
11224 just an informative message; if the frame hasn't really been
11225 initialized yet, just toss it. */
11226 if (sf
->glyphs_initialized_p
)
11227 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
11232 /* Helper function for truncate_echo_area. Truncate the current
11233 message to at most NCHARS characters. */
11236 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
11238 if (BEG
+ nchars
< Z
)
11239 del_range (BEG
+ nchars
, Z
);
11241 echo_area_buffer
[0] = Qnil
;
11245 /* Set the current message to STRING. */
11248 set_message (Lisp_Object string
)
11250 eassert (STRINGP (string
));
11252 message_enable_multibyte
= STRING_MULTIBYTE (string
);
11254 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
11255 message_buf_print
= false;
11256 help_echo_showing_p
= false;
11258 if (STRINGP (Vdebug_on_message
)
11259 && STRINGP (string
)
11260 && fast_string_match (Vdebug_on_message
, string
) >= 0)
11261 call_debugger (list2 (Qerror
, string
));
11265 /* Helper function for set_message. First argument is ignored and second
11266 argument has the same meaning as for set_message.
11267 This function is called with the echo area buffer being current. */
11270 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
11272 eassert (STRINGP (string
));
11274 /* Change multibyteness of the echo buffer appropriately. */
11275 if (message_enable_multibyte
11276 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
11277 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
11279 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
11280 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
11281 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
11283 /* Insert new message at BEG. */
11284 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
11286 /* This function takes care of single/multibyte conversion.
11287 We just have to ensure that the echo area buffer has the right
11288 setting of enable_multibyte_characters. */
11289 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), true);
11295 /* Clear messages. CURRENT_P means clear the current message.
11296 LAST_DISPLAYED_P means clear the message last displayed. */
11299 clear_message (bool current_p
, bool last_displayed_p
)
11303 echo_area_buffer
[0] = Qnil
;
11304 message_cleared_p
= true;
11307 if (last_displayed_p
)
11308 echo_area_buffer
[1] = Qnil
;
11310 message_buf_print
= false;
11313 /* Clear garbaged frames.
11315 This function is used where the old redisplay called
11316 redraw_garbaged_frames which in turn called redraw_frame which in
11317 turn called clear_frame. The call to clear_frame was a source of
11318 flickering. I believe a clear_frame is not necessary. It should
11319 suffice in the new redisplay to invalidate all current matrices,
11320 and ensure a complete redisplay of all windows. */
11323 clear_garbaged_frames (void)
11325 if (frame_garbaged
)
11327 Lisp_Object tail
, frame
;
11328 struct frame
*sf
= SELECTED_FRAME ();
11330 FOR_EACH_FRAME (tail
, frame
)
11332 struct frame
*f
= XFRAME (frame
);
11334 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
11337 /* It makes no sense to redraw a non-selected TTY
11338 frame, since that will actually clear the
11339 selected frame, and might leave the selected
11340 frame with corrupted display, if it happens not
11341 to be marked garbaged. */
11342 && !(f
!= sf
&& (FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))))
11345 clear_current_matrices (f
);
11346 fset_redisplay (f
);
11347 f
->garbaged
= false;
11348 f
->resized_p
= false;
11352 frame_garbaged
= false;
11357 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P, update
11361 echo_area_display (bool update_frame_p
)
11363 Lisp_Object mini_window
;
11366 bool window_height_changed_p
= false;
11367 struct frame
*sf
= SELECTED_FRAME ();
11369 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11370 w
= XWINDOW (mini_window
);
11371 f
= XFRAME (WINDOW_FRAME (w
));
11373 /* Don't display if frame is invisible or not yet initialized. */
11374 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
11377 #ifdef HAVE_WINDOW_SYSTEM
11378 /* When Emacs starts, selected_frame may be the initial terminal
11379 frame. If we let this through, a message would be displayed on
11381 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
11383 #endif /* HAVE_WINDOW_SYSTEM */
11385 /* Redraw garbaged frames. */
11386 clear_garbaged_frames ();
11388 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
11390 echo_area_window
= mini_window
;
11391 window_height_changed_p
= display_echo_area (w
);
11392 w
->must_be_updated_p
= true;
11394 /* Update the display, unless called from redisplay_internal.
11395 Also don't update the screen during redisplay itself. The
11396 update will happen at the end of redisplay, and an update
11397 here could cause confusion. */
11398 if (update_frame_p
&& !redisplaying_p
)
11402 /* If the display update has been interrupted by pending
11403 input, update mode lines in the frame. Due to the
11404 pending input, it might have been that redisplay hasn't
11405 been called, so that mode lines above the echo area are
11406 garbaged. This looks odd, so we prevent it here. */
11407 if (!display_completed
)
11408 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11410 if (window_height_changed_p
11411 /* Don't do this if Emacs is shutting down. Redisplay
11412 needs to run hooks. */
11413 && !NILP (Vrun_hooks
))
11415 /* Must update other windows. Likewise as in other
11416 cases, don't let this update be interrupted by
11418 ptrdiff_t count
= SPECPDL_INDEX ();
11419 specbind (Qredisplay_dont_pause
, Qt
);
11420 fset_redisplay (f
);
11421 redisplay_internal ();
11422 unbind_to (count
, Qnil
);
11424 else if (FRAME_WINDOW_P (f
) && n
== 0)
11426 /* Window configuration is the same as before.
11427 Can do with a display update of the echo area,
11428 unless we displayed some mode lines. */
11429 update_single_window (w
);
11433 update_frame (f
, true, true);
11435 /* If cursor is in the echo area, make sure that the next
11436 redisplay displays the minibuffer, so that the cursor will
11437 be replaced with what the minibuffer wants. */
11438 if (cursor_in_echo_area
)
11439 wset_redisplay (XWINDOW (mini_window
));
11442 else if (!EQ (mini_window
, selected_window
))
11443 wset_redisplay (XWINDOW (mini_window
));
11445 /* Last displayed message is now the current message. */
11446 echo_area_buffer
[1] = echo_area_buffer
[0];
11447 /* Inform read_char that we're not echoing. */
11448 echo_message_buffer
= Qnil
;
11450 /* Prevent redisplay optimization in redisplay_internal by resetting
11451 this_line_start_pos. This is done because the mini-buffer now
11452 displays the message instead of its buffer text. */
11453 if (EQ (mini_window
, selected_window
))
11454 CHARPOS (this_line_start_pos
) = 0;
11456 if (window_height_changed_p
)
11458 fset_redisplay (f
);
11460 /* If window configuration was changed, frames may have been
11461 marked garbaged. Clear them or we will experience
11462 surprises wrt scrolling.
11463 FIXME: How/why/when? */
11464 clear_garbaged_frames ();
11468 /* True if W's buffer was changed but not saved. */
11471 window_buffer_changed (struct window
*w
)
11473 struct buffer
*b
= XBUFFER (w
->contents
);
11475 eassert (BUFFER_LIVE_P (b
));
11477 return (BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
;
11480 /* True if W has %c in its mode line and mode line should be updated. */
11483 mode_line_update_needed (struct window
*w
)
11485 return (w
->column_number_displayed
!= -1
11486 && !(PT
== w
->last_point
&& !window_outdated (w
))
11487 && (w
->column_number_displayed
!= current_column ()));
11490 /* True if window start of W is frozen and may not be changed during
11494 window_frozen_p (struct window
*w
)
11496 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11498 Lisp_Object window
;
11500 XSETWINDOW (window
, w
);
11501 if (MINI_WINDOW_P (w
))
11503 else if (EQ (window
, selected_window
))
11505 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11506 && EQ (window
, Vminibuf_scroll_window
))
11507 /* This special window can't be frozen too. */
11515 /***********************************************************************
11516 Mode Lines and Frame Titles
11517 ***********************************************************************/
11519 /* A buffer for constructing non-propertized mode-line strings and
11520 frame titles in it; allocated from the heap in init_xdisp and
11521 resized as needed in store_mode_line_noprop_char. */
11523 static char *mode_line_noprop_buf
;
11525 /* The buffer's end, and a current output position in it. */
11527 static char *mode_line_noprop_buf_end
;
11528 static char *mode_line_noprop_ptr
;
11530 #define MODE_LINE_NOPROP_LEN(start) \
11531 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11534 MODE_LINE_DISPLAY
= 0,
11538 } mode_line_target
;
11540 /* Alist that caches the results of :propertize.
11541 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11542 static Lisp_Object mode_line_proptrans_alist
;
11544 /* List of strings making up the mode-line. */
11545 static Lisp_Object mode_line_string_list
;
11547 /* Base face property when building propertized mode line string. */
11548 static Lisp_Object mode_line_string_face
;
11549 static Lisp_Object mode_line_string_face_prop
;
11552 /* Unwind data for mode line strings */
11554 static Lisp_Object Vmode_line_unwind_vector
;
11557 format_mode_line_unwind_data (struct frame
*target_frame
,
11558 struct buffer
*obuf
,
11560 bool save_proptrans
)
11562 Lisp_Object vector
, tmp
;
11564 /* Reduce consing by keeping one vector in
11565 Vwith_echo_area_save_vector. */
11566 vector
= Vmode_line_unwind_vector
;
11567 Vmode_line_unwind_vector
= Qnil
;
11570 vector
= Fmake_vector (make_number (10), Qnil
);
11572 ASET (vector
, 0, make_number (mode_line_target
));
11573 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11574 ASET (vector
, 2, mode_line_string_list
);
11575 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11576 ASET (vector
, 4, mode_line_string_face
);
11577 ASET (vector
, 5, mode_line_string_face_prop
);
11580 XSETBUFFER (tmp
, obuf
);
11583 ASET (vector
, 6, tmp
);
11584 ASET (vector
, 7, owin
);
11587 /* Similarly to `with-selected-window', if the operation selects
11588 a window on another frame, we must restore that frame's
11589 selected window, and (for a tty) the top-frame. */
11590 ASET (vector
, 8, target_frame
->selected_window
);
11591 if (FRAME_TERMCAP_P (target_frame
))
11592 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11599 unwind_format_mode_line (Lisp_Object vector
)
11601 Lisp_Object old_window
= AREF (vector
, 7);
11602 Lisp_Object target_frame_window
= AREF (vector
, 8);
11603 Lisp_Object old_top_frame
= AREF (vector
, 9);
11605 mode_line_target
= XINT (AREF (vector
, 0));
11606 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11607 mode_line_string_list
= AREF (vector
, 2);
11608 if (! EQ (AREF (vector
, 3), Qt
))
11609 mode_line_proptrans_alist
= AREF (vector
, 3);
11610 mode_line_string_face
= AREF (vector
, 4);
11611 mode_line_string_face_prop
= AREF (vector
, 5);
11613 /* Select window before buffer, since it may change the buffer. */
11614 if (!NILP (old_window
))
11616 /* If the operation that we are unwinding had selected a window
11617 on a different frame, reset its frame-selected-window. For a
11618 text terminal, reset its top-frame if necessary. */
11619 if (!NILP (target_frame_window
))
11622 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11624 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11625 Fselect_window (target_frame_window
, Qt
);
11627 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11628 Fselect_frame (old_top_frame
, Qt
);
11631 Fselect_window (old_window
, Qt
);
11634 if (!NILP (AREF (vector
, 6)))
11636 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11637 ASET (vector
, 6, Qnil
);
11640 Vmode_line_unwind_vector
= vector
;
11644 /* Store a single character C for the frame title in mode_line_noprop_buf.
11645 Re-allocate mode_line_noprop_buf if necessary. */
11648 store_mode_line_noprop_char (char c
)
11650 /* If output position has reached the end of the allocated buffer,
11651 increase the buffer's size. */
11652 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11654 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11655 ptrdiff_t size
= len
;
11656 mode_line_noprop_buf
=
11657 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11658 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11659 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11662 *mode_line_noprop_ptr
++ = c
;
11666 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11667 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11668 characters that yield more columns than PRECISION; PRECISION <= 0
11669 means copy the whole string. Pad with spaces until FIELD_WIDTH
11670 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11671 pad. Called from display_mode_element when it is used to build a
11675 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11677 const unsigned char *str
= (const unsigned char *) string
;
11679 ptrdiff_t dummy
, nbytes
;
11681 /* Copy at most PRECISION chars from STR. */
11682 nbytes
= strlen (string
);
11683 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11685 store_mode_line_noprop_char (*str
++);
11687 /* Fill up with spaces until FIELD_WIDTH reached. */
11688 while (field_width
> 0
11689 && n
< field_width
)
11691 store_mode_line_noprop_char (' ');
11698 /***********************************************************************
11700 ***********************************************************************/
11702 #ifdef HAVE_WINDOW_SYSTEM
11704 /* Set the title of FRAME, if it has changed. The title format is
11705 Vicon_title_format if FRAME is iconified, otherwise it is
11706 frame_title_format. */
11709 x_consider_frame_title (Lisp_Object frame
)
11711 struct frame
*f
= XFRAME (frame
);
11713 if ((FRAME_WINDOW_P (f
)
11714 || FRAME_MINIBUF_ONLY_P (f
)
11715 || f
->explicit_name
)
11716 && NILP (Fframe_parameter (frame
, Qtooltip
)))
11718 /* Do we have more than one visible frame on this X display? */
11719 Lisp_Object tail
, other_frame
, fmt
;
11720 ptrdiff_t title_start
;
11724 ptrdiff_t count
= SPECPDL_INDEX ();
11726 FOR_EACH_FRAME (tail
, other_frame
)
11728 struct frame
*tf
= XFRAME (other_frame
);
11731 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11732 && !FRAME_MINIBUF_ONLY_P (tf
)
11733 && !EQ (other_frame
, tip_frame
)
11734 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11738 /* Set global variable indicating that multiple frames exist. */
11739 multiple_frames
= CONSP (tail
);
11741 /* Switch to the buffer of selected window of the frame. Set up
11742 mode_line_target so that display_mode_element will output into
11743 mode_line_noprop_buf; then display the title. */
11744 record_unwind_protect (unwind_format_mode_line
,
11745 format_mode_line_unwind_data
11746 (f
, current_buffer
, selected_window
, false));
11748 Fselect_window (f
->selected_window
, Qt
);
11749 set_buffer_internal_1
11750 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11751 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11753 mode_line_target
= MODE_LINE_TITLE
;
11754 title_start
= MODE_LINE_NOPROP_LEN (0);
11755 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11756 NULL
, DEFAULT_FACE_ID
);
11757 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, false);
11758 len
= MODE_LINE_NOPROP_LEN (title_start
);
11759 title
= mode_line_noprop_buf
+ title_start
;
11760 unbind_to (count
, Qnil
);
11762 /* Set the title only if it's changed. This avoids consing in
11763 the common case where it hasn't. (If it turns out that we've
11764 already wasted too much time by walking through the list with
11765 display_mode_element, then we might need to optimize at a
11766 higher level than this.) */
11767 if (! STRINGP (f
->name
)
11768 || SBYTES (f
->name
) != len
11769 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11770 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11774 #endif /* not HAVE_WINDOW_SYSTEM */
11777 /***********************************************************************
11779 ***********************************************************************/
11781 /* True if we will not redisplay all visible windows. */
11782 #define REDISPLAY_SOME_P() \
11783 ((windows_or_buffers_changed == 0 \
11784 || windows_or_buffers_changed == REDISPLAY_SOME) \
11785 && (update_mode_lines == 0 \
11786 || update_mode_lines == REDISPLAY_SOME))
11788 /* Prepare for redisplay by updating menu-bar item lists when
11789 appropriate. This can call eval. */
11792 prepare_menu_bars (void)
11794 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11795 bool some_windows
= REDISPLAY_SOME_P ();
11796 Lisp_Object tooltip_frame
;
11798 #ifdef HAVE_WINDOW_SYSTEM
11799 tooltip_frame
= tip_frame
;
11801 tooltip_frame
= Qnil
;
11804 if (FUNCTIONP (Vpre_redisplay_function
))
11806 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11807 if (all_windows
&& some_windows
)
11809 Lisp_Object ws
= window_list ();
11810 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11812 Lisp_Object
this = XCAR (ws
);
11813 struct window
*w
= XWINDOW (this);
11815 || XFRAME (w
->frame
)->redisplay
11816 || XBUFFER (w
->contents
)->text
->redisplay
)
11818 windows
= Fcons (this, windows
);
11822 safe__call1 (true, Vpre_redisplay_function
, windows
);
11825 /* Update all frame titles based on their buffer names, etc. We do
11826 this before the menu bars so that the buffer-menu will show the
11827 up-to-date frame titles. */
11828 #ifdef HAVE_WINDOW_SYSTEM
11831 Lisp_Object tail
, frame
;
11833 FOR_EACH_FRAME (tail
, frame
)
11835 struct frame
*f
= XFRAME (frame
);
11836 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11840 && !XBUFFER (w
->contents
)->text
->redisplay
)
11843 if (!EQ (frame
, tooltip_frame
)
11844 && (FRAME_ICONIFIED_P (f
)
11845 || FRAME_VISIBLE_P (f
) == 1
11846 /* Exclude TTY frames that are obscured because they
11847 are not the top frame on their console. This is
11848 because x_consider_frame_title actually switches
11849 to the frame, which for TTY frames means it is
11850 marked as garbaged, and will be completely
11851 redrawn on the next redisplay cycle. This causes
11852 TTY frames to be completely redrawn, when there
11853 are more than one of them, even though nothing
11854 should be changed on display. */
11855 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11856 x_consider_frame_title (frame
);
11859 #endif /* HAVE_WINDOW_SYSTEM */
11861 /* Update the menu bar item lists, if appropriate. This has to be
11862 done before any actual redisplay or generation of display lines. */
11866 Lisp_Object tail
, frame
;
11867 ptrdiff_t count
= SPECPDL_INDEX ();
11868 /* True means that update_menu_bar has run its hooks
11869 so any further calls to update_menu_bar shouldn't do so again. */
11870 bool menu_bar_hooks_run
= false;
11872 record_unwind_save_match_data ();
11874 FOR_EACH_FRAME (tail
, frame
)
11876 struct frame
*f
= XFRAME (frame
);
11877 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11879 /* Ignore tooltip frame. */
11880 if (EQ (frame
, tooltip_frame
))
11886 && !XBUFFER (w
->contents
)->text
->redisplay
)
11889 run_window_size_change_functions (frame
);
11890 menu_bar_hooks_run
= update_menu_bar (f
, false, menu_bar_hooks_run
);
11891 #ifdef HAVE_WINDOW_SYSTEM
11892 update_tool_bar (f
, false);
11896 unbind_to (count
, Qnil
);
11900 struct frame
*sf
= SELECTED_FRAME ();
11901 update_menu_bar (sf
, true, false);
11902 #ifdef HAVE_WINDOW_SYSTEM
11903 update_tool_bar (sf
, true);
11909 /* Update the menu bar item list for frame F. This has to be done
11910 before we start to fill in any display lines, because it can call
11913 If SAVE_MATCH_DATA, we must save and restore it here.
11915 If HOOKS_RUN, a previous call to update_menu_bar
11916 already ran the menu bar hooks for this redisplay, so there
11917 is no need to run them again. The return value is the
11918 updated value of this flag, to pass to the next call. */
11921 update_menu_bar (struct frame
*f
, bool save_match_data
, bool hooks_run
)
11923 Lisp_Object window
;
11926 /* If called recursively during a menu update, do nothing. This can
11927 happen when, for instance, an activate-menubar-hook causes a
11929 if (inhibit_menubar_update
)
11932 window
= FRAME_SELECTED_WINDOW (f
);
11933 w
= XWINDOW (window
);
11935 if (FRAME_WINDOW_P (f
)
11937 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11938 || defined (HAVE_NS) || defined (USE_GTK)
11939 FRAME_EXTERNAL_MENU_BAR (f
)
11941 FRAME_MENU_BAR_LINES (f
) > 0
11943 : FRAME_MENU_BAR_LINES (f
) > 0)
11945 /* If the user has switched buffers or windows, we need to
11946 recompute to reflect the new bindings. But we'll
11947 recompute when update_mode_lines is set too; that means
11948 that people can use force-mode-line-update to request
11949 that the menu bar be recomputed. The adverse effect on
11950 the rest of the redisplay algorithm is about the same as
11951 windows_or_buffers_changed anyway. */
11952 if (windows_or_buffers_changed
11953 /* This used to test w->update_mode_line, but we believe
11954 there is no need to recompute the menu in that case. */
11955 || update_mode_lines
11956 || window_buffer_changed (w
))
11958 struct buffer
*prev
= current_buffer
;
11959 ptrdiff_t count
= SPECPDL_INDEX ();
11961 specbind (Qinhibit_menubar_update
, Qt
);
11963 set_buffer_internal_1 (XBUFFER (w
->contents
));
11964 if (save_match_data
)
11965 record_unwind_save_match_data ();
11966 if (NILP (Voverriding_local_map_menu_flag
))
11968 specbind (Qoverriding_terminal_local_map
, Qnil
);
11969 specbind (Qoverriding_local_map
, Qnil
);
11974 /* Run the Lucid hook. */
11975 safe_run_hooks (Qactivate_menubar_hook
);
11977 /* If it has changed current-menubar from previous value,
11978 really recompute the menu-bar from the value. */
11979 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11980 call0 (Qrecompute_lucid_menubar
);
11982 safe_run_hooks (Qmenu_bar_update_hook
);
11987 XSETFRAME (Vmenu_updating_frame
, f
);
11988 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11990 /* Redisplay the menu bar in case we changed it. */
11991 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11992 || defined (HAVE_NS) || defined (USE_GTK)
11993 if (FRAME_WINDOW_P (f
))
11995 #if defined (HAVE_NS)
11996 /* All frames on Mac OS share the same menubar. So only
11997 the selected frame should be allowed to set it. */
11998 if (f
== SELECTED_FRAME ())
12000 set_frame_menubar (f
, false, false);
12003 /* On a terminal screen, the menu bar is an ordinary screen
12004 line, and this makes it get updated. */
12005 w
->update_mode_line
= true;
12006 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
12007 /* In the non-toolkit version, the menu bar is an ordinary screen
12008 line, and this makes it get updated. */
12009 w
->update_mode_line
= true;
12010 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
12012 unbind_to (count
, Qnil
);
12013 set_buffer_internal_1 (prev
);
12020 /***********************************************************************
12022 ***********************************************************************/
12024 #ifdef HAVE_WINDOW_SYSTEM
12026 /* Select `frame' temporarily without running all the code in
12028 FIXME: Maybe do_switch_frame should be trimmed down similarly
12029 when `norecord' is set. */
12031 fast_set_selected_frame (Lisp_Object frame
)
12033 if (!EQ (selected_frame
, frame
))
12035 selected_frame
= frame
;
12036 selected_window
= XFRAME (frame
)->selected_window
;
12040 /* Update the tool-bar item list for frame F. This has to be done
12041 before we start to fill in any display lines. Called from
12042 prepare_menu_bars. If SAVE_MATCH_DATA, we must save
12043 and restore it here. */
12046 update_tool_bar (struct frame
*f
, bool save_match_data
)
12048 #if defined (USE_GTK) || defined (HAVE_NS)
12049 bool do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
12051 bool do_update
= (WINDOWP (f
->tool_bar_window
)
12052 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0);
12057 Lisp_Object window
;
12060 window
= FRAME_SELECTED_WINDOW (f
);
12061 w
= XWINDOW (window
);
12063 /* If the user has switched buffers or windows, we need to
12064 recompute to reflect the new bindings. But we'll
12065 recompute when update_mode_lines is set too; that means
12066 that people can use force-mode-line-update to request
12067 that the menu bar be recomputed. The adverse effect on
12068 the rest of the redisplay algorithm is about the same as
12069 windows_or_buffers_changed anyway. */
12070 if (windows_or_buffers_changed
12071 || w
->update_mode_line
12072 || update_mode_lines
12073 || window_buffer_changed (w
))
12075 struct buffer
*prev
= current_buffer
;
12076 ptrdiff_t count
= SPECPDL_INDEX ();
12077 Lisp_Object frame
, new_tool_bar
;
12078 int new_n_tool_bar
;
12080 /* Set current_buffer to the buffer of the selected
12081 window of the frame, so that we get the right local
12083 set_buffer_internal_1 (XBUFFER (w
->contents
));
12085 /* Save match data, if we must. */
12086 if (save_match_data
)
12087 record_unwind_save_match_data ();
12089 /* Make sure that we don't accidentally use bogus keymaps. */
12090 if (NILP (Voverriding_local_map_menu_flag
))
12092 specbind (Qoverriding_terminal_local_map
, Qnil
);
12093 specbind (Qoverriding_local_map
, Qnil
);
12096 /* We must temporarily set the selected frame to this frame
12097 before calling tool_bar_items, because the calculation of
12098 the tool-bar keymap uses the selected frame (see
12099 `tool-bar-make-keymap' in tool-bar.el). */
12100 eassert (EQ (selected_window
,
12101 /* Since we only explicitly preserve selected_frame,
12102 check that selected_window would be redundant. */
12103 XFRAME (selected_frame
)->selected_window
));
12104 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
12105 XSETFRAME (frame
, f
);
12106 fast_set_selected_frame (frame
);
12108 /* Build desired tool-bar items from keymaps. */
12110 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
12113 /* Redisplay the tool-bar if we changed it. */
12114 if (new_n_tool_bar
!= f
->n_tool_bar_items
12115 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
12117 /* Redisplay that happens asynchronously due to an expose event
12118 may access f->tool_bar_items. Make sure we update both
12119 variables within BLOCK_INPUT so no such event interrupts. */
12121 fset_tool_bar_items (f
, new_tool_bar
);
12122 f
->n_tool_bar_items
= new_n_tool_bar
;
12123 w
->update_mode_line
= true;
12127 unbind_to (count
, Qnil
);
12128 set_buffer_internal_1 (prev
);
12133 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12135 /* Set F->desired_tool_bar_string to a Lisp string representing frame
12136 F's desired tool-bar contents. F->tool_bar_items must have
12137 been set up previously by calling prepare_menu_bars. */
12140 build_desired_tool_bar_string (struct frame
*f
)
12142 int i
, size
, size_needed
;
12143 Lisp_Object image
, plist
;
12145 image
= plist
= Qnil
;
12147 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
12148 Otherwise, make a new string. */
12150 /* The size of the string we might be able to reuse. */
12151 size
= (STRINGP (f
->desired_tool_bar_string
)
12152 ? SCHARS (f
->desired_tool_bar_string
)
12155 /* We need one space in the string for each image. */
12156 size_needed
= f
->n_tool_bar_items
;
12158 /* Reuse f->desired_tool_bar_string, if possible. */
12159 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
12160 fset_desired_tool_bar_string
12161 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
12164 AUTO_LIST4 (props
, Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
12165 Fremove_text_properties (make_number (0), make_number (size
),
12166 props
, f
->desired_tool_bar_string
);
12169 /* Put a `display' property on the string for the images to display,
12170 put a `menu_item' property on tool-bar items with a value that
12171 is the index of the item in F's tool-bar item vector. */
12172 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
12174 #define PROP(IDX) \
12175 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
12177 bool enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
12178 bool selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
12179 int hmargin
, vmargin
, relief
, idx
, end
;
12181 /* If image is a vector, choose the image according to the
12183 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
12184 if (VECTORP (image
))
12188 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
12189 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
12192 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
12193 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
12195 eassert (ASIZE (image
) >= idx
);
12196 image
= AREF (image
, idx
);
12201 /* Ignore invalid image specifications. */
12202 if (!valid_image_p (image
))
12205 /* Display the tool-bar button pressed, or depressed. */
12206 plist
= Fcopy_sequence (XCDR (image
));
12208 /* Compute margin and relief to draw. */
12209 relief
= (tool_bar_button_relief
>= 0
12210 ? tool_bar_button_relief
12211 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
12212 hmargin
= vmargin
= relief
;
12214 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
12215 INT_MAX
- max (hmargin
, vmargin
)))
12217 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
12218 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
12220 else if (CONSP (Vtool_bar_button_margin
))
12222 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
12223 INT_MAX
- hmargin
))
12224 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
12226 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
12227 INT_MAX
- vmargin
))
12228 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
12231 if (auto_raise_tool_bar_buttons_p
)
12233 /* Add a `:relief' property to the image spec if the item is
12237 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
12244 /* If image is selected, display it pressed, i.e. with a
12245 negative relief. If it's not selected, display it with a
12247 plist
= Fplist_put (plist
, QCrelief
,
12249 ? make_number (-relief
)
12250 : make_number (relief
)));
12255 /* Put a margin around the image. */
12256 if (hmargin
|| vmargin
)
12258 if (hmargin
== vmargin
)
12259 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
12261 plist
= Fplist_put (plist
, QCmargin
,
12262 Fcons (make_number (hmargin
),
12263 make_number (vmargin
)));
12266 /* If button is not enabled, and we don't have special images
12267 for the disabled state, make the image appear disabled by
12268 applying an appropriate algorithm to it. */
12269 if (!enabled_p
&& idx
< 0)
12270 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
12272 /* Put a `display' text property on the string for the image to
12273 display. Put a `menu-item' property on the string that gives
12274 the start of this item's properties in the tool-bar items
12276 image
= Fcons (Qimage
, plist
);
12277 AUTO_LIST4 (props
, Qdisplay
, image
, Qmenu_item
,
12278 make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
12280 /* Let the last image hide all remaining spaces in the tool bar
12281 string. The string can be longer than needed when we reuse a
12282 previous string. */
12283 if (i
+ 1 == f
->n_tool_bar_items
)
12284 end
= SCHARS (f
->desired_tool_bar_string
);
12287 Fadd_text_properties (make_number (i
), make_number (end
),
12288 props
, f
->desired_tool_bar_string
);
12294 /* Display one line of the tool-bar of frame IT->f.
12296 HEIGHT specifies the desired height of the tool-bar line.
12297 If the actual height of the glyph row is less than HEIGHT, the
12298 row's height is increased to HEIGHT, and the icons are centered
12299 vertically in the new height.
12301 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
12302 count a final empty row in case the tool-bar width exactly matches
12307 display_tool_bar_line (struct it
*it
, int height
)
12309 struct glyph_row
*row
= it
->glyph_row
;
12310 int max_x
= it
->last_visible_x
;
12311 struct glyph
*last
;
12313 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
12314 clear_glyph_row (row
);
12315 row
->enabled_p
= true;
12316 row
->y
= it
->current_y
;
12318 /* Note that this isn't made use of if the face hasn't a box,
12319 so there's no need to check the face here. */
12320 it
->start_of_box_run_p
= true;
12322 while (it
->current_x
< max_x
)
12324 int x
, n_glyphs_before
, i
, nglyphs
;
12325 struct it it_before
;
12327 /* Get the next display element. */
12328 if (!get_next_display_element (it
))
12330 /* Don't count empty row if we are counting needed tool-bar lines. */
12331 if (height
< 0 && !it
->hpos
)
12336 /* Produce glyphs. */
12337 n_glyphs_before
= row
->used
[TEXT_AREA
];
12340 PRODUCE_GLYPHS (it
);
12342 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12344 x
= it_before
.current_x
;
12345 while (i
< nglyphs
)
12347 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12349 if (x
+ glyph
->pixel_width
> max_x
)
12351 /* Glyph doesn't fit on line. Backtrack. */
12352 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12354 /* If this is the only glyph on this line, it will never fit on the
12355 tool-bar, so skip it. But ensure there is at least one glyph,
12356 so we don't accidentally disable the tool-bar. */
12357 if (n_glyphs_before
== 0
12358 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
12364 x
+= glyph
->pixel_width
;
12368 /* Stop at line end. */
12369 if (ITERATOR_AT_END_OF_LINE_P (it
))
12372 set_iterator_to_next (it
, true);
12377 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12379 /* Use default face for the border below the tool bar.
12381 FIXME: When auto-resize-tool-bars is grow-only, there is
12382 no additional border below the possibly empty tool-bar lines.
12383 So to make the extra empty lines look "normal", we have to
12384 use the tool-bar face for the border too. */
12385 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12386 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12387 it
->face_id
= DEFAULT_FACE_ID
;
12389 extend_face_to_end_of_line (it
);
12390 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12391 last
->right_box_line_p
= true;
12392 if (last
== row
->glyphs
[TEXT_AREA
])
12393 last
->left_box_line_p
= true;
12395 /* Make line the desired height and center it vertically. */
12396 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12398 /* Don't add more than one line height. */
12399 height
%= FRAME_LINE_HEIGHT (it
->f
);
12400 it
->max_ascent
+= height
/ 2;
12401 it
->max_descent
+= (height
+ 1) / 2;
12404 compute_line_metrics (it
);
12406 /* If line is empty, make it occupy the rest of the tool-bar. */
12407 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12409 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12410 row
->visible_height
= row
->height
;
12411 row
->ascent
= row
->phys_ascent
= 0;
12412 row
->extra_line_spacing
= 0;
12415 row
->full_width_p
= true;
12416 row
->continued_p
= false;
12417 row
->truncated_on_left_p
= false;
12418 row
->truncated_on_right_p
= false;
12420 it
->current_x
= it
->hpos
= 0;
12421 it
->current_y
+= row
->height
;
12427 /* Value is the number of pixels needed to make all tool-bar items of
12428 frame F visible. The actual number of glyph rows needed is
12429 returned in *N_ROWS if non-NULL. */
12431 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12433 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12435 /* tool_bar_height is called from redisplay_tool_bar after building
12436 the desired matrix, so use (unused) mode-line row as temporary row to
12437 avoid destroying the first tool-bar row. */
12438 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12440 /* Initialize an iterator for iteration over
12441 F->desired_tool_bar_string in the tool-bar window of frame F. */
12442 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12443 temp_row
->reversed_p
= false;
12444 it
.first_visible_x
= 0;
12445 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12446 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12447 it
.paragraph_embedding
= L2R
;
12449 while (!ITERATOR_AT_END_P (&it
))
12451 clear_glyph_row (temp_row
);
12452 it
.glyph_row
= temp_row
;
12453 display_tool_bar_line (&it
, -1);
12455 clear_glyph_row (temp_row
);
12457 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12459 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12462 return it
.current_y
;
12464 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12467 #endif /* !USE_GTK && !HAVE_NS */
12469 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12471 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12472 If FRAME is nil or omitted, use the selected frame. Optional argument
12473 PIXELWISE non-nil means return the height of the tool bar in pixels. */)
12474 (Lisp_Object frame
, Lisp_Object pixelwise
)
12478 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12479 struct frame
*f
= decode_any_frame (frame
);
12481 if (WINDOWP (f
->tool_bar_window
)
12482 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12484 update_tool_bar (f
, true);
12485 if (f
->n_tool_bar_items
)
12487 build_desired_tool_bar_string (f
);
12488 height
= tool_bar_height (f
, NULL
, !NILP (pixelwise
));
12493 return make_number (height
);
12497 /* Display the tool-bar of frame F. Value is true if tool-bar's
12498 height should be changed. */
12500 redisplay_tool_bar (struct frame
*f
)
12502 f
->tool_bar_redisplayed
= true;
12503 #if defined (USE_GTK) || defined (HAVE_NS)
12505 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12506 update_frame_tool_bar (f
);
12509 #else /* !USE_GTK && !HAVE_NS */
12513 struct glyph_row
*row
;
12515 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12516 do anything. This means you must start with tool-bar-lines
12517 non-zero to get the auto-sizing effect. Or in other words, you
12518 can turn off tool-bars by specifying tool-bar-lines zero. */
12519 if (!WINDOWP (f
->tool_bar_window
)
12520 || (w
= XWINDOW (f
->tool_bar_window
),
12521 WINDOW_TOTAL_LINES (w
) == 0))
12524 /* Set up an iterator for the tool-bar window. */
12525 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12526 it
.first_visible_x
= 0;
12527 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12528 row
= it
.glyph_row
;
12529 row
->reversed_p
= false;
12531 /* Build a string that represents the contents of the tool-bar. */
12532 build_desired_tool_bar_string (f
);
12533 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12534 /* FIXME: This should be controlled by a user option. But it
12535 doesn't make sense to have an R2L tool bar if the menu bar cannot
12536 be drawn also R2L, and making the menu bar R2L is tricky due
12537 toolkit-specific code that implements it. If an R2L tool bar is
12538 ever supported, display_tool_bar_line should also be augmented to
12539 call unproduce_glyphs like display_line and display_string
12541 it
.paragraph_embedding
= L2R
;
12543 if (f
->n_tool_bar_rows
== 0)
12545 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, true);
12547 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12549 x_change_tool_bar_height (f
, new_height
);
12550 frame_default_tool_bar_height
= new_height
;
12551 /* Always do that now. */
12552 clear_glyph_matrix (w
->desired_matrix
);
12553 f
->fonts_changed
= true;
12558 /* Display as many lines as needed to display all tool-bar items. */
12560 if (f
->n_tool_bar_rows
> 0)
12562 int border
, rows
, height
, extra
;
12564 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12565 border
= XINT (Vtool_bar_border
);
12566 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12567 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12568 else if (EQ (Vtool_bar_border
, Qborder_width
))
12569 border
= f
->border_width
;
12575 rows
= f
->n_tool_bar_rows
;
12576 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12577 extra
= it
.last_visible_y
- border
- height
* rows
;
12579 while (it
.current_y
< it
.last_visible_y
)
12582 if (extra
> 0 && rows
-- > 0)
12584 h
= (extra
+ rows
- 1) / rows
;
12587 display_tool_bar_line (&it
, height
+ h
);
12592 while (it
.current_y
< it
.last_visible_y
)
12593 display_tool_bar_line (&it
, 0);
12596 /* It doesn't make much sense to try scrolling in the tool-bar
12597 window, so don't do it. */
12598 w
->desired_matrix
->no_scrolling_p
= true;
12599 w
->must_be_updated_p
= true;
12601 if (!NILP (Vauto_resize_tool_bars
))
12603 bool change_height_p
= true;
12605 /* If we couldn't display everything, change the tool-bar's
12606 height if there is room for more. */
12607 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
12608 change_height_p
= true;
12610 /* We subtract 1 because display_tool_bar_line advances the
12611 glyph_row pointer before returning to its caller. We want to
12612 examine the last glyph row produced by
12613 display_tool_bar_line. */
12614 row
= it
.glyph_row
- 1;
12616 /* If there are blank lines at the end, except for a partially
12617 visible blank line at the end that is smaller than
12618 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12619 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12620 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12621 change_height_p
= true;
12623 /* If row displays tool-bar items, but is partially visible,
12624 change the tool-bar's height. */
12625 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12626 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
12627 change_height_p
= true;
12629 /* Resize windows as needed by changing the `tool-bar-lines'
12630 frame parameter. */
12631 if (change_height_p
)
12634 int new_height
= tool_bar_height (f
, &nrows
, true);
12636 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12637 && !f
->minimize_tool_bar_window_p
)
12638 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12639 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12640 f
->minimize_tool_bar_window_p
= false;
12642 if (change_height_p
)
12644 x_change_tool_bar_height (f
, new_height
);
12645 frame_default_tool_bar_height
= new_height
;
12646 clear_glyph_matrix (w
->desired_matrix
);
12647 f
->n_tool_bar_rows
= nrows
;
12648 f
->fonts_changed
= true;
12655 f
->minimize_tool_bar_window_p
= false;
12658 #endif /* USE_GTK || HAVE_NS */
12661 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12663 /* Get information about the tool-bar item which is displayed in GLYPH
12664 on frame F. Return in *PROP_IDX the index where tool-bar item
12665 properties start in F->tool_bar_items. Value is false if
12666 GLYPH doesn't display a tool-bar item. */
12669 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12674 /* This function can be called asynchronously, which means we must
12675 exclude any possibility that Fget_text_property signals an
12677 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12678 charpos
= max (0, charpos
);
12680 /* Get the text property `menu-item' at pos. The value of that
12681 property is the start index of this item's properties in
12682 F->tool_bar_items. */
12683 prop
= Fget_text_property (make_number (charpos
),
12684 Qmenu_item
, f
->current_tool_bar_string
);
12685 if (! INTEGERP (prop
))
12687 *prop_idx
= XINT (prop
);
12692 /* Get information about the tool-bar item at position X/Y on frame F.
12693 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12694 the current matrix of the tool-bar window of F, or NULL if not
12695 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12696 item in F->tool_bar_items. Value is
12698 -1 if X/Y is not on a tool-bar item
12699 0 if X/Y is on the same item that was highlighted before.
12703 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12704 int *hpos
, int *vpos
, int *prop_idx
)
12706 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12707 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12710 /* Find the glyph under X/Y. */
12711 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12712 if (*glyph
== NULL
)
12715 /* Get the start of this tool-bar item's properties in
12716 f->tool_bar_items. */
12717 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12720 /* Is mouse on the highlighted item? */
12721 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12722 && *vpos
>= hlinfo
->mouse_face_beg_row
12723 && *vpos
<= hlinfo
->mouse_face_end_row
12724 && (*vpos
> hlinfo
->mouse_face_beg_row
12725 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12726 && (*vpos
< hlinfo
->mouse_face_end_row
12727 || *hpos
< hlinfo
->mouse_face_end_col
12728 || hlinfo
->mouse_face_past_end
))
12736 Handle mouse button event on the tool-bar of frame F, at
12737 frame-relative coordinates X/Y. DOWN_P is true for a button press,
12738 false for button release. MODIFIERS is event modifiers for button
12742 handle_tool_bar_click (struct frame
*f
, int x
, int y
, bool down_p
,
12745 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12746 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12747 int hpos
, vpos
, prop_idx
;
12748 struct glyph
*glyph
;
12749 Lisp_Object enabled_p
;
12752 /* If not on the highlighted tool-bar item, and mouse-highlight is
12753 non-nil, return. This is so we generate the tool-bar button
12754 click only when the mouse button is released on the same item as
12755 where it was pressed. However, when mouse-highlight is disabled,
12756 generate the click when the button is released regardless of the
12757 highlight, since tool-bar items are not highlighted in that
12759 frame_to_window_pixel_xy (w
, &x
, &y
);
12760 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12762 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12765 /* When mouse-highlight is off, generate the click for the item
12766 where the button was pressed, disregarding where it was
12768 if (NILP (Vmouse_highlight
) && !down_p
)
12769 prop_idx
= f
->last_tool_bar_item
;
12771 /* If item is disabled, do nothing. */
12772 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12773 if (NILP (enabled_p
))
12778 /* Show item in pressed state. */
12779 if (!NILP (Vmouse_highlight
))
12780 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12781 f
->last_tool_bar_item
= prop_idx
;
12785 Lisp_Object key
, frame
;
12786 struct input_event event
;
12787 EVENT_INIT (event
);
12789 /* Show item in released state. */
12790 if (!NILP (Vmouse_highlight
))
12791 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12793 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12795 XSETFRAME (frame
, f
);
12796 event
.kind
= TOOL_BAR_EVENT
;
12797 event
.frame_or_window
= frame
;
12799 kbd_buffer_store_event (&event
);
12801 event
.kind
= TOOL_BAR_EVENT
;
12802 event
.frame_or_window
= frame
;
12804 event
.modifiers
= modifiers
;
12805 kbd_buffer_store_event (&event
);
12806 f
->last_tool_bar_item
= -1;
12811 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12812 tool-bar window-relative coordinates X/Y. Called from
12813 note_mouse_highlight. */
12816 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12818 Lisp_Object window
= f
->tool_bar_window
;
12819 struct window
*w
= XWINDOW (window
);
12820 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12821 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12823 struct glyph
*glyph
;
12824 struct glyph_row
*row
;
12826 Lisp_Object enabled_p
;
12828 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12832 /* Function note_mouse_highlight is called with negative X/Y
12833 values when mouse moves outside of the frame. */
12834 if (x
<= 0 || y
<= 0)
12836 clear_mouse_face (hlinfo
);
12840 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12843 /* Not on tool-bar item. */
12844 clear_mouse_face (hlinfo
);
12848 /* On same tool-bar item as before. */
12849 goto set_help_echo
;
12851 clear_mouse_face (hlinfo
);
12853 /* Mouse is down, but on different tool-bar item? */
12854 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12855 && f
== dpyinfo
->last_mouse_frame
);
12857 if (mouse_down_p
&& f
->last_tool_bar_item
!= prop_idx
)
12860 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12862 /* If tool-bar item is not enabled, don't highlight it. */
12863 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12864 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12866 /* Compute the x-position of the glyph. In front and past the
12867 image is a space. We include this in the highlighted area. */
12868 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12869 for (i
= x
= 0; i
< hpos
; ++i
)
12870 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12872 /* Record this as the current active region. */
12873 hlinfo
->mouse_face_beg_col
= hpos
;
12874 hlinfo
->mouse_face_beg_row
= vpos
;
12875 hlinfo
->mouse_face_beg_x
= x
;
12876 hlinfo
->mouse_face_past_end
= false;
12878 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12879 hlinfo
->mouse_face_end_row
= vpos
;
12880 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12881 hlinfo
->mouse_face_window
= window
;
12882 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12884 /* Display it as active. */
12885 show_mouse_face (hlinfo
, draw
);
12890 /* Set help_echo_string to a help string to display for this tool-bar item.
12891 XTread_socket does the rest. */
12892 help_echo_object
= help_echo_window
= Qnil
;
12893 help_echo_pos
= -1;
12894 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12895 if (NILP (help_echo_string
))
12896 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12899 #endif /* !USE_GTK && !HAVE_NS */
12901 #endif /* HAVE_WINDOW_SYSTEM */
12905 /************************************************************************
12906 Horizontal scrolling
12907 ************************************************************************/
12909 /* For all leaf windows in the window tree rooted at WINDOW, set their
12910 hscroll value so that PT is (i) visible in the window, and (ii) so
12911 that it is not within a certain margin at the window's left and
12912 right border. Value is true if any window's hscroll has been
12916 hscroll_window_tree (Lisp_Object window
)
12918 bool hscrolled_p
= false;
12919 bool hscroll_relative_p
= FLOATP (Vhscroll_step
);
12920 int hscroll_step_abs
= 0;
12921 double hscroll_step_rel
= 0;
12923 if (hscroll_relative_p
)
12925 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12926 if (hscroll_step_rel
< 0)
12928 hscroll_relative_p
= false;
12929 hscroll_step_abs
= 0;
12932 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12934 hscroll_step_abs
= XINT (Vhscroll_step
);
12935 if (hscroll_step_abs
< 0)
12936 hscroll_step_abs
= 0;
12939 hscroll_step_abs
= 0;
12941 while (WINDOWP (window
))
12943 struct window
*w
= XWINDOW (window
);
12945 if (WINDOWP (w
->contents
))
12946 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12947 else if (w
->cursor
.vpos
>= 0)
12950 int text_area_width
;
12951 struct glyph_row
*cursor_row
;
12952 struct glyph_row
*bottom_row
;
12954 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->desired_matrix
, w
);
12955 if (w
->cursor
.vpos
< bottom_row
- w
->desired_matrix
->rows
)
12956 cursor_row
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12958 cursor_row
= bottom_row
- 1;
12960 if (!cursor_row
->enabled_p
)
12962 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12963 if (w
->cursor
.vpos
< bottom_row
- w
->current_matrix
->rows
)
12964 cursor_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12966 cursor_row
= bottom_row
- 1;
12968 bool row_r2l_p
= cursor_row
->reversed_p
;
12970 text_area_width
= window_box_width (w
, TEXT_AREA
);
12972 /* Scroll when cursor is inside this scroll margin. */
12973 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12975 /* If the position of this window's point has explicitly
12976 changed, no more suspend auto hscrolling. */
12977 if (NILP (Fequal (Fwindow_point (window
), Fwindow_old_point (window
))))
12978 w
->suspend_auto_hscroll
= false;
12980 /* Remember window point. */
12981 Fset_marker (w
->old_pointm
,
12982 ((w
== XWINDOW (selected_window
))
12983 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
12984 : Fmarker_position (w
->pointm
)),
12987 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12988 && !w
->suspend_auto_hscroll
12989 /* In some pathological cases, like restoring a window
12990 configuration into a frame that is much smaller than
12991 the one from which the configuration was saved, we
12992 get glyph rows whose start and end have zero buffer
12993 positions, which we cannot handle below. Just skip
12995 && CHARPOS (cursor_row
->start
.pos
) >= BUF_BEG (w
->contents
)
12996 /* For left-to-right rows, hscroll when cursor is either
12997 (i) inside the right hscroll margin, or (ii) if it is
12998 inside the left margin and the window is already
13001 && ((w
->hscroll
&& w
->cursor
.x
<= h_margin
)
13002 || (cursor_row
->enabled_p
13003 && cursor_row
->truncated_on_right_p
13004 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
13005 /* For right-to-left rows, the logic is similar,
13006 except that rules for scrolling to left and right
13007 are reversed. E.g., if cursor.x <= h_margin, we
13008 need to hscroll "to the right" unconditionally,
13009 and that will scroll the screen to the left so as
13010 to reveal the next portion of the row. */
13012 && ((cursor_row
->enabled_p
13013 /* FIXME: It is confusing to set the
13014 truncated_on_right_p flag when R2L rows
13015 are actually truncated on the left. */
13016 && cursor_row
->truncated_on_right_p
13017 && w
->cursor
.x
<= h_margin
)
13019 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
13023 struct buffer
*saved_current_buffer
;
13027 /* Find point in a display of infinite width. */
13028 saved_current_buffer
= current_buffer
;
13029 current_buffer
= XBUFFER (w
->contents
);
13031 if (w
== XWINDOW (selected_window
))
13034 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
13036 /* Move iterator to pt starting at cursor_row->start in
13037 a line with infinite width. */
13038 init_to_row_start (&it
, w
, cursor_row
);
13039 it
.last_visible_x
= INFINITY
;
13040 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
13041 current_buffer
= saved_current_buffer
;
13043 /* Position cursor in window. */
13044 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
13045 hscroll
= max (0, (it
.current_x
13046 - (ITERATOR_AT_END_OF_LINE_P (&it
)
13047 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
13048 : (text_area_width
/ 2))))
13049 / FRAME_COLUMN_WIDTH (it
.f
);
13050 else if ((!row_r2l_p
13051 && w
->cursor
.x
>= text_area_width
- h_margin
)
13052 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
13054 if (hscroll_relative_p
)
13055 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
13058 wanted_x
= text_area_width
13059 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
13062 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
13066 if (hscroll_relative_p
)
13067 wanted_x
= text_area_width
* hscroll_step_rel
13070 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
13073 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
13075 hscroll
= max (hscroll
, w
->min_hscroll
);
13077 /* Don't prevent redisplay optimizations if hscroll
13078 hasn't changed, as it will unnecessarily slow down
13080 if (w
->hscroll
!= hscroll
)
13082 struct buffer
*b
= XBUFFER (w
->contents
);
13083 b
->prevent_redisplay_optimizations_p
= true;
13084 w
->hscroll
= hscroll
;
13085 hscrolled_p
= true;
13093 /* Value is true if hscroll of any leaf window has been changed. */
13094 return hscrolled_p
;
13098 /* Set hscroll so that cursor is visible and not inside horizontal
13099 scroll margins for all windows in the tree rooted at WINDOW. See
13100 also hscroll_window_tree above. Value is true if any window's
13101 hscroll has been changed. If it has, desired matrices on the frame
13102 of WINDOW are cleared. */
13105 hscroll_windows (Lisp_Object window
)
13107 bool hscrolled_p
= hscroll_window_tree (window
);
13109 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
13110 return hscrolled_p
;
13115 /************************************************************************
13117 ************************************************************************/
13119 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined.
13120 This is sometimes handy to have in a debugger session. */
13124 /* First and last unchanged row for try_window_id. */
13126 static int debug_first_unchanged_at_end_vpos
;
13127 static int debug_last_unchanged_at_beg_vpos
;
13129 /* Delta vpos and y. */
13131 static int debug_dvpos
, debug_dy
;
13133 /* Delta in characters and bytes for try_window_id. */
13135 static ptrdiff_t debug_delta
, debug_delta_bytes
;
13137 /* Values of window_end_pos and window_end_vpos at the end of
13140 static ptrdiff_t debug_end_vpos
;
13142 /* Append a string to W->desired_matrix->method. FMT is a printf
13143 format string. If trace_redisplay_p is true also printf the
13144 resulting string to stderr. */
13146 static void debug_method_add (struct window
*, char const *, ...)
13147 ATTRIBUTE_FORMAT_PRINTF (2, 3);
13150 debug_method_add (struct window
*w
, char const *fmt
, ...)
13153 char *method
= w
->desired_matrix
->method
;
13154 int len
= strlen (method
);
13155 int size
= sizeof w
->desired_matrix
->method
;
13156 int remaining
= size
- len
- 1;
13159 if (len
&& remaining
)
13162 --remaining
, ++len
;
13165 va_start (ap
, fmt
);
13166 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
13169 if (trace_redisplay_p
)
13170 fprintf (stderr
, "%p (%s): %s\n",
13172 ((BUFFERP (w
->contents
)
13173 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
13174 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
13179 #endif /* GLYPH_DEBUG */
13182 /* Value is true if all changes in window W, which displays
13183 current_buffer, are in the text between START and END. START is a
13184 buffer position, END is given as a distance from Z. Used in
13185 redisplay_internal for display optimization. */
13188 text_outside_line_unchanged_p (struct window
*w
,
13189 ptrdiff_t start
, ptrdiff_t end
)
13191 bool unchanged_p
= true;
13193 /* If text or overlays have changed, see where. */
13194 if (window_outdated (w
))
13196 /* Gap in the line? */
13197 if (GPT
< start
|| Z
- GPT
< end
)
13198 unchanged_p
= false;
13200 /* Changes start in front of the line, or end after it? */
13202 && (BEG_UNCHANGED
< start
- 1
13203 || END_UNCHANGED
< end
))
13204 unchanged_p
= false;
13206 /* If selective display, can't optimize if changes start at the
13207 beginning of the line. */
13209 && INTEGERP (BVAR (current_buffer
, selective_display
))
13210 && XINT (BVAR (current_buffer
, selective_display
)) > 0
13211 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
13212 unchanged_p
= false;
13214 /* If there are overlays at the start or end of the line, these
13215 may have overlay strings with newlines in them. A change at
13216 START, for instance, may actually concern the display of such
13217 overlay strings as well, and they are displayed on different
13218 lines. So, quickly rule out this case. (For the future, it
13219 might be desirable to implement something more telling than
13220 just BEG/END_UNCHANGED.) */
13223 if (BEG
+ BEG_UNCHANGED
== start
13224 && overlay_touches_p (start
))
13225 unchanged_p
= false;
13226 if (END_UNCHANGED
== end
13227 && overlay_touches_p (Z
- end
))
13228 unchanged_p
= false;
13231 /* Under bidi reordering, adding or deleting a character in the
13232 beginning of a paragraph, before the first strong directional
13233 character, can change the base direction of the paragraph (unless
13234 the buffer specifies a fixed paragraph direction), which will
13235 require redisplaying the whole paragraph. It might be worthwhile
13236 to find the paragraph limits and widen the range of redisplayed
13237 lines to that, but for now just give up this optimization. */
13238 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
13239 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
13240 unchanged_p
= false;
13243 return unchanged_p
;
13247 /* Do a frame update, taking possible shortcuts into account. This is
13248 the main external entry point for redisplay.
13250 If the last redisplay displayed an echo area message and that message
13251 is no longer requested, we clear the echo area or bring back the
13252 mini-buffer if that is in use. */
13257 redisplay_internal ();
13262 overlay_arrow_string_or_property (Lisp_Object var
)
13266 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
13269 return Voverlay_arrow_string
;
13272 /* Return true if there are any overlay-arrows in current_buffer. */
13274 overlay_arrow_in_current_buffer_p (void)
13278 for (vlist
= Voverlay_arrow_variable_list
;
13280 vlist
= XCDR (vlist
))
13282 Lisp_Object var
= XCAR (vlist
);
13285 if (!SYMBOLP (var
))
13287 val
= find_symbol_value (var
);
13289 && current_buffer
== XMARKER (val
)->buffer
)
13296 /* Return true if any overlay_arrows have moved or overlay-arrow-string
13300 overlay_arrows_changed_p (void)
13304 for (vlist
= Voverlay_arrow_variable_list
;
13306 vlist
= XCDR (vlist
))
13308 Lisp_Object var
= XCAR (vlist
);
13309 Lisp_Object val
, pstr
;
13311 if (!SYMBOLP (var
))
13313 val
= find_symbol_value (var
);
13314 if (!MARKERP (val
))
13316 if (! EQ (COERCE_MARKER (val
),
13317 Fget (var
, Qlast_arrow_position
))
13318 || ! (pstr
= overlay_arrow_string_or_property (var
),
13319 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
13325 /* Mark overlay arrows to be updated on next redisplay. */
13328 update_overlay_arrows (int up_to_date
)
13332 for (vlist
= Voverlay_arrow_variable_list
;
13334 vlist
= XCDR (vlist
))
13336 Lisp_Object var
= XCAR (vlist
);
13338 if (!SYMBOLP (var
))
13341 if (up_to_date
> 0)
13343 Lisp_Object val
= find_symbol_value (var
);
13344 Fput (var
, Qlast_arrow_position
,
13345 COERCE_MARKER (val
));
13346 Fput (var
, Qlast_arrow_string
,
13347 overlay_arrow_string_or_property (var
));
13349 else if (up_to_date
< 0
13350 || !NILP (Fget (var
, Qlast_arrow_position
)))
13352 Fput (var
, Qlast_arrow_position
, Qt
);
13353 Fput (var
, Qlast_arrow_string
, Qt
);
13359 /* Return overlay arrow string to display at row.
13360 Return integer (bitmap number) for arrow bitmap in left fringe.
13361 Return nil if no overlay arrow. */
13364 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
13368 for (vlist
= Voverlay_arrow_variable_list
;
13370 vlist
= XCDR (vlist
))
13372 Lisp_Object var
= XCAR (vlist
);
13375 if (!SYMBOLP (var
))
13378 val
= find_symbol_value (var
);
13381 && current_buffer
== XMARKER (val
)->buffer
13382 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13384 if (FRAME_WINDOW_P (it
->f
)
13385 /* FIXME: if ROW->reversed_p is set, this should test
13386 the right fringe, not the left one. */
13387 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13389 #ifdef HAVE_WINDOW_SYSTEM
13390 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13392 int fringe_bitmap
= lookup_fringe_bitmap (val
);
13393 if (fringe_bitmap
!= 0)
13394 return make_number (fringe_bitmap
);
13397 return make_number (-1); /* Use default arrow bitmap. */
13399 return overlay_arrow_string_or_property (var
);
13406 /* Return true if point moved out of or into a composition. Otherwise
13407 return false. PREV_BUF and PREV_PT are the last point buffer and
13408 position. BUF and PT are the current point buffer and position. */
13411 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13412 struct buffer
*buf
, ptrdiff_t pt
)
13414 ptrdiff_t start
, end
;
13416 Lisp_Object buffer
;
13418 XSETBUFFER (buffer
, buf
);
13419 /* Check a composition at the last point if point moved within the
13421 if (prev_buf
== buf
)
13424 /* Point didn't move. */
13427 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13428 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13429 && composition_valid_p (start
, end
, prop
)
13430 && start
< prev_pt
&& end
> prev_pt
)
13431 /* The last point was within the composition. Return true iff
13432 point moved out of the composition. */
13433 return (pt
<= start
|| pt
>= end
);
13436 /* Check a composition at the current point. */
13437 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13438 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13439 && composition_valid_p (start
, end
, prop
)
13440 && start
< pt
&& end
> pt
);
13443 /* Reconsider the clip changes of buffer which is displayed in W. */
13446 reconsider_clip_changes (struct window
*w
)
13448 struct buffer
*b
= XBUFFER (w
->contents
);
13450 if (b
->clip_changed
13451 && w
->window_end_valid
13452 && w
->current_matrix
->buffer
== b
13453 && w
->current_matrix
->zv
== BUF_ZV (b
)
13454 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13455 b
->clip_changed
= false;
13457 /* If display wasn't paused, and W is not a tool bar window, see if
13458 point has been moved into or out of a composition. In that case,
13459 set b->clip_changed to force updating the screen. If
13460 b->clip_changed has already been set, skip this check. */
13461 if (!b
->clip_changed
&& w
->window_end_valid
)
13463 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13464 ? PT
: marker_position (w
->pointm
));
13466 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13467 && check_point_in_composition (w
->current_matrix
->buffer
,
13468 w
->last_point
, b
, pt
))
13469 b
->clip_changed
= true;
13474 propagate_buffer_redisplay (void)
13475 { /* Resetting b->text->redisplay is problematic!
13476 We can't just reset it in the case that some window that displays
13477 it has not been redisplayed; and such a window can stay
13478 unredisplayed for a long time if it's currently invisible.
13479 But we do want to reset it at the end of redisplay otherwise
13480 its displayed windows will keep being redisplayed over and over
13482 So we copy all b->text->redisplay flags up to their windows here,
13483 such that mark_window_display_accurate can safely reset
13484 b->text->redisplay. */
13485 Lisp_Object ws
= window_list ();
13486 for (; CONSP (ws
); ws
= XCDR (ws
))
13488 struct window
*thisw
= XWINDOW (XCAR (ws
));
13489 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13490 if (thisb
->text
->redisplay
)
13491 thisw
->redisplay
= true;
13495 #define STOP_POLLING \
13496 do { if (! polling_stopped_here) stop_polling (); \
13497 polling_stopped_here = true; } while (false)
13499 #define RESUME_POLLING \
13500 do { if (polling_stopped_here) start_polling (); \
13501 polling_stopped_here = false; } while (false)
13504 /* Perhaps in the future avoid recentering windows if it
13505 is not necessary; currently that causes some problems. */
13508 redisplay_internal (void)
13510 struct window
*w
= XWINDOW (selected_window
);
13514 bool must_finish
= false, match_p
;
13515 struct text_pos tlbufpos
, tlendpos
;
13516 int number_of_visible_frames
;
13519 bool polling_stopped_here
= false;
13520 Lisp_Object tail
, frame
;
13522 /* True means redisplay has to consider all windows on all
13523 frames. False, only selected_window is considered. */
13524 bool consider_all_windows_p
;
13526 /* True means redisplay has to redisplay the miniwindow. */
13527 bool update_miniwindow_p
= false;
13529 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13531 /* No redisplay if running in batch mode or frame is not yet fully
13532 initialized, or redisplay is explicitly turned off by setting
13533 Vinhibit_redisplay. */
13534 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13535 || !NILP (Vinhibit_redisplay
))
13538 /* Don't examine these until after testing Vinhibit_redisplay.
13539 When Emacs is shutting down, perhaps because its connection to
13540 X has dropped, we should not look at them at all. */
13541 fr
= XFRAME (w
->frame
);
13542 sf
= SELECTED_FRAME ();
13544 if (!fr
->glyphs_initialized_p
)
13547 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13548 if (popup_activated ())
13552 /* I don't think this happens but let's be paranoid. */
13553 if (redisplaying_p
)
13556 /* Record a function that clears redisplaying_p
13557 when we leave this function. */
13558 count
= SPECPDL_INDEX ();
13559 record_unwind_protect_void (unwind_redisplay
);
13560 redisplaying_p
= true;
13561 specbind (Qinhibit_free_realized_faces
, Qnil
);
13563 /* Record this function, so it appears on the profiler's backtraces. */
13564 record_in_backtrace (Qredisplay_internal_xC_functionx
, 0, 0);
13566 FOR_EACH_FRAME (tail
, frame
)
13567 XFRAME (frame
)->already_hscrolled_p
= false;
13570 /* Remember the currently selected window. */
13574 forget_escape_and_glyphless_faces ();
13576 inhibit_free_realized_faces
= false;
13578 /* If face_change, init_iterator will free all realized faces, which
13579 includes the faces referenced from current matrices. So, we
13580 can't reuse current matrices in this case. */
13582 windows_or_buffers_changed
= 47;
13584 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13585 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13587 /* Since frames on a single ASCII terminal share the same
13588 display area, displaying a different frame means redisplay
13589 the whole thing. */
13590 SET_FRAME_GARBAGED (sf
);
13592 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13594 FRAME_TTY (sf
)->previous_frame
= sf
;
13597 /* Set the visible flags for all frames. Do this before checking for
13598 resized or garbaged frames; they want to know if their frames are
13599 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13600 number_of_visible_frames
= 0;
13602 FOR_EACH_FRAME (tail
, frame
)
13604 struct frame
*f
= XFRAME (frame
);
13606 if (FRAME_VISIBLE_P (f
))
13608 ++number_of_visible_frames
;
13609 /* Adjust matrices for visible frames only. */
13610 if (f
->fonts_changed
)
13612 adjust_frame_glyphs (f
);
13613 /* Disable all redisplay optimizations for this frame.
13614 This is because adjust_frame_glyphs resets the
13615 enabled_p flag for all glyph rows of all windows, so
13616 many optimizations will fail anyway, and some might
13617 fail to test that flag and do bogus things as
13619 SET_FRAME_GARBAGED (f
);
13620 f
->fonts_changed
= false;
13622 /* If cursor type has been changed on the frame
13623 other than selected, consider all frames. */
13624 if (f
!= sf
&& f
->cursor_type_changed
)
13625 fset_redisplay (f
);
13627 clear_desired_matrices (f
);
13630 /* Notice any pending interrupt request to change frame size. */
13631 do_pending_window_change (true);
13633 /* do_pending_window_change could change the selected_window due to
13634 frame resizing which makes the selected window too small. */
13635 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13638 /* Clear frames marked as garbaged. */
13639 clear_garbaged_frames ();
13641 /* Build menubar and tool-bar items. */
13642 if (NILP (Vmemory_full
))
13643 prepare_menu_bars ();
13645 reconsider_clip_changes (w
);
13647 /* In most cases selected window displays current buffer. */
13648 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13651 /* Detect case that we need to write or remove a star in the mode line. */
13652 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13653 w
->update_mode_line
= true;
13655 if (mode_line_update_needed (w
))
13656 w
->update_mode_line
= true;
13658 /* If reconsider_clip_changes above decided that the narrowing
13659 in the current buffer changed, make sure all other windows
13660 showing that buffer will be redisplayed. */
13661 if (current_buffer
->clip_changed
)
13662 bset_update_mode_line (current_buffer
);
13665 /* Normally the message* functions will have already displayed and
13666 updated the echo area, but the frame may have been trashed, or
13667 the update may have been preempted, so display the echo area
13668 again here. Checking message_cleared_p captures the case that
13669 the echo area should be cleared. */
13670 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13671 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13672 || (message_cleared_p
13673 && minibuf_level
== 0
13674 /* If the mini-window is currently selected, this means the
13675 echo-area doesn't show through. */
13676 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13678 echo_area_display (false);
13680 /* If echo_area_display resizes the mini-window, the redisplay and
13681 window_sizes_changed flags of the selected frame are set, but
13682 it's too late for the hooks in window-size-change-functions,
13683 which have been examined already in prepare_menu_bars. So in
13684 that case we call the hooks here only for the selected frame. */
13687 ptrdiff_t count1
= SPECPDL_INDEX ();
13689 record_unwind_save_match_data ();
13690 run_window_size_change_functions (selected_frame
);
13691 unbind_to (count1
, Qnil
);
13694 if (message_cleared_p
)
13695 update_miniwindow_p
= true;
13697 must_finish
= true;
13699 /* If we don't display the current message, don't clear the
13700 message_cleared_p flag, because, if we did, we wouldn't clear
13701 the echo area in the next redisplay which doesn't preserve
13703 if (!display_last_displayed_message_p
)
13704 message_cleared_p
= false;
13706 else if (EQ (selected_window
, minibuf_window
)
13707 && (current_buffer
->clip_changed
|| window_outdated (w
))
13708 && resize_mini_window (w
, false))
13712 ptrdiff_t count1
= SPECPDL_INDEX ();
13714 record_unwind_save_match_data ();
13715 run_window_size_change_functions (selected_frame
);
13716 unbind_to (count1
, Qnil
);
13719 /* Resized active mini-window to fit the size of what it is
13720 showing if its contents might have changed. */
13721 must_finish
= true;
13723 /* If window configuration was changed, frames may have been
13724 marked garbaged. Clear them or we will experience
13725 surprises wrt scrolling. */
13726 clear_garbaged_frames ();
13729 if (windows_or_buffers_changed
&& !update_mode_lines
)
13730 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13731 only the windows's contents needs to be refreshed, or whether the
13732 mode-lines also need a refresh. */
13733 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13734 ? REDISPLAY_SOME
: 32);
13736 /* If specs for an arrow have changed, do thorough redisplay
13737 to ensure we remove any arrow that should no longer exist. */
13738 if (overlay_arrows_changed_p ())
13739 /* Apparently, this is the only case where we update other windows,
13740 without updating other mode-lines. */
13741 windows_or_buffers_changed
= 49;
13743 consider_all_windows_p
= (update_mode_lines
13744 || windows_or_buffers_changed
);
13746 #define AINC(a,i) \
13748 Lisp_Object entry = Fgethash (make_number (i), a, make_number (0)); \
13749 if (INTEGERP (entry)) \
13750 Fputhash (make_number (i), make_number (1 + XINT (entry)), a); \
13753 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13754 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13756 /* Optimize the case that only the line containing the cursor in the
13757 selected window has changed. Variables starting with this_ are
13758 set in display_line and record information about the line
13759 containing the cursor. */
13760 tlbufpos
= this_line_start_pos
;
13761 tlendpos
= this_line_end_pos
;
13762 if (!consider_all_windows_p
13763 && CHARPOS (tlbufpos
) > 0
13764 && !w
->update_mode_line
13765 && !current_buffer
->clip_changed
13766 && !current_buffer
->prevent_redisplay_optimizations_p
13767 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13768 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13769 && !XFRAME (w
->frame
)->cursor_type_changed
13770 && !XFRAME (w
->frame
)->face_change
13771 /* Make sure recorded data applies to current buffer, etc. */
13772 && this_line_buffer
== current_buffer
13775 && !w
->optional_new_start
13776 /* Point must be on the line that we have info recorded about. */
13777 && PT
>= CHARPOS (tlbufpos
)
13778 && PT
<= Z
- CHARPOS (tlendpos
)
13779 /* All text outside that line, including its final newline,
13780 must be unchanged. */
13781 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13782 CHARPOS (tlendpos
)))
13784 if (CHARPOS (tlbufpos
) > BEGV
13785 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13786 && (CHARPOS (tlbufpos
) == ZV
13787 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13788 /* Former continuation line has disappeared by becoming empty. */
13790 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13792 /* We have to handle the case of continuation around a
13793 wide-column character (see the comment in indent.c around
13796 For instance, in the following case:
13798 -------- Insert --------
13799 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13800 J_I_ ==> J_I_ `^^' are cursors.
13804 As we have to redraw the line above, we cannot use this
13808 int line_height_before
= this_line_pixel_height
;
13810 /* Note that start_display will handle the case that the
13811 line starting at tlbufpos is a continuation line. */
13812 start_display (&it
, w
, tlbufpos
);
13814 /* Implementation note: It this still necessary? */
13815 if (it
.current_x
!= this_line_start_x
)
13818 TRACE ((stderr
, "trying display optimization 1\n"));
13819 w
->cursor
.vpos
= -1;
13820 overlay_arrow_seen
= false;
13821 it
.vpos
= this_line_vpos
;
13822 it
.current_y
= this_line_y
;
13823 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13824 display_line (&it
);
13826 /* If line contains point, is not continued,
13827 and ends at same distance from eob as before, we win. */
13828 if (w
->cursor
.vpos
>= 0
13829 /* Line is not continued, otherwise this_line_start_pos
13830 would have been set to 0 in display_line. */
13831 && CHARPOS (this_line_start_pos
)
13832 /* Line ends as before. */
13833 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13834 /* Line has same height as before. Otherwise other lines
13835 would have to be shifted up or down. */
13836 && this_line_pixel_height
== line_height_before
)
13838 /* If this is not the window's last line, we must adjust
13839 the charstarts of the lines below. */
13840 if (it
.current_y
< it
.last_visible_y
)
13842 struct glyph_row
*row
13843 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13844 ptrdiff_t delta
, delta_bytes
;
13846 /* We used to distinguish between two cases here,
13847 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13848 when the line ends in a newline or the end of the
13849 buffer's accessible portion. But both cases did
13850 the same, so they were collapsed. */
13852 - CHARPOS (tlendpos
)
13853 - MATRIX_ROW_START_CHARPOS (row
));
13854 delta_bytes
= (Z_BYTE
13855 - BYTEPOS (tlendpos
)
13856 - MATRIX_ROW_START_BYTEPOS (row
));
13858 increment_matrix_positions (w
->current_matrix
,
13859 this_line_vpos
+ 1,
13860 w
->current_matrix
->nrows
,
13861 delta
, delta_bytes
);
13864 /* If this row displays text now but previously didn't,
13865 or vice versa, w->window_end_vpos may have to be
13867 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13869 if (w
->window_end_vpos
< this_line_vpos
)
13870 w
->window_end_vpos
= this_line_vpos
;
13872 else if (w
->window_end_vpos
== this_line_vpos
13873 && this_line_vpos
> 0)
13874 w
->window_end_vpos
= this_line_vpos
- 1;
13875 w
->window_end_valid
= false;
13877 /* Update hint: No need to try to scroll in update_window. */
13878 w
->desired_matrix
->no_scrolling_p
= true;
13881 *w
->desired_matrix
->method
= 0;
13882 debug_method_add (w
, "optimization 1");
13884 #ifdef HAVE_WINDOW_SYSTEM
13885 update_window_fringes (w
, false);
13892 else if (/* Cursor position hasn't changed. */
13893 PT
== w
->last_point
13894 /* Make sure the cursor was last displayed
13895 in this window. Otherwise we have to reposition it. */
13897 /* PXW: Must be converted to pixels, probably. */
13898 && 0 <= w
->cursor
.vpos
13899 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13903 do_pending_window_change (true);
13904 /* If selected_window changed, redisplay again. */
13905 if (WINDOWP (selected_window
)
13906 && (w
= XWINDOW (selected_window
)) != sw
)
13909 /* We used to always goto end_of_redisplay here, but this
13910 isn't enough if we have a blinking cursor. */
13911 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13912 goto end_of_redisplay
;
13916 /* If highlighting the region, or if the cursor is in the echo area,
13917 then we can't just move the cursor. */
13918 else if (NILP (Vshow_trailing_whitespace
)
13919 && !cursor_in_echo_area
)
13922 struct glyph_row
*row
;
13924 /* Skip from tlbufpos to PT and see where it is. Note that
13925 PT may be in invisible text. If so, we will end at the
13926 next visible position. */
13927 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13928 NULL
, DEFAULT_FACE_ID
);
13929 it
.current_x
= this_line_start_x
;
13930 it
.current_y
= this_line_y
;
13931 it
.vpos
= this_line_vpos
;
13933 /* The call to move_it_to stops in front of PT, but
13934 moves over before-strings. */
13935 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13937 if (it
.vpos
== this_line_vpos
13938 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13941 eassert (this_line_vpos
== it
.vpos
);
13942 eassert (this_line_y
== it
.current_y
);
13943 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13944 if (cursor_row_fully_visible_p (w
, false, true))
13947 *w
->desired_matrix
->method
= 0;
13948 debug_method_add (w
, "optimization 3");
13960 /* Text changed drastically or point moved off of line. */
13961 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13964 CHARPOS (this_line_start_pos
) = 0;
13965 ++clear_face_cache_count
;
13966 #ifdef HAVE_WINDOW_SYSTEM
13967 ++clear_image_cache_count
;
13970 /* Build desired matrices, and update the display. If
13971 consider_all_windows_p, do it for all windows on all frames that
13972 require redisplay, as specified by their 'redisplay' flag.
13973 Otherwise do it for selected_window, only. */
13975 if (consider_all_windows_p
)
13977 FOR_EACH_FRAME (tail
, frame
)
13978 XFRAME (frame
)->updated_p
= false;
13980 propagate_buffer_redisplay ();
13982 FOR_EACH_FRAME (tail
, frame
)
13984 struct frame
*f
= XFRAME (frame
);
13986 /* We don't have to do anything for unselected terminal
13988 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13989 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13993 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13996 /* Only GC scrollbars when we redisplay the whole frame. */
13997 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13998 bool f_redisplay_flag
= f
->redisplay
;
13999 /* Mark all the scroll bars to be removed; we'll redeem
14000 the ones we want when we redisplay their windows. */
14001 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
14002 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
14004 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
14005 redisplay_windows (FRAME_ROOT_WINDOW (f
));
14006 /* Remember that the invisible frames need to be redisplayed next
14007 time they're visible. */
14008 else if (!REDISPLAY_SOME_P ())
14009 f
->redisplay
= true;
14011 /* The X error handler may have deleted that frame. */
14012 if (!FRAME_LIVE_P (f
))
14015 /* Any scroll bars which redisplay_windows should have
14016 nuked should now go away. */
14017 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
14018 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
14020 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
14022 /* If fonts changed on visible frame, display again. */
14023 if (f
->fonts_changed
)
14025 adjust_frame_glyphs (f
);
14026 /* Disable all redisplay optimizations for this
14027 frame. For the reasons, see the comment near
14028 the previous call to adjust_frame_glyphs above. */
14029 SET_FRAME_GARBAGED (f
);
14030 f
->fonts_changed
= false;
14034 /* See if we have to hscroll. */
14035 if (!f
->already_hscrolled_p
)
14037 f
->already_hscrolled_p
= true;
14038 if (hscroll_windows (f
->root_window
))
14042 /* If the frame's redisplay flag was not set before
14043 we went about redisplaying its windows, but it is
14044 set now, that means we employed some redisplay
14045 optimizations inside redisplay_windows, and
14046 bypassed producing some screen lines. But if
14047 f->redisplay is now set, it might mean the old
14048 faces are no longer valid (e.g., if redisplaying
14049 some window called some Lisp which defined a new
14050 face or redefined an existing face), so trying to
14051 use them in update_frame will segfault.
14052 Therefore, we must redisplay this frame. */
14053 if (!f_redisplay_flag
&& f
->redisplay
)
14056 /* Prevent various kinds of signals during display
14057 update. stdio is not robust about handling
14058 signals, which can cause an apparent I/O error. */
14059 if (interrupt_input
)
14060 unrequest_sigio ();
14063 pending
|= update_frame (f
, false, false);
14064 f
->cursor_type_changed
= false;
14065 f
->updated_p
= true;
14070 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
14074 /* Do the mark_window_display_accurate after all windows have
14075 been redisplayed because this call resets flags in buffers
14076 which are needed for proper redisplay. */
14077 FOR_EACH_FRAME (tail
, frame
)
14079 struct frame
*f
= XFRAME (frame
);
14082 f
->redisplay
= false;
14083 mark_window_display_accurate (f
->root_window
, true);
14084 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
14085 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
14090 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
14092 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
14093 /* Use list_of_error, not Qerror, so that
14094 we catch only errors and don't run the debugger. */
14095 internal_condition_case_1 (redisplay_window_1
, selected_window
,
14097 redisplay_window_error
);
14098 if (update_miniwindow_p
)
14099 internal_condition_case_1 (redisplay_window_1
,
14100 FRAME_MINIBUF_WINDOW (sf
), list_of_error
,
14101 redisplay_window_error
);
14103 /* Compare desired and current matrices, perform output. */
14106 /* If fonts changed, display again. Likewise if redisplay_window_1
14107 above caused some change (e.g., a change in faces) that requires
14108 considering the entire frame again. */
14109 if (sf
->fonts_changed
|| sf
->redisplay
)
14113 /* Set this to force a more thorough redisplay.
14114 Otherwise, we might immediately loop back to the
14115 above "else-if" clause (since all the conditions that
14116 led here might still be true), and we will then
14117 infloop, because the selected-frame's redisplay flag
14118 is not (and cannot be) reset. */
14119 windows_or_buffers_changed
= 50;
14124 /* Prevent freeing of realized faces, since desired matrices are
14125 pending that reference the faces we computed and cached. */
14126 inhibit_free_realized_faces
= true;
14128 /* Prevent various kinds of signals during display update.
14129 stdio is not robust about handling signals,
14130 which can cause an apparent I/O error. */
14131 if (interrupt_input
)
14132 unrequest_sigio ();
14135 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
14137 if (hscroll_windows (selected_window
))
14140 XWINDOW (selected_window
)->must_be_updated_p
= true;
14141 pending
= update_frame (sf
, false, false);
14142 sf
->cursor_type_changed
= false;
14145 /* We may have called echo_area_display at the top of this
14146 function. If the echo area is on another frame, that may
14147 have put text on a frame other than the selected one, so the
14148 above call to update_frame would not have caught it. Catch
14150 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
14151 struct frame
*mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
14153 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
14155 XWINDOW (mini_window
)->must_be_updated_p
= true;
14156 pending
|= update_frame (mini_frame
, false, false);
14157 mini_frame
->cursor_type_changed
= false;
14158 if (!pending
&& hscroll_windows (mini_window
))
14163 /* If display was paused because of pending input, make sure we do a
14164 thorough update the next time. */
14167 /* Prevent the optimization at the beginning of
14168 redisplay_internal that tries a single-line update of the
14169 line containing the cursor in the selected window. */
14170 CHARPOS (this_line_start_pos
) = 0;
14172 /* Let the overlay arrow be updated the next time. */
14173 update_overlay_arrows (0);
14175 /* If we pause after scrolling, some rows in the current
14176 matrices of some windows are not valid. */
14177 if (!WINDOW_FULL_WIDTH_P (w
)
14178 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
14179 update_mode_lines
= 36;
14183 if (!consider_all_windows_p
)
14185 /* This has already been done above if
14186 consider_all_windows_p is set. */
14187 if (XBUFFER (w
->contents
)->text
->redisplay
14188 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
14189 /* This can happen if b->text->redisplay was set during
14191 propagate_buffer_redisplay ();
14192 mark_window_display_accurate_1 (w
, true);
14194 /* Say overlay arrows are up to date. */
14195 update_overlay_arrows (1);
14197 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
14198 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
14201 update_mode_lines
= 0;
14202 windows_or_buffers_changed
= 0;
14205 /* Start SIGIO interrupts coming again. Having them off during the
14206 code above makes it less likely one will discard output, but not
14207 impossible, since there might be stuff in the system buffer here.
14208 But it is much hairier to try to do anything about that. */
14209 if (interrupt_input
)
14213 /* If a frame has become visible which was not before, redisplay
14214 again, so that we display it. Expose events for such a frame
14215 (which it gets when becoming visible) don't call the parts of
14216 redisplay constructing glyphs, so simply exposing a frame won't
14217 display anything in this case. So, we have to display these
14218 frames here explicitly. */
14223 FOR_EACH_FRAME (tail
, frame
)
14225 if (XFRAME (frame
)->visible
)
14229 if (new_count
!= number_of_visible_frames
)
14230 windows_or_buffers_changed
= 52;
14233 /* Change frame size now if a change is pending. */
14234 do_pending_window_change (true);
14236 /* If we just did a pending size change, or have additional
14237 visible frames, or selected_window changed, redisplay again. */
14238 if ((windows_or_buffers_changed
&& !pending
)
14239 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
14242 /* Clear the face and image caches.
14244 We used to do this only if consider_all_windows_p. But the cache
14245 needs to be cleared if a timer creates images in the current
14246 buffer (e.g. the test case in Bug#6230). */
14248 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
14250 clear_face_cache (false);
14251 clear_face_cache_count
= 0;
14254 #ifdef HAVE_WINDOW_SYSTEM
14255 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
14257 clear_image_caches (Qnil
);
14258 clear_image_cache_count
= 0;
14260 #endif /* HAVE_WINDOW_SYSTEM */
14264 ns_set_doc_edited ();
14266 if (interrupt_input
&& interrupts_deferred
)
14269 unbind_to (count
, Qnil
);
14274 /* Redisplay, but leave alone any recent echo area message unless
14275 another message has been requested in its place.
14277 This is useful in situations where you need to redisplay but no
14278 user action has occurred, making it inappropriate for the message
14279 area to be cleared. See tracking_off and
14280 wait_reading_process_output for examples of these situations.
14282 FROM_WHERE is an integer saying from where this function was
14283 called. This is useful for debugging. */
14286 redisplay_preserve_echo_area (int from_where
)
14288 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
14290 if (!NILP (echo_area_buffer
[1]))
14292 /* We have a previously displayed message, but no current
14293 message. Redisplay the previous message. */
14294 display_last_displayed_message_p
= true;
14295 redisplay_internal ();
14296 display_last_displayed_message_p
= false;
14299 redisplay_internal ();
14301 flush_frame (SELECTED_FRAME ());
14305 /* Function registered with record_unwind_protect in redisplay_internal. */
14308 unwind_redisplay (void)
14310 redisplaying_p
= false;
14314 /* Mark the display of leaf window W as accurate or inaccurate.
14315 If ACCURATE_P, mark display of W as accurate.
14316 If !ACCURATE_P, arrange for W to be redisplayed the next
14317 time redisplay_internal is called. */
14320 mark_window_display_accurate_1 (struct window
*w
, bool accurate_p
)
14322 struct buffer
*b
= XBUFFER (w
->contents
);
14324 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
14325 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
14326 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
14330 b
->clip_changed
= false;
14331 b
->prevent_redisplay_optimizations_p
= false;
14332 eassert (buffer_window_count (b
) > 0);
14333 /* Resetting b->text->redisplay is problematic!
14334 In order to make it safer to do it here, redisplay_internal must
14335 have copied all b->text->redisplay to their respective windows. */
14336 b
->text
->redisplay
= false;
14338 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
14339 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
14340 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
14341 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
14343 w
->current_matrix
->buffer
= b
;
14344 w
->current_matrix
->begv
= BUF_BEGV (b
);
14345 w
->current_matrix
->zv
= BUF_ZV (b
);
14347 w
->last_cursor_vpos
= w
->cursor
.vpos
;
14348 w
->last_cursor_off_p
= w
->cursor_off_p
;
14350 if (w
== XWINDOW (selected_window
))
14351 w
->last_point
= BUF_PT (b
);
14353 w
->last_point
= marker_position (w
->pointm
);
14355 w
->window_end_valid
= true;
14356 w
->update_mode_line
= false;
14359 w
->redisplay
= !accurate_p
;
14363 /* Mark the display of windows in the window tree rooted at WINDOW as
14364 accurate or inaccurate. If ACCURATE_P, mark display of
14365 windows as accurate. If !ACCURATE_P, arrange for windows to
14366 be redisplayed the next time redisplay_internal is called. */
14369 mark_window_display_accurate (Lisp_Object window
, bool accurate_p
)
14373 for (; !NILP (window
); window
= w
->next
)
14375 w
= XWINDOW (window
);
14376 if (WINDOWP (w
->contents
))
14377 mark_window_display_accurate (w
->contents
, accurate_p
);
14379 mark_window_display_accurate_1 (w
, accurate_p
);
14383 update_overlay_arrows (1);
14385 /* Force a thorough redisplay the next time by setting
14386 last_arrow_position and last_arrow_string to t, which is
14387 unequal to any useful value of Voverlay_arrow_... */
14388 update_overlay_arrows (-1);
14392 /* Return value in display table DP (Lisp_Char_Table *) for character
14393 C. Since a display table doesn't have any parent, we don't have to
14394 follow parent. Do not call this function directly but use the
14395 macro DISP_CHAR_VECTOR. */
14398 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
14402 if (ASCII_CHAR_P (c
))
14405 if (SUB_CHAR_TABLE_P (val
))
14406 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
14412 XSETCHAR_TABLE (table
, dp
);
14413 val
= char_table_ref (table
, c
);
14422 /***********************************************************************
14424 ***********************************************************************/
14426 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
14429 redisplay_windows (Lisp_Object window
)
14431 while (!NILP (window
))
14433 struct window
*w
= XWINDOW (window
);
14435 if (WINDOWP (w
->contents
))
14436 redisplay_windows (w
->contents
);
14437 else if (BUFFERP (w
->contents
))
14439 displayed_buffer
= XBUFFER (w
->contents
);
14440 /* Use list_of_error, not Qerror, so that
14441 we catch only errors and don't run the debugger. */
14442 internal_condition_case_1 (redisplay_window_0
, window
,
14444 redisplay_window_error
);
14452 redisplay_window_error (Lisp_Object ignore
)
14454 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14459 redisplay_window_0 (Lisp_Object window
)
14461 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14462 redisplay_window (window
, false);
14467 redisplay_window_1 (Lisp_Object window
)
14469 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14470 redisplay_window (window
, true);
14475 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14476 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14477 which positions recorded in ROW differ from current buffer
14480 Return true iff cursor is on this row. */
14483 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14484 struct glyph_matrix
*matrix
,
14485 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14488 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14489 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14490 struct glyph
*cursor
= NULL
;
14491 /* The last known character position in row. */
14492 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14494 ptrdiff_t pt_old
= PT
- delta
;
14495 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14496 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14497 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14498 /* A glyph beyond the edge of TEXT_AREA which we should never
14500 struct glyph
*glyphs_end
= end
;
14501 /* True means we've found a match for cursor position, but that
14502 glyph has the avoid_cursor_p flag set. */
14503 bool match_with_avoid_cursor
= false;
14504 /* True means we've seen at least one glyph that came from a
14506 bool string_seen
= false;
14507 /* Largest and smallest buffer positions seen so far during scan of
14509 ptrdiff_t bpos_max
= pos_before
;
14510 ptrdiff_t bpos_min
= pos_after
;
14511 /* Last buffer position covered by an overlay string with an integer
14512 `cursor' property. */
14513 ptrdiff_t bpos_covered
= 0;
14514 /* True means the display string on which to display the cursor
14515 comes from a text property, not from an overlay. */
14516 bool string_from_text_prop
= false;
14518 /* Don't even try doing anything if called for a mode-line or
14519 header-line row, since the rest of the code isn't prepared to
14520 deal with such calamities. */
14521 eassert (!row
->mode_line_p
);
14522 if (row
->mode_line_p
)
14525 /* Skip over glyphs not having an object at the start and the end of
14526 the row. These are special glyphs like truncation marks on
14527 terminal frames. */
14528 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14530 if (!row
->reversed_p
)
14533 && NILP (glyph
->object
)
14534 && glyph
->charpos
< 0)
14536 x
+= glyph
->pixel_width
;
14540 && NILP ((end
- 1)->object
)
14541 /* CHARPOS is zero for blanks and stretch glyphs
14542 inserted by extend_face_to_end_of_line. */
14543 && (end
- 1)->charpos
<= 0)
14545 glyph_before
= glyph
- 1;
14552 /* If the glyph row is reversed, we need to process it from back
14553 to front, so swap the edge pointers. */
14554 glyphs_end
= end
= glyph
- 1;
14555 glyph
+= row
->used
[TEXT_AREA
] - 1;
14557 while (glyph
> end
+ 1
14558 && NILP (glyph
->object
)
14559 && glyph
->charpos
< 0)
14562 x
-= glyph
->pixel_width
;
14564 if (NILP (glyph
->object
) && glyph
->charpos
< 0)
14566 /* By default, in reversed rows we put the cursor on the
14567 rightmost (first in the reading order) glyph. */
14568 for (g
= end
+ 1; g
< glyph
; g
++)
14569 x
+= g
->pixel_width
;
14571 && NILP ((end
+ 1)->object
)
14572 && (end
+ 1)->charpos
<= 0)
14574 glyph_before
= glyph
+ 1;
14578 else if (row
->reversed_p
)
14580 /* In R2L rows that don't display text, put the cursor on the
14581 rightmost glyph. Case in point: an empty last line that is
14582 part of an R2L paragraph. */
14584 /* Avoid placing the cursor on the last glyph of the row, where
14585 on terminal frames we hold the vertical border between
14586 adjacent windows. */
14587 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14588 && !WINDOW_RIGHTMOST_P (w
)
14589 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14591 x
= -1; /* will be computed below, at label compute_x */
14594 /* Step 1: Try to find the glyph whose character position
14595 corresponds to point. If that's not possible, find 2 glyphs
14596 whose character positions are the closest to point, one before
14597 point, the other after it. */
14598 if (!row
->reversed_p
)
14599 while (/* not marched to end of glyph row */
14601 /* glyph was not inserted by redisplay for internal purposes */
14602 && !NILP (glyph
->object
))
14604 if (BUFFERP (glyph
->object
))
14606 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14608 if (glyph
->charpos
> bpos_max
)
14609 bpos_max
= glyph
->charpos
;
14610 if (glyph
->charpos
< bpos_min
)
14611 bpos_min
= glyph
->charpos
;
14612 if (!glyph
->avoid_cursor_p
)
14614 /* If we hit point, we've found the glyph on which to
14615 display the cursor. */
14618 match_with_avoid_cursor
= false;
14621 /* See if we've found a better approximation to
14622 POS_BEFORE or to POS_AFTER. */
14623 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14625 pos_before
= glyph
->charpos
;
14626 glyph_before
= glyph
;
14628 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14630 pos_after
= glyph
->charpos
;
14631 glyph_after
= glyph
;
14634 else if (dpos
== 0)
14635 match_with_avoid_cursor
= true;
14637 else if (STRINGP (glyph
->object
))
14639 Lisp_Object chprop
;
14640 ptrdiff_t glyph_pos
= glyph
->charpos
;
14642 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14644 if (!NILP (chprop
))
14646 /* If the string came from a `display' text property,
14647 look up the buffer position of that property and
14648 use that position to update bpos_max, as if we
14649 actually saw such a position in one of the row's
14650 glyphs. This helps with supporting integer values
14651 of `cursor' property on the display string in
14652 situations where most or all of the row's buffer
14653 text is completely covered by display properties,
14654 so that no glyph with valid buffer positions is
14655 ever seen in the row. */
14656 ptrdiff_t prop_pos
=
14657 string_buffer_position_lim (glyph
->object
, pos_before
,
14660 if (prop_pos
>= pos_before
)
14661 bpos_max
= prop_pos
;
14663 if (INTEGERP (chprop
))
14665 bpos_covered
= bpos_max
+ XINT (chprop
);
14666 /* If the `cursor' property covers buffer positions up
14667 to and including point, we should display cursor on
14668 this glyph. Note that, if a `cursor' property on one
14669 of the string's characters has an integer value, we
14670 will break out of the loop below _before_ we get to
14671 the position match above. IOW, integer values of
14672 the `cursor' property override the "exact match for
14673 point" strategy of positioning the cursor. */
14674 /* Implementation note: bpos_max == pt_old when, e.g.,
14675 we are in an empty line, where bpos_max is set to
14676 MATRIX_ROW_START_CHARPOS, see above. */
14677 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14684 string_seen
= true;
14686 x
+= glyph
->pixel_width
;
14689 else if (glyph
> end
) /* row is reversed */
14690 while (!NILP (glyph
->object
))
14692 if (BUFFERP (glyph
->object
))
14694 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14696 if (glyph
->charpos
> bpos_max
)
14697 bpos_max
= glyph
->charpos
;
14698 if (glyph
->charpos
< bpos_min
)
14699 bpos_min
= glyph
->charpos
;
14700 if (!glyph
->avoid_cursor_p
)
14704 match_with_avoid_cursor
= false;
14707 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14709 pos_before
= glyph
->charpos
;
14710 glyph_before
= glyph
;
14712 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14714 pos_after
= glyph
->charpos
;
14715 glyph_after
= glyph
;
14718 else if (dpos
== 0)
14719 match_with_avoid_cursor
= true;
14721 else if (STRINGP (glyph
->object
))
14723 Lisp_Object chprop
;
14724 ptrdiff_t glyph_pos
= glyph
->charpos
;
14726 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14728 if (!NILP (chprop
))
14730 ptrdiff_t prop_pos
=
14731 string_buffer_position_lim (glyph
->object
, pos_before
,
14734 if (prop_pos
>= pos_before
)
14735 bpos_max
= prop_pos
;
14737 if (INTEGERP (chprop
))
14739 bpos_covered
= bpos_max
+ XINT (chprop
);
14740 /* If the `cursor' property covers buffer positions up
14741 to and including point, we should display cursor on
14743 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14749 string_seen
= true;
14752 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14754 x
--; /* can't use any pixel_width */
14757 x
-= glyph
->pixel_width
;
14760 /* Step 2: If we didn't find an exact match for point, we need to
14761 look for a proper place to put the cursor among glyphs between
14762 GLYPH_BEFORE and GLYPH_AFTER. */
14763 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14764 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14765 && !(bpos_max
<= pt_old
&& pt_old
<= bpos_covered
))
14767 /* An empty line has a single glyph whose OBJECT is nil and
14768 whose CHARPOS is the position of a newline on that line.
14769 Note that on a TTY, there are more glyphs after that, which
14770 were produced by extend_face_to_end_of_line, but their
14771 CHARPOS is zero or negative. */
14772 bool empty_line_p
=
14773 ((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14774 && NILP (glyph
->object
) && glyph
->charpos
> 0
14775 /* On a TTY, continued and truncated rows also have a glyph at
14776 their end whose OBJECT is nil and whose CHARPOS is
14777 positive (the continuation and truncation glyphs), but such
14778 rows are obviously not "empty". */
14779 && !(row
->continued_p
|| row
->truncated_on_right_p
));
14781 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14783 ptrdiff_t ellipsis_pos
;
14785 /* Scan back over the ellipsis glyphs. */
14786 if (!row
->reversed_p
)
14788 ellipsis_pos
= (glyph
- 1)->charpos
;
14789 while (glyph
> row
->glyphs
[TEXT_AREA
]
14790 && (glyph
- 1)->charpos
== ellipsis_pos
)
14791 glyph
--, x
-= glyph
->pixel_width
;
14792 /* That loop always goes one position too far, including
14793 the glyph before the ellipsis. So scan forward over
14795 x
+= glyph
->pixel_width
;
14798 else /* row is reversed */
14800 ellipsis_pos
= (glyph
+ 1)->charpos
;
14801 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14802 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14803 glyph
++, x
+= glyph
->pixel_width
;
14804 x
-= glyph
->pixel_width
;
14808 else if (match_with_avoid_cursor
)
14810 cursor
= glyph_after
;
14813 else if (string_seen
)
14815 int incr
= row
->reversed_p
? -1 : +1;
14817 /* Need to find the glyph that came out of a string which is
14818 present at point. That glyph is somewhere between
14819 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14820 positioned between POS_BEFORE and POS_AFTER in the
14822 struct glyph
*start
, *stop
;
14823 ptrdiff_t pos
= pos_before
;
14827 /* If the row ends in a newline from a display string,
14828 reordering could have moved the glyphs belonging to the
14829 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14830 in this case we extend the search to the last glyph in
14831 the row that was not inserted by redisplay. */
14832 if (row
->ends_in_newline_from_string_p
)
14835 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14838 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14839 correspond to POS_BEFORE and POS_AFTER, respectively. We
14840 need START and STOP in the order that corresponds to the
14841 row's direction as given by its reversed_p flag. If the
14842 directionality of characters between POS_BEFORE and
14843 POS_AFTER is the opposite of the row's base direction,
14844 these characters will have been reordered for display,
14845 and we need to reverse START and STOP. */
14846 if (!row
->reversed_p
)
14848 start
= min (glyph_before
, glyph_after
);
14849 stop
= max (glyph_before
, glyph_after
);
14853 start
= max (glyph_before
, glyph_after
);
14854 stop
= min (glyph_before
, glyph_after
);
14856 for (glyph
= start
+ incr
;
14857 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14860 /* Any glyphs that come from the buffer are here because
14861 of bidi reordering. Skip them, and only pay
14862 attention to glyphs that came from some string. */
14863 if (STRINGP (glyph
->object
))
14867 /* If the display property covers the newline, we
14868 need to search for it one position farther. */
14869 ptrdiff_t lim
= pos_after
14870 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14872 string_from_text_prop
= false;
14873 str
= glyph
->object
;
14874 tem
= string_buffer_position_lim (str
, pos
, lim
, false);
14875 if (tem
== 0 /* from overlay */
14878 /* If the string from which this glyph came is
14879 found in the buffer at point, or at position
14880 that is closer to point than pos_after, then
14881 we've found the glyph we've been looking for.
14882 If it comes from an overlay (tem == 0), and
14883 it has the `cursor' property on one of its
14884 glyphs, record that glyph as a candidate for
14885 displaying the cursor. (As in the
14886 unidirectional version, we will display the
14887 cursor on the last candidate we find.) */
14890 || (tem
- pt_old
> 0 && tem
< pos_after
))
14892 /* The glyphs from this string could have
14893 been reordered. Find the one with the
14894 smallest string position. Or there could
14895 be a character in the string with the
14896 `cursor' property, which means display
14897 cursor on that character's glyph. */
14898 ptrdiff_t strpos
= glyph
->charpos
;
14903 string_from_text_prop
= true;
14906 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14907 && EQ (glyph
->object
, str
);
14911 ptrdiff_t gpos
= glyph
->charpos
;
14913 cprop
= Fget_char_property (make_number (gpos
),
14921 if (tem
&& glyph
->charpos
< strpos
)
14923 strpos
= glyph
->charpos
;
14929 || (tem
- pt_old
> 0 && tem
< pos_after
))
14933 pos
= tem
+ 1; /* don't find previous instances */
14935 /* This string is not what we want; skip all of the
14936 glyphs that came from it. */
14937 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14938 && EQ (glyph
->object
, str
))
14945 /* If we reached the end of the line, and END was from a string,
14946 the cursor is not on this line. */
14948 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14949 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14950 && STRINGP (end
->object
)
14951 && row
->continued_p
)
14954 /* A truncated row may not include PT among its character positions.
14955 Setting the cursor inside the scroll margin will trigger
14956 recalculation of hscroll in hscroll_window_tree. But if a
14957 display string covers point, defer to the string-handling
14958 code below to figure this out. */
14959 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14961 cursor
= glyph_before
;
14964 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14965 /* Zero-width characters produce no glyphs. */
14967 && (row
->reversed_p
14968 ? glyph_after
> glyphs_end
14969 : glyph_after
< glyphs_end
)))
14971 cursor
= glyph_after
;
14977 if (cursor
!= NULL
)
14979 else if (glyph
== glyphs_end
14980 && pos_before
== pos_after
14981 && STRINGP ((row
->reversed_p
14982 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14983 : row
->glyphs
[TEXT_AREA
])->object
))
14985 /* If all the glyphs of this row came from strings, put the
14986 cursor on the first glyph of the row. This avoids having the
14987 cursor outside of the text area in this very rare and hard
14991 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14992 : row
->glyphs
[TEXT_AREA
];
14998 /* Need to compute x that corresponds to GLYPH. */
14999 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
15001 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
15003 x
+= g
->pixel_width
;
15007 /* ROW could be part of a continued line, which, under bidi
15008 reordering, might have other rows whose start and end charpos
15009 occlude point. Only set w->cursor if we found a better
15010 approximation to the cursor position than we have from previously
15011 examined candidate rows belonging to the same continued line. */
15012 if (/* We already have a candidate row. */
15013 w
->cursor
.vpos
>= 0
15014 /* That candidate is not the row we are processing. */
15015 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
15016 /* Make sure cursor.vpos specifies a row whose start and end
15017 charpos occlude point, and it is valid candidate for being a
15018 cursor-row. This is because some callers of this function
15019 leave cursor.vpos at the row where the cursor was displayed
15020 during the last redisplay cycle. */
15021 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
15022 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15023 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
15026 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
15028 /* Don't consider glyphs that are outside TEXT_AREA. */
15029 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
15031 /* Keep the candidate whose buffer position is the closest to
15032 point or has the `cursor' property. */
15033 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
15034 w
->cursor
.hpos
>= 0
15035 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
15036 && ((BUFFERP (g1
->object
)
15037 && (g1
->charpos
== pt_old
/* An exact match always wins. */
15038 || (BUFFERP (glyph
->object
)
15039 && eabs (g1
->charpos
- pt_old
)
15040 < eabs (glyph
->charpos
- pt_old
))))
15041 /* Previous candidate is a glyph from a string that has
15042 a non-nil `cursor' property. */
15043 || (STRINGP (g1
->object
)
15044 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
15045 Qcursor
, g1
->object
))
15046 /* Previous candidate is from the same display
15047 string as this one, and the display string
15048 came from a text property. */
15049 || (EQ (g1
->object
, glyph
->object
)
15050 && string_from_text_prop
)
15051 /* this candidate is from newline and its
15052 position is not an exact match */
15053 || (NILP (glyph
->object
)
15054 && glyph
->charpos
!= pt_old
)))))
15056 /* If this candidate gives an exact match, use that. */
15057 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
15058 /* If this candidate is a glyph created for the
15059 terminating newline of a line, and point is on that
15060 newline, it wins because it's an exact match. */
15061 || (!row
->continued_p
15062 && NILP (glyph
->object
)
15063 && glyph
->charpos
== 0
15064 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
15065 /* Otherwise, keep the candidate that comes from a row
15066 spanning less buffer positions. This may win when one or
15067 both candidate positions are on glyphs that came from
15068 display strings, for which we cannot compare buffer
15070 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15071 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15072 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
15075 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
15077 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
15078 w
->cursor
.y
= row
->y
+ dy
;
15080 if (w
== XWINDOW (selected_window
))
15082 if (!row
->continued_p
15083 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15086 this_line_buffer
= XBUFFER (w
->contents
);
15088 CHARPOS (this_line_start_pos
)
15089 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
15090 BYTEPOS (this_line_start_pos
)
15091 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
15093 CHARPOS (this_line_end_pos
)
15094 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
15095 BYTEPOS (this_line_end_pos
)
15096 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
15098 this_line_y
= w
->cursor
.y
;
15099 this_line_pixel_height
= row
->height
;
15100 this_line_vpos
= w
->cursor
.vpos
;
15101 this_line_start_x
= row
->x
;
15104 CHARPOS (this_line_start_pos
) = 0;
15111 /* Run window scroll functions, if any, for WINDOW with new window
15112 start STARTP. Sets the window start of WINDOW to that position.
15114 We assume that the window's buffer is really current. */
15116 static struct text_pos
15117 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
15119 struct window
*w
= XWINDOW (window
);
15120 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
15122 eassert (current_buffer
== XBUFFER (w
->contents
));
15124 if (!NILP (Vwindow_scroll_functions
))
15126 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
15127 make_number (CHARPOS (startp
)));
15128 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15129 /* In case the hook functions switch buffers. */
15130 set_buffer_internal (XBUFFER (w
->contents
));
15137 /* Make sure the line containing the cursor is fully visible.
15138 A value of true means there is nothing to be done.
15139 (Either the line is fully visible, or it cannot be made so,
15140 or we cannot tell.)
15142 If FORCE_P, return false even if partial visible cursor row
15143 is higher than window.
15145 If CURRENT_MATRIX_P, use the information from the
15146 window's current glyph matrix; otherwise use the desired glyph
15149 A value of false means the caller should do scrolling
15150 as if point had gone off the screen. */
15153 cursor_row_fully_visible_p (struct window
*w
, bool force_p
,
15154 bool current_matrix_p
)
15156 struct glyph_matrix
*matrix
;
15157 struct glyph_row
*row
;
15160 if (!make_cursor_line_fully_visible_p
)
15163 /* It's not always possible to find the cursor, e.g, when a window
15164 is full of overlay strings. Don't do anything in that case. */
15165 if (w
->cursor
.vpos
< 0)
15168 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
15169 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
15171 /* If the cursor row is not partially visible, there's nothing to do. */
15172 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
15175 /* If the row the cursor is in is taller than the window's height,
15176 it's not clear what to do, so do nothing. */
15177 window_height
= window_box_height (w
);
15178 if (row
->height
>= window_height
)
15180 if (!force_p
|| MINI_WINDOW_P (w
)
15181 || w
->vscroll
|| w
->cursor
.vpos
== 0)
15188 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
15189 means only WINDOW is redisplayed in redisplay_internal.
15190 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
15191 in redisplay_window to bring a partially visible line into view in
15192 the case that only the cursor has moved.
15194 LAST_LINE_MISFIT should be true if we're scrolling because the
15195 last screen line's vertical height extends past the end of the screen.
15199 1 if scrolling succeeded
15201 0 if scrolling didn't find point.
15203 -1 if new fonts have been loaded so that we must interrupt
15204 redisplay, adjust glyph matrices, and try again. */
15210 SCROLLING_NEED_LARGER_MATRICES
15213 /* If scroll-conservatively is more than this, never recenter.
15215 If you change this, don't forget to update the doc string of
15216 `scroll-conservatively' and the Emacs manual. */
15217 #define SCROLL_LIMIT 100
15220 try_scrolling (Lisp_Object window
, bool just_this_one_p
,
15221 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
15222 bool temp_scroll_step
, bool last_line_misfit
)
15224 struct window
*w
= XWINDOW (window
);
15225 struct frame
*f
= XFRAME (w
->frame
);
15226 struct text_pos pos
, startp
;
15228 int this_scroll_margin
, scroll_max
, rc
, height
;
15229 int dy
= 0, amount_to_scroll
= 0;
15230 bool scroll_down_p
= false;
15231 int extra_scroll_margin_lines
= last_line_misfit
;
15232 Lisp_Object aggressive
;
15233 /* We will never try scrolling more than this number of lines. */
15234 int scroll_limit
= SCROLL_LIMIT
;
15235 int frame_line_height
= default_line_pixel_height (w
);
15236 int window_total_lines
15237 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15240 debug_method_add (w
, "try_scrolling");
15243 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15245 /* Compute scroll margin height in pixels. We scroll when point is
15246 within this distance from the top or bottom of the window. */
15247 if (scroll_margin
> 0)
15248 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
15249 * frame_line_height
;
15251 this_scroll_margin
= 0;
15253 /* Force arg_scroll_conservatively to have a reasonable value, to
15254 avoid scrolling too far away with slow move_it_* functions. Note
15255 that the user can supply scroll-conservatively equal to
15256 `most-positive-fixnum', which can be larger than INT_MAX. */
15257 if (arg_scroll_conservatively
> scroll_limit
)
15259 arg_scroll_conservatively
= scroll_limit
+ 1;
15260 scroll_max
= scroll_limit
* frame_line_height
;
15262 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
15263 /* Compute how much we should try to scroll maximally to bring
15264 point into view. */
15265 scroll_max
= (max (scroll_step
,
15266 max (arg_scroll_conservatively
, temp_scroll_step
))
15267 * frame_line_height
);
15268 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
15269 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
15270 /* We're trying to scroll because of aggressive scrolling but no
15271 scroll_step is set. Choose an arbitrary one. */
15272 scroll_max
= 10 * frame_line_height
;
15278 /* Decide whether to scroll down. */
15279 if (PT
> CHARPOS (startp
))
15281 int scroll_margin_y
;
15283 /* Compute the pixel ypos of the scroll margin, then move IT to
15284 either that ypos or PT, whichever comes first. */
15285 start_display (&it
, w
, startp
);
15286 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
15287 - frame_line_height
* extra_scroll_margin_lines
;
15288 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
15289 (MOVE_TO_POS
| MOVE_TO_Y
));
15291 if (PT
> CHARPOS (it
.current
.pos
))
15293 int y0
= line_bottom_y (&it
);
15294 /* Compute how many pixels below window bottom to stop searching
15295 for PT. This avoids costly search for PT that is far away if
15296 the user limited scrolling by a small number of lines, but
15297 always finds PT if scroll_conservatively is set to a large
15298 number, such as most-positive-fixnum. */
15299 int slack
= max (scroll_max
, 10 * frame_line_height
);
15300 int y_to_move
= it
.last_visible_y
+ slack
;
15302 /* Compute the distance from the scroll margin to PT or to
15303 the scroll limit, whichever comes first. This should
15304 include the height of the cursor line, to make that line
15306 move_it_to (&it
, PT
, -1, y_to_move
,
15307 -1, MOVE_TO_POS
| MOVE_TO_Y
);
15308 dy
= line_bottom_y (&it
) - y0
;
15310 if (dy
> scroll_max
)
15311 return SCROLLING_FAILED
;
15314 scroll_down_p
= true;
15320 /* Point is in or below the bottom scroll margin, so move the
15321 window start down. If scrolling conservatively, move it just
15322 enough down to make point visible. If scroll_step is set,
15323 move it down by scroll_step. */
15324 if (arg_scroll_conservatively
)
15326 = min (max (dy
, frame_line_height
),
15327 frame_line_height
* arg_scroll_conservatively
);
15328 else if (scroll_step
|| temp_scroll_step
)
15329 amount_to_scroll
= scroll_max
;
15332 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
15333 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15334 if (NUMBERP (aggressive
))
15336 double float_amount
= XFLOATINT (aggressive
) * height
;
15337 int aggressive_scroll
= float_amount
;
15338 if (aggressive_scroll
== 0 && float_amount
> 0)
15339 aggressive_scroll
= 1;
15340 /* Don't let point enter the scroll margin near top of
15341 the window. This could happen if the value of
15342 scroll_up_aggressively is too large and there are
15343 non-zero margins, because scroll_up_aggressively
15344 means put point that fraction of window height
15345 _from_the_bottom_margin_. */
15346 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15347 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15348 amount_to_scroll
= dy
+ aggressive_scroll
;
15352 if (amount_to_scroll
<= 0)
15353 return SCROLLING_FAILED
;
15355 start_display (&it
, w
, startp
);
15356 if (arg_scroll_conservatively
<= scroll_limit
)
15357 move_it_vertically (&it
, amount_to_scroll
);
15360 /* Extra precision for users who set scroll-conservatively
15361 to a large number: make sure the amount we scroll
15362 the window start is never less than amount_to_scroll,
15363 which was computed as distance from window bottom to
15364 point. This matters when lines at window top and lines
15365 below window bottom have different height. */
15367 void *it1data
= NULL
;
15368 /* We use a temporary it1 because line_bottom_y can modify
15369 its argument, if it moves one line down; see there. */
15372 SAVE_IT (it1
, it
, it1data
);
15373 start_y
= line_bottom_y (&it1
);
15375 RESTORE_IT (&it
, &it
, it1data
);
15376 move_it_by_lines (&it
, 1);
15377 SAVE_IT (it1
, it
, it1data
);
15378 } while (IT_CHARPOS (it
) < ZV
15379 && line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
15380 bidi_unshelve_cache (it1data
, true);
15383 /* If STARTP is unchanged, move it down another screen line. */
15384 if (IT_CHARPOS (it
) == CHARPOS (startp
))
15385 move_it_by_lines (&it
, 1);
15386 startp
= it
.current
.pos
;
15390 struct text_pos scroll_margin_pos
= startp
;
15393 /* See if point is inside the scroll margin at the top of the
15395 if (this_scroll_margin
)
15399 start_display (&it
, w
, startp
);
15400 y_start
= it
.current_y
;
15401 move_it_vertically (&it
, this_scroll_margin
);
15402 scroll_margin_pos
= it
.current
.pos
;
15403 /* If we didn't move enough before hitting ZV, request
15404 additional amount of scroll, to move point out of the
15406 if (IT_CHARPOS (it
) == ZV
15407 && it
.current_y
- y_start
< this_scroll_margin
)
15408 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
15411 if (PT
< CHARPOS (scroll_margin_pos
))
15413 /* Point is in the scroll margin at the top of the window or
15414 above what is displayed in the window. */
15417 /* Compute the vertical distance from PT to the scroll
15418 margin position. Move as far as scroll_max allows, or
15419 one screenful, or 10 screen lines, whichever is largest.
15420 Give up if distance is greater than scroll_max or if we
15421 didn't reach the scroll margin position. */
15422 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
15423 start_display (&it
, w
, pos
);
15425 y_to_move
= max (it
.last_visible_y
,
15426 max (scroll_max
, 10 * frame_line_height
));
15427 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
15429 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15430 dy
= it
.current_y
- y0
;
15431 if (dy
> scroll_max
15432 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
15433 return SCROLLING_FAILED
;
15435 /* Additional scroll for when ZV was too close to point. */
15438 /* Compute new window start. */
15439 start_display (&it
, w
, startp
);
15441 if (arg_scroll_conservatively
)
15442 amount_to_scroll
= max (dy
, frame_line_height
15443 * max (scroll_step
, temp_scroll_step
));
15444 else if (scroll_step
|| temp_scroll_step
)
15445 amount_to_scroll
= scroll_max
;
15448 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15449 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15450 if (NUMBERP (aggressive
))
15452 double float_amount
= XFLOATINT (aggressive
) * height
;
15453 int aggressive_scroll
= float_amount
;
15454 if (aggressive_scroll
== 0 && float_amount
> 0)
15455 aggressive_scroll
= 1;
15456 /* Don't let point enter the scroll margin near
15457 bottom of the window, if the value of
15458 scroll_down_aggressively happens to be too
15460 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15461 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15462 amount_to_scroll
= dy
+ aggressive_scroll
;
15466 if (amount_to_scroll
<= 0)
15467 return SCROLLING_FAILED
;
15469 move_it_vertically_backward (&it
, amount_to_scroll
);
15470 startp
= it
.current
.pos
;
15474 /* Run window scroll functions. */
15475 startp
= run_window_scroll_functions (window
, startp
);
15477 /* Display the window. Give up if new fonts are loaded, or if point
15479 if (!try_window (window
, startp
, 0))
15480 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15481 else if (w
->cursor
.vpos
< 0)
15483 clear_glyph_matrix (w
->desired_matrix
);
15484 rc
= SCROLLING_FAILED
;
15488 /* Maybe forget recorded base line for line number display. */
15489 if (!just_this_one_p
15490 || current_buffer
->clip_changed
15491 || BEG_UNCHANGED
< CHARPOS (startp
))
15492 w
->base_line_number
= 0;
15494 /* If cursor ends up on a partially visible line,
15495 treat that as being off the bottom of the screen. */
15496 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1,
15498 /* It's possible that the cursor is on the first line of the
15499 buffer, which is partially obscured due to a vscroll
15500 (Bug#7537). In that case, avoid looping forever. */
15501 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15503 clear_glyph_matrix (w
->desired_matrix
);
15504 ++extra_scroll_margin_lines
;
15507 rc
= SCROLLING_SUCCESS
;
15514 /* Compute a suitable window start for window W if display of W starts
15515 on a continuation line. Value is true if a new window start
15518 The new window start will be computed, based on W's width, starting
15519 from the start of the continued line. It is the start of the
15520 screen line with the minimum distance from the old start W->start,
15521 which is still before point (otherwise point will definitely not
15522 be visible in the window). */
15525 compute_window_start_on_continuation_line (struct window
*w
)
15527 struct text_pos pos
, start_pos
, pos_before_pt
;
15528 bool window_start_changed_p
= false;
15530 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15532 /* If window start is on a continuation line... Window start may be
15533 < BEGV in case there's invisible text at the start of the
15534 buffer (M-x rmail, for example). */
15535 if (CHARPOS (start_pos
) > BEGV
15536 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15539 struct glyph_row
*row
;
15541 /* Handle the case that the window start is out of range. */
15542 if (CHARPOS (start_pos
) < BEGV
)
15543 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15544 else if (CHARPOS (start_pos
) > ZV
)
15545 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15547 /* Find the start of the continued line. This should be fast
15548 because find_newline is fast (newline cache). */
15549 row
= w
->desired_matrix
->rows
+ WINDOW_WANTS_HEADER_LINE_P (w
);
15550 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15551 row
, DEFAULT_FACE_ID
);
15552 reseat_at_previous_visible_line_start (&it
);
15554 /* If the line start is "too far" away from the window start,
15555 say it takes too much time to compute a new window start.
15556 Also, give up if the line start is after point, as in that
15557 case point will not be visible with any window start we
15559 if (IT_CHARPOS (it
) <= PT
15560 || (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15561 /* PXW: Do we need upper bounds here? */
15562 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
)))
15564 int min_distance
, distance
;
15566 /* Move forward by display lines to find the new window
15567 start. If window width was enlarged, the new start can
15568 be expected to be > the old start. If window width was
15569 decreased, the new window start will be < the old start.
15570 So, we're looking for the display line start with the
15571 minimum distance from the old window start. */
15572 pos_before_pt
= pos
= it
.current
.pos
;
15573 min_distance
= INFINITY
;
15574 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15575 distance
< min_distance
)
15577 min_distance
= distance
;
15578 if (CHARPOS (pos
) <= PT
)
15579 pos_before_pt
= pos
;
15580 pos
= it
.current
.pos
;
15581 if (it
.line_wrap
== WORD_WRAP
)
15583 /* Under WORD_WRAP, move_it_by_lines is likely to
15584 overshoot and stop not at the first, but the
15585 second character from the left margin. So in
15586 that case, we need a more tight control on the X
15587 coordinate of the iterator than move_it_by_lines
15588 promises in its contract. The method is to first
15589 go to the last (rightmost) visible character of a
15590 line, then move to the leftmost character on the
15591 next line in a separate call. */
15592 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15593 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15594 move_it_to (&it
, ZV
, 0,
15595 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15596 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15599 move_it_by_lines (&it
, 1);
15602 /* It makes very little sense to make the new window start
15603 after point, as point won't be visible. If that's what
15604 the loop above finds, fall back on the candidate before
15605 or at point that is closest to the old window start. */
15606 if (CHARPOS (pos
) > PT
)
15607 pos
= pos_before_pt
;
15609 /* Set the window start there. */
15610 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15611 window_start_changed_p
= true;
15615 return window_start_changed_p
;
15619 /* Try cursor movement in case text has not changed in window WINDOW,
15620 with window start STARTP. Value is
15622 CURSOR_MOVEMENT_SUCCESS if successful
15624 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15626 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15627 display. *SCROLL_STEP is set to true, under certain circumstances, if
15628 we want to scroll as if scroll-step were set to 1. See the code.
15630 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15631 which case we have to abort this redisplay, and adjust matrices
15636 CURSOR_MOVEMENT_SUCCESS
,
15637 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15638 CURSOR_MOVEMENT_MUST_SCROLL
,
15639 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15643 try_cursor_movement (Lisp_Object window
, struct text_pos startp
,
15646 struct window
*w
= XWINDOW (window
);
15647 struct frame
*f
= XFRAME (w
->frame
);
15648 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15651 if (inhibit_try_cursor_movement
)
15655 /* Previously, there was a check for Lisp integer in the
15656 if-statement below. Now, this field is converted to
15657 ptrdiff_t, thus zero means invalid position in a buffer. */
15658 eassert (w
->last_point
> 0);
15659 /* Likewise there was a check whether window_end_vpos is nil or larger
15660 than the window. Now window_end_vpos is int and so never nil, but
15661 let's leave eassert to check whether it fits in the window. */
15662 eassert (!w
->window_end_valid
15663 || w
->window_end_vpos
< w
->current_matrix
->nrows
);
15665 /* Handle case where text has not changed, only point, and it has
15666 not moved off the frame. */
15667 if (/* Point may be in this window. */
15668 PT
>= CHARPOS (startp
)
15669 /* Selective display hasn't changed. */
15670 && !current_buffer
->clip_changed
15671 /* Function force-mode-line-update is used to force a thorough
15672 redisplay. It sets either windows_or_buffers_changed or
15673 update_mode_lines. So don't take a shortcut here for these
15675 && !update_mode_lines
15676 && !windows_or_buffers_changed
15677 && !f
->cursor_type_changed
15678 && NILP (Vshow_trailing_whitespace
)
15679 /* This code is not used for mini-buffer for the sake of the case
15680 of redisplaying to replace an echo area message; since in
15681 that case the mini-buffer contents per se are usually
15682 unchanged. This code is of no real use in the mini-buffer
15683 since the handling of this_line_start_pos, etc., in redisplay
15684 handles the same cases. */
15685 && !EQ (window
, minibuf_window
)
15686 && (FRAME_WINDOW_P (f
)
15687 || !overlay_arrow_in_current_buffer_p ()))
15689 int this_scroll_margin
, top_scroll_margin
;
15690 struct glyph_row
*row
= NULL
;
15691 int frame_line_height
= default_line_pixel_height (w
);
15692 int window_total_lines
15693 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15696 debug_method_add (w
, "cursor movement");
15699 /* Scroll if point within this distance from the top or bottom
15700 of the window. This is a pixel value. */
15701 if (scroll_margin
> 0)
15703 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15704 this_scroll_margin
*= frame_line_height
;
15707 this_scroll_margin
= 0;
15709 top_scroll_margin
= this_scroll_margin
;
15710 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15711 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15713 /* Start with the row the cursor was displayed during the last
15714 not paused redisplay. Give up if that row is not valid. */
15715 if (w
->last_cursor_vpos
< 0
15716 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15717 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15720 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15721 if (row
->mode_line_p
)
15723 if (!row
->enabled_p
)
15724 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15727 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15729 bool scroll_p
= false, must_scroll
= false;
15730 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15732 if (PT
> w
->last_point
)
15734 /* Point has moved forward. */
15735 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15736 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15738 eassert (row
->enabled_p
);
15742 /* If the end position of a row equals the start
15743 position of the next row, and PT is at that position,
15744 we would rather display cursor in the next line. */
15745 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15746 && MATRIX_ROW_END_CHARPOS (row
) == PT
15747 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15748 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15749 && !cursor_row_p (row
))
15752 /* If within the scroll margin, scroll. Note that
15753 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15754 the next line would be drawn, and that
15755 this_scroll_margin can be zero. */
15756 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15757 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15758 /* Line is completely visible last line in window
15759 and PT is to be set in the next line. */
15760 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15761 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15762 && !row
->ends_at_zv_p
15763 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15766 else if (PT
< w
->last_point
)
15768 /* Cursor has to be moved backward. Note that PT >=
15769 CHARPOS (startp) because of the outer if-statement. */
15770 while (!row
->mode_line_p
15771 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15772 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15773 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15774 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15775 row
> w
->current_matrix
->rows
15776 && (row
-1)->ends_in_newline_from_string_p
))))
15777 && (row
->y
> top_scroll_margin
15778 || CHARPOS (startp
) == BEGV
))
15780 eassert (row
->enabled_p
);
15784 /* Consider the following case: Window starts at BEGV,
15785 there is invisible, intangible text at BEGV, so that
15786 display starts at some point START > BEGV. It can
15787 happen that we are called with PT somewhere between
15788 BEGV and START. Try to handle that case. */
15789 if (row
< w
->current_matrix
->rows
15790 || row
->mode_line_p
)
15792 row
= w
->current_matrix
->rows
;
15793 if (row
->mode_line_p
)
15797 /* Due to newlines in overlay strings, we may have to
15798 skip forward over overlay strings. */
15799 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15800 && MATRIX_ROW_END_CHARPOS (row
) == PT
15801 && !cursor_row_p (row
))
15804 /* If within the scroll margin, scroll. */
15805 if (row
->y
< top_scroll_margin
15806 && CHARPOS (startp
) != BEGV
)
15811 /* Cursor did not move. So don't scroll even if cursor line
15812 is partially visible, as it was so before. */
15813 rc
= CURSOR_MOVEMENT_SUCCESS
;
15816 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15817 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15819 /* if PT is not in the glyph row, give up. */
15820 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15821 must_scroll
= true;
15823 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15824 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15826 struct glyph_row
*row1
;
15828 /* If rows are bidi-reordered and point moved, back up
15829 until we find a row that does not belong to a
15830 continuation line. This is because we must consider
15831 all rows of a continued line as candidates for the
15832 new cursor positioning, since row start and end
15833 positions change non-linearly with vertical position
15835 /* FIXME: Revisit this when glyph ``spilling'' in
15836 continuation lines' rows is implemented for
15837 bidi-reordered rows. */
15838 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15839 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15842 /* If we hit the beginning of the displayed portion
15843 without finding the first row of a continued
15847 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15850 eassert (row
->enabled_p
);
15855 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15856 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15857 /* Make sure this isn't a header line by any chance, since
15858 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield true. */
15859 && !row
->mode_line_p
15860 && make_cursor_line_fully_visible_p
)
15862 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15863 && !row
->ends_at_zv_p
15864 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15865 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15866 else if (row
->height
> window_box_height (w
))
15868 /* If we end up in a partially visible line, let's
15869 make it fully visible, except when it's taller
15870 than the window, in which case we can't do much
15872 *scroll_step
= true;
15873 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15877 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15878 if (!cursor_row_fully_visible_p (w
, false, true))
15879 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15881 rc
= CURSOR_MOVEMENT_SUCCESS
;
15885 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15886 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15887 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15889 /* With bidi-reordered rows, there could be more than
15890 one candidate row whose start and end positions
15891 occlude point. We need to let set_cursor_from_row
15892 find the best candidate. */
15893 /* FIXME: Revisit this when glyph ``spilling'' in
15894 continuation lines' rows is implemented for
15895 bidi-reordered rows. */
15900 bool at_zv_p
= false, exact_match_p
= false;
15902 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15903 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15904 && cursor_row_p (row
))
15905 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15907 /* As soon as we've found the exact match for point,
15908 or the first suitable row whose ends_at_zv_p flag
15909 is set, we are done. */
15912 at_zv_p
= MATRIX_ROW (w
->current_matrix
,
15913 w
->cursor
.vpos
)->ends_at_zv_p
;
15915 && w
->cursor
.hpos
>= 0
15916 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15919 struct glyph_row
*candidate
=
15920 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15922 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15923 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15926 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15927 || (NILP (g
->object
)
15928 && (g
->charpos
== PT
15929 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15931 if (at_zv_p
|| exact_match_p
)
15933 rc
= CURSOR_MOVEMENT_SUCCESS
;
15937 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15941 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15942 || row
->continued_p
)
15943 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15944 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15945 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15946 /* If we didn't find any candidate rows, or exited the
15947 loop before all the candidates were examined, signal
15948 to the caller that this method failed. */
15949 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15951 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15952 && !row
->continued_p
))
15953 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15955 rc
= CURSOR_MOVEMENT_SUCCESS
;
15961 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15963 rc
= CURSOR_MOVEMENT_SUCCESS
;
15968 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15969 && MATRIX_ROW_START_CHARPOS (row
) == PT
15970 && cursor_row_p (row
));
15980 set_vertical_scroll_bar (struct window
*w
)
15982 ptrdiff_t start
, end
, whole
;
15984 /* Calculate the start and end positions for the current window.
15985 At some point, it would be nice to choose between scrollbars
15986 which reflect the whole buffer size, with special markers
15987 indicating narrowing, and scrollbars which reflect only the
15990 Note that mini-buffers sometimes aren't displaying any text. */
15991 if (!MINI_WINDOW_P (w
)
15992 || (w
== XWINDOW (minibuf_window
)
15993 && NILP (echo_area_buffer
[0])))
15995 struct buffer
*buf
= XBUFFER (w
->contents
);
15996 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15997 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15998 /* I don't think this is guaranteed to be right. For the
15999 moment, we'll pretend it is. */
16000 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
16004 if (whole
< (end
- start
))
16005 whole
= end
- start
;
16008 start
= end
= whole
= 0;
16010 /* Indicate what this scroll bar ought to be displaying now. */
16011 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
16012 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
16013 (w
, end
- start
, whole
, start
);
16018 set_horizontal_scroll_bar (struct window
*w
)
16020 int start
, end
, whole
, portion
;
16022 if (!MINI_WINDOW_P (w
)
16023 || (w
== XWINDOW (minibuf_window
)
16024 && NILP (echo_area_buffer
[0])))
16026 struct buffer
*b
= XBUFFER (w
->contents
);
16027 struct buffer
*old_buffer
= NULL
;
16029 struct text_pos startp
;
16031 if (b
!= current_buffer
)
16033 old_buffer
= current_buffer
;
16034 set_buffer_internal (b
);
16037 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16038 start_display (&it
, w
, startp
);
16039 it
.last_visible_x
= INT_MAX
;
16040 whole
= move_it_to (&it
, -1, INT_MAX
, window_box_height (w
), -1,
16041 MOVE_TO_X
| MOVE_TO_Y
);
16042 /* whole = move_it_to (&it, w->window_end_pos, INT_MAX,
16043 window_box_height (w), -1,
16044 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); */
16046 start
= w
->hscroll
* FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
16047 end
= start
+ window_box_width (w
, TEXT_AREA
);
16048 portion
= end
- start
;
16049 /* After enlarging a horizontally scrolled window such that it
16050 gets at least as wide as the text it contains, make sure that
16051 the thumb doesn't fill the entire scroll bar so we can still
16052 drag it back to see the entire text. */
16053 whole
= max (whole
, end
);
16059 pdir
= Fcurrent_bidi_paragraph_direction (Qnil
);
16060 if (EQ (pdir
, Qright_to_left
))
16062 start
= whole
- end
;
16063 end
= start
+ portion
;
16068 set_buffer_internal (old_buffer
);
16071 start
= end
= whole
= portion
= 0;
16073 w
->hscroll_whole
= whole
;
16075 /* Indicate what this scroll bar ought to be displaying now. */
16076 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
16077 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
16078 (w
, portion
, whole
, start
);
16082 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P means only
16083 selected_window is redisplayed.
16085 We can return without actually redisplaying the window if fonts has been
16086 changed on window's frame. In that case, redisplay_internal will retry.
16088 As one of the important parts of redisplaying a window, we need to
16089 decide whether the previous window-start position (stored in the
16090 window's w->start marker position) is still valid, and if it isn't,
16091 recompute it. Some details about that:
16093 . The previous window-start could be in a continuation line, in
16094 which case we need to recompute it when the window width
16095 changes. See compute_window_start_on_continuation_line and its
16098 . The text that changed since last redisplay could include the
16099 previous window-start position. In that case, we try to salvage
16100 what we can from the current glyph matrix by calling
16101 try_scrolling, which see.
16103 . Some Emacs command could force us to use a specific window-start
16104 position by setting the window's force_start flag, or gently
16105 propose doing that by setting the window's optional_new_start
16106 flag. In these cases, we try using the specified start point if
16107 that succeeds (i.e. the window desired matrix is successfully
16108 recomputed, and point location is within the window). In case
16109 of optional_new_start, we first check if the specified start
16110 position is feasible, i.e. if it will allow point to be
16111 displayed in the window. If using the specified start point
16112 fails, e.g., if new fonts are needed to be loaded, we abort the
16113 redisplay cycle and leave it up to the next cycle to figure out
16116 . Note that the window's force_start flag is sometimes set by
16117 redisplay itself, when it decides that the previous window start
16118 point is fine and should be kept. Search for "goto force_start"
16119 below to see the details. Like the values of window-start
16120 specified outside of redisplay, these internally-deduced values
16121 are tested for feasibility, and ignored if found to be
16124 . Note that the function try_window, used to completely redisplay
16125 a window, accepts the window's start point as its argument.
16126 This is used several times in the redisplay code to control
16127 where the window start will be, according to user options such
16128 as scroll-conservatively, and also to ensure the screen line
16129 showing point will be fully (as opposed to partially) visible on
16133 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
16135 struct window
*w
= XWINDOW (window
);
16136 struct frame
*f
= XFRAME (w
->frame
);
16137 struct buffer
*buffer
= XBUFFER (w
->contents
);
16138 struct buffer
*old
= current_buffer
;
16139 struct text_pos lpoint
, opoint
, startp
;
16140 bool update_mode_line
;
16143 /* Record it now because it's overwritten. */
16144 bool current_matrix_up_to_date_p
= false;
16145 bool used_current_matrix_p
= false;
16146 /* This is less strict than current_matrix_up_to_date_p.
16147 It indicates that the buffer contents and narrowing are unchanged. */
16148 bool buffer_unchanged_p
= false;
16149 bool temp_scroll_step
= false;
16150 ptrdiff_t count
= SPECPDL_INDEX ();
16152 int centering_position
= -1;
16153 bool last_line_misfit
= false;
16154 ptrdiff_t beg_unchanged
, end_unchanged
;
16155 int frame_line_height
;
16156 bool use_desired_matrix
;
16158 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16162 *w
->desired_matrix
->method
= 0;
16165 if (!just_this_one_p
16166 && REDISPLAY_SOME_P ()
16168 && !w
->update_mode_line
16171 && !buffer
->text
->redisplay
16172 && BUF_PT (buffer
) == w
->last_point
)
16175 /* Make sure that both W's markers are valid. */
16176 eassert (XMARKER (w
->start
)->buffer
== buffer
);
16177 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
16179 /* We come here again if we need to run window-text-change-functions
16182 reconsider_clip_changes (w
);
16183 frame_line_height
= default_line_pixel_height (w
);
16185 /* Has the mode line to be updated? */
16186 update_mode_line
= (w
->update_mode_line
16187 || update_mode_lines
16188 || buffer
->clip_changed
16189 || buffer
->prevent_redisplay_optimizations_p
);
16191 if (!just_this_one_p
)
16192 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
16193 cleverly elsewhere. */
16194 w
->must_be_updated_p
= true;
16196 if (MINI_WINDOW_P (w
))
16198 if (w
== XWINDOW (echo_area_window
)
16199 && !NILP (echo_area_buffer
[0]))
16201 if (update_mode_line
)
16202 /* We may have to update a tty frame's menu bar or a
16203 tool-bar. Example `M-x C-h C-h C-g'. */
16204 goto finish_menu_bars
;
16206 /* We've already displayed the echo area glyphs in this window. */
16207 goto finish_scroll_bars
;
16209 else if ((w
!= XWINDOW (minibuf_window
)
16210 || minibuf_level
== 0)
16211 /* When buffer is nonempty, redisplay window normally. */
16212 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
16213 /* Quail displays non-mini buffers in minibuffer window.
16214 In that case, redisplay the window normally. */
16215 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
16217 /* W is a mini-buffer window, but it's not active, so clear
16219 int yb
= window_text_bottom_y (w
);
16220 struct glyph_row
*row
;
16223 for (y
= 0, row
= w
->desired_matrix
->rows
;
16225 y
+= row
->height
, ++row
)
16226 blank_row (w
, row
, y
);
16227 goto finish_scroll_bars
;
16230 clear_glyph_matrix (w
->desired_matrix
);
16233 /* Otherwise set up data on this window; select its buffer and point
16235 /* Really select the buffer, for the sake of buffer-local
16237 set_buffer_internal_1 (XBUFFER (w
->contents
));
16239 current_matrix_up_to_date_p
16240 = (w
->window_end_valid
16241 && !current_buffer
->clip_changed
16242 && !current_buffer
->prevent_redisplay_optimizations_p
16243 && !window_outdated (w
));
16245 /* Run the window-text-change-functions
16246 if it is possible that the text on the screen has changed
16247 (either due to modification of the text, or any other reason). */
16248 if (!current_matrix_up_to_date_p
16249 && !NILP (Vwindow_text_change_functions
))
16251 safe_run_hooks (Qwindow_text_change_functions
);
16255 beg_unchanged
= BEG_UNCHANGED
;
16256 end_unchanged
= END_UNCHANGED
;
16258 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
16260 specbind (Qinhibit_point_motion_hooks
, Qt
);
16263 = (w
->window_end_valid
16264 && !current_buffer
->clip_changed
16265 && !window_outdated (w
));
16267 /* When windows_or_buffers_changed is non-zero, we can't rely
16268 on the window end being valid, so set it to zero there. */
16269 if (windows_or_buffers_changed
)
16271 /* If window starts on a continuation line, maybe adjust the
16272 window start in case the window's width changed. */
16273 if (XMARKER (w
->start
)->buffer
== current_buffer
)
16274 compute_window_start_on_continuation_line (w
);
16276 w
->window_end_valid
= false;
16277 /* If so, we also can't rely on current matrix
16278 and should not fool try_cursor_movement below. */
16279 current_matrix_up_to_date_p
= false;
16282 /* Some sanity checks. */
16283 CHECK_WINDOW_END (w
);
16284 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
16286 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
16289 if (mode_line_update_needed (w
))
16290 update_mode_line
= true;
16292 /* Point refers normally to the selected window. For any other
16293 window, set up appropriate value. */
16294 if (!EQ (window
, selected_window
))
16296 ptrdiff_t new_pt
= marker_position (w
->pointm
);
16297 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
16302 new_pt_byte
= BEGV_BYTE
;
16303 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
16305 else if (new_pt
> (ZV
- 1))
16308 new_pt_byte
= ZV_BYTE
;
16309 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
16312 /* We don't use SET_PT so that the point-motion hooks don't run. */
16313 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
16316 /* If any of the character widths specified in the display table
16317 have changed, invalidate the width run cache. It's true that
16318 this may be a bit late to catch such changes, but the rest of
16319 redisplay goes (non-fatally) haywire when the display table is
16320 changed, so why should we worry about doing any better? */
16321 if (current_buffer
->width_run_cache
16322 || (current_buffer
->base_buffer
16323 && current_buffer
->base_buffer
->width_run_cache
))
16325 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
16327 if (! disptab_matches_widthtab
16328 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
16330 struct buffer
*buf
= current_buffer
;
16332 if (buf
->base_buffer
)
16333 buf
= buf
->base_buffer
;
16334 invalidate_region_cache (buf
, buf
->width_run_cache
, BEG
, Z
);
16335 recompute_width_table (current_buffer
, disptab
);
16339 /* If window-start is screwed up, choose a new one. */
16340 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
16343 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16345 /* If someone specified a new starting point but did not insist,
16346 check whether it can be used. */
16347 if ((w
->optional_new_start
|| window_frozen_p (w
))
16348 && CHARPOS (startp
) >= BEGV
16349 && CHARPOS (startp
) <= ZV
)
16351 ptrdiff_t it_charpos
;
16353 w
->optional_new_start
= false;
16354 start_display (&it
, w
, startp
);
16355 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
16356 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
16357 /* Record IT's position now, since line_bottom_y might change
16359 it_charpos
= IT_CHARPOS (it
);
16360 /* Make sure we set the force_start flag only if the cursor row
16361 will be fully visible. Otherwise, the code under force_start
16362 label below will try to move point back into view, which is
16363 not what the code which sets optional_new_start wants. */
16364 if ((it
.current_y
== 0 || line_bottom_y (&it
) < it
.last_visible_y
)
16365 && !w
->force_start
)
16367 if (it_charpos
== PT
)
16368 w
->force_start
= true;
16369 /* IT may overshoot PT if text at PT is invisible. */
16370 else if (it_charpos
> PT
&& CHARPOS (startp
) <= PT
)
16371 w
->force_start
= true;
16373 if (w
->force_start
)
16375 if (window_frozen_p (w
))
16376 debug_method_add (w
, "set force_start from frozen window start");
16378 debug_method_add (w
, "set force_start from optional_new_start");
16386 /* Handle case where place to start displaying has been specified,
16387 unless the specified location is outside the accessible range. */
16388 if (w
->force_start
)
16390 /* We set this later on if we have to adjust point. */
16393 w
->force_start
= false;
16395 w
->window_end_valid
= false;
16397 /* Forget any recorded base line for line number display. */
16398 if (!buffer_unchanged_p
)
16399 w
->base_line_number
= 0;
16401 /* Redisplay the mode line. Select the buffer properly for that.
16402 Also, run the hook window-scroll-functions
16403 because we have scrolled. */
16404 /* Note, we do this after clearing force_start because
16405 if there's an error, it is better to forget about force_start
16406 than to get into an infinite loop calling the hook functions
16407 and having them get more errors. */
16408 if (!update_mode_line
16409 || ! NILP (Vwindow_scroll_functions
))
16411 update_mode_line
= true;
16412 w
->update_mode_line
= true;
16413 startp
= run_window_scroll_functions (window
, startp
);
16416 if (CHARPOS (startp
) < BEGV
)
16417 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
16418 else if (CHARPOS (startp
) > ZV
)
16419 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
16421 /* Redisplay, then check if cursor has been set during the
16422 redisplay. Give up if new fonts were loaded. */
16423 /* We used to issue a CHECK_MARGINS argument to try_window here,
16424 but this causes scrolling to fail when point begins inside
16425 the scroll margin (bug#148) -- cyd */
16426 if (!try_window (window
, startp
, 0))
16428 w
->force_start
= true;
16429 clear_glyph_matrix (w
->desired_matrix
);
16430 goto need_larger_matrices
;
16433 if (w
->cursor
.vpos
< 0)
16435 /* If point does not appear, try to move point so it does
16436 appear. The desired matrix has been built above, so we
16437 can use it here. First see if point is in invisible
16438 text, and if so, move it to the first visible buffer
16439 position past that. */
16440 struct glyph_row
*r
= NULL
;
16441 Lisp_Object invprop
=
16442 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16445 if (TEXT_PROP_MEANS_INVISIBLE (invprop
) != 0)
16448 Lisp_Object invprop_end
=
16449 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16452 if (NATNUMP (invprop_end
))
16453 alt_pt
= XFASTINT (invprop_end
);
16456 r
= row_containing_pos (w
, alt_pt
, w
->desired_matrix
->rows
,
16460 new_vpos
= MATRIX_ROW_BOTTOM_Y (r
);
16461 else /* Give up and just move to the middle of the window. */
16462 new_vpos
= window_box_height (w
) / 2;
16465 if (!cursor_row_fully_visible_p (w
, false, false))
16467 /* Point does appear, but on a line partly visible at end of window.
16468 Move it back to a fully-visible line. */
16469 new_vpos
= window_box_height (w
);
16470 /* But if window_box_height suggests a Y coordinate that is
16471 not less than we already have, that line will clearly not
16472 be fully visible, so give up and scroll the display.
16473 This can happen when the default face uses a font whose
16474 dimensions are different from the frame's default
16476 if (new_vpos
>= w
->cursor
.y
)
16478 w
->cursor
.vpos
= -1;
16479 clear_glyph_matrix (w
->desired_matrix
);
16480 goto try_to_scroll
;
16483 else if (w
->cursor
.vpos
>= 0)
16485 /* Some people insist on not letting point enter the scroll
16486 margin, even though this part handles windows that didn't
16488 int window_total_lines
16489 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16490 int margin
= min (scroll_margin
, window_total_lines
/ 4);
16491 int pixel_margin
= margin
* frame_line_height
;
16492 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
16494 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
16495 below, which finds the row to move point to, advances by
16496 the Y coordinate of the _next_ row, see the definition of
16497 MATRIX_ROW_BOTTOM_Y. */
16498 if (w
->cursor
.vpos
< margin
+ header_line
)
16500 w
->cursor
.vpos
= -1;
16501 clear_glyph_matrix (w
->desired_matrix
);
16502 goto try_to_scroll
;
16506 int window_height
= window_box_height (w
);
16509 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
16510 if (w
->cursor
.y
>= window_height
- pixel_margin
)
16512 w
->cursor
.vpos
= -1;
16513 clear_glyph_matrix (w
->desired_matrix
);
16514 goto try_to_scroll
;
16519 /* If we need to move point for either of the above reasons,
16520 now actually do it. */
16523 struct glyph_row
*row
;
16525 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
16526 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
16529 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
16530 MATRIX_ROW_START_BYTEPOS (row
));
16532 if (w
!= XWINDOW (selected_window
))
16533 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
16534 else if (current_buffer
== old
)
16535 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16537 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
16539 /* Re-run pre-redisplay-function so it can update the region
16540 according to the new position of point. */
16541 /* Other than the cursor, w's redisplay is done so we can set its
16542 redisplay to false. Also the buffer's redisplay can be set to
16543 false, since propagate_buffer_redisplay should have already
16544 propagated its info to `w' anyway. */
16545 w
->redisplay
= false;
16546 XBUFFER (w
->contents
)->text
->redisplay
= false;
16547 safe__call1 (true, Vpre_redisplay_function
, Fcons (window
, Qnil
));
16549 if (w
->redisplay
|| XBUFFER (w
->contents
)->text
->redisplay
)
16551 /* pre-redisplay-function made changes (e.g. move the region)
16552 that require another round of redisplay. */
16553 clear_glyph_matrix (w
->desired_matrix
);
16554 if (!try_window (window
, startp
, 0))
16555 goto need_larger_matrices
;
16558 if (w
->cursor
.vpos
< 0 || !cursor_row_fully_visible_p (w
, false, false))
16560 clear_glyph_matrix (w
->desired_matrix
);
16561 goto try_to_scroll
;
16565 debug_method_add (w
, "forced window start");
16570 /* Handle case where text has not changed, only point, and it has
16571 not moved off the frame, and we are not retrying after hscroll.
16572 (current_matrix_up_to_date_p is true when retrying.) */
16573 if (current_matrix_up_to_date_p
16574 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
16575 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
16579 case CURSOR_MOVEMENT_SUCCESS
:
16580 used_current_matrix_p
= true;
16583 case CURSOR_MOVEMENT_MUST_SCROLL
:
16584 goto try_to_scroll
;
16590 /* If current starting point was originally the beginning of a line
16591 but no longer is, find a new starting point. */
16592 else if (w
->start_at_line_beg
16593 && !(CHARPOS (startp
) <= BEGV
16594 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
16597 debug_method_add (w
, "recenter 1");
16602 /* Try scrolling with try_window_id. Value is > 0 if update has
16603 been done, it is -1 if we know that the same window start will
16604 not work. It is 0 if unsuccessful for some other reason. */
16605 else if ((tem
= try_window_id (w
)) != 0)
16608 debug_method_add (w
, "try_window_id %d", tem
);
16611 if (f
->fonts_changed
)
16612 goto need_larger_matrices
;
16616 /* Otherwise try_window_id has returned -1 which means that we
16617 don't want the alternative below this comment to execute. */
16619 else if (CHARPOS (startp
) >= BEGV
16620 && CHARPOS (startp
) <= ZV
16621 && PT
>= CHARPOS (startp
)
16622 && (CHARPOS (startp
) < ZV
16623 /* Avoid starting at end of buffer. */
16624 || CHARPOS (startp
) == BEGV
16625 || !window_outdated (w
)))
16627 int d1
, d2
, d5
, d6
;
16630 /* If first window line is a continuation line, and window start
16631 is inside the modified region, but the first change is before
16632 current window start, we must select a new window start.
16634 However, if this is the result of a down-mouse event (e.g. by
16635 extending the mouse-drag-overlay), we don't want to select a
16636 new window start, since that would change the position under
16637 the mouse, resulting in an unwanted mouse-movement rather
16638 than a simple mouse-click. */
16639 if (!w
->start_at_line_beg
16640 && NILP (do_mouse_tracking
)
16641 && CHARPOS (startp
) > BEGV
16642 && CHARPOS (startp
) > BEG
+ beg_unchanged
16643 && CHARPOS (startp
) <= Z
- end_unchanged
16644 /* Even if w->start_at_line_beg is nil, a new window may
16645 start at a line_beg, since that's how set_buffer_window
16646 sets it. So, we need to check the return value of
16647 compute_window_start_on_continuation_line. (See also
16649 && XMARKER (w
->start
)->buffer
== current_buffer
16650 && compute_window_start_on_continuation_line (w
)
16651 /* It doesn't make sense to force the window start like we
16652 do at label force_start if it is already known that point
16653 will not be fully visible in the resulting window, because
16654 doing so will move point from its correct position
16655 instead of scrolling the window to bring point into view.
16657 && pos_visible_p (w
, PT
, &d1
, &d2
, &rtop
, &rbot
, &d5
, &d6
)
16658 /* A very tall row could need more than the window height,
16659 in which case we accept that it is partially visible. */
16660 && (rtop
!= 0) == (rbot
!= 0))
16662 w
->force_start
= true;
16663 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16665 debug_method_add (w
, "recomputed window start in continuation line");
16671 debug_method_add (w
, "same window start");
16674 /* Try to redisplay starting at same place as before.
16675 If point has not moved off frame, accept the results. */
16676 if (!current_matrix_up_to_date_p
16677 /* Don't use try_window_reusing_current_matrix in this case
16678 because a window scroll function can have changed the
16680 || !NILP (Vwindow_scroll_functions
)
16681 || MINI_WINDOW_P (w
)
16682 || !(used_current_matrix_p
16683 = try_window_reusing_current_matrix (w
)))
16685 IF_DEBUG (debug_method_add (w
, "1"));
16686 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16687 /* -1 means we need to scroll.
16688 0 means we need new matrices, but fonts_changed
16689 is set in that case, so we will detect it below. */
16690 goto try_to_scroll
;
16693 if (f
->fonts_changed
)
16694 goto need_larger_matrices
;
16696 if (w
->cursor
.vpos
>= 0)
16698 if (!just_this_one_p
16699 || current_buffer
->clip_changed
16700 || BEG_UNCHANGED
< CHARPOS (startp
))
16701 /* Forget any recorded base line for line number display. */
16702 w
->base_line_number
= 0;
16704 if (!cursor_row_fully_visible_p (w
, true, false))
16706 clear_glyph_matrix (w
->desired_matrix
);
16707 last_line_misfit
= true;
16709 /* Drop through and scroll. */
16714 clear_glyph_matrix (w
->desired_matrix
);
16719 /* Redisplay the mode line. Select the buffer properly for that. */
16720 if (!update_mode_line
)
16722 update_mode_line
= true;
16723 w
->update_mode_line
= true;
16726 /* Try to scroll by specified few lines. */
16727 if ((scroll_conservatively
16728 || emacs_scroll_step
16729 || temp_scroll_step
16730 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16731 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16732 && CHARPOS (startp
) >= BEGV
16733 && CHARPOS (startp
) <= ZV
)
16735 /* The function returns -1 if new fonts were loaded, 1 if
16736 successful, 0 if not successful. */
16737 int ss
= try_scrolling (window
, just_this_one_p
,
16738 scroll_conservatively
,
16740 temp_scroll_step
, last_line_misfit
);
16743 case SCROLLING_SUCCESS
:
16746 case SCROLLING_NEED_LARGER_MATRICES
:
16747 goto need_larger_matrices
;
16749 case SCROLLING_FAILED
:
16757 /* Finally, just choose a place to start which positions point
16758 according to user preferences. */
16763 debug_method_add (w
, "recenter");
16766 /* Forget any previously recorded base line for line number display. */
16767 if (!buffer_unchanged_p
)
16768 w
->base_line_number
= 0;
16770 /* Determine the window start relative to point. */
16771 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16772 it
.current_y
= it
.last_visible_y
;
16773 if (centering_position
< 0)
16775 int window_total_lines
16776 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16778 = scroll_margin
> 0
16779 ? min (scroll_margin
, window_total_lines
/ 4)
16781 ptrdiff_t margin_pos
= CHARPOS (startp
);
16782 Lisp_Object aggressive
;
16785 /* If there is a scroll margin at the top of the window, find
16786 its character position. */
16788 /* Cannot call start_display if startp is not in the
16789 accessible region of the buffer. This can happen when we
16790 have just switched to a different buffer and/or changed
16791 its restriction. In that case, startp is initialized to
16792 the character position 1 (BEGV) because we did not yet
16793 have chance to display the buffer even once. */
16794 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16797 void *it1data
= NULL
;
16799 SAVE_IT (it1
, it
, it1data
);
16800 start_display (&it1
, w
, startp
);
16801 move_it_vertically (&it1
, margin
* frame_line_height
);
16802 margin_pos
= IT_CHARPOS (it1
);
16803 RESTORE_IT (&it
, &it
, it1data
);
16805 scrolling_up
= PT
> margin_pos
;
16808 ? BVAR (current_buffer
, scroll_up_aggressively
)
16809 : BVAR (current_buffer
, scroll_down_aggressively
);
16811 if (!MINI_WINDOW_P (w
)
16812 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16816 /* Setting scroll-conservatively overrides
16817 scroll-*-aggressively. */
16818 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16820 double float_amount
= XFLOATINT (aggressive
);
16822 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16823 if (pt_offset
== 0 && float_amount
> 0)
16825 if (pt_offset
&& margin
> 0)
16828 /* Compute how much to move the window start backward from
16829 point so that point will be displayed where the user
16833 centering_position
= it
.last_visible_y
;
16835 centering_position
-= pt_offset
;
16836 centering_position
-=
16837 (frame_line_height
* (1 + margin
+ last_line_misfit
)
16838 + WINDOW_HEADER_LINE_HEIGHT (w
));
16839 /* Don't let point enter the scroll margin near top of
16841 if (centering_position
< margin
* frame_line_height
)
16842 centering_position
= margin
* frame_line_height
;
16845 centering_position
= margin
* frame_line_height
+ pt_offset
;
16848 /* Set the window start half the height of the window backward
16850 centering_position
= window_box_height (w
) / 2;
16852 move_it_vertically_backward (&it
, centering_position
);
16854 eassert (IT_CHARPOS (it
) >= BEGV
);
16856 /* The function move_it_vertically_backward may move over more
16857 than the specified y-distance. If it->w is small, e.g. a
16858 mini-buffer window, we may end up in front of the window's
16859 display area. Start displaying at the start of the line
16860 containing PT in this case. */
16861 if (it
.current_y
<= 0)
16863 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16864 move_it_vertically_backward (&it
, 0);
16868 it
.current_x
= it
.hpos
= 0;
16870 /* Set the window start position here explicitly, to avoid an
16871 infinite loop in case the functions in window-scroll-functions
16873 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16875 /* Run scroll hooks. */
16876 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16878 /* Redisplay the window. */
16879 use_desired_matrix
= false;
16880 if (!current_matrix_up_to_date_p
16881 || windows_or_buffers_changed
16882 || f
->cursor_type_changed
16883 /* Don't use try_window_reusing_current_matrix in this case
16884 because it can have changed the buffer. */
16885 || !NILP (Vwindow_scroll_functions
)
16886 || !just_this_one_p
16887 || MINI_WINDOW_P (w
)
16888 || !(used_current_matrix_p
16889 = try_window_reusing_current_matrix (w
)))
16890 use_desired_matrix
= (try_window (window
, startp
, 0) == 1);
16892 /* If new fonts have been loaded (due to fontsets), give up. We
16893 have to start a new redisplay since we need to re-adjust glyph
16895 if (f
->fonts_changed
)
16896 goto need_larger_matrices
;
16898 /* If cursor did not appear assume that the middle of the window is
16899 in the first line of the window. Do it again with the next line.
16900 (Imagine a window of height 100, displaying two lines of height
16901 60. Moving back 50 from it->last_visible_y will end in the first
16903 if (w
->cursor
.vpos
< 0)
16905 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16907 clear_glyph_matrix (w
->desired_matrix
);
16908 move_it_by_lines (&it
, 1);
16909 try_window (window
, it
.current
.pos
, 0);
16911 else if (PT
< IT_CHARPOS (it
))
16913 clear_glyph_matrix (w
->desired_matrix
);
16914 move_it_by_lines (&it
, -1);
16915 try_window (window
, it
.current
.pos
, 0);
16919 /* Not much we can do about it. */
16923 /* Consider the following case: Window starts at BEGV, there is
16924 invisible, intangible text at BEGV, so that display starts at
16925 some point START > BEGV. It can happen that we are called with
16926 PT somewhere between BEGV and START. Try to handle that case,
16927 and similar ones. */
16928 if (w
->cursor
.vpos
< 0)
16930 /* Prefer the desired matrix to the current matrix, if possible,
16931 in the fallback calculations below. This is because using
16932 the current matrix might completely goof, e.g. if its first
16933 row is after point. */
16934 struct glyph_matrix
*matrix
=
16935 use_desired_matrix
? w
->desired_matrix
: w
->current_matrix
;
16936 /* First, try locating the proper glyph row for PT. */
16937 struct glyph_row
*row
=
16938 row_containing_pos (w
, PT
, matrix
->rows
, NULL
, 0);
16940 /* Sometimes point is at the beginning of invisible text that is
16941 before the 1st character displayed in the row. In that case,
16942 row_containing_pos fails to find the row, because no glyphs
16943 with appropriate buffer positions are present in the row.
16944 Therefore, we next try to find the row which shows the 1st
16945 position after the invisible text. */
16949 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16952 if (TEXT_PROP_MEANS_INVISIBLE (val
) != 0)
16955 Lisp_Object invis_end
=
16956 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16959 if (NATNUMP (invis_end
))
16960 alt_pos
= XFASTINT (invis_end
);
16963 row
= row_containing_pos (w
, alt_pos
, matrix
->rows
, NULL
, 0);
16966 /* Finally, fall back on the first row of the window after the
16967 header line (if any). This is slightly better than not
16968 displaying the cursor at all. */
16971 row
= matrix
->rows
;
16972 if (row
->mode_line_p
)
16975 set_cursor_from_row (w
, row
, matrix
, 0, 0, 0, 0);
16978 if (!cursor_row_fully_visible_p (w
, false, false))
16980 /* If vscroll is enabled, disable it and try again. */
16984 clear_glyph_matrix (w
->desired_matrix
);
16988 /* Users who set scroll-conservatively to a large number want
16989 point just above/below the scroll margin. If we ended up
16990 with point's row partially visible, move the window start to
16991 make that row fully visible and out of the margin. */
16992 if (scroll_conservatively
> SCROLL_LIMIT
)
16994 int window_total_lines
16995 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16998 ? min (scroll_margin
, window_total_lines
/ 4)
17000 bool move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
17002 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
17003 clear_glyph_matrix (w
->desired_matrix
);
17004 if (1 == try_window (window
, it
.current
.pos
,
17005 TRY_WINDOW_CHECK_MARGINS
))
17009 /* If centering point failed to make the whole line visible,
17010 put point at the top instead. That has to make the whole line
17011 visible, if it can be done. */
17012 if (centering_position
== 0)
17015 clear_glyph_matrix (w
->desired_matrix
);
17016 centering_position
= 0;
17022 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
17023 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
17024 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
17026 /* Display the mode line, if we must. */
17027 if ((update_mode_line
17028 /* If window not full width, must redo its mode line
17029 if (a) the window to its side is being redone and
17030 (b) we do a frame-based redisplay. This is a consequence
17031 of how inverted lines are drawn in frame-based redisplay. */
17032 || (!just_this_one_p
17033 && !FRAME_WINDOW_P (f
)
17034 && !WINDOW_FULL_WIDTH_P (w
))
17035 /* Line number to display. */
17036 || w
->base_line_pos
> 0
17037 /* Column number is displayed and different from the one displayed. */
17038 || (w
->column_number_displayed
!= -1
17039 && (w
->column_number_displayed
!= current_column ())))
17040 /* This means that the window has a mode line. */
17041 && (WINDOW_WANTS_MODELINE_P (w
)
17042 || WINDOW_WANTS_HEADER_LINE_P (w
)))
17045 display_mode_lines (w
);
17047 /* If mode line height has changed, arrange for a thorough
17048 immediate redisplay using the correct mode line height. */
17049 if (WINDOW_WANTS_MODELINE_P (w
)
17050 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
17052 f
->fonts_changed
= true;
17053 w
->mode_line_height
= -1;
17054 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
17055 = DESIRED_MODE_LINE_HEIGHT (w
);
17058 /* If header line height has changed, arrange for a thorough
17059 immediate redisplay using the correct header line height. */
17060 if (WINDOW_WANTS_HEADER_LINE_P (w
)
17061 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
17063 f
->fonts_changed
= true;
17064 w
->header_line_height
= -1;
17065 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
17066 = DESIRED_HEADER_LINE_HEIGHT (w
);
17069 if (f
->fonts_changed
)
17070 goto need_larger_matrices
;
17073 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
17075 w
->base_line_pos
= 0;
17076 w
->base_line_number
= 0;
17081 /* When we reach a frame's selected window, redo the frame's menu
17082 bar and the frame's title. */
17083 if (update_mode_line
17084 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
17086 bool redisplay_menu_p
;
17088 if (FRAME_WINDOW_P (f
))
17090 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
17091 || defined (HAVE_NS) || defined (USE_GTK)
17092 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
17094 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
17098 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
17100 if (redisplay_menu_p
)
17101 display_menu_bar (w
);
17103 #ifdef HAVE_WINDOW_SYSTEM
17104 if (FRAME_WINDOW_P (f
))
17106 #if defined (USE_GTK) || defined (HAVE_NS)
17107 if (FRAME_EXTERNAL_TOOL_BAR (f
))
17108 redisplay_tool_bar (f
);
17110 if (WINDOWP (f
->tool_bar_window
)
17111 && (FRAME_TOOL_BAR_LINES (f
) > 0
17112 || !NILP (Vauto_resize_tool_bars
))
17113 && redisplay_tool_bar (f
))
17114 ignore_mouse_drag_p
= true;
17117 ptrdiff_t count1
= SPECPDL_INDEX ();
17118 /* x_consider_frame_title calls select-frame, which calls
17119 resize_mini_window, which could resize the mini-window and by
17120 that undo the effect of this redisplay cycle wrt minibuffer
17121 and echo-area display. Binding inhibit-redisplay to t makes
17122 the call to resize_mini_window a no-op, thus avoiding the
17123 adverse side effects. */
17124 specbind (Qinhibit_redisplay
, Qt
);
17125 x_consider_frame_title (w
->frame
);
17126 unbind_to (count1
, Qnil
);
17130 #ifdef HAVE_WINDOW_SYSTEM
17131 if (FRAME_WINDOW_P (f
)
17132 && update_window_fringes (w
, (just_this_one_p
17133 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
17134 || w
->pseudo_window_p
)))
17138 if (draw_window_fringes (w
, true))
17140 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
17141 x_draw_right_divider (w
);
17143 x_draw_vertical_border (w
);
17149 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
17150 x_draw_bottom_divider (w
);
17151 #endif /* HAVE_WINDOW_SYSTEM */
17153 /* We go to this label, with fonts_changed set, if it is
17154 necessary to try again using larger glyph matrices.
17155 We have to redeem the scroll bar even in this case,
17156 because the loop in redisplay_internal expects that. */
17157 need_larger_matrices
:
17159 finish_scroll_bars
:
17161 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
) || WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
17163 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
17164 /* Set the thumb's position and size. */
17165 set_vertical_scroll_bar (w
);
17167 if (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
17168 /* Set the thumb's position and size. */
17169 set_horizontal_scroll_bar (w
);
17171 /* Note that we actually used the scroll bar attached to this
17172 window, so it shouldn't be deleted at the end of redisplay. */
17173 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
17174 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
17177 /* Restore current_buffer and value of point in it. The window
17178 update may have changed the buffer, so first make sure `opoint'
17179 is still valid (Bug#6177). */
17180 if (CHARPOS (opoint
) < BEGV
)
17181 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17182 else if (CHARPOS (opoint
) > ZV
)
17183 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
17185 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
17187 set_buffer_internal_1 (old
);
17188 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
17189 shorter. This can be caused by log truncation in *Messages*. */
17190 if (CHARPOS (lpoint
) <= ZV
)
17191 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17193 unbind_to (count
, Qnil
);
17197 /* Build the complete desired matrix of WINDOW with a window start
17198 buffer position POS.
17200 Value is 1 if successful. It is zero if fonts were loaded during
17201 redisplay which makes re-adjusting glyph matrices necessary, and -1
17202 if point would appear in the scroll margins.
17203 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
17204 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
17208 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
17210 struct window
*w
= XWINDOW (window
);
17212 struct glyph_row
*last_text_row
= NULL
;
17213 struct frame
*f
= XFRAME (w
->frame
);
17214 int frame_line_height
= default_line_pixel_height (w
);
17216 /* Make POS the new window start. */
17217 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
17219 /* Mark cursor position as unknown. No overlay arrow seen. */
17220 w
->cursor
.vpos
= -1;
17221 overlay_arrow_seen
= false;
17223 /* Initialize iterator and info to start at POS. */
17224 start_display (&it
, w
, pos
);
17225 it
.glyph_row
->reversed_p
= false;
17227 /* Display all lines of W. */
17228 while (it
.current_y
< it
.last_visible_y
)
17230 if (display_line (&it
))
17231 last_text_row
= it
.glyph_row
- 1;
17232 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
17236 /* Don't let the cursor end in the scroll margins. */
17237 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
17238 && !MINI_WINDOW_P (w
))
17240 int this_scroll_margin
;
17241 int window_total_lines
17242 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
17244 if (scroll_margin
> 0)
17246 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
17247 this_scroll_margin
*= frame_line_height
;
17250 this_scroll_margin
= 0;
17252 if ((w
->cursor
.y
>= 0 /* not vscrolled */
17253 && w
->cursor
.y
< this_scroll_margin
17254 && CHARPOS (pos
) > BEGV
17255 && IT_CHARPOS (it
) < ZV
)
17256 /* rms: considering make_cursor_line_fully_visible_p here
17257 seems to give wrong results. We don't want to recenter
17258 when the last line is partly visible, we want to allow
17259 that case to be handled in the usual way. */
17260 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
17262 w
->cursor
.vpos
= -1;
17263 clear_glyph_matrix (w
->desired_matrix
);
17268 /* If bottom moved off end of frame, change mode line percentage. */
17269 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
17270 w
->update_mode_line
= true;
17272 /* Set window_end_pos to the offset of the last character displayed
17273 on the window from the end of current_buffer. Set
17274 window_end_vpos to its row number. */
17277 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
17278 adjust_window_ends (w
, last_text_row
, false);
17280 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
17281 w
->window_end_vpos
)));
17285 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17286 w
->window_end_pos
= Z
- ZV
;
17287 w
->window_end_vpos
= 0;
17290 /* But that is not valid info until redisplay finishes. */
17291 w
->window_end_valid
= false;
17297 /************************************************************************
17298 Window redisplay reusing current matrix when buffer has not changed
17299 ************************************************************************/
17301 /* Try redisplay of window W showing an unchanged buffer with a
17302 different window start than the last time it was displayed by
17303 reusing its current matrix. Value is true if successful.
17304 W->start is the new window start. */
17307 try_window_reusing_current_matrix (struct window
*w
)
17309 struct frame
*f
= XFRAME (w
->frame
);
17310 struct glyph_row
*bottom_row
;
17313 struct text_pos start
, new_start
;
17314 int nrows_scrolled
, i
;
17315 struct glyph_row
*last_text_row
;
17316 struct glyph_row
*last_reused_text_row
;
17317 struct glyph_row
*start_row
;
17318 int start_vpos
, min_y
, max_y
;
17321 if (inhibit_try_window_reusing
)
17325 if (/* This function doesn't handle terminal frames. */
17326 !FRAME_WINDOW_P (f
)
17327 /* Don't try to reuse the display if windows have been split
17329 || windows_or_buffers_changed
17330 || f
->cursor_type_changed
)
17333 /* Can't do this if showing trailing whitespace. */
17334 if (!NILP (Vshow_trailing_whitespace
))
17337 /* If top-line visibility has changed, give up. */
17338 if (WINDOW_WANTS_HEADER_LINE_P (w
)
17339 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
17342 /* Give up if old or new display is scrolled vertically. We could
17343 make this function handle this, but right now it doesn't. */
17344 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17345 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
17348 /* The variable new_start now holds the new window start. The old
17349 start `start' can be determined from the current matrix. */
17350 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
17351 start
= start_row
->minpos
;
17352 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17354 /* Clear the desired matrix for the display below. */
17355 clear_glyph_matrix (w
->desired_matrix
);
17357 if (CHARPOS (new_start
) <= CHARPOS (start
))
17359 /* Don't use this method if the display starts with an ellipsis
17360 displayed for invisible text. It's not easy to handle that case
17361 below, and it's certainly not worth the effort since this is
17362 not a frequent case. */
17363 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
17366 IF_DEBUG (debug_method_add (w
, "twu1"));
17368 /* Display up to a row that can be reused. The variable
17369 last_text_row is set to the last row displayed that displays
17370 text. Note that it.vpos == 0 if or if not there is a
17371 header-line; it's not the same as the MATRIX_ROW_VPOS! */
17372 start_display (&it
, w
, new_start
);
17373 w
->cursor
.vpos
= -1;
17374 last_text_row
= last_reused_text_row
= NULL
;
17376 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17378 /* If we have reached into the characters in the START row,
17379 that means the line boundaries have changed. So we
17380 can't start copying with the row START. Maybe it will
17381 work to start copying with the following row. */
17382 while (IT_CHARPOS (it
) > CHARPOS (start
))
17384 /* Advance to the next row as the "start". */
17386 start
= start_row
->minpos
;
17387 /* If there are no more rows to try, or just one, give up. */
17388 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
17389 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
17390 || CHARPOS (start
) == ZV
)
17392 clear_glyph_matrix (w
->desired_matrix
);
17396 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17398 /* If we have reached alignment, we can copy the rest of the
17400 if (IT_CHARPOS (it
) == CHARPOS (start
)
17401 /* Don't accept "alignment" inside a display vector,
17402 since start_row could have started in the middle of
17403 that same display vector (thus their character
17404 positions match), and we have no way of telling if
17405 that is the case. */
17406 && it
.current
.dpvec_index
< 0)
17409 it
.glyph_row
->reversed_p
= false;
17410 if (display_line (&it
))
17411 last_text_row
= it
.glyph_row
- 1;
17415 /* A value of current_y < last_visible_y means that we stopped
17416 at the previous window start, which in turn means that we
17417 have at least one reusable row. */
17418 if (it
.current_y
< it
.last_visible_y
)
17420 struct glyph_row
*row
;
17422 /* IT.vpos always starts from 0; it counts text lines. */
17423 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
17425 /* Find PT if not already found in the lines displayed. */
17426 if (w
->cursor
.vpos
< 0)
17428 int dy
= it
.current_y
- start_row
->y
;
17430 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17431 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
17433 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
17434 dy
, nrows_scrolled
);
17437 clear_glyph_matrix (w
->desired_matrix
);
17442 /* Scroll the display. Do it before the current matrix is
17443 changed. The problem here is that update has not yet
17444 run, i.e. part of the current matrix is not up to date.
17445 scroll_run_hook will clear the cursor, and use the
17446 current matrix to get the height of the row the cursor is
17448 run
.current_y
= start_row
->y
;
17449 run
.desired_y
= it
.current_y
;
17450 run
.height
= it
.last_visible_y
- it
.current_y
;
17452 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
17455 FRAME_RIF (f
)->update_window_begin_hook (w
);
17456 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17457 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17458 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17462 /* Shift current matrix down by nrows_scrolled lines. */
17463 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17464 rotate_matrix (w
->current_matrix
,
17466 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17469 /* Disable lines that must be updated. */
17470 for (i
= 0; i
< nrows_scrolled
; ++i
)
17471 (start_row
+ i
)->enabled_p
= false;
17473 /* Re-compute Y positions. */
17474 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17475 max_y
= it
.last_visible_y
;
17476 for (row
= start_row
+ nrows_scrolled
;
17480 row
->y
= it
.current_y
;
17481 row
->visible_height
= row
->height
;
17483 if (row
->y
< min_y
)
17484 row
->visible_height
-= min_y
- row
->y
;
17485 if (row
->y
+ row
->height
> max_y
)
17486 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17487 if (row
->fringe_bitmap_periodic_p
)
17488 row
->redraw_fringe_bitmaps_p
= true;
17490 it
.current_y
+= row
->height
;
17492 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17493 last_reused_text_row
= row
;
17494 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
17498 /* Disable lines in the current matrix which are now
17499 below the window. */
17500 for (++row
; row
< bottom_row
; ++row
)
17501 row
->enabled_p
= row
->mode_line_p
= false;
17504 /* Update window_end_pos etc.; last_reused_text_row is the last
17505 reused row from the current matrix containing text, if any.
17506 The value of last_text_row is the last displayed line
17507 containing text. */
17508 if (last_reused_text_row
)
17509 adjust_window_ends (w
, last_reused_text_row
, true);
17510 else if (last_text_row
)
17511 adjust_window_ends (w
, last_text_row
, false);
17514 /* This window must be completely empty. */
17515 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17516 w
->window_end_pos
= Z
- ZV
;
17517 w
->window_end_vpos
= 0;
17519 w
->window_end_valid
= false;
17521 /* Update hint: don't try scrolling again in update_window. */
17522 w
->desired_matrix
->no_scrolling_p
= true;
17525 debug_method_add (w
, "try_window_reusing_current_matrix 1");
17529 else if (CHARPOS (new_start
) > CHARPOS (start
))
17531 struct glyph_row
*pt_row
, *row
;
17532 struct glyph_row
*first_reusable_row
;
17533 struct glyph_row
*first_row_to_display
;
17535 int yb
= window_text_bottom_y (w
);
17537 /* Find the row starting at new_start, if there is one. Don't
17538 reuse a partially visible line at the end. */
17539 first_reusable_row
= start_row
;
17540 while (first_reusable_row
->enabled_p
17541 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
17542 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17543 < CHARPOS (new_start
)))
17544 ++first_reusable_row
;
17546 /* Give up if there is no row to reuse. */
17547 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
17548 || !first_reusable_row
->enabled_p
17549 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17550 != CHARPOS (new_start
)))
17553 /* We can reuse fully visible rows beginning with
17554 first_reusable_row to the end of the window. Set
17555 first_row_to_display to the first row that cannot be reused.
17556 Set pt_row to the row containing point, if there is any. */
17558 for (first_row_to_display
= first_reusable_row
;
17559 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
17560 ++first_row_to_display
)
17562 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
17563 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17564 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17565 && first_row_to_display
->ends_at_zv_p
17566 && pt_row
== NULL
)))
17567 pt_row
= first_row_to_display
;
17570 /* Start displaying at the start of first_row_to_display. */
17571 eassert (first_row_to_display
->y
< yb
);
17572 init_to_row_start (&it
, w
, first_row_to_display
);
17574 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
17576 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
17578 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
17579 + WINDOW_HEADER_LINE_HEIGHT (w
));
17581 /* Display lines beginning with first_row_to_display in the
17582 desired matrix. Set last_text_row to the last row displayed
17583 that displays text. */
17584 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
17585 if (pt_row
== NULL
)
17586 w
->cursor
.vpos
= -1;
17587 last_text_row
= NULL
;
17588 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17589 if (display_line (&it
))
17590 last_text_row
= it
.glyph_row
- 1;
17592 /* If point is in a reused row, adjust y and vpos of the cursor
17596 w
->cursor
.vpos
-= nrows_scrolled
;
17597 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
17600 /* Give up if point isn't in a row displayed or reused. (This
17601 also handles the case where w->cursor.vpos < nrows_scrolled
17602 after the calls to display_line, which can happen with scroll
17603 margins. See bug#1295.) */
17604 if (w
->cursor
.vpos
< 0)
17606 clear_glyph_matrix (w
->desired_matrix
);
17610 /* Scroll the display. */
17611 run
.current_y
= first_reusable_row
->y
;
17612 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17613 run
.height
= it
.last_visible_y
- run
.current_y
;
17614 dy
= run
.current_y
- run
.desired_y
;
17619 FRAME_RIF (f
)->update_window_begin_hook (w
);
17620 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17621 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17622 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17626 /* Adjust Y positions of reused rows. */
17627 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17628 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17629 max_y
= it
.last_visible_y
;
17630 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
17633 row
->visible_height
= row
->height
;
17634 if (row
->y
< min_y
)
17635 row
->visible_height
-= min_y
- row
->y
;
17636 if (row
->y
+ row
->height
> max_y
)
17637 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17638 if (row
->fringe_bitmap_periodic_p
)
17639 row
->redraw_fringe_bitmaps_p
= true;
17642 /* Scroll the current matrix. */
17643 eassert (nrows_scrolled
> 0);
17644 rotate_matrix (w
->current_matrix
,
17646 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17649 /* Disable rows not reused. */
17650 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
17651 row
->enabled_p
= false;
17653 /* Point may have moved to a different line, so we cannot assume that
17654 the previous cursor position is valid; locate the correct row. */
17657 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
17659 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
17660 && !row
->ends_at_zv_p
;
17664 w
->cursor
.y
= row
->y
;
17666 if (row
< bottom_row
)
17668 /* Can't simply scan the row for point with
17669 bidi-reordered glyph rows. Let set_cursor_from_row
17670 figure out where to put the cursor, and if it fails,
17672 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
17674 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
17677 clear_glyph_matrix (w
->desired_matrix
);
17683 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
17684 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17687 && (!BUFFERP (glyph
->object
)
17688 || glyph
->charpos
< PT
);
17692 w
->cursor
.x
+= glyph
->pixel_width
;
17698 /* Adjust window end. A null value of last_text_row means that
17699 the window end is in reused rows which in turn means that
17700 only its vpos can have changed. */
17702 adjust_window_ends (w
, last_text_row
, false);
17704 w
->window_end_vpos
-= nrows_scrolled
;
17706 w
->window_end_valid
= false;
17707 w
->desired_matrix
->no_scrolling_p
= true;
17710 debug_method_add (w
, "try_window_reusing_current_matrix 2");
17720 /************************************************************************
17721 Window redisplay reusing current matrix when buffer has changed
17722 ************************************************************************/
17724 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
17725 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17726 ptrdiff_t *, ptrdiff_t *);
17727 static struct glyph_row
*
17728 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17729 struct glyph_row
*);
17732 /* Return the last row in MATRIX displaying text. If row START is
17733 non-null, start searching with that row. IT gives the dimensions
17734 of the display. Value is null if matrix is empty; otherwise it is
17735 a pointer to the row found. */
17737 static struct glyph_row
*
17738 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17739 struct glyph_row
*start
)
17741 struct glyph_row
*row
, *row_found
;
17743 /* Set row_found to the last row in IT->w's current matrix
17744 displaying text. The loop looks funny but think of partially
17747 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17748 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17750 eassert (row
->enabled_p
);
17752 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17761 /* Return the last row in the current matrix of W that is not affected
17762 by changes at the start of current_buffer that occurred since W's
17763 current matrix was built. Value is null if no such row exists.
17765 BEG_UNCHANGED us the number of characters unchanged at the start of
17766 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17767 first changed character in current_buffer. Characters at positions <
17768 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17769 when the current matrix was built. */
17771 static struct glyph_row
*
17772 find_last_unchanged_at_beg_row (struct window
*w
)
17774 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17775 struct glyph_row
*row
;
17776 struct glyph_row
*row_found
= NULL
;
17777 int yb
= window_text_bottom_y (w
);
17779 /* Find the last row displaying unchanged text. */
17780 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17781 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17782 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17785 if (/* If row ends before first_changed_pos, it is unchanged,
17786 except in some case. */
17787 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17788 /* When row ends in ZV and we write at ZV it is not
17790 && !row
->ends_at_zv_p
17791 /* When first_changed_pos is the end of a continued line,
17792 row is not unchanged because it may be no longer
17794 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17795 && (row
->continued_p
17796 || row
->exact_window_width_line_p
))
17797 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17798 needs to be recomputed, so don't consider this row as
17799 unchanged. This happens when the last line was
17800 bidi-reordered and was killed immediately before this
17801 redisplay cycle. In that case, ROW->end stores the
17802 buffer position of the first visual-order character of
17803 the killed text, which is now beyond ZV. */
17804 && CHARPOS (row
->end
.pos
) <= ZV
)
17807 /* Stop if last visible row. */
17808 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17816 /* Find the first glyph row in the current matrix of W that is not
17817 affected by changes at the end of current_buffer since the
17818 time W's current matrix was built.
17820 Return in *DELTA the number of chars by which buffer positions in
17821 unchanged text at the end of current_buffer must be adjusted.
17823 Return in *DELTA_BYTES the corresponding number of bytes.
17825 Value is null if no such row exists, i.e. all rows are affected by
17828 static struct glyph_row
*
17829 find_first_unchanged_at_end_row (struct window
*w
,
17830 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17832 struct glyph_row
*row
;
17833 struct glyph_row
*row_found
= NULL
;
17835 *delta
= *delta_bytes
= 0;
17837 /* Display must not have been paused, otherwise the current matrix
17838 is not up to date. */
17839 eassert (w
->window_end_valid
);
17841 /* A value of window_end_pos >= END_UNCHANGED means that the window
17842 end is in the range of changed text. If so, there is no
17843 unchanged row at the end of W's current matrix. */
17844 if (w
->window_end_pos
>= END_UNCHANGED
)
17847 /* Set row to the last row in W's current matrix displaying text. */
17848 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17850 /* If matrix is entirely empty, no unchanged row exists. */
17851 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17853 /* The value of row is the last glyph row in the matrix having a
17854 meaningful buffer position in it. The end position of row
17855 corresponds to window_end_pos. This allows us to translate
17856 buffer positions in the current matrix to current buffer
17857 positions for characters not in changed text. */
17859 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17860 ptrdiff_t Z_BYTE_old
=
17861 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17862 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17863 struct glyph_row
*first_text_row
17864 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17866 *delta
= Z
- Z_old
;
17867 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17869 /* Set last_unchanged_pos to the buffer position of the last
17870 character in the buffer that has not been changed. Z is the
17871 index + 1 of the last character in current_buffer, i.e. by
17872 subtracting END_UNCHANGED we get the index of the last
17873 unchanged character, and we have to add BEG to get its buffer
17875 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17876 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17878 /* Search backward from ROW for a row displaying a line that
17879 starts at a minimum position >= last_unchanged_pos_old. */
17880 for (; row
> first_text_row
; --row
)
17882 /* This used to abort, but it can happen.
17883 It is ok to just stop the search instead here. KFS. */
17884 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17887 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17892 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17898 /* Make sure that glyph rows in the current matrix of window W
17899 reference the same glyph memory as corresponding rows in the
17900 frame's frame matrix. This function is called after scrolling W's
17901 current matrix on a terminal frame in try_window_id and
17902 try_window_reusing_current_matrix. */
17905 sync_frame_with_window_matrix_rows (struct window
*w
)
17907 struct frame
*f
= XFRAME (w
->frame
);
17908 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17910 /* Preconditions: W must be a leaf window and full-width. Its frame
17911 must have a frame matrix. */
17912 eassert (BUFFERP (w
->contents
));
17913 eassert (WINDOW_FULL_WIDTH_P (w
));
17914 eassert (!FRAME_WINDOW_P (f
));
17916 /* If W is a full-width window, glyph pointers in W's current matrix
17917 have, by definition, to be the same as glyph pointers in the
17918 corresponding frame matrix. Note that frame matrices have no
17919 marginal areas (see build_frame_matrix). */
17920 window_row
= w
->current_matrix
->rows
;
17921 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17922 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17923 while (window_row
< window_row_end
)
17925 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17926 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17928 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17929 frame_row
->glyphs
[TEXT_AREA
] = start
;
17930 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17931 frame_row
->glyphs
[LAST_AREA
] = end
;
17933 /* Disable frame rows whose corresponding window rows have
17934 been disabled in try_window_id. */
17935 if (!window_row
->enabled_p
)
17936 frame_row
->enabled_p
= false;
17938 ++window_row
, ++frame_row
;
17943 /* Find the glyph row in window W containing CHARPOS. Consider all
17944 rows between START and END (not inclusive). END null means search
17945 all rows to the end of the display area of W. Value is the row
17946 containing CHARPOS or null. */
17949 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17950 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17952 struct glyph_row
*row
= start
;
17953 struct glyph_row
*best_row
= NULL
;
17954 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17957 /* If we happen to start on a header-line, skip that. */
17958 if (row
->mode_line_p
)
17961 if ((end
&& row
>= end
) || !row
->enabled_p
)
17964 last_y
= window_text_bottom_y (w
) - dy
;
17968 /* Give up if we have gone too far. */
17969 if ((end
&& row
>= end
) || !row
->enabled_p
)
17971 /* This formerly returned if they were equal.
17972 I think that both quantities are of a "last plus one" type;
17973 if so, when they are equal, the row is within the screen. -- rms. */
17974 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17977 /* If it is in this row, return this row. */
17978 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17979 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17980 /* The end position of a row equals the start
17981 position of the next row. If CHARPOS is there, we
17982 would rather consider it displayed in the next
17983 line, except when this line ends in ZV. */
17984 && !row_for_charpos_p (row
, charpos
)))
17985 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17989 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17990 || (!best_row
&& !row
->continued_p
))
17992 /* In bidi-reordered rows, there could be several rows whose
17993 edges surround CHARPOS, all of these rows belonging to
17994 the same continued line. We need to find the row which
17995 fits CHARPOS the best. */
17996 for (g
= row
->glyphs
[TEXT_AREA
];
17997 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
18000 if (!STRINGP (g
->object
))
18002 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
18004 mindif
= eabs (g
->charpos
- charpos
);
18006 /* Exact match always wins. */
18013 else if (best_row
&& !row
->continued_p
)
18020 /* Try to redisplay window W by reusing its existing display. W's
18021 current matrix must be up to date when this function is called,
18022 i.e., window_end_valid must be true.
18026 >= 1 if successful, i.e. display has been updated
18028 1 means the changes were in front of a newline that precedes
18029 the window start, and the whole current matrix was reused
18030 2 means the changes were after the last position displayed
18031 in the window, and the whole current matrix was reused
18032 3 means portions of the current matrix were reused, while
18033 some of the screen lines were redrawn
18034 -1 if redisplay with same window start is known not to succeed
18035 0 if otherwise unsuccessful
18037 The following steps are performed:
18039 1. Find the last row in the current matrix of W that is not
18040 affected by changes at the start of current_buffer. If no such row
18043 2. Find the first row in W's current matrix that is not affected by
18044 changes at the end of current_buffer. Maybe there is no such row.
18046 3. Display lines beginning with the row + 1 found in step 1 to the
18047 row found in step 2 or, if step 2 didn't find a row, to the end of
18050 4. If cursor is not known to appear on the window, give up.
18052 5. If display stopped at the row found in step 2, scroll the
18053 display and current matrix as needed.
18055 6. Maybe display some lines at the end of W, if we must. This can
18056 happen under various circumstances, like a partially visible line
18057 becoming fully visible, or because newly displayed lines are displayed
18058 in smaller font sizes.
18060 7. Update W's window end information. */
18063 try_window_id (struct window
*w
)
18065 struct frame
*f
= XFRAME (w
->frame
);
18066 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
18067 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
18068 struct glyph_row
*last_unchanged_at_beg_row
;
18069 struct glyph_row
*first_unchanged_at_end_row
;
18070 struct glyph_row
*row
;
18071 struct glyph_row
*bottom_row
;
18074 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
18076 struct text_pos start_pos
;
18078 int first_unchanged_at_end_vpos
= 0;
18079 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
18080 struct text_pos start
;
18081 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
18084 if (inhibit_try_window_id
)
18088 /* This is handy for debugging. */
18090 #define GIVE_UP(X) \
18092 TRACE ((stderr, "try_window_id give up %d\n", (X))); \
18096 #define GIVE_UP(X) return 0
18099 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
18101 /* Don't use this for mini-windows because these can show
18102 messages and mini-buffers, and we don't handle that here. */
18103 if (MINI_WINDOW_P (w
))
18106 /* This flag is used to prevent redisplay optimizations. */
18107 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
18110 /* This function's optimizations cannot be used if overlays have
18111 changed in the buffer displayed by the window, so give up if they
18113 if (w
->last_overlay_modified
!= OVERLAY_MODIFF
)
18116 /* Verify that narrowing has not changed.
18117 Also verify that we were not told to prevent redisplay optimizations.
18118 It would be nice to further
18119 reduce the number of cases where this prevents try_window_id. */
18120 if (current_buffer
->clip_changed
18121 || current_buffer
->prevent_redisplay_optimizations_p
)
18124 /* Window must either use window-based redisplay or be full width. */
18125 if (!FRAME_WINDOW_P (f
)
18126 && (!FRAME_LINE_INS_DEL_OK (f
)
18127 || !WINDOW_FULL_WIDTH_P (w
)))
18130 /* Give up if point is known NOT to appear in W. */
18131 if (PT
< CHARPOS (start
))
18134 /* Another way to prevent redisplay optimizations. */
18135 if (w
->last_modified
== 0)
18138 /* Verify that window is not hscrolled. */
18139 if (w
->hscroll
!= 0)
18142 /* Verify that display wasn't paused. */
18143 if (!w
->window_end_valid
)
18146 /* Likewise if highlighting trailing whitespace. */
18147 if (!NILP (Vshow_trailing_whitespace
))
18150 /* Can't use this if overlay arrow position and/or string have
18152 if (overlay_arrows_changed_p ())
18155 /* When word-wrap is on, adding a space to the first word of a
18156 wrapped line can change the wrap position, altering the line
18157 above it. It might be worthwhile to handle this more
18158 intelligently, but for now just redisplay from scratch. */
18159 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
18162 /* Under bidi reordering, adding or deleting a character in the
18163 beginning of a paragraph, before the first strong directional
18164 character, can change the base direction of the paragraph (unless
18165 the buffer specifies a fixed paragraph direction), which will
18166 require redisplaying the whole paragraph. It might be worthwhile
18167 to find the paragraph limits and widen the range of redisplayed
18168 lines to that, but for now just give up this optimization and
18169 redisplay from scratch. */
18170 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
18171 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
18174 /* Give up if the buffer has line-spacing set, as Lisp-level changes
18175 to that variable require thorough redisplay. */
18176 if (!NILP (BVAR (XBUFFER (w
->contents
), extra_line_spacing
)))
18179 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
18180 only if buffer has really changed. The reason is that the gap is
18181 initially at Z for freshly visited files. The code below would
18182 set end_unchanged to 0 in that case. */
18183 if (MODIFF
> SAVE_MODIFF
18184 /* This seems to happen sometimes after saving a buffer. */
18185 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
18187 if (GPT
- BEG
< BEG_UNCHANGED
)
18188 BEG_UNCHANGED
= GPT
- BEG
;
18189 if (Z
- GPT
< END_UNCHANGED
)
18190 END_UNCHANGED
= Z
- GPT
;
18193 /* The position of the first and last character that has been changed. */
18194 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
18195 last_changed_charpos
= Z
- END_UNCHANGED
;
18197 /* If window starts after a line end, and the last change is in
18198 front of that newline, then changes don't affect the display.
18199 This case happens with stealth-fontification. Note that although
18200 the display is unchanged, glyph positions in the matrix have to
18201 be adjusted, of course. */
18202 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
18203 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
18204 && ((last_changed_charpos
< CHARPOS (start
)
18205 && CHARPOS (start
) == BEGV
)
18206 || (last_changed_charpos
< CHARPOS (start
) - 1
18207 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
18209 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
18210 struct glyph_row
*r0
;
18212 /* Compute how many chars/bytes have been added to or removed
18213 from the buffer. */
18214 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
18215 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
18216 Z_delta
= Z
- Z_old
;
18217 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
18219 /* Give up if PT is not in the window. Note that it already has
18220 been checked at the start of try_window_id that PT is not in
18221 front of the window start. */
18222 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
18225 /* If window start is unchanged, we can reuse the whole matrix
18226 as is, after adjusting glyph positions. No need to compute
18227 the window end again, since its offset from Z hasn't changed. */
18228 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18229 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
18230 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
18231 /* PT must not be in a partially visible line. */
18232 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
18233 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
18235 /* Adjust positions in the glyph matrix. */
18236 if (Z_delta
|| Z_delta_bytes
)
18238 struct glyph_row
*r1
18239 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18240 increment_matrix_positions (w
->current_matrix
,
18241 MATRIX_ROW_VPOS (r0
, current_matrix
),
18242 MATRIX_ROW_VPOS (r1
, current_matrix
),
18243 Z_delta
, Z_delta_bytes
);
18246 /* Set the cursor. */
18247 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
18249 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
18254 /* Handle the case that changes are all below what is displayed in
18255 the window, and that PT is in the window. This shortcut cannot
18256 be taken if ZV is visible in the window, and text has been added
18257 there that is visible in the window. */
18258 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
18259 /* ZV is not visible in the window, or there are no
18260 changes at ZV, actually. */
18261 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
18262 || first_changed_charpos
== last_changed_charpos
))
18264 struct glyph_row
*r0
;
18266 /* Give up if PT is not in the window. Note that it already has
18267 been checked at the start of try_window_id that PT is not in
18268 front of the window start. */
18269 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
18272 /* If window start is unchanged, we can reuse the whole matrix
18273 as is, without changing glyph positions since no text has
18274 been added/removed in front of the window end. */
18275 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18276 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
18277 /* PT must not be in a partially visible line. */
18278 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
18279 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
18281 /* We have to compute the window end anew since text
18282 could have been added/removed after it. */
18283 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18284 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18286 /* Set the cursor. */
18287 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
18289 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
18294 /* Give up if window start is in the changed area.
18296 The condition used to read
18298 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
18300 but why that was tested escapes me at the moment. */
18301 if (CHARPOS (start
) >= first_changed_charpos
18302 && CHARPOS (start
) <= last_changed_charpos
)
18305 /* Check that window start agrees with the start of the first glyph
18306 row in its current matrix. Check this after we know the window
18307 start is not in changed text, otherwise positions would not be
18309 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18310 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
18313 /* Give up if the window ends in strings. Overlay strings
18314 at the end are difficult to handle, so don't try. */
18315 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
18316 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
18319 /* Compute the position at which we have to start displaying new
18320 lines. Some of the lines at the top of the window might be
18321 reusable because they are not displaying changed text. Find the
18322 last row in W's current matrix not affected by changes at the
18323 start of current_buffer. Value is null if changes start in the
18324 first line of window. */
18325 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
18326 if (last_unchanged_at_beg_row
)
18328 /* Avoid starting to display in the middle of a character, a TAB
18329 for instance. This is easier than to set up the iterator
18330 exactly, and it's not a frequent case, so the additional
18331 effort wouldn't really pay off. */
18332 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
18333 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
18334 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
18335 --last_unchanged_at_beg_row
;
18337 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
18340 if (! init_to_row_end (&it
, w
, last_unchanged_at_beg_row
))
18342 start_pos
= it
.current
.pos
;
18344 /* Start displaying new lines in the desired matrix at the same
18345 vpos we would use in the current matrix, i.e. below
18346 last_unchanged_at_beg_row. */
18347 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
18349 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18350 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
18352 eassert (it
.hpos
== 0 && it
.current_x
== 0);
18356 /* There are no reusable lines at the start of the window.
18357 Start displaying in the first text line. */
18358 start_display (&it
, w
, start
);
18359 it
.vpos
= it
.first_vpos
;
18360 start_pos
= it
.current
.pos
;
18363 /* Find the first row that is not affected by changes at the end of
18364 the buffer. Value will be null if there is no unchanged row, in
18365 which case we must redisplay to the end of the window. delta
18366 will be set to the value by which buffer positions beginning with
18367 first_unchanged_at_end_row have to be adjusted due to text
18369 first_unchanged_at_end_row
18370 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
18371 IF_DEBUG (debug_delta
= delta
);
18372 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
18374 /* Set stop_pos to the buffer position up to which we will have to
18375 display new lines. If first_unchanged_at_end_row != NULL, this
18376 is the buffer position of the start of the line displayed in that
18377 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
18378 that we don't stop at a buffer position. */
18380 if (first_unchanged_at_end_row
)
18382 eassert (last_unchanged_at_beg_row
== NULL
18383 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
18385 /* If this is a continuation line, move forward to the next one
18386 that isn't. Changes in lines above affect this line.
18387 Caution: this may move first_unchanged_at_end_row to a row
18388 not displaying text. */
18389 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
18390 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18391 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18392 < it
.last_visible_y
))
18393 ++first_unchanged_at_end_row
;
18395 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18396 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18397 >= it
.last_visible_y
))
18398 first_unchanged_at_end_row
= NULL
;
18401 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
18403 first_unchanged_at_end_vpos
18404 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
18405 eassert (stop_pos
>= Z
- END_UNCHANGED
);
18408 else if (last_unchanged_at_beg_row
== NULL
)
18414 /* Either there is no unchanged row at the end, or the one we have
18415 now displays text. This is a necessary condition for the window
18416 end pos calculation at the end of this function. */
18417 eassert (first_unchanged_at_end_row
== NULL
18418 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18420 debug_last_unchanged_at_beg_vpos
18421 = (last_unchanged_at_beg_row
18422 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
18424 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
18426 #endif /* GLYPH_DEBUG */
18429 /* Display new lines. Set last_text_row to the last new line
18430 displayed which has text on it, i.e. might end up as being the
18431 line where the window_end_vpos is. */
18432 w
->cursor
.vpos
= -1;
18433 last_text_row
= NULL
;
18434 overlay_arrow_seen
= false;
18435 if (it
.current_y
< it
.last_visible_y
18436 && !f
->fonts_changed
18437 && (first_unchanged_at_end_row
== NULL
18438 || IT_CHARPOS (it
) < stop_pos
))
18439 it
.glyph_row
->reversed_p
= false;
18440 while (it
.current_y
< it
.last_visible_y
18441 && !f
->fonts_changed
18442 && (first_unchanged_at_end_row
== NULL
18443 || IT_CHARPOS (it
) < stop_pos
))
18445 if (display_line (&it
))
18446 last_text_row
= it
.glyph_row
- 1;
18449 if (f
->fonts_changed
)
18452 /* The redisplay iterations in display_line above could have
18453 triggered font-lock, which could have done something that
18454 invalidates IT->w window's end-point information, on which we
18455 rely below. E.g., one package, which will remain unnamed, used
18456 to install a font-lock-fontify-region-function that called
18457 bury-buffer, whose side effect is to switch the buffer displayed
18458 by IT->w, and that predictably resets IT->w's window_end_valid
18459 flag, which we already tested at the entry to this function.
18460 Amply punish such packages/modes by giving up on this
18461 optimization in those cases. */
18462 if (!w
->window_end_valid
)
18464 clear_glyph_matrix (w
->desired_matrix
);
18468 /* Compute differences in buffer positions, y-positions etc. for
18469 lines reused at the bottom of the window. Compute what we can
18471 if (first_unchanged_at_end_row
18472 /* No lines reused because we displayed everything up to the
18473 bottom of the window. */
18474 && it
.current_y
< it
.last_visible_y
)
18477 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
18479 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
18480 run
.current_y
= first_unchanged_at_end_row
->y
;
18481 run
.desired_y
= run
.current_y
+ dy
;
18482 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
18486 delta
= delta_bytes
= dvpos
= dy
18487 = run
.current_y
= run
.desired_y
= run
.height
= 0;
18488 first_unchanged_at_end_row
= NULL
;
18490 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
18493 /* Find the cursor if not already found. We have to decide whether
18494 PT will appear on this window (it sometimes doesn't, but this is
18495 not a very frequent case.) This decision has to be made before
18496 the current matrix is altered. A value of cursor.vpos < 0 means
18497 that PT is either in one of the lines beginning at
18498 first_unchanged_at_end_row or below the window. Don't care for
18499 lines that might be displayed later at the window end; as
18500 mentioned, this is not a frequent case. */
18501 if (w
->cursor
.vpos
< 0)
18503 /* Cursor in unchanged rows at the top? */
18504 if (PT
< CHARPOS (start_pos
)
18505 && last_unchanged_at_beg_row
)
18507 row
= row_containing_pos (w
, PT
,
18508 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
18509 last_unchanged_at_beg_row
+ 1, 0);
18511 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
18514 /* Start from first_unchanged_at_end_row looking for PT. */
18515 else if (first_unchanged_at_end_row
)
18517 row
= row_containing_pos (w
, PT
- delta
,
18518 first_unchanged_at_end_row
, NULL
, 0);
18520 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
18521 delta_bytes
, dy
, dvpos
);
18524 /* Give up if cursor was not found. */
18525 if (w
->cursor
.vpos
< 0)
18527 clear_glyph_matrix (w
->desired_matrix
);
18532 /* Don't let the cursor end in the scroll margins. */
18534 int this_scroll_margin
, cursor_height
;
18535 int frame_line_height
= default_line_pixel_height (w
);
18536 int window_total_lines
18537 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
18539 this_scroll_margin
=
18540 max (0, min (scroll_margin
, window_total_lines
/ 4));
18541 this_scroll_margin
*= frame_line_height
;
18542 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
18544 if ((w
->cursor
.y
< this_scroll_margin
18545 && CHARPOS (start
) > BEGV
)
18546 /* Old redisplay didn't take scroll margin into account at the bottom,
18547 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
18548 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
18549 ? cursor_height
+ this_scroll_margin
18550 : 1)) > it
.last_visible_y
)
18552 w
->cursor
.vpos
= -1;
18553 clear_glyph_matrix (w
->desired_matrix
);
18558 /* Scroll the display. Do it before changing the current matrix so
18559 that xterm.c doesn't get confused about where the cursor glyph is
18561 if (dy
&& run
.height
)
18565 if (FRAME_WINDOW_P (f
))
18567 FRAME_RIF (f
)->update_window_begin_hook (w
);
18568 FRAME_RIF (f
)->clear_window_mouse_face (w
);
18569 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
18570 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
18574 /* Terminal frame. In this case, dvpos gives the number of
18575 lines to scroll by; dvpos < 0 means scroll up. */
18577 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
18578 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
18579 int end
= (WINDOW_TOP_EDGE_LINE (w
)
18580 + WINDOW_WANTS_HEADER_LINE_P (w
)
18581 + window_internal_height (w
));
18583 #if defined (HAVE_GPM) || defined (MSDOS)
18584 x_clear_window_mouse_face (w
);
18586 /* Perform the operation on the screen. */
18589 /* Scroll last_unchanged_at_beg_row to the end of the
18590 window down dvpos lines. */
18591 set_terminal_window (f
, end
);
18593 /* On dumb terminals delete dvpos lines at the end
18594 before inserting dvpos empty lines. */
18595 if (!FRAME_SCROLL_REGION_OK (f
))
18596 ins_del_lines (f
, end
- dvpos
, -dvpos
);
18598 /* Insert dvpos empty lines in front of
18599 last_unchanged_at_beg_row. */
18600 ins_del_lines (f
, from
, dvpos
);
18602 else if (dvpos
< 0)
18604 /* Scroll up last_unchanged_at_beg_vpos to the end of
18605 the window to last_unchanged_at_beg_vpos - |dvpos|. */
18606 set_terminal_window (f
, end
);
18608 /* Delete dvpos lines in front of
18609 last_unchanged_at_beg_vpos. ins_del_lines will set
18610 the cursor to the given vpos and emit |dvpos| delete
18612 ins_del_lines (f
, from
+ dvpos
, dvpos
);
18614 /* On a dumb terminal insert dvpos empty lines at the
18616 if (!FRAME_SCROLL_REGION_OK (f
))
18617 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
18620 set_terminal_window (f
, 0);
18626 /* Shift reused rows of the current matrix to the right position.
18627 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
18629 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18630 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
18633 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
18634 bottom_vpos
, dvpos
);
18635 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
18638 else if (dvpos
> 0)
18640 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
18641 bottom_vpos
, dvpos
);
18642 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
18643 first_unchanged_at_end_vpos
+ dvpos
);
18646 /* For frame-based redisplay, make sure that current frame and window
18647 matrix are in sync with respect to glyph memory. */
18648 if (!FRAME_WINDOW_P (f
))
18649 sync_frame_with_window_matrix_rows (w
);
18651 /* Adjust buffer positions in reused rows. */
18652 if (delta
|| delta_bytes
)
18653 increment_matrix_positions (current_matrix
,
18654 first_unchanged_at_end_vpos
+ dvpos
,
18655 bottom_vpos
, delta
, delta_bytes
);
18657 /* Adjust Y positions. */
18659 shift_glyph_matrix (w
, current_matrix
,
18660 first_unchanged_at_end_vpos
+ dvpos
,
18663 if (first_unchanged_at_end_row
)
18665 first_unchanged_at_end_row
+= dvpos
;
18666 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
18667 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
18668 first_unchanged_at_end_row
= NULL
;
18671 /* If scrolling up, there may be some lines to display at the end of
18673 last_text_row_at_end
= NULL
;
18676 /* Scrolling up can leave for example a partially visible line
18677 at the end of the window to be redisplayed. */
18678 /* Set last_row to the glyph row in the current matrix where the
18679 window end line is found. It has been moved up or down in
18680 the matrix by dvpos. */
18681 int last_vpos
= w
->window_end_vpos
+ dvpos
;
18682 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
18684 /* If last_row is the window end line, it should display text. */
18685 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
18687 /* If window end line was partially visible before, begin
18688 displaying at that line. Otherwise begin displaying with the
18689 line following it. */
18690 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
18692 init_to_row_start (&it
, w
, last_row
);
18693 it
.vpos
= last_vpos
;
18694 it
.current_y
= last_row
->y
;
18698 init_to_row_end (&it
, w
, last_row
);
18699 it
.vpos
= 1 + last_vpos
;
18700 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
18704 /* We may start in a continuation line. If so, we have to
18705 get the right continuation_lines_width and current_x. */
18706 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
18707 it
.hpos
= it
.current_x
= 0;
18709 /* Display the rest of the lines at the window end. */
18710 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18711 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
18713 /* Is it always sure that the display agrees with lines in
18714 the current matrix? I don't think so, so we mark rows
18715 displayed invalid in the current matrix by setting their
18716 enabled_p flag to false. */
18717 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
18718 if (display_line (&it
))
18719 last_text_row_at_end
= it
.glyph_row
- 1;
18723 /* Update window_end_pos and window_end_vpos. */
18724 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
18726 /* Window end line if one of the preserved rows from the current
18727 matrix. Set row to the last row displaying text in current
18728 matrix starting at first_unchanged_at_end_row, after
18730 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18731 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
18732 first_unchanged_at_end_row
);
18733 eassume (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
18734 adjust_window_ends (w
, row
, true);
18735 eassert (w
->window_end_bytepos
>= 0);
18736 IF_DEBUG (debug_method_add (w
, "A"));
18738 else if (last_text_row_at_end
)
18740 adjust_window_ends (w
, last_text_row_at_end
, false);
18741 eassert (w
->window_end_bytepos
>= 0);
18742 IF_DEBUG (debug_method_add (w
, "B"));
18744 else if (last_text_row
)
18746 /* We have displayed either to the end of the window or at the
18747 end of the window, i.e. the last row with text is to be found
18748 in the desired matrix. */
18749 adjust_window_ends (w
, last_text_row
, false);
18750 eassert (w
->window_end_bytepos
>= 0);
18752 else if (first_unchanged_at_end_row
== NULL
18753 && last_text_row
== NULL
18754 && last_text_row_at_end
== NULL
)
18756 /* Displayed to end of window, but no line containing text was
18757 displayed. Lines were deleted at the end of the window. */
18758 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
18759 int vpos
= w
->window_end_vpos
;
18760 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
18761 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18763 for (row
= NULL
; !row
; --vpos
, --current_row
, --desired_row
)
18765 eassert (first_vpos
<= vpos
);
18766 if (desired_row
->enabled_p
)
18768 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18771 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18775 w
->window_end_vpos
= vpos
+ 1;
18776 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18777 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18778 eassert (w
->window_end_bytepos
>= 0);
18779 IF_DEBUG (debug_method_add (w
, "C"));
18784 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18785 debug_end_vpos
= w
->window_end_vpos
));
18787 /* Record that display has not been completed. */
18788 w
->window_end_valid
= false;
18789 w
->desired_matrix
->no_scrolling_p
= true;
18797 /***********************************************************************
18798 More debugging support
18799 ***********************************************************************/
18803 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18804 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18805 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18808 /* Dump the contents of glyph matrix MATRIX on stderr.
18810 GLYPHS 0 means don't show glyph contents.
18811 GLYPHS 1 means show glyphs in short form
18812 GLYPHS > 1 means show glyphs in long form. */
18815 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18818 for (i
= 0; i
< matrix
->nrows
; ++i
)
18819 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18823 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18824 the glyph row and area where the glyph comes from. */
18827 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18829 if (glyph
->type
== CHAR_GLYPH
18830 || glyph
->type
== GLYPHLESS_GLYPH
)
18833 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18834 glyph
- row
->glyphs
[TEXT_AREA
],
18835 (glyph
->type
== CHAR_GLYPH
18839 (BUFFERP (glyph
->object
)
18841 : (STRINGP (glyph
->object
)
18843 : (NILP (glyph
->object
)
18846 glyph
->pixel_width
,
18848 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18852 glyph
->left_box_line_p
,
18853 glyph
->right_box_line_p
);
18855 else if (glyph
->type
== STRETCH_GLYPH
)
18858 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18859 glyph
- row
->glyphs
[TEXT_AREA
],
18862 (BUFFERP (glyph
->object
)
18864 : (STRINGP (glyph
->object
)
18866 : (NILP (glyph
->object
)
18869 glyph
->pixel_width
,
18873 glyph
->left_box_line_p
,
18874 glyph
->right_box_line_p
);
18876 else if (glyph
->type
== IMAGE_GLYPH
)
18879 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18880 glyph
- row
->glyphs
[TEXT_AREA
],
18883 (BUFFERP (glyph
->object
)
18885 : (STRINGP (glyph
->object
)
18887 : (NILP (glyph
->object
)
18890 glyph
->pixel_width
,
18894 glyph
->left_box_line_p
,
18895 glyph
->right_box_line_p
);
18897 else if (glyph
->type
== COMPOSITE_GLYPH
)
18900 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18901 glyph
- row
->glyphs
[TEXT_AREA
],
18904 (BUFFERP (glyph
->object
)
18906 : (STRINGP (glyph
->object
)
18908 : (NILP (glyph
->object
)
18911 glyph
->pixel_width
,
18913 if (glyph
->u
.cmp
.automatic
)
18916 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18917 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18919 glyph
->left_box_line_p
,
18920 glyph
->right_box_line_p
);
18922 else if (glyph
->type
== XWIDGET_GLYPH
)
18924 #ifndef HAVE_XWIDGETS
18928 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18929 glyph
- row
->glyphs
[TEXT_AREA
],
18932 (BUFFERP (glyph
->object
)
18934 : (STRINGP (glyph
->object
)
18937 glyph
->pixel_width
,
18941 glyph
->left_box_line_p
,
18942 glyph
->right_box_line_p
);
18948 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18949 GLYPHS 0 means don't show glyph contents.
18950 GLYPHS 1 means show glyphs in short form
18951 GLYPHS > 1 means show glyphs in long form. */
18954 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18958 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18959 fprintf (stderr
, "==============================================================================\n");
18961 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18962 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18964 MATRIX_ROW_START_CHARPOS (row
),
18965 MATRIX_ROW_END_CHARPOS (row
),
18966 row
->used
[TEXT_AREA
],
18967 row
->contains_overlapping_glyphs_p
,
18969 row
->truncated_on_left_p
,
18970 row
->truncated_on_right_p
,
18972 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18973 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18976 row
->ends_in_middle_of_char_p
,
18977 row
->starts_in_middle_of_char_p
,
18983 row
->visible_height
,
18986 /* The next 3 lines should align to "Start" in the header. */
18987 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18988 row
->end
.overlay_string_index
,
18989 row
->continuation_lines_width
);
18990 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18991 CHARPOS (row
->start
.string_pos
),
18992 CHARPOS (row
->end
.string_pos
));
18993 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18994 row
->end
.dpvec_index
);
19001 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
19003 struct glyph
*glyph
= row
->glyphs
[area
];
19004 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
19006 /* Glyph for a line end in text. */
19007 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
19010 if (glyph
< glyph_end
)
19011 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
19013 for (; glyph
< glyph_end
; ++glyph
)
19014 dump_glyph (row
, glyph
, area
);
19017 else if (glyphs
== 1)
19020 char s
[SHRT_MAX
+ 4];
19022 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
19026 for (i
= 0; i
< row
->used
[area
]; ++i
)
19028 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
19029 if (i
== row
->used
[area
] - 1
19030 && area
== TEXT_AREA
19031 && NILP (glyph
->object
)
19032 && glyph
->type
== CHAR_GLYPH
19033 && glyph
->u
.ch
== ' ')
19035 strcpy (&s
[i
], "[\\n]");
19038 else if (glyph
->type
== CHAR_GLYPH
19039 && glyph
->u
.ch
< 0x80
19040 && glyph
->u
.ch
>= ' ')
19041 s
[i
] = glyph
->u
.ch
;
19047 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
19053 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
19054 Sdump_glyph_matrix
, 0, 1, "p",
19055 doc
: /* Dump the current matrix of the selected window to stderr.
19056 Shows contents of glyph row structures. With non-nil
19057 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
19058 glyphs in short form, otherwise show glyphs in long form.
19060 Interactively, no argument means show glyphs in short form;
19061 with numeric argument, its value is passed as the GLYPHS flag. */)
19062 (Lisp_Object glyphs
)
19064 struct window
*w
= XWINDOW (selected_window
);
19065 struct buffer
*buffer
= XBUFFER (w
->contents
);
19067 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
19068 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
19069 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
19070 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
19071 fprintf (stderr
, "=============================================\n");
19072 dump_glyph_matrix (w
->current_matrix
,
19073 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
19078 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
19079 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* Dump the current glyph matrix of the selected frame to stderr.
19080 Only text-mode frames have frame glyph matrices. */)
19083 struct frame
*f
= XFRAME (selected_frame
);
19085 if (f
->current_matrix
)
19086 dump_glyph_matrix (f
->current_matrix
, 1);
19088 fprintf (stderr
, "*** This frame doesn't have a frame glyph matrix ***\n");
19093 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
19094 doc
: /* Dump glyph row ROW to stderr.
19095 GLYPH 0 means don't dump glyphs.
19096 GLYPH 1 means dump glyphs in short form.
19097 GLYPH > 1 or omitted means dump glyphs in long form. */)
19098 (Lisp_Object row
, Lisp_Object glyphs
)
19100 struct glyph_matrix
*matrix
;
19103 CHECK_NUMBER (row
);
19104 matrix
= XWINDOW (selected_window
)->current_matrix
;
19106 if (vpos
>= 0 && vpos
< matrix
->nrows
)
19107 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
19109 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
19114 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
19115 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
19116 GLYPH 0 means don't dump glyphs.
19117 GLYPH 1 means dump glyphs in short form.
19118 GLYPH > 1 or omitted means dump glyphs in long form.
19120 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
19122 (Lisp_Object row
, Lisp_Object glyphs
)
19124 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19125 struct frame
*sf
= SELECTED_FRAME ();
19126 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
19129 CHECK_NUMBER (row
);
19131 if (vpos
>= 0 && vpos
< m
->nrows
)
19132 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
19133 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
19139 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
19140 doc
: /* Toggle tracing of redisplay.
19141 With ARG, turn tracing on if and only if ARG is positive. */)
19145 trace_redisplay_p
= !trace_redisplay_p
;
19148 arg
= Fprefix_numeric_value (arg
);
19149 trace_redisplay_p
= XINT (arg
) > 0;
19156 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
19157 doc
: /* Like `format', but print result to stderr.
19158 usage: (trace-to-stderr STRING &rest OBJECTS) */)
19159 (ptrdiff_t nargs
, Lisp_Object
*args
)
19161 Lisp_Object s
= Fformat (nargs
, args
);
19162 fwrite (SDATA (s
), 1, SBYTES (s
), stderr
);
19166 #endif /* GLYPH_DEBUG */
19170 /***********************************************************************
19171 Building Desired Matrix Rows
19172 ***********************************************************************/
19174 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
19175 Used for non-window-redisplay windows, and for windows w/o left fringe. */
19177 static struct glyph_row
*
19178 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
19180 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19181 struct buffer
*buffer
= XBUFFER (w
->contents
);
19182 struct buffer
*old
= current_buffer
;
19183 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
19184 ptrdiff_t arrow_len
= SCHARS (overlay_arrow_string
);
19185 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
19186 const unsigned char *p
;
19189 int n_glyphs_before
;
19191 set_buffer_temp (buffer
);
19192 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
19193 scratch_glyph_row
.reversed_p
= false;
19194 it
.glyph_row
->used
[TEXT_AREA
] = 0;
19195 SET_TEXT_POS (it
.position
, 0, 0);
19197 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
19199 while (p
< arrow_end
)
19201 Lisp_Object face
, ilisp
;
19203 /* Get the next character. */
19205 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
19208 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
19209 if (! ASCII_CHAR_P (it
.c
))
19210 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
19214 /* Get its face. */
19215 ilisp
= make_number (p
- arrow_string
);
19216 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
19217 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
19219 /* Compute its width, get its glyphs. */
19220 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
19221 SET_TEXT_POS (it
.position
, -1, -1);
19222 PRODUCE_GLYPHS (&it
);
19224 /* If this character doesn't fit any more in the line, we have
19225 to remove some glyphs. */
19226 if (it
.current_x
> it
.last_visible_x
)
19228 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19233 set_buffer_temp (old
);
19234 return it
.glyph_row
;
19238 /* Insert truncation glyphs at the start of IT->glyph_row. Which
19239 glyphs to insert is determined by produce_special_glyphs. */
19242 insert_left_trunc_glyphs (struct it
*it
)
19244 struct it truncate_it
;
19245 struct glyph
*from
, *end
, *to
, *toend
;
19247 eassert (!FRAME_WINDOW_P (it
->f
)
19248 || (!it
->glyph_row
->reversed_p
19249 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19250 || (it
->glyph_row
->reversed_p
19251 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
19253 /* Get the truncation glyphs. */
19255 truncate_it
.current_x
= 0;
19256 truncate_it
.face_id
= DEFAULT_FACE_ID
;
19257 truncate_it
.glyph_row
= &scratch_glyph_row
;
19258 truncate_it
.area
= TEXT_AREA
;
19259 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
19260 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
19261 truncate_it
.object
= Qnil
;
19262 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
19264 /* Overwrite glyphs from IT with truncation glyphs. */
19265 if (!it
->glyph_row
->reversed_p
)
19267 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
19269 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19270 end
= from
+ tused
;
19271 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19272 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
19273 if (FRAME_WINDOW_P (it
->f
))
19275 /* On GUI frames, when variable-size fonts are displayed,
19276 the truncation glyphs may need more pixels than the row's
19277 glyphs they overwrite. We overwrite more glyphs to free
19278 enough screen real estate, and enlarge the stretch glyph
19279 on the right (see display_line), if there is one, to
19280 preserve the screen position of the truncation glyphs on
19283 struct glyph
*g
= to
;
19286 /* The first glyph could be partially visible, in which case
19287 it->glyph_row->x will be negative. But we want the left
19288 truncation glyphs to be aligned at the left margin of the
19289 window, so we override the x coordinate at which the row
19291 it
->glyph_row
->x
= 0;
19292 while (g
< toend
&& w
< it
->truncation_pixel_width
)
19294 w
+= g
->pixel_width
;
19297 if (g
- to
- tused
> 0)
19299 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
19300 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
19302 used
= it
->glyph_row
->used
[TEXT_AREA
];
19303 if (it
->glyph_row
->truncated_on_right_p
19304 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
19305 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
19308 int extra
= w
- it
->truncation_pixel_width
;
19310 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
19317 /* There may be padding glyphs left over. Overwrite them too. */
19318 if (!FRAME_WINDOW_P (it
->f
))
19320 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
19322 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19329 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
19333 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
19335 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
19336 that back to front. */
19337 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19338 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19339 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19340 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19341 if (FRAME_WINDOW_P (it
->f
))
19344 struct glyph
*g
= to
;
19346 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
19348 w
+= g
->pixel_width
;
19351 if (to
- g
- tused
> 0)
19353 if (it
->glyph_row
->truncated_on_right_p
19354 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
19355 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
19357 int extra
= w
- it
->truncation_pixel_width
;
19359 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
19363 while (from
>= end
&& to
>= toend
)
19365 if (!FRAME_WINDOW_P (it
->f
))
19367 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
19370 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
19371 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19372 while (from
>= end
&& to
>= toend
)
19378 /* Need to free some room before prepending additional
19380 int move_by
= from
- end
+ 1;
19381 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19382 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19384 for ( ; g
>= g0
; g
--)
19386 while (from
>= end
)
19388 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
19393 /* Compute the hash code for ROW. */
19395 row_hash (struct glyph_row
*row
)
19398 unsigned hashval
= 0;
19400 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
19401 for (k
= 0; k
< row
->used
[area
]; ++k
)
19402 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
19403 + row
->glyphs
[area
][k
].u
.val
19404 + row
->glyphs
[area
][k
].face_id
19405 + row
->glyphs
[area
][k
].padding_p
19406 + (row
->glyphs
[area
][k
].type
<< 2));
19411 /* Compute the pixel height and width of IT->glyph_row.
19413 Most of the time, ascent and height of a display line will be equal
19414 to the max_ascent and max_height values of the display iterator
19415 structure. This is not the case if
19417 1. We hit ZV without displaying anything. In this case, max_ascent
19418 and max_height will be zero.
19420 2. We have some glyphs that don't contribute to the line height.
19421 (The glyph row flag contributes_to_line_height_p is for future
19422 pixmap extensions).
19424 The first case is easily covered by using default values because in
19425 these cases, the line height does not really matter, except that it
19426 must not be zero. */
19429 compute_line_metrics (struct it
*it
)
19431 struct glyph_row
*row
= it
->glyph_row
;
19433 if (FRAME_WINDOW_P (it
->f
))
19435 int i
, min_y
, max_y
;
19437 /* The line may consist of one space only, that was added to
19438 place the cursor on it. If so, the row's height hasn't been
19440 if (row
->height
== 0)
19442 if (it
->max_ascent
+ it
->max_descent
== 0)
19443 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
19444 row
->ascent
= it
->max_ascent
;
19445 row
->height
= it
->max_ascent
+ it
->max_descent
;
19446 row
->phys_ascent
= it
->max_phys_ascent
;
19447 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19448 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19451 /* Compute the width of this line. */
19452 row
->pixel_width
= row
->x
;
19453 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
19454 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
19456 eassert (row
->pixel_width
>= 0);
19457 eassert (row
->ascent
>= 0 && row
->height
> 0);
19459 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
19460 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
19462 /* If first line's physical ascent is larger than its logical
19463 ascent, use the physical ascent, and make the row taller.
19464 This makes accented characters fully visible. */
19465 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
19466 && row
->phys_ascent
> row
->ascent
)
19468 row
->height
+= row
->phys_ascent
- row
->ascent
;
19469 row
->ascent
= row
->phys_ascent
;
19472 /* Compute how much of the line is visible. */
19473 row
->visible_height
= row
->height
;
19475 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
19476 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
19478 if (row
->y
< min_y
)
19479 row
->visible_height
-= min_y
- row
->y
;
19480 if (row
->y
+ row
->height
> max_y
)
19481 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
19485 row
->pixel_width
= row
->used
[TEXT_AREA
];
19486 if (row
->continued_p
)
19487 row
->pixel_width
-= it
->continuation_pixel_width
;
19488 else if (row
->truncated_on_right_p
)
19489 row
->pixel_width
-= it
->truncation_pixel_width
;
19490 row
->ascent
= row
->phys_ascent
= 0;
19491 row
->height
= row
->phys_height
= row
->visible_height
= 1;
19492 row
->extra_line_spacing
= 0;
19495 /* Compute a hash code for this row. */
19496 row
->hash
= row_hash (row
);
19498 it
->max_ascent
= it
->max_descent
= 0;
19499 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
19503 /* Append one space to the glyph row of iterator IT if doing a
19504 window-based redisplay. The space has the same face as
19505 IT->face_id. Value is true if a space was added.
19507 This function is called to make sure that there is always one glyph
19508 at the end of a glyph row that the cursor can be set on under
19509 window-systems. (If there weren't such a glyph we would not know
19510 how wide and tall a box cursor should be displayed).
19512 At the same time this space let's a nicely handle clearing to the
19513 end of the line if the row ends in italic text. */
19516 append_space_for_newline (struct it
*it
, bool default_face_p
)
19518 if (FRAME_WINDOW_P (it
->f
))
19520 int n
= it
->glyph_row
->used
[TEXT_AREA
];
19522 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
19523 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
19525 /* Save some values that must not be changed.
19526 Must save IT->c and IT->len because otherwise
19527 ITERATOR_AT_END_P wouldn't work anymore after
19528 append_space_for_newline has been called. */
19529 enum display_element_type saved_what
= it
->what
;
19530 int saved_c
= it
->c
, saved_len
= it
->len
;
19531 int saved_char_to_display
= it
->char_to_display
;
19532 int saved_x
= it
->current_x
;
19533 int saved_face_id
= it
->face_id
;
19534 bool saved_box_end
= it
->end_of_box_run_p
;
19535 struct text_pos saved_pos
;
19536 Lisp_Object saved_object
;
19539 saved_object
= it
->object
;
19540 saved_pos
= it
->position
;
19542 it
->what
= IT_CHARACTER
;
19543 memset (&it
->position
, 0, sizeof it
->position
);
19545 it
->c
= it
->char_to_display
= ' ';
19548 /* If the default face was remapped, be sure to use the
19549 remapped face for the appended newline. */
19550 if (default_face_p
)
19551 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
19552 else if (it
->face_before_selective_p
)
19553 it
->face_id
= it
->saved_face_id
;
19554 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19555 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
19556 /* In R2L rows, we will prepend a stretch glyph that will
19557 have the end_of_box_run_p flag set for it, so there's no
19558 need for the appended newline glyph to have that flag
19560 if (it
->glyph_row
->reversed_p
19561 /* But if the appended newline glyph goes all the way to
19562 the end of the row, there will be no stretch glyph,
19563 so leave the box flag set. */
19564 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
19565 it
->end_of_box_run_p
= false;
19567 PRODUCE_GLYPHS (it
);
19569 #ifdef HAVE_WINDOW_SYSTEM
19570 /* Make sure this space glyph has the right ascent and
19571 descent values, or else cursor at end of line will look
19572 funny, and height of empty lines will be incorrect. */
19573 struct glyph
*g
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19574 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19577 Lisp_Object height
, total_height
;
19578 int extra_line_spacing
= it
->extra_line_spacing
;
19579 int boff
= font
->baseline_offset
;
19581 if (font
->vertical_centering
)
19582 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19584 it
->object
= saved_object
; /* get_it_property needs this */
19585 normal_char_ascent_descent (font
, -1, &it
->ascent
, &it
->descent
);
19586 /* Must do a subset of line height processing from
19587 x_produce_glyph for newline characters. */
19588 height
= get_it_property (it
, Qline_height
);
19590 && CONSP (XCDR (height
))
19591 && NILP (XCDR (XCDR (height
))))
19593 total_height
= XCAR (XCDR (height
));
19594 height
= XCAR (height
);
19597 total_height
= Qnil
;
19598 height
= calc_line_height_property (it
, height
, font
, boff
, true);
19600 if (it
->override_ascent
>= 0)
19602 it
->ascent
= it
->override_ascent
;
19603 it
->descent
= it
->override_descent
;
19604 boff
= it
->override_boff
;
19606 if (EQ (height
, Qt
))
19607 extra_line_spacing
= 0;
19610 Lisp_Object spacing
;
19612 it
->phys_ascent
= it
->ascent
;
19613 it
->phys_descent
= it
->descent
;
19615 && XINT (height
) > it
->ascent
+ it
->descent
)
19616 it
->ascent
= XINT (height
) - it
->descent
;
19618 if (!NILP (total_height
))
19619 spacing
= calc_line_height_property (it
, total_height
, font
,
19623 spacing
= get_it_property (it
, Qline_spacing
);
19624 spacing
= calc_line_height_property (it
, spacing
, font
,
19627 if (INTEGERP (spacing
))
19629 extra_line_spacing
= XINT (spacing
);
19630 if (!NILP (total_height
))
19631 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19634 if (extra_line_spacing
> 0)
19636 it
->descent
+= extra_line_spacing
;
19637 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19638 it
->max_extra_line_spacing
= extra_line_spacing
;
19640 it
->max_ascent
= it
->ascent
;
19641 it
->max_descent
= it
->descent
;
19642 /* Make sure compute_line_metrics recomputes the row height. */
19643 it
->glyph_row
->height
= 0;
19646 g
->ascent
= it
->max_ascent
;
19647 g
->descent
= it
->max_descent
;
19650 it
->override_ascent
= -1;
19651 it
->constrain_row_ascent_descent_p
= false;
19652 it
->current_x
= saved_x
;
19653 it
->object
= saved_object
;
19654 it
->position
= saved_pos
;
19655 it
->what
= saved_what
;
19656 it
->face_id
= saved_face_id
;
19657 it
->len
= saved_len
;
19659 it
->char_to_display
= saved_char_to_display
;
19660 it
->end_of_box_run_p
= saved_box_end
;
19669 /* Extend the face of the last glyph in the text area of IT->glyph_row
19670 to the end of the display line. Called from display_line. If the
19671 glyph row is empty, add a space glyph to it so that we know the
19672 face to draw. Set the glyph row flag fill_line_p. If the glyph
19673 row is R2L, prepend a stretch glyph to cover the empty space to the
19674 left of the leftmost glyph. */
19677 extend_face_to_end_of_line (struct it
*it
)
19679 struct face
*face
, *default_face
;
19680 struct frame
*f
= it
->f
;
19682 /* If line is already filled, do nothing. Non window-system frames
19683 get a grace of one more ``pixel'' because their characters are
19684 1-``pixel'' wide, so they hit the equality too early. This grace
19685 is needed only for R2L rows that are not continued, to produce
19686 one extra blank where we could display the cursor. */
19687 if ((it
->current_x
>= it
->last_visible_x
19688 + (!FRAME_WINDOW_P (f
)
19689 && it
->glyph_row
->reversed_p
19690 && !it
->glyph_row
->continued_p
))
19691 /* If the window has display margins, we will need to extend
19692 their face even if the text area is filled. */
19693 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19694 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
19697 /* The default face, possibly remapped. */
19698 default_face
= FACE_FROM_ID_OR_NULL (f
,
19699 lookup_basic_face (f
, DEFAULT_FACE_ID
));
19701 /* Face extension extends the background and box of IT->face_id
19702 to the end of the line. If the background equals the background
19703 of the frame, we don't have to do anything. */
19704 face
= FACE_FROM_ID (f
, (it
->face_before_selective_p
19705 ? it
->saved_face_id
19708 if (FRAME_WINDOW_P (f
)
19709 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
19710 && face
->box
== FACE_NO_BOX
19711 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
19712 #ifdef HAVE_WINDOW_SYSTEM
19715 && !it
->glyph_row
->reversed_p
)
19718 /* Set the glyph row flag indicating that the face of the last glyph
19719 in the text area has to be drawn to the end of the text area. */
19720 it
->glyph_row
->fill_line_p
= true;
19722 /* If current character of IT is not ASCII, make sure we have the
19723 ASCII face. This will be automatically undone the next time
19724 get_next_display_element returns a multibyte character. Note
19725 that the character will always be single byte in unibyte
19727 if (!ASCII_CHAR_P (it
->c
))
19729 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
19732 if (FRAME_WINDOW_P (f
))
19734 /* If the row is empty, add a space with the current face of IT,
19735 so that we know which face to draw. */
19736 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
19738 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
19739 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
19740 it
->glyph_row
->used
[TEXT_AREA
] = 1;
19742 /* Mode line and the header line don't have margins, and
19743 likewise the frame's tool-bar window, if there is any. */
19744 if (!(it
->glyph_row
->mode_line_p
19745 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19746 || (WINDOWP (f
->tool_bar_window
)
19747 && it
->w
== XWINDOW (f
->tool_bar_window
))
19751 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19752 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
19754 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
19755 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
=
19757 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
19759 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19760 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
19762 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
19763 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
=
19765 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
19768 #ifdef HAVE_WINDOW_SYSTEM
19769 if (it
->glyph_row
->reversed_p
)
19771 /* Prepend a stretch glyph to the row, such that the
19772 rightmost glyph will be drawn flushed all the way to the
19773 right margin of the window. The stretch glyph that will
19774 occupy the empty space, if any, to the left of the
19776 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
19777 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19778 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
19780 int row_width
, stretch_ascent
, stretch_width
;
19781 struct text_pos saved_pos
;
19783 bool saved_avoid_cursor
, saved_box_start
;
19785 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
19786 row_width
+= g
->pixel_width
;
19788 /* FIXME: There are various minor display glitches in R2L
19789 rows when only one of the fringes is missing. The
19790 strange condition below produces the least bad effect. */
19791 if ((WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19792 == (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
19793 || WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
19794 stretch_width
= window_box_width (it
->w
, TEXT_AREA
);
19796 stretch_width
= it
->last_visible_x
- it
->first_visible_x
;
19797 stretch_width
-= row_width
;
19799 if (stretch_width
> 0)
19802 (((it
->ascent
+ it
->descent
)
19803 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
19804 saved_pos
= it
->position
;
19805 memset (&it
->position
, 0, sizeof it
->position
);
19806 saved_avoid_cursor
= it
->avoid_cursor_p
;
19807 it
->avoid_cursor_p
= true;
19808 saved_face_id
= it
->face_id
;
19809 saved_box_start
= it
->start_of_box_run_p
;
19810 /* The last row's stretch glyph should get the default
19811 face, to avoid painting the rest of the window with
19812 the region face, if the region ends at ZV. */
19813 if (it
->glyph_row
->ends_at_zv_p
)
19814 it
->face_id
= default_face
->id
;
19816 it
->face_id
= face
->id
;
19817 it
->start_of_box_run_p
= false;
19818 append_stretch_glyph (it
, Qnil
, stretch_width
,
19819 it
->ascent
+ it
->descent
, stretch_ascent
);
19820 it
->position
= saved_pos
;
19821 it
->avoid_cursor_p
= saved_avoid_cursor
;
19822 it
->face_id
= saved_face_id
;
19823 it
->start_of_box_run_p
= saved_box_start
;
19825 /* If stretch_width comes out negative, it means that the
19826 last glyph is only partially visible. In R2L rows, we
19827 want the leftmost glyph to be partially visible, so we
19828 need to give the row the corresponding left offset. */
19829 if (stretch_width
< 0)
19830 it
->glyph_row
->x
= stretch_width
;
19832 #endif /* HAVE_WINDOW_SYSTEM */
19836 /* Save some values that must not be changed. */
19837 int saved_x
= it
->current_x
;
19838 struct text_pos saved_pos
;
19839 Lisp_Object saved_object
;
19840 enum display_element_type saved_what
= it
->what
;
19841 int saved_face_id
= it
->face_id
;
19843 saved_object
= it
->object
;
19844 saved_pos
= it
->position
;
19846 it
->what
= IT_CHARACTER
;
19847 memset (&it
->position
, 0, sizeof it
->position
);
19849 it
->c
= it
->char_to_display
= ' ';
19852 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19853 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19854 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19855 && !it
->glyph_row
->mode_line_p
19856 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19858 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
19859 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
19861 for (it
->current_x
= 0; g
< e
; g
++)
19862 it
->current_x
+= g
->pixel_width
;
19864 it
->area
= LEFT_MARGIN_AREA
;
19865 it
->face_id
= default_face
->id
;
19866 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19867 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19869 PRODUCE_GLYPHS (it
);
19870 /* term.c:produce_glyphs advances it->current_x only for
19872 it
->current_x
+= it
->pixel_width
;
19875 it
->current_x
= saved_x
;
19876 it
->area
= TEXT_AREA
;
19879 /* The last row's blank glyphs should get the default face, to
19880 avoid painting the rest of the window with the region face,
19881 if the region ends at ZV. */
19882 if (it
->glyph_row
->ends_at_zv_p
)
19883 it
->face_id
= default_face
->id
;
19885 it
->face_id
= face
->id
;
19886 PRODUCE_GLYPHS (it
);
19888 while (it
->current_x
<= it
->last_visible_x
)
19889 PRODUCE_GLYPHS (it
);
19891 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19892 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19893 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19894 && !it
->glyph_row
->mode_line_p
19895 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19897 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
19898 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19900 for ( ; g
< e
; g
++)
19901 it
->current_x
+= g
->pixel_width
;
19903 it
->area
= RIGHT_MARGIN_AREA
;
19904 it
->face_id
= default_face
->id
;
19905 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19906 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19908 PRODUCE_GLYPHS (it
);
19909 it
->current_x
+= it
->pixel_width
;
19912 it
->area
= TEXT_AREA
;
19915 /* Don't count these blanks really. It would let us insert a left
19916 truncation glyph below and make us set the cursor on them, maybe. */
19917 it
->current_x
= saved_x
;
19918 it
->object
= saved_object
;
19919 it
->position
= saved_pos
;
19920 it
->what
= saved_what
;
19921 it
->face_id
= saved_face_id
;
19926 /* Value is true if text starting at CHARPOS in current_buffer is
19927 trailing whitespace. */
19930 trailing_whitespace_p (ptrdiff_t charpos
)
19932 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19935 while (bytepos
< ZV_BYTE
19936 && (c
= FETCH_CHAR (bytepos
),
19937 c
== ' ' || c
== '\t'))
19940 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19942 if (bytepos
!= PT_BYTE
)
19949 /* Highlight trailing whitespace, if any, in ROW. */
19952 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19954 int used
= row
->used
[TEXT_AREA
];
19958 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19959 struct glyph
*glyph
= start
+ used
- 1;
19961 if (row
->reversed_p
)
19963 /* Right-to-left rows need to be processed in the opposite
19964 direction, so swap the edge pointers. */
19966 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19969 /* Skip over glyphs inserted to display the cursor at the
19970 end of a line, for extending the face of the last glyph
19971 to the end of the line on terminals, and for truncation
19972 and continuation glyphs. */
19973 if (!row
->reversed_p
)
19975 while (glyph
>= start
19976 && glyph
->type
== CHAR_GLYPH
19977 && NILP (glyph
->object
))
19982 while (glyph
<= start
19983 && glyph
->type
== CHAR_GLYPH
19984 && NILP (glyph
->object
))
19988 /* If last glyph is a space or stretch, and it's trailing
19989 whitespace, set the face of all trailing whitespace glyphs in
19990 IT->glyph_row to `trailing-whitespace'. */
19991 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19992 && BUFFERP (glyph
->object
)
19993 && (glyph
->type
== STRETCH_GLYPH
19994 || (glyph
->type
== CHAR_GLYPH
19995 && glyph
->u
.ch
== ' '))
19996 && trailing_whitespace_p (glyph
->charpos
))
19998 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, false);
20002 if (!row
->reversed_p
)
20004 while (glyph
>= start
20005 && BUFFERP (glyph
->object
)
20006 && (glyph
->type
== STRETCH_GLYPH
20007 || (glyph
->type
== CHAR_GLYPH
20008 && glyph
->u
.ch
== ' ')))
20009 (glyph
--)->face_id
= face_id
;
20013 while (glyph
<= start
20014 && BUFFERP (glyph
->object
)
20015 && (glyph
->type
== STRETCH_GLYPH
20016 || (glyph
->type
== CHAR_GLYPH
20017 && glyph
->u
.ch
== ' ')))
20018 (glyph
++)->face_id
= face_id
;
20025 /* Value is true if glyph row ROW should be
20026 considered to hold the buffer position CHARPOS. */
20029 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
20031 bool result
= true;
20033 if (charpos
== CHARPOS (row
->end
.pos
)
20034 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
20036 /* Suppose the row ends on a string.
20037 Unless the row is continued, that means it ends on a newline
20038 in the string. If it's anything other than a display string
20039 (e.g., a before-string from an overlay), we don't want the
20040 cursor there. (This heuristic seems to give the optimal
20041 behavior for the various types of multi-line strings.)
20042 One exception: if the string has `cursor' property on one of
20043 its characters, we _do_ want the cursor there. */
20044 if (CHARPOS (row
->end
.string_pos
) >= 0)
20046 if (row
->continued_p
)
20050 /* Check for `display' property. */
20051 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
20052 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
20053 struct glyph
*glyph
;
20056 for (glyph
= end
; glyph
>= beg
; --glyph
)
20057 if (STRINGP (glyph
->object
))
20060 = Fget_char_property (make_number (charpos
),
20064 && display_prop_string_p (prop
, glyph
->object
));
20065 /* If there's a `cursor' property on one of the
20066 string's characters, this row is a cursor row,
20067 even though this is not a display string. */
20070 Lisp_Object s
= glyph
->object
;
20072 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
20074 ptrdiff_t gpos
= glyph
->charpos
;
20076 if (!NILP (Fget_char_property (make_number (gpos
),
20088 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
20090 /* If the row ends in middle of a real character,
20091 and the line is continued, we want the cursor here.
20092 That's because CHARPOS (ROW->end.pos) would equal
20093 PT if PT is before the character. */
20094 if (!row
->ends_in_ellipsis_p
)
20095 result
= row
->continued_p
;
20097 /* If the row ends in an ellipsis, then
20098 CHARPOS (ROW->end.pos) will equal point after the
20099 invisible text. We want that position to be displayed
20100 after the ellipsis. */
20103 /* If the row ends at ZV, display the cursor at the end of that
20104 row instead of at the start of the row below. */
20106 result
= row
->ends_at_zv_p
;
20112 /* Value is true if glyph row ROW should be
20113 used to hold the cursor. */
20116 cursor_row_p (struct glyph_row
*row
)
20118 return row_for_charpos_p (row
, PT
);
20123 /* Push the property PROP so that it will be rendered at the current
20124 position in IT. Return true if PROP was successfully pushed, false
20125 otherwise. Called from handle_line_prefix to handle the
20126 `line-prefix' and `wrap-prefix' properties. */
20129 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
20131 struct text_pos pos
=
20132 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
20134 eassert (it
->method
== GET_FROM_BUFFER
20135 || it
->method
== GET_FROM_DISPLAY_VECTOR
20136 || it
->method
== GET_FROM_STRING
20137 || it
->method
== GET_FROM_IMAGE
);
20139 /* We need to save the current buffer/string position, so it will be
20140 restored by pop_it, because iterate_out_of_display_property
20141 depends on that being set correctly, but some situations leave
20142 it->position not yet set when this function is called. */
20143 push_it (it
, &pos
);
20145 if (STRINGP (prop
))
20147 if (SCHARS (prop
) == 0)
20154 it
->string_from_prefix_prop_p
= true;
20155 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
20156 it
->current
.overlay_string_index
= -1;
20157 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
20158 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
20159 it
->method
= GET_FROM_STRING
;
20160 it
->stop_charpos
= 0;
20162 it
->base_level_stop
= 0;
20164 /* Force paragraph direction to be that of the parent
20166 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
20167 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
20169 it
->paragraph_embedding
= L2R
;
20171 /* Set up the bidi iterator for this display string. */
20174 it
->bidi_it
.string
.lstring
= it
->string
;
20175 it
->bidi_it
.string
.s
= NULL
;
20176 it
->bidi_it
.string
.schars
= it
->end_charpos
;
20177 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
20178 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
20179 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
20180 it
->bidi_it
.w
= it
->w
;
20181 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
20184 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
20186 it
->method
= GET_FROM_STRETCH
;
20189 #ifdef HAVE_WINDOW_SYSTEM
20190 else if (IMAGEP (prop
))
20192 it
->what
= IT_IMAGE
;
20193 it
->image_id
= lookup_image (it
->f
, prop
);
20194 it
->method
= GET_FROM_IMAGE
;
20196 #endif /* HAVE_WINDOW_SYSTEM */
20199 pop_it (it
); /* bogus display property, give up */
20206 /* Return the character-property PROP at the current position in IT. */
20209 get_it_property (struct it
*it
, Lisp_Object prop
)
20211 Lisp_Object position
, object
= it
->object
;
20213 if (STRINGP (object
))
20214 position
= make_number (IT_STRING_CHARPOS (*it
));
20215 else if (BUFFERP (object
))
20217 position
= make_number (IT_CHARPOS (*it
));
20218 object
= it
->window
;
20223 return Fget_char_property (position
, prop
, object
);
20226 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
20229 handle_line_prefix (struct it
*it
)
20231 Lisp_Object prefix
;
20233 if (it
->continuation_lines_width
> 0)
20235 prefix
= get_it_property (it
, Qwrap_prefix
);
20237 prefix
= Vwrap_prefix
;
20241 prefix
= get_it_property (it
, Qline_prefix
);
20243 prefix
= Vline_prefix
;
20245 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
20247 /* If the prefix is wider than the window, and we try to wrap
20248 it, it would acquire its own wrap prefix, and so on till the
20249 iterator stack overflows. So, don't wrap the prefix. */
20250 it
->line_wrap
= TRUNCATE
;
20251 it
->avoid_cursor_p
= true;
20257 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
20258 only for R2L lines from display_line and display_string, when they
20259 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
20260 the line/string needs to be continued on the next glyph row. */
20262 unproduce_glyphs (struct it
*it
, int n
)
20264 struct glyph
*glyph
, *end
;
20266 eassert (it
->glyph_row
);
20267 eassert (it
->glyph_row
->reversed_p
);
20268 eassert (it
->area
== TEXT_AREA
);
20269 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
20271 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
20272 n
= it
->glyph_row
->used
[TEXT_AREA
];
20273 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
20274 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
20275 for ( ; glyph
< end
; glyph
++)
20276 glyph
[-n
] = *glyph
;
20279 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
20280 and ROW->maxpos. */
20282 find_row_edges (struct it
*it
, struct glyph_row
*row
,
20283 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
20284 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
20286 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20287 lines' rows is implemented for bidi-reordered rows. */
20289 /* ROW->minpos is the value of min_pos, the minimal buffer position
20290 we have in ROW, or ROW->start.pos if that is smaller. */
20291 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
20292 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
20294 /* We didn't find buffer positions smaller than ROW->start, or
20295 didn't find _any_ valid buffer positions in any of the glyphs,
20296 so we must trust the iterator's computed positions. */
20297 row
->minpos
= row
->start
.pos
;
20300 max_pos
= CHARPOS (it
->current
.pos
);
20301 max_bpos
= BYTEPOS (it
->current
.pos
);
20304 /* Here are the various use-cases for ending the row, and the
20305 corresponding values for ROW->maxpos:
20307 Line ends in a newline from buffer eol_pos + 1
20308 Line is continued from buffer max_pos + 1
20309 Line is truncated on right it->current.pos
20310 Line ends in a newline from string max_pos + 1(*)
20311 (*) + 1 only when line ends in a forward scan
20312 Line is continued from string max_pos
20313 Line is continued from display vector max_pos
20314 Line is entirely from a string min_pos == max_pos
20315 Line is entirely from a display vector min_pos == max_pos
20316 Line that ends at ZV ZV
20318 If you discover other use-cases, please add them here as
20320 if (row
->ends_at_zv_p
)
20321 row
->maxpos
= it
->current
.pos
;
20322 else if (row
->used
[TEXT_AREA
])
20324 bool seen_this_string
= false;
20325 struct glyph_row
*r1
= row
- 1;
20327 /* Did we see the same display string on the previous row? */
20328 if (STRINGP (it
->object
)
20329 /* this is not the first row */
20330 && row
> it
->w
->desired_matrix
->rows
20331 /* previous row is not the header line */
20332 && !r1
->mode_line_p
20333 /* previous row also ends in a newline from a string */
20334 && r1
->ends_in_newline_from_string_p
)
20336 struct glyph
*start
, *end
;
20338 /* Search for the last glyph of the previous row that came
20339 from buffer or string. Depending on whether the row is
20340 L2R or R2L, we need to process it front to back or the
20341 other way round. */
20342 if (!r1
->reversed_p
)
20344 start
= r1
->glyphs
[TEXT_AREA
];
20345 end
= start
+ r1
->used
[TEXT_AREA
];
20346 /* Glyphs inserted by redisplay have nil as their object. */
20348 && NILP ((end
- 1)->object
)
20349 && (end
- 1)->charpos
<= 0)
20353 if (EQ ((end
- 1)->object
, it
->object
))
20354 seen_this_string
= true;
20357 /* If all the glyphs of the previous row were inserted
20358 by redisplay, it means the previous row was
20359 produced from a single newline, which is only
20360 possible if that newline came from the same string
20361 as the one which produced this ROW. */
20362 seen_this_string
= true;
20366 end
= r1
->glyphs
[TEXT_AREA
] - 1;
20367 start
= end
+ r1
->used
[TEXT_AREA
];
20369 && NILP ((end
+ 1)->object
)
20370 && (end
+ 1)->charpos
<= 0)
20374 if (EQ ((end
+ 1)->object
, it
->object
))
20375 seen_this_string
= true;
20378 seen_this_string
= true;
20381 /* Take note of each display string that covers a newline only
20382 once, the first time we see it. This is for when a display
20383 string includes more than one newline in it. */
20384 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
20386 /* If we were scanning the buffer forward when we displayed
20387 the string, we want to account for at least one buffer
20388 position that belongs to this row (position covered by
20389 the display string), so that cursor positioning will
20390 consider this row as a candidate when point is at the end
20391 of the visual line represented by this row. This is not
20392 required when scanning back, because max_pos will already
20393 have a much larger value. */
20394 if (CHARPOS (row
->end
.pos
) > max_pos
)
20395 INC_BOTH (max_pos
, max_bpos
);
20396 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20398 else if (CHARPOS (it
->eol_pos
) > 0)
20399 SET_TEXT_POS (row
->maxpos
,
20400 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
20401 else if (row
->continued_p
)
20403 /* If max_pos is different from IT's current position, it
20404 means IT->method does not belong to the display element
20405 at max_pos. However, it also means that the display
20406 element at max_pos was displayed in its entirety on this
20407 line, which is equivalent to saying that the next line
20408 starts at the next buffer position. */
20409 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
20410 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20413 INC_BOTH (max_pos
, max_bpos
);
20414 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20417 else if (row
->truncated_on_right_p
)
20418 /* display_line already called reseat_at_next_visible_line_start,
20419 which puts the iterator at the beginning of the next line, in
20420 the logical order. */
20421 row
->maxpos
= it
->current
.pos
;
20422 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
20423 /* A line that is entirely from a string/image/stretch... */
20424 row
->maxpos
= row
->minpos
;
20429 row
->maxpos
= it
->current
.pos
;
20432 /* Construct the glyph row IT->glyph_row in the desired matrix of
20433 IT->w from text at the current position of IT. See dispextern.h
20434 for an overview of struct it. Value is true if
20435 IT->glyph_row displays text, as opposed to a line displaying ZV
20439 display_line (struct it
*it
)
20441 struct glyph_row
*row
= it
->glyph_row
;
20442 Lisp_Object overlay_arrow_string
;
20444 void *wrap_data
= NULL
;
20445 bool may_wrap
= false;
20447 int wrap_row_used
= -1;
20448 int wrap_row_ascent UNINIT
, wrap_row_height UNINIT
;
20449 int wrap_row_phys_ascent UNINIT
, wrap_row_phys_height UNINIT
;
20450 int wrap_row_extra_line_spacing UNINIT
;
20451 ptrdiff_t wrap_row_min_pos UNINIT
, wrap_row_min_bpos UNINIT
;
20452 ptrdiff_t wrap_row_max_pos UNINIT
, wrap_row_max_bpos UNINIT
;
20454 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
20455 ptrdiff_t min_bpos UNINIT
, max_bpos UNINIT
;
20456 bool pending_handle_line_prefix
= false;
20458 /* We always start displaying at hpos zero even if hscrolled. */
20459 eassert (it
->hpos
== 0 && it
->current_x
== 0);
20461 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
20462 >= it
->w
->desired_matrix
->nrows
)
20464 it
->w
->nrows_scale_factor
++;
20465 it
->f
->fonts_changed
= true;
20469 /* Clear the result glyph row and enable it. */
20470 prepare_desired_row (it
->w
, row
, false);
20472 row
->y
= it
->current_y
;
20473 row
->start
= it
->start
;
20474 row
->continuation_lines_width
= it
->continuation_lines_width
;
20475 row
->displays_text_p
= true;
20476 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
20477 it
->starts_in_middle_of_char_p
= false;
20479 /* Arrange the overlays nicely for our purposes. Usually, we call
20480 display_line on only one line at a time, in which case this
20481 can't really hurt too much, or we call it on lines which appear
20482 one after another in the buffer, in which case all calls to
20483 recenter_overlay_lists but the first will be pretty cheap. */
20484 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
20486 /* Move over display elements that are not visible because we are
20487 hscrolled. This may stop at an x-position < IT->first_visible_x
20488 if the first glyph is partially visible or if we hit a line end. */
20489 if (it
->current_x
< it
->first_visible_x
)
20491 enum move_it_result move_result
;
20493 this_line_min_pos
= row
->start
.pos
;
20494 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
20495 MOVE_TO_POS
| MOVE_TO_X
);
20496 /* If we are under a large hscroll, move_it_in_display_line_to
20497 could hit the end of the line without reaching
20498 it->first_visible_x. Pretend that we did reach it. This is
20499 especially important on a TTY, where we will call
20500 extend_face_to_end_of_line, which needs to know how many
20501 blank glyphs to produce. */
20502 if (it
->current_x
< it
->first_visible_x
20503 && (move_result
== MOVE_NEWLINE_OR_CR
20504 || move_result
== MOVE_POS_MATCH_OR_ZV
))
20505 it
->current_x
= it
->first_visible_x
;
20507 /* Record the smallest positions seen while we moved over
20508 display elements that are not visible. This is needed by
20509 redisplay_internal for optimizing the case where the cursor
20510 stays inside the same line. The rest of this function only
20511 considers positions that are actually displayed, so
20512 RECORD_MAX_MIN_POS will not otherwise record positions that
20513 are hscrolled to the left of the left edge of the window. */
20514 min_pos
= CHARPOS (this_line_min_pos
);
20515 min_bpos
= BYTEPOS (this_line_min_pos
);
20517 else if (it
->area
== TEXT_AREA
)
20519 /* We only do this when not calling move_it_in_display_line_to
20520 above, because that function calls itself handle_line_prefix. */
20521 handle_line_prefix (it
);
20525 /* Line-prefix and wrap-prefix are always displayed in the text
20526 area. But if this is the first call to display_line after
20527 init_iterator, the iterator might have been set up to write
20528 into a marginal area, e.g. if the line begins with some
20529 display property that writes to the margins. So we need to
20530 wait with the call to handle_line_prefix until whatever
20531 writes to the margin has done its job. */
20532 pending_handle_line_prefix
= true;
20535 /* Get the initial row height. This is either the height of the
20536 text hscrolled, if there is any, or zero. */
20537 row
->ascent
= it
->max_ascent
;
20538 row
->height
= it
->max_ascent
+ it
->max_descent
;
20539 row
->phys_ascent
= it
->max_phys_ascent
;
20540 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20541 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20543 /* Utility macro to record max and min buffer positions seen until now. */
20544 #define RECORD_MAX_MIN_POS(IT) \
20547 bool composition_p \
20548 = !STRINGP ((IT)->string) && ((IT)->what == IT_COMPOSITION); \
20549 ptrdiff_t current_pos = \
20550 composition_p ? (IT)->cmp_it.charpos \
20551 : IT_CHARPOS (*(IT)); \
20552 ptrdiff_t current_bpos = \
20553 composition_p ? CHAR_TO_BYTE (current_pos) \
20554 : IT_BYTEPOS (*(IT)); \
20555 if (current_pos < min_pos) \
20557 min_pos = current_pos; \
20558 min_bpos = current_bpos; \
20560 if (IT_CHARPOS (*it) > max_pos) \
20562 max_pos = IT_CHARPOS (*it); \
20563 max_bpos = IT_BYTEPOS (*it); \
20568 /* Loop generating characters. The loop is left with IT on the next
20569 character to display. */
20572 int n_glyphs_before
, hpos_before
, x_before
;
20574 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
20576 /* Retrieve the next thing to display. Value is false if end of
20578 if (!get_next_display_element (it
))
20580 /* Maybe add a space at the end of this line that is used to
20581 display the cursor there under X. Set the charpos of the
20582 first glyph of blank lines not corresponding to any text
20584 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20585 row
->exact_window_width_line_p
= true;
20586 else if ((append_space_for_newline (it
, true)
20587 && row
->used
[TEXT_AREA
] == 1)
20588 || row
->used
[TEXT_AREA
] == 0)
20590 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
20591 row
->displays_text_p
= false;
20593 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
20594 && (!MINI_WINDOW_P (it
->w
)
20595 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
20596 row
->indicate_empty_line_p
= true;
20599 it
->continuation_lines_width
= 0;
20600 row
->ends_at_zv_p
= true;
20601 /* A row that displays right-to-left text must always have
20602 its last face extended all the way to the end of line,
20603 even if this row ends in ZV, because we still write to
20604 the screen left to right. We also need to extend the
20605 last face if the default face is remapped to some
20606 different face, otherwise the functions that clear
20607 portions of the screen will clear with the default face's
20608 background color. */
20609 if (row
->reversed_p
20610 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
20611 extend_face_to_end_of_line (it
);
20615 /* Now, get the metrics of what we want to display. This also
20616 generates glyphs in `row' (which is IT->glyph_row). */
20617 n_glyphs_before
= row
->used
[TEXT_AREA
];
20620 /* Remember the line height so far in case the next element doesn't
20621 fit on the line. */
20622 if (it
->line_wrap
!= TRUNCATE
)
20624 ascent
= it
->max_ascent
;
20625 descent
= it
->max_descent
;
20626 phys_ascent
= it
->max_phys_ascent
;
20627 phys_descent
= it
->max_phys_descent
;
20629 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
20631 if (IT_DISPLAYING_WHITESPACE (it
))
20635 SAVE_IT (wrap_it
, *it
, wrap_data
);
20637 wrap_row_used
= row
->used
[TEXT_AREA
];
20638 wrap_row_ascent
= row
->ascent
;
20639 wrap_row_height
= row
->height
;
20640 wrap_row_phys_ascent
= row
->phys_ascent
;
20641 wrap_row_phys_height
= row
->phys_height
;
20642 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
20643 wrap_row_min_pos
= min_pos
;
20644 wrap_row_min_bpos
= min_bpos
;
20645 wrap_row_max_pos
= max_pos
;
20646 wrap_row_max_bpos
= max_bpos
;
20652 PRODUCE_GLYPHS (it
);
20654 /* If this display element was in marginal areas, continue with
20656 if (it
->area
!= TEXT_AREA
)
20658 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20659 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20660 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20661 row
->phys_height
= max (row
->phys_height
,
20662 it
->max_phys_ascent
+ it
->max_phys_descent
);
20663 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20664 it
->max_extra_line_spacing
);
20665 set_iterator_to_next (it
, true);
20666 /* If we didn't handle the line/wrap prefix above, and the
20667 call to set_iterator_to_next just switched to TEXT_AREA,
20668 process the prefix now. */
20669 if (it
->area
== TEXT_AREA
&& pending_handle_line_prefix
)
20671 pending_handle_line_prefix
= false;
20672 handle_line_prefix (it
);
20677 /* Does the display element fit on the line? If we truncate
20678 lines, we should draw past the right edge of the window. If
20679 we don't truncate, we want to stop so that we can display the
20680 continuation glyph before the right margin. If lines are
20681 continued, there are two possible strategies for characters
20682 resulting in more than 1 glyph (e.g. tabs): Display as many
20683 glyphs as possible in this line and leave the rest for the
20684 continuation line, or display the whole element in the next
20685 line. Original redisplay did the former, so we do it also. */
20686 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20687 hpos_before
= it
->hpos
;
20690 if (/* Not a newline. */
20692 /* Glyphs produced fit entirely in the line. */
20693 && it
->current_x
< it
->last_visible_x
)
20695 it
->hpos
+= nglyphs
;
20696 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20697 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20698 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20699 row
->phys_height
= max (row
->phys_height
,
20700 it
->max_phys_ascent
+ it
->max_phys_descent
);
20701 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20702 it
->max_extra_line_spacing
);
20703 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
20704 /* In R2L rows, we arrange in extend_face_to_end_of_line
20705 to add a right offset to the line, by a suitable
20706 change to the stretch glyph that is the leftmost
20707 glyph of the line. */
20708 && !row
->reversed_p
)
20709 row
->x
= x
- it
->first_visible_x
;
20710 /* Record the maximum and minimum buffer positions seen so
20711 far in glyphs that will be displayed by this row. */
20713 RECORD_MAX_MIN_POS (it
);
20718 struct glyph
*glyph
;
20720 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
20722 /* Identify the glyphs added by the last call to
20723 PRODUCE_GLYPHS. In R2L rows, they are prepended to
20724 the previous glyphs. */
20725 if (!row
->reversed_p
)
20726 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20728 glyph
= row
->glyphs
[TEXT_AREA
] + nglyphs
- 1 - i
;
20729 new_x
= x
+ glyph
->pixel_width
;
20731 if (/* Lines are continued. */
20732 it
->line_wrap
!= TRUNCATE
20733 && (/* Glyph doesn't fit on the line. */
20734 new_x
> it
->last_visible_x
20735 /* Or it fits exactly on a window system frame. */
20736 || (new_x
== it
->last_visible_x
20737 && FRAME_WINDOW_P (it
->f
)
20738 && (row
->reversed_p
20739 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20740 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
20742 /* End of a continued line. */
20745 || (new_x
== it
->last_visible_x
20746 && FRAME_WINDOW_P (it
->f
)
20747 && (row
->reversed_p
20748 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20749 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
20751 /* Current glyph is the only one on the line or
20752 fits exactly on the line. We must continue
20753 the line because we can't draw the cursor
20754 after the glyph. */
20755 row
->continued_p
= true;
20756 it
->current_x
= new_x
;
20757 it
->continuation_lines_width
+= new_x
;
20759 if (i
== nglyphs
- 1)
20761 /* If line-wrap is on, check if a previous
20762 wrap point was found. */
20763 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)
20764 && wrap_row_used
> 0
20765 /* Even if there is a previous wrap
20766 point, continue the line here as
20767 usual, if (i) the previous character
20768 was a space or tab AND (ii) the
20769 current character is not. */
20771 || IT_DISPLAYING_WHITESPACE (it
)))
20774 /* Record the maximum and minimum buffer
20775 positions seen so far in glyphs that will be
20776 displayed by this row. */
20778 RECORD_MAX_MIN_POS (it
);
20779 set_iterator_to_next (it
, true);
20780 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20782 if (!get_next_display_element (it
))
20784 row
->exact_window_width_line_p
= true;
20785 it
->continuation_lines_width
= 0;
20786 row
->continued_p
= false;
20787 row
->ends_at_zv_p
= true;
20789 else if (ITERATOR_AT_END_OF_LINE_P (it
))
20791 row
->continued_p
= false;
20792 row
->exact_window_width_line_p
= true;
20794 /* If line-wrap is on, check if a
20795 previous wrap point was found. */
20796 else if (wrap_row_used
> 0
20797 /* Even if there is a previous wrap
20798 point, continue the line here as
20799 usual, if (i) the previous character
20800 was a space or tab AND (ii) the
20801 current character is not. */
20803 || IT_DISPLAYING_WHITESPACE (it
)))
20808 else if (it
->bidi_p
)
20809 RECORD_MAX_MIN_POS (it
);
20810 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20811 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20812 extend_face_to_end_of_line (it
);
20814 else if (CHAR_GLYPH_PADDING_P (*glyph
)
20815 && !FRAME_WINDOW_P (it
->f
))
20817 /* A padding glyph that doesn't fit on this line.
20818 This means the whole character doesn't fit
20820 if (row
->reversed_p
)
20821 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20822 - n_glyphs_before
);
20823 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20825 /* Fill the rest of the row with continuation
20826 glyphs like in 20.x. */
20827 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
20828 < row
->glyphs
[1 + TEXT_AREA
])
20829 produce_special_glyphs (it
, IT_CONTINUATION
);
20831 row
->continued_p
= true;
20832 it
->current_x
= x_before
;
20833 it
->continuation_lines_width
+= x_before
;
20835 /* Restore the height to what it was before the
20836 element not fitting on the line. */
20837 it
->max_ascent
= ascent
;
20838 it
->max_descent
= descent
;
20839 it
->max_phys_ascent
= phys_ascent
;
20840 it
->max_phys_descent
= phys_descent
;
20841 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20842 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20843 extend_face_to_end_of_line (it
);
20845 else if (wrap_row_used
> 0)
20848 if (row
->reversed_p
)
20849 unproduce_glyphs (it
,
20850 row
->used
[TEXT_AREA
] - wrap_row_used
);
20851 RESTORE_IT (it
, &wrap_it
, wrap_data
);
20852 it
->continuation_lines_width
+= wrap_x
;
20853 row
->used
[TEXT_AREA
] = wrap_row_used
;
20854 row
->ascent
= wrap_row_ascent
;
20855 row
->height
= wrap_row_height
;
20856 row
->phys_ascent
= wrap_row_phys_ascent
;
20857 row
->phys_height
= wrap_row_phys_height
;
20858 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
20859 min_pos
= wrap_row_min_pos
;
20860 min_bpos
= wrap_row_min_bpos
;
20861 max_pos
= wrap_row_max_pos
;
20862 max_bpos
= wrap_row_max_bpos
;
20863 row
->continued_p
= true;
20864 row
->ends_at_zv_p
= false;
20865 row
->exact_window_width_line_p
= false;
20866 it
->continuation_lines_width
+= x
;
20868 /* Make sure that a non-default face is extended
20869 up to the right margin of the window. */
20870 extend_face_to_end_of_line (it
);
20872 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
20874 /* A TAB that extends past the right edge of the
20875 window. This produces a single glyph on
20876 window system frames. We leave the glyph in
20877 this row and let it fill the row, but don't
20878 consume the TAB. */
20879 if ((row
->reversed_p
20880 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20881 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20882 produce_special_glyphs (it
, IT_CONTINUATION
);
20883 it
->continuation_lines_width
+= it
->last_visible_x
;
20884 row
->ends_in_middle_of_char_p
= true;
20885 row
->continued_p
= true;
20886 glyph
->pixel_width
= it
->last_visible_x
- x
;
20887 it
->starts_in_middle_of_char_p
= true;
20888 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20889 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20890 extend_face_to_end_of_line (it
);
20894 /* Something other than a TAB that draws past
20895 the right edge of the window. Restore
20896 positions to values before the element. */
20897 if (row
->reversed_p
)
20898 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20899 - (n_glyphs_before
+ i
));
20900 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20902 /* Display continuation glyphs. */
20903 it
->current_x
= x_before
;
20904 it
->continuation_lines_width
+= x
;
20905 if (!FRAME_WINDOW_P (it
->f
)
20906 || (row
->reversed_p
20907 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20908 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20909 produce_special_glyphs (it
, IT_CONTINUATION
);
20910 row
->continued_p
= true;
20912 extend_face_to_end_of_line (it
);
20914 if (nglyphs
> 1 && i
> 0)
20916 row
->ends_in_middle_of_char_p
= true;
20917 it
->starts_in_middle_of_char_p
= true;
20920 /* Restore the height to what it was before the
20921 element not fitting on the line. */
20922 it
->max_ascent
= ascent
;
20923 it
->max_descent
= descent
;
20924 it
->max_phys_ascent
= phys_ascent
;
20925 it
->max_phys_descent
= phys_descent
;
20930 else if (new_x
> it
->first_visible_x
)
20932 /* Increment number of glyphs actually displayed. */
20935 /* Record the maximum and minimum buffer positions
20936 seen so far in glyphs that will be displayed by
20939 RECORD_MAX_MIN_POS (it
);
20941 if (x
< it
->first_visible_x
&& !row
->reversed_p
)
20942 /* Glyph is partially visible, i.e. row starts at
20943 negative X position. Don't do that in R2L
20944 rows, where we arrange to add a right offset to
20945 the line in extend_face_to_end_of_line, by a
20946 suitable change to the stretch glyph that is
20947 the leftmost glyph of the line. */
20948 row
->x
= x
- it
->first_visible_x
;
20949 /* When the last glyph of an R2L row only fits
20950 partially on the line, we need to set row->x to a
20951 negative offset, so that the leftmost glyph is
20952 the one that is partially visible. But if we are
20953 going to produce the truncation glyph, this will
20954 be taken care of in produce_special_glyphs. */
20955 if (row
->reversed_p
20956 && new_x
> it
->last_visible_x
20957 && !(it
->line_wrap
== TRUNCATE
20958 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
20960 eassert (FRAME_WINDOW_P (it
->f
));
20961 row
->x
= it
->last_visible_x
- new_x
;
20966 /* Glyph is completely off the left margin of the
20967 window. This should not happen because of the
20968 move_it_in_display_line at the start of this
20969 function, unless the text display area of the
20970 window is empty. */
20971 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20974 /* Even if this display element produced no glyphs at all,
20975 we want to record its position. */
20976 if (it
->bidi_p
&& nglyphs
== 0)
20977 RECORD_MAX_MIN_POS (it
);
20979 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20980 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20981 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20982 row
->phys_height
= max (row
->phys_height
,
20983 it
->max_phys_ascent
+ it
->max_phys_descent
);
20984 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20985 it
->max_extra_line_spacing
);
20987 /* End of this display line if row is continued. */
20988 if (row
->continued_p
|| row
->ends_at_zv_p
)
20993 /* Is this a line end? If yes, we're also done, after making
20994 sure that a non-default face is extended up to the right
20995 margin of the window. */
20996 if (ITERATOR_AT_END_OF_LINE_P (it
))
20998 int used_before
= row
->used
[TEXT_AREA
];
21000 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
21002 /* Add a space at the end of the line that is used to
21003 display the cursor there. */
21004 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
21005 append_space_for_newline (it
, false);
21007 /* Extend the face to the end of the line. */
21008 extend_face_to_end_of_line (it
);
21010 /* Make sure we have the position. */
21011 if (used_before
== 0)
21012 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
21014 /* Record the position of the newline, for use in
21016 it
->eol_pos
= it
->current
.pos
;
21018 /* Consume the line end. This skips over invisible lines. */
21019 set_iterator_to_next (it
, true);
21020 it
->continuation_lines_width
= 0;
21024 /* Proceed with next display element. Note that this skips
21025 over lines invisible because of selective display. */
21026 set_iterator_to_next (it
, true);
21028 /* If we truncate lines, we are done when the last displayed
21029 glyphs reach past the right margin of the window. */
21030 if (it
->line_wrap
== TRUNCATE
21031 && ((FRAME_WINDOW_P (it
->f
)
21032 /* Images are preprocessed in produce_image_glyph such
21033 that they are cropped at the right edge of the
21034 window, so an image glyph will always end exactly at
21035 last_visible_x, even if there's no right fringe. */
21036 && ((row
->reversed_p
21037 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
21038 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))
21039 || it
->what
== IT_IMAGE
))
21040 ? (it
->current_x
>= it
->last_visible_x
)
21041 : (it
->current_x
> it
->last_visible_x
)))
21043 /* Maybe add truncation glyphs. */
21044 if (!FRAME_WINDOW_P (it
->f
)
21045 || (row
->reversed_p
21046 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
21047 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
21051 if (!row
->reversed_p
)
21053 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
21054 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
21059 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
21060 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
21062 /* Remove any padding glyphs at the front of ROW, to
21063 make room for the truncation glyphs we will be
21064 adding below. The loop below always inserts at
21065 least one truncation glyph, so also remove the
21066 last glyph added to ROW. */
21067 unproduce_glyphs (it
, i
+ 1);
21068 /* Adjust i for the loop below. */
21069 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
21072 /* produce_special_glyphs overwrites the last glyph, so
21073 we don't want that if we want to keep that last
21074 glyph, which means it's an image. */
21075 if (it
->current_x
> it
->last_visible_x
)
21077 it
->current_x
= x_before
;
21078 if (!FRAME_WINDOW_P (it
->f
))
21080 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
21082 row
->used
[TEXT_AREA
] = i
;
21083 produce_special_glyphs (it
, IT_TRUNCATION
);
21088 row
->used
[TEXT_AREA
] = i
;
21089 produce_special_glyphs (it
, IT_TRUNCATION
);
21091 it
->hpos
= hpos_before
;
21094 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
21096 /* Don't truncate if we can overflow newline into fringe. */
21097 if (!get_next_display_element (it
))
21099 it
->continuation_lines_width
= 0;
21100 row
->ends_at_zv_p
= true;
21101 row
->exact_window_width_line_p
= true;
21104 if (ITERATOR_AT_END_OF_LINE_P (it
))
21106 row
->exact_window_width_line_p
= true;
21107 goto at_end_of_line
;
21109 it
->current_x
= x_before
;
21110 it
->hpos
= hpos_before
;
21113 row
->truncated_on_right_p
= true;
21114 it
->continuation_lines_width
= 0;
21115 reseat_at_next_visible_line_start (it
, false);
21116 /* We insist below that IT's position be at ZV because in
21117 bidi-reordered lines the character at visible line start
21118 might not be the character that follows the newline in
21119 the logical order. */
21120 if (IT_BYTEPOS (*it
) > BEG_BYTE
)
21121 row
->ends_at_zv_p
=
21122 IT_BYTEPOS (*it
) >= ZV_BYTE
&& FETCH_BYTE (ZV_BYTE
- 1) != '\n';
21124 row
->ends_at_zv_p
= false;
21130 bidi_unshelve_cache (wrap_data
, true);
21132 /* If line is not empty and hscrolled, maybe insert truncation glyphs
21133 at the left window margin. */
21134 if (it
->first_visible_x
21135 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
21137 if (!FRAME_WINDOW_P (it
->f
)
21138 || (((row
->reversed_p
21139 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21140 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
21141 /* Don't let insert_left_trunc_glyphs overwrite the
21142 first glyph of the row if it is an image. */
21143 && row
->glyphs
[TEXT_AREA
]->type
!= IMAGE_GLYPH
))
21144 insert_left_trunc_glyphs (it
);
21145 row
->truncated_on_left_p
= true;
21148 /* Remember the position at which this line ends.
21150 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
21151 cannot be before the call to find_row_edges below, since that is
21152 where these positions are determined. */
21153 row
->end
= it
->current
;
21156 row
->minpos
= row
->start
.pos
;
21157 row
->maxpos
= row
->end
.pos
;
21161 /* ROW->minpos and ROW->maxpos must be the smallest and
21162 `1 + the largest' buffer positions in ROW. But if ROW was
21163 bidi-reordered, these two positions can be anywhere in the
21164 row, so we must determine them now. */
21165 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
21168 /* If the start of this line is the overlay arrow-position, then
21169 mark this glyph row as the one containing the overlay arrow.
21170 This is clearly a mess with variable size fonts. It would be
21171 better to let it be displayed like cursors under X. */
21172 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
21173 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
21174 !NILP (overlay_arrow_string
)))
21176 /* Overlay arrow in window redisplay is a fringe bitmap. */
21177 if (STRINGP (overlay_arrow_string
))
21179 struct glyph_row
*arrow_row
21180 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
21181 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
21182 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
21183 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
21184 struct glyph
*p2
, *end
;
21186 /* Copy the arrow glyphs. */
21187 while (glyph
< arrow_end
)
21190 /* Throw away padding glyphs. */
21192 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
21193 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
21199 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
21204 eassert (INTEGERP (overlay_arrow_string
));
21205 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
21207 overlay_arrow_seen
= true;
21210 /* Highlight trailing whitespace. */
21211 if (!NILP (Vshow_trailing_whitespace
))
21212 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
21214 /* Compute pixel dimensions of this line. */
21215 compute_line_metrics (it
);
21217 /* Implementation note: No changes in the glyphs of ROW or in their
21218 faces can be done past this point, because compute_line_metrics
21219 computes ROW's hash value and stores it within the glyph_row
21222 /* Record whether this row ends inside an ellipsis. */
21223 row
->ends_in_ellipsis_p
21224 = (it
->method
== GET_FROM_DISPLAY_VECTOR
21225 && it
->ellipsis_p
);
21227 /* Save fringe bitmaps in this row. */
21228 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
21229 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
21230 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
21231 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
21233 it
->left_user_fringe_bitmap
= 0;
21234 it
->left_user_fringe_face_id
= 0;
21235 it
->right_user_fringe_bitmap
= 0;
21236 it
->right_user_fringe_face_id
= 0;
21238 /* Maybe set the cursor. */
21239 cvpos
= it
->w
->cursor
.vpos
;
21241 /* In bidi-reordered rows, keep checking for proper cursor
21242 position even if one has been found already, because buffer
21243 positions in such rows change non-linearly with ROW->VPOS,
21244 when a line is continued. One exception: when we are at ZV,
21245 display cursor on the first suitable glyph row, since all
21246 the empty rows after that also have their position set to ZV. */
21247 /* FIXME: Revisit this when glyph ``spilling'' in continuation
21248 lines' rows is implemented for bidi-reordered rows. */
21250 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
21251 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
21252 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
21253 && cursor_row_p (row
))
21254 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
21256 /* Prepare for the next line. This line starts horizontally at (X
21257 HPOS) = (0 0). Vertical positions are incremented. As a
21258 convenience for the caller, IT->glyph_row is set to the next
21260 it
->current_x
= it
->hpos
= 0;
21261 it
->current_y
+= row
->height
;
21262 SET_TEXT_POS (it
->eol_pos
, 0, 0);
21265 /* The next row should by default use the same value of the
21266 reversed_p flag as this one. set_iterator_to_next decides when
21267 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
21268 the flag accordingly. */
21269 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
21270 it
->glyph_row
->reversed_p
= row
->reversed_p
;
21271 it
->start
= row
->end
;
21272 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
21274 #undef RECORD_MAX_MIN_POS
21277 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
21278 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
21279 doc
: /* Return paragraph direction at point in BUFFER.
21280 Value is either `left-to-right' or `right-to-left'.
21281 If BUFFER is omitted or nil, it defaults to the current buffer.
21283 Paragraph direction determines how the text in the paragraph is displayed.
21284 In left-to-right paragraphs, text begins at the left margin of the window
21285 and the reading direction is generally left to right. In right-to-left
21286 paragraphs, text begins at the right margin and is read from right to left.
21288 See also `bidi-paragraph-direction'. */)
21289 (Lisp_Object buffer
)
21291 struct buffer
*buf
= current_buffer
;
21292 struct buffer
*old
= buf
;
21294 if (! NILP (buffer
))
21296 CHECK_BUFFER (buffer
);
21297 buf
= XBUFFER (buffer
);
21300 if (NILP (BVAR (buf
, bidi_display_reordering
))
21301 || NILP (BVAR (buf
, enable_multibyte_characters
))
21302 /* When we are loading loadup.el, the character property tables
21303 needed for bidi iteration are not yet available. */
21304 || redisplay__inhibit_bidi
)
21305 return Qleft_to_right
;
21306 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
21307 return BVAR (buf
, bidi_paragraph_direction
);
21310 /* Determine the direction from buffer text. We could try to
21311 use current_matrix if it is up to date, but this seems fast
21312 enough as it is. */
21313 struct bidi_it itb
;
21314 ptrdiff_t pos
= BUF_PT (buf
);
21315 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
21317 void *itb_data
= bidi_shelve_cache ();
21319 set_buffer_temp (buf
);
21320 /* bidi_paragraph_init finds the base direction of the paragraph
21321 by searching forward from paragraph start. We need the base
21322 direction of the current or _previous_ paragraph, so we need
21323 to make sure we are within that paragraph. To that end, find
21324 the previous non-empty line. */
21325 if (pos
>= ZV
&& pos
> BEGV
)
21326 DEC_BOTH (pos
, bytepos
);
21327 AUTO_STRING (trailing_white_space
, "[\f\t ]*\n");
21328 if (fast_looking_at (trailing_white_space
,
21329 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
21331 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
21332 || c
== ' ' || c
== '\t' || c
== '\f')
21334 if (bytepos
<= BEGV_BYTE
)
21339 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
21342 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
21343 itb
.paragraph_dir
= NEUTRAL_DIR
;
21344 itb
.string
.s
= NULL
;
21345 itb
.string
.lstring
= Qnil
;
21346 itb
.string
.bufpos
= 0;
21347 itb
.string
.from_disp_str
= false;
21348 itb
.string
.unibyte
= false;
21349 /* We have no window to use here for ignoring window-specific
21350 overlays. Using NULL for window pointer will cause
21351 compute_display_string_pos to use the current buffer. */
21353 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, true);
21354 bidi_unshelve_cache (itb_data
, false);
21355 set_buffer_temp (old
);
21356 switch (itb
.paragraph_dir
)
21359 return Qleft_to_right
;
21362 return Qright_to_left
;
21370 DEFUN ("bidi-find-overridden-directionality",
21371 Fbidi_find_overridden_directionality
,
21372 Sbidi_find_overridden_directionality
, 2, 3, 0,
21373 doc
: /* Return position between FROM and TO where directionality was overridden.
21375 This function returns the first character position in the specified
21376 region of OBJECT where there is a character whose `bidi-class' property
21377 is `L', but which was forced to display as `R' by a directional
21378 override, and likewise with characters whose `bidi-class' is `R'
21379 or `AL' that were forced to display as `L'.
21381 If no such character is found, the function returns nil.
21383 OBJECT is a Lisp string or buffer to search for overridden
21384 directionality, and defaults to the current buffer if nil or omitted.
21385 OBJECT can also be a window, in which case the function will search
21386 the buffer displayed in that window. Passing the window instead of
21387 a buffer is preferable when the buffer is displayed in some window,
21388 because this function will then be able to correctly account for
21389 window-specific overlays, which can affect the results.
21391 Strong directional characters `L', `R', and `AL' can have their
21392 intrinsic directionality overridden by directional override
21393 control characters RLO (u+202e) and LRO (u+202d). See the
21394 function `get-char-code-property' for a way to inquire about
21395 the `bidi-class' property of a character. */)
21396 (Lisp_Object from
, Lisp_Object to
, Lisp_Object object
)
21398 struct buffer
*buf
= current_buffer
;
21399 struct buffer
*old
= buf
;
21400 struct window
*w
= NULL
;
21401 bool frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ());
21402 struct bidi_it itb
;
21403 ptrdiff_t from_pos
, to_pos
, from_bpos
;
21406 if (!NILP (object
))
21408 if (BUFFERP (object
))
21409 buf
= XBUFFER (object
);
21410 else if (WINDOWP (object
))
21412 w
= decode_live_window (object
);
21413 buf
= XBUFFER (w
->contents
);
21414 frame_window_p
= FRAME_WINDOW_P (XFRAME (w
->frame
));
21417 CHECK_STRING (object
);
21420 if (STRINGP (object
))
21422 /* Characters in unibyte strings are always treated by bidi.c as
21424 if (!STRING_MULTIBYTE (object
)
21425 /* When we are loading loadup.el, the character property
21426 tables needed for bidi iteration are not yet
21428 || redisplay__inhibit_bidi
)
21431 validate_subarray (object
, from
, to
, SCHARS (object
), &from_pos
, &to_pos
);
21432 if (from_pos
>= SCHARS (object
))
21435 /* Set up the bidi iterator. */
21436 itb_data
= bidi_shelve_cache ();
21437 itb
.paragraph_dir
= NEUTRAL_DIR
;
21438 itb
.string
.lstring
= object
;
21439 itb
.string
.s
= NULL
;
21440 itb
.string
.schars
= SCHARS (object
);
21441 itb
.string
.bufpos
= 0;
21442 itb
.string
.from_disp_str
= false;
21443 itb
.string
.unibyte
= false;
21445 bidi_init_it (0, 0, frame_window_p
, &itb
);
21449 /* Nothing this fancy can happen in unibyte buffers, or in a
21450 buffer that disabled reordering, or if FROM is at EOB. */
21451 if (NILP (BVAR (buf
, bidi_display_reordering
))
21452 || NILP (BVAR (buf
, enable_multibyte_characters
))
21453 /* When we are loading loadup.el, the character property
21454 tables needed for bidi iteration are not yet
21456 || redisplay__inhibit_bidi
)
21459 set_buffer_temp (buf
);
21460 validate_region (&from
, &to
);
21461 from_pos
= XINT (from
);
21462 to_pos
= XINT (to
);
21463 if (from_pos
>= ZV
)
21466 /* Set up the bidi iterator. */
21467 itb_data
= bidi_shelve_cache ();
21468 from_bpos
= CHAR_TO_BYTE (from_pos
);
21469 if (from_pos
== BEGV
)
21471 itb
.charpos
= BEGV
;
21472 itb
.bytepos
= BEGV_BYTE
;
21474 else if (FETCH_CHAR (from_bpos
- 1) == '\n')
21476 itb
.charpos
= from_pos
;
21477 itb
.bytepos
= from_bpos
;
21480 itb
.charpos
= find_newline_no_quit (from_pos
, CHAR_TO_BYTE (from_pos
),
21482 itb
.paragraph_dir
= NEUTRAL_DIR
;
21483 itb
.string
.s
= NULL
;
21484 itb
.string
.lstring
= Qnil
;
21485 itb
.string
.bufpos
= 0;
21486 itb
.string
.from_disp_str
= false;
21487 itb
.string
.unibyte
= false;
21489 bidi_init_it (itb
.charpos
, itb
.bytepos
, frame_window_p
, &itb
);
21494 /* For the purposes of this function, the actual base direction of
21495 the paragraph doesn't matter, so just set it to L2R. */
21496 bidi_paragraph_init (L2R
, &itb
, false);
21497 while ((found
= bidi_find_first_overridden (&itb
)) < from_pos
)
21499 } while (found
== ZV
&& itb
.ch
== '\n' && itb
.charpos
< to_pos
);
21501 bidi_unshelve_cache (itb_data
, false);
21502 set_buffer_temp (old
);
21504 return (from_pos
<= found
&& found
< to_pos
) ? make_number (found
) : Qnil
;
21507 DEFUN ("move-point-visually", Fmove_point_visually
,
21508 Smove_point_visually
, 1, 1, 0,
21509 doc
: /* Move point in the visual order in the specified DIRECTION.
21510 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
21513 Value is the new character position of point. */)
21514 (Lisp_Object direction
)
21516 struct window
*w
= XWINDOW (selected_window
);
21517 struct buffer
*b
= XBUFFER (w
->contents
);
21518 struct glyph_row
*row
;
21520 Lisp_Object paragraph_dir
;
21522 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
21523 (!(ROW)->continued_p \
21524 && NILP ((GLYPH)->object) \
21525 && (GLYPH)->type == CHAR_GLYPH \
21526 && (GLYPH)->u.ch == ' ' \
21527 && (GLYPH)->charpos >= 0 \
21528 && !(GLYPH)->avoid_cursor_p)
21530 CHECK_NUMBER (direction
);
21531 dir
= XINT (direction
);
21537 /* If current matrix is up-to-date, we can use the information
21538 recorded in the glyphs, at least as long as the goal is on the
21540 if (w
->window_end_valid
21541 && !windows_or_buffers_changed
21543 && !b
->clip_changed
21544 && !b
->prevent_redisplay_optimizations_p
21545 && !window_outdated (w
)
21546 /* We rely below on the cursor coordinates to be up to date, but
21547 we cannot trust them if some command moved point since the
21548 last complete redisplay. */
21549 && w
->last_point
== BUF_PT (b
)
21550 && w
->cursor
.vpos
>= 0
21551 && w
->cursor
.vpos
< w
->current_matrix
->nrows
21552 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
21554 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
21555 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
21556 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
21558 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
21560 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
21562 SET_PT (g
->charpos
);
21563 w
->cursor
.vpos
= -1;
21564 return make_number (PT
);
21566 else if (!NILP (g
->object
) && !EQ (g
->object
, gpt
->object
))
21570 if (BUFFERP (gpt
->object
))
21573 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
21574 new_pos
+= (row
->reversed_p
? -dir
: dir
);
21576 new_pos
-= (row
->reversed_p
? -dir
: dir
);
21578 else if (BUFFERP (g
->object
))
21579 new_pos
= g
->charpos
;
21583 w
->cursor
.vpos
= -1;
21584 return make_number (PT
);
21586 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
21588 /* Glyphs inserted at the end of a non-empty line for
21589 positioning the cursor have zero charpos, so we must
21590 deduce the value of point by other means. */
21591 if (g
->charpos
> 0)
21592 SET_PT (g
->charpos
);
21593 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
21595 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
21596 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21599 w
->cursor
.vpos
= -1;
21600 return make_number (PT
);
21603 if (g
== e
|| NILP (g
->object
))
21605 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
21606 goto simulate_display
;
21607 if (!row
->reversed_p
)
21611 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
21612 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
21613 goto simulate_display
;
21617 if (row
->reversed_p
&& !row
->continued_p
)
21619 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21620 w
->cursor
.vpos
= -1;
21621 return make_number (PT
);
21623 g
= row
->glyphs
[TEXT_AREA
];
21624 e
= g
+ row
->used
[TEXT_AREA
];
21625 for ( ; g
< e
; g
++)
21627 if (BUFFERP (g
->object
)
21628 /* Empty lines have only one glyph, which stands
21629 for the newline, and whose charpos is the
21630 buffer position of the newline. */
21631 || ROW_GLYPH_NEWLINE_P (row
, g
)
21632 /* When the buffer ends in a newline, the line at
21633 EOB also has one glyph, but its charpos is -1. */
21634 || (row
->ends_at_zv_p
21635 && !row
->reversed_p
21636 && NILP (g
->object
)
21637 && g
->type
== CHAR_GLYPH
21638 && g
->u
.ch
== ' '))
21640 if (g
->charpos
> 0)
21641 SET_PT (g
->charpos
);
21642 else if (!row
->reversed_p
21643 && row
->ends_at_zv_p
21648 w
->cursor
.vpos
= -1;
21649 return make_number (PT
);
21655 if (!row
->reversed_p
&& !row
->continued_p
)
21657 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21658 w
->cursor
.vpos
= -1;
21659 return make_number (PT
);
21661 e
= row
->glyphs
[TEXT_AREA
];
21662 g
= e
+ row
->used
[TEXT_AREA
] - 1;
21663 for ( ; g
>= e
; g
--)
21665 if (BUFFERP (g
->object
)
21666 || (ROW_GLYPH_NEWLINE_P (row
, g
)
21668 /* Empty R2L lines on GUI frames have the buffer
21669 position of the newline stored in the stretch
21671 || g
->type
== STRETCH_GLYPH
21672 || (row
->ends_at_zv_p
21674 && NILP (g
->object
)
21675 && g
->type
== CHAR_GLYPH
21676 && g
->u
.ch
== ' '))
21678 if (g
->charpos
> 0)
21679 SET_PT (g
->charpos
);
21680 else if (row
->reversed_p
21681 && row
->ends_at_zv_p
21686 w
->cursor
.vpos
= -1;
21687 return make_number (PT
);
21696 /* If we wind up here, we failed to move by using the glyphs, so we
21697 need to simulate display instead. */
21700 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
21702 paragraph_dir
= Qleft_to_right
;
21703 if (EQ (paragraph_dir
, Qright_to_left
))
21705 if (PT
<= BEGV
&& dir
< 0)
21706 xsignal0 (Qbeginning_of_buffer
);
21707 else if (PT
>= ZV
&& dir
> 0)
21708 xsignal0 (Qend_of_buffer
);
21711 struct text_pos pt
;
21713 int pt_x
, target_x
, pixel_width
, pt_vpos
;
21715 bool overshoot_expected
= false;
21716 bool target_is_eol_p
= false;
21718 /* Setup the arena. */
21719 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
21720 start_display (&it
, w
, pt
);
21721 /* When lines are truncated, we could be called with point
21722 outside of the windows edges, in which case move_it_*
21723 functions either prematurely stop at window's edge or jump to
21724 the next screen line, whereas we rely below on our ability to
21725 reach point, in order to start from its X coordinate. So we
21726 need to disregard the window's horizontal extent in that case. */
21727 if (it
.line_wrap
== TRUNCATE
)
21728 it
.last_visible_x
= INFINITY
;
21730 if (it
.cmp_it
.id
< 0
21731 && it
.method
== GET_FROM_STRING
21732 && it
.area
== TEXT_AREA
21733 && it
.string_from_display_prop_p
21734 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
21735 overshoot_expected
= true;
21737 /* Find the X coordinate of point. We start from the beginning
21738 of this or previous line to make sure we are before point in
21739 the logical order (since the move_it_* functions can only
21742 reseat_at_previous_visible_line_start (&it
);
21743 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
21744 if (IT_CHARPOS (it
) != PT
)
21746 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
21747 -1, -1, -1, MOVE_TO_POS
);
21748 /* If we missed point because the character there is
21749 displayed out of a display vector that has more than one
21750 glyph, retry expecting overshoot. */
21751 if (it
.method
== GET_FROM_DISPLAY_VECTOR
21752 && it
.current
.dpvec_index
> 0
21753 && !overshoot_expected
)
21755 overshoot_expected
= true;
21758 else if (IT_CHARPOS (it
) != PT
&& !overshoot_expected
)
21759 move_it_in_display_line (&it
, PT
, -1, MOVE_TO_POS
);
21761 pt_x
= it
.current_x
;
21763 if (dir
> 0 || overshoot_expected
)
21765 struct glyph_row
*row
= it
.glyph_row
;
21767 /* When point is at beginning of line, we don't have
21768 information about the glyph there loaded into struct
21769 it. Calling get_next_display_element fixes that. */
21771 get_next_display_element (&it
);
21772 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21773 it
.glyph_row
= NULL
;
21774 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
21775 it
.glyph_row
= row
;
21776 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
21777 it, lest it will become out of sync with it's buffer
21779 it
.current_x
= pt_x
;
21782 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21783 pixel_width
= it
.pixel_width
;
21784 if (overshoot_expected
&& at_eol_p
)
21786 else if (pixel_width
<= 0)
21789 /* If there's a display string (or something similar) at point,
21790 we are actually at the glyph to the left of point, so we need
21791 to correct the X coordinate. */
21792 if (overshoot_expected
)
21795 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
21797 pt_x
+= pixel_width
;
21800 /* Compute target X coordinate, either to the left or to the
21801 right of point. On TTY frames, all characters have the same
21802 pixel width of 1, so we can use that. On GUI frames we don't
21803 have an easy way of getting at the pixel width of the
21804 character to the left of point, so we use a different method
21805 of getting to that place. */
21807 target_x
= pt_x
+ pixel_width
;
21809 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
21811 /* Target X coordinate could be one line above or below the line
21812 of point, in which case we need to adjust the target X
21813 coordinate. Also, if moving to the left, we need to begin at
21814 the left edge of the point's screen line. */
21819 start_display (&it
, w
, pt
);
21820 if (it
.line_wrap
== TRUNCATE
)
21821 it
.last_visible_x
= INFINITY
;
21822 reseat_at_previous_visible_line_start (&it
);
21823 it
.current_x
= it
.current_y
= it
.hpos
= 0;
21825 move_it_by_lines (&it
, pt_vpos
);
21829 move_it_by_lines (&it
, -1);
21830 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
21831 target_is_eol_p
= true;
21832 /* Under word-wrap, we don't know the x coordinate of
21833 the last character displayed on the previous line,
21834 which immediately precedes the wrap point. To find
21835 out its x coordinate, we try moving to the right
21836 margin of the window, which will stop at the wrap
21837 point, and then reset target_x to point at the
21838 character that precedes the wrap point. This is not
21839 needed on GUI frames, because (see below) there we
21840 move from the left margin one grapheme cluster at a
21841 time, and stop when we hit the wrap point. */
21842 if (!FRAME_WINDOW_P (it
.f
) && it
.line_wrap
== WORD_WRAP
)
21844 void *it_data
= NULL
;
21847 SAVE_IT (it2
, it
, it_data
);
21848 move_it_in_display_line_to (&it
, ZV
, target_x
,
21849 MOVE_TO_POS
| MOVE_TO_X
);
21850 /* If we arrived at target_x, that _is_ the last
21851 character on the previous line. */
21852 if (it
.current_x
!= target_x
)
21853 target_x
= it
.current_x
- 1;
21854 RESTORE_IT (&it
, &it2
, it_data
);
21861 || (target_x
>= it
.last_visible_x
21862 && it
.line_wrap
!= TRUNCATE
))
21865 move_it_by_lines (&it
, 0);
21866 move_it_by_lines (&it
, 1);
21871 /* Move to the target X coordinate. */
21872 /* On GUI frames, as we don't know the X coordinate of the
21873 character to the left of point, moving point to the left
21874 requires walking, one grapheme cluster at a time, until we
21875 find ourself at a place immediately to the left of the
21876 character at point. */
21877 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
21879 struct text_pos new_pos
;
21880 enum move_it_result rc
= MOVE_X_REACHED
;
21882 if (it
.current_x
== 0)
21883 get_next_display_element (&it
);
21884 if (it
.what
== IT_COMPOSITION
)
21886 new_pos
.charpos
= it
.cmp_it
.charpos
;
21887 new_pos
.bytepos
= -1;
21890 new_pos
= it
.current
.pos
;
21892 while (it
.current_x
+ it
.pixel_width
<= target_x
21893 && (rc
== MOVE_X_REACHED
21894 /* Under word-wrap, move_it_in_display_line_to
21895 stops at correct coordinates, but sometimes
21896 returns MOVE_POS_MATCH_OR_ZV. */
21897 || (it
.line_wrap
== WORD_WRAP
21898 && rc
== MOVE_POS_MATCH_OR_ZV
)))
21900 int new_x
= it
.current_x
+ it
.pixel_width
;
21902 /* For composed characters, we want the position of the
21903 first character in the grapheme cluster (usually, the
21904 composition's base character), whereas it.current
21905 might give us the position of the _last_ one, e.g. if
21906 the composition is rendered in reverse due to bidi
21908 if (it
.what
== IT_COMPOSITION
)
21910 new_pos
.charpos
= it
.cmp_it
.charpos
;
21911 new_pos
.bytepos
= -1;
21914 new_pos
= it
.current
.pos
;
21915 if (new_x
== it
.current_x
)
21917 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
21918 MOVE_TO_POS
| MOVE_TO_X
);
21919 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
21922 /* The previous position we saw in the loop is the one we
21924 if (new_pos
.bytepos
== -1)
21925 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
21926 it
.current
.pos
= new_pos
;
21928 else if (it
.current_x
!= target_x
)
21929 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
21931 /* If we ended up in a display string that covers point, move to
21932 buffer position to the right in the visual order. */
21935 while (IT_CHARPOS (it
) == PT
)
21937 set_iterator_to_next (&it
, false);
21938 if (!get_next_display_element (&it
))
21943 /* Move point to that position. */
21944 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
21947 return make_number (PT
);
21949 #undef ROW_GLYPH_NEWLINE_P
21952 DEFUN ("bidi-resolved-levels", Fbidi_resolved_levels
,
21953 Sbidi_resolved_levels
, 0, 1, 0,
21954 doc
: /* Return the resolved bidirectional levels of characters at VPOS.
21956 The resolved levels are produced by the Emacs bidi reordering engine
21957 that implements the UBA, the Unicode Bidirectional Algorithm. Please
21958 read the Unicode Standard Annex 9 (UAX#9) for background information
21959 about these levels.
21961 VPOS is the zero-based number of the current window's screen line
21962 for which to produce the resolved levels. If VPOS is nil or omitted,
21963 it defaults to the screen line of point. If the window displays a
21964 header line, VPOS of zero will report on the header line, and first
21965 line of text in the window will have VPOS of 1.
21967 Value is an array of resolved levels, indexed by glyph number.
21968 Glyphs are numbered from zero starting from the beginning of the
21969 screen line, i.e. the left edge of the window for left-to-right lines
21970 and from the right edge for right-to-left lines. The resolved levels
21971 are produced only for the window's text area; text in display margins
21974 If the selected window's display is not up-to-date, or if the specified
21975 screen line does not display text, this function returns nil. It is
21976 highly recommended to bind this function to some simple key, like F8,
21977 in order to avoid these problems.
21979 This function exists mainly for testing the correctness of the
21980 Emacs UBA implementation, in particular with the test suite. */)
21983 struct window
*w
= XWINDOW (selected_window
);
21984 struct buffer
*b
= XBUFFER (w
->contents
);
21986 struct glyph_row
*row
;
21990 int d1
, d2
, d3
, d4
, d5
;
21992 pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &nrow
);
21996 CHECK_NUMBER_COERCE_MARKER (vpos
);
21997 nrow
= XINT (vpos
);
22000 /* We require up-to-date glyph matrix for this window. */
22001 if (w
->window_end_valid
22002 && !windows_or_buffers_changed
22004 && !b
->clip_changed
22005 && !b
->prevent_redisplay_optimizations_p
22006 && !window_outdated (w
)
22008 && nrow
< w
->current_matrix
->nrows
22009 && (row
= MATRIX_ROW (w
->current_matrix
, nrow
))->enabled_p
22010 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
22012 struct glyph
*g
, *e
, *g1
;
22014 Lisp_Object levels
;
22016 if (!row
->reversed_p
) /* Left-to-right glyph row. */
22018 g
= g1
= row
->glyphs
[TEXT_AREA
];
22019 e
= g
+ row
->used
[TEXT_AREA
];
22021 /* Skip over glyphs at the start of the row that was
22022 generated by redisplay for its own needs. */
22024 && NILP (g
->object
)
22029 /* Count the "interesting" glyphs in this row. */
22030 for (nglyphs
= 0; g
< e
&& !NILP (g
->object
); g
++)
22033 /* Create and fill the array. */
22034 levels
= make_uninit_vector (nglyphs
);
22035 for (i
= 0; g1
< g
; i
++, g1
++)
22036 ASET (levels
, i
, make_number (g1
->resolved_level
));
22038 else /* Right-to-left glyph row. */
22040 g
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
22041 e
= row
->glyphs
[TEXT_AREA
] - 1;
22043 && NILP (g
->object
)
22047 for (nglyphs
= 0; g
> e
&& !NILP (g
->object
); g
--)
22049 levels
= make_uninit_vector (nglyphs
);
22050 for (i
= 0; g1
> g
; i
++, g1
--)
22051 ASET (levels
, i
, make_number (g1
->resolved_level
));
22061 /***********************************************************************
22063 ***********************************************************************/
22065 /* Redisplay the menu bar in the frame for window W.
22067 The menu bar of X frames that don't have X toolkit support is
22068 displayed in a special window W->frame->menu_bar_window.
22070 The menu bar of terminal frames is treated specially as far as
22071 glyph matrices are concerned. Menu bar lines are not part of
22072 windows, so the update is done directly on the frame matrix rows
22073 for the menu bar. */
22076 display_menu_bar (struct window
*w
)
22078 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22083 /* Don't do all this for graphical frames. */
22085 if (FRAME_W32_P (f
))
22088 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
22094 if (FRAME_NS_P (f
))
22096 #endif /* HAVE_NS */
22098 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
22099 eassert (!FRAME_WINDOW_P (f
));
22100 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
22101 it
.first_visible_x
= 0;
22102 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
22103 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
22104 if (FRAME_WINDOW_P (f
))
22106 /* Menu bar lines are displayed in the desired matrix of the
22107 dummy window menu_bar_window. */
22108 struct window
*menu_w
;
22109 menu_w
= XWINDOW (f
->menu_bar_window
);
22110 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
22112 it
.first_visible_x
= 0;
22113 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
22116 #endif /* not USE_X_TOOLKIT and not USE_GTK */
22118 /* This is a TTY frame, i.e. character hpos/vpos are used as
22120 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
22122 it
.first_visible_x
= 0;
22123 it
.last_visible_x
= FRAME_COLS (f
);
22126 /* FIXME: This should be controlled by a user option. See the
22127 comments in redisplay_tool_bar and display_mode_line about
22129 it
.paragraph_embedding
= L2R
;
22131 /* Clear all rows of the menu bar. */
22132 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
22134 struct glyph_row
*row
= it
.glyph_row
+ i
;
22135 clear_glyph_row (row
);
22136 row
->enabled_p
= true;
22137 row
->full_width_p
= true;
22138 row
->reversed_p
= false;
22141 /* Display all items of the menu bar. */
22142 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
22143 for (i
= 0; i
< ASIZE (items
); i
+= 4)
22145 Lisp_Object string
;
22147 /* Stop at nil string. */
22148 string
= AREF (items
, i
+ 1);
22152 /* Remember where item was displayed. */
22153 ASET (items
, i
+ 3, make_number (it
.hpos
));
22155 /* Display the item, pad with one space. */
22156 if (it
.current_x
< it
.last_visible_x
)
22157 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
22158 SCHARS (string
) + 1, 0, 0, -1);
22161 /* Fill out the line with spaces. */
22162 if (it
.current_x
< it
.last_visible_x
)
22163 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
22165 /* Compute the total height of the lines. */
22166 compute_line_metrics (&it
);
22169 /* Deep copy of a glyph row, including the glyphs. */
22171 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
22173 struct glyph
*pointers
[1 + LAST_AREA
];
22174 int to_used
= to
->used
[TEXT_AREA
];
22176 /* Save glyph pointers of TO. */
22177 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
22179 /* Do a structure assignment. */
22182 /* Restore original glyph pointers of TO. */
22183 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
22185 /* Copy the glyphs. */
22186 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
22187 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
22189 /* If we filled only part of the TO row, fill the rest with
22190 space_glyph (which will display as empty space). */
22191 if (to_used
> from
->used
[TEXT_AREA
])
22192 fill_up_frame_row_with_spaces (to
, to_used
);
22195 /* Display one menu item on a TTY, by overwriting the glyphs in the
22196 frame F's desired glyph matrix with glyphs produced from the menu
22197 item text. Called from term.c to display TTY drop-down menus one
22200 ITEM_TEXT is the menu item text as a C string.
22202 FACE_ID is the face ID to be used for this menu item. FACE_ID
22203 could specify one of 3 faces: a face for an enabled item, a face
22204 for a disabled item, or a face for a selected item.
22206 X and Y are coordinates of the first glyph in the frame's desired
22207 matrix to be overwritten by the menu item. Since this is a TTY, Y
22208 is the zero-based number of the glyph row and X is the zero-based
22209 glyph number in the row, starting from left, where to start
22210 displaying the item.
22212 SUBMENU means this menu item drops down a submenu, which
22213 should be indicated by displaying a proper visual cue after the
22217 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
22218 int x
, int y
, bool submenu
)
22221 struct frame
*f
= SELECTED_FRAME ();
22222 struct window
*w
= XWINDOW (f
->selected_window
);
22223 struct glyph_row
*row
;
22224 size_t item_len
= strlen (item_text
);
22226 eassert (FRAME_TERMCAP_P (f
));
22228 /* Don't write beyond the matrix's last row. This can happen for
22229 TTY screens that are not high enough to show the entire menu.
22230 (This is actually a bit of defensive programming, as
22231 tty_menu_display already limits the number of menu items to one
22232 less than the number of screen lines.) */
22233 if (y
>= f
->desired_matrix
->nrows
)
22236 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
22237 it
.first_visible_x
= 0;
22238 it
.last_visible_x
= FRAME_COLS (f
) - 1;
22239 row
= it
.glyph_row
;
22240 /* Start with the row contents from the current matrix. */
22241 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
22242 bool saved_width
= row
->full_width_p
;
22243 row
->full_width_p
= true;
22244 bool saved_reversed
= row
->reversed_p
;
22245 row
->reversed_p
= false;
22246 row
->enabled_p
= true;
22248 /* Arrange for the menu item glyphs to start at (X,Y) and have the
22250 eassert (x
< f
->desired_matrix
->matrix_w
);
22251 it
.current_x
= it
.hpos
= x
;
22252 it
.current_y
= it
.vpos
= y
;
22253 int saved_used
= row
->used
[TEXT_AREA
];
22254 bool saved_truncated
= row
->truncated_on_right_p
;
22255 row
->used
[TEXT_AREA
] = x
;
22256 it
.face_id
= face_id
;
22257 it
.line_wrap
= TRUNCATE
;
22259 /* FIXME: This should be controlled by a user option. See the
22260 comments in redisplay_tool_bar and display_mode_line about this.
22261 Also, if paragraph_embedding could ever be R2L, changes will be
22262 needed to avoid shifting to the right the row characters in
22263 term.c:append_glyph. */
22264 it
.paragraph_embedding
= L2R
;
22266 /* Pad with a space on the left. */
22267 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
22269 /* Display the menu item, pad with spaces to WIDTH. */
22272 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
22273 item_len
, 0, FRAME_COLS (f
) - 1, -1);
22275 /* Indicate with " >" that there's a submenu. */
22276 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
22277 FRAME_COLS (f
) - 1, -1);
22280 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
22281 width
, 0, FRAME_COLS (f
) - 1, -1);
22283 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
22284 row
->truncated_on_right_p
= saved_truncated
;
22285 row
->hash
= row_hash (row
);
22286 row
->full_width_p
= saved_width
;
22287 row
->reversed_p
= saved_reversed
;
22290 /***********************************************************************
22292 ***********************************************************************/
22294 /* Redisplay mode lines in the window tree whose root is WINDOW.
22295 If FORCE, redisplay mode lines unconditionally.
22296 Otherwise, redisplay only mode lines that are garbaged. Value is
22297 the number of windows whose mode lines were redisplayed. */
22300 redisplay_mode_lines (Lisp_Object window
, bool force
)
22304 while (!NILP (window
))
22306 struct window
*w
= XWINDOW (window
);
22308 if (WINDOWP (w
->contents
))
22309 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
22311 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
22312 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
22314 struct text_pos lpoint
;
22315 struct buffer
*old
= current_buffer
;
22317 /* Set the window's buffer for the mode line display. */
22318 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
22319 set_buffer_internal_1 (XBUFFER (w
->contents
));
22321 /* Point refers normally to the selected window. For any
22322 other window, set up appropriate value. */
22323 if (!EQ (window
, selected_window
))
22325 struct text_pos pt
;
22327 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
22328 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
22331 /* Display mode lines. */
22332 clear_glyph_matrix (w
->desired_matrix
);
22333 if (display_mode_lines (w
))
22336 /* Restore old settings. */
22337 set_buffer_internal_1 (old
);
22338 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
22348 /* Display the mode and/or header line of window W. Value is the
22349 sum number of mode lines and header lines displayed. */
22352 display_mode_lines (struct window
*w
)
22354 Lisp_Object old_selected_window
= selected_window
;
22355 Lisp_Object old_selected_frame
= selected_frame
;
22356 Lisp_Object new_frame
= w
->frame
;
22357 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
22360 selected_frame
= new_frame
;
22361 /* FIXME: If we were to allow the mode-line's computation changing the buffer
22362 or window's point, then we'd need select_window_1 here as well. */
22363 XSETWINDOW (selected_window
, w
);
22364 XFRAME (new_frame
)->selected_window
= selected_window
;
22366 /* These will be set while the mode line specs are processed. */
22367 line_number_displayed
= false;
22368 w
->column_number_displayed
= -1;
22370 if (WINDOW_WANTS_MODELINE_P (w
))
22372 struct window
*sel_w
= XWINDOW (old_selected_window
);
22374 /* Select mode line face based on the real selected window. */
22375 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
22376 BVAR (current_buffer
, mode_line_format
));
22380 if (WINDOW_WANTS_HEADER_LINE_P (w
))
22382 display_mode_line (w
, HEADER_LINE_FACE_ID
,
22383 BVAR (current_buffer
, header_line_format
));
22387 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
22388 selected_frame
= old_selected_frame
;
22389 selected_window
= old_selected_window
;
22391 w
->must_be_updated_p
= true;
22396 /* Display mode or header line of window W. FACE_ID specifies which
22397 line to display; it is either MODE_LINE_FACE_ID or
22398 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
22399 display. Value is the pixel height of the mode/header line
22403 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
22407 ptrdiff_t count
= SPECPDL_INDEX ();
22409 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
22410 /* Don't extend on a previously drawn mode-line.
22411 This may happen if called from pos_visible_p. */
22412 it
.glyph_row
->enabled_p
= false;
22413 prepare_desired_row (w
, it
.glyph_row
, true);
22415 it
.glyph_row
->mode_line_p
= true;
22417 /* FIXME: This should be controlled by a user option. But
22418 supporting such an option is not trivial, since the mode line is
22419 made up of many separate strings. */
22420 it
.paragraph_embedding
= L2R
;
22422 record_unwind_protect (unwind_format_mode_line
,
22423 format_mode_line_unwind_data (NULL
, NULL
,
22426 mode_line_target
= MODE_LINE_DISPLAY
;
22428 /* Temporarily make frame's keyboard the current kboard so that
22429 kboard-local variables in the mode_line_format will get the right
22431 push_kboard (FRAME_KBOARD (it
.f
));
22432 record_unwind_save_match_data ();
22433 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
22436 unbind_to (count
, Qnil
);
22438 /* Fill up with spaces. */
22439 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
22441 compute_line_metrics (&it
);
22442 it
.glyph_row
->full_width_p
= true;
22443 it
.glyph_row
->continued_p
= false;
22444 it
.glyph_row
->truncated_on_left_p
= false;
22445 it
.glyph_row
->truncated_on_right_p
= false;
22447 /* Make a 3D mode-line have a shadow at its right end. */
22448 face
= FACE_FROM_ID (it
.f
, face_id
);
22449 extend_face_to_end_of_line (&it
);
22450 if (face
->box
!= FACE_NO_BOX
)
22452 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
22453 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
22454 last
->right_box_line_p
= true;
22457 return it
.glyph_row
->height
;
22460 /* Move element ELT in LIST to the front of LIST.
22461 Return the updated list. */
22464 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
22466 register Lisp_Object tail
, prev
;
22467 register Lisp_Object tem
;
22471 while (CONSP (tail
))
22477 /* Splice out the link TAIL. */
22479 list
= XCDR (tail
);
22481 Fsetcdr (prev
, XCDR (tail
));
22483 /* Now make it the first. */
22484 Fsetcdr (tail
, list
);
22489 tail
= XCDR (tail
);
22493 /* Not found--return unchanged LIST. */
22497 /* Contribute ELT to the mode line for window IT->w. How it
22498 translates into text depends on its data type.
22500 IT describes the display environment in which we display, as usual.
22502 DEPTH is the depth in recursion. It is used to prevent
22503 infinite recursion here.
22505 FIELD_WIDTH is the number of characters the display of ELT should
22506 occupy in the mode line, and PRECISION is the maximum number of
22507 characters to display from ELT's representation. See
22508 display_string for details.
22510 Returns the hpos of the end of the text generated by ELT.
22512 PROPS is a property list to add to any string we encounter.
22514 If RISKY, remove (disregard) any properties in any string
22515 we encounter, and ignore :eval and :propertize.
22517 The global variable `mode_line_target' determines whether the
22518 output is passed to `store_mode_line_noprop',
22519 `store_mode_line_string', or `display_string'. */
22522 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
22523 Lisp_Object elt
, Lisp_Object props
, bool risky
)
22525 int n
= 0, field
, prec
;
22526 bool literal
= false;
22530 elt
= build_string ("*too-deep*");
22534 switch (XTYPE (elt
))
22538 /* A string: output it and check for %-constructs within it. */
22540 ptrdiff_t offset
= 0;
22542 if (SCHARS (elt
) > 0
22543 && (!NILP (props
) || risky
))
22545 Lisp_Object oprops
, aelt
;
22546 oprops
= Ftext_properties_at (make_number (0), elt
);
22548 /* If the starting string's properties are not what
22549 we want, translate the string. Also, if the string
22550 is risky, do that anyway. */
22552 if (NILP (Fequal (props
, oprops
)) || risky
)
22554 /* If the starting string has properties,
22555 merge the specified ones onto the existing ones. */
22556 if (! NILP (oprops
) && !risky
)
22560 oprops
= Fcopy_sequence (oprops
);
22562 while (CONSP (tem
))
22564 oprops
= Fplist_put (oprops
, XCAR (tem
),
22565 XCAR (XCDR (tem
)));
22566 tem
= XCDR (XCDR (tem
));
22571 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
22572 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
22574 /* AELT is what we want. Move it to the front
22575 without consing. */
22577 mode_line_proptrans_alist
22578 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
22584 /* If AELT has the wrong props, it is useless.
22585 so get rid of it. */
22587 mode_line_proptrans_alist
22588 = Fdelq (aelt
, mode_line_proptrans_alist
);
22590 elt
= Fcopy_sequence (elt
);
22591 Fset_text_properties (make_number (0), Flength (elt
),
22593 /* Add this item to mode_line_proptrans_alist. */
22594 mode_line_proptrans_alist
22595 = Fcons (Fcons (elt
, props
),
22596 mode_line_proptrans_alist
);
22597 /* Truncate mode_line_proptrans_alist
22598 to at most 50 elements. */
22599 tem
= Fnthcdr (make_number (50),
22600 mode_line_proptrans_alist
);
22602 XSETCDR (tem
, Qnil
);
22611 prec
= precision
- n
;
22612 switch (mode_line_target
)
22614 case MODE_LINE_NOPROP
:
22615 case MODE_LINE_TITLE
:
22616 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
22618 case MODE_LINE_STRING
:
22619 n
+= store_mode_line_string (NULL
, elt
, true, 0, prec
, Qnil
);
22621 case MODE_LINE_DISPLAY
:
22622 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
22623 0, prec
, 0, STRING_MULTIBYTE (elt
));
22630 /* Handle the non-literal case. */
22632 while ((precision
<= 0 || n
< precision
)
22633 && SREF (elt
, offset
) != 0
22634 && (mode_line_target
!= MODE_LINE_DISPLAY
22635 || it
->current_x
< it
->last_visible_x
))
22637 ptrdiff_t last_offset
= offset
;
22639 /* Advance to end of string or next format specifier. */
22640 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
22643 if (offset
- 1 != last_offset
)
22645 ptrdiff_t nchars
, nbytes
;
22647 /* Output to end of string or up to '%'. Field width
22648 is length of string. Don't output more than
22649 PRECISION allows us. */
22652 prec
= c_string_width (SDATA (elt
) + last_offset
,
22653 offset
- last_offset
, precision
- n
,
22656 switch (mode_line_target
)
22658 case MODE_LINE_NOPROP
:
22659 case MODE_LINE_TITLE
:
22660 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
22662 case MODE_LINE_STRING
:
22664 ptrdiff_t bytepos
= last_offset
;
22665 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22666 ptrdiff_t endpos
= (precision
<= 0
22667 ? string_byte_to_char (elt
, offset
)
22668 : charpos
+ nchars
);
22669 Lisp_Object mode_string
22670 = Fsubstring (elt
, make_number (charpos
),
22671 make_number (endpos
));
22672 n
+= store_mode_line_string (NULL
, mode_string
, false,
22676 case MODE_LINE_DISPLAY
:
22678 ptrdiff_t bytepos
= last_offset
;
22679 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22681 if (precision
<= 0)
22682 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
22683 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
22685 STRING_MULTIBYTE (elt
));
22690 else /* c == '%' */
22692 ptrdiff_t percent_position
= offset
;
22694 /* Get the specified minimum width. Zero means
22697 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
22698 field
= field
* 10 + c
- '0';
22700 /* Don't pad beyond the total padding allowed. */
22701 if (field_width
- n
> 0 && field
> field_width
- n
)
22702 field
= field_width
- n
;
22704 /* Note that either PRECISION <= 0 or N < PRECISION. */
22705 prec
= precision
- n
;
22708 n
+= display_mode_element (it
, depth
, field
, prec
,
22709 Vglobal_mode_string
, props
,
22714 ptrdiff_t bytepos
, charpos
;
22716 Lisp_Object string
;
22718 bytepos
= percent_position
;
22719 charpos
= (STRING_MULTIBYTE (elt
)
22720 ? string_byte_to_char (elt
, bytepos
)
22722 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
22723 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
22725 switch (mode_line_target
)
22727 case MODE_LINE_NOPROP
:
22728 case MODE_LINE_TITLE
:
22729 n
+= store_mode_line_noprop (spec
, field
, prec
);
22731 case MODE_LINE_STRING
:
22733 Lisp_Object tem
= build_string (spec
);
22734 props
= Ftext_properties_at (make_number (charpos
), elt
);
22735 /* Should only keep face property in props */
22736 n
+= store_mode_line_string (NULL
, tem
, false,
22737 field
, prec
, props
);
22740 case MODE_LINE_DISPLAY
:
22742 int nglyphs_before
, nwritten
;
22744 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
22745 nwritten
= display_string (spec
, string
, elt
,
22750 /* Assign to the glyphs written above the
22751 string where the `%x' came from, position
22755 struct glyph
*glyph
22756 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
22760 for (i
= 0; i
< nwritten
; ++i
)
22762 glyph
[i
].object
= elt
;
22763 glyph
[i
].charpos
= charpos
;
22780 /* A symbol: process the value of the symbol recursively
22781 as if it appeared here directly. Avoid error if symbol void.
22782 Special case: if value of symbol is a string, output the string
22785 register Lisp_Object tem
;
22787 /* If the variable is not marked as risky to set
22788 then its contents are risky to use. */
22789 if (NILP (Fget (elt
, Qrisky_local_variable
)))
22792 tem
= Fboundp (elt
);
22795 tem
= Fsymbol_value (elt
);
22796 /* If value is a string, output that string literally:
22797 don't check for % within it. */
22801 if (!EQ (tem
, elt
))
22803 /* Give up right away for nil or t. */
22813 register Lisp_Object car
, tem
;
22815 /* A cons cell: five distinct cases.
22816 If first element is :eval or :propertize, do something special.
22817 If first element is a string or a cons, process all the elements
22818 and effectively concatenate them.
22819 If first element is a negative number, truncate displaying cdr to
22820 at most that many characters. If positive, pad (with spaces)
22821 to at least that many characters.
22822 If first element is a symbol, process the cadr or caddr recursively
22823 according to whether the symbol's value is non-nil or nil. */
22825 if (EQ (car
, QCeval
))
22827 /* An element of the form (:eval FORM) means evaluate FORM
22828 and use the result as mode line elements. */
22833 if (CONSP (XCDR (elt
)))
22836 spec
= safe__eval (true, XCAR (XCDR (elt
)));
22837 n
+= display_mode_element (it
, depth
, field_width
- n
,
22838 precision
- n
, spec
, props
,
22842 else if (EQ (car
, QCpropertize
))
22844 /* An element of the form (:propertize ELT PROPS...)
22845 means display ELT but applying properties PROPS. */
22850 if (CONSP (XCDR (elt
)))
22851 n
+= display_mode_element (it
, depth
, field_width
- n
,
22852 precision
- n
, XCAR (XCDR (elt
)),
22853 XCDR (XCDR (elt
)), risky
);
22855 else if (SYMBOLP (car
))
22857 tem
= Fboundp (car
);
22861 /* elt is now the cdr, and we know it is a cons cell.
22862 Use its car if CAR has a non-nil value. */
22865 tem
= Fsymbol_value (car
);
22872 /* Symbol's value is nil (or symbol is unbound)
22873 Get the cddr of the original list
22874 and if possible find the caddr and use that. */
22878 else if (!CONSP (elt
))
22883 else if (INTEGERP (car
))
22885 register int lim
= XINT (car
);
22889 /* Negative int means reduce maximum width. */
22890 if (precision
<= 0)
22893 precision
= min (precision
, -lim
);
22897 /* Padding specified. Don't let it be more than
22898 current maximum. */
22900 lim
= min (precision
, lim
);
22902 /* If that's more padding than already wanted, queue it.
22903 But don't reduce padding already specified even if
22904 that is beyond the current truncation point. */
22905 field_width
= max (lim
, field_width
);
22909 else if (STRINGP (car
) || CONSP (car
))
22911 Lisp_Object halftail
= elt
;
22915 && (precision
<= 0 || n
< precision
))
22917 n
+= display_mode_element (it
, depth
,
22918 /* Do padding only after the last
22919 element in the list. */
22920 (! CONSP (XCDR (elt
))
22923 precision
- n
, XCAR (elt
),
22927 if ((len
& 1) == 0)
22928 halftail
= XCDR (halftail
);
22929 /* Check for cycle. */
22930 if (EQ (halftail
, elt
))
22939 elt
= build_string ("*invalid*");
22943 /* Pad to FIELD_WIDTH. */
22944 if (field_width
> 0 && n
< field_width
)
22946 switch (mode_line_target
)
22948 case MODE_LINE_NOPROP
:
22949 case MODE_LINE_TITLE
:
22950 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
22952 case MODE_LINE_STRING
:
22953 n
+= store_mode_line_string ("", Qnil
, false, field_width
- n
, 0,
22956 case MODE_LINE_DISPLAY
:
22957 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
22966 /* Store a mode-line string element in mode_line_string_list.
22968 If STRING is non-null, display that C string. Otherwise, the Lisp
22969 string LISP_STRING is displayed.
22971 FIELD_WIDTH is the minimum number of output glyphs to produce.
22972 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22973 with spaces. FIELD_WIDTH <= 0 means don't pad.
22975 PRECISION is the maximum number of characters to output from
22976 STRING. PRECISION <= 0 means don't truncate the string.
22978 If COPY_STRING, make a copy of LISP_STRING before adding
22979 properties to the string.
22981 PROPS are the properties to add to the string.
22982 The mode_line_string_face face property is always added to the string.
22986 store_mode_line_string (const char *string
, Lisp_Object lisp_string
,
22988 int field_width
, int precision
, Lisp_Object props
)
22993 if (string
!= NULL
)
22995 len
= strlen (string
);
22996 if (precision
> 0 && len
> precision
)
22998 lisp_string
= make_string (string
, len
);
23000 props
= mode_line_string_face_prop
;
23001 else if (!NILP (mode_line_string_face
))
23003 Lisp_Object face
= Fplist_get (props
, Qface
);
23004 props
= Fcopy_sequence (props
);
23006 face
= mode_line_string_face
;
23008 face
= list2 (face
, mode_line_string_face
);
23009 props
= Fplist_put (props
, Qface
, face
);
23011 Fadd_text_properties (make_number (0), make_number (len
),
23012 props
, lisp_string
);
23016 len
= XFASTINT (Flength (lisp_string
));
23017 if (precision
> 0 && len
> precision
)
23020 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
23023 if (!NILP (mode_line_string_face
))
23027 props
= Ftext_properties_at (make_number (0), lisp_string
);
23028 face
= Fplist_get (props
, Qface
);
23030 face
= mode_line_string_face
;
23032 face
= list2 (face
, mode_line_string_face
);
23033 props
= list2 (Qface
, face
);
23035 lisp_string
= Fcopy_sequence (lisp_string
);
23038 Fadd_text_properties (make_number (0), make_number (len
),
23039 props
, lisp_string
);
23044 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
23048 if (field_width
> len
)
23050 field_width
-= len
;
23051 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
23053 Fadd_text_properties (make_number (0), make_number (field_width
),
23054 props
, lisp_string
);
23055 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
23063 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
23065 doc
: /* Format a string out of a mode line format specification.
23066 First arg FORMAT specifies the mode line format (see `mode-line-format'
23067 for details) to use.
23069 By default, the format is evaluated for the currently selected window.
23071 Optional second arg FACE specifies the face property to put on all
23072 characters for which no face is specified. The value nil means the
23073 default face. The value t means whatever face the window's mode line
23074 currently uses (either `mode-line' or `mode-line-inactive',
23075 depending on whether the window is the selected window or not).
23076 An integer value means the value string has no text
23079 Optional third and fourth args WINDOW and BUFFER specify the window
23080 and buffer to use as the context for the formatting (defaults
23081 are the selected window and the WINDOW's buffer). */)
23082 (Lisp_Object format
, Lisp_Object face
,
23083 Lisp_Object window
, Lisp_Object buffer
)
23088 struct buffer
*old_buffer
= NULL
;
23090 bool no_props
= INTEGERP (face
);
23091 ptrdiff_t count
= SPECPDL_INDEX ();
23093 int string_start
= 0;
23095 w
= decode_any_window (window
);
23096 XSETWINDOW (window
, w
);
23099 buffer
= w
->contents
;
23100 CHECK_BUFFER (buffer
);
23102 /* Make formatting the modeline a non-op when noninteractive, otherwise
23103 there will be problems later caused by a partially initialized frame. */
23104 if (NILP (format
) || noninteractive
)
23105 return empty_unibyte_string
;
23110 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
23111 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
23112 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
23113 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
23114 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
23115 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
23116 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
23119 old_buffer
= current_buffer
;
23121 /* Save things including mode_line_proptrans_alist,
23122 and set that to nil so that we don't alter the outer value. */
23123 record_unwind_protect (unwind_format_mode_line
,
23124 format_mode_line_unwind_data
23125 (XFRAME (WINDOW_FRAME (w
)),
23126 old_buffer
, selected_window
, true));
23127 mode_line_proptrans_alist
= Qnil
;
23129 Fselect_window (window
, Qt
);
23130 set_buffer_internal_1 (XBUFFER (buffer
));
23132 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
23136 mode_line_target
= MODE_LINE_NOPROP
;
23137 mode_line_string_face_prop
= Qnil
;
23138 mode_line_string_list
= Qnil
;
23139 string_start
= MODE_LINE_NOPROP_LEN (0);
23143 mode_line_target
= MODE_LINE_STRING
;
23144 mode_line_string_list
= Qnil
;
23145 mode_line_string_face
= face
;
23146 mode_line_string_face_prop
23147 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
23150 push_kboard (FRAME_KBOARD (it
.f
));
23151 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
23156 len
= MODE_LINE_NOPROP_LEN (string_start
);
23157 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
23161 mode_line_string_list
= Fnreverse (mode_line_string_list
);
23162 str
= Fmapconcat (Qidentity
, mode_line_string_list
,
23163 empty_unibyte_string
);
23166 unbind_to (count
, Qnil
);
23170 /* Write a null-terminated, right justified decimal representation of
23171 the positive integer D to BUF using a minimal field width WIDTH. */
23174 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
23176 register char *p
= buf
;
23184 *p
++ = d
% 10 + '0';
23189 for (width
-= (int) (p
- buf
); width
> 0; --width
)
23200 /* Write a null-terminated, right justified decimal and "human
23201 readable" representation of the nonnegative integer D to BUF using
23202 a minimal field width WIDTH. D should be smaller than 999.5e24. */
23204 static const char power_letter
[] =
23218 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
23220 /* We aim to represent the nonnegative integer D as
23221 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
23222 ptrdiff_t quotient
= d
;
23224 /* -1 means: do not use TENTHS. */
23228 /* Length of QUOTIENT.TENTHS as a string. */
23234 if (quotient
>= 1000)
23236 /* Scale to the appropriate EXPONENT. */
23239 remainder
= quotient
% 1000;
23243 while (quotient
>= 1000);
23245 /* Round to nearest and decide whether to use TENTHS or not. */
23248 tenths
= remainder
/ 100;
23249 if (remainder
% 100 >= 50)
23256 if (quotient
== 10)
23264 if (remainder
>= 500)
23266 if (quotient
< 999)
23277 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
23278 if (tenths
== -1 && quotient
<= 99)
23285 p
= psuffix
= buf
+ max (width
, length
);
23287 /* Print EXPONENT. */
23288 *psuffix
++ = power_letter
[exponent
];
23291 /* Print TENTHS. */
23294 *--p
= '0' + tenths
;
23298 /* Print QUOTIENT. */
23301 int digit
= quotient
% 10;
23302 *--p
= '0' + digit
;
23304 while ((quotient
/= 10) != 0);
23306 /* Print leading spaces. */
23311 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
23312 If EOL_FLAG, set also a mnemonic character for end-of-line
23313 type of CODING_SYSTEM. Return updated pointer into BUF. */
23315 static unsigned char invalid_eol_type
[] = "(*invalid*)";
23318 decode_mode_spec_coding (Lisp_Object coding_system
, char *buf
, bool eol_flag
)
23321 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
23322 const unsigned char *eol_str
;
23324 /* The EOL conversion we are using. */
23325 Lisp_Object eoltype
;
23327 val
= CODING_SYSTEM_SPEC (coding_system
);
23330 if (!VECTORP (val
)) /* Not yet decided. */
23332 *buf
++ = multibyte
? '-' : ' ';
23334 eoltype
= eol_mnemonic_undecided
;
23335 /* Don't mention EOL conversion if it isn't decided. */
23340 Lisp_Object eolvalue
;
23342 attrs
= AREF (val
, 0);
23343 eolvalue
= AREF (val
, 2);
23346 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
23351 /* The EOL conversion that is normal on this system. */
23353 if (NILP (eolvalue
)) /* Not yet decided. */
23354 eoltype
= eol_mnemonic_undecided
;
23355 else if (VECTORP (eolvalue
)) /* Not yet decided. */
23356 eoltype
= eol_mnemonic_undecided
;
23357 else /* eolvalue is Qunix, Qdos, or Qmac. */
23358 eoltype
= (EQ (eolvalue
, Qunix
)
23359 ? eol_mnemonic_unix
23360 : EQ (eolvalue
, Qdos
)
23361 ? eol_mnemonic_dos
: eol_mnemonic_mac
);
23367 /* Mention the EOL conversion if it is not the usual one. */
23368 if (STRINGP (eoltype
))
23370 eol_str
= SDATA (eoltype
);
23371 eol_str_len
= SBYTES (eoltype
);
23373 else if (CHARACTERP (eoltype
))
23375 int c
= XFASTINT (eoltype
);
23376 return buf
+ CHAR_STRING (c
, (unsigned char *) buf
);
23380 eol_str
= invalid_eol_type
;
23381 eol_str_len
= sizeof (invalid_eol_type
) - 1;
23383 memcpy (buf
, eol_str
, eol_str_len
);
23384 buf
+= eol_str_len
;
23390 /* Return a string for the output of a mode line %-spec for window W,
23391 generated by character C. FIELD_WIDTH > 0 means pad the string
23392 returned with spaces to that value. Return a Lisp string in
23393 *STRING if the resulting string is taken from that Lisp string.
23395 Note we operate on the current buffer for most purposes. */
23397 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
23399 static const char *
23400 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
23401 Lisp_Object
*string
)
23404 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23405 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
23406 /* We are going to use f->decode_mode_spec_buffer as the buffer to
23407 produce strings from numerical values, so limit preposterously
23408 large values of FIELD_WIDTH to avoid overrunning the buffer's
23409 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
23410 bytes plus the terminating null. */
23411 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
23412 struct buffer
*b
= current_buffer
;
23420 if (!NILP (BVAR (b
, read_only
)))
23422 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23427 /* This differs from %* only for a modified read-only buffer. */
23428 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23430 if (!NILP (BVAR (b
, read_only
)))
23435 /* This differs from %* in ignoring read-only-ness. */
23436 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23448 if (command_loop_level
> 5)
23450 p
= decode_mode_spec_buf
;
23451 for (i
= 0; i
< command_loop_level
; i
++)
23454 return decode_mode_spec_buf
;
23462 if (command_loop_level
> 5)
23464 p
= decode_mode_spec_buf
;
23465 for (i
= 0; i
< command_loop_level
; i
++)
23468 return decode_mode_spec_buf
;
23475 /* Let lots_of_dashes be a string of infinite length. */
23476 if (mode_line_target
== MODE_LINE_NOPROP
23477 || mode_line_target
== MODE_LINE_STRING
)
23479 if (field_width
<= 0
23480 || field_width
> sizeof (lots_of_dashes
))
23482 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
23483 decode_mode_spec_buf
[i
] = '-';
23484 decode_mode_spec_buf
[i
] = '\0';
23485 return decode_mode_spec_buf
;
23488 return lots_of_dashes
;
23492 obj
= BVAR (b
, name
);
23496 /* %c and %l are ignored in `frame-title-format'.
23497 (In redisplay_internal, the frame title is drawn _before_ the
23498 windows are updated, so the stuff which depends on actual
23499 window contents (such as %l) may fail to render properly, or
23500 even crash emacs.) */
23501 if (mode_line_target
== MODE_LINE_TITLE
)
23505 ptrdiff_t col
= current_column ();
23506 w
->column_number_displayed
= col
;
23507 pint2str (decode_mode_spec_buf
, width
, col
);
23508 return decode_mode_spec_buf
;
23512 #if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
23514 if (NILP (Vmemory_full
))
23517 return "!MEM FULL! ";
23524 /* %F displays the frame name. */
23525 if (!NILP (f
->title
))
23526 return SSDATA (f
->title
);
23527 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
23528 return SSDATA (f
->name
);
23532 obj
= BVAR (b
, filename
);
23537 ptrdiff_t size
= ZV
- BEGV
;
23538 pint2str (decode_mode_spec_buf
, width
, size
);
23539 return decode_mode_spec_buf
;
23544 ptrdiff_t size
= ZV
- BEGV
;
23545 pint2hrstr (decode_mode_spec_buf
, width
, size
);
23546 return decode_mode_spec_buf
;
23551 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
23552 ptrdiff_t topline
, nlines
, height
;
23555 /* %c and %l are ignored in `frame-title-format'. */
23556 if (mode_line_target
== MODE_LINE_TITLE
)
23559 startpos
= marker_position (w
->start
);
23560 startpos_byte
= marker_byte_position (w
->start
);
23561 height
= WINDOW_TOTAL_LINES (w
);
23563 /* If we decided that this buffer isn't suitable for line numbers,
23564 don't forget that too fast. */
23565 if (w
->base_line_pos
== -1)
23568 /* If the buffer is very big, don't waste time. */
23569 if (INTEGERP (Vline_number_display_limit
)
23570 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
23572 w
->base_line_pos
= 0;
23573 w
->base_line_number
= 0;
23577 if (w
->base_line_number
> 0
23578 && w
->base_line_pos
> 0
23579 && w
->base_line_pos
<= startpos
)
23581 line
= w
->base_line_number
;
23582 linepos
= w
->base_line_pos
;
23583 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
23588 linepos
= BUF_BEGV (b
);
23589 linepos_byte
= BUF_BEGV_BYTE (b
);
23592 /* Count lines from base line to window start position. */
23593 nlines
= display_count_lines (linepos_byte
,
23597 topline
= nlines
+ line
;
23599 /* Determine a new base line, if the old one is too close
23600 or too far away, or if we did not have one.
23601 "Too close" means it's plausible a scroll-down would
23602 go back past it. */
23603 if (startpos
== BUF_BEGV (b
))
23605 w
->base_line_number
= topline
;
23606 w
->base_line_pos
= BUF_BEGV (b
);
23608 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
23609 || linepos
== BUF_BEGV (b
))
23611 ptrdiff_t limit
= BUF_BEGV (b
);
23612 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
23613 ptrdiff_t position
;
23614 ptrdiff_t distance
=
23615 (height
* 2 + 30) * line_number_display_limit_width
;
23617 if (startpos
- distance
> limit
)
23619 limit
= startpos
- distance
;
23620 limit_byte
= CHAR_TO_BYTE (limit
);
23623 nlines
= display_count_lines (startpos_byte
,
23625 - (height
* 2 + 30),
23627 /* If we couldn't find the lines we wanted within
23628 line_number_display_limit_width chars per line,
23629 give up on line numbers for this window. */
23630 if (position
== limit_byte
&& limit
== startpos
- distance
)
23632 w
->base_line_pos
= -1;
23633 w
->base_line_number
= 0;
23637 w
->base_line_number
= topline
- nlines
;
23638 w
->base_line_pos
= BYTE_TO_CHAR (position
);
23641 /* Now count lines from the start pos to point. */
23642 nlines
= display_count_lines (startpos_byte
,
23643 PT_BYTE
, PT
, &junk
);
23645 /* Record that we did display the line number. */
23646 line_number_displayed
= true;
23648 /* Make the string to show. */
23649 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
23650 return decode_mode_spec_buf
;
23653 char *p
= decode_mode_spec_buf
;
23654 int pad
= width
- 2;
23660 return decode_mode_spec_buf
;
23666 obj
= BVAR (b
, mode_name
);
23670 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
23676 ptrdiff_t pos
= marker_position (w
->start
);
23677 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23679 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
23681 if (pos
<= BUF_BEGV (b
))
23686 else if (pos
<= BUF_BEGV (b
))
23690 if (total
> 1000000)
23691 /* Do it differently for a large value, to avoid overflow. */
23692 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23694 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23695 /* We can't normally display a 3-digit number,
23696 so get us a 2-digit number that is close. */
23699 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23700 return decode_mode_spec_buf
;
23704 /* Display percentage of size above the bottom of the screen. */
23707 ptrdiff_t toppos
= marker_position (w
->start
);
23708 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
23709 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23711 if (botpos
>= BUF_ZV (b
))
23713 if (toppos
<= BUF_BEGV (b
))
23720 if (total
> 1000000)
23721 /* Do it differently for a large value, to avoid overflow. */
23722 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23724 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23725 /* We can't normally display a 3-digit number,
23726 so get us a 2-digit number that is close. */
23729 if (toppos
<= BUF_BEGV (b
))
23730 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
23732 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23733 return decode_mode_spec_buf
;
23738 /* status of process */
23739 obj
= Fget_buffer_process (Fcurrent_buffer ());
23741 return "no process";
23743 obj
= Fsymbol_name (Fprocess_status (obj
));
23749 ptrdiff_t count
= inhibit_garbage_collection ();
23750 Lisp_Object curdir
= BVAR (current_buffer
, directory
);
23751 Lisp_Object val
= Qnil
;
23753 if (STRINGP (curdir
))
23754 val
= call1 (intern ("file-remote-p"), curdir
);
23756 unbind_to (count
, Qnil
);
23765 /* coding-system (not including end-of-line format) */
23767 /* coding-system (including end-of-line type) */
23769 bool eol_flag
= (c
== 'Z');
23770 char *p
= decode_mode_spec_buf
;
23772 if (! FRAME_WINDOW_P (f
))
23774 /* No need to mention EOL here--the terminal never needs
23775 to do EOL conversion. */
23776 p
= decode_mode_spec_coding (CODING_ID_NAME
23777 (FRAME_KEYBOARD_CODING (f
)->id
),
23779 p
= decode_mode_spec_coding (CODING_ID_NAME
23780 (FRAME_TERMINAL_CODING (f
)->id
),
23783 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
23786 #if false /* This proves to be annoying; I think we can do without. -- rms. */
23787 #ifdef subprocesses
23788 obj
= Fget_buffer_process (Fcurrent_buffer ());
23789 if (PROCESSP (obj
))
23791 p
= decode_mode_spec_coding
23792 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
23793 p
= decode_mode_spec_coding
23794 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
23796 #endif /* subprocesses */
23799 return decode_mode_spec_buf
;
23806 return SSDATA (obj
);
23813 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
23814 means count lines back from START_BYTE. But don't go beyond
23815 LIMIT_BYTE. Return the number of lines thus found (always
23818 Set *BYTE_POS_PTR to the byte position where we stopped. This is
23819 either the position COUNT lines after/before START_BYTE, if we
23820 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
23824 display_count_lines (ptrdiff_t start_byte
,
23825 ptrdiff_t limit_byte
, ptrdiff_t count
,
23826 ptrdiff_t *byte_pos_ptr
)
23828 register unsigned char *cursor
;
23829 unsigned char *base
;
23831 register ptrdiff_t ceiling
;
23832 register unsigned char *ceiling_addr
;
23833 ptrdiff_t orig_count
= count
;
23835 /* If we are not in selective display mode,
23836 check only for newlines. */
23837 bool selective_display
23838 = (!NILP (BVAR (current_buffer
, selective_display
))
23839 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
23843 while (start_byte
< limit_byte
)
23845 ceiling
= BUFFER_CEILING_OF (start_byte
);
23846 ceiling
= min (limit_byte
- 1, ceiling
);
23847 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
23848 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
23852 if (selective_display
)
23854 while (*cursor
!= '\n' && *cursor
!= 015
23855 && ++cursor
!= ceiling_addr
)
23857 if (cursor
== ceiling_addr
)
23862 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
23871 start_byte
+= cursor
- base
;
23872 *byte_pos_ptr
= start_byte
;
23876 while (cursor
< ceiling_addr
);
23878 start_byte
+= ceiling_addr
- base
;
23883 while (start_byte
> limit_byte
)
23885 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
23886 ceiling
= max (limit_byte
, ceiling
);
23887 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
23888 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
23891 if (selective_display
)
23893 while (--cursor
>= ceiling_addr
23894 && *cursor
!= '\n' && *cursor
!= 015)
23896 if (cursor
< ceiling_addr
)
23901 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
23908 start_byte
+= cursor
- base
+ 1;
23909 *byte_pos_ptr
= start_byte
;
23910 /* When scanning backwards, we should
23911 not count the newline posterior to which we stop. */
23912 return - orig_count
- 1;
23915 start_byte
+= ceiling_addr
- base
;
23919 *byte_pos_ptr
= limit_byte
;
23922 return - orig_count
+ count
;
23923 return orig_count
- count
;
23929 /***********************************************************************
23931 ***********************************************************************/
23933 /* Display a NUL-terminated string, starting with index START.
23935 If STRING is non-null, display that C string. Otherwise, the Lisp
23936 string LISP_STRING is displayed. There's a case that STRING is
23937 non-null and LISP_STRING is not nil. It means STRING is a string
23938 data of LISP_STRING. In that case, we display LISP_STRING while
23939 ignoring its text properties.
23941 If FACE_STRING is not nil, FACE_STRING_POS is a position in
23942 FACE_STRING. Display STRING or LISP_STRING with the face at
23943 FACE_STRING_POS in FACE_STRING:
23945 Display the string in the environment given by IT, but use the
23946 standard display table, temporarily.
23948 FIELD_WIDTH is the minimum number of output glyphs to produce.
23949 If STRING has fewer characters than FIELD_WIDTH, pad to the right
23950 with spaces. If STRING has more characters, more than FIELD_WIDTH
23951 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
23953 PRECISION is the maximum number of characters to output from
23954 STRING. PRECISION < 0 means don't truncate the string.
23956 This is roughly equivalent to printf format specifiers:
23958 FIELD_WIDTH PRECISION PRINTF
23959 ----------------------------------------
23965 MULTIBYTE zero means do not display multibyte chars, > 0 means do
23966 display them, and < 0 means obey the current buffer's value of
23967 enable_multibyte_characters.
23969 Value is the number of columns displayed. */
23972 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
23973 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
23974 int field_width
, int precision
, int max_x
, int multibyte
)
23976 int hpos_at_start
= it
->hpos
;
23977 int saved_face_id
= it
->face_id
;
23978 struct glyph_row
*row
= it
->glyph_row
;
23979 ptrdiff_t it_charpos
;
23981 /* Initialize the iterator IT for iteration over STRING beginning
23982 with index START. */
23983 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
23984 precision
, field_width
, multibyte
);
23985 if (string
&& STRINGP (lisp_string
))
23986 /* LISP_STRING is the one returned by decode_mode_spec. We should
23987 ignore its text properties. */
23988 it
->stop_charpos
= it
->end_charpos
;
23990 /* If displaying STRING, set up the face of the iterator from
23991 FACE_STRING, if that's given. */
23992 if (STRINGP (face_string
))
23998 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
23999 0, &endptr
, it
->base_face_id
, false);
24000 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24001 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
24004 /* Set max_x to the maximum allowed X position. Don't let it go
24005 beyond the right edge of the window. */
24007 max_x
= it
->last_visible_x
;
24009 max_x
= min (max_x
, it
->last_visible_x
);
24011 /* Skip over display elements that are not visible. because IT->w is
24013 if (it
->current_x
< it
->first_visible_x
)
24014 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
24015 MOVE_TO_POS
| MOVE_TO_X
);
24017 row
->ascent
= it
->max_ascent
;
24018 row
->height
= it
->max_ascent
+ it
->max_descent
;
24019 row
->phys_ascent
= it
->max_phys_ascent
;
24020 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
24021 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
24023 if (STRINGP (it
->string
))
24024 it_charpos
= IT_STRING_CHARPOS (*it
);
24026 it_charpos
= IT_CHARPOS (*it
);
24028 /* This condition is for the case that we are called with current_x
24029 past last_visible_x. */
24030 while (it
->current_x
< max_x
)
24032 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
24034 /* Get the next display element. */
24035 if (!get_next_display_element (it
))
24038 /* Produce glyphs. */
24039 x_before
= it
->current_x
;
24040 n_glyphs_before
= row
->used
[TEXT_AREA
];
24041 PRODUCE_GLYPHS (it
);
24043 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
24046 while (i
< nglyphs
)
24048 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
24050 if (it
->line_wrap
!= TRUNCATE
24051 && x
+ glyph
->pixel_width
> max_x
)
24053 /* End of continued line or max_x reached. */
24054 if (CHAR_GLYPH_PADDING_P (*glyph
))
24056 /* A wide character is unbreakable. */
24057 if (row
->reversed_p
)
24058 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
24059 - n_glyphs_before
);
24060 row
->used
[TEXT_AREA
] = n_glyphs_before
;
24061 it
->current_x
= x_before
;
24065 if (row
->reversed_p
)
24066 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
24067 - (n_glyphs_before
+ i
));
24068 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
24073 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
24075 /* Glyph is at least partially visible. */
24077 if (x
< it
->first_visible_x
)
24078 row
->x
= x
- it
->first_visible_x
;
24082 /* Glyph is off the left margin of the display area.
24083 Should not happen. */
24087 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
24088 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
24089 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
24090 row
->phys_height
= max (row
->phys_height
,
24091 it
->max_phys_ascent
+ it
->max_phys_descent
);
24092 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
24093 it
->max_extra_line_spacing
);
24094 x
+= glyph
->pixel_width
;
24098 /* Stop if max_x reached. */
24102 /* Stop at line ends. */
24103 if (ITERATOR_AT_END_OF_LINE_P (it
))
24105 it
->continuation_lines_width
= 0;
24109 set_iterator_to_next (it
, true);
24110 if (STRINGP (it
->string
))
24111 it_charpos
= IT_STRING_CHARPOS (*it
);
24113 it_charpos
= IT_CHARPOS (*it
);
24115 /* Stop if truncating at the right edge. */
24116 if (it
->line_wrap
== TRUNCATE
24117 && it
->current_x
>= it
->last_visible_x
)
24119 /* Add truncation mark, but don't do it if the line is
24120 truncated at a padding space. */
24121 if (it_charpos
< it
->string_nchars
)
24123 if (!FRAME_WINDOW_P (it
->f
))
24127 if (it
->current_x
> it
->last_visible_x
)
24129 if (!row
->reversed_p
)
24131 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
24132 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
24137 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
24138 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
24140 unproduce_glyphs (it
, ii
+ 1);
24141 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
24143 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
24145 row
->used
[TEXT_AREA
] = ii
;
24146 produce_special_glyphs (it
, IT_TRUNCATION
);
24149 produce_special_glyphs (it
, IT_TRUNCATION
);
24151 row
->truncated_on_right_p
= true;
24157 /* Maybe insert a truncation at the left. */
24158 if (it
->first_visible_x
24161 if (!FRAME_WINDOW_P (it
->f
)
24162 || (row
->reversed_p
24163 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
24164 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
24165 insert_left_trunc_glyphs (it
);
24166 row
->truncated_on_left_p
= true;
24169 it
->face_id
= saved_face_id
;
24171 /* Value is number of columns displayed. */
24172 return it
->hpos
- hpos_at_start
;
24177 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
24178 appears as an element of LIST or as the car of an element of LIST.
24179 If PROPVAL is a list, compare each element against LIST in that
24180 way, and return 1/2 if any element of PROPVAL is found in LIST.
24181 Otherwise return 0. This function cannot quit.
24182 The return value is 2 if the text is invisible but with an ellipsis
24183 and 1 if it's invisible and without an ellipsis. */
24186 invisible_prop (Lisp_Object propval
, Lisp_Object list
)
24188 Lisp_Object tail
, proptail
;
24190 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
24192 register Lisp_Object tem
;
24194 if (EQ (propval
, tem
))
24196 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
24197 return NILP (XCDR (tem
)) ? 1 : 2;
24200 if (CONSP (propval
))
24202 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
24204 Lisp_Object propelt
;
24205 propelt
= XCAR (proptail
);
24206 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
24208 register Lisp_Object tem
;
24210 if (EQ (propelt
, tem
))
24212 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
24213 return NILP (XCDR (tem
)) ? 1 : 2;
24221 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
24222 doc
: /* Non-nil if the property makes the text invisible.
24223 POS-OR-PROP can be a marker or number, in which case it is taken to be
24224 a position in the current buffer and the value of the `invisible' property
24225 is checked; or it can be some other value, which is then presumed to be the
24226 value of the `invisible' property of the text of interest.
24227 The non-nil value returned can be t for truly invisible text or something
24228 else if the text is replaced by an ellipsis. */)
24229 (Lisp_Object pos_or_prop
)
24232 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
24233 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
24235 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
24236 return (invis
== 0 ? Qnil
24238 : make_number (invis
));
24241 /* Calculate a width or height in pixels from a specification using
24242 the following elements:
24245 NUM - a (fractional) multiple of the default font width/height
24246 (NUM) - specifies exactly NUM pixels
24247 UNIT - a fixed number of pixels, see below.
24248 ELEMENT - size of a display element in pixels, see below.
24249 (NUM . SPEC) - equals NUM * SPEC
24250 (+ SPEC SPEC ...) - add pixel values
24251 (- SPEC SPEC ...) - subtract pixel values
24252 (- SPEC) - negate pixel value
24255 INT or FLOAT - a number constant
24256 SYMBOL - use symbol's (buffer local) variable binding.
24259 in - pixels per inch *)
24260 mm - pixels per 1/1000 meter *)
24261 cm - pixels per 1/100 meter *)
24262 width - width of current font in pixels.
24263 height - height of current font in pixels.
24265 *) using the ratio(s) defined in display-pixels-per-inch.
24269 left-fringe - left fringe width in pixels
24270 right-fringe - right fringe width in pixels
24272 left-margin - left margin width in pixels
24273 right-margin - right margin width in pixels
24275 scroll-bar - scroll-bar area width in pixels
24279 Pixels corresponding to 5 inches:
24282 Total width of non-text areas on left side of window (if scroll-bar is on left):
24283 '(space :width (+ left-fringe left-margin scroll-bar))
24285 Align to first text column (in header line):
24286 '(space :align-to 0)
24288 Align to middle of text area minus half the width of variable `my-image'
24289 containing a loaded image:
24290 '(space :align-to (0.5 . (- text my-image)))
24292 Width of left margin minus width of 1 character in the default font:
24293 '(space :width (- left-margin 1))
24295 Width of left margin minus width of 2 characters in the current font:
24296 '(space :width (- left-margin (2 . width)))
24298 Center 1 character over left-margin (in header line):
24299 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
24301 Different ways to express width of left fringe plus left margin minus one pixel:
24302 '(space :width (- (+ left-fringe left-margin) (1)))
24303 '(space :width (+ left-fringe left-margin (- (1))))
24304 '(space :width (+ left-fringe left-margin (-1)))
24309 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
24310 struct font
*font
, bool width_p
, int *align_to
)
24314 # define OK_PIXELS(val) (*res = (val), true)
24315 # define OK_ALIGN_TO(val) (*align_to = (val), true)
24318 return OK_PIXELS (0);
24320 eassert (FRAME_LIVE_P (it
->f
));
24322 if (SYMBOLP (prop
))
24324 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
24326 char *unit
= SSDATA (SYMBOL_NAME (prop
));
24328 if (unit
[0] == 'i' && unit
[1] == 'n')
24330 else if (unit
[0] == 'm' && unit
[1] == 'm')
24332 else if (unit
[0] == 'c' && unit
[1] == 'm')
24338 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
24339 : FRAME_RES_Y (it
->f
));
24342 return OK_PIXELS (ppi
/ pixels
);
24347 #ifdef HAVE_WINDOW_SYSTEM
24348 if (EQ (prop
, Qheight
))
24349 return OK_PIXELS (font
24350 ? normal_char_height (font
, -1)
24351 : FRAME_LINE_HEIGHT (it
->f
));
24352 if (EQ (prop
, Qwidth
))
24353 return OK_PIXELS (font
24354 ? FONT_WIDTH (font
)
24355 : FRAME_COLUMN_WIDTH (it
->f
));
24357 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
24358 return OK_PIXELS (1);
24361 if (EQ (prop
, Qtext
))
24362 return OK_PIXELS (width_p
24363 ? window_box_width (it
->w
, TEXT_AREA
)
24364 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
24366 if (align_to
&& *align_to
< 0)
24369 if (EQ (prop
, Qleft
))
24370 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
24371 if (EQ (prop
, Qright
))
24372 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
24373 if (EQ (prop
, Qcenter
))
24374 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
24375 + window_box_width (it
->w
, TEXT_AREA
) / 2);
24376 if (EQ (prop
, Qleft_fringe
))
24377 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24378 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
24379 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
24380 if (EQ (prop
, Qright_fringe
))
24381 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24382 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
24383 : window_box_right_offset (it
->w
, TEXT_AREA
));
24384 if (EQ (prop
, Qleft_margin
))
24385 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
24386 if (EQ (prop
, Qright_margin
))
24387 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
24388 if (EQ (prop
, Qscroll_bar
))
24389 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
24391 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
24392 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24393 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
24398 if (EQ (prop
, Qleft_fringe
))
24399 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
24400 if (EQ (prop
, Qright_fringe
))
24401 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
24402 if (EQ (prop
, Qleft_margin
))
24403 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
24404 if (EQ (prop
, Qright_margin
))
24405 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
24406 if (EQ (prop
, Qscroll_bar
))
24407 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
24410 prop
= buffer_local_value (prop
, it
->w
->contents
);
24411 if (EQ (prop
, Qunbound
))
24415 if (NUMBERP (prop
))
24417 int base_unit
= (width_p
24418 ? FRAME_COLUMN_WIDTH (it
->f
)
24419 : FRAME_LINE_HEIGHT (it
->f
));
24420 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
24425 Lisp_Object car
= XCAR (prop
);
24426 Lisp_Object cdr
= XCDR (prop
);
24430 #ifdef HAVE_WINDOW_SYSTEM
24431 if (FRAME_WINDOW_P (it
->f
)
24432 && valid_image_p (prop
))
24434 ptrdiff_t id
= lookup_image (it
->f
, prop
);
24435 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
24437 return OK_PIXELS (width_p
? img
->width
: img
->height
);
24439 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_spec_p (prop
))
24441 // TODO: Don't return dummy size.
24442 return OK_PIXELS (100);
24445 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
24451 while (CONSP (cdr
))
24453 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
24454 font
, width_p
, align_to
))
24457 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= false;
24462 if (EQ (car
, Qminus
))
24464 return OK_PIXELS (pixels
);
24467 car
= buffer_local_value (car
, it
->w
->contents
);
24468 if (EQ (car
, Qunbound
))
24475 pixels
= XFLOATINT (car
);
24477 return OK_PIXELS (pixels
);
24478 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
24479 font
, width_p
, align_to
))
24480 return OK_PIXELS (pixels
* fact
);
24491 get_font_ascent_descent (struct font
*font
, int *ascent
, int *descent
)
24493 #ifdef HAVE_WINDOW_SYSTEM
24494 normal_char_ascent_descent (font
, -1, ascent
, descent
);
24502 /***********************************************************************
24504 ***********************************************************************/
24506 #ifdef HAVE_WINDOW_SYSTEM
24511 dump_glyph_string (struct glyph_string
*s
)
24513 fprintf (stderr
, "glyph string\n");
24514 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
24515 s
->x
, s
->y
, s
->width
, s
->height
);
24516 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
24517 fprintf (stderr
, " hl = %d\n", s
->hl
);
24518 fprintf (stderr
, " left overhang = %d, right = %d\n",
24519 s
->left_overhang
, s
->right_overhang
);
24520 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
24521 fprintf (stderr
, " extends to end of line = %d\n",
24522 s
->extends_to_end_of_line_p
);
24523 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
24524 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
24527 #endif /* GLYPH_DEBUG */
24529 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
24530 of XChar2b structures for S; it can't be allocated in
24531 init_glyph_string because it must be allocated via `alloca'. W
24532 is the window on which S is drawn. ROW and AREA are the glyph row
24533 and area within the row from which S is constructed. START is the
24534 index of the first glyph structure covered by S. HL is a
24535 face-override for drawing S. */
24538 #define OPTIONAL_HDC(hdc) HDC hdc,
24539 #define DECLARE_HDC(hdc) HDC hdc;
24540 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
24541 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
24544 #ifndef OPTIONAL_HDC
24545 #define OPTIONAL_HDC(hdc)
24546 #define DECLARE_HDC(hdc)
24547 #define ALLOCATE_HDC(hdc, f)
24548 #define RELEASE_HDC(hdc, f)
24552 init_glyph_string (struct glyph_string
*s
,
24554 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
24555 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
24557 memset (s
, 0, sizeof *s
);
24559 s
->f
= XFRAME (w
->frame
);
24563 s
->display
= FRAME_X_DISPLAY (s
->f
);
24564 s
->window
= FRAME_X_WINDOW (s
->f
);
24565 s
->char2b
= char2b
;
24569 s
->first_glyph
= row
->glyphs
[area
] + start
;
24570 s
->height
= row
->height
;
24571 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
24572 s
->ybase
= s
->y
+ row
->ascent
;
24576 /* Append the list of glyph strings with head H and tail T to the list
24577 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
24580 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24581 struct glyph_string
*h
, struct glyph_string
*t
)
24595 /* Prepend the list of glyph strings with head H and tail T to the
24596 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
24600 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24601 struct glyph_string
*h
, struct glyph_string
*t
)
24615 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
24616 Set *HEAD and *TAIL to the resulting list. */
24619 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
24620 struct glyph_string
*s
)
24622 s
->next
= s
->prev
= NULL
;
24623 append_glyph_string_lists (head
, tail
, s
, s
);
24627 /* Get face and two-byte form of character C in face FACE_ID on frame F.
24628 The encoding of C is returned in *CHAR2B. DISPLAY_P means
24629 make sure that X resources for the face returned are allocated.
24630 Value is a pointer to a realized face that is ready for display if
24633 static struct face
*
24634 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
24635 XChar2b
*char2b
, bool display_p
)
24637 struct face
*face
= FACE_FROM_ID (f
, face_id
);
24642 code
= face
->font
->driver
->encode_char (face
->font
, c
);
24644 if (code
== FONT_INVALID_CODE
)
24647 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24649 /* Make sure X resources of the face are allocated. */
24650 #ifdef HAVE_X_WINDOWS
24654 eassert (face
!= NULL
);
24655 prepare_face_for_display (f
, face
);
24662 /* Get face and two-byte form of character glyph GLYPH on frame F.
24663 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
24664 a pointer to a realized face that is ready for display. */
24666 static struct face
*
24667 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
24673 eassert (glyph
->type
== CHAR_GLYPH
);
24674 face
= FACE_FROM_ID (f
, glyph
->face_id
);
24676 /* Make sure X resources of the face are allocated. */
24677 prepare_face_for_display (f
, face
);
24681 if (CHAR_BYTE8_P (glyph
->u
.ch
))
24682 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
24684 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
24686 if (code
== FONT_INVALID_CODE
)
24690 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24695 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
24696 Return true iff FONT has a glyph for C. */
24699 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
24703 if (CHAR_BYTE8_P (c
))
24704 code
= CHAR_TO_BYTE8 (c
);
24706 code
= font
->driver
->encode_char (font
, c
);
24708 if (code
== FONT_INVALID_CODE
)
24710 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24715 /* Fill glyph string S with composition components specified by S->cmp.
24717 BASE_FACE is the base face of the composition.
24718 S->cmp_from is the index of the first component for S.
24720 OVERLAPS non-zero means S should draw the foreground only, and use
24721 its physical height for clipping. See also draw_glyphs.
24723 Value is the index of a component not in S. */
24726 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
24730 /* For all glyphs of this composition, starting at the offset
24731 S->cmp_from, until we reach the end of the definition or encounter a
24732 glyph that requires the different face, add it to S. */
24737 s
->for_overlaps
= overlaps
;
24740 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
24742 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
24744 /* TAB in a composition means display glyphs with padding space
24745 on the left or right. */
24748 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
24751 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
24752 s
->char2b
+ i
, true);
24758 s
->font
= s
->face
->font
;
24760 else if (s
->face
!= face
)
24768 if (s
->face
== NULL
)
24770 s
->face
= base_face
->ascii_face
;
24771 s
->font
= s
->face
->font
;
24774 /* All glyph strings for the same composition has the same width,
24775 i.e. the width set for the first component of the composition. */
24776 s
->width
= s
->first_glyph
->pixel_width
;
24778 /* If the specified font could not be loaded, use the frame's
24779 default font, but record the fact that we couldn't load it in
24780 the glyph string so that we can draw rectangles for the
24781 characters of the glyph string. */
24782 if (s
->font
== NULL
)
24784 s
->font_not_found_p
= true;
24785 s
->font
= FRAME_FONT (s
->f
);
24788 /* Adjust base line for subscript/superscript text. */
24789 s
->ybase
+= s
->first_glyph
->voffset
;
24795 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
24796 int start
, int end
, int overlaps
)
24798 struct glyph
*glyph
, *last
;
24799 Lisp_Object lgstring
;
24802 s
->for_overlaps
= overlaps
;
24803 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24804 last
= s
->row
->glyphs
[s
->area
] + end
;
24805 s
->cmp_id
= glyph
->u
.cmp
.id
;
24806 s
->cmp_from
= glyph
->slice
.cmp
.from
;
24807 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
24808 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24809 lgstring
= composition_gstring_from_id (s
->cmp_id
);
24810 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
24812 while (glyph
< last
24813 && glyph
->u
.cmp
.automatic
24814 && glyph
->u
.cmp
.id
== s
->cmp_id
24815 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
24816 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
24818 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
24820 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
24821 unsigned code
= LGLYPH_CODE (lglyph
);
24823 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
24825 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
24826 return glyph
- s
->row
->glyphs
[s
->area
];
24830 /* Fill glyph string S from a sequence glyphs for glyphless characters.
24831 See the comment of fill_glyph_string for arguments.
24832 Value is the index of the first glyph not in S. */
24836 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
24837 int start
, int end
, int overlaps
)
24839 struct glyph
*glyph
, *last
;
24842 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
24843 s
->for_overlaps
= overlaps
;
24844 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24845 last
= s
->row
->glyphs
[s
->area
] + end
;
24846 voffset
= glyph
->voffset
;
24847 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24848 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
24850 s
->width
= glyph
->pixel_width
;
24852 while (glyph
< last
24853 && glyph
->type
== GLYPHLESS_GLYPH
24854 && glyph
->voffset
== voffset
24855 && glyph
->face_id
== face_id
)
24858 s
->width
+= glyph
->pixel_width
;
24861 s
->ybase
+= voffset
;
24862 return glyph
- s
->row
->glyphs
[s
->area
];
24866 /* Fill glyph string S from a sequence of character glyphs.
24868 FACE_ID is the face id of the string. START is the index of the
24869 first glyph to consider, END is the index of the last + 1.
24870 OVERLAPS non-zero means S should draw the foreground only, and use
24871 its physical height for clipping. See also draw_glyphs.
24873 Value is the index of the first glyph not in S. */
24876 fill_glyph_string (struct glyph_string
*s
, int face_id
,
24877 int start
, int end
, int overlaps
)
24879 struct glyph
*glyph
, *last
;
24881 bool glyph_not_available_p
;
24883 eassert (s
->f
== XFRAME (s
->w
->frame
));
24884 eassert (s
->nchars
== 0);
24885 eassert (start
>= 0 && end
> start
);
24887 s
->for_overlaps
= overlaps
;
24888 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24889 last
= s
->row
->glyphs
[s
->area
] + end
;
24890 voffset
= glyph
->voffset
;
24891 s
->padding_p
= glyph
->padding_p
;
24892 glyph_not_available_p
= glyph
->glyph_not_available_p
;
24894 while (glyph
< last
24895 && glyph
->type
== CHAR_GLYPH
24896 && glyph
->voffset
== voffset
24897 /* Same face id implies same font, nowadays. */
24898 && glyph
->face_id
== face_id
24899 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
24901 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
24902 s
->char2b
+ s
->nchars
);
24904 eassert (s
->nchars
<= end
- start
);
24905 s
->width
+= glyph
->pixel_width
;
24906 if (glyph
++->padding_p
!= s
->padding_p
)
24910 s
->font
= s
->face
->font
;
24912 /* If the specified font could not be loaded, use the frame's font,
24913 but record the fact that we couldn't load it in
24914 S->font_not_found_p so that we can draw rectangles for the
24915 characters of the glyph string. */
24916 if (s
->font
== NULL
|| glyph_not_available_p
)
24918 s
->font_not_found_p
= true;
24919 s
->font
= FRAME_FONT (s
->f
);
24922 /* Adjust base line for subscript/superscript text. */
24923 s
->ybase
+= voffset
;
24925 eassert (s
->face
&& s
->face
->gc
);
24926 return glyph
- s
->row
->glyphs
[s
->area
];
24930 /* Fill glyph string S from image glyph S->first_glyph. */
24933 fill_image_glyph_string (struct glyph_string
*s
)
24935 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
24936 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
24938 s
->slice
= s
->first_glyph
->slice
.img
;
24939 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24940 s
->font
= s
->face
->font
;
24941 s
->width
= s
->first_glyph
->pixel_width
;
24943 /* Adjust base line for subscript/superscript text. */
24944 s
->ybase
+= s
->first_glyph
->voffset
;
24948 #ifdef HAVE_XWIDGETS
24950 fill_xwidget_glyph_string (struct glyph_string
*s
)
24952 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
24953 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24954 s
->font
= s
->face
->font
;
24955 s
->width
= s
->first_glyph
->pixel_width
;
24956 s
->ybase
+= s
->first_glyph
->voffset
;
24957 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
24960 /* Fill glyph string S from a sequence of stretch glyphs.
24962 START is the index of the first glyph to consider,
24963 END is the index of the last + 1.
24965 Value is the index of the first glyph not in S. */
24968 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
24970 struct glyph
*glyph
, *last
;
24971 int voffset
, face_id
;
24973 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
24975 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24976 last
= s
->row
->glyphs
[s
->area
] + end
;
24977 face_id
= glyph
->face_id
;
24978 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24979 s
->font
= s
->face
->font
;
24980 s
->width
= glyph
->pixel_width
;
24982 voffset
= glyph
->voffset
;
24986 && glyph
->type
== STRETCH_GLYPH
24987 && glyph
->voffset
== voffset
24988 && glyph
->face_id
== face_id
);
24990 s
->width
+= glyph
->pixel_width
;
24992 /* Adjust base line for subscript/superscript text. */
24993 s
->ybase
+= voffset
;
24995 /* The case that face->gc == 0 is handled when drawing the glyph
24996 string by calling prepare_face_for_display. */
24998 return glyph
- s
->row
->glyphs
[s
->area
];
25001 static struct font_metrics
*
25002 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
25004 static struct font_metrics metrics
;
25009 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
25010 if (code
== FONT_INVALID_CODE
)
25012 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
25016 /* A subroutine that computes "normal" values of ASCENT and DESCENT
25017 for FONT. Values are taken from font-global ones, except for fonts
25018 that claim preposterously large values, but whose glyphs actually
25019 have reasonable dimensions. C is the character to use for metrics
25020 if the font-global values are too large; if C is negative, the
25021 function selects a default character. */
25023 normal_char_ascent_descent (struct font
*font
, int c
, int *ascent
, int *descent
)
25025 *ascent
= FONT_BASE (font
);
25026 *descent
= FONT_DESCENT (font
);
25028 if (FONT_TOO_HIGH (font
))
25032 /* Get metrics of C, defaulting to a reasonably sized ASCII
25034 if (get_char_glyph_code (c
>= 0 ? c
: '{', font
, &char2b
))
25036 struct font_metrics
*pcm
= get_per_char_metric (font
, &char2b
);
25038 if (!(pcm
->width
== 0 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0))
25040 /* We add 1 pixel to character dimensions as heuristics
25041 that produces nicer display, e.g. when the face has
25042 the box attribute. */
25043 *ascent
= pcm
->ascent
+ 1;
25044 *descent
= pcm
->descent
+ 1;
25050 /* A subroutine that computes a reasonable "normal character height"
25051 for fonts that claim preposterously large vertical dimensions, but
25052 whose glyphs are actually reasonably sized. C is the character
25053 whose metrics to use for those fonts, or -1 for default
25056 normal_char_height (struct font
*font
, int c
)
25058 int ascent
, descent
;
25060 normal_char_ascent_descent (font
, c
, &ascent
, &descent
);
25062 return ascent
+ descent
;
25066 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
25067 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
25068 assumed to be zero. */
25071 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
25073 *left
= *right
= 0;
25075 if (glyph
->type
== CHAR_GLYPH
)
25078 struct face
*face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
);
25081 struct font_metrics
*pcm
= get_per_char_metric (face
->font
, &char2b
);
25084 if (pcm
->rbearing
> pcm
->width
)
25085 *right
= pcm
->rbearing
- pcm
->width
;
25086 if (pcm
->lbearing
< 0)
25087 *left
= -pcm
->lbearing
;
25091 else if (glyph
->type
== COMPOSITE_GLYPH
)
25093 if (! glyph
->u
.cmp
.automatic
)
25095 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
25097 if (cmp
->rbearing
> cmp
->pixel_width
)
25098 *right
= cmp
->rbearing
- cmp
->pixel_width
;
25099 if (cmp
->lbearing
< 0)
25100 *left
= - cmp
->lbearing
;
25104 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
25105 struct font_metrics metrics
;
25107 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
25108 glyph
->slice
.cmp
.to
+ 1, &metrics
);
25109 if (metrics
.rbearing
> metrics
.width
)
25110 *right
= metrics
.rbearing
- metrics
.width
;
25111 if (metrics
.lbearing
< 0)
25112 *left
= - metrics
.lbearing
;
25118 /* Return the index of the first glyph preceding glyph string S that
25119 is overwritten by S because of S's left overhang. Value is -1
25120 if no glyphs are overwritten. */
25123 left_overwritten (struct glyph_string
*s
)
25127 if (s
->left_overhang
)
25130 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25131 int first
= s
->first_glyph
- glyphs
;
25133 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
25134 x
-= glyphs
[i
].pixel_width
;
25145 /* Return the index of the first glyph preceding glyph string S that
25146 is overwriting S because of its right overhang. Value is -1 if no
25147 glyph in front of S overwrites S. */
25150 left_overwriting (struct glyph_string
*s
)
25153 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25154 int first
= s
->first_glyph
- glyphs
;
25158 for (i
= first
- 1; i
>= 0; --i
)
25161 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
25164 x
-= glyphs
[i
].pixel_width
;
25171 /* Return the index of the last glyph following glyph string S that is
25172 overwritten by S because of S's right overhang. Value is -1 if
25173 no such glyph is found. */
25176 right_overwritten (struct glyph_string
*s
)
25180 if (s
->right_overhang
)
25183 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25184 int first
= (s
->first_glyph
- glyphs
25185 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
25186 int end
= s
->row
->used
[s
->area
];
25188 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
25189 x
+= glyphs
[i
].pixel_width
;
25198 /* Return the index of the last glyph following glyph string S that
25199 overwrites S because of its left overhang. Value is negative
25200 if no such glyph is found. */
25203 right_overwriting (struct glyph_string
*s
)
25206 int end
= s
->row
->used
[s
->area
];
25207 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25208 int first
= (s
->first_glyph
- glyphs
25209 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
25213 for (i
= first
; i
< end
; ++i
)
25216 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
25219 x
+= glyphs
[i
].pixel_width
;
25226 /* Set background width of glyph string S. START is the index of the
25227 first glyph following S. LAST_X is the right-most x-position + 1
25228 in the drawing area. */
25231 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
25233 /* If the face of this glyph string has to be drawn to the end of
25234 the drawing area, set S->extends_to_end_of_line_p. */
25236 if (start
== s
->row
->used
[s
->area
]
25237 && ((s
->row
->fill_line_p
25238 && (s
->hl
== DRAW_NORMAL_TEXT
25239 || s
->hl
== DRAW_IMAGE_RAISED
25240 || s
->hl
== DRAW_IMAGE_SUNKEN
))
25241 || s
->hl
== DRAW_MOUSE_FACE
))
25242 s
->extends_to_end_of_line_p
= true;
25244 /* If S extends its face to the end of the line, set its
25245 background_width to the distance to the right edge of the drawing
25247 if (s
->extends_to_end_of_line_p
)
25248 s
->background_width
= last_x
- s
->x
+ 1;
25250 s
->background_width
= s
->width
;
25254 /* Compute overhangs and x-positions for glyph string S and its
25255 predecessors, or successors. X is the starting x-position for S.
25256 BACKWARD_P means process predecessors. */
25259 compute_overhangs_and_x (struct glyph_string
*s
, int x
, bool backward_p
)
25265 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
25266 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
25276 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
25277 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
25287 /* The following macros are only called from draw_glyphs below.
25288 They reference the following parameters of that function directly:
25289 `w', `row', `area', and `overlap_p'
25290 as well as the following local variables:
25291 `s', `f', and `hdc' (in W32) */
25294 /* On W32, silently add local `hdc' variable to argument list of
25295 init_glyph_string. */
25296 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
25297 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
25299 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
25300 init_glyph_string (s, char2b, w, row, area, start, hl)
25303 /* Add a glyph string for a stretch glyph to the list of strings
25304 between HEAD and TAIL. START is the index of the stretch glyph in
25305 row area AREA of glyph row ROW. END is the index of the last glyph
25306 in that glyph row area. X is the current output position assigned
25307 to the new glyph string constructed. HL overrides that face of the
25308 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
25309 is the right-most x-position of the drawing area. */
25311 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
25312 and below -- keep them on one line. */
25313 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25316 s = alloca (sizeof *s); \
25317 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25318 START = fill_stretch_glyph_string (s, START, END); \
25319 append_glyph_string (&HEAD, &TAIL, s); \
25325 /* Add a glyph string for an image glyph to the list of strings
25326 between HEAD and TAIL. START is the index of the image glyph in
25327 row area AREA of glyph row ROW. END is the index of the last glyph
25328 in that glyph row area. X is the current output position assigned
25329 to the new glyph string constructed. HL overrides that face of the
25330 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
25331 is the right-most x-position of the drawing area. */
25333 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25336 s = alloca (sizeof *s); \
25337 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25338 fill_image_glyph_string (s); \
25339 append_glyph_string (&HEAD, &TAIL, s); \
25345 #ifndef HAVE_XWIDGETS
25346 # define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25349 # define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25352 s = alloca (sizeof *s); \
25353 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25354 fill_xwidget_glyph_string (s); \
25355 append_glyph_string (&(HEAD), &(TAIL), s); \
25362 /* Add a glyph string for a sequence of character glyphs to the list
25363 of strings between HEAD and TAIL. START is the index of the first
25364 glyph in row area AREA of glyph row ROW that is part of the new
25365 glyph string. END is the index of the last glyph in that glyph row
25366 area. X is the current output position assigned to the new glyph
25367 string constructed. HL overrides that face of the glyph; e.g. it
25368 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
25369 right-most x-position of the drawing area. */
25371 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25377 face_id = (row)->glyphs[area][START].face_id; \
25379 s = alloca (sizeof *s); \
25380 SAFE_NALLOCA (char2b, 1, (END) - (START)); \
25381 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25382 append_glyph_string (&HEAD, &TAIL, s); \
25384 START = fill_glyph_string (s, face_id, START, END, overlaps); \
25389 /* Add a glyph string for a composite sequence to the list of strings
25390 between HEAD and TAIL. START is the index of the first glyph in
25391 row area AREA of glyph row ROW that is part of the new glyph
25392 string. END is the index of the last glyph in that glyph row area.
25393 X is the current output position assigned to the new glyph string
25394 constructed. HL overrides that face of the glyph; e.g. it is
25395 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
25396 x-position of the drawing area. */
25398 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25400 int face_id = (row)->glyphs[area][START].face_id; \
25401 struct face *base_face = FACE_FROM_ID (f, face_id); \
25402 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
25403 struct composition *cmp = composition_table[cmp_id]; \
25405 struct glyph_string *first_s = NULL; \
25408 SAFE_NALLOCA (char2b, 1, cmp->glyph_len); \
25410 /* Make glyph_strings for each glyph sequence that is drawable by \
25411 the same face, and append them to HEAD/TAIL. */ \
25412 for (n = 0; n < cmp->glyph_len;) \
25414 s = alloca (sizeof *s); \
25415 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25416 append_glyph_string (&(HEAD), &(TAIL), s); \
25422 n = fill_composite_glyph_string (s, base_face, overlaps); \
25430 /* Add a glyph string for a glyph-string sequence to the list of strings
25431 between HEAD and TAIL. */
25433 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25437 Lisp_Object gstring; \
25439 face_id = (row)->glyphs[area][START].face_id; \
25440 gstring = (composition_gstring_from_id \
25441 ((row)->glyphs[area][START].u.cmp.id)); \
25442 s = alloca (sizeof *s); \
25443 SAFE_NALLOCA (char2b, 1, LGSTRING_GLYPH_LEN (gstring)); \
25444 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25445 append_glyph_string (&(HEAD), &(TAIL), s); \
25447 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
25451 /* Add a glyph string for a sequence of glyphless character's glyphs
25452 to the list of strings between HEAD and TAIL. The meanings of
25453 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
25455 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25460 face_id = (row)->glyphs[area][START].face_id; \
25462 s = alloca (sizeof *s); \
25463 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25464 append_glyph_string (&HEAD, &TAIL, s); \
25466 START = fill_glyphless_glyph_string (s, face_id, START, END, \
25472 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
25473 of AREA of glyph row ROW on window W between indices START and END.
25474 HL overrides the face for drawing glyph strings, e.g. it is
25475 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
25476 x-positions of the drawing area.
25478 This is an ugly monster macro construct because we must use alloca
25479 to allocate glyph strings (because draw_glyphs can be called
25480 asynchronously). */
25482 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25485 HEAD = TAIL = NULL; \
25486 while (START < END) \
25488 struct glyph *first_glyph = (row)->glyphs[area] + START; \
25489 switch (first_glyph->type) \
25492 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
25496 case COMPOSITE_GLYPH: \
25497 if (first_glyph->u.cmp.automatic) \
25498 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
25501 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
25505 case STRETCH_GLYPH: \
25506 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
25510 case IMAGE_GLYPH: \
25511 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
25515 #define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25516 case XWIDGET_GLYPH: \
25517 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
25521 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
25522 case GLYPHLESS_GLYPH: \
25523 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
25533 set_glyph_string_background_width (s, START, LAST_X); \
25540 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25541 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25542 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25543 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
25546 /* Draw glyphs between START and END in AREA of ROW on window W,
25547 starting at x-position X. X is relative to AREA in W. HL is a
25548 face-override with the following meaning:
25550 DRAW_NORMAL_TEXT draw normally
25551 DRAW_CURSOR draw in cursor face
25552 DRAW_MOUSE_FACE draw in mouse face.
25553 DRAW_INVERSE_VIDEO draw in mode line face
25554 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
25555 DRAW_IMAGE_RAISED draw an image with a raised relief around it
25557 If OVERLAPS is non-zero, draw only the foreground of characters and
25558 clip to the physical height of ROW. Non-zero value also defines
25559 the overlapping part to be drawn:
25561 OVERLAPS_PRED overlap with preceding rows
25562 OVERLAPS_SUCC overlap with succeeding rows
25563 OVERLAPS_BOTH overlap with both preceding/succeeding rows
25564 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
25566 Value is the x-position reached, relative to AREA of W. */
25569 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
25570 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
25571 enum draw_glyphs_face hl
, int overlaps
)
25573 struct glyph_string
*head
, *tail
;
25574 struct glyph_string
*s
;
25575 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
25576 int i
, j
, x_reached
, last_x
, area_left
= 0;
25577 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25580 ALLOCATE_HDC (hdc
, f
);
25582 /* Let's rather be paranoid than getting a SEGV. */
25583 end
= min (end
, row
->used
[area
]);
25584 start
= clip_to_bounds (0, start
, end
);
25586 /* Translate X to frame coordinates. Set last_x to the right
25587 end of the drawing area. */
25588 if (row
->full_width_p
)
25590 /* X is relative to the left edge of W, without scroll bars
25592 area_left
= WINDOW_LEFT_EDGE_X (w
);
25593 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
25594 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
25598 area_left
= window_box_left (w
, area
);
25599 last_x
= area_left
+ window_box_width (w
, area
);
25603 /* Build a doubly-linked list of glyph_string structures between
25604 head and tail from what we have to draw. Note that the macro
25605 BUILD_GLYPH_STRINGS will modify its start parameter. That's
25606 the reason we use a separate variable `i'. */
25609 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
25611 x_reached
= tail
->x
+ tail
->background_width
;
25615 /* If there are any glyphs with lbearing < 0 or rbearing > width in
25616 the row, redraw some glyphs in front or following the glyph
25617 strings built above. */
25618 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
25620 struct glyph_string
*h
, *t
;
25621 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25622 int mouse_beg_col UNINIT
, mouse_end_col UNINIT
;
25623 bool check_mouse_face
= false;
25626 /* If mouse highlighting is on, we may need to draw adjacent
25627 glyphs using mouse-face highlighting. */
25628 if (area
== TEXT_AREA
&& row
->mouse_face_p
25629 && hlinfo
->mouse_face_beg_row
>= 0
25630 && hlinfo
->mouse_face_end_row
>= 0)
25632 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
25634 if (row_vpos
>= hlinfo
->mouse_face_beg_row
25635 && row_vpos
<= hlinfo
->mouse_face_end_row
)
25637 check_mouse_face
= true;
25638 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
25639 ? hlinfo
->mouse_face_beg_col
: 0;
25640 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
25641 ? hlinfo
->mouse_face_end_col
25642 : row
->used
[TEXT_AREA
];
25646 /* Compute overhangs for all glyph strings. */
25647 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
25648 for (s
= head
; s
; s
= s
->next
)
25649 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
25651 /* Prepend glyph strings for glyphs in front of the first glyph
25652 string that are overwritten because of the first glyph
25653 string's left overhang. The background of all strings
25654 prepended must be drawn because the first glyph string
25656 i
= left_overwritten (head
);
25659 enum draw_glyphs_face overlap_hl
;
25661 /* If this row contains mouse highlighting, attempt to draw
25662 the overlapped glyphs with the correct highlight. This
25663 code fails if the overlap encompasses more than one glyph
25664 and mouse-highlight spans only some of these glyphs.
25665 However, making it work perfectly involves a lot more
25666 code, and I don't know if the pathological case occurs in
25667 practice, so we'll stick to this for now. --- cyd */
25668 if (check_mouse_face
25669 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25670 overlap_hl
= DRAW_MOUSE_FACE
;
25672 overlap_hl
= DRAW_NORMAL_TEXT
;
25674 if (hl
!= overlap_hl
)
25677 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
25678 overlap_hl
, dummy_x
, last_x
);
25680 compute_overhangs_and_x (t
, head
->x
, true);
25681 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25682 if (clip_head
== NULL
)
25686 /* Prepend glyph strings for glyphs in front of the first glyph
25687 string that overwrite that glyph string because of their
25688 right overhang. For these strings, only the foreground must
25689 be drawn, because it draws over the glyph string at `head'.
25690 The background must not be drawn because this would overwrite
25691 right overhangs of preceding glyphs for which no glyph
25693 i
= left_overwriting (head
);
25696 enum draw_glyphs_face overlap_hl
;
25698 if (check_mouse_face
25699 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25700 overlap_hl
= DRAW_MOUSE_FACE
;
25702 overlap_hl
= DRAW_NORMAL_TEXT
;
25704 if (hl
== overlap_hl
|| clip_head
== NULL
)
25706 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
25707 overlap_hl
, dummy_x
, last_x
);
25708 for (s
= h
; s
; s
= s
->next
)
25709 s
->background_filled_p
= true;
25710 compute_overhangs_and_x (t
, head
->x
, true);
25711 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25714 /* Append glyphs strings for glyphs following the last glyph
25715 string tail that are overwritten by tail. The background of
25716 these strings has to be drawn because tail's foreground draws
25718 i
= right_overwritten (tail
);
25721 enum draw_glyphs_face overlap_hl
;
25723 if (check_mouse_face
25724 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25725 overlap_hl
= DRAW_MOUSE_FACE
;
25727 overlap_hl
= DRAW_NORMAL_TEXT
;
25729 if (hl
!= overlap_hl
)
25731 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25732 overlap_hl
, x
, last_x
);
25733 /* Because BUILD_GLYPH_STRINGS updates the first argument,
25734 we don't have `end = i;' here. */
25735 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25736 append_glyph_string_lists (&head
, &tail
, h
, t
);
25737 if (clip_tail
== NULL
)
25741 /* Append glyph strings for glyphs following the last glyph
25742 string tail that overwrite tail. The foreground of such
25743 glyphs has to be drawn because it writes into the background
25744 of tail. The background must not be drawn because it could
25745 paint over the foreground of following glyphs. */
25746 i
= right_overwriting (tail
);
25749 enum draw_glyphs_face overlap_hl
;
25750 if (check_mouse_face
25751 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25752 overlap_hl
= DRAW_MOUSE_FACE
;
25754 overlap_hl
= DRAW_NORMAL_TEXT
;
25756 if (hl
== overlap_hl
|| clip_tail
== NULL
)
25758 i
++; /* We must include the Ith glyph. */
25759 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25760 overlap_hl
, x
, last_x
);
25761 for (s
= h
; s
; s
= s
->next
)
25762 s
->background_filled_p
= true;
25763 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25764 append_glyph_string_lists (&head
, &tail
, h
, t
);
25766 if (clip_head
|| clip_tail
)
25767 for (s
= head
; s
; s
= s
->next
)
25769 s
->clip_head
= clip_head
;
25770 s
->clip_tail
= clip_tail
;
25774 /* Draw all strings. */
25775 for (s
= head
; s
; s
= s
->next
)
25776 FRAME_RIF (f
)->draw_glyph_string (s
);
25779 /* When focus a sole frame and move horizontally, this clears on_p
25780 causing a failure to erase prev cursor position. */
25781 if (area
== TEXT_AREA
25782 && !row
->full_width_p
25783 /* When drawing overlapping rows, only the glyph strings'
25784 foreground is drawn, which doesn't erase a cursor
25788 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
25789 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
25790 : (tail
? tail
->x
+ tail
->background_width
: x
));
25794 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
25795 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
25799 /* Value is the x-position up to which drawn, relative to AREA of W.
25800 This doesn't include parts drawn because of overhangs. */
25801 if (row
->full_width_p
)
25802 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
25804 x_reached
-= area_left
;
25806 RELEASE_HDC (hdc
, f
);
25812 /* Expand row matrix if too narrow. Don't expand if area
25815 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
25817 if (!it->f->fonts_changed \
25818 && (it->glyph_row->glyphs[area] \
25819 < it->glyph_row->glyphs[area + 1])) \
25821 it->w->ncols_scale_factor++; \
25822 it->f->fonts_changed = true; \
25826 /* Store one glyph for IT->char_to_display in IT->glyph_row.
25827 Called from x_produce_glyphs when IT->glyph_row is non-null. */
25830 append_glyph (struct it
*it
)
25832 struct glyph
*glyph
;
25833 enum glyph_row_area area
= it
->area
;
25835 eassert (it
->glyph_row
);
25836 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
25838 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25839 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25841 /* If the glyph row is reversed, we need to prepend the glyph
25842 rather than append it. */
25843 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25847 /* Make room for the additional glyph. */
25848 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25850 glyph
= it
->glyph_row
->glyphs
[area
];
25852 glyph
->charpos
= CHARPOS (it
->position
);
25853 glyph
->object
= it
->object
;
25854 if (it
->pixel_width
> 0)
25856 eassert (it
->pixel_width
<= SHRT_MAX
);
25857 glyph
->pixel_width
= it
->pixel_width
;
25858 glyph
->padding_p
= false;
25862 /* Assure at least 1-pixel width. Otherwise, cursor can't
25863 be displayed correctly. */
25864 glyph
->pixel_width
= 1;
25865 glyph
->padding_p
= true;
25867 glyph
->ascent
= it
->ascent
;
25868 glyph
->descent
= it
->descent
;
25869 glyph
->voffset
= it
->voffset
;
25870 glyph
->type
= CHAR_GLYPH
;
25871 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25872 glyph
->multibyte_p
= it
->multibyte_p
;
25873 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25875 /* In R2L rows, the left and the right box edges need to be
25876 drawn in reverse direction. */
25877 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25878 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25882 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25883 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25885 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25886 || it
->phys_descent
> it
->descent
);
25887 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
25888 glyph
->face_id
= it
->face_id
;
25889 glyph
->u
.ch
= it
->char_to_display
;
25890 glyph
->slice
.img
= null_glyph_slice
;
25891 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25894 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25895 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25896 glyph
->bidi_type
= it
->bidi_it
.type
;
25900 glyph
->resolved_level
= 0;
25901 glyph
->bidi_type
= UNKNOWN_BT
;
25903 ++it
->glyph_row
->used
[area
];
25906 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25909 /* Store one glyph for the composition IT->cmp_it.id in
25910 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
25914 append_composite_glyph (struct it
*it
)
25916 struct glyph
*glyph
;
25917 enum glyph_row_area area
= it
->area
;
25919 eassert (it
->glyph_row
);
25921 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25922 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25924 /* If the glyph row is reversed, we need to prepend the glyph
25925 rather than append it. */
25926 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
25930 /* Make room for the new glyph. */
25931 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
25933 glyph
= it
->glyph_row
->glyphs
[it
->area
];
25935 glyph
->charpos
= it
->cmp_it
.charpos
;
25936 glyph
->object
= it
->object
;
25937 eassert (it
->pixel_width
<= SHRT_MAX
);
25938 glyph
->pixel_width
= it
->pixel_width
;
25939 glyph
->ascent
= it
->ascent
;
25940 glyph
->descent
= it
->descent
;
25941 glyph
->voffset
= it
->voffset
;
25942 glyph
->type
= COMPOSITE_GLYPH
;
25943 if (it
->cmp_it
.ch
< 0)
25945 glyph
->u
.cmp
.automatic
= false;
25946 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25947 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
25951 glyph
->u
.cmp
.automatic
= true;
25952 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25953 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
25954 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
25956 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25957 glyph
->multibyte_p
= it
->multibyte_p
;
25958 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25960 /* In R2L rows, the left and the right box edges need to be
25961 drawn in reverse direction. */
25962 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25963 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25967 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25968 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25970 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25971 || it
->phys_descent
> it
->descent
);
25972 glyph
->padding_p
= false;
25973 glyph
->glyph_not_available_p
= false;
25974 glyph
->face_id
= it
->face_id
;
25975 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25978 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25979 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25980 glyph
->bidi_type
= it
->bidi_it
.type
;
25982 ++it
->glyph_row
->used
[area
];
25985 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25989 /* Change IT->ascent and IT->height according to the setting of
25993 take_vertical_position_into_account (struct it
*it
)
25997 if (it
->voffset
< 0)
25998 /* Increase the ascent so that we can display the text higher
26000 it
->ascent
-= it
->voffset
;
26002 /* Increase the descent so that we can display the text lower
26004 it
->descent
+= it
->voffset
;
26009 /* Produce glyphs/get display metrics for the image IT is loaded with.
26010 See the description of struct display_iterator in dispextern.h for
26011 an overview of struct display_iterator. */
26014 produce_image_glyph (struct it
*it
)
26018 int glyph_ascent
, crop
;
26019 struct glyph_slice slice
;
26021 eassert (it
->what
== IT_IMAGE
);
26023 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26024 /* Make sure X resources of the face is loaded. */
26025 prepare_face_for_display (it
->f
, face
);
26027 if (it
->image_id
< 0)
26029 /* Fringe bitmap. */
26030 it
->ascent
= it
->phys_ascent
= 0;
26031 it
->descent
= it
->phys_descent
= 0;
26032 it
->pixel_width
= 0;
26037 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
26038 /* Make sure X resources of the image is loaded. */
26039 prepare_image_for_display (it
->f
, img
);
26041 slice
.x
= slice
.y
= 0;
26042 slice
.width
= img
->width
;
26043 slice
.height
= img
->height
;
26045 if (INTEGERP (it
->slice
.x
))
26046 slice
.x
= XINT (it
->slice
.x
);
26047 else if (FLOATP (it
->slice
.x
))
26048 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
26050 if (INTEGERP (it
->slice
.y
))
26051 slice
.y
= XINT (it
->slice
.y
);
26052 else if (FLOATP (it
->slice
.y
))
26053 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
26055 if (INTEGERP (it
->slice
.width
))
26056 slice
.width
= XINT (it
->slice
.width
);
26057 else if (FLOATP (it
->slice
.width
))
26058 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
26060 if (INTEGERP (it
->slice
.height
))
26061 slice
.height
= XINT (it
->slice
.height
);
26062 else if (FLOATP (it
->slice
.height
))
26063 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
26065 if (slice
.x
>= img
->width
)
26066 slice
.x
= img
->width
;
26067 if (slice
.y
>= img
->height
)
26068 slice
.y
= img
->height
;
26069 if (slice
.x
+ slice
.width
>= img
->width
)
26070 slice
.width
= img
->width
- slice
.x
;
26071 if (slice
.y
+ slice
.height
> img
->height
)
26072 slice
.height
= img
->height
- slice
.y
;
26074 if (slice
.width
== 0 || slice
.height
== 0)
26077 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
26079 it
->descent
= slice
.height
- glyph_ascent
;
26081 it
->descent
+= img
->vmargin
;
26082 if (slice
.y
+ slice
.height
== img
->height
)
26083 it
->descent
+= img
->vmargin
;
26084 it
->phys_descent
= it
->descent
;
26086 it
->pixel_width
= slice
.width
;
26088 it
->pixel_width
+= img
->hmargin
;
26089 if (slice
.x
+ slice
.width
== img
->width
)
26090 it
->pixel_width
+= img
->hmargin
;
26092 /* It's quite possible for images to have an ascent greater than
26093 their height, so don't get confused in that case. */
26094 if (it
->descent
< 0)
26099 if (face
->box
!= FACE_NO_BOX
)
26101 if (face
->box_line_width
> 0)
26104 it
->ascent
+= face
->box_line_width
;
26105 if (slice
.y
+ slice
.height
== img
->height
)
26106 it
->descent
+= face
->box_line_width
;
26109 if (it
->start_of_box_run_p
&& slice
.x
== 0)
26110 it
->pixel_width
+= eabs (face
->box_line_width
);
26111 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
26112 it
->pixel_width
+= eabs (face
->box_line_width
);
26115 take_vertical_position_into_account (it
);
26117 /* Automatically crop wide image glyphs at right edge so we can
26118 draw the cursor on same display row. */
26119 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
26120 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
26122 it
->pixel_width
-= crop
;
26123 slice
.width
-= crop
;
26128 struct glyph
*glyph
;
26129 enum glyph_row_area area
= it
->area
;
26131 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26132 if (it
->glyph_row
->reversed_p
)
26136 /* Make room for the new glyph. */
26137 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
26139 glyph
= it
->glyph_row
->glyphs
[it
->area
];
26141 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26143 glyph
->charpos
= CHARPOS (it
->position
);
26144 glyph
->object
= it
->object
;
26145 glyph
->pixel_width
= clip_to_bounds (-1, it
->pixel_width
, SHRT_MAX
);
26146 glyph
->ascent
= glyph_ascent
;
26147 glyph
->descent
= it
->descent
;
26148 glyph
->voffset
= it
->voffset
;
26149 glyph
->type
= IMAGE_GLYPH
;
26150 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26151 glyph
->multibyte_p
= it
->multibyte_p
;
26152 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26154 /* In R2L rows, the left and the right box edges need to be
26155 drawn in reverse direction. */
26156 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26157 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26161 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26162 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26164 glyph
->overlaps_vertically_p
= false;
26165 glyph
->padding_p
= false;
26166 glyph
->glyph_not_available_p
= false;
26167 glyph
->face_id
= it
->face_id
;
26168 glyph
->u
.img_id
= img
->id
;
26169 glyph
->slice
.img
= slice
;
26170 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26173 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26174 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26175 glyph
->bidi_type
= it
->bidi_it
.type
;
26177 ++it
->glyph_row
->used
[area
];
26180 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26185 produce_xwidget_glyph (struct it
*it
)
26187 #ifdef HAVE_XWIDGETS
26188 struct xwidget
*xw
;
26189 int glyph_ascent
, crop
;
26190 eassert (it
->what
== IT_XWIDGET
);
26192 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26193 /* Make sure X resources of the face is loaded. */
26194 prepare_face_for_display (it
->f
, face
);
26197 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
26198 it
->descent
= xw
->height
/2;
26199 it
->phys_descent
= it
->descent
;
26200 it
->pixel_width
= xw
->width
;
26201 /* It's quite possible for images to have an ascent greater than
26202 their height, so don't get confused in that case. */
26203 if (it
->descent
< 0)
26208 if (face
->box
!= FACE_NO_BOX
)
26210 if (face
->box_line_width
> 0)
26212 it
->ascent
+= face
->box_line_width
;
26213 it
->descent
+= face
->box_line_width
;
26216 if (it
->start_of_box_run_p
)
26217 it
->pixel_width
+= eabs (face
->box_line_width
);
26218 it
->pixel_width
+= eabs (face
->box_line_width
);
26221 take_vertical_position_into_account (it
);
26223 /* Automatically crop wide image glyphs at right edge so we can
26224 draw the cursor on same display row. */
26225 crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
);
26226 if (crop
> 0 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
26227 it
->pixel_width
-= crop
;
26231 enum glyph_row_area area
= it
->area
;
26232 struct glyph
*glyph
26233 = it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26235 if (it
->glyph_row
->reversed_p
)
26239 /* Make room for the new glyph. */
26240 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
26242 glyph
= it
->glyph_row
->glyphs
[it
->area
];
26244 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26246 glyph
->charpos
= CHARPOS (it
->position
);
26247 glyph
->object
= it
->object
;
26248 glyph
->pixel_width
= clip_to_bounds (-1, it
->pixel_width
, SHRT_MAX
);
26249 glyph
->ascent
= glyph_ascent
;
26250 glyph
->descent
= it
->descent
;
26251 glyph
->voffset
= it
->voffset
;
26252 glyph
->type
= XWIDGET_GLYPH
;
26253 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26254 glyph
->multibyte_p
= it
->multibyte_p
;
26255 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26257 /* In R2L rows, the left and the right box edges need to be
26258 drawn in reverse direction. */
26259 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26260 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26264 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26265 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26267 glyph
->overlaps_vertically_p
= 0;
26268 glyph
->padding_p
= 0;
26269 glyph
->glyph_not_available_p
= 0;
26270 glyph
->face_id
= it
->face_id
;
26271 glyph
->u
.xwidget
= it
->xwidget
;
26272 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26275 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26276 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26277 glyph
->bidi_type
= it
->bidi_it
.type
;
26279 ++it
->glyph_row
->used
[area
];
26282 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26287 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
26288 of the glyph, WIDTH and HEIGHT are the width and height of the
26289 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
26292 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
26293 int width
, int height
, int ascent
)
26295 struct glyph
*glyph
;
26296 enum glyph_row_area area
= it
->area
;
26298 eassert (ascent
>= 0 && ascent
<= height
);
26300 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26301 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26303 /* If the glyph row is reversed, we need to prepend the glyph
26304 rather than append it. */
26305 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26309 /* Make room for the additional glyph. */
26310 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26312 glyph
= it
->glyph_row
->glyphs
[area
];
26314 /* Decrease the width of the first glyph of the row that
26315 begins before first_visible_x (e.g., due to hscroll).
26316 This is so the overall width of the row becomes smaller
26317 by the scroll amount, and the stretch glyph appended by
26318 extend_face_to_end_of_line will be wider, to shift the
26319 row glyphs to the right. (In L2R rows, the corresponding
26320 left-shift effect is accomplished by setting row->x to a
26321 negative value, which won't work with R2L rows.)
26323 This must leave us with a positive value of WIDTH, since
26324 otherwise the call to move_it_in_display_line_to at the
26325 beginning of display_line would have got past the entire
26326 first glyph, and then it->current_x would have been
26327 greater or equal to it->first_visible_x. */
26328 if (it
->current_x
< it
->first_visible_x
)
26329 width
-= it
->first_visible_x
- it
->current_x
;
26330 eassert (width
> 0);
26332 glyph
->charpos
= CHARPOS (it
->position
);
26333 glyph
->object
= object
;
26334 /* FIXME: It would be better to use TYPE_MAX here, but
26335 __typeof__ is not portable enough... */
26336 glyph
->pixel_width
= clip_to_bounds (-1, width
, SHRT_MAX
);
26337 glyph
->ascent
= ascent
;
26338 glyph
->descent
= height
- ascent
;
26339 glyph
->voffset
= it
->voffset
;
26340 glyph
->type
= STRETCH_GLYPH
;
26341 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26342 glyph
->multibyte_p
= it
->multibyte_p
;
26343 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26345 /* In R2L rows, the left and the right box edges need to be
26346 drawn in reverse direction. */
26347 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26348 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26352 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26353 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26355 glyph
->overlaps_vertically_p
= false;
26356 glyph
->padding_p
= false;
26357 glyph
->glyph_not_available_p
= false;
26358 glyph
->face_id
= it
->face_id
;
26359 glyph
->u
.stretch
.ascent
= ascent
;
26360 glyph
->u
.stretch
.height
= height
;
26361 glyph
->slice
.img
= null_glyph_slice
;
26362 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26365 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26366 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26367 glyph
->bidi_type
= it
->bidi_it
.type
;
26371 glyph
->resolved_level
= 0;
26372 glyph
->bidi_type
= UNKNOWN_BT
;
26374 ++it
->glyph_row
->used
[area
];
26377 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26380 #endif /* HAVE_WINDOW_SYSTEM */
26382 /* Produce a stretch glyph for iterator IT. IT->object is the value
26383 of the glyph property displayed. The value must be a list
26384 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
26387 1. `:width WIDTH' specifies that the space should be WIDTH *
26388 canonical char width wide. WIDTH may be an integer or floating
26391 2. `:relative-width FACTOR' specifies that the width of the stretch
26392 should be computed from the width of the first character having the
26393 `glyph' property, and should be FACTOR times that width.
26395 3. `:align-to HPOS' specifies that the space should be wide enough
26396 to reach HPOS, a value in canonical character units.
26398 Exactly one of the above pairs must be present.
26400 4. `:height HEIGHT' specifies that the height of the stretch produced
26401 should be HEIGHT, measured in canonical character units.
26403 5. `:relative-height FACTOR' specifies that the height of the
26404 stretch should be FACTOR times the height of the characters having
26405 the glyph property.
26407 Either none or exactly one of 4 or 5 must be present.
26409 6. `:ascent ASCENT' specifies that ASCENT percent of the height
26410 of the stretch should be used for the ascent of the stretch.
26411 ASCENT must be in the range 0 <= ASCENT <= 100. */
26414 produce_stretch_glyph (struct it
*it
)
26416 /* (space :width WIDTH :height HEIGHT ...) */
26417 Lisp_Object prop
, plist
;
26418 int width
= 0, height
= 0, align_to
= -1;
26419 bool zero_width_ok_p
= false;
26421 struct font
*font
= NULL
;
26423 #ifdef HAVE_WINDOW_SYSTEM
26425 bool zero_height_ok_p
= false;
26427 if (FRAME_WINDOW_P (it
->f
))
26429 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26430 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26431 prepare_face_for_display (it
->f
, face
);
26435 /* List should start with `space'. */
26436 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
26437 plist
= XCDR (it
->object
);
26439 /* Compute the width of the stretch. */
26440 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
26441 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true, 0))
26443 /* Absolute width `:width WIDTH' specified and valid. */
26444 zero_width_ok_p
= true;
26447 else if (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0)
26449 /* Relative width `:relative-width FACTOR' specified and valid.
26450 Compute the width of the characters having the `glyph'
26453 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
26456 if (it
->multibyte_p
)
26457 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
26460 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
26461 if (! ASCII_CHAR_P (it2
.c
))
26462 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
26465 it2
.glyph_row
= NULL
;
26466 it2
.what
= IT_CHARACTER
;
26467 PRODUCE_GLYPHS (&it2
);
26468 width
= NUMVAL (prop
) * it2
.pixel_width
;
26470 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
26471 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true,
26474 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
26475 align_to
= (align_to
< 0
26477 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
26478 else if (align_to
< 0)
26479 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
26480 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
26481 zero_width_ok_p
= true;
26484 /* Nothing specified -> width defaults to canonical char width. */
26485 width
= FRAME_COLUMN_WIDTH (it
->f
);
26487 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
26490 #ifdef HAVE_WINDOW_SYSTEM
26491 /* Compute height. */
26492 if (FRAME_WINDOW_P (it
->f
))
26494 int default_height
= normal_char_height (font
, ' ');
26496 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
26497 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
26500 zero_height_ok_p
= true;
26502 else if (prop
= Fplist_get (plist
, QCrelative_height
),
26504 height
= default_height
* NUMVAL (prop
);
26506 height
= default_height
;
26508 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
26511 /* Compute percentage of height used for ascent. If
26512 `:ascent ASCENT' is present and valid, use that. Otherwise,
26513 derive the ascent from the font in use. */
26514 if (prop
= Fplist_get (plist
, QCascent
),
26515 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
26516 ascent
= height
* NUMVAL (prop
) / 100.0;
26517 else if (!NILP (prop
)
26518 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
26519 ascent
= min (max (0, (int)tem
), height
);
26521 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
26524 #endif /* HAVE_WINDOW_SYSTEM */
26527 if (width
> 0 && it
->line_wrap
!= TRUNCATE
26528 && it
->current_x
+ width
> it
->last_visible_x
)
26530 width
= it
->last_visible_x
- it
->current_x
;
26531 #ifdef HAVE_WINDOW_SYSTEM
26532 /* Subtract one more pixel from the stretch width, but only on
26533 GUI frames, since on a TTY each glyph is one "pixel" wide. */
26534 width
-= FRAME_WINDOW_P (it
->f
);
26538 if (width
> 0 && height
> 0 && it
->glyph_row
)
26540 Lisp_Object o_object
= it
->object
;
26541 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
26544 if (!STRINGP (object
))
26545 object
= it
->w
->contents
;
26546 #ifdef HAVE_WINDOW_SYSTEM
26547 if (FRAME_WINDOW_P (it
->f
))
26548 append_stretch_glyph (it
, object
, width
, height
, ascent
);
26552 it
->object
= object
;
26553 it
->char_to_display
= ' ';
26554 it
->pixel_width
= it
->len
= 1;
26556 tty_append_glyph (it
);
26557 it
->object
= o_object
;
26561 it
->pixel_width
= width
;
26562 #ifdef HAVE_WINDOW_SYSTEM
26563 if (FRAME_WINDOW_P (it
->f
))
26565 it
->ascent
= it
->phys_ascent
= ascent
;
26566 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
26567 it
->nglyphs
= width
> 0 && height
> 0;
26568 take_vertical_position_into_account (it
);
26572 it
->nglyphs
= width
;
26575 /* Get information about special display element WHAT in an
26576 environment described by IT. WHAT is one of IT_TRUNCATION or
26577 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
26578 non-null glyph_row member. This function ensures that fields like
26579 face_id, c, len of IT are left untouched. */
26582 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
26589 temp_it
.object
= Qnil
;
26590 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
26592 if (what
== IT_CONTINUATION
)
26594 /* Continuation glyph. For R2L lines, we mirror it by hand. */
26595 if (it
->bidi_it
.paragraph_dir
== R2L
)
26596 SET_GLYPH_FROM_CHAR (glyph
, '/');
26598 SET_GLYPH_FROM_CHAR (glyph
, '\\');
26600 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
26602 /* FIXME: Should we mirror GC for R2L lines? */
26603 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
26604 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
26607 else if (what
== IT_TRUNCATION
)
26609 /* Truncation glyph. */
26610 SET_GLYPH_FROM_CHAR (glyph
, '$');
26612 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
26614 /* FIXME: Should we mirror GC for R2L lines? */
26615 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
26616 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
26622 #ifdef HAVE_WINDOW_SYSTEM
26623 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
26624 is turned off, we precede the truncation/continuation glyphs by a
26625 stretch glyph whose width is computed such that these special
26626 glyphs are aligned at the window margin, even when very different
26627 fonts are used in different glyph rows. */
26628 if (FRAME_WINDOW_P (temp_it
.f
)
26629 /* init_iterator calls this with it->glyph_row == NULL, and it
26630 wants only the pixel width of the truncation/continuation
26632 && temp_it
.glyph_row
26633 /* insert_left_trunc_glyphs calls us at the beginning of the
26634 row, and it has its own calculation of the stretch glyph
26636 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
26637 && (temp_it
.glyph_row
->reversed_p
26638 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
26639 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
26641 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
26643 if (stretch_width
> 0)
26645 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
26646 struct font
*font
=
26647 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
26648 int stretch_ascent
=
26649 (((temp_it
.ascent
+ temp_it
.descent
)
26650 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
26652 append_stretch_glyph (&temp_it
, Qnil
, stretch_width
,
26653 temp_it
.ascent
+ temp_it
.descent
,
26660 temp_it
.what
= IT_CHARACTER
;
26661 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
26662 temp_it
.face_id
= GLYPH_FACE (glyph
);
26663 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
26665 PRODUCE_GLYPHS (&temp_it
);
26666 it
->pixel_width
= temp_it
.pixel_width
;
26667 it
->nglyphs
= temp_it
.nglyphs
;
26670 #ifdef HAVE_WINDOW_SYSTEM
26672 /* Calculate line-height and line-spacing properties.
26673 An integer value specifies explicit pixel value.
26674 A float value specifies relative value to current face height.
26675 A cons (float . face-name) specifies relative value to
26676 height of specified face font.
26678 Returns height in pixels, or nil. */
26681 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
26682 int boff
, bool override
)
26684 Lisp_Object face_name
= Qnil
;
26685 int ascent
, descent
, height
;
26687 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
26692 face_name
= XCAR (val
);
26694 if (!NUMBERP (val
))
26695 val
= make_number (1);
26696 if (NILP (face_name
))
26698 height
= it
->ascent
+ it
->descent
;
26703 if (NILP (face_name
))
26705 font
= FRAME_FONT (it
->f
);
26706 boff
= FRAME_BASELINE_OFFSET (it
->f
);
26708 else if (EQ (face_name
, Qt
))
26717 face_id
= lookup_named_face (it
->f
, face_name
, false);
26718 face
= FACE_FROM_ID_OR_NULL (it
->f
, face_id
);
26719 if (face
== NULL
|| ((font
= face
->font
) == NULL
))
26720 return make_number (-1);
26721 boff
= font
->baseline_offset
;
26722 if (font
->vertical_centering
)
26723 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26726 normal_char_ascent_descent (font
, -1, &ascent
, &descent
);
26730 it
->override_ascent
= ascent
;
26731 it
->override_descent
= descent
;
26732 it
->override_boff
= boff
;
26735 height
= ascent
+ descent
;
26739 height
= (int)(XFLOAT_DATA (val
) * height
);
26740 else if (INTEGERP (val
))
26741 height
*= XINT (val
);
26743 return make_number (height
);
26747 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
26748 is a face ID to be used for the glyph. FOR_NO_FONT is true if
26749 and only if this is for a character for which no font was found.
26751 If the display method (it->glyphless_method) is
26752 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
26753 length of the acronym or the hexadecimal string, UPPER_XOFF and
26754 UPPER_YOFF are pixel offsets for the upper part of the string,
26755 LOWER_XOFF and LOWER_YOFF are for the lower part.
26757 For the other display methods, LEN through LOWER_YOFF are zero. */
26760 append_glyphless_glyph (struct it
*it
, int face_id
, bool for_no_font
, int len
,
26761 short upper_xoff
, short upper_yoff
,
26762 short lower_xoff
, short lower_yoff
)
26764 struct glyph
*glyph
;
26765 enum glyph_row_area area
= it
->area
;
26767 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26768 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26770 /* If the glyph row is reversed, we need to prepend the glyph
26771 rather than append it. */
26772 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26776 /* Make room for the additional glyph. */
26777 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26779 glyph
= it
->glyph_row
->glyphs
[area
];
26781 glyph
->charpos
= CHARPOS (it
->position
);
26782 glyph
->object
= it
->object
;
26783 eassert (it
->pixel_width
<= SHRT_MAX
);
26784 glyph
->pixel_width
= it
->pixel_width
;
26785 glyph
->ascent
= it
->ascent
;
26786 glyph
->descent
= it
->descent
;
26787 glyph
->voffset
= it
->voffset
;
26788 glyph
->type
= GLYPHLESS_GLYPH
;
26789 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
26790 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
26791 glyph
->u
.glyphless
.len
= len
;
26792 glyph
->u
.glyphless
.ch
= it
->c
;
26793 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
26794 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
26795 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
26796 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
26797 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26798 glyph
->multibyte_p
= it
->multibyte_p
;
26799 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26801 /* In R2L rows, the left and the right box edges need to be
26802 drawn in reverse direction. */
26803 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26804 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26808 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26809 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26811 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
26812 || it
->phys_descent
> it
->descent
);
26813 glyph
->padding_p
= false;
26814 glyph
->glyph_not_available_p
= false;
26815 glyph
->face_id
= face_id
;
26816 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26819 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26820 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26821 glyph
->bidi_type
= it
->bidi_it
.type
;
26823 ++it
->glyph_row
->used
[area
];
26826 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26830 /* Produce a glyph for a glyphless character for iterator IT.
26831 IT->glyphless_method specifies which method to use for displaying
26832 the character. See the description of enum
26833 glyphless_display_method in dispextern.h for the detail.
26835 FOR_NO_FONT is true if and only if this is for a character for
26836 which no font was found. ACRONYM, if non-nil, is an acronym string
26837 for the character. */
26840 produce_glyphless_glyph (struct it
*it
, bool for_no_font
, Lisp_Object acronym
)
26845 int base_width
, base_height
, width
, height
;
26846 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
26849 /* Get the metrics of the base font. We always refer to the current
26851 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
26852 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26853 normal_char_ascent_descent (font
, -1, &it
->ascent
, &it
->descent
);
26854 it
->ascent
+= font
->baseline_offset
;
26855 it
->descent
-= font
->baseline_offset
;
26856 base_height
= it
->ascent
+ it
->descent
;
26857 base_width
= font
->average_width
;
26859 face_id
= merge_glyphless_glyph_face (it
);
26861 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
26863 it
->pixel_width
= THIN_SPACE_WIDTH
;
26865 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26867 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
26869 width
= CHAR_WIDTH (it
->c
);
26872 else if (width
> 4)
26874 it
->pixel_width
= base_width
* width
;
26876 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26882 unsigned int code
[6];
26884 int ascent
, descent
;
26885 struct font_metrics metrics_upper
, metrics_lower
;
26887 face
= FACE_FROM_ID (it
->f
, face_id
);
26888 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26889 prepare_face_for_display (it
->f
, face
);
26891 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
26893 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
26894 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
26895 if (CONSP (acronym
))
26896 acronym
= XCAR (acronym
);
26897 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
26901 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
26902 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
+ 0u);
26905 for (len
= 0; str
[len
] && ASCII_CHAR_P (str
[len
]) && len
< 6; len
++)
26906 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
26907 upper_len
= (len
+ 1) / 2;
26908 font
->driver
->text_extents (font
, code
, upper_len
,
26910 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
26915 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
26916 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
26917 upper_xoff
= upper_yoff
= 2; /* the typical case */
26918 if (base_width
>= width
)
26920 /* Align the upper to the left, the lower to the right. */
26921 it
->pixel_width
= base_width
;
26922 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
26926 /* Center the shorter one. */
26927 it
->pixel_width
= width
;
26928 if (metrics_upper
.width
>= metrics_lower
.width
)
26929 lower_xoff
= (width
- metrics_lower
.width
) / 2;
26932 /* FIXME: This code doesn't look right. It formerly was
26933 missing the "lower_xoff = 0;", which couldn't have
26934 been right since it left lower_xoff uninitialized. */
26936 upper_xoff
= (width
- metrics_upper
.width
) / 2;
26940 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
26941 top, bottom, and between upper and lower strings. */
26942 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
26943 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
26944 /* Center vertically.
26945 H:base_height, D:base_descent
26946 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
26948 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
26949 descent = D - H/2 + h/2;
26950 lower_yoff = descent - 2 - ld;
26951 upper_yoff = lower_yoff - la - 1 - ud; */
26952 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
26953 descent
= it
->descent
- (base_height
- height
) / 2;
26954 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
26955 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
26956 - metrics_upper
.descent
);
26957 /* Don't make the height shorter than the base height. */
26958 if (height
> base_height
)
26960 it
->ascent
= ascent
;
26961 it
->descent
= descent
;
26965 it
->phys_ascent
= it
->ascent
;
26966 it
->phys_descent
= it
->descent
;
26968 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
26969 upper_xoff
, upper_yoff
,
26970 lower_xoff
, lower_yoff
);
26972 take_vertical_position_into_account (it
);
26977 Produce glyphs/get display metrics for the display element IT is
26978 loaded with. See the description of struct it in dispextern.h
26979 for an overview of struct it. */
26982 x_produce_glyphs (struct it
*it
)
26984 int extra_line_spacing
= it
->extra_line_spacing
;
26986 it
->glyph_not_available_p
= false;
26988 if (it
->what
== IT_CHARACTER
)
26991 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26992 struct font
*font
= face
->font
;
26993 struct font_metrics
*pcm
= NULL
;
26994 int boff
; /* Baseline offset. */
26998 /* When no suitable font is found, display this character by
26999 the method specified in the first extra slot of
27000 Vglyphless_char_display. */
27001 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
27003 eassert (it
->what
== IT_GLYPHLESS
);
27004 produce_glyphless_glyph (it
, true,
27005 STRINGP (acronym
) ? acronym
: Qnil
);
27009 boff
= font
->baseline_offset
;
27010 if (font
->vertical_centering
)
27011 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
27013 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
27017 if (it
->override_ascent
>= 0)
27019 it
->ascent
= it
->override_ascent
;
27020 it
->descent
= it
->override_descent
;
27021 boff
= it
->override_boff
;
27025 it
->ascent
= FONT_BASE (font
) + boff
;
27026 it
->descent
= FONT_DESCENT (font
) - boff
;
27029 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
27031 pcm
= get_per_char_metric (font
, &char2b
);
27032 if (pcm
->width
== 0
27033 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
27039 it
->phys_ascent
= pcm
->ascent
+ boff
;
27040 it
->phys_descent
= pcm
->descent
- boff
;
27041 it
->pixel_width
= pcm
->width
;
27042 /* Don't use font-global values for ascent and descent
27043 if they result in an exceedingly large line height. */
27044 if (it
->override_ascent
< 0)
27046 if (FONT_TOO_HIGH (font
))
27048 it
->ascent
= it
->phys_ascent
;
27049 it
->descent
= it
->phys_descent
;
27050 /* These limitations are enforced by an
27051 assertion near the end of this function. */
27052 if (it
->ascent
< 0)
27054 if (it
->descent
< 0)
27061 it
->glyph_not_available_p
= true;
27062 it
->phys_ascent
= it
->ascent
;
27063 it
->phys_descent
= it
->descent
;
27064 it
->pixel_width
= font
->space_width
;
27067 if (it
->constrain_row_ascent_descent_p
)
27069 if (it
->descent
> it
->max_descent
)
27071 it
->ascent
+= it
->descent
- it
->max_descent
;
27072 it
->descent
= it
->max_descent
;
27074 if (it
->ascent
> it
->max_ascent
)
27076 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
27077 it
->ascent
= it
->max_ascent
;
27079 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
27080 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
27081 extra_line_spacing
= 0;
27084 /* If this is a space inside a region of text with
27085 `space-width' property, change its width. */
27087 = it
->char_to_display
== ' ' && !NILP (it
->space_width
);
27089 it
->pixel_width
*= XFLOATINT (it
->space_width
);
27091 /* If face has a box, add the box thickness to the character
27092 height. If character has a box line to the left and/or
27093 right, add the box line width to the character's width. */
27094 if (face
->box
!= FACE_NO_BOX
)
27096 int thick
= face
->box_line_width
;
27100 it
->ascent
+= thick
;
27101 it
->descent
+= thick
;
27106 if (it
->start_of_box_run_p
)
27107 it
->pixel_width
+= thick
;
27108 if (it
->end_of_box_run_p
)
27109 it
->pixel_width
+= thick
;
27112 /* If face has an overline, add the height of the overline
27113 (1 pixel) and a 1 pixel margin to the character height. */
27114 if (face
->overline_p
)
27115 it
->ascent
+= overline_margin
;
27117 if (it
->constrain_row_ascent_descent_p
)
27119 if (it
->ascent
> it
->max_ascent
)
27120 it
->ascent
= it
->max_ascent
;
27121 if (it
->descent
> it
->max_descent
)
27122 it
->descent
= it
->max_descent
;
27125 take_vertical_position_into_account (it
);
27127 /* If we have to actually produce glyphs, do it. */
27132 /* Translate a space with a `space-width' property
27133 into a stretch glyph. */
27134 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
27135 / FONT_HEIGHT (font
));
27136 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
27137 it
->ascent
+ it
->descent
, ascent
);
27142 /* If characters with lbearing or rbearing are displayed
27143 in this line, record that fact in a flag of the
27144 glyph row. This is used to optimize X output code. */
27145 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
27146 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27148 if (! stretched_p
&& it
->pixel_width
== 0)
27149 /* We assure that all visible glyphs have at least 1-pixel
27151 it
->pixel_width
= 1;
27153 else if (it
->char_to_display
== '\n')
27155 /* A newline has no width, but we need the height of the
27156 line. But if previous part of the line sets a height,
27157 don't increase that height. */
27159 Lisp_Object height
;
27160 Lisp_Object total_height
= Qnil
;
27162 it
->override_ascent
= -1;
27163 it
->pixel_width
= 0;
27166 height
= get_it_property (it
, Qline_height
);
27167 /* Split (line-height total-height) list. */
27169 && CONSP (XCDR (height
))
27170 && NILP (XCDR (XCDR (height
))))
27172 total_height
= XCAR (XCDR (height
));
27173 height
= XCAR (height
);
27175 height
= calc_line_height_property (it
, height
, font
, boff
, true);
27177 if (it
->override_ascent
>= 0)
27179 it
->ascent
= it
->override_ascent
;
27180 it
->descent
= it
->override_descent
;
27181 boff
= it
->override_boff
;
27185 if (FONT_TOO_HIGH (font
))
27187 it
->ascent
= font
->pixel_size
+ boff
- 1;
27188 it
->descent
= -boff
+ 1;
27189 if (it
->descent
< 0)
27194 it
->ascent
= FONT_BASE (font
) + boff
;
27195 it
->descent
= FONT_DESCENT (font
) - boff
;
27199 if (EQ (height
, Qt
))
27201 if (it
->descent
> it
->max_descent
)
27203 it
->ascent
+= it
->descent
- it
->max_descent
;
27204 it
->descent
= it
->max_descent
;
27206 if (it
->ascent
> it
->max_ascent
)
27208 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
27209 it
->ascent
= it
->max_ascent
;
27211 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
27212 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
27213 it
->constrain_row_ascent_descent_p
= true;
27214 extra_line_spacing
= 0;
27218 Lisp_Object spacing
;
27220 it
->phys_ascent
= it
->ascent
;
27221 it
->phys_descent
= it
->descent
;
27223 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
27224 && face
->box
!= FACE_NO_BOX
27225 && face
->box_line_width
> 0)
27227 it
->ascent
+= face
->box_line_width
;
27228 it
->descent
+= face
->box_line_width
;
27231 && XINT (height
) > it
->ascent
+ it
->descent
)
27232 it
->ascent
= XINT (height
) - it
->descent
;
27234 if (!NILP (total_height
))
27235 spacing
= calc_line_height_property (it
, total_height
, font
,
27239 spacing
= get_it_property (it
, Qline_spacing
);
27240 spacing
= calc_line_height_property (it
, spacing
, font
,
27243 if (INTEGERP (spacing
))
27245 extra_line_spacing
= XINT (spacing
);
27246 if (!NILP (total_height
))
27247 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
27251 else /* i.e. (it->char_to_display == '\t') */
27253 if (font
->space_width
> 0)
27255 int tab_width
= it
->tab_width
* font
->space_width
;
27256 int x
= it
->current_x
+ it
->continuation_lines_width
;
27257 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
27259 /* If the distance from the current position to the next tab
27260 stop is less than a space character width, use the
27261 tab stop after that. */
27262 if (next_tab_x
- x
< font
->space_width
)
27263 next_tab_x
+= tab_width
;
27265 it
->pixel_width
= next_tab_x
- x
;
27267 if (FONT_TOO_HIGH (font
))
27269 if (get_char_glyph_code (' ', font
, &char2b
))
27271 pcm
= get_per_char_metric (font
, &char2b
);
27272 if (pcm
->width
== 0
27273 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
27279 it
->ascent
= pcm
->ascent
+ boff
;
27280 it
->descent
= pcm
->descent
- boff
;
27284 it
->ascent
= font
->pixel_size
+ boff
- 1;
27285 it
->descent
= -boff
+ 1;
27287 if (it
->ascent
< 0)
27289 if (it
->descent
< 0)
27294 it
->ascent
= FONT_BASE (font
) + boff
;
27295 it
->descent
= FONT_DESCENT (font
) - boff
;
27297 it
->phys_ascent
= it
->ascent
;
27298 it
->phys_descent
= it
->descent
;
27302 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
27303 it
->ascent
+ it
->descent
, it
->ascent
);
27308 it
->pixel_width
= 0;
27313 if (FONT_TOO_HIGH (font
))
27315 int font_ascent
, font_descent
;
27317 /* For very large fonts, where we ignore the declared font
27318 dimensions, and go by per-character metrics instead,
27319 don't let the row ascent and descent values (and the row
27320 height computed from them) be smaller than the "normal"
27321 character metrics. This avoids unpleasant effects
27322 whereby lines on display would change their height
27323 depending on which characters are shown. */
27324 normal_char_ascent_descent (font
, -1, &font_ascent
, &font_descent
);
27325 it
->max_ascent
= max (it
->max_ascent
, font_ascent
);
27326 it
->max_descent
= max (it
->max_descent
, font_descent
);
27329 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
27331 /* A static composition.
27333 Note: A composition is represented as one glyph in the
27334 glyph matrix. There are no padding glyphs.
27336 Important note: pixel_width, ascent, and descent are the
27337 values of what is drawn by draw_glyphs (i.e. the values of
27338 the overall glyphs composed). */
27339 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27340 int boff
; /* baseline offset */
27341 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
27342 int glyph_len
= cmp
->glyph_len
;
27343 struct font
*font
= face
->font
;
27347 /* If we have not yet calculated pixel size data of glyphs of
27348 the composition for the current face font, calculate them
27349 now. Theoretically, we have to check all fonts for the
27350 glyphs, but that requires much time and memory space. So,
27351 here we check only the font of the first glyph. This may
27352 lead to incorrect display, but it's very rare, and C-l
27353 (recenter-top-bottom) can correct the display anyway. */
27354 if (! cmp
->font
|| cmp
->font
!= font
)
27356 /* Ascent and descent of the font of the first character
27357 of this composition (adjusted by baseline offset).
27358 Ascent and descent of overall glyphs should not be less
27359 than these, respectively. */
27360 int font_ascent
, font_descent
, font_height
;
27361 /* Bounding box of the overall glyphs. */
27362 int leftmost
, rightmost
, lowest
, highest
;
27363 int lbearing
, rbearing
;
27364 int i
, width
, ascent
, descent
;
27367 struct font_metrics
*pcm
;
27370 eassume (0 < glyph_len
); /* See Bug#8512. */
27372 c
= COMPOSITION_GLYPH (cmp
, --glyph_len
);
27373 while (c
== '\t' && 0 < glyph_len
);
27375 bool right_padded
= glyph_len
< cmp
->glyph_len
;
27376 for (i
= 0; i
< glyph_len
; i
++)
27378 c
= COMPOSITION_GLYPH (cmp
, i
);
27381 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
27383 bool left_padded
= i
> 0;
27385 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
27386 : IT_CHARPOS (*it
));
27387 /* If no suitable font is found, use the default font. */
27388 bool font_not_found_p
= font
== NULL
;
27389 if (font_not_found_p
)
27391 face
= face
->ascii_face
;
27394 boff
= font
->baseline_offset
;
27395 if (font
->vertical_centering
)
27396 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
27397 normal_char_ascent_descent (font
, -1, &font_ascent
, &font_descent
);
27398 font_ascent
+= boff
;
27399 font_descent
-= boff
;
27400 font_height
= font_ascent
+ font_descent
;
27405 if (! font_not_found_p
)
27407 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
27409 pcm
= get_per_char_metric (font
, &char2b
);
27412 /* Initialize the bounding box. */
27415 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
27416 ascent
= pcm
->ascent
;
27417 descent
= pcm
->descent
;
27418 lbearing
= pcm
->lbearing
;
27419 rbearing
= pcm
->rbearing
;
27423 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
27424 ascent
= FONT_BASE (font
);
27425 descent
= FONT_DESCENT (font
);
27432 lowest
= - descent
+ boff
;
27433 highest
= ascent
+ boff
;
27435 if (! font_not_found_p
27436 && font
->default_ascent
27437 && CHAR_TABLE_P (Vuse_default_ascent
)
27438 && !NILP (Faref (Vuse_default_ascent
,
27439 make_number (it
->char_to_display
))))
27440 highest
= font
->default_ascent
+ boff
;
27442 /* Draw the first glyph at the normal position. It may be
27443 shifted to right later if some other glyphs are drawn
27445 cmp
->offsets
[i
* 2] = 0;
27446 cmp
->offsets
[i
* 2 + 1] = boff
;
27447 cmp
->lbearing
= lbearing
;
27448 cmp
->rbearing
= rbearing
;
27450 /* Set cmp->offsets for the remaining glyphs. */
27451 for (i
++; i
< glyph_len
; i
++)
27453 int left
, right
, btm
, top
;
27454 int ch
= COMPOSITION_GLYPH (cmp
, i
);
27456 struct face
*this_face
;
27460 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
27461 this_face
= FACE_FROM_ID (it
->f
, face_id
);
27462 font
= this_face
->font
;
27468 get_char_face_and_encoding (it
->f
, ch
, face_id
,
27470 pcm
= get_per_char_metric (font
, &char2b
);
27473 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
27476 width
= pcm
->width
;
27477 ascent
= pcm
->ascent
;
27478 descent
= pcm
->descent
;
27479 lbearing
= pcm
->lbearing
;
27480 rbearing
= pcm
->rbearing
;
27481 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
27483 /* Relative composition with or without
27484 alternate chars. */
27485 left
= (leftmost
+ rightmost
- width
) / 2;
27486 btm
= - descent
+ boff
;
27487 if (font
->relative_compose
27488 && (! CHAR_TABLE_P (Vignore_relative_composition
)
27489 || NILP (Faref (Vignore_relative_composition
,
27490 make_number (ch
)))))
27493 if (- descent
>= font
->relative_compose
)
27494 /* One extra pixel between two glyphs. */
27496 else if (ascent
<= 0)
27497 /* One extra pixel between two glyphs. */
27498 btm
= lowest
- 1 - ascent
- descent
;
27503 /* A composition rule is specified by an integer
27504 value that encodes global and new reference
27505 points (GREF and NREF). GREF and NREF are
27506 specified by numbers as below:
27508 0---1---2 -- ascent
27512 9--10--11 -- center
27514 ---3---4---5--- baseline
27516 6---7---8 -- descent
27518 int rule
= COMPOSITION_RULE (cmp
, i
);
27519 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
27521 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
27522 grefx
= gref
% 3, nrefx
= nref
% 3;
27523 grefy
= gref
/ 3, nrefy
= nref
/ 3;
27525 xoff
= font_height
* (xoff
- 128) / 256;
27527 yoff
= font_height
* (yoff
- 128) / 256;
27530 + grefx
* (rightmost
- leftmost
) / 2
27531 - nrefx
* width
/ 2
27534 btm
= ((grefy
== 0 ? highest
27536 : grefy
== 2 ? lowest
27537 : (highest
+ lowest
) / 2)
27538 - (nrefy
== 0 ? ascent
+ descent
27539 : nrefy
== 1 ? descent
- boff
27541 : (ascent
+ descent
) / 2)
27545 cmp
->offsets
[i
* 2] = left
;
27546 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
27548 /* Update the bounding box of the overall glyphs. */
27551 right
= left
+ width
;
27552 if (left
< leftmost
)
27554 if (right
> rightmost
)
27557 top
= btm
+ descent
+ ascent
;
27563 if (cmp
->lbearing
> left
+ lbearing
)
27564 cmp
->lbearing
= left
+ lbearing
;
27565 if (cmp
->rbearing
< left
+ rbearing
)
27566 cmp
->rbearing
= left
+ rbearing
;
27570 /* If there are glyphs whose x-offsets are negative,
27571 shift all glyphs to the right and make all x-offsets
27575 for (i
= 0; i
< cmp
->glyph_len
; i
++)
27576 cmp
->offsets
[i
* 2] -= leftmost
;
27577 rightmost
-= leftmost
;
27578 cmp
->lbearing
-= leftmost
;
27579 cmp
->rbearing
-= leftmost
;
27582 if (left_padded
&& cmp
->lbearing
< 0)
27584 for (i
= 0; i
< cmp
->glyph_len
; i
++)
27585 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
27586 rightmost
-= cmp
->lbearing
;
27587 cmp
->rbearing
-= cmp
->lbearing
;
27590 if (right_padded
&& rightmost
< cmp
->rbearing
)
27592 rightmost
= cmp
->rbearing
;
27595 cmp
->pixel_width
= rightmost
;
27596 cmp
->ascent
= highest
;
27597 cmp
->descent
= - lowest
;
27598 if (cmp
->ascent
< font_ascent
)
27599 cmp
->ascent
= font_ascent
;
27600 if (cmp
->descent
< font_descent
)
27601 cmp
->descent
= font_descent
;
27605 && (cmp
->lbearing
< 0
27606 || cmp
->rbearing
> cmp
->pixel_width
))
27607 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27609 it
->pixel_width
= cmp
->pixel_width
;
27610 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
27611 it
->descent
= it
->phys_descent
= cmp
->descent
;
27612 if (face
->box
!= FACE_NO_BOX
)
27614 int thick
= face
->box_line_width
;
27618 it
->ascent
+= thick
;
27619 it
->descent
+= thick
;
27624 if (it
->start_of_box_run_p
)
27625 it
->pixel_width
+= thick
;
27626 if (it
->end_of_box_run_p
)
27627 it
->pixel_width
+= thick
;
27630 /* If face has an overline, add the height of the overline
27631 (1 pixel) and a 1 pixel margin to the character height. */
27632 if (face
->overline_p
)
27633 it
->ascent
+= overline_margin
;
27635 take_vertical_position_into_account (it
);
27636 if (it
->ascent
< 0)
27638 if (it
->descent
< 0)
27641 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
27642 append_composite_glyph (it
);
27644 else if (it
->what
== IT_COMPOSITION
)
27646 /* A dynamic (automatic) composition. */
27647 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27648 Lisp_Object gstring
;
27649 struct font_metrics metrics
;
27653 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
27655 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
27658 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
27659 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27660 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
27661 it
->descent
= it
->phys_descent
= metrics
.descent
;
27662 if (face
->box
!= FACE_NO_BOX
)
27664 int thick
= face
->box_line_width
;
27668 it
->ascent
+= thick
;
27669 it
->descent
+= thick
;
27674 if (it
->start_of_box_run_p
)
27675 it
->pixel_width
+= thick
;
27676 if (it
->end_of_box_run_p
)
27677 it
->pixel_width
+= thick
;
27679 /* If face has an overline, add the height of the overline
27680 (1 pixel) and a 1 pixel margin to the character height. */
27681 if (face
->overline_p
)
27682 it
->ascent
+= overline_margin
;
27683 take_vertical_position_into_account (it
);
27684 if (it
->ascent
< 0)
27686 if (it
->descent
< 0)
27690 append_composite_glyph (it
);
27692 else if (it
->what
== IT_GLYPHLESS
)
27693 produce_glyphless_glyph (it
, false, Qnil
);
27694 else if (it
->what
== IT_IMAGE
)
27695 produce_image_glyph (it
);
27696 else if (it
->what
== IT_STRETCH
)
27697 produce_stretch_glyph (it
);
27698 else if (it
->what
== IT_XWIDGET
)
27699 produce_xwidget_glyph (it
);
27702 /* Accumulate dimensions. Note: can't assume that it->descent > 0
27703 because this isn't true for images with `:ascent 100'. */
27704 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
27705 if (it
->area
== TEXT_AREA
)
27706 it
->current_x
+= it
->pixel_width
;
27708 if (extra_line_spacing
> 0)
27710 it
->descent
+= extra_line_spacing
;
27711 if (extra_line_spacing
> it
->max_extra_line_spacing
)
27712 it
->max_extra_line_spacing
= extra_line_spacing
;
27715 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
27716 it
->max_descent
= max (it
->max_descent
, it
->descent
);
27717 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
27718 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
27722 Output LEN glyphs starting at START at the nominal cursor position.
27723 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
27724 being updated, and UPDATED_AREA is the area of that row being updated. */
27727 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27728 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27730 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
27732 eassert (updated_row
);
27733 /* When the window is hscrolled, cursor hpos can legitimately be out
27734 of bounds, but we draw the cursor at the corresponding window
27735 margin in that case. */
27736 if (!updated_row
->reversed_p
&& chpos
< 0)
27738 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
27739 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
27743 /* Write glyphs. */
27745 hpos
= start
- updated_row
->glyphs
[updated_area
];
27746 x
= draw_glyphs (w
, w
->output_cursor
.x
,
27747 updated_row
, updated_area
,
27749 DRAW_NORMAL_TEXT
, 0);
27751 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
27752 if (updated_area
== TEXT_AREA
27753 && w
->phys_cursor_on_p
27754 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
27756 && chpos
< hpos
+ len
)
27757 w
->phys_cursor_on_p
= false;
27761 /* Advance the output cursor. */
27762 w
->output_cursor
.hpos
+= len
;
27763 w
->output_cursor
.x
= x
;
27768 Insert LEN glyphs from START at the nominal cursor position. */
27771 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27772 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27775 int line_height
, shift_by_width
, shifted_region_width
;
27776 struct glyph_row
*row
;
27777 struct glyph
*glyph
;
27778 int frame_x
, frame_y
;
27781 eassert (updated_row
);
27783 f
= XFRAME (WINDOW_FRAME (w
));
27785 /* Get the height of the line we are in. */
27787 line_height
= row
->height
;
27789 /* Get the width of the glyphs to insert. */
27790 shift_by_width
= 0;
27791 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
27792 shift_by_width
+= glyph
->pixel_width
;
27794 /* Get the width of the region to shift right. */
27795 shifted_region_width
= (window_box_width (w
, updated_area
)
27796 - w
->output_cursor
.x
27800 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
27801 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
27803 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
27804 line_height
, shift_by_width
);
27806 /* Write the glyphs. */
27807 hpos
= start
- row
->glyphs
[updated_area
];
27808 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
27810 DRAW_NORMAL_TEXT
, 0);
27812 /* Advance the output cursor. */
27813 w
->output_cursor
.hpos
+= len
;
27814 w
->output_cursor
.x
+= shift_by_width
;
27820 Erase the current text line from the nominal cursor position
27821 (inclusive) to pixel column TO_X (exclusive). The idea is that
27822 everything from TO_X onward is already erased.
27824 TO_X is a pixel position relative to UPDATED_AREA of currently
27825 updated window W. TO_X == -1 means clear to the end of this area. */
27828 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
27829 enum glyph_row_area updated_area
, int to_x
)
27832 int max_x
, min_y
, max_y
;
27833 int from_x
, from_y
, to_y
;
27835 eassert (updated_row
);
27836 f
= XFRAME (w
->frame
);
27838 if (updated_row
->full_width_p
)
27839 max_x
= (WINDOW_PIXEL_WIDTH (w
)
27840 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
27842 max_x
= window_box_width (w
, updated_area
);
27843 max_y
= window_text_bottom_y (w
);
27845 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
27846 of window. For TO_X > 0, truncate to end of drawing area. */
27852 to_x
= min (to_x
, max_x
);
27854 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
27856 /* Notice if the cursor will be cleared by this operation. */
27857 if (!updated_row
->full_width_p
)
27858 notice_overwritten_cursor (w
, updated_area
,
27859 w
->output_cursor
.x
, -1,
27861 MATRIX_ROW_BOTTOM_Y (updated_row
));
27863 from_x
= w
->output_cursor
.x
;
27865 /* Translate to frame coordinates. */
27866 if (updated_row
->full_width_p
)
27868 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
27869 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
27873 int area_left
= window_box_left (w
, updated_area
);
27874 from_x
+= area_left
;
27878 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
27879 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
27880 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
27882 /* Prevent inadvertently clearing to end of the X window. */
27883 if (to_x
> from_x
&& to_y
> from_y
)
27886 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
27887 to_x
- from_x
, to_y
- from_y
);
27892 #endif /* HAVE_WINDOW_SYSTEM */
27896 /***********************************************************************
27898 ***********************************************************************/
27900 /* Value is the internal representation of the specified cursor type
27901 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
27902 of the bar cursor. */
27904 static enum text_cursor_kinds
27905 get_specified_cursor_type (Lisp_Object arg
, int *width
)
27907 enum text_cursor_kinds type
;
27912 if (EQ (arg
, Qbox
))
27913 return FILLED_BOX_CURSOR
;
27915 if (EQ (arg
, Qhollow
))
27916 return HOLLOW_BOX_CURSOR
;
27918 if (EQ (arg
, Qbar
))
27925 && EQ (XCAR (arg
), Qbar
)
27926 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27928 *width
= XINT (XCDR (arg
));
27932 if (EQ (arg
, Qhbar
))
27935 return HBAR_CURSOR
;
27939 && EQ (XCAR (arg
), Qhbar
)
27940 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27942 *width
= XINT (XCDR (arg
));
27943 return HBAR_CURSOR
;
27946 /* Treat anything unknown as "hollow box cursor".
27947 It was bad to signal an error; people have trouble fixing
27948 .Xdefaults with Emacs, when it has something bad in it. */
27949 type
= HOLLOW_BOX_CURSOR
;
27954 /* Set the default cursor types for specified frame. */
27956 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
27961 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
27962 FRAME_CURSOR_WIDTH (f
) = width
;
27964 /* By default, set up the blink-off state depending on the on-state. */
27966 tem
= Fassoc (arg
, Vblink_cursor_alist
);
27969 FRAME_BLINK_OFF_CURSOR (f
)
27970 = get_specified_cursor_type (XCDR (tem
), &width
);
27971 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
27974 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
27976 /* Make sure the cursor gets redrawn. */
27977 f
->cursor_type_changed
= true;
27981 #ifdef HAVE_WINDOW_SYSTEM
27983 /* Return the cursor we want to be displayed in window W. Return
27984 width of bar/hbar cursor through WIDTH arg. Return with
27985 ACTIVE_CURSOR arg set to true if cursor in window W is `active'
27986 (i.e. if the `system caret' should track this cursor).
27988 In a mini-buffer window, we want the cursor only to appear if we
27989 are reading input from this window. For the selected window, we
27990 want the cursor type given by the frame parameter or buffer local
27991 setting of cursor-type. If explicitly marked off, draw no cursor.
27992 In all other cases, we want a hollow box cursor. */
27994 static enum text_cursor_kinds
27995 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
27996 bool *active_cursor
)
27998 struct frame
*f
= XFRAME (w
->frame
);
27999 struct buffer
*b
= XBUFFER (w
->contents
);
28000 int cursor_type
= DEFAULT_CURSOR
;
28001 Lisp_Object alt_cursor
;
28002 bool non_selected
= false;
28004 *active_cursor
= true;
28007 if (cursor_in_echo_area
28008 && FRAME_HAS_MINIBUF_P (f
)
28009 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
28011 if (w
== XWINDOW (echo_area_window
))
28013 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
28015 *width
= FRAME_CURSOR_WIDTH (f
);
28016 return FRAME_DESIRED_CURSOR (f
);
28019 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
28022 *active_cursor
= false;
28023 non_selected
= true;
28026 /* Detect a nonselected window or nonselected frame. */
28027 else if (w
!= XWINDOW (f
->selected_window
)
28028 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
28030 *active_cursor
= false;
28032 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
28035 non_selected
= true;
28038 /* Never display a cursor in a window in which cursor-type is nil. */
28039 if (NILP (BVAR (b
, cursor_type
)))
28042 /* Get the normal cursor type for this window. */
28043 if (EQ (BVAR (b
, cursor_type
), Qt
))
28045 cursor_type
= FRAME_DESIRED_CURSOR (f
);
28046 *width
= FRAME_CURSOR_WIDTH (f
);
28049 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
28051 /* Use cursor-in-non-selected-windows instead
28052 for non-selected window or frame. */
28055 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
28056 if (!EQ (Qt
, alt_cursor
))
28057 return get_specified_cursor_type (alt_cursor
, width
);
28058 /* t means modify the normal cursor type. */
28059 if (cursor_type
== FILLED_BOX_CURSOR
)
28060 cursor_type
= HOLLOW_BOX_CURSOR
;
28061 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
28063 return cursor_type
;
28066 /* Use normal cursor if not blinked off. */
28067 if (!w
->cursor_off_p
)
28069 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
)
28071 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28073 if (cursor_type
== FILLED_BOX_CURSOR
)
28075 /* Using a block cursor on large images can be very annoying.
28076 So use a hollow cursor for "large" images.
28077 If image is not transparent (no mask), also use hollow cursor. */
28078 struct image
*img
= IMAGE_OPT_FROM_ID (f
, glyph
->u
.img_id
);
28079 if (img
!= NULL
&& IMAGEP (img
->spec
))
28081 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
28082 where N = size of default frame font size.
28083 This should cover most of the "tiny" icons people may use. */
28085 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
28086 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
28087 cursor_type
= HOLLOW_BOX_CURSOR
;
28090 else if (cursor_type
!= NO_CURSOR
)
28092 /* Display current only supports BOX and HOLLOW cursors for images.
28093 So for now, unconditionally use a HOLLOW cursor when cursor is
28094 not a solid box cursor. */
28095 cursor_type
= HOLLOW_BOX_CURSOR
;
28098 return cursor_type
;
28101 /* Cursor is blinked off, so determine how to "toggle" it. */
28103 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
28104 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
28105 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
28107 /* Then see if frame has specified a specific blink off cursor type. */
28108 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
28110 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
28111 return FRAME_BLINK_OFF_CURSOR (f
);
28115 /* Some people liked having a permanently visible blinking cursor,
28116 while others had very strong opinions against it. So it was
28117 decided to remove it. KFS 2003-09-03 */
28119 /* Finally perform built-in cursor blinking:
28120 filled box <-> hollow box
28121 wide [h]bar <-> narrow [h]bar
28122 narrow [h]bar <-> no cursor
28123 other type <-> no cursor */
28125 if (cursor_type
== FILLED_BOX_CURSOR
)
28126 return HOLLOW_BOX_CURSOR
;
28128 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
28131 return cursor_type
;
28139 /* Notice when the text cursor of window W has been completely
28140 overwritten by a drawing operation that outputs glyphs in AREA
28141 starting at X0 and ending at X1 in the line starting at Y0 and
28142 ending at Y1. X coordinates are area-relative. X1 < 0 means all
28143 the rest of the line after X0 has been written. Y coordinates
28144 are window-relative. */
28147 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
28148 int x0
, int x1
, int y0
, int y1
)
28150 int cx0
, cx1
, cy0
, cy1
;
28151 struct glyph_row
*row
;
28153 if (!w
->phys_cursor_on_p
)
28155 if (area
!= TEXT_AREA
)
28158 if (w
->phys_cursor
.vpos
< 0
28159 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
28160 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
28161 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
28164 if (row
->cursor_in_fringe_p
)
28166 row
->cursor_in_fringe_p
= false;
28167 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
28168 w
->phys_cursor_on_p
= false;
28172 cx0
= w
->phys_cursor
.x
;
28173 cx1
= cx0
+ w
->phys_cursor_width
;
28174 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
28177 /* The cursor image will be completely removed from the
28178 screen if the output area intersects the cursor area in
28179 y-direction. When we draw in [y0 y1[, and some part of
28180 the cursor is at y < y0, that part must have been drawn
28181 before. When scrolling, the cursor is erased before
28182 actually scrolling, so we don't come here. When not
28183 scrolling, the rows above the old cursor row must have
28184 changed, and in this case these rows must have written
28185 over the cursor image.
28187 Likewise if part of the cursor is below y1, with the
28188 exception of the cursor being in the first blank row at
28189 the buffer and window end because update_text_area
28190 doesn't draw that row. (Except when it does, but
28191 that's handled in update_text_area.) */
28193 cy0
= w
->phys_cursor
.y
;
28194 cy1
= cy0
+ w
->phys_cursor_height
;
28195 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
28198 w
->phys_cursor_on_p
= false;
28201 #endif /* HAVE_WINDOW_SYSTEM */
28204 /************************************************************************
28206 ************************************************************************/
28208 #ifdef HAVE_WINDOW_SYSTEM
28211 Fix the display of area AREA of overlapping row ROW in window W
28212 with respect to the overlapping part OVERLAPS. */
28215 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
28216 enum glyph_row_area area
, int overlaps
)
28223 for (i
= 0; i
< row
->used
[area
];)
28225 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
28227 int start
= i
, start_x
= x
;
28231 x
+= row
->glyphs
[area
][i
].pixel_width
;
28234 while (i
< row
->used
[area
]
28235 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
28237 draw_glyphs (w
, start_x
, row
, area
,
28239 DRAW_NORMAL_TEXT
, overlaps
);
28243 x
+= row
->glyphs
[area
][i
].pixel_width
;
28253 Draw the cursor glyph of window W in glyph row ROW. See the
28254 comment of draw_glyphs for the meaning of HL. */
28257 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
28258 enum draw_glyphs_face hl
)
28260 /* If cursor hpos is out of bounds, don't draw garbage. This can
28261 happen in mini-buffer windows when switching between echo area
28262 glyphs and mini-buffer. */
28263 if ((row
->reversed_p
28264 ? (w
->phys_cursor
.hpos
>= 0)
28265 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
28267 bool on_p
= w
->phys_cursor_on_p
;
28269 int hpos
= w
->phys_cursor
.hpos
;
28271 /* When the window is hscrolled, cursor hpos can legitimately be
28272 out of bounds, but we draw the cursor at the corresponding
28273 window margin in that case. */
28274 if (!row
->reversed_p
&& hpos
< 0)
28276 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28277 hpos
= row
->used
[TEXT_AREA
] - 1;
28279 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
28281 w
->phys_cursor_on_p
= on_p
;
28283 if (hl
== DRAW_CURSOR
)
28284 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
28285 /* When we erase the cursor, and ROW is overlapped by other
28286 rows, make sure that these overlapping parts of other rows
28288 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
28290 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
28292 if (row
> w
->current_matrix
->rows
28293 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
28294 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
28295 OVERLAPS_ERASED_CURSOR
);
28297 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
28298 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
28299 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
28300 OVERLAPS_ERASED_CURSOR
);
28306 /* Erase the image of a cursor of window W from the screen. */
28309 erase_phys_cursor (struct window
*w
)
28311 struct frame
*f
= XFRAME (w
->frame
);
28312 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28313 int hpos
= w
->phys_cursor
.hpos
;
28314 int vpos
= w
->phys_cursor
.vpos
;
28315 bool mouse_face_here_p
= false;
28316 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
28317 struct glyph_row
*cursor_row
;
28318 struct glyph
*cursor_glyph
;
28319 enum draw_glyphs_face hl
;
28321 /* No cursor displayed or row invalidated => nothing to do on the
28323 if (w
->phys_cursor_type
== NO_CURSOR
)
28324 goto mark_cursor_off
;
28326 /* VPOS >= active_glyphs->nrows means that window has been resized.
28327 Don't bother to erase the cursor. */
28328 if (vpos
>= active_glyphs
->nrows
)
28329 goto mark_cursor_off
;
28331 /* If row containing cursor is marked invalid, there is nothing we
28333 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
28334 if (!cursor_row
->enabled_p
)
28335 goto mark_cursor_off
;
28337 /* If line spacing is > 0, old cursor may only be partially visible in
28338 window after split-window. So adjust visible height. */
28339 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
28340 window_text_bottom_y (w
) - cursor_row
->y
);
28342 /* If row is completely invisible, don't attempt to delete a cursor which
28343 isn't there. This can happen if cursor is at top of a window, and
28344 we switch to a buffer with a header line in that window. */
28345 if (cursor_row
->visible_height
<= 0)
28346 goto mark_cursor_off
;
28348 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
28349 if (cursor_row
->cursor_in_fringe_p
)
28351 cursor_row
->cursor_in_fringe_p
= false;
28352 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
28353 goto mark_cursor_off
;
28356 /* This can happen when the new row is shorter than the old one.
28357 In this case, either draw_glyphs or clear_end_of_line
28358 should have cleared the cursor. Note that we wouldn't be
28359 able to erase the cursor in this case because we don't have a
28360 cursor glyph at hand. */
28361 if ((cursor_row
->reversed_p
28362 ? (w
->phys_cursor
.hpos
< 0)
28363 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
28364 goto mark_cursor_off
;
28366 /* When the window is hscrolled, cursor hpos can legitimately be out
28367 of bounds, but we draw the cursor at the corresponding window
28368 margin in that case. */
28369 if (!cursor_row
->reversed_p
&& hpos
< 0)
28371 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
28372 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
28374 /* If the cursor is in the mouse face area, redisplay that when
28375 we clear the cursor. */
28376 if (! NILP (hlinfo
->mouse_face_window
)
28377 && coords_in_mouse_face_p (w
, hpos
, vpos
)
28378 /* Don't redraw the cursor's spot in mouse face if it is at the
28379 end of a line (on a newline). The cursor appears there, but
28380 mouse highlighting does not. */
28381 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
28382 mouse_face_here_p
= true;
28384 /* Maybe clear the display under the cursor. */
28385 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
28388 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
28391 cursor_glyph
= get_phys_cursor_glyph (w
);
28392 if (cursor_glyph
== NULL
)
28393 goto mark_cursor_off
;
28395 width
= cursor_glyph
->pixel_width
;
28396 x
= w
->phys_cursor
.x
;
28402 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
28403 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
28404 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
28407 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
28410 /* Erase the cursor by redrawing the character underneath it. */
28411 if (mouse_face_here_p
)
28412 hl
= DRAW_MOUSE_FACE
;
28414 hl
= DRAW_NORMAL_TEXT
;
28415 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
28418 w
->phys_cursor_on_p
= false;
28419 w
->phys_cursor_type
= NO_CURSOR
;
28423 /* Display or clear cursor of window W. If !ON, clear the cursor.
28424 If ON, display the cursor; where to put the cursor is specified by
28425 HPOS, VPOS, X and Y. */
28428 display_and_set_cursor (struct window
*w
, bool on
,
28429 int hpos
, int vpos
, int x
, int y
)
28431 struct frame
*f
= XFRAME (w
->frame
);
28432 int new_cursor_type
;
28433 int new_cursor_width
;
28434 bool active_cursor
;
28435 struct glyph_row
*glyph_row
;
28436 struct glyph
*glyph
;
28438 /* This is pointless on invisible frames, and dangerous on garbaged
28439 windows and frames; in the latter case, the frame or window may
28440 be in the midst of changing its size, and x and y may be off the
28442 if (! FRAME_VISIBLE_P (f
)
28443 || FRAME_GARBAGED_P (f
)
28444 || vpos
>= w
->current_matrix
->nrows
28445 || hpos
>= w
->current_matrix
->matrix_w
)
28448 /* If cursor is off and we want it off, return quickly. */
28449 if (!on
&& !w
->phys_cursor_on_p
)
28452 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28453 /* If cursor row is not enabled, we don't really know where to
28454 display the cursor. */
28455 if (!glyph_row
->enabled_p
)
28457 w
->phys_cursor_on_p
= false;
28462 if (!glyph_row
->exact_window_width_line_p
28463 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
28464 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
28466 eassert (input_blocked_p ());
28468 /* Set new_cursor_type to the cursor we want to be displayed. */
28469 new_cursor_type
= get_window_cursor_type (w
, glyph
,
28470 &new_cursor_width
, &active_cursor
);
28472 /* If cursor is currently being shown and we don't want it to be or
28473 it is in the wrong place, or the cursor type is not what we want,
28475 if (w
->phys_cursor_on_p
28477 || w
->phys_cursor
.x
!= x
28478 || w
->phys_cursor
.y
!= y
28479 /* HPOS can be negative in R2L rows whose
28480 exact_window_width_line_p flag is set (i.e. their newline
28481 would "overflow into the fringe"). */
28483 || new_cursor_type
!= w
->phys_cursor_type
28484 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
28485 && new_cursor_width
!= w
->phys_cursor_width
)))
28486 erase_phys_cursor (w
);
28488 /* Don't check phys_cursor_on_p here because that flag is only set
28489 to false in some cases where we know that the cursor has been
28490 completely erased, to avoid the extra work of erasing the cursor
28491 twice. In other words, phys_cursor_on_p can be true and the cursor
28492 still not be visible, or it has only been partly erased. */
28495 w
->phys_cursor_ascent
= glyph_row
->ascent
;
28496 w
->phys_cursor_height
= glyph_row
->height
;
28498 /* Set phys_cursor_.* before x_draw_.* is called because some
28499 of them may need the information. */
28500 w
->phys_cursor
.x
= x
;
28501 w
->phys_cursor
.y
= glyph_row
->y
;
28502 w
->phys_cursor
.hpos
= hpos
;
28503 w
->phys_cursor
.vpos
= vpos
;
28506 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
28507 new_cursor_type
, new_cursor_width
,
28508 on
, active_cursor
);
28512 /* Switch the display of W's cursor on or off, according to the value
28516 update_window_cursor (struct window
*w
, bool on
)
28518 /* Don't update cursor in windows whose frame is in the process
28519 of being deleted. */
28520 if (w
->current_matrix
)
28522 int hpos
= w
->phys_cursor
.hpos
;
28523 int vpos
= w
->phys_cursor
.vpos
;
28524 struct glyph_row
*row
;
28526 if (vpos
>= w
->current_matrix
->nrows
28527 || hpos
>= w
->current_matrix
->matrix_w
)
28530 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28532 /* When the window is hscrolled, cursor hpos can legitimately be
28533 out of bounds, but we draw the cursor at the corresponding
28534 window margin in that case. */
28535 if (!row
->reversed_p
&& hpos
< 0)
28537 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28538 hpos
= row
->used
[TEXT_AREA
] - 1;
28541 display_and_set_cursor (w
, on
, hpos
, vpos
,
28542 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28548 /* Call update_window_cursor with parameter ON_P on all leaf windows
28549 in the window tree rooted at W. */
28552 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
28556 if (WINDOWP (w
->contents
))
28557 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
28559 update_window_cursor (w
, on_p
);
28561 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
28567 Display the cursor on window W, or clear it, according to ON_P.
28568 Don't change the cursor's position. */
28571 x_update_cursor (struct frame
*f
, bool on_p
)
28573 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
28578 Clear the cursor of window W to background color, and mark the
28579 cursor as not shown. This is used when the text where the cursor
28580 is about to be rewritten. */
28583 x_clear_cursor (struct window
*w
)
28585 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
28586 update_window_cursor (w
, false);
28589 #endif /* HAVE_WINDOW_SYSTEM */
28591 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
28594 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
28595 int start_hpos
, int end_hpos
,
28596 enum draw_glyphs_face draw
)
28598 #ifdef HAVE_WINDOW_SYSTEM
28599 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
28601 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
28605 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
28606 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
28610 /* Display the active region described by mouse_face_* according to DRAW. */
28613 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
28615 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
28616 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28618 if (/* If window is in the process of being destroyed, don't bother
28620 w
->current_matrix
!= NULL
28621 /* Don't update mouse highlight if hidden. */
28622 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
28623 /* Recognize when we are called to operate on rows that don't exist
28624 anymore. This can happen when a window is split. */
28625 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
28627 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
28628 struct glyph_row
*row
, *first
, *last
;
28630 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
28631 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
28633 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
28635 int start_hpos
, end_hpos
, start_x
;
28637 /* For all but the first row, the highlight starts at column 0. */
28640 /* R2L rows have BEG and END in reversed order, but the
28641 screen drawing geometry is always left to right. So
28642 we need to mirror the beginning and end of the
28643 highlighted area in R2L rows. */
28644 if (!row
->reversed_p
)
28646 start_hpos
= hlinfo
->mouse_face_beg_col
;
28647 start_x
= hlinfo
->mouse_face_beg_x
;
28649 else if (row
== last
)
28651 start_hpos
= hlinfo
->mouse_face_end_col
;
28652 start_x
= hlinfo
->mouse_face_end_x
;
28660 else if (row
->reversed_p
&& row
== last
)
28662 start_hpos
= hlinfo
->mouse_face_end_col
;
28663 start_x
= hlinfo
->mouse_face_end_x
;
28673 if (!row
->reversed_p
)
28674 end_hpos
= hlinfo
->mouse_face_end_col
;
28675 else if (row
== first
)
28676 end_hpos
= hlinfo
->mouse_face_beg_col
;
28679 end_hpos
= row
->used
[TEXT_AREA
];
28680 if (draw
== DRAW_NORMAL_TEXT
)
28681 row
->fill_line_p
= true; /* Clear to end of line. */
28684 else if (row
->reversed_p
&& row
== first
)
28685 end_hpos
= hlinfo
->mouse_face_beg_col
;
28688 end_hpos
= row
->used
[TEXT_AREA
];
28689 if (draw
== DRAW_NORMAL_TEXT
)
28690 row
->fill_line_p
= true; /* Clear to end of line. */
28693 if (end_hpos
> start_hpos
)
28695 draw_row_with_mouse_face (w
, start_x
, row
,
28696 start_hpos
, end_hpos
, draw
);
28699 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
28703 /* When we've written over the cursor, arrange for it to
28704 be displayed again. */
28705 if (FRAME_WINDOW_P (f
)
28706 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
28708 #ifdef HAVE_WINDOW_SYSTEM
28709 int hpos
= w
->phys_cursor
.hpos
;
28711 /* When the window is hscrolled, cursor hpos can legitimately be
28712 out of bounds, but we draw the cursor at the corresponding
28713 window margin in that case. */
28714 if (!row
->reversed_p
&& hpos
< 0)
28716 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28717 hpos
= row
->used
[TEXT_AREA
] - 1;
28720 display_and_set_cursor (w
, true, hpos
, w
->phys_cursor
.vpos
,
28721 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28723 #endif /* HAVE_WINDOW_SYSTEM */
28727 #ifdef HAVE_WINDOW_SYSTEM
28728 /* Change the mouse cursor. */
28729 if (FRAME_WINDOW_P (f
) && NILP (do_mouse_tracking
))
28731 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
28732 if (draw
== DRAW_NORMAL_TEXT
28733 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
28734 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
28737 if (draw
== DRAW_MOUSE_FACE
)
28738 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
28740 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
28742 #endif /* HAVE_WINDOW_SYSTEM */
28746 Clear out the mouse-highlighted active region.
28747 Redraw it un-highlighted first. Value is true if mouse
28748 face was actually drawn unhighlighted. */
28751 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
28754 = !hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
);
28756 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
28757 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28758 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28759 hlinfo
->mouse_face_window
= Qnil
;
28760 hlinfo
->mouse_face_overlay
= Qnil
;
28764 /* Return true if the coordinates HPOS and VPOS on windows W are
28765 within the mouse face on that window. */
28767 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
28769 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28771 /* Quickly resolve the easy cases. */
28772 if (!(WINDOWP (hlinfo
->mouse_face_window
)
28773 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
28775 if (vpos
< hlinfo
->mouse_face_beg_row
28776 || vpos
> hlinfo
->mouse_face_end_row
)
28778 if (vpos
> hlinfo
->mouse_face_beg_row
28779 && vpos
< hlinfo
->mouse_face_end_row
)
28782 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
28784 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28786 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
28789 else if ((vpos
== hlinfo
->mouse_face_beg_row
28790 && hpos
>= hlinfo
->mouse_face_beg_col
)
28791 || (vpos
== hlinfo
->mouse_face_end_row
28792 && hpos
< hlinfo
->mouse_face_end_col
))
28797 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28799 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
28802 else if ((vpos
== hlinfo
->mouse_face_beg_row
28803 && hpos
<= hlinfo
->mouse_face_beg_col
)
28804 || (vpos
== hlinfo
->mouse_face_end_row
28805 && hpos
> hlinfo
->mouse_face_end_col
))
28813 True if physical cursor of window W is within mouse face. */
28816 cursor_in_mouse_face_p (struct window
*w
)
28818 int hpos
= w
->phys_cursor
.hpos
;
28819 int vpos
= w
->phys_cursor
.vpos
;
28820 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28822 /* When the window is hscrolled, cursor hpos can legitimately be out
28823 of bounds, but we draw the cursor at the corresponding window
28824 margin in that case. */
28825 if (!row
->reversed_p
&& hpos
< 0)
28827 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28828 hpos
= row
->used
[TEXT_AREA
] - 1;
28830 return coords_in_mouse_face_p (w
, hpos
, vpos
);
28835 /* Find the glyph rows START_ROW and END_ROW of window W that display
28836 characters between buffer positions START_CHARPOS and END_CHARPOS
28837 (excluding END_CHARPOS). DISP_STRING is a display string that
28838 covers these buffer positions. This is similar to
28839 row_containing_pos, but is more accurate when bidi reordering makes
28840 buffer positions change non-linearly with glyph rows. */
28842 rows_from_pos_range (struct window
*w
,
28843 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
28844 Lisp_Object disp_string
,
28845 struct glyph_row
**start
, struct glyph_row
**end
)
28847 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28848 int last_y
= window_text_bottom_y (w
);
28849 struct glyph_row
*row
;
28854 while (!first
->enabled_p
28855 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
28858 /* Find the START row. */
28860 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
28863 /* A row can potentially be the START row if the range of the
28864 characters it displays intersects the range
28865 [START_CHARPOS..END_CHARPOS). */
28866 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
28867 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
28868 /* See the commentary in row_containing_pos, for the
28869 explanation of the complicated way to check whether
28870 some position is beyond the end of the characters
28871 displayed by a row. */
28872 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28873 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28874 && !row
->ends_at_zv_p
28875 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
28876 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28877 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28878 && !row
->ends_at_zv_p
28879 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
28881 /* Found a candidate row. Now make sure at least one of the
28882 glyphs it displays has a charpos from the range
28883 [START_CHARPOS..END_CHARPOS).
28885 This is not obvious because bidi reordering could make
28886 buffer positions of a row be 1,2,3,102,101,100, and if we
28887 want to highlight characters in [50..60), we don't want
28888 this row, even though [50..60) does intersect [1..103),
28889 the range of character positions given by the row's start
28890 and end positions. */
28891 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
28892 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
28896 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28897 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28898 /* A glyph that comes from DISP_STRING is by
28899 definition to be highlighted. */
28900 || EQ (g
->object
, disp_string
))
28909 /* Find the END row. */
28911 /* If the last row is partially visible, start looking for END
28912 from that row, instead of starting from FIRST. */
28913 && !(row
->enabled_p
28914 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
28916 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
28918 struct glyph_row
*next
= row
+ 1;
28919 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
28921 if (!next
->enabled_p
28922 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
28923 /* The first row >= START whose range of displayed characters
28924 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
28925 is the row END + 1. */
28926 || (start_charpos
< next_start
28927 && end_charpos
< next_start
)
28928 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28929 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28930 && !next
->ends_at_zv_p
28931 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
28932 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28933 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28934 && !next
->ends_at_zv_p
28935 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
28942 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
28943 but none of the characters it displays are in the range, it is
28945 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
28946 struct glyph
*s
= g
;
28947 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
28951 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28952 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28953 /* If the buffer position of the first glyph in
28954 the row is equal to END_CHARPOS, it means
28955 the last character to be highlighted is the
28956 newline of ROW, and we must consider NEXT as
28958 || (((!next
->reversed_p
&& g
== s
)
28959 || (next
->reversed_p
&& g
== e
- 1))
28960 && (g
->charpos
== end_charpos
28961 /* Special case for when NEXT is an
28962 empty line at ZV. */
28963 || (g
->charpos
== -1
28964 && !row
->ends_at_zv_p
28965 && next_start
== end_charpos
)))))
28966 /* A glyph that comes from DISP_STRING is by
28967 definition to be highlighted. */
28968 || EQ (g
->object
, disp_string
))
28977 /* The first row that ends at ZV must be the last to be
28979 else if (next
->ends_at_zv_p
)
28988 /* This function sets the mouse_face_* elements of HLINFO, assuming
28989 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
28990 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
28991 for the overlay or run of text properties specifying the mouse
28992 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
28993 before-string and after-string that must also be highlighted.
28994 DISP_STRING, if non-nil, is a display string that may cover some
28995 or all of the highlighted text. */
28998 mouse_face_from_buffer_pos (Lisp_Object window
,
28999 Mouse_HLInfo
*hlinfo
,
29000 ptrdiff_t mouse_charpos
,
29001 ptrdiff_t start_charpos
,
29002 ptrdiff_t end_charpos
,
29003 Lisp_Object before_string
,
29004 Lisp_Object after_string
,
29005 Lisp_Object disp_string
)
29007 struct window
*w
= XWINDOW (window
);
29008 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29009 struct glyph_row
*r1
, *r2
;
29010 struct glyph
*glyph
, *end
;
29011 ptrdiff_t ignore
, pos
;
29014 eassert (NILP (disp_string
) || STRINGP (disp_string
));
29015 eassert (NILP (before_string
) || STRINGP (before_string
));
29016 eassert (NILP (after_string
) || STRINGP (after_string
));
29018 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
29019 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
29021 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
29022 /* If the before-string or display-string contains newlines,
29023 rows_from_pos_range skips to its last row. Move back. */
29024 if (!NILP (before_string
) || !NILP (disp_string
))
29026 struct glyph_row
*prev
;
29027 while ((prev
= r1
- 1, prev
>= first
)
29028 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
29029 && prev
->used
[TEXT_AREA
] > 0)
29031 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
29032 glyph
= beg
+ prev
->used
[TEXT_AREA
];
29033 while (--glyph
>= beg
&& NILP (glyph
->object
));
29035 || !(EQ (glyph
->object
, before_string
)
29036 || EQ (glyph
->object
, disp_string
)))
29043 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
29044 hlinfo
->mouse_face_past_end
= true;
29046 else if (!NILP (after_string
))
29048 /* If the after-string has newlines, advance to its last row. */
29049 struct glyph_row
*next
;
29050 struct glyph_row
*last
29051 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
29053 for (next
= r2
+ 1;
29055 && next
->used
[TEXT_AREA
] > 0
29056 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
29060 /* The rest of the display engine assumes that mouse_face_beg_row is
29061 either above mouse_face_end_row or identical to it. But with
29062 bidi-reordered continued lines, the row for START_CHARPOS could
29063 be below the row for END_CHARPOS. If so, swap the rows and store
29064 them in correct order. */
29067 struct glyph_row
*tem
= r2
;
29073 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
29074 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
29076 /* For a bidi-reordered row, the positions of BEFORE_STRING,
29077 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
29078 could be anywhere in the row and in any order. The strategy
29079 below is to find the leftmost and the rightmost glyph that
29080 belongs to either of these 3 strings, or whose position is
29081 between START_CHARPOS and END_CHARPOS, and highlight all the
29082 glyphs between those two. This may cover more than just the text
29083 between START_CHARPOS and END_CHARPOS if the range of characters
29084 strides the bidi level boundary, e.g. if the beginning is in R2L
29085 text while the end is in L2R text or vice versa. */
29086 if (!r1
->reversed_p
)
29088 /* This row is in a left to right paragraph. Scan it left to
29090 glyph
= r1
->glyphs
[TEXT_AREA
];
29091 end
= glyph
+ r1
->used
[TEXT_AREA
];
29094 /* Skip truncation glyphs at the start of the glyph row. */
29095 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
29097 && NILP (glyph
->object
)
29098 && glyph
->charpos
< 0;
29100 x
+= glyph
->pixel_width
;
29102 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
29103 or DISP_STRING, and the first glyph from buffer whose
29104 position is between START_CHARPOS and END_CHARPOS. */
29106 && !NILP (glyph
->object
)
29107 && !EQ (glyph
->object
, disp_string
)
29108 && !(BUFFERP (glyph
->object
)
29109 && (glyph
->charpos
>= start_charpos
29110 && glyph
->charpos
< end_charpos
));
29113 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29114 are present at buffer positions between START_CHARPOS and
29115 END_CHARPOS, or if they come from an overlay. */
29116 if (EQ (glyph
->object
, before_string
))
29118 pos
= string_buffer_position (before_string
,
29120 /* If pos == 0, it means before_string came from an
29121 overlay, not from a buffer position. */
29122 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29125 else if (EQ (glyph
->object
, after_string
))
29127 pos
= string_buffer_position (after_string
, end_charpos
);
29128 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29131 x
+= glyph
->pixel_width
;
29133 hlinfo
->mouse_face_beg_x
= x
;
29134 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
29138 /* This row is in a right to left paragraph. Scan it right to
29142 end
= r1
->glyphs
[TEXT_AREA
] - 1;
29143 glyph
= end
+ r1
->used
[TEXT_AREA
];
29145 /* Skip truncation glyphs at the start of the glyph row. */
29146 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
29148 && NILP (glyph
->object
)
29149 && glyph
->charpos
< 0;
29153 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
29154 or DISP_STRING, and the first glyph from buffer whose
29155 position is between START_CHARPOS and END_CHARPOS. */
29157 && !NILP (glyph
->object
)
29158 && !EQ (glyph
->object
, disp_string
)
29159 && !(BUFFERP (glyph
->object
)
29160 && (glyph
->charpos
>= start_charpos
29161 && glyph
->charpos
< end_charpos
));
29164 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29165 are present at buffer positions between START_CHARPOS and
29166 END_CHARPOS, or if they come from an overlay. */
29167 if (EQ (glyph
->object
, before_string
))
29169 pos
= string_buffer_position (before_string
, start_charpos
);
29170 /* If pos == 0, it means before_string came from an
29171 overlay, not from a buffer position. */
29172 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29175 else if (EQ (glyph
->object
, after_string
))
29177 pos
= string_buffer_position (after_string
, end_charpos
);
29178 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29183 glyph
++; /* first glyph to the right of the highlighted area */
29184 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
29185 x
+= g
->pixel_width
;
29186 hlinfo
->mouse_face_beg_x
= x
;
29187 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
29190 /* If the highlight ends in a different row, compute GLYPH and END
29191 for the end row. Otherwise, reuse the values computed above for
29192 the row where the highlight begins. */
29195 if (!r2
->reversed_p
)
29197 glyph
= r2
->glyphs
[TEXT_AREA
];
29198 end
= glyph
+ r2
->used
[TEXT_AREA
];
29203 end
= r2
->glyphs
[TEXT_AREA
] - 1;
29204 glyph
= end
+ r2
->used
[TEXT_AREA
];
29208 if (!r2
->reversed_p
)
29210 /* Skip truncation and continuation glyphs near the end of the
29211 row, and also blanks and stretch glyphs inserted by
29212 extend_face_to_end_of_line. */
29214 && NILP ((end
- 1)->object
))
29216 /* Scan the rest of the glyph row from the end, looking for the
29217 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
29218 DISP_STRING, or whose position is between START_CHARPOS
29222 && !NILP (end
->object
)
29223 && !EQ (end
->object
, disp_string
)
29224 && !(BUFFERP (end
->object
)
29225 && (end
->charpos
>= start_charpos
29226 && end
->charpos
< end_charpos
));
29229 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29230 are present at buffer positions between START_CHARPOS and
29231 END_CHARPOS, or if they come from an overlay. */
29232 if (EQ (end
->object
, before_string
))
29234 pos
= string_buffer_position (before_string
, start_charpos
);
29235 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29238 else if (EQ (end
->object
, after_string
))
29240 pos
= string_buffer_position (after_string
, end_charpos
);
29241 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29245 /* Find the X coordinate of the last glyph to be highlighted. */
29246 for (; glyph
<= end
; ++glyph
)
29247 x
+= glyph
->pixel_width
;
29249 hlinfo
->mouse_face_end_x
= x
;
29250 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
29254 /* Skip truncation and continuation glyphs near the end of the
29255 row, and also blanks and stretch glyphs inserted by
29256 extend_face_to_end_of_line. */
29260 && NILP (end
->object
))
29262 x
+= end
->pixel_width
;
29265 /* Scan the rest of the glyph row from the end, looking for the
29266 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
29267 DISP_STRING, or whose position is between START_CHARPOS
29271 && !NILP (end
->object
)
29272 && !EQ (end
->object
, disp_string
)
29273 && !(BUFFERP (end
->object
)
29274 && (end
->charpos
>= start_charpos
29275 && end
->charpos
< end_charpos
));
29278 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29279 are present at buffer positions between START_CHARPOS and
29280 END_CHARPOS, or if they come from an overlay. */
29281 if (EQ (end
->object
, before_string
))
29283 pos
= string_buffer_position (before_string
, start_charpos
);
29284 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29287 else if (EQ (end
->object
, after_string
))
29289 pos
= string_buffer_position (after_string
, end_charpos
);
29290 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29293 x
+= end
->pixel_width
;
29295 /* If we exited the above loop because we arrived at the last
29296 glyph of the row, and its buffer position is still not in
29297 range, it means the last character in range is the preceding
29298 newline. Bump the end column and x values to get past the
29301 && BUFFERP (end
->object
)
29302 && (end
->charpos
< start_charpos
29303 || end
->charpos
>= end_charpos
))
29305 x
+= end
->pixel_width
;
29308 hlinfo
->mouse_face_end_x
= x
;
29309 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
29312 hlinfo
->mouse_face_window
= window
;
29313 hlinfo
->mouse_face_face_id
29314 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
29316 !hlinfo
->mouse_face_hidden
, -1);
29317 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29320 /* The following function is not used anymore (replaced with
29321 mouse_face_from_string_pos), but I leave it here for the time
29322 being, in case someone would. */
29324 #if false /* not used */
29326 /* Find the position of the glyph for position POS in OBJECT in
29327 window W's current matrix, and return in *X, *Y the pixel
29328 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
29330 RIGHT_P means return the position of the right edge of the glyph.
29331 !RIGHT_P means return the left edge position.
29333 If no glyph for POS exists in the matrix, return the position of
29334 the glyph with the next smaller position that is in the matrix, if
29335 RIGHT_P is false. If RIGHT_P, and no glyph for POS
29336 exists in the matrix, return the position of the glyph with the
29337 next larger position in OBJECT.
29339 Value is true if a glyph was found. */
29342 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
29343 int *hpos
, int *vpos
, int *x
, int *y
, bool right_p
)
29345 int yb
= window_text_bottom_y (w
);
29346 struct glyph_row
*r
;
29347 struct glyph
*best_glyph
= NULL
;
29348 struct glyph_row
*best_row
= NULL
;
29351 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29352 r
->enabled_p
&& r
->y
< yb
;
29355 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
29356 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
29359 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
29360 if (EQ (g
->object
, object
))
29362 if (g
->charpos
== pos
)
29369 else if (best_glyph
== NULL
29370 || ((eabs (g
->charpos
- pos
)
29371 < eabs (best_glyph
->charpos
- pos
))
29374 : g
->charpos
> pos
)))
29388 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
29392 *x
+= best_glyph
->pixel_width
;
29397 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
29400 return best_glyph
!= NULL
;
29402 #endif /* not used */
29404 /* Find the positions of the first and the last glyphs in window W's
29405 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
29406 (assumed to be a string), and return in HLINFO's mouse_face_*
29407 members the pixel and column/row coordinates of those glyphs. */
29410 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
29411 Lisp_Object object
,
29412 ptrdiff_t startpos
, ptrdiff_t endpos
)
29414 int yb
= window_text_bottom_y (w
);
29415 struct glyph_row
*r
;
29416 struct glyph
*g
, *e
;
29418 bool found
= false;
29420 /* Find the glyph row with at least one position in the range
29421 [STARTPOS..ENDPOS), and the first glyph in that row whose
29422 position belongs to that range. */
29423 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29424 r
->enabled_p
&& r
->y
< yb
;
29427 if (!r
->reversed_p
)
29429 g
= r
->glyphs
[TEXT_AREA
];
29430 e
= g
+ r
->used
[TEXT_AREA
];
29431 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
29432 if (EQ (g
->object
, object
)
29433 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
29435 hlinfo
->mouse_face_beg_row
29436 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29437 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
29438 hlinfo
->mouse_face_beg_x
= gx
;
29447 e
= r
->glyphs
[TEXT_AREA
];
29448 g
= e
+ r
->used
[TEXT_AREA
];
29449 for ( ; g
> e
; --g
)
29450 if (EQ ((g
-1)->object
, object
)
29451 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
29453 hlinfo
->mouse_face_beg_row
29454 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29455 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
29456 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
29457 gx
+= g1
->pixel_width
;
29458 hlinfo
->mouse_face_beg_x
= gx
;
29470 /* Starting with the next row, look for the first row which does NOT
29471 include any glyphs whose positions are in the range. */
29472 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
29474 g
= r
->glyphs
[TEXT_AREA
];
29475 e
= g
+ r
->used
[TEXT_AREA
];
29477 for ( ; g
< e
; ++g
)
29478 if (EQ (g
->object
, object
)
29479 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
29488 /* The highlighted region ends on the previous row. */
29491 /* Set the end row. */
29492 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29494 /* Compute and set the end column and the end column's horizontal
29495 pixel coordinate. */
29496 if (!r
->reversed_p
)
29498 g
= r
->glyphs
[TEXT_AREA
];
29499 e
= g
+ r
->used
[TEXT_AREA
];
29500 for ( ; e
> g
; --e
)
29501 if (EQ ((e
-1)->object
, object
)
29502 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
29504 hlinfo
->mouse_face_end_col
= e
- g
;
29506 for (gx
= r
->x
; g
< e
; ++g
)
29507 gx
+= g
->pixel_width
;
29508 hlinfo
->mouse_face_end_x
= gx
;
29512 e
= r
->glyphs
[TEXT_AREA
];
29513 g
= e
+ r
->used
[TEXT_AREA
];
29514 for (gx
= r
->x
; e
< g
; ++e
)
29516 if (EQ (e
->object
, object
)
29517 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
29519 gx
+= e
->pixel_width
;
29521 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
29522 hlinfo
->mouse_face_end_x
= gx
;
29526 #ifdef HAVE_WINDOW_SYSTEM
29528 /* See if position X, Y is within a hot-spot of an image. */
29531 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
29533 if (!CONSP (hot_spot
))
29536 if (EQ (XCAR (hot_spot
), Qrect
))
29538 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
29539 Lisp_Object rect
= XCDR (hot_spot
);
29543 if (!CONSP (XCAR (rect
)))
29545 if (!CONSP (XCDR (rect
)))
29547 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
29549 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
29551 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
29553 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
29557 else if (EQ (XCAR (hot_spot
), Qcircle
))
29559 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
29560 Lisp_Object circ
= XCDR (hot_spot
);
29561 Lisp_Object lr
, lx0
, ly0
;
29563 && CONSP (XCAR (circ
))
29564 && (lr
= XCDR (circ
), NUMBERP (lr
))
29565 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
29566 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
29568 double r
= XFLOATINT (lr
);
29569 double dx
= XINT (lx0
) - x
;
29570 double dy
= XINT (ly0
) - y
;
29571 return (dx
* dx
+ dy
* dy
<= r
* r
);
29574 else if (EQ (XCAR (hot_spot
), Qpoly
))
29576 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
29577 if (VECTORP (XCDR (hot_spot
)))
29579 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
29580 Lisp_Object
*poly
= v
->contents
;
29581 ptrdiff_t n
= v
->header
.size
;
29583 bool inside
= false;
29584 Lisp_Object lx
, ly
;
29587 /* Need an even number of coordinates, and at least 3 edges. */
29588 if (n
< 6 || n
& 1)
29591 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
29592 If count is odd, we are inside polygon. Pixels on edges
29593 may or may not be included depending on actual geometry of the
29595 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
29596 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
29598 x0
= XINT (lx
), y0
= XINT (ly
);
29599 for (i
= 0; i
< n
; i
+= 2)
29601 int x1
= x0
, y1
= y0
;
29602 if ((lx
= poly
[i
], !INTEGERP (lx
))
29603 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
29605 x0
= XINT (lx
), y0
= XINT (ly
);
29607 /* Does this segment cross the X line? */
29615 if (y
> y0
&& y
> y1
)
29617 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
29627 find_hot_spot (Lisp_Object map
, int x
, int y
)
29629 while (CONSP (map
))
29631 if (CONSP (XCAR (map
))
29632 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
29640 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
29642 doc
: /* Lookup in image map MAP coordinates X and Y.
29643 An image map is an alist where each element has the format (AREA ID PLIST).
29644 An AREA is specified as either a rectangle, a circle, or a polygon:
29645 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
29646 pixel coordinates of the upper left and bottom right corners.
29647 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
29648 and the radius of the circle; r may be a float or integer.
29649 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
29650 vector describes one corner in the polygon.
29651 Returns the alist element for the first matching AREA in MAP. */)
29652 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
29660 return find_hot_spot (map
,
29661 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
29662 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
29664 #endif /* HAVE_WINDOW_SYSTEM */
29667 /* Display frame CURSOR, optionally using shape defined by POINTER. */
29669 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
29671 #ifdef HAVE_WINDOW_SYSTEM
29672 if (!FRAME_WINDOW_P (f
))
29675 /* Do not change cursor shape while dragging mouse. */
29676 if (EQ (do_mouse_tracking
, Qdragging
))
29679 if (!NILP (pointer
))
29681 if (EQ (pointer
, Qarrow
))
29682 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29683 else if (EQ (pointer
, Qhand
))
29684 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
29685 else if (EQ (pointer
, Qtext
))
29686 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
29687 else if (EQ (pointer
, intern ("hdrag")))
29688 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29689 else if (EQ (pointer
, intern ("nhdrag")))
29690 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
29691 # ifdef HAVE_X_WINDOWS
29692 else if (EQ (pointer
, intern ("vdrag")))
29693 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29695 else if (EQ (pointer
, intern ("hourglass")))
29696 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
29697 else if (EQ (pointer
, Qmodeline
))
29698 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
29700 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29703 if (cursor
!= No_Cursor
)
29704 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
29708 /* Take proper action when mouse has moved to the mode or header line
29709 or marginal area AREA of window W, x-position X and y-position Y.
29710 X is relative to the start of the text display area of W, so the
29711 width of bitmap areas and scroll bars must be subtracted to get a
29712 position relative to the start of the mode line. */
29715 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
29716 enum window_part area
)
29718 struct window
*w
= XWINDOW (window
);
29719 struct frame
*f
= XFRAME (w
->frame
);
29720 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29721 #ifdef HAVE_WINDOW_SYSTEM
29722 Display_Info
*dpyinfo
;
29724 Cursor cursor
= No_Cursor
;
29725 Lisp_Object pointer
= Qnil
;
29726 int dx
, dy
, width
, height
;
29728 Lisp_Object string
, object
= Qnil
;
29729 Lisp_Object pos UNINIT
;
29730 Lisp_Object mouse_face
;
29731 int original_x_pixel
= x
;
29732 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
29733 struct glyph_row
*row UNINIT
;
29735 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
29740 /* Kludge alert: mode_line_string takes X/Y in pixels, but
29741 returns them in row/column units! */
29742 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
29743 &object
, &dx
, &dy
, &width
, &height
);
29745 row
= (area
== ON_MODE_LINE
29746 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
29747 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
29749 /* Find the glyph under the mouse pointer. */
29750 if (row
->mode_line_p
&& row
->enabled_p
)
29752 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
29753 end
= glyph
+ row
->used
[TEXT_AREA
];
29755 for (x0
= original_x_pixel
;
29756 glyph
< end
&& x0
>= glyph
->pixel_width
;
29758 x0
-= glyph
->pixel_width
;
29766 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
29767 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
29768 returns them in row/column units! */
29769 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
29770 &object
, &dx
, &dy
, &width
, &height
);
29773 Lisp_Object help
= Qnil
;
29775 #ifdef HAVE_WINDOW_SYSTEM
29776 if (IMAGEP (object
))
29778 Lisp_Object image_map
, hotspot
;
29779 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
29781 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
29783 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
29787 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
29788 If so, we could look for mouse-enter, mouse-leave
29789 properties in PLIST (and do something...). */
29790 hotspot
= XCDR (hotspot
);
29791 if (CONSP (hotspot
)
29792 && (plist
= XCAR (hotspot
), CONSP (plist
)))
29794 pointer
= Fplist_get (plist
, Qpointer
);
29795 if (NILP (pointer
))
29797 help
= Fplist_get (plist
, Qhelp_echo
);
29800 help_echo_string
= help
;
29801 XSETWINDOW (help_echo_window
, w
);
29802 help_echo_object
= w
->contents
;
29803 help_echo_pos
= charpos
;
29807 if (NILP (pointer
))
29808 pointer
= Fplist_get (XCDR (object
), QCpointer
);
29810 #endif /* HAVE_WINDOW_SYSTEM */
29812 if (STRINGP (string
))
29813 pos
= make_number (charpos
);
29815 /* Set the help text and mouse pointer. If the mouse is on a part
29816 of the mode line without any text (e.g. past the right edge of
29817 the mode line text), use the default help text and pointer. */
29818 if (STRINGP (string
) || area
== ON_MODE_LINE
)
29820 /* Arrange to display the help by setting the global variables
29821 help_echo_string, help_echo_object, and help_echo_pos. */
29824 if (STRINGP (string
))
29825 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
29829 help_echo_string
= help
;
29830 XSETWINDOW (help_echo_window
, w
);
29831 help_echo_object
= string
;
29832 help_echo_pos
= charpos
;
29834 else if (area
== ON_MODE_LINE
)
29836 Lisp_Object default_help
29837 = buffer_local_value (Qmode_line_default_help_echo
,
29840 if (STRINGP (default_help
))
29842 help_echo_string
= default_help
;
29843 XSETWINDOW (help_echo_window
, w
);
29844 help_echo_object
= Qnil
;
29845 help_echo_pos
= -1;
29850 #ifdef HAVE_WINDOW_SYSTEM
29851 /* Change the mouse pointer according to what is under it. */
29852 if (FRAME_WINDOW_P (f
))
29854 bool draggable
= (! WINDOW_BOTTOMMOST_P (w
)
29856 || NILP (Vresize_mini_windows
));
29858 dpyinfo
= FRAME_DISPLAY_INFO (f
);
29859 if (STRINGP (string
))
29861 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29863 if (NILP (pointer
))
29864 pointer
= Fget_text_property (pos
, Qpointer
, string
);
29866 /* Change the mouse pointer according to what is under X/Y. */
29868 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
29871 map
= Fget_text_property (pos
, Qlocal_map
, string
);
29872 if (!KEYMAPP (map
))
29873 map
= Fget_text_property (pos
, Qkeymap
, string
);
29874 if (!KEYMAPP (map
) && draggable
)
29875 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
29878 else if (draggable
)
29879 /* Default mode-line pointer. */
29880 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29885 /* Change the mouse face according to what is under X/Y. */
29886 bool mouse_face_shown
= false;
29887 if (STRINGP (string
))
29889 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
29890 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
29891 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
29896 struct glyph
* tmp_glyph
;
29900 int total_pixel_width
;
29901 ptrdiff_t begpos
, endpos
, ignore
;
29905 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
29906 Qmouse_face
, string
, Qnil
);
29912 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
29914 endpos
= SCHARS (string
);
29918 /* Calculate the glyph position GPOS of GLYPH in the
29919 displayed string, relative to the beginning of the
29920 highlighted part of the string.
29922 Note: GPOS is different from CHARPOS. CHARPOS is the
29923 position of GLYPH in the internal string object. A mode
29924 line string format has structures which are converted to
29925 a flattened string by the Emacs Lisp interpreter. The
29926 internal string is an element of those structures. The
29927 displayed string is the flattened string. */
29928 tmp_glyph
= row_start_glyph
;
29929 while (tmp_glyph
< glyph
29930 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29931 && begpos
<= tmp_glyph
->charpos
29932 && tmp_glyph
->charpos
< endpos
)))
29934 gpos
= glyph
- tmp_glyph
;
29936 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
29937 the highlighted part of the displayed string to which
29938 GLYPH belongs. Note: GSEQ_LENGTH is different from
29939 SCHARS (STRING), because the latter returns the length of
29940 the internal string. */
29941 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
29943 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29944 && begpos
<= tmp_glyph
->charpos
29945 && tmp_glyph
->charpos
< endpos
));
29948 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
29950 /* Calculate the total pixel width of all the glyphs between
29951 the beginning of the highlighted area and GLYPH. */
29952 total_pixel_width
= 0;
29953 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
29954 total_pixel_width
+= tmp_glyph
->pixel_width
;
29956 /* Pre calculation of re-rendering position. Note: X is in
29957 column units here, after the call to mode_line_string or
29958 marginal_area_string. */
29960 vpos
= (area
== ON_MODE_LINE
29961 ? (w
->current_matrix
)->nrows
- 1
29964 /* If GLYPH's position is included in the region that is
29965 already drawn in mouse face, we have nothing to do. */
29966 if ( EQ (window
, hlinfo
->mouse_face_window
)
29967 && (!row
->reversed_p
29968 ? (hlinfo
->mouse_face_beg_col
<= hpos
29969 && hpos
< hlinfo
->mouse_face_end_col
)
29970 /* In R2L rows we swap BEG and END, see below. */
29971 : (hlinfo
->mouse_face_end_col
<= hpos
29972 && hpos
< hlinfo
->mouse_face_beg_col
))
29973 && hlinfo
->mouse_face_beg_row
== vpos
)
29976 if (clear_mouse_face (hlinfo
))
29977 cursor
= No_Cursor
;
29979 if (!row
->reversed_p
)
29981 hlinfo
->mouse_face_beg_col
= hpos
;
29982 hlinfo
->mouse_face_beg_x
= original_x_pixel
29983 - (total_pixel_width
+ dx
);
29984 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
29985 hlinfo
->mouse_face_end_x
= 0;
29989 /* In R2L rows, show_mouse_face expects BEG and END
29990 coordinates to be swapped. */
29991 hlinfo
->mouse_face_end_col
= hpos
;
29992 hlinfo
->mouse_face_end_x
= original_x_pixel
29993 - (total_pixel_width
+ dx
);
29994 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
29995 hlinfo
->mouse_face_beg_x
= 0;
29998 hlinfo
->mouse_face_beg_row
= vpos
;
29999 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
30000 hlinfo
->mouse_face_past_end
= false;
30001 hlinfo
->mouse_face_window
= window
;
30003 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
30008 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
30009 mouse_face_shown
= true;
30011 if (NILP (pointer
))
30016 /* If mouse-face doesn't need to be shown, clear any existing
30018 if ((area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
) && !mouse_face_shown
)
30019 clear_mouse_face (hlinfo
);
30021 define_frame_cursor1 (f
, cursor
, pointer
);
30026 Take proper action when the mouse has moved to position X, Y on
30027 frame F with regards to highlighting portions of display that have
30028 mouse-face properties. Also de-highlight portions of display where
30029 the mouse was before, set the mouse pointer shape as appropriate
30030 for the mouse coordinates, and activate help echo (tooltips).
30031 X and Y can be negative or out of range. */
30034 note_mouse_highlight (struct frame
*f
, int x
, int y
)
30036 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
30037 enum window_part part
= ON_NOTHING
;
30038 Lisp_Object window
;
30040 Cursor cursor
= No_Cursor
;
30041 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
30044 /* When a menu is active, don't highlight because this looks odd. */
30045 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
30046 if (popup_activated ())
30050 if (!f
->glyphs_initialized_p
30051 || f
->pointer_invisible
)
30054 hlinfo
->mouse_face_mouse_x
= x
;
30055 hlinfo
->mouse_face_mouse_y
= y
;
30056 hlinfo
->mouse_face_mouse_frame
= f
;
30058 if (hlinfo
->mouse_face_defer
)
30061 /* Which window is that in? */
30062 window
= window_from_coordinates (f
, x
, y
, &part
, true);
30064 /* If displaying active text in another window, clear that. */
30065 if (! EQ (window
, hlinfo
->mouse_face_window
)
30066 /* Also clear if we move out of text area in same window. */
30067 || (!NILP (hlinfo
->mouse_face_window
)
30070 && part
!= ON_MODE_LINE
30071 && part
!= ON_HEADER_LINE
))
30072 clear_mouse_face (hlinfo
);
30074 /* Not on a window -> return. */
30075 if (!WINDOWP (window
))
30078 /* Reset help_echo_string. It will get recomputed below. */
30079 help_echo_string
= Qnil
;
30081 /* Convert to window-relative pixel coordinates. */
30082 w
= XWINDOW (window
);
30083 frame_to_window_pixel_xy (w
, &x
, &y
);
30085 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
30086 /* Handle tool-bar window differently since it doesn't display a
30088 if (EQ (window
, f
->tool_bar_window
))
30090 note_tool_bar_highlight (f
, x
, y
);
30095 /* Mouse is on the mode, header line or margin? */
30096 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
30097 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
30099 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
30101 #ifdef HAVE_WINDOW_SYSTEM
30102 if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
30104 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30105 /* Show non-text cursor (Bug#16647). */
30113 #ifdef HAVE_WINDOW_SYSTEM
30114 if (part
== ON_VERTICAL_BORDER
)
30116 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
30117 help_echo_string
= build_string ("drag-mouse-1: resize");
30119 else if (part
== ON_RIGHT_DIVIDER
)
30121 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
30122 help_echo_string
= build_string ("drag-mouse-1: resize");
30124 else if (part
== ON_BOTTOM_DIVIDER
)
30125 if (! WINDOW_BOTTOMMOST_P (w
)
30127 || NILP (Vresize_mini_windows
))
30129 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
30130 help_echo_string
= build_string ("drag-mouse-1: resize");
30133 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30134 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
30135 || part
== ON_VERTICAL_SCROLL_BAR
30136 || part
== ON_HORIZONTAL_SCROLL_BAR
)
30137 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30139 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
30142 /* Are we in a window whose display is up to date?
30143 And verify the buffer's text has not changed. */
30144 b
= XBUFFER (w
->contents
);
30145 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
30147 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
30149 struct glyph
*glyph
;
30150 Lisp_Object object
;
30151 Lisp_Object mouse_face
= Qnil
, position
;
30152 Lisp_Object
*overlay_vec
= NULL
;
30153 ptrdiff_t i
, noverlays
;
30154 struct buffer
*obuf
;
30155 ptrdiff_t obegv
, ozv
;
30158 /* Find the glyph under X/Y. */
30159 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
30161 #ifdef HAVE_WINDOW_SYSTEM
30162 /* Look for :pointer property on image. */
30163 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
30165 struct image
*img
= IMAGE_OPT_FROM_ID (f
, glyph
->u
.img_id
);
30166 if (img
!= NULL
&& IMAGEP (img
->spec
))
30168 Lisp_Object image_map
, hotspot
;
30169 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
30171 && (hotspot
= find_hot_spot (image_map
,
30172 glyph
->slice
.img
.x
+ dx
,
30173 glyph
->slice
.img
.y
+ dy
),
30175 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
30179 /* Could check XCAR (hotspot) to see if we enter/leave
30181 If so, we could look for mouse-enter, mouse-leave
30182 properties in PLIST (and do something...). */
30183 hotspot
= XCDR (hotspot
);
30184 if (CONSP (hotspot
)
30185 && (plist
= XCAR (hotspot
), CONSP (plist
)))
30187 pointer
= Fplist_get (plist
, Qpointer
);
30188 if (NILP (pointer
))
30190 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
30191 if (!NILP (help_echo_string
))
30193 help_echo_window
= window
;
30194 help_echo_object
= glyph
->object
;
30195 help_echo_pos
= glyph
->charpos
;
30199 if (NILP (pointer
))
30200 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
30203 #endif /* HAVE_WINDOW_SYSTEM */
30205 /* Clear mouse face if X/Y not over text. */
30207 || area
!= TEXT_AREA
30208 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
30209 /* Glyph's OBJECT is nil for glyphs inserted by the
30210 display engine for its internal purposes, like truncation
30211 and continuation glyphs and blanks beyond the end of
30212 line's text on text terminals. If we are over such a
30213 glyph, we are not over any text. */
30214 || NILP (glyph
->object
)
30215 /* R2L rows have a stretch glyph at their front, which
30216 stands for no text, whereas L2R rows have no glyphs at
30217 all beyond the end of text. Treat such stretch glyphs
30218 like we do with NULL glyphs in L2R rows. */
30219 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
30220 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
30221 && glyph
->type
== STRETCH_GLYPH
30222 && glyph
->avoid_cursor_p
))
30224 if (clear_mouse_face (hlinfo
))
30225 cursor
= No_Cursor
;
30226 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
30228 #ifdef HAVE_WINDOW_SYSTEM
30229 if (area
!= TEXT_AREA
)
30230 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30232 pointer
= Vvoid_text_area_pointer
;
30238 pos
= glyph
->charpos
;
30239 object
= glyph
->object
;
30240 if (!STRINGP (object
) && !BUFFERP (object
))
30243 /* If we get an out-of-range value, return now; avoid an error. */
30244 if (BUFFERP (object
) && pos
> BUF_Z (b
))
30247 /* Make the window's buffer temporarily current for
30248 overlays_at and compute_char_face. */
30249 obuf
= current_buffer
;
30250 current_buffer
= b
;
30256 /* Is this char mouse-active or does it have help-echo? */
30257 position
= make_number (pos
);
30261 if (BUFFERP (object
))
30263 /* Put all the overlays we want in a vector in overlay_vec. */
30264 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, false);
30265 /* Sort overlays into increasing priority order. */
30266 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
30271 if (NILP (Vmouse_highlight
))
30273 clear_mouse_face (hlinfo
);
30274 goto check_help_echo
;
30277 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
30280 cursor
= No_Cursor
;
30282 /* Check mouse-face highlighting. */
30284 /* If there exists an overlay with mouse-face overlapping
30285 the one we are currently highlighting, we have to
30286 check if we enter the overlapping overlay, and then
30287 highlight only that. */
30288 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
30289 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
30291 /* Find the highest priority overlay with a mouse-face. */
30292 Lisp_Object overlay
= Qnil
;
30293 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
30295 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
30296 if (!NILP (mouse_face
))
30297 overlay
= overlay_vec
[i
];
30300 /* If we're highlighting the same overlay as before, there's
30301 no need to do that again. */
30302 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
30303 goto check_help_echo
;
30304 hlinfo
->mouse_face_overlay
= overlay
;
30306 /* Clear the display of the old active region, if any. */
30307 if (clear_mouse_face (hlinfo
))
30308 cursor
= No_Cursor
;
30310 /* If no overlay applies, get a text property. */
30311 if (NILP (overlay
))
30312 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
30314 /* Next, compute the bounds of the mouse highlighting and
30316 if (!NILP (mouse_face
) && STRINGP (object
))
30318 /* The mouse-highlighting comes from a display string
30319 with a mouse-face. */
30323 s
= Fprevious_single_property_change
30324 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
30325 e
= Fnext_single_property_change
30326 (position
, Qmouse_face
, object
, Qnil
);
30328 s
= make_number (0);
30330 e
= make_number (SCHARS (object
));
30331 mouse_face_from_string_pos (w
, hlinfo
, object
,
30332 XINT (s
), XINT (e
));
30333 hlinfo
->mouse_face_past_end
= false;
30334 hlinfo
->mouse_face_window
= window
;
30335 hlinfo
->mouse_face_face_id
30336 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
30337 glyph
->face_id
, true);
30338 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
30339 cursor
= No_Cursor
;
30343 /* The mouse-highlighting, if any, comes from an overlay
30344 or text property in the buffer. */
30345 Lisp_Object buffer UNINIT
;
30346 Lisp_Object disp_string UNINIT
;
30348 if (STRINGP (object
))
30350 /* If we are on a display string with no mouse-face,
30351 check if the text under it has one. */
30352 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
30353 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30354 pos
= string_buffer_position (object
, start
);
30357 mouse_face
= get_char_property_and_overlay
30358 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
30359 buffer
= w
->contents
;
30360 disp_string
= object
;
30366 disp_string
= Qnil
;
30369 if (!NILP (mouse_face
))
30371 Lisp_Object before
, after
;
30372 Lisp_Object before_string
, after_string
;
30373 /* To correctly find the limits of mouse highlight
30374 in a bidi-reordered buffer, we must not use the
30375 optimization of limiting the search in
30376 previous-single-property-change and
30377 next-single-property-change, because
30378 rows_from_pos_range needs the real start and end
30379 positions to DTRT in this case. That's because
30380 the first row visible in a window does not
30381 necessarily display the character whose position
30382 is the smallest. */
30384 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
30385 ? Fmarker_position (w
->start
)
30388 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
30389 ? make_number (BUF_Z (XBUFFER (buffer
))
30390 - w
->window_end_pos
)
30393 if (NILP (overlay
))
30395 /* Handle the text property case. */
30396 before
= Fprevious_single_property_change
30397 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
30398 after
= Fnext_single_property_change
30399 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
30400 before_string
= after_string
= Qnil
;
30404 /* Handle the overlay case. */
30405 before
= Foverlay_start (overlay
);
30406 after
= Foverlay_end (overlay
);
30407 before_string
= Foverlay_get (overlay
, Qbefore_string
);
30408 after_string
= Foverlay_get (overlay
, Qafter_string
);
30410 if (!STRINGP (before_string
)) before_string
= Qnil
;
30411 if (!STRINGP (after_string
)) after_string
= Qnil
;
30414 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
30417 : XFASTINT (before
),
30419 ? BUF_Z (XBUFFER (buffer
))
30420 : XFASTINT (after
),
30421 before_string
, after_string
,
30423 cursor
= No_Cursor
;
30430 /* Look for a `help-echo' property. */
30431 if (NILP (help_echo_string
)) {
30432 Lisp_Object help
, overlay
;
30434 /* Check overlays first. */
30435 help
= overlay
= Qnil
;
30436 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
30438 overlay
= overlay_vec
[i
];
30439 help
= Foverlay_get (overlay
, Qhelp_echo
);
30444 help_echo_string
= help
;
30445 help_echo_window
= window
;
30446 help_echo_object
= overlay
;
30447 help_echo_pos
= pos
;
30451 Lisp_Object obj
= glyph
->object
;
30452 ptrdiff_t charpos
= glyph
->charpos
;
30454 /* Try text properties. */
30457 && charpos
< SCHARS (obj
))
30459 help
= Fget_text_property (make_number (charpos
),
30463 /* If the string itself doesn't specify a help-echo,
30464 see if the buffer text ``under'' it does. */
30465 struct glyph_row
*r
30466 = MATRIX_ROW (w
->current_matrix
, vpos
);
30467 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30468 ptrdiff_t p
= string_buffer_position (obj
, start
);
30471 help
= Fget_char_property (make_number (p
),
30472 Qhelp_echo
, w
->contents
);
30481 else if (BUFFERP (obj
)
30484 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
30489 help_echo_string
= help
;
30490 help_echo_window
= window
;
30491 help_echo_object
= obj
;
30492 help_echo_pos
= charpos
;
30497 #ifdef HAVE_WINDOW_SYSTEM
30498 /* Look for a `pointer' property. */
30499 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
30501 /* Check overlays first. */
30502 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
30503 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
30505 if (NILP (pointer
))
30507 Lisp_Object obj
= glyph
->object
;
30508 ptrdiff_t charpos
= glyph
->charpos
;
30510 /* Try text properties. */
30513 && charpos
< SCHARS (obj
))
30515 pointer
= Fget_text_property (make_number (charpos
),
30517 if (NILP (pointer
))
30519 /* If the string itself doesn't specify a pointer,
30520 see if the buffer text ``under'' it does. */
30521 struct glyph_row
*r
30522 = MATRIX_ROW (w
->current_matrix
, vpos
);
30523 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30524 ptrdiff_t p
= string_buffer_position (obj
, start
);
30526 pointer
= Fget_char_property (make_number (p
),
30527 Qpointer
, w
->contents
);
30530 else if (BUFFERP (obj
)
30533 pointer
= Fget_text_property (make_number (charpos
),
30537 #endif /* HAVE_WINDOW_SYSTEM */
30541 current_buffer
= obuf
;
30546 define_frame_cursor1 (f
, cursor
, pointer
);
30551 Clear any mouse-face on window W. This function is part of the
30552 redisplay interface, and is called from try_window_id and similar
30553 functions to ensure the mouse-highlight is off. */
30556 x_clear_window_mouse_face (struct window
*w
)
30558 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
30559 Lisp_Object window
;
30562 XSETWINDOW (window
, w
);
30563 if (EQ (window
, hlinfo
->mouse_face_window
))
30564 clear_mouse_face (hlinfo
);
30570 Just discard the mouse face information for frame F, if any.
30571 This is used when the size of F is changed. */
30574 cancel_mouse_face (struct frame
*f
)
30576 Lisp_Object window
;
30577 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
30579 window
= hlinfo
->mouse_face_window
;
30580 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
30581 reset_mouse_highlight (hlinfo
);
30586 /***********************************************************************
30588 ***********************************************************************/
30590 #ifdef HAVE_WINDOW_SYSTEM
30592 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
30593 which intersects rectangle R. R is in window-relative coordinates. */
30596 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
30597 enum glyph_row_area area
)
30599 struct glyph
*first
= row
->glyphs
[area
];
30600 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
30601 struct glyph
*last
;
30602 int first_x
, start_x
, x
;
30604 if (area
== TEXT_AREA
&& row
->fill_line_p
)
30605 /* If row extends face to end of line write the whole line. */
30606 draw_glyphs (w
, 0, row
, area
,
30607 0, row
->used
[area
],
30608 DRAW_NORMAL_TEXT
, 0);
30611 /* Set START_X to the window-relative start position for drawing glyphs of
30612 AREA. The first glyph of the text area can be partially visible.
30613 The first glyphs of other areas cannot. */
30614 start_x
= window_box_left_offset (w
, area
);
30616 if (area
== TEXT_AREA
)
30619 /* Find the first glyph that must be redrawn. */
30621 && x
+ first
->pixel_width
< r
->x
)
30623 x
+= first
->pixel_width
;
30627 /* Find the last one. */
30630 /* Use a signed int intermediate value to avoid catastrophic
30631 failures due to comparison between signed and unsigned, when
30632 x is negative (can happen for wide images that are hscrolled). */
30633 int r_end
= r
->x
+ r
->width
;
30634 while (last
< end
&& x
< r_end
)
30636 x
+= last
->pixel_width
;
30642 draw_glyphs (w
, first_x
- start_x
, row
, area
,
30643 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
30644 DRAW_NORMAL_TEXT
, 0);
30649 /* Redraw the parts of the glyph row ROW on window W intersecting
30650 rectangle R. R is in window-relative coordinates. Value is
30651 true if mouse-face was overwritten. */
30654 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
30656 eassert (row
->enabled_p
);
30658 if (row
->mode_line_p
|| w
->pseudo_window_p
)
30659 draw_glyphs (w
, 0, row
, TEXT_AREA
,
30660 0, row
->used
[TEXT_AREA
],
30661 DRAW_NORMAL_TEXT
, 0);
30664 if (row
->used
[LEFT_MARGIN_AREA
])
30665 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
30666 if (row
->used
[TEXT_AREA
])
30667 expose_area (w
, row
, r
, TEXT_AREA
);
30668 if (row
->used
[RIGHT_MARGIN_AREA
])
30669 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
30670 draw_row_fringe_bitmaps (w
, row
);
30673 return row
->mouse_face_p
;
30677 /* Redraw those parts of glyphs rows during expose event handling that
30678 overlap other rows. Redrawing of an exposed line writes over parts
30679 of lines overlapping that exposed line; this function fixes that.
30681 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
30682 row in W's current matrix that is exposed and overlaps other rows.
30683 LAST_OVERLAPPING_ROW is the last such row. */
30686 expose_overlaps (struct window
*w
,
30687 struct glyph_row
*first_overlapping_row
,
30688 struct glyph_row
*last_overlapping_row
,
30691 struct glyph_row
*row
;
30693 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
30694 if (row
->overlapping_p
)
30696 eassert (row
->enabled_p
&& !row
->mode_line_p
);
30699 if (row
->used
[LEFT_MARGIN_AREA
])
30700 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
30702 if (row
->used
[TEXT_AREA
])
30703 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
30705 if (row
->used
[RIGHT_MARGIN_AREA
])
30706 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
30712 /* Return true if W's cursor intersects rectangle R. */
30715 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
30717 XRectangle cr
, result
;
30718 struct glyph
*cursor_glyph
;
30719 struct glyph_row
*row
;
30721 if (w
->phys_cursor
.vpos
>= 0
30722 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
30723 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
30725 && row
->cursor_in_fringe_p
)
30727 /* Cursor is in the fringe. */
30728 cr
.x
= window_box_right_offset (w
,
30729 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
30730 ? RIGHT_MARGIN_AREA
30733 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
30734 cr
.height
= row
->height
;
30735 return x_intersect_rectangles (&cr
, r
, &result
);
30738 cursor_glyph
= get_phys_cursor_glyph (w
);
30741 /* r is relative to W's box, but w->phys_cursor.x is relative
30742 to left edge of W's TEXT area. Adjust it. */
30743 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
30744 cr
.y
= w
->phys_cursor
.y
;
30745 cr
.width
= cursor_glyph
->pixel_width
;
30746 cr
.height
= w
->phys_cursor_height
;
30747 /* ++KFS: W32 version used W32-specific IntersectRect here, but
30748 I assume the effect is the same -- and this is portable. */
30749 return x_intersect_rectangles (&cr
, r
, &result
);
30751 /* If we don't understand the format, pretend we're not in the hot-spot. */
30757 Draw a vertical window border to the right of window W if W doesn't
30758 have vertical scroll bars. */
30761 x_draw_vertical_border (struct window
*w
)
30763 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30765 /* We could do better, if we knew what type of scroll-bar the adjacent
30766 windows (on either side) have... But we don't :-(
30767 However, I think this works ok. ++KFS 2003-04-25 */
30769 /* Redraw borders between horizontally adjacent windows. Don't
30770 do it for frames with vertical scroll bars because either the
30771 right scroll bar of a window, or the left scroll bar of its
30772 neighbor will suffice as a border. */
30773 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
30776 /* Note: It is necessary to redraw both the left and the right
30777 borders, for when only this single window W is being
30779 if (!WINDOW_RIGHTMOST_P (w
)
30780 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
30782 int x0
, x1
, y0
, y1
;
30784 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30787 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30790 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
30793 if (!WINDOW_LEFTMOST_P (w
)
30794 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
30796 int x0
, x1
, y0
, y1
;
30798 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30801 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30804 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
30809 /* Draw window dividers for window W. */
30812 x_draw_right_divider (struct window
*w
)
30814 struct frame
*f
= WINDOW_XFRAME (w
);
30816 if (w
->mini
|| w
->pseudo_window_p
)
30818 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30820 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
30821 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30822 int y0
= WINDOW_TOP_EDGE_Y (w
);
30823 /* The bottom divider prevails. */
30824 int y1
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30826 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30831 x_draw_bottom_divider (struct window
*w
)
30833 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30835 if (w
->mini
|| w
->pseudo_window_p
)
30837 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30839 int x0
= WINDOW_LEFT_EDGE_X (w
);
30840 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30841 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30842 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
30844 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30848 /* Redraw the part of window W intersection rectangle FR. Pixel
30849 coordinates in FR are frame-relative. Call this function with
30850 input blocked. Value is true if the exposure overwrites
30854 expose_window (struct window
*w
, XRectangle
*fr
)
30856 struct frame
*f
= XFRAME (w
->frame
);
30858 bool mouse_face_overwritten_p
= false;
30860 /* If window is not yet fully initialized, do nothing. This can
30861 happen when toolkit scroll bars are used and a window is split.
30862 Reconfiguring the scroll bar will generate an expose for a newly
30864 if (w
->current_matrix
== NULL
)
30867 /* When we're currently updating the window, display and current
30868 matrix usually don't agree. Arrange for a thorough display
30870 if (w
->must_be_updated_p
)
30872 SET_FRAME_GARBAGED (f
);
30876 /* Frame-relative pixel rectangle of W. */
30877 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
30878 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
30879 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
30880 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
30882 if (x_intersect_rectangles (fr
, &wr
, &r
))
30884 int yb
= window_text_bottom_y (w
);
30885 struct glyph_row
*row
;
30886 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
30888 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
30889 r
.x
, r
.y
, r
.width
, r
.height
));
30891 /* Convert to window coordinates. */
30892 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
30893 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
30895 /* Turn off the cursor. */
30896 bool cursor_cleared_p
= (!w
->pseudo_window_p
30897 && phys_cursor_in_rect_p (w
, &r
));
30898 if (cursor_cleared_p
)
30899 x_clear_cursor (w
);
30901 /* If the row containing the cursor extends face to end of line,
30902 then expose_area might overwrite the cursor outside the
30903 rectangle and thus notice_overwritten_cursor might clear
30904 w->phys_cursor_on_p. We remember the original value and
30905 check later if it is changed. */
30906 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
30908 /* Use a signed int intermediate value to avoid catastrophic
30909 failures due to comparison between signed and unsigned, when
30910 y0 or y1 is negative (can happen for tall images). */
30911 int r_bottom
= r
.y
+ r
.height
;
30913 /* Update lines intersecting rectangle R. */
30914 first_overlapping_row
= last_overlapping_row
= NULL
;
30915 for (row
= w
->current_matrix
->rows
;
30920 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
30922 if ((y0
>= r
.y
&& y0
< r_bottom
)
30923 || (y1
> r
.y
&& y1
< r_bottom
)
30924 || (r
.y
>= y0
&& r
.y
< y1
)
30925 || (r_bottom
> y0
&& r_bottom
< y1
))
30927 /* A header line may be overlapping, but there is no need
30928 to fix overlapping areas for them. KFS 2005-02-12 */
30929 if (row
->overlapping_p
&& !row
->mode_line_p
)
30931 if (first_overlapping_row
== NULL
)
30932 first_overlapping_row
= row
;
30933 last_overlapping_row
= row
;
30937 if (expose_line (w
, row
, &r
))
30938 mouse_face_overwritten_p
= true;
30941 else if (row
->overlapping_p
)
30943 /* We must redraw a row overlapping the exposed area. */
30945 ? y0
+ row
->phys_height
> r
.y
30946 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
30948 if (first_overlapping_row
== NULL
)
30949 first_overlapping_row
= row
;
30950 last_overlapping_row
= row
;
30958 /* Display the mode line if there is one. */
30959 if (WINDOW_WANTS_MODELINE_P (w
)
30960 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
30962 && row
->y
< r_bottom
)
30964 if (expose_line (w
, row
, &r
))
30965 mouse_face_overwritten_p
= true;
30968 if (!w
->pseudo_window_p
)
30970 /* Fix the display of overlapping rows. */
30971 if (first_overlapping_row
)
30972 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
30975 /* Draw border between windows. */
30976 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30977 x_draw_right_divider (w
);
30979 x_draw_vertical_border (w
);
30981 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30982 x_draw_bottom_divider (w
);
30984 /* Turn the cursor on again. */
30985 if (cursor_cleared_p
30986 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
30987 update_window_cursor (w
, true);
30991 return mouse_face_overwritten_p
;
30996 /* Redraw (parts) of all windows in the window tree rooted at W that
30997 intersect R. R contains frame pixel coordinates. Value is
30998 true if the exposure overwrites mouse-face. */
31001 expose_window_tree (struct window
*w
, XRectangle
*r
)
31003 struct frame
*f
= XFRAME (w
->frame
);
31004 bool mouse_face_overwritten_p
= false;
31006 while (w
&& !FRAME_GARBAGED_P (f
))
31008 mouse_face_overwritten_p
31009 |= (WINDOWP (w
->contents
)
31010 ? expose_window_tree (XWINDOW (w
->contents
), r
)
31011 : expose_window (w
, r
));
31013 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
31016 return mouse_face_overwritten_p
;
31021 Redisplay an exposed area of frame F. X and Y are the upper-left
31022 corner of the exposed rectangle. W and H are width and height of
31023 the exposed area. All are pixel values. W or H zero means redraw
31024 the entire frame. */
31027 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
31030 bool mouse_face_overwritten_p
= false;
31032 TRACE ((stderr
, "expose_frame "));
31034 /* No need to redraw if frame will be redrawn soon. */
31035 if (FRAME_GARBAGED_P (f
))
31037 TRACE ((stderr
, " garbaged\n"));
31041 /* If basic faces haven't been realized yet, there is no point in
31042 trying to redraw anything. This can happen when we get an expose
31043 event while Emacs is starting, e.g. by moving another window. */
31044 if (FRAME_FACE_CACHE (f
) == NULL
31045 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
31047 TRACE ((stderr
, " no faces\n"));
31051 if (w
== 0 || h
== 0)
31054 r
.width
= FRAME_TEXT_WIDTH (f
);
31055 r
.height
= FRAME_TEXT_HEIGHT (f
);
31065 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
31066 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
31068 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
31069 if (WINDOWP (f
->tool_bar_window
))
31070 mouse_face_overwritten_p
31071 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
31074 #ifdef HAVE_X_WINDOWS
31076 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
31077 if (WINDOWP (f
->menu_bar_window
))
31078 mouse_face_overwritten_p
31079 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
31080 #endif /* not USE_X_TOOLKIT and not USE_GTK */
31084 /* Some window managers support a focus-follows-mouse style with
31085 delayed raising of frames. Imagine a partially obscured frame,
31086 and moving the mouse into partially obscured mouse-face on that
31087 frame. The visible part of the mouse-face will be highlighted,
31088 then the WM raises the obscured frame. With at least one WM, KDE
31089 2.1, Emacs is not getting any event for the raising of the frame
31090 (even tried with SubstructureRedirectMask), only Expose events.
31091 These expose events will draw text normally, i.e. not
31092 highlighted. Which means we must redo the highlight here.
31093 Subsume it under ``we love X''. --gerd 2001-08-15 */
31094 /* Included in Windows version because Windows most likely does not
31095 do the right thing if any third party tool offers
31096 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
31097 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
31099 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
31100 if (f
== hlinfo
->mouse_face_mouse_frame
)
31102 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
31103 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
31104 clear_mouse_face (hlinfo
);
31105 note_mouse_highlight (f
, mouse_x
, mouse_y
);
31112 Determine the intersection of two rectangles R1 and R2. Return
31113 the intersection in *RESULT. Value is true if RESULT is not
31117 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
31119 XRectangle
*left
, *right
;
31120 XRectangle
*upper
, *lower
;
31121 bool intersection_p
= false;
31123 /* Rearrange so that R1 is the left-most rectangle. */
31125 left
= r1
, right
= r2
;
31127 left
= r2
, right
= r1
;
31129 /* X0 of the intersection is right.x0, if this is inside R1,
31130 otherwise there is no intersection. */
31131 if (right
->x
<= left
->x
+ left
->width
)
31133 result
->x
= right
->x
;
31135 /* The right end of the intersection is the minimum of
31136 the right ends of left and right. */
31137 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
31140 /* Same game for Y. */
31142 upper
= r1
, lower
= r2
;
31144 upper
= r2
, lower
= r1
;
31146 /* The upper end of the intersection is lower.y0, if this is inside
31147 of upper. Otherwise, there is no intersection. */
31148 if (lower
->y
<= upper
->y
+ upper
->height
)
31150 result
->y
= lower
->y
;
31152 /* The lower end of the intersection is the minimum of the lower
31153 ends of upper and lower. */
31154 result
->height
= (min (lower
->y
+ lower
->height
,
31155 upper
->y
+ upper
->height
)
31157 intersection_p
= true;
31161 return intersection_p
;
31164 #endif /* HAVE_WINDOW_SYSTEM */
31167 /***********************************************************************
31169 ***********************************************************************/
31172 syms_of_xdisp (void)
31174 Vwith_echo_area_save_vector
= Qnil
;
31175 staticpro (&Vwith_echo_area_save_vector
);
31177 Vmessage_stack
= Qnil
;
31178 staticpro (&Vmessage_stack
);
31180 /* Non-nil means don't actually do any redisplay. */
31181 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
31183 DEFSYM (Qredisplay_internal_xC_functionx
, "redisplay_internal (C function)");
31185 DEFVAR_BOOL("inhibit-message", inhibit_message
,
31186 doc
: /* Non-nil means calls to `message' are not displayed.
31187 They are still logged to the *Messages* buffer. */);
31188 inhibit_message
= 0;
31190 message_dolog_marker1
= Fmake_marker ();
31191 staticpro (&message_dolog_marker1
);
31192 message_dolog_marker2
= Fmake_marker ();
31193 staticpro (&message_dolog_marker2
);
31194 message_dolog_marker3
= Fmake_marker ();
31195 staticpro (&message_dolog_marker3
);
31198 defsubr (&Sdump_frame_glyph_matrix
);
31199 defsubr (&Sdump_glyph_matrix
);
31200 defsubr (&Sdump_glyph_row
);
31201 defsubr (&Sdump_tool_bar_row
);
31202 defsubr (&Strace_redisplay
);
31203 defsubr (&Strace_to_stderr
);
31205 #ifdef HAVE_WINDOW_SYSTEM
31206 defsubr (&Stool_bar_height
);
31207 defsubr (&Slookup_image_map
);
31209 defsubr (&Sline_pixel_height
);
31210 defsubr (&Sformat_mode_line
);
31211 defsubr (&Sinvisible_p
);
31212 defsubr (&Scurrent_bidi_paragraph_direction
);
31213 defsubr (&Swindow_text_pixel_size
);
31214 defsubr (&Smove_point_visually
);
31215 defsubr (&Sbidi_find_overridden_directionality
);
31217 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
31218 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
31219 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
31220 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
31221 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
31222 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
31223 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
31224 DEFSYM (Qeval
, "eval");
31225 DEFSYM (QCdata
, ":data");
31227 /* Names of text properties relevant for redisplay. */
31228 DEFSYM (Qdisplay
, "display");
31229 DEFSYM (Qspace_width
, "space-width");
31230 DEFSYM (Qraise
, "raise");
31231 DEFSYM (Qslice
, "slice");
31232 DEFSYM (Qspace
, "space");
31233 DEFSYM (Qmargin
, "margin");
31234 DEFSYM (Qpointer
, "pointer");
31235 DEFSYM (Qleft_margin
, "left-margin");
31236 DEFSYM (Qright_margin
, "right-margin");
31237 DEFSYM (Qcenter
, "center");
31238 DEFSYM (Qline_height
, "line-height");
31239 DEFSYM (QCalign_to
, ":align-to");
31240 DEFSYM (QCrelative_width
, ":relative-width");
31241 DEFSYM (QCrelative_height
, ":relative-height");
31242 DEFSYM (QCeval
, ":eval");
31243 DEFSYM (QCpropertize
, ":propertize");
31244 DEFSYM (QCfile
, ":file");
31245 DEFSYM (Qfontified
, "fontified");
31246 DEFSYM (Qfontification_functions
, "fontification-functions");
31248 /* Name of the face used to highlight trailing whitespace. */
31249 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
31251 /* Name and number of the face used to highlight escape glyphs. */
31252 DEFSYM (Qescape_glyph
, "escape-glyph");
31254 /* Name and number of the face used to highlight non-breaking
31256 DEFSYM (Qnobreak_space
, "nobreak-space");
31257 DEFSYM (Qnobreak_hyphen
, "nobreak-hyphen");
31259 /* The symbol 'image' which is the car of the lists used to represent
31260 images in Lisp. Also a tool bar style. */
31261 DEFSYM (Qimage
, "image");
31263 /* Tool bar styles. */
31264 DEFSYM (Qtext
, "text");
31265 DEFSYM (Qboth
, "both");
31266 DEFSYM (Qboth_horiz
, "both-horiz");
31267 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
31269 /* The image map types. */
31270 DEFSYM (QCmap
, ":map");
31271 DEFSYM (QCpointer
, ":pointer");
31272 DEFSYM (Qrect
, "rect");
31273 DEFSYM (Qcircle
, "circle");
31274 DEFSYM (Qpoly
, "poly");
31276 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
31278 DEFSYM (Qgrow_only
, "grow-only");
31279 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
31280 DEFSYM (Qposition
, "position");
31281 DEFSYM (Qbuffer_position
, "buffer-position");
31282 DEFSYM (Qobject
, "object");
31284 /* Cursor shapes. */
31285 DEFSYM (Qbar
, "bar");
31286 DEFSYM (Qhbar
, "hbar");
31287 DEFSYM (Qbox
, "box");
31288 DEFSYM (Qhollow
, "hollow");
31290 /* Pointer shapes. */
31291 DEFSYM (Qhand
, "hand");
31292 DEFSYM (Qarrow
, "arrow");
31295 DEFSYM (Qdragging
, "dragging");
31297 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
31299 list_of_error
= list1 (list2 (Qerror
, Qvoid_variable
));
31300 staticpro (&list_of_error
);
31302 /* Values of those variables at last redisplay are stored as
31303 properties on 'overlay-arrow-position' symbol. However, if
31304 Voverlay_arrow_position is a marker, last-arrow-position is its
31305 numerical position. */
31306 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
31307 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
31309 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
31310 properties on a symbol in overlay-arrow-variable-list. */
31311 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
31312 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
31314 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
31315 staticpro (&echo_buffer
[0]);
31316 staticpro (&echo_buffer
[1]);
31318 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
31319 staticpro (&echo_area_buffer
[0]);
31320 staticpro (&echo_area_buffer
[1]);
31322 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
31323 staticpro (&Vmessages_buffer_name
);
31325 mode_line_proptrans_alist
= Qnil
;
31326 staticpro (&mode_line_proptrans_alist
);
31327 mode_line_string_list
= Qnil
;
31328 staticpro (&mode_line_string_list
);
31329 mode_line_string_face
= Qnil
;
31330 staticpro (&mode_line_string_face
);
31331 mode_line_string_face_prop
= Qnil
;
31332 staticpro (&mode_line_string_face_prop
);
31333 Vmode_line_unwind_vector
= Qnil
;
31334 staticpro (&Vmode_line_unwind_vector
);
31336 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
31338 help_echo_string
= Qnil
;
31339 staticpro (&help_echo_string
);
31340 help_echo_object
= Qnil
;
31341 staticpro (&help_echo_object
);
31342 help_echo_window
= Qnil
;
31343 staticpro (&help_echo_window
);
31344 previous_help_echo_string
= Qnil
;
31345 staticpro (&previous_help_echo_string
);
31346 help_echo_pos
= -1;
31348 DEFSYM (Qright_to_left
, "right-to-left");
31349 DEFSYM (Qleft_to_right
, "left-to-right");
31350 defsubr (&Sbidi_resolved_levels
);
31352 #ifdef HAVE_WINDOW_SYSTEM
31353 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
31354 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
31355 For example, if a block cursor is over a tab, it will be drawn as
31356 wide as that tab on the display. */);
31357 x_stretch_cursor_p
= 0;
31360 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
31361 doc
: /* Non-nil means highlight trailing whitespace.
31362 The face used for trailing whitespace is `trailing-whitespace'. */);
31363 Vshow_trailing_whitespace
= Qnil
;
31365 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
31366 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
31367 If the value is t, Emacs highlights non-ASCII chars which have the
31368 same appearance as an ASCII space or hyphen, using the `nobreak-space'
31369 or `nobreak-hyphen' face respectively.
31371 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
31372 U+2011 (non-breaking hyphen) are affected.
31374 Any other non-nil value means to display these characters as a escape
31375 glyph followed by an ordinary space or hyphen.
31377 A value of nil means no special handling of these characters. */);
31378 Vnobreak_char_display
= Qt
;
31380 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
31381 doc
: /* The pointer shape to show in void text areas.
31382 A value of nil means to show the text pointer. Other options are
31383 `arrow', `text', `hand', `vdrag', `hdrag', `nhdrag', `modeline', and
31385 Vvoid_text_area_pointer
= Qarrow
;
31387 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
31388 doc
: /* Non-nil means don't actually do any redisplay.
31389 This is used for internal purposes. */);
31390 Vinhibit_redisplay
= Qnil
;
31392 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
31393 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
31394 Vglobal_mode_string
= Qnil
;
31396 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
31397 doc
: /* Marker for where to display an arrow on top of the buffer text.
31398 This must be the beginning of a line in order to work.
31399 See also `overlay-arrow-string'. */);
31400 Voverlay_arrow_position
= Qnil
;
31402 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
31403 doc
: /* String to display as an arrow in non-window frames.
31404 See also `overlay-arrow-position'. */);
31405 Voverlay_arrow_string
= build_pure_c_string ("=>");
31407 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
31408 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
31409 The symbols on this list are examined during redisplay to determine
31410 where to display overlay arrows. */);
31411 Voverlay_arrow_variable_list
31412 = list1 (intern_c_string ("overlay-arrow-position"));
31414 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
31415 doc
: /* The number of lines to try scrolling a window by when point moves out.
31416 If that fails to bring point back on frame, point is centered instead.
31417 If this is zero, point is always centered after it moves off frame.
31418 If you want scrolling to always be a line at a time, you should set
31419 `scroll-conservatively' to a large value rather than set this to 1. */);
31421 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
31422 doc
: /* Scroll up to this many lines, to bring point back on screen.
31423 If point moves off-screen, redisplay will scroll by up to
31424 `scroll-conservatively' lines in order to bring point just barely
31425 onto the screen again. If that cannot be done, then redisplay
31426 recenters point as usual.
31428 If the value is greater than 100, redisplay will never recenter point,
31429 but will always scroll just enough text to bring point into view, even
31430 if you move far away.
31432 A value of zero means always recenter point if it moves off screen. */);
31433 scroll_conservatively
= 0;
31435 DEFVAR_INT ("scroll-margin", scroll_margin
,
31436 doc
: /* Number of lines of margin at the top and bottom of a window.
31437 Recenter the window whenever point gets within this many lines
31438 of the top or bottom of the window. */);
31441 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
31442 doc
: /* Pixels per inch value for non-window system displays.
31443 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
31444 Vdisplay_pixels_per_inch
= make_float (72.0);
31447 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
31450 DEFVAR_LISP ("truncate-partial-width-windows",
31451 Vtruncate_partial_width_windows
,
31452 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
31453 For an integer value, truncate lines in each window narrower than the
31454 full frame width, provided the total window width in column units is less
31455 than that integer; otherwise, respect the value of `truncate-lines'.
31456 The total width of the window is as returned by `window-total-width', it
31457 includes the fringes, the continuation and truncation glyphs, the
31458 display margins (if any), and the scroll bar
31460 For any other non-nil value, truncate lines in all windows that do
31461 not span the full frame width.
31463 A value of nil means to respect the value of `truncate-lines'.
31465 If `word-wrap' is enabled, you might want to reduce this. */);
31466 Vtruncate_partial_width_windows
= make_number (50);
31468 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
31469 doc
: /* Maximum buffer size for which line number should be displayed.
31470 If the buffer is bigger than this, the line number does not appear
31471 in the mode line. A value of nil means no limit. */);
31472 Vline_number_display_limit
= Qnil
;
31474 DEFVAR_INT ("line-number-display-limit-width",
31475 line_number_display_limit_width
,
31476 doc
: /* Maximum line width (in characters) for line number display.
31477 If the average length of the lines near point is bigger than this, then the
31478 line number may be omitted from the mode line. */);
31479 line_number_display_limit_width
= 200;
31481 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
31482 doc
: /* Non-nil means highlight region even in nonselected windows. */);
31483 highlight_nonselected_windows
= false;
31485 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
31486 doc
: /* Non-nil if more than one frame is visible on this display.
31487 Minibuffer-only frames don't count, but iconified frames do.
31488 This variable is not guaranteed to be accurate except while processing
31489 `frame-title-format' and `icon-title-format'. */);
31491 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
31492 doc
: /* Template for displaying the title bar of visible frames.
31493 \(Assuming the window manager supports this feature.)
31495 This variable has the same structure as `mode-line-format', except that
31496 the %c and %l constructs are ignored. It is used only on frames for
31497 which no explicit name has been set (see `modify-frame-parameters'). */);
31499 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
31500 doc
: /* Template for displaying the title bar of an iconified frame.
31501 \(Assuming the window manager supports this feature.)
31502 This variable has the same structure as `mode-line-format' (which see),
31503 and is used only on frames for which no explicit name has been set
31504 \(see `modify-frame-parameters'). */);
31506 = Vframe_title_format
31507 = listn (CONSTYPE_PURE
, 3,
31508 intern_c_string ("multiple-frames"),
31509 build_pure_c_string ("%b"),
31510 listn (CONSTYPE_PURE
, 4,
31511 empty_unibyte_string
,
31512 intern_c_string ("invocation-name"),
31513 build_pure_c_string ("@"),
31514 intern_c_string ("system-name")));
31516 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
31517 doc
: /* Maximum number of lines to keep in the message log buffer.
31518 If nil, disable message logging. If t, log messages but don't truncate
31519 the buffer when it becomes large. */);
31520 Vmessage_log_max
= make_number (1000);
31522 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
31523 doc
: /* List of functions to call before redisplaying a window with scrolling.
31524 Each function is called with two arguments, the window and its new
31525 display-start position.
31526 These functions are called whenever the `window-start' marker is modified,
31527 either to point into another buffer (e.g. via `set-window-buffer') or another
31528 place in the same buffer.
31529 Note that the value of `window-end' is not valid when these functions are
31532 Warning: Do not use this feature to alter the way the window
31533 is scrolled. It is not designed for that, and such use probably won't
31535 Vwindow_scroll_functions
= Qnil
;
31537 DEFVAR_LISP ("window-text-change-functions",
31538 Vwindow_text_change_functions
,
31539 doc
: /* Functions to call in redisplay when text in the window might change. */);
31540 Vwindow_text_change_functions
= Qnil
;
31542 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
31543 doc
: /* Functions called when redisplay of a window reaches the end trigger.
31544 Each function is called with two arguments, the window and the end trigger value.
31545 See `set-window-redisplay-end-trigger'. */);
31546 Vredisplay_end_trigger_functions
= Qnil
;
31548 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
31549 doc
: /* Non-nil means autoselect window with mouse pointer.
31550 If nil, do not autoselect windows.
31551 A positive number means delay autoselection by that many seconds: a
31552 window is autoselected only after the mouse has remained in that
31553 window for the duration of the delay.
31554 A negative number has a similar effect, but causes windows to be
31555 autoselected only after the mouse has stopped moving. (Because of
31556 the way Emacs compares mouse events, you will occasionally wait twice
31557 that time before the window gets selected.)
31558 Any other value means to autoselect window instantaneously when the
31559 mouse pointer enters it.
31561 Autoselection selects the minibuffer only if it is active, and never
31562 unselects the minibuffer if it is active.
31564 When customizing this variable make sure that the actual value of
31565 `focus-follows-mouse' matches the behavior of your window manager. */);
31566 Vmouse_autoselect_window
= Qnil
;
31568 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
31569 doc
: /* Non-nil means automatically resize tool-bars.
31570 This dynamically changes the tool-bar's height to the minimum height
31571 that is needed to make all tool-bar items visible.
31572 If value is `grow-only', the tool-bar's height is only increased
31573 automatically; to decrease the tool-bar height, use \\[recenter]. */);
31574 Vauto_resize_tool_bars
= Qt
;
31576 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
31577 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
31578 auto_raise_tool_bar_buttons_p
= true;
31580 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
31581 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
31582 make_cursor_line_fully_visible_p
= true;
31584 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
31585 doc
: /* Border below tool-bar in pixels.
31586 If an integer, use it as the height of the border.
31587 If it is one of `internal-border-width' or `border-width', use the
31588 value of the corresponding frame parameter.
31589 Otherwise, no border is added below the tool-bar. */);
31590 Vtool_bar_border
= Qinternal_border_width
;
31592 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
31593 doc
: /* Margin around tool-bar buttons in pixels.
31594 If an integer, use that for both horizontal and vertical margins.
31595 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
31596 HORZ specifying the horizontal margin, and VERT specifying the
31597 vertical margin. */);
31598 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
31600 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
31601 doc
: /* Relief thickness of tool-bar buttons. */);
31602 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
31604 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
31605 doc
: /* Tool bar style to use.
31607 image - show images only
31608 text - show text only
31609 both - show both, text below image
31610 both-horiz - show text to the right of the image
31611 text-image-horiz - show text to the left of the image
31612 any other - use system default or image if no system default.
31614 This variable only affects the GTK+ toolkit version of Emacs. */);
31615 Vtool_bar_style
= Qnil
;
31617 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
31618 doc
: /* Maximum number of characters a label can have to be shown.
31619 The tool bar style must also show labels for this to have any effect, see
31620 `tool-bar-style'. */);
31621 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
31623 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
31624 doc
: /* List of functions to call to fontify regions of text.
31625 Each function is called with one argument POS. Functions must
31626 fontify a region starting at POS in the current buffer, and give
31627 fontified regions the property `fontified'. */);
31628 Vfontification_functions
= Qnil
;
31629 Fmake_variable_buffer_local (Qfontification_functions
);
31631 DEFVAR_BOOL ("unibyte-display-via-language-environment",
31632 unibyte_display_via_language_environment
,
31633 doc
: /* Non-nil means display unibyte text according to language environment.
31634 Specifically, this means that raw bytes in the range 160-255 decimal
31635 are displayed by converting them to the equivalent multibyte characters
31636 according to the current language environment. As a result, they are
31637 displayed according to the current fontset.
31639 Note that this variable affects only how these bytes are displayed,
31640 but does not change the fact they are interpreted as raw bytes. */);
31641 unibyte_display_via_language_environment
= false;
31643 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
31644 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
31645 If a float, it specifies a fraction of the mini-window frame's height.
31646 If an integer, it specifies a number of lines. */);
31647 Vmax_mini_window_height
= make_float (0.25);
31649 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
31650 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
31651 A value of nil means don't automatically resize mini-windows.
31652 A value of t means resize them to fit the text displayed in them.
31653 A value of `grow-only', the default, means let mini-windows grow only;
31654 they return to their normal size when the minibuffer is closed, or the
31655 echo area becomes empty. */);
31656 /* Contrary to the doc string, we initialize this to nil, so that
31657 loading loadup.el won't try to resize windows before loading
31658 window.el, where some functions we need to call for this live.
31659 We assign the 'grow-only' value right after loading window.el
31661 Vresize_mini_windows
= Qnil
;
31663 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
31664 doc
: /* Alist specifying how to blink the cursor off.
31665 Each element has the form (ON-STATE . OFF-STATE). Whenever the
31666 `cursor-type' frame-parameter or variable equals ON-STATE,
31667 comparing using `equal', Emacs uses OFF-STATE to specify
31668 how to blink it off. ON-STATE and OFF-STATE are values for
31669 the `cursor-type' frame parameter.
31671 If a frame's ON-STATE has no entry in this list,
31672 the frame's other specifications determine how to blink the cursor off. */);
31673 Vblink_cursor_alist
= Qnil
;
31675 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
31676 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
31677 If non-nil, windows are automatically scrolled horizontally to make
31678 point visible. */);
31679 automatic_hscrolling_p
= true;
31680 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
31682 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
31683 doc
: /* How many columns away from the window edge point is allowed to get
31684 before automatic hscrolling will horizontally scroll the window. */);
31685 hscroll_margin
= 5;
31687 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
31688 doc
: /* How many columns to scroll the window when point gets too close to the edge.
31689 When point is less than `hscroll-margin' columns from the window
31690 edge, automatic hscrolling will scroll the window by the amount of columns
31691 determined by this variable. If its value is a positive integer, scroll that
31692 many columns. If it's a positive floating-point number, it specifies the
31693 fraction of the window's width to scroll. If it's nil or zero, point will be
31694 centered horizontally after the scroll. Any other value, including negative
31695 numbers, are treated as if the value were zero.
31697 Automatic hscrolling always moves point outside the scroll margin, so if
31698 point was more than scroll step columns inside the margin, the window will
31699 scroll more than the value given by the scroll step.
31701 Note that the lower bound for automatic hscrolling specified by `scroll-left'
31702 and `scroll-right' overrides this variable's effect. */);
31703 Vhscroll_step
= make_number (0);
31705 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
31706 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
31707 Bind this around calls to `message' to let it take effect. */);
31708 message_truncate_lines
= false;
31710 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
31711 doc
: /* Normal hook run to update the menu bar definitions.
31712 Redisplay runs this hook before it redisplays the menu bar.
31713 This is used to update menus such as Buffers, whose contents depend on
31715 Vmenu_bar_update_hook
= Qnil
;
31717 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
31718 doc
: /* Frame for which we are updating a menu.
31719 The enable predicate for a menu binding should check this variable. */);
31720 Vmenu_updating_frame
= Qnil
;
31722 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
31723 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
31724 inhibit_menubar_update
= false;
31726 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
31727 doc
: /* Prefix prepended to all continuation lines at display time.
31728 The value may be a string, an image, or a stretch-glyph; it is
31729 interpreted in the same way as the value of a `display' text property.
31731 This variable is overridden by any `wrap-prefix' text or overlay
31734 To add a prefix to non-continuation lines, use `line-prefix'. */);
31735 Vwrap_prefix
= Qnil
;
31736 DEFSYM (Qwrap_prefix
, "wrap-prefix");
31737 Fmake_variable_buffer_local (Qwrap_prefix
);
31739 DEFVAR_LISP ("line-prefix", Vline_prefix
,
31740 doc
: /* Prefix prepended to all non-continuation lines at display time.
31741 The value may be a string, an image, or a stretch-glyph; it is
31742 interpreted in the same way as the value of a `display' text property.
31744 This variable is overridden by any `line-prefix' text or overlay
31747 To add a prefix to continuation lines, use `wrap-prefix'. */);
31748 Vline_prefix
= Qnil
;
31749 DEFSYM (Qline_prefix
, "line-prefix");
31750 Fmake_variable_buffer_local (Qline_prefix
);
31752 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
31753 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
31754 inhibit_eval_during_redisplay
= false;
31756 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
31757 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
31758 inhibit_free_realized_faces
= false;
31760 DEFVAR_BOOL ("inhibit-bidi-mirroring", inhibit_bidi_mirroring
,
31761 doc
: /* Non-nil means don't mirror characters even when bidi context requires that.
31762 Intended for use during debugging and for testing bidi display;
31763 see biditest.el in the test suite. */);
31764 inhibit_bidi_mirroring
= false;
31767 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
31768 doc
: /* Inhibit try_window_id display optimization. */);
31769 inhibit_try_window_id
= false;
31771 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
31772 doc
: /* Inhibit try_window_reusing display optimization. */);
31773 inhibit_try_window_reusing
= false;
31775 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
31776 doc
: /* Inhibit try_cursor_movement display optimization. */);
31777 inhibit_try_cursor_movement
= false;
31778 #endif /* GLYPH_DEBUG */
31780 DEFVAR_INT ("overline-margin", overline_margin
,
31781 doc
: /* Space between overline and text, in pixels.
31782 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
31783 margin to the character height. */);
31784 overline_margin
= 2;
31786 DEFVAR_INT ("underline-minimum-offset",
31787 underline_minimum_offset
,
31788 doc
: /* Minimum distance between baseline and underline.
31789 This can improve legibility of underlined text at small font sizes,
31790 particularly when using variable `x-use-underline-position-properties'
31791 with fonts that specify an UNDERLINE_POSITION relatively close to the
31792 baseline. The default value is 1. */);
31793 underline_minimum_offset
= 1;
31795 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
31796 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
31797 This feature only works when on a window system that can change
31798 cursor shapes. */);
31799 display_hourglass_p
= true;
31801 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
31802 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
31803 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
31805 #ifdef HAVE_WINDOW_SYSTEM
31806 hourglass_atimer
= NULL
;
31807 hourglass_shown_p
= false;
31808 #endif /* HAVE_WINDOW_SYSTEM */
31810 /* Name of the face used to display glyphless characters. */
31811 DEFSYM (Qglyphless_char
, "glyphless-char");
31813 /* Method symbols for Vglyphless_char_display. */
31814 DEFSYM (Qhex_code
, "hex-code");
31815 DEFSYM (Qempty_box
, "empty-box");
31816 DEFSYM (Qthin_space
, "thin-space");
31817 DEFSYM (Qzero_width
, "zero-width");
31819 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
31820 doc
: /* Function run just before redisplay.
31821 It is called with one argument, which is the set of windows that are to
31822 be redisplayed. This set can be nil (meaning, only the selected window),
31823 or t (meaning all windows). */);
31824 Vpre_redisplay_function
= intern ("ignore");
31826 /* Symbol for the purpose of Vglyphless_char_display. */
31827 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
31828 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
31830 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
31831 doc
: /* Char-table defining glyphless characters.
31832 Each element, if non-nil, should be one of the following:
31833 an ASCII acronym string: display this string in a box
31834 `hex-code': display the hexadecimal code of a character in a box
31835 `empty-box': display as an empty box
31836 `thin-space': display as 1-pixel width space
31837 `zero-width': don't display
31838 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
31839 display method for graphical terminals and text terminals respectively.
31840 GRAPHICAL and TEXT should each have one of the values listed above.
31842 The char-table has one extra slot to control the display of a character for
31843 which no font is found. This slot only takes effect on graphical terminals.
31844 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
31845 `thin-space'. The default is `empty-box'.
31847 If a character has a non-nil entry in an active display table, the
31848 display table takes effect; in this case, Emacs does not consult
31849 `glyphless-char-display' at all. */);
31850 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
31851 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
31854 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
31855 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
31856 Vdebug_on_message
= Qnil
;
31858 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
31860 Vredisplay__all_windows_cause
= Fmake_hash_table (0, NULL
);
31862 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
31864 Vredisplay__mode_lines_cause
= Fmake_hash_table (0, NULL
);
31866 DEFVAR_LISP ("redisplay--variables", Vredisplay__variables
,
31867 doc
: /* A hash-table of variables changing which triggers a thorough redisplay. */);
31868 Vredisplay__variables
= Qnil
;
31870 DEFVAR_BOOL ("redisplay--inhibit-bidi", redisplay__inhibit_bidi
,
31871 doc
: /* Non-nil means it is not safe to attempt bidi reordering for display. */);
31872 /* Initialize to t, since we need to disable reordering until
31873 loadup.el successfully loads charprop.el. */
31874 redisplay__inhibit_bidi
= true;
31878 /* Initialize this module when Emacs starts. */
31883 CHARPOS (this_line_start_pos
) = 0;
31885 if (!noninteractive
)
31887 struct window
*m
= XWINDOW (minibuf_window
);
31888 Lisp_Object frame
= m
->frame
;
31889 struct frame
*f
= XFRAME (frame
);
31890 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
31891 struct window
*r
= XWINDOW (root
);
31894 echo_area_window
= minibuf_window
;
31896 r
->top_line
= FRAME_TOP_MARGIN (f
);
31897 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
31898 r
->total_cols
= FRAME_COLS (f
);
31899 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31900 r
->total_lines
= FRAME_TOTAL_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
31901 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
31903 m
->top_line
= FRAME_TOTAL_LINES (f
) - 1;
31904 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
31905 m
->total_cols
= FRAME_COLS (f
);
31906 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31907 m
->total_lines
= 1;
31908 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
31910 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
31911 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
31912 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
31914 /* The default ellipsis glyphs `...'. */
31915 for (i
= 0; i
< 3; ++i
)
31916 default_invis_vector
[i
] = make_number ('.');
31920 /* Allocate the buffer for frame titles.
31921 Also used for `format-mode-line'. */
31923 mode_line_noprop_buf
= xmalloc (size
);
31924 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
31925 mode_line_noprop_ptr
= mode_line_noprop_buf
;
31926 mode_line_target
= MODE_LINE_DISPLAY
;
31929 help_echo_showing_p
= false;
31932 #ifdef HAVE_WINDOW_SYSTEM
31934 /* Platform-independent portion of hourglass implementation. */
31936 /* Timer function of hourglass_atimer. */
31939 show_hourglass (struct atimer
*timer
)
31941 /* The timer implementation will cancel this timer automatically
31942 after this function has run. Set hourglass_atimer to null
31943 so that we know the timer doesn't have to be canceled. */
31944 hourglass_atimer
= NULL
;
31946 if (!hourglass_shown_p
)
31948 Lisp_Object tail
, frame
;
31952 FOR_EACH_FRAME (tail
, frame
)
31954 struct frame
*f
= XFRAME (frame
);
31956 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31957 && FRAME_RIF (f
)->show_hourglass
)
31958 FRAME_RIF (f
)->show_hourglass (f
);
31961 hourglass_shown_p
= true;
31966 /* Cancel a currently active hourglass timer, and start a new one. */
31969 start_hourglass (void)
31971 struct timespec delay
;
31973 cancel_hourglass ();
31975 if (INTEGERP (Vhourglass_delay
)
31976 && XINT (Vhourglass_delay
) > 0)
31977 delay
= make_timespec (min (XINT (Vhourglass_delay
),
31978 TYPE_MAXIMUM (time_t)),
31980 else if (FLOATP (Vhourglass_delay
)
31981 && XFLOAT_DATA (Vhourglass_delay
) > 0)
31982 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
31984 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
31986 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
31987 show_hourglass
, NULL
);
31990 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
31994 cancel_hourglass (void)
31996 if (hourglass_atimer
)
31998 cancel_atimer (hourglass_atimer
);
31999 hourglass_atimer
= NULL
;
32002 if (hourglass_shown_p
)
32004 Lisp_Object tail
, frame
;
32008 FOR_EACH_FRAME (tail
, frame
)
32010 struct frame
*f
= XFRAME (frame
);
32012 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
32013 && FRAME_RIF (f
)->hide_hourglass
)
32014 FRAME_RIF (f
)->hide_hourglass (f
);
32016 /* No cursors on non GUI frames - restore to stock arrow cursor. */
32017 else if (!FRAME_W32_P (f
))
32018 w32_arrow_cursor ();
32022 hourglass_shown_p
= false;
32027 #endif /* HAVE_WINDOW_SYSTEM */