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
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code.
36 The following diagram shows how redisplay code is invoked. As you
37 can see, Lisp calls redisplay and vice versa. Under window systems
38 like X, some portions of the redisplay code are also called
39 asynchronously during mouse movement or expose events. It is very
40 important that these code parts do NOT use the C library (malloc,
41 free) because many C libraries under Unix are not reentrant. They
42 may also NOT call functions of the Lisp interpreter which could
43 change the interpreter's state. If you don't follow these rules,
44 you will encounter bugs which are very hard to explain.
46 +--------------+ redisplay +----------------+
47 | Lisp machine |---------------->| Redisplay code |<--+
48 +--------------+ (xdisp.c) +----------------+ |
50 +----------------------------------+ |
51 Don't use this path when called |
54 expose_window (asynchronous) |
56 X expose events -----+
58 What does redisplay do? Obviously, it has to figure out somehow what
59 has been changed since the last time the display has been updated,
60 and to make these changes visible. Preferably it would do that in
61 a moderately intelligent way, i.e. fast.
63 Changes in buffer text can be deduced from window and buffer
64 structures, and from some global variables like `beg_unchanged' and
65 `end_unchanged'. The contents of the display are additionally
66 recorded in a `glyph matrix', a two-dimensional matrix of glyph
67 structures. Each row in such a matrix corresponds to a line on the
68 display, and each glyph in a row corresponds to a column displaying
69 a character, an image, or what else. This matrix is called the
70 `current glyph matrix' or `current matrix' in redisplay
73 For buffer parts that have been changed since the last update, a
74 second glyph matrix is constructed, the so called `desired glyph
75 matrix' or short `desired matrix'. Current and desired matrix are
76 then compared to find a cheap way to update the display, e.g. by
77 reusing part of the display by scrolling lines.
79 You will find a lot of redisplay optimizations when you start
80 looking at the innards of redisplay. The overall goal of all these
81 optimizations is to make redisplay fast because it is done
82 frequently. Some of these optimizations are implemented by the
87 This function tries to update the display if the text in the
88 window did not change and did not scroll, only point moved, and
89 it did not move off the displayed portion of the text.
91 . try_window_reusing_current_matrix
93 This function reuses the current matrix of a window when text
94 has not changed, but the window start changed (e.g., due to
99 This function attempts to redisplay a window by reusing parts of
100 its existing display. It finds and reuses the part that was not
101 changed, and redraws the rest. (The "id" part in the function's
102 name stands for "insert/delete", not for "identification" or
107 This function performs the full redisplay of a single window
108 assuming that its fonts were not changed and that the cursor
109 will not end up in the scroll margins. (Loading fonts requires
110 re-adjustment of dimensions of glyph matrices, which makes this
111 method impossible to use.)
113 These optimizations are tried in sequence (some can be skipped if
114 it is known that they are not applicable). If none of the
115 optimizations were successful, redisplay calls redisplay_windows,
116 which performs a full redisplay of all windows.
118 Note that there's one more important optimization up Emacs's
119 sleeve, but it is related to actually redrawing the potentially
120 changed portions of the window/frame, not to reproducing the
121 desired matrices of those potentially changed portions. Namely,
122 the function update_frame and its subroutines, which you will find
123 in dispnew.c, compare the desired matrices with the current
124 matrices, and only redraw the portions that changed. So it could
125 happen that the functions in this file for some reason decide that
126 the entire desired matrix needs to be regenerated from scratch, and
127 still only parts of the Emacs display, or even nothing at all, will
128 be actually delivered to the glass, because update_frame has found
129 that the new and the old screen contents are similar or identical.
133 Desired matrices are always built per Emacs window. The function
134 `display_line' is the central function to look at if you are
135 interested. It constructs one row in a desired matrix given an
136 iterator structure containing both a buffer position and a
137 description of the environment in which the text is to be
138 displayed. But this is too early, read on.
140 Characters and pixmaps displayed for a range of buffer text depend
141 on various settings of buffers and windows, on overlays and text
142 properties, on display tables, on selective display. The good news
143 is that all this hairy stuff is hidden behind a small set of
144 interface functions taking an iterator structure (struct it)
147 Iteration over things to be displayed is then simple. It is
148 started by initializing an iterator with a call to init_iterator,
149 passing it the buffer position where to start iteration. For
150 iteration over strings, pass -1 as the position to init_iterator,
151 and call reseat_to_string when the string is ready, to initialize
152 the iterator for that string. Thereafter, calls to
153 get_next_display_element fill the iterator structure with relevant
154 information about the next thing to display. Calls to
155 set_iterator_to_next move the iterator to the next thing.
157 Besides this, an iterator also contains information about the
158 display environment in which glyphs for display elements are to be
159 produced. It has fields for the width and height of the display,
160 the information whether long lines are truncated or continued, a
161 current X and Y position, and lots of other stuff you can better
164 Glyphs in a desired matrix are normally constructed in a loop
165 calling get_next_display_element and then PRODUCE_GLYPHS. The call
166 to PRODUCE_GLYPHS will fill the iterator structure with pixel
167 information about the element being displayed and at the same time
168 produce glyphs for it. If the display element fits on the line
169 being displayed, set_iterator_to_next is called next, otherwise the
170 glyphs produced are discarded. The function display_line is the
171 workhorse of filling glyph rows in the desired matrix with glyphs.
172 In addition to producing glyphs, it also handles line truncation
173 and continuation, word wrap, and cursor positioning (for the
174 latter, see also set_cursor_from_row).
178 That just couldn't be all, could it? What about terminal types not
179 supporting operations on sub-windows of the screen? To update the
180 display on such a terminal, window-based glyph matrices are not
181 well suited. To be able to reuse part of the display (scrolling
182 lines up and down), we must instead have a view of the whole
183 screen. This is what `frame matrices' are for. They are a trick.
185 Frames on terminals like above have a glyph pool. Windows on such
186 a frame sub-allocate their glyph memory from their frame's glyph
187 pool. The frame itself is given its own glyph matrices. By
188 coincidence---or maybe something else---rows in window glyph
189 matrices are slices of corresponding rows in frame matrices. Thus
190 writing to window matrices implicitly updates a frame matrix which
191 provides us with the view of the whole screen that we originally
192 wanted to have without having to move many bytes around. To be
193 honest, there is a little bit more done, but not much more. If you
194 plan to extend that code, take a look at dispnew.c. The function
195 build_frame_matrix is a good starting point.
197 Bidirectional display.
199 Bidirectional display adds quite some hair to this already complex
200 design. The good news are that a large portion of that hairy stuff
201 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
202 reordering engine which is called by set_iterator_to_next and
203 returns the next character to display in the visual order. See
204 commentary on bidi.c for more details. As far as redisplay is
205 concerned, the effect of calling bidi_move_to_visually_next, the
206 main interface of the reordering engine, is that the iterator gets
207 magically placed on the buffer or string position that is to be
208 displayed next. In other words, a linear iteration through the
209 buffer/string is replaced with a non-linear one. All the rest of
210 the redisplay is oblivious to the bidi reordering.
212 Well, almost oblivious---there are still complications, most of
213 them due to the fact that buffer and string positions no longer
214 change monotonously with glyph indices in a glyph row. Moreover,
215 for continued lines, the buffer positions may not even be
216 monotonously changing with vertical positions. Also, accounting
217 for face changes, overlays, etc. becomes more complex because
218 non-linear iteration could potentially skip many positions with
219 changes, and then cross them again on the way back...
221 One other prominent effect of bidirectional display is that some
222 paragraphs of text need to be displayed starting at the right
223 margin of the window---the so-called right-to-left, or R2L
224 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
225 which have their reversed_p flag set. The bidi reordering engine
226 produces characters in such rows starting from the character which
227 should be the rightmost on display. PRODUCE_GLYPHS then reverses
228 the order, when it fills up the glyph row whose reversed_p flag is
229 set, by prepending each new glyph to what is already there, instead
230 of appending it. When the glyph row is complete, the function
231 extend_face_to_end_of_line fills the empty space to the left of the
232 leftmost character with special glyphs, which will display as,
233 well, empty. On text terminals, these special glyphs are simply
234 blank characters. On graphics terminals, there's a single stretch
235 glyph of a suitably computed width. Both the blanks and the
236 stretch glyph are given the face of the background of the line.
237 This way, the terminal-specific back-end can still draw the glyphs
238 left to right, even for R2L lines.
240 Bidirectional display and character compositions
242 Some scripts cannot be displayed by drawing each character
243 individually, because adjacent characters change each other's shape
244 on display. For example, Arabic and Indic scripts belong to this
247 Emacs display supports this by providing "character compositions",
248 most of which is implemented in composite.c. During the buffer
249 scan that delivers characters to PRODUCE_GLYPHS, if the next
250 character to be delivered is a composed character, the iteration
251 calls composition_reseat_it and next_element_from_composition. If
252 they succeed to compose the character with one or more of the
253 following characters, the whole sequence of characters that where
254 composed is recorded in the `struct composition_it' object that is
255 part of the buffer iterator. The composed sequence could produce
256 one or more font glyphs (called "grapheme clusters") on the screen.
257 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
258 in the direction corresponding to the current bidi scan direction
259 (recorded in the scan_dir member of the `struct bidi_it' object
260 that is part of the buffer iterator). In particular, if the bidi
261 iterator currently scans the buffer backwards, the grapheme
262 clusters are delivered back to front. This reorders the grapheme
263 clusters as appropriate for the current bidi context. Note that
264 this means that the grapheme clusters are always stored in the
265 LGSTRING object (see composite.c) in the logical order.
267 Moving an iterator in bidirectional text
268 without producing glyphs
270 Note one important detail mentioned above: that the bidi reordering
271 engine, driven by the iterator, produces characters in R2L rows
272 starting at the character that will be the rightmost on display.
273 As far as the iterator is concerned, the geometry of such rows is
274 still left to right, i.e. the iterator "thinks" the first character
275 is at the leftmost pixel position. The iterator does not know that
276 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
277 delivers. This is important when functions from the move_it_*
278 family are used to get to certain screen position or to match
279 screen coordinates with buffer coordinates: these functions use the
280 iterator geometry, which is left to right even in R2L paragraphs.
281 This works well with most callers of move_it_*, because they need
282 to get to a specific column, and columns are still numbered in the
283 reading order, i.e. the rightmost character in a R2L paragraph is
284 still column zero. But some callers do not get well with this; a
285 notable example is mouse clicks that need to find the character
286 that corresponds to certain pixel coordinates. See
287 buffer_posn_from_coords in dispnew.c for how this is handled. */
295 #include "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"
317 #ifdef HAVE_WINDOW_SYSTEM
319 #endif /* HAVE_WINDOW_SYSTEM */
322 # include "xwidget.h"
324 #ifndef FRAME_X_OUTPUT
325 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
328 #define INFINITY 10000000
330 /* Holds the list (error). */
331 static Lisp_Object list_of_error
;
333 #ifdef HAVE_WINDOW_SYSTEM
335 /* Test if overflow newline into fringe. Called with iterator IT
336 at or past right window margin, and with IT->current_x set. */
338 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
339 (!NILP (Voverflow_newline_into_fringe) \
340 && FRAME_WINDOW_P ((IT)->f) \
341 && ((IT)->bidi_it.paragraph_dir == R2L \
342 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
343 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
344 && (IT)->current_x == (IT)->last_visible_x)
346 #else /* !HAVE_WINDOW_SYSTEM */
347 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) false
348 #endif /* HAVE_WINDOW_SYSTEM */
350 /* Test if the display element loaded in IT, or the underlying buffer
351 or string character, is a space or a TAB character. This is used
352 to determine where word wrapping can occur. */
354 #define IT_DISPLAYING_WHITESPACE(it) \
355 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
356 || ((STRINGP (it->string) \
357 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
358 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
360 && (it->s[IT_BYTEPOS (*it)] == ' ' \
361 || it->s[IT_BYTEPOS (*it)] == '\t')) \
362 || (IT_BYTEPOS (*it) < ZV_BYTE \
363 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
364 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
366 /* True means print newline to stdout before next mini-buffer message. */
368 bool noninteractive_need_newline
;
370 /* True means print newline to message log before next message. */
372 static bool message_log_need_newline
;
374 /* Three markers that message_dolog uses.
375 It could allocate them itself, but that causes trouble
376 in handling memory-full errors. */
377 static Lisp_Object message_dolog_marker1
;
378 static Lisp_Object message_dolog_marker2
;
379 static Lisp_Object message_dolog_marker3
;
381 /* The buffer position of the first character appearing entirely or
382 partially on the line of the selected window which contains the
383 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
384 redisplay optimization in redisplay_internal. */
386 static struct text_pos this_line_start_pos
;
388 /* Number of characters past the end of the line above, including the
389 terminating newline. */
391 static struct text_pos this_line_end_pos
;
393 /* The vertical positions and the height of this line. */
395 static int this_line_vpos
;
396 static int this_line_y
;
397 static int this_line_pixel_height
;
399 /* X position at which this display line starts. Usually zero;
400 negative if first character is partially visible. */
402 static int this_line_start_x
;
404 /* The smallest character position seen by move_it_* functions as they
405 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
406 hscrolled lines, see display_line. */
408 static struct text_pos this_line_min_pos
;
410 /* Buffer that this_line_.* variables are referring to. */
412 static struct buffer
*this_line_buffer
;
414 /* True if an overlay arrow has been displayed in this window. */
416 static bool overlay_arrow_seen
;
418 /* Vector containing glyphs for an ellipsis `...'. */
420 static Lisp_Object default_invis_vector
[3];
422 /* This is the window where the echo area message was displayed. It
423 is always a mini-buffer window, but it may not be the same window
424 currently active as a mini-buffer. */
426 Lisp_Object echo_area_window
;
428 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
429 pushes the current message and the value of
430 message_enable_multibyte on the stack, the function restore_message
431 pops the stack and displays MESSAGE again. */
433 static Lisp_Object Vmessage_stack
;
435 /* True means multibyte characters were enabled when the echo area
436 message was specified. */
438 static bool message_enable_multibyte
;
440 /* At each redisplay cycle, we should refresh everything there is to refresh.
441 To do that efficiently, we use many optimizations that try to make sure we
442 don't waste too much time updating things that haven't changed.
443 The coarsest such optimization is that, in the most common cases, we only
444 look at the selected-window.
446 To know whether other windows should be considered for redisplay, we use the
447 variable windows_or_buffers_changed: as long as it is 0, it means that we
448 have not noticed anything that should require updating anything else than
449 the selected-window. If it is set to REDISPLAY_SOME, it means that since
450 last redisplay, some changes have been made which could impact other
451 windows. To know which ones need redisplay, every buffer, window, and frame
452 has a `redisplay' bit, which (if true) means that this object needs to be
453 redisplayed. If windows_or_buffers_changed is 0, we know there's no point
454 looking for those `redisplay' bits (actually, there might be some such bits
455 set, but then only on objects which aren't displayed anyway).
457 OTOH if it's non-zero we wil have to loop through all windows and then check
458 the `redisplay' bit of the corresponding window, frame, and buffer, in order
459 to decide whether that window needs attention or not. Note that we can't
460 just look at the frame's redisplay bit to decide that the whole frame can be
461 skipped, since even if the frame's redisplay bit is unset, some of its
462 windows's redisplay bits may be set.
464 Mostly for historical reasons, windows_or_buffers_changed can also take
465 other non-zero values. In that case, the precise value doesn't matter (it
466 encodes the cause of the setting but is only used for debugging purposes),
467 and what it means is that we shouldn't pay attention to any `redisplay' bits
468 and we should simply try and redisplay every window out there. */
470 int windows_or_buffers_changed
;
472 /* Nonzero if we should redraw the mode lines on the next redisplay.
473 Similarly to `windows_or_buffers_changed', If it has value REDISPLAY_SOME,
474 then only redisplay the mode lines in those buffers/windows/frames where the
475 `redisplay' bit has been set.
476 For any other value, redisplay all mode lines (the number used is then only
477 used to track down the cause for this full-redisplay).
479 Since the frame title uses the same %-constructs as the mode line
480 (except %c and %l), if this variable is non-zero, we also consider
481 redisplaying the title of each frame, see x_consider_frame_title.
483 The `redisplay' bits are the same as those used for
484 windows_or_buffers_changed, and setting windows_or_buffers_changed also
485 causes recomputation of the mode lines of all those windows. IOW this
486 variable only has an effect if windows_or_buffers_changed is zero, in which
487 case we should only need to redisplay the mode-line of those objects with
488 a `redisplay' bit set but not the window's text content (tho we may still
489 need to refresh the text content of the selected-window). */
491 int update_mode_lines
;
493 /* True after display_mode_line if %l was used and it displayed a
496 static bool line_number_displayed
;
498 /* The name of the *Messages* buffer, a string. */
500 static Lisp_Object Vmessages_buffer_name
;
502 /* Current, index 0, and last displayed echo area message. Either
503 buffers from echo_buffers, or nil to indicate no message. */
505 Lisp_Object echo_area_buffer
[2];
507 /* The buffers referenced from echo_area_buffer. */
509 static Lisp_Object echo_buffer
[2];
511 /* A vector saved used in with_area_buffer to reduce consing. */
513 static Lisp_Object Vwith_echo_area_save_vector
;
515 /* True means display_echo_area should display the last echo area
516 message again. Set by redisplay_preserve_echo_area. */
518 static bool display_last_displayed_message_p
;
520 /* True if echo area is being used by print; false if being used by
523 static bool message_buf_print
;
525 /* Set to true in clear_message to make redisplay_internal aware
526 of an emptied echo area. */
528 static bool message_cleared_p
;
530 /* A scratch glyph row with contents used for generating truncation
531 glyphs. Also used in direct_output_for_insert. */
533 #define MAX_SCRATCH_GLYPHS 100
534 static struct glyph_row scratch_glyph_row
;
535 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
537 /* Ascent and height of the last line processed by move_it_to. */
539 static int last_height
;
541 /* True if there's a help-echo in the echo area. */
543 bool help_echo_showing_p
;
545 /* The maximum distance to look ahead for text properties. Values
546 that are too small let us call compute_char_face and similar
547 functions too often which is expensive. Values that are too large
548 let us call compute_char_face and alike too often because we
549 might not be interested in text properties that far away. */
551 #define TEXT_PROP_DISTANCE_LIMIT 100
553 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
554 iterator state and later restore it. This is needed because the
555 bidi iterator on bidi.c keeps a stacked cache of its states, which
556 is really a singleton. When we use scratch iterator objects to
557 move around the buffer, we can cause the bidi cache to be pushed or
558 popped, and therefore we need to restore the cache state when we
559 return to the original iterator. */
560 #define SAVE_IT(ITCOPY, ITORIG, CACHE) \
563 bidi_unshelve_cache (CACHE, true); \
565 CACHE = bidi_shelve_cache (); \
568 #define RESTORE_IT(pITORIG, pITCOPY, CACHE) \
570 if (pITORIG != pITCOPY) \
571 *(pITORIG) = *(pITCOPY); \
572 bidi_unshelve_cache (CACHE, false); \
576 /* Functions to mark elements as needing redisplay. */
577 enum { REDISPLAY_SOME
= 2}; /* Arbitrary choice. */
580 redisplay_other_windows (void)
582 if (!windows_or_buffers_changed
)
583 windows_or_buffers_changed
= REDISPLAY_SOME
;
587 wset_redisplay (struct window
*w
)
589 /* Beware: selected_window can be nil during early stages. */
590 if (!EQ (make_lisp_ptr (w
, Lisp_Vectorlike
), selected_window
))
591 redisplay_other_windows ();
596 fset_redisplay (struct frame
*f
)
598 redisplay_other_windows ();
603 bset_redisplay (struct buffer
*b
)
605 int count
= buffer_window_count (b
);
608 /* ... it's visible in other window than selected, */
609 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
610 redisplay_other_windows ();
611 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
612 so that if we later set windows_or_buffers_changed, this buffer will
614 b
->text
->redisplay
= true;
619 bset_update_mode_line (struct buffer
*b
)
621 if (!update_mode_lines
)
622 update_mode_lines
= REDISPLAY_SOME
;
623 b
->text
->redisplay
= true;
627 maybe_set_redisplay (Lisp_Object symbol
)
629 if (HASH_TABLE_P (Vredisplay__variables
)
630 && hash_lookup (XHASH_TABLE (Vredisplay__variables
), symbol
, NULL
) >= 0)
632 bset_update_mode_line (current_buffer
);
633 current_buffer
->prevent_redisplay_optimizations_p
= true;
639 /* True means print traces of redisplay if compiled with
640 GLYPH_DEBUG defined. */
642 bool trace_redisplay_p
;
644 #endif /* GLYPH_DEBUG */
646 #ifdef DEBUG_TRACE_MOVE
647 /* True means trace with TRACE_MOVE to stderr. */
648 static bool trace_move
;
650 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
652 #define TRACE_MOVE(x) (void) 0
655 /* Buffer being redisplayed -- for redisplay_window_error. */
657 static struct buffer
*displayed_buffer
;
659 /* Value returned from text property handlers (see below). */
664 HANDLED_RECOMPUTE_PROPS
,
665 HANDLED_OVERLAY_STRING_CONSUMED
,
669 /* A description of text properties that redisplay is interested
674 /* The symbol index of the name of the property. */
677 /* A unique index for the property. */
680 /* A handler function called to set up iterator IT from the property
681 at IT's current position. Value is used to steer handle_stop. */
682 enum prop_handled (*handler
) (struct it
*it
);
685 static enum prop_handled
handle_face_prop (struct it
*);
686 static enum prop_handled
handle_invisible_prop (struct it
*);
687 static enum prop_handled
handle_display_prop (struct it
*);
688 static enum prop_handled
handle_composition_prop (struct it
*);
689 static enum prop_handled
handle_overlay_change (struct it
*);
690 static enum prop_handled
handle_fontified_prop (struct it
*);
692 /* Properties handled by iterators. */
694 static struct props it_props
[] =
696 {SYMBOL_INDEX (Qfontified
), FONTIFIED_PROP_IDX
, handle_fontified_prop
},
697 /* Handle `face' before `display' because some sub-properties of
698 `display' need to know the face. */
699 {SYMBOL_INDEX (Qface
), FACE_PROP_IDX
, handle_face_prop
},
700 {SYMBOL_INDEX (Qdisplay
), DISPLAY_PROP_IDX
, handle_display_prop
},
701 {SYMBOL_INDEX (Qinvisible
), INVISIBLE_PROP_IDX
, handle_invisible_prop
},
702 {SYMBOL_INDEX (Qcomposition
), COMPOSITION_PROP_IDX
, handle_composition_prop
},
706 /* Value is the position described by X. If X is a marker, value is
707 the marker_position of X. Otherwise, value is X. */
709 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
711 /* Enumeration returned by some move_it_.* functions internally. */
715 /* Not used. Undefined value. */
718 /* Move ended at the requested buffer position or ZV. */
719 MOVE_POS_MATCH_OR_ZV
,
721 /* Move ended at the requested X pixel position. */
724 /* Move within a line ended at the end of a line that must be
728 /* Move within a line ended at the end of a line that would
729 be displayed truncated. */
732 /* Move within a line ended at a line end. */
736 /* This counter is used to clear the face cache every once in a while
737 in redisplay_internal. It is incremented for each redisplay.
738 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
741 #define CLEAR_FACE_CACHE_COUNT 500
742 static int clear_face_cache_count
;
744 /* Similarly for the image cache. */
746 #ifdef HAVE_WINDOW_SYSTEM
747 #define CLEAR_IMAGE_CACHE_COUNT 101
748 static int clear_image_cache_count
;
750 /* Null glyph slice */
751 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
754 /* True while redisplay_internal is in progress. */
758 /* If a string, XTread_socket generates an event to display that string.
759 (The display is done in read_char.) */
761 Lisp_Object help_echo_string
;
762 Lisp_Object help_echo_window
;
763 Lisp_Object help_echo_object
;
764 ptrdiff_t help_echo_pos
;
766 /* Temporary variable for XTread_socket. */
768 Lisp_Object previous_help_echo_string
;
770 /* Platform-independent portion of hourglass implementation. */
772 #ifdef HAVE_WINDOW_SYSTEM
774 /* True means an hourglass cursor is currently shown. */
775 static bool hourglass_shown_p
;
777 /* If non-null, an asynchronous timer that, when it expires, displays
778 an hourglass cursor on all frames. */
779 static struct atimer
*hourglass_atimer
;
781 #endif /* HAVE_WINDOW_SYSTEM */
783 /* Default number of seconds to wait before displaying an hourglass
785 #define DEFAULT_HOURGLASS_DELAY 1
787 #ifdef HAVE_WINDOW_SYSTEM
789 /* Default pixel width of `thin-space' display method. */
790 #define THIN_SPACE_WIDTH 1
792 #endif /* HAVE_WINDOW_SYSTEM */
794 /* Function prototypes. */
796 static void setup_for_ellipsis (struct it
*, int);
797 static void set_iterator_to_next (struct it
*, bool);
798 static void mark_window_display_accurate_1 (struct window
*, bool);
799 static bool row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
800 static bool cursor_row_p (struct glyph_row
*);
801 static int redisplay_mode_lines (Lisp_Object
, bool);
803 static void handle_line_prefix (struct it
*);
805 static void handle_stop_backwards (struct it
*, ptrdiff_t);
806 static void unwind_with_echo_area_buffer (Lisp_Object
);
807 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
808 static bool current_message_1 (ptrdiff_t, Lisp_Object
);
809 static bool truncate_message_1 (ptrdiff_t, Lisp_Object
);
810 static void set_message (Lisp_Object
);
811 static bool set_message_1 (ptrdiff_t, Lisp_Object
);
812 static bool display_echo_area_1 (ptrdiff_t, Lisp_Object
);
813 static bool resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
814 static void unwind_redisplay (void);
815 static void extend_face_to_end_of_line (struct it
*);
816 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
817 static void push_it (struct it
*, struct text_pos
*);
818 static void iterate_out_of_display_property (struct it
*);
819 static void pop_it (struct it
*);
820 static void redisplay_internal (void);
821 static void echo_area_display (bool);
822 static void redisplay_windows (Lisp_Object
);
823 static void redisplay_window (Lisp_Object
, bool);
824 static Lisp_Object
redisplay_window_error (Lisp_Object
);
825 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
826 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
827 static bool set_cursor_from_row (struct window
*, struct glyph_row
*,
828 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
830 static bool update_menu_bar (struct frame
*, bool, bool);
831 static bool try_window_reusing_current_matrix (struct window
*);
832 static int try_window_id (struct window
*);
833 static bool display_line (struct it
*);
834 static int display_mode_lines (struct window
*);
835 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
836 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
,
838 static int store_mode_line_string (const char *, Lisp_Object
, bool, int, int,
840 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
841 static void display_menu_bar (struct window
*);
842 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
844 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
845 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
846 static void compute_line_metrics (struct it
*);
847 static void run_redisplay_end_trigger_hook (struct it
*);
848 static bool get_overlay_strings (struct it
*, ptrdiff_t);
849 static bool get_overlay_strings_1 (struct it
*, ptrdiff_t, bool);
850 static void next_overlay_string (struct it
*);
851 static void reseat (struct it
*, struct text_pos
, bool);
852 static void reseat_1 (struct it
*, struct text_pos
, bool);
853 static bool next_element_from_display_vector (struct it
*);
854 static bool next_element_from_string (struct it
*);
855 static bool next_element_from_c_string (struct it
*);
856 static bool next_element_from_buffer (struct it
*);
857 static bool next_element_from_composition (struct it
*);
858 static bool next_element_from_image (struct it
*);
859 static bool next_element_from_stretch (struct it
*);
861 static bool next_element_from_xwidget (struct it
*);
863 static void load_overlay_strings (struct it
*, ptrdiff_t);
864 static bool get_next_display_element (struct it
*);
865 static enum move_it_result
866 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
867 enum move_operation_enum
);
868 static void get_visually_first_element (struct it
*);
869 static void compute_stop_pos (struct it
*);
870 static int face_before_or_after_it_pos (struct it
*, bool);
871 static ptrdiff_t next_overlay_change (ptrdiff_t);
872 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
873 Lisp_Object
, struct text_pos
*, ptrdiff_t, bool);
874 static int handle_single_display_spec (struct it
*, Lisp_Object
,
875 Lisp_Object
, Lisp_Object
,
876 struct text_pos
*, ptrdiff_t, int, bool);
877 static int underlying_face_id (struct it
*);
879 #define face_before_it_pos(IT) face_before_or_after_it_pos (IT, true)
880 #define face_after_it_pos(IT) face_before_or_after_it_pos (IT, false)
882 #ifdef HAVE_WINDOW_SYSTEM
884 static void update_tool_bar (struct frame
*, bool);
885 static void x_draw_bottom_divider (struct window
*w
);
886 static void notice_overwritten_cursor (struct window
*,
889 static int normal_char_height (struct font
*, int);
890 static void normal_char_ascent_descent (struct font
*, int, int *, int *);
892 static void append_stretch_glyph (struct it
*, Lisp_Object
,
895 static Lisp_Object
get_it_property (struct it
*, Lisp_Object
);
896 static Lisp_Object
calc_line_height_property (struct it
*, Lisp_Object
,
897 struct font
*, int, bool);
899 #endif /* HAVE_WINDOW_SYSTEM */
901 static void produce_special_glyphs (struct it
*, enum display_element_type
);
902 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
903 static bool coords_in_mouse_face_p (struct window
*, int, int);
907 /***********************************************************************
908 Window display dimensions
909 ***********************************************************************/
911 /* Return the bottom boundary y-position for text lines in window W.
912 This is the first y position at which a line cannot start.
913 It is relative to the top of the window.
915 This is the height of W minus the height of a mode line, if any. */
918 window_text_bottom_y (struct window
*w
)
920 int height
= WINDOW_PIXEL_HEIGHT (w
);
922 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
924 if (WINDOW_WANTS_MODELINE_P (w
))
925 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
927 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
932 /* Return the pixel width of display area AREA of window W.
933 ANY_AREA means return the total width of W, not including
934 fringes to the left and right of the window. */
937 window_box_width (struct window
*w
, enum glyph_row_area area
)
939 int width
= w
->pixel_width
;
941 if (!w
->pseudo_window_p
)
943 width
-= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
944 width
-= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
946 if (area
== TEXT_AREA
)
947 width
-= (WINDOW_MARGINS_WIDTH (w
)
948 + WINDOW_FRINGES_WIDTH (w
));
949 else if (area
== LEFT_MARGIN_AREA
)
950 width
= WINDOW_LEFT_MARGIN_WIDTH (w
);
951 else if (area
== RIGHT_MARGIN_AREA
)
952 width
= WINDOW_RIGHT_MARGIN_WIDTH (w
);
955 /* With wide margins, fringes, etc. we might end up with a negative
956 width, correct that here. */
957 return max (0, width
);
961 /* Return the pixel height of the display area of window W, not
962 including mode lines of W, if any. */
965 window_box_height (struct window
*w
)
967 struct frame
*f
= XFRAME (w
->frame
);
968 int height
= WINDOW_PIXEL_HEIGHT (w
);
970 eassert (height
>= 0);
972 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
973 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
975 /* Note: the code below that determines the mode-line/header-line
976 height is essentially the same as that contained in the macro
977 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
978 the appropriate glyph row has its `mode_line_p' flag set,
979 and if it doesn't, uses estimate_mode_line_height instead. */
981 if (WINDOW_WANTS_MODELINE_P (w
))
983 struct glyph_row
*ml_row
984 = (w
->current_matrix
&& w
->current_matrix
->rows
985 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
987 if (ml_row
&& ml_row
->mode_line_p
)
988 height
-= ml_row
->height
;
990 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
993 if (WINDOW_WANTS_HEADER_LINE_P (w
))
995 struct glyph_row
*hl_row
996 = (w
->current_matrix
&& w
->current_matrix
->rows
997 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
999 if (hl_row
&& hl_row
->mode_line_p
)
1000 height
-= hl_row
->height
;
1002 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1005 /* With a very small font and a mode-line that's taller than
1006 default, we might end up with a negative height. */
1007 return max (0, height
);
1010 /* Return the window-relative coordinate of the left edge of display
1011 area AREA of window W. ANY_AREA means return the left edge of the
1012 whole window, to the right of the left fringe of W. */
1015 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1019 if (w
->pseudo_window_p
)
1022 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1024 if (area
== TEXT_AREA
)
1025 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1026 + window_box_width (w
, LEFT_MARGIN_AREA
));
1027 else if (area
== RIGHT_MARGIN_AREA
)
1028 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1029 + window_box_width (w
, LEFT_MARGIN_AREA
)
1030 + window_box_width (w
, TEXT_AREA
)
1031 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1033 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1034 else if (area
== LEFT_MARGIN_AREA
1035 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1036 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1038 /* Don't return more than the window's pixel width. */
1039 return min (x
, w
->pixel_width
);
1043 /* Return the window-relative coordinate of the right edge of display
1044 area AREA of window W. ANY_AREA means return the right edge of the
1045 whole window, to the left of the right fringe of W. */
1048 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1050 /* Don't return more than the window's pixel width. */
1051 return min (window_box_left_offset (w
, area
) + window_box_width (w
, area
),
1055 /* Return the frame-relative coordinate of the left edge of display
1056 area AREA of window W. ANY_AREA means return the left edge of the
1057 whole window, to the right of the left fringe of W. */
1060 window_box_left (struct window
*w
, enum glyph_row_area area
)
1062 struct frame
*f
= XFRAME (w
->frame
);
1065 if (w
->pseudo_window_p
)
1066 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1068 x
= (WINDOW_LEFT_EDGE_X (w
)
1069 + window_box_left_offset (w
, area
));
1075 /* Return the frame-relative coordinate of the right edge of display
1076 area AREA of window W. ANY_AREA means return the right edge of the
1077 whole window, to the left of the right fringe of W. */
1080 window_box_right (struct window
*w
, enum glyph_row_area area
)
1082 return window_box_left (w
, area
) + window_box_width (w
, area
);
1085 /* Get the bounding box of the display area AREA of window W, without
1086 mode lines, in frame-relative coordinates. ANY_AREA means the
1087 whole window, not including the left and right fringes of
1088 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1089 coordinates of the upper-left corner of the box. Return in
1090 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1093 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1094 int *box_y
, int *box_width
, int *box_height
)
1097 *box_width
= window_box_width (w
, area
);
1099 *box_height
= window_box_height (w
);
1101 *box_x
= window_box_left (w
, area
);
1104 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1105 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1106 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1110 #ifdef HAVE_WINDOW_SYSTEM
1112 /* Get the bounding box of the display area AREA of window W, without
1113 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1114 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1115 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1116 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1120 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1121 int *bottom_right_x
, int *bottom_right_y
)
1123 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1124 bottom_right_x
, bottom_right_y
);
1125 *bottom_right_x
+= *top_left_x
;
1126 *bottom_right_y
+= *top_left_y
;
1129 #endif /* HAVE_WINDOW_SYSTEM */
1131 /***********************************************************************
1133 ***********************************************************************/
1135 /* Return the bottom y-position of the line the iterator IT is in.
1136 This can modify IT's settings. */
1139 line_bottom_y (struct it
*it
)
1141 int line_height
= it
->max_ascent
+ it
->max_descent
;
1142 int line_top_y
= it
->current_y
;
1144 if (line_height
== 0)
1147 line_height
= last_height
;
1148 else if (IT_CHARPOS (*it
) < ZV
)
1150 move_it_by_lines (it
, 1);
1151 line_height
= (it
->max_ascent
|| it
->max_descent
1152 ? it
->max_ascent
+ it
->max_descent
1157 struct glyph_row
*row
= it
->glyph_row
;
1159 /* Use the default character height. */
1160 it
->glyph_row
= NULL
;
1161 it
->what
= IT_CHARACTER
;
1164 PRODUCE_GLYPHS (it
);
1165 line_height
= it
->ascent
+ it
->descent
;
1166 it
->glyph_row
= row
;
1170 return line_top_y
+ line_height
;
1173 DEFUN ("line-pixel-height", Fline_pixel_height
,
1174 Sline_pixel_height
, 0, 0, 0,
1175 doc
: /* Return height in pixels of text line in the selected window.
1177 Value is the height in pixels of the line at point. */)
1182 struct window
*w
= XWINDOW (selected_window
);
1183 struct buffer
*old_buffer
= NULL
;
1186 if (XBUFFER (w
->contents
) != current_buffer
)
1188 old_buffer
= current_buffer
;
1189 set_buffer_internal_1 (XBUFFER (w
->contents
));
1191 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1192 start_display (&it
, w
, pt
);
1193 it
.vpos
= it
.current_y
= 0;
1195 result
= make_number (line_bottom_y (&it
));
1197 set_buffer_internal_1 (old_buffer
);
1202 /* Return the default pixel height of text lines in window W. The
1203 value is the canonical height of the W frame's default font, plus
1204 any extra space required by the line-spacing variable or frame
1207 Implementation note: this ignores any line-spacing text properties
1208 put on the newline characters. This is because those properties
1209 only affect the _screen_ line ending in the newline (i.e., in a
1210 continued line, only the last screen line will be affected), which
1211 means only a small number of lines in a buffer can ever use this
1212 feature. Since this function is used to compute the default pixel
1213 equivalent of text lines in a window, we can safely ignore those
1214 few lines. For the same reasons, we ignore the line-height
1217 default_line_pixel_height (struct window
*w
)
1219 struct frame
*f
= WINDOW_XFRAME (w
);
1220 int height
= FRAME_LINE_HEIGHT (f
);
1222 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1224 struct buffer
*b
= XBUFFER (w
->contents
);
1225 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1228 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1231 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1232 height
+= XFASTINT (val
);
1233 else if (FLOATP (val
))
1235 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1242 height
+= f
->extra_line_spacing
;
1248 /* Subroutine of pos_visible_p below. Extracts a display string, if
1249 any, from the display spec given as its argument. */
1251 string_from_display_spec (Lisp_Object spec
)
1255 while (CONSP (spec
))
1257 if (STRINGP (XCAR (spec
)))
1262 else if (VECTORP (spec
))
1266 for (i
= 0; i
< ASIZE (spec
); i
++)
1268 if (STRINGP (AREF (spec
, i
)))
1269 return AREF (spec
, i
);
1278 /* Limit insanely large values of W->hscroll on frame F to the largest
1279 value that will still prevent first_visible_x and last_visible_x of
1280 'struct it' from overflowing an int. */
1282 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1284 ptrdiff_t window_hscroll
= w
->hscroll
;
1285 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1286 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1288 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1289 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1291 return window_hscroll
;
1294 /* Return true if position CHARPOS is visible in window W.
1295 CHARPOS < 0 means return info about WINDOW_END position.
1296 If visible, set *X and *Y to pixel coordinates of top left corner.
1297 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1298 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1301 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1302 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1305 void *itdata
= bidi_shelve_cache ();
1306 struct text_pos top
;
1307 bool visible_p
= false;
1308 struct buffer
*old_buffer
= NULL
;
1311 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1314 if (XBUFFER (w
->contents
) != current_buffer
)
1316 old_buffer
= current_buffer
;
1317 set_buffer_internal_1 (XBUFFER (w
->contents
));
1320 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1321 /* Scrolling a minibuffer window via scroll bar when the echo area
1322 shows long text sometimes resets the minibuffer contents behind
1324 if (CHARPOS (top
) > ZV
)
1325 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1327 /* Compute exact mode line heights. */
1328 if (WINDOW_WANTS_MODELINE_P (w
))
1330 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1331 BVAR (current_buffer
, mode_line_format
));
1333 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1334 w
->header_line_height
1335 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1336 BVAR (current_buffer
, header_line_format
));
1338 start_display (&it
, w
, top
);
1339 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1340 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1343 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
!= -1)
1344 && IT_CHARPOS (it
) >= charpos
)
1345 /* When scanning backwards under bidi iteration, move_it_to
1346 stops at or _before_ CHARPOS, because it stops at or to
1347 the _right_ of the character at CHARPOS. */
1348 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1349 && IT_CHARPOS (it
) <= charpos
)))
1351 /* We have reached CHARPOS, or passed it. How the call to
1352 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1353 or covered by a display property, move_it_to stops at the end
1354 of the invisible text, to the right of CHARPOS. (ii) If
1355 CHARPOS is in a display vector, move_it_to stops on its last
1357 int top_x
= it
.current_x
;
1358 int top_y
= it
.current_y
;
1359 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1362 void *save_it_data
= NULL
;
1364 /* Calling line_bottom_y may change it.method, it.position, etc. */
1365 SAVE_IT (save_it
, it
, save_it_data
);
1367 bottom_y
= line_bottom_y (&it
);
1368 if (top_y
< window_top_y
)
1369 visible_p
= bottom_y
> window_top_y
;
1370 else if (top_y
< it
.last_visible_y
)
1372 if (bottom_y
>= it
.last_visible_y
1373 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1374 && IT_CHARPOS (it
) < charpos
)
1376 /* When the last line of the window is scanned backwards
1377 under bidi iteration, we could be duped into thinking
1378 that we have passed CHARPOS, when in fact move_it_to
1379 simply stopped short of CHARPOS because it reached
1380 last_visible_y. To see if that's what happened, we call
1381 move_it_to again with a slightly larger vertical limit,
1382 and see if it actually moved vertically; if it did, we
1383 didn't really reach CHARPOS, which is beyond window end. */
1384 /* Why 10? because we don't know how many canonical lines
1385 will the height of the next line(s) be. So we guess. */
1386 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1388 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1389 MOVE_TO_POS
| MOVE_TO_Y
);
1390 if (it
.current_y
> top_y
)
1394 RESTORE_IT (&it
, &save_it
, save_it_data
);
1397 if (it
.method
== GET_FROM_DISPLAY_VECTOR
)
1399 /* We stopped on the last glyph of a display vector.
1400 Try and recompute. Hack alert! */
1401 if (charpos
< 2 || top
.charpos
>= charpos
)
1402 top_x
= it
.glyph_row
->x
;
1405 struct it it2
, it2_prev
;
1406 /* The idea is to get to the previous buffer
1407 position, consume the character there, and use
1408 the pixel coordinates we get after that. But if
1409 the previous buffer position is also displayed
1410 from a display vector, we need to consume all of
1411 the glyphs from that display vector. */
1412 start_display (&it2
, w
, top
);
1413 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1414 /* If we didn't get to CHARPOS - 1, there's some
1415 replacing display property at that position, and
1416 we stopped after it. That is exactly the place
1417 whose coordinates we want. */
1418 if (IT_CHARPOS (it2
) != charpos
- 1)
1422 /* Iterate until we get out of the display
1423 vector that displays the character at
1426 get_next_display_element (&it2
);
1427 PRODUCE_GLYPHS (&it2
);
1429 set_iterator_to_next (&it2
, true);
1430 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1431 && IT_CHARPOS (it2
) < charpos
);
1433 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1434 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1435 top_x
= it
.glyph_row
->x
;
1438 top_x
= it2_prev
.current_x
;
1439 top_y
= it2_prev
.current_y
;
1443 else if (IT_CHARPOS (it
) != charpos
)
1445 Lisp_Object cpos
= make_number (charpos
);
1446 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1447 Lisp_Object string
= string_from_display_spec (spec
);
1448 struct text_pos tpos
;
1449 bool newline_in_string
1451 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1453 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1454 bool replacing_spec_p
1456 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1457 charpos
, FRAME_WINDOW_P (it
.f
)));
1458 /* The tricky code below is needed because there's a
1459 discrepancy between move_it_to and how we set cursor
1460 when PT is at the beginning of a portion of text
1461 covered by a display property or an overlay with a
1462 display property, or the display line ends in a
1463 newline from a display string. move_it_to will stop
1464 _after_ such display strings, whereas
1465 set_cursor_from_row conspires with cursor_row_p to
1466 place the cursor on the first glyph produced from the
1469 /* We have overshoot PT because it is covered by a
1470 display property that replaces the text it covers.
1471 If the string includes embedded newlines, we are also
1472 in the wrong display line. Backtrack to the correct
1473 line, where the display property begins. */
1474 if (replacing_spec_p
)
1476 Lisp_Object startpos
, endpos
;
1477 EMACS_INT start
, end
;
1480 /* Find the first and the last buffer positions
1481 covered by the display string. */
1483 Fnext_single_char_property_change (cpos
, Qdisplay
,
1486 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1488 start
= XFASTINT (startpos
);
1489 end
= XFASTINT (endpos
);
1490 /* Move to the last buffer position before the
1491 display property. */
1492 start_display (&it3
, w
, top
);
1493 if (start
> CHARPOS (top
))
1494 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1495 /* Move forward one more line if the position before
1496 the display string is a newline or if it is the
1497 rightmost character on a line that is
1498 continued or word-wrapped. */
1499 if (it3
.method
== GET_FROM_BUFFER
1501 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1502 move_it_by_lines (&it3
, 1);
1503 else if (move_it_in_display_line_to (&it3
, -1,
1507 == MOVE_LINE_CONTINUED
)
1509 move_it_by_lines (&it3
, 1);
1510 /* When we are under word-wrap, the #$@%!
1511 move_it_by_lines moves 2 lines, so we need to
1513 if (it3
.line_wrap
== WORD_WRAP
)
1514 move_it_by_lines (&it3
, -1);
1517 /* Record the vertical coordinate of the display
1518 line where we wound up. */
1519 top_y
= it3
.current_y
;
1522 /* When characters are reordered for display,
1523 the character displayed to the left of the
1524 display string could be _after_ the display
1525 property in the logical order. Use the
1526 smallest vertical position of these two. */
1527 start_display (&it3
, w
, top
);
1528 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1529 if (it3
.current_y
< top_y
)
1530 top_y
= it3
.current_y
;
1532 /* Move from the top of the window to the beginning
1533 of the display line where the display string
1535 start_display (&it3
, w
, top
);
1536 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1537 /* If it3_moved stays false after the 'while' loop
1538 below, that means we already were at a newline
1539 before the loop (e.g., the display string begins
1540 with a newline), so we don't need to (and cannot)
1541 inspect the glyphs of it3.glyph_row, because
1542 PRODUCE_GLYPHS will not produce anything for a
1543 newline, and thus it3.glyph_row stays at its
1544 stale content it got at top of the window. */
1545 bool it3_moved
= false;
1546 /* Finally, advance the iterator until we hit the
1547 first display element whose character position is
1548 CHARPOS, or until the first newline from the
1549 display string, which signals the end of the
1551 while (get_next_display_element (&it3
))
1553 PRODUCE_GLYPHS (&it3
);
1554 if (IT_CHARPOS (it3
) == charpos
1555 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1558 set_iterator_to_next (&it3
, false);
1560 top_x
= it3
.current_x
- it3
.pixel_width
;
1561 /* Normally, we would exit the above loop because we
1562 found the display element whose character
1563 position is CHARPOS. For the contingency that we
1564 didn't, and stopped at the first newline from the
1565 display string, move back over the glyphs
1566 produced from the string, until we find the
1567 rightmost glyph not from the string. */
1569 && newline_in_string
1570 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1572 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1573 + it3
.glyph_row
->used
[TEXT_AREA
];
1575 while (EQ ((g
- 1)->object
, string
))
1578 top_x
-= g
->pixel_width
;
1580 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1581 + it3
.glyph_row
->used
[TEXT_AREA
]);
1587 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1588 *rtop
= max (0, window_top_y
- top_y
);
1589 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1590 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1591 - max (top_y
, window_top_y
)));
1593 if (it
.bidi_it
.paragraph_dir
== R2L
)
1599 /* Either we were asked to provide info about WINDOW_END, or
1600 CHARPOS is in the partially visible glyph row at end of
1603 void *it2data
= NULL
;
1605 SAVE_IT (it2
, it
, it2data
);
1606 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1607 move_it_by_lines (&it
, 1);
1608 if (charpos
< IT_CHARPOS (it
)
1609 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1612 RESTORE_IT (&it2
, &it2
, it2data
);
1613 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1615 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1616 *rtop
= max (0, -it2
.current_y
);
1617 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1618 - it
.last_visible_y
));
1619 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1621 - max (it2
.current_y
,
1622 WINDOW_HEADER_LINE_HEIGHT (w
))));
1624 if (it2
.bidi_it
.paragraph_dir
== R2L
)
1628 bidi_unshelve_cache (it2data
, true);
1630 bidi_unshelve_cache (itdata
, false);
1633 set_buffer_internal_1 (old_buffer
);
1639 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1640 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1641 /* For lines in an R2L paragraph, we need to mirror the X pixel
1642 coordinate wrt the text area. For the reasons, see the
1643 commentary in buffer_posn_from_coords and the explanation of
1644 the geometry used by the move_it_* functions at the end of
1645 the large commentary near the beginning of this file. */
1647 *x
= window_box_width (w
, TEXT_AREA
) - *x
- 1;
1651 /* Debugging code. */
1653 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1654 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1656 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1663 /* Return the next character from STR. Return in *LEN the length of
1664 the character. This is like STRING_CHAR_AND_LENGTH but never
1665 returns an invalid character. If we find one, we return a `?', but
1666 with the length of the invalid character. */
1669 string_char_and_length (const unsigned char *str
, int *len
)
1673 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1674 if (!CHAR_VALID_P (c
))
1675 /* We may not change the length here because other places in Emacs
1676 don't use this function, i.e. they silently accept invalid
1685 /* Given a position POS containing a valid character and byte position
1686 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1688 static struct text_pos
1689 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1691 eassert (STRINGP (string
) && nchars
>= 0);
1693 if (STRING_MULTIBYTE (string
))
1695 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1700 string_char_and_length (p
, &len
);
1703 BYTEPOS (pos
) += len
;
1707 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1713 /* Value is the text position, i.e. character and byte position,
1714 for character position CHARPOS in STRING. */
1716 static struct text_pos
1717 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1719 struct text_pos pos
;
1720 eassert (STRINGP (string
));
1721 eassert (charpos
>= 0);
1722 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1727 /* Value is a text position, i.e. character and byte position, for
1728 character position CHARPOS in C string S. MULTIBYTE_P
1729 means recognize multibyte characters. */
1731 static struct text_pos
1732 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1734 struct text_pos pos
;
1736 eassert (s
!= NULL
);
1737 eassert (charpos
>= 0);
1743 SET_TEXT_POS (pos
, 0, 0);
1746 string_char_and_length ((const unsigned char *) s
, &len
);
1749 BYTEPOS (pos
) += len
;
1753 SET_TEXT_POS (pos
, charpos
, charpos
);
1759 /* Value is the number of characters in C string S. MULTIBYTE_P
1760 means recognize multibyte characters. */
1763 number_of_chars (const char *s
, bool multibyte_p
)
1769 ptrdiff_t rest
= strlen (s
);
1771 const unsigned char *p
= (const unsigned char *) s
;
1773 for (nchars
= 0; rest
> 0; ++nchars
)
1775 string_char_and_length (p
, &len
);
1776 rest
-= len
, p
+= len
;
1780 nchars
= strlen (s
);
1786 /* Compute byte position NEWPOS->bytepos corresponding to
1787 NEWPOS->charpos. POS is a known position in string STRING.
1788 NEWPOS->charpos must be >= POS.charpos. */
1791 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1793 eassert (STRINGP (string
));
1794 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1796 if (STRING_MULTIBYTE (string
))
1797 *newpos
= string_pos_nchars_ahead (pos
, string
,
1798 CHARPOS (*newpos
) - CHARPOS (pos
));
1800 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1804 Return an estimation of the pixel height of mode or header lines on
1805 frame F. FACE_ID specifies what line's height to estimate. */
1808 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1810 #ifdef HAVE_WINDOW_SYSTEM
1811 if (FRAME_WINDOW_P (f
))
1813 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1815 /* This function is called so early when Emacs starts that the face
1816 cache and mode line face are not yet initialized. */
1817 if (FRAME_FACE_CACHE (f
))
1819 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1823 height
= normal_char_height (face
->font
, -1);
1824 if (face
->box_line_width
> 0)
1825 height
+= 2 * face
->box_line_width
;
1836 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1837 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1838 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP, do
1839 not force the value into range. */
1842 pixel_to_glyph_coords (struct frame
*f
, int pix_x
, int pix_y
, int *x
, int *y
,
1843 NativeRectangle
*bounds
, bool noclip
)
1846 #ifdef HAVE_WINDOW_SYSTEM
1847 if (FRAME_WINDOW_P (f
))
1849 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1850 even for negative values. */
1852 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1854 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1856 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1857 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1860 STORE_NATIVE_RECT (*bounds
,
1861 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1862 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1863 FRAME_COLUMN_WIDTH (f
) - 1,
1864 FRAME_LINE_HEIGHT (f
) - 1);
1866 /* PXW: Should we clip pixels before converting to columns/lines? */
1871 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1872 pix_x
= FRAME_TOTAL_COLS (f
);
1876 else if (pix_y
> FRAME_TOTAL_LINES (f
))
1877 pix_y
= FRAME_TOTAL_LINES (f
);
1887 /* Find the glyph under window-relative coordinates X/Y in window W.
1888 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1889 strings. Return in *HPOS and *VPOS the row and column number of
1890 the glyph found. Return in *AREA the glyph area containing X.
1891 Value is a pointer to the glyph found or null if X/Y is not on
1892 text, or we can't tell because W's current matrix is not up to
1895 static struct glyph
*
1896 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1897 int *dx
, int *dy
, int *area
)
1899 struct glyph
*glyph
, *end
;
1900 struct glyph_row
*row
= NULL
;
1903 /* Find row containing Y. Give up if some row is not enabled. */
1904 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1906 row
= MATRIX_ROW (w
->current_matrix
, i
);
1907 if (!row
->enabled_p
)
1909 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1916 /* Give up if Y is not in the window. */
1917 if (i
== w
->current_matrix
->nrows
)
1920 /* Get the glyph area containing X. */
1921 if (w
->pseudo_window_p
)
1928 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1930 *area
= LEFT_MARGIN_AREA
;
1931 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1933 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1936 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1940 *area
= RIGHT_MARGIN_AREA
;
1941 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1945 /* Find glyph containing X. */
1946 glyph
= row
->glyphs
[*area
];
1947 end
= glyph
+ row
->used
[*area
];
1949 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1951 x
-= glyph
->pixel_width
;
1961 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1964 *hpos
= glyph
- row
->glyphs
[*area
];
1968 /* Convert frame-relative x/y to coordinates relative to window W.
1969 Takes pseudo-windows into account. */
1972 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1974 if (w
->pseudo_window_p
)
1976 /* A pseudo-window is always full-width, and starts at the
1977 left edge of the frame, plus a frame border. */
1978 struct frame
*f
= XFRAME (w
->frame
);
1979 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1980 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1984 *x
-= WINDOW_LEFT_EDGE_X (w
);
1985 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1989 #ifdef HAVE_WINDOW_SYSTEM
1992 Return in RECTS[] at most N clipping rectangles for glyph string S.
1993 Return the number of stored rectangles. */
1996 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2003 if (s
->row
->full_width_p
)
2005 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2006 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2007 if (s
->row
->mode_line_p
)
2008 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
) - WINDOW_RIGHT_DIVIDER_WIDTH (s
->w
);
2010 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
);
2012 /* Unless displaying a mode or menu bar line, which are always
2013 fully visible, clip to the visible part of the row. */
2014 if (s
->w
->pseudo_window_p
)
2015 r
.height
= s
->row
->visible_height
;
2017 r
.height
= s
->height
;
2021 /* This is a text line that may be partially visible. */
2022 r
.x
= window_box_left (s
->w
, s
->area
);
2023 r
.width
= window_box_width (s
->w
, s
->area
);
2024 r
.height
= s
->row
->visible_height
;
2028 if (r
.x
< s
->clip_head
->x
)
2030 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2031 r
.width
-= s
->clip_head
->x
- r
.x
;
2034 r
.x
= s
->clip_head
->x
;
2037 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2039 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2040 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2045 /* If S draws overlapping rows, it's sufficient to use the top and
2046 bottom of the window for clipping because this glyph string
2047 intentionally draws over other lines. */
2048 if (s
->for_overlaps
)
2050 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2051 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2053 /* Alas, the above simple strategy does not work for the
2054 environments with anti-aliased text: if the same text is
2055 drawn onto the same place multiple times, it gets thicker.
2056 If the overlap we are processing is for the erased cursor, we
2057 take the intersection with the rectangle of the cursor. */
2058 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2060 XRectangle rc
, r_save
= r
;
2062 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2063 rc
.y
= s
->w
->phys_cursor
.y
;
2064 rc
.width
= s
->w
->phys_cursor_width
;
2065 rc
.height
= s
->w
->phys_cursor_height
;
2067 x_intersect_rectangles (&r_save
, &rc
, &r
);
2072 /* Don't use S->y for clipping because it doesn't take partially
2073 visible lines into account. For example, it can be negative for
2074 partially visible lines at the top of a window. */
2075 if (!s
->row
->full_width_p
2076 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2077 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2079 r
.y
= max (0, s
->row
->y
);
2082 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2084 /* If drawing the cursor, don't let glyph draw outside its
2085 advertised boundaries. Cleartype does this under some circumstances. */
2086 if (s
->hl
== DRAW_CURSOR
)
2088 struct glyph
*glyph
= s
->first_glyph
;
2093 if (r
.width
>= s
->x
- r
.x
)
2094 r
.width
-= s
->x
- r
.x
;
2095 else /* R2L hscrolled row with cursor outside text area */
2099 r
.width
= min (r
.width
, glyph
->pixel_width
);
2101 /* If r.y is below window bottom, ensure that we still see a cursor. */
2102 height
= min (glyph
->ascent
+ glyph
->descent
,
2103 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2104 max_y
= window_text_bottom_y (s
->w
) - height
;
2105 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2106 if (s
->ybase
- glyph
->ascent
> max_y
)
2113 /* Don't draw cursor glyph taller than our actual glyph. */
2114 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2115 if (height
< r
.height
)
2117 max_y
= r
.y
+ r
.height
;
2118 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2119 r
.height
= min (max_y
- r
.y
, height
);
2126 XRectangle r_save
= r
;
2128 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2132 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2133 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2135 #ifdef CONVERT_FROM_XRECT
2136 CONVERT_FROM_XRECT (r
, *rects
);
2144 /* If we are processing overlapping and allowed to return
2145 multiple clipping rectangles, we exclude the row of the glyph
2146 string from the clipping rectangle. This is to avoid drawing
2147 the same text on the environment with anti-aliasing. */
2148 #ifdef CONVERT_FROM_XRECT
2151 XRectangle
*rs
= rects
;
2153 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2155 if (s
->for_overlaps
& OVERLAPS_PRED
)
2158 if (r
.y
+ r
.height
> row_y
)
2161 rs
[i
].height
= row_y
- r
.y
;
2167 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2170 if (r
.y
< row_y
+ s
->row
->visible_height
)
2172 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2174 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2175 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2184 #ifdef CONVERT_FROM_XRECT
2185 for (i
= 0; i
< n
; i
++)
2186 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2193 Return in *NR the clipping rectangle for glyph string S. */
2196 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2198 get_glyph_string_clip_rects (s
, nr
, 1);
2203 Return the position and height of the phys cursor in window W.
2204 Set w->phys_cursor_width to width of phys cursor.
2208 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2209 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2211 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2212 int x
, y
, wd
, h
, h0
, y0
, ascent
;
2214 /* Compute the width of the rectangle to draw. If on a stretch
2215 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2216 rectangle as wide as the glyph, but use a canonical character
2218 wd
= glyph
->pixel_width
;
2220 x
= w
->phys_cursor
.x
;
2227 if (glyph
->type
== STRETCH_GLYPH
2228 && !x_stretch_cursor_p
)
2229 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2230 w
->phys_cursor_width
= wd
;
2232 /* Don't let the hollow cursor glyph descend below the glyph row's
2233 ascent value, lest the hollow cursor looks funny. */
2234 y
= w
->phys_cursor
.y
;
2235 ascent
= row
->ascent
;
2236 if (row
->ascent
< glyph
->ascent
)
2238 y
=- glyph
->ascent
- row
->ascent
;
2239 ascent
= glyph
->ascent
;
2242 /* If y is below window bottom, ensure that we still see a cursor. */
2243 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2245 h
= max (h0
, ascent
+ glyph
->descent
);
2246 h0
= min (h0
, ascent
+ glyph
->descent
);
2248 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2251 h
= max (h
- (y0
- y
) + 1, h0
);
2256 y0
= window_text_bottom_y (w
) - h0
;
2264 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2265 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2270 * Remember which glyph the mouse is over.
2274 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2278 struct glyph_row
*r
, *gr
, *end_row
;
2279 enum window_part part
;
2280 enum glyph_row_area area
;
2281 int x
, y
, width
, height
;
2283 /* Try to determine frame pixel position and size of the glyph under
2284 frame pixel coordinates X/Y on frame F. */
2286 if (window_resize_pixelwise
)
2291 else if (!f
->glyphs_initialized_p
2292 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, false),
2295 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2296 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2300 w
= XWINDOW (window
);
2301 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2302 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2304 x
= window_relative_x_coord (w
, part
, gx
);
2305 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2307 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2308 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2310 if (w
->pseudo_window_p
)
2313 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2319 case ON_LEFT_MARGIN
:
2320 area
= LEFT_MARGIN_AREA
;
2323 case ON_RIGHT_MARGIN
:
2324 area
= RIGHT_MARGIN_AREA
;
2327 case ON_HEADER_LINE
:
2329 gr
= (part
== ON_HEADER_LINE
2330 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2331 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2334 goto text_glyph_row_found
;
2341 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2342 if (r
->y
+ r
->height
> y
)
2348 text_glyph_row_found
:
2351 struct glyph
*g
= gr
->glyphs
[area
];
2352 struct glyph
*end
= g
+ gr
->used
[area
];
2354 height
= gr
->height
;
2355 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2356 if (gx
+ g
->pixel_width
> x
)
2361 if (g
->type
== IMAGE_GLYPH
)
2363 /* Don't remember when mouse is over image, as
2364 image may have hot-spots. */
2365 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2368 width
= g
->pixel_width
;
2372 /* Use nominal char spacing at end of line. */
2374 gx
+= (x
/ width
) * width
;
2377 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2379 gx
+= window_box_left_offset (w
, area
);
2380 /* Don't expand over the modeline to make sure the vertical
2381 drag cursor is shown early enough. */
2382 height
= min (height
,
2383 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2388 /* Use nominal line height at end of window. */
2389 gx
= (x
/ width
) * width
;
2391 gy
+= (y
/ height
) * height
;
2392 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2393 /* See comment above. */
2394 height
= min (height
,
2395 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2399 case ON_LEFT_FRINGE
:
2400 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2401 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2402 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2403 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2406 case ON_RIGHT_FRINGE
:
2407 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2408 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2409 : window_box_right_offset (w
, TEXT_AREA
));
2410 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
2411 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
2412 && !WINDOW_RIGHTMOST_P (w
))
2413 if (gx
< WINDOW_PIXEL_WIDTH (w
) - width
)
2414 /* Make sure the vertical border can get her own glyph to the
2415 right of the one we build here. */
2416 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
) - width
;
2418 width
= WINDOW_PIXEL_WIDTH (w
) - gx
;
2420 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2424 case ON_VERTICAL_BORDER
:
2425 gx
= WINDOW_PIXEL_WIDTH (w
) - width
;
2428 case ON_VERTICAL_SCROLL_BAR
:
2429 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2431 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2432 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2433 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2435 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2439 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2440 if (r
->y
+ r
->height
> y
)
2447 height
= gr
->height
;
2450 /* Use nominal line height at end of window. */
2452 gy
+= (y
/ height
) * height
;
2456 case ON_RIGHT_DIVIDER
:
2457 gx
= WINDOW_PIXEL_WIDTH (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2458 width
= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2460 /* The bottom divider prevails. */
2461 height
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2464 case ON_BOTTOM_DIVIDER
:
2466 width
= WINDOW_PIXEL_WIDTH (w
);
2467 gy
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2468 height
= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2474 /* If there is no glyph under the mouse, then we divide the screen
2475 into a grid of the smallest glyph in the frame, and use that
2478 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2479 round down even for negative values. */
2485 gx
= (gx
/ width
) * width
;
2486 gy
= (gy
/ height
) * height
;
2492 gx
+= WINDOW_LEFT_EDGE_X (w
);
2493 gy
+= WINDOW_TOP_EDGE_Y (w
);
2496 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2498 /* Visible feedback for debugging. */
2499 #if false && defined HAVE_X_WINDOWS
2500 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2501 f
->output_data
.x
->normal_gc
,
2502 gx
, gy
, width
, height
);
2507 #endif /* HAVE_WINDOW_SYSTEM */
2510 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2513 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2514 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2516 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2519 /***********************************************************************
2520 Lisp form evaluation
2521 ***********************************************************************/
2523 /* Error handler for safe_eval and safe_call. */
2526 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2528 add_to_log ("Error during redisplay: %S signaled %S",
2529 Flist (nargs
, args
), arg
);
2533 /* Call function FUNC with the rest of NARGS - 1 arguments
2534 following. Return the result, or nil if something went
2535 wrong. Prevent redisplay during the evaluation. */
2538 safe__call (bool inhibit_quit
, ptrdiff_t nargs
, Lisp_Object func
, va_list ap
)
2542 if (inhibit_eval_during_redisplay
)
2547 ptrdiff_t count
= SPECPDL_INDEX ();
2550 SAFE_ALLOCA_LISP (args
, nargs
);
2553 for (i
= 1; i
< nargs
; i
++)
2554 args
[i
] = va_arg (ap
, Lisp_Object
);
2556 specbind (Qinhibit_redisplay
, Qt
);
2558 specbind (Qinhibit_quit
, Qt
);
2559 /* Use Qt to ensure debugger does not run,
2560 so there is no possibility of wanting to redisplay. */
2561 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2564 val
= unbind_to (count
, val
);
2571 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2576 va_start (ap
, func
);
2577 retval
= safe__call (false, nargs
, func
, ap
);
2582 /* Call function FN with one argument ARG.
2583 Return the result, or nil if something went wrong. */
2586 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2588 return safe_call (2, fn
, arg
);
2592 safe__call1 (bool inhibit_quit
, Lisp_Object fn
, ...)
2598 retval
= safe__call (inhibit_quit
, 2, fn
, ap
);
2604 safe_eval (Lisp_Object sexpr
)
2606 return safe__call1 (false, Qeval
, sexpr
);
2610 safe__eval (bool inhibit_quit
, Lisp_Object sexpr
)
2612 return safe__call1 (inhibit_quit
, Qeval
, sexpr
);
2615 /* Call function FN with two arguments ARG1 and ARG2.
2616 Return the result, or nil if something went wrong. */
2619 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2621 return safe_call (3, fn
, arg1
, arg2
);
2626 /***********************************************************************
2628 ***********************************************************************/
2630 /* Define CHECK_IT to perform sanity checks on iterators.
2631 This is for debugging. It is too slow to do unconditionally. */
2634 CHECK_IT (struct it
*it
)
2637 if (it
->method
== GET_FROM_STRING
)
2639 eassert (STRINGP (it
->string
));
2640 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2644 eassert (IT_STRING_CHARPOS (*it
) < 0);
2645 if (it
->method
== GET_FROM_BUFFER
)
2647 /* Check that character and byte positions agree. */
2648 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2653 eassert (it
->current
.dpvec_index
>= 0);
2655 eassert (it
->current
.dpvec_index
< 0);
2660 /* Check that the window end of window W is what we expect it
2661 to be---the last row in the current matrix displaying text. */
2664 CHECK_WINDOW_END (struct window
*w
)
2666 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2667 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2669 struct glyph_row
*row
;
2670 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2672 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2673 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2678 /***********************************************************************
2679 Iterator initialization
2680 ***********************************************************************/
2682 /* Initialize IT for displaying current_buffer in window W, starting
2683 at character position CHARPOS. CHARPOS < 0 means that no buffer
2684 position is specified which is useful when the iterator is assigned
2685 a position later. BYTEPOS is the byte position corresponding to
2688 If ROW is not null, calls to produce_glyphs with IT as parameter
2689 will produce glyphs in that row.
2691 BASE_FACE_ID is the id of a base face to use. It must be one of
2692 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2693 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2694 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2696 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2697 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2698 will be initialized to use the corresponding mode line glyph row of
2699 the desired matrix of W. */
2702 init_iterator (struct it
*it
, struct window
*w
,
2703 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2704 struct glyph_row
*row
, enum face_id base_face_id
)
2706 enum face_id remapped_base_face_id
= base_face_id
;
2708 /* Some precondition checks. */
2709 eassert (w
!= NULL
&& it
!= NULL
);
2710 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2713 /* If face attributes have been changed since the last redisplay,
2714 free realized faces now because they depend on face definitions
2715 that might have changed. Don't free faces while there might be
2716 desired matrices pending which reference these faces. */
2717 if (!inhibit_free_realized_faces
)
2721 face_change
= false;
2722 free_all_realized_faces (Qnil
);
2724 else if (XFRAME (w
->frame
)->face_change
)
2726 XFRAME (w
->frame
)->face_change
= 0;
2727 free_all_realized_faces (w
->frame
);
2731 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2732 if (! NILP (Vface_remapping_alist
))
2733 remapped_base_face_id
2734 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2736 /* Use one of the mode line rows of W's desired matrix if
2740 if (base_face_id
== MODE_LINE_FACE_ID
2741 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2742 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2743 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2744 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2747 /* Clear IT, and set it->object and other IT's Lisp objects to Qnil.
2748 Other parts of redisplay rely on that. */
2749 memclear (it
, sizeof *it
);
2750 it
->current
.overlay_string_index
= -1;
2751 it
->current
.dpvec_index
= -1;
2752 it
->base_face_id
= remapped_base_face_id
;
2753 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2754 it
->paragraph_embedding
= L2R
;
2757 /* The window in which we iterate over current_buffer: */
2758 XSETWINDOW (it
->window
, w
);
2760 it
->f
= XFRAME (w
->frame
);
2764 /* Extra space between lines (on window systems only). */
2765 if (base_face_id
== DEFAULT_FACE_ID
2766 && FRAME_WINDOW_P (it
->f
))
2768 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2769 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2770 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2771 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2772 * FRAME_LINE_HEIGHT (it
->f
));
2773 else if (it
->f
->extra_line_spacing
> 0)
2774 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2777 /* If realized faces have been removed, e.g. because of face
2778 attribute changes of named faces, recompute them. When running
2779 in batch mode, the face cache of the initial frame is null. If
2780 we happen to get called, make a dummy face cache. */
2781 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2782 init_frame_faces (it
->f
);
2783 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2784 recompute_basic_faces (it
->f
);
2786 it
->override_ascent
= -1;
2788 /* Are control characters displayed as `^C'? */
2789 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2791 /* -1 means everything between a CR and the following line end
2792 is invisible. >0 means lines indented more than this value are
2794 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2796 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2798 : (!NILP (BVAR (current_buffer
, selective_display
))
2800 it
->selective_display_ellipsis_p
2801 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2803 /* Display table to use. */
2804 it
->dp
= window_display_table (w
);
2806 /* Are multibyte characters enabled in current_buffer? */
2807 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2809 /* Get the position at which the redisplay_end_trigger hook should
2810 be run, if it is to be run at all. */
2811 if (MARKERP (w
->redisplay_end_trigger
)
2812 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2813 it
->redisplay_end_trigger_charpos
2814 = marker_position (w
->redisplay_end_trigger
);
2815 else if (INTEGERP (w
->redisplay_end_trigger
))
2816 it
->redisplay_end_trigger_charpos
2817 = clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
),
2820 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2822 /* Are lines in the display truncated? */
2824 it
->line_wrap
= TRUNCATE
;
2825 if (base_face_id
== DEFAULT_FACE_ID
2827 && (WINDOW_FULL_WIDTH_P (it
->w
)
2828 || NILP (Vtruncate_partial_width_windows
)
2829 || (INTEGERP (Vtruncate_partial_width_windows
)
2830 /* PXW: Shall we do something about this? */
2831 && (XINT (Vtruncate_partial_width_windows
)
2832 <= WINDOW_TOTAL_COLS (it
->w
))))
2833 && NILP (BVAR (current_buffer
, truncate_lines
)))
2834 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2835 ? WINDOW_WRAP
: WORD_WRAP
;
2837 /* Get dimensions of truncation and continuation glyphs. These are
2838 displayed as fringe bitmaps under X, but we need them for such
2839 frames when the fringes are turned off. But leave the dimensions
2840 zero for tooltip frames, as these glyphs look ugly there and also
2841 sabotage calculations of tooltip dimensions in x-show-tip. */
2842 #ifdef HAVE_WINDOW_SYSTEM
2843 if (!(FRAME_WINDOW_P (it
->f
)
2844 && FRAMEP (tip_frame
)
2845 && it
->f
== XFRAME (tip_frame
)))
2848 if (it
->line_wrap
== TRUNCATE
)
2850 /* We will need the truncation glyph. */
2851 eassert (it
->glyph_row
== NULL
);
2852 produce_special_glyphs (it
, IT_TRUNCATION
);
2853 it
->truncation_pixel_width
= it
->pixel_width
;
2857 /* We will need the continuation glyph. */
2858 eassert (it
->glyph_row
== NULL
);
2859 produce_special_glyphs (it
, IT_CONTINUATION
);
2860 it
->continuation_pixel_width
= it
->pixel_width
;
2864 /* Reset these values to zero because the produce_special_glyphs
2865 above has changed them. */
2866 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2867 it
->phys_ascent
= it
->phys_descent
= 0;
2869 /* Set this after getting the dimensions of truncation and
2870 continuation glyphs, so that we don't produce glyphs when calling
2871 produce_special_glyphs, above. */
2872 it
->glyph_row
= row
;
2873 it
->area
= TEXT_AREA
;
2875 /* Get the dimensions of the display area. The display area
2876 consists of the visible window area plus a horizontally scrolled
2877 part to the left of the window. All x-values are relative to the
2878 start of this total display area. */
2879 if (base_face_id
!= DEFAULT_FACE_ID
)
2881 /* Mode lines, menu bar in terminal frames. */
2882 it
->first_visible_x
= 0;
2883 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2888 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2889 it
->last_visible_x
= (it
->first_visible_x
2890 + window_box_width (w
, TEXT_AREA
));
2892 /* If we truncate lines, leave room for the truncation glyph(s) at
2893 the right margin. Otherwise, leave room for the continuation
2894 glyph(s). Done only if the window has no right fringe. */
2895 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
2897 if (it
->line_wrap
== TRUNCATE
)
2898 it
->last_visible_x
-= it
->truncation_pixel_width
;
2900 it
->last_visible_x
-= it
->continuation_pixel_width
;
2903 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2904 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2907 /* Leave room for a border glyph. */
2908 if (!FRAME_WINDOW_P (it
->f
)
2909 && !WINDOW_RIGHTMOST_P (it
->w
))
2910 it
->last_visible_x
-= 1;
2912 it
->last_visible_y
= window_text_bottom_y (w
);
2914 /* For mode lines and alike, arrange for the first glyph having a
2915 left box line if the face specifies a box. */
2916 if (base_face_id
!= DEFAULT_FACE_ID
)
2920 it
->face_id
= remapped_base_face_id
;
2922 /* If we have a boxed mode line, make the first character appear
2923 with a left box line. */
2924 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2925 if (face
&& face
->box
!= FACE_NO_BOX
)
2926 it
->start_of_box_run_p
= true;
2929 /* If a buffer position was specified, set the iterator there,
2930 getting overlays and face properties from that position. */
2931 if (charpos
>= BUF_BEG (current_buffer
))
2933 it
->stop_charpos
= charpos
;
2934 it
->end_charpos
= ZV
;
2935 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2936 IT_CHARPOS (*it
) = charpos
;
2937 IT_BYTEPOS (*it
) = bytepos
;
2939 /* We will rely on `reseat' to set this up properly, via
2940 handle_face_prop. */
2941 it
->face_id
= it
->base_face_id
;
2943 it
->start
= it
->current
;
2944 /* Do we need to reorder bidirectional text? Not if this is a
2945 unibyte buffer: by definition, none of the single-byte
2946 characters are strong R2L, so no reordering is needed. And
2947 bidi.c doesn't support unibyte buffers anyway. Also, don't
2948 reorder while we are loading loadup.el, since the tables of
2949 character properties needed for reordering are not yet
2953 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2956 /* If we are to reorder bidirectional text, init the bidi
2960 /* Since we don't know at this point whether there will be
2961 any R2L lines in the window, we reserve space for
2962 truncation/continuation glyphs even if only the left
2963 fringe is absent. */
2964 if (base_face_id
== DEFAULT_FACE_ID
2965 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
2966 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
2968 if (it
->line_wrap
== TRUNCATE
)
2969 it
->last_visible_x
-= it
->truncation_pixel_width
;
2971 it
->last_visible_x
-= it
->continuation_pixel_width
;
2973 /* Note the paragraph direction that this buffer wants to
2975 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2977 it
->paragraph_embedding
= L2R
;
2978 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2980 it
->paragraph_embedding
= R2L
;
2982 it
->paragraph_embedding
= NEUTRAL_DIR
;
2983 bidi_unshelve_cache (NULL
, false);
2984 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2988 /* Compute faces etc. */
2989 reseat (it
, it
->current
.pos
, true);
2996 /* Initialize IT for the display of window W with window start POS. */
2999 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
3001 struct glyph_row
*row
;
3002 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
3004 row
= w
->desired_matrix
->rows
+ first_vpos
;
3005 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
3006 it
->first_vpos
= first_vpos
;
3008 /* Don't reseat to previous visible line start if current start
3009 position is in a string or image. */
3010 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
3012 int first_y
= it
->current_y
;
3014 /* If window start is not at a line start, skip forward to POS to
3015 get the correct continuation lines width. */
3016 bool start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3017 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3018 if (!start_at_line_beg_p
)
3022 reseat_at_previous_visible_line_start (it
);
3023 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3025 new_x
= it
->current_x
+ it
->pixel_width
;
3027 /* If lines are continued, this line may end in the middle
3028 of a multi-glyph character (e.g. a control character
3029 displayed as \003, or in the middle of an overlay
3030 string). In this case move_it_to above will not have
3031 taken us to the start of the continuation line but to the
3032 end of the continued line. */
3033 if (it
->current_x
> 0
3034 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3035 && (/* And glyph doesn't fit on the line. */
3036 new_x
> it
->last_visible_x
3037 /* Or it fits exactly and we're on a window
3039 || (new_x
== it
->last_visible_x
3040 && FRAME_WINDOW_P (it
->f
)
3041 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3042 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3043 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3045 if ((it
->current
.dpvec_index
>= 0
3046 || it
->current
.overlay_string_index
>= 0)
3047 /* If we are on a newline from a display vector or
3048 overlay string, then we are already at the end of
3049 a screen line; no need to go to the next line in
3050 that case, as this line is not really continued.
3051 (If we do go to the next line, C-e will not DTRT.) */
3054 set_iterator_to_next (it
, true);
3055 move_it_in_display_line_to (it
, -1, -1, 0);
3058 it
->continuation_lines_width
+= it
->current_x
;
3060 /* If the character at POS is displayed via a display
3061 vector, move_it_to above stops at the final glyph of
3062 IT->dpvec. To make the caller redisplay that character
3063 again (a.k.a. start at POS), we need to reset the
3064 dpvec_index to the beginning of IT->dpvec. */
3065 else if (it
->current
.dpvec_index
>= 0)
3066 it
->current
.dpvec_index
= 0;
3068 /* We're starting a new display line, not affected by the
3069 height of the continued line, so clear the appropriate
3070 fields in the iterator structure. */
3071 it
->max_ascent
= it
->max_descent
= 0;
3072 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3074 it
->current_y
= first_y
;
3076 it
->current_x
= it
->hpos
= 0;
3082 /* Return true if POS is a position in ellipses displayed for invisible
3083 text. W is the window we display, for text property lookup. */
3086 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3088 Lisp_Object prop
, window
;
3089 bool ellipses_p
= false;
3090 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3092 /* If POS specifies a position in a display vector, this might
3093 be for an ellipsis displayed for invisible text. We won't
3094 get the iterator set up for delivering that ellipsis unless
3095 we make sure that it gets aware of the invisible text. */
3096 if (pos
->dpvec_index
>= 0
3097 && pos
->overlay_string_index
< 0
3098 && CHARPOS (pos
->string_pos
) < 0
3100 && (XSETWINDOW (window
, w
),
3101 prop
= Fget_char_property (make_number (charpos
),
3102 Qinvisible
, window
),
3103 TEXT_PROP_MEANS_INVISIBLE (prop
) == 0))
3105 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3107 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3114 /* Initialize IT for stepping through current_buffer in window W,
3115 starting at position POS that includes overlay string and display
3116 vector/ control character translation position information. Value
3117 is false if there are overlay strings with newlines at POS. */
3120 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3122 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3124 bool overlay_strings_with_newlines
= false;
3126 /* If POS specifies a position in a display vector, this might
3127 be for an ellipsis displayed for invisible text. We won't
3128 get the iterator set up for delivering that ellipsis unless
3129 we make sure that it gets aware of the invisible text. */
3130 if (in_ellipses_for_invisible_text_p (pos
, w
))
3136 /* Keep in mind: the call to reseat in init_iterator skips invisible
3137 text, so we might end up at a position different from POS. This
3138 is only a problem when POS is a row start after a newline and an
3139 overlay starts there with an after-string, and the overlay has an
3140 invisible property. Since we don't skip invisible text in
3141 display_line and elsewhere immediately after consuming the
3142 newline before the row start, such a POS will not be in a string,
3143 but the call to init_iterator below will move us to the
3145 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3147 /* This only scans the current chunk -- it should scan all chunks.
3148 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3149 to 16 in 22.1 to make this a lesser problem. */
3150 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3152 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3153 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3155 while (s
< e
&& *s
!= '\n')
3160 overlay_strings_with_newlines
= true;
3165 /* If position is within an overlay string, set up IT to the right
3167 if (pos
->overlay_string_index
>= 0)
3171 /* If the first overlay string happens to have a `display'
3172 property for an image, the iterator will be set up for that
3173 image, and we have to undo that setup first before we can
3174 correct the overlay string index. */
3175 if (it
->method
== GET_FROM_IMAGE
)
3178 /* We already have the first chunk of overlay strings in
3179 IT->overlay_strings. Load more until the one for
3180 pos->overlay_string_index is in IT->overlay_strings. */
3181 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3183 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3184 it
->current
.overlay_string_index
= 0;
3187 load_overlay_strings (it
, 0);
3188 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3192 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3193 relative_index
= (it
->current
.overlay_string_index
3194 % OVERLAY_STRING_CHUNK_SIZE
);
3195 it
->string
= it
->overlay_strings
[relative_index
];
3196 eassert (STRINGP (it
->string
));
3197 it
->current
.string_pos
= pos
->string_pos
;
3198 it
->method
= GET_FROM_STRING
;
3199 it
->end_charpos
= SCHARS (it
->string
);
3200 /* Set up the bidi iterator for this overlay string. */
3203 it
->bidi_it
.string
.lstring
= it
->string
;
3204 it
->bidi_it
.string
.s
= NULL
;
3205 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3206 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3207 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3208 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3209 it
->bidi_it
.w
= it
->w
;
3210 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3211 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3213 /* Synchronize the state of the bidi iterator with
3214 pos->string_pos. For any string position other than
3215 zero, this will be done automagically when we resume
3216 iteration over the string and get_visually_first_element
3217 is called. But if string_pos is zero, and the string is
3218 to be reordered for display, we need to resync manually,
3219 since it could be that the iteration state recorded in
3220 pos ended at string_pos of 0 moving backwards in string. */
3221 if (CHARPOS (pos
->string_pos
) == 0)
3223 get_visually_first_element (it
);
3224 if (IT_STRING_CHARPOS (*it
) != 0)
3227 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3228 bidi_move_to_visually_next (&it
->bidi_it
);
3229 } while (it
->bidi_it
.charpos
!= 0);
3231 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3232 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3236 if (CHARPOS (pos
->string_pos
) >= 0)
3238 /* Recorded position is not in an overlay string, but in another
3239 string. This can only be a string from a `display' property.
3240 IT should already be filled with that string. */
3241 it
->current
.string_pos
= pos
->string_pos
;
3242 eassert (STRINGP (it
->string
));
3244 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3245 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3248 /* Restore position in display vector translations, control
3249 character translations or ellipses. */
3250 if (pos
->dpvec_index
>= 0)
3252 if (it
->dpvec
== NULL
)
3253 get_next_display_element (it
);
3254 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3255 it
->current
.dpvec_index
= pos
->dpvec_index
;
3259 return !overlay_strings_with_newlines
;
3263 /* Initialize IT for stepping through current_buffer in window W
3264 starting at ROW->start. */
3267 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3269 init_from_display_pos (it
, w
, &row
->start
);
3270 it
->start
= row
->start
;
3271 it
->continuation_lines_width
= row
->continuation_lines_width
;
3276 /* Initialize IT for stepping through current_buffer in window W
3277 starting in the line following ROW, i.e. starting at ROW->end.
3278 Value is false if there are overlay strings with newlines at ROW's
3282 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3284 bool success
= false;
3286 if (init_from_display_pos (it
, w
, &row
->end
))
3288 if (row
->continued_p
)
3289 it
->continuation_lines_width
3290 = row
->continuation_lines_width
+ row
->pixel_width
;
3301 /***********************************************************************
3303 ***********************************************************************/
3305 /* Called when IT reaches IT->stop_charpos. Handle text property and
3306 overlay changes. Set IT->stop_charpos to the next position where
3310 handle_stop (struct it
*it
)
3312 enum prop_handled handled
;
3313 bool handle_overlay_change_p
;
3317 it
->current
.dpvec_index
= -1;
3318 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3319 it
->ellipsis_p
= false;
3321 /* Use face of preceding text for ellipsis (if invisible) */
3322 if (it
->selective_display_ellipsis_p
)
3323 it
->saved_face_id
= it
->face_id
;
3325 /* Here's the description of the semantics of, and the logic behind,
3326 the various HANDLED_* statuses:
3328 HANDLED_NORMALLY means the handler did its job, and the loop
3329 should proceed to calling the next handler in order.
3331 HANDLED_RECOMPUTE_PROPS means the handler caused a significant
3332 change in the properties and overlays at current position, so the
3333 loop should be restarted, to re-invoke the handlers that were
3334 already called. This happens when fontification-functions were
3335 called by handle_fontified_prop, and actually fontified
3336 something. Another case where HANDLED_RECOMPUTE_PROPS is
3337 returned is when we discover overlay strings that need to be
3338 displayed right away. The loop below will continue for as long
3339 as the status is HANDLED_RECOMPUTE_PROPS.
3341 HANDLED_RETURN means return immediately to the caller, to
3342 continue iteration without calling any further handlers. This is
3343 used when we need to act on some property right away, for example
3344 when we need to display the ellipsis or a replacing display
3345 property, such as display string or image.
3347 HANDLED_OVERLAY_STRING_CONSUMED means an overlay string was just
3348 consumed, and the handler switched to the next overlay string.
3349 This signals the loop below to refrain from looking for more
3350 overlays before all the overlay strings of the current overlay
3353 Some of the handlers called by the loop push the iterator state
3354 onto the stack (see 'push_it'), and arrange for the iteration to
3355 continue with another object, such as an image, a display string,
3356 or an overlay string. In most such cases, it->stop_charpos is
3357 set to the first character of the string, so that when the
3358 iteration resumes, this function will immediately be called
3359 again, to examine the properties at the beginning of the string.
3361 When a display or overlay string is exhausted, the iterator state
3362 is popped (see 'pop_it'), and iteration continues with the
3363 previous object. Again, in many such cases this function is
3364 called again to find the next position where properties might
3369 handled
= HANDLED_NORMALLY
;
3371 /* Call text property handlers. */
3372 for (p
= it_props
; p
->handler
; ++p
)
3374 handled
= p
->handler (it
);
3376 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3378 else if (handled
== HANDLED_RETURN
)
3380 /* We still want to show before and after strings from
3381 overlays even if the actual buffer text is replaced. */
3382 if (!handle_overlay_change_p
3384 /* Don't call get_overlay_strings_1 if we already
3385 have overlay strings loaded, because doing so
3386 will load them again and push the iterator state
3387 onto the stack one more time, which is not
3388 expected by the rest of the code that processes
3390 || (it
->current
.overlay_string_index
< 0
3391 && !get_overlay_strings_1 (it
, 0, false)))
3394 setup_for_ellipsis (it
, 0);
3395 /* When handling a display spec, we might load an
3396 empty string. In that case, discard it here. We
3397 used to discard it in handle_single_display_spec,
3398 but that causes get_overlay_strings_1, above, to
3399 ignore overlay strings that we must check. */
3400 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3404 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3408 it
->string_from_display_prop_p
= false;
3409 it
->from_disp_prop_p
= false;
3410 handle_overlay_change_p
= false;
3412 handled
= HANDLED_RECOMPUTE_PROPS
;
3415 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3416 handle_overlay_change_p
= false;
3419 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3421 /* Don't check for overlay strings below when set to deliver
3422 characters from a display vector. */
3423 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3424 handle_overlay_change_p
= false;
3426 /* Handle overlay changes.
3427 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3428 if it finds overlays. */
3429 if (handle_overlay_change_p
)
3430 handled
= handle_overlay_change (it
);
3435 setup_for_ellipsis (it
, 0);
3439 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3441 /* Determine where to stop next. */
3442 if (handled
== HANDLED_NORMALLY
)
3443 compute_stop_pos (it
);
3447 /* Compute IT->stop_charpos from text property and overlay change
3448 information for IT's current position. */
3451 compute_stop_pos (struct it
*it
)
3453 register INTERVAL iv
, next_iv
;
3454 Lisp_Object object
, limit
, position
;
3455 ptrdiff_t charpos
, bytepos
;
3457 if (STRINGP (it
->string
))
3459 /* Strings are usually short, so don't limit the search for
3461 it
->stop_charpos
= it
->end_charpos
;
3462 object
= it
->string
;
3464 charpos
= IT_STRING_CHARPOS (*it
);
3465 bytepos
= IT_STRING_BYTEPOS (*it
);
3471 /* If end_charpos is out of range for some reason, such as a
3472 misbehaving display function, rationalize it (Bug#5984). */
3473 if (it
->end_charpos
> ZV
)
3474 it
->end_charpos
= ZV
;
3475 it
->stop_charpos
= it
->end_charpos
;
3477 /* If next overlay change is in front of the current stop pos
3478 (which is IT->end_charpos), stop there. Note: value of
3479 next_overlay_change is point-max if no overlay change
3481 charpos
= IT_CHARPOS (*it
);
3482 bytepos
= IT_BYTEPOS (*it
);
3483 pos
= next_overlay_change (charpos
);
3484 if (pos
< it
->stop_charpos
)
3485 it
->stop_charpos
= pos
;
3487 /* Set up variables for computing the stop position from text
3488 property changes. */
3489 XSETBUFFER (object
, current_buffer
);
3490 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3493 /* Get the interval containing IT's position. Value is a null
3494 interval if there isn't such an interval. */
3495 position
= make_number (charpos
);
3496 iv
= validate_interval_range (object
, &position
, &position
, false);
3499 Lisp_Object values_here
[LAST_PROP_IDX
];
3502 /* Get properties here. */
3503 for (p
= it_props
; p
->handler
; ++p
)
3504 values_here
[p
->idx
] = textget (iv
->plist
,
3505 builtin_lisp_symbol (p
->name
));
3507 /* Look for an interval following iv that has different
3509 for (next_iv
= next_interval (iv
);
3512 || XFASTINT (limit
) > next_iv
->position
));
3513 next_iv
= next_interval (next_iv
))
3515 for (p
= it_props
; p
->handler
; ++p
)
3517 Lisp_Object new_value
= textget (next_iv
->plist
,
3518 builtin_lisp_symbol (p
->name
));
3519 if (!EQ (values_here
[p
->idx
], new_value
))
3529 if (INTEGERP (limit
)
3530 && next_iv
->position
>= XFASTINT (limit
))
3531 /* No text property change up to limit. */
3532 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3534 /* Text properties change in next_iv. */
3535 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3539 if (it
->cmp_it
.id
< 0)
3541 ptrdiff_t stoppos
= it
->end_charpos
;
3543 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3545 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3546 stoppos
, it
->string
);
3549 eassert (STRINGP (it
->string
)
3550 || (it
->stop_charpos
>= BEGV
3551 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3555 /* Return the position of the next overlay change after POS in
3556 current_buffer. Value is point-max if no overlay change
3557 follows. This is like `next-overlay-change' but doesn't use
3561 next_overlay_change (ptrdiff_t pos
)
3563 ptrdiff_t i
, noverlays
;
3565 Lisp_Object
*overlays
;
3568 /* Get all overlays at the given position. */
3569 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, true);
3571 /* If any of these overlays ends before endpos,
3572 use its ending point instead. */
3573 for (i
= 0; i
< noverlays
; ++i
)
3578 oend
= OVERLAY_END (overlays
[i
]);
3579 oendpos
= OVERLAY_POSITION (oend
);
3580 endpos
= min (endpos
, oendpos
);
3587 /* How many characters forward to search for a display property or
3588 display string. Searching too far forward makes the bidi display
3589 sluggish, especially in small windows. */
3590 #define MAX_DISP_SCAN 250
3592 /* Return the character position of a display string at or after
3593 position specified by POSITION. If no display string exists at or
3594 after POSITION, return ZV. A display string is either an overlay
3595 with `display' property whose value is a string, or a `display'
3596 text property whose value is a string. STRING is data about the
3597 string to iterate; if STRING->lstring is nil, we are iterating a
3598 buffer. FRAME_WINDOW_P is true when we are displaying a window
3599 on a GUI frame. DISP_PROP is set to zero if we searched
3600 MAX_DISP_SCAN characters forward without finding any display
3601 strings, non-zero otherwise. It is set to 2 if the display string
3602 uses any kind of `(space ...)' spec that will produce a stretch of
3603 white space in the text area. */
3605 compute_display_string_pos (struct text_pos
*position
,
3606 struct bidi_string_data
*string
,
3608 bool frame_window_p
, int *disp_prop
)
3610 /* OBJECT = nil means current buffer. */
3611 Lisp_Object object
, object1
;
3612 Lisp_Object pos
, spec
, limpos
;
3613 bool string_p
= string
&& (STRINGP (string
->lstring
) || string
->s
);
3614 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3615 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3616 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3618 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3619 struct text_pos tpos
;
3622 if (string
&& STRINGP (string
->lstring
))
3623 object1
= object
= string
->lstring
;
3624 else if (w
&& !string_p
)
3626 XSETWINDOW (object
, w
);
3630 object1
= object
= Qnil
;
3635 /* We don't support display properties whose values are strings
3636 that have display string properties. */
3637 || string
->from_disp_str
3638 /* C strings cannot have display properties. */
3639 || (string
->s
&& !STRINGP (object
)))
3645 /* If the character at CHARPOS is where the display string begins,
3647 pos
= make_number (charpos
);
3648 if (STRINGP (object
))
3649 bufpos
= string
->bufpos
;
3653 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3655 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3658 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3666 /* Look forward for the first character with a `display' property
3667 that will replace the underlying text when displayed. */
3668 limpos
= make_number (lim
);
3670 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3671 CHARPOS (tpos
) = XFASTINT (pos
);
3672 if (CHARPOS (tpos
) >= lim
)
3677 if (STRINGP (object
))
3678 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3680 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3681 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3682 if (!STRINGP (object
))
3683 bufpos
= CHARPOS (tpos
);
3684 } while (NILP (spec
)
3685 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3686 bufpos
, frame_window_p
)));
3690 return CHARPOS (tpos
);
3693 /* Return the character position of the end of the display string that
3694 started at CHARPOS. If there's no display string at CHARPOS,
3695 return -1. A display string is either an overlay with `display'
3696 property whose value is a string or a `display' text property whose
3697 value is a string. */
3699 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3701 /* OBJECT = nil means current buffer. */
3702 Lisp_Object object
=
3703 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3704 Lisp_Object pos
= make_number (charpos
);
3706 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3708 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3711 /* It could happen that the display property or overlay was removed
3712 since we found it in compute_display_string_pos above. One way
3713 this can happen is if JIT font-lock was called (through
3714 handle_fontified_prop), and jit-lock-functions remove text
3715 properties or overlays from the portion of buffer that includes
3716 CHARPOS. Muse mode is known to do that, for example. In this
3717 case, we return -1 to the caller, to signal that no display
3718 string is actually present at CHARPOS. See bidi_fetch_char for
3719 how this is handled.
3721 An alternative would be to never look for display properties past
3722 it->stop_charpos. But neither compute_display_string_pos nor
3723 bidi_fetch_char that calls it know or care where the next
3725 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3728 /* Look forward for the first character where the `display' property
3730 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3732 return XFASTINT (pos
);
3737 /***********************************************************************
3739 ***********************************************************************/
3741 /* Handle changes in the `fontified' property of the current buffer by
3742 calling hook functions from Qfontification_functions to fontify
3745 static enum prop_handled
3746 handle_fontified_prop (struct it
*it
)
3748 Lisp_Object prop
, pos
;
3749 enum prop_handled handled
= HANDLED_NORMALLY
;
3751 if (!NILP (Vmemory_full
))
3754 /* Get the value of the `fontified' property at IT's current buffer
3755 position. (The `fontified' property doesn't have a special
3756 meaning in strings.) If the value is nil, call functions from
3757 Qfontification_functions. */
3758 if (!STRINGP (it
->string
)
3760 && !NILP (Vfontification_functions
)
3761 && !NILP (Vrun_hooks
)
3762 && (pos
= make_number (IT_CHARPOS (*it
)),
3763 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3764 /* Ignore the special cased nil value always present at EOB since
3765 no amount of fontifying will be able to change it. */
3766 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3768 ptrdiff_t count
= SPECPDL_INDEX ();
3770 struct buffer
*obuf
= current_buffer
;
3771 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3772 bool old_clip_changed
= current_buffer
->clip_changed
;
3774 val
= Vfontification_functions
;
3775 specbind (Qfontification_functions
, Qnil
);
3777 eassert (it
->end_charpos
== ZV
);
3779 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3780 safe_call1 (val
, pos
);
3783 Lisp_Object fns
, fn
;
3787 for (; CONSP (val
); val
= XCDR (val
))
3793 /* A value of t indicates this hook has a local
3794 binding; it means to run the global binding too.
3795 In a global value, t should not occur. If it
3796 does, we must ignore it to avoid an endless
3798 for (fns
= Fdefault_value (Qfontification_functions
);
3804 safe_call1 (fn
, pos
);
3808 safe_call1 (fn
, pos
);
3812 unbind_to (count
, Qnil
);
3814 /* Fontification functions routinely call `save-restriction'.
3815 Normally, this tags clip_changed, which can confuse redisplay
3816 (see discussion in Bug#6671). Since we don't perform any
3817 special handling of fontification changes in the case where
3818 `save-restriction' isn't called, there's no point doing so in
3819 this case either. So, if the buffer's restrictions are
3820 actually left unchanged, reset clip_changed. */
3821 if (obuf
== current_buffer
)
3823 if (begv
== BEGV
&& zv
== ZV
)
3824 current_buffer
->clip_changed
= old_clip_changed
;
3826 /* There isn't much we can reasonably do to protect against
3827 misbehaving fontification, but here's a fig leaf. */
3828 else if (BUFFER_LIVE_P (obuf
))
3829 set_buffer_internal_1 (obuf
);
3831 /* The fontification code may have added/removed text.
3832 It could do even a lot worse, but let's at least protect against
3833 the most obvious case where only the text past `pos' gets changed',
3834 as is/was done in grep.el where some escapes sequences are turned
3835 into face properties (bug#7876). */
3836 it
->end_charpos
= ZV
;
3838 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3839 something. This avoids an endless loop if they failed to
3840 fontify the text for which reason ever. */
3841 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3842 handled
= HANDLED_RECOMPUTE_PROPS
;
3850 /***********************************************************************
3852 ***********************************************************************/
3854 /* Set up iterator IT from face properties at its current position.
3855 Called from handle_stop. */
3857 static enum prop_handled
3858 handle_face_prop (struct it
*it
)
3861 ptrdiff_t next_stop
;
3863 if (!STRINGP (it
->string
))
3866 = face_at_buffer_position (it
->w
,
3870 + TEXT_PROP_DISTANCE_LIMIT
),
3871 false, it
->base_face_id
);
3873 /* Is this a start of a run of characters with box face?
3874 Caveat: this can be called for a freshly initialized
3875 iterator; face_id is -1 in this case. We know that the new
3876 face will not change until limit, i.e. if the new face has a
3877 box, all characters up to limit will have one. But, as
3878 usual, we don't know whether limit is really the end. */
3879 if (new_face_id
!= it
->face_id
)
3881 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3882 /* If it->face_id is -1, old_face below will be NULL, see
3883 the definition of FACE_FROM_ID. This will happen if this
3884 is the initial call that gets the face. */
3885 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3887 /* If the value of face_id of the iterator is -1, we have to
3888 look in front of IT's position and see whether there is a
3889 face there that's different from new_face_id. */
3890 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3892 int prev_face_id
= face_before_it_pos (it
);
3894 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3897 /* If the new face has a box, but the old face does not,
3898 this is the start of a run of characters with box face,
3899 i.e. this character has a shadow on the left side. */
3900 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3901 && (old_face
== NULL
|| !old_face
->box
));
3902 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3910 Lisp_Object from_overlay
3911 = (it
->current
.overlay_string_index
>= 0
3912 ? it
->string_overlays
[it
->current
.overlay_string_index
3913 % OVERLAY_STRING_CHUNK_SIZE
]
3916 /* See if we got to this string directly or indirectly from
3917 an overlay property. That includes the before-string or
3918 after-string of an overlay, strings in display properties
3919 provided by an overlay, their text properties, etc.
3921 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3922 if (! NILP (from_overlay
))
3923 for (i
= it
->sp
- 1; i
>= 0; i
--)
3925 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3927 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3928 % OVERLAY_STRING_CHUNK_SIZE
];
3929 else if (! NILP (it
->stack
[i
].from_overlay
))
3930 from_overlay
= it
->stack
[i
].from_overlay
;
3932 if (!NILP (from_overlay
))
3936 if (! NILP (from_overlay
))
3938 bufpos
= IT_CHARPOS (*it
);
3939 /* For a string from an overlay, the base face depends
3940 only on text properties and ignores overlays. */
3942 = face_for_overlay_string (it
->w
,
3946 + TEXT_PROP_DISTANCE_LIMIT
),
3954 /* For strings from a `display' property, use the face at
3955 IT's current buffer position as the base face to merge
3956 with, so that overlay strings appear in the same face as
3957 surrounding text, unless they specify their own faces.
3958 For strings from wrap-prefix and line-prefix properties,
3959 use the default face, possibly remapped via
3960 Vface_remapping_alist. */
3961 /* Note that the fact that we use the face at _buffer_
3962 position means that a 'display' property on an overlay
3963 string will not inherit the face of that overlay string,
3964 but will instead revert to the face of buffer text
3965 covered by the overlay. This is visible, e.g., when the
3966 overlay specifies a box face, but neither the buffer nor
3967 the display string do. This sounds like a design bug,
3968 but Emacs always did that since v21.1, so changing that
3969 might be a big deal. */
3970 base_face_id
= it
->string_from_prefix_prop_p
3971 ? (!NILP (Vface_remapping_alist
)
3972 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3974 : underlying_face_id (it
);
3977 new_face_id
= face_at_string_position (it
->w
,
3979 IT_STRING_CHARPOS (*it
),
3982 base_face_id
, false);
3984 /* Is this a start of a run of characters with box? Caveat:
3985 this can be called for a freshly allocated iterator; face_id
3986 is -1 is this case. We know that the new face will not
3987 change until the next check pos, i.e. if the new face has a
3988 box, all characters up to that position will have a
3989 box. But, as usual, we don't know whether that position
3990 is really the end. */
3991 if (new_face_id
!= it
->face_id
)
3993 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3994 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3996 /* If new face has a box but old face hasn't, this is the
3997 start of a run of characters with box, i.e. it has a
3998 shadow on the left side. */
3999 it
->start_of_box_run_p
4000 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
4001 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
4005 it
->face_id
= new_face_id
;
4006 return HANDLED_NORMALLY
;
4010 /* Return the ID of the face ``underlying'' IT's current position,
4011 which is in a string. If the iterator is associated with a
4012 buffer, return the face at IT's current buffer position.
4013 Otherwise, use the iterator's base_face_id. */
4016 underlying_face_id (struct it
*it
)
4018 int face_id
= it
->base_face_id
, i
;
4020 eassert (STRINGP (it
->string
));
4022 for (i
= it
->sp
- 1; i
>= 0; --i
)
4023 if (NILP (it
->stack
[i
].string
))
4024 face_id
= it
->stack
[i
].face_id
;
4030 /* Compute the face one character before or after the current position
4031 of IT, in the visual order. BEFORE_P means get the face
4032 in front (to the left in L2R paragraphs, to the right in R2L
4033 paragraphs) of IT's screen position. Value is the ID of the face. */
4036 face_before_or_after_it_pos (struct it
*it
, bool before_p
)
4039 ptrdiff_t next_check_charpos
;
4041 void *it_copy_data
= NULL
;
4043 eassert (it
->s
== NULL
);
4045 if (STRINGP (it
->string
))
4047 ptrdiff_t bufpos
, charpos
;
4050 /* No face change past the end of the string (for the case
4051 we are padding with spaces). No face change before the
4053 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
4054 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4059 /* Set charpos to the position before or after IT's current
4060 position, in the logical order, which in the non-bidi
4061 case is the same as the visual order. */
4063 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4064 else if (it
->what
== IT_COMPOSITION
)
4065 /* For composition, we must check the character after the
4067 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4069 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4075 /* With bidi iteration, the character before the current
4076 in the visual order cannot be found by simple
4077 iteration, because "reverse" reordering is not
4078 supported. Instead, we need to start from the string
4079 beginning and go all the way to the current string
4080 position, remembering the previous position. */
4081 /* Ignore face changes before the first visible
4082 character on this display line. */
4083 if (it
->current_x
<= it
->first_visible_x
)
4085 SAVE_IT (it_copy
, *it
, it_copy_data
);
4086 IT_STRING_CHARPOS (it_copy
) = 0;
4087 bidi_init_it (0, 0, FRAME_WINDOW_P (it_copy
.f
), &it_copy
.bidi_it
);
4091 charpos
= IT_STRING_CHARPOS (it_copy
);
4092 if (charpos
>= SCHARS (it
->string
))
4094 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4096 while (IT_STRING_CHARPOS (it_copy
) != IT_STRING_CHARPOS (*it
));
4098 RESTORE_IT (it
, it
, it_copy_data
);
4102 /* Set charpos to the string position of the character
4103 that comes after IT's current position in the visual
4105 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4109 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4111 charpos
= it_copy
.bidi_it
.charpos
;
4114 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4116 if (it
->current
.overlay_string_index
>= 0)
4117 bufpos
= IT_CHARPOS (*it
);
4121 base_face_id
= underlying_face_id (it
);
4123 /* Get the face for ASCII, or unibyte. */
4124 face_id
= face_at_string_position (it
->w
,
4128 &next_check_charpos
,
4129 base_face_id
, false);
4131 /* Correct the face for charsets different from ASCII. Do it
4132 for the multibyte case only. The face returned above is
4133 suitable for unibyte text if IT->string is unibyte. */
4134 if (STRING_MULTIBYTE (it
->string
))
4136 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4137 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4139 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4141 c
= string_char_and_length (p
, &len
);
4142 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4147 struct text_pos pos
;
4149 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4150 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4153 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4154 pos
= it
->current
.pos
;
4159 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4162 if (it
->what
== IT_COMPOSITION
)
4164 /* For composition, we must check the position after
4166 pos
.charpos
+= it
->cmp_it
.nchars
;
4167 pos
.bytepos
+= it
->len
;
4170 INC_TEXT_POS (pos
, it
->multibyte_p
);
4179 /* With bidi iteration, the character before the current
4180 in the visual order cannot be found by simple
4181 iteration, because "reverse" reordering is not
4182 supported. Instead, we need to use the move_it_*
4183 family of functions, and move to the previous
4184 character starting from the beginning of the visual
4186 /* Ignore face changes before the first visible
4187 character on this display line. */
4188 if (it
->current_x
<= it
->first_visible_x
)
4190 SAVE_IT (it_copy
, *it
, it_copy_data
);
4191 /* Implementation note: Since move_it_in_display_line
4192 works in the iterator geometry, and thinks the first
4193 character is always the leftmost, even in R2L lines,
4194 we don't need to distinguish between the R2L and L2R
4196 current_x
= it_copy
.current_x
;
4197 move_it_vertically_backward (&it_copy
, 0);
4198 move_it_in_display_line (&it_copy
, ZV
, current_x
- 1, MOVE_TO_X
);
4199 pos
= it_copy
.current
.pos
;
4200 RESTORE_IT (it
, it
, it_copy_data
);
4204 /* Set charpos to the buffer position of the character
4205 that comes after IT's current position in the visual
4207 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4211 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4214 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4217 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4219 /* Determine face for CHARSET_ASCII, or unibyte. */
4220 face_id
= face_at_buffer_position (it
->w
,
4222 &next_check_charpos
,
4225 /* Correct the face for charsets different from ASCII. Do it
4226 for the multibyte case only. The face returned above is
4227 suitable for unibyte text if current_buffer is unibyte. */
4228 if (it
->multibyte_p
)
4230 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4231 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4232 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4241 /***********************************************************************
4243 ***********************************************************************/
4245 /* Set up iterator IT from invisible properties at its current
4246 position. Called from handle_stop. */
4248 static enum prop_handled
4249 handle_invisible_prop (struct it
*it
)
4251 enum prop_handled handled
= HANDLED_NORMALLY
;
4255 if (STRINGP (it
->string
))
4257 Lisp_Object end_charpos
, limit
;
4259 /* Get the value of the invisible text property at the
4260 current position. Value will be nil if there is no such
4262 end_charpos
= make_number (IT_STRING_CHARPOS (*it
));
4263 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4264 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4266 if (invis
!= 0 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4268 /* Record whether we have to display an ellipsis for the
4270 bool display_ellipsis_p
= (invis
== 2);
4271 ptrdiff_t len
, endpos
;
4273 handled
= HANDLED_RECOMPUTE_PROPS
;
4275 /* Get the position at which the next visible text can be
4276 found in IT->string, if any. */
4277 endpos
= len
= SCHARS (it
->string
);
4278 XSETINT (limit
, len
);
4282 = Fnext_single_property_change (end_charpos
, Qinvisible
,
4284 /* Since LIMIT is always an integer, so should be the
4285 value returned by Fnext_single_property_change. */
4286 eassert (INTEGERP (end_charpos
));
4287 if (INTEGERP (end_charpos
))
4289 endpos
= XFASTINT (end_charpos
);
4290 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4291 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4293 display_ellipsis_p
= true;
4295 else /* Should never happen; but if it does, exit the loop. */
4298 while (invis
!= 0 && endpos
< len
);
4300 if (display_ellipsis_p
)
4301 it
->ellipsis_p
= true;
4305 /* Text at END_CHARPOS is visible. Move IT there. */
4306 struct text_pos old
;
4309 old
= it
->current
.string_pos
;
4310 oldpos
= CHARPOS (old
);
4313 if (it
->bidi_it
.first_elt
4314 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4315 bidi_paragraph_init (it
->paragraph_embedding
,
4316 &it
->bidi_it
, true);
4317 /* Bidi-iterate out of the invisible text. */
4320 bidi_move_to_visually_next (&it
->bidi_it
);
4322 while (oldpos
<= it
->bidi_it
.charpos
4323 && it
->bidi_it
.charpos
< endpos
);
4325 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4326 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4327 if (IT_CHARPOS (*it
) >= endpos
)
4328 it
->prev_stop
= endpos
;
4332 IT_STRING_CHARPOS (*it
) = endpos
;
4333 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4338 /* The rest of the string is invisible. If this is an
4339 overlay string, proceed with the next overlay string
4340 or whatever comes and return a character from there. */
4341 if (it
->current
.overlay_string_index
>= 0
4342 && !display_ellipsis_p
)
4344 next_overlay_string (it
);
4345 /* Don't check for overlay strings when we just
4346 finished processing them. */
4347 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4351 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4352 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4359 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4360 Lisp_Object pos
, overlay
;
4362 /* First of all, is there invisible text at this position? */
4363 tem
= start_charpos
= IT_CHARPOS (*it
);
4364 pos
= make_number (tem
);
4365 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4367 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4369 /* If we are on invisible text, skip over it. */
4370 if (invis
!= 0 && start_charpos
< it
->end_charpos
)
4372 /* Record whether we have to display an ellipsis for the
4374 bool display_ellipsis_p
= invis
== 2;
4376 handled
= HANDLED_RECOMPUTE_PROPS
;
4378 /* Loop skipping over invisible text. The loop is left at
4379 ZV or with IT on the first char being visible again. */
4382 /* Try to skip some invisible text. Return value is the
4383 position reached which can be equal to where we start
4384 if there is nothing invisible there. This skips both
4385 over invisible text properties and overlays with
4386 invisible property. */
4387 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4389 /* If we skipped nothing at all we weren't at invisible
4390 text in the first place. If everything to the end of
4391 the buffer was skipped, end the loop. */
4392 if (newpos
== tem
|| newpos
>= ZV
)
4396 /* We skipped some characters but not necessarily
4397 all there are. Check if we ended up on visible
4398 text. Fget_char_property returns the property of
4399 the char before the given position, i.e. if we
4400 get invis = 0, this means that the char at
4401 newpos is visible. */
4402 pos
= make_number (newpos
);
4403 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4404 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4407 /* If we ended up on invisible text, proceed to
4408 skip starting with next_stop. */
4412 /* If there are adjacent invisible texts, don't lose the
4413 second one's ellipsis. */
4415 display_ellipsis_p
= true;
4419 /* The position newpos is now either ZV or on visible text. */
4422 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4424 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4426 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4428 /* If the invisible text ends on a newline or on a
4429 character after a newline, we can avoid the costly,
4430 character by character, bidi iteration to NEWPOS, and
4431 instead simply reseat the iterator there. That's
4432 because all bidi reordering information is tossed at
4433 the newline. This is a big win for modes that hide
4434 complete lines, like Outline, Org, etc. */
4435 if (on_newline
|| after_newline
)
4437 struct text_pos tpos
;
4438 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4440 SET_TEXT_POS (tpos
, newpos
, bpos
);
4441 reseat_1 (it
, tpos
, false);
4442 /* If we reseat on a newline/ZV, we need to prep the
4443 bidi iterator for advancing to the next character
4444 after the newline/EOB, keeping the current paragraph
4445 direction (so that PRODUCE_GLYPHS does TRT wrt
4446 prepending/appending glyphs to a glyph row). */
4449 it
->bidi_it
.first_elt
= false;
4450 it
->bidi_it
.paragraph_dir
= pdir
;
4451 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4452 it
->bidi_it
.nchars
= 1;
4453 it
->bidi_it
.ch_len
= 1;
4456 else /* Must use the slow method. */
4458 /* With bidi iteration, the region of invisible text
4459 could start and/or end in the middle of a
4460 non-base embedding level. Therefore, we need to
4461 skip invisible text using the bidi iterator,
4462 starting at IT's current position, until we find
4463 ourselves outside of the invisible text.
4464 Skipping invisible text _after_ bidi iteration
4465 avoids affecting the visual order of the
4466 displayed text when invisible properties are
4467 added or removed. */
4468 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4470 /* If we were `reseat'ed to a new paragraph,
4471 determine the paragraph base direction. We
4472 need to do it now because
4473 next_element_from_buffer may not have a
4474 chance to do it, if we are going to skip any
4475 text at the beginning, which resets the
4477 bidi_paragraph_init (it
->paragraph_embedding
,
4478 &it
->bidi_it
, true);
4482 bidi_move_to_visually_next (&it
->bidi_it
);
4484 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4485 && it
->bidi_it
.charpos
< newpos
);
4486 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4487 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4488 /* If we overstepped NEWPOS, record its position in
4489 the iterator, so that we skip invisible text if
4490 later the bidi iteration lands us in the
4491 invisible region again. */
4492 if (IT_CHARPOS (*it
) >= newpos
)
4493 it
->prev_stop
= newpos
;
4498 IT_CHARPOS (*it
) = newpos
;
4499 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4502 if (display_ellipsis_p
)
4504 /* Make sure that the glyphs of the ellipsis will get
4505 correct `charpos' values. If we would not update
4506 it->position here, the glyphs would belong to the
4507 last visible character _before_ the invisible
4508 text, which confuses `set_cursor_from_row'.
4510 We use the last invisible position instead of the
4511 first because this way the cursor is always drawn on
4512 the first "." of the ellipsis, whenever PT is inside
4513 the invisible text. Otherwise the cursor would be
4514 placed _after_ the ellipsis when the point is after the
4515 first invisible character. */
4516 if (!STRINGP (it
->object
))
4518 it
->position
.charpos
= newpos
- 1;
4519 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4523 /* If there are before-strings at the start of invisible
4524 text, and the text is invisible because of a text
4525 property, arrange to show before-strings because 20.x did
4526 it that way. (If the text is invisible because of an
4527 overlay property instead of a text property, this is
4528 already handled in the overlay code.) */
4530 && get_overlay_strings (it
, it
->stop_charpos
))
4532 handled
= HANDLED_RECOMPUTE_PROPS
;
4535 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4536 /* The call to get_overlay_strings above recomputes
4537 it->stop_charpos, but it only considers changes
4538 in properties and overlays beyond iterator's
4539 current position. This causes us to miss changes
4540 that happen exactly where the invisible property
4541 ended. So we play it safe here and force the
4542 iterator to check for potential stop positions
4543 immediately after the invisible text. Note that
4544 if get_overlay_strings returns true, it
4545 normally also pushed the iterator stack, so we
4546 need to update the stop position in the slot
4547 below the current one. */
4548 it
->stack
[it
->sp
- 1].stop_charpos
4549 = CHARPOS (it
->stack
[it
->sp
- 1].current
.pos
);
4552 else if (display_ellipsis_p
)
4554 it
->ellipsis_p
= true;
4555 /* Let the ellipsis display before
4556 considering any properties of the following char.
4557 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4558 handled
= HANDLED_RETURN
;
4567 /* Make iterator IT return `...' next.
4568 Replaces LEN characters from buffer. */
4571 setup_for_ellipsis (struct it
*it
, int len
)
4573 /* Use the display table definition for `...'. Invalid glyphs
4574 will be handled by the method returning elements from dpvec. */
4575 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4577 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4578 it
->dpvec
= v
->contents
;
4579 it
->dpend
= v
->contents
+ v
->header
.size
;
4583 /* Default `...'. */
4584 it
->dpvec
= default_invis_vector
;
4585 it
->dpend
= default_invis_vector
+ 3;
4588 it
->dpvec_char_len
= len
;
4589 it
->current
.dpvec_index
= 0;
4590 it
->dpvec_face_id
= -1;
4592 /* Use IT->saved_face_id for the ellipsis, so that it has the same
4593 face as the preceding text. IT->saved_face_id was set in
4594 handle_stop to the face of the preceding character, and will be
4595 different from IT->face_id only if the invisible text skipped in
4596 handle_invisible_prop has some non-default face on its first
4597 character. We thus ignore the face of the invisible text when we
4598 display the ellipsis. IT's face is restored in set_iterator_to_next. */
4599 if (it
->saved_face_id
>= 0)
4600 it
->face_id
= it
->saved_face_id
;
4602 /* If the ellipsis represents buffer text, it means we advanced in
4603 the buffer, so we should no longer ignore overlay strings. */
4604 if (it
->method
== GET_FROM_BUFFER
)
4605 it
->ignore_overlay_strings_at_pos_p
= false;
4607 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4608 it
->ellipsis_p
= true;
4613 /***********************************************************************
4615 ***********************************************************************/
4617 /* Set up iterator IT from `display' property at its current position.
4618 Called from handle_stop.
4619 We return HANDLED_RETURN if some part of the display property
4620 overrides the display of the buffer text itself.
4621 Otherwise we return HANDLED_NORMALLY. */
4623 static enum prop_handled
4624 handle_display_prop (struct it
*it
)
4626 Lisp_Object propval
, object
, overlay
;
4627 struct text_pos
*position
;
4629 /* Nonzero if some property replaces the display of the text itself. */
4630 int display_replaced
= 0;
4632 if (STRINGP (it
->string
))
4634 object
= it
->string
;
4635 position
= &it
->current
.string_pos
;
4636 bufpos
= CHARPOS (it
->current
.pos
);
4640 XSETWINDOW (object
, it
->w
);
4641 position
= &it
->current
.pos
;
4642 bufpos
= CHARPOS (*position
);
4645 /* Reset those iterator values set from display property values. */
4646 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4647 it
->space_width
= Qnil
;
4648 it
->font_height
= Qnil
;
4651 /* We don't support recursive `display' properties, i.e. string
4652 values that have a string `display' property, that have a string
4653 `display' property etc. */
4654 if (!it
->string_from_display_prop_p
)
4655 it
->area
= TEXT_AREA
;
4657 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4658 Qdisplay
, object
, &overlay
);
4660 return HANDLED_NORMALLY
;
4661 /* Now OVERLAY is the overlay that gave us this property, or nil
4662 if it was a text property. */
4664 if (!STRINGP (it
->string
))
4665 object
= it
->w
->contents
;
4667 display_replaced
= handle_display_spec (it
, propval
, object
, overlay
,
4669 FRAME_WINDOW_P (it
->f
));
4670 return display_replaced
!= 0 ? HANDLED_RETURN
: HANDLED_NORMALLY
;
4673 /* Subroutine of handle_display_prop. Returns non-zero if the display
4674 specification in SPEC is a replacing specification, i.e. it would
4675 replace the text covered by `display' property with something else,
4676 such as an image or a display string. If SPEC includes any kind or
4677 `(space ...) specification, the value is 2; this is used by
4678 compute_display_string_pos, which see.
4680 See handle_single_display_spec for documentation of arguments.
4681 FRAME_WINDOW_P is true if the window being redisplayed is on a
4682 GUI frame; this argument is used only if IT is NULL, see below.
4684 IT can be NULL, if this is called by the bidi reordering code
4685 through compute_display_string_pos, which see. In that case, this
4686 function only examines SPEC, but does not otherwise "handle" it, in
4687 the sense that it doesn't set up members of IT from the display
4690 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4691 Lisp_Object overlay
, struct text_pos
*position
,
4692 ptrdiff_t bufpos
, bool frame_window_p
)
4697 /* Simple specifications. */
4698 && !EQ (XCAR (spec
), Qimage
)
4699 #ifdef HAVE_XWIDGETS
4700 && !EQ (XCAR (spec
), Qxwidget
)
4702 && !EQ (XCAR (spec
), Qspace
)
4703 && !EQ (XCAR (spec
), Qwhen
)
4704 && !EQ (XCAR (spec
), Qslice
)
4705 && !EQ (XCAR (spec
), Qspace_width
)
4706 && !EQ (XCAR (spec
), Qheight
)
4707 && !EQ (XCAR (spec
), Qraise
)
4708 /* Marginal area specifications. */
4709 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4710 && !EQ (XCAR (spec
), Qleft_fringe
)
4711 && !EQ (XCAR (spec
), Qright_fringe
)
4712 && !NILP (XCAR (spec
)))
4714 for (; CONSP (spec
); spec
= XCDR (spec
))
4716 int rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4717 overlay
, position
, bufpos
,
4718 replacing
, frame_window_p
);
4722 /* If some text in a string is replaced, `position' no
4723 longer points to the position of `object'. */
4724 if (!it
|| STRINGP (object
))
4729 else if (VECTORP (spec
))
4732 for (i
= 0; i
< ASIZE (spec
); ++i
)
4734 int rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4735 overlay
, position
, bufpos
,
4736 replacing
, frame_window_p
);
4740 /* If some text in a string is replaced, `position' no
4741 longer points to the position of `object'. */
4742 if (!it
|| STRINGP (object
))
4748 replacing
= handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4749 bufpos
, 0, frame_window_p
);
4753 /* Value is the position of the end of the `display' property starting
4754 at START_POS in OBJECT. */
4756 static struct text_pos
4757 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4760 struct text_pos end_pos
;
4762 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4763 Qdisplay
, object
, Qnil
);
4764 CHARPOS (end_pos
) = XFASTINT (end
);
4765 if (STRINGP (object
))
4766 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4768 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4774 /* Set up IT from a single `display' property specification SPEC. OBJECT
4775 is the object in which the `display' property was found. *POSITION
4776 is the position in OBJECT at which the `display' property was found.
4777 BUFPOS is the buffer position of OBJECT (different from POSITION if
4778 OBJECT is not a buffer). DISPLAY_REPLACED non-zero means that we
4779 previously saw a display specification which already replaced text
4780 display with something else, for example an image; we ignore such
4781 properties after the first one has been processed.
4783 OVERLAY is the overlay this `display' property came from,
4784 or nil if it was a text property.
4786 If SPEC is a `space' or `image' specification, and in some other
4787 cases too, set *POSITION to the position where the `display'
4790 If IT is NULL, only examine the property specification in SPEC, but
4791 don't set up IT. In that case, FRAME_WINDOW_P means SPEC
4792 is intended to be displayed in a window on a GUI frame.
4794 Value is non-zero if something was found which replaces the display
4795 of buffer or string text. */
4798 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4799 Lisp_Object overlay
, struct text_pos
*position
,
4800 ptrdiff_t bufpos
, int display_replaced
,
4801 bool frame_window_p
)
4804 Lisp_Object location
, value
;
4805 struct text_pos start_pos
= *position
;
4807 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4808 If the result is non-nil, use VALUE instead of SPEC. */
4810 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4819 if (!NILP (form
) && !EQ (form
, Qt
))
4821 ptrdiff_t count
= SPECPDL_INDEX ();
4823 /* Bind `object' to the object having the `display' property, a
4824 buffer or string. Bind `position' to the position in the
4825 object where the property was found, and `buffer-position'
4826 to the current position in the buffer. */
4829 XSETBUFFER (object
, current_buffer
);
4830 specbind (Qobject
, object
);
4831 specbind (Qposition
, make_number (CHARPOS (*position
)));
4832 specbind (Qbuffer_position
, make_number (bufpos
));
4833 form
= safe_eval (form
);
4834 unbind_to (count
, Qnil
);
4840 /* Handle `(height HEIGHT)' specifications. */
4842 && EQ (XCAR (spec
), Qheight
)
4843 && CONSP (XCDR (spec
)))
4847 if (!FRAME_WINDOW_P (it
->f
))
4850 it
->font_height
= XCAR (XCDR (spec
));
4851 if (!NILP (it
->font_height
))
4853 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4854 int new_height
= -1;
4856 if (CONSP (it
->font_height
)
4857 && (EQ (XCAR (it
->font_height
), Qplus
)
4858 || EQ (XCAR (it
->font_height
), Qminus
))
4859 && CONSP (XCDR (it
->font_height
))
4860 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4862 /* `(+ N)' or `(- N)' where N is an integer. */
4863 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4864 if (EQ (XCAR (it
->font_height
), Qplus
))
4866 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4868 else if (FUNCTIONP (it
->font_height
))
4870 /* Call function with current height as argument.
4871 Value is the new height. */
4873 height
= safe_call1 (it
->font_height
,
4874 face
->lface
[LFACE_HEIGHT_INDEX
]);
4875 if (NUMBERP (height
))
4876 new_height
= XFLOATINT (height
);
4878 else if (NUMBERP (it
->font_height
))
4880 /* Value is a multiple of the canonical char height. */
4883 f
= FACE_FROM_ID (it
->f
,
4884 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4885 new_height
= (XFLOATINT (it
->font_height
)
4886 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4890 /* Evaluate IT->font_height with `height' bound to the
4891 current specified height to get the new height. */
4892 ptrdiff_t count
= SPECPDL_INDEX ();
4894 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4895 value
= safe_eval (it
->font_height
);
4896 unbind_to (count
, Qnil
);
4898 if (NUMBERP (value
))
4899 new_height
= XFLOATINT (value
);
4903 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4910 /* Handle `(space-width WIDTH)'. */
4912 && EQ (XCAR (spec
), Qspace_width
)
4913 && CONSP (XCDR (spec
)))
4917 if (!FRAME_WINDOW_P (it
->f
))
4920 value
= XCAR (XCDR (spec
));
4921 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4922 it
->space_width
= value
;
4928 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4930 && EQ (XCAR (spec
), Qslice
))
4936 if (!FRAME_WINDOW_P (it
->f
))
4939 if (tem
= XCDR (spec
), CONSP (tem
))
4941 it
->slice
.x
= XCAR (tem
);
4942 if (tem
= XCDR (tem
), CONSP (tem
))
4944 it
->slice
.y
= XCAR (tem
);
4945 if (tem
= XCDR (tem
), CONSP (tem
))
4947 it
->slice
.width
= XCAR (tem
);
4948 if (tem
= XCDR (tem
), CONSP (tem
))
4949 it
->slice
.height
= XCAR (tem
);
4958 /* Handle `(raise FACTOR)'. */
4960 && EQ (XCAR (spec
), Qraise
)
4961 && CONSP (XCDR (spec
)))
4965 if (!FRAME_WINDOW_P (it
->f
))
4968 #ifdef HAVE_WINDOW_SYSTEM
4969 value
= XCAR (XCDR (spec
));
4970 if (NUMBERP (value
))
4972 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4973 it
->voffset
= - (XFLOATINT (value
)
4974 * (normal_char_height (face
->font
, -1)));
4976 #endif /* HAVE_WINDOW_SYSTEM */
4982 /* Don't handle the other kinds of display specifications
4983 inside a string that we got from a `display' property. */
4984 if (it
&& it
->string_from_display_prop_p
)
4987 /* Characters having this form of property are not displayed, so
4988 we have to find the end of the property. */
4991 start_pos
= *position
;
4992 *position
= display_prop_end (it
, object
, start_pos
);
4993 /* If the display property comes from an overlay, don't consider
4994 any potential stop_charpos values before the end of that
4995 overlay. Since display_prop_end will happily find another
4996 'display' property coming from some other overlay or text
4997 property on buffer positions before this overlay's end, we
4998 need to ignore them, or else we risk displaying this
4999 overlay's display string/image twice. */
5000 if (!NILP (overlay
))
5002 ptrdiff_t ovendpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5004 if (ovendpos
> CHARPOS (*position
))
5005 SET_TEXT_POS (*position
, ovendpos
, CHAR_TO_BYTE (ovendpos
));
5010 /* Stop the scan at that end position--we assume that all
5011 text properties change there. */
5013 it
->stop_charpos
= position
->charpos
;
5015 /* Handle `(left-fringe BITMAP [FACE])'
5016 and `(right-fringe BITMAP [FACE])'. */
5018 && (EQ (XCAR (spec
), Qleft_fringe
)
5019 || EQ (XCAR (spec
), Qright_fringe
))
5020 && CONSP (XCDR (spec
)))
5026 if (!FRAME_WINDOW_P (it
->f
))
5027 /* If we return here, POSITION has been advanced
5028 across the text with this property. */
5030 /* Synchronize the bidi iterator with POSITION. This is
5031 needed because we are not going to push the iterator
5032 on behalf of this display property, so there will be
5033 no pop_it call to do this synchronization for us. */
5036 it
->position
= *position
;
5037 iterate_out_of_display_property (it
);
5038 *position
= it
->position
;
5043 else if (!frame_window_p
)
5046 #ifdef HAVE_WINDOW_SYSTEM
5047 value
= XCAR (XCDR (spec
));
5048 if (!SYMBOLP (value
)
5049 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
5050 /* If we return here, POSITION has been advanced
5051 across the text with this property. */
5053 if (it
&& it
->bidi_p
)
5055 it
->position
= *position
;
5056 iterate_out_of_display_property (it
);
5057 *position
= it
->position
;
5064 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
5066 if (CONSP (XCDR (XCDR (spec
))))
5068 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
5069 int face_id2
= lookup_derived_face (it
->f
, face_name
,
5070 FRINGE_FACE_ID
, false);
5075 /* Save current settings of IT so that we can restore them
5076 when we are finished with the glyph property value. */
5077 push_it (it
, position
);
5079 it
->area
= TEXT_AREA
;
5080 it
->what
= IT_IMAGE
;
5081 it
->image_id
= -1; /* no image */
5082 it
->position
= start_pos
;
5083 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5084 it
->method
= GET_FROM_IMAGE
;
5085 it
->from_overlay
= Qnil
;
5086 it
->face_id
= face_id
;
5087 it
->from_disp_prop_p
= true;
5089 /* Say that we haven't consumed the characters with
5090 `display' property yet. The call to pop_it in
5091 set_iterator_to_next will clean this up. */
5092 *position
= start_pos
;
5094 if (EQ (XCAR (spec
), Qleft_fringe
))
5096 it
->left_user_fringe_bitmap
= fringe_bitmap
;
5097 it
->left_user_fringe_face_id
= face_id
;
5101 it
->right_user_fringe_bitmap
= fringe_bitmap
;
5102 it
->right_user_fringe_face_id
= face_id
;
5105 #endif /* HAVE_WINDOW_SYSTEM */
5109 /* Prepare to handle `((margin left-margin) ...)',
5110 `((margin right-margin) ...)' and `((margin nil) ...)'
5111 prefixes for display specifications. */
5112 location
= Qunbound
;
5113 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5117 value
= XCDR (spec
);
5119 value
= XCAR (value
);
5122 if (EQ (XCAR (tem
), Qmargin
)
5123 && (tem
= XCDR (tem
),
5124 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5126 || EQ (tem
, Qleft_margin
)
5127 || EQ (tem
, Qright_margin
))))
5131 if (EQ (location
, Qunbound
))
5137 /* After this point, VALUE is the property after any
5138 margin prefix has been stripped. It must be a string,
5139 an image specification, or `(space ...)'.
5141 LOCATION specifies where to display: `left-margin',
5142 `right-margin' or nil. */
5144 bool valid_p
= (STRINGP (value
)
5145 #ifdef HAVE_WINDOW_SYSTEM
5146 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5147 && valid_image_p (value
))
5148 #endif /* not HAVE_WINDOW_SYSTEM */
5149 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5150 #ifdef HAVE_XWIDGETS
5151 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5152 && valid_xwidget_spec_p (value
))
5156 if (valid_p
&& display_replaced
== 0)
5162 /* Callers need to know whether the display spec is any kind
5163 of `(space ...)' spec that is about to affect text-area
5165 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5170 /* Save current settings of IT so that we can restore them
5171 when we are finished with the glyph property value. */
5172 push_it (it
, position
);
5173 it
->from_overlay
= overlay
;
5174 it
->from_disp_prop_p
= true;
5176 if (NILP (location
))
5177 it
->area
= TEXT_AREA
;
5178 else if (EQ (location
, Qleft_margin
))
5179 it
->area
= LEFT_MARGIN_AREA
;
5181 it
->area
= RIGHT_MARGIN_AREA
;
5183 if (STRINGP (value
))
5186 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5187 it
->current
.overlay_string_index
= -1;
5188 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5189 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5190 it
->method
= GET_FROM_STRING
;
5191 it
->stop_charpos
= 0;
5193 it
->base_level_stop
= 0;
5194 it
->string_from_display_prop_p
= true;
5195 /* Say that we haven't consumed the characters with
5196 `display' property yet. The call to pop_it in
5197 set_iterator_to_next will clean this up. */
5198 if (BUFFERP (object
))
5199 *position
= start_pos
;
5201 /* Force paragraph direction to be that of the parent
5202 object. If the parent object's paragraph direction is
5203 not yet determined, default to L2R. */
5204 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5205 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5207 it
->paragraph_embedding
= L2R
;
5209 /* Set up the bidi iterator for this display string. */
5212 it
->bidi_it
.string
.lstring
= it
->string
;
5213 it
->bidi_it
.string
.s
= NULL
;
5214 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5215 it
->bidi_it
.string
.bufpos
= bufpos
;
5216 it
->bidi_it
.string
.from_disp_str
= true;
5217 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5218 it
->bidi_it
.w
= it
->w
;
5219 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5222 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5224 it
->method
= GET_FROM_STRETCH
;
5226 *position
= it
->position
= start_pos
;
5227 retval
= 1 + (it
->area
== TEXT_AREA
);
5229 #ifdef HAVE_XWIDGETS
5230 else if (valid_xwidget_spec_p(value
))
5232 it
->what
= IT_XWIDGET
;
5233 it
->method
= GET_FROM_XWIDGET
;
5234 it
->position
= start_pos
;
5235 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5236 *position
= start_pos
;
5237 it
->xwidget
= lookup_xwidget(value
);
5240 #ifdef HAVE_WINDOW_SYSTEM
5243 it
->what
= IT_IMAGE
;
5244 it
->image_id
= lookup_image (it
->f
, value
);
5245 it
->position
= start_pos
;
5246 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5247 it
->method
= GET_FROM_IMAGE
;
5249 /* Say that we haven't consumed the characters with
5250 `display' property yet. The call to pop_it in
5251 set_iterator_to_next will clean this up. */
5252 *position
= start_pos
;
5254 #endif /* HAVE_WINDOW_SYSTEM */
5259 /* Invalid property or property not supported. Restore
5260 POSITION to what it was before. */
5261 *position
= start_pos
;
5265 /* Check if PROP is a display property value whose text should be
5266 treated as intangible. OVERLAY is the overlay from which PROP
5267 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5268 specify the buffer position covered by PROP. */
5271 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5272 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5274 bool frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5275 struct text_pos position
;
5277 SET_TEXT_POS (position
, charpos
, bytepos
);
5278 return (handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5279 &position
, charpos
, frame_window_p
)
5284 /* Return true if PROP is a display sub-property value containing STRING.
5286 Implementation note: this and the following function are really
5287 special cases of handle_display_spec and
5288 handle_single_display_spec, and should ideally use the same code.
5289 Until they do, these two pairs must be consistent and must be
5290 modified in sync. */
5293 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5295 if (EQ (string
, prop
))
5298 /* Skip over `when FORM'. */
5299 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5304 /* Actually, the condition following `when' should be eval'ed,
5305 like handle_single_display_spec does, and we should return
5306 false if it evaluates to nil. However, this function is
5307 called only when the buffer was already displayed and some
5308 glyph in the glyph matrix was found to come from a display
5309 string. Therefore, the condition was already evaluated, and
5310 the result was non-nil, otherwise the display string wouldn't
5311 have been displayed and we would have never been called for
5312 this property. Thus, we can skip the evaluation and assume
5313 its result is non-nil. */
5318 /* Skip over `margin LOCATION'. */
5319 if (EQ (XCAR (prop
), Qmargin
))
5330 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5334 /* Return true if STRING appears in the `display' property PROP. */
5337 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5340 && !EQ (XCAR (prop
), Qwhen
)
5341 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5343 /* A list of sub-properties. */
5344 while (CONSP (prop
))
5346 if (single_display_spec_string_p (XCAR (prop
), string
))
5351 else if (VECTORP (prop
))
5353 /* A vector of sub-properties. */
5355 for (i
= 0; i
< ASIZE (prop
); ++i
)
5356 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5360 return single_display_spec_string_p (prop
, string
);
5365 /* Look for STRING in overlays and text properties in the current
5366 buffer, between character positions FROM and TO (excluding TO).
5367 BACK_P means look back (in this case, TO is supposed to be
5369 Value is the first character position where STRING was found, or
5370 zero if it wasn't found before hitting TO.
5372 This function may only use code that doesn't eval because it is
5373 called asynchronously from note_mouse_highlight. */
5376 string_buffer_position_lim (Lisp_Object string
,
5377 ptrdiff_t from
, ptrdiff_t to
, bool back_p
)
5379 Lisp_Object limit
, prop
, pos
;
5382 pos
= make_number (max (from
, BEGV
));
5384 if (!back_p
) /* looking forward */
5386 limit
= make_number (min (to
, ZV
));
5387 while (!found
&& !EQ (pos
, limit
))
5389 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5390 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5393 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5397 else /* looking back */
5399 limit
= make_number (max (to
, BEGV
));
5400 while (!found
&& !EQ (pos
, limit
))
5402 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5403 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5406 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5411 return found
? XINT (pos
) : 0;
5414 /* Determine which buffer position in current buffer STRING comes from.
5415 AROUND_CHARPOS is an approximate position where it could come from.
5416 Value is the buffer position or 0 if it couldn't be determined.
5418 This function is necessary because we don't record buffer positions
5419 in glyphs generated from strings (to keep struct glyph small).
5420 This function may only use code that doesn't eval because it is
5421 called asynchronously from note_mouse_highlight. */
5424 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5426 const int MAX_DISTANCE
= 1000;
5427 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5428 around_charpos
+ MAX_DISTANCE
,
5432 found
= string_buffer_position_lim (string
, around_charpos
,
5433 around_charpos
- MAX_DISTANCE
, true);
5439 /***********************************************************************
5440 `composition' property
5441 ***********************************************************************/
5443 /* Set up iterator IT from `composition' property at its current
5444 position. Called from handle_stop. */
5446 static enum prop_handled
5447 handle_composition_prop (struct it
*it
)
5449 Lisp_Object prop
, string
;
5450 ptrdiff_t pos
, pos_byte
, start
, end
;
5452 if (STRINGP (it
->string
))
5456 pos
= IT_STRING_CHARPOS (*it
);
5457 pos_byte
= IT_STRING_BYTEPOS (*it
);
5458 string
= it
->string
;
5459 s
= SDATA (string
) + pos_byte
;
5460 it
->c
= STRING_CHAR (s
);
5464 pos
= IT_CHARPOS (*it
);
5465 pos_byte
= IT_BYTEPOS (*it
);
5467 it
->c
= FETCH_CHAR (pos_byte
);
5470 /* If there's a valid composition and point is not inside of the
5471 composition (in the case that the composition is from the current
5472 buffer), draw a glyph composed from the composition components. */
5473 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5474 && composition_valid_p (start
, end
, prop
)
5475 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5478 /* As we can't handle this situation (perhaps font-lock added
5479 a new composition), we just return here hoping that next
5480 redisplay will detect this composition much earlier. */
5481 return HANDLED_NORMALLY
;
5484 if (STRINGP (it
->string
))
5485 pos_byte
= string_char_to_byte (it
->string
, start
);
5487 pos_byte
= CHAR_TO_BYTE (start
);
5489 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5492 if (it
->cmp_it
.id
>= 0)
5495 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5496 it
->cmp_it
.nglyphs
= -1;
5500 return HANDLED_NORMALLY
;
5505 /***********************************************************************
5507 ***********************************************************************/
5509 /* The following structure is used to record overlay strings for
5510 later sorting in load_overlay_strings. */
5512 struct overlay_entry
5514 Lisp_Object overlay
;
5517 bool after_string_p
;
5521 /* Set up iterator IT from overlay strings at its current position.
5522 Called from handle_stop. */
5524 static enum prop_handled
5525 handle_overlay_change (struct it
*it
)
5527 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5528 return HANDLED_RECOMPUTE_PROPS
;
5530 return HANDLED_NORMALLY
;
5534 /* Set up the next overlay string for delivery by IT, if there is an
5535 overlay string to deliver. Called by set_iterator_to_next when the
5536 end of the current overlay string is reached. If there are more
5537 overlay strings to display, IT->string and
5538 IT->current.overlay_string_index are set appropriately here.
5539 Otherwise IT->string is set to nil. */
5542 next_overlay_string (struct it
*it
)
5544 ++it
->current
.overlay_string_index
;
5545 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5547 /* No more overlay strings. Restore IT's settings to what
5548 they were before overlay strings were processed, and
5549 continue to deliver from current_buffer. */
5551 it
->ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
5554 || (NILP (it
->string
)
5555 && it
->method
== GET_FROM_BUFFER
5556 && it
->stop_charpos
>= BEGV
5557 && it
->stop_charpos
<= it
->end_charpos
));
5558 it
->current
.overlay_string_index
= -1;
5559 it
->n_overlay_strings
= 0;
5560 /* If there's an empty display string on the stack, pop the
5561 stack, to resync the bidi iterator with IT's position. Such
5562 empty strings are pushed onto the stack in
5563 get_overlay_strings_1. */
5564 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5567 /* Since we've exhausted overlay strings at this buffer
5568 position, set the flag to ignore overlays until we move to
5569 another position. The flag is reset in
5570 next_element_from_buffer. */
5571 it
->ignore_overlay_strings_at_pos_p
= true;
5573 /* If we're at the end of the buffer, record that we have
5574 processed the overlay strings there already, so that
5575 next_element_from_buffer doesn't try it again. */
5576 if (NILP (it
->string
)
5577 && IT_CHARPOS (*it
) >= it
->end_charpos
5578 && it
->overlay_strings_charpos
>= it
->end_charpos
)
5579 it
->overlay_strings_at_end_processed_p
= true;
5580 /* Note: we reset overlay_strings_charpos only here, to make
5581 sure the just-processed overlays were indeed at EOB.
5582 Otherwise, overlays on text with invisible text property,
5583 which are processed with IT's position past the invisible
5584 text, might fool us into thinking the overlays at EOB were
5585 already processed (linum-mode can cause this, for
5587 it
->overlay_strings_charpos
= -1;
5591 /* There are more overlay strings to process. If
5592 IT->current.overlay_string_index has advanced to a position
5593 where we must load IT->overlay_strings with more strings, do
5594 it. We must load at the IT->overlay_strings_charpos where
5595 IT->n_overlay_strings was originally computed; when invisible
5596 text is present, this might not be IT_CHARPOS (Bug#7016). */
5597 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5599 if (it
->current
.overlay_string_index
&& i
== 0)
5600 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5602 /* Initialize IT to deliver display elements from the overlay
5604 it
->string
= it
->overlay_strings
[i
];
5605 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5606 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5607 it
->method
= GET_FROM_STRING
;
5608 it
->stop_charpos
= 0;
5609 it
->end_charpos
= SCHARS (it
->string
);
5610 if (it
->cmp_it
.stop_pos
>= 0)
5611 it
->cmp_it
.stop_pos
= 0;
5613 it
->base_level_stop
= 0;
5615 /* Set up the bidi iterator for this overlay string. */
5618 it
->bidi_it
.string
.lstring
= it
->string
;
5619 it
->bidi_it
.string
.s
= NULL
;
5620 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5621 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5622 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5623 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5624 it
->bidi_it
.w
= it
->w
;
5625 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5633 /* Compare two overlay_entry structures E1 and E2. Used as a
5634 comparison function for qsort in load_overlay_strings. Overlay
5635 strings for the same position are sorted so that
5637 1. All after-strings come in front of before-strings, except
5638 when they come from the same overlay.
5640 2. Within after-strings, strings are sorted so that overlay strings
5641 from overlays with higher priorities come first.
5643 2. Within before-strings, strings are sorted so that overlay
5644 strings from overlays with higher priorities come last.
5646 Value is analogous to strcmp. */
5650 compare_overlay_entries (const void *e1
, const void *e2
)
5652 struct overlay_entry
const *entry1
= e1
;
5653 struct overlay_entry
const *entry2
= e2
;
5656 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5658 /* Let after-strings appear in front of before-strings if
5659 they come from different overlays. */
5660 if (EQ (entry1
->overlay
, entry2
->overlay
))
5661 result
= entry1
->after_string_p
? 1 : -1;
5663 result
= entry1
->after_string_p
? -1 : 1;
5665 else if (entry1
->priority
!= entry2
->priority
)
5667 if (entry1
->after_string_p
)
5668 /* After-strings sorted in order of decreasing priority. */
5669 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5671 /* Before-strings sorted in order of increasing priority. */
5672 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5681 /* Load the vector IT->overlay_strings with overlay strings from IT's
5682 current buffer position, or from CHARPOS if that is > 0. Set
5683 IT->n_overlays to the total number of overlay strings found.
5685 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5686 a time. On entry into load_overlay_strings,
5687 IT->current.overlay_string_index gives the number of overlay
5688 strings that have already been loaded by previous calls to this
5691 IT->add_overlay_start contains an additional overlay start
5692 position to consider for taking overlay strings from, if non-zero.
5693 This position comes into play when the overlay has an `invisible'
5694 property, and both before and after-strings. When we've skipped to
5695 the end of the overlay, because of its `invisible' property, we
5696 nevertheless want its before-string to appear.
5697 IT->add_overlay_start will contain the overlay start position
5700 Overlay strings are sorted so that after-string strings come in
5701 front of before-string strings. Within before and after-strings,
5702 strings are sorted by overlay priority. See also function
5703 compare_overlay_entries. */
5706 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5708 Lisp_Object overlay
, window
, str
, invisible
;
5709 struct Lisp_Overlay
*ov
;
5710 ptrdiff_t start
, end
;
5711 ptrdiff_t n
= 0, i
, j
;
5713 struct overlay_entry entriesbuf
[20];
5714 ptrdiff_t size
= ARRAYELTS (entriesbuf
);
5715 struct overlay_entry
*entries
= entriesbuf
;
5719 charpos
= IT_CHARPOS (*it
);
5721 /* Append the overlay string STRING of overlay OVERLAY to vector
5722 `entries' which has size `size' and currently contains `n'
5723 elements. AFTER_P means STRING is an after-string of
5725 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5728 Lisp_Object priority; \
5732 struct overlay_entry *old = entries; \
5733 SAFE_NALLOCA (entries, 2, size); \
5734 memcpy (entries, old, size * sizeof *entries); \
5738 entries[n].string = (STRING); \
5739 entries[n].overlay = (OVERLAY); \
5740 priority = Foverlay_get ((OVERLAY), Qpriority); \
5741 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5742 entries[n].after_string_p = (AFTER_P); \
5747 /* Process overlay before the overlay center. */
5748 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5750 XSETMISC (overlay
, ov
);
5751 eassert (OVERLAYP (overlay
));
5752 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5753 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5758 /* Skip this overlay if it doesn't start or end at IT's current
5760 if (end
!= charpos
&& start
!= charpos
)
5763 /* Skip this overlay if it doesn't apply to IT->w. */
5764 window
= Foverlay_get (overlay
, Qwindow
);
5765 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5768 /* If the text ``under'' the overlay is invisible, both before-
5769 and after-strings from this overlay are visible; start and
5770 end position are indistinguishable. */
5771 invisible
= Foverlay_get (overlay
, Qinvisible
);
5772 invis
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5774 /* If overlay has a non-empty before-string, record it. */
5775 if ((start
== charpos
|| (end
== charpos
&& invis
!= 0))
5776 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5778 RECORD_OVERLAY_STRING (overlay
, str
, false);
5780 /* If overlay has a non-empty after-string, record it. */
5781 if ((end
== charpos
|| (start
== charpos
&& invis
!= 0))
5782 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5784 RECORD_OVERLAY_STRING (overlay
, str
, true);
5787 /* Process overlays after the overlay center. */
5788 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5790 XSETMISC (overlay
, ov
);
5791 eassert (OVERLAYP (overlay
));
5792 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5793 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5795 if (start
> charpos
)
5798 /* Skip this overlay if it doesn't start or end at IT's current
5800 if (end
!= charpos
&& start
!= charpos
)
5803 /* Skip this overlay if it doesn't apply to IT->w. */
5804 window
= Foverlay_get (overlay
, Qwindow
);
5805 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5808 /* If the text ``under'' the overlay is invisible, it has a zero
5809 dimension, and both before- and after-strings apply. */
5810 invisible
= Foverlay_get (overlay
, Qinvisible
);
5811 invis
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5813 /* If overlay has a non-empty before-string, record it. */
5814 if ((start
== charpos
|| (end
== charpos
&& invis
!= 0))
5815 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5817 RECORD_OVERLAY_STRING (overlay
, str
, false);
5819 /* If overlay has a non-empty after-string, record it. */
5820 if ((end
== charpos
|| (start
== charpos
&& invis
!= 0))
5821 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5823 RECORD_OVERLAY_STRING (overlay
, str
, true);
5826 #undef RECORD_OVERLAY_STRING
5830 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5832 /* Record number of overlay strings, and where we computed it. */
5833 it
->n_overlay_strings
= n
;
5834 it
->overlay_strings_charpos
= charpos
;
5836 /* IT->current.overlay_string_index is the number of overlay strings
5837 that have already been consumed by IT. Copy some of the
5838 remaining overlay strings to IT->overlay_strings. */
5840 j
= it
->current
.overlay_string_index
;
5841 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5843 it
->overlay_strings
[i
] = entries
[j
].string
;
5844 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5852 /* Get the first chunk of overlay strings at IT's current buffer
5853 position, or at CHARPOS if that is > 0. Value is true if at
5854 least one overlay string was found. */
5857 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, bool compute_stop_p
)
5859 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5860 process. This fills IT->overlay_strings with strings, and sets
5861 IT->n_overlay_strings to the total number of strings to process.
5862 IT->pos.overlay_string_index has to be set temporarily to zero
5863 because load_overlay_strings needs this; it must be set to -1
5864 when no overlay strings are found because a zero value would
5865 indicate a position in the first overlay string. */
5866 it
->current
.overlay_string_index
= 0;
5867 load_overlay_strings (it
, charpos
);
5869 /* If we found overlay strings, set up IT to deliver display
5870 elements from the first one. Otherwise set up IT to deliver
5871 from current_buffer. */
5872 if (it
->n_overlay_strings
)
5874 /* Make sure we know settings in current_buffer, so that we can
5875 restore meaningful values when we're done with the overlay
5878 compute_stop_pos (it
);
5879 eassert (it
->face_id
>= 0);
5881 /* Save IT's settings. They are restored after all overlay
5882 strings have been processed. */
5883 eassert (!compute_stop_p
|| it
->sp
== 0);
5885 /* When called from handle_stop, there might be an empty display
5886 string loaded. In that case, don't bother saving it. But
5887 don't use this optimization with the bidi iterator, since we
5888 need the corresponding pop_it call to resync the bidi
5889 iterator's position with IT's position, after we are done
5890 with the overlay strings. (The corresponding call to pop_it
5891 in case of an empty display string is in
5892 next_overlay_string.) */
5894 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5897 /* Set up IT to deliver display elements from the first overlay
5899 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5900 it
->string
= it
->overlay_strings
[0];
5901 it
->from_overlay
= Qnil
;
5902 it
->stop_charpos
= 0;
5903 eassert (STRINGP (it
->string
));
5904 it
->end_charpos
= SCHARS (it
->string
);
5906 it
->base_level_stop
= 0;
5907 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5908 it
->method
= GET_FROM_STRING
;
5909 it
->from_disp_prop_p
= 0;
5911 /* Force paragraph direction to be that of the parent
5913 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5914 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5916 it
->paragraph_embedding
= L2R
;
5918 /* Set up the bidi iterator for this overlay string. */
5921 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5923 it
->bidi_it
.string
.lstring
= it
->string
;
5924 it
->bidi_it
.string
.s
= NULL
;
5925 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5926 it
->bidi_it
.string
.bufpos
= pos
;
5927 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5928 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5929 it
->bidi_it
.w
= it
->w
;
5930 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5935 it
->current
.overlay_string_index
= -1;
5940 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5943 it
->method
= GET_FROM_BUFFER
;
5945 get_overlay_strings_1 (it
, charpos
, true);
5949 /* Value is true if we found at least one overlay string. */
5950 return STRINGP (it
->string
);
5955 /***********************************************************************
5956 Saving and restoring state
5957 ***********************************************************************/
5959 /* Save current settings of IT on IT->stack. Called, for example,
5960 before setting up IT for an overlay string, to be able to restore
5961 IT's settings to what they were after the overlay string has been
5962 processed. If POSITION is non-NULL, it is the position to save on
5963 the stack instead of IT->position. */
5966 push_it (struct it
*it
, struct text_pos
*position
)
5968 struct iterator_stack_entry
*p
;
5970 eassert (it
->sp
< IT_STACK_SIZE
);
5971 p
= it
->stack
+ it
->sp
;
5973 p
->stop_charpos
= it
->stop_charpos
;
5974 p
->prev_stop
= it
->prev_stop
;
5975 p
->base_level_stop
= it
->base_level_stop
;
5976 p
->cmp_it
= it
->cmp_it
;
5977 eassert (it
->face_id
>= 0);
5978 p
->face_id
= it
->face_id
;
5979 p
->string
= it
->string
;
5980 p
->method
= it
->method
;
5981 p
->from_overlay
= it
->from_overlay
;
5984 case GET_FROM_IMAGE
:
5985 p
->u
.image
.object
= it
->object
;
5986 p
->u
.image
.image_id
= it
->image_id
;
5987 p
->u
.image
.slice
= it
->slice
;
5989 case GET_FROM_STRETCH
:
5990 p
->u
.stretch
.object
= it
->object
;
5992 #ifdef HAVE_XWIDGETS
5993 case GET_FROM_XWIDGET
:
5994 p
->u
.xwidget
.object
= it
->object
;
5997 case GET_FROM_BUFFER
:
5998 case GET_FROM_DISPLAY_VECTOR
:
5999 case GET_FROM_STRING
:
6000 case GET_FROM_C_STRING
:
6005 p
->position
= position
? *position
: it
->position
;
6006 p
->current
= it
->current
;
6007 p
->end_charpos
= it
->end_charpos
;
6008 p
->string_nchars
= it
->string_nchars
;
6010 p
->multibyte_p
= it
->multibyte_p
;
6011 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
6012 p
->space_width
= it
->space_width
;
6013 p
->font_height
= it
->font_height
;
6014 p
->voffset
= it
->voffset
;
6015 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
6016 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
6017 p
->display_ellipsis_p
= false;
6018 p
->line_wrap
= it
->line_wrap
;
6019 p
->bidi_p
= it
->bidi_p
;
6020 p
->paragraph_embedding
= it
->paragraph_embedding
;
6021 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
6024 /* Save the state of the bidi iterator as well. */
6026 bidi_push_it (&it
->bidi_it
);
6030 iterate_out_of_display_property (struct it
*it
)
6032 bool buffer_p
= !STRINGP (it
->string
);
6033 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
6034 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
6036 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
6038 /* Maybe initialize paragraph direction. If we are at the beginning
6039 of a new paragraph, next_element_from_buffer may not have a
6040 chance to do that. */
6041 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
6042 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
6043 /* prev_stop can be zero, so check against BEGV as well. */
6044 while (it
->bidi_it
.charpos
>= bob
6045 && it
->prev_stop
<= it
->bidi_it
.charpos
6046 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
6047 && it
->bidi_it
.charpos
< eob
)
6048 bidi_move_to_visually_next (&it
->bidi_it
);
6049 /* Record the stop_pos we just crossed, for when we cross it
6051 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
6052 it
->prev_stop
= CHARPOS (it
->position
);
6053 /* If we ended up not where pop_it put us, resync IT's
6054 positional members with the bidi iterator. */
6055 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
6056 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
6058 it
->current
.pos
= it
->position
;
6060 it
->current
.string_pos
= it
->position
;
6063 /* Restore IT's settings from IT->stack. Called, for example, when no
6064 more overlay strings must be processed, and we return to delivering
6065 display elements from a buffer, or when the end of a string from a
6066 `display' property is reached and we return to delivering display
6067 elements from an overlay string, or from a buffer. */
6070 pop_it (struct it
*it
)
6072 struct iterator_stack_entry
*p
;
6073 bool from_display_prop
= it
->from_disp_prop_p
;
6074 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
6076 eassert (it
->sp
> 0);
6078 p
= it
->stack
+ it
->sp
;
6079 it
->stop_charpos
= p
->stop_charpos
;
6080 it
->prev_stop
= p
->prev_stop
;
6081 it
->base_level_stop
= p
->base_level_stop
;
6082 it
->cmp_it
= p
->cmp_it
;
6083 it
->face_id
= p
->face_id
;
6084 it
->current
= p
->current
;
6085 it
->position
= p
->position
;
6086 it
->string
= p
->string
;
6087 it
->from_overlay
= p
->from_overlay
;
6088 if (NILP (it
->string
))
6089 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
6090 it
->method
= p
->method
;
6093 case GET_FROM_IMAGE
:
6094 it
->image_id
= p
->u
.image
.image_id
;
6095 it
->object
= p
->u
.image
.object
;
6096 it
->slice
= p
->u
.image
.slice
;
6098 #ifdef HAVE_XWIDGETS
6099 case GET_FROM_XWIDGET
:
6100 it
->object
= p
->u
.xwidget
.object
;
6103 case GET_FROM_STRETCH
:
6104 it
->object
= p
->u
.stretch
.object
;
6106 case GET_FROM_BUFFER
:
6107 it
->object
= it
->w
->contents
;
6109 case GET_FROM_STRING
:
6111 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6113 /* Restore the face_box_p flag, since it could have been
6114 overwritten by the face of the object that we just finished
6117 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
6118 it
->object
= it
->string
;
6121 case GET_FROM_DISPLAY_VECTOR
:
6123 it
->method
= GET_FROM_C_STRING
;
6124 else if (STRINGP (it
->string
))
6125 it
->method
= GET_FROM_STRING
;
6128 it
->method
= GET_FROM_BUFFER
;
6129 it
->object
= it
->w
->contents
;
6132 case GET_FROM_C_STRING
:
6137 it
->end_charpos
= p
->end_charpos
;
6138 it
->string_nchars
= p
->string_nchars
;
6140 it
->multibyte_p
= p
->multibyte_p
;
6141 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
6142 it
->space_width
= p
->space_width
;
6143 it
->font_height
= p
->font_height
;
6144 it
->voffset
= p
->voffset
;
6145 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
6146 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
6147 it
->line_wrap
= p
->line_wrap
;
6148 it
->bidi_p
= p
->bidi_p
;
6149 it
->paragraph_embedding
= p
->paragraph_embedding
;
6150 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
6153 bidi_pop_it (&it
->bidi_it
);
6154 /* Bidi-iterate until we get out of the portion of text, if any,
6155 covered by a `display' text property or by an overlay with
6156 `display' property. (We cannot just jump there, because the
6157 internal coherency of the bidi iterator state can not be
6158 preserved across such jumps.) We also must determine the
6159 paragraph base direction if the overlay we just processed is
6160 at the beginning of a new paragraph. */
6161 if (from_display_prop
6162 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
6163 iterate_out_of_display_property (it
);
6165 eassert ((BUFFERP (it
->object
)
6166 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
6167 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6168 || (STRINGP (it
->object
)
6169 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
6170 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6171 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6173 /* If we move the iterator over text covered by a display property
6174 to a new buffer position, any info about previously seen overlays
6175 is no longer valid. */
6176 if (from_display_prop
&& it
->sp
== 0 && CHARPOS (it
->position
) != prev_pos
)
6177 it
->ignore_overlay_strings_at_pos_p
= false;
6182 /***********************************************************************
6184 ***********************************************************************/
6186 /* Set IT's current position to the previous line start. */
6189 back_to_previous_line_start (struct it
*it
)
6191 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6194 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6198 /* Move IT to the next line start.
6200 Value is true if a newline was found. Set *SKIPPED_P to true if
6201 we skipped over part of the text (as opposed to moving the iterator
6202 continuously over the text). Otherwise, don't change the value
6205 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6206 iterator on the newline, if it was found.
6208 Newlines may come from buffer text, overlay strings, or strings
6209 displayed via the `display' property. That's the reason we can't
6210 simply use find_newline_no_quit.
6212 Note that this function may not skip over invisible text that is so
6213 because of text properties and immediately follows a newline. If
6214 it would, function reseat_at_next_visible_line_start, when called
6215 from set_iterator_to_next, would effectively make invisible
6216 characters following a newline part of the wrong glyph row, which
6217 leads to wrong cursor motion. */
6220 forward_to_next_line_start (struct it
*it
, bool *skipped_p
,
6221 struct bidi_it
*bidi_it_prev
)
6223 ptrdiff_t old_selective
;
6224 bool newline_found_p
= false;
6226 const int MAX_NEWLINE_DISTANCE
= 500;
6228 /* If already on a newline, just consume it to avoid unintended
6229 skipping over invisible text below. */
6230 if (it
->what
== IT_CHARACTER
6232 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6234 if (it
->bidi_p
&& bidi_it_prev
)
6235 *bidi_it_prev
= it
->bidi_it
;
6236 set_iterator_to_next (it
, false);
6241 /* Don't handle selective display in the following. It's (a)
6242 unnecessary because it's done by the caller, and (b) leads to an
6243 infinite recursion because next_element_from_ellipsis indirectly
6244 calls this function. */
6245 old_selective
= it
->selective
;
6248 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6249 from buffer text. */
6251 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6252 n
+= !STRINGP (it
->string
))
6254 if (!get_next_display_element (it
))
6256 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6257 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6258 *bidi_it_prev
= it
->bidi_it
;
6259 set_iterator_to_next (it
, false);
6262 /* If we didn't find a newline near enough, see if we can use a
6264 if (!newline_found_p
)
6266 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6267 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6271 eassert (!STRINGP (it
->string
));
6273 /* If there isn't any `display' property in sight, and no
6274 overlays, we can just use the position of the newline in
6276 if (it
->stop_charpos
>= limit
6277 || ((pos
= Fnext_single_property_change (make_number (start
),
6279 make_number (limit
)),
6281 && next_overlay_change (start
) == ZV
))
6285 IT_CHARPOS (*it
) = limit
;
6286 IT_BYTEPOS (*it
) = bytepos
;
6290 struct bidi_it bprev
;
6292 /* Help bidi.c avoid expensive searches for display
6293 properties and overlays, by telling it that there are
6294 none up to `limit'. */
6295 if (it
->bidi_it
.disp_pos
< limit
)
6297 it
->bidi_it
.disp_pos
= limit
;
6298 it
->bidi_it
.disp_prop
= 0;
6301 bprev
= it
->bidi_it
;
6302 bidi_move_to_visually_next (&it
->bidi_it
);
6303 } while (it
->bidi_it
.charpos
!= limit
);
6304 IT_CHARPOS (*it
) = limit
;
6305 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6307 *bidi_it_prev
= bprev
;
6309 *skipped_p
= newline_found_p
= true;
6313 while (get_next_display_element (it
)
6314 && !newline_found_p
)
6316 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6317 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6318 *bidi_it_prev
= it
->bidi_it
;
6319 set_iterator_to_next (it
, false);
6324 it
->selective
= old_selective
;
6325 return newline_found_p
;
6329 /* Set IT's current position to the previous visible line start. Skip
6330 invisible text that is so either due to text properties or due to
6331 selective display. Caution: this does not change IT->current_x and
6335 back_to_previous_visible_line_start (struct it
*it
)
6337 while (IT_CHARPOS (*it
) > BEGV
)
6339 back_to_previous_line_start (it
);
6341 if (IT_CHARPOS (*it
) <= BEGV
)
6344 /* If selective > 0, then lines indented more than its value are
6346 if (it
->selective
> 0
6347 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6351 /* Check the newline before point for invisibility. */
6354 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6355 Qinvisible
, it
->window
);
6356 if (TEXT_PROP_MEANS_INVISIBLE (prop
) != 0)
6360 if (IT_CHARPOS (*it
) <= BEGV
)
6365 void *it2data
= NULL
;
6368 Lisp_Object val
, overlay
;
6370 SAVE_IT (it2
, *it
, it2data
);
6372 /* If newline is part of a composition, continue from start of composition */
6373 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6374 && beg
< IT_CHARPOS (*it
))
6377 /* If newline is replaced by a display property, find start of overlay
6378 or interval and continue search from that point. */
6379 pos
= --IT_CHARPOS (it2
);
6382 bidi_unshelve_cache (NULL
, false);
6383 it2
.string_from_display_prop_p
= false;
6384 it2
.from_disp_prop_p
= false;
6385 if (handle_display_prop (&it2
) == HANDLED_RETURN
6386 && !NILP (val
= get_char_property_and_overlay
6387 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6388 && (OVERLAYP (overlay
)
6389 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6390 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6392 RESTORE_IT (it
, it
, it2data
);
6396 /* Newline is not replaced by anything -- so we are done. */
6397 RESTORE_IT (it
, it
, it2data
);
6403 IT_CHARPOS (*it
) = beg
;
6404 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6408 it
->continuation_lines_width
= 0;
6410 eassert (IT_CHARPOS (*it
) >= BEGV
);
6411 eassert (IT_CHARPOS (*it
) == BEGV
6412 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6417 /* Reseat iterator IT at the previous visible line start. Skip
6418 invisible text that is so either due to text properties or due to
6419 selective display. At the end, update IT's overlay information,
6420 face information etc. */
6423 reseat_at_previous_visible_line_start (struct it
*it
)
6425 back_to_previous_visible_line_start (it
);
6426 reseat (it
, it
->current
.pos
, true);
6431 /* Reseat iterator IT on the next visible line start in the current
6432 buffer. ON_NEWLINE_P means position IT on the newline
6433 preceding the line start. Skip over invisible text that is so
6434 because of selective display. Compute faces, overlays etc at the
6435 new position. Note that this function does not skip over text that
6436 is invisible because of text properties. */
6439 reseat_at_next_visible_line_start (struct it
*it
, bool on_newline_p
)
6441 bool skipped_p
= false;
6442 struct bidi_it bidi_it_prev
;
6443 bool newline_found_p
6444 = forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6446 /* Skip over lines that are invisible because they are indented
6447 more than the value of IT->selective. */
6448 if (it
->selective
> 0)
6449 while (IT_CHARPOS (*it
) < ZV
6450 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6453 eassert (IT_BYTEPOS (*it
) == BEGV
6454 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6456 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6459 /* Position on the newline if that's what's requested. */
6460 if (on_newline_p
&& newline_found_p
)
6462 if (STRINGP (it
->string
))
6464 if (IT_STRING_CHARPOS (*it
) > 0)
6468 --IT_STRING_CHARPOS (*it
);
6469 --IT_STRING_BYTEPOS (*it
);
6473 /* We need to restore the bidi iterator to the state
6474 it had on the newline, and resync the IT's
6475 position with that. */
6476 it
->bidi_it
= bidi_it_prev
;
6477 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6478 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6482 else if (IT_CHARPOS (*it
) > BEGV
)
6491 /* We need to restore the bidi iterator to the state it
6492 had on the newline and resync IT with that. */
6493 it
->bidi_it
= bidi_it_prev
;
6494 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6495 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6497 reseat (it
, it
->current
.pos
, false);
6501 reseat (it
, it
->current
.pos
, false);
6508 /***********************************************************************
6509 Changing an iterator's position
6510 ***********************************************************************/
6512 /* Change IT's current position to POS in current_buffer.
6513 If FORCE_P, always check for text properties at the new position.
6514 Otherwise, text properties are only looked up if POS >=
6515 IT->check_charpos of a property. */
6518 reseat (struct it
*it
, struct text_pos pos
, bool force_p
)
6520 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6522 reseat_1 (it
, pos
, false);
6524 /* Determine where to check text properties. Avoid doing it
6525 where possible because text property lookup is very expensive. */
6527 || CHARPOS (pos
) > it
->stop_charpos
6528 || CHARPOS (pos
) < original_pos
)
6532 /* For bidi iteration, we need to prime prev_stop and
6533 base_level_stop with our best estimations. */
6534 /* Implementation note: Of course, POS is not necessarily a
6535 stop position, so assigning prev_pos to it is a lie; we
6536 should have called compute_stop_backwards. However, if
6537 the current buffer does not include any R2L characters,
6538 that call would be a waste of cycles, because the
6539 iterator will never move back, and thus never cross this
6540 "fake" stop position. So we delay that backward search
6541 until the time we really need it, in next_element_from_buffer. */
6542 if (CHARPOS (pos
) != it
->prev_stop
)
6543 it
->prev_stop
= CHARPOS (pos
);
6544 if (CHARPOS (pos
) < it
->base_level_stop
)
6545 it
->base_level_stop
= 0; /* meaning it's unknown */
6551 it
->prev_stop
= it
->base_level_stop
= 0;
6560 /* Change IT's buffer position to POS. SET_STOP_P means set
6561 IT->stop_pos to POS, also. */
6564 reseat_1 (struct it
*it
, struct text_pos pos
, bool set_stop_p
)
6566 /* Don't call this function when scanning a C string. */
6567 eassert (it
->s
== NULL
);
6569 /* POS must be a reasonable value. */
6570 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6572 it
->current
.pos
= it
->position
= pos
;
6573 it
->end_charpos
= ZV
;
6575 it
->current
.dpvec_index
= -1;
6576 it
->current
.overlay_string_index
= -1;
6577 IT_STRING_CHARPOS (*it
) = -1;
6578 IT_STRING_BYTEPOS (*it
) = -1;
6580 it
->method
= GET_FROM_BUFFER
;
6581 it
->object
= it
->w
->contents
;
6582 it
->area
= TEXT_AREA
;
6583 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6585 it
->string_from_display_prop_p
= false;
6586 it
->string_from_prefix_prop_p
= false;
6588 it
->from_disp_prop_p
= false;
6589 it
->face_before_selective_p
= false;
6592 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6594 bidi_unshelve_cache (NULL
, false);
6595 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6596 it
->bidi_it
.string
.s
= NULL
;
6597 it
->bidi_it
.string
.lstring
= Qnil
;
6598 it
->bidi_it
.string
.bufpos
= 0;
6599 it
->bidi_it
.string
.from_disp_str
= false;
6600 it
->bidi_it
.string
.unibyte
= false;
6601 it
->bidi_it
.w
= it
->w
;
6606 it
->stop_charpos
= CHARPOS (pos
);
6607 it
->base_level_stop
= CHARPOS (pos
);
6609 /* This make the information stored in it->cmp_it invalidate. */
6614 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6615 If S is non-null, it is a C string to iterate over. Otherwise,
6616 STRING gives a Lisp string to iterate over.
6618 If PRECISION > 0, don't return more then PRECISION number of
6619 characters from the string.
6621 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6622 characters have been returned. FIELD_WIDTH < 0 means an infinite
6625 MULTIBYTE = 0 means disable processing of multibyte characters,
6626 MULTIBYTE > 0 means enable it,
6627 MULTIBYTE < 0 means use IT->multibyte_p.
6629 IT must be initialized via a prior call to init_iterator before
6630 calling this function. */
6633 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6634 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6637 /* No text property checks performed by default, but see below. */
6638 it
->stop_charpos
= -1;
6640 /* Set iterator position and end position. */
6641 memset (&it
->current
, 0, sizeof it
->current
);
6642 it
->current
.overlay_string_index
= -1;
6643 it
->current
.dpvec_index
= -1;
6644 eassert (charpos
>= 0);
6646 /* If STRING is specified, use its multibyteness, otherwise use the
6647 setting of MULTIBYTE, if specified. */
6649 it
->multibyte_p
= multibyte
> 0;
6651 /* Bidirectional reordering of strings is controlled by the default
6652 value of bidi-display-reordering. Don't try to reorder while
6653 loading loadup.el, as the necessary character property tables are
6654 not yet available. */
6657 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6661 eassert (STRINGP (string
));
6662 it
->string
= string
;
6664 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6665 it
->method
= GET_FROM_STRING
;
6666 it
->current
.string_pos
= string_pos (charpos
, string
);
6670 it
->bidi_it
.string
.lstring
= string
;
6671 it
->bidi_it
.string
.s
= NULL
;
6672 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6673 it
->bidi_it
.string
.bufpos
= 0;
6674 it
->bidi_it
.string
.from_disp_str
= false;
6675 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6676 it
->bidi_it
.w
= it
->w
;
6677 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6678 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6683 it
->s
= (const unsigned char *) s
;
6686 /* Note that we use IT->current.pos, not it->current.string_pos,
6687 for displaying C strings. */
6688 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6689 if (it
->multibyte_p
)
6691 it
->current
.pos
= c_string_pos (charpos
, s
, true);
6692 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, true);
6696 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6697 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6702 it
->bidi_it
.string
.lstring
= Qnil
;
6703 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6704 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6705 it
->bidi_it
.string
.bufpos
= 0;
6706 it
->bidi_it
.string
.from_disp_str
= false;
6707 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6708 it
->bidi_it
.w
= it
->w
;
6709 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6712 it
->method
= GET_FROM_C_STRING
;
6715 /* PRECISION > 0 means don't return more than PRECISION characters
6717 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6719 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6721 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6724 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6725 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6726 FIELD_WIDTH < 0 means infinite field width. This is useful for
6727 padding with `-' at the end of a mode line. */
6728 if (field_width
< 0)
6729 field_width
= INFINITY
;
6730 /* Implementation note: We deliberately don't enlarge
6731 it->bidi_it.string.schars here to fit it->end_charpos, because
6732 the bidi iterator cannot produce characters out of thin air. */
6733 if (field_width
> it
->end_charpos
- charpos
)
6734 it
->end_charpos
= charpos
+ field_width
;
6736 /* Use the standard display table for displaying strings. */
6737 if (DISP_TABLE_P (Vstandard_display_table
))
6738 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6740 it
->stop_charpos
= charpos
;
6741 it
->prev_stop
= charpos
;
6742 it
->base_level_stop
= 0;
6745 it
->bidi_it
.first_elt
= true;
6746 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6747 it
->bidi_it
.disp_pos
= -1;
6749 if (s
== NULL
&& it
->multibyte_p
)
6751 ptrdiff_t endpos
= SCHARS (it
->string
);
6752 if (endpos
> it
->end_charpos
)
6753 endpos
= it
->end_charpos
;
6754 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6762 /***********************************************************************
6764 ***********************************************************************/
6766 /* Map enum it_method value to corresponding next_element_from_* function. */
6768 typedef bool (*next_element_function
) (struct it
*);
6770 static next_element_function
const get_next_element
[NUM_IT_METHODS
] =
6772 next_element_from_buffer
,
6773 next_element_from_display_vector
,
6774 next_element_from_string
,
6775 next_element_from_c_string
,
6776 next_element_from_image
,
6777 next_element_from_stretch
,
6778 #ifdef HAVE_XWIDGETS
6779 next_element_from_xwidget
,
6783 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6786 /* Return true iff a character at CHARPOS (and BYTEPOS) is composed
6787 (possibly with the following characters). */
6789 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6790 ((IT)->cmp_it.id >= 0 \
6791 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6792 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6793 END_CHARPOS, (IT)->w, \
6794 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6798 /* Lookup the char-table Vglyphless_char_display for character C (-1
6799 if we want information for no-font case), and return the display
6800 method symbol. By side-effect, update it->what and
6801 it->glyphless_method. This function is called from
6802 get_next_display_element for each character element, and from
6803 x_produce_glyphs when no suitable font was found. */
6806 lookup_glyphless_char_display (int c
, struct it
*it
)
6808 Lisp_Object glyphless_method
= Qnil
;
6810 if (CHAR_TABLE_P (Vglyphless_char_display
)
6811 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6815 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6816 if (CONSP (glyphless_method
))
6817 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6818 ? XCAR (glyphless_method
)
6819 : XCDR (glyphless_method
);
6822 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6826 if (NILP (glyphless_method
))
6829 /* The default is to display the character by a proper font. */
6831 /* The default for the no-font case is to display an empty box. */
6832 glyphless_method
= Qempty_box
;
6834 if (EQ (glyphless_method
, Qzero_width
))
6837 return glyphless_method
;
6838 /* This method can't be used for the no-font case. */
6839 glyphless_method
= Qempty_box
;
6841 if (EQ (glyphless_method
, Qthin_space
))
6842 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6843 else if (EQ (glyphless_method
, Qempty_box
))
6844 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6845 else if (EQ (glyphless_method
, Qhex_code
))
6846 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6847 else if (STRINGP (glyphless_method
))
6848 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6851 /* Invalid value. We use the default method. */
6852 glyphless_method
= Qnil
;
6855 it
->what
= IT_GLYPHLESS
;
6856 return glyphless_method
;
6859 /* Merge escape glyph face and cache the result. */
6861 static struct frame
*last_escape_glyph_frame
= NULL
;
6862 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6863 static int last_escape_glyph_merged_face_id
= 0;
6866 merge_escape_glyph_face (struct it
*it
)
6870 if (it
->f
== last_escape_glyph_frame
6871 && it
->face_id
== last_escape_glyph_face_id
)
6872 face_id
= last_escape_glyph_merged_face_id
;
6875 /* Merge the `escape-glyph' face into the current face. */
6876 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6877 last_escape_glyph_frame
= it
->f
;
6878 last_escape_glyph_face_id
= it
->face_id
;
6879 last_escape_glyph_merged_face_id
= face_id
;
6884 /* Likewise for glyphless glyph face. */
6886 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6887 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6888 static int last_glyphless_glyph_merged_face_id
= 0;
6891 merge_glyphless_glyph_face (struct it
*it
)
6895 if (it
->f
== last_glyphless_glyph_frame
6896 && it
->face_id
== last_glyphless_glyph_face_id
)
6897 face_id
= last_glyphless_glyph_merged_face_id
;
6900 /* Merge the `glyphless-char' face into the current face. */
6901 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6902 last_glyphless_glyph_frame
= it
->f
;
6903 last_glyphless_glyph_face_id
= it
->face_id
;
6904 last_glyphless_glyph_merged_face_id
= face_id
;
6909 /* Forget the `escape-glyph' and `glyphless-char' faces. This should
6910 be called before redisplaying windows, and when the frame's face
6913 forget_escape_and_glyphless_faces (void)
6915 last_escape_glyph_frame
= NULL
;
6916 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6917 last_glyphless_glyph_frame
= NULL
;
6918 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6921 /* Load IT's display element fields with information about the next
6922 display element from the current position of IT. Value is false if
6923 end of buffer (or C string) is reached. */
6926 get_next_display_element (struct it
*it
)
6928 /* True means that we found a display element. False means that
6929 we hit the end of what we iterate over. Performance note: the
6930 function pointer `method' used here turns out to be faster than
6931 using a sequence of if-statements. */
6935 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6937 if (it
->what
== IT_CHARACTER
)
6939 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6940 and only if (a) the resolved directionality of that character
6942 /* FIXME: Do we need an exception for characters from display
6944 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
6945 && !inhibit_bidi_mirroring
)
6946 it
->c
= bidi_mirror_char (it
->c
);
6947 /* Map via display table or translate control characters.
6948 IT->c, IT->len etc. have been set to the next character by
6949 the function call above. If we have a display table, and it
6950 contains an entry for IT->c, translate it. Don't do this if
6951 IT->c itself comes from a display table, otherwise we could
6952 end up in an infinite recursion. (An alternative could be to
6953 count the recursion depth of this function and signal an
6954 error when a certain maximum depth is reached.) Is it worth
6956 if (success_p
&& it
->dpvec
== NULL
)
6959 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6960 bool nonascii_space_p
= false;
6961 bool nonascii_hyphen_p
= false;
6962 int c
= it
->c
; /* This is the character to display. */
6964 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6966 eassert (SINGLE_BYTE_CHAR_P (c
));
6967 if (unibyte_display_via_language_environment
)
6969 c
= DECODE_CHAR (unibyte
, c
);
6971 c
= BYTE8_TO_CHAR (it
->c
);
6974 c
= BYTE8_TO_CHAR (it
->c
);
6978 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6981 struct Lisp_Vector
*v
= XVECTOR (dv
);
6983 /* Return the first character from the display table
6984 entry, if not empty. If empty, don't display the
6985 current character. */
6988 it
->dpvec_char_len
= it
->len
;
6989 it
->dpvec
= v
->contents
;
6990 it
->dpend
= v
->contents
+ v
->header
.size
;
6991 it
->current
.dpvec_index
= 0;
6992 it
->dpvec_face_id
= -1;
6993 it
->saved_face_id
= it
->face_id
;
6994 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6995 it
->ellipsis_p
= false;
6999 set_iterator_to_next (it
, false);
7004 if (! NILP (lookup_glyphless_char_display (c
, it
)))
7006 if (it
->what
== IT_GLYPHLESS
)
7008 /* Don't display this character. */
7009 set_iterator_to_next (it
, false);
7013 /* If `nobreak-char-display' is non-nil, we display
7014 non-ASCII spaces and hyphens specially. */
7015 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
7017 if (c
== NO_BREAK_SPACE
)
7018 nonascii_space_p
= true;
7019 else if (c
== SOFT_HYPHEN
|| c
== HYPHEN
7020 || c
== NON_BREAKING_HYPHEN
)
7021 nonascii_hyphen_p
= true;
7024 /* Translate control characters into `\003' or `^C' form.
7025 Control characters coming from a display table entry are
7026 currently not translated because we use IT->dpvec to hold
7027 the translation. This could easily be changed but I
7028 don't believe that it is worth doing.
7030 The characters handled by `nobreak-char-display' must be
7033 Non-printable characters and raw-byte characters are also
7034 translated to octal form. */
7035 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
7036 ? (it
->area
!= TEXT_AREA
7037 /* In mode line, treat \n, \t like other crl chars. */
7040 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
7041 || (c
!= '\n' && c
!= '\t'))
7043 || nonascii_hyphen_p
7045 || ! CHAR_PRINTABLE_P (c
))))
7047 /* C is a control character, non-ASCII space/hyphen,
7048 raw-byte, or a non-printable character which must be
7049 displayed either as '\003' or as `^C' where the '\\'
7050 and '^' can be defined in the display table. Fill
7051 IT->ctl_chars with glyphs for what we have to
7052 display. Then, set IT->dpvec to these glyphs. */
7059 /* Handle control characters with ^. */
7061 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
7065 g
= '^'; /* default glyph for Control */
7066 /* Set IT->ctl_chars[0] to the glyph for `^'. */
7068 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
7070 g
= GLYPH_CODE_CHAR (gc
);
7071 lface_id
= GLYPH_CODE_FACE (gc
);
7075 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
7076 : merge_escape_glyph_face (it
));
7078 XSETINT (it
->ctl_chars
[0], g
);
7079 XSETINT (it
->ctl_chars
[1], c
^ 0100);
7081 goto display_control
;
7084 /* Handle non-ascii space in the mode where it only gets
7087 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
7089 /* Merge `nobreak-space' into the current face. */
7090 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
7092 XSETINT (it
->ctl_chars
[0], ' ');
7094 goto display_control
;
7097 /* Handle sequences that start with the "escape glyph". */
7099 /* the default escape glyph is \. */
7100 escape_glyph
= '\\';
7103 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
7105 escape_glyph
= GLYPH_CODE_CHAR (gc
);
7106 lface_id
= GLYPH_CODE_FACE (gc
);
7110 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
7111 : merge_escape_glyph_face (it
));
7113 /* Draw non-ASCII hyphen with just highlighting: */
7115 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
7117 XSETINT (it
->ctl_chars
[0], '-');
7119 goto display_control
;
7122 /* Draw non-ASCII space/hyphen with escape glyph: */
7124 if (nonascii_space_p
|| nonascii_hyphen_p
)
7126 XSETINT (it
->ctl_chars
[0], escape_glyph
);
7127 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
7129 goto display_control
;
7136 if (CHAR_BYTE8_P (c
))
7137 /* Display \200 instead of \17777600. */
7138 c
= CHAR_TO_BYTE8 (c
);
7139 len
= sprintf (str
, "%03o", c
+ 0u);
7141 XSETINT (it
->ctl_chars
[0], escape_glyph
);
7142 for (i
= 0; i
< len
; i
++)
7143 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
7148 /* Set up IT->dpvec and return first character from it. */
7149 it
->dpvec_char_len
= it
->len
;
7150 it
->dpvec
= it
->ctl_chars
;
7151 it
->dpend
= it
->dpvec
+ ctl_len
;
7152 it
->current
.dpvec_index
= 0;
7153 it
->dpvec_face_id
= face_id
;
7154 it
->saved_face_id
= it
->face_id
;
7155 it
->method
= GET_FROM_DISPLAY_VECTOR
;
7156 it
->ellipsis_p
= false;
7159 it
->char_to_display
= c
;
7163 it
->char_to_display
= it
->c
;
7167 #ifdef HAVE_WINDOW_SYSTEM
7168 /* Adjust face id for a multibyte character. There are no multibyte
7169 character in unibyte text. */
7170 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
7173 && FRAME_WINDOW_P (it
->f
))
7175 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7177 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
7179 /* Automatic composition with glyph-string. */
7180 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
7182 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
7186 ptrdiff_t pos
= (it
->s
? -1
7187 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
7188 : IT_CHARPOS (*it
));
7191 if (it
->what
== IT_CHARACTER
)
7192 c
= it
->char_to_display
;
7195 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
7199 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7200 /* TAB in a composition means display glyphs with
7201 padding space on the left or right. */
7202 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7205 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7208 #endif /* HAVE_WINDOW_SYSTEM */
7211 /* Is this character the last one of a run of characters with
7212 box? If yes, set IT->end_of_box_run_p to true. */
7216 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7218 int face_id
= underlying_face_id (it
);
7219 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7223 if (face
->box
== FACE_NO_BOX
)
7225 /* If the box comes from face properties in a
7226 display string, check faces in that string. */
7227 int string_face_id
= face_after_it_pos (it
);
7228 it
->end_of_box_run_p
7229 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7232 /* Otherwise, the box comes from the underlying face.
7233 If this is the last string character displayed, check
7234 the next buffer location. */
7235 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7236 /* n_overlay_strings is unreliable unless
7237 overlay_string_index is non-negative. */
7238 && ((it
->current
.overlay_string_index
>= 0
7239 && (it
->current
.overlay_string_index
7240 == it
->n_overlay_strings
- 1))
7241 /* A string from display property. */
7242 || it
->from_disp_prop_p
))
7246 struct text_pos pos
= it
->current
.pos
;
7248 /* For a string from a display property, the next
7249 buffer position is stored in the 'position'
7250 member of the iteration stack slot below the
7251 current one, see handle_single_display_spec. By
7252 contrast, it->current.pos was is not yet updated
7253 to point to that buffer position; that will
7254 happen in pop_it, after we finish displaying the
7255 current string. Note that we already checked
7256 above that it->sp is positive, so subtracting one
7258 if (it
->from_disp_prop_p
)
7259 pos
= (it
->stack
+ it
->sp
- 1)->position
;
7261 INC_TEXT_POS (pos
, it
->multibyte_p
);
7263 if (CHARPOS (pos
) >= ZV
)
7264 it
->end_of_box_run_p
= true;
7267 next_face_id
= face_at_buffer_position
7268 (it
->w
, CHARPOS (pos
), &ignore
,
7269 CHARPOS (pos
) + TEXT_PROP_DISTANCE_LIMIT
, false, -1);
7270 it
->end_of_box_run_p
7271 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7277 /* next_element_from_display_vector sets this flag according to
7278 faces of the display vector glyphs, see there. */
7279 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7281 int face_id
= face_after_it_pos (it
);
7282 it
->end_of_box_run_p
7283 = (face_id
!= it
->face_id
7284 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7287 /* If we reached the end of the object we've been iterating (e.g., a
7288 display string or an overlay string), and there's something on
7289 IT->stack, proceed with what's on the stack. It doesn't make
7290 sense to return false if there's unprocessed stuff on the stack,
7291 because otherwise that stuff will never be displayed. */
7292 if (!success_p
&& it
->sp
> 0)
7294 set_iterator_to_next (it
, false);
7295 success_p
= get_next_display_element (it
);
7298 /* Value is false if end of buffer or string reached. */
7303 /* Move IT to the next display element.
7305 RESEAT_P means if called on a newline in buffer text,
7306 skip to the next visible line start.
7308 Functions get_next_display_element and set_iterator_to_next are
7309 separate because I find this arrangement easier to handle than a
7310 get_next_display_element function that also increments IT's
7311 position. The way it is we can first look at an iterator's current
7312 display element, decide whether it fits on a line, and if it does,
7313 increment the iterator position. The other way around we probably
7314 would either need a flag indicating whether the iterator has to be
7315 incremented the next time, or we would have to implement a
7316 decrement position function which would not be easy to write. */
7319 set_iterator_to_next (struct it
*it
, bool reseat_p
)
7321 /* Reset flags indicating start and end of a sequence of characters
7322 with box. Reset them at the start of this function because
7323 moving the iterator to a new position might set them. */
7324 it
->start_of_box_run_p
= it
->end_of_box_run_p
= false;
7328 case GET_FROM_BUFFER
:
7329 /* The current display element of IT is a character from
7330 current_buffer. Advance in the buffer, and maybe skip over
7331 invisible lines that are so because of selective display. */
7332 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7333 reseat_at_next_visible_line_start (it
, false);
7334 else if (it
->cmp_it
.id
>= 0)
7336 /* We are currently getting glyphs from a composition. */
7339 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7340 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7346 /* Update IT's char/byte positions to point to the first
7347 character of the next grapheme cluster, or to the
7348 character visually after the current composition. */
7349 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7350 bidi_move_to_visually_next (&it
->bidi_it
);
7351 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7352 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7355 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7356 && it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7358 /* Composition created while scanning forward. Proceed
7359 to the next grapheme cluster. */
7360 it
->cmp_it
.from
= it
->cmp_it
.to
;
7362 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7363 && it
->cmp_it
.from
> 0)
7365 /* Composition created while scanning backward. Proceed
7366 to the previous grapheme cluster. */
7367 it
->cmp_it
.to
= it
->cmp_it
.from
;
7371 /* No more grapheme clusters in this composition.
7372 Find the next stop position. */
7373 ptrdiff_t stop
= it
->end_charpos
;
7375 if (it
->bidi_it
.scan_dir
< 0)
7376 /* Now we are scanning backward and don't know
7379 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7380 IT_BYTEPOS (*it
), stop
, Qnil
);
7385 eassert (it
->len
!= 0);
7389 IT_BYTEPOS (*it
) += it
->len
;
7390 IT_CHARPOS (*it
) += 1;
7394 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7395 /* If this is a new paragraph, determine its base
7396 direction (a.k.a. its base embedding level). */
7397 if (it
->bidi_it
.new_paragraph
)
7398 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
7400 bidi_move_to_visually_next (&it
->bidi_it
);
7401 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7402 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7403 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7405 /* As the scan direction was changed, we must
7406 re-compute the stop position for composition. */
7407 ptrdiff_t stop
= it
->end_charpos
;
7408 if (it
->bidi_it
.scan_dir
< 0)
7410 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7411 IT_BYTEPOS (*it
), stop
, Qnil
);
7414 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7418 case GET_FROM_C_STRING
:
7419 /* Current display element of IT is from a C string. */
7421 /* If the string position is beyond string's end, it means
7422 next_element_from_c_string is padding the string with
7423 blanks, in which case we bypass the bidi iterator,
7424 because it cannot deal with such virtual characters. */
7425 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7427 IT_BYTEPOS (*it
) += it
->len
;
7428 IT_CHARPOS (*it
) += 1;
7432 bidi_move_to_visually_next (&it
->bidi_it
);
7433 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7434 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7438 case GET_FROM_DISPLAY_VECTOR
:
7439 /* Current display element of IT is from a display table entry.
7440 Advance in the display table definition. Reset it to null if
7441 end reached, and continue with characters from buffers/
7443 ++it
->current
.dpvec_index
;
7445 /* Restore face of the iterator to what they were before the
7446 display vector entry (these entries may contain faces). */
7447 it
->face_id
= it
->saved_face_id
;
7449 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7451 bool recheck_faces
= it
->ellipsis_p
;
7454 it
->method
= GET_FROM_C_STRING
;
7455 else if (STRINGP (it
->string
))
7456 it
->method
= GET_FROM_STRING
;
7459 it
->method
= GET_FROM_BUFFER
;
7460 it
->object
= it
->w
->contents
;
7464 it
->current
.dpvec_index
= -1;
7466 /* Skip over characters which were displayed via IT->dpvec. */
7467 if (it
->dpvec_char_len
< 0)
7468 reseat_at_next_visible_line_start (it
, true);
7469 else if (it
->dpvec_char_len
> 0)
7471 it
->len
= it
->dpvec_char_len
;
7472 set_iterator_to_next (it
, reseat_p
);
7475 /* Maybe recheck faces after display vector. */
7478 if (it
->method
== GET_FROM_STRING
)
7479 it
->stop_charpos
= IT_STRING_CHARPOS (*it
);
7481 it
->stop_charpos
= IT_CHARPOS (*it
);
7486 case GET_FROM_STRING
:
7487 /* Current display element is a character from a Lisp string. */
7488 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7489 /* Don't advance past string end. These conditions are true
7490 when set_iterator_to_next is called at the end of
7491 get_next_display_element, in which case the Lisp string is
7492 already exhausted, and all we want is pop the iterator
7494 if (it
->current
.overlay_string_index
>= 0)
7496 /* This is an overlay string, so there's no padding with
7497 spaces, and the number of characters in the string is
7498 where the string ends. */
7499 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7500 goto consider_string_end
;
7504 /* Not an overlay string. There could be padding, so test
7505 against it->end_charpos. */
7506 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7507 goto consider_string_end
;
7509 if (it
->cmp_it
.id
>= 0)
7511 /* We are delivering display elements from a composition.
7512 Update the string position past the grapheme cluster
7513 we've just processed. */
7516 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7517 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7523 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7524 bidi_move_to_visually_next (&it
->bidi_it
);
7525 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7526 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7529 /* Did we exhaust all the grapheme clusters of this
7531 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7532 && (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
))
7534 /* Not all the grapheme clusters were processed yet;
7535 advance to the next cluster. */
7536 it
->cmp_it
.from
= it
->cmp_it
.to
;
7538 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7539 && it
->cmp_it
.from
> 0)
7541 /* Likewise: advance to the next cluster, but going in
7542 the reverse direction. */
7543 it
->cmp_it
.to
= it
->cmp_it
.from
;
7547 /* This composition was fully processed; find the next
7548 candidate place for checking for composed
7550 /* Always limit string searches to the string length;
7551 any padding spaces are not part of the string, and
7552 there cannot be any compositions in that padding. */
7553 ptrdiff_t stop
= SCHARS (it
->string
);
7555 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
7557 else if (it
->end_charpos
< stop
)
7559 /* Cf. PRECISION in reseat_to_string: we might be
7560 limited in how many of the string characters we
7562 stop
= it
->end_charpos
;
7564 composition_compute_stop_pos (&it
->cmp_it
,
7565 IT_STRING_CHARPOS (*it
),
7566 IT_STRING_BYTEPOS (*it
), stop
,
7573 /* If the string position is beyond string's end, it
7574 means next_element_from_string is padding the string
7575 with blanks, in which case we bypass the bidi
7576 iterator, because it cannot deal with such virtual
7578 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7580 IT_STRING_BYTEPOS (*it
) += it
->len
;
7581 IT_STRING_CHARPOS (*it
) += 1;
7585 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7587 bidi_move_to_visually_next (&it
->bidi_it
);
7588 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7589 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7590 /* If the scan direction changes, we may need to update
7591 the place where to check for composed characters. */
7592 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7594 ptrdiff_t stop
= SCHARS (it
->string
);
7596 if (it
->bidi_it
.scan_dir
< 0)
7598 else if (it
->end_charpos
< stop
)
7599 stop
= it
->end_charpos
;
7601 composition_compute_stop_pos (&it
->cmp_it
,
7602 IT_STRING_CHARPOS (*it
),
7603 IT_STRING_BYTEPOS (*it
), stop
,
7609 consider_string_end
:
7611 if (it
->current
.overlay_string_index
>= 0)
7613 /* IT->string is an overlay string. Advance to the
7614 next, if there is one. */
7615 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7617 it
->ellipsis_p
= false;
7618 next_overlay_string (it
);
7620 setup_for_ellipsis (it
, 0);
7625 /* IT->string is not an overlay string. If we reached
7626 its end, and there is something on IT->stack, proceed
7627 with what is on the stack. This can be either another
7628 string, this time an overlay string, or a buffer. */
7629 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7633 if (it
->method
== GET_FROM_STRING
)
7634 goto consider_string_end
;
7639 case GET_FROM_IMAGE
:
7640 case GET_FROM_STRETCH
:
7641 #ifdef HAVE_XWIDGETS
7642 case GET_FROM_XWIDGET
:
7645 /* The position etc with which we have to proceed are on
7646 the stack. The position may be at the end of a string,
7647 if the `display' property takes up the whole string. */
7648 eassert (it
->sp
> 0);
7650 if (it
->method
== GET_FROM_STRING
)
7651 goto consider_string_end
;
7655 /* There are no other methods defined, so this should be a bug. */
7659 eassert (it
->method
!= GET_FROM_STRING
7660 || (STRINGP (it
->string
)
7661 && IT_STRING_CHARPOS (*it
) >= 0));
7664 /* Load IT's display element fields with information about the next
7665 display element which comes from a display table entry or from the
7666 result of translating a control character to one of the forms `^C'
7669 IT->dpvec holds the glyphs to return as characters.
7670 IT->saved_face_id holds the face id before the display vector--it
7671 is restored into IT->face_id in set_iterator_to_next. */
7674 next_element_from_display_vector (struct it
*it
)
7677 int prev_face_id
= it
->face_id
;
7681 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7683 it
->face_id
= it
->saved_face_id
;
7685 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7686 That seemed totally bogus - so I changed it... */
7687 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7689 if (GLYPH_CODE_P (gc
))
7691 struct face
*this_face
, *prev_face
, *next_face
;
7693 it
->c
= GLYPH_CODE_CHAR (gc
);
7694 it
->len
= CHAR_BYTES (it
->c
);
7696 /* The entry may contain a face id to use. Such a face id is
7697 the id of a Lisp face, not a realized face. A face id of
7698 zero means no face is specified. */
7699 if (it
->dpvec_face_id
>= 0)
7700 it
->face_id
= it
->dpvec_face_id
;
7703 int lface_id
= GLYPH_CODE_FACE (gc
);
7705 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7709 /* Glyphs in the display vector could have the box face, so we
7710 need to set the related flags in the iterator, as
7712 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7713 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7715 /* Is this character the first character of a box-face run? */
7716 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7718 || prev_face
->box
== FACE_NO_BOX
));
7720 /* For the last character of the box-face run, we need to look
7721 either at the next glyph from the display vector, or at the
7722 face we saw before the display vector. */
7723 next_face_id
= it
->saved_face_id
;
7724 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7726 if (it
->dpvec_face_id
>= 0)
7727 next_face_id
= it
->dpvec_face_id
;
7731 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7734 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7738 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7739 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7741 || next_face
->box
== FACE_NO_BOX
));
7742 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7745 /* Display table entry is invalid. Return a space. */
7746 it
->c
= ' ', it
->len
= 1;
7748 /* Don't change position and object of the iterator here. They are
7749 still the values of the character that had this display table
7750 entry or was translated, and that's what we want. */
7751 it
->what
= IT_CHARACTER
;
7755 /* Get the first element of string/buffer in the visual order, after
7756 being reseated to a new position in a string or a buffer. */
7758 get_visually_first_element (struct it
*it
)
7760 bool string_p
= STRINGP (it
->string
) || it
->s
;
7761 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7762 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7764 if (STRINGP (it
->string
))
7766 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7767 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7771 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7772 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7775 if (it
->bidi_it
.charpos
== eob
)
7777 /* Nothing to do, but reset the FIRST_ELT flag, like
7778 bidi_paragraph_init does, because we are not going to
7780 it
->bidi_it
.first_elt
= false;
7782 else if (it
->bidi_it
.charpos
== bob
7784 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7785 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7787 /* If we are at the beginning of a line/string, we can produce
7788 the next element right away. */
7789 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7790 bidi_move_to_visually_next (&it
->bidi_it
);
7794 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7796 /* We need to prime the bidi iterator starting at the line's or
7797 string's beginning, before we will be able to produce the
7800 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7802 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7803 IT_BYTEPOS (*it
), -1,
7804 &it
->bidi_it
.bytepos
);
7805 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7808 /* Now return to buffer/string position where we were asked
7809 to get the next display element, and produce that. */
7810 bidi_move_to_visually_next (&it
->bidi_it
);
7812 while (it
->bidi_it
.bytepos
!= orig_bytepos
7813 && it
->bidi_it
.charpos
< eob
);
7816 /* Adjust IT's position information to where we ended up. */
7817 if (STRINGP (it
->string
))
7819 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7820 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7824 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7825 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7828 if (STRINGP (it
->string
) || !it
->s
)
7830 ptrdiff_t stop
, charpos
, bytepos
;
7832 if (STRINGP (it
->string
))
7835 stop
= SCHARS (it
->string
);
7836 if (stop
> it
->end_charpos
)
7837 stop
= it
->end_charpos
;
7838 charpos
= IT_STRING_CHARPOS (*it
);
7839 bytepos
= IT_STRING_BYTEPOS (*it
);
7843 stop
= it
->end_charpos
;
7844 charpos
= IT_CHARPOS (*it
);
7845 bytepos
= IT_BYTEPOS (*it
);
7847 if (it
->bidi_it
.scan_dir
< 0)
7849 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7854 /* Load IT with the next display element from Lisp string IT->string.
7855 IT->current.string_pos is the current position within the string.
7856 If IT->current.overlay_string_index >= 0, the Lisp string is an
7860 next_element_from_string (struct it
*it
)
7862 struct text_pos position
;
7864 eassert (STRINGP (it
->string
));
7865 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7866 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7867 position
= it
->current
.string_pos
;
7869 /* With bidi reordering, the character to display might not be the
7870 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT means
7871 that we were reseat()ed to a new string, whose paragraph
7872 direction is not known. */
7873 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7875 get_visually_first_element (it
);
7876 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7879 /* Time to check for invisible text? */
7880 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7882 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7885 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7886 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7888 /* With bidi non-linear iteration, we could find
7889 ourselves far beyond the last computed stop_charpos,
7890 with several other stop positions in between that we
7891 missed. Scan them all now, in buffer's logical
7892 order, until we find and handle the last stop_charpos
7893 that precedes our current position. */
7894 handle_stop_backwards (it
, it
->stop_charpos
);
7895 return GET_NEXT_DISPLAY_ELEMENT (it
);
7901 /* Take note of the stop position we just moved
7902 across, for when we will move back across it. */
7903 it
->prev_stop
= it
->stop_charpos
;
7904 /* If we are at base paragraph embedding level, take
7905 note of the last stop position seen at this
7907 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7908 it
->base_level_stop
= it
->stop_charpos
;
7912 /* Since a handler may have changed IT->method, we must
7914 return GET_NEXT_DISPLAY_ELEMENT (it
);
7918 /* If we are before prev_stop, we may have overstepped
7919 on our way backwards a stop_pos, and if so, we need
7920 to handle that stop_pos. */
7921 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7922 /* We can sometimes back up for reasons that have nothing
7923 to do with bidi reordering. E.g., compositions. The
7924 code below is only needed when we are above the base
7925 embedding level, so test for that explicitly. */
7926 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7928 /* If we lost track of base_level_stop, we have no better
7929 place for handle_stop_backwards to start from than string
7930 beginning. This happens, e.g., when we were reseated to
7931 the previous screenful of text by vertical-motion. */
7932 if (it
->base_level_stop
<= 0
7933 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7934 it
->base_level_stop
= 0;
7935 handle_stop_backwards (it
, it
->base_level_stop
);
7936 return GET_NEXT_DISPLAY_ELEMENT (it
);
7940 if (it
->current
.overlay_string_index
>= 0)
7942 /* Get the next character from an overlay string. In overlay
7943 strings, there is no field width or padding with spaces to
7945 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7950 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7951 IT_STRING_BYTEPOS (*it
),
7952 it
->bidi_it
.scan_dir
< 0
7954 : SCHARS (it
->string
))
7955 && next_element_from_composition (it
))
7959 else if (STRING_MULTIBYTE (it
->string
))
7961 const unsigned char *s
= (SDATA (it
->string
)
7962 + IT_STRING_BYTEPOS (*it
));
7963 it
->c
= string_char_and_length (s
, &it
->len
);
7967 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7973 /* Get the next character from a Lisp string that is not an
7974 overlay string. Such strings come from the mode line, for
7975 example. We may have to pad with spaces, or truncate the
7976 string. See also next_element_from_c_string. */
7977 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7982 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7984 /* Pad with spaces. */
7985 it
->c
= ' ', it
->len
= 1;
7986 CHARPOS (position
) = BYTEPOS (position
) = -1;
7988 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7989 IT_STRING_BYTEPOS (*it
),
7990 it
->bidi_it
.scan_dir
< 0
7992 : it
->string_nchars
)
7993 && next_element_from_composition (it
))
7997 else if (STRING_MULTIBYTE (it
->string
))
7999 const unsigned char *s
= (SDATA (it
->string
)
8000 + IT_STRING_BYTEPOS (*it
));
8001 it
->c
= string_char_and_length (s
, &it
->len
);
8005 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
8010 /* Record what we have and where it came from. */
8011 it
->what
= IT_CHARACTER
;
8012 it
->object
= it
->string
;
8013 it
->position
= position
;
8018 /* Load IT with next display element from C string IT->s.
8019 IT->string_nchars is the maximum number of characters to return
8020 from the string. IT->end_charpos may be greater than
8021 IT->string_nchars when this function is called, in which case we
8022 may have to return padding spaces. Value is false if end of string
8023 reached, including padding spaces. */
8026 next_element_from_c_string (struct it
*it
)
8028 bool success_p
= true;
8031 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
8032 it
->what
= IT_CHARACTER
;
8033 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
8034 it
->object
= make_number (0);
8036 /* With bidi reordering, the character to display might not be the
8037 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8038 we were reseated to a new string, whose paragraph direction is
8040 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8041 get_visually_first_element (it
);
8043 /* IT's position can be greater than IT->string_nchars in case a
8044 field width or precision has been specified when the iterator was
8046 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8048 /* End of the game. */
8052 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
8054 /* Pad with spaces. */
8055 it
->c
= ' ', it
->len
= 1;
8056 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
8058 else if (it
->multibyte_p
)
8059 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
8061 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
8067 /* Set up IT to return characters from an ellipsis, if appropriate.
8068 The definition of the ellipsis glyphs may come from a display table
8069 entry. This function fills IT with the first glyph from the
8070 ellipsis if an ellipsis is to be displayed. */
8073 next_element_from_ellipsis (struct it
*it
)
8075 if (it
->selective_display_ellipsis_p
)
8076 setup_for_ellipsis (it
, it
->len
);
8079 /* The face at the current position may be different from the
8080 face we find after the invisible text. Remember what it
8081 was in IT->saved_face_id, and signal that it's there by
8082 setting face_before_selective_p. */
8083 it
->saved_face_id
= it
->face_id
;
8084 it
->method
= GET_FROM_BUFFER
;
8085 it
->object
= it
->w
->contents
;
8086 reseat_at_next_visible_line_start (it
, true);
8087 it
->face_before_selective_p
= true;
8090 return GET_NEXT_DISPLAY_ELEMENT (it
);
8094 /* Deliver an image display element. The iterator IT is already
8095 filled with image information (done in handle_display_prop). Value
8100 next_element_from_image (struct it
*it
)
8102 it
->what
= IT_IMAGE
;
8106 #ifdef HAVE_XWIDGETS
8108 next_element_from_xwidget (struct it
*it
)
8110 it
->what
= IT_XWIDGET
;
8116 /* Fill iterator IT with next display element from a stretch glyph
8117 property. IT->object is the value of the text property. Value is
8121 next_element_from_stretch (struct it
*it
)
8123 it
->what
= IT_STRETCH
;
8127 /* Scan backwards from IT's current position until we find a stop
8128 position, or until BEGV. This is called when we find ourself
8129 before both the last known prev_stop and base_level_stop while
8130 reordering bidirectional text. */
8133 compute_stop_pos_backwards (struct it
*it
)
8135 const int SCAN_BACK_LIMIT
= 1000;
8136 struct text_pos pos
;
8137 struct display_pos save_current
= it
->current
;
8138 struct text_pos save_position
= it
->position
;
8139 ptrdiff_t charpos
= IT_CHARPOS (*it
);
8140 ptrdiff_t where_we_are
= charpos
;
8141 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
8142 ptrdiff_t save_end_pos
= it
->end_charpos
;
8144 eassert (NILP (it
->string
) && !it
->s
);
8145 eassert (it
->bidi_p
);
8149 it
->end_charpos
= min (charpos
+ 1, ZV
);
8150 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
8151 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
8152 reseat_1 (it
, pos
, false);
8153 compute_stop_pos (it
);
8154 /* We must advance forward, right? */
8155 if (it
->stop_charpos
<= charpos
)
8158 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
8160 if (it
->stop_charpos
<= where_we_are
)
8161 it
->prev_stop
= it
->stop_charpos
;
8163 it
->prev_stop
= BEGV
;
8165 it
->current
= save_current
;
8166 it
->position
= save_position
;
8167 it
->stop_charpos
= save_stop_pos
;
8168 it
->end_charpos
= save_end_pos
;
8171 /* Scan forward from CHARPOS in the current buffer/string, until we
8172 find a stop position > current IT's position. Then handle the stop
8173 position before that. This is called when we bump into a stop
8174 position while reordering bidirectional text. CHARPOS should be
8175 the last previously processed stop_pos (or BEGV/0, if none were
8176 processed yet) whose position is less that IT's current
8180 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
8182 bool bufp
= !STRINGP (it
->string
);
8183 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
8184 struct display_pos save_current
= it
->current
;
8185 struct text_pos save_position
= it
->position
;
8186 struct text_pos pos1
;
8187 ptrdiff_t next_stop
;
8189 /* Scan in strict logical order. */
8190 eassert (it
->bidi_p
);
8194 it
->prev_stop
= charpos
;
8197 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
8198 reseat_1 (it
, pos1
, false);
8201 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
8202 compute_stop_pos (it
);
8203 /* We must advance forward, right? */
8204 if (it
->stop_charpos
<= it
->prev_stop
)
8206 charpos
= it
->stop_charpos
;
8208 while (charpos
<= where_we_are
);
8211 it
->current
= save_current
;
8212 it
->position
= save_position
;
8213 next_stop
= it
->stop_charpos
;
8214 it
->stop_charpos
= it
->prev_stop
;
8216 it
->stop_charpos
= next_stop
;
8219 /* Load IT with the next display element from current_buffer. Value
8220 is false if end of buffer reached. IT->stop_charpos is the next
8221 position at which to stop and check for text properties or buffer
8225 next_element_from_buffer (struct it
*it
)
8227 bool success_p
= true;
8229 eassert (IT_CHARPOS (*it
) >= BEGV
);
8230 eassert (NILP (it
->string
) && !it
->s
);
8231 eassert (!it
->bidi_p
8232 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8233 && it
->bidi_it
.string
.s
== NULL
));
8235 /* With bidi reordering, the character to display might not be the
8236 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8237 we were reseat()ed to a new buffer position, which is potentially
8238 a different paragraph. */
8239 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8241 get_visually_first_element (it
);
8242 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8245 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8247 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8249 bool overlay_strings_follow_p
;
8251 /* End of the game, except when overlay strings follow that
8252 haven't been returned yet. */
8253 if (it
->overlay_strings_at_end_processed_p
)
8254 overlay_strings_follow_p
= false;
8257 it
->overlay_strings_at_end_processed_p
= true;
8258 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8261 if (overlay_strings_follow_p
)
8262 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8266 it
->position
= it
->current
.pos
;
8270 else if (!(!it
->bidi_p
8271 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8272 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8274 /* With bidi non-linear iteration, we could find ourselves
8275 far beyond the last computed stop_charpos, with several
8276 other stop positions in between that we missed. Scan
8277 them all now, in buffer's logical order, until we find
8278 and handle the last stop_charpos that precedes our
8279 current position. */
8280 handle_stop_backwards (it
, it
->stop_charpos
);
8281 it
->ignore_overlay_strings_at_pos_p
= false;
8282 return GET_NEXT_DISPLAY_ELEMENT (it
);
8288 /* Take note of the stop position we just moved across,
8289 for when we will move back across it. */
8290 it
->prev_stop
= it
->stop_charpos
;
8291 /* If we are at base paragraph embedding level, take
8292 note of the last stop position seen at this
8294 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8295 it
->base_level_stop
= it
->stop_charpos
;
8298 it
->ignore_overlay_strings_at_pos_p
= false;
8299 return GET_NEXT_DISPLAY_ELEMENT (it
);
8303 /* If we are before prev_stop, we may have overstepped on
8304 our way backwards a stop_pos, and if so, we need to
8305 handle that stop_pos. */
8306 && IT_CHARPOS (*it
) < it
->prev_stop
8307 /* We can sometimes back up for reasons that have nothing
8308 to do with bidi reordering. E.g., compositions. The
8309 code below is only needed when we are above the base
8310 embedding level, so test for that explicitly. */
8311 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8313 if (it
->base_level_stop
<= 0
8314 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8316 /* If we lost track of base_level_stop, we need to find
8317 prev_stop by looking backwards. This happens, e.g., when
8318 we were reseated to the previous screenful of text by
8320 it
->base_level_stop
= BEGV
;
8321 compute_stop_pos_backwards (it
);
8322 handle_stop_backwards (it
, it
->prev_stop
);
8325 handle_stop_backwards (it
, it
->base_level_stop
);
8326 it
->ignore_overlay_strings_at_pos_p
= false;
8327 return GET_NEXT_DISPLAY_ELEMENT (it
);
8331 /* No face changes, overlays etc. in sight, so just return a
8332 character from current_buffer. */
8336 /* We moved to the next buffer position, so any info about
8337 previously seen overlays is no longer valid. */
8338 it
->ignore_overlay_strings_at_pos_p
= false;
8340 /* Maybe run the redisplay end trigger hook. Performance note:
8341 This doesn't seem to cost measurable time. */
8342 if (it
->redisplay_end_trigger_charpos
8344 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8345 run_redisplay_end_trigger_hook (it
);
8347 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8348 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8350 && next_element_from_composition (it
))
8355 /* Get the next character, maybe multibyte. */
8356 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8357 if (it
->multibyte_p
&& !ASCII_CHAR_P (*p
))
8358 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8360 it
->c
= *p
, it
->len
= 1;
8362 /* Record what we have and where it came from. */
8363 it
->what
= IT_CHARACTER
;
8364 it
->object
= it
->w
->contents
;
8365 it
->position
= it
->current
.pos
;
8367 /* Normally we return the character found above, except when we
8368 really want to return an ellipsis for selective display. */
8373 /* A value of selective > 0 means hide lines indented more
8374 than that number of columns. */
8375 if (it
->selective
> 0
8376 && IT_CHARPOS (*it
) + 1 < ZV
8377 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8378 IT_BYTEPOS (*it
) + 1,
8381 success_p
= next_element_from_ellipsis (it
);
8382 it
->dpvec_char_len
= -1;
8385 else if (it
->c
== '\r' && it
->selective
== -1)
8387 /* A value of selective == -1 means that everything from the
8388 CR to the end of the line is invisible, with maybe an
8389 ellipsis displayed for it. */
8390 success_p
= next_element_from_ellipsis (it
);
8391 it
->dpvec_char_len
= -1;
8396 /* Value is false if end of buffer reached. */
8397 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8402 /* Run the redisplay end trigger hook for IT. */
8405 run_redisplay_end_trigger_hook (struct it
*it
)
8407 /* IT->glyph_row should be non-null, i.e. we should be actually
8408 displaying something, or otherwise we should not run the hook. */
8409 eassert (it
->glyph_row
);
8411 ptrdiff_t charpos
= it
->redisplay_end_trigger_charpos
;
8412 it
->redisplay_end_trigger_charpos
= 0;
8414 /* Since we are *trying* to run these functions, don't try to run
8415 them again, even if they get an error. */
8416 wset_redisplay_end_trigger (it
->w
, Qnil
);
8417 CALLN (Frun_hook_with_args
, Qredisplay_end_trigger_functions
, it
->window
,
8418 make_number (charpos
));
8420 /* Notice if it changed the face of the character we are on. */
8421 handle_face_prop (it
);
8425 /* Deliver a composition display element. Unlike the other
8426 next_element_from_XXX, this function is not registered in the array
8427 get_next_element[]. It is called from next_element_from_buffer and
8428 next_element_from_string when necessary. */
8431 next_element_from_composition (struct it
*it
)
8433 it
->what
= IT_COMPOSITION
;
8434 it
->len
= it
->cmp_it
.nbytes
;
8435 if (STRINGP (it
->string
))
8439 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8440 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8443 it
->position
= it
->current
.string_pos
;
8444 it
->object
= it
->string
;
8445 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8446 IT_STRING_BYTEPOS (*it
), it
->string
);
8452 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8453 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8456 if (it
->bidi_it
.new_paragraph
)
8457 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
8459 /* Resync the bidi iterator with IT's new position.
8460 FIXME: this doesn't support bidirectional text. */
8461 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8462 bidi_move_to_visually_next (&it
->bidi_it
);
8466 it
->position
= it
->current
.pos
;
8467 it
->object
= it
->w
->contents
;
8468 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8469 IT_BYTEPOS (*it
), Qnil
);
8476 /***********************************************************************
8477 Moving an iterator without producing glyphs
8478 ***********************************************************************/
8480 /* Check if iterator is at a position corresponding to a valid buffer
8481 position after some move_it_ call. */
8483 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8484 ((it)->method != GET_FROM_STRING || IT_STRING_CHARPOS (*it) == 0)
8487 /* Move iterator IT to a specified buffer or X position within one
8488 line on the display without producing glyphs.
8490 OP should be a bit mask including some or all of these bits:
8491 MOVE_TO_X: Stop upon reaching x-position TO_X.
8492 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8493 Regardless of OP's value, stop upon reaching the end of the display line.
8495 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8496 This means, in particular, that TO_X includes window's horizontal
8499 The return value has several possible values that
8500 say what condition caused the scan to stop:
8502 MOVE_POS_MATCH_OR_ZV
8503 - when TO_POS or ZV was reached.
8506 -when TO_X was reached before TO_POS or ZV were reached.
8509 - when we reached the end of the display area and the line must
8513 - when we reached the end of the display area and the line is
8517 - when we stopped at a line end, i.e. a newline or a CR and selective
8520 static enum move_it_result
8521 move_it_in_display_line_to (struct it
*it
,
8522 ptrdiff_t to_charpos
, int to_x
,
8523 enum move_operation_enum op
)
8525 enum move_it_result result
= MOVE_UNDEFINED
;
8526 struct glyph_row
*saved_glyph_row
;
8527 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8528 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8529 void *ppos_data
= NULL
;
8530 bool may_wrap
= false;
8531 enum it_method prev_method
= it
->method
;
8532 ptrdiff_t closest_pos
IF_LINT (= 0), prev_pos
= IT_CHARPOS (*it
);
8533 bool saw_smaller_pos
= prev_pos
< to_charpos
;
8535 /* Don't produce glyphs in produce_glyphs. */
8536 saved_glyph_row
= it
->glyph_row
;
8537 it
->glyph_row
= NULL
;
8539 /* Use wrap_it to save a copy of IT wherever a word wrap could
8540 occur. Use atpos_it to save a copy of IT at the desired buffer
8541 position, if found, so that we can scan ahead and check if the
8542 word later overshoots the window edge. Use atx_it similarly, for
8548 /* Use ppos_it under bidi reordering to save a copy of IT for the
8549 initial position. We restore that position in IT when we have
8550 scanned the entire display line without finding a match for
8551 TO_CHARPOS and all the character positions are greater than
8552 TO_CHARPOS. We then restart the scan from the initial position,
8553 and stop at CLOSEST_POS, which is a position > TO_CHARPOS that is
8554 the closest to TO_CHARPOS. */
8557 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8559 SAVE_IT (ppos_it
, *it
, ppos_data
);
8560 closest_pos
= IT_CHARPOS (*it
);
8566 #define BUFFER_POS_REACHED_P() \
8567 ((op & MOVE_TO_POS) != 0 \
8568 && BUFFERP (it->object) \
8569 && (IT_CHARPOS (*it) == to_charpos \
8571 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8572 && IT_CHARPOS (*it) > to_charpos) \
8573 || (it->what == IT_COMPOSITION \
8574 && ((IT_CHARPOS (*it) > to_charpos \
8575 && to_charpos >= it->cmp_it.charpos) \
8576 || (IT_CHARPOS (*it) < to_charpos \
8577 && to_charpos <= it->cmp_it.charpos)))) \
8578 && (it->method == GET_FROM_BUFFER \
8579 || (it->method == GET_FROM_DISPLAY_VECTOR \
8580 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8582 /* If there's a line-/wrap-prefix, handle it. */
8583 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8584 && it
->current_y
< it
->last_visible_y
)
8585 handle_line_prefix (it
);
8587 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8588 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8592 int x
, i
, ascent
= 0, descent
= 0;
8594 /* Utility macro to reset an iterator with x, ascent, and descent. */
8595 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8596 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8597 (IT)->max_descent = descent)
8599 /* Stop if we move beyond TO_CHARPOS (after an image or a
8600 display string or stretch glyph). */
8601 if ((op
& MOVE_TO_POS
) != 0
8602 && BUFFERP (it
->object
)
8603 && it
->method
== GET_FROM_BUFFER
8605 /* When the iterator is at base embedding level, we
8606 are guaranteed that characters are delivered for
8607 display in strictly increasing order of their
8608 buffer positions. */
8609 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8610 && IT_CHARPOS (*it
) > to_charpos
)
8612 && (prev_method
== GET_FROM_IMAGE
8613 || prev_method
== GET_FROM_STRETCH
8614 || prev_method
== GET_FROM_STRING
)
8615 /* Passed TO_CHARPOS from left to right. */
8616 && ((prev_pos
< to_charpos
8617 && IT_CHARPOS (*it
) > to_charpos
)
8618 /* Passed TO_CHARPOS from right to left. */
8619 || (prev_pos
> to_charpos
8620 && IT_CHARPOS (*it
) < to_charpos
)))))
8622 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8624 result
= MOVE_POS_MATCH_OR_ZV
;
8627 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8628 /* If wrap_it is valid, the current position might be in a
8629 word that is wrapped. So, save the iterator in
8630 atpos_it and continue to see if wrapping happens. */
8631 SAVE_IT (atpos_it
, *it
, atpos_data
);
8634 /* Stop when ZV reached.
8635 We used to stop here when TO_CHARPOS reached as well, but that is
8636 too soon if this glyph does not fit on this line. So we handle it
8637 explicitly below. */
8638 if (!get_next_display_element (it
))
8640 result
= MOVE_POS_MATCH_OR_ZV
;
8644 if (it
->line_wrap
== TRUNCATE
)
8646 if (BUFFER_POS_REACHED_P ())
8648 result
= MOVE_POS_MATCH_OR_ZV
;
8654 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
8656 if (IT_DISPLAYING_WHITESPACE (it
))
8660 /* We have reached a glyph that follows one or more
8661 whitespace characters. If the position is
8662 already found, we are done. */
8663 if (atpos_it
.sp
>= 0)
8665 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8666 result
= MOVE_POS_MATCH_OR_ZV
;
8671 RESTORE_IT (it
, &atx_it
, atx_data
);
8672 result
= MOVE_X_REACHED
;
8675 /* Otherwise, we can wrap here. */
8676 SAVE_IT (wrap_it
, *it
, wrap_data
);
8682 /* Remember the line height for the current line, in case
8683 the next element doesn't fit on the line. */
8684 ascent
= it
->max_ascent
;
8685 descent
= it
->max_descent
;
8687 /* The call to produce_glyphs will get the metrics of the
8688 display element IT is loaded with. Record the x-position
8689 before this display element, in case it doesn't fit on the
8693 PRODUCE_GLYPHS (it
);
8695 if (it
->area
!= TEXT_AREA
)
8697 prev_method
= it
->method
;
8698 if (it
->method
== GET_FROM_BUFFER
)
8699 prev_pos
= IT_CHARPOS (*it
);
8700 set_iterator_to_next (it
, true);
8701 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8702 SET_TEXT_POS (this_line_min_pos
,
8703 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8705 && (op
& MOVE_TO_POS
)
8706 && IT_CHARPOS (*it
) > to_charpos
8707 && IT_CHARPOS (*it
) < closest_pos
)
8708 closest_pos
= IT_CHARPOS (*it
);
8712 /* The number of glyphs we get back in IT->nglyphs will normally
8713 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8714 character on a terminal frame, or (iii) a line end. For the
8715 second case, IT->nglyphs - 1 padding glyphs will be present.
8716 (On X frames, there is only one glyph produced for a
8717 composite character.)
8719 The behavior implemented below means, for continuation lines,
8720 that as many spaces of a TAB as fit on the current line are
8721 displayed there. For terminal frames, as many glyphs of a
8722 multi-glyph character are displayed in the current line, too.
8723 This is what the old redisplay code did, and we keep it that
8724 way. Under X, the whole shape of a complex character must
8725 fit on the line or it will be completely displayed in the
8728 Note that both for tabs and padding glyphs, all glyphs have
8732 /* More than one glyph or glyph doesn't fit on line. All
8733 glyphs have the same width. */
8734 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8736 int x_before_this_char
= x
;
8737 int hpos_before_this_char
= it
->hpos
;
8739 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8741 new_x
= x
+ single_glyph_width
;
8743 /* We want to leave anything reaching TO_X to the caller. */
8744 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8746 if (BUFFER_POS_REACHED_P ())
8748 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8749 goto buffer_pos_reached
;
8750 if (atpos_it
.sp
< 0)
8752 SAVE_IT (atpos_it
, *it
, atpos_data
);
8753 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8758 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8761 result
= MOVE_X_REACHED
;
8766 SAVE_IT (atx_it
, *it
, atx_data
);
8767 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8772 if (/* Lines are continued. */
8773 it
->line_wrap
!= TRUNCATE
8774 && (/* And glyph doesn't fit on the line. */
8775 new_x
> it
->last_visible_x
8776 /* Or it fits exactly and we're on a window
8778 || (new_x
== it
->last_visible_x
8779 && FRAME_WINDOW_P (it
->f
)
8780 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8781 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8782 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8784 if (/* IT->hpos == 0 means the very first glyph
8785 doesn't fit on the line, e.g. a wide image. */
8787 || (new_x
== it
->last_visible_x
8788 && FRAME_WINDOW_P (it
->f
)))
8791 it
->current_x
= new_x
;
8793 /* The character's last glyph just barely fits
8795 if (i
== it
->nglyphs
- 1)
8797 /* If this is the destination position,
8798 return a position *before* it in this row,
8799 now that we know it fits in this row. */
8800 if (BUFFER_POS_REACHED_P ())
8802 if (it
->line_wrap
!= WORD_WRAP
8804 /* If we've just found whitespace to
8805 wrap, effectively ignore the
8806 previous wrap point -- it is no
8807 longer relevant, but we won't
8808 have an opportunity to update it,
8809 since we've reached the edge of
8810 this screen line. */
8812 && IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8814 it
->hpos
= hpos_before_this_char
;
8815 it
->current_x
= x_before_this_char
;
8816 result
= MOVE_POS_MATCH_OR_ZV
;
8819 if (it
->line_wrap
== WORD_WRAP
8822 SAVE_IT (atpos_it
, *it
, atpos_data
);
8823 atpos_it
.current_x
= x_before_this_char
;
8824 atpos_it
.hpos
= hpos_before_this_char
;
8828 prev_method
= it
->method
;
8829 if (it
->method
== GET_FROM_BUFFER
)
8830 prev_pos
= IT_CHARPOS (*it
);
8831 set_iterator_to_next (it
, true);
8832 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8833 SET_TEXT_POS (this_line_min_pos
,
8834 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8835 /* On graphical terminals, newlines may
8836 "overflow" into the fringe if
8837 overflow-newline-into-fringe is non-nil.
8838 On text terminals, and on graphical
8839 terminals with no right margin, newlines
8840 may overflow into the last glyph on the
8842 if (!FRAME_WINDOW_P (it
->f
)
8844 && it
->bidi_it
.paragraph_dir
== R2L
)
8845 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8846 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8847 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8849 if (!get_next_display_element (it
))
8851 result
= MOVE_POS_MATCH_OR_ZV
;
8854 if (BUFFER_POS_REACHED_P ())
8856 if (ITERATOR_AT_END_OF_LINE_P (it
))
8857 result
= MOVE_POS_MATCH_OR_ZV
;
8859 result
= MOVE_LINE_CONTINUED
;
8862 if (ITERATOR_AT_END_OF_LINE_P (it
)
8863 && (it
->line_wrap
!= WORD_WRAP
8865 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8867 result
= MOVE_NEWLINE_OR_CR
;
8874 IT_RESET_X_ASCENT_DESCENT (it
);
8876 /* If the screen line ends with whitespace, and we
8877 are under word-wrap, don't use wrap_it: it is no
8878 longer relevant, but we won't have an opportunity
8879 to update it, since we are done with this screen
8881 if (may_wrap
&& IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8883 /* If we've found TO_X, go back there, as we now
8884 know the last word fits on this screen line. */
8885 if ((op
& MOVE_TO_X
) && new_x
== it
->last_visible_x
8888 RESTORE_IT (it
, &atx_it
, atx_data
);
8891 result
= MOVE_X_REACHED
;
8895 else if (wrap_it
.sp
>= 0)
8897 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8902 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8904 result
= MOVE_LINE_CONTINUED
;
8908 if (BUFFER_POS_REACHED_P ())
8910 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8911 goto buffer_pos_reached
;
8912 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8914 SAVE_IT (atpos_it
, *it
, atpos_data
);
8915 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8919 if (new_x
> it
->first_visible_x
)
8921 /* Glyph is visible. Increment number of glyphs that
8922 would be displayed. */
8927 if (result
!= MOVE_UNDEFINED
)
8930 else if (BUFFER_POS_REACHED_P ())
8933 IT_RESET_X_ASCENT_DESCENT (it
);
8934 result
= MOVE_POS_MATCH_OR_ZV
;
8937 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8939 /* Stop when TO_X specified and reached. This check is
8940 necessary here because of lines consisting of a line end,
8941 only. The line end will not produce any glyphs and we
8942 would never get MOVE_X_REACHED. */
8943 eassert (it
->nglyphs
== 0);
8944 result
= MOVE_X_REACHED
;
8948 /* Is this a line end? If yes, we're done. */
8949 if (ITERATOR_AT_END_OF_LINE_P (it
))
8951 /* If we are past TO_CHARPOS, but never saw any character
8952 positions smaller than TO_CHARPOS, return
8953 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8955 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8957 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8959 if (closest_pos
< ZV
)
8961 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8962 /* Don't recurse if closest_pos is equal to
8963 to_charpos, since we have just tried that. */
8964 if (closest_pos
!= to_charpos
)
8965 move_it_in_display_line_to (it
, closest_pos
, -1,
8967 result
= MOVE_POS_MATCH_OR_ZV
;
8970 goto buffer_pos_reached
;
8972 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8973 && IT_CHARPOS (*it
) > to_charpos
)
8974 goto buffer_pos_reached
;
8976 result
= MOVE_NEWLINE_OR_CR
;
8979 result
= MOVE_NEWLINE_OR_CR
;
8983 prev_method
= it
->method
;
8984 if (it
->method
== GET_FROM_BUFFER
)
8985 prev_pos
= IT_CHARPOS (*it
);
8986 /* The current display element has been consumed. Advance
8988 set_iterator_to_next (it
, true);
8989 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8990 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8991 if (IT_CHARPOS (*it
) < to_charpos
)
8992 saw_smaller_pos
= true;
8994 && (op
& MOVE_TO_POS
)
8995 && IT_CHARPOS (*it
) >= to_charpos
8996 && IT_CHARPOS (*it
) < closest_pos
)
8997 closest_pos
= IT_CHARPOS (*it
);
8999 /* Stop if lines are truncated and IT's current x-position is
9000 past the right edge of the window now. */
9001 if (it
->line_wrap
== TRUNCATE
9002 && it
->current_x
>= it
->last_visible_x
)
9004 if (!FRAME_WINDOW_P (it
->f
)
9005 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
9006 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
9007 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
9008 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
9010 bool at_eob_p
= false;
9012 if ((at_eob_p
= !get_next_display_element (it
))
9013 || BUFFER_POS_REACHED_P ()
9014 /* If we are past TO_CHARPOS, but never saw any
9015 character positions smaller than TO_CHARPOS,
9016 return MOVE_POS_MATCH_OR_ZV, like the
9017 unidirectional display did. */
9018 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
9020 && IT_CHARPOS (*it
) > to_charpos
))
9023 && !BUFFER_POS_REACHED_P ()
9024 && !at_eob_p
&& closest_pos
< ZV
)
9026 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9027 if (closest_pos
!= to_charpos
)
9028 move_it_in_display_line_to (it
, closest_pos
, -1,
9031 result
= MOVE_POS_MATCH_OR_ZV
;
9034 if (ITERATOR_AT_END_OF_LINE_P (it
))
9036 result
= MOVE_NEWLINE_OR_CR
;
9040 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
9042 && IT_CHARPOS (*it
) > to_charpos
)
9044 if (closest_pos
< ZV
)
9046 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9047 if (closest_pos
!= to_charpos
)
9048 move_it_in_display_line_to (it
, closest_pos
, -1,
9051 result
= MOVE_POS_MATCH_OR_ZV
;
9054 result
= MOVE_LINE_TRUNCATED
;
9057 #undef IT_RESET_X_ASCENT_DESCENT
9060 #undef BUFFER_POS_REACHED_P
9062 /* If we scanned beyond to_pos and didn't find a point to wrap at,
9063 restore the saved iterator. */
9064 if (atpos_it
.sp
>= 0)
9065 RESTORE_IT (it
, &atpos_it
, atpos_data
);
9066 else if (atx_it
.sp
>= 0)
9067 RESTORE_IT (it
, &atx_it
, atx_data
);
9072 bidi_unshelve_cache (atpos_data
, true);
9074 bidi_unshelve_cache (atx_data
, true);
9076 bidi_unshelve_cache (wrap_data
, true);
9078 bidi_unshelve_cache (ppos_data
, true);
9080 /* Restore the iterator settings altered at the beginning of this
9082 it
->glyph_row
= saved_glyph_row
;
9086 /* For external use. */
9088 move_it_in_display_line (struct it
*it
,
9089 ptrdiff_t to_charpos
, int to_x
,
9090 enum move_operation_enum op
)
9092 if (it
->line_wrap
== WORD_WRAP
9093 && (op
& MOVE_TO_X
))
9096 void *save_data
= NULL
;
9099 SAVE_IT (save_it
, *it
, save_data
);
9100 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9101 /* When word-wrap is on, TO_X may lie past the end
9102 of a wrapped line. Then it->current is the
9103 character on the next line, so backtrack to the
9104 space before the wrap point. */
9105 if (skip
== MOVE_LINE_CONTINUED
)
9107 int prev_x
= max (it
->current_x
- 1, 0);
9108 RESTORE_IT (it
, &save_it
, save_data
);
9109 move_it_in_display_line_to
9110 (it
, -1, prev_x
, MOVE_TO_X
);
9113 bidi_unshelve_cache (save_data
, true);
9116 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9120 /* Move IT forward until it satisfies one or more of the criteria in
9121 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
9123 OP is a bit-mask that specifies where to stop, and in particular,
9124 which of those four position arguments makes a difference. See the
9125 description of enum move_operation_enum.
9127 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
9128 screen line, this function will set IT to the next position that is
9129 displayed to the right of TO_CHARPOS on the screen.
9131 Return the maximum pixel length of any line scanned but never more
9132 than it.last_visible_x. */
9135 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
9137 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
9138 int line_height
, line_start_x
= 0, reached
= 0;
9139 int max_current_x
= 0;
9140 void *backup_data
= NULL
;
9144 if (op
& MOVE_TO_VPOS
)
9146 /* If no TO_CHARPOS and no TO_X specified, stop at the
9147 start of the line TO_VPOS. */
9148 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
9150 if (it
->vpos
== to_vpos
)
9156 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
9160 /* TO_VPOS >= 0 means stop at TO_X in the line at
9161 TO_VPOS, or at TO_POS, whichever comes first. */
9162 if (it
->vpos
== to_vpos
)
9168 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9170 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
9175 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
9177 /* We have reached TO_X but not in the line we want. */
9178 skip
= move_it_in_display_line_to (it
, to_charpos
,
9180 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9188 else if (op
& MOVE_TO_Y
)
9190 struct it it_backup
;
9192 if (it
->line_wrap
== WORD_WRAP
)
9193 SAVE_IT (it_backup
, *it
, backup_data
);
9195 /* TO_Y specified means stop at TO_X in the line containing
9196 TO_Y---or at TO_CHARPOS if this is reached first. The
9197 problem is that we can't really tell whether the line
9198 contains TO_Y before we have completely scanned it, and
9199 this may skip past TO_X. What we do is to first scan to
9202 If TO_X is not specified, use a TO_X of zero. The reason
9203 is to make the outcome of this function more predictable.
9204 If we didn't use TO_X == 0, we would stop at the end of
9205 the line which is probably not what a caller would expect
9207 skip
= move_it_in_display_line_to
9208 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
9209 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
9211 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
9212 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9214 else if (skip
== MOVE_X_REACHED
)
9216 /* If TO_X was reached, we want to know whether TO_Y is
9217 in the line. We know this is the case if the already
9218 scanned glyphs make the line tall enough. Otherwise,
9219 we must check by scanning the rest of the line. */
9220 line_height
= it
->max_ascent
+ it
->max_descent
;
9221 if (to_y
>= it
->current_y
9222 && to_y
< it
->current_y
+ line_height
)
9227 SAVE_IT (it_backup
, *it
, backup_data
);
9228 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
9229 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
9231 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
9232 line_height
= it
->max_ascent
+ it
->max_descent
;
9233 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9235 if (to_y
>= it
->current_y
9236 && to_y
< it
->current_y
+ line_height
)
9238 /* If TO_Y is in this line and TO_X was reached
9239 above, we scanned too far. We have to restore
9240 IT's settings to the ones before skipping. But
9241 keep the more accurate values of max_ascent and
9242 max_descent we've found while skipping the rest
9243 of the line, for the sake of callers, such as
9244 pos_visible_p, that need to know the line
9246 int max_ascent
= it
->max_ascent
;
9247 int max_descent
= it
->max_descent
;
9249 RESTORE_IT (it
, &it_backup
, backup_data
);
9250 it
->max_ascent
= max_ascent
;
9251 it
->max_descent
= max_descent
;
9257 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9263 /* Check whether TO_Y is in this line. */
9264 line_height
= it
->max_ascent
+ it
->max_descent
;
9265 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9267 if (to_y
>= it
->current_y
9268 && to_y
< it
->current_y
+ line_height
)
9270 if (to_y
> it
->current_y
)
9271 max_current_x
= max (it
->current_x
, max_current_x
);
9273 /* When word-wrap is on, TO_X may lie past the end
9274 of a wrapped line. Then it->current is the
9275 character on the next line, so backtrack to the
9276 space before the wrap point. */
9277 if (skip
== MOVE_LINE_CONTINUED
9278 && it
->line_wrap
== WORD_WRAP
)
9280 int prev_x
= max (it
->current_x
- 1, 0);
9281 RESTORE_IT (it
, &it_backup
, backup_data
);
9282 skip
= move_it_in_display_line_to
9283 (it
, -1, prev_x
, MOVE_TO_X
);
9292 max_current_x
= max (it
->current_x
, max_current_x
);
9296 else if (BUFFERP (it
->object
)
9297 && (it
->method
== GET_FROM_BUFFER
9298 || it
->method
== GET_FROM_STRETCH
)
9299 && IT_CHARPOS (*it
) >= to_charpos
9300 /* Under bidi iteration, a call to set_iterator_to_next
9301 can scan far beyond to_charpos if the initial
9302 portion of the next line needs to be reordered. In
9303 that case, give move_it_in_display_line_to another
9306 && it
->bidi_it
.scan_dir
== -1))
9307 skip
= MOVE_POS_MATCH_OR_ZV
;
9309 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9313 case MOVE_POS_MATCH_OR_ZV
:
9314 max_current_x
= max (it
->current_x
, max_current_x
);
9318 case MOVE_NEWLINE_OR_CR
:
9319 max_current_x
= max (it
->current_x
, max_current_x
);
9320 set_iterator_to_next (it
, true);
9321 it
->continuation_lines_width
= 0;
9324 case MOVE_LINE_TRUNCATED
:
9325 max_current_x
= it
->last_visible_x
;
9326 it
->continuation_lines_width
= 0;
9327 reseat_at_next_visible_line_start (it
, false);
9328 if ((op
& MOVE_TO_POS
) != 0
9329 && IT_CHARPOS (*it
) > to_charpos
)
9336 case MOVE_LINE_CONTINUED
:
9337 max_current_x
= it
->last_visible_x
;
9338 /* For continued lines ending in a tab, some of the glyphs
9339 associated with the tab are displayed on the current
9340 line. Since it->current_x does not include these glyphs,
9341 we use it->last_visible_x instead. */
9344 it
->continuation_lines_width
+= it
->last_visible_x
;
9345 /* When moving by vpos, ensure that the iterator really
9346 advances to the next line (bug#847, bug#969). Fixme:
9347 do we need to do this in other circumstances? */
9348 if (it
->current_x
!= it
->last_visible_x
9349 && (op
& MOVE_TO_VPOS
)
9350 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9352 line_start_x
= it
->current_x
+ it
->pixel_width
9353 - it
->last_visible_x
;
9354 if (FRAME_WINDOW_P (it
->f
))
9356 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
9357 struct font
*face_font
= face
->font
;
9359 /* When display_line produces a continued line
9360 that ends in a TAB, it skips a tab stop that
9361 is closer than the font's space character
9362 width (see x_produce_glyphs where it produces
9363 the stretch glyph which represents a TAB).
9364 We need to reproduce the same logic here. */
9365 eassert (face_font
);
9368 if (line_start_x
< face_font
->space_width
)
9370 += it
->tab_width
* face_font
->space_width
;
9373 set_iterator_to_next (it
, false);
9377 it
->continuation_lines_width
+= it
->current_x
;
9384 /* Reset/increment for the next run. */
9385 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9386 it
->current_x
= line_start_x
;
9389 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9391 last_height
= it
->max_ascent
+ it
->max_descent
;
9392 it
->max_ascent
= it
->max_descent
= 0;
9397 /* On text terminals, we may stop at the end of a line in the middle
9398 of a multi-character glyph. If the glyph itself is continued,
9399 i.e. it is actually displayed on the next line, don't treat this
9400 stopping point as valid; move to the next line instead (unless
9401 that brings us offscreen). */
9402 if (!FRAME_WINDOW_P (it
->f
)
9404 && IT_CHARPOS (*it
) == to_charpos
9405 && it
->what
== IT_CHARACTER
9407 && it
->line_wrap
== WINDOW_WRAP
9408 && it
->current_x
== it
->last_visible_x
- 1
9411 && it
->w
->window_end_valid
9412 && it
->vpos
< it
->w
->window_end_vpos
)
9414 it
->continuation_lines_width
+= it
->current_x
;
9415 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9416 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9418 last_height
= it
->max_ascent
+ it
->max_descent
;
9422 bidi_unshelve_cache (backup_data
, true);
9424 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9426 return max_current_x
;
9430 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9432 If DY > 0, move IT backward at least that many pixels. DY = 0
9433 means move IT backward to the preceding line start or BEGV. This
9434 function may move over more than DY pixels if IT->current_y - DY
9435 ends up in the middle of a line; in this case IT->current_y will be
9436 set to the top of the line moved to. */
9439 move_it_vertically_backward (struct it
*it
, int dy
)
9443 void *it2data
= NULL
, *it3data
= NULL
;
9444 ptrdiff_t start_pos
;
9446 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9447 ptrdiff_t pos_limit
;
9452 start_pos
= IT_CHARPOS (*it
);
9454 /* Estimate how many newlines we must move back. */
9455 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9456 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9459 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9461 /* Set the iterator's position that many lines back. But don't go
9462 back more than NLINES full screen lines -- this wins a day with
9463 buffers which have very long lines. */
9464 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9465 back_to_previous_visible_line_start (it
);
9467 /* Reseat the iterator here. When moving backward, we don't want
9468 reseat to skip forward over invisible text, set up the iterator
9469 to deliver from overlay strings at the new position etc. So,
9470 use reseat_1 here. */
9471 reseat_1 (it
, it
->current
.pos
, true);
9473 /* We are now surely at a line start. */
9474 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9475 reordering is in effect. */
9476 it
->continuation_lines_width
= 0;
9478 /* Move forward and see what y-distance we moved. First move to the
9479 start of the next line so that we get its height. We need this
9480 height to be able to tell whether we reached the specified
9482 SAVE_IT (it2
, *it
, it2data
);
9483 it2
.max_ascent
= it2
.max_descent
= 0;
9486 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9487 MOVE_TO_POS
| MOVE_TO_VPOS
);
9489 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9490 /* If we are in a display string which starts at START_POS,
9491 and that display string includes a newline, and we are
9492 right after that newline (i.e. at the beginning of a
9493 display line), exit the loop, because otherwise we will
9494 infloop, since move_it_to will see that it is already at
9495 START_POS and will not move. */
9496 || (it2
.method
== GET_FROM_STRING
9497 && IT_CHARPOS (it2
) == start_pos
9498 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9499 eassert (IT_CHARPOS (*it
) >= BEGV
);
9500 SAVE_IT (it3
, it2
, it3data
);
9502 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9503 eassert (IT_CHARPOS (*it
) >= BEGV
);
9504 /* H is the actual vertical distance from the position in *IT
9505 and the starting position. */
9506 h
= it2
.current_y
- it
->current_y
;
9507 /* NLINES is the distance in number of lines. */
9508 nlines
= it2
.vpos
- it
->vpos
;
9510 /* Correct IT's y and vpos position
9511 so that they are relative to the starting point. */
9517 /* DY == 0 means move to the start of the screen line. The
9518 value of nlines is > 0 if continuation lines were involved,
9519 or if the original IT position was at start of a line. */
9520 RESTORE_IT (it
, it
, it2data
);
9522 move_it_by_lines (it
, nlines
);
9523 /* The above code moves us to some position NLINES down,
9524 usually to its first glyph (leftmost in an L2R line), but
9525 that's not necessarily the start of the line, under bidi
9526 reordering. We want to get to the character position
9527 that is immediately after the newline of the previous
9530 && !it
->continuation_lines_width
9531 && !STRINGP (it
->string
)
9532 && IT_CHARPOS (*it
) > BEGV
9533 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9535 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9538 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9539 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9541 bidi_unshelve_cache (it3data
, true);
9545 /* The y-position we try to reach, relative to *IT.
9546 Note that H has been subtracted in front of the if-statement. */
9547 int target_y
= it
->current_y
+ h
- dy
;
9548 int y0
= it3
.current_y
;
9552 RESTORE_IT (&it3
, &it3
, it3data
);
9553 y1
= line_bottom_y (&it3
);
9554 line_height
= y1
- y0
;
9555 RESTORE_IT (it
, it
, it2data
);
9556 /* If we did not reach target_y, try to move further backward if
9557 we can. If we moved too far backward, try to move forward. */
9558 if (target_y
< it
->current_y
9559 /* This is heuristic. In a window that's 3 lines high, with
9560 a line height of 13 pixels each, recentering with point
9561 on the bottom line will try to move -39/2 = 19 pixels
9562 backward. Try to avoid moving into the first line. */
9563 && (it
->current_y
- target_y
9564 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9565 && IT_CHARPOS (*it
) > BEGV
)
9567 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9568 target_y
- it
->current_y
));
9569 dy
= it
->current_y
- target_y
;
9570 goto move_further_back
;
9572 else if (target_y
>= it
->current_y
+ line_height
9573 && IT_CHARPOS (*it
) < ZV
)
9575 /* Should move forward by at least one line, maybe more.
9577 Note: Calling move_it_by_lines can be expensive on
9578 terminal frames, where compute_motion is used (via
9579 vmotion) to do the job, when there are very long lines
9580 and truncate-lines is nil. That's the reason for
9581 treating terminal frames specially here. */
9583 if (!FRAME_WINDOW_P (it
->f
))
9584 move_it_vertically (it
, target_y
- it
->current_y
);
9589 move_it_by_lines (it
, 1);
9591 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9598 /* Move IT by a specified amount of pixel lines DY. DY negative means
9599 move backwards. DY = 0 means move to start of screen line. At the
9600 end, IT will be on the start of a screen line. */
9603 move_it_vertically (struct it
*it
, int dy
)
9606 move_it_vertically_backward (it
, -dy
);
9609 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9610 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9611 MOVE_TO_POS
| MOVE_TO_Y
);
9612 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9614 /* If buffer ends in ZV without a newline, move to the start of
9615 the line to satisfy the post-condition. */
9616 if (IT_CHARPOS (*it
) == ZV
9618 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9619 move_it_by_lines (it
, 0);
9624 /* Move iterator IT past the end of the text line it is in. */
9627 move_it_past_eol (struct it
*it
)
9629 enum move_it_result rc
;
9631 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9632 if (rc
== MOVE_NEWLINE_OR_CR
)
9633 set_iterator_to_next (it
, false);
9637 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9638 negative means move up. DVPOS == 0 means move to the start of the
9641 Optimization idea: If we would know that IT->f doesn't use
9642 a face with proportional font, we could be faster for
9643 truncate-lines nil. */
9646 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9649 /* The commented-out optimization uses vmotion on terminals. This
9650 gives bad results, because elements like it->what, on which
9651 callers such as pos_visible_p rely, aren't updated. */
9652 /* struct position pos;
9653 if (!FRAME_WINDOW_P (it->f))
9655 struct text_pos textpos;
9657 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9658 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9659 reseat (it, textpos, true);
9660 it->vpos += pos.vpos;
9661 it->current_y += pos.vpos;
9667 /* DVPOS == 0 means move to the start of the screen line. */
9668 move_it_vertically_backward (it
, 0);
9669 /* Let next call to line_bottom_y calculate real line height. */
9674 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9675 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9677 /* Only move to the next buffer position if we ended up in a
9678 string from display property, not in an overlay string
9679 (before-string or after-string). That is because the
9680 latter don't conceal the underlying buffer position, so
9681 we can ask to move the iterator to the exact position we
9682 are interested in. Note that, even if we are already at
9683 IT_CHARPOS (*it), the call below is not a no-op, as it
9684 will detect that we are at the end of the string, pop the
9685 iterator, and compute it->current_x and it->hpos
9687 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9688 -1, -1, -1, MOVE_TO_POS
);
9694 void *it2data
= NULL
;
9695 ptrdiff_t start_charpos
, i
;
9697 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9698 bool hit_pos_limit
= false;
9699 ptrdiff_t pos_limit
;
9701 /* Start at the beginning of the screen line containing IT's
9702 position. This may actually move vertically backwards,
9703 in case of overlays, so adjust dvpos accordingly. */
9705 move_it_vertically_backward (it
, 0);
9708 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9709 screen lines, and reseat the iterator there. */
9710 start_charpos
= IT_CHARPOS (*it
);
9711 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9714 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9716 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9717 back_to_previous_visible_line_start (it
);
9718 if (i
> 0 && IT_CHARPOS (*it
) <= pos_limit
)
9719 hit_pos_limit
= true;
9720 reseat (it
, it
->current
.pos
, true);
9722 /* Move further back if we end up in a string or an image. */
9723 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9725 /* First try to move to start of display line. */
9727 move_it_vertically_backward (it
, 0);
9729 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9731 /* If start of line is still in string or image,
9732 move further back. */
9733 back_to_previous_visible_line_start (it
);
9734 reseat (it
, it
->current
.pos
, true);
9738 it
->current_x
= it
->hpos
= 0;
9740 /* Above call may have moved too far if continuation lines
9741 are involved. Scan forward and see if it did. */
9742 SAVE_IT (it2
, *it
, it2data
);
9743 it2
.vpos
= it2
.current_y
= 0;
9744 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9745 it
->vpos
-= it2
.vpos
;
9746 it
->current_y
-= it2
.current_y
;
9747 it
->current_x
= it
->hpos
= 0;
9749 /* If we moved too far back, move IT some lines forward. */
9750 if (it2
.vpos
> -dvpos
)
9752 int delta
= it2
.vpos
+ dvpos
;
9754 RESTORE_IT (&it2
, &it2
, it2data
);
9755 SAVE_IT (it2
, *it
, it2data
);
9756 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9757 /* Move back again if we got too far ahead. */
9758 if (IT_CHARPOS (*it
) >= start_charpos
)
9759 RESTORE_IT (it
, &it2
, it2data
);
9761 bidi_unshelve_cache (it2data
, true);
9763 else if (hit_pos_limit
&& pos_limit
> BEGV
9764 && dvpos
< 0 && it2
.vpos
< -dvpos
)
9766 /* If we hit the limit, but still didn't make it far enough
9767 back, that means there's a display string with a newline
9768 covering a large chunk of text, and that caused
9769 back_to_previous_visible_line_start try to go too far.
9770 Punish those who commit such atrocities by going back
9771 until we've reached DVPOS, after lifting the limit, which
9772 could make it slow for very long lines. "If it hurts,
9775 RESTORE_IT (it
, it
, it2data
);
9776 for (i
= -dvpos
; i
> 0; --i
)
9778 back_to_previous_visible_line_start (it
);
9781 reseat_1 (it
, it
->current
.pos
, true);
9784 RESTORE_IT (it
, it
, it2data
);
9788 /* Return true if IT points into the middle of a display vector. */
9791 in_display_vector_p (struct it
*it
)
9793 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9794 && it
->current
.dpvec_index
> 0
9795 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9798 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9799 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9800 WINDOW must be a live window and defaults to the selected one. The
9801 return value is a cons of the maximum pixel-width of any text line and
9802 the maximum pixel-height of all text lines.
9804 The optional argument FROM, if non-nil, specifies the first text
9805 position and defaults to the minimum accessible position of the buffer.
9806 If FROM is t, use the minimum accessible position that is not a newline
9807 character. TO, if non-nil, specifies the last text position and
9808 defaults to the maximum accessible position of the buffer. If TO is t,
9809 use the maximum accessible position that is not a newline character.
9811 The optional argument X-LIMIT, if non-nil, specifies the maximum text
9812 width that can be returned. X-LIMIT nil or omitted, means to use the
9813 pixel-width of WINDOW's body; use this if you do not intend to change
9814 the width of WINDOW. Use the maximum width WINDOW may assume if you
9815 intend to change WINDOW's width. In any case, text whose x-coordinate
9816 is beyond X-LIMIT is ignored. Since calculating the width of long lines
9817 can take some time, it's always a good idea to make this argument as
9818 small as possible; in particular, if the buffer contains long lines that
9819 shall be truncated anyway.
9821 The optional argument Y-LIMIT, if non-nil, specifies the maximum text
9822 height that can be returned. Text lines whose y-coordinate is beyond
9823 Y-LIMIT are ignored. Since calculating the text height of a large
9824 buffer can take some time, it makes sense to specify this argument if
9825 the size of the buffer is unknown.
9827 Optional argument MODE-AND-HEADER-LINE nil or omitted means do not
9828 include the height of the mode- or header-line of WINDOW in the return
9829 value. If it is either the symbol `mode-line' or `header-line', include
9830 only the height of that line, if present, in the return value. If t,
9831 include the height of both, if present, in the return value. */)
9832 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
,
9833 Lisp_Object y_limit
, Lisp_Object mode_and_header_line
)
9835 struct window
*w
= decode_live_window (window
);
9836 Lisp_Object buffer
= w
->contents
;
9839 struct buffer
*old_b
= NULL
;
9840 ptrdiff_t start
, end
, pos
;
9841 struct text_pos startp
;
9842 void *itdata
= NULL
;
9843 int c
, max_y
= -1, x
= 0, y
= 0;
9845 CHECK_BUFFER (buffer
);
9846 b
= XBUFFER (buffer
);
9848 if (b
!= current_buffer
)
9850 old_b
= current_buffer
;
9851 set_buffer_internal (b
);
9856 else if (EQ (from
, Qt
))
9859 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9860 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9862 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9867 CHECK_NUMBER_COERCE_MARKER (from
);
9868 start
= min (max (XINT (from
), BEGV
), ZV
);
9873 else if (EQ (to
, Qt
))
9876 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9877 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9879 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9884 CHECK_NUMBER_COERCE_MARKER (to
);
9885 end
= max (start
, min (XINT (to
), ZV
));
9888 if (!NILP (y_limit
))
9890 CHECK_NUMBER (y_limit
);
9891 max_y
= min (XINT (y_limit
), INT_MAX
);
9894 itdata
= bidi_shelve_cache ();
9895 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9896 start_display (&it
, w
, startp
);
9899 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9902 CHECK_NUMBER (x_limit
);
9903 it
.last_visible_x
= min (XINT (x_limit
), INFINITY
);
9904 /* Actually, we never want move_it_to stop at to_x. But to make
9905 sure that move_it_in_display_line_to always moves far enough,
9906 we set it to INT_MAX and specify MOVE_TO_X. */
9907 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9908 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9911 y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9913 if (!EQ (mode_and_header_line
, Qheader_line
)
9914 && !EQ (mode_and_header_line
, Qt
))
9915 /* Do not count the header-line which was counted automatically by
9917 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9919 if (EQ (mode_and_header_line
, Qmode_line
)
9920 || EQ (mode_and_header_line
, Qt
))
9921 /* Do count the mode-line which is not included automatically by
9923 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9925 bidi_unshelve_cache (itdata
, false);
9928 set_buffer_internal (old_b
);
9930 return Fcons (make_number (x
), make_number (y
));
9933 /***********************************************************************
9935 ***********************************************************************/
9937 /* Return the number of arguments the format string FORMAT needs. */
9940 format_nargs (char const *format
)
9942 ptrdiff_t nargs
= 0;
9943 for (char const *p
= format
; (p
= strchr (p
, '%')); p
++)
9951 /* Add a message with format string FORMAT and formatted arguments
9955 add_to_log (const char *format
, ...)
9958 va_start (ap
, format
);
9959 vadd_to_log (format
, ap
);
9964 vadd_to_log (char const *format
, va_list ap
)
9966 ptrdiff_t form_nargs
= format_nargs (format
);
9967 ptrdiff_t nargs
= 1 + form_nargs
;
9968 Lisp_Object args
[10];
9969 eassert (nargs
<= ARRAYELTS (args
));
9970 AUTO_STRING (args0
, format
);
9972 for (ptrdiff_t i
= 1; i
<= nargs
; i
++)
9973 args
[i
] = va_arg (ap
, Lisp_Object
);
9974 Lisp_Object msg
= Qnil
;
9975 msg
= Fformat_message (nargs
, args
);
9977 ptrdiff_t len
= SBYTES (msg
) + 1;
9979 char *buffer
= SAFE_ALLOCA (len
);
9980 memcpy (buffer
, SDATA (msg
), len
);
9982 message_dolog (buffer
, len
- 1, true, STRING_MULTIBYTE (msg
));
9987 /* Output a newline in the *Messages* buffer if "needs" one. */
9990 message_log_maybe_newline (void)
9992 if (message_log_need_newline
)
9993 message_dolog ("", 0, true, false);
9997 /* Add a string M of length NBYTES to the message log, optionally
9998 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9999 true, means interpret the contents of M as multibyte. This
10000 function calls low-level routines in order to bypass text property
10001 hooks, etc. which might not be safe to run.
10003 This may GC (insert may run before/after change hooks),
10004 so the buffer M must NOT point to a Lisp string. */
10007 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
10009 const unsigned char *msg
= (const unsigned char *) m
;
10011 if (!NILP (Vmemory_full
))
10014 if (!NILP (Vmessage_log_max
))
10016 struct buffer
*oldbuf
;
10017 Lisp_Object oldpoint
, oldbegv
, oldzv
;
10018 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
10019 ptrdiff_t point_at_end
= 0;
10020 ptrdiff_t zv_at_end
= 0;
10021 Lisp_Object old_deactivate_mark
;
10023 old_deactivate_mark
= Vdeactivate_mark
;
10024 oldbuf
= current_buffer
;
10026 /* Ensure the Messages buffer exists, and switch to it.
10027 If we created it, set the major-mode. */
10028 bool newbuffer
= NILP (Fget_buffer (Vmessages_buffer_name
));
10029 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
10031 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
10032 call0 (intern ("messages-buffer-mode"));
10034 bset_undo_list (current_buffer
, Qt
);
10035 bset_cache_long_scans (current_buffer
, Qnil
);
10037 oldpoint
= message_dolog_marker1
;
10038 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
10039 oldbegv
= message_dolog_marker2
;
10040 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
10041 oldzv
= message_dolog_marker3
;
10042 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
10050 BEGV_BYTE
= BEG_BYTE
;
10053 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10055 /* Insert the string--maybe converting multibyte to single byte
10056 or vice versa, so that all the text fits the buffer. */
10058 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10064 /* Convert a multibyte string to single-byte
10065 for the *Message* buffer. */
10066 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
10068 c
= string_char_and_length (msg
+ i
, &char_bytes
);
10069 work
[0] = CHAR_TO_BYTE8 (c
);
10070 insert_1_both (work
, 1, 1, true, false, false);
10073 else if (! multibyte
10074 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10078 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10079 /* Convert a single-byte string to multibyte
10080 for the *Message* buffer. */
10081 for (i
= 0; i
< nbytes
; i
++)
10084 MAKE_CHAR_MULTIBYTE (c
);
10085 char_bytes
= CHAR_STRING (c
, str
);
10086 insert_1_both ((char *) str
, 1, char_bytes
, true, false, false);
10090 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
,
10091 true, false, false);
10095 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
10098 insert_1_both ("\n", 1, 1, true, false, false);
10100 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, false);
10102 this_bol_byte
= PT_BYTE
;
10104 /* See if this line duplicates the previous one.
10105 If so, combine duplicates. */
10106 if (this_bol
> BEG
)
10108 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, false);
10110 prev_bol_byte
= PT_BYTE
;
10112 dups
= message_log_check_duplicate (prev_bol_byte
,
10116 del_range_both (prev_bol
, prev_bol_byte
,
10117 this_bol
, this_bol_byte
, false);
10120 char dupstr
[sizeof " [ times]"
10121 + INT_STRLEN_BOUND (printmax_t
)];
10123 /* If you change this format, don't forget to also
10124 change message_log_check_duplicate. */
10125 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
10126 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
10127 insert_1_both (dupstr
, duplen
, duplen
,
10128 true, false, true);
10133 /* If we have more than the desired maximum number of lines
10134 in the *Messages* buffer now, delete the oldest ones.
10135 This is safe because we don't have undo in this buffer. */
10137 if (NATNUMP (Vmessage_log_max
))
10139 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
10140 -XFASTINT (Vmessage_log_max
) - 1, false);
10141 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, false);
10144 BEGV
= marker_position (oldbegv
);
10145 BEGV_BYTE
= marker_byte_position (oldbegv
);
10154 ZV
= marker_position (oldzv
);
10155 ZV_BYTE
= marker_byte_position (oldzv
);
10159 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10161 /* We can't do Fgoto_char (oldpoint) because it will run some
10163 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
10164 marker_byte_position (oldpoint
));
10166 unchain_marker (XMARKER (oldpoint
));
10167 unchain_marker (XMARKER (oldbegv
));
10168 unchain_marker (XMARKER (oldzv
));
10170 /* We called insert_1_both above with its 5th argument (PREPARE)
10171 false, which prevents insert_1_both from calling
10172 prepare_to_modify_buffer, which in turns prevents us from
10173 incrementing windows_or_buffers_changed even if *Messages* is
10174 shown in some window. So we must manually set
10175 windows_or_buffers_changed here to make up for that. */
10176 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
10177 bset_redisplay (current_buffer
);
10179 set_buffer_internal (oldbuf
);
10181 message_log_need_newline
= !nlflag
;
10182 Vdeactivate_mark
= old_deactivate_mark
;
10187 /* We are at the end of the buffer after just having inserted a newline.
10188 (Note: We depend on the fact we won't be crossing the gap.)
10189 Check to see if the most recent message looks a lot like the previous one.
10190 Return 0 if different, 1 if the new one should just replace it, or a
10191 value N > 1 if we should also append " [N times]". */
10194 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
10197 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
10198 bool seen_dots
= false;
10199 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
10200 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
10202 for (i
= 0; i
< len
; i
++)
10204 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
10206 if (p1
[i
] != p2
[i
])
10212 if (*p1
++ == ' ' && *p1
++ == '[')
10215 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
10216 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
10223 /* Display an echo area message M with a specified length of NBYTES
10224 bytes. The string may include null characters. If M is not a
10225 string, clear out any existing message, and let the mini-buffer
10228 This function cancels echoing. */
10231 message3 (Lisp_Object m
)
10233 clear_message (true, true);
10236 /* First flush out any partial line written with print. */
10237 message_log_maybe_newline ();
10240 ptrdiff_t nbytes
= SBYTES (m
);
10241 bool multibyte
= STRING_MULTIBYTE (m
);
10244 SAFE_ALLOCA_STRING (buffer
, m
);
10245 message_dolog (buffer
, nbytes
, true, multibyte
);
10248 if (! inhibit_message
)
10249 message3_nolog (m
);
10252 /* Log the message M to stderr. Log an empty line if M is not a string. */
10255 message_to_stderr (Lisp_Object m
)
10257 if (noninteractive_need_newline
)
10259 noninteractive_need_newline
= false;
10260 fputc ('\n', stderr
);
10264 Lisp_Object coding_system
= Vlocale_coding_system
;
10267 if (!NILP (Vcoding_system_for_write
))
10268 coding_system
= Vcoding_system_for_write
;
10269 if (!NILP (coding_system
))
10270 s
= code_convert_string_norecord (m
, coding_system
, true);
10274 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
10276 if (!cursor_in_echo_area
)
10277 fputc ('\n', stderr
);
10281 /* The non-logging version of message3.
10282 This does not cancel echoing, because it is used for echoing.
10283 Perhaps we need to make a separate function for echoing
10284 and make this cancel echoing. */
10287 message3_nolog (Lisp_Object m
)
10289 struct frame
*sf
= SELECTED_FRAME ();
10291 if (FRAME_INITIAL_P (sf
))
10292 message_to_stderr (m
);
10293 /* Error messages get reported properly by cmd_error, so this must be just an
10294 informative message; if the frame hasn't really been initialized yet, just
10296 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
10298 /* Get the frame containing the mini-buffer
10299 that the selected frame is using. */
10300 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10301 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
10302 struct frame
*f
= XFRAME (frame
);
10304 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
10305 Fmake_frame_visible (frame
);
10307 if (STRINGP (m
) && SCHARS (m
) > 0)
10310 if (minibuffer_auto_raise
)
10311 Fraise_frame (frame
);
10312 /* Assume we are not echoing.
10313 (If we are, echo_now will override this.) */
10314 echo_message_buffer
= Qnil
;
10317 clear_message (true, true);
10319 do_pending_window_change (false);
10320 echo_area_display (true);
10321 do_pending_window_change (false);
10322 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
10323 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
10328 /* Display a null-terminated echo area message M. If M is 0, clear
10329 out any existing message, and let the mini-buffer text show through.
10331 The buffer M must continue to exist until after the echo area gets
10332 cleared or some other message gets displayed there. Do not pass
10333 text that is stored in a Lisp string. Do not pass text in a buffer
10334 that was alloca'd. */
10337 message1 (const char *m
)
10339 message3 (m
? build_unibyte_string (m
) : Qnil
);
10343 /* The non-logging counterpart of message1. */
10346 message1_nolog (const char *m
)
10348 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10351 /* Display a message M which contains a single %s
10352 which gets replaced with STRING. */
10355 message_with_string (const char *m
, Lisp_Object string
, bool log
)
10357 CHECK_STRING (string
);
10360 if (noninteractive
)
10361 need_message
= !!m
;
10362 else if (!INTERACTIVE
)
10363 need_message
= false;
10366 /* The frame whose minibuffer we're going to display the message on.
10367 It may be larger than the selected frame, so we need
10368 to use its buffer, not the selected frame's buffer. */
10369 Lisp_Object mini_window
;
10370 struct frame
*f
, *sf
= SELECTED_FRAME ();
10372 /* Get the frame containing the minibuffer
10373 that the selected frame is using. */
10374 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10375 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10377 /* Error messages get reported properly by cmd_error, so this must be
10378 just an informative message; if the frame hasn't really been
10379 initialized yet, just toss it. */
10380 need_message
= f
->glyphs_initialized_p
;
10385 AUTO_STRING (fmt
, m
);
10386 Lisp_Object msg
= CALLN (Fformat_message
, fmt
, string
);
10388 if (noninteractive
)
10389 message_to_stderr (msg
);
10395 message3_nolog (msg
);
10397 /* Print should start at the beginning of the message
10398 buffer next time. */
10399 message_buf_print
= false;
10405 /* Dump an informative message to the minibuf. If M is 0, clear out
10406 any existing message, and let the mini-buffer text show through.
10408 The message must be safe ASCII and the format must not contain ` or
10409 '. If your message and format do not fit into this category,
10410 convert your arguments to Lisp objects and use Fmessage instead. */
10412 static void ATTRIBUTE_FORMAT_PRINTF (1, 0)
10413 vmessage (const char *m
, va_list ap
)
10415 if (noninteractive
)
10419 if (noninteractive_need_newline
)
10420 putc ('\n', stderr
);
10421 noninteractive_need_newline
= false;
10422 vfprintf (stderr
, m
, ap
);
10423 if (!cursor_in_echo_area
)
10424 fprintf (stderr
, "\n");
10428 else if (INTERACTIVE
)
10430 /* The frame whose mini-buffer we're going to display the message
10431 on. It may be larger than the selected frame, so we need to
10432 use its buffer, not the selected frame's buffer. */
10433 Lisp_Object mini_window
;
10434 struct frame
*f
, *sf
= SELECTED_FRAME ();
10436 /* Get the frame containing the mini-buffer
10437 that the selected frame is using. */
10438 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10439 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10441 /* Error messages get reported properly by cmd_error, so this must be
10442 just an informative message; if the frame hasn't really been
10443 initialized yet, just toss it. */
10444 if (f
->glyphs_initialized_p
)
10449 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10451 char *message_buf
= SAFE_ALLOCA (maxsize
+ 1);
10453 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10455 message3 (make_string (message_buf
, len
));
10461 /* Print should start at the beginning of the message
10462 buffer next time. */
10463 message_buf_print
= false;
10469 message (const char *m
, ...)
10478 /* Display the current message in the current mini-buffer. This is
10479 only called from error handlers in process.c, and is not time
10483 update_echo_area (void)
10485 if (!NILP (echo_area_buffer
[0]))
10487 Lisp_Object string
;
10488 string
= Fcurrent_message ();
10494 /* Make sure echo area buffers in `echo_buffers' are live.
10495 If they aren't, make new ones. */
10498 ensure_echo_area_buffers (void)
10502 for (i
= 0; i
< 2; ++i
)
10503 if (!BUFFERP (echo_buffer
[i
])
10504 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10507 Lisp_Object old_buffer
;
10510 old_buffer
= echo_buffer
[i
];
10511 echo_buffer
[i
] = Fget_buffer_create
10512 (make_formatted_string (name
, " *Echo Area %d*", i
));
10513 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10514 /* to force word wrap in echo area -
10515 it was decided to postpone this*/
10516 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10518 for (j
= 0; j
< 2; ++j
)
10519 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10520 echo_area_buffer
[j
] = echo_buffer
[i
];
10525 /* Call FN with args A1..A2 with either the current or last displayed
10526 echo_area_buffer as current buffer.
10528 WHICH zero means use the current message buffer
10529 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10530 from echo_buffer[] and clear it.
10532 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10533 suitable buffer from echo_buffer[] and clear it.
10535 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10536 that the current message becomes the last displayed one, make
10537 choose a suitable buffer for echo_area_buffer[0], and clear it.
10539 Value is what FN returns. */
10542 with_echo_area_buffer (struct window
*w
, int which
,
10543 bool (*fn
) (ptrdiff_t, Lisp_Object
),
10544 ptrdiff_t a1
, Lisp_Object a2
)
10546 Lisp_Object buffer
;
10547 bool this_one
, the_other
, clear_buffer_p
, rc
;
10548 ptrdiff_t count
= SPECPDL_INDEX ();
10550 /* If buffers aren't live, make new ones. */
10551 ensure_echo_area_buffers ();
10553 clear_buffer_p
= false;
10556 this_one
= false, the_other
= true;
10557 else if (which
> 0)
10558 this_one
= true, the_other
= false;
10561 this_one
= false, the_other
= true;
10562 clear_buffer_p
= true;
10564 /* We need a fresh one in case the current echo buffer equals
10565 the one containing the last displayed echo area message. */
10566 if (!NILP (echo_area_buffer
[this_one
])
10567 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10568 echo_area_buffer
[this_one
] = Qnil
;
10571 /* Choose a suitable buffer from echo_buffer[] is we don't
10573 if (NILP (echo_area_buffer
[this_one
]))
10575 echo_area_buffer
[this_one
]
10576 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10577 ? echo_buffer
[the_other
]
10578 : echo_buffer
[this_one
]);
10579 clear_buffer_p
= true;
10582 buffer
= echo_area_buffer
[this_one
];
10584 /* Don't get confused by reusing the buffer used for echoing
10585 for a different purpose. */
10586 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10589 record_unwind_protect (unwind_with_echo_area_buffer
,
10590 with_echo_area_buffer_unwind_data (w
));
10592 /* Make the echo area buffer current. Note that for display
10593 purposes, it is not necessary that the displayed window's buffer
10594 == current_buffer, except for text property lookup. So, let's
10595 only set that buffer temporarily here without doing a full
10596 Fset_window_buffer. We must also change w->pointm, though,
10597 because otherwise an assertions in unshow_buffer fails, and Emacs
10599 set_buffer_internal_1 (XBUFFER (buffer
));
10602 wset_buffer (w
, buffer
);
10603 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10604 set_marker_both (w
->old_pointm
, buffer
, BEG
, BEG_BYTE
);
10607 bset_undo_list (current_buffer
, Qt
);
10608 bset_read_only (current_buffer
, Qnil
);
10609 specbind (Qinhibit_read_only
, Qt
);
10610 specbind (Qinhibit_modification_hooks
, Qt
);
10612 if (clear_buffer_p
&& Z
> BEG
)
10613 del_range (BEG
, Z
);
10615 eassert (BEGV
>= BEG
);
10616 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10620 eassert (BEGV
>= BEG
);
10621 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10623 unbind_to (count
, Qnil
);
10628 /* Save state that should be preserved around the call to the function
10629 FN called in with_echo_area_buffer. */
10632 with_echo_area_buffer_unwind_data (struct window
*w
)
10635 Lisp_Object vector
, tmp
;
10637 /* Reduce consing by keeping one vector in
10638 Vwith_echo_area_save_vector. */
10639 vector
= Vwith_echo_area_save_vector
;
10640 Vwith_echo_area_save_vector
= Qnil
;
10643 vector
= Fmake_vector (make_number (11), Qnil
);
10645 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10646 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10647 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10651 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10652 ASET (vector
, i
, w
->contents
); ++i
;
10653 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10654 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10655 ASET (vector
, i
, make_number (marker_position (w
->old_pointm
))); ++i
;
10656 ASET (vector
, i
, make_number (marker_byte_position (w
->old_pointm
))); ++i
;
10657 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10658 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10663 for (; i
< end
; ++i
)
10664 ASET (vector
, i
, Qnil
);
10667 eassert (i
== ASIZE (vector
));
10672 /* Restore global state from VECTOR which was created by
10673 with_echo_area_buffer_unwind_data. */
10676 unwind_with_echo_area_buffer (Lisp_Object vector
)
10678 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10679 Vdeactivate_mark
= AREF (vector
, 1);
10680 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10682 if (WINDOWP (AREF (vector
, 3)))
10685 Lisp_Object buffer
;
10687 w
= XWINDOW (AREF (vector
, 3));
10688 buffer
= AREF (vector
, 4);
10690 wset_buffer (w
, buffer
);
10691 set_marker_both (w
->pointm
, buffer
,
10692 XFASTINT (AREF (vector
, 5)),
10693 XFASTINT (AREF (vector
, 6)));
10694 set_marker_both (w
->old_pointm
, buffer
,
10695 XFASTINT (AREF (vector
, 7)),
10696 XFASTINT (AREF (vector
, 8)));
10697 set_marker_both (w
->start
, buffer
,
10698 XFASTINT (AREF (vector
, 9)),
10699 XFASTINT (AREF (vector
, 10)));
10702 Vwith_echo_area_save_vector
= vector
;
10706 /* Set up the echo area for use by print functions. MULTIBYTE_P
10707 means we will print multibyte. */
10710 setup_echo_area_for_printing (bool multibyte_p
)
10712 /* If we can't find an echo area any more, exit. */
10713 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10714 Fkill_emacs (Qnil
);
10716 ensure_echo_area_buffers ();
10718 if (!message_buf_print
)
10720 /* A message has been output since the last time we printed.
10721 Choose a fresh echo area buffer. */
10722 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10723 echo_area_buffer
[0] = echo_buffer
[1];
10725 echo_area_buffer
[0] = echo_buffer
[0];
10727 /* Switch to that buffer and clear it. */
10728 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10729 bset_truncate_lines (current_buffer
, Qnil
);
10733 ptrdiff_t count
= SPECPDL_INDEX ();
10734 specbind (Qinhibit_read_only
, Qt
);
10735 /* Note that undo recording is always disabled. */
10736 del_range (BEG
, Z
);
10737 unbind_to (count
, Qnil
);
10739 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10741 /* Set up the buffer for the multibyteness we need. */
10743 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10744 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10746 /* Raise the frame containing the echo area. */
10747 if (minibuffer_auto_raise
)
10749 struct frame
*sf
= SELECTED_FRAME ();
10750 Lisp_Object mini_window
;
10751 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10752 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10755 message_log_maybe_newline ();
10756 message_buf_print
= true;
10760 if (NILP (echo_area_buffer
[0]))
10762 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10763 echo_area_buffer
[0] = echo_buffer
[1];
10765 echo_area_buffer
[0] = echo_buffer
[0];
10768 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10770 /* Someone switched buffers between print requests. */
10771 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10772 bset_truncate_lines (current_buffer
, Qnil
);
10778 /* Display an echo area message in window W. Value is true if W's
10779 height is changed. If display_last_displayed_message_p,
10780 display the message that was last displayed, otherwise
10781 display the current message. */
10784 display_echo_area (struct window
*w
)
10786 bool no_message_p
, window_height_changed_p
;
10788 /* Temporarily disable garbage collections while displaying the echo
10789 area. This is done because a GC can print a message itself.
10790 That message would modify the echo area buffer's contents while a
10791 redisplay of the buffer is going on, and seriously confuse
10793 ptrdiff_t count
= inhibit_garbage_collection ();
10795 /* If there is no message, we must call display_echo_area_1
10796 nevertheless because it resizes the window. But we will have to
10797 reset the echo_area_buffer in question to nil at the end because
10798 with_echo_area_buffer will sets it to an empty buffer. */
10799 bool i
= display_last_displayed_message_p
;
10800 /* According to the C99, C11 and C++11 standards, the integral value
10801 of a "bool" is always 0 or 1, so this array access is safe here,
10803 no_message_p
= NILP (echo_area_buffer
[i
]);
10805 window_height_changed_p
10806 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10807 display_echo_area_1
,
10808 (intptr_t) w
, Qnil
);
10811 echo_area_buffer
[i
] = Qnil
;
10813 unbind_to (count
, Qnil
);
10814 return window_height_changed_p
;
10818 /* Helper for display_echo_area. Display the current buffer which
10819 contains the current echo area message in window W, a mini-window,
10820 a pointer to which is passed in A1. A2..A4 are currently not used.
10821 Change the height of W so that all of the message is displayed.
10822 Value is true if height of W was changed. */
10825 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10828 struct window
*w
= (struct window
*) i1
;
10829 Lisp_Object window
;
10830 struct text_pos start
;
10832 /* We are about to enter redisplay without going through
10833 redisplay_internal, so we need to forget these faces by hand
10835 forget_escape_and_glyphless_faces ();
10837 /* Do this before displaying, so that we have a large enough glyph
10838 matrix for the display. If we can't get enough space for the
10839 whole text, display the last N lines. That works by setting w->start. */
10840 bool window_height_changed_p
= resize_mini_window (w
, false);
10842 /* Use the starting position chosen by resize_mini_window. */
10843 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10846 clear_glyph_matrix (w
->desired_matrix
);
10847 XSETWINDOW (window
, w
);
10848 try_window (window
, start
, 0);
10850 return window_height_changed_p
;
10854 /* Resize the echo area window to exactly the size needed for the
10855 currently displayed message, if there is one. If a mini-buffer
10856 is active, don't shrink it. */
10859 resize_echo_area_exactly (void)
10861 if (BUFFERP (echo_area_buffer
[0])
10862 && WINDOWP (echo_area_window
))
10864 struct window
*w
= XWINDOW (echo_area_window
);
10865 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10866 bool resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10867 (intptr_t) w
, resize_exactly
);
10870 windows_or_buffers_changed
= 42;
10871 update_mode_lines
= 30;
10872 redisplay_internal ();
10878 /* Callback function for with_echo_area_buffer, when used from
10879 resize_echo_area_exactly. A1 contains a pointer to the window to
10880 resize, EXACTLY non-nil means resize the mini-window exactly to the
10881 size of the text displayed. A3 and A4 are not used. Value is what
10882 resize_mini_window returns. */
10885 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10888 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10892 /* Resize mini-window W to fit the size of its contents. EXACT_P
10893 means size the window exactly to the size needed. Otherwise, it's
10894 only enlarged until W's buffer is empty.
10896 Set W->start to the right place to begin display. If the whole
10897 contents fit, start at the beginning. Otherwise, start so as
10898 to make the end of the contents appear. This is particularly
10899 important for y-or-n-p, but seems desirable generally.
10901 Value is true if the window height has been changed. */
10904 resize_mini_window (struct window
*w
, bool exact_p
)
10906 struct frame
*f
= XFRAME (w
->frame
);
10907 bool window_height_changed_p
= false;
10909 eassert (MINI_WINDOW_P (w
));
10911 /* By default, start display at the beginning. */
10912 set_marker_both (w
->start
, w
->contents
,
10913 BUF_BEGV (XBUFFER (w
->contents
)),
10914 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10916 /* Don't resize windows while redisplaying a window; it would
10917 confuse redisplay functions when the size of the window they are
10918 displaying changes from under them. Such a resizing can happen,
10919 for instance, when which-func prints a long message while
10920 we are running fontification-functions. We're running these
10921 functions with safe_call which binds inhibit-redisplay to t. */
10922 if (!NILP (Vinhibit_redisplay
))
10925 /* Nil means don't try to resize. */
10926 if (NILP (Vresize_mini_windows
)
10927 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10930 if (!FRAME_MINIBUF_ONLY_P (f
))
10933 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10934 + WINDOW_PIXEL_HEIGHT (w
));
10935 int unit
= FRAME_LINE_HEIGHT (f
);
10936 int height
, max_height
;
10937 struct text_pos start
;
10938 struct buffer
*old_current_buffer
= NULL
;
10940 if (current_buffer
!= XBUFFER (w
->contents
))
10942 old_current_buffer
= current_buffer
;
10943 set_buffer_internal (XBUFFER (w
->contents
));
10946 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10948 /* Compute the max. number of lines specified by the user. */
10949 if (FLOATP (Vmax_mini_window_height
))
10950 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10951 else if (INTEGERP (Vmax_mini_window_height
))
10952 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10954 max_height
= total_height
/ 4;
10956 /* Correct that max. height if it's bogus. */
10957 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10959 /* Find out the height of the text in the window. */
10960 if (it
.line_wrap
== TRUNCATE
)
10965 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10966 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10967 height
= it
.current_y
+ last_height
;
10969 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10970 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10973 /* Compute a suitable window start. */
10974 if (height
> max_height
)
10976 height
= (max_height
/ unit
) * unit
;
10977 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10978 move_it_vertically_backward (&it
, height
- unit
);
10979 start
= it
.current
.pos
;
10982 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10983 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10985 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10987 /* Let it grow only, until we display an empty message, in which
10988 case the window shrinks again. */
10989 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10991 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10993 FRAME_WINDOWS_FROZEN (f
) = true;
10994 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
10995 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10997 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10998 && (exact_p
|| BEGV
== ZV
))
11000 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11002 FRAME_WINDOWS_FROZEN (f
) = false;
11003 shrink_mini_window (w
, true);
11004 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11009 /* Always resize to exact size needed. */
11010 if (height
> WINDOW_PIXEL_HEIGHT (w
))
11012 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11014 FRAME_WINDOWS_FROZEN (f
) = true;
11015 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
11016 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11018 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
11020 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11022 FRAME_WINDOWS_FROZEN (f
) = false;
11023 shrink_mini_window (w
, true);
11027 FRAME_WINDOWS_FROZEN (f
) = true;
11028 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
11031 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11035 if (old_current_buffer
)
11036 set_buffer_internal (old_current_buffer
);
11039 return window_height_changed_p
;
11043 /* Value is the current message, a string, or nil if there is no
11044 current message. */
11047 current_message (void)
11051 if (!BUFFERP (echo_area_buffer
[0]))
11055 with_echo_area_buffer (0, 0, current_message_1
,
11056 (intptr_t) &msg
, Qnil
);
11058 echo_area_buffer
[0] = Qnil
;
11066 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
11069 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
11072 *msg
= make_buffer_string (BEG
, Z
, true);
11079 /* Push the current message on Vmessage_stack for later restoration
11080 by restore_message. Value is true if the current message isn't
11081 empty. This is a relatively infrequent operation, so it's not
11082 worth optimizing. */
11085 push_message (void)
11087 Lisp_Object msg
= current_message ();
11088 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
11089 return STRINGP (msg
);
11093 /* Restore message display from the top of Vmessage_stack. */
11096 restore_message (void)
11098 eassert (CONSP (Vmessage_stack
));
11099 message3_nolog (XCAR (Vmessage_stack
));
11103 /* Handler for unwind-protect calling pop_message. */
11106 pop_message_unwind (void)
11108 /* Pop the top-most entry off Vmessage_stack. */
11109 eassert (CONSP (Vmessage_stack
));
11110 Vmessage_stack
= XCDR (Vmessage_stack
);
11114 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
11115 exits. If the stack is not empty, we have a missing pop_message
11119 check_message_stack (void)
11121 if (!NILP (Vmessage_stack
))
11126 /* Truncate to NCHARS what will be displayed in the echo area the next
11127 time we display it---but don't redisplay it now. */
11130 truncate_echo_area (ptrdiff_t nchars
)
11133 echo_area_buffer
[0] = Qnil
;
11134 else if (!noninteractive
11136 && !NILP (echo_area_buffer
[0]))
11138 struct frame
*sf
= SELECTED_FRAME ();
11139 /* Error messages get reported properly by cmd_error, so this must be
11140 just an informative message; if the frame hasn't really been
11141 initialized yet, just toss it. */
11142 if (sf
->glyphs_initialized_p
)
11143 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
11148 /* Helper function for truncate_echo_area. Truncate the current
11149 message to at most NCHARS characters. */
11152 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
11154 if (BEG
+ nchars
< Z
)
11155 del_range (BEG
+ nchars
, Z
);
11157 echo_area_buffer
[0] = Qnil
;
11161 /* Set the current message to STRING. */
11164 set_message (Lisp_Object string
)
11166 eassert (STRINGP (string
));
11168 message_enable_multibyte
= STRING_MULTIBYTE (string
);
11170 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
11171 message_buf_print
= false;
11172 help_echo_showing_p
= false;
11174 if (STRINGP (Vdebug_on_message
)
11175 && STRINGP (string
)
11176 && fast_string_match (Vdebug_on_message
, string
) >= 0)
11177 call_debugger (list2 (Qerror
, string
));
11181 /* Helper function for set_message. First argument is ignored and second
11182 argument has the same meaning as for set_message.
11183 This function is called with the echo area buffer being current. */
11186 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
11188 eassert (STRINGP (string
));
11190 /* Change multibyteness of the echo buffer appropriately. */
11191 if (message_enable_multibyte
11192 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
11193 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
11195 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
11196 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
11197 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
11199 /* Insert new message at BEG. */
11200 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
11202 /* This function takes care of single/multibyte conversion.
11203 We just have to ensure that the echo area buffer has the right
11204 setting of enable_multibyte_characters. */
11205 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), true);
11211 /* Clear messages. CURRENT_P means clear the current message.
11212 LAST_DISPLAYED_P means clear the message last displayed. */
11215 clear_message (bool current_p
, bool last_displayed_p
)
11219 echo_area_buffer
[0] = Qnil
;
11220 message_cleared_p
= true;
11223 if (last_displayed_p
)
11224 echo_area_buffer
[1] = Qnil
;
11226 message_buf_print
= false;
11229 /* Clear garbaged frames.
11231 This function is used where the old redisplay called
11232 redraw_garbaged_frames which in turn called redraw_frame which in
11233 turn called clear_frame. The call to clear_frame was a source of
11234 flickering. I believe a clear_frame is not necessary. It should
11235 suffice in the new redisplay to invalidate all current matrices,
11236 and ensure a complete redisplay of all windows. */
11239 clear_garbaged_frames (void)
11241 if (frame_garbaged
)
11243 Lisp_Object tail
, frame
;
11245 FOR_EACH_FRAME (tail
, frame
)
11247 struct frame
*f
= XFRAME (frame
);
11249 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
11254 clear_current_matrices (f
);
11255 fset_redisplay (f
);
11256 f
->garbaged
= false;
11257 f
->resized_p
= false;
11261 frame_garbaged
= false;
11266 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P, update
11270 echo_area_display (bool update_frame_p
)
11272 Lisp_Object mini_window
;
11275 bool window_height_changed_p
= false;
11276 struct frame
*sf
= SELECTED_FRAME ();
11278 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11279 w
= XWINDOW (mini_window
);
11280 f
= XFRAME (WINDOW_FRAME (w
));
11282 /* Don't display if frame is invisible or not yet initialized. */
11283 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
11286 #ifdef HAVE_WINDOW_SYSTEM
11287 /* When Emacs starts, selected_frame may be the initial terminal
11288 frame. If we let this through, a message would be displayed on
11290 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
11292 #endif /* HAVE_WINDOW_SYSTEM */
11294 /* Redraw garbaged frames. */
11295 clear_garbaged_frames ();
11297 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
11299 echo_area_window
= mini_window
;
11300 window_height_changed_p
= display_echo_area (w
);
11301 w
->must_be_updated_p
= true;
11303 /* Update the display, unless called from redisplay_internal.
11304 Also don't update the screen during redisplay itself. The
11305 update will happen at the end of redisplay, and an update
11306 here could cause confusion. */
11307 if (update_frame_p
&& !redisplaying_p
)
11311 /* If the display update has been interrupted by pending
11312 input, update mode lines in the frame. Due to the
11313 pending input, it might have been that redisplay hasn't
11314 been called, so that mode lines above the echo area are
11315 garbaged. This looks odd, so we prevent it here. */
11316 if (!display_completed
)
11317 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11319 if (window_height_changed_p
11320 /* Don't do this if Emacs is shutting down. Redisplay
11321 needs to run hooks. */
11322 && !NILP (Vrun_hooks
))
11324 /* Must update other windows. Likewise as in other
11325 cases, don't let this update be interrupted by
11327 ptrdiff_t count
= SPECPDL_INDEX ();
11328 specbind (Qredisplay_dont_pause
, Qt
);
11329 fset_redisplay (f
);
11330 redisplay_internal ();
11331 unbind_to (count
, Qnil
);
11333 else if (FRAME_WINDOW_P (f
) && n
== 0)
11335 /* Window configuration is the same as before.
11336 Can do with a display update of the echo area,
11337 unless we displayed some mode lines. */
11338 update_single_window (w
);
11342 update_frame (f
, true, true);
11344 /* If cursor is in the echo area, make sure that the next
11345 redisplay displays the minibuffer, so that the cursor will
11346 be replaced with what the minibuffer wants. */
11347 if (cursor_in_echo_area
)
11348 wset_redisplay (XWINDOW (mini_window
));
11351 else if (!EQ (mini_window
, selected_window
))
11352 wset_redisplay (XWINDOW (mini_window
));
11354 /* Last displayed message is now the current message. */
11355 echo_area_buffer
[1] = echo_area_buffer
[0];
11356 /* Inform read_char that we're not echoing. */
11357 echo_message_buffer
= Qnil
;
11359 /* Prevent redisplay optimization in redisplay_internal by resetting
11360 this_line_start_pos. This is done because the mini-buffer now
11361 displays the message instead of its buffer text. */
11362 if (EQ (mini_window
, selected_window
))
11363 CHARPOS (this_line_start_pos
) = 0;
11365 if (window_height_changed_p
)
11367 fset_redisplay (f
);
11369 /* If window configuration was changed, frames may have been
11370 marked garbaged. Clear them or we will experience
11371 surprises wrt scrolling.
11372 FIXME: How/why/when? */
11373 clear_garbaged_frames ();
11377 /* True if W's buffer was changed but not saved. */
11380 window_buffer_changed (struct window
*w
)
11382 struct buffer
*b
= XBUFFER (w
->contents
);
11384 eassert (BUFFER_LIVE_P (b
));
11386 return (BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
;
11389 /* True if W has %c in its mode line and mode line should be updated. */
11392 mode_line_update_needed (struct window
*w
)
11394 return (w
->column_number_displayed
!= -1
11395 && !(PT
== w
->last_point
&& !window_outdated (w
))
11396 && (w
->column_number_displayed
!= current_column ()));
11399 /* True if window start of W is frozen and may not be changed during
11403 window_frozen_p (struct window
*w
)
11405 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11407 Lisp_Object window
;
11409 XSETWINDOW (window
, w
);
11410 if (MINI_WINDOW_P (w
))
11412 else if (EQ (window
, selected_window
))
11414 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11415 && EQ (window
, Vminibuf_scroll_window
))
11416 /* This special window can't be frozen too. */
11424 /***********************************************************************
11425 Mode Lines and Frame Titles
11426 ***********************************************************************/
11428 /* A buffer for constructing non-propertized mode-line strings and
11429 frame titles in it; allocated from the heap in init_xdisp and
11430 resized as needed in store_mode_line_noprop_char. */
11432 static char *mode_line_noprop_buf
;
11434 /* The buffer's end, and a current output position in it. */
11436 static char *mode_line_noprop_buf_end
;
11437 static char *mode_line_noprop_ptr
;
11439 #define MODE_LINE_NOPROP_LEN(start) \
11440 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11443 MODE_LINE_DISPLAY
= 0,
11447 } mode_line_target
;
11449 /* Alist that caches the results of :propertize.
11450 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11451 static Lisp_Object mode_line_proptrans_alist
;
11453 /* List of strings making up the mode-line. */
11454 static Lisp_Object mode_line_string_list
;
11456 /* Base face property when building propertized mode line string. */
11457 static Lisp_Object mode_line_string_face
;
11458 static Lisp_Object mode_line_string_face_prop
;
11461 /* Unwind data for mode line strings */
11463 static Lisp_Object Vmode_line_unwind_vector
;
11466 format_mode_line_unwind_data (struct frame
*target_frame
,
11467 struct buffer
*obuf
,
11469 bool save_proptrans
)
11471 Lisp_Object vector
, tmp
;
11473 /* Reduce consing by keeping one vector in
11474 Vwith_echo_area_save_vector. */
11475 vector
= Vmode_line_unwind_vector
;
11476 Vmode_line_unwind_vector
= Qnil
;
11479 vector
= Fmake_vector (make_number (10), Qnil
);
11481 ASET (vector
, 0, make_number (mode_line_target
));
11482 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11483 ASET (vector
, 2, mode_line_string_list
);
11484 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11485 ASET (vector
, 4, mode_line_string_face
);
11486 ASET (vector
, 5, mode_line_string_face_prop
);
11489 XSETBUFFER (tmp
, obuf
);
11492 ASET (vector
, 6, tmp
);
11493 ASET (vector
, 7, owin
);
11496 /* Similarly to `with-selected-window', if the operation selects
11497 a window on another frame, we must restore that frame's
11498 selected window, and (for a tty) the top-frame. */
11499 ASET (vector
, 8, target_frame
->selected_window
);
11500 if (FRAME_TERMCAP_P (target_frame
))
11501 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11508 unwind_format_mode_line (Lisp_Object vector
)
11510 Lisp_Object old_window
= AREF (vector
, 7);
11511 Lisp_Object target_frame_window
= AREF (vector
, 8);
11512 Lisp_Object old_top_frame
= AREF (vector
, 9);
11514 mode_line_target
= XINT (AREF (vector
, 0));
11515 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11516 mode_line_string_list
= AREF (vector
, 2);
11517 if (! EQ (AREF (vector
, 3), Qt
))
11518 mode_line_proptrans_alist
= AREF (vector
, 3);
11519 mode_line_string_face
= AREF (vector
, 4);
11520 mode_line_string_face_prop
= AREF (vector
, 5);
11522 /* Select window before buffer, since it may change the buffer. */
11523 if (!NILP (old_window
))
11525 /* If the operation that we are unwinding had selected a window
11526 on a different frame, reset its frame-selected-window. For a
11527 text terminal, reset its top-frame if necessary. */
11528 if (!NILP (target_frame_window
))
11531 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11533 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11534 Fselect_window (target_frame_window
, Qt
);
11536 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11537 Fselect_frame (old_top_frame
, Qt
);
11540 Fselect_window (old_window
, Qt
);
11543 if (!NILP (AREF (vector
, 6)))
11545 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11546 ASET (vector
, 6, Qnil
);
11549 Vmode_line_unwind_vector
= vector
;
11553 /* Store a single character C for the frame title in mode_line_noprop_buf.
11554 Re-allocate mode_line_noprop_buf if necessary. */
11557 store_mode_line_noprop_char (char c
)
11559 /* If output position has reached the end of the allocated buffer,
11560 increase the buffer's size. */
11561 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11563 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11564 ptrdiff_t size
= len
;
11565 mode_line_noprop_buf
=
11566 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11567 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11568 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11571 *mode_line_noprop_ptr
++ = c
;
11575 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11576 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11577 characters that yield more columns than PRECISION; PRECISION <= 0
11578 means copy the whole string. Pad with spaces until FIELD_WIDTH
11579 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11580 pad. Called from display_mode_element when it is used to build a
11584 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11586 const unsigned char *str
= (const unsigned char *) string
;
11588 ptrdiff_t dummy
, nbytes
;
11590 /* Copy at most PRECISION chars from STR. */
11591 nbytes
= strlen (string
);
11592 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11594 store_mode_line_noprop_char (*str
++);
11596 /* Fill up with spaces until FIELD_WIDTH reached. */
11597 while (field_width
> 0
11598 && n
< field_width
)
11600 store_mode_line_noprop_char (' ');
11607 /***********************************************************************
11609 ***********************************************************************/
11611 #ifdef HAVE_WINDOW_SYSTEM
11613 /* Set the title of FRAME, if it has changed. The title format is
11614 Vicon_title_format if FRAME is iconified, otherwise it is
11615 frame_title_format. */
11618 x_consider_frame_title (Lisp_Object frame
)
11620 struct frame
*f
= XFRAME (frame
);
11622 if ((FRAME_WINDOW_P (f
)
11623 || FRAME_MINIBUF_ONLY_P (f
)
11624 || f
->explicit_name
)
11625 && NILP (Fframe_parameter (frame
, Qtooltip
)))
11627 /* Do we have more than one visible frame on this X display? */
11628 Lisp_Object tail
, other_frame
, fmt
;
11629 ptrdiff_t title_start
;
11633 ptrdiff_t count
= SPECPDL_INDEX ();
11635 FOR_EACH_FRAME (tail
, other_frame
)
11637 struct frame
*tf
= XFRAME (other_frame
);
11640 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11641 && !FRAME_MINIBUF_ONLY_P (tf
)
11642 && !EQ (other_frame
, tip_frame
)
11643 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11647 /* Set global variable indicating that multiple frames exist. */
11648 multiple_frames
= CONSP (tail
);
11650 /* Switch to the buffer of selected window of the frame. Set up
11651 mode_line_target so that display_mode_element will output into
11652 mode_line_noprop_buf; then display the title. */
11653 record_unwind_protect (unwind_format_mode_line
,
11654 format_mode_line_unwind_data
11655 (f
, current_buffer
, selected_window
, false));
11657 Fselect_window (f
->selected_window
, Qt
);
11658 set_buffer_internal_1
11659 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11660 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11662 mode_line_target
= MODE_LINE_TITLE
;
11663 title_start
= MODE_LINE_NOPROP_LEN (0);
11664 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11665 NULL
, DEFAULT_FACE_ID
);
11666 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, false);
11667 len
= MODE_LINE_NOPROP_LEN (title_start
);
11668 title
= mode_line_noprop_buf
+ title_start
;
11669 unbind_to (count
, Qnil
);
11671 /* Set the title only if it's changed. This avoids consing in
11672 the common case where it hasn't. (If it turns out that we've
11673 already wasted too much time by walking through the list with
11674 display_mode_element, then we might need to optimize at a
11675 higher level than this.) */
11676 if (! STRINGP (f
->name
)
11677 || SBYTES (f
->name
) != len
11678 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11679 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11683 #endif /* not HAVE_WINDOW_SYSTEM */
11686 /***********************************************************************
11688 ***********************************************************************/
11690 /* True if we will not redisplay all visible windows. */
11691 #define REDISPLAY_SOME_P() \
11692 ((windows_or_buffers_changed == 0 \
11693 || windows_or_buffers_changed == REDISPLAY_SOME) \
11694 && (update_mode_lines == 0 \
11695 || update_mode_lines == REDISPLAY_SOME))
11697 /* Prepare for redisplay by updating menu-bar item lists when
11698 appropriate. This can call eval. */
11701 prepare_menu_bars (void)
11703 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11704 bool some_windows
= REDISPLAY_SOME_P ();
11705 Lisp_Object tooltip_frame
;
11707 #ifdef HAVE_WINDOW_SYSTEM
11708 tooltip_frame
= tip_frame
;
11710 tooltip_frame
= Qnil
;
11713 if (FUNCTIONP (Vpre_redisplay_function
))
11715 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11716 if (all_windows
&& some_windows
)
11718 Lisp_Object ws
= window_list ();
11719 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11721 Lisp_Object
this = XCAR (ws
);
11722 struct window
*w
= XWINDOW (this);
11724 || XFRAME (w
->frame
)->redisplay
11725 || XBUFFER (w
->contents
)->text
->redisplay
)
11727 windows
= Fcons (this, windows
);
11731 safe__call1 (true, Vpre_redisplay_function
, windows
);
11734 /* Update all frame titles based on their buffer names, etc. We do
11735 this before the menu bars so that the buffer-menu will show the
11736 up-to-date frame titles. */
11737 #ifdef HAVE_WINDOW_SYSTEM
11740 Lisp_Object tail
, frame
;
11742 FOR_EACH_FRAME (tail
, frame
)
11744 struct frame
*f
= XFRAME (frame
);
11745 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11749 && !XBUFFER (w
->contents
)->text
->redisplay
)
11752 if (!EQ (frame
, tooltip_frame
)
11753 && (FRAME_ICONIFIED_P (f
)
11754 || FRAME_VISIBLE_P (f
) == 1
11755 /* Exclude TTY frames that are obscured because they
11756 are not the top frame on their console. This is
11757 because x_consider_frame_title actually switches
11758 to the frame, which for TTY frames means it is
11759 marked as garbaged, and will be completely
11760 redrawn on the next redisplay cycle. This causes
11761 TTY frames to be completely redrawn, when there
11762 are more than one of them, even though nothing
11763 should be changed on display. */
11764 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11765 x_consider_frame_title (frame
);
11768 #endif /* HAVE_WINDOW_SYSTEM */
11770 /* Update the menu bar item lists, if appropriate. This has to be
11771 done before any actual redisplay or generation of display lines. */
11775 Lisp_Object tail
, frame
;
11776 ptrdiff_t count
= SPECPDL_INDEX ();
11777 /* True means that update_menu_bar has run its hooks
11778 so any further calls to update_menu_bar shouldn't do so again. */
11779 bool menu_bar_hooks_run
= false;
11781 record_unwind_save_match_data ();
11783 FOR_EACH_FRAME (tail
, frame
)
11785 struct frame
*f
= XFRAME (frame
);
11786 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11788 /* Ignore tooltip frame. */
11789 if (EQ (frame
, tooltip_frame
))
11795 && !XBUFFER (w
->contents
)->text
->redisplay
)
11798 /* If a window on this frame changed size, report that to
11799 the user and clear the size-change flag. */
11800 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11802 Lisp_Object functions
;
11804 /* Clear flag first in case we get an error below. */
11805 FRAME_WINDOW_SIZES_CHANGED (f
) = false;
11806 functions
= Vwindow_size_change_functions
;
11808 while (CONSP (functions
))
11810 if (!EQ (XCAR (functions
), Qt
))
11811 call1 (XCAR (functions
), frame
);
11812 functions
= XCDR (functions
);
11816 menu_bar_hooks_run
= update_menu_bar (f
, false, menu_bar_hooks_run
);
11817 #ifdef HAVE_WINDOW_SYSTEM
11818 update_tool_bar (f
, false);
11822 unbind_to (count
, Qnil
);
11826 struct frame
*sf
= SELECTED_FRAME ();
11827 update_menu_bar (sf
, true, false);
11828 #ifdef HAVE_WINDOW_SYSTEM
11829 update_tool_bar (sf
, true);
11835 /* Update the menu bar item list for frame F. This has to be done
11836 before we start to fill in any display lines, because it can call
11839 If SAVE_MATCH_DATA, we must save and restore it here.
11841 If HOOKS_RUN, a previous call to update_menu_bar
11842 already ran the menu bar hooks for this redisplay, so there
11843 is no need to run them again. The return value is the
11844 updated value of this flag, to pass to the next call. */
11847 update_menu_bar (struct frame
*f
, bool save_match_data
, bool hooks_run
)
11849 Lisp_Object window
;
11852 /* If called recursively during a menu update, do nothing. This can
11853 happen when, for instance, an activate-menubar-hook causes a
11855 if (inhibit_menubar_update
)
11858 window
= FRAME_SELECTED_WINDOW (f
);
11859 w
= XWINDOW (window
);
11861 if (FRAME_WINDOW_P (f
)
11863 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11864 || defined (HAVE_NS) || defined (USE_GTK)
11865 FRAME_EXTERNAL_MENU_BAR (f
)
11867 FRAME_MENU_BAR_LINES (f
) > 0
11869 : FRAME_MENU_BAR_LINES (f
) > 0)
11871 /* If the user has switched buffers or windows, we need to
11872 recompute to reflect the new bindings. But we'll
11873 recompute when update_mode_lines is set too; that means
11874 that people can use force-mode-line-update to request
11875 that the menu bar be recomputed. The adverse effect on
11876 the rest of the redisplay algorithm is about the same as
11877 windows_or_buffers_changed anyway. */
11878 if (windows_or_buffers_changed
11879 /* This used to test w->update_mode_line, but we believe
11880 there is no need to recompute the menu in that case. */
11881 || update_mode_lines
11882 || window_buffer_changed (w
))
11884 struct buffer
*prev
= current_buffer
;
11885 ptrdiff_t count
= SPECPDL_INDEX ();
11887 specbind (Qinhibit_menubar_update
, Qt
);
11889 set_buffer_internal_1 (XBUFFER (w
->contents
));
11890 if (save_match_data
)
11891 record_unwind_save_match_data ();
11892 if (NILP (Voverriding_local_map_menu_flag
))
11894 specbind (Qoverriding_terminal_local_map
, Qnil
);
11895 specbind (Qoverriding_local_map
, Qnil
);
11900 /* Run the Lucid hook. */
11901 safe_run_hooks (Qactivate_menubar_hook
);
11903 /* If it has changed current-menubar from previous value,
11904 really recompute the menu-bar from the value. */
11905 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11906 call0 (Qrecompute_lucid_menubar
);
11908 safe_run_hooks (Qmenu_bar_update_hook
);
11913 XSETFRAME (Vmenu_updating_frame
, f
);
11914 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11916 /* Redisplay the menu bar in case we changed it. */
11917 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11918 || defined (HAVE_NS) || defined (USE_GTK)
11919 if (FRAME_WINDOW_P (f
))
11921 #if defined (HAVE_NS)
11922 /* All frames on Mac OS share the same menubar. So only
11923 the selected frame should be allowed to set it. */
11924 if (f
== SELECTED_FRAME ())
11926 set_frame_menubar (f
, false, false);
11929 /* On a terminal screen, the menu bar is an ordinary screen
11930 line, and this makes it get updated. */
11931 w
->update_mode_line
= true;
11932 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11933 /* In the non-toolkit version, the menu bar is an ordinary screen
11934 line, and this makes it get updated. */
11935 w
->update_mode_line
= true;
11936 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11938 unbind_to (count
, Qnil
);
11939 set_buffer_internal_1 (prev
);
11946 /***********************************************************************
11948 ***********************************************************************/
11950 #ifdef HAVE_WINDOW_SYSTEM
11952 /* Select `frame' temporarily without running all the code in
11954 FIXME: Maybe do_switch_frame should be trimmed down similarly
11955 when `norecord' is set. */
11957 fast_set_selected_frame (Lisp_Object frame
)
11959 if (!EQ (selected_frame
, frame
))
11961 selected_frame
= frame
;
11962 selected_window
= XFRAME (frame
)->selected_window
;
11966 /* Update the tool-bar item list for frame F. This has to be done
11967 before we start to fill in any display lines. Called from
11968 prepare_menu_bars. If SAVE_MATCH_DATA, we must save
11969 and restore it here. */
11972 update_tool_bar (struct frame
*f
, bool save_match_data
)
11974 #if defined (USE_GTK) || defined (HAVE_NS)
11975 bool do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11977 bool do_update
= (WINDOWP (f
->tool_bar_window
)
11978 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0);
11983 Lisp_Object window
;
11986 window
= FRAME_SELECTED_WINDOW (f
);
11987 w
= XWINDOW (window
);
11989 /* If the user has switched buffers or windows, we need to
11990 recompute to reflect the new bindings. But we'll
11991 recompute when update_mode_lines is set too; that means
11992 that people can use force-mode-line-update to request
11993 that the menu bar be recomputed. The adverse effect on
11994 the rest of the redisplay algorithm is about the same as
11995 windows_or_buffers_changed anyway. */
11996 if (windows_or_buffers_changed
11997 || w
->update_mode_line
11998 || update_mode_lines
11999 || window_buffer_changed (w
))
12001 struct buffer
*prev
= current_buffer
;
12002 ptrdiff_t count
= SPECPDL_INDEX ();
12003 Lisp_Object frame
, new_tool_bar
;
12004 int new_n_tool_bar
;
12006 /* Set current_buffer to the buffer of the selected
12007 window of the frame, so that we get the right local
12009 set_buffer_internal_1 (XBUFFER (w
->contents
));
12011 /* Save match data, if we must. */
12012 if (save_match_data
)
12013 record_unwind_save_match_data ();
12015 /* Make sure that we don't accidentally use bogus keymaps. */
12016 if (NILP (Voverriding_local_map_menu_flag
))
12018 specbind (Qoverriding_terminal_local_map
, Qnil
);
12019 specbind (Qoverriding_local_map
, Qnil
);
12022 /* We must temporarily set the selected frame to this frame
12023 before calling tool_bar_items, because the calculation of
12024 the tool-bar keymap uses the selected frame (see
12025 `tool-bar-make-keymap' in tool-bar.el). */
12026 eassert (EQ (selected_window
,
12027 /* Since we only explicitly preserve selected_frame,
12028 check that selected_window would be redundant. */
12029 XFRAME (selected_frame
)->selected_window
));
12030 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
12031 XSETFRAME (frame
, f
);
12032 fast_set_selected_frame (frame
);
12034 /* Build desired tool-bar items from keymaps. */
12036 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
12039 /* Redisplay the tool-bar if we changed it. */
12040 if (new_n_tool_bar
!= f
->n_tool_bar_items
12041 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
12043 /* Redisplay that happens asynchronously due to an expose event
12044 may access f->tool_bar_items. Make sure we update both
12045 variables within BLOCK_INPUT so no such event interrupts. */
12047 fset_tool_bar_items (f
, new_tool_bar
);
12048 f
->n_tool_bar_items
= new_n_tool_bar
;
12049 w
->update_mode_line
= true;
12053 unbind_to (count
, Qnil
);
12054 set_buffer_internal_1 (prev
);
12059 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12061 /* Set F->desired_tool_bar_string to a Lisp string representing frame
12062 F's desired tool-bar contents. F->tool_bar_items must have
12063 been set up previously by calling prepare_menu_bars. */
12066 build_desired_tool_bar_string (struct frame
*f
)
12068 int i
, size
, size_needed
;
12069 Lisp_Object image
, plist
;
12071 image
= plist
= Qnil
;
12073 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
12074 Otherwise, make a new string. */
12076 /* The size of the string we might be able to reuse. */
12077 size
= (STRINGP (f
->desired_tool_bar_string
)
12078 ? SCHARS (f
->desired_tool_bar_string
)
12081 /* We need one space in the string for each image. */
12082 size_needed
= f
->n_tool_bar_items
;
12084 /* Reuse f->desired_tool_bar_string, if possible. */
12085 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
12086 fset_desired_tool_bar_string
12087 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
12090 AUTO_LIST4 (props
, Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
12091 Fremove_text_properties (make_number (0), make_number (size
),
12092 props
, f
->desired_tool_bar_string
);
12095 /* Put a `display' property on the string for the images to display,
12096 put a `menu_item' property on tool-bar items with a value that
12097 is the index of the item in F's tool-bar item vector. */
12098 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
12100 #define PROP(IDX) \
12101 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
12103 bool enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
12104 bool selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
12105 int hmargin
, vmargin
, relief
, idx
, end
;
12107 /* If image is a vector, choose the image according to the
12109 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
12110 if (VECTORP (image
))
12114 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
12115 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
12118 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
12119 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
12121 eassert (ASIZE (image
) >= idx
);
12122 image
= AREF (image
, idx
);
12127 /* Ignore invalid image specifications. */
12128 if (!valid_image_p (image
))
12131 /* Display the tool-bar button pressed, or depressed. */
12132 plist
= Fcopy_sequence (XCDR (image
));
12134 /* Compute margin and relief to draw. */
12135 relief
= (tool_bar_button_relief
>= 0
12136 ? tool_bar_button_relief
12137 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
12138 hmargin
= vmargin
= relief
;
12140 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
12141 INT_MAX
- max (hmargin
, vmargin
)))
12143 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
12144 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
12146 else if (CONSP (Vtool_bar_button_margin
))
12148 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
12149 INT_MAX
- hmargin
))
12150 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
12152 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
12153 INT_MAX
- vmargin
))
12154 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
12157 if (auto_raise_tool_bar_buttons_p
)
12159 /* Add a `:relief' property to the image spec if the item is
12163 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
12170 /* If image is selected, display it pressed, i.e. with a
12171 negative relief. If it's not selected, display it with a
12173 plist
= Fplist_put (plist
, QCrelief
,
12175 ? make_number (-relief
)
12176 : make_number (relief
)));
12181 /* Put a margin around the image. */
12182 if (hmargin
|| vmargin
)
12184 if (hmargin
== vmargin
)
12185 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
12187 plist
= Fplist_put (plist
, QCmargin
,
12188 Fcons (make_number (hmargin
),
12189 make_number (vmargin
)));
12192 /* If button is not enabled, and we don't have special images
12193 for the disabled state, make the image appear disabled by
12194 applying an appropriate algorithm to it. */
12195 if (!enabled_p
&& idx
< 0)
12196 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
12198 /* Put a `display' text property on the string for the image to
12199 display. Put a `menu-item' property on the string that gives
12200 the start of this item's properties in the tool-bar items
12202 image
= Fcons (Qimage
, plist
);
12203 AUTO_LIST4 (props
, Qdisplay
, image
, Qmenu_item
,
12204 make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
12206 /* Let the last image hide all remaining spaces in the tool bar
12207 string. The string can be longer than needed when we reuse a
12208 previous string. */
12209 if (i
+ 1 == f
->n_tool_bar_items
)
12210 end
= SCHARS (f
->desired_tool_bar_string
);
12213 Fadd_text_properties (make_number (i
), make_number (end
),
12214 props
, f
->desired_tool_bar_string
);
12220 /* Display one line of the tool-bar of frame IT->f.
12222 HEIGHT specifies the desired height of the tool-bar line.
12223 If the actual height of the glyph row is less than HEIGHT, the
12224 row's height is increased to HEIGHT, and the icons are centered
12225 vertically in the new height.
12227 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
12228 count a final empty row in case the tool-bar width exactly matches
12233 display_tool_bar_line (struct it
*it
, int height
)
12235 struct glyph_row
*row
= it
->glyph_row
;
12236 int max_x
= it
->last_visible_x
;
12237 struct glyph
*last
;
12239 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
12240 clear_glyph_row (row
);
12241 row
->enabled_p
= true;
12242 row
->y
= it
->current_y
;
12244 /* Note that this isn't made use of if the face hasn't a box,
12245 so there's no need to check the face here. */
12246 it
->start_of_box_run_p
= true;
12248 while (it
->current_x
< max_x
)
12250 int x
, n_glyphs_before
, i
, nglyphs
;
12251 struct it it_before
;
12253 /* Get the next display element. */
12254 if (!get_next_display_element (it
))
12256 /* Don't count empty row if we are counting needed tool-bar lines. */
12257 if (height
< 0 && !it
->hpos
)
12262 /* Produce glyphs. */
12263 n_glyphs_before
= row
->used
[TEXT_AREA
];
12266 PRODUCE_GLYPHS (it
);
12268 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12270 x
= it_before
.current_x
;
12271 while (i
< nglyphs
)
12273 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12275 if (x
+ glyph
->pixel_width
> max_x
)
12277 /* Glyph doesn't fit on line. Backtrack. */
12278 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12280 /* If this is the only glyph on this line, it will never fit on the
12281 tool-bar, so skip it. But ensure there is at least one glyph,
12282 so we don't accidentally disable the tool-bar. */
12283 if (n_glyphs_before
== 0
12284 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
12290 x
+= glyph
->pixel_width
;
12294 /* Stop at line end. */
12295 if (ITERATOR_AT_END_OF_LINE_P (it
))
12298 set_iterator_to_next (it
, true);
12303 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12305 /* Use default face for the border below the tool bar.
12307 FIXME: When auto-resize-tool-bars is grow-only, there is
12308 no additional border below the possibly empty tool-bar lines.
12309 So to make the extra empty lines look "normal", we have to
12310 use the tool-bar face for the border too. */
12311 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12312 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12313 it
->face_id
= DEFAULT_FACE_ID
;
12315 extend_face_to_end_of_line (it
);
12316 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12317 last
->right_box_line_p
= true;
12318 if (last
== row
->glyphs
[TEXT_AREA
])
12319 last
->left_box_line_p
= true;
12321 /* Make line the desired height and center it vertically. */
12322 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12324 /* Don't add more than one line height. */
12325 height
%= FRAME_LINE_HEIGHT (it
->f
);
12326 it
->max_ascent
+= height
/ 2;
12327 it
->max_descent
+= (height
+ 1) / 2;
12330 compute_line_metrics (it
);
12332 /* If line is empty, make it occupy the rest of the tool-bar. */
12333 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12335 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12336 row
->visible_height
= row
->height
;
12337 row
->ascent
= row
->phys_ascent
= 0;
12338 row
->extra_line_spacing
= 0;
12341 row
->full_width_p
= true;
12342 row
->continued_p
= false;
12343 row
->truncated_on_left_p
= false;
12344 row
->truncated_on_right_p
= false;
12346 it
->current_x
= it
->hpos
= 0;
12347 it
->current_y
+= row
->height
;
12353 /* Value is the number of pixels needed to make all tool-bar items of
12354 frame F visible. The actual number of glyph rows needed is
12355 returned in *N_ROWS if non-NULL. */
12357 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12359 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12361 /* tool_bar_height is called from redisplay_tool_bar after building
12362 the desired matrix, so use (unused) mode-line row as temporary row to
12363 avoid destroying the first tool-bar row. */
12364 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12366 /* Initialize an iterator for iteration over
12367 F->desired_tool_bar_string in the tool-bar window of frame F. */
12368 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12369 temp_row
->reversed_p
= false;
12370 it
.first_visible_x
= 0;
12371 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12372 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12373 it
.paragraph_embedding
= L2R
;
12375 while (!ITERATOR_AT_END_P (&it
))
12377 clear_glyph_row (temp_row
);
12378 it
.glyph_row
= temp_row
;
12379 display_tool_bar_line (&it
, -1);
12381 clear_glyph_row (temp_row
);
12383 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12385 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12388 return it
.current_y
;
12390 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12393 #endif /* !USE_GTK && !HAVE_NS */
12395 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12397 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12398 If FRAME is nil or omitted, use the selected frame. Optional argument
12399 PIXELWISE non-nil means return the height of the tool bar in pixels. */)
12400 (Lisp_Object frame
, Lisp_Object pixelwise
)
12404 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12405 struct frame
*f
= decode_any_frame (frame
);
12407 if (WINDOWP (f
->tool_bar_window
)
12408 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12410 update_tool_bar (f
, true);
12411 if (f
->n_tool_bar_items
)
12413 build_desired_tool_bar_string (f
);
12414 height
= tool_bar_height (f
, NULL
, !NILP (pixelwise
));
12419 return make_number (height
);
12423 /* Display the tool-bar of frame F. Value is true if tool-bar's
12424 height should be changed. */
12426 redisplay_tool_bar (struct frame
*f
)
12428 f
->tool_bar_redisplayed
= true;
12429 #if defined (USE_GTK) || defined (HAVE_NS)
12431 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12432 update_frame_tool_bar (f
);
12435 #else /* !USE_GTK && !HAVE_NS */
12439 struct glyph_row
*row
;
12441 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12442 do anything. This means you must start with tool-bar-lines
12443 non-zero to get the auto-sizing effect. Or in other words, you
12444 can turn off tool-bars by specifying tool-bar-lines zero. */
12445 if (!WINDOWP (f
->tool_bar_window
)
12446 || (w
= XWINDOW (f
->tool_bar_window
),
12447 WINDOW_TOTAL_LINES (w
) == 0))
12450 /* Set up an iterator for the tool-bar window. */
12451 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12452 it
.first_visible_x
= 0;
12453 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12454 row
= it
.glyph_row
;
12455 row
->reversed_p
= false;
12457 /* Build a string that represents the contents of the tool-bar. */
12458 build_desired_tool_bar_string (f
);
12459 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12460 /* FIXME: This should be controlled by a user option. But it
12461 doesn't make sense to have an R2L tool bar if the menu bar cannot
12462 be drawn also R2L, and making the menu bar R2L is tricky due
12463 toolkit-specific code that implements it. If an R2L tool bar is
12464 ever supported, display_tool_bar_line should also be augmented to
12465 call unproduce_glyphs like display_line and display_string
12467 it
.paragraph_embedding
= L2R
;
12469 if (f
->n_tool_bar_rows
== 0)
12471 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, true);
12473 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12475 x_change_tool_bar_height (f
, new_height
);
12476 frame_default_tool_bar_height
= new_height
;
12477 /* Always do that now. */
12478 clear_glyph_matrix (w
->desired_matrix
);
12479 f
->fonts_changed
= true;
12484 /* Display as many lines as needed to display all tool-bar items. */
12486 if (f
->n_tool_bar_rows
> 0)
12488 int border
, rows
, height
, extra
;
12490 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12491 border
= XINT (Vtool_bar_border
);
12492 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12493 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12494 else if (EQ (Vtool_bar_border
, Qborder_width
))
12495 border
= f
->border_width
;
12501 rows
= f
->n_tool_bar_rows
;
12502 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12503 extra
= it
.last_visible_y
- border
- height
* rows
;
12505 while (it
.current_y
< it
.last_visible_y
)
12508 if (extra
> 0 && rows
-- > 0)
12510 h
= (extra
+ rows
- 1) / rows
;
12513 display_tool_bar_line (&it
, height
+ h
);
12518 while (it
.current_y
< it
.last_visible_y
)
12519 display_tool_bar_line (&it
, 0);
12522 /* It doesn't make much sense to try scrolling in the tool-bar
12523 window, so don't do it. */
12524 w
->desired_matrix
->no_scrolling_p
= true;
12525 w
->must_be_updated_p
= true;
12527 if (!NILP (Vauto_resize_tool_bars
))
12529 bool change_height_p
= true;
12531 /* If we couldn't display everything, change the tool-bar's
12532 height if there is room for more. */
12533 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
12534 change_height_p
= true;
12536 /* We subtract 1 because display_tool_bar_line advances the
12537 glyph_row pointer before returning to its caller. We want to
12538 examine the last glyph row produced by
12539 display_tool_bar_line. */
12540 row
= it
.glyph_row
- 1;
12542 /* If there are blank lines at the end, except for a partially
12543 visible blank line at the end that is smaller than
12544 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12545 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12546 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12547 change_height_p
= true;
12549 /* If row displays tool-bar items, but is partially visible,
12550 change the tool-bar's height. */
12551 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12552 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
12553 change_height_p
= true;
12555 /* Resize windows as needed by changing the `tool-bar-lines'
12556 frame parameter. */
12557 if (change_height_p
)
12560 int new_height
= tool_bar_height (f
, &nrows
, true);
12562 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12563 && !f
->minimize_tool_bar_window_p
)
12564 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12565 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12566 f
->minimize_tool_bar_window_p
= false;
12568 if (change_height_p
)
12570 x_change_tool_bar_height (f
, new_height
);
12571 frame_default_tool_bar_height
= new_height
;
12572 clear_glyph_matrix (w
->desired_matrix
);
12573 f
->n_tool_bar_rows
= nrows
;
12574 f
->fonts_changed
= true;
12581 f
->minimize_tool_bar_window_p
= false;
12584 #endif /* USE_GTK || HAVE_NS */
12587 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12589 /* Get information about the tool-bar item which is displayed in GLYPH
12590 on frame F. Return in *PROP_IDX the index where tool-bar item
12591 properties start in F->tool_bar_items. Value is false if
12592 GLYPH doesn't display a tool-bar item. */
12595 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12600 /* This function can be called asynchronously, which means we must
12601 exclude any possibility that Fget_text_property signals an
12603 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12604 charpos
= max (0, charpos
);
12606 /* Get the text property `menu-item' at pos. The value of that
12607 property is the start index of this item's properties in
12608 F->tool_bar_items. */
12609 prop
= Fget_text_property (make_number (charpos
),
12610 Qmenu_item
, f
->current_tool_bar_string
);
12611 if (! INTEGERP (prop
))
12613 *prop_idx
= XINT (prop
);
12618 /* Get information about the tool-bar item at position X/Y on frame F.
12619 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12620 the current matrix of the tool-bar window of F, or NULL if not
12621 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12622 item in F->tool_bar_items. Value is
12624 -1 if X/Y is not on a tool-bar item
12625 0 if X/Y is on the same item that was highlighted before.
12629 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12630 int *hpos
, int *vpos
, int *prop_idx
)
12632 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12633 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12636 /* Find the glyph under X/Y. */
12637 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12638 if (*glyph
== NULL
)
12641 /* Get the start of this tool-bar item's properties in
12642 f->tool_bar_items. */
12643 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12646 /* Is mouse on the highlighted item? */
12647 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12648 && *vpos
>= hlinfo
->mouse_face_beg_row
12649 && *vpos
<= hlinfo
->mouse_face_end_row
12650 && (*vpos
> hlinfo
->mouse_face_beg_row
12651 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12652 && (*vpos
< hlinfo
->mouse_face_end_row
12653 || *hpos
< hlinfo
->mouse_face_end_col
12654 || hlinfo
->mouse_face_past_end
))
12662 Handle mouse button event on the tool-bar of frame F, at
12663 frame-relative coordinates X/Y. DOWN_P is true for a button press,
12664 false for button release. MODIFIERS is event modifiers for button
12668 handle_tool_bar_click (struct frame
*f
, int x
, int y
, bool down_p
,
12671 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12672 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12673 int hpos
, vpos
, prop_idx
;
12674 struct glyph
*glyph
;
12675 Lisp_Object enabled_p
;
12678 /* If not on the highlighted tool-bar item, and mouse-highlight is
12679 non-nil, return. This is so we generate the tool-bar button
12680 click only when the mouse button is released on the same item as
12681 where it was pressed. However, when mouse-highlight is disabled,
12682 generate the click when the button is released regardless of the
12683 highlight, since tool-bar items are not highlighted in that
12685 frame_to_window_pixel_xy (w
, &x
, &y
);
12686 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12688 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12691 /* When mouse-highlight is off, generate the click for the item
12692 where the button was pressed, disregarding where it was
12694 if (NILP (Vmouse_highlight
) && !down_p
)
12695 prop_idx
= f
->last_tool_bar_item
;
12697 /* If item is disabled, do nothing. */
12698 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12699 if (NILP (enabled_p
))
12704 /* Show item in pressed state. */
12705 if (!NILP (Vmouse_highlight
))
12706 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12707 f
->last_tool_bar_item
= prop_idx
;
12711 Lisp_Object key
, frame
;
12712 struct input_event event
;
12713 EVENT_INIT (event
);
12715 /* Show item in released state. */
12716 if (!NILP (Vmouse_highlight
))
12717 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12719 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12721 XSETFRAME (frame
, f
);
12722 event
.kind
= TOOL_BAR_EVENT
;
12723 event
.frame_or_window
= frame
;
12725 kbd_buffer_store_event (&event
);
12727 event
.kind
= TOOL_BAR_EVENT
;
12728 event
.frame_or_window
= frame
;
12730 event
.modifiers
= modifiers
;
12731 kbd_buffer_store_event (&event
);
12732 f
->last_tool_bar_item
= -1;
12737 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12738 tool-bar window-relative coordinates X/Y. Called from
12739 note_mouse_highlight. */
12742 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12744 Lisp_Object window
= f
->tool_bar_window
;
12745 struct window
*w
= XWINDOW (window
);
12746 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12747 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12749 struct glyph
*glyph
;
12750 struct glyph_row
*row
;
12752 Lisp_Object enabled_p
;
12754 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12758 /* Function note_mouse_highlight is called with negative X/Y
12759 values when mouse moves outside of the frame. */
12760 if (x
<= 0 || y
<= 0)
12762 clear_mouse_face (hlinfo
);
12766 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12769 /* Not on tool-bar item. */
12770 clear_mouse_face (hlinfo
);
12774 /* On same tool-bar item as before. */
12775 goto set_help_echo
;
12777 clear_mouse_face (hlinfo
);
12779 /* Mouse is down, but on different tool-bar item? */
12780 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12781 && f
== dpyinfo
->last_mouse_frame
);
12783 if (mouse_down_p
&& f
->last_tool_bar_item
!= prop_idx
)
12786 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12788 /* If tool-bar item is not enabled, don't highlight it. */
12789 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12790 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12792 /* Compute the x-position of the glyph. In front and past the
12793 image is a space. We include this in the highlighted area. */
12794 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12795 for (i
= x
= 0; i
< hpos
; ++i
)
12796 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12798 /* Record this as the current active region. */
12799 hlinfo
->mouse_face_beg_col
= hpos
;
12800 hlinfo
->mouse_face_beg_row
= vpos
;
12801 hlinfo
->mouse_face_beg_x
= x
;
12802 hlinfo
->mouse_face_past_end
= false;
12804 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12805 hlinfo
->mouse_face_end_row
= vpos
;
12806 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12807 hlinfo
->mouse_face_window
= window
;
12808 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12810 /* Display it as active. */
12811 show_mouse_face (hlinfo
, draw
);
12816 /* Set help_echo_string to a help string to display for this tool-bar item.
12817 XTread_socket does the rest. */
12818 help_echo_object
= help_echo_window
= Qnil
;
12819 help_echo_pos
= -1;
12820 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12821 if (NILP (help_echo_string
))
12822 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12825 #endif /* !USE_GTK && !HAVE_NS */
12827 #endif /* HAVE_WINDOW_SYSTEM */
12831 /************************************************************************
12832 Horizontal scrolling
12833 ************************************************************************/
12835 /* For all leaf windows in the window tree rooted at WINDOW, set their
12836 hscroll value so that PT is (i) visible in the window, and (ii) so
12837 that it is not within a certain margin at the window's left and
12838 right border. Value is true if any window's hscroll has been
12842 hscroll_window_tree (Lisp_Object window
)
12844 bool hscrolled_p
= false;
12845 bool hscroll_relative_p
= FLOATP (Vhscroll_step
);
12846 int hscroll_step_abs
= 0;
12847 double hscroll_step_rel
= 0;
12849 if (hscroll_relative_p
)
12851 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12852 if (hscroll_step_rel
< 0)
12854 hscroll_relative_p
= false;
12855 hscroll_step_abs
= 0;
12858 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12860 hscroll_step_abs
= XINT (Vhscroll_step
);
12861 if (hscroll_step_abs
< 0)
12862 hscroll_step_abs
= 0;
12865 hscroll_step_abs
= 0;
12867 while (WINDOWP (window
))
12869 struct window
*w
= XWINDOW (window
);
12871 if (WINDOWP (w
->contents
))
12872 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12873 else if (w
->cursor
.vpos
>= 0)
12876 int text_area_width
;
12877 struct glyph_row
*cursor_row
;
12878 struct glyph_row
*bottom_row
;
12880 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->desired_matrix
, w
);
12881 if (w
->cursor
.vpos
< bottom_row
- w
->desired_matrix
->rows
)
12882 cursor_row
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12884 cursor_row
= bottom_row
- 1;
12886 if (!cursor_row
->enabled_p
)
12888 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12889 if (w
->cursor
.vpos
< bottom_row
- w
->current_matrix
->rows
)
12890 cursor_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12892 cursor_row
= bottom_row
- 1;
12894 bool row_r2l_p
= cursor_row
->reversed_p
;
12896 text_area_width
= window_box_width (w
, TEXT_AREA
);
12898 /* Scroll when cursor is inside this scroll margin. */
12899 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12901 /* If the position of this window's point has explicitly
12902 changed, no more suspend auto hscrolling. */
12903 if (NILP (Fequal (Fwindow_point (window
), Fwindow_old_point (window
))))
12904 w
->suspend_auto_hscroll
= false;
12906 /* Remember window point. */
12907 Fset_marker (w
->old_pointm
,
12908 ((w
== XWINDOW (selected_window
))
12909 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
12910 : Fmarker_position (w
->pointm
)),
12913 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12914 && !w
->suspend_auto_hscroll
12915 /* In some pathological cases, like restoring a window
12916 configuration into a frame that is much smaller than
12917 the one from which the configuration was saved, we
12918 get glyph rows whose start and end have zero buffer
12919 positions, which we cannot handle below. Just skip
12921 && CHARPOS (cursor_row
->start
.pos
) >= BUF_BEG (w
->contents
)
12922 /* For left-to-right rows, hscroll when cursor is either
12923 (i) inside the right hscroll margin, or (ii) if it is
12924 inside the left margin and the window is already
12927 && ((w
->hscroll
&& w
->cursor
.x
<= h_margin
)
12928 || (cursor_row
->enabled_p
12929 && cursor_row
->truncated_on_right_p
12930 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12931 /* For right-to-left rows, the logic is similar,
12932 except that rules for scrolling to left and right
12933 are reversed. E.g., if cursor.x <= h_margin, we
12934 need to hscroll "to the right" unconditionally,
12935 and that will scroll the screen to the left so as
12936 to reveal the next portion of the row. */
12938 && ((cursor_row
->enabled_p
12939 /* FIXME: It is confusing to set the
12940 truncated_on_right_p flag when R2L rows
12941 are actually truncated on the left. */
12942 && cursor_row
->truncated_on_right_p
12943 && w
->cursor
.x
<= h_margin
)
12945 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12949 struct buffer
*saved_current_buffer
;
12953 /* Find point in a display of infinite width. */
12954 saved_current_buffer
= current_buffer
;
12955 current_buffer
= XBUFFER (w
->contents
);
12957 if (w
== XWINDOW (selected_window
))
12960 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12962 /* Move iterator to pt starting at cursor_row->start in
12963 a line with infinite width. */
12964 init_to_row_start (&it
, w
, cursor_row
);
12965 it
.last_visible_x
= INFINITY
;
12966 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12967 current_buffer
= saved_current_buffer
;
12969 /* Position cursor in window. */
12970 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12971 hscroll
= max (0, (it
.current_x
12972 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12973 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12974 : (text_area_width
/ 2))))
12975 / FRAME_COLUMN_WIDTH (it
.f
);
12976 else if ((!row_r2l_p
12977 && w
->cursor
.x
>= text_area_width
- h_margin
)
12978 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12980 if (hscroll_relative_p
)
12981 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12984 wanted_x
= text_area_width
12985 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12988 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12992 if (hscroll_relative_p
)
12993 wanted_x
= text_area_width
* hscroll_step_rel
12996 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12999 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
13001 hscroll
= max (hscroll
, w
->min_hscroll
);
13003 /* Don't prevent redisplay optimizations if hscroll
13004 hasn't changed, as it will unnecessarily slow down
13006 if (w
->hscroll
!= hscroll
)
13008 struct buffer
*b
= XBUFFER (w
->contents
);
13009 b
->prevent_redisplay_optimizations_p
= true;
13010 w
->hscroll
= hscroll
;
13011 hscrolled_p
= true;
13019 /* Value is true if hscroll of any leaf window has been changed. */
13020 return hscrolled_p
;
13024 /* Set hscroll so that cursor is visible and not inside horizontal
13025 scroll margins for all windows in the tree rooted at WINDOW. See
13026 also hscroll_window_tree above. Value is true if any window's
13027 hscroll has been changed. If it has, desired matrices on the frame
13028 of WINDOW are cleared. */
13031 hscroll_windows (Lisp_Object window
)
13033 bool hscrolled_p
= hscroll_window_tree (window
);
13035 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
13036 return hscrolled_p
;
13041 /************************************************************************
13043 ************************************************************************/
13045 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined.
13046 This is sometimes handy to have in a debugger session. */
13050 /* First and last unchanged row for try_window_id. */
13052 static int debug_first_unchanged_at_end_vpos
;
13053 static int debug_last_unchanged_at_beg_vpos
;
13055 /* Delta vpos and y. */
13057 static int debug_dvpos
, debug_dy
;
13059 /* Delta in characters and bytes for try_window_id. */
13061 static ptrdiff_t debug_delta
, debug_delta_bytes
;
13063 /* Values of window_end_pos and window_end_vpos at the end of
13066 static ptrdiff_t debug_end_vpos
;
13068 /* Append a string to W->desired_matrix->method. FMT is a printf
13069 format string. If trace_redisplay_p is true also printf the
13070 resulting string to stderr. */
13072 static void debug_method_add (struct window
*, char const *, ...)
13073 ATTRIBUTE_FORMAT_PRINTF (2, 3);
13076 debug_method_add (struct window
*w
, char const *fmt
, ...)
13079 char *method
= w
->desired_matrix
->method
;
13080 int len
= strlen (method
);
13081 int size
= sizeof w
->desired_matrix
->method
;
13082 int remaining
= size
- len
- 1;
13085 if (len
&& remaining
)
13088 --remaining
, ++len
;
13091 va_start (ap
, fmt
);
13092 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
13095 if (trace_redisplay_p
)
13096 fprintf (stderr
, "%p (%s): %s\n",
13098 ((BUFFERP (w
->contents
)
13099 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
13100 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
13105 #endif /* GLYPH_DEBUG */
13108 /* Value is true if all changes in window W, which displays
13109 current_buffer, are in the text between START and END. START is a
13110 buffer position, END is given as a distance from Z. Used in
13111 redisplay_internal for display optimization. */
13114 text_outside_line_unchanged_p (struct window
*w
,
13115 ptrdiff_t start
, ptrdiff_t end
)
13117 bool unchanged_p
= true;
13119 /* If text or overlays have changed, see where. */
13120 if (window_outdated (w
))
13122 /* Gap in the line? */
13123 if (GPT
< start
|| Z
- GPT
< end
)
13124 unchanged_p
= false;
13126 /* Changes start in front of the line, or end after it? */
13128 && (BEG_UNCHANGED
< start
- 1
13129 || END_UNCHANGED
< end
))
13130 unchanged_p
= false;
13132 /* If selective display, can't optimize if changes start at the
13133 beginning of the line. */
13135 && INTEGERP (BVAR (current_buffer
, selective_display
))
13136 && XINT (BVAR (current_buffer
, selective_display
)) > 0
13137 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
13138 unchanged_p
= false;
13140 /* If there are overlays at the start or end of the line, these
13141 may have overlay strings with newlines in them. A change at
13142 START, for instance, may actually concern the display of such
13143 overlay strings as well, and they are displayed on different
13144 lines. So, quickly rule out this case. (For the future, it
13145 might be desirable to implement something more telling than
13146 just BEG/END_UNCHANGED.) */
13149 if (BEG
+ BEG_UNCHANGED
== start
13150 && overlay_touches_p (start
))
13151 unchanged_p
= false;
13152 if (END_UNCHANGED
== end
13153 && overlay_touches_p (Z
- end
))
13154 unchanged_p
= false;
13157 /* Under bidi reordering, adding or deleting a character in the
13158 beginning of a paragraph, before the first strong directional
13159 character, can change the base direction of the paragraph (unless
13160 the buffer specifies a fixed paragraph direction), which will
13161 require to redisplay the whole paragraph. It might be worthwhile
13162 to find the paragraph limits and widen the range of redisplayed
13163 lines to that, but for now just give up this optimization. */
13164 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
13165 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
13166 unchanged_p
= false;
13169 return unchanged_p
;
13173 /* Do a frame update, taking possible shortcuts into account. This is
13174 the main external entry point for redisplay.
13176 If the last redisplay displayed an echo area message and that message
13177 is no longer requested, we clear the echo area or bring back the
13178 mini-buffer if that is in use. */
13183 redisplay_internal ();
13188 overlay_arrow_string_or_property (Lisp_Object var
)
13192 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
13195 return Voverlay_arrow_string
;
13198 /* Return true if there are any overlay-arrows in current_buffer. */
13200 overlay_arrow_in_current_buffer_p (void)
13204 for (vlist
= Voverlay_arrow_variable_list
;
13206 vlist
= XCDR (vlist
))
13208 Lisp_Object var
= XCAR (vlist
);
13211 if (!SYMBOLP (var
))
13213 val
= find_symbol_value (var
);
13215 && current_buffer
== XMARKER (val
)->buffer
)
13222 /* Return true if any overlay_arrows have moved or overlay-arrow-string
13226 overlay_arrows_changed_p (void)
13230 for (vlist
= Voverlay_arrow_variable_list
;
13232 vlist
= XCDR (vlist
))
13234 Lisp_Object var
= XCAR (vlist
);
13235 Lisp_Object val
, pstr
;
13237 if (!SYMBOLP (var
))
13239 val
= find_symbol_value (var
);
13240 if (!MARKERP (val
))
13242 if (! EQ (COERCE_MARKER (val
),
13243 Fget (var
, Qlast_arrow_position
))
13244 || ! (pstr
= overlay_arrow_string_or_property (var
),
13245 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
13251 /* Mark overlay arrows to be updated on next redisplay. */
13254 update_overlay_arrows (int up_to_date
)
13258 for (vlist
= Voverlay_arrow_variable_list
;
13260 vlist
= XCDR (vlist
))
13262 Lisp_Object var
= XCAR (vlist
);
13264 if (!SYMBOLP (var
))
13267 if (up_to_date
> 0)
13269 Lisp_Object val
= find_symbol_value (var
);
13270 Fput (var
, Qlast_arrow_position
,
13271 COERCE_MARKER (val
));
13272 Fput (var
, Qlast_arrow_string
,
13273 overlay_arrow_string_or_property (var
));
13275 else if (up_to_date
< 0
13276 || !NILP (Fget (var
, Qlast_arrow_position
)))
13278 Fput (var
, Qlast_arrow_position
, Qt
);
13279 Fput (var
, Qlast_arrow_string
, Qt
);
13285 /* Return overlay arrow string to display at row.
13286 Return integer (bitmap number) for arrow bitmap in left fringe.
13287 Return nil if no overlay arrow. */
13290 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
13294 for (vlist
= Voverlay_arrow_variable_list
;
13296 vlist
= XCDR (vlist
))
13298 Lisp_Object var
= XCAR (vlist
);
13301 if (!SYMBOLP (var
))
13304 val
= find_symbol_value (var
);
13307 && current_buffer
== XMARKER (val
)->buffer
13308 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13310 if (FRAME_WINDOW_P (it
->f
)
13311 /* FIXME: if ROW->reversed_p is set, this should test
13312 the right fringe, not the left one. */
13313 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13315 #ifdef HAVE_WINDOW_SYSTEM
13316 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13318 int fringe_bitmap
= lookup_fringe_bitmap (val
);
13319 if (fringe_bitmap
!= 0)
13320 return make_number (fringe_bitmap
);
13323 return make_number (-1); /* Use default arrow bitmap. */
13325 return overlay_arrow_string_or_property (var
);
13332 /* Return true if point moved out of or into a composition. Otherwise
13333 return false. PREV_BUF and PREV_PT are the last point buffer and
13334 position. BUF and PT are the current point buffer and position. */
13337 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13338 struct buffer
*buf
, ptrdiff_t pt
)
13340 ptrdiff_t start
, end
;
13342 Lisp_Object buffer
;
13344 XSETBUFFER (buffer
, buf
);
13345 /* Check a composition at the last point if point moved within the
13347 if (prev_buf
== buf
)
13350 /* Point didn't move. */
13353 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13354 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13355 && composition_valid_p (start
, end
, prop
)
13356 && start
< prev_pt
&& end
> prev_pt
)
13357 /* The last point was within the composition. Return true iff
13358 point moved out of the composition. */
13359 return (pt
<= start
|| pt
>= end
);
13362 /* Check a composition at the current point. */
13363 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13364 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13365 && composition_valid_p (start
, end
, prop
)
13366 && start
< pt
&& end
> pt
);
13369 /* Reconsider the clip changes of buffer which is displayed in W. */
13372 reconsider_clip_changes (struct window
*w
)
13374 struct buffer
*b
= XBUFFER (w
->contents
);
13376 if (b
->clip_changed
13377 && w
->window_end_valid
13378 && w
->current_matrix
->buffer
== b
13379 && w
->current_matrix
->zv
== BUF_ZV (b
)
13380 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13381 b
->clip_changed
= false;
13383 /* If display wasn't paused, and W is not a tool bar window, see if
13384 point has been moved into or out of a composition. In that case,
13385 set b->clip_changed to force updating the screen. If
13386 b->clip_changed has already been set, skip this check. */
13387 if (!b
->clip_changed
&& w
->window_end_valid
)
13389 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13390 ? PT
: marker_position (w
->pointm
));
13392 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13393 && check_point_in_composition (w
->current_matrix
->buffer
,
13394 w
->last_point
, b
, pt
))
13395 b
->clip_changed
= true;
13400 propagate_buffer_redisplay (void)
13401 { /* Resetting b->text->redisplay is problematic!
13402 We can't just reset it in the case that some window that displays
13403 it has not been redisplayed; and such a window can stay
13404 unredisplayed for a long time if it's currently invisible.
13405 But we do want to reset it at the end of redisplay otherwise
13406 its displayed windows will keep being redisplayed over and over
13408 So we copy all b->text->redisplay flags up to their windows here,
13409 such that mark_window_display_accurate can safely reset
13410 b->text->redisplay. */
13411 Lisp_Object ws
= window_list ();
13412 for (; CONSP (ws
); ws
= XCDR (ws
))
13414 struct window
*thisw
= XWINDOW (XCAR (ws
));
13415 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13416 if (thisb
->text
->redisplay
)
13417 thisw
->redisplay
= true;
13421 #define STOP_POLLING \
13422 do { if (! polling_stopped_here) stop_polling (); \
13423 polling_stopped_here = true; } while (false)
13425 #define RESUME_POLLING \
13426 do { if (polling_stopped_here) start_polling (); \
13427 polling_stopped_here = false; } while (false)
13430 /* Perhaps in the future avoid recentering windows if it
13431 is not necessary; currently that causes some problems. */
13434 redisplay_internal (void)
13436 struct window
*w
= XWINDOW (selected_window
);
13440 bool must_finish
= false, match_p
;
13441 struct text_pos tlbufpos
, tlendpos
;
13442 int number_of_visible_frames
;
13445 bool polling_stopped_here
= false;
13446 Lisp_Object tail
, frame
;
13448 /* True means redisplay has to consider all windows on all
13449 frames. False, only selected_window is considered. */
13450 bool consider_all_windows_p
;
13452 /* True means redisplay has to redisplay the miniwindow. */
13453 bool update_miniwindow_p
= false;
13455 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13457 /* No redisplay if running in batch mode or frame is not yet fully
13458 initialized, or redisplay is explicitly turned off by setting
13459 Vinhibit_redisplay. */
13460 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13461 || !NILP (Vinhibit_redisplay
))
13464 /* Don't examine these until after testing Vinhibit_redisplay.
13465 When Emacs is shutting down, perhaps because its connection to
13466 X has dropped, we should not look at them at all. */
13467 fr
= XFRAME (w
->frame
);
13468 sf
= SELECTED_FRAME ();
13470 if (!fr
->glyphs_initialized_p
)
13473 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13474 if (popup_activated ())
13478 /* I don't think this happens but let's be paranoid. */
13479 if (redisplaying_p
)
13482 /* Record a function that clears redisplaying_p
13483 when we leave this function. */
13484 count
= SPECPDL_INDEX ();
13485 record_unwind_protect_void (unwind_redisplay
);
13486 redisplaying_p
= true;
13487 specbind (Qinhibit_free_realized_faces
, Qnil
);
13489 /* Record this function, so it appears on the profiler's backtraces. */
13490 record_in_backtrace (Qredisplay_internal
, 0, 0);
13492 FOR_EACH_FRAME (tail
, frame
)
13493 XFRAME (frame
)->already_hscrolled_p
= false;
13496 /* Remember the currently selected window. */
13500 forget_escape_and_glyphless_faces ();
13502 inhibit_free_realized_faces
= false;
13504 /* If face_change, init_iterator will free all realized faces, which
13505 includes the faces referenced from current matrices. So, we
13506 can't reuse current matrices in this case. */
13508 windows_or_buffers_changed
= 47;
13510 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13511 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13513 /* Since frames on a single ASCII terminal share the same
13514 display area, displaying a different frame means redisplay
13515 the whole thing. */
13516 SET_FRAME_GARBAGED (sf
);
13518 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13520 FRAME_TTY (sf
)->previous_frame
= sf
;
13523 /* Set the visible flags for all frames. Do this before checking for
13524 resized or garbaged frames; they want to know if their frames are
13525 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13526 number_of_visible_frames
= 0;
13528 FOR_EACH_FRAME (tail
, frame
)
13530 struct frame
*f
= XFRAME (frame
);
13532 if (FRAME_VISIBLE_P (f
))
13534 ++number_of_visible_frames
;
13535 /* Adjust matrices for visible frames only. */
13536 if (f
->fonts_changed
)
13538 adjust_frame_glyphs (f
);
13539 /* Disable all redisplay optimizations for this frame.
13540 This is because adjust_frame_glyphs resets the
13541 enabled_p flag for all glyph rows of all windows, so
13542 many optimizations will fail anyway, and some might
13543 fail to test that flag and do bogus things as
13545 SET_FRAME_GARBAGED (f
);
13546 f
->fonts_changed
= false;
13548 /* If cursor type has been changed on the frame
13549 other than selected, consider all frames. */
13550 if (f
!= sf
&& f
->cursor_type_changed
)
13551 fset_redisplay (f
);
13553 clear_desired_matrices (f
);
13556 /* Notice any pending interrupt request to change frame size. */
13557 do_pending_window_change (true);
13559 /* do_pending_window_change could change the selected_window due to
13560 frame resizing which makes the selected window too small. */
13561 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13564 /* Clear frames marked as garbaged. */
13565 clear_garbaged_frames ();
13567 /* Build menubar and tool-bar items. */
13568 if (NILP (Vmemory_full
))
13569 prepare_menu_bars ();
13571 reconsider_clip_changes (w
);
13573 /* In most cases selected window displays current buffer. */
13574 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13577 /* Detect case that we need to write or remove a star in the mode line. */
13578 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13579 w
->update_mode_line
= true;
13581 if (mode_line_update_needed (w
))
13582 w
->update_mode_line
= true;
13584 /* If reconsider_clip_changes above decided that the narrowing
13585 in the current buffer changed, make sure all other windows
13586 showing that buffer will be redisplayed. */
13587 if (current_buffer
->clip_changed
)
13588 bset_update_mode_line (current_buffer
);
13591 /* Normally the message* functions will have already displayed and
13592 updated the echo area, but the frame may have been trashed, or
13593 the update may have been preempted, so display the echo area
13594 again here. Checking message_cleared_p captures the case that
13595 the echo area should be cleared. */
13596 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13597 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13598 || (message_cleared_p
13599 && minibuf_level
== 0
13600 /* If the mini-window is currently selected, this means the
13601 echo-area doesn't show through. */
13602 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13604 echo_area_display (false);
13606 /* If echo_area_display resizes the mini-window, the redisplay and
13607 window_sizes_changed flags of the selected frame are set, but
13608 it's too late for the hooks in window-size-change-functions,
13609 which have been examined already in prepare_menu_bars. So in
13610 that case we call the hooks here only for the selected frame. */
13611 if (sf
->redisplay
&& FRAME_WINDOW_SIZES_CHANGED (sf
))
13613 Lisp_Object functions
;
13614 ptrdiff_t count1
= SPECPDL_INDEX ();
13616 record_unwind_save_match_data ();
13618 /* Clear flag first in case we get an error below. */
13619 FRAME_WINDOW_SIZES_CHANGED (sf
) = false;
13620 functions
= Vwindow_size_change_functions
;
13622 while (CONSP (functions
))
13624 if (!EQ (XCAR (functions
), Qt
))
13625 call1 (XCAR (functions
), selected_frame
);
13626 functions
= XCDR (functions
);
13629 unbind_to (count1
, Qnil
);
13632 if (message_cleared_p
)
13633 update_miniwindow_p
= true;
13635 must_finish
= true;
13637 /* If we don't display the current message, don't clear the
13638 message_cleared_p flag, because, if we did, we wouldn't clear
13639 the echo area in the next redisplay which doesn't preserve
13641 if (!display_last_displayed_message_p
)
13642 message_cleared_p
= false;
13644 else if (EQ (selected_window
, minibuf_window
)
13645 && (current_buffer
->clip_changed
|| window_outdated (w
))
13646 && resize_mini_window (w
, false))
13650 Lisp_Object functions
;
13651 ptrdiff_t count1
= SPECPDL_INDEX ();
13653 record_unwind_save_match_data ();
13655 /* Clear flag first in case we get an error below. */
13656 FRAME_WINDOW_SIZES_CHANGED (sf
) = false;
13657 functions
= Vwindow_size_change_functions
;
13659 while (CONSP (functions
))
13661 if (!EQ (XCAR (functions
), Qt
))
13662 call1 (XCAR (functions
), selected_frame
);
13663 functions
= XCDR (functions
);
13666 unbind_to (count1
, Qnil
);
13669 /* Resized active mini-window to fit the size of what it is
13670 showing if its contents might have changed. */
13671 must_finish
= true;
13673 /* If window configuration was changed, frames may have been
13674 marked garbaged. Clear them or we will experience
13675 surprises wrt scrolling. */
13676 clear_garbaged_frames ();
13679 if (windows_or_buffers_changed
&& !update_mode_lines
)
13680 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13681 only the windows's contents needs to be refreshed, or whether the
13682 mode-lines also need a refresh. */
13683 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13684 ? REDISPLAY_SOME
: 32);
13686 /* If specs for an arrow have changed, do thorough redisplay
13687 to ensure we remove any arrow that should no longer exist. */
13688 if (overlay_arrows_changed_p ())
13689 /* Apparently, this is the only case where we update other windows,
13690 without updating other mode-lines. */
13691 windows_or_buffers_changed
= 49;
13693 consider_all_windows_p
= (update_mode_lines
13694 || windows_or_buffers_changed
);
13696 #define AINC(a,i) \
13698 Lisp_Object entry = Fgethash (make_number (i), a, make_number (0)); \
13699 if (INTEGERP (entry)) \
13700 Fputhash (make_number (i), make_number (1 + XINT (entry)), a); \
13703 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13704 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13706 /* Optimize the case that only the line containing the cursor in the
13707 selected window has changed. Variables starting with this_ are
13708 set in display_line and record information about the line
13709 containing the cursor. */
13710 tlbufpos
= this_line_start_pos
;
13711 tlendpos
= this_line_end_pos
;
13712 if (!consider_all_windows_p
13713 && CHARPOS (tlbufpos
) > 0
13714 && !w
->update_mode_line
13715 && !current_buffer
->clip_changed
13716 && !current_buffer
->prevent_redisplay_optimizations_p
13717 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13718 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13719 && !XFRAME (w
->frame
)->cursor_type_changed
13720 && !XFRAME (w
->frame
)->face_change
13721 /* Make sure recorded data applies to current buffer, etc. */
13722 && this_line_buffer
== current_buffer
13725 && !w
->optional_new_start
13726 /* Point must be on the line that we have info recorded about. */
13727 && PT
>= CHARPOS (tlbufpos
)
13728 && PT
<= Z
- CHARPOS (tlendpos
)
13729 /* All text outside that line, including its final newline,
13730 must be unchanged. */
13731 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13732 CHARPOS (tlendpos
)))
13734 if (CHARPOS (tlbufpos
) > BEGV
13735 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13736 && (CHARPOS (tlbufpos
) == ZV
13737 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13738 /* Former continuation line has disappeared by becoming empty. */
13740 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13742 /* We have to handle the case of continuation around a
13743 wide-column character (see the comment in indent.c around
13746 For instance, in the following case:
13748 -------- Insert --------
13749 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13750 J_I_ ==> J_I_ `^^' are cursors.
13754 As we have to redraw the line above, we cannot use this
13758 int line_height_before
= this_line_pixel_height
;
13760 /* Note that start_display will handle the case that the
13761 line starting at tlbufpos is a continuation line. */
13762 start_display (&it
, w
, tlbufpos
);
13764 /* Implementation note: It this still necessary? */
13765 if (it
.current_x
!= this_line_start_x
)
13768 TRACE ((stderr
, "trying display optimization 1\n"));
13769 w
->cursor
.vpos
= -1;
13770 overlay_arrow_seen
= false;
13771 it
.vpos
= this_line_vpos
;
13772 it
.current_y
= this_line_y
;
13773 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13774 display_line (&it
);
13776 /* If line contains point, is not continued,
13777 and ends at same distance from eob as before, we win. */
13778 if (w
->cursor
.vpos
>= 0
13779 /* Line is not continued, otherwise this_line_start_pos
13780 would have been set to 0 in display_line. */
13781 && CHARPOS (this_line_start_pos
)
13782 /* Line ends as before. */
13783 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13784 /* Line has same height as before. Otherwise other lines
13785 would have to be shifted up or down. */
13786 && this_line_pixel_height
== line_height_before
)
13788 /* If this is not the window's last line, we must adjust
13789 the charstarts of the lines below. */
13790 if (it
.current_y
< it
.last_visible_y
)
13792 struct glyph_row
*row
13793 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13794 ptrdiff_t delta
, delta_bytes
;
13796 /* We used to distinguish between two cases here,
13797 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13798 when the line ends in a newline or the end of the
13799 buffer's accessible portion. But both cases did
13800 the same, so they were collapsed. */
13802 - CHARPOS (tlendpos
)
13803 - MATRIX_ROW_START_CHARPOS (row
));
13804 delta_bytes
= (Z_BYTE
13805 - BYTEPOS (tlendpos
)
13806 - MATRIX_ROW_START_BYTEPOS (row
));
13808 increment_matrix_positions (w
->current_matrix
,
13809 this_line_vpos
+ 1,
13810 w
->current_matrix
->nrows
,
13811 delta
, delta_bytes
);
13814 /* If this row displays text now but previously didn't,
13815 or vice versa, w->window_end_vpos may have to be
13817 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13819 if (w
->window_end_vpos
< this_line_vpos
)
13820 w
->window_end_vpos
= this_line_vpos
;
13822 else if (w
->window_end_vpos
== this_line_vpos
13823 && this_line_vpos
> 0)
13824 w
->window_end_vpos
= this_line_vpos
- 1;
13825 w
->window_end_valid
= false;
13827 /* Update hint: No need to try to scroll in update_window. */
13828 w
->desired_matrix
->no_scrolling_p
= true;
13831 *w
->desired_matrix
->method
= 0;
13832 debug_method_add (w
, "optimization 1");
13834 #ifdef HAVE_WINDOW_SYSTEM
13835 update_window_fringes (w
, false);
13842 else if (/* Cursor position hasn't changed. */
13843 PT
== w
->last_point
13844 /* Make sure the cursor was last displayed
13845 in this window. Otherwise we have to reposition it. */
13847 /* PXW: Must be converted to pixels, probably. */
13848 && 0 <= w
->cursor
.vpos
13849 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13853 do_pending_window_change (true);
13854 /* If selected_window changed, redisplay again. */
13855 if (WINDOWP (selected_window
)
13856 && (w
= XWINDOW (selected_window
)) != sw
)
13859 /* We used to always goto end_of_redisplay here, but this
13860 isn't enough if we have a blinking cursor. */
13861 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13862 goto end_of_redisplay
;
13866 /* If highlighting the region, or if the cursor is in the echo area,
13867 then we can't just move the cursor. */
13868 else if (NILP (Vshow_trailing_whitespace
)
13869 && !cursor_in_echo_area
)
13872 struct glyph_row
*row
;
13874 /* Skip from tlbufpos to PT and see where it is. Note that
13875 PT may be in invisible text. If so, we will end at the
13876 next visible position. */
13877 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13878 NULL
, DEFAULT_FACE_ID
);
13879 it
.current_x
= this_line_start_x
;
13880 it
.current_y
= this_line_y
;
13881 it
.vpos
= this_line_vpos
;
13883 /* The call to move_it_to stops in front of PT, but
13884 moves over before-strings. */
13885 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13887 if (it
.vpos
== this_line_vpos
13888 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13891 eassert (this_line_vpos
== it
.vpos
);
13892 eassert (this_line_y
== it
.current_y
);
13893 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13895 *w
->desired_matrix
->method
= 0;
13896 debug_method_add (w
, "optimization 3");
13905 /* Text changed drastically or point moved off of line. */
13906 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13909 CHARPOS (this_line_start_pos
) = 0;
13910 ++clear_face_cache_count
;
13911 #ifdef HAVE_WINDOW_SYSTEM
13912 ++clear_image_cache_count
;
13915 /* Build desired matrices, and update the display. If
13916 consider_all_windows_p, do it for all windows on all frames that
13917 require redisplay, as specified by their 'redisplay' flag.
13918 Otherwise do it for selected_window, only. */
13920 if (consider_all_windows_p
)
13922 FOR_EACH_FRAME (tail
, frame
)
13923 XFRAME (frame
)->updated_p
= false;
13925 propagate_buffer_redisplay ();
13927 FOR_EACH_FRAME (tail
, frame
)
13929 struct frame
*f
= XFRAME (frame
);
13931 /* We don't have to do anything for unselected terminal
13933 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13934 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13938 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13941 /* Only GC scrollbars when we redisplay the whole frame. */
13942 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13943 bool f_redisplay_flag
= f
->redisplay
;
13944 /* Mark all the scroll bars to be removed; we'll redeem
13945 the ones we want when we redisplay their windows. */
13946 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13947 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13949 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13950 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13951 /* Remember that the invisible frames need to be redisplayed next
13952 time they're visible. */
13953 else if (!REDISPLAY_SOME_P ())
13954 f
->redisplay
= true;
13956 /* The X error handler may have deleted that frame. */
13957 if (!FRAME_LIVE_P (f
))
13960 /* Any scroll bars which redisplay_windows should have
13961 nuked should now go away. */
13962 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13963 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13965 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13967 /* If fonts changed on visible frame, display again. */
13968 if (f
->fonts_changed
)
13970 adjust_frame_glyphs (f
);
13971 /* Disable all redisplay optimizations for this
13972 frame. For the reasons, see the comment near
13973 the previous call to adjust_frame_glyphs above. */
13974 SET_FRAME_GARBAGED (f
);
13975 f
->fonts_changed
= false;
13979 /* See if we have to hscroll. */
13980 if (!f
->already_hscrolled_p
)
13982 f
->already_hscrolled_p
= true;
13983 if (hscroll_windows (f
->root_window
))
13987 /* If the frame's redisplay flag was not set before
13988 we went about redisplaying its windows, but it is
13989 set now, that means we employed some redisplay
13990 optimizations inside redisplay_windows, and
13991 bypassed producing some screen lines. But if
13992 f->redisplay is now set, it might mean the old
13993 faces are no longer valid (e.g., if redisplaying
13994 some window called some Lisp which defined a new
13995 face or redefined an existing face), so trying to
13996 use them in update_frame will segfault.
13997 Therefore, we must redisplay this frame. */
13998 if (!f_redisplay_flag
&& f
->redisplay
)
14001 /* Prevent various kinds of signals during display
14002 update. stdio is not robust about handling
14003 signals, which can cause an apparent I/O error. */
14004 if (interrupt_input
)
14005 unrequest_sigio ();
14008 pending
|= update_frame (f
, false, false);
14009 f
->cursor_type_changed
= false;
14010 f
->updated_p
= true;
14015 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
14019 /* Do the mark_window_display_accurate after all windows have
14020 been redisplayed because this call resets flags in buffers
14021 which are needed for proper redisplay. */
14022 FOR_EACH_FRAME (tail
, frame
)
14024 struct frame
*f
= XFRAME (frame
);
14027 f
->redisplay
= false;
14028 mark_window_display_accurate (f
->root_window
, true);
14029 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
14030 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
14035 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
14037 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
14038 struct frame
*mini_frame
;
14040 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
14041 /* Use list_of_error, not Qerror, so that
14042 we catch only errors and don't run the debugger. */
14043 internal_condition_case_1 (redisplay_window_1
, selected_window
,
14045 redisplay_window_error
);
14046 if (update_miniwindow_p
)
14047 internal_condition_case_1 (redisplay_window_1
, mini_window
,
14049 redisplay_window_error
);
14051 /* Compare desired and current matrices, perform output. */
14054 /* If fonts changed, display again. Likewise if redisplay_window_1
14055 above caused some change (e.g., a change in faces) that requires
14056 considering the entire frame again. */
14057 if (sf
->fonts_changed
|| sf
->redisplay
)
14061 /* Set this to force a more thorough redisplay.
14062 Otherwise, we might immediately loop back to the
14063 above "else-if" clause (since all the conditions that
14064 led here might still be true), and we will then
14065 infloop, because the selected-frame's redisplay flag
14066 is not (and cannot be) reset. */
14067 windows_or_buffers_changed
= 50;
14072 /* Prevent freeing of realized faces, since desired matrices are
14073 pending that reference the faces we computed and cached. */
14074 inhibit_free_realized_faces
= true;
14076 /* Prevent various kinds of signals during display update.
14077 stdio is not robust about handling signals,
14078 which can cause an apparent I/O error. */
14079 if (interrupt_input
)
14080 unrequest_sigio ();
14083 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
14085 if (hscroll_windows (selected_window
))
14088 XWINDOW (selected_window
)->must_be_updated_p
= true;
14089 pending
= update_frame (sf
, false, false);
14090 sf
->cursor_type_changed
= false;
14093 /* We may have called echo_area_display at the top of this
14094 function. If the echo area is on another frame, that may
14095 have put text on a frame other than the selected one, so the
14096 above call to update_frame would not have caught it. Catch
14098 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
14099 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
14101 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
14103 XWINDOW (mini_window
)->must_be_updated_p
= true;
14104 pending
|= update_frame (mini_frame
, false, false);
14105 mini_frame
->cursor_type_changed
= false;
14106 if (!pending
&& hscroll_windows (mini_window
))
14111 /* If display was paused because of pending input, make sure we do a
14112 thorough update the next time. */
14115 /* Prevent the optimization at the beginning of
14116 redisplay_internal that tries a single-line update of the
14117 line containing the cursor in the selected window. */
14118 CHARPOS (this_line_start_pos
) = 0;
14120 /* Let the overlay arrow be updated the next time. */
14121 update_overlay_arrows (0);
14123 /* If we pause after scrolling, some rows in the current
14124 matrices of some windows are not valid. */
14125 if (!WINDOW_FULL_WIDTH_P (w
)
14126 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
14127 update_mode_lines
= 36;
14131 if (!consider_all_windows_p
)
14133 /* This has already been done above if
14134 consider_all_windows_p is set. */
14135 if (XBUFFER (w
->contents
)->text
->redisplay
14136 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
14137 /* This can happen if b->text->redisplay was set during
14139 propagate_buffer_redisplay ();
14140 mark_window_display_accurate_1 (w
, true);
14142 /* Say overlay arrows are up to date. */
14143 update_overlay_arrows (1);
14145 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
14146 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
14149 update_mode_lines
= 0;
14150 windows_or_buffers_changed
= 0;
14153 /* Start SIGIO interrupts coming again. Having them off during the
14154 code above makes it less likely one will discard output, but not
14155 impossible, since there might be stuff in the system buffer here.
14156 But it is much hairier to try to do anything about that. */
14157 if (interrupt_input
)
14161 /* If a frame has become visible which was not before, redisplay
14162 again, so that we display it. Expose events for such a frame
14163 (which it gets when becoming visible) don't call the parts of
14164 redisplay constructing glyphs, so simply exposing a frame won't
14165 display anything in this case. So, we have to display these
14166 frames here explicitly. */
14171 FOR_EACH_FRAME (tail
, frame
)
14173 if (XFRAME (frame
)->visible
)
14177 if (new_count
!= number_of_visible_frames
)
14178 windows_or_buffers_changed
= 52;
14181 /* Change frame size now if a change is pending. */
14182 do_pending_window_change (true);
14184 /* If we just did a pending size change, or have additional
14185 visible frames, or selected_window changed, redisplay again. */
14186 if ((windows_or_buffers_changed
&& !pending
)
14187 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
14190 /* Clear the face and image caches.
14192 We used to do this only if consider_all_windows_p. But the cache
14193 needs to be cleared if a timer creates images in the current
14194 buffer (e.g. the test case in Bug#6230). */
14196 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
14198 clear_face_cache (false);
14199 clear_face_cache_count
= 0;
14202 #ifdef HAVE_WINDOW_SYSTEM
14203 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
14205 clear_image_caches (Qnil
);
14206 clear_image_cache_count
= 0;
14208 #endif /* HAVE_WINDOW_SYSTEM */
14212 ns_set_doc_edited ();
14214 if (interrupt_input
&& interrupts_deferred
)
14217 unbind_to (count
, Qnil
);
14222 /* Redisplay, but leave alone any recent echo area message unless
14223 another message has been requested in its place.
14225 This is useful in situations where you need to redisplay but no
14226 user action has occurred, making it inappropriate for the message
14227 area to be cleared. See tracking_off and
14228 wait_reading_process_output for examples of these situations.
14230 FROM_WHERE is an integer saying from where this function was
14231 called. This is useful for debugging. */
14234 redisplay_preserve_echo_area (int from_where
)
14236 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
14238 if (!NILP (echo_area_buffer
[1]))
14240 /* We have a previously displayed message, but no current
14241 message. Redisplay the previous message. */
14242 display_last_displayed_message_p
= true;
14243 redisplay_internal ();
14244 display_last_displayed_message_p
= false;
14247 redisplay_internal ();
14249 flush_frame (SELECTED_FRAME ());
14253 /* Function registered with record_unwind_protect in redisplay_internal. */
14256 unwind_redisplay (void)
14258 redisplaying_p
= false;
14262 /* Mark the display of leaf window W as accurate or inaccurate.
14263 If ACCURATE_P, mark display of W as accurate.
14264 If !ACCURATE_P, arrange for W to be redisplayed the next
14265 time redisplay_internal is called. */
14268 mark_window_display_accurate_1 (struct window
*w
, bool accurate_p
)
14270 struct buffer
*b
= XBUFFER (w
->contents
);
14272 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
14273 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
14274 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
14278 b
->clip_changed
= false;
14279 b
->prevent_redisplay_optimizations_p
= false;
14280 eassert (buffer_window_count (b
) > 0);
14281 /* Resetting b->text->redisplay is problematic!
14282 In order to make it safer to do it here, redisplay_internal must
14283 have copied all b->text->redisplay to their respective windows. */
14284 b
->text
->redisplay
= false;
14286 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
14287 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
14288 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
14289 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
14291 w
->current_matrix
->buffer
= b
;
14292 w
->current_matrix
->begv
= BUF_BEGV (b
);
14293 w
->current_matrix
->zv
= BUF_ZV (b
);
14295 w
->last_cursor_vpos
= w
->cursor
.vpos
;
14296 w
->last_cursor_off_p
= w
->cursor_off_p
;
14298 if (w
== XWINDOW (selected_window
))
14299 w
->last_point
= BUF_PT (b
);
14301 w
->last_point
= marker_position (w
->pointm
);
14303 w
->window_end_valid
= true;
14304 w
->update_mode_line
= false;
14307 w
->redisplay
= !accurate_p
;
14311 /* Mark the display of windows in the window tree rooted at WINDOW as
14312 accurate or inaccurate. If ACCURATE_P, mark display of
14313 windows as accurate. If !ACCURATE_P, arrange for windows to
14314 be redisplayed the next time redisplay_internal is called. */
14317 mark_window_display_accurate (Lisp_Object window
, bool accurate_p
)
14321 for (; !NILP (window
); window
= w
->next
)
14323 w
= XWINDOW (window
);
14324 if (WINDOWP (w
->contents
))
14325 mark_window_display_accurate (w
->contents
, accurate_p
);
14327 mark_window_display_accurate_1 (w
, accurate_p
);
14331 update_overlay_arrows (1);
14333 /* Force a thorough redisplay the next time by setting
14334 last_arrow_position and last_arrow_string to t, which is
14335 unequal to any useful value of Voverlay_arrow_... */
14336 update_overlay_arrows (-1);
14340 /* Return value in display table DP (Lisp_Char_Table *) for character
14341 C. Since a display table doesn't have any parent, we don't have to
14342 follow parent. Do not call this function directly but use the
14343 macro DISP_CHAR_VECTOR. */
14346 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
14350 if (ASCII_CHAR_P (c
))
14353 if (SUB_CHAR_TABLE_P (val
))
14354 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
14360 XSETCHAR_TABLE (table
, dp
);
14361 val
= char_table_ref (table
, c
);
14370 /***********************************************************************
14372 ***********************************************************************/
14374 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
14377 redisplay_windows (Lisp_Object window
)
14379 while (!NILP (window
))
14381 struct window
*w
= XWINDOW (window
);
14383 if (WINDOWP (w
->contents
))
14384 redisplay_windows (w
->contents
);
14385 else if (BUFFERP (w
->contents
))
14387 displayed_buffer
= XBUFFER (w
->contents
);
14388 /* Use list_of_error, not Qerror, so that
14389 we catch only errors and don't run the debugger. */
14390 internal_condition_case_1 (redisplay_window_0
, window
,
14392 redisplay_window_error
);
14400 redisplay_window_error (Lisp_Object ignore
)
14402 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14407 redisplay_window_0 (Lisp_Object window
)
14409 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14410 redisplay_window (window
, false);
14415 redisplay_window_1 (Lisp_Object window
)
14417 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14418 redisplay_window (window
, true);
14423 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14424 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14425 which positions recorded in ROW differ from current buffer
14428 Return true iff cursor is on this row. */
14431 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14432 struct glyph_matrix
*matrix
,
14433 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14436 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14437 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14438 struct glyph
*cursor
= NULL
;
14439 /* The last known character position in row. */
14440 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14442 ptrdiff_t pt_old
= PT
- delta
;
14443 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14444 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14445 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14446 /* A glyph beyond the edge of TEXT_AREA which we should never
14448 struct glyph
*glyphs_end
= end
;
14449 /* True means we've found a match for cursor position, but that
14450 glyph has the avoid_cursor_p flag set. */
14451 bool match_with_avoid_cursor
= false;
14452 /* True means we've seen at least one glyph that came from a
14454 bool string_seen
= false;
14455 /* Largest and smallest buffer positions seen so far during scan of
14457 ptrdiff_t bpos_max
= pos_before
;
14458 ptrdiff_t bpos_min
= pos_after
;
14459 /* Last buffer position covered by an overlay string with an integer
14460 `cursor' property. */
14461 ptrdiff_t bpos_covered
= 0;
14462 /* True means the display string on which to display the cursor
14463 comes from a text property, not from an overlay. */
14464 bool string_from_text_prop
= false;
14466 /* Don't even try doing anything if called for a mode-line or
14467 header-line row, since the rest of the code isn't prepared to
14468 deal with such calamities. */
14469 eassert (!row
->mode_line_p
);
14470 if (row
->mode_line_p
)
14473 /* Skip over glyphs not having an object at the start and the end of
14474 the row. These are special glyphs like truncation marks on
14475 terminal frames. */
14476 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14478 if (!row
->reversed_p
)
14481 && NILP (glyph
->object
)
14482 && glyph
->charpos
< 0)
14484 x
+= glyph
->pixel_width
;
14488 && NILP ((end
- 1)->object
)
14489 /* CHARPOS is zero for blanks and stretch glyphs
14490 inserted by extend_face_to_end_of_line. */
14491 && (end
- 1)->charpos
<= 0)
14493 glyph_before
= glyph
- 1;
14500 /* If the glyph row is reversed, we need to process it from back
14501 to front, so swap the edge pointers. */
14502 glyphs_end
= end
= glyph
- 1;
14503 glyph
+= row
->used
[TEXT_AREA
] - 1;
14505 while (glyph
> end
+ 1
14506 && NILP (glyph
->object
)
14507 && glyph
->charpos
< 0)
14510 x
-= glyph
->pixel_width
;
14512 if (NILP (glyph
->object
) && glyph
->charpos
< 0)
14514 /* By default, in reversed rows we put the cursor on the
14515 rightmost (first in the reading order) glyph. */
14516 for (g
= end
+ 1; g
< glyph
; g
++)
14517 x
+= g
->pixel_width
;
14519 && NILP ((end
+ 1)->object
)
14520 && (end
+ 1)->charpos
<= 0)
14522 glyph_before
= glyph
+ 1;
14526 else if (row
->reversed_p
)
14528 /* In R2L rows that don't display text, put the cursor on the
14529 rightmost glyph. Case in point: an empty last line that is
14530 part of an R2L paragraph. */
14532 /* Avoid placing the cursor on the last glyph of the row, where
14533 on terminal frames we hold the vertical border between
14534 adjacent windows. */
14535 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14536 && !WINDOW_RIGHTMOST_P (w
)
14537 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14539 x
= -1; /* will be computed below, at label compute_x */
14542 /* Step 1: Try to find the glyph whose character position
14543 corresponds to point. If that's not possible, find 2 glyphs
14544 whose character positions are the closest to point, one before
14545 point, the other after it. */
14546 if (!row
->reversed_p
)
14547 while (/* not marched to end of glyph row */
14549 /* glyph was not inserted by redisplay for internal purposes */
14550 && !NILP (glyph
->object
))
14552 if (BUFFERP (glyph
->object
))
14554 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14556 if (glyph
->charpos
> bpos_max
)
14557 bpos_max
= glyph
->charpos
;
14558 if (glyph
->charpos
< bpos_min
)
14559 bpos_min
= glyph
->charpos
;
14560 if (!glyph
->avoid_cursor_p
)
14562 /* If we hit point, we've found the glyph on which to
14563 display the cursor. */
14566 match_with_avoid_cursor
= false;
14569 /* See if we've found a better approximation to
14570 POS_BEFORE or to POS_AFTER. */
14571 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14573 pos_before
= glyph
->charpos
;
14574 glyph_before
= glyph
;
14576 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14578 pos_after
= glyph
->charpos
;
14579 glyph_after
= glyph
;
14582 else if (dpos
== 0)
14583 match_with_avoid_cursor
= true;
14585 else if (STRINGP (glyph
->object
))
14587 Lisp_Object chprop
;
14588 ptrdiff_t glyph_pos
= glyph
->charpos
;
14590 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14592 if (!NILP (chprop
))
14594 /* If the string came from a `display' text property,
14595 look up the buffer position of that property and
14596 use that position to update bpos_max, as if we
14597 actually saw such a position in one of the row's
14598 glyphs. This helps with supporting integer values
14599 of `cursor' property on the display string in
14600 situations where most or all of the row's buffer
14601 text is completely covered by display properties,
14602 so that no glyph with valid buffer positions is
14603 ever seen in the row. */
14604 ptrdiff_t prop_pos
=
14605 string_buffer_position_lim (glyph
->object
, pos_before
,
14608 if (prop_pos
>= pos_before
)
14609 bpos_max
= prop_pos
;
14611 if (INTEGERP (chprop
))
14613 bpos_covered
= bpos_max
+ XINT (chprop
);
14614 /* If the `cursor' property covers buffer positions up
14615 to and including point, we should display cursor on
14616 this glyph. Note that, if a `cursor' property on one
14617 of the string's characters has an integer value, we
14618 will break out of the loop below _before_ we get to
14619 the position match above. IOW, integer values of
14620 the `cursor' property override the "exact match for
14621 point" strategy of positioning the cursor. */
14622 /* Implementation note: bpos_max == pt_old when, e.g.,
14623 we are in an empty line, where bpos_max is set to
14624 MATRIX_ROW_START_CHARPOS, see above. */
14625 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14632 string_seen
= true;
14634 x
+= glyph
->pixel_width
;
14637 else if (glyph
> end
) /* row is reversed */
14638 while (!NILP (glyph
->object
))
14640 if (BUFFERP (glyph
->object
))
14642 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14644 if (glyph
->charpos
> bpos_max
)
14645 bpos_max
= glyph
->charpos
;
14646 if (glyph
->charpos
< bpos_min
)
14647 bpos_min
= glyph
->charpos
;
14648 if (!glyph
->avoid_cursor_p
)
14652 match_with_avoid_cursor
= false;
14655 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14657 pos_before
= glyph
->charpos
;
14658 glyph_before
= glyph
;
14660 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14662 pos_after
= glyph
->charpos
;
14663 glyph_after
= glyph
;
14666 else if (dpos
== 0)
14667 match_with_avoid_cursor
= true;
14669 else if (STRINGP (glyph
->object
))
14671 Lisp_Object chprop
;
14672 ptrdiff_t glyph_pos
= glyph
->charpos
;
14674 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14676 if (!NILP (chprop
))
14678 ptrdiff_t prop_pos
=
14679 string_buffer_position_lim (glyph
->object
, pos_before
,
14682 if (prop_pos
>= pos_before
)
14683 bpos_max
= prop_pos
;
14685 if (INTEGERP (chprop
))
14687 bpos_covered
= bpos_max
+ XINT (chprop
);
14688 /* If the `cursor' property covers buffer positions up
14689 to and including point, we should display cursor on
14691 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14697 string_seen
= true;
14700 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14702 x
--; /* can't use any pixel_width */
14705 x
-= glyph
->pixel_width
;
14708 /* Step 2: If we didn't find an exact match for point, we need to
14709 look for a proper place to put the cursor among glyphs between
14710 GLYPH_BEFORE and GLYPH_AFTER. */
14711 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14712 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14713 && !(bpos_max
<= pt_old
&& pt_old
<= bpos_covered
))
14715 /* An empty line has a single glyph whose OBJECT is nil and
14716 whose CHARPOS is the position of a newline on that line.
14717 Note that on a TTY, there are more glyphs after that, which
14718 were produced by extend_face_to_end_of_line, but their
14719 CHARPOS is zero or negative. */
14720 bool empty_line_p
=
14721 ((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14722 && NILP (glyph
->object
) && glyph
->charpos
> 0
14723 /* On a TTY, continued and truncated rows also have a glyph at
14724 their end whose OBJECT is nil and whose CHARPOS is
14725 positive (the continuation and truncation glyphs), but such
14726 rows are obviously not "empty". */
14727 && !(row
->continued_p
|| row
->truncated_on_right_p
));
14729 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14731 ptrdiff_t ellipsis_pos
;
14733 /* Scan back over the ellipsis glyphs. */
14734 if (!row
->reversed_p
)
14736 ellipsis_pos
= (glyph
- 1)->charpos
;
14737 while (glyph
> row
->glyphs
[TEXT_AREA
]
14738 && (glyph
- 1)->charpos
== ellipsis_pos
)
14739 glyph
--, x
-= glyph
->pixel_width
;
14740 /* That loop always goes one position too far, including
14741 the glyph before the ellipsis. So scan forward over
14743 x
+= glyph
->pixel_width
;
14746 else /* row is reversed */
14748 ellipsis_pos
= (glyph
+ 1)->charpos
;
14749 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14750 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14751 glyph
++, x
+= glyph
->pixel_width
;
14752 x
-= glyph
->pixel_width
;
14756 else if (match_with_avoid_cursor
)
14758 cursor
= glyph_after
;
14761 else if (string_seen
)
14763 int incr
= row
->reversed_p
? -1 : +1;
14765 /* Need to find the glyph that came out of a string which is
14766 present at point. That glyph is somewhere between
14767 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14768 positioned between POS_BEFORE and POS_AFTER in the
14770 struct glyph
*start
, *stop
;
14771 ptrdiff_t pos
= pos_before
;
14775 /* If the row ends in a newline from a display string,
14776 reordering could have moved the glyphs belonging to the
14777 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14778 in this case we extend the search to the last glyph in
14779 the row that was not inserted by redisplay. */
14780 if (row
->ends_in_newline_from_string_p
)
14783 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14786 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14787 correspond to POS_BEFORE and POS_AFTER, respectively. We
14788 need START and STOP in the order that corresponds to the
14789 row's direction as given by its reversed_p flag. If the
14790 directionality of characters between POS_BEFORE and
14791 POS_AFTER is the opposite of the row's base direction,
14792 these characters will have been reordered for display,
14793 and we need to reverse START and STOP. */
14794 if (!row
->reversed_p
)
14796 start
= min (glyph_before
, glyph_after
);
14797 stop
= max (glyph_before
, glyph_after
);
14801 start
= max (glyph_before
, glyph_after
);
14802 stop
= min (glyph_before
, glyph_after
);
14804 for (glyph
= start
+ incr
;
14805 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14808 /* Any glyphs that come from the buffer are here because
14809 of bidi reordering. Skip them, and only pay
14810 attention to glyphs that came from some string. */
14811 if (STRINGP (glyph
->object
))
14815 /* If the display property covers the newline, we
14816 need to search for it one position farther. */
14817 ptrdiff_t lim
= pos_after
14818 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14820 string_from_text_prop
= false;
14821 str
= glyph
->object
;
14822 tem
= string_buffer_position_lim (str
, pos
, lim
, false);
14823 if (tem
== 0 /* from overlay */
14826 /* If the string from which this glyph came is
14827 found in the buffer at point, or at position
14828 that is closer to point than pos_after, then
14829 we've found the glyph we've been looking for.
14830 If it comes from an overlay (tem == 0), and
14831 it has the `cursor' property on one of its
14832 glyphs, record that glyph as a candidate for
14833 displaying the cursor. (As in the
14834 unidirectional version, we will display the
14835 cursor on the last candidate we find.) */
14838 || (tem
- pt_old
> 0 && tem
< pos_after
))
14840 /* The glyphs from this string could have
14841 been reordered. Find the one with the
14842 smallest string position. Or there could
14843 be a character in the string with the
14844 `cursor' property, which means display
14845 cursor on that character's glyph. */
14846 ptrdiff_t strpos
= glyph
->charpos
;
14851 string_from_text_prop
= true;
14854 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14855 && EQ (glyph
->object
, str
);
14859 ptrdiff_t gpos
= glyph
->charpos
;
14861 cprop
= Fget_char_property (make_number (gpos
),
14869 if (tem
&& glyph
->charpos
< strpos
)
14871 strpos
= glyph
->charpos
;
14877 || (tem
- pt_old
> 0 && tem
< pos_after
))
14881 pos
= tem
+ 1; /* don't find previous instances */
14883 /* This string is not what we want; skip all of the
14884 glyphs that came from it. */
14885 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14886 && EQ (glyph
->object
, str
))
14893 /* If we reached the end of the line, and END was from a string,
14894 the cursor is not on this line. */
14896 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14897 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14898 && STRINGP (end
->object
)
14899 && row
->continued_p
)
14902 /* A truncated row may not include PT among its character positions.
14903 Setting the cursor inside the scroll margin will trigger
14904 recalculation of hscroll in hscroll_window_tree. But if a
14905 display string covers point, defer to the string-handling
14906 code below to figure this out. */
14907 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14909 cursor
= glyph_before
;
14912 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14913 /* Zero-width characters produce no glyphs. */
14915 && (row
->reversed_p
14916 ? glyph_after
> glyphs_end
14917 : glyph_after
< glyphs_end
)))
14919 cursor
= glyph_after
;
14925 if (cursor
!= NULL
)
14927 else if (glyph
== glyphs_end
14928 && pos_before
== pos_after
14929 && STRINGP ((row
->reversed_p
14930 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14931 : row
->glyphs
[TEXT_AREA
])->object
))
14933 /* If all the glyphs of this row came from strings, put the
14934 cursor on the first glyph of the row. This avoids having the
14935 cursor outside of the text area in this very rare and hard
14939 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14940 : row
->glyphs
[TEXT_AREA
];
14946 /* Need to compute x that corresponds to GLYPH. */
14947 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14949 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14951 x
+= g
->pixel_width
;
14955 /* ROW could be part of a continued line, which, under bidi
14956 reordering, might have other rows whose start and end charpos
14957 occlude point. Only set w->cursor if we found a better
14958 approximation to the cursor position than we have from previously
14959 examined candidate rows belonging to the same continued line. */
14960 if (/* We already have a candidate row. */
14961 w
->cursor
.vpos
>= 0
14962 /* That candidate is not the row we are processing. */
14963 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14964 /* Make sure cursor.vpos specifies a row whose start and end
14965 charpos occlude point, and it is valid candidate for being a
14966 cursor-row. This is because some callers of this function
14967 leave cursor.vpos at the row where the cursor was displayed
14968 during the last redisplay cycle. */
14969 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14970 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14971 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14974 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14976 /* Don't consider glyphs that are outside TEXT_AREA. */
14977 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14979 /* Keep the candidate whose buffer position is the closest to
14980 point or has the `cursor' property. */
14981 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14982 w
->cursor
.hpos
>= 0
14983 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14984 && ((BUFFERP (g1
->object
)
14985 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14986 || (BUFFERP (glyph
->object
)
14987 && eabs (g1
->charpos
- pt_old
)
14988 < eabs (glyph
->charpos
- pt_old
))))
14989 /* Previous candidate is a glyph from a string that has
14990 a non-nil `cursor' property. */
14991 || (STRINGP (g1
->object
)
14992 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14993 Qcursor
, g1
->object
))
14994 /* Previous candidate is from the same display
14995 string as this one, and the display string
14996 came from a text property. */
14997 || (EQ (g1
->object
, glyph
->object
)
14998 && string_from_text_prop
)
14999 /* this candidate is from newline and its
15000 position is not an exact match */
15001 || (NILP (glyph
->object
)
15002 && glyph
->charpos
!= pt_old
)))))
15004 /* If this candidate gives an exact match, use that. */
15005 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
15006 /* If this candidate is a glyph created for the
15007 terminating newline of a line, and point is on that
15008 newline, it wins because it's an exact match. */
15009 || (!row
->continued_p
15010 && NILP (glyph
->object
)
15011 && glyph
->charpos
== 0
15012 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
15013 /* Otherwise, keep the candidate that comes from a row
15014 spanning less buffer positions. This may win when one or
15015 both candidate positions are on glyphs that came from
15016 display strings, for which we cannot compare buffer
15018 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15019 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15020 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
15023 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
15025 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
15026 w
->cursor
.y
= row
->y
+ dy
;
15028 if (w
== XWINDOW (selected_window
))
15030 if (!row
->continued_p
15031 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15034 this_line_buffer
= XBUFFER (w
->contents
);
15036 CHARPOS (this_line_start_pos
)
15037 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
15038 BYTEPOS (this_line_start_pos
)
15039 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
15041 CHARPOS (this_line_end_pos
)
15042 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
15043 BYTEPOS (this_line_end_pos
)
15044 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
15046 this_line_y
= w
->cursor
.y
;
15047 this_line_pixel_height
= row
->height
;
15048 this_line_vpos
= w
->cursor
.vpos
;
15049 this_line_start_x
= row
->x
;
15052 CHARPOS (this_line_start_pos
) = 0;
15059 /* Run window scroll functions, if any, for WINDOW with new window
15060 start STARTP. Sets the window start of WINDOW to that position.
15062 We assume that the window's buffer is really current. */
15064 static struct text_pos
15065 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
15067 struct window
*w
= XWINDOW (window
);
15068 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
15070 eassert (current_buffer
== XBUFFER (w
->contents
));
15072 if (!NILP (Vwindow_scroll_functions
))
15074 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
15075 make_number (CHARPOS (startp
)));
15076 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15077 /* In case the hook functions switch buffers. */
15078 set_buffer_internal (XBUFFER (w
->contents
));
15085 /* Make sure the line containing the cursor is fully visible.
15086 A value of true means there is nothing to be done.
15087 (Either the line is fully visible, or it cannot be made so,
15088 or we cannot tell.)
15090 If FORCE_P, return false even if partial visible cursor row
15091 is higher than window.
15093 If CURRENT_MATRIX_P, use the information from the
15094 window's current glyph matrix; otherwise use the desired glyph
15097 A value of false means the caller should do scrolling
15098 as if point had gone off the screen. */
15101 cursor_row_fully_visible_p (struct window
*w
, bool force_p
,
15102 bool current_matrix_p
)
15104 struct glyph_matrix
*matrix
;
15105 struct glyph_row
*row
;
15108 if (!make_cursor_line_fully_visible_p
)
15111 /* It's not always possible to find the cursor, e.g, when a window
15112 is full of overlay strings. Don't do anything in that case. */
15113 if (w
->cursor
.vpos
< 0)
15116 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
15117 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
15119 /* If the cursor row is not partially visible, there's nothing to do. */
15120 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
15123 /* If the row the cursor is in is taller than the window's height,
15124 it's not clear what to do, so do nothing. */
15125 window_height
= window_box_height (w
);
15126 if (row
->height
>= window_height
)
15128 if (!force_p
|| MINI_WINDOW_P (w
)
15129 || w
->vscroll
|| w
->cursor
.vpos
== 0)
15136 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
15137 means only WINDOW is redisplayed in redisplay_internal.
15138 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
15139 in redisplay_window to bring a partially visible line into view in
15140 the case that only the cursor has moved.
15142 LAST_LINE_MISFIT should be true if we're scrolling because the
15143 last screen line's vertical height extends past the end of the screen.
15147 1 if scrolling succeeded
15149 0 if scrolling didn't find point.
15151 -1 if new fonts have been loaded so that we must interrupt
15152 redisplay, adjust glyph matrices, and try again. */
15158 SCROLLING_NEED_LARGER_MATRICES
15161 /* If scroll-conservatively is more than this, never recenter.
15163 If you change this, don't forget to update the doc string of
15164 `scroll-conservatively' and the Emacs manual. */
15165 #define SCROLL_LIMIT 100
15168 try_scrolling (Lisp_Object window
, bool just_this_one_p
,
15169 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
15170 bool temp_scroll_step
, bool last_line_misfit
)
15172 struct window
*w
= XWINDOW (window
);
15173 struct frame
*f
= XFRAME (w
->frame
);
15174 struct text_pos pos
, startp
;
15176 int this_scroll_margin
, scroll_max
, rc
, height
;
15177 int dy
= 0, amount_to_scroll
= 0;
15178 bool scroll_down_p
= false;
15179 int extra_scroll_margin_lines
= last_line_misfit
;
15180 Lisp_Object aggressive
;
15181 /* We will never try scrolling more than this number of lines. */
15182 int scroll_limit
= SCROLL_LIMIT
;
15183 int frame_line_height
= default_line_pixel_height (w
);
15184 int window_total_lines
15185 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15188 debug_method_add (w
, "try_scrolling");
15191 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15193 /* Compute scroll margin height in pixels. We scroll when point is
15194 within this distance from the top or bottom of the window. */
15195 if (scroll_margin
> 0)
15196 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
15197 * frame_line_height
;
15199 this_scroll_margin
= 0;
15201 /* Force arg_scroll_conservatively to have a reasonable value, to
15202 avoid scrolling too far away with slow move_it_* functions. Note
15203 that the user can supply scroll-conservatively equal to
15204 `most-positive-fixnum', which can be larger than INT_MAX. */
15205 if (arg_scroll_conservatively
> scroll_limit
)
15207 arg_scroll_conservatively
= scroll_limit
+ 1;
15208 scroll_max
= scroll_limit
* frame_line_height
;
15210 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
15211 /* Compute how much we should try to scroll maximally to bring
15212 point into view. */
15213 scroll_max
= (max (scroll_step
,
15214 max (arg_scroll_conservatively
, temp_scroll_step
))
15215 * frame_line_height
);
15216 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
15217 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
15218 /* We're trying to scroll because of aggressive scrolling but no
15219 scroll_step is set. Choose an arbitrary one. */
15220 scroll_max
= 10 * frame_line_height
;
15226 /* Decide whether to scroll down. */
15227 if (PT
> CHARPOS (startp
))
15229 int scroll_margin_y
;
15231 /* Compute the pixel ypos of the scroll margin, then move IT to
15232 either that ypos or PT, whichever comes first. */
15233 start_display (&it
, w
, startp
);
15234 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
15235 - frame_line_height
* extra_scroll_margin_lines
;
15236 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
15237 (MOVE_TO_POS
| MOVE_TO_Y
));
15239 if (PT
> CHARPOS (it
.current
.pos
))
15241 int y0
= line_bottom_y (&it
);
15242 /* Compute how many pixels below window bottom to stop searching
15243 for PT. This avoids costly search for PT that is far away if
15244 the user limited scrolling by a small number of lines, but
15245 always finds PT if scroll_conservatively is set to a large
15246 number, such as most-positive-fixnum. */
15247 int slack
= max (scroll_max
, 10 * frame_line_height
);
15248 int y_to_move
= it
.last_visible_y
+ slack
;
15250 /* Compute the distance from the scroll margin to PT or to
15251 the scroll limit, whichever comes first. This should
15252 include the height of the cursor line, to make that line
15254 move_it_to (&it
, PT
, -1, y_to_move
,
15255 -1, MOVE_TO_POS
| MOVE_TO_Y
);
15256 dy
= line_bottom_y (&it
) - y0
;
15258 if (dy
> scroll_max
)
15259 return SCROLLING_FAILED
;
15262 scroll_down_p
= true;
15268 /* Point is in or below the bottom scroll margin, so move the
15269 window start down. If scrolling conservatively, move it just
15270 enough down to make point visible. If scroll_step is set,
15271 move it down by scroll_step. */
15272 if (arg_scroll_conservatively
)
15274 = min (max (dy
, frame_line_height
),
15275 frame_line_height
* arg_scroll_conservatively
);
15276 else if (scroll_step
|| temp_scroll_step
)
15277 amount_to_scroll
= scroll_max
;
15280 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
15281 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15282 if (NUMBERP (aggressive
))
15284 double float_amount
= XFLOATINT (aggressive
) * height
;
15285 int aggressive_scroll
= float_amount
;
15286 if (aggressive_scroll
== 0 && float_amount
> 0)
15287 aggressive_scroll
= 1;
15288 /* Don't let point enter the scroll margin near top of
15289 the window. This could happen if the value of
15290 scroll_up_aggressively is too large and there are
15291 non-zero margins, because scroll_up_aggressively
15292 means put point that fraction of window height
15293 _from_the_bottom_margin_. */
15294 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15295 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15296 amount_to_scroll
= dy
+ aggressive_scroll
;
15300 if (amount_to_scroll
<= 0)
15301 return SCROLLING_FAILED
;
15303 start_display (&it
, w
, startp
);
15304 if (arg_scroll_conservatively
<= scroll_limit
)
15305 move_it_vertically (&it
, amount_to_scroll
);
15308 /* Extra precision for users who set scroll-conservatively
15309 to a large number: make sure the amount we scroll
15310 the window start is never less than amount_to_scroll,
15311 which was computed as distance from window bottom to
15312 point. This matters when lines at window top and lines
15313 below window bottom have different height. */
15315 void *it1data
= NULL
;
15316 /* We use a temporary it1 because line_bottom_y can modify
15317 its argument, if it moves one line down; see there. */
15320 SAVE_IT (it1
, it
, it1data
);
15321 start_y
= line_bottom_y (&it1
);
15323 RESTORE_IT (&it
, &it
, it1data
);
15324 move_it_by_lines (&it
, 1);
15325 SAVE_IT (it1
, it
, it1data
);
15326 } while (IT_CHARPOS (it
) < ZV
15327 && line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
15328 bidi_unshelve_cache (it1data
, true);
15331 /* If STARTP is unchanged, move it down another screen line. */
15332 if (IT_CHARPOS (it
) == CHARPOS (startp
))
15333 move_it_by_lines (&it
, 1);
15334 startp
= it
.current
.pos
;
15338 struct text_pos scroll_margin_pos
= startp
;
15341 /* See if point is inside the scroll margin at the top of the
15343 if (this_scroll_margin
)
15347 start_display (&it
, w
, startp
);
15348 y_start
= it
.current_y
;
15349 move_it_vertically (&it
, this_scroll_margin
);
15350 scroll_margin_pos
= it
.current
.pos
;
15351 /* If we didn't move enough before hitting ZV, request
15352 additional amount of scroll, to move point out of the
15354 if (IT_CHARPOS (it
) == ZV
15355 && it
.current_y
- y_start
< this_scroll_margin
)
15356 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
15359 if (PT
< CHARPOS (scroll_margin_pos
))
15361 /* Point is in the scroll margin at the top of the window or
15362 above what is displayed in the window. */
15365 /* Compute the vertical distance from PT to the scroll
15366 margin position. Move as far as scroll_max allows, or
15367 one screenful, or 10 screen lines, whichever is largest.
15368 Give up if distance is greater than scroll_max or if we
15369 didn't reach the scroll margin position. */
15370 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
15371 start_display (&it
, w
, pos
);
15373 y_to_move
= max (it
.last_visible_y
,
15374 max (scroll_max
, 10 * frame_line_height
));
15375 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
15377 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15378 dy
= it
.current_y
- y0
;
15379 if (dy
> scroll_max
15380 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
15381 return SCROLLING_FAILED
;
15383 /* Additional scroll for when ZV was too close to point. */
15386 /* Compute new window start. */
15387 start_display (&it
, w
, startp
);
15389 if (arg_scroll_conservatively
)
15390 amount_to_scroll
= max (dy
, frame_line_height
15391 * max (scroll_step
, temp_scroll_step
));
15392 else if (scroll_step
|| temp_scroll_step
)
15393 amount_to_scroll
= scroll_max
;
15396 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15397 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15398 if (NUMBERP (aggressive
))
15400 double float_amount
= XFLOATINT (aggressive
) * height
;
15401 int aggressive_scroll
= float_amount
;
15402 if (aggressive_scroll
== 0 && float_amount
> 0)
15403 aggressive_scroll
= 1;
15404 /* Don't let point enter the scroll margin near
15405 bottom of the window, if the value of
15406 scroll_down_aggressively happens to be too
15408 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15409 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15410 amount_to_scroll
= dy
+ aggressive_scroll
;
15414 if (amount_to_scroll
<= 0)
15415 return SCROLLING_FAILED
;
15417 move_it_vertically_backward (&it
, amount_to_scroll
);
15418 startp
= it
.current
.pos
;
15422 /* Run window scroll functions. */
15423 startp
= run_window_scroll_functions (window
, startp
);
15425 /* Display the window. Give up if new fonts are loaded, or if point
15427 if (!try_window (window
, startp
, 0))
15428 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15429 else if (w
->cursor
.vpos
< 0)
15431 clear_glyph_matrix (w
->desired_matrix
);
15432 rc
= SCROLLING_FAILED
;
15436 /* Maybe forget recorded base line for line number display. */
15437 if (!just_this_one_p
15438 || current_buffer
->clip_changed
15439 || BEG_UNCHANGED
< CHARPOS (startp
))
15440 w
->base_line_number
= 0;
15442 /* If cursor ends up on a partially visible line,
15443 treat that as being off the bottom of the screen. */
15444 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1,
15446 /* It's possible that the cursor is on the first line of the
15447 buffer, which is partially obscured due to a vscroll
15448 (Bug#7537). In that case, avoid looping forever. */
15449 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15451 clear_glyph_matrix (w
->desired_matrix
);
15452 ++extra_scroll_margin_lines
;
15455 rc
= SCROLLING_SUCCESS
;
15462 /* Compute a suitable window start for window W if display of W starts
15463 on a continuation line. Value is true if a new window start
15466 The new window start will be computed, based on W's width, starting
15467 from the start of the continued line. It is the start of the
15468 screen line with the minimum distance from the old start W->start. */
15471 compute_window_start_on_continuation_line (struct window
*w
)
15473 struct text_pos pos
, start_pos
;
15474 bool window_start_changed_p
= false;
15476 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15478 /* If window start is on a continuation line... Window start may be
15479 < BEGV in case there's invisible text at the start of the
15480 buffer (M-x rmail, for example). */
15481 if (CHARPOS (start_pos
) > BEGV
15482 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15485 struct glyph_row
*row
;
15487 /* Handle the case that the window start is out of range. */
15488 if (CHARPOS (start_pos
) < BEGV
)
15489 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15490 else if (CHARPOS (start_pos
) > ZV
)
15491 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15493 /* Find the start of the continued line. This should be fast
15494 because find_newline is fast (newline cache). */
15495 row
= w
->desired_matrix
->rows
+ WINDOW_WANTS_HEADER_LINE_P (w
);
15496 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15497 row
, DEFAULT_FACE_ID
);
15498 reseat_at_previous_visible_line_start (&it
);
15500 /* If the line start is "too far" away from the window start,
15501 say it takes too much time to compute a new window start. */
15502 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15503 /* PXW: Do we need upper bounds here? */
15504 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15506 int min_distance
, distance
;
15508 /* Move forward by display lines to find the new window
15509 start. If window width was enlarged, the new start can
15510 be expected to be > the old start. If window width was
15511 decreased, the new window start will be < the old start.
15512 So, we're looking for the display line start with the
15513 minimum distance from the old window start. */
15514 pos
= it
.current
.pos
;
15515 min_distance
= INFINITY
;
15516 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15517 distance
< min_distance
)
15519 min_distance
= distance
;
15520 pos
= it
.current
.pos
;
15521 if (it
.line_wrap
== WORD_WRAP
)
15523 /* Under WORD_WRAP, move_it_by_lines is likely to
15524 overshoot and stop not at the first, but the
15525 second character from the left margin. So in
15526 that case, we need a more tight control on the X
15527 coordinate of the iterator than move_it_by_lines
15528 promises in its contract. The method is to first
15529 go to the last (rightmost) visible character of a
15530 line, then move to the leftmost character on the
15531 next line in a separate call. */
15532 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15533 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15534 move_it_to (&it
, ZV
, 0,
15535 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15536 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15539 move_it_by_lines (&it
, 1);
15542 /* Set the window start there. */
15543 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15544 window_start_changed_p
= true;
15548 return window_start_changed_p
;
15552 /* Try cursor movement in case text has not changed in window WINDOW,
15553 with window start STARTP. Value is
15555 CURSOR_MOVEMENT_SUCCESS if successful
15557 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15559 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15560 display. *SCROLL_STEP is set to true, under certain circumstances, if
15561 we want to scroll as if scroll-step were set to 1. See the code.
15563 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15564 which case we have to abort this redisplay, and adjust matrices
15569 CURSOR_MOVEMENT_SUCCESS
,
15570 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15571 CURSOR_MOVEMENT_MUST_SCROLL
,
15572 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15576 try_cursor_movement (Lisp_Object window
, struct text_pos startp
,
15579 struct window
*w
= XWINDOW (window
);
15580 struct frame
*f
= XFRAME (w
->frame
);
15581 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15584 if (inhibit_try_cursor_movement
)
15588 /* Previously, there was a check for Lisp integer in the
15589 if-statement below. Now, this field is converted to
15590 ptrdiff_t, thus zero means invalid position in a buffer. */
15591 eassert (w
->last_point
> 0);
15592 /* Likewise there was a check whether window_end_vpos is nil or larger
15593 than the window. Now window_end_vpos is int and so never nil, but
15594 let's leave eassert to check whether it fits in the window. */
15595 eassert (!w
->window_end_valid
15596 || w
->window_end_vpos
< w
->current_matrix
->nrows
);
15598 /* Handle case where text has not changed, only point, and it has
15599 not moved off the frame. */
15600 if (/* Point may be in this window. */
15601 PT
>= CHARPOS (startp
)
15602 /* Selective display hasn't changed. */
15603 && !current_buffer
->clip_changed
15604 /* Function force-mode-line-update is used to force a thorough
15605 redisplay. It sets either windows_or_buffers_changed or
15606 update_mode_lines. So don't take a shortcut here for these
15608 && !update_mode_lines
15609 && !windows_or_buffers_changed
15610 && !f
->cursor_type_changed
15611 && NILP (Vshow_trailing_whitespace
)
15612 /* This code is not used for mini-buffer for the sake of the case
15613 of redisplaying to replace an echo area message; since in
15614 that case the mini-buffer contents per se are usually
15615 unchanged. This code is of no real use in the mini-buffer
15616 since the handling of this_line_start_pos, etc., in redisplay
15617 handles the same cases. */
15618 && !EQ (window
, minibuf_window
)
15619 && (FRAME_WINDOW_P (f
)
15620 || !overlay_arrow_in_current_buffer_p ()))
15622 int this_scroll_margin
, top_scroll_margin
;
15623 struct glyph_row
*row
= NULL
;
15624 int frame_line_height
= default_line_pixel_height (w
);
15625 int window_total_lines
15626 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15629 debug_method_add (w
, "cursor movement");
15632 /* Scroll if point within this distance from the top or bottom
15633 of the window. This is a pixel value. */
15634 if (scroll_margin
> 0)
15636 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15637 this_scroll_margin
*= frame_line_height
;
15640 this_scroll_margin
= 0;
15642 top_scroll_margin
= this_scroll_margin
;
15643 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15644 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15646 /* Start with the row the cursor was displayed during the last
15647 not paused redisplay. Give up if that row is not valid. */
15648 if (w
->last_cursor_vpos
< 0
15649 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15650 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15653 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15654 if (row
->mode_line_p
)
15656 if (!row
->enabled_p
)
15657 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15660 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15662 bool scroll_p
= false, must_scroll
= false;
15663 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15665 if (PT
> w
->last_point
)
15667 /* Point has moved forward. */
15668 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15669 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15671 eassert (row
->enabled_p
);
15675 /* If the end position of a row equals the start
15676 position of the next row, and PT is at that position,
15677 we would rather display cursor in the next line. */
15678 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15679 && MATRIX_ROW_END_CHARPOS (row
) == PT
15680 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15681 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15682 && !cursor_row_p (row
))
15685 /* If within the scroll margin, scroll. Note that
15686 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15687 the next line would be drawn, and that
15688 this_scroll_margin can be zero. */
15689 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15690 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15691 /* Line is completely visible last line in window
15692 and PT is to be set in the next line. */
15693 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15694 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15695 && !row
->ends_at_zv_p
15696 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15699 else if (PT
< w
->last_point
)
15701 /* Cursor has to be moved backward. Note that PT >=
15702 CHARPOS (startp) because of the outer if-statement. */
15703 while (!row
->mode_line_p
15704 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15705 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15706 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15707 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15708 row
> w
->current_matrix
->rows
15709 && (row
-1)->ends_in_newline_from_string_p
))))
15710 && (row
->y
> top_scroll_margin
15711 || CHARPOS (startp
) == BEGV
))
15713 eassert (row
->enabled_p
);
15717 /* Consider the following case: Window starts at BEGV,
15718 there is invisible, intangible text at BEGV, so that
15719 display starts at some point START > BEGV. It can
15720 happen that we are called with PT somewhere between
15721 BEGV and START. Try to handle that case. */
15722 if (row
< w
->current_matrix
->rows
15723 || row
->mode_line_p
)
15725 row
= w
->current_matrix
->rows
;
15726 if (row
->mode_line_p
)
15730 /* Due to newlines in overlay strings, we may have to
15731 skip forward over overlay strings. */
15732 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15733 && MATRIX_ROW_END_CHARPOS (row
) == PT
15734 && !cursor_row_p (row
))
15737 /* If within the scroll margin, scroll. */
15738 if (row
->y
< top_scroll_margin
15739 && CHARPOS (startp
) != BEGV
)
15744 /* Cursor did not move. So don't scroll even if cursor line
15745 is partially visible, as it was so before. */
15746 rc
= CURSOR_MOVEMENT_SUCCESS
;
15749 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15750 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15752 /* if PT is not in the glyph row, give up. */
15753 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15754 must_scroll
= true;
15756 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15757 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15759 struct glyph_row
*row1
;
15761 /* If rows are bidi-reordered and point moved, back up
15762 until we find a row that does not belong to a
15763 continuation line. This is because we must consider
15764 all rows of a continued line as candidates for the
15765 new cursor positioning, since row start and end
15766 positions change non-linearly with vertical position
15768 /* FIXME: Revisit this when glyph ``spilling'' in
15769 continuation lines' rows is implemented for
15770 bidi-reordered rows. */
15771 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15772 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15775 /* If we hit the beginning of the displayed portion
15776 without finding the first row of a continued
15780 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15783 eassert (row
->enabled_p
);
15788 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15789 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15790 /* Make sure this isn't a header line by any chance, since
15791 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield true. */
15792 && !row
->mode_line_p
15793 && make_cursor_line_fully_visible_p
)
15795 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15796 && !row
->ends_at_zv_p
15797 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15798 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15799 else if (row
->height
> window_box_height (w
))
15801 /* If we end up in a partially visible line, let's
15802 make it fully visible, except when it's taller
15803 than the window, in which case we can't do much
15805 *scroll_step
= true;
15806 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15810 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15811 if (!cursor_row_fully_visible_p (w
, false, true))
15812 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15814 rc
= CURSOR_MOVEMENT_SUCCESS
;
15818 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15819 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15820 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15822 /* With bidi-reordered rows, there could be more than
15823 one candidate row whose start and end positions
15824 occlude point. We need to let set_cursor_from_row
15825 find the best candidate. */
15826 /* FIXME: Revisit this when glyph ``spilling'' in
15827 continuation lines' rows is implemented for
15828 bidi-reordered rows. */
15833 bool at_zv_p
= false, exact_match_p
= false;
15835 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15836 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15837 && cursor_row_p (row
))
15838 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15840 /* As soon as we've found the exact match for point,
15841 or the first suitable row whose ends_at_zv_p flag
15842 is set, we are done. */
15845 at_zv_p
= MATRIX_ROW (w
->current_matrix
,
15846 w
->cursor
.vpos
)->ends_at_zv_p
;
15848 && w
->cursor
.hpos
>= 0
15849 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15852 struct glyph_row
*candidate
=
15853 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15855 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15856 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15859 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15860 || (NILP (g
->object
)
15861 && (g
->charpos
== PT
15862 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15864 if (at_zv_p
|| exact_match_p
)
15866 rc
= CURSOR_MOVEMENT_SUCCESS
;
15870 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15874 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15875 || row
->continued_p
)
15876 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15877 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15878 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15879 /* If we didn't find any candidate rows, or exited the
15880 loop before all the candidates were examined, signal
15881 to the caller that this method failed. */
15882 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15884 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15885 && !row
->continued_p
))
15886 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15888 rc
= CURSOR_MOVEMENT_SUCCESS
;
15894 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15896 rc
= CURSOR_MOVEMENT_SUCCESS
;
15901 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15902 && MATRIX_ROW_START_CHARPOS (row
) == PT
15903 && cursor_row_p (row
));
15913 set_vertical_scroll_bar (struct window
*w
)
15915 ptrdiff_t start
, end
, whole
;
15917 /* Calculate the start and end positions for the current window.
15918 At some point, it would be nice to choose between scrollbars
15919 which reflect the whole buffer size, with special markers
15920 indicating narrowing, and scrollbars which reflect only the
15923 Note that mini-buffers sometimes aren't displaying any text. */
15924 if (!MINI_WINDOW_P (w
)
15925 || (w
== XWINDOW (minibuf_window
)
15926 && NILP (echo_area_buffer
[0])))
15928 struct buffer
*buf
= XBUFFER (w
->contents
);
15929 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15930 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15931 /* I don't think this is guaranteed to be right. For the
15932 moment, we'll pretend it is. */
15933 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15937 if (whole
< (end
- start
))
15938 whole
= end
- start
;
15941 start
= end
= whole
= 0;
15943 /* Indicate what this scroll bar ought to be displaying now. */
15944 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15945 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15946 (w
, end
- start
, whole
, start
);
15951 set_horizontal_scroll_bar (struct window
*w
)
15953 int start
, end
, whole
, portion
;
15955 if (!MINI_WINDOW_P (w
)
15956 || (w
== XWINDOW (minibuf_window
)
15957 && NILP (echo_area_buffer
[0])))
15959 struct buffer
*b
= XBUFFER (w
->contents
);
15960 struct buffer
*old_buffer
= NULL
;
15962 struct text_pos startp
;
15964 if (b
!= current_buffer
)
15966 old_buffer
= current_buffer
;
15967 set_buffer_internal (b
);
15970 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15971 start_display (&it
, w
, startp
);
15972 it
.last_visible_x
= INT_MAX
;
15973 whole
= move_it_to (&it
, -1, INT_MAX
, window_box_height (w
), -1,
15974 MOVE_TO_X
| MOVE_TO_Y
);
15975 /* whole = move_it_to (&it, w->window_end_pos, INT_MAX,
15976 window_box_height (w), -1,
15977 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); */
15979 start
= w
->hscroll
* FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
15980 end
= start
+ window_box_width (w
, TEXT_AREA
);
15981 portion
= end
- start
;
15982 /* After enlarging a horizontally scrolled window such that it
15983 gets at least as wide as the text it contains, make sure that
15984 the thumb doesn't fill the entire scroll bar so we can still
15985 drag it back to see the entire text. */
15986 whole
= max (whole
, end
);
15992 pdir
= Fcurrent_bidi_paragraph_direction (Qnil
);
15993 if (EQ (pdir
, Qright_to_left
))
15995 start
= whole
- end
;
15996 end
= start
+ portion
;
16001 set_buffer_internal (old_buffer
);
16004 start
= end
= whole
= portion
= 0;
16006 w
->hscroll_whole
= whole
;
16008 /* Indicate what this scroll bar ought to be displaying now. */
16009 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
16010 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
16011 (w
, portion
, whole
, start
);
16015 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P means only
16016 selected_window is redisplayed.
16018 We can return without actually redisplaying the window if fonts has been
16019 changed on window's frame. In that case, redisplay_internal will retry.
16021 As one of the important parts of redisplaying a window, we need to
16022 decide whether the previous window-start position (stored in the
16023 window's w->start marker position) is still valid, and if it isn't,
16024 recompute it. Some details about that:
16026 . The previous window-start could be in a continuation line, in
16027 which case we need to recompute it when the window width
16028 changes. See compute_window_start_on_continuation_line and its
16031 . The text that changed since last redisplay could include the
16032 previous window-start position. In that case, we try to salvage
16033 what we can from the current glyph matrix by calling
16034 try_scrolling, which see.
16036 . Some Emacs command could force us to use a specific window-start
16037 position by setting the window's force_start flag, or gently
16038 propose doing that by setting the window's optional_new_start
16039 flag. In these cases, we try using the specified start point if
16040 that succeeds (i.e. the window desired matrix is successfully
16041 recomputed, and point location is within the window). In case
16042 of optional_new_start, we first check if the specified start
16043 position is feasible, i.e. if it will allow point to be
16044 displayed in the window. If using the specified start point
16045 fails, e.g., if new fonts are needed to be loaded, we abort the
16046 redisplay cycle and leave it up to the next cycle to figure out
16049 . Note that the window's force_start flag is sometimes set by
16050 redisplay itself, when it decides that the previous window start
16051 point is fine and should be kept. Search for "goto force_start"
16052 below to see the details. Like the values of window-start
16053 specified outside of redisplay, these internally-deduced values
16054 are tested for feasibility, and ignored if found to be
16057 . Note that the function try_window, used to completely redisplay
16058 a window, accepts the window's start point as its argument.
16059 This is used several times in the redisplay code to control
16060 where the window start will be, according to user options such
16061 as scroll-conservatively, and also to ensure the screen line
16062 showing point will be fully (as opposed to partially) visible on
16066 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
16068 struct window
*w
= XWINDOW (window
);
16069 struct frame
*f
= XFRAME (w
->frame
);
16070 struct buffer
*buffer
= XBUFFER (w
->contents
);
16071 struct buffer
*old
= current_buffer
;
16072 struct text_pos lpoint
, opoint
, startp
;
16073 bool update_mode_line
;
16076 /* Record it now because it's overwritten. */
16077 bool current_matrix_up_to_date_p
= false;
16078 bool used_current_matrix_p
= false;
16079 /* This is less strict than current_matrix_up_to_date_p.
16080 It indicates that the buffer contents and narrowing are unchanged. */
16081 bool buffer_unchanged_p
= false;
16082 bool temp_scroll_step
= false;
16083 ptrdiff_t count
= SPECPDL_INDEX ();
16085 int centering_position
= -1;
16086 bool last_line_misfit
= false;
16087 ptrdiff_t beg_unchanged
, end_unchanged
;
16088 int frame_line_height
;
16090 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16094 *w
->desired_matrix
->method
= 0;
16097 if (!just_this_one_p
16098 && REDISPLAY_SOME_P ()
16100 && !w
->update_mode_line
16103 && !buffer
->text
->redisplay
16104 && BUF_PT (buffer
) == w
->last_point
)
16107 /* Make sure that both W's markers are valid. */
16108 eassert (XMARKER (w
->start
)->buffer
== buffer
);
16109 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
16111 /* We come here again if we need to run window-text-change-functions
16114 reconsider_clip_changes (w
);
16115 frame_line_height
= default_line_pixel_height (w
);
16117 /* Has the mode line to be updated? */
16118 update_mode_line
= (w
->update_mode_line
16119 || update_mode_lines
16120 || buffer
->clip_changed
16121 || buffer
->prevent_redisplay_optimizations_p
);
16123 if (!just_this_one_p
)
16124 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
16125 cleverly elsewhere. */
16126 w
->must_be_updated_p
= true;
16128 if (MINI_WINDOW_P (w
))
16130 if (w
== XWINDOW (echo_area_window
)
16131 && !NILP (echo_area_buffer
[0]))
16133 if (update_mode_line
)
16134 /* We may have to update a tty frame's menu bar or a
16135 tool-bar. Example `M-x C-h C-h C-g'. */
16136 goto finish_menu_bars
;
16138 /* We've already displayed the echo area glyphs in this window. */
16139 goto finish_scroll_bars
;
16141 else if ((w
!= XWINDOW (minibuf_window
)
16142 || minibuf_level
== 0)
16143 /* When buffer is nonempty, redisplay window normally. */
16144 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
16145 /* Quail displays non-mini buffers in minibuffer window.
16146 In that case, redisplay the window normally. */
16147 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
16149 /* W is a mini-buffer window, but it's not active, so clear
16151 int yb
= window_text_bottom_y (w
);
16152 struct glyph_row
*row
;
16155 for (y
= 0, row
= w
->desired_matrix
->rows
;
16157 y
+= row
->height
, ++row
)
16158 blank_row (w
, row
, y
);
16159 goto finish_scroll_bars
;
16162 clear_glyph_matrix (w
->desired_matrix
);
16165 /* Otherwise set up data on this window; select its buffer and point
16167 /* Really select the buffer, for the sake of buffer-local
16169 set_buffer_internal_1 (XBUFFER (w
->contents
));
16171 current_matrix_up_to_date_p
16172 = (w
->window_end_valid
16173 && !current_buffer
->clip_changed
16174 && !current_buffer
->prevent_redisplay_optimizations_p
16175 && !window_outdated (w
));
16177 /* Run the window-text-change-functions
16178 if it is possible that the text on the screen has changed
16179 (either due to modification of the text, or any other reason). */
16180 if (!current_matrix_up_to_date_p
16181 && !NILP (Vwindow_text_change_functions
))
16183 safe_run_hooks (Qwindow_text_change_functions
);
16187 beg_unchanged
= BEG_UNCHANGED
;
16188 end_unchanged
= END_UNCHANGED
;
16190 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
16192 specbind (Qinhibit_point_motion_hooks
, Qt
);
16195 = (w
->window_end_valid
16196 && !current_buffer
->clip_changed
16197 && !window_outdated (w
));
16199 /* When windows_or_buffers_changed is non-zero, we can't rely
16200 on the window end being valid, so set it to zero there. */
16201 if (windows_or_buffers_changed
)
16203 /* If window starts on a continuation line, maybe adjust the
16204 window start in case the window's width changed. */
16205 if (XMARKER (w
->start
)->buffer
== current_buffer
)
16206 compute_window_start_on_continuation_line (w
);
16208 w
->window_end_valid
= false;
16209 /* If so, we also can't rely on current matrix
16210 and should not fool try_cursor_movement below. */
16211 current_matrix_up_to_date_p
= false;
16214 /* Some sanity checks. */
16215 CHECK_WINDOW_END (w
);
16216 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
16218 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
16221 if (mode_line_update_needed (w
))
16222 update_mode_line
= true;
16224 /* Point refers normally to the selected window. For any other
16225 window, set up appropriate value. */
16226 if (!EQ (window
, selected_window
))
16228 ptrdiff_t new_pt
= marker_position (w
->pointm
);
16229 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
16234 new_pt_byte
= BEGV_BYTE
;
16235 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
16237 else if (new_pt
> (ZV
- 1))
16240 new_pt_byte
= ZV_BYTE
;
16241 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
16244 /* We don't use SET_PT so that the point-motion hooks don't run. */
16245 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
16248 /* If any of the character widths specified in the display table
16249 have changed, invalidate the width run cache. It's true that
16250 this may be a bit late to catch such changes, but the rest of
16251 redisplay goes (non-fatally) haywire when the display table is
16252 changed, so why should we worry about doing any better? */
16253 if (current_buffer
->width_run_cache
16254 || (current_buffer
->base_buffer
16255 && current_buffer
->base_buffer
->width_run_cache
))
16257 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
16259 if (! disptab_matches_widthtab
16260 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
16262 struct buffer
*buf
= current_buffer
;
16264 if (buf
->base_buffer
)
16265 buf
= buf
->base_buffer
;
16266 invalidate_region_cache (buf
, buf
->width_run_cache
, BEG
, Z
);
16267 recompute_width_table (current_buffer
, disptab
);
16271 /* If window-start is screwed up, choose a new one. */
16272 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
16275 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16277 /* If someone specified a new starting point but did not insist,
16278 check whether it can be used. */
16279 if ((w
->optional_new_start
|| window_frozen_p (w
))
16280 && CHARPOS (startp
) >= BEGV
16281 && CHARPOS (startp
) <= ZV
)
16283 ptrdiff_t it_charpos
;
16285 w
->optional_new_start
= false;
16286 start_display (&it
, w
, startp
);
16287 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
16288 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
16289 /* Record IT's position now, since line_bottom_y might change
16291 it_charpos
= IT_CHARPOS (it
);
16292 /* Make sure we set the force_start flag only if the cursor row
16293 will be fully visible. Otherwise, the code under force_start
16294 label below will try to move point back into view, which is
16295 not what the code which sets optional_new_start wants. */
16296 if ((it
.current_y
== 0 || line_bottom_y (&it
) < it
.last_visible_y
)
16297 && !w
->force_start
)
16299 if (it_charpos
== PT
)
16300 w
->force_start
= true;
16301 /* IT may overshoot PT if text at PT is invisible. */
16302 else if (it_charpos
> PT
&& CHARPOS (startp
) <= PT
)
16303 w
->force_start
= true;
16305 if (w
->force_start
)
16307 if (window_frozen_p (w
))
16308 debug_method_add (w
, "set force_start from frozen window start");
16310 debug_method_add (w
, "set force_start from optional_new_start");
16318 /* Handle case where place to start displaying has been specified,
16319 unless the specified location is outside the accessible range. */
16320 if (w
->force_start
)
16322 /* We set this later on if we have to adjust point. */
16325 w
->force_start
= false;
16327 w
->window_end_valid
= false;
16329 /* Forget any recorded base line for line number display. */
16330 if (!buffer_unchanged_p
)
16331 w
->base_line_number
= 0;
16333 /* Redisplay the mode line. Select the buffer properly for that.
16334 Also, run the hook window-scroll-functions
16335 because we have scrolled. */
16336 /* Note, we do this after clearing force_start because
16337 if there's an error, it is better to forget about force_start
16338 than to get into an infinite loop calling the hook functions
16339 and having them get more errors. */
16340 if (!update_mode_line
16341 || ! NILP (Vwindow_scroll_functions
))
16343 update_mode_line
= true;
16344 w
->update_mode_line
= true;
16345 startp
= run_window_scroll_functions (window
, startp
);
16348 if (CHARPOS (startp
) < BEGV
)
16349 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
16350 else if (CHARPOS (startp
) > ZV
)
16351 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
16353 /* Redisplay, then check if cursor has been set during the
16354 redisplay. Give up if new fonts were loaded. */
16355 /* We used to issue a CHECK_MARGINS argument to try_window here,
16356 but this causes scrolling to fail when point begins inside
16357 the scroll margin (bug#148) -- cyd */
16358 if (!try_window (window
, startp
, 0))
16360 w
->force_start
= true;
16361 clear_glyph_matrix (w
->desired_matrix
);
16362 goto need_larger_matrices
;
16365 if (w
->cursor
.vpos
< 0)
16367 /* If point does not appear, try to move point so it does
16368 appear. The desired matrix has been built above, so we
16369 can use it here. First see if point is in invisible
16370 text, and if so, move it to the first visible buffer
16371 position past that. */
16372 struct glyph_row
*r
= NULL
;
16373 Lisp_Object invprop
=
16374 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16377 if (TEXT_PROP_MEANS_INVISIBLE (invprop
) != 0)
16380 Lisp_Object invprop_end
=
16381 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16384 if (NATNUMP (invprop_end
))
16385 alt_pt
= XFASTINT (invprop_end
);
16388 r
= row_containing_pos (w
, alt_pt
, w
->desired_matrix
->rows
,
16392 new_vpos
= MATRIX_ROW_BOTTOM_Y (r
);
16393 else /* Give up and just move to the middle of the window. */
16394 new_vpos
= window_box_height (w
) / 2;
16397 if (!cursor_row_fully_visible_p (w
, false, false))
16399 /* Point does appear, but on a line partly visible at end of window.
16400 Move it back to a fully-visible line. */
16401 new_vpos
= window_box_height (w
);
16402 /* But if window_box_height suggests a Y coordinate that is
16403 not less than we already have, that line will clearly not
16404 be fully visible, so give up and scroll the display.
16405 This can happen when the default face uses a font whose
16406 dimensions are different from the frame's default
16408 if (new_vpos
>= w
->cursor
.y
)
16410 w
->cursor
.vpos
= -1;
16411 clear_glyph_matrix (w
->desired_matrix
);
16412 goto try_to_scroll
;
16415 else if (w
->cursor
.vpos
>= 0)
16417 /* Some people insist on not letting point enter the scroll
16418 margin, even though this part handles windows that didn't
16420 int window_total_lines
16421 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16422 int margin
= min (scroll_margin
, window_total_lines
/ 4);
16423 int pixel_margin
= margin
* frame_line_height
;
16424 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
16426 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
16427 below, which finds the row to move point to, advances by
16428 the Y coordinate of the _next_ row, see the definition of
16429 MATRIX_ROW_BOTTOM_Y. */
16430 if (w
->cursor
.vpos
< margin
+ header_line
)
16432 w
->cursor
.vpos
= -1;
16433 clear_glyph_matrix (w
->desired_matrix
);
16434 goto try_to_scroll
;
16438 int window_height
= window_box_height (w
);
16441 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
16442 if (w
->cursor
.y
>= window_height
- pixel_margin
)
16444 w
->cursor
.vpos
= -1;
16445 clear_glyph_matrix (w
->desired_matrix
);
16446 goto try_to_scroll
;
16451 /* If we need to move point for either of the above reasons,
16452 now actually do it. */
16455 struct glyph_row
*row
;
16457 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
16458 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
16461 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
16462 MATRIX_ROW_START_BYTEPOS (row
));
16464 if (w
!= XWINDOW (selected_window
))
16465 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
16466 else if (current_buffer
== old
)
16467 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16469 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
16471 /* Re-run pre-redisplay-function so it can update the region
16472 according to the new position of point. */
16473 /* Other than the cursor, w's redisplay is done so we can set its
16474 redisplay to false. Also the buffer's redisplay can be set to
16475 false, since propagate_buffer_redisplay should have already
16476 propagated its info to `w' anyway. */
16477 w
->redisplay
= false;
16478 XBUFFER (w
->contents
)->text
->redisplay
= false;
16479 safe__call1 (true, Vpre_redisplay_function
, Fcons (window
, Qnil
));
16481 if (w
->redisplay
|| XBUFFER (w
->contents
)->text
->redisplay
)
16483 /* pre-redisplay-function made changes (e.g. move the region)
16484 that require another round of redisplay. */
16485 clear_glyph_matrix (w
->desired_matrix
);
16486 if (!try_window (window
, startp
, 0))
16487 goto need_larger_matrices
;
16490 if (w
->cursor
.vpos
< 0 || !cursor_row_fully_visible_p (w
, false, false))
16492 clear_glyph_matrix (w
->desired_matrix
);
16493 goto try_to_scroll
;
16497 debug_method_add (w
, "forced window start");
16502 /* Handle case where text has not changed, only point, and it has
16503 not moved off the frame, and we are not retrying after hscroll.
16504 (current_matrix_up_to_date_p is true when retrying.) */
16505 if (current_matrix_up_to_date_p
16506 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
16507 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
16511 case CURSOR_MOVEMENT_SUCCESS
:
16512 used_current_matrix_p
= true;
16515 case CURSOR_MOVEMENT_MUST_SCROLL
:
16516 goto try_to_scroll
;
16522 /* If current starting point was originally the beginning of a line
16523 but no longer is, find a new starting point. */
16524 else if (w
->start_at_line_beg
16525 && !(CHARPOS (startp
) <= BEGV
16526 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
16529 debug_method_add (w
, "recenter 1");
16534 /* Try scrolling with try_window_id. Value is > 0 if update has
16535 been done, it is -1 if we know that the same window start will
16536 not work. It is 0 if unsuccessful for some other reason. */
16537 else if ((tem
= try_window_id (w
)) != 0)
16540 debug_method_add (w
, "try_window_id %d", tem
);
16543 if (f
->fonts_changed
)
16544 goto need_larger_matrices
;
16548 /* Otherwise try_window_id has returned -1 which means that we
16549 don't want the alternative below this comment to execute. */
16551 else if (CHARPOS (startp
) >= BEGV
16552 && CHARPOS (startp
) <= ZV
16553 && PT
>= CHARPOS (startp
)
16554 && (CHARPOS (startp
) < ZV
16555 /* Avoid starting at end of buffer. */
16556 || CHARPOS (startp
) == BEGV
16557 || !window_outdated (w
)))
16559 int d1
, d2
, d5
, d6
;
16562 /* If first window line is a continuation line, and window start
16563 is inside the modified region, but the first change is before
16564 current window start, we must select a new window start.
16566 However, if this is the result of a down-mouse event (e.g. by
16567 extending the mouse-drag-overlay), we don't want to select a
16568 new window start, since that would change the position under
16569 the mouse, resulting in an unwanted mouse-movement rather
16570 than a simple mouse-click. */
16571 if (!w
->start_at_line_beg
16572 && NILP (do_mouse_tracking
)
16573 && CHARPOS (startp
) > BEGV
16574 && CHARPOS (startp
) > BEG
+ beg_unchanged
16575 && CHARPOS (startp
) <= Z
- end_unchanged
16576 /* Even if w->start_at_line_beg is nil, a new window may
16577 start at a line_beg, since that's how set_buffer_window
16578 sets it. So, we need to check the return value of
16579 compute_window_start_on_continuation_line. (See also
16581 && XMARKER (w
->start
)->buffer
== current_buffer
16582 && compute_window_start_on_continuation_line (w
)
16583 /* It doesn't make sense to force the window start like we
16584 do at label force_start if it is already known that point
16585 will not be fully visible in the resulting window, because
16586 doing so will move point from its correct position
16587 instead of scrolling the window to bring point into view.
16589 && pos_visible_p (w
, PT
, &d1
, &d2
, &rtop
, &rbot
, &d5
, &d6
)
16590 /* A very tall row could need more than the window height,
16591 in which case we accept that it is partially visible. */
16592 && (rtop
!= 0) == (rbot
!= 0))
16594 w
->force_start
= true;
16595 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16597 debug_method_add (w
, "recomputed window start in continuation line");
16603 debug_method_add (w
, "same window start");
16606 /* Try to redisplay starting at same place as before.
16607 If point has not moved off frame, accept the results. */
16608 if (!current_matrix_up_to_date_p
16609 /* Don't use try_window_reusing_current_matrix in this case
16610 because a window scroll function can have changed the
16612 || !NILP (Vwindow_scroll_functions
)
16613 || MINI_WINDOW_P (w
)
16614 || !(used_current_matrix_p
16615 = try_window_reusing_current_matrix (w
)))
16617 IF_DEBUG (debug_method_add (w
, "1"));
16618 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16619 /* -1 means we need to scroll.
16620 0 means we need new matrices, but fonts_changed
16621 is set in that case, so we will detect it below. */
16622 goto try_to_scroll
;
16625 if (f
->fonts_changed
)
16626 goto need_larger_matrices
;
16628 if (w
->cursor
.vpos
>= 0)
16630 if (!just_this_one_p
16631 || current_buffer
->clip_changed
16632 || BEG_UNCHANGED
< CHARPOS (startp
))
16633 /* Forget any recorded base line for line number display. */
16634 w
->base_line_number
= 0;
16636 if (!cursor_row_fully_visible_p (w
, true, false))
16638 clear_glyph_matrix (w
->desired_matrix
);
16639 last_line_misfit
= true;
16641 /* Drop through and scroll. */
16646 clear_glyph_matrix (w
->desired_matrix
);
16651 /* Redisplay the mode line. Select the buffer properly for that. */
16652 if (!update_mode_line
)
16654 update_mode_line
= true;
16655 w
->update_mode_line
= true;
16658 /* Try to scroll by specified few lines. */
16659 if ((scroll_conservatively
16660 || emacs_scroll_step
16661 || temp_scroll_step
16662 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16663 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16664 && CHARPOS (startp
) >= BEGV
16665 && CHARPOS (startp
) <= ZV
)
16667 /* The function returns -1 if new fonts were loaded, 1 if
16668 successful, 0 if not successful. */
16669 int ss
= try_scrolling (window
, just_this_one_p
,
16670 scroll_conservatively
,
16672 temp_scroll_step
, last_line_misfit
);
16675 case SCROLLING_SUCCESS
:
16678 case SCROLLING_NEED_LARGER_MATRICES
:
16679 goto need_larger_matrices
;
16681 case SCROLLING_FAILED
:
16689 /* Finally, just choose a place to start which positions point
16690 according to user preferences. */
16695 debug_method_add (w
, "recenter");
16698 /* Forget any previously recorded base line for line number display. */
16699 if (!buffer_unchanged_p
)
16700 w
->base_line_number
= 0;
16702 /* Determine the window start relative to point. */
16703 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16704 it
.current_y
= it
.last_visible_y
;
16705 if (centering_position
< 0)
16707 int window_total_lines
16708 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16710 = scroll_margin
> 0
16711 ? min (scroll_margin
, window_total_lines
/ 4)
16713 ptrdiff_t margin_pos
= CHARPOS (startp
);
16714 Lisp_Object aggressive
;
16717 /* If there is a scroll margin at the top of the window, find
16718 its character position. */
16720 /* Cannot call start_display if startp is not in the
16721 accessible region of the buffer. This can happen when we
16722 have just switched to a different buffer and/or changed
16723 its restriction. In that case, startp is initialized to
16724 the character position 1 (BEGV) because we did not yet
16725 have chance to display the buffer even once. */
16726 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16729 void *it1data
= NULL
;
16731 SAVE_IT (it1
, it
, it1data
);
16732 start_display (&it1
, w
, startp
);
16733 move_it_vertically (&it1
, margin
* frame_line_height
);
16734 margin_pos
= IT_CHARPOS (it1
);
16735 RESTORE_IT (&it
, &it
, it1data
);
16737 scrolling_up
= PT
> margin_pos
;
16740 ? BVAR (current_buffer
, scroll_up_aggressively
)
16741 : BVAR (current_buffer
, scroll_down_aggressively
);
16743 if (!MINI_WINDOW_P (w
)
16744 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16748 /* Setting scroll-conservatively overrides
16749 scroll-*-aggressively. */
16750 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16752 double float_amount
= XFLOATINT (aggressive
);
16754 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16755 if (pt_offset
== 0 && float_amount
> 0)
16757 if (pt_offset
&& margin
> 0)
16760 /* Compute how much to move the window start backward from
16761 point so that point will be displayed where the user
16765 centering_position
= it
.last_visible_y
;
16767 centering_position
-= pt_offset
;
16768 centering_position
-=
16769 (frame_line_height
* (1 + margin
+ last_line_misfit
)
16770 + WINDOW_HEADER_LINE_HEIGHT (w
));
16771 /* Don't let point enter the scroll margin near top of
16773 if (centering_position
< margin
* frame_line_height
)
16774 centering_position
= margin
* frame_line_height
;
16777 centering_position
= margin
* frame_line_height
+ pt_offset
;
16780 /* Set the window start half the height of the window backward
16782 centering_position
= window_box_height (w
) / 2;
16784 move_it_vertically_backward (&it
, centering_position
);
16786 eassert (IT_CHARPOS (it
) >= BEGV
);
16788 /* The function move_it_vertically_backward may move over more
16789 than the specified y-distance. If it->w is small, e.g. a
16790 mini-buffer window, we may end up in front of the window's
16791 display area. Start displaying at the start of the line
16792 containing PT in this case. */
16793 if (it
.current_y
<= 0)
16795 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16796 move_it_vertically_backward (&it
, 0);
16800 it
.current_x
= it
.hpos
= 0;
16802 /* Set the window start position here explicitly, to avoid an
16803 infinite loop in case the functions in window-scroll-functions
16805 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16807 /* Run scroll hooks. */
16808 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16810 /* Redisplay the window. */
16811 bool use_desired_matrix
= false;
16812 if (!current_matrix_up_to_date_p
16813 || windows_or_buffers_changed
16814 || f
->cursor_type_changed
16815 /* Don't use try_window_reusing_current_matrix in this case
16816 because it can have changed the buffer. */
16817 || !NILP (Vwindow_scroll_functions
)
16818 || !just_this_one_p
16819 || MINI_WINDOW_P (w
)
16820 || !(used_current_matrix_p
16821 = try_window_reusing_current_matrix (w
)))
16822 use_desired_matrix
= (try_window (window
, startp
, 0) == 1);
16824 /* If new fonts have been loaded (due to fontsets), give up. We
16825 have to start a new redisplay since we need to re-adjust glyph
16827 if (f
->fonts_changed
)
16828 goto need_larger_matrices
;
16830 /* If cursor did not appear assume that the middle of the window is
16831 in the first line of the window. Do it again with the next line.
16832 (Imagine a window of height 100, displaying two lines of height
16833 60. Moving back 50 from it->last_visible_y will end in the first
16835 if (w
->cursor
.vpos
< 0)
16837 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16839 clear_glyph_matrix (w
->desired_matrix
);
16840 move_it_by_lines (&it
, 1);
16841 try_window (window
, it
.current
.pos
, 0);
16843 else if (PT
< IT_CHARPOS (it
))
16845 clear_glyph_matrix (w
->desired_matrix
);
16846 move_it_by_lines (&it
, -1);
16847 try_window (window
, it
.current
.pos
, 0);
16851 /* Not much we can do about it. */
16855 /* Consider the following case: Window starts at BEGV, there is
16856 invisible, intangible text at BEGV, so that display starts at
16857 some point START > BEGV. It can happen that we are called with
16858 PT somewhere between BEGV and START. Try to handle that case,
16859 and similar ones. */
16860 if (w
->cursor
.vpos
< 0)
16862 /* Prefer the desired matrix to the current matrix, if possible,
16863 in the fallback calculations below. This is because using
16864 the current matrix might completely goof, e.g. if its first
16865 row is after point. */
16866 struct glyph_matrix
*matrix
=
16867 use_desired_matrix
? w
->desired_matrix
: w
->current_matrix
;
16868 /* First, try locating the proper glyph row for PT. */
16869 struct glyph_row
*row
=
16870 row_containing_pos (w
, PT
, matrix
->rows
, NULL
, 0);
16872 /* Sometimes point is at the beginning of invisible text that is
16873 before the 1st character displayed in the row. In that case,
16874 row_containing_pos fails to find the row, because no glyphs
16875 with appropriate buffer positions are present in the row.
16876 Therefore, we next try to find the row which shows the 1st
16877 position after the invisible text. */
16881 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16884 if (TEXT_PROP_MEANS_INVISIBLE (val
) != 0)
16887 Lisp_Object invis_end
=
16888 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16891 if (NATNUMP (invis_end
))
16892 alt_pos
= XFASTINT (invis_end
);
16895 row
= row_containing_pos (w
, alt_pos
, matrix
->rows
, NULL
, 0);
16898 /* Finally, fall back on the first row of the window after the
16899 header line (if any). This is slightly better than not
16900 displaying the cursor at all. */
16903 row
= matrix
->rows
;
16904 if (row
->mode_line_p
)
16907 set_cursor_from_row (w
, row
, matrix
, 0, 0, 0, 0);
16910 if (!cursor_row_fully_visible_p (w
, false, false))
16912 /* If vscroll is enabled, disable it and try again. */
16916 clear_glyph_matrix (w
->desired_matrix
);
16920 /* Users who set scroll-conservatively to a large number want
16921 point just above/below the scroll margin. If we ended up
16922 with point's row partially visible, move the window start to
16923 make that row fully visible and out of the margin. */
16924 if (scroll_conservatively
> SCROLL_LIMIT
)
16926 int window_total_lines
16927 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16930 ? min (scroll_margin
, window_total_lines
/ 4)
16932 bool move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16934 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16935 clear_glyph_matrix (w
->desired_matrix
);
16936 if (1 == try_window (window
, it
.current
.pos
,
16937 TRY_WINDOW_CHECK_MARGINS
))
16941 /* If centering point failed to make the whole line visible,
16942 put point at the top instead. That has to make the whole line
16943 visible, if it can be done. */
16944 if (centering_position
== 0)
16947 clear_glyph_matrix (w
->desired_matrix
);
16948 centering_position
= 0;
16954 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16955 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16956 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16958 /* Display the mode line, if we must. */
16959 if ((update_mode_line
16960 /* If window not full width, must redo its mode line
16961 if (a) the window to its side is being redone and
16962 (b) we do a frame-based redisplay. This is a consequence
16963 of how inverted lines are drawn in frame-based redisplay. */
16964 || (!just_this_one_p
16965 && !FRAME_WINDOW_P (f
)
16966 && !WINDOW_FULL_WIDTH_P (w
))
16967 /* Line number to display. */
16968 || w
->base_line_pos
> 0
16969 /* Column number is displayed and different from the one displayed. */
16970 || (w
->column_number_displayed
!= -1
16971 && (w
->column_number_displayed
!= current_column ())))
16972 /* This means that the window has a mode line. */
16973 && (WINDOW_WANTS_MODELINE_P (w
)
16974 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16977 display_mode_lines (w
);
16979 /* If mode line height has changed, arrange for a thorough
16980 immediate redisplay using the correct mode line height. */
16981 if (WINDOW_WANTS_MODELINE_P (w
)
16982 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16984 f
->fonts_changed
= true;
16985 w
->mode_line_height
= -1;
16986 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16987 = DESIRED_MODE_LINE_HEIGHT (w
);
16990 /* If header line height has changed, arrange for a thorough
16991 immediate redisplay using the correct header line height. */
16992 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16993 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16995 f
->fonts_changed
= true;
16996 w
->header_line_height
= -1;
16997 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16998 = DESIRED_HEADER_LINE_HEIGHT (w
);
17001 if (f
->fonts_changed
)
17002 goto need_larger_matrices
;
17005 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
17007 w
->base_line_pos
= 0;
17008 w
->base_line_number
= 0;
17013 /* When we reach a frame's selected window, redo the frame's menu
17014 bar and the frame's title. */
17015 if (update_mode_line
17016 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
17018 bool redisplay_menu_p
;
17020 if (FRAME_WINDOW_P (f
))
17022 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
17023 || defined (HAVE_NS) || defined (USE_GTK)
17024 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
17026 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
17030 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
17032 if (redisplay_menu_p
)
17033 display_menu_bar (w
);
17035 #ifdef HAVE_WINDOW_SYSTEM
17036 if (FRAME_WINDOW_P (f
))
17038 #if defined (USE_GTK) || defined (HAVE_NS)
17039 if (FRAME_EXTERNAL_TOOL_BAR (f
))
17040 redisplay_tool_bar (f
);
17042 if (WINDOWP (f
->tool_bar_window
)
17043 && (FRAME_TOOL_BAR_LINES (f
) > 0
17044 || !NILP (Vauto_resize_tool_bars
))
17045 && redisplay_tool_bar (f
))
17046 ignore_mouse_drag_p
= true;
17049 x_consider_frame_title (w
->frame
);
17053 #ifdef HAVE_WINDOW_SYSTEM
17054 if (FRAME_WINDOW_P (f
)
17055 && update_window_fringes (w
, (just_this_one_p
17056 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
17057 || w
->pseudo_window_p
)))
17061 if (draw_window_fringes (w
, true))
17063 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
17064 x_draw_right_divider (w
);
17066 x_draw_vertical_border (w
);
17072 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
17073 x_draw_bottom_divider (w
);
17074 #endif /* HAVE_WINDOW_SYSTEM */
17076 /* We go to this label, with fonts_changed set, if it is
17077 necessary to try again using larger glyph matrices.
17078 We have to redeem the scroll bar even in this case,
17079 because the loop in redisplay_internal expects that. */
17080 need_larger_matrices
:
17082 finish_scroll_bars
:
17084 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
) || WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
17086 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
17087 /* Set the thumb's position and size. */
17088 set_vertical_scroll_bar (w
);
17090 if (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
17091 /* Set the thumb's position and size. */
17092 set_horizontal_scroll_bar (w
);
17094 /* Note that we actually used the scroll bar attached to this
17095 window, so it shouldn't be deleted at the end of redisplay. */
17096 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
17097 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
17100 /* Restore current_buffer and value of point in it. The window
17101 update may have changed the buffer, so first make sure `opoint'
17102 is still valid (Bug#6177). */
17103 if (CHARPOS (opoint
) < BEGV
)
17104 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17105 else if (CHARPOS (opoint
) > ZV
)
17106 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
17108 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
17110 set_buffer_internal_1 (old
);
17111 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
17112 shorter. This can be caused by log truncation in *Messages*. */
17113 if (CHARPOS (lpoint
) <= ZV
)
17114 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17116 unbind_to (count
, Qnil
);
17120 /* Build the complete desired matrix of WINDOW with a window start
17121 buffer position POS.
17123 Value is 1 if successful. It is zero if fonts were loaded during
17124 redisplay which makes re-adjusting glyph matrices necessary, and -1
17125 if point would appear in the scroll margins.
17126 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
17127 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
17131 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
17133 struct window
*w
= XWINDOW (window
);
17135 struct glyph_row
*last_text_row
= NULL
;
17136 struct frame
*f
= XFRAME (w
->frame
);
17137 int frame_line_height
= default_line_pixel_height (w
);
17139 /* Make POS the new window start. */
17140 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
17142 /* Mark cursor position as unknown. No overlay arrow seen. */
17143 w
->cursor
.vpos
= -1;
17144 overlay_arrow_seen
= false;
17146 /* Initialize iterator and info to start at POS. */
17147 start_display (&it
, w
, pos
);
17148 it
.glyph_row
->reversed_p
= false;
17150 /* Display all lines of W. */
17151 while (it
.current_y
< it
.last_visible_y
)
17153 if (display_line (&it
))
17154 last_text_row
= it
.glyph_row
- 1;
17155 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
17159 /* Don't let the cursor end in the scroll margins. */
17160 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
17161 && !MINI_WINDOW_P (w
))
17163 int this_scroll_margin
;
17164 int window_total_lines
17165 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
17167 if (scroll_margin
> 0)
17169 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
17170 this_scroll_margin
*= frame_line_height
;
17173 this_scroll_margin
= 0;
17175 if ((w
->cursor
.y
>= 0 /* not vscrolled */
17176 && w
->cursor
.y
< this_scroll_margin
17177 && CHARPOS (pos
) > BEGV
17178 && IT_CHARPOS (it
) < ZV
)
17179 /* rms: considering make_cursor_line_fully_visible_p here
17180 seems to give wrong results. We don't want to recenter
17181 when the last line is partly visible, we want to allow
17182 that case to be handled in the usual way. */
17183 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
17185 w
->cursor
.vpos
= -1;
17186 clear_glyph_matrix (w
->desired_matrix
);
17191 /* If bottom moved off end of frame, change mode line percentage. */
17192 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
17193 w
->update_mode_line
= true;
17195 /* Set window_end_pos to the offset of the last character displayed
17196 on the window from the end of current_buffer. Set
17197 window_end_vpos to its row number. */
17200 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
17201 adjust_window_ends (w
, last_text_row
, false);
17203 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
17204 w
->window_end_vpos
)));
17208 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17209 w
->window_end_pos
= Z
- ZV
;
17210 w
->window_end_vpos
= 0;
17213 /* But that is not valid info until redisplay finishes. */
17214 w
->window_end_valid
= false;
17220 /************************************************************************
17221 Window redisplay reusing current matrix when buffer has not changed
17222 ************************************************************************/
17224 /* Try redisplay of window W showing an unchanged buffer with a
17225 different window start than the last time it was displayed by
17226 reusing its current matrix. Value is true if successful.
17227 W->start is the new window start. */
17230 try_window_reusing_current_matrix (struct window
*w
)
17232 struct frame
*f
= XFRAME (w
->frame
);
17233 struct glyph_row
*bottom_row
;
17236 struct text_pos start
, new_start
;
17237 int nrows_scrolled
, i
;
17238 struct glyph_row
*last_text_row
;
17239 struct glyph_row
*last_reused_text_row
;
17240 struct glyph_row
*start_row
;
17241 int start_vpos
, min_y
, max_y
;
17244 if (inhibit_try_window_reusing
)
17248 if (/* This function doesn't handle terminal frames. */
17249 !FRAME_WINDOW_P (f
)
17250 /* Don't try to reuse the display if windows have been split
17252 || windows_or_buffers_changed
17253 || f
->cursor_type_changed
)
17256 /* Can't do this if showing trailing whitespace. */
17257 if (!NILP (Vshow_trailing_whitespace
))
17260 /* If top-line visibility has changed, give up. */
17261 if (WINDOW_WANTS_HEADER_LINE_P (w
)
17262 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
17265 /* Give up if old or new display is scrolled vertically. We could
17266 make this function handle this, but right now it doesn't. */
17267 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17268 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
17271 /* The variable new_start now holds the new window start. The old
17272 start `start' can be determined from the current matrix. */
17273 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
17274 start
= start_row
->minpos
;
17275 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17277 /* Clear the desired matrix for the display below. */
17278 clear_glyph_matrix (w
->desired_matrix
);
17280 if (CHARPOS (new_start
) <= CHARPOS (start
))
17282 /* Don't use this method if the display starts with an ellipsis
17283 displayed for invisible text. It's not easy to handle that case
17284 below, and it's certainly not worth the effort since this is
17285 not a frequent case. */
17286 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
17289 IF_DEBUG (debug_method_add (w
, "twu1"));
17291 /* Display up to a row that can be reused. The variable
17292 last_text_row is set to the last row displayed that displays
17293 text. Note that it.vpos == 0 if or if not there is a
17294 header-line; it's not the same as the MATRIX_ROW_VPOS! */
17295 start_display (&it
, w
, new_start
);
17296 w
->cursor
.vpos
= -1;
17297 last_text_row
= last_reused_text_row
= NULL
;
17299 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17301 /* If we have reached into the characters in the START row,
17302 that means the line boundaries have changed. So we
17303 can't start copying with the row START. Maybe it will
17304 work to start copying with the following row. */
17305 while (IT_CHARPOS (it
) > CHARPOS (start
))
17307 /* Advance to the next row as the "start". */
17309 start
= start_row
->minpos
;
17310 /* If there are no more rows to try, or just one, give up. */
17311 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
17312 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
17313 || CHARPOS (start
) == ZV
)
17315 clear_glyph_matrix (w
->desired_matrix
);
17319 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17321 /* If we have reached alignment, we can copy the rest of the
17323 if (IT_CHARPOS (it
) == CHARPOS (start
)
17324 /* Don't accept "alignment" inside a display vector,
17325 since start_row could have started in the middle of
17326 that same display vector (thus their character
17327 positions match), and we have no way of telling if
17328 that is the case. */
17329 && it
.current
.dpvec_index
< 0)
17332 it
.glyph_row
->reversed_p
= false;
17333 if (display_line (&it
))
17334 last_text_row
= it
.glyph_row
- 1;
17338 /* A value of current_y < last_visible_y means that we stopped
17339 at the previous window start, which in turn means that we
17340 have at least one reusable row. */
17341 if (it
.current_y
< it
.last_visible_y
)
17343 struct glyph_row
*row
;
17345 /* IT.vpos always starts from 0; it counts text lines. */
17346 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
17348 /* Find PT if not already found in the lines displayed. */
17349 if (w
->cursor
.vpos
< 0)
17351 int dy
= it
.current_y
- start_row
->y
;
17353 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17354 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
17356 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
17357 dy
, nrows_scrolled
);
17360 clear_glyph_matrix (w
->desired_matrix
);
17365 /* Scroll the display. Do it before the current matrix is
17366 changed. The problem here is that update has not yet
17367 run, i.e. part of the current matrix is not up to date.
17368 scroll_run_hook will clear the cursor, and use the
17369 current matrix to get the height of the row the cursor is
17371 run
.current_y
= start_row
->y
;
17372 run
.desired_y
= it
.current_y
;
17373 run
.height
= it
.last_visible_y
- it
.current_y
;
17375 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
17378 FRAME_RIF (f
)->update_window_begin_hook (w
);
17379 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17380 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17381 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17385 /* Shift current matrix down by nrows_scrolled lines. */
17386 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17387 rotate_matrix (w
->current_matrix
,
17389 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17392 /* Disable lines that must be updated. */
17393 for (i
= 0; i
< nrows_scrolled
; ++i
)
17394 (start_row
+ i
)->enabled_p
= false;
17396 /* Re-compute Y positions. */
17397 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17398 max_y
= it
.last_visible_y
;
17399 for (row
= start_row
+ nrows_scrolled
;
17403 row
->y
= it
.current_y
;
17404 row
->visible_height
= row
->height
;
17406 if (row
->y
< min_y
)
17407 row
->visible_height
-= min_y
- row
->y
;
17408 if (row
->y
+ row
->height
> max_y
)
17409 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17410 if (row
->fringe_bitmap_periodic_p
)
17411 row
->redraw_fringe_bitmaps_p
= true;
17413 it
.current_y
+= row
->height
;
17415 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17416 last_reused_text_row
= row
;
17417 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
17421 /* Disable lines in the current matrix which are now
17422 below the window. */
17423 for (++row
; row
< bottom_row
; ++row
)
17424 row
->enabled_p
= row
->mode_line_p
= false;
17427 /* Update window_end_pos etc.; last_reused_text_row is the last
17428 reused row from the current matrix containing text, if any.
17429 The value of last_text_row is the last displayed line
17430 containing text. */
17431 if (last_reused_text_row
)
17432 adjust_window_ends (w
, last_reused_text_row
, true);
17433 else if (last_text_row
)
17434 adjust_window_ends (w
, last_text_row
, false);
17437 /* This window must be completely empty. */
17438 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17439 w
->window_end_pos
= Z
- ZV
;
17440 w
->window_end_vpos
= 0;
17442 w
->window_end_valid
= false;
17444 /* Update hint: don't try scrolling again in update_window. */
17445 w
->desired_matrix
->no_scrolling_p
= true;
17448 debug_method_add (w
, "try_window_reusing_current_matrix 1");
17452 else if (CHARPOS (new_start
) > CHARPOS (start
))
17454 struct glyph_row
*pt_row
, *row
;
17455 struct glyph_row
*first_reusable_row
;
17456 struct glyph_row
*first_row_to_display
;
17458 int yb
= window_text_bottom_y (w
);
17460 /* Find the row starting at new_start, if there is one. Don't
17461 reuse a partially visible line at the end. */
17462 first_reusable_row
= start_row
;
17463 while (first_reusable_row
->enabled_p
17464 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
17465 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17466 < CHARPOS (new_start
)))
17467 ++first_reusable_row
;
17469 /* Give up if there is no row to reuse. */
17470 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
17471 || !first_reusable_row
->enabled_p
17472 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17473 != CHARPOS (new_start
)))
17476 /* We can reuse fully visible rows beginning with
17477 first_reusable_row to the end of the window. Set
17478 first_row_to_display to the first row that cannot be reused.
17479 Set pt_row to the row containing point, if there is any. */
17481 for (first_row_to_display
= first_reusable_row
;
17482 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
17483 ++first_row_to_display
)
17485 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
17486 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17487 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17488 && first_row_to_display
->ends_at_zv_p
17489 && pt_row
== NULL
)))
17490 pt_row
= first_row_to_display
;
17493 /* Start displaying at the start of first_row_to_display. */
17494 eassert (first_row_to_display
->y
< yb
);
17495 init_to_row_start (&it
, w
, first_row_to_display
);
17497 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
17499 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
17501 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
17502 + WINDOW_HEADER_LINE_HEIGHT (w
));
17504 /* Display lines beginning with first_row_to_display in the
17505 desired matrix. Set last_text_row to the last row displayed
17506 that displays text. */
17507 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
17508 if (pt_row
== NULL
)
17509 w
->cursor
.vpos
= -1;
17510 last_text_row
= NULL
;
17511 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17512 if (display_line (&it
))
17513 last_text_row
= it
.glyph_row
- 1;
17515 /* If point is in a reused row, adjust y and vpos of the cursor
17519 w
->cursor
.vpos
-= nrows_scrolled
;
17520 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
17523 /* Give up if point isn't in a row displayed or reused. (This
17524 also handles the case where w->cursor.vpos < nrows_scrolled
17525 after the calls to display_line, which can happen with scroll
17526 margins. See bug#1295.) */
17527 if (w
->cursor
.vpos
< 0)
17529 clear_glyph_matrix (w
->desired_matrix
);
17533 /* Scroll the display. */
17534 run
.current_y
= first_reusable_row
->y
;
17535 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17536 run
.height
= it
.last_visible_y
- run
.current_y
;
17537 dy
= run
.current_y
- run
.desired_y
;
17542 FRAME_RIF (f
)->update_window_begin_hook (w
);
17543 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17544 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17545 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17549 /* Adjust Y positions of reused rows. */
17550 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17551 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17552 max_y
= it
.last_visible_y
;
17553 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
17556 row
->visible_height
= row
->height
;
17557 if (row
->y
< min_y
)
17558 row
->visible_height
-= min_y
- row
->y
;
17559 if (row
->y
+ row
->height
> max_y
)
17560 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17561 if (row
->fringe_bitmap_periodic_p
)
17562 row
->redraw_fringe_bitmaps_p
= true;
17565 /* Scroll the current matrix. */
17566 eassert (nrows_scrolled
> 0);
17567 rotate_matrix (w
->current_matrix
,
17569 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17572 /* Disable rows not reused. */
17573 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
17574 row
->enabled_p
= false;
17576 /* Point may have moved to a different line, so we cannot assume that
17577 the previous cursor position is valid; locate the correct row. */
17580 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
17582 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
17583 && !row
->ends_at_zv_p
;
17587 w
->cursor
.y
= row
->y
;
17589 if (row
< bottom_row
)
17591 /* Can't simply scan the row for point with
17592 bidi-reordered glyph rows. Let set_cursor_from_row
17593 figure out where to put the cursor, and if it fails,
17595 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
17597 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
17600 clear_glyph_matrix (w
->desired_matrix
);
17606 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
17607 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17610 && (!BUFFERP (glyph
->object
)
17611 || glyph
->charpos
< PT
);
17615 w
->cursor
.x
+= glyph
->pixel_width
;
17621 /* Adjust window end. A null value of last_text_row means that
17622 the window end is in reused rows which in turn means that
17623 only its vpos can have changed. */
17625 adjust_window_ends (w
, last_text_row
, false);
17627 w
->window_end_vpos
-= nrows_scrolled
;
17629 w
->window_end_valid
= false;
17630 w
->desired_matrix
->no_scrolling_p
= true;
17633 debug_method_add (w
, "try_window_reusing_current_matrix 2");
17643 /************************************************************************
17644 Window redisplay reusing current matrix when buffer has changed
17645 ************************************************************************/
17647 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
17648 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17649 ptrdiff_t *, ptrdiff_t *);
17650 static struct glyph_row
*
17651 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17652 struct glyph_row
*);
17655 /* Return the last row in MATRIX displaying text. If row START is
17656 non-null, start searching with that row. IT gives the dimensions
17657 of the display. Value is null if matrix is empty; otherwise it is
17658 a pointer to the row found. */
17660 static struct glyph_row
*
17661 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17662 struct glyph_row
*start
)
17664 struct glyph_row
*row
, *row_found
;
17666 /* Set row_found to the last row in IT->w's current matrix
17667 displaying text. The loop looks funny but think of partially
17670 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17671 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17673 eassert (row
->enabled_p
);
17675 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17684 /* Return the last row in the current matrix of W that is not affected
17685 by changes at the start of current_buffer that occurred since W's
17686 current matrix was built. Value is null if no such row exists.
17688 BEG_UNCHANGED us the number of characters unchanged at the start of
17689 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17690 first changed character in current_buffer. Characters at positions <
17691 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17692 when the current matrix was built. */
17694 static struct glyph_row
*
17695 find_last_unchanged_at_beg_row (struct window
*w
)
17697 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17698 struct glyph_row
*row
;
17699 struct glyph_row
*row_found
= NULL
;
17700 int yb
= window_text_bottom_y (w
);
17702 /* Find the last row displaying unchanged text. */
17703 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17704 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17705 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17708 if (/* If row ends before first_changed_pos, it is unchanged,
17709 except in some case. */
17710 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17711 /* When row ends in ZV and we write at ZV it is not
17713 && !row
->ends_at_zv_p
17714 /* When first_changed_pos is the end of a continued line,
17715 row is not unchanged because it may be no longer
17717 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17718 && (row
->continued_p
17719 || row
->exact_window_width_line_p
))
17720 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17721 needs to be recomputed, so don't consider this row as
17722 unchanged. This happens when the last line was
17723 bidi-reordered and was killed immediately before this
17724 redisplay cycle. In that case, ROW->end stores the
17725 buffer position of the first visual-order character of
17726 the killed text, which is now beyond ZV. */
17727 && CHARPOS (row
->end
.pos
) <= ZV
)
17730 /* Stop if last visible row. */
17731 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17739 /* Find the first glyph row in the current matrix of W that is not
17740 affected by changes at the end of current_buffer since the
17741 time W's current matrix was built.
17743 Return in *DELTA the number of chars by which buffer positions in
17744 unchanged text at the end of current_buffer must be adjusted.
17746 Return in *DELTA_BYTES the corresponding number of bytes.
17748 Value is null if no such row exists, i.e. all rows are affected by
17751 static struct glyph_row
*
17752 find_first_unchanged_at_end_row (struct window
*w
,
17753 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17755 struct glyph_row
*row
;
17756 struct glyph_row
*row_found
= NULL
;
17758 *delta
= *delta_bytes
= 0;
17760 /* Display must not have been paused, otherwise the current matrix
17761 is not up to date. */
17762 eassert (w
->window_end_valid
);
17764 /* A value of window_end_pos >= END_UNCHANGED means that the window
17765 end is in the range of changed text. If so, there is no
17766 unchanged row at the end of W's current matrix. */
17767 if (w
->window_end_pos
>= END_UNCHANGED
)
17770 /* Set row to the last row in W's current matrix displaying text. */
17771 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17773 /* If matrix is entirely empty, no unchanged row exists. */
17774 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17776 /* The value of row is the last glyph row in the matrix having a
17777 meaningful buffer position in it. The end position of row
17778 corresponds to window_end_pos. This allows us to translate
17779 buffer positions in the current matrix to current buffer
17780 positions for characters not in changed text. */
17782 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17783 ptrdiff_t Z_BYTE_old
=
17784 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17785 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17786 struct glyph_row
*first_text_row
17787 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17789 *delta
= Z
- Z_old
;
17790 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17792 /* Set last_unchanged_pos to the buffer position of the last
17793 character in the buffer that has not been changed. Z is the
17794 index + 1 of the last character in current_buffer, i.e. by
17795 subtracting END_UNCHANGED we get the index of the last
17796 unchanged character, and we have to add BEG to get its buffer
17798 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17799 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17801 /* Search backward from ROW for a row displaying a line that
17802 starts at a minimum position >= last_unchanged_pos_old. */
17803 for (; row
> first_text_row
; --row
)
17805 /* This used to abort, but it can happen.
17806 It is ok to just stop the search instead here. KFS. */
17807 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17810 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17815 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17821 /* Make sure that glyph rows in the current matrix of window W
17822 reference the same glyph memory as corresponding rows in the
17823 frame's frame matrix. This function is called after scrolling W's
17824 current matrix on a terminal frame in try_window_id and
17825 try_window_reusing_current_matrix. */
17828 sync_frame_with_window_matrix_rows (struct window
*w
)
17830 struct frame
*f
= XFRAME (w
->frame
);
17831 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17833 /* Preconditions: W must be a leaf window and full-width. Its frame
17834 must have a frame matrix. */
17835 eassert (BUFFERP (w
->contents
));
17836 eassert (WINDOW_FULL_WIDTH_P (w
));
17837 eassert (!FRAME_WINDOW_P (f
));
17839 /* If W is a full-width window, glyph pointers in W's current matrix
17840 have, by definition, to be the same as glyph pointers in the
17841 corresponding frame matrix. Note that frame matrices have no
17842 marginal areas (see build_frame_matrix). */
17843 window_row
= w
->current_matrix
->rows
;
17844 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17845 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17846 while (window_row
< window_row_end
)
17848 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17849 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17851 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17852 frame_row
->glyphs
[TEXT_AREA
] = start
;
17853 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17854 frame_row
->glyphs
[LAST_AREA
] = end
;
17856 /* Disable frame rows whose corresponding window rows have
17857 been disabled in try_window_id. */
17858 if (!window_row
->enabled_p
)
17859 frame_row
->enabled_p
= false;
17861 ++window_row
, ++frame_row
;
17866 /* Find the glyph row in window W containing CHARPOS. Consider all
17867 rows between START and END (not inclusive). END null means search
17868 all rows to the end of the display area of W. Value is the row
17869 containing CHARPOS or null. */
17872 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17873 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17875 struct glyph_row
*row
= start
;
17876 struct glyph_row
*best_row
= NULL
;
17877 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17880 /* If we happen to start on a header-line, skip that. */
17881 if (row
->mode_line_p
)
17884 if ((end
&& row
>= end
) || !row
->enabled_p
)
17887 last_y
= window_text_bottom_y (w
) - dy
;
17891 /* Give up if we have gone too far. */
17892 if ((end
&& row
>= end
) || !row
->enabled_p
)
17894 /* This formerly returned if they were equal.
17895 I think that both quantities are of a "last plus one" type;
17896 if so, when they are equal, the row is within the screen. -- rms. */
17897 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17900 /* If it is in this row, return this row. */
17901 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17902 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17903 /* The end position of a row equals the start
17904 position of the next row. If CHARPOS is there, we
17905 would rather consider it displayed in the next
17906 line, except when this line ends in ZV. */
17907 && !row_for_charpos_p (row
, charpos
)))
17908 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17912 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17913 || (!best_row
&& !row
->continued_p
))
17915 /* In bidi-reordered rows, there could be several rows whose
17916 edges surround CHARPOS, all of these rows belonging to
17917 the same continued line. We need to find the row which
17918 fits CHARPOS the best. */
17919 for (g
= row
->glyphs
[TEXT_AREA
];
17920 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17923 if (!STRINGP (g
->object
))
17925 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17927 mindif
= eabs (g
->charpos
- charpos
);
17929 /* Exact match always wins. */
17936 else if (best_row
&& !row
->continued_p
)
17943 /* Try to redisplay window W by reusing its existing display. W's
17944 current matrix must be up to date when this function is called,
17945 i.e., window_end_valid must be true.
17949 >= 1 if successful, i.e. display has been updated
17951 1 means the changes were in front of a newline that precedes
17952 the window start, and the whole current matrix was reused
17953 2 means the changes were after the last position displayed
17954 in the window, and the whole current matrix was reused
17955 3 means portions of the current matrix were reused, while
17956 some of the screen lines were redrawn
17957 -1 if redisplay with same window start is known not to succeed
17958 0 if otherwise unsuccessful
17960 The following steps are performed:
17962 1. Find the last row in the current matrix of W that is not
17963 affected by changes at the start of current_buffer. If no such row
17966 2. Find the first row in W's current matrix that is not affected by
17967 changes at the end of current_buffer. Maybe there is no such row.
17969 3. Display lines beginning with the row + 1 found in step 1 to the
17970 row found in step 2 or, if step 2 didn't find a row, to the end of
17973 4. If cursor is not known to appear on the window, give up.
17975 5. If display stopped at the row found in step 2, scroll the
17976 display and current matrix as needed.
17978 6. Maybe display some lines at the end of W, if we must. This can
17979 happen under various circumstances, like a partially visible line
17980 becoming fully visible, or because newly displayed lines are displayed
17981 in smaller font sizes.
17983 7. Update W's window end information. */
17986 try_window_id (struct window
*w
)
17988 struct frame
*f
= XFRAME (w
->frame
);
17989 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17990 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17991 struct glyph_row
*last_unchanged_at_beg_row
;
17992 struct glyph_row
*first_unchanged_at_end_row
;
17993 struct glyph_row
*row
;
17994 struct glyph_row
*bottom_row
;
17997 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17999 struct text_pos start_pos
;
18001 int first_unchanged_at_end_vpos
= 0;
18002 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
18003 struct text_pos start
;
18004 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
18007 if (inhibit_try_window_id
)
18011 /* This is handy for debugging. */
18013 #define GIVE_UP(X) \
18015 TRACE ((stderr, "try_window_id give up %d\n", (X))); \
18019 #define GIVE_UP(X) return 0
18022 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
18024 /* Don't use this for mini-windows because these can show
18025 messages and mini-buffers, and we don't handle that here. */
18026 if (MINI_WINDOW_P (w
))
18029 /* This flag is used to prevent redisplay optimizations. */
18030 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
18033 /* This function's optimizations cannot be used if overlays have
18034 changed in the buffer displayed by the window, so give up if they
18036 if (w
->last_overlay_modified
!= OVERLAY_MODIFF
)
18039 /* Verify that narrowing has not changed.
18040 Also verify that we were not told to prevent redisplay optimizations.
18041 It would be nice to further
18042 reduce the number of cases where this prevents try_window_id. */
18043 if (current_buffer
->clip_changed
18044 || current_buffer
->prevent_redisplay_optimizations_p
)
18047 /* Window must either use window-based redisplay or be full width. */
18048 if (!FRAME_WINDOW_P (f
)
18049 && (!FRAME_LINE_INS_DEL_OK (f
)
18050 || !WINDOW_FULL_WIDTH_P (w
)))
18053 /* Give up if point is known NOT to appear in W. */
18054 if (PT
< CHARPOS (start
))
18057 /* Another way to prevent redisplay optimizations. */
18058 if (w
->last_modified
== 0)
18061 /* Verify that window is not hscrolled. */
18062 if (w
->hscroll
!= 0)
18065 /* Verify that display wasn't paused. */
18066 if (!w
->window_end_valid
)
18069 /* Likewise if highlighting trailing whitespace. */
18070 if (!NILP (Vshow_trailing_whitespace
))
18073 /* Can't use this if overlay arrow position and/or string have
18075 if (overlay_arrows_changed_p ())
18078 /* When word-wrap is on, adding a space to the first word of a
18079 wrapped line can change the wrap position, altering the line
18080 above it. It might be worthwhile to handle this more
18081 intelligently, but for now just redisplay from scratch. */
18082 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
18085 /* Under bidi reordering, adding or deleting a character in the
18086 beginning of a paragraph, before the first strong directional
18087 character, can change the base direction of the paragraph (unless
18088 the buffer specifies a fixed paragraph direction), which will
18089 require to redisplay the whole paragraph. It might be worthwhile
18090 to find the paragraph limits and widen the range of redisplayed
18091 lines to that, but for now just give up this optimization and
18092 redisplay from scratch. */
18093 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
18094 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
18097 /* Give up if the buffer has line-spacing set, as Lisp-level changes
18098 to that variable require thorough redisplay. */
18099 if (!NILP (BVAR (XBUFFER (w
->contents
), extra_line_spacing
)))
18102 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
18103 only if buffer has really changed. The reason is that the gap is
18104 initially at Z for freshly visited files. The code below would
18105 set end_unchanged to 0 in that case. */
18106 if (MODIFF
> SAVE_MODIFF
18107 /* This seems to happen sometimes after saving a buffer. */
18108 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
18110 if (GPT
- BEG
< BEG_UNCHANGED
)
18111 BEG_UNCHANGED
= GPT
- BEG
;
18112 if (Z
- GPT
< END_UNCHANGED
)
18113 END_UNCHANGED
= Z
- GPT
;
18116 /* The position of the first and last character that has been changed. */
18117 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
18118 last_changed_charpos
= Z
- END_UNCHANGED
;
18120 /* If window starts after a line end, and the last change is in
18121 front of that newline, then changes don't affect the display.
18122 This case happens with stealth-fontification. Note that although
18123 the display is unchanged, glyph positions in the matrix have to
18124 be adjusted, of course. */
18125 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
18126 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
18127 && ((last_changed_charpos
< CHARPOS (start
)
18128 && CHARPOS (start
) == BEGV
)
18129 || (last_changed_charpos
< CHARPOS (start
) - 1
18130 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
18132 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
18133 struct glyph_row
*r0
;
18135 /* Compute how many chars/bytes have been added to or removed
18136 from the buffer. */
18137 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
18138 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
18139 Z_delta
= Z
- Z_old
;
18140 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
18142 /* Give up if PT is not in the window. Note that it already has
18143 been checked at the start of try_window_id that PT is not in
18144 front of the window start. */
18145 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
18148 /* If window start is unchanged, we can reuse the whole matrix
18149 as is, after adjusting glyph positions. No need to compute
18150 the window end again, since its offset from Z hasn't changed. */
18151 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18152 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
18153 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
18154 /* PT must not be in a partially visible line. */
18155 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
18156 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
18158 /* Adjust positions in the glyph matrix. */
18159 if (Z_delta
|| Z_delta_bytes
)
18161 struct glyph_row
*r1
18162 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18163 increment_matrix_positions (w
->current_matrix
,
18164 MATRIX_ROW_VPOS (r0
, current_matrix
),
18165 MATRIX_ROW_VPOS (r1
, current_matrix
),
18166 Z_delta
, Z_delta_bytes
);
18169 /* Set the cursor. */
18170 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
18172 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
18177 /* Handle the case that changes are all below what is displayed in
18178 the window, and that PT is in the window. This shortcut cannot
18179 be taken if ZV is visible in the window, and text has been added
18180 there that is visible in the window. */
18181 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
18182 /* ZV is not visible in the window, or there are no
18183 changes at ZV, actually. */
18184 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
18185 || first_changed_charpos
== last_changed_charpos
))
18187 struct glyph_row
*r0
;
18189 /* Give up if PT is not in the window. Note that it already has
18190 been checked at the start of try_window_id that PT is not in
18191 front of the window start. */
18192 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
18195 /* If window start is unchanged, we can reuse the whole matrix
18196 as is, without changing glyph positions since no text has
18197 been added/removed in front of the window end. */
18198 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18199 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
18200 /* PT must not be in a partially visible line. */
18201 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
18202 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
18204 /* We have to compute the window end anew since text
18205 could have been added/removed after it. */
18206 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18207 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18209 /* Set the cursor. */
18210 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
18212 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
18217 /* Give up if window start is in the changed area.
18219 The condition used to read
18221 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
18223 but why that was tested escapes me at the moment. */
18224 if (CHARPOS (start
) >= first_changed_charpos
18225 && CHARPOS (start
) <= last_changed_charpos
)
18228 /* Check that window start agrees with the start of the first glyph
18229 row in its current matrix. Check this after we know the window
18230 start is not in changed text, otherwise positions would not be
18232 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18233 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
18236 /* Give up if the window ends in strings. Overlay strings
18237 at the end are difficult to handle, so don't try. */
18238 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
18239 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
18242 /* Compute the position at which we have to start displaying new
18243 lines. Some of the lines at the top of the window might be
18244 reusable because they are not displaying changed text. Find the
18245 last row in W's current matrix not affected by changes at the
18246 start of current_buffer. Value is null if changes start in the
18247 first line of window. */
18248 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
18249 if (last_unchanged_at_beg_row
)
18251 /* Avoid starting to display in the middle of a character, a TAB
18252 for instance. This is easier than to set up the iterator
18253 exactly, and it's not a frequent case, so the additional
18254 effort wouldn't really pay off. */
18255 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
18256 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
18257 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
18258 --last_unchanged_at_beg_row
;
18260 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
18263 if (! init_to_row_end (&it
, w
, last_unchanged_at_beg_row
))
18265 start_pos
= it
.current
.pos
;
18267 /* Start displaying new lines in the desired matrix at the same
18268 vpos we would use in the current matrix, i.e. below
18269 last_unchanged_at_beg_row. */
18270 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
18272 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18273 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
18275 eassert (it
.hpos
== 0 && it
.current_x
== 0);
18279 /* There are no reusable lines at the start of the window.
18280 Start displaying in the first text line. */
18281 start_display (&it
, w
, start
);
18282 it
.vpos
= it
.first_vpos
;
18283 start_pos
= it
.current
.pos
;
18286 /* Find the first row that is not affected by changes at the end of
18287 the buffer. Value will be null if there is no unchanged row, in
18288 which case we must redisplay to the end of the window. delta
18289 will be set to the value by which buffer positions beginning with
18290 first_unchanged_at_end_row have to be adjusted due to text
18292 first_unchanged_at_end_row
18293 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
18294 IF_DEBUG (debug_delta
= delta
);
18295 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
18297 /* Set stop_pos to the buffer position up to which we will have to
18298 display new lines. If first_unchanged_at_end_row != NULL, this
18299 is the buffer position of the start of the line displayed in that
18300 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
18301 that we don't stop at a buffer position. */
18303 if (first_unchanged_at_end_row
)
18305 eassert (last_unchanged_at_beg_row
== NULL
18306 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
18308 /* If this is a continuation line, move forward to the next one
18309 that isn't. Changes in lines above affect this line.
18310 Caution: this may move first_unchanged_at_end_row to a row
18311 not displaying text. */
18312 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
18313 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18314 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18315 < it
.last_visible_y
))
18316 ++first_unchanged_at_end_row
;
18318 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18319 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18320 >= it
.last_visible_y
))
18321 first_unchanged_at_end_row
= NULL
;
18324 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
18326 first_unchanged_at_end_vpos
18327 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
18328 eassert (stop_pos
>= Z
- END_UNCHANGED
);
18331 else if (last_unchanged_at_beg_row
== NULL
)
18337 /* Either there is no unchanged row at the end, or the one we have
18338 now displays text. This is a necessary condition for the window
18339 end pos calculation at the end of this function. */
18340 eassert (first_unchanged_at_end_row
== NULL
18341 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18343 debug_last_unchanged_at_beg_vpos
18344 = (last_unchanged_at_beg_row
18345 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
18347 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
18349 #endif /* GLYPH_DEBUG */
18352 /* Display new lines. Set last_text_row to the last new line
18353 displayed which has text on it, i.e. might end up as being the
18354 line where the window_end_vpos is. */
18355 w
->cursor
.vpos
= -1;
18356 last_text_row
= NULL
;
18357 overlay_arrow_seen
= false;
18358 if (it
.current_y
< it
.last_visible_y
18359 && !f
->fonts_changed
18360 && (first_unchanged_at_end_row
== NULL
18361 || IT_CHARPOS (it
) < stop_pos
))
18362 it
.glyph_row
->reversed_p
= false;
18363 while (it
.current_y
< it
.last_visible_y
18364 && !f
->fonts_changed
18365 && (first_unchanged_at_end_row
== NULL
18366 || IT_CHARPOS (it
) < stop_pos
))
18368 if (display_line (&it
))
18369 last_text_row
= it
.glyph_row
- 1;
18372 if (f
->fonts_changed
)
18375 /* The redisplay iterations in display_line above could have
18376 triggered font-lock, which could have done something that
18377 invalidates IT->w window's end-point information, on which we
18378 rely below. E.g., one package, which will remain unnamed, used
18379 to install a font-lock-fontify-region-function that called
18380 bury-buffer, whose side effect is to switch the buffer displayed
18381 by IT->w, and that predictably resets IT->w's window_end_valid
18382 flag, which we already tested at the entry to this function.
18383 Amply punish such packages/modes by giving up on this
18384 optimization in those cases. */
18385 if (!w
->window_end_valid
)
18387 clear_glyph_matrix (w
->desired_matrix
);
18391 /* Compute differences in buffer positions, y-positions etc. for
18392 lines reused at the bottom of the window. Compute what we can
18394 if (first_unchanged_at_end_row
18395 /* No lines reused because we displayed everything up to the
18396 bottom of the window. */
18397 && it
.current_y
< it
.last_visible_y
)
18400 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
18402 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
18403 run
.current_y
= first_unchanged_at_end_row
->y
;
18404 run
.desired_y
= run
.current_y
+ dy
;
18405 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
18409 delta
= delta_bytes
= dvpos
= dy
18410 = run
.current_y
= run
.desired_y
= run
.height
= 0;
18411 first_unchanged_at_end_row
= NULL
;
18413 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
18416 /* Find the cursor if not already found. We have to decide whether
18417 PT will appear on this window (it sometimes doesn't, but this is
18418 not a very frequent case.) This decision has to be made before
18419 the current matrix is altered. A value of cursor.vpos < 0 means
18420 that PT is either in one of the lines beginning at
18421 first_unchanged_at_end_row or below the window. Don't care for
18422 lines that might be displayed later at the window end; as
18423 mentioned, this is not a frequent case. */
18424 if (w
->cursor
.vpos
< 0)
18426 /* Cursor in unchanged rows at the top? */
18427 if (PT
< CHARPOS (start_pos
)
18428 && last_unchanged_at_beg_row
)
18430 row
= row_containing_pos (w
, PT
,
18431 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
18432 last_unchanged_at_beg_row
+ 1, 0);
18434 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
18437 /* Start from first_unchanged_at_end_row looking for PT. */
18438 else if (first_unchanged_at_end_row
)
18440 row
= row_containing_pos (w
, PT
- delta
,
18441 first_unchanged_at_end_row
, NULL
, 0);
18443 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
18444 delta_bytes
, dy
, dvpos
);
18447 /* Give up if cursor was not found. */
18448 if (w
->cursor
.vpos
< 0)
18450 clear_glyph_matrix (w
->desired_matrix
);
18455 /* Don't let the cursor end in the scroll margins. */
18457 int this_scroll_margin
, cursor_height
;
18458 int frame_line_height
= default_line_pixel_height (w
);
18459 int window_total_lines
18460 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
18462 this_scroll_margin
=
18463 max (0, min (scroll_margin
, window_total_lines
/ 4));
18464 this_scroll_margin
*= frame_line_height
;
18465 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
18467 if ((w
->cursor
.y
< this_scroll_margin
18468 && CHARPOS (start
) > BEGV
)
18469 /* Old redisplay didn't take scroll margin into account at the bottom,
18470 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
18471 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
18472 ? cursor_height
+ this_scroll_margin
18473 : 1)) > it
.last_visible_y
)
18475 w
->cursor
.vpos
= -1;
18476 clear_glyph_matrix (w
->desired_matrix
);
18481 /* Scroll the display. Do it before changing the current matrix so
18482 that xterm.c doesn't get confused about where the cursor glyph is
18484 if (dy
&& run
.height
)
18488 if (FRAME_WINDOW_P (f
))
18490 FRAME_RIF (f
)->update_window_begin_hook (w
);
18491 FRAME_RIF (f
)->clear_window_mouse_face (w
);
18492 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
18493 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
18497 /* Terminal frame. In this case, dvpos gives the number of
18498 lines to scroll by; dvpos < 0 means scroll up. */
18500 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
18501 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
18502 int end
= (WINDOW_TOP_EDGE_LINE (w
)
18503 + WINDOW_WANTS_HEADER_LINE_P (w
)
18504 + window_internal_height (w
));
18506 #if defined (HAVE_GPM) || defined (MSDOS)
18507 x_clear_window_mouse_face (w
);
18509 /* Perform the operation on the screen. */
18512 /* Scroll last_unchanged_at_beg_row to the end of the
18513 window down dvpos lines. */
18514 set_terminal_window (f
, end
);
18516 /* On dumb terminals delete dvpos lines at the end
18517 before inserting dvpos empty lines. */
18518 if (!FRAME_SCROLL_REGION_OK (f
))
18519 ins_del_lines (f
, end
- dvpos
, -dvpos
);
18521 /* Insert dvpos empty lines in front of
18522 last_unchanged_at_beg_row. */
18523 ins_del_lines (f
, from
, dvpos
);
18525 else if (dvpos
< 0)
18527 /* Scroll up last_unchanged_at_beg_vpos to the end of
18528 the window to last_unchanged_at_beg_vpos - |dvpos|. */
18529 set_terminal_window (f
, end
);
18531 /* Delete dvpos lines in front of
18532 last_unchanged_at_beg_vpos. ins_del_lines will set
18533 the cursor to the given vpos and emit |dvpos| delete
18535 ins_del_lines (f
, from
+ dvpos
, dvpos
);
18537 /* On a dumb terminal insert dvpos empty lines at the
18539 if (!FRAME_SCROLL_REGION_OK (f
))
18540 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
18543 set_terminal_window (f
, 0);
18549 /* Shift reused rows of the current matrix to the right position.
18550 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
18552 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18553 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
18556 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
18557 bottom_vpos
, dvpos
);
18558 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
18561 else if (dvpos
> 0)
18563 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
18564 bottom_vpos
, dvpos
);
18565 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
18566 first_unchanged_at_end_vpos
+ dvpos
);
18569 /* For frame-based redisplay, make sure that current frame and window
18570 matrix are in sync with respect to glyph memory. */
18571 if (!FRAME_WINDOW_P (f
))
18572 sync_frame_with_window_matrix_rows (w
);
18574 /* Adjust buffer positions in reused rows. */
18575 if (delta
|| delta_bytes
)
18576 increment_matrix_positions (current_matrix
,
18577 first_unchanged_at_end_vpos
+ dvpos
,
18578 bottom_vpos
, delta
, delta_bytes
);
18580 /* Adjust Y positions. */
18582 shift_glyph_matrix (w
, current_matrix
,
18583 first_unchanged_at_end_vpos
+ dvpos
,
18586 if (first_unchanged_at_end_row
)
18588 first_unchanged_at_end_row
+= dvpos
;
18589 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
18590 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
18591 first_unchanged_at_end_row
= NULL
;
18594 /* If scrolling up, there may be some lines to display at the end of
18596 last_text_row_at_end
= NULL
;
18599 /* Scrolling up can leave for example a partially visible line
18600 at the end of the window to be redisplayed. */
18601 /* Set last_row to the glyph row in the current matrix where the
18602 window end line is found. It has been moved up or down in
18603 the matrix by dvpos. */
18604 int last_vpos
= w
->window_end_vpos
+ dvpos
;
18605 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
18607 /* If last_row is the window end line, it should display text. */
18608 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
18610 /* If window end line was partially visible before, begin
18611 displaying at that line. Otherwise begin displaying with the
18612 line following it. */
18613 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
18615 init_to_row_start (&it
, w
, last_row
);
18616 it
.vpos
= last_vpos
;
18617 it
.current_y
= last_row
->y
;
18621 init_to_row_end (&it
, w
, last_row
);
18622 it
.vpos
= 1 + last_vpos
;
18623 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
18627 /* We may start in a continuation line. If so, we have to
18628 get the right continuation_lines_width and current_x. */
18629 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
18630 it
.hpos
= it
.current_x
= 0;
18632 /* Display the rest of the lines at the window end. */
18633 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18634 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
18636 /* Is it always sure that the display agrees with lines in
18637 the current matrix? I don't think so, so we mark rows
18638 displayed invalid in the current matrix by setting their
18639 enabled_p flag to false. */
18640 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
18641 if (display_line (&it
))
18642 last_text_row_at_end
= it
.glyph_row
- 1;
18646 /* Update window_end_pos and window_end_vpos. */
18647 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
18649 /* Window end line if one of the preserved rows from the current
18650 matrix. Set row to the last row displaying text in current
18651 matrix starting at first_unchanged_at_end_row, after
18653 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18654 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
18655 first_unchanged_at_end_row
);
18656 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
18657 adjust_window_ends (w
, row
, true);
18658 eassert (w
->window_end_bytepos
>= 0);
18659 IF_DEBUG (debug_method_add (w
, "A"));
18661 else if (last_text_row_at_end
)
18663 adjust_window_ends (w
, last_text_row_at_end
, false);
18664 eassert (w
->window_end_bytepos
>= 0);
18665 IF_DEBUG (debug_method_add (w
, "B"));
18667 else if (last_text_row
)
18669 /* We have displayed either to the end of the window or at the
18670 end of the window, i.e. the last row with text is to be found
18671 in the desired matrix. */
18672 adjust_window_ends (w
, last_text_row
, false);
18673 eassert (w
->window_end_bytepos
>= 0);
18675 else if (first_unchanged_at_end_row
== NULL
18676 && last_text_row
== NULL
18677 && last_text_row_at_end
== NULL
)
18679 /* Displayed to end of window, but no line containing text was
18680 displayed. Lines were deleted at the end of the window. */
18681 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
18682 int vpos
= w
->window_end_vpos
;
18683 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
18684 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18687 row
== NULL
&& vpos
>= first_vpos
;
18688 --vpos
, --current_row
, --desired_row
)
18690 if (desired_row
->enabled_p
)
18692 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18695 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18699 eassert (row
!= NULL
);
18700 w
->window_end_vpos
= vpos
+ 1;
18701 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18702 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18703 eassert (w
->window_end_bytepos
>= 0);
18704 IF_DEBUG (debug_method_add (w
, "C"));
18709 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18710 debug_end_vpos
= w
->window_end_vpos
));
18712 /* Record that display has not been completed. */
18713 w
->window_end_valid
= false;
18714 w
->desired_matrix
->no_scrolling_p
= true;
18722 /***********************************************************************
18723 More debugging support
18724 ***********************************************************************/
18728 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18729 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18730 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18733 /* Dump the contents of glyph matrix MATRIX on stderr.
18735 GLYPHS 0 means don't show glyph contents.
18736 GLYPHS 1 means show glyphs in short form
18737 GLYPHS > 1 means show glyphs in long form. */
18740 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18743 for (i
= 0; i
< matrix
->nrows
; ++i
)
18744 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18748 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18749 the glyph row and area where the glyph comes from. */
18752 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18754 if (glyph
->type
== CHAR_GLYPH
18755 || glyph
->type
== GLYPHLESS_GLYPH
)
18758 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18759 glyph
- row
->glyphs
[TEXT_AREA
],
18760 (glyph
->type
== CHAR_GLYPH
18764 (BUFFERP (glyph
->object
)
18766 : (STRINGP (glyph
->object
)
18768 : (NILP (glyph
->object
)
18771 glyph
->pixel_width
,
18773 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18777 glyph
->left_box_line_p
,
18778 glyph
->right_box_line_p
);
18780 else if (glyph
->type
== STRETCH_GLYPH
)
18783 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18784 glyph
- row
->glyphs
[TEXT_AREA
],
18787 (BUFFERP (glyph
->object
)
18789 : (STRINGP (glyph
->object
)
18791 : (NILP (glyph
->object
)
18794 glyph
->pixel_width
,
18798 glyph
->left_box_line_p
,
18799 glyph
->right_box_line_p
);
18801 else if (glyph
->type
== IMAGE_GLYPH
)
18804 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18805 glyph
- row
->glyphs
[TEXT_AREA
],
18808 (BUFFERP (glyph
->object
)
18810 : (STRINGP (glyph
->object
)
18812 : (NILP (glyph
->object
)
18815 glyph
->pixel_width
,
18819 glyph
->left_box_line_p
,
18820 glyph
->right_box_line_p
);
18822 else if (glyph
->type
== COMPOSITE_GLYPH
)
18825 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18826 glyph
- row
->glyphs
[TEXT_AREA
],
18829 (BUFFERP (glyph
->object
)
18831 : (STRINGP (glyph
->object
)
18833 : (NILP (glyph
->object
)
18836 glyph
->pixel_width
,
18838 if (glyph
->u
.cmp
.automatic
)
18841 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18842 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18844 glyph
->left_box_line_p
,
18845 glyph
->right_box_line_p
);
18847 #ifdef HAVE_XWIDGETS
18848 else if (glyph
->type
== XWIDGET_GLYPH
)
18851 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18852 glyph
- row
->glyphs
[TEXT_AREA
],
18855 (BUFFERP (glyph
->object
)
18857 : (STRINGP (glyph
->object
)
18860 glyph
->pixel_width
,
18864 glyph
->left_box_line_p
,
18865 glyph
->right_box_line_p
);
18872 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18873 GLYPHS 0 means don't show glyph contents.
18874 GLYPHS 1 means show glyphs in short form
18875 GLYPHS > 1 means show glyphs in long form. */
18878 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18882 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18883 fprintf (stderr
, "==============================================================================\n");
18885 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18886 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18888 MATRIX_ROW_START_CHARPOS (row
),
18889 MATRIX_ROW_END_CHARPOS (row
),
18890 row
->used
[TEXT_AREA
],
18891 row
->contains_overlapping_glyphs_p
,
18893 row
->truncated_on_left_p
,
18894 row
->truncated_on_right_p
,
18896 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18897 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18900 row
->ends_in_middle_of_char_p
,
18901 row
->starts_in_middle_of_char_p
,
18907 row
->visible_height
,
18910 /* The next 3 lines should align to "Start" in the header. */
18911 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18912 row
->end
.overlay_string_index
,
18913 row
->continuation_lines_width
);
18914 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18915 CHARPOS (row
->start
.string_pos
),
18916 CHARPOS (row
->end
.string_pos
));
18917 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18918 row
->end
.dpvec_index
);
18925 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18927 struct glyph
*glyph
= row
->glyphs
[area
];
18928 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18930 /* Glyph for a line end in text. */
18931 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18934 if (glyph
< glyph_end
)
18935 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18937 for (; glyph
< glyph_end
; ++glyph
)
18938 dump_glyph (row
, glyph
, area
);
18941 else if (glyphs
== 1)
18944 char s
[SHRT_MAX
+ 4];
18946 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18950 for (i
= 0; i
< row
->used
[area
]; ++i
)
18952 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18953 if (i
== row
->used
[area
] - 1
18954 && area
== TEXT_AREA
18955 && NILP (glyph
->object
)
18956 && glyph
->type
== CHAR_GLYPH
18957 && glyph
->u
.ch
== ' ')
18959 strcpy (&s
[i
], "[\\n]");
18962 else if (glyph
->type
== CHAR_GLYPH
18963 && glyph
->u
.ch
< 0x80
18964 && glyph
->u
.ch
>= ' ')
18965 s
[i
] = glyph
->u
.ch
;
18971 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18977 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18978 Sdump_glyph_matrix
, 0, 1, "p",
18979 doc
: /* Dump the current matrix of the selected window to stderr.
18980 Shows contents of glyph row structures. With non-nil
18981 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18982 glyphs in short form, otherwise show glyphs in long form.
18984 Interactively, no argument means show glyphs in short form;
18985 with numeric argument, its value is passed as the GLYPHS flag. */)
18986 (Lisp_Object glyphs
)
18988 struct window
*w
= XWINDOW (selected_window
);
18989 struct buffer
*buffer
= XBUFFER (w
->contents
);
18991 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18992 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18993 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18994 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18995 fprintf (stderr
, "=============================================\n");
18996 dump_glyph_matrix (w
->current_matrix
,
18997 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
19002 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
19003 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* Dump the current glyph matrix of the selected frame to stderr.
19004 Only text-mode frames have frame glyph matrices. */)
19007 struct frame
*f
= XFRAME (selected_frame
);
19009 if (f
->current_matrix
)
19010 dump_glyph_matrix (f
->current_matrix
, 1);
19012 fprintf (stderr
, "*** This frame doesn't have a frame glyph matrix ***\n");
19017 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
19018 doc
: /* Dump glyph row ROW to stderr.
19019 GLYPH 0 means don't dump glyphs.
19020 GLYPH 1 means dump glyphs in short form.
19021 GLYPH > 1 or omitted means dump glyphs in long form. */)
19022 (Lisp_Object row
, Lisp_Object glyphs
)
19024 struct glyph_matrix
*matrix
;
19027 CHECK_NUMBER (row
);
19028 matrix
= XWINDOW (selected_window
)->current_matrix
;
19030 if (vpos
>= 0 && vpos
< matrix
->nrows
)
19031 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
19033 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
19038 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
19039 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
19040 GLYPH 0 means don't dump glyphs.
19041 GLYPH 1 means dump glyphs in short form.
19042 GLYPH > 1 or omitted means dump glyphs in long form.
19044 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
19046 (Lisp_Object row
, Lisp_Object glyphs
)
19048 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19049 struct frame
*sf
= SELECTED_FRAME ();
19050 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
19053 CHECK_NUMBER (row
);
19055 if (vpos
>= 0 && vpos
< m
->nrows
)
19056 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
19057 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
19063 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
19064 doc
: /* Toggle tracing of redisplay.
19065 With ARG, turn tracing on if and only if ARG is positive. */)
19069 trace_redisplay_p
= !trace_redisplay_p
;
19072 arg
= Fprefix_numeric_value (arg
);
19073 trace_redisplay_p
= XINT (arg
) > 0;
19080 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
19081 doc
: /* Like `format', but print result to stderr.
19082 usage: (trace-to-stderr STRING &rest OBJECTS) */)
19083 (ptrdiff_t nargs
, Lisp_Object
*args
)
19085 Lisp_Object s
= Fformat (nargs
, args
);
19086 fwrite (SDATA (s
), 1, SBYTES (s
), stderr
);
19090 #endif /* GLYPH_DEBUG */
19094 /***********************************************************************
19095 Building Desired Matrix Rows
19096 ***********************************************************************/
19098 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
19099 Used for non-window-redisplay windows, and for windows w/o left fringe. */
19101 static struct glyph_row
*
19102 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
19104 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19105 struct buffer
*buffer
= XBUFFER (w
->contents
);
19106 struct buffer
*old
= current_buffer
;
19107 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
19108 ptrdiff_t arrow_len
= SCHARS (overlay_arrow_string
);
19109 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
19110 const unsigned char *p
;
19113 int n_glyphs_before
;
19115 set_buffer_temp (buffer
);
19116 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
19117 scratch_glyph_row
.reversed_p
= false;
19118 it
.glyph_row
->used
[TEXT_AREA
] = 0;
19119 SET_TEXT_POS (it
.position
, 0, 0);
19121 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
19123 while (p
< arrow_end
)
19125 Lisp_Object face
, ilisp
;
19127 /* Get the next character. */
19129 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
19132 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
19133 if (! ASCII_CHAR_P (it
.c
))
19134 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
19138 /* Get its face. */
19139 ilisp
= make_number (p
- arrow_string
);
19140 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
19141 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
19143 /* Compute its width, get its glyphs. */
19144 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
19145 SET_TEXT_POS (it
.position
, -1, -1);
19146 PRODUCE_GLYPHS (&it
);
19148 /* If this character doesn't fit any more in the line, we have
19149 to remove some glyphs. */
19150 if (it
.current_x
> it
.last_visible_x
)
19152 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19157 set_buffer_temp (old
);
19158 return it
.glyph_row
;
19162 /* Insert truncation glyphs at the start of IT->glyph_row. Which
19163 glyphs to insert is determined by produce_special_glyphs. */
19166 insert_left_trunc_glyphs (struct it
*it
)
19168 struct it truncate_it
;
19169 struct glyph
*from
, *end
, *to
, *toend
;
19171 eassert (!FRAME_WINDOW_P (it
->f
)
19172 || (!it
->glyph_row
->reversed_p
19173 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19174 || (it
->glyph_row
->reversed_p
19175 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
19177 /* Get the truncation glyphs. */
19179 truncate_it
.current_x
= 0;
19180 truncate_it
.face_id
= DEFAULT_FACE_ID
;
19181 truncate_it
.glyph_row
= &scratch_glyph_row
;
19182 truncate_it
.area
= TEXT_AREA
;
19183 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
19184 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
19185 truncate_it
.object
= Qnil
;
19186 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
19188 /* Overwrite glyphs from IT with truncation glyphs. */
19189 if (!it
->glyph_row
->reversed_p
)
19191 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
19193 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19194 end
= from
+ tused
;
19195 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19196 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
19197 if (FRAME_WINDOW_P (it
->f
))
19199 /* On GUI frames, when variable-size fonts are displayed,
19200 the truncation glyphs may need more pixels than the row's
19201 glyphs they overwrite. We overwrite more glyphs to free
19202 enough screen real estate, and enlarge the stretch glyph
19203 on the right (see display_line), if there is one, to
19204 preserve the screen position of the truncation glyphs on
19207 struct glyph
*g
= to
;
19210 /* The first glyph could be partially visible, in which case
19211 it->glyph_row->x will be negative. But we want the left
19212 truncation glyphs to be aligned at the left margin of the
19213 window, so we override the x coordinate at which the row
19215 it
->glyph_row
->x
= 0;
19216 while (g
< toend
&& w
< it
->truncation_pixel_width
)
19218 w
+= g
->pixel_width
;
19221 if (g
- to
- tused
> 0)
19223 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
19224 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
19226 used
= it
->glyph_row
->used
[TEXT_AREA
];
19227 if (it
->glyph_row
->truncated_on_right_p
19228 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
19229 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
19232 int extra
= w
- it
->truncation_pixel_width
;
19234 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
19241 /* There may be padding glyphs left over. Overwrite them too. */
19242 if (!FRAME_WINDOW_P (it
->f
))
19244 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
19246 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19253 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
19257 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
19259 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
19260 that back to front. */
19261 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19262 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19263 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19264 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19265 if (FRAME_WINDOW_P (it
->f
))
19268 struct glyph
*g
= to
;
19270 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
19272 w
+= g
->pixel_width
;
19275 if (to
- g
- tused
> 0)
19277 if (it
->glyph_row
->truncated_on_right_p
19278 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
19279 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
19281 int extra
= w
- it
->truncation_pixel_width
;
19283 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
19287 while (from
>= end
&& to
>= toend
)
19289 if (!FRAME_WINDOW_P (it
->f
))
19291 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
19294 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
19295 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19296 while (from
>= end
&& to
>= toend
)
19302 /* Need to free some room before prepending additional
19304 int move_by
= from
- end
+ 1;
19305 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19306 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19308 for ( ; g
>= g0
; g
--)
19310 while (from
>= end
)
19312 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
19317 /* Compute the hash code for ROW. */
19319 row_hash (struct glyph_row
*row
)
19322 unsigned hashval
= 0;
19324 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
19325 for (k
= 0; k
< row
->used
[area
]; ++k
)
19326 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
19327 + row
->glyphs
[area
][k
].u
.val
19328 + row
->glyphs
[area
][k
].face_id
19329 + row
->glyphs
[area
][k
].padding_p
19330 + (row
->glyphs
[area
][k
].type
<< 2));
19335 /* Compute the pixel height and width of IT->glyph_row.
19337 Most of the time, ascent and height of a display line will be equal
19338 to the max_ascent and max_height values of the display iterator
19339 structure. This is not the case if
19341 1. We hit ZV without displaying anything. In this case, max_ascent
19342 and max_height will be zero.
19344 2. We have some glyphs that don't contribute to the line height.
19345 (The glyph row flag contributes_to_line_height_p is for future
19346 pixmap extensions).
19348 The first case is easily covered by using default values because in
19349 these cases, the line height does not really matter, except that it
19350 must not be zero. */
19353 compute_line_metrics (struct it
*it
)
19355 struct glyph_row
*row
= it
->glyph_row
;
19357 if (FRAME_WINDOW_P (it
->f
))
19359 int i
, min_y
, max_y
;
19361 /* The line may consist of one space only, that was added to
19362 place the cursor on it. If so, the row's height hasn't been
19364 if (row
->height
== 0)
19366 if (it
->max_ascent
+ it
->max_descent
== 0)
19367 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
19368 row
->ascent
= it
->max_ascent
;
19369 row
->height
= it
->max_ascent
+ it
->max_descent
;
19370 row
->phys_ascent
= it
->max_phys_ascent
;
19371 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19372 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19375 /* Compute the width of this line. */
19376 row
->pixel_width
= row
->x
;
19377 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
19378 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
19380 eassert (row
->pixel_width
>= 0);
19381 eassert (row
->ascent
>= 0 && row
->height
> 0);
19383 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
19384 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
19386 /* If first line's physical ascent is larger than its logical
19387 ascent, use the physical ascent, and make the row taller.
19388 This makes accented characters fully visible. */
19389 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
19390 && row
->phys_ascent
> row
->ascent
)
19392 row
->height
+= row
->phys_ascent
- row
->ascent
;
19393 row
->ascent
= row
->phys_ascent
;
19396 /* Compute how much of the line is visible. */
19397 row
->visible_height
= row
->height
;
19399 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
19400 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
19402 if (row
->y
< min_y
)
19403 row
->visible_height
-= min_y
- row
->y
;
19404 if (row
->y
+ row
->height
> max_y
)
19405 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
19409 row
->pixel_width
= row
->used
[TEXT_AREA
];
19410 if (row
->continued_p
)
19411 row
->pixel_width
-= it
->continuation_pixel_width
;
19412 else if (row
->truncated_on_right_p
)
19413 row
->pixel_width
-= it
->truncation_pixel_width
;
19414 row
->ascent
= row
->phys_ascent
= 0;
19415 row
->height
= row
->phys_height
= row
->visible_height
= 1;
19416 row
->extra_line_spacing
= 0;
19419 /* Compute a hash code for this row. */
19420 row
->hash
= row_hash (row
);
19422 it
->max_ascent
= it
->max_descent
= 0;
19423 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
19427 /* Append one space to the glyph row of iterator IT if doing a
19428 window-based redisplay. The space has the same face as
19429 IT->face_id. Value is true if a space was added.
19431 This function is called to make sure that there is always one glyph
19432 at the end of a glyph row that the cursor can be set on under
19433 window-systems. (If there weren't such a glyph we would not know
19434 how wide and tall a box cursor should be displayed).
19436 At the same time this space let's a nicely handle clearing to the
19437 end of the line if the row ends in italic text. */
19440 append_space_for_newline (struct it
*it
, bool default_face_p
)
19442 if (FRAME_WINDOW_P (it
->f
))
19444 int n
= it
->glyph_row
->used
[TEXT_AREA
];
19446 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
19447 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
19449 /* Save some values that must not be changed.
19450 Must save IT->c and IT->len because otherwise
19451 ITERATOR_AT_END_P wouldn't work anymore after
19452 append_space_for_newline has been called. */
19453 enum display_element_type saved_what
= it
->what
;
19454 int saved_c
= it
->c
, saved_len
= it
->len
;
19455 int saved_char_to_display
= it
->char_to_display
;
19456 int saved_x
= it
->current_x
;
19457 int saved_face_id
= it
->face_id
;
19458 bool saved_box_end
= it
->end_of_box_run_p
;
19459 struct text_pos saved_pos
;
19460 Lisp_Object saved_object
;
19464 saved_object
= it
->object
;
19465 saved_pos
= it
->position
;
19467 it
->what
= IT_CHARACTER
;
19468 memset (&it
->position
, 0, sizeof it
->position
);
19470 it
->c
= it
->char_to_display
= ' ';
19473 /* If the default face was remapped, be sure to use the
19474 remapped face for the appended newline. */
19475 if (default_face_p
)
19476 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
19477 else if (it
->face_before_selective_p
)
19478 it
->face_id
= it
->saved_face_id
;
19479 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19480 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
19481 /* In R2L rows, we will prepend a stretch glyph that will
19482 have the end_of_box_run_p flag set for it, so there's no
19483 need for the appended newline glyph to have that flag
19485 if (it
->glyph_row
->reversed_p
19486 /* But if the appended newline glyph goes all the way to
19487 the end of the row, there will be no stretch glyph,
19488 so leave the box flag set. */
19489 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
19490 it
->end_of_box_run_p
= false;
19492 PRODUCE_GLYPHS (it
);
19494 #ifdef HAVE_WINDOW_SYSTEM
19495 /* Make sure this space glyph has the right ascent and
19496 descent values, or else cursor at end of line will look
19497 funny, and height of empty lines will be incorrect. */
19498 g
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19499 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19502 Lisp_Object height
, total_height
;
19503 int extra_line_spacing
= it
->extra_line_spacing
;
19504 int boff
= font
->baseline_offset
;
19506 if (font
->vertical_centering
)
19507 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19509 it
->object
= saved_object
; /* get_it_property needs this */
19510 normal_char_ascent_descent (font
, -1, &it
->ascent
, &it
->descent
);
19511 /* Must do a subset of line height processing from
19512 x_produce_glyph for newline characters. */
19513 height
= get_it_property (it
, Qline_height
);
19515 && CONSP (XCDR (height
))
19516 && NILP (XCDR (XCDR (height
))))
19518 total_height
= XCAR (XCDR (height
));
19519 height
= XCAR (height
);
19522 total_height
= Qnil
;
19523 height
= calc_line_height_property (it
, height
, font
, boff
, true);
19525 if (it
->override_ascent
>= 0)
19527 it
->ascent
= it
->override_ascent
;
19528 it
->descent
= it
->override_descent
;
19529 boff
= it
->override_boff
;
19531 if (EQ (height
, Qt
))
19532 extra_line_spacing
= 0;
19535 Lisp_Object spacing
;
19537 it
->phys_ascent
= it
->ascent
;
19538 it
->phys_descent
= it
->descent
;
19540 && XINT (height
) > it
->ascent
+ it
->descent
)
19541 it
->ascent
= XINT (height
) - it
->descent
;
19543 if (!NILP (total_height
))
19544 spacing
= calc_line_height_property (it
, total_height
, font
,
19548 spacing
= get_it_property (it
, Qline_spacing
);
19549 spacing
= calc_line_height_property (it
, spacing
, font
,
19552 if (INTEGERP (spacing
))
19554 extra_line_spacing
= XINT (spacing
);
19555 if (!NILP (total_height
))
19556 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19559 if (extra_line_spacing
> 0)
19561 it
->descent
+= extra_line_spacing
;
19562 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19563 it
->max_extra_line_spacing
= extra_line_spacing
;
19565 it
->max_ascent
= it
->ascent
;
19566 it
->max_descent
= it
->descent
;
19567 /* Make sure compute_line_metrics recomputes the row height. */
19568 it
->glyph_row
->height
= 0;
19571 g
->ascent
= it
->max_ascent
;
19572 g
->descent
= it
->max_descent
;
19575 it
->override_ascent
= -1;
19576 it
->constrain_row_ascent_descent_p
= false;
19577 it
->current_x
= saved_x
;
19578 it
->object
= saved_object
;
19579 it
->position
= saved_pos
;
19580 it
->what
= saved_what
;
19581 it
->face_id
= saved_face_id
;
19582 it
->len
= saved_len
;
19584 it
->char_to_display
= saved_char_to_display
;
19585 it
->end_of_box_run_p
= saved_box_end
;
19594 /* Extend the face of the last glyph in the text area of IT->glyph_row
19595 to the end of the display line. Called from display_line. If the
19596 glyph row is empty, add a space glyph to it so that we know the
19597 face to draw. Set the glyph row flag fill_line_p. If the glyph
19598 row is R2L, prepend a stretch glyph to cover the empty space to the
19599 left of the leftmost glyph. */
19602 extend_face_to_end_of_line (struct it
*it
)
19604 struct face
*face
, *default_face
;
19605 struct frame
*f
= it
->f
;
19607 /* If line is already filled, do nothing. Non window-system frames
19608 get a grace of one more ``pixel'' because their characters are
19609 1-``pixel'' wide, so they hit the equality too early. This grace
19610 is needed only for R2L rows that are not continued, to produce
19611 one extra blank where we could display the cursor. */
19612 if ((it
->current_x
>= it
->last_visible_x
19613 + (!FRAME_WINDOW_P (f
)
19614 && it
->glyph_row
->reversed_p
19615 && !it
->glyph_row
->continued_p
))
19616 /* If the window has display margins, we will need to extend
19617 their face even if the text area is filled. */
19618 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19619 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
19622 /* The default face, possibly remapped. */
19623 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
19625 /* Face extension extends the background and box of IT->face_id
19626 to the end of the line. If the background equals the background
19627 of the frame, we don't have to do anything. */
19628 if (it
->face_before_selective_p
)
19629 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
19631 face
= FACE_FROM_ID (f
, it
->face_id
);
19633 if (FRAME_WINDOW_P (f
)
19634 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
19635 && face
->box
== FACE_NO_BOX
19636 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
19637 #ifdef HAVE_WINDOW_SYSTEM
19640 && !it
->glyph_row
->reversed_p
)
19643 /* Set the glyph row flag indicating that the face of the last glyph
19644 in the text area has to be drawn to the end of the text area. */
19645 it
->glyph_row
->fill_line_p
= true;
19647 /* If current character of IT is not ASCII, make sure we have the
19648 ASCII face. This will be automatically undone the next time
19649 get_next_display_element returns a multibyte character. Note
19650 that the character will always be single byte in unibyte
19652 if (!ASCII_CHAR_P (it
->c
))
19654 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
19657 if (FRAME_WINDOW_P (f
))
19659 /* If the row is empty, add a space with the current face of IT,
19660 so that we know which face to draw. */
19661 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
19663 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
19664 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
19665 it
->glyph_row
->used
[TEXT_AREA
] = 1;
19667 /* Mode line and the header line don't have margins, and
19668 likewise the frame's tool-bar window, if there is any. */
19669 if (!(it
->glyph_row
->mode_line_p
19670 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19671 || (WINDOWP (f
->tool_bar_window
)
19672 && it
->w
== XWINDOW (f
->tool_bar_window
))
19676 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19677 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
19679 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
19680 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
=
19682 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
19684 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19685 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
19687 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
19688 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
=
19690 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
19693 #ifdef HAVE_WINDOW_SYSTEM
19694 if (it
->glyph_row
->reversed_p
)
19696 /* Prepend a stretch glyph to the row, such that the
19697 rightmost glyph will be drawn flushed all the way to the
19698 right margin of the window. The stretch glyph that will
19699 occupy the empty space, if any, to the left of the
19701 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
19702 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19703 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
19705 int row_width
, stretch_ascent
, stretch_width
;
19706 struct text_pos saved_pos
;
19708 bool saved_avoid_cursor
, saved_box_start
;
19710 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
19711 row_width
+= g
->pixel_width
;
19713 /* FIXME: There are various minor display glitches in R2L
19714 rows when only one of the fringes is missing. The
19715 strange condition below produces the least bad effect. */
19716 if ((WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19717 == (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
19718 || WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
19719 stretch_width
= window_box_width (it
->w
, TEXT_AREA
);
19721 stretch_width
= it
->last_visible_x
- it
->first_visible_x
;
19722 stretch_width
-= row_width
;
19724 if (stretch_width
> 0)
19727 (((it
->ascent
+ it
->descent
)
19728 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
19729 saved_pos
= it
->position
;
19730 memset (&it
->position
, 0, sizeof it
->position
);
19731 saved_avoid_cursor
= it
->avoid_cursor_p
;
19732 it
->avoid_cursor_p
= true;
19733 saved_face_id
= it
->face_id
;
19734 saved_box_start
= it
->start_of_box_run_p
;
19735 /* The last row's stretch glyph should get the default
19736 face, to avoid painting the rest of the window with
19737 the region face, if the region ends at ZV. */
19738 if (it
->glyph_row
->ends_at_zv_p
)
19739 it
->face_id
= default_face
->id
;
19741 it
->face_id
= face
->id
;
19742 it
->start_of_box_run_p
= false;
19743 append_stretch_glyph (it
, Qnil
, stretch_width
,
19744 it
->ascent
+ it
->descent
, stretch_ascent
);
19745 it
->position
= saved_pos
;
19746 it
->avoid_cursor_p
= saved_avoid_cursor
;
19747 it
->face_id
= saved_face_id
;
19748 it
->start_of_box_run_p
= saved_box_start
;
19750 /* If stretch_width comes out negative, it means that the
19751 last glyph is only partially visible. In R2L rows, we
19752 want the leftmost glyph to be partially visible, so we
19753 need to give the row the corresponding left offset. */
19754 if (stretch_width
< 0)
19755 it
->glyph_row
->x
= stretch_width
;
19757 #endif /* HAVE_WINDOW_SYSTEM */
19761 /* Save some values that must not be changed. */
19762 int saved_x
= it
->current_x
;
19763 struct text_pos saved_pos
;
19764 Lisp_Object saved_object
;
19765 enum display_element_type saved_what
= it
->what
;
19766 int saved_face_id
= it
->face_id
;
19768 saved_object
= it
->object
;
19769 saved_pos
= it
->position
;
19771 it
->what
= IT_CHARACTER
;
19772 memset (&it
->position
, 0, sizeof it
->position
);
19774 it
->c
= it
->char_to_display
= ' ';
19777 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19778 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19779 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19780 && !it
->glyph_row
->mode_line_p
19781 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19783 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
19784 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
19786 for (it
->current_x
= 0; g
< e
; g
++)
19787 it
->current_x
+= g
->pixel_width
;
19789 it
->area
= LEFT_MARGIN_AREA
;
19790 it
->face_id
= default_face
->id
;
19791 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19792 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19794 PRODUCE_GLYPHS (it
);
19795 /* term.c:produce_glyphs advances it->current_x only for
19797 it
->current_x
+= it
->pixel_width
;
19800 it
->current_x
= saved_x
;
19801 it
->area
= TEXT_AREA
;
19804 /* The last row's blank glyphs should get the default face, to
19805 avoid painting the rest of the window with the region face,
19806 if the region ends at ZV. */
19807 if (it
->glyph_row
->ends_at_zv_p
)
19808 it
->face_id
= default_face
->id
;
19810 it
->face_id
= face
->id
;
19811 PRODUCE_GLYPHS (it
);
19813 while (it
->current_x
<= it
->last_visible_x
)
19814 PRODUCE_GLYPHS (it
);
19816 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19817 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19818 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19819 && !it
->glyph_row
->mode_line_p
19820 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19822 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
19823 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19825 for ( ; g
< e
; g
++)
19826 it
->current_x
+= g
->pixel_width
;
19828 it
->area
= RIGHT_MARGIN_AREA
;
19829 it
->face_id
= default_face
->id
;
19830 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19831 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19833 PRODUCE_GLYPHS (it
);
19834 it
->current_x
+= it
->pixel_width
;
19837 it
->area
= TEXT_AREA
;
19840 /* Don't count these blanks really. It would let us insert a left
19841 truncation glyph below and make us set the cursor on them, maybe. */
19842 it
->current_x
= saved_x
;
19843 it
->object
= saved_object
;
19844 it
->position
= saved_pos
;
19845 it
->what
= saved_what
;
19846 it
->face_id
= saved_face_id
;
19851 /* Value is true if text starting at CHARPOS in current_buffer is
19852 trailing whitespace. */
19855 trailing_whitespace_p (ptrdiff_t charpos
)
19857 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19860 while (bytepos
< ZV_BYTE
19861 && (c
= FETCH_CHAR (bytepos
),
19862 c
== ' ' || c
== '\t'))
19865 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19867 if (bytepos
!= PT_BYTE
)
19874 /* Highlight trailing whitespace, if any, in ROW. */
19877 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19879 int used
= row
->used
[TEXT_AREA
];
19883 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19884 struct glyph
*glyph
= start
+ used
- 1;
19886 if (row
->reversed_p
)
19888 /* Right-to-left rows need to be processed in the opposite
19889 direction, so swap the edge pointers. */
19891 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19894 /* Skip over glyphs inserted to display the cursor at the
19895 end of a line, for extending the face of the last glyph
19896 to the end of the line on terminals, and for truncation
19897 and continuation glyphs. */
19898 if (!row
->reversed_p
)
19900 while (glyph
>= start
19901 && glyph
->type
== CHAR_GLYPH
19902 && NILP (glyph
->object
))
19907 while (glyph
<= start
19908 && glyph
->type
== CHAR_GLYPH
19909 && NILP (glyph
->object
))
19913 /* If last glyph is a space or stretch, and it's trailing
19914 whitespace, set the face of all trailing whitespace glyphs in
19915 IT->glyph_row to `trailing-whitespace'. */
19916 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19917 && BUFFERP (glyph
->object
)
19918 && (glyph
->type
== STRETCH_GLYPH
19919 || (glyph
->type
== CHAR_GLYPH
19920 && glyph
->u
.ch
== ' '))
19921 && trailing_whitespace_p (glyph
->charpos
))
19923 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, false);
19927 if (!row
->reversed_p
)
19929 while (glyph
>= start
19930 && BUFFERP (glyph
->object
)
19931 && (glyph
->type
== STRETCH_GLYPH
19932 || (glyph
->type
== CHAR_GLYPH
19933 && glyph
->u
.ch
== ' ')))
19934 (glyph
--)->face_id
= face_id
;
19938 while (glyph
<= start
19939 && BUFFERP (glyph
->object
)
19940 && (glyph
->type
== STRETCH_GLYPH
19941 || (glyph
->type
== CHAR_GLYPH
19942 && glyph
->u
.ch
== ' ')))
19943 (glyph
++)->face_id
= face_id
;
19950 /* Value is true if glyph row ROW should be
19951 considered to hold the buffer position CHARPOS. */
19954 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19956 bool result
= true;
19958 if (charpos
== CHARPOS (row
->end
.pos
)
19959 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19961 /* Suppose the row ends on a string.
19962 Unless the row is continued, that means it ends on a newline
19963 in the string. If it's anything other than a display string
19964 (e.g., a before-string from an overlay), we don't want the
19965 cursor there. (This heuristic seems to give the optimal
19966 behavior for the various types of multi-line strings.)
19967 One exception: if the string has `cursor' property on one of
19968 its characters, we _do_ want the cursor there. */
19969 if (CHARPOS (row
->end
.string_pos
) >= 0)
19971 if (row
->continued_p
)
19975 /* Check for `display' property. */
19976 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19977 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19978 struct glyph
*glyph
;
19981 for (glyph
= end
; glyph
>= beg
; --glyph
)
19982 if (STRINGP (glyph
->object
))
19985 = Fget_char_property (make_number (charpos
),
19989 && display_prop_string_p (prop
, glyph
->object
));
19990 /* If there's a `cursor' property on one of the
19991 string's characters, this row is a cursor row,
19992 even though this is not a display string. */
19995 Lisp_Object s
= glyph
->object
;
19997 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19999 ptrdiff_t gpos
= glyph
->charpos
;
20001 if (!NILP (Fget_char_property (make_number (gpos
),
20013 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
20015 /* If the row ends in middle of a real character,
20016 and the line is continued, we want the cursor here.
20017 That's because CHARPOS (ROW->end.pos) would equal
20018 PT if PT is before the character. */
20019 if (!row
->ends_in_ellipsis_p
)
20020 result
= row
->continued_p
;
20022 /* If the row ends in an ellipsis, then
20023 CHARPOS (ROW->end.pos) will equal point after the
20024 invisible text. We want that position to be displayed
20025 after the ellipsis. */
20028 /* If the row ends at ZV, display the cursor at the end of that
20029 row instead of at the start of the row below. */
20031 result
= row
->ends_at_zv_p
;
20037 /* Value is true if glyph row ROW should be
20038 used to hold the cursor. */
20041 cursor_row_p (struct glyph_row
*row
)
20043 return row_for_charpos_p (row
, PT
);
20048 /* Push the property PROP so that it will be rendered at the current
20049 position in IT. Return true if PROP was successfully pushed, false
20050 otherwise. Called from handle_line_prefix to handle the
20051 `line-prefix' and `wrap-prefix' properties. */
20054 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
20056 struct text_pos pos
=
20057 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
20059 eassert (it
->method
== GET_FROM_BUFFER
20060 || it
->method
== GET_FROM_DISPLAY_VECTOR
20061 || it
->method
== GET_FROM_STRING
20062 || it
->method
== GET_FROM_IMAGE
);
20064 /* We need to save the current buffer/string position, so it will be
20065 restored by pop_it, because iterate_out_of_display_property
20066 depends on that being set correctly, but some situations leave
20067 it->position not yet set when this function is called. */
20068 push_it (it
, &pos
);
20070 if (STRINGP (prop
))
20072 if (SCHARS (prop
) == 0)
20079 it
->string_from_prefix_prop_p
= true;
20080 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
20081 it
->current
.overlay_string_index
= -1;
20082 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
20083 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
20084 it
->method
= GET_FROM_STRING
;
20085 it
->stop_charpos
= 0;
20087 it
->base_level_stop
= 0;
20089 /* Force paragraph direction to be that of the parent
20091 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
20092 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
20094 it
->paragraph_embedding
= L2R
;
20096 /* Set up the bidi iterator for this display string. */
20099 it
->bidi_it
.string
.lstring
= it
->string
;
20100 it
->bidi_it
.string
.s
= NULL
;
20101 it
->bidi_it
.string
.schars
= it
->end_charpos
;
20102 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
20103 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
20104 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
20105 it
->bidi_it
.w
= it
->w
;
20106 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
20109 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
20111 it
->method
= GET_FROM_STRETCH
;
20114 #ifdef HAVE_WINDOW_SYSTEM
20115 else if (IMAGEP (prop
))
20117 it
->what
= IT_IMAGE
;
20118 it
->image_id
= lookup_image (it
->f
, prop
);
20119 it
->method
= GET_FROM_IMAGE
;
20121 #endif /* HAVE_WINDOW_SYSTEM */
20124 pop_it (it
); /* bogus display property, give up */
20131 /* Return the character-property PROP at the current position in IT. */
20134 get_it_property (struct it
*it
, Lisp_Object prop
)
20136 Lisp_Object position
, object
= it
->object
;
20138 if (STRINGP (object
))
20139 position
= make_number (IT_STRING_CHARPOS (*it
));
20140 else if (BUFFERP (object
))
20142 position
= make_number (IT_CHARPOS (*it
));
20143 object
= it
->window
;
20148 return Fget_char_property (position
, prop
, object
);
20151 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
20154 handle_line_prefix (struct it
*it
)
20156 Lisp_Object prefix
;
20158 if (it
->continuation_lines_width
> 0)
20160 prefix
= get_it_property (it
, Qwrap_prefix
);
20162 prefix
= Vwrap_prefix
;
20166 prefix
= get_it_property (it
, Qline_prefix
);
20168 prefix
= Vline_prefix
;
20170 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
20172 /* If the prefix is wider than the window, and we try to wrap
20173 it, it would acquire its own wrap prefix, and so on till the
20174 iterator stack overflows. So, don't wrap the prefix. */
20175 it
->line_wrap
= TRUNCATE
;
20176 it
->avoid_cursor_p
= true;
20182 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
20183 only for R2L lines from display_line and display_string, when they
20184 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
20185 the line/string needs to be continued on the next glyph row. */
20187 unproduce_glyphs (struct it
*it
, int n
)
20189 struct glyph
*glyph
, *end
;
20191 eassert (it
->glyph_row
);
20192 eassert (it
->glyph_row
->reversed_p
);
20193 eassert (it
->area
== TEXT_AREA
);
20194 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
20196 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
20197 n
= it
->glyph_row
->used
[TEXT_AREA
];
20198 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
20199 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
20200 for ( ; glyph
< end
; glyph
++)
20201 glyph
[-n
] = *glyph
;
20204 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
20205 and ROW->maxpos. */
20207 find_row_edges (struct it
*it
, struct glyph_row
*row
,
20208 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
20209 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
20211 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20212 lines' rows is implemented for bidi-reordered rows. */
20214 /* ROW->minpos is the value of min_pos, the minimal buffer position
20215 we have in ROW, or ROW->start.pos if that is smaller. */
20216 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
20217 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
20219 /* We didn't find buffer positions smaller than ROW->start, or
20220 didn't find _any_ valid buffer positions in any of the glyphs,
20221 so we must trust the iterator's computed positions. */
20222 row
->minpos
= row
->start
.pos
;
20225 max_pos
= CHARPOS (it
->current
.pos
);
20226 max_bpos
= BYTEPOS (it
->current
.pos
);
20229 /* Here are the various use-cases for ending the row, and the
20230 corresponding values for ROW->maxpos:
20232 Line ends in a newline from buffer eol_pos + 1
20233 Line is continued from buffer max_pos + 1
20234 Line is truncated on right it->current.pos
20235 Line ends in a newline from string max_pos + 1(*)
20236 (*) + 1 only when line ends in a forward scan
20237 Line is continued from string max_pos
20238 Line is continued from display vector max_pos
20239 Line is entirely from a string min_pos == max_pos
20240 Line is entirely from a display vector min_pos == max_pos
20241 Line that ends at ZV ZV
20243 If you discover other use-cases, please add them here as
20245 if (row
->ends_at_zv_p
)
20246 row
->maxpos
= it
->current
.pos
;
20247 else if (row
->used
[TEXT_AREA
])
20249 bool seen_this_string
= false;
20250 struct glyph_row
*r1
= row
- 1;
20252 /* Did we see the same display string on the previous row? */
20253 if (STRINGP (it
->object
)
20254 /* this is not the first row */
20255 && row
> it
->w
->desired_matrix
->rows
20256 /* previous row is not the header line */
20257 && !r1
->mode_line_p
20258 /* previous row also ends in a newline from a string */
20259 && r1
->ends_in_newline_from_string_p
)
20261 struct glyph
*start
, *end
;
20263 /* Search for the last glyph of the previous row that came
20264 from buffer or string. Depending on whether the row is
20265 L2R or R2L, we need to process it front to back or the
20266 other way round. */
20267 if (!r1
->reversed_p
)
20269 start
= r1
->glyphs
[TEXT_AREA
];
20270 end
= start
+ r1
->used
[TEXT_AREA
];
20271 /* Glyphs inserted by redisplay have nil as their object. */
20273 && NILP ((end
- 1)->object
)
20274 && (end
- 1)->charpos
<= 0)
20278 if (EQ ((end
- 1)->object
, it
->object
))
20279 seen_this_string
= true;
20282 /* If all the glyphs of the previous row were inserted
20283 by redisplay, it means the previous row was
20284 produced from a single newline, which is only
20285 possible if that newline came from the same string
20286 as the one which produced this ROW. */
20287 seen_this_string
= true;
20291 end
= r1
->glyphs
[TEXT_AREA
] - 1;
20292 start
= end
+ r1
->used
[TEXT_AREA
];
20294 && NILP ((end
+ 1)->object
)
20295 && (end
+ 1)->charpos
<= 0)
20299 if (EQ ((end
+ 1)->object
, it
->object
))
20300 seen_this_string
= true;
20303 seen_this_string
= true;
20306 /* Take note of each display string that covers a newline only
20307 once, the first time we see it. This is for when a display
20308 string includes more than one newline in it. */
20309 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
20311 /* If we were scanning the buffer forward when we displayed
20312 the string, we want to account for at least one buffer
20313 position that belongs to this row (position covered by
20314 the display string), so that cursor positioning will
20315 consider this row as a candidate when point is at the end
20316 of the visual line represented by this row. This is not
20317 required when scanning back, because max_pos will already
20318 have a much larger value. */
20319 if (CHARPOS (row
->end
.pos
) > max_pos
)
20320 INC_BOTH (max_pos
, max_bpos
);
20321 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20323 else if (CHARPOS (it
->eol_pos
) > 0)
20324 SET_TEXT_POS (row
->maxpos
,
20325 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
20326 else if (row
->continued_p
)
20328 /* If max_pos is different from IT's current position, it
20329 means IT->method does not belong to the display element
20330 at max_pos. However, it also means that the display
20331 element at max_pos was displayed in its entirety on this
20332 line, which is equivalent to saying that the next line
20333 starts at the next buffer position. */
20334 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
20335 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20338 INC_BOTH (max_pos
, max_bpos
);
20339 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20342 else if (row
->truncated_on_right_p
)
20343 /* display_line already called reseat_at_next_visible_line_start,
20344 which puts the iterator at the beginning of the next line, in
20345 the logical order. */
20346 row
->maxpos
= it
->current
.pos
;
20347 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
20348 /* A line that is entirely from a string/image/stretch... */
20349 row
->maxpos
= row
->minpos
;
20354 row
->maxpos
= it
->current
.pos
;
20357 /* Construct the glyph row IT->glyph_row in the desired matrix of
20358 IT->w from text at the current position of IT. See dispextern.h
20359 for an overview of struct it. Value is true if
20360 IT->glyph_row displays text, as opposed to a line displaying ZV
20364 display_line (struct it
*it
)
20366 struct glyph_row
*row
= it
->glyph_row
;
20367 Lisp_Object overlay_arrow_string
;
20369 void *wrap_data
= NULL
;
20370 bool may_wrap
= false;
20371 int wrap_x
IF_LINT (= 0);
20372 int wrap_row_used
= -1;
20373 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
20374 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
20375 int wrap_row_extra_line_spacing
IF_LINT (= 0);
20376 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
20377 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
20379 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
20380 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
20381 bool pending_handle_line_prefix
= false;
20383 /* We always start displaying at hpos zero even if hscrolled. */
20384 eassert (it
->hpos
== 0 && it
->current_x
== 0);
20386 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
20387 >= it
->w
->desired_matrix
->nrows
)
20389 it
->w
->nrows_scale_factor
++;
20390 it
->f
->fonts_changed
= true;
20394 /* Clear the result glyph row and enable it. */
20395 prepare_desired_row (it
->w
, row
, false);
20397 row
->y
= it
->current_y
;
20398 row
->start
= it
->start
;
20399 row
->continuation_lines_width
= it
->continuation_lines_width
;
20400 row
->displays_text_p
= true;
20401 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
20402 it
->starts_in_middle_of_char_p
= false;
20404 /* Arrange the overlays nicely for our purposes. Usually, we call
20405 display_line on only one line at a time, in which case this
20406 can't really hurt too much, or we call it on lines which appear
20407 one after another in the buffer, in which case all calls to
20408 recenter_overlay_lists but the first will be pretty cheap. */
20409 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
20411 /* Move over display elements that are not visible because we are
20412 hscrolled. This may stop at an x-position < IT->first_visible_x
20413 if the first glyph is partially visible or if we hit a line end. */
20414 if (it
->current_x
< it
->first_visible_x
)
20416 enum move_it_result move_result
;
20418 this_line_min_pos
= row
->start
.pos
;
20419 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
20420 MOVE_TO_POS
| MOVE_TO_X
);
20421 /* If we are under a large hscroll, move_it_in_display_line_to
20422 could hit the end of the line without reaching
20423 it->first_visible_x. Pretend that we did reach it. This is
20424 especially important on a TTY, where we will call
20425 extend_face_to_end_of_line, which needs to know how many
20426 blank glyphs to produce. */
20427 if (it
->current_x
< it
->first_visible_x
20428 && (move_result
== MOVE_NEWLINE_OR_CR
20429 || move_result
== MOVE_POS_MATCH_OR_ZV
))
20430 it
->current_x
= it
->first_visible_x
;
20432 /* Record the smallest positions seen while we moved over
20433 display elements that are not visible. This is needed by
20434 redisplay_internal for optimizing the case where the cursor
20435 stays inside the same line. The rest of this function only
20436 considers positions that are actually displayed, so
20437 RECORD_MAX_MIN_POS will not otherwise record positions that
20438 are hscrolled to the left of the left edge of the window. */
20439 min_pos
= CHARPOS (this_line_min_pos
);
20440 min_bpos
= BYTEPOS (this_line_min_pos
);
20442 else if (it
->area
== TEXT_AREA
)
20444 /* We only do this when not calling move_it_in_display_line_to
20445 above, because that function calls itself handle_line_prefix. */
20446 handle_line_prefix (it
);
20450 /* Line-prefix and wrap-prefix are always displayed in the text
20451 area. But if this is the first call to display_line after
20452 init_iterator, the iterator might have been set up to write
20453 into a marginal area, e.g. if the line begins with some
20454 display property that writes to the margins. So we need to
20455 wait with the call to handle_line_prefix until whatever
20456 writes to the margin has done its job. */
20457 pending_handle_line_prefix
= true;
20460 /* Get the initial row height. This is either the height of the
20461 text hscrolled, if there is any, or zero. */
20462 row
->ascent
= it
->max_ascent
;
20463 row
->height
= it
->max_ascent
+ it
->max_descent
;
20464 row
->phys_ascent
= it
->max_phys_ascent
;
20465 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20466 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20468 /* Utility macro to record max and min buffer positions seen until now. */
20469 #define RECORD_MAX_MIN_POS(IT) \
20472 bool composition_p \
20473 = !STRINGP ((IT)->string) && ((IT)->what == IT_COMPOSITION); \
20474 ptrdiff_t current_pos = \
20475 composition_p ? (IT)->cmp_it.charpos \
20476 : IT_CHARPOS (*(IT)); \
20477 ptrdiff_t current_bpos = \
20478 composition_p ? CHAR_TO_BYTE (current_pos) \
20479 : IT_BYTEPOS (*(IT)); \
20480 if (current_pos < min_pos) \
20482 min_pos = current_pos; \
20483 min_bpos = current_bpos; \
20485 if (IT_CHARPOS (*it) > max_pos) \
20487 max_pos = IT_CHARPOS (*it); \
20488 max_bpos = IT_BYTEPOS (*it); \
20493 /* Loop generating characters. The loop is left with IT on the next
20494 character to display. */
20497 int n_glyphs_before
, hpos_before
, x_before
;
20499 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
20501 /* Retrieve the next thing to display. Value is false if end of
20503 if (!get_next_display_element (it
))
20505 /* Maybe add a space at the end of this line that is used to
20506 display the cursor there under X. Set the charpos of the
20507 first glyph of blank lines not corresponding to any text
20509 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20510 row
->exact_window_width_line_p
= true;
20511 else if ((append_space_for_newline (it
, true)
20512 && row
->used
[TEXT_AREA
] == 1)
20513 || row
->used
[TEXT_AREA
] == 0)
20515 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
20516 row
->displays_text_p
= false;
20518 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
20519 && (!MINI_WINDOW_P (it
->w
)
20520 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
20521 row
->indicate_empty_line_p
= true;
20524 it
->continuation_lines_width
= 0;
20525 row
->ends_at_zv_p
= true;
20526 /* A row that displays right-to-left text must always have
20527 its last face extended all the way to the end of line,
20528 even if this row ends in ZV, because we still write to
20529 the screen left to right. We also need to extend the
20530 last face if the default face is remapped to some
20531 different face, otherwise the functions that clear
20532 portions of the screen will clear with the default face's
20533 background color. */
20534 if (row
->reversed_p
20535 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
20536 extend_face_to_end_of_line (it
);
20540 /* Now, get the metrics of what we want to display. This also
20541 generates glyphs in `row' (which is IT->glyph_row). */
20542 n_glyphs_before
= row
->used
[TEXT_AREA
];
20545 /* Remember the line height so far in case the next element doesn't
20546 fit on the line. */
20547 if (it
->line_wrap
!= TRUNCATE
)
20549 ascent
= it
->max_ascent
;
20550 descent
= it
->max_descent
;
20551 phys_ascent
= it
->max_phys_ascent
;
20552 phys_descent
= it
->max_phys_descent
;
20554 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
20556 if (IT_DISPLAYING_WHITESPACE (it
))
20560 SAVE_IT (wrap_it
, *it
, wrap_data
);
20562 wrap_row_used
= row
->used
[TEXT_AREA
];
20563 wrap_row_ascent
= row
->ascent
;
20564 wrap_row_height
= row
->height
;
20565 wrap_row_phys_ascent
= row
->phys_ascent
;
20566 wrap_row_phys_height
= row
->phys_height
;
20567 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
20568 wrap_row_min_pos
= min_pos
;
20569 wrap_row_min_bpos
= min_bpos
;
20570 wrap_row_max_pos
= max_pos
;
20571 wrap_row_max_bpos
= max_bpos
;
20577 PRODUCE_GLYPHS (it
);
20579 /* If this display element was in marginal areas, continue with
20581 if (it
->area
!= TEXT_AREA
)
20583 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20584 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20585 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20586 row
->phys_height
= max (row
->phys_height
,
20587 it
->max_phys_ascent
+ it
->max_phys_descent
);
20588 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20589 it
->max_extra_line_spacing
);
20590 set_iterator_to_next (it
, true);
20591 /* If we didn't handle the line/wrap prefix above, and the
20592 call to set_iterator_to_next just switched to TEXT_AREA,
20593 process the prefix now. */
20594 if (it
->area
== TEXT_AREA
&& pending_handle_line_prefix
)
20596 pending_handle_line_prefix
= false;
20597 handle_line_prefix (it
);
20602 /* Does the display element fit on the line? If we truncate
20603 lines, we should draw past the right edge of the window. If
20604 we don't truncate, we want to stop so that we can display the
20605 continuation glyph before the right margin. If lines are
20606 continued, there are two possible strategies for characters
20607 resulting in more than 1 glyph (e.g. tabs): Display as many
20608 glyphs as possible in this line and leave the rest for the
20609 continuation line, or display the whole element in the next
20610 line. Original redisplay did the former, so we do it also. */
20611 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20612 hpos_before
= it
->hpos
;
20615 if (/* Not a newline. */
20617 /* Glyphs produced fit entirely in the line. */
20618 && it
->current_x
< it
->last_visible_x
)
20620 it
->hpos
+= nglyphs
;
20621 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20622 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20623 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20624 row
->phys_height
= max (row
->phys_height
,
20625 it
->max_phys_ascent
+ it
->max_phys_descent
);
20626 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20627 it
->max_extra_line_spacing
);
20628 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
20629 /* In R2L rows, we arrange in extend_face_to_end_of_line
20630 to add a right offset to the line, by a suitable
20631 change to the stretch glyph that is the leftmost
20632 glyph of the line. */
20633 && !row
->reversed_p
)
20634 row
->x
= x
- it
->first_visible_x
;
20635 /* Record the maximum and minimum buffer positions seen so
20636 far in glyphs that will be displayed by this row. */
20638 RECORD_MAX_MIN_POS (it
);
20643 struct glyph
*glyph
;
20645 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
20647 /* Identify the glyphs added by the last call to
20648 PRODUCE_GLYPHS. In R2L rows, they are prepended to
20649 the previous glyphs. */
20650 if (!row
->reversed_p
)
20651 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20653 glyph
= row
->glyphs
[TEXT_AREA
] + nglyphs
- 1 - i
;
20654 new_x
= x
+ glyph
->pixel_width
;
20656 if (/* Lines are continued. */
20657 it
->line_wrap
!= TRUNCATE
20658 && (/* Glyph doesn't fit on the line. */
20659 new_x
> it
->last_visible_x
20660 /* Or it fits exactly on a window system frame. */
20661 || (new_x
== it
->last_visible_x
20662 && FRAME_WINDOW_P (it
->f
)
20663 && (row
->reversed_p
20664 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20665 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
20667 /* End of a continued line. */
20670 || (new_x
== it
->last_visible_x
20671 && FRAME_WINDOW_P (it
->f
)
20672 && (row
->reversed_p
20673 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20674 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
20676 /* Current glyph is the only one on the line or
20677 fits exactly on the line. We must continue
20678 the line because we can't draw the cursor
20679 after the glyph. */
20680 row
->continued_p
= true;
20681 it
->current_x
= new_x
;
20682 it
->continuation_lines_width
+= new_x
;
20684 if (i
== nglyphs
- 1)
20686 /* If line-wrap is on, check if a previous
20687 wrap point was found. */
20688 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)
20689 && wrap_row_used
> 0
20690 /* Even if there is a previous wrap
20691 point, continue the line here as
20692 usual, if (i) the previous character
20693 was a space or tab AND (ii) the
20694 current character is not. */
20696 || IT_DISPLAYING_WHITESPACE (it
)))
20699 /* Record the maximum and minimum buffer
20700 positions seen so far in glyphs that will be
20701 displayed by this row. */
20703 RECORD_MAX_MIN_POS (it
);
20704 set_iterator_to_next (it
, true);
20705 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20707 if (!get_next_display_element (it
))
20709 row
->exact_window_width_line_p
= true;
20710 it
->continuation_lines_width
= 0;
20711 row
->continued_p
= false;
20712 row
->ends_at_zv_p
= true;
20714 else if (ITERATOR_AT_END_OF_LINE_P (it
))
20716 row
->continued_p
= false;
20717 row
->exact_window_width_line_p
= true;
20719 /* If line-wrap is on, check if a
20720 previous wrap point was found. */
20721 else if (wrap_row_used
> 0
20722 /* Even if there is a previous wrap
20723 point, continue the line here as
20724 usual, if (i) the previous character
20725 was a space or tab AND (ii) the
20726 current character is not. */
20728 || IT_DISPLAYING_WHITESPACE (it
)))
20733 else if (it
->bidi_p
)
20734 RECORD_MAX_MIN_POS (it
);
20735 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20736 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20737 extend_face_to_end_of_line (it
);
20739 else if (CHAR_GLYPH_PADDING_P (*glyph
)
20740 && !FRAME_WINDOW_P (it
->f
))
20742 /* A padding glyph that doesn't fit on this line.
20743 This means the whole character doesn't fit
20745 if (row
->reversed_p
)
20746 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20747 - n_glyphs_before
);
20748 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20750 /* Fill the rest of the row with continuation
20751 glyphs like in 20.x. */
20752 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
20753 < row
->glyphs
[1 + TEXT_AREA
])
20754 produce_special_glyphs (it
, IT_CONTINUATION
);
20756 row
->continued_p
= true;
20757 it
->current_x
= x_before
;
20758 it
->continuation_lines_width
+= x_before
;
20760 /* Restore the height to what it was before the
20761 element not fitting on the line. */
20762 it
->max_ascent
= ascent
;
20763 it
->max_descent
= descent
;
20764 it
->max_phys_ascent
= phys_ascent
;
20765 it
->max_phys_descent
= phys_descent
;
20766 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20767 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20768 extend_face_to_end_of_line (it
);
20770 else if (wrap_row_used
> 0)
20773 if (row
->reversed_p
)
20774 unproduce_glyphs (it
,
20775 row
->used
[TEXT_AREA
] - wrap_row_used
);
20776 RESTORE_IT (it
, &wrap_it
, wrap_data
);
20777 it
->continuation_lines_width
+= wrap_x
;
20778 row
->used
[TEXT_AREA
] = wrap_row_used
;
20779 row
->ascent
= wrap_row_ascent
;
20780 row
->height
= wrap_row_height
;
20781 row
->phys_ascent
= wrap_row_phys_ascent
;
20782 row
->phys_height
= wrap_row_phys_height
;
20783 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
20784 min_pos
= wrap_row_min_pos
;
20785 min_bpos
= wrap_row_min_bpos
;
20786 max_pos
= wrap_row_max_pos
;
20787 max_bpos
= wrap_row_max_bpos
;
20788 row
->continued_p
= true;
20789 row
->ends_at_zv_p
= false;
20790 row
->exact_window_width_line_p
= false;
20791 it
->continuation_lines_width
+= x
;
20793 /* Make sure that a non-default face is extended
20794 up to the right margin of the window. */
20795 extend_face_to_end_of_line (it
);
20797 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
20799 /* A TAB that extends past the right edge of the
20800 window. This produces a single glyph on
20801 window system frames. We leave the glyph in
20802 this row and let it fill the row, but don't
20803 consume the TAB. */
20804 if ((row
->reversed_p
20805 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20806 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20807 produce_special_glyphs (it
, IT_CONTINUATION
);
20808 it
->continuation_lines_width
+= it
->last_visible_x
;
20809 row
->ends_in_middle_of_char_p
= true;
20810 row
->continued_p
= true;
20811 glyph
->pixel_width
= it
->last_visible_x
- x
;
20812 it
->starts_in_middle_of_char_p
= true;
20813 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20814 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20815 extend_face_to_end_of_line (it
);
20819 /* Something other than a TAB that draws past
20820 the right edge of the window. Restore
20821 positions to values before the element. */
20822 if (row
->reversed_p
)
20823 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20824 - (n_glyphs_before
+ i
));
20825 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20827 /* Display continuation glyphs. */
20828 it
->current_x
= x_before
;
20829 it
->continuation_lines_width
+= x
;
20830 if (!FRAME_WINDOW_P (it
->f
)
20831 || (row
->reversed_p
20832 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20833 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20834 produce_special_glyphs (it
, IT_CONTINUATION
);
20835 row
->continued_p
= true;
20837 extend_face_to_end_of_line (it
);
20839 if (nglyphs
> 1 && i
> 0)
20841 row
->ends_in_middle_of_char_p
= true;
20842 it
->starts_in_middle_of_char_p
= true;
20845 /* Restore the height to what it was before the
20846 element not fitting on the line. */
20847 it
->max_ascent
= ascent
;
20848 it
->max_descent
= descent
;
20849 it
->max_phys_ascent
= phys_ascent
;
20850 it
->max_phys_descent
= phys_descent
;
20855 else if (new_x
> it
->first_visible_x
)
20857 /* Increment number of glyphs actually displayed. */
20860 /* Record the maximum and minimum buffer positions
20861 seen so far in glyphs that will be displayed by
20864 RECORD_MAX_MIN_POS (it
);
20866 if (x
< it
->first_visible_x
&& !row
->reversed_p
)
20867 /* Glyph is partially visible, i.e. row starts at
20868 negative X position. Don't do that in R2L
20869 rows, where we arrange to add a right offset to
20870 the line in extend_face_to_end_of_line, by a
20871 suitable change to the stretch glyph that is
20872 the leftmost glyph of the line. */
20873 row
->x
= x
- it
->first_visible_x
;
20874 /* When the last glyph of an R2L row only fits
20875 partially on the line, we need to set row->x to a
20876 negative offset, so that the leftmost glyph is
20877 the one that is partially visible. But if we are
20878 going to produce the truncation glyph, this will
20879 be taken care of in produce_special_glyphs. */
20880 if (row
->reversed_p
20881 && new_x
> it
->last_visible_x
20882 && !(it
->line_wrap
== TRUNCATE
20883 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
20885 eassert (FRAME_WINDOW_P (it
->f
));
20886 row
->x
= it
->last_visible_x
- new_x
;
20891 /* Glyph is completely off the left margin of the
20892 window. This should not happen because of the
20893 move_it_in_display_line at the start of this
20894 function, unless the text display area of the
20895 window is empty. */
20896 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20899 /* Even if this display element produced no glyphs at all,
20900 we want to record its position. */
20901 if (it
->bidi_p
&& nglyphs
== 0)
20902 RECORD_MAX_MIN_POS (it
);
20904 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20905 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20906 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20907 row
->phys_height
= max (row
->phys_height
,
20908 it
->max_phys_ascent
+ it
->max_phys_descent
);
20909 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20910 it
->max_extra_line_spacing
);
20912 /* End of this display line if row is continued. */
20913 if (row
->continued_p
|| row
->ends_at_zv_p
)
20918 /* Is this a line end? If yes, we're also done, after making
20919 sure that a non-default face is extended up to the right
20920 margin of the window. */
20921 if (ITERATOR_AT_END_OF_LINE_P (it
))
20923 int used_before
= row
->used
[TEXT_AREA
];
20925 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
20927 /* Add a space at the end of the line that is used to
20928 display the cursor there. */
20929 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20930 append_space_for_newline (it
, false);
20932 /* Extend the face to the end of the line. */
20933 extend_face_to_end_of_line (it
);
20935 /* Make sure we have the position. */
20936 if (used_before
== 0)
20937 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
20939 /* Record the position of the newline, for use in
20941 it
->eol_pos
= it
->current
.pos
;
20943 /* Consume the line end. This skips over invisible lines. */
20944 set_iterator_to_next (it
, true);
20945 it
->continuation_lines_width
= 0;
20949 /* Proceed with next display element. Note that this skips
20950 over lines invisible because of selective display. */
20951 set_iterator_to_next (it
, true);
20953 /* If we truncate lines, we are done when the last displayed
20954 glyphs reach past the right margin of the window. */
20955 if (it
->line_wrap
== TRUNCATE
20956 && ((FRAME_WINDOW_P (it
->f
)
20957 /* Images are preprocessed in produce_image_glyph such
20958 that they are cropped at the right edge of the
20959 window, so an image glyph will always end exactly at
20960 last_visible_x, even if there's no right fringe. */
20961 && ((row
->reversed_p
20962 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20963 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))
20964 || it
->what
== IT_IMAGE
))
20965 ? (it
->current_x
>= it
->last_visible_x
)
20966 : (it
->current_x
> it
->last_visible_x
)))
20968 /* Maybe add truncation glyphs. */
20969 if (!FRAME_WINDOW_P (it
->f
)
20970 || (row
->reversed_p
20971 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20972 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20976 if (!row
->reversed_p
)
20978 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20979 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20984 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20985 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20987 /* Remove any padding glyphs at the front of ROW, to
20988 make room for the truncation glyphs we will be
20989 adding below. The loop below always inserts at
20990 least one truncation glyph, so also remove the
20991 last glyph added to ROW. */
20992 unproduce_glyphs (it
, i
+ 1);
20993 /* Adjust i for the loop below. */
20994 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20997 /* produce_special_glyphs overwrites the last glyph, so
20998 we don't want that if we want to keep that last
20999 glyph, which means it's an image. */
21000 if (it
->current_x
> it
->last_visible_x
)
21002 it
->current_x
= x_before
;
21003 if (!FRAME_WINDOW_P (it
->f
))
21005 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
21007 row
->used
[TEXT_AREA
] = i
;
21008 produce_special_glyphs (it
, IT_TRUNCATION
);
21013 row
->used
[TEXT_AREA
] = i
;
21014 produce_special_glyphs (it
, IT_TRUNCATION
);
21016 it
->hpos
= hpos_before
;
21019 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
21021 /* Don't truncate if we can overflow newline into fringe. */
21022 if (!get_next_display_element (it
))
21024 it
->continuation_lines_width
= 0;
21025 row
->ends_at_zv_p
= true;
21026 row
->exact_window_width_line_p
= true;
21029 if (ITERATOR_AT_END_OF_LINE_P (it
))
21031 row
->exact_window_width_line_p
= true;
21032 goto at_end_of_line
;
21034 it
->current_x
= x_before
;
21035 it
->hpos
= hpos_before
;
21038 row
->truncated_on_right_p
= true;
21039 it
->continuation_lines_width
= 0;
21040 reseat_at_next_visible_line_start (it
, false);
21041 /* We insist below that IT's position be at ZV because in
21042 bidi-reordered lines the character at visible line start
21043 might not be the character that follows the newline in
21044 the logical order. */
21045 if (IT_BYTEPOS (*it
) > BEG_BYTE
)
21046 row
->ends_at_zv_p
=
21047 IT_BYTEPOS (*it
) >= ZV_BYTE
&& FETCH_BYTE (ZV_BYTE
- 1) != '\n';
21049 row
->ends_at_zv_p
= false;
21055 bidi_unshelve_cache (wrap_data
, true);
21057 /* If line is not empty and hscrolled, maybe insert truncation glyphs
21058 at the left window margin. */
21059 if (it
->first_visible_x
21060 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
21062 if (!FRAME_WINDOW_P (it
->f
)
21063 || (((row
->reversed_p
21064 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21065 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
21066 /* Don't let insert_left_trunc_glyphs overwrite the
21067 first glyph of the row if it is an image. */
21068 && row
->glyphs
[TEXT_AREA
]->type
!= IMAGE_GLYPH
))
21069 insert_left_trunc_glyphs (it
);
21070 row
->truncated_on_left_p
= true;
21073 /* Remember the position at which this line ends.
21075 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
21076 cannot be before the call to find_row_edges below, since that is
21077 where these positions are determined. */
21078 row
->end
= it
->current
;
21081 row
->minpos
= row
->start
.pos
;
21082 row
->maxpos
= row
->end
.pos
;
21086 /* ROW->minpos and ROW->maxpos must be the smallest and
21087 `1 + the largest' buffer positions in ROW. But if ROW was
21088 bidi-reordered, these two positions can be anywhere in the
21089 row, so we must determine them now. */
21090 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
21093 /* If the start of this line is the overlay arrow-position, then
21094 mark this glyph row as the one containing the overlay arrow.
21095 This is clearly a mess with variable size fonts. It would be
21096 better to let it be displayed like cursors under X. */
21097 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
21098 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
21099 !NILP (overlay_arrow_string
)))
21101 /* Overlay arrow in window redisplay is a fringe bitmap. */
21102 if (STRINGP (overlay_arrow_string
))
21104 struct glyph_row
*arrow_row
21105 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
21106 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
21107 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
21108 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
21109 struct glyph
*p2
, *end
;
21111 /* Copy the arrow glyphs. */
21112 while (glyph
< arrow_end
)
21115 /* Throw away padding glyphs. */
21117 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
21118 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
21124 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
21129 eassert (INTEGERP (overlay_arrow_string
));
21130 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
21132 overlay_arrow_seen
= true;
21135 /* Highlight trailing whitespace. */
21136 if (!NILP (Vshow_trailing_whitespace
))
21137 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
21139 /* Compute pixel dimensions of this line. */
21140 compute_line_metrics (it
);
21142 /* Implementation note: No changes in the glyphs of ROW or in their
21143 faces can be done past this point, because compute_line_metrics
21144 computes ROW's hash value and stores it within the glyph_row
21147 /* Record whether this row ends inside an ellipsis. */
21148 row
->ends_in_ellipsis_p
21149 = (it
->method
== GET_FROM_DISPLAY_VECTOR
21150 && it
->ellipsis_p
);
21152 /* Save fringe bitmaps in this row. */
21153 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
21154 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
21155 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
21156 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
21158 it
->left_user_fringe_bitmap
= 0;
21159 it
->left_user_fringe_face_id
= 0;
21160 it
->right_user_fringe_bitmap
= 0;
21161 it
->right_user_fringe_face_id
= 0;
21163 /* Maybe set the cursor. */
21164 cvpos
= it
->w
->cursor
.vpos
;
21166 /* In bidi-reordered rows, keep checking for proper cursor
21167 position even if one has been found already, because buffer
21168 positions in such rows change non-linearly with ROW->VPOS,
21169 when a line is continued. One exception: when we are at ZV,
21170 display cursor on the first suitable glyph row, since all
21171 the empty rows after that also have their position set to ZV. */
21172 /* FIXME: Revisit this when glyph ``spilling'' in continuation
21173 lines' rows is implemented for bidi-reordered rows. */
21175 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
21176 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
21177 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
21178 && cursor_row_p (row
))
21179 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
21181 /* Prepare for the next line. This line starts horizontally at (X
21182 HPOS) = (0 0). Vertical positions are incremented. As a
21183 convenience for the caller, IT->glyph_row is set to the next
21185 it
->current_x
= it
->hpos
= 0;
21186 it
->current_y
+= row
->height
;
21187 SET_TEXT_POS (it
->eol_pos
, 0, 0);
21190 /* The next row should by default use the same value of the
21191 reversed_p flag as this one. set_iterator_to_next decides when
21192 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
21193 the flag accordingly. */
21194 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
21195 it
->glyph_row
->reversed_p
= row
->reversed_p
;
21196 it
->start
= row
->end
;
21197 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
21199 #undef RECORD_MAX_MIN_POS
21202 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
21203 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
21204 doc
: /* Return paragraph direction at point in BUFFER.
21205 Value is either `left-to-right' or `right-to-left'.
21206 If BUFFER is omitted or nil, it defaults to the current buffer.
21208 Paragraph direction determines how the text in the paragraph is displayed.
21209 In left-to-right paragraphs, text begins at the left margin of the window
21210 and the reading direction is generally left to right. In right-to-left
21211 paragraphs, text begins at the right margin and is read from right to left.
21213 See also `bidi-paragraph-direction'. */)
21214 (Lisp_Object buffer
)
21216 struct buffer
*buf
= current_buffer
;
21217 struct buffer
*old
= buf
;
21219 if (! NILP (buffer
))
21221 CHECK_BUFFER (buffer
);
21222 buf
= XBUFFER (buffer
);
21225 if (NILP (BVAR (buf
, bidi_display_reordering
))
21226 || NILP (BVAR (buf
, enable_multibyte_characters
))
21227 /* When we are loading loadup.el, the character property tables
21228 needed for bidi iteration are not yet available. */
21229 || !NILP (Vpurify_flag
))
21230 return Qleft_to_right
;
21231 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
21232 return BVAR (buf
, bidi_paragraph_direction
);
21235 /* Determine the direction from buffer text. We could try to
21236 use current_matrix if it is up to date, but this seems fast
21237 enough as it is. */
21238 struct bidi_it itb
;
21239 ptrdiff_t pos
= BUF_PT (buf
);
21240 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
21242 void *itb_data
= bidi_shelve_cache ();
21244 set_buffer_temp (buf
);
21245 /* bidi_paragraph_init finds the base direction of the paragraph
21246 by searching forward from paragraph start. We need the base
21247 direction of the current or _previous_ paragraph, so we need
21248 to make sure we are within that paragraph. To that end, find
21249 the previous non-empty line. */
21250 if (pos
>= ZV
&& pos
> BEGV
)
21251 DEC_BOTH (pos
, bytepos
);
21252 AUTO_STRING (trailing_white_space
, "[\f\t ]*\n");
21253 if (fast_looking_at (trailing_white_space
,
21254 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
21256 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
21257 || c
== ' ' || c
== '\t' || c
== '\f')
21259 if (bytepos
<= BEGV_BYTE
)
21264 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
21267 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
21268 itb
.paragraph_dir
= NEUTRAL_DIR
;
21269 itb
.string
.s
= NULL
;
21270 itb
.string
.lstring
= Qnil
;
21271 itb
.string
.bufpos
= 0;
21272 itb
.string
.from_disp_str
= false;
21273 itb
.string
.unibyte
= false;
21274 /* We have no window to use here for ignoring window-specific
21275 overlays. Using NULL for window pointer will cause
21276 compute_display_string_pos to use the current buffer. */
21278 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, true);
21279 bidi_unshelve_cache (itb_data
, false);
21280 set_buffer_temp (old
);
21281 switch (itb
.paragraph_dir
)
21284 return Qleft_to_right
;
21287 return Qright_to_left
;
21295 DEFUN ("bidi-find-overridden-directionality",
21296 Fbidi_find_overridden_directionality
,
21297 Sbidi_find_overridden_directionality
, 2, 3, 0,
21298 doc
: /* Return position between FROM and TO where directionality was overridden.
21300 This function returns the first character position in the specified
21301 region of OBJECT where there is a character whose `bidi-class' property
21302 is `L', but which was forced to display as `R' by a directional
21303 override, and likewise with characters whose `bidi-class' is `R'
21304 or `AL' that were forced to display as `L'.
21306 If no such character is found, the function returns nil.
21308 OBJECT is a Lisp string or buffer to search for overridden
21309 directionality, and defaults to the current buffer if nil or omitted.
21310 OBJECT can also be a window, in which case the function will search
21311 the buffer displayed in that window. Passing the window instead of
21312 a buffer is preferable when the buffer is displayed in some window,
21313 because this function will then be able to correctly account for
21314 window-specific overlays, which can affect the results.
21316 Strong directional characters `L', `R', and `AL' can have their
21317 intrinsic directionality overridden by directional override
21318 control characters RLO (u+202e) and LRO (u+202d). See the
21319 function `get-char-code-property' for a way to inquire about
21320 the `bidi-class' property of a character. */)
21321 (Lisp_Object from
, Lisp_Object to
, Lisp_Object object
)
21323 struct buffer
*buf
= current_buffer
;
21324 struct buffer
*old
= buf
;
21325 struct window
*w
= NULL
;
21326 bool frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ());
21327 struct bidi_it itb
;
21328 ptrdiff_t from_pos
, to_pos
, from_bpos
;
21331 if (!NILP (object
))
21333 if (BUFFERP (object
))
21334 buf
= XBUFFER (object
);
21335 else if (WINDOWP (object
))
21337 w
= decode_live_window (object
);
21338 buf
= XBUFFER (w
->contents
);
21339 frame_window_p
= FRAME_WINDOW_P (XFRAME (w
->frame
));
21342 CHECK_STRING (object
);
21345 if (STRINGP (object
))
21347 /* Characters in unibyte strings are always treated by bidi.c as
21349 if (!STRING_MULTIBYTE (object
)
21350 /* When we are loading loadup.el, the character property
21351 tables needed for bidi iteration are not yet
21353 || !NILP (Vpurify_flag
))
21356 validate_subarray (object
, from
, to
, SCHARS (object
), &from_pos
, &to_pos
);
21357 if (from_pos
>= SCHARS (object
))
21360 /* Set up the bidi iterator. */
21361 itb_data
= bidi_shelve_cache ();
21362 itb
.paragraph_dir
= NEUTRAL_DIR
;
21363 itb
.string
.lstring
= object
;
21364 itb
.string
.s
= NULL
;
21365 itb
.string
.schars
= SCHARS (object
);
21366 itb
.string
.bufpos
= 0;
21367 itb
.string
.from_disp_str
= false;
21368 itb
.string
.unibyte
= false;
21370 bidi_init_it (0, 0, frame_window_p
, &itb
);
21374 /* Nothing this fancy can happen in unibyte buffers, or in a
21375 buffer that disabled reordering, or if FROM is at EOB. */
21376 if (NILP (BVAR (buf
, bidi_display_reordering
))
21377 || NILP (BVAR (buf
, enable_multibyte_characters
))
21378 /* When we are loading loadup.el, the character property
21379 tables needed for bidi iteration are not yet
21381 || !NILP (Vpurify_flag
))
21384 set_buffer_temp (buf
);
21385 validate_region (&from
, &to
);
21386 from_pos
= XINT (from
);
21387 to_pos
= XINT (to
);
21388 if (from_pos
>= ZV
)
21391 /* Set up the bidi iterator. */
21392 itb_data
= bidi_shelve_cache ();
21393 from_bpos
= CHAR_TO_BYTE (from_pos
);
21394 if (from_pos
== BEGV
)
21396 itb
.charpos
= BEGV
;
21397 itb
.bytepos
= BEGV_BYTE
;
21399 else if (FETCH_CHAR (from_bpos
- 1) == '\n')
21401 itb
.charpos
= from_pos
;
21402 itb
.bytepos
= from_bpos
;
21405 itb
.charpos
= find_newline_no_quit (from_pos
, CHAR_TO_BYTE (from_pos
),
21407 itb
.paragraph_dir
= NEUTRAL_DIR
;
21408 itb
.string
.s
= NULL
;
21409 itb
.string
.lstring
= Qnil
;
21410 itb
.string
.bufpos
= 0;
21411 itb
.string
.from_disp_str
= false;
21412 itb
.string
.unibyte
= false;
21414 bidi_init_it (itb
.charpos
, itb
.bytepos
, frame_window_p
, &itb
);
21419 /* For the purposes of this function, the actual base direction of
21420 the paragraph doesn't matter, so just set it to L2R. */
21421 bidi_paragraph_init (L2R
, &itb
, false);
21422 while ((found
= bidi_find_first_overridden (&itb
)) < from_pos
)
21424 } while (found
== ZV
&& itb
.ch
== '\n' && itb
.charpos
< to_pos
);
21426 bidi_unshelve_cache (itb_data
, false);
21427 set_buffer_temp (old
);
21429 return (from_pos
<= found
&& found
< to_pos
) ? make_number (found
) : Qnil
;
21432 DEFUN ("move-point-visually", Fmove_point_visually
,
21433 Smove_point_visually
, 1, 1, 0,
21434 doc
: /* Move point in the visual order in the specified DIRECTION.
21435 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
21438 Value is the new character position of point. */)
21439 (Lisp_Object direction
)
21441 struct window
*w
= XWINDOW (selected_window
);
21442 struct buffer
*b
= XBUFFER (w
->contents
);
21443 struct glyph_row
*row
;
21445 Lisp_Object paragraph_dir
;
21447 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
21448 (!(ROW)->continued_p \
21449 && NILP ((GLYPH)->object) \
21450 && (GLYPH)->type == CHAR_GLYPH \
21451 && (GLYPH)->u.ch == ' ' \
21452 && (GLYPH)->charpos >= 0 \
21453 && !(GLYPH)->avoid_cursor_p)
21455 CHECK_NUMBER (direction
);
21456 dir
= XINT (direction
);
21462 /* If current matrix is up-to-date, we can use the information
21463 recorded in the glyphs, at least as long as the goal is on the
21465 if (w
->window_end_valid
21466 && !windows_or_buffers_changed
21468 && !b
->clip_changed
21469 && !b
->prevent_redisplay_optimizations_p
21470 && !window_outdated (w
)
21471 /* We rely below on the cursor coordinates to be up to date, but
21472 we cannot trust them if some command moved point since the
21473 last complete redisplay. */
21474 && w
->last_point
== BUF_PT (b
)
21475 && w
->cursor
.vpos
>= 0
21476 && w
->cursor
.vpos
< w
->current_matrix
->nrows
21477 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
21479 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
21480 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
21481 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
21483 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
21485 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
21487 SET_PT (g
->charpos
);
21488 w
->cursor
.vpos
= -1;
21489 return make_number (PT
);
21491 else if (!NILP (g
->object
) && !EQ (g
->object
, gpt
->object
))
21495 if (BUFFERP (gpt
->object
))
21498 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
21499 new_pos
+= (row
->reversed_p
? -dir
: dir
);
21501 new_pos
-= (row
->reversed_p
? -dir
: dir
);
21503 else if (BUFFERP (g
->object
))
21504 new_pos
= g
->charpos
;
21508 w
->cursor
.vpos
= -1;
21509 return make_number (PT
);
21511 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
21513 /* Glyphs inserted at the end of a non-empty line for
21514 positioning the cursor have zero charpos, so we must
21515 deduce the value of point by other means. */
21516 if (g
->charpos
> 0)
21517 SET_PT (g
->charpos
);
21518 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
21520 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
21521 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21524 w
->cursor
.vpos
= -1;
21525 return make_number (PT
);
21528 if (g
== e
|| NILP (g
->object
))
21530 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
21531 goto simulate_display
;
21532 if (!row
->reversed_p
)
21536 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
21537 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
21538 goto simulate_display
;
21542 if (row
->reversed_p
&& !row
->continued_p
)
21544 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21545 w
->cursor
.vpos
= -1;
21546 return make_number (PT
);
21548 g
= row
->glyphs
[TEXT_AREA
];
21549 e
= g
+ row
->used
[TEXT_AREA
];
21550 for ( ; g
< e
; g
++)
21552 if (BUFFERP (g
->object
)
21553 /* Empty lines have only one glyph, which stands
21554 for the newline, and whose charpos is the
21555 buffer position of the newline. */
21556 || ROW_GLYPH_NEWLINE_P (row
, g
)
21557 /* When the buffer ends in a newline, the line at
21558 EOB also has one glyph, but its charpos is -1. */
21559 || (row
->ends_at_zv_p
21560 && !row
->reversed_p
21561 && NILP (g
->object
)
21562 && g
->type
== CHAR_GLYPH
21563 && g
->u
.ch
== ' '))
21565 if (g
->charpos
> 0)
21566 SET_PT (g
->charpos
);
21567 else if (!row
->reversed_p
21568 && row
->ends_at_zv_p
21573 w
->cursor
.vpos
= -1;
21574 return make_number (PT
);
21580 if (!row
->reversed_p
&& !row
->continued_p
)
21582 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21583 w
->cursor
.vpos
= -1;
21584 return make_number (PT
);
21586 e
= row
->glyphs
[TEXT_AREA
];
21587 g
= e
+ row
->used
[TEXT_AREA
] - 1;
21588 for ( ; g
>= e
; g
--)
21590 if (BUFFERP (g
->object
)
21591 || (ROW_GLYPH_NEWLINE_P (row
, g
)
21593 /* Empty R2L lines on GUI frames have the buffer
21594 position of the newline stored in the stretch
21596 || g
->type
== STRETCH_GLYPH
21597 || (row
->ends_at_zv_p
21599 && NILP (g
->object
)
21600 && g
->type
== CHAR_GLYPH
21601 && g
->u
.ch
== ' '))
21603 if (g
->charpos
> 0)
21604 SET_PT (g
->charpos
);
21605 else if (row
->reversed_p
21606 && row
->ends_at_zv_p
21611 w
->cursor
.vpos
= -1;
21612 return make_number (PT
);
21621 /* If we wind up here, we failed to move by using the glyphs, so we
21622 need to simulate display instead. */
21625 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
21627 paragraph_dir
= Qleft_to_right
;
21628 if (EQ (paragraph_dir
, Qright_to_left
))
21630 if (PT
<= BEGV
&& dir
< 0)
21631 xsignal0 (Qbeginning_of_buffer
);
21632 else if (PT
>= ZV
&& dir
> 0)
21633 xsignal0 (Qend_of_buffer
);
21636 struct text_pos pt
;
21638 int pt_x
, target_x
, pixel_width
, pt_vpos
;
21640 bool overshoot_expected
= false;
21641 bool target_is_eol_p
= false;
21643 /* Setup the arena. */
21644 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
21645 start_display (&it
, w
, pt
);
21646 /* When lines are truncated, we could be called with point
21647 outside of the windows edges, in which case move_it_*
21648 functions either prematurely stop at window's edge or jump to
21649 the next screen line, whereas we rely below on our ability to
21650 reach point, in order to start from its X coordinate. So we
21651 need to disregard the window's horizontal extent in that case. */
21652 if (it
.line_wrap
== TRUNCATE
)
21653 it
.last_visible_x
= INFINITY
;
21655 if (it
.cmp_it
.id
< 0
21656 && it
.method
== GET_FROM_STRING
21657 && it
.area
== TEXT_AREA
21658 && it
.string_from_display_prop_p
21659 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
21660 overshoot_expected
= true;
21662 /* Find the X coordinate of point. We start from the beginning
21663 of this or previous line to make sure we are before point in
21664 the logical order (since the move_it_* functions can only
21667 reseat_at_previous_visible_line_start (&it
);
21668 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
21669 if (IT_CHARPOS (it
) != PT
)
21671 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
21672 -1, -1, -1, MOVE_TO_POS
);
21673 /* If we missed point because the character there is
21674 displayed out of a display vector that has more than one
21675 glyph, retry expecting overshoot. */
21676 if (it
.method
== GET_FROM_DISPLAY_VECTOR
21677 && it
.current
.dpvec_index
> 0
21678 && !overshoot_expected
)
21680 overshoot_expected
= true;
21683 else if (IT_CHARPOS (it
) != PT
&& !overshoot_expected
)
21684 move_it_in_display_line (&it
, PT
, -1, MOVE_TO_POS
);
21686 pt_x
= it
.current_x
;
21688 if (dir
> 0 || overshoot_expected
)
21690 struct glyph_row
*row
= it
.glyph_row
;
21692 /* When point is at beginning of line, we don't have
21693 information about the glyph there loaded into struct
21694 it. Calling get_next_display_element fixes that. */
21696 get_next_display_element (&it
);
21697 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21698 it
.glyph_row
= NULL
;
21699 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
21700 it
.glyph_row
= row
;
21701 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
21702 it, lest it will become out of sync with it's buffer
21704 it
.current_x
= pt_x
;
21707 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21708 pixel_width
= it
.pixel_width
;
21709 if (overshoot_expected
&& at_eol_p
)
21711 else if (pixel_width
<= 0)
21714 /* If there's a display string (or something similar) at point,
21715 we are actually at the glyph to the left of point, so we need
21716 to correct the X coordinate. */
21717 if (overshoot_expected
)
21720 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
21722 pt_x
+= pixel_width
;
21725 /* Compute target X coordinate, either to the left or to the
21726 right of point. On TTY frames, all characters have the same
21727 pixel width of 1, so we can use that. On GUI frames we don't
21728 have an easy way of getting at the pixel width of the
21729 character to the left of point, so we use a different method
21730 of getting to that place. */
21732 target_x
= pt_x
+ pixel_width
;
21734 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
21736 /* Target X coordinate could be one line above or below the line
21737 of point, in which case we need to adjust the target X
21738 coordinate. Also, if moving to the left, we need to begin at
21739 the left edge of the point's screen line. */
21744 start_display (&it
, w
, pt
);
21745 if (it
.line_wrap
== TRUNCATE
)
21746 it
.last_visible_x
= INFINITY
;
21747 reseat_at_previous_visible_line_start (&it
);
21748 it
.current_x
= it
.current_y
= it
.hpos
= 0;
21750 move_it_by_lines (&it
, pt_vpos
);
21754 move_it_by_lines (&it
, -1);
21755 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
21756 target_is_eol_p
= true;
21757 /* Under word-wrap, we don't know the x coordinate of
21758 the last character displayed on the previous line,
21759 which immediately precedes the wrap point. To find
21760 out its x coordinate, we try moving to the right
21761 margin of the window, which will stop at the wrap
21762 point, and then reset target_x to point at the
21763 character that precedes the wrap point. This is not
21764 needed on GUI frames, because (see below) there we
21765 move from the left margin one grapheme cluster at a
21766 time, and stop when we hit the wrap point. */
21767 if (!FRAME_WINDOW_P (it
.f
) && it
.line_wrap
== WORD_WRAP
)
21769 void *it_data
= NULL
;
21772 SAVE_IT (it2
, it
, it_data
);
21773 move_it_in_display_line_to (&it
, ZV
, target_x
,
21774 MOVE_TO_POS
| MOVE_TO_X
);
21775 /* If we arrived at target_x, that _is_ the last
21776 character on the previous line. */
21777 if (it
.current_x
!= target_x
)
21778 target_x
= it
.current_x
- 1;
21779 RESTORE_IT (&it
, &it2
, it_data
);
21786 || (target_x
>= it
.last_visible_x
21787 && it
.line_wrap
!= TRUNCATE
))
21790 move_it_by_lines (&it
, 0);
21791 move_it_by_lines (&it
, 1);
21796 /* Move to the target X coordinate. */
21797 #ifdef HAVE_WINDOW_SYSTEM
21798 /* On GUI frames, as we don't know the X coordinate of the
21799 character to the left of point, moving point to the left
21800 requires walking, one grapheme cluster at a time, until we
21801 find ourself at a place immediately to the left of the
21802 character at point. */
21803 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
21805 struct text_pos new_pos
;
21806 enum move_it_result rc
= MOVE_X_REACHED
;
21808 if (it
.current_x
== 0)
21809 get_next_display_element (&it
);
21810 if (it
.what
== IT_COMPOSITION
)
21812 new_pos
.charpos
= it
.cmp_it
.charpos
;
21813 new_pos
.bytepos
= -1;
21816 new_pos
= it
.current
.pos
;
21818 while (it
.current_x
+ it
.pixel_width
<= target_x
21819 && (rc
== MOVE_X_REACHED
21820 /* Under word-wrap, move_it_in_display_line_to
21821 stops at correct coordinates, but sometimes
21822 returns MOVE_POS_MATCH_OR_ZV. */
21823 || (it
.line_wrap
== WORD_WRAP
21824 && rc
== MOVE_POS_MATCH_OR_ZV
)))
21826 int new_x
= it
.current_x
+ it
.pixel_width
;
21828 /* For composed characters, we want the position of the
21829 first character in the grapheme cluster (usually, the
21830 composition's base character), whereas it.current
21831 might give us the position of the _last_ one, e.g. if
21832 the composition is rendered in reverse due to bidi
21834 if (it
.what
== IT_COMPOSITION
)
21836 new_pos
.charpos
= it
.cmp_it
.charpos
;
21837 new_pos
.bytepos
= -1;
21840 new_pos
= it
.current
.pos
;
21841 if (new_x
== it
.current_x
)
21843 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
21844 MOVE_TO_POS
| MOVE_TO_X
);
21845 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
21848 /* The previous position we saw in the loop is the one we
21850 if (new_pos
.bytepos
== -1)
21851 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
21852 it
.current
.pos
= new_pos
;
21856 if (it
.current_x
!= target_x
)
21857 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
21859 /* If we ended up in a display string that covers point, move to
21860 buffer position to the right in the visual order. */
21863 while (IT_CHARPOS (it
) == PT
)
21865 set_iterator_to_next (&it
, false);
21866 if (!get_next_display_element (&it
))
21871 /* Move point to that position. */
21872 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
21875 return make_number (PT
);
21877 #undef ROW_GLYPH_NEWLINE_P
21880 DEFUN ("bidi-resolved-levels", Fbidi_resolved_levels
,
21881 Sbidi_resolved_levels
, 0, 1, 0,
21882 doc
: /* Return the resolved bidirectional levels of characters at VPOS.
21884 The resolved levels are produced by the Emacs bidi reordering engine
21885 that implements the UBA, the Unicode Bidirectional Algorithm. Please
21886 read the Unicode Standard Annex 9 (UAX#9) for background information
21887 about these levels.
21889 VPOS is the zero-based number of the current window's screen line
21890 for which to produce the resolved levels. If VPOS is nil or omitted,
21891 it defaults to the screen line of point. If the window displays a
21892 header line, VPOS of zero will report on the header line, and first
21893 line of text in the window will have VPOS of 1.
21895 Value is an array of resolved levels, indexed by glyph number.
21896 Glyphs are numbered from zero starting from the beginning of the
21897 screen line, i.e. the left edge of the window for left-to-right lines
21898 and from the right edge for right-to-left lines. The resolved levels
21899 are produced only for the window's text area; text in display margins
21902 If the selected window's display is not up-to-date, or if the specified
21903 screen line does not display text, this function returns nil. It is
21904 highly recommended to bind this function to some simple key, like F8,
21905 in order to avoid these problems.
21907 This function exists mainly for testing the correctness of the
21908 Emacs UBA implementation, in particular with the test suite. */)
21911 struct window
*w
= XWINDOW (selected_window
);
21912 struct buffer
*b
= XBUFFER (w
->contents
);
21914 struct glyph_row
*row
;
21918 int d1
, d2
, d3
, d4
, d5
;
21920 pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &nrow
);
21924 CHECK_NUMBER_COERCE_MARKER (vpos
);
21925 nrow
= XINT (vpos
);
21928 /* We require up-to-date glyph matrix for this window. */
21929 if (w
->window_end_valid
21930 && !windows_or_buffers_changed
21932 && !b
->clip_changed
21933 && !b
->prevent_redisplay_optimizations_p
21934 && !window_outdated (w
)
21936 && nrow
< w
->current_matrix
->nrows
21937 && (row
= MATRIX_ROW (w
->current_matrix
, nrow
))->enabled_p
21938 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
21940 struct glyph
*g
, *e
, *g1
;
21942 Lisp_Object levels
;
21944 if (!row
->reversed_p
) /* Left-to-right glyph row. */
21946 g
= g1
= row
->glyphs
[TEXT_AREA
];
21947 e
= g
+ row
->used
[TEXT_AREA
];
21949 /* Skip over glyphs at the start of the row that was
21950 generated by redisplay for its own needs. */
21952 && NILP (g
->object
)
21957 /* Count the "interesting" glyphs in this row. */
21958 for (nglyphs
= 0; g
< e
&& !NILP (g
->object
); g
++)
21961 /* Create and fill the array. */
21962 levels
= make_uninit_vector (nglyphs
);
21963 for (i
= 0; g1
< g
; i
++, g1
++)
21964 ASET (levels
, i
, make_number (g1
->resolved_level
));
21966 else /* Right-to-left glyph row. */
21968 g
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
21969 e
= row
->glyphs
[TEXT_AREA
] - 1;
21971 && NILP (g
->object
)
21975 for (nglyphs
= 0; g
> e
&& !NILP (g
->object
); g
--)
21977 levels
= make_uninit_vector (nglyphs
);
21978 for (i
= 0; g1
> g
; i
++, g1
--)
21979 ASET (levels
, i
, make_number (g1
->resolved_level
));
21989 /***********************************************************************
21991 ***********************************************************************/
21993 /* Redisplay the menu bar in the frame for window W.
21995 The menu bar of X frames that don't have X toolkit support is
21996 displayed in a special window W->frame->menu_bar_window.
21998 The menu bar of terminal frames is treated specially as far as
21999 glyph matrices are concerned. Menu bar lines are not part of
22000 windows, so the update is done directly on the frame matrix rows
22001 for the menu bar. */
22004 display_menu_bar (struct window
*w
)
22006 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22011 /* Don't do all this for graphical frames. */
22013 if (FRAME_W32_P (f
))
22016 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
22022 if (FRAME_NS_P (f
))
22024 #endif /* HAVE_NS */
22026 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
22027 eassert (!FRAME_WINDOW_P (f
));
22028 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
22029 it
.first_visible_x
= 0;
22030 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
22031 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
22032 if (FRAME_WINDOW_P (f
))
22034 /* Menu bar lines are displayed in the desired matrix of the
22035 dummy window menu_bar_window. */
22036 struct window
*menu_w
;
22037 menu_w
= XWINDOW (f
->menu_bar_window
);
22038 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
22040 it
.first_visible_x
= 0;
22041 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
22044 #endif /* not USE_X_TOOLKIT and not USE_GTK */
22046 /* This is a TTY frame, i.e. character hpos/vpos are used as
22048 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
22050 it
.first_visible_x
= 0;
22051 it
.last_visible_x
= FRAME_COLS (f
);
22054 /* FIXME: This should be controlled by a user option. See the
22055 comments in redisplay_tool_bar and display_mode_line about
22057 it
.paragraph_embedding
= L2R
;
22059 /* Clear all rows of the menu bar. */
22060 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
22062 struct glyph_row
*row
= it
.glyph_row
+ i
;
22063 clear_glyph_row (row
);
22064 row
->enabled_p
= true;
22065 row
->full_width_p
= true;
22066 row
->reversed_p
= false;
22069 /* Display all items of the menu bar. */
22070 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
22071 for (i
= 0; i
< ASIZE (items
); i
+= 4)
22073 Lisp_Object string
;
22075 /* Stop at nil string. */
22076 string
= AREF (items
, i
+ 1);
22080 /* Remember where item was displayed. */
22081 ASET (items
, i
+ 3, make_number (it
.hpos
));
22083 /* Display the item, pad with one space. */
22084 if (it
.current_x
< it
.last_visible_x
)
22085 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
22086 SCHARS (string
) + 1, 0, 0, -1);
22089 /* Fill out the line with spaces. */
22090 if (it
.current_x
< it
.last_visible_x
)
22091 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
22093 /* Compute the total height of the lines. */
22094 compute_line_metrics (&it
);
22097 /* Deep copy of a glyph row, including the glyphs. */
22099 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
22101 struct glyph
*pointers
[1 + LAST_AREA
];
22102 int to_used
= to
->used
[TEXT_AREA
];
22104 /* Save glyph pointers of TO. */
22105 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
22107 /* Do a structure assignment. */
22110 /* Restore original glyph pointers of TO. */
22111 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
22113 /* Copy the glyphs. */
22114 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
22115 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
22117 /* If we filled only part of the TO row, fill the rest with
22118 space_glyph (which will display as empty space). */
22119 if (to_used
> from
->used
[TEXT_AREA
])
22120 fill_up_frame_row_with_spaces (to
, to_used
);
22123 /* Display one menu item on a TTY, by overwriting the glyphs in the
22124 frame F's desired glyph matrix with glyphs produced from the menu
22125 item text. Called from term.c to display TTY drop-down menus one
22128 ITEM_TEXT is the menu item text as a C string.
22130 FACE_ID is the face ID to be used for this menu item. FACE_ID
22131 could specify one of 3 faces: a face for an enabled item, a face
22132 for a disabled item, or a face for a selected item.
22134 X and Y are coordinates of the first glyph in the frame's desired
22135 matrix to be overwritten by the menu item. Since this is a TTY, Y
22136 is the zero-based number of the glyph row and X is the zero-based
22137 glyph number in the row, starting from left, where to start
22138 displaying the item.
22140 SUBMENU means this menu item drops down a submenu, which
22141 should be indicated by displaying a proper visual cue after the
22145 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
22146 int x
, int y
, bool submenu
)
22149 struct frame
*f
= SELECTED_FRAME ();
22150 struct window
*w
= XWINDOW (f
->selected_window
);
22151 struct glyph_row
*row
;
22152 size_t item_len
= strlen (item_text
);
22154 eassert (FRAME_TERMCAP_P (f
));
22156 /* Don't write beyond the matrix's last row. This can happen for
22157 TTY screens that are not high enough to show the entire menu.
22158 (This is actually a bit of defensive programming, as
22159 tty_menu_display already limits the number of menu items to one
22160 less than the number of screen lines.) */
22161 if (y
>= f
->desired_matrix
->nrows
)
22164 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
22165 it
.first_visible_x
= 0;
22166 it
.last_visible_x
= FRAME_COLS (f
) - 1;
22167 row
= it
.glyph_row
;
22168 /* Start with the row contents from the current matrix. */
22169 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
22170 bool saved_width
= row
->full_width_p
;
22171 row
->full_width_p
= true;
22172 bool saved_reversed
= row
->reversed_p
;
22173 row
->reversed_p
= false;
22174 row
->enabled_p
= true;
22176 /* Arrange for the menu item glyphs to start at (X,Y) and have the
22178 eassert (x
< f
->desired_matrix
->matrix_w
);
22179 it
.current_x
= it
.hpos
= x
;
22180 it
.current_y
= it
.vpos
= y
;
22181 int saved_used
= row
->used
[TEXT_AREA
];
22182 bool saved_truncated
= row
->truncated_on_right_p
;
22183 row
->used
[TEXT_AREA
] = x
;
22184 it
.face_id
= face_id
;
22185 it
.line_wrap
= TRUNCATE
;
22187 /* FIXME: This should be controlled by a user option. See the
22188 comments in redisplay_tool_bar and display_mode_line about this.
22189 Also, if paragraph_embedding could ever be R2L, changes will be
22190 needed to avoid shifting to the right the row characters in
22191 term.c:append_glyph. */
22192 it
.paragraph_embedding
= L2R
;
22194 /* Pad with a space on the left. */
22195 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
22197 /* Display the menu item, pad with spaces to WIDTH. */
22200 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
22201 item_len
, 0, FRAME_COLS (f
) - 1, -1);
22203 /* Indicate with " >" that there's a submenu. */
22204 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
22205 FRAME_COLS (f
) - 1, -1);
22208 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
22209 width
, 0, FRAME_COLS (f
) - 1, -1);
22211 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
22212 row
->truncated_on_right_p
= saved_truncated
;
22213 row
->hash
= row_hash (row
);
22214 row
->full_width_p
= saved_width
;
22215 row
->reversed_p
= saved_reversed
;
22218 /***********************************************************************
22220 ***********************************************************************/
22222 /* Redisplay mode lines in the window tree whose root is WINDOW.
22223 If FORCE, redisplay mode lines unconditionally.
22224 Otherwise, redisplay only mode lines that are garbaged. Value is
22225 the number of windows whose mode lines were redisplayed. */
22228 redisplay_mode_lines (Lisp_Object window
, bool force
)
22232 while (!NILP (window
))
22234 struct window
*w
= XWINDOW (window
);
22236 if (WINDOWP (w
->contents
))
22237 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
22239 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
22240 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
22242 struct text_pos lpoint
;
22243 struct buffer
*old
= current_buffer
;
22245 /* Set the window's buffer for the mode line display. */
22246 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
22247 set_buffer_internal_1 (XBUFFER (w
->contents
));
22249 /* Point refers normally to the selected window. For any
22250 other window, set up appropriate value. */
22251 if (!EQ (window
, selected_window
))
22253 struct text_pos pt
;
22255 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
22256 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
22259 /* Display mode lines. */
22260 clear_glyph_matrix (w
->desired_matrix
);
22261 if (display_mode_lines (w
))
22264 /* Restore old settings. */
22265 set_buffer_internal_1 (old
);
22266 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
22276 /* Display the mode and/or header line of window W. Value is the
22277 sum number of mode lines and header lines displayed. */
22280 display_mode_lines (struct window
*w
)
22282 Lisp_Object old_selected_window
= selected_window
;
22283 Lisp_Object old_selected_frame
= selected_frame
;
22284 Lisp_Object new_frame
= w
->frame
;
22285 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
22288 selected_frame
= new_frame
;
22289 /* FIXME: If we were to allow the mode-line's computation changing the buffer
22290 or window's point, then we'd need select_window_1 here as well. */
22291 XSETWINDOW (selected_window
, w
);
22292 XFRAME (new_frame
)->selected_window
= selected_window
;
22294 /* These will be set while the mode line specs are processed. */
22295 line_number_displayed
= false;
22296 w
->column_number_displayed
= -1;
22298 if (WINDOW_WANTS_MODELINE_P (w
))
22300 struct window
*sel_w
= XWINDOW (old_selected_window
);
22302 /* Select mode line face based on the real selected window. */
22303 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
22304 BVAR (current_buffer
, mode_line_format
));
22308 if (WINDOW_WANTS_HEADER_LINE_P (w
))
22310 display_mode_line (w
, HEADER_LINE_FACE_ID
,
22311 BVAR (current_buffer
, header_line_format
));
22315 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
22316 selected_frame
= old_selected_frame
;
22317 selected_window
= old_selected_window
;
22319 w
->must_be_updated_p
= true;
22324 /* Display mode or header line of window W. FACE_ID specifies which
22325 line to display; it is either MODE_LINE_FACE_ID or
22326 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
22327 display. Value is the pixel height of the mode/header line
22331 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
22335 ptrdiff_t count
= SPECPDL_INDEX ();
22337 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
22338 /* Don't extend on a previously drawn mode-line.
22339 This may happen if called from pos_visible_p. */
22340 it
.glyph_row
->enabled_p
= false;
22341 prepare_desired_row (w
, it
.glyph_row
, true);
22343 it
.glyph_row
->mode_line_p
= true;
22345 /* FIXME: This should be controlled by a user option. But
22346 supporting such an option is not trivial, since the mode line is
22347 made up of many separate strings. */
22348 it
.paragraph_embedding
= L2R
;
22350 record_unwind_protect (unwind_format_mode_line
,
22351 format_mode_line_unwind_data (NULL
, NULL
,
22354 mode_line_target
= MODE_LINE_DISPLAY
;
22356 /* Temporarily make frame's keyboard the current kboard so that
22357 kboard-local variables in the mode_line_format will get the right
22359 push_kboard (FRAME_KBOARD (it
.f
));
22360 record_unwind_save_match_data ();
22361 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
22364 unbind_to (count
, Qnil
);
22366 /* Fill up with spaces. */
22367 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
22369 compute_line_metrics (&it
);
22370 it
.glyph_row
->full_width_p
= true;
22371 it
.glyph_row
->continued_p
= false;
22372 it
.glyph_row
->truncated_on_left_p
= false;
22373 it
.glyph_row
->truncated_on_right_p
= false;
22375 /* Make a 3D mode-line have a shadow at its right end. */
22376 face
= FACE_FROM_ID (it
.f
, face_id
);
22377 extend_face_to_end_of_line (&it
);
22378 if (face
->box
!= FACE_NO_BOX
)
22380 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
22381 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
22382 last
->right_box_line_p
= true;
22385 return it
.glyph_row
->height
;
22388 /* Move element ELT in LIST to the front of LIST.
22389 Return the updated list. */
22392 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
22394 register Lisp_Object tail
, prev
;
22395 register Lisp_Object tem
;
22399 while (CONSP (tail
))
22405 /* Splice out the link TAIL. */
22407 list
= XCDR (tail
);
22409 Fsetcdr (prev
, XCDR (tail
));
22411 /* Now make it the first. */
22412 Fsetcdr (tail
, list
);
22417 tail
= XCDR (tail
);
22421 /* Not found--return unchanged LIST. */
22425 /* Contribute ELT to the mode line for window IT->w. How it
22426 translates into text depends on its data type.
22428 IT describes the display environment in which we display, as usual.
22430 DEPTH is the depth in recursion. It is used to prevent
22431 infinite recursion here.
22433 FIELD_WIDTH is the number of characters the display of ELT should
22434 occupy in the mode line, and PRECISION is the maximum number of
22435 characters to display from ELT's representation. See
22436 display_string for details.
22438 Returns the hpos of the end of the text generated by ELT.
22440 PROPS is a property list to add to any string we encounter.
22442 If RISKY, remove (disregard) any properties in any string
22443 we encounter, and ignore :eval and :propertize.
22445 The global variable `mode_line_target' determines whether the
22446 output is passed to `store_mode_line_noprop',
22447 `store_mode_line_string', or `display_string'. */
22450 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
22451 Lisp_Object elt
, Lisp_Object props
, bool risky
)
22453 int n
= 0, field
, prec
;
22454 bool literal
= false;
22458 elt
= build_string ("*too-deep*");
22462 switch (XTYPE (elt
))
22466 /* A string: output it and check for %-constructs within it. */
22468 ptrdiff_t offset
= 0;
22470 if (SCHARS (elt
) > 0
22471 && (!NILP (props
) || risky
))
22473 Lisp_Object oprops
, aelt
;
22474 oprops
= Ftext_properties_at (make_number (0), elt
);
22476 /* If the starting string's properties are not what
22477 we want, translate the string. Also, if the string
22478 is risky, do that anyway. */
22480 if (NILP (Fequal (props
, oprops
)) || risky
)
22482 /* If the starting string has properties,
22483 merge the specified ones onto the existing ones. */
22484 if (! NILP (oprops
) && !risky
)
22488 oprops
= Fcopy_sequence (oprops
);
22490 while (CONSP (tem
))
22492 oprops
= Fplist_put (oprops
, XCAR (tem
),
22493 XCAR (XCDR (tem
)));
22494 tem
= XCDR (XCDR (tem
));
22499 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
22500 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
22502 /* AELT is what we want. Move it to the front
22503 without consing. */
22505 mode_line_proptrans_alist
22506 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
22512 /* If AELT has the wrong props, it is useless.
22513 so get rid of it. */
22515 mode_line_proptrans_alist
22516 = Fdelq (aelt
, mode_line_proptrans_alist
);
22518 elt
= Fcopy_sequence (elt
);
22519 Fset_text_properties (make_number (0), Flength (elt
),
22521 /* Add this item to mode_line_proptrans_alist. */
22522 mode_line_proptrans_alist
22523 = Fcons (Fcons (elt
, props
),
22524 mode_line_proptrans_alist
);
22525 /* Truncate mode_line_proptrans_alist
22526 to at most 50 elements. */
22527 tem
= Fnthcdr (make_number (50),
22528 mode_line_proptrans_alist
);
22530 XSETCDR (tem
, Qnil
);
22539 prec
= precision
- n
;
22540 switch (mode_line_target
)
22542 case MODE_LINE_NOPROP
:
22543 case MODE_LINE_TITLE
:
22544 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
22546 case MODE_LINE_STRING
:
22547 n
+= store_mode_line_string (NULL
, elt
, true, 0, prec
, Qnil
);
22549 case MODE_LINE_DISPLAY
:
22550 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
22551 0, prec
, 0, STRING_MULTIBYTE (elt
));
22558 /* Handle the non-literal case. */
22560 while ((precision
<= 0 || n
< precision
)
22561 && SREF (elt
, offset
) != 0
22562 && (mode_line_target
!= MODE_LINE_DISPLAY
22563 || it
->current_x
< it
->last_visible_x
))
22565 ptrdiff_t last_offset
= offset
;
22567 /* Advance to end of string or next format specifier. */
22568 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
22571 if (offset
- 1 != last_offset
)
22573 ptrdiff_t nchars
, nbytes
;
22575 /* Output to end of string or up to '%'. Field width
22576 is length of string. Don't output more than
22577 PRECISION allows us. */
22580 prec
= c_string_width (SDATA (elt
) + last_offset
,
22581 offset
- last_offset
, precision
- n
,
22584 switch (mode_line_target
)
22586 case MODE_LINE_NOPROP
:
22587 case MODE_LINE_TITLE
:
22588 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
22590 case MODE_LINE_STRING
:
22592 ptrdiff_t bytepos
= last_offset
;
22593 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22594 ptrdiff_t endpos
= (precision
<= 0
22595 ? string_byte_to_char (elt
, offset
)
22596 : charpos
+ nchars
);
22597 Lisp_Object mode_string
22598 = Fsubstring (elt
, make_number (charpos
),
22599 make_number (endpos
));
22600 n
+= store_mode_line_string (NULL
, mode_string
, false,
22604 case MODE_LINE_DISPLAY
:
22606 ptrdiff_t bytepos
= last_offset
;
22607 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22609 if (precision
<= 0)
22610 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
22611 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
22613 STRING_MULTIBYTE (elt
));
22618 else /* c == '%' */
22620 ptrdiff_t percent_position
= offset
;
22622 /* Get the specified minimum width. Zero means
22625 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
22626 field
= field
* 10 + c
- '0';
22628 /* Don't pad beyond the total padding allowed. */
22629 if (field_width
- n
> 0 && field
> field_width
- n
)
22630 field
= field_width
- n
;
22632 /* Note that either PRECISION <= 0 or N < PRECISION. */
22633 prec
= precision
- n
;
22636 n
+= display_mode_element (it
, depth
, field
, prec
,
22637 Vglobal_mode_string
, props
,
22642 ptrdiff_t bytepos
, charpos
;
22644 Lisp_Object string
;
22646 bytepos
= percent_position
;
22647 charpos
= (STRING_MULTIBYTE (elt
)
22648 ? string_byte_to_char (elt
, bytepos
)
22650 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
22651 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
22653 switch (mode_line_target
)
22655 case MODE_LINE_NOPROP
:
22656 case MODE_LINE_TITLE
:
22657 n
+= store_mode_line_noprop (spec
, field
, prec
);
22659 case MODE_LINE_STRING
:
22661 Lisp_Object tem
= build_string (spec
);
22662 props
= Ftext_properties_at (make_number (charpos
), elt
);
22663 /* Should only keep face property in props */
22664 n
+= store_mode_line_string (NULL
, tem
, false,
22665 field
, prec
, props
);
22668 case MODE_LINE_DISPLAY
:
22670 int nglyphs_before
, nwritten
;
22672 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
22673 nwritten
= display_string (spec
, string
, elt
,
22678 /* Assign to the glyphs written above the
22679 string where the `%x' came from, position
22683 struct glyph
*glyph
22684 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
22688 for (i
= 0; i
< nwritten
; ++i
)
22690 glyph
[i
].object
= elt
;
22691 glyph
[i
].charpos
= charpos
;
22708 /* A symbol: process the value of the symbol recursively
22709 as if it appeared here directly. Avoid error if symbol void.
22710 Special case: if value of symbol is a string, output the string
22713 register Lisp_Object tem
;
22715 /* If the variable is not marked as risky to set
22716 then its contents are risky to use. */
22717 if (NILP (Fget (elt
, Qrisky_local_variable
)))
22720 tem
= Fboundp (elt
);
22723 tem
= Fsymbol_value (elt
);
22724 /* If value is a string, output that string literally:
22725 don't check for % within it. */
22729 if (!EQ (tem
, elt
))
22731 /* Give up right away for nil or t. */
22741 register Lisp_Object car
, tem
;
22743 /* A cons cell: five distinct cases.
22744 If first element is :eval or :propertize, do something special.
22745 If first element is a string or a cons, process all the elements
22746 and effectively concatenate them.
22747 If first element is a negative number, truncate displaying cdr to
22748 at most that many characters. If positive, pad (with spaces)
22749 to at least that many characters.
22750 If first element is a symbol, process the cadr or caddr recursively
22751 according to whether the symbol's value is non-nil or nil. */
22753 if (EQ (car
, QCeval
))
22755 /* An element of the form (:eval FORM) means evaluate FORM
22756 and use the result as mode line elements. */
22761 if (CONSP (XCDR (elt
)))
22764 spec
= safe__eval (true, XCAR (XCDR (elt
)));
22765 n
+= display_mode_element (it
, depth
, field_width
- n
,
22766 precision
- n
, spec
, props
,
22770 else if (EQ (car
, QCpropertize
))
22772 /* An element of the form (:propertize ELT PROPS...)
22773 means display ELT but applying properties PROPS. */
22778 if (CONSP (XCDR (elt
)))
22779 n
+= display_mode_element (it
, depth
, field_width
- n
,
22780 precision
- n
, XCAR (XCDR (elt
)),
22781 XCDR (XCDR (elt
)), risky
);
22783 else if (SYMBOLP (car
))
22785 tem
= Fboundp (car
);
22789 /* elt is now the cdr, and we know it is a cons cell.
22790 Use its car if CAR has a non-nil value. */
22793 tem
= Fsymbol_value (car
);
22800 /* Symbol's value is nil (or symbol is unbound)
22801 Get the cddr of the original list
22802 and if possible find the caddr and use that. */
22806 else if (!CONSP (elt
))
22811 else if (INTEGERP (car
))
22813 register int lim
= XINT (car
);
22817 /* Negative int means reduce maximum width. */
22818 if (precision
<= 0)
22821 precision
= min (precision
, -lim
);
22825 /* Padding specified. Don't let it be more than
22826 current maximum. */
22828 lim
= min (precision
, lim
);
22830 /* If that's more padding than already wanted, queue it.
22831 But don't reduce padding already specified even if
22832 that is beyond the current truncation point. */
22833 field_width
= max (lim
, field_width
);
22837 else if (STRINGP (car
) || CONSP (car
))
22839 Lisp_Object halftail
= elt
;
22843 && (precision
<= 0 || n
< precision
))
22845 n
+= display_mode_element (it
, depth
,
22846 /* Do padding only after the last
22847 element in the list. */
22848 (! CONSP (XCDR (elt
))
22851 precision
- n
, XCAR (elt
),
22855 if ((len
& 1) == 0)
22856 halftail
= XCDR (halftail
);
22857 /* Check for cycle. */
22858 if (EQ (halftail
, elt
))
22867 elt
= build_string ("*invalid*");
22871 /* Pad to FIELD_WIDTH. */
22872 if (field_width
> 0 && n
< field_width
)
22874 switch (mode_line_target
)
22876 case MODE_LINE_NOPROP
:
22877 case MODE_LINE_TITLE
:
22878 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
22880 case MODE_LINE_STRING
:
22881 n
+= store_mode_line_string ("", Qnil
, false, field_width
- n
, 0,
22884 case MODE_LINE_DISPLAY
:
22885 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
22894 /* Store a mode-line string element in mode_line_string_list.
22896 If STRING is non-null, display that C string. Otherwise, the Lisp
22897 string LISP_STRING is displayed.
22899 FIELD_WIDTH is the minimum number of output glyphs to produce.
22900 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22901 with spaces. FIELD_WIDTH <= 0 means don't pad.
22903 PRECISION is the maximum number of characters to output from
22904 STRING. PRECISION <= 0 means don't truncate the string.
22906 If COPY_STRING, make a copy of LISP_STRING before adding
22907 properties to the string.
22909 PROPS are the properties to add to the string.
22910 The mode_line_string_face face property is always added to the string.
22914 store_mode_line_string (const char *string
, Lisp_Object lisp_string
,
22916 int field_width
, int precision
, Lisp_Object props
)
22921 if (string
!= NULL
)
22923 len
= strlen (string
);
22924 if (precision
> 0 && len
> precision
)
22926 lisp_string
= make_string (string
, len
);
22928 props
= mode_line_string_face_prop
;
22929 else if (!NILP (mode_line_string_face
))
22931 Lisp_Object face
= Fplist_get (props
, Qface
);
22932 props
= Fcopy_sequence (props
);
22934 face
= mode_line_string_face
;
22936 face
= list2 (face
, mode_line_string_face
);
22937 props
= Fplist_put (props
, Qface
, face
);
22939 Fadd_text_properties (make_number (0), make_number (len
),
22940 props
, lisp_string
);
22944 len
= XFASTINT (Flength (lisp_string
));
22945 if (precision
> 0 && len
> precision
)
22948 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
22951 if (!NILP (mode_line_string_face
))
22955 props
= Ftext_properties_at (make_number (0), lisp_string
);
22956 face
= Fplist_get (props
, Qface
);
22958 face
= mode_line_string_face
;
22960 face
= list2 (face
, mode_line_string_face
);
22961 props
= list2 (Qface
, face
);
22963 lisp_string
= Fcopy_sequence (lisp_string
);
22966 Fadd_text_properties (make_number (0), make_number (len
),
22967 props
, lisp_string
);
22972 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22976 if (field_width
> len
)
22978 field_width
-= len
;
22979 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
22981 Fadd_text_properties (make_number (0), make_number (field_width
),
22982 props
, lisp_string
);
22983 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22991 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
22993 doc
: /* Format a string out of a mode line format specification.
22994 First arg FORMAT specifies the mode line format (see `mode-line-format'
22995 for details) to use.
22997 By default, the format is evaluated for the currently selected window.
22999 Optional second arg FACE specifies the face property to put on all
23000 characters for which no face is specified. The value nil means the
23001 default face. The value t means whatever face the window's mode line
23002 currently uses (either `mode-line' or `mode-line-inactive',
23003 depending on whether the window is the selected window or not).
23004 An integer value means the value string has no text
23007 Optional third and fourth args WINDOW and BUFFER specify the window
23008 and buffer to use as the context for the formatting (defaults
23009 are the selected window and the WINDOW's buffer). */)
23010 (Lisp_Object format
, Lisp_Object face
,
23011 Lisp_Object window
, Lisp_Object buffer
)
23016 struct buffer
*old_buffer
= NULL
;
23018 bool no_props
= INTEGERP (face
);
23019 ptrdiff_t count
= SPECPDL_INDEX ();
23021 int string_start
= 0;
23023 w
= decode_any_window (window
);
23024 XSETWINDOW (window
, w
);
23027 buffer
= w
->contents
;
23028 CHECK_BUFFER (buffer
);
23030 /* Make formatting the modeline a non-op when noninteractive, otherwise
23031 there will be problems later caused by a partially initialized frame. */
23032 if (NILP (format
) || noninteractive
)
23033 return empty_unibyte_string
;
23038 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
23039 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
23040 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
23041 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
23042 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
23043 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
23044 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
23047 old_buffer
= current_buffer
;
23049 /* Save things including mode_line_proptrans_alist,
23050 and set that to nil so that we don't alter the outer value. */
23051 record_unwind_protect (unwind_format_mode_line
,
23052 format_mode_line_unwind_data
23053 (XFRAME (WINDOW_FRAME (w
)),
23054 old_buffer
, selected_window
, true));
23055 mode_line_proptrans_alist
= Qnil
;
23057 Fselect_window (window
, Qt
);
23058 set_buffer_internal_1 (XBUFFER (buffer
));
23060 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
23064 mode_line_target
= MODE_LINE_NOPROP
;
23065 mode_line_string_face_prop
= Qnil
;
23066 mode_line_string_list
= Qnil
;
23067 string_start
= MODE_LINE_NOPROP_LEN (0);
23071 mode_line_target
= MODE_LINE_STRING
;
23072 mode_line_string_list
= Qnil
;
23073 mode_line_string_face
= face
;
23074 mode_line_string_face_prop
23075 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
23078 push_kboard (FRAME_KBOARD (it
.f
));
23079 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
23084 len
= MODE_LINE_NOPROP_LEN (string_start
);
23085 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
23089 mode_line_string_list
= Fnreverse (mode_line_string_list
);
23090 str
= Fmapconcat (Qidentity
, mode_line_string_list
,
23091 empty_unibyte_string
);
23094 unbind_to (count
, Qnil
);
23098 /* Write a null-terminated, right justified decimal representation of
23099 the positive integer D to BUF using a minimal field width WIDTH. */
23102 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
23104 register char *p
= buf
;
23112 *p
++ = d
% 10 + '0';
23117 for (width
-= (int) (p
- buf
); width
> 0; --width
)
23128 /* Write a null-terminated, right justified decimal and "human
23129 readable" representation of the nonnegative integer D to BUF using
23130 a minimal field width WIDTH. D should be smaller than 999.5e24. */
23132 static const char power_letter
[] =
23146 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
23148 /* We aim to represent the nonnegative integer D as
23149 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
23150 ptrdiff_t quotient
= d
;
23152 /* -1 means: do not use TENTHS. */
23156 /* Length of QUOTIENT.TENTHS as a string. */
23162 if (quotient
>= 1000)
23164 /* Scale to the appropriate EXPONENT. */
23167 remainder
= quotient
% 1000;
23171 while (quotient
>= 1000);
23173 /* Round to nearest and decide whether to use TENTHS or not. */
23176 tenths
= remainder
/ 100;
23177 if (remainder
% 100 >= 50)
23184 if (quotient
== 10)
23192 if (remainder
>= 500)
23194 if (quotient
< 999)
23205 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
23206 if (tenths
== -1 && quotient
<= 99)
23213 p
= psuffix
= buf
+ max (width
, length
);
23215 /* Print EXPONENT. */
23216 *psuffix
++ = power_letter
[exponent
];
23219 /* Print TENTHS. */
23222 *--p
= '0' + tenths
;
23226 /* Print QUOTIENT. */
23229 int digit
= quotient
% 10;
23230 *--p
= '0' + digit
;
23232 while ((quotient
/= 10) != 0);
23234 /* Print leading spaces. */
23239 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
23240 If EOL_FLAG, set also a mnemonic character for end-of-line
23241 type of CODING_SYSTEM. Return updated pointer into BUF. */
23243 static unsigned char invalid_eol_type
[] = "(*invalid*)";
23246 decode_mode_spec_coding (Lisp_Object coding_system
, char *buf
, bool eol_flag
)
23249 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
23250 const unsigned char *eol_str
;
23252 /* The EOL conversion we are using. */
23253 Lisp_Object eoltype
;
23255 val
= CODING_SYSTEM_SPEC (coding_system
);
23258 if (!VECTORP (val
)) /* Not yet decided. */
23260 *buf
++ = multibyte
? '-' : ' ';
23262 eoltype
= eol_mnemonic_undecided
;
23263 /* Don't mention EOL conversion if it isn't decided. */
23268 Lisp_Object eolvalue
;
23270 attrs
= AREF (val
, 0);
23271 eolvalue
= AREF (val
, 2);
23274 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
23279 /* The EOL conversion that is normal on this system. */
23281 if (NILP (eolvalue
)) /* Not yet decided. */
23282 eoltype
= eol_mnemonic_undecided
;
23283 else if (VECTORP (eolvalue
)) /* Not yet decided. */
23284 eoltype
= eol_mnemonic_undecided
;
23285 else /* eolvalue is Qunix, Qdos, or Qmac. */
23286 eoltype
= (EQ (eolvalue
, Qunix
)
23287 ? eol_mnemonic_unix
23288 : EQ (eolvalue
, Qdos
)
23289 ? eol_mnemonic_dos
: eol_mnemonic_mac
);
23295 /* Mention the EOL conversion if it is not the usual one. */
23296 if (STRINGP (eoltype
))
23298 eol_str
= SDATA (eoltype
);
23299 eol_str_len
= SBYTES (eoltype
);
23301 else if (CHARACTERP (eoltype
))
23303 int c
= XFASTINT (eoltype
);
23304 return buf
+ CHAR_STRING (c
, (unsigned char *) buf
);
23308 eol_str
= invalid_eol_type
;
23309 eol_str_len
= sizeof (invalid_eol_type
) - 1;
23311 memcpy (buf
, eol_str
, eol_str_len
);
23312 buf
+= eol_str_len
;
23318 /* Return a string for the output of a mode line %-spec for window W,
23319 generated by character C. FIELD_WIDTH > 0 means pad the string
23320 returned with spaces to that value. Return a Lisp string in
23321 *STRING if the resulting string is taken from that Lisp string.
23323 Note we operate on the current buffer for most purposes. */
23325 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
23327 static const char *
23328 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
23329 Lisp_Object
*string
)
23332 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23333 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
23334 /* We are going to use f->decode_mode_spec_buffer as the buffer to
23335 produce strings from numerical values, so limit preposterously
23336 large values of FIELD_WIDTH to avoid overrunning the buffer's
23337 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
23338 bytes plus the terminating null. */
23339 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
23340 struct buffer
*b
= current_buffer
;
23348 if (!NILP (BVAR (b
, read_only
)))
23350 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23355 /* This differs from %* only for a modified read-only buffer. */
23356 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23358 if (!NILP (BVAR (b
, read_only
)))
23363 /* This differs from %* in ignoring read-only-ness. */
23364 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23376 if (command_loop_level
> 5)
23378 p
= decode_mode_spec_buf
;
23379 for (i
= 0; i
< command_loop_level
; i
++)
23382 return decode_mode_spec_buf
;
23390 if (command_loop_level
> 5)
23392 p
= decode_mode_spec_buf
;
23393 for (i
= 0; i
< command_loop_level
; i
++)
23396 return decode_mode_spec_buf
;
23403 /* Let lots_of_dashes be a string of infinite length. */
23404 if (mode_line_target
== MODE_LINE_NOPROP
23405 || mode_line_target
== MODE_LINE_STRING
)
23407 if (field_width
<= 0
23408 || field_width
> sizeof (lots_of_dashes
))
23410 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
23411 decode_mode_spec_buf
[i
] = '-';
23412 decode_mode_spec_buf
[i
] = '\0';
23413 return decode_mode_spec_buf
;
23416 return lots_of_dashes
;
23420 obj
= BVAR (b
, name
);
23424 /* %c and %l are ignored in `frame-title-format'.
23425 (In redisplay_internal, the frame title is drawn _before_ the
23426 windows are updated, so the stuff which depends on actual
23427 window contents (such as %l) may fail to render properly, or
23428 even crash emacs.) */
23429 if (mode_line_target
== MODE_LINE_TITLE
)
23433 ptrdiff_t col
= current_column ();
23434 w
->column_number_displayed
= col
;
23435 pint2str (decode_mode_spec_buf
, width
, col
);
23436 return decode_mode_spec_buf
;
23440 #if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
23442 if (NILP (Vmemory_full
))
23445 return "!MEM FULL! ";
23452 /* %F displays the frame name. */
23453 if (!NILP (f
->title
))
23454 return SSDATA (f
->title
);
23455 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
23456 return SSDATA (f
->name
);
23460 obj
= BVAR (b
, filename
);
23465 ptrdiff_t size
= ZV
- BEGV
;
23466 pint2str (decode_mode_spec_buf
, width
, size
);
23467 return decode_mode_spec_buf
;
23472 ptrdiff_t size
= ZV
- BEGV
;
23473 pint2hrstr (decode_mode_spec_buf
, width
, size
);
23474 return decode_mode_spec_buf
;
23479 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
23480 ptrdiff_t topline
, nlines
, height
;
23483 /* %c and %l are ignored in `frame-title-format'. */
23484 if (mode_line_target
== MODE_LINE_TITLE
)
23487 startpos
= marker_position (w
->start
);
23488 startpos_byte
= marker_byte_position (w
->start
);
23489 height
= WINDOW_TOTAL_LINES (w
);
23491 /* If we decided that this buffer isn't suitable for line numbers,
23492 don't forget that too fast. */
23493 if (w
->base_line_pos
== -1)
23496 /* If the buffer is very big, don't waste time. */
23497 if (INTEGERP (Vline_number_display_limit
)
23498 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
23500 w
->base_line_pos
= 0;
23501 w
->base_line_number
= 0;
23505 if (w
->base_line_number
> 0
23506 && w
->base_line_pos
> 0
23507 && w
->base_line_pos
<= startpos
)
23509 line
= w
->base_line_number
;
23510 linepos
= w
->base_line_pos
;
23511 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
23516 linepos
= BUF_BEGV (b
);
23517 linepos_byte
= BUF_BEGV_BYTE (b
);
23520 /* Count lines from base line to window start position. */
23521 nlines
= display_count_lines (linepos_byte
,
23525 topline
= nlines
+ line
;
23527 /* Determine a new base line, if the old one is too close
23528 or too far away, or if we did not have one.
23529 "Too close" means it's plausible a scroll-down would
23530 go back past it. */
23531 if (startpos
== BUF_BEGV (b
))
23533 w
->base_line_number
= topline
;
23534 w
->base_line_pos
= BUF_BEGV (b
);
23536 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
23537 || linepos
== BUF_BEGV (b
))
23539 ptrdiff_t limit
= BUF_BEGV (b
);
23540 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
23541 ptrdiff_t position
;
23542 ptrdiff_t distance
=
23543 (height
* 2 + 30) * line_number_display_limit_width
;
23545 if (startpos
- distance
> limit
)
23547 limit
= startpos
- distance
;
23548 limit_byte
= CHAR_TO_BYTE (limit
);
23551 nlines
= display_count_lines (startpos_byte
,
23553 - (height
* 2 + 30),
23555 /* If we couldn't find the lines we wanted within
23556 line_number_display_limit_width chars per line,
23557 give up on line numbers for this window. */
23558 if (position
== limit_byte
&& limit
== startpos
- distance
)
23560 w
->base_line_pos
= -1;
23561 w
->base_line_number
= 0;
23565 w
->base_line_number
= topline
- nlines
;
23566 w
->base_line_pos
= BYTE_TO_CHAR (position
);
23569 /* Now count lines from the start pos to point. */
23570 nlines
= display_count_lines (startpos_byte
,
23571 PT_BYTE
, PT
, &junk
);
23573 /* Record that we did display the line number. */
23574 line_number_displayed
= true;
23576 /* Make the string to show. */
23577 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
23578 return decode_mode_spec_buf
;
23581 char *p
= decode_mode_spec_buf
;
23582 int pad
= width
- 2;
23588 return decode_mode_spec_buf
;
23594 obj
= BVAR (b
, mode_name
);
23598 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
23604 ptrdiff_t pos
= marker_position (w
->start
);
23605 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23607 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
23609 if (pos
<= BUF_BEGV (b
))
23614 else if (pos
<= BUF_BEGV (b
))
23618 if (total
> 1000000)
23619 /* Do it differently for a large value, to avoid overflow. */
23620 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23622 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23623 /* We can't normally display a 3-digit number,
23624 so get us a 2-digit number that is close. */
23627 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23628 return decode_mode_spec_buf
;
23632 /* Display percentage of size above the bottom of the screen. */
23635 ptrdiff_t toppos
= marker_position (w
->start
);
23636 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
23637 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23639 if (botpos
>= BUF_ZV (b
))
23641 if (toppos
<= BUF_BEGV (b
))
23648 if (total
> 1000000)
23649 /* Do it differently for a large value, to avoid overflow. */
23650 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23652 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23653 /* We can't normally display a 3-digit number,
23654 so get us a 2-digit number that is close. */
23657 if (toppos
<= BUF_BEGV (b
))
23658 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
23660 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23661 return decode_mode_spec_buf
;
23666 /* status of process */
23667 obj
= Fget_buffer_process (Fcurrent_buffer ());
23669 return "no process";
23671 obj
= Fsymbol_name (Fprocess_status (obj
));
23677 ptrdiff_t count
= inhibit_garbage_collection ();
23678 Lisp_Object curdir
= BVAR (current_buffer
, directory
);
23679 Lisp_Object val
= Qnil
;
23681 if (STRINGP (curdir
))
23682 val
= call1 (intern ("file-remote-p"), curdir
);
23684 unbind_to (count
, Qnil
);
23693 /* coding-system (not including end-of-line format) */
23695 /* coding-system (including end-of-line type) */
23697 bool eol_flag
= (c
== 'Z');
23698 char *p
= decode_mode_spec_buf
;
23700 if (! FRAME_WINDOW_P (f
))
23702 /* No need to mention EOL here--the terminal never needs
23703 to do EOL conversion. */
23704 p
= decode_mode_spec_coding (CODING_ID_NAME
23705 (FRAME_KEYBOARD_CODING (f
)->id
),
23707 p
= decode_mode_spec_coding (CODING_ID_NAME
23708 (FRAME_TERMINAL_CODING (f
)->id
),
23711 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
23714 #if false /* This proves to be annoying; I think we can do without. -- rms. */
23715 #ifdef subprocesses
23716 obj
= Fget_buffer_process (Fcurrent_buffer ());
23717 if (PROCESSP (obj
))
23719 p
= decode_mode_spec_coding
23720 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
23721 p
= decode_mode_spec_coding
23722 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
23724 #endif /* subprocesses */
23727 return decode_mode_spec_buf
;
23734 return SSDATA (obj
);
23741 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
23742 means count lines back from START_BYTE. But don't go beyond
23743 LIMIT_BYTE. Return the number of lines thus found (always
23746 Set *BYTE_POS_PTR to the byte position where we stopped. This is
23747 either the position COUNT lines after/before START_BYTE, if we
23748 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
23752 display_count_lines (ptrdiff_t start_byte
,
23753 ptrdiff_t limit_byte
, ptrdiff_t count
,
23754 ptrdiff_t *byte_pos_ptr
)
23756 register unsigned char *cursor
;
23757 unsigned char *base
;
23759 register ptrdiff_t ceiling
;
23760 register unsigned char *ceiling_addr
;
23761 ptrdiff_t orig_count
= count
;
23763 /* If we are not in selective display mode,
23764 check only for newlines. */
23765 bool selective_display
23766 = (!NILP (BVAR (current_buffer
, selective_display
))
23767 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
23771 while (start_byte
< limit_byte
)
23773 ceiling
= BUFFER_CEILING_OF (start_byte
);
23774 ceiling
= min (limit_byte
- 1, ceiling
);
23775 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
23776 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
23780 if (selective_display
)
23782 while (*cursor
!= '\n' && *cursor
!= 015
23783 && ++cursor
!= ceiling_addr
)
23785 if (cursor
== ceiling_addr
)
23790 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
23799 start_byte
+= cursor
- base
;
23800 *byte_pos_ptr
= start_byte
;
23804 while (cursor
< ceiling_addr
);
23806 start_byte
+= ceiling_addr
- base
;
23811 while (start_byte
> limit_byte
)
23813 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
23814 ceiling
= max (limit_byte
, ceiling
);
23815 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
23816 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
23819 if (selective_display
)
23821 while (--cursor
>= ceiling_addr
23822 && *cursor
!= '\n' && *cursor
!= 015)
23824 if (cursor
< ceiling_addr
)
23829 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
23836 start_byte
+= cursor
- base
+ 1;
23837 *byte_pos_ptr
= start_byte
;
23838 /* When scanning backwards, we should
23839 not count the newline posterior to which we stop. */
23840 return - orig_count
- 1;
23843 start_byte
+= ceiling_addr
- base
;
23847 *byte_pos_ptr
= limit_byte
;
23850 return - orig_count
+ count
;
23851 return orig_count
- count
;
23857 /***********************************************************************
23859 ***********************************************************************/
23861 /* Display a NUL-terminated string, starting with index START.
23863 If STRING is non-null, display that C string. Otherwise, the Lisp
23864 string LISP_STRING is displayed. There's a case that STRING is
23865 non-null and LISP_STRING is not nil. It means STRING is a string
23866 data of LISP_STRING. In that case, we display LISP_STRING while
23867 ignoring its text properties.
23869 If FACE_STRING is not nil, FACE_STRING_POS is a position in
23870 FACE_STRING. Display STRING or LISP_STRING with the face at
23871 FACE_STRING_POS in FACE_STRING:
23873 Display the string in the environment given by IT, but use the
23874 standard display table, temporarily.
23876 FIELD_WIDTH is the minimum number of output glyphs to produce.
23877 If STRING has fewer characters than FIELD_WIDTH, pad to the right
23878 with spaces. If STRING has more characters, more than FIELD_WIDTH
23879 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
23881 PRECISION is the maximum number of characters to output from
23882 STRING. PRECISION < 0 means don't truncate the string.
23884 This is roughly equivalent to printf format specifiers:
23886 FIELD_WIDTH PRECISION PRINTF
23887 ----------------------------------------
23893 MULTIBYTE zero means do not display multibyte chars, > 0 means do
23894 display them, and < 0 means obey the current buffer's value of
23895 enable_multibyte_characters.
23897 Value is the number of columns displayed. */
23900 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
23901 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
23902 int field_width
, int precision
, int max_x
, int multibyte
)
23904 int hpos_at_start
= it
->hpos
;
23905 int saved_face_id
= it
->face_id
;
23906 struct glyph_row
*row
= it
->glyph_row
;
23907 ptrdiff_t it_charpos
;
23909 /* Initialize the iterator IT for iteration over STRING beginning
23910 with index START. */
23911 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
23912 precision
, field_width
, multibyte
);
23913 if (string
&& STRINGP (lisp_string
))
23914 /* LISP_STRING is the one returned by decode_mode_spec. We should
23915 ignore its text properties. */
23916 it
->stop_charpos
= it
->end_charpos
;
23918 /* If displaying STRING, set up the face of the iterator from
23919 FACE_STRING, if that's given. */
23920 if (STRINGP (face_string
))
23926 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
23927 0, &endptr
, it
->base_face_id
, false);
23928 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23929 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
23932 /* Set max_x to the maximum allowed X position. Don't let it go
23933 beyond the right edge of the window. */
23935 max_x
= it
->last_visible_x
;
23937 max_x
= min (max_x
, it
->last_visible_x
);
23939 /* Skip over display elements that are not visible. because IT->w is
23941 if (it
->current_x
< it
->first_visible_x
)
23942 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
23943 MOVE_TO_POS
| MOVE_TO_X
);
23945 row
->ascent
= it
->max_ascent
;
23946 row
->height
= it
->max_ascent
+ it
->max_descent
;
23947 row
->phys_ascent
= it
->max_phys_ascent
;
23948 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
23949 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
23951 if (STRINGP (it
->string
))
23952 it_charpos
= IT_STRING_CHARPOS (*it
);
23954 it_charpos
= IT_CHARPOS (*it
);
23956 /* This condition is for the case that we are called with current_x
23957 past last_visible_x. */
23958 while (it
->current_x
< max_x
)
23960 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
23962 /* Get the next display element. */
23963 if (!get_next_display_element (it
))
23966 /* Produce glyphs. */
23967 x_before
= it
->current_x
;
23968 n_glyphs_before
= row
->used
[TEXT_AREA
];
23969 PRODUCE_GLYPHS (it
);
23971 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
23974 while (i
< nglyphs
)
23976 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
23978 if (it
->line_wrap
!= TRUNCATE
23979 && x
+ glyph
->pixel_width
> max_x
)
23981 /* End of continued line or max_x reached. */
23982 if (CHAR_GLYPH_PADDING_P (*glyph
))
23984 /* A wide character is unbreakable. */
23985 if (row
->reversed_p
)
23986 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23987 - n_glyphs_before
);
23988 row
->used
[TEXT_AREA
] = n_glyphs_before
;
23989 it
->current_x
= x_before
;
23993 if (row
->reversed_p
)
23994 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23995 - (n_glyphs_before
+ i
));
23996 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
24001 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
24003 /* Glyph is at least partially visible. */
24005 if (x
< it
->first_visible_x
)
24006 row
->x
= x
- it
->first_visible_x
;
24010 /* Glyph is off the left margin of the display area.
24011 Should not happen. */
24015 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
24016 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
24017 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
24018 row
->phys_height
= max (row
->phys_height
,
24019 it
->max_phys_ascent
+ it
->max_phys_descent
);
24020 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
24021 it
->max_extra_line_spacing
);
24022 x
+= glyph
->pixel_width
;
24026 /* Stop if max_x reached. */
24030 /* Stop at line ends. */
24031 if (ITERATOR_AT_END_OF_LINE_P (it
))
24033 it
->continuation_lines_width
= 0;
24037 set_iterator_to_next (it
, true);
24038 if (STRINGP (it
->string
))
24039 it_charpos
= IT_STRING_CHARPOS (*it
);
24041 it_charpos
= IT_CHARPOS (*it
);
24043 /* Stop if truncating at the right edge. */
24044 if (it
->line_wrap
== TRUNCATE
24045 && it
->current_x
>= it
->last_visible_x
)
24047 /* Add truncation mark, but don't do it if the line is
24048 truncated at a padding space. */
24049 if (it_charpos
< it
->string_nchars
)
24051 if (!FRAME_WINDOW_P (it
->f
))
24055 if (it
->current_x
> it
->last_visible_x
)
24057 if (!row
->reversed_p
)
24059 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
24060 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
24065 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
24066 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
24068 unproduce_glyphs (it
, ii
+ 1);
24069 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
24071 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
24073 row
->used
[TEXT_AREA
] = ii
;
24074 produce_special_glyphs (it
, IT_TRUNCATION
);
24077 produce_special_glyphs (it
, IT_TRUNCATION
);
24079 row
->truncated_on_right_p
= true;
24085 /* Maybe insert a truncation at the left. */
24086 if (it
->first_visible_x
24089 if (!FRAME_WINDOW_P (it
->f
)
24090 || (row
->reversed_p
24091 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
24092 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
24093 insert_left_trunc_glyphs (it
);
24094 row
->truncated_on_left_p
= true;
24097 it
->face_id
= saved_face_id
;
24099 /* Value is number of columns displayed. */
24100 return it
->hpos
- hpos_at_start
;
24105 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
24106 appears as an element of LIST or as the car of an element of LIST.
24107 If PROPVAL is a list, compare each element against LIST in that
24108 way, and return 1/2 if any element of PROPVAL is found in LIST.
24109 Otherwise return 0. This function cannot quit.
24110 The return value is 2 if the text is invisible but with an ellipsis
24111 and 1 if it's invisible and without an ellipsis. */
24114 invisible_prop (Lisp_Object propval
, Lisp_Object list
)
24116 Lisp_Object tail
, proptail
;
24118 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
24120 register Lisp_Object tem
;
24122 if (EQ (propval
, tem
))
24124 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
24125 return NILP (XCDR (tem
)) ? 1 : 2;
24128 if (CONSP (propval
))
24130 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
24132 Lisp_Object propelt
;
24133 propelt
= XCAR (proptail
);
24134 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
24136 register Lisp_Object tem
;
24138 if (EQ (propelt
, tem
))
24140 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
24141 return NILP (XCDR (tem
)) ? 1 : 2;
24149 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
24150 doc
: /* Non-nil if the property makes the text invisible.
24151 POS-OR-PROP can be a marker or number, in which case it is taken to be
24152 a position in the current buffer and the value of the `invisible' property
24153 is checked; or it can be some other value, which is then presumed to be the
24154 value of the `invisible' property of the text of interest.
24155 The non-nil value returned can be t for truly invisible text or something
24156 else if the text is replaced by an ellipsis. */)
24157 (Lisp_Object pos_or_prop
)
24160 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
24161 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
24163 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
24164 return (invis
== 0 ? Qnil
24166 : make_number (invis
));
24169 /* Calculate a width or height in pixels from a specification using
24170 the following elements:
24173 NUM - a (fractional) multiple of the default font width/height
24174 (NUM) - specifies exactly NUM pixels
24175 UNIT - a fixed number of pixels, see below.
24176 ELEMENT - size of a display element in pixels, see below.
24177 (NUM . SPEC) - equals NUM * SPEC
24178 (+ SPEC SPEC ...) - add pixel values
24179 (- SPEC SPEC ...) - subtract pixel values
24180 (- SPEC) - negate pixel value
24183 INT or FLOAT - a number constant
24184 SYMBOL - use symbol's (buffer local) variable binding.
24187 in - pixels per inch *)
24188 mm - pixels per 1/1000 meter *)
24189 cm - pixels per 1/100 meter *)
24190 width - width of current font in pixels.
24191 height - height of current font in pixels.
24193 *) using the ratio(s) defined in display-pixels-per-inch.
24197 left-fringe - left fringe width in pixels
24198 right-fringe - right fringe width in pixels
24200 left-margin - left margin width in pixels
24201 right-margin - right margin width in pixels
24203 scroll-bar - scroll-bar area width in pixels
24207 Pixels corresponding to 5 inches:
24210 Total width of non-text areas on left side of window (if scroll-bar is on left):
24211 '(space :width (+ left-fringe left-margin scroll-bar))
24213 Align to first text column (in header line):
24214 '(space :align-to 0)
24216 Align to middle of text area minus half the width of variable `my-image'
24217 containing a loaded image:
24218 '(space :align-to (0.5 . (- text my-image)))
24220 Width of left margin minus width of 1 character in the default font:
24221 '(space :width (- left-margin 1))
24223 Width of left margin minus width of 2 characters in the current font:
24224 '(space :width (- left-margin (2 . width)))
24226 Center 1 character over left-margin (in header line):
24227 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
24229 Different ways to express width of left fringe plus left margin minus one pixel:
24230 '(space :width (- (+ left-fringe left-margin) (1)))
24231 '(space :width (+ left-fringe left-margin (- (1))))
24232 '(space :width (+ left-fringe left-margin (-1)))
24237 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
24238 struct font
*font
, bool width_p
, int *align_to
)
24242 # define OK_PIXELS(val) (*res = (val), true)
24243 # define OK_ALIGN_TO(val) (*align_to = (val), true)
24246 return OK_PIXELS (0);
24248 eassert (FRAME_LIVE_P (it
->f
));
24250 if (SYMBOLP (prop
))
24252 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
24254 char *unit
= SSDATA (SYMBOL_NAME (prop
));
24256 if (unit
[0] == 'i' && unit
[1] == 'n')
24258 else if (unit
[0] == 'm' && unit
[1] == 'm')
24260 else if (unit
[0] == 'c' && unit
[1] == 'm')
24266 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
24267 : FRAME_RES_Y (it
->f
));
24270 return OK_PIXELS (ppi
/ pixels
);
24275 #ifdef HAVE_WINDOW_SYSTEM
24276 if (EQ (prop
, Qheight
))
24277 return OK_PIXELS (font
24278 ? normal_char_height (font
, -1)
24279 : FRAME_LINE_HEIGHT (it
->f
));
24280 if (EQ (prop
, Qwidth
))
24281 return OK_PIXELS (font
24282 ? FONT_WIDTH (font
)
24283 : FRAME_COLUMN_WIDTH (it
->f
));
24285 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
24286 return OK_PIXELS (1);
24289 if (EQ (prop
, Qtext
))
24290 return OK_PIXELS (width_p
24291 ? window_box_width (it
->w
, TEXT_AREA
)
24292 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
24294 if (align_to
&& *align_to
< 0)
24297 if (EQ (prop
, Qleft
))
24298 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
24299 if (EQ (prop
, Qright
))
24300 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
24301 if (EQ (prop
, Qcenter
))
24302 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
24303 + window_box_width (it
->w
, TEXT_AREA
) / 2);
24304 if (EQ (prop
, Qleft_fringe
))
24305 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24306 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
24307 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
24308 if (EQ (prop
, Qright_fringe
))
24309 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24310 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
24311 : window_box_right_offset (it
->w
, TEXT_AREA
));
24312 if (EQ (prop
, Qleft_margin
))
24313 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
24314 if (EQ (prop
, Qright_margin
))
24315 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
24316 if (EQ (prop
, Qscroll_bar
))
24317 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
24319 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
24320 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24321 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
24326 if (EQ (prop
, Qleft_fringe
))
24327 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
24328 if (EQ (prop
, Qright_fringe
))
24329 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
24330 if (EQ (prop
, Qleft_margin
))
24331 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
24332 if (EQ (prop
, Qright_margin
))
24333 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
24334 if (EQ (prop
, Qscroll_bar
))
24335 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
24338 prop
= buffer_local_value (prop
, it
->w
->contents
);
24339 if (EQ (prop
, Qunbound
))
24343 if (NUMBERP (prop
))
24345 int base_unit
= (width_p
24346 ? FRAME_COLUMN_WIDTH (it
->f
)
24347 : FRAME_LINE_HEIGHT (it
->f
));
24348 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
24353 Lisp_Object car
= XCAR (prop
);
24354 Lisp_Object cdr
= XCDR (prop
);
24358 #ifdef HAVE_WINDOW_SYSTEM
24359 if (FRAME_WINDOW_P (it
->f
)
24360 && valid_image_p (prop
))
24362 ptrdiff_t id
= lookup_image (it
->f
, prop
);
24363 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
24365 return OK_PIXELS (width_p
? img
->width
: img
->height
);
24367 # ifdef HAVE_XWIDGETS
24368 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_spec_p (prop
))
24370 // TODO: Don't return dummy size.
24371 return OK_PIXELS (100);
24375 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
24381 while (CONSP (cdr
))
24383 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
24384 font
, width_p
, align_to
))
24387 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= false;
24392 if (EQ (car
, Qminus
))
24394 return OK_PIXELS (pixels
);
24397 car
= buffer_local_value (car
, it
->w
->contents
);
24398 if (EQ (car
, Qunbound
))
24405 pixels
= XFLOATINT (car
);
24407 return OK_PIXELS (pixels
);
24408 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
24409 font
, width_p
, align_to
))
24410 return OK_PIXELS (pixels
* fact
);
24421 get_font_ascent_descent (struct font
*font
, int *ascent
, int *descent
)
24423 #ifdef HAVE_WINDOW_SYSTEM
24424 normal_char_ascent_descent (font
, -1, ascent
, descent
);
24432 /***********************************************************************
24434 ***********************************************************************/
24436 #ifdef HAVE_WINDOW_SYSTEM
24441 dump_glyph_string (struct glyph_string
*s
)
24443 fprintf (stderr
, "glyph string\n");
24444 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
24445 s
->x
, s
->y
, s
->width
, s
->height
);
24446 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
24447 fprintf (stderr
, " hl = %d\n", s
->hl
);
24448 fprintf (stderr
, " left overhang = %d, right = %d\n",
24449 s
->left_overhang
, s
->right_overhang
);
24450 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
24451 fprintf (stderr
, " extends to end of line = %d\n",
24452 s
->extends_to_end_of_line_p
);
24453 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
24454 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
24457 #endif /* GLYPH_DEBUG */
24459 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
24460 of XChar2b structures for S; it can't be allocated in
24461 init_glyph_string because it must be allocated via `alloca'. W
24462 is the window on which S is drawn. ROW and AREA are the glyph row
24463 and area within the row from which S is constructed. START is the
24464 index of the first glyph structure covered by S. HL is a
24465 face-override for drawing S. */
24468 #define OPTIONAL_HDC(hdc) HDC hdc,
24469 #define DECLARE_HDC(hdc) HDC hdc;
24470 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
24471 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
24474 #ifndef OPTIONAL_HDC
24475 #define OPTIONAL_HDC(hdc)
24476 #define DECLARE_HDC(hdc)
24477 #define ALLOCATE_HDC(hdc, f)
24478 #define RELEASE_HDC(hdc, f)
24482 init_glyph_string (struct glyph_string
*s
,
24484 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
24485 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
24487 memset (s
, 0, sizeof *s
);
24489 s
->f
= XFRAME (w
->frame
);
24493 s
->display
= FRAME_X_DISPLAY (s
->f
);
24494 s
->window
= FRAME_X_WINDOW (s
->f
);
24495 s
->char2b
= char2b
;
24499 s
->first_glyph
= row
->glyphs
[area
] + start
;
24500 s
->height
= row
->height
;
24501 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
24502 s
->ybase
= s
->y
+ row
->ascent
;
24506 /* Append the list of glyph strings with head H and tail T to the list
24507 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
24510 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24511 struct glyph_string
*h
, struct glyph_string
*t
)
24525 /* Prepend the list of glyph strings with head H and tail T to the
24526 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
24530 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24531 struct glyph_string
*h
, struct glyph_string
*t
)
24545 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
24546 Set *HEAD and *TAIL to the resulting list. */
24549 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
24550 struct glyph_string
*s
)
24552 s
->next
= s
->prev
= NULL
;
24553 append_glyph_string_lists (head
, tail
, s
, s
);
24557 /* Get face and two-byte form of character C in face FACE_ID on frame F.
24558 The encoding of C is returned in *CHAR2B. DISPLAY_P means
24559 make sure that X resources for the face returned are allocated.
24560 Value is a pointer to a realized face that is ready for display if
24563 static struct face
*
24564 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
24565 XChar2b
*char2b
, bool display_p
)
24567 struct face
*face
= FACE_FROM_ID (f
, face_id
);
24572 code
= face
->font
->driver
->encode_char (face
->font
, c
);
24574 if (code
== FONT_INVALID_CODE
)
24577 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24579 /* Make sure X resources of the face are allocated. */
24580 #ifdef HAVE_X_WINDOWS
24584 eassert (face
!= NULL
);
24585 prepare_face_for_display (f
, face
);
24592 /* Get face and two-byte form of character glyph GLYPH on frame F.
24593 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
24594 a pointer to a realized face that is ready for display. */
24596 static struct face
*
24597 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
24603 eassert (glyph
->type
== CHAR_GLYPH
);
24604 face
= FACE_FROM_ID (f
, glyph
->face_id
);
24606 /* Make sure X resources of the face are allocated. */
24607 eassert (face
!= NULL
);
24608 prepare_face_for_display (f
, face
);
24612 if (CHAR_BYTE8_P (glyph
->u
.ch
))
24613 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
24615 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
24617 if (code
== FONT_INVALID_CODE
)
24621 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24626 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
24627 Return true iff FONT has a glyph for C. */
24630 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
24634 if (CHAR_BYTE8_P (c
))
24635 code
= CHAR_TO_BYTE8 (c
);
24637 code
= font
->driver
->encode_char (font
, c
);
24639 if (code
== FONT_INVALID_CODE
)
24641 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24646 /* Fill glyph string S with composition components specified by S->cmp.
24648 BASE_FACE is the base face of the composition.
24649 S->cmp_from is the index of the first component for S.
24651 OVERLAPS non-zero means S should draw the foreground only, and use
24652 its physical height for clipping. See also draw_glyphs.
24654 Value is the index of a component not in S. */
24657 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
24661 /* For all glyphs of this composition, starting at the offset
24662 S->cmp_from, until we reach the end of the definition or encounter a
24663 glyph that requires the different face, add it to S. */
24668 s
->for_overlaps
= overlaps
;
24671 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
24673 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
24675 /* TAB in a composition means display glyphs with padding space
24676 on the left or right. */
24679 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
24682 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
24683 s
->char2b
+ i
, true);
24689 s
->font
= s
->face
->font
;
24691 else if (s
->face
!= face
)
24699 if (s
->face
== NULL
)
24701 s
->face
= base_face
->ascii_face
;
24702 s
->font
= s
->face
->font
;
24705 /* All glyph strings for the same composition has the same width,
24706 i.e. the width set for the first component of the composition. */
24707 s
->width
= s
->first_glyph
->pixel_width
;
24709 /* If the specified font could not be loaded, use the frame's
24710 default font, but record the fact that we couldn't load it in
24711 the glyph string so that we can draw rectangles for the
24712 characters of the glyph string. */
24713 if (s
->font
== NULL
)
24715 s
->font_not_found_p
= true;
24716 s
->font
= FRAME_FONT (s
->f
);
24719 /* Adjust base line for subscript/superscript text. */
24720 s
->ybase
+= s
->first_glyph
->voffset
;
24726 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
24727 int start
, int end
, int overlaps
)
24729 struct glyph
*glyph
, *last
;
24730 Lisp_Object lgstring
;
24733 s
->for_overlaps
= overlaps
;
24734 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24735 last
= s
->row
->glyphs
[s
->area
] + end
;
24736 s
->cmp_id
= glyph
->u
.cmp
.id
;
24737 s
->cmp_from
= glyph
->slice
.cmp
.from
;
24738 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
24739 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24740 lgstring
= composition_gstring_from_id (s
->cmp_id
);
24741 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
24743 while (glyph
< last
24744 && glyph
->u
.cmp
.automatic
24745 && glyph
->u
.cmp
.id
== s
->cmp_id
24746 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
24747 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
24749 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
24751 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
24752 unsigned code
= LGLYPH_CODE (lglyph
);
24754 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
24756 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
24757 return glyph
- s
->row
->glyphs
[s
->area
];
24761 /* Fill glyph string S from a sequence glyphs for glyphless characters.
24762 See the comment of fill_glyph_string for arguments.
24763 Value is the index of the first glyph not in S. */
24767 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
24768 int start
, int end
, int overlaps
)
24770 struct glyph
*glyph
, *last
;
24773 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
24774 s
->for_overlaps
= overlaps
;
24775 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24776 last
= s
->row
->glyphs
[s
->area
] + end
;
24777 voffset
= glyph
->voffset
;
24778 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24779 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
24781 s
->width
= glyph
->pixel_width
;
24783 while (glyph
< last
24784 && glyph
->type
== GLYPHLESS_GLYPH
24785 && glyph
->voffset
== voffset
24786 && glyph
->face_id
== face_id
)
24789 s
->width
+= glyph
->pixel_width
;
24792 s
->ybase
+= voffset
;
24793 return glyph
- s
->row
->glyphs
[s
->area
];
24797 /* Fill glyph string S from a sequence of character glyphs.
24799 FACE_ID is the face id of the string. START is the index of the
24800 first glyph to consider, END is the index of the last + 1.
24801 OVERLAPS non-zero means S should draw the foreground only, and use
24802 its physical height for clipping. See also draw_glyphs.
24804 Value is the index of the first glyph not in S. */
24807 fill_glyph_string (struct glyph_string
*s
, int face_id
,
24808 int start
, int end
, int overlaps
)
24810 struct glyph
*glyph
, *last
;
24812 bool glyph_not_available_p
;
24814 eassert (s
->f
== XFRAME (s
->w
->frame
));
24815 eassert (s
->nchars
== 0);
24816 eassert (start
>= 0 && end
> start
);
24818 s
->for_overlaps
= overlaps
;
24819 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24820 last
= s
->row
->glyphs
[s
->area
] + end
;
24821 voffset
= glyph
->voffset
;
24822 s
->padding_p
= glyph
->padding_p
;
24823 glyph_not_available_p
= glyph
->glyph_not_available_p
;
24825 while (glyph
< last
24826 && glyph
->type
== CHAR_GLYPH
24827 && glyph
->voffset
== voffset
24828 /* Same face id implies same font, nowadays. */
24829 && glyph
->face_id
== face_id
24830 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
24832 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
24833 s
->char2b
+ s
->nchars
);
24835 eassert (s
->nchars
<= end
- start
);
24836 s
->width
+= glyph
->pixel_width
;
24837 if (glyph
++->padding_p
!= s
->padding_p
)
24841 s
->font
= s
->face
->font
;
24843 /* If the specified font could not be loaded, use the frame's font,
24844 but record the fact that we couldn't load it in
24845 S->font_not_found_p so that we can draw rectangles for the
24846 characters of the glyph string. */
24847 if (s
->font
== NULL
|| glyph_not_available_p
)
24849 s
->font_not_found_p
= true;
24850 s
->font
= FRAME_FONT (s
->f
);
24853 /* Adjust base line for subscript/superscript text. */
24854 s
->ybase
+= voffset
;
24856 eassert (s
->face
&& s
->face
->gc
);
24857 return glyph
- s
->row
->glyphs
[s
->area
];
24861 /* Fill glyph string S from image glyph S->first_glyph. */
24864 fill_image_glyph_string (struct glyph_string
*s
)
24866 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
24867 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
24869 s
->slice
= s
->first_glyph
->slice
.img
;
24870 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24871 s
->font
= s
->face
->font
;
24872 s
->width
= s
->first_glyph
->pixel_width
;
24874 /* Adjust base line for subscript/superscript text. */
24875 s
->ybase
+= s
->first_glyph
->voffset
;
24879 #ifdef HAVE_XWIDGETS
24881 fill_xwidget_glyph_string (struct glyph_string
*s
)
24883 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
24884 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24885 s
->font
= s
->face
->font
;
24886 s
->width
= s
->first_glyph
->pixel_width
;
24887 s
->ybase
+= s
->first_glyph
->voffset
;
24888 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
24891 /* Fill glyph string S from a sequence of stretch glyphs.
24893 START is the index of the first glyph to consider,
24894 END is the index of the last + 1.
24896 Value is the index of the first glyph not in S. */
24899 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
24901 struct glyph
*glyph
, *last
;
24902 int voffset
, face_id
;
24904 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
24906 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24907 last
= s
->row
->glyphs
[s
->area
] + end
;
24908 face_id
= glyph
->face_id
;
24909 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24910 s
->font
= s
->face
->font
;
24911 s
->width
= glyph
->pixel_width
;
24913 voffset
= glyph
->voffset
;
24917 && glyph
->type
== STRETCH_GLYPH
24918 && glyph
->voffset
== voffset
24919 && glyph
->face_id
== face_id
);
24921 s
->width
+= glyph
->pixel_width
;
24923 /* Adjust base line for subscript/superscript text. */
24924 s
->ybase
+= voffset
;
24926 /* The case that face->gc == 0 is handled when drawing the glyph
24927 string by calling prepare_face_for_display. */
24929 return glyph
- s
->row
->glyphs
[s
->area
];
24932 static struct font_metrics
*
24933 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
24935 static struct font_metrics metrics
;
24940 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
24941 if (code
== FONT_INVALID_CODE
)
24943 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
24947 /* A subroutine that computes "normal" values of ASCENT and DESCENT
24948 for FONT. Values are taken from font-global ones, except for fonts
24949 that claim preposterously large values, but whose glyphs actually
24950 have reasonable dimensions. C is the character to use for metrics
24951 if the font-global values are too large; if C is negative, the
24952 function selects a default character. */
24954 normal_char_ascent_descent (struct font
*font
, int c
, int *ascent
, int *descent
)
24956 *ascent
= FONT_BASE (font
);
24957 *descent
= FONT_DESCENT (font
);
24959 if (FONT_TOO_HIGH (font
))
24963 /* Get metrics of C, defaulting to a reasonably sized ASCII
24965 if (get_char_glyph_code (c
>= 0 ? c
: '{', font
, &char2b
))
24967 struct font_metrics
*pcm
= get_per_char_metric (font
, &char2b
);
24969 if (!(pcm
->width
== 0 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0))
24971 /* We add 1 pixel to character dimensions as heuristics
24972 that produces nicer display, e.g. when the face has
24973 the box attribute. */
24974 *ascent
= pcm
->ascent
+ 1;
24975 *descent
= pcm
->descent
+ 1;
24981 /* A subroutine that computes a reasonable "normal character height"
24982 for fonts that claim preposterously large vertical dimensions, but
24983 whose glyphs are actually reasonably sized. C is the character
24984 whose metrics to use for those fonts, or -1 for default
24987 normal_char_height (struct font
*font
, int c
)
24989 int ascent
, descent
;
24991 normal_char_ascent_descent (font
, c
, &ascent
, &descent
);
24993 return ascent
+ descent
;
24997 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
24998 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
24999 assumed to be zero. */
25002 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
25004 *left
= *right
= 0;
25006 if (glyph
->type
== CHAR_GLYPH
)
25009 struct face
*face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
);
25012 struct font_metrics
*pcm
= get_per_char_metric (face
->font
, &char2b
);
25015 if (pcm
->rbearing
> pcm
->width
)
25016 *right
= pcm
->rbearing
- pcm
->width
;
25017 if (pcm
->lbearing
< 0)
25018 *left
= -pcm
->lbearing
;
25022 else if (glyph
->type
== COMPOSITE_GLYPH
)
25024 if (! glyph
->u
.cmp
.automatic
)
25026 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
25028 if (cmp
->rbearing
> cmp
->pixel_width
)
25029 *right
= cmp
->rbearing
- cmp
->pixel_width
;
25030 if (cmp
->lbearing
< 0)
25031 *left
= - cmp
->lbearing
;
25035 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
25036 struct font_metrics metrics
;
25038 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
25039 glyph
->slice
.cmp
.to
+ 1, &metrics
);
25040 if (metrics
.rbearing
> metrics
.width
)
25041 *right
= metrics
.rbearing
- metrics
.width
;
25042 if (metrics
.lbearing
< 0)
25043 *left
= - metrics
.lbearing
;
25049 /* Return the index of the first glyph preceding glyph string S that
25050 is overwritten by S because of S's left overhang. Value is -1
25051 if no glyphs are overwritten. */
25054 left_overwritten (struct glyph_string
*s
)
25058 if (s
->left_overhang
)
25061 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25062 int first
= s
->first_glyph
- glyphs
;
25064 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
25065 x
-= glyphs
[i
].pixel_width
;
25076 /* Return the index of the first glyph preceding glyph string S that
25077 is overwriting S because of its right overhang. Value is -1 if no
25078 glyph in front of S overwrites S. */
25081 left_overwriting (struct glyph_string
*s
)
25084 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25085 int first
= s
->first_glyph
- glyphs
;
25089 for (i
= first
- 1; i
>= 0; --i
)
25092 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
25095 x
-= glyphs
[i
].pixel_width
;
25102 /* Return the index of the last glyph following glyph string S that is
25103 overwritten by S because of S's right overhang. Value is -1 if
25104 no such glyph is found. */
25107 right_overwritten (struct glyph_string
*s
)
25111 if (s
->right_overhang
)
25114 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25115 int first
= (s
->first_glyph
- glyphs
25116 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
25117 int end
= s
->row
->used
[s
->area
];
25119 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
25120 x
+= glyphs
[i
].pixel_width
;
25129 /* Return the index of the last glyph following glyph string S that
25130 overwrites S because of its left overhang. Value is negative
25131 if no such glyph is found. */
25134 right_overwriting (struct glyph_string
*s
)
25137 int end
= s
->row
->used
[s
->area
];
25138 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25139 int first
= (s
->first_glyph
- glyphs
25140 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
25144 for (i
= first
; i
< end
; ++i
)
25147 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
25150 x
+= glyphs
[i
].pixel_width
;
25157 /* Set background width of glyph string S. START is the index of the
25158 first glyph following S. LAST_X is the right-most x-position + 1
25159 in the drawing area. */
25162 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
25164 /* If the face of this glyph string has to be drawn to the end of
25165 the drawing area, set S->extends_to_end_of_line_p. */
25167 if (start
== s
->row
->used
[s
->area
]
25168 && ((s
->row
->fill_line_p
25169 && (s
->hl
== DRAW_NORMAL_TEXT
25170 || s
->hl
== DRAW_IMAGE_RAISED
25171 || s
->hl
== DRAW_IMAGE_SUNKEN
))
25172 || s
->hl
== DRAW_MOUSE_FACE
))
25173 s
->extends_to_end_of_line_p
= true;
25175 /* If S extends its face to the end of the line, set its
25176 background_width to the distance to the right edge of the drawing
25178 if (s
->extends_to_end_of_line_p
)
25179 s
->background_width
= last_x
- s
->x
+ 1;
25181 s
->background_width
= s
->width
;
25185 /* Compute overhangs and x-positions for glyph string S and its
25186 predecessors, or successors. X is the starting x-position for S.
25187 BACKWARD_P means process predecessors. */
25190 compute_overhangs_and_x (struct glyph_string
*s
, int x
, bool backward_p
)
25196 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
25197 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
25207 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
25208 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
25218 /* The following macros are only called from draw_glyphs below.
25219 They reference the following parameters of that function directly:
25220 `w', `row', `area', and `overlap_p'
25221 as well as the following local variables:
25222 `s', `f', and `hdc' (in W32) */
25225 /* On W32, silently add local `hdc' variable to argument list of
25226 init_glyph_string. */
25227 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
25228 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
25230 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
25231 init_glyph_string (s, char2b, w, row, area, start, hl)
25234 /* Add a glyph string for a stretch glyph to the list of strings
25235 between HEAD and TAIL. START is the index of the stretch glyph in
25236 row area AREA of glyph row ROW. END is the index of the last glyph
25237 in that glyph row area. X is the current output position assigned
25238 to the new glyph string constructed. HL overrides that face of the
25239 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
25240 is the right-most x-position of the drawing area. */
25242 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
25243 and below -- keep them on one line. */
25244 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25247 s = alloca (sizeof *s); \
25248 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25249 START = fill_stretch_glyph_string (s, START, END); \
25250 append_glyph_string (&HEAD, &TAIL, s); \
25256 /* Add a glyph string for an image glyph to the list of strings
25257 between HEAD and TAIL. START is the index of the image glyph in
25258 row area AREA of glyph row ROW. END is the index of the last glyph
25259 in that glyph row area. X is the current output position assigned
25260 to the new glyph string constructed. HL overrides that face of the
25261 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
25262 is the right-most x-position of the drawing area. */
25264 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25267 s = alloca (sizeof *s); \
25268 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25269 fill_image_glyph_string (s); \
25270 append_glyph_string (&HEAD, &TAIL, s); \
25276 #ifdef HAVE_XWIDGETS
25277 #define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25280 s = alloca (sizeof *s); \
25281 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25282 fill_xwidget_glyph_string (s); \
25283 append_glyph_string (&(HEAD), &(TAIL), s); \
25291 /* Add a glyph string for a sequence of character glyphs to the list
25292 of strings between HEAD and TAIL. START is the index of the first
25293 glyph in row area AREA of glyph row ROW that is part of the new
25294 glyph string. END is the index of the last glyph in that glyph row
25295 area. X is the current output position assigned to the new glyph
25296 string constructed. HL overrides that face of the glyph; e.g. it
25297 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
25298 right-most x-position of the drawing area. */
25300 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25306 face_id = (row)->glyphs[area][START].face_id; \
25308 s = alloca (sizeof *s); \
25309 SAFE_NALLOCA (char2b, 1, (END) - (START)); \
25310 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25311 append_glyph_string (&HEAD, &TAIL, s); \
25313 START = fill_glyph_string (s, face_id, START, END, overlaps); \
25318 /* Add a glyph string for a composite sequence to the list of strings
25319 between HEAD and TAIL. START is the index of the first glyph in
25320 row area AREA of glyph row ROW that is part of the new glyph
25321 string. END is the index of the last glyph in that glyph row area.
25322 X is the current output position assigned to the new glyph string
25323 constructed. HL overrides that face of the glyph; e.g. it is
25324 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
25325 x-position of the drawing area. */
25327 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25329 int face_id = (row)->glyphs[area][START].face_id; \
25330 struct face *base_face = FACE_FROM_ID (f, face_id); \
25331 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
25332 struct composition *cmp = composition_table[cmp_id]; \
25334 struct glyph_string *first_s = NULL; \
25337 SAFE_NALLOCA (char2b, 1, cmp->glyph_len); \
25339 /* Make glyph_strings for each glyph sequence that is drawable by \
25340 the same face, and append them to HEAD/TAIL. */ \
25341 for (n = 0; n < cmp->glyph_len;) \
25343 s = alloca (sizeof *s); \
25344 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25345 append_glyph_string (&(HEAD), &(TAIL), s); \
25351 n = fill_composite_glyph_string (s, base_face, overlaps); \
25359 /* Add a glyph string for a glyph-string sequence to the list of strings
25360 between HEAD and TAIL. */
25362 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25366 Lisp_Object gstring; \
25368 face_id = (row)->glyphs[area][START].face_id; \
25369 gstring = (composition_gstring_from_id \
25370 ((row)->glyphs[area][START].u.cmp.id)); \
25371 s = alloca (sizeof *s); \
25372 SAFE_NALLOCA (char2b, 1, LGSTRING_GLYPH_LEN (gstring)); \
25373 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25374 append_glyph_string (&(HEAD), &(TAIL), s); \
25376 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
25380 /* Add a glyph string for a sequence of glyphless character's glyphs
25381 to the list of strings between HEAD and TAIL. The meanings of
25382 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
25384 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25389 face_id = (row)->glyphs[area][START].face_id; \
25391 s = alloca (sizeof *s); \
25392 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25393 append_glyph_string (&HEAD, &TAIL, s); \
25395 START = fill_glyphless_glyph_string (s, face_id, START, END, \
25401 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
25402 of AREA of glyph row ROW on window W between indices START and END.
25403 HL overrides the face for drawing glyph strings, e.g. it is
25404 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
25405 x-positions of the drawing area.
25407 This is an ugly monster macro construct because we must use alloca
25408 to allocate glyph strings (because draw_glyphs can be called
25409 asynchronously). */
25411 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25414 HEAD = TAIL = NULL; \
25415 while (START < END) \
25417 struct glyph *first_glyph = (row)->glyphs[area] + START; \
25418 switch (first_glyph->type) \
25421 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
25425 case COMPOSITE_GLYPH: \
25426 if (first_glyph->u.cmp.automatic) \
25427 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
25430 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
25434 case STRETCH_GLYPH: \
25435 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
25439 case IMAGE_GLYPH: \
25440 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
25444 #ifdef HAVE_XWIDGETS
25445 # define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25446 case XWIDGET_GLYPH: \
25447 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
25452 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
25453 case GLYPHLESS_GLYPH: \
25454 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
25464 set_glyph_string_background_width (s, START, LAST_X); \
25471 #ifdef HAVE_XWIDGETS
25472 # define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25473 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25474 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25475 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
25477 # define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25478 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25479 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
25483 /* Draw glyphs between START and END in AREA of ROW on window W,
25484 starting at x-position X. X is relative to AREA in W. HL is a
25485 face-override with the following meaning:
25487 DRAW_NORMAL_TEXT draw normally
25488 DRAW_CURSOR draw in cursor face
25489 DRAW_MOUSE_FACE draw in mouse face.
25490 DRAW_INVERSE_VIDEO draw in mode line face
25491 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
25492 DRAW_IMAGE_RAISED draw an image with a raised relief around it
25494 If OVERLAPS is non-zero, draw only the foreground of characters and
25495 clip to the physical height of ROW. Non-zero value also defines
25496 the overlapping part to be drawn:
25498 OVERLAPS_PRED overlap with preceding rows
25499 OVERLAPS_SUCC overlap with succeeding rows
25500 OVERLAPS_BOTH overlap with both preceding/succeeding rows
25501 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
25503 Value is the x-position reached, relative to AREA of W. */
25506 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
25507 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
25508 enum draw_glyphs_face hl
, int overlaps
)
25510 struct glyph_string
*head
, *tail
;
25511 struct glyph_string
*s
;
25512 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
25513 int i
, j
, x_reached
, last_x
, area_left
= 0;
25514 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25517 ALLOCATE_HDC (hdc
, f
);
25519 /* Let's rather be paranoid than getting a SEGV. */
25520 end
= min (end
, row
->used
[area
]);
25521 start
= clip_to_bounds (0, start
, end
);
25523 /* Translate X to frame coordinates. Set last_x to the right
25524 end of the drawing area. */
25525 if (row
->full_width_p
)
25527 /* X is relative to the left edge of W, without scroll bars
25529 area_left
= WINDOW_LEFT_EDGE_X (w
);
25530 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
25531 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
25535 area_left
= window_box_left (w
, area
);
25536 last_x
= area_left
+ window_box_width (w
, area
);
25540 /* Build a doubly-linked list of glyph_string structures between
25541 head and tail from what we have to draw. Note that the macro
25542 BUILD_GLYPH_STRINGS will modify its start parameter. That's
25543 the reason we use a separate variable `i'. */
25546 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
25548 x_reached
= tail
->x
+ tail
->background_width
;
25552 /* If there are any glyphs with lbearing < 0 or rbearing > width in
25553 the row, redraw some glyphs in front or following the glyph
25554 strings built above. */
25555 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
25557 struct glyph_string
*h
, *t
;
25558 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25559 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
25560 bool check_mouse_face
= false;
25563 /* If mouse highlighting is on, we may need to draw adjacent
25564 glyphs using mouse-face highlighting. */
25565 if (area
== TEXT_AREA
&& row
->mouse_face_p
25566 && hlinfo
->mouse_face_beg_row
>= 0
25567 && hlinfo
->mouse_face_end_row
>= 0)
25569 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
25571 if (row_vpos
>= hlinfo
->mouse_face_beg_row
25572 && row_vpos
<= hlinfo
->mouse_face_end_row
)
25574 check_mouse_face
= true;
25575 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
25576 ? hlinfo
->mouse_face_beg_col
: 0;
25577 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
25578 ? hlinfo
->mouse_face_end_col
25579 : row
->used
[TEXT_AREA
];
25583 /* Compute overhangs for all glyph strings. */
25584 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
25585 for (s
= head
; s
; s
= s
->next
)
25586 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
25588 /* Prepend glyph strings for glyphs in front of the first glyph
25589 string that are overwritten because of the first glyph
25590 string's left overhang. The background of all strings
25591 prepended must be drawn because the first glyph string
25593 i
= left_overwritten (head
);
25596 enum draw_glyphs_face overlap_hl
;
25598 /* If this row contains mouse highlighting, attempt to draw
25599 the overlapped glyphs with the correct highlight. This
25600 code fails if the overlap encompasses more than one glyph
25601 and mouse-highlight spans only some of these glyphs.
25602 However, making it work perfectly involves a lot more
25603 code, and I don't know if the pathological case occurs in
25604 practice, so we'll stick to this for now. --- cyd */
25605 if (check_mouse_face
25606 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25607 overlap_hl
= DRAW_MOUSE_FACE
;
25609 overlap_hl
= DRAW_NORMAL_TEXT
;
25611 if (hl
!= overlap_hl
)
25614 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
25615 overlap_hl
, dummy_x
, last_x
);
25617 compute_overhangs_and_x (t
, head
->x
, true);
25618 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25619 if (clip_head
== NULL
)
25623 /* Prepend glyph strings for glyphs in front of the first glyph
25624 string that overwrite that glyph string because of their
25625 right overhang. For these strings, only the foreground must
25626 be drawn, because it draws over the glyph string at `head'.
25627 The background must not be drawn because this would overwrite
25628 right overhangs of preceding glyphs for which no glyph
25630 i
= left_overwriting (head
);
25633 enum draw_glyphs_face overlap_hl
;
25635 if (check_mouse_face
25636 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25637 overlap_hl
= DRAW_MOUSE_FACE
;
25639 overlap_hl
= DRAW_NORMAL_TEXT
;
25641 if (hl
== overlap_hl
|| clip_head
== NULL
)
25643 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
25644 overlap_hl
, dummy_x
, last_x
);
25645 for (s
= h
; s
; s
= s
->next
)
25646 s
->background_filled_p
= true;
25647 compute_overhangs_and_x (t
, head
->x
, true);
25648 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25651 /* Append glyphs strings for glyphs following the last glyph
25652 string tail that are overwritten by tail. The background of
25653 these strings has to be drawn because tail's foreground draws
25655 i
= right_overwritten (tail
);
25658 enum draw_glyphs_face overlap_hl
;
25660 if (check_mouse_face
25661 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25662 overlap_hl
= DRAW_MOUSE_FACE
;
25664 overlap_hl
= DRAW_NORMAL_TEXT
;
25666 if (hl
!= overlap_hl
)
25668 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25669 overlap_hl
, x
, last_x
);
25670 /* Because BUILD_GLYPH_STRINGS updates the first argument,
25671 we don't have `end = i;' here. */
25672 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25673 append_glyph_string_lists (&head
, &tail
, h
, t
);
25674 if (clip_tail
== NULL
)
25678 /* Append glyph strings for glyphs following the last glyph
25679 string tail that overwrite tail. The foreground of such
25680 glyphs has to be drawn because it writes into the background
25681 of tail. The background must not be drawn because it could
25682 paint over the foreground of following glyphs. */
25683 i
= right_overwriting (tail
);
25686 enum draw_glyphs_face overlap_hl
;
25687 if (check_mouse_face
25688 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25689 overlap_hl
= DRAW_MOUSE_FACE
;
25691 overlap_hl
= DRAW_NORMAL_TEXT
;
25693 if (hl
== overlap_hl
|| clip_tail
== NULL
)
25695 i
++; /* We must include the Ith glyph. */
25696 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25697 overlap_hl
, x
, last_x
);
25698 for (s
= h
; s
; s
= s
->next
)
25699 s
->background_filled_p
= true;
25700 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25701 append_glyph_string_lists (&head
, &tail
, h
, t
);
25703 if (clip_head
|| clip_tail
)
25704 for (s
= head
; s
; s
= s
->next
)
25706 s
->clip_head
= clip_head
;
25707 s
->clip_tail
= clip_tail
;
25711 /* Draw all strings. */
25712 for (s
= head
; s
; s
= s
->next
)
25713 FRAME_RIF (f
)->draw_glyph_string (s
);
25716 /* When focus a sole frame and move horizontally, this clears on_p
25717 causing a failure to erase prev cursor position. */
25718 if (area
== TEXT_AREA
25719 && !row
->full_width_p
25720 /* When drawing overlapping rows, only the glyph strings'
25721 foreground is drawn, which doesn't erase a cursor
25725 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
25726 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
25727 : (tail
? tail
->x
+ tail
->background_width
: x
));
25731 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
25732 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
25736 /* Value is the x-position up to which drawn, relative to AREA of W.
25737 This doesn't include parts drawn because of overhangs. */
25738 if (row
->full_width_p
)
25739 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
25741 x_reached
-= area_left
;
25743 RELEASE_HDC (hdc
, f
);
25749 /* Expand row matrix if too narrow. Don't expand if area
25752 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
25754 if (!it->f->fonts_changed \
25755 && (it->glyph_row->glyphs[area] \
25756 < it->glyph_row->glyphs[area + 1])) \
25758 it->w->ncols_scale_factor++; \
25759 it->f->fonts_changed = true; \
25763 /* Store one glyph for IT->char_to_display in IT->glyph_row.
25764 Called from x_produce_glyphs when IT->glyph_row is non-null. */
25767 append_glyph (struct it
*it
)
25769 struct glyph
*glyph
;
25770 enum glyph_row_area area
= it
->area
;
25772 eassert (it
->glyph_row
);
25773 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
25775 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25776 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25778 /* If the glyph row is reversed, we need to prepend the glyph
25779 rather than append it. */
25780 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25784 /* Make room for the additional glyph. */
25785 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25787 glyph
= it
->glyph_row
->glyphs
[area
];
25789 glyph
->charpos
= CHARPOS (it
->position
);
25790 glyph
->object
= it
->object
;
25791 if (it
->pixel_width
> 0)
25793 glyph
->pixel_width
= it
->pixel_width
;
25794 glyph
->padding_p
= false;
25798 /* Assure at least 1-pixel width. Otherwise, cursor can't
25799 be displayed correctly. */
25800 glyph
->pixel_width
= 1;
25801 glyph
->padding_p
= true;
25803 glyph
->ascent
= it
->ascent
;
25804 glyph
->descent
= it
->descent
;
25805 glyph
->voffset
= it
->voffset
;
25806 glyph
->type
= CHAR_GLYPH
;
25807 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25808 glyph
->multibyte_p
= it
->multibyte_p
;
25809 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25811 /* In R2L rows, the left and the right box edges need to be
25812 drawn in reverse direction. */
25813 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25814 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25818 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25819 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25821 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25822 || it
->phys_descent
> it
->descent
);
25823 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
25824 glyph
->face_id
= it
->face_id
;
25825 glyph
->u
.ch
= it
->char_to_display
;
25826 glyph
->slice
.img
= null_glyph_slice
;
25827 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25830 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25831 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25832 glyph
->bidi_type
= it
->bidi_it
.type
;
25836 glyph
->resolved_level
= 0;
25837 glyph
->bidi_type
= UNKNOWN_BT
;
25839 ++it
->glyph_row
->used
[area
];
25842 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25845 /* Store one glyph for the composition IT->cmp_it.id in
25846 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
25850 append_composite_glyph (struct it
*it
)
25852 struct glyph
*glyph
;
25853 enum glyph_row_area area
= it
->area
;
25855 eassert (it
->glyph_row
);
25857 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25858 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25860 /* If the glyph row is reversed, we need to prepend the glyph
25861 rather than append it. */
25862 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
25866 /* Make room for the new glyph. */
25867 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
25869 glyph
= it
->glyph_row
->glyphs
[it
->area
];
25871 glyph
->charpos
= it
->cmp_it
.charpos
;
25872 glyph
->object
= it
->object
;
25873 glyph
->pixel_width
= it
->pixel_width
;
25874 glyph
->ascent
= it
->ascent
;
25875 glyph
->descent
= it
->descent
;
25876 glyph
->voffset
= it
->voffset
;
25877 glyph
->type
= COMPOSITE_GLYPH
;
25878 if (it
->cmp_it
.ch
< 0)
25880 glyph
->u
.cmp
.automatic
= false;
25881 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25882 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
25886 glyph
->u
.cmp
.automatic
= true;
25887 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25888 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
25889 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
25891 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25892 glyph
->multibyte_p
= it
->multibyte_p
;
25893 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25895 /* In R2L rows, the left and the right box edges need to be
25896 drawn in reverse direction. */
25897 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25898 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25902 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25903 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25905 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25906 || it
->phys_descent
> it
->descent
);
25907 glyph
->padding_p
= false;
25908 glyph
->glyph_not_available_p
= false;
25909 glyph
->face_id
= it
->face_id
;
25910 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25913 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25914 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25915 glyph
->bidi_type
= it
->bidi_it
.type
;
25917 ++it
->glyph_row
->used
[area
];
25920 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25924 /* Change IT->ascent and IT->height according to the setting of
25928 take_vertical_position_into_account (struct it
*it
)
25932 if (it
->voffset
< 0)
25933 /* Increase the ascent so that we can display the text higher
25935 it
->ascent
-= it
->voffset
;
25937 /* Increase the descent so that we can display the text lower
25939 it
->descent
+= it
->voffset
;
25944 /* Produce glyphs/get display metrics for the image IT is loaded with.
25945 See the description of struct display_iterator in dispextern.h for
25946 an overview of struct display_iterator. */
25949 produce_image_glyph (struct it
*it
)
25953 int glyph_ascent
, crop
;
25954 struct glyph_slice slice
;
25956 eassert (it
->what
== IT_IMAGE
);
25958 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25960 /* Make sure X resources of the face is loaded. */
25961 prepare_face_for_display (it
->f
, face
);
25963 if (it
->image_id
< 0)
25965 /* Fringe bitmap. */
25966 it
->ascent
= it
->phys_ascent
= 0;
25967 it
->descent
= it
->phys_descent
= 0;
25968 it
->pixel_width
= 0;
25973 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
25975 /* Make sure X resources of the image is loaded. */
25976 prepare_image_for_display (it
->f
, img
);
25978 slice
.x
= slice
.y
= 0;
25979 slice
.width
= img
->width
;
25980 slice
.height
= img
->height
;
25982 if (INTEGERP (it
->slice
.x
))
25983 slice
.x
= XINT (it
->slice
.x
);
25984 else if (FLOATP (it
->slice
.x
))
25985 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
25987 if (INTEGERP (it
->slice
.y
))
25988 slice
.y
= XINT (it
->slice
.y
);
25989 else if (FLOATP (it
->slice
.y
))
25990 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
25992 if (INTEGERP (it
->slice
.width
))
25993 slice
.width
= XINT (it
->slice
.width
);
25994 else if (FLOATP (it
->slice
.width
))
25995 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
25997 if (INTEGERP (it
->slice
.height
))
25998 slice
.height
= XINT (it
->slice
.height
);
25999 else if (FLOATP (it
->slice
.height
))
26000 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
26002 if (slice
.x
>= img
->width
)
26003 slice
.x
= img
->width
;
26004 if (slice
.y
>= img
->height
)
26005 slice
.y
= img
->height
;
26006 if (slice
.x
+ slice
.width
>= img
->width
)
26007 slice
.width
= img
->width
- slice
.x
;
26008 if (slice
.y
+ slice
.height
> img
->height
)
26009 slice
.height
= img
->height
- slice
.y
;
26011 if (slice
.width
== 0 || slice
.height
== 0)
26014 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
26016 it
->descent
= slice
.height
- glyph_ascent
;
26018 it
->descent
+= img
->vmargin
;
26019 if (slice
.y
+ slice
.height
== img
->height
)
26020 it
->descent
+= img
->vmargin
;
26021 it
->phys_descent
= it
->descent
;
26023 it
->pixel_width
= slice
.width
;
26025 it
->pixel_width
+= img
->hmargin
;
26026 if (slice
.x
+ slice
.width
== img
->width
)
26027 it
->pixel_width
+= img
->hmargin
;
26029 /* It's quite possible for images to have an ascent greater than
26030 their height, so don't get confused in that case. */
26031 if (it
->descent
< 0)
26036 if (face
->box
!= FACE_NO_BOX
)
26038 if (face
->box_line_width
> 0)
26041 it
->ascent
+= face
->box_line_width
;
26042 if (slice
.y
+ slice
.height
== img
->height
)
26043 it
->descent
+= face
->box_line_width
;
26046 if (it
->start_of_box_run_p
&& slice
.x
== 0)
26047 it
->pixel_width
+= eabs (face
->box_line_width
);
26048 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
26049 it
->pixel_width
+= eabs (face
->box_line_width
);
26052 take_vertical_position_into_account (it
);
26054 /* Automatically crop wide image glyphs at right edge so we can
26055 draw the cursor on same display row. */
26056 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
26057 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
26059 it
->pixel_width
-= crop
;
26060 slice
.width
-= crop
;
26065 struct glyph
*glyph
;
26066 enum glyph_row_area area
= it
->area
;
26068 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26069 if (it
->glyph_row
->reversed_p
)
26073 /* Make room for the new glyph. */
26074 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
26076 glyph
= it
->glyph_row
->glyphs
[it
->area
];
26078 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26080 glyph
->charpos
= CHARPOS (it
->position
);
26081 glyph
->object
= it
->object
;
26082 glyph
->pixel_width
= it
->pixel_width
;
26083 glyph
->ascent
= glyph_ascent
;
26084 glyph
->descent
= it
->descent
;
26085 glyph
->voffset
= it
->voffset
;
26086 glyph
->type
= IMAGE_GLYPH
;
26087 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26088 glyph
->multibyte_p
= it
->multibyte_p
;
26089 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26091 /* In R2L rows, the left and the right box edges need to be
26092 drawn in reverse direction. */
26093 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26094 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26098 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26099 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26101 glyph
->overlaps_vertically_p
= false;
26102 glyph
->padding_p
= false;
26103 glyph
->glyph_not_available_p
= false;
26104 glyph
->face_id
= it
->face_id
;
26105 glyph
->u
.img_id
= img
->id
;
26106 glyph
->slice
.img
= slice
;
26107 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26110 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26111 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26112 glyph
->bidi_type
= it
->bidi_it
.type
;
26114 ++it
->glyph_row
->used
[area
];
26117 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26121 #ifdef HAVE_XWIDGETS
26123 produce_xwidget_glyph (struct it
*it
)
26125 struct xwidget
*xw
;
26126 int glyph_ascent
, crop
;
26127 eassert (it
->what
== IT_XWIDGET
);
26129 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26131 /* Make sure X resources of the face is loaded. */
26132 prepare_face_for_display (it
->f
, face
);
26135 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
26136 it
->descent
= xw
->height
/2;
26137 it
->phys_descent
= it
->descent
;
26138 it
->pixel_width
= xw
->width
;
26139 /* It's quite possible for images to have an ascent greater than
26140 their height, so don't get confused in that case. */
26141 if (it
->descent
< 0)
26146 if (face
->box
!= FACE_NO_BOX
)
26148 if (face
->box_line_width
> 0)
26150 it
->ascent
+= face
->box_line_width
;
26151 it
->descent
+= face
->box_line_width
;
26154 if (it
->start_of_box_run_p
)
26155 it
->pixel_width
+= eabs (face
->box_line_width
);
26156 it
->pixel_width
+= eabs (face
->box_line_width
);
26159 take_vertical_position_into_account (it
);
26161 /* Automatically crop wide image glyphs at right edge so we can
26162 draw the cursor on same display row. */
26163 crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
);
26164 if (crop
> 0 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
26165 it
->pixel_width
-= crop
;
26169 enum glyph_row_area area
= it
->area
;
26170 struct glyph
*glyph
26171 = it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26173 if (it
->glyph_row
->reversed_p
)
26177 /* Make room for the new glyph. */
26178 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
26180 glyph
= it
->glyph_row
->glyphs
[it
->area
];
26182 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26184 glyph
->charpos
= CHARPOS (it
->position
);
26185 glyph
->object
= it
->object
;
26186 glyph
->pixel_width
= it
->pixel_width
;
26187 glyph
->ascent
= glyph_ascent
;
26188 glyph
->descent
= it
->descent
;
26189 glyph
->voffset
= it
->voffset
;
26190 glyph
->type
= XWIDGET_GLYPH
;
26191 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26192 glyph
->multibyte_p
= it
->multibyte_p
;
26193 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26195 /* In R2L rows, the left and the right box edges need to be
26196 drawn in reverse direction. */
26197 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26198 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26202 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26203 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26205 glyph
->overlaps_vertically_p
= 0;
26206 glyph
->padding_p
= 0;
26207 glyph
->glyph_not_available_p
= 0;
26208 glyph
->face_id
= it
->face_id
;
26209 glyph
->u
.xwidget
= it
->xwidget
;
26210 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26213 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26214 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26215 glyph
->bidi_type
= it
->bidi_it
.type
;
26217 ++it
->glyph_row
->used
[area
];
26220 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26225 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
26226 of the glyph, WIDTH and HEIGHT are the width and height of the
26227 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
26230 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
26231 int width
, int height
, int ascent
)
26233 struct glyph
*glyph
;
26234 enum glyph_row_area area
= it
->area
;
26236 eassert (ascent
>= 0 && ascent
<= height
);
26238 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26239 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26241 /* If the glyph row is reversed, we need to prepend the glyph
26242 rather than append it. */
26243 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26247 /* Make room for the additional glyph. */
26248 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26250 glyph
= it
->glyph_row
->glyphs
[area
];
26252 /* Decrease the width of the first glyph of the row that
26253 begins before first_visible_x (e.g., due to hscroll).
26254 This is so the overall width of the row becomes smaller
26255 by the scroll amount, and the stretch glyph appended by
26256 extend_face_to_end_of_line will be wider, to shift the
26257 row glyphs to the right. (In L2R rows, the corresponding
26258 left-shift effect is accomplished by setting row->x to a
26259 negative value, which won't work with R2L rows.)
26261 This must leave us with a positive value of WIDTH, since
26262 otherwise the call to move_it_in_display_line_to at the
26263 beginning of display_line would have got past the entire
26264 first glyph, and then it->current_x would have been
26265 greater or equal to it->first_visible_x. */
26266 if (it
->current_x
< it
->first_visible_x
)
26267 width
-= it
->first_visible_x
- it
->current_x
;
26268 eassert (width
> 0);
26270 glyph
->charpos
= CHARPOS (it
->position
);
26271 glyph
->object
= object
;
26272 glyph
->pixel_width
= width
;
26273 glyph
->ascent
= ascent
;
26274 glyph
->descent
= height
- ascent
;
26275 glyph
->voffset
= it
->voffset
;
26276 glyph
->type
= STRETCH_GLYPH
;
26277 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26278 glyph
->multibyte_p
= it
->multibyte_p
;
26279 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26281 /* In R2L rows, the left and the right box edges need to be
26282 drawn in reverse direction. */
26283 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26284 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26288 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26289 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26291 glyph
->overlaps_vertically_p
= false;
26292 glyph
->padding_p
= false;
26293 glyph
->glyph_not_available_p
= false;
26294 glyph
->face_id
= it
->face_id
;
26295 glyph
->u
.stretch
.ascent
= ascent
;
26296 glyph
->u
.stretch
.height
= height
;
26297 glyph
->slice
.img
= null_glyph_slice
;
26298 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26301 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26302 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26303 glyph
->bidi_type
= it
->bidi_it
.type
;
26307 glyph
->resolved_level
= 0;
26308 glyph
->bidi_type
= UNKNOWN_BT
;
26310 ++it
->glyph_row
->used
[area
];
26313 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26316 #endif /* HAVE_WINDOW_SYSTEM */
26318 /* Produce a stretch glyph for iterator IT. IT->object is the value
26319 of the glyph property displayed. The value must be a list
26320 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
26323 1. `:width WIDTH' specifies that the space should be WIDTH *
26324 canonical char width wide. WIDTH may be an integer or floating
26327 2. `:relative-width FACTOR' specifies that the width of the stretch
26328 should be computed from the width of the first character having the
26329 `glyph' property, and should be FACTOR times that width.
26331 3. `:align-to HPOS' specifies that the space should be wide enough
26332 to reach HPOS, a value in canonical character units.
26334 Exactly one of the above pairs must be present.
26336 4. `:height HEIGHT' specifies that the height of the stretch produced
26337 should be HEIGHT, measured in canonical character units.
26339 5. `:relative-height FACTOR' specifies that the height of the
26340 stretch should be FACTOR times the height of the characters having
26341 the glyph property.
26343 Either none or exactly one of 4 or 5 must be present.
26345 6. `:ascent ASCENT' specifies that ASCENT percent of the height
26346 of the stretch should be used for the ascent of the stretch.
26347 ASCENT must be in the range 0 <= ASCENT <= 100. */
26350 produce_stretch_glyph (struct it
*it
)
26352 /* (space :width WIDTH :height HEIGHT ...) */
26353 Lisp_Object prop
, plist
;
26354 int width
= 0, height
= 0, align_to
= -1;
26355 bool zero_width_ok_p
= false;
26357 struct font
*font
= NULL
;
26359 #ifdef HAVE_WINDOW_SYSTEM
26361 bool zero_height_ok_p
= false;
26363 if (FRAME_WINDOW_P (it
->f
))
26365 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26366 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26367 prepare_face_for_display (it
->f
, face
);
26371 /* List should start with `space'. */
26372 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
26373 plist
= XCDR (it
->object
);
26375 /* Compute the width of the stretch. */
26376 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
26377 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true, 0))
26379 /* Absolute width `:width WIDTH' specified and valid. */
26380 zero_width_ok_p
= true;
26383 else if (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0)
26385 /* Relative width `:relative-width FACTOR' specified and valid.
26386 Compute the width of the characters having the `glyph'
26389 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
26392 if (it
->multibyte_p
)
26393 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
26396 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
26397 if (! ASCII_CHAR_P (it2
.c
))
26398 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
26401 it2
.glyph_row
= NULL
;
26402 it2
.what
= IT_CHARACTER
;
26403 PRODUCE_GLYPHS (&it2
);
26404 width
= NUMVAL (prop
) * it2
.pixel_width
;
26406 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
26407 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true,
26410 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
26411 align_to
= (align_to
< 0
26413 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
26414 else if (align_to
< 0)
26415 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
26416 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
26417 zero_width_ok_p
= true;
26420 /* Nothing specified -> width defaults to canonical char width. */
26421 width
= FRAME_COLUMN_WIDTH (it
->f
);
26423 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
26426 #ifdef HAVE_WINDOW_SYSTEM
26427 /* Compute height. */
26428 if (FRAME_WINDOW_P (it
->f
))
26430 int default_height
= normal_char_height (font
, ' ');
26432 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
26433 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
26436 zero_height_ok_p
= true;
26438 else if (prop
= Fplist_get (plist
, QCrelative_height
),
26440 height
= default_height
* NUMVAL (prop
);
26442 height
= default_height
;
26444 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
26447 /* Compute percentage of height used for ascent. If
26448 `:ascent ASCENT' is present and valid, use that. Otherwise,
26449 derive the ascent from the font in use. */
26450 if (prop
= Fplist_get (plist
, QCascent
),
26451 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
26452 ascent
= height
* NUMVAL (prop
) / 100.0;
26453 else if (!NILP (prop
)
26454 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
26455 ascent
= min (max (0, (int)tem
), height
);
26457 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
26460 #endif /* HAVE_WINDOW_SYSTEM */
26463 if (width
> 0 && it
->line_wrap
!= TRUNCATE
26464 && it
->current_x
+ width
> it
->last_visible_x
)
26466 width
= it
->last_visible_x
- it
->current_x
;
26467 #ifdef HAVE_WINDOW_SYSTEM
26468 /* Subtract one more pixel from the stretch width, but only on
26469 GUI frames, since on a TTY each glyph is one "pixel" wide. */
26470 width
-= FRAME_WINDOW_P (it
->f
);
26474 if (width
> 0 && height
> 0 && it
->glyph_row
)
26476 Lisp_Object o_object
= it
->object
;
26477 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
26480 if (!STRINGP (object
))
26481 object
= it
->w
->contents
;
26482 #ifdef HAVE_WINDOW_SYSTEM
26483 if (FRAME_WINDOW_P (it
->f
))
26484 append_stretch_glyph (it
, object
, width
, height
, ascent
);
26488 it
->object
= object
;
26489 it
->char_to_display
= ' ';
26490 it
->pixel_width
= it
->len
= 1;
26492 tty_append_glyph (it
);
26493 it
->object
= o_object
;
26497 it
->pixel_width
= width
;
26498 #ifdef HAVE_WINDOW_SYSTEM
26499 if (FRAME_WINDOW_P (it
->f
))
26501 it
->ascent
= it
->phys_ascent
= ascent
;
26502 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
26503 it
->nglyphs
= width
> 0 && height
> 0;
26504 take_vertical_position_into_account (it
);
26508 it
->nglyphs
= width
;
26511 /* Get information about special display element WHAT in an
26512 environment described by IT. WHAT is one of IT_TRUNCATION or
26513 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
26514 non-null glyph_row member. This function ensures that fields like
26515 face_id, c, len of IT are left untouched. */
26518 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
26525 temp_it
.object
= Qnil
;
26526 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
26528 if (what
== IT_CONTINUATION
)
26530 /* Continuation glyph. For R2L lines, we mirror it by hand. */
26531 if (it
->bidi_it
.paragraph_dir
== R2L
)
26532 SET_GLYPH_FROM_CHAR (glyph
, '/');
26534 SET_GLYPH_FROM_CHAR (glyph
, '\\');
26536 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
26538 /* FIXME: Should we mirror GC for R2L lines? */
26539 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
26540 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
26543 else if (what
== IT_TRUNCATION
)
26545 /* Truncation glyph. */
26546 SET_GLYPH_FROM_CHAR (glyph
, '$');
26548 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
26550 /* FIXME: Should we mirror GC for R2L lines? */
26551 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
26552 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
26558 #ifdef HAVE_WINDOW_SYSTEM
26559 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
26560 is turned off, we precede the truncation/continuation glyphs by a
26561 stretch glyph whose width is computed such that these special
26562 glyphs are aligned at the window margin, even when very different
26563 fonts are used in different glyph rows. */
26564 if (FRAME_WINDOW_P (temp_it
.f
)
26565 /* init_iterator calls this with it->glyph_row == NULL, and it
26566 wants only the pixel width of the truncation/continuation
26568 && temp_it
.glyph_row
26569 /* insert_left_trunc_glyphs calls us at the beginning of the
26570 row, and it has its own calculation of the stretch glyph
26572 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
26573 && (temp_it
.glyph_row
->reversed_p
26574 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
26575 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
26577 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
26579 if (stretch_width
> 0)
26581 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
26582 struct font
*font
=
26583 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
26584 int stretch_ascent
=
26585 (((temp_it
.ascent
+ temp_it
.descent
)
26586 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
26588 append_stretch_glyph (&temp_it
, Qnil
, stretch_width
,
26589 temp_it
.ascent
+ temp_it
.descent
,
26596 temp_it
.what
= IT_CHARACTER
;
26597 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
26598 temp_it
.face_id
= GLYPH_FACE (glyph
);
26599 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
26601 PRODUCE_GLYPHS (&temp_it
);
26602 it
->pixel_width
= temp_it
.pixel_width
;
26603 it
->nglyphs
= temp_it
.nglyphs
;
26606 #ifdef HAVE_WINDOW_SYSTEM
26608 /* Calculate line-height and line-spacing properties.
26609 An integer value specifies explicit pixel value.
26610 A float value specifies relative value to current face height.
26611 A cons (float . face-name) specifies relative value to
26612 height of specified face font.
26614 Returns height in pixels, or nil. */
26617 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
26618 int boff
, bool override
)
26620 Lisp_Object face_name
= Qnil
;
26621 int ascent
, descent
, height
;
26623 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
26628 face_name
= XCAR (val
);
26630 if (!NUMBERP (val
))
26631 val
= make_number (1);
26632 if (NILP (face_name
))
26634 height
= it
->ascent
+ it
->descent
;
26639 if (NILP (face_name
))
26641 font
= FRAME_FONT (it
->f
);
26642 boff
= FRAME_BASELINE_OFFSET (it
->f
);
26644 else if (EQ (face_name
, Qt
))
26653 face_id
= lookup_named_face (it
->f
, face_name
, false);
26655 return make_number (-1);
26657 face
= FACE_FROM_ID (it
->f
, face_id
);
26660 return make_number (-1);
26661 boff
= font
->baseline_offset
;
26662 if (font
->vertical_centering
)
26663 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26666 normal_char_ascent_descent (font
, -1, &ascent
, &descent
);
26670 it
->override_ascent
= ascent
;
26671 it
->override_descent
= descent
;
26672 it
->override_boff
= boff
;
26675 height
= ascent
+ descent
;
26679 height
= (int)(XFLOAT_DATA (val
) * height
);
26680 else if (INTEGERP (val
))
26681 height
*= XINT (val
);
26683 return make_number (height
);
26687 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
26688 is a face ID to be used for the glyph. FOR_NO_FONT is true if
26689 and only if this is for a character for which no font was found.
26691 If the display method (it->glyphless_method) is
26692 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
26693 length of the acronym or the hexadecimal string, UPPER_XOFF and
26694 UPPER_YOFF are pixel offsets for the upper part of the string,
26695 LOWER_XOFF and LOWER_YOFF are for the lower part.
26697 For the other display methods, LEN through LOWER_YOFF are zero. */
26700 append_glyphless_glyph (struct it
*it
, int face_id
, bool for_no_font
, int len
,
26701 short upper_xoff
, short upper_yoff
,
26702 short lower_xoff
, short lower_yoff
)
26704 struct glyph
*glyph
;
26705 enum glyph_row_area area
= it
->area
;
26707 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26708 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26710 /* If the glyph row is reversed, we need to prepend the glyph
26711 rather than append it. */
26712 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26716 /* Make room for the additional glyph. */
26717 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26719 glyph
= it
->glyph_row
->glyphs
[area
];
26721 glyph
->charpos
= CHARPOS (it
->position
);
26722 glyph
->object
= it
->object
;
26723 glyph
->pixel_width
= it
->pixel_width
;
26724 glyph
->ascent
= it
->ascent
;
26725 glyph
->descent
= it
->descent
;
26726 glyph
->voffset
= it
->voffset
;
26727 glyph
->type
= GLYPHLESS_GLYPH
;
26728 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
26729 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
26730 glyph
->u
.glyphless
.len
= len
;
26731 glyph
->u
.glyphless
.ch
= it
->c
;
26732 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
26733 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
26734 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
26735 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
26736 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26737 glyph
->multibyte_p
= it
->multibyte_p
;
26738 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26740 /* In R2L rows, the left and the right box edges need to be
26741 drawn in reverse direction. */
26742 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26743 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26747 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26748 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26750 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
26751 || it
->phys_descent
> it
->descent
);
26752 glyph
->padding_p
= false;
26753 glyph
->glyph_not_available_p
= false;
26754 glyph
->face_id
= face_id
;
26755 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26758 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26759 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26760 glyph
->bidi_type
= it
->bidi_it
.type
;
26762 ++it
->glyph_row
->used
[area
];
26765 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26769 /* Produce a glyph for a glyphless character for iterator IT.
26770 IT->glyphless_method specifies which method to use for displaying
26771 the character. See the description of enum
26772 glyphless_display_method in dispextern.h for the detail.
26774 FOR_NO_FONT is true if and only if this is for a character for
26775 which no font was found. ACRONYM, if non-nil, is an acronym string
26776 for the character. */
26779 produce_glyphless_glyph (struct it
*it
, bool for_no_font
, Lisp_Object acronym
)
26784 int base_width
, base_height
, width
, height
;
26785 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
26788 /* Get the metrics of the base font. We always refer to the current
26790 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
26791 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26792 normal_char_ascent_descent (font
, -1, &it
->ascent
, &it
->descent
);
26793 it
->ascent
+= font
->baseline_offset
;
26794 it
->descent
-= font
->baseline_offset
;
26795 base_height
= it
->ascent
+ it
->descent
;
26796 base_width
= font
->average_width
;
26798 face_id
= merge_glyphless_glyph_face (it
);
26800 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
26802 it
->pixel_width
= THIN_SPACE_WIDTH
;
26804 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26806 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
26808 width
= CHAR_WIDTH (it
->c
);
26811 else if (width
> 4)
26813 it
->pixel_width
= base_width
* width
;
26815 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26821 unsigned int code
[6];
26823 int ascent
, descent
;
26824 struct font_metrics metrics_upper
, metrics_lower
;
26826 face
= FACE_FROM_ID (it
->f
, face_id
);
26827 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26828 prepare_face_for_display (it
->f
, face
);
26830 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
26832 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
26833 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
26834 if (CONSP (acronym
))
26835 acronym
= XCAR (acronym
);
26836 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
26840 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
26841 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
+ 0u);
26844 for (len
= 0; str
[len
] && ASCII_CHAR_P (str
[len
]) && len
< 6; len
++)
26845 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
26846 upper_len
= (len
+ 1) / 2;
26847 font
->driver
->text_extents (font
, code
, upper_len
,
26849 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
26854 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
26855 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
26856 upper_xoff
= upper_yoff
= 2; /* the typical case */
26857 if (base_width
>= width
)
26859 /* Align the upper to the left, the lower to the right. */
26860 it
->pixel_width
= base_width
;
26861 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
26865 /* Center the shorter one. */
26866 it
->pixel_width
= width
;
26867 if (metrics_upper
.width
>= metrics_lower
.width
)
26868 lower_xoff
= (width
- metrics_lower
.width
) / 2;
26871 /* FIXME: This code doesn't look right. It formerly was
26872 missing the "lower_xoff = 0;", which couldn't have
26873 been right since it left lower_xoff uninitialized. */
26875 upper_xoff
= (width
- metrics_upper
.width
) / 2;
26879 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
26880 top, bottom, and between upper and lower strings. */
26881 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
26882 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
26883 /* Center vertically.
26884 H:base_height, D:base_descent
26885 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
26887 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
26888 descent = D - H/2 + h/2;
26889 lower_yoff = descent - 2 - ld;
26890 upper_yoff = lower_yoff - la - 1 - ud; */
26891 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
26892 descent
= it
->descent
- (base_height
- height
) / 2;
26893 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
26894 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
26895 - metrics_upper
.descent
);
26896 /* Don't make the height shorter than the base height. */
26897 if (height
> base_height
)
26899 it
->ascent
= ascent
;
26900 it
->descent
= descent
;
26904 it
->phys_ascent
= it
->ascent
;
26905 it
->phys_descent
= it
->descent
;
26907 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
26908 upper_xoff
, upper_yoff
,
26909 lower_xoff
, lower_yoff
);
26911 take_vertical_position_into_account (it
);
26916 Produce glyphs/get display metrics for the display element IT is
26917 loaded with. See the description of struct it in dispextern.h
26918 for an overview of struct it. */
26921 x_produce_glyphs (struct it
*it
)
26923 int extra_line_spacing
= it
->extra_line_spacing
;
26925 it
->glyph_not_available_p
= false;
26927 if (it
->what
== IT_CHARACTER
)
26930 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26931 struct font
*font
= face
->font
;
26932 struct font_metrics
*pcm
= NULL
;
26933 int boff
; /* Baseline offset. */
26937 /* When no suitable font is found, display this character by
26938 the method specified in the first extra slot of
26939 Vglyphless_char_display. */
26940 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
26942 eassert (it
->what
== IT_GLYPHLESS
);
26943 produce_glyphless_glyph (it
, true,
26944 STRINGP (acronym
) ? acronym
: Qnil
);
26948 boff
= font
->baseline_offset
;
26949 if (font
->vertical_centering
)
26950 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26952 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
26956 if (it
->override_ascent
>= 0)
26958 it
->ascent
= it
->override_ascent
;
26959 it
->descent
= it
->override_descent
;
26960 boff
= it
->override_boff
;
26964 it
->ascent
= FONT_BASE (font
) + boff
;
26965 it
->descent
= FONT_DESCENT (font
) - boff
;
26968 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
26970 pcm
= get_per_char_metric (font
, &char2b
);
26971 if (pcm
->width
== 0
26972 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
26978 it
->phys_ascent
= pcm
->ascent
+ boff
;
26979 it
->phys_descent
= pcm
->descent
- boff
;
26980 it
->pixel_width
= pcm
->width
;
26981 /* Don't use font-global values for ascent and descent
26982 if they result in an exceedingly large line height. */
26983 if (it
->override_ascent
< 0)
26985 if (FONT_TOO_HIGH (font
))
26987 it
->ascent
= it
->phys_ascent
;
26988 it
->descent
= it
->phys_descent
;
26989 /* These limitations are enforced by an
26990 assertion near the end of this function. */
26991 if (it
->ascent
< 0)
26993 if (it
->descent
< 0)
27000 it
->glyph_not_available_p
= true;
27001 it
->phys_ascent
= it
->ascent
;
27002 it
->phys_descent
= it
->descent
;
27003 it
->pixel_width
= font
->space_width
;
27006 if (it
->constrain_row_ascent_descent_p
)
27008 if (it
->descent
> it
->max_descent
)
27010 it
->ascent
+= it
->descent
- it
->max_descent
;
27011 it
->descent
= it
->max_descent
;
27013 if (it
->ascent
> it
->max_ascent
)
27015 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
27016 it
->ascent
= it
->max_ascent
;
27018 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
27019 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
27020 extra_line_spacing
= 0;
27023 /* If this is a space inside a region of text with
27024 `space-width' property, change its width. */
27026 = it
->char_to_display
== ' ' && !NILP (it
->space_width
);
27028 it
->pixel_width
*= XFLOATINT (it
->space_width
);
27030 /* If face has a box, add the box thickness to the character
27031 height. If character has a box line to the left and/or
27032 right, add the box line width to the character's width. */
27033 if (face
->box
!= FACE_NO_BOX
)
27035 int thick
= face
->box_line_width
;
27039 it
->ascent
+= thick
;
27040 it
->descent
+= thick
;
27045 if (it
->start_of_box_run_p
)
27046 it
->pixel_width
+= thick
;
27047 if (it
->end_of_box_run_p
)
27048 it
->pixel_width
+= thick
;
27051 /* If face has an overline, add the height of the overline
27052 (1 pixel) and a 1 pixel margin to the character height. */
27053 if (face
->overline_p
)
27054 it
->ascent
+= overline_margin
;
27056 if (it
->constrain_row_ascent_descent_p
)
27058 if (it
->ascent
> it
->max_ascent
)
27059 it
->ascent
= it
->max_ascent
;
27060 if (it
->descent
> it
->max_descent
)
27061 it
->descent
= it
->max_descent
;
27064 take_vertical_position_into_account (it
);
27066 /* If we have to actually produce glyphs, do it. */
27071 /* Translate a space with a `space-width' property
27072 into a stretch glyph. */
27073 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
27074 / FONT_HEIGHT (font
));
27075 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
27076 it
->ascent
+ it
->descent
, ascent
);
27081 /* If characters with lbearing or rbearing are displayed
27082 in this line, record that fact in a flag of the
27083 glyph row. This is used to optimize X output code. */
27084 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
27085 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27087 if (! stretched_p
&& it
->pixel_width
== 0)
27088 /* We assure that all visible glyphs have at least 1-pixel
27090 it
->pixel_width
= 1;
27092 else if (it
->char_to_display
== '\n')
27094 /* A newline has no width, but we need the height of the
27095 line. But if previous part of the line sets a height,
27096 don't increase that height. */
27098 Lisp_Object height
;
27099 Lisp_Object total_height
= Qnil
;
27101 it
->override_ascent
= -1;
27102 it
->pixel_width
= 0;
27105 height
= get_it_property (it
, Qline_height
);
27106 /* Split (line-height total-height) list. */
27108 && CONSP (XCDR (height
))
27109 && NILP (XCDR (XCDR (height
))))
27111 total_height
= XCAR (XCDR (height
));
27112 height
= XCAR (height
);
27114 height
= calc_line_height_property (it
, height
, font
, boff
, true);
27116 if (it
->override_ascent
>= 0)
27118 it
->ascent
= it
->override_ascent
;
27119 it
->descent
= it
->override_descent
;
27120 boff
= it
->override_boff
;
27124 if (FONT_TOO_HIGH (font
))
27126 it
->ascent
= font
->pixel_size
+ boff
- 1;
27127 it
->descent
= -boff
+ 1;
27128 if (it
->descent
< 0)
27133 it
->ascent
= FONT_BASE (font
) + boff
;
27134 it
->descent
= FONT_DESCENT (font
) - boff
;
27138 if (EQ (height
, Qt
))
27140 if (it
->descent
> it
->max_descent
)
27142 it
->ascent
+= it
->descent
- it
->max_descent
;
27143 it
->descent
= it
->max_descent
;
27145 if (it
->ascent
> it
->max_ascent
)
27147 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
27148 it
->ascent
= it
->max_ascent
;
27150 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
27151 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
27152 it
->constrain_row_ascent_descent_p
= true;
27153 extra_line_spacing
= 0;
27157 Lisp_Object spacing
;
27159 it
->phys_ascent
= it
->ascent
;
27160 it
->phys_descent
= it
->descent
;
27162 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
27163 && face
->box
!= FACE_NO_BOX
27164 && face
->box_line_width
> 0)
27166 it
->ascent
+= face
->box_line_width
;
27167 it
->descent
+= face
->box_line_width
;
27170 && XINT (height
) > it
->ascent
+ it
->descent
)
27171 it
->ascent
= XINT (height
) - it
->descent
;
27173 if (!NILP (total_height
))
27174 spacing
= calc_line_height_property (it
, total_height
, font
,
27178 spacing
= get_it_property (it
, Qline_spacing
);
27179 spacing
= calc_line_height_property (it
, spacing
, font
,
27182 if (INTEGERP (spacing
))
27184 extra_line_spacing
= XINT (spacing
);
27185 if (!NILP (total_height
))
27186 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
27190 else /* i.e. (it->char_to_display == '\t') */
27192 if (font
->space_width
> 0)
27194 int tab_width
= it
->tab_width
* font
->space_width
;
27195 int x
= it
->current_x
+ it
->continuation_lines_width
;
27196 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
27198 /* If the distance from the current position to the next tab
27199 stop is less than a space character width, use the
27200 tab stop after that. */
27201 if (next_tab_x
- x
< font
->space_width
)
27202 next_tab_x
+= tab_width
;
27204 it
->pixel_width
= next_tab_x
- x
;
27206 if (FONT_TOO_HIGH (font
))
27208 if (get_char_glyph_code (' ', font
, &char2b
))
27210 pcm
= get_per_char_metric (font
, &char2b
);
27211 if (pcm
->width
== 0
27212 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
27218 it
->ascent
= pcm
->ascent
+ boff
;
27219 it
->descent
= pcm
->descent
- boff
;
27223 it
->ascent
= font
->pixel_size
+ boff
- 1;
27224 it
->descent
= -boff
+ 1;
27226 if (it
->ascent
< 0)
27228 if (it
->descent
< 0)
27233 it
->ascent
= FONT_BASE (font
) + boff
;
27234 it
->descent
= FONT_DESCENT (font
) - boff
;
27236 it
->phys_ascent
= it
->ascent
;
27237 it
->phys_descent
= it
->descent
;
27241 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
27242 it
->ascent
+ it
->descent
, it
->ascent
);
27247 it
->pixel_width
= 0;
27252 if (FONT_TOO_HIGH (font
))
27254 int font_ascent
, font_descent
;
27256 /* For very large fonts, where we ignore the declared font
27257 dimensions, and go by per-character metrics instead,
27258 don't let the row ascent and descent values (and the row
27259 height computed from them) be smaller than the "normal"
27260 character metrics. This avoids unpleasant effects
27261 whereby lines on display would change their height
27262 depending on which characters are shown. */
27263 normal_char_ascent_descent (font
, -1, &font_ascent
, &font_descent
);
27264 it
->max_ascent
= max (it
->max_ascent
, font_ascent
);
27265 it
->max_descent
= max (it
->max_descent
, font_descent
);
27268 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
27270 /* A static composition.
27272 Note: A composition is represented as one glyph in the
27273 glyph matrix. There are no padding glyphs.
27275 Important note: pixel_width, ascent, and descent are the
27276 values of what is drawn by draw_glyphs (i.e. the values of
27277 the overall glyphs composed). */
27278 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27279 int boff
; /* baseline offset */
27280 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
27281 int glyph_len
= cmp
->glyph_len
;
27282 struct font
*font
= face
->font
;
27286 /* If we have not yet calculated pixel size data of glyphs of
27287 the composition for the current face font, calculate them
27288 now. Theoretically, we have to check all fonts for the
27289 glyphs, but that requires much time and memory space. So,
27290 here we check only the font of the first glyph. This may
27291 lead to incorrect display, but it's very rare, and C-l
27292 (recenter-top-bottom) can correct the display anyway. */
27293 if (! cmp
->font
|| cmp
->font
!= font
)
27295 /* Ascent and descent of the font of the first character
27296 of this composition (adjusted by baseline offset).
27297 Ascent and descent of overall glyphs should not be less
27298 than these, respectively. */
27299 int font_ascent
, font_descent
, font_height
;
27300 /* Bounding box of the overall glyphs. */
27301 int leftmost
, rightmost
, lowest
, highest
;
27302 int lbearing
, rbearing
;
27303 int i
, width
, ascent
, descent
;
27304 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
27306 struct font_metrics
*pcm
;
27309 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
27310 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
27312 bool right_padded
= glyph_len
< cmp
->glyph_len
;
27313 for (i
= 0; i
< glyph_len
; i
++)
27315 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
27317 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
27319 bool left_padded
= i
> 0;
27321 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
27322 : IT_CHARPOS (*it
));
27323 /* If no suitable font is found, use the default font. */
27324 bool font_not_found_p
= font
== NULL
;
27325 if (font_not_found_p
)
27327 face
= face
->ascii_face
;
27330 boff
= font
->baseline_offset
;
27331 if (font
->vertical_centering
)
27332 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
27333 normal_char_ascent_descent (font
, -1, &font_ascent
, &font_descent
);
27334 font_ascent
+= boff
;
27335 font_descent
-= boff
;
27336 font_height
= font_ascent
+ font_descent
;
27341 if (! font_not_found_p
)
27343 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
27345 pcm
= get_per_char_metric (font
, &char2b
);
27348 /* Initialize the bounding box. */
27351 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
27352 ascent
= pcm
->ascent
;
27353 descent
= pcm
->descent
;
27354 lbearing
= pcm
->lbearing
;
27355 rbearing
= pcm
->rbearing
;
27359 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
27360 ascent
= FONT_BASE (font
);
27361 descent
= FONT_DESCENT (font
);
27368 lowest
= - descent
+ boff
;
27369 highest
= ascent
+ boff
;
27371 if (! font_not_found_p
27372 && font
->default_ascent
27373 && CHAR_TABLE_P (Vuse_default_ascent
)
27374 && !NILP (Faref (Vuse_default_ascent
,
27375 make_number (it
->char_to_display
))))
27376 highest
= font
->default_ascent
+ boff
;
27378 /* Draw the first glyph at the normal position. It may be
27379 shifted to right later if some other glyphs are drawn
27381 cmp
->offsets
[i
* 2] = 0;
27382 cmp
->offsets
[i
* 2 + 1] = boff
;
27383 cmp
->lbearing
= lbearing
;
27384 cmp
->rbearing
= rbearing
;
27386 /* Set cmp->offsets for the remaining glyphs. */
27387 for (i
++; i
< glyph_len
; i
++)
27389 int left
, right
, btm
, top
;
27390 int ch
= COMPOSITION_GLYPH (cmp
, i
);
27392 struct face
*this_face
;
27396 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
27397 this_face
= FACE_FROM_ID (it
->f
, face_id
);
27398 font
= this_face
->font
;
27404 get_char_face_and_encoding (it
->f
, ch
, face_id
,
27406 pcm
= get_per_char_metric (font
, &char2b
);
27409 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
27412 width
= pcm
->width
;
27413 ascent
= pcm
->ascent
;
27414 descent
= pcm
->descent
;
27415 lbearing
= pcm
->lbearing
;
27416 rbearing
= pcm
->rbearing
;
27417 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
27419 /* Relative composition with or without
27420 alternate chars. */
27421 left
= (leftmost
+ rightmost
- width
) / 2;
27422 btm
= - descent
+ boff
;
27423 if (font
->relative_compose
27424 && (! CHAR_TABLE_P (Vignore_relative_composition
)
27425 || NILP (Faref (Vignore_relative_composition
,
27426 make_number (ch
)))))
27429 if (- descent
>= font
->relative_compose
)
27430 /* One extra pixel between two glyphs. */
27432 else if (ascent
<= 0)
27433 /* One extra pixel between two glyphs. */
27434 btm
= lowest
- 1 - ascent
- descent
;
27439 /* A composition rule is specified by an integer
27440 value that encodes global and new reference
27441 points (GREF and NREF). GREF and NREF are
27442 specified by numbers as below:
27444 0---1---2 -- ascent
27448 9--10--11 -- center
27450 ---3---4---5--- baseline
27452 6---7---8 -- descent
27454 int rule
= COMPOSITION_RULE (cmp
, i
);
27455 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
27457 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
27458 grefx
= gref
% 3, nrefx
= nref
% 3;
27459 grefy
= gref
/ 3, nrefy
= nref
/ 3;
27461 xoff
= font_height
* (xoff
- 128) / 256;
27463 yoff
= font_height
* (yoff
- 128) / 256;
27466 + grefx
* (rightmost
- leftmost
) / 2
27467 - nrefx
* width
/ 2
27470 btm
= ((grefy
== 0 ? highest
27472 : grefy
== 2 ? lowest
27473 : (highest
+ lowest
) / 2)
27474 - (nrefy
== 0 ? ascent
+ descent
27475 : nrefy
== 1 ? descent
- boff
27477 : (ascent
+ descent
) / 2)
27481 cmp
->offsets
[i
* 2] = left
;
27482 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
27484 /* Update the bounding box of the overall glyphs. */
27487 right
= left
+ width
;
27488 if (left
< leftmost
)
27490 if (right
> rightmost
)
27493 top
= btm
+ descent
+ ascent
;
27499 if (cmp
->lbearing
> left
+ lbearing
)
27500 cmp
->lbearing
= left
+ lbearing
;
27501 if (cmp
->rbearing
< left
+ rbearing
)
27502 cmp
->rbearing
= left
+ rbearing
;
27506 /* If there are glyphs whose x-offsets are negative,
27507 shift all glyphs to the right and make all x-offsets
27511 for (i
= 0; i
< cmp
->glyph_len
; i
++)
27512 cmp
->offsets
[i
* 2] -= leftmost
;
27513 rightmost
-= leftmost
;
27514 cmp
->lbearing
-= leftmost
;
27515 cmp
->rbearing
-= leftmost
;
27518 if (left_padded
&& cmp
->lbearing
< 0)
27520 for (i
= 0; i
< cmp
->glyph_len
; i
++)
27521 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
27522 rightmost
-= cmp
->lbearing
;
27523 cmp
->rbearing
-= cmp
->lbearing
;
27526 if (right_padded
&& rightmost
< cmp
->rbearing
)
27528 rightmost
= cmp
->rbearing
;
27531 cmp
->pixel_width
= rightmost
;
27532 cmp
->ascent
= highest
;
27533 cmp
->descent
= - lowest
;
27534 if (cmp
->ascent
< font_ascent
)
27535 cmp
->ascent
= font_ascent
;
27536 if (cmp
->descent
< font_descent
)
27537 cmp
->descent
= font_descent
;
27541 && (cmp
->lbearing
< 0
27542 || cmp
->rbearing
> cmp
->pixel_width
))
27543 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27545 it
->pixel_width
= cmp
->pixel_width
;
27546 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
27547 it
->descent
= it
->phys_descent
= cmp
->descent
;
27548 if (face
->box
!= FACE_NO_BOX
)
27550 int thick
= face
->box_line_width
;
27554 it
->ascent
+= thick
;
27555 it
->descent
+= thick
;
27560 if (it
->start_of_box_run_p
)
27561 it
->pixel_width
+= thick
;
27562 if (it
->end_of_box_run_p
)
27563 it
->pixel_width
+= thick
;
27566 /* If face has an overline, add the height of the overline
27567 (1 pixel) and a 1 pixel margin to the character height. */
27568 if (face
->overline_p
)
27569 it
->ascent
+= overline_margin
;
27571 take_vertical_position_into_account (it
);
27572 if (it
->ascent
< 0)
27574 if (it
->descent
< 0)
27577 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
27578 append_composite_glyph (it
);
27580 else if (it
->what
== IT_COMPOSITION
)
27582 /* A dynamic (automatic) composition. */
27583 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27584 Lisp_Object gstring
;
27585 struct font_metrics metrics
;
27589 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
27591 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
27594 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
27595 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27596 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
27597 it
->descent
= it
->phys_descent
= metrics
.descent
;
27598 if (face
->box
!= FACE_NO_BOX
)
27600 int thick
= face
->box_line_width
;
27604 it
->ascent
+= thick
;
27605 it
->descent
+= thick
;
27610 if (it
->start_of_box_run_p
)
27611 it
->pixel_width
+= thick
;
27612 if (it
->end_of_box_run_p
)
27613 it
->pixel_width
+= thick
;
27615 /* If face has an overline, add the height of the overline
27616 (1 pixel) and a 1 pixel margin to the character height. */
27617 if (face
->overline_p
)
27618 it
->ascent
+= overline_margin
;
27619 take_vertical_position_into_account (it
);
27620 if (it
->ascent
< 0)
27622 if (it
->descent
< 0)
27626 append_composite_glyph (it
);
27628 else if (it
->what
== IT_GLYPHLESS
)
27629 produce_glyphless_glyph (it
, false, Qnil
);
27630 else if (it
->what
== IT_IMAGE
)
27631 produce_image_glyph (it
);
27632 else if (it
->what
== IT_STRETCH
)
27633 produce_stretch_glyph (it
);
27634 #ifdef HAVE_XWIDGETS
27635 else if (it
->what
== IT_XWIDGET
)
27636 produce_xwidget_glyph (it
);
27640 /* Accumulate dimensions. Note: can't assume that it->descent > 0
27641 because this isn't true for images with `:ascent 100'. */
27642 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
27643 if (it
->area
== TEXT_AREA
)
27644 it
->current_x
+= it
->pixel_width
;
27646 if (extra_line_spacing
> 0)
27648 it
->descent
+= extra_line_spacing
;
27649 if (extra_line_spacing
> it
->max_extra_line_spacing
)
27650 it
->max_extra_line_spacing
= extra_line_spacing
;
27653 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
27654 it
->max_descent
= max (it
->max_descent
, it
->descent
);
27655 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
27656 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
27660 Output LEN glyphs starting at START at the nominal cursor position.
27661 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
27662 being updated, and UPDATED_AREA is the area of that row being updated. */
27665 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27666 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27668 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
27670 eassert (updated_row
);
27671 /* When the window is hscrolled, cursor hpos can legitimately be out
27672 of bounds, but we draw the cursor at the corresponding window
27673 margin in that case. */
27674 if (!updated_row
->reversed_p
&& chpos
< 0)
27676 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
27677 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
27681 /* Write glyphs. */
27683 hpos
= start
- updated_row
->glyphs
[updated_area
];
27684 x
= draw_glyphs (w
, w
->output_cursor
.x
,
27685 updated_row
, updated_area
,
27687 DRAW_NORMAL_TEXT
, 0);
27689 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
27690 if (updated_area
== TEXT_AREA
27691 && w
->phys_cursor_on_p
27692 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
27694 && chpos
< hpos
+ len
)
27695 w
->phys_cursor_on_p
= false;
27699 /* Advance the output cursor. */
27700 w
->output_cursor
.hpos
+= len
;
27701 w
->output_cursor
.x
= x
;
27706 Insert LEN glyphs from START at the nominal cursor position. */
27709 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27710 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27713 int line_height
, shift_by_width
, shifted_region_width
;
27714 struct glyph_row
*row
;
27715 struct glyph
*glyph
;
27716 int frame_x
, frame_y
;
27719 eassert (updated_row
);
27721 f
= XFRAME (WINDOW_FRAME (w
));
27723 /* Get the height of the line we are in. */
27725 line_height
= row
->height
;
27727 /* Get the width of the glyphs to insert. */
27728 shift_by_width
= 0;
27729 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
27730 shift_by_width
+= glyph
->pixel_width
;
27732 /* Get the width of the region to shift right. */
27733 shifted_region_width
= (window_box_width (w
, updated_area
)
27734 - w
->output_cursor
.x
27738 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
27739 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
27741 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
27742 line_height
, shift_by_width
);
27744 /* Write the glyphs. */
27745 hpos
= start
- row
->glyphs
[updated_area
];
27746 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
27748 DRAW_NORMAL_TEXT
, 0);
27750 /* Advance the output cursor. */
27751 w
->output_cursor
.hpos
+= len
;
27752 w
->output_cursor
.x
+= shift_by_width
;
27758 Erase the current text line from the nominal cursor position
27759 (inclusive) to pixel column TO_X (exclusive). The idea is that
27760 everything from TO_X onward is already erased.
27762 TO_X is a pixel position relative to UPDATED_AREA of currently
27763 updated window W. TO_X == -1 means clear to the end of this area. */
27766 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
27767 enum glyph_row_area updated_area
, int to_x
)
27770 int max_x
, min_y
, max_y
;
27771 int from_x
, from_y
, to_y
;
27773 eassert (updated_row
);
27774 f
= XFRAME (w
->frame
);
27776 if (updated_row
->full_width_p
)
27777 max_x
= (WINDOW_PIXEL_WIDTH (w
)
27778 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
27780 max_x
= window_box_width (w
, updated_area
);
27781 max_y
= window_text_bottom_y (w
);
27783 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
27784 of window. For TO_X > 0, truncate to end of drawing area. */
27790 to_x
= min (to_x
, max_x
);
27792 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
27794 /* Notice if the cursor will be cleared by this operation. */
27795 if (!updated_row
->full_width_p
)
27796 notice_overwritten_cursor (w
, updated_area
,
27797 w
->output_cursor
.x
, -1,
27799 MATRIX_ROW_BOTTOM_Y (updated_row
));
27801 from_x
= w
->output_cursor
.x
;
27803 /* Translate to frame coordinates. */
27804 if (updated_row
->full_width_p
)
27806 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
27807 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
27811 int area_left
= window_box_left (w
, updated_area
);
27812 from_x
+= area_left
;
27816 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
27817 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
27818 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
27820 /* Prevent inadvertently clearing to end of the X window. */
27821 if (to_x
> from_x
&& to_y
> from_y
)
27824 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
27825 to_x
- from_x
, to_y
- from_y
);
27830 #endif /* HAVE_WINDOW_SYSTEM */
27834 /***********************************************************************
27836 ***********************************************************************/
27838 /* Value is the internal representation of the specified cursor type
27839 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
27840 of the bar cursor. */
27842 static enum text_cursor_kinds
27843 get_specified_cursor_type (Lisp_Object arg
, int *width
)
27845 enum text_cursor_kinds type
;
27850 if (EQ (arg
, Qbox
))
27851 return FILLED_BOX_CURSOR
;
27853 if (EQ (arg
, Qhollow
))
27854 return HOLLOW_BOX_CURSOR
;
27856 if (EQ (arg
, Qbar
))
27863 && EQ (XCAR (arg
), Qbar
)
27864 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27866 *width
= XINT (XCDR (arg
));
27870 if (EQ (arg
, Qhbar
))
27873 return HBAR_CURSOR
;
27877 && EQ (XCAR (arg
), Qhbar
)
27878 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27880 *width
= XINT (XCDR (arg
));
27881 return HBAR_CURSOR
;
27884 /* Treat anything unknown as "hollow box cursor".
27885 It was bad to signal an error; people have trouble fixing
27886 .Xdefaults with Emacs, when it has something bad in it. */
27887 type
= HOLLOW_BOX_CURSOR
;
27892 /* Set the default cursor types for specified frame. */
27894 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
27899 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
27900 FRAME_CURSOR_WIDTH (f
) = width
;
27902 /* By default, set up the blink-off state depending on the on-state. */
27904 tem
= Fassoc (arg
, Vblink_cursor_alist
);
27907 FRAME_BLINK_OFF_CURSOR (f
)
27908 = get_specified_cursor_type (XCDR (tem
), &width
);
27909 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
27912 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
27914 /* Make sure the cursor gets redrawn. */
27915 f
->cursor_type_changed
= true;
27919 #ifdef HAVE_WINDOW_SYSTEM
27921 /* Return the cursor we want to be displayed in window W. Return
27922 width of bar/hbar cursor through WIDTH arg. Return with
27923 ACTIVE_CURSOR arg set to true if cursor in window W is `active'
27924 (i.e. if the `system caret' should track this cursor).
27926 In a mini-buffer window, we want the cursor only to appear if we
27927 are reading input from this window. For the selected window, we
27928 want the cursor type given by the frame parameter or buffer local
27929 setting of cursor-type. If explicitly marked off, draw no cursor.
27930 In all other cases, we want a hollow box cursor. */
27932 static enum text_cursor_kinds
27933 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
27934 bool *active_cursor
)
27936 struct frame
*f
= XFRAME (w
->frame
);
27937 struct buffer
*b
= XBUFFER (w
->contents
);
27938 int cursor_type
= DEFAULT_CURSOR
;
27939 Lisp_Object alt_cursor
;
27940 bool non_selected
= false;
27942 *active_cursor
= true;
27945 if (cursor_in_echo_area
27946 && FRAME_HAS_MINIBUF_P (f
)
27947 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
27949 if (w
== XWINDOW (echo_area_window
))
27951 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
27953 *width
= FRAME_CURSOR_WIDTH (f
);
27954 return FRAME_DESIRED_CURSOR (f
);
27957 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27960 *active_cursor
= false;
27961 non_selected
= true;
27964 /* Detect a nonselected window or nonselected frame. */
27965 else if (w
!= XWINDOW (f
->selected_window
)
27966 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
27968 *active_cursor
= false;
27970 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
27973 non_selected
= true;
27976 /* Never display a cursor in a window in which cursor-type is nil. */
27977 if (NILP (BVAR (b
, cursor_type
)))
27980 /* Get the normal cursor type for this window. */
27981 if (EQ (BVAR (b
, cursor_type
), Qt
))
27983 cursor_type
= FRAME_DESIRED_CURSOR (f
);
27984 *width
= FRAME_CURSOR_WIDTH (f
);
27987 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27989 /* Use cursor-in-non-selected-windows instead
27990 for non-selected window or frame. */
27993 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
27994 if (!EQ (Qt
, alt_cursor
))
27995 return get_specified_cursor_type (alt_cursor
, width
);
27996 /* t means modify the normal cursor type. */
27997 if (cursor_type
== FILLED_BOX_CURSOR
)
27998 cursor_type
= HOLLOW_BOX_CURSOR
;
27999 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
28001 return cursor_type
;
28004 /* Use normal cursor if not blinked off. */
28005 if (!w
->cursor_off_p
)
28007 #ifdef HAVE_XWIDGETS
28008 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
)
28011 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28013 if (cursor_type
== FILLED_BOX_CURSOR
)
28015 /* Using a block cursor on large images can be very annoying.
28016 So use a hollow cursor for "large" images.
28017 If image is not transparent (no mask), also use hollow cursor. */
28018 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28019 if (img
!= NULL
&& IMAGEP (img
->spec
))
28021 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
28022 where N = size of default frame font size.
28023 This should cover most of the "tiny" icons people may use. */
28025 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
28026 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
28027 cursor_type
= HOLLOW_BOX_CURSOR
;
28030 else if (cursor_type
!= NO_CURSOR
)
28032 /* Display current only supports BOX and HOLLOW cursors for images.
28033 So for now, unconditionally use a HOLLOW cursor when cursor is
28034 not a solid box cursor. */
28035 cursor_type
= HOLLOW_BOX_CURSOR
;
28038 return cursor_type
;
28041 /* Cursor is blinked off, so determine how to "toggle" it. */
28043 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
28044 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
28045 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
28047 /* Then see if frame has specified a specific blink off cursor type. */
28048 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
28050 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
28051 return FRAME_BLINK_OFF_CURSOR (f
);
28055 /* Some people liked having a permanently visible blinking cursor,
28056 while others had very strong opinions against it. So it was
28057 decided to remove it. KFS 2003-09-03 */
28059 /* Finally perform built-in cursor blinking:
28060 filled box <-> hollow box
28061 wide [h]bar <-> narrow [h]bar
28062 narrow [h]bar <-> no cursor
28063 other type <-> no cursor */
28065 if (cursor_type
== FILLED_BOX_CURSOR
)
28066 return HOLLOW_BOX_CURSOR
;
28068 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
28071 return cursor_type
;
28079 /* Notice when the text cursor of window W has been completely
28080 overwritten by a drawing operation that outputs glyphs in AREA
28081 starting at X0 and ending at X1 in the line starting at Y0 and
28082 ending at Y1. X coordinates are area-relative. X1 < 0 means all
28083 the rest of the line after X0 has been written. Y coordinates
28084 are window-relative. */
28087 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
28088 int x0
, int x1
, int y0
, int y1
)
28090 int cx0
, cx1
, cy0
, cy1
;
28091 struct glyph_row
*row
;
28093 if (!w
->phys_cursor_on_p
)
28095 if (area
!= TEXT_AREA
)
28098 if (w
->phys_cursor
.vpos
< 0
28099 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
28100 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
28101 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
28104 if (row
->cursor_in_fringe_p
)
28106 row
->cursor_in_fringe_p
= false;
28107 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
28108 w
->phys_cursor_on_p
= false;
28112 cx0
= w
->phys_cursor
.x
;
28113 cx1
= cx0
+ w
->phys_cursor_width
;
28114 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
28117 /* The cursor image will be completely removed from the
28118 screen if the output area intersects the cursor area in
28119 y-direction. When we draw in [y0 y1[, and some part of
28120 the cursor is at y < y0, that part must have been drawn
28121 before. When scrolling, the cursor is erased before
28122 actually scrolling, so we don't come here. When not
28123 scrolling, the rows above the old cursor row must have
28124 changed, and in this case these rows must have written
28125 over the cursor image.
28127 Likewise if part of the cursor is below y1, with the
28128 exception of the cursor being in the first blank row at
28129 the buffer and window end because update_text_area
28130 doesn't draw that row. (Except when it does, but
28131 that's handled in update_text_area.) */
28133 cy0
= w
->phys_cursor
.y
;
28134 cy1
= cy0
+ w
->phys_cursor_height
;
28135 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
28138 w
->phys_cursor_on_p
= false;
28141 #endif /* HAVE_WINDOW_SYSTEM */
28144 /************************************************************************
28146 ************************************************************************/
28148 #ifdef HAVE_WINDOW_SYSTEM
28151 Fix the display of area AREA of overlapping row ROW in window W
28152 with respect to the overlapping part OVERLAPS. */
28155 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
28156 enum glyph_row_area area
, int overlaps
)
28163 for (i
= 0; i
< row
->used
[area
];)
28165 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
28167 int start
= i
, start_x
= x
;
28171 x
+= row
->glyphs
[area
][i
].pixel_width
;
28174 while (i
< row
->used
[area
]
28175 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
28177 draw_glyphs (w
, start_x
, row
, area
,
28179 DRAW_NORMAL_TEXT
, overlaps
);
28183 x
+= row
->glyphs
[area
][i
].pixel_width
;
28193 Draw the cursor glyph of window W in glyph row ROW. See the
28194 comment of draw_glyphs for the meaning of HL. */
28197 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
28198 enum draw_glyphs_face hl
)
28200 /* If cursor hpos is out of bounds, don't draw garbage. This can
28201 happen in mini-buffer windows when switching between echo area
28202 glyphs and mini-buffer. */
28203 if ((row
->reversed_p
28204 ? (w
->phys_cursor
.hpos
>= 0)
28205 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
28207 bool on_p
= w
->phys_cursor_on_p
;
28209 int hpos
= w
->phys_cursor
.hpos
;
28211 /* When the window is hscrolled, cursor hpos can legitimately be
28212 out of bounds, but we draw the cursor at the corresponding
28213 window margin in that case. */
28214 if (!row
->reversed_p
&& hpos
< 0)
28216 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28217 hpos
= row
->used
[TEXT_AREA
] - 1;
28219 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
28221 w
->phys_cursor_on_p
= on_p
;
28223 if (hl
== DRAW_CURSOR
)
28224 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
28225 /* When we erase the cursor, and ROW is overlapped by other
28226 rows, make sure that these overlapping parts of other rows
28228 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
28230 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
28232 if (row
> w
->current_matrix
->rows
28233 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
28234 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
28235 OVERLAPS_ERASED_CURSOR
);
28237 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
28238 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
28239 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
28240 OVERLAPS_ERASED_CURSOR
);
28246 /* Erase the image of a cursor of window W from the screen. */
28249 erase_phys_cursor (struct window
*w
)
28251 struct frame
*f
= XFRAME (w
->frame
);
28252 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28253 int hpos
= w
->phys_cursor
.hpos
;
28254 int vpos
= w
->phys_cursor
.vpos
;
28255 bool mouse_face_here_p
= false;
28256 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
28257 struct glyph_row
*cursor_row
;
28258 struct glyph
*cursor_glyph
;
28259 enum draw_glyphs_face hl
;
28261 /* No cursor displayed or row invalidated => nothing to do on the
28263 if (w
->phys_cursor_type
== NO_CURSOR
)
28264 goto mark_cursor_off
;
28266 /* VPOS >= active_glyphs->nrows means that window has been resized.
28267 Don't bother to erase the cursor. */
28268 if (vpos
>= active_glyphs
->nrows
)
28269 goto mark_cursor_off
;
28271 /* If row containing cursor is marked invalid, there is nothing we
28273 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
28274 if (!cursor_row
->enabled_p
)
28275 goto mark_cursor_off
;
28277 /* If line spacing is > 0, old cursor may only be partially visible in
28278 window after split-window. So adjust visible height. */
28279 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
28280 window_text_bottom_y (w
) - cursor_row
->y
);
28282 /* If row is completely invisible, don't attempt to delete a cursor which
28283 isn't there. This can happen if cursor is at top of a window, and
28284 we switch to a buffer with a header line in that window. */
28285 if (cursor_row
->visible_height
<= 0)
28286 goto mark_cursor_off
;
28288 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
28289 if (cursor_row
->cursor_in_fringe_p
)
28291 cursor_row
->cursor_in_fringe_p
= false;
28292 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
28293 goto mark_cursor_off
;
28296 /* This can happen when the new row is shorter than the old one.
28297 In this case, either draw_glyphs or clear_end_of_line
28298 should have cleared the cursor. Note that we wouldn't be
28299 able to erase the cursor in this case because we don't have a
28300 cursor glyph at hand. */
28301 if ((cursor_row
->reversed_p
28302 ? (w
->phys_cursor
.hpos
< 0)
28303 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
28304 goto mark_cursor_off
;
28306 /* When the window is hscrolled, cursor hpos can legitimately be out
28307 of bounds, but we draw the cursor at the corresponding window
28308 margin in that case. */
28309 if (!cursor_row
->reversed_p
&& hpos
< 0)
28311 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
28312 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
28314 /* If the cursor is in the mouse face area, redisplay that when
28315 we clear the cursor. */
28316 if (! NILP (hlinfo
->mouse_face_window
)
28317 && coords_in_mouse_face_p (w
, hpos
, vpos
)
28318 /* Don't redraw the cursor's spot in mouse face if it is at the
28319 end of a line (on a newline). The cursor appears there, but
28320 mouse highlighting does not. */
28321 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
28322 mouse_face_here_p
= true;
28324 /* Maybe clear the display under the cursor. */
28325 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
28328 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
28331 cursor_glyph
= get_phys_cursor_glyph (w
);
28332 if (cursor_glyph
== NULL
)
28333 goto mark_cursor_off
;
28335 width
= cursor_glyph
->pixel_width
;
28336 x
= w
->phys_cursor
.x
;
28342 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
28343 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
28344 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
28347 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
28350 /* Erase the cursor by redrawing the character underneath it. */
28351 if (mouse_face_here_p
)
28352 hl
= DRAW_MOUSE_FACE
;
28354 hl
= DRAW_NORMAL_TEXT
;
28355 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
28358 w
->phys_cursor_on_p
= false;
28359 w
->phys_cursor_type
= NO_CURSOR
;
28363 /* Display or clear cursor of window W. If !ON, clear the cursor.
28364 If ON, display the cursor; where to put the cursor is specified by
28365 HPOS, VPOS, X and Y. */
28368 display_and_set_cursor (struct window
*w
, bool on
,
28369 int hpos
, int vpos
, int x
, int y
)
28371 struct frame
*f
= XFRAME (w
->frame
);
28372 int new_cursor_type
;
28373 int new_cursor_width
;
28374 bool active_cursor
;
28375 struct glyph_row
*glyph_row
;
28376 struct glyph
*glyph
;
28378 /* This is pointless on invisible frames, and dangerous on garbaged
28379 windows and frames; in the latter case, the frame or window may
28380 be in the midst of changing its size, and x and y may be off the
28382 if (! FRAME_VISIBLE_P (f
)
28383 || FRAME_GARBAGED_P (f
)
28384 || vpos
>= w
->current_matrix
->nrows
28385 || hpos
>= w
->current_matrix
->matrix_w
)
28388 /* If cursor is off and we want it off, return quickly. */
28389 if (!on
&& !w
->phys_cursor_on_p
)
28392 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28393 /* If cursor row is not enabled, we don't really know where to
28394 display the cursor. */
28395 if (!glyph_row
->enabled_p
)
28397 w
->phys_cursor_on_p
= false;
28402 if (!glyph_row
->exact_window_width_line_p
28403 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
28404 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
28406 eassert (input_blocked_p ());
28408 /* Set new_cursor_type to the cursor we want to be displayed. */
28409 new_cursor_type
= get_window_cursor_type (w
, glyph
,
28410 &new_cursor_width
, &active_cursor
);
28412 /* If cursor is currently being shown and we don't want it to be or
28413 it is in the wrong place, or the cursor type is not what we want,
28415 if (w
->phys_cursor_on_p
28417 || w
->phys_cursor
.x
!= x
28418 || w
->phys_cursor
.y
!= y
28419 /* HPOS can be negative in R2L rows whose
28420 exact_window_width_line_p flag is set (i.e. their newline
28421 would "overflow into the fringe"). */
28423 || new_cursor_type
!= w
->phys_cursor_type
28424 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
28425 && new_cursor_width
!= w
->phys_cursor_width
)))
28426 erase_phys_cursor (w
);
28428 /* Don't check phys_cursor_on_p here because that flag is only set
28429 to false in some cases where we know that the cursor has been
28430 completely erased, to avoid the extra work of erasing the cursor
28431 twice. In other words, phys_cursor_on_p can be true and the cursor
28432 still not be visible, or it has only been partly erased. */
28435 w
->phys_cursor_ascent
= glyph_row
->ascent
;
28436 w
->phys_cursor_height
= glyph_row
->height
;
28438 /* Set phys_cursor_.* before x_draw_.* is called because some
28439 of them may need the information. */
28440 w
->phys_cursor
.x
= x
;
28441 w
->phys_cursor
.y
= glyph_row
->y
;
28442 w
->phys_cursor
.hpos
= hpos
;
28443 w
->phys_cursor
.vpos
= vpos
;
28446 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
28447 new_cursor_type
, new_cursor_width
,
28448 on
, active_cursor
);
28452 /* Switch the display of W's cursor on or off, according to the value
28456 update_window_cursor (struct window
*w
, bool on
)
28458 /* Don't update cursor in windows whose frame is in the process
28459 of being deleted. */
28460 if (w
->current_matrix
)
28462 int hpos
= w
->phys_cursor
.hpos
;
28463 int vpos
= w
->phys_cursor
.vpos
;
28464 struct glyph_row
*row
;
28466 if (vpos
>= w
->current_matrix
->nrows
28467 || hpos
>= w
->current_matrix
->matrix_w
)
28470 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28472 /* When the window is hscrolled, cursor hpos can legitimately be
28473 out of bounds, but we draw the cursor at the corresponding
28474 window margin in that case. */
28475 if (!row
->reversed_p
&& hpos
< 0)
28477 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28478 hpos
= row
->used
[TEXT_AREA
] - 1;
28481 display_and_set_cursor (w
, on
, hpos
, vpos
,
28482 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28488 /* Call update_window_cursor with parameter ON_P on all leaf windows
28489 in the window tree rooted at W. */
28492 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
28496 if (WINDOWP (w
->contents
))
28497 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
28499 update_window_cursor (w
, on_p
);
28501 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
28507 Display the cursor on window W, or clear it, according to ON_P.
28508 Don't change the cursor's position. */
28511 x_update_cursor (struct frame
*f
, bool on_p
)
28513 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
28518 Clear the cursor of window W to background color, and mark the
28519 cursor as not shown. This is used when the text where the cursor
28520 is about to be rewritten. */
28523 x_clear_cursor (struct window
*w
)
28525 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
28526 update_window_cursor (w
, false);
28529 #endif /* HAVE_WINDOW_SYSTEM */
28531 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
28534 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
28535 int start_hpos
, int end_hpos
,
28536 enum draw_glyphs_face draw
)
28538 #ifdef HAVE_WINDOW_SYSTEM
28539 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
28541 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
28545 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
28546 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
28550 /* Display the active region described by mouse_face_* according to DRAW. */
28553 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
28555 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
28556 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28558 if (/* If window is in the process of being destroyed, don't bother
28560 w
->current_matrix
!= NULL
28561 /* Don't update mouse highlight if hidden. */
28562 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
28563 /* Recognize when we are called to operate on rows that don't exist
28564 anymore. This can happen when a window is split. */
28565 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
28567 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
28568 struct glyph_row
*row
, *first
, *last
;
28570 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
28571 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
28573 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
28575 int start_hpos
, end_hpos
, start_x
;
28577 /* For all but the first row, the highlight starts at column 0. */
28580 /* R2L rows have BEG and END in reversed order, but the
28581 screen drawing geometry is always left to right. So
28582 we need to mirror the beginning and end of the
28583 highlighted area in R2L rows. */
28584 if (!row
->reversed_p
)
28586 start_hpos
= hlinfo
->mouse_face_beg_col
;
28587 start_x
= hlinfo
->mouse_face_beg_x
;
28589 else if (row
== last
)
28591 start_hpos
= hlinfo
->mouse_face_end_col
;
28592 start_x
= hlinfo
->mouse_face_end_x
;
28600 else if (row
->reversed_p
&& row
== last
)
28602 start_hpos
= hlinfo
->mouse_face_end_col
;
28603 start_x
= hlinfo
->mouse_face_end_x
;
28613 if (!row
->reversed_p
)
28614 end_hpos
= hlinfo
->mouse_face_end_col
;
28615 else if (row
== first
)
28616 end_hpos
= hlinfo
->mouse_face_beg_col
;
28619 end_hpos
= row
->used
[TEXT_AREA
];
28620 if (draw
== DRAW_NORMAL_TEXT
)
28621 row
->fill_line_p
= true; /* Clear to end of line. */
28624 else if (row
->reversed_p
&& row
== first
)
28625 end_hpos
= hlinfo
->mouse_face_beg_col
;
28628 end_hpos
= row
->used
[TEXT_AREA
];
28629 if (draw
== DRAW_NORMAL_TEXT
)
28630 row
->fill_line_p
= true; /* Clear to end of line. */
28633 if (end_hpos
> start_hpos
)
28635 draw_row_with_mouse_face (w
, start_x
, row
,
28636 start_hpos
, end_hpos
, draw
);
28639 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
28643 #ifdef HAVE_WINDOW_SYSTEM
28644 /* When we've written over the cursor, arrange for it to
28645 be displayed again. */
28646 if (FRAME_WINDOW_P (f
)
28647 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
28649 int hpos
= w
->phys_cursor
.hpos
;
28651 /* When the window is hscrolled, cursor hpos can legitimately be
28652 out of bounds, but we draw the cursor at the corresponding
28653 window margin in that case. */
28654 if (!row
->reversed_p
&& hpos
< 0)
28656 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28657 hpos
= row
->used
[TEXT_AREA
] - 1;
28660 display_and_set_cursor (w
, true, hpos
, w
->phys_cursor
.vpos
,
28661 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28664 #endif /* HAVE_WINDOW_SYSTEM */
28667 #ifdef HAVE_WINDOW_SYSTEM
28668 /* Change the mouse cursor. */
28669 if (FRAME_WINDOW_P (f
) && NILP (do_mouse_tracking
))
28671 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
28672 if (draw
== DRAW_NORMAL_TEXT
28673 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
28674 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
28677 if (draw
== DRAW_MOUSE_FACE
)
28678 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
28680 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
28682 #endif /* HAVE_WINDOW_SYSTEM */
28686 Clear out the mouse-highlighted active region.
28687 Redraw it un-highlighted first. Value is true if mouse
28688 face was actually drawn unhighlighted. */
28691 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
28694 = !hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
);
28696 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
28697 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28698 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28699 hlinfo
->mouse_face_window
= Qnil
;
28700 hlinfo
->mouse_face_overlay
= Qnil
;
28704 /* Return true if the coordinates HPOS and VPOS on windows W are
28705 within the mouse face on that window. */
28707 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
28709 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28711 /* Quickly resolve the easy cases. */
28712 if (!(WINDOWP (hlinfo
->mouse_face_window
)
28713 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
28715 if (vpos
< hlinfo
->mouse_face_beg_row
28716 || vpos
> hlinfo
->mouse_face_end_row
)
28718 if (vpos
> hlinfo
->mouse_face_beg_row
28719 && vpos
< hlinfo
->mouse_face_end_row
)
28722 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
28724 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28726 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
28729 else if ((vpos
== hlinfo
->mouse_face_beg_row
28730 && hpos
>= hlinfo
->mouse_face_beg_col
)
28731 || (vpos
== hlinfo
->mouse_face_end_row
28732 && hpos
< hlinfo
->mouse_face_end_col
))
28737 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28739 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
28742 else if ((vpos
== hlinfo
->mouse_face_beg_row
28743 && hpos
<= hlinfo
->mouse_face_beg_col
)
28744 || (vpos
== hlinfo
->mouse_face_end_row
28745 && hpos
> hlinfo
->mouse_face_end_col
))
28753 True if physical cursor of window W is within mouse face. */
28756 cursor_in_mouse_face_p (struct window
*w
)
28758 int hpos
= w
->phys_cursor
.hpos
;
28759 int vpos
= w
->phys_cursor
.vpos
;
28760 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28762 /* When the window is hscrolled, cursor hpos can legitimately be out
28763 of bounds, but we draw the cursor at the corresponding window
28764 margin in that case. */
28765 if (!row
->reversed_p
&& hpos
< 0)
28767 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28768 hpos
= row
->used
[TEXT_AREA
] - 1;
28770 return coords_in_mouse_face_p (w
, hpos
, vpos
);
28775 /* Find the glyph rows START_ROW and END_ROW of window W that display
28776 characters between buffer positions START_CHARPOS and END_CHARPOS
28777 (excluding END_CHARPOS). DISP_STRING is a display string that
28778 covers these buffer positions. This is similar to
28779 row_containing_pos, but is more accurate when bidi reordering makes
28780 buffer positions change non-linearly with glyph rows. */
28782 rows_from_pos_range (struct window
*w
,
28783 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
28784 Lisp_Object disp_string
,
28785 struct glyph_row
**start
, struct glyph_row
**end
)
28787 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28788 int last_y
= window_text_bottom_y (w
);
28789 struct glyph_row
*row
;
28794 while (!first
->enabled_p
28795 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
28798 /* Find the START row. */
28800 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
28803 /* A row can potentially be the START row if the range of the
28804 characters it displays intersects the range
28805 [START_CHARPOS..END_CHARPOS). */
28806 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
28807 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
28808 /* See the commentary in row_containing_pos, for the
28809 explanation of the complicated way to check whether
28810 some position is beyond the end of the characters
28811 displayed by a row. */
28812 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28813 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28814 && !row
->ends_at_zv_p
28815 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
28816 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28817 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28818 && !row
->ends_at_zv_p
28819 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
28821 /* Found a candidate row. Now make sure at least one of the
28822 glyphs it displays has a charpos from the range
28823 [START_CHARPOS..END_CHARPOS).
28825 This is not obvious because bidi reordering could make
28826 buffer positions of a row be 1,2,3,102,101,100, and if we
28827 want to highlight characters in [50..60), we don't want
28828 this row, even though [50..60) does intersect [1..103),
28829 the range of character positions given by the row's start
28830 and end positions. */
28831 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
28832 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
28836 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28837 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28838 /* A glyph that comes from DISP_STRING is by
28839 definition to be highlighted. */
28840 || EQ (g
->object
, disp_string
))
28849 /* Find the END row. */
28851 /* If the last row is partially visible, start looking for END
28852 from that row, instead of starting from FIRST. */
28853 && !(row
->enabled_p
28854 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
28856 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
28858 struct glyph_row
*next
= row
+ 1;
28859 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
28861 if (!next
->enabled_p
28862 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
28863 /* The first row >= START whose range of displayed characters
28864 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
28865 is the row END + 1. */
28866 || (start_charpos
< next_start
28867 && end_charpos
< next_start
)
28868 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28869 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28870 && !next
->ends_at_zv_p
28871 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
28872 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28873 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28874 && !next
->ends_at_zv_p
28875 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
28882 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
28883 but none of the characters it displays are in the range, it is
28885 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
28886 struct glyph
*s
= g
;
28887 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
28891 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28892 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28893 /* If the buffer position of the first glyph in
28894 the row is equal to END_CHARPOS, it means
28895 the last character to be highlighted is the
28896 newline of ROW, and we must consider NEXT as
28898 || (((!next
->reversed_p
&& g
== s
)
28899 || (next
->reversed_p
&& g
== e
- 1))
28900 && (g
->charpos
== end_charpos
28901 /* Special case for when NEXT is an
28902 empty line at ZV. */
28903 || (g
->charpos
== -1
28904 && !row
->ends_at_zv_p
28905 && next_start
== end_charpos
)))))
28906 /* A glyph that comes from DISP_STRING is by
28907 definition to be highlighted. */
28908 || EQ (g
->object
, disp_string
))
28917 /* The first row that ends at ZV must be the last to be
28919 else if (next
->ends_at_zv_p
)
28928 /* This function sets the mouse_face_* elements of HLINFO, assuming
28929 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
28930 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
28931 for the overlay or run of text properties specifying the mouse
28932 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
28933 before-string and after-string that must also be highlighted.
28934 DISP_STRING, if non-nil, is a display string that may cover some
28935 or all of the highlighted text. */
28938 mouse_face_from_buffer_pos (Lisp_Object window
,
28939 Mouse_HLInfo
*hlinfo
,
28940 ptrdiff_t mouse_charpos
,
28941 ptrdiff_t start_charpos
,
28942 ptrdiff_t end_charpos
,
28943 Lisp_Object before_string
,
28944 Lisp_Object after_string
,
28945 Lisp_Object disp_string
)
28947 struct window
*w
= XWINDOW (window
);
28948 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28949 struct glyph_row
*r1
, *r2
;
28950 struct glyph
*glyph
, *end
;
28951 ptrdiff_t ignore
, pos
;
28954 eassert (NILP (disp_string
) || STRINGP (disp_string
));
28955 eassert (NILP (before_string
) || STRINGP (before_string
));
28956 eassert (NILP (after_string
) || STRINGP (after_string
));
28958 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
28959 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
28961 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28962 /* If the before-string or display-string contains newlines,
28963 rows_from_pos_range skips to its last row. Move back. */
28964 if (!NILP (before_string
) || !NILP (disp_string
))
28966 struct glyph_row
*prev
;
28967 while ((prev
= r1
- 1, prev
>= first
)
28968 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
28969 && prev
->used
[TEXT_AREA
] > 0)
28971 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
28972 glyph
= beg
+ prev
->used
[TEXT_AREA
];
28973 while (--glyph
>= beg
&& NILP (glyph
->object
));
28975 || !(EQ (glyph
->object
, before_string
)
28976 || EQ (glyph
->object
, disp_string
)))
28983 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28984 hlinfo
->mouse_face_past_end
= true;
28986 else if (!NILP (after_string
))
28988 /* If the after-string has newlines, advance to its last row. */
28989 struct glyph_row
*next
;
28990 struct glyph_row
*last
28991 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28993 for (next
= r2
+ 1;
28995 && next
->used
[TEXT_AREA
] > 0
28996 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
29000 /* The rest of the display engine assumes that mouse_face_beg_row is
29001 either above mouse_face_end_row or identical to it. But with
29002 bidi-reordered continued lines, the row for START_CHARPOS could
29003 be below the row for END_CHARPOS. If so, swap the rows and store
29004 them in correct order. */
29007 struct glyph_row
*tem
= r2
;
29013 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
29014 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
29016 /* For a bidi-reordered row, the positions of BEFORE_STRING,
29017 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
29018 could be anywhere in the row and in any order. The strategy
29019 below is to find the leftmost and the rightmost glyph that
29020 belongs to either of these 3 strings, or whose position is
29021 between START_CHARPOS and END_CHARPOS, and highlight all the
29022 glyphs between those two. This may cover more than just the text
29023 between START_CHARPOS and END_CHARPOS if the range of characters
29024 strides the bidi level boundary, e.g. if the beginning is in R2L
29025 text while the end is in L2R text or vice versa. */
29026 if (!r1
->reversed_p
)
29028 /* This row is in a left to right paragraph. Scan it left to
29030 glyph
= r1
->glyphs
[TEXT_AREA
];
29031 end
= glyph
+ r1
->used
[TEXT_AREA
];
29034 /* Skip truncation glyphs at the start of the glyph row. */
29035 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
29037 && NILP (glyph
->object
)
29038 && glyph
->charpos
< 0;
29040 x
+= glyph
->pixel_width
;
29042 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
29043 or DISP_STRING, and the first glyph from buffer whose
29044 position is between START_CHARPOS and END_CHARPOS. */
29046 && !NILP (glyph
->object
)
29047 && !EQ (glyph
->object
, disp_string
)
29048 && !(BUFFERP (glyph
->object
)
29049 && (glyph
->charpos
>= start_charpos
29050 && glyph
->charpos
< end_charpos
));
29053 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29054 are present at buffer positions between START_CHARPOS and
29055 END_CHARPOS, or if they come from an overlay. */
29056 if (EQ (glyph
->object
, before_string
))
29058 pos
= string_buffer_position (before_string
,
29060 /* If pos == 0, it means before_string came from an
29061 overlay, not from a buffer position. */
29062 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29065 else if (EQ (glyph
->object
, after_string
))
29067 pos
= string_buffer_position (after_string
, end_charpos
);
29068 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29071 x
+= glyph
->pixel_width
;
29073 hlinfo
->mouse_face_beg_x
= x
;
29074 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
29078 /* This row is in a right to left paragraph. Scan it right to
29082 end
= r1
->glyphs
[TEXT_AREA
] - 1;
29083 glyph
= end
+ r1
->used
[TEXT_AREA
];
29085 /* Skip truncation glyphs at the start of the glyph row. */
29086 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
29088 && NILP (glyph
->object
)
29089 && glyph
->charpos
< 0;
29093 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
29094 or DISP_STRING, and the first glyph from buffer whose
29095 position is between START_CHARPOS and END_CHARPOS. */
29097 && !NILP (glyph
->object
)
29098 && !EQ (glyph
->object
, disp_string
)
29099 && !(BUFFERP (glyph
->object
)
29100 && (glyph
->charpos
>= start_charpos
29101 && glyph
->charpos
< end_charpos
));
29104 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29105 are present at buffer positions between START_CHARPOS and
29106 END_CHARPOS, or if they come from an overlay. */
29107 if (EQ (glyph
->object
, before_string
))
29109 pos
= string_buffer_position (before_string
, start_charpos
);
29110 /* If pos == 0, it means before_string came from an
29111 overlay, not from a buffer position. */
29112 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29115 else if (EQ (glyph
->object
, after_string
))
29117 pos
= string_buffer_position (after_string
, end_charpos
);
29118 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29123 glyph
++; /* first glyph to the right of the highlighted area */
29124 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
29125 x
+= g
->pixel_width
;
29126 hlinfo
->mouse_face_beg_x
= x
;
29127 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
29130 /* If the highlight ends in a different row, compute GLYPH and END
29131 for the end row. Otherwise, reuse the values computed above for
29132 the row where the highlight begins. */
29135 if (!r2
->reversed_p
)
29137 glyph
= r2
->glyphs
[TEXT_AREA
];
29138 end
= glyph
+ r2
->used
[TEXT_AREA
];
29143 end
= r2
->glyphs
[TEXT_AREA
] - 1;
29144 glyph
= end
+ r2
->used
[TEXT_AREA
];
29148 if (!r2
->reversed_p
)
29150 /* Skip truncation and continuation glyphs near the end of the
29151 row, and also blanks and stretch glyphs inserted by
29152 extend_face_to_end_of_line. */
29154 && NILP ((end
- 1)->object
))
29156 /* Scan the rest of the glyph row from the end, looking for the
29157 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
29158 DISP_STRING, or whose position is between START_CHARPOS
29162 && !NILP (end
->object
)
29163 && !EQ (end
->object
, disp_string
)
29164 && !(BUFFERP (end
->object
)
29165 && (end
->charpos
>= start_charpos
29166 && end
->charpos
< end_charpos
));
29169 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29170 are present at buffer positions between START_CHARPOS and
29171 END_CHARPOS, or if they come from an overlay. */
29172 if (EQ (end
->object
, before_string
))
29174 pos
= string_buffer_position (before_string
, start_charpos
);
29175 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29178 else if (EQ (end
->object
, after_string
))
29180 pos
= string_buffer_position (after_string
, end_charpos
);
29181 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29185 /* Find the X coordinate of the last glyph to be highlighted. */
29186 for (; glyph
<= end
; ++glyph
)
29187 x
+= glyph
->pixel_width
;
29189 hlinfo
->mouse_face_end_x
= x
;
29190 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
29194 /* Skip truncation and continuation glyphs near the end of the
29195 row, and also blanks and stretch glyphs inserted by
29196 extend_face_to_end_of_line. */
29200 && NILP (end
->object
))
29202 x
+= end
->pixel_width
;
29205 /* Scan the rest of the glyph row from the end, looking for the
29206 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
29207 DISP_STRING, or whose position is between START_CHARPOS
29211 && !NILP (end
->object
)
29212 && !EQ (end
->object
, disp_string
)
29213 && !(BUFFERP (end
->object
)
29214 && (end
->charpos
>= start_charpos
29215 && end
->charpos
< end_charpos
));
29218 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29219 are present at buffer positions between START_CHARPOS and
29220 END_CHARPOS, or if they come from an overlay. */
29221 if (EQ (end
->object
, before_string
))
29223 pos
= string_buffer_position (before_string
, start_charpos
);
29224 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29227 else if (EQ (end
->object
, after_string
))
29229 pos
= string_buffer_position (after_string
, end_charpos
);
29230 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29233 x
+= end
->pixel_width
;
29235 /* If we exited the above loop because we arrived at the last
29236 glyph of the row, and its buffer position is still not in
29237 range, it means the last character in range is the preceding
29238 newline. Bump the end column and x values to get past the
29241 && BUFFERP (end
->object
)
29242 && (end
->charpos
< start_charpos
29243 || end
->charpos
>= end_charpos
))
29245 x
+= end
->pixel_width
;
29248 hlinfo
->mouse_face_end_x
= x
;
29249 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
29252 hlinfo
->mouse_face_window
= window
;
29253 hlinfo
->mouse_face_face_id
29254 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
29256 !hlinfo
->mouse_face_hidden
, -1);
29257 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29260 /* The following function is not used anymore (replaced with
29261 mouse_face_from_string_pos), but I leave it here for the time
29262 being, in case someone would. */
29264 #if false /* not used */
29266 /* Find the position of the glyph for position POS in OBJECT in
29267 window W's current matrix, and return in *X, *Y the pixel
29268 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
29270 RIGHT_P means return the position of the right edge of the glyph.
29271 !RIGHT_P means return the left edge position.
29273 If no glyph for POS exists in the matrix, return the position of
29274 the glyph with the next smaller position that is in the matrix, if
29275 RIGHT_P is false. If RIGHT_P, and no glyph for POS
29276 exists in the matrix, return the position of the glyph with the
29277 next larger position in OBJECT.
29279 Value is true if a glyph was found. */
29282 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
29283 int *hpos
, int *vpos
, int *x
, int *y
, bool right_p
)
29285 int yb
= window_text_bottom_y (w
);
29286 struct glyph_row
*r
;
29287 struct glyph
*best_glyph
= NULL
;
29288 struct glyph_row
*best_row
= NULL
;
29291 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29292 r
->enabled_p
&& r
->y
< yb
;
29295 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
29296 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
29299 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
29300 if (EQ (g
->object
, object
))
29302 if (g
->charpos
== pos
)
29309 else if (best_glyph
== NULL
29310 || ((eabs (g
->charpos
- pos
)
29311 < eabs (best_glyph
->charpos
- pos
))
29314 : g
->charpos
> pos
)))
29328 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
29332 *x
+= best_glyph
->pixel_width
;
29337 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
29340 return best_glyph
!= NULL
;
29342 #endif /* not used */
29344 /* Find the positions of the first and the last glyphs in window W's
29345 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
29346 (assumed to be a string), and return in HLINFO's mouse_face_*
29347 members the pixel and column/row coordinates of those glyphs. */
29350 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
29351 Lisp_Object object
,
29352 ptrdiff_t startpos
, ptrdiff_t endpos
)
29354 int yb
= window_text_bottom_y (w
);
29355 struct glyph_row
*r
;
29356 struct glyph
*g
, *e
;
29358 bool found
= false;
29360 /* Find the glyph row with at least one position in the range
29361 [STARTPOS..ENDPOS), and the first glyph in that row whose
29362 position belongs to that range. */
29363 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29364 r
->enabled_p
&& r
->y
< yb
;
29367 if (!r
->reversed_p
)
29369 g
= r
->glyphs
[TEXT_AREA
];
29370 e
= g
+ r
->used
[TEXT_AREA
];
29371 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
29372 if (EQ (g
->object
, object
)
29373 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
29375 hlinfo
->mouse_face_beg_row
29376 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29377 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
29378 hlinfo
->mouse_face_beg_x
= gx
;
29387 e
= r
->glyphs
[TEXT_AREA
];
29388 g
= e
+ r
->used
[TEXT_AREA
];
29389 for ( ; g
> e
; --g
)
29390 if (EQ ((g
-1)->object
, object
)
29391 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
29393 hlinfo
->mouse_face_beg_row
29394 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29395 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
29396 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
29397 gx
+= g1
->pixel_width
;
29398 hlinfo
->mouse_face_beg_x
= gx
;
29410 /* Starting with the next row, look for the first row which does NOT
29411 include any glyphs whose positions are in the range. */
29412 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
29414 g
= r
->glyphs
[TEXT_AREA
];
29415 e
= g
+ r
->used
[TEXT_AREA
];
29417 for ( ; g
< e
; ++g
)
29418 if (EQ (g
->object
, object
)
29419 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
29428 /* The highlighted region ends on the previous row. */
29431 /* Set the end row. */
29432 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29434 /* Compute and set the end column and the end column's horizontal
29435 pixel coordinate. */
29436 if (!r
->reversed_p
)
29438 g
= r
->glyphs
[TEXT_AREA
];
29439 e
= g
+ r
->used
[TEXT_AREA
];
29440 for ( ; e
> g
; --e
)
29441 if (EQ ((e
-1)->object
, object
)
29442 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
29444 hlinfo
->mouse_face_end_col
= e
- g
;
29446 for (gx
= r
->x
; g
< e
; ++g
)
29447 gx
+= g
->pixel_width
;
29448 hlinfo
->mouse_face_end_x
= gx
;
29452 e
= r
->glyphs
[TEXT_AREA
];
29453 g
= e
+ r
->used
[TEXT_AREA
];
29454 for (gx
= r
->x
; e
< g
; ++e
)
29456 if (EQ (e
->object
, object
)
29457 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
29459 gx
+= e
->pixel_width
;
29461 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
29462 hlinfo
->mouse_face_end_x
= gx
;
29466 #ifdef HAVE_WINDOW_SYSTEM
29468 /* See if position X, Y is within a hot-spot of an image. */
29471 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
29473 if (!CONSP (hot_spot
))
29476 if (EQ (XCAR (hot_spot
), Qrect
))
29478 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
29479 Lisp_Object rect
= XCDR (hot_spot
);
29483 if (!CONSP (XCAR (rect
)))
29485 if (!CONSP (XCDR (rect
)))
29487 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
29489 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
29491 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
29493 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
29497 else if (EQ (XCAR (hot_spot
), Qcircle
))
29499 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
29500 Lisp_Object circ
= XCDR (hot_spot
);
29501 Lisp_Object lr
, lx0
, ly0
;
29503 && CONSP (XCAR (circ
))
29504 && (lr
= XCDR (circ
), NUMBERP (lr
))
29505 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
29506 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
29508 double r
= XFLOATINT (lr
);
29509 double dx
= XINT (lx0
) - x
;
29510 double dy
= XINT (ly0
) - y
;
29511 return (dx
* dx
+ dy
* dy
<= r
* r
);
29514 else if (EQ (XCAR (hot_spot
), Qpoly
))
29516 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
29517 if (VECTORP (XCDR (hot_spot
)))
29519 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
29520 Lisp_Object
*poly
= v
->contents
;
29521 ptrdiff_t n
= v
->header
.size
;
29523 bool inside
= false;
29524 Lisp_Object lx
, ly
;
29527 /* Need an even number of coordinates, and at least 3 edges. */
29528 if (n
< 6 || n
& 1)
29531 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
29532 If count is odd, we are inside polygon. Pixels on edges
29533 may or may not be included depending on actual geometry of the
29535 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
29536 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
29538 x0
= XINT (lx
), y0
= XINT (ly
);
29539 for (i
= 0; i
< n
; i
+= 2)
29541 int x1
= x0
, y1
= y0
;
29542 if ((lx
= poly
[i
], !INTEGERP (lx
))
29543 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
29545 x0
= XINT (lx
), y0
= XINT (ly
);
29547 /* Does this segment cross the X line? */
29555 if (y
> y0
&& y
> y1
)
29557 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
29567 find_hot_spot (Lisp_Object map
, int x
, int y
)
29569 while (CONSP (map
))
29571 if (CONSP (XCAR (map
))
29572 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
29580 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
29582 doc
: /* Lookup in image map MAP coordinates X and Y.
29583 An image map is an alist where each element has the format (AREA ID PLIST).
29584 An AREA is specified as either a rectangle, a circle, or a polygon:
29585 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
29586 pixel coordinates of the upper left and bottom right corners.
29587 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
29588 and the radius of the circle; r may be a float or integer.
29589 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
29590 vector describes one corner in the polygon.
29591 Returns the alist element for the first matching AREA in MAP. */)
29592 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
29600 return find_hot_spot (map
,
29601 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
29602 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
29606 /* Display frame CURSOR, optionally using shape defined by POINTER. */
29608 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
29610 /* Do not change cursor shape while dragging mouse. */
29611 if (EQ (do_mouse_tracking
, Qdragging
))
29614 if (!NILP (pointer
))
29616 if (EQ (pointer
, Qarrow
))
29617 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29618 else if (EQ (pointer
, Qhand
))
29619 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
29620 else if (EQ (pointer
, Qtext
))
29621 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
29622 else if (EQ (pointer
, intern ("hdrag")))
29623 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29624 else if (EQ (pointer
, intern ("nhdrag")))
29625 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
29626 #ifdef HAVE_X_WINDOWS
29627 else if (EQ (pointer
, intern ("vdrag")))
29628 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29630 else if (EQ (pointer
, intern ("hourglass")))
29631 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
29632 else if (EQ (pointer
, Qmodeline
))
29633 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
29635 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29638 if (cursor
!= No_Cursor
)
29639 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
29642 #endif /* HAVE_WINDOW_SYSTEM */
29644 /* Take proper action when mouse has moved to the mode or header line
29645 or marginal area AREA of window W, x-position X and y-position Y.
29646 X is relative to the start of the text display area of W, so the
29647 width of bitmap areas and scroll bars must be subtracted to get a
29648 position relative to the start of the mode line. */
29651 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
29652 enum window_part area
)
29654 struct window
*w
= XWINDOW (window
);
29655 struct frame
*f
= XFRAME (w
->frame
);
29656 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29657 #ifdef HAVE_WINDOW_SYSTEM
29658 Display_Info
*dpyinfo
;
29660 Cursor cursor
= No_Cursor
;
29661 Lisp_Object pointer
= Qnil
;
29662 int dx
, dy
, width
, height
;
29664 Lisp_Object string
, object
= Qnil
;
29665 Lisp_Object pos
IF_LINT (= Qnil
), help
;
29667 Lisp_Object mouse_face
;
29668 int original_x_pixel
= x
;
29669 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
29670 struct glyph_row
*row
IF_LINT (= 0);
29672 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
29677 /* Kludge alert: mode_line_string takes X/Y in pixels, but
29678 returns them in row/column units! */
29679 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
29680 &object
, &dx
, &dy
, &width
, &height
);
29682 row
= (area
== ON_MODE_LINE
29683 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
29684 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
29686 /* Find the glyph under the mouse pointer. */
29687 if (row
->mode_line_p
&& row
->enabled_p
)
29689 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
29690 end
= glyph
+ row
->used
[TEXT_AREA
];
29692 for (x0
= original_x_pixel
;
29693 glyph
< end
&& x0
>= glyph
->pixel_width
;
29695 x0
-= glyph
->pixel_width
;
29703 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
29704 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
29705 returns them in row/column units! */
29706 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
29707 &object
, &dx
, &dy
, &width
, &height
);
29712 #ifdef HAVE_WINDOW_SYSTEM
29713 if (IMAGEP (object
))
29715 Lisp_Object image_map
, hotspot
;
29716 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
29718 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
29720 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
29724 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
29725 If so, we could look for mouse-enter, mouse-leave
29726 properties in PLIST (and do something...). */
29727 hotspot
= XCDR (hotspot
);
29728 if (CONSP (hotspot
)
29729 && (plist
= XCAR (hotspot
), CONSP (plist
)))
29731 pointer
= Fplist_get (plist
, Qpointer
);
29732 if (NILP (pointer
))
29734 help
= Fplist_get (plist
, Qhelp_echo
);
29737 help_echo_string
= help
;
29738 XSETWINDOW (help_echo_window
, w
);
29739 help_echo_object
= w
->contents
;
29740 help_echo_pos
= charpos
;
29744 if (NILP (pointer
))
29745 pointer
= Fplist_get (XCDR (object
), QCpointer
);
29747 #endif /* HAVE_WINDOW_SYSTEM */
29749 if (STRINGP (string
))
29750 pos
= make_number (charpos
);
29752 /* Set the help text and mouse pointer. If the mouse is on a part
29753 of the mode line without any text (e.g. past the right edge of
29754 the mode line text), use the default help text and pointer. */
29755 if (STRINGP (string
) || area
== ON_MODE_LINE
)
29757 /* Arrange to display the help by setting the global variables
29758 help_echo_string, help_echo_object, and help_echo_pos. */
29761 if (STRINGP (string
))
29762 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
29766 help_echo_string
= help
;
29767 XSETWINDOW (help_echo_window
, w
);
29768 help_echo_object
= string
;
29769 help_echo_pos
= charpos
;
29771 else if (area
== ON_MODE_LINE
)
29773 Lisp_Object default_help
29774 = buffer_local_value (Qmode_line_default_help_echo
,
29777 if (STRINGP (default_help
))
29779 help_echo_string
= default_help
;
29780 XSETWINDOW (help_echo_window
, w
);
29781 help_echo_object
= Qnil
;
29782 help_echo_pos
= -1;
29787 #ifdef HAVE_WINDOW_SYSTEM
29788 /* Change the mouse pointer according to what is under it. */
29789 if (FRAME_WINDOW_P (f
))
29791 bool draggable
= (! WINDOW_BOTTOMMOST_P (w
)
29793 || NILP (Vresize_mini_windows
));
29795 dpyinfo
= FRAME_DISPLAY_INFO (f
);
29796 if (STRINGP (string
))
29798 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29800 if (NILP (pointer
))
29801 pointer
= Fget_text_property (pos
, Qpointer
, string
);
29803 /* Change the mouse pointer according to what is under X/Y. */
29805 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
29808 map
= Fget_text_property (pos
, Qlocal_map
, string
);
29809 if (!KEYMAPP (map
))
29810 map
= Fget_text_property (pos
, Qkeymap
, string
);
29811 if (!KEYMAPP (map
) && draggable
)
29812 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
29815 else if (draggable
)
29816 /* Default mode-line pointer. */
29817 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29822 /* Change the mouse face according to what is under X/Y. */
29823 bool mouse_face_shown
= false;
29824 if (STRINGP (string
))
29826 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
29827 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
29828 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
29833 struct glyph
* tmp_glyph
;
29837 int total_pixel_width
;
29838 ptrdiff_t begpos
, endpos
, ignore
;
29842 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
29843 Qmouse_face
, string
, Qnil
);
29849 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
29851 endpos
= SCHARS (string
);
29855 /* Calculate the glyph position GPOS of GLYPH in the
29856 displayed string, relative to the beginning of the
29857 highlighted part of the string.
29859 Note: GPOS is different from CHARPOS. CHARPOS is the
29860 position of GLYPH in the internal string object. A mode
29861 line string format has structures which are converted to
29862 a flattened string by the Emacs Lisp interpreter. The
29863 internal string is an element of those structures. The
29864 displayed string is the flattened string. */
29865 tmp_glyph
= row_start_glyph
;
29866 while (tmp_glyph
< glyph
29867 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29868 && begpos
<= tmp_glyph
->charpos
29869 && tmp_glyph
->charpos
< endpos
)))
29871 gpos
= glyph
- tmp_glyph
;
29873 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
29874 the highlighted part of the displayed string to which
29875 GLYPH belongs. Note: GSEQ_LENGTH is different from
29876 SCHARS (STRING), because the latter returns the length of
29877 the internal string. */
29878 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
29880 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29881 && begpos
<= tmp_glyph
->charpos
29882 && tmp_glyph
->charpos
< endpos
));
29885 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
29887 /* Calculate the total pixel width of all the glyphs between
29888 the beginning of the highlighted area and GLYPH. */
29889 total_pixel_width
= 0;
29890 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
29891 total_pixel_width
+= tmp_glyph
->pixel_width
;
29893 /* Pre calculation of re-rendering position. Note: X is in
29894 column units here, after the call to mode_line_string or
29895 marginal_area_string. */
29897 vpos
= (area
== ON_MODE_LINE
29898 ? (w
->current_matrix
)->nrows
- 1
29901 /* If GLYPH's position is included in the region that is
29902 already drawn in mouse face, we have nothing to do. */
29903 if ( EQ (window
, hlinfo
->mouse_face_window
)
29904 && (!row
->reversed_p
29905 ? (hlinfo
->mouse_face_beg_col
<= hpos
29906 && hpos
< hlinfo
->mouse_face_end_col
)
29907 /* In R2L rows we swap BEG and END, see below. */
29908 : (hlinfo
->mouse_face_end_col
<= hpos
29909 && hpos
< hlinfo
->mouse_face_beg_col
))
29910 && hlinfo
->mouse_face_beg_row
== vpos
)
29913 if (clear_mouse_face (hlinfo
))
29914 cursor
= No_Cursor
;
29916 if (!row
->reversed_p
)
29918 hlinfo
->mouse_face_beg_col
= hpos
;
29919 hlinfo
->mouse_face_beg_x
= original_x_pixel
29920 - (total_pixel_width
+ dx
);
29921 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
29922 hlinfo
->mouse_face_end_x
= 0;
29926 /* In R2L rows, show_mouse_face expects BEG and END
29927 coordinates to be swapped. */
29928 hlinfo
->mouse_face_end_col
= hpos
;
29929 hlinfo
->mouse_face_end_x
= original_x_pixel
29930 - (total_pixel_width
+ dx
);
29931 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
29932 hlinfo
->mouse_face_beg_x
= 0;
29935 hlinfo
->mouse_face_beg_row
= vpos
;
29936 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
29937 hlinfo
->mouse_face_past_end
= false;
29938 hlinfo
->mouse_face_window
= window
;
29940 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
29945 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29946 mouse_face_shown
= true;
29948 if (NILP (pointer
))
29953 /* If mouse-face doesn't need to be shown, clear any existing
29955 if ((area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
) && !mouse_face_shown
)
29956 clear_mouse_face (hlinfo
);
29958 #ifdef HAVE_WINDOW_SYSTEM
29959 if (FRAME_WINDOW_P (f
))
29960 define_frame_cursor1 (f
, cursor
, pointer
);
29966 Take proper action when the mouse has moved to position X, Y on
29967 frame F with regards to highlighting portions of display that have
29968 mouse-face properties. Also de-highlight portions of display where
29969 the mouse was before, set the mouse pointer shape as appropriate
29970 for the mouse coordinates, and activate help echo (tooltips).
29971 X and Y can be negative or out of range. */
29974 note_mouse_highlight (struct frame
*f
, int x
, int y
)
29976 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29977 enum window_part part
= ON_NOTHING
;
29978 Lisp_Object window
;
29980 Cursor cursor
= No_Cursor
;
29981 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
29984 /* When a menu is active, don't highlight because this looks odd. */
29985 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
29986 if (popup_activated ())
29990 if (!f
->glyphs_initialized_p
29991 || f
->pointer_invisible
)
29994 hlinfo
->mouse_face_mouse_x
= x
;
29995 hlinfo
->mouse_face_mouse_y
= y
;
29996 hlinfo
->mouse_face_mouse_frame
= f
;
29998 if (hlinfo
->mouse_face_defer
)
30001 /* Which window is that in? */
30002 window
= window_from_coordinates (f
, x
, y
, &part
, true);
30004 /* If displaying active text in another window, clear that. */
30005 if (! EQ (window
, hlinfo
->mouse_face_window
)
30006 /* Also clear if we move out of text area in same window. */
30007 || (!NILP (hlinfo
->mouse_face_window
)
30010 && part
!= ON_MODE_LINE
30011 && part
!= ON_HEADER_LINE
))
30012 clear_mouse_face (hlinfo
);
30014 /* Not on a window -> return. */
30015 if (!WINDOWP (window
))
30018 /* Reset help_echo_string. It will get recomputed below. */
30019 help_echo_string
= Qnil
;
30021 /* Convert to window-relative pixel coordinates. */
30022 w
= XWINDOW (window
);
30023 frame_to_window_pixel_xy (w
, &x
, &y
);
30025 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
30026 /* Handle tool-bar window differently since it doesn't display a
30028 if (EQ (window
, f
->tool_bar_window
))
30030 note_tool_bar_highlight (f
, x
, y
);
30035 /* Mouse is on the mode, header line or margin? */
30036 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
30037 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
30039 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
30041 #ifdef HAVE_WINDOW_SYSTEM
30042 if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
30044 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30045 /* Show non-text cursor (Bug#16647). */
30053 #ifdef HAVE_WINDOW_SYSTEM
30054 if (part
== ON_VERTICAL_BORDER
)
30056 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
30057 help_echo_string
= build_string ("drag-mouse-1: resize");
30059 else if (part
== ON_RIGHT_DIVIDER
)
30061 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
30062 help_echo_string
= build_string ("drag-mouse-1: resize");
30064 else if (part
== ON_BOTTOM_DIVIDER
)
30065 if (! WINDOW_BOTTOMMOST_P (w
)
30067 || NILP (Vresize_mini_windows
))
30069 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
30070 help_echo_string
= build_string ("drag-mouse-1: resize");
30073 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30074 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
30075 || part
== ON_VERTICAL_SCROLL_BAR
30076 || part
== ON_HORIZONTAL_SCROLL_BAR
)
30077 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30079 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
30082 /* Are we in a window whose display is up to date?
30083 And verify the buffer's text has not changed. */
30084 b
= XBUFFER (w
->contents
);
30085 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
30087 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
30089 struct glyph
*glyph
;
30090 Lisp_Object object
;
30091 Lisp_Object mouse_face
= Qnil
, position
;
30092 Lisp_Object
*overlay_vec
= NULL
;
30093 ptrdiff_t i
, noverlays
;
30094 struct buffer
*obuf
;
30095 ptrdiff_t obegv
, ozv
;
30098 /* Find the glyph under X/Y. */
30099 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
30101 #ifdef HAVE_WINDOW_SYSTEM
30102 /* Look for :pointer property on image. */
30103 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
30105 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
30106 if (img
!= NULL
&& IMAGEP (img
->spec
))
30108 Lisp_Object image_map
, hotspot
;
30109 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
30111 && (hotspot
= find_hot_spot (image_map
,
30112 glyph
->slice
.img
.x
+ dx
,
30113 glyph
->slice
.img
.y
+ dy
),
30115 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
30119 /* Could check XCAR (hotspot) to see if we enter/leave
30121 If so, we could look for mouse-enter, mouse-leave
30122 properties in PLIST (and do something...). */
30123 hotspot
= XCDR (hotspot
);
30124 if (CONSP (hotspot
)
30125 && (plist
= XCAR (hotspot
), CONSP (plist
)))
30127 pointer
= Fplist_get (plist
, Qpointer
);
30128 if (NILP (pointer
))
30130 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
30131 if (!NILP (help_echo_string
))
30133 help_echo_window
= window
;
30134 help_echo_object
= glyph
->object
;
30135 help_echo_pos
= glyph
->charpos
;
30139 if (NILP (pointer
))
30140 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
30143 #endif /* HAVE_WINDOW_SYSTEM */
30145 /* Clear mouse face if X/Y not over text. */
30147 || area
!= TEXT_AREA
30148 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
30149 /* Glyph's OBJECT is nil for glyphs inserted by the
30150 display engine for its internal purposes, like truncation
30151 and continuation glyphs and blanks beyond the end of
30152 line's text on text terminals. If we are over such a
30153 glyph, we are not over any text. */
30154 || NILP (glyph
->object
)
30155 /* R2L rows have a stretch glyph at their front, which
30156 stands for no text, whereas L2R rows have no glyphs at
30157 all beyond the end of text. Treat such stretch glyphs
30158 like we do with NULL glyphs in L2R rows. */
30159 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
30160 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
30161 && glyph
->type
== STRETCH_GLYPH
30162 && glyph
->avoid_cursor_p
))
30164 if (clear_mouse_face (hlinfo
))
30165 cursor
= No_Cursor
;
30166 #ifdef HAVE_WINDOW_SYSTEM
30167 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
30169 if (area
!= TEXT_AREA
)
30170 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30172 pointer
= Vvoid_text_area_pointer
;
30178 pos
= glyph
->charpos
;
30179 object
= glyph
->object
;
30180 if (!STRINGP (object
) && !BUFFERP (object
))
30183 /* If we get an out-of-range value, return now; avoid an error. */
30184 if (BUFFERP (object
) && pos
> BUF_Z (b
))
30187 /* Make the window's buffer temporarily current for
30188 overlays_at and compute_char_face. */
30189 obuf
= current_buffer
;
30190 current_buffer
= b
;
30196 /* Is this char mouse-active or does it have help-echo? */
30197 position
= make_number (pos
);
30201 if (BUFFERP (object
))
30203 /* Put all the overlays we want in a vector in overlay_vec. */
30204 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, false);
30205 /* Sort overlays into increasing priority order. */
30206 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
30211 if (NILP (Vmouse_highlight
))
30213 clear_mouse_face (hlinfo
);
30214 goto check_help_echo
;
30217 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
30220 cursor
= No_Cursor
;
30222 /* Check mouse-face highlighting. */
30224 /* If there exists an overlay with mouse-face overlapping
30225 the one we are currently highlighting, we have to
30226 check if we enter the overlapping overlay, and then
30227 highlight only that. */
30228 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
30229 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
30231 /* Find the highest priority overlay with a mouse-face. */
30232 Lisp_Object overlay
= Qnil
;
30233 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
30235 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
30236 if (!NILP (mouse_face
))
30237 overlay
= overlay_vec
[i
];
30240 /* If we're highlighting the same overlay as before, there's
30241 no need to do that again. */
30242 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
30243 goto check_help_echo
;
30244 hlinfo
->mouse_face_overlay
= overlay
;
30246 /* Clear the display of the old active region, if any. */
30247 if (clear_mouse_face (hlinfo
))
30248 cursor
= No_Cursor
;
30250 /* If no overlay applies, get a text property. */
30251 if (NILP (overlay
))
30252 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
30254 /* Next, compute the bounds of the mouse highlighting and
30256 if (!NILP (mouse_face
) && STRINGP (object
))
30258 /* The mouse-highlighting comes from a display string
30259 with a mouse-face. */
30263 s
= Fprevious_single_property_change
30264 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
30265 e
= Fnext_single_property_change
30266 (position
, Qmouse_face
, object
, Qnil
);
30268 s
= make_number (0);
30270 e
= make_number (SCHARS (object
));
30271 mouse_face_from_string_pos (w
, hlinfo
, object
,
30272 XINT (s
), XINT (e
));
30273 hlinfo
->mouse_face_past_end
= false;
30274 hlinfo
->mouse_face_window
= window
;
30275 hlinfo
->mouse_face_face_id
30276 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
30277 glyph
->face_id
, true);
30278 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
30279 cursor
= No_Cursor
;
30283 /* The mouse-highlighting, if any, comes from an overlay
30284 or text property in the buffer. */
30285 Lisp_Object buffer
IF_LINT (= Qnil
);
30286 Lisp_Object disp_string
IF_LINT (= Qnil
);
30288 if (STRINGP (object
))
30290 /* If we are on a display string with no mouse-face,
30291 check if the text under it has one. */
30292 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
30293 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30294 pos
= string_buffer_position (object
, start
);
30297 mouse_face
= get_char_property_and_overlay
30298 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
30299 buffer
= w
->contents
;
30300 disp_string
= object
;
30306 disp_string
= Qnil
;
30309 if (!NILP (mouse_face
))
30311 Lisp_Object before
, after
;
30312 Lisp_Object before_string
, after_string
;
30313 /* To correctly find the limits of mouse highlight
30314 in a bidi-reordered buffer, we must not use the
30315 optimization of limiting the search in
30316 previous-single-property-change and
30317 next-single-property-change, because
30318 rows_from_pos_range needs the real start and end
30319 positions to DTRT in this case. That's because
30320 the first row visible in a window does not
30321 necessarily display the character whose position
30322 is the smallest. */
30324 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
30325 ? Fmarker_position (w
->start
)
30328 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
30329 ? make_number (BUF_Z (XBUFFER (buffer
))
30330 - w
->window_end_pos
)
30333 if (NILP (overlay
))
30335 /* Handle the text property case. */
30336 before
= Fprevious_single_property_change
30337 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
30338 after
= Fnext_single_property_change
30339 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
30340 before_string
= after_string
= Qnil
;
30344 /* Handle the overlay case. */
30345 before
= Foverlay_start (overlay
);
30346 after
= Foverlay_end (overlay
);
30347 before_string
= Foverlay_get (overlay
, Qbefore_string
);
30348 after_string
= Foverlay_get (overlay
, Qafter_string
);
30350 if (!STRINGP (before_string
)) before_string
= Qnil
;
30351 if (!STRINGP (after_string
)) after_string
= Qnil
;
30354 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
30357 : XFASTINT (before
),
30359 ? BUF_Z (XBUFFER (buffer
))
30360 : XFASTINT (after
),
30361 before_string
, after_string
,
30363 cursor
= No_Cursor
;
30370 /* Look for a `help-echo' property. */
30371 if (NILP (help_echo_string
)) {
30372 Lisp_Object help
, overlay
;
30374 /* Check overlays first. */
30375 help
= overlay
= Qnil
;
30376 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
30378 overlay
= overlay_vec
[i
];
30379 help
= Foverlay_get (overlay
, Qhelp_echo
);
30384 help_echo_string
= help
;
30385 help_echo_window
= window
;
30386 help_echo_object
= overlay
;
30387 help_echo_pos
= pos
;
30391 Lisp_Object obj
= glyph
->object
;
30392 ptrdiff_t charpos
= glyph
->charpos
;
30394 /* Try text properties. */
30397 && charpos
< SCHARS (obj
))
30399 help
= Fget_text_property (make_number (charpos
),
30403 /* If the string itself doesn't specify a help-echo,
30404 see if the buffer text ``under'' it does. */
30405 struct glyph_row
*r
30406 = MATRIX_ROW (w
->current_matrix
, vpos
);
30407 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30408 ptrdiff_t p
= string_buffer_position (obj
, start
);
30411 help
= Fget_char_property (make_number (p
),
30412 Qhelp_echo
, w
->contents
);
30421 else if (BUFFERP (obj
)
30424 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
30429 help_echo_string
= help
;
30430 help_echo_window
= window
;
30431 help_echo_object
= obj
;
30432 help_echo_pos
= charpos
;
30437 #ifdef HAVE_WINDOW_SYSTEM
30438 /* Look for a `pointer' property. */
30439 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
30441 /* Check overlays first. */
30442 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
30443 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
30445 if (NILP (pointer
))
30447 Lisp_Object obj
= glyph
->object
;
30448 ptrdiff_t charpos
= glyph
->charpos
;
30450 /* Try text properties. */
30453 && charpos
< SCHARS (obj
))
30455 pointer
= Fget_text_property (make_number (charpos
),
30457 if (NILP (pointer
))
30459 /* If the string itself doesn't specify a pointer,
30460 see if the buffer text ``under'' it does. */
30461 struct glyph_row
*r
30462 = MATRIX_ROW (w
->current_matrix
, vpos
);
30463 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30464 ptrdiff_t p
= string_buffer_position (obj
, start
);
30466 pointer
= Fget_char_property (make_number (p
),
30467 Qpointer
, w
->contents
);
30470 else if (BUFFERP (obj
)
30473 pointer
= Fget_text_property (make_number (charpos
),
30477 #endif /* HAVE_WINDOW_SYSTEM */
30481 current_buffer
= obuf
;
30487 #ifdef HAVE_WINDOW_SYSTEM
30488 if (FRAME_WINDOW_P (f
))
30489 define_frame_cursor1 (f
, cursor
, pointer
);
30491 /* This is here to prevent a compiler error, about "label at end of
30492 compound statement". */
30499 Clear any mouse-face on window W. This function is part of the
30500 redisplay interface, and is called from try_window_id and similar
30501 functions to ensure the mouse-highlight is off. */
30504 x_clear_window_mouse_face (struct window
*w
)
30506 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
30507 Lisp_Object window
;
30510 XSETWINDOW (window
, w
);
30511 if (EQ (window
, hlinfo
->mouse_face_window
))
30512 clear_mouse_face (hlinfo
);
30518 Just discard the mouse face information for frame F, if any.
30519 This is used when the size of F is changed. */
30522 cancel_mouse_face (struct frame
*f
)
30524 Lisp_Object window
;
30525 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
30527 window
= hlinfo
->mouse_face_window
;
30528 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
30529 reset_mouse_highlight (hlinfo
);
30534 /***********************************************************************
30536 ***********************************************************************/
30538 #ifdef HAVE_WINDOW_SYSTEM
30540 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
30541 which intersects rectangle R. R is in window-relative coordinates. */
30544 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
30545 enum glyph_row_area area
)
30547 struct glyph
*first
= row
->glyphs
[area
];
30548 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
30549 struct glyph
*last
;
30550 int first_x
, start_x
, x
;
30552 if (area
== TEXT_AREA
&& row
->fill_line_p
)
30553 /* If row extends face to end of line write the whole line. */
30554 draw_glyphs (w
, 0, row
, area
,
30555 0, row
->used
[area
],
30556 DRAW_NORMAL_TEXT
, 0);
30559 /* Set START_X to the window-relative start position for drawing glyphs of
30560 AREA. The first glyph of the text area can be partially visible.
30561 The first glyphs of other areas cannot. */
30562 start_x
= window_box_left_offset (w
, area
);
30564 if (area
== TEXT_AREA
)
30567 /* Find the first glyph that must be redrawn. */
30569 && x
+ first
->pixel_width
< r
->x
)
30571 x
+= first
->pixel_width
;
30575 /* Find the last one. */
30578 /* Use a signed int intermediate value to avoid catastrophic
30579 failures due to comparison between signed and unsigned, when
30580 x is negative (can happen for wide images that are hscrolled). */
30581 int r_end
= r
->x
+ r
->width
;
30582 while (last
< end
&& x
< r_end
)
30584 x
+= last
->pixel_width
;
30590 draw_glyphs (w
, first_x
- start_x
, row
, area
,
30591 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
30592 DRAW_NORMAL_TEXT
, 0);
30597 /* Redraw the parts of the glyph row ROW on window W intersecting
30598 rectangle R. R is in window-relative coordinates. Value is
30599 true if mouse-face was overwritten. */
30602 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
30604 eassert (row
->enabled_p
);
30606 if (row
->mode_line_p
|| w
->pseudo_window_p
)
30607 draw_glyphs (w
, 0, row
, TEXT_AREA
,
30608 0, row
->used
[TEXT_AREA
],
30609 DRAW_NORMAL_TEXT
, 0);
30612 if (row
->used
[LEFT_MARGIN_AREA
])
30613 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
30614 if (row
->used
[TEXT_AREA
])
30615 expose_area (w
, row
, r
, TEXT_AREA
);
30616 if (row
->used
[RIGHT_MARGIN_AREA
])
30617 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
30618 draw_row_fringe_bitmaps (w
, row
);
30621 return row
->mouse_face_p
;
30625 /* Redraw those parts of glyphs rows during expose event handling that
30626 overlap other rows. Redrawing of an exposed line writes over parts
30627 of lines overlapping that exposed line; this function fixes that.
30629 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
30630 row in W's current matrix that is exposed and overlaps other rows.
30631 LAST_OVERLAPPING_ROW is the last such row. */
30634 expose_overlaps (struct window
*w
,
30635 struct glyph_row
*first_overlapping_row
,
30636 struct glyph_row
*last_overlapping_row
,
30639 struct glyph_row
*row
;
30641 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
30642 if (row
->overlapping_p
)
30644 eassert (row
->enabled_p
&& !row
->mode_line_p
);
30647 if (row
->used
[LEFT_MARGIN_AREA
])
30648 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
30650 if (row
->used
[TEXT_AREA
])
30651 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
30653 if (row
->used
[RIGHT_MARGIN_AREA
])
30654 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
30660 /* Return true if W's cursor intersects rectangle R. */
30663 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
30665 XRectangle cr
, result
;
30666 struct glyph
*cursor_glyph
;
30667 struct glyph_row
*row
;
30669 if (w
->phys_cursor
.vpos
>= 0
30670 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
30671 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
30673 && row
->cursor_in_fringe_p
)
30675 /* Cursor is in the fringe. */
30676 cr
.x
= window_box_right_offset (w
,
30677 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
30678 ? RIGHT_MARGIN_AREA
30681 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
30682 cr
.height
= row
->height
;
30683 return x_intersect_rectangles (&cr
, r
, &result
);
30686 cursor_glyph
= get_phys_cursor_glyph (w
);
30689 /* r is relative to W's box, but w->phys_cursor.x is relative
30690 to left edge of W's TEXT area. Adjust it. */
30691 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
30692 cr
.y
= w
->phys_cursor
.y
;
30693 cr
.width
= cursor_glyph
->pixel_width
;
30694 cr
.height
= w
->phys_cursor_height
;
30695 /* ++KFS: W32 version used W32-specific IntersectRect here, but
30696 I assume the effect is the same -- and this is portable. */
30697 return x_intersect_rectangles (&cr
, r
, &result
);
30699 /* If we don't understand the format, pretend we're not in the hot-spot. */
30705 Draw a vertical window border to the right of window W if W doesn't
30706 have vertical scroll bars. */
30709 x_draw_vertical_border (struct window
*w
)
30711 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30713 /* We could do better, if we knew what type of scroll-bar the adjacent
30714 windows (on either side) have... But we don't :-(
30715 However, I think this works ok. ++KFS 2003-04-25 */
30717 /* Redraw borders between horizontally adjacent windows. Don't
30718 do it for frames with vertical scroll bars because either the
30719 right scroll bar of a window, or the left scroll bar of its
30720 neighbor will suffice as a border. */
30721 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
30724 /* Note: It is necessary to redraw both the left and the right
30725 borders, for when only this single window W is being
30727 if (!WINDOW_RIGHTMOST_P (w
)
30728 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
30730 int x0
, x1
, y0
, y1
;
30732 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30735 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30738 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
30741 if (!WINDOW_LEFTMOST_P (w
)
30742 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
30744 int x0
, x1
, y0
, y1
;
30746 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30749 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30752 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
30757 /* Draw window dividers for window W. */
30760 x_draw_right_divider (struct window
*w
)
30762 struct frame
*f
= WINDOW_XFRAME (w
);
30764 if (w
->mini
|| w
->pseudo_window_p
)
30766 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30768 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
30769 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30770 int y0
= WINDOW_TOP_EDGE_Y (w
);
30771 /* The bottom divider prevails. */
30772 int y1
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30774 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30779 x_draw_bottom_divider (struct window
*w
)
30781 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30783 if (w
->mini
|| w
->pseudo_window_p
)
30785 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30787 int x0
= WINDOW_LEFT_EDGE_X (w
);
30788 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30789 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30790 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
30792 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30796 /* Redraw the part of window W intersection rectangle FR. Pixel
30797 coordinates in FR are frame-relative. Call this function with
30798 input blocked. Value is true if the exposure overwrites
30802 expose_window (struct window
*w
, XRectangle
*fr
)
30804 struct frame
*f
= XFRAME (w
->frame
);
30806 bool mouse_face_overwritten_p
= false;
30808 /* If window is not yet fully initialized, do nothing. This can
30809 happen when toolkit scroll bars are used and a window is split.
30810 Reconfiguring the scroll bar will generate an expose for a newly
30812 if (w
->current_matrix
== NULL
)
30815 /* When we're currently updating the window, display and current
30816 matrix usually don't agree. Arrange for a thorough display
30818 if (w
->must_be_updated_p
)
30820 SET_FRAME_GARBAGED (f
);
30824 /* Frame-relative pixel rectangle of W. */
30825 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
30826 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
30827 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
30828 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
30830 if (x_intersect_rectangles (fr
, &wr
, &r
))
30832 int yb
= window_text_bottom_y (w
);
30833 struct glyph_row
*row
;
30834 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
30836 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
30837 r
.x
, r
.y
, r
.width
, r
.height
));
30839 /* Convert to window coordinates. */
30840 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
30841 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
30843 /* Turn off the cursor. */
30844 bool cursor_cleared_p
= (!w
->pseudo_window_p
30845 && phys_cursor_in_rect_p (w
, &r
));
30846 if (cursor_cleared_p
)
30847 x_clear_cursor (w
);
30849 /* If the row containing the cursor extends face to end of line,
30850 then expose_area might overwrite the cursor outside the
30851 rectangle and thus notice_overwritten_cursor might clear
30852 w->phys_cursor_on_p. We remember the original value and
30853 check later if it is changed. */
30854 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
30856 /* Use a signed int intermediate value to avoid catastrophic
30857 failures due to comparison between signed and unsigned, when
30858 y0 or y1 is negative (can happen for tall images). */
30859 int r_bottom
= r
.y
+ r
.height
;
30861 /* Update lines intersecting rectangle R. */
30862 first_overlapping_row
= last_overlapping_row
= NULL
;
30863 for (row
= w
->current_matrix
->rows
;
30868 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
30870 if ((y0
>= r
.y
&& y0
< r_bottom
)
30871 || (y1
> r
.y
&& y1
< r_bottom
)
30872 || (r
.y
>= y0
&& r
.y
< y1
)
30873 || (r_bottom
> y0
&& r_bottom
< y1
))
30875 /* A header line may be overlapping, but there is no need
30876 to fix overlapping areas for them. KFS 2005-02-12 */
30877 if (row
->overlapping_p
&& !row
->mode_line_p
)
30879 if (first_overlapping_row
== NULL
)
30880 first_overlapping_row
= row
;
30881 last_overlapping_row
= row
;
30885 if (expose_line (w
, row
, &r
))
30886 mouse_face_overwritten_p
= true;
30889 else if (row
->overlapping_p
)
30891 /* We must redraw a row overlapping the exposed area. */
30893 ? y0
+ row
->phys_height
> r
.y
30894 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
30896 if (first_overlapping_row
== NULL
)
30897 first_overlapping_row
= row
;
30898 last_overlapping_row
= row
;
30906 /* Display the mode line if there is one. */
30907 if (WINDOW_WANTS_MODELINE_P (w
)
30908 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
30910 && row
->y
< r_bottom
)
30912 if (expose_line (w
, row
, &r
))
30913 mouse_face_overwritten_p
= true;
30916 if (!w
->pseudo_window_p
)
30918 /* Fix the display of overlapping rows. */
30919 if (first_overlapping_row
)
30920 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
30923 /* Draw border between windows. */
30924 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30925 x_draw_right_divider (w
);
30927 x_draw_vertical_border (w
);
30929 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30930 x_draw_bottom_divider (w
);
30932 /* Turn the cursor on again. */
30933 if (cursor_cleared_p
30934 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
30935 update_window_cursor (w
, true);
30939 return mouse_face_overwritten_p
;
30944 /* Redraw (parts) of all windows in the window tree rooted at W that
30945 intersect R. R contains frame pixel coordinates. Value is
30946 true if the exposure overwrites mouse-face. */
30949 expose_window_tree (struct window
*w
, XRectangle
*r
)
30951 struct frame
*f
= XFRAME (w
->frame
);
30952 bool mouse_face_overwritten_p
= false;
30954 while (w
&& !FRAME_GARBAGED_P (f
))
30956 mouse_face_overwritten_p
30957 |= (WINDOWP (w
->contents
)
30958 ? expose_window_tree (XWINDOW (w
->contents
), r
)
30959 : expose_window (w
, r
));
30961 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
30964 return mouse_face_overwritten_p
;
30969 Redisplay an exposed area of frame F. X and Y are the upper-left
30970 corner of the exposed rectangle. W and H are width and height of
30971 the exposed area. All are pixel values. W or H zero means redraw
30972 the entire frame. */
30975 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
30978 bool mouse_face_overwritten_p
= false;
30980 TRACE ((stderr
, "expose_frame "));
30982 /* No need to redraw if frame will be redrawn soon. */
30983 if (FRAME_GARBAGED_P (f
))
30985 TRACE ((stderr
, " garbaged\n"));
30989 /* If basic faces haven't been realized yet, there is no point in
30990 trying to redraw anything. This can happen when we get an expose
30991 event while Emacs is starting, e.g. by moving another window. */
30992 if (FRAME_FACE_CACHE (f
) == NULL
30993 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
30995 TRACE ((stderr
, " no faces\n"));
30999 if (w
== 0 || h
== 0)
31002 r
.width
= FRAME_TEXT_WIDTH (f
);
31003 r
.height
= FRAME_TEXT_HEIGHT (f
);
31013 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
31014 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
31016 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
31017 if (WINDOWP (f
->tool_bar_window
))
31018 mouse_face_overwritten_p
31019 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
31022 #ifdef HAVE_X_WINDOWS
31024 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
31025 if (WINDOWP (f
->menu_bar_window
))
31026 mouse_face_overwritten_p
31027 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
31028 #endif /* not USE_X_TOOLKIT and not USE_GTK */
31032 /* Some window managers support a focus-follows-mouse style with
31033 delayed raising of frames. Imagine a partially obscured frame,
31034 and moving the mouse into partially obscured mouse-face on that
31035 frame. The visible part of the mouse-face will be highlighted,
31036 then the WM raises the obscured frame. With at least one WM, KDE
31037 2.1, Emacs is not getting any event for the raising of the frame
31038 (even tried with SubstructureRedirectMask), only Expose events.
31039 These expose events will draw text normally, i.e. not
31040 highlighted. Which means we must redo the highlight here.
31041 Subsume it under ``we love X''. --gerd 2001-08-15 */
31042 /* Included in Windows version because Windows most likely does not
31043 do the right thing if any third party tool offers
31044 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
31045 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
31047 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
31048 if (f
== hlinfo
->mouse_face_mouse_frame
)
31050 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
31051 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
31052 clear_mouse_face (hlinfo
);
31053 note_mouse_highlight (f
, mouse_x
, mouse_y
);
31060 Determine the intersection of two rectangles R1 and R2. Return
31061 the intersection in *RESULT. Value is true if RESULT is not
31065 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
31067 XRectangle
*left
, *right
;
31068 XRectangle
*upper
, *lower
;
31069 bool intersection_p
= false;
31071 /* Rearrange so that R1 is the left-most rectangle. */
31073 left
= r1
, right
= r2
;
31075 left
= r2
, right
= r1
;
31077 /* X0 of the intersection is right.x0, if this is inside R1,
31078 otherwise there is no intersection. */
31079 if (right
->x
<= left
->x
+ left
->width
)
31081 result
->x
= right
->x
;
31083 /* The right end of the intersection is the minimum of
31084 the right ends of left and right. */
31085 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
31088 /* Same game for Y. */
31090 upper
= r1
, lower
= r2
;
31092 upper
= r2
, lower
= r1
;
31094 /* The upper end of the intersection is lower.y0, if this is inside
31095 of upper. Otherwise, there is no intersection. */
31096 if (lower
->y
<= upper
->y
+ upper
->height
)
31098 result
->y
= lower
->y
;
31100 /* The lower end of the intersection is the minimum of the lower
31101 ends of upper and lower. */
31102 result
->height
= (min (lower
->y
+ lower
->height
,
31103 upper
->y
+ upper
->height
)
31105 intersection_p
= true;
31109 return intersection_p
;
31112 #endif /* HAVE_WINDOW_SYSTEM */
31115 /***********************************************************************
31117 ***********************************************************************/
31120 syms_of_xdisp (void)
31122 Vwith_echo_area_save_vector
= Qnil
;
31123 staticpro (&Vwith_echo_area_save_vector
);
31125 Vmessage_stack
= Qnil
;
31126 staticpro (&Vmessage_stack
);
31128 /* Non-nil means don't actually do any redisplay. */
31129 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
31131 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
31133 DEFVAR_BOOL("inhibit-message", inhibit_message
,
31134 doc
: /* Non-nil means calls to `message' are not displayed.
31135 They are still logged to the *Messages* buffer. */);
31136 inhibit_message
= 0;
31138 message_dolog_marker1
= Fmake_marker ();
31139 staticpro (&message_dolog_marker1
);
31140 message_dolog_marker2
= Fmake_marker ();
31141 staticpro (&message_dolog_marker2
);
31142 message_dolog_marker3
= Fmake_marker ();
31143 staticpro (&message_dolog_marker3
);
31146 defsubr (&Sdump_frame_glyph_matrix
);
31147 defsubr (&Sdump_glyph_matrix
);
31148 defsubr (&Sdump_glyph_row
);
31149 defsubr (&Sdump_tool_bar_row
);
31150 defsubr (&Strace_redisplay
);
31151 defsubr (&Strace_to_stderr
);
31153 #ifdef HAVE_WINDOW_SYSTEM
31154 defsubr (&Stool_bar_height
);
31155 defsubr (&Slookup_image_map
);
31157 defsubr (&Sline_pixel_height
);
31158 defsubr (&Sformat_mode_line
);
31159 defsubr (&Sinvisible_p
);
31160 defsubr (&Scurrent_bidi_paragraph_direction
);
31161 defsubr (&Swindow_text_pixel_size
);
31162 defsubr (&Smove_point_visually
);
31163 defsubr (&Sbidi_find_overridden_directionality
);
31165 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
31166 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
31167 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
31168 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
31169 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
31170 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
31171 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
31172 DEFSYM (Qeval
, "eval");
31173 DEFSYM (QCdata
, ":data");
31175 /* Names of text properties relevant for redisplay. */
31176 DEFSYM (Qdisplay
, "display");
31177 DEFSYM (Qspace_width
, "space-width");
31178 DEFSYM (Qraise
, "raise");
31179 DEFSYM (Qslice
, "slice");
31180 DEFSYM (Qspace
, "space");
31181 DEFSYM (Qmargin
, "margin");
31182 DEFSYM (Qpointer
, "pointer");
31183 DEFSYM (Qleft_margin
, "left-margin");
31184 DEFSYM (Qright_margin
, "right-margin");
31185 DEFSYM (Qcenter
, "center");
31186 DEFSYM (Qline_height
, "line-height");
31187 DEFSYM (QCalign_to
, ":align-to");
31188 DEFSYM (QCrelative_width
, ":relative-width");
31189 DEFSYM (QCrelative_height
, ":relative-height");
31190 DEFSYM (QCeval
, ":eval");
31191 DEFSYM (QCpropertize
, ":propertize");
31192 DEFSYM (QCfile
, ":file");
31193 DEFSYM (Qfontified
, "fontified");
31194 DEFSYM (Qfontification_functions
, "fontification-functions");
31196 /* Name of the face used to highlight trailing whitespace. */
31197 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
31199 /* Name and number of the face used to highlight escape glyphs. */
31200 DEFSYM (Qescape_glyph
, "escape-glyph");
31202 /* Name and number of the face used to highlight non-breaking spaces. */
31203 DEFSYM (Qnobreak_space
, "nobreak-space");
31205 /* The symbol 'image' which is the car of the lists used to represent
31206 images in Lisp. Also a tool bar style. */
31207 DEFSYM (Qimage
, "image");
31209 /* Tool bar styles. */
31210 DEFSYM (Qtext
, "text");
31211 DEFSYM (Qboth
, "both");
31212 DEFSYM (Qboth_horiz
, "both-horiz");
31213 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
31215 /* The image map types. */
31216 DEFSYM (QCmap
, ":map");
31217 DEFSYM (QCpointer
, ":pointer");
31218 DEFSYM (Qrect
, "rect");
31219 DEFSYM (Qcircle
, "circle");
31220 DEFSYM (Qpoly
, "poly");
31222 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
31224 DEFSYM (Qgrow_only
, "grow-only");
31225 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
31226 DEFSYM (Qposition
, "position");
31227 DEFSYM (Qbuffer_position
, "buffer-position");
31228 DEFSYM (Qobject
, "object");
31230 /* Cursor shapes. */
31231 DEFSYM (Qbar
, "bar");
31232 DEFSYM (Qhbar
, "hbar");
31233 DEFSYM (Qbox
, "box");
31234 DEFSYM (Qhollow
, "hollow");
31236 /* Pointer shapes. */
31237 DEFSYM (Qhand
, "hand");
31238 DEFSYM (Qarrow
, "arrow");
31241 DEFSYM (Qdragging
, "dragging");
31243 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
31245 list_of_error
= list1 (list2 (Qerror
, Qvoid_variable
));
31246 staticpro (&list_of_error
);
31248 /* Values of those variables at last redisplay are stored as
31249 properties on 'overlay-arrow-position' symbol. However, if
31250 Voverlay_arrow_position is a marker, last-arrow-position is its
31251 numerical position. */
31252 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
31253 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
31255 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
31256 properties on a symbol in overlay-arrow-variable-list. */
31257 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
31258 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
31260 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
31261 staticpro (&echo_buffer
[0]);
31262 staticpro (&echo_buffer
[1]);
31264 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
31265 staticpro (&echo_area_buffer
[0]);
31266 staticpro (&echo_area_buffer
[1]);
31268 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
31269 staticpro (&Vmessages_buffer_name
);
31271 mode_line_proptrans_alist
= Qnil
;
31272 staticpro (&mode_line_proptrans_alist
);
31273 mode_line_string_list
= Qnil
;
31274 staticpro (&mode_line_string_list
);
31275 mode_line_string_face
= Qnil
;
31276 staticpro (&mode_line_string_face
);
31277 mode_line_string_face_prop
= Qnil
;
31278 staticpro (&mode_line_string_face_prop
);
31279 Vmode_line_unwind_vector
= Qnil
;
31280 staticpro (&Vmode_line_unwind_vector
);
31282 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
31284 help_echo_string
= Qnil
;
31285 staticpro (&help_echo_string
);
31286 help_echo_object
= Qnil
;
31287 staticpro (&help_echo_object
);
31288 help_echo_window
= Qnil
;
31289 staticpro (&help_echo_window
);
31290 previous_help_echo_string
= Qnil
;
31291 staticpro (&previous_help_echo_string
);
31292 help_echo_pos
= -1;
31294 DEFSYM (Qright_to_left
, "right-to-left");
31295 DEFSYM (Qleft_to_right
, "left-to-right");
31296 defsubr (&Sbidi_resolved_levels
);
31298 #ifdef HAVE_WINDOW_SYSTEM
31299 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
31300 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
31301 For example, if a block cursor is over a tab, it will be drawn as
31302 wide as that tab on the display. */);
31303 x_stretch_cursor_p
= 0;
31306 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
31307 doc
: /* Non-nil means highlight trailing whitespace.
31308 The face used for trailing whitespace is `trailing-whitespace'. */);
31309 Vshow_trailing_whitespace
= Qnil
;
31311 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
31312 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
31313 If the value is t, Emacs highlights non-ASCII chars which have the
31314 same appearance as an ASCII space or hyphen, using the `nobreak-space'
31315 or `escape-glyph' face respectively.
31317 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
31318 U+2011 (non-breaking hyphen) are affected.
31320 Any other non-nil value means to display these characters as a escape
31321 glyph followed by an ordinary space or hyphen.
31323 A value of nil means no special handling of these characters. */);
31324 Vnobreak_char_display
= Qt
;
31326 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
31327 doc
: /* The pointer shape to show in void text areas.
31328 A value of nil means to show the text pointer. Other options are
31329 `arrow', `text', `hand', `vdrag', `hdrag', `nhdrag', `modeline', and
31331 Vvoid_text_area_pointer
= Qarrow
;
31333 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
31334 doc
: /* Non-nil means don't actually do any redisplay.
31335 This is used for internal purposes. */);
31336 Vinhibit_redisplay
= Qnil
;
31338 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
31339 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
31340 Vglobal_mode_string
= Qnil
;
31342 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
31343 doc
: /* Marker for where to display an arrow on top of the buffer text.
31344 This must be the beginning of a line in order to work.
31345 See also `overlay-arrow-string'. */);
31346 Voverlay_arrow_position
= Qnil
;
31348 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
31349 doc
: /* String to display as an arrow in non-window frames.
31350 See also `overlay-arrow-position'. */);
31351 Voverlay_arrow_string
= build_pure_c_string ("=>");
31353 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
31354 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
31355 The symbols on this list are examined during redisplay to determine
31356 where to display overlay arrows. */);
31357 Voverlay_arrow_variable_list
31358 = list1 (intern_c_string ("overlay-arrow-position"));
31360 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
31361 doc
: /* The number of lines to try scrolling a window by when point moves out.
31362 If that fails to bring point back on frame, point is centered instead.
31363 If this is zero, point is always centered after it moves off frame.
31364 If you want scrolling to always be a line at a time, you should set
31365 `scroll-conservatively' to a large value rather than set this to 1. */);
31367 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
31368 doc
: /* Scroll up to this many lines, to bring point back on screen.
31369 If point moves off-screen, redisplay will scroll by up to
31370 `scroll-conservatively' lines in order to bring point just barely
31371 onto the screen again. If that cannot be done, then redisplay
31372 recenters point as usual.
31374 If the value is greater than 100, redisplay will never recenter point,
31375 but will always scroll just enough text to bring point into view, even
31376 if you move far away.
31378 A value of zero means always recenter point if it moves off screen. */);
31379 scroll_conservatively
= 0;
31381 DEFVAR_INT ("scroll-margin", scroll_margin
,
31382 doc
: /* Number of lines of margin at the top and bottom of a window.
31383 Recenter the window whenever point gets within this many lines
31384 of the top or bottom of the window. */);
31387 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
31388 doc
: /* Pixels per inch value for non-window system displays.
31389 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
31390 Vdisplay_pixels_per_inch
= make_float (72.0);
31393 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
31396 DEFVAR_LISP ("truncate-partial-width-windows",
31397 Vtruncate_partial_width_windows
,
31398 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
31399 For an integer value, truncate lines in each window narrower than the
31400 full frame width, provided the window width is less than that integer;
31401 otherwise, respect the value of `truncate-lines'.
31403 For any other non-nil value, truncate lines in all windows that do
31404 not span the full frame width.
31406 A value of nil means to respect the value of `truncate-lines'.
31408 If `word-wrap' is enabled, you might want to reduce this. */);
31409 Vtruncate_partial_width_windows
= make_number (50);
31411 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
31412 doc
: /* Maximum buffer size for which line number should be displayed.
31413 If the buffer is bigger than this, the line number does not appear
31414 in the mode line. A value of nil means no limit. */);
31415 Vline_number_display_limit
= Qnil
;
31417 DEFVAR_INT ("line-number-display-limit-width",
31418 line_number_display_limit_width
,
31419 doc
: /* Maximum line width (in characters) for line number display.
31420 If the average length of the lines near point is bigger than this, then the
31421 line number may be omitted from the mode line. */);
31422 line_number_display_limit_width
= 200;
31424 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
31425 doc
: /* Non-nil means highlight region even in nonselected windows. */);
31426 highlight_nonselected_windows
= false;
31428 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
31429 doc
: /* Non-nil if more than one frame is visible on this display.
31430 Minibuffer-only frames don't count, but iconified frames do.
31431 This variable is not guaranteed to be accurate except while processing
31432 `frame-title-format' and `icon-title-format'. */);
31434 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
31435 doc
: /* Template for displaying the title bar of visible frames.
31436 (Assuming the window manager supports this feature.)
31438 This variable has the same structure as `mode-line-format', except that
31439 the %c and %l constructs are ignored. It is used only on frames for
31440 which no explicit name has been set (see `modify-frame-parameters'). */);
31442 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
31443 doc
: /* Template for displaying the title bar of an iconified frame.
31444 (Assuming the window manager supports this feature.)
31445 This variable has the same structure as `mode-line-format' (which see),
31446 and is used only on frames for which no explicit name has been set
31447 (see `modify-frame-parameters'). */);
31449 = Vframe_title_format
31450 = listn (CONSTYPE_PURE
, 3,
31451 intern_c_string ("multiple-frames"),
31452 build_pure_c_string ("%b"),
31453 listn (CONSTYPE_PURE
, 4,
31454 empty_unibyte_string
,
31455 intern_c_string ("invocation-name"),
31456 build_pure_c_string ("@"),
31457 intern_c_string ("system-name")));
31459 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
31460 doc
: /* Maximum number of lines to keep in the message log buffer.
31461 If nil, disable message logging. If t, log messages but don't truncate
31462 the buffer when it becomes large. */);
31463 Vmessage_log_max
= make_number (1000);
31465 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
31466 doc
: /* Functions called during redisplay, if window sizes have changed.
31467 The value should be a list of functions that take one argument.
31468 During the first part of redisplay, for each frame, if any of its windows
31469 have changed size since the last redisplay, or have been split or deleted,
31470 all the functions in the list are called, with the frame as argument.
31471 If redisplay decides to resize the minibuffer window, it calls these
31472 functions on behalf of that as well. */);
31473 Vwindow_size_change_functions
= Qnil
;
31475 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
31476 doc
: /* List of functions to call before redisplaying a window with scrolling.
31477 Each function is called with two arguments, the window and its new
31478 display-start position.
31479 These functions are called whenever the `window-start' marker is modified,
31480 either to point into another buffer (e.g. via `set-window-buffer') or another
31481 place in the same buffer.
31482 Note that the value of `window-end' is not valid when these functions are
31485 Warning: Do not use this feature to alter the way the window
31486 is scrolled. It is not designed for that, and such use probably won't
31488 Vwindow_scroll_functions
= Qnil
;
31490 DEFVAR_LISP ("window-text-change-functions",
31491 Vwindow_text_change_functions
,
31492 doc
: /* Functions to call in redisplay when text in the window might change. */);
31493 Vwindow_text_change_functions
= Qnil
;
31495 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
31496 doc
: /* Functions called when redisplay of a window reaches the end trigger.
31497 Each function is called with two arguments, the window and the end trigger value.
31498 See `set-window-redisplay-end-trigger'. */);
31499 Vredisplay_end_trigger_functions
= Qnil
;
31501 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
31502 doc
: /* Non-nil means autoselect window with mouse pointer.
31503 If nil, do not autoselect windows.
31504 A positive number means delay autoselection by that many seconds: a
31505 window is autoselected only after the mouse has remained in that
31506 window for the duration of the delay.
31507 A negative number has a similar effect, but causes windows to be
31508 autoselected only after the mouse has stopped moving. (Because of
31509 the way Emacs compares mouse events, you will occasionally wait twice
31510 that time before the window gets selected.)
31511 Any other value means to autoselect window instantaneously when the
31512 mouse pointer enters it.
31514 Autoselection selects the minibuffer only if it is active, and never
31515 unselects the minibuffer if it is active.
31517 When customizing this variable make sure that the actual value of
31518 `focus-follows-mouse' matches the behavior of your window manager. */);
31519 Vmouse_autoselect_window
= Qnil
;
31521 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
31522 doc
: /* Non-nil means automatically resize tool-bars.
31523 This dynamically changes the tool-bar's height to the minimum height
31524 that is needed to make all tool-bar items visible.
31525 If value is `grow-only', the tool-bar's height is only increased
31526 automatically; to decrease the tool-bar height, use \\[recenter]. */);
31527 Vauto_resize_tool_bars
= Qt
;
31529 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
31530 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
31531 auto_raise_tool_bar_buttons_p
= true;
31533 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
31534 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
31535 make_cursor_line_fully_visible_p
= true;
31537 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
31538 doc
: /* Border below tool-bar in pixels.
31539 If an integer, use it as the height of the border.
31540 If it is one of `internal-border-width' or `border-width', use the
31541 value of the corresponding frame parameter.
31542 Otherwise, no border is added below the tool-bar. */);
31543 Vtool_bar_border
= Qinternal_border_width
;
31545 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
31546 doc
: /* Margin around tool-bar buttons in pixels.
31547 If an integer, use that for both horizontal and vertical margins.
31548 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
31549 HORZ specifying the horizontal margin, and VERT specifying the
31550 vertical margin. */);
31551 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
31553 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
31554 doc
: /* Relief thickness of tool-bar buttons. */);
31555 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
31557 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
31558 doc
: /* Tool bar style to use.
31560 image - show images only
31561 text - show text only
31562 both - show both, text below image
31563 both-horiz - show text to the right of the image
31564 text-image-horiz - show text to the left of the image
31565 any other - use system default or image if no system default.
31567 This variable only affects the GTK+ toolkit version of Emacs. */);
31568 Vtool_bar_style
= Qnil
;
31570 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
31571 doc
: /* Maximum number of characters a label can have to be shown.
31572 The tool bar style must also show labels for this to have any effect, see
31573 `tool-bar-style'. */);
31574 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
31576 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
31577 doc
: /* List of functions to call to fontify regions of text.
31578 Each function is called with one argument POS. Functions must
31579 fontify a region starting at POS in the current buffer, and give
31580 fontified regions the property `fontified'. */);
31581 Vfontification_functions
= Qnil
;
31582 Fmake_variable_buffer_local (Qfontification_functions
);
31584 DEFVAR_BOOL ("unibyte-display-via-language-environment",
31585 unibyte_display_via_language_environment
,
31586 doc
: /* Non-nil means display unibyte text according to language environment.
31587 Specifically, this means that raw bytes in the range 160-255 decimal
31588 are displayed by converting them to the equivalent multibyte characters
31589 according to the current language environment. As a result, they are
31590 displayed according to the current fontset.
31592 Note that this variable affects only how these bytes are displayed,
31593 but does not change the fact they are interpreted as raw bytes. */);
31594 unibyte_display_via_language_environment
= false;
31596 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
31597 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
31598 If a float, it specifies a fraction of the mini-window frame's height.
31599 If an integer, it specifies a number of lines. */);
31600 Vmax_mini_window_height
= make_float (0.25);
31602 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
31603 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
31604 A value of nil means don't automatically resize mini-windows.
31605 A value of t means resize them to fit the text displayed in them.
31606 A value of `grow-only', the default, means let mini-windows grow only;
31607 they return to their normal size when the minibuffer is closed, or the
31608 echo area becomes empty. */);
31609 Vresize_mini_windows
= Qgrow_only
;
31611 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
31612 doc
: /* Alist specifying how to blink the cursor off.
31613 Each element has the form (ON-STATE . OFF-STATE). Whenever the
31614 `cursor-type' frame-parameter or variable equals ON-STATE,
31615 comparing using `equal', Emacs uses OFF-STATE to specify
31616 how to blink it off. ON-STATE and OFF-STATE are values for
31617 the `cursor-type' frame parameter.
31619 If a frame's ON-STATE has no entry in this list,
31620 the frame's other specifications determine how to blink the cursor off. */);
31621 Vblink_cursor_alist
= Qnil
;
31623 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
31624 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
31625 If non-nil, windows are automatically scrolled horizontally to make
31626 point visible. */);
31627 automatic_hscrolling_p
= true;
31628 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
31630 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
31631 doc
: /* How many columns away from the window edge point is allowed to get
31632 before automatic hscrolling will horizontally scroll the window. */);
31633 hscroll_margin
= 5;
31635 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
31636 doc
: /* How many columns to scroll the window when point gets too close to the edge.
31637 When point is less than `hscroll-margin' columns from the window
31638 edge, automatic hscrolling will scroll the window by the amount of columns
31639 determined by this variable. If its value is a positive integer, scroll that
31640 many columns. If it's a positive floating-point number, it specifies the
31641 fraction of the window's width to scroll. If it's nil or zero, point will be
31642 centered horizontally after the scroll. Any other value, including negative
31643 numbers, are treated as if the value were zero.
31645 Automatic hscrolling always moves point outside the scroll margin, so if
31646 point was more than scroll step columns inside the margin, the window will
31647 scroll more than the value given by the scroll step.
31649 Note that the lower bound for automatic hscrolling specified by `scroll-left'
31650 and `scroll-right' overrides this variable's effect. */);
31651 Vhscroll_step
= make_number (0);
31653 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
31654 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
31655 Bind this around calls to `message' to let it take effect. */);
31656 message_truncate_lines
= false;
31658 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
31659 doc
: /* Normal hook run to update the menu bar definitions.
31660 Redisplay runs this hook before it redisplays the menu bar.
31661 This is used to update menus such as Buffers, whose contents depend on
31663 Vmenu_bar_update_hook
= Qnil
;
31665 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
31666 doc
: /* Frame for which we are updating a menu.
31667 The enable predicate for a menu binding should check this variable. */);
31668 Vmenu_updating_frame
= Qnil
;
31670 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
31671 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
31672 inhibit_menubar_update
= false;
31674 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
31675 doc
: /* Prefix prepended to all continuation lines at display time.
31676 The value may be a string, an image, or a stretch-glyph; it is
31677 interpreted in the same way as the value of a `display' text property.
31679 This variable is overridden by any `wrap-prefix' text or overlay
31682 To add a prefix to non-continuation lines, use `line-prefix'. */);
31683 Vwrap_prefix
= Qnil
;
31684 DEFSYM (Qwrap_prefix
, "wrap-prefix");
31685 Fmake_variable_buffer_local (Qwrap_prefix
);
31687 DEFVAR_LISP ("line-prefix", Vline_prefix
,
31688 doc
: /* Prefix prepended to all non-continuation lines at display time.
31689 The value may be a string, an image, or a stretch-glyph; it is
31690 interpreted in the same way as the value of a `display' text property.
31692 This variable is overridden by any `line-prefix' text or overlay
31695 To add a prefix to continuation lines, use `wrap-prefix'. */);
31696 Vline_prefix
= Qnil
;
31697 DEFSYM (Qline_prefix
, "line-prefix");
31698 Fmake_variable_buffer_local (Qline_prefix
);
31700 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
31701 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
31702 inhibit_eval_during_redisplay
= false;
31704 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
31705 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
31706 inhibit_free_realized_faces
= false;
31708 DEFVAR_BOOL ("inhibit-bidi-mirroring", inhibit_bidi_mirroring
,
31709 doc
: /* Non-nil means don't mirror characters even when bidi context requires that.
31710 Intended for use during debugging and for testing bidi display;
31711 see biditest.el in the test suite. */);
31712 inhibit_bidi_mirroring
= false;
31715 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
31716 doc
: /* Inhibit try_window_id display optimization. */);
31717 inhibit_try_window_id
= false;
31719 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
31720 doc
: /* Inhibit try_window_reusing display optimization. */);
31721 inhibit_try_window_reusing
= false;
31723 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
31724 doc
: /* Inhibit try_cursor_movement display optimization. */);
31725 inhibit_try_cursor_movement
= false;
31726 #endif /* GLYPH_DEBUG */
31728 DEFVAR_INT ("overline-margin", overline_margin
,
31729 doc
: /* Space between overline and text, in pixels.
31730 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
31731 margin to the character height. */);
31732 overline_margin
= 2;
31734 DEFVAR_INT ("underline-minimum-offset",
31735 underline_minimum_offset
,
31736 doc
: /* Minimum distance between baseline and underline.
31737 This can improve legibility of underlined text at small font sizes,
31738 particularly when using variable `x-use-underline-position-properties'
31739 with fonts that specify an UNDERLINE_POSITION relatively close to the
31740 baseline. The default value is 1. */);
31741 underline_minimum_offset
= 1;
31743 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
31744 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
31745 This feature only works when on a window system that can change
31746 cursor shapes. */);
31747 display_hourglass_p
= true;
31749 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
31750 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
31751 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
31753 #ifdef HAVE_WINDOW_SYSTEM
31754 hourglass_atimer
= NULL
;
31755 hourglass_shown_p
= false;
31756 #endif /* HAVE_WINDOW_SYSTEM */
31758 /* Name of the face used to display glyphless characters. */
31759 DEFSYM (Qglyphless_char
, "glyphless-char");
31761 /* Method symbols for Vglyphless_char_display. */
31762 DEFSYM (Qhex_code
, "hex-code");
31763 DEFSYM (Qempty_box
, "empty-box");
31764 DEFSYM (Qthin_space
, "thin-space");
31765 DEFSYM (Qzero_width
, "zero-width");
31767 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
31768 doc
: /* Function run just before redisplay.
31769 It is called with one argument, which is the set of windows that are to
31770 be redisplayed. This set can be nil (meaning, only the selected window),
31771 or t (meaning all windows). */);
31772 Vpre_redisplay_function
= intern ("ignore");
31774 /* Symbol for the purpose of Vglyphless_char_display. */
31775 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
31776 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
31778 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
31779 doc
: /* Char-table defining glyphless characters.
31780 Each element, if non-nil, should be one of the following:
31781 an ASCII acronym string: display this string in a box
31782 `hex-code': display the hexadecimal code of a character in a box
31783 `empty-box': display as an empty box
31784 `thin-space': display as 1-pixel width space
31785 `zero-width': don't display
31786 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
31787 display method for graphical terminals and text terminals respectively.
31788 GRAPHICAL and TEXT should each have one of the values listed above.
31790 The char-table has one extra slot to control the display of a character for
31791 which no font is found. This slot only takes effect on graphical terminals.
31792 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
31793 `thin-space'. The default is `empty-box'.
31795 If a character has a non-nil entry in an active display table, the
31796 display table takes effect; in this case, Emacs does not consult
31797 `glyphless-char-display' at all. */);
31798 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
31799 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
31802 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
31803 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
31804 Vdebug_on_message
= Qnil
;
31806 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
31808 Vredisplay__all_windows_cause
= Fmake_hash_table (0, NULL
);
31810 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
31812 Vredisplay__mode_lines_cause
= Fmake_hash_table (0, NULL
);
31814 DEFVAR_LISP ("redisplay--variables", Vredisplay__variables
,
31815 doc
: /* A hash-table of variables changing which triggers a thorough redisplay. */);
31816 Vredisplay__variables
= Qnil
;
31820 /* Initialize this module when Emacs starts. */
31825 CHARPOS (this_line_start_pos
) = 0;
31827 if (!noninteractive
)
31829 struct window
*m
= XWINDOW (minibuf_window
);
31830 Lisp_Object frame
= m
->frame
;
31831 struct frame
*f
= XFRAME (frame
);
31832 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
31833 struct window
*r
= XWINDOW (root
);
31836 echo_area_window
= minibuf_window
;
31838 r
->top_line
= FRAME_TOP_MARGIN (f
);
31839 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
31840 r
->total_cols
= FRAME_COLS (f
);
31841 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31842 r
->total_lines
= FRAME_TOTAL_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
31843 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
31845 m
->top_line
= FRAME_TOTAL_LINES (f
) - 1;
31846 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
31847 m
->total_cols
= FRAME_COLS (f
);
31848 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31849 m
->total_lines
= 1;
31850 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
31852 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
31853 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
31854 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
31856 /* The default ellipsis glyphs `...'. */
31857 for (i
= 0; i
< 3; ++i
)
31858 default_invis_vector
[i
] = make_number ('.');
31862 /* Allocate the buffer for frame titles.
31863 Also used for `format-mode-line'. */
31865 mode_line_noprop_buf
= xmalloc (size
);
31866 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
31867 mode_line_noprop_ptr
= mode_line_noprop_buf
;
31868 mode_line_target
= MODE_LINE_DISPLAY
;
31871 help_echo_showing_p
= false;
31874 #ifdef HAVE_WINDOW_SYSTEM
31876 /* Platform-independent portion of hourglass implementation. */
31878 /* Timer function of hourglass_atimer. */
31881 show_hourglass (struct atimer
*timer
)
31883 /* The timer implementation will cancel this timer automatically
31884 after this function has run. Set hourglass_atimer to null
31885 so that we know the timer doesn't have to be canceled. */
31886 hourglass_atimer
= NULL
;
31888 if (!hourglass_shown_p
)
31890 Lisp_Object tail
, frame
;
31894 FOR_EACH_FRAME (tail
, frame
)
31896 struct frame
*f
= XFRAME (frame
);
31898 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31899 && FRAME_RIF (f
)->show_hourglass
)
31900 FRAME_RIF (f
)->show_hourglass (f
);
31903 hourglass_shown_p
= true;
31908 /* Cancel a currently active hourglass timer, and start a new one. */
31911 start_hourglass (void)
31913 struct timespec delay
;
31915 cancel_hourglass ();
31917 if (INTEGERP (Vhourglass_delay
)
31918 && XINT (Vhourglass_delay
) > 0)
31919 delay
= make_timespec (min (XINT (Vhourglass_delay
),
31920 TYPE_MAXIMUM (time_t)),
31922 else if (FLOATP (Vhourglass_delay
)
31923 && XFLOAT_DATA (Vhourglass_delay
) > 0)
31924 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
31926 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
31928 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
31929 show_hourglass
, NULL
);
31932 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
31936 cancel_hourglass (void)
31938 if (hourglass_atimer
)
31940 cancel_atimer (hourglass_atimer
);
31941 hourglass_atimer
= NULL
;
31944 if (hourglass_shown_p
)
31946 Lisp_Object tail
, frame
;
31950 FOR_EACH_FRAME (tail
, frame
)
31952 struct frame
*f
= XFRAME (frame
);
31954 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31955 && FRAME_RIF (f
)->hide_hourglass
)
31956 FRAME_RIF (f
)->hide_hourglass (f
);
31958 /* No cursors on non GUI frames - restore to stock arrow cursor. */
31959 else if (!FRAME_W32_P (f
))
31960 w32_arrow_cursor ();
31964 hourglass_shown_p
= false;
31969 #endif /* HAVE_WINDOW_SYSTEM */