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"
318 #ifdef HAVE_WINDOW_SYSTEM
320 #endif /* HAVE_WINDOW_SYSTEM */
322 #ifndef FRAME_X_OUTPUT
323 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
326 #define INFINITY 10000000
328 /* Holds the list (error). */
329 static Lisp_Object list_of_error
;
331 #ifdef HAVE_WINDOW_SYSTEM
333 /* Test if overflow newline into fringe. Called with iterator IT
334 at or past right window margin, and with IT->current_x set. */
336 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
337 (!NILP (Voverflow_newline_into_fringe) \
338 && FRAME_WINDOW_P ((IT)->f) \
339 && ((IT)->bidi_it.paragraph_dir == R2L \
340 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
341 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
342 && (IT)->current_x == (IT)->last_visible_x)
344 #else /* !HAVE_WINDOW_SYSTEM */
345 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) false
346 #endif /* HAVE_WINDOW_SYSTEM */
348 /* Test if the display element loaded in IT, or the underlying buffer
349 or string character, is a space or a TAB character. This is used
350 to determine where word wrapping can occur. */
352 #define IT_DISPLAYING_WHITESPACE(it) \
353 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
354 || ((STRINGP (it->string) \
355 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
356 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
358 && (it->s[IT_BYTEPOS (*it)] == ' ' \
359 || it->s[IT_BYTEPOS (*it)] == '\t')) \
360 || (IT_BYTEPOS (*it) < ZV_BYTE \
361 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
362 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
364 /* True means print newline to stdout before next mini-buffer message. */
366 bool noninteractive_need_newline
;
368 /* True means print newline to message log before next message. */
370 static bool message_log_need_newline
;
372 /* Three markers that message_dolog uses.
373 It could allocate them itself, but that causes trouble
374 in handling memory-full errors. */
375 static Lisp_Object message_dolog_marker1
;
376 static Lisp_Object message_dolog_marker2
;
377 static Lisp_Object message_dolog_marker3
;
379 /* The buffer position of the first character appearing entirely or
380 partially on the line of the selected window which contains the
381 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
382 redisplay optimization in redisplay_internal. */
384 static struct text_pos this_line_start_pos
;
386 /* Number of characters past the end of the line above, including the
387 terminating newline. */
389 static struct text_pos this_line_end_pos
;
391 /* The vertical positions and the height of this line. */
393 static int this_line_vpos
;
394 static int this_line_y
;
395 static int this_line_pixel_height
;
397 /* X position at which this display line starts. Usually zero;
398 negative if first character is partially visible. */
400 static int this_line_start_x
;
402 /* The smallest character position seen by move_it_* functions as they
403 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
404 hscrolled lines, see display_line. */
406 static struct text_pos this_line_min_pos
;
408 /* Buffer that this_line_.* variables are referring to. */
410 static struct buffer
*this_line_buffer
;
412 /* True if an overlay arrow has been displayed in this window. */
414 static bool overlay_arrow_seen
;
416 /* Vector containing glyphs for an ellipsis `...'. */
418 static Lisp_Object default_invis_vector
[3];
420 /* This is the window where the echo area message was displayed. It
421 is always a mini-buffer window, but it may not be the same window
422 currently active as a mini-buffer. */
424 Lisp_Object echo_area_window
;
426 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
427 pushes the current message and the value of
428 message_enable_multibyte on the stack, the function restore_message
429 pops the stack and displays MESSAGE again. */
431 static Lisp_Object Vmessage_stack
;
433 /* True means multibyte characters were enabled when the echo area
434 message was specified. */
436 static bool message_enable_multibyte
;
438 /* At each redisplay cycle, we should refresh everything there is to refresh.
439 To do that efficiently, we use many optimizations that try to make sure we
440 don't waste too much time updating things that haven't changed.
441 The coarsest such optimization is that, in the most common cases, we only
442 look at the selected-window.
444 To know whether other windows should be considered for redisplay, we use the
445 variable windows_or_buffers_changed: as long as it is 0, it means that we
446 have not noticed anything that should require updating anything else than
447 the selected-window. If it is set to REDISPLAY_SOME, it means that since
448 last redisplay, some changes have been made which could impact other
449 windows. To know which ones need redisplay, every buffer, window, and frame
450 has a `redisplay' bit, which (if true) means that this object needs to be
451 redisplayed. If windows_or_buffers_changed is 0, we know there's no point
452 looking for those `redisplay' bits (actually, there might be some such bits
453 set, but then only on objects which aren't displayed anyway).
455 OTOH if it's non-zero we wil have to loop through all windows and then check
456 the `redisplay' bit of the corresponding window, frame, and buffer, in order
457 to decide whether that window needs attention or not. Note that we can't
458 just look at the frame's redisplay bit to decide that the whole frame can be
459 skipped, since even if the frame's redisplay bit is unset, some of its
460 windows's redisplay bits may be set.
462 Mostly for historical reasons, windows_or_buffers_changed can also take
463 other non-zero values. In that case, the precise value doesn't matter (it
464 encodes the cause of the setting but is only used for debugging purposes),
465 and what it means is that we shouldn't pay attention to any `redisplay' bits
466 and we should simply try and redisplay every window out there. */
468 int windows_or_buffers_changed
;
470 /* Nonzero if we should redraw the mode lines on the next redisplay.
471 Similarly to `windows_or_buffers_changed', If it has value REDISPLAY_SOME,
472 then only redisplay the mode lines in those buffers/windows/frames where the
473 `redisplay' bit has been set.
474 For any other value, redisplay all mode lines (the number used is then only
475 used to track down the cause for this full-redisplay).
477 Since the frame title uses the same %-constructs as the mode line
478 (except %c and %l), if this variable is non-zero, we also consider
479 redisplaying the title of each frame, see x_consider_frame_title.
481 The `redisplay' bits are the same as those used for
482 windows_or_buffers_changed, and setting windows_or_buffers_changed also
483 causes recomputation of the mode lines of all those windows. IOW this
484 variable only has an effect if windows_or_buffers_changed is zero, in which
485 case we should only need to redisplay the mode-line of those objects with
486 a `redisplay' bit set but not the window's text content (tho we may still
487 need to refresh the text content of the selected-window). */
489 int update_mode_lines
;
491 /* True after display_mode_line if %l was used and it displayed a
494 static bool line_number_displayed
;
496 /* The name of the *Messages* buffer, a string. */
498 static Lisp_Object Vmessages_buffer_name
;
500 /* Current, index 0, and last displayed echo area message. Either
501 buffers from echo_buffers, or nil to indicate no message. */
503 Lisp_Object echo_area_buffer
[2];
505 /* The buffers referenced from echo_area_buffer. */
507 static Lisp_Object echo_buffer
[2];
509 /* A vector saved used in with_area_buffer to reduce consing. */
511 static Lisp_Object Vwith_echo_area_save_vector
;
513 /* True means display_echo_area should display the last echo area
514 message again. Set by redisplay_preserve_echo_area. */
516 static bool display_last_displayed_message_p
;
518 /* True if echo area is being used by print; false if being used by
521 static bool message_buf_print
;
523 /* Set to true in clear_message to make redisplay_internal aware
524 of an emptied echo area. */
526 static bool message_cleared_p
;
528 /* A scratch glyph row with contents used for generating truncation
529 glyphs. Also used in direct_output_for_insert. */
531 #define MAX_SCRATCH_GLYPHS 100
532 static struct glyph_row scratch_glyph_row
;
533 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
535 /* Ascent and height of the last line processed by move_it_to. */
537 static int last_height
;
539 /* True if there's a help-echo in the echo area. */
541 bool help_echo_showing_p
;
543 /* The maximum distance to look ahead for text properties. Values
544 that are too small let us call compute_char_face and similar
545 functions too often which is expensive. Values that are too large
546 let us call compute_char_face and alike too often because we
547 might not be interested in text properties that far away. */
549 #define TEXT_PROP_DISTANCE_LIMIT 100
551 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
552 iterator state and later restore it. This is needed because the
553 bidi iterator on bidi.c keeps a stacked cache of its states, which
554 is really a singleton. When we use scratch iterator objects to
555 move around the buffer, we can cause the bidi cache to be pushed or
556 popped, and therefore we need to restore the cache state when we
557 return to the original iterator. */
558 #define SAVE_IT(ITCOPY, ITORIG, CACHE) \
561 bidi_unshelve_cache (CACHE, true); \
563 CACHE = bidi_shelve_cache (); \
566 #define RESTORE_IT(pITORIG, pITCOPY, CACHE) \
568 if (pITORIG != pITCOPY) \
569 *(pITORIG) = *(pITCOPY); \
570 bidi_unshelve_cache (CACHE, false); \
574 /* Functions to mark elements as needing redisplay. */
575 enum { REDISPLAY_SOME
= 2}; /* Arbitrary choice. */
578 redisplay_other_windows (void)
580 if (!windows_or_buffers_changed
)
581 windows_or_buffers_changed
= REDISPLAY_SOME
;
585 wset_redisplay (struct window
*w
)
587 /* Beware: selected_window can be nil during early stages. */
588 if (!EQ (make_lisp_ptr (w
, Lisp_Vectorlike
), selected_window
))
589 redisplay_other_windows ();
594 fset_redisplay (struct frame
*f
)
596 redisplay_other_windows ();
601 bset_redisplay (struct buffer
*b
)
603 int count
= buffer_window_count (b
);
606 /* ... it's visible in other window than selected, */
607 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
608 redisplay_other_windows ();
609 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
610 so that if we later set windows_or_buffers_changed, this buffer will
612 b
->text
->redisplay
= true;
617 bset_update_mode_line (struct buffer
*b
)
619 if (!update_mode_lines
)
620 update_mode_lines
= REDISPLAY_SOME
;
621 b
->text
->redisplay
= true;
625 maybe_set_redisplay (Lisp_Object symbol
)
627 if (HASH_TABLE_P (Vredisplay__variables
)
628 && hash_lookup (XHASH_TABLE (Vredisplay__variables
), symbol
, NULL
) >= 0)
630 bset_update_mode_line (current_buffer
);
631 current_buffer
->prevent_redisplay_optimizations_p
= true;
637 /* True means print traces of redisplay if compiled with
638 GLYPH_DEBUG defined. */
640 bool trace_redisplay_p
;
642 #endif /* GLYPH_DEBUG */
644 #ifdef DEBUG_TRACE_MOVE
645 /* True means trace with TRACE_MOVE to stderr. */
646 static bool trace_move
;
648 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
650 #define TRACE_MOVE(x) (void) 0
653 /* Buffer being redisplayed -- for redisplay_window_error. */
655 static struct buffer
*displayed_buffer
;
657 /* Value returned from text property handlers (see below). */
662 HANDLED_RECOMPUTE_PROPS
,
663 HANDLED_OVERLAY_STRING_CONSUMED
,
667 /* A description of text properties that redisplay is interested
672 /* The symbol index of the name of the property. */
675 /* A unique index for the property. */
678 /* A handler function called to set up iterator IT from the property
679 at IT's current position. Value is used to steer handle_stop. */
680 enum prop_handled (*handler
) (struct it
*it
);
683 static enum prop_handled
handle_face_prop (struct it
*);
684 static enum prop_handled
handle_invisible_prop (struct it
*);
685 static enum prop_handled
handle_display_prop (struct it
*);
686 static enum prop_handled
handle_composition_prop (struct it
*);
687 static enum prop_handled
handle_overlay_change (struct it
*);
688 static enum prop_handled
handle_fontified_prop (struct it
*);
690 /* Properties handled by iterators. */
692 static struct props it_props
[] =
694 {SYMBOL_INDEX (Qfontified
), FONTIFIED_PROP_IDX
, handle_fontified_prop
},
695 /* Handle `face' before `display' because some sub-properties of
696 `display' need to know the face. */
697 {SYMBOL_INDEX (Qface
), FACE_PROP_IDX
, handle_face_prop
},
698 {SYMBOL_INDEX (Qdisplay
), DISPLAY_PROP_IDX
, handle_display_prop
},
699 {SYMBOL_INDEX (Qinvisible
), INVISIBLE_PROP_IDX
, handle_invisible_prop
},
700 {SYMBOL_INDEX (Qcomposition
), COMPOSITION_PROP_IDX
, handle_composition_prop
},
704 /* Value is the position described by X. If X is a marker, value is
705 the marker_position of X. Otherwise, value is X. */
707 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
709 /* Enumeration returned by some move_it_.* functions internally. */
713 /* Not used. Undefined value. */
716 /* Move ended at the requested buffer position or ZV. */
717 MOVE_POS_MATCH_OR_ZV
,
719 /* Move ended at the requested X pixel position. */
722 /* Move within a line ended at the end of a line that must be
726 /* Move within a line ended at the end of a line that would
727 be displayed truncated. */
730 /* Move within a line ended at a line end. */
734 /* This counter is used to clear the face cache every once in a while
735 in redisplay_internal. It is incremented for each redisplay.
736 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
739 #define CLEAR_FACE_CACHE_COUNT 500
740 static int clear_face_cache_count
;
742 /* Similarly for the image cache. */
744 #ifdef HAVE_WINDOW_SYSTEM
745 #define CLEAR_IMAGE_CACHE_COUNT 101
746 static int clear_image_cache_count
;
748 /* Null glyph slice */
749 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
752 /* True while redisplay_internal is in progress. */
756 /* If a string, XTread_socket generates an event to display that string.
757 (The display is done in read_char.) */
759 Lisp_Object help_echo_string
;
760 Lisp_Object help_echo_window
;
761 Lisp_Object help_echo_object
;
762 ptrdiff_t help_echo_pos
;
764 /* Temporary variable for XTread_socket. */
766 Lisp_Object previous_help_echo_string
;
768 /* Platform-independent portion of hourglass implementation. */
770 #ifdef HAVE_WINDOW_SYSTEM
772 /* True means an hourglass cursor is currently shown. */
773 static bool hourglass_shown_p
;
775 /* If non-null, an asynchronous timer that, when it expires, displays
776 an hourglass cursor on all frames. */
777 static struct atimer
*hourglass_atimer
;
779 #endif /* HAVE_WINDOW_SYSTEM */
781 /* Default number of seconds to wait before displaying an hourglass
783 #define DEFAULT_HOURGLASS_DELAY 1
785 #ifdef HAVE_WINDOW_SYSTEM
787 /* Default pixel width of `thin-space' display method. */
788 #define THIN_SPACE_WIDTH 1
790 #endif /* HAVE_WINDOW_SYSTEM */
792 /* Function prototypes. */
794 static void setup_for_ellipsis (struct it
*, int);
795 static void set_iterator_to_next (struct it
*, bool);
796 static void mark_window_display_accurate_1 (struct window
*, bool);
797 static bool row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
798 static bool cursor_row_p (struct glyph_row
*);
799 static int redisplay_mode_lines (Lisp_Object
, bool);
801 static void handle_line_prefix (struct it
*);
803 static void handle_stop_backwards (struct it
*, ptrdiff_t);
804 static void unwind_with_echo_area_buffer (Lisp_Object
);
805 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
806 static bool current_message_1 (ptrdiff_t, Lisp_Object
);
807 static bool truncate_message_1 (ptrdiff_t, Lisp_Object
);
808 static void set_message (Lisp_Object
);
809 static bool set_message_1 (ptrdiff_t, Lisp_Object
);
810 static bool display_echo_area_1 (ptrdiff_t, Lisp_Object
);
811 static bool resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
812 static void unwind_redisplay (void);
813 static void extend_face_to_end_of_line (struct it
*);
814 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
815 static void push_it (struct it
*, struct text_pos
*);
816 static void iterate_out_of_display_property (struct it
*);
817 static void pop_it (struct it
*);
818 static void redisplay_internal (void);
819 static void echo_area_display (bool);
820 static void redisplay_windows (Lisp_Object
);
821 static void redisplay_window (Lisp_Object
, bool);
822 static Lisp_Object
redisplay_window_error (Lisp_Object
);
823 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
824 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
825 static bool set_cursor_from_row (struct window
*, struct glyph_row
*,
826 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
828 static bool update_menu_bar (struct frame
*, bool, bool);
829 static bool try_window_reusing_current_matrix (struct window
*);
830 static int try_window_id (struct window
*);
831 static bool display_line (struct it
*);
832 static int display_mode_lines (struct window
*);
833 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
834 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
,
836 static int store_mode_line_string (const char *, Lisp_Object
, bool, int, int,
838 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
839 static void display_menu_bar (struct window
*);
840 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
842 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
843 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
844 static void compute_line_metrics (struct it
*);
845 static void run_redisplay_end_trigger_hook (struct it
*);
846 static bool get_overlay_strings (struct it
*, ptrdiff_t);
847 static bool get_overlay_strings_1 (struct it
*, ptrdiff_t, bool);
848 static void next_overlay_string (struct it
*);
849 static void reseat (struct it
*, struct text_pos
, bool);
850 static void reseat_1 (struct it
*, struct text_pos
, bool);
851 static bool next_element_from_display_vector (struct it
*);
852 static bool next_element_from_string (struct it
*);
853 static bool next_element_from_c_string (struct it
*);
854 static bool next_element_from_buffer (struct it
*);
855 static bool next_element_from_composition (struct it
*);
856 static bool next_element_from_image (struct it
*);
857 static bool next_element_from_stretch (struct it
*);
858 static bool next_element_from_xwidget (struct it
*);
859 static void load_overlay_strings (struct it
*, ptrdiff_t);
860 static bool get_next_display_element (struct it
*);
861 static enum move_it_result
862 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
863 enum move_operation_enum
);
864 static void get_visually_first_element (struct it
*);
865 static void compute_stop_pos (struct it
*);
866 static int face_before_or_after_it_pos (struct it
*, bool);
867 static ptrdiff_t next_overlay_change (ptrdiff_t);
868 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
869 Lisp_Object
, struct text_pos
*, ptrdiff_t, bool);
870 static int handle_single_display_spec (struct it
*, Lisp_Object
,
871 Lisp_Object
, Lisp_Object
,
872 struct text_pos
*, ptrdiff_t, int, bool);
873 static int underlying_face_id (struct it
*);
875 #define face_before_it_pos(IT) face_before_or_after_it_pos (IT, true)
876 #define face_after_it_pos(IT) face_before_or_after_it_pos (IT, false)
878 #ifdef HAVE_WINDOW_SYSTEM
880 static void update_tool_bar (struct frame
*, bool);
881 static void x_draw_bottom_divider (struct window
*w
);
882 static void notice_overwritten_cursor (struct window
*,
885 static int normal_char_height (struct font
*, int);
886 static void normal_char_ascent_descent (struct font
*, int, int *, int *);
888 static void append_stretch_glyph (struct it
*, Lisp_Object
,
891 static Lisp_Object
get_it_property (struct it
*, Lisp_Object
);
892 static Lisp_Object
calc_line_height_property (struct it
*, Lisp_Object
,
893 struct font
*, int, bool);
895 #endif /* HAVE_WINDOW_SYSTEM */
897 static void produce_special_glyphs (struct it
*, enum display_element_type
);
898 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
899 static bool coords_in_mouse_face_p (struct window
*, int, int);
903 /***********************************************************************
904 Window display dimensions
905 ***********************************************************************/
907 /* Return the bottom boundary y-position for text lines in window W.
908 This is the first y position at which a line cannot start.
909 It is relative to the top of the window.
911 This is the height of W minus the height of a mode line, if any. */
914 window_text_bottom_y (struct window
*w
)
916 int height
= WINDOW_PIXEL_HEIGHT (w
);
918 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
920 if (WINDOW_WANTS_MODELINE_P (w
))
921 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
923 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
928 /* Return the pixel width of display area AREA of window W.
929 ANY_AREA means return the total width of W, not including
930 fringes to the left and right of the window. */
933 window_box_width (struct window
*w
, enum glyph_row_area area
)
935 int width
= w
->pixel_width
;
937 if (!w
->pseudo_window_p
)
939 width
-= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
940 width
-= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
942 if (area
== TEXT_AREA
)
943 width
-= (WINDOW_MARGINS_WIDTH (w
)
944 + WINDOW_FRINGES_WIDTH (w
));
945 else if (area
== LEFT_MARGIN_AREA
)
946 width
= WINDOW_LEFT_MARGIN_WIDTH (w
);
947 else if (area
== RIGHT_MARGIN_AREA
)
948 width
= WINDOW_RIGHT_MARGIN_WIDTH (w
);
951 /* With wide margins, fringes, etc. we might end up with a negative
952 width, correct that here. */
953 return max (0, width
);
957 /* Return the pixel height of the display area of window W, not
958 including mode lines of W, if any. */
961 window_box_height (struct window
*w
)
963 struct frame
*f
= XFRAME (w
->frame
);
964 int height
= WINDOW_PIXEL_HEIGHT (w
);
966 eassert (height
>= 0);
968 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
969 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
971 /* Note: the code below that determines the mode-line/header-line
972 height is essentially the same as that contained in the macro
973 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
974 the appropriate glyph row has its `mode_line_p' flag set,
975 and if it doesn't, uses estimate_mode_line_height instead. */
977 if (WINDOW_WANTS_MODELINE_P (w
))
979 struct glyph_row
*ml_row
980 = (w
->current_matrix
&& w
->current_matrix
->rows
981 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
983 if (ml_row
&& ml_row
->mode_line_p
)
984 height
-= ml_row
->height
;
986 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
989 if (WINDOW_WANTS_HEADER_LINE_P (w
))
991 struct glyph_row
*hl_row
992 = (w
->current_matrix
&& w
->current_matrix
->rows
993 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
995 if (hl_row
&& hl_row
->mode_line_p
)
996 height
-= hl_row
->height
;
998 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1001 /* With a very small font and a mode-line that's taller than
1002 default, we might end up with a negative height. */
1003 return max (0, height
);
1006 /* Return the window-relative coordinate of the left edge of display
1007 area AREA of window W. ANY_AREA means return the left edge of the
1008 whole window, to the right of the left fringe of W. */
1011 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1015 if (w
->pseudo_window_p
)
1018 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1020 if (area
== TEXT_AREA
)
1021 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1022 + window_box_width (w
, LEFT_MARGIN_AREA
));
1023 else if (area
== RIGHT_MARGIN_AREA
)
1024 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1025 + window_box_width (w
, LEFT_MARGIN_AREA
)
1026 + window_box_width (w
, TEXT_AREA
)
1027 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1029 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1030 else if (area
== LEFT_MARGIN_AREA
1031 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1032 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1034 /* Don't return more than the window's pixel width. */
1035 return min (x
, w
->pixel_width
);
1039 /* Return the window-relative coordinate of the right edge of display
1040 area AREA of window W. ANY_AREA means return the right edge of the
1041 whole window, to the left of the right fringe of W. */
1044 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1046 /* Don't return more than the window's pixel width. */
1047 return min (window_box_left_offset (w
, area
) + window_box_width (w
, area
),
1051 /* Return the frame-relative coordinate of the left edge of display
1052 area AREA of window W. ANY_AREA means return the left edge of the
1053 whole window, to the right of the left fringe of W. */
1056 window_box_left (struct window
*w
, enum glyph_row_area area
)
1058 struct frame
*f
= XFRAME (w
->frame
);
1061 if (w
->pseudo_window_p
)
1062 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1064 x
= (WINDOW_LEFT_EDGE_X (w
)
1065 + window_box_left_offset (w
, area
));
1071 /* Return the frame-relative coordinate of the right edge of display
1072 area AREA of window W. ANY_AREA means return the right edge of the
1073 whole window, to the left of the right fringe of W. */
1076 window_box_right (struct window
*w
, enum glyph_row_area area
)
1078 return window_box_left (w
, area
) + window_box_width (w
, area
);
1081 /* Get the bounding box of the display area AREA of window W, without
1082 mode lines, in frame-relative coordinates. ANY_AREA means the
1083 whole window, not including the left and right fringes of
1084 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1085 coordinates of the upper-left corner of the box. Return in
1086 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1089 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1090 int *box_y
, int *box_width
, int *box_height
)
1093 *box_width
= window_box_width (w
, area
);
1095 *box_height
= window_box_height (w
);
1097 *box_x
= window_box_left (w
, area
);
1100 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1101 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1102 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1106 #ifdef HAVE_WINDOW_SYSTEM
1108 /* Get the bounding box of the display area AREA of window W, without
1109 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1110 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1111 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1112 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1116 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1117 int *bottom_right_x
, int *bottom_right_y
)
1119 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1120 bottom_right_x
, bottom_right_y
);
1121 *bottom_right_x
+= *top_left_x
;
1122 *bottom_right_y
+= *top_left_y
;
1125 #endif /* HAVE_WINDOW_SYSTEM */
1127 /***********************************************************************
1129 ***********************************************************************/
1131 /* Return the bottom y-position of the line the iterator IT is in.
1132 This can modify IT's settings. */
1135 line_bottom_y (struct it
*it
)
1137 int line_height
= it
->max_ascent
+ it
->max_descent
;
1138 int line_top_y
= it
->current_y
;
1140 if (line_height
== 0)
1143 line_height
= last_height
;
1144 else if (IT_CHARPOS (*it
) < ZV
)
1146 move_it_by_lines (it
, 1);
1147 line_height
= (it
->max_ascent
|| it
->max_descent
1148 ? it
->max_ascent
+ it
->max_descent
1153 struct glyph_row
*row
= it
->glyph_row
;
1155 /* Use the default character height. */
1156 it
->glyph_row
= NULL
;
1157 it
->what
= IT_CHARACTER
;
1160 PRODUCE_GLYPHS (it
);
1161 line_height
= it
->ascent
+ it
->descent
;
1162 it
->glyph_row
= row
;
1166 return line_top_y
+ line_height
;
1169 DEFUN ("line-pixel-height", Fline_pixel_height
,
1170 Sline_pixel_height
, 0, 0, 0,
1171 doc
: /* Return height in pixels of text line in the selected window.
1173 Value is the height in pixels of the line at point. */)
1178 struct window
*w
= XWINDOW (selected_window
);
1179 struct buffer
*old_buffer
= NULL
;
1182 if (XBUFFER (w
->contents
) != current_buffer
)
1184 old_buffer
= current_buffer
;
1185 set_buffer_internal_1 (XBUFFER (w
->contents
));
1187 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1188 start_display (&it
, w
, pt
);
1189 it
.vpos
= it
.current_y
= 0;
1191 result
= make_number (line_bottom_y (&it
));
1193 set_buffer_internal_1 (old_buffer
);
1198 /* Return the default pixel height of text lines in window W. The
1199 value is the canonical height of the W frame's default font, plus
1200 any extra space required by the line-spacing variable or frame
1203 Implementation note: this ignores any line-spacing text properties
1204 put on the newline characters. This is because those properties
1205 only affect the _screen_ line ending in the newline (i.e., in a
1206 continued line, only the last screen line will be affected), which
1207 means only a small number of lines in a buffer can ever use this
1208 feature. Since this function is used to compute the default pixel
1209 equivalent of text lines in a window, we can safely ignore those
1210 few lines. For the same reasons, we ignore the line-height
1213 default_line_pixel_height (struct window
*w
)
1215 struct frame
*f
= WINDOW_XFRAME (w
);
1216 int height
= FRAME_LINE_HEIGHT (f
);
1218 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1220 struct buffer
*b
= XBUFFER (w
->contents
);
1221 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1224 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1227 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1228 height
+= XFASTINT (val
);
1229 else if (FLOATP (val
))
1231 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1238 height
+= f
->extra_line_spacing
;
1244 /* Subroutine of pos_visible_p below. Extracts a display string, if
1245 any, from the display spec given as its argument. */
1247 string_from_display_spec (Lisp_Object spec
)
1251 while (CONSP (spec
))
1253 if (STRINGP (XCAR (spec
)))
1258 else if (VECTORP (spec
))
1262 for (i
= 0; i
< ASIZE (spec
); i
++)
1264 if (STRINGP (AREF (spec
, i
)))
1265 return AREF (spec
, i
);
1274 /* Limit insanely large values of W->hscroll on frame F to the largest
1275 value that will still prevent first_visible_x and last_visible_x of
1276 'struct it' from overflowing an int. */
1278 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1280 ptrdiff_t window_hscroll
= w
->hscroll
;
1281 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1282 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1284 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1285 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1287 return window_hscroll
;
1290 /* Return true if position CHARPOS is visible in window W.
1291 CHARPOS < 0 means return info about WINDOW_END position.
1292 If visible, set *X and *Y to pixel coordinates of top left corner.
1293 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1294 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1297 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1298 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1301 void *itdata
= bidi_shelve_cache ();
1302 struct text_pos top
;
1303 bool visible_p
= false;
1304 struct buffer
*old_buffer
= NULL
;
1307 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1310 if (XBUFFER (w
->contents
) != current_buffer
)
1312 old_buffer
= current_buffer
;
1313 set_buffer_internal_1 (XBUFFER (w
->contents
));
1316 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1317 /* Scrolling a minibuffer window via scroll bar when the echo area
1318 shows long text sometimes resets the minibuffer contents behind
1320 if (CHARPOS (top
) > ZV
)
1321 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1323 /* Compute exact mode line heights. */
1324 if (WINDOW_WANTS_MODELINE_P (w
))
1326 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1327 BVAR (current_buffer
, mode_line_format
));
1329 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1330 w
->header_line_height
1331 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1332 BVAR (current_buffer
, header_line_format
));
1334 start_display (&it
, w
, top
);
1335 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1336 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1339 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
!= -1)
1340 && IT_CHARPOS (it
) >= charpos
)
1341 /* When scanning backwards under bidi iteration, move_it_to
1342 stops at or _before_ CHARPOS, because it stops at or to
1343 the _right_ of the character at CHARPOS. */
1344 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1345 && IT_CHARPOS (it
) <= charpos
)))
1347 /* We have reached CHARPOS, or passed it. How the call to
1348 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1349 or covered by a display property, move_it_to stops at the end
1350 of the invisible text, to the right of CHARPOS. (ii) If
1351 CHARPOS is in a display vector, move_it_to stops on its last
1353 int top_x
= it
.current_x
;
1354 int top_y
= it
.current_y
;
1355 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1358 void *save_it_data
= NULL
;
1360 /* Calling line_bottom_y may change it.method, it.position, etc. */
1361 SAVE_IT (save_it
, it
, save_it_data
);
1363 bottom_y
= line_bottom_y (&it
);
1364 if (top_y
< window_top_y
)
1365 visible_p
= bottom_y
> window_top_y
;
1366 else if (top_y
< it
.last_visible_y
)
1368 if (bottom_y
>= it
.last_visible_y
1369 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1370 && IT_CHARPOS (it
) < charpos
)
1372 /* When the last line of the window is scanned backwards
1373 under bidi iteration, we could be duped into thinking
1374 that we have passed CHARPOS, when in fact move_it_to
1375 simply stopped short of CHARPOS because it reached
1376 last_visible_y. To see if that's what happened, we call
1377 move_it_to again with a slightly larger vertical limit,
1378 and see if it actually moved vertically; if it did, we
1379 didn't really reach CHARPOS, which is beyond window end. */
1380 /* Why 10? because we don't know how many canonical lines
1381 will the height of the next line(s) be. So we guess. */
1382 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1384 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1385 MOVE_TO_POS
| MOVE_TO_Y
);
1386 if (it
.current_y
> top_y
)
1390 RESTORE_IT (&it
, &save_it
, save_it_data
);
1393 if (it
.method
== GET_FROM_DISPLAY_VECTOR
)
1395 /* We stopped on the last glyph of a display vector.
1396 Try and recompute. Hack alert! */
1397 if (charpos
< 2 || top
.charpos
>= charpos
)
1398 top_x
= it
.glyph_row
->x
;
1401 struct it it2
, it2_prev
;
1402 /* The idea is to get to the previous buffer
1403 position, consume the character there, and use
1404 the pixel coordinates we get after that. But if
1405 the previous buffer position is also displayed
1406 from a display vector, we need to consume all of
1407 the glyphs from that display vector. */
1408 start_display (&it2
, w
, top
);
1409 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1410 /* If we didn't get to CHARPOS - 1, there's some
1411 replacing display property at that position, and
1412 we stopped after it. That is exactly the place
1413 whose coordinates we want. */
1414 if (IT_CHARPOS (it2
) != charpos
- 1)
1418 /* Iterate until we get out of the display
1419 vector that displays the character at
1422 get_next_display_element (&it2
);
1423 PRODUCE_GLYPHS (&it2
);
1425 set_iterator_to_next (&it2
, true);
1426 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1427 && IT_CHARPOS (it2
) < charpos
);
1429 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1430 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1431 top_x
= it
.glyph_row
->x
;
1434 top_x
= it2_prev
.current_x
;
1435 top_y
= it2_prev
.current_y
;
1439 else if (IT_CHARPOS (it
) != charpos
)
1441 Lisp_Object cpos
= make_number (charpos
);
1442 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1443 Lisp_Object string
= string_from_display_spec (spec
);
1444 struct text_pos tpos
;
1445 bool newline_in_string
1447 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1449 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1450 bool replacing_spec_p
1452 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1453 charpos
, FRAME_WINDOW_P (it
.f
)));
1454 /* The tricky code below is needed because there's a
1455 discrepancy between move_it_to and how we set cursor
1456 when PT is at the beginning of a portion of text
1457 covered by a display property or an overlay with a
1458 display property, or the display line ends in a
1459 newline from a display string. move_it_to will stop
1460 _after_ such display strings, whereas
1461 set_cursor_from_row conspires with cursor_row_p to
1462 place the cursor on the first glyph produced from the
1465 /* We have overshoot PT because it is covered by a
1466 display property that replaces the text it covers.
1467 If the string includes embedded newlines, we are also
1468 in the wrong display line. Backtrack to the correct
1469 line, where the display property begins. */
1470 if (replacing_spec_p
)
1472 Lisp_Object startpos
, endpos
;
1473 EMACS_INT start
, end
;
1476 /* Find the first and the last buffer positions
1477 covered by the display string. */
1479 Fnext_single_char_property_change (cpos
, Qdisplay
,
1482 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1484 start
= XFASTINT (startpos
);
1485 end
= XFASTINT (endpos
);
1486 /* Move to the last buffer position before the
1487 display property. */
1488 start_display (&it3
, w
, top
);
1489 if (start
> CHARPOS (top
))
1490 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1491 /* Move forward one more line if the position before
1492 the display string is a newline or if it is the
1493 rightmost character on a line that is
1494 continued or word-wrapped. */
1495 if (it3
.method
== GET_FROM_BUFFER
1497 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1498 move_it_by_lines (&it3
, 1);
1499 else if (move_it_in_display_line_to (&it3
, -1,
1503 == MOVE_LINE_CONTINUED
)
1505 move_it_by_lines (&it3
, 1);
1506 /* When we are under word-wrap, the #$@%!
1507 move_it_by_lines moves 2 lines, so we need to
1509 if (it3
.line_wrap
== WORD_WRAP
)
1510 move_it_by_lines (&it3
, -1);
1513 /* Record the vertical coordinate of the display
1514 line where we wound up. */
1515 top_y
= it3
.current_y
;
1518 /* When characters are reordered for display,
1519 the character displayed to the left of the
1520 display string could be _after_ the display
1521 property in the logical order. Use the
1522 smallest vertical position of these two. */
1523 start_display (&it3
, w
, top
);
1524 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1525 if (it3
.current_y
< top_y
)
1526 top_y
= it3
.current_y
;
1528 /* Move from the top of the window to the beginning
1529 of the display line where the display string
1531 start_display (&it3
, w
, top
);
1532 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1533 /* If it3_moved stays false after the 'while' loop
1534 below, that means we already were at a newline
1535 before the loop (e.g., the display string begins
1536 with a newline), so we don't need to (and cannot)
1537 inspect the glyphs of it3.glyph_row, because
1538 PRODUCE_GLYPHS will not produce anything for a
1539 newline, and thus it3.glyph_row stays at its
1540 stale content it got at top of the window. */
1541 bool it3_moved
= false;
1542 /* Finally, advance the iterator until we hit the
1543 first display element whose character position is
1544 CHARPOS, or until the first newline from the
1545 display string, which signals the end of the
1547 while (get_next_display_element (&it3
))
1549 PRODUCE_GLYPHS (&it3
);
1550 if (IT_CHARPOS (it3
) == charpos
1551 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1554 set_iterator_to_next (&it3
, false);
1556 top_x
= it3
.current_x
- it3
.pixel_width
;
1557 /* Normally, we would exit the above loop because we
1558 found the display element whose character
1559 position is CHARPOS. For the contingency that we
1560 didn't, and stopped at the first newline from the
1561 display string, move back over the glyphs
1562 produced from the string, until we find the
1563 rightmost glyph not from the string. */
1565 && newline_in_string
1566 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1568 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1569 + it3
.glyph_row
->used
[TEXT_AREA
];
1571 while (EQ ((g
- 1)->object
, string
))
1574 top_x
-= g
->pixel_width
;
1576 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1577 + it3
.glyph_row
->used
[TEXT_AREA
]);
1583 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1584 *rtop
= max (0, window_top_y
- top_y
);
1585 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1586 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1587 - max (top_y
, window_top_y
)));
1589 if (it
.bidi_it
.paragraph_dir
== R2L
)
1595 /* Either we were asked to provide info about WINDOW_END, or
1596 CHARPOS is in the partially visible glyph row at end of
1599 void *it2data
= NULL
;
1601 SAVE_IT (it2
, it
, it2data
);
1602 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1603 move_it_by_lines (&it
, 1);
1604 if (charpos
< IT_CHARPOS (it
)
1605 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1608 RESTORE_IT (&it2
, &it2
, it2data
);
1609 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1611 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1612 *rtop
= max (0, -it2
.current_y
);
1613 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1614 - it
.last_visible_y
));
1615 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1617 - max (it2
.current_y
,
1618 WINDOW_HEADER_LINE_HEIGHT (w
))));
1620 if (it2
.bidi_it
.paragraph_dir
== R2L
)
1624 bidi_unshelve_cache (it2data
, true);
1626 bidi_unshelve_cache (itdata
, false);
1629 set_buffer_internal_1 (old_buffer
);
1635 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1636 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1637 /* For lines in an R2L paragraph, we need to mirror the X pixel
1638 coordinate wrt the text area. For the reasons, see the
1639 commentary in buffer_posn_from_coords and the explanation of
1640 the geometry used by the move_it_* functions at the end of
1641 the large commentary near the beginning of this file. */
1643 *x
= window_box_width (w
, TEXT_AREA
) - *x
- 1;
1647 /* Debugging code. */
1649 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1650 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1652 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1659 /* Return the next character from STR. Return in *LEN the length of
1660 the character. This is like STRING_CHAR_AND_LENGTH but never
1661 returns an invalid character. If we find one, we return a `?', but
1662 with the length of the invalid character. */
1665 string_char_and_length (const unsigned char *str
, int *len
)
1669 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1670 if (!CHAR_VALID_P (c
))
1671 /* We may not change the length here because other places in Emacs
1672 don't use this function, i.e. they silently accept invalid
1681 /* Given a position POS containing a valid character and byte position
1682 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1684 static struct text_pos
1685 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1687 eassert (STRINGP (string
) && nchars
>= 0);
1689 if (STRING_MULTIBYTE (string
))
1691 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1696 string_char_and_length (p
, &len
);
1699 BYTEPOS (pos
) += len
;
1703 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1709 /* Value is the text position, i.e. character and byte position,
1710 for character position CHARPOS in STRING. */
1712 static struct text_pos
1713 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1715 struct text_pos pos
;
1716 eassert (STRINGP (string
));
1717 eassert (charpos
>= 0);
1718 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1723 /* Value is a text position, i.e. character and byte position, for
1724 character position CHARPOS in C string S. MULTIBYTE_P
1725 means recognize multibyte characters. */
1727 static struct text_pos
1728 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1730 struct text_pos pos
;
1732 eassert (s
!= NULL
);
1733 eassert (charpos
>= 0);
1739 SET_TEXT_POS (pos
, 0, 0);
1742 string_char_and_length ((const unsigned char *) s
, &len
);
1745 BYTEPOS (pos
) += len
;
1749 SET_TEXT_POS (pos
, charpos
, charpos
);
1755 /* Value is the number of characters in C string S. MULTIBYTE_P
1756 means recognize multibyte characters. */
1759 number_of_chars (const char *s
, bool multibyte_p
)
1765 ptrdiff_t rest
= strlen (s
);
1767 const unsigned char *p
= (const unsigned char *) s
;
1769 for (nchars
= 0; rest
> 0; ++nchars
)
1771 string_char_and_length (p
, &len
);
1772 rest
-= len
, p
+= len
;
1776 nchars
= strlen (s
);
1782 /* Compute byte position NEWPOS->bytepos corresponding to
1783 NEWPOS->charpos. POS is a known position in string STRING.
1784 NEWPOS->charpos must be >= POS.charpos. */
1787 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1789 eassert (STRINGP (string
));
1790 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1792 if (STRING_MULTIBYTE (string
))
1793 *newpos
= string_pos_nchars_ahead (pos
, string
,
1794 CHARPOS (*newpos
) - CHARPOS (pos
));
1796 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1800 Return an estimation of the pixel height of mode or header lines on
1801 frame F. FACE_ID specifies what line's height to estimate. */
1804 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1806 #ifdef HAVE_WINDOW_SYSTEM
1807 if (FRAME_WINDOW_P (f
))
1809 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1811 /* This function is called so early when Emacs starts that the face
1812 cache and mode line face are not yet initialized. */
1813 if (FRAME_FACE_CACHE (f
))
1815 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1819 height
= normal_char_height (face
->font
, -1);
1820 if (face
->box_line_width
> 0)
1821 height
+= 2 * face
->box_line_width
;
1832 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1833 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1834 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP, do
1835 not force the value into range. */
1838 pixel_to_glyph_coords (struct frame
*f
, int pix_x
, int pix_y
, int *x
, int *y
,
1839 NativeRectangle
*bounds
, bool noclip
)
1842 #ifdef HAVE_WINDOW_SYSTEM
1843 if (FRAME_WINDOW_P (f
))
1845 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1846 even for negative values. */
1848 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1850 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1852 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1853 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1856 STORE_NATIVE_RECT (*bounds
,
1857 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1858 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1859 FRAME_COLUMN_WIDTH (f
) - 1,
1860 FRAME_LINE_HEIGHT (f
) - 1);
1862 /* PXW: Should we clip pixels before converting to columns/lines? */
1867 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1868 pix_x
= FRAME_TOTAL_COLS (f
);
1872 else if (pix_y
> FRAME_TOTAL_LINES (f
))
1873 pix_y
= FRAME_TOTAL_LINES (f
);
1883 /* Find the glyph under window-relative coordinates X/Y in window W.
1884 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1885 strings. Return in *HPOS and *VPOS the row and column number of
1886 the glyph found. Return in *AREA the glyph area containing X.
1887 Value is a pointer to the glyph found or null if X/Y is not on
1888 text, or we can't tell because W's current matrix is not up to
1891 static struct glyph
*
1892 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1893 int *dx
, int *dy
, int *area
)
1895 struct glyph
*glyph
, *end
;
1896 struct glyph_row
*row
= NULL
;
1899 /* Find row containing Y. Give up if some row is not enabled. */
1900 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1902 row
= MATRIX_ROW (w
->current_matrix
, i
);
1903 if (!row
->enabled_p
)
1905 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1912 /* Give up if Y is not in the window. */
1913 if (i
== w
->current_matrix
->nrows
)
1916 /* Get the glyph area containing X. */
1917 if (w
->pseudo_window_p
)
1924 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1926 *area
= LEFT_MARGIN_AREA
;
1927 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1929 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1932 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1936 *area
= RIGHT_MARGIN_AREA
;
1937 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1941 /* Find glyph containing X. */
1942 glyph
= row
->glyphs
[*area
];
1943 end
= glyph
+ row
->used
[*area
];
1945 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1947 x
-= glyph
->pixel_width
;
1957 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1960 *hpos
= glyph
- row
->glyphs
[*area
];
1964 /* Convert frame-relative x/y to coordinates relative to window W.
1965 Takes pseudo-windows into account. */
1968 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1970 if (w
->pseudo_window_p
)
1972 /* A pseudo-window is always full-width, and starts at the
1973 left edge of the frame, plus a frame border. */
1974 struct frame
*f
= XFRAME (w
->frame
);
1975 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1976 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1980 *x
-= WINDOW_LEFT_EDGE_X (w
);
1981 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1985 #ifdef HAVE_WINDOW_SYSTEM
1988 Return in RECTS[] at most N clipping rectangles for glyph string S.
1989 Return the number of stored rectangles. */
1992 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1999 if (s
->row
->full_width_p
)
2001 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2002 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2003 if (s
->row
->mode_line_p
)
2004 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
) - WINDOW_RIGHT_DIVIDER_WIDTH (s
->w
);
2006 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
);
2008 /* Unless displaying a mode or menu bar line, which are always
2009 fully visible, clip to the visible part of the row. */
2010 if (s
->w
->pseudo_window_p
)
2011 r
.height
= s
->row
->visible_height
;
2013 r
.height
= s
->height
;
2017 /* This is a text line that may be partially visible. */
2018 r
.x
= window_box_left (s
->w
, s
->area
);
2019 r
.width
= window_box_width (s
->w
, s
->area
);
2020 r
.height
= s
->row
->visible_height
;
2024 if (r
.x
< s
->clip_head
->x
)
2026 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2027 r
.width
-= s
->clip_head
->x
- r
.x
;
2030 r
.x
= s
->clip_head
->x
;
2033 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2035 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2036 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2041 /* If S draws overlapping rows, it's sufficient to use the top and
2042 bottom of the window for clipping because this glyph string
2043 intentionally draws over other lines. */
2044 if (s
->for_overlaps
)
2046 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2047 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2049 /* Alas, the above simple strategy does not work for the
2050 environments with anti-aliased text: if the same text is
2051 drawn onto the same place multiple times, it gets thicker.
2052 If the overlap we are processing is for the erased cursor, we
2053 take the intersection with the rectangle of the cursor. */
2054 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2056 XRectangle rc
, r_save
= r
;
2058 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2059 rc
.y
= s
->w
->phys_cursor
.y
;
2060 rc
.width
= s
->w
->phys_cursor_width
;
2061 rc
.height
= s
->w
->phys_cursor_height
;
2063 x_intersect_rectangles (&r_save
, &rc
, &r
);
2068 /* Don't use S->y for clipping because it doesn't take partially
2069 visible lines into account. For example, it can be negative for
2070 partially visible lines at the top of a window. */
2071 if (!s
->row
->full_width_p
2072 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2073 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2075 r
.y
= max (0, s
->row
->y
);
2078 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2080 /* If drawing the cursor, don't let glyph draw outside its
2081 advertised boundaries. Cleartype does this under some circumstances. */
2082 if (s
->hl
== DRAW_CURSOR
)
2084 struct glyph
*glyph
= s
->first_glyph
;
2089 if (r
.width
>= s
->x
- r
.x
)
2090 r
.width
-= s
->x
- r
.x
;
2091 else /* R2L hscrolled row with cursor outside text area */
2095 r
.width
= min (r
.width
, glyph
->pixel_width
);
2097 /* If r.y is below window bottom, ensure that we still see a cursor. */
2098 height
= min (glyph
->ascent
+ glyph
->descent
,
2099 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2100 max_y
= window_text_bottom_y (s
->w
) - height
;
2101 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2102 if (s
->ybase
- glyph
->ascent
> max_y
)
2109 /* Don't draw cursor glyph taller than our actual glyph. */
2110 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2111 if (height
< r
.height
)
2113 max_y
= r
.y
+ r
.height
;
2114 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2115 r
.height
= min (max_y
- r
.y
, height
);
2122 XRectangle r_save
= r
;
2124 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2128 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2129 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2131 #ifdef CONVERT_FROM_XRECT
2132 CONVERT_FROM_XRECT (r
, *rects
);
2140 /* If we are processing overlapping and allowed to return
2141 multiple clipping rectangles, we exclude the row of the glyph
2142 string from the clipping rectangle. This is to avoid drawing
2143 the same text on the environment with anti-aliasing. */
2144 #ifdef CONVERT_FROM_XRECT
2147 XRectangle
*rs
= rects
;
2149 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2151 if (s
->for_overlaps
& OVERLAPS_PRED
)
2154 if (r
.y
+ r
.height
> row_y
)
2157 rs
[i
].height
= row_y
- r
.y
;
2163 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2166 if (r
.y
< row_y
+ s
->row
->visible_height
)
2168 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2170 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2171 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2180 #ifdef CONVERT_FROM_XRECT
2181 for (i
= 0; i
< n
; i
++)
2182 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2189 Return in *NR the clipping rectangle for glyph string S. */
2192 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2194 get_glyph_string_clip_rects (s
, nr
, 1);
2199 Return the position and height of the phys cursor in window W.
2200 Set w->phys_cursor_width to width of phys cursor.
2204 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2205 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2207 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2208 int x
, y
, wd
, h
, h0
, y0
, ascent
;
2210 /* Compute the width of the rectangle to draw. If on a stretch
2211 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2212 rectangle as wide as the glyph, but use a canonical character
2214 wd
= glyph
->pixel_width
;
2216 x
= w
->phys_cursor
.x
;
2223 if (glyph
->type
== STRETCH_GLYPH
2224 && !x_stretch_cursor_p
)
2225 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2226 w
->phys_cursor_width
= wd
;
2228 /* Don't let the hollow cursor glyph descend below the glyph row's
2229 ascent value, lest the hollow cursor looks funny. */
2230 y
= w
->phys_cursor
.y
;
2231 ascent
= row
->ascent
;
2232 if (row
->ascent
< glyph
->ascent
)
2234 y
=- glyph
->ascent
- row
->ascent
;
2235 ascent
= glyph
->ascent
;
2238 /* If y is below window bottom, ensure that we still see a cursor. */
2239 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2241 h
= max (h0
, ascent
+ glyph
->descent
);
2242 h0
= min (h0
, ascent
+ glyph
->descent
);
2244 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2247 h
= max (h
- (y0
- y
) + 1, h0
);
2252 y0
= window_text_bottom_y (w
) - h0
;
2260 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2261 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2266 * Remember which glyph the mouse is over.
2270 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2274 struct glyph_row
*r
, *gr
, *end_row
;
2275 enum window_part part
;
2276 enum glyph_row_area area
;
2277 int x
, y
, width
, height
;
2279 /* Try to determine frame pixel position and size of the glyph under
2280 frame pixel coordinates X/Y on frame F. */
2282 if (window_resize_pixelwise
)
2287 else if (!f
->glyphs_initialized_p
2288 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, false),
2291 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2292 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2296 w
= XWINDOW (window
);
2297 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2298 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2300 x
= window_relative_x_coord (w
, part
, gx
);
2301 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2303 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2304 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2306 if (w
->pseudo_window_p
)
2309 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2315 case ON_LEFT_MARGIN
:
2316 area
= LEFT_MARGIN_AREA
;
2319 case ON_RIGHT_MARGIN
:
2320 area
= RIGHT_MARGIN_AREA
;
2323 case ON_HEADER_LINE
:
2325 gr
= (part
== ON_HEADER_LINE
2326 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2327 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2330 goto text_glyph_row_found
;
2337 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2338 if (r
->y
+ r
->height
> y
)
2344 text_glyph_row_found
:
2347 struct glyph
*g
= gr
->glyphs
[area
];
2348 struct glyph
*end
= g
+ gr
->used
[area
];
2350 height
= gr
->height
;
2351 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2352 if (gx
+ g
->pixel_width
> x
)
2357 if (g
->type
== IMAGE_GLYPH
)
2359 /* Don't remember when mouse is over image, as
2360 image may have hot-spots. */
2361 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2364 width
= g
->pixel_width
;
2368 /* Use nominal char spacing at end of line. */
2370 gx
+= (x
/ width
) * width
;
2373 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2375 gx
+= window_box_left_offset (w
, area
);
2376 /* Don't expand over the modeline to make sure the vertical
2377 drag cursor is shown early enough. */
2378 height
= min (height
,
2379 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2384 /* Use nominal line height at end of window. */
2385 gx
= (x
/ width
) * width
;
2387 gy
+= (y
/ height
) * height
;
2388 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2389 /* See comment above. */
2390 height
= min (height
,
2391 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2395 case ON_LEFT_FRINGE
:
2396 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2397 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2398 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2399 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2402 case ON_RIGHT_FRINGE
:
2403 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2404 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2405 : window_box_right_offset (w
, TEXT_AREA
));
2406 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
2407 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
2408 && !WINDOW_RIGHTMOST_P (w
))
2409 if (gx
< WINDOW_PIXEL_WIDTH (w
) - width
)
2410 /* Make sure the vertical border can get her own glyph to the
2411 right of the one we build here. */
2412 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
) - width
;
2414 width
= WINDOW_PIXEL_WIDTH (w
) - gx
;
2416 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2420 case ON_VERTICAL_BORDER
:
2421 gx
= WINDOW_PIXEL_WIDTH (w
) - width
;
2424 case ON_VERTICAL_SCROLL_BAR
:
2425 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2427 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2428 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2429 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2431 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2435 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2436 if (r
->y
+ r
->height
> y
)
2443 height
= gr
->height
;
2446 /* Use nominal line height at end of window. */
2448 gy
+= (y
/ height
) * height
;
2452 case ON_RIGHT_DIVIDER
:
2453 gx
= WINDOW_PIXEL_WIDTH (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2454 width
= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2456 /* The bottom divider prevails. */
2457 height
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2460 case ON_BOTTOM_DIVIDER
:
2462 width
= WINDOW_PIXEL_WIDTH (w
);
2463 gy
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2464 height
= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2470 /* If there is no glyph under the mouse, then we divide the screen
2471 into a grid of the smallest glyph in the frame, and use that
2474 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2475 round down even for negative values. */
2481 gx
= (gx
/ width
) * width
;
2482 gy
= (gy
/ height
) * height
;
2488 gx
+= WINDOW_LEFT_EDGE_X (w
);
2489 gy
+= WINDOW_TOP_EDGE_Y (w
);
2492 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2494 /* Visible feedback for debugging. */
2495 #if false && defined HAVE_X_WINDOWS
2496 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2497 f
->output_data
.x
->normal_gc
,
2498 gx
, gy
, width
, height
);
2503 #endif /* HAVE_WINDOW_SYSTEM */
2506 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2509 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2510 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2512 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2515 /***********************************************************************
2516 Lisp form evaluation
2517 ***********************************************************************/
2519 /* Error handler for safe_eval and safe_call. */
2522 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2524 add_to_log ("Error during redisplay: %S signaled %S",
2525 Flist (nargs
, args
), arg
);
2529 /* Call function FUNC with the rest of NARGS - 1 arguments
2530 following. Return the result, or nil if something went
2531 wrong. Prevent redisplay during the evaluation. */
2534 safe__call (bool inhibit_quit
, ptrdiff_t nargs
, Lisp_Object func
, va_list ap
)
2538 if (inhibit_eval_during_redisplay
)
2543 ptrdiff_t count
= SPECPDL_INDEX ();
2546 SAFE_ALLOCA_LISP (args
, nargs
);
2549 for (i
= 1; i
< nargs
; i
++)
2550 args
[i
] = va_arg (ap
, Lisp_Object
);
2552 specbind (Qinhibit_redisplay
, Qt
);
2554 specbind (Qinhibit_quit
, Qt
);
2555 /* Use Qt to ensure debugger does not run,
2556 so there is no possibility of wanting to redisplay. */
2557 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2560 val
= unbind_to (count
, val
);
2567 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2572 va_start (ap
, func
);
2573 retval
= safe__call (false, nargs
, func
, ap
);
2578 /* Call function FN with one argument ARG.
2579 Return the result, or nil if something went wrong. */
2582 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2584 return safe_call (2, fn
, arg
);
2588 safe__call1 (bool inhibit_quit
, Lisp_Object fn
, ...)
2594 retval
= safe__call (inhibit_quit
, 2, fn
, ap
);
2600 safe_eval (Lisp_Object sexpr
)
2602 return safe__call1 (false, Qeval
, sexpr
);
2606 safe__eval (bool inhibit_quit
, Lisp_Object sexpr
)
2608 return safe__call1 (inhibit_quit
, Qeval
, sexpr
);
2611 /* Call function FN with two arguments ARG1 and ARG2.
2612 Return the result, or nil if something went wrong. */
2615 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2617 return safe_call (3, fn
, arg1
, arg2
);
2622 /***********************************************************************
2624 ***********************************************************************/
2626 /* Define CHECK_IT to perform sanity checks on iterators.
2627 This is for debugging. It is too slow to do unconditionally. */
2630 CHECK_IT (struct it
*it
)
2633 if (it
->method
== GET_FROM_STRING
)
2635 eassert (STRINGP (it
->string
));
2636 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2640 eassert (IT_STRING_CHARPOS (*it
) < 0);
2641 if (it
->method
== GET_FROM_BUFFER
)
2643 /* Check that character and byte positions agree. */
2644 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2649 eassert (it
->current
.dpvec_index
>= 0);
2651 eassert (it
->current
.dpvec_index
< 0);
2656 /* Check that the window end of window W is what we expect it
2657 to be---the last row in the current matrix displaying text. */
2660 CHECK_WINDOW_END (struct window
*w
)
2662 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2663 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2665 struct glyph_row
*row
;
2666 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2668 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2669 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2674 /***********************************************************************
2675 Iterator initialization
2676 ***********************************************************************/
2678 /* Initialize IT for displaying current_buffer in window W, starting
2679 at character position CHARPOS. CHARPOS < 0 means that no buffer
2680 position is specified which is useful when the iterator is assigned
2681 a position later. BYTEPOS is the byte position corresponding to
2684 If ROW is not null, calls to produce_glyphs with IT as parameter
2685 will produce glyphs in that row.
2687 BASE_FACE_ID is the id of a base face to use. It must be one of
2688 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2689 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2690 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2692 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2693 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2694 will be initialized to use the corresponding mode line glyph row of
2695 the desired matrix of W. */
2698 init_iterator (struct it
*it
, struct window
*w
,
2699 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2700 struct glyph_row
*row
, enum face_id base_face_id
)
2702 enum face_id remapped_base_face_id
= base_face_id
;
2704 /* Some precondition checks. */
2705 eassert (w
!= NULL
&& it
!= NULL
);
2706 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2709 /* If face attributes have been changed since the last redisplay,
2710 free realized faces now because they depend on face definitions
2711 that might have changed. Don't free faces while there might be
2712 desired matrices pending which reference these faces. */
2713 if (!inhibit_free_realized_faces
)
2717 face_change
= false;
2718 free_all_realized_faces (Qnil
);
2720 else if (XFRAME (w
->frame
)->face_change
)
2722 XFRAME (w
->frame
)->face_change
= 0;
2723 free_all_realized_faces (w
->frame
);
2727 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2728 if (! NILP (Vface_remapping_alist
))
2729 remapped_base_face_id
2730 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2732 /* Use one of the mode line rows of W's desired matrix if
2736 if (base_face_id
== MODE_LINE_FACE_ID
2737 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2738 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2739 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2740 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2743 /* Clear IT, and set it->object and other IT's Lisp objects to Qnil.
2744 Other parts of redisplay rely on that. */
2745 memclear (it
, sizeof *it
);
2746 it
->current
.overlay_string_index
= -1;
2747 it
->current
.dpvec_index
= -1;
2748 it
->base_face_id
= remapped_base_face_id
;
2749 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2750 it
->paragraph_embedding
= L2R
;
2753 /* The window in which we iterate over current_buffer: */
2754 XSETWINDOW (it
->window
, w
);
2756 it
->f
= XFRAME (w
->frame
);
2760 /* Extra space between lines (on window systems only). */
2761 if (base_face_id
== DEFAULT_FACE_ID
2762 && FRAME_WINDOW_P (it
->f
))
2764 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2765 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2766 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2767 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2768 * FRAME_LINE_HEIGHT (it
->f
));
2769 else if (it
->f
->extra_line_spacing
> 0)
2770 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2773 /* If realized faces have been removed, e.g. because of face
2774 attribute changes of named faces, recompute them. When running
2775 in batch mode, the face cache of the initial frame is null. If
2776 we happen to get called, make a dummy face cache. */
2777 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2778 init_frame_faces (it
->f
);
2779 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2780 recompute_basic_faces (it
->f
);
2782 it
->override_ascent
= -1;
2784 /* Are control characters displayed as `^C'? */
2785 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2787 /* -1 means everything between a CR and the following line end
2788 is invisible. >0 means lines indented more than this value are
2790 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2792 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2794 : (!NILP (BVAR (current_buffer
, selective_display
))
2796 it
->selective_display_ellipsis_p
2797 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2799 /* Display table to use. */
2800 it
->dp
= window_display_table (w
);
2802 /* Are multibyte characters enabled in current_buffer? */
2803 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2805 /* Get the position at which the redisplay_end_trigger hook should
2806 be run, if it is to be run at all. */
2807 if (MARKERP (w
->redisplay_end_trigger
)
2808 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2809 it
->redisplay_end_trigger_charpos
2810 = marker_position (w
->redisplay_end_trigger
);
2811 else if (INTEGERP (w
->redisplay_end_trigger
))
2812 it
->redisplay_end_trigger_charpos
2813 = clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
),
2816 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2818 /* Are lines in the display truncated? */
2820 it
->line_wrap
= TRUNCATE
;
2821 if (base_face_id
== DEFAULT_FACE_ID
2823 && (WINDOW_FULL_WIDTH_P (it
->w
)
2824 || NILP (Vtruncate_partial_width_windows
)
2825 || (INTEGERP (Vtruncate_partial_width_windows
)
2826 /* PXW: Shall we do something about this? */
2827 && (XINT (Vtruncate_partial_width_windows
)
2828 <= WINDOW_TOTAL_COLS (it
->w
))))
2829 && NILP (BVAR (current_buffer
, truncate_lines
)))
2830 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2831 ? WINDOW_WRAP
: WORD_WRAP
;
2833 /* Get dimensions of truncation and continuation glyphs. These are
2834 displayed as fringe bitmaps under X, but we need them for such
2835 frames when the fringes are turned off. But leave the dimensions
2836 zero for tooltip frames, as these glyphs look ugly there and also
2837 sabotage calculations of tooltip dimensions in x-show-tip. */
2838 #ifdef HAVE_WINDOW_SYSTEM
2839 if (!(FRAME_WINDOW_P (it
->f
)
2840 && FRAMEP (tip_frame
)
2841 && it
->f
== XFRAME (tip_frame
)))
2844 if (it
->line_wrap
== TRUNCATE
)
2846 /* We will need the truncation glyph. */
2847 eassert (it
->glyph_row
== NULL
);
2848 produce_special_glyphs (it
, IT_TRUNCATION
);
2849 it
->truncation_pixel_width
= it
->pixel_width
;
2853 /* We will need the continuation glyph. */
2854 eassert (it
->glyph_row
== NULL
);
2855 produce_special_glyphs (it
, IT_CONTINUATION
);
2856 it
->continuation_pixel_width
= it
->pixel_width
;
2860 /* Reset these values to zero because the produce_special_glyphs
2861 above has changed them. */
2862 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2863 it
->phys_ascent
= it
->phys_descent
= 0;
2865 /* Set this after getting the dimensions of truncation and
2866 continuation glyphs, so that we don't produce glyphs when calling
2867 produce_special_glyphs, above. */
2868 it
->glyph_row
= row
;
2869 it
->area
= TEXT_AREA
;
2871 /* Get the dimensions of the display area. The display area
2872 consists of the visible window area plus a horizontally scrolled
2873 part to the left of the window. All x-values are relative to the
2874 start of this total display area. */
2875 if (base_face_id
!= DEFAULT_FACE_ID
)
2877 /* Mode lines, menu bar in terminal frames. */
2878 it
->first_visible_x
= 0;
2879 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2884 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2885 it
->last_visible_x
= (it
->first_visible_x
2886 + window_box_width (w
, TEXT_AREA
));
2888 /* If we truncate lines, leave room for the truncation glyph(s) at
2889 the right margin. Otherwise, leave room for the continuation
2890 glyph(s). Done only if the window has no right fringe. */
2891 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
2893 if (it
->line_wrap
== TRUNCATE
)
2894 it
->last_visible_x
-= it
->truncation_pixel_width
;
2896 it
->last_visible_x
-= it
->continuation_pixel_width
;
2899 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2900 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2903 /* Leave room for a border glyph. */
2904 if (!FRAME_WINDOW_P (it
->f
)
2905 && !WINDOW_RIGHTMOST_P (it
->w
))
2906 it
->last_visible_x
-= 1;
2908 it
->last_visible_y
= window_text_bottom_y (w
);
2910 /* For mode lines and alike, arrange for the first glyph having a
2911 left box line if the face specifies a box. */
2912 if (base_face_id
!= DEFAULT_FACE_ID
)
2916 it
->face_id
= remapped_base_face_id
;
2918 /* If we have a boxed mode line, make the first character appear
2919 with a left box line. */
2920 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2921 if (face
&& face
->box
!= FACE_NO_BOX
)
2922 it
->start_of_box_run_p
= true;
2925 /* If a buffer position was specified, set the iterator there,
2926 getting overlays and face properties from that position. */
2927 if (charpos
>= BUF_BEG (current_buffer
))
2929 it
->stop_charpos
= charpos
;
2930 it
->end_charpos
= ZV
;
2931 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2932 IT_CHARPOS (*it
) = charpos
;
2933 IT_BYTEPOS (*it
) = bytepos
;
2935 /* We will rely on `reseat' to set this up properly, via
2936 handle_face_prop. */
2937 it
->face_id
= it
->base_face_id
;
2939 it
->start
= it
->current
;
2940 /* Do we need to reorder bidirectional text? Not if this is a
2941 unibyte buffer: by definition, none of the single-byte
2942 characters are strong R2L, so no reordering is needed. And
2943 bidi.c doesn't support unibyte buffers anyway. Also, don't
2944 reorder while we are loading loadup.el, since the tables of
2945 character properties needed for reordering are not yet
2949 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2952 /* If we are to reorder bidirectional text, init the bidi
2956 /* Since we don't know at this point whether there will be
2957 any R2L lines in the window, we reserve space for
2958 truncation/continuation glyphs even if only the left
2959 fringe is absent. */
2960 if (base_face_id
== DEFAULT_FACE_ID
2961 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
2962 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
2964 if (it
->line_wrap
== TRUNCATE
)
2965 it
->last_visible_x
-= it
->truncation_pixel_width
;
2967 it
->last_visible_x
-= it
->continuation_pixel_width
;
2969 /* Note the paragraph direction that this buffer wants to
2971 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2973 it
->paragraph_embedding
= L2R
;
2974 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2976 it
->paragraph_embedding
= R2L
;
2978 it
->paragraph_embedding
= NEUTRAL_DIR
;
2979 bidi_unshelve_cache (NULL
, false);
2980 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2984 /* Compute faces etc. */
2985 reseat (it
, it
->current
.pos
, true);
2992 /* Initialize IT for the display of window W with window start POS. */
2995 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2997 struct glyph_row
*row
;
2998 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
3000 row
= w
->desired_matrix
->rows
+ first_vpos
;
3001 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
3002 it
->first_vpos
= first_vpos
;
3004 /* Don't reseat to previous visible line start if current start
3005 position is in a string or image. */
3006 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
3008 int first_y
= it
->current_y
;
3010 /* If window start is not at a line start, skip forward to POS to
3011 get the correct continuation lines width. */
3012 bool start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3013 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3014 if (!start_at_line_beg_p
)
3018 reseat_at_previous_visible_line_start (it
);
3019 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3021 new_x
= it
->current_x
+ it
->pixel_width
;
3023 /* If lines are continued, this line may end in the middle
3024 of a multi-glyph character (e.g. a control character
3025 displayed as \003, or in the middle of an overlay
3026 string). In this case move_it_to above will not have
3027 taken us to the start of the continuation line but to the
3028 end of the continued line. */
3029 if (it
->current_x
> 0
3030 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3031 && (/* And glyph doesn't fit on the line. */
3032 new_x
> it
->last_visible_x
3033 /* Or it fits exactly and we're on a window
3035 || (new_x
== it
->last_visible_x
3036 && FRAME_WINDOW_P (it
->f
)
3037 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3038 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3039 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3041 if ((it
->current
.dpvec_index
>= 0
3042 || it
->current
.overlay_string_index
>= 0)
3043 /* If we are on a newline from a display vector or
3044 overlay string, then we are already at the end of
3045 a screen line; no need to go to the next line in
3046 that case, as this line is not really continued.
3047 (If we do go to the next line, C-e will not DTRT.) */
3050 set_iterator_to_next (it
, true);
3051 move_it_in_display_line_to (it
, -1, -1, 0);
3054 it
->continuation_lines_width
+= it
->current_x
;
3056 /* If the character at POS is displayed via a display
3057 vector, move_it_to above stops at the final glyph of
3058 IT->dpvec. To make the caller redisplay that character
3059 again (a.k.a. start at POS), we need to reset the
3060 dpvec_index to the beginning of IT->dpvec. */
3061 else if (it
->current
.dpvec_index
>= 0)
3062 it
->current
.dpvec_index
= 0;
3064 /* We're starting a new display line, not affected by the
3065 height of the continued line, so clear the appropriate
3066 fields in the iterator structure. */
3067 it
->max_ascent
= it
->max_descent
= 0;
3068 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3070 it
->current_y
= first_y
;
3072 it
->current_x
= it
->hpos
= 0;
3078 /* Return true if POS is a position in ellipses displayed for invisible
3079 text. W is the window we display, for text property lookup. */
3082 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3084 Lisp_Object prop
, window
;
3085 bool ellipses_p
= false;
3086 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3088 /* If POS specifies a position in a display vector, this might
3089 be for an ellipsis displayed for invisible text. We won't
3090 get the iterator set up for delivering that ellipsis unless
3091 we make sure that it gets aware of the invisible text. */
3092 if (pos
->dpvec_index
>= 0
3093 && pos
->overlay_string_index
< 0
3094 && CHARPOS (pos
->string_pos
) < 0
3096 && (XSETWINDOW (window
, w
),
3097 prop
= Fget_char_property (make_number (charpos
),
3098 Qinvisible
, window
),
3099 TEXT_PROP_MEANS_INVISIBLE (prop
) == 0))
3101 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3103 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3110 /* Initialize IT for stepping through current_buffer in window W,
3111 starting at position POS that includes overlay string and display
3112 vector/ control character translation position information. Value
3113 is false if there are overlay strings with newlines at POS. */
3116 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3118 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3120 bool overlay_strings_with_newlines
= false;
3122 /* If POS specifies a position in a display vector, this might
3123 be for an ellipsis displayed for invisible text. We won't
3124 get the iterator set up for delivering that ellipsis unless
3125 we make sure that it gets aware of the invisible text. */
3126 if (in_ellipses_for_invisible_text_p (pos
, w
))
3132 /* Keep in mind: the call to reseat in init_iterator skips invisible
3133 text, so we might end up at a position different from POS. This
3134 is only a problem when POS is a row start after a newline and an
3135 overlay starts there with an after-string, and the overlay has an
3136 invisible property. Since we don't skip invisible text in
3137 display_line and elsewhere immediately after consuming the
3138 newline before the row start, such a POS will not be in a string,
3139 but the call to init_iterator below will move us to the
3141 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3143 /* This only scans the current chunk -- it should scan all chunks.
3144 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3145 to 16 in 22.1 to make this a lesser problem. */
3146 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3148 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3149 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3151 while (s
< e
&& *s
!= '\n')
3156 overlay_strings_with_newlines
= true;
3161 /* If position is within an overlay string, set up IT to the right
3163 if (pos
->overlay_string_index
>= 0)
3167 /* If the first overlay string happens to have a `display'
3168 property for an image, the iterator will be set up for that
3169 image, and we have to undo that setup first before we can
3170 correct the overlay string index. */
3171 if (it
->method
== GET_FROM_IMAGE
)
3174 /* We already have the first chunk of overlay strings in
3175 IT->overlay_strings. Load more until the one for
3176 pos->overlay_string_index is in IT->overlay_strings. */
3177 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3179 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3180 it
->current
.overlay_string_index
= 0;
3183 load_overlay_strings (it
, 0);
3184 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3188 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3189 relative_index
= (it
->current
.overlay_string_index
3190 % OVERLAY_STRING_CHUNK_SIZE
);
3191 it
->string
= it
->overlay_strings
[relative_index
];
3192 eassert (STRINGP (it
->string
));
3193 it
->current
.string_pos
= pos
->string_pos
;
3194 it
->method
= GET_FROM_STRING
;
3195 it
->end_charpos
= SCHARS (it
->string
);
3196 /* Set up the bidi iterator for this overlay string. */
3199 it
->bidi_it
.string
.lstring
= it
->string
;
3200 it
->bidi_it
.string
.s
= NULL
;
3201 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3202 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3203 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3204 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3205 it
->bidi_it
.w
= it
->w
;
3206 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3207 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3209 /* Synchronize the state of the bidi iterator with
3210 pos->string_pos. For any string position other than
3211 zero, this will be done automagically when we resume
3212 iteration over the string and get_visually_first_element
3213 is called. But if string_pos is zero, and the string is
3214 to be reordered for display, we need to resync manually,
3215 since it could be that the iteration state recorded in
3216 pos ended at string_pos of 0 moving backwards in string. */
3217 if (CHARPOS (pos
->string_pos
) == 0)
3219 get_visually_first_element (it
);
3220 if (IT_STRING_CHARPOS (*it
) != 0)
3223 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3224 bidi_move_to_visually_next (&it
->bidi_it
);
3225 } while (it
->bidi_it
.charpos
!= 0);
3227 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3228 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3232 if (CHARPOS (pos
->string_pos
) >= 0)
3234 /* Recorded position is not in an overlay string, but in another
3235 string. This can only be a string from a `display' property.
3236 IT should already be filled with that string. */
3237 it
->current
.string_pos
= pos
->string_pos
;
3238 eassert (STRINGP (it
->string
));
3240 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3241 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3244 /* Restore position in display vector translations, control
3245 character translations or ellipses. */
3246 if (pos
->dpvec_index
>= 0)
3248 if (it
->dpvec
== NULL
)
3249 get_next_display_element (it
);
3250 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3251 it
->current
.dpvec_index
= pos
->dpvec_index
;
3255 return !overlay_strings_with_newlines
;
3259 /* Initialize IT for stepping through current_buffer in window W
3260 starting at ROW->start. */
3263 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3265 init_from_display_pos (it
, w
, &row
->start
);
3266 it
->start
= row
->start
;
3267 it
->continuation_lines_width
= row
->continuation_lines_width
;
3272 /* Initialize IT for stepping through current_buffer in window W
3273 starting in the line following ROW, i.e. starting at ROW->end.
3274 Value is false if there are overlay strings with newlines at ROW's
3278 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3280 bool success
= false;
3282 if (init_from_display_pos (it
, w
, &row
->end
))
3284 if (row
->continued_p
)
3285 it
->continuation_lines_width
3286 = row
->continuation_lines_width
+ row
->pixel_width
;
3297 /***********************************************************************
3299 ***********************************************************************/
3301 /* Called when IT reaches IT->stop_charpos. Handle text property and
3302 overlay changes. Set IT->stop_charpos to the next position where
3306 handle_stop (struct it
*it
)
3308 enum prop_handled handled
;
3309 bool handle_overlay_change_p
;
3313 it
->current
.dpvec_index
= -1;
3314 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3315 it
->ellipsis_p
= false;
3317 /* Use face of preceding text for ellipsis (if invisible) */
3318 if (it
->selective_display_ellipsis_p
)
3319 it
->saved_face_id
= it
->face_id
;
3321 /* Here's the description of the semantics of, and the logic behind,
3322 the various HANDLED_* statuses:
3324 HANDLED_NORMALLY means the handler did its job, and the loop
3325 should proceed to calling the next handler in order.
3327 HANDLED_RECOMPUTE_PROPS means the handler caused a significant
3328 change in the properties and overlays at current position, so the
3329 loop should be restarted, to re-invoke the handlers that were
3330 already called. This happens when fontification-functions were
3331 called by handle_fontified_prop, and actually fontified
3332 something. Another case where HANDLED_RECOMPUTE_PROPS is
3333 returned is when we discover overlay strings that need to be
3334 displayed right away. The loop below will continue for as long
3335 as the status is HANDLED_RECOMPUTE_PROPS.
3337 HANDLED_RETURN means return immediately to the caller, to
3338 continue iteration without calling any further handlers. This is
3339 used when we need to act on some property right away, for example
3340 when we need to display the ellipsis or a replacing display
3341 property, such as display string or image.
3343 HANDLED_OVERLAY_STRING_CONSUMED means an overlay string was just
3344 consumed, and the handler switched to the next overlay string.
3345 This signals the loop below to refrain from looking for more
3346 overlays before all the overlay strings of the current overlay
3349 Some of the handlers called by the loop push the iterator state
3350 onto the stack (see 'push_it'), and arrange for the iteration to
3351 continue with another object, such as an image, a display string,
3352 or an overlay string. In most such cases, it->stop_charpos is
3353 set to the first character of the string, so that when the
3354 iteration resumes, this function will immediately be called
3355 again, to examine the properties at the beginning of the string.
3357 When a display or overlay string is exhausted, the iterator state
3358 is popped (see 'pop_it'), and iteration continues with the
3359 previous object. Again, in many such cases this function is
3360 called again to find the next position where properties might
3365 handled
= HANDLED_NORMALLY
;
3367 /* Call text property handlers. */
3368 for (p
= it_props
; p
->handler
; ++p
)
3370 handled
= p
->handler (it
);
3372 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3374 else if (handled
== HANDLED_RETURN
)
3376 /* We still want to show before and after strings from
3377 overlays even if the actual buffer text is replaced. */
3378 if (!handle_overlay_change_p
3380 /* Don't call get_overlay_strings_1 if we already
3381 have overlay strings loaded, because doing so
3382 will load them again and push the iterator state
3383 onto the stack one more time, which is not
3384 expected by the rest of the code that processes
3386 || (it
->current
.overlay_string_index
< 0
3387 && !get_overlay_strings_1 (it
, 0, false)))
3390 setup_for_ellipsis (it
, 0);
3391 /* When handling a display spec, we might load an
3392 empty string. In that case, discard it here. We
3393 used to discard it in handle_single_display_spec,
3394 but that causes get_overlay_strings_1, above, to
3395 ignore overlay strings that we must check. */
3396 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3400 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3404 it
->string_from_display_prop_p
= false;
3405 it
->from_disp_prop_p
= false;
3406 handle_overlay_change_p
= false;
3408 handled
= HANDLED_RECOMPUTE_PROPS
;
3411 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3412 handle_overlay_change_p
= false;
3415 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3417 /* Don't check for overlay strings below when set to deliver
3418 characters from a display vector. */
3419 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3420 handle_overlay_change_p
= false;
3422 /* Handle overlay changes.
3423 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3424 if it finds overlays. */
3425 if (handle_overlay_change_p
)
3426 handled
= handle_overlay_change (it
);
3431 setup_for_ellipsis (it
, 0);
3435 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3437 /* Determine where to stop next. */
3438 if (handled
== HANDLED_NORMALLY
)
3439 compute_stop_pos (it
);
3443 /* Compute IT->stop_charpos from text property and overlay change
3444 information for IT's current position. */
3447 compute_stop_pos (struct it
*it
)
3449 register INTERVAL iv
, next_iv
;
3450 Lisp_Object object
, limit
, position
;
3451 ptrdiff_t charpos
, bytepos
;
3453 if (STRINGP (it
->string
))
3455 /* Strings are usually short, so don't limit the search for
3457 it
->stop_charpos
= it
->end_charpos
;
3458 object
= it
->string
;
3460 charpos
= IT_STRING_CHARPOS (*it
);
3461 bytepos
= IT_STRING_BYTEPOS (*it
);
3467 /* If end_charpos is out of range for some reason, such as a
3468 misbehaving display function, rationalize it (Bug#5984). */
3469 if (it
->end_charpos
> ZV
)
3470 it
->end_charpos
= ZV
;
3471 it
->stop_charpos
= it
->end_charpos
;
3473 /* If next overlay change is in front of the current stop pos
3474 (which is IT->end_charpos), stop there. Note: value of
3475 next_overlay_change is point-max if no overlay change
3477 charpos
= IT_CHARPOS (*it
);
3478 bytepos
= IT_BYTEPOS (*it
);
3479 pos
= next_overlay_change (charpos
);
3480 if (pos
< it
->stop_charpos
)
3481 it
->stop_charpos
= pos
;
3483 /* Set up variables for computing the stop position from text
3484 property changes. */
3485 XSETBUFFER (object
, current_buffer
);
3486 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3489 /* Get the interval containing IT's position. Value is a null
3490 interval if there isn't such an interval. */
3491 position
= make_number (charpos
);
3492 iv
= validate_interval_range (object
, &position
, &position
, false);
3495 Lisp_Object values_here
[LAST_PROP_IDX
];
3498 /* Get properties here. */
3499 for (p
= it_props
; p
->handler
; ++p
)
3500 values_here
[p
->idx
] = textget (iv
->plist
,
3501 builtin_lisp_symbol (p
->name
));
3503 /* Look for an interval following iv that has different
3505 for (next_iv
= next_interval (iv
);
3508 || XFASTINT (limit
) > next_iv
->position
));
3509 next_iv
= next_interval (next_iv
))
3511 for (p
= it_props
; p
->handler
; ++p
)
3513 Lisp_Object new_value
= textget (next_iv
->plist
,
3514 builtin_lisp_symbol (p
->name
));
3515 if (!EQ (values_here
[p
->idx
], new_value
))
3525 if (INTEGERP (limit
)
3526 && next_iv
->position
>= XFASTINT (limit
))
3527 /* No text property change up to limit. */
3528 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3530 /* Text properties change in next_iv. */
3531 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3535 if (it
->cmp_it
.id
< 0)
3537 ptrdiff_t stoppos
= it
->end_charpos
;
3539 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3541 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3542 stoppos
, it
->string
);
3545 eassert (STRINGP (it
->string
)
3546 || (it
->stop_charpos
>= BEGV
3547 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3551 /* Return the position of the next overlay change after POS in
3552 current_buffer. Value is point-max if no overlay change
3553 follows. This is like `next-overlay-change' but doesn't use
3557 next_overlay_change (ptrdiff_t pos
)
3559 ptrdiff_t i
, noverlays
;
3561 Lisp_Object
*overlays
;
3564 /* Get all overlays at the given position. */
3565 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, true);
3567 /* If any of these overlays ends before endpos,
3568 use its ending point instead. */
3569 for (i
= 0; i
< noverlays
; ++i
)
3574 oend
= OVERLAY_END (overlays
[i
]);
3575 oendpos
= OVERLAY_POSITION (oend
);
3576 endpos
= min (endpos
, oendpos
);
3583 /* How many characters forward to search for a display property or
3584 display string. Searching too far forward makes the bidi display
3585 sluggish, especially in small windows. */
3586 #define MAX_DISP_SCAN 250
3588 /* Return the character position of a display string at or after
3589 position specified by POSITION. If no display string exists at or
3590 after POSITION, return ZV. A display string is either an overlay
3591 with `display' property whose value is a string, or a `display'
3592 text property whose value is a string. STRING is data about the
3593 string to iterate; if STRING->lstring is nil, we are iterating a
3594 buffer. FRAME_WINDOW_P is true when we are displaying a window
3595 on a GUI frame. DISP_PROP is set to zero if we searched
3596 MAX_DISP_SCAN characters forward without finding any display
3597 strings, non-zero otherwise. It is set to 2 if the display string
3598 uses any kind of `(space ...)' spec that will produce a stretch of
3599 white space in the text area. */
3601 compute_display_string_pos (struct text_pos
*position
,
3602 struct bidi_string_data
*string
,
3604 bool frame_window_p
, int *disp_prop
)
3606 /* OBJECT = nil means current buffer. */
3607 Lisp_Object object
, object1
;
3608 Lisp_Object pos
, spec
, limpos
;
3609 bool string_p
= string
&& (STRINGP (string
->lstring
) || string
->s
);
3610 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3611 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3612 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3614 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3615 struct text_pos tpos
;
3618 if (string
&& STRINGP (string
->lstring
))
3619 object1
= object
= string
->lstring
;
3620 else if (w
&& !string_p
)
3622 XSETWINDOW (object
, w
);
3626 object1
= object
= Qnil
;
3631 /* We don't support display properties whose values are strings
3632 that have display string properties. */
3633 || string
->from_disp_str
3634 /* C strings cannot have display properties. */
3635 || (string
->s
&& !STRINGP (object
)))
3641 /* If the character at CHARPOS is where the display string begins,
3643 pos
= make_number (charpos
);
3644 if (STRINGP (object
))
3645 bufpos
= string
->bufpos
;
3649 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3651 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3654 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3662 /* Look forward for the first character with a `display' property
3663 that will replace the underlying text when displayed. */
3664 limpos
= make_number (lim
);
3666 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3667 CHARPOS (tpos
) = XFASTINT (pos
);
3668 if (CHARPOS (tpos
) >= lim
)
3673 if (STRINGP (object
))
3674 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3676 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3677 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3678 if (!STRINGP (object
))
3679 bufpos
= CHARPOS (tpos
);
3680 } while (NILP (spec
)
3681 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3682 bufpos
, frame_window_p
)));
3686 return CHARPOS (tpos
);
3689 /* Return the character position of the end of the display string that
3690 started at CHARPOS. If there's no display string at CHARPOS,
3691 return -1. A display string is either an overlay with `display'
3692 property whose value is a string or a `display' text property whose
3693 value is a string. */
3695 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3697 /* OBJECT = nil means current buffer. */
3698 Lisp_Object object
=
3699 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3700 Lisp_Object pos
= make_number (charpos
);
3702 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3704 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3707 /* It could happen that the display property or overlay was removed
3708 since we found it in compute_display_string_pos above. One way
3709 this can happen is if JIT font-lock was called (through
3710 handle_fontified_prop), and jit-lock-functions remove text
3711 properties or overlays from the portion of buffer that includes
3712 CHARPOS. Muse mode is known to do that, for example. In this
3713 case, we return -1 to the caller, to signal that no display
3714 string is actually present at CHARPOS. See bidi_fetch_char for
3715 how this is handled.
3717 An alternative would be to never look for display properties past
3718 it->stop_charpos. But neither compute_display_string_pos nor
3719 bidi_fetch_char that calls it know or care where the next
3721 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3724 /* Look forward for the first character where the `display' property
3726 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3728 return XFASTINT (pos
);
3733 /***********************************************************************
3735 ***********************************************************************/
3737 /* Handle changes in the `fontified' property of the current buffer by
3738 calling hook functions from Qfontification_functions to fontify
3741 static enum prop_handled
3742 handle_fontified_prop (struct it
*it
)
3744 Lisp_Object prop
, pos
;
3745 enum prop_handled handled
= HANDLED_NORMALLY
;
3747 if (!NILP (Vmemory_full
))
3750 /* Get the value of the `fontified' property at IT's current buffer
3751 position. (The `fontified' property doesn't have a special
3752 meaning in strings.) If the value is nil, call functions from
3753 Qfontification_functions. */
3754 if (!STRINGP (it
->string
)
3756 && !NILP (Vfontification_functions
)
3757 && !NILP (Vrun_hooks
)
3758 && (pos
= make_number (IT_CHARPOS (*it
)),
3759 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3760 /* Ignore the special cased nil value always present at EOB since
3761 no amount of fontifying will be able to change it. */
3762 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3764 ptrdiff_t count
= SPECPDL_INDEX ();
3766 struct buffer
*obuf
= current_buffer
;
3767 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3768 bool old_clip_changed
= current_buffer
->clip_changed
;
3770 val
= Vfontification_functions
;
3771 specbind (Qfontification_functions
, Qnil
);
3773 eassert (it
->end_charpos
== ZV
);
3775 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3776 safe_call1 (val
, pos
);
3779 Lisp_Object fns
, fn
;
3783 for (; CONSP (val
); val
= XCDR (val
))
3789 /* A value of t indicates this hook has a local
3790 binding; it means to run the global binding too.
3791 In a global value, t should not occur. If it
3792 does, we must ignore it to avoid an endless
3794 for (fns
= Fdefault_value (Qfontification_functions
);
3800 safe_call1 (fn
, pos
);
3804 safe_call1 (fn
, pos
);
3808 unbind_to (count
, Qnil
);
3810 /* Fontification functions routinely call `save-restriction'.
3811 Normally, this tags clip_changed, which can confuse redisplay
3812 (see discussion in Bug#6671). Since we don't perform any
3813 special handling of fontification changes in the case where
3814 `save-restriction' isn't called, there's no point doing so in
3815 this case either. So, if the buffer's restrictions are
3816 actually left unchanged, reset clip_changed. */
3817 if (obuf
== current_buffer
)
3819 if (begv
== BEGV
&& zv
== ZV
)
3820 current_buffer
->clip_changed
= old_clip_changed
;
3822 /* There isn't much we can reasonably do to protect against
3823 misbehaving fontification, but here's a fig leaf. */
3824 else if (BUFFER_LIVE_P (obuf
))
3825 set_buffer_internal_1 (obuf
);
3827 /* The fontification code may have added/removed text.
3828 It could do even a lot worse, but let's at least protect against
3829 the most obvious case where only the text past `pos' gets changed',
3830 as is/was done in grep.el where some escapes sequences are turned
3831 into face properties (bug#7876). */
3832 it
->end_charpos
= ZV
;
3834 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3835 something. This avoids an endless loop if they failed to
3836 fontify the text for which reason ever. */
3837 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3838 handled
= HANDLED_RECOMPUTE_PROPS
;
3846 /***********************************************************************
3848 ***********************************************************************/
3850 /* Set up iterator IT from face properties at its current position.
3851 Called from handle_stop. */
3853 static enum prop_handled
3854 handle_face_prop (struct it
*it
)
3857 ptrdiff_t next_stop
;
3859 if (!STRINGP (it
->string
))
3862 = face_at_buffer_position (it
->w
,
3866 + TEXT_PROP_DISTANCE_LIMIT
),
3867 false, it
->base_face_id
);
3869 /* Is this a start of a run of characters with box face?
3870 Caveat: this can be called for a freshly initialized
3871 iterator; face_id is -1 in this case. We know that the new
3872 face will not change until limit, i.e. if the new face has a
3873 box, all characters up to limit will have one. But, as
3874 usual, we don't know whether limit is really the end. */
3875 if (new_face_id
!= it
->face_id
)
3877 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3878 /* If it->face_id is -1, old_face below will be NULL, see
3879 the definition of FACE_FROM_ID. This will happen if this
3880 is the initial call that gets the face. */
3881 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3883 /* If the value of face_id of the iterator is -1, we have to
3884 look in front of IT's position and see whether there is a
3885 face there that's different from new_face_id. */
3886 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3888 int prev_face_id
= face_before_it_pos (it
);
3890 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3893 /* If the new face has a box, but the old face does not,
3894 this is the start of a run of characters with box face,
3895 i.e. this character has a shadow on the left side. */
3896 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3897 && (old_face
== NULL
|| !old_face
->box
));
3898 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3906 Lisp_Object from_overlay
3907 = (it
->current
.overlay_string_index
>= 0
3908 ? it
->string_overlays
[it
->current
.overlay_string_index
3909 % OVERLAY_STRING_CHUNK_SIZE
]
3912 /* See if we got to this string directly or indirectly from
3913 an overlay property. That includes the before-string or
3914 after-string of an overlay, strings in display properties
3915 provided by an overlay, their text properties, etc.
3917 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3918 if (! NILP (from_overlay
))
3919 for (i
= it
->sp
- 1; i
>= 0; i
--)
3921 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3923 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3924 % OVERLAY_STRING_CHUNK_SIZE
];
3925 else if (! NILP (it
->stack
[i
].from_overlay
))
3926 from_overlay
= it
->stack
[i
].from_overlay
;
3928 if (!NILP (from_overlay
))
3932 if (! NILP (from_overlay
))
3934 bufpos
= IT_CHARPOS (*it
);
3935 /* For a string from an overlay, the base face depends
3936 only on text properties and ignores overlays. */
3938 = face_for_overlay_string (it
->w
,
3942 + TEXT_PROP_DISTANCE_LIMIT
),
3950 /* For strings from a `display' property, use the face at
3951 IT's current buffer position as the base face to merge
3952 with, so that overlay strings appear in the same face as
3953 surrounding text, unless they specify their own faces.
3954 For strings from wrap-prefix and line-prefix properties,
3955 use the default face, possibly remapped via
3956 Vface_remapping_alist. */
3957 /* Note that the fact that we use the face at _buffer_
3958 position means that a 'display' property on an overlay
3959 string will not inherit the face of that overlay string,
3960 but will instead revert to the face of buffer text
3961 covered by the overlay. This is visible, e.g., when the
3962 overlay specifies a box face, but neither the buffer nor
3963 the display string do. This sounds like a design bug,
3964 but Emacs always did that since v21.1, so changing that
3965 might be a big deal. */
3966 base_face_id
= it
->string_from_prefix_prop_p
3967 ? (!NILP (Vface_remapping_alist
)
3968 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3970 : underlying_face_id (it
);
3973 new_face_id
= face_at_string_position (it
->w
,
3975 IT_STRING_CHARPOS (*it
),
3978 base_face_id
, false);
3980 /* Is this a start of a run of characters with box? Caveat:
3981 this can be called for a freshly allocated iterator; face_id
3982 is -1 is this case. We know that the new face will not
3983 change until the next check pos, i.e. if the new face has a
3984 box, all characters up to that position will have a
3985 box. But, as usual, we don't know whether that position
3986 is really the end. */
3987 if (new_face_id
!= it
->face_id
)
3989 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3990 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3992 /* If new face has a box but old face hasn't, this is the
3993 start of a run of characters with box, i.e. it has a
3994 shadow on the left side. */
3995 it
->start_of_box_run_p
3996 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3997 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
4001 it
->face_id
= new_face_id
;
4002 return HANDLED_NORMALLY
;
4006 /* Return the ID of the face ``underlying'' IT's current position,
4007 which is in a string. If the iterator is associated with a
4008 buffer, return the face at IT's current buffer position.
4009 Otherwise, use the iterator's base_face_id. */
4012 underlying_face_id (struct it
*it
)
4014 int face_id
= it
->base_face_id
, i
;
4016 eassert (STRINGP (it
->string
));
4018 for (i
= it
->sp
- 1; i
>= 0; --i
)
4019 if (NILP (it
->stack
[i
].string
))
4020 face_id
= it
->stack
[i
].face_id
;
4026 /* Compute the face one character before or after the current position
4027 of IT, in the visual order. BEFORE_P means get the face
4028 in front (to the left in L2R paragraphs, to the right in R2L
4029 paragraphs) of IT's screen position. Value is the ID of the face. */
4032 face_before_or_after_it_pos (struct it
*it
, bool before_p
)
4035 ptrdiff_t next_check_charpos
;
4037 void *it_copy_data
= NULL
;
4039 eassert (it
->s
== NULL
);
4041 if (STRINGP (it
->string
))
4043 ptrdiff_t bufpos
, charpos
;
4046 /* No face change past the end of the string (for the case
4047 we are padding with spaces). No face change before the
4049 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
4050 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4055 /* Set charpos to the position before or after IT's current
4056 position, in the logical order, which in the non-bidi
4057 case is the same as the visual order. */
4059 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4060 else if (it
->what
== IT_COMPOSITION
)
4061 /* For composition, we must check the character after the
4063 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4065 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4071 /* With bidi iteration, the character before the current
4072 in the visual order cannot be found by simple
4073 iteration, because "reverse" reordering is not
4074 supported. Instead, we need to start from the string
4075 beginning and go all the way to the current string
4076 position, remembering the previous position. */
4077 /* Ignore face changes before the first visible
4078 character on this display line. */
4079 if (it
->current_x
<= it
->first_visible_x
)
4081 SAVE_IT (it_copy
, *it
, it_copy_data
);
4082 IT_STRING_CHARPOS (it_copy
) = 0;
4083 bidi_init_it (0, 0, FRAME_WINDOW_P (it_copy
.f
), &it_copy
.bidi_it
);
4087 charpos
= IT_STRING_CHARPOS (it_copy
);
4088 if (charpos
>= SCHARS (it
->string
))
4090 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4092 while (IT_STRING_CHARPOS (it_copy
) != IT_STRING_CHARPOS (*it
));
4094 RESTORE_IT (it
, it
, it_copy_data
);
4098 /* Set charpos to the string position of the character
4099 that comes after IT's current position in the visual
4101 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4105 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4107 charpos
= it_copy
.bidi_it
.charpos
;
4110 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4112 if (it
->current
.overlay_string_index
>= 0)
4113 bufpos
= IT_CHARPOS (*it
);
4117 base_face_id
= underlying_face_id (it
);
4119 /* Get the face for ASCII, or unibyte. */
4120 face_id
= face_at_string_position (it
->w
,
4124 &next_check_charpos
,
4125 base_face_id
, false);
4127 /* Correct the face for charsets different from ASCII. Do it
4128 for the multibyte case only. The face returned above is
4129 suitable for unibyte text if IT->string is unibyte. */
4130 if (STRING_MULTIBYTE (it
->string
))
4132 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4133 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4135 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4137 c
= string_char_and_length (p
, &len
);
4138 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4143 struct text_pos pos
;
4145 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4146 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4149 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4150 pos
= it
->current
.pos
;
4155 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4158 if (it
->what
== IT_COMPOSITION
)
4160 /* For composition, we must check the position after
4162 pos
.charpos
+= it
->cmp_it
.nchars
;
4163 pos
.bytepos
+= it
->len
;
4166 INC_TEXT_POS (pos
, it
->multibyte_p
);
4175 /* With bidi iteration, the character before the current
4176 in the visual order cannot be found by simple
4177 iteration, because "reverse" reordering is not
4178 supported. Instead, we need to use the move_it_*
4179 family of functions, and move to the previous
4180 character starting from the beginning of the visual
4182 /* Ignore face changes before the first visible
4183 character on this display line. */
4184 if (it
->current_x
<= it
->first_visible_x
)
4186 SAVE_IT (it_copy
, *it
, it_copy_data
);
4187 /* Implementation note: Since move_it_in_display_line
4188 works in the iterator geometry, and thinks the first
4189 character is always the leftmost, even in R2L lines,
4190 we don't need to distinguish between the R2L and L2R
4192 current_x
= it_copy
.current_x
;
4193 move_it_vertically_backward (&it_copy
, 0);
4194 move_it_in_display_line (&it_copy
, ZV
, current_x
- 1, MOVE_TO_X
);
4195 pos
= it_copy
.current
.pos
;
4196 RESTORE_IT (it
, it
, it_copy_data
);
4200 /* Set charpos to the buffer position of the character
4201 that comes after IT's current position in the visual
4203 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4207 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4210 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4213 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4215 /* Determine face for CHARSET_ASCII, or unibyte. */
4216 face_id
= face_at_buffer_position (it
->w
,
4218 &next_check_charpos
,
4221 /* Correct the face for charsets different from ASCII. Do it
4222 for the multibyte case only. The face returned above is
4223 suitable for unibyte text if current_buffer is unibyte. */
4224 if (it
->multibyte_p
)
4226 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4227 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4228 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4237 /***********************************************************************
4239 ***********************************************************************/
4241 /* Set up iterator IT from invisible properties at its current
4242 position. Called from handle_stop. */
4244 static enum prop_handled
4245 handle_invisible_prop (struct it
*it
)
4247 enum prop_handled handled
= HANDLED_NORMALLY
;
4251 if (STRINGP (it
->string
))
4253 Lisp_Object end_charpos
, limit
;
4255 /* Get the value of the invisible text property at the
4256 current position. Value will be nil if there is no such
4258 end_charpos
= make_number (IT_STRING_CHARPOS (*it
));
4259 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4260 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4262 if (invis
!= 0 && IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4264 /* Record whether we have to display an ellipsis for the
4266 bool display_ellipsis_p
= (invis
== 2);
4267 ptrdiff_t len
, endpos
;
4269 handled
= HANDLED_RECOMPUTE_PROPS
;
4271 /* Get the position at which the next visible text can be
4272 found in IT->string, if any. */
4273 endpos
= len
= SCHARS (it
->string
);
4274 XSETINT (limit
, len
);
4278 = Fnext_single_property_change (end_charpos
, Qinvisible
,
4280 /* Since LIMIT is always an integer, so should be the
4281 value returned by Fnext_single_property_change. */
4282 eassert (INTEGERP (end_charpos
));
4283 if (INTEGERP (end_charpos
))
4285 endpos
= XFASTINT (end_charpos
);
4286 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4287 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4289 display_ellipsis_p
= true;
4291 else /* Should never happen; but if it does, exit the loop. */
4294 while (invis
!= 0 && endpos
< len
);
4296 if (display_ellipsis_p
)
4297 it
->ellipsis_p
= true;
4301 /* Text at END_CHARPOS is visible. Move IT there. */
4302 struct text_pos old
;
4305 old
= it
->current
.string_pos
;
4306 oldpos
= CHARPOS (old
);
4309 if (it
->bidi_it
.first_elt
4310 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4311 bidi_paragraph_init (it
->paragraph_embedding
,
4312 &it
->bidi_it
, true);
4313 /* Bidi-iterate out of the invisible text. */
4316 bidi_move_to_visually_next (&it
->bidi_it
);
4318 while (oldpos
<= it
->bidi_it
.charpos
4319 && it
->bidi_it
.charpos
< endpos
);
4321 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4322 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4323 if (IT_CHARPOS (*it
) >= endpos
)
4324 it
->prev_stop
= endpos
;
4328 IT_STRING_CHARPOS (*it
) = endpos
;
4329 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4334 /* The rest of the string is invisible. If this is an
4335 overlay string, proceed with the next overlay string
4336 or whatever comes and return a character from there. */
4337 if (it
->current
.overlay_string_index
>= 0
4338 && !display_ellipsis_p
)
4340 next_overlay_string (it
);
4341 /* Don't check for overlay strings when we just
4342 finished processing them. */
4343 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4347 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4348 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4355 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4356 Lisp_Object pos
, overlay
;
4358 /* First of all, is there invisible text at this position? */
4359 tem
= start_charpos
= IT_CHARPOS (*it
);
4360 pos
= make_number (tem
);
4361 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4363 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4365 /* If we are on invisible text, skip over it. */
4366 if (invis
!= 0 && start_charpos
< it
->end_charpos
)
4368 /* Record whether we have to display an ellipsis for the
4370 bool display_ellipsis_p
= invis
== 2;
4372 handled
= HANDLED_RECOMPUTE_PROPS
;
4374 /* Loop skipping over invisible text. The loop is left at
4375 ZV or with IT on the first char being visible again. */
4378 /* Try to skip some invisible text. Return value is the
4379 position reached which can be equal to where we start
4380 if there is nothing invisible there. This skips both
4381 over invisible text properties and overlays with
4382 invisible property. */
4383 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4385 /* If we skipped nothing at all we weren't at invisible
4386 text in the first place. If everything to the end of
4387 the buffer was skipped, end the loop. */
4388 if (newpos
== tem
|| newpos
>= ZV
)
4392 /* We skipped some characters but not necessarily
4393 all there are. Check if we ended up on visible
4394 text. Fget_char_property returns the property of
4395 the char before the given position, i.e. if we
4396 get invis = 0, this means that the char at
4397 newpos is visible. */
4398 pos
= make_number (newpos
);
4399 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4400 invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4403 /* If we ended up on invisible text, proceed to
4404 skip starting with next_stop. */
4408 /* If there are adjacent invisible texts, don't lose the
4409 second one's ellipsis. */
4411 display_ellipsis_p
= true;
4415 /* The position newpos is now either ZV or on visible text. */
4418 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4420 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4422 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4424 /* If the invisible text ends on a newline or on a
4425 character after a newline, we can avoid the costly,
4426 character by character, bidi iteration to NEWPOS, and
4427 instead simply reseat the iterator there. That's
4428 because all bidi reordering information is tossed at
4429 the newline. This is a big win for modes that hide
4430 complete lines, like Outline, Org, etc. */
4431 if (on_newline
|| after_newline
)
4433 struct text_pos tpos
;
4434 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4436 SET_TEXT_POS (tpos
, newpos
, bpos
);
4437 reseat_1 (it
, tpos
, false);
4438 /* If we reseat on a newline/ZV, we need to prep the
4439 bidi iterator for advancing to the next character
4440 after the newline/EOB, keeping the current paragraph
4441 direction (so that PRODUCE_GLYPHS does TRT wrt
4442 prepending/appending glyphs to a glyph row). */
4445 it
->bidi_it
.first_elt
= false;
4446 it
->bidi_it
.paragraph_dir
= pdir
;
4447 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4448 it
->bidi_it
.nchars
= 1;
4449 it
->bidi_it
.ch_len
= 1;
4452 else /* Must use the slow method. */
4454 /* With bidi iteration, the region of invisible text
4455 could start and/or end in the middle of a
4456 non-base embedding level. Therefore, we need to
4457 skip invisible text using the bidi iterator,
4458 starting at IT's current position, until we find
4459 ourselves outside of the invisible text.
4460 Skipping invisible text _after_ bidi iteration
4461 avoids affecting the visual order of the
4462 displayed text when invisible properties are
4463 added or removed. */
4464 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4466 /* If we were `reseat'ed to a new paragraph,
4467 determine the paragraph base direction. We
4468 need to do it now because
4469 next_element_from_buffer may not have a
4470 chance to do it, if we are going to skip any
4471 text at the beginning, which resets the
4473 bidi_paragraph_init (it
->paragraph_embedding
,
4474 &it
->bidi_it
, true);
4478 bidi_move_to_visually_next (&it
->bidi_it
);
4480 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4481 && it
->bidi_it
.charpos
< newpos
);
4482 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4483 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4484 /* If we overstepped NEWPOS, record its position in
4485 the iterator, so that we skip invisible text if
4486 later the bidi iteration lands us in the
4487 invisible region again. */
4488 if (IT_CHARPOS (*it
) >= newpos
)
4489 it
->prev_stop
= newpos
;
4494 IT_CHARPOS (*it
) = newpos
;
4495 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4498 if (display_ellipsis_p
)
4500 /* Make sure that the glyphs of the ellipsis will get
4501 correct `charpos' values. If we would not update
4502 it->position here, the glyphs would belong to the
4503 last visible character _before_ the invisible
4504 text, which confuses `set_cursor_from_row'.
4506 We use the last invisible position instead of the
4507 first because this way the cursor is always drawn on
4508 the first "." of the ellipsis, whenever PT is inside
4509 the invisible text. Otherwise the cursor would be
4510 placed _after_ the ellipsis when the point is after the
4511 first invisible character. */
4512 if (!STRINGP (it
->object
))
4514 it
->position
.charpos
= newpos
- 1;
4515 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4519 /* If there are before-strings at the start of invisible
4520 text, and the text is invisible because of a text
4521 property, arrange to show before-strings because 20.x did
4522 it that way. (If the text is invisible because of an
4523 overlay property instead of a text property, this is
4524 already handled in the overlay code.) */
4526 && get_overlay_strings (it
, it
->stop_charpos
))
4528 handled
= HANDLED_RECOMPUTE_PROPS
;
4531 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4532 /* The call to get_overlay_strings above recomputes
4533 it->stop_charpos, but it only considers changes
4534 in properties and overlays beyond iterator's
4535 current position. This causes us to miss changes
4536 that happen exactly where the invisible property
4537 ended. So we play it safe here and force the
4538 iterator to check for potential stop positions
4539 immediately after the invisible text. Note that
4540 if get_overlay_strings returns true, it
4541 normally also pushed the iterator stack, so we
4542 need to update the stop position in the slot
4543 below the current one. */
4544 it
->stack
[it
->sp
- 1].stop_charpos
4545 = CHARPOS (it
->stack
[it
->sp
- 1].current
.pos
);
4548 else if (display_ellipsis_p
)
4550 it
->ellipsis_p
= true;
4551 /* Let the ellipsis display before
4552 considering any properties of the following char.
4553 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4554 handled
= HANDLED_RETURN
;
4563 /* Make iterator IT return `...' next.
4564 Replaces LEN characters from buffer. */
4567 setup_for_ellipsis (struct it
*it
, int len
)
4569 /* Use the display table definition for `...'. Invalid glyphs
4570 will be handled by the method returning elements from dpvec. */
4571 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4573 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4574 it
->dpvec
= v
->contents
;
4575 it
->dpend
= v
->contents
+ v
->header
.size
;
4579 /* Default `...'. */
4580 it
->dpvec
= default_invis_vector
;
4581 it
->dpend
= default_invis_vector
+ 3;
4584 it
->dpvec_char_len
= len
;
4585 it
->current
.dpvec_index
= 0;
4586 it
->dpvec_face_id
= -1;
4588 /* Use IT->saved_face_id for the ellipsis, so that it has the same
4589 face as the preceding text. IT->saved_face_id was set in
4590 handle_stop to the face of the preceding character, and will be
4591 different from IT->face_id only if the invisible text skipped in
4592 handle_invisible_prop has some non-default face on its first
4593 character. We thus ignore the face of the invisible text when we
4594 display the ellipsis. IT's face is restored in set_iterator_to_next. */
4595 if (it
->saved_face_id
>= 0)
4596 it
->face_id
= it
->saved_face_id
;
4598 /* If the ellipsis represents buffer text, it means we advanced in
4599 the buffer, so we should no longer ignore overlay strings. */
4600 if (it
->method
== GET_FROM_BUFFER
)
4601 it
->ignore_overlay_strings_at_pos_p
= false;
4603 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4604 it
->ellipsis_p
= true;
4609 /***********************************************************************
4611 ***********************************************************************/
4613 /* Set up iterator IT from `display' property at its current position.
4614 Called from handle_stop.
4615 We return HANDLED_RETURN if some part of the display property
4616 overrides the display of the buffer text itself.
4617 Otherwise we return HANDLED_NORMALLY. */
4619 static enum prop_handled
4620 handle_display_prop (struct it
*it
)
4622 Lisp_Object propval
, object
, overlay
;
4623 struct text_pos
*position
;
4625 /* Nonzero if some property replaces the display of the text itself. */
4626 int display_replaced
= 0;
4628 if (STRINGP (it
->string
))
4630 object
= it
->string
;
4631 position
= &it
->current
.string_pos
;
4632 bufpos
= CHARPOS (it
->current
.pos
);
4636 XSETWINDOW (object
, it
->w
);
4637 position
= &it
->current
.pos
;
4638 bufpos
= CHARPOS (*position
);
4641 /* Reset those iterator values set from display property values. */
4642 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4643 it
->space_width
= Qnil
;
4644 it
->font_height
= Qnil
;
4647 /* We don't support recursive `display' properties, i.e. string
4648 values that have a string `display' property, that have a string
4649 `display' property etc. */
4650 if (!it
->string_from_display_prop_p
)
4651 it
->area
= TEXT_AREA
;
4653 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4654 Qdisplay
, object
, &overlay
);
4656 return HANDLED_NORMALLY
;
4657 /* Now OVERLAY is the overlay that gave us this property, or nil
4658 if it was a text property. */
4660 if (!STRINGP (it
->string
))
4661 object
= it
->w
->contents
;
4663 display_replaced
= handle_display_spec (it
, propval
, object
, overlay
,
4665 FRAME_WINDOW_P (it
->f
));
4666 return display_replaced
!= 0 ? HANDLED_RETURN
: HANDLED_NORMALLY
;
4669 /* Subroutine of handle_display_prop. Returns non-zero if the display
4670 specification in SPEC is a replacing specification, i.e. it would
4671 replace the text covered by `display' property with something else,
4672 such as an image or a display string. If SPEC includes any kind or
4673 `(space ...) specification, the value is 2; this is used by
4674 compute_display_string_pos, which see.
4676 See handle_single_display_spec for documentation of arguments.
4677 FRAME_WINDOW_P is true if the window being redisplayed is on a
4678 GUI frame; this argument is used only if IT is NULL, see below.
4680 IT can be NULL, if this is called by the bidi reordering code
4681 through compute_display_string_pos, which see. In that case, this
4682 function only examines SPEC, but does not otherwise "handle" it, in
4683 the sense that it doesn't set up members of IT from the display
4686 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4687 Lisp_Object overlay
, struct text_pos
*position
,
4688 ptrdiff_t bufpos
, bool frame_window_p
)
4693 /* Simple specifications. */
4694 && !EQ (XCAR (spec
), Qimage
)
4695 #ifdef HAVE_XWIDGETS
4696 && !EQ (XCAR (spec
), Qxwidget
)
4698 && !EQ (XCAR (spec
), Qspace
)
4699 && !EQ (XCAR (spec
), Qwhen
)
4700 && !EQ (XCAR (spec
), Qslice
)
4701 && !EQ (XCAR (spec
), Qspace_width
)
4702 && !EQ (XCAR (spec
), Qheight
)
4703 && !EQ (XCAR (spec
), Qraise
)
4704 /* Marginal area specifications. */
4705 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4706 && !EQ (XCAR (spec
), Qleft_fringe
)
4707 && !EQ (XCAR (spec
), Qright_fringe
)
4708 && !NILP (XCAR (spec
)))
4710 for (; CONSP (spec
); spec
= XCDR (spec
))
4712 int rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4713 overlay
, position
, bufpos
,
4714 replacing
, frame_window_p
);
4718 /* If some text in a string is replaced, `position' no
4719 longer points to the position of `object'. */
4720 if (!it
|| STRINGP (object
))
4725 else if (VECTORP (spec
))
4728 for (i
= 0; i
< ASIZE (spec
); ++i
)
4730 int rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4731 overlay
, position
, bufpos
,
4732 replacing
, frame_window_p
);
4736 /* If some text in a string is replaced, `position' no
4737 longer points to the position of `object'. */
4738 if (!it
|| STRINGP (object
))
4744 replacing
= handle_single_display_spec (it
, spec
, object
, overlay
, position
,
4745 bufpos
, 0, frame_window_p
);
4749 /* Value is the position of the end of the `display' property starting
4750 at START_POS in OBJECT. */
4752 static struct text_pos
4753 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4756 struct text_pos end_pos
;
4758 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4759 Qdisplay
, object
, Qnil
);
4760 CHARPOS (end_pos
) = XFASTINT (end
);
4761 if (STRINGP (object
))
4762 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4764 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4770 /* Set up IT from a single `display' property specification SPEC. OBJECT
4771 is the object in which the `display' property was found. *POSITION
4772 is the position in OBJECT at which the `display' property was found.
4773 BUFPOS is the buffer position of OBJECT (different from POSITION if
4774 OBJECT is not a buffer). DISPLAY_REPLACED non-zero means that we
4775 previously saw a display specification which already replaced text
4776 display with something else, for example an image; we ignore such
4777 properties after the first one has been processed.
4779 OVERLAY is the overlay this `display' property came from,
4780 or nil if it was a text property.
4782 If SPEC is a `space' or `image' specification, and in some other
4783 cases too, set *POSITION to the position where the `display'
4786 If IT is NULL, only examine the property specification in SPEC, but
4787 don't set up IT. In that case, FRAME_WINDOW_P means SPEC
4788 is intended to be displayed in a window on a GUI frame.
4790 Value is non-zero if something was found which replaces the display
4791 of buffer or string text. */
4794 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4795 Lisp_Object overlay
, struct text_pos
*position
,
4796 ptrdiff_t bufpos
, int display_replaced
,
4797 bool frame_window_p
)
4800 Lisp_Object location
, value
;
4801 struct text_pos start_pos
= *position
;
4803 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4804 If the result is non-nil, use VALUE instead of SPEC. */
4806 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4815 if (!NILP (form
) && !EQ (form
, Qt
))
4817 ptrdiff_t count
= SPECPDL_INDEX ();
4819 /* Bind `object' to the object having the `display' property, a
4820 buffer or string. Bind `position' to the position in the
4821 object where the property was found, and `buffer-position'
4822 to the current position in the buffer. */
4825 XSETBUFFER (object
, current_buffer
);
4826 specbind (Qobject
, object
);
4827 specbind (Qposition
, make_number (CHARPOS (*position
)));
4828 specbind (Qbuffer_position
, make_number (bufpos
));
4829 form
= safe_eval (form
);
4830 unbind_to (count
, Qnil
);
4836 /* Handle `(height HEIGHT)' specifications. */
4838 && EQ (XCAR (spec
), Qheight
)
4839 && CONSP (XCDR (spec
)))
4843 if (!FRAME_WINDOW_P (it
->f
))
4846 it
->font_height
= XCAR (XCDR (spec
));
4847 if (!NILP (it
->font_height
))
4849 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4850 int new_height
= -1;
4852 if (CONSP (it
->font_height
)
4853 && (EQ (XCAR (it
->font_height
), Qplus
)
4854 || EQ (XCAR (it
->font_height
), Qminus
))
4855 && CONSP (XCDR (it
->font_height
))
4856 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4858 /* `(+ N)' or `(- N)' where N is an integer. */
4859 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4860 if (EQ (XCAR (it
->font_height
), Qplus
))
4862 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4864 else if (FUNCTIONP (it
->font_height
))
4866 /* Call function with current height as argument.
4867 Value is the new height. */
4869 height
= safe_call1 (it
->font_height
,
4870 face
->lface
[LFACE_HEIGHT_INDEX
]);
4871 if (NUMBERP (height
))
4872 new_height
= XFLOATINT (height
);
4874 else if (NUMBERP (it
->font_height
))
4876 /* Value is a multiple of the canonical char height. */
4879 f
= FACE_FROM_ID (it
->f
,
4880 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4881 new_height
= (XFLOATINT (it
->font_height
)
4882 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4886 /* Evaluate IT->font_height with `height' bound to the
4887 current specified height to get the new height. */
4888 ptrdiff_t count
= SPECPDL_INDEX ();
4890 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4891 value
= safe_eval (it
->font_height
);
4892 unbind_to (count
, Qnil
);
4894 if (NUMBERP (value
))
4895 new_height
= XFLOATINT (value
);
4899 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4906 /* Handle `(space-width WIDTH)'. */
4908 && EQ (XCAR (spec
), Qspace_width
)
4909 && CONSP (XCDR (spec
)))
4913 if (!FRAME_WINDOW_P (it
->f
))
4916 value
= XCAR (XCDR (spec
));
4917 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4918 it
->space_width
= value
;
4924 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4926 && EQ (XCAR (spec
), Qslice
))
4932 if (!FRAME_WINDOW_P (it
->f
))
4935 if (tem
= XCDR (spec
), CONSP (tem
))
4937 it
->slice
.x
= XCAR (tem
);
4938 if (tem
= XCDR (tem
), CONSP (tem
))
4940 it
->slice
.y
= XCAR (tem
);
4941 if (tem
= XCDR (tem
), CONSP (tem
))
4943 it
->slice
.width
= XCAR (tem
);
4944 if (tem
= XCDR (tem
), CONSP (tem
))
4945 it
->slice
.height
= XCAR (tem
);
4954 /* Handle `(raise FACTOR)'. */
4956 && EQ (XCAR (spec
), Qraise
)
4957 && CONSP (XCDR (spec
)))
4961 if (!FRAME_WINDOW_P (it
->f
))
4964 #ifdef HAVE_WINDOW_SYSTEM
4965 value
= XCAR (XCDR (spec
));
4966 if (NUMBERP (value
))
4968 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4969 it
->voffset
= - (XFLOATINT (value
)
4970 * (normal_char_height (face
->font
, -1)));
4972 #endif /* HAVE_WINDOW_SYSTEM */
4978 /* Don't handle the other kinds of display specifications
4979 inside a string that we got from a `display' property. */
4980 if (it
&& it
->string_from_display_prop_p
)
4983 /* Characters having this form of property are not displayed, so
4984 we have to find the end of the property. */
4987 start_pos
= *position
;
4988 *position
= display_prop_end (it
, object
, start_pos
);
4989 /* If the display property comes from an overlay, don't consider
4990 any potential stop_charpos values before the end of that
4991 overlay. Since display_prop_end will happily find another
4992 'display' property coming from some other overlay or text
4993 property on buffer positions before this overlay's end, we
4994 need to ignore them, or else we risk displaying this
4995 overlay's display string/image twice. */
4996 if (!NILP (overlay
))
4998 ptrdiff_t ovendpos
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5000 if (ovendpos
> CHARPOS (*position
))
5001 SET_TEXT_POS (*position
, ovendpos
, CHAR_TO_BYTE (ovendpos
));
5006 /* Stop the scan at that end position--we assume that all
5007 text properties change there. */
5009 it
->stop_charpos
= position
->charpos
;
5011 /* Handle `(left-fringe BITMAP [FACE])'
5012 and `(right-fringe BITMAP [FACE])'. */
5014 && (EQ (XCAR (spec
), Qleft_fringe
)
5015 || EQ (XCAR (spec
), Qright_fringe
))
5016 && CONSP (XCDR (spec
)))
5022 if (!FRAME_WINDOW_P (it
->f
))
5023 /* If we return here, POSITION has been advanced
5024 across the text with this property. */
5026 /* Synchronize the bidi iterator with POSITION. This is
5027 needed because we are not going to push the iterator
5028 on behalf of this display property, so there will be
5029 no pop_it call to do this synchronization for us. */
5032 it
->position
= *position
;
5033 iterate_out_of_display_property (it
);
5034 *position
= it
->position
;
5039 else if (!frame_window_p
)
5042 #ifdef HAVE_WINDOW_SYSTEM
5043 value
= XCAR (XCDR (spec
));
5044 if (!SYMBOLP (value
)
5045 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
5046 /* If we return here, POSITION has been advanced
5047 across the text with this property. */
5049 if (it
&& it
->bidi_p
)
5051 it
->position
= *position
;
5052 iterate_out_of_display_property (it
);
5053 *position
= it
->position
;
5060 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
5062 if (CONSP (XCDR (XCDR (spec
))))
5064 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
5065 int face_id2
= lookup_derived_face (it
->f
, face_name
,
5066 FRINGE_FACE_ID
, false);
5071 /* Save current settings of IT so that we can restore them
5072 when we are finished with the glyph property value. */
5073 push_it (it
, position
);
5075 it
->area
= TEXT_AREA
;
5076 it
->what
= IT_IMAGE
;
5077 it
->image_id
= -1; /* no image */
5078 it
->position
= start_pos
;
5079 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5080 it
->method
= GET_FROM_IMAGE
;
5081 it
->from_overlay
= Qnil
;
5082 it
->face_id
= face_id
;
5083 it
->from_disp_prop_p
= true;
5085 /* Say that we haven't consumed the characters with
5086 `display' property yet. The call to pop_it in
5087 set_iterator_to_next will clean this up. */
5088 *position
= start_pos
;
5090 if (EQ (XCAR (spec
), Qleft_fringe
))
5092 it
->left_user_fringe_bitmap
= fringe_bitmap
;
5093 it
->left_user_fringe_face_id
= face_id
;
5097 it
->right_user_fringe_bitmap
= fringe_bitmap
;
5098 it
->right_user_fringe_face_id
= face_id
;
5101 #endif /* HAVE_WINDOW_SYSTEM */
5105 /* Prepare to handle `((margin left-margin) ...)',
5106 `((margin right-margin) ...)' and `((margin nil) ...)'
5107 prefixes for display specifications. */
5108 location
= Qunbound
;
5109 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5113 value
= XCDR (spec
);
5115 value
= XCAR (value
);
5118 if (EQ (XCAR (tem
), Qmargin
)
5119 && (tem
= XCDR (tem
),
5120 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5122 || EQ (tem
, Qleft_margin
)
5123 || EQ (tem
, Qright_margin
))))
5127 if (EQ (location
, Qunbound
))
5133 /* After this point, VALUE is the property after any
5134 margin prefix has been stripped. It must be a string,
5135 an image specification, or `(space ...)'.
5137 LOCATION specifies where to display: `left-margin',
5138 `right-margin' or nil. */
5140 bool valid_p
= (STRINGP (value
)
5141 #ifdef HAVE_WINDOW_SYSTEM
5142 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5143 && valid_image_p (value
))
5144 #endif /* not HAVE_WINDOW_SYSTEM */
5145 || (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5146 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5147 && valid_xwidget_spec_p (value
)));
5149 if (valid_p
&& display_replaced
== 0)
5155 /* Callers need to know whether the display spec is any kind
5156 of `(space ...)' spec that is about to affect text-area
5158 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5163 /* Save current settings of IT so that we can restore them
5164 when we are finished with the glyph property value. */
5165 push_it (it
, position
);
5166 it
->from_overlay
= overlay
;
5167 it
->from_disp_prop_p
= true;
5169 if (NILP (location
))
5170 it
->area
= TEXT_AREA
;
5171 else if (EQ (location
, Qleft_margin
))
5172 it
->area
= LEFT_MARGIN_AREA
;
5174 it
->area
= RIGHT_MARGIN_AREA
;
5176 if (STRINGP (value
))
5179 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5180 it
->current
.overlay_string_index
= -1;
5181 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5182 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5183 it
->method
= GET_FROM_STRING
;
5184 it
->stop_charpos
= 0;
5186 it
->base_level_stop
= 0;
5187 it
->string_from_display_prop_p
= true;
5188 /* Say that we haven't consumed the characters with
5189 `display' property yet. The call to pop_it in
5190 set_iterator_to_next will clean this up. */
5191 if (BUFFERP (object
))
5192 *position
= start_pos
;
5194 /* Force paragraph direction to be that of the parent
5195 object. If the parent object's paragraph direction is
5196 not yet determined, default to L2R. */
5197 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5198 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5200 it
->paragraph_embedding
= L2R
;
5202 /* Set up the bidi iterator for this display string. */
5205 it
->bidi_it
.string
.lstring
= it
->string
;
5206 it
->bidi_it
.string
.s
= NULL
;
5207 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5208 it
->bidi_it
.string
.bufpos
= bufpos
;
5209 it
->bidi_it
.string
.from_disp_str
= true;
5210 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5211 it
->bidi_it
.w
= it
->w
;
5212 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5215 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5217 it
->method
= GET_FROM_STRETCH
;
5219 *position
= it
->position
= start_pos
;
5220 retval
= 1 + (it
->area
== TEXT_AREA
);
5222 else if (valid_xwidget_spec_p (value
))
5224 it
->what
= IT_XWIDGET
;
5225 it
->method
= GET_FROM_XWIDGET
;
5226 it
->position
= start_pos
;
5227 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5228 *position
= start_pos
;
5229 it
->xwidget
= lookup_xwidget (value
);
5231 #ifdef HAVE_WINDOW_SYSTEM
5234 it
->what
= IT_IMAGE
;
5235 it
->image_id
= lookup_image (it
->f
, value
);
5236 it
->position
= start_pos
;
5237 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5238 it
->method
= GET_FROM_IMAGE
;
5240 /* Say that we haven't consumed the characters with
5241 `display' property yet. The call to pop_it in
5242 set_iterator_to_next will clean this up. */
5243 *position
= start_pos
;
5245 #endif /* HAVE_WINDOW_SYSTEM */
5250 /* Invalid property or property not supported. Restore
5251 POSITION to what it was before. */
5252 *position
= start_pos
;
5256 /* Check if PROP is a display property value whose text should be
5257 treated as intangible. OVERLAY is the overlay from which PROP
5258 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5259 specify the buffer position covered by PROP. */
5262 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5263 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5265 bool frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5266 struct text_pos position
;
5268 SET_TEXT_POS (position
, charpos
, bytepos
);
5269 return (handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5270 &position
, charpos
, frame_window_p
)
5275 /* Return true if PROP is a display sub-property value containing STRING.
5277 Implementation note: this and the following function are really
5278 special cases of handle_display_spec and
5279 handle_single_display_spec, and should ideally use the same code.
5280 Until they do, these two pairs must be consistent and must be
5281 modified in sync. */
5284 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5286 if (EQ (string
, prop
))
5289 /* Skip over `when FORM'. */
5290 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5295 /* Actually, the condition following `when' should be eval'ed,
5296 like handle_single_display_spec does, and we should return
5297 false if it evaluates to nil. However, this function is
5298 called only when the buffer was already displayed and some
5299 glyph in the glyph matrix was found to come from a display
5300 string. Therefore, the condition was already evaluated, and
5301 the result was non-nil, otherwise the display string wouldn't
5302 have been displayed and we would have never been called for
5303 this property. Thus, we can skip the evaluation and assume
5304 its result is non-nil. */
5309 /* Skip over `margin LOCATION'. */
5310 if (EQ (XCAR (prop
), Qmargin
))
5321 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5325 /* Return true if STRING appears in the `display' property PROP. */
5328 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5331 && !EQ (XCAR (prop
), Qwhen
)
5332 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5334 /* A list of sub-properties. */
5335 while (CONSP (prop
))
5337 if (single_display_spec_string_p (XCAR (prop
), string
))
5342 else if (VECTORP (prop
))
5344 /* A vector of sub-properties. */
5346 for (i
= 0; i
< ASIZE (prop
); ++i
)
5347 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5351 return single_display_spec_string_p (prop
, string
);
5356 /* Look for STRING in overlays and text properties in the current
5357 buffer, between character positions FROM and TO (excluding TO).
5358 BACK_P means look back (in this case, TO is supposed to be
5360 Value is the first character position where STRING was found, or
5361 zero if it wasn't found before hitting TO.
5363 This function may only use code that doesn't eval because it is
5364 called asynchronously from note_mouse_highlight. */
5367 string_buffer_position_lim (Lisp_Object string
,
5368 ptrdiff_t from
, ptrdiff_t to
, bool back_p
)
5370 Lisp_Object limit
, prop
, pos
;
5373 pos
= make_number (max (from
, BEGV
));
5375 if (!back_p
) /* looking forward */
5377 limit
= make_number (min (to
, ZV
));
5378 while (!found
&& !EQ (pos
, limit
))
5380 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5381 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5384 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5388 else /* looking back */
5390 limit
= make_number (max (to
, BEGV
));
5391 while (!found
&& !EQ (pos
, limit
))
5393 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5394 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5397 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5402 return found
? XINT (pos
) : 0;
5405 /* Determine which buffer position in current buffer STRING comes from.
5406 AROUND_CHARPOS is an approximate position where it could come from.
5407 Value is the buffer position or 0 if it couldn't be determined.
5409 This function is necessary because we don't record buffer positions
5410 in glyphs generated from strings (to keep struct glyph small).
5411 This function may only use code that doesn't eval because it is
5412 called asynchronously from note_mouse_highlight. */
5415 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5417 const int MAX_DISTANCE
= 1000;
5418 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5419 around_charpos
+ MAX_DISTANCE
,
5423 found
= string_buffer_position_lim (string
, around_charpos
,
5424 around_charpos
- MAX_DISTANCE
, true);
5430 /***********************************************************************
5431 `composition' property
5432 ***********************************************************************/
5434 /* Set up iterator IT from `composition' property at its current
5435 position. Called from handle_stop. */
5437 static enum prop_handled
5438 handle_composition_prop (struct it
*it
)
5440 Lisp_Object prop
, string
;
5441 ptrdiff_t pos
, pos_byte
, start
, end
;
5443 if (STRINGP (it
->string
))
5447 pos
= IT_STRING_CHARPOS (*it
);
5448 pos_byte
= IT_STRING_BYTEPOS (*it
);
5449 string
= it
->string
;
5450 s
= SDATA (string
) + pos_byte
;
5451 it
->c
= STRING_CHAR (s
);
5455 pos
= IT_CHARPOS (*it
);
5456 pos_byte
= IT_BYTEPOS (*it
);
5458 it
->c
= FETCH_CHAR (pos_byte
);
5461 /* If there's a valid composition and point is not inside of the
5462 composition (in the case that the composition is from the current
5463 buffer), draw a glyph composed from the composition components. */
5464 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5465 && composition_valid_p (start
, end
, prop
)
5466 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5469 /* As we can't handle this situation (perhaps font-lock added
5470 a new composition), we just return here hoping that next
5471 redisplay will detect this composition much earlier. */
5472 return HANDLED_NORMALLY
;
5475 if (STRINGP (it
->string
))
5476 pos_byte
= string_char_to_byte (it
->string
, start
);
5478 pos_byte
= CHAR_TO_BYTE (start
);
5480 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5483 if (it
->cmp_it
.id
>= 0)
5486 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5487 it
->cmp_it
.nglyphs
= -1;
5491 return HANDLED_NORMALLY
;
5496 /***********************************************************************
5498 ***********************************************************************/
5500 /* The following structure is used to record overlay strings for
5501 later sorting in load_overlay_strings. */
5503 struct overlay_entry
5505 Lisp_Object overlay
;
5508 bool after_string_p
;
5512 /* Set up iterator IT from overlay strings at its current position.
5513 Called from handle_stop. */
5515 static enum prop_handled
5516 handle_overlay_change (struct it
*it
)
5518 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5519 return HANDLED_RECOMPUTE_PROPS
;
5521 return HANDLED_NORMALLY
;
5525 /* Set up the next overlay string for delivery by IT, if there is an
5526 overlay string to deliver. Called by set_iterator_to_next when the
5527 end of the current overlay string is reached. If there are more
5528 overlay strings to display, IT->string and
5529 IT->current.overlay_string_index are set appropriately here.
5530 Otherwise IT->string is set to nil. */
5533 next_overlay_string (struct it
*it
)
5535 ++it
->current
.overlay_string_index
;
5536 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5538 /* No more overlay strings. Restore IT's settings to what
5539 they were before overlay strings were processed, and
5540 continue to deliver from current_buffer. */
5542 it
->ellipsis_p
= it
->stack
[it
->sp
- 1].display_ellipsis_p
;
5545 || (NILP (it
->string
)
5546 && it
->method
== GET_FROM_BUFFER
5547 && it
->stop_charpos
>= BEGV
5548 && it
->stop_charpos
<= it
->end_charpos
));
5549 it
->current
.overlay_string_index
= -1;
5550 it
->n_overlay_strings
= 0;
5551 /* If there's an empty display string on the stack, pop the
5552 stack, to resync the bidi iterator with IT's position. Such
5553 empty strings are pushed onto the stack in
5554 get_overlay_strings_1. */
5555 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5558 /* Since we've exhausted overlay strings at this buffer
5559 position, set the flag to ignore overlays until we move to
5560 another position. The flag is reset in
5561 next_element_from_buffer. */
5562 it
->ignore_overlay_strings_at_pos_p
= true;
5564 /* If we're at the end of the buffer, record that we have
5565 processed the overlay strings there already, so that
5566 next_element_from_buffer doesn't try it again. */
5567 if (NILP (it
->string
)
5568 && IT_CHARPOS (*it
) >= it
->end_charpos
5569 && it
->overlay_strings_charpos
>= it
->end_charpos
)
5570 it
->overlay_strings_at_end_processed_p
= true;
5571 /* Note: we reset overlay_strings_charpos only here, to make
5572 sure the just-processed overlays were indeed at EOB.
5573 Otherwise, overlays on text with invisible text property,
5574 which are processed with IT's position past the invisible
5575 text, might fool us into thinking the overlays at EOB were
5576 already processed (linum-mode can cause this, for
5578 it
->overlay_strings_charpos
= -1;
5582 /* There are more overlay strings to process. If
5583 IT->current.overlay_string_index has advanced to a position
5584 where we must load IT->overlay_strings with more strings, do
5585 it. We must load at the IT->overlay_strings_charpos where
5586 IT->n_overlay_strings was originally computed; when invisible
5587 text is present, this might not be IT_CHARPOS (Bug#7016). */
5588 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5590 if (it
->current
.overlay_string_index
&& i
== 0)
5591 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5593 /* Initialize IT to deliver display elements from the overlay
5595 it
->string
= it
->overlay_strings
[i
];
5596 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5597 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5598 it
->method
= GET_FROM_STRING
;
5599 it
->stop_charpos
= 0;
5600 it
->end_charpos
= SCHARS (it
->string
);
5601 if (it
->cmp_it
.stop_pos
>= 0)
5602 it
->cmp_it
.stop_pos
= 0;
5604 it
->base_level_stop
= 0;
5606 /* Set up the bidi iterator for this overlay string. */
5609 it
->bidi_it
.string
.lstring
= it
->string
;
5610 it
->bidi_it
.string
.s
= NULL
;
5611 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5612 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5613 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5614 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5615 it
->bidi_it
.w
= it
->w
;
5616 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5624 /* Compare two overlay_entry structures E1 and E2. Used as a
5625 comparison function for qsort in load_overlay_strings. Overlay
5626 strings for the same position are sorted so that
5628 1. All after-strings come in front of before-strings, except
5629 when they come from the same overlay.
5631 2. Within after-strings, strings are sorted so that overlay strings
5632 from overlays with higher priorities come first.
5634 2. Within before-strings, strings are sorted so that overlay
5635 strings from overlays with higher priorities come last.
5637 Value is analogous to strcmp. */
5641 compare_overlay_entries (const void *e1
, const void *e2
)
5643 struct overlay_entry
const *entry1
= e1
;
5644 struct overlay_entry
const *entry2
= e2
;
5647 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5649 /* Let after-strings appear in front of before-strings if
5650 they come from different overlays. */
5651 if (EQ (entry1
->overlay
, entry2
->overlay
))
5652 result
= entry1
->after_string_p
? 1 : -1;
5654 result
= entry1
->after_string_p
? -1 : 1;
5656 else if (entry1
->priority
!= entry2
->priority
)
5658 if (entry1
->after_string_p
)
5659 /* After-strings sorted in order of decreasing priority. */
5660 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5662 /* Before-strings sorted in order of increasing priority. */
5663 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5672 /* Load the vector IT->overlay_strings with overlay strings from IT's
5673 current buffer position, or from CHARPOS if that is > 0. Set
5674 IT->n_overlays to the total number of overlay strings found.
5676 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5677 a time. On entry into load_overlay_strings,
5678 IT->current.overlay_string_index gives the number of overlay
5679 strings that have already been loaded by previous calls to this
5682 IT->add_overlay_start contains an additional overlay start
5683 position to consider for taking overlay strings from, if non-zero.
5684 This position comes into play when the overlay has an `invisible'
5685 property, and both before and after-strings. When we've skipped to
5686 the end of the overlay, because of its `invisible' property, we
5687 nevertheless want its before-string to appear.
5688 IT->add_overlay_start will contain the overlay start position
5691 Overlay strings are sorted so that after-string strings come in
5692 front of before-string strings. Within before and after-strings,
5693 strings are sorted by overlay priority. See also function
5694 compare_overlay_entries. */
5697 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5699 Lisp_Object overlay
, window
, str
, invisible
;
5700 struct Lisp_Overlay
*ov
;
5701 ptrdiff_t start
, end
;
5702 ptrdiff_t n
= 0, i
, j
;
5704 struct overlay_entry entriesbuf
[20];
5705 ptrdiff_t size
= ARRAYELTS (entriesbuf
);
5706 struct overlay_entry
*entries
= entriesbuf
;
5710 charpos
= IT_CHARPOS (*it
);
5712 /* Append the overlay string STRING of overlay OVERLAY to vector
5713 `entries' which has size `size' and currently contains `n'
5714 elements. AFTER_P means STRING is an after-string of
5716 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5719 Lisp_Object priority; \
5723 struct overlay_entry *old = entries; \
5724 SAFE_NALLOCA (entries, 2, size); \
5725 memcpy (entries, old, size * sizeof *entries); \
5729 entries[n].string = (STRING); \
5730 entries[n].overlay = (OVERLAY); \
5731 priority = Foverlay_get ((OVERLAY), Qpriority); \
5732 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5733 entries[n].after_string_p = (AFTER_P); \
5738 /* Process overlay before the overlay center. */
5739 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5741 XSETMISC (overlay
, ov
);
5742 eassert (OVERLAYP (overlay
));
5743 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5744 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5749 /* Skip this overlay if it doesn't start or end at IT's current
5751 if (end
!= charpos
&& start
!= charpos
)
5754 /* Skip this overlay if it doesn't apply to IT->w. */
5755 window
= Foverlay_get (overlay
, Qwindow
);
5756 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5759 /* If the text ``under'' the overlay is invisible, both before-
5760 and after-strings from this overlay are visible; start and
5761 end position are indistinguishable. */
5762 invisible
= Foverlay_get (overlay
, Qinvisible
);
5763 invis
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5765 /* If overlay has a non-empty before-string, record it. */
5766 if ((start
== charpos
|| (end
== charpos
&& invis
!= 0))
5767 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5769 RECORD_OVERLAY_STRING (overlay
, str
, false);
5771 /* If overlay has a non-empty after-string, record it. */
5772 if ((end
== charpos
|| (start
== charpos
&& invis
!= 0))
5773 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5775 RECORD_OVERLAY_STRING (overlay
, str
, true);
5778 /* Process overlays after the overlay center. */
5779 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5781 XSETMISC (overlay
, ov
);
5782 eassert (OVERLAYP (overlay
));
5783 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5784 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5786 if (start
> charpos
)
5789 /* Skip this overlay if it doesn't start or end at IT's current
5791 if (end
!= charpos
&& start
!= charpos
)
5794 /* Skip this overlay if it doesn't apply to IT->w. */
5795 window
= Foverlay_get (overlay
, Qwindow
);
5796 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5799 /* If the text ``under'' the overlay is invisible, it has a zero
5800 dimension, and both before- and after-strings apply. */
5801 invisible
= Foverlay_get (overlay
, Qinvisible
);
5802 invis
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5804 /* If overlay has a non-empty before-string, record it. */
5805 if ((start
== charpos
|| (end
== charpos
&& invis
!= 0))
5806 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5808 RECORD_OVERLAY_STRING (overlay
, str
, false);
5810 /* If overlay has a non-empty after-string, record it. */
5811 if ((end
== charpos
|| (start
== charpos
&& invis
!= 0))
5812 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5814 RECORD_OVERLAY_STRING (overlay
, str
, true);
5817 #undef RECORD_OVERLAY_STRING
5821 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5823 /* Record number of overlay strings, and where we computed it. */
5824 it
->n_overlay_strings
= n
;
5825 it
->overlay_strings_charpos
= charpos
;
5827 /* IT->current.overlay_string_index is the number of overlay strings
5828 that have already been consumed by IT. Copy some of the
5829 remaining overlay strings to IT->overlay_strings. */
5831 j
= it
->current
.overlay_string_index
;
5832 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5834 it
->overlay_strings
[i
] = entries
[j
].string
;
5835 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5843 /* Get the first chunk of overlay strings at IT's current buffer
5844 position, or at CHARPOS if that is > 0. Value is true if at
5845 least one overlay string was found. */
5848 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, bool compute_stop_p
)
5850 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5851 process. This fills IT->overlay_strings with strings, and sets
5852 IT->n_overlay_strings to the total number of strings to process.
5853 IT->pos.overlay_string_index has to be set temporarily to zero
5854 because load_overlay_strings needs this; it must be set to -1
5855 when no overlay strings are found because a zero value would
5856 indicate a position in the first overlay string. */
5857 it
->current
.overlay_string_index
= 0;
5858 load_overlay_strings (it
, charpos
);
5860 /* If we found overlay strings, set up IT to deliver display
5861 elements from the first one. Otherwise set up IT to deliver
5862 from current_buffer. */
5863 if (it
->n_overlay_strings
)
5865 /* Make sure we know settings in current_buffer, so that we can
5866 restore meaningful values when we're done with the overlay
5869 compute_stop_pos (it
);
5870 eassert (it
->face_id
>= 0);
5872 /* Save IT's settings. They are restored after all overlay
5873 strings have been processed. */
5874 eassert (!compute_stop_p
|| it
->sp
== 0);
5876 /* When called from handle_stop, there might be an empty display
5877 string loaded. In that case, don't bother saving it. But
5878 don't use this optimization with the bidi iterator, since we
5879 need the corresponding pop_it call to resync the bidi
5880 iterator's position with IT's position, after we are done
5881 with the overlay strings. (The corresponding call to pop_it
5882 in case of an empty display string is in
5883 next_overlay_string.) */
5885 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5888 /* Set up IT to deliver display elements from the first overlay
5890 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5891 it
->string
= it
->overlay_strings
[0];
5892 it
->from_overlay
= Qnil
;
5893 it
->stop_charpos
= 0;
5894 eassert (STRINGP (it
->string
));
5895 it
->end_charpos
= SCHARS (it
->string
);
5897 it
->base_level_stop
= 0;
5898 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5899 it
->method
= GET_FROM_STRING
;
5900 it
->from_disp_prop_p
= 0;
5902 /* Force paragraph direction to be that of the parent
5904 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5905 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5907 it
->paragraph_embedding
= L2R
;
5909 /* Set up the bidi iterator for this overlay string. */
5912 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5914 it
->bidi_it
.string
.lstring
= it
->string
;
5915 it
->bidi_it
.string
.s
= NULL
;
5916 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5917 it
->bidi_it
.string
.bufpos
= pos
;
5918 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5919 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5920 it
->bidi_it
.w
= it
->w
;
5921 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5926 it
->current
.overlay_string_index
= -1;
5931 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5934 it
->method
= GET_FROM_BUFFER
;
5936 get_overlay_strings_1 (it
, charpos
, true);
5940 /* Value is true if we found at least one overlay string. */
5941 return STRINGP (it
->string
);
5946 /***********************************************************************
5947 Saving and restoring state
5948 ***********************************************************************/
5950 /* Save current settings of IT on IT->stack. Called, for example,
5951 before setting up IT for an overlay string, to be able to restore
5952 IT's settings to what they were after the overlay string has been
5953 processed. If POSITION is non-NULL, it is the position to save on
5954 the stack instead of IT->position. */
5957 push_it (struct it
*it
, struct text_pos
*position
)
5959 struct iterator_stack_entry
*p
;
5961 eassert (it
->sp
< IT_STACK_SIZE
);
5962 p
= it
->stack
+ it
->sp
;
5964 p
->stop_charpos
= it
->stop_charpos
;
5965 p
->prev_stop
= it
->prev_stop
;
5966 p
->base_level_stop
= it
->base_level_stop
;
5967 p
->cmp_it
= it
->cmp_it
;
5968 eassert (it
->face_id
>= 0);
5969 p
->face_id
= it
->face_id
;
5970 p
->string
= it
->string
;
5971 p
->method
= it
->method
;
5972 p
->from_overlay
= it
->from_overlay
;
5975 case GET_FROM_IMAGE
:
5976 p
->u
.image
.object
= it
->object
;
5977 p
->u
.image
.image_id
= it
->image_id
;
5978 p
->u
.image
.slice
= it
->slice
;
5980 case GET_FROM_STRETCH
:
5981 p
->u
.stretch
.object
= it
->object
;
5983 case GET_FROM_XWIDGET
:
5984 p
->u
.xwidget
.object
= it
->object
;
5986 case GET_FROM_BUFFER
:
5987 case GET_FROM_DISPLAY_VECTOR
:
5988 case GET_FROM_STRING
:
5989 case GET_FROM_C_STRING
:
5994 p
->position
= position
? *position
: it
->position
;
5995 p
->current
= it
->current
;
5996 p
->end_charpos
= it
->end_charpos
;
5997 p
->string_nchars
= it
->string_nchars
;
5999 p
->multibyte_p
= it
->multibyte_p
;
6000 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
6001 p
->space_width
= it
->space_width
;
6002 p
->font_height
= it
->font_height
;
6003 p
->voffset
= it
->voffset
;
6004 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
6005 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
6006 p
->display_ellipsis_p
= false;
6007 p
->line_wrap
= it
->line_wrap
;
6008 p
->bidi_p
= it
->bidi_p
;
6009 p
->paragraph_embedding
= it
->paragraph_embedding
;
6010 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
6013 /* Save the state of the bidi iterator as well. */
6015 bidi_push_it (&it
->bidi_it
);
6019 iterate_out_of_display_property (struct it
*it
)
6021 bool buffer_p
= !STRINGP (it
->string
);
6022 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
6023 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
6025 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
6027 /* Maybe initialize paragraph direction. If we are at the beginning
6028 of a new paragraph, next_element_from_buffer may not have a
6029 chance to do that. */
6030 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
6031 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
6032 /* prev_stop can be zero, so check against BEGV as well. */
6033 while (it
->bidi_it
.charpos
>= bob
6034 && it
->prev_stop
<= it
->bidi_it
.charpos
6035 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
6036 && it
->bidi_it
.charpos
< eob
)
6037 bidi_move_to_visually_next (&it
->bidi_it
);
6038 /* Record the stop_pos we just crossed, for when we cross it
6040 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
6041 it
->prev_stop
= CHARPOS (it
->position
);
6042 /* If we ended up not where pop_it put us, resync IT's
6043 positional members with the bidi iterator. */
6044 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
6045 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
6047 it
->current
.pos
= it
->position
;
6049 it
->current
.string_pos
= it
->position
;
6052 /* Restore IT's settings from IT->stack. Called, for example, when no
6053 more overlay strings must be processed, and we return to delivering
6054 display elements from a buffer, or when the end of a string from a
6055 `display' property is reached and we return to delivering display
6056 elements from an overlay string, or from a buffer. */
6059 pop_it (struct it
*it
)
6061 struct iterator_stack_entry
*p
;
6062 bool from_display_prop
= it
->from_disp_prop_p
;
6063 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
6065 eassert (it
->sp
> 0);
6067 p
= it
->stack
+ it
->sp
;
6068 it
->stop_charpos
= p
->stop_charpos
;
6069 it
->prev_stop
= p
->prev_stop
;
6070 it
->base_level_stop
= p
->base_level_stop
;
6071 it
->cmp_it
= p
->cmp_it
;
6072 it
->face_id
= p
->face_id
;
6073 it
->current
= p
->current
;
6074 it
->position
= p
->position
;
6075 it
->string
= p
->string
;
6076 it
->from_overlay
= p
->from_overlay
;
6077 if (NILP (it
->string
))
6078 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
6079 it
->method
= p
->method
;
6082 case GET_FROM_IMAGE
:
6083 it
->image_id
= p
->u
.image
.image_id
;
6084 it
->object
= p
->u
.image
.object
;
6085 it
->slice
= p
->u
.image
.slice
;
6087 case GET_FROM_XWIDGET
:
6088 it
->object
= p
->u
.xwidget
.object
;
6090 case GET_FROM_STRETCH
:
6091 it
->object
= p
->u
.stretch
.object
;
6093 case GET_FROM_BUFFER
:
6094 it
->object
= it
->w
->contents
;
6096 case GET_FROM_STRING
:
6098 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6100 /* Restore the face_box_p flag, since it could have been
6101 overwritten by the face of the object that we just finished
6104 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
6105 it
->object
= it
->string
;
6108 case GET_FROM_DISPLAY_VECTOR
:
6110 it
->method
= GET_FROM_C_STRING
;
6111 else if (STRINGP (it
->string
))
6112 it
->method
= GET_FROM_STRING
;
6115 it
->method
= GET_FROM_BUFFER
;
6116 it
->object
= it
->w
->contents
;
6119 case GET_FROM_C_STRING
:
6124 it
->end_charpos
= p
->end_charpos
;
6125 it
->string_nchars
= p
->string_nchars
;
6127 it
->multibyte_p
= p
->multibyte_p
;
6128 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
6129 it
->space_width
= p
->space_width
;
6130 it
->font_height
= p
->font_height
;
6131 it
->voffset
= p
->voffset
;
6132 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
6133 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
6134 it
->line_wrap
= p
->line_wrap
;
6135 it
->bidi_p
= p
->bidi_p
;
6136 it
->paragraph_embedding
= p
->paragraph_embedding
;
6137 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
6140 bidi_pop_it (&it
->bidi_it
);
6141 /* Bidi-iterate until we get out of the portion of text, if any,
6142 covered by a `display' text property or by an overlay with
6143 `display' property. (We cannot just jump there, because the
6144 internal coherency of the bidi iterator state can not be
6145 preserved across such jumps.) We also must determine the
6146 paragraph base direction if the overlay we just processed is
6147 at the beginning of a new paragraph. */
6148 if (from_display_prop
6149 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
6150 iterate_out_of_display_property (it
);
6152 eassert ((BUFFERP (it
->object
)
6153 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
6154 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6155 || (STRINGP (it
->object
)
6156 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
6157 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6158 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6160 /* If we move the iterator over text covered by a display property
6161 to a new buffer position, any info about previously seen overlays
6162 is no longer valid. */
6163 if (from_display_prop
&& it
->sp
== 0 && CHARPOS (it
->position
) != prev_pos
)
6164 it
->ignore_overlay_strings_at_pos_p
= false;
6169 /***********************************************************************
6171 ***********************************************************************/
6173 /* Set IT's current position to the previous line start. */
6176 back_to_previous_line_start (struct it
*it
)
6178 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6181 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6185 /* Move IT to the next line start.
6187 Value is true if a newline was found. Set *SKIPPED_P to true if
6188 we skipped over part of the text (as opposed to moving the iterator
6189 continuously over the text). Otherwise, don't change the value
6192 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6193 iterator on the newline, if it was found.
6195 Newlines may come from buffer text, overlay strings, or strings
6196 displayed via the `display' property. That's the reason we can't
6197 simply use find_newline_no_quit.
6199 Note that this function may not skip over invisible text that is so
6200 because of text properties and immediately follows a newline. If
6201 it would, function reseat_at_next_visible_line_start, when called
6202 from set_iterator_to_next, would effectively make invisible
6203 characters following a newline part of the wrong glyph row, which
6204 leads to wrong cursor motion. */
6207 forward_to_next_line_start (struct it
*it
, bool *skipped_p
,
6208 struct bidi_it
*bidi_it_prev
)
6210 ptrdiff_t old_selective
;
6211 bool newline_found_p
= false;
6213 const int MAX_NEWLINE_DISTANCE
= 500;
6215 /* If already on a newline, just consume it to avoid unintended
6216 skipping over invisible text below. */
6217 if (it
->what
== IT_CHARACTER
6219 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6221 if (it
->bidi_p
&& bidi_it_prev
)
6222 *bidi_it_prev
= it
->bidi_it
;
6223 set_iterator_to_next (it
, false);
6228 /* Don't handle selective display in the following. It's (a)
6229 unnecessary because it's done by the caller, and (b) leads to an
6230 infinite recursion because next_element_from_ellipsis indirectly
6231 calls this function. */
6232 old_selective
= it
->selective
;
6235 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6236 from buffer text. */
6238 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6239 n
+= !STRINGP (it
->string
))
6241 if (!get_next_display_element (it
))
6243 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6244 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6245 *bidi_it_prev
= it
->bidi_it
;
6246 set_iterator_to_next (it
, false);
6249 /* If we didn't find a newline near enough, see if we can use a
6251 if (!newline_found_p
)
6253 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6254 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6258 eassert (!STRINGP (it
->string
));
6260 /* If there isn't any `display' property in sight, and no
6261 overlays, we can just use the position of the newline in
6263 if (it
->stop_charpos
>= limit
6264 || ((pos
= Fnext_single_property_change (make_number (start
),
6266 make_number (limit
)),
6268 && next_overlay_change (start
) == ZV
))
6272 IT_CHARPOS (*it
) = limit
;
6273 IT_BYTEPOS (*it
) = bytepos
;
6277 struct bidi_it bprev
;
6279 /* Help bidi.c avoid expensive searches for display
6280 properties and overlays, by telling it that there are
6281 none up to `limit'. */
6282 if (it
->bidi_it
.disp_pos
< limit
)
6284 it
->bidi_it
.disp_pos
= limit
;
6285 it
->bidi_it
.disp_prop
= 0;
6288 bprev
= it
->bidi_it
;
6289 bidi_move_to_visually_next (&it
->bidi_it
);
6290 } while (it
->bidi_it
.charpos
!= limit
);
6291 IT_CHARPOS (*it
) = limit
;
6292 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6294 *bidi_it_prev
= bprev
;
6296 *skipped_p
= newline_found_p
= true;
6300 while (get_next_display_element (it
)
6301 && !newline_found_p
)
6303 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6304 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6305 *bidi_it_prev
= it
->bidi_it
;
6306 set_iterator_to_next (it
, false);
6311 it
->selective
= old_selective
;
6312 return newline_found_p
;
6316 /* Set IT's current position to the previous visible line start. Skip
6317 invisible text that is so either due to text properties or due to
6318 selective display. Caution: this does not change IT->current_x and
6322 back_to_previous_visible_line_start (struct it
*it
)
6324 while (IT_CHARPOS (*it
) > BEGV
)
6326 back_to_previous_line_start (it
);
6328 if (IT_CHARPOS (*it
) <= BEGV
)
6331 /* If selective > 0, then lines indented more than its value are
6333 if (it
->selective
> 0
6334 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6338 /* Check the newline before point for invisibility. */
6341 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6342 Qinvisible
, it
->window
);
6343 if (TEXT_PROP_MEANS_INVISIBLE (prop
) != 0)
6347 if (IT_CHARPOS (*it
) <= BEGV
)
6352 void *it2data
= NULL
;
6355 Lisp_Object val
, overlay
;
6357 SAVE_IT (it2
, *it
, it2data
);
6359 /* If newline is part of a composition, continue from start of composition */
6360 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6361 && beg
< IT_CHARPOS (*it
))
6364 /* If newline is replaced by a display property, find start of overlay
6365 or interval and continue search from that point. */
6366 pos
= --IT_CHARPOS (it2
);
6369 bidi_unshelve_cache (NULL
, false);
6370 it2
.string_from_display_prop_p
= false;
6371 it2
.from_disp_prop_p
= false;
6372 if (handle_display_prop (&it2
) == HANDLED_RETURN
6373 && !NILP (val
= get_char_property_and_overlay
6374 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6375 && (OVERLAYP (overlay
)
6376 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6377 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6379 RESTORE_IT (it
, it
, it2data
);
6383 /* Newline is not replaced by anything -- so we are done. */
6384 RESTORE_IT (it
, it
, it2data
);
6390 IT_CHARPOS (*it
) = beg
;
6391 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6395 it
->continuation_lines_width
= 0;
6397 eassert (IT_CHARPOS (*it
) >= BEGV
);
6398 eassert (IT_CHARPOS (*it
) == BEGV
6399 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6404 /* Reseat iterator IT at the previous visible line start. Skip
6405 invisible text that is so either due to text properties or due to
6406 selective display. At the end, update IT's overlay information,
6407 face information etc. */
6410 reseat_at_previous_visible_line_start (struct it
*it
)
6412 back_to_previous_visible_line_start (it
);
6413 reseat (it
, it
->current
.pos
, true);
6418 /* Reseat iterator IT on the next visible line start in the current
6419 buffer. ON_NEWLINE_P means position IT on the newline
6420 preceding the line start. Skip over invisible text that is so
6421 because of selective display. Compute faces, overlays etc at the
6422 new position. Note that this function does not skip over text that
6423 is invisible because of text properties. */
6426 reseat_at_next_visible_line_start (struct it
*it
, bool on_newline_p
)
6428 bool skipped_p
= false;
6429 struct bidi_it bidi_it_prev
;
6430 bool newline_found_p
6431 = forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6433 /* Skip over lines that are invisible because they are indented
6434 more than the value of IT->selective. */
6435 if (it
->selective
> 0)
6436 while (IT_CHARPOS (*it
) < ZV
6437 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6440 eassert (IT_BYTEPOS (*it
) == BEGV
6441 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6443 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6446 /* Position on the newline if that's what's requested. */
6447 if (on_newline_p
&& newline_found_p
)
6449 if (STRINGP (it
->string
))
6451 if (IT_STRING_CHARPOS (*it
) > 0)
6455 --IT_STRING_CHARPOS (*it
);
6456 --IT_STRING_BYTEPOS (*it
);
6460 /* We need to restore the bidi iterator to the state
6461 it had on the newline, and resync the IT's
6462 position with that. */
6463 it
->bidi_it
= bidi_it_prev
;
6464 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6465 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6469 else if (IT_CHARPOS (*it
) > BEGV
)
6478 /* We need to restore the bidi iterator to the state it
6479 had on the newline and resync IT with that. */
6480 it
->bidi_it
= bidi_it_prev
;
6481 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6482 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6484 reseat (it
, it
->current
.pos
, false);
6488 reseat (it
, it
->current
.pos
, false);
6495 /***********************************************************************
6496 Changing an iterator's position
6497 ***********************************************************************/
6499 /* Change IT's current position to POS in current_buffer.
6500 If FORCE_P, always check for text properties at the new position.
6501 Otherwise, text properties are only looked up if POS >=
6502 IT->check_charpos of a property. */
6505 reseat (struct it
*it
, struct text_pos pos
, bool force_p
)
6507 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6509 reseat_1 (it
, pos
, false);
6511 /* Determine where to check text properties. Avoid doing it
6512 where possible because text property lookup is very expensive. */
6514 || CHARPOS (pos
) > it
->stop_charpos
6515 || CHARPOS (pos
) < original_pos
)
6519 /* For bidi iteration, we need to prime prev_stop and
6520 base_level_stop with our best estimations. */
6521 /* Implementation note: Of course, POS is not necessarily a
6522 stop position, so assigning prev_pos to it is a lie; we
6523 should have called compute_stop_backwards. However, if
6524 the current buffer does not include any R2L characters,
6525 that call would be a waste of cycles, because the
6526 iterator will never move back, and thus never cross this
6527 "fake" stop position. So we delay that backward search
6528 until the time we really need it, in next_element_from_buffer. */
6529 if (CHARPOS (pos
) != it
->prev_stop
)
6530 it
->prev_stop
= CHARPOS (pos
);
6531 if (CHARPOS (pos
) < it
->base_level_stop
)
6532 it
->base_level_stop
= 0; /* meaning it's unknown */
6538 it
->prev_stop
= it
->base_level_stop
= 0;
6547 /* Change IT's buffer position to POS. SET_STOP_P means set
6548 IT->stop_pos to POS, also. */
6551 reseat_1 (struct it
*it
, struct text_pos pos
, bool set_stop_p
)
6553 /* Don't call this function when scanning a C string. */
6554 eassert (it
->s
== NULL
);
6556 /* POS must be a reasonable value. */
6557 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6559 it
->current
.pos
= it
->position
= pos
;
6560 it
->end_charpos
= ZV
;
6562 it
->current
.dpvec_index
= -1;
6563 it
->current
.overlay_string_index
= -1;
6564 IT_STRING_CHARPOS (*it
) = -1;
6565 IT_STRING_BYTEPOS (*it
) = -1;
6567 it
->method
= GET_FROM_BUFFER
;
6568 it
->object
= it
->w
->contents
;
6569 it
->area
= TEXT_AREA
;
6570 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6572 it
->string_from_display_prop_p
= false;
6573 it
->string_from_prefix_prop_p
= false;
6575 it
->from_disp_prop_p
= false;
6576 it
->face_before_selective_p
= false;
6579 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6581 bidi_unshelve_cache (NULL
, false);
6582 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6583 it
->bidi_it
.string
.s
= NULL
;
6584 it
->bidi_it
.string
.lstring
= Qnil
;
6585 it
->bidi_it
.string
.bufpos
= 0;
6586 it
->bidi_it
.string
.from_disp_str
= false;
6587 it
->bidi_it
.string
.unibyte
= false;
6588 it
->bidi_it
.w
= it
->w
;
6593 it
->stop_charpos
= CHARPOS (pos
);
6594 it
->base_level_stop
= CHARPOS (pos
);
6596 /* This make the information stored in it->cmp_it invalidate. */
6601 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6602 If S is non-null, it is a C string to iterate over. Otherwise,
6603 STRING gives a Lisp string to iterate over.
6605 If PRECISION > 0, don't return more then PRECISION number of
6606 characters from the string.
6608 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6609 characters have been returned. FIELD_WIDTH < 0 means an infinite
6612 MULTIBYTE = 0 means disable processing of multibyte characters,
6613 MULTIBYTE > 0 means enable it,
6614 MULTIBYTE < 0 means use IT->multibyte_p.
6616 IT must be initialized via a prior call to init_iterator before
6617 calling this function. */
6620 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6621 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6624 /* No text property checks performed by default, but see below. */
6625 it
->stop_charpos
= -1;
6627 /* Set iterator position and end position. */
6628 memset (&it
->current
, 0, sizeof it
->current
);
6629 it
->current
.overlay_string_index
= -1;
6630 it
->current
.dpvec_index
= -1;
6631 eassert (charpos
>= 0);
6633 /* If STRING is specified, use its multibyteness, otherwise use the
6634 setting of MULTIBYTE, if specified. */
6636 it
->multibyte_p
= multibyte
> 0;
6638 /* Bidirectional reordering of strings is controlled by the default
6639 value of bidi-display-reordering. Don't try to reorder while
6640 loading loadup.el, as the necessary character property tables are
6641 not yet available. */
6644 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6648 eassert (STRINGP (string
));
6649 it
->string
= string
;
6651 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6652 it
->method
= GET_FROM_STRING
;
6653 it
->current
.string_pos
= string_pos (charpos
, string
);
6657 it
->bidi_it
.string
.lstring
= string
;
6658 it
->bidi_it
.string
.s
= NULL
;
6659 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6660 it
->bidi_it
.string
.bufpos
= 0;
6661 it
->bidi_it
.string
.from_disp_str
= false;
6662 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6663 it
->bidi_it
.w
= it
->w
;
6664 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6665 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6670 it
->s
= (const unsigned char *) s
;
6673 /* Note that we use IT->current.pos, not it->current.string_pos,
6674 for displaying C strings. */
6675 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6676 if (it
->multibyte_p
)
6678 it
->current
.pos
= c_string_pos (charpos
, s
, true);
6679 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, true);
6683 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6684 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6689 it
->bidi_it
.string
.lstring
= Qnil
;
6690 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6691 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6692 it
->bidi_it
.string
.bufpos
= 0;
6693 it
->bidi_it
.string
.from_disp_str
= false;
6694 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6695 it
->bidi_it
.w
= it
->w
;
6696 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6699 it
->method
= GET_FROM_C_STRING
;
6702 /* PRECISION > 0 means don't return more than PRECISION characters
6704 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6706 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6708 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6711 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6712 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6713 FIELD_WIDTH < 0 means infinite field width. This is useful for
6714 padding with `-' at the end of a mode line. */
6715 if (field_width
< 0)
6716 field_width
= INFINITY
;
6717 /* Implementation note: We deliberately don't enlarge
6718 it->bidi_it.string.schars here to fit it->end_charpos, because
6719 the bidi iterator cannot produce characters out of thin air. */
6720 if (field_width
> it
->end_charpos
- charpos
)
6721 it
->end_charpos
= charpos
+ field_width
;
6723 /* Use the standard display table for displaying strings. */
6724 if (DISP_TABLE_P (Vstandard_display_table
))
6725 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6727 it
->stop_charpos
= charpos
;
6728 it
->prev_stop
= charpos
;
6729 it
->base_level_stop
= 0;
6732 it
->bidi_it
.first_elt
= true;
6733 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6734 it
->bidi_it
.disp_pos
= -1;
6736 if (s
== NULL
&& it
->multibyte_p
)
6738 ptrdiff_t endpos
= SCHARS (it
->string
);
6739 if (endpos
> it
->end_charpos
)
6740 endpos
= it
->end_charpos
;
6741 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6749 /***********************************************************************
6751 ***********************************************************************/
6753 /* Map enum it_method value to corresponding next_element_from_* function. */
6755 typedef bool (*next_element_function
) (struct it
*);
6757 static next_element_function
const get_next_element
[NUM_IT_METHODS
] =
6759 next_element_from_buffer
,
6760 next_element_from_display_vector
,
6761 next_element_from_string
,
6762 next_element_from_c_string
,
6763 next_element_from_image
,
6764 next_element_from_stretch
,
6765 next_element_from_xwidget
,
6768 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6771 /* Return true iff a character at CHARPOS (and BYTEPOS) is composed
6772 (possibly with the following characters). */
6774 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6775 ((IT)->cmp_it.id >= 0 \
6776 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6777 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6778 END_CHARPOS, (IT)->w, \
6779 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6783 /* Lookup the char-table Vglyphless_char_display for character C (-1
6784 if we want information for no-font case), and return the display
6785 method symbol. By side-effect, update it->what and
6786 it->glyphless_method. This function is called from
6787 get_next_display_element for each character element, and from
6788 x_produce_glyphs when no suitable font was found. */
6791 lookup_glyphless_char_display (int c
, struct it
*it
)
6793 Lisp_Object glyphless_method
= Qnil
;
6795 if (CHAR_TABLE_P (Vglyphless_char_display
)
6796 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6800 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6801 if (CONSP (glyphless_method
))
6802 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6803 ? XCAR (glyphless_method
)
6804 : XCDR (glyphless_method
);
6807 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6811 if (NILP (glyphless_method
))
6814 /* The default is to display the character by a proper font. */
6816 /* The default for the no-font case is to display an empty box. */
6817 glyphless_method
= Qempty_box
;
6819 if (EQ (glyphless_method
, Qzero_width
))
6822 return glyphless_method
;
6823 /* This method can't be used for the no-font case. */
6824 glyphless_method
= Qempty_box
;
6826 if (EQ (glyphless_method
, Qthin_space
))
6827 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6828 else if (EQ (glyphless_method
, Qempty_box
))
6829 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6830 else if (EQ (glyphless_method
, Qhex_code
))
6831 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6832 else if (STRINGP (glyphless_method
))
6833 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6836 /* Invalid value. We use the default method. */
6837 glyphless_method
= Qnil
;
6840 it
->what
= IT_GLYPHLESS
;
6841 return glyphless_method
;
6844 /* Merge escape glyph face and cache the result. */
6846 static struct frame
*last_escape_glyph_frame
= NULL
;
6847 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6848 static int last_escape_glyph_merged_face_id
= 0;
6851 merge_escape_glyph_face (struct it
*it
)
6855 if (it
->f
== last_escape_glyph_frame
6856 && it
->face_id
== last_escape_glyph_face_id
)
6857 face_id
= last_escape_glyph_merged_face_id
;
6860 /* Merge the `escape-glyph' face into the current face. */
6861 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6862 last_escape_glyph_frame
= it
->f
;
6863 last_escape_glyph_face_id
= it
->face_id
;
6864 last_escape_glyph_merged_face_id
= face_id
;
6869 /* Likewise for glyphless glyph face. */
6871 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6872 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6873 static int last_glyphless_glyph_merged_face_id
= 0;
6876 merge_glyphless_glyph_face (struct it
*it
)
6880 if (it
->f
== last_glyphless_glyph_frame
6881 && it
->face_id
== last_glyphless_glyph_face_id
)
6882 face_id
= last_glyphless_glyph_merged_face_id
;
6885 /* Merge the `glyphless-char' face into the current face. */
6886 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6887 last_glyphless_glyph_frame
= it
->f
;
6888 last_glyphless_glyph_face_id
= it
->face_id
;
6889 last_glyphless_glyph_merged_face_id
= face_id
;
6894 /* Forget the `escape-glyph' and `glyphless-char' faces. This should
6895 be called before redisplaying windows, and when the frame's face
6898 forget_escape_and_glyphless_faces (void)
6900 last_escape_glyph_frame
= NULL
;
6901 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6902 last_glyphless_glyph_frame
= NULL
;
6903 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6906 /* Load IT's display element fields with information about the next
6907 display element from the current position of IT. Value is false if
6908 end of buffer (or C string) is reached. */
6911 get_next_display_element (struct it
*it
)
6913 /* True means that we found a display element. False means that
6914 we hit the end of what we iterate over. Performance note: the
6915 function pointer `method' used here turns out to be faster than
6916 using a sequence of if-statements. */
6920 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6922 if (it
->what
== IT_CHARACTER
)
6924 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6925 and only if (a) the resolved directionality of that character
6927 /* FIXME: Do we need an exception for characters from display
6929 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
6930 && !inhibit_bidi_mirroring
)
6931 it
->c
= bidi_mirror_char (it
->c
);
6932 /* Map via display table or translate control characters.
6933 IT->c, IT->len etc. have been set to the next character by
6934 the function call above. If we have a display table, and it
6935 contains an entry for IT->c, translate it. Don't do this if
6936 IT->c itself comes from a display table, otherwise we could
6937 end up in an infinite recursion. (An alternative could be to
6938 count the recursion depth of this function and signal an
6939 error when a certain maximum depth is reached.) Is it worth
6941 if (success_p
&& it
->dpvec
== NULL
)
6944 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6945 bool nonascii_space_p
= false;
6946 bool nonascii_hyphen_p
= false;
6947 int c
= it
->c
; /* This is the character to display. */
6949 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6951 eassert (SINGLE_BYTE_CHAR_P (c
));
6952 if (unibyte_display_via_language_environment
)
6954 c
= DECODE_CHAR (unibyte
, c
);
6956 c
= BYTE8_TO_CHAR (it
->c
);
6959 c
= BYTE8_TO_CHAR (it
->c
);
6963 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6966 struct Lisp_Vector
*v
= XVECTOR (dv
);
6968 /* Return the first character from the display table
6969 entry, if not empty. If empty, don't display the
6970 current character. */
6973 it
->dpvec_char_len
= it
->len
;
6974 it
->dpvec
= v
->contents
;
6975 it
->dpend
= v
->contents
+ v
->header
.size
;
6976 it
->current
.dpvec_index
= 0;
6977 it
->dpvec_face_id
= -1;
6978 it
->saved_face_id
= it
->face_id
;
6979 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6980 it
->ellipsis_p
= false;
6984 set_iterator_to_next (it
, false);
6989 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6991 if (it
->what
== IT_GLYPHLESS
)
6993 /* Don't display this character. */
6994 set_iterator_to_next (it
, false);
6998 /* If `nobreak-char-display' is non-nil, we display
6999 non-ASCII spaces and hyphens specially. */
7000 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
7002 if (c
== NO_BREAK_SPACE
)
7003 nonascii_space_p
= true;
7004 else if (c
== SOFT_HYPHEN
|| c
== HYPHEN
7005 || c
== NON_BREAKING_HYPHEN
)
7006 nonascii_hyphen_p
= true;
7009 /* Translate control characters into `\003' or `^C' form.
7010 Control characters coming from a display table entry are
7011 currently not translated because we use IT->dpvec to hold
7012 the translation. This could easily be changed but I
7013 don't believe that it is worth doing.
7015 The characters handled by `nobreak-char-display' must be
7018 Non-printable characters and raw-byte characters are also
7019 translated to octal form. */
7020 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
7021 ? (it
->area
!= TEXT_AREA
7022 /* In mode line, treat \n, \t like other crl chars. */
7025 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
7026 || (c
!= '\n' && c
!= '\t'))
7028 || nonascii_hyphen_p
7030 || ! CHAR_PRINTABLE_P (c
))))
7032 /* C is a control character, non-ASCII space/hyphen,
7033 raw-byte, or a non-printable character which must be
7034 displayed either as '\003' or as `^C' where the '\\'
7035 and '^' can be defined in the display table. Fill
7036 IT->ctl_chars with glyphs for what we have to
7037 display. Then, set IT->dpvec to these glyphs. */
7044 /* Handle control characters with ^. */
7046 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
7050 g
= '^'; /* default glyph for Control */
7051 /* Set IT->ctl_chars[0] to the glyph for `^'. */
7053 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
7055 g
= GLYPH_CODE_CHAR (gc
);
7056 lface_id
= GLYPH_CODE_FACE (gc
);
7060 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
7061 : merge_escape_glyph_face (it
));
7063 XSETINT (it
->ctl_chars
[0], g
);
7064 XSETINT (it
->ctl_chars
[1], c
^ 0100);
7066 goto display_control
;
7069 /* Handle non-ascii space in the mode where it only gets
7072 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
7074 /* Merge `nobreak-space' into the current face. */
7075 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
7077 XSETINT (it
->ctl_chars
[0], ' ');
7079 goto display_control
;
7082 /* Handle sequences that start with the "escape glyph". */
7084 /* the default escape glyph is \. */
7085 escape_glyph
= '\\';
7088 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
7090 escape_glyph
= GLYPH_CODE_CHAR (gc
);
7091 lface_id
= GLYPH_CODE_FACE (gc
);
7095 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
7096 : merge_escape_glyph_face (it
));
7098 /* Draw non-ASCII hyphen with just highlighting: */
7100 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
7102 XSETINT (it
->ctl_chars
[0], '-');
7104 goto display_control
;
7107 /* Draw non-ASCII space/hyphen with escape glyph: */
7109 if (nonascii_space_p
|| nonascii_hyphen_p
)
7111 XSETINT (it
->ctl_chars
[0], escape_glyph
);
7112 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
7114 goto display_control
;
7121 if (CHAR_BYTE8_P (c
))
7122 /* Display \200 instead of \17777600. */
7123 c
= CHAR_TO_BYTE8 (c
);
7124 len
= sprintf (str
, "%03o", c
+ 0u);
7126 XSETINT (it
->ctl_chars
[0], escape_glyph
);
7127 for (i
= 0; i
< len
; i
++)
7128 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
7133 /* Set up IT->dpvec and return first character from it. */
7134 it
->dpvec_char_len
= it
->len
;
7135 it
->dpvec
= it
->ctl_chars
;
7136 it
->dpend
= it
->dpvec
+ ctl_len
;
7137 it
->current
.dpvec_index
= 0;
7138 it
->dpvec_face_id
= face_id
;
7139 it
->saved_face_id
= it
->face_id
;
7140 it
->method
= GET_FROM_DISPLAY_VECTOR
;
7141 it
->ellipsis_p
= false;
7144 it
->char_to_display
= c
;
7148 it
->char_to_display
= it
->c
;
7152 #ifdef HAVE_WINDOW_SYSTEM
7153 /* Adjust face id for a multibyte character. There are no multibyte
7154 character in unibyte text. */
7155 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
7158 && FRAME_WINDOW_P (it
->f
))
7160 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7162 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
7164 /* Automatic composition with glyph-string. */
7165 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
7167 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
7171 ptrdiff_t pos
= (it
->s
? -1
7172 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
7173 : IT_CHARPOS (*it
));
7176 if (it
->what
== IT_CHARACTER
)
7177 c
= it
->char_to_display
;
7180 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
7184 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7185 /* TAB in a composition means display glyphs with
7186 padding space on the left or right. */
7187 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7190 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7193 #endif /* HAVE_WINDOW_SYSTEM */
7196 /* Is this character the last one of a run of characters with
7197 box? If yes, set IT->end_of_box_run_p to true. */
7201 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7203 int face_id
= underlying_face_id (it
);
7204 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7208 if (face
->box
== FACE_NO_BOX
)
7210 /* If the box comes from face properties in a
7211 display string, check faces in that string. */
7212 int string_face_id
= face_after_it_pos (it
);
7213 it
->end_of_box_run_p
7214 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7217 /* Otherwise, the box comes from the underlying face.
7218 If this is the last string character displayed, check
7219 the next buffer location. */
7220 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7221 /* n_overlay_strings is unreliable unless
7222 overlay_string_index is non-negative. */
7223 && ((it
->current
.overlay_string_index
>= 0
7224 && (it
->current
.overlay_string_index
7225 == it
->n_overlay_strings
- 1))
7226 /* A string from display property. */
7227 || it
->from_disp_prop_p
))
7231 struct text_pos pos
= it
->current
.pos
;
7233 /* For a string from a display property, the next
7234 buffer position is stored in the 'position'
7235 member of the iteration stack slot below the
7236 current one, see handle_single_display_spec. By
7237 contrast, it->current.pos was is not yet updated
7238 to point to that buffer position; that will
7239 happen in pop_it, after we finish displaying the
7240 current string. Note that we already checked
7241 above that it->sp is positive, so subtracting one
7243 if (it
->from_disp_prop_p
)
7244 pos
= (it
->stack
+ it
->sp
- 1)->position
;
7246 INC_TEXT_POS (pos
, it
->multibyte_p
);
7248 if (CHARPOS (pos
) >= ZV
)
7249 it
->end_of_box_run_p
= true;
7252 next_face_id
= face_at_buffer_position
7253 (it
->w
, CHARPOS (pos
), &ignore
,
7254 CHARPOS (pos
) + TEXT_PROP_DISTANCE_LIMIT
, false, -1);
7255 it
->end_of_box_run_p
7256 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7262 /* next_element_from_display_vector sets this flag according to
7263 faces of the display vector glyphs, see there. */
7264 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7266 int face_id
= face_after_it_pos (it
);
7267 it
->end_of_box_run_p
7268 = (face_id
!= it
->face_id
7269 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7272 /* If we reached the end of the object we've been iterating (e.g., a
7273 display string or an overlay string), and there's something on
7274 IT->stack, proceed with what's on the stack. It doesn't make
7275 sense to return false if there's unprocessed stuff on the stack,
7276 because otherwise that stuff will never be displayed. */
7277 if (!success_p
&& it
->sp
> 0)
7279 set_iterator_to_next (it
, false);
7280 success_p
= get_next_display_element (it
);
7283 /* Value is false if end of buffer or string reached. */
7288 /* Move IT to the next display element.
7290 RESEAT_P means if called on a newline in buffer text,
7291 skip to the next visible line start.
7293 Functions get_next_display_element and set_iterator_to_next are
7294 separate because I find this arrangement easier to handle than a
7295 get_next_display_element function that also increments IT's
7296 position. The way it is we can first look at an iterator's current
7297 display element, decide whether it fits on a line, and if it does,
7298 increment the iterator position. The other way around we probably
7299 would either need a flag indicating whether the iterator has to be
7300 incremented the next time, or we would have to implement a
7301 decrement position function which would not be easy to write. */
7304 set_iterator_to_next (struct it
*it
, bool reseat_p
)
7306 /* Reset flags indicating start and end of a sequence of characters
7307 with box. Reset them at the start of this function because
7308 moving the iterator to a new position might set them. */
7309 it
->start_of_box_run_p
= it
->end_of_box_run_p
= false;
7313 case GET_FROM_BUFFER
:
7314 /* The current display element of IT is a character from
7315 current_buffer. Advance in the buffer, and maybe skip over
7316 invisible lines that are so because of selective display. */
7317 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7318 reseat_at_next_visible_line_start (it
, false);
7319 else if (it
->cmp_it
.id
>= 0)
7321 /* We are currently getting glyphs from a composition. */
7324 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7325 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7331 /* Update IT's char/byte positions to point to the first
7332 character of the next grapheme cluster, or to the
7333 character visually after the current composition. */
7334 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7335 bidi_move_to_visually_next (&it
->bidi_it
);
7336 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7337 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7340 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7341 && it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7343 /* Composition created while scanning forward. Proceed
7344 to the next grapheme cluster. */
7345 it
->cmp_it
.from
= it
->cmp_it
.to
;
7347 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7348 && it
->cmp_it
.from
> 0)
7350 /* Composition created while scanning backward. Proceed
7351 to the previous grapheme cluster. */
7352 it
->cmp_it
.to
= it
->cmp_it
.from
;
7356 /* No more grapheme clusters in this composition.
7357 Find the next stop position. */
7358 ptrdiff_t stop
= it
->end_charpos
;
7360 if (it
->bidi_it
.scan_dir
< 0)
7361 /* Now we are scanning backward and don't know
7364 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7365 IT_BYTEPOS (*it
), stop
, Qnil
);
7370 eassert (it
->len
!= 0);
7374 IT_BYTEPOS (*it
) += it
->len
;
7375 IT_CHARPOS (*it
) += 1;
7379 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7380 /* If this is a new paragraph, determine its base
7381 direction (a.k.a. its base embedding level). */
7382 if (it
->bidi_it
.new_paragraph
)
7383 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
7385 bidi_move_to_visually_next (&it
->bidi_it
);
7386 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7387 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7388 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7390 /* As the scan direction was changed, we must
7391 re-compute the stop position for composition. */
7392 ptrdiff_t stop
= it
->end_charpos
;
7393 if (it
->bidi_it
.scan_dir
< 0)
7395 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7396 IT_BYTEPOS (*it
), stop
, Qnil
);
7399 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7403 case GET_FROM_C_STRING
:
7404 /* Current display element of IT is from a C string. */
7406 /* If the string position is beyond string's end, it means
7407 next_element_from_c_string is padding the string with
7408 blanks, in which case we bypass the bidi iterator,
7409 because it cannot deal with such virtual characters. */
7410 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7412 IT_BYTEPOS (*it
) += it
->len
;
7413 IT_CHARPOS (*it
) += 1;
7417 bidi_move_to_visually_next (&it
->bidi_it
);
7418 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7419 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7423 case GET_FROM_DISPLAY_VECTOR
:
7424 /* Current display element of IT is from a display table entry.
7425 Advance in the display table definition. Reset it to null if
7426 end reached, and continue with characters from buffers/
7428 ++it
->current
.dpvec_index
;
7430 /* Restore face of the iterator to what they were before the
7431 display vector entry (these entries may contain faces). */
7432 it
->face_id
= it
->saved_face_id
;
7434 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7436 bool recheck_faces
= it
->ellipsis_p
;
7439 it
->method
= GET_FROM_C_STRING
;
7440 else if (STRINGP (it
->string
))
7441 it
->method
= GET_FROM_STRING
;
7444 it
->method
= GET_FROM_BUFFER
;
7445 it
->object
= it
->w
->contents
;
7449 it
->current
.dpvec_index
= -1;
7451 /* Skip over characters which were displayed via IT->dpvec. */
7452 if (it
->dpvec_char_len
< 0)
7453 reseat_at_next_visible_line_start (it
, true);
7454 else if (it
->dpvec_char_len
> 0)
7456 it
->len
= it
->dpvec_char_len
;
7457 set_iterator_to_next (it
, reseat_p
);
7460 /* Maybe recheck faces after display vector. */
7463 if (it
->method
== GET_FROM_STRING
)
7464 it
->stop_charpos
= IT_STRING_CHARPOS (*it
);
7466 it
->stop_charpos
= IT_CHARPOS (*it
);
7471 case GET_FROM_STRING
:
7472 /* Current display element is a character from a Lisp string. */
7473 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7474 /* Don't advance past string end. These conditions are true
7475 when set_iterator_to_next is called at the end of
7476 get_next_display_element, in which case the Lisp string is
7477 already exhausted, and all we want is pop the iterator
7479 if (it
->current
.overlay_string_index
>= 0)
7481 /* This is an overlay string, so there's no padding with
7482 spaces, and the number of characters in the string is
7483 where the string ends. */
7484 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7485 goto consider_string_end
;
7489 /* Not an overlay string. There could be padding, so test
7490 against it->end_charpos. */
7491 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7492 goto consider_string_end
;
7494 if (it
->cmp_it
.id
>= 0)
7496 /* We are delivering display elements from a composition.
7497 Update the string position past the grapheme cluster
7498 we've just processed. */
7501 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7502 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7508 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7509 bidi_move_to_visually_next (&it
->bidi_it
);
7510 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7511 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7514 /* Did we exhaust all the grapheme clusters of this
7516 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7517 && (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
))
7519 /* Not all the grapheme clusters were processed yet;
7520 advance to the next cluster. */
7521 it
->cmp_it
.from
= it
->cmp_it
.to
;
7523 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7524 && it
->cmp_it
.from
> 0)
7526 /* Likewise: advance to the next cluster, but going in
7527 the reverse direction. */
7528 it
->cmp_it
.to
= it
->cmp_it
.from
;
7532 /* This composition was fully processed; find the next
7533 candidate place for checking for composed
7535 /* Always limit string searches to the string length;
7536 any padding spaces are not part of the string, and
7537 there cannot be any compositions in that padding. */
7538 ptrdiff_t stop
= SCHARS (it
->string
);
7540 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
7542 else if (it
->end_charpos
< stop
)
7544 /* Cf. PRECISION in reseat_to_string: we might be
7545 limited in how many of the string characters we
7547 stop
= it
->end_charpos
;
7549 composition_compute_stop_pos (&it
->cmp_it
,
7550 IT_STRING_CHARPOS (*it
),
7551 IT_STRING_BYTEPOS (*it
), stop
,
7558 /* If the string position is beyond string's end, it
7559 means next_element_from_string is padding the string
7560 with blanks, in which case we bypass the bidi
7561 iterator, because it cannot deal with such virtual
7563 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7565 IT_STRING_BYTEPOS (*it
) += it
->len
;
7566 IT_STRING_CHARPOS (*it
) += 1;
7570 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7572 bidi_move_to_visually_next (&it
->bidi_it
);
7573 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7574 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7575 /* If the scan direction changes, we may need to update
7576 the place where to check for composed characters. */
7577 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7579 ptrdiff_t stop
= SCHARS (it
->string
);
7581 if (it
->bidi_it
.scan_dir
< 0)
7583 else if (it
->end_charpos
< stop
)
7584 stop
= it
->end_charpos
;
7586 composition_compute_stop_pos (&it
->cmp_it
,
7587 IT_STRING_CHARPOS (*it
),
7588 IT_STRING_BYTEPOS (*it
), stop
,
7594 consider_string_end
:
7596 if (it
->current
.overlay_string_index
>= 0)
7598 /* IT->string is an overlay string. Advance to the
7599 next, if there is one. */
7600 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7602 it
->ellipsis_p
= false;
7603 next_overlay_string (it
);
7605 setup_for_ellipsis (it
, 0);
7610 /* IT->string is not an overlay string. If we reached
7611 its end, and there is something on IT->stack, proceed
7612 with what is on the stack. This can be either another
7613 string, this time an overlay string, or a buffer. */
7614 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7618 if (it
->method
== GET_FROM_STRING
)
7619 goto consider_string_end
;
7624 case GET_FROM_IMAGE
:
7625 case GET_FROM_STRETCH
:
7626 case GET_FROM_XWIDGET
:
7628 /* The position etc with which we have to proceed are on
7629 the stack. The position may be at the end of a string,
7630 if the `display' property takes up the whole string. */
7631 eassert (it
->sp
> 0);
7633 if (it
->method
== GET_FROM_STRING
)
7634 goto consider_string_end
;
7638 /* There are no other methods defined, so this should be a bug. */
7642 eassert (it
->method
!= GET_FROM_STRING
7643 || (STRINGP (it
->string
)
7644 && IT_STRING_CHARPOS (*it
) >= 0));
7647 /* Load IT's display element fields with information about the next
7648 display element which comes from a display table entry or from the
7649 result of translating a control character to one of the forms `^C'
7652 IT->dpvec holds the glyphs to return as characters.
7653 IT->saved_face_id holds the face id before the display vector--it
7654 is restored into IT->face_id in set_iterator_to_next. */
7657 next_element_from_display_vector (struct it
*it
)
7660 int prev_face_id
= it
->face_id
;
7664 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7666 it
->face_id
= it
->saved_face_id
;
7668 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7669 That seemed totally bogus - so I changed it... */
7670 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7672 if (GLYPH_CODE_P (gc
))
7674 struct face
*this_face
, *prev_face
, *next_face
;
7676 it
->c
= GLYPH_CODE_CHAR (gc
);
7677 it
->len
= CHAR_BYTES (it
->c
);
7679 /* The entry may contain a face id to use. Such a face id is
7680 the id of a Lisp face, not a realized face. A face id of
7681 zero means no face is specified. */
7682 if (it
->dpvec_face_id
>= 0)
7683 it
->face_id
= it
->dpvec_face_id
;
7686 int lface_id
= GLYPH_CODE_FACE (gc
);
7688 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7692 /* Glyphs in the display vector could have the box face, so we
7693 need to set the related flags in the iterator, as
7695 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7696 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7698 /* Is this character the first character of a box-face run? */
7699 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7701 || prev_face
->box
== FACE_NO_BOX
));
7703 /* For the last character of the box-face run, we need to look
7704 either at the next glyph from the display vector, or at the
7705 face we saw before the display vector. */
7706 next_face_id
= it
->saved_face_id
;
7707 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7709 if (it
->dpvec_face_id
>= 0)
7710 next_face_id
= it
->dpvec_face_id
;
7714 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7717 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7721 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7722 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7724 || next_face
->box
== FACE_NO_BOX
));
7725 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7728 /* Display table entry is invalid. Return a space. */
7729 it
->c
= ' ', it
->len
= 1;
7731 /* Don't change position and object of the iterator here. They are
7732 still the values of the character that had this display table
7733 entry or was translated, and that's what we want. */
7734 it
->what
= IT_CHARACTER
;
7738 /* Get the first element of string/buffer in the visual order, after
7739 being reseated to a new position in a string or a buffer. */
7741 get_visually_first_element (struct it
*it
)
7743 bool string_p
= STRINGP (it
->string
) || it
->s
;
7744 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7745 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7747 if (STRINGP (it
->string
))
7749 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7750 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7754 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7755 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7758 if (it
->bidi_it
.charpos
== eob
)
7760 /* Nothing to do, but reset the FIRST_ELT flag, like
7761 bidi_paragraph_init does, because we are not going to
7763 it
->bidi_it
.first_elt
= false;
7765 else if (it
->bidi_it
.charpos
== bob
7767 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7768 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7770 /* If we are at the beginning of a line/string, we can produce
7771 the next element right away. */
7772 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7773 bidi_move_to_visually_next (&it
->bidi_it
);
7777 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7779 /* We need to prime the bidi iterator starting at the line's or
7780 string's beginning, before we will be able to produce the
7783 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7785 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7786 IT_BYTEPOS (*it
), -1,
7787 &it
->bidi_it
.bytepos
);
7788 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7791 /* Now return to buffer/string position where we were asked
7792 to get the next display element, and produce that. */
7793 bidi_move_to_visually_next (&it
->bidi_it
);
7795 while (it
->bidi_it
.bytepos
!= orig_bytepos
7796 && it
->bidi_it
.charpos
< eob
);
7799 /* Adjust IT's position information to where we ended up. */
7800 if (STRINGP (it
->string
))
7802 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7803 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7807 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7808 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7811 if (STRINGP (it
->string
) || !it
->s
)
7813 ptrdiff_t stop
, charpos
, bytepos
;
7815 if (STRINGP (it
->string
))
7818 stop
= SCHARS (it
->string
);
7819 if (stop
> it
->end_charpos
)
7820 stop
= it
->end_charpos
;
7821 charpos
= IT_STRING_CHARPOS (*it
);
7822 bytepos
= IT_STRING_BYTEPOS (*it
);
7826 stop
= it
->end_charpos
;
7827 charpos
= IT_CHARPOS (*it
);
7828 bytepos
= IT_BYTEPOS (*it
);
7830 if (it
->bidi_it
.scan_dir
< 0)
7832 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7837 /* Load IT with the next display element from Lisp string IT->string.
7838 IT->current.string_pos is the current position within the string.
7839 If IT->current.overlay_string_index >= 0, the Lisp string is an
7843 next_element_from_string (struct it
*it
)
7845 struct text_pos position
;
7847 eassert (STRINGP (it
->string
));
7848 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7849 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7850 position
= it
->current
.string_pos
;
7852 /* With bidi reordering, the character to display might not be the
7853 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT means
7854 that we were reseat()ed to a new string, whose paragraph
7855 direction is not known. */
7856 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7858 get_visually_first_element (it
);
7859 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7862 /* Time to check for invisible text? */
7863 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7865 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7868 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7869 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7871 /* With bidi non-linear iteration, we could find
7872 ourselves far beyond the last computed stop_charpos,
7873 with several other stop positions in between that we
7874 missed. Scan them all now, in buffer's logical
7875 order, until we find and handle the last stop_charpos
7876 that precedes our current position. */
7877 handle_stop_backwards (it
, it
->stop_charpos
);
7878 return GET_NEXT_DISPLAY_ELEMENT (it
);
7884 /* Take note of the stop position we just moved
7885 across, for when we will move back across it. */
7886 it
->prev_stop
= it
->stop_charpos
;
7887 /* If we are at base paragraph embedding level, take
7888 note of the last stop position seen at this
7890 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7891 it
->base_level_stop
= it
->stop_charpos
;
7895 /* Since a handler may have changed IT->method, we must
7897 return GET_NEXT_DISPLAY_ELEMENT (it
);
7901 /* If we are before prev_stop, we may have overstepped
7902 on our way backwards a stop_pos, and if so, we need
7903 to handle that stop_pos. */
7904 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7905 /* We can sometimes back up for reasons that have nothing
7906 to do with bidi reordering. E.g., compositions. The
7907 code below is only needed when we are above the base
7908 embedding level, so test for that explicitly. */
7909 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7911 /* If we lost track of base_level_stop, we have no better
7912 place for handle_stop_backwards to start from than string
7913 beginning. This happens, e.g., when we were reseated to
7914 the previous screenful of text by vertical-motion. */
7915 if (it
->base_level_stop
<= 0
7916 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7917 it
->base_level_stop
= 0;
7918 handle_stop_backwards (it
, it
->base_level_stop
);
7919 return GET_NEXT_DISPLAY_ELEMENT (it
);
7923 if (it
->current
.overlay_string_index
>= 0)
7925 /* Get the next character from an overlay string. In overlay
7926 strings, there is no field width or padding with spaces to
7928 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7933 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7934 IT_STRING_BYTEPOS (*it
),
7935 it
->bidi_it
.scan_dir
< 0
7937 : SCHARS (it
->string
))
7938 && next_element_from_composition (it
))
7942 else if (STRING_MULTIBYTE (it
->string
))
7944 const unsigned char *s
= (SDATA (it
->string
)
7945 + IT_STRING_BYTEPOS (*it
));
7946 it
->c
= string_char_and_length (s
, &it
->len
);
7950 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7956 /* Get the next character from a Lisp string that is not an
7957 overlay string. Such strings come from the mode line, for
7958 example. We may have to pad with spaces, or truncate the
7959 string. See also next_element_from_c_string. */
7960 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7965 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7967 /* Pad with spaces. */
7968 it
->c
= ' ', it
->len
= 1;
7969 CHARPOS (position
) = BYTEPOS (position
) = -1;
7971 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7972 IT_STRING_BYTEPOS (*it
),
7973 it
->bidi_it
.scan_dir
< 0
7975 : it
->string_nchars
)
7976 && next_element_from_composition (it
))
7980 else if (STRING_MULTIBYTE (it
->string
))
7982 const unsigned char *s
= (SDATA (it
->string
)
7983 + IT_STRING_BYTEPOS (*it
));
7984 it
->c
= string_char_and_length (s
, &it
->len
);
7988 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7993 /* Record what we have and where it came from. */
7994 it
->what
= IT_CHARACTER
;
7995 it
->object
= it
->string
;
7996 it
->position
= position
;
8001 /* Load IT with next display element from C string IT->s.
8002 IT->string_nchars is the maximum number of characters to return
8003 from the string. IT->end_charpos may be greater than
8004 IT->string_nchars when this function is called, in which case we
8005 may have to return padding spaces. Value is false if end of string
8006 reached, including padding spaces. */
8009 next_element_from_c_string (struct it
*it
)
8011 bool success_p
= true;
8014 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
8015 it
->what
= IT_CHARACTER
;
8016 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
8017 it
->object
= make_number (0);
8019 /* With bidi reordering, the character to display might not be the
8020 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8021 we were reseated to a new string, whose paragraph direction is
8023 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8024 get_visually_first_element (it
);
8026 /* IT's position can be greater than IT->string_nchars in case a
8027 field width or precision has been specified when the iterator was
8029 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8031 /* End of the game. */
8035 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
8037 /* Pad with spaces. */
8038 it
->c
= ' ', it
->len
= 1;
8039 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
8041 else if (it
->multibyte_p
)
8042 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
8044 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
8050 /* Set up IT to return characters from an ellipsis, if appropriate.
8051 The definition of the ellipsis glyphs may come from a display table
8052 entry. This function fills IT with the first glyph from the
8053 ellipsis if an ellipsis is to be displayed. */
8056 next_element_from_ellipsis (struct it
*it
)
8058 if (it
->selective_display_ellipsis_p
)
8059 setup_for_ellipsis (it
, it
->len
);
8062 /* The face at the current position may be different from the
8063 face we find after the invisible text. Remember what it
8064 was in IT->saved_face_id, and signal that it's there by
8065 setting face_before_selective_p. */
8066 it
->saved_face_id
= it
->face_id
;
8067 it
->method
= GET_FROM_BUFFER
;
8068 it
->object
= it
->w
->contents
;
8069 reseat_at_next_visible_line_start (it
, true);
8070 it
->face_before_selective_p
= true;
8073 return GET_NEXT_DISPLAY_ELEMENT (it
);
8077 /* Deliver an image display element. The iterator IT is already
8078 filled with image information (done in handle_display_prop). Value
8083 next_element_from_image (struct it
*it
)
8085 it
->what
= IT_IMAGE
;
8090 next_element_from_xwidget (struct it
*it
)
8092 it
->what
= IT_XWIDGET
;
8097 /* Fill iterator IT with next display element from a stretch glyph
8098 property. IT->object is the value of the text property. Value is
8102 next_element_from_stretch (struct it
*it
)
8104 it
->what
= IT_STRETCH
;
8108 /* Scan backwards from IT's current position until we find a stop
8109 position, or until BEGV. This is called when we find ourself
8110 before both the last known prev_stop and base_level_stop while
8111 reordering bidirectional text. */
8114 compute_stop_pos_backwards (struct it
*it
)
8116 const int SCAN_BACK_LIMIT
= 1000;
8117 struct text_pos pos
;
8118 struct display_pos save_current
= it
->current
;
8119 struct text_pos save_position
= it
->position
;
8120 ptrdiff_t charpos
= IT_CHARPOS (*it
);
8121 ptrdiff_t where_we_are
= charpos
;
8122 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
8123 ptrdiff_t save_end_pos
= it
->end_charpos
;
8125 eassert (NILP (it
->string
) && !it
->s
);
8126 eassert (it
->bidi_p
);
8130 it
->end_charpos
= min (charpos
+ 1, ZV
);
8131 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
8132 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
8133 reseat_1 (it
, pos
, false);
8134 compute_stop_pos (it
);
8135 /* We must advance forward, right? */
8136 if (it
->stop_charpos
<= charpos
)
8139 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
8141 if (it
->stop_charpos
<= where_we_are
)
8142 it
->prev_stop
= it
->stop_charpos
;
8144 it
->prev_stop
= BEGV
;
8146 it
->current
= save_current
;
8147 it
->position
= save_position
;
8148 it
->stop_charpos
= save_stop_pos
;
8149 it
->end_charpos
= save_end_pos
;
8152 /* Scan forward from CHARPOS in the current buffer/string, until we
8153 find a stop position > current IT's position. Then handle the stop
8154 position before that. This is called when we bump into a stop
8155 position while reordering bidirectional text. CHARPOS should be
8156 the last previously processed stop_pos (or BEGV/0, if none were
8157 processed yet) whose position is less that IT's current
8161 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
8163 bool bufp
= !STRINGP (it
->string
);
8164 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
8165 struct display_pos save_current
= it
->current
;
8166 struct text_pos save_position
= it
->position
;
8167 struct text_pos pos1
;
8168 ptrdiff_t next_stop
;
8170 /* Scan in strict logical order. */
8171 eassert (it
->bidi_p
);
8175 it
->prev_stop
= charpos
;
8178 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
8179 reseat_1 (it
, pos1
, false);
8182 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
8183 compute_stop_pos (it
);
8184 /* We must advance forward, right? */
8185 if (it
->stop_charpos
<= it
->prev_stop
)
8187 charpos
= it
->stop_charpos
;
8189 while (charpos
<= where_we_are
);
8192 it
->current
= save_current
;
8193 it
->position
= save_position
;
8194 next_stop
= it
->stop_charpos
;
8195 it
->stop_charpos
= it
->prev_stop
;
8197 it
->stop_charpos
= next_stop
;
8200 /* Load IT with the next display element from current_buffer. Value
8201 is false if end of buffer reached. IT->stop_charpos is the next
8202 position at which to stop and check for text properties or buffer
8206 next_element_from_buffer (struct it
*it
)
8208 bool success_p
= true;
8210 eassert (IT_CHARPOS (*it
) >= BEGV
);
8211 eassert (NILP (it
->string
) && !it
->s
);
8212 eassert (!it
->bidi_p
8213 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8214 && it
->bidi_it
.string
.s
== NULL
));
8216 /* With bidi reordering, the character to display might not be the
8217 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8218 we were reseat()ed to a new buffer position, which is potentially
8219 a different paragraph. */
8220 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8222 get_visually_first_element (it
);
8223 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8226 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8228 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8230 bool overlay_strings_follow_p
;
8232 /* End of the game, except when overlay strings follow that
8233 haven't been returned yet. */
8234 if (it
->overlay_strings_at_end_processed_p
)
8235 overlay_strings_follow_p
= false;
8238 it
->overlay_strings_at_end_processed_p
= true;
8239 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8242 if (overlay_strings_follow_p
)
8243 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8247 it
->position
= it
->current
.pos
;
8251 else if (!(!it
->bidi_p
8252 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8253 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8255 /* With bidi non-linear iteration, we could find ourselves
8256 far beyond the last computed stop_charpos, with several
8257 other stop positions in between that we missed. Scan
8258 them all now, in buffer's logical order, until we find
8259 and handle the last stop_charpos that precedes our
8260 current position. */
8261 handle_stop_backwards (it
, it
->stop_charpos
);
8262 it
->ignore_overlay_strings_at_pos_p
= false;
8263 return GET_NEXT_DISPLAY_ELEMENT (it
);
8269 /* Take note of the stop position we just moved across,
8270 for when we will move back across it. */
8271 it
->prev_stop
= it
->stop_charpos
;
8272 /* If we are at base paragraph embedding level, take
8273 note of the last stop position seen at this
8275 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8276 it
->base_level_stop
= it
->stop_charpos
;
8279 it
->ignore_overlay_strings_at_pos_p
= false;
8280 return GET_NEXT_DISPLAY_ELEMENT (it
);
8284 /* If we are before prev_stop, we may have overstepped on
8285 our way backwards a stop_pos, and if so, we need to
8286 handle that stop_pos. */
8287 && IT_CHARPOS (*it
) < it
->prev_stop
8288 /* We can sometimes back up for reasons that have nothing
8289 to do with bidi reordering. E.g., compositions. The
8290 code below is only needed when we are above the base
8291 embedding level, so test for that explicitly. */
8292 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8294 if (it
->base_level_stop
<= 0
8295 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8297 /* If we lost track of base_level_stop, we need to find
8298 prev_stop by looking backwards. This happens, e.g., when
8299 we were reseated to the previous screenful of text by
8301 it
->base_level_stop
= BEGV
;
8302 compute_stop_pos_backwards (it
);
8303 handle_stop_backwards (it
, it
->prev_stop
);
8306 handle_stop_backwards (it
, it
->base_level_stop
);
8307 it
->ignore_overlay_strings_at_pos_p
= false;
8308 return GET_NEXT_DISPLAY_ELEMENT (it
);
8312 /* No face changes, overlays etc. in sight, so just return a
8313 character from current_buffer. */
8317 /* We moved to the next buffer position, so any info about
8318 previously seen overlays is no longer valid. */
8319 it
->ignore_overlay_strings_at_pos_p
= false;
8321 /* Maybe run the redisplay end trigger hook. Performance note:
8322 This doesn't seem to cost measurable time. */
8323 if (it
->redisplay_end_trigger_charpos
8325 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8326 run_redisplay_end_trigger_hook (it
);
8328 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8329 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8331 && next_element_from_composition (it
))
8336 /* Get the next character, maybe multibyte. */
8337 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8338 if (it
->multibyte_p
&& !ASCII_CHAR_P (*p
))
8339 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8341 it
->c
= *p
, it
->len
= 1;
8343 /* Record what we have and where it came from. */
8344 it
->what
= IT_CHARACTER
;
8345 it
->object
= it
->w
->contents
;
8346 it
->position
= it
->current
.pos
;
8348 /* Normally we return the character found above, except when we
8349 really want to return an ellipsis for selective display. */
8354 /* A value of selective > 0 means hide lines indented more
8355 than that number of columns. */
8356 if (it
->selective
> 0
8357 && IT_CHARPOS (*it
) + 1 < ZV
8358 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8359 IT_BYTEPOS (*it
) + 1,
8362 success_p
= next_element_from_ellipsis (it
);
8363 it
->dpvec_char_len
= -1;
8366 else if (it
->c
== '\r' && it
->selective
== -1)
8368 /* A value of selective == -1 means that everything from the
8369 CR to the end of the line is invisible, with maybe an
8370 ellipsis displayed for it. */
8371 success_p
= next_element_from_ellipsis (it
);
8372 it
->dpvec_char_len
= -1;
8377 /* Value is false if end of buffer reached. */
8378 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8383 /* Run the redisplay end trigger hook for IT. */
8386 run_redisplay_end_trigger_hook (struct it
*it
)
8388 /* IT->glyph_row should be non-null, i.e. we should be actually
8389 displaying something, or otherwise we should not run the hook. */
8390 eassert (it
->glyph_row
);
8392 ptrdiff_t charpos
= it
->redisplay_end_trigger_charpos
;
8393 it
->redisplay_end_trigger_charpos
= 0;
8395 /* Since we are *trying* to run these functions, don't try to run
8396 them again, even if they get an error. */
8397 wset_redisplay_end_trigger (it
->w
, Qnil
);
8398 CALLN (Frun_hook_with_args
, Qredisplay_end_trigger_functions
, it
->window
,
8399 make_number (charpos
));
8401 /* Notice if it changed the face of the character we are on. */
8402 handle_face_prop (it
);
8406 /* Deliver a composition display element. Unlike the other
8407 next_element_from_XXX, this function is not registered in the array
8408 get_next_element[]. It is called from next_element_from_buffer and
8409 next_element_from_string when necessary. */
8412 next_element_from_composition (struct it
*it
)
8414 it
->what
= IT_COMPOSITION
;
8415 it
->len
= it
->cmp_it
.nbytes
;
8416 if (STRINGP (it
->string
))
8420 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8421 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8424 it
->position
= it
->current
.string_pos
;
8425 it
->object
= it
->string
;
8426 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8427 IT_STRING_BYTEPOS (*it
), it
->string
);
8433 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8434 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8437 if (it
->bidi_it
.new_paragraph
)
8438 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
8440 /* Resync the bidi iterator with IT's new position.
8441 FIXME: this doesn't support bidirectional text. */
8442 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8443 bidi_move_to_visually_next (&it
->bidi_it
);
8447 it
->position
= it
->current
.pos
;
8448 it
->object
= it
->w
->contents
;
8449 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8450 IT_BYTEPOS (*it
), Qnil
);
8457 /***********************************************************************
8458 Moving an iterator without producing glyphs
8459 ***********************************************************************/
8461 /* Check if iterator is at a position corresponding to a valid buffer
8462 position after some move_it_ call. */
8464 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8465 ((it)->method != GET_FROM_STRING || IT_STRING_CHARPOS (*it) == 0)
8468 /* Move iterator IT to a specified buffer or X position within one
8469 line on the display without producing glyphs.
8471 OP should be a bit mask including some or all of these bits:
8472 MOVE_TO_X: Stop upon reaching x-position TO_X.
8473 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8474 Regardless of OP's value, stop upon reaching the end of the display line.
8476 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8477 This means, in particular, that TO_X includes window's horizontal
8480 The return value has several possible values that
8481 say what condition caused the scan to stop:
8483 MOVE_POS_MATCH_OR_ZV
8484 - when TO_POS or ZV was reached.
8487 -when TO_X was reached before TO_POS or ZV were reached.
8490 - when we reached the end of the display area and the line must
8494 - when we reached the end of the display area and the line is
8498 - when we stopped at a line end, i.e. a newline or a CR and selective
8501 static enum move_it_result
8502 move_it_in_display_line_to (struct it
*it
,
8503 ptrdiff_t to_charpos
, int to_x
,
8504 enum move_operation_enum op
)
8506 enum move_it_result result
= MOVE_UNDEFINED
;
8507 struct glyph_row
*saved_glyph_row
;
8508 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8509 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8510 void *ppos_data
= NULL
;
8511 bool may_wrap
= false;
8512 enum it_method prev_method
= it
->method
;
8513 ptrdiff_t closest_pos
IF_LINT (= 0), prev_pos
= IT_CHARPOS (*it
);
8514 bool saw_smaller_pos
= prev_pos
< to_charpos
;
8516 /* Don't produce glyphs in produce_glyphs. */
8517 saved_glyph_row
= it
->glyph_row
;
8518 it
->glyph_row
= NULL
;
8520 /* Use wrap_it to save a copy of IT wherever a word wrap could
8521 occur. Use atpos_it to save a copy of IT at the desired buffer
8522 position, if found, so that we can scan ahead and check if the
8523 word later overshoots the window edge. Use atx_it similarly, for
8529 /* Use ppos_it under bidi reordering to save a copy of IT for the
8530 initial position. We restore that position in IT when we have
8531 scanned the entire display line without finding a match for
8532 TO_CHARPOS and all the character positions are greater than
8533 TO_CHARPOS. We then restart the scan from the initial position,
8534 and stop at CLOSEST_POS, which is a position > TO_CHARPOS that is
8535 the closest to TO_CHARPOS. */
8538 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8540 SAVE_IT (ppos_it
, *it
, ppos_data
);
8541 closest_pos
= IT_CHARPOS (*it
);
8547 #define BUFFER_POS_REACHED_P() \
8548 ((op & MOVE_TO_POS) != 0 \
8549 && BUFFERP (it->object) \
8550 && (IT_CHARPOS (*it) == to_charpos \
8552 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8553 && IT_CHARPOS (*it) > to_charpos) \
8554 || (it->what == IT_COMPOSITION \
8555 && ((IT_CHARPOS (*it) > to_charpos \
8556 && to_charpos >= it->cmp_it.charpos) \
8557 || (IT_CHARPOS (*it) < to_charpos \
8558 && to_charpos <= it->cmp_it.charpos)))) \
8559 && (it->method == GET_FROM_BUFFER \
8560 || (it->method == GET_FROM_DISPLAY_VECTOR \
8561 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8563 /* If there's a line-/wrap-prefix, handle it. */
8564 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8565 && it
->current_y
< it
->last_visible_y
)
8566 handle_line_prefix (it
);
8568 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8569 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8573 int x
, i
, ascent
= 0, descent
= 0;
8575 /* Utility macro to reset an iterator with x, ascent, and descent. */
8576 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8577 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8578 (IT)->max_descent = descent)
8580 /* Stop if we move beyond TO_CHARPOS (after an image or a
8581 display string or stretch glyph). */
8582 if ((op
& MOVE_TO_POS
) != 0
8583 && BUFFERP (it
->object
)
8584 && it
->method
== GET_FROM_BUFFER
8586 /* When the iterator is at base embedding level, we
8587 are guaranteed that characters are delivered for
8588 display in strictly increasing order of their
8589 buffer positions. */
8590 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8591 && IT_CHARPOS (*it
) > to_charpos
)
8593 && (prev_method
== GET_FROM_IMAGE
8594 || prev_method
== GET_FROM_STRETCH
8595 || prev_method
== GET_FROM_STRING
)
8596 /* Passed TO_CHARPOS from left to right. */
8597 && ((prev_pos
< to_charpos
8598 && IT_CHARPOS (*it
) > to_charpos
)
8599 /* Passed TO_CHARPOS from right to left. */
8600 || (prev_pos
> to_charpos
8601 && IT_CHARPOS (*it
) < to_charpos
)))))
8603 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8605 result
= MOVE_POS_MATCH_OR_ZV
;
8608 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8609 /* If wrap_it is valid, the current position might be in a
8610 word that is wrapped. So, save the iterator in
8611 atpos_it and continue to see if wrapping happens. */
8612 SAVE_IT (atpos_it
, *it
, atpos_data
);
8615 /* Stop when ZV reached.
8616 We used to stop here when TO_CHARPOS reached as well, but that is
8617 too soon if this glyph does not fit on this line. So we handle it
8618 explicitly below. */
8619 if (!get_next_display_element (it
))
8621 result
= MOVE_POS_MATCH_OR_ZV
;
8625 if (it
->line_wrap
== TRUNCATE
)
8627 if (BUFFER_POS_REACHED_P ())
8629 result
= MOVE_POS_MATCH_OR_ZV
;
8635 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
8637 if (IT_DISPLAYING_WHITESPACE (it
))
8641 /* We have reached a glyph that follows one or more
8642 whitespace characters. If the position is
8643 already found, we are done. */
8644 if (atpos_it
.sp
>= 0)
8646 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8647 result
= MOVE_POS_MATCH_OR_ZV
;
8652 RESTORE_IT (it
, &atx_it
, atx_data
);
8653 result
= MOVE_X_REACHED
;
8656 /* Otherwise, we can wrap here. */
8657 SAVE_IT (wrap_it
, *it
, wrap_data
);
8663 /* Remember the line height for the current line, in case
8664 the next element doesn't fit on the line. */
8665 ascent
= it
->max_ascent
;
8666 descent
= it
->max_descent
;
8668 /* The call to produce_glyphs will get the metrics of the
8669 display element IT is loaded with. Record the x-position
8670 before this display element, in case it doesn't fit on the
8674 PRODUCE_GLYPHS (it
);
8676 if (it
->area
!= TEXT_AREA
)
8678 prev_method
= it
->method
;
8679 if (it
->method
== GET_FROM_BUFFER
)
8680 prev_pos
= IT_CHARPOS (*it
);
8681 set_iterator_to_next (it
, true);
8682 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8683 SET_TEXT_POS (this_line_min_pos
,
8684 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8686 && (op
& MOVE_TO_POS
)
8687 && IT_CHARPOS (*it
) > to_charpos
8688 && IT_CHARPOS (*it
) < closest_pos
)
8689 closest_pos
= IT_CHARPOS (*it
);
8693 /* The number of glyphs we get back in IT->nglyphs will normally
8694 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8695 character on a terminal frame, or (iii) a line end. For the
8696 second case, IT->nglyphs - 1 padding glyphs will be present.
8697 (On X frames, there is only one glyph produced for a
8698 composite character.)
8700 The behavior implemented below means, for continuation lines,
8701 that as many spaces of a TAB as fit on the current line are
8702 displayed there. For terminal frames, as many glyphs of a
8703 multi-glyph character are displayed in the current line, too.
8704 This is what the old redisplay code did, and we keep it that
8705 way. Under X, the whole shape of a complex character must
8706 fit on the line or it will be completely displayed in the
8709 Note that both for tabs and padding glyphs, all glyphs have
8713 /* More than one glyph or glyph doesn't fit on line. All
8714 glyphs have the same width. */
8715 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8717 int x_before_this_char
= x
;
8718 int hpos_before_this_char
= it
->hpos
;
8720 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8722 new_x
= x
+ single_glyph_width
;
8724 /* We want to leave anything reaching TO_X to the caller. */
8725 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8727 if (BUFFER_POS_REACHED_P ())
8729 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8730 goto buffer_pos_reached
;
8731 if (atpos_it
.sp
< 0)
8733 SAVE_IT (atpos_it
, *it
, atpos_data
);
8734 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8739 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8742 result
= MOVE_X_REACHED
;
8747 SAVE_IT (atx_it
, *it
, atx_data
);
8748 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8753 if (/* Lines are continued. */
8754 it
->line_wrap
!= TRUNCATE
8755 && (/* And glyph doesn't fit on the line. */
8756 new_x
> it
->last_visible_x
8757 /* Or it fits exactly and we're on a window
8759 || (new_x
== it
->last_visible_x
8760 && FRAME_WINDOW_P (it
->f
)
8761 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8762 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8763 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8765 if (/* IT->hpos == 0 means the very first glyph
8766 doesn't fit on the line, e.g. a wide image. */
8768 || (new_x
== it
->last_visible_x
8769 && FRAME_WINDOW_P (it
->f
)))
8772 it
->current_x
= new_x
;
8774 /* The character's last glyph just barely fits
8776 if (i
== it
->nglyphs
- 1)
8778 /* If this is the destination position,
8779 return a position *before* it in this row,
8780 now that we know it fits in this row. */
8781 if (BUFFER_POS_REACHED_P ())
8783 if (it
->line_wrap
!= WORD_WRAP
8785 /* If we've just found whitespace to
8786 wrap, effectively ignore the
8787 previous wrap point -- it is no
8788 longer relevant, but we won't
8789 have an opportunity to update it,
8790 since we've reached the edge of
8791 this screen line. */
8793 && IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8795 it
->hpos
= hpos_before_this_char
;
8796 it
->current_x
= x_before_this_char
;
8797 result
= MOVE_POS_MATCH_OR_ZV
;
8800 if (it
->line_wrap
== WORD_WRAP
8803 SAVE_IT (atpos_it
, *it
, atpos_data
);
8804 atpos_it
.current_x
= x_before_this_char
;
8805 atpos_it
.hpos
= hpos_before_this_char
;
8809 prev_method
= it
->method
;
8810 if (it
->method
== GET_FROM_BUFFER
)
8811 prev_pos
= IT_CHARPOS (*it
);
8812 set_iterator_to_next (it
, true);
8813 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8814 SET_TEXT_POS (this_line_min_pos
,
8815 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8816 /* On graphical terminals, newlines may
8817 "overflow" into the fringe if
8818 overflow-newline-into-fringe is non-nil.
8819 On text terminals, and on graphical
8820 terminals with no right margin, newlines
8821 may overflow into the last glyph on the
8823 if (!FRAME_WINDOW_P (it
->f
)
8825 && it
->bidi_it
.paragraph_dir
== R2L
)
8826 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8827 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8828 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8830 if (!get_next_display_element (it
))
8832 result
= MOVE_POS_MATCH_OR_ZV
;
8835 if (BUFFER_POS_REACHED_P ())
8837 if (ITERATOR_AT_END_OF_LINE_P (it
))
8838 result
= MOVE_POS_MATCH_OR_ZV
;
8840 result
= MOVE_LINE_CONTINUED
;
8843 if (ITERATOR_AT_END_OF_LINE_P (it
)
8844 && (it
->line_wrap
!= WORD_WRAP
8846 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8848 result
= MOVE_NEWLINE_OR_CR
;
8855 IT_RESET_X_ASCENT_DESCENT (it
);
8857 /* If the screen line ends with whitespace, and we
8858 are under word-wrap, don't use wrap_it: it is no
8859 longer relevant, but we won't have an opportunity
8860 to update it, since we are done with this screen
8862 if (may_wrap
&& IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8864 /* If we've found TO_X, go back there, as we now
8865 know the last word fits on this screen line. */
8866 if ((op
& MOVE_TO_X
) && new_x
== it
->last_visible_x
8869 RESTORE_IT (it
, &atx_it
, atx_data
);
8872 result
= MOVE_X_REACHED
;
8876 else if (wrap_it
.sp
>= 0)
8878 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8883 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8885 result
= MOVE_LINE_CONTINUED
;
8889 if (BUFFER_POS_REACHED_P ())
8891 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8892 goto buffer_pos_reached
;
8893 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8895 SAVE_IT (atpos_it
, *it
, atpos_data
);
8896 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8900 if (new_x
> it
->first_visible_x
)
8902 /* Glyph is visible. Increment number of glyphs that
8903 would be displayed. */
8908 if (result
!= MOVE_UNDEFINED
)
8911 else if (BUFFER_POS_REACHED_P ())
8914 IT_RESET_X_ASCENT_DESCENT (it
);
8915 result
= MOVE_POS_MATCH_OR_ZV
;
8918 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8920 /* Stop when TO_X specified and reached. This check is
8921 necessary here because of lines consisting of a line end,
8922 only. The line end will not produce any glyphs and we
8923 would never get MOVE_X_REACHED. */
8924 eassert (it
->nglyphs
== 0);
8925 result
= MOVE_X_REACHED
;
8929 /* Is this a line end? If yes, we're done. */
8930 if (ITERATOR_AT_END_OF_LINE_P (it
))
8932 /* If we are past TO_CHARPOS, but never saw any character
8933 positions smaller than TO_CHARPOS, return
8934 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8936 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8938 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8940 if (closest_pos
< ZV
)
8942 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8943 /* Don't recurse if closest_pos is equal to
8944 to_charpos, since we have just tried that. */
8945 if (closest_pos
!= to_charpos
)
8946 move_it_in_display_line_to (it
, closest_pos
, -1,
8948 result
= MOVE_POS_MATCH_OR_ZV
;
8951 goto buffer_pos_reached
;
8953 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8954 && IT_CHARPOS (*it
) > to_charpos
)
8955 goto buffer_pos_reached
;
8957 result
= MOVE_NEWLINE_OR_CR
;
8960 result
= MOVE_NEWLINE_OR_CR
;
8964 prev_method
= it
->method
;
8965 if (it
->method
== GET_FROM_BUFFER
)
8966 prev_pos
= IT_CHARPOS (*it
);
8967 /* The current display element has been consumed. Advance
8969 set_iterator_to_next (it
, true);
8970 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8971 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8972 if (IT_CHARPOS (*it
) < to_charpos
)
8973 saw_smaller_pos
= true;
8975 && (op
& MOVE_TO_POS
)
8976 && IT_CHARPOS (*it
) >= to_charpos
8977 && IT_CHARPOS (*it
) < closest_pos
)
8978 closest_pos
= IT_CHARPOS (*it
);
8980 /* Stop if lines are truncated and IT's current x-position is
8981 past the right edge of the window now. */
8982 if (it
->line_wrap
== TRUNCATE
8983 && it
->current_x
>= it
->last_visible_x
)
8985 if (!FRAME_WINDOW_P (it
->f
)
8986 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8987 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8988 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8989 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8991 bool at_eob_p
= false;
8993 if ((at_eob_p
= !get_next_display_element (it
))
8994 || BUFFER_POS_REACHED_P ()
8995 /* If we are past TO_CHARPOS, but never saw any
8996 character positions smaller than TO_CHARPOS,
8997 return MOVE_POS_MATCH_OR_ZV, like the
8998 unidirectional display did. */
8999 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
9001 && IT_CHARPOS (*it
) > to_charpos
))
9004 && !BUFFER_POS_REACHED_P ()
9005 && !at_eob_p
&& closest_pos
< ZV
)
9007 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9008 if (closest_pos
!= to_charpos
)
9009 move_it_in_display_line_to (it
, closest_pos
, -1,
9012 result
= MOVE_POS_MATCH_OR_ZV
;
9015 if (ITERATOR_AT_END_OF_LINE_P (it
))
9017 result
= MOVE_NEWLINE_OR_CR
;
9021 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
9023 && IT_CHARPOS (*it
) > to_charpos
)
9025 if (closest_pos
< ZV
)
9027 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9028 if (closest_pos
!= to_charpos
)
9029 move_it_in_display_line_to (it
, closest_pos
, -1,
9032 result
= MOVE_POS_MATCH_OR_ZV
;
9035 result
= MOVE_LINE_TRUNCATED
;
9038 #undef IT_RESET_X_ASCENT_DESCENT
9041 #undef BUFFER_POS_REACHED_P
9043 /* If we scanned beyond to_pos and didn't find a point to wrap at,
9044 restore the saved iterator. */
9045 if (atpos_it
.sp
>= 0)
9046 RESTORE_IT (it
, &atpos_it
, atpos_data
);
9047 else if (atx_it
.sp
>= 0)
9048 RESTORE_IT (it
, &atx_it
, atx_data
);
9053 bidi_unshelve_cache (atpos_data
, true);
9055 bidi_unshelve_cache (atx_data
, true);
9057 bidi_unshelve_cache (wrap_data
, true);
9059 bidi_unshelve_cache (ppos_data
, true);
9061 /* Restore the iterator settings altered at the beginning of this
9063 it
->glyph_row
= saved_glyph_row
;
9067 /* For external use. */
9069 move_it_in_display_line (struct it
*it
,
9070 ptrdiff_t to_charpos
, int to_x
,
9071 enum move_operation_enum op
)
9073 if (it
->line_wrap
== WORD_WRAP
9074 && (op
& MOVE_TO_X
))
9077 void *save_data
= NULL
;
9080 SAVE_IT (save_it
, *it
, save_data
);
9081 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9082 /* When word-wrap is on, TO_X may lie past the end
9083 of a wrapped line. Then it->current is the
9084 character on the next line, so backtrack to the
9085 space before the wrap point. */
9086 if (skip
== MOVE_LINE_CONTINUED
)
9088 int prev_x
= max (it
->current_x
- 1, 0);
9089 RESTORE_IT (it
, &save_it
, save_data
);
9090 move_it_in_display_line_to
9091 (it
, -1, prev_x
, MOVE_TO_X
);
9094 bidi_unshelve_cache (save_data
, true);
9097 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9101 /* Move IT forward until it satisfies one or more of the criteria in
9102 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
9104 OP is a bit-mask that specifies where to stop, and in particular,
9105 which of those four position arguments makes a difference. See the
9106 description of enum move_operation_enum.
9108 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
9109 screen line, this function will set IT to the next position that is
9110 displayed to the right of TO_CHARPOS on the screen.
9112 Return the maximum pixel length of any line scanned but never more
9113 than it.last_visible_x. */
9116 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
9118 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
9119 int line_height
, line_start_x
= 0, reached
= 0;
9120 int max_current_x
= 0;
9121 void *backup_data
= NULL
;
9125 if (op
& MOVE_TO_VPOS
)
9127 /* If no TO_CHARPOS and no TO_X specified, stop at the
9128 start of the line TO_VPOS. */
9129 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
9131 if (it
->vpos
== to_vpos
)
9137 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
9141 /* TO_VPOS >= 0 means stop at TO_X in the line at
9142 TO_VPOS, or at TO_POS, whichever comes first. */
9143 if (it
->vpos
== to_vpos
)
9149 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9151 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
9156 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
9158 /* We have reached TO_X but not in the line we want. */
9159 skip
= move_it_in_display_line_to (it
, to_charpos
,
9161 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9169 else if (op
& MOVE_TO_Y
)
9171 struct it it_backup
;
9173 if (it
->line_wrap
== WORD_WRAP
)
9174 SAVE_IT (it_backup
, *it
, backup_data
);
9176 /* TO_Y specified means stop at TO_X in the line containing
9177 TO_Y---or at TO_CHARPOS if this is reached first. The
9178 problem is that we can't really tell whether the line
9179 contains TO_Y before we have completely scanned it, and
9180 this may skip past TO_X. What we do is to first scan to
9183 If TO_X is not specified, use a TO_X of zero. The reason
9184 is to make the outcome of this function more predictable.
9185 If we didn't use TO_X == 0, we would stop at the end of
9186 the line which is probably not what a caller would expect
9188 skip
= move_it_in_display_line_to
9189 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
9190 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
9192 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
9193 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9195 else if (skip
== MOVE_X_REACHED
)
9197 /* If TO_X was reached, we want to know whether TO_Y is
9198 in the line. We know this is the case if the already
9199 scanned glyphs make the line tall enough. Otherwise,
9200 we must check by scanning the rest of the line. */
9201 line_height
= it
->max_ascent
+ it
->max_descent
;
9202 if (to_y
>= it
->current_y
9203 && to_y
< it
->current_y
+ line_height
)
9208 SAVE_IT (it_backup
, *it
, backup_data
);
9209 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
9210 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
9212 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
9213 line_height
= it
->max_ascent
+ it
->max_descent
;
9214 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9216 if (to_y
>= it
->current_y
9217 && to_y
< it
->current_y
+ line_height
)
9219 /* If TO_Y is in this line and TO_X was reached
9220 above, we scanned too far. We have to restore
9221 IT's settings to the ones before skipping. But
9222 keep the more accurate values of max_ascent and
9223 max_descent we've found while skipping the rest
9224 of the line, for the sake of callers, such as
9225 pos_visible_p, that need to know the line
9227 int max_ascent
= it
->max_ascent
;
9228 int max_descent
= it
->max_descent
;
9230 RESTORE_IT (it
, &it_backup
, backup_data
);
9231 it
->max_ascent
= max_ascent
;
9232 it
->max_descent
= max_descent
;
9238 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9244 /* Check whether TO_Y is in this line. */
9245 line_height
= it
->max_ascent
+ it
->max_descent
;
9246 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9248 if (to_y
>= it
->current_y
9249 && to_y
< it
->current_y
+ line_height
)
9251 if (to_y
> it
->current_y
)
9252 max_current_x
= max (it
->current_x
, max_current_x
);
9254 /* When word-wrap is on, TO_X may lie past the end
9255 of a wrapped line. Then it->current is the
9256 character on the next line, so backtrack to the
9257 space before the wrap point. */
9258 if (skip
== MOVE_LINE_CONTINUED
9259 && it
->line_wrap
== WORD_WRAP
)
9261 int prev_x
= max (it
->current_x
- 1, 0);
9262 RESTORE_IT (it
, &it_backup
, backup_data
);
9263 skip
= move_it_in_display_line_to
9264 (it
, -1, prev_x
, MOVE_TO_X
);
9273 max_current_x
= max (it
->current_x
, max_current_x
);
9277 else if (BUFFERP (it
->object
)
9278 && (it
->method
== GET_FROM_BUFFER
9279 || it
->method
== GET_FROM_STRETCH
)
9280 && IT_CHARPOS (*it
) >= to_charpos
9281 /* Under bidi iteration, a call to set_iterator_to_next
9282 can scan far beyond to_charpos if the initial
9283 portion of the next line needs to be reordered. In
9284 that case, give move_it_in_display_line_to another
9287 && it
->bidi_it
.scan_dir
== -1))
9288 skip
= MOVE_POS_MATCH_OR_ZV
;
9290 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9294 case MOVE_POS_MATCH_OR_ZV
:
9295 max_current_x
= max (it
->current_x
, max_current_x
);
9299 case MOVE_NEWLINE_OR_CR
:
9300 max_current_x
= max (it
->current_x
, max_current_x
);
9301 set_iterator_to_next (it
, true);
9302 it
->continuation_lines_width
= 0;
9305 case MOVE_LINE_TRUNCATED
:
9306 max_current_x
= it
->last_visible_x
;
9307 it
->continuation_lines_width
= 0;
9308 reseat_at_next_visible_line_start (it
, false);
9309 if ((op
& MOVE_TO_POS
) != 0
9310 && IT_CHARPOS (*it
) > to_charpos
)
9317 case MOVE_LINE_CONTINUED
:
9318 max_current_x
= it
->last_visible_x
;
9319 /* For continued lines ending in a tab, some of the glyphs
9320 associated with the tab are displayed on the current
9321 line. Since it->current_x does not include these glyphs,
9322 we use it->last_visible_x instead. */
9325 it
->continuation_lines_width
+= it
->last_visible_x
;
9326 /* When moving by vpos, ensure that the iterator really
9327 advances to the next line (bug#847, bug#969). Fixme:
9328 do we need to do this in other circumstances? */
9329 if (it
->current_x
!= it
->last_visible_x
9330 && (op
& MOVE_TO_VPOS
)
9331 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9333 line_start_x
= it
->current_x
+ it
->pixel_width
9334 - it
->last_visible_x
;
9335 if (FRAME_WINDOW_P (it
->f
))
9337 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
9338 struct font
*face_font
= face
->font
;
9340 /* When display_line produces a continued line
9341 that ends in a TAB, it skips a tab stop that
9342 is closer than the font's space character
9343 width (see x_produce_glyphs where it produces
9344 the stretch glyph which represents a TAB).
9345 We need to reproduce the same logic here. */
9346 eassert (face_font
);
9349 if (line_start_x
< face_font
->space_width
)
9351 += it
->tab_width
* face_font
->space_width
;
9354 set_iterator_to_next (it
, false);
9358 it
->continuation_lines_width
+= it
->current_x
;
9365 /* Reset/increment for the next run. */
9366 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9367 it
->current_x
= line_start_x
;
9370 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9372 last_height
= it
->max_ascent
+ it
->max_descent
;
9373 it
->max_ascent
= it
->max_descent
= 0;
9378 /* On text terminals, we may stop at the end of a line in the middle
9379 of a multi-character glyph. If the glyph itself is continued,
9380 i.e. it is actually displayed on the next line, don't treat this
9381 stopping point as valid; move to the next line instead (unless
9382 that brings us offscreen). */
9383 if (!FRAME_WINDOW_P (it
->f
)
9385 && IT_CHARPOS (*it
) == to_charpos
9386 && it
->what
== IT_CHARACTER
9388 && it
->line_wrap
== WINDOW_WRAP
9389 && it
->current_x
== it
->last_visible_x
- 1
9392 && it
->w
->window_end_valid
9393 && it
->vpos
< it
->w
->window_end_vpos
)
9395 it
->continuation_lines_width
+= it
->current_x
;
9396 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9397 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9399 last_height
= it
->max_ascent
+ it
->max_descent
;
9403 bidi_unshelve_cache (backup_data
, true);
9405 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9407 return max_current_x
;
9411 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9413 If DY > 0, move IT backward at least that many pixels. DY = 0
9414 means move IT backward to the preceding line start or BEGV. This
9415 function may move over more than DY pixels if IT->current_y - DY
9416 ends up in the middle of a line; in this case IT->current_y will be
9417 set to the top of the line moved to. */
9420 move_it_vertically_backward (struct it
*it
, int dy
)
9424 void *it2data
= NULL
, *it3data
= NULL
;
9425 ptrdiff_t start_pos
;
9427 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9428 ptrdiff_t pos_limit
;
9433 start_pos
= IT_CHARPOS (*it
);
9435 /* Estimate how many newlines we must move back. */
9436 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9437 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9440 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9442 /* Set the iterator's position that many lines back. But don't go
9443 back more than NLINES full screen lines -- this wins a day with
9444 buffers which have very long lines. */
9445 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9446 back_to_previous_visible_line_start (it
);
9448 /* Reseat the iterator here. When moving backward, we don't want
9449 reseat to skip forward over invisible text, set up the iterator
9450 to deliver from overlay strings at the new position etc. So,
9451 use reseat_1 here. */
9452 reseat_1 (it
, it
->current
.pos
, true);
9454 /* We are now surely at a line start. */
9455 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9456 reordering is in effect. */
9457 it
->continuation_lines_width
= 0;
9459 /* Move forward and see what y-distance we moved. First move to the
9460 start of the next line so that we get its height. We need this
9461 height to be able to tell whether we reached the specified
9463 SAVE_IT (it2
, *it
, it2data
);
9464 it2
.max_ascent
= it2
.max_descent
= 0;
9467 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9468 MOVE_TO_POS
| MOVE_TO_VPOS
);
9470 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9471 /* If we are in a display string which starts at START_POS,
9472 and that display string includes a newline, and we are
9473 right after that newline (i.e. at the beginning of a
9474 display line), exit the loop, because otherwise we will
9475 infloop, since move_it_to will see that it is already at
9476 START_POS and will not move. */
9477 || (it2
.method
== GET_FROM_STRING
9478 && IT_CHARPOS (it2
) == start_pos
9479 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9480 eassert (IT_CHARPOS (*it
) >= BEGV
);
9481 SAVE_IT (it3
, it2
, it3data
);
9483 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9484 eassert (IT_CHARPOS (*it
) >= BEGV
);
9485 /* H is the actual vertical distance from the position in *IT
9486 and the starting position. */
9487 h
= it2
.current_y
- it
->current_y
;
9488 /* NLINES is the distance in number of lines. */
9489 nlines
= it2
.vpos
- it
->vpos
;
9491 /* Correct IT's y and vpos position
9492 so that they are relative to the starting point. */
9498 /* DY == 0 means move to the start of the screen line. The
9499 value of nlines is > 0 if continuation lines were involved,
9500 or if the original IT position was at start of a line. */
9501 RESTORE_IT (it
, it
, it2data
);
9503 move_it_by_lines (it
, nlines
);
9504 /* The above code moves us to some position NLINES down,
9505 usually to its first glyph (leftmost in an L2R line), but
9506 that's not necessarily the start of the line, under bidi
9507 reordering. We want to get to the character position
9508 that is immediately after the newline of the previous
9511 && !it
->continuation_lines_width
9512 && !STRINGP (it
->string
)
9513 && IT_CHARPOS (*it
) > BEGV
9514 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9516 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9519 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9520 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9522 bidi_unshelve_cache (it3data
, true);
9526 /* The y-position we try to reach, relative to *IT.
9527 Note that H has been subtracted in front of the if-statement. */
9528 int target_y
= it
->current_y
+ h
- dy
;
9529 int y0
= it3
.current_y
;
9533 RESTORE_IT (&it3
, &it3
, it3data
);
9534 y1
= line_bottom_y (&it3
);
9535 line_height
= y1
- y0
;
9536 RESTORE_IT (it
, it
, it2data
);
9537 /* If we did not reach target_y, try to move further backward if
9538 we can. If we moved too far backward, try to move forward. */
9539 if (target_y
< it
->current_y
9540 /* This is heuristic. In a window that's 3 lines high, with
9541 a line height of 13 pixels each, recentering with point
9542 on the bottom line will try to move -39/2 = 19 pixels
9543 backward. Try to avoid moving into the first line. */
9544 && (it
->current_y
- target_y
9545 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9546 && IT_CHARPOS (*it
) > BEGV
)
9548 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9549 target_y
- it
->current_y
));
9550 dy
= it
->current_y
- target_y
;
9551 goto move_further_back
;
9553 else if (target_y
>= it
->current_y
+ line_height
9554 && IT_CHARPOS (*it
) < ZV
)
9556 /* Should move forward by at least one line, maybe more.
9558 Note: Calling move_it_by_lines can be expensive on
9559 terminal frames, where compute_motion is used (via
9560 vmotion) to do the job, when there are very long lines
9561 and truncate-lines is nil. That's the reason for
9562 treating terminal frames specially here. */
9564 if (!FRAME_WINDOW_P (it
->f
))
9565 move_it_vertically (it
, target_y
- it
->current_y
);
9570 move_it_by_lines (it
, 1);
9572 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9579 /* Move IT by a specified amount of pixel lines DY. DY negative means
9580 move backwards. DY = 0 means move to start of screen line. At the
9581 end, IT will be on the start of a screen line. */
9584 move_it_vertically (struct it
*it
, int dy
)
9587 move_it_vertically_backward (it
, -dy
);
9590 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9591 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9592 MOVE_TO_POS
| MOVE_TO_Y
);
9593 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9595 /* If buffer ends in ZV without a newline, move to the start of
9596 the line to satisfy the post-condition. */
9597 if (IT_CHARPOS (*it
) == ZV
9599 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9600 move_it_by_lines (it
, 0);
9605 /* Move iterator IT past the end of the text line it is in. */
9608 move_it_past_eol (struct it
*it
)
9610 enum move_it_result rc
;
9612 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9613 if (rc
== MOVE_NEWLINE_OR_CR
)
9614 set_iterator_to_next (it
, false);
9618 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9619 negative means move up. DVPOS == 0 means move to the start of the
9622 Optimization idea: If we would know that IT->f doesn't use
9623 a face with proportional font, we could be faster for
9624 truncate-lines nil. */
9627 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9630 /* The commented-out optimization uses vmotion on terminals. This
9631 gives bad results, because elements like it->what, on which
9632 callers such as pos_visible_p rely, aren't updated. */
9633 /* struct position pos;
9634 if (!FRAME_WINDOW_P (it->f))
9636 struct text_pos textpos;
9638 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9639 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9640 reseat (it, textpos, true);
9641 it->vpos += pos.vpos;
9642 it->current_y += pos.vpos;
9648 /* DVPOS == 0 means move to the start of the screen line. */
9649 move_it_vertically_backward (it
, 0);
9650 /* Let next call to line_bottom_y calculate real line height. */
9655 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9656 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9658 /* Only move to the next buffer position if we ended up in a
9659 string from display property, not in an overlay string
9660 (before-string or after-string). That is because the
9661 latter don't conceal the underlying buffer position, so
9662 we can ask to move the iterator to the exact position we
9663 are interested in. Note that, even if we are already at
9664 IT_CHARPOS (*it), the call below is not a no-op, as it
9665 will detect that we are at the end of the string, pop the
9666 iterator, and compute it->current_x and it->hpos
9668 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9669 -1, -1, -1, MOVE_TO_POS
);
9675 void *it2data
= NULL
;
9676 ptrdiff_t start_charpos
, i
;
9678 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9679 bool hit_pos_limit
= false;
9680 ptrdiff_t pos_limit
;
9682 /* Start at the beginning of the screen line containing IT's
9683 position. This may actually move vertically backwards,
9684 in case of overlays, so adjust dvpos accordingly. */
9686 move_it_vertically_backward (it
, 0);
9689 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9690 screen lines, and reseat the iterator there. */
9691 start_charpos
= IT_CHARPOS (*it
);
9692 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9695 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9697 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9698 back_to_previous_visible_line_start (it
);
9699 if (i
> 0 && IT_CHARPOS (*it
) <= pos_limit
)
9700 hit_pos_limit
= true;
9701 reseat (it
, it
->current
.pos
, true);
9703 /* Move further back if we end up in a string or an image. */
9704 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9706 /* First try to move to start of display line. */
9708 move_it_vertically_backward (it
, 0);
9710 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9712 /* If start of line is still in string or image,
9713 move further back. */
9714 back_to_previous_visible_line_start (it
);
9715 reseat (it
, it
->current
.pos
, true);
9719 it
->current_x
= it
->hpos
= 0;
9721 /* Above call may have moved too far if continuation lines
9722 are involved. Scan forward and see if it did. */
9723 SAVE_IT (it2
, *it
, it2data
);
9724 it2
.vpos
= it2
.current_y
= 0;
9725 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9726 it
->vpos
-= it2
.vpos
;
9727 it
->current_y
-= it2
.current_y
;
9728 it
->current_x
= it
->hpos
= 0;
9730 /* If we moved too far back, move IT some lines forward. */
9731 if (it2
.vpos
> -dvpos
)
9733 int delta
= it2
.vpos
+ dvpos
;
9735 RESTORE_IT (&it2
, &it2
, it2data
);
9736 SAVE_IT (it2
, *it
, it2data
);
9737 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9738 /* Move back again if we got too far ahead. */
9739 if (IT_CHARPOS (*it
) >= start_charpos
)
9740 RESTORE_IT (it
, &it2
, it2data
);
9742 bidi_unshelve_cache (it2data
, true);
9744 else if (hit_pos_limit
&& pos_limit
> BEGV
9745 && dvpos
< 0 && it2
.vpos
< -dvpos
)
9747 /* If we hit the limit, but still didn't make it far enough
9748 back, that means there's a display string with a newline
9749 covering a large chunk of text, and that caused
9750 back_to_previous_visible_line_start try to go too far.
9751 Punish those who commit such atrocities by going back
9752 until we've reached DVPOS, after lifting the limit, which
9753 could make it slow for very long lines. "If it hurts,
9756 RESTORE_IT (it
, it
, it2data
);
9757 for (i
= -dvpos
; i
> 0; --i
)
9759 back_to_previous_visible_line_start (it
);
9762 reseat_1 (it
, it
->current
.pos
, true);
9765 RESTORE_IT (it
, it
, it2data
);
9769 /* Return true if IT points into the middle of a display vector. */
9772 in_display_vector_p (struct it
*it
)
9774 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9775 && it
->current
.dpvec_index
> 0
9776 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9779 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9780 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9781 WINDOW must be a live window and defaults to the selected one. The
9782 return value is a cons of the maximum pixel-width of any text line and
9783 the maximum pixel-height of all text lines.
9785 The optional argument FROM, if non-nil, specifies the first text
9786 position and defaults to the minimum accessible position of the buffer.
9787 If FROM is t, use the minimum accessible position that is not a newline
9788 character. TO, if non-nil, specifies the last text position and
9789 defaults to the maximum accessible position of the buffer. If TO is t,
9790 use the maximum accessible position that is not a newline character.
9792 The optional argument X-LIMIT, if non-nil, specifies the maximum text
9793 width that can be returned. X-LIMIT nil or omitted, means to use the
9794 pixel-width of WINDOW's body; use this if you do not intend to change
9795 the width of WINDOW. Use the maximum width WINDOW may assume if you
9796 intend to change WINDOW's width. In any case, text whose x-coordinate
9797 is beyond X-LIMIT is ignored. Since calculating the width of long lines
9798 can take some time, it's always a good idea to make this argument as
9799 small as possible; in particular, if the buffer contains long lines that
9800 shall be truncated anyway.
9802 The optional argument Y-LIMIT, if non-nil, specifies the maximum text
9803 height that can be returned. Text lines whose y-coordinate is beyond
9804 Y-LIMIT are ignored. Since calculating the text height of a large
9805 buffer can take some time, it makes sense to specify this argument if
9806 the size of the buffer is unknown.
9808 Optional argument MODE-AND-HEADER-LINE nil or omitted means do not
9809 include the height of the mode- or header-line of WINDOW in the return
9810 value. If it is either the symbol `mode-line' or `header-line', include
9811 only the height of that line, if present, in the return value. If t,
9812 include the height of both, if present, in the return value. */)
9813 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
,
9814 Lisp_Object y_limit
, Lisp_Object mode_and_header_line
)
9816 struct window
*w
= decode_live_window (window
);
9817 Lisp_Object buffer
= w
->contents
;
9820 struct buffer
*old_b
= NULL
;
9821 ptrdiff_t start
, end
, pos
;
9822 struct text_pos startp
;
9823 void *itdata
= NULL
;
9824 int c
, max_y
= -1, x
= 0, y
= 0;
9826 CHECK_BUFFER (buffer
);
9827 b
= XBUFFER (buffer
);
9829 if (b
!= current_buffer
)
9831 old_b
= current_buffer
;
9832 set_buffer_internal (b
);
9837 else if (EQ (from
, Qt
))
9840 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9841 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9843 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9848 CHECK_NUMBER_COERCE_MARKER (from
);
9849 start
= min (max (XINT (from
), BEGV
), ZV
);
9854 else if (EQ (to
, Qt
))
9857 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9858 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9860 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9865 CHECK_NUMBER_COERCE_MARKER (to
);
9866 end
= max (start
, min (XINT (to
), ZV
));
9869 if (!NILP (y_limit
))
9871 CHECK_NUMBER (y_limit
);
9872 max_y
= min (XINT (y_limit
), INT_MAX
);
9875 itdata
= bidi_shelve_cache ();
9876 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9877 start_display (&it
, w
, startp
);
9880 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9883 CHECK_NUMBER (x_limit
);
9884 it
.last_visible_x
= min (XINT (x_limit
), INFINITY
);
9885 /* Actually, we never want move_it_to stop at to_x. But to make
9886 sure that move_it_in_display_line_to always moves far enough,
9887 we set it to INT_MAX and specify MOVE_TO_X. */
9888 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9889 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9892 y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9894 if (!EQ (mode_and_header_line
, Qheader_line
)
9895 && !EQ (mode_and_header_line
, Qt
))
9896 /* Do not count the header-line which was counted automatically by
9898 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9900 if (EQ (mode_and_header_line
, Qmode_line
)
9901 || EQ (mode_and_header_line
, Qt
))
9902 /* Do count the mode-line which is not included automatically by
9904 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9906 bidi_unshelve_cache (itdata
, false);
9909 set_buffer_internal (old_b
);
9911 return Fcons (make_number (x
), make_number (y
));
9914 /***********************************************************************
9916 ***********************************************************************/
9918 /* Return the number of arguments the format string FORMAT needs. */
9921 format_nargs (char const *format
)
9923 ptrdiff_t nargs
= 0;
9924 for (char const *p
= format
; (p
= strchr (p
, '%')); p
++)
9932 /* Add a message with format string FORMAT and formatted arguments
9936 add_to_log (const char *format
, ...)
9939 va_start (ap
, format
);
9940 vadd_to_log (format
, ap
);
9945 vadd_to_log (char const *format
, va_list ap
)
9947 ptrdiff_t form_nargs
= format_nargs (format
);
9948 ptrdiff_t nargs
= 1 + form_nargs
;
9949 Lisp_Object args
[10];
9950 eassert (nargs
<= ARRAYELTS (args
));
9951 AUTO_STRING (args0
, format
);
9953 for (ptrdiff_t i
= 1; i
<= nargs
; i
++)
9954 args
[i
] = va_arg (ap
, Lisp_Object
);
9955 Lisp_Object msg
= Qnil
;
9956 msg
= Fformat_message (nargs
, args
);
9958 ptrdiff_t len
= SBYTES (msg
) + 1;
9960 char *buffer
= SAFE_ALLOCA (len
);
9961 memcpy (buffer
, SDATA (msg
), len
);
9963 message_dolog (buffer
, len
- 1, true, STRING_MULTIBYTE (msg
));
9968 /* Output a newline in the *Messages* buffer if "needs" one. */
9971 message_log_maybe_newline (void)
9973 if (message_log_need_newline
)
9974 message_dolog ("", 0, true, false);
9978 /* Add a string M of length NBYTES to the message log, optionally
9979 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9980 true, means interpret the contents of M as multibyte. This
9981 function calls low-level routines in order to bypass text property
9982 hooks, etc. which might not be safe to run.
9984 This may GC (insert may run before/after change hooks),
9985 so the buffer M must NOT point to a Lisp string. */
9988 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9990 const unsigned char *msg
= (const unsigned char *) m
;
9992 if (!NILP (Vmemory_full
))
9995 if (!NILP (Vmessage_log_max
))
9997 struct buffer
*oldbuf
;
9998 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9999 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
10000 ptrdiff_t point_at_end
= 0;
10001 ptrdiff_t zv_at_end
= 0;
10002 Lisp_Object old_deactivate_mark
;
10004 old_deactivate_mark
= Vdeactivate_mark
;
10005 oldbuf
= current_buffer
;
10007 /* Ensure the Messages buffer exists, and switch to it.
10008 If we created it, set the major-mode. */
10009 bool newbuffer
= NILP (Fget_buffer (Vmessages_buffer_name
));
10010 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
10012 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
10013 call0 (intern ("messages-buffer-mode"));
10015 bset_undo_list (current_buffer
, Qt
);
10016 bset_cache_long_scans (current_buffer
, Qnil
);
10018 oldpoint
= message_dolog_marker1
;
10019 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
10020 oldbegv
= message_dolog_marker2
;
10021 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
10022 oldzv
= message_dolog_marker3
;
10023 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
10031 BEGV_BYTE
= BEG_BYTE
;
10034 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10036 /* Insert the string--maybe converting multibyte to single byte
10037 or vice versa, so that all the text fits the buffer. */
10039 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10045 /* Convert a multibyte string to single-byte
10046 for the *Message* buffer. */
10047 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
10049 c
= string_char_and_length (msg
+ i
, &char_bytes
);
10050 work
[0] = CHAR_TO_BYTE8 (c
);
10051 insert_1_both (work
, 1, 1, true, false, false);
10054 else if (! multibyte
10055 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10059 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10060 /* Convert a single-byte string to multibyte
10061 for the *Message* buffer. */
10062 for (i
= 0; i
< nbytes
; i
++)
10065 MAKE_CHAR_MULTIBYTE (c
);
10066 char_bytes
= CHAR_STRING (c
, str
);
10067 insert_1_both ((char *) str
, 1, char_bytes
, true, false, false);
10071 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
,
10072 true, false, false);
10076 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
10079 insert_1_both ("\n", 1, 1, true, false, false);
10081 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, false);
10083 this_bol_byte
= PT_BYTE
;
10085 /* See if this line duplicates the previous one.
10086 If so, combine duplicates. */
10087 if (this_bol
> BEG
)
10089 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, false);
10091 prev_bol_byte
= PT_BYTE
;
10093 dups
= message_log_check_duplicate (prev_bol_byte
,
10097 del_range_both (prev_bol
, prev_bol_byte
,
10098 this_bol
, this_bol_byte
, false);
10101 char dupstr
[sizeof " [ times]"
10102 + INT_STRLEN_BOUND (printmax_t
)];
10104 /* If you change this format, don't forget to also
10105 change message_log_check_duplicate. */
10106 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
10107 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
10108 insert_1_both (dupstr
, duplen
, duplen
,
10109 true, false, true);
10114 /* If we have more than the desired maximum number of lines
10115 in the *Messages* buffer now, delete the oldest ones.
10116 This is safe because we don't have undo in this buffer. */
10118 if (NATNUMP (Vmessage_log_max
))
10120 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
10121 -XFASTINT (Vmessage_log_max
) - 1, false);
10122 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, false);
10125 BEGV
= marker_position (oldbegv
);
10126 BEGV_BYTE
= marker_byte_position (oldbegv
);
10135 ZV
= marker_position (oldzv
);
10136 ZV_BYTE
= marker_byte_position (oldzv
);
10140 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10142 /* We can't do Fgoto_char (oldpoint) because it will run some
10144 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
10145 marker_byte_position (oldpoint
));
10147 unchain_marker (XMARKER (oldpoint
));
10148 unchain_marker (XMARKER (oldbegv
));
10149 unchain_marker (XMARKER (oldzv
));
10151 /* We called insert_1_both above with its 5th argument (PREPARE)
10152 false, which prevents insert_1_both from calling
10153 prepare_to_modify_buffer, which in turns prevents us from
10154 incrementing windows_or_buffers_changed even if *Messages* is
10155 shown in some window. So we must manually set
10156 windows_or_buffers_changed here to make up for that. */
10157 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
10158 bset_redisplay (current_buffer
);
10160 set_buffer_internal (oldbuf
);
10162 message_log_need_newline
= !nlflag
;
10163 Vdeactivate_mark
= old_deactivate_mark
;
10168 /* We are at the end of the buffer after just having inserted a newline.
10169 (Note: We depend on the fact we won't be crossing the gap.)
10170 Check to see if the most recent message looks a lot like the previous one.
10171 Return 0 if different, 1 if the new one should just replace it, or a
10172 value N > 1 if we should also append " [N times]". */
10175 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
10178 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
10179 bool seen_dots
= false;
10180 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
10181 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
10183 for (i
= 0; i
< len
; i
++)
10185 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
10187 if (p1
[i
] != p2
[i
])
10193 if (*p1
++ == ' ' && *p1
++ == '[')
10196 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
10197 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
10204 /* Display an echo area message M with a specified length of NBYTES
10205 bytes. The string may include null characters. If M is not a
10206 string, clear out any existing message, and let the mini-buffer
10209 This function cancels echoing. */
10212 message3 (Lisp_Object m
)
10214 clear_message (true, true);
10217 /* First flush out any partial line written with print. */
10218 message_log_maybe_newline ();
10221 ptrdiff_t nbytes
= SBYTES (m
);
10222 bool multibyte
= STRING_MULTIBYTE (m
);
10225 SAFE_ALLOCA_STRING (buffer
, m
);
10226 message_dolog (buffer
, nbytes
, true, multibyte
);
10229 if (! inhibit_message
)
10230 message3_nolog (m
);
10233 /* Log the message M to stderr. Log an empty line if M is not a string. */
10236 message_to_stderr (Lisp_Object m
)
10238 if (noninteractive_need_newline
)
10240 noninteractive_need_newline
= false;
10241 fputc ('\n', stderr
);
10245 Lisp_Object coding_system
= Vlocale_coding_system
;
10248 if (!NILP (Vcoding_system_for_write
))
10249 coding_system
= Vcoding_system_for_write
;
10250 if (!NILP (coding_system
))
10251 s
= code_convert_string_norecord (m
, coding_system
, true);
10255 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
10257 if (!cursor_in_echo_area
)
10258 fputc ('\n', stderr
);
10262 /* The non-logging version of message3.
10263 This does not cancel echoing, because it is used for echoing.
10264 Perhaps we need to make a separate function for echoing
10265 and make this cancel echoing. */
10268 message3_nolog (Lisp_Object m
)
10270 struct frame
*sf
= SELECTED_FRAME ();
10272 if (FRAME_INITIAL_P (sf
))
10273 message_to_stderr (m
);
10274 /* Error messages get reported properly by cmd_error, so this must be just an
10275 informative message; if the frame hasn't really been initialized yet, just
10277 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
10279 /* Get the frame containing the mini-buffer
10280 that the selected frame is using. */
10281 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10282 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
10283 struct frame
*f
= XFRAME (frame
);
10285 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
10286 Fmake_frame_visible (frame
);
10288 if (STRINGP (m
) && SCHARS (m
) > 0)
10291 if (minibuffer_auto_raise
)
10292 Fraise_frame (frame
);
10293 /* Assume we are not echoing.
10294 (If we are, echo_now will override this.) */
10295 echo_message_buffer
= Qnil
;
10298 clear_message (true, true);
10300 do_pending_window_change (false);
10301 echo_area_display (true);
10302 do_pending_window_change (false);
10303 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
10304 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
10309 /* Display a null-terminated echo area message M. If M is 0, clear
10310 out any existing message, and let the mini-buffer text show through.
10312 The buffer M must continue to exist until after the echo area gets
10313 cleared or some other message gets displayed there. Do not pass
10314 text that is stored in a Lisp string. Do not pass text in a buffer
10315 that was alloca'd. */
10318 message1 (const char *m
)
10320 message3 (m
? build_unibyte_string (m
) : Qnil
);
10324 /* The non-logging counterpart of message1. */
10327 message1_nolog (const char *m
)
10329 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10332 /* Display a message M which contains a single %s
10333 which gets replaced with STRING. */
10336 message_with_string (const char *m
, Lisp_Object string
, bool log
)
10338 CHECK_STRING (string
);
10341 if (noninteractive
)
10342 need_message
= !!m
;
10343 else if (!INTERACTIVE
)
10344 need_message
= false;
10347 /* The frame whose minibuffer we're going to display the message on.
10348 It may be larger than the selected frame, so we need
10349 to use its buffer, not the selected frame's buffer. */
10350 Lisp_Object mini_window
;
10351 struct frame
*f
, *sf
= SELECTED_FRAME ();
10353 /* Get the frame containing the minibuffer
10354 that the selected frame is using. */
10355 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10356 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10358 /* Error messages get reported properly by cmd_error, so this must be
10359 just an informative message; if the frame hasn't really been
10360 initialized yet, just toss it. */
10361 need_message
= f
->glyphs_initialized_p
;
10366 AUTO_STRING (fmt
, m
);
10367 Lisp_Object msg
= CALLN (Fformat_message
, fmt
, string
);
10369 if (noninteractive
)
10370 message_to_stderr (msg
);
10376 message3_nolog (msg
);
10378 /* Print should start at the beginning of the message
10379 buffer next time. */
10380 message_buf_print
= false;
10386 /* Dump an informative message to the minibuf. If M is 0, clear out
10387 any existing message, and let the mini-buffer text show through.
10389 The message must be safe ASCII and the format must not contain ` or
10390 '. If your message and format do not fit into this category,
10391 convert your arguments to Lisp objects and use Fmessage instead. */
10393 static void ATTRIBUTE_FORMAT_PRINTF (1, 0)
10394 vmessage (const char *m
, va_list ap
)
10396 if (noninteractive
)
10400 if (noninteractive_need_newline
)
10401 putc ('\n', stderr
);
10402 noninteractive_need_newline
= false;
10403 vfprintf (stderr
, m
, ap
);
10404 if (!cursor_in_echo_area
)
10405 fprintf (stderr
, "\n");
10409 else if (INTERACTIVE
)
10411 /* The frame whose mini-buffer we're going to display the message
10412 on. It may be larger than the selected frame, so we need to
10413 use its buffer, not the selected frame's buffer. */
10414 Lisp_Object mini_window
;
10415 struct frame
*f
, *sf
= SELECTED_FRAME ();
10417 /* Get the frame containing the mini-buffer
10418 that the selected frame is using. */
10419 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10420 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10422 /* Error messages get reported properly by cmd_error, so this must be
10423 just an informative message; if the frame hasn't really been
10424 initialized yet, just toss it. */
10425 if (f
->glyphs_initialized_p
)
10430 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10432 char *message_buf
= SAFE_ALLOCA (maxsize
+ 1);
10434 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10436 message3 (make_string (message_buf
, len
));
10442 /* Print should start at the beginning of the message
10443 buffer next time. */
10444 message_buf_print
= false;
10450 message (const char *m
, ...)
10459 /* Display the current message in the current mini-buffer. This is
10460 only called from error handlers in process.c, and is not time
10464 update_echo_area (void)
10466 if (!NILP (echo_area_buffer
[0]))
10468 Lisp_Object string
;
10469 string
= Fcurrent_message ();
10475 /* Make sure echo area buffers in `echo_buffers' are live.
10476 If they aren't, make new ones. */
10479 ensure_echo_area_buffers (void)
10483 for (i
= 0; i
< 2; ++i
)
10484 if (!BUFFERP (echo_buffer
[i
])
10485 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10488 Lisp_Object old_buffer
;
10491 old_buffer
= echo_buffer
[i
];
10492 echo_buffer
[i
] = Fget_buffer_create
10493 (make_formatted_string (name
, " *Echo Area %d*", i
));
10494 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10495 /* to force word wrap in echo area -
10496 it was decided to postpone this*/
10497 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10499 for (j
= 0; j
< 2; ++j
)
10500 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10501 echo_area_buffer
[j
] = echo_buffer
[i
];
10506 /* Call FN with args A1..A2 with either the current or last displayed
10507 echo_area_buffer as current buffer.
10509 WHICH zero means use the current message buffer
10510 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10511 from echo_buffer[] and clear it.
10513 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10514 suitable buffer from echo_buffer[] and clear it.
10516 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10517 that the current message becomes the last displayed one, make
10518 choose a suitable buffer for echo_area_buffer[0], and clear it.
10520 Value is what FN returns. */
10523 with_echo_area_buffer (struct window
*w
, int which
,
10524 bool (*fn
) (ptrdiff_t, Lisp_Object
),
10525 ptrdiff_t a1
, Lisp_Object a2
)
10527 Lisp_Object buffer
;
10528 bool this_one
, the_other
, clear_buffer_p
, rc
;
10529 ptrdiff_t count
= SPECPDL_INDEX ();
10531 /* If buffers aren't live, make new ones. */
10532 ensure_echo_area_buffers ();
10534 clear_buffer_p
= false;
10537 this_one
= false, the_other
= true;
10538 else if (which
> 0)
10539 this_one
= true, the_other
= false;
10542 this_one
= false, the_other
= true;
10543 clear_buffer_p
= true;
10545 /* We need a fresh one in case the current echo buffer equals
10546 the one containing the last displayed echo area message. */
10547 if (!NILP (echo_area_buffer
[this_one
])
10548 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10549 echo_area_buffer
[this_one
] = Qnil
;
10552 /* Choose a suitable buffer from echo_buffer[] is we don't
10554 if (NILP (echo_area_buffer
[this_one
]))
10556 echo_area_buffer
[this_one
]
10557 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10558 ? echo_buffer
[the_other
]
10559 : echo_buffer
[this_one
]);
10560 clear_buffer_p
= true;
10563 buffer
= echo_area_buffer
[this_one
];
10565 /* Don't get confused by reusing the buffer used for echoing
10566 for a different purpose. */
10567 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10570 record_unwind_protect (unwind_with_echo_area_buffer
,
10571 with_echo_area_buffer_unwind_data (w
));
10573 /* Make the echo area buffer current. Note that for display
10574 purposes, it is not necessary that the displayed window's buffer
10575 == current_buffer, except for text property lookup. So, let's
10576 only set that buffer temporarily here without doing a full
10577 Fset_window_buffer. We must also change w->pointm, though,
10578 because otherwise an assertions in unshow_buffer fails, and Emacs
10580 set_buffer_internal_1 (XBUFFER (buffer
));
10583 wset_buffer (w
, buffer
);
10584 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10585 set_marker_both (w
->old_pointm
, buffer
, BEG
, BEG_BYTE
);
10588 bset_undo_list (current_buffer
, Qt
);
10589 bset_read_only (current_buffer
, Qnil
);
10590 specbind (Qinhibit_read_only
, Qt
);
10591 specbind (Qinhibit_modification_hooks
, Qt
);
10593 if (clear_buffer_p
&& Z
> BEG
)
10594 del_range (BEG
, Z
);
10596 eassert (BEGV
>= BEG
);
10597 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10601 eassert (BEGV
>= BEG
);
10602 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10604 unbind_to (count
, Qnil
);
10609 /* Save state that should be preserved around the call to the function
10610 FN called in with_echo_area_buffer. */
10613 with_echo_area_buffer_unwind_data (struct window
*w
)
10616 Lisp_Object vector
, tmp
;
10618 /* Reduce consing by keeping one vector in
10619 Vwith_echo_area_save_vector. */
10620 vector
= Vwith_echo_area_save_vector
;
10621 Vwith_echo_area_save_vector
= Qnil
;
10624 vector
= Fmake_vector (make_number (11), Qnil
);
10626 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10627 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10628 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10632 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10633 ASET (vector
, i
, w
->contents
); ++i
;
10634 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10635 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10636 ASET (vector
, i
, make_number (marker_position (w
->old_pointm
))); ++i
;
10637 ASET (vector
, i
, make_number (marker_byte_position (w
->old_pointm
))); ++i
;
10638 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10639 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10644 for (; i
< end
; ++i
)
10645 ASET (vector
, i
, Qnil
);
10648 eassert (i
== ASIZE (vector
));
10653 /* Restore global state from VECTOR which was created by
10654 with_echo_area_buffer_unwind_data. */
10657 unwind_with_echo_area_buffer (Lisp_Object vector
)
10659 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10660 Vdeactivate_mark
= AREF (vector
, 1);
10661 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10663 if (WINDOWP (AREF (vector
, 3)))
10666 Lisp_Object buffer
;
10668 w
= XWINDOW (AREF (vector
, 3));
10669 buffer
= AREF (vector
, 4);
10671 wset_buffer (w
, buffer
);
10672 set_marker_both (w
->pointm
, buffer
,
10673 XFASTINT (AREF (vector
, 5)),
10674 XFASTINT (AREF (vector
, 6)));
10675 set_marker_both (w
->old_pointm
, buffer
,
10676 XFASTINT (AREF (vector
, 7)),
10677 XFASTINT (AREF (vector
, 8)));
10678 set_marker_both (w
->start
, buffer
,
10679 XFASTINT (AREF (vector
, 9)),
10680 XFASTINT (AREF (vector
, 10)));
10683 Vwith_echo_area_save_vector
= vector
;
10687 /* Set up the echo area for use by print functions. MULTIBYTE_P
10688 means we will print multibyte. */
10691 setup_echo_area_for_printing (bool multibyte_p
)
10693 /* If we can't find an echo area any more, exit. */
10694 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10695 Fkill_emacs (Qnil
);
10697 ensure_echo_area_buffers ();
10699 if (!message_buf_print
)
10701 /* A message has been output since the last time we printed.
10702 Choose a fresh echo area buffer. */
10703 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10704 echo_area_buffer
[0] = echo_buffer
[1];
10706 echo_area_buffer
[0] = echo_buffer
[0];
10708 /* Switch to that buffer and clear it. */
10709 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10710 bset_truncate_lines (current_buffer
, Qnil
);
10714 ptrdiff_t count
= SPECPDL_INDEX ();
10715 specbind (Qinhibit_read_only
, Qt
);
10716 /* Note that undo recording is always disabled. */
10717 del_range (BEG
, Z
);
10718 unbind_to (count
, Qnil
);
10720 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10722 /* Set up the buffer for the multibyteness we need. */
10724 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10725 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10727 /* Raise the frame containing the echo area. */
10728 if (minibuffer_auto_raise
)
10730 struct frame
*sf
= SELECTED_FRAME ();
10731 Lisp_Object mini_window
;
10732 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10733 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10736 message_log_maybe_newline ();
10737 message_buf_print
= true;
10741 if (NILP (echo_area_buffer
[0]))
10743 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10744 echo_area_buffer
[0] = echo_buffer
[1];
10746 echo_area_buffer
[0] = echo_buffer
[0];
10749 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10751 /* Someone switched buffers between print requests. */
10752 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10753 bset_truncate_lines (current_buffer
, Qnil
);
10759 /* Display an echo area message in window W. Value is true if W's
10760 height is changed. If display_last_displayed_message_p,
10761 display the message that was last displayed, otherwise
10762 display the current message. */
10765 display_echo_area (struct window
*w
)
10767 bool no_message_p
, window_height_changed_p
;
10769 /* Temporarily disable garbage collections while displaying the echo
10770 area. This is done because a GC can print a message itself.
10771 That message would modify the echo area buffer's contents while a
10772 redisplay of the buffer is going on, and seriously confuse
10774 ptrdiff_t count
= inhibit_garbage_collection ();
10776 /* If there is no message, we must call display_echo_area_1
10777 nevertheless because it resizes the window. But we will have to
10778 reset the echo_area_buffer in question to nil at the end because
10779 with_echo_area_buffer will sets it to an empty buffer. */
10780 bool i
= display_last_displayed_message_p
;
10781 /* According to the C99, C11 and C++11 standards, the integral value
10782 of a "bool" is always 0 or 1, so this array access is safe here,
10784 no_message_p
= NILP (echo_area_buffer
[i
]);
10786 window_height_changed_p
10787 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10788 display_echo_area_1
,
10789 (intptr_t) w
, Qnil
);
10792 echo_area_buffer
[i
] = Qnil
;
10794 unbind_to (count
, Qnil
);
10795 return window_height_changed_p
;
10799 /* Helper for display_echo_area. Display the current buffer which
10800 contains the current echo area message in window W, a mini-window,
10801 a pointer to which is passed in A1. A2..A4 are currently not used.
10802 Change the height of W so that all of the message is displayed.
10803 Value is true if height of W was changed. */
10806 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10809 struct window
*w
= (struct window
*) i1
;
10810 Lisp_Object window
;
10811 struct text_pos start
;
10813 /* We are about to enter redisplay without going through
10814 redisplay_internal, so we need to forget these faces by hand
10816 forget_escape_and_glyphless_faces ();
10818 /* Do this before displaying, so that we have a large enough glyph
10819 matrix for the display. If we can't get enough space for the
10820 whole text, display the last N lines. That works by setting w->start. */
10821 bool window_height_changed_p
= resize_mini_window (w
, false);
10823 /* Use the starting position chosen by resize_mini_window. */
10824 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10827 clear_glyph_matrix (w
->desired_matrix
);
10828 XSETWINDOW (window
, w
);
10829 try_window (window
, start
, 0);
10831 return window_height_changed_p
;
10835 /* Resize the echo area window to exactly the size needed for the
10836 currently displayed message, if there is one. If a mini-buffer
10837 is active, don't shrink it. */
10840 resize_echo_area_exactly (void)
10842 if (BUFFERP (echo_area_buffer
[0])
10843 && WINDOWP (echo_area_window
))
10845 struct window
*w
= XWINDOW (echo_area_window
);
10846 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10847 bool resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10848 (intptr_t) w
, resize_exactly
);
10851 windows_or_buffers_changed
= 42;
10852 update_mode_lines
= 30;
10853 redisplay_internal ();
10859 /* Callback function for with_echo_area_buffer, when used from
10860 resize_echo_area_exactly. A1 contains a pointer to the window to
10861 resize, EXACTLY non-nil means resize the mini-window exactly to the
10862 size of the text displayed. A3 and A4 are not used. Value is what
10863 resize_mini_window returns. */
10866 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10869 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10873 /* Resize mini-window W to fit the size of its contents. EXACT_P
10874 means size the window exactly to the size needed. Otherwise, it's
10875 only enlarged until W's buffer is empty.
10877 Set W->start to the right place to begin display. If the whole
10878 contents fit, start at the beginning. Otherwise, start so as
10879 to make the end of the contents appear. This is particularly
10880 important for y-or-n-p, but seems desirable generally.
10882 Value is true if the window height has been changed. */
10885 resize_mini_window (struct window
*w
, bool exact_p
)
10887 struct frame
*f
= XFRAME (w
->frame
);
10888 bool window_height_changed_p
= false;
10890 eassert (MINI_WINDOW_P (w
));
10892 /* By default, start display at the beginning. */
10893 set_marker_both (w
->start
, w
->contents
,
10894 BUF_BEGV (XBUFFER (w
->contents
)),
10895 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10897 /* Don't resize windows while redisplaying a window; it would
10898 confuse redisplay functions when the size of the window they are
10899 displaying changes from under them. Such a resizing can happen,
10900 for instance, when which-func prints a long message while
10901 we are running fontification-functions. We're running these
10902 functions with safe_call which binds inhibit-redisplay to t. */
10903 if (!NILP (Vinhibit_redisplay
))
10906 /* Nil means don't try to resize. */
10907 if (NILP (Vresize_mini_windows
)
10908 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10911 if (!FRAME_MINIBUF_ONLY_P (f
))
10914 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10915 + WINDOW_PIXEL_HEIGHT (w
));
10916 int unit
= FRAME_LINE_HEIGHT (f
);
10917 int height
, max_height
;
10918 struct text_pos start
;
10919 struct buffer
*old_current_buffer
= NULL
;
10921 if (current_buffer
!= XBUFFER (w
->contents
))
10923 old_current_buffer
= current_buffer
;
10924 set_buffer_internal (XBUFFER (w
->contents
));
10927 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10929 /* Compute the max. number of lines specified by the user. */
10930 if (FLOATP (Vmax_mini_window_height
))
10931 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10932 else if (INTEGERP (Vmax_mini_window_height
))
10933 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10935 max_height
= total_height
/ 4;
10937 /* Correct that max. height if it's bogus. */
10938 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10940 /* Find out the height of the text in the window. */
10941 if (it
.line_wrap
== TRUNCATE
)
10946 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10947 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10948 height
= it
.current_y
+ last_height
;
10950 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10951 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10954 /* Compute a suitable window start. */
10955 if (height
> max_height
)
10957 height
= (max_height
/ unit
) * unit
;
10958 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10959 move_it_vertically_backward (&it
, height
- unit
);
10960 start
= it
.current
.pos
;
10963 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10964 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10966 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10968 /* Let it grow only, until we display an empty message, in which
10969 case the window shrinks again. */
10970 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10972 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10974 FRAME_WINDOWS_FROZEN (f
) = true;
10975 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
10976 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10978 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10979 && (exact_p
|| BEGV
== ZV
))
10981 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10983 FRAME_WINDOWS_FROZEN (f
) = false;
10984 shrink_mini_window (w
, true);
10985 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10990 /* Always resize to exact size needed. */
10991 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10993 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10995 FRAME_WINDOWS_FROZEN (f
) = true;
10996 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
10997 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10999 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
11001 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11003 FRAME_WINDOWS_FROZEN (f
) = false;
11004 shrink_mini_window (w
, true);
11008 FRAME_WINDOWS_FROZEN (f
) = true;
11009 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
11012 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11016 if (old_current_buffer
)
11017 set_buffer_internal (old_current_buffer
);
11020 return window_height_changed_p
;
11024 /* Value is the current message, a string, or nil if there is no
11025 current message. */
11028 current_message (void)
11032 if (!BUFFERP (echo_area_buffer
[0]))
11036 with_echo_area_buffer (0, 0, current_message_1
,
11037 (intptr_t) &msg
, Qnil
);
11039 echo_area_buffer
[0] = Qnil
;
11047 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
11050 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
11053 *msg
= make_buffer_string (BEG
, Z
, true);
11060 /* Push the current message on Vmessage_stack for later restoration
11061 by restore_message. Value is true if the current message isn't
11062 empty. This is a relatively infrequent operation, so it's not
11063 worth optimizing. */
11066 push_message (void)
11068 Lisp_Object msg
= current_message ();
11069 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
11070 return STRINGP (msg
);
11074 /* Restore message display from the top of Vmessage_stack. */
11077 restore_message (void)
11079 eassert (CONSP (Vmessage_stack
));
11080 message3_nolog (XCAR (Vmessage_stack
));
11084 /* Handler for unwind-protect calling pop_message. */
11087 pop_message_unwind (void)
11089 /* Pop the top-most entry off Vmessage_stack. */
11090 eassert (CONSP (Vmessage_stack
));
11091 Vmessage_stack
= XCDR (Vmessage_stack
);
11095 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
11096 exits. If the stack is not empty, we have a missing pop_message
11100 check_message_stack (void)
11102 if (!NILP (Vmessage_stack
))
11107 /* Truncate to NCHARS what will be displayed in the echo area the next
11108 time we display it---but don't redisplay it now. */
11111 truncate_echo_area (ptrdiff_t nchars
)
11114 echo_area_buffer
[0] = Qnil
;
11115 else if (!noninteractive
11117 && !NILP (echo_area_buffer
[0]))
11119 struct frame
*sf
= SELECTED_FRAME ();
11120 /* Error messages get reported properly by cmd_error, so this must be
11121 just an informative message; if the frame hasn't really been
11122 initialized yet, just toss it. */
11123 if (sf
->glyphs_initialized_p
)
11124 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
11129 /* Helper function for truncate_echo_area. Truncate the current
11130 message to at most NCHARS characters. */
11133 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
11135 if (BEG
+ nchars
< Z
)
11136 del_range (BEG
+ nchars
, Z
);
11138 echo_area_buffer
[0] = Qnil
;
11142 /* Set the current message to STRING. */
11145 set_message (Lisp_Object string
)
11147 eassert (STRINGP (string
));
11149 message_enable_multibyte
= STRING_MULTIBYTE (string
);
11151 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
11152 message_buf_print
= false;
11153 help_echo_showing_p
= false;
11155 if (STRINGP (Vdebug_on_message
)
11156 && STRINGP (string
)
11157 && fast_string_match (Vdebug_on_message
, string
) >= 0)
11158 call_debugger (list2 (Qerror
, string
));
11162 /* Helper function for set_message. First argument is ignored and second
11163 argument has the same meaning as for set_message.
11164 This function is called with the echo area buffer being current. */
11167 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
11169 eassert (STRINGP (string
));
11171 /* Change multibyteness of the echo buffer appropriately. */
11172 if (message_enable_multibyte
11173 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
11174 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
11176 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
11177 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
11178 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
11180 /* Insert new message at BEG. */
11181 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
11183 /* This function takes care of single/multibyte conversion.
11184 We just have to ensure that the echo area buffer has the right
11185 setting of enable_multibyte_characters. */
11186 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), true);
11192 /* Clear messages. CURRENT_P means clear the current message.
11193 LAST_DISPLAYED_P means clear the message last displayed. */
11196 clear_message (bool current_p
, bool last_displayed_p
)
11200 echo_area_buffer
[0] = Qnil
;
11201 message_cleared_p
= true;
11204 if (last_displayed_p
)
11205 echo_area_buffer
[1] = Qnil
;
11207 message_buf_print
= false;
11210 /* Clear garbaged frames.
11212 This function is used where the old redisplay called
11213 redraw_garbaged_frames which in turn called redraw_frame which in
11214 turn called clear_frame. The call to clear_frame was a source of
11215 flickering. I believe a clear_frame is not necessary. It should
11216 suffice in the new redisplay to invalidate all current matrices,
11217 and ensure a complete redisplay of all windows. */
11220 clear_garbaged_frames (void)
11222 if (frame_garbaged
)
11224 Lisp_Object tail
, frame
;
11226 FOR_EACH_FRAME (tail
, frame
)
11228 struct frame
*f
= XFRAME (frame
);
11230 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
11235 clear_current_matrices (f
);
11236 fset_redisplay (f
);
11237 f
->garbaged
= false;
11238 f
->resized_p
= false;
11242 frame_garbaged
= false;
11247 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P, update
11251 echo_area_display (bool update_frame_p
)
11253 Lisp_Object mini_window
;
11256 bool window_height_changed_p
= false;
11257 struct frame
*sf
= SELECTED_FRAME ();
11259 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11260 w
= XWINDOW (mini_window
);
11261 f
= XFRAME (WINDOW_FRAME (w
));
11263 /* Don't display if frame is invisible or not yet initialized. */
11264 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
11267 #ifdef HAVE_WINDOW_SYSTEM
11268 /* When Emacs starts, selected_frame may be the initial terminal
11269 frame. If we let this through, a message would be displayed on
11271 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
11273 #endif /* HAVE_WINDOW_SYSTEM */
11275 /* Redraw garbaged frames. */
11276 clear_garbaged_frames ();
11278 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
11280 echo_area_window
= mini_window
;
11281 window_height_changed_p
= display_echo_area (w
);
11282 w
->must_be_updated_p
= true;
11284 /* Update the display, unless called from redisplay_internal.
11285 Also don't update the screen during redisplay itself. The
11286 update will happen at the end of redisplay, and an update
11287 here could cause confusion. */
11288 if (update_frame_p
&& !redisplaying_p
)
11292 /* If the display update has been interrupted by pending
11293 input, update mode lines in the frame. Due to the
11294 pending input, it might have been that redisplay hasn't
11295 been called, so that mode lines above the echo area are
11296 garbaged. This looks odd, so we prevent it here. */
11297 if (!display_completed
)
11298 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11300 if (window_height_changed_p
11301 /* Don't do this if Emacs is shutting down. Redisplay
11302 needs to run hooks. */
11303 && !NILP (Vrun_hooks
))
11305 /* Must update other windows. Likewise as in other
11306 cases, don't let this update be interrupted by
11308 ptrdiff_t count
= SPECPDL_INDEX ();
11309 specbind (Qredisplay_dont_pause
, Qt
);
11310 fset_redisplay (f
);
11311 redisplay_internal ();
11312 unbind_to (count
, Qnil
);
11314 else if (FRAME_WINDOW_P (f
) && n
== 0)
11316 /* Window configuration is the same as before.
11317 Can do with a display update of the echo area,
11318 unless we displayed some mode lines. */
11319 update_single_window (w
);
11323 update_frame (f
, true, true);
11325 /* If cursor is in the echo area, make sure that the next
11326 redisplay displays the minibuffer, so that the cursor will
11327 be replaced with what the minibuffer wants. */
11328 if (cursor_in_echo_area
)
11329 wset_redisplay (XWINDOW (mini_window
));
11332 else if (!EQ (mini_window
, selected_window
))
11333 wset_redisplay (XWINDOW (mini_window
));
11335 /* Last displayed message is now the current message. */
11336 echo_area_buffer
[1] = echo_area_buffer
[0];
11337 /* Inform read_char that we're not echoing. */
11338 echo_message_buffer
= Qnil
;
11340 /* Prevent redisplay optimization in redisplay_internal by resetting
11341 this_line_start_pos. This is done because the mini-buffer now
11342 displays the message instead of its buffer text. */
11343 if (EQ (mini_window
, selected_window
))
11344 CHARPOS (this_line_start_pos
) = 0;
11346 if (window_height_changed_p
)
11348 fset_redisplay (f
);
11350 /* If window configuration was changed, frames may have been
11351 marked garbaged. Clear them or we will experience
11352 surprises wrt scrolling.
11353 FIXME: How/why/when? */
11354 clear_garbaged_frames ();
11358 /* True if W's buffer was changed but not saved. */
11361 window_buffer_changed (struct window
*w
)
11363 struct buffer
*b
= XBUFFER (w
->contents
);
11365 eassert (BUFFER_LIVE_P (b
));
11367 return (BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
;
11370 /* True if W has %c in its mode line and mode line should be updated. */
11373 mode_line_update_needed (struct window
*w
)
11375 return (w
->column_number_displayed
!= -1
11376 && !(PT
== w
->last_point
&& !window_outdated (w
))
11377 && (w
->column_number_displayed
!= current_column ()));
11380 /* True if window start of W is frozen and may not be changed during
11384 window_frozen_p (struct window
*w
)
11386 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11388 Lisp_Object window
;
11390 XSETWINDOW (window
, w
);
11391 if (MINI_WINDOW_P (w
))
11393 else if (EQ (window
, selected_window
))
11395 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11396 && EQ (window
, Vminibuf_scroll_window
))
11397 /* This special window can't be frozen too. */
11405 /***********************************************************************
11406 Mode Lines and Frame Titles
11407 ***********************************************************************/
11409 /* A buffer for constructing non-propertized mode-line strings and
11410 frame titles in it; allocated from the heap in init_xdisp and
11411 resized as needed in store_mode_line_noprop_char. */
11413 static char *mode_line_noprop_buf
;
11415 /* The buffer's end, and a current output position in it. */
11417 static char *mode_line_noprop_buf_end
;
11418 static char *mode_line_noprop_ptr
;
11420 #define MODE_LINE_NOPROP_LEN(start) \
11421 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11424 MODE_LINE_DISPLAY
= 0,
11428 } mode_line_target
;
11430 /* Alist that caches the results of :propertize.
11431 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11432 static Lisp_Object mode_line_proptrans_alist
;
11434 /* List of strings making up the mode-line. */
11435 static Lisp_Object mode_line_string_list
;
11437 /* Base face property when building propertized mode line string. */
11438 static Lisp_Object mode_line_string_face
;
11439 static Lisp_Object mode_line_string_face_prop
;
11442 /* Unwind data for mode line strings */
11444 static Lisp_Object Vmode_line_unwind_vector
;
11447 format_mode_line_unwind_data (struct frame
*target_frame
,
11448 struct buffer
*obuf
,
11450 bool save_proptrans
)
11452 Lisp_Object vector
, tmp
;
11454 /* Reduce consing by keeping one vector in
11455 Vwith_echo_area_save_vector. */
11456 vector
= Vmode_line_unwind_vector
;
11457 Vmode_line_unwind_vector
= Qnil
;
11460 vector
= Fmake_vector (make_number (10), Qnil
);
11462 ASET (vector
, 0, make_number (mode_line_target
));
11463 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11464 ASET (vector
, 2, mode_line_string_list
);
11465 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11466 ASET (vector
, 4, mode_line_string_face
);
11467 ASET (vector
, 5, mode_line_string_face_prop
);
11470 XSETBUFFER (tmp
, obuf
);
11473 ASET (vector
, 6, tmp
);
11474 ASET (vector
, 7, owin
);
11477 /* Similarly to `with-selected-window', if the operation selects
11478 a window on another frame, we must restore that frame's
11479 selected window, and (for a tty) the top-frame. */
11480 ASET (vector
, 8, target_frame
->selected_window
);
11481 if (FRAME_TERMCAP_P (target_frame
))
11482 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11489 unwind_format_mode_line (Lisp_Object vector
)
11491 Lisp_Object old_window
= AREF (vector
, 7);
11492 Lisp_Object target_frame_window
= AREF (vector
, 8);
11493 Lisp_Object old_top_frame
= AREF (vector
, 9);
11495 mode_line_target
= XINT (AREF (vector
, 0));
11496 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11497 mode_line_string_list
= AREF (vector
, 2);
11498 if (! EQ (AREF (vector
, 3), Qt
))
11499 mode_line_proptrans_alist
= AREF (vector
, 3);
11500 mode_line_string_face
= AREF (vector
, 4);
11501 mode_line_string_face_prop
= AREF (vector
, 5);
11503 /* Select window before buffer, since it may change the buffer. */
11504 if (!NILP (old_window
))
11506 /* If the operation that we are unwinding had selected a window
11507 on a different frame, reset its frame-selected-window. For a
11508 text terminal, reset its top-frame if necessary. */
11509 if (!NILP (target_frame_window
))
11512 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11514 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11515 Fselect_window (target_frame_window
, Qt
);
11517 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11518 Fselect_frame (old_top_frame
, Qt
);
11521 Fselect_window (old_window
, Qt
);
11524 if (!NILP (AREF (vector
, 6)))
11526 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11527 ASET (vector
, 6, Qnil
);
11530 Vmode_line_unwind_vector
= vector
;
11534 /* Store a single character C for the frame title in mode_line_noprop_buf.
11535 Re-allocate mode_line_noprop_buf if necessary. */
11538 store_mode_line_noprop_char (char c
)
11540 /* If output position has reached the end of the allocated buffer,
11541 increase the buffer's size. */
11542 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11544 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11545 ptrdiff_t size
= len
;
11546 mode_line_noprop_buf
=
11547 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11548 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11549 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11552 *mode_line_noprop_ptr
++ = c
;
11556 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11557 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11558 characters that yield more columns than PRECISION; PRECISION <= 0
11559 means copy the whole string. Pad with spaces until FIELD_WIDTH
11560 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11561 pad. Called from display_mode_element when it is used to build a
11565 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11567 const unsigned char *str
= (const unsigned char *) string
;
11569 ptrdiff_t dummy
, nbytes
;
11571 /* Copy at most PRECISION chars from STR. */
11572 nbytes
= strlen (string
);
11573 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11575 store_mode_line_noprop_char (*str
++);
11577 /* Fill up with spaces until FIELD_WIDTH reached. */
11578 while (field_width
> 0
11579 && n
< field_width
)
11581 store_mode_line_noprop_char (' ');
11588 /***********************************************************************
11590 ***********************************************************************/
11592 #ifdef HAVE_WINDOW_SYSTEM
11594 /* Set the title of FRAME, if it has changed. The title format is
11595 Vicon_title_format if FRAME is iconified, otherwise it is
11596 frame_title_format. */
11599 x_consider_frame_title (Lisp_Object frame
)
11601 struct frame
*f
= XFRAME (frame
);
11603 if ((FRAME_WINDOW_P (f
)
11604 || FRAME_MINIBUF_ONLY_P (f
)
11605 || f
->explicit_name
)
11606 && NILP (Fframe_parameter (frame
, Qtooltip
)))
11608 /* Do we have more than one visible frame on this X display? */
11609 Lisp_Object tail
, other_frame
, fmt
;
11610 ptrdiff_t title_start
;
11614 ptrdiff_t count
= SPECPDL_INDEX ();
11616 FOR_EACH_FRAME (tail
, other_frame
)
11618 struct frame
*tf
= XFRAME (other_frame
);
11621 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11622 && !FRAME_MINIBUF_ONLY_P (tf
)
11623 && !EQ (other_frame
, tip_frame
)
11624 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11628 /* Set global variable indicating that multiple frames exist. */
11629 multiple_frames
= CONSP (tail
);
11631 /* Switch to the buffer of selected window of the frame. Set up
11632 mode_line_target so that display_mode_element will output into
11633 mode_line_noprop_buf; then display the title. */
11634 record_unwind_protect (unwind_format_mode_line
,
11635 format_mode_line_unwind_data
11636 (f
, current_buffer
, selected_window
, false));
11638 Fselect_window (f
->selected_window
, Qt
);
11639 set_buffer_internal_1
11640 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11641 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11643 mode_line_target
= MODE_LINE_TITLE
;
11644 title_start
= MODE_LINE_NOPROP_LEN (0);
11645 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11646 NULL
, DEFAULT_FACE_ID
);
11647 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, false);
11648 len
= MODE_LINE_NOPROP_LEN (title_start
);
11649 title
= mode_line_noprop_buf
+ title_start
;
11650 unbind_to (count
, Qnil
);
11652 /* Set the title only if it's changed. This avoids consing in
11653 the common case where it hasn't. (If it turns out that we've
11654 already wasted too much time by walking through the list with
11655 display_mode_element, then we might need to optimize at a
11656 higher level than this.) */
11657 if (! STRINGP (f
->name
)
11658 || SBYTES (f
->name
) != len
11659 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11660 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11664 #endif /* not HAVE_WINDOW_SYSTEM */
11667 /***********************************************************************
11669 ***********************************************************************/
11671 /* True if we will not redisplay all visible windows. */
11672 #define REDISPLAY_SOME_P() \
11673 ((windows_or_buffers_changed == 0 \
11674 || windows_or_buffers_changed == REDISPLAY_SOME) \
11675 && (update_mode_lines == 0 \
11676 || update_mode_lines == REDISPLAY_SOME))
11678 /* Prepare for redisplay by updating menu-bar item lists when
11679 appropriate. This can call eval. */
11682 prepare_menu_bars (void)
11684 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11685 bool some_windows
= REDISPLAY_SOME_P ();
11686 Lisp_Object tooltip_frame
;
11688 #ifdef HAVE_WINDOW_SYSTEM
11689 tooltip_frame
= tip_frame
;
11691 tooltip_frame
= Qnil
;
11694 if (FUNCTIONP (Vpre_redisplay_function
))
11696 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11697 if (all_windows
&& some_windows
)
11699 Lisp_Object ws
= window_list ();
11700 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11702 Lisp_Object
this = XCAR (ws
);
11703 struct window
*w
= XWINDOW (this);
11705 || XFRAME (w
->frame
)->redisplay
11706 || XBUFFER (w
->contents
)->text
->redisplay
)
11708 windows
= Fcons (this, windows
);
11712 safe__call1 (true, Vpre_redisplay_function
, windows
);
11715 /* Update all frame titles based on their buffer names, etc. We do
11716 this before the menu bars so that the buffer-menu will show the
11717 up-to-date frame titles. */
11718 #ifdef HAVE_WINDOW_SYSTEM
11721 Lisp_Object tail
, frame
;
11723 FOR_EACH_FRAME (tail
, frame
)
11725 struct frame
*f
= XFRAME (frame
);
11726 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11730 && !XBUFFER (w
->contents
)->text
->redisplay
)
11733 if (!EQ (frame
, tooltip_frame
)
11734 && (FRAME_ICONIFIED_P (f
)
11735 || FRAME_VISIBLE_P (f
) == 1
11736 /* Exclude TTY frames that are obscured because they
11737 are not the top frame on their console. This is
11738 because x_consider_frame_title actually switches
11739 to the frame, which for TTY frames means it is
11740 marked as garbaged, and will be completely
11741 redrawn on the next redisplay cycle. This causes
11742 TTY frames to be completely redrawn, when there
11743 are more than one of them, even though nothing
11744 should be changed on display. */
11745 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11746 x_consider_frame_title (frame
);
11749 #endif /* HAVE_WINDOW_SYSTEM */
11751 /* Update the menu bar item lists, if appropriate. This has to be
11752 done before any actual redisplay or generation of display lines. */
11756 Lisp_Object tail
, frame
;
11757 ptrdiff_t count
= SPECPDL_INDEX ();
11758 /* True means that update_menu_bar has run its hooks
11759 so any further calls to update_menu_bar shouldn't do so again. */
11760 bool menu_bar_hooks_run
= false;
11762 record_unwind_save_match_data ();
11764 FOR_EACH_FRAME (tail
, frame
)
11766 struct frame
*f
= XFRAME (frame
);
11767 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11769 /* Ignore tooltip frame. */
11770 if (EQ (frame
, tooltip_frame
))
11776 && !XBUFFER (w
->contents
)->text
->redisplay
)
11779 /* If a window on this frame changed size, report that to
11780 the user and clear the size-change flag. */
11781 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11783 Lisp_Object functions
;
11785 /* Clear flag first in case we get an error below. */
11786 FRAME_WINDOW_SIZES_CHANGED (f
) = false;
11787 functions
= Vwindow_size_change_functions
;
11789 while (CONSP (functions
))
11791 if (!EQ (XCAR (functions
), Qt
))
11792 call1 (XCAR (functions
), frame
);
11793 functions
= XCDR (functions
);
11797 menu_bar_hooks_run
= update_menu_bar (f
, false, menu_bar_hooks_run
);
11798 #ifdef HAVE_WINDOW_SYSTEM
11799 update_tool_bar (f
, false);
11803 unbind_to (count
, Qnil
);
11807 struct frame
*sf
= SELECTED_FRAME ();
11808 update_menu_bar (sf
, true, false);
11809 #ifdef HAVE_WINDOW_SYSTEM
11810 update_tool_bar (sf
, true);
11816 /* Update the menu bar item list for frame F. This has to be done
11817 before we start to fill in any display lines, because it can call
11820 If SAVE_MATCH_DATA, we must save and restore it here.
11822 If HOOKS_RUN, a previous call to update_menu_bar
11823 already ran the menu bar hooks for this redisplay, so there
11824 is no need to run them again. The return value is the
11825 updated value of this flag, to pass to the next call. */
11828 update_menu_bar (struct frame
*f
, bool save_match_data
, bool hooks_run
)
11830 Lisp_Object window
;
11833 /* If called recursively during a menu update, do nothing. This can
11834 happen when, for instance, an activate-menubar-hook causes a
11836 if (inhibit_menubar_update
)
11839 window
= FRAME_SELECTED_WINDOW (f
);
11840 w
= XWINDOW (window
);
11842 if (FRAME_WINDOW_P (f
)
11844 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11845 || defined (HAVE_NS) || defined (USE_GTK)
11846 FRAME_EXTERNAL_MENU_BAR (f
)
11848 FRAME_MENU_BAR_LINES (f
) > 0
11850 : FRAME_MENU_BAR_LINES (f
) > 0)
11852 /* If the user has switched buffers or windows, we need to
11853 recompute to reflect the new bindings. But we'll
11854 recompute when update_mode_lines is set too; that means
11855 that people can use force-mode-line-update to request
11856 that the menu bar be recomputed. The adverse effect on
11857 the rest of the redisplay algorithm is about the same as
11858 windows_or_buffers_changed anyway. */
11859 if (windows_or_buffers_changed
11860 /* This used to test w->update_mode_line, but we believe
11861 there is no need to recompute the menu in that case. */
11862 || update_mode_lines
11863 || window_buffer_changed (w
))
11865 struct buffer
*prev
= current_buffer
;
11866 ptrdiff_t count
= SPECPDL_INDEX ();
11868 specbind (Qinhibit_menubar_update
, Qt
);
11870 set_buffer_internal_1 (XBUFFER (w
->contents
));
11871 if (save_match_data
)
11872 record_unwind_save_match_data ();
11873 if (NILP (Voverriding_local_map_menu_flag
))
11875 specbind (Qoverriding_terminal_local_map
, Qnil
);
11876 specbind (Qoverriding_local_map
, Qnil
);
11881 /* Run the Lucid hook. */
11882 safe_run_hooks (Qactivate_menubar_hook
);
11884 /* If it has changed current-menubar from previous value,
11885 really recompute the menu-bar from the value. */
11886 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11887 call0 (Qrecompute_lucid_menubar
);
11889 safe_run_hooks (Qmenu_bar_update_hook
);
11894 XSETFRAME (Vmenu_updating_frame
, f
);
11895 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11897 /* Redisplay the menu bar in case we changed it. */
11898 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11899 || defined (HAVE_NS) || defined (USE_GTK)
11900 if (FRAME_WINDOW_P (f
))
11902 #if defined (HAVE_NS)
11903 /* All frames on Mac OS share the same menubar. So only
11904 the selected frame should be allowed to set it. */
11905 if (f
== SELECTED_FRAME ())
11907 set_frame_menubar (f
, false, false);
11910 /* On a terminal screen, the menu bar is an ordinary screen
11911 line, and this makes it get updated. */
11912 w
->update_mode_line
= true;
11913 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11914 /* In the non-toolkit version, the menu bar is an ordinary screen
11915 line, and this makes it get updated. */
11916 w
->update_mode_line
= true;
11917 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11919 unbind_to (count
, Qnil
);
11920 set_buffer_internal_1 (prev
);
11927 /***********************************************************************
11929 ***********************************************************************/
11931 #ifdef HAVE_WINDOW_SYSTEM
11933 /* Select `frame' temporarily without running all the code in
11935 FIXME: Maybe do_switch_frame should be trimmed down similarly
11936 when `norecord' is set. */
11938 fast_set_selected_frame (Lisp_Object frame
)
11940 if (!EQ (selected_frame
, frame
))
11942 selected_frame
= frame
;
11943 selected_window
= XFRAME (frame
)->selected_window
;
11947 /* Update the tool-bar item list for frame F. This has to be done
11948 before we start to fill in any display lines. Called from
11949 prepare_menu_bars. If SAVE_MATCH_DATA, we must save
11950 and restore it here. */
11953 update_tool_bar (struct frame
*f
, bool save_match_data
)
11955 #if defined (USE_GTK) || defined (HAVE_NS)
11956 bool do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11958 bool do_update
= (WINDOWP (f
->tool_bar_window
)
11959 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0);
11964 Lisp_Object window
;
11967 window
= FRAME_SELECTED_WINDOW (f
);
11968 w
= XWINDOW (window
);
11970 /* If the user has switched buffers or windows, we need to
11971 recompute to reflect the new bindings. But we'll
11972 recompute when update_mode_lines is set too; that means
11973 that people can use force-mode-line-update to request
11974 that the menu bar be recomputed. The adverse effect on
11975 the rest of the redisplay algorithm is about the same as
11976 windows_or_buffers_changed anyway. */
11977 if (windows_or_buffers_changed
11978 || w
->update_mode_line
11979 || update_mode_lines
11980 || window_buffer_changed (w
))
11982 struct buffer
*prev
= current_buffer
;
11983 ptrdiff_t count
= SPECPDL_INDEX ();
11984 Lisp_Object frame
, new_tool_bar
;
11985 int new_n_tool_bar
;
11987 /* Set current_buffer to the buffer of the selected
11988 window of the frame, so that we get the right local
11990 set_buffer_internal_1 (XBUFFER (w
->contents
));
11992 /* Save match data, if we must. */
11993 if (save_match_data
)
11994 record_unwind_save_match_data ();
11996 /* Make sure that we don't accidentally use bogus keymaps. */
11997 if (NILP (Voverriding_local_map_menu_flag
))
11999 specbind (Qoverriding_terminal_local_map
, Qnil
);
12000 specbind (Qoverriding_local_map
, Qnil
);
12003 /* We must temporarily set the selected frame to this frame
12004 before calling tool_bar_items, because the calculation of
12005 the tool-bar keymap uses the selected frame (see
12006 `tool-bar-make-keymap' in tool-bar.el). */
12007 eassert (EQ (selected_window
,
12008 /* Since we only explicitly preserve selected_frame,
12009 check that selected_window would be redundant. */
12010 XFRAME (selected_frame
)->selected_window
));
12011 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
12012 XSETFRAME (frame
, f
);
12013 fast_set_selected_frame (frame
);
12015 /* Build desired tool-bar items from keymaps. */
12017 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
12020 /* Redisplay the tool-bar if we changed it. */
12021 if (new_n_tool_bar
!= f
->n_tool_bar_items
12022 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
12024 /* Redisplay that happens asynchronously due to an expose event
12025 may access f->tool_bar_items. Make sure we update both
12026 variables within BLOCK_INPUT so no such event interrupts. */
12028 fset_tool_bar_items (f
, new_tool_bar
);
12029 f
->n_tool_bar_items
= new_n_tool_bar
;
12030 w
->update_mode_line
= true;
12034 unbind_to (count
, Qnil
);
12035 set_buffer_internal_1 (prev
);
12040 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12042 /* Set F->desired_tool_bar_string to a Lisp string representing frame
12043 F's desired tool-bar contents. F->tool_bar_items must have
12044 been set up previously by calling prepare_menu_bars. */
12047 build_desired_tool_bar_string (struct frame
*f
)
12049 int i
, size
, size_needed
;
12050 Lisp_Object image
, plist
;
12052 image
= plist
= Qnil
;
12054 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
12055 Otherwise, make a new string. */
12057 /* The size of the string we might be able to reuse. */
12058 size
= (STRINGP (f
->desired_tool_bar_string
)
12059 ? SCHARS (f
->desired_tool_bar_string
)
12062 /* We need one space in the string for each image. */
12063 size_needed
= f
->n_tool_bar_items
;
12065 /* Reuse f->desired_tool_bar_string, if possible. */
12066 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
12067 fset_desired_tool_bar_string
12068 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
12071 AUTO_LIST4 (props
, Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
12072 Fremove_text_properties (make_number (0), make_number (size
),
12073 props
, f
->desired_tool_bar_string
);
12076 /* Put a `display' property on the string for the images to display,
12077 put a `menu_item' property on tool-bar items with a value that
12078 is the index of the item in F's tool-bar item vector. */
12079 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
12081 #define PROP(IDX) \
12082 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
12084 bool enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
12085 bool selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
12086 int hmargin
, vmargin
, relief
, idx
, end
;
12088 /* If image is a vector, choose the image according to the
12090 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
12091 if (VECTORP (image
))
12095 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
12096 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
12099 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
12100 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
12102 eassert (ASIZE (image
) >= idx
);
12103 image
= AREF (image
, idx
);
12108 /* Ignore invalid image specifications. */
12109 if (!valid_image_p (image
))
12112 /* Display the tool-bar button pressed, or depressed. */
12113 plist
= Fcopy_sequence (XCDR (image
));
12115 /* Compute margin and relief to draw. */
12116 relief
= (tool_bar_button_relief
>= 0
12117 ? tool_bar_button_relief
12118 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
12119 hmargin
= vmargin
= relief
;
12121 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
12122 INT_MAX
- max (hmargin
, vmargin
)))
12124 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
12125 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
12127 else if (CONSP (Vtool_bar_button_margin
))
12129 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
12130 INT_MAX
- hmargin
))
12131 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
12133 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
12134 INT_MAX
- vmargin
))
12135 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
12138 if (auto_raise_tool_bar_buttons_p
)
12140 /* Add a `:relief' property to the image spec if the item is
12144 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
12151 /* If image is selected, display it pressed, i.e. with a
12152 negative relief. If it's not selected, display it with a
12154 plist
= Fplist_put (plist
, QCrelief
,
12156 ? make_number (-relief
)
12157 : make_number (relief
)));
12162 /* Put a margin around the image. */
12163 if (hmargin
|| vmargin
)
12165 if (hmargin
== vmargin
)
12166 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
12168 plist
= Fplist_put (plist
, QCmargin
,
12169 Fcons (make_number (hmargin
),
12170 make_number (vmargin
)));
12173 /* If button is not enabled, and we don't have special images
12174 for the disabled state, make the image appear disabled by
12175 applying an appropriate algorithm to it. */
12176 if (!enabled_p
&& idx
< 0)
12177 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
12179 /* Put a `display' text property on the string for the image to
12180 display. Put a `menu-item' property on the string that gives
12181 the start of this item's properties in the tool-bar items
12183 image
= Fcons (Qimage
, plist
);
12184 AUTO_LIST4 (props
, Qdisplay
, image
, Qmenu_item
,
12185 make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
12187 /* Let the last image hide all remaining spaces in the tool bar
12188 string. The string can be longer than needed when we reuse a
12189 previous string. */
12190 if (i
+ 1 == f
->n_tool_bar_items
)
12191 end
= SCHARS (f
->desired_tool_bar_string
);
12194 Fadd_text_properties (make_number (i
), make_number (end
),
12195 props
, f
->desired_tool_bar_string
);
12201 /* Display one line of the tool-bar of frame IT->f.
12203 HEIGHT specifies the desired height of the tool-bar line.
12204 If the actual height of the glyph row is less than HEIGHT, the
12205 row's height is increased to HEIGHT, and the icons are centered
12206 vertically in the new height.
12208 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
12209 count a final empty row in case the tool-bar width exactly matches
12214 display_tool_bar_line (struct it
*it
, int height
)
12216 struct glyph_row
*row
= it
->glyph_row
;
12217 int max_x
= it
->last_visible_x
;
12218 struct glyph
*last
;
12220 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
12221 clear_glyph_row (row
);
12222 row
->enabled_p
= true;
12223 row
->y
= it
->current_y
;
12225 /* Note that this isn't made use of if the face hasn't a box,
12226 so there's no need to check the face here. */
12227 it
->start_of_box_run_p
= true;
12229 while (it
->current_x
< max_x
)
12231 int x
, n_glyphs_before
, i
, nglyphs
;
12232 struct it it_before
;
12234 /* Get the next display element. */
12235 if (!get_next_display_element (it
))
12237 /* Don't count empty row if we are counting needed tool-bar lines. */
12238 if (height
< 0 && !it
->hpos
)
12243 /* Produce glyphs. */
12244 n_glyphs_before
= row
->used
[TEXT_AREA
];
12247 PRODUCE_GLYPHS (it
);
12249 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12251 x
= it_before
.current_x
;
12252 while (i
< nglyphs
)
12254 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12256 if (x
+ glyph
->pixel_width
> max_x
)
12258 /* Glyph doesn't fit on line. Backtrack. */
12259 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12261 /* If this is the only glyph on this line, it will never fit on the
12262 tool-bar, so skip it. But ensure there is at least one glyph,
12263 so we don't accidentally disable the tool-bar. */
12264 if (n_glyphs_before
== 0
12265 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
12271 x
+= glyph
->pixel_width
;
12275 /* Stop at line end. */
12276 if (ITERATOR_AT_END_OF_LINE_P (it
))
12279 set_iterator_to_next (it
, true);
12284 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12286 /* Use default face for the border below the tool bar.
12288 FIXME: When auto-resize-tool-bars is grow-only, there is
12289 no additional border below the possibly empty tool-bar lines.
12290 So to make the extra empty lines look "normal", we have to
12291 use the tool-bar face for the border too. */
12292 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12293 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12294 it
->face_id
= DEFAULT_FACE_ID
;
12296 extend_face_to_end_of_line (it
);
12297 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12298 last
->right_box_line_p
= true;
12299 if (last
== row
->glyphs
[TEXT_AREA
])
12300 last
->left_box_line_p
= true;
12302 /* Make line the desired height and center it vertically. */
12303 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12305 /* Don't add more than one line height. */
12306 height
%= FRAME_LINE_HEIGHT (it
->f
);
12307 it
->max_ascent
+= height
/ 2;
12308 it
->max_descent
+= (height
+ 1) / 2;
12311 compute_line_metrics (it
);
12313 /* If line is empty, make it occupy the rest of the tool-bar. */
12314 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12316 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12317 row
->visible_height
= row
->height
;
12318 row
->ascent
= row
->phys_ascent
= 0;
12319 row
->extra_line_spacing
= 0;
12322 row
->full_width_p
= true;
12323 row
->continued_p
= false;
12324 row
->truncated_on_left_p
= false;
12325 row
->truncated_on_right_p
= false;
12327 it
->current_x
= it
->hpos
= 0;
12328 it
->current_y
+= row
->height
;
12334 /* Value is the number of pixels needed to make all tool-bar items of
12335 frame F visible. The actual number of glyph rows needed is
12336 returned in *N_ROWS if non-NULL. */
12338 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12340 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12342 /* tool_bar_height is called from redisplay_tool_bar after building
12343 the desired matrix, so use (unused) mode-line row as temporary row to
12344 avoid destroying the first tool-bar row. */
12345 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12347 /* Initialize an iterator for iteration over
12348 F->desired_tool_bar_string in the tool-bar window of frame F. */
12349 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12350 temp_row
->reversed_p
= false;
12351 it
.first_visible_x
= 0;
12352 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12353 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12354 it
.paragraph_embedding
= L2R
;
12356 while (!ITERATOR_AT_END_P (&it
))
12358 clear_glyph_row (temp_row
);
12359 it
.glyph_row
= temp_row
;
12360 display_tool_bar_line (&it
, -1);
12362 clear_glyph_row (temp_row
);
12364 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12366 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12369 return it
.current_y
;
12371 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12374 #endif /* !USE_GTK && !HAVE_NS */
12376 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12378 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12379 If FRAME is nil or omitted, use the selected frame. Optional argument
12380 PIXELWISE non-nil means return the height of the tool bar in pixels. */)
12381 (Lisp_Object frame
, Lisp_Object pixelwise
)
12385 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12386 struct frame
*f
= decode_any_frame (frame
);
12388 if (WINDOWP (f
->tool_bar_window
)
12389 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12391 update_tool_bar (f
, true);
12392 if (f
->n_tool_bar_items
)
12394 build_desired_tool_bar_string (f
);
12395 height
= tool_bar_height (f
, NULL
, !NILP (pixelwise
));
12400 return make_number (height
);
12404 /* Display the tool-bar of frame F. Value is true if tool-bar's
12405 height should be changed. */
12407 redisplay_tool_bar (struct frame
*f
)
12409 f
->tool_bar_redisplayed
= true;
12410 #if defined (USE_GTK) || defined (HAVE_NS)
12412 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12413 update_frame_tool_bar (f
);
12416 #else /* !USE_GTK && !HAVE_NS */
12420 struct glyph_row
*row
;
12422 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12423 do anything. This means you must start with tool-bar-lines
12424 non-zero to get the auto-sizing effect. Or in other words, you
12425 can turn off tool-bars by specifying tool-bar-lines zero. */
12426 if (!WINDOWP (f
->tool_bar_window
)
12427 || (w
= XWINDOW (f
->tool_bar_window
),
12428 WINDOW_TOTAL_LINES (w
) == 0))
12431 /* Set up an iterator for the tool-bar window. */
12432 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12433 it
.first_visible_x
= 0;
12434 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12435 row
= it
.glyph_row
;
12436 row
->reversed_p
= false;
12438 /* Build a string that represents the contents of the tool-bar. */
12439 build_desired_tool_bar_string (f
);
12440 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12441 /* FIXME: This should be controlled by a user option. But it
12442 doesn't make sense to have an R2L tool bar if the menu bar cannot
12443 be drawn also R2L, and making the menu bar R2L is tricky due
12444 toolkit-specific code that implements it. If an R2L tool bar is
12445 ever supported, display_tool_bar_line should also be augmented to
12446 call unproduce_glyphs like display_line and display_string
12448 it
.paragraph_embedding
= L2R
;
12450 if (f
->n_tool_bar_rows
== 0)
12452 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, true);
12454 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12456 x_change_tool_bar_height (f
, new_height
);
12457 frame_default_tool_bar_height
= new_height
;
12458 /* Always do that now. */
12459 clear_glyph_matrix (w
->desired_matrix
);
12460 f
->fonts_changed
= true;
12465 /* Display as many lines as needed to display all tool-bar items. */
12467 if (f
->n_tool_bar_rows
> 0)
12469 int border
, rows
, height
, extra
;
12471 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12472 border
= XINT (Vtool_bar_border
);
12473 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12474 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12475 else if (EQ (Vtool_bar_border
, Qborder_width
))
12476 border
= f
->border_width
;
12482 rows
= f
->n_tool_bar_rows
;
12483 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12484 extra
= it
.last_visible_y
- border
- height
* rows
;
12486 while (it
.current_y
< it
.last_visible_y
)
12489 if (extra
> 0 && rows
-- > 0)
12491 h
= (extra
+ rows
- 1) / rows
;
12494 display_tool_bar_line (&it
, height
+ h
);
12499 while (it
.current_y
< it
.last_visible_y
)
12500 display_tool_bar_line (&it
, 0);
12503 /* It doesn't make much sense to try scrolling in the tool-bar
12504 window, so don't do it. */
12505 w
->desired_matrix
->no_scrolling_p
= true;
12506 w
->must_be_updated_p
= true;
12508 if (!NILP (Vauto_resize_tool_bars
))
12510 bool change_height_p
= true;
12512 /* If we couldn't display everything, change the tool-bar's
12513 height if there is room for more. */
12514 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
12515 change_height_p
= true;
12517 /* We subtract 1 because display_tool_bar_line advances the
12518 glyph_row pointer before returning to its caller. We want to
12519 examine the last glyph row produced by
12520 display_tool_bar_line. */
12521 row
= it
.glyph_row
- 1;
12523 /* If there are blank lines at the end, except for a partially
12524 visible blank line at the end that is smaller than
12525 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12526 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12527 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12528 change_height_p
= true;
12530 /* If row displays tool-bar items, but is partially visible,
12531 change the tool-bar's height. */
12532 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12533 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
12534 change_height_p
= true;
12536 /* Resize windows as needed by changing the `tool-bar-lines'
12537 frame parameter. */
12538 if (change_height_p
)
12541 int new_height
= tool_bar_height (f
, &nrows
, true);
12543 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12544 && !f
->minimize_tool_bar_window_p
)
12545 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12546 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12547 f
->minimize_tool_bar_window_p
= false;
12549 if (change_height_p
)
12551 x_change_tool_bar_height (f
, new_height
);
12552 frame_default_tool_bar_height
= new_height
;
12553 clear_glyph_matrix (w
->desired_matrix
);
12554 f
->n_tool_bar_rows
= nrows
;
12555 f
->fonts_changed
= true;
12562 f
->minimize_tool_bar_window_p
= false;
12565 #endif /* USE_GTK || HAVE_NS */
12568 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12570 /* Get information about the tool-bar item which is displayed in GLYPH
12571 on frame F. Return in *PROP_IDX the index where tool-bar item
12572 properties start in F->tool_bar_items. Value is false if
12573 GLYPH doesn't display a tool-bar item. */
12576 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12581 /* This function can be called asynchronously, which means we must
12582 exclude any possibility that Fget_text_property signals an
12584 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12585 charpos
= max (0, charpos
);
12587 /* Get the text property `menu-item' at pos. The value of that
12588 property is the start index of this item's properties in
12589 F->tool_bar_items. */
12590 prop
= Fget_text_property (make_number (charpos
),
12591 Qmenu_item
, f
->current_tool_bar_string
);
12592 if (! INTEGERP (prop
))
12594 *prop_idx
= XINT (prop
);
12599 /* Get information about the tool-bar item at position X/Y on frame F.
12600 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12601 the current matrix of the tool-bar window of F, or NULL if not
12602 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12603 item in F->tool_bar_items. Value is
12605 -1 if X/Y is not on a tool-bar item
12606 0 if X/Y is on the same item that was highlighted before.
12610 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12611 int *hpos
, int *vpos
, int *prop_idx
)
12613 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12614 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12617 /* Find the glyph under X/Y. */
12618 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12619 if (*glyph
== NULL
)
12622 /* Get the start of this tool-bar item's properties in
12623 f->tool_bar_items. */
12624 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12627 /* Is mouse on the highlighted item? */
12628 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12629 && *vpos
>= hlinfo
->mouse_face_beg_row
12630 && *vpos
<= hlinfo
->mouse_face_end_row
12631 && (*vpos
> hlinfo
->mouse_face_beg_row
12632 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12633 && (*vpos
< hlinfo
->mouse_face_end_row
12634 || *hpos
< hlinfo
->mouse_face_end_col
12635 || hlinfo
->mouse_face_past_end
))
12643 Handle mouse button event on the tool-bar of frame F, at
12644 frame-relative coordinates X/Y. DOWN_P is true for a button press,
12645 false for button release. MODIFIERS is event modifiers for button
12649 handle_tool_bar_click (struct frame
*f
, int x
, int y
, bool down_p
,
12652 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12653 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12654 int hpos
, vpos
, prop_idx
;
12655 struct glyph
*glyph
;
12656 Lisp_Object enabled_p
;
12659 /* If not on the highlighted tool-bar item, and mouse-highlight is
12660 non-nil, return. This is so we generate the tool-bar button
12661 click only when the mouse button is released on the same item as
12662 where it was pressed. However, when mouse-highlight is disabled,
12663 generate the click when the button is released regardless of the
12664 highlight, since tool-bar items are not highlighted in that
12666 frame_to_window_pixel_xy (w
, &x
, &y
);
12667 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12669 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12672 /* When mouse-highlight is off, generate the click for the item
12673 where the button was pressed, disregarding where it was
12675 if (NILP (Vmouse_highlight
) && !down_p
)
12676 prop_idx
= f
->last_tool_bar_item
;
12678 /* If item is disabled, do nothing. */
12679 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12680 if (NILP (enabled_p
))
12685 /* Show item in pressed state. */
12686 if (!NILP (Vmouse_highlight
))
12687 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12688 f
->last_tool_bar_item
= prop_idx
;
12692 Lisp_Object key
, frame
;
12693 struct input_event event
;
12694 EVENT_INIT (event
);
12696 /* Show item in released state. */
12697 if (!NILP (Vmouse_highlight
))
12698 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12700 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12702 XSETFRAME (frame
, f
);
12703 event
.kind
= TOOL_BAR_EVENT
;
12704 event
.frame_or_window
= frame
;
12706 kbd_buffer_store_event (&event
);
12708 event
.kind
= TOOL_BAR_EVENT
;
12709 event
.frame_or_window
= frame
;
12711 event
.modifiers
= modifiers
;
12712 kbd_buffer_store_event (&event
);
12713 f
->last_tool_bar_item
= -1;
12718 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12719 tool-bar window-relative coordinates X/Y. Called from
12720 note_mouse_highlight. */
12723 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12725 Lisp_Object window
= f
->tool_bar_window
;
12726 struct window
*w
= XWINDOW (window
);
12727 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12728 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12730 struct glyph
*glyph
;
12731 struct glyph_row
*row
;
12733 Lisp_Object enabled_p
;
12735 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12739 /* Function note_mouse_highlight is called with negative X/Y
12740 values when mouse moves outside of the frame. */
12741 if (x
<= 0 || y
<= 0)
12743 clear_mouse_face (hlinfo
);
12747 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12750 /* Not on tool-bar item. */
12751 clear_mouse_face (hlinfo
);
12755 /* On same tool-bar item as before. */
12756 goto set_help_echo
;
12758 clear_mouse_face (hlinfo
);
12760 /* Mouse is down, but on different tool-bar item? */
12761 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12762 && f
== dpyinfo
->last_mouse_frame
);
12764 if (mouse_down_p
&& f
->last_tool_bar_item
!= prop_idx
)
12767 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12769 /* If tool-bar item is not enabled, don't highlight it. */
12770 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12771 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12773 /* Compute the x-position of the glyph. In front and past the
12774 image is a space. We include this in the highlighted area. */
12775 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12776 for (i
= x
= 0; i
< hpos
; ++i
)
12777 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12779 /* Record this as the current active region. */
12780 hlinfo
->mouse_face_beg_col
= hpos
;
12781 hlinfo
->mouse_face_beg_row
= vpos
;
12782 hlinfo
->mouse_face_beg_x
= x
;
12783 hlinfo
->mouse_face_past_end
= false;
12785 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12786 hlinfo
->mouse_face_end_row
= vpos
;
12787 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12788 hlinfo
->mouse_face_window
= window
;
12789 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12791 /* Display it as active. */
12792 show_mouse_face (hlinfo
, draw
);
12797 /* Set help_echo_string to a help string to display for this tool-bar item.
12798 XTread_socket does the rest. */
12799 help_echo_object
= help_echo_window
= Qnil
;
12800 help_echo_pos
= -1;
12801 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12802 if (NILP (help_echo_string
))
12803 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12806 #endif /* !USE_GTK && !HAVE_NS */
12808 #endif /* HAVE_WINDOW_SYSTEM */
12812 /************************************************************************
12813 Horizontal scrolling
12814 ************************************************************************/
12816 /* For all leaf windows in the window tree rooted at WINDOW, set their
12817 hscroll value so that PT is (i) visible in the window, and (ii) so
12818 that it is not within a certain margin at the window's left and
12819 right border. Value is true if any window's hscroll has been
12823 hscroll_window_tree (Lisp_Object window
)
12825 bool hscrolled_p
= false;
12826 bool hscroll_relative_p
= FLOATP (Vhscroll_step
);
12827 int hscroll_step_abs
= 0;
12828 double hscroll_step_rel
= 0;
12830 if (hscroll_relative_p
)
12832 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12833 if (hscroll_step_rel
< 0)
12835 hscroll_relative_p
= false;
12836 hscroll_step_abs
= 0;
12839 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12841 hscroll_step_abs
= XINT (Vhscroll_step
);
12842 if (hscroll_step_abs
< 0)
12843 hscroll_step_abs
= 0;
12846 hscroll_step_abs
= 0;
12848 while (WINDOWP (window
))
12850 struct window
*w
= XWINDOW (window
);
12852 if (WINDOWP (w
->contents
))
12853 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12854 else if (w
->cursor
.vpos
>= 0)
12857 int text_area_width
;
12858 struct glyph_row
*cursor_row
;
12859 struct glyph_row
*bottom_row
;
12861 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->desired_matrix
, w
);
12862 if (w
->cursor
.vpos
< bottom_row
- w
->desired_matrix
->rows
)
12863 cursor_row
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12865 cursor_row
= bottom_row
- 1;
12867 if (!cursor_row
->enabled_p
)
12869 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12870 if (w
->cursor
.vpos
< bottom_row
- w
->current_matrix
->rows
)
12871 cursor_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12873 cursor_row
= bottom_row
- 1;
12875 bool row_r2l_p
= cursor_row
->reversed_p
;
12877 text_area_width
= window_box_width (w
, TEXT_AREA
);
12879 /* Scroll when cursor is inside this scroll margin. */
12880 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12882 /* If the position of this window's point has explicitly
12883 changed, no more suspend auto hscrolling. */
12884 if (NILP (Fequal (Fwindow_point (window
), Fwindow_old_point (window
))))
12885 w
->suspend_auto_hscroll
= false;
12887 /* Remember window point. */
12888 Fset_marker (w
->old_pointm
,
12889 ((w
== XWINDOW (selected_window
))
12890 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
12891 : Fmarker_position (w
->pointm
)),
12894 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12895 && !w
->suspend_auto_hscroll
12896 /* In some pathological cases, like restoring a window
12897 configuration into a frame that is much smaller than
12898 the one from which the configuration was saved, we
12899 get glyph rows whose start and end have zero buffer
12900 positions, which we cannot handle below. Just skip
12902 && CHARPOS (cursor_row
->start
.pos
) >= BUF_BEG (w
->contents
)
12903 /* For left-to-right rows, hscroll when cursor is either
12904 (i) inside the right hscroll margin, or (ii) if it is
12905 inside the left margin and the window is already
12908 && ((w
->hscroll
&& w
->cursor
.x
<= h_margin
)
12909 || (cursor_row
->enabled_p
12910 && cursor_row
->truncated_on_right_p
12911 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12912 /* For right-to-left rows, the logic is similar,
12913 except that rules for scrolling to left and right
12914 are reversed. E.g., if cursor.x <= h_margin, we
12915 need to hscroll "to the right" unconditionally,
12916 and that will scroll the screen to the left so as
12917 to reveal the next portion of the row. */
12919 && ((cursor_row
->enabled_p
12920 /* FIXME: It is confusing to set the
12921 truncated_on_right_p flag when R2L rows
12922 are actually truncated on the left. */
12923 && cursor_row
->truncated_on_right_p
12924 && w
->cursor
.x
<= h_margin
)
12926 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12930 struct buffer
*saved_current_buffer
;
12934 /* Find point in a display of infinite width. */
12935 saved_current_buffer
= current_buffer
;
12936 current_buffer
= XBUFFER (w
->contents
);
12938 if (w
== XWINDOW (selected_window
))
12941 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12943 /* Move iterator to pt starting at cursor_row->start in
12944 a line with infinite width. */
12945 init_to_row_start (&it
, w
, cursor_row
);
12946 it
.last_visible_x
= INFINITY
;
12947 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12948 current_buffer
= saved_current_buffer
;
12950 /* Position cursor in window. */
12951 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12952 hscroll
= max (0, (it
.current_x
12953 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12954 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12955 : (text_area_width
/ 2))))
12956 / FRAME_COLUMN_WIDTH (it
.f
);
12957 else if ((!row_r2l_p
12958 && w
->cursor
.x
>= text_area_width
- h_margin
)
12959 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12961 if (hscroll_relative_p
)
12962 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12965 wanted_x
= text_area_width
12966 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12969 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12973 if (hscroll_relative_p
)
12974 wanted_x
= text_area_width
* hscroll_step_rel
12977 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12980 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12982 hscroll
= max (hscroll
, w
->min_hscroll
);
12984 /* Don't prevent redisplay optimizations if hscroll
12985 hasn't changed, as it will unnecessarily slow down
12987 if (w
->hscroll
!= hscroll
)
12989 struct buffer
*b
= XBUFFER (w
->contents
);
12990 b
->prevent_redisplay_optimizations_p
= true;
12991 w
->hscroll
= hscroll
;
12992 hscrolled_p
= true;
13000 /* Value is true if hscroll of any leaf window has been changed. */
13001 return hscrolled_p
;
13005 /* Set hscroll so that cursor is visible and not inside horizontal
13006 scroll margins for all windows in the tree rooted at WINDOW. See
13007 also hscroll_window_tree above. Value is true if any window's
13008 hscroll has been changed. If it has, desired matrices on the frame
13009 of WINDOW are cleared. */
13012 hscroll_windows (Lisp_Object window
)
13014 bool hscrolled_p
= hscroll_window_tree (window
);
13016 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
13017 return hscrolled_p
;
13022 /************************************************************************
13024 ************************************************************************/
13026 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined.
13027 This is sometimes handy to have in a debugger session. */
13031 /* First and last unchanged row for try_window_id. */
13033 static int debug_first_unchanged_at_end_vpos
;
13034 static int debug_last_unchanged_at_beg_vpos
;
13036 /* Delta vpos and y. */
13038 static int debug_dvpos
, debug_dy
;
13040 /* Delta in characters and bytes for try_window_id. */
13042 static ptrdiff_t debug_delta
, debug_delta_bytes
;
13044 /* Values of window_end_pos and window_end_vpos at the end of
13047 static ptrdiff_t debug_end_vpos
;
13049 /* Append a string to W->desired_matrix->method. FMT is a printf
13050 format string. If trace_redisplay_p is true also printf the
13051 resulting string to stderr. */
13053 static void debug_method_add (struct window
*, char const *, ...)
13054 ATTRIBUTE_FORMAT_PRINTF (2, 3);
13057 debug_method_add (struct window
*w
, char const *fmt
, ...)
13060 char *method
= w
->desired_matrix
->method
;
13061 int len
= strlen (method
);
13062 int size
= sizeof w
->desired_matrix
->method
;
13063 int remaining
= size
- len
- 1;
13066 if (len
&& remaining
)
13069 --remaining
, ++len
;
13072 va_start (ap
, fmt
);
13073 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
13076 if (trace_redisplay_p
)
13077 fprintf (stderr
, "%p (%s): %s\n",
13079 ((BUFFERP (w
->contents
)
13080 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
13081 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
13086 #endif /* GLYPH_DEBUG */
13089 /* Value is true if all changes in window W, which displays
13090 current_buffer, are in the text between START and END. START is a
13091 buffer position, END is given as a distance from Z. Used in
13092 redisplay_internal for display optimization. */
13095 text_outside_line_unchanged_p (struct window
*w
,
13096 ptrdiff_t start
, ptrdiff_t end
)
13098 bool unchanged_p
= true;
13100 /* If text or overlays have changed, see where. */
13101 if (window_outdated (w
))
13103 /* Gap in the line? */
13104 if (GPT
< start
|| Z
- GPT
< end
)
13105 unchanged_p
= false;
13107 /* Changes start in front of the line, or end after it? */
13109 && (BEG_UNCHANGED
< start
- 1
13110 || END_UNCHANGED
< end
))
13111 unchanged_p
= false;
13113 /* If selective display, can't optimize if changes start at the
13114 beginning of the line. */
13116 && INTEGERP (BVAR (current_buffer
, selective_display
))
13117 && XINT (BVAR (current_buffer
, selective_display
)) > 0
13118 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
13119 unchanged_p
= false;
13121 /* If there are overlays at the start or end of the line, these
13122 may have overlay strings with newlines in them. A change at
13123 START, for instance, may actually concern the display of such
13124 overlay strings as well, and they are displayed on different
13125 lines. So, quickly rule out this case. (For the future, it
13126 might be desirable to implement something more telling than
13127 just BEG/END_UNCHANGED.) */
13130 if (BEG
+ BEG_UNCHANGED
== start
13131 && overlay_touches_p (start
))
13132 unchanged_p
= false;
13133 if (END_UNCHANGED
== end
13134 && overlay_touches_p (Z
- end
))
13135 unchanged_p
= false;
13138 /* Under bidi reordering, adding or deleting a character in the
13139 beginning of a paragraph, before the first strong directional
13140 character, can change the base direction of the paragraph (unless
13141 the buffer specifies a fixed paragraph direction), which will
13142 require to redisplay the whole paragraph. It might be worthwhile
13143 to find the paragraph limits and widen the range of redisplayed
13144 lines to that, but for now just give up this optimization. */
13145 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
13146 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
13147 unchanged_p
= false;
13150 return unchanged_p
;
13154 /* Do a frame update, taking possible shortcuts into account. This is
13155 the main external entry point for redisplay.
13157 If the last redisplay displayed an echo area message and that message
13158 is no longer requested, we clear the echo area or bring back the
13159 mini-buffer if that is in use. */
13164 redisplay_internal ();
13169 overlay_arrow_string_or_property (Lisp_Object var
)
13173 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
13176 return Voverlay_arrow_string
;
13179 /* Return true if there are any overlay-arrows in current_buffer. */
13181 overlay_arrow_in_current_buffer_p (void)
13185 for (vlist
= Voverlay_arrow_variable_list
;
13187 vlist
= XCDR (vlist
))
13189 Lisp_Object var
= XCAR (vlist
);
13192 if (!SYMBOLP (var
))
13194 val
= find_symbol_value (var
);
13196 && current_buffer
== XMARKER (val
)->buffer
)
13203 /* Return true if any overlay_arrows have moved or overlay-arrow-string
13207 overlay_arrows_changed_p (void)
13211 for (vlist
= Voverlay_arrow_variable_list
;
13213 vlist
= XCDR (vlist
))
13215 Lisp_Object var
= XCAR (vlist
);
13216 Lisp_Object val
, pstr
;
13218 if (!SYMBOLP (var
))
13220 val
= find_symbol_value (var
);
13221 if (!MARKERP (val
))
13223 if (! EQ (COERCE_MARKER (val
),
13224 Fget (var
, Qlast_arrow_position
))
13225 || ! (pstr
= overlay_arrow_string_or_property (var
),
13226 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
13232 /* Mark overlay arrows to be updated on next redisplay. */
13235 update_overlay_arrows (int up_to_date
)
13239 for (vlist
= Voverlay_arrow_variable_list
;
13241 vlist
= XCDR (vlist
))
13243 Lisp_Object var
= XCAR (vlist
);
13245 if (!SYMBOLP (var
))
13248 if (up_to_date
> 0)
13250 Lisp_Object val
= find_symbol_value (var
);
13251 Fput (var
, Qlast_arrow_position
,
13252 COERCE_MARKER (val
));
13253 Fput (var
, Qlast_arrow_string
,
13254 overlay_arrow_string_or_property (var
));
13256 else if (up_to_date
< 0
13257 || !NILP (Fget (var
, Qlast_arrow_position
)))
13259 Fput (var
, Qlast_arrow_position
, Qt
);
13260 Fput (var
, Qlast_arrow_string
, Qt
);
13266 /* Return overlay arrow string to display at row.
13267 Return integer (bitmap number) for arrow bitmap in left fringe.
13268 Return nil if no overlay arrow. */
13271 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
13275 for (vlist
= Voverlay_arrow_variable_list
;
13277 vlist
= XCDR (vlist
))
13279 Lisp_Object var
= XCAR (vlist
);
13282 if (!SYMBOLP (var
))
13285 val
= find_symbol_value (var
);
13288 && current_buffer
== XMARKER (val
)->buffer
13289 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13291 if (FRAME_WINDOW_P (it
->f
)
13292 /* FIXME: if ROW->reversed_p is set, this should test
13293 the right fringe, not the left one. */
13294 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13296 #ifdef HAVE_WINDOW_SYSTEM
13297 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13299 int fringe_bitmap
= lookup_fringe_bitmap (val
);
13300 if (fringe_bitmap
!= 0)
13301 return make_number (fringe_bitmap
);
13304 return make_number (-1); /* Use default arrow bitmap. */
13306 return overlay_arrow_string_or_property (var
);
13313 /* Return true if point moved out of or into a composition. Otherwise
13314 return false. PREV_BUF and PREV_PT are the last point buffer and
13315 position. BUF and PT are the current point buffer and position. */
13318 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13319 struct buffer
*buf
, ptrdiff_t pt
)
13321 ptrdiff_t start
, end
;
13323 Lisp_Object buffer
;
13325 XSETBUFFER (buffer
, buf
);
13326 /* Check a composition at the last point if point moved within the
13328 if (prev_buf
== buf
)
13331 /* Point didn't move. */
13334 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13335 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13336 && composition_valid_p (start
, end
, prop
)
13337 && start
< prev_pt
&& end
> prev_pt
)
13338 /* The last point was within the composition. Return true iff
13339 point moved out of the composition. */
13340 return (pt
<= start
|| pt
>= end
);
13343 /* Check a composition at the current point. */
13344 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13345 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13346 && composition_valid_p (start
, end
, prop
)
13347 && start
< pt
&& end
> pt
);
13350 /* Reconsider the clip changes of buffer which is displayed in W. */
13353 reconsider_clip_changes (struct window
*w
)
13355 struct buffer
*b
= XBUFFER (w
->contents
);
13357 if (b
->clip_changed
13358 && w
->window_end_valid
13359 && w
->current_matrix
->buffer
== b
13360 && w
->current_matrix
->zv
== BUF_ZV (b
)
13361 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13362 b
->clip_changed
= false;
13364 /* If display wasn't paused, and W is not a tool bar window, see if
13365 point has been moved into or out of a composition. In that case,
13366 set b->clip_changed to force updating the screen. If
13367 b->clip_changed has already been set, skip this check. */
13368 if (!b
->clip_changed
&& w
->window_end_valid
)
13370 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13371 ? PT
: marker_position (w
->pointm
));
13373 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13374 && check_point_in_composition (w
->current_matrix
->buffer
,
13375 w
->last_point
, b
, pt
))
13376 b
->clip_changed
= true;
13381 propagate_buffer_redisplay (void)
13382 { /* Resetting b->text->redisplay is problematic!
13383 We can't just reset it in the case that some window that displays
13384 it has not been redisplayed; and such a window can stay
13385 unredisplayed for a long time if it's currently invisible.
13386 But we do want to reset it at the end of redisplay otherwise
13387 its displayed windows will keep being redisplayed over and over
13389 So we copy all b->text->redisplay flags up to their windows here,
13390 such that mark_window_display_accurate can safely reset
13391 b->text->redisplay. */
13392 Lisp_Object ws
= window_list ();
13393 for (; CONSP (ws
); ws
= XCDR (ws
))
13395 struct window
*thisw
= XWINDOW (XCAR (ws
));
13396 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13397 if (thisb
->text
->redisplay
)
13398 thisw
->redisplay
= true;
13402 #define STOP_POLLING \
13403 do { if (! polling_stopped_here) stop_polling (); \
13404 polling_stopped_here = true; } while (false)
13406 #define RESUME_POLLING \
13407 do { if (polling_stopped_here) start_polling (); \
13408 polling_stopped_here = false; } while (false)
13411 /* Perhaps in the future avoid recentering windows if it
13412 is not necessary; currently that causes some problems. */
13415 redisplay_internal (void)
13417 struct window
*w
= XWINDOW (selected_window
);
13421 bool must_finish
= false, match_p
;
13422 struct text_pos tlbufpos
, tlendpos
;
13423 int number_of_visible_frames
;
13426 bool polling_stopped_here
= false;
13427 Lisp_Object tail
, frame
;
13429 /* True means redisplay has to consider all windows on all
13430 frames. False, only selected_window is considered. */
13431 bool consider_all_windows_p
;
13433 /* True means redisplay has to redisplay the miniwindow. */
13434 bool update_miniwindow_p
= false;
13436 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13438 /* No redisplay if running in batch mode or frame is not yet fully
13439 initialized, or redisplay is explicitly turned off by setting
13440 Vinhibit_redisplay. */
13441 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13442 || !NILP (Vinhibit_redisplay
))
13445 /* Don't examine these until after testing Vinhibit_redisplay.
13446 When Emacs is shutting down, perhaps because its connection to
13447 X has dropped, we should not look at them at all. */
13448 fr
= XFRAME (w
->frame
);
13449 sf
= SELECTED_FRAME ();
13451 if (!fr
->glyphs_initialized_p
)
13454 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13455 if (popup_activated ())
13459 /* I don't think this happens but let's be paranoid. */
13460 if (redisplaying_p
)
13463 /* Record a function that clears redisplaying_p
13464 when we leave this function. */
13465 count
= SPECPDL_INDEX ();
13466 record_unwind_protect_void (unwind_redisplay
);
13467 redisplaying_p
= true;
13468 specbind (Qinhibit_free_realized_faces
, Qnil
);
13470 /* Record this function, so it appears on the profiler's backtraces. */
13471 record_in_backtrace (Qredisplay_internal
, 0, 0);
13473 FOR_EACH_FRAME (tail
, frame
)
13474 XFRAME (frame
)->already_hscrolled_p
= false;
13477 /* Remember the currently selected window. */
13481 forget_escape_and_glyphless_faces ();
13483 inhibit_free_realized_faces
= false;
13485 /* If face_change, init_iterator will free all realized faces, which
13486 includes the faces referenced from current matrices. So, we
13487 can't reuse current matrices in this case. */
13489 windows_or_buffers_changed
= 47;
13491 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13492 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13494 /* Since frames on a single ASCII terminal share the same
13495 display area, displaying a different frame means redisplay
13496 the whole thing. */
13497 SET_FRAME_GARBAGED (sf
);
13499 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13501 FRAME_TTY (sf
)->previous_frame
= sf
;
13504 /* Set the visible flags for all frames. Do this before checking for
13505 resized or garbaged frames; they want to know if their frames are
13506 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13507 number_of_visible_frames
= 0;
13509 FOR_EACH_FRAME (tail
, frame
)
13511 struct frame
*f
= XFRAME (frame
);
13513 if (FRAME_VISIBLE_P (f
))
13515 ++number_of_visible_frames
;
13516 /* Adjust matrices for visible frames only. */
13517 if (f
->fonts_changed
)
13519 adjust_frame_glyphs (f
);
13520 /* Disable all redisplay optimizations for this frame.
13521 This is because adjust_frame_glyphs resets the
13522 enabled_p flag for all glyph rows of all windows, so
13523 many optimizations will fail anyway, and some might
13524 fail to test that flag and do bogus things as
13526 SET_FRAME_GARBAGED (f
);
13527 f
->fonts_changed
= false;
13529 /* If cursor type has been changed on the frame
13530 other than selected, consider all frames. */
13531 if (f
!= sf
&& f
->cursor_type_changed
)
13532 fset_redisplay (f
);
13534 clear_desired_matrices (f
);
13537 /* Notice any pending interrupt request to change frame size. */
13538 do_pending_window_change (true);
13540 /* do_pending_window_change could change the selected_window due to
13541 frame resizing which makes the selected window too small. */
13542 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13545 /* Clear frames marked as garbaged. */
13546 clear_garbaged_frames ();
13548 /* Build menubar and tool-bar items. */
13549 if (NILP (Vmemory_full
))
13550 prepare_menu_bars ();
13552 reconsider_clip_changes (w
);
13554 /* In most cases selected window displays current buffer. */
13555 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13558 /* Detect case that we need to write or remove a star in the mode line. */
13559 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13560 w
->update_mode_line
= true;
13562 if (mode_line_update_needed (w
))
13563 w
->update_mode_line
= true;
13565 /* If reconsider_clip_changes above decided that the narrowing
13566 in the current buffer changed, make sure all other windows
13567 showing that buffer will be redisplayed. */
13568 if (current_buffer
->clip_changed
)
13569 bset_update_mode_line (current_buffer
);
13572 /* Normally the message* functions will have already displayed and
13573 updated the echo area, but the frame may have been trashed, or
13574 the update may have been preempted, so display the echo area
13575 again here. Checking message_cleared_p captures the case that
13576 the echo area should be cleared. */
13577 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13578 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13579 || (message_cleared_p
13580 && minibuf_level
== 0
13581 /* If the mini-window is currently selected, this means the
13582 echo-area doesn't show through. */
13583 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13585 echo_area_display (false);
13587 /* If echo_area_display resizes the mini-window, the redisplay and
13588 window_sizes_changed flags of the selected frame are set, but
13589 it's too late for the hooks in window-size-change-functions,
13590 which have been examined already in prepare_menu_bars. So in
13591 that case we call the hooks here only for the selected frame. */
13592 if (sf
->redisplay
&& FRAME_WINDOW_SIZES_CHANGED (sf
))
13594 Lisp_Object functions
;
13595 ptrdiff_t count1
= SPECPDL_INDEX ();
13597 record_unwind_save_match_data ();
13599 /* Clear flag first in case we get an error below. */
13600 FRAME_WINDOW_SIZES_CHANGED (sf
) = false;
13601 functions
= Vwindow_size_change_functions
;
13603 while (CONSP (functions
))
13605 if (!EQ (XCAR (functions
), Qt
))
13606 call1 (XCAR (functions
), selected_frame
);
13607 functions
= XCDR (functions
);
13610 unbind_to (count1
, Qnil
);
13613 if (message_cleared_p
)
13614 update_miniwindow_p
= true;
13616 must_finish
= true;
13618 /* If we don't display the current message, don't clear the
13619 message_cleared_p flag, because, if we did, we wouldn't clear
13620 the echo area in the next redisplay which doesn't preserve
13622 if (!display_last_displayed_message_p
)
13623 message_cleared_p
= false;
13625 else if (EQ (selected_window
, minibuf_window
)
13626 && (current_buffer
->clip_changed
|| window_outdated (w
))
13627 && resize_mini_window (w
, false))
13631 Lisp_Object functions
;
13632 ptrdiff_t count1
= SPECPDL_INDEX ();
13634 record_unwind_save_match_data ();
13636 /* Clear flag first in case we get an error below. */
13637 FRAME_WINDOW_SIZES_CHANGED (sf
) = false;
13638 functions
= Vwindow_size_change_functions
;
13640 while (CONSP (functions
))
13642 if (!EQ (XCAR (functions
), Qt
))
13643 call1 (XCAR (functions
), selected_frame
);
13644 functions
= XCDR (functions
);
13647 unbind_to (count1
, Qnil
);
13650 /* Resized active mini-window to fit the size of what it is
13651 showing if its contents might have changed. */
13652 must_finish
= true;
13654 /* If window configuration was changed, frames may have been
13655 marked garbaged. Clear them or we will experience
13656 surprises wrt scrolling. */
13657 clear_garbaged_frames ();
13660 if (windows_or_buffers_changed
&& !update_mode_lines
)
13661 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13662 only the windows's contents needs to be refreshed, or whether the
13663 mode-lines also need a refresh. */
13664 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13665 ? REDISPLAY_SOME
: 32);
13667 /* If specs for an arrow have changed, do thorough redisplay
13668 to ensure we remove any arrow that should no longer exist. */
13669 if (overlay_arrows_changed_p ())
13670 /* Apparently, this is the only case where we update other windows,
13671 without updating other mode-lines. */
13672 windows_or_buffers_changed
= 49;
13674 consider_all_windows_p
= (update_mode_lines
13675 || windows_or_buffers_changed
);
13677 #define AINC(a,i) \
13679 Lisp_Object entry = Fgethash (make_number (i), a, make_number (0)); \
13680 if (INTEGERP (entry)) \
13681 Fputhash (make_number (i), make_number (1 + XINT (entry)), a); \
13684 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13685 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13687 /* Optimize the case that only the line containing the cursor in the
13688 selected window has changed. Variables starting with this_ are
13689 set in display_line and record information about the line
13690 containing the cursor. */
13691 tlbufpos
= this_line_start_pos
;
13692 tlendpos
= this_line_end_pos
;
13693 if (!consider_all_windows_p
13694 && CHARPOS (tlbufpos
) > 0
13695 && !w
->update_mode_line
13696 && !current_buffer
->clip_changed
13697 && !current_buffer
->prevent_redisplay_optimizations_p
13698 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13699 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13700 && !XFRAME (w
->frame
)->cursor_type_changed
13701 && !XFRAME (w
->frame
)->face_change
13702 /* Make sure recorded data applies to current buffer, etc. */
13703 && this_line_buffer
== current_buffer
13706 && !w
->optional_new_start
13707 /* Point must be on the line that we have info recorded about. */
13708 && PT
>= CHARPOS (tlbufpos
)
13709 && PT
<= Z
- CHARPOS (tlendpos
)
13710 /* All text outside that line, including its final newline,
13711 must be unchanged. */
13712 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13713 CHARPOS (tlendpos
)))
13715 if (CHARPOS (tlbufpos
) > BEGV
13716 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13717 && (CHARPOS (tlbufpos
) == ZV
13718 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13719 /* Former continuation line has disappeared by becoming empty. */
13721 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13723 /* We have to handle the case of continuation around a
13724 wide-column character (see the comment in indent.c around
13727 For instance, in the following case:
13729 -------- Insert --------
13730 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13731 J_I_ ==> J_I_ `^^' are cursors.
13735 As we have to redraw the line above, we cannot use this
13739 int line_height_before
= this_line_pixel_height
;
13741 /* Note that start_display will handle the case that the
13742 line starting at tlbufpos is a continuation line. */
13743 start_display (&it
, w
, tlbufpos
);
13745 /* Implementation note: It this still necessary? */
13746 if (it
.current_x
!= this_line_start_x
)
13749 TRACE ((stderr
, "trying display optimization 1\n"));
13750 w
->cursor
.vpos
= -1;
13751 overlay_arrow_seen
= false;
13752 it
.vpos
= this_line_vpos
;
13753 it
.current_y
= this_line_y
;
13754 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13755 display_line (&it
);
13757 /* If line contains point, is not continued,
13758 and ends at same distance from eob as before, we win. */
13759 if (w
->cursor
.vpos
>= 0
13760 /* Line is not continued, otherwise this_line_start_pos
13761 would have been set to 0 in display_line. */
13762 && CHARPOS (this_line_start_pos
)
13763 /* Line ends as before. */
13764 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13765 /* Line has same height as before. Otherwise other lines
13766 would have to be shifted up or down. */
13767 && this_line_pixel_height
== line_height_before
)
13769 /* If this is not the window's last line, we must adjust
13770 the charstarts of the lines below. */
13771 if (it
.current_y
< it
.last_visible_y
)
13773 struct glyph_row
*row
13774 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13775 ptrdiff_t delta
, delta_bytes
;
13777 /* We used to distinguish between two cases here,
13778 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13779 when the line ends in a newline or the end of the
13780 buffer's accessible portion. But both cases did
13781 the same, so they were collapsed. */
13783 - CHARPOS (tlendpos
)
13784 - MATRIX_ROW_START_CHARPOS (row
));
13785 delta_bytes
= (Z_BYTE
13786 - BYTEPOS (tlendpos
)
13787 - MATRIX_ROW_START_BYTEPOS (row
));
13789 increment_matrix_positions (w
->current_matrix
,
13790 this_line_vpos
+ 1,
13791 w
->current_matrix
->nrows
,
13792 delta
, delta_bytes
);
13795 /* If this row displays text now but previously didn't,
13796 or vice versa, w->window_end_vpos may have to be
13798 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13800 if (w
->window_end_vpos
< this_line_vpos
)
13801 w
->window_end_vpos
= this_line_vpos
;
13803 else if (w
->window_end_vpos
== this_line_vpos
13804 && this_line_vpos
> 0)
13805 w
->window_end_vpos
= this_line_vpos
- 1;
13806 w
->window_end_valid
= false;
13808 /* Update hint: No need to try to scroll in update_window. */
13809 w
->desired_matrix
->no_scrolling_p
= true;
13812 *w
->desired_matrix
->method
= 0;
13813 debug_method_add (w
, "optimization 1");
13815 #ifdef HAVE_WINDOW_SYSTEM
13816 update_window_fringes (w
, false);
13823 else if (/* Cursor position hasn't changed. */
13824 PT
== w
->last_point
13825 /* Make sure the cursor was last displayed
13826 in this window. Otherwise we have to reposition it. */
13828 /* PXW: Must be converted to pixels, probably. */
13829 && 0 <= w
->cursor
.vpos
13830 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13834 do_pending_window_change (true);
13835 /* If selected_window changed, redisplay again. */
13836 if (WINDOWP (selected_window
)
13837 && (w
= XWINDOW (selected_window
)) != sw
)
13840 /* We used to always goto end_of_redisplay here, but this
13841 isn't enough if we have a blinking cursor. */
13842 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13843 goto end_of_redisplay
;
13847 /* If highlighting the region, or if the cursor is in the echo area,
13848 then we can't just move the cursor. */
13849 else if (NILP (Vshow_trailing_whitespace
)
13850 && !cursor_in_echo_area
)
13853 struct glyph_row
*row
;
13855 /* Skip from tlbufpos to PT and see where it is. Note that
13856 PT may be in invisible text. If so, we will end at the
13857 next visible position. */
13858 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13859 NULL
, DEFAULT_FACE_ID
);
13860 it
.current_x
= this_line_start_x
;
13861 it
.current_y
= this_line_y
;
13862 it
.vpos
= this_line_vpos
;
13864 /* The call to move_it_to stops in front of PT, but
13865 moves over before-strings. */
13866 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13868 if (it
.vpos
== this_line_vpos
13869 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13872 eassert (this_line_vpos
== it
.vpos
);
13873 eassert (this_line_y
== it
.current_y
);
13874 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13876 *w
->desired_matrix
->method
= 0;
13877 debug_method_add (w
, "optimization 3");
13886 /* Text changed drastically or point moved off of line. */
13887 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13890 CHARPOS (this_line_start_pos
) = 0;
13891 ++clear_face_cache_count
;
13892 #ifdef HAVE_WINDOW_SYSTEM
13893 ++clear_image_cache_count
;
13896 /* Build desired matrices, and update the display. If
13897 consider_all_windows_p, do it for all windows on all frames that
13898 require redisplay, as specified by their 'redisplay' flag.
13899 Otherwise do it for selected_window, only. */
13901 if (consider_all_windows_p
)
13903 FOR_EACH_FRAME (tail
, frame
)
13904 XFRAME (frame
)->updated_p
= false;
13906 propagate_buffer_redisplay ();
13908 FOR_EACH_FRAME (tail
, frame
)
13910 struct frame
*f
= XFRAME (frame
);
13912 /* We don't have to do anything for unselected terminal
13914 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13915 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13919 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13922 /* Only GC scrollbars when we redisplay the whole frame. */
13923 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13924 bool f_redisplay_flag
= f
->redisplay
;
13925 /* Mark all the scroll bars to be removed; we'll redeem
13926 the ones we want when we redisplay their windows. */
13927 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13928 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13930 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13931 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13932 /* Remember that the invisible frames need to be redisplayed next
13933 time they're visible. */
13934 else if (!REDISPLAY_SOME_P ())
13935 f
->redisplay
= true;
13937 /* The X error handler may have deleted that frame. */
13938 if (!FRAME_LIVE_P (f
))
13941 /* Any scroll bars which redisplay_windows should have
13942 nuked should now go away. */
13943 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13944 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13946 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13948 /* If fonts changed on visible frame, display again. */
13949 if (f
->fonts_changed
)
13951 adjust_frame_glyphs (f
);
13952 /* Disable all redisplay optimizations for this
13953 frame. For the reasons, see the comment near
13954 the previous call to adjust_frame_glyphs above. */
13955 SET_FRAME_GARBAGED (f
);
13956 f
->fonts_changed
= false;
13960 /* See if we have to hscroll. */
13961 if (!f
->already_hscrolled_p
)
13963 f
->already_hscrolled_p
= true;
13964 if (hscroll_windows (f
->root_window
))
13968 /* If the frame's redisplay flag was not set before
13969 we went about redisplaying its windows, but it is
13970 set now, that means we employed some redisplay
13971 optimizations inside redisplay_windows, and
13972 bypassed producing some screen lines. But if
13973 f->redisplay is now set, it might mean the old
13974 faces are no longer valid (e.g., if redisplaying
13975 some window called some Lisp which defined a new
13976 face or redefined an existing face), so trying to
13977 use them in update_frame will segfault.
13978 Therefore, we must redisplay this frame. */
13979 if (!f_redisplay_flag
&& f
->redisplay
)
13982 /* Prevent various kinds of signals during display
13983 update. stdio is not robust about handling
13984 signals, which can cause an apparent I/O error. */
13985 if (interrupt_input
)
13986 unrequest_sigio ();
13989 pending
|= update_frame (f
, false, false);
13990 f
->cursor_type_changed
= false;
13991 f
->updated_p
= true;
13996 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
14000 /* Do the mark_window_display_accurate after all windows have
14001 been redisplayed because this call resets flags in buffers
14002 which are needed for proper redisplay. */
14003 FOR_EACH_FRAME (tail
, frame
)
14005 struct frame
*f
= XFRAME (frame
);
14008 f
->redisplay
= false;
14009 mark_window_display_accurate (f
->root_window
, true);
14010 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
14011 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
14016 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
14018 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
14019 struct frame
*mini_frame
;
14021 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
14022 /* Use list_of_error, not Qerror, so that
14023 we catch only errors and don't run the debugger. */
14024 internal_condition_case_1 (redisplay_window_1
, selected_window
,
14026 redisplay_window_error
);
14027 if (update_miniwindow_p
)
14028 internal_condition_case_1 (redisplay_window_1
, mini_window
,
14030 redisplay_window_error
);
14032 /* Compare desired and current matrices, perform output. */
14035 /* If fonts changed, display again. Likewise if redisplay_window_1
14036 above caused some change (e.g., a change in faces) that requires
14037 considering the entire frame again. */
14038 if (sf
->fonts_changed
|| sf
->redisplay
)
14042 /* Set this to force a more thorough redisplay.
14043 Otherwise, we might immediately loop back to the
14044 above "else-if" clause (since all the conditions that
14045 led here might still be true), and we will then
14046 infloop, because the selected-frame's redisplay flag
14047 is not (and cannot be) reset. */
14048 windows_or_buffers_changed
= 50;
14053 /* Prevent freeing of realized faces, since desired matrices are
14054 pending that reference the faces we computed and cached. */
14055 inhibit_free_realized_faces
= true;
14057 /* Prevent various kinds of signals during display update.
14058 stdio is not robust about handling signals,
14059 which can cause an apparent I/O error. */
14060 if (interrupt_input
)
14061 unrequest_sigio ();
14064 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
14066 if (hscroll_windows (selected_window
))
14069 XWINDOW (selected_window
)->must_be_updated_p
= true;
14070 pending
= update_frame (sf
, false, false);
14071 sf
->cursor_type_changed
= false;
14074 /* We may have called echo_area_display at the top of this
14075 function. If the echo area is on another frame, that may
14076 have put text on a frame other than the selected one, so the
14077 above call to update_frame would not have caught it. Catch
14079 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
14080 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
14082 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
14084 XWINDOW (mini_window
)->must_be_updated_p
= true;
14085 pending
|= update_frame (mini_frame
, false, false);
14086 mini_frame
->cursor_type_changed
= false;
14087 if (!pending
&& hscroll_windows (mini_window
))
14092 /* If display was paused because of pending input, make sure we do a
14093 thorough update the next time. */
14096 /* Prevent the optimization at the beginning of
14097 redisplay_internal that tries a single-line update of the
14098 line containing the cursor in the selected window. */
14099 CHARPOS (this_line_start_pos
) = 0;
14101 /* Let the overlay arrow be updated the next time. */
14102 update_overlay_arrows (0);
14104 /* If we pause after scrolling, some rows in the current
14105 matrices of some windows are not valid. */
14106 if (!WINDOW_FULL_WIDTH_P (w
)
14107 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
14108 update_mode_lines
= 36;
14112 if (!consider_all_windows_p
)
14114 /* This has already been done above if
14115 consider_all_windows_p is set. */
14116 if (XBUFFER (w
->contents
)->text
->redisplay
14117 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
14118 /* This can happen if b->text->redisplay was set during
14120 propagate_buffer_redisplay ();
14121 mark_window_display_accurate_1 (w
, true);
14123 /* Say overlay arrows are up to date. */
14124 update_overlay_arrows (1);
14126 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
14127 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
14130 update_mode_lines
= 0;
14131 windows_or_buffers_changed
= 0;
14134 /* Start SIGIO interrupts coming again. Having them off during the
14135 code above makes it less likely one will discard output, but not
14136 impossible, since there might be stuff in the system buffer here.
14137 But it is much hairier to try to do anything about that. */
14138 if (interrupt_input
)
14142 /* If a frame has become visible which was not before, redisplay
14143 again, so that we display it. Expose events for such a frame
14144 (which it gets when becoming visible) don't call the parts of
14145 redisplay constructing glyphs, so simply exposing a frame won't
14146 display anything in this case. So, we have to display these
14147 frames here explicitly. */
14152 FOR_EACH_FRAME (tail
, frame
)
14154 if (XFRAME (frame
)->visible
)
14158 if (new_count
!= number_of_visible_frames
)
14159 windows_or_buffers_changed
= 52;
14162 /* Change frame size now if a change is pending. */
14163 do_pending_window_change (true);
14165 /* If we just did a pending size change, or have additional
14166 visible frames, or selected_window changed, redisplay again. */
14167 if ((windows_or_buffers_changed
&& !pending
)
14168 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
14171 /* Clear the face and image caches.
14173 We used to do this only if consider_all_windows_p. But the cache
14174 needs to be cleared if a timer creates images in the current
14175 buffer (e.g. the test case in Bug#6230). */
14177 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
14179 clear_face_cache (false);
14180 clear_face_cache_count
= 0;
14183 #ifdef HAVE_WINDOW_SYSTEM
14184 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
14186 clear_image_caches (Qnil
);
14187 clear_image_cache_count
= 0;
14189 #endif /* HAVE_WINDOW_SYSTEM */
14193 ns_set_doc_edited ();
14195 if (interrupt_input
&& interrupts_deferred
)
14198 unbind_to (count
, Qnil
);
14203 /* Redisplay, but leave alone any recent echo area message unless
14204 another message has been requested in its place.
14206 This is useful in situations where you need to redisplay but no
14207 user action has occurred, making it inappropriate for the message
14208 area to be cleared. See tracking_off and
14209 wait_reading_process_output for examples of these situations.
14211 FROM_WHERE is an integer saying from where this function was
14212 called. This is useful for debugging. */
14215 redisplay_preserve_echo_area (int from_where
)
14217 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
14219 if (!NILP (echo_area_buffer
[1]))
14221 /* We have a previously displayed message, but no current
14222 message. Redisplay the previous message. */
14223 display_last_displayed_message_p
= true;
14224 redisplay_internal ();
14225 display_last_displayed_message_p
= false;
14228 redisplay_internal ();
14230 flush_frame (SELECTED_FRAME ());
14234 /* Function registered with record_unwind_protect in redisplay_internal. */
14237 unwind_redisplay (void)
14239 redisplaying_p
= false;
14243 /* Mark the display of leaf window W as accurate or inaccurate.
14244 If ACCURATE_P, mark display of W as accurate.
14245 If !ACCURATE_P, arrange for W to be redisplayed the next
14246 time redisplay_internal is called. */
14249 mark_window_display_accurate_1 (struct window
*w
, bool accurate_p
)
14251 struct buffer
*b
= XBUFFER (w
->contents
);
14253 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
14254 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
14255 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
14259 b
->clip_changed
= false;
14260 b
->prevent_redisplay_optimizations_p
= false;
14261 eassert (buffer_window_count (b
) > 0);
14262 /* Resetting b->text->redisplay is problematic!
14263 In order to make it safer to do it here, redisplay_internal must
14264 have copied all b->text->redisplay to their respective windows. */
14265 b
->text
->redisplay
= false;
14267 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
14268 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
14269 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
14270 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
14272 w
->current_matrix
->buffer
= b
;
14273 w
->current_matrix
->begv
= BUF_BEGV (b
);
14274 w
->current_matrix
->zv
= BUF_ZV (b
);
14276 w
->last_cursor_vpos
= w
->cursor
.vpos
;
14277 w
->last_cursor_off_p
= w
->cursor_off_p
;
14279 if (w
== XWINDOW (selected_window
))
14280 w
->last_point
= BUF_PT (b
);
14282 w
->last_point
= marker_position (w
->pointm
);
14284 w
->window_end_valid
= true;
14285 w
->update_mode_line
= false;
14288 w
->redisplay
= !accurate_p
;
14292 /* Mark the display of windows in the window tree rooted at WINDOW as
14293 accurate or inaccurate. If ACCURATE_P, mark display of
14294 windows as accurate. If !ACCURATE_P, arrange for windows to
14295 be redisplayed the next time redisplay_internal is called. */
14298 mark_window_display_accurate (Lisp_Object window
, bool accurate_p
)
14302 for (; !NILP (window
); window
= w
->next
)
14304 w
= XWINDOW (window
);
14305 if (WINDOWP (w
->contents
))
14306 mark_window_display_accurate (w
->contents
, accurate_p
);
14308 mark_window_display_accurate_1 (w
, accurate_p
);
14312 update_overlay_arrows (1);
14314 /* Force a thorough redisplay the next time by setting
14315 last_arrow_position and last_arrow_string to t, which is
14316 unequal to any useful value of Voverlay_arrow_... */
14317 update_overlay_arrows (-1);
14321 /* Return value in display table DP (Lisp_Char_Table *) for character
14322 C. Since a display table doesn't have any parent, we don't have to
14323 follow parent. Do not call this function directly but use the
14324 macro DISP_CHAR_VECTOR. */
14327 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
14331 if (ASCII_CHAR_P (c
))
14334 if (SUB_CHAR_TABLE_P (val
))
14335 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
14341 XSETCHAR_TABLE (table
, dp
);
14342 val
= char_table_ref (table
, c
);
14351 /***********************************************************************
14353 ***********************************************************************/
14355 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
14358 redisplay_windows (Lisp_Object window
)
14360 while (!NILP (window
))
14362 struct window
*w
= XWINDOW (window
);
14364 if (WINDOWP (w
->contents
))
14365 redisplay_windows (w
->contents
);
14366 else if (BUFFERP (w
->contents
))
14368 displayed_buffer
= XBUFFER (w
->contents
);
14369 /* Use list_of_error, not Qerror, so that
14370 we catch only errors and don't run the debugger. */
14371 internal_condition_case_1 (redisplay_window_0
, window
,
14373 redisplay_window_error
);
14381 redisplay_window_error (Lisp_Object ignore
)
14383 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14388 redisplay_window_0 (Lisp_Object window
)
14390 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14391 redisplay_window (window
, false);
14396 redisplay_window_1 (Lisp_Object window
)
14398 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14399 redisplay_window (window
, true);
14404 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14405 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14406 which positions recorded in ROW differ from current buffer
14409 Return true iff cursor is on this row. */
14412 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14413 struct glyph_matrix
*matrix
,
14414 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14417 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14418 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14419 struct glyph
*cursor
= NULL
;
14420 /* The last known character position in row. */
14421 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14423 ptrdiff_t pt_old
= PT
- delta
;
14424 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14425 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14426 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14427 /* A glyph beyond the edge of TEXT_AREA which we should never
14429 struct glyph
*glyphs_end
= end
;
14430 /* True means we've found a match for cursor position, but that
14431 glyph has the avoid_cursor_p flag set. */
14432 bool match_with_avoid_cursor
= false;
14433 /* True means we've seen at least one glyph that came from a
14435 bool string_seen
= false;
14436 /* Largest and smallest buffer positions seen so far during scan of
14438 ptrdiff_t bpos_max
= pos_before
;
14439 ptrdiff_t bpos_min
= pos_after
;
14440 /* Last buffer position covered by an overlay string with an integer
14441 `cursor' property. */
14442 ptrdiff_t bpos_covered
= 0;
14443 /* True means the display string on which to display the cursor
14444 comes from a text property, not from an overlay. */
14445 bool string_from_text_prop
= false;
14447 /* Don't even try doing anything if called for a mode-line or
14448 header-line row, since the rest of the code isn't prepared to
14449 deal with such calamities. */
14450 eassert (!row
->mode_line_p
);
14451 if (row
->mode_line_p
)
14454 /* Skip over glyphs not having an object at the start and the end of
14455 the row. These are special glyphs like truncation marks on
14456 terminal frames. */
14457 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14459 if (!row
->reversed_p
)
14462 && NILP (glyph
->object
)
14463 && glyph
->charpos
< 0)
14465 x
+= glyph
->pixel_width
;
14469 && NILP ((end
- 1)->object
)
14470 /* CHARPOS is zero for blanks and stretch glyphs
14471 inserted by extend_face_to_end_of_line. */
14472 && (end
- 1)->charpos
<= 0)
14474 glyph_before
= glyph
- 1;
14481 /* If the glyph row is reversed, we need to process it from back
14482 to front, so swap the edge pointers. */
14483 glyphs_end
= end
= glyph
- 1;
14484 glyph
+= row
->used
[TEXT_AREA
] - 1;
14486 while (glyph
> end
+ 1
14487 && NILP (glyph
->object
)
14488 && glyph
->charpos
< 0)
14491 x
-= glyph
->pixel_width
;
14493 if (NILP (glyph
->object
) && glyph
->charpos
< 0)
14495 /* By default, in reversed rows we put the cursor on the
14496 rightmost (first in the reading order) glyph. */
14497 for (g
= end
+ 1; g
< glyph
; g
++)
14498 x
+= g
->pixel_width
;
14500 && NILP ((end
+ 1)->object
)
14501 && (end
+ 1)->charpos
<= 0)
14503 glyph_before
= glyph
+ 1;
14507 else if (row
->reversed_p
)
14509 /* In R2L rows that don't display text, put the cursor on the
14510 rightmost glyph. Case in point: an empty last line that is
14511 part of an R2L paragraph. */
14513 /* Avoid placing the cursor on the last glyph of the row, where
14514 on terminal frames we hold the vertical border between
14515 adjacent windows. */
14516 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14517 && !WINDOW_RIGHTMOST_P (w
)
14518 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14520 x
= -1; /* will be computed below, at label compute_x */
14523 /* Step 1: Try to find the glyph whose character position
14524 corresponds to point. If that's not possible, find 2 glyphs
14525 whose character positions are the closest to point, one before
14526 point, the other after it. */
14527 if (!row
->reversed_p
)
14528 while (/* not marched to end of glyph row */
14530 /* glyph was not inserted by redisplay for internal purposes */
14531 && !NILP (glyph
->object
))
14533 if (BUFFERP (glyph
->object
))
14535 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14537 if (glyph
->charpos
> bpos_max
)
14538 bpos_max
= glyph
->charpos
;
14539 if (glyph
->charpos
< bpos_min
)
14540 bpos_min
= glyph
->charpos
;
14541 if (!glyph
->avoid_cursor_p
)
14543 /* If we hit point, we've found the glyph on which to
14544 display the cursor. */
14547 match_with_avoid_cursor
= false;
14550 /* See if we've found a better approximation to
14551 POS_BEFORE or to POS_AFTER. */
14552 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14554 pos_before
= glyph
->charpos
;
14555 glyph_before
= glyph
;
14557 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14559 pos_after
= glyph
->charpos
;
14560 glyph_after
= glyph
;
14563 else if (dpos
== 0)
14564 match_with_avoid_cursor
= true;
14566 else if (STRINGP (glyph
->object
))
14568 Lisp_Object chprop
;
14569 ptrdiff_t glyph_pos
= glyph
->charpos
;
14571 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14573 if (!NILP (chprop
))
14575 /* If the string came from a `display' text property,
14576 look up the buffer position of that property and
14577 use that position to update bpos_max, as if we
14578 actually saw such a position in one of the row's
14579 glyphs. This helps with supporting integer values
14580 of `cursor' property on the display string in
14581 situations where most or all of the row's buffer
14582 text is completely covered by display properties,
14583 so that no glyph with valid buffer positions is
14584 ever seen in the row. */
14585 ptrdiff_t prop_pos
=
14586 string_buffer_position_lim (glyph
->object
, pos_before
,
14589 if (prop_pos
>= pos_before
)
14590 bpos_max
= prop_pos
;
14592 if (INTEGERP (chprop
))
14594 bpos_covered
= bpos_max
+ XINT (chprop
);
14595 /* If the `cursor' property covers buffer positions up
14596 to and including point, we should display cursor on
14597 this glyph. Note that, if a `cursor' property on one
14598 of the string's characters has an integer value, we
14599 will break out of the loop below _before_ we get to
14600 the position match above. IOW, integer values of
14601 the `cursor' property override the "exact match for
14602 point" strategy of positioning the cursor. */
14603 /* Implementation note: bpos_max == pt_old when, e.g.,
14604 we are in an empty line, where bpos_max is set to
14605 MATRIX_ROW_START_CHARPOS, see above. */
14606 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14613 string_seen
= true;
14615 x
+= glyph
->pixel_width
;
14618 else if (glyph
> end
) /* row is reversed */
14619 while (!NILP (glyph
->object
))
14621 if (BUFFERP (glyph
->object
))
14623 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14625 if (glyph
->charpos
> bpos_max
)
14626 bpos_max
= glyph
->charpos
;
14627 if (glyph
->charpos
< bpos_min
)
14628 bpos_min
= glyph
->charpos
;
14629 if (!glyph
->avoid_cursor_p
)
14633 match_with_avoid_cursor
= false;
14636 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14638 pos_before
= glyph
->charpos
;
14639 glyph_before
= glyph
;
14641 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14643 pos_after
= glyph
->charpos
;
14644 glyph_after
= glyph
;
14647 else if (dpos
== 0)
14648 match_with_avoid_cursor
= true;
14650 else if (STRINGP (glyph
->object
))
14652 Lisp_Object chprop
;
14653 ptrdiff_t glyph_pos
= glyph
->charpos
;
14655 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14657 if (!NILP (chprop
))
14659 ptrdiff_t prop_pos
=
14660 string_buffer_position_lim (glyph
->object
, pos_before
,
14663 if (prop_pos
>= pos_before
)
14664 bpos_max
= prop_pos
;
14666 if (INTEGERP (chprop
))
14668 bpos_covered
= bpos_max
+ XINT (chprop
);
14669 /* If the `cursor' property covers buffer positions up
14670 to and including point, we should display cursor on
14672 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14678 string_seen
= true;
14681 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14683 x
--; /* can't use any pixel_width */
14686 x
-= glyph
->pixel_width
;
14689 /* Step 2: If we didn't find an exact match for point, we need to
14690 look for a proper place to put the cursor among glyphs between
14691 GLYPH_BEFORE and GLYPH_AFTER. */
14692 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14693 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14694 && !(bpos_max
<= pt_old
&& pt_old
<= bpos_covered
))
14696 /* An empty line has a single glyph whose OBJECT is nil and
14697 whose CHARPOS is the position of a newline on that line.
14698 Note that on a TTY, there are more glyphs after that, which
14699 were produced by extend_face_to_end_of_line, but their
14700 CHARPOS is zero or negative. */
14701 bool empty_line_p
=
14702 ((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14703 && NILP (glyph
->object
) && glyph
->charpos
> 0
14704 /* On a TTY, continued and truncated rows also have a glyph at
14705 their end whose OBJECT is nil and whose CHARPOS is
14706 positive (the continuation and truncation glyphs), but such
14707 rows are obviously not "empty". */
14708 && !(row
->continued_p
|| row
->truncated_on_right_p
));
14710 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14712 ptrdiff_t ellipsis_pos
;
14714 /* Scan back over the ellipsis glyphs. */
14715 if (!row
->reversed_p
)
14717 ellipsis_pos
= (glyph
- 1)->charpos
;
14718 while (glyph
> row
->glyphs
[TEXT_AREA
]
14719 && (glyph
- 1)->charpos
== ellipsis_pos
)
14720 glyph
--, x
-= glyph
->pixel_width
;
14721 /* That loop always goes one position too far, including
14722 the glyph before the ellipsis. So scan forward over
14724 x
+= glyph
->pixel_width
;
14727 else /* row is reversed */
14729 ellipsis_pos
= (glyph
+ 1)->charpos
;
14730 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14731 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14732 glyph
++, x
+= glyph
->pixel_width
;
14733 x
-= glyph
->pixel_width
;
14737 else if (match_with_avoid_cursor
)
14739 cursor
= glyph_after
;
14742 else if (string_seen
)
14744 int incr
= row
->reversed_p
? -1 : +1;
14746 /* Need to find the glyph that came out of a string which is
14747 present at point. That glyph is somewhere between
14748 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14749 positioned between POS_BEFORE and POS_AFTER in the
14751 struct glyph
*start
, *stop
;
14752 ptrdiff_t pos
= pos_before
;
14756 /* If the row ends in a newline from a display string,
14757 reordering could have moved the glyphs belonging to the
14758 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14759 in this case we extend the search to the last glyph in
14760 the row that was not inserted by redisplay. */
14761 if (row
->ends_in_newline_from_string_p
)
14764 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14767 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14768 correspond to POS_BEFORE and POS_AFTER, respectively. We
14769 need START and STOP in the order that corresponds to the
14770 row's direction as given by its reversed_p flag. If the
14771 directionality of characters between POS_BEFORE and
14772 POS_AFTER is the opposite of the row's base direction,
14773 these characters will have been reordered for display,
14774 and we need to reverse START and STOP. */
14775 if (!row
->reversed_p
)
14777 start
= min (glyph_before
, glyph_after
);
14778 stop
= max (glyph_before
, glyph_after
);
14782 start
= max (glyph_before
, glyph_after
);
14783 stop
= min (glyph_before
, glyph_after
);
14785 for (glyph
= start
+ incr
;
14786 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14789 /* Any glyphs that come from the buffer are here because
14790 of bidi reordering. Skip them, and only pay
14791 attention to glyphs that came from some string. */
14792 if (STRINGP (glyph
->object
))
14796 /* If the display property covers the newline, we
14797 need to search for it one position farther. */
14798 ptrdiff_t lim
= pos_after
14799 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14801 string_from_text_prop
= false;
14802 str
= glyph
->object
;
14803 tem
= string_buffer_position_lim (str
, pos
, lim
, false);
14804 if (tem
== 0 /* from overlay */
14807 /* If the string from which this glyph came is
14808 found in the buffer at point, or at position
14809 that is closer to point than pos_after, then
14810 we've found the glyph we've been looking for.
14811 If it comes from an overlay (tem == 0), and
14812 it has the `cursor' property on one of its
14813 glyphs, record that glyph as a candidate for
14814 displaying the cursor. (As in the
14815 unidirectional version, we will display the
14816 cursor on the last candidate we find.) */
14819 || (tem
- pt_old
> 0 && tem
< pos_after
))
14821 /* The glyphs from this string could have
14822 been reordered. Find the one with the
14823 smallest string position. Or there could
14824 be a character in the string with the
14825 `cursor' property, which means display
14826 cursor on that character's glyph. */
14827 ptrdiff_t strpos
= glyph
->charpos
;
14832 string_from_text_prop
= true;
14835 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14836 && EQ (glyph
->object
, str
);
14840 ptrdiff_t gpos
= glyph
->charpos
;
14842 cprop
= Fget_char_property (make_number (gpos
),
14850 if (tem
&& glyph
->charpos
< strpos
)
14852 strpos
= glyph
->charpos
;
14858 || (tem
- pt_old
> 0 && tem
< pos_after
))
14862 pos
= tem
+ 1; /* don't find previous instances */
14864 /* This string is not what we want; skip all of the
14865 glyphs that came from it. */
14866 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14867 && EQ (glyph
->object
, str
))
14874 /* If we reached the end of the line, and END was from a string,
14875 the cursor is not on this line. */
14877 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14878 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14879 && STRINGP (end
->object
)
14880 && row
->continued_p
)
14883 /* A truncated row may not include PT among its character positions.
14884 Setting the cursor inside the scroll margin will trigger
14885 recalculation of hscroll in hscroll_window_tree. But if a
14886 display string covers point, defer to the string-handling
14887 code below to figure this out. */
14888 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14890 cursor
= glyph_before
;
14893 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14894 /* Zero-width characters produce no glyphs. */
14896 && (row
->reversed_p
14897 ? glyph_after
> glyphs_end
14898 : glyph_after
< glyphs_end
)))
14900 cursor
= glyph_after
;
14906 if (cursor
!= NULL
)
14908 else if (glyph
== glyphs_end
14909 && pos_before
== pos_after
14910 && STRINGP ((row
->reversed_p
14911 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14912 : row
->glyphs
[TEXT_AREA
])->object
))
14914 /* If all the glyphs of this row came from strings, put the
14915 cursor on the first glyph of the row. This avoids having the
14916 cursor outside of the text area in this very rare and hard
14920 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14921 : row
->glyphs
[TEXT_AREA
];
14927 /* Need to compute x that corresponds to GLYPH. */
14928 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14930 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14932 x
+= g
->pixel_width
;
14936 /* ROW could be part of a continued line, which, under bidi
14937 reordering, might have other rows whose start and end charpos
14938 occlude point. Only set w->cursor if we found a better
14939 approximation to the cursor position than we have from previously
14940 examined candidate rows belonging to the same continued line. */
14941 if (/* We already have a candidate row. */
14942 w
->cursor
.vpos
>= 0
14943 /* That candidate is not the row we are processing. */
14944 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14945 /* Make sure cursor.vpos specifies a row whose start and end
14946 charpos occlude point, and it is valid candidate for being a
14947 cursor-row. This is because some callers of this function
14948 leave cursor.vpos at the row where the cursor was displayed
14949 during the last redisplay cycle. */
14950 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14951 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14952 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14955 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14957 /* Don't consider glyphs that are outside TEXT_AREA. */
14958 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14960 /* Keep the candidate whose buffer position is the closest to
14961 point or has the `cursor' property. */
14962 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14963 w
->cursor
.hpos
>= 0
14964 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14965 && ((BUFFERP (g1
->object
)
14966 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14967 || (BUFFERP (glyph
->object
)
14968 && eabs (g1
->charpos
- pt_old
)
14969 < eabs (glyph
->charpos
- pt_old
))))
14970 /* Previous candidate is a glyph from a string that has
14971 a non-nil `cursor' property. */
14972 || (STRINGP (g1
->object
)
14973 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14974 Qcursor
, g1
->object
))
14975 /* Previous candidate is from the same display
14976 string as this one, and the display string
14977 came from a text property. */
14978 || (EQ (g1
->object
, glyph
->object
)
14979 && string_from_text_prop
)
14980 /* this candidate is from newline and its
14981 position is not an exact match */
14982 || (NILP (glyph
->object
)
14983 && glyph
->charpos
!= pt_old
)))))
14985 /* If this candidate gives an exact match, use that. */
14986 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14987 /* If this candidate is a glyph created for the
14988 terminating newline of a line, and point is on that
14989 newline, it wins because it's an exact match. */
14990 || (!row
->continued_p
14991 && NILP (glyph
->object
)
14992 && glyph
->charpos
== 0
14993 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14994 /* Otherwise, keep the candidate that comes from a row
14995 spanning less buffer positions. This may win when one or
14996 both candidate positions are on glyphs that came from
14997 display strings, for which we cannot compare buffer
14999 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15000 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15001 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
15004 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
15006 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
15007 w
->cursor
.y
= row
->y
+ dy
;
15009 if (w
== XWINDOW (selected_window
))
15011 if (!row
->continued_p
15012 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15015 this_line_buffer
= XBUFFER (w
->contents
);
15017 CHARPOS (this_line_start_pos
)
15018 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
15019 BYTEPOS (this_line_start_pos
)
15020 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
15022 CHARPOS (this_line_end_pos
)
15023 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
15024 BYTEPOS (this_line_end_pos
)
15025 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
15027 this_line_y
= w
->cursor
.y
;
15028 this_line_pixel_height
= row
->height
;
15029 this_line_vpos
= w
->cursor
.vpos
;
15030 this_line_start_x
= row
->x
;
15033 CHARPOS (this_line_start_pos
) = 0;
15040 /* Run window scroll functions, if any, for WINDOW with new window
15041 start STARTP. Sets the window start of WINDOW to that position.
15043 We assume that the window's buffer is really current. */
15045 static struct text_pos
15046 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
15048 struct window
*w
= XWINDOW (window
);
15049 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
15051 eassert (current_buffer
== XBUFFER (w
->contents
));
15053 if (!NILP (Vwindow_scroll_functions
))
15055 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
15056 make_number (CHARPOS (startp
)));
15057 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15058 /* In case the hook functions switch buffers. */
15059 set_buffer_internal (XBUFFER (w
->contents
));
15066 /* Make sure the line containing the cursor is fully visible.
15067 A value of true means there is nothing to be done.
15068 (Either the line is fully visible, or it cannot be made so,
15069 or we cannot tell.)
15071 If FORCE_P, return false even if partial visible cursor row
15072 is higher than window.
15074 If CURRENT_MATRIX_P, use the information from the
15075 window's current glyph matrix; otherwise use the desired glyph
15078 A value of false means the caller should do scrolling
15079 as if point had gone off the screen. */
15082 cursor_row_fully_visible_p (struct window
*w
, bool force_p
,
15083 bool current_matrix_p
)
15085 struct glyph_matrix
*matrix
;
15086 struct glyph_row
*row
;
15089 if (!make_cursor_line_fully_visible_p
)
15092 /* It's not always possible to find the cursor, e.g, when a window
15093 is full of overlay strings. Don't do anything in that case. */
15094 if (w
->cursor
.vpos
< 0)
15097 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
15098 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
15100 /* If the cursor row is not partially visible, there's nothing to do. */
15101 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
15104 /* If the row the cursor is in is taller than the window's height,
15105 it's not clear what to do, so do nothing. */
15106 window_height
= window_box_height (w
);
15107 if (row
->height
>= window_height
)
15109 if (!force_p
|| MINI_WINDOW_P (w
)
15110 || w
->vscroll
|| w
->cursor
.vpos
== 0)
15117 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
15118 means only WINDOW is redisplayed in redisplay_internal.
15119 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
15120 in redisplay_window to bring a partially visible line into view in
15121 the case that only the cursor has moved.
15123 LAST_LINE_MISFIT should be true if we're scrolling because the
15124 last screen line's vertical height extends past the end of the screen.
15128 1 if scrolling succeeded
15130 0 if scrolling didn't find point.
15132 -1 if new fonts have been loaded so that we must interrupt
15133 redisplay, adjust glyph matrices, and try again. */
15139 SCROLLING_NEED_LARGER_MATRICES
15142 /* If scroll-conservatively is more than this, never recenter.
15144 If you change this, don't forget to update the doc string of
15145 `scroll-conservatively' and the Emacs manual. */
15146 #define SCROLL_LIMIT 100
15149 try_scrolling (Lisp_Object window
, bool just_this_one_p
,
15150 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
15151 bool temp_scroll_step
, bool last_line_misfit
)
15153 struct window
*w
= XWINDOW (window
);
15154 struct frame
*f
= XFRAME (w
->frame
);
15155 struct text_pos pos
, startp
;
15157 int this_scroll_margin
, scroll_max
, rc
, height
;
15158 int dy
= 0, amount_to_scroll
= 0;
15159 bool scroll_down_p
= false;
15160 int extra_scroll_margin_lines
= last_line_misfit
;
15161 Lisp_Object aggressive
;
15162 /* We will never try scrolling more than this number of lines. */
15163 int scroll_limit
= SCROLL_LIMIT
;
15164 int frame_line_height
= default_line_pixel_height (w
);
15165 int window_total_lines
15166 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15169 debug_method_add (w
, "try_scrolling");
15172 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15174 /* Compute scroll margin height in pixels. We scroll when point is
15175 within this distance from the top or bottom of the window. */
15176 if (scroll_margin
> 0)
15177 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
15178 * frame_line_height
;
15180 this_scroll_margin
= 0;
15182 /* Force arg_scroll_conservatively to have a reasonable value, to
15183 avoid scrolling too far away with slow move_it_* functions. Note
15184 that the user can supply scroll-conservatively equal to
15185 `most-positive-fixnum', which can be larger than INT_MAX. */
15186 if (arg_scroll_conservatively
> scroll_limit
)
15188 arg_scroll_conservatively
= scroll_limit
+ 1;
15189 scroll_max
= scroll_limit
* frame_line_height
;
15191 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
15192 /* Compute how much we should try to scroll maximally to bring
15193 point into view. */
15194 scroll_max
= (max (scroll_step
,
15195 max (arg_scroll_conservatively
, temp_scroll_step
))
15196 * frame_line_height
);
15197 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
15198 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
15199 /* We're trying to scroll because of aggressive scrolling but no
15200 scroll_step is set. Choose an arbitrary one. */
15201 scroll_max
= 10 * frame_line_height
;
15207 /* Decide whether to scroll down. */
15208 if (PT
> CHARPOS (startp
))
15210 int scroll_margin_y
;
15212 /* Compute the pixel ypos of the scroll margin, then move IT to
15213 either that ypos or PT, whichever comes first. */
15214 start_display (&it
, w
, startp
);
15215 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
15216 - frame_line_height
* extra_scroll_margin_lines
;
15217 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
15218 (MOVE_TO_POS
| MOVE_TO_Y
));
15220 if (PT
> CHARPOS (it
.current
.pos
))
15222 int y0
= line_bottom_y (&it
);
15223 /* Compute how many pixels below window bottom to stop searching
15224 for PT. This avoids costly search for PT that is far away if
15225 the user limited scrolling by a small number of lines, but
15226 always finds PT if scroll_conservatively is set to a large
15227 number, such as most-positive-fixnum. */
15228 int slack
= max (scroll_max
, 10 * frame_line_height
);
15229 int y_to_move
= it
.last_visible_y
+ slack
;
15231 /* Compute the distance from the scroll margin to PT or to
15232 the scroll limit, whichever comes first. This should
15233 include the height of the cursor line, to make that line
15235 move_it_to (&it
, PT
, -1, y_to_move
,
15236 -1, MOVE_TO_POS
| MOVE_TO_Y
);
15237 dy
= line_bottom_y (&it
) - y0
;
15239 if (dy
> scroll_max
)
15240 return SCROLLING_FAILED
;
15243 scroll_down_p
= true;
15249 /* Point is in or below the bottom scroll margin, so move the
15250 window start down. If scrolling conservatively, move it just
15251 enough down to make point visible. If scroll_step is set,
15252 move it down by scroll_step. */
15253 if (arg_scroll_conservatively
)
15255 = min (max (dy
, frame_line_height
),
15256 frame_line_height
* arg_scroll_conservatively
);
15257 else if (scroll_step
|| temp_scroll_step
)
15258 amount_to_scroll
= scroll_max
;
15261 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
15262 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15263 if (NUMBERP (aggressive
))
15265 double float_amount
= XFLOATINT (aggressive
) * height
;
15266 int aggressive_scroll
= float_amount
;
15267 if (aggressive_scroll
== 0 && float_amount
> 0)
15268 aggressive_scroll
= 1;
15269 /* Don't let point enter the scroll margin near top of
15270 the window. This could happen if the value of
15271 scroll_up_aggressively is too large and there are
15272 non-zero margins, because scroll_up_aggressively
15273 means put point that fraction of window height
15274 _from_the_bottom_margin_. */
15275 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15276 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15277 amount_to_scroll
= dy
+ aggressive_scroll
;
15281 if (amount_to_scroll
<= 0)
15282 return SCROLLING_FAILED
;
15284 start_display (&it
, w
, startp
);
15285 if (arg_scroll_conservatively
<= scroll_limit
)
15286 move_it_vertically (&it
, amount_to_scroll
);
15289 /* Extra precision for users who set scroll-conservatively
15290 to a large number: make sure the amount we scroll
15291 the window start is never less than amount_to_scroll,
15292 which was computed as distance from window bottom to
15293 point. This matters when lines at window top and lines
15294 below window bottom have different height. */
15296 void *it1data
= NULL
;
15297 /* We use a temporary it1 because line_bottom_y can modify
15298 its argument, if it moves one line down; see there. */
15301 SAVE_IT (it1
, it
, it1data
);
15302 start_y
= line_bottom_y (&it1
);
15304 RESTORE_IT (&it
, &it
, it1data
);
15305 move_it_by_lines (&it
, 1);
15306 SAVE_IT (it1
, it
, it1data
);
15307 } while (IT_CHARPOS (it
) < ZV
15308 && line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
15309 bidi_unshelve_cache (it1data
, true);
15312 /* If STARTP is unchanged, move it down another screen line. */
15313 if (IT_CHARPOS (it
) == CHARPOS (startp
))
15314 move_it_by_lines (&it
, 1);
15315 startp
= it
.current
.pos
;
15319 struct text_pos scroll_margin_pos
= startp
;
15322 /* See if point is inside the scroll margin at the top of the
15324 if (this_scroll_margin
)
15328 start_display (&it
, w
, startp
);
15329 y_start
= it
.current_y
;
15330 move_it_vertically (&it
, this_scroll_margin
);
15331 scroll_margin_pos
= it
.current
.pos
;
15332 /* If we didn't move enough before hitting ZV, request
15333 additional amount of scroll, to move point out of the
15335 if (IT_CHARPOS (it
) == ZV
15336 && it
.current_y
- y_start
< this_scroll_margin
)
15337 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
15340 if (PT
< CHARPOS (scroll_margin_pos
))
15342 /* Point is in the scroll margin at the top of the window or
15343 above what is displayed in the window. */
15346 /* Compute the vertical distance from PT to the scroll
15347 margin position. Move as far as scroll_max allows, or
15348 one screenful, or 10 screen lines, whichever is largest.
15349 Give up if distance is greater than scroll_max or if we
15350 didn't reach the scroll margin position. */
15351 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
15352 start_display (&it
, w
, pos
);
15354 y_to_move
= max (it
.last_visible_y
,
15355 max (scroll_max
, 10 * frame_line_height
));
15356 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
15358 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15359 dy
= it
.current_y
- y0
;
15360 if (dy
> scroll_max
15361 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
15362 return SCROLLING_FAILED
;
15364 /* Additional scroll for when ZV was too close to point. */
15367 /* Compute new window start. */
15368 start_display (&it
, w
, startp
);
15370 if (arg_scroll_conservatively
)
15371 amount_to_scroll
= max (dy
, frame_line_height
15372 * max (scroll_step
, temp_scroll_step
));
15373 else if (scroll_step
|| temp_scroll_step
)
15374 amount_to_scroll
= scroll_max
;
15377 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15378 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15379 if (NUMBERP (aggressive
))
15381 double float_amount
= XFLOATINT (aggressive
) * height
;
15382 int aggressive_scroll
= float_amount
;
15383 if (aggressive_scroll
== 0 && float_amount
> 0)
15384 aggressive_scroll
= 1;
15385 /* Don't let point enter the scroll margin near
15386 bottom of the window, if the value of
15387 scroll_down_aggressively happens to be too
15389 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15390 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15391 amount_to_scroll
= dy
+ aggressive_scroll
;
15395 if (amount_to_scroll
<= 0)
15396 return SCROLLING_FAILED
;
15398 move_it_vertically_backward (&it
, amount_to_scroll
);
15399 startp
= it
.current
.pos
;
15403 /* Run window scroll functions. */
15404 startp
= run_window_scroll_functions (window
, startp
);
15406 /* Display the window. Give up if new fonts are loaded, or if point
15408 if (!try_window (window
, startp
, 0))
15409 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15410 else if (w
->cursor
.vpos
< 0)
15412 clear_glyph_matrix (w
->desired_matrix
);
15413 rc
= SCROLLING_FAILED
;
15417 /* Maybe forget recorded base line for line number display. */
15418 if (!just_this_one_p
15419 || current_buffer
->clip_changed
15420 || BEG_UNCHANGED
< CHARPOS (startp
))
15421 w
->base_line_number
= 0;
15423 /* If cursor ends up on a partially visible line,
15424 treat that as being off the bottom of the screen. */
15425 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1,
15427 /* It's possible that the cursor is on the first line of the
15428 buffer, which is partially obscured due to a vscroll
15429 (Bug#7537). In that case, avoid looping forever. */
15430 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15432 clear_glyph_matrix (w
->desired_matrix
);
15433 ++extra_scroll_margin_lines
;
15436 rc
= SCROLLING_SUCCESS
;
15443 /* Compute a suitable window start for window W if display of W starts
15444 on a continuation line. Value is true if a new window start
15447 The new window start will be computed, based on W's width, starting
15448 from the start of the continued line. It is the start of the
15449 screen line with the minimum distance from the old start W->start. */
15452 compute_window_start_on_continuation_line (struct window
*w
)
15454 struct text_pos pos
, start_pos
;
15455 bool window_start_changed_p
= false;
15457 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15459 /* If window start is on a continuation line... Window start may be
15460 < BEGV in case there's invisible text at the start of the
15461 buffer (M-x rmail, for example). */
15462 if (CHARPOS (start_pos
) > BEGV
15463 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15466 struct glyph_row
*row
;
15468 /* Handle the case that the window start is out of range. */
15469 if (CHARPOS (start_pos
) < BEGV
)
15470 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15471 else if (CHARPOS (start_pos
) > ZV
)
15472 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15474 /* Find the start of the continued line. This should be fast
15475 because find_newline is fast (newline cache). */
15476 row
= w
->desired_matrix
->rows
+ WINDOW_WANTS_HEADER_LINE_P (w
);
15477 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15478 row
, DEFAULT_FACE_ID
);
15479 reseat_at_previous_visible_line_start (&it
);
15481 /* If the line start is "too far" away from the window start,
15482 say it takes too much time to compute a new window start. */
15483 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15484 /* PXW: Do we need upper bounds here? */
15485 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15487 int min_distance
, distance
;
15489 /* Move forward by display lines to find the new window
15490 start. If window width was enlarged, the new start can
15491 be expected to be > the old start. If window width was
15492 decreased, the new window start will be < the old start.
15493 So, we're looking for the display line start with the
15494 minimum distance from the old window start. */
15495 pos
= it
.current
.pos
;
15496 min_distance
= INFINITY
;
15497 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15498 distance
< min_distance
)
15500 min_distance
= distance
;
15501 pos
= it
.current
.pos
;
15502 if (it
.line_wrap
== WORD_WRAP
)
15504 /* Under WORD_WRAP, move_it_by_lines is likely to
15505 overshoot and stop not at the first, but the
15506 second character from the left margin. So in
15507 that case, we need a more tight control on the X
15508 coordinate of the iterator than move_it_by_lines
15509 promises in its contract. The method is to first
15510 go to the last (rightmost) visible character of a
15511 line, then move to the leftmost character on the
15512 next line in a separate call. */
15513 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15514 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15515 move_it_to (&it
, ZV
, 0,
15516 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15517 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15520 move_it_by_lines (&it
, 1);
15523 /* Set the window start there. */
15524 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15525 window_start_changed_p
= true;
15529 return window_start_changed_p
;
15533 /* Try cursor movement in case text has not changed in window WINDOW,
15534 with window start STARTP. Value is
15536 CURSOR_MOVEMENT_SUCCESS if successful
15538 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15540 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15541 display. *SCROLL_STEP is set to true, under certain circumstances, if
15542 we want to scroll as if scroll-step were set to 1. See the code.
15544 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15545 which case we have to abort this redisplay, and adjust matrices
15550 CURSOR_MOVEMENT_SUCCESS
,
15551 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15552 CURSOR_MOVEMENT_MUST_SCROLL
,
15553 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15557 try_cursor_movement (Lisp_Object window
, struct text_pos startp
,
15560 struct window
*w
= XWINDOW (window
);
15561 struct frame
*f
= XFRAME (w
->frame
);
15562 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15565 if (inhibit_try_cursor_movement
)
15569 /* Previously, there was a check for Lisp integer in the
15570 if-statement below. Now, this field is converted to
15571 ptrdiff_t, thus zero means invalid position in a buffer. */
15572 eassert (w
->last_point
> 0);
15573 /* Likewise there was a check whether window_end_vpos is nil or larger
15574 than the window. Now window_end_vpos is int and so never nil, but
15575 let's leave eassert to check whether it fits in the window. */
15576 eassert (!w
->window_end_valid
15577 || w
->window_end_vpos
< w
->current_matrix
->nrows
);
15579 /* Handle case where text has not changed, only point, and it has
15580 not moved off the frame. */
15581 if (/* Point may be in this window. */
15582 PT
>= CHARPOS (startp
)
15583 /* Selective display hasn't changed. */
15584 && !current_buffer
->clip_changed
15585 /* Function force-mode-line-update is used to force a thorough
15586 redisplay. It sets either windows_or_buffers_changed or
15587 update_mode_lines. So don't take a shortcut here for these
15589 && !update_mode_lines
15590 && !windows_or_buffers_changed
15591 && !f
->cursor_type_changed
15592 && NILP (Vshow_trailing_whitespace
)
15593 /* This code is not used for mini-buffer for the sake of the case
15594 of redisplaying to replace an echo area message; since in
15595 that case the mini-buffer contents per se are usually
15596 unchanged. This code is of no real use in the mini-buffer
15597 since the handling of this_line_start_pos, etc., in redisplay
15598 handles the same cases. */
15599 && !EQ (window
, minibuf_window
)
15600 && (FRAME_WINDOW_P (f
)
15601 || !overlay_arrow_in_current_buffer_p ()))
15603 int this_scroll_margin
, top_scroll_margin
;
15604 struct glyph_row
*row
= NULL
;
15605 int frame_line_height
= default_line_pixel_height (w
);
15606 int window_total_lines
15607 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15610 debug_method_add (w
, "cursor movement");
15613 /* Scroll if point within this distance from the top or bottom
15614 of the window. This is a pixel value. */
15615 if (scroll_margin
> 0)
15617 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15618 this_scroll_margin
*= frame_line_height
;
15621 this_scroll_margin
= 0;
15623 top_scroll_margin
= this_scroll_margin
;
15624 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15625 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15627 /* Start with the row the cursor was displayed during the last
15628 not paused redisplay. Give up if that row is not valid. */
15629 if (w
->last_cursor_vpos
< 0
15630 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15631 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15634 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15635 if (row
->mode_line_p
)
15637 if (!row
->enabled_p
)
15638 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15641 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15643 bool scroll_p
= false, must_scroll
= false;
15644 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15646 if (PT
> w
->last_point
)
15648 /* Point has moved forward. */
15649 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15650 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15652 eassert (row
->enabled_p
);
15656 /* If the end position of a row equals the start
15657 position of the next row, and PT is at that position,
15658 we would rather display cursor in the next line. */
15659 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15660 && MATRIX_ROW_END_CHARPOS (row
) == PT
15661 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15662 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15663 && !cursor_row_p (row
))
15666 /* If within the scroll margin, scroll. Note that
15667 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15668 the next line would be drawn, and that
15669 this_scroll_margin can be zero. */
15670 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15671 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15672 /* Line is completely visible last line in window
15673 and PT is to be set in the next line. */
15674 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15675 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15676 && !row
->ends_at_zv_p
15677 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15680 else if (PT
< w
->last_point
)
15682 /* Cursor has to be moved backward. Note that PT >=
15683 CHARPOS (startp) because of the outer if-statement. */
15684 while (!row
->mode_line_p
15685 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15686 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15687 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15688 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15689 row
> w
->current_matrix
->rows
15690 && (row
-1)->ends_in_newline_from_string_p
))))
15691 && (row
->y
> top_scroll_margin
15692 || CHARPOS (startp
) == BEGV
))
15694 eassert (row
->enabled_p
);
15698 /* Consider the following case: Window starts at BEGV,
15699 there is invisible, intangible text at BEGV, so that
15700 display starts at some point START > BEGV. It can
15701 happen that we are called with PT somewhere between
15702 BEGV and START. Try to handle that case. */
15703 if (row
< w
->current_matrix
->rows
15704 || row
->mode_line_p
)
15706 row
= w
->current_matrix
->rows
;
15707 if (row
->mode_line_p
)
15711 /* Due to newlines in overlay strings, we may have to
15712 skip forward over overlay strings. */
15713 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15714 && MATRIX_ROW_END_CHARPOS (row
) == PT
15715 && !cursor_row_p (row
))
15718 /* If within the scroll margin, scroll. */
15719 if (row
->y
< top_scroll_margin
15720 && CHARPOS (startp
) != BEGV
)
15725 /* Cursor did not move. So don't scroll even if cursor line
15726 is partially visible, as it was so before. */
15727 rc
= CURSOR_MOVEMENT_SUCCESS
;
15730 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15731 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15733 /* if PT is not in the glyph row, give up. */
15734 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15735 must_scroll
= true;
15737 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15738 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15740 struct glyph_row
*row1
;
15742 /* If rows are bidi-reordered and point moved, back up
15743 until we find a row that does not belong to a
15744 continuation line. This is because we must consider
15745 all rows of a continued line as candidates for the
15746 new cursor positioning, since row start and end
15747 positions change non-linearly with vertical position
15749 /* FIXME: Revisit this when glyph ``spilling'' in
15750 continuation lines' rows is implemented for
15751 bidi-reordered rows. */
15752 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15753 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15756 /* If we hit the beginning of the displayed portion
15757 without finding the first row of a continued
15761 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15764 eassert (row
->enabled_p
);
15769 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15770 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15771 /* Make sure this isn't a header line by any chance, since
15772 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield true. */
15773 && !row
->mode_line_p
15774 && make_cursor_line_fully_visible_p
)
15776 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15777 && !row
->ends_at_zv_p
15778 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15779 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15780 else if (row
->height
> window_box_height (w
))
15782 /* If we end up in a partially visible line, let's
15783 make it fully visible, except when it's taller
15784 than the window, in which case we can't do much
15786 *scroll_step
= true;
15787 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15791 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15792 if (!cursor_row_fully_visible_p (w
, false, true))
15793 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15795 rc
= CURSOR_MOVEMENT_SUCCESS
;
15799 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15800 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15801 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15803 /* With bidi-reordered rows, there could be more than
15804 one candidate row whose start and end positions
15805 occlude point. We need to let set_cursor_from_row
15806 find the best candidate. */
15807 /* FIXME: Revisit this when glyph ``spilling'' in
15808 continuation lines' rows is implemented for
15809 bidi-reordered rows. */
15814 bool at_zv_p
= false, exact_match_p
= false;
15816 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15817 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15818 && cursor_row_p (row
))
15819 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15821 /* As soon as we've found the exact match for point,
15822 or the first suitable row whose ends_at_zv_p flag
15823 is set, we are done. */
15826 at_zv_p
= MATRIX_ROW (w
->current_matrix
,
15827 w
->cursor
.vpos
)->ends_at_zv_p
;
15829 && w
->cursor
.hpos
>= 0
15830 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15833 struct glyph_row
*candidate
=
15834 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15836 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15837 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15840 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15841 || (NILP (g
->object
)
15842 && (g
->charpos
== PT
15843 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15845 if (at_zv_p
|| exact_match_p
)
15847 rc
= CURSOR_MOVEMENT_SUCCESS
;
15851 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15855 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15856 || row
->continued_p
)
15857 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15858 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15859 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15860 /* If we didn't find any candidate rows, or exited the
15861 loop before all the candidates were examined, signal
15862 to the caller that this method failed. */
15863 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15865 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15866 && !row
->continued_p
))
15867 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15869 rc
= CURSOR_MOVEMENT_SUCCESS
;
15875 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15877 rc
= CURSOR_MOVEMENT_SUCCESS
;
15882 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15883 && MATRIX_ROW_START_CHARPOS (row
) == PT
15884 && cursor_row_p (row
));
15894 set_vertical_scroll_bar (struct window
*w
)
15896 ptrdiff_t start
, end
, whole
;
15898 /* Calculate the start and end positions for the current window.
15899 At some point, it would be nice to choose between scrollbars
15900 which reflect the whole buffer size, with special markers
15901 indicating narrowing, and scrollbars which reflect only the
15904 Note that mini-buffers sometimes aren't displaying any text. */
15905 if (!MINI_WINDOW_P (w
)
15906 || (w
== XWINDOW (minibuf_window
)
15907 && NILP (echo_area_buffer
[0])))
15909 struct buffer
*buf
= XBUFFER (w
->contents
);
15910 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15911 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15912 /* I don't think this is guaranteed to be right. For the
15913 moment, we'll pretend it is. */
15914 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15918 if (whole
< (end
- start
))
15919 whole
= end
- start
;
15922 start
= end
= whole
= 0;
15924 /* Indicate what this scroll bar ought to be displaying now. */
15925 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15926 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15927 (w
, end
- start
, whole
, start
);
15932 set_horizontal_scroll_bar (struct window
*w
)
15934 int start
, end
, whole
, portion
;
15936 if (!MINI_WINDOW_P (w
)
15937 || (w
== XWINDOW (minibuf_window
)
15938 && NILP (echo_area_buffer
[0])))
15940 struct buffer
*b
= XBUFFER (w
->contents
);
15941 struct buffer
*old_buffer
= NULL
;
15943 struct text_pos startp
;
15945 if (b
!= current_buffer
)
15947 old_buffer
= current_buffer
;
15948 set_buffer_internal (b
);
15951 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15952 start_display (&it
, w
, startp
);
15953 it
.last_visible_x
= INT_MAX
;
15954 whole
= move_it_to (&it
, -1, INT_MAX
, window_box_height (w
), -1,
15955 MOVE_TO_X
| MOVE_TO_Y
);
15956 /* whole = move_it_to (&it, w->window_end_pos, INT_MAX,
15957 window_box_height (w), -1,
15958 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); */
15960 start
= w
->hscroll
* FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
15961 end
= start
+ window_box_width (w
, TEXT_AREA
);
15962 portion
= end
- start
;
15963 /* After enlarging a horizontally scrolled window such that it
15964 gets at least as wide as the text it contains, make sure that
15965 the thumb doesn't fill the entire scroll bar so we can still
15966 drag it back to see the entire text. */
15967 whole
= max (whole
, end
);
15973 pdir
= Fcurrent_bidi_paragraph_direction (Qnil
);
15974 if (EQ (pdir
, Qright_to_left
))
15976 start
= whole
- end
;
15977 end
= start
+ portion
;
15982 set_buffer_internal (old_buffer
);
15985 start
= end
= whole
= portion
= 0;
15987 w
->hscroll_whole
= whole
;
15989 /* Indicate what this scroll bar ought to be displaying now. */
15990 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
15991 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
15992 (w
, portion
, whole
, start
);
15996 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P means only
15997 selected_window is redisplayed.
15999 We can return without actually redisplaying the window if fonts has been
16000 changed on window's frame. In that case, redisplay_internal will retry.
16002 As one of the important parts of redisplaying a window, we need to
16003 decide whether the previous window-start position (stored in the
16004 window's w->start marker position) is still valid, and if it isn't,
16005 recompute it. Some details about that:
16007 . The previous window-start could be in a continuation line, in
16008 which case we need to recompute it when the window width
16009 changes. See compute_window_start_on_continuation_line and its
16012 . The text that changed since last redisplay could include the
16013 previous window-start position. In that case, we try to salvage
16014 what we can from the current glyph matrix by calling
16015 try_scrolling, which see.
16017 . Some Emacs command could force us to use a specific window-start
16018 position by setting the window's force_start flag, or gently
16019 propose doing that by setting the window's optional_new_start
16020 flag. In these cases, we try using the specified start point if
16021 that succeeds (i.e. the window desired matrix is successfully
16022 recomputed, and point location is within the window). In case
16023 of optional_new_start, we first check if the specified start
16024 position is feasible, i.e. if it will allow point to be
16025 displayed in the window. If using the specified start point
16026 fails, e.g., if new fonts are needed to be loaded, we abort the
16027 redisplay cycle and leave it up to the next cycle to figure out
16030 . Note that the window's force_start flag is sometimes set by
16031 redisplay itself, when it decides that the previous window start
16032 point is fine and should be kept. Search for "goto force_start"
16033 below to see the details. Like the values of window-start
16034 specified outside of redisplay, these internally-deduced values
16035 are tested for feasibility, and ignored if found to be
16038 . Note that the function try_window, used to completely redisplay
16039 a window, accepts the window's start point as its argument.
16040 This is used several times in the redisplay code to control
16041 where the window start will be, according to user options such
16042 as scroll-conservatively, and also to ensure the screen line
16043 showing point will be fully (as opposed to partially) visible on
16047 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
16049 struct window
*w
= XWINDOW (window
);
16050 struct frame
*f
= XFRAME (w
->frame
);
16051 struct buffer
*buffer
= XBUFFER (w
->contents
);
16052 struct buffer
*old
= current_buffer
;
16053 struct text_pos lpoint
, opoint
, startp
;
16054 bool update_mode_line
;
16057 /* Record it now because it's overwritten. */
16058 bool current_matrix_up_to_date_p
= false;
16059 bool used_current_matrix_p
= false;
16060 /* This is less strict than current_matrix_up_to_date_p.
16061 It indicates that the buffer contents and narrowing are unchanged. */
16062 bool buffer_unchanged_p
= false;
16063 bool temp_scroll_step
= false;
16064 ptrdiff_t count
= SPECPDL_INDEX ();
16066 int centering_position
= -1;
16067 bool last_line_misfit
= false;
16068 ptrdiff_t beg_unchanged
, end_unchanged
;
16069 int frame_line_height
;
16071 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16075 *w
->desired_matrix
->method
= 0;
16078 if (!just_this_one_p
16079 && REDISPLAY_SOME_P ()
16081 && !w
->update_mode_line
16084 && !buffer
->text
->redisplay
16085 && BUF_PT (buffer
) == w
->last_point
)
16088 /* Make sure that both W's markers are valid. */
16089 eassert (XMARKER (w
->start
)->buffer
== buffer
);
16090 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
16092 /* We come here again if we need to run window-text-change-functions
16095 reconsider_clip_changes (w
);
16096 frame_line_height
= default_line_pixel_height (w
);
16098 /* Has the mode line to be updated? */
16099 update_mode_line
= (w
->update_mode_line
16100 || update_mode_lines
16101 || buffer
->clip_changed
16102 || buffer
->prevent_redisplay_optimizations_p
);
16104 if (!just_this_one_p
)
16105 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
16106 cleverly elsewhere. */
16107 w
->must_be_updated_p
= true;
16109 if (MINI_WINDOW_P (w
))
16111 if (w
== XWINDOW (echo_area_window
)
16112 && !NILP (echo_area_buffer
[0]))
16114 if (update_mode_line
)
16115 /* We may have to update a tty frame's menu bar or a
16116 tool-bar. Example `M-x C-h C-h C-g'. */
16117 goto finish_menu_bars
;
16119 /* We've already displayed the echo area glyphs in this window. */
16120 goto finish_scroll_bars
;
16122 else if ((w
!= XWINDOW (minibuf_window
)
16123 || minibuf_level
== 0)
16124 /* When buffer is nonempty, redisplay window normally. */
16125 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
16126 /* Quail displays non-mini buffers in minibuffer window.
16127 In that case, redisplay the window normally. */
16128 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
16130 /* W is a mini-buffer window, but it's not active, so clear
16132 int yb
= window_text_bottom_y (w
);
16133 struct glyph_row
*row
;
16136 for (y
= 0, row
= w
->desired_matrix
->rows
;
16138 y
+= row
->height
, ++row
)
16139 blank_row (w
, row
, y
);
16140 goto finish_scroll_bars
;
16143 clear_glyph_matrix (w
->desired_matrix
);
16146 /* Otherwise set up data on this window; select its buffer and point
16148 /* Really select the buffer, for the sake of buffer-local
16150 set_buffer_internal_1 (XBUFFER (w
->contents
));
16152 current_matrix_up_to_date_p
16153 = (w
->window_end_valid
16154 && !current_buffer
->clip_changed
16155 && !current_buffer
->prevent_redisplay_optimizations_p
16156 && !window_outdated (w
));
16158 /* Run the window-text-change-functions
16159 if it is possible that the text on the screen has changed
16160 (either due to modification of the text, or any other reason). */
16161 if (!current_matrix_up_to_date_p
16162 && !NILP (Vwindow_text_change_functions
))
16164 safe_run_hooks (Qwindow_text_change_functions
);
16168 beg_unchanged
= BEG_UNCHANGED
;
16169 end_unchanged
= END_UNCHANGED
;
16171 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
16173 specbind (Qinhibit_point_motion_hooks
, Qt
);
16176 = (w
->window_end_valid
16177 && !current_buffer
->clip_changed
16178 && !window_outdated (w
));
16180 /* When windows_or_buffers_changed is non-zero, we can't rely
16181 on the window end being valid, so set it to zero there. */
16182 if (windows_or_buffers_changed
)
16184 /* If window starts on a continuation line, maybe adjust the
16185 window start in case the window's width changed. */
16186 if (XMARKER (w
->start
)->buffer
== current_buffer
)
16187 compute_window_start_on_continuation_line (w
);
16189 w
->window_end_valid
= false;
16190 /* If so, we also can't rely on current matrix
16191 and should not fool try_cursor_movement below. */
16192 current_matrix_up_to_date_p
= false;
16195 /* Some sanity checks. */
16196 CHECK_WINDOW_END (w
);
16197 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
16199 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
16202 if (mode_line_update_needed (w
))
16203 update_mode_line
= true;
16205 /* Point refers normally to the selected window. For any other
16206 window, set up appropriate value. */
16207 if (!EQ (window
, selected_window
))
16209 ptrdiff_t new_pt
= marker_position (w
->pointm
);
16210 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
16215 new_pt_byte
= BEGV_BYTE
;
16216 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
16218 else if (new_pt
> (ZV
- 1))
16221 new_pt_byte
= ZV_BYTE
;
16222 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
16225 /* We don't use SET_PT so that the point-motion hooks don't run. */
16226 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
16229 /* If any of the character widths specified in the display table
16230 have changed, invalidate the width run cache. It's true that
16231 this may be a bit late to catch such changes, but the rest of
16232 redisplay goes (non-fatally) haywire when the display table is
16233 changed, so why should we worry about doing any better? */
16234 if (current_buffer
->width_run_cache
16235 || (current_buffer
->base_buffer
16236 && current_buffer
->base_buffer
->width_run_cache
))
16238 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
16240 if (! disptab_matches_widthtab
16241 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
16243 struct buffer
*buf
= current_buffer
;
16245 if (buf
->base_buffer
)
16246 buf
= buf
->base_buffer
;
16247 invalidate_region_cache (buf
, buf
->width_run_cache
, BEG
, Z
);
16248 recompute_width_table (current_buffer
, disptab
);
16252 /* If window-start is screwed up, choose a new one. */
16253 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
16256 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16258 /* If someone specified a new starting point but did not insist,
16259 check whether it can be used. */
16260 if ((w
->optional_new_start
|| window_frozen_p (w
))
16261 && CHARPOS (startp
) >= BEGV
16262 && CHARPOS (startp
) <= ZV
)
16264 ptrdiff_t it_charpos
;
16266 w
->optional_new_start
= false;
16267 start_display (&it
, w
, startp
);
16268 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
16269 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
16270 /* Record IT's position now, since line_bottom_y might change
16272 it_charpos
= IT_CHARPOS (it
);
16273 /* Make sure we set the force_start flag only if the cursor row
16274 will be fully visible. Otherwise, the code under force_start
16275 label below will try to move point back into view, which is
16276 not what the code which sets optional_new_start wants. */
16277 if ((it
.current_y
== 0 || line_bottom_y (&it
) < it
.last_visible_y
)
16278 && !w
->force_start
)
16280 if (it_charpos
== PT
)
16281 w
->force_start
= true;
16282 /* IT may overshoot PT if text at PT is invisible. */
16283 else if (it_charpos
> PT
&& CHARPOS (startp
) <= PT
)
16284 w
->force_start
= true;
16286 if (w
->force_start
)
16288 if (window_frozen_p (w
))
16289 debug_method_add (w
, "set force_start from frozen window start");
16291 debug_method_add (w
, "set force_start from optional_new_start");
16299 /* Handle case where place to start displaying has been specified,
16300 unless the specified location is outside the accessible range. */
16301 if (w
->force_start
)
16303 /* We set this later on if we have to adjust point. */
16306 w
->force_start
= false;
16308 w
->window_end_valid
= false;
16310 /* Forget any recorded base line for line number display. */
16311 if (!buffer_unchanged_p
)
16312 w
->base_line_number
= 0;
16314 /* Redisplay the mode line. Select the buffer properly for that.
16315 Also, run the hook window-scroll-functions
16316 because we have scrolled. */
16317 /* Note, we do this after clearing force_start because
16318 if there's an error, it is better to forget about force_start
16319 than to get into an infinite loop calling the hook functions
16320 and having them get more errors. */
16321 if (!update_mode_line
16322 || ! NILP (Vwindow_scroll_functions
))
16324 update_mode_line
= true;
16325 w
->update_mode_line
= true;
16326 startp
= run_window_scroll_functions (window
, startp
);
16329 if (CHARPOS (startp
) < BEGV
)
16330 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
16331 else if (CHARPOS (startp
) > ZV
)
16332 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
16334 /* Redisplay, then check if cursor has been set during the
16335 redisplay. Give up if new fonts were loaded. */
16336 /* We used to issue a CHECK_MARGINS argument to try_window here,
16337 but this causes scrolling to fail when point begins inside
16338 the scroll margin (bug#148) -- cyd */
16339 if (!try_window (window
, startp
, 0))
16341 w
->force_start
= true;
16342 clear_glyph_matrix (w
->desired_matrix
);
16343 goto need_larger_matrices
;
16346 if (w
->cursor
.vpos
< 0)
16348 /* If point does not appear, try to move point so it does
16349 appear. The desired matrix has been built above, so we
16350 can use it here. First see if point is in invisible
16351 text, and if so, move it to the first visible buffer
16352 position past that. */
16353 struct glyph_row
*r
= NULL
;
16354 Lisp_Object invprop
=
16355 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16358 if (TEXT_PROP_MEANS_INVISIBLE (invprop
) != 0)
16361 Lisp_Object invprop_end
=
16362 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16365 if (NATNUMP (invprop_end
))
16366 alt_pt
= XFASTINT (invprop_end
);
16369 r
= row_containing_pos (w
, alt_pt
, w
->desired_matrix
->rows
,
16373 new_vpos
= MATRIX_ROW_BOTTOM_Y (r
);
16374 else /* Give up and just move to the middle of the window. */
16375 new_vpos
= window_box_height (w
) / 2;
16378 if (!cursor_row_fully_visible_p (w
, false, false))
16380 /* Point does appear, but on a line partly visible at end of window.
16381 Move it back to a fully-visible line. */
16382 new_vpos
= window_box_height (w
);
16383 /* But if window_box_height suggests a Y coordinate that is
16384 not less than we already have, that line will clearly not
16385 be fully visible, so give up and scroll the display.
16386 This can happen when the default face uses a font whose
16387 dimensions are different from the frame's default
16389 if (new_vpos
>= w
->cursor
.y
)
16391 w
->cursor
.vpos
= -1;
16392 clear_glyph_matrix (w
->desired_matrix
);
16393 goto try_to_scroll
;
16396 else if (w
->cursor
.vpos
>= 0)
16398 /* Some people insist on not letting point enter the scroll
16399 margin, even though this part handles windows that didn't
16401 int window_total_lines
16402 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16403 int margin
= min (scroll_margin
, window_total_lines
/ 4);
16404 int pixel_margin
= margin
* frame_line_height
;
16405 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
16407 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
16408 below, which finds the row to move point to, advances by
16409 the Y coordinate of the _next_ row, see the definition of
16410 MATRIX_ROW_BOTTOM_Y. */
16411 if (w
->cursor
.vpos
< margin
+ header_line
)
16413 w
->cursor
.vpos
= -1;
16414 clear_glyph_matrix (w
->desired_matrix
);
16415 goto try_to_scroll
;
16419 int window_height
= window_box_height (w
);
16422 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
16423 if (w
->cursor
.y
>= window_height
- pixel_margin
)
16425 w
->cursor
.vpos
= -1;
16426 clear_glyph_matrix (w
->desired_matrix
);
16427 goto try_to_scroll
;
16432 /* If we need to move point for either of the above reasons,
16433 now actually do it. */
16436 struct glyph_row
*row
;
16438 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
16439 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
16442 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
16443 MATRIX_ROW_START_BYTEPOS (row
));
16445 if (w
!= XWINDOW (selected_window
))
16446 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
16447 else if (current_buffer
== old
)
16448 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16450 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
16452 /* Re-run pre-redisplay-function so it can update the region
16453 according to the new position of point. */
16454 /* Other than the cursor, w's redisplay is done so we can set its
16455 redisplay to false. Also the buffer's redisplay can be set to
16456 false, since propagate_buffer_redisplay should have already
16457 propagated its info to `w' anyway. */
16458 w
->redisplay
= false;
16459 XBUFFER (w
->contents
)->text
->redisplay
= false;
16460 safe__call1 (true, Vpre_redisplay_function
, Fcons (window
, Qnil
));
16462 if (w
->redisplay
|| XBUFFER (w
->contents
)->text
->redisplay
)
16464 /* pre-redisplay-function made changes (e.g. move the region)
16465 that require another round of redisplay. */
16466 clear_glyph_matrix (w
->desired_matrix
);
16467 if (!try_window (window
, startp
, 0))
16468 goto need_larger_matrices
;
16471 if (w
->cursor
.vpos
< 0 || !cursor_row_fully_visible_p (w
, false, false))
16473 clear_glyph_matrix (w
->desired_matrix
);
16474 goto try_to_scroll
;
16478 debug_method_add (w
, "forced window start");
16483 /* Handle case where text has not changed, only point, and it has
16484 not moved off the frame, and we are not retrying after hscroll.
16485 (current_matrix_up_to_date_p is true when retrying.) */
16486 if (current_matrix_up_to_date_p
16487 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
16488 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
16492 case CURSOR_MOVEMENT_SUCCESS
:
16493 used_current_matrix_p
= true;
16496 case CURSOR_MOVEMENT_MUST_SCROLL
:
16497 goto try_to_scroll
;
16503 /* If current starting point was originally the beginning of a line
16504 but no longer is, find a new starting point. */
16505 else if (w
->start_at_line_beg
16506 && !(CHARPOS (startp
) <= BEGV
16507 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
16510 debug_method_add (w
, "recenter 1");
16515 /* Try scrolling with try_window_id. Value is > 0 if update has
16516 been done, it is -1 if we know that the same window start will
16517 not work. It is 0 if unsuccessful for some other reason. */
16518 else if ((tem
= try_window_id (w
)) != 0)
16521 debug_method_add (w
, "try_window_id %d", tem
);
16524 if (f
->fonts_changed
)
16525 goto need_larger_matrices
;
16529 /* Otherwise try_window_id has returned -1 which means that we
16530 don't want the alternative below this comment to execute. */
16532 else if (CHARPOS (startp
) >= BEGV
16533 && CHARPOS (startp
) <= ZV
16534 && PT
>= CHARPOS (startp
)
16535 && (CHARPOS (startp
) < ZV
16536 /* Avoid starting at end of buffer. */
16537 || CHARPOS (startp
) == BEGV
16538 || !window_outdated (w
)))
16540 int d1
, d2
, d5
, d6
;
16543 /* If first window line is a continuation line, and window start
16544 is inside the modified region, but the first change is before
16545 current window start, we must select a new window start.
16547 However, if this is the result of a down-mouse event (e.g. by
16548 extending the mouse-drag-overlay), we don't want to select a
16549 new window start, since that would change the position under
16550 the mouse, resulting in an unwanted mouse-movement rather
16551 than a simple mouse-click. */
16552 if (!w
->start_at_line_beg
16553 && NILP (do_mouse_tracking
)
16554 && CHARPOS (startp
) > BEGV
16555 && CHARPOS (startp
) > BEG
+ beg_unchanged
16556 && CHARPOS (startp
) <= Z
- end_unchanged
16557 /* Even if w->start_at_line_beg is nil, a new window may
16558 start at a line_beg, since that's how set_buffer_window
16559 sets it. So, we need to check the return value of
16560 compute_window_start_on_continuation_line. (See also
16562 && XMARKER (w
->start
)->buffer
== current_buffer
16563 && compute_window_start_on_continuation_line (w
)
16564 /* It doesn't make sense to force the window start like we
16565 do at label force_start if it is already known that point
16566 will not be fully visible in the resulting window, because
16567 doing so will move point from its correct position
16568 instead of scrolling the window to bring point into view.
16570 && pos_visible_p (w
, PT
, &d1
, &d2
, &rtop
, &rbot
, &d5
, &d6
)
16571 /* A very tall row could need more than the window height,
16572 in which case we accept that it is partially visible. */
16573 && (rtop
!= 0) == (rbot
!= 0))
16575 w
->force_start
= true;
16576 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16578 debug_method_add (w
, "recomputed window start in continuation line");
16584 debug_method_add (w
, "same window start");
16587 /* Try to redisplay starting at same place as before.
16588 If point has not moved off frame, accept the results. */
16589 if (!current_matrix_up_to_date_p
16590 /* Don't use try_window_reusing_current_matrix in this case
16591 because a window scroll function can have changed the
16593 || !NILP (Vwindow_scroll_functions
)
16594 || MINI_WINDOW_P (w
)
16595 || !(used_current_matrix_p
16596 = try_window_reusing_current_matrix (w
)))
16598 IF_DEBUG (debug_method_add (w
, "1"));
16599 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16600 /* -1 means we need to scroll.
16601 0 means we need new matrices, but fonts_changed
16602 is set in that case, so we will detect it below. */
16603 goto try_to_scroll
;
16606 if (f
->fonts_changed
)
16607 goto need_larger_matrices
;
16609 if (w
->cursor
.vpos
>= 0)
16611 if (!just_this_one_p
16612 || current_buffer
->clip_changed
16613 || BEG_UNCHANGED
< CHARPOS (startp
))
16614 /* Forget any recorded base line for line number display. */
16615 w
->base_line_number
= 0;
16617 if (!cursor_row_fully_visible_p (w
, true, false))
16619 clear_glyph_matrix (w
->desired_matrix
);
16620 last_line_misfit
= true;
16622 /* Drop through and scroll. */
16627 clear_glyph_matrix (w
->desired_matrix
);
16632 /* Redisplay the mode line. Select the buffer properly for that. */
16633 if (!update_mode_line
)
16635 update_mode_line
= true;
16636 w
->update_mode_line
= true;
16639 /* Try to scroll by specified few lines. */
16640 if ((scroll_conservatively
16641 || emacs_scroll_step
16642 || temp_scroll_step
16643 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16644 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16645 && CHARPOS (startp
) >= BEGV
16646 && CHARPOS (startp
) <= ZV
)
16648 /* The function returns -1 if new fonts were loaded, 1 if
16649 successful, 0 if not successful. */
16650 int ss
= try_scrolling (window
, just_this_one_p
,
16651 scroll_conservatively
,
16653 temp_scroll_step
, last_line_misfit
);
16656 case SCROLLING_SUCCESS
:
16659 case SCROLLING_NEED_LARGER_MATRICES
:
16660 goto need_larger_matrices
;
16662 case SCROLLING_FAILED
:
16670 /* Finally, just choose a place to start which positions point
16671 according to user preferences. */
16676 debug_method_add (w
, "recenter");
16679 /* Forget any previously recorded base line for line number display. */
16680 if (!buffer_unchanged_p
)
16681 w
->base_line_number
= 0;
16683 /* Determine the window start relative to point. */
16684 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16685 it
.current_y
= it
.last_visible_y
;
16686 if (centering_position
< 0)
16688 int window_total_lines
16689 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16691 = scroll_margin
> 0
16692 ? min (scroll_margin
, window_total_lines
/ 4)
16694 ptrdiff_t margin_pos
= CHARPOS (startp
);
16695 Lisp_Object aggressive
;
16698 /* If there is a scroll margin at the top of the window, find
16699 its character position. */
16701 /* Cannot call start_display if startp is not in the
16702 accessible region of the buffer. This can happen when we
16703 have just switched to a different buffer and/or changed
16704 its restriction. In that case, startp is initialized to
16705 the character position 1 (BEGV) because we did not yet
16706 have chance to display the buffer even once. */
16707 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16710 void *it1data
= NULL
;
16712 SAVE_IT (it1
, it
, it1data
);
16713 start_display (&it1
, w
, startp
);
16714 move_it_vertically (&it1
, margin
* frame_line_height
);
16715 margin_pos
= IT_CHARPOS (it1
);
16716 RESTORE_IT (&it
, &it
, it1data
);
16718 scrolling_up
= PT
> margin_pos
;
16721 ? BVAR (current_buffer
, scroll_up_aggressively
)
16722 : BVAR (current_buffer
, scroll_down_aggressively
);
16724 if (!MINI_WINDOW_P (w
)
16725 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16729 /* Setting scroll-conservatively overrides
16730 scroll-*-aggressively. */
16731 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16733 double float_amount
= XFLOATINT (aggressive
);
16735 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16736 if (pt_offset
== 0 && float_amount
> 0)
16738 if (pt_offset
&& margin
> 0)
16741 /* Compute how much to move the window start backward from
16742 point so that point will be displayed where the user
16746 centering_position
= it
.last_visible_y
;
16748 centering_position
-= pt_offset
;
16749 centering_position
-=
16750 (frame_line_height
* (1 + margin
+ last_line_misfit
)
16751 + WINDOW_HEADER_LINE_HEIGHT (w
));
16752 /* Don't let point enter the scroll margin near top of
16754 if (centering_position
< margin
* frame_line_height
)
16755 centering_position
= margin
* frame_line_height
;
16758 centering_position
= margin
* frame_line_height
+ pt_offset
;
16761 /* Set the window start half the height of the window backward
16763 centering_position
= window_box_height (w
) / 2;
16765 move_it_vertically_backward (&it
, centering_position
);
16767 eassert (IT_CHARPOS (it
) >= BEGV
);
16769 /* The function move_it_vertically_backward may move over more
16770 than the specified y-distance. If it->w is small, e.g. a
16771 mini-buffer window, we may end up in front of the window's
16772 display area. Start displaying at the start of the line
16773 containing PT in this case. */
16774 if (it
.current_y
<= 0)
16776 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16777 move_it_vertically_backward (&it
, 0);
16781 it
.current_x
= it
.hpos
= 0;
16783 /* Set the window start position here explicitly, to avoid an
16784 infinite loop in case the functions in window-scroll-functions
16786 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16788 /* Run scroll hooks. */
16789 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16791 /* Redisplay the window. */
16792 bool use_desired_matrix
= false;
16793 if (!current_matrix_up_to_date_p
16794 || windows_or_buffers_changed
16795 || f
->cursor_type_changed
16796 /* Don't use try_window_reusing_current_matrix in this case
16797 because it can have changed the buffer. */
16798 || !NILP (Vwindow_scroll_functions
)
16799 || !just_this_one_p
16800 || MINI_WINDOW_P (w
)
16801 || !(used_current_matrix_p
16802 = try_window_reusing_current_matrix (w
)))
16803 use_desired_matrix
= (try_window (window
, startp
, 0) == 1);
16805 /* If new fonts have been loaded (due to fontsets), give up. We
16806 have to start a new redisplay since we need to re-adjust glyph
16808 if (f
->fonts_changed
)
16809 goto need_larger_matrices
;
16811 /* If cursor did not appear assume that the middle of the window is
16812 in the first line of the window. Do it again with the next line.
16813 (Imagine a window of height 100, displaying two lines of height
16814 60. Moving back 50 from it->last_visible_y will end in the first
16816 if (w
->cursor
.vpos
< 0)
16818 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16820 clear_glyph_matrix (w
->desired_matrix
);
16821 move_it_by_lines (&it
, 1);
16822 try_window (window
, it
.current
.pos
, 0);
16824 else if (PT
< IT_CHARPOS (it
))
16826 clear_glyph_matrix (w
->desired_matrix
);
16827 move_it_by_lines (&it
, -1);
16828 try_window (window
, it
.current
.pos
, 0);
16832 /* Not much we can do about it. */
16836 /* Consider the following case: Window starts at BEGV, there is
16837 invisible, intangible text at BEGV, so that display starts at
16838 some point START > BEGV. It can happen that we are called with
16839 PT somewhere between BEGV and START. Try to handle that case,
16840 and similar ones. */
16841 if (w
->cursor
.vpos
< 0)
16843 /* Prefer the desired matrix to the current matrix, if possible,
16844 in the fallback calculations below. This is because using
16845 the current matrix might completely goof, e.g. if its first
16846 row is after point. */
16847 struct glyph_matrix
*matrix
=
16848 use_desired_matrix
? w
->desired_matrix
: w
->current_matrix
;
16849 /* First, try locating the proper glyph row for PT. */
16850 struct glyph_row
*row
=
16851 row_containing_pos (w
, PT
, matrix
->rows
, NULL
, 0);
16853 /* Sometimes point is at the beginning of invisible text that is
16854 before the 1st character displayed in the row. In that case,
16855 row_containing_pos fails to find the row, because no glyphs
16856 with appropriate buffer positions are present in the row.
16857 Therefore, we next try to find the row which shows the 1st
16858 position after the invisible text. */
16862 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16865 if (TEXT_PROP_MEANS_INVISIBLE (val
) != 0)
16868 Lisp_Object invis_end
=
16869 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16872 if (NATNUMP (invis_end
))
16873 alt_pos
= XFASTINT (invis_end
);
16876 row
= row_containing_pos (w
, alt_pos
, matrix
->rows
, NULL
, 0);
16879 /* Finally, fall back on the first row of the window after the
16880 header line (if any). This is slightly better than not
16881 displaying the cursor at all. */
16884 row
= matrix
->rows
;
16885 if (row
->mode_line_p
)
16888 set_cursor_from_row (w
, row
, matrix
, 0, 0, 0, 0);
16891 if (!cursor_row_fully_visible_p (w
, false, false))
16893 /* If vscroll is enabled, disable it and try again. */
16897 clear_glyph_matrix (w
->desired_matrix
);
16901 /* Users who set scroll-conservatively to a large number want
16902 point just above/below the scroll margin. If we ended up
16903 with point's row partially visible, move the window start to
16904 make that row fully visible and out of the margin. */
16905 if (scroll_conservatively
> SCROLL_LIMIT
)
16907 int window_total_lines
16908 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16911 ? min (scroll_margin
, window_total_lines
/ 4)
16913 bool move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16915 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16916 clear_glyph_matrix (w
->desired_matrix
);
16917 if (1 == try_window (window
, it
.current
.pos
,
16918 TRY_WINDOW_CHECK_MARGINS
))
16922 /* If centering point failed to make the whole line visible,
16923 put point at the top instead. That has to make the whole line
16924 visible, if it can be done. */
16925 if (centering_position
== 0)
16928 clear_glyph_matrix (w
->desired_matrix
);
16929 centering_position
= 0;
16935 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16936 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16937 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16939 /* Display the mode line, if we must. */
16940 if ((update_mode_line
16941 /* If window not full width, must redo its mode line
16942 if (a) the window to its side is being redone and
16943 (b) we do a frame-based redisplay. This is a consequence
16944 of how inverted lines are drawn in frame-based redisplay. */
16945 || (!just_this_one_p
16946 && !FRAME_WINDOW_P (f
)
16947 && !WINDOW_FULL_WIDTH_P (w
))
16948 /* Line number to display. */
16949 || w
->base_line_pos
> 0
16950 /* Column number is displayed and different from the one displayed. */
16951 || (w
->column_number_displayed
!= -1
16952 && (w
->column_number_displayed
!= current_column ())))
16953 /* This means that the window has a mode line. */
16954 && (WINDOW_WANTS_MODELINE_P (w
)
16955 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16958 display_mode_lines (w
);
16960 /* If mode line height has changed, arrange for a thorough
16961 immediate redisplay using the correct mode line height. */
16962 if (WINDOW_WANTS_MODELINE_P (w
)
16963 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16965 f
->fonts_changed
= true;
16966 w
->mode_line_height
= -1;
16967 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16968 = DESIRED_MODE_LINE_HEIGHT (w
);
16971 /* If header line height has changed, arrange for a thorough
16972 immediate redisplay using the correct header line height. */
16973 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16974 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16976 f
->fonts_changed
= true;
16977 w
->header_line_height
= -1;
16978 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16979 = DESIRED_HEADER_LINE_HEIGHT (w
);
16982 if (f
->fonts_changed
)
16983 goto need_larger_matrices
;
16986 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16988 w
->base_line_pos
= 0;
16989 w
->base_line_number
= 0;
16994 /* When we reach a frame's selected window, redo the frame's menu
16995 bar and the frame's title. */
16996 if (update_mode_line
16997 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16999 bool redisplay_menu_p
;
17001 if (FRAME_WINDOW_P (f
))
17003 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
17004 || defined (HAVE_NS) || defined (USE_GTK)
17005 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
17007 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
17011 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
17013 if (redisplay_menu_p
)
17014 display_menu_bar (w
);
17016 #ifdef HAVE_WINDOW_SYSTEM
17017 if (FRAME_WINDOW_P (f
))
17019 #if defined (USE_GTK) || defined (HAVE_NS)
17020 if (FRAME_EXTERNAL_TOOL_BAR (f
))
17021 redisplay_tool_bar (f
);
17023 if (WINDOWP (f
->tool_bar_window
)
17024 && (FRAME_TOOL_BAR_LINES (f
) > 0
17025 || !NILP (Vauto_resize_tool_bars
))
17026 && redisplay_tool_bar (f
))
17027 ignore_mouse_drag_p
= true;
17030 x_consider_frame_title (w
->frame
);
17034 #ifdef HAVE_WINDOW_SYSTEM
17035 if (FRAME_WINDOW_P (f
)
17036 && update_window_fringes (w
, (just_this_one_p
17037 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
17038 || w
->pseudo_window_p
)))
17042 if (draw_window_fringes (w
, true))
17044 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
17045 x_draw_right_divider (w
);
17047 x_draw_vertical_border (w
);
17053 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
17054 x_draw_bottom_divider (w
);
17055 #endif /* HAVE_WINDOW_SYSTEM */
17057 /* We go to this label, with fonts_changed set, if it is
17058 necessary to try again using larger glyph matrices.
17059 We have to redeem the scroll bar even in this case,
17060 because the loop in redisplay_internal expects that. */
17061 need_larger_matrices
:
17063 finish_scroll_bars
:
17065 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
) || WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
17067 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
17068 /* Set the thumb's position and size. */
17069 set_vertical_scroll_bar (w
);
17071 if (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
17072 /* Set the thumb's position and size. */
17073 set_horizontal_scroll_bar (w
);
17075 /* Note that we actually used the scroll bar attached to this
17076 window, so it shouldn't be deleted at the end of redisplay. */
17077 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
17078 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
17081 /* Restore current_buffer and value of point in it. The window
17082 update may have changed the buffer, so first make sure `opoint'
17083 is still valid (Bug#6177). */
17084 if (CHARPOS (opoint
) < BEGV
)
17085 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17086 else if (CHARPOS (opoint
) > ZV
)
17087 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
17089 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
17091 set_buffer_internal_1 (old
);
17092 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
17093 shorter. This can be caused by log truncation in *Messages*. */
17094 if (CHARPOS (lpoint
) <= ZV
)
17095 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17097 unbind_to (count
, Qnil
);
17101 /* Build the complete desired matrix of WINDOW with a window start
17102 buffer position POS.
17104 Value is 1 if successful. It is zero if fonts were loaded during
17105 redisplay which makes re-adjusting glyph matrices necessary, and -1
17106 if point would appear in the scroll margins.
17107 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
17108 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
17112 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
17114 struct window
*w
= XWINDOW (window
);
17116 struct glyph_row
*last_text_row
= NULL
;
17117 struct frame
*f
= XFRAME (w
->frame
);
17118 int frame_line_height
= default_line_pixel_height (w
);
17120 /* Make POS the new window start. */
17121 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
17123 /* Mark cursor position as unknown. No overlay arrow seen. */
17124 w
->cursor
.vpos
= -1;
17125 overlay_arrow_seen
= false;
17127 /* Initialize iterator and info to start at POS. */
17128 start_display (&it
, w
, pos
);
17129 it
.glyph_row
->reversed_p
= false;
17131 /* Display all lines of W. */
17132 while (it
.current_y
< it
.last_visible_y
)
17134 if (display_line (&it
))
17135 last_text_row
= it
.glyph_row
- 1;
17136 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
17140 /* Don't let the cursor end in the scroll margins. */
17141 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
17142 && !MINI_WINDOW_P (w
))
17144 int this_scroll_margin
;
17145 int window_total_lines
17146 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
17148 if (scroll_margin
> 0)
17150 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
17151 this_scroll_margin
*= frame_line_height
;
17154 this_scroll_margin
= 0;
17156 if ((w
->cursor
.y
>= 0 /* not vscrolled */
17157 && w
->cursor
.y
< this_scroll_margin
17158 && CHARPOS (pos
) > BEGV
17159 && IT_CHARPOS (it
) < ZV
)
17160 /* rms: considering make_cursor_line_fully_visible_p here
17161 seems to give wrong results. We don't want to recenter
17162 when the last line is partly visible, we want to allow
17163 that case to be handled in the usual way. */
17164 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
17166 w
->cursor
.vpos
= -1;
17167 clear_glyph_matrix (w
->desired_matrix
);
17172 /* If bottom moved off end of frame, change mode line percentage. */
17173 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
17174 w
->update_mode_line
= true;
17176 /* Set window_end_pos to the offset of the last character displayed
17177 on the window from the end of current_buffer. Set
17178 window_end_vpos to its row number. */
17181 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
17182 adjust_window_ends (w
, last_text_row
, false);
17184 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
17185 w
->window_end_vpos
)));
17189 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17190 w
->window_end_pos
= Z
- ZV
;
17191 w
->window_end_vpos
= 0;
17194 /* But that is not valid info until redisplay finishes. */
17195 w
->window_end_valid
= false;
17201 /************************************************************************
17202 Window redisplay reusing current matrix when buffer has not changed
17203 ************************************************************************/
17205 /* Try redisplay of window W showing an unchanged buffer with a
17206 different window start than the last time it was displayed by
17207 reusing its current matrix. Value is true if successful.
17208 W->start is the new window start. */
17211 try_window_reusing_current_matrix (struct window
*w
)
17213 struct frame
*f
= XFRAME (w
->frame
);
17214 struct glyph_row
*bottom_row
;
17217 struct text_pos start
, new_start
;
17218 int nrows_scrolled
, i
;
17219 struct glyph_row
*last_text_row
;
17220 struct glyph_row
*last_reused_text_row
;
17221 struct glyph_row
*start_row
;
17222 int start_vpos
, min_y
, max_y
;
17225 if (inhibit_try_window_reusing
)
17229 if (/* This function doesn't handle terminal frames. */
17230 !FRAME_WINDOW_P (f
)
17231 /* Don't try to reuse the display if windows have been split
17233 || windows_or_buffers_changed
17234 || f
->cursor_type_changed
)
17237 /* Can't do this if showing trailing whitespace. */
17238 if (!NILP (Vshow_trailing_whitespace
))
17241 /* If top-line visibility has changed, give up. */
17242 if (WINDOW_WANTS_HEADER_LINE_P (w
)
17243 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
17246 /* Give up if old or new display is scrolled vertically. We could
17247 make this function handle this, but right now it doesn't. */
17248 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17249 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
17252 /* The variable new_start now holds the new window start. The old
17253 start `start' can be determined from the current matrix. */
17254 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
17255 start
= start_row
->minpos
;
17256 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17258 /* Clear the desired matrix for the display below. */
17259 clear_glyph_matrix (w
->desired_matrix
);
17261 if (CHARPOS (new_start
) <= CHARPOS (start
))
17263 /* Don't use this method if the display starts with an ellipsis
17264 displayed for invisible text. It's not easy to handle that case
17265 below, and it's certainly not worth the effort since this is
17266 not a frequent case. */
17267 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
17270 IF_DEBUG (debug_method_add (w
, "twu1"));
17272 /* Display up to a row that can be reused. The variable
17273 last_text_row is set to the last row displayed that displays
17274 text. Note that it.vpos == 0 if or if not there is a
17275 header-line; it's not the same as the MATRIX_ROW_VPOS! */
17276 start_display (&it
, w
, new_start
);
17277 w
->cursor
.vpos
= -1;
17278 last_text_row
= last_reused_text_row
= NULL
;
17280 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17282 /* If we have reached into the characters in the START row,
17283 that means the line boundaries have changed. So we
17284 can't start copying with the row START. Maybe it will
17285 work to start copying with the following row. */
17286 while (IT_CHARPOS (it
) > CHARPOS (start
))
17288 /* Advance to the next row as the "start". */
17290 start
= start_row
->minpos
;
17291 /* If there are no more rows to try, or just one, give up. */
17292 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
17293 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
17294 || CHARPOS (start
) == ZV
)
17296 clear_glyph_matrix (w
->desired_matrix
);
17300 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17302 /* If we have reached alignment, we can copy the rest of the
17304 if (IT_CHARPOS (it
) == CHARPOS (start
)
17305 /* Don't accept "alignment" inside a display vector,
17306 since start_row could have started in the middle of
17307 that same display vector (thus their character
17308 positions match), and we have no way of telling if
17309 that is the case. */
17310 && it
.current
.dpvec_index
< 0)
17313 it
.glyph_row
->reversed_p
= false;
17314 if (display_line (&it
))
17315 last_text_row
= it
.glyph_row
- 1;
17319 /* A value of current_y < last_visible_y means that we stopped
17320 at the previous window start, which in turn means that we
17321 have at least one reusable row. */
17322 if (it
.current_y
< it
.last_visible_y
)
17324 struct glyph_row
*row
;
17326 /* IT.vpos always starts from 0; it counts text lines. */
17327 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
17329 /* Find PT if not already found in the lines displayed. */
17330 if (w
->cursor
.vpos
< 0)
17332 int dy
= it
.current_y
- start_row
->y
;
17334 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17335 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
17337 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
17338 dy
, nrows_scrolled
);
17341 clear_glyph_matrix (w
->desired_matrix
);
17346 /* Scroll the display. Do it before the current matrix is
17347 changed. The problem here is that update has not yet
17348 run, i.e. part of the current matrix is not up to date.
17349 scroll_run_hook will clear the cursor, and use the
17350 current matrix to get the height of the row the cursor is
17352 run
.current_y
= start_row
->y
;
17353 run
.desired_y
= it
.current_y
;
17354 run
.height
= it
.last_visible_y
- it
.current_y
;
17356 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
17359 FRAME_RIF (f
)->update_window_begin_hook (w
);
17360 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17361 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17362 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17366 /* Shift current matrix down by nrows_scrolled lines. */
17367 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17368 rotate_matrix (w
->current_matrix
,
17370 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17373 /* Disable lines that must be updated. */
17374 for (i
= 0; i
< nrows_scrolled
; ++i
)
17375 (start_row
+ i
)->enabled_p
= false;
17377 /* Re-compute Y positions. */
17378 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17379 max_y
= it
.last_visible_y
;
17380 for (row
= start_row
+ nrows_scrolled
;
17384 row
->y
= it
.current_y
;
17385 row
->visible_height
= row
->height
;
17387 if (row
->y
< min_y
)
17388 row
->visible_height
-= min_y
- row
->y
;
17389 if (row
->y
+ row
->height
> max_y
)
17390 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17391 if (row
->fringe_bitmap_periodic_p
)
17392 row
->redraw_fringe_bitmaps_p
= true;
17394 it
.current_y
+= row
->height
;
17396 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17397 last_reused_text_row
= row
;
17398 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
17402 /* Disable lines in the current matrix which are now
17403 below the window. */
17404 for (++row
; row
< bottom_row
; ++row
)
17405 row
->enabled_p
= row
->mode_line_p
= false;
17408 /* Update window_end_pos etc.; last_reused_text_row is the last
17409 reused row from the current matrix containing text, if any.
17410 The value of last_text_row is the last displayed line
17411 containing text. */
17412 if (last_reused_text_row
)
17413 adjust_window_ends (w
, last_reused_text_row
, true);
17414 else if (last_text_row
)
17415 adjust_window_ends (w
, last_text_row
, false);
17418 /* This window must be completely empty. */
17419 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17420 w
->window_end_pos
= Z
- ZV
;
17421 w
->window_end_vpos
= 0;
17423 w
->window_end_valid
= false;
17425 /* Update hint: don't try scrolling again in update_window. */
17426 w
->desired_matrix
->no_scrolling_p
= true;
17429 debug_method_add (w
, "try_window_reusing_current_matrix 1");
17433 else if (CHARPOS (new_start
) > CHARPOS (start
))
17435 struct glyph_row
*pt_row
, *row
;
17436 struct glyph_row
*first_reusable_row
;
17437 struct glyph_row
*first_row_to_display
;
17439 int yb
= window_text_bottom_y (w
);
17441 /* Find the row starting at new_start, if there is one. Don't
17442 reuse a partially visible line at the end. */
17443 first_reusable_row
= start_row
;
17444 while (first_reusable_row
->enabled_p
17445 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
17446 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17447 < CHARPOS (new_start
)))
17448 ++first_reusable_row
;
17450 /* Give up if there is no row to reuse. */
17451 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
17452 || !first_reusable_row
->enabled_p
17453 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17454 != CHARPOS (new_start
)))
17457 /* We can reuse fully visible rows beginning with
17458 first_reusable_row to the end of the window. Set
17459 first_row_to_display to the first row that cannot be reused.
17460 Set pt_row to the row containing point, if there is any. */
17462 for (first_row_to_display
= first_reusable_row
;
17463 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
17464 ++first_row_to_display
)
17466 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
17467 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17468 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17469 && first_row_to_display
->ends_at_zv_p
17470 && pt_row
== NULL
)))
17471 pt_row
= first_row_to_display
;
17474 /* Start displaying at the start of first_row_to_display. */
17475 eassert (first_row_to_display
->y
< yb
);
17476 init_to_row_start (&it
, w
, first_row_to_display
);
17478 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
17480 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
17482 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
17483 + WINDOW_HEADER_LINE_HEIGHT (w
));
17485 /* Display lines beginning with first_row_to_display in the
17486 desired matrix. Set last_text_row to the last row displayed
17487 that displays text. */
17488 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
17489 if (pt_row
== NULL
)
17490 w
->cursor
.vpos
= -1;
17491 last_text_row
= NULL
;
17492 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17493 if (display_line (&it
))
17494 last_text_row
= it
.glyph_row
- 1;
17496 /* If point is in a reused row, adjust y and vpos of the cursor
17500 w
->cursor
.vpos
-= nrows_scrolled
;
17501 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
17504 /* Give up if point isn't in a row displayed or reused. (This
17505 also handles the case where w->cursor.vpos < nrows_scrolled
17506 after the calls to display_line, which can happen with scroll
17507 margins. See bug#1295.) */
17508 if (w
->cursor
.vpos
< 0)
17510 clear_glyph_matrix (w
->desired_matrix
);
17514 /* Scroll the display. */
17515 run
.current_y
= first_reusable_row
->y
;
17516 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17517 run
.height
= it
.last_visible_y
- run
.current_y
;
17518 dy
= run
.current_y
- run
.desired_y
;
17523 FRAME_RIF (f
)->update_window_begin_hook (w
);
17524 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17525 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17526 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17530 /* Adjust Y positions of reused rows. */
17531 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17532 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17533 max_y
= it
.last_visible_y
;
17534 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
17537 row
->visible_height
= row
->height
;
17538 if (row
->y
< min_y
)
17539 row
->visible_height
-= min_y
- row
->y
;
17540 if (row
->y
+ row
->height
> max_y
)
17541 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17542 if (row
->fringe_bitmap_periodic_p
)
17543 row
->redraw_fringe_bitmaps_p
= true;
17546 /* Scroll the current matrix. */
17547 eassert (nrows_scrolled
> 0);
17548 rotate_matrix (w
->current_matrix
,
17550 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17553 /* Disable rows not reused. */
17554 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
17555 row
->enabled_p
= false;
17557 /* Point may have moved to a different line, so we cannot assume that
17558 the previous cursor position is valid; locate the correct row. */
17561 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
17563 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
17564 && !row
->ends_at_zv_p
;
17568 w
->cursor
.y
= row
->y
;
17570 if (row
< bottom_row
)
17572 /* Can't simply scan the row for point with
17573 bidi-reordered glyph rows. Let set_cursor_from_row
17574 figure out where to put the cursor, and if it fails,
17576 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
17578 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
17581 clear_glyph_matrix (w
->desired_matrix
);
17587 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
17588 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17591 && (!BUFFERP (glyph
->object
)
17592 || glyph
->charpos
< PT
);
17596 w
->cursor
.x
+= glyph
->pixel_width
;
17602 /* Adjust window end. A null value of last_text_row means that
17603 the window end is in reused rows which in turn means that
17604 only its vpos can have changed. */
17606 adjust_window_ends (w
, last_text_row
, false);
17608 w
->window_end_vpos
-= nrows_scrolled
;
17610 w
->window_end_valid
= false;
17611 w
->desired_matrix
->no_scrolling_p
= true;
17614 debug_method_add (w
, "try_window_reusing_current_matrix 2");
17624 /************************************************************************
17625 Window redisplay reusing current matrix when buffer has changed
17626 ************************************************************************/
17628 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
17629 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17630 ptrdiff_t *, ptrdiff_t *);
17631 static struct glyph_row
*
17632 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17633 struct glyph_row
*);
17636 /* Return the last row in MATRIX displaying text. If row START is
17637 non-null, start searching with that row. IT gives the dimensions
17638 of the display. Value is null if matrix is empty; otherwise it is
17639 a pointer to the row found. */
17641 static struct glyph_row
*
17642 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17643 struct glyph_row
*start
)
17645 struct glyph_row
*row
, *row_found
;
17647 /* Set row_found to the last row in IT->w's current matrix
17648 displaying text. The loop looks funny but think of partially
17651 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17652 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17654 eassert (row
->enabled_p
);
17656 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17665 /* Return the last row in the current matrix of W that is not affected
17666 by changes at the start of current_buffer that occurred since W's
17667 current matrix was built. Value is null if no such row exists.
17669 BEG_UNCHANGED us the number of characters unchanged at the start of
17670 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17671 first changed character in current_buffer. Characters at positions <
17672 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17673 when the current matrix was built. */
17675 static struct glyph_row
*
17676 find_last_unchanged_at_beg_row (struct window
*w
)
17678 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17679 struct glyph_row
*row
;
17680 struct glyph_row
*row_found
= NULL
;
17681 int yb
= window_text_bottom_y (w
);
17683 /* Find the last row displaying unchanged text. */
17684 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17685 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17686 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17689 if (/* If row ends before first_changed_pos, it is unchanged,
17690 except in some case. */
17691 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17692 /* When row ends in ZV and we write at ZV it is not
17694 && !row
->ends_at_zv_p
17695 /* When first_changed_pos is the end of a continued line,
17696 row is not unchanged because it may be no longer
17698 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17699 && (row
->continued_p
17700 || row
->exact_window_width_line_p
))
17701 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17702 needs to be recomputed, so don't consider this row as
17703 unchanged. This happens when the last line was
17704 bidi-reordered and was killed immediately before this
17705 redisplay cycle. In that case, ROW->end stores the
17706 buffer position of the first visual-order character of
17707 the killed text, which is now beyond ZV. */
17708 && CHARPOS (row
->end
.pos
) <= ZV
)
17711 /* Stop if last visible row. */
17712 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17720 /* Find the first glyph row in the current matrix of W that is not
17721 affected by changes at the end of current_buffer since the
17722 time W's current matrix was built.
17724 Return in *DELTA the number of chars by which buffer positions in
17725 unchanged text at the end of current_buffer must be adjusted.
17727 Return in *DELTA_BYTES the corresponding number of bytes.
17729 Value is null if no such row exists, i.e. all rows are affected by
17732 static struct glyph_row
*
17733 find_first_unchanged_at_end_row (struct window
*w
,
17734 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17736 struct glyph_row
*row
;
17737 struct glyph_row
*row_found
= NULL
;
17739 *delta
= *delta_bytes
= 0;
17741 /* Display must not have been paused, otherwise the current matrix
17742 is not up to date. */
17743 eassert (w
->window_end_valid
);
17745 /* A value of window_end_pos >= END_UNCHANGED means that the window
17746 end is in the range of changed text. If so, there is no
17747 unchanged row at the end of W's current matrix. */
17748 if (w
->window_end_pos
>= END_UNCHANGED
)
17751 /* Set row to the last row in W's current matrix displaying text. */
17752 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17754 /* If matrix is entirely empty, no unchanged row exists. */
17755 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17757 /* The value of row is the last glyph row in the matrix having a
17758 meaningful buffer position in it. The end position of row
17759 corresponds to window_end_pos. This allows us to translate
17760 buffer positions in the current matrix to current buffer
17761 positions for characters not in changed text. */
17763 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17764 ptrdiff_t Z_BYTE_old
=
17765 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17766 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17767 struct glyph_row
*first_text_row
17768 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17770 *delta
= Z
- Z_old
;
17771 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17773 /* Set last_unchanged_pos to the buffer position of the last
17774 character in the buffer that has not been changed. Z is the
17775 index + 1 of the last character in current_buffer, i.e. by
17776 subtracting END_UNCHANGED we get the index of the last
17777 unchanged character, and we have to add BEG to get its buffer
17779 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17780 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17782 /* Search backward from ROW for a row displaying a line that
17783 starts at a minimum position >= last_unchanged_pos_old. */
17784 for (; row
> first_text_row
; --row
)
17786 /* This used to abort, but it can happen.
17787 It is ok to just stop the search instead here. KFS. */
17788 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17791 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17796 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17802 /* Make sure that glyph rows in the current matrix of window W
17803 reference the same glyph memory as corresponding rows in the
17804 frame's frame matrix. This function is called after scrolling W's
17805 current matrix on a terminal frame in try_window_id and
17806 try_window_reusing_current_matrix. */
17809 sync_frame_with_window_matrix_rows (struct window
*w
)
17811 struct frame
*f
= XFRAME (w
->frame
);
17812 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17814 /* Preconditions: W must be a leaf window and full-width. Its frame
17815 must have a frame matrix. */
17816 eassert (BUFFERP (w
->contents
));
17817 eassert (WINDOW_FULL_WIDTH_P (w
));
17818 eassert (!FRAME_WINDOW_P (f
));
17820 /* If W is a full-width window, glyph pointers in W's current matrix
17821 have, by definition, to be the same as glyph pointers in the
17822 corresponding frame matrix. Note that frame matrices have no
17823 marginal areas (see build_frame_matrix). */
17824 window_row
= w
->current_matrix
->rows
;
17825 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17826 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17827 while (window_row
< window_row_end
)
17829 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17830 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17832 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17833 frame_row
->glyphs
[TEXT_AREA
] = start
;
17834 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17835 frame_row
->glyphs
[LAST_AREA
] = end
;
17837 /* Disable frame rows whose corresponding window rows have
17838 been disabled in try_window_id. */
17839 if (!window_row
->enabled_p
)
17840 frame_row
->enabled_p
= false;
17842 ++window_row
, ++frame_row
;
17847 /* Find the glyph row in window W containing CHARPOS. Consider all
17848 rows between START and END (not inclusive). END null means search
17849 all rows to the end of the display area of W. Value is the row
17850 containing CHARPOS or null. */
17853 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17854 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17856 struct glyph_row
*row
= start
;
17857 struct glyph_row
*best_row
= NULL
;
17858 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17861 /* If we happen to start on a header-line, skip that. */
17862 if (row
->mode_line_p
)
17865 if ((end
&& row
>= end
) || !row
->enabled_p
)
17868 last_y
= window_text_bottom_y (w
) - dy
;
17872 /* Give up if we have gone too far. */
17873 if ((end
&& row
>= end
) || !row
->enabled_p
)
17875 /* This formerly returned if they were equal.
17876 I think that both quantities are of a "last plus one" type;
17877 if so, when they are equal, the row is within the screen. -- rms. */
17878 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17881 /* If it is in this row, return this row. */
17882 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17883 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17884 /* The end position of a row equals the start
17885 position of the next row. If CHARPOS is there, we
17886 would rather consider it displayed in the next
17887 line, except when this line ends in ZV. */
17888 && !row_for_charpos_p (row
, charpos
)))
17889 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17893 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17894 || (!best_row
&& !row
->continued_p
))
17896 /* In bidi-reordered rows, there could be several rows whose
17897 edges surround CHARPOS, all of these rows belonging to
17898 the same continued line. We need to find the row which
17899 fits CHARPOS the best. */
17900 for (g
= row
->glyphs
[TEXT_AREA
];
17901 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17904 if (!STRINGP (g
->object
))
17906 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17908 mindif
= eabs (g
->charpos
- charpos
);
17910 /* Exact match always wins. */
17917 else if (best_row
&& !row
->continued_p
)
17924 /* Try to redisplay window W by reusing its existing display. W's
17925 current matrix must be up to date when this function is called,
17926 i.e., window_end_valid must be true.
17930 >= 1 if successful, i.e. display has been updated
17932 1 means the changes were in front of a newline that precedes
17933 the window start, and the whole current matrix was reused
17934 2 means the changes were after the last position displayed
17935 in the window, and the whole current matrix was reused
17936 3 means portions of the current matrix were reused, while
17937 some of the screen lines were redrawn
17938 -1 if redisplay with same window start is known not to succeed
17939 0 if otherwise unsuccessful
17941 The following steps are performed:
17943 1. Find the last row in the current matrix of W that is not
17944 affected by changes at the start of current_buffer. If no such row
17947 2. Find the first row in W's current matrix that is not affected by
17948 changes at the end of current_buffer. Maybe there is no such row.
17950 3. Display lines beginning with the row + 1 found in step 1 to the
17951 row found in step 2 or, if step 2 didn't find a row, to the end of
17954 4. If cursor is not known to appear on the window, give up.
17956 5. If display stopped at the row found in step 2, scroll the
17957 display and current matrix as needed.
17959 6. Maybe display some lines at the end of W, if we must. This can
17960 happen under various circumstances, like a partially visible line
17961 becoming fully visible, or because newly displayed lines are displayed
17962 in smaller font sizes.
17964 7. Update W's window end information. */
17967 try_window_id (struct window
*w
)
17969 struct frame
*f
= XFRAME (w
->frame
);
17970 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17971 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17972 struct glyph_row
*last_unchanged_at_beg_row
;
17973 struct glyph_row
*first_unchanged_at_end_row
;
17974 struct glyph_row
*row
;
17975 struct glyph_row
*bottom_row
;
17978 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17980 struct text_pos start_pos
;
17982 int first_unchanged_at_end_vpos
= 0;
17983 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17984 struct text_pos start
;
17985 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17988 if (inhibit_try_window_id
)
17992 /* This is handy for debugging. */
17994 #define GIVE_UP(X) \
17996 TRACE ((stderr, "try_window_id give up %d\n", (X))); \
18000 #define GIVE_UP(X) return 0
18003 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
18005 /* Don't use this for mini-windows because these can show
18006 messages and mini-buffers, and we don't handle that here. */
18007 if (MINI_WINDOW_P (w
))
18010 /* This flag is used to prevent redisplay optimizations. */
18011 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
18014 /* This function's optimizations cannot be used if overlays have
18015 changed in the buffer displayed by the window, so give up if they
18017 if (w
->last_overlay_modified
!= OVERLAY_MODIFF
)
18020 /* Verify that narrowing has not changed.
18021 Also verify that we were not told to prevent redisplay optimizations.
18022 It would be nice to further
18023 reduce the number of cases where this prevents try_window_id. */
18024 if (current_buffer
->clip_changed
18025 || current_buffer
->prevent_redisplay_optimizations_p
)
18028 /* Window must either use window-based redisplay or be full width. */
18029 if (!FRAME_WINDOW_P (f
)
18030 && (!FRAME_LINE_INS_DEL_OK (f
)
18031 || !WINDOW_FULL_WIDTH_P (w
)))
18034 /* Give up if point is known NOT to appear in W. */
18035 if (PT
< CHARPOS (start
))
18038 /* Another way to prevent redisplay optimizations. */
18039 if (w
->last_modified
== 0)
18042 /* Verify that window is not hscrolled. */
18043 if (w
->hscroll
!= 0)
18046 /* Verify that display wasn't paused. */
18047 if (!w
->window_end_valid
)
18050 /* Likewise if highlighting trailing whitespace. */
18051 if (!NILP (Vshow_trailing_whitespace
))
18054 /* Can't use this if overlay arrow position and/or string have
18056 if (overlay_arrows_changed_p ())
18059 /* When word-wrap is on, adding a space to the first word of a
18060 wrapped line can change the wrap position, altering the line
18061 above it. It might be worthwhile to handle this more
18062 intelligently, but for now just redisplay from scratch. */
18063 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
18066 /* Under bidi reordering, adding or deleting a character in the
18067 beginning of a paragraph, before the first strong directional
18068 character, can change the base direction of the paragraph (unless
18069 the buffer specifies a fixed paragraph direction), which will
18070 require to redisplay the whole paragraph. It might be worthwhile
18071 to find the paragraph limits and widen the range of redisplayed
18072 lines to that, but for now just give up this optimization and
18073 redisplay from scratch. */
18074 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
18075 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
18078 /* Give up if the buffer has line-spacing set, as Lisp-level changes
18079 to that variable require thorough redisplay. */
18080 if (!NILP (BVAR (XBUFFER (w
->contents
), extra_line_spacing
)))
18083 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
18084 only if buffer has really changed. The reason is that the gap is
18085 initially at Z for freshly visited files. The code below would
18086 set end_unchanged to 0 in that case. */
18087 if (MODIFF
> SAVE_MODIFF
18088 /* This seems to happen sometimes after saving a buffer. */
18089 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
18091 if (GPT
- BEG
< BEG_UNCHANGED
)
18092 BEG_UNCHANGED
= GPT
- BEG
;
18093 if (Z
- GPT
< END_UNCHANGED
)
18094 END_UNCHANGED
= Z
- GPT
;
18097 /* The position of the first and last character that has been changed. */
18098 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
18099 last_changed_charpos
= Z
- END_UNCHANGED
;
18101 /* If window starts after a line end, and the last change is in
18102 front of that newline, then changes don't affect the display.
18103 This case happens with stealth-fontification. Note that although
18104 the display is unchanged, glyph positions in the matrix have to
18105 be adjusted, of course. */
18106 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
18107 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
18108 && ((last_changed_charpos
< CHARPOS (start
)
18109 && CHARPOS (start
) == BEGV
)
18110 || (last_changed_charpos
< CHARPOS (start
) - 1
18111 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
18113 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
18114 struct glyph_row
*r0
;
18116 /* Compute how many chars/bytes have been added to or removed
18117 from the buffer. */
18118 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
18119 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
18120 Z_delta
= Z
- Z_old
;
18121 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
18123 /* Give up if PT is not in the window. Note that it already has
18124 been checked at the start of try_window_id that PT is not in
18125 front of the window start. */
18126 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
18129 /* If window start is unchanged, we can reuse the whole matrix
18130 as is, after adjusting glyph positions. No need to compute
18131 the window end again, since its offset from Z hasn't changed. */
18132 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18133 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
18134 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
18135 /* PT must not be in a partially visible line. */
18136 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
18137 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
18139 /* Adjust positions in the glyph matrix. */
18140 if (Z_delta
|| Z_delta_bytes
)
18142 struct glyph_row
*r1
18143 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18144 increment_matrix_positions (w
->current_matrix
,
18145 MATRIX_ROW_VPOS (r0
, current_matrix
),
18146 MATRIX_ROW_VPOS (r1
, current_matrix
),
18147 Z_delta
, Z_delta_bytes
);
18150 /* Set the cursor. */
18151 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
18153 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
18158 /* Handle the case that changes are all below what is displayed in
18159 the window, and that PT is in the window. This shortcut cannot
18160 be taken if ZV is visible in the window, and text has been added
18161 there that is visible in the window. */
18162 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
18163 /* ZV is not visible in the window, or there are no
18164 changes at ZV, actually. */
18165 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
18166 || first_changed_charpos
== last_changed_charpos
))
18168 struct glyph_row
*r0
;
18170 /* Give up if PT is not in the window. Note that it already has
18171 been checked at the start of try_window_id that PT is not in
18172 front of the window start. */
18173 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
18176 /* If window start is unchanged, we can reuse the whole matrix
18177 as is, without changing glyph positions since no text has
18178 been added/removed in front of the window end. */
18179 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18180 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
18181 /* PT must not be in a partially visible line. */
18182 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
18183 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
18185 /* We have to compute the window end anew since text
18186 could have been added/removed after it. */
18187 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18188 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18190 /* Set the cursor. */
18191 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
18193 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
18198 /* Give up if window start is in the changed area.
18200 The condition used to read
18202 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
18204 but why that was tested escapes me at the moment. */
18205 if (CHARPOS (start
) >= first_changed_charpos
18206 && CHARPOS (start
) <= last_changed_charpos
)
18209 /* Check that window start agrees with the start of the first glyph
18210 row in its current matrix. Check this after we know the window
18211 start is not in changed text, otherwise positions would not be
18213 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18214 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
18217 /* Give up if the window ends in strings. Overlay strings
18218 at the end are difficult to handle, so don't try. */
18219 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
18220 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
18223 /* Compute the position at which we have to start displaying new
18224 lines. Some of the lines at the top of the window might be
18225 reusable because they are not displaying changed text. Find the
18226 last row in W's current matrix not affected by changes at the
18227 start of current_buffer. Value is null if changes start in the
18228 first line of window. */
18229 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
18230 if (last_unchanged_at_beg_row
)
18232 /* Avoid starting to display in the middle of a character, a TAB
18233 for instance. This is easier than to set up the iterator
18234 exactly, and it's not a frequent case, so the additional
18235 effort wouldn't really pay off. */
18236 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
18237 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
18238 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
18239 --last_unchanged_at_beg_row
;
18241 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
18244 if (! init_to_row_end (&it
, w
, last_unchanged_at_beg_row
))
18246 start_pos
= it
.current
.pos
;
18248 /* Start displaying new lines in the desired matrix at the same
18249 vpos we would use in the current matrix, i.e. below
18250 last_unchanged_at_beg_row. */
18251 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
18253 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18254 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
18256 eassert (it
.hpos
== 0 && it
.current_x
== 0);
18260 /* There are no reusable lines at the start of the window.
18261 Start displaying in the first text line. */
18262 start_display (&it
, w
, start
);
18263 it
.vpos
= it
.first_vpos
;
18264 start_pos
= it
.current
.pos
;
18267 /* Find the first row that is not affected by changes at the end of
18268 the buffer. Value will be null if there is no unchanged row, in
18269 which case we must redisplay to the end of the window. delta
18270 will be set to the value by which buffer positions beginning with
18271 first_unchanged_at_end_row have to be adjusted due to text
18273 first_unchanged_at_end_row
18274 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
18275 IF_DEBUG (debug_delta
= delta
);
18276 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
18278 /* Set stop_pos to the buffer position up to which we will have to
18279 display new lines. If first_unchanged_at_end_row != NULL, this
18280 is the buffer position of the start of the line displayed in that
18281 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
18282 that we don't stop at a buffer position. */
18284 if (first_unchanged_at_end_row
)
18286 eassert (last_unchanged_at_beg_row
== NULL
18287 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
18289 /* If this is a continuation line, move forward to the next one
18290 that isn't. Changes in lines above affect this line.
18291 Caution: this may move first_unchanged_at_end_row to a row
18292 not displaying text. */
18293 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
18294 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18295 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18296 < it
.last_visible_y
))
18297 ++first_unchanged_at_end_row
;
18299 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18300 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18301 >= it
.last_visible_y
))
18302 first_unchanged_at_end_row
= NULL
;
18305 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
18307 first_unchanged_at_end_vpos
18308 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
18309 eassert (stop_pos
>= Z
- END_UNCHANGED
);
18312 else if (last_unchanged_at_beg_row
== NULL
)
18318 /* Either there is no unchanged row at the end, or the one we have
18319 now displays text. This is a necessary condition for the window
18320 end pos calculation at the end of this function. */
18321 eassert (first_unchanged_at_end_row
== NULL
18322 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18324 debug_last_unchanged_at_beg_vpos
18325 = (last_unchanged_at_beg_row
18326 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
18328 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
18330 #endif /* GLYPH_DEBUG */
18333 /* Display new lines. Set last_text_row to the last new line
18334 displayed which has text on it, i.e. might end up as being the
18335 line where the window_end_vpos is. */
18336 w
->cursor
.vpos
= -1;
18337 last_text_row
= NULL
;
18338 overlay_arrow_seen
= false;
18339 if (it
.current_y
< it
.last_visible_y
18340 && !f
->fonts_changed
18341 && (first_unchanged_at_end_row
== NULL
18342 || IT_CHARPOS (it
) < stop_pos
))
18343 it
.glyph_row
->reversed_p
= false;
18344 while (it
.current_y
< it
.last_visible_y
18345 && !f
->fonts_changed
18346 && (first_unchanged_at_end_row
== NULL
18347 || IT_CHARPOS (it
) < stop_pos
))
18349 if (display_line (&it
))
18350 last_text_row
= it
.glyph_row
- 1;
18353 if (f
->fonts_changed
)
18356 /* The redisplay iterations in display_line above could have
18357 triggered font-lock, which could have done something that
18358 invalidates IT->w window's end-point information, on which we
18359 rely below. E.g., one package, which will remain unnamed, used
18360 to install a font-lock-fontify-region-function that called
18361 bury-buffer, whose side effect is to switch the buffer displayed
18362 by IT->w, and that predictably resets IT->w's window_end_valid
18363 flag, which we already tested at the entry to this function.
18364 Amply punish such packages/modes by giving up on this
18365 optimization in those cases. */
18366 if (!w
->window_end_valid
)
18368 clear_glyph_matrix (w
->desired_matrix
);
18372 /* Compute differences in buffer positions, y-positions etc. for
18373 lines reused at the bottom of the window. Compute what we can
18375 if (first_unchanged_at_end_row
18376 /* No lines reused because we displayed everything up to the
18377 bottom of the window. */
18378 && it
.current_y
< it
.last_visible_y
)
18381 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
18383 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
18384 run
.current_y
= first_unchanged_at_end_row
->y
;
18385 run
.desired_y
= run
.current_y
+ dy
;
18386 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
18390 delta
= delta_bytes
= dvpos
= dy
18391 = run
.current_y
= run
.desired_y
= run
.height
= 0;
18392 first_unchanged_at_end_row
= NULL
;
18394 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
18397 /* Find the cursor if not already found. We have to decide whether
18398 PT will appear on this window (it sometimes doesn't, but this is
18399 not a very frequent case.) This decision has to be made before
18400 the current matrix is altered. A value of cursor.vpos < 0 means
18401 that PT is either in one of the lines beginning at
18402 first_unchanged_at_end_row or below the window. Don't care for
18403 lines that might be displayed later at the window end; as
18404 mentioned, this is not a frequent case. */
18405 if (w
->cursor
.vpos
< 0)
18407 /* Cursor in unchanged rows at the top? */
18408 if (PT
< CHARPOS (start_pos
)
18409 && last_unchanged_at_beg_row
)
18411 row
= row_containing_pos (w
, PT
,
18412 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
18413 last_unchanged_at_beg_row
+ 1, 0);
18415 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
18418 /* Start from first_unchanged_at_end_row looking for PT. */
18419 else if (first_unchanged_at_end_row
)
18421 row
= row_containing_pos (w
, PT
- delta
,
18422 first_unchanged_at_end_row
, NULL
, 0);
18424 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
18425 delta_bytes
, dy
, dvpos
);
18428 /* Give up if cursor was not found. */
18429 if (w
->cursor
.vpos
< 0)
18431 clear_glyph_matrix (w
->desired_matrix
);
18436 /* Don't let the cursor end in the scroll margins. */
18438 int this_scroll_margin
, cursor_height
;
18439 int frame_line_height
= default_line_pixel_height (w
);
18440 int window_total_lines
18441 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
18443 this_scroll_margin
=
18444 max (0, min (scroll_margin
, window_total_lines
/ 4));
18445 this_scroll_margin
*= frame_line_height
;
18446 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
18448 if ((w
->cursor
.y
< this_scroll_margin
18449 && CHARPOS (start
) > BEGV
)
18450 /* Old redisplay didn't take scroll margin into account at the bottom,
18451 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
18452 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
18453 ? cursor_height
+ this_scroll_margin
18454 : 1)) > it
.last_visible_y
)
18456 w
->cursor
.vpos
= -1;
18457 clear_glyph_matrix (w
->desired_matrix
);
18462 /* Scroll the display. Do it before changing the current matrix so
18463 that xterm.c doesn't get confused about where the cursor glyph is
18465 if (dy
&& run
.height
)
18469 if (FRAME_WINDOW_P (f
))
18471 FRAME_RIF (f
)->update_window_begin_hook (w
);
18472 FRAME_RIF (f
)->clear_window_mouse_face (w
);
18473 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
18474 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
18478 /* Terminal frame. In this case, dvpos gives the number of
18479 lines to scroll by; dvpos < 0 means scroll up. */
18481 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
18482 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
18483 int end
= (WINDOW_TOP_EDGE_LINE (w
)
18484 + WINDOW_WANTS_HEADER_LINE_P (w
)
18485 + window_internal_height (w
));
18487 #if defined (HAVE_GPM) || defined (MSDOS)
18488 x_clear_window_mouse_face (w
);
18490 /* Perform the operation on the screen. */
18493 /* Scroll last_unchanged_at_beg_row to the end of the
18494 window down dvpos lines. */
18495 set_terminal_window (f
, end
);
18497 /* On dumb terminals delete dvpos lines at the end
18498 before inserting dvpos empty lines. */
18499 if (!FRAME_SCROLL_REGION_OK (f
))
18500 ins_del_lines (f
, end
- dvpos
, -dvpos
);
18502 /* Insert dvpos empty lines in front of
18503 last_unchanged_at_beg_row. */
18504 ins_del_lines (f
, from
, dvpos
);
18506 else if (dvpos
< 0)
18508 /* Scroll up last_unchanged_at_beg_vpos to the end of
18509 the window to last_unchanged_at_beg_vpos - |dvpos|. */
18510 set_terminal_window (f
, end
);
18512 /* Delete dvpos lines in front of
18513 last_unchanged_at_beg_vpos. ins_del_lines will set
18514 the cursor to the given vpos and emit |dvpos| delete
18516 ins_del_lines (f
, from
+ dvpos
, dvpos
);
18518 /* On a dumb terminal insert dvpos empty lines at the
18520 if (!FRAME_SCROLL_REGION_OK (f
))
18521 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
18524 set_terminal_window (f
, 0);
18530 /* Shift reused rows of the current matrix to the right position.
18531 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
18533 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18534 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
18537 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
18538 bottom_vpos
, dvpos
);
18539 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
18542 else if (dvpos
> 0)
18544 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
18545 bottom_vpos
, dvpos
);
18546 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
18547 first_unchanged_at_end_vpos
+ dvpos
);
18550 /* For frame-based redisplay, make sure that current frame and window
18551 matrix are in sync with respect to glyph memory. */
18552 if (!FRAME_WINDOW_P (f
))
18553 sync_frame_with_window_matrix_rows (w
);
18555 /* Adjust buffer positions in reused rows. */
18556 if (delta
|| delta_bytes
)
18557 increment_matrix_positions (current_matrix
,
18558 first_unchanged_at_end_vpos
+ dvpos
,
18559 bottom_vpos
, delta
, delta_bytes
);
18561 /* Adjust Y positions. */
18563 shift_glyph_matrix (w
, current_matrix
,
18564 first_unchanged_at_end_vpos
+ dvpos
,
18567 if (first_unchanged_at_end_row
)
18569 first_unchanged_at_end_row
+= dvpos
;
18570 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
18571 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
18572 first_unchanged_at_end_row
= NULL
;
18575 /* If scrolling up, there may be some lines to display at the end of
18577 last_text_row_at_end
= NULL
;
18580 /* Scrolling up can leave for example a partially visible line
18581 at the end of the window to be redisplayed. */
18582 /* Set last_row to the glyph row in the current matrix where the
18583 window end line is found. It has been moved up or down in
18584 the matrix by dvpos. */
18585 int last_vpos
= w
->window_end_vpos
+ dvpos
;
18586 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
18588 /* If last_row is the window end line, it should display text. */
18589 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
18591 /* If window end line was partially visible before, begin
18592 displaying at that line. Otherwise begin displaying with the
18593 line following it. */
18594 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
18596 init_to_row_start (&it
, w
, last_row
);
18597 it
.vpos
= last_vpos
;
18598 it
.current_y
= last_row
->y
;
18602 init_to_row_end (&it
, w
, last_row
);
18603 it
.vpos
= 1 + last_vpos
;
18604 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
18608 /* We may start in a continuation line. If so, we have to
18609 get the right continuation_lines_width and current_x. */
18610 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
18611 it
.hpos
= it
.current_x
= 0;
18613 /* Display the rest of the lines at the window end. */
18614 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18615 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
18617 /* Is it always sure that the display agrees with lines in
18618 the current matrix? I don't think so, so we mark rows
18619 displayed invalid in the current matrix by setting their
18620 enabled_p flag to false. */
18621 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
18622 if (display_line (&it
))
18623 last_text_row_at_end
= it
.glyph_row
- 1;
18627 /* Update window_end_pos and window_end_vpos. */
18628 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
18630 /* Window end line if one of the preserved rows from the current
18631 matrix. Set row to the last row displaying text in current
18632 matrix starting at first_unchanged_at_end_row, after
18634 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18635 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
18636 first_unchanged_at_end_row
);
18637 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
18638 adjust_window_ends (w
, row
, true);
18639 eassert (w
->window_end_bytepos
>= 0);
18640 IF_DEBUG (debug_method_add (w
, "A"));
18642 else if (last_text_row_at_end
)
18644 adjust_window_ends (w
, last_text_row_at_end
, false);
18645 eassert (w
->window_end_bytepos
>= 0);
18646 IF_DEBUG (debug_method_add (w
, "B"));
18648 else if (last_text_row
)
18650 /* We have displayed either to the end of the window or at the
18651 end of the window, i.e. the last row with text is to be found
18652 in the desired matrix. */
18653 adjust_window_ends (w
, last_text_row
, false);
18654 eassert (w
->window_end_bytepos
>= 0);
18656 else if (first_unchanged_at_end_row
== NULL
18657 && last_text_row
== NULL
18658 && last_text_row_at_end
== NULL
)
18660 /* Displayed to end of window, but no line containing text was
18661 displayed. Lines were deleted at the end of the window. */
18662 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
18663 int vpos
= w
->window_end_vpos
;
18664 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
18665 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18668 row
== NULL
&& vpos
>= first_vpos
;
18669 --vpos
, --current_row
, --desired_row
)
18671 if (desired_row
->enabled_p
)
18673 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18676 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18680 eassert (row
!= NULL
);
18681 w
->window_end_vpos
= vpos
+ 1;
18682 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18683 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18684 eassert (w
->window_end_bytepos
>= 0);
18685 IF_DEBUG (debug_method_add (w
, "C"));
18690 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18691 debug_end_vpos
= w
->window_end_vpos
));
18693 /* Record that display has not been completed. */
18694 w
->window_end_valid
= false;
18695 w
->desired_matrix
->no_scrolling_p
= true;
18703 /***********************************************************************
18704 More debugging support
18705 ***********************************************************************/
18709 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18710 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18711 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18714 /* Dump the contents of glyph matrix MATRIX on stderr.
18716 GLYPHS 0 means don't show glyph contents.
18717 GLYPHS 1 means show glyphs in short form
18718 GLYPHS > 1 means show glyphs in long form. */
18721 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18724 for (i
= 0; i
< matrix
->nrows
; ++i
)
18725 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18729 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18730 the glyph row and area where the glyph comes from. */
18733 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18735 if (glyph
->type
== CHAR_GLYPH
18736 || glyph
->type
== GLYPHLESS_GLYPH
)
18739 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18740 glyph
- row
->glyphs
[TEXT_AREA
],
18741 (glyph
->type
== CHAR_GLYPH
18745 (BUFFERP (glyph
->object
)
18747 : (STRINGP (glyph
->object
)
18749 : (NILP (glyph
->object
)
18752 glyph
->pixel_width
,
18754 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18758 glyph
->left_box_line_p
,
18759 glyph
->right_box_line_p
);
18761 else if (glyph
->type
== STRETCH_GLYPH
)
18764 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18765 glyph
- row
->glyphs
[TEXT_AREA
],
18768 (BUFFERP (glyph
->object
)
18770 : (STRINGP (glyph
->object
)
18772 : (NILP (glyph
->object
)
18775 glyph
->pixel_width
,
18779 glyph
->left_box_line_p
,
18780 glyph
->right_box_line_p
);
18782 else if (glyph
->type
== IMAGE_GLYPH
)
18785 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18786 glyph
- row
->glyphs
[TEXT_AREA
],
18789 (BUFFERP (glyph
->object
)
18791 : (STRINGP (glyph
->object
)
18793 : (NILP (glyph
->object
)
18796 glyph
->pixel_width
,
18800 glyph
->left_box_line_p
,
18801 glyph
->right_box_line_p
);
18803 else if (glyph
->type
== COMPOSITE_GLYPH
)
18806 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18807 glyph
- row
->glyphs
[TEXT_AREA
],
18810 (BUFFERP (glyph
->object
)
18812 : (STRINGP (glyph
->object
)
18814 : (NILP (glyph
->object
)
18817 glyph
->pixel_width
,
18819 if (glyph
->u
.cmp
.automatic
)
18822 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18823 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18825 glyph
->left_box_line_p
,
18826 glyph
->right_box_line_p
);
18828 else if (glyph
->type
== XWIDGET_GLYPH
)
18831 #ifdef HAVE_XWIDGETS
18832 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18834 " %5d %4c %6d %c %3d %c %4d %1.1d%1.1d\n",
18836 glyph
- row
->glyphs
[TEXT_AREA
],
18839 (BUFFERP (glyph
->object
)
18841 : (STRINGP (glyph
->object
)
18844 glyph
->pixel_width
,
18845 #ifdef HAVE_XWIDGETS
18850 glyph
->left_box_line_p
,
18851 glyph
->right_box_line_p
);
18857 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18858 GLYPHS 0 means don't show glyph contents.
18859 GLYPHS 1 means show glyphs in short form
18860 GLYPHS > 1 means show glyphs in long form. */
18863 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18867 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18868 fprintf (stderr
, "==============================================================================\n");
18870 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18871 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18873 MATRIX_ROW_START_CHARPOS (row
),
18874 MATRIX_ROW_END_CHARPOS (row
),
18875 row
->used
[TEXT_AREA
],
18876 row
->contains_overlapping_glyphs_p
,
18878 row
->truncated_on_left_p
,
18879 row
->truncated_on_right_p
,
18881 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18882 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18885 row
->ends_in_middle_of_char_p
,
18886 row
->starts_in_middle_of_char_p
,
18892 row
->visible_height
,
18895 /* The next 3 lines should align to "Start" in the header. */
18896 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18897 row
->end
.overlay_string_index
,
18898 row
->continuation_lines_width
);
18899 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18900 CHARPOS (row
->start
.string_pos
),
18901 CHARPOS (row
->end
.string_pos
));
18902 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18903 row
->end
.dpvec_index
);
18910 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18912 struct glyph
*glyph
= row
->glyphs
[area
];
18913 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18915 /* Glyph for a line end in text. */
18916 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18919 if (glyph
< glyph_end
)
18920 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18922 for (; glyph
< glyph_end
; ++glyph
)
18923 dump_glyph (row
, glyph
, area
);
18926 else if (glyphs
== 1)
18929 char s
[SHRT_MAX
+ 4];
18931 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18935 for (i
= 0; i
< row
->used
[area
]; ++i
)
18937 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18938 if (i
== row
->used
[area
] - 1
18939 && area
== TEXT_AREA
18940 && NILP (glyph
->object
)
18941 && glyph
->type
== CHAR_GLYPH
18942 && glyph
->u
.ch
== ' ')
18944 strcpy (&s
[i
], "[\\n]");
18947 else if (glyph
->type
== CHAR_GLYPH
18948 && glyph
->u
.ch
< 0x80
18949 && glyph
->u
.ch
>= ' ')
18950 s
[i
] = glyph
->u
.ch
;
18956 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18962 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18963 Sdump_glyph_matrix
, 0, 1, "p",
18964 doc
: /* Dump the current matrix of the selected window to stderr.
18965 Shows contents of glyph row structures. With non-nil
18966 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18967 glyphs in short form, otherwise show glyphs in long form.
18969 Interactively, no argument means show glyphs in short form;
18970 with numeric argument, its value is passed as the GLYPHS flag. */)
18971 (Lisp_Object glyphs
)
18973 struct window
*w
= XWINDOW (selected_window
);
18974 struct buffer
*buffer
= XBUFFER (w
->contents
);
18976 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18977 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18978 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18979 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18980 fprintf (stderr
, "=============================================\n");
18981 dump_glyph_matrix (w
->current_matrix
,
18982 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18987 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18988 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* Dump the current glyph matrix of the selected frame to stderr.
18989 Only text-mode frames have frame glyph matrices. */)
18992 struct frame
*f
= XFRAME (selected_frame
);
18994 if (f
->current_matrix
)
18995 dump_glyph_matrix (f
->current_matrix
, 1);
18997 fprintf (stderr
, "*** This frame doesn't have a frame glyph matrix ***\n");
19002 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
19003 doc
: /* Dump glyph row ROW to stderr.
19004 GLYPH 0 means don't dump glyphs.
19005 GLYPH 1 means dump glyphs in short form.
19006 GLYPH > 1 or omitted means dump glyphs in long form. */)
19007 (Lisp_Object row
, Lisp_Object glyphs
)
19009 struct glyph_matrix
*matrix
;
19012 CHECK_NUMBER (row
);
19013 matrix
= XWINDOW (selected_window
)->current_matrix
;
19015 if (vpos
>= 0 && vpos
< matrix
->nrows
)
19016 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
19018 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
19023 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
19024 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
19025 GLYPH 0 means don't dump glyphs.
19026 GLYPH 1 means dump glyphs in short form.
19027 GLYPH > 1 or omitted means dump glyphs in long form.
19029 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
19031 (Lisp_Object row
, Lisp_Object glyphs
)
19033 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19034 struct frame
*sf
= SELECTED_FRAME ();
19035 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
19038 CHECK_NUMBER (row
);
19040 if (vpos
>= 0 && vpos
< m
->nrows
)
19041 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
19042 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
19048 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
19049 doc
: /* Toggle tracing of redisplay.
19050 With ARG, turn tracing on if and only if ARG is positive. */)
19054 trace_redisplay_p
= !trace_redisplay_p
;
19057 arg
= Fprefix_numeric_value (arg
);
19058 trace_redisplay_p
= XINT (arg
) > 0;
19065 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
19066 doc
: /* Like `format', but print result to stderr.
19067 usage: (trace-to-stderr STRING &rest OBJECTS) */)
19068 (ptrdiff_t nargs
, Lisp_Object
*args
)
19070 Lisp_Object s
= Fformat (nargs
, args
);
19071 fwrite (SDATA (s
), 1, SBYTES (s
), stderr
);
19075 #endif /* GLYPH_DEBUG */
19079 /***********************************************************************
19080 Building Desired Matrix Rows
19081 ***********************************************************************/
19083 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
19084 Used for non-window-redisplay windows, and for windows w/o left fringe. */
19086 static struct glyph_row
*
19087 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
19089 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19090 struct buffer
*buffer
= XBUFFER (w
->contents
);
19091 struct buffer
*old
= current_buffer
;
19092 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
19093 ptrdiff_t arrow_len
= SCHARS (overlay_arrow_string
);
19094 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
19095 const unsigned char *p
;
19098 int n_glyphs_before
;
19100 set_buffer_temp (buffer
);
19101 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
19102 scratch_glyph_row
.reversed_p
= false;
19103 it
.glyph_row
->used
[TEXT_AREA
] = 0;
19104 SET_TEXT_POS (it
.position
, 0, 0);
19106 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
19108 while (p
< arrow_end
)
19110 Lisp_Object face
, ilisp
;
19112 /* Get the next character. */
19114 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
19117 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
19118 if (! ASCII_CHAR_P (it
.c
))
19119 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
19123 /* Get its face. */
19124 ilisp
= make_number (p
- arrow_string
);
19125 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
19126 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
19128 /* Compute its width, get its glyphs. */
19129 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
19130 SET_TEXT_POS (it
.position
, -1, -1);
19131 PRODUCE_GLYPHS (&it
);
19133 /* If this character doesn't fit any more in the line, we have
19134 to remove some glyphs. */
19135 if (it
.current_x
> it
.last_visible_x
)
19137 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19142 set_buffer_temp (old
);
19143 return it
.glyph_row
;
19147 /* Insert truncation glyphs at the start of IT->glyph_row. Which
19148 glyphs to insert is determined by produce_special_glyphs. */
19151 insert_left_trunc_glyphs (struct it
*it
)
19153 struct it truncate_it
;
19154 struct glyph
*from
, *end
, *to
, *toend
;
19156 eassert (!FRAME_WINDOW_P (it
->f
)
19157 || (!it
->glyph_row
->reversed_p
19158 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19159 || (it
->glyph_row
->reversed_p
19160 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
19162 /* Get the truncation glyphs. */
19164 truncate_it
.current_x
= 0;
19165 truncate_it
.face_id
= DEFAULT_FACE_ID
;
19166 truncate_it
.glyph_row
= &scratch_glyph_row
;
19167 truncate_it
.area
= TEXT_AREA
;
19168 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
19169 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
19170 truncate_it
.object
= Qnil
;
19171 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
19173 /* Overwrite glyphs from IT with truncation glyphs. */
19174 if (!it
->glyph_row
->reversed_p
)
19176 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
19178 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19179 end
= from
+ tused
;
19180 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19181 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
19182 if (FRAME_WINDOW_P (it
->f
))
19184 /* On GUI frames, when variable-size fonts are displayed,
19185 the truncation glyphs may need more pixels than the row's
19186 glyphs they overwrite. We overwrite more glyphs to free
19187 enough screen real estate, and enlarge the stretch glyph
19188 on the right (see display_line), if there is one, to
19189 preserve the screen position of the truncation glyphs on
19192 struct glyph
*g
= to
;
19195 /* The first glyph could be partially visible, in which case
19196 it->glyph_row->x will be negative. But we want the left
19197 truncation glyphs to be aligned at the left margin of the
19198 window, so we override the x coordinate at which the row
19200 it
->glyph_row
->x
= 0;
19201 while (g
< toend
&& w
< it
->truncation_pixel_width
)
19203 w
+= g
->pixel_width
;
19206 if (g
- to
- tused
> 0)
19208 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
19209 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
19211 used
= it
->glyph_row
->used
[TEXT_AREA
];
19212 if (it
->glyph_row
->truncated_on_right_p
19213 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
19214 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
19217 int extra
= w
- it
->truncation_pixel_width
;
19219 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
19226 /* There may be padding glyphs left over. Overwrite them too. */
19227 if (!FRAME_WINDOW_P (it
->f
))
19229 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
19231 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19238 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
19242 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
19244 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
19245 that back to front. */
19246 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19247 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19248 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19249 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19250 if (FRAME_WINDOW_P (it
->f
))
19253 struct glyph
*g
= to
;
19255 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
19257 w
+= g
->pixel_width
;
19260 if (to
- g
- tused
> 0)
19262 if (it
->glyph_row
->truncated_on_right_p
19263 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
19264 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
19266 int extra
= w
- it
->truncation_pixel_width
;
19268 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
19272 while (from
>= end
&& to
>= toend
)
19274 if (!FRAME_WINDOW_P (it
->f
))
19276 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
19279 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
19280 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19281 while (from
>= end
&& to
>= toend
)
19287 /* Need to free some room before prepending additional
19289 int move_by
= from
- end
+ 1;
19290 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19291 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19293 for ( ; g
>= g0
; g
--)
19295 while (from
>= end
)
19297 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
19302 /* Compute the hash code for ROW. */
19304 row_hash (struct glyph_row
*row
)
19307 unsigned hashval
= 0;
19309 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
19310 for (k
= 0; k
< row
->used
[area
]; ++k
)
19311 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
19312 + row
->glyphs
[area
][k
].u
.val
19313 + row
->glyphs
[area
][k
].face_id
19314 + row
->glyphs
[area
][k
].padding_p
19315 + (row
->glyphs
[area
][k
].type
<< 2));
19320 /* Compute the pixel height and width of IT->glyph_row.
19322 Most of the time, ascent and height of a display line will be equal
19323 to the max_ascent and max_height values of the display iterator
19324 structure. This is not the case if
19326 1. We hit ZV without displaying anything. In this case, max_ascent
19327 and max_height will be zero.
19329 2. We have some glyphs that don't contribute to the line height.
19330 (The glyph row flag contributes_to_line_height_p is for future
19331 pixmap extensions).
19333 The first case is easily covered by using default values because in
19334 these cases, the line height does not really matter, except that it
19335 must not be zero. */
19338 compute_line_metrics (struct it
*it
)
19340 struct glyph_row
*row
= it
->glyph_row
;
19342 if (FRAME_WINDOW_P (it
->f
))
19344 int i
, min_y
, max_y
;
19346 /* The line may consist of one space only, that was added to
19347 place the cursor on it. If so, the row's height hasn't been
19349 if (row
->height
== 0)
19351 if (it
->max_ascent
+ it
->max_descent
== 0)
19352 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
19353 row
->ascent
= it
->max_ascent
;
19354 row
->height
= it
->max_ascent
+ it
->max_descent
;
19355 row
->phys_ascent
= it
->max_phys_ascent
;
19356 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19357 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19360 /* Compute the width of this line. */
19361 row
->pixel_width
= row
->x
;
19362 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
19363 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
19365 eassert (row
->pixel_width
>= 0);
19366 eassert (row
->ascent
>= 0 && row
->height
> 0);
19368 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
19369 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
19371 /* If first line's physical ascent is larger than its logical
19372 ascent, use the physical ascent, and make the row taller.
19373 This makes accented characters fully visible. */
19374 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
19375 && row
->phys_ascent
> row
->ascent
)
19377 row
->height
+= row
->phys_ascent
- row
->ascent
;
19378 row
->ascent
= row
->phys_ascent
;
19381 /* Compute how much of the line is visible. */
19382 row
->visible_height
= row
->height
;
19384 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
19385 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
19387 if (row
->y
< min_y
)
19388 row
->visible_height
-= min_y
- row
->y
;
19389 if (row
->y
+ row
->height
> max_y
)
19390 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
19394 row
->pixel_width
= row
->used
[TEXT_AREA
];
19395 if (row
->continued_p
)
19396 row
->pixel_width
-= it
->continuation_pixel_width
;
19397 else if (row
->truncated_on_right_p
)
19398 row
->pixel_width
-= it
->truncation_pixel_width
;
19399 row
->ascent
= row
->phys_ascent
= 0;
19400 row
->height
= row
->phys_height
= row
->visible_height
= 1;
19401 row
->extra_line_spacing
= 0;
19404 /* Compute a hash code for this row. */
19405 row
->hash
= row_hash (row
);
19407 it
->max_ascent
= it
->max_descent
= 0;
19408 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
19412 /* Append one space to the glyph row of iterator IT if doing a
19413 window-based redisplay. The space has the same face as
19414 IT->face_id. Value is true if a space was added.
19416 This function is called to make sure that there is always one glyph
19417 at the end of a glyph row that the cursor can be set on under
19418 window-systems. (If there weren't such a glyph we would not know
19419 how wide and tall a box cursor should be displayed).
19421 At the same time this space let's a nicely handle clearing to the
19422 end of the line if the row ends in italic text. */
19425 append_space_for_newline (struct it
*it
, bool default_face_p
)
19427 if (FRAME_WINDOW_P (it
->f
))
19429 int n
= it
->glyph_row
->used
[TEXT_AREA
];
19431 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
19432 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
19434 /* Save some values that must not be changed.
19435 Must save IT->c and IT->len because otherwise
19436 ITERATOR_AT_END_P wouldn't work anymore after
19437 append_space_for_newline has been called. */
19438 enum display_element_type saved_what
= it
->what
;
19439 int saved_c
= it
->c
, saved_len
= it
->len
;
19440 int saved_char_to_display
= it
->char_to_display
;
19441 int saved_x
= it
->current_x
;
19442 int saved_face_id
= it
->face_id
;
19443 bool saved_box_end
= it
->end_of_box_run_p
;
19444 struct text_pos saved_pos
;
19445 Lisp_Object saved_object
;
19449 saved_object
= it
->object
;
19450 saved_pos
= it
->position
;
19452 it
->what
= IT_CHARACTER
;
19453 memset (&it
->position
, 0, sizeof it
->position
);
19455 it
->c
= it
->char_to_display
= ' ';
19458 /* If the default face was remapped, be sure to use the
19459 remapped face for the appended newline. */
19460 if (default_face_p
)
19461 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
19462 else if (it
->face_before_selective_p
)
19463 it
->face_id
= it
->saved_face_id
;
19464 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19465 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
19466 /* In R2L rows, we will prepend a stretch glyph that will
19467 have the end_of_box_run_p flag set for it, so there's no
19468 need for the appended newline glyph to have that flag
19470 if (it
->glyph_row
->reversed_p
19471 /* But if the appended newline glyph goes all the way to
19472 the end of the row, there will be no stretch glyph,
19473 so leave the box flag set. */
19474 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
19475 it
->end_of_box_run_p
= false;
19477 PRODUCE_GLYPHS (it
);
19479 #ifdef HAVE_WINDOW_SYSTEM
19480 /* Make sure this space glyph has the right ascent and
19481 descent values, or else cursor at end of line will look
19482 funny, and height of empty lines will be incorrect. */
19483 g
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19484 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19487 Lisp_Object height
, total_height
;
19488 int extra_line_spacing
= it
->extra_line_spacing
;
19489 int boff
= font
->baseline_offset
;
19491 if (font
->vertical_centering
)
19492 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19494 it
->object
= saved_object
; /* get_it_property needs this */
19495 normal_char_ascent_descent (font
, -1, &it
->ascent
, &it
->descent
);
19496 /* Must do a subset of line height processing from
19497 x_produce_glyph for newline characters. */
19498 height
= get_it_property (it
, Qline_height
);
19500 && CONSP (XCDR (height
))
19501 && NILP (XCDR (XCDR (height
))))
19503 total_height
= XCAR (XCDR (height
));
19504 height
= XCAR (height
);
19507 total_height
= Qnil
;
19508 height
= calc_line_height_property (it
, height
, font
, boff
, true);
19510 if (it
->override_ascent
>= 0)
19512 it
->ascent
= it
->override_ascent
;
19513 it
->descent
= it
->override_descent
;
19514 boff
= it
->override_boff
;
19516 if (EQ (height
, Qt
))
19517 extra_line_spacing
= 0;
19520 Lisp_Object spacing
;
19522 it
->phys_ascent
= it
->ascent
;
19523 it
->phys_descent
= it
->descent
;
19525 && XINT (height
) > it
->ascent
+ it
->descent
)
19526 it
->ascent
= XINT (height
) - it
->descent
;
19528 if (!NILP (total_height
))
19529 spacing
= calc_line_height_property (it
, total_height
, font
,
19533 spacing
= get_it_property (it
, Qline_spacing
);
19534 spacing
= calc_line_height_property (it
, spacing
, font
,
19537 if (INTEGERP (spacing
))
19539 extra_line_spacing
= XINT (spacing
);
19540 if (!NILP (total_height
))
19541 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19544 if (extra_line_spacing
> 0)
19546 it
->descent
+= extra_line_spacing
;
19547 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19548 it
->max_extra_line_spacing
= extra_line_spacing
;
19550 it
->max_ascent
= it
->ascent
;
19551 it
->max_descent
= it
->descent
;
19552 /* Make sure compute_line_metrics recomputes the row height. */
19553 it
->glyph_row
->height
= 0;
19556 g
->ascent
= it
->max_ascent
;
19557 g
->descent
= it
->max_descent
;
19560 it
->override_ascent
= -1;
19561 it
->constrain_row_ascent_descent_p
= false;
19562 it
->current_x
= saved_x
;
19563 it
->object
= saved_object
;
19564 it
->position
= saved_pos
;
19565 it
->what
= saved_what
;
19566 it
->face_id
= saved_face_id
;
19567 it
->len
= saved_len
;
19569 it
->char_to_display
= saved_char_to_display
;
19570 it
->end_of_box_run_p
= saved_box_end
;
19579 /* Extend the face of the last glyph in the text area of IT->glyph_row
19580 to the end of the display line. Called from display_line. If the
19581 glyph row is empty, add a space glyph to it so that we know the
19582 face to draw. Set the glyph row flag fill_line_p. If the glyph
19583 row is R2L, prepend a stretch glyph to cover the empty space to the
19584 left of the leftmost glyph. */
19587 extend_face_to_end_of_line (struct it
*it
)
19589 struct face
*face
, *default_face
;
19590 struct frame
*f
= it
->f
;
19592 /* If line is already filled, do nothing. Non window-system frames
19593 get a grace of one more ``pixel'' because their characters are
19594 1-``pixel'' wide, so they hit the equality too early. This grace
19595 is needed only for R2L rows that are not continued, to produce
19596 one extra blank where we could display the cursor. */
19597 if ((it
->current_x
>= it
->last_visible_x
19598 + (!FRAME_WINDOW_P (f
)
19599 && it
->glyph_row
->reversed_p
19600 && !it
->glyph_row
->continued_p
))
19601 /* If the window has display margins, we will need to extend
19602 their face even if the text area is filled. */
19603 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19604 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
19607 /* The default face, possibly remapped. */
19608 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
19610 /* Face extension extends the background and box of IT->face_id
19611 to the end of the line. If the background equals the background
19612 of the frame, we don't have to do anything. */
19613 if (it
->face_before_selective_p
)
19614 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
19616 face
= FACE_FROM_ID (f
, it
->face_id
);
19618 if (FRAME_WINDOW_P (f
)
19619 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
19620 && face
->box
== FACE_NO_BOX
19621 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
19622 #ifdef HAVE_WINDOW_SYSTEM
19625 && !it
->glyph_row
->reversed_p
)
19628 /* Set the glyph row flag indicating that the face of the last glyph
19629 in the text area has to be drawn to the end of the text area. */
19630 it
->glyph_row
->fill_line_p
= true;
19632 /* If current character of IT is not ASCII, make sure we have the
19633 ASCII face. This will be automatically undone the next time
19634 get_next_display_element returns a multibyte character. Note
19635 that the character will always be single byte in unibyte
19637 if (!ASCII_CHAR_P (it
->c
))
19639 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
19642 if (FRAME_WINDOW_P (f
))
19644 /* If the row is empty, add a space with the current face of IT,
19645 so that we know which face to draw. */
19646 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
19648 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
19649 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
19650 it
->glyph_row
->used
[TEXT_AREA
] = 1;
19652 /* Mode line and the header line don't have margins, and
19653 likewise the frame's tool-bar window, if there is any. */
19654 if (!(it
->glyph_row
->mode_line_p
19655 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19656 || (WINDOWP (f
->tool_bar_window
)
19657 && it
->w
== XWINDOW (f
->tool_bar_window
))
19661 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19662 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
19664 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
19665 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
=
19667 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
19669 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19670 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
19672 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
19673 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
=
19675 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
19678 #ifdef HAVE_WINDOW_SYSTEM
19679 if (it
->glyph_row
->reversed_p
)
19681 /* Prepend a stretch glyph to the row, such that the
19682 rightmost glyph will be drawn flushed all the way to the
19683 right margin of the window. The stretch glyph that will
19684 occupy the empty space, if any, to the left of the
19686 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
19687 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19688 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
19690 int row_width
, stretch_ascent
, stretch_width
;
19691 struct text_pos saved_pos
;
19693 bool saved_avoid_cursor
, saved_box_start
;
19695 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
19696 row_width
+= g
->pixel_width
;
19698 /* FIXME: There are various minor display glitches in R2L
19699 rows when only one of the fringes is missing. The
19700 strange condition below produces the least bad effect. */
19701 if ((WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19702 == (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
19703 || WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
19704 stretch_width
= window_box_width (it
->w
, TEXT_AREA
);
19706 stretch_width
= it
->last_visible_x
- it
->first_visible_x
;
19707 stretch_width
-= row_width
;
19709 if (stretch_width
> 0)
19712 (((it
->ascent
+ it
->descent
)
19713 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
19714 saved_pos
= it
->position
;
19715 memset (&it
->position
, 0, sizeof it
->position
);
19716 saved_avoid_cursor
= it
->avoid_cursor_p
;
19717 it
->avoid_cursor_p
= true;
19718 saved_face_id
= it
->face_id
;
19719 saved_box_start
= it
->start_of_box_run_p
;
19720 /* The last row's stretch glyph should get the default
19721 face, to avoid painting the rest of the window with
19722 the region face, if the region ends at ZV. */
19723 if (it
->glyph_row
->ends_at_zv_p
)
19724 it
->face_id
= default_face
->id
;
19726 it
->face_id
= face
->id
;
19727 it
->start_of_box_run_p
= false;
19728 append_stretch_glyph (it
, Qnil
, stretch_width
,
19729 it
->ascent
+ it
->descent
, stretch_ascent
);
19730 it
->position
= saved_pos
;
19731 it
->avoid_cursor_p
= saved_avoid_cursor
;
19732 it
->face_id
= saved_face_id
;
19733 it
->start_of_box_run_p
= saved_box_start
;
19735 /* If stretch_width comes out negative, it means that the
19736 last glyph is only partially visible. In R2L rows, we
19737 want the leftmost glyph to be partially visible, so we
19738 need to give the row the corresponding left offset. */
19739 if (stretch_width
< 0)
19740 it
->glyph_row
->x
= stretch_width
;
19742 #endif /* HAVE_WINDOW_SYSTEM */
19746 /* Save some values that must not be changed. */
19747 int saved_x
= it
->current_x
;
19748 struct text_pos saved_pos
;
19749 Lisp_Object saved_object
;
19750 enum display_element_type saved_what
= it
->what
;
19751 int saved_face_id
= it
->face_id
;
19753 saved_object
= it
->object
;
19754 saved_pos
= it
->position
;
19756 it
->what
= IT_CHARACTER
;
19757 memset (&it
->position
, 0, sizeof it
->position
);
19759 it
->c
= it
->char_to_display
= ' ';
19762 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19763 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19764 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19765 && !it
->glyph_row
->mode_line_p
19766 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19768 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
19769 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
19771 for (it
->current_x
= 0; g
< e
; g
++)
19772 it
->current_x
+= g
->pixel_width
;
19774 it
->area
= LEFT_MARGIN_AREA
;
19775 it
->face_id
= default_face
->id
;
19776 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19777 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19779 PRODUCE_GLYPHS (it
);
19780 /* term.c:produce_glyphs advances it->current_x only for
19782 it
->current_x
+= it
->pixel_width
;
19785 it
->current_x
= saved_x
;
19786 it
->area
= TEXT_AREA
;
19789 /* The last row's blank glyphs should get the default face, to
19790 avoid painting the rest of the window with the region face,
19791 if the region ends at ZV. */
19792 if (it
->glyph_row
->ends_at_zv_p
)
19793 it
->face_id
= default_face
->id
;
19795 it
->face_id
= face
->id
;
19796 PRODUCE_GLYPHS (it
);
19798 while (it
->current_x
<= it
->last_visible_x
)
19799 PRODUCE_GLYPHS (it
);
19801 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19802 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19803 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19804 && !it
->glyph_row
->mode_line_p
19805 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19807 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
19808 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19810 for ( ; g
< e
; g
++)
19811 it
->current_x
+= g
->pixel_width
;
19813 it
->area
= RIGHT_MARGIN_AREA
;
19814 it
->face_id
= default_face
->id
;
19815 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19816 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19818 PRODUCE_GLYPHS (it
);
19819 it
->current_x
+= it
->pixel_width
;
19822 it
->area
= TEXT_AREA
;
19825 /* Don't count these blanks really. It would let us insert a left
19826 truncation glyph below and make us set the cursor on them, maybe. */
19827 it
->current_x
= saved_x
;
19828 it
->object
= saved_object
;
19829 it
->position
= saved_pos
;
19830 it
->what
= saved_what
;
19831 it
->face_id
= saved_face_id
;
19836 /* Value is true if text starting at CHARPOS in current_buffer is
19837 trailing whitespace. */
19840 trailing_whitespace_p (ptrdiff_t charpos
)
19842 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19845 while (bytepos
< ZV_BYTE
19846 && (c
= FETCH_CHAR (bytepos
),
19847 c
== ' ' || c
== '\t'))
19850 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19852 if (bytepos
!= PT_BYTE
)
19859 /* Highlight trailing whitespace, if any, in ROW. */
19862 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19864 int used
= row
->used
[TEXT_AREA
];
19868 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19869 struct glyph
*glyph
= start
+ used
- 1;
19871 if (row
->reversed_p
)
19873 /* Right-to-left rows need to be processed in the opposite
19874 direction, so swap the edge pointers. */
19876 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19879 /* Skip over glyphs inserted to display the cursor at the
19880 end of a line, for extending the face of the last glyph
19881 to the end of the line on terminals, and for truncation
19882 and continuation glyphs. */
19883 if (!row
->reversed_p
)
19885 while (glyph
>= start
19886 && glyph
->type
== CHAR_GLYPH
19887 && NILP (glyph
->object
))
19892 while (glyph
<= start
19893 && glyph
->type
== CHAR_GLYPH
19894 && NILP (glyph
->object
))
19898 /* If last glyph is a space or stretch, and it's trailing
19899 whitespace, set the face of all trailing whitespace glyphs in
19900 IT->glyph_row to `trailing-whitespace'. */
19901 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19902 && BUFFERP (glyph
->object
)
19903 && (glyph
->type
== STRETCH_GLYPH
19904 || (glyph
->type
== CHAR_GLYPH
19905 && glyph
->u
.ch
== ' '))
19906 && trailing_whitespace_p (glyph
->charpos
))
19908 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, false);
19912 if (!row
->reversed_p
)
19914 while (glyph
>= start
19915 && BUFFERP (glyph
->object
)
19916 && (glyph
->type
== STRETCH_GLYPH
19917 || (glyph
->type
== CHAR_GLYPH
19918 && glyph
->u
.ch
== ' ')))
19919 (glyph
--)->face_id
= face_id
;
19923 while (glyph
<= start
19924 && BUFFERP (glyph
->object
)
19925 && (glyph
->type
== STRETCH_GLYPH
19926 || (glyph
->type
== CHAR_GLYPH
19927 && glyph
->u
.ch
== ' ')))
19928 (glyph
++)->face_id
= face_id
;
19935 /* Value is true if glyph row ROW should be
19936 considered to hold the buffer position CHARPOS. */
19939 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19941 bool result
= true;
19943 if (charpos
== CHARPOS (row
->end
.pos
)
19944 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19946 /* Suppose the row ends on a string.
19947 Unless the row is continued, that means it ends on a newline
19948 in the string. If it's anything other than a display string
19949 (e.g., a before-string from an overlay), we don't want the
19950 cursor there. (This heuristic seems to give the optimal
19951 behavior for the various types of multi-line strings.)
19952 One exception: if the string has `cursor' property on one of
19953 its characters, we _do_ want the cursor there. */
19954 if (CHARPOS (row
->end
.string_pos
) >= 0)
19956 if (row
->continued_p
)
19960 /* Check for `display' property. */
19961 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19962 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19963 struct glyph
*glyph
;
19966 for (glyph
= end
; glyph
>= beg
; --glyph
)
19967 if (STRINGP (glyph
->object
))
19970 = Fget_char_property (make_number (charpos
),
19974 && display_prop_string_p (prop
, glyph
->object
));
19975 /* If there's a `cursor' property on one of the
19976 string's characters, this row is a cursor row,
19977 even though this is not a display string. */
19980 Lisp_Object s
= glyph
->object
;
19982 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19984 ptrdiff_t gpos
= glyph
->charpos
;
19986 if (!NILP (Fget_char_property (make_number (gpos
),
19998 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
20000 /* If the row ends in middle of a real character,
20001 and the line is continued, we want the cursor here.
20002 That's because CHARPOS (ROW->end.pos) would equal
20003 PT if PT is before the character. */
20004 if (!row
->ends_in_ellipsis_p
)
20005 result
= row
->continued_p
;
20007 /* If the row ends in an ellipsis, then
20008 CHARPOS (ROW->end.pos) will equal point after the
20009 invisible text. We want that position to be displayed
20010 after the ellipsis. */
20013 /* If the row ends at ZV, display the cursor at the end of that
20014 row instead of at the start of the row below. */
20016 result
= row
->ends_at_zv_p
;
20022 /* Value is true if glyph row ROW should be
20023 used to hold the cursor. */
20026 cursor_row_p (struct glyph_row
*row
)
20028 return row_for_charpos_p (row
, PT
);
20033 /* Push the property PROP so that it will be rendered at the current
20034 position in IT. Return true if PROP was successfully pushed, false
20035 otherwise. Called from handle_line_prefix to handle the
20036 `line-prefix' and `wrap-prefix' properties. */
20039 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
20041 struct text_pos pos
=
20042 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
20044 eassert (it
->method
== GET_FROM_BUFFER
20045 || it
->method
== GET_FROM_DISPLAY_VECTOR
20046 || it
->method
== GET_FROM_STRING
20047 || it
->method
== GET_FROM_IMAGE
);
20049 /* We need to save the current buffer/string position, so it will be
20050 restored by pop_it, because iterate_out_of_display_property
20051 depends on that being set correctly, but some situations leave
20052 it->position not yet set when this function is called. */
20053 push_it (it
, &pos
);
20055 if (STRINGP (prop
))
20057 if (SCHARS (prop
) == 0)
20064 it
->string_from_prefix_prop_p
= true;
20065 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
20066 it
->current
.overlay_string_index
= -1;
20067 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
20068 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
20069 it
->method
= GET_FROM_STRING
;
20070 it
->stop_charpos
= 0;
20072 it
->base_level_stop
= 0;
20074 /* Force paragraph direction to be that of the parent
20076 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
20077 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
20079 it
->paragraph_embedding
= L2R
;
20081 /* Set up the bidi iterator for this display string. */
20084 it
->bidi_it
.string
.lstring
= it
->string
;
20085 it
->bidi_it
.string
.s
= NULL
;
20086 it
->bidi_it
.string
.schars
= it
->end_charpos
;
20087 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
20088 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
20089 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
20090 it
->bidi_it
.w
= it
->w
;
20091 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
20094 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
20096 it
->method
= GET_FROM_STRETCH
;
20099 #ifdef HAVE_WINDOW_SYSTEM
20100 else if (IMAGEP (prop
))
20102 it
->what
= IT_IMAGE
;
20103 it
->image_id
= lookup_image (it
->f
, prop
);
20104 it
->method
= GET_FROM_IMAGE
;
20106 #endif /* HAVE_WINDOW_SYSTEM */
20109 pop_it (it
); /* bogus display property, give up */
20116 /* Return the character-property PROP at the current position in IT. */
20119 get_it_property (struct it
*it
, Lisp_Object prop
)
20121 Lisp_Object position
, object
= it
->object
;
20123 if (STRINGP (object
))
20124 position
= make_number (IT_STRING_CHARPOS (*it
));
20125 else if (BUFFERP (object
))
20127 position
= make_number (IT_CHARPOS (*it
));
20128 object
= it
->window
;
20133 return Fget_char_property (position
, prop
, object
);
20136 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
20139 handle_line_prefix (struct it
*it
)
20141 Lisp_Object prefix
;
20143 if (it
->continuation_lines_width
> 0)
20145 prefix
= get_it_property (it
, Qwrap_prefix
);
20147 prefix
= Vwrap_prefix
;
20151 prefix
= get_it_property (it
, Qline_prefix
);
20153 prefix
= Vline_prefix
;
20155 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
20157 /* If the prefix is wider than the window, and we try to wrap
20158 it, it would acquire its own wrap prefix, and so on till the
20159 iterator stack overflows. So, don't wrap the prefix. */
20160 it
->line_wrap
= TRUNCATE
;
20161 it
->avoid_cursor_p
= true;
20167 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
20168 only for R2L lines from display_line and display_string, when they
20169 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
20170 the line/string needs to be continued on the next glyph row. */
20172 unproduce_glyphs (struct it
*it
, int n
)
20174 struct glyph
*glyph
, *end
;
20176 eassert (it
->glyph_row
);
20177 eassert (it
->glyph_row
->reversed_p
);
20178 eassert (it
->area
== TEXT_AREA
);
20179 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
20181 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
20182 n
= it
->glyph_row
->used
[TEXT_AREA
];
20183 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
20184 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
20185 for ( ; glyph
< end
; glyph
++)
20186 glyph
[-n
] = *glyph
;
20189 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
20190 and ROW->maxpos. */
20192 find_row_edges (struct it
*it
, struct glyph_row
*row
,
20193 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
20194 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
20196 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20197 lines' rows is implemented for bidi-reordered rows. */
20199 /* ROW->minpos is the value of min_pos, the minimal buffer position
20200 we have in ROW, or ROW->start.pos if that is smaller. */
20201 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
20202 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
20204 /* We didn't find buffer positions smaller than ROW->start, or
20205 didn't find _any_ valid buffer positions in any of the glyphs,
20206 so we must trust the iterator's computed positions. */
20207 row
->minpos
= row
->start
.pos
;
20210 max_pos
= CHARPOS (it
->current
.pos
);
20211 max_bpos
= BYTEPOS (it
->current
.pos
);
20214 /* Here are the various use-cases for ending the row, and the
20215 corresponding values for ROW->maxpos:
20217 Line ends in a newline from buffer eol_pos + 1
20218 Line is continued from buffer max_pos + 1
20219 Line is truncated on right it->current.pos
20220 Line ends in a newline from string max_pos + 1(*)
20221 (*) + 1 only when line ends in a forward scan
20222 Line is continued from string max_pos
20223 Line is continued from display vector max_pos
20224 Line is entirely from a string min_pos == max_pos
20225 Line is entirely from a display vector min_pos == max_pos
20226 Line that ends at ZV ZV
20228 If you discover other use-cases, please add them here as
20230 if (row
->ends_at_zv_p
)
20231 row
->maxpos
= it
->current
.pos
;
20232 else if (row
->used
[TEXT_AREA
])
20234 bool seen_this_string
= false;
20235 struct glyph_row
*r1
= row
- 1;
20237 /* Did we see the same display string on the previous row? */
20238 if (STRINGP (it
->object
)
20239 /* this is not the first row */
20240 && row
> it
->w
->desired_matrix
->rows
20241 /* previous row is not the header line */
20242 && !r1
->mode_line_p
20243 /* previous row also ends in a newline from a string */
20244 && r1
->ends_in_newline_from_string_p
)
20246 struct glyph
*start
, *end
;
20248 /* Search for the last glyph of the previous row that came
20249 from buffer or string. Depending on whether the row is
20250 L2R or R2L, we need to process it front to back or the
20251 other way round. */
20252 if (!r1
->reversed_p
)
20254 start
= r1
->glyphs
[TEXT_AREA
];
20255 end
= start
+ r1
->used
[TEXT_AREA
];
20256 /* Glyphs inserted by redisplay have nil as their object. */
20258 && NILP ((end
- 1)->object
)
20259 && (end
- 1)->charpos
<= 0)
20263 if (EQ ((end
- 1)->object
, it
->object
))
20264 seen_this_string
= true;
20267 /* If all the glyphs of the previous row were inserted
20268 by redisplay, it means the previous row was
20269 produced from a single newline, which is only
20270 possible if that newline came from the same string
20271 as the one which produced this ROW. */
20272 seen_this_string
= true;
20276 end
= r1
->glyphs
[TEXT_AREA
] - 1;
20277 start
= end
+ r1
->used
[TEXT_AREA
];
20279 && NILP ((end
+ 1)->object
)
20280 && (end
+ 1)->charpos
<= 0)
20284 if (EQ ((end
+ 1)->object
, it
->object
))
20285 seen_this_string
= true;
20288 seen_this_string
= true;
20291 /* Take note of each display string that covers a newline only
20292 once, the first time we see it. This is for when a display
20293 string includes more than one newline in it. */
20294 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
20296 /* If we were scanning the buffer forward when we displayed
20297 the string, we want to account for at least one buffer
20298 position that belongs to this row (position covered by
20299 the display string), so that cursor positioning will
20300 consider this row as a candidate when point is at the end
20301 of the visual line represented by this row. This is not
20302 required when scanning back, because max_pos will already
20303 have a much larger value. */
20304 if (CHARPOS (row
->end
.pos
) > max_pos
)
20305 INC_BOTH (max_pos
, max_bpos
);
20306 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20308 else if (CHARPOS (it
->eol_pos
) > 0)
20309 SET_TEXT_POS (row
->maxpos
,
20310 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
20311 else if (row
->continued_p
)
20313 /* If max_pos is different from IT's current position, it
20314 means IT->method does not belong to the display element
20315 at max_pos. However, it also means that the display
20316 element at max_pos was displayed in its entirety on this
20317 line, which is equivalent to saying that the next line
20318 starts at the next buffer position. */
20319 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
20320 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20323 INC_BOTH (max_pos
, max_bpos
);
20324 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20327 else if (row
->truncated_on_right_p
)
20328 /* display_line already called reseat_at_next_visible_line_start,
20329 which puts the iterator at the beginning of the next line, in
20330 the logical order. */
20331 row
->maxpos
= it
->current
.pos
;
20332 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
20333 /* A line that is entirely from a string/image/stretch... */
20334 row
->maxpos
= row
->minpos
;
20339 row
->maxpos
= it
->current
.pos
;
20342 /* Construct the glyph row IT->glyph_row in the desired matrix of
20343 IT->w from text at the current position of IT. See dispextern.h
20344 for an overview of struct it. Value is true if
20345 IT->glyph_row displays text, as opposed to a line displaying ZV
20349 display_line (struct it
*it
)
20351 struct glyph_row
*row
= it
->glyph_row
;
20352 Lisp_Object overlay_arrow_string
;
20354 void *wrap_data
= NULL
;
20355 bool may_wrap
= false;
20356 int wrap_x
IF_LINT (= 0);
20357 int wrap_row_used
= -1;
20358 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
20359 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
20360 int wrap_row_extra_line_spacing
IF_LINT (= 0);
20361 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
20362 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
20364 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
20365 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
20366 bool pending_handle_line_prefix
= false;
20368 /* We always start displaying at hpos zero even if hscrolled. */
20369 eassert (it
->hpos
== 0 && it
->current_x
== 0);
20371 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
20372 >= it
->w
->desired_matrix
->nrows
)
20374 it
->w
->nrows_scale_factor
++;
20375 it
->f
->fonts_changed
= true;
20379 /* Clear the result glyph row and enable it. */
20380 prepare_desired_row (it
->w
, row
, false);
20382 row
->y
= it
->current_y
;
20383 row
->start
= it
->start
;
20384 row
->continuation_lines_width
= it
->continuation_lines_width
;
20385 row
->displays_text_p
= true;
20386 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
20387 it
->starts_in_middle_of_char_p
= false;
20389 /* Arrange the overlays nicely for our purposes. Usually, we call
20390 display_line on only one line at a time, in which case this
20391 can't really hurt too much, or we call it on lines which appear
20392 one after another in the buffer, in which case all calls to
20393 recenter_overlay_lists but the first will be pretty cheap. */
20394 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
20396 /* Move over display elements that are not visible because we are
20397 hscrolled. This may stop at an x-position < IT->first_visible_x
20398 if the first glyph is partially visible or if we hit a line end. */
20399 if (it
->current_x
< it
->first_visible_x
)
20401 enum move_it_result move_result
;
20403 this_line_min_pos
= row
->start
.pos
;
20404 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
20405 MOVE_TO_POS
| MOVE_TO_X
);
20406 /* If we are under a large hscroll, move_it_in_display_line_to
20407 could hit the end of the line without reaching
20408 it->first_visible_x. Pretend that we did reach it. This is
20409 especially important on a TTY, where we will call
20410 extend_face_to_end_of_line, which needs to know how many
20411 blank glyphs to produce. */
20412 if (it
->current_x
< it
->first_visible_x
20413 && (move_result
== MOVE_NEWLINE_OR_CR
20414 || move_result
== MOVE_POS_MATCH_OR_ZV
))
20415 it
->current_x
= it
->first_visible_x
;
20417 /* Record the smallest positions seen while we moved over
20418 display elements that are not visible. This is needed by
20419 redisplay_internal for optimizing the case where the cursor
20420 stays inside the same line. The rest of this function only
20421 considers positions that are actually displayed, so
20422 RECORD_MAX_MIN_POS will not otherwise record positions that
20423 are hscrolled to the left of the left edge of the window. */
20424 min_pos
= CHARPOS (this_line_min_pos
);
20425 min_bpos
= BYTEPOS (this_line_min_pos
);
20427 else if (it
->area
== TEXT_AREA
)
20429 /* We only do this when not calling move_it_in_display_line_to
20430 above, because that function calls itself handle_line_prefix. */
20431 handle_line_prefix (it
);
20435 /* Line-prefix and wrap-prefix are always displayed in the text
20436 area. But if this is the first call to display_line after
20437 init_iterator, the iterator might have been set up to write
20438 into a marginal area, e.g. if the line begins with some
20439 display property that writes to the margins. So we need to
20440 wait with the call to handle_line_prefix until whatever
20441 writes to the margin has done its job. */
20442 pending_handle_line_prefix
= true;
20445 /* Get the initial row height. This is either the height of the
20446 text hscrolled, if there is any, or zero. */
20447 row
->ascent
= it
->max_ascent
;
20448 row
->height
= it
->max_ascent
+ it
->max_descent
;
20449 row
->phys_ascent
= it
->max_phys_ascent
;
20450 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20451 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20453 /* Utility macro to record max and min buffer positions seen until now. */
20454 #define RECORD_MAX_MIN_POS(IT) \
20457 bool composition_p \
20458 = !STRINGP ((IT)->string) && ((IT)->what == IT_COMPOSITION); \
20459 ptrdiff_t current_pos = \
20460 composition_p ? (IT)->cmp_it.charpos \
20461 : IT_CHARPOS (*(IT)); \
20462 ptrdiff_t current_bpos = \
20463 composition_p ? CHAR_TO_BYTE (current_pos) \
20464 : IT_BYTEPOS (*(IT)); \
20465 if (current_pos < min_pos) \
20467 min_pos = current_pos; \
20468 min_bpos = current_bpos; \
20470 if (IT_CHARPOS (*it) > max_pos) \
20472 max_pos = IT_CHARPOS (*it); \
20473 max_bpos = IT_BYTEPOS (*it); \
20478 /* Loop generating characters. The loop is left with IT on the next
20479 character to display. */
20482 int n_glyphs_before
, hpos_before
, x_before
;
20484 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
20486 /* Retrieve the next thing to display. Value is false if end of
20488 if (!get_next_display_element (it
))
20490 /* Maybe add a space at the end of this line that is used to
20491 display the cursor there under X. Set the charpos of the
20492 first glyph of blank lines not corresponding to any text
20494 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20495 row
->exact_window_width_line_p
= true;
20496 else if ((append_space_for_newline (it
, true)
20497 && row
->used
[TEXT_AREA
] == 1)
20498 || row
->used
[TEXT_AREA
] == 0)
20500 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
20501 row
->displays_text_p
= false;
20503 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
20504 && (!MINI_WINDOW_P (it
->w
)
20505 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
20506 row
->indicate_empty_line_p
= true;
20509 it
->continuation_lines_width
= 0;
20510 row
->ends_at_zv_p
= true;
20511 /* A row that displays right-to-left text must always have
20512 its last face extended all the way to the end of line,
20513 even if this row ends in ZV, because we still write to
20514 the screen left to right. We also need to extend the
20515 last face if the default face is remapped to some
20516 different face, otherwise the functions that clear
20517 portions of the screen will clear with the default face's
20518 background color. */
20519 if (row
->reversed_p
20520 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
20521 extend_face_to_end_of_line (it
);
20525 /* Now, get the metrics of what we want to display. This also
20526 generates glyphs in `row' (which is IT->glyph_row). */
20527 n_glyphs_before
= row
->used
[TEXT_AREA
];
20530 /* Remember the line height so far in case the next element doesn't
20531 fit on the line. */
20532 if (it
->line_wrap
!= TRUNCATE
)
20534 ascent
= it
->max_ascent
;
20535 descent
= it
->max_descent
;
20536 phys_ascent
= it
->max_phys_ascent
;
20537 phys_descent
= it
->max_phys_descent
;
20539 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
20541 if (IT_DISPLAYING_WHITESPACE (it
))
20545 SAVE_IT (wrap_it
, *it
, wrap_data
);
20547 wrap_row_used
= row
->used
[TEXT_AREA
];
20548 wrap_row_ascent
= row
->ascent
;
20549 wrap_row_height
= row
->height
;
20550 wrap_row_phys_ascent
= row
->phys_ascent
;
20551 wrap_row_phys_height
= row
->phys_height
;
20552 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
20553 wrap_row_min_pos
= min_pos
;
20554 wrap_row_min_bpos
= min_bpos
;
20555 wrap_row_max_pos
= max_pos
;
20556 wrap_row_max_bpos
= max_bpos
;
20562 PRODUCE_GLYPHS (it
);
20564 /* If this display element was in marginal areas, continue with
20566 if (it
->area
!= TEXT_AREA
)
20568 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20569 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20570 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20571 row
->phys_height
= max (row
->phys_height
,
20572 it
->max_phys_ascent
+ it
->max_phys_descent
);
20573 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20574 it
->max_extra_line_spacing
);
20575 set_iterator_to_next (it
, true);
20576 /* If we didn't handle the line/wrap prefix above, and the
20577 call to set_iterator_to_next just switched to TEXT_AREA,
20578 process the prefix now. */
20579 if (it
->area
== TEXT_AREA
&& pending_handle_line_prefix
)
20581 pending_handle_line_prefix
= false;
20582 handle_line_prefix (it
);
20587 /* Does the display element fit on the line? If we truncate
20588 lines, we should draw past the right edge of the window. If
20589 we don't truncate, we want to stop so that we can display the
20590 continuation glyph before the right margin. If lines are
20591 continued, there are two possible strategies for characters
20592 resulting in more than 1 glyph (e.g. tabs): Display as many
20593 glyphs as possible in this line and leave the rest for the
20594 continuation line, or display the whole element in the next
20595 line. Original redisplay did the former, so we do it also. */
20596 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20597 hpos_before
= it
->hpos
;
20600 if (/* Not a newline. */
20602 /* Glyphs produced fit entirely in the line. */
20603 && it
->current_x
< it
->last_visible_x
)
20605 it
->hpos
+= nglyphs
;
20606 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20607 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20608 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20609 row
->phys_height
= max (row
->phys_height
,
20610 it
->max_phys_ascent
+ it
->max_phys_descent
);
20611 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20612 it
->max_extra_line_spacing
);
20613 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
20614 /* In R2L rows, we arrange in extend_face_to_end_of_line
20615 to add a right offset to the line, by a suitable
20616 change to the stretch glyph that is the leftmost
20617 glyph of the line. */
20618 && !row
->reversed_p
)
20619 row
->x
= x
- it
->first_visible_x
;
20620 /* Record the maximum and minimum buffer positions seen so
20621 far in glyphs that will be displayed by this row. */
20623 RECORD_MAX_MIN_POS (it
);
20628 struct glyph
*glyph
;
20630 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
20632 /* Identify the glyphs added by the last call to
20633 PRODUCE_GLYPHS. In R2L rows, they are prepended to
20634 the previous glyphs. */
20635 if (!row
->reversed_p
)
20636 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20638 glyph
= row
->glyphs
[TEXT_AREA
] + nglyphs
- 1 - i
;
20639 new_x
= x
+ glyph
->pixel_width
;
20641 if (/* Lines are continued. */
20642 it
->line_wrap
!= TRUNCATE
20643 && (/* Glyph doesn't fit on the line. */
20644 new_x
> it
->last_visible_x
20645 /* Or it fits exactly on a window system frame. */
20646 || (new_x
== it
->last_visible_x
20647 && FRAME_WINDOW_P (it
->f
)
20648 && (row
->reversed_p
20649 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20650 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
20652 /* End of a continued line. */
20655 || (new_x
== it
->last_visible_x
20656 && FRAME_WINDOW_P (it
->f
)
20657 && (row
->reversed_p
20658 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20659 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
20661 /* Current glyph is the only one on the line or
20662 fits exactly on the line. We must continue
20663 the line because we can't draw the cursor
20664 after the glyph. */
20665 row
->continued_p
= true;
20666 it
->current_x
= new_x
;
20667 it
->continuation_lines_width
+= new_x
;
20669 if (i
== nglyphs
- 1)
20671 /* If line-wrap is on, check if a previous
20672 wrap point was found. */
20673 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)
20674 && wrap_row_used
> 0
20675 /* Even if there is a previous wrap
20676 point, continue the line here as
20677 usual, if (i) the previous character
20678 was a space or tab AND (ii) the
20679 current character is not. */
20681 || IT_DISPLAYING_WHITESPACE (it
)))
20684 /* Record the maximum and minimum buffer
20685 positions seen so far in glyphs that will be
20686 displayed by this row. */
20688 RECORD_MAX_MIN_POS (it
);
20689 set_iterator_to_next (it
, true);
20690 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20692 if (!get_next_display_element (it
))
20694 row
->exact_window_width_line_p
= true;
20695 it
->continuation_lines_width
= 0;
20696 row
->continued_p
= false;
20697 row
->ends_at_zv_p
= true;
20699 else if (ITERATOR_AT_END_OF_LINE_P (it
))
20701 row
->continued_p
= false;
20702 row
->exact_window_width_line_p
= true;
20704 /* If line-wrap is on, check if a
20705 previous wrap point was found. */
20706 else if (wrap_row_used
> 0
20707 /* Even if there is a previous wrap
20708 point, continue the line here as
20709 usual, if (i) the previous character
20710 was a space or tab AND (ii) the
20711 current character is not. */
20713 || IT_DISPLAYING_WHITESPACE (it
)))
20718 else if (it
->bidi_p
)
20719 RECORD_MAX_MIN_POS (it
);
20720 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20721 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20722 extend_face_to_end_of_line (it
);
20724 else if (CHAR_GLYPH_PADDING_P (*glyph
)
20725 && !FRAME_WINDOW_P (it
->f
))
20727 /* A padding glyph that doesn't fit on this line.
20728 This means the whole character doesn't fit
20730 if (row
->reversed_p
)
20731 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20732 - n_glyphs_before
);
20733 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20735 /* Fill the rest of the row with continuation
20736 glyphs like in 20.x. */
20737 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
20738 < row
->glyphs
[1 + TEXT_AREA
])
20739 produce_special_glyphs (it
, IT_CONTINUATION
);
20741 row
->continued_p
= true;
20742 it
->current_x
= x_before
;
20743 it
->continuation_lines_width
+= x_before
;
20745 /* Restore the height to what it was before the
20746 element not fitting on the line. */
20747 it
->max_ascent
= ascent
;
20748 it
->max_descent
= descent
;
20749 it
->max_phys_ascent
= phys_ascent
;
20750 it
->max_phys_descent
= phys_descent
;
20751 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20752 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20753 extend_face_to_end_of_line (it
);
20755 else if (wrap_row_used
> 0)
20758 if (row
->reversed_p
)
20759 unproduce_glyphs (it
,
20760 row
->used
[TEXT_AREA
] - wrap_row_used
);
20761 RESTORE_IT (it
, &wrap_it
, wrap_data
);
20762 it
->continuation_lines_width
+= wrap_x
;
20763 row
->used
[TEXT_AREA
] = wrap_row_used
;
20764 row
->ascent
= wrap_row_ascent
;
20765 row
->height
= wrap_row_height
;
20766 row
->phys_ascent
= wrap_row_phys_ascent
;
20767 row
->phys_height
= wrap_row_phys_height
;
20768 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
20769 min_pos
= wrap_row_min_pos
;
20770 min_bpos
= wrap_row_min_bpos
;
20771 max_pos
= wrap_row_max_pos
;
20772 max_bpos
= wrap_row_max_bpos
;
20773 row
->continued_p
= true;
20774 row
->ends_at_zv_p
= false;
20775 row
->exact_window_width_line_p
= false;
20776 it
->continuation_lines_width
+= x
;
20778 /* Make sure that a non-default face is extended
20779 up to the right margin of the window. */
20780 extend_face_to_end_of_line (it
);
20782 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
20784 /* A TAB that extends past the right edge of the
20785 window. This produces a single glyph on
20786 window system frames. We leave the glyph in
20787 this row and let it fill the row, but don't
20788 consume the TAB. */
20789 if ((row
->reversed_p
20790 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20791 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20792 produce_special_glyphs (it
, IT_CONTINUATION
);
20793 it
->continuation_lines_width
+= it
->last_visible_x
;
20794 row
->ends_in_middle_of_char_p
= true;
20795 row
->continued_p
= true;
20796 glyph
->pixel_width
= it
->last_visible_x
- x
;
20797 it
->starts_in_middle_of_char_p
= true;
20798 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20799 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20800 extend_face_to_end_of_line (it
);
20804 /* Something other than a TAB that draws past
20805 the right edge of the window. Restore
20806 positions to values before the element. */
20807 if (row
->reversed_p
)
20808 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20809 - (n_glyphs_before
+ i
));
20810 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20812 /* Display continuation glyphs. */
20813 it
->current_x
= x_before
;
20814 it
->continuation_lines_width
+= x
;
20815 if (!FRAME_WINDOW_P (it
->f
)
20816 || (row
->reversed_p
20817 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20818 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20819 produce_special_glyphs (it
, IT_CONTINUATION
);
20820 row
->continued_p
= true;
20822 extend_face_to_end_of_line (it
);
20824 if (nglyphs
> 1 && i
> 0)
20826 row
->ends_in_middle_of_char_p
= true;
20827 it
->starts_in_middle_of_char_p
= true;
20830 /* Restore the height to what it was before the
20831 element not fitting on the line. */
20832 it
->max_ascent
= ascent
;
20833 it
->max_descent
= descent
;
20834 it
->max_phys_ascent
= phys_ascent
;
20835 it
->max_phys_descent
= phys_descent
;
20840 else if (new_x
> it
->first_visible_x
)
20842 /* Increment number of glyphs actually displayed. */
20845 /* Record the maximum and minimum buffer positions
20846 seen so far in glyphs that will be displayed by
20849 RECORD_MAX_MIN_POS (it
);
20851 if (x
< it
->first_visible_x
&& !row
->reversed_p
)
20852 /* Glyph is partially visible, i.e. row starts at
20853 negative X position. Don't do that in R2L
20854 rows, where we arrange to add a right offset to
20855 the line in extend_face_to_end_of_line, by a
20856 suitable change to the stretch glyph that is
20857 the leftmost glyph of the line. */
20858 row
->x
= x
- it
->first_visible_x
;
20859 /* When the last glyph of an R2L row only fits
20860 partially on the line, we need to set row->x to a
20861 negative offset, so that the leftmost glyph is
20862 the one that is partially visible. But if we are
20863 going to produce the truncation glyph, this will
20864 be taken care of in produce_special_glyphs. */
20865 if (row
->reversed_p
20866 && new_x
> it
->last_visible_x
20867 && !(it
->line_wrap
== TRUNCATE
20868 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
20870 eassert (FRAME_WINDOW_P (it
->f
));
20871 row
->x
= it
->last_visible_x
- new_x
;
20876 /* Glyph is completely off the left margin of the
20877 window. This should not happen because of the
20878 move_it_in_display_line at the start of this
20879 function, unless the text display area of the
20880 window is empty. */
20881 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20884 /* Even if this display element produced no glyphs at all,
20885 we want to record its position. */
20886 if (it
->bidi_p
&& nglyphs
== 0)
20887 RECORD_MAX_MIN_POS (it
);
20889 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20890 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20891 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20892 row
->phys_height
= max (row
->phys_height
,
20893 it
->max_phys_ascent
+ it
->max_phys_descent
);
20894 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20895 it
->max_extra_line_spacing
);
20897 /* End of this display line if row is continued. */
20898 if (row
->continued_p
|| row
->ends_at_zv_p
)
20903 /* Is this a line end? If yes, we're also done, after making
20904 sure that a non-default face is extended up to the right
20905 margin of the window. */
20906 if (ITERATOR_AT_END_OF_LINE_P (it
))
20908 int used_before
= row
->used
[TEXT_AREA
];
20910 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
20912 /* Add a space at the end of the line that is used to
20913 display the cursor there. */
20914 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20915 append_space_for_newline (it
, false);
20917 /* Extend the face to the end of the line. */
20918 extend_face_to_end_of_line (it
);
20920 /* Make sure we have the position. */
20921 if (used_before
== 0)
20922 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
20924 /* Record the position of the newline, for use in
20926 it
->eol_pos
= it
->current
.pos
;
20928 /* Consume the line end. This skips over invisible lines. */
20929 set_iterator_to_next (it
, true);
20930 it
->continuation_lines_width
= 0;
20934 /* Proceed with next display element. Note that this skips
20935 over lines invisible because of selective display. */
20936 set_iterator_to_next (it
, true);
20938 /* If we truncate lines, we are done when the last displayed
20939 glyphs reach past the right margin of the window. */
20940 if (it
->line_wrap
== TRUNCATE
20941 && ((FRAME_WINDOW_P (it
->f
)
20942 /* Images are preprocessed in produce_image_glyph such
20943 that they are cropped at the right edge of the
20944 window, so an image glyph will always end exactly at
20945 last_visible_x, even if there's no right fringe. */
20946 && ((row
->reversed_p
20947 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20948 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))
20949 || it
->what
== IT_IMAGE
))
20950 ? (it
->current_x
>= it
->last_visible_x
)
20951 : (it
->current_x
> it
->last_visible_x
)))
20953 /* Maybe add truncation glyphs. */
20954 if (!FRAME_WINDOW_P (it
->f
)
20955 || (row
->reversed_p
20956 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20957 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20961 if (!row
->reversed_p
)
20963 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20964 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20969 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20970 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20972 /* Remove any padding glyphs at the front of ROW, to
20973 make room for the truncation glyphs we will be
20974 adding below. The loop below always inserts at
20975 least one truncation glyph, so also remove the
20976 last glyph added to ROW. */
20977 unproduce_glyphs (it
, i
+ 1);
20978 /* Adjust i for the loop below. */
20979 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20982 /* produce_special_glyphs overwrites the last glyph, so
20983 we don't want that if we want to keep that last
20984 glyph, which means it's an image. */
20985 if (it
->current_x
> it
->last_visible_x
)
20987 it
->current_x
= x_before
;
20988 if (!FRAME_WINDOW_P (it
->f
))
20990 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20992 row
->used
[TEXT_AREA
] = i
;
20993 produce_special_glyphs (it
, IT_TRUNCATION
);
20998 row
->used
[TEXT_AREA
] = i
;
20999 produce_special_glyphs (it
, IT_TRUNCATION
);
21001 it
->hpos
= hpos_before
;
21004 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
21006 /* Don't truncate if we can overflow newline into fringe. */
21007 if (!get_next_display_element (it
))
21009 it
->continuation_lines_width
= 0;
21010 row
->ends_at_zv_p
= true;
21011 row
->exact_window_width_line_p
= true;
21014 if (ITERATOR_AT_END_OF_LINE_P (it
))
21016 row
->exact_window_width_line_p
= true;
21017 goto at_end_of_line
;
21019 it
->current_x
= x_before
;
21020 it
->hpos
= hpos_before
;
21023 row
->truncated_on_right_p
= true;
21024 it
->continuation_lines_width
= 0;
21025 reseat_at_next_visible_line_start (it
, false);
21026 /* We insist below that IT's position be at ZV because in
21027 bidi-reordered lines the character at visible line start
21028 might not be the character that follows the newline in
21029 the logical order. */
21030 if (IT_BYTEPOS (*it
) > BEG_BYTE
)
21031 row
->ends_at_zv_p
=
21032 IT_BYTEPOS (*it
) >= ZV_BYTE
&& FETCH_BYTE (ZV_BYTE
- 1) != '\n';
21034 row
->ends_at_zv_p
= false;
21040 bidi_unshelve_cache (wrap_data
, true);
21042 /* If line is not empty and hscrolled, maybe insert truncation glyphs
21043 at the left window margin. */
21044 if (it
->first_visible_x
21045 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
21047 if (!FRAME_WINDOW_P (it
->f
)
21048 || (((row
->reversed_p
21049 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21050 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
21051 /* Don't let insert_left_trunc_glyphs overwrite the
21052 first glyph of the row if it is an image. */
21053 && row
->glyphs
[TEXT_AREA
]->type
!= IMAGE_GLYPH
))
21054 insert_left_trunc_glyphs (it
);
21055 row
->truncated_on_left_p
= true;
21058 /* Remember the position at which this line ends.
21060 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
21061 cannot be before the call to find_row_edges below, since that is
21062 where these positions are determined. */
21063 row
->end
= it
->current
;
21066 row
->minpos
= row
->start
.pos
;
21067 row
->maxpos
= row
->end
.pos
;
21071 /* ROW->minpos and ROW->maxpos must be the smallest and
21072 `1 + the largest' buffer positions in ROW. But if ROW was
21073 bidi-reordered, these two positions can be anywhere in the
21074 row, so we must determine them now. */
21075 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
21078 /* If the start of this line is the overlay arrow-position, then
21079 mark this glyph row as the one containing the overlay arrow.
21080 This is clearly a mess with variable size fonts. It would be
21081 better to let it be displayed like cursors under X. */
21082 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
21083 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
21084 !NILP (overlay_arrow_string
)))
21086 /* Overlay arrow in window redisplay is a fringe bitmap. */
21087 if (STRINGP (overlay_arrow_string
))
21089 struct glyph_row
*arrow_row
21090 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
21091 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
21092 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
21093 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
21094 struct glyph
*p2
, *end
;
21096 /* Copy the arrow glyphs. */
21097 while (glyph
< arrow_end
)
21100 /* Throw away padding glyphs. */
21102 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
21103 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
21109 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
21114 eassert (INTEGERP (overlay_arrow_string
));
21115 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
21117 overlay_arrow_seen
= true;
21120 /* Highlight trailing whitespace. */
21121 if (!NILP (Vshow_trailing_whitespace
))
21122 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
21124 /* Compute pixel dimensions of this line. */
21125 compute_line_metrics (it
);
21127 /* Implementation note: No changes in the glyphs of ROW or in their
21128 faces can be done past this point, because compute_line_metrics
21129 computes ROW's hash value and stores it within the glyph_row
21132 /* Record whether this row ends inside an ellipsis. */
21133 row
->ends_in_ellipsis_p
21134 = (it
->method
== GET_FROM_DISPLAY_VECTOR
21135 && it
->ellipsis_p
);
21137 /* Save fringe bitmaps in this row. */
21138 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
21139 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
21140 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
21141 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
21143 it
->left_user_fringe_bitmap
= 0;
21144 it
->left_user_fringe_face_id
= 0;
21145 it
->right_user_fringe_bitmap
= 0;
21146 it
->right_user_fringe_face_id
= 0;
21148 /* Maybe set the cursor. */
21149 cvpos
= it
->w
->cursor
.vpos
;
21151 /* In bidi-reordered rows, keep checking for proper cursor
21152 position even if one has been found already, because buffer
21153 positions in such rows change non-linearly with ROW->VPOS,
21154 when a line is continued. One exception: when we are at ZV,
21155 display cursor on the first suitable glyph row, since all
21156 the empty rows after that also have their position set to ZV. */
21157 /* FIXME: Revisit this when glyph ``spilling'' in continuation
21158 lines' rows is implemented for bidi-reordered rows. */
21160 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
21161 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
21162 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
21163 && cursor_row_p (row
))
21164 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
21166 /* Prepare for the next line. This line starts horizontally at (X
21167 HPOS) = (0 0). Vertical positions are incremented. As a
21168 convenience for the caller, IT->glyph_row is set to the next
21170 it
->current_x
= it
->hpos
= 0;
21171 it
->current_y
+= row
->height
;
21172 SET_TEXT_POS (it
->eol_pos
, 0, 0);
21175 /* The next row should by default use the same value of the
21176 reversed_p flag as this one. set_iterator_to_next decides when
21177 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
21178 the flag accordingly. */
21179 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
21180 it
->glyph_row
->reversed_p
= row
->reversed_p
;
21181 it
->start
= row
->end
;
21182 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
21184 #undef RECORD_MAX_MIN_POS
21187 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
21188 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
21189 doc
: /* Return paragraph direction at point in BUFFER.
21190 Value is either `left-to-right' or `right-to-left'.
21191 If BUFFER is omitted or nil, it defaults to the current buffer.
21193 Paragraph direction determines how the text in the paragraph is displayed.
21194 In left-to-right paragraphs, text begins at the left margin of the window
21195 and the reading direction is generally left to right. In right-to-left
21196 paragraphs, text begins at the right margin and is read from right to left.
21198 See also `bidi-paragraph-direction'. */)
21199 (Lisp_Object buffer
)
21201 struct buffer
*buf
= current_buffer
;
21202 struct buffer
*old
= buf
;
21204 if (! NILP (buffer
))
21206 CHECK_BUFFER (buffer
);
21207 buf
= XBUFFER (buffer
);
21210 if (NILP (BVAR (buf
, bidi_display_reordering
))
21211 || NILP (BVAR (buf
, enable_multibyte_characters
))
21212 /* When we are loading loadup.el, the character property tables
21213 needed for bidi iteration are not yet available. */
21214 || !NILP (Vpurify_flag
))
21215 return Qleft_to_right
;
21216 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
21217 return BVAR (buf
, bidi_paragraph_direction
);
21220 /* Determine the direction from buffer text. We could try to
21221 use current_matrix if it is up to date, but this seems fast
21222 enough as it is. */
21223 struct bidi_it itb
;
21224 ptrdiff_t pos
= BUF_PT (buf
);
21225 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
21227 void *itb_data
= bidi_shelve_cache ();
21229 set_buffer_temp (buf
);
21230 /* bidi_paragraph_init finds the base direction of the paragraph
21231 by searching forward from paragraph start. We need the base
21232 direction of the current or _previous_ paragraph, so we need
21233 to make sure we are within that paragraph. To that end, find
21234 the previous non-empty line. */
21235 if (pos
>= ZV
&& pos
> BEGV
)
21236 DEC_BOTH (pos
, bytepos
);
21237 AUTO_STRING (trailing_white_space
, "[\f\t ]*\n");
21238 if (fast_looking_at (trailing_white_space
,
21239 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
21241 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
21242 || c
== ' ' || c
== '\t' || c
== '\f')
21244 if (bytepos
<= BEGV_BYTE
)
21249 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
21252 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
21253 itb
.paragraph_dir
= NEUTRAL_DIR
;
21254 itb
.string
.s
= NULL
;
21255 itb
.string
.lstring
= Qnil
;
21256 itb
.string
.bufpos
= 0;
21257 itb
.string
.from_disp_str
= false;
21258 itb
.string
.unibyte
= false;
21259 /* We have no window to use here for ignoring window-specific
21260 overlays. Using NULL for window pointer will cause
21261 compute_display_string_pos to use the current buffer. */
21263 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, true);
21264 bidi_unshelve_cache (itb_data
, false);
21265 set_buffer_temp (old
);
21266 switch (itb
.paragraph_dir
)
21269 return Qleft_to_right
;
21272 return Qright_to_left
;
21280 DEFUN ("bidi-find-overridden-directionality",
21281 Fbidi_find_overridden_directionality
,
21282 Sbidi_find_overridden_directionality
, 2, 3, 0,
21283 doc
: /* Return position between FROM and TO where directionality was overridden.
21285 This function returns the first character position in the specified
21286 region of OBJECT where there is a character whose `bidi-class' property
21287 is `L', but which was forced to display as `R' by a directional
21288 override, and likewise with characters whose `bidi-class' is `R'
21289 or `AL' that were forced to display as `L'.
21291 If no such character is found, the function returns nil.
21293 OBJECT is a Lisp string or buffer to search for overridden
21294 directionality, and defaults to the current buffer if nil or omitted.
21295 OBJECT can also be a window, in which case the function will search
21296 the buffer displayed in that window. Passing the window instead of
21297 a buffer is preferable when the buffer is displayed in some window,
21298 because this function will then be able to correctly account for
21299 window-specific overlays, which can affect the results.
21301 Strong directional characters `L', `R', and `AL' can have their
21302 intrinsic directionality overridden by directional override
21303 control characters RLO (u+202e) and LRO (u+202d). See the
21304 function `get-char-code-property' for a way to inquire about
21305 the `bidi-class' property of a character. */)
21306 (Lisp_Object from
, Lisp_Object to
, Lisp_Object object
)
21308 struct buffer
*buf
= current_buffer
;
21309 struct buffer
*old
= buf
;
21310 struct window
*w
= NULL
;
21311 bool frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ());
21312 struct bidi_it itb
;
21313 ptrdiff_t from_pos
, to_pos
, from_bpos
;
21316 if (!NILP (object
))
21318 if (BUFFERP (object
))
21319 buf
= XBUFFER (object
);
21320 else if (WINDOWP (object
))
21322 w
= decode_live_window (object
);
21323 buf
= XBUFFER (w
->contents
);
21324 frame_window_p
= FRAME_WINDOW_P (XFRAME (w
->frame
));
21327 CHECK_STRING (object
);
21330 if (STRINGP (object
))
21332 /* Characters in unibyte strings are always treated by bidi.c as
21334 if (!STRING_MULTIBYTE (object
)
21335 /* When we are loading loadup.el, the character property
21336 tables needed for bidi iteration are not yet
21338 || !NILP (Vpurify_flag
))
21341 validate_subarray (object
, from
, to
, SCHARS (object
), &from_pos
, &to_pos
);
21342 if (from_pos
>= SCHARS (object
))
21345 /* Set up the bidi iterator. */
21346 itb_data
= bidi_shelve_cache ();
21347 itb
.paragraph_dir
= NEUTRAL_DIR
;
21348 itb
.string
.lstring
= object
;
21349 itb
.string
.s
= NULL
;
21350 itb
.string
.schars
= SCHARS (object
);
21351 itb
.string
.bufpos
= 0;
21352 itb
.string
.from_disp_str
= false;
21353 itb
.string
.unibyte
= false;
21355 bidi_init_it (0, 0, frame_window_p
, &itb
);
21359 /* Nothing this fancy can happen in unibyte buffers, or in a
21360 buffer that disabled reordering, or if FROM is at EOB. */
21361 if (NILP (BVAR (buf
, bidi_display_reordering
))
21362 || NILP (BVAR (buf
, enable_multibyte_characters
))
21363 /* When we are loading loadup.el, the character property
21364 tables needed for bidi iteration are not yet
21366 || !NILP (Vpurify_flag
))
21369 set_buffer_temp (buf
);
21370 validate_region (&from
, &to
);
21371 from_pos
= XINT (from
);
21372 to_pos
= XINT (to
);
21373 if (from_pos
>= ZV
)
21376 /* Set up the bidi iterator. */
21377 itb_data
= bidi_shelve_cache ();
21378 from_bpos
= CHAR_TO_BYTE (from_pos
);
21379 if (from_pos
== BEGV
)
21381 itb
.charpos
= BEGV
;
21382 itb
.bytepos
= BEGV_BYTE
;
21384 else if (FETCH_CHAR (from_bpos
- 1) == '\n')
21386 itb
.charpos
= from_pos
;
21387 itb
.bytepos
= from_bpos
;
21390 itb
.charpos
= find_newline_no_quit (from_pos
, CHAR_TO_BYTE (from_pos
),
21392 itb
.paragraph_dir
= NEUTRAL_DIR
;
21393 itb
.string
.s
= NULL
;
21394 itb
.string
.lstring
= Qnil
;
21395 itb
.string
.bufpos
= 0;
21396 itb
.string
.from_disp_str
= false;
21397 itb
.string
.unibyte
= false;
21399 bidi_init_it (itb
.charpos
, itb
.bytepos
, frame_window_p
, &itb
);
21404 /* For the purposes of this function, the actual base direction of
21405 the paragraph doesn't matter, so just set it to L2R. */
21406 bidi_paragraph_init (L2R
, &itb
, false);
21407 while ((found
= bidi_find_first_overridden (&itb
)) < from_pos
)
21409 } while (found
== ZV
&& itb
.ch
== '\n' && itb
.charpos
< to_pos
);
21411 bidi_unshelve_cache (itb_data
, false);
21412 set_buffer_temp (old
);
21414 return (from_pos
<= found
&& found
< to_pos
) ? make_number (found
) : Qnil
;
21417 DEFUN ("move-point-visually", Fmove_point_visually
,
21418 Smove_point_visually
, 1, 1, 0,
21419 doc
: /* Move point in the visual order in the specified DIRECTION.
21420 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
21423 Value is the new character position of point. */)
21424 (Lisp_Object direction
)
21426 struct window
*w
= XWINDOW (selected_window
);
21427 struct buffer
*b
= XBUFFER (w
->contents
);
21428 struct glyph_row
*row
;
21430 Lisp_Object paragraph_dir
;
21432 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
21433 (!(ROW)->continued_p \
21434 && NILP ((GLYPH)->object) \
21435 && (GLYPH)->type == CHAR_GLYPH \
21436 && (GLYPH)->u.ch == ' ' \
21437 && (GLYPH)->charpos >= 0 \
21438 && !(GLYPH)->avoid_cursor_p)
21440 CHECK_NUMBER (direction
);
21441 dir
= XINT (direction
);
21447 /* If current matrix is up-to-date, we can use the information
21448 recorded in the glyphs, at least as long as the goal is on the
21450 if (w
->window_end_valid
21451 && !windows_or_buffers_changed
21453 && !b
->clip_changed
21454 && !b
->prevent_redisplay_optimizations_p
21455 && !window_outdated (w
)
21456 /* We rely below on the cursor coordinates to be up to date, but
21457 we cannot trust them if some command moved point since the
21458 last complete redisplay. */
21459 && w
->last_point
== BUF_PT (b
)
21460 && w
->cursor
.vpos
>= 0
21461 && w
->cursor
.vpos
< w
->current_matrix
->nrows
21462 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
21464 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
21465 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
21466 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
21468 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
21470 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
21472 SET_PT (g
->charpos
);
21473 w
->cursor
.vpos
= -1;
21474 return make_number (PT
);
21476 else if (!NILP (g
->object
) && !EQ (g
->object
, gpt
->object
))
21480 if (BUFFERP (gpt
->object
))
21483 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
21484 new_pos
+= (row
->reversed_p
? -dir
: dir
);
21486 new_pos
-= (row
->reversed_p
? -dir
: dir
);
21488 else if (BUFFERP (g
->object
))
21489 new_pos
= g
->charpos
;
21493 w
->cursor
.vpos
= -1;
21494 return make_number (PT
);
21496 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
21498 /* Glyphs inserted at the end of a non-empty line for
21499 positioning the cursor have zero charpos, so we must
21500 deduce the value of point by other means. */
21501 if (g
->charpos
> 0)
21502 SET_PT (g
->charpos
);
21503 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
21505 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
21506 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21509 w
->cursor
.vpos
= -1;
21510 return make_number (PT
);
21513 if (g
== e
|| NILP (g
->object
))
21515 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
21516 goto simulate_display
;
21517 if (!row
->reversed_p
)
21521 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
21522 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
21523 goto simulate_display
;
21527 if (row
->reversed_p
&& !row
->continued_p
)
21529 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21530 w
->cursor
.vpos
= -1;
21531 return make_number (PT
);
21533 g
= row
->glyphs
[TEXT_AREA
];
21534 e
= g
+ row
->used
[TEXT_AREA
];
21535 for ( ; g
< e
; g
++)
21537 if (BUFFERP (g
->object
)
21538 /* Empty lines have only one glyph, which stands
21539 for the newline, and whose charpos is the
21540 buffer position of the newline. */
21541 || ROW_GLYPH_NEWLINE_P (row
, g
)
21542 /* When the buffer ends in a newline, the line at
21543 EOB also has one glyph, but its charpos is -1. */
21544 || (row
->ends_at_zv_p
21545 && !row
->reversed_p
21546 && NILP (g
->object
)
21547 && g
->type
== CHAR_GLYPH
21548 && g
->u
.ch
== ' '))
21550 if (g
->charpos
> 0)
21551 SET_PT (g
->charpos
);
21552 else if (!row
->reversed_p
21553 && row
->ends_at_zv_p
21558 w
->cursor
.vpos
= -1;
21559 return make_number (PT
);
21565 if (!row
->reversed_p
&& !row
->continued_p
)
21567 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21568 w
->cursor
.vpos
= -1;
21569 return make_number (PT
);
21571 e
= row
->glyphs
[TEXT_AREA
];
21572 g
= e
+ row
->used
[TEXT_AREA
] - 1;
21573 for ( ; g
>= e
; g
--)
21575 if (BUFFERP (g
->object
)
21576 || (ROW_GLYPH_NEWLINE_P (row
, g
)
21578 /* Empty R2L lines on GUI frames have the buffer
21579 position of the newline stored in the stretch
21581 || g
->type
== STRETCH_GLYPH
21582 || (row
->ends_at_zv_p
21584 && NILP (g
->object
)
21585 && g
->type
== CHAR_GLYPH
21586 && g
->u
.ch
== ' '))
21588 if (g
->charpos
> 0)
21589 SET_PT (g
->charpos
);
21590 else if (row
->reversed_p
21591 && row
->ends_at_zv_p
21596 w
->cursor
.vpos
= -1;
21597 return make_number (PT
);
21606 /* If we wind up here, we failed to move by using the glyphs, so we
21607 need to simulate display instead. */
21610 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
21612 paragraph_dir
= Qleft_to_right
;
21613 if (EQ (paragraph_dir
, Qright_to_left
))
21615 if (PT
<= BEGV
&& dir
< 0)
21616 xsignal0 (Qbeginning_of_buffer
);
21617 else if (PT
>= ZV
&& dir
> 0)
21618 xsignal0 (Qend_of_buffer
);
21621 struct text_pos pt
;
21623 int pt_x
, target_x
, pixel_width
, pt_vpos
;
21625 bool overshoot_expected
= false;
21626 bool target_is_eol_p
= false;
21628 /* Setup the arena. */
21629 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
21630 start_display (&it
, w
, pt
);
21631 /* When lines are truncated, we could be called with point
21632 outside of the windows edges, in which case move_it_*
21633 functions either prematurely stop at window's edge or jump to
21634 the next screen line, whereas we rely below on our ability to
21635 reach point, in order to start from its X coordinate. So we
21636 need to disregard the window's horizontal extent in that case. */
21637 if (it
.line_wrap
== TRUNCATE
)
21638 it
.last_visible_x
= INFINITY
;
21640 if (it
.cmp_it
.id
< 0
21641 && it
.method
== GET_FROM_STRING
21642 && it
.area
== TEXT_AREA
21643 && it
.string_from_display_prop_p
21644 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
21645 overshoot_expected
= true;
21647 /* Find the X coordinate of point. We start from the beginning
21648 of this or previous line to make sure we are before point in
21649 the logical order (since the move_it_* functions can only
21652 reseat_at_previous_visible_line_start (&it
);
21653 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
21654 if (IT_CHARPOS (it
) != PT
)
21656 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
21657 -1, -1, -1, MOVE_TO_POS
);
21658 /* If we missed point because the character there is
21659 displayed out of a display vector that has more than one
21660 glyph, retry expecting overshoot. */
21661 if (it
.method
== GET_FROM_DISPLAY_VECTOR
21662 && it
.current
.dpvec_index
> 0
21663 && !overshoot_expected
)
21665 overshoot_expected
= true;
21668 else if (IT_CHARPOS (it
) != PT
&& !overshoot_expected
)
21669 move_it_in_display_line (&it
, PT
, -1, MOVE_TO_POS
);
21671 pt_x
= it
.current_x
;
21673 if (dir
> 0 || overshoot_expected
)
21675 struct glyph_row
*row
= it
.glyph_row
;
21677 /* When point is at beginning of line, we don't have
21678 information about the glyph there loaded into struct
21679 it. Calling get_next_display_element fixes that. */
21681 get_next_display_element (&it
);
21682 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21683 it
.glyph_row
= NULL
;
21684 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
21685 it
.glyph_row
= row
;
21686 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
21687 it, lest it will become out of sync with it's buffer
21689 it
.current_x
= pt_x
;
21692 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21693 pixel_width
= it
.pixel_width
;
21694 if (overshoot_expected
&& at_eol_p
)
21696 else if (pixel_width
<= 0)
21699 /* If there's a display string (or something similar) at point,
21700 we are actually at the glyph to the left of point, so we need
21701 to correct the X coordinate. */
21702 if (overshoot_expected
)
21705 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
21707 pt_x
+= pixel_width
;
21710 /* Compute target X coordinate, either to the left or to the
21711 right of point. On TTY frames, all characters have the same
21712 pixel width of 1, so we can use that. On GUI frames we don't
21713 have an easy way of getting at the pixel width of the
21714 character to the left of point, so we use a different method
21715 of getting to that place. */
21717 target_x
= pt_x
+ pixel_width
;
21719 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
21721 /* Target X coordinate could be one line above or below the line
21722 of point, in which case we need to adjust the target X
21723 coordinate. Also, if moving to the left, we need to begin at
21724 the left edge of the point's screen line. */
21729 start_display (&it
, w
, pt
);
21730 if (it
.line_wrap
== TRUNCATE
)
21731 it
.last_visible_x
= INFINITY
;
21732 reseat_at_previous_visible_line_start (&it
);
21733 it
.current_x
= it
.current_y
= it
.hpos
= 0;
21735 move_it_by_lines (&it
, pt_vpos
);
21739 move_it_by_lines (&it
, -1);
21740 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
21741 target_is_eol_p
= true;
21742 /* Under word-wrap, we don't know the x coordinate of
21743 the last character displayed on the previous line,
21744 which immediately precedes the wrap point. To find
21745 out its x coordinate, we try moving to the right
21746 margin of the window, which will stop at the wrap
21747 point, and then reset target_x to point at the
21748 character that precedes the wrap point. This is not
21749 needed on GUI frames, because (see below) there we
21750 move from the left margin one grapheme cluster at a
21751 time, and stop when we hit the wrap point. */
21752 if (!FRAME_WINDOW_P (it
.f
) && it
.line_wrap
== WORD_WRAP
)
21754 void *it_data
= NULL
;
21757 SAVE_IT (it2
, it
, it_data
);
21758 move_it_in_display_line_to (&it
, ZV
, target_x
,
21759 MOVE_TO_POS
| MOVE_TO_X
);
21760 /* If we arrived at target_x, that _is_ the last
21761 character on the previous line. */
21762 if (it
.current_x
!= target_x
)
21763 target_x
= it
.current_x
- 1;
21764 RESTORE_IT (&it
, &it2
, it_data
);
21771 || (target_x
>= it
.last_visible_x
21772 && it
.line_wrap
!= TRUNCATE
))
21775 move_it_by_lines (&it
, 0);
21776 move_it_by_lines (&it
, 1);
21781 /* Move to the target X coordinate. */
21782 #ifdef HAVE_WINDOW_SYSTEM
21783 /* On GUI frames, as we don't know the X coordinate of the
21784 character to the left of point, moving point to the left
21785 requires walking, one grapheme cluster at a time, until we
21786 find ourself at a place immediately to the left of the
21787 character at point. */
21788 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
21790 struct text_pos new_pos
;
21791 enum move_it_result rc
= MOVE_X_REACHED
;
21793 if (it
.current_x
== 0)
21794 get_next_display_element (&it
);
21795 if (it
.what
== IT_COMPOSITION
)
21797 new_pos
.charpos
= it
.cmp_it
.charpos
;
21798 new_pos
.bytepos
= -1;
21801 new_pos
= it
.current
.pos
;
21803 while (it
.current_x
+ it
.pixel_width
<= target_x
21804 && (rc
== MOVE_X_REACHED
21805 /* Under word-wrap, move_it_in_display_line_to
21806 stops at correct coordinates, but sometimes
21807 returns MOVE_POS_MATCH_OR_ZV. */
21808 || (it
.line_wrap
== WORD_WRAP
21809 && rc
== MOVE_POS_MATCH_OR_ZV
)))
21811 int new_x
= it
.current_x
+ it
.pixel_width
;
21813 /* For composed characters, we want the position of the
21814 first character in the grapheme cluster (usually, the
21815 composition's base character), whereas it.current
21816 might give us the position of the _last_ one, e.g. if
21817 the composition is rendered in reverse due to bidi
21819 if (it
.what
== IT_COMPOSITION
)
21821 new_pos
.charpos
= it
.cmp_it
.charpos
;
21822 new_pos
.bytepos
= -1;
21825 new_pos
= it
.current
.pos
;
21826 if (new_x
== it
.current_x
)
21828 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
21829 MOVE_TO_POS
| MOVE_TO_X
);
21830 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
21833 /* The previous position we saw in the loop is the one we
21835 if (new_pos
.bytepos
== -1)
21836 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
21837 it
.current
.pos
= new_pos
;
21841 if (it
.current_x
!= target_x
)
21842 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
21844 /* If we ended up in a display string that covers point, move to
21845 buffer position to the right in the visual order. */
21848 while (IT_CHARPOS (it
) == PT
)
21850 set_iterator_to_next (&it
, false);
21851 if (!get_next_display_element (&it
))
21856 /* Move point to that position. */
21857 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
21860 return make_number (PT
);
21862 #undef ROW_GLYPH_NEWLINE_P
21865 DEFUN ("bidi-resolved-levels", Fbidi_resolved_levels
,
21866 Sbidi_resolved_levels
, 0, 1, 0,
21867 doc
: /* Return the resolved bidirectional levels of characters at VPOS.
21869 The resolved levels are produced by the Emacs bidi reordering engine
21870 that implements the UBA, the Unicode Bidirectional Algorithm. Please
21871 read the Unicode Standard Annex 9 (UAX#9) for background information
21872 about these levels.
21874 VPOS is the zero-based number of the current window's screen line
21875 for which to produce the resolved levels. If VPOS is nil or omitted,
21876 it defaults to the screen line of point. If the window displays a
21877 header line, VPOS of zero will report on the header line, and first
21878 line of text in the window will have VPOS of 1.
21880 Value is an array of resolved levels, indexed by glyph number.
21881 Glyphs are numbered from zero starting from the beginning of the
21882 screen line, i.e. the left edge of the window for left-to-right lines
21883 and from the right edge for right-to-left lines. The resolved levels
21884 are produced only for the window's text area; text in display margins
21887 If the selected window's display is not up-to-date, or if the specified
21888 screen line does not display text, this function returns nil. It is
21889 highly recommended to bind this function to some simple key, like F8,
21890 in order to avoid these problems.
21892 This function exists mainly for testing the correctness of the
21893 Emacs UBA implementation, in particular with the test suite. */)
21896 struct window
*w
= XWINDOW (selected_window
);
21897 struct buffer
*b
= XBUFFER (w
->contents
);
21899 struct glyph_row
*row
;
21903 int d1
, d2
, d3
, d4
, d5
;
21905 pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &nrow
);
21909 CHECK_NUMBER_COERCE_MARKER (vpos
);
21910 nrow
= XINT (vpos
);
21913 /* We require up-to-date glyph matrix for this window. */
21914 if (w
->window_end_valid
21915 && !windows_or_buffers_changed
21917 && !b
->clip_changed
21918 && !b
->prevent_redisplay_optimizations_p
21919 && !window_outdated (w
)
21921 && nrow
< w
->current_matrix
->nrows
21922 && (row
= MATRIX_ROW (w
->current_matrix
, nrow
))->enabled_p
21923 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
21925 struct glyph
*g
, *e
, *g1
;
21927 Lisp_Object levels
;
21929 if (!row
->reversed_p
) /* Left-to-right glyph row. */
21931 g
= g1
= row
->glyphs
[TEXT_AREA
];
21932 e
= g
+ row
->used
[TEXT_AREA
];
21934 /* Skip over glyphs at the start of the row that was
21935 generated by redisplay for its own needs. */
21937 && NILP (g
->object
)
21942 /* Count the "interesting" glyphs in this row. */
21943 for (nglyphs
= 0; g
< e
&& !NILP (g
->object
); g
++)
21946 /* Create and fill the array. */
21947 levels
= make_uninit_vector (nglyphs
);
21948 for (i
= 0; g1
< g
; i
++, g1
++)
21949 ASET (levels
, i
, make_number (g1
->resolved_level
));
21951 else /* Right-to-left glyph row. */
21953 g
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
21954 e
= row
->glyphs
[TEXT_AREA
] - 1;
21956 && NILP (g
->object
)
21960 for (nglyphs
= 0; g
> e
&& !NILP (g
->object
); g
--)
21962 levels
= make_uninit_vector (nglyphs
);
21963 for (i
= 0; g1
> g
; i
++, g1
--)
21964 ASET (levels
, i
, make_number (g1
->resolved_level
));
21974 /***********************************************************************
21976 ***********************************************************************/
21978 /* Redisplay the menu bar in the frame for window W.
21980 The menu bar of X frames that don't have X toolkit support is
21981 displayed in a special window W->frame->menu_bar_window.
21983 The menu bar of terminal frames is treated specially as far as
21984 glyph matrices are concerned. Menu bar lines are not part of
21985 windows, so the update is done directly on the frame matrix rows
21986 for the menu bar. */
21989 display_menu_bar (struct window
*w
)
21991 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21996 /* Don't do all this for graphical frames. */
21998 if (FRAME_W32_P (f
))
22001 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
22007 if (FRAME_NS_P (f
))
22009 #endif /* HAVE_NS */
22011 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
22012 eassert (!FRAME_WINDOW_P (f
));
22013 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
22014 it
.first_visible_x
= 0;
22015 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
22016 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
22017 if (FRAME_WINDOW_P (f
))
22019 /* Menu bar lines are displayed in the desired matrix of the
22020 dummy window menu_bar_window. */
22021 struct window
*menu_w
;
22022 menu_w
= XWINDOW (f
->menu_bar_window
);
22023 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
22025 it
.first_visible_x
= 0;
22026 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
22029 #endif /* not USE_X_TOOLKIT and not USE_GTK */
22031 /* This is a TTY frame, i.e. character hpos/vpos are used as
22033 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
22035 it
.first_visible_x
= 0;
22036 it
.last_visible_x
= FRAME_COLS (f
);
22039 /* FIXME: This should be controlled by a user option. See the
22040 comments in redisplay_tool_bar and display_mode_line about
22042 it
.paragraph_embedding
= L2R
;
22044 /* Clear all rows of the menu bar. */
22045 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
22047 struct glyph_row
*row
= it
.glyph_row
+ i
;
22048 clear_glyph_row (row
);
22049 row
->enabled_p
= true;
22050 row
->full_width_p
= true;
22051 row
->reversed_p
= false;
22054 /* Display all items of the menu bar. */
22055 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
22056 for (i
= 0; i
< ASIZE (items
); i
+= 4)
22058 Lisp_Object string
;
22060 /* Stop at nil string. */
22061 string
= AREF (items
, i
+ 1);
22065 /* Remember where item was displayed. */
22066 ASET (items
, i
+ 3, make_number (it
.hpos
));
22068 /* Display the item, pad with one space. */
22069 if (it
.current_x
< it
.last_visible_x
)
22070 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
22071 SCHARS (string
) + 1, 0, 0, -1);
22074 /* Fill out the line with spaces. */
22075 if (it
.current_x
< it
.last_visible_x
)
22076 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
22078 /* Compute the total height of the lines. */
22079 compute_line_metrics (&it
);
22082 /* Deep copy of a glyph row, including the glyphs. */
22084 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
22086 struct glyph
*pointers
[1 + LAST_AREA
];
22087 int to_used
= to
->used
[TEXT_AREA
];
22089 /* Save glyph pointers of TO. */
22090 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
22092 /* Do a structure assignment. */
22095 /* Restore original glyph pointers of TO. */
22096 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
22098 /* Copy the glyphs. */
22099 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
22100 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
22102 /* If we filled only part of the TO row, fill the rest with
22103 space_glyph (which will display as empty space). */
22104 if (to_used
> from
->used
[TEXT_AREA
])
22105 fill_up_frame_row_with_spaces (to
, to_used
);
22108 /* Display one menu item on a TTY, by overwriting the glyphs in the
22109 frame F's desired glyph matrix with glyphs produced from the menu
22110 item text. Called from term.c to display TTY drop-down menus one
22113 ITEM_TEXT is the menu item text as a C string.
22115 FACE_ID is the face ID to be used for this menu item. FACE_ID
22116 could specify one of 3 faces: a face for an enabled item, a face
22117 for a disabled item, or a face for a selected item.
22119 X and Y are coordinates of the first glyph in the frame's desired
22120 matrix to be overwritten by the menu item. Since this is a TTY, Y
22121 is the zero-based number of the glyph row and X is the zero-based
22122 glyph number in the row, starting from left, where to start
22123 displaying the item.
22125 SUBMENU means this menu item drops down a submenu, which
22126 should be indicated by displaying a proper visual cue after the
22130 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
22131 int x
, int y
, bool submenu
)
22134 struct frame
*f
= SELECTED_FRAME ();
22135 struct window
*w
= XWINDOW (f
->selected_window
);
22136 struct glyph_row
*row
;
22137 size_t item_len
= strlen (item_text
);
22139 eassert (FRAME_TERMCAP_P (f
));
22141 /* Don't write beyond the matrix's last row. This can happen for
22142 TTY screens that are not high enough to show the entire menu.
22143 (This is actually a bit of defensive programming, as
22144 tty_menu_display already limits the number of menu items to one
22145 less than the number of screen lines.) */
22146 if (y
>= f
->desired_matrix
->nrows
)
22149 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
22150 it
.first_visible_x
= 0;
22151 it
.last_visible_x
= FRAME_COLS (f
) - 1;
22152 row
= it
.glyph_row
;
22153 /* Start with the row contents from the current matrix. */
22154 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
22155 bool saved_width
= row
->full_width_p
;
22156 row
->full_width_p
= true;
22157 bool saved_reversed
= row
->reversed_p
;
22158 row
->reversed_p
= false;
22159 row
->enabled_p
= true;
22161 /* Arrange for the menu item glyphs to start at (X,Y) and have the
22163 eassert (x
< f
->desired_matrix
->matrix_w
);
22164 it
.current_x
= it
.hpos
= x
;
22165 it
.current_y
= it
.vpos
= y
;
22166 int saved_used
= row
->used
[TEXT_AREA
];
22167 bool saved_truncated
= row
->truncated_on_right_p
;
22168 row
->used
[TEXT_AREA
] = x
;
22169 it
.face_id
= face_id
;
22170 it
.line_wrap
= TRUNCATE
;
22172 /* FIXME: This should be controlled by a user option. See the
22173 comments in redisplay_tool_bar and display_mode_line about this.
22174 Also, if paragraph_embedding could ever be R2L, changes will be
22175 needed to avoid shifting to the right the row characters in
22176 term.c:append_glyph. */
22177 it
.paragraph_embedding
= L2R
;
22179 /* Pad with a space on the left. */
22180 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
22182 /* Display the menu item, pad with spaces to WIDTH. */
22185 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
22186 item_len
, 0, FRAME_COLS (f
) - 1, -1);
22188 /* Indicate with " >" that there's a submenu. */
22189 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
22190 FRAME_COLS (f
) - 1, -1);
22193 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
22194 width
, 0, FRAME_COLS (f
) - 1, -1);
22196 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
22197 row
->truncated_on_right_p
= saved_truncated
;
22198 row
->hash
= row_hash (row
);
22199 row
->full_width_p
= saved_width
;
22200 row
->reversed_p
= saved_reversed
;
22203 /***********************************************************************
22205 ***********************************************************************/
22207 /* Redisplay mode lines in the window tree whose root is WINDOW.
22208 If FORCE, redisplay mode lines unconditionally.
22209 Otherwise, redisplay only mode lines that are garbaged. Value is
22210 the number of windows whose mode lines were redisplayed. */
22213 redisplay_mode_lines (Lisp_Object window
, bool force
)
22217 while (!NILP (window
))
22219 struct window
*w
= XWINDOW (window
);
22221 if (WINDOWP (w
->contents
))
22222 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
22224 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
22225 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
22227 struct text_pos lpoint
;
22228 struct buffer
*old
= current_buffer
;
22230 /* Set the window's buffer for the mode line display. */
22231 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
22232 set_buffer_internal_1 (XBUFFER (w
->contents
));
22234 /* Point refers normally to the selected window. For any
22235 other window, set up appropriate value. */
22236 if (!EQ (window
, selected_window
))
22238 struct text_pos pt
;
22240 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
22241 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
22244 /* Display mode lines. */
22245 clear_glyph_matrix (w
->desired_matrix
);
22246 if (display_mode_lines (w
))
22249 /* Restore old settings. */
22250 set_buffer_internal_1 (old
);
22251 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
22261 /* Display the mode and/or header line of window W. Value is the
22262 sum number of mode lines and header lines displayed. */
22265 display_mode_lines (struct window
*w
)
22267 Lisp_Object old_selected_window
= selected_window
;
22268 Lisp_Object old_selected_frame
= selected_frame
;
22269 Lisp_Object new_frame
= w
->frame
;
22270 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
22273 selected_frame
= new_frame
;
22274 /* FIXME: If we were to allow the mode-line's computation changing the buffer
22275 or window's point, then we'd need select_window_1 here as well. */
22276 XSETWINDOW (selected_window
, w
);
22277 XFRAME (new_frame
)->selected_window
= selected_window
;
22279 /* These will be set while the mode line specs are processed. */
22280 line_number_displayed
= false;
22281 w
->column_number_displayed
= -1;
22283 if (WINDOW_WANTS_MODELINE_P (w
))
22285 struct window
*sel_w
= XWINDOW (old_selected_window
);
22287 /* Select mode line face based on the real selected window. */
22288 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
22289 BVAR (current_buffer
, mode_line_format
));
22293 if (WINDOW_WANTS_HEADER_LINE_P (w
))
22295 display_mode_line (w
, HEADER_LINE_FACE_ID
,
22296 BVAR (current_buffer
, header_line_format
));
22300 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
22301 selected_frame
= old_selected_frame
;
22302 selected_window
= old_selected_window
;
22304 w
->must_be_updated_p
= true;
22309 /* Display mode or header line of window W. FACE_ID specifies which
22310 line to display; it is either MODE_LINE_FACE_ID or
22311 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
22312 display. Value is the pixel height of the mode/header line
22316 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
22320 ptrdiff_t count
= SPECPDL_INDEX ();
22322 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
22323 /* Don't extend on a previously drawn mode-line.
22324 This may happen if called from pos_visible_p. */
22325 it
.glyph_row
->enabled_p
= false;
22326 prepare_desired_row (w
, it
.glyph_row
, true);
22328 it
.glyph_row
->mode_line_p
= true;
22330 /* FIXME: This should be controlled by a user option. But
22331 supporting such an option is not trivial, since the mode line is
22332 made up of many separate strings. */
22333 it
.paragraph_embedding
= L2R
;
22335 record_unwind_protect (unwind_format_mode_line
,
22336 format_mode_line_unwind_data (NULL
, NULL
,
22339 mode_line_target
= MODE_LINE_DISPLAY
;
22341 /* Temporarily make frame's keyboard the current kboard so that
22342 kboard-local variables in the mode_line_format will get the right
22344 push_kboard (FRAME_KBOARD (it
.f
));
22345 record_unwind_save_match_data ();
22346 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
22349 unbind_to (count
, Qnil
);
22351 /* Fill up with spaces. */
22352 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
22354 compute_line_metrics (&it
);
22355 it
.glyph_row
->full_width_p
= true;
22356 it
.glyph_row
->continued_p
= false;
22357 it
.glyph_row
->truncated_on_left_p
= false;
22358 it
.glyph_row
->truncated_on_right_p
= false;
22360 /* Make a 3D mode-line have a shadow at its right end. */
22361 face
= FACE_FROM_ID (it
.f
, face_id
);
22362 extend_face_to_end_of_line (&it
);
22363 if (face
->box
!= FACE_NO_BOX
)
22365 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
22366 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
22367 last
->right_box_line_p
= true;
22370 return it
.glyph_row
->height
;
22373 /* Move element ELT in LIST to the front of LIST.
22374 Return the updated list. */
22377 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
22379 register Lisp_Object tail
, prev
;
22380 register Lisp_Object tem
;
22384 while (CONSP (tail
))
22390 /* Splice out the link TAIL. */
22392 list
= XCDR (tail
);
22394 Fsetcdr (prev
, XCDR (tail
));
22396 /* Now make it the first. */
22397 Fsetcdr (tail
, list
);
22402 tail
= XCDR (tail
);
22406 /* Not found--return unchanged LIST. */
22410 /* Contribute ELT to the mode line for window IT->w. How it
22411 translates into text depends on its data type.
22413 IT describes the display environment in which we display, as usual.
22415 DEPTH is the depth in recursion. It is used to prevent
22416 infinite recursion here.
22418 FIELD_WIDTH is the number of characters the display of ELT should
22419 occupy in the mode line, and PRECISION is the maximum number of
22420 characters to display from ELT's representation. See
22421 display_string for details.
22423 Returns the hpos of the end of the text generated by ELT.
22425 PROPS is a property list to add to any string we encounter.
22427 If RISKY, remove (disregard) any properties in any string
22428 we encounter, and ignore :eval and :propertize.
22430 The global variable `mode_line_target' determines whether the
22431 output is passed to `store_mode_line_noprop',
22432 `store_mode_line_string', or `display_string'. */
22435 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
22436 Lisp_Object elt
, Lisp_Object props
, bool risky
)
22438 int n
= 0, field
, prec
;
22439 bool literal
= false;
22443 elt
= build_string ("*too-deep*");
22447 switch (XTYPE (elt
))
22451 /* A string: output it and check for %-constructs within it. */
22453 ptrdiff_t offset
= 0;
22455 if (SCHARS (elt
) > 0
22456 && (!NILP (props
) || risky
))
22458 Lisp_Object oprops
, aelt
;
22459 oprops
= Ftext_properties_at (make_number (0), elt
);
22461 /* If the starting string's properties are not what
22462 we want, translate the string. Also, if the string
22463 is risky, do that anyway. */
22465 if (NILP (Fequal (props
, oprops
)) || risky
)
22467 /* If the starting string has properties,
22468 merge the specified ones onto the existing ones. */
22469 if (! NILP (oprops
) && !risky
)
22473 oprops
= Fcopy_sequence (oprops
);
22475 while (CONSP (tem
))
22477 oprops
= Fplist_put (oprops
, XCAR (tem
),
22478 XCAR (XCDR (tem
)));
22479 tem
= XCDR (XCDR (tem
));
22484 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
22485 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
22487 /* AELT is what we want. Move it to the front
22488 without consing. */
22490 mode_line_proptrans_alist
22491 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
22497 /* If AELT has the wrong props, it is useless.
22498 so get rid of it. */
22500 mode_line_proptrans_alist
22501 = Fdelq (aelt
, mode_line_proptrans_alist
);
22503 elt
= Fcopy_sequence (elt
);
22504 Fset_text_properties (make_number (0), Flength (elt
),
22506 /* Add this item to mode_line_proptrans_alist. */
22507 mode_line_proptrans_alist
22508 = Fcons (Fcons (elt
, props
),
22509 mode_line_proptrans_alist
);
22510 /* Truncate mode_line_proptrans_alist
22511 to at most 50 elements. */
22512 tem
= Fnthcdr (make_number (50),
22513 mode_line_proptrans_alist
);
22515 XSETCDR (tem
, Qnil
);
22524 prec
= precision
- n
;
22525 switch (mode_line_target
)
22527 case MODE_LINE_NOPROP
:
22528 case MODE_LINE_TITLE
:
22529 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
22531 case MODE_LINE_STRING
:
22532 n
+= store_mode_line_string (NULL
, elt
, true, 0, prec
, Qnil
);
22534 case MODE_LINE_DISPLAY
:
22535 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
22536 0, prec
, 0, STRING_MULTIBYTE (elt
));
22543 /* Handle the non-literal case. */
22545 while ((precision
<= 0 || n
< precision
)
22546 && SREF (elt
, offset
) != 0
22547 && (mode_line_target
!= MODE_LINE_DISPLAY
22548 || it
->current_x
< it
->last_visible_x
))
22550 ptrdiff_t last_offset
= offset
;
22552 /* Advance to end of string or next format specifier. */
22553 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
22556 if (offset
- 1 != last_offset
)
22558 ptrdiff_t nchars
, nbytes
;
22560 /* Output to end of string or up to '%'. Field width
22561 is length of string. Don't output more than
22562 PRECISION allows us. */
22565 prec
= c_string_width (SDATA (elt
) + last_offset
,
22566 offset
- last_offset
, precision
- n
,
22569 switch (mode_line_target
)
22571 case MODE_LINE_NOPROP
:
22572 case MODE_LINE_TITLE
:
22573 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
22575 case MODE_LINE_STRING
:
22577 ptrdiff_t bytepos
= last_offset
;
22578 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22579 ptrdiff_t endpos
= (precision
<= 0
22580 ? string_byte_to_char (elt
, offset
)
22581 : charpos
+ nchars
);
22582 Lisp_Object mode_string
22583 = Fsubstring (elt
, make_number (charpos
),
22584 make_number (endpos
));
22585 n
+= store_mode_line_string (NULL
, mode_string
, false,
22589 case MODE_LINE_DISPLAY
:
22591 ptrdiff_t bytepos
= last_offset
;
22592 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22594 if (precision
<= 0)
22595 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
22596 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
22598 STRING_MULTIBYTE (elt
));
22603 else /* c == '%' */
22605 ptrdiff_t percent_position
= offset
;
22607 /* Get the specified minimum width. Zero means
22610 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
22611 field
= field
* 10 + c
- '0';
22613 /* Don't pad beyond the total padding allowed. */
22614 if (field_width
- n
> 0 && field
> field_width
- n
)
22615 field
= field_width
- n
;
22617 /* Note that either PRECISION <= 0 or N < PRECISION. */
22618 prec
= precision
- n
;
22621 n
+= display_mode_element (it
, depth
, field
, prec
,
22622 Vglobal_mode_string
, props
,
22627 ptrdiff_t bytepos
, charpos
;
22629 Lisp_Object string
;
22631 bytepos
= percent_position
;
22632 charpos
= (STRING_MULTIBYTE (elt
)
22633 ? string_byte_to_char (elt
, bytepos
)
22635 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
22636 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
22638 switch (mode_line_target
)
22640 case MODE_LINE_NOPROP
:
22641 case MODE_LINE_TITLE
:
22642 n
+= store_mode_line_noprop (spec
, field
, prec
);
22644 case MODE_LINE_STRING
:
22646 Lisp_Object tem
= build_string (spec
);
22647 props
= Ftext_properties_at (make_number (charpos
), elt
);
22648 /* Should only keep face property in props */
22649 n
+= store_mode_line_string (NULL
, tem
, false,
22650 field
, prec
, props
);
22653 case MODE_LINE_DISPLAY
:
22655 int nglyphs_before
, nwritten
;
22657 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
22658 nwritten
= display_string (spec
, string
, elt
,
22663 /* Assign to the glyphs written above the
22664 string where the `%x' came from, position
22668 struct glyph
*glyph
22669 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
22673 for (i
= 0; i
< nwritten
; ++i
)
22675 glyph
[i
].object
= elt
;
22676 glyph
[i
].charpos
= charpos
;
22693 /* A symbol: process the value of the symbol recursively
22694 as if it appeared here directly. Avoid error if symbol void.
22695 Special case: if value of symbol is a string, output the string
22698 register Lisp_Object tem
;
22700 /* If the variable is not marked as risky to set
22701 then its contents are risky to use. */
22702 if (NILP (Fget (elt
, Qrisky_local_variable
)))
22705 tem
= Fboundp (elt
);
22708 tem
= Fsymbol_value (elt
);
22709 /* If value is a string, output that string literally:
22710 don't check for % within it. */
22714 if (!EQ (tem
, elt
))
22716 /* Give up right away for nil or t. */
22726 register Lisp_Object car
, tem
;
22728 /* A cons cell: five distinct cases.
22729 If first element is :eval or :propertize, do something special.
22730 If first element is a string or a cons, process all the elements
22731 and effectively concatenate them.
22732 If first element is a negative number, truncate displaying cdr to
22733 at most that many characters. If positive, pad (with spaces)
22734 to at least that many characters.
22735 If first element is a symbol, process the cadr or caddr recursively
22736 according to whether the symbol's value is non-nil or nil. */
22738 if (EQ (car
, QCeval
))
22740 /* An element of the form (:eval FORM) means evaluate FORM
22741 and use the result as mode line elements. */
22746 if (CONSP (XCDR (elt
)))
22749 spec
= safe__eval (true, XCAR (XCDR (elt
)));
22750 n
+= display_mode_element (it
, depth
, field_width
- n
,
22751 precision
- n
, spec
, props
,
22755 else if (EQ (car
, QCpropertize
))
22757 /* An element of the form (:propertize ELT PROPS...)
22758 means display ELT but applying properties PROPS. */
22763 if (CONSP (XCDR (elt
)))
22764 n
+= display_mode_element (it
, depth
, field_width
- n
,
22765 precision
- n
, XCAR (XCDR (elt
)),
22766 XCDR (XCDR (elt
)), risky
);
22768 else if (SYMBOLP (car
))
22770 tem
= Fboundp (car
);
22774 /* elt is now the cdr, and we know it is a cons cell.
22775 Use its car if CAR has a non-nil value. */
22778 tem
= Fsymbol_value (car
);
22785 /* Symbol's value is nil (or symbol is unbound)
22786 Get the cddr of the original list
22787 and if possible find the caddr and use that. */
22791 else if (!CONSP (elt
))
22796 else if (INTEGERP (car
))
22798 register int lim
= XINT (car
);
22802 /* Negative int means reduce maximum width. */
22803 if (precision
<= 0)
22806 precision
= min (precision
, -lim
);
22810 /* Padding specified. Don't let it be more than
22811 current maximum. */
22813 lim
= min (precision
, lim
);
22815 /* If that's more padding than already wanted, queue it.
22816 But don't reduce padding already specified even if
22817 that is beyond the current truncation point. */
22818 field_width
= max (lim
, field_width
);
22822 else if (STRINGP (car
) || CONSP (car
))
22824 Lisp_Object halftail
= elt
;
22828 && (precision
<= 0 || n
< precision
))
22830 n
+= display_mode_element (it
, depth
,
22831 /* Do padding only after the last
22832 element in the list. */
22833 (! CONSP (XCDR (elt
))
22836 precision
- n
, XCAR (elt
),
22840 if ((len
& 1) == 0)
22841 halftail
= XCDR (halftail
);
22842 /* Check for cycle. */
22843 if (EQ (halftail
, elt
))
22852 elt
= build_string ("*invalid*");
22856 /* Pad to FIELD_WIDTH. */
22857 if (field_width
> 0 && n
< field_width
)
22859 switch (mode_line_target
)
22861 case MODE_LINE_NOPROP
:
22862 case MODE_LINE_TITLE
:
22863 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
22865 case MODE_LINE_STRING
:
22866 n
+= store_mode_line_string ("", Qnil
, false, field_width
- n
, 0,
22869 case MODE_LINE_DISPLAY
:
22870 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
22879 /* Store a mode-line string element in mode_line_string_list.
22881 If STRING is non-null, display that C string. Otherwise, the Lisp
22882 string LISP_STRING is displayed.
22884 FIELD_WIDTH is the minimum number of output glyphs to produce.
22885 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22886 with spaces. FIELD_WIDTH <= 0 means don't pad.
22888 PRECISION is the maximum number of characters to output from
22889 STRING. PRECISION <= 0 means don't truncate the string.
22891 If COPY_STRING, make a copy of LISP_STRING before adding
22892 properties to the string.
22894 PROPS are the properties to add to the string.
22895 The mode_line_string_face face property is always added to the string.
22899 store_mode_line_string (const char *string
, Lisp_Object lisp_string
,
22901 int field_width
, int precision
, Lisp_Object props
)
22906 if (string
!= NULL
)
22908 len
= strlen (string
);
22909 if (precision
> 0 && len
> precision
)
22911 lisp_string
= make_string (string
, len
);
22913 props
= mode_line_string_face_prop
;
22914 else if (!NILP (mode_line_string_face
))
22916 Lisp_Object face
= Fplist_get (props
, Qface
);
22917 props
= Fcopy_sequence (props
);
22919 face
= mode_line_string_face
;
22921 face
= list2 (face
, mode_line_string_face
);
22922 props
= Fplist_put (props
, Qface
, face
);
22924 Fadd_text_properties (make_number (0), make_number (len
),
22925 props
, lisp_string
);
22929 len
= XFASTINT (Flength (lisp_string
));
22930 if (precision
> 0 && len
> precision
)
22933 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
22936 if (!NILP (mode_line_string_face
))
22940 props
= Ftext_properties_at (make_number (0), lisp_string
);
22941 face
= Fplist_get (props
, Qface
);
22943 face
= mode_line_string_face
;
22945 face
= list2 (face
, mode_line_string_face
);
22946 props
= list2 (Qface
, face
);
22948 lisp_string
= Fcopy_sequence (lisp_string
);
22951 Fadd_text_properties (make_number (0), make_number (len
),
22952 props
, lisp_string
);
22957 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22961 if (field_width
> len
)
22963 field_width
-= len
;
22964 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
22966 Fadd_text_properties (make_number (0), make_number (field_width
),
22967 props
, lisp_string
);
22968 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22976 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
22978 doc
: /* Format a string out of a mode line format specification.
22979 First arg FORMAT specifies the mode line format (see `mode-line-format'
22980 for details) to use.
22982 By default, the format is evaluated for the currently selected window.
22984 Optional second arg FACE specifies the face property to put on all
22985 characters for which no face is specified. The value nil means the
22986 default face. The value t means whatever face the window's mode line
22987 currently uses (either `mode-line' or `mode-line-inactive',
22988 depending on whether the window is the selected window or not).
22989 An integer value means the value string has no text
22992 Optional third and fourth args WINDOW and BUFFER specify the window
22993 and buffer to use as the context for the formatting (defaults
22994 are the selected window and the WINDOW's buffer). */)
22995 (Lisp_Object format
, Lisp_Object face
,
22996 Lisp_Object window
, Lisp_Object buffer
)
23001 struct buffer
*old_buffer
= NULL
;
23003 bool no_props
= INTEGERP (face
);
23004 ptrdiff_t count
= SPECPDL_INDEX ();
23006 int string_start
= 0;
23008 w
= decode_any_window (window
);
23009 XSETWINDOW (window
, w
);
23012 buffer
= w
->contents
;
23013 CHECK_BUFFER (buffer
);
23015 /* Make formatting the modeline a non-op when noninteractive, otherwise
23016 there will be problems later caused by a partially initialized frame. */
23017 if (NILP (format
) || noninteractive
)
23018 return empty_unibyte_string
;
23023 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
23024 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
23025 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
23026 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
23027 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
23028 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
23029 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
23032 old_buffer
= current_buffer
;
23034 /* Save things including mode_line_proptrans_alist,
23035 and set that to nil so that we don't alter the outer value. */
23036 record_unwind_protect (unwind_format_mode_line
,
23037 format_mode_line_unwind_data
23038 (XFRAME (WINDOW_FRAME (w
)),
23039 old_buffer
, selected_window
, true));
23040 mode_line_proptrans_alist
= Qnil
;
23042 Fselect_window (window
, Qt
);
23043 set_buffer_internal_1 (XBUFFER (buffer
));
23045 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
23049 mode_line_target
= MODE_LINE_NOPROP
;
23050 mode_line_string_face_prop
= Qnil
;
23051 mode_line_string_list
= Qnil
;
23052 string_start
= MODE_LINE_NOPROP_LEN (0);
23056 mode_line_target
= MODE_LINE_STRING
;
23057 mode_line_string_list
= Qnil
;
23058 mode_line_string_face
= face
;
23059 mode_line_string_face_prop
23060 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
23063 push_kboard (FRAME_KBOARD (it
.f
));
23064 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
23069 len
= MODE_LINE_NOPROP_LEN (string_start
);
23070 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
23074 mode_line_string_list
= Fnreverse (mode_line_string_list
);
23075 str
= Fmapconcat (Qidentity
, mode_line_string_list
,
23076 empty_unibyte_string
);
23079 unbind_to (count
, Qnil
);
23083 /* Write a null-terminated, right justified decimal representation of
23084 the positive integer D to BUF using a minimal field width WIDTH. */
23087 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
23089 register char *p
= buf
;
23097 *p
++ = d
% 10 + '0';
23102 for (width
-= (int) (p
- buf
); width
> 0; --width
)
23113 /* Write a null-terminated, right justified decimal and "human
23114 readable" representation of the nonnegative integer D to BUF using
23115 a minimal field width WIDTH. D should be smaller than 999.5e24. */
23117 static const char power_letter
[] =
23131 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
23133 /* We aim to represent the nonnegative integer D as
23134 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
23135 ptrdiff_t quotient
= d
;
23137 /* -1 means: do not use TENTHS. */
23141 /* Length of QUOTIENT.TENTHS as a string. */
23147 if (quotient
>= 1000)
23149 /* Scale to the appropriate EXPONENT. */
23152 remainder
= quotient
% 1000;
23156 while (quotient
>= 1000);
23158 /* Round to nearest and decide whether to use TENTHS or not. */
23161 tenths
= remainder
/ 100;
23162 if (remainder
% 100 >= 50)
23169 if (quotient
== 10)
23177 if (remainder
>= 500)
23179 if (quotient
< 999)
23190 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
23191 if (tenths
== -1 && quotient
<= 99)
23198 p
= psuffix
= buf
+ max (width
, length
);
23200 /* Print EXPONENT. */
23201 *psuffix
++ = power_letter
[exponent
];
23204 /* Print TENTHS. */
23207 *--p
= '0' + tenths
;
23211 /* Print QUOTIENT. */
23214 int digit
= quotient
% 10;
23215 *--p
= '0' + digit
;
23217 while ((quotient
/= 10) != 0);
23219 /* Print leading spaces. */
23224 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
23225 If EOL_FLAG, set also a mnemonic character for end-of-line
23226 type of CODING_SYSTEM. Return updated pointer into BUF. */
23228 static unsigned char invalid_eol_type
[] = "(*invalid*)";
23231 decode_mode_spec_coding (Lisp_Object coding_system
, char *buf
, bool eol_flag
)
23234 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
23235 const unsigned char *eol_str
;
23237 /* The EOL conversion we are using. */
23238 Lisp_Object eoltype
;
23240 val
= CODING_SYSTEM_SPEC (coding_system
);
23243 if (!VECTORP (val
)) /* Not yet decided. */
23245 *buf
++ = multibyte
? '-' : ' ';
23247 eoltype
= eol_mnemonic_undecided
;
23248 /* Don't mention EOL conversion if it isn't decided. */
23253 Lisp_Object eolvalue
;
23255 attrs
= AREF (val
, 0);
23256 eolvalue
= AREF (val
, 2);
23259 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
23264 /* The EOL conversion that is normal on this system. */
23266 if (NILP (eolvalue
)) /* Not yet decided. */
23267 eoltype
= eol_mnemonic_undecided
;
23268 else if (VECTORP (eolvalue
)) /* Not yet decided. */
23269 eoltype
= eol_mnemonic_undecided
;
23270 else /* eolvalue is Qunix, Qdos, or Qmac. */
23271 eoltype
= (EQ (eolvalue
, Qunix
)
23272 ? eol_mnemonic_unix
23273 : EQ (eolvalue
, Qdos
)
23274 ? eol_mnemonic_dos
: eol_mnemonic_mac
);
23280 /* Mention the EOL conversion if it is not the usual one. */
23281 if (STRINGP (eoltype
))
23283 eol_str
= SDATA (eoltype
);
23284 eol_str_len
= SBYTES (eoltype
);
23286 else if (CHARACTERP (eoltype
))
23288 int c
= XFASTINT (eoltype
);
23289 return buf
+ CHAR_STRING (c
, (unsigned char *) buf
);
23293 eol_str
= invalid_eol_type
;
23294 eol_str_len
= sizeof (invalid_eol_type
) - 1;
23296 memcpy (buf
, eol_str
, eol_str_len
);
23297 buf
+= eol_str_len
;
23303 /* Return a string for the output of a mode line %-spec for window W,
23304 generated by character C. FIELD_WIDTH > 0 means pad the string
23305 returned with spaces to that value. Return a Lisp string in
23306 *STRING if the resulting string is taken from that Lisp string.
23308 Note we operate on the current buffer for most purposes. */
23310 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
23312 static const char *
23313 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
23314 Lisp_Object
*string
)
23317 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23318 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
23319 /* We are going to use f->decode_mode_spec_buffer as the buffer to
23320 produce strings from numerical values, so limit preposterously
23321 large values of FIELD_WIDTH to avoid overrunning the buffer's
23322 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
23323 bytes plus the terminating null. */
23324 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
23325 struct buffer
*b
= current_buffer
;
23333 if (!NILP (BVAR (b
, read_only
)))
23335 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23340 /* This differs from %* only for a modified read-only buffer. */
23341 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23343 if (!NILP (BVAR (b
, read_only
)))
23348 /* This differs from %* in ignoring read-only-ness. */
23349 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23361 if (command_loop_level
> 5)
23363 p
= decode_mode_spec_buf
;
23364 for (i
= 0; i
< command_loop_level
; i
++)
23367 return decode_mode_spec_buf
;
23375 if (command_loop_level
> 5)
23377 p
= decode_mode_spec_buf
;
23378 for (i
= 0; i
< command_loop_level
; i
++)
23381 return decode_mode_spec_buf
;
23388 /* Let lots_of_dashes be a string of infinite length. */
23389 if (mode_line_target
== MODE_LINE_NOPROP
23390 || mode_line_target
== MODE_LINE_STRING
)
23392 if (field_width
<= 0
23393 || field_width
> sizeof (lots_of_dashes
))
23395 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
23396 decode_mode_spec_buf
[i
] = '-';
23397 decode_mode_spec_buf
[i
] = '\0';
23398 return decode_mode_spec_buf
;
23401 return lots_of_dashes
;
23405 obj
= BVAR (b
, name
);
23409 /* %c and %l are ignored in `frame-title-format'.
23410 (In redisplay_internal, the frame title is drawn _before_ the
23411 windows are updated, so the stuff which depends on actual
23412 window contents (such as %l) may fail to render properly, or
23413 even crash emacs.) */
23414 if (mode_line_target
== MODE_LINE_TITLE
)
23418 ptrdiff_t col
= current_column ();
23419 w
->column_number_displayed
= col
;
23420 pint2str (decode_mode_spec_buf
, width
, col
);
23421 return decode_mode_spec_buf
;
23425 #if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
23427 if (NILP (Vmemory_full
))
23430 return "!MEM FULL! ";
23437 /* %F displays the frame name. */
23438 if (!NILP (f
->title
))
23439 return SSDATA (f
->title
);
23440 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
23441 return SSDATA (f
->name
);
23445 obj
= BVAR (b
, filename
);
23450 ptrdiff_t size
= ZV
- BEGV
;
23451 pint2str (decode_mode_spec_buf
, width
, size
);
23452 return decode_mode_spec_buf
;
23457 ptrdiff_t size
= ZV
- BEGV
;
23458 pint2hrstr (decode_mode_spec_buf
, width
, size
);
23459 return decode_mode_spec_buf
;
23464 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
23465 ptrdiff_t topline
, nlines
, height
;
23468 /* %c and %l are ignored in `frame-title-format'. */
23469 if (mode_line_target
== MODE_LINE_TITLE
)
23472 startpos
= marker_position (w
->start
);
23473 startpos_byte
= marker_byte_position (w
->start
);
23474 height
= WINDOW_TOTAL_LINES (w
);
23476 /* If we decided that this buffer isn't suitable for line numbers,
23477 don't forget that too fast. */
23478 if (w
->base_line_pos
== -1)
23481 /* If the buffer is very big, don't waste time. */
23482 if (INTEGERP (Vline_number_display_limit
)
23483 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
23485 w
->base_line_pos
= 0;
23486 w
->base_line_number
= 0;
23490 if (w
->base_line_number
> 0
23491 && w
->base_line_pos
> 0
23492 && w
->base_line_pos
<= startpos
)
23494 line
= w
->base_line_number
;
23495 linepos
= w
->base_line_pos
;
23496 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
23501 linepos
= BUF_BEGV (b
);
23502 linepos_byte
= BUF_BEGV_BYTE (b
);
23505 /* Count lines from base line to window start position. */
23506 nlines
= display_count_lines (linepos_byte
,
23510 topline
= nlines
+ line
;
23512 /* Determine a new base line, if the old one is too close
23513 or too far away, or if we did not have one.
23514 "Too close" means it's plausible a scroll-down would
23515 go back past it. */
23516 if (startpos
== BUF_BEGV (b
))
23518 w
->base_line_number
= topline
;
23519 w
->base_line_pos
= BUF_BEGV (b
);
23521 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
23522 || linepos
== BUF_BEGV (b
))
23524 ptrdiff_t limit
= BUF_BEGV (b
);
23525 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
23526 ptrdiff_t position
;
23527 ptrdiff_t distance
=
23528 (height
* 2 + 30) * line_number_display_limit_width
;
23530 if (startpos
- distance
> limit
)
23532 limit
= startpos
- distance
;
23533 limit_byte
= CHAR_TO_BYTE (limit
);
23536 nlines
= display_count_lines (startpos_byte
,
23538 - (height
* 2 + 30),
23540 /* If we couldn't find the lines we wanted within
23541 line_number_display_limit_width chars per line,
23542 give up on line numbers for this window. */
23543 if (position
== limit_byte
&& limit
== startpos
- distance
)
23545 w
->base_line_pos
= -1;
23546 w
->base_line_number
= 0;
23550 w
->base_line_number
= topline
- nlines
;
23551 w
->base_line_pos
= BYTE_TO_CHAR (position
);
23554 /* Now count lines from the start pos to point. */
23555 nlines
= display_count_lines (startpos_byte
,
23556 PT_BYTE
, PT
, &junk
);
23558 /* Record that we did display the line number. */
23559 line_number_displayed
= true;
23561 /* Make the string to show. */
23562 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
23563 return decode_mode_spec_buf
;
23566 char *p
= decode_mode_spec_buf
;
23567 int pad
= width
- 2;
23573 return decode_mode_spec_buf
;
23579 obj
= BVAR (b
, mode_name
);
23583 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
23589 ptrdiff_t pos
= marker_position (w
->start
);
23590 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23592 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
23594 if (pos
<= BUF_BEGV (b
))
23599 else if (pos
<= BUF_BEGV (b
))
23603 if (total
> 1000000)
23604 /* Do it differently for a large value, to avoid overflow. */
23605 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23607 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23608 /* We can't normally display a 3-digit number,
23609 so get us a 2-digit number that is close. */
23612 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23613 return decode_mode_spec_buf
;
23617 /* Display percentage of size above the bottom of the screen. */
23620 ptrdiff_t toppos
= marker_position (w
->start
);
23621 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
23622 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23624 if (botpos
>= BUF_ZV (b
))
23626 if (toppos
<= BUF_BEGV (b
))
23633 if (total
> 1000000)
23634 /* Do it differently for a large value, to avoid overflow. */
23635 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23637 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23638 /* We can't normally display a 3-digit number,
23639 so get us a 2-digit number that is close. */
23642 if (toppos
<= BUF_BEGV (b
))
23643 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
23645 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23646 return decode_mode_spec_buf
;
23651 /* status of process */
23652 obj
= Fget_buffer_process (Fcurrent_buffer ());
23654 return "no process";
23656 obj
= Fsymbol_name (Fprocess_status (obj
));
23662 ptrdiff_t count
= inhibit_garbage_collection ();
23663 Lisp_Object curdir
= BVAR (current_buffer
, directory
);
23664 Lisp_Object val
= Qnil
;
23666 if (STRINGP (curdir
))
23667 val
= call1 (intern ("file-remote-p"), curdir
);
23669 unbind_to (count
, Qnil
);
23678 /* coding-system (not including end-of-line format) */
23680 /* coding-system (including end-of-line type) */
23682 bool eol_flag
= (c
== 'Z');
23683 char *p
= decode_mode_spec_buf
;
23685 if (! FRAME_WINDOW_P (f
))
23687 /* No need to mention EOL here--the terminal never needs
23688 to do EOL conversion. */
23689 p
= decode_mode_spec_coding (CODING_ID_NAME
23690 (FRAME_KEYBOARD_CODING (f
)->id
),
23692 p
= decode_mode_spec_coding (CODING_ID_NAME
23693 (FRAME_TERMINAL_CODING (f
)->id
),
23696 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
23699 #if false /* This proves to be annoying; I think we can do without. -- rms. */
23700 #ifdef subprocesses
23701 obj
= Fget_buffer_process (Fcurrent_buffer ());
23702 if (PROCESSP (obj
))
23704 p
= decode_mode_spec_coding
23705 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
23706 p
= decode_mode_spec_coding
23707 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
23709 #endif /* subprocesses */
23712 return decode_mode_spec_buf
;
23719 return SSDATA (obj
);
23726 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
23727 means count lines back from START_BYTE. But don't go beyond
23728 LIMIT_BYTE. Return the number of lines thus found (always
23731 Set *BYTE_POS_PTR to the byte position where we stopped. This is
23732 either the position COUNT lines after/before START_BYTE, if we
23733 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
23737 display_count_lines (ptrdiff_t start_byte
,
23738 ptrdiff_t limit_byte
, ptrdiff_t count
,
23739 ptrdiff_t *byte_pos_ptr
)
23741 register unsigned char *cursor
;
23742 unsigned char *base
;
23744 register ptrdiff_t ceiling
;
23745 register unsigned char *ceiling_addr
;
23746 ptrdiff_t orig_count
= count
;
23748 /* If we are not in selective display mode,
23749 check only for newlines. */
23750 bool selective_display
23751 = (!NILP (BVAR (current_buffer
, selective_display
))
23752 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
23756 while (start_byte
< limit_byte
)
23758 ceiling
= BUFFER_CEILING_OF (start_byte
);
23759 ceiling
= min (limit_byte
- 1, ceiling
);
23760 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
23761 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
23765 if (selective_display
)
23767 while (*cursor
!= '\n' && *cursor
!= 015
23768 && ++cursor
!= ceiling_addr
)
23770 if (cursor
== ceiling_addr
)
23775 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
23784 start_byte
+= cursor
- base
;
23785 *byte_pos_ptr
= start_byte
;
23789 while (cursor
< ceiling_addr
);
23791 start_byte
+= ceiling_addr
- base
;
23796 while (start_byte
> limit_byte
)
23798 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
23799 ceiling
= max (limit_byte
, ceiling
);
23800 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
23801 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
23804 if (selective_display
)
23806 while (--cursor
>= ceiling_addr
23807 && *cursor
!= '\n' && *cursor
!= 015)
23809 if (cursor
< ceiling_addr
)
23814 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
23821 start_byte
+= cursor
- base
+ 1;
23822 *byte_pos_ptr
= start_byte
;
23823 /* When scanning backwards, we should
23824 not count the newline posterior to which we stop. */
23825 return - orig_count
- 1;
23828 start_byte
+= ceiling_addr
- base
;
23832 *byte_pos_ptr
= limit_byte
;
23835 return - orig_count
+ count
;
23836 return orig_count
- count
;
23842 /***********************************************************************
23844 ***********************************************************************/
23846 /* Display a NUL-terminated string, starting with index START.
23848 If STRING is non-null, display that C string. Otherwise, the Lisp
23849 string LISP_STRING is displayed. There's a case that STRING is
23850 non-null and LISP_STRING is not nil. It means STRING is a string
23851 data of LISP_STRING. In that case, we display LISP_STRING while
23852 ignoring its text properties.
23854 If FACE_STRING is not nil, FACE_STRING_POS is a position in
23855 FACE_STRING. Display STRING or LISP_STRING with the face at
23856 FACE_STRING_POS in FACE_STRING:
23858 Display the string in the environment given by IT, but use the
23859 standard display table, temporarily.
23861 FIELD_WIDTH is the minimum number of output glyphs to produce.
23862 If STRING has fewer characters than FIELD_WIDTH, pad to the right
23863 with spaces. If STRING has more characters, more than FIELD_WIDTH
23864 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
23866 PRECISION is the maximum number of characters to output from
23867 STRING. PRECISION < 0 means don't truncate the string.
23869 This is roughly equivalent to printf format specifiers:
23871 FIELD_WIDTH PRECISION PRINTF
23872 ----------------------------------------
23878 MULTIBYTE zero means do not display multibyte chars, > 0 means do
23879 display them, and < 0 means obey the current buffer's value of
23880 enable_multibyte_characters.
23882 Value is the number of columns displayed. */
23885 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
23886 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
23887 int field_width
, int precision
, int max_x
, int multibyte
)
23889 int hpos_at_start
= it
->hpos
;
23890 int saved_face_id
= it
->face_id
;
23891 struct glyph_row
*row
= it
->glyph_row
;
23892 ptrdiff_t it_charpos
;
23894 /* Initialize the iterator IT for iteration over STRING beginning
23895 with index START. */
23896 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
23897 precision
, field_width
, multibyte
);
23898 if (string
&& STRINGP (lisp_string
))
23899 /* LISP_STRING is the one returned by decode_mode_spec. We should
23900 ignore its text properties. */
23901 it
->stop_charpos
= it
->end_charpos
;
23903 /* If displaying STRING, set up the face of the iterator from
23904 FACE_STRING, if that's given. */
23905 if (STRINGP (face_string
))
23911 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
23912 0, &endptr
, it
->base_face_id
, false);
23913 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23914 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
23917 /* Set max_x to the maximum allowed X position. Don't let it go
23918 beyond the right edge of the window. */
23920 max_x
= it
->last_visible_x
;
23922 max_x
= min (max_x
, it
->last_visible_x
);
23924 /* Skip over display elements that are not visible. because IT->w is
23926 if (it
->current_x
< it
->first_visible_x
)
23927 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
23928 MOVE_TO_POS
| MOVE_TO_X
);
23930 row
->ascent
= it
->max_ascent
;
23931 row
->height
= it
->max_ascent
+ it
->max_descent
;
23932 row
->phys_ascent
= it
->max_phys_ascent
;
23933 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
23934 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
23936 if (STRINGP (it
->string
))
23937 it_charpos
= IT_STRING_CHARPOS (*it
);
23939 it_charpos
= IT_CHARPOS (*it
);
23941 /* This condition is for the case that we are called with current_x
23942 past last_visible_x. */
23943 while (it
->current_x
< max_x
)
23945 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
23947 /* Get the next display element. */
23948 if (!get_next_display_element (it
))
23951 /* Produce glyphs. */
23952 x_before
= it
->current_x
;
23953 n_glyphs_before
= row
->used
[TEXT_AREA
];
23954 PRODUCE_GLYPHS (it
);
23956 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
23959 while (i
< nglyphs
)
23961 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
23963 if (it
->line_wrap
!= TRUNCATE
23964 && x
+ glyph
->pixel_width
> max_x
)
23966 /* End of continued line or max_x reached. */
23967 if (CHAR_GLYPH_PADDING_P (*glyph
))
23969 /* A wide character is unbreakable. */
23970 if (row
->reversed_p
)
23971 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23972 - n_glyphs_before
);
23973 row
->used
[TEXT_AREA
] = n_glyphs_before
;
23974 it
->current_x
= x_before
;
23978 if (row
->reversed_p
)
23979 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23980 - (n_glyphs_before
+ i
));
23981 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
23986 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
23988 /* Glyph is at least partially visible. */
23990 if (x
< it
->first_visible_x
)
23991 row
->x
= x
- it
->first_visible_x
;
23995 /* Glyph is off the left margin of the display area.
23996 Should not happen. */
24000 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
24001 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
24002 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
24003 row
->phys_height
= max (row
->phys_height
,
24004 it
->max_phys_ascent
+ it
->max_phys_descent
);
24005 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
24006 it
->max_extra_line_spacing
);
24007 x
+= glyph
->pixel_width
;
24011 /* Stop if max_x reached. */
24015 /* Stop at line ends. */
24016 if (ITERATOR_AT_END_OF_LINE_P (it
))
24018 it
->continuation_lines_width
= 0;
24022 set_iterator_to_next (it
, true);
24023 if (STRINGP (it
->string
))
24024 it_charpos
= IT_STRING_CHARPOS (*it
);
24026 it_charpos
= IT_CHARPOS (*it
);
24028 /* Stop if truncating at the right edge. */
24029 if (it
->line_wrap
== TRUNCATE
24030 && it
->current_x
>= it
->last_visible_x
)
24032 /* Add truncation mark, but don't do it if the line is
24033 truncated at a padding space. */
24034 if (it_charpos
< it
->string_nchars
)
24036 if (!FRAME_WINDOW_P (it
->f
))
24040 if (it
->current_x
> it
->last_visible_x
)
24042 if (!row
->reversed_p
)
24044 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
24045 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
24050 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
24051 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
24053 unproduce_glyphs (it
, ii
+ 1);
24054 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
24056 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
24058 row
->used
[TEXT_AREA
] = ii
;
24059 produce_special_glyphs (it
, IT_TRUNCATION
);
24062 produce_special_glyphs (it
, IT_TRUNCATION
);
24064 row
->truncated_on_right_p
= true;
24070 /* Maybe insert a truncation at the left. */
24071 if (it
->first_visible_x
24074 if (!FRAME_WINDOW_P (it
->f
)
24075 || (row
->reversed_p
24076 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
24077 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
24078 insert_left_trunc_glyphs (it
);
24079 row
->truncated_on_left_p
= true;
24082 it
->face_id
= saved_face_id
;
24084 /* Value is number of columns displayed. */
24085 return it
->hpos
- hpos_at_start
;
24090 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
24091 appears as an element of LIST or as the car of an element of LIST.
24092 If PROPVAL is a list, compare each element against LIST in that
24093 way, and return 1/2 if any element of PROPVAL is found in LIST.
24094 Otherwise return 0. This function cannot quit.
24095 The return value is 2 if the text is invisible but with an ellipsis
24096 and 1 if it's invisible and without an ellipsis. */
24099 invisible_prop (Lisp_Object propval
, Lisp_Object list
)
24101 Lisp_Object tail
, proptail
;
24103 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
24105 register Lisp_Object tem
;
24107 if (EQ (propval
, tem
))
24109 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
24110 return NILP (XCDR (tem
)) ? 1 : 2;
24113 if (CONSP (propval
))
24115 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
24117 Lisp_Object propelt
;
24118 propelt
= XCAR (proptail
);
24119 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
24121 register Lisp_Object tem
;
24123 if (EQ (propelt
, tem
))
24125 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
24126 return NILP (XCDR (tem
)) ? 1 : 2;
24134 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
24135 doc
: /* Non-nil if the property makes the text invisible.
24136 POS-OR-PROP can be a marker or number, in which case it is taken to be
24137 a position in the current buffer and the value of the `invisible' property
24138 is checked; or it can be some other value, which is then presumed to be the
24139 value of the `invisible' property of the text of interest.
24140 The non-nil value returned can be t for truly invisible text or something
24141 else if the text is replaced by an ellipsis. */)
24142 (Lisp_Object pos_or_prop
)
24145 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
24146 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
24148 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
24149 return (invis
== 0 ? Qnil
24151 : make_number (invis
));
24154 /* Calculate a width or height in pixels from a specification using
24155 the following elements:
24158 NUM - a (fractional) multiple of the default font width/height
24159 (NUM) - specifies exactly NUM pixels
24160 UNIT - a fixed number of pixels, see below.
24161 ELEMENT - size of a display element in pixels, see below.
24162 (NUM . SPEC) - equals NUM * SPEC
24163 (+ SPEC SPEC ...) - add pixel values
24164 (- SPEC SPEC ...) - subtract pixel values
24165 (- SPEC) - negate pixel value
24168 INT or FLOAT - a number constant
24169 SYMBOL - use symbol's (buffer local) variable binding.
24172 in - pixels per inch *)
24173 mm - pixels per 1/1000 meter *)
24174 cm - pixels per 1/100 meter *)
24175 width - width of current font in pixels.
24176 height - height of current font in pixels.
24178 *) using the ratio(s) defined in display-pixels-per-inch.
24182 left-fringe - left fringe width in pixels
24183 right-fringe - right fringe width in pixels
24185 left-margin - left margin width in pixels
24186 right-margin - right margin width in pixels
24188 scroll-bar - scroll-bar area width in pixels
24192 Pixels corresponding to 5 inches:
24195 Total width of non-text areas on left side of window (if scroll-bar is on left):
24196 '(space :width (+ left-fringe left-margin scroll-bar))
24198 Align to first text column (in header line):
24199 '(space :align-to 0)
24201 Align to middle of text area minus half the width of variable `my-image'
24202 containing a loaded image:
24203 '(space :align-to (0.5 . (- text my-image)))
24205 Width of left margin minus width of 1 character in the default font:
24206 '(space :width (- left-margin 1))
24208 Width of left margin minus width of 2 characters in the current font:
24209 '(space :width (- left-margin (2 . width)))
24211 Center 1 character over left-margin (in header line):
24212 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
24214 Different ways to express width of left fringe plus left margin minus one pixel:
24215 '(space :width (- (+ left-fringe left-margin) (1)))
24216 '(space :width (+ left-fringe left-margin (- (1))))
24217 '(space :width (+ left-fringe left-margin (-1)))
24222 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
24223 struct font
*font
, bool width_p
, int *align_to
)
24227 # define OK_PIXELS(val) (*res = (val), true)
24228 # define OK_ALIGN_TO(val) (*align_to = (val), true)
24231 return OK_PIXELS (0);
24233 eassert (FRAME_LIVE_P (it
->f
));
24235 if (SYMBOLP (prop
))
24237 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
24239 char *unit
= SSDATA (SYMBOL_NAME (prop
));
24241 if (unit
[0] == 'i' && unit
[1] == 'n')
24243 else if (unit
[0] == 'm' && unit
[1] == 'm')
24245 else if (unit
[0] == 'c' && unit
[1] == 'm')
24251 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
24252 : FRAME_RES_Y (it
->f
));
24255 return OK_PIXELS (ppi
/ pixels
);
24260 #ifdef HAVE_WINDOW_SYSTEM
24261 if (EQ (prop
, Qheight
))
24262 return OK_PIXELS (font
24263 ? normal_char_height (font
, -1)
24264 : FRAME_LINE_HEIGHT (it
->f
));
24265 if (EQ (prop
, Qwidth
))
24266 return OK_PIXELS (font
24267 ? FONT_WIDTH (font
)
24268 : FRAME_COLUMN_WIDTH (it
->f
));
24270 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
24271 return OK_PIXELS (1);
24274 if (EQ (prop
, Qtext
))
24275 return OK_PIXELS (width_p
24276 ? window_box_width (it
->w
, TEXT_AREA
)
24277 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
24279 if (align_to
&& *align_to
< 0)
24282 if (EQ (prop
, Qleft
))
24283 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
24284 if (EQ (prop
, Qright
))
24285 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
24286 if (EQ (prop
, Qcenter
))
24287 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
24288 + window_box_width (it
->w
, TEXT_AREA
) / 2);
24289 if (EQ (prop
, Qleft_fringe
))
24290 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24291 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
24292 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
24293 if (EQ (prop
, Qright_fringe
))
24294 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24295 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
24296 : window_box_right_offset (it
->w
, TEXT_AREA
));
24297 if (EQ (prop
, Qleft_margin
))
24298 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
24299 if (EQ (prop
, Qright_margin
))
24300 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
24301 if (EQ (prop
, Qscroll_bar
))
24302 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
24304 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
24305 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24306 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
24311 if (EQ (prop
, Qleft_fringe
))
24312 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
24313 if (EQ (prop
, Qright_fringe
))
24314 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
24315 if (EQ (prop
, Qleft_margin
))
24316 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
24317 if (EQ (prop
, Qright_margin
))
24318 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
24319 if (EQ (prop
, Qscroll_bar
))
24320 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
24323 prop
= buffer_local_value (prop
, it
->w
->contents
);
24324 if (EQ (prop
, Qunbound
))
24328 if (NUMBERP (prop
))
24330 int base_unit
= (width_p
24331 ? FRAME_COLUMN_WIDTH (it
->f
)
24332 : FRAME_LINE_HEIGHT (it
->f
));
24333 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
24338 Lisp_Object car
= XCAR (prop
);
24339 Lisp_Object cdr
= XCDR (prop
);
24343 #ifdef HAVE_WINDOW_SYSTEM
24344 if (FRAME_WINDOW_P (it
->f
)
24345 && valid_image_p (prop
))
24347 ptrdiff_t id
= lookup_image (it
->f
, prop
);
24348 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
24350 return OK_PIXELS (width_p
? img
->width
: img
->height
);
24352 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_spec_p (prop
))
24354 // TODO: Don't return dummy size.
24355 return OK_PIXELS (100);
24358 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
24364 while (CONSP (cdr
))
24366 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
24367 font
, width_p
, align_to
))
24370 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= false;
24375 if (EQ (car
, Qminus
))
24377 return OK_PIXELS (pixels
);
24380 car
= buffer_local_value (car
, it
->w
->contents
);
24381 if (EQ (car
, Qunbound
))
24388 pixels
= XFLOATINT (car
);
24390 return OK_PIXELS (pixels
);
24391 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
24392 font
, width_p
, align_to
))
24393 return OK_PIXELS (pixels
* fact
);
24404 get_font_ascent_descent (struct font
*font
, int *ascent
, int *descent
)
24406 #ifdef HAVE_WINDOW_SYSTEM
24407 normal_char_ascent_descent (font
, -1, ascent
, descent
);
24415 /***********************************************************************
24417 ***********************************************************************/
24419 #ifdef HAVE_WINDOW_SYSTEM
24424 dump_glyph_string (struct glyph_string
*s
)
24426 fprintf (stderr
, "glyph string\n");
24427 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
24428 s
->x
, s
->y
, s
->width
, s
->height
);
24429 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
24430 fprintf (stderr
, " hl = %d\n", s
->hl
);
24431 fprintf (stderr
, " left overhang = %d, right = %d\n",
24432 s
->left_overhang
, s
->right_overhang
);
24433 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
24434 fprintf (stderr
, " extends to end of line = %d\n",
24435 s
->extends_to_end_of_line_p
);
24436 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
24437 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
24440 #endif /* GLYPH_DEBUG */
24442 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
24443 of XChar2b structures for S; it can't be allocated in
24444 init_glyph_string because it must be allocated via `alloca'. W
24445 is the window on which S is drawn. ROW and AREA are the glyph row
24446 and area within the row from which S is constructed. START is the
24447 index of the first glyph structure covered by S. HL is a
24448 face-override for drawing S. */
24451 #define OPTIONAL_HDC(hdc) HDC hdc,
24452 #define DECLARE_HDC(hdc) HDC hdc;
24453 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
24454 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
24457 #ifndef OPTIONAL_HDC
24458 #define OPTIONAL_HDC(hdc)
24459 #define DECLARE_HDC(hdc)
24460 #define ALLOCATE_HDC(hdc, f)
24461 #define RELEASE_HDC(hdc, f)
24465 init_glyph_string (struct glyph_string
*s
,
24467 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
24468 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
24470 memset (s
, 0, sizeof *s
);
24472 s
->f
= XFRAME (w
->frame
);
24476 s
->display
= FRAME_X_DISPLAY (s
->f
);
24477 s
->window
= FRAME_X_WINDOW (s
->f
);
24478 s
->char2b
= char2b
;
24482 s
->first_glyph
= row
->glyphs
[area
] + start
;
24483 s
->height
= row
->height
;
24484 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
24485 s
->ybase
= s
->y
+ row
->ascent
;
24489 /* Append the list of glyph strings with head H and tail T to the list
24490 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
24493 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24494 struct glyph_string
*h
, struct glyph_string
*t
)
24508 /* Prepend the list of glyph strings with head H and tail T to the
24509 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
24513 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24514 struct glyph_string
*h
, struct glyph_string
*t
)
24528 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
24529 Set *HEAD and *TAIL to the resulting list. */
24532 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
24533 struct glyph_string
*s
)
24535 s
->next
= s
->prev
= NULL
;
24536 append_glyph_string_lists (head
, tail
, s
, s
);
24540 /* Get face and two-byte form of character C in face FACE_ID on frame F.
24541 The encoding of C is returned in *CHAR2B. DISPLAY_P means
24542 make sure that X resources for the face returned are allocated.
24543 Value is a pointer to a realized face that is ready for display if
24546 static struct face
*
24547 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
24548 XChar2b
*char2b
, bool display_p
)
24550 struct face
*face
= FACE_FROM_ID (f
, face_id
);
24555 code
= face
->font
->driver
->encode_char (face
->font
, c
);
24557 if (code
== FONT_INVALID_CODE
)
24560 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24562 /* Make sure X resources of the face are allocated. */
24563 #ifdef HAVE_X_WINDOWS
24567 eassert (face
!= NULL
);
24568 prepare_face_for_display (f
, face
);
24575 /* Get face and two-byte form of character glyph GLYPH on frame F.
24576 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
24577 a pointer to a realized face that is ready for display. */
24579 static struct face
*
24580 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
24586 eassert (glyph
->type
== CHAR_GLYPH
);
24587 face
= FACE_FROM_ID (f
, glyph
->face_id
);
24589 /* Make sure X resources of the face are allocated. */
24590 eassert (face
!= NULL
);
24591 prepare_face_for_display (f
, face
);
24595 if (CHAR_BYTE8_P (glyph
->u
.ch
))
24596 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
24598 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
24600 if (code
== FONT_INVALID_CODE
)
24604 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24609 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
24610 Return true iff FONT has a glyph for C. */
24613 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
24617 if (CHAR_BYTE8_P (c
))
24618 code
= CHAR_TO_BYTE8 (c
);
24620 code
= font
->driver
->encode_char (font
, c
);
24622 if (code
== FONT_INVALID_CODE
)
24624 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24629 /* Fill glyph string S with composition components specified by S->cmp.
24631 BASE_FACE is the base face of the composition.
24632 S->cmp_from is the index of the first component for S.
24634 OVERLAPS non-zero means S should draw the foreground only, and use
24635 its physical height for clipping. See also draw_glyphs.
24637 Value is the index of a component not in S. */
24640 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
24644 /* For all glyphs of this composition, starting at the offset
24645 S->cmp_from, until we reach the end of the definition or encounter a
24646 glyph that requires the different face, add it to S. */
24651 s
->for_overlaps
= overlaps
;
24654 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
24656 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
24658 /* TAB in a composition means display glyphs with padding space
24659 on the left or right. */
24662 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
24665 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
24666 s
->char2b
+ i
, true);
24672 s
->font
= s
->face
->font
;
24674 else if (s
->face
!= face
)
24682 if (s
->face
== NULL
)
24684 s
->face
= base_face
->ascii_face
;
24685 s
->font
= s
->face
->font
;
24688 /* All glyph strings for the same composition has the same width,
24689 i.e. the width set for the first component of the composition. */
24690 s
->width
= s
->first_glyph
->pixel_width
;
24692 /* If the specified font could not be loaded, use the frame's
24693 default font, but record the fact that we couldn't load it in
24694 the glyph string so that we can draw rectangles for the
24695 characters of the glyph string. */
24696 if (s
->font
== NULL
)
24698 s
->font_not_found_p
= true;
24699 s
->font
= FRAME_FONT (s
->f
);
24702 /* Adjust base line for subscript/superscript text. */
24703 s
->ybase
+= s
->first_glyph
->voffset
;
24709 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
24710 int start
, int end
, int overlaps
)
24712 struct glyph
*glyph
, *last
;
24713 Lisp_Object lgstring
;
24716 s
->for_overlaps
= overlaps
;
24717 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24718 last
= s
->row
->glyphs
[s
->area
] + end
;
24719 s
->cmp_id
= glyph
->u
.cmp
.id
;
24720 s
->cmp_from
= glyph
->slice
.cmp
.from
;
24721 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
24722 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24723 lgstring
= composition_gstring_from_id (s
->cmp_id
);
24724 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
24726 while (glyph
< last
24727 && glyph
->u
.cmp
.automatic
24728 && glyph
->u
.cmp
.id
== s
->cmp_id
24729 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
24730 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
24732 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
24734 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
24735 unsigned code
= LGLYPH_CODE (lglyph
);
24737 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
24739 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
24740 return glyph
- s
->row
->glyphs
[s
->area
];
24744 /* Fill glyph string S from a sequence glyphs for glyphless characters.
24745 See the comment of fill_glyph_string for arguments.
24746 Value is the index of the first glyph not in S. */
24750 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
24751 int start
, int end
, int overlaps
)
24753 struct glyph
*glyph
, *last
;
24756 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
24757 s
->for_overlaps
= overlaps
;
24758 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24759 last
= s
->row
->glyphs
[s
->area
] + end
;
24760 voffset
= glyph
->voffset
;
24761 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24762 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
24764 s
->width
= glyph
->pixel_width
;
24766 while (glyph
< last
24767 && glyph
->type
== GLYPHLESS_GLYPH
24768 && glyph
->voffset
== voffset
24769 && glyph
->face_id
== face_id
)
24772 s
->width
+= glyph
->pixel_width
;
24775 s
->ybase
+= voffset
;
24776 return glyph
- s
->row
->glyphs
[s
->area
];
24780 /* Fill glyph string S from a sequence of character glyphs.
24782 FACE_ID is the face id of the string. START is the index of the
24783 first glyph to consider, END is the index of the last + 1.
24784 OVERLAPS non-zero means S should draw the foreground only, and use
24785 its physical height for clipping. See also draw_glyphs.
24787 Value is the index of the first glyph not in S. */
24790 fill_glyph_string (struct glyph_string
*s
, int face_id
,
24791 int start
, int end
, int overlaps
)
24793 struct glyph
*glyph
, *last
;
24795 bool glyph_not_available_p
;
24797 eassert (s
->f
== XFRAME (s
->w
->frame
));
24798 eassert (s
->nchars
== 0);
24799 eassert (start
>= 0 && end
> start
);
24801 s
->for_overlaps
= overlaps
;
24802 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24803 last
= s
->row
->glyphs
[s
->area
] + end
;
24804 voffset
= glyph
->voffset
;
24805 s
->padding_p
= glyph
->padding_p
;
24806 glyph_not_available_p
= glyph
->glyph_not_available_p
;
24808 while (glyph
< last
24809 && glyph
->type
== CHAR_GLYPH
24810 && glyph
->voffset
== voffset
24811 /* Same face id implies same font, nowadays. */
24812 && glyph
->face_id
== face_id
24813 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
24815 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
24816 s
->char2b
+ s
->nchars
);
24818 eassert (s
->nchars
<= end
- start
);
24819 s
->width
+= glyph
->pixel_width
;
24820 if (glyph
++->padding_p
!= s
->padding_p
)
24824 s
->font
= s
->face
->font
;
24826 /* If the specified font could not be loaded, use the frame's font,
24827 but record the fact that we couldn't load it in
24828 S->font_not_found_p so that we can draw rectangles for the
24829 characters of the glyph string. */
24830 if (s
->font
== NULL
|| glyph_not_available_p
)
24832 s
->font_not_found_p
= true;
24833 s
->font
= FRAME_FONT (s
->f
);
24836 /* Adjust base line for subscript/superscript text. */
24837 s
->ybase
+= voffset
;
24839 eassert (s
->face
&& s
->face
->gc
);
24840 return glyph
- s
->row
->glyphs
[s
->area
];
24844 /* Fill glyph string S from image glyph S->first_glyph. */
24847 fill_image_glyph_string (struct glyph_string
*s
)
24849 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
24850 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
24852 s
->slice
= s
->first_glyph
->slice
.img
;
24853 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24854 s
->font
= s
->face
->font
;
24855 s
->width
= s
->first_glyph
->pixel_width
;
24857 /* Adjust base line for subscript/superscript text. */
24858 s
->ybase
+= s
->first_glyph
->voffset
;
24862 #ifdef HAVE_XWIDGETS
24864 fill_xwidget_glyph_string (struct glyph_string
*s
)
24866 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
24867 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24868 s
->font
= s
->face
->font
;
24869 s
->width
= s
->first_glyph
->pixel_width
;
24870 s
->ybase
+= s
->first_glyph
->voffset
;
24871 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
24874 /* Fill glyph string S from a sequence of stretch glyphs.
24876 START is the index of the first glyph to consider,
24877 END is the index of the last + 1.
24879 Value is the index of the first glyph not in S. */
24882 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
24884 struct glyph
*glyph
, *last
;
24885 int voffset
, face_id
;
24887 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
24889 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24890 last
= s
->row
->glyphs
[s
->area
] + end
;
24891 face_id
= glyph
->face_id
;
24892 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24893 s
->font
= s
->face
->font
;
24894 s
->width
= glyph
->pixel_width
;
24896 voffset
= glyph
->voffset
;
24900 && glyph
->type
== STRETCH_GLYPH
24901 && glyph
->voffset
== voffset
24902 && glyph
->face_id
== face_id
);
24904 s
->width
+= glyph
->pixel_width
;
24906 /* Adjust base line for subscript/superscript text. */
24907 s
->ybase
+= voffset
;
24909 /* The case that face->gc == 0 is handled when drawing the glyph
24910 string by calling prepare_face_for_display. */
24912 return glyph
- s
->row
->glyphs
[s
->area
];
24915 static struct font_metrics
*
24916 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
24918 static struct font_metrics metrics
;
24923 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
24924 if (code
== FONT_INVALID_CODE
)
24926 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
24930 /* A subroutine that computes "normal" values of ASCENT and DESCENT
24931 for FONT. Values are taken from font-global ones, except for fonts
24932 that claim preposterously large values, but whose glyphs actually
24933 have reasonable dimensions. C is the character to use for metrics
24934 if the font-global values are too large; if C is negative, the
24935 function selects a default character. */
24937 normal_char_ascent_descent (struct font
*font
, int c
, int *ascent
, int *descent
)
24939 *ascent
= FONT_BASE (font
);
24940 *descent
= FONT_DESCENT (font
);
24942 if (FONT_TOO_HIGH (font
))
24946 /* Get metrics of C, defaulting to a reasonably sized ASCII
24948 if (get_char_glyph_code (c
>= 0 ? c
: '{', font
, &char2b
))
24950 struct font_metrics
*pcm
= get_per_char_metric (font
, &char2b
);
24952 if (!(pcm
->width
== 0 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0))
24954 /* We add 1 pixel to character dimensions as heuristics
24955 that produces nicer display, e.g. when the face has
24956 the box attribute. */
24957 *ascent
= pcm
->ascent
+ 1;
24958 *descent
= pcm
->descent
+ 1;
24964 /* A subroutine that computes a reasonable "normal character height"
24965 for fonts that claim preposterously large vertical dimensions, but
24966 whose glyphs are actually reasonably sized. C is the character
24967 whose metrics to use for those fonts, or -1 for default
24970 normal_char_height (struct font
*font
, int c
)
24972 int ascent
, descent
;
24974 normal_char_ascent_descent (font
, c
, &ascent
, &descent
);
24976 return ascent
+ descent
;
24980 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
24981 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
24982 assumed to be zero. */
24985 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
24987 *left
= *right
= 0;
24989 if (glyph
->type
== CHAR_GLYPH
)
24992 struct face
*face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
);
24995 struct font_metrics
*pcm
= get_per_char_metric (face
->font
, &char2b
);
24998 if (pcm
->rbearing
> pcm
->width
)
24999 *right
= pcm
->rbearing
- pcm
->width
;
25000 if (pcm
->lbearing
< 0)
25001 *left
= -pcm
->lbearing
;
25005 else if (glyph
->type
== COMPOSITE_GLYPH
)
25007 if (! glyph
->u
.cmp
.automatic
)
25009 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
25011 if (cmp
->rbearing
> cmp
->pixel_width
)
25012 *right
= cmp
->rbearing
- cmp
->pixel_width
;
25013 if (cmp
->lbearing
< 0)
25014 *left
= - cmp
->lbearing
;
25018 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
25019 struct font_metrics metrics
;
25021 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
25022 glyph
->slice
.cmp
.to
+ 1, &metrics
);
25023 if (metrics
.rbearing
> metrics
.width
)
25024 *right
= metrics
.rbearing
- metrics
.width
;
25025 if (metrics
.lbearing
< 0)
25026 *left
= - metrics
.lbearing
;
25032 /* Return the index of the first glyph preceding glyph string S that
25033 is overwritten by S because of S's left overhang. Value is -1
25034 if no glyphs are overwritten. */
25037 left_overwritten (struct glyph_string
*s
)
25041 if (s
->left_overhang
)
25044 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25045 int first
= s
->first_glyph
- glyphs
;
25047 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
25048 x
-= glyphs
[i
].pixel_width
;
25059 /* Return the index of the first glyph preceding glyph string S that
25060 is overwriting S because of its right overhang. Value is -1 if no
25061 glyph in front of S overwrites S. */
25064 left_overwriting (struct glyph_string
*s
)
25067 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25068 int first
= s
->first_glyph
- glyphs
;
25072 for (i
= first
- 1; i
>= 0; --i
)
25075 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
25078 x
-= glyphs
[i
].pixel_width
;
25085 /* Return the index of the last glyph following glyph string S that is
25086 overwritten by S because of S's right overhang. Value is -1 if
25087 no such glyph is found. */
25090 right_overwritten (struct glyph_string
*s
)
25094 if (s
->right_overhang
)
25097 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25098 int first
= (s
->first_glyph
- glyphs
25099 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
25100 int end
= s
->row
->used
[s
->area
];
25102 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
25103 x
+= glyphs
[i
].pixel_width
;
25112 /* Return the index of the last glyph following glyph string S that
25113 overwrites S because of its left overhang. Value is negative
25114 if no such glyph is found. */
25117 right_overwriting (struct glyph_string
*s
)
25120 int end
= s
->row
->used
[s
->area
];
25121 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25122 int first
= (s
->first_glyph
- glyphs
25123 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
25127 for (i
= first
; i
< end
; ++i
)
25130 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
25133 x
+= glyphs
[i
].pixel_width
;
25140 /* Set background width of glyph string S. START is the index of the
25141 first glyph following S. LAST_X is the right-most x-position + 1
25142 in the drawing area. */
25145 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
25147 /* If the face of this glyph string has to be drawn to the end of
25148 the drawing area, set S->extends_to_end_of_line_p. */
25150 if (start
== s
->row
->used
[s
->area
]
25151 && ((s
->row
->fill_line_p
25152 && (s
->hl
== DRAW_NORMAL_TEXT
25153 || s
->hl
== DRAW_IMAGE_RAISED
25154 || s
->hl
== DRAW_IMAGE_SUNKEN
))
25155 || s
->hl
== DRAW_MOUSE_FACE
))
25156 s
->extends_to_end_of_line_p
= true;
25158 /* If S extends its face to the end of the line, set its
25159 background_width to the distance to the right edge of the drawing
25161 if (s
->extends_to_end_of_line_p
)
25162 s
->background_width
= last_x
- s
->x
+ 1;
25164 s
->background_width
= s
->width
;
25168 /* Compute overhangs and x-positions for glyph string S and its
25169 predecessors, or successors. X is the starting x-position for S.
25170 BACKWARD_P means process predecessors. */
25173 compute_overhangs_and_x (struct glyph_string
*s
, int x
, bool backward_p
)
25179 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
25180 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
25190 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
25191 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
25201 /* The following macros are only called from draw_glyphs below.
25202 They reference the following parameters of that function directly:
25203 `w', `row', `area', and `overlap_p'
25204 as well as the following local variables:
25205 `s', `f', and `hdc' (in W32) */
25208 /* On W32, silently add local `hdc' variable to argument list of
25209 init_glyph_string. */
25210 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
25211 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
25213 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
25214 init_glyph_string (s, char2b, w, row, area, start, hl)
25217 /* Add a glyph string for a stretch glyph to the list of strings
25218 between HEAD and TAIL. START is the index of the stretch glyph in
25219 row area AREA of glyph row ROW. END is the index of the last glyph
25220 in that glyph row area. X is the current output position assigned
25221 to the new glyph string constructed. HL overrides that face of the
25222 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
25223 is the right-most x-position of the drawing area. */
25225 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
25226 and below -- keep them on one line. */
25227 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25230 s = alloca (sizeof *s); \
25231 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25232 START = fill_stretch_glyph_string (s, START, END); \
25233 append_glyph_string (&HEAD, &TAIL, s); \
25239 /* Add a glyph string for an image glyph to the list of strings
25240 between HEAD and TAIL. START is the index of the image glyph in
25241 row area AREA of glyph row ROW. END is the index of the last glyph
25242 in that glyph row area. X is the current output position assigned
25243 to the new glyph string constructed. HL overrides that face of the
25244 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
25245 is the right-most x-position of the drawing area. */
25247 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25250 s = alloca (sizeof *s); \
25251 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25252 fill_image_glyph_string (s); \
25253 append_glyph_string (&HEAD, &TAIL, s); \
25259 #ifndef HAVE_XWIDGETS
25260 # define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25263 # define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25266 s = alloca (sizeof *s); \
25267 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25268 fill_xwidget_glyph_string (s); \
25269 append_glyph_string (&(HEAD), &(TAIL), s); \
25276 /* Add a glyph string for a sequence of character glyphs to the list
25277 of strings between HEAD and TAIL. START is the index of the first
25278 glyph in row area AREA of glyph row ROW that is part of the new
25279 glyph string. END is the index of the last glyph in that glyph row
25280 area. X is the current output position assigned to the new glyph
25281 string constructed. HL overrides that face of the glyph; e.g. it
25282 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
25283 right-most x-position of the drawing area. */
25285 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25291 face_id = (row)->glyphs[area][START].face_id; \
25293 s = alloca (sizeof *s); \
25294 SAFE_NALLOCA (char2b, 1, (END) - (START)); \
25295 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25296 append_glyph_string (&HEAD, &TAIL, s); \
25298 START = fill_glyph_string (s, face_id, START, END, overlaps); \
25303 /* Add a glyph string for a composite sequence to the list of strings
25304 between HEAD and TAIL. START is the index of the first glyph in
25305 row area AREA of glyph row ROW that is part of the new glyph
25306 string. END is the index of the last glyph in that glyph row area.
25307 X is the current output position assigned to the new glyph string
25308 constructed. HL overrides that face of the glyph; e.g. it is
25309 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
25310 x-position of the drawing area. */
25312 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25314 int face_id = (row)->glyphs[area][START].face_id; \
25315 struct face *base_face = FACE_FROM_ID (f, face_id); \
25316 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
25317 struct composition *cmp = composition_table[cmp_id]; \
25319 struct glyph_string *first_s = NULL; \
25322 SAFE_NALLOCA (char2b, 1, cmp->glyph_len); \
25324 /* Make glyph_strings for each glyph sequence that is drawable by \
25325 the same face, and append them to HEAD/TAIL. */ \
25326 for (n = 0; n < cmp->glyph_len;) \
25328 s = alloca (sizeof *s); \
25329 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25330 append_glyph_string (&(HEAD), &(TAIL), s); \
25336 n = fill_composite_glyph_string (s, base_face, overlaps); \
25344 /* Add a glyph string for a glyph-string sequence to the list of strings
25345 between HEAD and TAIL. */
25347 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25351 Lisp_Object gstring; \
25353 face_id = (row)->glyphs[area][START].face_id; \
25354 gstring = (composition_gstring_from_id \
25355 ((row)->glyphs[area][START].u.cmp.id)); \
25356 s = alloca (sizeof *s); \
25357 SAFE_NALLOCA (char2b, 1, LGSTRING_GLYPH_LEN (gstring)); \
25358 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25359 append_glyph_string (&(HEAD), &(TAIL), s); \
25361 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
25365 /* Add a glyph string for a sequence of glyphless character's glyphs
25366 to the list of strings between HEAD and TAIL. The meanings of
25367 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
25369 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25374 face_id = (row)->glyphs[area][START].face_id; \
25376 s = alloca (sizeof *s); \
25377 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25378 append_glyph_string (&HEAD, &TAIL, s); \
25380 START = fill_glyphless_glyph_string (s, face_id, START, END, \
25386 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
25387 of AREA of glyph row ROW on window W between indices START and END.
25388 HL overrides the face for drawing glyph strings, e.g. it is
25389 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
25390 x-positions of the drawing area.
25392 This is an ugly monster macro construct because we must use alloca
25393 to allocate glyph strings (because draw_glyphs can be called
25394 asynchronously). */
25396 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25399 HEAD = TAIL = NULL; \
25400 while (START < END) \
25402 struct glyph *first_glyph = (row)->glyphs[area] + START; \
25403 switch (first_glyph->type) \
25406 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
25410 case COMPOSITE_GLYPH: \
25411 if (first_glyph->u.cmp.automatic) \
25412 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
25415 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
25419 case STRETCH_GLYPH: \
25420 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
25424 case IMAGE_GLYPH: \
25425 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
25429 #define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25430 case XWIDGET_GLYPH: \
25431 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
25435 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
25436 case GLYPHLESS_GLYPH: \
25437 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
25447 set_glyph_string_background_width (s, START, LAST_X); \
25454 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25455 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25456 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25457 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
25460 /* Draw glyphs between START and END in AREA of ROW on window W,
25461 starting at x-position X. X is relative to AREA in W. HL is a
25462 face-override with the following meaning:
25464 DRAW_NORMAL_TEXT draw normally
25465 DRAW_CURSOR draw in cursor face
25466 DRAW_MOUSE_FACE draw in mouse face.
25467 DRAW_INVERSE_VIDEO draw in mode line face
25468 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
25469 DRAW_IMAGE_RAISED draw an image with a raised relief around it
25471 If OVERLAPS is non-zero, draw only the foreground of characters and
25472 clip to the physical height of ROW. Non-zero value also defines
25473 the overlapping part to be drawn:
25475 OVERLAPS_PRED overlap with preceding rows
25476 OVERLAPS_SUCC overlap with succeeding rows
25477 OVERLAPS_BOTH overlap with both preceding/succeeding rows
25478 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
25480 Value is the x-position reached, relative to AREA of W. */
25483 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
25484 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
25485 enum draw_glyphs_face hl
, int overlaps
)
25487 struct glyph_string
*head
, *tail
;
25488 struct glyph_string
*s
;
25489 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
25490 int i
, j
, x_reached
, last_x
, area_left
= 0;
25491 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25494 ALLOCATE_HDC (hdc
, f
);
25496 /* Let's rather be paranoid than getting a SEGV. */
25497 end
= min (end
, row
->used
[area
]);
25498 start
= clip_to_bounds (0, start
, end
);
25500 /* Translate X to frame coordinates. Set last_x to the right
25501 end of the drawing area. */
25502 if (row
->full_width_p
)
25504 /* X is relative to the left edge of W, without scroll bars
25506 area_left
= WINDOW_LEFT_EDGE_X (w
);
25507 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
25508 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
25512 area_left
= window_box_left (w
, area
);
25513 last_x
= area_left
+ window_box_width (w
, area
);
25517 /* Build a doubly-linked list of glyph_string structures between
25518 head and tail from what we have to draw. Note that the macro
25519 BUILD_GLYPH_STRINGS will modify its start parameter. That's
25520 the reason we use a separate variable `i'. */
25523 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
25525 x_reached
= tail
->x
+ tail
->background_width
;
25529 /* If there are any glyphs with lbearing < 0 or rbearing > width in
25530 the row, redraw some glyphs in front or following the glyph
25531 strings built above. */
25532 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
25534 struct glyph_string
*h
, *t
;
25535 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25536 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
25537 bool check_mouse_face
= false;
25540 /* If mouse highlighting is on, we may need to draw adjacent
25541 glyphs using mouse-face highlighting. */
25542 if (area
== TEXT_AREA
&& row
->mouse_face_p
25543 && hlinfo
->mouse_face_beg_row
>= 0
25544 && hlinfo
->mouse_face_end_row
>= 0)
25546 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
25548 if (row_vpos
>= hlinfo
->mouse_face_beg_row
25549 && row_vpos
<= hlinfo
->mouse_face_end_row
)
25551 check_mouse_face
= true;
25552 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
25553 ? hlinfo
->mouse_face_beg_col
: 0;
25554 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
25555 ? hlinfo
->mouse_face_end_col
25556 : row
->used
[TEXT_AREA
];
25560 /* Compute overhangs for all glyph strings. */
25561 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
25562 for (s
= head
; s
; s
= s
->next
)
25563 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
25565 /* Prepend glyph strings for glyphs in front of the first glyph
25566 string that are overwritten because of the first glyph
25567 string's left overhang. The background of all strings
25568 prepended must be drawn because the first glyph string
25570 i
= left_overwritten (head
);
25573 enum draw_glyphs_face overlap_hl
;
25575 /* If this row contains mouse highlighting, attempt to draw
25576 the overlapped glyphs with the correct highlight. This
25577 code fails if the overlap encompasses more than one glyph
25578 and mouse-highlight spans only some of these glyphs.
25579 However, making it work perfectly involves a lot more
25580 code, and I don't know if the pathological case occurs in
25581 practice, so we'll stick to this for now. --- cyd */
25582 if (check_mouse_face
25583 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25584 overlap_hl
= DRAW_MOUSE_FACE
;
25586 overlap_hl
= DRAW_NORMAL_TEXT
;
25588 if (hl
!= overlap_hl
)
25591 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
25592 overlap_hl
, dummy_x
, last_x
);
25594 compute_overhangs_and_x (t
, head
->x
, true);
25595 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25596 if (clip_head
== NULL
)
25600 /* Prepend glyph strings for glyphs in front of the first glyph
25601 string that overwrite that glyph string because of their
25602 right overhang. For these strings, only the foreground must
25603 be drawn, because it draws over the glyph string at `head'.
25604 The background must not be drawn because this would overwrite
25605 right overhangs of preceding glyphs for which no glyph
25607 i
= left_overwriting (head
);
25610 enum draw_glyphs_face overlap_hl
;
25612 if (check_mouse_face
25613 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25614 overlap_hl
= DRAW_MOUSE_FACE
;
25616 overlap_hl
= DRAW_NORMAL_TEXT
;
25618 if (hl
== overlap_hl
|| clip_head
== NULL
)
25620 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
25621 overlap_hl
, dummy_x
, last_x
);
25622 for (s
= h
; s
; s
= s
->next
)
25623 s
->background_filled_p
= true;
25624 compute_overhangs_and_x (t
, head
->x
, true);
25625 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25628 /* Append glyphs strings for glyphs following the last glyph
25629 string tail that are overwritten by tail. The background of
25630 these strings has to be drawn because tail's foreground draws
25632 i
= right_overwritten (tail
);
25635 enum draw_glyphs_face overlap_hl
;
25637 if (check_mouse_face
25638 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25639 overlap_hl
= DRAW_MOUSE_FACE
;
25641 overlap_hl
= DRAW_NORMAL_TEXT
;
25643 if (hl
!= overlap_hl
)
25645 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25646 overlap_hl
, x
, last_x
);
25647 /* Because BUILD_GLYPH_STRINGS updates the first argument,
25648 we don't have `end = i;' here. */
25649 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25650 append_glyph_string_lists (&head
, &tail
, h
, t
);
25651 if (clip_tail
== NULL
)
25655 /* Append glyph strings for glyphs following the last glyph
25656 string tail that overwrite tail. The foreground of such
25657 glyphs has to be drawn because it writes into the background
25658 of tail. The background must not be drawn because it could
25659 paint over the foreground of following glyphs. */
25660 i
= right_overwriting (tail
);
25663 enum draw_glyphs_face overlap_hl
;
25664 if (check_mouse_face
25665 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25666 overlap_hl
= DRAW_MOUSE_FACE
;
25668 overlap_hl
= DRAW_NORMAL_TEXT
;
25670 if (hl
== overlap_hl
|| clip_tail
== NULL
)
25672 i
++; /* We must include the Ith glyph. */
25673 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25674 overlap_hl
, x
, last_x
);
25675 for (s
= h
; s
; s
= s
->next
)
25676 s
->background_filled_p
= true;
25677 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25678 append_glyph_string_lists (&head
, &tail
, h
, t
);
25680 if (clip_head
|| clip_tail
)
25681 for (s
= head
; s
; s
= s
->next
)
25683 s
->clip_head
= clip_head
;
25684 s
->clip_tail
= clip_tail
;
25688 /* Draw all strings. */
25689 for (s
= head
; s
; s
= s
->next
)
25690 FRAME_RIF (f
)->draw_glyph_string (s
);
25693 /* When focus a sole frame and move horizontally, this clears on_p
25694 causing a failure to erase prev cursor position. */
25695 if (area
== TEXT_AREA
25696 && !row
->full_width_p
25697 /* When drawing overlapping rows, only the glyph strings'
25698 foreground is drawn, which doesn't erase a cursor
25702 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
25703 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
25704 : (tail
? tail
->x
+ tail
->background_width
: x
));
25708 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
25709 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
25713 /* Value is the x-position up to which drawn, relative to AREA of W.
25714 This doesn't include parts drawn because of overhangs. */
25715 if (row
->full_width_p
)
25716 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
25718 x_reached
-= area_left
;
25720 RELEASE_HDC (hdc
, f
);
25726 /* Expand row matrix if too narrow. Don't expand if area
25729 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
25731 if (!it->f->fonts_changed \
25732 && (it->glyph_row->glyphs[area] \
25733 < it->glyph_row->glyphs[area + 1])) \
25735 it->w->ncols_scale_factor++; \
25736 it->f->fonts_changed = true; \
25740 /* Store one glyph for IT->char_to_display in IT->glyph_row.
25741 Called from x_produce_glyphs when IT->glyph_row is non-null. */
25744 append_glyph (struct it
*it
)
25746 struct glyph
*glyph
;
25747 enum glyph_row_area area
= it
->area
;
25749 eassert (it
->glyph_row
);
25750 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
25752 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25753 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25755 /* If the glyph row is reversed, we need to prepend the glyph
25756 rather than append it. */
25757 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25761 /* Make room for the additional glyph. */
25762 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25764 glyph
= it
->glyph_row
->glyphs
[area
];
25766 glyph
->charpos
= CHARPOS (it
->position
);
25767 glyph
->object
= it
->object
;
25768 if (it
->pixel_width
> 0)
25770 glyph
->pixel_width
= it
->pixel_width
;
25771 glyph
->padding_p
= false;
25775 /* Assure at least 1-pixel width. Otherwise, cursor can't
25776 be displayed correctly. */
25777 glyph
->pixel_width
= 1;
25778 glyph
->padding_p
= true;
25780 glyph
->ascent
= it
->ascent
;
25781 glyph
->descent
= it
->descent
;
25782 glyph
->voffset
= it
->voffset
;
25783 glyph
->type
= CHAR_GLYPH
;
25784 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25785 glyph
->multibyte_p
= it
->multibyte_p
;
25786 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25788 /* In R2L rows, the left and the right box edges need to be
25789 drawn in reverse direction. */
25790 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25791 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25795 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25796 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25798 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25799 || it
->phys_descent
> it
->descent
);
25800 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
25801 glyph
->face_id
= it
->face_id
;
25802 glyph
->u
.ch
= it
->char_to_display
;
25803 glyph
->slice
.img
= null_glyph_slice
;
25804 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25807 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25808 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25809 glyph
->bidi_type
= it
->bidi_it
.type
;
25813 glyph
->resolved_level
= 0;
25814 glyph
->bidi_type
= UNKNOWN_BT
;
25816 ++it
->glyph_row
->used
[area
];
25819 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25822 /* Store one glyph for the composition IT->cmp_it.id in
25823 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
25827 append_composite_glyph (struct it
*it
)
25829 struct glyph
*glyph
;
25830 enum glyph_row_area area
= it
->area
;
25832 eassert (it
->glyph_row
);
25834 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25835 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25837 /* If the glyph row is reversed, we need to prepend the glyph
25838 rather than append it. */
25839 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
25843 /* Make room for the new glyph. */
25844 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
25846 glyph
= it
->glyph_row
->glyphs
[it
->area
];
25848 glyph
->charpos
= it
->cmp_it
.charpos
;
25849 glyph
->object
= it
->object
;
25850 glyph
->pixel_width
= it
->pixel_width
;
25851 glyph
->ascent
= it
->ascent
;
25852 glyph
->descent
= it
->descent
;
25853 glyph
->voffset
= it
->voffset
;
25854 glyph
->type
= COMPOSITE_GLYPH
;
25855 if (it
->cmp_it
.ch
< 0)
25857 glyph
->u
.cmp
.automatic
= false;
25858 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25859 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
25863 glyph
->u
.cmp
.automatic
= true;
25864 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25865 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
25866 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
25868 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25869 glyph
->multibyte_p
= it
->multibyte_p
;
25870 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25872 /* In R2L rows, the left and the right box edges need to be
25873 drawn in reverse direction. */
25874 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25875 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25879 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25880 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25882 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25883 || it
->phys_descent
> it
->descent
);
25884 glyph
->padding_p
= false;
25885 glyph
->glyph_not_available_p
= false;
25886 glyph
->face_id
= it
->face_id
;
25887 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25890 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25891 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25892 glyph
->bidi_type
= it
->bidi_it
.type
;
25894 ++it
->glyph_row
->used
[area
];
25897 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25901 /* Change IT->ascent and IT->height according to the setting of
25905 take_vertical_position_into_account (struct it
*it
)
25909 if (it
->voffset
< 0)
25910 /* Increase the ascent so that we can display the text higher
25912 it
->ascent
-= it
->voffset
;
25914 /* Increase the descent so that we can display the text lower
25916 it
->descent
+= it
->voffset
;
25921 /* Produce glyphs/get display metrics for the image IT is loaded with.
25922 See the description of struct display_iterator in dispextern.h for
25923 an overview of struct display_iterator. */
25926 produce_image_glyph (struct it
*it
)
25930 int glyph_ascent
, crop
;
25931 struct glyph_slice slice
;
25933 eassert (it
->what
== IT_IMAGE
);
25935 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25937 /* Make sure X resources of the face is loaded. */
25938 prepare_face_for_display (it
->f
, face
);
25940 if (it
->image_id
< 0)
25942 /* Fringe bitmap. */
25943 it
->ascent
= it
->phys_ascent
= 0;
25944 it
->descent
= it
->phys_descent
= 0;
25945 it
->pixel_width
= 0;
25950 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
25952 /* Make sure X resources of the image is loaded. */
25953 prepare_image_for_display (it
->f
, img
);
25955 slice
.x
= slice
.y
= 0;
25956 slice
.width
= img
->width
;
25957 slice
.height
= img
->height
;
25959 if (INTEGERP (it
->slice
.x
))
25960 slice
.x
= XINT (it
->slice
.x
);
25961 else if (FLOATP (it
->slice
.x
))
25962 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
25964 if (INTEGERP (it
->slice
.y
))
25965 slice
.y
= XINT (it
->slice
.y
);
25966 else if (FLOATP (it
->slice
.y
))
25967 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
25969 if (INTEGERP (it
->slice
.width
))
25970 slice
.width
= XINT (it
->slice
.width
);
25971 else if (FLOATP (it
->slice
.width
))
25972 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
25974 if (INTEGERP (it
->slice
.height
))
25975 slice
.height
= XINT (it
->slice
.height
);
25976 else if (FLOATP (it
->slice
.height
))
25977 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
25979 if (slice
.x
>= img
->width
)
25980 slice
.x
= img
->width
;
25981 if (slice
.y
>= img
->height
)
25982 slice
.y
= img
->height
;
25983 if (slice
.x
+ slice
.width
>= img
->width
)
25984 slice
.width
= img
->width
- slice
.x
;
25985 if (slice
.y
+ slice
.height
> img
->height
)
25986 slice
.height
= img
->height
- slice
.y
;
25988 if (slice
.width
== 0 || slice
.height
== 0)
25991 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
25993 it
->descent
= slice
.height
- glyph_ascent
;
25995 it
->descent
+= img
->vmargin
;
25996 if (slice
.y
+ slice
.height
== img
->height
)
25997 it
->descent
+= img
->vmargin
;
25998 it
->phys_descent
= it
->descent
;
26000 it
->pixel_width
= slice
.width
;
26002 it
->pixel_width
+= img
->hmargin
;
26003 if (slice
.x
+ slice
.width
== img
->width
)
26004 it
->pixel_width
+= img
->hmargin
;
26006 /* It's quite possible for images to have an ascent greater than
26007 their height, so don't get confused in that case. */
26008 if (it
->descent
< 0)
26013 if (face
->box
!= FACE_NO_BOX
)
26015 if (face
->box_line_width
> 0)
26018 it
->ascent
+= face
->box_line_width
;
26019 if (slice
.y
+ slice
.height
== img
->height
)
26020 it
->descent
+= face
->box_line_width
;
26023 if (it
->start_of_box_run_p
&& slice
.x
== 0)
26024 it
->pixel_width
+= eabs (face
->box_line_width
);
26025 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
26026 it
->pixel_width
+= eabs (face
->box_line_width
);
26029 take_vertical_position_into_account (it
);
26031 /* Automatically crop wide image glyphs at right edge so we can
26032 draw the cursor on same display row. */
26033 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
26034 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
26036 it
->pixel_width
-= crop
;
26037 slice
.width
-= crop
;
26042 struct glyph
*glyph
;
26043 enum glyph_row_area area
= it
->area
;
26045 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26046 if (it
->glyph_row
->reversed_p
)
26050 /* Make room for the new glyph. */
26051 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
26053 glyph
= it
->glyph_row
->glyphs
[it
->area
];
26055 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26057 glyph
->charpos
= CHARPOS (it
->position
);
26058 glyph
->object
= it
->object
;
26059 glyph
->pixel_width
= it
->pixel_width
;
26060 glyph
->ascent
= glyph_ascent
;
26061 glyph
->descent
= it
->descent
;
26062 glyph
->voffset
= it
->voffset
;
26063 glyph
->type
= IMAGE_GLYPH
;
26064 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26065 glyph
->multibyte_p
= it
->multibyte_p
;
26066 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26068 /* In R2L rows, the left and the right box edges need to be
26069 drawn in reverse direction. */
26070 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26071 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26075 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26076 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26078 glyph
->overlaps_vertically_p
= false;
26079 glyph
->padding_p
= false;
26080 glyph
->glyph_not_available_p
= false;
26081 glyph
->face_id
= it
->face_id
;
26082 glyph
->u
.img_id
= img
->id
;
26083 glyph
->slice
.img
= slice
;
26084 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26087 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26088 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26089 glyph
->bidi_type
= it
->bidi_it
.type
;
26091 ++it
->glyph_row
->used
[area
];
26094 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26099 produce_xwidget_glyph (struct it
*it
)
26101 #ifdef HAVE_XWIDGETS
26102 struct xwidget
*xw
;
26103 int glyph_ascent
, crop
;
26104 eassert (it
->what
== IT_XWIDGET
);
26106 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26108 /* Make sure X resources of the face is loaded. */
26109 prepare_face_for_display (it
->f
, face
);
26112 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
26113 it
->descent
= xw
->height
/2;
26114 it
->phys_descent
= it
->descent
;
26115 it
->pixel_width
= xw
->width
;
26116 /* It's quite possible for images to have an ascent greater than
26117 their height, so don't get confused in that case. */
26118 if (it
->descent
< 0)
26123 if (face
->box
!= FACE_NO_BOX
)
26125 if (face
->box_line_width
> 0)
26127 it
->ascent
+= face
->box_line_width
;
26128 it
->descent
+= face
->box_line_width
;
26131 if (it
->start_of_box_run_p
)
26132 it
->pixel_width
+= eabs (face
->box_line_width
);
26133 it
->pixel_width
+= eabs (face
->box_line_width
);
26136 take_vertical_position_into_account (it
);
26138 /* Automatically crop wide image glyphs at right edge so we can
26139 draw the cursor on same display row. */
26140 crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
);
26141 if (crop
> 0 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
26142 it
->pixel_width
-= crop
;
26146 enum glyph_row_area area
= it
->area
;
26147 struct glyph
*glyph
26148 = it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26150 if (it
->glyph_row
->reversed_p
)
26154 /* Make room for the new glyph. */
26155 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
26157 glyph
= it
->glyph_row
->glyphs
[it
->area
];
26159 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26161 glyph
->charpos
= CHARPOS (it
->position
);
26162 glyph
->object
= it
->object
;
26163 glyph
->pixel_width
= it
->pixel_width
;
26164 glyph
->ascent
= glyph_ascent
;
26165 glyph
->descent
= it
->descent
;
26166 glyph
->voffset
= it
->voffset
;
26167 glyph
->type
= XWIDGET_GLYPH
;
26168 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26169 glyph
->multibyte_p
= it
->multibyte_p
;
26170 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26172 /* In R2L rows, the left and the right box edges need to be
26173 drawn in reverse direction. */
26174 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26175 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26179 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26180 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26182 glyph
->overlaps_vertically_p
= 0;
26183 glyph
->padding_p
= 0;
26184 glyph
->glyph_not_available_p
= 0;
26185 glyph
->face_id
= it
->face_id
;
26186 glyph
->u
.xwidget
= it
->xwidget
;
26187 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26190 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26191 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26192 glyph
->bidi_type
= it
->bidi_it
.type
;
26194 ++it
->glyph_row
->used
[area
];
26197 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26202 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
26203 of the glyph, WIDTH and HEIGHT are the width and height of the
26204 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
26207 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
26208 int width
, int height
, int ascent
)
26210 struct glyph
*glyph
;
26211 enum glyph_row_area area
= it
->area
;
26213 eassert (ascent
>= 0 && ascent
<= height
);
26215 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26216 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26218 /* If the glyph row is reversed, we need to prepend the glyph
26219 rather than append it. */
26220 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26224 /* Make room for the additional glyph. */
26225 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26227 glyph
= it
->glyph_row
->glyphs
[area
];
26229 /* Decrease the width of the first glyph of the row that
26230 begins before first_visible_x (e.g., due to hscroll).
26231 This is so the overall width of the row becomes smaller
26232 by the scroll amount, and the stretch glyph appended by
26233 extend_face_to_end_of_line will be wider, to shift the
26234 row glyphs to the right. (In L2R rows, the corresponding
26235 left-shift effect is accomplished by setting row->x to a
26236 negative value, which won't work with R2L rows.)
26238 This must leave us with a positive value of WIDTH, since
26239 otherwise the call to move_it_in_display_line_to at the
26240 beginning of display_line would have got past the entire
26241 first glyph, and then it->current_x would have been
26242 greater or equal to it->first_visible_x. */
26243 if (it
->current_x
< it
->first_visible_x
)
26244 width
-= it
->first_visible_x
- it
->current_x
;
26245 eassert (width
> 0);
26247 glyph
->charpos
= CHARPOS (it
->position
);
26248 glyph
->object
= object
;
26249 glyph
->pixel_width
= width
;
26250 glyph
->ascent
= ascent
;
26251 glyph
->descent
= height
- ascent
;
26252 glyph
->voffset
= it
->voffset
;
26253 glyph
->type
= STRETCH_GLYPH
;
26254 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26255 glyph
->multibyte_p
= it
->multibyte_p
;
26256 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26258 /* In R2L rows, the left and the right box edges need to be
26259 drawn in reverse direction. */
26260 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26261 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26265 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26266 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26268 glyph
->overlaps_vertically_p
= false;
26269 glyph
->padding_p
= false;
26270 glyph
->glyph_not_available_p
= false;
26271 glyph
->face_id
= it
->face_id
;
26272 glyph
->u
.stretch
.ascent
= ascent
;
26273 glyph
->u
.stretch
.height
= height
;
26274 glyph
->slice
.img
= null_glyph_slice
;
26275 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26278 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26279 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26280 glyph
->bidi_type
= it
->bidi_it
.type
;
26284 glyph
->resolved_level
= 0;
26285 glyph
->bidi_type
= UNKNOWN_BT
;
26287 ++it
->glyph_row
->used
[area
];
26290 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26293 #endif /* HAVE_WINDOW_SYSTEM */
26295 /* Produce a stretch glyph for iterator IT. IT->object is the value
26296 of the glyph property displayed. The value must be a list
26297 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
26300 1. `:width WIDTH' specifies that the space should be WIDTH *
26301 canonical char width wide. WIDTH may be an integer or floating
26304 2. `:relative-width FACTOR' specifies that the width of the stretch
26305 should be computed from the width of the first character having the
26306 `glyph' property, and should be FACTOR times that width.
26308 3. `:align-to HPOS' specifies that the space should be wide enough
26309 to reach HPOS, a value in canonical character units.
26311 Exactly one of the above pairs must be present.
26313 4. `:height HEIGHT' specifies that the height of the stretch produced
26314 should be HEIGHT, measured in canonical character units.
26316 5. `:relative-height FACTOR' specifies that the height of the
26317 stretch should be FACTOR times the height of the characters having
26318 the glyph property.
26320 Either none or exactly one of 4 or 5 must be present.
26322 6. `:ascent ASCENT' specifies that ASCENT percent of the height
26323 of the stretch should be used for the ascent of the stretch.
26324 ASCENT must be in the range 0 <= ASCENT <= 100. */
26327 produce_stretch_glyph (struct it
*it
)
26329 /* (space :width WIDTH :height HEIGHT ...) */
26330 Lisp_Object prop
, plist
;
26331 int width
= 0, height
= 0, align_to
= -1;
26332 bool zero_width_ok_p
= false;
26334 struct font
*font
= NULL
;
26336 #ifdef HAVE_WINDOW_SYSTEM
26338 bool zero_height_ok_p
= false;
26340 if (FRAME_WINDOW_P (it
->f
))
26342 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26343 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26344 prepare_face_for_display (it
->f
, face
);
26348 /* List should start with `space'. */
26349 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
26350 plist
= XCDR (it
->object
);
26352 /* Compute the width of the stretch. */
26353 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
26354 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true, 0))
26356 /* Absolute width `:width WIDTH' specified and valid. */
26357 zero_width_ok_p
= true;
26360 else if (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0)
26362 /* Relative width `:relative-width FACTOR' specified and valid.
26363 Compute the width of the characters having the `glyph'
26366 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
26369 if (it
->multibyte_p
)
26370 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
26373 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
26374 if (! ASCII_CHAR_P (it2
.c
))
26375 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
26378 it2
.glyph_row
= NULL
;
26379 it2
.what
= IT_CHARACTER
;
26380 PRODUCE_GLYPHS (&it2
);
26381 width
= NUMVAL (prop
) * it2
.pixel_width
;
26383 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
26384 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true,
26387 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
26388 align_to
= (align_to
< 0
26390 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
26391 else if (align_to
< 0)
26392 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
26393 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
26394 zero_width_ok_p
= true;
26397 /* Nothing specified -> width defaults to canonical char width. */
26398 width
= FRAME_COLUMN_WIDTH (it
->f
);
26400 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
26403 #ifdef HAVE_WINDOW_SYSTEM
26404 /* Compute height. */
26405 if (FRAME_WINDOW_P (it
->f
))
26407 int default_height
= normal_char_height (font
, ' ');
26409 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
26410 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
26413 zero_height_ok_p
= true;
26415 else if (prop
= Fplist_get (plist
, QCrelative_height
),
26417 height
= default_height
* NUMVAL (prop
);
26419 height
= default_height
;
26421 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
26424 /* Compute percentage of height used for ascent. If
26425 `:ascent ASCENT' is present and valid, use that. Otherwise,
26426 derive the ascent from the font in use. */
26427 if (prop
= Fplist_get (plist
, QCascent
),
26428 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
26429 ascent
= height
* NUMVAL (prop
) / 100.0;
26430 else if (!NILP (prop
)
26431 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
26432 ascent
= min (max (0, (int)tem
), height
);
26434 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
26437 #endif /* HAVE_WINDOW_SYSTEM */
26440 if (width
> 0 && it
->line_wrap
!= TRUNCATE
26441 && it
->current_x
+ width
> it
->last_visible_x
)
26443 width
= it
->last_visible_x
- it
->current_x
;
26444 #ifdef HAVE_WINDOW_SYSTEM
26445 /* Subtract one more pixel from the stretch width, but only on
26446 GUI frames, since on a TTY each glyph is one "pixel" wide. */
26447 width
-= FRAME_WINDOW_P (it
->f
);
26451 if (width
> 0 && height
> 0 && it
->glyph_row
)
26453 Lisp_Object o_object
= it
->object
;
26454 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
26457 if (!STRINGP (object
))
26458 object
= it
->w
->contents
;
26459 #ifdef HAVE_WINDOW_SYSTEM
26460 if (FRAME_WINDOW_P (it
->f
))
26461 append_stretch_glyph (it
, object
, width
, height
, ascent
);
26465 it
->object
= object
;
26466 it
->char_to_display
= ' ';
26467 it
->pixel_width
= it
->len
= 1;
26469 tty_append_glyph (it
);
26470 it
->object
= o_object
;
26474 it
->pixel_width
= width
;
26475 #ifdef HAVE_WINDOW_SYSTEM
26476 if (FRAME_WINDOW_P (it
->f
))
26478 it
->ascent
= it
->phys_ascent
= ascent
;
26479 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
26480 it
->nglyphs
= width
> 0 && height
> 0;
26481 take_vertical_position_into_account (it
);
26485 it
->nglyphs
= width
;
26488 /* Get information about special display element WHAT in an
26489 environment described by IT. WHAT is one of IT_TRUNCATION or
26490 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
26491 non-null glyph_row member. This function ensures that fields like
26492 face_id, c, len of IT are left untouched. */
26495 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
26502 temp_it
.object
= Qnil
;
26503 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
26505 if (what
== IT_CONTINUATION
)
26507 /* Continuation glyph. For R2L lines, we mirror it by hand. */
26508 if (it
->bidi_it
.paragraph_dir
== R2L
)
26509 SET_GLYPH_FROM_CHAR (glyph
, '/');
26511 SET_GLYPH_FROM_CHAR (glyph
, '\\');
26513 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
26515 /* FIXME: Should we mirror GC for R2L lines? */
26516 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
26517 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
26520 else if (what
== IT_TRUNCATION
)
26522 /* Truncation glyph. */
26523 SET_GLYPH_FROM_CHAR (glyph
, '$');
26525 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
26527 /* FIXME: Should we mirror GC for R2L lines? */
26528 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
26529 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
26535 #ifdef HAVE_WINDOW_SYSTEM
26536 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
26537 is turned off, we precede the truncation/continuation glyphs by a
26538 stretch glyph whose width is computed such that these special
26539 glyphs are aligned at the window margin, even when very different
26540 fonts are used in different glyph rows. */
26541 if (FRAME_WINDOW_P (temp_it
.f
)
26542 /* init_iterator calls this with it->glyph_row == NULL, and it
26543 wants only the pixel width of the truncation/continuation
26545 && temp_it
.glyph_row
26546 /* insert_left_trunc_glyphs calls us at the beginning of the
26547 row, and it has its own calculation of the stretch glyph
26549 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
26550 && (temp_it
.glyph_row
->reversed_p
26551 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
26552 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
26554 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
26556 if (stretch_width
> 0)
26558 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
26559 struct font
*font
=
26560 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
26561 int stretch_ascent
=
26562 (((temp_it
.ascent
+ temp_it
.descent
)
26563 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
26565 append_stretch_glyph (&temp_it
, Qnil
, stretch_width
,
26566 temp_it
.ascent
+ temp_it
.descent
,
26573 temp_it
.what
= IT_CHARACTER
;
26574 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
26575 temp_it
.face_id
= GLYPH_FACE (glyph
);
26576 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
26578 PRODUCE_GLYPHS (&temp_it
);
26579 it
->pixel_width
= temp_it
.pixel_width
;
26580 it
->nglyphs
= temp_it
.nglyphs
;
26583 #ifdef HAVE_WINDOW_SYSTEM
26585 /* Calculate line-height and line-spacing properties.
26586 An integer value specifies explicit pixel value.
26587 A float value specifies relative value to current face height.
26588 A cons (float . face-name) specifies relative value to
26589 height of specified face font.
26591 Returns height in pixels, or nil. */
26594 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
26595 int boff
, bool override
)
26597 Lisp_Object face_name
= Qnil
;
26598 int ascent
, descent
, height
;
26600 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
26605 face_name
= XCAR (val
);
26607 if (!NUMBERP (val
))
26608 val
= make_number (1);
26609 if (NILP (face_name
))
26611 height
= it
->ascent
+ it
->descent
;
26616 if (NILP (face_name
))
26618 font
= FRAME_FONT (it
->f
);
26619 boff
= FRAME_BASELINE_OFFSET (it
->f
);
26621 else if (EQ (face_name
, Qt
))
26630 face_id
= lookup_named_face (it
->f
, face_name
, false);
26632 return make_number (-1);
26634 face
= FACE_FROM_ID (it
->f
, face_id
);
26637 return make_number (-1);
26638 boff
= font
->baseline_offset
;
26639 if (font
->vertical_centering
)
26640 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26643 normal_char_ascent_descent (font
, -1, &ascent
, &descent
);
26647 it
->override_ascent
= ascent
;
26648 it
->override_descent
= descent
;
26649 it
->override_boff
= boff
;
26652 height
= ascent
+ descent
;
26656 height
= (int)(XFLOAT_DATA (val
) * height
);
26657 else if (INTEGERP (val
))
26658 height
*= XINT (val
);
26660 return make_number (height
);
26664 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
26665 is a face ID to be used for the glyph. FOR_NO_FONT is true if
26666 and only if this is for a character for which no font was found.
26668 If the display method (it->glyphless_method) is
26669 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
26670 length of the acronym or the hexadecimal string, UPPER_XOFF and
26671 UPPER_YOFF are pixel offsets for the upper part of the string,
26672 LOWER_XOFF and LOWER_YOFF are for the lower part.
26674 For the other display methods, LEN through LOWER_YOFF are zero. */
26677 append_glyphless_glyph (struct it
*it
, int face_id
, bool for_no_font
, int len
,
26678 short upper_xoff
, short upper_yoff
,
26679 short lower_xoff
, short lower_yoff
)
26681 struct glyph
*glyph
;
26682 enum glyph_row_area area
= it
->area
;
26684 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26685 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26687 /* If the glyph row is reversed, we need to prepend the glyph
26688 rather than append it. */
26689 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26693 /* Make room for the additional glyph. */
26694 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26696 glyph
= it
->glyph_row
->glyphs
[area
];
26698 glyph
->charpos
= CHARPOS (it
->position
);
26699 glyph
->object
= it
->object
;
26700 glyph
->pixel_width
= it
->pixel_width
;
26701 glyph
->ascent
= it
->ascent
;
26702 glyph
->descent
= it
->descent
;
26703 glyph
->voffset
= it
->voffset
;
26704 glyph
->type
= GLYPHLESS_GLYPH
;
26705 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
26706 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
26707 glyph
->u
.glyphless
.len
= len
;
26708 glyph
->u
.glyphless
.ch
= it
->c
;
26709 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
26710 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
26711 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
26712 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
26713 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26714 glyph
->multibyte_p
= it
->multibyte_p
;
26715 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26717 /* In R2L rows, the left and the right box edges need to be
26718 drawn in reverse direction. */
26719 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26720 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26724 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26725 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26727 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
26728 || it
->phys_descent
> it
->descent
);
26729 glyph
->padding_p
= false;
26730 glyph
->glyph_not_available_p
= false;
26731 glyph
->face_id
= face_id
;
26732 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26735 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26736 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26737 glyph
->bidi_type
= it
->bidi_it
.type
;
26739 ++it
->glyph_row
->used
[area
];
26742 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26746 /* Produce a glyph for a glyphless character for iterator IT.
26747 IT->glyphless_method specifies which method to use for displaying
26748 the character. See the description of enum
26749 glyphless_display_method in dispextern.h for the detail.
26751 FOR_NO_FONT is true if and only if this is for a character for
26752 which no font was found. ACRONYM, if non-nil, is an acronym string
26753 for the character. */
26756 produce_glyphless_glyph (struct it
*it
, bool for_no_font
, Lisp_Object acronym
)
26761 int base_width
, base_height
, width
, height
;
26762 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
26765 /* Get the metrics of the base font. We always refer to the current
26767 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
26768 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26769 normal_char_ascent_descent (font
, -1, &it
->ascent
, &it
->descent
);
26770 it
->ascent
+= font
->baseline_offset
;
26771 it
->descent
-= font
->baseline_offset
;
26772 base_height
= it
->ascent
+ it
->descent
;
26773 base_width
= font
->average_width
;
26775 face_id
= merge_glyphless_glyph_face (it
);
26777 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
26779 it
->pixel_width
= THIN_SPACE_WIDTH
;
26781 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26783 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
26785 width
= CHAR_WIDTH (it
->c
);
26788 else if (width
> 4)
26790 it
->pixel_width
= base_width
* width
;
26792 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26798 unsigned int code
[6];
26800 int ascent
, descent
;
26801 struct font_metrics metrics_upper
, metrics_lower
;
26803 face
= FACE_FROM_ID (it
->f
, face_id
);
26804 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26805 prepare_face_for_display (it
->f
, face
);
26807 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
26809 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
26810 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
26811 if (CONSP (acronym
))
26812 acronym
= XCAR (acronym
);
26813 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
26817 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
26818 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
+ 0u);
26821 for (len
= 0; str
[len
] && ASCII_CHAR_P (str
[len
]) && len
< 6; len
++)
26822 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
26823 upper_len
= (len
+ 1) / 2;
26824 font
->driver
->text_extents (font
, code
, upper_len
,
26826 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
26831 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
26832 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
26833 upper_xoff
= upper_yoff
= 2; /* the typical case */
26834 if (base_width
>= width
)
26836 /* Align the upper to the left, the lower to the right. */
26837 it
->pixel_width
= base_width
;
26838 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
26842 /* Center the shorter one. */
26843 it
->pixel_width
= width
;
26844 if (metrics_upper
.width
>= metrics_lower
.width
)
26845 lower_xoff
= (width
- metrics_lower
.width
) / 2;
26848 /* FIXME: This code doesn't look right. It formerly was
26849 missing the "lower_xoff = 0;", which couldn't have
26850 been right since it left lower_xoff uninitialized. */
26852 upper_xoff
= (width
- metrics_upper
.width
) / 2;
26856 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
26857 top, bottom, and between upper and lower strings. */
26858 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
26859 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
26860 /* Center vertically.
26861 H:base_height, D:base_descent
26862 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
26864 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
26865 descent = D - H/2 + h/2;
26866 lower_yoff = descent - 2 - ld;
26867 upper_yoff = lower_yoff - la - 1 - ud; */
26868 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
26869 descent
= it
->descent
- (base_height
- height
) / 2;
26870 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
26871 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
26872 - metrics_upper
.descent
);
26873 /* Don't make the height shorter than the base height. */
26874 if (height
> base_height
)
26876 it
->ascent
= ascent
;
26877 it
->descent
= descent
;
26881 it
->phys_ascent
= it
->ascent
;
26882 it
->phys_descent
= it
->descent
;
26884 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
26885 upper_xoff
, upper_yoff
,
26886 lower_xoff
, lower_yoff
);
26888 take_vertical_position_into_account (it
);
26893 Produce glyphs/get display metrics for the display element IT is
26894 loaded with. See the description of struct it in dispextern.h
26895 for an overview of struct it. */
26898 x_produce_glyphs (struct it
*it
)
26900 int extra_line_spacing
= it
->extra_line_spacing
;
26902 it
->glyph_not_available_p
= false;
26904 if (it
->what
== IT_CHARACTER
)
26907 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26908 struct font
*font
= face
->font
;
26909 struct font_metrics
*pcm
= NULL
;
26910 int boff
; /* Baseline offset. */
26914 /* When no suitable font is found, display this character by
26915 the method specified in the first extra slot of
26916 Vglyphless_char_display. */
26917 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
26919 eassert (it
->what
== IT_GLYPHLESS
);
26920 produce_glyphless_glyph (it
, true,
26921 STRINGP (acronym
) ? acronym
: Qnil
);
26925 boff
= font
->baseline_offset
;
26926 if (font
->vertical_centering
)
26927 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26929 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
26933 if (it
->override_ascent
>= 0)
26935 it
->ascent
= it
->override_ascent
;
26936 it
->descent
= it
->override_descent
;
26937 boff
= it
->override_boff
;
26941 it
->ascent
= FONT_BASE (font
) + boff
;
26942 it
->descent
= FONT_DESCENT (font
) - boff
;
26945 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
26947 pcm
= get_per_char_metric (font
, &char2b
);
26948 if (pcm
->width
== 0
26949 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
26955 it
->phys_ascent
= pcm
->ascent
+ boff
;
26956 it
->phys_descent
= pcm
->descent
- boff
;
26957 it
->pixel_width
= pcm
->width
;
26958 /* Don't use font-global values for ascent and descent
26959 if they result in an exceedingly large line height. */
26960 if (it
->override_ascent
< 0)
26962 if (FONT_TOO_HIGH (font
))
26964 it
->ascent
= it
->phys_ascent
;
26965 it
->descent
= it
->phys_descent
;
26966 /* These limitations are enforced by an
26967 assertion near the end of this function. */
26968 if (it
->ascent
< 0)
26970 if (it
->descent
< 0)
26977 it
->glyph_not_available_p
= true;
26978 it
->phys_ascent
= it
->ascent
;
26979 it
->phys_descent
= it
->descent
;
26980 it
->pixel_width
= font
->space_width
;
26983 if (it
->constrain_row_ascent_descent_p
)
26985 if (it
->descent
> it
->max_descent
)
26987 it
->ascent
+= it
->descent
- it
->max_descent
;
26988 it
->descent
= it
->max_descent
;
26990 if (it
->ascent
> it
->max_ascent
)
26992 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
26993 it
->ascent
= it
->max_ascent
;
26995 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
26996 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
26997 extra_line_spacing
= 0;
27000 /* If this is a space inside a region of text with
27001 `space-width' property, change its width. */
27003 = it
->char_to_display
== ' ' && !NILP (it
->space_width
);
27005 it
->pixel_width
*= XFLOATINT (it
->space_width
);
27007 /* If face has a box, add the box thickness to the character
27008 height. If character has a box line to the left and/or
27009 right, add the box line width to the character's width. */
27010 if (face
->box
!= FACE_NO_BOX
)
27012 int thick
= face
->box_line_width
;
27016 it
->ascent
+= thick
;
27017 it
->descent
+= thick
;
27022 if (it
->start_of_box_run_p
)
27023 it
->pixel_width
+= thick
;
27024 if (it
->end_of_box_run_p
)
27025 it
->pixel_width
+= thick
;
27028 /* If face has an overline, add the height of the overline
27029 (1 pixel) and a 1 pixel margin to the character height. */
27030 if (face
->overline_p
)
27031 it
->ascent
+= overline_margin
;
27033 if (it
->constrain_row_ascent_descent_p
)
27035 if (it
->ascent
> it
->max_ascent
)
27036 it
->ascent
= it
->max_ascent
;
27037 if (it
->descent
> it
->max_descent
)
27038 it
->descent
= it
->max_descent
;
27041 take_vertical_position_into_account (it
);
27043 /* If we have to actually produce glyphs, do it. */
27048 /* Translate a space with a `space-width' property
27049 into a stretch glyph. */
27050 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
27051 / FONT_HEIGHT (font
));
27052 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
27053 it
->ascent
+ it
->descent
, ascent
);
27058 /* If characters with lbearing or rbearing are displayed
27059 in this line, record that fact in a flag of the
27060 glyph row. This is used to optimize X output code. */
27061 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
27062 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27064 if (! stretched_p
&& it
->pixel_width
== 0)
27065 /* We assure that all visible glyphs have at least 1-pixel
27067 it
->pixel_width
= 1;
27069 else if (it
->char_to_display
== '\n')
27071 /* A newline has no width, but we need the height of the
27072 line. But if previous part of the line sets a height,
27073 don't increase that height. */
27075 Lisp_Object height
;
27076 Lisp_Object total_height
= Qnil
;
27078 it
->override_ascent
= -1;
27079 it
->pixel_width
= 0;
27082 height
= get_it_property (it
, Qline_height
);
27083 /* Split (line-height total-height) list. */
27085 && CONSP (XCDR (height
))
27086 && NILP (XCDR (XCDR (height
))))
27088 total_height
= XCAR (XCDR (height
));
27089 height
= XCAR (height
);
27091 height
= calc_line_height_property (it
, height
, font
, boff
, true);
27093 if (it
->override_ascent
>= 0)
27095 it
->ascent
= it
->override_ascent
;
27096 it
->descent
= it
->override_descent
;
27097 boff
= it
->override_boff
;
27101 if (FONT_TOO_HIGH (font
))
27103 it
->ascent
= font
->pixel_size
+ boff
- 1;
27104 it
->descent
= -boff
+ 1;
27105 if (it
->descent
< 0)
27110 it
->ascent
= FONT_BASE (font
) + boff
;
27111 it
->descent
= FONT_DESCENT (font
) - boff
;
27115 if (EQ (height
, Qt
))
27117 if (it
->descent
> it
->max_descent
)
27119 it
->ascent
+= it
->descent
- it
->max_descent
;
27120 it
->descent
= it
->max_descent
;
27122 if (it
->ascent
> it
->max_ascent
)
27124 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
27125 it
->ascent
= it
->max_ascent
;
27127 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
27128 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
27129 it
->constrain_row_ascent_descent_p
= true;
27130 extra_line_spacing
= 0;
27134 Lisp_Object spacing
;
27136 it
->phys_ascent
= it
->ascent
;
27137 it
->phys_descent
= it
->descent
;
27139 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
27140 && face
->box
!= FACE_NO_BOX
27141 && face
->box_line_width
> 0)
27143 it
->ascent
+= face
->box_line_width
;
27144 it
->descent
+= face
->box_line_width
;
27147 && XINT (height
) > it
->ascent
+ it
->descent
)
27148 it
->ascent
= XINT (height
) - it
->descent
;
27150 if (!NILP (total_height
))
27151 spacing
= calc_line_height_property (it
, total_height
, font
,
27155 spacing
= get_it_property (it
, Qline_spacing
);
27156 spacing
= calc_line_height_property (it
, spacing
, font
,
27159 if (INTEGERP (spacing
))
27161 extra_line_spacing
= XINT (spacing
);
27162 if (!NILP (total_height
))
27163 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
27167 else /* i.e. (it->char_to_display == '\t') */
27169 if (font
->space_width
> 0)
27171 int tab_width
= it
->tab_width
* font
->space_width
;
27172 int x
= it
->current_x
+ it
->continuation_lines_width
;
27173 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
27175 /* If the distance from the current position to the next tab
27176 stop is less than a space character width, use the
27177 tab stop after that. */
27178 if (next_tab_x
- x
< font
->space_width
)
27179 next_tab_x
+= tab_width
;
27181 it
->pixel_width
= next_tab_x
- x
;
27183 if (FONT_TOO_HIGH (font
))
27185 if (get_char_glyph_code (' ', font
, &char2b
))
27187 pcm
= get_per_char_metric (font
, &char2b
);
27188 if (pcm
->width
== 0
27189 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
27195 it
->ascent
= pcm
->ascent
+ boff
;
27196 it
->descent
= pcm
->descent
- boff
;
27200 it
->ascent
= font
->pixel_size
+ boff
- 1;
27201 it
->descent
= -boff
+ 1;
27203 if (it
->ascent
< 0)
27205 if (it
->descent
< 0)
27210 it
->ascent
= FONT_BASE (font
) + boff
;
27211 it
->descent
= FONT_DESCENT (font
) - boff
;
27213 it
->phys_ascent
= it
->ascent
;
27214 it
->phys_descent
= it
->descent
;
27218 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
27219 it
->ascent
+ it
->descent
, it
->ascent
);
27224 it
->pixel_width
= 0;
27229 if (FONT_TOO_HIGH (font
))
27231 int font_ascent
, font_descent
;
27233 /* For very large fonts, where we ignore the declared font
27234 dimensions, and go by per-character metrics instead,
27235 don't let the row ascent and descent values (and the row
27236 height computed from them) be smaller than the "normal"
27237 character metrics. This avoids unpleasant effects
27238 whereby lines on display would change their height
27239 depending on which characters are shown. */
27240 normal_char_ascent_descent (font
, -1, &font_ascent
, &font_descent
);
27241 it
->max_ascent
= max (it
->max_ascent
, font_ascent
);
27242 it
->max_descent
= max (it
->max_descent
, font_descent
);
27245 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
27247 /* A static composition.
27249 Note: A composition is represented as one glyph in the
27250 glyph matrix. There are no padding glyphs.
27252 Important note: pixel_width, ascent, and descent are the
27253 values of what is drawn by draw_glyphs (i.e. the values of
27254 the overall glyphs composed). */
27255 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27256 int boff
; /* baseline offset */
27257 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
27258 int glyph_len
= cmp
->glyph_len
;
27259 struct font
*font
= face
->font
;
27263 /* If we have not yet calculated pixel size data of glyphs of
27264 the composition for the current face font, calculate them
27265 now. Theoretically, we have to check all fonts for the
27266 glyphs, but that requires much time and memory space. So,
27267 here we check only the font of the first glyph. This may
27268 lead to incorrect display, but it's very rare, and C-l
27269 (recenter-top-bottom) can correct the display anyway. */
27270 if (! cmp
->font
|| cmp
->font
!= font
)
27272 /* Ascent and descent of the font of the first character
27273 of this composition (adjusted by baseline offset).
27274 Ascent and descent of overall glyphs should not be less
27275 than these, respectively. */
27276 int font_ascent
, font_descent
, font_height
;
27277 /* Bounding box of the overall glyphs. */
27278 int leftmost
, rightmost
, lowest
, highest
;
27279 int lbearing
, rbearing
;
27280 int i
, width
, ascent
, descent
;
27281 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
27283 struct font_metrics
*pcm
;
27286 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
27287 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
27289 bool right_padded
= glyph_len
< cmp
->glyph_len
;
27290 for (i
= 0; i
< glyph_len
; i
++)
27292 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
27294 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
27296 bool left_padded
= i
> 0;
27298 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
27299 : IT_CHARPOS (*it
));
27300 /* If no suitable font is found, use the default font. */
27301 bool font_not_found_p
= font
== NULL
;
27302 if (font_not_found_p
)
27304 face
= face
->ascii_face
;
27307 boff
= font
->baseline_offset
;
27308 if (font
->vertical_centering
)
27309 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
27310 normal_char_ascent_descent (font
, -1, &font_ascent
, &font_descent
);
27311 font_ascent
+= boff
;
27312 font_descent
-= boff
;
27313 font_height
= font_ascent
+ font_descent
;
27318 if (! font_not_found_p
)
27320 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
27322 pcm
= get_per_char_metric (font
, &char2b
);
27325 /* Initialize the bounding box. */
27328 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
27329 ascent
= pcm
->ascent
;
27330 descent
= pcm
->descent
;
27331 lbearing
= pcm
->lbearing
;
27332 rbearing
= pcm
->rbearing
;
27336 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
27337 ascent
= FONT_BASE (font
);
27338 descent
= FONT_DESCENT (font
);
27345 lowest
= - descent
+ boff
;
27346 highest
= ascent
+ boff
;
27348 if (! font_not_found_p
27349 && font
->default_ascent
27350 && CHAR_TABLE_P (Vuse_default_ascent
)
27351 && !NILP (Faref (Vuse_default_ascent
,
27352 make_number (it
->char_to_display
))))
27353 highest
= font
->default_ascent
+ boff
;
27355 /* Draw the first glyph at the normal position. It may be
27356 shifted to right later if some other glyphs are drawn
27358 cmp
->offsets
[i
* 2] = 0;
27359 cmp
->offsets
[i
* 2 + 1] = boff
;
27360 cmp
->lbearing
= lbearing
;
27361 cmp
->rbearing
= rbearing
;
27363 /* Set cmp->offsets for the remaining glyphs. */
27364 for (i
++; i
< glyph_len
; i
++)
27366 int left
, right
, btm
, top
;
27367 int ch
= COMPOSITION_GLYPH (cmp
, i
);
27369 struct face
*this_face
;
27373 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
27374 this_face
= FACE_FROM_ID (it
->f
, face_id
);
27375 font
= this_face
->font
;
27381 get_char_face_and_encoding (it
->f
, ch
, face_id
,
27383 pcm
= get_per_char_metric (font
, &char2b
);
27386 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
27389 width
= pcm
->width
;
27390 ascent
= pcm
->ascent
;
27391 descent
= pcm
->descent
;
27392 lbearing
= pcm
->lbearing
;
27393 rbearing
= pcm
->rbearing
;
27394 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
27396 /* Relative composition with or without
27397 alternate chars. */
27398 left
= (leftmost
+ rightmost
- width
) / 2;
27399 btm
= - descent
+ boff
;
27400 if (font
->relative_compose
27401 && (! CHAR_TABLE_P (Vignore_relative_composition
)
27402 || NILP (Faref (Vignore_relative_composition
,
27403 make_number (ch
)))))
27406 if (- descent
>= font
->relative_compose
)
27407 /* One extra pixel between two glyphs. */
27409 else if (ascent
<= 0)
27410 /* One extra pixel between two glyphs. */
27411 btm
= lowest
- 1 - ascent
- descent
;
27416 /* A composition rule is specified by an integer
27417 value that encodes global and new reference
27418 points (GREF and NREF). GREF and NREF are
27419 specified by numbers as below:
27421 0---1---2 -- ascent
27425 9--10--11 -- center
27427 ---3---4---5--- baseline
27429 6---7---8 -- descent
27431 int rule
= COMPOSITION_RULE (cmp
, i
);
27432 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
27434 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
27435 grefx
= gref
% 3, nrefx
= nref
% 3;
27436 grefy
= gref
/ 3, nrefy
= nref
/ 3;
27438 xoff
= font_height
* (xoff
- 128) / 256;
27440 yoff
= font_height
* (yoff
- 128) / 256;
27443 + grefx
* (rightmost
- leftmost
) / 2
27444 - nrefx
* width
/ 2
27447 btm
= ((grefy
== 0 ? highest
27449 : grefy
== 2 ? lowest
27450 : (highest
+ lowest
) / 2)
27451 - (nrefy
== 0 ? ascent
+ descent
27452 : nrefy
== 1 ? descent
- boff
27454 : (ascent
+ descent
) / 2)
27458 cmp
->offsets
[i
* 2] = left
;
27459 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
27461 /* Update the bounding box of the overall glyphs. */
27464 right
= left
+ width
;
27465 if (left
< leftmost
)
27467 if (right
> rightmost
)
27470 top
= btm
+ descent
+ ascent
;
27476 if (cmp
->lbearing
> left
+ lbearing
)
27477 cmp
->lbearing
= left
+ lbearing
;
27478 if (cmp
->rbearing
< left
+ rbearing
)
27479 cmp
->rbearing
= left
+ rbearing
;
27483 /* If there are glyphs whose x-offsets are negative,
27484 shift all glyphs to the right and make all x-offsets
27488 for (i
= 0; i
< cmp
->glyph_len
; i
++)
27489 cmp
->offsets
[i
* 2] -= leftmost
;
27490 rightmost
-= leftmost
;
27491 cmp
->lbearing
-= leftmost
;
27492 cmp
->rbearing
-= leftmost
;
27495 if (left_padded
&& cmp
->lbearing
< 0)
27497 for (i
= 0; i
< cmp
->glyph_len
; i
++)
27498 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
27499 rightmost
-= cmp
->lbearing
;
27500 cmp
->rbearing
-= cmp
->lbearing
;
27503 if (right_padded
&& rightmost
< cmp
->rbearing
)
27505 rightmost
= cmp
->rbearing
;
27508 cmp
->pixel_width
= rightmost
;
27509 cmp
->ascent
= highest
;
27510 cmp
->descent
= - lowest
;
27511 if (cmp
->ascent
< font_ascent
)
27512 cmp
->ascent
= font_ascent
;
27513 if (cmp
->descent
< font_descent
)
27514 cmp
->descent
= font_descent
;
27518 && (cmp
->lbearing
< 0
27519 || cmp
->rbearing
> cmp
->pixel_width
))
27520 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27522 it
->pixel_width
= cmp
->pixel_width
;
27523 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
27524 it
->descent
= it
->phys_descent
= cmp
->descent
;
27525 if (face
->box
!= FACE_NO_BOX
)
27527 int thick
= face
->box_line_width
;
27531 it
->ascent
+= thick
;
27532 it
->descent
+= thick
;
27537 if (it
->start_of_box_run_p
)
27538 it
->pixel_width
+= thick
;
27539 if (it
->end_of_box_run_p
)
27540 it
->pixel_width
+= thick
;
27543 /* If face has an overline, add the height of the overline
27544 (1 pixel) and a 1 pixel margin to the character height. */
27545 if (face
->overline_p
)
27546 it
->ascent
+= overline_margin
;
27548 take_vertical_position_into_account (it
);
27549 if (it
->ascent
< 0)
27551 if (it
->descent
< 0)
27554 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
27555 append_composite_glyph (it
);
27557 else if (it
->what
== IT_COMPOSITION
)
27559 /* A dynamic (automatic) composition. */
27560 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27561 Lisp_Object gstring
;
27562 struct font_metrics metrics
;
27566 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
27568 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
27571 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
27572 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27573 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
27574 it
->descent
= it
->phys_descent
= metrics
.descent
;
27575 if (face
->box
!= FACE_NO_BOX
)
27577 int thick
= face
->box_line_width
;
27581 it
->ascent
+= thick
;
27582 it
->descent
+= thick
;
27587 if (it
->start_of_box_run_p
)
27588 it
->pixel_width
+= thick
;
27589 if (it
->end_of_box_run_p
)
27590 it
->pixel_width
+= thick
;
27592 /* If face has an overline, add the height of the overline
27593 (1 pixel) and a 1 pixel margin to the character height. */
27594 if (face
->overline_p
)
27595 it
->ascent
+= overline_margin
;
27596 take_vertical_position_into_account (it
);
27597 if (it
->ascent
< 0)
27599 if (it
->descent
< 0)
27603 append_composite_glyph (it
);
27605 else if (it
->what
== IT_GLYPHLESS
)
27606 produce_glyphless_glyph (it
, false, Qnil
);
27607 else if (it
->what
== IT_IMAGE
)
27608 produce_image_glyph (it
);
27609 else if (it
->what
== IT_STRETCH
)
27610 produce_stretch_glyph (it
);
27611 else if (it
->what
== IT_XWIDGET
)
27612 produce_xwidget_glyph (it
);
27615 /* Accumulate dimensions. Note: can't assume that it->descent > 0
27616 because this isn't true for images with `:ascent 100'. */
27617 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
27618 if (it
->area
== TEXT_AREA
)
27619 it
->current_x
+= it
->pixel_width
;
27621 if (extra_line_spacing
> 0)
27623 it
->descent
+= extra_line_spacing
;
27624 if (extra_line_spacing
> it
->max_extra_line_spacing
)
27625 it
->max_extra_line_spacing
= extra_line_spacing
;
27628 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
27629 it
->max_descent
= max (it
->max_descent
, it
->descent
);
27630 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
27631 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
27635 Output LEN glyphs starting at START at the nominal cursor position.
27636 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
27637 being updated, and UPDATED_AREA is the area of that row being updated. */
27640 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27641 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27643 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
27645 eassert (updated_row
);
27646 /* When the window is hscrolled, cursor hpos can legitimately be out
27647 of bounds, but we draw the cursor at the corresponding window
27648 margin in that case. */
27649 if (!updated_row
->reversed_p
&& chpos
< 0)
27651 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
27652 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
27656 /* Write glyphs. */
27658 hpos
= start
- updated_row
->glyphs
[updated_area
];
27659 x
= draw_glyphs (w
, w
->output_cursor
.x
,
27660 updated_row
, updated_area
,
27662 DRAW_NORMAL_TEXT
, 0);
27664 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
27665 if (updated_area
== TEXT_AREA
27666 && w
->phys_cursor_on_p
27667 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
27669 && chpos
< hpos
+ len
)
27670 w
->phys_cursor_on_p
= false;
27674 /* Advance the output cursor. */
27675 w
->output_cursor
.hpos
+= len
;
27676 w
->output_cursor
.x
= x
;
27681 Insert LEN glyphs from START at the nominal cursor position. */
27684 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27685 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27688 int line_height
, shift_by_width
, shifted_region_width
;
27689 struct glyph_row
*row
;
27690 struct glyph
*glyph
;
27691 int frame_x
, frame_y
;
27694 eassert (updated_row
);
27696 f
= XFRAME (WINDOW_FRAME (w
));
27698 /* Get the height of the line we are in. */
27700 line_height
= row
->height
;
27702 /* Get the width of the glyphs to insert. */
27703 shift_by_width
= 0;
27704 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
27705 shift_by_width
+= glyph
->pixel_width
;
27707 /* Get the width of the region to shift right. */
27708 shifted_region_width
= (window_box_width (w
, updated_area
)
27709 - w
->output_cursor
.x
27713 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
27714 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
27716 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
27717 line_height
, shift_by_width
);
27719 /* Write the glyphs. */
27720 hpos
= start
- row
->glyphs
[updated_area
];
27721 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
27723 DRAW_NORMAL_TEXT
, 0);
27725 /* Advance the output cursor. */
27726 w
->output_cursor
.hpos
+= len
;
27727 w
->output_cursor
.x
+= shift_by_width
;
27733 Erase the current text line from the nominal cursor position
27734 (inclusive) to pixel column TO_X (exclusive). The idea is that
27735 everything from TO_X onward is already erased.
27737 TO_X is a pixel position relative to UPDATED_AREA of currently
27738 updated window W. TO_X == -1 means clear to the end of this area. */
27741 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
27742 enum glyph_row_area updated_area
, int to_x
)
27745 int max_x
, min_y
, max_y
;
27746 int from_x
, from_y
, to_y
;
27748 eassert (updated_row
);
27749 f
= XFRAME (w
->frame
);
27751 if (updated_row
->full_width_p
)
27752 max_x
= (WINDOW_PIXEL_WIDTH (w
)
27753 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
27755 max_x
= window_box_width (w
, updated_area
);
27756 max_y
= window_text_bottom_y (w
);
27758 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
27759 of window. For TO_X > 0, truncate to end of drawing area. */
27765 to_x
= min (to_x
, max_x
);
27767 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
27769 /* Notice if the cursor will be cleared by this operation. */
27770 if (!updated_row
->full_width_p
)
27771 notice_overwritten_cursor (w
, updated_area
,
27772 w
->output_cursor
.x
, -1,
27774 MATRIX_ROW_BOTTOM_Y (updated_row
));
27776 from_x
= w
->output_cursor
.x
;
27778 /* Translate to frame coordinates. */
27779 if (updated_row
->full_width_p
)
27781 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
27782 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
27786 int area_left
= window_box_left (w
, updated_area
);
27787 from_x
+= area_left
;
27791 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
27792 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
27793 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
27795 /* Prevent inadvertently clearing to end of the X window. */
27796 if (to_x
> from_x
&& to_y
> from_y
)
27799 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
27800 to_x
- from_x
, to_y
- from_y
);
27805 #endif /* HAVE_WINDOW_SYSTEM */
27809 /***********************************************************************
27811 ***********************************************************************/
27813 /* Value is the internal representation of the specified cursor type
27814 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
27815 of the bar cursor. */
27817 static enum text_cursor_kinds
27818 get_specified_cursor_type (Lisp_Object arg
, int *width
)
27820 enum text_cursor_kinds type
;
27825 if (EQ (arg
, Qbox
))
27826 return FILLED_BOX_CURSOR
;
27828 if (EQ (arg
, Qhollow
))
27829 return HOLLOW_BOX_CURSOR
;
27831 if (EQ (arg
, Qbar
))
27838 && EQ (XCAR (arg
), Qbar
)
27839 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27841 *width
= XINT (XCDR (arg
));
27845 if (EQ (arg
, Qhbar
))
27848 return HBAR_CURSOR
;
27852 && EQ (XCAR (arg
), Qhbar
)
27853 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27855 *width
= XINT (XCDR (arg
));
27856 return HBAR_CURSOR
;
27859 /* Treat anything unknown as "hollow box cursor".
27860 It was bad to signal an error; people have trouble fixing
27861 .Xdefaults with Emacs, when it has something bad in it. */
27862 type
= HOLLOW_BOX_CURSOR
;
27867 /* Set the default cursor types for specified frame. */
27869 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
27874 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
27875 FRAME_CURSOR_WIDTH (f
) = width
;
27877 /* By default, set up the blink-off state depending on the on-state. */
27879 tem
= Fassoc (arg
, Vblink_cursor_alist
);
27882 FRAME_BLINK_OFF_CURSOR (f
)
27883 = get_specified_cursor_type (XCDR (tem
), &width
);
27884 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
27887 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
27889 /* Make sure the cursor gets redrawn. */
27890 f
->cursor_type_changed
= true;
27894 #ifdef HAVE_WINDOW_SYSTEM
27896 /* Return the cursor we want to be displayed in window W. Return
27897 width of bar/hbar cursor through WIDTH arg. Return with
27898 ACTIVE_CURSOR arg set to true if cursor in window W is `active'
27899 (i.e. if the `system caret' should track this cursor).
27901 In a mini-buffer window, we want the cursor only to appear if we
27902 are reading input from this window. For the selected window, we
27903 want the cursor type given by the frame parameter or buffer local
27904 setting of cursor-type. If explicitly marked off, draw no cursor.
27905 In all other cases, we want a hollow box cursor. */
27907 static enum text_cursor_kinds
27908 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
27909 bool *active_cursor
)
27911 struct frame
*f
= XFRAME (w
->frame
);
27912 struct buffer
*b
= XBUFFER (w
->contents
);
27913 int cursor_type
= DEFAULT_CURSOR
;
27914 Lisp_Object alt_cursor
;
27915 bool non_selected
= false;
27917 *active_cursor
= true;
27920 if (cursor_in_echo_area
27921 && FRAME_HAS_MINIBUF_P (f
)
27922 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
27924 if (w
== XWINDOW (echo_area_window
))
27926 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
27928 *width
= FRAME_CURSOR_WIDTH (f
);
27929 return FRAME_DESIRED_CURSOR (f
);
27932 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27935 *active_cursor
= false;
27936 non_selected
= true;
27939 /* Detect a nonselected window or nonselected frame. */
27940 else if (w
!= XWINDOW (f
->selected_window
)
27941 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
27943 *active_cursor
= false;
27945 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
27948 non_selected
= true;
27951 /* Never display a cursor in a window in which cursor-type is nil. */
27952 if (NILP (BVAR (b
, cursor_type
)))
27955 /* Get the normal cursor type for this window. */
27956 if (EQ (BVAR (b
, cursor_type
), Qt
))
27958 cursor_type
= FRAME_DESIRED_CURSOR (f
);
27959 *width
= FRAME_CURSOR_WIDTH (f
);
27962 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27964 /* Use cursor-in-non-selected-windows instead
27965 for non-selected window or frame. */
27968 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
27969 if (!EQ (Qt
, alt_cursor
))
27970 return get_specified_cursor_type (alt_cursor
, width
);
27971 /* t means modify the normal cursor type. */
27972 if (cursor_type
== FILLED_BOX_CURSOR
)
27973 cursor_type
= HOLLOW_BOX_CURSOR
;
27974 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
27976 return cursor_type
;
27979 /* Use normal cursor if not blinked off. */
27980 if (!w
->cursor_off_p
)
27982 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
)
27984 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27986 if (cursor_type
== FILLED_BOX_CURSOR
)
27988 /* Using a block cursor on large images can be very annoying.
27989 So use a hollow cursor for "large" images.
27990 If image is not transparent (no mask), also use hollow cursor. */
27991 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27992 if (img
!= NULL
&& IMAGEP (img
->spec
))
27994 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
27995 where N = size of default frame font size.
27996 This should cover most of the "tiny" icons people may use. */
27998 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
27999 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
28000 cursor_type
= HOLLOW_BOX_CURSOR
;
28003 else if (cursor_type
!= NO_CURSOR
)
28005 /* Display current only supports BOX and HOLLOW cursors for images.
28006 So for now, unconditionally use a HOLLOW cursor when cursor is
28007 not a solid box cursor. */
28008 cursor_type
= HOLLOW_BOX_CURSOR
;
28011 return cursor_type
;
28014 /* Cursor is blinked off, so determine how to "toggle" it. */
28016 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
28017 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
28018 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
28020 /* Then see if frame has specified a specific blink off cursor type. */
28021 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
28023 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
28024 return FRAME_BLINK_OFF_CURSOR (f
);
28028 /* Some people liked having a permanently visible blinking cursor,
28029 while others had very strong opinions against it. So it was
28030 decided to remove it. KFS 2003-09-03 */
28032 /* Finally perform built-in cursor blinking:
28033 filled box <-> hollow box
28034 wide [h]bar <-> narrow [h]bar
28035 narrow [h]bar <-> no cursor
28036 other type <-> no cursor */
28038 if (cursor_type
== FILLED_BOX_CURSOR
)
28039 return HOLLOW_BOX_CURSOR
;
28041 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
28044 return cursor_type
;
28052 /* Notice when the text cursor of window W has been completely
28053 overwritten by a drawing operation that outputs glyphs in AREA
28054 starting at X0 and ending at X1 in the line starting at Y0 and
28055 ending at Y1. X coordinates are area-relative. X1 < 0 means all
28056 the rest of the line after X0 has been written. Y coordinates
28057 are window-relative. */
28060 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
28061 int x0
, int x1
, int y0
, int y1
)
28063 int cx0
, cx1
, cy0
, cy1
;
28064 struct glyph_row
*row
;
28066 if (!w
->phys_cursor_on_p
)
28068 if (area
!= TEXT_AREA
)
28071 if (w
->phys_cursor
.vpos
< 0
28072 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
28073 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
28074 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
28077 if (row
->cursor_in_fringe_p
)
28079 row
->cursor_in_fringe_p
= false;
28080 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
28081 w
->phys_cursor_on_p
= false;
28085 cx0
= w
->phys_cursor
.x
;
28086 cx1
= cx0
+ w
->phys_cursor_width
;
28087 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
28090 /* The cursor image will be completely removed from the
28091 screen if the output area intersects the cursor area in
28092 y-direction. When we draw in [y0 y1[, and some part of
28093 the cursor is at y < y0, that part must have been drawn
28094 before. When scrolling, the cursor is erased before
28095 actually scrolling, so we don't come here. When not
28096 scrolling, the rows above the old cursor row must have
28097 changed, and in this case these rows must have written
28098 over the cursor image.
28100 Likewise if part of the cursor is below y1, with the
28101 exception of the cursor being in the first blank row at
28102 the buffer and window end because update_text_area
28103 doesn't draw that row. (Except when it does, but
28104 that's handled in update_text_area.) */
28106 cy0
= w
->phys_cursor
.y
;
28107 cy1
= cy0
+ w
->phys_cursor_height
;
28108 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
28111 w
->phys_cursor_on_p
= false;
28114 #endif /* HAVE_WINDOW_SYSTEM */
28117 /************************************************************************
28119 ************************************************************************/
28121 #ifdef HAVE_WINDOW_SYSTEM
28124 Fix the display of area AREA of overlapping row ROW in window W
28125 with respect to the overlapping part OVERLAPS. */
28128 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
28129 enum glyph_row_area area
, int overlaps
)
28136 for (i
= 0; i
< row
->used
[area
];)
28138 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
28140 int start
= i
, start_x
= x
;
28144 x
+= row
->glyphs
[area
][i
].pixel_width
;
28147 while (i
< row
->used
[area
]
28148 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
28150 draw_glyphs (w
, start_x
, row
, area
,
28152 DRAW_NORMAL_TEXT
, overlaps
);
28156 x
+= row
->glyphs
[area
][i
].pixel_width
;
28166 Draw the cursor glyph of window W in glyph row ROW. See the
28167 comment of draw_glyphs for the meaning of HL. */
28170 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
28171 enum draw_glyphs_face hl
)
28173 /* If cursor hpos is out of bounds, don't draw garbage. This can
28174 happen in mini-buffer windows when switching between echo area
28175 glyphs and mini-buffer. */
28176 if ((row
->reversed_p
28177 ? (w
->phys_cursor
.hpos
>= 0)
28178 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
28180 bool on_p
= w
->phys_cursor_on_p
;
28182 int hpos
= w
->phys_cursor
.hpos
;
28184 /* When the window is hscrolled, cursor hpos can legitimately be
28185 out of bounds, but we draw the cursor at the corresponding
28186 window margin in that case. */
28187 if (!row
->reversed_p
&& hpos
< 0)
28189 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28190 hpos
= row
->used
[TEXT_AREA
] - 1;
28192 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
28194 w
->phys_cursor_on_p
= on_p
;
28196 if (hl
== DRAW_CURSOR
)
28197 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
28198 /* When we erase the cursor, and ROW is overlapped by other
28199 rows, make sure that these overlapping parts of other rows
28201 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
28203 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
28205 if (row
> w
->current_matrix
->rows
28206 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
28207 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
28208 OVERLAPS_ERASED_CURSOR
);
28210 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
28211 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
28212 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
28213 OVERLAPS_ERASED_CURSOR
);
28219 /* Erase the image of a cursor of window W from the screen. */
28222 erase_phys_cursor (struct window
*w
)
28224 struct frame
*f
= XFRAME (w
->frame
);
28225 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28226 int hpos
= w
->phys_cursor
.hpos
;
28227 int vpos
= w
->phys_cursor
.vpos
;
28228 bool mouse_face_here_p
= false;
28229 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
28230 struct glyph_row
*cursor_row
;
28231 struct glyph
*cursor_glyph
;
28232 enum draw_glyphs_face hl
;
28234 /* No cursor displayed or row invalidated => nothing to do on the
28236 if (w
->phys_cursor_type
== NO_CURSOR
)
28237 goto mark_cursor_off
;
28239 /* VPOS >= active_glyphs->nrows means that window has been resized.
28240 Don't bother to erase the cursor. */
28241 if (vpos
>= active_glyphs
->nrows
)
28242 goto mark_cursor_off
;
28244 /* If row containing cursor is marked invalid, there is nothing we
28246 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
28247 if (!cursor_row
->enabled_p
)
28248 goto mark_cursor_off
;
28250 /* If line spacing is > 0, old cursor may only be partially visible in
28251 window after split-window. So adjust visible height. */
28252 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
28253 window_text_bottom_y (w
) - cursor_row
->y
);
28255 /* If row is completely invisible, don't attempt to delete a cursor which
28256 isn't there. This can happen if cursor is at top of a window, and
28257 we switch to a buffer with a header line in that window. */
28258 if (cursor_row
->visible_height
<= 0)
28259 goto mark_cursor_off
;
28261 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
28262 if (cursor_row
->cursor_in_fringe_p
)
28264 cursor_row
->cursor_in_fringe_p
= false;
28265 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
28266 goto mark_cursor_off
;
28269 /* This can happen when the new row is shorter than the old one.
28270 In this case, either draw_glyphs or clear_end_of_line
28271 should have cleared the cursor. Note that we wouldn't be
28272 able to erase the cursor in this case because we don't have a
28273 cursor glyph at hand. */
28274 if ((cursor_row
->reversed_p
28275 ? (w
->phys_cursor
.hpos
< 0)
28276 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
28277 goto mark_cursor_off
;
28279 /* When the window is hscrolled, cursor hpos can legitimately be out
28280 of bounds, but we draw the cursor at the corresponding window
28281 margin in that case. */
28282 if (!cursor_row
->reversed_p
&& hpos
< 0)
28284 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
28285 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
28287 /* If the cursor is in the mouse face area, redisplay that when
28288 we clear the cursor. */
28289 if (! NILP (hlinfo
->mouse_face_window
)
28290 && coords_in_mouse_face_p (w
, hpos
, vpos
)
28291 /* Don't redraw the cursor's spot in mouse face if it is at the
28292 end of a line (on a newline). The cursor appears there, but
28293 mouse highlighting does not. */
28294 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
28295 mouse_face_here_p
= true;
28297 /* Maybe clear the display under the cursor. */
28298 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
28301 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
28304 cursor_glyph
= get_phys_cursor_glyph (w
);
28305 if (cursor_glyph
== NULL
)
28306 goto mark_cursor_off
;
28308 width
= cursor_glyph
->pixel_width
;
28309 x
= w
->phys_cursor
.x
;
28315 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
28316 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
28317 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
28320 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
28323 /* Erase the cursor by redrawing the character underneath it. */
28324 if (mouse_face_here_p
)
28325 hl
= DRAW_MOUSE_FACE
;
28327 hl
= DRAW_NORMAL_TEXT
;
28328 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
28331 w
->phys_cursor_on_p
= false;
28332 w
->phys_cursor_type
= NO_CURSOR
;
28336 /* Display or clear cursor of window W. If !ON, clear the cursor.
28337 If ON, display the cursor; where to put the cursor is specified by
28338 HPOS, VPOS, X and Y. */
28341 display_and_set_cursor (struct window
*w
, bool on
,
28342 int hpos
, int vpos
, int x
, int y
)
28344 struct frame
*f
= XFRAME (w
->frame
);
28345 int new_cursor_type
;
28346 int new_cursor_width
;
28347 bool active_cursor
;
28348 struct glyph_row
*glyph_row
;
28349 struct glyph
*glyph
;
28351 /* This is pointless on invisible frames, and dangerous on garbaged
28352 windows and frames; in the latter case, the frame or window may
28353 be in the midst of changing its size, and x and y may be off the
28355 if (! FRAME_VISIBLE_P (f
)
28356 || FRAME_GARBAGED_P (f
)
28357 || vpos
>= w
->current_matrix
->nrows
28358 || hpos
>= w
->current_matrix
->matrix_w
)
28361 /* If cursor is off and we want it off, return quickly. */
28362 if (!on
&& !w
->phys_cursor_on_p
)
28365 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28366 /* If cursor row is not enabled, we don't really know where to
28367 display the cursor. */
28368 if (!glyph_row
->enabled_p
)
28370 w
->phys_cursor_on_p
= false;
28375 if (!glyph_row
->exact_window_width_line_p
28376 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
28377 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
28379 eassert (input_blocked_p ());
28381 /* Set new_cursor_type to the cursor we want to be displayed. */
28382 new_cursor_type
= get_window_cursor_type (w
, glyph
,
28383 &new_cursor_width
, &active_cursor
);
28385 /* If cursor is currently being shown and we don't want it to be or
28386 it is in the wrong place, or the cursor type is not what we want,
28388 if (w
->phys_cursor_on_p
28390 || w
->phys_cursor
.x
!= x
28391 || w
->phys_cursor
.y
!= y
28392 /* HPOS can be negative in R2L rows whose
28393 exact_window_width_line_p flag is set (i.e. their newline
28394 would "overflow into the fringe"). */
28396 || new_cursor_type
!= w
->phys_cursor_type
28397 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
28398 && new_cursor_width
!= w
->phys_cursor_width
)))
28399 erase_phys_cursor (w
);
28401 /* Don't check phys_cursor_on_p here because that flag is only set
28402 to false in some cases where we know that the cursor has been
28403 completely erased, to avoid the extra work of erasing the cursor
28404 twice. In other words, phys_cursor_on_p can be true and the cursor
28405 still not be visible, or it has only been partly erased. */
28408 w
->phys_cursor_ascent
= glyph_row
->ascent
;
28409 w
->phys_cursor_height
= glyph_row
->height
;
28411 /* Set phys_cursor_.* before x_draw_.* is called because some
28412 of them may need the information. */
28413 w
->phys_cursor
.x
= x
;
28414 w
->phys_cursor
.y
= glyph_row
->y
;
28415 w
->phys_cursor
.hpos
= hpos
;
28416 w
->phys_cursor
.vpos
= vpos
;
28419 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
28420 new_cursor_type
, new_cursor_width
,
28421 on
, active_cursor
);
28425 /* Switch the display of W's cursor on or off, according to the value
28429 update_window_cursor (struct window
*w
, bool on
)
28431 /* Don't update cursor in windows whose frame is in the process
28432 of being deleted. */
28433 if (w
->current_matrix
)
28435 int hpos
= w
->phys_cursor
.hpos
;
28436 int vpos
= w
->phys_cursor
.vpos
;
28437 struct glyph_row
*row
;
28439 if (vpos
>= w
->current_matrix
->nrows
28440 || hpos
>= w
->current_matrix
->matrix_w
)
28443 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28445 /* When the window is hscrolled, cursor hpos can legitimately be
28446 out of bounds, but we draw the cursor at the corresponding
28447 window margin in that case. */
28448 if (!row
->reversed_p
&& hpos
< 0)
28450 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28451 hpos
= row
->used
[TEXT_AREA
] - 1;
28454 display_and_set_cursor (w
, on
, hpos
, vpos
,
28455 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28461 /* Call update_window_cursor with parameter ON_P on all leaf windows
28462 in the window tree rooted at W. */
28465 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
28469 if (WINDOWP (w
->contents
))
28470 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
28472 update_window_cursor (w
, on_p
);
28474 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
28480 Display the cursor on window W, or clear it, according to ON_P.
28481 Don't change the cursor's position. */
28484 x_update_cursor (struct frame
*f
, bool on_p
)
28486 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
28491 Clear the cursor of window W to background color, and mark the
28492 cursor as not shown. This is used when the text where the cursor
28493 is about to be rewritten. */
28496 x_clear_cursor (struct window
*w
)
28498 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
28499 update_window_cursor (w
, false);
28502 #endif /* HAVE_WINDOW_SYSTEM */
28504 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
28507 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
28508 int start_hpos
, int end_hpos
,
28509 enum draw_glyphs_face draw
)
28511 #ifdef HAVE_WINDOW_SYSTEM
28512 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
28514 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
28518 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
28519 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
28523 /* Display the active region described by mouse_face_* according to DRAW. */
28526 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
28528 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
28529 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28531 if (/* If window is in the process of being destroyed, don't bother
28533 w
->current_matrix
!= NULL
28534 /* Don't update mouse highlight if hidden. */
28535 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
28536 /* Recognize when we are called to operate on rows that don't exist
28537 anymore. This can happen when a window is split. */
28538 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
28540 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
28541 struct glyph_row
*row
, *first
, *last
;
28543 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
28544 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
28546 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
28548 int start_hpos
, end_hpos
, start_x
;
28550 /* For all but the first row, the highlight starts at column 0. */
28553 /* R2L rows have BEG and END in reversed order, but the
28554 screen drawing geometry is always left to right. So
28555 we need to mirror the beginning and end of the
28556 highlighted area in R2L rows. */
28557 if (!row
->reversed_p
)
28559 start_hpos
= hlinfo
->mouse_face_beg_col
;
28560 start_x
= hlinfo
->mouse_face_beg_x
;
28562 else if (row
== last
)
28564 start_hpos
= hlinfo
->mouse_face_end_col
;
28565 start_x
= hlinfo
->mouse_face_end_x
;
28573 else if (row
->reversed_p
&& row
== last
)
28575 start_hpos
= hlinfo
->mouse_face_end_col
;
28576 start_x
= hlinfo
->mouse_face_end_x
;
28586 if (!row
->reversed_p
)
28587 end_hpos
= hlinfo
->mouse_face_end_col
;
28588 else if (row
== first
)
28589 end_hpos
= hlinfo
->mouse_face_beg_col
;
28592 end_hpos
= row
->used
[TEXT_AREA
];
28593 if (draw
== DRAW_NORMAL_TEXT
)
28594 row
->fill_line_p
= true; /* Clear to end of line. */
28597 else if (row
->reversed_p
&& row
== first
)
28598 end_hpos
= hlinfo
->mouse_face_beg_col
;
28601 end_hpos
= row
->used
[TEXT_AREA
];
28602 if (draw
== DRAW_NORMAL_TEXT
)
28603 row
->fill_line_p
= true; /* Clear to end of line. */
28606 if (end_hpos
> start_hpos
)
28608 draw_row_with_mouse_face (w
, start_x
, row
,
28609 start_hpos
, end_hpos
, draw
);
28612 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
28616 #ifdef HAVE_WINDOW_SYSTEM
28617 /* When we've written over the cursor, arrange for it to
28618 be displayed again. */
28619 if (FRAME_WINDOW_P (f
)
28620 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
28622 int hpos
= w
->phys_cursor
.hpos
;
28624 /* When the window is hscrolled, cursor hpos can legitimately be
28625 out of bounds, but we draw the cursor at the corresponding
28626 window margin in that case. */
28627 if (!row
->reversed_p
&& hpos
< 0)
28629 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28630 hpos
= row
->used
[TEXT_AREA
] - 1;
28633 display_and_set_cursor (w
, true, hpos
, w
->phys_cursor
.vpos
,
28634 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28637 #endif /* HAVE_WINDOW_SYSTEM */
28640 #ifdef HAVE_WINDOW_SYSTEM
28641 /* Change the mouse cursor. */
28642 if (FRAME_WINDOW_P (f
) && NILP (do_mouse_tracking
))
28644 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
28645 if (draw
== DRAW_NORMAL_TEXT
28646 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
28647 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
28650 if (draw
== DRAW_MOUSE_FACE
)
28651 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
28653 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
28655 #endif /* HAVE_WINDOW_SYSTEM */
28659 Clear out the mouse-highlighted active region.
28660 Redraw it un-highlighted first. Value is true if mouse
28661 face was actually drawn unhighlighted. */
28664 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
28667 = !hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
);
28669 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
28670 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28671 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28672 hlinfo
->mouse_face_window
= Qnil
;
28673 hlinfo
->mouse_face_overlay
= Qnil
;
28677 /* Return true if the coordinates HPOS and VPOS on windows W are
28678 within the mouse face on that window. */
28680 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
28682 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28684 /* Quickly resolve the easy cases. */
28685 if (!(WINDOWP (hlinfo
->mouse_face_window
)
28686 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
28688 if (vpos
< hlinfo
->mouse_face_beg_row
28689 || vpos
> hlinfo
->mouse_face_end_row
)
28691 if (vpos
> hlinfo
->mouse_face_beg_row
28692 && vpos
< hlinfo
->mouse_face_end_row
)
28695 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
28697 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28699 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
28702 else if ((vpos
== hlinfo
->mouse_face_beg_row
28703 && hpos
>= hlinfo
->mouse_face_beg_col
)
28704 || (vpos
== hlinfo
->mouse_face_end_row
28705 && hpos
< hlinfo
->mouse_face_end_col
))
28710 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28712 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
28715 else if ((vpos
== hlinfo
->mouse_face_beg_row
28716 && hpos
<= hlinfo
->mouse_face_beg_col
)
28717 || (vpos
== hlinfo
->mouse_face_end_row
28718 && hpos
> hlinfo
->mouse_face_end_col
))
28726 True if physical cursor of window W is within mouse face. */
28729 cursor_in_mouse_face_p (struct window
*w
)
28731 int hpos
= w
->phys_cursor
.hpos
;
28732 int vpos
= w
->phys_cursor
.vpos
;
28733 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28735 /* When the window is hscrolled, cursor hpos can legitimately be out
28736 of bounds, but we draw the cursor at the corresponding window
28737 margin in that case. */
28738 if (!row
->reversed_p
&& hpos
< 0)
28740 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28741 hpos
= row
->used
[TEXT_AREA
] - 1;
28743 return coords_in_mouse_face_p (w
, hpos
, vpos
);
28748 /* Find the glyph rows START_ROW and END_ROW of window W that display
28749 characters between buffer positions START_CHARPOS and END_CHARPOS
28750 (excluding END_CHARPOS). DISP_STRING is a display string that
28751 covers these buffer positions. This is similar to
28752 row_containing_pos, but is more accurate when bidi reordering makes
28753 buffer positions change non-linearly with glyph rows. */
28755 rows_from_pos_range (struct window
*w
,
28756 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
28757 Lisp_Object disp_string
,
28758 struct glyph_row
**start
, struct glyph_row
**end
)
28760 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28761 int last_y
= window_text_bottom_y (w
);
28762 struct glyph_row
*row
;
28767 while (!first
->enabled_p
28768 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
28771 /* Find the START row. */
28773 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
28776 /* A row can potentially be the START row if the range of the
28777 characters it displays intersects the range
28778 [START_CHARPOS..END_CHARPOS). */
28779 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
28780 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
28781 /* See the commentary in row_containing_pos, for the
28782 explanation of the complicated way to check whether
28783 some position is beyond the end of the characters
28784 displayed by a row. */
28785 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28786 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28787 && !row
->ends_at_zv_p
28788 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
28789 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28790 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28791 && !row
->ends_at_zv_p
28792 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
28794 /* Found a candidate row. Now make sure at least one of the
28795 glyphs it displays has a charpos from the range
28796 [START_CHARPOS..END_CHARPOS).
28798 This is not obvious because bidi reordering could make
28799 buffer positions of a row be 1,2,3,102,101,100, and if we
28800 want to highlight characters in [50..60), we don't want
28801 this row, even though [50..60) does intersect [1..103),
28802 the range of character positions given by the row's start
28803 and end positions. */
28804 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
28805 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
28809 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28810 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28811 /* A glyph that comes from DISP_STRING is by
28812 definition to be highlighted. */
28813 || EQ (g
->object
, disp_string
))
28822 /* Find the END row. */
28824 /* If the last row is partially visible, start looking for END
28825 from that row, instead of starting from FIRST. */
28826 && !(row
->enabled_p
28827 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
28829 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
28831 struct glyph_row
*next
= row
+ 1;
28832 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
28834 if (!next
->enabled_p
28835 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
28836 /* The first row >= START whose range of displayed characters
28837 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
28838 is the row END + 1. */
28839 || (start_charpos
< next_start
28840 && end_charpos
< next_start
)
28841 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28842 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28843 && !next
->ends_at_zv_p
28844 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
28845 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28846 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28847 && !next
->ends_at_zv_p
28848 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
28855 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
28856 but none of the characters it displays are in the range, it is
28858 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
28859 struct glyph
*s
= g
;
28860 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
28864 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28865 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28866 /* If the buffer position of the first glyph in
28867 the row is equal to END_CHARPOS, it means
28868 the last character to be highlighted is the
28869 newline of ROW, and we must consider NEXT as
28871 || (((!next
->reversed_p
&& g
== s
)
28872 || (next
->reversed_p
&& g
== e
- 1))
28873 && (g
->charpos
== end_charpos
28874 /* Special case for when NEXT is an
28875 empty line at ZV. */
28876 || (g
->charpos
== -1
28877 && !row
->ends_at_zv_p
28878 && next_start
== end_charpos
)))))
28879 /* A glyph that comes from DISP_STRING is by
28880 definition to be highlighted. */
28881 || EQ (g
->object
, disp_string
))
28890 /* The first row that ends at ZV must be the last to be
28892 else if (next
->ends_at_zv_p
)
28901 /* This function sets the mouse_face_* elements of HLINFO, assuming
28902 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
28903 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
28904 for the overlay or run of text properties specifying the mouse
28905 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
28906 before-string and after-string that must also be highlighted.
28907 DISP_STRING, if non-nil, is a display string that may cover some
28908 or all of the highlighted text. */
28911 mouse_face_from_buffer_pos (Lisp_Object window
,
28912 Mouse_HLInfo
*hlinfo
,
28913 ptrdiff_t mouse_charpos
,
28914 ptrdiff_t start_charpos
,
28915 ptrdiff_t end_charpos
,
28916 Lisp_Object before_string
,
28917 Lisp_Object after_string
,
28918 Lisp_Object disp_string
)
28920 struct window
*w
= XWINDOW (window
);
28921 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28922 struct glyph_row
*r1
, *r2
;
28923 struct glyph
*glyph
, *end
;
28924 ptrdiff_t ignore
, pos
;
28927 eassert (NILP (disp_string
) || STRINGP (disp_string
));
28928 eassert (NILP (before_string
) || STRINGP (before_string
));
28929 eassert (NILP (after_string
) || STRINGP (after_string
));
28931 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
28932 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
28934 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28935 /* If the before-string or display-string contains newlines,
28936 rows_from_pos_range skips to its last row. Move back. */
28937 if (!NILP (before_string
) || !NILP (disp_string
))
28939 struct glyph_row
*prev
;
28940 while ((prev
= r1
- 1, prev
>= first
)
28941 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
28942 && prev
->used
[TEXT_AREA
] > 0)
28944 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
28945 glyph
= beg
+ prev
->used
[TEXT_AREA
];
28946 while (--glyph
>= beg
&& NILP (glyph
->object
));
28948 || !(EQ (glyph
->object
, before_string
)
28949 || EQ (glyph
->object
, disp_string
)))
28956 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28957 hlinfo
->mouse_face_past_end
= true;
28959 else if (!NILP (after_string
))
28961 /* If the after-string has newlines, advance to its last row. */
28962 struct glyph_row
*next
;
28963 struct glyph_row
*last
28964 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28966 for (next
= r2
+ 1;
28968 && next
->used
[TEXT_AREA
] > 0
28969 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
28973 /* The rest of the display engine assumes that mouse_face_beg_row is
28974 either above mouse_face_end_row or identical to it. But with
28975 bidi-reordered continued lines, the row for START_CHARPOS could
28976 be below the row for END_CHARPOS. If so, swap the rows and store
28977 them in correct order. */
28980 struct glyph_row
*tem
= r2
;
28986 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
28987 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
28989 /* For a bidi-reordered row, the positions of BEFORE_STRING,
28990 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
28991 could be anywhere in the row and in any order. The strategy
28992 below is to find the leftmost and the rightmost glyph that
28993 belongs to either of these 3 strings, or whose position is
28994 between START_CHARPOS and END_CHARPOS, and highlight all the
28995 glyphs between those two. This may cover more than just the text
28996 between START_CHARPOS and END_CHARPOS if the range of characters
28997 strides the bidi level boundary, e.g. if the beginning is in R2L
28998 text while the end is in L2R text or vice versa. */
28999 if (!r1
->reversed_p
)
29001 /* This row is in a left to right paragraph. Scan it left to
29003 glyph
= r1
->glyphs
[TEXT_AREA
];
29004 end
= glyph
+ r1
->used
[TEXT_AREA
];
29007 /* Skip truncation glyphs at the start of the glyph row. */
29008 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
29010 && NILP (glyph
->object
)
29011 && glyph
->charpos
< 0;
29013 x
+= glyph
->pixel_width
;
29015 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
29016 or DISP_STRING, and the first glyph from buffer whose
29017 position is between START_CHARPOS and END_CHARPOS. */
29019 && !NILP (glyph
->object
)
29020 && !EQ (glyph
->object
, disp_string
)
29021 && !(BUFFERP (glyph
->object
)
29022 && (glyph
->charpos
>= start_charpos
29023 && glyph
->charpos
< end_charpos
));
29026 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29027 are present at buffer positions between START_CHARPOS and
29028 END_CHARPOS, or if they come from an overlay. */
29029 if (EQ (glyph
->object
, before_string
))
29031 pos
= string_buffer_position (before_string
,
29033 /* If pos == 0, it means before_string came from an
29034 overlay, not from a buffer position. */
29035 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29038 else if (EQ (glyph
->object
, after_string
))
29040 pos
= string_buffer_position (after_string
, end_charpos
);
29041 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29044 x
+= glyph
->pixel_width
;
29046 hlinfo
->mouse_face_beg_x
= x
;
29047 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
29051 /* This row is in a right to left paragraph. Scan it right to
29055 end
= r1
->glyphs
[TEXT_AREA
] - 1;
29056 glyph
= end
+ r1
->used
[TEXT_AREA
];
29058 /* Skip truncation glyphs at the start of the glyph row. */
29059 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
29061 && NILP (glyph
->object
)
29062 && glyph
->charpos
< 0;
29066 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
29067 or DISP_STRING, and the first glyph from buffer whose
29068 position is between START_CHARPOS and END_CHARPOS. */
29070 && !NILP (glyph
->object
)
29071 && !EQ (glyph
->object
, disp_string
)
29072 && !(BUFFERP (glyph
->object
)
29073 && (glyph
->charpos
>= start_charpos
29074 && glyph
->charpos
< end_charpos
));
29077 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29078 are present at buffer positions between START_CHARPOS and
29079 END_CHARPOS, or if they come from an overlay. */
29080 if (EQ (glyph
->object
, before_string
))
29082 pos
= string_buffer_position (before_string
, start_charpos
);
29083 /* If pos == 0, it means before_string came from an
29084 overlay, not from a buffer position. */
29085 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29088 else if (EQ (glyph
->object
, after_string
))
29090 pos
= string_buffer_position (after_string
, end_charpos
);
29091 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29096 glyph
++; /* first glyph to the right of the highlighted area */
29097 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
29098 x
+= g
->pixel_width
;
29099 hlinfo
->mouse_face_beg_x
= x
;
29100 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
29103 /* If the highlight ends in a different row, compute GLYPH and END
29104 for the end row. Otherwise, reuse the values computed above for
29105 the row where the highlight begins. */
29108 if (!r2
->reversed_p
)
29110 glyph
= r2
->glyphs
[TEXT_AREA
];
29111 end
= glyph
+ r2
->used
[TEXT_AREA
];
29116 end
= r2
->glyphs
[TEXT_AREA
] - 1;
29117 glyph
= end
+ r2
->used
[TEXT_AREA
];
29121 if (!r2
->reversed_p
)
29123 /* Skip truncation and continuation glyphs near the end of the
29124 row, and also blanks and stretch glyphs inserted by
29125 extend_face_to_end_of_line. */
29127 && NILP ((end
- 1)->object
))
29129 /* Scan the rest of the glyph row from the end, looking for the
29130 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
29131 DISP_STRING, or whose position is between START_CHARPOS
29135 && !NILP (end
->object
)
29136 && !EQ (end
->object
, disp_string
)
29137 && !(BUFFERP (end
->object
)
29138 && (end
->charpos
>= start_charpos
29139 && end
->charpos
< end_charpos
));
29142 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29143 are present at buffer positions between START_CHARPOS and
29144 END_CHARPOS, or if they come from an overlay. */
29145 if (EQ (end
->object
, before_string
))
29147 pos
= string_buffer_position (before_string
, start_charpos
);
29148 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29151 else if (EQ (end
->object
, after_string
))
29153 pos
= string_buffer_position (after_string
, end_charpos
);
29154 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29158 /* Find the X coordinate of the last glyph to be highlighted. */
29159 for (; glyph
<= end
; ++glyph
)
29160 x
+= glyph
->pixel_width
;
29162 hlinfo
->mouse_face_end_x
= x
;
29163 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
29167 /* Skip truncation and continuation glyphs near the end of the
29168 row, and also blanks and stretch glyphs inserted by
29169 extend_face_to_end_of_line. */
29173 && NILP (end
->object
))
29175 x
+= end
->pixel_width
;
29178 /* Scan the rest of the glyph row from the end, looking for the
29179 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
29180 DISP_STRING, or whose position is between START_CHARPOS
29184 && !NILP (end
->object
)
29185 && !EQ (end
->object
, disp_string
)
29186 && !(BUFFERP (end
->object
)
29187 && (end
->charpos
>= start_charpos
29188 && end
->charpos
< end_charpos
));
29191 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29192 are present at buffer positions between START_CHARPOS and
29193 END_CHARPOS, or if they come from an overlay. */
29194 if (EQ (end
->object
, before_string
))
29196 pos
= string_buffer_position (before_string
, start_charpos
);
29197 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29200 else if (EQ (end
->object
, after_string
))
29202 pos
= string_buffer_position (after_string
, end_charpos
);
29203 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29206 x
+= end
->pixel_width
;
29208 /* If we exited the above loop because we arrived at the last
29209 glyph of the row, and its buffer position is still not in
29210 range, it means the last character in range is the preceding
29211 newline. Bump the end column and x values to get past the
29214 && BUFFERP (end
->object
)
29215 && (end
->charpos
< start_charpos
29216 || end
->charpos
>= end_charpos
))
29218 x
+= end
->pixel_width
;
29221 hlinfo
->mouse_face_end_x
= x
;
29222 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
29225 hlinfo
->mouse_face_window
= window
;
29226 hlinfo
->mouse_face_face_id
29227 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
29229 !hlinfo
->mouse_face_hidden
, -1);
29230 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29233 /* The following function is not used anymore (replaced with
29234 mouse_face_from_string_pos), but I leave it here for the time
29235 being, in case someone would. */
29237 #if false /* not used */
29239 /* Find the position of the glyph for position POS in OBJECT in
29240 window W's current matrix, and return in *X, *Y the pixel
29241 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
29243 RIGHT_P means return the position of the right edge of the glyph.
29244 !RIGHT_P means return the left edge position.
29246 If no glyph for POS exists in the matrix, return the position of
29247 the glyph with the next smaller position that is in the matrix, if
29248 RIGHT_P is false. If RIGHT_P, and no glyph for POS
29249 exists in the matrix, return the position of the glyph with the
29250 next larger position in OBJECT.
29252 Value is true if a glyph was found. */
29255 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
29256 int *hpos
, int *vpos
, int *x
, int *y
, bool right_p
)
29258 int yb
= window_text_bottom_y (w
);
29259 struct glyph_row
*r
;
29260 struct glyph
*best_glyph
= NULL
;
29261 struct glyph_row
*best_row
= NULL
;
29264 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29265 r
->enabled_p
&& r
->y
< yb
;
29268 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
29269 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
29272 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
29273 if (EQ (g
->object
, object
))
29275 if (g
->charpos
== pos
)
29282 else if (best_glyph
== NULL
29283 || ((eabs (g
->charpos
- pos
)
29284 < eabs (best_glyph
->charpos
- pos
))
29287 : g
->charpos
> pos
)))
29301 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
29305 *x
+= best_glyph
->pixel_width
;
29310 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
29313 return best_glyph
!= NULL
;
29315 #endif /* not used */
29317 /* Find the positions of the first and the last glyphs in window W's
29318 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
29319 (assumed to be a string), and return in HLINFO's mouse_face_*
29320 members the pixel and column/row coordinates of those glyphs. */
29323 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
29324 Lisp_Object object
,
29325 ptrdiff_t startpos
, ptrdiff_t endpos
)
29327 int yb
= window_text_bottom_y (w
);
29328 struct glyph_row
*r
;
29329 struct glyph
*g
, *e
;
29331 bool found
= false;
29333 /* Find the glyph row with at least one position in the range
29334 [STARTPOS..ENDPOS), and the first glyph in that row whose
29335 position belongs to that range. */
29336 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29337 r
->enabled_p
&& r
->y
< yb
;
29340 if (!r
->reversed_p
)
29342 g
= r
->glyphs
[TEXT_AREA
];
29343 e
= g
+ r
->used
[TEXT_AREA
];
29344 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
29345 if (EQ (g
->object
, object
)
29346 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
29348 hlinfo
->mouse_face_beg_row
29349 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29350 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
29351 hlinfo
->mouse_face_beg_x
= gx
;
29360 e
= r
->glyphs
[TEXT_AREA
];
29361 g
= e
+ r
->used
[TEXT_AREA
];
29362 for ( ; g
> e
; --g
)
29363 if (EQ ((g
-1)->object
, object
)
29364 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
29366 hlinfo
->mouse_face_beg_row
29367 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29368 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
29369 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
29370 gx
+= g1
->pixel_width
;
29371 hlinfo
->mouse_face_beg_x
= gx
;
29383 /* Starting with the next row, look for the first row which does NOT
29384 include any glyphs whose positions are in the range. */
29385 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
29387 g
= r
->glyphs
[TEXT_AREA
];
29388 e
= g
+ r
->used
[TEXT_AREA
];
29390 for ( ; g
< e
; ++g
)
29391 if (EQ (g
->object
, object
)
29392 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
29401 /* The highlighted region ends on the previous row. */
29404 /* Set the end row. */
29405 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29407 /* Compute and set the end column and the end column's horizontal
29408 pixel coordinate. */
29409 if (!r
->reversed_p
)
29411 g
= r
->glyphs
[TEXT_AREA
];
29412 e
= g
+ r
->used
[TEXT_AREA
];
29413 for ( ; e
> g
; --e
)
29414 if (EQ ((e
-1)->object
, object
)
29415 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
29417 hlinfo
->mouse_face_end_col
= e
- g
;
29419 for (gx
= r
->x
; g
< e
; ++g
)
29420 gx
+= g
->pixel_width
;
29421 hlinfo
->mouse_face_end_x
= gx
;
29425 e
= r
->glyphs
[TEXT_AREA
];
29426 g
= e
+ r
->used
[TEXT_AREA
];
29427 for (gx
= r
->x
; e
< g
; ++e
)
29429 if (EQ (e
->object
, object
)
29430 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
29432 gx
+= e
->pixel_width
;
29434 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
29435 hlinfo
->mouse_face_end_x
= gx
;
29439 #ifdef HAVE_WINDOW_SYSTEM
29441 /* See if position X, Y is within a hot-spot of an image. */
29444 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
29446 if (!CONSP (hot_spot
))
29449 if (EQ (XCAR (hot_spot
), Qrect
))
29451 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
29452 Lisp_Object rect
= XCDR (hot_spot
);
29456 if (!CONSP (XCAR (rect
)))
29458 if (!CONSP (XCDR (rect
)))
29460 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
29462 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
29464 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
29466 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
29470 else if (EQ (XCAR (hot_spot
), Qcircle
))
29472 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
29473 Lisp_Object circ
= XCDR (hot_spot
);
29474 Lisp_Object lr
, lx0
, ly0
;
29476 && CONSP (XCAR (circ
))
29477 && (lr
= XCDR (circ
), NUMBERP (lr
))
29478 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
29479 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
29481 double r
= XFLOATINT (lr
);
29482 double dx
= XINT (lx0
) - x
;
29483 double dy
= XINT (ly0
) - y
;
29484 return (dx
* dx
+ dy
* dy
<= r
* r
);
29487 else if (EQ (XCAR (hot_spot
), Qpoly
))
29489 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
29490 if (VECTORP (XCDR (hot_spot
)))
29492 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
29493 Lisp_Object
*poly
= v
->contents
;
29494 ptrdiff_t n
= v
->header
.size
;
29496 bool inside
= false;
29497 Lisp_Object lx
, ly
;
29500 /* Need an even number of coordinates, and at least 3 edges. */
29501 if (n
< 6 || n
& 1)
29504 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
29505 If count is odd, we are inside polygon. Pixels on edges
29506 may or may not be included depending on actual geometry of the
29508 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
29509 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
29511 x0
= XINT (lx
), y0
= XINT (ly
);
29512 for (i
= 0; i
< n
; i
+= 2)
29514 int x1
= x0
, y1
= y0
;
29515 if ((lx
= poly
[i
], !INTEGERP (lx
))
29516 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
29518 x0
= XINT (lx
), y0
= XINT (ly
);
29520 /* Does this segment cross the X line? */
29528 if (y
> y0
&& y
> y1
)
29530 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
29540 find_hot_spot (Lisp_Object map
, int x
, int y
)
29542 while (CONSP (map
))
29544 if (CONSP (XCAR (map
))
29545 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
29553 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
29555 doc
: /* Lookup in image map MAP coordinates X and Y.
29556 An image map is an alist where each element has the format (AREA ID PLIST).
29557 An AREA is specified as either a rectangle, a circle, or a polygon:
29558 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
29559 pixel coordinates of the upper left and bottom right corners.
29560 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
29561 and the radius of the circle; r may be a float or integer.
29562 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
29563 vector describes one corner in the polygon.
29564 Returns the alist element for the first matching AREA in MAP. */)
29565 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
29573 return find_hot_spot (map
,
29574 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
29575 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
29579 /* Display frame CURSOR, optionally using shape defined by POINTER. */
29581 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
29583 /* Do not change cursor shape while dragging mouse. */
29584 if (EQ (do_mouse_tracking
, Qdragging
))
29587 if (!NILP (pointer
))
29589 if (EQ (pointer
, Qarrow
))
29590 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29591 else if (EQ (pointer
, Qhand
))
29592 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
29593 else if (EQ (pointer
, Qtext
))
29594 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
29595 else if (EQ (pointer
, intern ("hdrag")))
29596 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29597 else if (EQ (pointer
, intern ("nhdrag")))
29598 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
29599 #ifdef HAVE_X_WINDOWS
29600 else if (EQ (pointer
, intern ("vdrag")))
29601 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29603 else if (EQ (pointer
, intern ("hourglass")))
29604 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
29605 else if (EQ (pointer
, Qmodeline
))
29606 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
29608 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29611 if (cursor
!= No_Cursor
)
29612 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
29615 #endif /* HAVE_WINDOW_SYSTEM */
29617 /* Take proper action when mouse has moved to the mode or header line
29618 or marginal area AREA of window W, x-position X and y-position Y.
29619 X is relative to the start of the text display area of W, so the
29620 width of bitmap areas and scroll bars must be subtracted to get a
29621 position relative to the start of the mode line. */
29624 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
29625 enum window_part area
)
29627 struct window
*w
= XWINDOW (window
);
29628 struct frame
*f
= XFRAME (w
->frame
);
29629 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29630 #ifdef HAVE_WINDOW_SYSTEM
29631 Display_Info
*dpyinfo
;
29633 Cursor cursor
= No_Cursor
;
29634 Lisp_Object pointer
= Qnil
;
29635 int dx
, dy
, width
, height
;
29637 Lisp_Object string
, object
= Qnil
;
29638 Lisp_Object pos
IF_LINT (= Qnil
), help
;
29640 Lisp_Object mouse_face
;
29641 int original_x_pixel
= x
;
29642 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
29643 struct glyph_row
*row
IF_LINT (= 0);
29645 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
29650 /* Kludge alert: mode_line_string takes X/Y in pixels, but
29651 returns them in row/column units! */
29652 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
29653 &object
, &dx
, &dy
, &width
, &height
);
29655 row
= (area
== ON_MODE_LINE
29656 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
29657 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
29659 /* Find the glyph under the mouse pointer. */
29660 if (row
->mode_line_p
&& row
->enabled_p
)
29662 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
29663 end
= glyph
+ row
->used
[TEXT_AREA
];
29665 for (x0
= original_x_pixel
;
29666 glyph
< end
&& x0
>= glyph
->pixel_width
;
29668 x0
-= glyph
->pixel_width
;
29676 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
29677 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
29678 returns them in row/column units! */
29679 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
29680 &object
, &dx
, &dy
, &width
, &height
);
29685 #ifdef HAVE_WINDOW_SYSTEM
29686 if (IMAGEP (object
))
29688 Lisp_Object image_map
, hotspot
;
29689 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
29691 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
29693 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
29697 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
29698 If so, we could look for mouse-enter, mouse-leave
29699 properties in PLIST (and do something...). */
29700 hotspot
= XCDR (hotspot
);
29701 if (CONSP (hotspot
)
29702 && (plist
= XCAR (hotspot
), CONSP (plist
)))
29704 pointer
= Fplist_get (plist
, Qpointer
);
29705 if (NILP (pointer
))
29707 help
= Fplist_get (plist
, Qhelp_echo
);
29710 help_echo_string
= help
;
29711 XSETWINDOW (help_echo_window
, w
);
29712 help_echo_object
= w
->contents
;
29713 help_echo_pos
= charpos
;
29717 if (NILP (pointer
))
29718 pointer
= Fplist_get (XCDR (object
), QCpointer
);
29720 #endif /* HAVE_WINDOW_SYSTEM */
29722 if (STRINGP (string
))
29723 pos
= make_number (charpos
);
29725 /* Set the help text and mouse pointer. If the mouse is on a part
29726 of the mode line without any text (e.g. past the right edge of
29727 the mode line text), use the default help text and pointer. */
29728 if (STRINGP (string
) || area
== ON_MODE_LINE
)
29730 /* Arrange to display the help by setting the global variables
29731 help_echo_string, help_echo_object, and help_echo_pos. */
29734 if (STRINGP (string
))
29735 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
29739 help_echo_string
= help
;
29740 XSETWINDOW (help_echo_window
, w
);
29741 help_echo_object
= string
;
29742 help_echo_pos
= charpos
;
29744 else if (area
== ON_MODE_LINE
)
29746 Lisp_Object default_help
29747 = buffer_local_value (Qmode_line_default_help_echo
,
29750 if (STRINGP (default_help
))
29752 help_echo_string
= default_help
;
29753 XSETWINDOW (help_echo_window
, w
);
29754 help_echo_object
= Qnil
;
29755 help_echo_pos
= -1;
29760 #ifdef HAVE_WINDOW_SYSTEM
29761 /* Change the mouse pointer according to what is under it. */
29762 if (FRAME_WINDOW_P (f
))
29764 bool draggable
= (! WINDOW_BOTTOMMOST_P (w
)
29766 || NILP (Vresize_mini_windows
));
29768 dpyinfo
= FRAME_DISPLAY_INFO (f
);
29769 if (STRINGP (string
))
29771 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29773 if (NILP (pointer
))
29774 pointer
= Fget_text_property (pos
, Qpointer
, string
);
29776 /* Change the mouse pointer according to what is under X/Y. */
29778 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
29781 map
= Fget_text_property (pos
, Qlocal_map
, string
);
29782 if (!KEYMAPP (map
))
29783 map
= Fget_text_property (pos
, Qkeymap
, string
);
29784 if (!KEYMAPP (map
) && draggable
)
29785 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
29788 else if (draggable
)
29789 /* Default mode-line pointer. */
29790 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29795 /* Change the mouse face according to what is under X/Y. */
29796 bool mouse_face_shown
= false;
29797 if (STRINGP (string
))
29799 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
29800 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
29801 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
29806 struct glyph
* tmp_glyph
;
29810 int total_pixel_width
;
29811 ptrdiff_t begpos
, endpos
, ignore
;
29815 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
29816 Qmouse_face
, string
, Qnil
);
29822 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
29824 endpos
= SCHARS (string
);
29828 /* Calculate the glyph position GPOS of GLYPH in the
29829 displayed string, relative to the beginning of the
29830 highlighted part of the string.
29832 Note: GPOS is different from CHARPOS. CHARPOS is the
29833 position of GLYPH in the internal string object. A mode
29834 line string format has structures which are converted to
29835 a flattened string by the Emacs Lisp interpreter. The
29836 internal string is an element of those structures. The
29837 displayed string is the flattened string. */
29838 tmp_glyph
= row_start_glyph
;
29839 while (tmp_glyph
< glyph
29840 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29841 && begpos
<= tmp_glyph
->charpos
29842 && tmp_glyph
->charpos
< endpos
)))
29844 gpos
= glyph
- tmp_glyph
;
29846 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
29847 the highlighted part of the displayed string to which
29848 GLYPH belongs. Note: GSEQ_LENGTH is different from
29849 SCHARS (STRING), because the latter returns the length of
29850 the internal string. */
29851 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
29853 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29854 && begpos
<= tmp_glyph
->charpos
29855 && tmp_glyph
->charpos
< endpos
));
29858 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
29860 /* Calculate the total pixel width of all the glyphs between
29861 the beginning of the highlighted area and GLYPH. */
29862 total_pixel_width
= 0;
29863 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
29864 total_pixel_width
+= tmp_glyph
->pixel_width
;
29866 /* Pre calculation of re-rendering position. Note: X is in
29867 column units here, after the call to mode_line_string or
29868 marginal_area_string. */
29870 vpos
= (area
== ON_MODE_LINE
29871 ? (w
->current_matrix
)->nrows
- 1
29874 /* If GLYPH's position is included in the region that is
29875 already drawn in mouse face, we have nothing to do. */
29876 if ( EQ (window
, hlinfo
->mouse_face_window
)
29877 && (!row
->reversed_p
29878 ? (hlinfo
->mouse_face_beg_col
<= hpos
29879 && hpos
< hlinfo
->mouse_face_end_col
)
29880 /* In R2L rows we swap BEG and END, see below. */
29881 : (hlinfo
->mouse_face_end_col
<= hpos
29882 && hpos
< hlinfo
->mouse_face_beg_col
))
29883 && hlinfo
->mouse_face_beg_row
== vpos
)
29886 if (clear_mouse_face (hlinfo
))
29887 cursor
= No_Cursor
;
29889 if (!row
->reversed_p
)
29891 hlinfo
->mouse_face_beg_col
= hpos
;
29892 hlinfo
->mouse_face_beg_x
= original_x_pixel
29893 - (total_pixel_width
+ dx
);
29894 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
29895 hlinfo
->mouse_face_end_x
= 0;
29899 /* In R2L rows, show_mouse_face expects BEG and END
29900 coordinates to be swapped. */
29901 hlinfo
->mouse_face_end_col
= hpos
;
29902 hlinfo
->mouse_face_end_x
= original_x_pixel
29903 - (total_pixel_width
+ dx
);
29904 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
29905 hlinfo
->mouse_face_beg_x
= 0;
29908 hlinfo
->mouse_face_beg_row
= vpos
;
29909 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
29910 hlinfo
->mouse_face_past_end
= false;
29911 hlinfo
->mouse_face_window
= window
;
29913 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
29918 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29919 mouse_face_shown
= true;
29921 if (NILP (pointer
))
29926 /* If mouse-face doesn't need to be shown, clear any existing
29928 if ((area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
) && !mouse_face_shown
)
29929 clear_mouse_face (hlinfo
);
29931 #ifdef HAVE_WINDOW_SYSTEM
29932 if (FRAME_WINDOW_P (f
))
29933 define_frame_cursor1 (f
, cursor
, pointer
);
29939 Take proper action when the mouse has moved to position X, Y on
29940 frame F with regards to highlighting portions of display that have
29941 mouse-face properties. Also de-highlight portions of display where
29942 the mouse was before, set the mouse pointer shape as appropriate
29943 for the mouse coordinates, and activate help echo (tooltips).
29944 X and Y can be negative or out of range. */
29947 note_mouse_highlight (struct frame
*f
, int x
, int y
)
29949 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29950 enum window_part part
= ON_NOTHING
;
29951 Lisp_Object window
;
29953 Cursor cursor
= No_Cursor
;
29954 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
29957 /* When a menu is active, don't highlight because this looks odd. */
29958 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
29959 if (popup_activated ())
29963 if (!f
->glyphs_initialized_p
29964 || f
->pointer_invisible
)
29967 hlinfo
->mouse_face_mouse_x
= x
;
29968 hlinfo
->mouse_face_mouse_y
= y
;
29969 hlinfo
->mouse_face_mouse_frame
= f
;
29971 if (hlinfo
->mouse_face_defer
)
29974 /* Which window is that in? */
29975 window
= window_from_coordinates (f
, x
, y
, &part
, true);
29977 /* If displaying active text in another window, clear that. */
29978 if (! EQ (window
, hlinfo
->mouse_face_window
)
29979 /* Also clear if we move out of text area in same window. */
29980 || (!NILP (hlinfo
->mouse_face_window
)
29983 && part
!= ON_MODE_LINE
29984 && part
!= ON_HEADER_LINE
))
29985 clear_mouse_face (hlinfo
);
29987 /* Not on a window -> return. */
29988 if (!WINDOWP (window
))
29991 /* Reset help_echo_string. It will get recomputed below. */
29992 help_echo_string
= Qnil
;
29994 /* Convert to window-relative pixel coordinates. */
29995 w
= XWINDOW (window
);
29996 frame_to_window_pixel_xy (w
, &x
, &y
);
29998 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
29999 /* Handle tool-bar window differently since it doesn't display a
30001 if (EQ (window
, f
->tool_bar_window
))
30003 note_tool_bar_highlight (f
, x
, y
);
30008 /* Mouse is on the mode, header line or margin? */
30009 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
30010 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
30012 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
30014 #ifdef HAVE_WINDOW_SYSTEM
30015 if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
30017 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30018 /* Show non-text cursor (Bug#16647). */
30026 #ifdef HAVE_WINDOW_SYSTEM
30027 if (part
== ON_VERTICAL_BORDER
)
30029 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
30030 help_echo_string
= build_string ("drag-mouse-1: resize");
30032 else if (part
== ON_RIGHT_DIVIDER
)
30034 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
30035 help_echo_string
= build_string ("drag-mouse-1: resize");
30037 else if (part
== ON_BOTTOM_DIVIDER
)
30038 if (! WINDOW_BOTTOMMOST_P (w
)
30040 || NILP (Vresize_mini_windows
))
30042 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
30043 help_echo_string
= build_string ("drag-mouse-1: resize");
30046 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30047 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
30048 || part
== ON_VERTICAL_SCROLL_BAR
30049 || part
== ON_HORIZONTAL_SCROLL_BAR
)
30050 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30052 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
30055 /* Are we in a window whose display is up to date?
30056 And verify the buffer's text has not changed. */
30057 b
= XBUFFER (w
->contents
);
30058 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
30060 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
30062 struct glyph
*glyph
;
30063 Lisp_Object object
;
30064 Lisp_Object mouse_face
= Qnil
, position
;
30065 Lisp_Object
*overlay_vec
= NULL
;
30066 ptrdiff_t i
, noverlays
;
30067 struct buffer
*obuf
;
30068 ptrdiff_t obegv
, ozv
;
30071 /* Find the glyph under X/Y. */
30072 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
30074 #ifdef HAVE_WINDOW_SYSTEM
30075 /* Look for :pointer property on image. */
30076 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
30078 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
30079 if (img
!= NULL
&& IMAGEP (img
->spec
))
30081 Lisp_Object image_map
, hotspot
;
30082 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
30084 && (hotspot
= find_hot_spot (image_map
,
30085 glyph
->slice
.img
.x
+ dx
,
30086 glyph
->slice
.img
.y
+ dy
),
30088 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
30092 /* Could check XCAR (hotspot) to see if we enter/leave
30094 If so, we could look for mouse-enter, mouse-leave
30095 properties in PLIST (and do something...). */
30096 hotspot
= XCDR (hotspot
);
30097 if (CONSP (hotspot
)
30098 && (plist
= XCAR (hotspot
), CONSP (plist
)))
30100 pointer
= Fplist_get (plist
, Qpointer
);
30101 if (NILP (pointer
))
30103 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
30104 if (!NILP (help_echo_string
))
30106 help_echo_window
= window
;
30107 help_echo_object
= glyph
->object
;
30108 help_echo_pos
= glyph
->charpos
;
30112 if (NILP (pointer
))
30113 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
30116 #endif /* HAVE_WINDOW_SYSTEM */
30118 /* Clear mouse face if X/Y not over text. */
30120 || area
!= TEXT_AREA
30121 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
30122 /* Glyph's OBJECT is nil for glyphs inserted by the
30123 display engine for its internal purposes, like truncation
30124 and continuation glyphs and blanks beyond the end of
30125 line's text on text terminals. If we are over such a
30126 glyph, we are not over any text. */
30127 || NILP (glyph
->object
)
30128 /* R2L rows have a stretch glyph at their front, which
30129 stands for no text, whereas L2R rows have no glyphs at
30130 all beyond the end of text. Treat such stretch glyphs
30131 like we do with NULL glyphs in L2R rows. */
30132 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
30133 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
30134 && glyph
->type
== STRETCH_GLYPH
30135 && glyph
->avoid_cursor_p
))
30137 if (clear_mouse_face (hlinfo
))
30138 cursor
= No_Cursor
;
30139 #ifdef HAVE_WINDOW_SYSTEM
30140 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
30142 if (area
!= TEXT_AREA
)
30143 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30145 pointer
= Vvoid_text_area_pointer
;
30151 pos
= glyph
->charpos
;
30152 object
= glyph
->object
;
30153 if (!STRINGP (object
) && !BUFFERP (object
))
30156 /* If we get an out-of-range value, return now; avoid an error. */
30157 if (BUFFERP (object
) && pos
> BUF_Z (b
))
30160 /* Make the window's buffer temporarily current for
30161 overlays_at and compute_char_face. */
30162 obuf
= current_buffer
;
30163 current_buffer
= b
;
30169 /* Is this char mouse-active or does it have help-echo? */
30170 position
= make_number (pos
);
30174 if (BUFFERP (object
))
30176 /* Put all the overlays we want in a vector in overlay_vec. */
30177 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, false);
30178 /* Sort overlays into increasing priority order. */
30179 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
30184 if (NILP (Vmouse_highlight
))
30186 clear_mouse_face (hlinfo
);
30187 goto check_help_echo
;
30190 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
30193 cursor
= No_Cursor
;
30195 /* Check mouse-face highlighting. */
30197 /* If there exists an overlay with mouse-face overlapping
30198 the one we are currently highlighting, we have to
30199 check if we enter the overlapping overlay, and then
30200 highlight only that. */
30201 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
30202 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
30204 /* Find the highest priority overlay with a mouse-face. */
30205 Lisp_Object overlay
= Qnil
;
30206 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
30208 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
30209 if (!NILP (mouse_face
))
30210 overlay
= overlay_vec
[i
];
30213 /* If we're highlighting the same overlay as before, there's
30214 no need to do that again. */
30215 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
30216 goto check_help_echo
;
30217 hlinfo
->mouse_face_overlay
= overlay
;
30219 /* Clear the display of the old active region, if any. */
30220 if (clear_mouse_face (hlinfo
))
30221 cursor
= No_Cursor
;
30223 /* If no overlay applies, get a text property. */
30224 if (NILP (overlay
))
30225 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
30227 /* Next, compute the bounds of the mouse highlighting and
30229 if (!NILP (mouse_face
) && STRINGP (object
))
30231 /* The mouse-highlighting comes from a display string
30232 with a mouse-face. */
30236 s
= Fprevious_single_property_change
30237 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
30238 e
= Fnext_single_property_change
30239 (position
, Qmouse_face
, object
, Qnil
);
30241 s
= make_number (0);
30243 e
= make_number (SCHARS (object
));
30244 mouse_face_from_string_pos (w
, hlinfo
, object
,
30245 XINT (s
), XINT (e
));
30246 hlinfo
->mouse_face_past_end
= false;
30247 hlinfo
->mouse_face_window
= window
;
30248 hlinfo
->mouse_face_face_id
30249 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
30250 glyph
->face_id
, true);
30251 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
30252 cursor
= No_Cursor
;
30256 /* The mouse-highlighting, if any, comes from an overlay
30257 or text property in the buffer. */
30258 Lisp_Object buffer
IF_LINT (= Qnil
);
30259 Lisp_Object disp_string
IF_LINT (= Qnil
);
30261 if (STRINGP (object
))
30263 /* If we are on a display string with no mouse-face,
30264 check if the text under it has one. */
30265 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
30266 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30267 pos
= string_buffer_position (object
, start
);
30270 mouse_face
= get_char_property_and_overlay
30271 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
30272 buffer
= w
->contents
;
30273 disp_string
= object
;
30279 disp_string
= Qnil
;
30282 if (!NILP (mouse_face
))
30284 Lisp_Object before
, after
;
30285 Lisp_Object before_string
, after_string
;
30286 /* To correctly find the limits of mouse highlight
30287 in a bidi-reordered buffer, we must not use the
30288 optimization of limiting the search in
30289 previous-single-property-change and
30290 next-single-property-change, because
30291 rows_from_pos_range needs the real start and end
30292 positions to DTRT in this case. That's because
30293 the first row visible in a window does not
30294 necessarily display the character whose position
30295 is the smallest. */
30297 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
30298 ? Fmarker_position (w
->start
)
30301 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
30302 ? make_number (BUF_Z (XBUFFER (buffer
))
30303 - w
->window_end_pos
)
30306 if (NILP (overlay
))
30308 /* Handle the text property case. */
30309 before
= Fprevious_single_property_change
30310 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
30311 after
= Fnext_single_property_change
30312 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
30313 before_string
= after_string
= Qnil
;
30317 /* Handle the overlay case. */
30318 before
= Foverlay_start (overlay
);
30319 after
= Foverlay_end (overlay
);
30320 before_string
= Foverlay_get (overlay
, Qbefore_string
);
30321 after_string
= Foverlay_get (overlay
, Qafter_string
);
30323 if (!STRINGP (before_string
)) before_string
= Qnil
;
30324 if (!STRINGP (after_string
)) after_string
= Qnil
;
30327 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
30330 : XFASTINT (before
),
30332 ? BUF_Z (XBUFFER (buffer
))
30333 : XFASTINT (after
),
30334 before_string
, after_string
,
30336 cursor
= No_Cursor
;
30343 /* Look for a `help-echo' property. */
30344 if (NILP (help_echo_string
)) {
30345 Lisp_Object help
, overlay
;
30347 /* Check overlays first. */
30348 help
= overlay
= Qnil
;
30349 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
30351 overlay
= overlay_vec
[i
];
30352 help
= Foverlay_get (overlay
, Qhelp_echo
);
30357 help_echo_string
= help
;
30358 help_echo_window
= window
;
30359 help_echo_object
= overlay
;
30360 help_echo_pos
= pos
;
30364 Lisp_Object obj
= glyph
->object
;
30365 ptrdiff_t charpos
= glyph
->charpos
;
30367 /* Try text properties. */
30370 && charpos
< SCHARS (obj
))
30372 help
= Fget_text_property (make_number (charpos
),
30376 /* If the string itself doesn't specify a help-echo,
30377 see if the buffer text ``under'' it does. */
30378 struct glyph_row
*r
30379 = MATRIX_ROW (w
->current_matrix
, vpos
);
30380 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30381 ptrdiff_t p
= string_buffer_position (obj
, start
);
30384 help
= Fget_char_property (make_number (p
),
30385 Qhelp_echo
, w
->contents
);
30394 else if (BUFFERP (obj
)
30397 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
30402 help_echo_string
= help
;
30403 help_echo_window
= window
;
30404 help_echo_object
= obj
;
30405 help_echo_pos
= charpos
;
30410 #ifdef HAVE_WINDOW_SYSTEM
30411 /* Look for a `pointer' property. */
30412 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
30414 /* Check overlays first. */
30415 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
30416 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
30418 if (NILP (pointer
))
30420 Lisp_Object obj
= glyph
->object
;
30421 ptrdiff_t charpos
= glyph
->charpos
;
30423 /* Try text properties. */
30426 && charpos
< SCHARS (obj
))
30428 pointer
= Fget_text_property (make_number (charpos
),
30430 if (NILP (pointer
))
30432 /* If the string itself doesn't specify a pointer,
30433 see if the buffer text ``under'' it does. */
30434 struct glyph_row
*r
30435 = MATRIX_ROW (w
->current_matrix
, vpos
);
30436 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30437 ptrdiff_t p
= string_buffer_position (obj
, start
);
30439 pointer
= Fget_char_property (make_number (p
),
30440 Qpointer
, w
->contents
);
30443 else if (BUFFERP (obj
)
30446 pointer
= Fget_text_property (make_number (charpos
),
30450 #endif /* HAVE_WINDOW_SYSTEM */
30454 current_buffer
= obuf
;
30460 #ifdef HAVE_WINDOW_SYSTEM
30461 if (FRAME_WINDOW_P (f
))
30462 define_frame_cursor1 (f
, cursor
, pointer
);
30464 /* This is here to prevent a compiler error, about "label at end of
30465 compound statement". */
30472 Clear any mouse-face on window W. This function is part of the
30473 redisplay interface, and is called from try_window_id and similar
30474 functions to ensure the mouse-highlight is off. */
30477 x_clear_window_mouse_face (struct window
*w
)
30479 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
30480 Lisp_Object window
;
30483 XSETWINDOW (window
, w
);
30484 if (EQ (window
, hlinfo
->mouse_face_window
))
30485 clear_mouse_face (hlinfo
);
30491 Just discard the mouse face information for frame F, if any.
30492 This is used when the size of F is changed. */
30495 cancel_mouse_face (struct frame
*f
)
30497 Lisp_Object window
;
30498 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
30500 window
= hlinfo
->mouse_face_window
;
30501 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
30502 reset_mouse_highlight (hlinfo
);
30507 /***********************************************************************
30509 ***********************************************************************/
30511 #ifdef HAVE_WINDOW_SYSTEM
30513 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
30514 which intersects rectangle R. R is in window-relative coordinates. */
30517 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
30518 enum glyph_row_area area
)
30520 struct glyph
*first
= row
->glyphs
[area
];
30521 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
30522 struct glyph
*last
;
30523 int first_x
, start_x
, x
;
30525 if (area
== TEXT_AREA
&& row
->fill_line_p
)
30526 /* If row extends face to end of line write the whole line. */
30527 draw_glyphs (w
, 0, row
, area
,
30528 0, row
->used
[area
],
30529 DRAW_NORMAL_TEXT
, 0);
30532 /* Set START_X to the window-relative start position for drawing glyphs of
30533 AREA. The first glyph of the text area can be partially visible.
30534 The first glyphs of other areas cannot. */
30535 start_x
= window_box_left_offset (w
, area
);
30537 if (area
== TEXT_AREA
)
30540 /* Find the first glyph that must be redrawn. */
30542 && x
+ first
->pixel_width
< r
->x
)
30544 x
+= first
->pixel_width
;
30548 /* Find the last one. */
30551 /* Use a signed int intermediate value to avoid catastrophic
30552 failures due to comparison between signed and unsigned, when
30553 x is negative (can happen for wide images that are hscrolled). */
30554 int r_end
= r
->x
+ r
->width
;
30555 while (last
< end
&& x
< r_end
)
30557 x
+= last
->pixel_width
;
30563 draw_glyphs (w
, first_x
- start_x
, row
, area
,
30564 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
30565 DRAW_NORMAL_TEXT
, 0);
30570 /* Redraw the parts of the glyph row ROW on window W intersecting
30571 rectangle R. R is in window-relative coordinates. Value is
30572 true if mouse-face was overwritten. */
30575 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
30577 eassert (row
->enabled_p
);
30579 if (row
->mode_line_p
|| w
->pseudo_window_p
)
30580 draw_glyphs (w
, 0, row
, TEXT_AREA
,
30581 0, row
->used
[TEXT_AREA
],
30582 DRAW_NORMAL_TEXT
, 0);
30585 if (row
->used
[LEFT_MARGIN_AREA
])
30586 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
30587 if (row
->used
[TEXT_AREA
])
30588 expose_area (w
, row
, r
, TEXT_AREA
);
30589 if (row
->used
[RIGHT_MARGIN_AREA
])
30590 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
30591 draw_row_fringe_bitmaps (w
, row
);
30594 return row
->mouse_face_p
;
30598 /* Redraw those parts of glyphs rows during expose event handling that
30599 overlap other rows. Redrawing of an exposed line writes over parts
30600 of lines overlapping that exposed line; this function fixes that.
30602 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
30603 row in W's current matrix that is exposed and overlaps other rows.
30604 LAST_OVERLAPPING_ROW is the last such row. */
30607 expose_overlaps (struct window
*w
,
30608 struct glyph_row
*first_overlapping_row
,
30609 struct glyph_row
*last_overlapping_row
,
30612 struct glyph_row
*row
;
30614 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
30615 if (row
->overlapping_p
)
30617 eassert (row
->enabled_p
&& !row
->mode_line_p
);
30620 if (row
->used
[LEFT_MARGIN_AREA
])
30621 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
30623 if (row
->used
[TEXT_AREA
])
30624 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
30626 if (row
->used
[RIGHT_MARGIN_AREA
])
30627 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
30633 /* Return true if W's cursor intersects rectangle R. */
30636 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
30638 XRectangle cr
, result
;
30639 struct glyph
*cursor_glyph
;
30640 struct glyph_row
*row
;
30642 if (w
->phys_cursor
.vpos
>= 0
30643 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
30644 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
30646 && row
->cursor_in_fringe_p
)
30648 /* Cursor is in the fringe. */
30649 cr
.x
= window_box_right_offset (w
,
30650 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
30651 ? RIGHT_MARGIN_AREA
30654 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
30655 cr
.height
= row
->height
;
30656 return x_intersect_rectangles (&cr
, r
, &result
);
30659 cursor_glyph
= get_phys_cursor_glyph (w
);
30662 /* r is relative to W's box, but w->phys_cursor.x is relative
30663 to left edge of W's TEXT area. Adjust it. */
30664 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
30665 cr
.y
= w
->phys_cursor
.y
;
30666 cr
.width
= cursor_glyph
->pixel_width
;
30667 cr
.height
= w
->phys_cursor_height
;
30668 /* ++KFS: W32 version used W32-specific IntersectRect here, but
30669 I assume the effect is the same -- and this is portable. */
30670 return x_intersect_rectangles (&cr
, r
, &result
);
30672 /* If we don't understand the format, pretend we're not in the hot-spot. */
30678 Draw a vertical window border to the right of window W if W doesn't
30679 have vertical scroll bars. */
30682 x_draw_vertical_border (struct window
*w
)
30684 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30686 /* We could do better, if we knew what type of scroll-bar the adjacent
30687 windows (on either side) have... But we don't :-(
30688 However, I think this works ok. ++KFS 2003-04-25 */
30690 /* Redraw borders between horizontally adjacent windows. Don't
30691 do it for frames with vertical scroll bars because either the
30692 right scroll bar of a window, or the left scroll bar of its
30693 neighbor will suffice as a border. */
30694 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
30697 /* Note: It is necessary to redraw both the left and the right
30698 borders, for when only this single window W is being
30700 if (!WINDOW_RIGHTMOST_P (w
)
30701 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
30703 int x0
, x1
, y0
, y1
;
30705 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30708 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30711 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
30714 if (!WINDOW_LEFTMOST_P (w
)
30715 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
30717 int x0
, x1
, y0
, y1
;
30719 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30722 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30725 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
30730 /* Draw window dividers for window W. */
30733 x_draw_right_divider (struct window
*w
)
30735 struct frame
*f
= WINDOW_XFRAME (w
);
30737 if (w
->mini
|| w
->pseudo_window_p
)
30739 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30741 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
30742 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30743 int y0
= WINDOW_TOP_EDGE_Y (w
);
30744 /* The bottom divider prevails. */
30745 int y1
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30747 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30752 x_draw_bottom_divider (struct window
*w
)
30754 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30756 if (w
->mini
|| w
->pseudo_window_p
)
30758 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30760 int x0
= WINDOW_LEFT_EDGE_X (w
);
30761 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30762 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30763 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
30765 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30769 /* Redraw the part of window W intersection rectangle FR. Pixel
30770 coordinates in FR are frame-relative. Call this function with
30771 input blocked. Value is true if the exposure overwrites
30775 expose_window (struct window
*w
, XRectangle
*fr
)
30777 struct frame
*f
= XFRAME (w
->frame
);
30779 bool mouse_face_overwritten_p
= false;
30781 /* If window is not yet fully initialized, do nothing. This can
30782 happen when toolkit scroll bars are used and a window is split.
30783 Reconfiguring the scroll bar will generate an expose for a newly
30785 if (w
->current_matrix
== NULL
)
30788 /* When we're currently updating the window, display and current
30789 matrix usually don't agree. Arrange for a thorough display
30791 if (w
->must_be_updated_p
)
30793 SET_FRAME_GARBAGED (f
);
30797 /* Frame-relative pixel rectangle of W. */
30798 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
30799 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
30800 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
30801 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
30803 if (x_intersect_rectangles (fr
, &wr
, &r
))
30805 int yb
= window_text_bottom_y (w
);
30806 struct glyph_row
*row
;
30807 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
30809 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
30810 r
.x
, r
.y
, r
.width
, r
.height
));
30812 /* Convert to window coordinates. */
30813 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
30814 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
30816 /* Turn off the cursor. */
30817 bool cursor_cleared_p
= (!w
->pseudo_window_p
30818 && phys_cursor_in_rect_p (w
, &r
));
30819 if (cursor_cleared_p
)
30820 x_clear_cursor (w
);
30822 /* If the row containing the cursor extends face to end of line,
30823 then expose_area might overwrite the cursor outside the
30824 rectangle and thus notice_overwritten_cursor might clear
30825 w->phys_cursor_on_p. We remember the original value and
30826 check later if it is changed. */
30827 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
30829 /* Use a signed int intermediate value to avoid catastrophic
30830 failures due to comparison between signed and unsigned, when
30831 y0 or y1 is negative (can happen for tall images). */
30832 int r_bottom
= r
.y
+ r
.height
;
30834 /* Update lines intersecting rectangle R. */
30835 first_overlapping_row
= last_overlapping_row
= NULL
;
30836 for (row
= w
->current_matrix
->rows
;
30841 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
30843 if ((y0
>= r
.y
&& y0
< r_bottom
)
30844 || (y1
> r
.y
&& y1
< r_bottom
)
30845 || (r
.y
>= y0
&& r
.y
< y1
)
30846 || (r_bottom
> y0
&& r_bottom
< y1
))
30848 /* A header line may be overlapping, but there is no need
30849 to fix overlapping areas for them. KFS 2005-02-12 */
30850 if (row
->overlapping_p
&& !row
->mode_line_p
)
30852 if (first_overlapping_row
== NULL
)
30853 first_overlapping_row
= row
;
30854 last_overlapping_row
= row
;
30858 if (expose_line (w
, row
, &r
))
30859 mouse_face_overwritten_p
= true;
30862 else if (row
->overlapping_p
)
30864 /* We must redraw a row overlapping the exposed area. */
30866 ? y0
+ row
->phys_height
> r
.y
30867 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
30869 if (first_overlapping_row
== NULL
)
30870 first_overlapping_row
= row
;
30871 last_overlapping_row
= row
;
30879 /* Display the mode line if there is one. */
30880 if (WINDOW_WANTS_MODELINE_P (w
)
30881 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
30883 && row
->y
< r_bottom
)
30885 if (expose_line (w
, row
, &r
))
30886 mouse_face_overwritten_p
= true;
30889 if (!w
->pseudo_window_p
)
30891 /* Fix the display of overlapping rows. */
30892 if (first_overlapping_row
)
30893 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
30896 /* Draw border between windows. */
30897 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30898 x_draw_right_divider (w
);
30900 x_draw_vertical_border (w
);
30902 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30903 x_draw_bottom_divider (w
);
30905 /* Turn the cursor on again. */
30906 if (cursor_cleared_p
30907 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
30908 update_window_cursor (w
, true);
30912 return mouse_face_overwritten_p
;
30917 /* Redraw (parts) of all windows in the window tree rooted at W that
30918 intersect R. R contains frame pixel coordinates. Value is
30919 true if the exposure overwrites mouse-face. */
30922 expose_window_tree (struct window
*w
, XRectangle
*r
)
30924 struct frame
*f
= XFRAME (w
->frame
);
30925 bool mouse_face_overwritten_p
= false;
30927 while (w
&& !FRAME_GARBAGED_P (f
))
30929 mouse_face_overwritten_p
30930 |= (WINDOWP (w
->contents
)
30931 ? expose_window_tree (XWINDOW (w
->contents
), r
)
30932 : expose_window (w
, r
));
30934 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
30937 return mouse_face_overwritten_p
;
30942 Redisplay an exposed area of frame F. X and Y are the upper-left
30943 corner of the exposed rectangle. W and H are width and height of
30944 the exposed area. All are pixel values. W or H zero means redraw
30945 the entire frame. */
30948 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
30951 bool mouse_face_overwritten_p
= false;
30953 TRACE ((stderr
, "expose_frame "));
30955 /* No need to redraw if frame will be redrawn soon. */
30956 if (FRAME_GARBAGED_P (f
))
30958 TRACE ((stderr
, " garbaged\n"));
30962 /* If basic faces haven't been realized yet, there is no point in
30963 trying to redraw anything. This can happen when we get an expose
30964 event while Emacs is starting, e.g. by moving another window. */
30965 if (FRAME_FACE_CACHE (f
) == NULL
30966 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
30968 TRACE ((stderr
, " no faces\n"));
30972 if (w
== 0 || h
== 0)
30975 r
.width
= FRAME_TEXT_WIDTH (f
);
30976 r
.height
= FRAME_TEXT_HEIGHT (f
);
30986 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
30987 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
30989 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
30990 if (WINDOWP (f
->tool_bar_window
))
30991 mouse_face_overwritten_p
30992 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
30995 #ifdef HAVE_X_WINDOWS
30997 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
30998 if (WINDOWP (f
->menu_bar_window
))
30999 mouse_face_overwritten_p
31000 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
31001 #endif /* not USE_X_TOOLKIT and not USE_GTK */
31005 /* Some window managers support a focus-follows-mouse style with
31006 delayed raising of frames. Imagine a partially obscured frame,
31007 and moving the mouse into partially obscured mouse-face on that
31008 frame. The visible part of the mouse-face will be highlighted,
31009 then the WM raises the obscured frame. With at least one WM, KDE
31010 2.1, Emacs is not getting any event for the raising of the frame
31011 (even tried with SubstructureRedirectMask), only Expose events.
31012 These expose events will draw text normally, i.e. not
31013 highlighted. Which means we must redo the highlight here.
31014 Subsume it under ``we love X''. --gerd 2001-08-15 */
31015 /* Included in Windows version because Windows most likely does not
31016 do the right thing if any third party tool offers
31017 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
31018 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
31020 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
31021 if (f
== hlinfo
->mouse_face_mouse_frame
)
31023 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
31024 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
31025 clear_mouse_face (hlinfo
);
31026 note_mouse_highlight (f
, mouse_x
, mouse_y
);
31033 Determine the intersection of two rectangles R1 and R2. Return
31034 the intersection in *RESULT. Value is true if RESULT is not
31038 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
31040 XRectangle
*left
, *right
;
31041 XRectangle
*upper
, *lower
;
31042 bool intersection_p
= false;
31044 /* Rearrange so that R1 is the left-most rectangle. */
31046 left
= r1
, right
= r2
;
31048 left
= r2
, right
= r1
;
31050 /* X0 of the intersection is right.x0, if this is inside R1,
31051 otherwise there is no intersection. */
31052 if (right
->x
<= left
->x
+ left
->width
)
31054 result
->x
= right
->x
;
31056 /* The right end of the intersection is the minimum of
31057 the right ends of left and right. */
31058 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
31061 /* Same game for Y. */
31063 upper
= r1
, lower
= r2
;
31065 upper
= r2
, lower
= r1
;
31067 /* The upper end of the intersection is lower.y0, if this is inside
31068 of upper. Otherwise, there is no intersection. */
31069 if (lower
->y
<= upper
->y
+ upper
->height
)
31071 result
->y
= lower
->y
;
31073 /* The lower end of the intersection is the minimum of the lower
31074 ends of upper and lower. */
31075 result
->height
= (min (lower
->y
+ lower
->height
,
31076 upper
->y
+ upper
->height
)
31078 intersection_p
= true;
31082 return intersection_p
;
31085 #endif /* HAVE_WINDOW_SYSTEM */
31088 /***********************************************************************
31090 ***********************************************************************/
31093 syms_of_xdisp (void)
31095 Vwith_echo_area_save_vector
= Qnil
;
31096 staticpro (&Vwith_echo_area_save_vector
);
31098 Vmessage_stack
= Qnil
;
31099 staticpro (&Vmessage_stack
);
31101 /* Non-nil means don't actually do any redisplay. */
31102 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
31104 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
31106 DEFVAR_BOOL("inhibit-message", inhibit_message
,
31107 doc
: /* Non-nil means calls to `message' are not displayed.
31108 They are still logged to the *Messages* buffer. */);
31109 inhibit_message
= 0;
31111 message_dolog_marker1
= Fmake_marker ();
31112 staticpro (&message_dolog_marker1
);
31113 message_dolog_marker2
= Fmake_marker ();
31114 staticpro (&message_dolog_marker2
);
31115 message_dolog_marker3
= Fmake_marker ();
31116 staticpro (&message_dolog_marker3
);
31119 defsubr (&Sdump_frame_glyph_matrix
);
31120 defsubr (&Sdump_glyph_matrix
);
31121 defsubr (&Sdump_glyph_row
);
31122 defsubr (&Sdump_tool_bar_row
);
31123 defsubr (&Strace_redisplay
);
31124 defsubr (&Strace_to_stderr
);
31126 #ifdef HAVE_WINDOW_SYSTEM
31127 defsubr (&Stool_bar_height
);
31128 defsubr (&Slookup_image_map
);
31130 defsubr (&Sline_pixel_height
);
31131 defsubr (&Sformat_mode_line
);
31132 defsubr (&Sinvisible_p
);
31133 defsubr (&Scurrent_bidi_paragraph_direction
);
31134 defsubr (&Swindow_text_pixel_size
);
31135 defsubr (&Smove_point_visually
);
31136 defsubr (&Sbidi_find_overridden_directionality
);
31138 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
31139 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
31140 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
31141 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
31142 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
31143 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
31144 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
31145 DEFSYM (Qeval
, "eval");
31146 DEFSYM (QCdata
, ":data");
31148 /* Names of text properties relevant for redisplay. */
31149 DEFSYM (Qdisplay
, "display");
31150 DEFSYM (Qspace_width
, "space-width");
31151 DEFSYM (Qraise
, "raise");
31152 DEFSYM (Qslice
, "slice");
31153 DEFSYM (Qspace
, "space");
31154 DEFSYM (Qmargin
, "margin");
31155 DEFSYM (Qpointer
, "pointer");
31156 DEFSYM (Qleft_margin
, "left-margin");
31157 DEFSYM (Qright_margin
, "right-margin");
31158 DEFSYM (Qcenter
, "center");
31159 DEFSYM (Qline_height
, "line-height");
31160 DEFSYM (QCalign_to
, ":align-to");
31161 DEFSYM (QCrelative_width
, ":relative-width");
31162 DEFSYM (QCrelative_height
, ":relative-height");
31163 DEFSYM (QCeval
, ":eval");
31164 DEFSYM (QCpropertize
, ":propertize");
31165 DEFSYM (QCfile
, ":file");
31166 DEFSYM (Qfontified
, "fontified");
31167 DEFSYM (Qfontification_functions
, "fontification-functions");
31169 /* Name of the face used to highlight trailing whitespace. */
31170 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
31172 /* Name and number of the face used to highlight escape glyphs. */
31173 DEFSYM (Qescape_glyph
, "escape-glyph");
31175 /* Name and number of the face used to highlight non-breaking spaces. */
31176 DEFSYM (Qnobreak_space
, "nobreak-space");
31178 /* The symbol 'image' which is the car of the lists used to represent
31179 images in Lisp. Also a tool bar style. */
31180 DEFSYM (Qimage
, "image");
31182 /* Tool bar styles. */
31183 DEFSYM (Qtext
, "text");
31184 DEFSYM (Qboth
, "both");
31185 DEFSYM (Qboth_horiz
, "both-horiz");
31186 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
31188 /* The image map types. */
31189 DEFSYM (QCmap
, ":map");
31190 DEFSYM (QCpointer
, ":pointer");
31191 DEFSYM (Qrect
, "rect");
31192 DEFSYM (Qcircle
, "circle");
31193 DEFSYM (Qpoly
, "poly");
31195 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
31197 DEFSYM (Qgrow_only
, "grow-only");
31198 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
31199 DEFSYM (Qposition
, "position");
31200 DEFSYM (Qbuffer_position
, "buffer-position");
31201 DEFSYM (Qobject
, "object");
31203 /* Cursor shapes. */
31204 DEFSYM (Qbar
, "bar");
31205 DEFSYM (Qhbar
, "hbar");
31206 DEFSYM (Qbox
, "box");
31207 DEFSYM (Qhollow
, "hollow");
31209 /* Pointer shapes. */
31210 DEFSYM (Qhand
, "hand");
31211 DEFSYM (Qarrow
, "arrow");
31214 DEFSYM (Qdragging
, "dragging");
31216 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
31218 list_of_error
= list1 (list2 (Qerror
, Qvoid_variable
));
31219 staticpro (&list_of_error
);
31221 /* Values of those variables at last redisplay are stored as
31222 properties on 'overlay-arrow-position' symbol. However, if
31223 Voverlay_arrow_position is a marker, last-arrow-position is its
31224 numerical position. */
31225 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
31226 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
31228 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
31229 properties on a symbol in overlay-arrow-variable-list. */
31230 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
31231 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
31233 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
31234 staticpro (&echo_buffer
[0]);
31235 staticpro (&echo_buffer
[1]);
31237 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
31238 staticpro (&echo_area_buffer
[0]);
31239 staticpro (&echo_area_buffer
[1]);
31241 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
31242 staticpro (&Vmessages_buffer_name
);
31244 mode_line_proptrans_alist
= Qnil
;
31245 staticpro (&mode_line_proptrans_alist
);
31246 mode_line_string_list
= Qnil
;
31247 staticpro (&mode_line_string_list
);
31248 mode_line_string_face
= Qnil
;
31249 staticpro (&mode_line_string_face
);
31250 mode_line_string_face_prop
= Qnil
;
31251 staticpro (&mode_line_string_face_prop
);
31252 Vmode_line_unwind_vector
= Qnil
;
31253 staticpro (&Vmode_line_unwind_vector
);
31255 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
31257 help_echo_string
= Qnil
;
31258 staticpro (&help_echo_string
);
31259 help_echo_object
= Qnil
;
31260 staticpro (&help_echo_object
);
31261 help_echo_window
= Qnil
;
31262 staticpro (&help_echo_window
);
31263 previous_help_echo_string
= Qnil
;
31264 staticpro (&previous_help_echo_string
);
31265 help_echo_pos
= -1;
31267 DEFSYM (Qright_to_left
, "right-to-left");
31268 DEFSYM (Qleft_to_right
, "left-to-right");
31269 defsubr (&Sbidi_resolved_levels
);
31271 #ifdef HAVE_WINDOW_SYSTEM
31272 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
31273 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
31274 For example, if a block cursor is over a tab, it will be drawn as
31275 wide as that tab on the display. */);
31276 x_stretch_cursor_p
= 0;
31279 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
31280 doc
: /* Non-nil means highlight trailing whitespace.
31281 The face used for trailing whitespace is `trailing-whitespace'. */);
31282 Vshow_trailing_whitespace
= Qnil
;
31284 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
31285 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
31286 If the value is t, Emacs highlights non-ASCII chars which have the
31287 same appearance as an ASCII space or hyphen, using the `nobreak-space'
31288 or `escape-glyph' face respectively.
31290 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
31291 U+2011 (non-breaking hyphen) are affected.
31293 Any other non-nil value means to display these characters as a escape
31294 glyph followed by an ordinary space or hyphen.
31296 A value of nil means no special handling of these characters. */);
31297 Vnobreak_char_display
= Qt
;
31299 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
31300 doc
: /* The pointer shape to show in void text areas.
31301 A value of nil means to show the text pointer. Other options are
31302 `arrow', `text', `hand', `vdrag', `hdrag', `nhdrag', `modeline', and
31304 Vvoid_text_area_pointer
= Qarrow
;
31306 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
31307 doc
: /* Non-nil means don't actually do any redisplay.
31308 This is used for internal purposes. */);
31309 Vinhibit_redisplay
= Qnil
;
31311 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
31312 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
31313 Vglobal_mode_string
= Qnil
;
31315 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
31316 doc
: /* Marker for where to display an arrow on top of the buffer text.
31317 This must be the beginning of a line in order to work.
31318 See also `overlay-arrow-string'. */);
31319 Voverlay_arrow_position
= Qnil
;
31321 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
31322 doc
: /* String to display as an arrow in non-window frames.
31323 See also `overlay-arrow-position'. */);
31324 Voverlay_arrow_string
= build_pure_c_string ("=>");
31326 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
31327 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
31328 The symbols on this list are examined during redisplay to determine
31329 where to display overlay arrows. */);
31330 Voverlay_arrow_variable_list
31331 = list1 (intern_c_string ("overlay-arrow-position"));
31333 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
31334 doc
: /* The number of lines to try scrolling a window by when point moves out.
31335 If that fails to bring point back on frame, point is centered instead.
31336 If this is zero, point is always centered after it moves off frame.
31337 If you want scrolling to always be a line at a time, you should set
31338 `scroll-conservatively' to a large value rather than set this to 1. */);
31340 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
31341 doc
: /* Scroll up to this many lines, to bring point back on screen.
31342 If point moves off-screen, redisplay will scroll by up to
31343 `scroll-conservatively' lines in order to bring point just barely
31344 onto the screen again. If that cannot be done, then redisplay
31345 recenters point as usual.
31347 If the value is greater than 100, redisplay will never recenter point,
31348 but will always scroll just enough text to bring point into view, even
31349 if you move far away.
31351 A value of zero means always recenter point if it moves off screen. */);
31352 scroll_conservatively
= 0;
31354 DEFVAR_INT ("scroll-margin", scroll_margin
,
31355 doc
: /* Number of lines of margin at the top and bottom of a window.
31356 Recenter the window whenever point gets within this many lines
31357 of the top or bottom of the window. */);
31360 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
31361 doc
: /* Pixels per inch value for non-window system displays.
31362 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
31363 Vdisplay_pixels_per_inch
= make_float (72.0);
31366 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
31369 DEFVAR_LISP ("truncate-partial-width-windows",
31370 Vtruncate_partial_width_windows
,
31371 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
31372 For an integer value, truncate lines in each window narrower than the
31373 full frame width, provided the window width is less than that integer;
31374 otherwise, respect the value of `truncate-lines'.
31376 For any other non-nil value, truncate lines in all windows that do
31377 not span the full frame width.
31379 A value of nil means to respect the value of `truncate-lines'.
31381 If `word-wrap' is enabled, you might want to reduce this. */);
31382 Vtruncate_partial_width_windows
= make_number (50);
31384 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
31385 doc
: /* Maximum buffer size for which line number should be displayed.
31386 If the buffer is bigger than this, the line number does not appear
31387 in the mode line. A value of nil means no limit. */);
31388 Vline_number_display_limit
= Qnil
;
31390 DEFVAR_INT ("line-number-display-limit-width",
31391 line_number_display_limit_width
,
31392 doc
: /* Maximum line width (in characters) for line number display.
31393 If the average length of the lines near point is bigger than this, then the
31394 line number may be omitted from the mode line. */);
31395 line_number_display_limit_width
= 200;
31397 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
31398 doc
: /* Non-nil means highlight region even in nonselected windows. */);
31399 highlight_nonselected_windows
= false;
31401 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
31402 doc
: /* Non-nil if more than one frame is visible on this display.
31403 Minibuffer-only frames don't count, but iconified frames do.
31404 This variable is not guaranteed to be accurate except while processing
31405 `frame-title-format' and `icon-title-format'. */);
31407 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
31408 doc
: /* Template for displaying the title bar of visible frames.
31409 (Assuming the window manager supports this feature.)
31411 This variable has the same structure as `mode-line-format', except that
31412 the %c and %l constructs are ignored. It is used only on frames for
31413 which no explicit name has been set (see `modify-frame-parameters'). */);
31415 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
31416 doc
: /* Template for displaying the title bar of an iconified frame.
31417 (Assuming the window manager supports this feature.)
31418 This variable has the same structure as `mode-line-format' (which see),
31419 and is used only on frames for which no explicit name has been set
31420 (see `modify-frame-parameters'). */);
31422 = Vframe_title_format
31423 = listn (CONSTYPE_PURE
, 3,
31424 intern_c_string ("multiple-frames"),
31425 build_pure_c_string ("%b"),
31426 listn (CONSTYPE_PURE
, 4,
31427 empty_unibyte_string
,
31428 intern_c_string ("invocation-name"),
31429 build_pure_c_string ("@"),
31430 intern_c_string ("system-name")));
31432 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
31433 doc
: /* Maximum number of lines to keep in the message log buffer.
31434 If nil, disable message logging. If t, log messages but don't truncate
31435 the buffer when it becomes large. */);
31436 Vmessage_log_max
= make_number (1000);
31438 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
31439 doc
: /* Functions called during redisplay, if window sizes have changed.
31440 The value should be a list of functions that take one argument.
31441 During the first part of redisplay, for each frame, if any of its windows
31442 have changed size since the last redisplay, or have been split or deleted,
31443 all the functions in the list are called, with the frame as argument.
31444 If redisplay decides to resize the minibuffer window, it calls these
31445 functions on behalf of that as well. */);
31446 Vwindow_size_change_functions
= Qnil
;
31448 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
31449 doc
: /* List of functions to call before redisplaying a window with scrolling.
31450 Each function is called with two arguments, the window and its new
31451 display-start position.
31452 These functions are called whenever the `window-start' marker is modified,
31453 either to point into another buffer (e.g. via `set-window-buffer') or another
31454 place in the same buffer.
31455 Note that the value of `window-end' is not valid when these functions are
31458 Warning: Do not use this feature to alter the way the window
31459 is scrolled. It is not designed for that, and such use probably won't
31461 Vwindow_scroll_functions
= Qnil
;
31463 DEFVAR_LISP ("window-text-change-functions",
31464 Vwindow_text_change_functions
,
31465 doc
: /* Functions to call in redisplay when text in the window might change. */);
31466 Vwindow_text_change_functions
= Qnil
;
31468 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
31469 doc
: /* Functions called when redisplay of a window reaches the end trigger.
31470 Each function is called with two arguments, the window and the end trigger value.
31471 See `set-window-redisplay-end-trigger'. */);
31472 Vredisplay_end_trigger_functions
= Qnil
;
31474 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
31475 doc
: /* Non-nil means autoselect window with mouse pointer.
31476 If nil, do not autoselect windows.
31477 A positive number means delay autoselection by that many seconds: a
31478 window is autoselected only after the mouse has remained in that
31479 window for the duration of the delay.
31480 A negative number has a similar effect, but causes windows to be
31481 autoselected only after the mouse has stopped moving. (Because of
31482 the way Emacs compares mouse events, you will occasionally wait twice
31483 that time before the window gets selected.)
31484 Any other value means to autoselect window instantaneously when the
31485 mouse pointer enters it.
31487 Autoselection selects the minibuffer only if it is active, and never
31488 unselects the minibuffer if it is active.
31490 When customizing this variable make sure that the actual value of
31491 `focus-follows-mouse' matches the behavior of your window manager. */);
31492 Vmouse_autoselect_window
= Qnil
;
31494 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
31495 doc
: /* Non-nil means automatically resize tool-bars.
31496 This dynamically changes the tool-bar's height to the minimum height
31497 that is needed to make all tool-bar items visible.
31498 If value is `grow-only', the tool-bar's height is only increased
31499 automatically; to decrease the tool-bar height, use \\[recenter]. */);
31500 Vauto_resize_tool_bars
= Qt
;
31502 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
31503 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
31504 auto_raise_tool_bar_buttons_p
= true;
31506 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
31507 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
31508 make_cursor_line_fully_visible_p
= true;
31510 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
31511 doc
: /* Border below tool-bar in pixels.
31512 If an integer, use it as the height of the border.
31513 If it is one of `internal-border-width' or `border-width', use the
31514 value of the corresponding frame parameter.
31515 Otherwise, no border is added below the tool-bar. */);
31516 Vtool_bar_border
= Qinternal_border_width
;
31518 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
31519 doc
: /* Margin around tool-bar buttons in pixels.
31520 If an integer, use that for both horizontal and vertical margins.
31521 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
31522 HORZ specifying the horizontal margin, and VERT specifying the
31523 vertical margin. */);
31524 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
31526 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
31527 doc
: /* Relief thickness of tool-bar buttons. */);
31528 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
31530 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
31531 doc
: /* Tool bar style to use.
31533 image - show images only
31534 text - show text only
31535 both - show both, text below image
31536 both-horiz - show text to the right of the image
31537 text-image-horiz - show text to the left of the image
31538 any other - use system default or image if no system default.
31540 This variable only affects the GTK+ toolkit version of Emacs. */);
31541 Vtool_bar_style
= Qnil
;
31543 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
31544 doc
: /* Maximum number of characters a label can have to be shown.
31545 The tool bar style must also show labels for this to have any effect, see
31546 `tool-bar-style'. */);
31547 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
31549 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
31550 doc
: /* List of functions to call to fontify regions of text.
31551 Each function is called with one argument POS. Functions must
31552 fontify a region starting at POS in the current buffer, and give
31553 fontified regions the property `fontified'. */);
31554 Vfontification_functions
= Qnil
;
31555 Fmake_variable_buffer_local (Qfontification_functions
);
31557 DEFVAR_BOOL ("unibyte-display-via-language-environment",
31558 unibyte_display_via_language_environment
,
31559 doc
: /* Non-nil means display unibyte text according to language environment.
31560 Specifically, this means that raw bytes in the range 160-255 decimal
31561 are displayed by converting them to the equivalent multibyte characters
31562 according to the current language environment. As a result, they are
31563 displayed according to the current fontset.
31565 Note that this variable affects only how these bytes are displayed,
31566 but does not change the fact they are interpreted as raw bytes. */);
31567 unibyte_display_via_language_environment
= false;
31569 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
31570 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
31571 If a float, it specifies a fraction of the mini-window frame's height.
31572 If an integer, it specifies a number of lines. */);
31573 Vmax_mini_window_height
= make_float (0.25);
31575 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
31576 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
31577 A value of nil means don't automatically resize mini-windows.
31578 A value of t means resize them to fit the text displayed in them.
31579 A value of `grow-only', the default, means let mini-windows grow only;
31580 they return to their normal size when the minibuffer is closed, or the
31581 echo area becomes empty. */);
31582 Vresize_mini_windows
= Qgrow_only
;
31584 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
31585 doc
: /* Alist specifying how to blink the cursor off.
31586 Each element has the form (ON-STATE . OFF-STATE). Whenever the
31587 `cursor-type' frame-parameter or variable equals ON-STATE,
31588 comparing using `equal', Emacs uses OFF-STATE to specify
31589 how to blink it off. ON-STATE and OFF-STATE are values for
31590 the `cursor-type' frame parameter.
31592 If a frame's ON-STATE has no entry in this list,
31593 the frame's other specifications determine how to blink the cursor off. */);
31594 Vblink_cursor_alist
= Qnil
;
31596 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
31597 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
31598 If non-nil, windows are automatically scrolled horizontally to make
31599 point visible. */);
31600 automatic_hscrolling_p
= true;
31601 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
31603 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
31604 doc
: /* How many columns away from the window edge point is allowed to get
31605 before automatic hscrolling will horizontally scroll the window. */);
31606 hscroll_margin
= 5;
31608 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
31609 doc
: /* How many columns to scroll the window when point gets too close to the edge.
31610 When point is less than `hscroll-margin' columns from the window
31611 edge, automatic hscrolling will scroll the window by the amount of columns
31612 determined by this variable. If its value is a positive integer, scroll that
31613 many columns. If it's a positive floating-point number, it specifies the
31614 fraction of the window's width to scroll. If it's nil or zero, point will be
31615 centered horizontally after the scroll. Any other value, including negative
31616 numbers, are treated as if the value were zero.
31618 Automatic hscrolling always moves point outside the scroll margin, so if
31619 point was more than scroll step columns inside the margin, the window will
31620 scroll more than the value given by the scroll step.
31622 Note that the lower bound for automatic hscrolling specified by `scroll-left'
31623 and `scroll-right' overrides this variable's effect. */);
31624 Vhscroll_step
= make_number (0);
31626 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
31627 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
31628 Bind this around calls to `message' to let it take effect. */);
31629 message_truncate_lines
= false;
31631 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
31632 doc
: /* Normal hook run to update the menu bar definitions.
31633 Redisplay runs this hook before it redisplays the menu bar.
31634 This is used to update menus such as Buffers, whose contents depend on
31636 Vmenu_bar_update_hook
= Qnil
;
31638 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
31639 doc
: /* Frame for which we are updating a menu.
31640 The enable predicate for a menu binding should check this variable. */);
31641 Vmenu_updating_frame
= Qnil
;
31643 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
31644 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
31645 inhibit_menubar_update
= false;
31647 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
31648 doc
: /* Prefix prepended to all continuation lines at display time.
31649 The value may be a string, an image, or a stretch-glyph; it is
31650 interpreted in the same way as the value of a `display' text property.
31652 This variable is overridden by any `wrap-prefix' text or overlay
31655 To add a prefix to non-continuation lines, use `line-prefix'. */);
31656 Vwrap_prefix
= Qnil
;
31657 DEFSYM (Qwrap_prefix
, "wrap-prefix");
31658 Fmake_variable_buffer_local (Qwrap_prefix
);
31660 DEFVAR_LISP ("line-prefix", Vline_prefix
,
31661 doc
: /* Prefix prepended to all non-continuation lines at display time.
31662 The value may be a string, an image, or a stretch-glyph; it is
31663 interpreted in the same way as the value of a `display' text property.
31665 This variable is overridden by any `line-prefix' text or overlay
31668 To add a prefix to continuation lines, use `wrap-prefix'. */);
31669 Vline_prefix
= Qnil
;
31670 DEFSYM (Qline_prefix
, "line-prefix");
31671 Fmake_variable_buffer_local (Qline_prefix
);
31673 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
31674 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
31675 inhibit_eval_during_redisplay
= false;
31677 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
31678 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
31679 inhibit_free_realized_faces
= false;
31681 DEFVAR_BOOL ("inhibit-bidi-mirroring", inhibit_bidi_mirroring
,
31682 doc
: /* Non-nil means don't mirror characters even when bidi context requires that.
31683 Intended for use during debugging and for testing bidi display;
31684 see biditest.el in the test suite. */);
31685 inhibit_bidi_mirroring
= false;
31688 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
31689 doc
: /* Inhibit try_window_id display optimization. */);
31690 inhibit_try_window_id
= false;
31692 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
31693 doc
: /* Inhibit try_window_reusing display optimization. */);
31694 inhibit_try_window_reusing
= false;
31696 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
31697 doc
: /* Inhibit try_cursor_movement display optimization. */);
31698 inhibit_try_cursor_movement
= false;
31699 #endif /* GLYPH_DEBUG */
31701 DEFVAR_INT ("overline-margin", overline_margin
,
31702 doc
: /* Space between overline and text, in pixels.
31703 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
31704 margin to the character height. */);
31705 overline_margin
= 2;
31707 DEFVAR_INT ("underline-minimum-offset",
31708 underline_minimum_offset
,
31709 doc
: /* Minimum distance between baseline and underline.
31710 This can improve legibility of underlined text at small font sizes,
31711 particularly when using variable `x-use-underline-position-properties'
31712 with fonts that specify an UNDERLINE_POSITION relatively close to the
31713 baseline. The default value is 1. */);
31714 underline_minimum_offset
= 1;
31716 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
31717 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
31718 This feature only works when on a window system that can change
31719 cursor shapes. */);
31720 display_hourglass_p
= true;
31722 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
31723 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
31724 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
31726 #ifdef HAVE_WINDOW_SYSTEM
31727 hourglass_atimer
= NULL
;
31728 hourglass_shown_p
= false;
31729 #endif /* HAVE_WINDOW_SYSTEM */
31731 /* Name of the face used to display glyphless characters. */
31732 DEFSYM (Qglyphless_char
, "glyphless-char");
31734 /* Method symbols for Vglyphless_char_display. */
31735 DEFSYM (Qhex_code
, "hex-code");
31736 DEFSYM (Qempty_box
, "empty-box");
31737 DEFSYM (Qthin_space
, "thin-space");
31738 DEFSYM (Qzero_width
, "zero-width");
31740 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
31741 doc
: /* Function run just before redisplay.
31742 It is called with one argument, which is the set of windows that are to
31743 be redisplayed. This set can be nil (meaning, only the selected window),
31744 or t (meaning all windows). */);
31745 Vpre_redisplay_function
= intern ("ignore");
31747 /* Symbol for the purpose of Vglyphless_char_display. */
31748 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
31749 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
31751 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
31752 doc
: /* Char-table defining glyphless characters.
31753 Each element, if non-nil, should be one of the following:
31754 an ASCII acronym string: display this string in a box
31755 `hex-code': display the hexadecimal code of a character in a box
31756 `empty-box': display as an empty box
31757 `thin-space': display as 1-pixel width space
31758 `zero-width': don't display
31759 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
31760 display method for graphical terminals and text terminals respectively.
31761 GRAPHICAL and TEXT should each have one of the values listed above.
31763 The char-table has one extra slot to control the display of a character for
31764 which no font is found. This slot only takes effect on graphical terminals.
31765 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
31766 `thin-space'. The default is `empty-box'.
31768 If a character has a non-nil entry in an active display table, the
31769 display table takes effect; in this case, Emacs does not consult
31770 `glyphless-char-display' at all. */);
31771 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
31772 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
31775 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
31776 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
31777 Vdebug_on_message
= Qnil
;
31779 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
31781 Vredisplay__all_windows_cause
= Fmake_hash_table (0, NULL
);
31783 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
31785 Vredisplay__mode_lines_cause
= Fmake_hash_table (0, NULL
);
31787 DEFVAR_LISP ("redisplay--variables", Vredisplay__variables
,
31788 doc
: /* A hash-table of variables changing which triggers a thorough redisplay. */);
31789 Vredisplay__variables
= Qnil
;
31793 /* Initialize this module when Emacs starts. */
31798 CHARPOS (this_line_start_pos
) = 0;
31800 if (!noninteractive
)
31802 struct window
*m
= XWINDOW (minibuf_window
);
31803 Lisp_Object frame
= m
->frame
;
31804 struct frame
*f
= XFRAME (frame
);
31805 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
31806 struct window
*r
= XWINDOW (root
);
31809 echo_area_window
= minibuf_window
;
31811 r
->top_line
= FRAME_TOP_MARGIN (f
);
31812 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
31813 r
->total_cols
= FRAME_COLS (f
);
31814 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31815 r
->total_lines
= FRAME_TOTAL_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
31816 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
31818 m
->top_line
= FRAME_TOTAL_LINES (f
) - 1;
31819 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
31820 m
->total_cols
= FRAME_COLS (f
);
31821 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31822 m
->total_lines
= 1;
31823 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
31825 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
31826 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
31827 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
31829 /* The default ellipsis glyphs `...'. */
31830 for (i
= 0; i
< 3; ++i
)
31831 default_invis_vector
[i
] = make_number ('.');
31835 /* Allocate the buffer for frame titles.
31836 Also used for `format-mode-line'. */
31838 mode_line_noprop_buf
= xmalloc (size
);
31839 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
31840 mode_line_noprop_ptr
= mode_line_noprop_buf
;
31841 mode_line_target
= MODE_LINE_DISPLAY
;
31844 help_echo_showing_p
= false;
31847 #ifdef HAVE_WINDOW_SYSTEM
31849 /* Platform-independent portion of hourglass implementation. */
31851 /* Timer function of hourglass_atimer. */
31854 show_hourglass (struct atimer
*timer
)
31856 /* The timer implementation will cancel this timer automatically
31857 after this function has run. Set hourglass_atimer to null
31858 so that we know the timer doesn't have to be canceled. */
31859 hourglass_atimer
= NULL
;
31861 if (!hourglass_shown_p
)
31863 Lisp_Object tail
, frame
;
31867 FOR_EACH_FRAME (tail
, frame
)
31869 struct frame
*f
= XFRAME (frame
);
31871 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31872 && FRAME_RIF (f
)->show_hourglass
)
31873 FRAME_RIF (f
)->show_hourglass (f
);
31876 hourglass_shown_p
= true;
31881 /* Cancel a currently active hourglass timer, and start a new one. */
31884 start_hourglass (void)
31886 struct timespec delay
;
31888 cancel_hourglass ();
31890 if (INTEGERP (Vhourglass_delay
)
31891 && XINT (Vhourglass_delay
) > 0)
31892 delay
= make_timespec (min (XINT (Vhourglass_delay
),
31893 TYPE_MAXIMUM (time_t)),
31895 else if (FLOATP (Vhourglass_delay
)
31896 && XFLOAT_DATA (Vhourglass_delay
) > 0)
31897 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
31899 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
31901 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
31902 show_hourglass
, NULL
);
31905 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
31909 cancel_hourglass (void)
31911 if (hourglass_atimer
)
31913 cancel_atimer (hourglass_atimer
);
31914 hourglass_atimer
= NULL
;
31917 if (hourglass_shown_p
)
31919 Lisp_Object tail
, frame
;
31923 FOR_EACH_FRAME (tail
, frame
)
31925 struct frame
*f
= XFRAME (frame
);
31927 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31928 && FRAME_RIF (f
)->hide_hourglass
)
31929 FRAME_RIF (f
)->hide_hourglass (f
);
31931 /* No cursors on non GUI frames - restore to stock arrow cursor. */
31932 else if (!FRAME_W32_P (f
))
31933 w32_arrow_cursor ();
31937 hourglass_shown_p
= false;
31942 #endif /* HAVE_WINDOW_SYSTEM */