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 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
)
7245 int stackp
= it
->sp
- 1;
7247 /* Find the stack level with data from buffer. */
7249 && STRINGP ((it
->stack
+ stackp
)->string
))
7251 eassert (stackp
>= 0);
7252 pos
= (it
->stack
+ stackp
)->position
;
7255 INC_TEXT_POS (pos
, it
->multibyte_p
);
7257 if (CHARPOS (pos
) >= ZV
)
7258 it
->end_of_box_run_p
= true;
7261 next_face_id
= face_at_buffer_position
7262 (it
->w
, CHARPOS (pos
), &ignore
,
7263 CHARPOS (pos
) + TEXT_PROP_DISTANCE_LIMIT
, false, -1);
7264 it
->end_of_box_run_p
7265 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7271 /* next_element_from_display_vector sets this flag according to
7272 faces of the display vector glyphs, see there. */
7273 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7275 int face_id
= face_after_it_pos (it
);
7276 it
->end_of_box_run_p
7277 = (face_id
!= it
->face_id
7278 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7281 /* If we reached the end of the object we've been iterating (e.g., a
7282 display string or an overlay string), and there's something on
7283 IT->stack, proceed with what's on the stack. It doesn't make
7284 sense to return false if there's unprocessed stuff on the stack,
7285 because otherwise that stuff will never be displayed. */
7286 if (!success_p
&& it
->sp
> 0)
7288 set_iterator_to_next (it
, false);
7289 success_p
= get_next_display_element (it
);
7292 /* Value is false if end of buffer or string reached. */
7297 /* Move IT to the next display element.
7299 RESEAT_P means if called on a newline in buffer text,
7300 skip to the next visible line start.
7302 Functions get_next_display_element and set_iterator_to_next are
7303 separate because I find this arrangement easier to handle than a
7304 get_next_display_element function that also increments IT's
7305 position. The way it is we can first look at an iterator's current
7306 display element, decide whether it fits on a line, and if it does,
7307 increment the iterator position. The other way around we probably
7308 would either need a flag indicating whether the iterator has to be
7309 incremented the next time, or we would have to implement a
7310 decrement position function which would not be easy to write. */
7313 set_iterator_to_next (struct it
*it
, bool reseat_p
)
7315 /* Reset flags indicating start and end of a sequence of characters
7316 with box. Reset them at the start of this function because
7317 moving the iterator to a new position might set them. */
7318 it
->start_of_box_run_p
= it
->end_of_box_run_p
= false;
7322 case GET_FROM_BUFFER
:
7323 /* The current display element of IT is a character from
7324 current_buffer. Advance in the buffer, and maybe skip over
7325 invisible lines that are so because of selective display. */
7326 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7327 reseat_at_next_visible_line_start (it
, false);
7328 else if (it
->cmp_it
.id
>= 0)
7330 /* We are currently getting glyphs from a composition. */
7333 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7334 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7340 /* Update IT's char/byte positions to point to the first
7341 character of the next grapheme cluster, or to the
7342 character visually after the current composition. */
7343 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7344 bidi_move_to_visually_next (&it
->bidi_it
);
7345 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7346 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7349 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7350 && it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7352 /* Composition created while scanning forward. Proceed
7353 to the next grapheme cluster. */
7354 it
->cmp_it
.from
= it
->cmp_it
.to
;
7356 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7357 && it
->cmp_it
.from
> 0)
7359 /* Composition created while scanning backward. Proceed
7360 to the previous grapheme cluster. */
7361 it
->cmp_it
.to
= it
->cmp_it
.from
;
7365 /* No more grapheme clusters in this composition.
7366 Find the next stop position. */
7367 ptrdiff_t stop
= it
->end_charpos
;
7369 if (it
->bidi_it
.scan_dir
< 0)
7370 /* Now we are scanning backward and don't know
7373 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7374 IT_BYTEPOS (*it
), stop
, Qnil
);
7379 eassert (it
->len
!= 0);
7383 IT_BYTEPOS (*it
) += it
->len
;
7384 IT_CHARPOS (*it
) += 1;
7388 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7389 /* If this is a new paragraph, determine its base
7390 direction (a.k.a. its base embedding level). */
7391 if (it
->bidi_it
.new_paragraph
)
7392 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
7394 bidi_move_to_visually_next (&it
->bidi_it
);
7395 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7396 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7397 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7399 /* As the scan direction was changed, we must
7400 re-compute the stop position for composition. */
7401 ptrdiff_t stop
= it
->end_charpos
;
7402 if (it
->bidi_it
.scan_dir
< 0)
7404 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7405 IT_BYTEPOS (*it
), stop
, Qnil
);
7408 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7412 case GET_FROM_C_STRING
:
7413 /* Current display element of IT is from a C string. */
7415 /* If the string position is beyond string's end, it means
7416 next_element_from_c_string is padding the string with
7417 blanks, in which case we bypass the bidi iterator,
7418 because it cannot deal with such virtual characters. */
7419 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7421 IT_BYTEPOS (*it
) += it
->len
;
7422 IT_CHARPOS (*it
) += 1;
7426 bidi_move_to_visually_next (&it
->bidi_it
);
7427 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7428 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7432 case GET_FROM_DISPLAY_VECTOR
:
7433 /* Current display element of IT is from a display table entry.
7434 Advance in the display table definition. Reset it to null if
7435 end reached, and continue with characters from buffers/
7437 ++it
->current
.dpvec_index
;
7439 /* Restore face of the iterator to what they were before the
7440 display vector entry (these entries may contain faces). */
7441 it
->face_id
= it
->saved_face_id
;
7443 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7445 bool recheck_faces
= it
->ellipsis_p
;
7448 it
->method
= GET_FROM_C_STRING
;
7449 else if (STRINGP (it
->string
))
7450 it
->method
= GET_FROM_STRING
;
7453 it
->method
= GET_FROM_BUFFER
;
7454 it
->object
= it
->w
->contents
;
7458 it
->current
.dpvec_index
= -1;
7460 /* Skip over characters which were displayed via IT->dpvec. */
7461 if (it
->dpvec_char_len
< 0)
7462 reseat_at_next_visible_line_start (it
, true);
7463 else if (it
->dpvec_char_len
> 0)
7465 it
->len
= it
->dpvec_char_len
;
7466 set_iterator_to_next (it
, reseat_p
);
7469 /* Maybe recheck faces after display vector. */
7472 if (it
->method
== GET_FROM_STRING
)
7473 it
->stop_charpos
= IT_STRING_CHARPOS (*it
);
7475 it
->stop_charpos
= IT_CHARPOS (*it
);
7480 case GET_FROM_STRING
:
7481 /* Current display element is a character from a Lisp string. */
7482 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7483 /* Don't advance past string end. These conditions are true
7484 when set_iterator_to_next is called at the end of
7485 get_next_display_element, in which case the Lisp string is
7486 already exhausted, and all we want is pop the iterator
7488 if (it
->current
.overlay_string_index
>= 0)
7490 /* This is an overlay string, so there's no padding with
7491 spaces, and the number of characters in the string is
7492 where the string ends. */
7493 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7494 goto consider_string_end
;
7498 /* Not an overlay string. There could be padding, so test
7499 against it->end_charpos. */
7500 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7501 goto consider_string_end
;
7503 if (it
->cmp_it
.id
>= 0)
7505 /* We are delivering display elements from a composition.
7506 Update the string position past the grapheme cluster
7507 we've just processed. */
7510 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7511 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7517 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7518 bidi_move_to_visually_next (&it
->bidi_it
);
7519 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7520 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7523 /* Did we exhaust all the grapheme clusters of this
7525 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7526 && (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
))
7528 /* Not all the grapheme clusters were processed yet;
7529 advance to the next cluster. */
7530 it
->cmp_it
.from
= it
->cmp_it
.to
;
7532 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7533 && it
->cmp_it
.from
> 0)
7535 /* Likewise: advance to the next cluster, but going in
7536 the reverse direction. */
7537 it
->cmp_it
.to
= it
->cmp_it
.from
;
7541 /* This composition was fully processed; find the next
7542 candidate place for checking for composed
7544 /* Always limit string searches to the string length;
7545 any padding spaces are not part of the string, and
7546 there cannot be any compositions in that padding. */
7547 ptrdiff_t stop
= SCHARS (it
->string
);
7549 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
7551 else if (it
->end_charpos
< stop
)
7553 /* Cf. PRECISION in reseat_to_string: we might be
7554 limited in how many of the string characters we
7556 stop
= it
->end_charpos
;
7558 composition_compute_stop_pos (&it
->cmp_it
,
7559 IT_STRING_CHARPOS (*it
),
7560 IT_STRING_BYTEPOS (*it
), stop
,
7567 /* If the string position is beyond string's end, it
7568 means next_element_from_string is padding the string
7569 with blanks, in which case we bypass the bidi
7570 iterator, because it cannot deal with such virtual
7572 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7574 IT_STRING_BYTEPOS (*it
) += it
->len
;
7575 IT_STRING_CHARPOS (*it
) += 1;
7579 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7581 bidi_move_to_visually_next (&it
->bidi_it
);
7582 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7583 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7584 /* If the scan direction changes, we may need to update
7585 the place where to check for composed characters. */
7586 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7588 ptrdiff_t stop
= SCHARS (it
->string
);
7590 if (it
->bidi_it
.scan_dir
< 0)
7592 else if (it
->end_charpos
< stop
)
7593 stop
= it
->end_charpos
;
7595 composition_compute_stop_pos (&it
->cmp_it
,
7596 IT_STRING_CHARPOS (*it
),
7597 IT_STRING_BYTEPOS (*it
), stop
,
7603 consider_string_end
:
7605 if (it
->current
.overlay_string_index
>= 0)
7607 /* IT->string is an overlay string. Advance to the
7608 next, if there is one. */
7609 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7611 it
->ellipsis_p
= false;
7612 next_overlay_string (it
);
7614 setup_for_ellipsis (it
, 0);
7619 /* IT->string is not an overlay string. If we reached
7620 its end, and there is something on IT->stack, proceed
7621 with what is on the stack. This can be either another
7622 string, this time an overlay string, or a buffer. */
7623 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7627 if (it
->method
== GET_FROM_STRING
)
7628 goto consider_string_end
;
7633 case GET_FROM_IMAGE
:
7634 case GET_FROM_STRETCH
:
7635 case GET_FROM_XWIDGET
:
7637 /* The position etc with which we have to proceed are on
7638 the stack. The position may be at the end of a string,
7639 if the `display' property takes up the whole string. */
7640 eassert (it
->sp
> 0);
7642 if (it
->method
== GET_FROM_STRING
)
7643 goto consider_string_end
;
7647 /* There are no other methods defined, so this should be a bug. */
7651 eassert (it
->method
!= GET_FROM_STRING
7652 || (STRINGP (it
->string
)
7653 && IT_STRING_CHARPOS (*it
) >= 0));
7656 /* Load IT's display element fields with information about the next
7657 display element which comes from a display table entry or from the
7658 result of translating a control character to one of the forms `^C'
7661 IT->dpvec holds the glyphs to return as characters.
7662 IT->saved_face_id holds the face id before the display vector--it
7663 is restored into IT->face_id in set_iterator_to_next. */
7666 next_element_from_display_vector (struct it
*it
)
7669 int prev_face_id
= it
->face_id
;
7673 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7675 it
->face_id
= it
->saved_face_id
;
7677 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7678 That seemed totally bogus - so I changed it... */
7679 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7681 if (GLYPH_CODE_P (gc
))
7683 struct face
*this_face
, *prev_face
, *next_face
;
7685 it
->c
= GLYPH_CODE_CHAR (gc
);
7686 it
->len
= CHAR_BYTES (it
->c
);
7688 /* The entry may contain a face id to use. Such a face id is
7689 the id of a Lisp face, not a realized face. A face id of
7690 zero means no face is specified. */
7691 if (it
->dpvec_face_id
>= 0)
7692 it
->face_id
= it
->dpvec_face_id
;
7695 int lface_id
= GLYPH_CODE_FACE (gc
);
7697 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7701 /* Glyphs in the display vector could have the box face, so we
7702 need to set the related flags in the iterator, as
7704 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7705 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7707 /* Is this character the first character of a box-face run? */
7708 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7710 || prev_face
->box
== FACE_NO_BOX
));
7712 /* For the last character of the box-face run, we need to look
7713 either at the next glyph from the display vector, or at the
7714 face we saw before the display vector. */
7715 next_face_id
= it
->saved_face_id
;
7716 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7718 if (it
->dpvec_face_id
>= 0)
7719 next_face_id
= it
->dpvec_face_id
;
7723 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7726 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7730 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7731 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7733 || next_face
->box
== FACE_NO_BOX
));
7734 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7737 /* Display table entry is invalid. Return a space. */
7738 it
->c
= ' ', it
->len
= 1;
7740 /* Don't change position and object of the iterator here. They are
7741 still the values of the character that had this display table
7742 entry or was translated, and that's what we want. */
7743 it
->what
= IT_CHARACTER
;
7747 /* Get the first element of string/buffer in the visual order, after
7748 being reseated to a new position in a string or a buffer. */
7750 get_visually_first_element (struct it
*it
)
7752 bool string_p
= STRINGP (it
->string
) || it
->s
;
7753 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7754 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7756 if (STRINGP (it
->string
))
7758 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7759 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7763 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7764 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7767 if (it
->bidi_it
.charpos
== eob
)
7769 /* Nothing to do, but reset the FIRST_ELT flag, like
7770 bidi_paragraph_init does, because we are not going to
7772 it
->bidi_it
.first_elt
= false;
7774 else if (it
->bidi_it
.charpos
== bob
7776 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7777 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7779 /* If we are at the beginning of a line/string, we can produce
7780 the next element right away. */
7781 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7782 bidi_move_to_visually_next (&it
->bidi_it
);
7786 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7788 /* We need to prime the bidi iterator starting at the line's or
7789 string's beginning, before we will be able to produce the
7792 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7794 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7795 IT_BYTEPOS (*it
), -1,
7796 &it
->bidi_it
.bytepos
);
7797 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, true);
7800 /* Now return to buffer/string position where we were asked
7801 to get the next display element, and produce that. */
7802 bidi_move_to_visually_next (&it
->bidi_it
);
7804 while (it
->bidi_it
.bytepos
!= orig_bytepos
7805 && it
->bidi_it
.charpos
< eob
);
7808 /* Adjust IT's position information to where we ended up. */
7809 if (STRINGP (it
->string
))
7811 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7812 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7816 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7817 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7820 if (STRINGP (it
->string
) || !it
->s
)
7822 ptrdiff_t stop
, charpos
, bytepos
;
7824 if (STRINGP (it
->string
))
7827 stop
= SCHARS (it
->string
);
7828 if (stop
> it
->end_charpos
)
7829 stop
= it
->end_charpos
;
7830 charpos
= IT_STRING_CHARPOS (*it
);
7831 bytepos
= IT_STRING_BYTEPOS (*it
);
7835 stop
= it
->end_charpos
;
7836 charpos
= IT_CHARPOS (*it
);
7837 bytepos
= IT_BYTEPOS (*it
);
7839 if (it
->bidi_it
.scan_dir
< 0)
7841 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7846 /* Load IT with the next display element from Lisp string IT->string.
7847 IT->current.string_pos is the current position within the string.
7848 If IT->current.overlay_string_index >= 0, the Lisp string is an
7852 next_element_from_string (struct it
*it
)
7854 struct text_pos position
;
7856 eassert (STRINGP (it
->string
));
7857 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7858 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7859 position
= it
->current
.string_pos
;
7861 /* With bidi reordering, the character to display might not be the
7862 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT means
7863 that we were reseat()ed to a new string, whose paragraph
7864 direction is not known. */
7865 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7867 get_visually_first_element (it
);
7868 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7871 /* Time to check for invisible text? */
7872 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7874 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7877 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7878 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7880 /* With bidi non-linear iteration, we could find
7881 ourselves far beyond the last computed stop_charpos,
7882 with several other stop positions in between that we
7883 missed. Scan them all now, in buffer's logical
7884 order, until we find and handle the last stop_charpos
7885 that precedes our current position. */
7886 handle_stop_backwards (it
, it
->stop_charpos
);
7887 return GET_NEXT_DISPLAY_ELEMENT (it
);
7893 /* Take note of the stop position we just moved
7894 across, for when we will move back across it. */
7895 it
->prev_stop
= it
->stop_charpos
;
7896 /* If we are at base paragraph embedding level, take
7897 note of the last stop position seen at this
7899 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7900 it
->base_level_stop
= it
->stop_charpos
;
7904 /* Since a handler may have changed IT->method, we must
7906 return GET_NEXT_DISPLAY_ELEMENT (it
);
7910 /* If we are before prev_stop, we may have overstepped
7911 on our way backwards a stop_pos, and if so, we need
7912 to handle that stop_pos. */
7913 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7914 /* We can sometimes back up for reasons that have nothing
7915 to do with bidi reordering. E.g., compositions. The
7916 code below is only needed when we are above the base
7917 embedding level, so test for that explicitly. */
7918 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7920 /* If we lost track of base_level_stop, we have no better
7921 place for handle_stop_backwards to start from than string
7922 beginning. This happens, e.g., when we were reseated to
7923 the previous screenful of text by vertical-motion. */
7924 if (it
->base_level_stop
<= 0
7925 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7926 it
->base_level_stop
= 0;
7927 handle_stop_backwards (it
, it
->base_level_stop
);
7928 return GET_NEXT_DISPLAY_ELEMENT (it
);
7932 if (it
->current
.overlay_string_index
>= 0)
7934 /* Get the next character from an overlay string. In overlay
7935 strings, there is no field width or padding with spaces to
7937 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7942 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7943 IT_STRING_BYTEPOS (*it
),
7944 it
->bidi_it
.scan_dir
< 0
7946 : SCHARS (it
->string
))
7947 && next_element_from_composition (it
))
7951 else if (STRING_MULTIBYTE (it
->string
))
7953 const unsigned char *s
= (SDATA (it
->string
)
7954 + IT_STRING_BYTEPOS (*it
));
7955 it
->c
= string_char_and_length (s
, &it
->len
);
7959 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7965 /* Get the next character from a Lisp string that is not an
7966 overlay string. Such strings come from the mode line, for
7967 example. We may have to pad with spaces, or truncate the
7968 string. See also next_element_from_c_string. */
7969 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7974 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7976 /* Pad with spaces. */
7977 it
->c
= ' ', it
->len
= 1;
7978 CHARPOS (position
) = BYTEPOS (position
) = -1;
7980 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7981 IT_STRING_BYTEPOS (*it
),
7982 it
->bidi_it
.scan_dir
< 0
7984 : it
->string_nchars
)
7985 && next_element_from_composition (it
))
7989 else if (STRING_MULTIBYTE (it
->string
))
7991 const unsigned char *s
= (SDATA (it
->string
)
7992 + IT_STRING_BYTEPOS (*it
));
7993 it
->c
= string_char_and_length (s
, &it
->len
);
7997 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
8002 /* Record what we have and where it came from. */
8003 it
->what
= IT_CHARACTER
;
8004 it
->object
= it
->string
;
8005 it
->position
= position
;
8010 /* Load IT with next display element from C string IT->s.
8011 IT->string_nchars is the maximum number of characters to return
8012 from the string. IT->end_charpos may be greater than
8013 IT->string_nchars when this function is called, in which case we
8014 may have to return padding spaces. Value is false if end of string
8015 reached, including padding spaces. */
8018 next_element_from_c_string (struct it
*it
)
8020 bool success_p
= true;
8023 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
8024 it
->what
= IT_CHARACTER
;
8025 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
8026 it
->object
= make_number (0);
8028 /* With bidi reordering, the character to display might not be the
8029 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8030 we were reseated to a new string, whose paragraph direction is
8032 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8033 get_visually_first_element (it
);
8035 /* IT's position can be greater than IT->string_nchars in case a
8036 field width or precision has been specified when the iterator was
8038 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8040 /* End of the game. */
8044 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
8046 /* Pad with spaces. */
8047 it
->c
= ' ', it
->len
= 1;
8048 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
8050 else if (it
->multibyte_p
)
8051 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
8053 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
8059 /* Set up IT to return characters from an ellipsis, if appropriate.
8060 The definition of the ellipsis glyphs may come from a display table
8061 entry. This function fills IT with the first glyph from the
8062 ellipsis if an ellipsis is to be displayed. */
8065 next_element_from_ellipsis (struct it
*it
)
8067 if (it
->selective_display_ellipsis_p
)
8068 setup_for_ellipsis (it
, it
->len
);
8071 /* The face at the current position may be different from the
8072 face we find after the invisible text. Remember what it
8073 was in IT->saved_face_id, and signal that it's there by
8074 setting face_before_selective_p. */
8075 it
->saved_face_id
= it
->face_id
;
8076 it
->method
= GET_FROM_BUFFER
;
8077 it
->object
= it
->w
->contents
;
8078 reseat_at_next_visible_line_start (it
, true);
8079 it
->face_before_selective_p
= true;
8082 return GET_NEXT_DISPLAY_ELEMENT (it
);
8086 /* Deliver an image display element. The iterator IT is already
8087 filled with image information (done in handle_display_prop). Value
8092 next_element_from_image (struct it
*it
)
8094 it
->what
= IT_IMAGE
;
8099 next_element_from_xwidget (struct it
*it
)
8101 it
->what
= IT_XWIDGET
;
8106 /* Fill iterator IT with next display element from a stretch glyph
8107 property. IT->object is the value of the text property. Value is
8111 next_element_from_stretch (struct it
*it
)
8113 it
->what
= IT_STRETCH
;
8117 /* Scan backwards from IT's current position until we find a stop
8118 position, or until BEGV. This is called when we find ourself
8119 before both the last known prev_stop and base_level_stop while
8120 reordering bidirectional text. */
8123 compute_stop_pos_backwards (struct it
*it
)
8125 const int SCAN_BACK_LIMIT
= 1000;
8126 struct text_pos pos
;
8127 struct display_pos save_current
= it
->current
;
8128 struct text_pos save_position
= it
->position
;
8129 ptrdiff_t charpos
= IT_CHARPOS (*it
);
8130 ptrdiff_t where_we_are
= charpos
;
8131 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
8132 ptrdiff_t save_end_pos
= it
->end_charpos
;
8134 eassert (NILP (it
->string
) && !it
->s
);
8135 eassert (it
->bidi_p
);
8139 it
->end_charpos
= min (charpos
+ 1, ZV
);
8140 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
8141 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
8142 reseat_1 (it
, pos
, false);
8143 compute_stop_pos (it
);
8144 /* We must advance forward, right? */
8145 if (it
->stop_charpos
<= charpos
)
8148 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
8150 if (it
->stop_charpos
<= where_we_are
)
8151 it
->prev_stop
= it
->stop_charpos
;
8153 it
->prev_stop
= BEGV
;
8155 it
->current
= save_current
;
8156 it
->position
= save_position
;
8157 it
->stop_charpos
= save_stop_pos
;
8158 it
->end_charpos
= save_end_pos
;
8161 /* Scan forward from CHARPOS in the current buffer/string, until we
8162 find a stop position > current IT's position. Then handle the stop
8163 position before that. This is called when we bump into a stop
8164 position while reordering bidirectional text. CHARPOS should be
8165 the last previously processed stop_pos (or BEGV/0, if none were
8166 processed yet) whose position is less that IT's current
8170 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
8172 bool bufp
= !STRINGP (it
->string
);
8173 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
8174 struct display_pos save_current
= it
->current
;
8175 struct text_pos save_position
= it
->position
;
8176 struct text_pos pos1
;
8177 ptrdiff_t next_stop
;
8179 /* Scan in strict logical order. */
8180 eassert (it
->bidi_p
);
8184 it
->prev_stop
= charpos
;
8187 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
8188 reseat_1 (it
, pos1
, false);
8191 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
8192 compute_stop_pos (it
);
8193 /* We must advance forward, right? */
8194 if (it
->stop_charpos
<= it
->prev_stop
)
8196 charpos
= it
->stop_charpos
;
8198 while (charpos
<= where_we_are
);
8201 it
->current
= save_current
;
8202 it
->position
= save_position
;
8203 next_stop
= it
->stop_charpos
;
8204 it
->stop_charpos
= it
->prev_stop
;
8206 it
->stop_charpos
= next_stop
;
8209 /* Load IT with the next display element from current_buffer. Value
8210 is false if end of buffer reached. IT->stop_charpos is the next
8211 position at which to stop and check for text properties or buffer
8215 next_element_from_buffer (struct it
*it
)
8217 bool success_p
= true;
8219 eassert (IT_CHARPOS (*it
) >= BEGV
);
8220 eassert (NILP (it
->string
) && !it
->s
);
8221 eassert (!it
->bidi_p
8222 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8223 && it
->bidi_it
.string
.s
== NULL
));
8225 /* With bidi reordering, the character to display might not be the
8226 character at IT_CHARPOS. BIDI_IT.FIRST_ELT means that
8227 we were reseat()ed to a new buffer position, which is potentially
8228 a different paragraph. */
8229 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8231 get_visually_first_element (it
);
8232 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8235 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8237 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8239 bool overlay_strings_follow_p
;
8241 /* End of the game, except when overlay strings follow that
8242 haven't been returned yet. */
8243 if (it
->overlay_strings_at_end_processed_p
)
8244 overlay_strings_follow_p
= false;
8247 it
->overlay_strings_at_end_processed_p
= true;
8248 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8251 if (overlay_strings_follow_p
)
8252 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8256 it
->position
= it
->current
.pos
;
8260 else if (!(!it
->bidi_p
8261 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8262 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8264 /* With bidi non-linear iteration, we could find ourselves
8265 far beyond the last computed stop_charpos, with several
8266 other stop positions in between that we missed. Scan
8267 them all now, in buffer's logical order, until we find
8268 and handle the last stop_charpos that precedes our
8269 current position. */
8270 handle_stop_backwards (it
, it
->stop_charpos
);
8271 it
->ignore_overlay_strings_at_pos_p
= false;
8272 return GET_NEXT_DISPLAY_ELEMENT (it
);
8278 /* Take note of the stop position we just moved across,
8279 for when we will move back across it. */
8280 it
->prev_stop
= it
->stop_charpos
;
8281 /* If we are at base paragraph embedding level, take
8282 note of the last stop position seen at this
8284 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8285 it
->base_level_stop
= it
->stop_charpos
;
8288 it
->ignore_overlay_strings_at_pos_p
= false;
8289 return GET_NEXT_DISPLAY_ELEMENT (it
);
8293 /* If we are before prev_stop, we may have overstepped on
8294 our way backwards a stop_pos, and if so, we need to
8295 handle that stop_pos. */
8296 && IT_CHARPOS (*it
) < it
->prev_stop
8297 /* We can sometimes back up for reasons that have nothing
8298 to do with bidi reordering. E.g., compositions. The
8299 code below is only needed when we are above the base
8300 embedding level, so test for that explicitly. */
8301 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8303 if (it
->base_level_stop
<= 0
8304 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8306 /* If we lost track of base_level_stop, we need to find
8307 prev_stop by looking backwards. This happens, e.g., when
8308 we were reseated to the previous screenful of text by
8310 it
->base_level_stop
= BEGV
;
8311 compute_stop_pos_backwards (it
);
8312 handle_stop_backwards (it
, it
->prev_stop
);
8315 handle_stop_backwards (it
, it
->base_level_stop
);
8316 it
->ignore_overlay_strings_at_pos_p
= false;
8317 return GET_NEXT_DISPLAY_ELEMENT (it
);
8321 /* No face changes, overlays etc. in sight, so just return a
8322 character from current_buffer. */
8326 /* We moved to the next buffer position, so any info about
8327 previously seen overlays is no longer valid. */
8328 it
->ignore_overlay_strings_at_pos_p
= false;
8330 /* Maybe run the redisplay end trigger hook. Performance note:
8331 This doesn't seem to cost measurable time. */
8332 if (it
->redisplay_end_trigger_charpos
8334 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8335 run_redisplay_end_trigger_hook (it
);
8337 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8338 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8340 && next_element_from_composition (it
))
8345 /* Get the next character, maybe multibyte. */
8346 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8347 if (it
->multibyte_p
&& !ASCII_CHAR_P (*p
))
8348 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8350 it
->c
= *p
, it
->len
= 1;
8352 /* Record what we have and where it came from. */
8353 it
->what
= IT_CHARACTER
;
8354 it
->object
= it
->w
->contents
;
8355 it
->position
= it
->current
.pos
;
8357 /* Normally we return the character found above, except when we
8358 really want to return an ellipsis for selective display. */
8363 /* A value of selective > 0 means hide lines indented more
8364 than that number of columns. */
8365 if (it
->selective
> 0
8366 && IT_CHARPOS (*it
) + 1 < ZV
8367 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8368 IT_BYTEPOS (*it
) + 1,
8371 success_p
= next_element_from_ellipsis (it
);
8372 it
->dpvec_char_len
= -1;
8375 else if (it
->c
== '\r' && it
->selective
== -1)
8377 /* A value of selective == -1 means that everything from the
8378 CR to the end of the line is invisible, with maybe an
8379 ellipsis displayed for it. */
8380 success_p
= next_element_from_ellipsis (it
);
8381 it
->dpvec_char_len
= -1;
8386 /* Value is false if end of buffer reached. */
8387 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8392 /* Run the redisplay end trigger hook for IT. */
8395 run_redisplay_end_trigger_hook (struct it
*it
)
8397 /* IT->glyph_row should be non-null, i.e. we should be actually
8398 displaying something, or otherwise we should not run the hook. */
8399 eassert (it
->glyph_row
);
8401 ptrdiff_t charpos
= it
->redisplay_end_trigger_charpos
;
8402 it
->redisplay_end_trigger_charpos
= 0;
8404 /* Since we are *trying* to run these functions, don't try to run
8405 them again, even if they get an error. */
8406 wset_redisplay_end_trigger (it
->w
, Qnil
);
8407 CALLN (Frun_hook_with_args
, Qredisplay_end_trigger_functions
, it
->window
,
8408 make_number (charpos
));
8410 /* Notice if it changed the face of the character we are on. */
8411 handle_face_prop (it
);
8415 /* Deliver a composition display element. Unlike the other
8416 next_element_from_XXX, this function is not registered in the array
8417 get_next_element[]. It is called from next_element_from_buffer and
8418 next_element_from_string when necessary. */
8421 next_element_from_composition (struct it
*it
)
8423 it
->what
= IT_COMPOSITION
;
8424 it
->len
= it
->cmp_it
.nbytes
;
8425 if (STRINGP (it
->string
))
8429 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8430 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8433 it
->position
= it
->current
.string_pos
;
8434 it
->object
= it
->string
;
8435 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8436 IT_STRING_BYTEPOS (*it
), it
->string
);
8442 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8443 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8446 if (it
->bidi_it
.new_paragraph
)
8447 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
,
8449 /* Resync the bidi iterator with IT's new position.
8450 FIXME: this doesn't support bidirectional text. */
8451 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8452 bidi_move_to_visually_next (&it
->bidi_it
);
8456 it
->position
= it
->current
.pos
;
8457 it
->object
= it
->w
->contents
;
8458 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8459 IT_BYTEPOS (*it
), Qnil
);
8466 /***********************************************************************
8467 Moving an iterator without producing glyphs
8468 ***********************************************************************/
8470 /* Check if iterator is at a position corresponding to a valid buffer
8471 position after some move_it_ call. */
8473 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8474 ((it)->method != GET_FROM_STRING || IT_STRING_CHARPOS (*it) == 0)
8477 /* Move iterator IT to a specified buffer or X position within one
8478 line on the display without producing glyphs.
8480 OP should be a bit mask including some or all of these bits:
8481 MOVE_TO_X: Stop upon reaching x-position TO_X.
8482 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8483 Regardless of OP's value, stop upon reaching the end of the display line.
8485 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8486 This means, in particular, that TO_X includes window's horizontal
8489 The return value has several possible values that
8490 say what condition caused the scan to stop:
8492 MOVE_POS_MATCH_OR_ZV
8493 - when TO_POS or ZV was reached.
8496 -when TO_X was reached before TO_POS or ZV were reached.
8499 - when we reached the end of the display area and the line must
8503 - when we reached the end of the display area and the line is
8507 - when we stopped at a line end, i.e. a newline or a CR and selective
8510 static enum move_it_result
8511 move_it_in_display_line_to (struct it
*it
,
8512 ptrdiff_t to_charpos
, int to_x
,
8513 enum move_operation_enum op
)
8515 enum move_it_result result
= MOVE_UNDEFINED
;
8516 struct glyph_row
*saved_glyph_row
;
8517 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8518 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8519 void *ppos_data
= NULL
;
8520 bool may_wrap
= false;
8521 enum it_method prev_method
= it
->method
;
8522 ptrdiff_t closest_pos
IF_LINT (= 0), prev_pos
= IT_CHARPOS (*it
);
8523 bool saw_smaller_pos
= prev_pos
< to_charpos
;
8525 /* Don't produce glyphs in produce_glyphs. */
8526 saved_glyph_row
= it
->glyph_row
;
8527 it
->glyph_row
= NULL
;
8529 /* Use wrap_it to save a copy of IT wherever a word wrap could
8530 occur. Use atpos_it to save a copy of IT at the desired buffer
8531 position, if found, so that we can scan ahead and check if the
8532 word later overshoots the window edge. Use atx_it similarly, for
8538 /* Use ppos_it under bidi reordering to save a copy of IT for the
8539 initial position. We restore that position in IT when we have
8540 scanned the entire display line without finding a match for
8541 TO_CHARPOS and all the character positions are greater than
8542 TO_CHARPOS. We then restart the scan from the initial position,
8543 and stop at CLOSEST_POS, which is a position > TO_CHARPOS that is
8544 the closest to TO_CHARPOS. */
8547 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8549 SAVE_IT (ppos_it
, *it
, ppos_data
);
8550 closest_pos
= IT_CHARPOS (*it
);
8556 #define BUFFER_POS_REACHED_P() \
8557 ((op & MOVE_TO_POS) != 0 \
8558 && BUFFERP (it->object) \
8559 && (IT_CHARPOS (*it) == to_charpos \
8561 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8562 && IT_CHARPOS (*it) > to_charpos) \
8563 || (it->what == IT_COMPOSITION \
8564 && ((IT_CHARPOS (*it) > to_charpos \
8565 && to_charpos >= it->cmp_it.charpos) \
8566 || (IT_CHARPOS (*it) < to_charpos \
8567 && to_charpos <= it->cmp_it.charpos)))) \
8568 && (it->method == GET_FROM_BUFFER \
8569 || (it->method == GET_FROM_DISPLAY_VECTOR \
8570 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8572 /* If there's a line-/wrap-prefix, handle it. */
8573 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8574 && it
->current_y
< it
->last_visible_y
)
8575 handle_line_prefix (it
);
8577 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8578 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8582 int x
, i
, ascent
= 0, descent
= 0;
8584 /* Utility macro to reset an iterator with x, ascent, and descent. */
8585 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8586 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8587 (IT)->max_descent = descent)
8589 /* Stop if we move beyond TO_CHARPOS (after an image or a
8590 display string or stretch glyph). */
8591 if ((op
& MOVE_TO_POS
) != 0
8592 && BUFFERP (it
->object
)
8593 && it
->method
== GET_FROM_BUFFER
8595 /* When the iterator is at base embedding level, we
8596 are guaranteed that characters are delivered for
8597 display in strictly increasing order of their
8598 buffer positions. */
8599 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8600 && IT_CHARPOS (*it
) > to_charpos
)
8602 && (prev_method
== GET_FROM_IMAGE
8603 || prev_method
== GET_FROM_STRETCH
8604 || prev_method
== GET_FROM_STRING
)
8605 /* Passed TO_CHARPOS from left to right. */
8606 && ((prev_pos
< to_charpos
8607 && IT_CHARPOS (*it
) > to_charpos
)
8608 /* Passed TO_CHARPOS from right to left. */
8609 || (prev_pos
> to_charpos
8610 && IT_CHARPOS (*it
) < to_charpos
)))))
8612 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8614 result
= MOVE_POS_MATCH_OR_ZV
;
8617 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8618 /* If wrap_it is valid, the current position might be in a
8619 word that is wrapped. So, save the iterator in
8620 atpos_it and continue to see if wrapping happens. */
8621 SAVE_IT (atpos_it
, *it
, atpos_data
);
8624 /* Stop when ZV reached.
8625 We used to stop here when TO_CHARPOS reached as well, but that is
8626 too soon if this glyph does not fit on this line. So we handle it
8627 explicitly below. */
8628 if (!get_next_display_element (it
))
8630 result
= MOVE_POS_MATCH_OR_ZV
;
8634 if (it
->line_wrap
== TRUNCATE
)
8636 if (BUFFER_POS_REACHED_P ())
8638 result
= MOVE_POS_MATCH_OR_ZV
;
8644 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
8646 if (IT_DISPLAYING_WHITESPACE (it
))
8650 /* We have reached a glyph that follows one or more
8651 whitespace characters. If the position is
8652 already found, we are done. */
8653 if (atpos_it
.sp
>= 0)
8655 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8656 result
= MOVE_POS_MATCH_OR_ZV
;
8661 RESTORE_IT (it
, &atx_it
, atx_data
);
8662 result
= MOVE_X_REACHED
;
8665 /* Otherwise, we can wrap here. */
8666 SAVE_IT (wrap_it
, *it
, wrap_data
);
8672 /* Remember the line height for the current line, in case
8673 the next element doesn't fit on the line. */
8674 ascent
= it
->max_ascent
;
8675 descent
= it
->max_descent
;
8677 /* The call to produce_glyphs will get the metrics of the
8678 display element IT is loaded with. Record the x-position
8679 before this display element, in case it doesn't fit on the
8683 PRODUCE_GLYPHS (it
);
8685 if (it
->area
!= TEXT_AREA
)
8687 prev_method
= it
->method
;
8688 if (it
->method
== GET_FROM_BUFFER
)
8689 prev_pos
= IT_CHARPOS (*it
);
8690 set_iterator_to_next (it
, true);
8691 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8692 SET_TEXT_POS (this_line_min_pos
,
8693 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8695 && (op
& MOVE_TO_POS
)
8696 && IT_CHARPOS (*it
) > to_charpos
8697 && IT_CHARPOS (*it
) < closest_pos
)
8698 closest_pos
= IT_CHARPOS (*it
);
8702 /* The number of glyphs we get back in IT->nglyphs will normally
8703 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8704 character on a terminal frame, or (iii) a line end. For the
8705 second case, IT->nglyphs - 1 padding glyphs will be present.
8706 (On X frames, there is only one glyph produced for a
8707 composite character.)
8709 The behavior implemented below means, for continuation lines,
8710 that as many spaces of a TAB as fit on the current line are
8711 displayed there. For terminal frames, as many glyphs of a
8712 multi-glyph character are displayed in the current line, too.
8713 This is what the old redisplay code did, and we keep it that
8714 way. Under X, the whole shape of a complex character must
8715 fit on the line or it will be completely displayed in the
8718 Note that both for tabs and padding glyphs, all glyphs have
8722 /* More than one glyph or glyph doesn't fit on line. All
8723 glyphs have the same width. */
8724 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8726 int x_before_this_char
= x
;
8727 int hpos_before_this_char
= it
->hpos
;
8729 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8731 new_x
= x
+ single_glyph_width
;
8733 /* We want to leave anything reaching TO_X to the caller. */
8734 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8736 if (BUFFER_POS_REACHED_P ())
8738 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8739 goto buffer_pos_reached
;
8740 if (atpos_it
.sp
< 0)
8742 SAVE_IT (atpos_it
, *it
, atpos_data
);
8743 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8748 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8751 result
= MOVE_X_REACHED
;
8756 SAVE_IT (atx_it
, *it
, atx_data
);
8757 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8762 if (/* Lines are continued. */
8763 it
->line_wrap
!= TRUNCATE
8764 && (/* And glyph doesn't fit on the line. */
8765 new_x
> it
->last_visible_x
8766 /* Or it fits exactly and we're on a window
8768 || (new_x
== it
->last_visible_x
8769 && FRAME_WINDOW_P (it
->f
)
8770 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8771 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8772 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8774 if (/* IT->hpos == 0 means the very first glyph
8775 doesn't fit on the line, e.g. a wide image. */
8777 || (new_x
== it
->last_visible_x
8778 && FRAME_WINDOW_P (it
->f
)))
8781 it
->current_x
= new_x
;
8783 /* The character's last glyph just barely fits
8785 if (i
== it
->nglyphs
- 1)
8787 /* If this is the destination position,
8788 return a position *before* it in this row,
8789 now that we know it fits in this row. */
8790 if (BUFFER_POS_REACHED_P ())
8792 if (it
->line_wrap
!= WORD_WRAP
8794 /* If we've just found whitespace to
8795 wrap, effectively ignore the
8796 previous wrap point -- it is no
8797 longer relevant, but we won't
8798 have an opportunity to update it,
8799 since we've reached the edge of
8800 this screen line. */
8802 && IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8804 it
->hpos
= hpos_before_this_char
;
8805 it
->current_x
= x_before_this_char
;
8806 result
= MOVE_POS_MATCH_OR_ZV
;
8809 if (it
->line_wrap
== WORD_WRAP
8812 SAVE_IT (atpos_it
, *it
, atpos_data
);
8813 atpos_it
.current_x
= x_before_this_char
;
8814 atpos_it
.hpos
= hpos_before_this_char
;
8818 prev_method
= it
->method
;
8819 if (it
->method
== GET_FROM_BUFFER
)
8820 prev_pos
= IT_CHARPOS (*it
);
8821 set_iterator_to_next (it
, true);
8822 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8823 SET_TEXT_POS (this_line_min_pos
,
8824 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8825 /* On graphical terminals, newlines may
8826 "overflow" into the fringe if
8827 overflow-newline-into-fringe is non-nil.
8828 On text terminals, and on graphical
8829 terminals with no right margin, newlines
8830 may overflow into the last glyph on the
8832 if (!FRAME_WINDOW_P (it
->f
)
8834 && it
->bidi_it
.paragraph_dir
== R2L
)
8835 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8836 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8837 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8839 if (!get_next_display_element (it
))
8841 result
= MOVE_POS_MATCH_OR_ZV
;
8844 if (BUFFER_POS_REACHED_P ())
8846 if (ITERATOR_AT_END_OF_LINE_P (it
))
8847 result
= MOVE_POS_MATCH_OR_ZV
;
8849 result
= MOVE_LINE_CONTINUED
;
8852 if (ITERATOR_AT_END_OF_LINE_P (it
)
8853 && (it
->line_wrap
!= WORD_WRAP
8855 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8857 result
= MOVE_NEWLINE_OR_CR
;
8864 IT_RESET_X_ASCENT_DESCENT (it
);
8866 /* If the screen line ends with whitespace, and we
8867 are under word-wrap, don't use wrap_it: it is no
8868 longer relevant, but we won't have an opportunity
8869 to update it, since we are done with this screen
8871 if (may_wrap
&& IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8873 /* If we've found TO_X, go back there, as we now
8874 know the last word fits on this screen line. */
8875 if ((op
& MOVE_TO_X
) && new_x
== it
->last_visible_x
8878 RESTORE_IT (it
, &atx_it
, atx_data
);
8881 result
= MOVE_X_REACHED
;
8885 else if (wrap_it
.sp
>= 0)
8887 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8892 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8894 result
= MOVE_LINE_CONTINUED
;
8898 if (BUFFER_POS_REACHED_P ())
8900 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8901 goto buffer_pos_reached
;
8902 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8904 SAVE_IT (atpos_it
, *it
, atpos_data
);
8905 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8909 if (new_x
> it
->first_visible_x
)
8911 /* Glyph is visible. Increment number of glyphs that
8912 would be displayed. */
8917 if (result
!= MOVE_UNDEFINED
)
8920 else if (BUFFER_POS_REACHED_P ())
8923 IT_RESET_X_ASCENT_DESCENT (it
);
8924 result
= MOVE_POS_MATCH_OR_ZV
;
8927 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8929 /* Stop when TO_X specified and reached. This check is
8930 necessary here because of lines consisting of a line end,
8931 only. The line end will not produce any glyphs and we
8932 would never get MOVE_X_REACHED. */
8933 eassert (it
->nglyphs
== 0);
8934 result
= MOVE_X_REACHED
;
8938 /* Is this a line end? If yes, we're done. */
8939 if (ITERATOR_AT_END_OF_LINE_P (it
))
8941 /* If we are past TO_CHARPOS, but never saw any character
8942 positions smaller than TO_CHARPOS, return
8943 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8945 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8947 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8949 if (closest_pos
< ZV
)
8951 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8952 /* Don't recurse if closest_pos is equal to
8953 to_charpos, since we have just tried that. */
8954 if (closest_pos
!= to_charpos
)
8955 move_it_in_display_line_to (it
, closest_pos
, -1,
8957 result
= MOVE_POS_MATCH_OR_ZV
;
8960 goto buffer_pos_reached
;
8962 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8963 && IT_CHARPOS (*it
) > to_charpos
)
8964 goto buffer_pos_reached
;
8966 result
= MOVE_NEWLINE_OR_CR
;
8969 result
= MOVE_NEWLINE_OR_CR
;
8973 prev_method
= it
->method
;
8974 if (it
->method
== GET_FROM_BUFFER
)
8975 prev_pos
= IT_CHARPOS (*it
);
8976 /* The current display element has been consumed. Advance
8978 set_iterator_to_next (it
, true);
8979 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8980 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8981 if (IT_CHARPOS (*it
) < to_charpos
)
8982 saw_smaller_pos
= true;
8984 && (op
& MOVE_TO_POS
)
8985 && IT_CHARPOS (*it
) >= to_charpos
8986 && IT_CHARPOS (*it
) < closest_pos
)
8987 closest_pos
= IT_CHARPOS (*it
);
8989 /* Stop if lines are truncated and IT's current x-position is
8990 past the right edge of the window now. */
8991 if (it
->line_wrap
== TRUNCATE
8992 && it
->current_x
>= it
->last_visible_x
)
8994 if (!FRAME_WINDOW_P (it
->f
)
8995 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8996 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8997 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8998 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
9000 bool at_eob_p
= false;
9002 if ((at_eob_p
= !get_next_display_element (it
))
9003 || BUFFER_POS_REACHED_P ()
9004 /* If we are past TO_CHARPOS, but never saw any
9005 character positions smaller than TO_CHARPOS,
9006 return MOVE_POS_MATCH_OR_ZV, like the
9007 unidirectional display did. */
9008 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
9010 && IT_CHARPOS (*it
) > to_charpos
))
9013 && !BUFFER_POS_REACHED_P ()
9014 && !at_eob_p
&& closest_pos
< ZV
)
9016 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9017 if (closest_pos
!= to_charpos
)
9018 move_it_in_display_line_to (it
, closest_pos
, -1,
9021 result
= MOVE_POS_MATCH_OR_ZV
;
9024 if (ITERATOR_AT_END_OF_LINE_P (it
))
9026 result
= MOVE_NEWLINE_OR_CR
;
9030 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
9032 && IT_CHARPOS (*it
) > to_charpos
)
9034 if (closest_pos
< ZV
)
9036 RESTORE_IT (it
, &ppos_it
, ppos_data
);
9037 if (closest_pos
!= to_charpos
)
9038 move_it_in_display_line_to (it
, closest_pos
, -1,
9041 result
= MOVE_POS_MATCH_OR_ZV
;
9044 result
= MOVE_LINE_TRUNCATED
;
9047 #undef IT_RESET_X_ASCENT_DESCENT
9050 #undef BUFFER_POS_REACHED_P
9052 /* If we scanned beyond to_pos and didn't find a point to wrap at,
9053 restore the saved iterator. */
9054 if (atpos_it
.sp
>= 0)
9055 RESTORE_IT (it
, &atpos_it
, atpos_data
);
9056 else if (atx_it
.sp
>= 0)
9057 RESTORE_IT (it
, &atx_it
, atx_data
);
9062 bidi_unshelve_cache (atpos_data
, true);
9064 bidi_unshelve_cache (atx_data
, true);
9066 bidi_unshelve_cache (wrap_data
, true);
9068 bidi_unshelve_cache (ppos_data
, true);
9070 /* Restore the iterator settings altered at the beginning of this
9072 it
->glyph_row
= saved_glyph_row
;
9076 /* For external use. */
9078 move_it_in_display_line (struct it
*it
,
9079 ptrdiff_t to_charpos
, int to_x
,
9080 enum move_operation_enum op
)
9082 if (it
->line_wrap
== WORD_WRAP
9083 && (op
& MOVE_TO_X
))
9086 void *save_data
= NULL
;
9089 SAVE_IT (save_it
, *it
, save_data
);
9090 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9091 /* When word-wrap is on, TO_X may lie past the end
9092 of a wrapped line. Then it->current is the
9093 character on the next line, so backtrack to the
9094 space before the wrap point. */
9095 if (skip
== MOVE_LINE_CONTINUED
)
9097 int prev_x
= max (it
->current_x
- 1, 0);
9098 RESTORE_IT (it
, &save_it
, save_data
);
9099 move_it_in_display_line_to
9100 (it
, -1, prev_x
, MOVE_TO_X
);
9103 bidi_unshelve_cache (save_data
, true);
9106 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9110 /* Move IT forward until it satisfies one or more of the criteria in
9111 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
9113 OP is a bit-mask that specifies where to stop, and in particular,
9114 which of those four position arguments makes a difference. See the
9115 description of enum move_operation_enum.
9117 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
9118 screen line, this function will set IT to the next position that is
9119 displayed to the right of TO_CHARPOS on the screen.
9121 Return the maximum pixel length of any line scanned but never more
9122 than it.last_visible_x. */
9125 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
9127 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
9128 int line_height
, line_start_x
= 0, reached
= 0;
9129 int max_current_x
= 0;
9130 void *backup_data
= NULL
;
9134 if (op
& MOVE_TO_VPOS
)
9136 /* If no TO_CHARPOS and no TO_X specified, stop at the
9137 start of the line TO_VPOS. */
9138 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
9140 if (it
->vpos
== to_vpos
)
9146 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
9150 /* TO_VPOS >= 0 means stop at TO_X in the line at
9151 TO_VPOS, or at TO_POS, whichever comes first. */
9152 if (it
->vpos
== to_vpos
)
9158 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9160 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
9165 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
9167 /* We have reached TO_X but not in the line we want. */
9168 skip
= move_it_in_display_line_to (it
, to_charpos
,
9170 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9178 else if (op
& MOVE_TO_Y
)
9180 struct it it_backup
;
9182 if (it
->line_wrap
== WORD_WRAP
)
9183 SAVE_IT (it_backup
, *it
, backup_data
);
9185 /* TO_Y specified means stop at TO_X in the line containing
9186 TO_Y---or at TO_CHARPOS if this is reached first. The
9187 problem is that we can't really tell whether the line
9188 contains TO_Y before we have completely scanned it, and
9189 this may skip past TO_X. What we do is to first scan to
9192 If TO_X is not specified, use a TO_X of zero. The reason
9193 is to make the outcome of this function more predictable.
9194 If we didn't use TO_X == 0, we would stop at the end of
9195 the line which is probably not what a caller would expect
9197 skip
= move_it_in_display_line_to
9198 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
9199 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
9201 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
9202 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9204 else if (skip
== MOVE_X_REACHED
)
9206 /* If TO_X was reached, we want to know whether TO_Y is
9207 in the line. We know this is the case if the already
9208 scanned glyphs make the line tall enough. Otherwise,
9209 we must check by scanning the rest of the line. */
9210 line_height
= it
->max_ascent
+ it
->max_descent
;
9211 if (to_y
>= it
->current_y
9212 && to_y
< it
->current_y
+ line_height
)
9217 SAVE_IT (it_backup
, *it
, backup_data
);
9218 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
9219 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
9221 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
9222 line_height
= it
->max_ascent
+ it
->max_descent
;
9223 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9225 if (to_y
>= it
->current_y
9226 && to_y
< it
->current_y
+ line_height
)
9228 /* If TO_Y is in this line and TO_X was reached
9229 above, we scanned too far. We have to restore
9230 IT's settings to the ones before skipping. But
9231 keep the more accurate values of max_ascent and
9232 max_descent we've found while skipping the rest
9233 of the line, for the sake of callers, such as
9234 pos_visible_p, that need to know the line
9236 int max_ascent
= it
->max_ascent
;
9237 int max_descent
= it
->max_descent
;
9239 RESTORE_IT (it
, &it_backup
, backup_data
);
9240 it
->max_ascent
= max_ascent
;
9241 it
->max_descent
= max_descent
;
9247 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9253 /* Check whether TO_Y is in this line. */
9254 line_height
= it
->max_ascent
+ it
->max_descent
;
9255 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9257 if (to_y
>= it
->current_y
9258 && to_y
< it
->current_y
+ line_height
)
9260 if (to_y
> it
->current_y
)
9261 max_current_x
= max (it
->current_x
, max_current_x
);
9263 /* When word-wrap is on, TO_X may lie past the end
9264 of a wrapped line. Then it->current is the
9265 character on the next line, so backtrack to the
9266 space before the wrap point. */
9267 if (skip
== MOVE_LINE_CONTINUED
9268 && it
->line_wrap
== WORD_WRAP
)
9270 int prev_x
= max (it
->current_x
- 1, 0);
9271 RESTORE_IT (it
, &it_backup
, backup_data
);
9272 skip
= move_it_in_display_line_to
9273 (it
, -1, prev_x
, MOVE_TO_X
);
9282 max_current_x
= max (it
->current_x
, max_current_x
);
9286 else if (BUFFERP (it
->object
)
9287 && (it
->method
== GET_FROM_BUFFER
9288 || it
->method
== GET_FROM_STRETCH
)
9289 && IT_CHARPOS (*it
) >= to_charpos
9290 /* Under bidi iteration, a call to set_iterator_to_next
9291 can scan far beyond to_charpos if the initial
9292 portion of the next line needs to be reordered. In
9293 that case, give move_it_in_display_line_to another
9296 && it
->bidi_it
.scan_dir
== -1))
9297 skip
= MOVE_POS_MATCH_OR_ZV
;
9299 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9303 case MOVE_POS_MATCH_OR_ZV
:
9304 max_current_x
= max (it
->current_x
, max_current_x
);
9308 case MOVE_NEWLINE_OR_CR
:
9309 max_current_x
= max (it
->current_x
, max_current_x
);
9310 set_iterator_to_next (it
, true);
9311 it
->continuation_lines_width
= 0;
9314 case MOVE_LINE_TRUNCATED
:
9315 max_current_x
= it
->last_visible_x
;
9316 it
->continuation_lines_width
= 0;
9317 reseat_at_next_visible_line_start (it
, false);
9318 if ((op
& MOVE_TO_POS
) != 0
9319 && IT_CHARPOS (*it
) > to_charpos
)
9326 case MOVE_LINE_CONTINUED
:
9327 max_current_x
= it
->last_visible_x
;
9328 /* For continued lines ending in a tab, some of the glyphs
9329 associated with the tab are displayed on the current
9330 line. Since it->current_x does not include these glyphs,
9331 we use it->last_visible_x instead. */
9334 it
->continuation_lines_width
+= it
->last_visible_x
;
9335 /* When moving by vpos, ensure that the iterator really
9336 advances to the next line (bug#847, bug#969). Fixme:
9337 do we need to do this in other circumstances? */
9338 if (it
->current_x
!= it
->last_visible_x
9339 && (op
& MOVE_TO_VPOS
)
9340 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9342 line_start_x
= it
->current_x
+ it
->pixel_width
9343 - it
->last_visible_x
;
9344 if (FRAME_WINDOW_P (it
->f
))
9346 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
9347 struct font
*face_font
= face
->font
;
9349 /* When display_line produces a continued line
9350 that ends in a TAB, it skips a tab stop that
9351 is closer than the font's space character
9352 width (see x_produce_glyphs where it produces
9353 the stretch glyph which represents a TAB).
9354 We need to reproduce the same logic here. */
9355 eassert (face_font
);
9358 if (line_start_x
< face_font
->space_width
)
9360 += it
->tab_width
* face_font
->space_width
;
9363 set_iterator_to_next (it
, false);
9367 it
->continuation_lines_width
+= it
->current_x
;
9374 /* Reset/increment for the next run. */
9375 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9376 it
->current_x
= line_start_x
;
9379 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9381 last_height
= it
->max_ascent
+ it
->max_descent
;
9382 it
->max_ascent
= it
->max_descent
= 0;
9387 /* On text terminals, we may stop at the end of a line in the middle
9388 of a multi-character glyph. If the glyph itself is continued,
9389 i.e. it is actually displayed on the next line, don't treat this
9390 stopping point as valid; move to the next line instead (unless
9391 that brings us offscreen). */
9392 if (!FRAME_WINDOW_P (it
->f
)
9394 && IT_CHARPOS (*it
) == to_charpos
9395 && it
->what
== IT_CHARACTER
9397 && it
->line_wrap
== WINDOW_WRAP
9398 && it
->current_x
== it
->last_visible_x
- 1
9401 && it
->w
->window_end_valid
9402 && it
->vpos
< it
->w
->window_end_vpos
)
9404 it
->continuation_lines_width
+= it
->current_x
;
9405 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9406 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9408 last_height
= it
->max_ascent
+ it
->max_descent
;
9412 bidi_unshelve_cache (backup_data
, true);
9414 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9416 return max_current_x
;
9420 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9422 If DY > 0, move IT backward at least that many pixels. DY = 0
9423 means move IT backward to the preceding line start or BEGV. This
9424 function may move over more than DY pixels if IT->current_y - DY
9425 ends up in the middle of a line; in this case IT->current_y will be
9426 set to the top of the line moved to. */
9429 move_it_vertically_backward (struct it
*it
, int dy
)
9433 void *it2data
= NULL
, *it3data
= NULL
;
9434 ptrdiff_t start_pos
;
9436 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9437 ptrdiff_t pos_limit
;
9442 start_pos
= IT_CHARPOS (*it
);
9444 /* Estimate how many newlines we must move back. */
9445 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9446 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9449 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9451 /* Set the iterator's position that many lines back. But don't go
9452 back more than NLINES full screen lines -- this wins a day with
9453 buffers which have very long lines. */
9454 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9455 back_to_previous_visible_line_start (it
);
9457 /* Reseat the iterator here. When moving backward, we don't want
9458 reseat to skip forward over invisible text, set up the iterator
9459 to deliver from overlay strings at the new position etc. So,
9460 use reseat_1 here. */
9461 reseat_1 (it
, it
->current
.pos
, true);
9463 /* We are now surely at a line start. */
9464 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9465 reordering is in effect. */
9466 it
->continuation_lines_width
= 0;
9468 /* Move forward and see what y-distance we moved. First move to the
9469 start of the next line so that we get its height. We need this
9470 height to be able to tell whether we reached the specified
9472 SAVE_IT (it2
, *it
, it2data
);
9473 it2
.max_ascent
= it2
.max_descent
= 0;
9476 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9477 MOVE_TO_POS
| MOVE_TO_VPOS
);
9479 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9480 /* If we are in a display string which starts at START_POS,
9481 and that display string includes a newline, and we are
9482 right after that newline (i.e. at the beginning of a
9483 display line), exit the loop, because otherwise we will
9484 infloop, since move_it_to will see that it is already at
9485 START_POS and will not move. */
9486 || (it2
.method
== GET_FROM_STRING
9487 && IT_CHARPOS (it2
) == start_pos
9488 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9489 eassert (IT_CHARPOS (*it
) >= BEGV
);
9490 SAVE_IT (it3
, it2
, it3data
);
9492 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9493 eassert (IT_CHARPOS (*it
) >= BEGV
);
9494 /* H is the actual vertical distance from the position in *IT
9495 and the starting position. */
9496 h
= it2
.current_y
- it
->current_y
;
9497 /* NLINES is the distance in number of lines. */
9498 nlines
= it2
.vpos
- it
->vpos
;
9500 /* Correct IT's y and vpos position
9501 so that they are relative to the starting point. */
9507 /* DY == 0 means move to the start of the screen line. The
9508 value of nlines is > 0 if continuation lines were involved,
9509 or if the original IT position was at start of a line. */
9510 RESTORE_IT (it
, it
, it2data
);
9512 move_it_by_lines (it
, nlines
);
9513 /* The above code moves us to some position NLINES down,
9514 usually to its first glyph (leftmost in an L2R line), but
9515 that's not necessarily the start of the line, under bidi
9516 reordering. We want to get to the character position
9517 that is immediately after the newline of the previous
9520 && !it
->continuation_lines_width
9521 && !STRINGP (it
->string
)
9522 && IT_CHARPOS (*it
) > BEGV
9523 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9525 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9528 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9529 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9531 bidi_unshelve_cache (it3data
, true);
9535 /* The y-position we try to reach, relative to *IT.
9536 Note that H has been subtracted in front of the if-statement. */
9537 int target_y
= it
->current_y
+ h
- dy
;
9538 int y0
= it3
.current_y
;
9542 RESTORE_IT (&it3
, &it3
, it3data
);
9543 y1
= line_bottom_y (&it3
);
9544 line_height
= y1
- y0
;
9545 RESTORE_IT (it
, it
, it2data
);
9546 /* If we did not reach target_y, try to move further backward if
9547 we can. If we moved too far backward, try to move forward. */
9548 if (target_y
< it
->current_y
9549 /* This is heuristic. In a window that's 3 lines high, with
9550 a line height of 13 pixels each, recentering with point
9551 on the bottom line will try to move -39/2 = 19 pixels
9552 backward. Try to avoid moving into the first line. */
9553 && (it
->current_y
- target_y
9554 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9555 && IT_CHARPOS (*it
) > BEGV
)
9557 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9558 target_y
- it
->current_y
));
9559 dy
= it
->current_y
- target_y
;
9560 goto move_further_back
;
9562 else if (target_y
>= it
->current_y
+ line_height
9563 && IT_CHARPOS (*it
) < ZV
)
9565 /* Should move forward by at least one line, maybe more.
9567 Note: Calling move_it_by_lines can be expensive on
9568 terminal frames, where compute_motion is used (via
9569 vmotion) to do the job, when there are very long lines
9570 and truncate-lines is nil. That's the reason for
9571 treating terminal frames specially here. */
9573 if (!FRAME_WINDOW_P (it
->f
))
9574 move_it_vertically (it
, target_y
- it
->current_y
);
9579 move_it_by_lines (it
, 1);
9581 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9588 /* Move IT by a specified amount of pixel lines DY. DY negative means
9589 move backwards. DY = 0 means move to start of screen line. At the
9590 end, IT will be on the start of a screen line. */
9593 move_it_vertically (struct it
*it
, int dy
)
9596 move_it_vertically_backward (it
, -dy
);
9599 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9600 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9601 MOVE_TO_POS
| MOVE_TO_Y
);
9602 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9604 /* If buffer ends in ZV without a newline, move to the start of
9605 the line to satisfy the post-condition. */
9606 if (IT_CHARPOS (*it
) == ZV
9608 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9609 move_it_by_lines (it
, 0);
9614 /* Move iterator IT past the end of the text line it is in. */
9617 move_it_past_eol (struct it
*it
)
9619 enum move_it_result rc
;
9621 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9622 if (rc
== MOVE_NEWLINE_OR_CR
)
9623 set_iterator_to_next (it
, false);
9627 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9628 negative means move up. DVPOS == 0 means move to the start of the
9631 Optimization idea: If we would know that IT->f doesn't use
9632 a face with proportional font, we could be faster for
9633 truncate-lines nil. */
9636 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9639 /* The commented-out optimization uses vmotion on terminals. This
9640 gives bad results, because elements like it->what, on which
9641 callers such as pos_visible_p rely, aren't updated. */
9642 /* struct position pos;
9643 if (!FRAME_WINDOW_P (it->f))
9645 struct text_pos textpos;
9647 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9648 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9649 reseat (it, textpos, true);
9650 it->vpos += pos.vpos;
9651 it->current_y += pos.vpos;
9657 /* DVPOS == 0 means move to the start of the screen line. */
9658 move_it_vertically_backward (it
, 0);
9659 /* Let next call to line_bottom_y calculate real line height. */
9664 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9665 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9667 /* Only move to the next buffer position if we ended up in a
9668 string from display property, not in an overlay string
9669 (before-string or after-string). That is because the
9670 latter don't conceal the underlying buffer position, so
9671 we can ask to move the iterator to the exact position we
9672 are interested in. Note that, even if we are already at
9673 IT_CHARPOS (*it), the call below is not a no-op, as it
9674 will detect that we are at the end of the string, pop the
9675 iterator, and compute it->current_x and it->hpos
9677 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9678 -1, -1, -1, MOVE_TO_POS
);
9684 void *it2data
= NULL
;
9685 ptrdiff_t start_charpos
, i
;
9687 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9688 bool hit_pos_limit
= false;
9689 ptrdiff_t pos_limit
;
9691 /* Start at the beginning of the screen line containing IT's
9692 position. This may actually move vertically backwards,
9693 in case of overlays, so adjust dvpos accordingly. */
9695 move_it_vertically_backward (it
, 0);
9698 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9699 screen lines, and reseat the iterator there. */
9700 start_charpos
= IT_CHARPOS (*it
);
9701 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9704 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9706 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9707 back_to_previous_visible_line_start (it
);
9708 if (i
> 0 && IT_CHARPOS (*it
) <= pos_limit
)
9709 hit_pos_limit
= true;
9710 reseat (it
, it
->current
.pos
, true);
9712 /* Move further back if we end up in a string or an image. */
9713 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9715 /* First try to move to start of display line. */
9717 move_it_vertically_backward (it
, 0);
9719 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9721 /* If start of line is still in string or image,
9722 move further back. */
9723 back_to_previous_visible_line_start (it
);
9724 reseat (it
, it
->current
.pos
, true);
9728 it
->current_x
= it
->hpos
= 0;
9730 /* Above call may have moved too far if continuation lines
9731 are involved. Scan forward and see if it did. */
9732 SAVE_IT (it2
, *it
, it2data
);
9733 it2
.vpos
= it2
.current_y
= 0;
9734 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9735 it
->vpos
-= it2
.vpos
;
9736 it
->current_y
-= it2
.current_y
;
9737 it
->current_x
= it
->hpos
= 0;
9739 /* If we moved too far back, move IT some lines forward. */
9740 if (it2
.vpos
> -dvpos
)
9742 int delta
= it2
.vpos
+ dvpos
;
9744 RESTORE_IT (&it2
, &it2
, it2data
);
9745 SAVE_IT (it2
, *it
, it2data
);
9746 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9747 /* Move back again if we got too far ahead. */
9748 if (IT_CHARPOS (*it
) >= start_charpos
)
9749 RESTORE_IT (it
, &it2
, it2data
);
9751 bidi_unshelve_cache (it2data
, true);
9753 else if (hit_pos_limit
&& pos_limit
> BEGV
9754 && dvpos
< 0 && it2
.vpos
< -dvpos
)
9756 /* If we hit the limit, but still didn't make it far enough
9757 back, that means there's a display string with a newline
9758 covering a large chunk of text, and that caused
9759 back_to_previous_visible_line_start try to go too far.
9760 Punish those who commit such atrocities by going back
9761 until we've reached DVPOS, after lifting the limit, which
9762 could make it slow for very long lines. "If it hurts,
9765 RESTORE_IT (it
, it
, it2data
);
9766 for (i
= -dvpos
; i
> 0; --i
)
9768 back_to_previous_visible_line_start (it
);
9771 reseat_1 (it
, it
->current
.pos
, true);
9774 RESTORE_IT (it
, it
, it2data
);
9778 /* Return true if IT points into the middle of a display vector. */
9781 in_display_vector_p (struct it
*it
)
9783 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9784 && it
->current
.dpvec_index
> 0
9785 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9788 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9789 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9790 WINDOW must be a live window and defaults to the selected one. The
9791 return value is a cons of the maximum pixel-width of any text line and
9792 the maximum pixel-height of all text lines.
9794 The optional argument FROM, if non-nil, specifies the first text
9795 position and defaults to the minimum accessible position of the buffer.
9796 If FROM is t, use the minimum accessible position that is not a newline
9797 character. TO, if non-nil, specifies the last text position and
9798 defaults to the maximum accessible position of the buffer. If TO is t,
9799 use the maximum accessible position that is not a newline character.
9801 The optional argument X-LIMIT, if non-nil, specifies the maximum text
9802 width that can be returned. X-LIMIT nil or omitted, means to use the
9803 pixel-width of WINDOW's body; use this if you do not intend to change
9804 the width of WINDOW. Use the maximum width WINDOW may assume if you
9805 intend to change WINDOW's width. In any case, text whose x-coordinate
9806 is beyond X-LIMIT is ignored. Since calculating the width of long lines
9807 can take some time, it's always a good idea to make this argument as
9808 small as possible; in particular, if the buffer contains long lines that
9809 shall be truncated anyway.
9811 The optional argument Y-LIMIT, if non-nil, specifies the maximum text
9812 height that can be returned. Text lines whose y-coordinate is beyond
9813 Y-LIMIT are ignored. Since calculating the text height of a large
9814 buffer can take some time, it makes sense to specify this argument if
9815 the size of the buffer is unknown.
9817 Optional argument MODE-AND-HEADER-LINE nil or omitted means do not
9818 include the height of the mode- or header-line of WINDOW in the return
9819 value. If it is either the symbol `mode-line' or `header-line', include
9820 only the height of that line, if present, in the return value. If t,
9821 include the height of both, if present, in the return value. */)
9822 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
,
9823 Lisp_Object y_limit
, Lisp_Object mode_and_header_line
)
9825 struct window
*w
= decode_live_window (window
);
9826 Lisp_Object buffer
= w
->contents
;
9829 struct buffer
*old_b
= NULL
;
9830 ptrdiff_t start
, end
, pos
;
9831 struct text_pos startp
;
9832 void *itdata
= NULL
;
9833 int c
, max_y
= -1, x
= 0, y
= 0;
9835 CHECK_BUFFER (buffer
);
9836 b
= XBUFFER (buffer
);
9838 if (b
!= current_buffer
)
9840 old_b
= current_buffer
;
9841 set_buffer_internal (b
);
9846 else if (EQ (from
, Qt
))
9849 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9850 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9852 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9857 CHECK_NUMBER_COERCE_MARKER (from
);
9858 start
= min (max (XINT (from
), BEGV
), ZV
);
9863 else if (EQ (to
, Qt
))
9866 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9867 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9869 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9874 CHECK_NUMBER_COERCE_MARKER (to
);
9875 end
= max (start
, min (XINT (to
), ZV
));
9878 if (!NILP (y_limit
))
9880 CHECK_NUMBER (y_limit
);
9881 max_y
= min (XINT (y_limit
), INT_MAX
);
9884 itdata
= bidi_shelve_cache ();
9885 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9886 start_display (&it
, w
, startp
);
9889 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9892 CHECK_NUMBER (x_limit
);
9893 it
.last_visible_x
= min (XINT (x_limit
), INFINITY
);
9894 /* Actually, we never want move_it_to stop at to_x. But to make
9895 sure that move_it_in_display_line_to always moves far enough,
9896 we set it to INT_MAX and specify MOVE_TO_X. */
9897 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9898 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9901 y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9903 if (!EQ (mode_and_header_line
, Qheader_line
)
9904 && !EQ (mode_and_header_line
, Qt
))
9905 /* Do not count the header-line which was counted automatically by
9907 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9909 if (EQ (mode_and_header_line
, Qmode_line
)
9910 || EQ (mode_and_header_line
, Qt
))
9911 /* Do count the mode-line which is not included automatically by
9913 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9915 bidi_unshelve_cache (itdata
, false);
9918 set_buffer_internal (old_b
);
9920 return Fcons (make_number (x
), make_number (y
));
9923 /***********************************************************************
9925 ***********************************************************************/
9927 /* Return the number of arguments the format string FORMAT needs. */
9930 format_nargs (char const *format
)
9932 ptrdiff_t nargs
= 0;
9933 for (char const *p
= format
; (p
= strchr (p
, '%')); p
++)
9941 /* Add a message with format string FORMAT and formatted arguments
9945 add_to_log (const char *format
, ...)
9948 va_start (ap
, format
);
9949 vadd_to_log (format
, ap
);
9954 vadd_to_log (char const *format
, va_list ap
)
9956 ptrdiff_t form_nargs
= format_nargs (format
);
9957 ptrdiff_t nargs
= 1 + form_nargs
;
9958 Lisp_Object args
[10];
9959 eassert (nargs
<= ARRAYELTS (args
));
9960 AUTO_STRING (args0
, format
);
9962 for (ptrdiff_t i
= 1; i
<= nargs
; i
++)
9963 args
[i
] = va_arg (ap
, Lisp_Object
);
9964 Lisp_Object msg
= Qnil
;
9965 msg
= Fformat_message (nargs
, args
);
9967 ptrdiff_t len
= SBYTES (msg
) + 1;
9969 char *buffer
= SAFE_ALLOCA (len
);
9970 memcpy (buffer
, SDATA (msg
), len
);
9972 message_dolog (buffer
, len
- 1, true, STRING_MULTIBYTE (msg
));
9977 /* Output a newline in the *Messages* buffer if "needs" one. */
9980 message_log_maybe_newline (void)
9982 if (message_log_need_newline
)
9983 message_dolog ("", 0, true, false);
9987 /* Add a string M of length NBYTES to the message log, optionally
9988 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9989 true, means interpret the contents of M as multibyte. This
9990 function calls low-level routines in order to bypass text property
9991 hooks, etc. which might not be safe to run.
9993 This may GC (insert may run before/after change hooks),
9994 so the buffer M must NOT point to a Lisp string. */
9997 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9999 const unsigned char *msg
= (const unsigned char *) m
;
10001 if (!NILP (Vmemory_full
))
10004 if (!NILP (Vmessage_log_max
))
10006 struct buffer
*oldbuf
;
10007 Lisp_Object oldpoint
, oldbegv
, oldzv
;
10008 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
10009 ptrdiff_t point_at_end
= 0;
10010 ptrdiff_t zv_at_end
= 0;
10011 Lisp_Object old_deactivate_mark
;
10013 old_deactivate_mark
= Vdeactivate_mark
;
10014 oldbuf
= current_buffer
;
10016 /* Ensure the Messages buffer exists, and switch to it.
10017 If we created it, set the major-mode. */
10018 bool newbuffer
= NILP (Fget_buffer (Vmessages_buffer_name
));
10019 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
10021 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
10022 call0 (intern ("messages-buffer-mode"));
10024 bset_undo_list (current_buffer
, Qt
);
10025 bset_cache_long_scans (current_buffer
, Qnil
);
10027 oldpoint
= message_dolog_marker1
;
10028 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
10029 oldbegv
= message_dolog_marker2
;
10030 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
10031 oldzv
= message_dolog_marker3
;
10032 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
10040 BEGV_BYTE
= BEG_BYTE
;
10043 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10045 /* Insert the string--maybe converting multibyte to single byte
10046 or vice versa, so that all the text fits the buffer. */
10048 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10054 /* Convert a multibyte string to single-byte
10055 for the *Message* buffer. */
10056 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
10058 c
= string_char_and_length (msg
+ i
, &char_bytes
);
10059 work
[0] = CHAR_TO_BYTE8 (c
);
10060 insert_1_both (work
, 1, 1, true, false, false);
10063 else if (! multibyte
10064 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10068 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10069 /* Convert a single-byte string to multibyte
10070 for the *Message* buffer. */
10071 for (i
= 0; i
< nbytes
; i
++)
10074 MAKE_CHAR_MULTIBYTE (c
);
10075 char_bytes
= CHAR_STRING (c
, str
);
10076 insert_1_both ((char *) str
, 1, char_bytes
, true, false, false);
10080 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
,
10081 true, false, false);
10085 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
10088 insert_1_both ("\n", 1, 1, true, false, false);
10090 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, false);
10092 this_bol_byte
= PT_BYTE
;
10094 /* See if this line duplicates the previous one.
10095 If so, combine duplicates. */
10096 if (this_bol
> BEG
)
10098 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, false);
10100 prev_bol_byte
= PT_BYTE
;
10102 dups
= message_log_check_duplicate (prev_bol_byte
,
10106 del_range_both (prev_bol
, prev_bol_byte
,
10107 this_bol
, this_bol_byte
, false);
10110 char dupstr
[sizeof " [ times]"
10111 + INT_STRLEN_BOUND (printmax_t
)];
10113 /* If you change this format, don't forget to also
10114 change message_log_check_duplicate. */
10115 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
10116 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
10117 insert_1_both (dupstr
, duplen
, duplen
,
10118 true, false, true);
10123 /* If we have more than the desired maximum number of lines
10124 in the *Messages* buffer now, delete the oldest ones.
10125 This is safe because we don't have undo in this buffer. */
10127 if (NATNUMP (Vmessage_log_max
))
10129 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
10130 -XFASTINT (Vmessage_log_max
) - 1, false);
10131 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, false);
10134 BEGV
= marker_position (oldbegv
);
10135 BEGV_BYTE
= marker_byte_position (oldbegv
);
10144 ZV
= marker_position (oldzv
);
10145 ZV_BYTE
= marker_byte_position (oldzv
);
10149 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10151 /* We can't do Fgoto_char (oldpoint) because it will run some
10153 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
10154 marker_byte_position (oldpoint
));
10156 unchain_marker (XMARKER (oldpoint
));
10157 unchain_marker (XMARKER (oldbegv
));
10158 unchain_marker (XMARKER (oldzv
));
10160 /* We called insert_1_both above with its 5th argument (PREPARE)
10161 false, which prevents insert_1_both from calling
10162 prepare_to_modify_buffer, which in turns prevents us from
10163 incrementing windows_or_buffers_changed even if *Messages* is
10164 shown in some window. So we must manually set
10165 windows_or_buffers_changed here to make up for that. */
10166 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
10167 bset_redisplay (current_buffer
);
10169 set_buffer_internal (oldbuf
);
10171 message_log_need_newline
= !nlflag
;
10172 Vdeactivate_mark
= old_deactivate_mark
;
10177 /* We are at the end of the buffer after just having inserted a newline.
10178 (Note: We depend on the fact we won't be crossing the gap.)
10179 Check to see if the most recent message looks a lot like the previous one.
10180 Return 0 if different, 1 if the new one should just replace it, or a
10181 value N > 1 if we should also append " [N times]". */
10184 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
10187 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
10188 bool seen_dots
= false;
10189 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
10190 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
10192 for (i
= 0; i
< len
; i
++)
10194 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
10196 if (p1
[i
] != p2
[i
])
10202 if (*p1
++ == ' ' && *p1
++ == '[')
10205 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
10206 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
10213 /* Display an echo area message M with a specified length of NBYTES
10214 bytes. The string may include null characters. If M is not a
10215 string, clear out any existing message, and let the mini-buffer
10218 This function cancels echoing. */
10221 message3 (Lisp_Object m
)
10223 clear_message (true, true);
10226 /* First flush out any partial line written with print. */
10227 message_log_maybe_newline ();
10230 ptrdiff_t nbytes
= SBYTES (m
);
10231 bool multibyte
= STRING_MULTIBYTE (m
);
10234 SAFE_ALLOCA_STRING (buffer
, m
);
10235 message_dolog (buffer
, nbytes
, true, multibyte
);
10238 if (! inhibit_message
)
10239 message3_nolog (m
);
10242 /* Log the message M to stderr. Log an empty line if M is not a string. */
10245 message_to_stderr (Lisp_Object m
)
10247 if (noninteractive_need_newline
)
10249 noninteractive_need_newline
= false;
10250 fputc ('\n', stderr
);
10254 Lisp_Object coding_system
= Vlocale_coding_system
;
10257 if (!NILP (Vcoding_system_for_write
))
10258 coding_system
= Vcoding_system_for_write
;
10259 if (!NILP (coding_system
))
10260 s
= code_convert_string_norecord (m
, coding_system
, true);
10264 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
10266 if (!cursor_in_echo_area
)
10267 fputc ('\n', stderr
);
10271 /* The non-logging version of message3.
10272 This does not cancel echoing, because it is used for echoing.
10273 Perhaps we need to make a separate function for echoing
10274 and make this cancel echoing. */
10277 message3_nolog (Lisp_Object m
)
10279 struct frame
*sf
= SELECTED_FRAME ();
10281 if (FRAME_INITIAL_P (sf
))
10282 message_to_stderr (m
);
10283 /* Error messages get reported properly by cmd_error, so this must be just an
10284 informative message; if the frame hasn't really been initialized yet, just
10286 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
10288 /* Get the frame containing the mini-buffer
10289 that the selected frame is using. */
10290 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10291 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
10292 struct frame
*f
= XFRAME (frame
);
10294 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
10295 Fmake_frame_visible (frame
);
10297 if (STRINGP (m
) && SCHARS (m
) > 0)
10300 if (minibuffer_auto_raise
)
10301 Fraise_frame (frame
);
10302 /* Assume we are not echoing.
10303 (If we are, echo_now will override this.) */
10304 echo_message_buffer
= Qnil
;
10307 clear_message (true, true);
10309 do_pending_window_change (false);
10310 echo_area_display (true);
10311 do_pending_window_change (false);
10312 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
10313 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
10318 /* Display a null-terminated echo area message M. If M is 0, clear
10319 out any existing message, and let the mini-buffer text show through.
10321 The buffer M must continue to exist until after the echo area gets
10322 cleared or some other message gets displayed there. Do not pass
10323 text that is stored in a Lisp string. Do not pass text in a buffer
10324 that was alloca'd. */
10327 message1 (const char *m
)
10329 message3 (m
? build_unibyte_string (m
) : Qnil
);
10333 /* The non-logging counterpart of message1. */
10336 message1_nolog (const char *m
)
10338 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10341 /* Display a message M which contains a single %s
10342 which gets replaced with STRING. */
10345 message_with_string (const char *m
, Lisp_Object string
, bool log
)
10347 CHECK_STRING (string
);
10350 if (noninteractive
)
10351 need_message
= !!m
;
10352 else if (!INTERACTIVE
)
10353 need_message
= false;
10356 /* The frame whose minibuffer we're going to display the message on.
10357 It may be larger than the selected frame, so we need
10358 to use its buffer, not the selected frame's buffer. */
10359 Lisp_Object mini_window
;
10360 struct frame
*f
, *sf
= SELECTED_FRAME ();
10362 /* Get the frame containing the minibuffer
10363 that the selected frame is using. */
10364 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10365 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10367 /* Error messages get reported properly by cmd_error, so this must be
10368 just an informative message; if the frame hasn't really been
10369 initialized yet, just toss it. */
10370 need_message
= f
->glyphs_initialized_p
;
10375 AUTO_STRING (fmt
, m
);
10376 Lisp_Object msg
= CALLN (Fformat_message
, fmt
, string
);
10378 if (noninteractive
)
10379 message_to_stderr (msg
);
10385 message3_nolog (msg
);
10387 /* Print should start at the beginning of the message
10388 buffer next time. */
10389 message_buf_print
= false;
10395 /* Dump an informative message to the minibuf. If M is 0, clear out
10396 any existing message, and let the mini-buffer text show through.
10398 The message must be safe ASCII and the format must not contain ` or
10399 '. If your message and format do not fit into this category,
10400 convert your arguments to Lisp objects and use Fmessage instead. */
10402 static void ATTRIBUTE_FORMAT_PRINTF (1, 0)
10403 vmessage (const char *m
, va_list ap
)
10405 if (noninteractive
)
10409 if (noninteractive_need_newline
)
10410 putc ('\n', stderr
);
10411 noninteractive_need_newline
= false;
10412 vfprintf (stderr
, m
, ap
);
10413 if (!cursor_in_echo_area
)
10414 fprintf (stderr
, "\n");
10418 else if (INTERACTIVE
)
10420 /* The frame whose mini-buffer we're going to display the message
10421 on. It may be larger than the selected frame, so we need to
10422 use its buffer, not the selected frame's buffer. */
10423 Lisp_Object mini_window
;
10424 struct frame
*f
, *sf
= SELECTED_FRAME ();
10426 /* Get the frame containing the mini-buffer
10427 that the selected frame is using. */
10428 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10429 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10431 /* Error messages get reported properly by cmd_error, so this must be
10432 just an informative message; if the frame hasn't really been
10433 initialized yet, just toss it. */
10434 if (f
->glyphs_initialized_p
)
10439 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10441 char *message_buf
= SAFE_ALLOCA (maxsize
+ 1);
10443 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10445 message3 (make_string (message_buf
, len
));
10451 /* Print should start at the beginning of the message
10452 buffer next time. */
10453 message_buf_print
= false;
10459 message (const char *m
, ...)
10468 /* Display the current message in the current mini-buffer. This is
10469 only called from error handlers in process.c, and is not time
10473 update_echo_area (void)
10475 if (!NILP (echo_area_buffer
[0]))
10477 Lisp_Object string
;
10478 string
= Fcurrent_message ();
10484 /* Make sure echo area buffers in `echo_buffers' are live.
10485 If they aren't, make new ones. */
10488 ensure_echo_area_buffers (void)
10492 for (i
= 0; i
< 2; ++i
)
10493 if (!BUFFERP (echo_buffer
[i
])
10494 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10497 Lisp_Object old_buffer
;
10500 old_buffer
= echo_buffer
[i
];
10501 echo_buffer
[i
] = Fget_buffer_create
10502 (make_formatted_string (name
, " *Echo Area %d*", i
));
10503 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10504 /* to force word wrap in echo area -
10505 it was decided to postpone this*/
10506 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10508 for (j
= 0; j
< 2; ++j
)
10509 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10510 echo_area_buffer
[j
] = echo_buffer
[i
];
10515 /* Call FN with args A1..A2 with either the current or last displayed
10516 echo_area_buffer as current buffer.
10518 WHICH zero means use the current message buffer
10519 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10520 from echo_buffer[] and clear it.
10522 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10523 suitable buffer from echo_buffer[] and clear it.
10525 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10526 that the current message becomes the last displayed one, make
10527 choose a suitable buffer for echo_area_buffer[0], and clear it.
10529 Value is what FN returns. */
10532 with_echo_area_buffer (struct window
*w
, int which
,
10533 bool (*fn
) (ptrdiff_t, Lisp_Object
),
10534 ptrdiff_t a1
, Lisp_Object a2
)
10536 Lisp_Object buffer
;
10537 bool this_one
, the_other
, clear_buffer_p
, rc
;
10538 ptrdiff_t count
= SPECPDL_INDEX ();
10540 /* If buffers aren't live, make new ones. */
10541 ensure_echo_area_buffers ();
10543 clear_buffer_p
= false;
10546 this_one
= false, the_other
= true;
10547 else if (which
> 0)
10548 this_one
= true, the_other
= false;
10551 this_one
= false, the_other
= true;
10552 clear_buffer_p
= true;
10554 /* We need a fresh one in case the current echo buffer equals
10555 the one containing the last displayed echo area message. */
10556 if (!NILP (echo_area_buffer
[this_one
])
10557 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10558 echo_area_buffer
[this_one
] = Qnil
;
10561 /* Choose a suitable buffer from echo_buffer[] is we don't
10563 if (NILP (echo_area_buffer
[this_one
]))
10565 echo_area_buffer
[this_one
]
10566 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10567 ? echo_buffer
[the_other
]
10568 : echo_buffer
[this_one
]);
10569 clear_buffer_p
= true;
10572 buffer
= echo_area_buffer
[this_one
];
10574 /* Don't get confused by reusing the buffer used for echoing
10575 for a different purpose. */
10576 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10579 record_unwind_protect (unwind_with_echo_area_buffer
,
10580 with_echo_area_buffer_unwind_data (w
));
10582 /* Make the echo area buffer current. Note that for display
10583 purposes, it is not necessary that the displayed window's buffer
10584 == current_buffer, except for text property lookup. So, let's
10585 only set that buffer temporarily here without doing a full
10586 Fset_window_buffer. We must also change w->pointm, though,
10587 because otherwise an assertions in unshow_buffer fails, and Emacs
10589 set_buffer_internal_1 (XBUFFER (buffer
));
10592 wset_buffer (w
, buffer
);
10593 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10594 set_marker_both (w
->old_pointm
, buffer
, BEG
, BEG_BYTE
);
10597 bset_undo_list (current_buffer
, Qt
);
10598 bset_read_only (current_buffer
, Qnil
);
10599 specbind (Qinhibit_read_only
, Qt
);
10600 specbind (Qinhibit_modification_hooks
, Qt
);
10602 if (clear_buffer_p
&& Z
> BEG
)
10603 del_range (BEG
, Z
);
10605 eassert (BEGV
>= BEG
);
10606 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10610 eassert (BEGV
>= BEG
);
10611 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10613 unbind_to (count
, Qnil
);
10618 /* Save state that should be preserved around the call to the function
10619 FN called in with_echo_area_buffer. */
10622 with_echo_area_buffer_unwind_data (struct window
*w
)
10625 Lisp_Object vector
, tmp
;
10627 /* Reduce consing by keeping one vector in
10628 Vwith_echo_area_save_vector. */
10629 vector
= Vwith_echo_area_save_vector
;
10630 Vwith_echo_area_save_vector
= Qnil
;
10633 vector
= Fmake_vector (make_number (11), Qnil
);
10635 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10636 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10637 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10641 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10642 ASET (vector
, i
, w
->contents
); ++i
;
10643 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10644 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10645 ASET (vector
, i
, make_number (marker_position (w
->old_pointm
))); ++i
;
10646 ASET (vector
, i
, make_number (marker_byte_position (w
->old_pointm
))); ++i
;
10647 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10648 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10653 for (; i
< end
; ++i
)
10654 ASET (vector
, i
, Qnil
);
10657 eassert (i
== ASIZE (vector
));
10662 /* Restore global state from VECTOR which was created by
10663 with_echo_area_buffer_unwind_data. */
10666 unwind_with_echo_area_buffer (Lisp_Object vector
)
10668 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10669 Vdeactivate_mark
= AREF (vector
, 1);
10670 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10672 if (WINDOWP (AREF (vector
, 3)))
10675 Lisp_Object buffer
;
10677 w
= XWINDOW (AREF (vector
, 3));
10678 buffer
= AREF (vector
, 4);
10680 wset_buffer (w
, buffer
);
10681 set_marker_both (w
->pointm
, buffer
,
10682 XFASTINT (AREF (vector
, 5)),
10683 XFASTINT (AREF (vector
, 6)));
10684 set_marker_both (w
->old_pointm
, buffer
,
10685 XFASTINT (AREF (vector
, 7)),
10686 XFASTINT (AREF (vector
, 8)));
10687 set_marker_both (w
->start
, buffer
,
10688 XFASTINT (AREF (vector
, 9)),
10689 XFASTINT (AREF (vector
, 10)));
10692 Vwith_echo_area_save_vector
= vector
;
10696 /* Set up the echo area for use by print functions. MULTIBYTE_P
10697 means we will print multibyte. */
10700 setup_echo_area_for_printing (bool multibyte_p
)
10702 /* If we can't find an echo area any more, exit. */
10703 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10704 Fkill_emacs (Qnil
);
10706 ensure_echo_area_buffers ();
10708 if (!message_buf_print
)
10710 /* A message has been output since the last time we printed.
10711 Choose a fresh echo area buffer. */
10712 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10713 echo_area_buffer
[0] = echo_buffer
[1];
10715 echo_area_buffer
[0] = echo_buffer
[0];
10717 /* Switch to that buffer and clear it. */
10718 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10719 bset_truncate_lines (current_buffer
, Qnil
);
10723 ptrdiff_t count
= SPECPDL_INDEX ();
10724 specbind (Qinhibit_read_only
, Qt
);
10725 /* Note that undo recording is always disabled. */
10726 del_range (BEG
, Z
);
10727 unbind_to (count
, Qnil
);
10729 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10731 /* Set up the buffer for the multibyteness we need. */
10733 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10734 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10736 /* Raise the frame containing the echo area. */
10737 if (minibuffer_auto_raise
)
10739 struct frame
*sf
= SELECTED_FRAME ();
10740 Lisp_Object mini_window
;
10741 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10742 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10745 message_log_maybe_newline ();
10746 message_buf_print
= true;
10750 if (NILP (echo_area_buffer
[0]))
10752 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10753 echo_area_buffer
[0] = echo_buffer
[1];
10755 echo_area_buffer
[0] = echo_buffer
[0];
10758 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10760 /* Someone switched buffers between print requests. */
10761 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10762 bset_truncate_lines (current_buffer
, Qnil
);
10768 /* Display an echo area message in window W. Value is true if W's
10769 height is changed. If display_last_displayed_message_p,
10770 display the message that was last displayed, otherwise
10771 display the current message. */
10774 display_echo_area (struct window
*w
)
10776 bool no_message_p
, window_height_changed_p
;
10778 /* Temporarily disable garbage collections while displaying the echo
10779 area. This is done because a GC can print a message itself.
10780 That message would modify the echo area buffer's contents while a
10781 redisplay of the buffer is going on, and seriously confuse
10783 ptrdiff_t count
= inhibit_garbage_collection ();
10785 /* If there is no message, we must call display_echo_area_1
10786 nevertheless because it resizes the window. But we will have to
10787 reset the echo_area_buffer in question to nil at the end because
10788 with_echo_area_buffer will sets it to an empty buffer. */
10789 bool i
= display_last_displayed_message_p
;
10790 /* According to the C99, C11 and C++11 standards, the integral value
10791 of a "bool" is always 0 or 1, so this array access is safe here,
10793 no_message_p
= NILP (echo_area_buffer
[i
]);
10795 window_height_changed_p
10796 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10797 display_echo_area_1
,
10798 (intptr_t) w
, Qnil
);
10801 echo_area_buffer
[i
] = Qnil
;
10803 unbind_to (count
, Qnil
);
10804 return window_height_changed_p
;
10808 /* Helper for display_echo_area. Display the current buffer which
10809 contains the current echo area message in window W, a mini-window,
10810 a pointer to which is passed in A1. A2..A4 are currently not used.
10811 Change the height of W so that all of the message is displayed.
10812 Value is true if height of W was changed. */
10815 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10818 struct window
*w
= (struct window
*) i1
;
10819 Lisp_Object window
;
10820 struct text_pos start
;
10822 /* We are about to enter redisplay without going through
10823 redisplay_internal, so we need to forget these faces by hand
10825 forget_escape_and_glyphless_faces ();
10827 /* Do this before displaying, so that we have a large enough glyph
10828 matrix for the display. If we can't get enough space for the
10829 whole text, display the last N lines. That works by setting w->start. */
10830 bool window_height_changed_p
= resize_mini_window (w
, false);
10832 /* Use the starting position chosen by resize_mini_window. */
10833 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10836 clear_glyph_matrix (w
->desired_matrix
);
10837 XSETWINDOW (window
, w
);
10838 try_window (window
, start
, 0);
10840 return window_height_changed_p
;
10844 /* Resize the echo area window to exactly the size needed for the
10845 currently displayed message, if there is one. If a mini-buffer
10846 is active, don't shrink it. */
10849 resize_echo_area_exactly (void)
10851 if (BUFFERP (echo_area_buffer
[0])
10852 && WINDOWP (echo_area_window
))
10854 struct window
*w
= XWINDOW (echo_area_window
);
10855 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10856 bool resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10857 (intptr_t) w
, resize_exactly
);
10860 windows_or_buffers_changed
= 42;
10861 update_mode_lines
= 30;
10862 redisplay_internal ();
10868 /* Callback function for with_echo_area_buffer, when used from
10869 resize_echo_area_exactly. A1 contains a pointer to the window to
10870 resize, EXACTLY non-nil means resize the mini-window exactly to the
10871 size of the text displayed. A3 and A4 are not used. Value is what
10872 resize_mini_window returns. */
10875 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10878 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10882 /* Resize mini-window W to fit the size of its contents. EXACT_P
10883 means size the window exactly to the size needed. Otherwise, it's
10884 only enlarged until W's buffer is empty.
10886 Set W->start to the right place to begin display. If the whole
10887 contents fit, start at the beginning. Otherwise, start so as
10888 to make the end of the contents appear. This is particularly
10889 important for y-or-n-p, but seems desirable generally.
10891 Value is true if the window height has been changed. */
10894 resize_mini_window (struct window
*w
, bool exact_p
)
10896 struct frame
*f
= XFRAME (w
->frame
);
10897 bool window_height_changed_p
= false;
10899 eassert (MINI_WINDOW_P (w
));
10901 /* By default, start display at the beginning. */
10902 set_marker_both (w
->start
, w
->contents
,
10903 BUF_BEGV (XBUFFER (w
->contents
)),
10904 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10906 /* Don't resize windows while redisplaying a window; it would
10907 confuse redisplay functions when the size of the window they are
10908 displaying changes from under them. Such a resizing can happen,
10909 for instance, when which-func prints a long message while
10910 we are running fontification-functions. We're running these
10911 functions with safe_call which binds inhibit-redisplay to t. */
10912 if (!NILP (Vinhibit_redisplay
))
10915 /* Nil means don't try to resize. */
10916 if (NILP (Vresize_mini_windows
)
10917 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10920 if (!FRAME_MINIBUF_ONLY_P (f
))
10923 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10924 + WINDOW_PIXEL_HEIGHT (w
));
10925 int unit
= FRAME_LINE_HEIGHT (f
);
10926 int height
, max_height
;
10927 struct text_pos start
;
10928 struct buffer
*old_current_buffer
= NULL
;
10930 if (current_buffer
!= XBUFFER (w
->contents
))
10932 old_current_buffer
= current_buffer
;
10933 set_buffer_internal (XBUFFER (w
->contents
));
10936 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10938 /* Compute the max. number of lines specified by the user. */
10939 if (FLOATP (Vmax_mini_window_height
))
10940 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10941 else if (INTEGERP (Vmax_mini_window_height
))
10942 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10944 max_height
= total_height
/ 4;
10946 /* Correct that max. height if it's bogus. */
10947 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10949 /* Find out the height of the text in the window. */
10950 if (it
.line_wrap
== TRUNCATE
)
10955 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10956 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10957 height
= it
.current_y
+ last_height
;
10959 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10960 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10963 /* Compute a suitable window start. */
10964 if (height
> max_height
)
10966 height
= (max_height
/ unit
) * unit
;
10967 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10968 move_it_vertically_backward (&it
, height
- unit
);
10969 start
= it
.current
.pos
;
10972 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10973 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10975 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10977 /* Let it grow only, until we display an empty message, in which
10978 case the window shrinks again. */
10979 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10981 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10983 FRAME_WINDOWS_FROZEN (f
) = true;
10984 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
10985 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10987 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10988 && (exact_p
|| BEGV
== ZV
))
10990 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10992 FRAME_WINDOWS_FROZEN (f
) = false;
10993 shrink_mini_window (w
, true);
10994 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10999 /* Always resize to exact size needed. */
11000 if (height
> WINDOW_PIXEL_HEIGHT (w
))
11002 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11004 FRAME_WINDOWS_FROZEN (f
) = true;
11005 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
11006 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11008 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
11010 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
11012 FRAME_WINDOWS_FROZEN (f
) = false;
11013 shrink_mini_window (w
, true);
11017 FRAME_WINDOWS_FROZEN (f
) = true;
11018 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), true);
11021 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
11025 if (old_current_buffer
)
11026 set_buffer_internal (old_current_buffer
);
11029 return window_height_changed_p
;
11033 /* Value is the current message, a string, or nil if there is no
11034 current message. */
11037 current_message (void)
11041 if (!BUFFERP (echo_area_buffer
[0]))
11045 with_echo_area_buffer (0, 0, current_message_1
,
11046 (intptr_t) &msg
, Qnil
);
11048 echo_area_buffer
[0] = Qnil
;
11056 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
11059 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
11062 *msg
= make_buffer_string (BEG
, Z
, true);
11069 /* Push the current message on Vmessage_stack for later restoration
11070 by restore_message. Value is true if the current message isn't
11071 empty. This is a relatively infrequent operation, so it's not
11072 worth optimizing. */
11075 push_message (void)
11077 Lisp_Object msg
= current_message ();
11078 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
11079 return STRINGP (msg
);
11083 /* Restore message display from the top of Vmessage_stack. */
11086 restore_message (void)
11088 eassert (CONSP (Vmessage_stack
));
11089 message3_nolog (XCAR (Vmessage_stack
));
11093 /* Handler for unwind-protect calling pop_message. */
11096 pop_message_unwind (void)
11098 /* Pop the top-most entry off Vmessage_stack. */
11099 eassert (CONSP (Vmessage_stack
));
11100 Vmessage_stack
= XCDR (Vmessage_stack
);
11104 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
11105 exits. If the stack is not empty, we have a missing pop_message
11109 check_message_stack (void)
11111 if (!NILP (Vmessage_stack
))
11116 /* Truncate to NCHARS what will be displayed in the echo area the next
11117 time we display it---but don't redisplay it now. */
11120 truncate_echo_area (ptrdiff_t nchars
)
11123 echo_area_buffer
[0] = Qnil
;
11124 else if (!noninteractive
11126 && !NILP (echo_area_buffer
[0]))
11128 struct frame
*sf
= SELECTED_FRAME ();
11129 /* Error messages get reported properly by cmd_error, so this must be
11130 just an informative message; if the frame hasn't really been
11131 initialized yet, just toss it. */
11132 if (sf
->glyphs_initialized_p
)
11133 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
11138 /* Helper function for truncate_echo_area. Truncate the current
11139 message to at most NCHARS characters. */
11142 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
11144 if (BEG
+ nchars
< Z
)
11145 del_range (BEG
+ nchars
, Z
);
11147 echo_area_buffer
[0] = Qnil
;
11151 /* Set the current message to STRING. */
11154 set_message (Lisp_Object string
)
11156 eassert (STRINGP (string
));
11158 message_enable_multibyte
= STRING_MULTIBYTE (string
);
11160 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
11161 message_buf_print
= false;
11162 help_echo_showing_p
= false;
11164 if (STRINGP (Vdebug_on_message
)
11165 && STRINGP (string
)
11166 && fast_string_match (Vdebug_on_message
, string
) >= 0)
11167 call_debugger (list2 (Qerror
, string
));
11171 /* Helper function for set_message. First argument is ignored and second
11172 argument has the same meaning as for set_message.
11173 This function is called with the echo area buffer being current. */
11176 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
11178 eassert (STRINGP (string
));
11180 /* Change multibyteness of the echo buffer appropriately. */
11181 if (message_enable_multibyte
11182 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
11183 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
11185 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
11186 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
11187 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
11189 /* Insert new message at BEG. */
11190 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
11192 /* This function takes care of single/multibyte conversion.
11193 We just have to ensure that the echo area buffer has the right
11194 setting of enable_multibyte_characters. */
11195 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), true);
11201 /* Clear messages. CURRENT_P means clear the current message.
11202 LAST_DISPLAYED_P means clear the message last displayed. */
11205 clear_message (bool current_p
, bool last_displayed_p
)
11209 echo_area_buffer
[0] = Qnil
;
11210 message_cleared_p
= true;
11213 if (last_displayed_p
)
11214 echo_area_buffer
[1] = Qnil
;
11216 message_buf_print
= false;
11219 /* Clear garbaged frames.
11221 This function is used where the old redisplay called
11222 redraw_garbaged_frames which in turn called redraw_frame which in
11223 turn called clear_frame. The call to clear_frame was a source of
11224 flickering. I believe a clear_frame is not necessary. It should
11225 suffice in the new redisplay to invalidate all current matrices,
11226 and ensure a complete redisplay of all windows. */
11229 clear_garbaged_frames (void)
11231 if (frame_garbaged
)
11233 Lisp_Object tail
, frame
;
11235 FOR_EACH_FRAME (tail
, frame
)
11237 struct frame
*f
= XFRAME (frame
);
11239 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
11244 clear_current_matrices (f
);
11245 fset_redisplay (f
);
11246 f
->garbaged
= false;
11247 f
->resized_p
= false;
11251 frame_garbaged
= false;
11256 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P, update
11260 echo_area_display (bool update_frame_p
)
11262 Lisp_Object mini_window
;
11265 bool window_height_changed_p
= false;
11266 struct frame
*sf
= SELECTED_FRAME ();
11268 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11269 w
= XWINDOW (mini_window
);
11270 f
= XFRAME (WINDOW_FRAME (w
));
11272 /* Don't display if frame is invisible or not yet initialized. */
11273 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
11276 #ifdef HAVE_WINDOW_SYSTEM
11277 /* When Emacs starts, selected_frame may be the initial terminal
11278 frame. If we let this through, a message would be displayed on
11280 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
11282 #endif /* HAVE_WINDOW_SYSTEM */
11284 /* Redraw garbaged frames. */
11285 clear_garbaged_frames ();
11287 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
11289 echo_area_window
= mini_window
;
11290 window_height_changed_p
= display_echo_area (w
);
11291 w
->must_be_updated_p
= true;
11293 /* Update the display, unless called from redisplay_internal.
11294 Also don't update the screen during redisplay itself. The
11295 update will happen at the end of redisplay, and an update
11296 here could cause confusion. */
11297 if (update_frame_p
&& !redisplaying_p
)
11301 /* If the display update has been interrupted by pending
11302 input, update mode lines in the frame. Due to the
11303 pending input, it might have been that redisplay hasn't
11304 been called, so that mode lines above the echo area are
11305 garbaged. This looks odd, so we prevent it here. */
11306 if (!display_completed
)
11307 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11309 if (window_height_changed_p
11310 /* Don't do this if Emacs is shutting down. Redisplay
11311 needs to run hooks. */
11312 && !NILP (Vrun_hooks
))
11314 /* Must update other windows. Likewise as in other
11315 cases, don't let this update be interrupted by
11317 ptrdiff_t count
= SPECPDL_INDEX ();
11318 specbind (Qredisplay_dont_pause
, Qt
);
11319 fset_redisplay (f
);
11320 redisplay_internal ();
11321 unbind_to (count
, Qnil
);
11323 else if (FRAME_WINDOW_P (f
) && n
== 0)
11325 /* Window configuration is the same as before.
11326 Can do with a display update of the echo area,
11327 unless we displayed some mode lines. */
11328 update_single_window (w
);
11332 update_frame (f
, true, true);
11334 /* If cursor is in the echo area, make sure that the next
11335 redisplay displays the minibuffer, so that the cursor will
11336 be replaced with what the minibuffer wants. */
11337 if (cursor_in_echo_area
)
11338 wset_redisplay (XWINDOW (mini_window
));
11341 else if (!EQ (mini_window
, selected_window
))
11342 wset_redisplay (XWINDOW (mini_window
));
11344 /* Last displayed message is now the current message. */
11345 echo_area_buffer
[1] = echo_area_buffer
[0];
11346 /* Inform read_char that we're not echoing. */
11347 echo_message_buffer
= Qnil
;
11349 /* Prevent redisplay optimization in redisplay_internal by resetting
11350 this_line_start_pos. This is done because the mini-buffer now
11351 displays the message instead of its buffer text. */
11352 if (EQ (mini_window
, selected_window
))
11353 CHARPOS (this_line_start_pos
) = 0;
11355 if (window_height_changed_p
)
11357 fset_redisplay (f
);
11359 /* If window configuration was changed, frames may have been
11360 marked garbaged. Clear them or we will experience
11361 surprises wrt scrolling.
11362 FIXME: How/why/when? */
11363 clear_garbaged_frames ();
11367 /* True if W's buffer was changed but not saved. */
11370 window_buffer_changed (struct window
*w
)
11372 struct buffer
*b
= XBUFFER (w
->contents
);
11374 eassert (BUFFER_LIVE_P (b
));
11376 return (BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
;
11379 /* True if W has %c in its mode line and mode line should be updated. */
11382 mode_line_update_needed (struct window
*w
)
11384 return (w
->column_number_displayed
!= -1
11385 && !(PT
== w
->last_point
&& !window_outdated (w
))
11386 && (w
->column_number_displayed
!= current_column ()));
11389 /* True if window start of W is frozen and may not be changed during
11393 window_frozen_p (struct window
*w
)
11395 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11397 Lisp_Object window
;
11399 XSETWINDOW (window
, w
);
11400 if (MINI_WINDOW_P (w
))
11402 else if (EQ (window
, selected_window
))
11404 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11405 && EQ (window
, Vminibuf_scroll_window
))
11406 /* This special window can't be frozen too. */
11414 /***********************************************************************
11415 Mode Lines and Frame Titles
11416 ***********************************************************************/
11418 /* A buffer for constructing non-propertized mode-line strings and
11419 frame titles in it; allocated from the heap in init_xdisp and
11420 resized as needed in store_mode_line_noprop_char. */
11422 static char *mode_line_noprop_buf
;
11424 /* The buffer's end, and a current output position in it. */
11426 static char *mode_line_noprop_buf_end
;
11427 static char *mode_line_noprop_ptr
;
11429 #define MODE_LINE_NOPROP_LEN(start) \
11430 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11433 MODE_LINE_DISPLAY
= 0,
11437 } mode_line_target
;
11439 /* Alist that caches the results of :propertize.
11440 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11441 static Lisp_Object mode_line_proptrans_alist
;
11443 /* List of strings making up the mode-line. */
11444 static Lisp_Object mode_line_string_list
;
11446 /* Base face property when building propertized mode line string. */
11447 static Lisp_Object mode_line_string_face
;
11448 static Lisp_Object mode_line_string_face_prop
;
11451 /* Unwind data for mode line strings */
11453 static Lisp_Object Vmode_line_unwind_vector
;
11456 format_mode_line_unwind_data (struct frame
*target_frame
,
11457 struct buffer
*obuf
,
11459 bool save_proptrans
)
11461 Lisp_Object vector
, tmp
;
11463 /* Reduce consing by keeping one vector in
11464 Vwith_echo_area_save_vector. */
11465 vector
= Vmode_line_unwind_vector
;
11466 Vmode_line_unwind_vector
= Qnil
;
11469 vector
= Fmake_vector (make_number (10), Qnil
);
11471 ASET (vector
, 0, make_number (mode_line_target
));
11472 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11473 ASET (vector
, 2, mode_line_string_list
);
11474 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11475 ASET (vector
, 4, mode_line_string_face
);
11476 ASET (vector
, 5, mode_line_string_face_prop
);
11479 XSETBUFFER (tmp
, obuf
);
11482 ASET (vector
, 6, tmp
);
11483 ASET (vector
, 7, owin
);
11486 /* Similarly to `with-selected-window', if the operation selects
11487 a window on another frame, we must restore that frame's
11488 selected window, and (for a tty) the top-frame. */
11489 ASET (vector
, 8, target_frame
->selected_window
);
11490 if (FRAME_TERMCAP_P (target_frame
))
11491 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11498 unwind_format_mode_line (Lisp_Object vector
)
11500 Lisp_Object old_window
= AREF (vector
, 7);
11501 Lisp_Object target_frame_window
= AREF (vector
, 8);
11502 Lisp_Object old_top_frame
= AREF (vector
, 9);
11504 mode_line_target
= XINT (AREF (vector
, 0));
11505 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11506 mode_line_string_list
= AREF (vector
, 2);
11507 if (! EQ (AREF (vector
, 3), Qt
))
11508 mode_line_proptrans_alist
= AREF (vector
, 3);
11509 mode_line_string_face
= AREF (vector
, 4);
11510 mode_line_string_face_prop
= AREF (vector
, 5);
11512 /* Select window before buffer, since it may change the buffer. */
11513 if (!NILP (old_window
))
11515 /* If the operation that we are unwinding had selected a window
11516 on a different frame, reset its frame-selected-window. For a
11517 text terminal, reset its top-frame if necessary. */
11518 if (!NILP (target_frame_window
))
11521 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11523 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11524 Fselect_window (target_frame_window
, Qt
);
11526 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11527 Fselect_frame (old_top_frame
, Qt
);
11530 Fselect_window (old_window
, Qt
);
11533 if (!NILP (AREF (vector
, 6)))
11535 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11536 ASET (vector
, 6, Qnil
);
11539 Vmode_line_unwind_vector
= vector
;
11543 /* Store a single character C for the frame title in mode_line_noprop_buf.
11544 Re-allocate mode_line_noprop_buf if necessary. */
11547 store_mode_line_noprop_char (char c
)
11549 /* If output position has reached the end of the allocated buffer,
11550 increase the buffer's size. */
11551 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11553 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11554 ptrdiff_t size
= len
;
11555 mode_line_noprop_buf
=
11556 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11557 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11558 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11561 *mode_line_noprop_ptr
++ = c
;
11565 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11566 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11567 characters that yield more columns than PRECISION; PRECISION <= 0
11568 means copy the whole string. Pad with spaces until FIELD_WIDTH
11569 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11570 pad. Called from display_mode_element when it is used to build a
11574 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11576 const unsigned char *str
= (const unsigned char *) string
;
11578 ptrdiff_t dummy
, nbytes
;
11580 /* Copy at most PRECISION chars from STR. */
11581 nbytes
= strlen (string
);
11582 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11584 store_mode_line_noprop_char (*str
++);
11586 /* Fill up with spaces until FIELD_WIDTH reached. */
11587 while (field_width
> 0
11588 && n
< field_width
)
11590 store_mode_line_noprop_char (' ');
11597 /***********************************************************************
11599 ***********************************************************************/
11601 #ifdef HAVE_WINDOW_SYSTEM
11603 /* Set the title of FRAME, if it has changed. The title format is
11604 Vicon_title_format if FRAME is iconified, otherwise it is
11605 frame_title_format. */
11608 x_consider_frame_title (Lisp_Object frame
)
11610 struct frame
*f
= XFRAME (frame
);
11612 if ((FRAME_WINDOW_P (f
)
11613 || FRAME_MINIBUF_ONLY_P (f
)
11614 || f
->explicit_name
)
11615 && NILP (Fframe_parameter (frame
, Qtooltip
)))
11617 /* Do we have more than one visible frame on this X display? */
11618 Lisp_Object tail
, other_frame
, fmt
;
11619 ptrdiff_t title_start
;
11623 ptrdiff_t count
= SPECPDL_INDEX ();
11625 FOR_EACH_FRAME (tail
, other_frame
)
11627 struct frame
*tf
= XFRAME (other_frame
);
11630 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11631 && !FRAME_MINIBUF_ONLY_P (tf
)
11632 && !EQ (other_frame
, tip_frame
)
11633 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11637 /* Set global variable indicating that multiple frames exist. */
11638 multiple_frames
= CONSP (tail
);
11640 /* Switch to the buffer of selected window of the frame. Set up
11641 mode_line_target so that display_mode_element will output into
11642 mode_line_noprop_buf; then display the title. */
11643 record_unwind_protect (unwind_format_mode_line
,
11644 format_mode_line_unwind_data
11645 (f
, current_buffer
, selected_window
, false));
11647 Fselect_window (f
->selected_window
, Qt
);
11648 set_buffer_internal_1
11649 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11650 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11652 mode_line_target
= MODE_LINE_TITLE
;
11653 title_start
= MODE_LINE_NOPROP_LEN (0);
11654 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11655 NULL
, DEFAULT_FACE_ID
);
11656 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, false);
11657 len
= MODE_LINE_NOPROP_LEN (title_start
);
11658 title
= mode_line_noprop_buf
+ title_start
;
11659 unbind_to (count
, Qnil
);
11661 /* Set the title only if it's changed. This avoids consing in
11662 the common case where it hasn't. (If it turns out that we've
11663 already wasted too much time by walking through the list with
11664 display_mode_element, then we might need to optimize at a
11665 higher level than this.) */
11666 if (! STRINGP (f
->name
)
11667 || SBYTES (f
->name
) != len
11668 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11669 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11673 #endif /* not HAVE_WINDOW_SYSTEM */
11676 /***********************************************************************
11678 ***********************************************************************/
11680 /* True if we will not redisplay all visible windows. */
11681 #define REDISPLAY_SOME_P() \
11682 ((windows_or_buffers_changed == 0 \
11683 || windows_or_buffers_changed == REDISPLAY_SOME) \
11684 && (update_mode_lines == 0 \
11685 || update_mode_lines == REDISPLAY_SOME))
11687 /* Prepare for redisplay by updating menu-bar item lists when
11688 appropriate. This can call eval. */
11691 prepare_menu_bars (void)
11693 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11694 bool some_windows
= REDISPLAY_SOME_P ();
11695 Lisp_Object tooltip_frame
;
11697 #ifdef HAVE_WINDOW_SYSTEM
11698 tooltip_frame
= tip_frame
;
11700 tooltip_frame
= Qnil
;
11703 if (FUNCTIONP (Vpre_redisplay_function
))
11705 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11706 if (all_windows
&& some_windows
)
11708 Lisp_Object ws
= window_list ();
11709 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11711 Lisp_Object
this = XCAR (ws
);
11712 struct window
*w
= XWINDOW (this);
11714 || XFRAME (w
->frame
)->redisplay
11715 || XBUFFER (w
->contents
)->text
->redisplay
)
11717 windows
= Fcons (this, windows
);
11721 safe__call1 (true, Vpre_redisplay_function
, windows
);
11724 /* Update all frame titles based on their buffer names, etc. We do
11725 this before the menu bars so that the buffer-menu will show the
11726 up-to-date frame titles. */
11727 #ifdef HAVE_WINDOW_SYSTEM
11730 Lisp_Object tail
, frame
;
11732 FOR_EACH_FRAME (tail
, frame
)
11734 struct frame
*f
= XFRAME (frame
);
11735 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11739 && !XBUFFER (w
->contents
)->text
->redisplay
)
11742 if (!EQ (frame
, tooltip_frame
)
11743 && (FRAME_ICONIFIED_P (f
)
11744 || FRAME_VISIBLE_P (f
) == 1
11745 /* Exclude TTY frames that are obscured because they
11746 are not the top frame on their console. This is
11747 because x_consider_frame_title actually switches
11748 to the frame, which for TTY frames means it is
11749 marked as garbaged, and will be completely
11750 redrawn on the next redisplay cycle. This causes
11751 TTY frames to be completely redrawn, when there
11752 are more than one of them, even though nothing
11753 should be changed on display. */
11754 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11755 x_consider_frame_title (frame
);
11758 #endif /* HAVE_WINDOW_SYSTEM */
11760 /* Update the menu bar item lists, if appropriate. This has to be
11761 done before any actual redisplay or generation of display lines. */
11765 Lisp_Object tail
, frame
;
11766 ptrdiff_t count
= SPECPDL_INDEX ();
11767 /* True means that update_menu_bar has run its hooks
11768 so any further calls to update_menu_bar shouldn't do so again. */
11769 bool menu_bar_hooks_run
= false;
11771 record_unwind_save_match_data ();
11773 FOR_EACH_FRAME (tail
, frame
)
11775 struct frame
*f
= XFRAME (frame
);
11776 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11778 /* Ignore tooltip frame. */
11779 if (EQ (frame
, tooltip_frame
))
11785 && !XBUFFER (w
->contents
)->text
->redisplay
)
11788 /* If a window on this frame changed size, report that to
11789 the user and clear the size-change flag. */
11790 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11792 Lisp_Object functions
;
11794 /* Clear flag first in case we get an error below. */
11795 FRAME_WINDOW_SIZES_CHANGED (f
) = false;
11796 functions
= Vwindow_size_change_functions
;
11798 while (CONSP (functions
))
11800 if (!EQ (XCAR (functions
), Qt
))
11801 call1 (XCAR (functions
), frame
);
11802 functions
= XCDR (functions
);
11806 menu_bar_hooks_run
= update_menu_bar (f
, false, menu_bar_hooks_run
);
11807 #ifdef HAVE_WINDOW_SYSTEM
11808 update_tool_bar (f
, false);
11812 unbind_to (count
, Qnil
);
11816 struct frame
*sf
= SELECTED_FRAME ();
11817 update_menu_bar (sf
, true, false);
11818 #ifdef HAVE_WINDOW_SYSTEM
11819 update_tool_bar (sf
, true);
11825 /* Update the menu bar item list for frame F. This has to be done
11826 before we start to fill in any display lines, because it can call
11829 If SAVE_MATCH_DATA, we must save and restore it here.
11831 If HOOKS_RUN, a previous call to update_menu_bar
11832 already ran the menu bar hooks for this redisplay, so there
11833 is no need to run them again. The return value is the
11834 updated value of this flag, to pass to the next call. */
11837 update_menu_bar (struct frame
*f
, bool save_match_data
, bool hooks_run
)
11839 Lisp_Object window
;
11842 /* If called recursively during a menu update, do nothing. This can
11843 happen when, for instance, an activate-menubar-hook causes a
11845 if (inhibit_menubar_update
)
11848 window
= FRAME_SELECTED_WINDOW (f
);
11849 w
= XWINDOW (window
);
11851 if (FRAME_WINDOW_P (f
)
11853 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11854 || defined (HAVE_NS) || defined (USE_GTK)
11855 FRAME_EXTERNAL_MENU_BAR (f
)
11857 FRAME_MENU_BAR_LINES (f
) > 0
11859 : FRAME_MENU_BAR_LINES (f
) > 0)
11861 /* If the user has switched buffers or windows, we need to
11862 recompute to reflect the new bindings. But we'll
11863 recompute when update_mode_lines is set too; that means
11864 that people can use force-mode-line-update to request
11865 that the menu bar be recomputed. The adverse effect on
11866 the rest of the redisplay algorithm is about the same as
11867 windows_or_buffers_changed anyway. */
11868 if (windows_or_buffers_changed
11869 /* This used to test w->update_mode_line, but we believe
11870 there is no need to recompute the menu in that case. */
11871 || update_mode_lines
11872 || window_buffer_changed (w
))
11874 struct buffer
*prev
= current_buffer
;
11875 ptrdiff_t count
= SPECPDL_INDEX ();
11877 specbind (Qinhibit_menubar_update
, Qt
);
11879 set_buffer_internal_1 (XBUFFER (w
->contents
));
11880 if (save_match_data
)
11881 record_unwind_save_match_data ();
11882 if (NILP (Voverriding_local_map_menu_flag
))
11884 specbind (Qoverriding_terminal_local_map
, Qnil
);
11885 specbind (Qoverriding_local_map
, Qnil
);
11890 /* Run the Lucid hook. */
11891 safe_run_hooks (Qactivate_menubar_hook
);
11893 /* If it has changed current-menubar from previous value,
11894 really recompute the menu-bar from the value. */
11895 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11896 call0 (Qrecompute_lucid_menubar
);
11898 safe_run_hooks (Qmenu_bar_update_hook
);
11903 XSETFRAME (Vmenu_updating_frame
, f
);
11904 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11906 /* Redisplay the menu bar in case we changed it. */
11907 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11908 || defined (HAVE_NS) || defined (USE_GTK)
11909 if (FRAME_WINDOW_P (f
))
11911 #if defined (HAVE_NS)
11912 /* All frames on Mac OS share the same menubar. So only
11913 the selected frame should be allowed to set it. */
11914 if (f
== SELECTED_FRAME ())
11916 set_frame_menubar (f
, false, false);
11919 /* On a terminal screen, the menu bar is an ordinary screen
11920 line, and this makes it get updated. */
11921 w
->update_mode_line
= true;
11922 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11923 /* In the non-toolkit version, the menu bar is an ordinary screen
11924 line, and this makes it get updated. */
11925 w
->update_mode_line
= true;
11926 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11928 unbind_to (count
, Qnil
);
11929 set_buffer_internal_1 (prev
);
11936 /***********************************************************************
11938 ***********************************************************************/
11940 #ifdef HAVE_WINDOW_SYSTEM
11942 /* Select `frame' temporarily without running all the code in
11944 FIXME: Maybe do_switch_frame should be trimmed down similarly
11945 when `norecord' is set. */
11947 fast_set_selected_frame (Lisp_Object frame
)
11949 if (!EQ (selected_frame
, frame
))
11951 selected_frame
= frame
;
11952 selected_window
= XFRAME (frame
)->selected_window
;
11956 /* Update the tool-bar item list for frame F. This has to be done
11957 before we start to fill in any display lines. Called from
11958 prepare_menu_bars. If SAVE_MATCH_DATA, we must save
11959 and restore it here. */
11962 update_tool_bar (struct frame
*f
, bool save_match_data
)
11964 #if defined (USE_GTK) || defined (HAVE_NS)
11965 bool do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11967 bool do_update
= (WINDOWP (f
->tool_bar_window
)
11968 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0);
11973 Lisp_Object window
;
11976 window
= FRAME_SELECTED_WINDOW (f
);
11977 w
= XWINDOW (window
);
11979 /* If the user has switched buffers or windows, we need to
11980 recompute to reflect the new bindings. But we'll
11981 recompute when update_mode_lines is set too; that means
11982 that people can use force-mode-line-update to request
11983 that the menu bar be recomputed. The adverse effect on
11984 the rest of the redisplay algorithm is about the same as
11985 windows_or_buffers_changed anyway. */
11986 if (windows_or_buffers_changed
11987 || w
->update_mode_line
11988 || update_mode_lines
11989 || window_buffer_changed (w
))
11991 struct buffer
*prev
= current_buffer
;
11992 ptrdiff_t count
= SPECPDL_INDEX ();
11993 Lisp_Object frame
, new_tool_bar
;
11994 int new_n_tool_bar
;
11996 /* Set current_buffer to the buffer of the selected
11997 window of the frame, so that we get the right local
11999 set_buffer_internal_1 (XBUFFER (w
->contents
));
12001 /* Save match data, if we must. */
12002 if (save_match_data
)
12003 record_unwind_save_match_data ();
12005 /* Make sure that we don't accidentally use bogus keymaps. */
12006 if (NILP (Voverriding_local_map_menu_flag
))
12008 specbind (Qoverriding_terminal_local_map
, Qnil
);
12009 specbind (Qoverriding_local_map
, Qnil
);
12012 /* We must temporarily set the selected frame to this frame
12013 before calling tool_bar_items, because the calculation of
12014 the tool-bar keymap uses the selected frame (see
12015 `tool-bar-make-keymap' in tool-bar.el). */
12016 eassert (EQ (selected_window
,
12017 /* Since we only explicitly preserve selected_frame,
12018 check that selected_window would be redundant. */
12019 XFRAME (selected_frame
)->selected_window
));
12020 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
12021 XSETFRAME (frame
, f
);
12022 fast_set_selected_frame (frame
);
12024 /* Build desired tool-bar items from keymaps. */
12026 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
12029 /* Redisplay the tool-bar if we changed it. */
12030 if (new_n_tool_bar
!= f
->n_tool_bar_items
12031 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
12033 /* Redisplay that happens asynchronously due to an expose event
12034 may access f->tool_bar_items. Make sure we update both
12035 variables within BLOCK_INPUT so no such event interrupts. */
12037 fset_tool_bar_items (f
, new_tool_bar
);
12038 f
->n_tool_bar_items
= new_n_tool_bar
;
12039 w
->update_mode_line
= true;
12043 unbind_to (count
, Qnil
);
12044 set_buffer_internal_1 (prev
);
12049 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12051 /* Set F->desired_tool_bar_string to a Lisp string representing frame
12052 F's desired tool-bar contents. F->tool_bar_items must have
12053 been set up previously by calling prepare_menu_bars. */
12056 build_desired_tool_bar_string (struct frame
*f
)
12058 int i
, size
, size_needed
;
12059 Lisp_Object image
, plist
;
12061 image
= plist
= Qnil
;
12063 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
12064 Otherwise, make a new string. */
12066 /* The size of the string we might be able to reuse. */
12067 size
= (STRINGP (f
->desired_tool_bar_string
)
12068 ? SCHARS (f
->desired_tool_bar_string
)
12071 /* We need one space in the string for each image. */
12072 size_needed
= f
->n_tool_bar_items
;
12074 /* Reuse f->desired_tool_bar_string, if possible. */
12075 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
12076 fset_desired_tool_bar_string
12077 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
12080 AUTO_LIST4 (props
, Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
12081 Fremove_text_properties (make_number (0), make_number (size
),
12082 props
, f
->desired_tool_bar_string
);
12085 /* Put a `display' property on the string for the images to display,
12086 put a `menu_item' property on tool-bar items with a value that
12087 is the index of the item in F's tool-bar item vector. */
12088 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
12090 #define PROP(IDX) \
12091 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
12093 bool enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
12094 bool selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
12095 int hmargin
, vmargin
, relief
, idx
, end
;
12097 /* If image is a vector, choose the image according to the
12099 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
12100 if (VECTORP (image
))
12104 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
12105 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
12108 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
12109 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
12111 eassert (ASIZE (image
) >= idx
);
12112 image
= AREF (image
, idx
);
12117 /* Ignore invalid image specifications. */
12118 if (!valid_image_p (image
))
12121 /* Display the tool-bar button pressed, or depressed. */
12122 plist
= Fcopy_sequence (XCDR (image
));
12124 /* Compute margin and relief to draw. */
12125 relief
= (tool_bar_button_relief
>= 0
12126 ? tool_bar_button_relief
12127 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
12128 hmargin
= vmargin
= relief
;
12130 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
12131 INT_MAX
- max (hmargin
, vmargin
)))
12133 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
12134 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
12136 else if (CONSP (Vtool_bar_button_margin
))
12138 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
12139 INT_MAX
- hmargin
))
12140 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
12142 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
12143 INT_MAX
- vmargin
))
12144 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
12147 if (auto_raise_tool_bar_buttons_p
)
12149 /* Add a `:relief' property to the image spec if the item is
12153 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
12160 /* If image is selected, display it pressed, i.e. with a
12161 negative relief. If it's not selected, display it with a
12163 plist
= Fplist_put (plist
, QCrelief
,
12165 ? make_number (-relief
)
12166 : make_number (relief
)));
12171 /* Put a margin around the image. */
12172 if (hmargin
|| vmargin
)
12174 if (hmargin
== vmargin
)
12175 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
12177 plist
= Fplist_put (plist
, QCmargin
,
12178 Fcons (make_number (hmargin
),
12179 make_number (vmargin
)));
12182 /* If button is not enabled, and we don't have special images
12183 for the disabled state, make the image appear disabled by
12184 applying an appropriate algorithm to it. */
12185 if (!enabled_p
&& idx
< 0)
12186 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
12188 /* Put a `display' text property on the string for the image to
12189 display. Put a `menu-item' property on the string that gives
12190 the start of this item's properties in the tool-bar items
12192 image
= Fcons (Qimage
, plist
);
12193 AUTO_LIST4 (props
, Qdisplay
, image
, Qmenu_item
,
12194 make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
12196 /* Let the last image hide all remaining spaces in the tool bar
12197 string. The string can be longer than needed when we reuse a
12198 previous string. */
12199 if (i
+ 1 == f
->n_tool_bar_items
)
12200 end
= SCHARS (f
->desired_tool_bar_string
);
12203 Fadd_text_properties (make_number (i
), make_number (end
),
12204 props
, f
->desired_tool_bar_string
);
12210 /* Display one line of the tool-bar of frame IT->f.
12212 HEIGHT specifies the desired height of the tool-bar line.
12213 If the actual height of the glyph row is less than HEIGHT, the
12214 row's height is increased to HEIGHT, and the icons are centered
12215 vertically in the new height.
12217 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
12218 count a final empty row in case the tool-bar width exactly matches
12223 display_tool_bar_line (struct it
*it
, int height
)
12225 struct glyph_row
*row
= it
->glyph_row
;
12226 int max_x
= it
->last_visible_x
;
12227 struct glyph
*last
;
12229 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
12230 clear_glyph_row (row
);
12231 row
->enabled_p
= true;
12232 row
->y
= it
->current_y
;
12234 /* Note that this isn't made use of if the face hasn't a box,
12235 so there's no need to check the face here. */
12236 it
->start_of_box_run_p
= true;
12238 while (it
->current_x
< max_x
)
12240 int x
, n_glyphs_before
, i
, nglyphs
;
12241 struct it it_before
;
12243 /* Get the next display element. */
12244 if (!get_next_display_element (it
))
12246 /* Don't count empty row if we are counting needed tool-bar lines. */
12247 if (height
< 0 && !it
->hpos
)
12252 /* Produce glyphs. */
12253 n_glyphs_before
= row
->used
[TEXT_AREA
];
12256 PRODUCE_GLYPHS (it
);
12258 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12260 x
= it_before
.current_x
;
12261 while (i
< nglyphs
)
12263 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12265 if (x
+ glyph
->pixel_width
> max_x
)
12267 /* Glyph doesn't fit on line. Backtrack. */
12268 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12270 /* If this is the only glyph on this line, it will never fit on the
12271 tool-bar, so skip it. But ensure there is at least one glyph,
12272 so we don't accidentally disable the tool-bar. */
12273 if (n_glyphs_before
== 0
12274 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
12280 x
+= glyph
->pixel_width
;
12284 /* Stop at line end. */
12285 if (ITERATOR_AT_END_OF_LINE_P (it
))
12288 set_iterator_to_next (it
, true);
12293 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12295 /* Use default face for the border below the tool bar.
12297 FIXME: When auto-resize-tool-bars is grow-only, there is
12298 no additional border below the possibly empty tool-bar lines.
12299 So to make the extra empty lines look "normal", we have to
12300 use the tool-bar face for the border too. */
12301 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12302 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12303 it
->face_id
= DEFAULT_FACE_ID
;
12305 extend_face_to_end_of_line (it
);
12306 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12307 last
->right_box_line_p
= true;
12308 if (last
== row
->glyphs
[TEXT_AREA
])
12309 last
->left_box_line_p
= true;
12311 /* Make line the desired height and center it vertically. */
12312 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12314 /* Don't add more than one line height. */
12315 height
%= FRAME_LINE_HEIGHT (it
->f
);
12316 it
->max_ascent
+= height
/ 2;
12317 it
->max_descent
+= (height
+ 1) / 2;
12320 compute_line_metrics (it
);
12322 /* If line is empty, make it occupy the rest of the tool-bar. */
12323 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12325 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12326 row
->visible_height
= row
->height
;
12327 row
->ascent
= row
->phys_ascent
= 0;
12328 row
->extra_line_spacing
= 0;
12331 row
->full_width_p
= true;
12332 row
->continued_p
= false;
12333 row
->truncated_on_left_p
= false;
12334 row
->truncated_on_right_p
= false;
12336 it
->current_x
= it
->hpos
= 0;
12337 it
->current_y
+= row
->height
;
12343 /* Value is the number of pixels needed to make all tool-bar items of
12344 frame F visible. The actual number of glyph rows needed is
12345 returned in *N_ROWS if non-NULL. */
12347 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12349 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12351 /* tool_bar_height is called from redisplay_tool_bar after building
12352 the desired matrix, so use (unused) mode-line row as temporary row to
12353 avoid destroying the first tool-bar row. */
12354 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12356 /* Initialize an iterator for iteration over
12357 F->desired_tool_bar_string in the tool-bar window of frame F. */
12358 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12359 temp_row
->reversed_p
= false;
12360 it
.first_visible_x
= 0;
12361 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12362 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12363 it
.paragraph_embedding
= L2R
;
12365 while (!ITERATOR_AT_END_P (&it
))
12367 clear_glyph_row (temp_row
);
12368 it
.glyph_row
= temp_row
;
12369 display_tool_bar_line (&it
, -1);
12371 clear_glyph_row (temp_row
);
12373 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12375 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12378 return it
.current_y
;
12380 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12383 #endif /* !USE_GTK && !HAVE_NS */
12385 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12387 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12388 If FRAME is nil or omitted, use the selected frame. Optional argument
12389 PIXELWISE non-nil means return the height of the tool bar in pixels. */)
12390 (Lisp_Object frame
, Lisp_Object pixelwise
)
12394 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12395 struct frame
*f
= decode_any_frame (frame
);
12397 if (WINDOWP (f
->tool_bar_window
)
12398 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12400 update_tool_bar (f
, true);
12401 if (f
->n_tool_bar_items
)
12403 build_desired_tool_bar_string (f
);
12404 height
= tool_bar_height (f
, NULL
, !NILP (pixelwise
));
12409 return make_number (height
);
12413 /* Display the tool-bar of frame F. Value is true if tool-bar's
12414 height should be changed. */
12416 redisplay_tool_bar (struct frame
*f
)
12418 f
->tool_bar_redisplayed
= true;
12419 #if defined (USE_GTK) || defined (HAVE_NS)
12421 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12422 update_frame_tool_bar (f
);
12425 #else /* !USE_GTK && !HAVE_NS */
12429 struct glyph_row
*row
;
12431 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12432 do anything. This means you must start with tool-bar-lines
12433 non-zero to get the auto-sizing effect. Or in other words, you
12434 can turn off tool-bars by specifying tool-bar-lines zero. */
12435 if (!WINDOWP (f
->tool_bar_window
)
12436 || (w
= XWINDOW (f
->tool_bar_window
),
12437 WINDOW_TOTAL_LINES (w
) == 0))
12440 /* Set up an iterator for the tool-bar window. */
12441 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12442 it
.first_visible_x
= 0;
12443 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12444 row
= it
.glyph_row
;
12445 row
->reversed_p
= false;
12447 /* Build a string that represents the contents of the tool-bar. */
12448 build_desired_tool_bar_string (f
);
12449 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12450 /* FIXME: This should be controlled by a user option. But it
12451 doesn't make sense to have an R2L tool bar if the menu bar cannot
12452 be drawn also R2L, and making the menu bar R2L is tricky due
12453 toolkit-specific code that implements it. If an R2L tool bar is
12454 ever supported, display_tool_bar_line should also be augmented to
12455 call unproduce_glyphs like display_line and display_string
12457 it
.paragraph_embedding
= L2R
;
12459 if (f
->n_tool_bar_rows
== 0)
12461 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, true);
12463 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12465 x_change_tool_bar_height (f
, new_height
);
12466 frame_default_tool_bar_height
= new_height
;
12467 /* Always do that now. */
12468 clear_glyph_matrix (w
->desired_matrix
);
12469 f
->fonts_changed
= true;
12474 /* Display as many lines as needed to display all tool-bar items. */
12476 if (f
->n_tool_bar_rows
> 0)
12478 int border
, rows
, height
, extra
;
12480 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12481 border
= XINT (Vtool_bar_border
);
12482 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12483 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12484 else if (EQ (Vtool_bar_border
, Qborder_width
))
12485 border
= f
->border_width
;
12491 rows
= f
->n_tool_bar_rows
;
12492 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12493 extra
= it
.last_visible_y
- border
- height
* rows
;
12495 while (it
.current_y
< it
.last_visible_y
)
12498 if (extra
> 0 && rows
-- > 0)
12500 h
= (extra
+ rows
- 1) / rows
;
12503 display_tool_bar_line (&it
, height
+ h
);
12508 while (it
.current_y
< it
.last_visible_y
)
12509 display_tool_bar_line (&it
, 0);
12512 /* It doesn't make much sense to try scrolling in the tool-bar
12513 window, so don't do it. */
12514 w
->desired_matrix
->no_scrolling_p
= true;
12515 w
->must_be_updated_p
= true;
12517 if (!NILP (Vauto_resize_tool_bars
))
12519 bool change_height_p
= true;
12521 /* If we couldn't display everything, change the tool-bar's
12522 height if there is room for more. */
12523 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
12524 change_height_p
= true;
12526 /* We subtract 1 because display_tool_bar_line advances the
12527 glyph_row pointer before returning to its caller. We want to
12528 examine the last glyph row produced by
12529 display_tool_bar_line. */
12530 row
= it
.glyph_row
- 1;
12532 /* If there are blank lines at the end, except for a partially
12533 visible blank line at the end that is smaller than
12534 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12535 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12536 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12537 change_height_p
= true;
12539 /* If row displays tool-bar items, but is partially visible,
12540 change the tool-bar's height. */
12541 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12542 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
12543 change_height_p
= true;
12545 /* Resize windows as needed by changing the `tool-bar-lines'
12546 frame parameter. */
12547 if (change_height_p
)
12550 int new_height
= tool_bar_height (f
, &nrows
, true);
12552 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12553 && !f
->minimize_tool_bar_window_p
)
12554 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12555 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12556 f
->minimize_tool_bar_window_p
= false;
12558 if (change_height_p
)
12560 x_change_tool_bar_height (f
, new_height
);
12561 frame_default_tool_bar_height
= new_height
;
12562 clear_glyph_matrix (w
->desired_matrix
);
12563 f
->n_tool_bar_rows
= nrows
;
12564 f
->fonts_changed
= true;
12571 f
->minimize_tool_bar_window_p
= false;
12574 #endif /* USE_GTK || HAVE_NS */
12577 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12579 /* Get information about the tool-bar item which is displayed in GLYPH
12580 on frame F. Return in *PROP_IDX the index where tool-bar item
12581 properties start in F->tool_bar_items. Value is false if
12582 GLYPH doesn't display a tool-bar item. */
12585 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12590 /* This function can be called asynchronously, which means we must
12591 exclude any possibility that Fget_text_property signals an
12593 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12594 charpos
= max (0, charpos
);
12596 /* Get the text property `menu-item' at pos. The value of that
12597 property is the start index of this item's properties in
12598 F->tool_bar_items. */
12599 prop
= Fget_text_property (make_number (charpos
),
12600 Qmenu_item
, f
->current_tool_bar_string
);
12601 if (! INTEGERP (prop
))
12603 *prop_idx
= XINT (prop
);
12608 /* Get information about the tool-bar item at position X/Y on frame F.
12609 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12610 the current matrix of the tool-bar window of F, or NULL if not
12611 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12612 item in F->tool_bar_items. Value is
12614 -1 if X/Y is not on a tool-bar item
12615 0 if X/Y is on the same item that was highlighted before.
12619 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12620 int *hpos
, int *vpos
, int *prop_idx
)
12622 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12623 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12626 /* Find the glyph under X/Y. */
12627 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12628 if (*glyph
== NULL
)
12631 /* Get the start of this tool-bar item's properties in
12632 f->tool_bar_items. */
12633 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12636 /* Is mouse on the highlighted item? */
12637 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12638 && *vpos
>= hlinfo
->mouse_face_beg_row
12639 && *vpos
<= hlinfo
->mouse_face_end_row
12640 && (*vpos
> hlinfo
->mouse_face_beg_row
12641 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12642 && (*vpos
< hlinfo
->mouse_face_end_row
12643 || *hpos
< hlinfo
->mouse_face_end_col
12644 || hlinfo
->mouse_face_past_end
))
12652 Handle mouse button event on the tool-bar of frame F, at
12653 frame-relative coordinates X/Y. DOWN_P is true for a button press,
12654 false for button release. MODIFIERS is event modifiers for button
12658 handle_tool_bar_click (struct frame
*f
, int x
, int y
, bool down_p
,
12661 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12662 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12663 int hpos
, vpos
, prop_idx
;
12664 struct glyph
*glyph
;
12665 Lisp_Object enabled_p
;
12668 /* If not on the highlighted tool-bar item, and mouse-highlight is
12669 non-nil, return. This is so we generate the tool-bar button
12670 click only when the mouse button is released on the same item as
12671 where it was pressed. However, when mouse-highlight is disabled,
12672 generate the click when the button is released regardless of the
12673 highlight, since tool-bar items are not highlighted in that
12675 frame_to_window_pixel_xy (w
, &x
, &y
);
12676 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12678 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12681 /* When mouse-highlight is off, generate the click for the item
12682 where the button was pressed, disregarding where it was
12684 if (NILP (Vmouse_highlight
) && !down_p
)
12685 prop_idx
= f
->last_tool_bar_item
;
12687 /* If item is disabled, do nothing. */
12688 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12689 if (NILP (enabled_p
))
12694 /* Show item in pressed state. */
12695 if (!NILP (Vmouse_highlight
))
12696 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12697 f
->last_tool_bar_item
= prop_idx
;
12701 Lisp_Object key
, frame
;
12702 struct input_event event
;
12703 EVENT_INIT (event
);
12705 /* Show item in released state. */
12706 if (!NILP (Vmouse_highlight
))
12707 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12709 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12711 XSETFRAME (frame
, f
);
12712 event
.kind
= TOOL_BAR_EVENT
;
12713 event
.frame_or_window
= frame
;
12715 kbd_buffer_store_event (&event
);
12717 event
.kind
= TOOL_BAR_EVENT
;
12718 event
.frame_or_window
= frame
;
12720 event
.modifiers
= modifiers
;
12721 kbd_buffer_store_event (&event
);
12722 f
->last_tool_bar_item
= -1;
12727 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12728 tool-bar window-relative coordinates X/Y. Called from
12729 note_mouse_highlight. */
12732 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12734 Lisp_Object window
= f
->tool_bar_window
;
12735 struct window
*w
= XWINDOW (window
);
12736 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12737 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12739 struct glyph
*glyph
;
12740 struct glyph_row
*row
;
12742 Lisp_Object enabled_p
;
12744 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12748 /* Function note_mouse_highlight is called with negative X/Y
12749 values when mouse moves outside of the frame. */
12750 if (x
<= 0 || y
<= 0)
12752 clear_mouse_face (hlinfo
);
12756 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12759 /* Not on tool-bar item. */
12760 clear_mouse_face (hlinfo
);
12764 /* On same tool-bar item as before. */
12765 goto set_help_echo
;
12767 clear_mouse_face (hlinfo
);
12769 /* Mouse is down, but on different tool-bar item? */
12770 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12771 && f
== dpyinfo
->last_mouse_frame
);
12773 if (mouse_down_p
&& f
->last_tool_bar_item
!= prop_idx
)
12776 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12778 /* If tool-bar item is not enabled, don't highlight it. */
12779 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12780 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12782 /* Compute the x-position of the glyph. In front and past the
12783 image is a space. We include this in the highlighted area. */
12784 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12785 for (i
= x
= 0; i
< hpos
; ++i
)
12786 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12788 /* Record this as the current active region. */
12789 hlinfo
->mouse_face_beg_col
= hpos
;
12790 hlinfo
->mouse_face_beg_row
= vpos
;
12791 hlinfo
->mouse_face_beg_x
= x
;
12792 hlinfo
->mouse_face_past_end
= false;
12794 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12795 hlinfo
->mouse_face_end_row
= vpos
;
12796 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12797 hlinfo
->mouse_face_window
= window
;
12798 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12800 /* Display it as active. */
12801 show_mouse_face (hlinfo
, draw
);
12806 /* Set help_echo_string to a help string to display for this tool-bar item.
12807 XTread_socket does the rest. */
12808 help_echo_object
= help_echo_window
= Qnil
;
12809 help_echo_pos
= -1;
12810 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12811 if (NILP (help_echo_string
))
12812 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12815 #endif /* !USE_GTK && !HAVE_NS */
12817 #endif /* HAVE_WINDOW_SYSTEM */
12821 /************************************************************************
12822 Horizontal scrolling
12823 ************************************************************************/
12825 /* For all leaf windows in the window tree rooted at WINDOW, set their
12826 hscroll value so that PT is (i) visible in the window, and (ii) so
12827 that it is not within a certain margin at the window's left and
12828 right border. Value is true if any window's hscroll has been
12832 hscroll_window_tree (Lisp_Object window
)
12834 bool hscrolled_p
= false;
12835 bool hscroll_relative_p
= FLOATP (Vhscroll_step
);
12836 int hscroll_step_abs
= 0;
12837 double hscroll_step_rel
= 0;
12839 if (hscroll_relative_p
)
12841 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12842 if (hscroll_step_rel
< 0)
12844 hscroll_relative_p
= false;
12845 hscroll_step_abs
= 0;
12848 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12850 hscroll_step_abs
= XINT (Vhscroll_step
);
12851 if (hscroll_step_abs
< 0)
12852 hscroll_step_abs
= 0;
12855 hscroll_step_abs
= 0;
12857 while (WINDOWP (window
))
12859 struct window
*w
= XWINDOW (window
);
12861 if (WINDOWP (w
->contents
))
12862 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12863 else if (w
->cursor
.vpos
>= 0)
12866 int text_area_width
;
12867 struct glyph_row
*cursor_row
;
12868 struct glyph_row
*bottom_row
;
12870 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->desired_matrix
, w
);
12871 if (w
->cursor
.vpos
< bottom_row
- w
->desired_matrix
->rows
)
12872 cursor_row
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12874 cursor_row
= bottom_row
- 1;
12876 if (!cursor_row
->enabled_p
)
12878 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12879 if (w
->cursor
.vpos
< bottom_row
- w
->current_matrix
->rows
)
12880 cursor_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12882 cursor_row
= bottom_row
- 1;
12884 bool row_r2l_p
= cursor_row
->reversed_p
;
12886 text_area_width
= window_box_width (w
, TEXT_AREA
);
12888 /* Scroll when cursor is inside this scroll margin. */
12889 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12891 /* If the position of this window's point has explicitly
12892 changed, no more suspend auto hscrolling. */
12893 if (NILP (Fequal (Fwindow_point (window
), Fwindow_old_point (window
))))
12894 w
->suspend_auto_hscroll
= false;
12896 /* Remember window point. */
12897 Fset_marker (w
->old_pointm
,
12898 ((w
== XWINDOW (selected_window
))
12899 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
12900 : Fmarker_position (w
->pointm
)),
12903 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12904 && !w
->suspend_auto_hscroll
12905 /* In some pathological cases, like restoring a window
12906 configuration into a frame that is much smaller than
12907 the one from which the configuration was saved, we
12908 get glyph rows whose start and end have zero buffer
12909 positions, which we cannot handle below. Just skip
12911 && CHARPOS (cursor_row
->start
.pos
) >= BUF_BEG (w
->contents
)
12912 /* For left-to-right rows, hscroll when cursor is either
12913 (i) inside the right hscroll margin, or (ii) if it is
12914 inside the left margin and the window is already
12917 && ((w
->hscroll
&& w
->cursor
.x
<= h_margin
)
12918 || (cursor_row
->enabled_p
12919 && cursor_row
->truncated_on_right_p
12920 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12921 /* For right-to-left rows, the logic is similar,
12922 except that rules for scrolling to left and right
12923 are reversed. E.g., if cursor.x <= h_margin, we
12924 need to hscroll "to the right" unconditionally,
12925 and that will scroll the screen to the left so as
12926 to reveal the next portion of the row. */
12928 && ((cursor_row
->enabled_p
12929 /* FIXME: It is confusing to set the
12930 truncated_on_right_p flag when R2L rows
12931 are actually truncated on the left. */
12932 && cursor_row
->truncated_on_right_p
12933 && w
->cursor
.x
<= h_margin
)
12935 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12939 struct buffer
*saved_current_buffer
;
12943 /* Find point in a display of infinite width. */
12944 saved_current_buffer
= current_buffer
;
12945 current_buffer
= XBUFFER (w
->contents
);
12947 if (w
== XWINDOW (selected_window
))
12950 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12952 /* Move iterator to pt starting at cursor_row->start in
12953 a line with infinite width. */
12954 init_to_row_start (&it
, w
, cursor_row
);
12955 it
.last_visible_x
= INFINITY
;
12956 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12957 current_buffer
= saved_current_buffer
;
12959 /* Position cursor in window. */
12960 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12961 hscroll
= max (0, (it
.current_x
12962 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12963 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12964 : (text_area_width
/ 2))))
12965 / FRAME_COLUMN_WIDTH (it
.f
);
12966 else if ((!row_r2l_p
12967 && w
->cursor
.x
>= text_area_width
- h_margin
)
12968 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12970 if (hscroll_relative_p
)
12971 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12974 wanted_x
= text_area_width
12975 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12978 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12982 if (hscroll_relative_p
)
12983 wanted_x
= text_area_width
* hscroll_step_rel
12986 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12989 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12991 hscroll
= max (hscroll
, w
->min_hscroll
);
12993 /* Don't prevent redisplay optimizations if hscroll
12994 hasn't changed, as it will unnecessarily slow down
12996 if (w
->hscroll
!= hscroll
)
12998 struct buffer
*b
= XBUFFER (w
->contents
);
12999 b
->prevent_redisplay_optimizations_p
= true;
13000 w
->hscroll
= hscroll
;
13001 hscrolled_p
= true;
13009 /* Value is true if hscroll of any leaf window has been changed. */
13010 return hscrolled_p
;
13014 /* Set hscroll so that cursor is visible and not inside horizontal
13015 scroll margins for all windows in the tree rooted at WINDOW. See
13016 also hscroll_window_tree above. Value is true if any window's
13017 hscroll has been changed. If it has, desired matrices on the frame
13018 of WINDOW are cleared. */
13021 hscroll_windows (Lisp_Object window
)
13023 bool hscrolled_p
= hscroll_window_tree (window
);
13025 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
13026 return hscrolled_p
;
13031 /************************************************************************
13033 ************************************************************************/
13035 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined.
13036 This is sometimes handy to have in a debugger session. */
13040 /* First and last unchanged row for try_window_id. */
13042 static int debug_first_unchanged_at_end_vpos
;
13043 static int debug_last_unchanged_at_beg_vpos
;
13045 /* Delta vpos and y. */
13047 static int debug_dvpos
, debug_dy
;
13049 /* Delta in characters and bytes for try_window_id. */
13051 static ptrdiff_t debug_delta
, debug_delta_bytes
;
13053 /* Values of window_end_pos and window_end_vpos at the end of
13056 static ptrdiff_t debug_end_vpos
;
13058 /* Append a string to W->desired_matrix->method. FMT is a printf
13059 format string. If trace_redisplay_p is true also printf the
13060 resulting string to stderr. */
13062 static void debug_method_add (struct window
*, char const *, ...)
13063 ATTRIBUTE_FORMAT_PRINTF (2, 3);
13066 debug_method_add (struct window
*w
, char const *fmt
, ...)
13069 char *method
= w
->desired_matrix
->method
;
13070 int len
= strlen (method
);
13071 int size
= sizeof w
->desired_matrix
->method
;
13072 int remaining
= size
- len
- 1;
13075 if (len
&& remaining
)
13078 --remaining
, ++len
;
13081 va_start (ap
, fmt
);
13082 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
13085 if (trace_redisplay_p
)
13086 fprintf (stderr
, "%p (%s): %s\n",
13088 ((BUFFERP (w
->contents
)
13089 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
13090 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
13095 #endif /* GLYPH_DEBUG */
13098 /* Value is true if all changes in window W, which displays
13099 current_buffer, are in the text between START and END. START is a
13100 buffer position, END is given as a distance from Z. Used in
13101 redisplay_internal for display optimization. */
13104 text_outside_line_unchanged_p (struct window
*w
,
13105 ptrdiff_t start
, ptrdiff_t end
)
13107 bool unchanged_p
= true;
13109 /* If text or overlays have changed, see where. */
13110 if (window_outdated (w
))
13112 /* Gap in the line? */
13113 if (GPT
< start
|| Z
- GPT
< end
)
13114 unchanged_p
= false;
13116 /* Changes start in front of the line, or end after it? */
13118 && (BEG_UNCHANGED
< start
- 1
13119 || END_UNCHANGED
< end
))
13120 unchanged_p
= false;
13122 /* If selective display, can't optimize if changes start at the
13123 beginning of the line. */
13125 && INTEGERP (BVAR (current_buffer
, selective_display
))
13126 && XINT (BVAR (current_buffer
, selective_display
)) > 0
13127 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
13128 unchanged_p
= false;
13130 /* If there are overlays at the start or end of the line, these
13131 may have overlay strings with newlines in them. A change at
13132 START, for instance, may actually concern the display of such
13133 overlay strings as well, and they are displayed on different
13134 lines. So, quickly rule out this case. (For the future, it
13135 might be desirable to implement something more telling than
13136 just BEG/END_UNCHANGED.) */
13139 if (BEG
+ BEG_UNCHANGED
== start
13140 && overlay_touches_p (start
))
13141 unchanged_p
= false;
13142 if (END_UNCHANGED
== end
13143 && overlay_touches_p (Z
- end
))
13144 unchanged_p
= false;
13147 /* Under bidi reordering, adding or deleting a character in the
13148 beginning of a paragraph, before the first strong directional
13149 character, can change the base direction of the paragraph (unless
13150 the buffer specifies a fixed paragraph direction), which will
13151 require redisplaying the whole paragraph. It might be worthwhile
13152 to find the paragraph limits and widen the range of redisplayed
13153 lines to that, but for now just give up this optimization. */
13154 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
13155 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
13156 unchanged_p
= false;
13159 return unchanged_p
;
13163 /* Do a frame update, taking possible shortcuts into account. This is
13164 the main external entry point for redisplay.
13166 If the last redisplay displayed an echo area message and that message
13167 is no longer requested, we clear the echo area or bring back the
13168 mini-buffer if that is in use. */
13173 redisplay_internal ();
13178 overlay_arrow_string_or_property (Lisp_Object var
)
13182 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
13185 return Voverlay_arrow_string
;
13188 /* Return true if there are any overlay-arrows in current_buffer. */
13190 overlay_arrow_in_current_buffer_p (void)
13194 for (vlist
= Voverlay_arrow_variable_list
;
13196 vlist
= XCDR (vlist
))
13198 Lisp_Object var
= XCAR (vlist
);
13201 if (!SYMBOLP (var
))
13203 val
= find_symbol_value (var
);
13205 && current_buffer
== XMARKER (val
)->buffer
)
13212 /* Return true if any overlay_arrows have moved or overlay-arrow-string
13216 overlay_arrows_changed_p (void)
13220 for (vlist
= Voverlay_arrow_variable_list
;
13222 vlist
= XCDR (vlist
))
13224 Lisp_Object var
= XCAR (vlist
);
13225 Lisp_Object val
, pstr
;
13227 if (!SYMBOLP (var
))
13229 val
= find_symbol_value (var
);
13230 if (!MARKERP (val
))
13232 if (! EQ (COERCE_MARKER (val
),
13233 Fget (var
, Qlast_arrow_position
))
13234 || ! (pstr
= overlay_arrow_string_or_property (var
),
13235 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
13241 /* Mark overlay arrows to be updated on next redisplay. */
13244 update_overlay_arrows (int up_to_date
)
13248 for (vlist
= Voverlay_arrow_variable_list
;
13250 vlist
= XCDR (vlist
))
13252 Lisp_Object var
= XCAR (vlist
);
13254 if (!SYMBOLP (var
))
13257 if (up_to_date
> 0)
13259 Lisp_Object val
= find_symbol_value (var
);
13260 Fput (var
, Qlast_arrow_position
,
13261 COERCE_MARKER (val
));
13262 Fput (var
, Qlast_arrow_string
,
13263 overlay_arrow_string_or_property (var
));
13265 else if (up_to_date
< 0
13266 || !NILP (Fget (var
, Qlast_arrow_position
)))
13268 Fput (var
, Qlast_arrow_position
, Qt
);
13269 Fput (var
, Qlast_arrow_string
, Qt
);
13275 /* Return overlay arrow string to display at row.
13276 Return integer (bitmap number) for arrow bitmap in left fringe.
13277 Return nil if no overlay arrow. */
13280 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
13284 for (vlist
= Voverlay_arrow_variable_list
;
13286 vlist
= XCDR (vlist
))
13288 Lisp_Object var
= XCAR (vlist
);
13291 if (!SYMBOLP (var
))
13294 val
= find_symbol_value (var
);
13297 && current_buffer
== XMARKER (val
)->buffer
13298 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13300 if (FRAME_WINDOW_P (it
->f
)
13301 /* FIXME: if ROW->reversed_p is set, this should test
13302 the right fringe, not the left one. */
13303 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13305 #ifdef HAVE_WINDOW_SYSTEM
13306 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13308 int fringe_bitmap
= lookup_fringe_bitmap (val
);
13309 if (fringe_bitmap
!= 0)
13310 return make_number (fringe_bitmap
);
13313 return make_number (-1); /* Use default arrow bitmap. */
13315 return overlay_arrow_string_or_property (var
);
13322 /* Return true if point moved out of or into a composition. Otherwise
13323 return false. PREV_BUF and PREV_PT are the last point buffer and
13324 position. BUF and PT are the current point buffer and position. */
13327 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13328 struct buffer
*buf
, ptrdiff_t pt
)
13330 ptrdiff_t start
, end
;
13332 Lisp_Object buffer
;
13334 XSETBUFFER (buffer
, buf
);
13335 /* Check a composition at the last point if point moved within the
13337 if (prev_buf
== buf
)
13340 /* Point didn't move. */
13343 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13344 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13345 && composition_valid_p (start
, end
, prop
)
13346 && start
< prev_pt
&& end
> prev_pt
)
13347 /* The last point was within the composition. Return true iff
13348 point moved out of the composition. */
13349 return (pt
<= start
|| pt
>= end
);
13352 /* Check a composition at the current point. */
13353 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13354 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13355 && composition_valid_p (start
, end
, prop
)
13356 && start
< pt
&& end
> pt
);
13359 /* Reconsider the clip changes of buffer which is displayed in W. */
13362 reconsider_clip_changes (struct window
*w
)
13364 struct buffer
*b
= XBUFFER (w
->contents
);
13366 if (b
->clip_changed
13367 && w
->window_end_valid
13368 && w
->current_matrix
->buffer
== b
13369 && w
->current_matrix
->zv
== BUF_ZV (b
)
13370 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13371 b
->clip_changed
= false;
13373 /* If display wasn't paused, and W is not a tool bar window, see if
13374 point has been moved into or out of a composition. In that case,
13375 set b->clip_changed to force updating the screen. If
13376 b->clip_changed has already been set, skip this check. */
13377 if (!b
->clip_changed
&& w
->window_end_valid
)
13379 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13380 ? PT
: marker_position (w
->pointm
));
13382 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13383 && check_point_in_composition (w
->current_matrix
->buffer
,
13384 w
->last_point
, b
, pt
))
13385 b
->clip_changed
= true;
13390 propagate_buffer_redisplay (void)
13391 { /* Resetting b->text->redisplay is problematic!
13392 We can't just reset it in the case that some window that displays
13393 it has not been redisplayed; and such a window can stay
13394 unredisplayed for a long time if it's currently invisible.
13395 But we do want to reset it at the end of redisplay otherwise
13396 its displayed windows will keep being redisplayed over and over
13398 So we copy all b->text->redisplay flags up to their windows here,
13399 such that mark_window_display_accurate can safely reset
13400 b->text->redisplay. */
13401 Lisp_Object ws
= window_list ();
13402 for (; CONSP (ws
); ws
= XCDR (ws
))
13404 struct window
*thisw
= XWINDOW (XCAR (ws
));
13405 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13406 if (thisb
->text
->redisplay
)
13407 thisw
->redisplay
= true;
13411 #define STOP_POLLING \
13412 do { if (! polling_stopped_here) stop_polling (); \
13413 polling_stopped_here = true; } while (false)
13415 #define RESUME_POLLING \
13416 do { if (polling_stopped_here) start_polling (); \
13417 polling_stopped_here = false; } while (false)
13420 /* Perhaps in the future avoid recentering windows if it
13421 is not necessary; currently that causes some problems. */
13424 redisplay_internal (void)
13426 struct window
*w
= XWINDOW (selected_window
);
13430 bool must_finish
= false, match_p
;
13431 struct text_pos tlbufpos
, tlendpos
;
13432 int number_of_visible_frames
;
13435 bool polling_stopped_here
= false;
13436 Lisp_Object tail
, frame
;
13438 /* True means redisplay has to consider all windows on all
13439 frames. False, only selected_window is considered. */
13440 bool consider_all_windows_p
;
13442 /* True means redisplay has to redisplay the miniwindow. */
13443 bool update_miniwindow_p
= false;
13445 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13447 /* No redisplay if running in batch mode or frame is not yet fully
13448 initialized, or redisplay is explicitly turned off by setting
13449 Vinhibit_redisplay. */
13450 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13451 || !NILP (Vinhibit_redisplay
))
13454 /* Don't examine these until after testing Vinhibit_redisplay.
13455 When Emacs is shutting down, perhaps because its connection to
13456 X has dropped, we should not look at them at all. */
13457 fr
= XFRAME (w
->frame
);
13458 sf
= SELECTED_FRAME ();
13460 if (!fr
->glyphs_initialized_p
)
13463 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13464 if (popup_activated ())
13468 /* I don't think this happens but let's be paranoid. */
13469 if (redisplaying_p
)
13472 /* Record a function that clears redisplaying_p
13473 when we leave this function. */
13474 count
= SPECPDL_INDEX ();
13475 record_unwind_protect_void (unwind_redisplay
);
13476 redisplaying_p
= true;
13477 specbind (Qinhibit_free_realized_faces
, Qnil
);
13479 /* Record this function, so it appears on the profiler's backtraces. */
13480 record_in_backtrace (Qredisplay_internal
, 0, 0);
13482 FOR_EACH_FRAME (tail
, frame
)
13483 XFRAME (frame
)->already_hscrolled_p
= false;
13486 /* Remember the currently selected window. */
13490 forget_escape_and_glyphless_faces ();
13492 inhibit_free_realized_faces
= false;
13494 /* If face_change, init_iterator will free all realized faces, which
13495 includes the faces referenced from current matrices. So, we
13496 can't reuse current matrices in this case. */
13498 windows_or_buffers_changed
= 47;
13500 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13501 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13503 /* Since frames on a single ASCII terminal share the same
13504 display area, displaying a different frame means redisplay
13505 the whole thing. */
13506 SET_FRAME_GARBAGED (sf
);
13508 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13510 FRAME_TTY (sf
)->previous_frame
= sf
;
13513 /* Set the visible flags for all frames. Do this before checking for
13514 resized or garbaged frames; they want to know if their frames are
13515 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13516 number_of_visible_frames
= 0;
13518 FOR_EACH_FRAME (tail
, frame
)
13520 struct frame
*f
= XFRAME (frame
);
13522 if (FRAME_VISIBLE_P (f
))
13524 ++number_of_visible_frames
;
13525 /* Adjust matrices for visible frames only. */
13526 if (f
->fonts_changed
)
13528 adjust_frame_glyphs (f
);
13529 /* Disable all redisplay optimizations for this frame.
13530 This is because adjust_frame_glyphs resets the
13531 enabled_p flag for all glyph rows of all windows, so
13532 many optimizations will fail anyway, and some might
13533 fail to test that flag and do bogus things as
13535 SET_FRAME_GARBAGED (f
);
13536 f
->fonts_changed
= false;
13538 /* If cursor type has been changed on the frame
13539 other than selected, consider all frames. */
13540 if (f
!= sf
&& f
->cursor_type_changed
)
13541 fset_redisplay (f
);
13543 clear_desired_matrices (f
);
13546 /* Notice any pending interrupt request to change frame size. */
13547 do_pending_window_change (true);
13549 /* do_pending_window_change could change the selected_window due to
13550 frame resizing which makes the selected window too small. */
13551 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13554 /* Clear frames marked as garbaged. */
13555 clear_garbaged_frames ();
13557 /* Build menubar and tool-bar items. */
13558 if (NILP (Vmemory_full
))
13559 prepare_menu_bars ();
13561 reconsider_clip_changes (w
);
13563 /* In most cases selected window displays current buffer. */
13564 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13567 /* Detect case that we need to write or remove a star in the mode line. */
13568 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13569 w
->update_mode_line
= true;
13571 if (mode_line_update_needed (w
))
13572 w
->update_mode_line
= true;
13574 /* If reconsider_clip_changes above decided that the narrowing
13575 in the current buffer changed, make sure all other windows
13576 showing that buffer will be redisplayed. */
13577 if (current_buffer
->clip_changed
)
13578 bset_update_mode_line (current_buffer
);
13581 /* Normally the message* functions will have already displayed and
13582 updated the echo area, but the frame may have been trashed, or
13583 the update may have been preempted, so display the echo area
13584 again here. Checking message_cleared_p captures the case that
13585 the echo area should be cleared. */
13586 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13587 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13588 || (message_cleared_p
13589 && minibuf_level
== 0
13590 /* If the mini-window is currently selected, this means the
13591 echo-area doesn't show through. */
13592 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13594 echo_area_display (false);
13596 /* If echo_area_display resizes the mini-window, the redisplay and
13597 window_sizes_changed flags of the selected frame are set, but
13598 it's too late for the hooks in window-size-change-functions,
13599 which have been examined already in prepare_menu_bars. So in
13600 that case we call the hooks here only for the selected frame. */
13601 if (sf
->redisplay
&& FRAME_WINDOW_SIZES_CHANGED (sf
))
13603 Lisp_Object functions
;
13604 ptrdiff_t count1
= SPECPDL_INDEX ();
13606 record_unwind_save_match_data ();
13608 /* Clear flag first in case we get an error below. */
13609 FRAME_WINDOW_SIZES_CHANGED (sf
) = false;
13610 functions
= Vwindow_size_change_functions
;
13612 while (CONSP (functions
))
13614 if (!EQ (XCAR (functions
), Qt
))
13615 call1 (XCAR (functions
), selected_frame
);
13616 functions
= XCDR (functions
);
13619 unbind_to (count1
, Qnil
);
13622 if (message_cleared_p
)
13623 update_miniwindow_p
= true;
13625 must_finish
= true;
13627 /* If we don't display the current message, don't clear the
13628 message_cleared_p flag, because, if we did, we wouldn't clear
13629 the echo area in the next redisplay which doesn't preserve
13631 if (!display_last_displayed_message_p
)
13632 message_cleared_p
= false;
13634 else if (EQ (selected_window
, minibuf_window
)
13635 && (current_buffer
->clip_changed
|| window_outdated (w
))
13636 && resize_mini_window (w
, false))
13640 Lisp_Object functions
;
13641 ptrdiff_t count1
= SPECPDL_INDEX ();
13643 record_unwind_save_match_data ();
13645 /* Clear flag first in case we get an error below. */
13646 FRAME_WINDOW_SIZES_CHANGED (sf
) = false;
13647 functions
= Vwindow_size_change_functions
;
13649 while (CONSP (functions
))
13651 if (!EQ (XCAR (functions
), Qt
))
13652 call1 (XCAR (functions
), selected_frame
);
13653 functions
= XCDR (functions
);
13656 unbind_to (count1
, Qnil
);
13659 /* Resized active mini-window to fit the size of what it is
13660 showing if its contents might have changed. */
13661 must_finish
= true;
13663 /* If window configuration was changed, frames may have been
13664 marked garbaged. Clear them or we will experience
13665 surprises wrt scrolling. */
13666 clear_garbaged_frames ();
13669 if (windows_or_buffers_changed
&& !update_mode_lines
)
13670 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13671 only the windows's contents needs to be refreshed, or whether the
13672 mode-lines also need a refresh. */
13673 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13674 ? REDISPLAY_SOME
: 32);
13676 /* If specs for an arrow have changed, do thorough redisplay
13677 to ensure we remove any arrow that should no longer exist. */
13678 if (overlay_arrows_changed_p ())
13679 /* Apparently, this is the only case where we update other windows,
13680 without updating other mode-lines. */
13681 windows_or_buffers_changed
= 49;
13683 consider_all_windows_p
= (update_mode_lines
13684 || windows_or_buffers_changed
);
13686 #define AINC(a,i) \
13688 Lisp_Object entry = Fgethash (make_number (i), a, make_number (0)); \
13689 if (INTEGERP (entry)) \
13690 Fputhash (make_number (i), make_number (1 + XINT (entry)), a); \
13693 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13694 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13696 /* Optimize the case that only the line containing the cursor in the
13697 selected window has changed. Variables starting with this_ are
13698 set in display_line and record information about the line
13699 containing the cursor. */
13700 tlbufpos
= this_line_start_pos
;
13701 tlendpos
= this_line_end_pos
;
13702 if (!consider_all_windows_p
13703 && CHARPOS (tlbufpos
) > 0
13704 && !w
->update_mode_line
13705 && !current_buffer
->clip_changed
13706 && !current_buffer
->prevent_redisplay_optimizations_p
13707 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13708 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13709 && !XFRAME (w
->frame
)->cursor_type_changed
13710 && !XFRAME (w
->frame
)->face_change
13711 /* Make sure recorded data applies to current buffer, etc. */
13712 && this_line_buffer
== current_buffer
13715 && !w
->optional_new_start
13716 /* Point must be on the line that we have info recorded about. */
13717 && PT
>= CHARPOS (tlbufpos
)
13718 && PT
<= Z
- CHARPOS (tlendpos
)
13719 /* All text outside that line, including its final newline,
13720 must be unchanged. */
13721 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13722 CHARPOS (tlendpos
)))
13724 if (CHARPOS (tlbufpos
) > BEGV
13725 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13726 && (CHARPOS (tlbufpos
) == ZV
13727 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13728 /* Former continuation line has disappeared by becoming empty. */
13730 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13732 /* We have to handle the case of continuation around a
13733 wide-column character (see the comment in indent.c around
13736 For instance, in the following case:
13738 -------- Insert --------
13739 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13740 J_I_ ==> J_I_ `^^' are cursors.
13744 As we have to redraw the line above, we cannot use this
13748 int line_height_before
= this_line_pixel_height
;
13750 /* Note that start_display will handle the case that the
13751 line starting at tlbufpos is a continuation line. */
13752 start_display (&it
, w
, tlbufpos
);
13754 /* Implementation note: It this still necessary? */
13755 if (it
.current_x
!= this_line_start_x
)
13758 TRACE ((stderr
, "trying display optimization 1\n"));
13759 w
->cursor
.vpos
= -1;
13760 overlay_arrow_seen
= false;
13761 it
.vpos
= this_line_vpos
;
13762 it
.current_y
= this_line_y
;
13763 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13764 display_line (&it
);
13766 /* If line contains point, is not continued,
13767 and ends at same distance from eob as before, we win. */
13768 if (w
->cursor
.vpos
>= 0
13769 /* Line is not continued, otherwise this_line_start_pos
13770 would have been set to 0 in display_line. */
13771 && CHARPOS (this_line_start_pos
)
13772 /* Line ends as before. */
13773 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13774 /* Line has same height as before. Otherwise other lines
13775 would have to be shifted up or down. */
13776 && this_line_pixel_height
== line_height_before
)
13778 /* If this is not the window's last line, we must adjust
13779 the charstarts of the lines below. */
13780 if (it
.current_y
< it
.last_visible_y
)
13782 struct glyph_row
*row
13783 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13784 ptrdiff_t delta
, delta_bytes
;
13786 /* We used to distinguish between two cases here,
13787 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13788 when the line ends in a newline or the end of the
13789 buffer's accessible portion. But both cases did
13790 the same, so they were collapsed. */
13792 - CHARPOS (tlendpos
)
13793 - MATRIX_ROW_START_CHARPOS (row
));
13794 delta_bytes
= (Z_BYTE
13795 - BYTEPOS (tlendpos
)
13796 - MATRIX_ROW_START_BYTEPOS (row
));
13798 increment_matrix_positions (w
->current_matrix
,
13799 this_line_vpos
+ 1,
13800 w
->current_matrix
->nrows
,
13801 delta
, delta_bytes
);
13804 /* If this row displays text now but previously didn't,
13805 or vice versa, w->window_end_vpos may have to be
13807 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13809 if (w
->window_end_vpos
< this_line_vpos
)
13810 w
->window_end_vpos
= this_line_vpos
;
13812 else if (w
->window_end_vpos
== this_line_vpos
13813 && this_line_vpos
> 0)
13814 w
->window_end_vpos
= this_line_vpos
- 1;
13815 w
->window_end_valid
= false;
13817 /* Update hint: No need to try to scroll in update_window. */
13818 w
->desired_matrix
->no_scrolling_p
= true;
13821 *w
->desired_matrix
->method
= 0;
13822 debug_method_add (w
, "optimization 1");
13824 #ifdef HAVE_WINDOW_SYSTEM
13825 update_window_fringes (w
, false);
13832 else if (/* Cursor position hasn't changed. */
13833 PT
== w
->last_point
13834 /* Make sure the cursor was last displayed
13835 in this window. Otherwise we have to reposition it. */
13837 /* PXW: Must be converted to pixels, probably. */
13838 && 0 <= w
->cursor
.vpos
13839 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13843 do_pending_window_change (true);
13844 /* If selected_window changed, redisplay again. */
13845 if (WINDOWP (selected_window
)
13846 && (w
= XWINDOW (selected_window
)) != sw
)
13849 /* We used to always goto end_of_redisplay here, but this
13850 isn't enough if we have a blinking cursor. */
13851 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13852 goto end_of_redisplay
;
13856 /* If highlighting the region, or if the cursor is in the echo area,
13857 then we can't just move the cursor. */
13858 else if (NILP (Vshow_trailing_whitespace
)
13859 && !cursor_in_echo_area
)
13862 struct glyph_row
*row
;
13864 /* Skip from tlbufpos to PT and see where it is. Note that
13865 PT may be in invisible text. If so, we will end at the
13866 next visible position. */
13867 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13868 NULL
, DEFAULT_FACE_ID
);
13869 it
.current_x
= this_line_start_x
;
13870 it
.current_y
= this_line_y
;
13871 it
.vpos
= this_line_vpos
;
13873 /* The call to move_it_to stops in front of PT, but
13874 moves over before-strings. */
13875 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13877 if (it
.vpos
== this_line_vpos
13878 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13881 eassert (this_line_vpos
== it
.vpos
);
13882 eassert (this_line_y
== it
.current_y
);
13883 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13885 *w
->desired_matrix
->method
= 0;
13886 debug_method_add (w
, "optimization 3");
13895 /* Text changed drastically or point moved off of line. */
13896 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13899 CHARPOS (this_line_start_pos
) = 0;
13900 ++clear_face_cache_count
;
13901 #ifdef HAVE_WINDOW_SYSTEM
13902 ++clear_image_cache_count
;
13905 /* Build desired matrices, and update the display. If
13906 consider_all_windows_p, do it for all windows on all frames that
13907 require redisplay, as specified by their 'redisplay' flag.
13908 Otherwise do it for selected_window, only. */
13910 if (consider_all_windows_p
)
13912 FOR_EACH_FRAME (tail
, frame
)
13913 XFRAME (frame
)->updated_p
= false;
13915 propagate_buffer_redisplay ();
13917 FOR_EACH_FRAME (tail
, frame
)
13919 struct frame
*f
= XFRAME (frame
);
13921 /* We don't have to do anything for unselected terminal
13923 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13924 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13928 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13931 /* Only GC scrollbars when we redisplay the whole frame. */
13932 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13933 bool f_redisplay_flag
= f
->redisplay
;
13934 /* Mark all the scroll bars to be removed; we'll redeem
13935 the ones we want when we redisplay their windows. */
13936 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13937 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13939 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13940 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13941 /* Remember that the invisible frames need to be redisplayed next
13942 time they're visible. */
13943 else if (!REDISPLAY_SOME_P ())
13944 f
->redisplay
= true;
13946 /* The X error handler may have deleted that frame. */
13947 if (!FRAME_LIVE_P (f
))
13950 /* Any scroll bars which redisplay_windows should have
13951 nuked should now go away. */
13952 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13953 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13955 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13957 /* If fonts changed on visible frame, display again. */
13958 if (f
->fonts_changed
)
13960 adjust_frame_glyphs (f
);
13961 /* Disable all redisplay optimizations for this
13962 frame. For the reasons, see the comment near
13963 the previous call to adjust_frame_glyphs above. */
13964 SET_FRAME_GARBAGED (f
);
13965 f
->fonts_changed
= false;
13969 /* See if we have to hscroll. */
13970 if (!f
->already_hscrolled_p
)
13972 f
->already_hscrolled_p
= true;
13973 if (hscroll_windows (f
->root_window
))
13977 /* If the frame's redisplay flag was not set before
13978 we went about redisplaying its windows, but it is
13979 set now, that means we employed some redisplay
13980 optimizations inside redisplay_windows, and
13981 bypassed producing some screen lines. But if
13982 f->redisplay is now set, it might mean the old
13983 faces are no longer valid (e.g., if redisplaying
13984 some window called some Lisp which defined a new
13985 face or redefined an existing face), so trying to
13986 use them in update_frame will segfault.
13987 Therefore, we must redisplay this frame. */
13988 if (!f_redisplay_flag
&& f
->redisplay
)
13991 /* Prevent various kinds of signals during display
13992 update. stdio is not robust about handling
13993 signals, which can cause an apparent I/O error. */
13994 if (interrupt_input
)
13995 unrequest_sigio ();
13998 pending
|= update_frame (f
, false, false);
13999 f
->cursor_type_changed
= false;
14000 f
->updated_p
= true;
14005 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
14009 /* Do the mark_window_display_accurate after all windows have
14010 been redisplayed because this call resets flags in buffers
14011 which are needed for proper redisplay. */
14012 FOR_EACH_FRAME (tail
, frame
)
14014 struct frame
*f
= XFRAME (frame
);
14017 f
->redisplay
= false;
14018 mark_window_display_accurate (f
->root_window
, true);
14019 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
14020 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
14025 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
14027 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
14028 struct frame
*mini_frame
;
14030 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
14031 /* Use list_of_error, not Qerror, so that
14032 we catch only errors and don't run the debugger. */
14033 internal_condition_case_1 (redisplay_window_1
, selected_window
,
14035 redisplay_window_error
);
14036 if (update_miniwindow_p
)
14037 internal_condition_case_1 (redisplay_window_1
, mini_window
,
14039 redisplay_window_error
);
14041 /* Compare desired and current matrices, perform output. */
14044 /* If fonts changed, display again. Likewise if redisplay_window_1
14045 above caused some change (e.g., a change in faces) that requires
14046 considering the entire frame again. */
14047 if (sf
->fonts_changed
|| sf
->redisplay
)
14051 /* Set this to force a more thorough redisplay.
14052 Otherwise, we might immediately loop back to the
14053 above "else-if" clause (since all the conditions that
14054 led here might still be true), and we will then
14055 infloop, because the selected-frame's redisplay flag
14056 is not (and cannot be) reset. */
14057 windows_or_buffers_changed
= 50;
14062 /* Prevent freeing of realized faces, since desired matrices are
14063 pending that reference the faces we computed and cached. */
14064 inhibit_free_realized_faces
= true;
14066 /* Prevent various kinds of signals during display update.
14067 stdio is not robust about handling signals,
14068 which can cause an apparent I/O error. */
14069 if (interrupt_input
)
14070 unrequest_sigio ();
14073 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
14075 if (hscroll_windows (selected_window
))
14078 XWINDOW (selected_window
)->must_be_updated_p
= true;
14079 pending
= update_frame (sf
, false, false);
14080 sf
->cursor_type_changed
= false;
14083 /* We may have called echo_area_display at the top of this
14084 function. If the echo area is on another frame, that may
14085 have put text on a frame other than the selected one, so the
14086 above call to update_frame would not have caught it. Catch
14088 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
14089 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
14091 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
14093 XWINDOW (mini_window
)->must_be_updated_p
= true;
14094 pending
|= update_frame (mini_frame
, false, false);
14095 mini_frame
->cursor_type_changed
= false;
14096 if (!pending
&& hscroll_windows (mini_window
))
14101 /* If display was paused because of pending input, make sure we do a
14102 thorough update the next time. */
14105 /* Prevent the optimization at the beginning of
14106 redisplay_internal that tries a single-line update of the
14107 line containing the cursor in the selected window. */
14108 CHARPOS (this_line_start_pos
) = 0;
14110 /* Let the overlay arrow be updated the next time. */
14111 update_overlay_arrows (0);
14113 /* If we pause after scrolling, some rows in the current
14114 matrices of some windows are not valid. */
14115 if (!WINDOW_FULL_WIDTH_P (w
)
14116 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
14117 update_mode_lines
= 36;
14121 if (!consider_all_windows_p
)
14123 /* This has already been done above if
14124 consider_all_windows_p is set. */
14125 if (XBUFFER (w
->contents
)->text
->redisplay
14126 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
14127 /* This can happen if b->text->redisplay was set during
14129 propagate_buffer_redisplay ();
14130 mark_window_display_accurate_1 (w
, true);
14132 /* Say overlay arrows are up to date. */
14133 update_overlay_arrows (1);
14135 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
14136 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
14139 update_mode_lines
= 0;
14140 windows_or_buffers_changed
= 0;
14143 /* Start SIGIO interrupts coming again. Having them off during the
14144 code above makes it less likely one will discard output, but not
14145 impossible, since there might be stuff in the system buffer here.
14146 But it is much hairier to try to do anything about that. */
14147 if (interrupt_input
)
14151 /* If a frame has become visible which was not before, redisplay
14152 again, so that we display it. Expose events for such a frame
14153 (which it gets when becoming visible) don't call the parts of
14154 redisplay constructing glyphs, so simply exposing a frame won't
14155 display anything in this case. So, we have to display these
14156 frames here explicitly. */
14161 FOR_EACH_FRAME (tail
, frame
)
14163 if (XFRAME (frame
)->visible
)
14167 if (new_count
!= number_of_visible_frames
)
14168 windows_or_buffers_changed
= 52;
14171 /* Change frame size now if a change is pending. */
14172 do_pending_window_change (true);
14174 /* If we just did a pending size change, or have additional
14175 visible frames, or selected_window changed, redisplay again. */
14176 if ((windows_or_buffers_changed
&& !pending
)
14177 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
14180 /* Clear the face and image caches.
14182 We used to do this only if consider_all_windows_p. But the cache
14183 needs to be cleared if a timer creates images in the current
14184 buffer (e.g. the test case in Bug#6230). */
14186 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
14188 clear_face_cache (false);
14189 clear_face_cache_count
= 0;
14192 #ifdef HAVE_WINDOW_SYSTEM
14193 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
14195 clear_image_caches (Qnil
);
14196 clear_image_cache_count
= 0;
14198 #endif /* HAVE_WINDOW_SYSTEM */
14202 ns_set_doc_edited ();
14204 if (interrupt_input
&& interrupts_deferred
)
14207 unbind_to (count
, Qnil
);
14212 /* Redisplay, but leave alone any recent echo area message unless
14213 another message has been requested in its place.
14215 This is useful in situations where you need to redisplay but no
14216 user action has occurred, making it inappropriate for the message
14217 area to be cleared. See tracking_off and
14218 wait_reading_process_output for examples of these situations.
14220 FROM_WHERE is an integer saying from where this function was
14221 called. This is useful for debugging. */
14224 redisplay_preserve_echo_area (int from_where
)
14226 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
14228 if (!NILP (echo_area_buffer
[1]))
14230 /* We have a previously displayed message, but no current
14231 message. Redisplay the previous message. */
14232 display_last_displayed_message_p
= true;
14233 redisplay_internal ();
14234 display_last_displayed_message_p
= false;
14237 redisplay_internal ();
14239 flush_frame (SELECTED_FRAME ());
14243 /* Function registered with record_unwind_protect in redisplay_internal. */
14246 unwind_redisplay (void)
14248 redisplaying_p
= false;
14252 /* Mark the display of leaf window W as accurate or inaccurate.
14253 If ACCURATE_P, mark display of W as accurate.
14254 If !ACCURATE_P, arrange for W to be redisplayed the next
14255 time redisplay_internal is called. */
14258 mark_window_display_accurate_1 (struct window
*w
, bool accurate_p
)
14260 struct buffer
*b
= XBUFFER (w
->contents
);
14262 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
14263 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
14264 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
14268 b
->clip_changed
= false;
14269 b
->prevent_redisplay_optimizations_p
= false;
14270 eassert (buffer_window_count (b
) > 0);
14271 /* Resetting b->text->redisplay is problematic!
14272 In order to make it safer to do it here, redisplay_internal must
14273 have copied all b->text->redisplay to their respective windows. */
14274 b
->text
->redisplay
= false;
14276 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
14277 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
14278 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
14279 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
14281 w
->current_matrix
->buffer
= b
;
14282 w
->current_matrix
->begv
= BUF_BEGV (b
);
14283 w
->current_matrix
->zv
= BUF_ZV (b
);
14285 w
->last_cursor_vpos
= w
->cursor
.vpos
;
14286 w
->last_cursor_off_p
= w
->cursor_off_p
;
14288 if (w
== XWINDOW (selected_window
))
14289 w
->last_point
= BUF_PT (b
);
14291 w
->last_point
= marker_position (w
->pointm
);
14293 w
->window_end_valid
= true;
14294 w
->update_mode_line
= false;
14297 w
->redisplay
= !accurate_p
;
14301 /* Mark the display of windows in the window tree rooted at WINDOW as
14302 accurate or inaccurate. If ACCURATE_P, mark display of
14303 windows as accurate. If !ACCURATE_P, arrange for windows to
14304 be redisplayed the next time redisplay_internal is called. */
14307 mark_window_display_accurate (Lisp_Object window
, bool accurate_p
)
14311 for (; !NILP (window
); window
= w
->next
)
14313 w
= XWINDOW (window
);
14314 if (WINDOWP (w
->contents
))
14315 mark_window_display_accurate (w
->contents
, accurate_p
);
14317 mark_window_display_accurate_1 (w
, accurate_p
);
14321 update_overlay_arrows (1);
14323 /* Force a thorough redisplay the next time by setting
14324 last_arrow_position and last_arrow_string to t, which is
14325 unequal to any useful value of Voverlay_arrow_... */
14326 update_overlay_arrows (-1);
14330 /* Return value in display table DP (Lisp_Char_Table *) for character
14331 C. Since a display table doesn't have any parent, we don't have to
14332 follow parent. Do not call this function directly but use the
14333 macro DISP_CHAR_VECTOR. */
14336 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
14340 if (ASCII_CHAR_P (c
))
14343 if (SUB_CHAR_TABLE_P (val
))
14344 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
14350 XSETCHAR_TABLE (table
, dp
);
14351 val
= char_table_ref (table
, c
);
14360 /***********************************************************************
14362 ***********************************************************************/
14364 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
14367 redisplay_windows (Lisp_Object window
)
14369 while (!NILP (window
))
14371 struct window
*w
= XWINDOW (window
);
14373 if (WINDOWP (w
->contents
))
14374 redisplay_windows (w
->contents
);
14375 else if (BUFFERP (w
->contents
))
14377 displayed_buffer
= XBUFFER (w
->contents
);
14378 /* Use list_of_error, not Qerror, so that
14379 we catch only errors and don't run the debugger. */
14380 internal_condition_case_1 (redisplay_window_0
, window
,
14382 redisplay_window_error
);
14390 redisplay_window_error (Lisp_Object ignore
)
14392 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14397 redisplay_window_0 (Lisp_Object window
)
14399 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14400 redisplay_window (window
, false);
14405 redisplay_window_1 (Lisp_Object window
)
14407 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14408 redisplay_window (window
, true);
14413 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14414 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14415 which positions recorded in ROW differ from current buffer
14418 Return true iff cursor is on this row. */
14421 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14422 struct glyph_matrix
*matrix
,
14423 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14426 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14427 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14428 struct glyph
*cursor
= NULL
;
14429 /* The last known character position in row. */
14430 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14432 ptrdiff_t pt_old
= PT
- delta
;
14433 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14434 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14435 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14436 /* A glyph beyond the edge of TEXT_AREA which we should never
14438 struct glyph
*glyphs_end
= end
;
14439 /* True means we've found a match for cursor position, but that
14440 glyph has the avoid_cursor_p flag set. */
14441 bool match_with_avoid_cursor
= false;
14442 /* True means we've seen at least one glyph that came from a
14444 bool string_seen
= false;
14445 /* Largest and smallest buffer positions seen so far during scan of
14447 ptrdiff_t bpos_max
= pos_before
;
14448 ptrdiff_t bpos_min
= pos_after
;
14449 /* Last buffer position covered by an overlay string with an integer
14450 `cursor' property. */
14451 ptrdiff_t bpos_covered
= 0;
14452 /* True means the display string on which to display the cursor
14453 comes from a text property, not from an overlay. */
14454 bool string_from_text_prop
= false;
14456 /* Don't even try doing anything if called for a mode-line or
14457 header-line row, since the rest of the code isn't prepared to
14458 deal with such calamities. */
14459 eassert (!row
->mode_line_p
);
14460 if (row
->mode_line_p
)
14463 /* Skip over glyphs not having an object at the start and the end of
14464 the row. These are special glyphs like truncation marks on
14465 terminal frames. */
14466 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14468 if (!row
->reversed_p
)
14471 && NILP (glyph
->object
)
14472 && glyph
->charpos
< 0)
14474 x
+= glyph
->pixel_width
;
14478 && NILP ((end
- 1)->object
)
14479 /* CHARPOS is zero for blanks and stretch glyphs
14480 inserted by extend_face_to_end_of_line. */
14481 && (end
- 1)->charpos
<= 0)
14483 glyph_before
= glyph
- 1;
14490 /* If the glyph row is reversed, we need to process it from back
14491 to front, so swap the edge pointers. */
14492 glyphs_end
= end
= glyph
- 1;
14493 glyph
+= row
->used
[TEXT_AREA
] - 1;
14495 while (glyph
> end
+ 1
14496 && NILP (glyph
->object
)
14497 && glyph
->charpos
< 0)
14500 x
-= glyph
->pixel_width
;
14502 if (NILP (glyph
->object
) && glyph
->charpos
< 0)
14504 /* By default, in reversed rows we put the cursor on the
14505 rightmost (first in the reading order) glyph. */
14506 for (g
= end
+ 1; g
< glyph
; g
++)
14507 x
+= g
->pixel_width
;
14509 && NILP ((end
+ 1)->object
)
14510 && (end
+ 1)->charpos
<= 0)
14512 glyph_before
= glyph
+ 1;
14516 else if (row
->reversed_p
)
14518 /* In R2L rows that don't display text, put the cursor on the
14519 rightmost glyph. Case in point: an empty last line that is
14520 part of an R2L paragraph. */
14522 /* Avoid placing the cursor on the last glyph of the row, where
14523 on terminal frames we hold the vertical border between
14524 adjacent windows. */
14525 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14526 && !WINDOW_RIGHTMOST_P (w
)
14527 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14529 x
= -1; /* will be computed below, at label compute_x */
14532 /* Step 1: Try to find the glyph whose character position
14533 corresponds to point. If that's not possible, find 2 glyphs
14534 whose character positions are the closest to point, one before
14535 point, the other after it. */
14536 if (!row
->reversed_p
)
14537 while (/* not marched to end of glyph row */
14539 /* glyph was not inserted by redisplay for internal purposes */
14540 && !NILP (glyph
->object
))
14542 if (BUFFERP (glyph
->object
))
14544 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14546 if (glyph
->charpos
> bpos_max
)
14547 bpos_max
= glyph
->charpos
;
14548 if (glyph
->charpos
< bpos_min
)
14549 bpos_min
= glyph
->charpos
;
14550 if (!glyph
->avoid_cursor_p
)
14552 /* If we hit point, we've found the glyph on which to
14553 display the cursor. */
14556 match_with_avoid_cursor
= false;
14559 /* See if we've found a better approximation to
14560 POS_BEFORE or to POS_AFTER. */
14561 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14563 pos_before
= glyph
->charpos
;
14564 glyph_before
= glyph
;
14566 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14568 pos_after
= glyph
->charpos
;
14569 glyph_after
= glyph
;
14572 else if (dpos
== 0)
14573 match_with_avoid_cursor
= true;
14575 else if (STRINGP (glyph
->object
))
14577 Lisp_Object chprop
;
14578 ptrdiff_t glyph_pos
= glyph
->charpos
;
14580 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14582 if (!NILP (chprop
))
14584 /* If the string came from a `display' text property,
14585 look up the buffer position of that property and
14586 use that position to update bpos_max, as if we
14587 actually saw such a position in one of the row's
14588 glyphs. This helps with supporting integer values
14589 of `cursor' property on the display string in
14590 situations where most or all of the row's buffer
14591 text is completely covered by display properties,
14592 so that no glyph with valid buffer positions is
14593 ever seen in the row. */
14594 ptrdiff_t prop_pos
=
14595 string_buffer_position_lim (glyph
->object
, pos_before
,
14598 if (prop_pos
>= pos_before
)
14599 bpos_max
= prop_pos
;
14601 if (INTEGERP (chprop
))
14603 bpos_covered
= bpos_max
+ XINT (chprop
);
14604 /* If the `cursor' property covers buffer positions up
14605 to and including point, we should display cursor on
14606 this glyph. Note that, if a `cursor' property on one
14607 of the string's characters has an integer value, we
14608 will break out of the loop below _before_ we get to
14609 the position match above. IOW, integer values of
14610 the `cursor' property override the "exact match for
14611 point" strategy of positioning the cursor. */
14612 /* Implementation note: bpos_max == pt_old when, e.g.,
14613 we are in an empty line, where bpos_max is set to
14614 MATRIX_ROW_START_CHARPOS, see above. */
14615 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14622 string_seen
= true;
14624 x
+= glyph
->pixel_width
;
14627 else if (glyph
> end
) /* row is reversed */
14628 while (!NILP (glyph
->object
))
14630 if (BUFFERP (glyph
->object
))
14632 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14634 if (glyph
->charpos
> bpos_max
)
14635 bpos_max
= glyph
->charpos
;
14636 if (glyph
->charpos
< bpos_min
)
14637 bpos_min
= glyph
->charpos
;
14638 if (!glyph
->avoid_cursor_p
)
14642 match_with_avoid_cursor
= false;
14645 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14647 pos_before
= glyph
->charpos
;
14648 glyph_before
= glyph
;
14650 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14652 pos_after
= glyph
->charpos
;
14653 glyph_after
= glyph
;
14656 else if (dpos
== 0)
14657 match_with_avoid_cursor
= true;
14659 else if (STRINGP (glyph
->object
))
14661 Lisp_Object chprop
;
14662 ptrdiff_t glyph_pos
= glyph
->charpos
;
14664 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14666 if (!NILP (chprop
))
14668 ptrdiff_t prop_pos
=
14669 string_buffer_position_lim (glyph
->object
, pos_before
,
14672 if (prop_pos
>= pos_before
)
14673 bpos_max
= prop_pos
;
14675 if (INTEGERP (chprop
))
14677 bpos_covered
= bpos_max
+ XINT (chprop
);
14678 /* If the `cursor' property covers buffer positions up
14679 to and including point, we should display cursor on
14681 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14687 string_seen
= true;
14690 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14692 x
--; /* can't use any pixel_width */
14695 x
-= glyph
->pixel_width
;
14698 /* Step 2: If we didn't find an exact match for point, we need to
14699 look for a proper place to put the cursor among glyphs between
14700 GLYPH_BEFORE and GLYPH_AFTER. */
14701 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14702 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14703 && !(bpos_max
<= pt_old
&& pt_old
<= bpos_covered
))
14705 /* An empty line has a single glyph whose OBJECT is nil and
14706 whose CHARPOS is the position of a newline on that line.
14707 Note that on a TTY, there are more glyphs after that, which
14708 were produced by extend_face_to_end_of_line, but their
14709 CHARPOS is zero or negative. */
14710 bool empty_line_p
=
14711 ((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14712 && NILP (glyph
->object
) && glyph
->charpos
> 0
14713 /* On a TTY, continued and truncated rows also have a glyph at
14714 their end whose OBJECT is nil and whose CHARPOS is
14715 positive (the continuation and truncation glyphs), but such
14716 rows are obviously not "empty". */
14717 && !(row
->continued_p
|| row
->truncated_on_right_p
));
14719 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14721 ptrdiff_t ellipsis_pos
;
14723 /* Scan back over the ellipsis glyphs. */
14724 if (!row
->reversed_p
)
14726 ellipsis_pos
= (glyph
- 1)->charpos
;
14727 while (glyph
> row
->glyphs
[TEXT_AREA
]
14728 && (glyph
- 1)->charpos
== ellipsis_pos
)
14729 glyph
--, x
-= glyph
->pixel_width
;
14730 /* That loop always goes one position too far, including
14731 the glyph before the ellipsis. So scan forward over
14733 x
+= glyph
->pixel_width
;
14736 else /* row is reversed */
14738 ellipsis_pos
= (glyph
+ 1)->charpos
;
14739 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14740 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14741 glyph
++, x
+= glyph
->pixel_width
;
14742 x
-= glyph
->pixel_width
;
14746 else if (match_with_avoid_cursor
)
14748 cursor
= glyph_after
;
14751 else if (string_seen
)
14753 int incr
= row
->reversed_p
? -1 : +1;
14755 /* Need to find the glyph that came out of a string which is
14756 present at point. That glyph is somewhere between
14757 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14758 positioned between POS_BEFORE and POS_AFTER in the
14760 struct glyph
*start
, *stop
;
14761 ptrdiff_t pos
= pos_before
;
14765 /* If the row ends in a newline from a display string,
14766 reordering could have moved the glyphs belonging to the
14767 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14768 in this case we extend the search to the last glyph in
14769 the row that was not inserted by redisplay. */
14770 if (row
->ends_in_newline_from_string_p
)
14773 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14776 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14777 correspond to POS_BEFORE and POS_AFTER, respectively. We
14778 need START and STOP in the order that corresponds to the
14779 row's direction as given by its reversed_p flag. If the
14780 directionality of characters between POS_BEFORE and
14781 POS_AFTER is the opposite of the row's base direction,
14782 these characters will have been reordered for display,
14783 and we need to reverse START and STOP. */
14784 if (!row
->reversed_p
)
14786 start
= min (glyph_before
, glyph_after
);
14787 stop
= max (glyph_before
, glyph_after
);
14791 start
= max (glyph_before
, glyph_after
);
14792 stop
= min (glyph_before
, glyph_after
);
14794 for (glyph
= start
+ incr
;
14795 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14798 /* Any glyphs that come from the buffer are here because
14799 of bidi reordering. Skip them, and only pay
14800 attention to glyphs that came from some string. */
14801 if (STRINGP (glyph
->object
))
14805 /* If the display property covers the newline, we
14806 need to search for it one position farther. */
14807 ptrdiff_t lim
= pos_after
14808 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14810 string_from_text_prop
= false;
14811 str
= glyph
->object
;
14812 tem
= string_buffer_position_lim (str
, pos
, lim
, false);
14813 if (tem
== 0 /* from overlay */
14816 /* If the string from which this glyph came is
14817 found in the buffer at point, or at position
14818 that is closer to point than pos_after, then
14819 we've found the glyph we've been looking for.
14820 If it comes from an overlay (tem == 0), and
14821 it has the `cursor' property on one of its
14822 glyphs, record that glyph as a candidate for
14823 displaying the cursor. (As in the
14824 unidirectional version, we will display the
14825 cursor on the last candidate we find.) */
14828 || (tem
- pt_old
> 0 && tem
< pos_after
))
14830 /* The glyphs from this string could have
14831 been reordered. Find the one with the
14832 smallest string position. Or there could
14833 be a character in the string with the
14834 `cursor' property, which means display
14835 cursor on that character's glyph. */
14836 ptrdiff_t strpos
= glyph
->charpos
;
14841 string_from_text_prop
= true;
14844 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14845 && EQ (glyph
->object
, str
);
14849 ptrdiff_t gpos
= glyph
->charpos
;
14851 cprop
= Fget_char_property (make_number (gpos
),
14859 if (tem
&& glyph
->charpos
< strpos
)
14861 strpos
= glyph
->charpos
;
14867 || (tem
- pt_old
> 0 && tem
< pos_after
))
14871 pos
= tem
+ 1; /* don't find previous instances */
14873 /* This string is not what we want; skip all of the
14874 glyphs that came from it. */
14875 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14876 && EQ (glyph
->object
, str
))
14883 /* If we reached the end of the line, and END was from a string,
14884 the cursor is not on this line. */
14886 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14887 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14888 && STRINGP (end
->object
)
14889 && row
->continued_p
)
14892 /* A truncated row may not include PT among its character positions.
14893 Setting the cursor inside the scroll margin will trigger
14894 recalculation of hscroll in hscroll_window_tree. But if a
14895 display string covers point, defer to the string-handling
14896 code below to figure this out. */
14897 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14899 cursor
= glyph_before
;
14902 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14903 /* Zero-width characters produce no glyphs. */
14905 && (row
->reversed_p
14906 ? glyph_after
> glyphs_end
14907 : glyph_after
< glyphs_end
)))
14909 cursor
= glyph_after
;
14915 if (cursor
!= NULL
)
14917 else if (glyph
== glyphs_end
14918 && pos_before
== pos_after
14919 && STRINGP ((row
->reversed_p
14920 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14921 : row
->glyphs
[TEXT_AREA
])->object
))
14923 /* If all the glyphs of this row came from strings, put the
14924 cursor on the first glyph of the row. This avoids having the
14925 cursor outside of the text area in this very rare and hard
14929 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14930 : row
->glyphs
[TEXT_AREA
];
14936 /* Need to compute x that corresponds to GLYPH. */
14937 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14939 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14941 x
+= g
->pixel_width
;
14945 /* ROW could be part of a continued line, which, under bidi
14946 reordering, might have other rows whose start and end charpos
14947 occlude point. Only set w->cursor if we found a better
14948 approximation to the cursor position than we have from previously
14949 examined candidate rows belonging to the same continued line. */
14950 if (/* We already have a candidate row. */
14951 w
->cursor
.vpos
>= 0
14952 /* That candidate is not the row we are processing. */
14953 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14954 /* Make sure cursor.vpos specifies a row whose start and end
14955 charpos occlude point, and it is valid candidate for being a
14956 cursor-row. This is because some callers of this function
14957 leave cursor.vpos at the row where the cursor was displayed
14958 during the last redisplay cycle. */
14959 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14960 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14961 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14964 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14966 /* Don't consider glyphs that are outside TEXT_AREA. */
14967 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14969 /* Keep the candidate whose buffer position is the closest to
14970 point or has the `cursor' property. */
14971 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14972 w
->cursor
.hpos
>= 0
14973 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14974 && ((BUFFERP (g1
->object
)
14975 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14976 || (BUFFERP (glyph
->object
)
14977 && eabs (g1
->charpos
- pt_old
)
14978 < eabs (glyph
->charpos
- pt_old
))))
14979 /* Previous candidate is a glyph from a string that has
14980 a non-nil `cursor' property. */
14981 || (STRINGP (g1
->object
)
14982 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14983 Qcursor
, g1
->object
))
14984 /* Previous candidate is from the same display
14985 string as this one, and the display string
14986 came from a text property. */
14987 || (EQ (g1
->object
, glyph
->object
)
14988 && string_from_text_prop
)
14989 /* this candidate is from newline and its
14990 position is not an exact match */
14991 || (NILP (glyph
->object
)
14992 && glyph
->charpos
!= pt_old
)))))
14994 /* If this candidate gives an exact match, use that. */
14995 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14996 /* If this candidate is a glyph created for the
14997 terminating newline of a line, and point is on that
14998 newline, it wins because it's an exact match. */
14999 || (!row
->continued_p
15000 && NILP (glyph
->object
)
15001 && glyph
->charpos
== 0
15002 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
15003 /* Otherwise, keep the candidate that comes from a row
15004 spanning less buffer positions. This may win when one or
15005 both candidate positions are on glyphs that came from
15006 display strings, for which we cannot compare buffer
15008 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15009 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
15010 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
15013 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
15015 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
15016 w
->cursor
.y
= row
->y
+ dy
;
15018 if (w
== XWINDOW (selected_window
))
15020 if (!row
->continued_p
15021 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15024 this_line_buffer
= XBUFFER (w
->contents
);
15026 CHARPOS (this_line_start_pos
)
15027 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
15028 BYTEPOS (this_line_start_pos
)
15029 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
15031 CHARPOS (this_line_end_pos
)
15032 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
15033 BYTEPOS (this_line_end_pos
)
15034 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
15036 this_line_y
= w
->cursor
.y
;
15037 this_line_pixel_height
= row
->height
;
15038 this_line_vpos
= w
->cursor
.vpos
;
15039 this_line_start_x
= row
->x
;
15042 CHARPOS (this_line_start_pos
) = 0;
15049 /* Run window scroll functions, if any, for WINDOW with new window
15050 start STARTP. Sets the window start of WINDOW to that position.
15052 We assume that the window's buffer is really current. */
15054 static struct text_pos
15055 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
15057 struct window
*w
= XWINDOW (window
);
15058 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
15060 eassert (current_buffer
== XBUFFER (w
->contents
));
15062 if (!NILP (Vwindow_scroll_functions
))
15064 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
15065 make_number (CHARPOS (startp
)));
15066 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15067 /* In case the hook functions switch buffers. */
15068 set_buffer_internal (XBUFFER (w
->contents
));
15075 /* Make sure the line containing the cursor is fully visible.
15076 A value of true means there is nothing to be done.
15077 (Either the line is fully visible, or it cannot be made so,
15078 or we cannot tell.)
15080 If FORCE_P, return false even if partial visible cursor row
15081 is higher than window.
15083 If CURRENT_MATRIX_P, use the information from the
15084 window's current glyph matrix; otherwise use the desired glyph
15087 A value of false means the caller should do scrolling
15088 as if point had gone off the screen. */
15091 cursor_row_fully_visible_p (struct window
*w
, bool force_p
,
15092 bool current_matrix_p
)
15094 struct glyph_matrix
*matrix
;
15095 struct glyph_row
*row
;
15098 if (!make_cursor_line_fully_visible_p
)
15101 /* It's not always possible to find the cursor, e.g, when a window
15102 is full of overlay strings. Don't do anything in that case. */
15103 if (w
->cursor
.vpos
< 0)
15106 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
15107 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
15109 /* If the cursor row is not partially visible, there's nothing to do. */
15110 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
15113 /* If the row the cursor is in is taller than the window's height,
15114 it's not clear what to do, so do nothing. */
15115 window_height
= window_box_height (w
);
15116 if (row
->height
>= window_height
)
15118 if (!force_p
|| MINI_WINDOW_P (w
)
15119 || w
->vscroll
|| w
->cursor
.vpos
== 0)
15126 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
15127 means only WINDOW is redisplayed in redisplay_internal.
15128 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
15129 in redisplay_window to bring a partially visible line into view in
15130 the case that only the cursor has moved.
15132 LAST_LINE_MISFIT should be true if we're scrolling because the
15133 last screen line's vertical height extends past the end of the screen.
15137 1 if scrolling succeeded
15139 0 if scrolling didn't find point.
15141 -1 if new fonts have been loaded so that we must interrupt
15142 redisplay, adjust glyph matrices, and try again. */
15148 SCROLLING_NEED_LARGER_MATRICES
15151 /* If scroll-conservatively is more than this, never recenter.
15153 If you change this, don't forget to update the doc string of
15154 `scroll-conservatively' and the Emacs manual. */
15155 #define SCROLL_LIMIT 100
15158 try_scrolling (Lisp_Object window
, bool just_this_one_p
,
15159 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
15160 bool temp_scroll_step
, bool last_line_misfit
)
15162 struct window
*w
= XWINDOW (window
);
15163 struct frame
*f
= XFRAME (w
->frame
);
15164 struct text_pos pos
, startp
;
15166 int this_scroll_margin
, scroll_max
, rc
, height
;
15167 int dy
= 0, amount_to_scroll
= 0;
15168 bool scroll_down_p
= false;
15169 int extra_scroll_margin_lines
= last_line_misfit
;
15170 Lisp_Object aggressive
;
15171 /* We will never try scrolling more than this number of lines. */
15172 int scroll_limit
= SCROLL_LIMIT
;
15173 int frame_line_height
= default_line_pixel_height (w
);
15174 int window_total_lines
15175 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15178 debug_method_add (w
, "try_scrolling");
15181 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15183 /* Compute scroll margin height in pixels. We scroll when point is
15184 within this distance from the top or bottom of the window. */
15185 if (scroll_margin
> 0)
15186 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
15187 * frame_line_height
;
15189 this_scroll_margin
= 0;
15191 /* Force arg_scroll_conservatively to have a reasonable value, to
15192 avoid scrolling too far away with slow move_it_* functions. Note
15193 that the user can supply scroll-conservatively equal to
15194 `most-positive-fixnum', which can be larger than INT_MAX. */
15195 if (arg_scroll_conservatively
> scroll_limit
)
15197 arg_scroll_conservatively
= scroll_limit
+ 1;
15198 scroll_max
= scroll_limit
* frame_line_height
;
15200 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
15201 /* Compute how much we should try to scroll maximally to bring
15202 point into view. */
15203 scroll_max
= (max (scroll_step
,
15204 max (arg_scroll_conservatively
, temp_scroll_step
))
15205 * frame_line_height
);
15206 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
15207 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
15208 /* We're trying to scroll because of aggressive scrolling but no
15209 scroll_step is set. Choose an arbitrary one. */
15210 scroll_max
= 10 * frame_line_height
;
15216 /* Decide whether to scroll down. */
15217 if (PT
> CHARPOS (startp
))
15219 int scroll_margin_y
;
15221 /* Compute the pixel ypos of the scroll margin, then move IT to
15222 either that ypos or PT, whichever comes first. */
15223 start_display (&it
, w
, startp
);
15224 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
15225 - frame_line_height
* extra_scroll_margin_lines
;
15226 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
15227 (MOVE_TO_POS
| MOVE_TO_Y
));
15229 if (PT
> CHARPOS (it
.current
.pos
))
15231 int y0
= line_bottom_y (&it
);
15232 /* Compute how many pixels below window bottom to stop searching
15233 for PT. This avoids costly search for PT that is far away if
15234 the user limited scrolling by a small number of lines, but
15235 always finds PT if scroll_conservatively is set to a large
15236 number, such as most-positive-fixnum. */
15237 int slack
= max (scroll_max
, 10 * frame_line_height
);
15238 int y_to_move
= it
.last_visible_y
+ slack
;
15240 /* Compute the distance from the scroll margin to PT or to
15241 the scroll limit, whichever comes first. This should
15242 include the height of the cursor line, to make that line
15244 move_it_to (&it
, PT
, -1, y_to_move
,
15245 -1, MOVE_TO_POS
| MOVE_TO_Y
);
15246 dy
= line_bottom_y (&it
) - y0
;
15248 if (dy
> scroll_max
)
15249 return SCROLLING_FAILED
;
15252 scroll_down_p
= true;
15258 /* Point is in or below the bottom scroll margin, so move the
15259 window start down. If scrolling conservatively, move it just
15260 enough down to make point visible. If scroll_step is set,
15261 move it down by scroll_step. */
15262 if (arg_scroll_conservatively
)
15264 = min (max (dy
, frame_line_height
),
15265 frame_line_height
* arg_scroll_conservatively
);
15266 else if (scroll_step
|| temp_scroll_step
)
15267 amount_to_scroll
= scroll_max
;
15270 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
15271 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15272 if (NUMBERP (aggressive
))
15274 double float_amount
= XFLOATINT (aggressive
) * height
;
15275 int aggressive_scroll
= float_amount
;
15276 if (aggressive_scroll
== 0 && float_amount
> 0)
15277 aggressive_scroll
= 1;
15278 /* Don't let point enter the scroll margin near top of
15279 the window. This could happen if the value of
15280 scroll_up_aggressively is too large and there are
15281 non-zero margins, because scroll_up_aggressively
15282 means put point that fraction of window height
15283 _from_the_bottom_margin_. */
15284 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15285 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15286 amount_to_scroll
= dy
+ aggressive_scroll
;
15290 if (amount_to_scroll
<= 0)
15291 return SCROLLING_FAILED
;
15293 start_display (&it
, w
, startp
);
15294 if (arg_scroll_conservatively
<= scroll_limit
)
15295 move_it_vertically (&it
, amount_to_scroll
);
15298 /* Extra precision for users who set scroll-conservatively
15299 to a large number: make sure the amount we scroll
15300 the window start is never less than amount_to_scroll,
15301 which was computed as distance from window bottom to
15302 point. This matters when lines at window top and lines
15303 below window bottom have different height. */
15305 void *it1data
= NULL
;
15306 /* We use a temporary it1 because line_bottom_y can modify
15307 its argument, if it moves one line down; see there. */
15310 SAVE_IT (it1
, it
, it1data
);
15311 start_y
= line_bottom_y (&it1
);
15313 RESTORE_IT (&it
, &it
, it1data
);
15314 move_it_by_lines (&it
, 1);
15315 SAVE_IT (it1
, it
, it1data
);
15316 } while (IT_CHARPOS (it
) < ZV
15317 && line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
15318 bidi_unshelve_cache (it1data
, true);
15321 /* If STARTP is unchanged, move it down another screen line. */
15322 if (IT_CHARPOS (it
) == CHARPOS (startp
))
15323 move_it_by_lines (&it
, 1);
15324 startp
= it
.current
.pos
;
15328 struct text_pos scroll_margin_pos
= startp
;
15331 /* See if point is inside the scroll margin at the top of the
15333 if (this_scroll_margin
)
15337 start_display (&it
, w
, startp
);
15338 y_start
= it
.current_y
;
15339 move_it_vertically (&it
, this_scroll_margin
);
15340 scroll_margin_pos
= it
.current
.pos
;
15341 /* If we didn't move enough before hitting ZV, request
15342 additional amount of scroll, to move point out of the
15344 if (IT_CHARPOS (it
) == ZV
15345 && it
.current_y
- y_start
< this_scroll_margin
)
15346 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
15349 if (PT
< CHARPOS (scroll_margin_pos
))
15351 /* Point is in the scroll margin at the top of the window or
15352 above what is displayed in the window. */
15355 /* Compute the vertical distance from PT to the scroll
15356 margin position. Move as far as scroll_max allows, or
15357 one screenful, or 10 screen lines, whichever is largest.
15358 Give up if distance is greater than scroll_max or if we
15359 didn't reach the scroll margin position. */
15360 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
15361 start_display (&it
, w
, pos
);
15363 y_to_move
= max (it
.last_visible_y
,
15364 max (scroll_max
, 10 * frame_line_height
));
15365 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
15367 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15368 dy
= it
.current_y
- y0
;
15369 if (dy
> scroll_max
15370 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
15371 return SCROLLING_FAILED
;
15373 /* Additional scroll for when ZV was too close to point. */
15376 /* Compute new window start. */
15377 start_display (&it
, w
, startp
);
15379 if (arg_scroll_conservatively
)
15380 amount_to_scroll
= max (dy
, frame_line_height
15381 * max (scroll_step
, temp_scroll_step
));
15382 else if (scroll_step
|| temp_scroll_step
)
15383 amount_to_scroll
= scroll_max
;
15386 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15387 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15388 if (NUMBERP (aggressive
))
15390 double float_amount
= XFLOATINT (aggressive
) * height
;
15391 int aggressive_scroll
= float_amount
;
15392 if (aggressive_scroll
== 0 && float_amount
> 0)
15393 aggressive_scroll
= 1;
15394 /* Don't let point enter the scroll margin near
15395 bottom of the window, if the value of
15396 scroll_down_aggressively happens to be too
15398 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15399 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15400 amount_to_scroll
= dy
+ aggressive_scroll
;
15404 if (amount_to_scroll
<= 0)
15405 return SCROLLING_FAILED
;
15407 move_it_vertically_backward (&it
, amount_to_scroll
);
15408 startp
= it
.current
.pos
;
15412 /* Run window scroll functions. */
15413 startp
= run_window_scroll_functions (window
, startp
);
15415 /* Display the window. Give up if new fonts are loaded, or if point
15417 if (!try_window (window
, startp
, 0))
15418 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15419 else if (w
->cursor
.vpos
< 0)
15421 clear_glyph_matrix (w
->desired_matrix
);
15422 rc
= SCROLLING_FAILED
;
15426 /* Maybe forget recorded base line for line number display. */
15427 if (!just_this_one_p
15428 || current_buffer
->clip_changed
15429 || BEG_UNCHANGED
< CHARPOS (startp
))
15430 w
->base_line_number
= 0;
15432 /* If cursor ends up on a partially visible line,
15433 treat that as being off the bottom of the screen. */
15434 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1,
15436 /* It's possible that the cursor is on the first line of the
15437 buffer, which is partially obscured due to a vscroll
15438 (Bug#7537). In that case, avoid looping forever. */
15439 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15441 clear_glyph_matrix (w
->desired_matrix
);
15442 ++extra_scroll_margin_lines
;
15445 rc
= SCROLLING_SUCCESS
;
15452 /* Compute a suitable window start for window W if display of W starts
15453 on a continuation line. Value is true if a new window start
15456 The new window start will be computed, based on W's width, starting
15457 from the start of the continued line. It is the start of the
15458 screen line with the minimum distance from the old start W->start. */
15461 compute_window_start_on_continuation_line (struct window
*w
)
15463 struct text_pos pos
, start_pos
;
15464 bool window_start_changed_p
= false;
15466 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15468 /* If window start is on a continuation line... Window start may be
15469 < BEGV in case there's invisible text at the start of the
15470 buffer (M-x rmail, for example). */
15471 if (CHARPOS (start_pos
) > BEGV
15472 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15475 struct glyph_row
*row
;
15477 /* Handle the case that the window start is out of range. */
15478 if (CHARPOS (start_pos
) < BEGV
)
15479 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15480 else if (CHARPOS (start_pos
) > ZV
)
15481 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15483 /* Find the start of the continued line. This should be fast
15484 because find_newline is fast (newline cache). */
15485 row
= w
->desired_matrix
->rows
+ WINDOW_WANTS_HEADER_LINE_P (w
);
15486 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15487 row
, DEFAULT_FACE_ID
);
15488 reseat_at_previous_visible_line_start (&it
);
15490 /* If the line start is "too far" away from the window start,
15491 say it takes too much time to compute a new window start. */
15492 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15493 /* PXW: Do we need upper bounds here? */
15494 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15496 int min_distance
, distance
;
15498 /* Move forward by display lines to find the new window
15499 start. If window width was enlarged, the new start can
15500 be expected to be > the old start. If window width was
15501 decreased, the new window start will be < the old start.
15502 So, we're looking for the display line start with the
15503 minimum distance from the old window start. */
15504 pos
= it
.current
.pos
;
15505 min_distance
= INFINITY
;
15506 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15507 distance
< min_distance
)
15509 min_distance
= distance
;
15510 pos
= it
.current
.pos
;
15511 if (it
.line_wrap
== WORD_WRAP
)
15513 /* Under WORD_WRAP, move_it_by_lines is likely to
15514 overshoot and stop not at the first, but the
15515 second character from the left margin. So in
15516 that case, we need a more tight control on the X
15517 coordinate of the iterator than move_it_by_lines
15518 promises in its contract. The method is to first
15519 go to the last (rightmost) visible character of a
15520 line, then move to the leftmost character on the
15521 next line in a separate call. */
15522 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15523 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15524 move_it_to (&it
, ZV
, 0,
15525 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15526 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15529 move_it_by_lines (&it
, 1);
15532 /* Set the window start there. */
15533 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15534 window_start_changed_p
= true;
15538 return window_start_changed_p
;
15542 /* Try cursor movement in case text has not changed in window WINDOW,
15543 with window start STARTP. Value is
15545 CURSOR_MOVEMENT_SUCCESS if successful
15547 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15549 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15550 display. *SCROLL_STEP is set to true, under certain circumstances, if
15551 we want to scroll as if scroll-step were set to 1. See the code.
15553 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15554 which case we have to abort this redisplay, and adjust matrices
15559 CURSOR_MOVEMENT_SUCCESS
,
15560 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15561 CURSOR_MOVEMENT_MUST_SCROLL
,
15562 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15566 try_cursor_movement (Lisp_Object window
, struct text_pos startp
,
15569 struct window
*w
= XWINDOW (window
);
15570 struct frame
*f
= XFRAME (w
->frame
);
15571 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15574 if (inhibit_try_cursor_movement
)
15578 /* Previously, there was a check for Lisp integer in the
15579 if-statement below. Now, this field is converted to
15580 ptrdiff_t, thus zero means invalid position in a buffer. */
15581 eassert (w
->last_point
> 0);
15582 /* Likewise there was a check whether window_end_vpos is nil or larger
15583 than the window. Now window_end_vpos is int and so never nil, but
15584 let's leave eassert to check whether it fits in the window. */
15585 eassert (!w
->window_end_valid
15586 || w
->window_end_vpos
< w
->current_matrix
->nrows
);
15588 /* Handle case where text has not changed, only point, and it has
15589 not moved off the frame. */
15590 if (/* Point may be in this window. */
15591 PT
>= CHARPOS (startp
)
15592 /* Selective display hasn't changed. */
15593 && !current_buffer
->clip_changed
15594 /* Function force-mode-line-update is used to force a thorough
15595 redisplay. It sets either windows_or_buffers_changed or
15596 update_mode_lines. So don't take a shortcut here for these
15598 && !update_mode_lines
15599 && !windows_or_buffers_changed
15600 && !f
->cursor_type_changed
15601 && NILP (Vshow_trailing_whitespace
)
15602 /* This code is not used for mini-buffer for the sake of the case
15603 of redisplaying to replace an echo area message; since in
15604 that case the mini-buffer contents per se are usually
15605 unchanged. This code is of no real use in the mini-buffer
15606 since the handling of this_line_start_pos, etc., in redisplay
15607 handles the same cases. */
15608 && !EQ (window
, minibuf_window
)
15609 && (FRAME_WINDOW_P (f
)
15610 || !overlay_arrow_in_current_buffer_p ()))
15612 int this_scroll_margin
, top_scroll_margin
;
15613 struct glyph_row
*row
= NULL
;
15614 int frame_line_height
= default_line_pixel_height (w
);
15615 int window_total_lines
15616 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15619 debug_method_add (w
, "cursor movement");
15622 /* Scroll if point within this distance from the top or bottom
15623 of the window. This is a pixel value. */
15624 if (scroll_margin
> 0)
15626 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15627 this_scroll_margin
*= frame_line_height
;
15630 this_scroll_margin
= 0;
15632 top_scroll_margin
= this_scroll_margin
;
15633 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15634 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15636 /* Start with the row the cursor was displayed during the last
15637 not paused redisplay. Give up if that row is not valid. */
15638 if (w
->last_cursor_vpos
< 0
15639 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15640 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15643 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15644 if (row
->mode_line_p
)
15646 if (!row
->enabled_p
)
15647 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15650 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15652 bool scroll_p
= false, must_scroll
= false;
15653 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15655 if (PT
> w
->last_point
)
15657 /* Point has moved forward. */
15658 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15659 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15661 eassert (row
->enabled_p
);
15665 /* If the end position of a row equals the start
15666 position of the next row, and PT is at that position,
15667 we would rather display cursor in the next line. */
15668 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15669 && MATRIX_ROW_END_CHARPOS (row
) == PT
15670 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15671 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15672 && !cursor_row_p (row
))
15675 /* If within the scroll margin, scroll. Note that
15676 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15677 the next line would be drawn, and that
15678 this_scroll_margin can be zero. */
15679 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15680 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15681 /* Line is completely visible last line in window
15682 and PT is to be set in the next line. */
15683 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15684 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15685 && !row
->ends_at_zv_p
15686 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15689 else if (PT
< w
->last_point
)
15691 /* Cursor has to be moved backward. Note that PT >=
15692 CHARPOS (startp) because of the outer if-statement. */
15693 while (!row
->mode_line_p
15694 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15695 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15696 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15697 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15698 row
> w
->current_matrix
->rows
15699 && (row
-1)->ends_in_newline_from_string_p
))))
15700 && (row
->y
> top_scroll_margin
15701 || CHARPOS (startp
) == BEGV
))
15703 eassert (row
->enabled_p
);
15707 /* Consider the following case: Window starts at BEGV,
15708 there is invisible, intangible text at BEGV, so that
15709 display starts at some point START > BEGV. It can
15710 happen that we are called with PT somewhere between
15711 BEGV and START. Try to handle that case. */
15712 if (row
< w
->current_matrix
->rows
15713 || row
->mode_line_p
)
15715 row
= w
->current_matrix
->rows
;
15716 if (row
->mode_line_p
)
15720 /* Due to newlines in overlay strings, we may have to
15721 skip forward over overlay strings. */
15722 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15723 && MATRIX_ROW_END_CHARPOS (row
) == PT
15724 && !cursor_row_p (row
))
15727 /* If within the scroll margin, scroll. */
15728 if (row
->y
< top_scroll_margin
15729 && CHARPOS (startp
) != BEGV
)
15734 /* Cursor did not move. So don't scroll even if cursor line
15735 is partially visible, as it was so before. */
15736 rc
= CURSOR_MOVEMENT_SUCCESS
;
15739 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15740 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15742 /* if PT is not in the glyph row, give up. */
15743 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15744 must_scroll
= true;
15746 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15747 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15749 struct glyph_row
*row1
;
15751 /* If rows are bidi-reordered and point moved, back up
15752 until we find a row that does not belong to a
15753 continuation line. This is because we must consider
15754 all rows of a continued line as candidates for the
15755 new cursor positioning, since row start and end
15756 positions change non-linearly with vertical position
15758 /* FIXME: Revisit this when glyph ``spilling'' in
15759 continuation lines' rows is implemented for
15760 bidi-reordered rows. */
15761 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15762 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15765 /* If we hit the beginning of the displayed portion
15766 without finding the first row of a continued
15770 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15773 eassert (row
->enabled_p
);
15778 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15779 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15780 /* Make sure this isn't a header line by any chance, since
15781 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield true. */
15782 && !row
->mode_line_p
15783 && make_cursor_line_fully_visible_p
)
15785 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15786 && !row
->ends_at_zv_p
15787 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15788 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15789 else if (row
->height
> window_box_height (w
))
15791 /* If we end up in a partially visible line, let's
15792 make it fully visible, except when it's taller
15793 than the window, in which case we can't do much
15795 *scroll_step
= true;
15796 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15800 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15801 if (!cursor_row_fully_visible_p (w
, false, true))
15802 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15804 rc
= CURSOR_MOVEMENT_SUCCESS
;
15808 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15809 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15810 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15812 /* With bidi-reordered rows, there could be more than
15813 one candidate row whose start and end positions
15814 occlude point. We need to let set_cursor_from_row
15815 find the best candidate. */
15816 /* FIXME: Revisit this when glyph ``spilling'' in
15817 continuation lines' rows is implemented for
15818 bidi-reordered rows. */
15823 bool at_zv_p
= false, exact_match_p
= false;
15825 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15826 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15827 && cursor_row_p (row
))
15828 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15830 /* As soon as we've found the exact match for point,
15831 or the first suitable row whose ends_at_zv_p flag
15832 is set, we are done. */
15835 at_zv_p
= MATRIX_ROW (w
->current_matrix
,
15836 w
->cursor
.vpos
)->ends_at_zv_p
;
15838 && w
->cursor
.hpos
>= 0
15839 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15842 struct glyph_row
*candidate
=
15843 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15845 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15846 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15849 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15850 || (NILP (g
->object
)
15851 && (g
->charpos
== PT
15852 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15854 if (at_zv_p
|| exact_match_p
)
15856 rc
= CURSOR_MOVEMENT_SUCCESS
;
15860 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15864 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15865 || row
->continued_p
)
15866 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15867 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15868 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15869 /* If we didn't find any candidate rows, or exited the
15870 loop before all the candidates were examined, signal
15871 to the caller that this method failed. */
15872 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15874 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15875 && !row
->continued_p
))
15876 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15878 rc
= CURSOR_MOVEMENT_SUCCESS
;
15884 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15886 rc
= CURSOR_MOVEMENT_SUCCESS
;
15891 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15892 && MATRIX_ROW_START_CHARPOS (row
) == PT
15893 && cursor_row_p (row
));
15903 set_vertical_scroll_bar (struct window
*w
)
15905 ptrdiff_t start
, end
, whole
;
15907 /* Calculate the start and end positions for the current window.
15908 At some point, it would be nice to choose between scrollbars
15909 which reflect the whole buffer size, with special markers
15910 indicating narrowing, and scrollbars which reflect only the
15913 Note that mini-buffers sometimes aren't displaying any text. */
15914 if (!MINI_WINDOW_P (w
)
15915 || (w
== XWINDOW (minibuf_window
)
15916 && NILP (echo_area_buffer
[0])))
15918 struct buffer
*buf
= XBUFFER (w
->contents
);
15919 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15920 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15921 /* I don't think this is guaranteed to be right. For the
15922 moment, we'll pretend it is. */
15923 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15927 if (whole
< (end
- start
))
15928 whole
= end
- start
;
15931 start
= end
= whole
= 0;
15933 /* Indicate what this scroll bar ought to be displaying now. */
15934 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15935 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15936 (w
, end
- start
, whole
, start
);
15941 set_horizontal_scroll_bar (struct window
*w
)
15943 int start
, end
, whole
, portion
;
15945 if (!MINI_WINDOW_P (w
)
15946 || (w
== XWINDOW (minibuf_window
)
15947 && NILP (echo_area_buffer
[0])))
15949 struct buffer
*b
= XBUFFER (w
->contents
);
15950 struct buffer
*old_buffer
= NULL
;
15952 struct text_pos startp
;
15954 if (b
!= current_buffer
)
15956 old_buffer
= current_buffer
;
15957 set_buffer_internal (b
);
15960 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15961 start_display (&it
, w
, startp
);
15962 it
.last_visible_x
= INT_MAX
;
15963 whole
= move_it_to (&it
, -1, INT_MAX
, window_box_height (w
), -1,
15964 MOVE_TO_X
| MOVE_TO_Y
);
15965 /* whole = move_it_to (&it, w->window_end_pos, INT_MAX,
15966 window_box_height (w), -1,
15967 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); */
15969 start
= w
->hscroll
* FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
15970 end
= start
+ window_box_width (w
, TEXT_AREA
);
15971 portion
= end
- start
;
15972 /* After enlarging a horizontally scrolled window such that it
15973 gets at least as wide as the text it contains, make sure that
15974 the thumb doesn't fill the entire scroll bar so we can still
15975 drag it back to see the entire text. */
15976 whole
= max (whole
, end
);
15982 pdir
= Fcurrent_bidi_paragraph_direction (Qnil
);
15983 if (EQ (pdir
, Qright_to_left
))
15985 start
= whole
- end
;
15986 end
= start
+ portion
;
15991 set_buffer_internal (old_buffer
);
15994 start
= end
= whole
= portion
= 0;
15996 w
->hscroll_whole
= whole
;
15998 /* Indicate what this scroll bar ought to be displaying now. */
15999 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
16000 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
16001 (w
, portion
, whole
, start
);
16005 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P means only
16006 selected_window is redisplayed.
16008 We can return without actually redisplaying the window if fonts has been
16009 changed on window's frame. In that case, redisplay_internal will retry.
16011 As one of the important parts of redisplaying a window, we need to
16012 decide whether the previous window-start position (stored in the
16013 window's w->start marker position) is still valid, and if it isn't,
16014 recompute it. Some details about that:
16016 . The previous window-start could be in a continuation line, in
16017 which case we need to recompute it when the window width
16018 changes. See compute_window_start_on_continuation_line and its
16021 . The text that changed since last redisplay could include the
16022 previous window-start position. In that case, we try to salvage
16023 what we can from the current glyph matrix by calling
16024 try_scrolling, which see.
16026 . Some Emacs command could force us to use a specific window-start
16027 position by setting the window's force_start flag, or gently
16028 propose doing that by setting the window's optional_new_start
16029 flag. In these cases, we try using the specified start point if
16030 that succeeds (i.e. the window desired matrix is successfully
16031 recomputed, and point location is within the window). In case
16032 of optional_new_start, we first check if the specified start
16033 position is feasible, i.e. if it will allow point to be
16034 displayed in the window. If using the specified start point
16035 fails, e.g., if new fonts are needed to be loaded, we abort the
16036 redisplay cycle and leave it up to the next cycle to figure out
16039 . Note that the window's force_start flag is sometimes set by
16040 redisplay itself, when it decides that the previous window start
16041 point is fine and should be kept. Search for "goto force_start"
16042 below to see the details. Like the values of window-start
16043 specified outside of redisplay, these internally-deduced values
16044 are tested for feasibility, and ignored if found to be
16047 . Note that the function try_window, used to completely redisplay
16048 a window, accepts the window's start point as its argument.
16049 This is used several times in the redisplay code to control
16050 where the window start will be, according to user options such
16051 as scroll-conservatively, and also to ensure the screen line
16052 showing point will be fully (as opposed to partially) visible on
16056 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
16058 struct window
*w
= XWINDOW (window
);
16059 struct frame
*f
= XFRAME (w
->frame
);
16060 struct buffer
*buffer
= XBUFFER (w
->contents
);
16061 struct buffer
*old
= current_buffer
;
16062 struct text_pos lpoint
, opoint
, startp
;
16063 bool update_mode_line
;
16066 /* Record it now because it's overwritten. */
16067 bool current_matrix_up_to_date_p
= false;
16068 bool used_current_matrix_p
= false;
16069 /* This is less strict than current_matrix_up_to_date_p.
16070 It indicates that the buffer contents and narrowing are unchanged. */
16071 bool buffer_unchanged_p
= false;
16072 bool temp_scroll_step
= false;
16073 ptrdiff_t count
= SPECPDL_INDEX ();
16075 int centering_position
= -1;
16076 bool last_line_misfit
= false;
16077 ptrdiff_t beg_unchanged
, end_unchanged
;
16078 int frame_line_height
;
16080 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16084 *w
->desired_matrix
->method
= 0;
16087 if (!just_this_one_p
16088 && REDISPLAY_SOME_P ()
16090 && !w
->update_mode_line
16093 && !buffer
->text
->redisplay
16094 && BUF_PT (buffer
) == w
->last_point
)
16097 /* Make sure that both W's markers are valid. */
16098 eassert (XMARKER (w
->start
)->buffer
== buffer
);
16099 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
16101 /* We come here again if we need to run window-text-change-functions
16104 reconsider_clip_changes (w
);
16105 frame_line_height
= default_line_pixel_height (w
);
16107 /* Has the mode line to be updated? */
16108 update_mode_line
= (w
->update_mode_line
16109 || update_mode_lines
16110 || buffer
->clip_changed
16111 || buffer
->prevent_redisplay_optimizations_p
);
16113 if (!just_this_one_p
)
16114 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
16115 cleverly elsewhere. */
16116 w
->must_be_updated_p
= true;
16118 if (MINI_WINDOW_P (w
))
16120 if (w
== XWINDOW (echo_area_window
)
16121 && !NILP (echo_area_buffer
[0]))
16123 if (update_mode_line
)
16124 /* We may have to update a tty frame's menu bar or a
16125 tool-bar. Example `M-x C-h C-h C-g'. */
16126 goto finish_menu_bars
;
16128 /* We've already displayed the echo area glyphs in this window. */
16129 goto finish_scroll_bars
;
16131 else if ((w
!= XWINDOW (minibuf_window
)
16132 || minibuf_level
== 0)
16133 /* When buffer is nonempty, redisplay window normally. */
16134 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
16135 /* Quail displays non-mini buffers in minibuffer window.
16136 In that case, redisplay the window normally. */
16137 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
16139 /* W is a mini-buffer window, but it's not active, so clear
16141 int yb
= window_text_bottom_y (w
);
16142 struct glyph_row
*row
;
16145 for (y
= 0, row
= w
->desired_matrix
->rows
;
16147 y
+= row
->height
, ++row
)
16148 blank_row (w
, row
, y
);
16149 goto finish_scroll_bars
;
16152 clear_glyph_matrix (w
->desired_matrix
);
16155 /* Otherwise set up data on this window; select its buffer and point
16157 /* Really select the buffer, for the sake of buffer-local
16159 set_buffer_internal_1 (XBUFFER (w
->contents
));
16161 current_matrix_up_to_date_p
16162 = (w
->window_end_valid
16163 && !current_buffer
->clip_changed
16164 && !current_buffer
->prevent_redisplay_optimizations_p
16165 && !window_outdated (w
));
16167 /* Run the window-text-change-functions
16168 if it is possible that the text on the screen has changed
16169 (either due to modification of the text, or any other reason). */
16170 if (!current_matrix_up_to_date_p
16171 && !NILP (Vwindow_text_change_functions
))
16173 safe_run_hooks (Qwindow_text_change_functions
);
16177 beg_unchanged
= BEG_UNCHANGED
;
16178 end_unchanged
= END_UNCHANGED
;
16180 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
16182 specbind (Qinhibit_point_motion_hooks
, Qt
);
16185 = (w
->window_end_valid
16186 && !current_buffer
->clip_changed
16187 && !window_outdated (w
));
16189 /* When windows_or_buffers_changed is non-zero, we can't rely
16190 on the window end being valid, so set it to zero there. */
16191 if (windows_or_buffers_changed
)
16193 /* If window starts on a continuation line, maybe adjust the
16194 window start in case the window's width changed. */
16195 if (XMARKER (w
->start
)->buffer
== current_buffer
)
16196 compute_window_start_on_continuation_line (w
);
16198 w
->window_end_valid
= false;
16199 /* If so, we also can't rely on current matrix
16200 and should not fool try_cursor_movement below. */
16201 current_matrix_up_to_date_p
= false;
16204 /* Some sanity checks. */
16205 CHECK_WINDOW_END (w
);
16206 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
16208 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
16211 if (mode_line_update_needed (w
))
16212 update_mode_line
= true;
16214 /* Point refers normally to the selected window. For any other
16215 window, set up appropriate value. */
16216 if (!EQ (window
, selected_window
))
16218 ptrdiff_t new_pt
= marker_position (w
->pointm
);
16219 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
16224 new_pt_byte
= BEGV_BYTE
;
16225 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
16227 else if (new_pt
> (ZV
- 1))
16230 new_pt_byte
= ZV_BYTE
;
16231 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
16234 /* We don't use SET_PT so that the point-motion hooks don't run. */
16235 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
16238 /* If any of the character widths specified in the display table
16239 have changed, invalidate the width run cache. It's true that
16240 this may be a bit late to catch such changes, but the rest of
16241 redisplay goes (non-fatally) haywire when the display table is
16242 changed, so why should we worry about doing any better? */
16243 if (current_buffer
->width_run_cache
16244 || (current_buffer
->base_buffer
16245 && current_buffer
->base_buffer
->width_run_cache
))
16247 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
16249 if (! disptab_matches_widthtab
16250 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
16252 struct buffer
*buf
= current_buffer
;
16254 if (buf
->base_buffer
)
16255 buf
= buf
->base_buffer
;
16256 invalidate_region_cache (buf
, buf
->width_run_cache
, BEG
, Z
);
16257 recompute_width_table (current_buffer
, disptab
);
16261 /* If window-start is screwed up, choose a new one. */
16262 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
16265 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16267 /* If someone specified a new starting point but did not insist,
16268 check whether it can be used. */
16269 if ((w
->optional_new_start
|| window_frozen_p (w
))
16270 && CHARPOS (startp
) >= BEGV
16271 && CHARPOS (startp
) <= ZV
)
16273 ptrdiff_t it_charpos
;
16275 w
->optional_new_start
= false;
16276 start_display (&it
, w
, startp
);
16277 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
16278 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
16279 /* Record IT's position now, since line_bottom_y might change
16281 it_charpos
= IT_CHARPOS (it
);
16282 /* Make sure we set the force_start flag only if the cursor row
16283 will be fully visible. Otherwise, the code under force_start
16284 label below will try to move point back into view, which is
16285 not what the code which sets optional_new_start wants. */
16286 if ((it
.current_y
== 0 || line_bottom_y (&it
) < it
.last_visible_y
)
16287 && !w
->force_start
)
16289 if (it_charpos
== PT
)
16290 w
->force_start
= true;
16291 /* IT may overshoot PT if text at PT is invisible. */
16292 else if (it_charpos
> PT
&& CHARPOS (startp
) <= PT
)
16293 w
->force_start
= true;
16295 if (w
->force_start
)
16297 if (window_frozen_p (w
))
16298 debug_method_add (w
, "set force_start from frozen window start");
16300 debug_method_add (w
, "set force_start from optional_new_start");
16308 /* Handle case where place to start displaying has been specified,
16309 unless the specified location is outside the accessible range. */
16310 if (w
->force_start
)
16312 /* We set this later on if we have to adjust point. */
16315 w
->force_start
= false;
16317 w
->window_end_valid
= false;
16319 /* Forget any recorded base line for line number display. */
16320 if (!buffer_unchanged_p
)
16321 w
->base_line_number
= 0;
16323 /* Redisplay the mode line. Select the buffer properly for that.
16324 Also, run the hook window-scroll-functions
16325 because we have scrolled. */
16326 /* Note, we do this after clearing force_start because
16327 if there's an error, it is better to forget about force_start
16328 than to get into an infinite loop calling the hook functions
16329 and having them get more errors. */
16330 if (!update_mode_line
16331 || ! NILP (Vwindow_scroll_functions
))
16333 update_mode_line
= true;
16334 w
->update_mode_line
= true;
16335 startp
= run_window_scroll_functions (window
, startp
);
16338 if (CHARPOS (startp
) < BEGV
)
16339 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
16340 else if (CHARPOS (startp
) > ZV
)
16341 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
16343 /* Redisplay, then check if cursor has been set during the
16344 redisplay. Give up if new fonts were loaded. */
16345 /* We used to issue a CHECK_MARGINS argument to try_window here,
16346 but this causes scrolling to fail when point begins inside
16347 the scroll margin (bug#148) -- cyd */
16348 if (!try_window (window
, startp
, 0))
16350 w
->force_start
= true;
16351 clear_glyph_matrix (w
->desired_matrix
);
16352 goto need_larger_matrices
;
16355 if (w
->cursor
.vpos
< 0)
16357 /* If point does not appear, try to move point so it does
16358 appear. The desired matrix has been built above, so we
16359 can use it here. First see if point is in invisible
16360 text, and if so, move it to the first visible buffer
16361 position past that. */
16362 struct glyph_row
*r
= NULL
;
16363 Lisp_Object invprop
=
16364 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16367 if (TEXT_PROP_MEANS_INVISIBLE (invprop
) != 0)
16370 Lisp_Object invprop_end
=
16371 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16374 if (NATNUMP (invprop_end
))
16375 alt_pt
= XFASTINT (invprop_end
);
16378 r
= row_containing_pos (w
, alt_pt
, w
->desired_matrix
->rows
,
16382 new_vpos
= MATRIX_ROW_BOTTOM_Y (r
);
16383 else /* Give up and just move to the middle of the window. */
16384 new_vpos
= window_box_height (w
) / 2;
16387 if (!cursor_row_fully_visible_p (w
, false, false))
16389 /* Point does appear, but on a line partly visible at end of window.
16390 Move it back to a fully-visible line. */
16391 new_vpos
= window_box_height (w
);
16392 /* But if window_box_height suggests a Y coordinate that is
16393 not less than we already have, that line will clearly not
16394 be fully visible, so give up and scroll the display.
16395 This can happen when the default face uses a font whose
16396 dimensions are different from the frame's default
16398 if (new_vpos
>= w
->cursor
.y
)
16400 w
->cursor
.vpos
= -1;
16401 clear_glyph_matrix (w
->desired_matrix
);
16402 goto try_to_scroll
;
16405 else if (w
->cursor
.vpos
>= 0)
16407 /* Some people insist on not letting point enter the scroll
16408 margin, even though this part handles windows that didn't
16410 int window_total_lines
16411 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16412 int margin
= min (scroll_margin
, window_total_lines
/ 4);
16413 int pixel_margin
= margin
* frame_line_height
;
16414 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
16416 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
16417 below, which finds the row to move point to, advances by
16418 the Y coordinate of the _next_ row, see the definition of
16419 MATRIX_ROW_BOTTOM_Y. */
16420 if (w
->cursor
.vpos
< margin
+ header_line
)
16422 w
->cursor
.vpos
= -1;
16423 clear_glyph_matrix (w
->desired_matrix
);
16424 goto try_to_scroll
;
16428 int window_height
= window_box_height (w
);
16431 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
16432 if (w
->cursor
.y
>= window_height
- pixel_margin
)
16434 w
->cursor
.vpos
= -1;
16435 clear_glyph_matrix (w
->desired_matrix
);
16436 goto try_to_scroll
;
16441 /* If we need to move point for either of the above reasons,
16442 now actually do it. */
16445 struct glyph_row
*row
;
16447 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
16448 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
16451 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
16452 MATRIX_ROW_START_BYTEPOS (row
));
16454 if (w
!= XWINDOW (selected_window
))
16455 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
16456 else if (current_buffer
== old
)
16457 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16459 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
16461 /* Re-run pre-redisplay-function so it can update the region
16462 according to the new position of point. */
16463 /* Other than the cursor, w's redisplay is done so we can set its
16464 redisplay to false. Also the buffer's redisplay can be set to
16465 false, since propagate_buffer_redisplay should have already
16466 propagated its info to `w' anyway. */
16467 w
->redisplay
= false;
16468 XBUFFER (w
->contents
)->text
->redisplay
= false;
16469 safe__call1 (true, Vpre_redisplay_function
, Fcons (window
, Qnil
));
16471 if (w
->redisplay
|| XBUFFER (w
->contents
)->text
->redisplay
)
16473 /* pre-redisplay-function made changes (e.g. move the region)
16474 that require another round of redisplay. */
16475 clear_glyph_matrix (w
->desired_matrix
);
16476 if (!try_window (window
, startp
, 0))
16477 goto need_larger_matrices
;
16480 if (w
->cursor
.vpos
< 0 || !cursor_row_fully_visible_p (w
, false, false))
16482 clear_glyph_matrix (w
->desired_matrix
);
16483 goto try_to_scroll
;
16487 debug_method_add (w
, "forced window start");
16492 /* Handle case where text has not changed, only point, and it has
16493 not moved off the frame, and we are not retrying after hscroll.
16494 (current_matrix_up_to_date_p is true when retrying.) */
16495 if (current_matrix_up_to_date_p
16496 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
16497 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
16501 case CURSOR_MOVEMENT_SUCCESS
:
16502 used_current_matrix_p
= true;
16505 case CURSOR_MOVEMENT_MUST_SCROLL
:
16506 goto try_to_scroll
;
16512 /* If current starting point was originally the beginning of a line
16513 but no longer is, find a new starting point. */
16514 else if (w
->start_at_line_beg
16515 && !(CHARPOS (startp
) <= BEGV
16516 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
16519 debug_method_add (w
, "recenter 1");
16524 /* Try scrolling with try_window_id. Value is > 0 if update has
16525 been done, it is -1 if we know that the same window start will
16526 not work. It is 0 if unsuccessful for some other reason. */
16527 else if ((tem
= try_window_id (w
)) != 0)
16530 debug_method_add (w
, "try_window_id %d", tem
);
16533 if (f
->fonts_changed
)
16534 goto need_larger_matrices
;
16538 /* Otherwise try_window_id has returned -1 which means that we
16539 don't want the alternative below this comment to execute. */
16541 else if (CHARPOS (startp
) >= BEGV
16542 && CHARPOS (startp
) <= ZV
16543 && PT
>= CHARPOS (startp
)
16544 && (CHARPOS (startp
) < ZV
16545 /* Avoid starting at end of buffer. */
16546 || CHARPOS (startp
) == BEGV
16547 || !window_outdated (w
)))
16549 int d1
, d2
, d5
, d6
;
16552 /* If first window line is a continuation line, and window start
16553 is inside the modified region, but the first change is before
16554 current window start, we must select a new window start.
16556 However, if this is the result of a down-mouse event (e.g. by
16557 extending the mouse-drag-overlay), we don't want to select a
16558 new window start, since that would change the position under
16559 the mouse, resulting in an unwanted mouse-movement rather
16560 than a simple mouse-click. */
16561 if (!w
->start_at_line_beg
16562 && NILP (do_mouse_tracking
)
16563 && CHARPOS (startp
) > BEGV
16564 && CHARPOS (startp
) > BEG
+ beg_unchanged
16565 && CHARPOS (startp
) <= Z
- end_unchanged
16566 /* Even if w->start_at_line_beg is nil, a new window may
16567 start at a line_beg, since that's how set_buffer_window
16568 sets it. So, we need to check the return value of
16569 compute_window_start_on_continuation_line. (See also
16571 && XMARKER (w
->start
)->buffer
== current_buffer
16572 && compute_window_start_on_continuation_line (w
)
16573 /* It doesn't make sense to force the window start like we
16574 do at label force_start if it is already known that point
16575 will not be fully visible in the resulting window, because
16576 doing so will move point from its correct position
16577 instead of scrolling the window to bring point into view.
16579 && pos_visible_p (w
, PT
, &d1
, &d2
, &rtop
, &rbot
, &d5
, &d6
)
16580 /* A very tall row could need more than the window height,
16581 in which case we accept that it is partially visible. */
16582 && (rtop
!= 0) == (rbot
!= 0))
16584 w
->force_start
= true;
16585 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16587 debug_method_add (w
, "recomputed window start in continuation line");
16593 debug_method_add (w
, "same window start");
16596 /* Try to redisplay starting at same place as before.
16597 If point has not moved off frame, accept the results. */
16598 if (!current_matrix_up_to_date_p
16599 /* Don't use try_window_reusing_current_matrix in this case
16600 because a window scroll function can have changed the
16602 || !NILP (Vwindow_scroll_functions
)
16603 || MINI_WINDOW_P (w
)
16604 || !(used_current_matrix_p
16605 = try_window_reusing_current_matrix (w
)))
16607 IF_DEBUG (debug_method_add (w
, "1"));
16608 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16609 /* -1 means we need to scroll.
16610 0 means we need new matrices, but fonts_changed
16611 is set in that case, so we will detect it below. */
16612 goto try_to_scroll
;
16615 if (f
->fonts_changed
)
16616 goto need_larger_matrices
;
16618 if (w
->cursor
.vpos
>= 0)
16620 if (!just_this_one_p
16621 || current_buffer
->clip_changed
16622 || BEG_UNCHANGED
< CHARPOS (startp
))
16623 /* Forget any recorded base line for line number display. */
16624 w
->base_line_number
= 0;
16626 if (!cursor_row_fully_visible_p (w
, true, false))
16628 clear_glyph_matrix (w
->desired_matrix
);
16629 last_line_misfit
= true;
16631 /* Drop through and scroll. */
16636 clear_glyph_matrix (w
->desired_matrix
);
16641 /* Redisplay the mode line. Select the buffer properly for that. */
16642 if (!update_mode_line
)
16644 update_mode_line
= true;
16645 w
->update_mode_line
= true;
16648 /* Try to scroll by specified few lines. */
16649 if ((scroll_conservatively
16650 || emacs_scroll_step
16651 || temp_scroll_step
16652 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16653 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16654 && CHARPOS (startp
) >= BEGV
16655 && CHARPOS (startp
) <= ZV
)
16657 /* The function returns -1 if new fonts were loaded, 1 if
16658 successful, 0 if not successful. */
16659 int ss
= try_scrolling (window
, just_this_one_p
,
16660 scroll_conservatively
,
16662 temp_scroll_step
, last_line_misfit
);
16665 case SCROLLING_SUCCESS
:
16668 case SCROLLING_NEED_LARGER_MATRICES
:
16669 goto need_larger_matrices
;
16671 case SCROLLING_FAILED
:
16679 /* Finally, just choose a place to start which positions point
16680 according to user preferences. */
16685 debug_method_add (w
, "recenter");
16688 /* Forget any previously recorded base line for line number display. */
16689 if (!buffer_unchanged_p
)
16690 w
->base_line_number
= 0;
16692 /* Determine the window start relative to point. */
16693 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16694 it
.current_y
= it
.last_visible_y
;
16695 if (centering_position
< 0)
16697 int window_total_lines
16698 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16700 = scroll_margin
> 0
16701 ? min (scroll_margin
, window_total_lines
/ 4)
16703 ptrdiff_t margin_pos
= CHARPOS (startp
);
16704 Lisp_Object aggressive
;
16707 /* If there is a scroll margin at the top of the window, find
16708 its character position. */
16710 /* Cannot call start_display if startp is not in the
16711 accessible region of the buffer. This can happen when we
16712 have just switched to a different buffer and/or changed
16713 its restriction. In that case, startp is initialized to
16714 the character position 1 (BEGV) because we did not yet
16715 have chance to display the buffer even once. */
16716 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16719 void *it1data
= NULL
;
16721 SAVE_IT (it1
, it
, it1data
);
16722 start_display (&it1
, w
, startp
);
16723 move_it_vertically (&it1
, margin
* frame_line_height
);
16724 margin_pos
= IT_CHARPOS (it1
);
16725 RESTORE_IT (&it
, &it
, it1data
);
16727 scrolling_up
= PT
> margin_pos
;
16730 ? BVAR (current_buffer
, scroll_up_aggressively
)
16731 : BVAR (current_buffer
, scroll_down_aggressively
);
16733 if (!MINI_WINDOW_P (w
)
16734 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16738 /* Setting scroll-conservatively overrides
16739 scroll-*-aggressively. */
16740 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16742 double float_amount
= XFLOATINT (aggressive
);
16744 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16745 if (pt_offset
== 0 && float_amount
> 0)
16747 if (pt_offset
&& margin
> 0)
16750 /* Compute how much to move the window start backward from
16751 point so that point will be displayed where the user
16755 centering_position
= it
.last_visible_y
;
16757 centering_position
-= pt_offset
;
16758 centering_position
-=
16759 (frame_line_height
* (1 + margin
+ last_line_misfit
)
16760 + WINDOW_HEADER_LINE_HEIGHT (w
));
16761 /* Don't let point enter the scroll margin near top of
16763 if (centering_position
< margin
* frame_line_height
)
16764 centering_position
= margin
* frame_line_height
;
16767 centering_position
= margin
* frame_line_height
+ pt_offset
;
16770 /* Set the window start half the height of the window backward
16772 centering_position
= window_box_height (w
) / 2;
16774 move_it_vertically_backward (&it
, centering_position
);
16776 eassert (IT_CHARPOS (it
) >= BEGV
);
16778 /* The function move_it_vertically_backward may move over more
16779 than the specified y-distance. If it->w is small, e.g. a
16780 mini-buffer window, we may end up in front of the window's
16781 display area. Start displaying at the start of the line
16782 containing PT in this case. */
16783 if (it
.current_y
<= 0)
16785 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16786 move_it_vertically_backward (&it
, 0);
16790 it
.current_x
= it
.hpos
= 0;
16792 /* Set the window start position here explicitly, to avoid an
16793 infinite loop in case the functions in window-scroll-functions
16795 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16797 /* Run scroll hooks. */
16798 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16800 /* Redisplay the window. */
16801 bool use_desired_matrix
= false;
16802 if (!current_matrix_up_to_date_p
16803 || windows_or_buffers_changed
16804 || f
->cursor_type_changed
16805 /* Don't use try_window_reusing_current_matrix in this case
16806 because it can have changed the buffer. */
16807 || !NILP (Vwindow_scroll_functions
)
16808 || !just_this_one_p
16809 || MINI_WINDOW_P (w
)
16810 || !(used_current_matrix_p
16811 = try_window_reusing_current_matrix (w
)))
16812 use_desired_matrix
= (try_window (window
, startp
, 0) == 1);
16814 /* If new fonts have been loaded (due to fontsets), give up. We
16815 have to start a new redisplay since we need to re-adjust glyph
16817 if (f
->fonts_changed
)
16818 goto need_larger_matrices
;
16820 /* If cursor did not appear assume that the middle of the window is
16821 in the first line of the window. Do it again with the next line.
16822 (Imagine a window of height 100, displaying two lines of height
16823 60. Moving back 50 from it->last_visible_y will end in the first
16825 if (w
->cursor
.vpos
< 0)
16827 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16829 clear_glyph_matrix (w
->desired_matrix
);
16830 move_it_by_lines (&it
, 1);
16831 try_window (window
, it
.current
.pos
, 0);
16833 else if (PT
< IT_CHARPOS (it
))
16835 clear_glyph_matrix (w
->desired_matrix
);
16836 move_it_by_lines (&it
, -1);
16837 try_window (window
, it
.current
.pos
, 0);
16841 /* Not much we can do about it. */
16845 /* Consider the following case: Window starts at BEGV, there is
16846 invisible, intangible text at BEGV, so that display starts at
16847 some point START > BEGV. It can happen that we are called with
16848 PT somewhere between BEGV and START. Try to handle that case,
16849 and similar ones. */
16850 if (w
->cursor
.vpos
< 0)
16852 /* Prefer the desired matrix to the current matrix, if possible,
16853 in the fallback calculations below. This is because using
16854 the current matrix might completely goof, e.g. if its first
16855 row is after point. */
16856 struct glyph_matrix
*matrix
=
16857 use_desired_matrix
? w
->desired_matrix
: w
->current_matrix
;
16858 /* First, try locating the proper glyph row for PT. */
16859 struct glyph_row
*row
=
16860 row_containing_pos (w
, PT
, matrix
->rows
, NULL
, 0);
16862 /* Sometimes point is at the beginning of invisible text that is
16863 before the 1st character displayed in the row. In that case,
16864 row_containing_pos fails to find the row, because no glyphs
16865 with appropriate buffer positions are present in the row.
16866 Therefore, we next try to find the row which shows the 1st
16867 position after the invisible text. */
16871 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16874 if (TEXT_PROP_MEANS_INVISIBLE (val
) != 0)
16877 Lisp_Object invis_end
=
16878 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16881 if (NATNUMP (invis_end
))
16882 alt_pos
= XFASTINT (invis_end
);
16885 row
= row_containing_pos (w
, alt_pos
, matrix
->rows
, NULL
, 0);
16888 /* Finally, fall back on the first row of the window after the
16889 header line (if any). This is slightly better than not
16890 displaying the cursor at all. */
16893 row
= matrix
->rows
;
16894 if (row
->mode_line_p
)
16897 set_cursor_from_row (w
, row
, matrix
, 0, 0, 0, 0);
16900 if (!cursor_row_fully_visible_p (w
, false, false))
16902 /* If vscroll is enabled, disable it and try again. */
16906 clear_glyph_matrix (w
->desired_matrix
);
16910 /* Users who set scroll-conservatively to a large number want
16911 point just above/below the scroll margin. If we ended up
16912 with point's row partially visible, move the window start to
16913 make that row fully visible and out of the margin. */
16914 if (scroll_conservatively
> SCROLL_LIMIT
)
16916 int window_total_lines
16917 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16920 ? min (scroll_margin
, window_total_lines
/ 4)
16922 bool move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16924 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16925 clear_glyph_matrix (w
->desired_matrix
);
16926 if (1 == try_window (window
, it
.current
.pos
,
16927 TRY_WINDOW_CHECK_MARGINS
))
16931 /* If centering point failed to make the whole line visible,
16932 put point at the top instead. That has to make the whole line
16933 visible, if it can be done. */
16934 if (centering_position
== 0)
16937 clear_glyph_matrix (w
->desired_matrix
);
16938 centering_position
= 0;
16944 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16945 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16946 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16948 /* Display the mode line, if we must. */
16949 if ((update_mode_line
16950 /* If window not full width, must redo its mode line
16951 if (a) the window to its side is being redone and
16952 (b) we do a frame-based redisplay. This is a consequence
16953 of how inverted lines are drawn in frame-based redisplay. */
16954 || (!just_this_one_p
16955 && !FRAME_WINDOW_P (f
)
16956 && !WINDOW_FULL_WIDTH_P (w
))
16957 /* Line number to display. */
16958 || w
->base_line_pos
> 0
16959 /* Column number is displayed and different from the one displayed. */
16960 || (w
->column_number_displayed
!= -1
16961 && (w
->column_number_displayed
!= current_column ())))
16962 /* This means that the window has a mode line. */
16963 && (WINDOW_WANTS_MODELINE_P (w
)
16964 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16967 display_mode_lines (w
);
16969 /* If mode line height has changed, arrange for a thorough
16970 immediate redisplay using the correct mode line height. */
16971 if (WINDOW_WANTS_MODELINE_P (w
)
16972 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16974 f
->fonts_changed
= true;
16975 w
->mode_line_height
= -1;
16976 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16977 = DESIRED_MODE_LINE_HEIGHT (w
);
16980 /* If header line height has changed, arrange for a thorough
16981 immediate redisplay using the correct header line height. */
16982 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16983 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16985 f
->fonts_changed
= true;
16986 w
->header_line_height
= -1;
16987 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16988 = DESIRED_HEADER_LINE_HEIGHT (w
);
16991 if (f
->fonts_changed
)
16992 goto need_larger_matrices
;
16995 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16997 w
->base_line_pos
= 0;
16998 w
->base_line_number
= 0;
17003 /* When we reach a frame's selected window, redo the frame's menu
17004 bar and the frame's title. */
17005 if (update_mode_line
17006 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
17008 bool redisplay_menu_p
;
17010 if (FRAME_WINDOW_P (f
))
17012 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
17013 || defined (HAVE_NS) || defined (USE_GTK)
17014 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
17016 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
17020 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
17022 if (redisplay_menu_p
)
17023 display_menu_bar (w
);
17025 #ifdef HAVE_WINDOW_SYSTEM
17026 if (FRAME_WINDOW_P (f
))
17028 #if defined (USE_GTK) || defined (HAVE_NS)
17029 if (FRAME_EXTERNAL_TOOL_BAR (f
))
17030 redisplay_tool_bar (f
);
17032 if (WINDOWP (f
->tool_bar_window
)
17033 && (FRAME_TOOL_BAR_LINES (f
) > 0
17034 || !NILP (Vauto_resize_tool_bars
))
17035 && redisplay_tool_bar (f
))
17036 ignore_mouse_drag_p
= true;
17039 x_consider_frame_title (w
->frame
);
17043 #ifdef HAVE_WINDOW_SYSTEM
17044 if (FRAME_WINDOW_P (f
)
17045 && update_window_fringes (w
, (just_this_one_p
17046 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
17047 || w
->pseudo_window_p
)))
17051 if (draw_window_fringes (w
, true))
17053 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
17054 x_draw_right_divider (w
);
17056 x_draw_vertical_border (w
);
17062 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
17063 x_draw_bottom_divider (w
);
17064 #endif /* HAVE_WINDOW_SYSTEM */
17066 /* We go to this label, with fonts_changed set, if it is
17067 necessary to try again using larger glyph matrices.
17068 We have to redeem the scroll bar even in this case,
17069 because the loop in redisplay_internal expects that. */
17070 need_larger_matrices
:
17072 finish_scroll_bars
:
17074 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
) || WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
17076 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
17077 /* Set the thumb's position and size. */
17078 set_vertical_scroll_bar (w
);
17080 if (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
17081 /* Set the thumb's position and size. */
17082 set_horizontal_scroll_bar (w
);
17084 /* Note that we actually used the scroll bar attached to this
17085 window, so it shouldn't be deleted at the end of redisplay. */
17086 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
17087 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
17090 /* Restore current_buffer and value of point in it. The window
17091 update may have changed the buffer, so first make sure `opoint'
17092 is still valid (Bug#6177). */
17093 if (CHARPOS (opoint
) < BEGV
)
17094 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
17095 else if (CHARPOS (opoint
) > ZV
)
17096 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
17098 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
17100 set_buffer_internal_1 (old
);
17101 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
17102 shorter. This can be caused by log truncation in *Messages*. */
17103 if (CHARPOS (lpoint
) <= ZV
)
17104 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
17106 unbind_to (count
, Qnil
);
17110 /* Build the complete desired matrix of WINDOW with a window start
17111 buffer position POS.
17113 Value is 1 if successful. It is zero if fonts were loaded during
17114 redisplay which makes re-adjusting glyph matrices necessary, and -1
17115 if point would appear in the scroll margins.
17116 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
17117 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
17121 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
17123 struct window
*w
= XWINDOW (window
);
17125 struct glyph_row
*last_text_row
= NULL
;
17126 struct frame
*f
= XFRAME (w
->frame
);
17127 int frame_line_height
= default_line_pixel_height (w
);
17129 /* Make POS the new window start. */
17130 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
17132 /* Mark cursor position as unknown. No overlay arrow seen. */
17133 w
->cursor
.vpos
= -1;
17134 overlay_arrow_seen
= false;
17136 /* Initialize iterator and info to start at POS. */
17137 start_display (&it
, w
, pos
);
17138 it
.glyph_row
->reversed_p
= false;
17140 /* Display all lines of W. */
17141 while (it
.current_y
< it
.last_visible_y
)
17143 if (display_line (&it
))
17144 last_text_row
= it
.glyph_row
- 1;
17145 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
17149 /* Don't let the cursor end in the scroll margins. */
17150 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
17151 && !MINI_WINDOW_P (w
))
17153 int this_scroll_margin
;
17154 int window_total_lines
17155 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
17157 if (scroll_margin
> 0)
17159 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
17160 this_scroll_margin
*= frame_line_height
;
17163 this_scroll_margin
= 0;
17165 if ((w
->cursor
.y
>= 0 /* not vscrolled */
17166 && w
->cursor
.y
< this_scroll_margin
17167 && CHARPOS (pos
) > BEGV
17168 && IT_CHARPOS (it
) < ZV
)
17169 /* rms: considering make_cursor_line_fully_visible_p here
17170 seems to give wrong results. We don't want to recenter
17171 when the last line is partly visible, we want to allow
17172 that case to be handled in the usual way. */
17173 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
17175 w
->cursor
.vpos
= -1;
17176 clear_glyph_matrix (w
->desired_matrix
);
17181 /* If bottom moved off end of frame, change mode line percentage. */
17182 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
17183 w
->update_mode_line
= true;
17185 /* Set window_end_pos to the offset of the last character displayed
17186 on the window from the end of current_buffer. Set
17187 window_end_vpos to its row number. */
17190 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
17191 adjust_window_ends (w
, last_text_row
, false);
17193 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
17194 w
->window_end_vpos
)));
17198 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17199 w
->window_end_pos
= Z
- ZV
;
17200 w
->window_end_vpos
= 0;
17203 /* But that is not valid info until redisplay finishes. */
17204 w
->window_end_valid
= false;
17210 /************************************************************************
17211 Window redisplay reusing current matrix when buffer has not changed
17212 ************************************************************************/
17214 /* Try redisplay of window W showing an unchanged buffer with a
17215 different window start than the last time it was displayed by
17216 reusing its current matrix. Value is true if successful.
17217 W->start is the new window start. */
17220 try_window_reusing_current_matrix (struct window
*w
)
17222 struct frame
*f
= XFRAME (w
->frame
);
17223 struct glyph_row
*bottom_row
;
17226 struct text_pos start
, new_start
;
17227 int nrows_scrolled
, i
;
17228 struct glyph_row
*last_text_row
;
17229 struct glyph_row
*last_reused_text_row
;
17230 struct glyph_row
*start_row
;
17231 int start_vpos
, min_y
, max_y
;
17234 if (inhibit_try_window_reusing
)
17238 if (/* This function doesn't handle terminal frames. */
17239 !FRAME_WINDOW_P (f
)
17240 /* Don't try to reuse the display if windows have been split
17242 || windows_or_buffers_changed
17243 || f
->cursor_type_changed
)
17246 /* Can't do this if showing trailing whitespace. */
17247 if (!NILP (Vshow_trailing_whitespace
))
17250 /* If top-line visibility has changed, give up. */
17251 if (WINDOW_WANTS_HEADER_LINE_P (w
)
17252 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
17255 /* Give up if old or new display is scrolled vertically. We could
17256 make this function handle this, but right now it doesn't. */
17257 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17258 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
17261 /* The variable new_start now holds the new window start. The old
17262 start `start' can be determined from the current matrix. */
17263 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
17264 start
= start_row
->minpos
;
17265 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17267 /* Clear the desired matrix for the display below. */
17268 clear_glyph_matrix (w
->desired_matrix
);
17270 if (CHARPOS (new_start
) <= CHARPOS (start
))
17272 /* Don't use this method if the display starts with an ellipsis
17273 displayed for invisible text. It's not easy to handle that case
17274 below, and it's certainly not worth the effort since this is
17275 not a frequent case. */
17276 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
17279 IF_DEBUG (debug_method_add (w
, "twu1"));
17281 /* Display up to a row that can be reused. The variable
17282 last_text_row is set to the last row displayed that displays
17283 text. Note that it.vpos == 0 if or if not there is a
17284 header-line; it's not the same as the MATRIX_ROW_VPOS! */
17285 start_display (&it
, w
, new_start
);
17286 w
->cursor
.vpos
= -1;
17287 last_text_row
= last_reused_text_row
= NULL
;
17289 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17291 /* If we have reached into the characters in the START row,
17292 that means the line boundaries have changed. So we
17293 can't start copying with the row START. Maybe it will
17294 work to start copying with the following row. */
17295 while (IT_CHARPOS (it
) > CHARPOS (start
))
17297 /* Advance to the next row as the "start". */
17299 start
= start_row
->minpos
;
17300 /* If there are no more rows to try, or just one, give up. */
17301 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
17302 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
17303 || CHARPOS (start
) == ZV
)
17305 clear_glyph_matrix (w
->desired_matrix
);
17309 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17311 /* If we have reached alignment, we can copy the rest of the
17313 if (IT_CHARPOS (it
) == CHARPOS (start
)
17314 /* Don't accept "alignment" inside a display vector,
17315 since start_row could have started in the middle of
17316 that same display vector (thus their character
17317 positions match), and we have no way of telling if
17318 that is the case. */
17319 && it
.current
.dpvec_index
< 0)
17322 it
.glyph_row
->reversed_p
= false;
17323 if (display_line (&it
))
17324 last_text_row
= it
.glyph_row
- 1;
17328 /* A value of current_y < last_visible_y means that we stopped
17329 at the previous window start, which in turn means that we
17330 have at least one reusable row. */
17331 if (it
.current_y
< it
.last_visible_y
)
17333 struct glyph_row
*row
;
17335 /* IT.vpos always starts from 0; it counts text lines. */
17336 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
17338 /* Find PT if not already found in the lines displayed. */
17339 if (w
->cursor
.vpos
< 0)
17341 int dy
= it
.current_y
- start_row
->y
;
17343 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17344 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
17346 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
17347 dy
, nrows_scrolled
);
17350 clear_glyph_matrix (w
->desired_matrix
);
17355 /* Scroll the display. Do it before the current matrix is
17356 changed. The problem here is that update has not yet
17357 run, i.e. part of the current matrix is not up to date.
17358 scroll_run_hook will clear the cursor, and use the
17359 current matrix to get the height of the row the cursor is
17361 run
.current_y
= start_row
->y
;
17362 run
.desired_y
= it
.current_y
;
17363 run
.height
= it
.last_visible_y
- it
.current_y
;
17365 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
17368 FRAME_RIF (f
)->update_window_begin_hook (w
);
17369 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17370 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17371 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17375 /* Shift current matrix down by nrows_scrolled lines. */
17376 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17377 rotate_matrix (w
->current_matrix
,
17379 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17382 /* Disable lines that must be updated. */
17383 for (i
= 0; i
< nrows_scrolled
; ++i
)
17384 (start_row
+ i
)->enabled_p
= false;
17386 /* Re-compute Y positions. */
17387 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17388 max_y
= it
.last_visible_y
;
17389 for (row
= start_row
+ nrows_scrolled
;
17393 row
->y
= it
.current_y
;
17394 row
->visible_height
= row
->height
;
17396 if (row
->y
< min_y
)
17397 row
->visible_height
-= min_y
- row
->y
;
17398 if (row
->y
+ row
->height
> max_y
)
17399 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17400 if (row
->fringe_bitmap_periodic_p
)
17401 row
->redraw_fringe_bitmaps_p
= true;
17403 it
.current_y
+= row
->height
;
17405 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17406 last_reused_text_row
= row
;
17407 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
17411 /* Disable lines in the current matrix which are now
17412 below the window. */
17413 for (++row
; row
< bottom_row
; ++row
)
17414 row
->enabled_p
= row
->mode_line_p
= false;
17417 /* Update window_end_pos etc.; last_reused_text_row is the last
17418 reused row from the current matrix containing text, if any.
17419 The value of last_text_row is the last displayed line
17420 containing text. */
17421 if (last_reused_text_row
)
17422 adjust_window_ends (w
, last_reused_text_row
, true);
17423 else if (last_text_row
)
17424 adjust_window_ends (w
, last_text_row
, false);
17427 /* This window must be completely empty. */
17428 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17429 w
->window_end_pos
= Z
- ZV
;
17430 w
->window_end_vpos
= 0;
17432 w
->window_end_valid
= false;
17434 /* Update hint: don't try scrolling again in update_window. */
17435 w
->desired_matrix
->no_scrolling_p
= true;
17438 debug_method_add (w
, "try_window_reusing_current_matrix 1");
17442 else if (CHARPOS (new_start
) > CHARPOS (start
))
17444 struct glyph_row
*pt_row
, *row
;
17445 struct glyph_row
*first_reusable_row
;
17446 struct glyph_row
*first_row_to_display
;
17448 int yb
= window_text_bottom_y (w
);
17450 /* Find the row starting at new_start, if there is one. Don't
17451 reuse a partially visible line at the end. */
17452 first_reusable_row
= start_row
;
17453 while (first_reusable_row
->enabled_p
17454 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
17455 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17456 < CHARPOS (new_start
)))
17457 ++first_reusable_row
;
17459 /* Give up if there is no row to reuse. */
17460 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
17461 || !first_reusable_row
->enabled_p
17462 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17463 != CHARPOS (new_start
)))
17466 /* We can reuse fully visible rows beginning with
17467 first_reusable_row to the end of the window. Set
17468 first_row_to_display to the first row that cannot be reused.
17469 Set pt_row to the row containing point, if there is any. */
17471 for (first_row_to_display
= first_reusable_row
;
17472 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
17473 ++first_row_to_display
)
17475 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
17476 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17477 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17478 && first_row_to_display
->ends_at_zv_p
17479 && pt_row
== NULL
)))
17480 pt_row
= first_row_to_display
;
17483 /* Start displaying at the start of first_row_to_display. */
17484 eassert (first_row_to_display
->y
< yb
);
17485 init_to_row_start (&it
, w
, first_row_to_display
);
17487 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
17489 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
17491 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
17492 + WINDOW_HEADER_LINE_HEIGHT (w
));
17494 /* Display lines beginning with first_row_to_display in the
17495 desired matrix. Set last_text_row to the last row displayed
17496 that displays text. */
17497 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
17498 if (pt_row
== NULL
)
17499 w
->cursor
.vpos
= -1;
17500 last_text_row
= NULL
;
17501 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17502 if (display_line (&it
))
17503 last_text_row
= it
.glyph_row
- 1;
17505 /* If point is in a reused row, adjust y and vpos of the cursor
17509 w
->cursor
.vpos
-= nrows_scrolled
;
17510 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
17513 /* Give up if point isn't in a row displayed or reused. (This
17514 also handles the case where w->cursor.vpos < nrows_scrolled
17515 after the calls to display_line, which can happen with scroll
17516 margins. See bug#1295.) */
17517 if (w
->cursor
.vpos
< 0)
17519 clear_glyph_matrix (w
->desired_matrix
);
17523 /* Scroll the display. */
17524 run
.current_y
= first_reusable_row
->y
;
17525 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17526 run
.height
= it
.last_visible_y
- run
.current_y
;
17527 dy
= run
.current_y
- run
.desired_y
;
17532 FRAME_RIF (f
)->update_window_begin_hook (w
);
17533 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17534 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17535 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
17539 /* Adjust Y positions of reused rows. */
17540 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17541 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17542 max_y
= it
.last_visible_y
;
17543 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
17546 row
->visible_height
= row
->height
;
17547 if (row
->y
< min_y
)
17548 row
->visible_height
-= min_y
- row
->y
;
17549 if (row
->y
+ row
->height
> max_y
)
17550 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17551 if (row
->fringe_bitmap_periodic_p
)
17552 row
->redraw_fringe_bitmaps_p
= true;
17555 /* Scroll the current matrix. */
17556 eassert (nrows_scrolled
> 0);
17557 rotate_matrix (w
->current_matrix
,
17559 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17562 /* Disable rows not reused. */
17563 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
17564 row
->enabled_p
= false;
17566 /* Point may have moved to a different line, so we cannot assume that
17567 the previous cursor position is valid; locate the correct row. */
17570 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
17572 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
17573 && !row
->ends_at_zv_p
;
17577 w
->cursor
.y
= row
->y
;
17579 if (row
< bottom_row
)
17581 /* Can't simply scan the row for point with
17582 bidi-reordered glyph rows. Let set_cursor_from_row
17583 figure out where to put the cursor, and if it fails,
17585 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
17587 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
17590 clear_glyph_matrix (w
->desired_matrix
);
17596 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
17597 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17600 && (!BUFFERP (glyph
->object
)
17601 || glyph
->charpos
< PT
);
17605 w
->cursor
.x
+= glyph
->pixel_width
;
17611 /* Adjust window end. A null value of last_text_row means that
17612 the window end is in reused rows which in turn means that
17613 only its vpos can have changed. */
17615 adjust_window_ends (w
, last_text_row
, false);
17617 w
->window_end_vpos
-= nrows_scrolled
;
17619 w
->window_end_valid
= false;
17620 w
->desired_matrix
->no_scrolling_p
= true;
17623 debug_method_add (w
, "try_window_reusing_current_matrix 2");
17633 /************************************************************************
17634 Window redisplay reusing current matrix when buffer has changed
17635 ************************************************************************/
17637 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
17638 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17639 ptrdiff_t *, ptrdiff_t *);
17640 static struct glyph_row
*
17641 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17642 struct glyph_row
*);
17645 /* Return the last row in MATRIX displaying text. If row START is
17646 non-null, start searching with that row. IT gives the dimensions
17647 of the display. Value is null if matrix is empty; otherwise it is
17648 a pointer to the row found. */
17650 static struct glyph_row
*
17651 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17652 struct glyph_row
*start
)
17654 struct glyph_row
*row
, *row_found
;
17656 /* Set row_found to the last row in IT->w's current matrix
17657 displaying text. The loop looks funny but think of partially
17660 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17661 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17663 eassert (row
->enabled_p
);
17665 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17674 /* Return the last row in the current matrix of W that is not affected
17675 by changes at the start of current_buffer that occurred since W's
17676 current matrix was built. Value is null if no such row exists.
17678 BEG_UNCHANGED us the number of characters unchanged at the start of
17679 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17680 first changed character in current_buffer. Characters at positions <
17681 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17682 when the current matrix was built. */
17684 static struct glyph_row
*
17685 find_last_unchanged_at_beg_row (struct window
*w
)
17687 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17688 struct glyph_row
*row
;
17689 struct glyph_row
*row_found
= NULL
;
17690 int yb
= window_text_bottom_y (w
);
17692 /* Find the last row displaying unchanged text. */
17693 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17694 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17695 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17698 if (/* If row ends before first_changed_pos, it is unchanged,
17699 except in some case. */
17700 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17701 /* When row ends in ZV and we write at ZV it is not
17703 && !row
->ends_at_zv_p
17704 /* When first_changed_pos is the end of a continued line,
17705 row is not unchanged because it may be no longer
17707 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17708 && (row
->continued_p
17709 || row
->exact_window_width_line_p
))
17710 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17711 needs to be recomputed, so don't consider this row as
17712 unchanged. This happens when the last line was
17713 bidi-reordered and was killed immediately before this
17714 redisplay cycle. In that case, ROW->end stores the
17715 buffer position of the first visual-order character of
17716 the killed text, which is now beyond ZV. */
17717 && CHARPOS (row
->end
.pos
) <= ZV
)
17720 /* Stop if last visible row. */
17721 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17729 /* Find the first glyph row in the current matrix of W that is not
17730 affected by changes at the end of current_buffer since the
17731 time W's current matrix was built.
17733 Return in *DELTA the number of chars by which buffer positions in
17734 unchanged text at the end of current_buffer must be adjusted.
17736 Return in *DELTA_BYTES the corresponding number of bytes.
17738 Value is null if no such row exists, i.e. all rows are affected by
17741 static struct glyph_row
*
17742 find_first_unchanged_at_end_row (struct window
*w
,
17743 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17745 struct glyph_row
*row
;
17746 struct glyph_row
*row_found
= NULL
;
17748 *delta
= *delta_bytes
= 0;
17750 /* Display must not have been paused, otherwise the current matrix
17751 is not up to date. */
17752 eassert (w
->window_end_valid
);
17754 /* A value of window_end_pos >= END_UNCHANGED means that the window
17755 end is in the range of changed text. If so, there is no
17756 unchanged row at the end of W's current matrix. */
17757 if (w
->window_end_pos
>= END_UNCHANGED
)
17760 /* Set row to the last row in W's current matrix displaying text. */
17761 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17763 /* If matrix is entirely empty, no unchanged row exists. */
17764 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17766 /* The value of row is the last glyph row in the matrix having a
17767 meaningful buffer position in it. The end position of row
17768 corresponds to window_end_pos. This allows us to translate
17769 buffer positions in the current matrix to current buffer
17770 positions for characters not in changed text. */
17772 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17773 ptrdiff_t Z_BYTE_old
=
17774 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17775 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17776 struct glyph_row
*first_text_row
17777 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17779 *delta
= Z
- Z_old
;
17780 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17782 /* Set last_unchanged_pos to the buffer position of the last
17783 character in the buffer that has not been changed. Z is the
17784 index + 1 of the last character in current_buffer, i.e. by
17785 subtracting END_UNCHANGED we get the index of the last
17786 unchanged character, and we have to add BEG to get its buffer
17788 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17789 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17791 /* Search backward from ROW for a row displaying a line that
17792 starts at a minimum position >= last_unchanged_pos_old. */
17793 for (; row
> first_text_row
; --row
)
17795 /* This used to abort, but it can happen.
17796 It is ok to just stop the search instead here. KFS. */
17797 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17800 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17805 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17811 /* Make sure that glyph rows in the current matrix of window W
17812 reference the same glyph memory as corresponding rows in the
17813 frame's frame matrix. This function is called after scrolling W's
17814 current matrix on a terminal frame in try_window_id and
17815 try_window_reusing_current_matrix. */
17818 sync_frame_with_window_matrix_rows (struct window
*w
)
17820 struct frame
*f
= XFRAME (w
->frame
);
17821 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17823 /* Preconditions: W must be a leaf window and full-width. Its frame
17824 must have a frame matrix. */
17825 eassert (BUFFERP (w
->contents
));
17826 eassert (WINDOW_FULL_WIDTH_P (w
));
17827 eassert (!FRAME_WINDOW_P (f
));
17829 /* If W is a full-width window, glyph pointers in W's current matrix
17830 have, by definition, to be the same as glyph pointers in the
17831 corresponding frame matrix. Note that frame matrices have no
17832 marginal areas (see build_frame_matrix). */
17833 window_row
= w
->current_matrix
->rows
;
17834 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17835 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17836 while (window_row
< window_row_end
)
17838 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17839 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17841 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17842 frame_row
->glyphs
[TEXT_AREA
] = start
;
17843 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17844 frame_row
->glyphs
[LAST_AREA
] = end
;
17846 /* Disable frame rows whose corresponding window rows have
17847 been disabled in try_window_id. */
17848 if (!window_row
->enabled_p
)
17849 frame_row
->enabled_p
= false;
17851 ++window_row
, ++frame_row
;
17856 /* Find the glyph row in window W containing CHARPOS. Consider all
17857 rows between START and END (not inclusive). END null means search
17858 all rows to the end of the display area of W. Value is the row
17859 containing CHARPOS or null. */
17862 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17863 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17865 struct glyph_row
*row
= start
;
17866 struct glyph_row
*best_row
= NULL
;
17867 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17870 /* If we happen to start on a header-line, skip that. */
17871 if (row
->mode_line_p
)
17874 if ((end
&& row
>= end
) || !row
->enabled_p
)
17877 last_y
= window_text_bottom_y (w
) - dy
;
17881 /* Give up if we have gone too far. */
17882 if ((end
&& row
>= end
) || !row
->enabled_p
)
17884 /* This formerly returned if they were equal.
17885 I think that both quantities are of a "last plus one" type;
17886 if so, when they are equal, the row is within the screen. -- rms. */
17887 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17890 /* If it is in this row, return this row. */
17891 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17892 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17893 /* The end position of a row equals the start
17894 position of the next row. If CHARPOS is there, we
17895 would rather consider it displayed in the next
17896 line, except when this line ends in ZV. */
17897 && !row_for_charpos_p (row
, charpos
)))
17898 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17902 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17903 || (!best_row
&& !row
->continued_p
))
17905 /* In bidi-reordered rows, there could be several rows whose
17906 edges surround CHARPOS, all of these rows belonging to
17907 the same continued line. We need to find the row which
17908 fits CHARPOS the best. */
17909 for (g
= row
->glyphs
[TEXT_AREA
];
17910 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17913 if (!STRINGP (g
->object
))
17915 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17917 mindif
= eabs (g
->charpos
- charpos
);
17919 /* Exact match always wins. */
17926 else if (best_row
&& !row
->continued_p
)
17933 /* Try to redisplay window W by reusing its existing display. W's
17934 current matrix must be up to date when this function is called,
17935 i.e., window_end_valid must be true.
17939 >= 1 if successful, i.e. display has been updated
17941 1 means the changes were in front of a newline that precedes
17942 the window start, and the whole current matrix was reused
17943 2 means the changes were after the last position displayed
17944 in the window, and the whole current matrix was reused
17945 3 means portions of the current matrix were reused, while
17946 some of the screen lines were redrawn
17947 -1 if redisplay with same window start is known not to succeed
17948 0 if otherwise unsuccessful
17950 The following steps are performed:
17952 1. Find the last row in the current matrix of W that is not
17953 affected by changes at the start of current_buffer. If no such row
17956 2. Find the first row in W's current matrix that is not affected by
17957 changes at the end of current_buffer. Maybe there is no such row.
17959 3. Display lines beginning with the row + 1 found in step 1 to the
17960 row found in step 2 or, if step 2 didn't find a row, to the end of
17963 4. If cursor is not known to appear on the window, give up.
17965 5. If display stopped at the row found in step 2, scroll the
17966 display and current matrix as needed.
17968 6. Maybe display some lines at the end of W, if we must. This can
17969 happen under various circumstances, like a partially visible line
17970 becoming fully visible, or because newly displayed lines are displayed
17971 in smaller font sizes.
17973 7. Update W's window end information. */
17976 try_window_id (struct window
*w
)
17978 struct frame
*f
= XFRAME (w
->frame
);
17979 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17980 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17981 struct glyph_row
*last_unchanged_at_beg_row
;
17982 struct glyph_row
*first_unchanged_at_end_row
;
17983 struct glyph_row
*row
;
17984 struct glyph_row
*bottom_row
;
17987 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17989 struct text_pos start_pos
;
17991 int first_unchanged_at_end_vpos
= 0;
17992 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17993 struct text_pos start
;
17994 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17997 if (inhibit_try_window_id
)
18001 /* This is handy for debugging. */
18003 #define GIVE_UP(X) \
18005 TRACE ((stderr, "try_window_id give up %d\n", (X))); \
18009 #define GIVE_UP(X) return 0
18012 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
18014 /* Don't use this for mini-windows because these can show
18015 messages and mini-buffers, and we don't handle that here. */
18016 if (MINI_WINDOW_P (w
))
18019 /* This flag is used to prevent redisplay optimizations. */
18020 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
18023 /* This function's optimizations cannot be used if overlays have
18024 changed in the buffer displayed by the window, so give up if they
18026 if (w
->last_overlay_modified
!= OVERLAY_MODIFF
)
18029 /* Verify that narrowing has not changed.
18030 Also verify that we were not told to prevent redisplay optimizations.
18031 It would be nice to further
18032 reduce the number of cases where this prevents try_window_id. */
18033 if (current_buffer
->clip_changed
18034 || current_buffer
->prevent_redisplay_optimizations_p
)
18037 /* Window must either use window-based redisplay or be full width. */
18038 if (!FRAME_WINDOW_P (f
)
18039 && (!FRAME_LINE_INS_DEL_OK (f
)
18040 || !WINDOW_FULL_WIDTH_P (w
)))
18043 /* Give up if point is known NOT to appear in W. */
18044 if (PT
< CHARPOS (start
))
18047 /* Another way to prevent redisplay optimizations. */
18048 if (w
->last_modified
== 0)
18051 /* Verify that window is not hscrolled. */
18052 if (w
->hscroll
!= 0)
18055 /* Verify that display wasn't paused. */
18056 if (!w
->window_end_valid
)
18059 /* Likewise if highlighting trailing whitespace. */
18060 if (!NILP (Vshow_trailing_whitespace
))
18063 /* Can't use this if overlay arrow position and/or string have
18065 if (overlay_arrows_changed_p ())
18068 /* When word-wrap is on, adding a space to the first word of a
18069 wrapped line can change the wrap position, altering the line
18070 above it. It might be worthwhile to handle this more
18071 intelligently, but for now just redisplay from scratch. */
18072 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
18075 /* Under bidi reordering, adding or deleting a character in the
18076 beginning of a paragraph, before the first strong directional
18077 character, can change the base direction of the paragraph (unless
18078 the buffer specifies a fixed paragraph direction), which will
18079 require redisplaying the whole paragraph. It might be worthwhile
18080 to find the paragraph limits and widen the range of redisplayed
18081 lines to that, but for now just give up this optimization and
18082 redisplay from scratch. */
18083 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
18084 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
18087 /* Give up if the buffer has line-spacing set, as Lisp-level changes
18088 to that variable require thorough redisplay. */
18089 if (!NILP (BVAR (XBUFFER (w
->contents
), extra_line_spacing
)))
18092 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
18093 only if buffer has really changed. The reason is that the gap is
18094 initially at Z for freshly visited files. The code below would
18095 set end_unchanged to 0 in that case. */
18096 if (MODIFF
> SAVE_MODIFF
18097 /* This seems to happen sometimes after saving a buffer. */
18098 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
18100 if (GPT
- BEG
< BEG_UNCHANGED
)
18101 BEG_UNCHANGED
= GPT
- BEG
;
18102 if (Z
- GPT
< END_UNCHANGED
)
18103 END_UNCHANGED
= Z
- GPT
;
18106 /* The position of the first and last character that has been changed. */
18107 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
18108 last_changed_charpos
= Z
- END_UNCHANGED
;
18110 /* If window starts after a line end, and the last change is in
18111 front of that newline, then changes don't affect the display.
18112 This case happens with stealth-fontification. Note that although
18113 the display is unchanged, glyph positions in the matrix have to
18114 be adjusted, of course. */
18115 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
18116 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
18117 && ((last_changed_charpos
< CHARPOS (start
)
18118 && CHARPOS (start
) == BEGV
)
18119 || (last_changed_charpos
< CHARPOS (start
) - 1
18120 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
18122 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
18123 struct glyph_row
*r0
;
18125 /* Compute how many chars/bytes have been added to or removed
18126 from the buffer. */
18127 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
18128 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
18129 Z_delta
= Z
- Z_old
;
18130 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
18132 /* Give up if PT is not in the window. Note that it already has
18133 been checked at the start of try_window_id that PT is not in
18134 front of the window start. */
18135 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
18138 /* If window start is unchanged, we can reuse the whole matrix
18139 as is, after adjusting glyph positions. No need to compute
18140 the window end again, since its offset from Z hasn't changed. */
18141 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18142 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
18143 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
18144 /* PT must not be in a partially visible line. */
18145 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
18146 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
18148 /* Adjust positions in the glyph matrix. */
18149 if (Z_delta
|| Z_delta_bytes
)
18151 struct glyph_row
*r1
18152 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18153 increment_matrix_positions (w
->current_matrix
,
18154 MATRIX_ROW_VPOS (r0
, current_matrix
),
18155 MATRIX_ROW_VPOS (r1
, current_matrix
),
18156 Z_delta
, Z_delta_bytes
);
18159 /* Set the cursor. */
18160 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
18162 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
18167 /* Handle the case that changes are all below what is displayed in
18168 the window, and that PT is in the window. This shortcut cannot
18169 be taken if ZV is visible in the window, and text has been added
18170 there that is visible in the window. */
18171 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
18172 /* ZV is not visible in the window, or there are no
18173 changes at ZV, actually. */
18174 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
18175 || first_changed_charpos
== last_changed_charpos
))
18177 struct glyph_row
*r0
;
18179 /* Give up if PT is not in the window. Note that it already has
18180 been checked at the start of try_window_id that PT is not in
18181 front of the window start. */
18182 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
18185 /* If window start is unchanged, we can reuse the whole matrix
18186 as is, without changing glyph positions since no text has
18187 been added/removed in front of the window end. */
18188 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18189 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
18190 /* PT must not be in a partially visible line. */
18191 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
18192 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
18194 /* We have to compute the window end anew since text
18195 could have been added/removed after it. */
18196 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18197 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18199 /* Set the cursor. */
18200 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
18202 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
18207 /* Give up if window start is in the changed area.
18209 The condition used to read
18211 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
18213 but why that was tested escapes me at the moment. */
18214 if (CHARPOS (start
) >= first_changed_charpos
18215 && CHARPOS (start
) <= last_changed_charpos
)
18218 /* Check that window start agrees with the start of the first glyph
18219 row in its current matrix. Check this after we know the window
18220 start is not in changed text, otherwise positions would not be
18222 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
18223 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
18226 /* Give up if the window ends in strings. Overlay strings
18227 at the end are difficult to handle, so don't try. */
18228 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
18229 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
18232 /* Compute the position at which we have to start displaying new
18233 lines. Some of the lines at the top of the window might be
18234 reusable because they are not displaying changed text. Find the
18235 last row in W's current matrix not affected by changes at the
18236 start of current_buffer. Value is null if changes start in the
18237 first line of window. */
18238 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
18239 if (last_unchanged_at_beg_row
)
18241 /* Avoid starting to display in the middle of a character, a TAB
18242 for instance. This is easier than to set up the iterator
18243 exactly, and it's not a frequent case, so the additional
18244 effort wouldn't really pay off. */
18245 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
18246 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
18247 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
18248 --last_unchanged_at_beg_row
;
18250 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
18253 if (! init_to_row_end (&it
, w
, last_unchanged_at_beg_row
))
18255 start_pos
= it
.current
.pos
;
18257 /* Start displaying new lines in the desired matrix at the same
18258 vpos we would use in the current matrix, i.e. below
18259 last_unchanged_at_beg_row. */
18260 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
18262 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18263 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
18265 eassert (it
.hpos
== 0 && it
.current_x
== 0);
18269 /* There are no reusable lines at the start of the window.
18270 Start displaying in the first text line. */
18271 start_display (&it
, w
, start
);
18272 it
.vpos
= it
.first_vpos
;
18273 start_pos
= it
.current
.pos
;
18276 /* Find the first row that is not affected by changes at the end of
18277 the buffer. Value will be null if there is no unchanged row, in
18278 which case we must redisplay to the end of the window. delta
18279 will be set to the value by which buffer positions beginning with
18280 first_unchanged_at_end_row have to be adjusted due to text
18282 first_unchanged_at_end_row
18283 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
18284 IF_DEBUG (debug_delta
= delta
);
18285 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
18287 /* Set stop_pos to the buffer position up to which we will have to
18288 display new lines. If first_unchanged_at_end_row != NULL, this
18289 is the buffer position of the start of the line displayed in that
18290 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
18291 that we don't stop at a buffer position. */
18293 if (first_unchanged_at_end_row
)
18295 eassert (last_unchanged_at_beg_row
== NULL
18296 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
18298 /* If this is a continuation line, move forward to the next one
18299 that isn't. Changes in lines above affect this line.
18300 Caution: this may move first_unchanged_at_end_row to a row
18301 not displaying text. */
18302 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
18303 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18304 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18305 < it
.last_visible_y
))
18306 ++first_unchanged_at_end_row
;
18308 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18309 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18310 >= it
.last_visible_y
))
18311 first_unchanged_at_end_row
= NULL
;
18314 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
18316 first_unchanged_at_end_vpos
18317 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
18318 eassert (stop_pos
>= Z
- END_UNCHANGED
);
18321 else if (last_unchanged_at_beg_row
== NULL
)
18327 /* Either there is no unchanged row at the end, or the one we have
18328 now displays text. This is a necessary condition for the window
18329 end pos calculation at the end of this function. */
18330 eassert (first_unchanged_at_end_row
== NULL
18331 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18333 debug_last_unchanged_at_beg_vpos
18334 = (last_unchanged_at_beg_row
18335 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
18337 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
18339 #endif /* GLYPH_DEBUG */
18342 /* Display new lines. Set last_text_row to the last new line
18343 displayed which has text on it, i.e. might end up as being the
18344 line where the window_end_vpos is. */
18345 w
->cursor
.vpos
= -1;
18346 last_text_row
= NULL
;
18347 overlay_arrow_seen
= false;
18348 if (it
.current_y
< it
.last_visible_y
18349 && !f
->fonts_changed
18350 && (first_unchanged_at_end_row
== NULL
18351 || IT_CHARPOS (it
) < stop_pos
))
18352 it
.glyph_row
->reversed_p
= false;
18353 while (it
.current_y
< it
.last_visible_y
18354 && !f
->fonts_changed
18355 && (first_unchanged_at_end_row
== NULL
18356 || IT_CHARPOS (it
) < stop_pos
))
18358 if (display_line (&it
))
18359 last_text_row
= it
.glyph_row
- 1;
18362 if (f
->fonts_changed
)
18365 /* The redisplay iterations in display_line above could have
18366 triggered font-lock, which could have done something that
18367 invalidates IT->w window's end-point information, on which we
18368 rely below. E.g., one package, which will remain unnamed, used
18369 to install a font-lock-fontify-region-function that called
18370 bury-buffer, whose side effect is to switch the buffer displayed
18371 by IT->w, and that predictably resets IT->w's window_end_valid
18372 flag, which we already tested at the entry to this function.
18373 Amply punish such packages/modes by giving up on this
18374 optimization in those cases. */
18375 if (!w
->window_end_valid
)
18377 clear_glyph_matrix (w
->desired_matrix
);
18381 /* Compute differences in buffer positions, y-positions etc. for
18382 lines reused at the bottom of the window. Compute what we can
18384 if (first_unchanged_at_end_row
18385 /* No lines reused because we displayed everything up to the
18386 bottom of the window. */
18387 && it
.current_y
< it
.last_visible_y
)
18390 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
18392 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
18393 run
.current_y
= first_unchanged_at_end_row
->y
;
18394 run
.desired_y
= run
.current_y
+ dy
;
18395 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
18399 delta
= delta_bytes
= dvpos
= dy
18400 = run
.current_y
= run
.desired_y
= run
.height
= 0;
18401 first_unchanged_at_end_row
= NULL
;
18403 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
18406 /* Find the cursor if not already found. We have to decide whether
18407 PT will appear on this window (it sometimes doesn't, but this is
18408 not a very frequent case.) This decision has to be made before
18409 the current matrix is altered. A value of cursor.vpos < 0 means
18410 that PT is either in one of the lines beginning at
18411 first_unchanged_at_end_row or below the window. Don't care for
18412 lines that might be displayed later at the window end; as
18413 mentioned, this is not a frequent case. */
18414 if (w
->cursor
.vpos
< 0)
18416 /* Cursor in unchanged rows at the top? */
18417 if (PT
< CHARPOS (start_pos
)
18418 && last_unchanged_at_beg_row
)
18420 row
= row_containing_pos (w
, PT
,
18421 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
18422 last_unchanged_at_beg_row
+ 1, 0);
18424 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
18427 /* Start from first_unchanged_at_end_row looking for PT. */
18428 else if (first_unchanged_at_end_row
)
18430 row
= row_containing_pos (w
, PT
- delta
,
18431 first_unchanged_at_end_row
, NULL
, 0);
18433 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
18434 delta_bytes
, dy
, dvpos
);
18437 /* Give up if cursor was not found. */
18438 if (w
->cursor
.vpos
< 0)
18440 clear_glyph_matrix (w
->desired_matrix
);
18445 /* Don't let the cursor end in the scroll margins. */
18447 int this_scroll_margin
, cursor_height
;
18448 int frame_line_height
= default_line_pixel_height (w
);
18449 int window_total_lines
18450 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
18452 this_scroll_margin
=
18453 max (0, min (scroll_margin
, window_total_lines
/ 4));
18454 this_scroll_margin
*= frame_line_height
;
18455 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
18457 if ((w
->cursor
.y
< this_scroll_margin
18458 && CHARPOS (start
) > BEGV
)
18459 /* Old redisplay didn't take scroll margin into account at the bottom,
18460 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
18461 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
18462 ? cursor_height
+ this_scroll_margin
18463 : 1)) > it
.last_visible_y
)
18465 w
->cursor
.vpos
= -1;
18466 clear_glyph_matrix (w
->desired_matrix
);
18471 /* Scroll the display. Do it before changing the current matrix so
18472 that xterm.c doesn't get confused about where the cursor glyph is
18474 if (dy
&& run
.height
)
18478 if (FRAME_WINDOW_P (f
))
18480 FRAME_RIF (f
)->update_window_begin_hook (w
);
18481 FRAME_RIF (f
)->clear_window_mouse_face (w
);
18482 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
18483 FRAME_RIF (f
)->update_window_end_hook (w
, false, false);
18487 /* Terminal frame. In this case, dvpos gives the number of
18488 lines to scroll by; dvpos < 0 means scroll up. */
18490 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
18491 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
18492 int end
= (WINDOW_TOP_EDGE_LINE (w
)
18493 + WINDOW_WANTS_HEADER_LINE_P (w
)
18494 + window_internal_height (w
));
18496 #if defined (HAVE_GPM) || defined (MSDOS)
18497 x_clear_window_mouse_face (w
);
18499 /* Perform the operation on the screen. */
18502 /* Scroll last_unchanged_at_beg_row to the end of the
18503 window down dvpos lines. */
18504 set_terminal_window (f
, end
);
18506 /* On dumb terminals delete dvpos lines at the end
18507 before inserting dvpos empty lines. */
18508 if (!FRAME_SCROLL_REGION_OK (f
))
18509 ins_del_lines (f
, end
- dvpos
, -dvpos
);
18511 /* Insert dvpos empty lines in front of
18512 last_unchanged_at_beg_row. */
18513 ins_del_lines (f
, from
, dvpos
);
18515 else if (dvpos
< 0)
18517 /* Scroll up last_unchanged_at_beg_vpos to the end of
18518 the window to last_unchanged_at_beg_vpos - |dvpos|. */
18519 set_terminal_window (f
, end
);
18521 /* Delete dvpos lines in front of
18522 last_unchanged_at_beg_vpos. ins_del_lines will set
18523 the cursor to the given vpos and emit |dvpos| delete
18525 ins_del_lines (f
, from
+ dvpos
, dvpos
);
18527 /* On a dumb terminal insert dvpos empty lines at the
18529 if (!FRAME_SCROLL_REGION_OK (f
))
18530 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
18533 set_terminal_window (f
, 0);
18539 /* Shift reused rows of the current matrix to the right position.
18540 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
18542 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18543 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
18546 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
18547 bottom_vpos
, dvpos
);
18548 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
18551 else if (dvpos
> 0)
18553 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
18554 bottom_vpos
, dvpos
);
18555 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
18556 first_unchanged_at_end_vpos
+ dvpos
);
18559 /* For frame-based redisplay, make sure that current frame and window
18560 matrix are in sync with respect to glyph memory. */
18561 if (!FRAME_WINDOW_P (f
))
18562 sync_frame_with_window_matrix_rows (w
);
18564 /* Adjust buffer positions in reused rows. */
18565 if (delta
|| delta_bytes
)
18566 increment_matrix_positions (current_matrix
,
18567 first_unchanged_at_end_vpos
+ dvpos
,
18568 bottom_vpos
, delta
, delta_bytes
);
18570 /* Adjust Y positions. */
18572 shift_glyph_matrix (w
, current_matrix
,
18573 first_unchanged_at_end_vpos
+ dvpos
,
18576 if (first_unchanged_at_end_row
)
18578 first_unchanged_at_end_row
+= dvpos
;
18579 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
18580 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
18581 first_unchanged_at_end_row
= NULL
;
18584 /* If scrolling up, there may be some lines to display at the end of
18586 last_text_row_at_end
= NULL
;
18589 /* Scrolling up can leave for example a partially visible line
18590 at the end of the window to be redisplayed. */
18591 /* Set last_row to the glyph row in the current matrix where the
18592 window end line is found. It has been moved up or down in
18593 the matrix by dvpos. */
18594 int last_vpos
= w
->window_end_vpos
+ dvpos
;
18595 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
18597 /* If last_row is the window end line, it should display text. */
18598 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
18600 /* If window end line was partially visible before, begin
18601 displaying at that line. Otherwise begin displaying with the
18602 line following it. */
18603 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
18605 init_to_row_start (&it
, w
, last_row
);
18606 it
.vpos
= last_vpos
;
18607 it
.current_y
= last_row
->y
;
18611 init_to_row_end (&it
, w
, last_row
);
18612 it
.vpos
= 1 + last_vpos
;
18613 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
18617 /* We may start in a continuation line. If so, we have to
18618 get the right continuation_lines_width and current_x. */
18619 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
18620 it
.hpos
= it
.current_x
= 0;
18622 /* Display the rest of the lines at the window end. */
18623 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18624 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
18626 /* Is it always sure that the display agrees with lines in
18627 the current matrix? I don't think so, so we mark rows
18628 displayed invalid in the current matrix by setting their
18629 enabled_p flag to false. */
18630 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
18631 if (display_line (&it
))
18632 last_text_row_at_end
= it
.glyph_row
- 1;
18636 /* Update window_end_pos and window_end_vpos. */
18637 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
18639 /* Window end line if one of the preserved rows from the current
18640 matrix. Set row to the last row displaying text in current
18641 matrix starting at first_unchanged_at_end_row, after
18643 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18644 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
18645 first_unchanged_at_end_row
);
18646 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
18647 adjust_window_ends (w
, row
, true);
18648 eassert (w
->window_end_bytepos
>= 0);
18649 IF_DEBUG (debug_method_add (w
, "A"));
18651 else if (last_text_row_at_end
)
18653 adjust_window_ends (w
, last_text_row_at_end
, false);
18654 eassert (w
->window_end_bytepos
>= 0);
18655 IF_DEBUG (debug_method_add (w
, "B"));
18657 else if (last_text_row
)
18659 /* We have displayed either to the end of the window or at the
18660 end of the window, i.e. the last row with text is to be found
18661 in the desired matrix. */
18662 adjust_window_ends (w
, last_text_row
, false);
18663 eassert (w
->window_end_bytepos
>= 0);
18665 else if (first_unchanged_at_end_row
== NULL
18666 && last_text_row
== NULL
18667 && last_text_row_at_end
== NULL
)
18669 /* Displayed to end of window, but no line containing text was
18670 displayed. Lines were deleted at the end of the window. */
18671 bool first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
);
18672 int vpos
= w
->window_end_vpos
;
18673 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
18674 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18677 row
== NULL
&& vpos
>= first_vpos
;
18678 --vpos
, --current_row
, --desired_row
)
18680 if (desired_row
->enabled_p
)
18682 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18685 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18689 eassert (row
!= NULL
);
18690 w
->window_end_vpos
= vpos
+ 1;
18691 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18692 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18693 eassert (w
->window_end_bytepos
>= 0);
18694 IF_DEBUG (debug_method_add (w
, "C"));
18699 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18700 debug_end_vpos
= w
->window_end_vpos
));
18702 /* Record that display has not been completed. */
18703 w
->window_end_valid
= false;
18704 w
->desired_matrix
->no_scrolling_p
= true;
18712 /***********************************************************************
18713 More debugging support
18714 ***********************************************************************/
18718 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18719 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18720 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18723 /* Dump the contents of glyph matrix MATRIX on stderr.
18725 GLYPHS 0 means don't show glyph contents.
18726 GLYPHS 1 means show glyphs in short form
18727 GLYPHS > 1 means show glyphs in long form. */
18730 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18733 for (i
= 0; i
< matrix
->nrows
; ++i
)
18734 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18738 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18739 the glyph row and area where the glyph comes from. */
18742 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18744 if (glyph
->type
== CHAR_GLYPH
18745 || glyph
->type
== GLYPHLESS_GLYPH
)
18748 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18749 glyph
- row
->glyphs
[TEXT_AREA
],
18750 (glyph
->type
== CHAR_GLYPH
18754 (BUFFERP (glyph
->object
)
18756 : (STRINGP (glyph
->object
)
18758 : (NILP (glyph
->object
)
18761 glyph
->pixel_width
,
18763 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18767 glyph
->left_box_line_p
,
18768 glyph
->right_box_line_p
);
18770 else if (glyph
->type
== STRETCH_GLYPH
)
18773 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18774 glyph
- row
->glyphs
[TEXT_AREA
],
18777 (BUFFERP (glyph
->object
)
18779 : (STRINGP (glyph
->object
)
18781 : (NILP (glyph
->object
)
18784 glyph
->pixel_width
,
18788 glyph
->left_box_line_p
,
18789 glyph
->right_box_line_p
);
18791 else if (glyph
->type
== IMAGE_GLYPH
)
18794 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18795 glyph
- row
->glyphs
[TEXT_AREA
],
18798 (BUFFERP (glyph
->object
)
18800 : (STRINGP (glyph
->object
)
18802 : (NILP (glyph
->object
)
18805 glyph
->pixel_width
,
18809 glyph
->left_box_line_p
,
18810 glyph
->right_box_line_p
);
18812 else if (glyph
->type
== COMPOSITE_GLYPH
)
18815 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18816 glyph
- row
->glyphs
[TEXT_AREA
],
18819 (BUFFERP (glyph
->object
)
18821 : (STRINGP (glyph
->object
)
18823 : (NILP (glyph
->object
)
18826 glyph
->pixel_width
,
18828 if (glyph
->u
.cmp
.automatic
)
18831 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18832 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18834 glyph
->left_box_line_p
,
18835 glyph
->right_box_line_p
);
18837 else if (glyph
->type
== XWIDGET_GLYPH
)
18839 #ifndef HAVE_XWIDGETS
18843 " %5d %4c %6d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18844 glyph
- row
->glyphs
[TEXT_AREA
],
18847 (BUFFERP (glyph
->object
)
18849 : (STRINGP (glyph
->object
)
18852 glyph
->pixel_width
,
18856 glyph
->left_box_line_p
,
18857 glyph
->right_box_line_p
);
18863 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18864 GLYPHS 0 means don't show glyph contents.
18865 GLYPHS 1 means show glyphs in short form
18866 GLYPHS > 1 means show glyphs in long form. */
18869 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18873 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18874 fprintf (stderr
, "==============================================================================\n");
18876 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18877 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18879 MATRIX_ROW_START_CHARPOS (row
),
18880 MATRIX_ROW_END_CHARPOS (row
),
18881 row
->used
[TEXT_AREA
],
18882 row
->contains_overlapping_glyphs_p
,
18884 row
->truncated_on_left_p
,
18885 row
->truncated_on_right_p
,
18887 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18888 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18891 row
->ends_in_middle_of_char_p
,
18892 row
->starts_in_middle_of_char_p
,
18898 row
->visible_height
,
18901 /* The next 3 lines should align to "Start" in the header. */
18902 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18903 row
->end
.overlay_string_index
,
18904 row
->continuation_lines_width
);
18905 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18906 CHARPOS (row
->start
.string_pos
),
18907 CHARPOS (row
->end
.string_pos
));
18908 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18909 row
->end
.dpvec_index
);
18916 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18918 struct glyph
*glyph
= row
->glyphs
[area
];
18919 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18921 /* Glyph for a line end in text. */
18922 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18925 if (glyph
< glyph_end
)
18926 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18928 for (; glyph
< glyph_end
; ++glyph
)
18929 dump_glyph (row
, glyph
, area
);
18932 else if (glyphs
== 1)
18935 char s
[SHRT_MAX
+ 4];
18937 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18941 for (i
= 0; i
< row
->used
[area
]; ++i
)
18943 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18944 if (i
== row
->used
[area
] - 1
18945 && area
== TEXT_AREA
18946 && NILP (glyph
->object
)
18947 && glyph
->type
== CHAR_GLYPH
18948 && glyph
->u
.ch
== ' ')
18950 strcpy (&s
[i
], "[\\n]");
18953 else if (glyph
->type
== CHAR_GLYPH
18954 && glyph
->u
.ch
< 0x80
18955 && glyph
->u
.ch
>= ' ')
18956 s
[i
] = glyph
->u
.ch
;
18962 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18968 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18969 Sdump_glyph_matrix
, 0, 1, "p",
18970 doc
: /* Dump the current matrix of the selected window to stderr.
18971 Shows contents of glyph row structures. With non-nil
18972 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18973 glyphs in short form, otherwise show glyphs in long form.
18975 Interactively, no argument means show glyphs in short form;
18976 with numeric argument, its value is passed as the GLYPHS flag. */)
18977 (Lisp_Object glyphs
)
18979 struct window
*w
= XWINDOW (selected_window
);
18980 struct buffer
*buffer
= XBUFFER (w
->contents
);
18982 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18983 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18984 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18985 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18986 fprintf (stderr
, "=============================================\n");
18987 dump_glyph_matrix (w
->current_matrix
,
18988 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18993 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18994 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* Dump the current glyph matrix of the selected frame to stderr.
18995 Only text-mode frames have frame glyph matrices. */)
18998 struct frame
*f
= XFRAME (selected_frame
);
19000 if (f
->current_matrix
)
19001 dump_glyph_matrix (f
->current_matrix
, 1);
19003 fprintf (stderr
, "*** This frame doesn't have a frame glyph matrix ***\n");
19008 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
19009 doc
: /* Dump glyph row ROW to stderr.
19010 GLYPH 0 means don't dump glyphs.
19011 GLYPH 1 means dump glyphs in short form.
19012 GLYPH > 1 or omitted means dump glyphs in long form. */)
19013 (Lisp_Object row
, Lisp_Object glyphs
)
19015 struct glyph_matrix
*matrix
;
19018 CHECK_NUMBER (row
);
19019 matrix
= XWINDOW (selected_window
)->current_matrix
;
19021 if (vpos
>= 0 && vpos
< matrix
->nrows
)
19022 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
19024 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
19029 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
19030 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
19031 GLYPH 0 means don't dump glyphs.
19032 GLYPH 1 means dump glyphs in short form.
19033 GLYPH > 1 or omitted means dump glyphs in long form.
19035 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
19037 (Lisp_Object row
, Lisp_Object glyphs
)
19039 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19040 struct frame
*sf
= SELECTED_FRAME ();
19041 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
19044 CHECK_NUMBER (row
);
19046 if (vpos
>= 0 && vpos
< m
->nrows
)
19047 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
19048 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
19054 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
19055 doc
: /* Toggle tracing of redisplay.
19056 With ARG, turn tracing on if and only if ARG is positive. */)
19060 trace_redisplay_p
= !trace_redisplay_p
;
19063 arg
= Fprefix_numeric_value (arg
);
19064 trace_redisplay_p
= XINT (arg
) > 0;
19071 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
19072 doc
: /* Like `format', but print result to stderr.
19073 usage: (trace-to-stderr STRING &rest OBJECTS) */)
19074 (ptrdiff_t nargs
, Lisp_Object
*args
)
19076 Lisp_Object s
= Fformat (nargs
, args
);
19077 fwrite (SDATA (s
), 1, SBYTES (s
), stderr
);
19081 #endif /* GLYPH_DEBUG */
19085 /***********************************************************************
19086 Building Desired Matrix Rows
19087 ***********************************************************************/
19089 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
19090 Used for non-window-redisplay windows, and for windows w/o left fringe. */
19092 static struct glyph_row
*
19093 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
19095 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
19096 struct buffer
*buffer
= XBUFFER (w
->contents
);
19097 struct buffer
*old
= current_buffer
;
19098 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
19099 ptrdiff_t arrow_len
= SCHARS (overlay_arrow_string
);
19100 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
19101 const unsigned char *p
;
19104 int n_glyphs_before
;
19106 set_buffer_temp (buffer
);
19107 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
19108 scratch_glyph_row
.reversed_p
= false;
19109 it
.glyph_row
->used
[TEXT_AREA
] = 0;
19110 SET_TEXT_POS (it
.position
, 0, 0);
19112 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
19114 while (p
< arrow_end
)
19116 Lisp_Object face
, ilisp
;
19118 /* Get the next character. */
19120 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
19123 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
19124 if (! ASCII_CHAR_P (it
.c
))
19125 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
19129 /* Get its face. */
19130 ilisp
= make_number (p
- arrow_string
);
19131 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
19132 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
19134 /* Compute its width, get its glyphs. */
19135 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
19136 SET_TEXT_POS (it
.position
, -1, -1);
19137 PRODUCE_GLYPHS (&it
);
19139 /* If this character doesn't fit any more in the line, we have
19140 to remove some glyphs. */
19141 if (it
.current_x
> it
.last_visible_x
)
19143 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
19148 set_buffer_temp (old
);
19149 return it
.glyph_row
;
19153 /* Insert truncation glyphs at the start of IT->glyph_row. Which
19154 glyphs to insert is determined by produce_special_glyphs. */
19157 insert_left_trunc_glyphs (struct it
*it
)
19159 struct it truncate_it
;
19160 struct glyph
*from
, *end
, *to
, *toend
;
19162 eassert (!FRAME_WINDOW_P (it
->f
)
19163 || (!it
->glyph_row
->reversed_p
19164 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19165 || (it
->glyph_row
->reversed_p
19166 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
19168 /* Get the truncation glyphs. */
19170 truncate_it
.current_x
= 0;
19171 truncate_it
.face_id
= DEFAULT_FACE_ID
;
19172 truncate_it
.glyph_row
= &scratch_glyph_row
;
19173 truncate_it
.area
= TEXT_AREA
;
19174 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
19175 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
19176 truncate_it
.object
= Qnil
;
19177 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
19179 /* Overwrite glyphs from IT with truncation glyphs. */
19180 if (!it
->glyph_row
->reversed_p
)
19182 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
19184 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19185 end
= from
+ tused
;
19186 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19187 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
19188 if (FRAME_WINDOW_P (it
->f
))
19190 /* On GUI frames, when variable-size fonts are displayed,
19191 the truncation glyphs may need more pixels than the row's
19192 glyphs they overwrite. We overwrite more glyphs to free
19193 enough screen real estate, and enlarge the stretch glyph
19194 on the right (see display_line), if there is one, to
19195 preserve the screen position of the truncation glyphs on
19198 struct glyph
*g
= to
;
19201 /* The first glyph could be partially visible, in which case
19202 it->glyph_row->x will be negative. But we want the left
19203 truncation glyphs to be aligned at the left margin of the
19204 window, so we override the x coordinate at which the row
19206 it
->glyph_row
->x
= 0;
19207 while (g
< toend
&& w
< it
->truncation_pixel_width
)
19209 w
+= g
->pixel_width
;
19212 if (g
- to
- tused
> 0)
19214 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
19215 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
19217 used
= it
->glyph_row
->used
[TEXT_AREA
];
19218 if (it
->glyph_row
->truncated_on_right_p
19219 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
19220 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
19223 int extra
= w
- it
->truncation_pixel_width
;
19225 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
19232 /* There may be padding glyphs left over. Overwrite them too. */
19233 if (!FRAME_WINDOW_P (it
->f
))
19235 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
19237 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19244 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
19248 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
19250 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
19251 that back to front. */
19252 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
19253 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19254 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19255 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19256 if (FRAME_WINDOW_P (it
->f
))
19259 struct glyph
*g
= to
;
19261 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
19263 w
+= g
->pixel_width
;
19266 if (to
- g
- tused
> 0)
19268 if (it
->glyph_row
->truncated_on_right_p
19269 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
19270 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
19272 int extra
= w
- it
->truncation_pixel_width
;
19274 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
19278 while (from
>= end
&& to
>= toend
)
19280 if (!FRAME_WINDOW_P (it
->f
))
19282 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
19285 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
19286 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19287 while (from
>= end
&& to
>= toend
)
19293 /* Need to free some room before prepending additional
19295 int move_by
= from
- end
+ 1;
19296 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19297 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19299 for ( ; g
>= g0
; g
--)
19301 while (from
>= end
)
19303 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
19308 /* Compute the hash code for ROW. */
19310 row_hash (struct glyph_row
*row
)
19313 unsigned hashval
= 0;
19315 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
19316 for (k
= 0; k
< row
->used
[area
]; ++k
)
19317 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
19318 + row
->glyphs
[area
][k
].u
.val
19319 + row
->glyphs
[area
][k
].face_id
19320 + row
->glyphs
[area
][k
].padding_p
19321 + (row
->glyphs
[area
][k
].type
<< 2));
19326 /* Compute the pixel height and width of IT->glyph_row.
19328 Most of the time, ascent and height of a display line will be equal
19329 to the max_ascent and max_height values of the display iterator
19330 structure. This is not the case if
19332 1. We hit ZV without displaying anything. In this case, max_ascent
19333 and max_height will be zero.
19335 2. We have some glyphs that don't contribute to the line height.
19336 (The glyph row flag contributes_to_line_height_p is for future
19337 pixmap extensions).
19339 The first case is easily covered by using default values because in
19340 these cases, the line height does not really matter, except that it
19341 must not be zero. */
19344 compute_line_metrics (struct it
*it
)
19346 struct glyph_row
*row
= it
->glyph_row
;
19348 if (FRAME_WINDOW_P (it
->f
))
19350 int i
, min_y
, max_y
;
19352 /* The line may consist of one space only, that was added to
19353 place the cursor on it. If so, the row's height hasn't been
19355 if (row
->height
== 0)
19357 if (it
->max_ascent
+ it
->max_descent
== 0)
19358 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
19359 row
->ascent
= it
->max_ascent
;
19360 row
->height
= it
->max_ascent
+ it
->max_descent
;
19361 row
->phys_ascent
= it
->max_phys_ascent
;
19362 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19363 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19366 /* Compute the width of this line. */
19367 row
->pixel_width
= row
->x
;
19368 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
19369 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
19371 eassert (row
->pixel_width
>= 0);
19372 eassert (row
->ascent
>= 0 && row
->height
> 0);
19374 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
19375 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
19377 /* If first line's physical ascent is larger than its logical
19378 ascent, use the physical ascent, and make the row taller.
19379 This makes accented characters fully visible. */
19380 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
19381 && row
->phys_ascent
> row
->ascent
)
19383 row
->height
+= row
->phys_ascent
- row
->ascent
;
19384 row
->ascent
= row
->phys_ascent
;
19387 /* Compute how much of the line is visible. */
19388 row
->visible_height
= row
->height
;
19390 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
19391 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
19393 if (row
->y
< min_y
)
19394 row
->visible_height
-= min_y
- row
->y
;
19395 if (row
->y
+ row
->height
> max_y
)
19396 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
19400 row
->pixel_width
= row
->used
[TEXT_AREA
];
19401 if (row
->continued_p
)
19402 row
->pixel_width
-= it
->continuation_pixel_width
;
19403 else if (row
->truncated_on_right_p
)
19404 row
->pixel_width
-= it
->truncation_pixel_width
;
19405 row
->ascent
= row
->phys_ascent
= 0;
19406 row
->height
= row
->phys_height
= row
->visible_height
= 1;
19407 row
->extra_line_spacing
= 0;
19410 /* Compute a hash code for this row. */
19411 row
->hash
= row_hash (row
);
19413 it
->max_ascent
= it
->max_descent
= 0;
19414 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
19418 /* Append one space to the glyph row of iterator IT if doing a
19419 window-based redisplay. The space has the same face as
19420 IT->face_id. Value is true if a space was added.
19422 This function is called to make sure that there is always one glyph
19423 at the end of a glyph row that the cursor can be set on under
19424 window-systems. (If there weren't such a glyph we would not know
19425 how wide and tall a box cursor should be displayed).
19427 At the same time this space let's a nicely handle clearing to the
19428 end of the line if the row ends in italic text. */
19431 append_space_for_newline (struct it
*it
, bool default_face_p
)
19433 if (FRAME_WINDOW_P (it
->f
))
19435 int n
= it
->glyph_row
->used
[TEXT_AREA
];
19437 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
19438 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
19440 /* Save some values that must not be changed.
19441 Must save IT->c and IT->len because otherwise
19442 ITERATOR_AT_END_P wouldn't work anymore after
19443 append_space_for_newline has been called. */
19444 enum display_element_type saved_what
= it
->what
;
19445 int saved_c
= it
->c
, saved_len
= it
->len
;
19446 int saved_char_to_display
= it
->char_to_display
;
19447 int saved_x
= it
->current_x
;
19448 int saved_face_id
= it
->face_id
;
19449 bool saved_box_end
= it
->end_of_box_run_p
;
19450 struct text_pos saved_pos
;
19451 Lisp_Object saved_object
;
19455 saved_object
= it
->object
;
19456 saved_pos
= it
->position
;
19458 it
->what
= IT_CHARACTER
;
19459 memset (&it
->position
, 0, sizeof it
->position
);
19461 it
->c
= it
->char_to_display
= ' ';
19464 /* If the default face was remapped, be sure to use the
19465 remapped face for the appended newline. */
19466 if (default_face_p
)
19467 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
19468 else if (it
->face_before_selective_p
)
19469 it
->face_id
= it
->saved_face_id
;
19470 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19471 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
19472 /* In R2L rows, we will prepend a stretch glyph that will
19473 have the end_of_box_run_p flag set for it, so there's no
19474 need for the appended newline glyph to have that flag
19476 if (it
->glyph_row
->reversed_p
19477 /* But if the appended newline glyph goes all the way to
19478 the end of the row, there will be no stretch glyph,
19479 so leave the box flag set. */
19480 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
19481 it
->end_of_box_run_p
= false;
19483 PRODUCE_GLYPHS (it
);
19485 #ifdef HAVE_WINDOW_SYSTEM
19486 /* Make sure this space glyph has the right ascent and
19487 descent values, or else cursor at end of line will look
19488 funny, and height of empty lines will be incorrect. */
19489 g
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19490 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
19493 Lisp_Object height
, total_height
;
19494 int extra_line_spacing
= it
->extra_line_spacing
;
19495 int boff
= font
->baseline_offset
;
19497 if (font
->vertical_centering
)
19498 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
19500 it
->object
= saved_object
; /* get_it_property needs this */
19501 normal_char_ascent_descent (font
, -1, &it
->ascent
, &it
->descent
);
19502 /* Must do a subset of line height processing from
19503 x_produce_glyph for newline characters. */
19504 height
= get_it_property (it
, Qline_height
);
19506 && CONSP (XCDR (height
))
19507 && NILP (XCDR (XCDR (height
))))
19509 total_height
= XCAR (XCDR (height
));
19510 height
= XCAR (height
);
19513 total_height
= Qnil
;
19514 height
= calc_line_height_property (it
, height
, font
, boff
, true);
19516 if (it
->override_ascent
>= 0)
19518 it
->ascent
= it
->override_ascent
;
19519 it
->descent
= it
->override_descent
;
19520 boff
= it
->override_boff
;
19522 if (EQ (height
, Qt
))
19523 extra_line_spacing
= 0;
19526 Lisp_Object spacing
;
19528 it
->phys_ascent
= it
->ascent
;
19529 it
->phys_descent
= it
->descent
;
19531 && XINT (height
) > it
->ascent
+ it
->descent
)
19532 it
->ascent
= XINT (height
) - it
->descent
;
19534 if (!NILP (total_height
))
19535 spacing
= calc_line_height_property (it
, total_height
, font
,
19539 spacing
= get_it_property (it
, Qline_spacing
);
19540 spacing
= calc_line_height_property (it
, spacing
, font
,
19543 if (INTEGERP (spacing
))
19545 extra_line_spacing
= XINT (spacing
);
19546 if (!NILP (total_height
))
19547 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
19550 if (extra_line_spacing
> 0)
19552 it
->descent
+= extra_line_spacing
;
19553 if (extra_line_spacing
> it
->max_extra_line_spacing
)
19554 it
->max_extra_line_spacing
= extra_line_spacing
;
19556 it
->max_ascent
= it
->ascent
;
19557 it
->max_descent
= it
->descent
;
19558 /* Make sure compute_line_metrics recomputes the row height. */
19559 it
->glyph_row
->height
= 0;
19562 g
->ascent
= it
->max_ascent
;
19563 g
->descent
= it
->max_descent
;
19566 it
->override_ascent
= -1;
19567 it
->constrain_row_ascent_descent_p
= false;
19568 it
->current_x
= saved_x
;
19569 it
->object
= saved_object
;
19570 it
->position
= saved_pos
;
19571 it
->what
= saved_what
;
19572 it
->face_id
= saved_face_id
;
19573 it
->len
= saved_len
;
19575 it
->char_to_display
= saved_char_to_display
;
19576 it
->end_of_box_run_p
= saved_box_end
;
19585 /* Extend the face of the last glyph in the text area of IT->glyph_row
19586 to the end of the display line. Called from display_line. If the
19587 glyph row is empty, add a space glyph to it so that we know the
19588 face to draw. Set the glyph row flag fill_line_p. If the glyph
19589 row is R2L, prepend a stretch glyph to cover the empty space to the
19590 left of the leftmost glyph. */
19593 extend_face_to_end_of_line (struct it
*it
)
19595 struct face
*face
, *default_face
;
19596 struct frame
*f
= it
->f
;
19598 /* If line is already filled, do nothing. Non window-system frames
19599 get a grace of one more ``pixel'' because their characters are
19600 1-``pixel'' wide, so they hit the equality too early. This grace
19601 is needed only for R2L rows that are not continued, to produce
19602 one extra blank where we could display the cursor. */
19603 if ((it
->current_x
>= it
->last_visible_x
19604 + (!FRAME_WINDOW_P (f
)
19605 && it
->glyph_row
->reversed_p
19606 && !it
->glyph_row
->continued_p
))
19607 /* If the window has display margins, we will need to extend
19608 their face even if the text area is filled. */
19609 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19610 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
19613 /* The default face, possibly remapped. */
19614 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
19616 /* Face extension extends the background and box of IT->face_id
19617 to the end of the line. If the background equals the background
19618 of the frame, we don't have to do anything. */
19619 if (it
->face_before_selective_p
)
19620 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
19622 face
= FACE_FROM_ID (f
, it
->face_id
);
19624 if (FRAME_WINDOW_P (f
)
19625 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
19626 && face
->box
== FACE_NO_BOX
19627 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
19628 #ifdef HAVE_WINDOW_SYSTEM
19631 && !it
->glyph_row
->reversed_p
)
19634 /* Set the glyph row flag indicating that the face of the last glyph
19635 in the text area has to be drawn to the end of the text area. */
19636 it
->glyph_row
->fill_line_p
= true;
19638 /* If current character of IT is not ASCII, make sure we have the
19639 ASCII face. This will be automatically undone the next time
19640 get_next_display_element returns a multibyte character. Note
19641 that the character will always be single byte in unibyte
19643 if (!ASCII_CHAR_P (it
->c
))
19645 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
19648 if (FRAME_WINDOW_P (f
))
19650 /* If the row is empty, add a space with the current face of IT,
19651 so that we know which face to draw. */
19652 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
19654 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
19655 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
19656 it
->glyph_row
->used
[TEXT_AREA
] = 1;
19658 /* Mode line and the header line don't have margins, and
19659 likewise the frame's tool-bar window, if there is any. */
19660 if (!(it
->glyph_row
->mode_line_p
19661 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19662 || (WINDOWP (f
->tool_bar_window
)
19663 && it
->w
== XWINDOW (f
->tool_bar_window
))
19667 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19668 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
19670 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
19671 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
=
19673 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
19675 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19676 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
19678 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
19679 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
=
19681 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
19684 #ifdef HAVE_WINDOW_SYSTEM
19685 if (it
->glyph_row
->reversed_p
)
19687 /* Prepend a stretch glyph to the row, such that the
19688 rightmost glyph will be drawn flushed all the way to the
19689 right margin of the window. The stretch glyph that will
19690 occupy the empty space, if any, to the left of the
19692 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
19693 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19694 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
19696 int row_width
, stretch_ascent
, stretch_width
;
19697 struct text_pos saved_pos
;
19699 bool saved_avoid_cursor
, saved_box_start
;
19701 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
19702 row_width
+= g
->pixel_width
;
19704 /* FIXME: There are various minor display glitches in R2L
19705 rows when only one of the fringes is missing. The
19706 strange condition below produces the least bad effect. */
19707 if ((WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19708 == (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
19709 || WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
19710 stretch_width
= window_box_width (it
->w
, TEXT_AREA
);
19712 stretch_width
= it
->last_visible_x
- it
->first_visible_x
;
19713 stretch_width
-= row_width
;
19715 if (stretch_width
> 0)
19718 (((it
->ascent
+ it
->descent
)
19719 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
19720 saved_pos
= it
->position
;
19721 memset (&it
->position
, 0, sizeof it
->position
);
19722 saved_avoid_cursor
= it
->avoid_cursor_p
;
19723 it
->avoid_cursor_p
= true;
19724 saved_face_id
= it
->face_id
;
19725 saved_box_start
= it
->start_of_box_run_p
;
19726 /* The last row's stretch glyph should get the default
19727 face, to avoid painting the rest of the window with
19728 the region face, if the region ends at ZV. */
19729 if (it
->glyph_row
->ends_at_zv_p
)
19730 it
->face_id
= default_face
->id
;
19732 it
->face_id
= face
->id
;
19733 it
->start_of_box_run_p
= false;
19734 append_stretch_glyph (it
, Qnil
, stretch_width
,
19735 it
->ascent
+ it
->descent
, stretch_ascent
);
19736 it
->position
= saved_pos
;
19737 it
->avoid_cursor_p
= saved_avoid_cursor
;
19738 it
->face_id
= saved_face_id
;
19739 it
->start_of_box_run_p
= saved_box_start
;
19741 /* If stretch_width comes out negative, it means that the
19742 last glyph is only partially visible. In R2L rows, we
19743 want the leftmost glyph to be partially visible, so we
19744 need to give the row the corresponding left offset. */
19745 if (stretch_width
< 0)
19746 it
->glyph_row
->x
= stretch_width
;
19748 #endif /* HAVE_WINDOW_SYSTEM */
19752 /* Save some values that must not be changed. */
19753 int saved_x
= it
->current_x
;
19754 struct text_pos saved_pos
;
19755 Lisp_Object saved_object
;
19756 enum display_element_type saved_what
= it
->what
;
19757 int saved_face_id
= it
->face_id
;
19759 saved_object
= it
->object
;
19760 saved_pos
= it
->position
;
19762 it
->what
= IT_CHARACTER
;
19763 memset (&it
->position
, 0, sizeof it
->position
);
19765 it
->c
= it
->char_to_display
= ' ';
19768 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19769 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19770 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19771 && !it
->glyph_row
->mode_line_p
19772 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19774 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
19775 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
19777 for (it
->current_x
= 0; g
< e
; g
++)
19778 it
->current_x
+= g
->pixel_width
;
19780 it
->area
= LEFT_MARGIN_AREA
;
19781 it
->face_id
= default_face
->id
;
19782 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19783 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19785 PRODUCE_GLYPHS (it
);
19786 /* term.c:produce_glyphs advances it->current_x only for
19788 it
->current_x
+= it
->pixel_width
;
19791 it
->current_x
= saved_x
;
19792 it
->area
= TEXT_AREA
;
19795 /* The last row's blank glyphs should get the default face, to
19796 avoid painting the rest of the window with the region face,
19797 if the region ends at ZV. */
19798 if (it
->glyph_row
->ends_at_zv_p
)
19799 it
->face_id
= default_face
->id
;
19801 it
->face_id
= face
->id
;
19802 PRODUCE_GLYPHS (it
);
19804 while (it
->current_x
<= it
->last_visible_x
)
19805 PRODUCE_GLYPHS (it
);
19807 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19808 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19809 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19810 && !it
->glyph_row
->mode_line_p
19811 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19813 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
19814 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19816 for ( ; g
< e
; g
++)
19817 it
->current_x
+= g
->pixel_width
;
19819 it
->area
= RIGHT_MARGIN_AREA
;
19820 it
->face_id
= default_face
->id
;
19821 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19822 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19824 PRODUCE_GLYPHS (it
);
19825 it
->current_x
+= it
->pixel_width
;
19828 it
->area
= TEXT_AREA
;
19831 /* Don't count these blanks really. It would let us insert a left
19832 truncation glyph below and make us set the cursor on them, maybe. */
19833 it
->current_x
= saved_x
;
19834 it
->object
= saved_object
;
19835 it
->position
= saved_pos
;
19836 it
->what
= saved_what
;
19837 it
->face_id
= saved_face_id
;
19842 /* Value is true if text starting at CHARPOS in current_buffer is
19843 trailing whitespace. */
19846 trailing_whitespace_p (ptrdiff_t charpos
)
19848 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19851 while (bytepos
< ZV_BYTE
19852 && (c
= FETCH_CHAR (bytepos
),
19853 c
== ' ' || c
== '\t'))
19856 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19858 if (bytepos
!= PT_BYTE
)
19865 /* Highlight trailing whitespace, if any, in ROW. */
19868 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19870 int used
= row
->used
[TEXT_AREA
];
19874 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19875 struct glyph
*glyph
= start
+ used
- 1;
19877 if (row
->reversed_p
)
19879 /* Right-to-left rows need to be processed in the opposite
19880 direction, so swap the edge pointers. */
19882 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19885 /* Skip over glyphs inserted to display the cursor at the
19886 end of a line, for extending the face of the last glyph
19887 to the end of the line on terminals, and for truncation
19888 and continuation glyphs. */
19889 if (!row
->reversed_p
)
19891 while (glyph
>= start
19892 && glyph
->type
== CHAR_GLYPH
19893 && NILP (glyph
->object
))
19898 while (glyph
<= start
19899 && glyph
->type
== CHAR_GLYPH
19900 && NILP (glyph
->object
))
19904 /* If last glyph is a space or stretch, and it's trailing
19905 whitespace, set the face of all trailing whitespace glyphs in
19906 IT->glyph_row to `trailing-whitespace'. */
19907 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19908 && BUFFERP (glyph
->object
)
19909 && (glyph
->type
== STRETCH_GLYPH
19910 || (glyph
->type
== CHAR_GLYPH
19911 && glyph
->u
.ch
== ' '))
19912 && trailing_whitespace_p (glyph
->charpos
))
19914 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, false);
19918 if (!row
->reversed_p
)
19920 while (glyph
>= start
19921 && BUFFERP (glyph
->object
)
19922 && (glyph
->type
== STRETCH_GLYPH
19923 || (glyph
->type
== CHAR_GLYPH
19924 && glyph
->u
.ch
== ' ')))
19925 (glyph
--)->face_id
= face_id
;
19929 while (glyph
<= start
19930 && BUFFERP (glyph
->object
)
19931 && (glyph
->type
== STRETCH_GLYPH
19932 || (glyph
->type
== CHAR_GLYPH
19933 && glyph
->u
.ch
== ' ')))
19934 (glyph
++)->face_id
= face_id
;
19941 /* Value is true if glyph row ROW should be
19942 considered to hold the buffer position CHARPOS. */
19945 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19947 bool result
= true;
19949 if (charpos
== CHARPOS (row
->end
.pos
)
19950 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19952 /* Suppose the row ends on a string.
19953 Unless the row is continued, that means it ends on a newline
19954 in the string. If it's anything other than a display string
19955 (e.g., a before-string from an overlay), we don't want the
19956 cursor there. (This heuristic seems to give the optimal
19957 behavior for the various types of multi-line strings.)
19958 One exception: if the string has `cursor' property on one of
19959 its characters, we _do_ want the cursor there. */
19960 if (CHARPOS (row
->end
.string_pos
) >= 0)
19962 if (row
->continued_p
)
19966 /* Check for `display' property. */
19967 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19968 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19969 struct glyph
*glyph
;
19972 for (glyph
= end
; glyph
>= beg
; --glyph
)
19973 if (STRINGP (glyph
->object
))
19976 = Fget_char_property (make_number (charpos
),
19980 && display_prop_string_p (prop
, glyph
->object
));
19981 /* If there's a `cursor' property on one of the
19982 string's characters, this row is a cursor row,
19983 even though this is not a display string. */
19986 Lisp_Object s
= glyph
->object
;
19988 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19990 ptrdiff_t gpos
= glyph
->charpos
;
19992 if (!NILP (Fget_char_property (make_number (gpos
),
20004 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
20006 /* If the row ends in middle of a real character,
20007 and the line is continued, we want the cursor here.
20008 That's because CHARPOS (ROW->end.pos) would equal
20009 PT if PT is before the character. */
20010 if (!row
->ends_in_ellipsis_p
)
20011 result
= row
->continued_p
;
20013 /* If the row ends in an ellipsis, then
20014 CHARPOS (ROW->end.pos) will equal point after the
20015 invisible text. We want that position to be displayed
20016 after the ellipsis. */
20019 /* If the row ends at ZV, display the cursor at the end of that
20020 row instead of at the start of the row below. */
20022 result
= row
->ends_at_zv_p
;
20028 /* Value is true if glyph row ROW should be
20029 used to hold the cursor. */
20032 cursor_row_p (struct glyph_row
*row
)
20034 return row_for_charpos_p (row
, PT
);
20039 /* Push the property PROP so that it will be rendered at the current
20040 position in IT. Return true if PROP was successfully pushed, false
20041 otherwise. Called from handle_line_prefix to handle the
20042 `line-prefix' and `wrap-prefix' properties. */
20045 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
20047 struct text_pos pos
=
20048 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
20050 eassert (it
->method
== GET_FROM_BUFFER
20051 || it
->method
== GET_FROM_DISPLAY_VECTOR
20052 || it
->method
== GET_FROM_STRING
20053 || it
->method
== GET_FROM_IMAGE
);
20055 /* We need to save the current buffer/string position, so it will be
20056 restored by pop_it, because iterate_out_of_display_property
20057 depends on that being set correctly, but some situations leave
20058 it->position not yet set when this function is called. */
20059 push_it (it
, &pos
);
20061 if (STRINGP (prop
))
20063 if (SCHARS (prop
) == 0)
20070 it
->string_from_prefix_prop_p
= true;
20071 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
20072 it
->current
.overlay_string_index
= -1;
20073 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
20074 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
20075 it
->method
= GET_FROM_STRING
;
20076 it
->stop_charpos
= 0;
20078 it
->base_level_stop
= 0;
20080 /* Force paragraph direction to be that of the parent
20082 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
20083 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
20085 it
->paragraph_embedding
= L2R
;
20087 /* Set up the bidi iterator for this display string. */
20090 it
->bidi_it
.string
.lstring
= it
->string
;
20091 it
->bidi_it
.string
.s
= NULL
;
20092 it
->bidi_it
.string
.schars
= it
->end_charpos
;
20093 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
20094 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
20095 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
20096 it
->bidi_it
.w
= it
->w
;
20097 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
20100 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
20102 it
->method
= GET_FROM_STRETCH
;
20105 #ifdef HAVE_WINDOW_SYSTEM
20106 else if (IMAGEP (prop
))
20108 it
->what
= IT_IMAGE
;
20109 it
->image_id
= lookup_image (it
->f
, prop
);
20110 it
->method
= GET_FROM_IMAGE
;
20112 #endif /* HAVE_WINDOW_SYSTEM */
20115 pop_it (it
); /* bogus display property, give up */
20122 /* Return the character-property PROP at the current position in IT. */
20125 get_it_property (struct it
*it
, Lisp_Object prop
)
20127 Lisp_Object position
, object
= it
->object
;
20129 if (STRINGP (object
))
20130 position
= make_number (IT_STRING_CHARPOS (*it
));
20131 else if (BUFFERP (object
))
20133 position
= make_number (IT_CHARPOS (*it
));
20134 object
= it
->window
;
20139 return Fget_char_property (position
, prop
, object
);
20142 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
20145 handle_line_prefix (struct it
*it
)
20147 Lisp_Object prefix
;
20149 if (it
->continuation_lines_width
> 0)
20151 prefix
= get_it_property (it
, Qwrap_prefix
);
20153 prefix
= Vwrap_prefix
;
20157 prefix
= get_it_property (it
, Qline_prefix
);
20159 prefix
= Vline_prefix
;
20161 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
20163 /* If the prefix is wider than the window, and we try to wrap
20164 it, it would acquire its own wrap prefix, and so on till the
20165 iterator stack overflows. So, don't wrap the prefix. */
20166 it
->line_wrap
= TRUNCATE
;
20167 it
->avoid_cursor_p
= true;
20173 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
20174 only for R2L lines from display_line and display_string, when they
20175 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
20176 the line/string needs to be continued on the next glyph row. */
20178 unproduce_glyphs (struct it
*it
, int n
)
20180 struct glyph
*glyph
, *end
;
20182 eassert (it
->glyph_row
);
20183 eassert (it
->glyph_row
->reversed_p
);
20184 eassert (it
->area
== TEXT_AREA
);
20185 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
20187 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
20188 n
= it
->glyph_row
->used
[TEXT_AREA
];
20189 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
20190 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
20191 for ( ; glyph
< end
; glyph
++)
20192 glyph
[-n
] = *glyph
;
20195 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
20196 and ROW->maxpos. */
20198 find_row_edges (struct it
*it
, struct glyph_row
*row
,
20199 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
20200 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
20202 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20203 lines' rows is implemented for bidi-reordered rows. */
20205 /* ROW->minpos is the value of min_pos, the minimal buffer position
20206 we have in ROW, or ROW->start.pos if that is smaller. */
20207 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
20208 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
20210 /* We didn't find buffer positions smaller than ROW->start, or
20211 didn't find _any_ valid buffer positions in any of the glyphs,
20212 so we must trust the iterator's computed positions. */
20213 row
->minpos
= row
->start
.pos
;
20216 max_pos
= CHARPOS (it
->current
.pos
);
20217 max_bpos
= BYTEPOS (it
->current
.pos
);
20220 /* Here are the various use-cases for ending the row, and the
20221 corresponding values for ROW->maxpos:
20223 Line ends in a newline from buffer eol_pos + 1
20224 Line is continued from buffer max_pos + 1
20225 Line is truncated on right it->current.pos
20226 Line ends in a newline from string max_pos + 1(*)
20227 (*) + 1 only when line ends in a forward scan
20228 Line is continued from string max_pos
20229 Line is continued from display vector max_pos
20230 Line is entirely from a string min_pos == max_pos
20231 Line is entirely from a display vector min_pos == max_pos
20232 Line that ends at ZV ZV
20234 If you discover other use-cases, please add them here as
20236 if (row
->ends_at_zv_p
)
20237 row
->maxpos
= it
->current
.pos
;
20238 else if (row
->used
[TEXT_AREA
])
20240 bool seen_this_string
= false;
20241 struct glyph_row
*r1
= row
- 1;
20243 /* Did we see the same display string on the previous row? */
20244 if (STRINGP (it
->object
)
20245 /* this is not the first row */
20246 && row
> it
->w
->desired_matrix
->rows
20247 /* previous row is not the header line */
20248 && !r1
->mode_line_p
20249 /* previous row also ends in a newline from a string */
20250 && r1
->ends_in_newline_from_string_p
)
20252 struct glyph
*start
, *end
;
20254 /* Search for the last glyph of the previous row that came
20255 from buffer or string. Depending on whether the row is
20256 L2R or R2L, we need to process it front to back or the
20257 other way round. */
20258 if (!r1
->reversed_p
)
20260 start
= r1
->glyphs
[TEXT_AREA
];
20261 end
= start
+ r1
->used
[TEXT_AREA
];
20262 /* Glyphs inserted by redisplay have nil as their object. */
20264 && NILP ((end
- 1)->object
)
20265 && (end
- 1)->charpos
<= 0)
20269 if (EQ ((end
- 1)->object
, it
->object
))
20270 seen_this_string
= true;
20273 /* If all the glyphs of the previous row were inserted
20274 by redisplay, it means the previous row was
20275 produced from a single newline, which is only
20276 possible if that newline came from the same string
20277 as the one which produced this ROW. */
20278 seen_this_string
= true;
20282 end
= r1
->glyphs
[TEXT_AREA
] - 1;
20283 start
= end
+ r1
->used
[TEXT_AREA
];
20285 && NILP ((end
+ 1)->object
)
20286 && (end
+ 1)->charpos
<= 0)
20290 if (EQ ((end
+ 1)->object
, it
->object
))
20291 seen_this_string
= true;
20294 seen_this_string
= true;
20297 /* Take note of each display string that covers a newline only
20298 once, the first time we see it. This is for when a display
20299 string includes more than one newline in it. */
20300 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
20302 /* If we were scanning the buffer forward when we displayed
20303 the string, we want to account for at least one buffer
20304 position that belongs to this row (position covered by
20305 the display string), so that cursor positioning will
20306 consider this row as a candidate when point is at the end
20307 of the visual line represented by this row. This is not
20308 required when scanning back, because max_pos will already
20309 have a much larger value. */
20310 if (CHARPOS (row
->end
.pos
) > max_pos
)
20311 INC_BOTH (max_pos
, max_bpos
);
20312 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20314 else if (CHARPOS (it
->eol_pos
) > 0)
20315 SET_TEXT_POS (row
->maxpos
,
20316 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
20317 else if (row
->continued_p
)
20319 /* If max_pos is different from IT's current position, it
20320 means IT->method does not belong to the display element
20321 at max_pos. However, it also means that the display
20322 element at max_pos was displayed in its entirety on this
20323 line, which is equivalent to saying that the next line
20324 starts at the next buffer position. */
20325 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
20326 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20329 INC_BOTH (max_pos
, max_bpos
);
20330 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
20333 else if (row
->truncated_on_right_p
)
20334 /* display_line already called reseat_at_next_visible_line_start,
20335 which puts the iterator at the beginning of the next line, in
20336 the logical order. */
20337 row
->maxpos
= it
->current
.pos
;
20338 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
20339 /* A line that is entirely from a string/image/stretch... */
20340 row
->maxpos
= row
->minpos
;
20345 row
->maxpos
= it
->current
.pos
;
20348 /* Construct the glyph row IT->glyph_row in the desired matrix of
20349 IT->w from text at the current position of IT. See dispextern.h
20350 for an overview of struct it. Value is true if
20351 IT->glyph_row displays text, as opposed to a line displaying ZV
20355 display_line (struct it
*it
)
20357 struct glyph_row
*row
= it
->glyph_row
;
20358 Lisp_Object overlay_arrow_string
;
20360 void *wrap_data
= NULL
;
20361 bool may_wrap
= false;
20362 int wrap_x
IF_LINT (= 0);
20363 int wrap_row_used
= -1;
20364 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
20365 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
20366 int wrap_row_extra_line_spacing
IF_LINT (= 0);
20367 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
20368 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
20370 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
20371 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
20372 bool pending_handle_line_prefix
= false;
20374 /* We always start displaying at hpos zero even if hscrolled. */
20375 eassert (it
->hpos
== 0 && it
->current_x
== 0);
20377 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
20378 >= it
->w
->desired_matrix
->nrows
)
20380 it
->w
->nrows_scale_factor
++;
20381 it
->f
->fonts_changed
= true;
20385 /* Clear the result glyph row and enable it. */
20386 prepare_desired_row (it
->w
, row
, false);
20388 row
->y
= it
->current_y
;
20389 row
->start
= it
->start
;
20390 row
->continuation_lines_width
= it
->continuation_lines_width
;
20391 row
->displays_text_p
= true;
20392 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
20393 it
->starts_in_middle_of_char_p
= false;
20395 /* Arrange the overlays nicely for our purposes. Usually, we call
20396 display_line on only one line at a time, in which case this
20397 can't really hurt too much, or we call it on lines which appear
20398 one after another in the buffer, in which case all calls to
20399 recenter_overlay_lists but the first will be pretty cheap. */
20400 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
20402 /* Move over display elements that are not visible because we are
20403 hscrolled. This may stop at an x-position < IT->first_visible_x
20404 if the first glyph is partially visible or if we hit a line end. */
20405 if (it
->current_x
< it
->first_visible_x
)
20407 enum move_it_result move_result
;
20409 this_line_min_pos
= row
->start
.pos
;
20410 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
20411 MOVE_TO_POS
| MOVE_TO_X
);
20412 /* If we are under a large hscroll, move_it_in_display_line_to
20413 could hit the end of the line without reaching
20414 it->first_visible_x. Pretend that we did reach it. This is
20415 especially important on a TTY, where we will call
20416 extend_face_to_end_of_line, which needs to know how many
20417 blank glyphs to produce. */
20418 if (it
->current_x
< it
->first_visible_x
20419 && (move_result
== MOVE_NEWLINE_OR_CR
20420 || move_result
== MOVE_POS_MATCH_OR_ZV
))
20421 it
->current_x
= it
->first_visible_x
;
20423 /* Record the smallest positions seen while we moved over
20424 display elements that are not visible. This is needed by
20425 redisplay_internal for optimizing the case where the cursor
20426 stays inside the same line. The rest of this function only
20427 considers positions that are actually displayed, so
20428 RECORD_MAX_MIN_POS will not otherwise record positions that
20429 are hscrolled to the left of the left edge of the window. */
20430 min_pos
= CHARPOS (this_line_min_pos
);
20431 min_bpos
= BYTEPOS (this_line_min_pos
);
20433 else if (it
->area
== TEXT_AREA
)
20435 /* We only do this when not calling move_it_in_display_line_to
20436 above, because that function calls itself handle_line_prefix. */
20437 handle_line_prefix (it
);
20441 /* Line-prefix and wrap-prefix are always displayed in the text
20442 area. But if this is the first call to display_line after
20443 init_iterator, the iterator might have been set up to write
20444 into a marginal area, e.g. if the line begins with some
20445 display property that writes to the margins. So we need to
20446 wait with the call to handle_line_prefix until whatever
20447 writes to the margin has done its job. */
20448 pending_handle_line_prefix
= true;
20451 /* Get the initial row height. This is either the height of the
20452 text hscrolled, if there is any, or zero. */
20453 row
->ascent
= it
->max_ascent
;
20454 row
->height
= it
->max_ascent
+ it
->max_descent
;
20455 row
->phys_ascent
= it
->max_phys_ascent
;
20456 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20457 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20459 /* Utility macro to record max and min buffer positions seen until now. */
20460 #define RECORD_MAX_MIN_POS(IT) \
20463 bool composition_p \
20464 = !STRINGP ((IT)->string) && ((IT)->what == IT_COMPOSITION); \
20465 ptrdiff_t current_pos = \
20466 composition_p ? (IT)->cmp_it.charpos \
20467 : IT_CHARPOS (*(IT)); \
20468 ptrdiff_t current_bpos = \
20469 composition_p ? CHAR_TO_BYTE (current_pos) \
20470 : IT_BYTEPOS (*(IT)); \
20471 if (current_pos < min_pos) \
20473 min_pos = current_pos; \
20474 min_bpos = current_bpos; \
20476 if (IT_CHARPOS (*it) > max_pos) \
20478 max_pos = IT_CHARPOS (*it); \
20479 max_bpos = IT_BYTEPOS (*it); \
20484 /* Loop generating characters. The loop is left with IT on the next
20485 character to display. */
20488 int n_glyphs_before
, hpos_before
, x_before
;
20490 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
20492 /* Retrieve the next thing to display. Value is false if end of
20494 if (!get_next_display_element (it
))
20496 /* Maybe add a space at the end of this line that is used to
20497 display the cursor there under X. Set the charpos of the
20498 first glyph of blank lines not corresponding to any text
20500 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20501 row
->exact_window_width_line_p
= true;
20502 else if ((append_space_for_newline (it
, true)
20503 && row
->used
[TEXT_AREA
] == 1)
20504 || row
->used
[TEXT_AREA
] == 0)
20506 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
20507 row
->displays_text_p
= false;
20509 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
20510 && (!MINI_WINDOW_P (it
->w
)
20511 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
20512 row
->indicate_empty_line_p
= true;
20515 it
->continuation_lines_width
= 0;
20516 row
->ends_at_zv_p
= true;
20517 /* A row that displays right-to-left text must always have
20518 its last face extended all the way to the end of line,
20519 even if this row ends in ZV, because we still write to
20520 the screen left to right. We also need to extend the
20521 last face if the default face is remapped to some
20522 different face, otherwise the functions that clear
20523 portions of the screen will clear with the default face's
20524 background color. */
20525 if (row
->reversed_p
20526 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
20527 extend_face_to_end_of_line (it
);
20531 /* Now, get the metrics of what we want to display. This also
20532 generates glyphs in `row' (which is IT->glyph_row). */
20533 n_glyphs_before
= row
->used
[TEXT_AREA
];
20536 /* Remember the line height so far in case the next element doesn't
20537 fit on the line. */
20538 if (it
->line_wrap
!= TRUNCATE
)
20540 ascent
= it
->max_ascent
;
20541 descent
= it
->max_descent
;
20542 phys_ascent
= it
->max_phys_ascent
;
20543 phys_descent
= it
->max_phys_descent
;
20545 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
20547 if (IT_DISPLAYING_WHITESPACE (it
))
20551 SAVE_IT (wrap_it
, *it
, wrap_data
);
20553 wrap_row_used
= row
->used
[TEXT_AREA
];
20554 wrap_row_ascent
= row
->ascent
;
20555 wrap_row_height
= row
->height
;
20556 wrap_row_phys_ascent
= row
->phys_ascent
;
20557 wrap_row_phys_height
= row
->phys_height
;
20558 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
20559 wrap_row_min_pos
= min_pos
;
20560 wrap_row_min_bpos
= min_bpos
;
20561 wrap_row_max_pos
= max_pos
;
20562 wrap_row_max_bpos
= max_bpos
;
20568 PRODUCE_GLYPHS (it
);
20570 /* If this display element was in marginal areas, continue with
20572 if (it
->area
!= TEXT_AREA
)
20574 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20575 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20576 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20577 row
->phys_height
= max (row
->phys_height
,
20578 it
->max_phys_ascent
+ it
->max_phys_descent
);
20579 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20580 it
->max_extra_line_spacing
);
20581 set_iterator_to_next (it
, true);
20582 /* If we didn't handle the line/wrap prefix above, and the
20583 call to set_iterator_to_next just switched to TEXT_AREA,
20584 process the prefix now. */
20585 if (it
->area
== TEXT_AREA
&& pending_handle_line_prefix
)
20587 pending_handle_line_prefix
= false;
20588 handle_line_prefix (it
);
20593 /* Does the display element fit on the line? If we truncate
20594 lines, we should draw past the right edge of the window. If
20595 we don't truncate, we want to stop so that we can display the
20596 continuation glyph before the right margin. If lines are
20597 continued, there are two possible strategies for characters
20598 resulting in more than 1 glyph (e.g. tabs): Display as many
20599 glyphs as possible in this line and leave the rest for the
20600 continuation line, or display the whole element in the next
20601 line. Original redisplay did the former, so we do it also. */
20602 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20603 hpos_before
= it
->hpos
;
20606 if (/* Not a newline. */
20608 /* Glyphs produced fit entirely in the line. */
20609 && it
->current_x
< it
->last_visible_x
)
20611 it
->hpos
+= nglyphs
;
20612 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20613 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20614 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20615 row
->phys_height
= max (row
->phys_height
,
20616 it
->max_phys_ascent
+ it
->max_phys_descent
);
20617 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20618 it
->max_extra_line_spacing
);
20619 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
20620 /* In R2L rows, we arrange in extend_face_to_end_of_line
20621 to add a right offset to the line, by a suitable
20622 change to the stretch glyph that is the leftmost
20623 glyph of the line. */
20624 && !row
->reversed_p
)
20625 row
->x
= x
- it
->first_visible_x
;
20626 /* Record the maximum and minimum buffer positions seen so
20627 far in glyphs that will be displayed by this row. */
20629 RECORD_MAX_MIN_POS (it
);
20634 struct glyph
*glyph
;
20636 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
20638 /* Identify the glyphs added by the last call to
20639 PRODUCE_GLYPHS. In R2L rows, they are prepended to
20640 the previous glyphs. */
20641 if (!row
->reversed_p
)
20642 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20644 glyph
= row
->glyphs
[TEXT_AREA
] + nglyphs
- 1 - i
;
20645 new_x
= x
+ glyph
->pixel_width
;
20647 if (/* Lines are continued. */
20648 it
->line_wrap
!= TRUNCATE
20649 && (/* Glyph doesn't fit on the line. */
20650 new_x
> it
->last_visible_x
20651 /* Or it fits exactly on a window system frame. */
20652 || (new_x
== it
->last_visible_x
20653 && FRAME_WINDOW_P (it
->f
)
20654 && (row
->reversed_p
20655 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20656 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
20658 /* End of a continued line. */
20661 || (new_x
== it
->last_visible_x
20662 && FRAME_WINDOW_P (it
->f
)
20663 && (row
->reversed_p
20664 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20665 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
20667 /* Current glyph is the only one on the line or
20668 fits exactly on the line. We must continue
20669 the line because we can't draw the cursor
20670 after the glyph. */
20671 row
->continued_p
= true;
20672 it
->current_x
= new_x
;
20673 it
->continuation_lines_width
+= new_x
;
20675 if (i
== nglyphs
- 1)
20677 /* If line-wrap is on, check if a previous
20678 wrap point was found. */
20679 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)
20680 && wrap_row_used
> 0
20681 /* Even if there is a previous wrap
20682 point, continue the line here as
20683 usual, if (i) the previous character
20684 was a space or tab AND (ii) the
20685 current character is not. */
20687 || IT_DISPLAYING_WHITESPACE (it
)))
20690 /* Record the maximum and minimum buffer
20691 positions seen so far in glyphs that will be
20692 displayed by this row. */
20694 RECORD_MAX_MIN_POS (it
);
20695 set_iterator_to_next (it
, true);
20696 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20698 if (!get_next_display_element (it
))
20700 row
->exact_window_width_line_p
= true;
20701 it
->continuation_lines_width
= 0;
20702 row
->continued_p
= false;
20703 row
->ends_at_zv_p
= true;
20705 else if (ITERATOR_AT_END_OF_LINE_P (it
))
20707 row
->continued_p
= false;
20708 row
->exact_window_width_line_p
= true;
20710 /* If line-wrap is on, check if a
20711 previous wrap point was found. */
20712 else if (wrap_row_used
> 0
20713 /* Even if there is a previous wrap
20714 point, continue the line here as
20715 usual, if (i) the previous character
20716 was a space or tab AND (ii) the
20717 current character is not. */
20719 || IT_DISPLAYING_WHITESPACE (it
)))
20724 else if (it
->bidi_p
)
20725 RECORD_MAX_MIN_POS (it
);
20726 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20727 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20728 extend_face_to_end_of_line (it
);
20730 else if (CHAR_GLYPH_PADDING_P (*glyph
)
20731 && !FRAME_WINDOW_P (it
->f
))
20733 /* A padding glyph that doesn't fit on this line.
20734 This means the whole character doesn't fit
20736 if (row
->reversed_p
)
20737 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20738 - n_glyphs_before
);
20739 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20741 /* Fill the rest of the row with continuation
20742 glyphs like in 20.x. */
20743 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
20744 < row
->glyphs
[1 + TEXT_AREA
])
20745 produce_special_glyphs (it
, IT_CONTINUATION
);
20747 row
->continued_p
= true;
20748 it
->current_x
= x_before
;
20749 it
->continuation_lines_width
+= x_before
;
20751 /* Restore the height to what it was before the
20752 element not fitting on the line. */
20753 it
->max_ascent
= ascent
;
20754 it
->max_descent
= descent
;
20755 it
->max_phys_ascent
= phys_ascent
;
20756 it
->max_phys_descent
= phys_descent
;
20757 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20758 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20759 extend_face_to_end_of_line (it
);
20761 else if (wrap_row_used
> 0)
20764 if (row
->reversed_p
)
20765 unproduce_glyphs (it
,
20766 row
->used
[TEXT_AREA
] - wrap_row_used
);
20767 RESTORE_IT (it
, &wrap_it
, wrap_data
);
20768 it
->continuation_lines_width
+= wrap_x
;
20769 row
->used
[TEXT_AREA
] = wrap_row_used
;
20770 row
->ascent
= wrap_row_ascent
;
20771 row
->height
= wrap_row_height
;
20772 row
->phys_ascent
= wrap_row_phys_ascent
;
20773 row
->phys_height
= wrap_row_phys_height
;
20774 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
20775 min_pos
= wrap_row_min_pos
;
20776 min_bpos
= wrap_row_min_bpos
;
20777 max_pos
= wrap_row_max_pos
;
20778 max_bpos
= wrap_row_max_bpos
;
20779 row
->continued_p
= true;
20780 row
->ends_at_zv_p
= false;
20781 row
->exact_window_width_line_p
= false;
20782 it
->continuation_lines_width
+= x
;
20784 /* Make sure that a non-default face is extended
20785 up to the right margin of the window. */
20786 extend_face_to_end_of_line (it
);
20788 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
20790 /* A TAB that extends past the right edge of the
20791 window. This produces a single glyph on
20792 window system frames. We leave the glyph in
20793 this row and let it fill the row, but don't
20794 consume the TAB. */
20795 if ((row
->reversed_p
20796 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20797 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20798 produce_special_glyphs (it
, IT_CONTINUATION
);
20799 it
->continuation_lines_width
+= it
->last_visible_x
;
20800 row
->ends_in_middle_of_char_p
= true;
20801 row
->continued_p
= true;
20802 glyph
->pixel_width
= it
->last_visible_x
- x
;
20803 it
->starts_in_middle_of_char_p
= true;
20804 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20805 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20806 extend_face_to_end_of_line (it
);
20810 /* Something other than a TAB that draws past
20811 the right edge of the window. Restore
20812 positions to values before the element. */
20813 if (row
->reversed_p
)
20814 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20815 - (n_glyphs_before
+ i
));
20816 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20818 /* Display continuation glyphs. */
20819 it
->current_x
= x_before
;
20820 it
->continuation_lines_width
+= x
;
20821 if (!FRAME_WINDOW_P (it
->f
)
20822 || (row
->reversed_p
20823 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20824 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20825 produce_special_glyphs (it
, IT_CONTINUATION
);
20826 row
->continued_p
= true;
20828 extend_face_to_end_of_line (it
);
20830 if (nglyphs
> 1 && i
> 0)
20832 row
->ends_in_middle_of_char_p
= true;
20833 it
->starts_in_middle_of_char_p
= true;
20836 /* Restore the height to what it was before the
20837 element not fitting on the line. */
20838 it
->max_ascent
= ascent
;
20839 it
->max_descent
= descent
;
20840 it
->max_phys_ascent
= phys_ascent
;
20841 it
->max_phys_descent
= phys_descent
;
20846 else if (new_x
> it
->first_visible_x
)
20848 /* Increment number of glyphs actually displayed. */
20851 /* Record the maximum and minimum buffer positions
20852 seen so far in glyphs that will be displayed by
20855 RECORD_MAX_MIN_POS (it
);
20857 if (x
< it
->first_visible_x
&& !row
->reversed_p
)
20858 /* Glyph is partially visible, i.e. row starts at
20859 negative X position. Don't do that in R2L
20860 rows, where we arrange to add a right offset to
20861 the line in extend_face_to_end_of_line, by a
20862 suitable change to the stretch glyph that is
20863 the leftmost glyph of the line. */
20864 row
->x
= x
- it
->first_visible_x
;
20865 /* When the last glyph of an R2L row only fits
20866 partially on the line, we need to set row->x to a
20867 negative offset, so that the leftmost glyph is
20868 the one that is partially visible. But if we are
20869 going to produce the truncation glyph, this will
20870 be taken care of in produce_special_glyphs. */
20871 if (row
->reversed_p
20872 && new_x
> it
->last_visible_x
20873 && !(it
->line_wrap
== TRUNCATE
20874 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
20876 eassert (FRAME_WINDOW_P (it
->f
));
20877 row
->x
= it
->last_visible_x
- new_x
;
20882 /* Glyph is completely off the left margin of the
20883 window. This should not happen because of the
20884 move_it_in_display_line at the start of this
20885 function, unless the text display area of the
20886 window is empty. */
20887 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20890 /* Even if this display element produced no glyphs at all,
20891 we want to record its position. */
20892 if (it
->bidi_p
&& nglyphs
== 0)
20893 RECORD_MAX_MIN_POS (it
);
20895 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20896 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20897 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20898 row
->phys_height
= max (row
->phys_height
,
20899 it
->max_phys_ascent
+ it
->max_phys_descent
);
20900 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20901 it
->max_extra_line_spacing
);
20903 /* End of this display line if row is continued. */
20904 if (row
->continued_p
|| row
->ends_at_zv_p
)
20909 /* Is this a line end? If yes, we're also done, after making
20910 sure that a non-default face is extended up to the right
20911 margin of the window. */
20912 if (ITERATOR_AT_END_OF_LINE_P (it
))
20914 int used_before
= row
->used
[TEXT_AREA
];
20916 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
20918 /* Add a space at the end of the line that is used to
20919 display the cursor there. */
20920 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20921 append_space_for_newline (it
, false);
20923 /* Extend the face to the end of the line. */
20924 extend_face_to_end_of_line (it
);
20926 /* Make sure we have the position. */
20927 if (used_before
== 0)
20928 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
20930 /* Record the position of the newline, for use in
20932 it
->eol_pos
= it
->current
.pos
;
20934 /* Consume the line end. This skips over invisible lines. */
20935 set_iterator_to_next (it
, true);
20936 it
->continuation_lines_width
= 0;
20940 /* Proceed with next display element. Note that this skips
20941 over lines invisible because of selective display. */
20942 set_iterator_to_next (it
, true);
20944 /* If we truncate lines, we are done when the last displayed
20945 glyphs reach past the right margin of the window. */
20946 if (it
->line_wrap
== TRUNCATE
20947 && ((FRAME_WINDOW_P (it
->f
)
20948 /* Images are preprocessed in produce_image_glyph such
20949 that they are cropped at the right edge of the
20950 window, so an image glyph will always end exactly at
20951 last_visible_x, even if there's no right fringe. */
20952 && ((row
->reversed_p
20953 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20954 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))
20955 || it
->what
== IT_IMAGE
))
20956 ? (it
->current_x
>= it
->last_visible_x
)
20957 : (it
->current_x
> it
->last_visible_x
)))
20959 /* Maybe add truncation glyphs. */
20960 if (!FRAME_WINDOW_P (it
->f
)
20961 || (row
->reversed_p
20962 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20963 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20967 if (!row
->reversed_p
)
20969 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20970 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20975 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20976 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20978 /* Remove any padding glyphs at the front of ROW, to
20979 make room for the truncation glyphs we will be
20980 adding below. The loop below always inserts at
20981 least one truncation glyph, so also remove the
20982 last glyph added to ROW. */
20983 unproduce_glyphs (it
, i
+ 1);
20984 /* Adjust i for the loop below. */
20985 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20988 /* produce_special_glyphs overwrites the last glyph, so
20989 we don't want that if we want to keep that last
20990 glyph, which means it's an image. */
20991 if (it
->current_x
> it
->last_visible_x
)
20993 it
->current_x
= x_before
;
20994 if (!FRAME_WINDOW_P (it
->f
))
20996 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20998 row
->used
[TEXT_AREA
] = i
;
20999 produce_special_glyphs (it
, IT_TRUNCATION
);
21004 row
->used
[TEXT_AREA
] = i
;
21005 produce_special_glyphs (it
, IT_TRUNCATION
);
21007 it
->hpos
= hpos_before
;
21010 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
21012 /* Don't truncate if we can overflow newline into fringe. */
21013 if (!get_next_display_element (it
))
21015 it
->continuation_lines_width
= 0;
21016 row
->ends_at_zv_p
= true;
21017 row
->exact_window_width_line_p
= true;
21020 if (ITERATOR_AT_END_OF_LINE_P (it
))
21022 row
->exact_window_width_line_p
= true;
21023 goto at_end_of_line
;
21025 it
->current_x
= x_before
;
21026 it
->hpos
= hpos_before
;
21029 row
->truncated_on_right_p
= true;
21030 it
->continuation_lines_width
= 0;
21031 reseat_at_next_visible_line_start (it
, false);
21032 /* We insist below that IT's position be at ZV because in
21033 bidi-reordered lines the character at visible line start
21034 might not be the character that follows the newline in
21035 the logical order. */
21036 if (IT_BYTEPOS (*it
) > BEG_BYTE
)
21037 row
->ends_at_zv_p
=
21038 IT_BYTEPOS (*it
) >= ZV_BYTE
&& FETCH_BYTE (ZV_BYTE
- 1) != '\n';
21040 row
->ends_at_zv_p
= false;
21046 bidi_unshelve_cache (wrap_data
, true);
21048 /* If line is not empty and hscrolled, maybe insert truncation glyphs
21049 at the left window margin. */
21050 if (it
->first_visible_x
21051 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
21053 if (!FRAME_WINDOW_P (it
->f
)
21054 || (((row
->reversed_p
21055 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
21056 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
21057 /* Don't let insert_left_trunc_glyphs overwrite the
21058 first glyph of the row if it is an image. */
21059 && row
->glyphs
[TEXT_AREA
]->type
!= IMAGE_GLYPH
))
21060 insert_left_trunc_glyphs (it
);
21061 row
->truncated_on_left_p
= true;
21064 /* Remember the position at which this line ends.
21066 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
21067 cannot be before the call to find_row_edges below, since that is
21068 where these positions are determined. */
21069 row
->end
= it
->current
;
21072 row
->minpos
= row
->start
.pos
;
21073 row
->maxpos
= row
->end
.pos
;
21077 /* ROW->minpos and ROW->maxpos must be the smallest and
21078 `1 + the largest' buffer positions in ROW. But if ROW was
21079 bidi-reordered, these two positions can be anywhere in the
21080 row, so we must determine them now. */
21081 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
21084 /* If the start of this line is the overlay arrow-position, then
21085 mark this glyph row as the one containing the overlay arrow.
21086 This is clearly a mess with variable size fonts. It would be
21087 better to let it be displayed like cursors under X. */
21088 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
21089 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
21090 !NILP (overlay_arrow_string
)))
21092 /* Overlay arrow in window redisplay is a fringe bitmap. */
21093 if (STRINGP (overlay_arrow_string
))
21095 struct glyph_row
*arrow_row
21096 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
21097 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
21098 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
21099 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
21100 struct glyph
*p2
, *end
;
21102 /* Copy the arrow glyphs. */
21103 while (glyph
< arrow_end
)
21106 /* Throw away padding glyphs. */
21108 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
21109 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
21115 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
21120 eassert (INTEGERP (overlay_arrow_string
));
21121 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
21123 overlay_arrow_seen
= true;
21126 /* Highlight trailing whitespace. */
21127 if (!NILP (Vshow_trailing_whitespace
))
21128 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
21130 /* Compute pixel dimensions of this line. */
21131 compute_line_metrics (it
);
21133 /* Implementation note: No changes in the glyphs of ROW or in their
21134 faces can be done past this point, because compute_line_metrics
21135 computes ROW's hash value and stores it within the glyph_row
21138 /* Record whether this row ends inside an ellipsis. */
21139 row
->ends_in_ellipsis_p
21140 = (it
->method
== GET_FROM_DISPLAY_VECTOR
21141 && it
->ellipsis_p
);
21143 /* Save fringe bitmaps in this row. */
21144 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
21145 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
21146 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
21147 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
21149 it
->left_user_fringe_bitmap
= 0;
21150 it
->left_user_fringe_face_id
= 0;
21151 it
->right_user_fringe_bitmap
= 0;
21152 it
->right_user_fringe_face_id
= 0;
21154 /* Maybe set the cursor. */
21155 cvpos
= it
->w
->cursor
.vpos
;
21157 /* In bidi-reordered rows, keep checking for proper cursor
21158 position even if one has been found already, because buffer
21159 positions in such rows change non-linearly with ROW->VPOS,
21160 when a line is continued. One exception: when we are at ZV,
21161 display cursor on the first suitable glyph row, since all
21162 the empty rows after that also have their position set to ZV. */
21163 /* FIXME: Revisit this when glyph ``spilling'' in continuation
21164 lines' rows is implemented for bidi-reordered rows. */
21166 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
21167 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
21168 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
21169 && cursor_row_p (row
))
21170 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
21172 /* Prepare for the next line. This line starts horizontally at (X
21173 HPOS) = (0 0). Vertical positions are incremented. As a
21174 convenience for the caller, IT->glyph_row is set to the next
21176 it
->current_x
= it
->hpos
= 0;
21177 it
->current_y
+= row
->height
;
21178 SET_TEXT_POS (it
->eol_pos
, 0, 0);
21181 /* The next row should by default use the same value of the
21182 reversed_p flag as this one. set_iterator_to_next decides when
21183 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
21184 the flag accordingly. */
21185 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
21186 it
->glyph_row
->reversed_p
= row
->reversed_p
;
21187 it
->start
= row
->end
;
21188 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
21190 #undef RECORD_MAX_MIN_POS
21193 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
21194 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
21195 doc
: /* Return paragraph direction at point in BUFFER.
21196 Value is either `left-to-right' or `right-to-left'.
21197 If BUFFER is omitted or nil, it defaults to the current buffer.
21199 Paragraph direction determines how the text in the paragraph is displayed.
21200 In left-to-right paragraphs, text begins at the left margin of the window
21201 and the reading direction is generally left to right. In right-to-left
21202 paragraphs, text begins at the right margin and is read from right to left.
21204 See also `bidi-paragraph-direction'. */)
21205 (Lisp_Object buffer
)
21207 struct buffer
*buf
= current_buffer
;
21208 struct buffer
*old
= buf
;
21210 if (! NILP (buffer
))
21212 CHECK_BUFFER (buffer
);
21213 buf
= XBUFFER (buffer
);
21216 if (NILP (BVAR (buf
, bidi_display_reordering
))
21217 || NILP (BVAR (buf
, enable_multibyte_characters
))
21218 /* When we are loading loadup.el, the character property tables
21219 needed for bidi iteration are not yet available. */
21220 || !NILP (Vpurify_flag
))
21221 return Qleft_to_right
;
21222 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
21223 return BVAR (buf
, bidi_paragraph_direction
);
21226 /* Determine the direction from buffer text. We could try to
21227 use current_matrix if it is up to date, but this seems fast
21228 enough as it is. */
21229 struct bidi_it itb
;
21230 ptrdiff_t pos
= BUF_PT (buf
);
21231 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
21233 void *itb_data
= bidi_shelve_cache ();
21235 set_buffer_temp (buf
);
21236 /* bidi_paragraph_init finds the base direction of the paragraph
21237 by searching forward from paragraph start. We need the base
21238 direction of the current or _previous_ paragraph, so we need
21239 to make sure we are within that paragraph. To that end, find
21240 the previous non-empty line. */
21241 if (pos
>= ZV
&& pos
> BEGV
)
21242 DEC_BOTH (pos
, bytepos
);
21243 AUTO_STRING (trailing_white_space
, "[\f\t ]*\n");
21244 if (fast_looking_at (trailing_white_space
,
21245 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
21247 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
21248 || c
== ' ' || c
== '\t' || c
== '\f')
21250 if (bytepos
<= BEGV_BYTE
)
21255 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
21258 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
21259 itb
.paragraph_dir
= NEUTRAL_DIR
;
21260 itb
.string
.s
= NULL
;
21261 itb
.string
.lstring
= Qnil
;
21262 itb
.string
.bufpos
= 0;
21263 itb
.string
.from_disp_str
= false;
21264 itb
.string
.unibyte
= false;
21265 /* We have no window to use here for ignoring window-specific
21266 overlays. Using NULL for window pointer will cause
21267 compute_display_string_pos to use the current buffer. */
21269 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, true);
21270 bidi_unshelve_cache (itb_data
, false);
21271 set_buffer_temp (old
);
21272 switch (itb
.paragraph_dir
)
21275 return Qleft_to_right
;
21278 return Qright_to_left
;
21286 DEFUN ("bidi-find-overridden-directionality",
21287 Fbidi_find_overridden_directionality
,
21288 Sbidi_find_overridden_directionality
, 2, 3, 0,
21289 doc
: /* Return position between FROM and TO where directionality was overridden.
21291 This function returns the first character position in the specified
21292 region of OBJECT where there is a character whose `bidi-class' property
21293 is `L', but which was forced to display as `R' by a directional
21294 override, and likewise with characters whose `bidi-class' is `R'
21295 or `AL' that were forced to display as `L'.
21297 If no such character is found, the function returns nil.
21299 OBJECT is a Lisp string or buffer to search for overridden
21300 directionality, and defaults to the current buffer if nil or omitted.
21301 OBJECT can also be a window, in which case the function will search
21302 the buffer displayed in that window. Passing the window instead of
21303 a buffer is preferable when the buffer is displayed in some window,
21304 because this function will then be able to correctly account for
21305 window-specific overlays, which can affect the results.
21307 Strong directional characters `L', `R', and `AL' can have their
21308 intrinsic directionality overridden by directional override
21309 control characters RLO (u+202e) and LRO (u+202d). See the
21310 function `get-char-code-property' for a way to inquire about
21311 the `bidi-class' property of a character. */)
21312 (Lisp_Object from
, Lisp_Object to
, Lisp_Object object
)
21314 struct buffer
*buf
= current_buffer
;
21315 struct buffer
*old
= buf
;
21316 struct window
*w
= NULL
;
21317 bool frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ());
21318 struct bidi_it itb
;
21319 ptrdiff_t from_pos
, to_pos
, from_bpos
;
21322 if (!NILP (object
))
21324 if (BUFFERP (object
))
21325 buf
= XBUFFER (object
);
21326 else if (WINDOWP (object
))
21328 w
= decode_live_window (object
);
21329 buf
= XBUFFER (w
->contents
);
21330 frame_window_p
= FRAME_WINDOW_P (XFRAME (w
->frame
));
21333 CHECK_STRING (object
);
21336 if (STRINGP (object
))
21338 /* Characters in unibyte strings are always treated by bidi.c as
21340 if (!STRING_MULTIBYTE (object
)
21341 /* When we are loading loadup.el, the character property
21342 tables needed for bidi iteration are not yet
21344 || !NILP (Vpurify_flag
))
21347 validate_subarray (object
, from
, to
, SCHARS (object
), &from_pos
, &to_pos
);
21348 if (from_pos
>= SCHARS (object
))
21351 /* Set up the bidi iterator. */
21352 itb_data
= bidi_shelve_cache ();
21353 itb
.paragraph_dir
= NEUTRAL_DIR
;
21354 itb
.string
.lstring
= object
;
21355 itb
.string
.s
= NULL
;
21356 itb
.string
.schars
= SCHARS (object
);
21357 itb
.string
.bufpos
= 0;
21358 itb
.string
.from_disp_str
= false;
21359 itb
.string
.unibyte
= false;
21361 bidi_init_it (0, 0, frame_window_p
, &itb
);
21365 /* Nothing this fancy can happen in unibyte buffers, or in a
21366 buffer that disabled reordering, or if FROM is at EOB. */
21367 if (NILP (BVAR (buf
, bidi_display_reordering
))
21368 || NILP (BVAR (buf
, enable_multibyte_characters
))
21369 /* When we are loading loadup.el, the character property
21370 tables needed for bidi iteration are not yet
21372 || !NILP (Vpurify_flag
))
21375 set_buffer_temp (buf
);
21376 validate_region (&from
, &to
);
21377 from_pos
= XINT (from
);
21378 to_pos
= XINT (to
);
21379 if (from_pos
>= ZV
)
21382 /* Set up the bidi iterator. */
21383 itb_data
= bidi_shelve_cache ();
21384 from_bpos
= CHAR_TO_BYTE (from_pos
);
21385 if (from_pos
== BEGV
)
21387 itb
.charpos
= BEGV
;
21388 itb
.bytepos
= BEGV_BYTE
;
21390 else if (FETCH_CHAR (from_bpos
- 1) == '\n')
21392 itb
.charpos
= from_pos
;
21393 itb
.bytepos
= from_bpos
;
21396 itb
.charpos
= find_newline_no_quit (from_pos
, CHAR_TO_BYTE (from_pos
),
21398 itb
.paragraph_dir
= NEUTRAL_DIR
;
21399 itb
.string
.s
= NULL
;
21400 itb
.string
.lstring
= Qnil
;
21401 itb
.string
.bufpos
= 0;
21402 itb
.string
.from_disp_str
= false;
21403 itb
.string
.unibyte
= false;
21405 bidi_init_it (itb
.charpos
, itb
.bytepos
, frame_window_p
, &itb
);
21410 /* For the purposes of this function, the actual base direction of
21411 the paragraph doesn't matter, so just set it to L2R. */
21412 bidi_paragraph_init (L2R
, &itb
, false);
21413 while ((found
= bidi_find_first_overridden (&itb
)) < from_pos
)
21415 } while (found
== ZV
&& itb
.ch
== '\n' && itb
.charpos
< to_pos
);
21417 bidi_unshelve_cache (itb_data
, false);
21418 set_buffer_temp (old
);
21420 return (from_pos
<= found
&& found
< to_pos
) ? make_number (found
) : Qnil
;
21423 DEFUN ("move-point-visually", Fmove_point_visually
,
21424 Smove_point_visually
, 1, 1, 0,
21425 doc
: /* Move point in the visual order in the specified DIRECTION.
21426 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
21429 Value is the new character position of point. */)
21430 (Lisp_Object direction
)
21432 struct window
*w
= XWINDOW (selected_window
);
21433 struct buffer
*b
= XBUFFER (w
->contents
);
21434 struct glyph_row
*row
;
21436 Lisp_Object paragraph_dir
;
21438 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
21439 (!(ROW)->continued_p \
21440 && NILP ((GLYPH)->object) \
21441 && (GLYPH)->type == CHAR_GLYPH \
21442 && (GLYPH)->u.ch == ' ' \
21443 && (GLYPH)->charpos >= 0 \
21444 && !(GLYPH)->avoid_cursor_p)
21446 CHECK_NUMBER (direction
);
21447 dir
= XINT (direction
);
21453 /* If current matrix is up-to-date, we can use the information
21454 recorded in the glyphs, at least as long as the goal is on the
21456 if (w
->window_end_valid
21457 && !windows_or_buffers_changed
21459 && !b
->clip_changed
21460 && !b
->prevent_redisplay_optimizations_p
21461 && !window_outdated (w
)
21462 /* We rely below on the cursor coordinates to be up to date, but
21463 we cannot trust them if some command moved point since the
21464 last complete redisplay. */
21465 && w
->last_point
== BUF_PT (b
)
21466 && w
->cursor
.vpos
>= 0
21467 && w
->cursor
.vpos
< w
->current_matrix
->nrows
21468 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
21470 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
21471 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
21472 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
21474 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
21476 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
21478 SET_PT (g
->charpos
);
21479 w
->cursor
.vpos
= -1;
21480 return make_number (PT
);
21482 else if (!NILP (g
->object
) && !EQ (g
->object
, gpt
->object
))
21486 if (BUFFERP (gpt
->object
))
21489 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
21490 new_pos
+= (row
->reversed_p
? -dir
: dir
);
21492 new_pos
-= (row
->reversed_p
? -dir
: dir
);
21494 else if (BUFFERP (g
->object
))
21495 new_pos
= g
->charpos
;
21499 w
->cursor
.vpos
= -1;
21500 return make_number (PT
);
21502 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
21504 /* Glyphs inserted at the end of a non-empty line for
21505 positioning the cursor have zero charpos, so we must
21506 deduce the value of point by other means. */
21507 if (g
->charpos
> 0)
21508 SET_PT (g
->charpos
);
21509 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
21511 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
21512 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21515 w
->cursor
.vpos
= -1;
21516 return make_number (PT
);
21519 if (g
== e
|| NILP (g
->object
))
21521 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
21522 goto simulate_display
;
21523 if (!row
->reversed_p
)
21527 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
21528 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
21529 goto simulate_display
;
21533 if (row
->reversed_p
&& !row
->continued_p
)
21535 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21536 w
->cursor
.vpos
= -1;
21537 return make_number (PT
);
21539 g
= row
->glyphs
[TEXT_AREA
];
21540 e
= g
+ row
->used
[TEXT_AREA
];
21541 for ( ; g
< e
; g
++)
21543 if (BUFFERP (g
->object
)
21544 /* Empty lines have only one glyph, which stands
21545 for the newline, and whose charpos is the
21546 buffer position of the newline. */
21547 || ROW_GLYPH_NEWLINE_P (row
, g
)
21548 /* When the buffer ends in a newline, the line at
21549 EOB also has one glyph, but its charpos is -1. */
21550 || (row
->ends_at_zv_p
21551 && !row
->reversed_p
21552 && NILP (g
->object
)
21553 && g
->type
== CHAR_GLYPH
21554 && g
->u
.ch
== ' '))
21556 if (g
->charpos
> 0)
21557 SET_PT (g
->charpos
);
21558 else if (!row
->reversed_p
21559 && row
->ends_at_zv_p
21564 w
->cursor
.vpos
= -1;
21565 return make_number (PT
);
21571 if (!row
->reversed_p
&& !row
->continued_p
)
21573 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21574 w
->cursor
.vpos
= -1;
21575 return make_number (PT
);
21577 e
= row
->glyphs
[TEXT_AREA
];
21578 g
= e
+ row
->used
[TEXT_AREA
] - 1;
21579 for ( ; g
>= e
; g
--)
21581 if (BUFFERP (g
->object
)
21582 || (ROW_GLYPH_NEWLINE_P (row
, g
)
21584 /* Empty R2L lines on GUI frames have the buffer
21585 position of the newline stored in the stretch
21587 || g
->type
== STRETCH_GLYPH
21588 || (row
->ends_at_zv_p
21590 && NILP (g
->object
)
21591 && g
->type
== CHAR_GLYPH
21592 && g
->u
.ch
== ' '))
21594 if (g
->charpos
> 0)
21595 SET_PT (g
->charpos
);
21596 else if (row
->reversed_p
21597 && row
->ends_at_zv_p
21602 w
->cursor
.vpos
= -1;
21603 return make_number (PT
);
21612 /* If we wind up here, we failed to move by using the glyphs, so we
21613 need to simulate display instead. */
21616 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
21618 paragraph_dir
= Qleft_to_right
;
21619 if (EQ (paragraph_dir
, Qright_to_left
))
21621 if (PT
<= BEGV
&& dir
< 0)
21622 xsignal0 (Qbeginning_of_buffer
);
21623 else if (PT
>= ZV
&& dir
> 0)
21624 xsignal0 (Qend_of_buffer
);
21627 struct text_pos pt
;
21629 int pt_x
, target_x
, pixel_width
, pt_vpos
;
21631 bool overshoot_expected
= false;
21632 bool target_is_eol_p
= false;
21634 /* Setup the arena. */
21635 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
21636 start_display (&it
, w
, pt
);
21637 /* When lines are truncated, we could be called with point
21638 outside of the windows edges, in which case move_it_*
21639 functions either prematurely stop at window's edge or jump to
21640 the next screen line, whereas we rely below on our ability to
21641 reach point, in order to start from its X coordinate. So we
21642 need to disregard the window's horizontal extent in that case. */
21643 if (it
.line_wrap
== TRUNCATE
)
21644 it
.last_visible_x
= INFINITY
;
21646 if (it
.cmp_it
.id
< 0
21647 && it
.method
== GET_FROM_STRING
21648 && it
.area
== TEXT_AREA
21649 && it
.string_from_display_prop_p
21650 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
21651 overshoot_expected
= true;
21653 /* Find the X coordinate of point. We start from the beginning
21654 of this or previous line to make sure we are before point in
21655 the logical order (since the move_it_* functions can only
21658 reseat_at_previous_visible_line_start (&it
);
21659 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
21660 if (IT_CHARPOS (it
) != PT
)
21662 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
21663 -1, -1, -1, MOVE_TO_POS
);
21664 /* If we missed point because the character there is
21665 displayed out of a display vector that has more than one
21666 glyph, retry expecting overshoot. */
21667 if (it
.method
== GET_FROM_DISPLAY_VECTOR
21668 && it
.current
.dpvec_index
> 0
21669 && !overshoot_expected
)
21671 overshoot_expected
= true;
21674 else if (IT_CHARPOS (it
) != PT
&& !overshoot_expected
)
21675 move_it_in_display_line (&it
, PT
, -1, MOVE_TO_POS
);
21677 pt_x
= it
.current_x
;
21679 if (dir
> 0 || overshoot_expected
)
21681 struct glyph_row
*row
= it
.glyph_row
;
21683 /* When point is at beginning of line, we don't have
21684 information about the glyph there loaded into struct
21685 it. Calling get_next_display_element fixes that. */
21687 get_next_display_element (&it
);
21688 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21689 it
.glyph_row
= NULL
;
21690 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
21691 it
.glyph_row
= row
;
21692 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
21693 it, lest it will become out of sync with it's buffer
21695 it
.current_x
= pt_x
;
21698 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21699 pixel_width
= it
.pixel_width
;
21700 if (overshoot_expected
&& at_eol_p
)
21702 else if (pixel_width
<= 0)
21705 /* If there's a display string (or something similar) at point,
21706 we are actually at the glyph to the left of point, so we need
21707 to correct the X coordinate. */
21708 if (overshoot_expected
)
21711 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
21713 pt_x
+= pixel_width
;
21716 /* Compute target X coordinate, either to the left or to the
21717 right of point. On TTY frames, all characters have the same
21718 pixel width of 1, so we can use that. On GUI frames we don't
21719 have an easy way of getting at the pixel width of the
21720 character to the left of point, so we use a different method
21721 of getting to that place. */
21723 target_x
= pt_x
+ pixel_width
;
21725 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
21727 /* Target X coordinate could be one line above or below the line
21728 of point, in which case we need to adjust the target X
21729 coordinate. Also, if moving to the left, we need to begin at
21730 the left edge of the point's screen line. */
21735 start_display (&it
, w
, pt
);
21736 if (it
.line_wrap
== TRUNCATE
)
21737 it
.last_visible_x
= INFINITY
;
21738 reseat_at_previous_visible_line_start (&it
);
21739 it
.current_x
= it
.current_y
= it
.hpos
= 0;
21741 move_it_by_lines (&it
, pt_vpos
);
21745 move_it_by_lines (&it
, -1);
21746 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
21747 target_is_eol_p
= true;
21748 /* Under word-wrap, we don't know the x coordinate of
21749 the last character displayed on the previous line,
21750 which immediately precedes the wrap point. To find
21751 out its x coordinate, we try moving to the right
21752 margin of the window, which will stop at the wrap
21753 point, and then reset target_x to point at the
21754 character that precedes the wrap point. This is not
21755 needed on GUI frames, because (see below) there we
21756 move from the left margin one grapheme cluster at a
21757 time, and stop when we hit the wrap point. */
21758 if (!FRAME_WINDOW_P (it
.f
) && it
.line_wrap
== WORD_WRAP
)
21760 void *it_data
= NULL
;
21763 SAVE_IT (it2
, it
, it_data
);
21764 move_it_in_display_line_to (&it
, ZV
, target_x
,
21765 MOVE_TO_POS
| MOVE_TO_X
);
21766 /* If we arrived at target_x, that _is_ the last
21767 character on the previous line. */
21768 if (it
.current_x
!= target_x
)
21769 target_x
= it
.current_x
- 1;
21770 RESTORE_IT (&it
, &it2
, it_data
);
21777 || (target_x
>= it
.last_visible_x
21778 && it
.line_wrap
!= TRUNCATE
))
21781 move_it_by_lines (&it
, 0);
21782 move_it_by_lines (&it
, 1);
21787 /* Move to the target X coordinate. */
21788 #ifdef HAVE_WINDOW_SYSTEM
21789 /* On GUI frames, as we don't know the X coordinate of the
21790 character to the left of point, moving point to the left
21791 requires walking, one grapheme cluster at a time, until we
21792 find ourself at a place immediately to the left of the
21793 character at point. */
21794 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
21796 struct text_pos new_pos
;
21797 enum move_it_result rc
= MOVE_X_REACHED
;
21799 if (it
.current_x
== 0)
21800 get_next_display_element (&it
);
21801 if (it
.what
== IT_COMPOSITION
)
21803 new_pos
.charpos
= it
.cmp_it
.charpos
;
21804 new_pos
.bytepos
= -1;
21807 new_pos
= it
.current
.pos
;
21809 while (it
.current_x
+ it
.pixel_width
<= target_x
21810 && (rc
== MOVE_X_REACHED
21811 /* Under word-wrap, move_it_in_display_line_to
21812 stops at correct coordinates, but sometimes
21813 returns MOVE_POS_MATCH_OR_ZV. */
21814 || (it
.line_wrap
== WORD_WRAP
21815 && rc
== MOVE_POS_MATCH_OR_ZV
)))
21817 int new_x
= it
.current_x
+ it
.pixel_width
;
21819 /* For composed characters, we want the position of the
21820 first character in the grapheme cluster (usually, the
21821 composition's base character), whereas it.current
21822 might give us the position of the _last_ one, e.g. if
21823 the composition is rendered in reverse due to bidi
21825 if (it
.what
== IT_COMPOSITION
)
21827 new_pos
.charpos
= it
.cmp_it
.charpos
;
21828 new_pos
.bytepos
= -1;
21831 new_pos
= it
.current
.pos
;
21832 if (new_x
== it
.current_x
)
21834 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
21835 MOVE_TO_POS
| MOVE_TO_X
);
21836 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
21839 /* The previous position we saw in the loop is the one we
21841 if (new_pos
.bytepos
== -1)
21842 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
21843 it
.current
.pos
= new_pos
;
21847 if (it
.current_x
!= target_x
)
21848 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
21850 /* If we ended up in a display string that covers point, move to
21851 buffer position to the right in the visual order. */
21854 while (IT_CHARPOS (it
) == PT
)
21856 set_iterator_to_next (&it
, false);
21857 if (!get_next_display_element (&it
))
21862 /* Move point to that position. */
21863 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
21866 return make_number (PT
);
21868 #undef ROW_GLYPH_NEWLINE_P
21871 DEFUN ("bidi-resolved-levels", Fbidi_resolved_levels
,
21872 Sbidi_resolved_levels
, 0, 1, 0,
21873 doc
: /* Return the resolved bidirectional levels of characters at VPOS.
21875 The resolved levels are produced by the Emacs bidi reordering engine
21876 that implements the UBA, the Unicode Bidirectional Algorithm. Please
21877 read the Unicode Standard Annex 9 (UAX#9) for background information
21878 about these levels.
21880 VPOS is the zero-based number of the current window's screen line
21881 for which to produce the resolved levels. If VPOS is nil or omitted,
21882 it defaults to the screen line of point. If the window displays a
21883 header line, VPOS of zero will report on the header line, and first
21884 line of text in the window will have VPOS of 1.
21886 Value is an array of resolved levels, indexed by glyph number.
21887 Glyphs are numbered from zero starting from the beginning of the
21888 screen line, i.e. the left edge of the window for left-to-right lines
21889 and from the right edge for right-to-left lines. The resolved levels
21890 are produced only for the window's text area; text in display margins
21893 If the selected window's display is not up-to-date, or if the specified
21894 screen line does not display text, this function returns nil. It is
21895 highly recommended to bind this function to some simple key, like F8,
21896 in order to avoid these problems.
21898 This function exists mainly for testing the correctness of the
21899 Emacs UBA implementation, in particular with the test suite. */)
21902 struct window
*w
= XWINDOW (selected_window
);
21903 struct buffer
*b
= XBUFFER (w
->contents
);
21905 struct glyph_row
*row
;
21909 int d1
, d2
, d3
, d4
, d5
;
21911 pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &nrow
);
21915 CHECK_NUMBER_COERCE_MARKER (vpos
);
21916 nrow
= XINT (vpos
);
21919 /* We require up-to-date glyph matrix for this window. */
21920 if (w
->window_end_valid
21921 && !windows_or_buffers_changed
21923 && !b
->clip_changed
21924 && !b
->prevent_redisplay_optimizations_p
21925 && !window_outdated (w
)
21927 && nrow
< w
->current_matrix
->nrows
21928 && (row
= MATRIX_ROW (w
->current_matrix
, nrow
))->enabled_p
21929 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
21931 struct glyph
*g
, *e
, *g1
;
21933 Lisp_Object levels
;
21935 if (!row
->reversed_p
) /* Left-to-right glyph row. */
21937 g
= g1
= row
->glyphs
[TEXT_AREA
];
21938 e
= g
+ row
->used
[TEXT_AREA
];
21940 /* Skip over glyphs at the start of the row that was
21941 generated by redisplay for its own needs. */
21943 && NILP (g
->object
)
21948 /* Count the "interesting" glyphs in this row. */
21949 for (nglyphs
= 0; g
< e
&& !NILP (g
->object
); g
++)
21952 /* Create and fill the array. */
21953 levels
= make_uninit_vector (nglyphs
);
21954 for (i
= 0; g1
< g
; i
++, g1
++)
21955 ASET (levels
, i
, make_number (g1
->resolved_level
));
21957 else /* Right-to-left glyph row. */
21959 g
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
21960 e
= row
->glyphs
[TEXT_AREA
] - 1;
21962 && NILP (g
->object
)
21966 for (nglyphs
= 0; g
> e
&& !NILP (g
->object
); g
--)
21968 levels
= make_uninit_vector (nglyphs
);
21969 for (i
= 0; g1
> g
; i
++, g1
--)
21970 ASET (levels
, i
, make_number (g1
->resolved_level
));
21980 /***********************************************************************
21982 ***********************************************************************/
21984 /* Redisplay the menu bar in the frame for window W.
21986 The menu bar of X frames that don't have X toolkit support is
21987 displayed in a special window W->frame->menu_bar_window.
21989 The menu bar of terminal frames is treated specially as far as
21990 glyph matrices are concerned. Menu bar lines are not part of
21991 windows, so the update is done directly on the frame matrix rows
21992 for the menu bar. */
21995 display_menu_bar (struct window
*w
)
21997 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22002 /* Don't do all this for graphical frames. */
22004 if (FRAME_W32_P (f
))
22007 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
22013 if (FRAME_NS_P (f
))
22015 #endif /* HAVE_NS */
22017 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
22018 eassert (!FRAME_WINDOW_P (f
));
22019 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
22020 it
.first_visible_x
= 0;
22021 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
22022 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
22023 if (FRAME_WINDOW_P (f
))
22025 /* Menu bar lines are displayed in the desired matrix of the
22026 dummy window menu_bar_window. */
22027 struct window
*menu_w
;
22028 menu_w
= XWINDOW (f
->menu_bar_window
);
22029 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
22031 it
.first_visible_x
= 0;
22032 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
22035 #endif /* not USE_X_TOOLKIT and not USE_GTK */
22037 /* This is a TTY frame, i.e. character hpos/vpos are used as
22039 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
22041 it
.first_visible_x
= 0;
22042 it
.last_visible_x
= FRAME_COLS (f
);
22045 /* FIXME: This should be controlled by a user option. See the
22046 comments in redisplay_tool_bar and display_mode_line about
22048 it
.paragraph_embedding
= L2R
;
22050 /* Clear all rows of the menu bar. */
22051 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
22053 struct glyph_row
*row
= it
.glyph_row
+ i
;
22054 clear_glyph_row (row
);
22055 row
->enabled_p
= true;
22056 row
->full_width_p
= true;
22057 row
->reversed_p
= false;
22060 /* Display all items of the menu bar. */
22061 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
22062 for (i
= 0; i
< ASIZE (items
); i
+= 4)
22064 Lisp_Object string
;
22066 /* Stop at nil string. */
22067 string
= AREF (items
, i
+ 1);
22071 /* Remember where item was displayed. */
22072 ASET (items
, i
+ 3, make_number (it
.hpos
));
22074 /* Display the item, pad with one space. */
22075 if (it
.current_x
< it
.last_visible_x
)
22076 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
22077 SCHARS (string
) + 1, 0, 0, -1);
22080 /* Fill out the line with spaces. */
22081 if (it
.current_x
< it
.last_visible_x
)
22082 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
22084 /* Compute the total height of the lines. */
22085 compute_line_metrics (&it
);
22088 /* Deep copy of a glyph row, including the glyphs. */
22090 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
22092 struct glyph
*pointers
[1 + LAST_AREA
];
22093 int to_used
= to
->used
[TEXT_AREA
];
22095 /* Save glyph pointers of TO. */
22096 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
22098 /* Do a structure assignment. */
22101 /* Restore original glyph pointers of TO. */
22102 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
22104 /* Copy the glyphs. */
22105 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
22106 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
22108 /* If we filled only part of the TO row, fill the rest with
22109 space_glyph (which will display as empty space). */
22110 if (to_used
> from
->used
[TEXT_AREA
])
22111 fill_up_frame_row_with_spaces (to
, to_used
);
22114 /* Display one menu item on a TTY, by overwriting the glyphs in the
22115 frame F's desired glyph matrix with glyphs produced from the menu
22116 item text. Called from term.c to display TTY drop-down menus one
22119 ITEM_TEXT is the menu item text as a C string.
22121 FACE_ID is the face ID to be used for this menu item. FACE_ID
22122 could specify one of 3 faces: a face for an enabled item, a face
22123 for a disabled item, or a face for a selected item.
22125 X and Y are coordinates of the first glyph in the frame's desired
22126 matrix to be overwritten by the menu item. Since this is a TTY, Y
22127 is the zero-based number of the glyph row and X is the zero-based
22128 glyph number in the row, starting from left, where to start
22129 displaying the item.
22131 SUBMENU means this menu item drops down a submenu, which
22132 should be indicated by displaying a proper visual cue after the
22136 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
22137 int x
, int y
, bool submenu
)
22140 struct frame
*f
= SELECTED_FRAME ();
22141 struct window
*w
= XWINDOW (f
->selected_window
);
22142 struct glyph_row
*row
;
22143 size_t item_len
= strlen (item_text
);
22145 eassert (FRAME_TERMCAP_P (f
));
22147 /* Don't write beyond the matrix's last row. This can happen for
22148 TTY screens that are not high enough to show the entire menu.
22149 (This is actually a bit of defensive programming, as
22150 tty_menu_display already limits the number of menu items to one
22151 less than the number of screen lines.) */
22152 if (y
>= f
->desired_matrix
->nrows
)
22155 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
22156 it
.first_visible_x
= 0;
22157 it
.last_visible_x
= FRAME_COLS (f
) - 1;
22158 row
= it
.glyph_row
;
22159 /* Start with the row contents from the current matrix. */
22160 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
22161 bool saved_width
= row
->full_width_p
;
22162 row
->full_width_p
= true;
22163 bool saved_reversed
= row
->reversed_p
;
22164 row
->reversed_p
= false;
22165 row
->enabled_p
= true;
22167 /* Arrange for the menu item glyphs to start at (X,Y) and have the
22169 eassert (x
< f
->desired_matrix
->matrix_w
);
22170 it
.current_x
= it
.hpos
= x
;
22171 it
.current_y
= it
.vpos
= y
;
22172 int saved_used
= row
->used
[TEXT_AREA
];
22173 bool saved_truncated
= row
->truncated_on_right_p
;
22174 row
->used
[TEXT_AREA
] = x
;
22175 it
.face_id
= face_id
;
22176 it
.line_wrap
= TRUNCATE
;
22178 /* FIXME: This should be controlled by a user option. See the
22179 comments in redisplay_tool_bar and display_mode_line about this.
22180 Also, if paragraph_embedding could ever be R2L, changes will be
22181 needed to avoid shifting to the right the row characters in
22182 term.c:append_glyph. */
22183 it
.paragraph_embedding
= L2R
;
22185 /* Pad with a space on the left. */
22186 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
22188 /* Display the menu item, pad with spaces to WIDTH. */
22191 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
22192 item_len
, 0, FRAME_COLS (f
) - 1, -1);
22194 /* Indicate with " >" that there's a submenu. */
22195 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
22196 FRAME_COLS (f
) - 1, -1);
22199 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
22200 width
, 0, FRAME_COLS (f
) - 1, -1);
22202 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
22203 row
->truncated_on_right_p
= saved_truncated
;
22204 row
->hash
= row_hash (row
);
22205 row
->full_width_p
= saved_width
;
22206 row
->reversed_p
= saved_reversed
;
22209 /***********************************************************************
22211 ***********************************************************************/
22213 /* Redisplay mode lines in the window tree whose root is WINDOW.
22214 If FORCE, redisplay mode lines unconditionally.
22215 Otherwise, redisplay only mode lines that are garbaged. Value is
22216 the number of windows whose mode lines were redisplayed. */
22219 redisplay_mode_lines (Lisp_Object window
, bool force
)
22223 while (!NILP (window
))
22225 struct window
*w
= XWINDOW (window
);
22227 if (WINDOWP (w
->contents
))
22228 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
22230 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
22231 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
22233 struct text_pos lpoint
;
22234 struct buffer
*old
= current_buffer
;
22236 /* Set the window's buffer for the mode line display. */
22237 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
22238 set_buffer_internal_1 (XBUFFER (w
->contents
));
22240 /* Point refers normally to the selected window. For any
22241 other window, set up appropriate value. */
22242 if (!EQ (window
, selected_window
))
22244 struct text_pos pt
;
22246 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
22247 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
22250 /* Display mode lines. */
22251 clear_glyph_matrix (w
->desired_matrix
);
22252 if (display_mode_lines (w
))
22255 /* Restore old settings. */
22256 set_buffer_internal_1 (old
);
22257 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
22267 /* Display the mode and/or header line of window W. Value is the
22268 sum number of mode lines and header lines displayed. */
22271 display_mode_lines (struct window
*w
)
22273 Lisp_Object old_selected_window
= selected_window
;
22274 Lisp_Object old_selected_frame
= selected_frame
;
22275 Lisp_Object new_frame
= w
->frame
;
22276 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
22279 selected_frame
= new_frame
;
22280 /* FIXME: If we were to allow the mode-line's computation changing the buffer
22281 or window's point, then we'd need select_window_1 here as well. */
22282 XSETWINDOW (selected_window
, w
);
22283 XFRAME (new_frame
)->selected_window
= selected_window
;
22285 /* These will be set while the mode line specs are processed. */
22286 line_number_displayed
= false;
22287 w
->column_number_displayed
= -1;
22289 if (WINDOW_WANTS_MODELINE_P (w
))
22291 struct window
*sel_w
= XWINDOW (old_selected_window
);
22293 /* Select mode line face based on the real selected window. */
22294 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
22295 BVAR (current_buffer
, mode_line_format
));
22299 if (WINDOW_WANTS_HEADER_LINE_P (w
))
22301 display_mode_line (w
, HEADER_LINE_FACE_ID
,
22302 BVAR (current_buffer
, header_line_format
));
22306 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
22307 selected_frame
= old_selected_frame
;
22308 selected_window
= old_selected_window
;
22310 w
->must_be_updated_p
= true;
22315 /* Display mode or header line of window W. FACE_ID specifies which
22316 line to display; it is either MODE_LINE_FACE_ID or
22317 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
22318 display. Value is the pixel height of the mode/header line
22322 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
22326 ptrdiff_t count
= SPECPDL_INDEX ();
22328 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
22329 /* Don't extend on a previously drawn mode-line.
22330 This may happen if called from pos_visible_p. */
22331 it
.glyph_row
->enabled_p
= false;
22332 prepare_desired_row (w
, it
.glyph_row
, true);
22334 it
.glyph_row
->mode_line_p
= true;
22336 /* FIXME: This should be controlled by a user option. But
22337 supporting such an option is not trivial, since the mode line is
22338 made up of many separate strings. */
22339 it
.paragraph_embedding
= L2R
;
22341 record_unwind_protect (unwind_format_mode_line
,
22342 format_mode_line_unwind_data (NULL
, NULL
,
22345 mode_line_target
= MODE_LINE_DISPLAY
;
22347 /* Temporarily make frame's keyboard the current kboard so that
22348 kboard-local variables in the mode_line_format will get the right
22350 push_kboard (FRAME_KBOARD (it
.f
));
22351 record_unwind_save_match_data ();
22352 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
22355 unbind_to (count
, Qnil
);
22357 /* Fill up with spaces. */
22358 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
22360 compute_line_metrics (&it
);
22361 it
.glyph_row
->full_width_p
= true;
22362 it
.glyph_row
->continued_p
= false;
22363 it
.glyph_row
->truncated_on_left_p
= false;
22364 it
.glyph_row
->truncated_on_right_p
= false;
22366 /* Make a 3D mode-line have a shadow at its right end. */
22367 face
= FACE_FROM_ID (it
.f
, face_id
);
22368 extend_face_to_end_of_line (&it
);
22369 if (face
->box
!= FACE_NO_BOX
)
22371 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
22372 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
22373 last
->right_box_line_p
= true;
22376 return it
.glyph_row
->height
;
22379 /* Move element ELT in LIST to the front of LIST.
22380 Return the updated list. */
22383 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
22385 register Lisp_Object tail
, prev
;
22386 register Lisp_Object tem
;
22390 while (CONSP (tail
))
22396 /* Splice out the link TAIL. */
22398 list
= XCDR (tail
);
22400 Fsetcdr (prev
, XCDR (tail
));
22402 /* Now make it the first. */
22403 Fsetcdr (tail
, list
);
22408 tail
= XCDR (tail
);
22412 /* Not found--return unchanged LIST. */
22416 /* Contribute ELT to the mode line for window IT->w. How it
22417 translates into text depends on its data type.
22419 IT describes the display environment in which we display, as usual.
22421 DEPTH is the depth in recursion. It is used to prevent
22422 infinite recursion here.
22424 FIELD_WIDTH is the number of characters the display of ELT should
22425 occupy in the mode line, and PRECISION is the maximum number of
22426 characters to display from ELT's representation. See
22427 display_string for details.
22429 Returns the hpos of the end of the text generated by ELT.
22431 PROPS is a property list to add to any string we encounter.
22433 If RISKY, remove (disregard) any properties in any string
22434 we encounter, and ignore :eval and :propertize.
22436 The global variable `mode_line_target' determines whether the
22437 output is passed to `store_mode_line_noprop',
22438 `store_mode_line_string', or `display_string'. */
22441 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
22442 Lisp_Object elt
, Lisp_Object props
, bool risky
)
22444 int n
= 0, field
, prec
;
22445 bool literal
= false;
22449 elt
= build_string ("*too-deep*");
22453 switch (XTYPE (elt
))
22457 /* A string: output it and check for %-constructs within it. */
22459 ptrdiff_t offset
= 0;
22461 if (SCHARS (elt
) > 0
22462 && (!NILP (props
) || risky
))
22464 Lisp_Object oprops
, aelt
;
22465 oprops
= Ftext_properties_at (make_number (0), elt
);
22467 /* If the starting string's properties are not what
22468 we want, translate the string. Also, if the string
22469 is risky, do that anyway. */
22471 if (NILP (Fequal (props
, oprops
)) || risky
)
22473 /* If the starting string has properties,
22474 merge the specified ones onto the existing ones. */
22475 if (! NILP (oprops
) && !risky
)
22479 oprops
= Fcopy_sequence (oprops
);
22481 while (CONSP (tem
))
22483 oprops
= Fplist_put (oprops
, XCAR (tem
),
22484 XCAR (XCDR (tem
)));
22485 tem
= XCDR (XCDR (tem
));
22490 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
22491 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
22493 /* AELT is what we want. Move it to the front
22494 without consing. */
22496 mode_line_proptrans_alist
22497 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
22503 /* If AELT has the wrong props, it is useless.
22504 so get rid of it. */
22506 mode_line_proptrans_alist
22507 = Fdelq (aelt
, mode_line_proptrans_alist
);
22509 elt
= Fcopy_sequence (elt
);
22510 Fset_text_properties (make_number (0), Flength (elt
),
22512 /* Add this item to mode_line_proptrans_alist. */
22513 mode_line_proptrans_alist
22514 = Fcons (Fcons (elt
, props
),
22515 mode_line_proptrans_alist
);
22516 /* Truncate mode_line_proptrans_alist
22517 to at most 50 elements. */
22518 tem
= Fnthcdr (make_number (50),
22519 mode_line_proptrans_alist
);
22521 XSETCDR (tem
, Qnil
);
22530 prec
= precision
- n
;
22531 switch (mode_line_target
)
22533 case MODE_LINE_NOPROP
:
22534 case MODE_LINE_TITLE
:
22535 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
22537 case MODE_LINE_STRING
:
22538 n
+= store_mode_line_string (NULL
, elt
, true, 0, prec
, Qnil
);
22540 case MODE_LINE_DISPLAY
:
22541 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
22542 0, prec
, 0, STRING_MULTIBYTE (elt
));
22549 /* Handle the non-literal case. */
22551 while ((precision
<= 0 || n
< precision
)
22552 && SREF (elt
, offset
) != 0
22553 && (mode_line_target
!= MODE_LINE_DISPLAY
22554 || it
->current_x
< it
->last_visible_x
))
22556 ptrdiff_t last_offset
= offset
;
22558 /* Advance to end of string or next format specifier. */
22559 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
22562 if (offset
- 1 != last_offset
)
22564 ptrdiff_t nchars
, nbytes
;
22566 /* Output to end of string or up to '%'. Field width
22567 is length of string. Don't output more than
22568 PRECISION allows us. */
22571 prec
= c_string_width (SDATA (elt
) + last_offset
,
22572 offset
- last_offset
, precision
- n
,
22575 switch (mode_line_target
)
22577 case MODE_LINE_NOPROP
:
22578 case MODE_LINE_TITLE
:
22579 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
22581 case MODE_LINE_STRING
:
22583 ptrdiff_t bytepos
= last_offset
;
22584 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22585 ptrdiff_t endpos
= (precision
<= 0
22586 ? string_byte_to_char (elt
, offset
)
22587 : charpos
+ nchars
);
22588 Lisp_Object mode_string
22589 = Fsubstring (elt
, make_number (charpos
),
22590 make_number (endpos
));
22591 n
+= store_mode_line_string (NULL
, mode_string
, false,
22595 case MODE_LINE_DISPLAY
:
22597 ptrdiff_t bytepos
= last_offset
;
22598 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22600 if (precision
<= 0)
22601 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
22602 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
22604 STRING_MULTIBYTE (elt
));
22609 else /* c == '%' */
22611 ptrdiff_t percent_position
= offset
;
22613 /* Get the specified minimum width. Zero means
22616 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
22617 field
= field
* 10 + c
- '0';
22619 /* Don't pad beyond the total padding allowed. */
22620 if (field_width
- n
> 0 && field
> field_width
- n
)
22621 field
= field_width
- n
;
22623 /* Note that either PRECISION <= 0 or N < PRECISION. */
22624 prec
= precision
- n
;
22627 n
+= display_mode_element (it
, depth
, field
, prec
,
22628 Vglobal_mode_string
, props
,
22633 ptrdiff_t bytepos
, charpos
;
22635 Lisp_Object string
;
22637 bytepos
= percent_position
;
22638 charpos
= (STRING_MULTIBYTE (elt
)
22639 ? string_byte_to_char (elt
, bytepos
)
22641 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
22642 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
22644 switch (mode_line_target
)
22646 case MODE_LINE_NOPROP
:
22647 case MODE_LINE_TITLE
:
22648 n
+= store_mode_line_noprop (spec
, field
, prec
);
22650 case MODE_LINE_STRING
:
22652 Lisp_Object tem
= build_string (spec
);
22653 props
= Ftext_properties_at (make_number (charpos
), elt
);
22654 /* Should only keep face property in props */
22655 n
+= store_mode_line_string (NULL
, tem
, false,
22656 field
, prec
, props
);
22659 case MODE_LINE_DISPLAY
:
22661 int nglyphs_before
, nwritten
;
22663 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
22664 nwritten
= display_string (spec
, string
, elt
,
22669 /* Assign to the glyphs written above the
22670 string where the `%x' came from, position
22674 struct glyph
*glyph
22675 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
22679 for (i
= 0; i
< nwritten
; ++i
)
22681 glyph
[i
].object
= elt
;
22682 glyph
[i
].charpos
= charpos
;
22699 /* A symbol: process the value of the symbol recursively
22700 as if it appeared here directly. Avoid error if symbol void.
22701 Special case: if value of symbol is a string, output the string
22704 register Lisp_Object tem
;
22706 /* If the variable is not marked as risky to set
22707 then its contents are risky to use. */
22708 if (NILP (Fget (elt
, Qrisky_local_variable
)))
22711 tem
= Fboundp (elt
);
22714 tem
= Fsymbol_value (elt
);
22715 /* If value is a string, output that string literally:
22716 don't check for % within it. */
22720 if (!EQ (tem
, elt
))
22722 /* Give up right away for nil or t. */
22732 register Lisp_Object car
, tem
;
22734 /* A cons cell: five distinct cases.
22735 If first element is :eval or :propertize, do something special.
22736 If first element is a string or a cons, process all the elements
22737 and effectively concatenate them.
22738 If first element is a negative number, truncate displaying cdr to
22739 at most that many characters. If positive, pad (with spaces)
22740 to at least that many characters.
22741 If first element is a symbol, process the cadr or caddr recursively
22742 according to whether the symbol's value is non-nil or nil. */
22744 if (EQ (car
, QCeval
))
22746 /* An element of the form (:eval FORM) means evaluate FORM
22747 and use the result as mode line elements. */
22752 if (CONSP (XCDR (elt
)))
22755 spec
= safe__eval (true, XCAR (XCDR (elt
)));
22756 n
+= display_mode_element (it
, depth
, field_width
- n
,
22757 precision
- n
, spec
, props
,
22761 else if (EQ (car
, QCpropertize
))
22763 /* An element of the form (:propertize ELT PROPS...)
22764 means display ELT but applying properties PROPS. */
22769 if (CONSP (XCDR (elt
)))
22770 n
+= display_mode_element (it
, depth
, field_width
- n
,
22771 precision
- n
, XCAR (XCDR (elt
)),
22772 XCDR (XCDR (elt
)), risky
);
22774 else if (SYMBOLP (car
))
22776 tem
= Fboundp (car
);
22780 /* elt is now the cdr, and we know it is a cons cell.
22781 Use its car if CAR has a non-nil value. */
22784 tem
= Fsymbol_value (car
);
22791 /* Symbol's value is nil (or symbol is unbound)
22792 Get the cddr of the original list
22793 and if possible find the caddr and use that. */
22797 else if (!CONSP (elt
))
22802 else if (INTEGERP (car
))
22804 register int lim
= XINT (car
);
22808 /* Negative int means reduce maximum width. */
22809 if (precision
<= 0)
22812 precision
= min (precision
, -lim
);
22816 /* Padding specified. Don't let it be more than
22817 current maximum. */
22819 lim
= min (precision
, lim
);
22821 /* If that's more padding than already wanted, queue it.
22822 But don't reduce padding already specified even if
22823 that is beyond the current truncation point. */
22824 field_width
= max (lim
, field_width
);
22828 else if (STRINGP (car
) || CONSP (car
))
22830 Lisp_Object halftail
= elt
;
22834 && (precision
<= 0 || n
< precision
))
22836 n
+= display_mode_element (it
, depth
,
22837 /* Do padding only after the last
22838 element in the list. */
22839 (! CONSP (XCDR (elt
))
22842 precision
- n
, XCAR (elt
),
22846 if ((len
& 1) == 0)
22847 halftail
= XCDR (halftail
);
22848 /* Check for cycle. */
22849 if (EQ (halftail
, elt
))
22858 elt
= build_string ("*invalid*");
22862 /* Pad to FIELD_WIDTH. */
22863 if (field_width
> 0 && n
< field_width
)
22865 switch (mode_line_target
)
22867 case MODE_LINE_NOPROP
:
22868 case MODE_LINE_TITLE
:
22869 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
22871 case MODE_LINE_STRING
:
22872 n
+= store_mode_line_string ("", Qnil
, false, field_width
- n
, 0,
22875 case MODE_LINE_DISPLAY
:
22876 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
22885 /* Store a mode-line string element in mode_line_string_list.
22887 If STRING is non-null, display that C string. Otherwise, the Lisp
22888 string LISP_STRING is displayed.
22890 FIELD_WIDTH is the minimum number of output glyphs to produce.
22891 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22892 with spaces. FIELD_WIDTH <= 0 means don't pad.
22894 PRECISION is the maximum number of characters to output from
22895 STRING. PRECISION <= 0 means don't truncate the string.
22897 If COPY_STRING, make a copy of LISP_STRING before adding
22898 properties to the string.
22900 PROPS are the properties to add to the string.
22901 The mode_line_string_face face property is always added to the string.
22905 store_mode_line_string (const char *string
, Lisp_Object lisp_string
,
22907 int field_width
, int precision
, Lisp_Object props
)
22912 if (string
!= NULL
)
22914 len
= strlen (string
);
22915 if (precision
> 0 && len
> precision
)
22917 lisp_string
= make_string (string
, len
);
22919 props
= mode_line_string_face_prop
;
22920 else if (!NILP (mode_line_string_face
))
22922 Lisp_Object face
= Fplist_get (props
, Qface
);
22923 props
= Fcopy_sequence (props
);
22925 face
= mode_line_string_face
;
22927 face
= list2 (face
, mode_line_string_face
);
22928 props
= Fplist_put (props
, Qface
, face
);
22930 Fadd_text_properties (make_number (0), make_number (len
),
22931 props
, lisp_string
);
22935 len
= XFASTINT (Flength (lisp_string
));
22936 if (precision
> 0 && len
> precision
)
22939 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
22942 if (!NILP (mode_line_string_face
))
22946 props
= Ftext_properties_at (make_number (0), lisp_string
);
22947 face
= Fplist_get (props
, Qface
);
22949 face
= mode_line_string_face
;
22951 face
= list2 (face
, mode_line_string_face
);
22952 props
= list2 (Qface
, face
);
22954 lisp_string
= Fcopy_sequence (lisp_string
);
22957 Fadd_text_properties (make_number (0), make_number (len
),
22958 props
, lisp_string
);
22963 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22967 if (field_width
> len
)
22969 field_width
-= len
;
22970 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
22972 Fadd_text_properties (make_number (0), make_number (field_width
),
22973 props
, lisp_string
);
22974 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22982 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
22984 doc
: /* Format a string out of a mode line format specification.
22985 First arg FORMAT specifies the mode line format (see `mode-line-format'
22986 for details) to use.
22988 By default, the format is evaluated for the currently selected window.
22990 Optional second arg FACE specifies the face property to put on all
22991 characters for which no face is specified. The value nil means the
22992 default face. The value t means whatever face the window's mode line
22993 currently uses (either `mode-line' or `mode-line-inactive',
22994 depending on whether the window is the selected window or not).
22995 An integer value means the value string has no text
22998 Optional third and fourth args WINDOW and BUFFER specify the window
22999 and buffer to use as the context for the formatting (defaults
23000 are the selected window and the WINDOW's buffer). */)
23001 (Lisp_Object format
, Lisp_Object face
,
23002 Lisp_Object window
, Lisp_Object buffer
)
23007 struct buffer
*old_buffer
= NULL
;
23009 bool no_props
= INTEGERP (face
);
23010 ptrdiff_t count
= SPECPDL_INDEX ();
23012 int string_start
= 0;
23014 w
= decode_any_window (window
);
23015 XSETWINDOW (window
, w
);
23018 buffer
= w
->contents
;
23019 CHECK_BUFFER (buffer
);
23021 /* Make formatting the modeline a non-op when noninteractive, otherwise
23022 there will be problems later caused by a partially initialized frame. */
23023 if (NILP (format
) || noninteractive
)
23024 return empty_unibyte_string
;
23029 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
23030 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
23031 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
23032 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
23033 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
23034 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
23035 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
23038 old_buffer
= current_buffer
;
23040 /* Save things including mode_line_proptrans_alist,
23041 and set that to nil so that we don't alter the outer value. */
23042 record_unwind_protect (unwind_format_mode_line
,
23043 format_mode_line_unwind_data
23044 (XFRAME (WINDOW_FRAME (w
)),
23045 old_buffer
, selected_window
, true));
23046 mode_line_proptrans_alist
= Qnil
;
23048 Fselect_window (window
, Qt
);
23049 set_buffer_internal_1 (XBUFFER (buffer
));
23051 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
23055 mode_line_target
= MODE_LINE_NOPROP
;
23056 mode_line_string_face_prop
= Qnil
;
23057 mode_line_string_list
= Qnil
;
23058 string_start
= MODE_LINE_NOPROP_LEN (0);
23062 mode_line_target
= MODE_LINE_STRING
;
23063 mode_line_string_list
= Qnil
;
23064 mode_line_string_face
= face
;
23065 mode_line_string_face_prop
23066 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
23069 push_kboard (FRAME_KBOARD (it
.f
));
23070 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, false);
23075 len
= MODE_LINE_NOPROP_LEN (string_start
);
23076 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
23080 mode_line_string_list
= Fnreverse (mode_line_string_list
);
23081 str
= Fmapconcat (Qidentity
, mode_line_string_list
,
23082 empty_unibyte_string
);
23085 unbind_to (count
, Qnil
);
23089 /* Write a null-terminated, right justified decimal representation of
23090 the positive integer D to BUF using a minimal field width WIDTH. */
23093 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
23095 register char *p
= buf
;
23103 *p
++ = d
% 10 + '0';
23108 for (width
-= (int) (p
- buf
); width
> 0; --width
)
23119 /* Write a null-terminated, right justified decimal and "human
23120 readable" representation of the nonnegative integer D to BUF using
23121 a minimal field width WIDTH. D should be smaller than 999.5e24. */
23123 static const char power_letter
[] =
23137 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
23139 /* We aim to represent the nonnegative integer D as
23140 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
23141 ptrdiff_t quotient
= d
;
23143 /* -1 means: do not use TENTHS. */
23147 /* Length of QUOTIENT.TENTHS as a string. */
23153 if (quotient
>= 1000)
23155 /* Scale to the appropriate EXPONENT. */
23158 remainder
= quotient
% 1000;
23162 while (quotient
>= 1000);
23164 /* Round to nearest and decide whether to use TENTHS or not. */
23167 tenths
= remainder
/ 100;
23168 if (remainder
% 100 >= 50)
23175 if (quotient
== 10)
23183 if (remainder
>= 500)
23185 if (quotient
< 999)
23196 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
23197 if (tenths
== -1 && quotient
<= 99)
23204 p
= psuffix
= buf
+ max (width
, length
);
23206 /* Print EXPONENT. */
23207 *psuffix
++ = power_letter
[exponent
];
23210 /* Print TENTHS. */
23213 *--p
= '0' + tenths
;
23217 /* Print QUOTIENT. */
23220 int digit
= quotient
% 10;
23221 *--p
= '0' + digit
;
23223 while ((quotient
/= 10) != 0);
23225 /* Print leading spaces. */
23230 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
23231 If EOL_FLAG, set also a mnemonic character for end-of-line
23232 type of CODING_SYSTEM. Return updated pointer into BUF. */
23234 static unsigned char invalid_eol_type
[] = "(*invalid*)";
23237 decode_mode_spec_coding (Lisp_Object coding_system
, char *buf
, bool eol_flag
)
23240 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
23241 const unsigned char *eol_str
;
23243 /* The EOL conversion we are using. */
23244 Lisp_Object eoltype
;
23246 val
= CODING_SYSTEM_SPEC (coding_system
);
23249 if (!VECTORP (val
)) /* Not yet decided. */
23251 *buf
++ = multibyte
? '-' : ' ';
23253 eoltype
= eol_mnemonic_undecided
;
23254 /* Don't mention EOL conversion if it isn't decided. */
23259 Lisp_Object eolvalue
;
23261 attrs
= AREF (val
, 0);
23262 eolvalue
= AREF (val
, 2);
23265 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
23270 /* The EOL conversion that is normal on this system. */
23272 if (NILP (eolvalue
)) /* Not yet decided. */
23273 eoltype
= eol_mnemonic_undecided
;
23274 else if (VECTORP (eolvalue
)) /* Not yet decided. */
23275 eoltype
= eol_mnemonic_undecided
;
23276 else /* eolvalue is Qunix, Qdos, or Qmac. */
23277 eoltype
= (EQ (eolvalue
, Qunix
)
23278 ? eol_mnemonic_unix
23279 : EQ (eolvalue
, Qdos
)
23280 ? eol_mnemonic_dos
: eol_mnemonic_mac
);
23286 /* Mention the EOL conversion if it is not the usual one. */
23287 if (STRINGP (eoltype
))
23289 eol_str
= SDATA (eoltype
);
23290 eol_str_len
= SBYTES (eoltype
);
23292 else if (CHARACTERP (eoltype
))
23294 int c
= XFASTINT (eoltype
);
23295 return buf
+ CHAR_STRING (c
, (unsigned char *) buf
);
23299 eol_str
= invalid_eol_type
;
23300 eol_str_len
= sizeof (invalid_eol_type
) - 1;
23302 memcpy (buf
, eol_str
, eol_str_len
);
23303 buf
+= eol_str_len
;
23309 /* Return a string for the output of a mode line %-spec for window W,
23310 generated by character C. FIELD_WIDTH > 0 means pad the string
23311 returned with spaces to that value. Return a Lisp string in
23312 *STRING if the resulting string is taken from that Lisp string.
23314 Note we operate on the current buffer for most purposes. */
23316 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
23318 static const char *
23319 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
23320 Lisp_Object
*string
)
23323 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23324 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
23325 /* We are going to use f->decode_mode_spec_buffer as the buffer to
23326 produce strings from numerical values, so limit preposterously
23327 large values of FIELD_WIDTH to avoid overrunning the buffer's
23328 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
23329 bytes plus the terminating null. */
23330 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
23331 struct buffer
*b
= current_buffer
;
23339 if (!NILP (BVAR (b
, read_only
)))
23341 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23346 /* This differs from %* only for a modified read-only buffer. */
23347 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23349 if (!NILP (BVAR (b
, read_only
)))
23354 /* This differs from %* in ignoring read-only-ness. */
23355 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23367 if (command_loop_level
> 5)
23369 p
= decode_mode_spec_buf
;
23370 for (i
= 0; i
< command_loop_level
; i
++)
23373 return decode_mode_spec_buf
;
23381 if (command_loop_level
> 5)
23383 p
= decode_mode_spec_buf
;
23384 for (i
= 0; i
< command_loop_level
; i
++)
23387 return decode_mode_spec_buf
;
23394 /* Let lots_of_dashes be a string of infinite length. */
23395 if (mode_line_target
== MODE_LINE_NOPROP
23396 || mode_line_target
== MODE_LINE_STRING
)
23398 if (field_width
<= 0
23399 || field_width
> sizeof (lots_of_dashes
))
23401 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
23402 decode_mode_spec_buf
[i
] = '-';
23403 decode_mode_spec_buf
[i
] = '\0';
23404 return decode_mode_spec_buf
;
23407 return lots_of_dashes
;
23411 obj
= BVAR (b
, name
);
23415 /* %c and %l are ignored in `frame-title-format'.
23416 (In redisplay_internal, the frame title is drawn _before_ the
23417 windows are updated, so the stuff which depends on actual
23418 window contents (such as %l) may fail to render properly, or
23419 even crash emacs.) */
23420 if (mode_line_target
== MODE_LINE_TITLE
)
23424 ptrdiff_t col
= current_column ();
23425 w
->column_number_displayed
= col
;
23426 pint2str (decode_mode_spec_buf
, width
, col
);
23427 return decode_mode_spec_buf
;
23431 #if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
23433 if (NILP (Vmemory_full
))
23436 return "!MEM FULL! ";
23443 /* %F displays the frame name. */
23444 if (!NILP (f
->title
))
23445 return SSDATA (f
->title
);
23446 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
23447 return SSDATA (f
->name
);
23451 obj
= BVAR (b
, filename
);
23456 ptrdiff_t size
= ZV
- BEGV
;
23457 pint2str (decode_mode_spec_buf
, width
, size
);
23458 return decode_mode_spec_buf
;
23463 ptrdiff_t size
= ZV
- BEGV
;
23464 pint2hrstr (decode_mode_spec_buf
, width
, size
);
23465 return decode_mode_spec_buf
;
23470 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
23471 ptrdiff_t topline
, nlines
, height
;
23474 /* %c and %l are ignored in `frame-title-format'. */
23475 if (mode_line_target
== MODE_LINE_TITLE
)
23478 startpos
= marker_position (w
->start
);
23479 startpos_byte
= marker_byte_position (w
->start
);
23480 height
= WINDOW_TOTAL_LINES (w
);
23482 /* If we decided that this buffer isn't suitable for line numbers,
23483 don't forget that too fast. */
23484 if (w
->base_line_pos
== -1)
23487 /* If the buffer is very big, don't waste time. */
23488 if (INTEGERP (Vline_number_display_limit
)
23489 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
23491 w
->base_line_pos
= 0;
23492 w
->base_line_number
= 0;
23496 if (w
->base_line_number
> 0
23497 && w
->base_line_pos
> 0
23498 && w
->base_line_pos
<= startpos
)
23500 line
= w
->base_line_number
;
23501 linepos
= w
->base_line_pos
;
23502 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
23507 linepos
= BUF_BEGV (b
);
23508 linepos_byte
= BUF_BEGV_BYTE (b
);
23511 /* Count lines from base line to window start position. */
23512 nlines
= display_count_lines (linepos_byte
,
23516 topline
= nlines
+ line
;
23518 /* Determine a new base line, if the old one is too close
23519 or too far away, or if we did not have one.
23520 "Too close" means it's plausible a scroll-down would
23521 go back past it. */
23522 if (startpos
== BUF_BEGV (b
))
23524 w
->base_line_number
= topline
;
23525 w
->base_line_pos
= BUF_BEGV (b
);
23527 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
23528 || linepos
== BUF_BEGV (b
))
23530 ptrdiff_t limit
= BUF_BEGV (b
);
23531 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
23532 ptrdiff_t position
;
23533 ptrdiff_t distance
=
23534 (height
* 2 + 30) * line_number_display_limit_width
;
23536 if (startpos
- distance
> limit
)
23538 limit
= startpos
- distance
;
23539 limit_byte
= CHAR_TO_BYTE (limit
);
23542 nlines
= display_count_lines (startpos_byte
,
23544 - (height
* 2 + 30),
23546 /* If we couldn't find the lines we wanted within
23547 line_number_display_limit_width chars per line,
23548 give up on line numbers for this window. */
23549 if (position
== limit_byte
&& limit
== startpos
- distance
)
23551 w
->base_line_pos
= -1;
23552 w
->base_line_number
= 0;
23556 w
->base_line_number
= topline
- nlines
;
23557 w
->base_line_pos
= BYTE_TO_CHAR (position
);
23560 /* Now count lines from the start pos to point. */
23561 nlines
= display_count_lines (startpos_byte
,
23562 PT_BYTE
, PT
, &junk
);
23564 /* Record that we did display the line number. */
23565 line_number_displayed
= true;
23567 /* Make the string to show. */
23568 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
23569 return decode_mode_spec_buf
;
23572 char *p
= decode_mode_spec_buf
;
23573 int pad
= width
- 2;
23579 return decode_mode_spec_buf
;
23585 obj
= BVAR (b
, mode_name
);
23589 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
23595 ptrdiff_t pos
= marker_position (w
->start
);
23596 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23598 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
23600 if (pos
<= BUF_BEGV (b
))
23605 else if (pos
<= BUF_BEGV (b
))
23609 if (total
> 1000000)
23610 /* Do it differently for a large value, to avoid overflow. */
23611 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23613 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23614 /* We can't normally display a 3-digit number,
23615 so get us a 2-digit number that is close. */
23618 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23619 return decode_mode_spec_buf
;
23623 /* Display percentage of size above the bottom of the screen. */
23626 ptrdiff_t toppos
= marker_position (w
->start
);
23627 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
23628 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23630 if (botpos
>= BUF_ZV (b
))
23632 if (toppos
<= BUF_BEGV (b
))
23639 if (total
> 1000000)
23640 /* Do it differently for a large value, to avoid overflow. */
23641 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23643 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23644 /* We can't normally display a 3-digit number,
23645 so get us a 2-digit number that is close. */
23648 if (toppos
<= BUF_BEGV (b
))
23649 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
23651 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23652 return decode_mode_spec_buf
;
23657 /* status of process */
23658 obj
= Fget_buffer_process (Fcurrent_buffer ());
23660 return "no process";
23662 obj
= Fsymbol_name (Fprocess_status (obj
));
23668 ptrdiff_t count
= inhibit_garbage_collection ();
23669 Lisp_Object curdir
= BVAR (current_buffer
, directory
);
23670 Lisp_Object val
= Qnil
;
23672 if (STRINGP (curdir
))
23673 val
= call1 (intern ("file-remote-p"), curdir
);
23675 unbind_to (count
, Qnil
);
23684 /* coding-system (not including end-of-line format) */
23686 /* coding-system (including end-of-line type) */
23688 bool eol_flag
= (c
== 'Z');
23689 char *p
= decode_mode_spec_buf
;
23691 if (! FRAME_WINDOW_P (f
))
23693 /* No need to mention EOL here--the terminal never needs
23694 to do EOL conversion. */
23695 p
= decode_mode_spec_coding (CODING_ID_NAME
23696 (FRAME_KEYBOARD_CODING (f
)->id
),
23698 p
= decode_mode_spec_coding (CODING_ID_NAME
23699 (FRAME_TERMINAL_CODING (f
)->id
),
23702 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
23705 #if false /* This proves to be annoying; I think we can do without. -- rms. */
23706 #ifdef subprocesses
23707 obj
= Fget_buffer_process (Fcurrent_buffer ());
23708 if (PROCESSP (obj
))
23710 p
= decode_mode_spec_coding
23711 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
23712 p
= decode_mode_spec_coding
23713 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
23715 #endif /* subprocesses */
23718 return decode_mode_spec_buf
;
23725 return SSDATA (obj
);
23732 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
23733 means count lines back from START_BYTE. But don't go beyond
23734 LIMIT_BYTE. Return the number of lines thus found (always
23737 Set *BYTE_POS_PTR to the byte position where we stopped. This is
23738 either the position COUNT lines after/before START_BYTE, if we
23739 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
23743 display_count_lines (ptrdiff_t start_byte
,
23744 ptrdiff_t limit_byte
, ptrdiff_t count
,
23745 ptrdiff_t *byte_pos_ptr
)
23747 register unsigned char *cursor
;
23748 unsigned char *base
;
23750 register ptrdiff_t ceiling
;
23751 register unsigned char *ceiling_addr
;
23752 ptrdiff_t orig_count
= count
;
23754 /* If we are not in selective display mode,
23755 check only for newlines. */
23756 bool selective_display
23757 = (!NILP (BVAR (current_buffer
, selective_display
))
23758 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
23762 while (start_byte
< limit_byte
)
23764 ceiling
= BUFFER_CEILING_OF (start_byte
);
23765 ceiling
= min (limit_byte
- 1, ceiling
);
23766 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
23767 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
23771 if (selective_display
)
23773 while (*cursor
!= '\n' && *cursor
!= 015
23774 && ++cursor
!= ceiling_addr
)
23776 if (cursor
== ceiling_addr
)
23781 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
23790 start_byte
+= cursor
- base
;
23791 *byte_pos_ptr
= start_byte
;
23795 while (cursor
< ceiling_addr
);
23797 start_byte
+= ceiling_addr
- base
;
23802 while (start_byte
> limit_byte
)
23804 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
23805 ceiling
= max (limit_byte
, ceiling
);
23806 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
23807 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
23810 if (selective_display
)
23812 while (--cursor
>= ceiling_addr
23813 && *cursor
!= '\n' && *cursor
!= 015)
23815 if (cursor
< ceiling_addr
)
23820 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
23827 start_byte
+= cursor
- base
+ 1;
23828 *byte_pos_ptr
= start_byte
;
23829 /* When scanning backwards, we should
23830 not count the newline posterior to which we stop. */
23831 return - orig_count
- 1;
23834 start_byte
+= ceiling_addr
- base
;
23838 *byte_pos_ptr
= limit_byte
;
23841 return - orig_count
+ count
;
23842 return orig_count
- count
;
23848 /***********************************************************************
23850 ***********************************************************************/
23852 /* Display a NUL-terminated string, starting with index START.
23854 If STRING is non-null, display that C string. Otherwise, the Lisp
23855 string LISP_STRING is displayed. There's a case that STRING is
23856 non-null and LISP_STRING is not nil. It means STRING is a string
23857 data of LISP_STRING. In that case, we display LISP_STRING while
23858 ignoring its text properties.
23860 If FACE_STRING is not nil, FACE_STRING_POS is a position in
23861 FACE_STRING. Display STRING or LISP_STRING with the face at
23862 FACE_STRING_POS in FACE_STRING:
23864 Display the string in the environment given by IT, but use the
23865 standard display table, temporarily.
23867 FIELD_WIDTH is the minimum number of output glyphs to produce.
23868 If STRING has fewer characters than FIELD_WIDTH, pad to the right
23869 with spaces. If STRING has more characters, more than FIELD_WIDTH
23870 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
23872 PRECISION is the maximum number of characters to output from
23873 STRING. PRECISION < 0 means don't truncate the string.
23875 This is roughly equivalent to printf format specifiers:
23877 FIELD_WIDTH PRECISION PRINTF
23878 ----------------------------------------
23884 MULTIBYTE zero means do not display multibyte chars, > 0 means do
23885 display them, and < 0 means obey the current buffer's value of
23886 enable_multibyte_characters.
23888 Value is the number of columns displayed. */
23891 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
23892 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
23893 int field_width
, int precision
, int max_x
, int multibyte
)
23895 int hpos_at_start
= it
->hpos
;
23896 int saved_face_id
= it
->face_id
;
23897 struct glyph_row
*row
= it
->glyph_row
;
23898 ptrdiff_t it_charpos
;
23900 /* Initialize the iterator IT for iteration over STRING beginning
23901 with index START. */
23902 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
23903 precision
, field_width
, multibyte
);
23904 if (string
&& STRINGP (lisp_string
))
23905 /* LISP_STRING is the one returned by decode_mode_spec. We should
23906 ignore its text properties. */
23907 it
->stop_charpos
= it
->end_charpos
;
23909 /* If displaying STRING, set up the face of the iterator from
23910 FACE_STRING, if that's given. */
23911 if (STRINGP (face_string
))
23917 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
23918 0, &endptr
, it
->base_face_id
, false);
23919 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23920 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
23923 /* Set max_x to the maximum allowed X position. Don't let it go
23924 beyond the right edge of the window. */
23926 max_x
= it
->last_visible_x
;
23928 max_x
= min (max_x
, it
->last_visible_x
);
23930 /* Skip over display elements that are not visible. because IT->w is
23932 if (it
->current_x
< it
->first_visible_x
)
23933 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
23934 MOVE_TO_POS
| MOVE_TO_X
);
23936 row
->ascent
= it
->max_ascent
;
23937 row
->height
= it
->max_ascent
+ it
->max_descent
;
23938 row
->phys_ascent
= it
->max_phys_ascent
;
23939 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
23940 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
23942 if (STRINGP (it
->string
))
23943 it_charpos
= IT_STRING_CHARPOS (*it
);
23945 it_charpos
= IT_CHARPOS (*it
);
23947 /* This condition is for the case that we are called with current_x
23948 past last_visible_x. */
23949 while (it
->current_x
< max_x
)
23951 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
23953 /* Get the next display element. */
23954 if (!get_next_display_element (it
))
23957 /* Produce glyphs. */
23958 x_before
= it
->current_x
;
23959 n_glyphs_before
= row
->used
[TEXT_AREA
];
23960 PRODUCE_GLYPHS (it
);
23962 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
23965 while (i
< nglyphs
)
23967 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
23969 if (it
->line_wrap
!= TRUNCATE
23970 && x
+ glyph
->pixel_width
> max_x
)
23972 /* End of continued line or max_x reached. */
23973 if (CHAR_GLYPH_PADDING_P (*glyph
))
23975 /* A wide character is unbreakable. */
23976 if (row
->reversed_p
)
23977 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23978 - n_glyphs_before
);
23979 row
->used
[TEXT_AREA
] = n_glyphs_before
;
23980 it
->current_x
= x_before
;
23984 if (row
->reversed_p
)
23985 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23986 - (n_glyphs_before
+ i
));
23987 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
23992 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
23994 /* Glyph is at least partially visible. */
23996 if (x
< it
->first_visible_x
)
23997 row
->x
= x
- it
->first_visible_x
;
24001 /* Glyph is off the left margin of the display area.
24002 Should not happen. */
24006 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
24007 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
24008 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
24009 row
->phys_height
= max (row
->phys_height
,
24010 it
->max_phys_ascent
+ it
->max_phys_descent
);
24011 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
24012 it
->max_extra_line_spacing
);
24013 x
+= glyph
->pixel_width
;
24017 /* Stop if max_x reached. */
24021 /* Stop at line ends. */
24022 if (ITERATOR_AT_END_OF_LINE_P (it
))
24024 it
->continuation_lines_width
= 0;
24028 set_iterator_to_next (it
, true);
24029 if (STRINGP (it
->string
))
24030 it_charpos
= IT_STRING_CHARPOS (*it
);
24032 it_charpos
= IT_CHARPOS (*it
);
24034 /* Stop if truncating at the right edge. */
24035 if (it
->line_wrap
== TRUNCATE
24036 && it
->current_x
>= it
->last_visible_x
)
24038 /* Add truncation mark, but don't do it if the line is
24039 truncated at a padding space. */
24040 if (it_charpos
< it
->string_nchars
)
24042 if (!FRAME_WINDOW_P (it
->f
))
24046 if (it
->current_x
> it
->last_visible_x
)
24048 if (!row
->reversed_p
)
24050 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
24051 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
24056 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
24057 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
24059 unproduce_glyphs (it
, ii
+ 1);
24060 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
24062 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
24064 row
->used
[TEXT_AREA
] = ii
;
24065 produce_special_glyphs (it
, IT_TRUNCATION
);
24068 produce_special_glyphs (it
, IT_TRUNCATION
);
24070 row
->truncated_on_right_p
= true;
24076 /* Maybe insert a truncation at the left. */
24077 if (it
->first_visible_x
24080 if (!FRAME_WINDOW_P (it
->f
)
24081 || (row
->reversed_p
24082 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
24083 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
24084 insert_left_trunc_glyphs (it
);
24085 row
->truncated_on_left_p
= true;
24088 it
->face_id
= saved_face_id
;
24090 /* Value is number of columns displayed. */
24091 return it
->hpos
- hpos_at_start
;
24096 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
24097 appears as an element of LIST or as the car of an element of LIST.
24098 If PROPVAL is a list, compare each element against LIST in that
24099 way, and return 1/2 if any element of PROPVAL is found in LIST.
24100 Otherwise return 0. This function cannot quit.
24101 The return value is 2 if the text is invisible but with an ellipsis
24102 and 1 if it's invisible and without an ellipsis. */
24105 invisible_prop (Lisp_Object propval
, Lisp_Object list
)
24107 Lisp_Object tail
, proptail
;
24109 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
24111 register Lisp_Object tem
;
24113 if (EQ (propval
, tem
))
24115 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
24116 return NILP (XCDR (tem
)) ? 1 : 2;
24119 if (CONSP (propval
))
24121 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
24123 Lisp_Object propelt
;
24124 propelt
= XCAR (proptail
);
24125 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
24127 register Lisp_Object tem
;
24129 if (EQ (propelt
, tem
))
24131 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
24132 return NILP (XCDR (tem
)) ? 1 : 2;
24140 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
24141 doc
: /* Non-nil if the property makes the text invisible.
24142 POS-OR-PROP can be a marker or number, in which case it is taken to be
24143 a position in the current buffer and the value of the `invisible' property
24144 is checked; or it can be some other value, which is then presumed to be the
24145 value of the `invisible' property of the text of interest.
24146 The non-nil value returned can be t for truly invisible text or something
24147 else if the text is replaced by an ellipsis. */)
24148 (Lisp_Object pos_or_prop
)
24151 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
24152 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
24154 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
24155 return (invis
== 0 ? Qnil
24157 : make_number (invis
));
24160 /* Calculate a width or height in pixels from a specification using
24161 the following elements:
24164 NUM - a (fractional) multiple of the default font width/height
24165 (NUM) - specifies exactly NUM pixels
24166 UNIT - a fixed number of pixels, see below.
24167 ELEMENT - size of a display element in pixels, see below.
24168 (NUM . SPEC) - equals NUM * SPEC
24169 (+ SPEC SPEC ...) - add pixel values
24170 (- SPEC SPEC ...) - subtract pixel values
24171 (- SPEC) - negate pixel value
24174 INT or FLOAT - a number constant
24175 SYMBOL - use symbol's (buffer local) variable binding.
24178 in - pixels per inch *)
24179 mm - pixels per 1/1000 meter *)
24180 cm - pixels per 1/100 meter *)
24181 width - width of current font in pixels.
24182 height - height of current font in pixels.
24184 *) using the ratio(s) defined in display-pixels-per-inch.
24188 left-fringe - left fringe width in pixels
24189 right-fringe - right fringe width in pixels
24191 left-margin - left margin width in pixels
24192 right-margin - right margin width in pixels
24194 scroll-bar - scroll-bar area width in pixels
24198 Pixels corresponding to 5 inches:
24201 Total width of non-text areas on left side of window (if scroll-bar is on left):
24202 '(space :width (+ left-fringe left-margin scroll-bar))
24204 Align to first text column (in header line):
24205 '(space :align-to 0)
24207 Align to middle of text area minus half the width of variable `my-image'
24208 containing a loaded image:
24209 '(space :align-to (0.5 . (- text my-image)))
24211 Width of left margin minus width of 1 character in the default font:
24212 '(space :width (- left-margin 1))
24214 Width of left margin minus width of 2 characters in the current font:
24215 '(space :width (- left-margin (2 . width)))
24217 Center 1 character over left-margin (in header line):
24218 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
24220 Different ways to express width of left fringe plus left margin minus one pixel:
24221 '(space :width (- (+ left-fringe left-margin) (1)))
24222 '(space :width (+ left-fringe left-margin (- (1))))
24223 '(space :width (+ left-fringe left-margin (-1)))
24228 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
24229 struct font
*font
, bool width_p
, int *align_to
)
24233 # define OK_PIXELS(val) (*res = (val), true)
24234 # define OK_ALIGN_TO(val) (*align_to = (val), true)
24237 return OK_PIXELS (0);
24239 eassert (FRAME_LIVE_P (it
->f
));
24241 if (SYMBOLP (prop
))
24243 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
24245 char *unit
= SSDATA (SYMBOL_NAME (prop
));
24247 if (unit
[0] == 'i' && unit
[1] == 'n')
24249 else if (unit
[0] == 'm' && unit
[1] == 'm')
24251 else if (unit
[0] == 'c' && unit
[1] == 'm')
24257 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
24258 : FRAME_RES_Y (it
->f
));
24261 return OK_PIXELS (ppi
/ pixels
);
24266 #ifdef HAVE_WINDOW_SYSTEM
24267 if (EQ (prop
, Qheight
))
24268 return OK_PIXELS (font
24269 ? normal_char_height (font
, -1)
24270 : FRAME_LINE_HEIGHT (it
->f
));
24271 if (EQ (prop
, Qwidth
))
24272 return OK_PIXELS (font
24273 ? FONT_WIDTH (font
)
24274 : FRAME_COLUMN_WIDTH (it
->f
));
24276 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
24277 return OK_PIXELS (1);
24280 if (EQ (prop
, Qtext
))
24281 return OK_PIXELS (width_p
24282 ? window_box_width (it
->w
, TEXT_AREA
)
24283 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
24285 if (align_to
&& *align_to
< 0)
24288 if (EQ (prop
, Qleft
))
24289 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
24290 if (EQ (prop
, Qright
))
24291 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
24292 if (EQ (prop
, Qcenter
))
24293 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
24294 + window_box_width (it
->w
, TEXT_AREA
) / 2);
24295 if (EQ (prop
, Qleft_fringe
))
24296 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24297 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
24298 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
24299 if (EQ (prop
, Qright_fringe
))
24300 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24301 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
24302 : window_box_right_offset (it
->w
, TEXT_AREA
));
24303 if (EQ (prop
, Qleft_margin
))
24304 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
24305 if (EQ (prop
, Qright_margin
))
24306 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
24307 if (EQ (prop
, Qscroll_bar
))
24308 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
24310 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
24311 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
24312 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
24317 if (EQ (prop
, Qleft_fringe
))
24318 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
24319 if (EQ (prop
, Qright_fringe
))
24320 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
24321 if (EQ (prop
, Qleft_margin
))
24322 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
24323 if (EQ (prop
, Qright_margin
))
24324 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
24325 if (EQ (prop
, Qscroll_bar
))
24326 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
24329 prop
= buffer_local_value (prop
, it
->w
->contents
);
24330 if (EQ (prop
, Qunbound
))
24334 if (NUMBERP (prop
))
24336 int base_unit
= (width_p
24337 ? FRAME_COLUMN_WIDTH (it
->f
)
24338 : FRAME_LINE_HEIGHT (it
->f
));
24339 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
24344 Lisp_Object car
= XCAR (prop
);
24345 Lisp_Object cdr
= XCDR (prop
);
24349 #ifdef HAVE_WINDOW_SYSTEM
24350 if (FRAME_WINDOW_P (it
->f
)
24351 && valid_image_p (prop
))
24353 ptrdiff_t id
= lookup_image (it
->f
, prop
);
24354 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
24356 return OK_PIXELS (width_p
? img
->width
: img
->height
);
24358 if (FRAME_WINDOW_P (it
->f
) && valid_xwidget_spec_p (prop
))
24360 // TODO: Don't return dummy size.
24361 return OK_PIXELS (100);
24364 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
24370 while (CONSP (cdr
))
24372 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
24373 font
, width_p
, align_to
))
24376 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= false;
24381 if (EQ (car
, Qminus
))
24383 return OK_PIXELS (pixels
);
24386 car
= buffer_local_value (car
, it
->w
->contents
);
24387 if (EQ (car
, Qunbound
))
24394 pixels
= XFLOATINT (car
);
24396 return OK_PIXELS (pixels
);
24397 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
24398 font
, width_p
, align_to
))
24399 return OK_PIXELS (pixels
* fact
);
24410 get_font_ascent_descent (struct font
*font
, int *ascent
, int *descent
)
24412 #ifdef HAVE_WINDOW_SYSTEM
24413 normal_char_ascent_descent (font
, -1, ascent
, descent
);
24421 /***********************************************************************
24423 ***********************************************************************/
24425 #ifdef HAVE_WINDOW_SYSTEM
24430 dump_glyph_string (struct glyph_string
*s
)
24432 fprintf (stderr
, "glyph string\n");
24433 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
24434 s
->x
, s
->y
, s
->width
, s
->height
);
24435 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
24436 fprintf (stderr
, " hl = %d\n", s
->hl
);
24437 fprintf (stderr
, " left overhang = %d, right = %d\n",
24438 s
->left_overhang
, s
->right_overhang
);
24439 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
24440 fprintf (stderr
, " extends to end of line = %d\n",
24441 s
->extends_to_end_of_line_p
);
24442 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
24443 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
24446 #endif /* GLYPH_DEBUG */
24448 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
24449 of XChar2b structures for S; it can't be allocated in
24450 init_glyph_string because it must be allocated via `alloca'. W
24451 is the window on which S is drawn. ROW and AREA are the glyph row
24452 and area within the row from which S is constructed. START is the
24453 index of the first glyph structure covered by S. HL is a
24454 face-override for drawing S. */
24457 #define OPTIONAL_HDC(hdc) HDC hdc,
24458 #define DECLARE_HDC(hdc) HDC hdc;
24459 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
24460 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
24463 #ifndef OPTIONAL_HDC
24464 #define OPTIONAL_HDC(hdc)
24465 #define DECLARE_HDC(hdc)
24466 #define ALLOCATE_HDC(hdc, f)
24467 #define RELEASE_HDC(hdc, f)
24471 init_glyph_string (struct glyph_string
*s
,
24473 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
24474 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
24476 memset (s
, 0, sizeof *s
);
24478 s
->f
= XFRAME (w
->frame
);
24482 s
->display
= FRAME_X_DISPLAY (s
->f
);
24483 s
->window
= FRAME_X_WINDOW (s
->f
);
24484 s
->char2b
= char2b
;
24488 s
->first_glyph
= row
->glyphs
[area
] + start
;
24489 s
->height
= row
->height
;
24490 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
24491 s
->ybase
= s
->y
+ row
->ascent
;
24495 /* Append the list of glyph strings with head H and tail T to the list
24496 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
24499 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24500 struct glyph_string
*h
, struct glyph_string
*t
)
24514 /* Prepend the list of glyph strings with head H and tail T to the
24515 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
24519 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24520 struct glyph_string
*h
, struct glyph_string
*t
)
24534 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
24535 Set *HEAD and *TAIL to the resulting list. */
24538 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
24539 struct glyph_string
*s
)
24541 s
->next
= s
->prev
= NULL
;
24542 append_glyph_string_lists (head
, tail
, s
, s
);
24546 /* Get face and two-byte form of character C in face FACE_ID on frame F.
24547 The encoding of C is returned in *CHAR2B. DISPLAY_P means
24548 make sure that X resources for the face returned are allocated.
24549 Value is a pointer to a realized face that is ready for display if
24552 static struct face
*
24553 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
24554 XChar2b
*char2b
, bool display_p
)
24556 struct face
*face
= FACE_FROM_ID (f
, face_id
);
24561 code
= face
->font
->driver
->encode_char (face
->font
, c
);
24563 if (code
== FONT_INVALID_CODE
)
24566 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24568 /* Make sure X resources of the face are allocated. */
24569 #ifdef HAVE_X_WINDOWS
24573 eassert (face
!= NULL
);
24574 prepare_face_for_display (f
, face
);
24581 /* Get face and two-byte form of character glyph GLYPH on frame F.
24582 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
24583 a pointer to a realized face that is ready for display. */
24585 static struct face
*
24586 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
24592 eassert (glyph
->type
== CHAR_GLYPH
);
24593 face
= FACE_FROM_ID (f
, glyph
->face_id
);
24595 /* Make sure X resources of the face are allocated. */
24596 eassert (face
!= NULL
);
24597 prepare_face_for_display (f
, face
);
24601 if (CHAR_BYTE8_P (glyph
->u
.ch
))
24602 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
24604 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
24606 if (code
== FONT_INVALID_CODE
)
24610 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24615 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
24616 Return true iff FONT has a glyph for C. */
24619 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
24623 if (CHAR_BYTE8_P (c
))
24624 code
= CHAR_TO_BYTE8 (c
);
24626 code
= font
->driver
->encode_char (font
, c
);
24628 if (code
== FONT_INVALID_CODE
)
24630 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24635 /* Fill glyph string S with composition components specified by S->cmp.
24637 BASE_FACE is the base face of the composition.
24638 S->cmp_from is the index of the first component for S.
24640 OVERLAPS non-zero means S should draw the foreground only, and use
24641 its physical height for clipping. See also draw_glyphs.
24643 Value is the index of a component not in S. */
24646 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
24650 /* For all glyphs of this composition, starting at the offset
24651 S->cmp_from, until we reach the end of the definition or encounter a
24652 glyph that requires the different face, add it to S. */
24657 s
->for_overlaps
= overlaps
;
24660 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
24662 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
24664 /* TAB in a composition means display glyphs with padding space
24665 on the left or right. */
24668 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
24671 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
24672 s
->char2b
+ i
, true);
24678 s
->font
= s
->face
->font
;
24680 else if (s
->face
!= face
)
24688 if (s
->face
== NULL
)
24690 s
->face
= base_face
->ascii_face
;
24691 s
->font
= s
->face
->font
;
24694 /* All glyph strings for the same composition has the same width,
24695 i.e. the width set for the first component of the composition. */
24696 s
->width
= s
->first_glyph
->pixel_width
;
24698 /* If the specified font could not be loaded, use the frame's
24699 default font, but record the fact that we couldn't load it in
24700 the glyph string so that we can draw rectangles for the
24701 characters of the glyph string. */
24702 if (s
->font
== NULL
)
24704 s
->font_not_found_p
= true;
24705 s
->font
= FRAME_FONT (s
->f
);
24708 /* Adjust base line for subscript/superscript text. */
24709 s
->ybase
+= s
->first_glyph
->voffset
;
24715 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
24716 int start
, int end
, int overlaps
)
24718 struct glyph
*glyph
, *last
;
24719 Lisp_Object lgstring
;
24722 s
->for_overlaps
= overlaps
;
24723 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24724 last
= s
->row
->glyphs
[s
->area
] + end
;
24725 s
->cmp_id
= glyph
->u
.cmp
.id
;
24726 s
->cmp_from
= glyph
->slice
.cmp
.from
;
24727 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
24728 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24729 lgstring
= composition_gstring_from_id (s
->cmp_id
);
24730 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
24732 while (glyph
< last
24733 && glyph
->u
.cmp
.automatic
24734 && glyph
->u
.cmp
.id
== s
->cmp_id
24735 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
24736 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
24738 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
24740 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
24741 unsigned code
= LGLYPH_CODE (lglyph
);
24743 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
24745 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
24746 return glyph
- s
->row
->glyphs
[s
->area
];
24750 /* Fill glyph string S from a sequence glyphs for glyphless characters.
24751 See the comment of fill_glyph_string for arguments.
24752 Value is the index of the first glyph not in S. */
24756 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
24757 int start
, int end
, int overlaps
)
24759 struct glyph
*glyph
, *last
;
24762 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
24763 s
->for_overlaps
= overlaps
;
24764 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24765 last
= s
->row
->glyphs
[s
->area
] + end
;
24766 voffset
= glyph
->voffset
;
24767 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24768 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
24770 s
->width
= glyph
->pixel_width
;
24772 while (glyph
< last
24773 && glyph
->type
== GLYPHLESS_GLYPH
24774 && glyph
->voffset
== voffset
24775 && glyph
->face_id
== face_id
)
24778 s
->width
+= glyph
->pixel_width
;
24781 s
->ybase
+= voffset
;
24782 return glyph
- s
->row
->glyphs
[s
->area
];
24786 /* Fill glyph string S from a sequence of character glyphs.
24788 FACE_ID is the face id of the string. START is the index of the
24789 first glyph to consider, END is the index of the last + 1.
24790 OVERLAPS non-zero means S should draw the foreground only, and use
24791 its physical height for clipping. See also draw_glyphs.
24793 Value is the index of the first glyph not in S. */
24796 fill_glyph_string (struct glyph_string
*s
, int face_id
,
24797 int start
, int end
, int overlaps
)
24799 struct glyph
*glyph
, *last
;
24801 bool glyph_not_available_p
;
24803 eassert (s
->f
== XFRAME (s
->w
->frame
));
24804 eassert (s
->nchars
== 0);
24805 eassert (start
>= 0 && end
> start
);
24807 s
->for_overlaps
= overlaps
;
24808 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24809 last
= s
->row
->glyphs
[s
->area
] + end
;
24810 voffset
= glyph
->voffset
;
24811 s
->padding_p
= glyph
->padding_p
;
24812 glyph_not_available_p
= glyph
->glyph_not_available_p
;
24814 while (glyph
< last
24815 && glyph
->type
== CHAR_GLYPH
24816 && glyph
->voffset
== voffset
24817 /* Same face id implies same font, nowadays. */
24818 && glyph
->face_id
== face_id
24819 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
24821 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
24822 s
->char2b
+ s
->nchars
);
24824 eassert (s
->nchars
<= end
- start
);
24825 s
->width
+= glyph
->pixel_width
;
24826 if (glyph
++->padding_p
!= s
->padding_p
)
24830 s
->font
= s
->face
->font
;
24832 /* If the specified font could not be loaded, use the frame's font,
24833 but record the fact that we couldn't load it in
24834 S->font_not_found_p so that we can draw rectangles for the
24835 characters of the glyph string. */
24836 if (s
->font
== NULL
|| glyph_not_available_p
)
24838 s
->font_not_found_p
= true;
24839 s
->font
= FRAME_FONT (s
->f
);
24842 /* Adjust base line for subscript/superscript text. */
24843 s
->ybase
+= voffset
;
24845 eassert (s
->face
&& s
->face
->gc
);
24846 return glyph
- s
->row
->glyphs
[s
->area
];
24850 /* Fill glyph string S from image glyph S->first_glyph. */
24853 fill_image_glyph_string (struct glyph_string
*s
)
24855 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
24856 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
24858 s
->slice
= s
->first_glyph
->slice
.img
;
24859 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24860 s
->font
= s
->face
->font
;
24861 s
->width
= s
->first_glyph
->pixel_width
;
24863 /* Adjust base line for subscript/superscript text. */
24864 s
->ybase
+= s
->first_glyph
->voffset
;
24868 #ifdef HAVE_XWIDGETS
24870 fill_xwidget_glyph_string (struct glyph_string
*s
)
24872 eassert (s
->first_glyph
->type
== XWIDGET_GLYPH
);
24873 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24874 s
->font
= s
->face
->font
;
24875 s
->width
= s
->first_glyph
->pixel_width
;
24876 s
->ybase
+= s
->first_glyph
->voffset
;
24877 s
->xwidget
= s
->first_glyph
->u
.xwidget
;
24880 /* Fill glyph string S from a sequence of stretch glyphs.
24882 START is the index of the first glyph to consider,
24883 END is the index of the last + 1.
24885 Value is the index of the first glyph not in S. */
24888 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
24890 struct glyph
*glyph
, *last
;
24891 int voffset
, face_id
;
24893 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
24895 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24896 last
= s
->row
->glyphs
[s
->area
] + end
;
24897 face_id
= glyph
->face_id
;
24898 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24899 s
->font
= s
->face
->font
;
24900 s
->width
= glyph
->pixel_width
;
24902 voffset
= glyph
->voffset
;
24906 && glyph
->type
== STRETCH_GLYPH
24907 && glyph
->voffset
== voffset
24908 && glyph
->face_id
== face_id
);
24910 s
->width
+= glyph
->pixel_width
;
24912 /* Adjust base line for subscript/superscript text. */
24913 s
->ybase
+= voffset
;
24915 /* The case that face->gc == 0 is handled when drawing the glyph
24916 string by calling prepare_face_for_display. */
24918 return glyph
- s
->row
->glyphs
[s
->area
];
24921 static struct font_metrics
*
24922 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
24924 static struct font_metrics metrics
;
24929 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
24930 if (code
== FONT_INVALID_CODE
)
24932 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
24936 /* A subroutine that computes "normal" values of ASCENT and DESCENT
24937 for FONT. Values are taken from font-global ones, except for fonts
24938 that claim preposterously large values, but whose glyphs actually
24939 have reasonable dimensions. C is the character to use for metrics
24940 if the font-global values are too large; if C is negative, the
24941 function selects a default character. */
24943 normal_char_ascent_descent (struct font
*font
, int c
, int *ascent
, int *descent
)
24945 *ascent
= FONT_BASE (font
);
24946 *descent
= FONT_DESCENT (font
);
24948 if (FONT_TOO_HIGH (font
))
24952 /* Get metrics of C, defaulting to a reasonably sized ASCII
24954 if (get_char_glyph_code (c
>= 0 ? c
: '{', font
, &char2b
))
24956 struct font_metrics
*pcm
= get_per_char_metric (font
, &char2b
);
24958 if (!(pcm
->width
== 0 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0))
24960 /* We add 1 pixel to character dimensions as heuristics
24961 that produces nicer display, e.g. when the face has
24962 the box attribute. */
24963 *ascent
= pcm
->ascent
+ 1;
24964 *descent
= pcm
->descent
+ 1;
24970 /* A subroutine that computes a reasonable "normal character height"
24971 for fonts that claim preposterously large vertical dimensions, but
24972 whose glyphs are actually reasonably sized. C is the character
24973 whose metrics to use for those fonts, or -1 for default
24976 normal_char_height (struct font
*font
, int c
)
24978 int ascent
, descent
;
24980 normal_char_ascent_descent (font
, c
, &ascent
, &descent
);
24982 return ascent
+ descent
;
24986 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
24987 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
24988 assumed to be zero. */
24991 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
24993 *left
= *right
= 0;
24995 if (glyph
->type
== CHAR_GLYPH
)
24998 struct face
*face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
);
25001 struct font_metrics
*pcm
= get_per_char_metric (face
->font
, &char2b
);
25004 if (pcm
->rbearing
> pcm
->width
)
25005 *right
= pcm
->rbearing
- pcm
->width
;
25006 if (pcm
->lbearing
< 0)
25007 *left
= -pcm
->lbearing
;
25011 else if (glyph
->type
== COMPOSITE_GLYPH
)
25013 if (! glyph
->u
.cmp
.automatic
)
25015 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
25017 if (cmp
->rbearing
> cmp
->pixel_width
)
25018 *right
= cmp
->rbearing
- cmp
->pixel_width
;
25019 if (cmp
->lbearing
< 0)
25020 *left
= - cmp
->lbearing
;
25024 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
25025 struct font_metrics metrics
;
25027 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
25028 glyph
->slice
.cmp
.to
+ 1, &metrics
);
25029 if (metrics
.rbearing
> metrics
.width
)
25030 *right
= metrics
.rbearing
- metrics
.width
;
25031 if (metrics
.lbearing
< 0)
25032 *left
= - metrics
.lbearing
;
25038 /* Return the index of the first glyph preceding glyph string S that
25039 is overwritten by S because of S's left overhang. Value is -1
25040 if no glyphs are overwritten. */
25043 left_overwritten (struct glyph_string
*s
)
25047 if (s
->left_overhang
)
25050 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25051 int first
= s
->first_glyph
- glyphs
;
25053 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
25054 x
-= glyphs
[i
].pixel_width
;
25065 /* Return the index of the first glyph preceding glyph string S that
25066 is overwriting S because of its right overhang. Value is -1 if no
25067 glyph in front of S overwrites S. */
25070 left_overwriting (struct glyph_string
*s
)
25073 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25074 int first
= s
->first_glyph
- glyphs
;
25078 for (i
= first
- 1; i
>= 0; --i
)
25081 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
25084 x
-= glyphs
[i
].pixel_width
;
25091 /* Return the index of the last glyph following glyph string S that is
25092 overwritten by S because of S's right overhang. Value is -1 if
25093 no such glyph is found. */
25096 right_overwritten (struct glyph_string
*s
)
25100 if (s
->right_overhang
)
25103 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25104 int first
= (s
->first_glyph
- glyphs
25105 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
25106 int end
= s
->row
->used
[s
->area
];
25108 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
25109 x
+= glyphs
[i
].pixel_width
;
25118 /* Return the index of the last glyph following glyph string S that
25119 overwrites S because of its left overhang. Value is negative
25120 if no such glyph is found. */
25123 right_overwriting (struct glyph_string
*s
)
25126 int end
= s
->row
->used
[s
->area
];
25127 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
25128 int first
= (s
->first_glyph
- glyphs
25129 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
25133 for (i
= first
; i
< end
; ++i
)
25136 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
25139 x
+= glyphs
[i
].pixel_width
;
25146 /* Set background width of glyph string S. START is the index of the
25147 first glyph following S. LAST_X is the right-most x-position + 1
25148 in the drawing area. */
25151 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
25153 /* If the face of this glyph string has to be drawn to the end of
25154 the drawing area, set S->extends_to_end_of_line_p. */
25156 if (start
== s
->row
->used
[s
->area
]
25157 && ((s
->row
->fill_line_p
25158 && (s
->hl
== DRAW_NORMAL_TEXT
25159 || s
->hl
== DRAW_IMAGE_RAISED
25160 || s
->hl
== DRAW_IMAGE_SUNKEN
))
25161 || s
->hl
== DRAW_MOUSE_FACE
))
25162 s
->extends_to_end_of_line_p
= true;
25164 /* If S extends its face to the end of the line, set its
25165 background_width to the distance to the right edge of the drawing
25167 if (s
->extends_to_end_of_line_p
)
25168 s
->background_width
= last_x
- s
->x
+ 1;
25170 s
->background_width
= s
->width
;
25174 /* Compute overhangs and x-positions for glyph string S and its
25175 predecessors, or successors. X is the starting x-position for S.
25176 BACKWARD_P means process predecessors. */
25179 compute_overhangs_and_x (struct glyph_string
*s
, int x
, bool backward_p
)
25185 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
25186 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
25196 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
25197 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
25207 /* The following macros are only called from draw_glyphs below.
25208 They reference the following parameters of that function directly:
25209 `w', `row', `area', and `overlap_p'
25210 as well as the following local variables:
25211 `s', `f', and `hdc' (in W32) */
25214 /* On W32, silently add local `hdc' variable to argument list of
25215 init_glyph_string. */
25216 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
25217 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
25219 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
25220 init_glyph_string (s, char2b, w, row, area, start, hl)
25223 /* Add a glyph string for a stretch glyph to the list of strings
25224 between HEAD and TAIL. START is the index of the stretch glyph in
25225 row area AREA of glyph row ROW. END is the index of the last glyph
25226 in that glyph row area. X is the current output position assigned
25227 to the new glyph string constructed. HL overrides that face of the
25228 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
25229 is the right-most x-position of the drawing area. */
25231 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
25232 and below -- keep them on one line. */
25233 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25236 s = alloca (sizeof *s); \
25237 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25238 START = fill_stretch_glyph_string (s, START, END); \
25239 append_glyph_string (&HEAD, &TAIL, s); \
25245 /* Add a glyph string for an image glyph to the list of strings
25246 between HEAD and TAIL. START is the index of the image glyph in
25247 row area AREA of glyph row ROW. END is the index of the last glyph
25248 in that glyph row area. X is the current output position assigned
25249 to the new glyph string constructed. HL overrides that face of the
25250 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
25251 is the right-most x-position of the drawing area. */
25253 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25256 s = alloca (sizeof *s); \
25257 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25258 fill_image_glyph_string (s); \
25259 append_glyph_string (&HEAD, &TAIL, s); \
25265 #ifndef HAVE_XWIDGETS
25266 # define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25269 # define BUILD_XWIDGET_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25272 s = alloca (sizeof *s); \
25273 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25274 fill_xwidget_glyph_string (s); \
25275 append_glyph_string (&(HEAD), &(TAIL), s); \
25282 /* Add a glyph string for a sequence of character glyphs to the list
25283 of strings between HEAD and TAIL. START is the index of the first
25284 glyph in row area AREA of glyph row ROW that is part of the new
25285 glyph string. END is the index of the last glyph in that glyph row
25286 area. X is the current output position assigned to the new glyph
25287 string constructed. HL overrides that face of the glyph; e.g. it
25288 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
25289 right-most x-position of the drawing area. */
25291 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25297 face_id = (row)->glyphs[area][START].face_id; \
25299 s = alloca (sizeof *s); \
25300 SAFE_NALLOCA (char2b, 1, (END) - (START)); \
25301 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25302 append_glyph_string (&HEAD, &TAIL, s); \
25304 START = fill_glyph_string (s, face_id, START, END, overlaps); \
25309 /* Add a glyph string for a composite sequence to the list of strings
25310 between HEAD and TAIL. START is the index of the first glyph in
25311 row area AREA of glyph row ROW that is part of the new glyph
25312 string. END is the index of the last glyph in that glyph row area.
25313 X is the current output position assigned to the new glyph string
25314 constructed. HL overrides that face of the glyph; e.g. it is
25315 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
25316 x-position of the drawing area. */
25318 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25320 int face_id = (row)->glyphs[area][START].face_id; \
25321 struct face *base_face = FACE_FROM_ID (f, face_id); \
25322 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
25323 struct composition *cmp = composition_table[cmp_id]; \
25325 struct glyph_string *first_s = NULL; \
25328 SAFE_NALLOCA (char2b, 1, cmp->glyph_len); \
25330 /* Make glyph_strings for each glyph sequence that is drawable by \
25331 the same face, and append them to HEAD/TAIL. */ \
25332 for (n = 0; n < cmp->glyph_len;) \
25334 s = alloca (sizeof *s); \
25335 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25336 append_glyph_string (&(HEAD), &(TAIL), s); \
25342 n = fill_composite_glyph_string (s, base_face, overlaps); \
25350 /* Add a glyph string for a glyph-string sequence to the list of strings
25351 between HEAD and TAIL. */
25353 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25357 Lisp_Object gstring; \
25359 face_id = (row)->glyphs[area][START].face_id; \
25360 gstring = (composition_gstring_from_id \
25361 ((row)->glyphs[area][START].u.cmp.id)); \
25362 s = alloca (sizeof *s); \
25363 SAFE_NALLOCA (char2b, 1, LGSTRING_GLYPH_LEN (gstring)); \
25364 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
25365 append_glyph_string (&(HEAD), &(TAIL), s); \
25367 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
25371 /* Add a glyph string for a sequence of glyphless character's glyphs
25372 to the list of strings between HEAD and TAIL. The meanings of
25373 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
25375 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
25380 face_id = (row)->glyphs[area][START].face_id; \
25382 s = alloca (sizeof *s); \
25383 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
25384 append_glyph_string (&HEAD, &TAIL, s); \
25386 START = fill_glyphless_glyph_string (s, face_id, START, END, \
25392 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
25393 of AREA of glyph row ROW on window W between indices START and END.
25394 HL overrides the face for drawing glyph strings, e.g. it is
25395 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
25396 x-positions of the drawing area.
25398 This is an ugly monster macro construct because we must use alloca
25399 to allocate glyph strings (because draw_glyphs can be called
25400 asynchronously). */
25402 #define BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25405 HEAD = TAIL = NULL; \
25406 while (START < END) \
25408 struct glyph *first_glyph = (row)->glyphs[area] + START; \
25409 switch (first_glyph->type) \
25412 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
25416 case COMPOSITE_GLYPH: \
25417 if (first_glyph->u.cmp.automatic) \
25418 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
25421 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
25425 case STRETCH_GLYPH: \
25426 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
25430 case IMAGE_GLYPH: \
25431 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
25435 #define BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25436 case XWIDGET_GLYPH: \
25437 BUILD_XWIDGET_GLYPH_STRING (START, END, HEAD, TAIL, \
25441 #define BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X) \
25442 case GLYPHLESS_GLYPH: \
25443 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
25453 set_glyph_string_background_width (s, START, LAST_X); \
25460 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
25461 BUILD_GLYPH_STRINGS_1(START, END, HEAD, TAIL, HL, X, LAST_X) \
25462 BUILD_GLYPH_STRINGS_XW(START, END, HEAD, TAIL, HL, X, LAST_X) \
25463 BUILD_GLYPH_STRINGS_2(START, END, HEAD, TAIL, HL, X, LAST_X)
25466 /* Draw glyphs between START and END in AREA of ROW on window W,
25467 starting at x-position X. X is relative to AREA in W. HL is a
25468 face-override with the following meaning:
25470 DRAW_NORMAL_TEXT draw normally
25471 DRAW_CURSOR draw in cursor face
25472 DRAW_MOUSE_FACE draw in mouse face.
25473 DRAW_INVERSE_VIDEO draw in mode line face
25474 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
25475 DRAW_IMAGE_RAISED draw an image with a raised relief around it
25477 If OVERLAPS is non-zero, draw only the foreground of characters and
25478 clip to the physical height of ROW. Non-zero value also defines
25479 the overlapping part to be drawn:
25481 OVERLAPS_PRED overlap with preceding rows
25482 OVERLAPS_SUCC overlap with succeeding rows
25483 OVERLAPS_BOTH overlap with both preceding/succeeding rows
25484 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
25486 Value is the x-position reached, relative to AREA of W. */
25489 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
25490 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
25491 enum draw_glyphs_face hl
, int overlaps
)
25493 struct glyph_string
*head
, *tail
;
25494 struct glyph_string
*s
;
25495 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
25496 int i
, j
, x_reached
, last_x
, area_left
= 0;
25497 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25500 ALLOCATE_HDC (hdc
, f
);
25502 /* Let's rather be paranoid than getting a SEGV. */
25503 end
= min (end
, row
->used
[area
]);
25504 start
= clip_to_bounds (0, start
, end
);
25506 /* Translate X to frame coordinates. Set last_x to the right
25507 end of the drawing area. */
25508 if (row
->full_width_p
)
25510 /* X is relative to the left edge of W, without scroll bars
25512 area_left
= WINDOW_LEFT_EDGE_X (w
);
25513 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
25514 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
25518 area_left
= window_box_left (w
, area
);
25519 last_x
= area_left
+ window_box_width (w
, area
);
25523 /* Build a doubly-linked list of glyph_string structures between
25524 head and tail from what we have to draw. Note that the macro
25525 BUILD_GLYPH_STRINGS will modify its start parameter. That's
25526 the reason we use a separate variable `i'. */
25529 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
25531 x_reached
= tail
->x
+ tail
->background_width
;
25535 /* If there are any glyphs with lbearing < 0 or rbearing > width in
25536 the row, redraw some glyphs in front or following the glyph
25537 strings built above. */
25538 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
25540 struct glyph_string
*h
, *t
;
25541 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25542 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
25543 bool check_mouse_face
= false;
25546 /* If mouse highlighting is on, we may need to draw adjacent
25547 glyphs using mouse-face highlighting. */
25548 if (area
== TEXT_AREA
&& row
->mouse_face_p
25549 && hlinfo
->mouse_face_beg_row
>= 0
25550 && hlinfo
->mouse_face_end_row
>= 0)
25552 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
25554 if (row_vpos
>= hlinfo
->mouse_face_beg_row
25555 && row_vpos
<= hlinfo
->mouse_face_end_row
)
25557 check_mouse_face
= true;
25558 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
25559 ? hlinfo
->mouse_face_beg_col
: 0;
25560 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
25561 ? hlinfo
->mouse_face_end_col
25562 : row
->used
[TEXT_AREA
];
25566 /* Compute overhangs for all glyph strings. */
25567 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
25568 for (s
= head
; s
; s
= s
->next
)
25569 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
25571 /* Prepend glyph strings for glyphs in front of the first glyph
25572 string that are overwritten because of the first glyph
25573 string's left overhang. The background of all strings
25574 prepended must be drawn because the first glyph string
25576 i
= left_overwritten (head
);
25579 enum draw_glyphs_face overlap_hl
;
25581 /* If this row contains mouse highlighting, attempt to draw
25582 the overlapped glyphs with the correct highlight. This
25583 code fails if the overlap encompasses more than one glyph
25584 and mouse-highlight spans only some of these glyphs.
25585 However, making it work perfectly involves a lot more
25586 code, and I don't know if the pathological case occurs in
25587 practice, so we'll stick to this for now. --- cyd */
25588 if (check_mouse_face
25589 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25590 overlap_hl
= DRAW_MOUSE_FACE
;
25592 overlap_hl
= DRAW_NORMAL_TEXT
;
25594 if (hl
!= overlap_hl
)
25597 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
25598 overlap_hl
, dummy_x
, last_x
);
25600 compute_overhangs_and_x (t
, head
->x
, true);
25601 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25602 if (clip_head
== NULL
)
25606 /* Prepend glyph strings for glyphs in front of the first glyph
25607 string that overwrite that glyph string because of their
25608 right overhang. For these strings, only the foreground must
25609 be drawn, because it draws over the glyph string at `head'.
25610 The background must not be drawn because this would overwrite
25611 right overhangs of preceding glyphs for which no glyph
25613 i
= left_overwriting (head
);
25616 enum draw_glyphs_face overlap_hl
;
25618 if (check_mouse_face
25619 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25620 overlap_hl
= DRAW_MOUSE_FACE
;
25622 overlap_hl
= DRAW_NORMAL_TEXT
;
25624 if (hl
== overlap_hl
|| clip_head
== NULL
)
25626 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
25627 overlap_hl
, dummy_x
, last_x
);
25628 for (s
= h
; s
; s
= s
->next
)
25629 s
->background_filled_p
= true;
25630 compute_overhangs_and_x (t
, head
->x
, true);
25631 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25634 /* Append glyphs strings for glyphs following the last glyph
25635 string tail that are overwritten by tail. The background of
25636 these strings has to be drawn because tail's foreground draws
25638 i
= right_overwritten (tail
);
25641 enum draw_glyphs_face overlap_hl
;
25643 if (check_mouse_face
25644 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25645 overlap_hl
= DRAW_MOUSE_FACE
;
25647 overlap_hl
= DRAW_NORMAL_TEXT
;
25649 if (hl
!= overlap_hl
)
25651 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25652 overlap_hl
, x
, last_x
);
25653 /* Because BUILD_GLYPH_STRINGS updates the first argument,
25654 we don't have `end = i;' here. */
25655 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25656 append_glyph_string_lists (&head
, &tail
, h
, t
);
25657 if (clip_tail
== NULL
)
25661 /* Append glyph strings for glyphs following the last glyph
25662 string tail that overwrite tail. The foreground of such
25663 glyphs has to be drawn because it writes into the background
25664 of tail. The background must not be drawn because it could
25665 paint over the foreground of following glyphs. */
25666 i
= right_overwriting (tail
);
25669 enum draw_glyphs_face overlap_hl
;
25670 if (check_mouse_face
25671 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25672 overlap_hl
= DRAW_MOUSE_FACE
;
25674 overlap_hl
= DRAW_NORMAL_TEXT
;
25676 if (hl
== overlap_hl
|| clip_tail
== NULL
)
25678 i
++; /* We must include the Ith glyph. */
25679 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25680 overlap_hl
, x
, last_x
);
25681 for (s
= h
; s
; s
= s
->next
)
25682 s
->background_filled_p
= true;
25683 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, false);
25684 append_glyph_string_lists (&head
, &tail
, h
, t
);
25686 if (clip_head
|| clip_tail
)
25687 for (s
= head
; s
; s
= s
->next
)
25689 s
->clip_head
= clip_head
;
25690 s
->clip_tail
= clip_tail
;
25694 /* Draw all strings. */
25695 for (s
= head
; s
; s
= s
->next
)
25696 FRAME_RIF (f
)->draw_glyph_string (s
);
25699 /* When focus a sole frame and move horizontally, this clears on_p
25700 causing a failure to erase prev cursor position. */
25701 if (area
== TEXT_AREA
25702 && !row
->full_width_p
25703 /* When drawing overlapping rows, only the glyph strings'
25704 foreground is drawn, which doesn't erase a cursor
25708 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
25709 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
25710 : (tail
? tail
->x
+ tail
->background_width
: x
));
25714 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
25715 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
25719 /* Value is the x-position up to which drawn, relative to AREA of W.
25720 This doesn't include parts drawn because of overhangs. */
25721 if (row
->full_width_p
)
25722 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
25724 x_reached
-= area_left
;
25726 RELEASE_HDC (hdc
, f
);
25732 /* Expand row matrix if too narrow. Don't expand if area
25735 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
25737 if (!it->f->fonts_changed \
25738 && (it->glyph_row->glyphs[area] \
25739 < it->glyph_row->glyphs[area + 1])) \
25741 it->w->ncols_scale_factor++; \
25742 it->f->fonts_changed = true; \
25746 /* Store one glyph for IT->char_to_display in IT->glyph_row.
25747 Called from x_produce_glyphs when IT->glyph_row is non-null. */
25750 append_glyph (struct it
*it
)
25752 struct glyph
*glyph
;
25753 enum glyph_row_area area
= it
->area
;
25755 eassert (it
->glyph_row
);
25756 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
25758 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25759 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25761 /* If the glyph row is reversed, we need to prepend the glyph
25762 rather than append it. */
25763 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25767 /* Make room for the additional glyph. */
25768 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25770 glyph
= it
->glyph_row
->glyphs
[area
];
25772 glyph
->charpos
= CHARPOS (it
->position
);
25773 glyph
->object
= it
->object
;
25774 if (it
->pixel_width
> 0)
25776 glyph
->pixel_width
= it
->pixel_width
;
25777 glyph
->padding_p
= false;
25781 /* Assure at least 1-pixel width. Otherwise, cursor can't
25782 be displayed correctly. */
25783 glyph
->pixel_width
= 1;
25784 glyph
->padding_p
= true;
25786 glyph
->ascent
= it
->ascent
;
25787 glyph
->descent
= it
->descent
;
25788 glyph
->voffset
= it
->voffset
;
25789 glyph
->type
= CHAR_GLYPH
;
25790 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25791 glyph
->multibyte_p
= it
->multibyte_p
;
25792 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25794 /* In R2L rows, the left and the right box edges need to be
25795 drawn in reverse direction. */
25796 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25797 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25801 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25802 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25804 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25805 || it
->phys_descent
> it
->descent
);
25806 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
25807 glyph
->face_id
= it
->face_id
;
25808 glyph
->u
.ch
= it
->char_to_display
;
25809 glyph
->slice
.img
= null_glyph_slice
;
25810 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25813 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25814 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25815 glyph
->bidi_type
= it
->bidi_it
.type
;
25819 glyph
->resolved_level
= 0;
25820 glyph
->bidi_type
= UNKNOWN_BT
;
25822 ++it
->glyph_row
->used
[area
];
25825 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25828 /* Store one glyph for the composition IT->cmp_it.id in
25829 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
25833 append_composite_glyph (struct it
*it
)
25835 struct glyph
*glyph
;
25836 enum glyph_row_area area
= it
->area
;
25838 eassert (it
->glyph_row
);
25840 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25841 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25843 /* If the glyph row is reversed, we need to prepend the glyph
25844 rather than append it. */
25845 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
25849 /* Make room for the new glyph. */
25850 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
25852 glyph
= it
->glyph_row
->glyphs
[it
->area
];
25854 glyph
->charpos
= it
->cmp_it
.charpos
;
25855 glyph
->object
= it
->object
;
25856 glyph
->pixel_width
= it
->pixel_width
;
25857 glyph
->ascent
= it
->ascent
;
25858 glyph
->descent
= it
->descent
;
25859 glyph
->voffset
= it
->voffset
;
25860 glyph
->type
= COMPOSITE_GLYPH
;
25861 if (it
->cmp_it
.ch
< 0)
25863 glyph
->u
.cmp
.automatic
= false;
25864 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25865 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
25869 glyph
->u
.cmp
.automatic
= true;
25870 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25871 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
25872 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
25874 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25875 glyph
->multibyte_p
= it
->multibyte_p
;
25876 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25878 /* In R2L rows, the left and the right box edges need to be
25879 drawn in reverse direction. */
25880 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25881 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25885 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25886 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25888 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25889 || it
->phys_descent
> it
->descent
);
25890 glyph
->padding_p
= false;
25891 glyph
->glyph_not_available_p
= false;
25892 glyph
->face_id
= it
->face_id
;
25893 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25896 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25897 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25898 glyph
->bidi_type
= it
->bidi_it
.type
;
25900 ++it
->glyph_row
->used
[area
];
25903 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25907 /* Change IT->ascent and IT->height according to the setting of
25911 take_vertical_position_into_account (struct it
*it
)
25915 if (it
->voffset
< 0)
25916 /* Increase the ascent so that we can display the text higher
25918 it
->ascent
-= it
->voffset
;
25920 /* Increase the descent so that we can display the text lower
25922 it
->descent
+= it
->voffset
;
25927 /* Produce glyphs/get display metrics for the image IT is loaded with.
25928 See the description of struct display_iterator in dispextern.h for
25929 an overview of struct display_iterator. */
25932 produce_image_glyph (struct it
*it
)
25936 int glyph_ascent
, crop
;
25937 struct glyph_slice slice
;
25939 eassert (it
->what
== IT_IMAGE
);
25941 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25943 /* Make sure X resources of the face is loaded. */
25944 prepare_face_for_display (it
->f
, face
);
25946 if (it
->image_id
< 0)
25948 /* Fringe bitmap. */
25949 it
->ascent
= it
->phys_ascent
= 0;
25950 it
->descent
= it
->phys_descent
= 0;
25951 it
->pixel_width
= 0;
25956 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
25958 /* Make sure X resources of the image is loaded. */
25959 prepare_image_for_display (it
->f
, img
);
25961 slice
.x
= slice
.y
= 0;
25962 slice
.width
= img
->width
;
25963 slice
.height
= img
->height
;
25965 if (INTEGERP (it
->slice
.x
))
25966 slice
.x
= XINT (it
->slice
.x
);
25967 else if (FLOATP (it
->slice
.x
))
25968 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
25970 if (INTEGERP (it
->slice
.y
))
25971 slice
.y
= XINT (it
->slice
.y
);
25972 else if (FLOATP (it
->slice
.y
))
25973 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
25975 if (INTEGERP (it
->slice
.width
))
25976 slice
.width
= XINT (it
->slice
.width
);
25977 else if (FLOATP (it
->slice
.width
))
25978 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
25980 if (INTEGERP (it
->slice
.height
))
25981 slice
.height
= XINT (it
->slice
.height
);
25982 else if (FLOATP (it
->slice
.height
))
25983 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
25985 if (slice
.x
>= img
->width
)
25986 slice
.x
= img
->width
;
25987 if (slice
.y
>= img
->height
)
25988 slice
.y
= img
->height
;
25989 if (slice
.x
+ slice
.width
>= img
->width
)
25990 slice
.width
= img
->width
- slice
.x
;
25991 if (slice
.y
+ slice
.height
> img
->height
)
25992 slice
.height
= img
->height
- slice
.y
;
25994 if (slice
.width
== 0 || slice
.height
== 0)
25997 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
25999 it
->descent
= slice
.height
- glyph_ascent
;
26001 it
->descent
+= img
->vmargin
;
26002 if (slice
.y
+ slice
.height
== img
->height
)
26003 it
->descent
+= img
->vmargin
;
26004 it
->phys_descent
= it
->descent
;
26006 it
->pixel_width
= slice
.width
;
26008 it
->pixel_width
+= img
->hmargin
;
26009 if (slice
.x
+ slice
.width
== img
->width
)
26010 it
->pixel_width
+= img
->hmargin
;
26012 /* It's quite possible for images to have an ascent greater than
26013 their height, so don't get confused in that case. */
26014 if (it
->descent
< 0)
26019 if (face
->box
!= FACE_NO_BOX
)
26021 if (face
->box_line_width
> 0)
26024 it
->ascent
+= face
->box_line_width
;
26025 if (slice
.y
+ slice
.height
== img
->height
)
26026 it
->descent
+= face
->box_line_width
;
26029 if (it
->start_of_box_run_p
&& slice
.x
== 0)
26030 it
->pixel_width
+= eabs (face
->box_line_width
);
26031 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
26032 it
->pixel_width
+= eabs (face
->box_line_width
);
26035 take_vertical_position_into_account (it
);
26037 /* Automatically crop wide image glyphs at right edge so we can
26038 draw the cursor on same display row. */
26039 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
26040 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
26042 it
->pixel_width
-= crop
;
26043 slice
.width
-= crop
;
26048 struct glyph
*glyph
;
26049 enum glyph_row_area area
= it
->area
;
26051 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26052 if (it
->glyph_row
->reversed_p
)
26056 /* Make room for the new glyph. */
26057 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
26059 glyph
= it
->glyph_row
->glyphs
[it
->area
];
26061 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26063 glyph
->charpos
= CHARPOS (it
->position
);
26064 glyph
->object
= it
->object
;
26065 glyph
->pixel_width
= it
->pixel_width
;
26066 glyph
->ascent
= glyph_ascent
;
26067 glyph
->descent
= it
->descent
;
26068 glyph
->voffset
= it
->voffset
;
26069 glyph
->type
= IMAGE_GLYPH
;
26070 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26071 glyph
->multibyte_p
= it
->multibyte_p
;
26072 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26074 /* In R2L rows, the left and the right box edges need to be
26075 drawn in reverse direction. */
26076 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26077 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26081 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26082 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26084 glyph
->overlaps_vertically_p
= false;
26085 glyph
->padding_p
= false;
26086 glyph
->glyph_not_available_p
= false;
26087 glyph
->face_id
= it
->face_id
;
26088 glyph
->u
.img_id
= img
->id
;
26089 glyph
->slice
.img
= slice
;
26090 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26093 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26094 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26095 glyph
->bidi_type
= it
->bidi_it
.type
;
26097 ++it
->glyph_row
->used
[area
];
26100 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26105 produce_xwidget_glyph (struct it
*it
)
26107 #ifdef HAVE_XWIDGETS
26108 struct xwidget
*xw
;
26109 int glyph_ascent
, crop
;
26110 eassert (it
->what
== IT_XWIDGET
);
26112 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26114 /* Make sure X resources of the face is loaded. */
26115 prepare_face_for_display (it
->f
, face
);
26118 it
->ascent
= it
->phys_ascent
= glyph_ascent
= xw
->height
/2;
26119 it
->descent
= xw
->height
/2;
26120 it
->phys_descent
= it
->descent
;
26121 it
->pixel_width
= xw
->width
;
26122 /* It's quite possible for images to have an ascent greater than
26123 their height, so don't get confused in that case. */
26124 if (it
->descent
< 0)
26129 if (face
->box
!= FACE_NO_BOX
)
26131 if (face
->box_line_width
> 0)
26133 it
->ascent
+= face
->box_line_width
;
26134 it
->descent
+= face
->box_line_width
;
26137 if (it
->start_of_box_run_p
)
26138 it
->pixel_width
+= eabs (face
->box_line_width
);
26139 it
->pixel_width
+= eabs (face
->box_line_width
);
26142 take_vertical_position_into_account (it
);
26144 /* Automatically crop wide image glyphs at right edge so we can
26145 draw the cursor on same display row. */
26146 crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
);
26147 if (crop
> 0 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
26148 it
->pixel_width
-= crop
;
26152 enum glyph_row_area area
= it
->area
;
26153 struct glyph
*glyph
26154 = it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26156 if (it
->glyph_row
->reversed_p
)
26160 /* Make room for the new glyph. */
26161 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
26163 glyph
= it
->glyph_row
->glyphs
[it
->area
];
26165 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26167 glyph
->charpos
= CHARPOS (it
->position
);
26168 glyph
->object
= it
->object
;
26169 glyph
->pixel_width
= it
->pixel_width
;
26170 glyph
->ascent
= glyph_ascent
;
26171 glyph
->descent
= it
->descent
;
26172 glyph
->voffset
= it
->voffset
;
26173 glyph
->type
= XWIDGET_GLYPH
;
26174 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26175 glyph
->multibyte_p
= it
->multibyte_p
;
26176 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26178 /* In R2L rows, the left and the right box edges need to be
26179 drawn in reverse direction. */
26180 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26181 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26185 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26186 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26188 glyph
->overlaps_vertically_p
= 0;
26189 glyph
->padding_p
= 0;
26190 glyph
->glyph_not_available_p
= 0;
26191 glyph
->face_id
= it
->face_id
;
26192 glyph
->u
.xwidget
= it
->xwidget
;
26193 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26196 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26197 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26198 glyph
->bidi_type
= it
->bidi_it
.type
;
26200 ++it
->glyph_row
->used
[area
];
26203 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26208 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
26209 of the glyph, WIDTH and HEIGHT are the width and height of the
26210 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
26213 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
26214 int width
, int height
, int ascent
)
26216 struct glyph
*glyph
;
26217 enum glyph_row_area area
= it
->area
;
26219 eassert (ascent
>= 0 && ascent
<= height
);
26221 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26222 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26224 /* If the glyph row is reversed, we need to prepend the glyph
26225 rather than append it. */
26226 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26230 /* Make room for the additional glyph. */
26231 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26233 glyph
= it
->glyph_row
->glyphs
[area
];
26235 /* Decrease the width of the first glyph of the row that
26236 begins before first_visible_x (e.g., due to hscroll).
26237 This is so the overall width of the row becomes smaller
26238 by the scroll amount, and the stretch glyph appended by
26239 extend_face_to_end_of_line will be wider, to shift the
26240 row glyphs to the right. (In L2R rows, the corresponding
26241 left-shift effect is accomplished by setting row->x to a
26242 negative value, which won't work with R2L rows.)
26244 This must leave us with a positive value of WIDTH, since
26245 otherwise the call to move_it_in_display_line_to at the
26246 beginning of display_line would have got past the entire
26247 first glyph, and then it->current_x would have been
26248 greater or equal to it->first_visible_x. */
26249 if (it
->current_x
< it
->first_visible_x
)
26250 width
-= it
->first_visible_x
- it
->current_x
;
26251 eassert (width
> 0);
26253 glyph
->charpos
= CHARPOS (it
->position
);
26254 glyph
->object
= object
;
26255 glyph
->pixel_width
= width
;
26256 glyph
->ascent
= ascent
;
26257 glyph
->descent
= height
- ascent
;
26258 glyph
->voffset
= it
->voffset
;
26259 glyph
->type
= STRETCH_GLYPH
;
26260 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26261 glyph
->multibyte_p
= it
->multibyte_p
;
26262 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26264 /* In R2L rows, the left and the right box edges need to be
26265 drawn in reverse direction. */
26266 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26267 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26271 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26272 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26274 glyph
->overlaps_vertically_p
= false;
26275 glyph
->padding_p
= false;
26276 glyph
->glyph_not_available_p
= false;
26277 glyph
->face_id
= it
->face_id
;
26278 glyph
->u
.stretch
.ascent
= ascent
;
26279 glyph
->u
.stretch
.height
= height
;
26280 glyph
->slice
.img
= null_glyph_slice
;
26281 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26284 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26285 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26286 glyph
->bidi_type
= it
->bidi_it
.type
;
26290 glyph
->resolved_level
= 0;
26291 glyph
->bidi_type
= UNKNOWN_BT
;
26293 ++it
->glyph_row
->used
[area
];
26296 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26299 #endif /* HAVE_WINDOW_SYSTEM */
26301 /* Produce a stretch glyph for iterator IT. IT->object is the value
26302 of the glyph property displayed. The value must be a list
26303 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
26306 1. `:width WIDTH' specifies that the space should be WIDTH *
26307 canonical char width wide. WIDTH may be an integer or floating
26310 2. `:relative-width FACTOR' specifies that the width of the stretch
26311 should be computed from the width of the first character having the
26312 `glyph' property, and should be FACTOR times that width.
26314 3. `:align-to HPOS' specifies that the space should be wide enough
26315 to reach HPOS, a value in canonical character units.
26317 Exactly one of the above pairs must be present.
26319 4. `:height HEIGHT' specifies that the height of the stretch produced
26320 should be HEIGHT, measured in canonical character units.
26322 5. `:relative-height FACTOR' specifies that the height of the
26323 stretch should be FACTOR times the height of the characters having
26324 the glyph property.
26326 Either none or exactly one of 4 or 5 must be present.
26328 6. `:ascent ASCENT' specifies that ASCENT percent of the height
26329 of the stretch should be used for the ascent of the stretch.
26330 ASCENT must be in the range 0 <= ASCENT <= 100. */
26333 produce_stretch_glyph (struct it
*it
)
26335 /* (space :width WIDTH :height HEIGHT ...) */
26336 Lisp_Object prop
, plist
;
26337 int width
= 0, height
= 0, align_to
= -1;
26338 bool zero_width_ok_p
= false;
26340 struct font
*font
= NULL
;
26342 #ifdef HAVE_WINDOW_SYSTEM
26344 bool zero_height_ok_p
= false;
26346 if (FRAME_WINDOW_P (it
->f
))
26348 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26349 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26350 prepare_face_for_display (it
->f
, face
);
26354 /* List should start with `space'. */
26355 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
26356 plist
= XCDR (it
->object
);
26358 /* Compute the width of the stretch. */
26359 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
26360 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true, 0))
26362 /* Absolute width `:width WIDTH' specified and valid. */
26363 zero_width_ok_p
= true;
26366 else if (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0)
26368 /* Relative width `:relative-width FACTOR' specified and valid.
26369 Compute the width of the characters having the `glyph'
26372 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
26375 if (it
->multibyte_p
)
26376 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
26379 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
26380 if (! ASCII_CHAR_P (it2
.c
))
26381 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
26384 it2
.glyph_row
= NULL
;
26385 it2
.what
= IT_CHARACTER
;
26386 PRODUCE_GLYPHS (&it2
);
26387 width
= NUMVAL (prop
) * it2
.pixel_width
;
26389 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
26390 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, true,
26393 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
26394 align_to
= (align_to
< 0
26396 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
26397 else if (align_to
< 0)
26398 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
26399 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
26400 zero_width_ok_p
= true;
26403 /* Nothing specified -> width defaults to canonical char width. */
26404 width
= FRAME_COLUMN_WIDTH (it
->f
);
26406 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
26409 #ifdef HAVE_WINDOW_SYSTEM
26410 /* Compute height. */
26411 if (FRAME_WINDOW_P (it
->f
))
26413 int default_height
= normal_char_height (font
, ' ');
26415 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
26416 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
26419 zero_height_ok_p
= true;
26421 else if (prop
= Fplist_get (plist
, QCrelative_height
),
26423 height
= default_height
* NUMVAL (prop
);
26425 height
= default_height
;
26427 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
26430 /* Compute percentage of height used for ascent. If
26431 `:ascent ASCENT' is present and valid, use that. Otherwise,
26432 derive the ascent from the font in use. */
26433 if (prop
= Fplist_get (plist
, QCascent
),
26434 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
26435 ascent
= height
* NUMVAL (prop
) / 100.0;
26436 else if (!NILP (prop
)
26437 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, false, 0))
26438 ascent
= min (max (0, (int)tem
), height
);
26440 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
26443 #endif /* HAVE_WINDOW_SYSTEM */
26446 if (width
> 0 && it
->line_wrap
!= TRUNCATE
26447 && it
->current_x
+ width
> it
->last_visible_x
)
26449 width
= it
->last_visible_x
- it
->current_x
;
26450 #ifdef HAVE_WINDOW_SYSTEM
26451 /* Subtract one more pixel from the stretch width, but only on
26452 GUI frames, since on a TTY each glyph is one "pixel" wide. */
26453 width
-= FRAME_WINDOW_P (it
->f
);
26457 if (width
> 0 && height
> 0 && it
->glyph_row
)
26459 Lisp_Object o_object
= it
->object
;
26460 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
26463 if (!STRINGP (object
))
26464 object
= it
->w
->contents
;
26465 #ifdef HAVE_WINDOW_SYSTEM
26466 if (FRAME_WINDOW_P (it
->f
))
26467 append_stretch_glyph (it
, object
, width
, height
, ascent
);
26471 it
->object
= object
;
26472 it
->char_to_display
= ' ';
26473 it
->pixel_width
= it
->len
= 1;
26475 tty_append_glyph (it
);
26476 it
->object
= o_object
;
26480 it
->pixel_width
= width
;
26481 #ifdef HAVE_WINDOW_SYSTEM
26482 if (FRAME_WINDOW_P (it
->f
))
26484 it
->ascent
= it
->phys_ascent
= ascent
;
26485 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
26486 it
->nglyphs
= width
> 0 && height
> 0;
26487 take_vertical_position_into_account (it
);
26491 it
->nglyphs
= width
;
26494 /* Get information about special display element WHAT in an
26495 environment described by IT. WHAT is one of IT_TRUNCATION or
26496 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
26497 non-null glyph_row member. This function ensures that fields like
26498 face_id, c, len of IT are left untouched. */
26501 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
26508 temp_it
.object
= Qnil
;
26509 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
26511 if (what
== IT_CONTINUATION
)
26513 /* Continuation glyph. For R2L lines, we mirror it by hand. */
26514 if (it
->bidi_it
.paragraph_dir
== R2L
)
26515 SET_GLYPH_FROM_CHAR (glyph
, '/');
26517 SET_GLYPH_FROM_CHAR (glyph
, '\\');
26519 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
26521 /* FIXME: Should we mirror GC for R2L lines? */
26522 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
26523 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
26526 else if (what
== IT_TRUNCATION
)
26528 /* Truncation glyph. */
26529 SET_GLYPH_FROM_CHAR (glyph
, '$');
26531 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
26533 /* FIXME: Should we mirror GC for R2L lines? */
26534 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
26535 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
26541 #ifdef HAVE_WINDOW_SYSTEM
26542 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
26543 is turned off, we precede the truncation/continuation glyphs by a
26544 stretch glyph whose width is computed such that these special
26545 glyphs are aligned at the window margin, even when very different
26546 fonts are used in different glyph rows. */
26547 if (FRAME_WINDOW_P (temp_it
.f
)
26548 /* init_iterator calls this with it->glyph_row == NULL, and it
26549 wants only the pixel width of the truncation/continuation
26551 && temp_it
.glyph_row
26552 /* insert_left_trunc_glyphs calls us at the beginning of the
26553 row, and it has its own calculation of the stretch glyph
26555 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
26556 && (temp_it
.glyph_row
->reversed_p
26557 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
26558 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
26560 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
26562 if (stretch_width
> 0)
26564 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
26565 struct font
*font
=
26566 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
26567 int stretch_ascent
=
26568 (((temp_it
.ascent
+ temp_it
.descent
)
26569 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
26571 append_stretch_glyph (&temp_it
, Qnil
, stretch_width
,
26572 temp_it
.ascent
+ temp_it
.descent
,
26579 temp_it
.what
= IT_CHARACTER
;
26580 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
26581 temp_it
.face_id
= GLYPH_FACE (glyph
);
26582 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
26584 PRODUCE_GLYPHS (&temp_it
);
26585 it
->pixel_width
= temp_it
.pixel_width
;
26586 it
->nglyphs
= temp_it
.nglyphs
;
26589 #ifdef HAVE_WINDOW_SYSTEM
26591 /* Calculate line-height and line-spacing properties.
26592 An integer value specifies explicit pixel value.
26593 A float value specifies relative value to current face height.
26594 A cons (float . face-name) specifies relative value to
26595 height of specified face font.
26597 Returns height in pixels, or nil. */
26600 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
26601 int boff
, bool override
)
26603 Lisp_Object face_name
= Qnil
;
26604 int ascent
, descent
, height
;
26606 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
26611 face_name
= XCAR (val
);
26613 if (!NUMBERP (val
))
26614 val
= make_number (1);
26615 if (NILP (face_name
))
26617 height
= it
->ascent
+ it
->descent
;
26622 if (NILP (face_name
))
26624 font
= FRAME_FONT (it
->f
);
26625 boff
= FRAME_BASELINE_OFFSET (it
->f
);
26627 else if (EQ (face_name
, Qt
))
26636 face_id
= lookup_named_face (it
->f
, face_name
, false);
26638 return make_number (-1);
26640 face
= FACE_FROM_ID (it
->f
, face_id
);
26643 return make_number (-1);
26644 boff
= font
->baseline_offset
;
26645 if (font
->vertical_centering
)
26646 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26649 normal_char_ascent_descent (font
, -1, &ascent
, &descent
);
26653 it
->override_ascent
= ascent
;
26654 it
->override_descent
= descent
;
26655 it
->override_boff
= boff
;
26658 height
= ascent
+ descent
;
26662 height
= (int)(XFLOAT_DATA (val
) * height
);
26663 else if (INTEGERP (val
))
26664 height
*= XINT (val
);
26666 return make_number (height
);
26670 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
26671 is a face ID to be used for the glyph. FOR_NO_FONT is true if
26672 and only if this is for a character for which no font was found.
26674 If the display method (it->glyphless_method) is
26675 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
26676 length of the acronym or the hexadecimal string, UPPER_XOFF and
26677 UPPER_YOFF are pixel offsets for the upper part of the string,
26678 LOWER_XOFF and LOWER_YOFF are for the lower part.
26680 For the other display methods, LEN through LOWER_YOFF are zero. */
26683 append_glyphless_glyph (struct it
*it
, int face_id
, bool for_no_font
, int len
,
26684 short upper_xoff
, short upper_yoff
,
26685 short lower_xoff
, short lower_yoff
)
26687 struct glyph
*glyph
;
26688 enum glyph_row_area area
= it
->area
;
26690 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26691 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26693 /* If the glyph row is reversed, we need to prepend the glyph
26694 rather than append it. */
26695 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26699 /* Make room for the additional glyph. */
26700 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26702 glyph
= it
->glyph_row
->glyphs
[area
];
26704 glyph
->charpos
= CHARPOS (it
->position
);
26705 glyph
->object
= it
->object
;
26706 glyph
->pixel_width
= it
->pixel_width
;
26707 glyph
->ascent
= it
->ascent
;
26708 glyph
->descent
= it
->descent
;
26709 glyph
->voffset
= it
->voffset
;
26710 glyph
->type
= GLYPHLESS_GLYPH
;
26711 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
26712 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
26713 glyph
->u
.glyphless
.len
= len
;
26714 glyph
->u
.glyphless
.ch
= it
->c
;
26715 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
26716 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
26717 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
26718 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
26719 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26720 glyph
->multibyte_p
= it
->multibyte_p
;
26721 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26723 /* In R2L rows, the left and the right box edges need to be
26724 drawn in reverse direction. */
26725 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26726 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26730 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26731 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26733 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
26734 || it
->phys_descent
> it
->descent
);
26735 glyph
->padding_p
= false;
26736 glyph
->glyph_not_available_p
= false;
26737 glyph
->face_id
= face_id
;
26738 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26741 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26742 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26743 glyph
->bidi_type
= it
->bidi_it
.type
;
26745 ++it
->glyph_row
->used
[area
];
26748 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26752 /* Produce a glyph for a glyphless character for iterator IT.
26753 IT->glyphless_method specifies which method to use for displaying
26754 the character. See the description of enum
26755 glyphless_display_method in dispextern.h for the detail.
26757 FOR_NO_FONT is true if and only if this is for a character for
26758 which no font was found. ACRONYM, if non-nil, is an acronym string
26759 for the character. */
26762 produce_glyphless_glyph (struct it
*it
, bool for_no_font
, Lisp_Object acronym
)
26767 int base_width
, base_height
, width
, height
;
26768 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
26771 /* Get the metrics of the base font. We always refer to the current
26773 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
26774 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26775 normal_char_ascent_descent (font
, -1, &it
->ascent
, &it
->descent
);
26776 it
->ascent
+= font
->baseline_offset
;
26777 it
->descent
-= font
->baseline_offset
;
26778 base_height
= it
->ascent
+ it
->descent
;
26779 base_width
= font
->average_width
;
26781 face_id
= merge_glyphless_glyph_face (it
);
26783 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
26785 it
->pixel_width
= THIN_SPACE_WIDTH
;
26787 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26789 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
26791 width
= CHAR_WIDTH (it
->c
);
26794 else if (width
> 4)
26796 it
->pixel_width
= base_width
* width
;
26798 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26804 unsigned int code
[6];
26806 int ascent
, descent
;
26807 struct font_metrics metrics_upper
, metrics_lower
;
26809 face
= FACE_FROM_ID (it
->f
, face_id
);
26810 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26811 prepare_face_for_display (it
->f
, face
);
26813 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
26815 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
26816 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
26817 if (CONSP (acronym
))
26818 acronym
= XCAR (acronym
);
26819 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
26823 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
26824 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
+ 0u);
26827 for (len
= 0; str
[len
] && ASCII_CHAR_P (str
[len
]) && len
< 6; len
++)
26828 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
26829 upper_len
= (len
+ 1) / 2;
26830 font
->driver
->text_extents (font
, code
, upper_len
,
26832 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
26837 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
26838 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
26839 upper_xoff
= upper_yoff
= 2; /* the typical case */
26840 if (base_width
>= width
)
26842 /* Align the upper to the left, the lower to the right. */
26843 it
->pixel_width
= base_width
;
26844 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
26848 /* Center the shorter one. */
26849 it
->pixel_width
= width
;
26850 if (metrics_upper
.width
>= metrics_lower
.width
)
26851 lower_xoff
= (width
- metrics_lower
.width
) / 2;
26854 /* FIXME: This code doesn't look right. It formerly was
26855 missing the "lower_xoff = 0;", which couldn't have
26856 been right since it left lower_xoff uninitialized. */
26858 upper_xoff
= (width
- metrics_upper
.width
) / 2;
26862 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
26863 top, bottom, and between upper and lower strings. */
26864 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
26865 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
26866 /* Center vertically.
26867 H:base_height, D:base_descent
26868 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
26870 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
26871 descent = D - H/2 + h/2;
26872 lower_yoff = descent - 2 - ld;
26873 upper_yoff = lower_yoff - la - 1 - ud; */
26874 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
26875 descent
= it
->descent
- (base_height
- height
) / 2;
26876 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
26877 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
26878 - metrics_upper
.descent
);
26879 /* Don't make the height shorter than the base height. */
26880 if (height
> base_height
)
26882 it
->ascent
= ascent
;
26883 it
->descent
= descent
;
26887 it
->phys_ascent
= it
->ascent
;
26888 it
->phys_descent
= it
->descent
;
26890 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
26891 upper_xoff
, upper_yoff
,
26892 lower_xoff
, lower_yoff
);
26894 take_vertical_position_into_account (it
);
26899 Produce glyphs/get display metrics for the display element IT is
26900 loaded with. See the description of struct it in dispextern.h
26901 for an overview of struct it. */
26904 x_produce_glyphs (struct it
*it
)
26906 int extra_line_spacing
= it
->extra_line_spacing
;
26908 it
->glyph_not_available_p
= false;
26910 if (it
->what
== IT_CHARACTER
)
26913 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26914 struct font
*font
= face
->font
;
26915 struct font_metrics
*pcm
= NULL
;
26916 int boff
; /* Baseline offset. */
26920 /* When no suitable font is found, display this character by
26921 the method specified in the first extra slot of
26922 Vglyphless_char_display. */
26923 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
26925 eassert (it
->what
== IT_GLYPHLESS
);
26926 produce_glyphless_glyph (it
, true,
26927 STRINGP (acronym
) ? acronym
: Qnil
);
26931 boff
= font
->baseline_offset
;
26932 if (font
->vertical_centering
)
26933 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26935 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
26939 if (it
->override_ascent
>= 0)
26941 it
->ascent
= it
->override_ascent
;
26942 it
->descent
= it
->override_descent
;
26943 boff
= it
->override_boff
;
26947 it
->ascent
= FONT_BASE (font
) + boff
;
26948 it
->descent
= FONT_DESCENT (font
) - boff
;
26951 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
26953 pcm
= get_per_char_metric (font
, &char2b
);
26954 if (pcm
->width
== 0
26955 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
26961 it
->phys_ascent
= pcm
->ascent
+ boff
;
26962 it
->phys_descent
= pcm
->descent
- boff
;
26963 it
->pixel_width
= pcm
->width
;
26964 /* Don't use font-global values for ascent and descent
26965 if they result in an exceedingly large line height. */
26966 if (it
->override_ascent
< 0)
26968 if (FONT_TOO_HIGH (font
))
26970 it
->ascent
= it
->phys_ascent
;
26971 it
->descent
= it
->phys_descent
;
26972 /* These limitations are enforced by an
26973 assertion near the end of this function. */
26974 if (it
->ascent
< 0)
26976 if (it
->descent
< 0)
26983 it
->glyph_not_available_p
= true;
26984 it
->phys_ascent
= it
->ascent
;
26985 it
->phys_descent
= it
->descent
;
26986 it
->pixel_width
= font
->space_width
;
26989 if (it
->constrain_row_ascent_descent_p
)
26991 if (it
->descent
> it
->max_descent
)
26993 it
->ascent
+= it
->descent
- it
->max_descent
;
26994 it
->descent
= it
->max_descent
;
26996 if (it
->ascent
> it
->max_ascent
)
26998 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
26999 it
->ascent
= it
->max_ascent
;
27001 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
27002 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
27003 extra_line_spacing
= 0;
27006 /* If this is a space inside a region of text with
27007 `space-width' property, change its width. */
27009 = it
->char_to_display
== ' ' && !NILP (it
->space_width
);
27011 it
->pixel_width
*= XFLOATINT (it
->space_width
);
27013 /* If face has a box, add the box thickness to the character
27014 height. If character has a box line to the left and/or
27015 right, add the box line width to the character's width. */
27016 if (face
->box
!= FACE_NO_BOX
)
27018 int thick
= face
->box_line_width
;
27022 it
->ascent
+= thick
;
27023 it
->descent
+= thick
;
27028 if (it
->start_of_box_run_p
)
27029 it
->pixel_width
+= thick
;
27030 if (it
->end_of_box_run_p
)
27031 it
->pixel_width
+= thick
;
27034 /* If face has an overline, add the height of the overline
27035 (1 pixel) and a 1 pixel margin to the character height. */
27036 if (face
->overline_p
)
27037 it
->ascent
+= overline_margin
;
27039 if (it
->constrain_row_ascent_descent_p
)
27041 if (it
->ascent
> it
->max_ascent
)
27042 it
->ascent
= it
->max_ascent
;
27043 if (it
->descent
> it
->max_descent
)
27044 it
->descent
= it
->max_descent
;
27047 take_vertical_position_into_account (it
);
27049 /* If we have to actually produce glyphs, do it. */
27054 /* Translate a space with a `space-width' property
27055 into a stretch glyph. */
27056 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
27057 / FONT_HEIGHT (font
));
27058 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
27059 it
->ascent
+ it
->descent
, ascent
);
27064 /* If characters with lbearing or rbearing are displayed
27065 in this line, record that fact in a flag of the
27066 glyph row. This is used to optimize X output code. */
27067 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
27068 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27070 if (! stretched_p
&& it
->pixel_width
== 0)
27071 /* We assure that all visible glyphs have at least 1-pixel
27073 it
->pixel_width
= 1;
27075 else if (it
->char_to_display
== '\n')
27077 /* A newline has no width, but we need the height of the
27078 line. But if previous part of the line sets a height,
27079 don't increase that height. */
27081 Lisp_Object height
;
27082 Lisp_Object total_height
= Qnil
;
27084 it
->override_ascent
= -1;
27085 it
->pixel_width
= 0;
27088 height
= get_it_property (it
, Qline_height
);
27089 /* Split (line-height total-height) list. */
27091 && CONSP (XCDR (height
))
27092 && NILP (XCDR (XCDR (height
))))
27094 total_height
= XCAR (XCDR (height
));
27095 height
= XCAR (height
);
27097 height
= calc_line_height_property (it
, height
, font
, boff
, true);
27099 if (it
->override_ascent
>= 0)
27101 it
->ascent
= it
->override_ascent
;
27102 it
->descent
= it
->override_descent
;
27103 boff
= it
->override_boff
;
27107 if (FONT_TOO_HIGH (font
))
27109 it
->ascent
= font
->pixel_size
+ boff
- 1;
27110 it
->descent
= -boff
+ 1;
27111 if (it
->descent
< 0)
27116 it
->ascent
= FONT_BASE (font
) + boff
;
27117 it
->descent
= FONT_DESCENT (font
) - boff
;
27121 if (EQ (height
, Qt
))
27123 if (it
->descent
> it
->max_descent
)
27125 it
->ascent
+= it
->descent
- it
->max_descent
;
27126 it
->descent
= it
->max_descent
;
27128 if (it
->ascent
> it
->max_ascent
)
27130 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
27131 it
->ascent
= it
->max_ascent
;
27133 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
27134 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
27135 it
->constrain_row_ascent_descent_p
= true;
27136 extra_line_spacing
= 0;
27140 Lisp_Object spacing
;
27142 it
->phys_ascent
= it
->ascent
;
27143 it
->phys_descent
= it
->descent
;
27145 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
27146 && face
->box
!= FACE_NO_BOX
27147 && face
->box_line_width
> 0)
27149 it
->ascent
+= face
->box_line_width
;
27150 it
->descent
+= face
->box_line_width
;
27153 && XINT (height
) > it
->ascent
+ it
->descent
)
27154 it
->ascent
= XINT (height
) - it
->descent
;
27156 if (!NILP (total_height
))
27157 spacing
= calc_line_height_property (it
, total_height
, font
,
27161 spacing
= get_it_property (it
, Qline_spacing
);
27162 spacing
= calc_line_height_property (it
, spacing
, font
,
27165 if (INTEGERP (spacing
))
27167 extra_line_spacing
= XINT (spacing
);
27168 if (!NILP (total_height
))
27169 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
27173 else /* i.e. (it->char_to_display == '\t') */
27175 if (font
->space_width
> 0)
27177 int tab_width
= it
->tab_width
* font
->space_width
;
27178 int x
= it
->current_x
+ it
->continuation_lines_width
;
27179 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
27181 /* If the distance from the current position to the next tab
27182 stop is less than a space character width, use the
27183 tab stop after that. */
27184 if (next_tab_x
- x
< font
->space_width
)
27185 next_tab_x
+= tab_width
;
27187 it
->pixel_width
= next_tab_x
- x
;
27189 if (FONT_TOO_HIGH (font
))
27191 if (get_char_glyph_code (' ', font
, &char2b
))
27193 pcm
= get_per_char_metric (font
, &char2b
);
27194 if (pcm
->width
== 0
27195 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
27201 it
->ascent
= pcm
->ascent
+ boff
;
27202 it
->descent
= pcm
->descent
- boff
;
27206 it
->ascent
= font
->pixel_size
+ boff
- 1;
27207 it
->descent
= -boff
+ 1;
27209 if (it
->ascent
< 0)
27211 if (it
->descent
< 0)
27216 it
->ascent
= FONT_BASE (font
) + boff
;
27217 it
->descent
= FONT_DESCENT (font
) - boff
;
27219 it
->phys_ascent
= it
->ascent
;
27220 it
->phys_descent
= it
->descent
;
27224 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
27225 it
->ascent
+ it
->descent
, it
->ascent
);
27230 it
->pixel_width
= 0;
27235 if (FONT_TOO_HIGH (font
))
27237 int font_ascent
, font_descent
;
27239 /* For very large fonts, where we ignore the declared font
27240 dimensions, and go by per-character metrics instead,
27241 don't let the row ascent and descent values (and the row
27242 height computed from them) be smaller than the "normal"
27243 character metrics. This avoids unpleasant effects
27244 whereby lines on display would change their height
27245 depending on which characters are shown. */
27246 normal_char_ascent_descent (font
, -1, &font_ascent
, &font_descent
);
27247 it
->max_ascent
= max (it
->max_ascent
, font_ascent
);
27248 it
->max_descent
= max (it
->max_descent
, font_descent
);
27251 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
27253 /* A static composition.
27255 Note: A composition is represented as one glyph in the
27256 glyph matrix. There are no padding glyphs.
27258 Important note: pixel_width, ascent, and descent are the
27259 values of what is drawn by draw_glyphs (i.e. the values of
27260 the overall glyphs composed). */
27261 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27262 int boff
; /* baseline offset */
27263 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
27264 int glyph_len
= cmp
->glyph_len
;
27265 struct font
*font
= face
->font
;
27269 /* If we have not yet calculated pixel size data of glyphs of
27270 the composition for the current face font, calculate them
27271 now. Theoretically, we have to check all fonts for the
27272 glyphs, but that requires much time and memory space. So,
27273 here we check only the font of the first glyph. This may
27274 lead to incorrect display, but it's very rare, and C-l
27275 (recenter-top-bottom) can correct the display anyway. */
27276 if (! cmp
->font
|| cmp
->font
!= font
)
27278 /* Ascent and descent of the font of the first character
27279 of this composition (adjusted by baseline offset).
27280 Ascent and descent of overall glyphs should not be less
27281 than these, respectively. */
27282 int font_ascent
, font_descent
, font_height
;
27283 /* Bounding box of the overall glyphs. */
27284 int leftmost
, rightmost
, lowest
, highest
;
27285 int lbearing
, rbearing
;
27286 int i
, width
, ascent
, descent
;
27287 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
27289 struct font_metrics
*pcm
;
27292 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
27293 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
27295 bool right_padded
= glyph_len
< cmp
->glyph_len
;
27296 for (i
= 0; i
< glyph_len
; i
++)
27298 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
27300 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
27302 bool left_padded
= i
> 0;
27304 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
27305 : IT_CHARPOS (*it
));
27306 /* If no suitable font is found, use the default font. */
27307 bool font_not_found_p
= font
== NULL
;
27308 if (font_not_found_p
)
27310 face
= face
->ascii_face
;
27313 boff
= font
->baseline_offset
;
27314 if (font
->vertical_centering
)
27315 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
27316 normal_char_ascent_descent (font
, -1, &font_ascent
, &font_descent
);
27317 font_ascent
+= boff
;
27318 font_descent
-= boff
;
27319 font_height
= font_ascent
+ font_descent
;
27324 if (! font_not_found_p
)
27326 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
27328 pcm
= get_per_char_metric (font
, &char2b
);
27331 /* Initialize the bounding box. */
27334 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
27335 ascent
= pcm
->ascent
;
27336 descent
= pcm
->descent
;
27337 lbearing
= pcm
->lbearing
;
27338 rbearing
= pcm
->rbearing
;
27342 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
27343 ascent
= FONT_BASE (font
);
27344 descent
= FONT_DESCENT (font
);
27351 lowest
= - descent
+ boff
;
27352 highest
= ascent
+ boff
;
27354 if (! font_not_found_p
27355 && font
->default_ascent
27356 && CHAR_TABLE_P (Vuse_default_ascent
)
27357 && !NILP (Faref (Vuse_default_ascent
,
27358 make_number (it
->char_to_display
))))
27359 highest
= font
->default_ascent
+ boff
;
27361 /* Draw the first glyph at the normal position. It may be
27362 shifted to right later if some other glyphs are drawn
27364 cmp
->offsets
[i
* 2] = 0;
27365 cmp
->offsets
[i
* 2 + 1] = boff
;
27366 cmp
->lbearing
= lbearing
;
27367 cmp
->rbearing
= rbearing
;
27369 /* Set cmp->offsets for the remaining glyphs. */
27370 for (i
++; i
< glyph_len
; i
++)
27372 int left
, right
, btm
, top
;
27373 int ch
= COMPOSITION_GLYPH (cmp
, i
);
27375 struct face
*this_face
;
27379 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
27380 this_face
= FACE_FROM_ID (it
->f
, face_id
);
27381 font
= this_face
->font
;
27387 get_char_face_and_encoding (it
->f
, ch
, face_id
,
27389 pcm
= get_per_char_metric (font
, &char2b
);
27392 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
27395 width
= pcm
->width
;
27396 ascent
= pcm
->ascent
;
27397 descent
= pcm
->descent
;
27398 lbearing
= pcm
->lbearing
;
27399 rbearing
= pcm
->rbearing
;
27400 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
27402 /* Relative composition with or without
27403 alternate chars. */
27404 left
= (leftmost
+ rightmost
- width
) / 2;
27405 btm
= - descent
+ boff
;
27406 if (font
->relative_compose
27407 && (! CHAR_TABLE_P (Vignore_relative_composition
)
27408 || NILP (Faref (Vignore_relative_composition
,
27409 make_number (ch
)))))
27412 if (- descent
>= font
->relative_compose
)
27413 /* One extra pixel between two glyphs. */
27415 else if (ascent
<= 0)
27416 /* One extra pixel between two glyphs. */
27417 btm
= lowest
- 1 - ascent
- descent
;
27422 /* A composition rule is specified by an integer
27423 value that encodes global and new reference
27424 points (GREF and NREF). GREF and NREF are
27425 specified by numbers as below:
27427 0---1---2 -- ascent
27431 9--10--11 -- center
27433 ---3---4---5--- baseline
27435 6---7---8 -- descent
27437 int rule
= COMPOSITION_RULE (cmp
, i
);
27438 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
27440 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
27441 grefx
= gref
% 3, nrefx
= nref
% 3;
27442 grefy
= gref
/ 3, nrefy
= nref
/ 3;
27444 xoff
= font_height
* (xoff
- 128) / 256;
27446 yoff
= font_height
* (yoff
- 128) / 256;
27449 + grefx
* (rightmost
- leftmost
) / 2
27450 - nrefx
* width
/ 2
27453 btm
= ((grefy
== 0 ? highest
27455 : grefy
== 2 ? lowest
27456 : (highest
+ lowest
) / 2)
27457 - (nrefy
== 0 ? ascent
+ descent
27458 : nrefy
== 1 ? descent
- boff
27460 : (ascent
+ descent
) / 2)
27464 cmp
->offsets
[i
* 2] = left
;
27465 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
27467 /* Update the bounding box of the overall glyphs. */
27470 right
= left
+ width
;
27471 if (left
< leftmost
)
27473 if (right
> rightmost
)
27476 top
= btm
+ descent
+ ascent
;
27482 if (cmp
->lbearing
> left
+ lbearing
)
27483 cmp
->lbearing
= left
+ lbearing
;
27484 if (cmp
->rbearing
< left
+ rbearing
)
27485 cmp
->rbearing
= left
+ rbearing
;
27489 /* If there are glyphs whose x-offsets are negative,
27490 shift all glyphs to the right and make all x-offsets
27494 for (i
= 0; i
< cmp
->glyph_len
; i
++)
27495 cmp
->offsets
[i
* 2] -= leftmost
;
27496 rightmost
-= leftmost
;
27497 cmp
->lbearing
-= leftmost
;
27498 cmp
->rbearing
-= leftmost
;
27501 if (left_padded
&& cmp
->lbearing
< 0)
27503 for (i
= 0; i
< cmp
->glyph_len
; i
++)
27504 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
27505 rightmost
-= cmp
->lbearing
;
27506 cmp
->rbearing
-= cmp
->lbearing
;
27509 if (right_padded
&& rightmost
< cmp
->rbearing
)
27511 rightmost
= cmp
->rbearing
;
27514 cmp
->pixel_width
= rightmost
;
27515 cmp
->ascent
= highest
;
27516 cmp
->descent
= - lowest
;
27517 if (cmp
->ascent
< font_ascent
)
27518 cmp
->ascent
= font_ascent
;
27519 if (cmp
->descent
< font_descent
)
27520 cmp
->descent
= font_descent
;
27524 && (cmp
->lbearing
< 0
27525 || cmp
->rbearing
> cmp
->pixel_width
))
27526 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27528 it
->pixel_width
= cmp
->pixel_width
;
27529 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
27530 it
->descent
= it
->phys_descent
= cmp
->descent
;
27531 if (face
->box
!= FACE_NO_BOX
)
27533 int thick
= face
->box_line_width
;
27537 it
->ascent
+= thick
;
27538 it
->descent
+= thick
;
27543 if (it
->start_of_box_run_p
)
27544 it
->pixel_width
+= thick
;
27545 if (it
->end_of_box_run_p
)
27546 it
->pixel_width
+= thick
;
27549 /* If face has an overline, add the height of the overline
27550 (1 pixel) and a 1 pixel margin to the character height. */
27551 if (face
->overline_p
)
27552 it
->ascent
+= overline_margin
;
27554 take_vertical_position_into_account (it
);
27555 if (it
->ascent
< 0)
27557 if (it
->descent
< 0)
27560 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
27561 append_composite_glyph (it
);
27563 else if (it
->what
== IT_COMPOSITION
)
27565 /* A dynamic (automatic) composition. */
27566 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
27567 Lisp_Object gstring
;
27568 struct font_metrics metrics
;
27572 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
27574 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
27577 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
27578 it
->glyph_row
->contains_overlapping_glyphs_p
= true;
27579 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
27580 it
->descent
= it
->phys_descent
= metrics
.descent
;
27581 if (face
->box
!= FACE_NO_BOX
)
27583 int thick
= face
->box_line_width
;
27587 it
->ascent
+= thick
;
27588 it
->descent
+= thick
;
27593 if (it
->start_of_box_run_p
)
27594 it
->pixel_width
+= thick
;
27595 if (it
->end_of_box_run_p
)
27596 it
->pixel_width
+= thick
;
27598 /* If face has an overline, add the height of the overline
27599 (1 pixel) and a 1 pixel margin to the character height. */
27600 if (face
->overline_p
)
27601 it
->ascent
+= overline_margin
;
27602 take_vertical_position_into_account (it
);
27603 if (it
->ascent
< 0)
27605 if (it
->descent
< 0)
27609 append_composite_glyph (it
);
27611 else if (it
->what
== IT_GLYPHLESS
)
27612 produce_glyphless_glyph (it
, false, Qnil
);
27613 else if (it
->what
== IT_IMAGE
)
27614 produce_image_glyph (it
);
27615 else if (it
->what
== IT_STRETCH
)
27616 produce_stretch_glyph (it
);
27617 else if (it
->what
== IT_XWIDGET
)
27618 produce_xwidget_glyph (it
);
27621 /* Accumulate dimensions. Note: can't assume that it->descent > 0
27622 because this isn't true for images with `:ascent 100'. */
27623 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
27624 if (it
->area
== TEXT_AREA
)
27625 it
->current_x
+= it
->pixel_width
;
27627 if (extra_line_spacing
> 0)
27629 it
->descent
+= extra_line_spacing
;
27630 if (extra_line_spacing
> it
->max_extra_line_spacing
)
27631 it
->max_extra_line_spacing
= extra_line_spacing
;
27634 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
27635 it
->max_descent
= max (it
->max_descent
, it
->descent
);
27636 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
27637 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
27641 Output LEN glyphs starting at START at the nominal cursor position.
27642 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
27643 being updated, and UPDATED_AREA is the area of that row being updated. */
27646 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27647 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27649 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
27651 eassert (updated_row
);
27652 /* When the window is hscrolled, cursor hpos can legitimately be out
27653 of bounds, but we draw the cursor at the corresponding window
27654 margin in that case. */
27655 if (!updated_row
->reversed_p
&& chpos
< 0)
27657 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
27658 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
27662 /* Write glyphs. */
27664 hpos
= start
- updated_row
->glyphs
[updated_area
];
27665 x
= draw_glyphs (w
, w
->output_cursor
.x
,
27666 updated_row
, updated_area
,
27668 DRAW_NORMAL_TEXT
, 0);
27670 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
27671 if (updated_area
== TEXT_AREA
27672 && w
->phys_cursor_on_p
27673 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
27675 && chpos
< hpos
+ len
)
27676 w
->phys_cursor_on_p
= false;
27680 /* Advance the output cursor. */
27681 w
->output_cursor
.hpos
+= len
;
27682 w
->output_cursor
.x
= x
;
27687 Insert LEN glyphs from START at the nominal cursor position. */
27690 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27691 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27694 int line_height
, shift_by_width
, shifted_region_width
;
27695 struct glyph_row
*row
;
27696 struct glyph
*glyph
;
27697 int frame_x
, frame_y
;
27700 eassert (updated_row
);
27702 f
= XFRAME (WINDOW_FRAME (w
));
27704 /* Get the height of the line we are in. */
27706 line_height
= row
->height
;
27708 /* Get the width of the glyphs to insert. */
27709 shift_by_width
= 0;
27710 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
27711 shift_by_width
+= glyph
->pixel_width
;
27713 /* Get the width of the region to shift right. */
27714 shifted_region_width
= (window_box_width (w
, updated_area
)
27715 - w
->output_cursor
.x
27719 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
27720 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
27722 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
27723 line_height
, shift_by_width
);
27725 /* Write the glyphs. */
27726 hpos
= start
- row
->glyphs
[updated_area
];
27727 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
27729 DRAW_NORMAL_TEXT
, 0);
27731 /* Advance the output cursor. */
27732 w
->output_cursor
.hpos
+= len
;
27733 w
->output_cursor
.x
+= shift_by_width
;
27739 Erase the current text line from the nominal cursor position
27740 (inclusive) to pixel column TO_X (exclusive). The idea is that
27741 everything from TO_X onward is already erased.
27743 TO_X is a pixel position relative to UPDATED_AREA of currently
27744 updated window W. TO_X == -1 means clear to the end of this area. */
27747 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
27748 enum glyph_row_area updated_area
, int to_x
)
27751 int max_x
, min_y
, max_y
;
27752 int from_x
, from_y
, to_y
;
27754 eassert (updated_row
);
27755 f
= XFRAME (w
->frame
);
27757 if (updated_row
->full_width_p
)
27758 max_x
= (WINDOW_PIXEL_WIDTH (w
)
27759 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
27761 max_x
= window_box_width (w
, updated_area
);
27762 max_y
= window_text_bottom_y (w
);
27764 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
27765 of window. For TO_X > 0, truncate to end of drawing area. */
27771 to_x
= min (to_x
, max_x
);
27773 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
27775 /* Notice if the cursor will be cleared by this operation. */
27776 if (!updated_row
->full_width_p
)
27777 notice_overwritten_cursor (w
, updated_area
,
27778 w
->output_cursor
.x
, -1,
27780 MATRIX_ROW_BOTTOM_Y (updated_row
));
27782 from_x
= w
->output_cursor
.x
;
27784 /* Translate to frame coordinates. */
27785 if (updated_row
->full_width_p
)
27787 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
27788 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
27792 int area_left
= window_box_left (w
, updated_area
);
27793 from_x
+= area_left
;
27797 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
27798 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
27799 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
27801 /* Prevent inadvertently clearing to end of the X window. */
27802 if (to_x
> from_x
&& to_y
> from_y
)
27805 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
27806 to_x
- from_x
, to_y
- from_y
);
27811 #endif /* HAVE_WINDOW_SYSTEM */
27815 /***********************************************************************
27817 ***********************************************************************/
27819 /* Value is the internal representation of the specified cursor type
27820 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
27821 of the bar cursor. */
27823 static enum text_cursor_kinds
27824 get_specified_cursor_type (Lisp_Object arg
, int *width
)
27826 enum text_cursor_kinds type
;
27831 if (EQ (arg
, Qbox
))
27832 return FILLED_BOX_CURSOR
;
27834 if (EQ (arg
, Qhollow
))
27835 return HOLLOW_BOX_CURSOR
;
27837 if (EQ (arg
, Qbar
))
27844 && EQ (XCAR (arg
), Qbar
)
27845 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27847 *width
= XINT (XCDR (arg
));
27851 if (EQ (arg
, Qhbar
))
27854 return HBAR_CURSOR
;
27858 && EQ (XCAR (arg
), Qhbar
)
27859 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27861 *width
= XINT (XCDR (arg
));
27862 return HBAR_CURSOR
;
27865 /* Treat anything unknown as "hollow box cursor".
27866 It was bad to signal an error; people have trouble fixing
27867 .Xdefaults with Emacs, when it has something bad in it. */
27868 type
= HOLLOW_BOX_CURSOR
;
27873 /* Set the default cursor types for specified frame. */
27875 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
27880 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
27881 FRAME_CURSOR_WIDTH (f
) = width
;
27883 /* By default, set up the blink-off state depending on the on-state. */
27885 tem
= Fassoc (arg
, Vblink_cursor_alist
);
27888 FRAME_BLINK_OFF_CURSOR (f
)
27889 = get_specified_cursor_type (XCDR (tem
), &width
);
27890 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
27893 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
27895 /* Make sure the cursor gets redrawn. */
27896 f
->cursor_type_changed
= true;
27900 #ifdef HAVE_WINDOW_SYSTEM
27902 /* Return the cursor we want to be displayed in window W. Return
27903 width of bar/hbar cursor through WIDTH arg. Return with
27904 ACTIVE_CURSOR arg set to true if cursor in window W is `active'
27905 (i.e. if the `system caret' should track this cursor).
27907 In a mini-buffer window, we want the cursor only to appear if we
27908 are reading input from this window. For the selected window, we
27909 want the cursor type given by the frame parameter or buffer local
27910 setting of cursor-type. If explicitly marked off, draw no cursor.
27911 In all other cases, we want a hollow box cursor. */
27913 static enum text_cursor_kinds
27914 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
27915 bool *active_cursor
)
27917 struct frame
*f
= XFRAME (w
->frame
);
27918 struct buffer
*b
= XBUFFER (w
->contents
);
27919 int cursor_type
= DEFAULT_CURSOR
;
27920 Lisp_Object alt_cursor
;
27921 bool non_selected
= false;
27923 *active_cursor
= true;
27926 if (cursor_in_echo_area
27927 && FRAME_HAS_MINIBUF_P (f
)
27928 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
27930 if (w
== XWINDOW (echo_area_window
))
27932 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
27934 *width
= FRAME_CURSOR_WIDTH (f
);
27935 return FRAME_DESIRED_CURSOR (f
);
27938 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27941 *active_cursor
= false;
27942 non_selected
= true;
27945 /* Detect a nonselected window or nonselected frame. */
27946 else if (w
!= XWINDOW (f
->selected_window
)
27947 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
27949 *active_cursor
= false;
27951 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
27954 non_selected
= true;
27957 /* Never display a cursor in a window in which cursor-type is nil. */
27958 if (NILP (BVAR (b
, cursor_type
)))
27961 /* Get the normal cursor type for this window. */
27962 if (EQ (BVAR (b
, cursor_type
), Qt
))
27964 cursor_type
= FRAME_DESIRED_CURSOR (f
);
27965 *width
= FRAME_CURSOR_WIDTH (f
);
27968 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27970 /* Use cursor-in-non-selected-windows instead
27971 for non-selected window or frame. */
27974 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
27975 if (!EQ (Qt
, alt_cursor
))
27976 return get_specified_cursor_type (alt_cursor
, width
);
27977 /* t means modify the normal cursor type. */
27978 if (cursor_type
== FILLED_BOX_CURSOR
)
27979 cursor_type
= HOLLOW_BOX_CURSOR
;
27980 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
27982 return cursor_type
;
27985 /* Use normal cursor if not blinked off. */
27986 if (!w
->cursor_off_p
)
27988 if (glyph
!= NULL
&& glyph
->type
== XWIDGET_GLYPH
)
27990 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27992 if (cursor_type
== FILLED_BOX_CURSOR
)
27994 /* Using a block cursor on large images can be very annoying.
27995 So use a hollow cursor for "large" images.
27996 If image is not transparent (no mask), also use hollow cursor. */
27997 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27998 if (img
!= NULL
&& IMAGEP (img
->spec
))
28000 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
28001 where N = size of default frame font size.
28002 This should cover most of the "tiny" icons people may use. */
28004 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
28005 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
28006 cursor_type
= HOLLOW_BOX_CURSOR
;
28009 else if (cursor_type
!= NO_CURSOR
)
28011 /* Display current only supports BOX and HOLLOW cursors for images.
28012 So for now, unconditionally use a HOLLOW cursor when cursor is
28013 not a solid box cursor. */
28014 cursor_type
= HOLLOW_BOX_CURSOR
;
28017 return cursor_type
;
28020 /* Cursor is blinked off, so determine how to "toggle" it. */
28022 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
28023 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
28024 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
28026 /* Then see if frame has specified a specific blink off cursor type. */
28027 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
28029 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
28030 return FRAME_BLINK_OFF_CURSOR (f
);
28034 /* Some people liked having a permanently visible blinking cursor,
28035 while others had very strong opinions against it. So it was
28036 decided to remove it. KFS 2003-09-03 */
28038 /* Finally perform built-in cursor blinking:
28039 filled box <-> hollow box
28040 wide [h]bar <-> narrow [h]bar
28041 narrow [h]bar <-> no cursor
28042 other type <-> no cursor */
28044 if (cursor_type
== FILLED_BOX_CURSOR
)
28045 return HOLLOW_BOX_CURSOR
;
28047 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
28050 return cursor_type
;
28058 /* Notice when the text cursor of window W has been completely
28059 overwritten by a drawing operation that outputs glyphs in AREA
28060 starting at X0 and ending at X1 in the line starting at Y0 and
28061 ending at Y1. X coordinates are area-relative. X1 < 0 means all
28062 the rest of the line after X0 has been written. Y coordinates
28063 are window-relative. */
28066 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
28067 int x0
, int x1
, int y0
, int y1
)
28069 int cx0
, cx1
, cy0
, cy1
;
28070 struct glyph_row
*row
;
28072 if (!w
->phys_cursor_on_p
)
28074 if (area
!= TEXT_AREA
)
28077 if (w
->phys_cursor
.vpos
< 0
28078 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
28079 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
28080 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
28083 if (row
->cursor_in_fringe_p
)
28085 row
->cursor_in_fringe_p
= false;
28086 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
28087 w
->phys_cursor_on_p
= false;
28091 cx0
= w
->phys_cursor
.x
;
28092 cx1
= cx0
+ w
->phys_cursor_width
;
28093 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
28096 /* The cursor image will be completely removed from the
28097 screen if the output area intersects the cursor area in
28098 y-direction. When we draw in [y0 y1[, and some part of
28099 the cursor is at y < y0, that part must have been drawn
28100 before. When scrolling, the cursor is erased before
28101 actually scrolling, so we don't come here. When not
28102 scrolling, the rows above the old cursor row must have
28103 changed, and in this case these rows must have written
28104 over the cursor image.
28106 Likewise if part of the cursor is below y1, with the
28107 exception of the cursor being in the first blank row at
28108 the buffer and window end because update_text_area
28109 doesn't draw that row. (Except when it does, but
28110 that's handled in update_text_area.) */
28112 cy0
= w
->phys_cursor
.y
;
28113 cy1
= cy0
+ w
->phys_cursor_height
;
28114 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
28117 w
->phys_cursor_on_p
= false;
28120 #endif /* HAVE_WINDOW_SYSTEM */
28123 /************************************************************************
28125 ************************************************************************/
28127 #ifdef HAVE_WINDOW_SYSTEM
28130 Fix the display of area AREA of overlapping row ROW in window W
28131 with respect to the overlapping part OVERLAPS. */
28134 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
28135 enum glyph_row_area area
, int overlaps
)
28142 for (i
= 0; i
< row
->used
[area
];)
28144 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
28146 int start
= i
, start_x
= x
;
28150 x
+= row
->glyphs
[area
][i
].pixel_width
;
28153 while (i
< row
->used
[area
]
28154 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
28156 draw_glyphs (w
, start_x
, row
, area
,
28158 DRAW_NORMAL_TEXT
, overlaps
);
28162 x
+= row
->glyphs
[area
][i
].pixel_width
;
28172 Draw the cursor glyph of window W in glyph row ROW. See the
28173 comment of draw_glyphs for the meaning of HL. */
28176 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
28177 enum draw_glyphs_face hl
)
28179 /* If cursor hpos is out of bounds, don't draw garbage. This can
28180 happen in mini-buffer windows when switching between echo area
28181 glyphs and mini-buffer. */
28182 if ((row
->reversed_p
28183 ? (w
->phys_cursor
.hpos
>= 0)
28184 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
28186 bool on_p
= w
->phys_cursor_on_p
;
28188 int hpos
= w
->phys_cursor
.hpos
;
28190 /* When the window is hscrolled, cursor hpos can legitimately be
28191 out of bounds, but we draw the cursor at the corresponding
28192 window margin in that case. */
28193 if (!row
->reversed_p
&& hpos
< 0)
28195 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28196 hpos
= row
->used
[TEXT_AREA
] - 1;
28198 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
28200 w
->phys_cursor_on_p
= on_p
;
28202 if (hl
== DRAW_CURSOR
)
28203 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
28204 /* When we erase the cursor, and ROW is overlapped by other
28205 rows, make sure that these overlapping parts of other rows
28207 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
28209 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
28211 if (row
> w
->current_matrix
->rows
28212 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
28213 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
28214 OVERLAPS_ERASED_CURSOR
);
28216 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
28217 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
28218 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
28219 OVERLAPS_ERASED_CURSOR
);
28225 /* Erase the image of a cursor of window W from the screen. */
28228 erase_phys_cursor (struct window
*w
)
28230 struct frame
*f
= XFRAME (w
->frame
);
28231 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28232 int hpos
= w
->phys_cursor
.hpos
;
28233 int vpos
= w
->phys_cursor
.vpos
;
28234 bool mouse_face_here_p
= false;
28235 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
28236 struct glyph_row
*cursor_row
;
28237 struct glyph
*cursor_glyph
;
28238 enum draw_glyphs_face hl
;
28240 /* No cursor displayed or row invalidated => nothing to do on the
28242 if (w
->phys_cursor_type
== NO_CURSOR
)
28243 goto mark_cursor_off
;
28245 /* VPOS >= active_glyphs->nrows means that window has been resized.
28246 Don't bother to erase the cursor. */
28247 if (vpos
>= active_glyphs
->nrows
)
28248 goto mark_cursor_off
;
28250 /* If row containing cursor is marked invalid, there is nothing we
28252 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
28253 if (!cursor_row
->enabled_p
)
28254 goto mark_cursor_off
;
28256 /* If line spacing is > 0, old cursor may only be partially visible in
28257 window after split-window. So adjust visible height. */
28258 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
28259 window_text_bottom_y (w
) - cursor_row
->y
);
28261 /* If row is completely invisible, don't attempt to delete a cursor which
28262 isn't there. This can happen if cursor is at top of a window, and
28263 we switch to a buffer with a header line in that window. */
28264 if (cursor_row
->visible_height
<= 0)
28265 goto mark_cursor_off
;
28267 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
28268 if (cursor_row
->cursor_in_fringe_p
)
28270 cursor_row
->cursor_in_fringe_p
= false;
28271 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
28272 goto mark_cursor_off
;
28275 /* This can happen when the new row is shorter than the old one.
28276 In this case, either draw_glyphs or clear_end_of_line
28277 should have cleared the cursor. Note that we wouldn't be
28278 able to erase the cursor in this case because we don't have a
28279 cursor glyph at hand. */
28280 if ((cursor_row
->reversed_p
28281 ? (w
->phys_cursor
.hpos
< 0)
28282 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
28283 goto mark_cursor_off
;
28285 /* When the window is hscrolled, cursor hpos can legitimately be out
28286 of bounds, but we draw the cursor at the corresponding window
28287 margin in that case. */
28288 if (!cursor_row
->reversed_p
&& hpos
< 0)
28290 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
28291 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
28293 /* If the cursor is in the mouse face area, redisplay that when
28294 we clear the cursor. */
28295 if (! NILP (hlinfo
->mouse_face_window
)
28296 && coords_in_mouse_face_p (w
, hpos
, vpos
)
28297 /* Don't redraw the cursor's spot in mouse face if it is at the
28298 end of a line (on a newline). The cursor appears there, but
28299 mouse highlighting does not. */
28300 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
28301 mouse_face_here_p
= true;
28303 /* Maybe clear the display under the cursor. */
28304 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
28307 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
28310 cursor_glyph
= get_phys_cursor_glyph (w
);
28311 if (cursor_glyph
== NULL
)
28312 goto mark_cursor_off
;
28314 width
= cursor_glyph
->pixel_width
;
28315 x
= w
->phys_cursor
.x
;
28321 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
28322 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
28323 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
28326 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
28329 /* Erase the cursor by redrawing the character underneath it. */
28330 if (mouse_face_here_p
)
28331 hl
= DRAW_MOUSE_FACE
;
28333 hl
= DRAW_NORMAL_TEXT
;
28334 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
28337 w
->phys_cursor_on_p
= false;
28338 w
->phys_cursor_type
= NO_CURSOR
;
28342 /* Display or clear cursor of window W. If !ON, clear the cursor.
28343 If ON, display the cursor; where to put the cursor is specified by
28344 HPOS, VPOS, X and Y. */
28347 display_and_set_cursor (struct window
*w
, bool on
,
28348 int hpos
, int vpos
, int x
, int y
)
28350 struct frame
*f
= XFRAME (w
->frame
);
28351 int new_cursor_type
;
28352 int new_cursor_width
;
28353 bool active_cursor
;
28354 struct glyph_row
*glyph_row
;
28355 struct glyph
*glyph
;
28357 /* This is pointless on invisible frames, and dangerous on garbaged
28358 windows and frames; in the latter case, the frame or window may
28359 be in the midst of changing its size, and x and y may be off the
28361 if (! FRAME_VISIBLE_P (f
)
28362 || FRAME_GARBAGED_P (f
)
28363 || vpos
>= w
->current_matrix
->nrows
28364 || hpos
>= w
->current_matrix
->matrix_w
)
28367 /* If cursor is off and we want it off, return quickly. */
28368 if (!on
&& !w
->phys_cursor_on_p
)
28371 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28372 /* If cursor row is not enabled, we don't really know where to
28373 display the cursor. */
28374 if (!glyph_row
->enabled_p
)
28376 w
->phys_cursor_on_p
= false;
28381 if (!glyph_row
->exact_window_width_line_p
28382 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
28383 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
28385 eassert (input_blocked_p ());
28387 /* Set new_cursor_type to the cursor we want to be displayed. */
28388 new_cursor_type
= get_window_cursor_type (w
, glyph
,
28389 &new_cursor_width
, &active_cursor
);
28391 /* If cursor is currently being shown and we don't want it to be or
28392 it is in the wrong place, or the cursor type is not what we want,
28394 if (w
->phys_cursor_on_p
28396 || w
->phys_cursor
.x
!= x
28397 || w
->phys_cursor
.y
!= y
28398 /* HPOS can be negative in R2L rows whose
28399 exact_window_width_line_p flag is set (i.e. their newline
28400 would "overflow into the fringe"). */
28402 || new_cursor_type
!= w
->phys_cursor_type
28403 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
28404 && new_cursor_width
!= w
->phys_cursor_width
)))
28405 erase_phys_cursor (w
);
28407 /* Don't check phys_cursor_on_p here because that flag is only set
28408 to false in some cases where we know that the cursor has been
28409 completely erased, to avoid the extra work of erasing the cursor
28410 twice. In other words, phys_cursor_on_p can be true and the cursor
28411 still not be visible, or it has only been partly erased. */
28414 w
->phys_cursor_ascent
= glyph_row
->ascent
;
28415 w
->phys_cursor_height
= glyph_row
->height
;
28417 /* Set phys_cursor_.* before x_draw_.* is called because some
28418 of them may need the information. */
28419 w
->phys_cursor
.x
= x
;
28420 w
->phys_cursor
.y
= glyph_row
->y
;
28421 w
->phys_cursor
.hpos
= hpos
;
28422 w
->phys_cursor
.vpos
= vpos
;
28425 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
28426 new_cursor_type
, new_cursor_width
,
28427 on
, active_cursor
);
28431 /* Switch the display of W's cursor on or off, according to the value
28435 update_window_cursor (struct window
*w
, bool on
)
28437 /* Don't update cursor in windows whose frame is in the process
28438 of being deleted. */
28439 if (w
->current_matrix
)
28441 int hpos
= w
->phys_cursor
.hpos
;
28442 int vpos
= w
->phys_cursor
.vpos
;
28443 struct glyph_row
*row
;
28445 if (vpos
>= w
->current_matrix
->nrows
28446 || hpos
>= w
->current_matrix
->matrix_w
)
28449 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28451 /* When the window is hscrolled, cursor hpos can legitimately be
28452 out of bounds, but we draw the cursor at the corresponding
28453 window margin in that case. */
28454 if (!row
->reversed_p
&& hpos
< 0)
28456 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28457 hpos
= row
->used
[TEXT_AREA
] - 1;
28460 display_and_set_cursor (w
, on
, hpos
, vpos
,
28461 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28467 /* Call update_window_cursor with parameter ON_P on all leaf windows
28468 in the window tree rooted at W. */
28471 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
28475 if (WINDOWP (w
->contents
))
28476 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
28478 update_window_cursor (w
, on_p
);
28480 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
28486 Display the cursor on window W, or clear it, according to ON_P.
28487 Don't change the cursor's position. */
28490 x_update_cursor (struct frame
*f
, bool on_p
)
28492 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
28497 Clear the cursor of window W to background color, and mark the
28498 cursor as not shown. This is used when the text where the cursor
28499 is about to be rewritten. */
28502 x_clear_cursor (struct window
*w
)
28504 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
28505 update_window_cursor (w
, false);
28508 #endif /* HAVE_WINDOW_SYSTEM */
28510 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
28513 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
28514 int start_hpos
, int end_hpos
,
28515 enum draw_glyphs_face draw
)
28517 #ifdef HAVE_WINDOW_SYSTEM
28518 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
28520 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
28524 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
28525 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
28529 /* Display the active region described by mouse_face_* according to DRAW. */
28532 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
28534 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
28535 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28537 if (/* If window is in the process of being destroyed, don't bother
28539 w
->current_matrix
!= NULL
28540 /* Don't update mouse highlight if hidden. */
28541 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
28542 /* Recognize when we are called to operate on rows that don't exist
28543 anymore. This can happen when a window is split. */
28544 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
28546 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
28547 struct glyph_row
*row
, *first
, *last
;
28549 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
28550 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
28552 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
28554 int start_hpos
, end_hpos
, start_x
;
28556 /* For all but the first row, the highlight starts at column 0. */
28559 /* R2L rows have BEG and END in reversed order, but the
28560 screen drawing geometry is always left to right. So
28561 we need to mirror the beginning and end of the
28562 highlighted area in R2L rows. */
28563 if (!row
->reversed_p
)
28565 start_hpos
= hlinfo
->mouse_face_beg_col
;
28566 start_x
= hlinfo
->mouse_face_beg_x
;
28568 else if (row
== last
)
28570 start_hpos
= hlinfo
->mouse_face_end_col
;
28571 start_x
= hlinfo
->mouse_face_end_x
;
28579 else if (row
->reversed_p
&& row
== last
)
28581 start_hpos
= hlinfo
->mouse_face_end_col
;
28582 start_x
= hlinfo
->mouse_face_end_x
;
28592 if (!row
->reversed_p
)
28593 end_hpos
= hlinfo
->mouse_face_end_col
;
28594 else if (row
== first
)
28595 end_hpos
= hlinfo
->mouse_face_beg_col
;
28598 end_hpos
= row
->used
[TEXT_AREA
];
28599 if (draw
== DRAW_NORMAL_TEXT
)
28600 row
->fill_line_p
= true; /* Clear to end of line. */
28603 else if (row
->reversed_p
&& row
== first
)
28604 end_hpos
= hlinfo
->mouse_face_beg_col
;
28607 end_hpos
= row
->used
[TEXT_AREA
];
28608 if (draw
== DRAW_NORMAL_TEXT
)
28609 row
->fill_line_p
= true; /* Clear to end of line. */
28612 if (end_hpos
> start_hpos
)
28614 draw_row_with_mouse_face (w
, start_x
, row
,
28615 start_hpos
, end_hpos
, draw
);
28618 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
28622 #ifdef HAVE_WINDOW_SYSTEM
28623 /* When we've written over the cursor, arrange for it to
28624 be displayed again. */
28625 if (FRAME_WINDOW_P (f
)
28626 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
28628 int hpos
= w
->phys_cursor
.hpos
;
28630 /* When the window is hscrolled, cursor hpos can legitimately be
28631 out of bounds, but we draw the cursor at the corresponding
28632 window margin in that case. */
28633 if (!row
->reversed_p
&& hpos
< 0)
28635 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28636 hpos
= row
->used
[TEXT_AREA
] - 1;
28639 display_and_set_cursor (w
, true, hpos
, w
->phys_cursor
.vpos
,
28640 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28643 #endif /* HAVE_WINDOW_SYSTEM */
28646 #ifdef HAVE_WINDOW_SYSTEM
28647 /* Change the mouse cursor. */
28648 if (FRAME_WINDOW_P (f
) && NILP (do_mouse_tracking
))
28650 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
28651 if (draw
== DRAW_NORMAL_TEXT
28652 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
28653 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
28656 if (draw
== DRAW_MOUSE_FACE
)
28657 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
28659 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
28661 #endif /* HAVE_WINDOW_SYSTEM */
28665 Clear out the mouse-highlighted active region.
28666 Redraw it un-highlighted first. Value is true if mouse
28667 face was actually drawn unhighlighted. */
28670 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
28673 = !hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
);
28675 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
28676 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28677 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28678 hlinfo
->mouse_face_window
= Qnil
;
28679 hlinfo
->mouse_face_overlay
= Qnil
;
28683 /* Return true if the coordinates HPOS and VPOS on windows W are
28684 within the mouse face on that window. */
28686 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
28688 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28690 /* Quickly resolve the easy cases. */
28691 if (!(WINDOWP (hlinfo
->mouse_face_window
)
28692 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
28694 if (vpos
< hlinfo
->mouse_face_beg_row
28695 || vpos
> hlinfo
->mouse_face_end_row
)
28697 if (vpos
> hlinfo
->mouse_face_beg_row
28698 && vpos
< hlinfo
->mouse_face_end_row
)
28701 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
28703 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28705 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
28708 else if ((vpos
== hlinfo
->mouse_face_beg_row
28709 && hpos
>= hlinfo
->mouse_face_beg_col
)
28710 || (vpos
== hlinfo
->mouse_face_end_row
28711 && hpos
< hlinfo
->mouse_face_end_col
))
28716 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28718 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
28721 else if ((vpos
== hlinfo
->mouse_face_beg_row
28722 && hpos
<= hlinfo
->mouse_face_beg_col
)
28723 || (vpos
== hlinfo
->mouse_face_end_row
28724 && hpos
> hlinfo
->mouse_face_end_col
))
28732 True if physical cursor of window W is within mouse face. */
28735 cursor_in_mouse_face_p (struct window
*w
)
28737 int hpos
= w
->phys_cursor
.hpos
;
28738 int vpos
= w
->phys_cursor
.vpos
;
28739 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28741 /* When the window is hscrolled, cursor hpos can legitimately be out
28742 of bounds, but we draw the cursor at the corresponding window
28743 margin in that case. */
28744 if (!row
->reversed_p
&& hpos
< 0)
28746 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28747 hpos
= row
->used
[TEXT_AREA
] - 1;
28749 return coords_in_mouse_face_p (w
, hpos
, vpos
);
28754 /* Find the glyph rows START_ROW and END_ROW of window W that display
28755 characters between buffer positions START_CHARPOS and END_CHARPOS
28756 (excluding END_CHARPOS). DISP_STRING is a display string that
28757 covers these buffer positions. This is similar to
28758 row_containing_pos, but is more accurate when bidi reordering makes
28759 buffer positions change non-linearly with glyph rows. */
28761 rows_from_pos_range (struct window
*w
,
28762 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
28763 Lisp_Object disp_string
,
28764 struct glyph_row
**start
, struct glyph_row
**end
)
28766 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28767 int last_y
= window_text_bottom_y (w
);
28768 struct glyph_row
*row
;
28773 while (!first
->enabled_p
28774 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
28777 /* Find the START row. */
28779 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
28782 /* A row can potentially be the START row if the range of the
28783 characters it displays intersects the range
28784 [START_CHARPOS..END_CHARPOS). */
28785 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
28786 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
28787 /* See the commentary in row_containing_pos, for the
28788 explanation of the complicated way to check whether
28789 some position is beyond the end of the characters
28790 displayed by a row. */
28791 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28792 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28793 && !row
->ends_at_zv_p
28794 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
28795 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28796 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28797 && !row
->ends_at_zv_p
28798 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
28800 /* Found a candidate row. Now make sure at least one of the
28801 glyphs it displays has a charpos from the range
28802 [START_CHARPOS..END_CHARPOS).
28804 This is not obvious because bidi reordering could make
28805 buffer positions of a row be 1,2,3,102,101,100, and if we
28806 want to highlight characters in [50..60), we don't want
28807 this row, even though [50..60) does intersect [1..103),
28808 the range of character positions given by the row's start
28809 and end positions. */
28810 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
28811 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
28815 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28816 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28817 /* A glyph that comes from DISP_STRING is by
28818 definition to be highlighted. */
28819 || EQ (g
->object
, disp_string
))
28828 /* Find the END row. */
28830 /* If the last row is partially visible, start looking for END
28831 from that row, instead of starting from FIRST. */
28832 && !(row
->enabled_p
28833 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
28835 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
28837 struct glyph_row
*next
= row
+ 1;
28838 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
28840 if (!next
->enabled_p
28841 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
28842 /* The first row >= START whose range of displayed characters
28843 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
28844 is the row END + 1. */
28845 || (start_charpos
< next_start
28846 && end_charpos
< next_start
)
28847 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28848 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28849 && !next
->ends_at_zv_p
28850 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
28851 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28852 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28853 && !next
->ends_at_zv_p
28854 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
28861 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
28862 but none of the characters it displays are in the range, it is
28864 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
28865 struct glyph
*s
= g
;
28866 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
28870 if (((BUFFERP (g
->object
) || NILP (g
->object
))
28871 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28872 /* If the buffer position of the first glyph in
28873 the row is equal to END_CHARPOS, it means
28874 the last character to be highlighted is the
28875 newline of ROW, and we must consider NEXT as
28877 || (((!next
->reversed_p
&& g
== s
)
28878 || (next
->reversed_p
&& g
== e
- 1))
28879 && (g
->charpos
== end_charpos
28880 /* Special case for when NEXT is an
28881 empty line at ZV. */
28882 || (g
->charpos
== -1
28883 && !row
->ends_at_zv_p
28884 && next_start
== end_charpos
)))))
28885 /* A glyph that comes from DISP_STRING is by
28886 definition to be highlighted. */
28887 || EQ (g
->object
, disp_string
))
28896 /* The first row that ends at ZV must be the last to be
28898 else if (next
->ends_at_zv_p
)
28907 /* This function sets the mouse_face_* elements of HLINFO, assuming
28908 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
28909 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
28910 for the overlay or run of text properties specifying the mouse
28911 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
28912 before-string and after-string that must also be highlighted.
28913 DISP_STRING, if non-nil, is a display string that may cover some
28914 or all of the highlighted text. */
28917 mouse_face_from_buffer_pos (Lisp_Object window
,
28918 Mouse_HLInfo
*hlinfo
,
28919 ptrdiff_t mouse_charpos
,
28920 ptrdiff_t start_charpos
,
28921 ptrdiff_t end_charpos
,
28922 Lisp_Object before_string
,
28923 Lisp_Object after_string
,
28924 Lisp_Object disp_string
)
28926 struct window
*w
= XWINDOW (window
);
28927 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28928 struct glyph_row
*r1
, *r2
;
28929 struct glyph
*glyph
, *end
;
28930 ptrdiff_t ignore
, pos
;
28933 eassert (NILP (disp_string
) || STRINGP (disp_string
));
28934 eassert (NILP (before_string
) || STRINGP (before_string
));
28935 eassert (NILP (after_string
) || STRINGP (after_string
));
28937 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
28938 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
28940 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28941 /* If the before-string or display-string contains newlines,
28942 rows_from_pos_range skips to its last row. Move back. */
28943 if (!NILP (before_string
) || !NILP (disp_string
))
28945 struct glyph_row
*prev
;
28946 while ((prev
= r1
- 1, prev
>= first
)
28947 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
28948 && prev
->used
[TEXT_AREA
] > 0)
28950 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
28951 glyph
= beg
+ prev
->used
[TEXT_AREA
];
28952 while (--glyph
>= beg
&& NILP (glyph
->object
));
28954 || !(EQ (glyph
->object
, before_string
)
28955 || EQ (glyph
->object
, disp_string
)))
28962 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28963 hlinfo
->mouse_face_past_end
= true;
28965 else if (!NILP (after_string
))
28967 /* If the after-string has newlines, advance to its last row. */
28968 struct glyph_row
*next
;
28969 struct glyph_row
*last
28970 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28972 for (next
= r2
+ 1;
28974 && next
->used
[TEXT_AREA
] > 0
28975 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
28979 /* The rest of the display engine assumes that mouse_face_beg_row is
28980 either above mouse_face_end_row or identical to it. But with
28981 bidi-reordered continued lines, the row for START_CHARPOS could
28982 be below the row for END_CHARPOS. If so, swap the rows and store
28983 them in correct order. */
28986 struct glyph_row
*tem
= r2
;
28992 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
28993 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
28995 /* For a bidi-reordered row, the positions of BEFORE_STRING,
28996 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
28997 could be anywhere in the row and in any order. The strategy
28998 below is to find the leftmost and the rightmost glyph that
28999 belongs to either of these 3 strings, or whose position is
29000 between START_CHARPOS and END_CHARPOS, and highlight all the
29001 glyphs between those two. This may cover more than just the text
29002 between START_CHARPOS and END_CHARPOS if the range of characters
29003 strides the bidi level boundary, e.g. if the beginning is in R2L
29004 text while the end is in L2R text or vice versa. */
29005 if (!r1
->reversed_p
)
29007 /* This row is in a left to right paragraph. Scan it left to
29009 glyph
= r1
->glyphs
[TEXT_AREA
];
29010 end
= glyph
+ r1
->used
[TEXT_AREA
];
29013 /* Skip truncation glyphs at the start of the glyph row. */
29014 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
29016 && NILP (glyph
->object
)
29017 && glyph
->charpos
< 0;
29019 x
+= glyph
->pixel_width
;
29021 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
29022 or DISP_STRING, and the first glyph from buffer whose
29023 position is between START_CHARPOS and END_CHARPOS. */
29025 && !NILP (glyph
->object
)
29026 && !EQ (glyph
->object
, disp_string
)
29027 && !(BUFFERP (glyph
->object
)
29028 && (glyph
->charpos
>= start_charpos
29029 && glyph
->charpos
< end_charpos
));
29032 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29033 are present at buffer positions between START_CHARPOS and
29034 END_CHARPOS, or if they come from an overlay. */
29035 if (EQ (glyph
->object
, before_string
))
29037 pos
= string_buffer_position (before_string
,
29039 /* If pos == 0, it means before_string came from an
29040 overlay, not from a buffer position. */
29041 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29044 else if (EQ (glyph
->object
, after_string
))
29046 pos
= string_buffer_position (after_string
, end_charpos
);
29047 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29050 x
+= glyph
->pixel_width
;
29052 hlinfo
->mouse_face_beg_x
= x
;
29053 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
29057 /* This row is in a right to left paragraph. Scan it right to
29061 end
= r1
->glyphs
[TEXT_AREA
] - 1;
29062 glyph
= end
+ r1
->used
[TEXT_AREA
];
29064 /* Skip truncation glyphs at the start of the glyph row. */
29065 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
29067 && NILP (glyph
->object
)
29068 && glyph
->charpos
< 0;
29072 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
29073 or DISP_STRING, and the first glyph from buffer whose
29074 position is between START_CHARPOS and END_CHARPOS. */
29076 && !NILP (glyph
->object
)
29077 && !EQ (glyph
->object
, disp_string
)
29078 && !(BUFFERP (glyph
->object
)
29079 && (glyph
->charpos
>= start_charpos
29080 && glyph
->charpos
< end_charpos
));
29083 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29084 are present at buffer positions between START_CHARPOS and
29085 END_CHARPOS, or if they come from an overlay. */
29086 if (EQ (glyph
->object
, before_string
))
29088 pos
= string_buffer_position (before_string
, start_charpos
);
29089 /* If pos == 0, it means before_string came from an
29090 overlay, not from a buffer position. */
29091 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29094 else if (EQ (glyph
->object
, after_string
))
29096 pos
= string_buffer_position (after_string
, end_charpos
);
29097 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29102 glyph
++; /* first glyph to the right of the highlighted area */
29103 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
29104 x
+= g
->pixel_width
;
29105 hlinfo
->mouse_face_beg_x
= x
;
29106 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
29109 /* If the highlight ends in a different row, compute GLYPH and END
29110 for the end row. Otherwise, reuse the values computed above for
29111 the row where the highlight begins. */
29114 if (!r2
->reversed_p
)
29116 glyph
= r2
->glyphs
[TEXT_AREA
];
29117 end
= glyph
+ r2
->used
[TEXT_AREA
];
29122 end
= r2
->glyphs
[TEXT_AREA
] - 1;
29123 glyph
= end
+ r2
->used
[TEXT_AREA
];
29127 if (!r2
->reversed_p
)
29129 /* Skip truncation and continuation glyphs near the end of the
29130 row, and also blanks and stretch glyphs inserted by
29131 extend_face_to_end_of_line. */
29133 && NILP ((end
- 1)->object
))
29135 /* Scan the rest of the glyph row from the end, looking for the
29136 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
29137 DISP_STRING, or whose position is between START_CHARPOS
29141 && !NILP (end
->object
)
29142 && !EQ (end
->object
, disp_string
)
29143 && !(BUFFERP (end
->object
)
29144 && (end
->charpos
>= start_charpos
29145 && end
->charpos
< end_charpos
));
29148 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29149 are present at buffer positions between START_CHARPOS and
29150 END_CHARPOS, or if they come from an overlay. */
29151 if (EQ (end
->object
, before_string
))
29153 pos
= string_buffer_position (before_string
, start_charpos
);
29154 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29157 else if (EQ (end
->object
, after_string
))
29159 pos
= string_buffer_position (after_string
, end_charpos
);
29160 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29164 /* Find the X coordinate of the last glyph to be highlighted. */
29165 for (; glyph
<= end
; ++glyph
)
29166 x
+= glyph
->pixel_width
;
29168 hlinfo
->mouse_face_end_x
= x
;
29169 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
29173 /* Skip truncation and continuation glyphs near the end of the
29174 row, and also blanks and stretch glyphs inserted by
29175 extend_face_to_end_of_line. */
29179 && NILP (end
->object
))
29181 x
+= end
->pixel_width
;
29184 /* Scan the rest of the glyph row from the end, looking for the
29185 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
29186 DISP_STRING, or whose position is between START_CHARPOS
29190 && !NILP (end
->object
)
29191 && !EQ (end
->object
, disp_string
)
29192 && !(BUFFERP (end
->object
)
29193 && (end
->charpos
>= start_charpos
29194 && end
->charpos
< end_charpos
));
29197 /* BEFORE_STRING or AFTER_STRING are only relevant if they
29198 are present at buffer positions between START_CHARPOS and
29199 END_CHARPOS, or if they come from an overlay. */
29200 if (EQ (end
->object
, before_string
))
29202 pos
= string_buffer_position (before_string
, start_charpos
);
29203 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29206 else if (EQ (end
->object
, after_string
))
29208 pos
= string_buffer_position (after_string
, end_charpos
);
29209 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
29212 x
+= end
->pixel_width
;
29214 /* If we exited the above loop because we arrived at the last
29215 glyph of the row, and its buffer position is still not in
29216 range, it means the last character in range is the preceding
29217 newline. Bump the end column and x values to get past the
29220 && BUFFERP (end
->object
)
29221 && (end
->charpos
< start_charpos
29222 || end
->charpos
>= end_charpos
))
29224 x
+= end
->pixel_width
;
29227 hlinfo
->mouse_face_end_x
= x
;
29228 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
29231 hlinfo
->mouse_face_window
= window
;
29232 hlinfo
->mouse_face_face_id
29233 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
29235 !hlinfo
->mouse_face_hidden
, -1);
29236 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29239 /* The following function is not used anymore (replaced with
29240 mouse_face_from_string_pos), but I leave it here for the time
29241 being, in case someone would. */
29243 #if false /* not used */
29245 /* Find the position of the glyph for position POS in OBJECT in
29246 window W's current matrix, and return in *X, *Y the pixel
29247 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
29249 RIGHT_P means return the position of the right edge of the glyph.
29250 !RIGHT_P means return the left edge position.
29252 If no glyph for POS exists in the matrix, return the position of
29253 the glyph with the next smaller position that is in the matrix, if
29254 RIGHT_P is false. If RIGHT_P, and no glyph for POS
29255 exists in the matrix, return the position of the glyph with the
29256 next larger position in OBJECT.
29258 Value is true if a glyph was found. */
29261 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
29262 int *hpos
, int *vpos
, int *x
, int *y
, bool right_p
)
29264 int yb
= window_text_bottom_y (w
);
29265 struct glyph_row
*r
;
29266 struct glyph
*best_glyph
= NULL
;
29267 struct glyph_row
*best_row
= NULL
;
29270 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29271 r
->enabled_p
&& r
->y
< yb
;
29274 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
29275 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
29278 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
29279 if (EQ (g
->object
, object
))
29281 if (g
->charpos
== pos
)
29288 else if (best_glyph
== NULL
29289 || ((eabs (g
->charpos
- pos
)
29290 < eabs (best_glyph
->charpos
- pos
))
29293 : g
->charpos
> pos
)))
29307 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
29311 *x
+= best_glyph
->pixel_width
;
29316 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
29319 return best_glyph
!= NULL
;
29321 #endif /* not used */
29323 /* Find the positions of the first and the last glyphs in window W's
29324 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
29325 (assumed to be a string), and return in HLINFO's mouse_face_*
29326 members the pixel and column/row coordinates of those glyphs. */
29329 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
29330 Lisp_Object object
,
29331 ptrdiff_t startpos
, ptrdiff_t endpos
)
29333 int yb
= window_text_bottom_y (w
);
29334 struct glyph_row
*r
;
29335 struct glyph
*g
, *e
;
29337 bool found
= false;
29339 /* Find the glyph row with at least one position in the range
29340 [STARTPOS..ENDPOS), and the first glyph in that row whose
29341 position belongs to that range. */
29342 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
29343 r
->enabled_p
&& r
->y
< yb
;
29346 if (!r
->reversed_p
)
29348 g
= r
->glyphs
[TEXT_AREA
];
29349 e
= g
+ r
->used
[TEXT_AREA
];
29350 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
29351 if (EQ (g
->object
, object
)
29352 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
29354 hlinfo
->mouse_face_beg_row
29355 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29356 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
29357 hlinfo
->mouse_face_beg_x
= gx
;
29366 e
= r
->glyphs
[TEXT_AREA
];
29367 g
= e
+ r
->used
[TEXT_AREA
];
29368 for ( ; g
> e
; --g
)
29369 if (EQ ((g
-1)->object
, object
)
29370 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
29372 hlinfo
->mouse_face_beg_row
29373 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29374 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
29375 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
29376 gx
+= g1
->pixel_width
;
29377 hlinfo
->mouse_face_beg_x
= gx
;
29389 /* Starting with the next row, look for the first row which does NOT
29390 include any glyphs whose positions are in the range. */
29391 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
29393 g
= r
->glyphs
[TEXT_AREA
];
29394 e
= g
+ r
->used
[TEXT_AREA
];
29396 for ( ; g
< e
; ++g
)
29397 if (EQ (g
->object
, object
)
29398 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
29407 /* The highlighted region ends on the previous row. */
29410 /* Set the end row. */
29411 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
29413 /* Compute and set the end column and the end column's horizontal
29414 pixel coordinate. */
29415 if (!r
->reversed_p
)
29417 g
= r
->glyphs
[TEXT_AREA
];
29418 e
= g
+ r
->used
[TEXT_AREA
];
29419 for ( ; e
> g
; --e
)
29420 if (EQ ((e
-1)->object
, object
)
29421 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
29423 hlinfo
->mouse_face_end_col
= e
- g
;
29425 for (gx
= r
->x
; g
< e
; ++g
)
29426 gx
+= g
->pixel_width
;
29427 hlinfo
->mouse_face_end_x
= gx
;
29431 e
= r
->glyphs
[TEXT_AREA
];
29432 g
= e
+ r
->used
[TEXT_AREA
];
29433 for (gx
= r
->x
; e
< g
; ++e
)
29435 if (EQ (e
->object
, object
)
29436 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
29438 gx
+= e
->pixel_width
;
29440 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
29441 hlinfo
->mouse_face_end_x
= gx
;
29445 #ifdef HAVE_WINDOW_SYSTEM
29447 /* See if position X, Y is within a hot-spot of an image. */
29450 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
29452 if (!CONSP (hot_spot
))
29455 if (EQ (XCAR (hot_spot
), Qrect
))
29457 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
29458 Lisp_Object rect
= XCDR (hot_spot
);
29462 if (!CONSP (XCAR (rect
)))
29464 if (!CONSP (XCDR (rect
)))
29466 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
29468 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
29470 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
29472 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
29476 else if (EQ (XCAR (hot_spot
), Qcircle
))
29478 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
29479 Lisp_Object circ
= XCDR (hot_spot
);
29480 Lisp_Object lr
, lx0
, ly0
;
29482 && CONSP (XCAR (circ
))
29483 && (lr
= XCDR (circ
), NUMBERP (lr
))
29484 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
29485 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
29487 double r
= XFLOATINT (lr
);
29488 double dx
= XINT (lx0
) - x
;
29489 double dy
= XINT (ly0
) - y
;
29490 return (dx
* dx
+ dy
* dy
<= r
* r
);
29493 else if (EQ (XCAR (hot_spot
), Qpoly
))
29495 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
29496 if (VECTORP (XCDR (hot_spot
)))
29498 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
29499 Lisp_Object
*poly
= v
->contents
;
29500 ptrdiff_t n
= v
->header
.size
;
29502 bool inside
= false;
29503 Lisp_Object lx
, ly
;
29506 /* Need an even number of coordinates, and at least 3 edges. */
29507 if (n
< 6 || n
& 1)
29510 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
29511 If count is odd, we are inside polygon. Pixels on edges
29512 may or may not be included depending on actual geometry of the
29514 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
29515 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
29517 x0
= XINT (lx
), y0
= XINT (ly
);
29518 for (i
= 0; i
< n
; i
+= 2)
29520 int x1
= x0
, y1
= y0
;
29521 if ((lx
= poly
[i
], !INTEGERP (lx
))
29522 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
29524 x0
= XINT (lx
), y0
= XINT (ly
);
29526 /* Does this segment cross the X line? */
29534 if (y
> y0
&& y
> y1
)
29536 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
29546 find_hot_spot (Lisp_Object map
, int x
, int y
)
29548 while (CONSP (map
))
29550 if (CONSP (XCAR (map
))
29551 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
29559 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
29561 doc
: /* Lookup in image map MAP coordinates X and Y.
29562 An image map is an alist where each element has the format (AREA ID PLIST).
29563 An AREA is specified as either a rectangle, a circle, or a polygon:
29564 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
29565 pixel coordinates of the upper left and bottom right corners.
29566 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
29567 and the radius of the circle; r may be a float or integer.
29568 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
29569 vector describes one corner in the polygon.
29570 Returns the alist element for the first matching AREA in MAP. */)
29571 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
29579 return find_hot_spot (map
,
29580 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
29581 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
29585 /* Display frame CURSOR, optionally using shape defined by POINTER. */
29587 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
29589 /* Do not change cursor shape while dragging mouse. */
29590 if (EQ (do_mouse_tracking
, Qdragging
))
29593 if (!NILP (pointer
))
29595 if (EQ (pointer
, Qarrow
))
29596 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29597 else if (EQ (pointer
, Qhand
))
29598 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
29599 else if (EQ (pointer
, Qtext
))
29600 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
29601 else if (EQ (pointer
, intern ("hdrag")))
29602 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29603 else if (EQ (pointer
, intern ("nhdrag")))
29604 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
29605 #ifdef HAVE_X_WINDOWS
29606 else if (EQ (pointer
, intern ("vdrag")))
29607 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29609 else if (EQ (pointer
, intern ("hourglass")))
29610 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
29611 else if (EQ (pointer
, Qmodeline
))
29612 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
29614 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29617 if (cursor
!= No_Cursor
)
29618 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
29621 #endif /* HAVE_WINDOW_SYSTEM */
29623 /* Take proper action when mouse has moved to the mode or header line
29624 or marginal area AREA of window W, x-position X and y-position Y.
29625 X is relative to the start of the text display area of W, so the
29626 width of bitmap areas and scroll bars must be subtracted to get a
29627 position relative to the start of the mode line. */
29630 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
29631 enum window_part area
)
29633 struct window
*w
= XWINDOW (window
);
29634 struct frame
*f
= XFRAME (w
->frame
);
29635 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29636 #ifdef HAVE_WINDOW_SYSTEM
29637 Display_Info
*dpyinfo
;
29639 Cursor cursor
= No_Cursor
;
29640 Lisp_Object pointer
= Qnil
;
29641 int dx
, dy
, width
, height
;
29643 Lisp_Object string
, object
= Qnil
;
29644 Lisp_Object pos
IF_LINT (= Qnil
), help
;
29646 Lisp_Object mouse_face
;
29647 int original_x_pixel
= x
;
29648 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
29649 struct glyph_row
*row
IF_LINT (= 0);
29651 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
29656 /* Kludge alert: mode_line_string takes X/Y in pixels, but
29657 returns them in row/column units! */
29658 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
29659 &object
, &dx
, &dy
, &width
, &height
);
29661 row
= (area
== ON_MODE_LINE
29662 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
29663 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
29665 /* Find the glyph under the mouse pointer. */
29666 if (row
->mode_line_p
&& row
->enabled_p
)
29668 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
29669 end
= glyph
+ row
->used
[TEXT_AREA
];
29671 for (x0
= original_x_pixel
;
29672 glyph
< end
&& x0
>= glyph
->pixel_width
;
29674 x0
-= glyph
->pixel_width
;
29682 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
29683 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
29684 returns them in row/column units! */
29685 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
29686 &object
, &dx
, &dy
, &width
, &height
);
29691 #ifdef HAVE_WINDOW_SYSTEM
29692 if (IMAGEP (object
))
29694 Lisp_Object image_map
, hotspot
;
29695 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
29697 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
29699 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
29703 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
29704 If so, we could look for mouse-enter, mouse-leave
29705 properties in PLIST (and do something...). */
29706 hotspot
= XCDR (hotspot
);
29707 if (CONSP (hotspot
)
29708 && (plist
= XCAR (hotspot
), CONSP (plist
)))
29710 pointer
= Fplist_get (plist
, Qpointer
);
29711 if (NILP (pointer
))
29713 help
= Fplist_get (plist
, Qhelp_echo
);
29716 help_echo_string
= help
;
29717 XSETWINDOW (help_echo_window
, w
);
29718 help_echo_object
= w
->contents
;
29719 help_echo_pos
= charpos
;
29723 if (NILP (pointer
))
29724 pointer
= Fplist_get (XCDR (object
), QCpointer
);
29726 #endif /* HAVE_WINDOW_SYSTEM */
29728 if (STRINGP (string
))
29729 pos
= make_number (charpos
);
29731 /* Set the help text and mouse pointer. If the mouse is on a part
29732 of the mode line without any text (e.g. past the right edge of
29733 the mode line text), use the default help text and pointer. */
29734 if (STRINGP (string
) || area
== ON_MODE_LINE
)
29736 /* Arrange to display the help by setting the global variables
29737 help_echo_string, help_echo_object, and help_echo_pos. */
29740 if (STRINGP (string
))
29741 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
29745 help_echo_string
= help
;
29746 XSETWINDOW (help_echo_window
, w
);
29747 help_echo_object
= string
;
29748 help_echo_pos
= charpos
;
29750 else if (area
== ON_MODE_LINE
)
29752 Lisp_Object default_help
29753 = buffer_local_value (Qmode_line_default_help_echo
,
29756 if (STRINGP (default_help
))
29758 help_echo_string
= default_help
;
29759 XSETWINDOW (help_echo_window
, w
);
29760 help_echo_object
= Qnil
;
29761 help_echo_pos
= -1;
29766 #ifdef HAVE_WINDOW_SYSTEM
29767 /* Change the mouse pointer according to what is under it. */
29768 if (FRAME_WINDOW_P (f
))
29770 bool draggable
= (! WINDOW_BOTTOMMOST_P (w
)
29772 || NILP (Vresize_mini_windows
));
29774 dpyinfo
= FRAME_DISPLAY_INFO (f
);
29775 if (STRINGP (string
))
29777 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29779 if (NILP (pointer
))
29780 pointer
= Fget_text_property (pos
, Qpointer
, string
);
29782 /* Change the mouse pointer according to what is under X/Y. */
29784 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
29787 map
= Fget_text_property (pos
, Qlocal_map
, string
);
29788 if (!KEYMAPP (map
))
29789 map
= Fget_text_property (pos
, Qkeymap
, string
);
29790 if (!KEYMAPP (map
) && draggable
)
29791 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
29794 else if (draggable
)
29795 /* Default mode-line pointer. */
29796 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29801 /* Change the mouse face according to what is under X/Y. */
29802 bool mouse_face_shown
= false;
29803 if (STRINGP (string
))
29805 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
29806 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
29807 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
29812 struct glyph
* tmp_glyph
;
29816 int total_pixel_width
;
29817 ptrdiff_t begpos
, endpos
, ignore
;
29821 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
29822 Qmouse_face
, string
, Qnil
);
29828 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
29830 endpos
= SCHARS (string
);
29834 /* Calculate the glyph position GPOS of GLYPH in the
29835 displayed string, relative to the beginning of the
29836 highlighted part of the string.
29838 Note: GPOS is different from CHARPOS. CHARPOS is the
29839 position of GLYPH in the internal string object. A mode
29840 line string format has structures which are converted to
29841 a flattened string by the Emacs Lisp interpreter. The
29842 internal string is an element of those structures. The
29843 displayed string is the flattened string. */
29844 tmp_glyph
= row_start_glyph
;
29845 while (tmp_glyph
< glyph
29846 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29847 && begpos
<= tmp_glyph
->charpos
29848 && tmp_glyph
->charpos
< endpos
)))
29850 gpos
= glyph
- tmp_glyph
;
29852 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
29853 the highlighted part of the displayed string to which
29854 GLYPH belongs. Note: GSEQ_LENGTH is different from
29855 SCHARS (STRING), because the latter returns the length of
29856 the internal string. */
29857 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
29859 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29860 && begpos
<= tmp_glyph
->charpos
29861 && tmp_glyph
->charpos
< endpos
));
29864 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
29866 /* Calculate the total pixel width of all the glyphs between
29867 the beginning of the highlighted area and GLYPH. */
29868 total_pixel_width
= 0;
29869 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
29870 total_pixel_width
+= tmp_glyph
->pixel_width
;
29872 /* Pre calculation of re-rendering position. Note: X is in
29873 column units here, after the call to mode_line_string or
29874 marginal_area_string. */
29876 vpos
= (area
== ON_MODE_LINE
29877 ? (w
->current_matrix
)->nrows
- 1
29880 /* If GLYPH's position is included in the region that is
29881 already drawn in mouse face, we have nothing to do. */
29882 if ( EQ (window
, hlinfo
->mouse_face_window
)
29883 && (!row
->reversed_p
29884 ? (hlinfo
->mouse_face_beg_col
<= hpos
29885 && hpos
< hlinfo
->mouse_face_end_col
)
29886 /* In R2L rows we swap BEG and END, see below. */
29887 : (hlinfo
->mouse_face_end_col
<= hpos
29888 && hpos
< hlinfo
->mouse_face_beg_col
))
29889 && hlinfo
->mouse_face_beg_row
== vpos
)
29892 if (clear_mouse_face (hlinfo
))
29893 cursor
= No_Cursor
;
29895 if (!row
->reversed_p
)
29897 hlinfo
->mouse_face_beg_col
= hpos
;
29898 hlinfo
->mouse_face_beg_x
= original_x_pixel
29899 - (total_pixel_width
+ dx
);
29900 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
29901 hlinfo
->mouse_face_end_x
= 0;
29905 /* In R2L rows, show_mouse_face expects BEG and END
29906 coordinates to be swapped. */
29907 hlinfo
->mouse_face_end_col
= hpos
;
29908 hlinfo
->mouse_face_end_x
= original_x_pixel
29909 - (total_pixel_width
+ dx
);
29910 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
29911 hlinfo
->mouse_face_beg_x
= 0;
29914 hlinfo
->mouse_face_beg_row
= vpos
;
29915 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
29916 hlinfo
->mouse_face_past_end
= false;
29917 hlinfo
->mouse_face_window
= window
;
29919 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
29924 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29925 mouse_face_shown
= true;
29927 if (NILP (pointer
))
29932 /* If mouse-face doesn't need to be shown, clear any existing
29934 if ((area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
) && !mouse_face_shown
)
29935 clear_mouse_face (hlinfo
);
29937 #ifdef HAVE_WINDOW_SYSTEM
29938 if (FRAME_WINDOW_P (f
))
29939 define_frame_cursor1 (f
, cursor
, pointer
);
29945 Take proper action when the mouse has moved to position X, Y on
29946 frame F with regards to highlighting portions of display that have
29947 mouse-face properties. Also de-highlight portions of display where
29948 the mouse was before, set the mouse pointer shape as appropriate
29949 for the mouse coordinates, and activate help echo (tooltips).
29950 X and Y can be negative or out of range. */
29953 note_mouse_highlight (struct frame
*f
, int x
, int y
)
29955 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29956 enum window_part part
= ON_NOTHING
;
29957 Lisp_Object window
;
29959 Cursor cursor
= No_Cursor
;
29960 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
29963 /* When a menu is active, don't highlight because this looks odd. */
29964 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
29965 if (popup_activated ())
29969 if (!f
->glyphs_initialized_p
29970 || f
->pointer_invisible
)
29973 hlinfo
->mouse_face_mouse_x
= x
;
29974 hlinfo
->mouse_face_mouse_y
= y
;
29975 hlinfo
->mouse_face_mouse_frame
= f
;
29977 if (hlinfo
->mouse_face_defer
)
29980 /* Which window is that in? */
29981 window
= window_from_coordinates (f
, x
, y
, &part
, true);
29983 /* If displaying active text in another window, clear that. */
29984 if (! EQ (window
, hlinfo
->mouse_face_window
)
29985 /* Also clear if we move out of text area in same window. */
29986 || (!NILP (hlinfo
->mouse_face_window
)
29989 && part
!= ON_MODE_LINE
29990 && part
!= ON_HEADER_LINE
))
29991 clear_mouse_face (hlinfo
);
29993 /* Not on a window -> return. */
29994 if (!WINDOWP (window
))
29997 /* Reset help_echo_string. It will get recomputed below. */
29998 help_echo_string
= Qnil
;
30000 /* Convert to window-relative pixel coordinates. */
30001 w
= XWINDOW (window
);
30002 frame_to_window_pixel_xy (w
, &x
, &y
);
30004 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
30005 /* Handle tool-bar window differently since it doesn't display a
30007 if (EQ (window
, f
->tool_bar_window
))
30009 note_tool_bar_highlight (f
, x
, y
);
30014 /* Mouse is on the mode, header line or margin? */
30015 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
30016 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
30018 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
30020 #ifdef HAVE_WINDOW_SYSTEM
30021 if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
30023 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30024 /* Show non-text cursor (Bug#16647). */
30032 #ifdef HAVE_WINDOW_SYSTEM
30033 if (part
== ON_VERTICAL_BORDER
)
30035 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
30036 help_echo_string
= build_string ("drag-mouse-1: resize");
30038 else if (part
== ON_RIGHT_DIVIDER
)
30040 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
30041 help_echo_string
= build_string ("drag-mouse-1: resize");
30043 else if (part
== ON_BOTTOM_DIVIDER
)
30044 if (! WINDOW_BOTTOMMOST_P (w
)
30046 || NILP (Vresize_mini_windows
))
30048 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
30049 help_echo_string
= build_string ("drag-mouse-1: resize");
30052 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30053 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
30054 || part
== ON_VERTICAL_SCROLL_BAR
30055 || part
== ON_HORIZONTAL_SCROLL_BAR
)
30056 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30058 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
30061 /* Are we in a window whose display is up to date?
30062 And verify the buffer's text has not changed. */
30063 b
= XBUFFER (w
->contents
);
30064 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
30066 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
30068 struct glyph
*glyph
;
30069 Lisp_Object object
;
30070 Lisp_Object mouse_face
= Qnil
, position
;
30071 Lisp_Object
*overlay_vec
= NULL
;
30072 ptrdiff_t i
, noverlays
;
30073 struct buffer
*obuf
;
30074 ptrdiff_t obegv
, ozv
;
30077 /* Find the glyph under X/Y. */
30078 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
30080 #ifdef HAVE_WINDOW_SYSTEM
30081 /* Look for :pointer property on image. */
30082 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
30084 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
30085 if (img
!= NULL
&& IMAGEP (img
->spec
))
30087 Lisp_Object image_map
, hotspot
;
30088 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
30090 && (hotspot
= find_hot_spot (image_map
,
30091 glyph
->slice
.img
.x
+ dx
,
30092 glyph
->slice
.img
.y
+ dy
),
30094 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
30098 /* Could check XCAR (hotspot) to see if we enter/leave
30100 If so, we could look for mouse-enter, mouse-leave
30101 properties in PLIST (and do something...). */
30102 hotspot
= XCDR (hotspot
);
30103 if (CONSP (hotspot
)
30104 && (plist
= XCAR (hotspot
), CONSP (plist
)))
30106 pointer
= Fplist_get (plist
, Qpointer
);
30107 if (NILP (pointer
))
30109 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
30110 if (!NILP (help_echo_string
))
30112 help_echo_window
= window
;
30113 help_echo_object
= glyph
->object
;
30114 help_echo_pos
= glyph
->charpos
;
30118 if (NILP (pointer
))
30119 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
30122 #endif /* HAVE_WINDOW_SYSTEM */
30124 /* Clear mouse face if X/Y not over text. */
30126 || area
!= TEXT_AREA
30127 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
30128 /* Glyph's OBJECT is nil for glyphs inserted by the
30129 display engine for its internal purposes, like truncation
30130 and continuation glyphs and blanks beyond the end of
30131 line's text on text terminals. If we are over such a
30132 glyph, we are not over any text. */
30133 || NILP (glyph
->object
)
30134 /* R2L rows have a stretch glyph at their front, which
30135 stands for no text, whereas L2R rows have no glyphs at
30136 all beyond the end of text. Treat such stretch glyphs
30137 like we do with NULL glyphs in L2R rows. */
30138 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
30139 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
30140 && glyph
->type
== STRETCH_GLYPH
30141 && glyph
->avoid_cursor_p
))
30143 if (clear_mouse_face (hlinfo
))
30144 cursor
= No_Cursor
;
30145 #ifdef HAVE_WINDOW_SYSTEM
30146 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
30148 if (area
!= TEXT_AREA
)
30149 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
30151 pointer
= Vvoid_text_area_pointer
;
30157 pos
= glyph
->charpos
;
30158 object
= glyph
->object
;
30159 if (!STRINGP (object
) && !BUFFERP (object
))
30162 /* If we get an out-of-range value, return now; avoid an error. */
30163 if (BUFFERP (object
) && pos
> BUF_Z (b
))
30166 /* Make the window's buffer temporarily current for
30167 overlays_at and compute_char_face. */
30168 obuf
= current_buffer
;
30169 current_buffer
= b
;
30175 /* Is this char mouse-active or does it have help-echo? */
30176 position
= make_number (pos
);
30180 if (BUFFERP (object
))
30182 /* Put all the overlays we want in a vector in overlay_vec. */
30183 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, false);
30184 /* Sort overlays into increasing priority order. */
30185 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
30190 if (NILP (Vmouse_highlight
))
30192 clear_mouse_face (hlinfo
);
30193 goto check_help_echo
;
30196 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
30199 cursor
= No_Cursor
;
30201 /* Check mouse-face highlighting. */
30203 /* If there exists an overlay with mouse-face overlapping
30204 the one we are currently highlighting, we have to
30205 check if we enter the overlapping overlay, and then
30206 highlight only that. */
30207 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
30208 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
30210 /* Find the highest priority overlay with a mouse-face. */
30211 Lisp_Object overlay
= Qnil
;
30212 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
30214 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
30215 if (!NILP (mouse_face
))
30216 overlay
= overlay_vec
[i
];
30219 /* If we're highlighting the same overlay as before, there's
30220 no need to do that again. */
30221 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
30222 goto check_help_echo
;
30223 hlinfo
->mouse_face_overlay
= overlay
;
30225 /* Clear the display of the old active region, if any. */
30226 if (clear_mouse_face (hlinfo
))
30227 cursor
= No_Cursor
;
30229 /* If no overlay applies, get a text property. */
30230 if (NILP (overlay
))
30231 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
30233 /* Next, compute the bounds of the mouse highlighting and
30235 if (!NILP (mouse_face
) && STRINGP (object
))
30237 /* The mouse-highlighting comes from a display string
30238 with a mouse-face. */
30242 s
= Fprevious_single_property_change
30243 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
30244 e
= Fnext_single_property_change
30245 (position
, Qmouse_face
, object
, Qnil
);
30247 s
= make_number (0);
30249 e
= make_number (SCHARS (object
));
30250 mouse_face_from_string_pos (w
, hlinfo
, object
,
30251 XINT (s
), XINT (e
));
30252 hlinfo
->mouse_face_past_end
= false;
30253 hlinfo
->mouse_face_window
= window
;
30254 hlinfo
->mouse_face_face_id
30255 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
30256 glyph
->face_id
, true);
30257 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
30258 cursor
= No_Cursor
;
30262 /* The mouse-highlighting, if any, comes from an overlay
30263 or text property in the buffer. */
30264 Lisp_Object buffer
IF_LINT (= Qnil
);
30265 Lisp_Object disp_string
IF_LINT (= Qnil
);
30267 if (STRINGP (object
))
30269 /* If we are on a display string with no mouse-face,
30270 check if the text under it has one. */
30271 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
30272 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30273 pos
= string_buffer_position (object
, start
);
30276 mouse_face
= get_char_property_and_overlay
30277 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
30278 buffer
= w
->contents
;
30279 disp_string
= object
;
30285 disp_string
= Qnil
;
30288 if (!NILP (mouse_face
))
30290 Lisp_Object before
, after
;
30291 Lisp_Object before_string
, after_string
;
30292 /* To correctly find the limits of mouse highlight
30293 in a bidi-reordered buffer, we must not use the
30294 optimization of limiting the search in
30295 previous-single-property-change and
30296 next-single-property-change, because
30297 rows_from_pos_range needs the real start and end
30298 positions to DTRT in this case. That's because
30299 the first row visible in a window does not
30300 necessarily display the character whose position
30301 is the smallest. */
30303 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
30304 ? Fmarker_position (w
->start
)
30307 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
30308 ? make_number (BUF_Z (XBUFFER (buffer
))
30309 - w
->window_end_pos
)
30312 if (NILP (overlay
))
30314 /* Handle the text property case. */
30315 before
= Fprevious_single_property_change
30316 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
30317 after
= Fnext_single_property_change
30318 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
30319 before_string
= after_string
= Qnil
;
30323 /* Handle the overlay case. */
30324 before
= Foverlay_start (overlay
);
30325 after
= Foverlay_end (overlay
);
30326 before_string
= Foverlay_get (overlay
, Qbefore_string
);
30327 after_string
= Foverlay_get (overlay
, Qafter_string
);
30329 if (!STRINGP (before_string
)) before_string
= Qnil
;
30330 if (!STRINGP (after_string
)) after_string
= Qnil
;
30333 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
30336 : XFASTINT (before
),
30338 ? BUF_Z (XBUFFER (buffer
))
30339 : XFASTINT (after
),
30340 before_string
, after_string
,
30342 cursor
= No_Cursor
;
30349 /* Look for a `help-echo' property. */
30350 if (NILP (help_echo_string
)) {
30351 Lisp_Object help
, overlay
;
30353 /* Check overlays first. */
30354 help
= overlay
= Qnil
;
30355 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
30357 overlay
= overlay_vec
[i
];
30358 help
= Foverlay_get (overlay
, Qhelp_echo
);
30363 help_echo_string
= help
;
30364 help_echo_window
= window
;
30365 help_echo_object
= overlay
;
30366 help_echo_pos
= pos
;
30370 Lisp_Object obj
= glyph
->object
;
30371 ptrdiff_t charpos
= glyph
->charpos
;
30373 /* Try text properties. */
30376 && charpos
< SCHARS (obj
))
30378 help
= Fget_text_property (make_number (charpos
),
30382 /* If the string itself doesn't specify a help-echo,
30383 see if the buffer text ``under'' it does. */
30384 struct glyph_row
*r
30385 = MATRIX_ROW (w
->current_matrix
, vpos
);
30386 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30387 ptrdiff_t p
= string_buffer_position (obj
, start
);
30390 help
= Fget_char_property (make_number (p
),
30391 Qhelp_echo
, w
->contents
);
30400 else if (BUFFERP (obj
)
30403 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
30408 help_echo_string
= help
;
30409 help_echo_window
= window
;
30410 help_echo_object
= obj
;
30411 help_echo_pos
= charpos
;
30416 #ifdef HAVE_WINDOW_SYSTEM
30417 /* Look for a `pointer' property. */
30418 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
30420 /* Check overlays first. */
30421 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
30422 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
30424 if (NILP (pointer
))
30426 Lisp_Object obj
= glyph
->object
;
30427 ptrdiff_t charpos
= glyph
->charpos
;
30429 /* Try text properties. */
30432 && charpos
< SCHARS (obj
))
30434 pointer
= Fget_text_property (make_number (charpos
),
30436 if (NILP (pointer
))
30438 /* If the string itself doesn't specify a pointer,
30439 see if the buffer text ``under'' it does. */
30440 struct glyph_row
*r
30441 = MATRIX_ROW (w
->current_matrix
, vpos
);
30442 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
30443 ptrdiff_t p
= string_buffer_position (obj
, start
);
30445 pointer
= Fget_char_property (make_number (p
),
30446 Qpointer
, w
->contents
);
30449 else if (BUFFERP (obj
)
30452 pointer
= Fget_text_property (make_number (charpos
),
30456 #endif /* HAVE_WINDOW_SYSTEM */
30460 current_buffer
= obuf
;
30466 #ifdef HAVE_WINDOW_SYSTEM
30467 if (FRAME_WINDOW_P (f
))
30468 define_frame_cursor1 (f
, cursor
, pointer
);
30470 /* This is here to prevent a compiler error, about "label at end of
30471 compound statement". */
30478 Clear any mouse-face on window W. This function is part of the
30479 redisplay interface, and is called from try_window_id and similar
30480 functions to ensure the mouse-highlight is off. */
30483 x_clear_window_mouse_face (struct window
*w
)
30485 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
30486 Lisp_Object window
;
30489 XSETWINDOW (window
, w
);
30490 if (EQ (window
, hlinfo
->mouse_face_window
))
30491 clear_mouse_face (hlinfo
);
30497 Just discard the mouse face information for frame F, if any.
30498 This is used when the size of F is changed. */
30501 cancel_mouse_face (struct frame
*f
)
30503 Lisp_Object window
;
30504 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
30506 window
= hlinfo
->mouse_face_window
;
30507 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
30508 reset_mouse_highlight (hlinfo
);
30513 /***********************************************************************
30515 ***********************************************************************/
30517 #ifdef HAVE_WINDOW_SYSTEM
30519 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
30520 which intersects rectangle R. R is in window-relative coordinates. */
30523 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
30524 enum glyph_row_area area
)
30526 struct glyph
*first
= row
->glyphs
[area
];
30527 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
30528 struct glyph
*last
;
30529 int first_x
, start_x
, x
;
30531 if (area
== TEXT_AREA
&& row
->fill_line_p
)
30532 /* If row extends face to end of line write the whole line. */
30533 draw_glyphs (w
, 0, row
, area
,
30534 0, row
->used
[area
],
30535 DRAW_NORMAL_TEXT
, 0);
30538 /* Set START_X to the window-relative start position for drawing glyphs of
30539 AREA. The first glyph of the text area can be partially visible.
30540 The first glyphs of other areas cannot. */
30541 start_x
= window_box_left_offset (w
, area
);
30543 if (area
== TEXT_AREA
)
30546 /* Find the first glyph that must be redrawn. */
30548 && x
+ first
->pixel_width
< r
->x
)
30550 x
+= first
->pixel_width
;
30554 /* Find the last one. */
30557 /* Use a signed int intermediate value to avoid catastrophic
30558 failures due to comparison between signed and unsigned, when
30559 x is negative (can happen for wide images that are hscrolled). */
30560 int r_end
= r
->x
+ r
->width
;
30561 while (last
< end
&& x
< r_end
)
30563 x
+= last
->pixel_width
;
30569 draw_glyphs (w
, first_x
- start_x
, row
, area
,
30570 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
30571 DRAW_NORMAL_TEXT
, 0);
30576 /* Redraw the parts of the glyph row ROW on window W intersecting
30577 rectangle R. R is in window-relative coordinates. Value is
30578 true if mouse-face was overwritten. */
30581 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
30583 eassert (row
->enabled_p
);
30585 if (row
->mode_line_p
|| w
->pseudo_window_p
)
30586 draw_glyphs (w
, 0, row
, TEXT_AREA
,
30587 0, row
->used
[TEXT_AREA
],
30588 DRAW_NORMAL_TEXT
, 0);
30591 if (row
->used
[LEFT_MARGIN_AREA
])
30592 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
30593 if (row
->used
[TEXT_AREA
])
30594 expose_area (w
, row
, r
, TEXT_AREA
);
30595 if (row
->used
[RIGHT_MARGIN_AREA
])
30596 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
30597 draw_row_fringe_bitmaps (w
, row
);
30600 return row
->mouse_face_p
;
30604 /* Redraw those parts of glyphs rows during expose event handling that
30605 overlap other rows. Redrawing of an exposed line writes over parts
30606 of lines overlapping that exposed line; this function fixes that.
30608 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
30609 row in W's current matrix that is exposed and overlaps other rows.
30610 LAST_OVERLAPPING_ROW is the last such row. */
30613 expose_overlaps (struct window
*w
,
30614 struct glyph_row
*first_overlapping_row
,
30615 struct glyph_row
*last_overlapping_row
,
30618 struct glyph_row
*row
;
30620 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
30621 if (row
->overlapping_p
)
30623 eassert (row
->enabled_p
&& !row
->mode_line_p
);
30626 if (row
->used
[LEFT_MARGIN_AREA
])
30627 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
30629 if (row
->used
[TEXT_AREA
])
30630 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
30632 if (row
->used
[RIGHT_MARGIN_AREA
])
30633 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
30639 /* Return true if W's cursor intersects rectangle R. */
30642 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
30644 XRectangle cr
, result
;
30645 struct glyph
*cursor_glyph
;
30646 struct glyph_row
*row
;
30648 if (w
->phys_cursor
.vpos
>= 0
30649 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
30650 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
30652 && row
->cursor_in_fringe_p
)
30654 /* Cursor is in the fringe. */
30655 cr
.x
= window_box_right_offset (w
,
30656 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
30657 ? RIGHT_MARGIN_AREA
30660 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
30661 cr
.height
= row
->height
;
30662 return x_intersect_rectangles (&cr
, r
, &result
);
30665 cursor_glyph
= get_phys_cursor_glyph (w
);
30668 /* r is relative to W's box, but w->phys_cursor.x is relative
30669 to left edge of W's TEXT area. Adjust it. */
30670 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
30671 cr
.y
= w
->phys_cursor
.y
;
30672 cr
.width
= cursor_glyph
->pixel_width
;
30673 cr
.height
= w
->phys_cursor_height
;
30674 /* ++KFS: W32 version used W32-specific IntersectRect here, but
30675 I assume the effect is the same -- and this is portable. */
30676 return x_intersect_rectangles (&cr
, r
, &result
);
30678 /* If we don't understand the format, pretend we're not in the hot-spot. */
30684 Draw a vertical window border to the right of window W if W doesn't
30685 have vertical scroll bars. */
30688 x_draw_vertical_border (struct window
*w
)
30690 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30692 /* We could do better, if we knew what type of scroll-bar the adjacent
30693 windows (on either side) have... But we don't :-(
30694 However, I think this works ok. ++KFS 2003-04-25 */
30696 /* Redraw borders between horizontally adjacent windows. Don't
30697 do it for frames with vertical scroll bars because either the
30698 right scroll bar of a window, or the left scroll bar of its
30699 neighbor will suffice as a border. */
30700 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
30703 /* Note: It is necessary to redraw both the left and the right
30704 borders, for when only this single window W is being
30706 if (!WINDOW_RIGHTMOST_P (w
)
30707 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
30709 int x0
, x1
, y0
, y1
;
30711 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30714 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30717 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
30720 if (!WINDOW_LEFTMOST_P (w
)
30721 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
30723 int x0
, x1
, y0
, y1
;
30725 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30728 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30731 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
30736 /* Draw window dividers for window W. */
30739 x_draw_right_divider (struct window
*w
)
30741 struct frame
*f
= WINDOW_XFRAME (w
);
30743 if (w
->mini
|| w
->pseudo_window_p
)
30745 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30747 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
30748 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30749 int y0
= WINDOW_TOP_EDGE_Y (w
);
30750 /* The bottom divider prevails. */
30751 int y1
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30753 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30758 x_draw_bottom_divider (struct window
*w
)
30760 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30762 if (w
->mini
|| w
->pseudo_window_p
)
30764 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30766 int x0
= WINDOW_LEFT_EDGE_X (w
);
30767 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30768 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30769 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
30771 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30775 /* Redraw the part of window W intersection rectangle FR. Pixel
30776 coordinates in FR are frame-relative. Call this function with
30777 input blocked. Value is true if the exposure overwrites
30781 expose_window (struct window
*w
, XRectangle
*fr
)
30783 struct frame
*f
= XFRAME (w
->frame
);
30785 bool mouse_face_overwritten_p
= false;
30787 /* If window is not yet fully initialized, do nothing. This can
30788 happen when toolkit scroll bars are used and a window is split.
30789 Reconfiguring the scroll bar will generate an expose for a newly
30791 if (w
->current_matrix
== NULL
)
30794 /* When we're currently updating the window, display and current
30795 matrix usually don't agree. Arrange for a thorough display
30797 if (w
->must_be_updated_p
)
30799 SET_FRAME_GARBAGED (f
);
30803 /* Frame-relative pixel rectangle of W. */
30804 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
30805 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
30806 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
30807 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
30809 if (x_intersect_rectangles (fr
, &wr
, &r
))
30811 int yb
= window_text_bottom_y (w
);
30812 struct glyph_row
*row
;
30813 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
30815 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
30816 r
.x
, r
.y
, r
.width
, r
.height
));
30818 /* Convert to window coordinates. */
30819 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
30820 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
30822 /* Turn off the cursor. */
30823 bool cursor_cleared_p
= (!w
->pseudo_window_p
30824 && phys_cursor_in_rect_p (w
, &r
));
30825 if (cursor_cleared_p
)
30826 x_clear_cursor (w
);
30828 /* If the row containing the cursor extends face to end of line,
30829 then expose_area might overwrite the cursor outside the
30830 rectangle and thus notice_overwritten_cursor might clear
30831 w->phys_cursor_on_p. We remember the original value and
30832 check later if it is changed. */
30833 bool phys_cursor_on_p
= w
->phys_cursor_on_p
;
30835 /* Use a signed int intermediate value to avoid catastrophic
30836 failures due to comparison between signed and unsigned, when
30837 y0 or y1 is negative (can happen for tall images). */
30838 int r_bottom
= r
.y
+ r
.height
;
30840 /* Update lines intersecting rectangle R. */
30841 first_overlapping_row
= last_overlapping_row
= NULL
;
30842 for (row
= w
->current_matrix
->rows
;
30847 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
30849 if ((y0
>= r
.y
&& y0
< r_bottom
)
30850 || (y1
> r
.y
&& y1
< r_bottom
)
30851 || (r
.y
>= y0
&& r
.y
< y1
)
30852 || (r_bottom
> y0
&& r_bottom
< y1
))
30854 /* A header line may be overlapping, but there is no need
30855 to fix overlapping areas for them. KFS 2005-02-12 */
30856 if (row
->overlapping_p
&& !row
->mode_line_p
)
30858 if (first_overlapping_row
== NULL
)
30859 first_overlapping_row
= row
;
30860 last_overlapping_row
= row
;
30864 if (expose_line (w
, row
, &r
))
30865 mouse_face_overwritten_p
= true;
30868 else if (row
->overlapping_p
)
30870 /* We must redraw a row overlapping the exposed area. */
30872 ? y0
+ row
->phys_height
> r
.y
30873 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
30875 if (first_overlapping_row
== NULL
)
30876 first_overlapping_row
= row
;
30877 last_overlapping_row
= row
;
30885 /* Display the mode line if there is one. */
30886 if (WINDOW_WANTS_MODELINE_P (w
)
30887 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
30889 && row
->y
< r_bottom
)
30891 if (expose_line (w
, row
, &r
))
30892 mouse_face_overwritten_p
= true;
30895 if (!w
->pseudo_window_p
)
30897 /* Fix the display of overlapping rows. */
30898 if (first_overlapping_row
)
30899 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
30902 /* Draw border between windows. */
30903 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30904 x_draw_right_divider (w
);
30906 x_draw_vertical_border (w
);
30908 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30909 x_draw_bottom_divider (w
);
30911 /* Turn the cursor on again. */
30912 if (cursor_cleared_p
30913 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
30914 update_window_cursor (w
, true);
30918 return mouse_face_overwritten_p
;
30923 /* Redraw (parts) of all windows in the window tree rooted at W that
30924 intersect R. R contains frame pixel coordinates. Value is
30925 true if the exposure overwrites mouse-face. */
30928 expose_window_tree (struct window
*w
, XRectangle
*r
)
30930 struct frame
*f
= XFRAME (w
->frame
);
30931 bool mouse_face_overwritten_p
= false;
30933 while (w
&& !FRAME_GARBAGED_P (f
))
30935 mouse_face_overwritten_p
30936 |= (WINDOWP (w
->contents
)
30937 ? expose_window_tree (XWINDOW (w
->contents
), r
)
30938 : expose_window (w
, r
));
30940 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
30943 return mouse_face_overwritten_p
;
30948 Redisplay an exposed area of frame F. X and Y are the upper-left
30949 corner of the exposed rectangle. W and H are width and height of
30950 the exposed area. All are pixel values. W or H zero means redraw
30951 the entire frame. */
30954 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
30957 bool mouse_face_overwritten_p
= false;
30959 TRACE ((stderr
, "expose_frame "));
30961 /* No need to redraw if frame will be redrawn soon. */
30962 if (FRAME_GARBAGED_P (f
))
30964 TRACE ((stderr
, " garbaged\n"));
30968 /* If basic faces haven't been realized yet, there is no point in
30969 trying to redraw anything. This can happen when we get an expose
30970 event while Emacs is starting, e.g. by moving another window. */
30971 if (FRAME_FACE_CACHE (f
) == NULL
30972 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
30974 TRACE ((stderr
, " no faces\n"));
30978 if (w
== 0 || h
== 0)
30981 r
.width
= FRAME_TEXT_WIDTH (f
);
30982 r
.height
= FRAME_TEXT_HEIGHT (f
);
30992 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
30993 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
30995 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
30996 if (WINDOWP (f
->tool_bar_window
))
30997 mouse_face_overwritten_p
30998 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
31001 #ifdef HAVE_X_WINDOWS
31003 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
31004 if (WINDOWP (f
->menu_bar_window
))
31005 mouse_face_overwritten_p
31006 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
31007 #endif /* not USE_X_TOOLKIT and not USE_GTK */
31011 /* Some window managers support a focus-follows-mouse style with
31012 delayed raising of frames. Imagine a partially obscured frame,
31013 and moving the mouse into partially obscured mouse-face on that
31014 frame. The visible part of the mouse-face will be highlighted,
31015 then the WM raises the obscured frame. With at least one WM, KDE
31016 2.1, Emacs is not getting any event for the raising of the frame
31017 (even tried with SubstructureRedirectMask), only Expose events.
31018 These expose events will draw text normally, i.e. not
31019 highlighted. Which means we must redo the highlight here.
31020 Subsume it under ``we love X''. --gerd 2001-08-15 */
31021 /* Included in Windows version because Windows most likely does not
31022 do the right thing if any third party tool offers
31023 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
31024 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
31026 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
31027 if (f
== hlinfo
->mouse_face_mouse_frame
)
31029 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
31030 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
31031 clear_mouse_face (hlinfo
);
31032 note_mouse_highlight (f
, mouse_x
, mouse_y
);
31039 Determine the intersection of two rectangles R1 and R2. Return
31040 the intersection in *RESULT. Value is true if RESULT is not
31044 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
31046 XRectangle
*left
, *right
;
31047 XRectangle
*upper
, *lower
;
31048 bool intersection_p
= false;
31050 /* Rearrange so that R1 is the left-most rectangle. */
31052 left
= r1
, right
= r2
;
31054 left
= r2
, right
= r1
;
31056 /* X0 of the intersection is right.x0, if this is inside R1,
31057 otherwise there is no intersection. */
31058 if (right
->x
<= left
->x
+ left
->width
)
31060 result
->x
= right
->x
;
31062 /* The right end of the intersection is the minimum of
31063 the right ends of left and right. */
31064 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
31067 /* Same game for Y. */
31069 upper
= r1
, lower
= r2
;
31071 upper
= r2
, lower
= r1
;
31073 /* The upper end of the intersection is lower.y0, if this is inside
31074 of upper. Otherwise, there is no intersection. */
31075 if (lower
->y
<= upper
->y
+ upper
->height
)
31077 result
->y
= lower
->y
;
31079 /* The lower end of the intersection is the minimum of the lower
31080 ends of upper and lower. */
31081 result
->height
= (min (lower
->y
+ lower
->height
,
31082 upper
->y
+ upper
->height
)
31084 intersection_p
= true;
31088 return intersection_p
;
31091 #endif /* HAVE_WINDOW_SYSTEM */
31094 /***********************************************************************
31096 ***********************************************************************/
31099 syms_of_xdisp (void)
31101 Vwith_echo_area_save_vector
= Qnil
;
31102 staticpro (&Vwith_echo_area_save_vector
);
31104 Vmessage_stack
= Qnil
;
31105 staticpro (&Vmessage_stack
);
31107 /* Non-nil means don't actually do any redisplay. */
31108 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
31110 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
31112 DEFVAR_BOOL("inhibit-message", inhibit_message
,
31113 doc
: /* Non-nil means calls to `message' are not displayed.
31114 They are still logged to the *Messages* buffer. */);
31115 inhibit_message
= 0;
31117 message_dolog_marker1
= Fmake_marker ();
31118 staticpro (&message_dolog_marker1
);
31119 message_dolog_marker2
= Fmake_marker ();
31120 staticpro (&message_dolog_marker2
);
31121 message_dolog_marker3
= Fmake_marker ();
31122 staticpro (&message_dolog_marker3
);
31125 defsubr (&Sdump_frame_glyph_matrix
);
31126 defsubr (&Sdump_glyph_matrix
);
31127 defsubr (&Sdump_glyph_row
);
31128 defsubr (&Sdump_tool_bar_row
);
31129 defsubr (&Strace_redisplay
);
31130 defsubr (&Strace_to_stderr
);
31132 #ifdef HAVE_WINDOW_SYSTEM
31133 defsubr (&Stool_bar_height
);
31134 defsubr (&Slookup_image_map
);
31136 defsubr (&Sline_pixel_height
);
31137 defsubr (&Sformat_mode_line
);
31138 defsubr (&Sinvisible_p
);
31139 defsubr (&Scurrent_bidi_paragraph_direction
);
31140 defsubr (&Swindow_text_pixel_size
);
31141 defsubr (&Smove_point_visually
);
31142 defsubr (&Sbidi_find_overridden_directionality
);
31144 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
31145 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
31146 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
31147 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
31148 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
31149 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
31150 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
31151 DEFSYM (Qeval
, "eval");
31152 DEFSYM (QCdata
, ":data");
31154 /* Names of text properties relevant for redisplay. */
31155 DEFSYM (Qdisplay
, "display");
31156 DEFSYM (Qspace_width
, "space-width");
31157 DEFSYM (Qraise
, "raise");
31158 DEFSYM (Qslice
, "slice");
31159 DEFSYM (Qspace
, "space");
31160 DEFSYM (Qmargin
, "margin");
31161 DEFSYM (Qpointer
, "pointer");
31162 DEFSYM (Qleft_margin
, "left-margin");
31163 DEFSYM (Qright_margin
, "right-margin");
31164 DEFSYM (Qcenter
, "center");
31165 DEFSYM (Qline_height
, "line-height");
31166 DEFSYM (QCalign_to
, ":align-to");
31167 DEFSYM (QCrelative_width
, ":relative-width");
31168 DEFSYM (QCrelative_height
, ":relative-height");
31169 DEFSYM (QCeval
, ":eval");
31170 DEFSYM (QCpropertize
, ":propertize");
31171 DEFSYM (QCfile
, ":file");
31172 DEFSYM (Qfontified
, "fontified");
31173 DEFSYM (Qfontification_functions
, "fontification-functions");
31175 /* Name of the face used to highlight trailing whitespace. */
31176 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
31178 /* Name and number of the face used to highlight escape glyphs. */
31179 DEFSYM (Qescape_glyph
, "escape-glyph");
31181 /* Name and number of the face used to highlight non-breaking spaces. */
31182 DEFSYM (Qnobreak_space
, "nobreak-space");
31184 /* The symbol 'image' which is the car of the lists used to represent
31185 images in Lisp. Also a tool bar style. */
31186 DEFSYM (Qimage
, "image");
31188 /* Tool bar styles. */
31189 DEFSYM (Qtext
, "text");
31190 DEFSYM (Qboth
, "both");
31191 DEFSYM (Qboth_horiz
, "both-horiz");
31192 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
31194 /* The image map types. */
31195 DEFSYM (QCmap
, ":map");
31196 DEFSYM (QCpointer
, ":pointer");
31197 DEFSYM (Qrect
, "rect");
31198 DEFSYM (Qcircle
, "circle");
31199 DEFSYM (Qpoly
, "poly");
31201 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
31203 DEFSYM (Qgrow_only
, "grow-only");
31204 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
31205 DEFSYM (Qposition
, "position");
31206 DEFSYM (Qbuffer_position
, "buffer-position");
31207 DEFSYM (Qobject
, "object");
31209 /* Cursor shapes. */
31210 DEFSYM (Qbar
, "bar");
31211 DEFSYM (Qhbar
, "hbar");
31212 DEFSYM (Qbox
, "box");
31213 DEFSYM (Qhollow
, "hollow");
31215 /* Pointer shapes. */
31216 DEFSYM (Qhand
, "hand");
31217 DEFSYM (Qarrow
, "arrow");
31220 DEFSYM (Qdragging
, "dragging");
31222 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
31224 list_of_error
= list1 (list2 (Qerror
, Qvoid_variable
));
31225 staticpro (&list_of_error
);
31227 /* Values of those variables at last redisplay are stored as
31228 properties on 'overlay-arrow-position' symbol. However, if
31229 Voverlay_arrow_position is a marker, last-arrow-position is its
31230 numerical position. */
31231 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
31232 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
31234 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
31235 properties on a symbol in overlay-arrow-variable-list. */
31236 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
31237 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
31239 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
31240 staticpro (&echo_buffer
[0]);
31241 staticpro (&echo_buffer
[1]);
31243 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
31244 staticpro (&echo_area_buffer
[0]);
31245 staticpro (&echo_area_buffer
[1]);
31247 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
31248 staticpro (&Vmessages_buffer_name
);
31250 mode_line_proptrans_alist
= Qnil
;
31251 staticpro (&mode_line_proptrans_alist
);
31252 mode_line_string_list
= Qnil
;
31253 staticpro (&mode_line_string_list
);
31254 mode_line_string_face
= Qnil
;
31255 staticpro (&mode_line_string_face
);
31256 mode_line_string_face_prop
= Qnil
;
31257 staticpro (&mode_line_string_face_prop
);
31258 Vmode_line_unwind_vector
= Qnil
;
31259 staticpro (&Vmode_line_unwind_vector
);
31261 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
31263 help_echo_string
= Qnil
;
31264 staticpro (&help_echo_string
);
31265 help_echo_object
= Qnil
;
31266 staticpro (&help_echo_object
);
31267 help_echo_window
= Qnil
;
31268 staticpro (&help_echo_window
);
31269 previous_help_echo_string
= Qnil
;
31270 staticpro (&previous_help_echo_string
);
31271 help_echo_pos
= -1;
31273 DEFSYM (Qright_to_left
, "right-to-left");
31274 DEFSYM (Qleft_to_right
, "left-to-right");
31275 defsubr (&Sbidi_resolved_levels
);
31277 #ifdef HAVE_WINDOW_SYSTEM
31278 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
31279 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
31280 For example, if a block cursor is over a tab, it will be drawn as
31281 wide as that tab on the display. */);
31282 x_stretch_cursor_p
= 0;
31285 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
31286 doc
: /* Non-nil means highlight trailing whitespace.
31287 The face used for trailing whitespace is `trailing-whitespace'. */);
31288 Vshow_trailing_whitespace
= Qnil
;
31290 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
31291 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
31292 If the value is t, Emacs highlights non-ASCII chars which have the
31293 same appearance as an ASCII space or hyphen, using the `nobreak-space'
31294 or `escape-glyph' face respectively.
31296 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
31297 U+2011 (non-breaking hyphen) are affected.
31299 Any other non-nil value means to display these characters as a escape
31300 glyph followed by an ordinary space or hyphen.
31302 A value of nil means no special handling of these characters. */);
31303 Vnobreak_char_display
= Qt
;
31305 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
31306 doc
: /* The pointer shape to show in void text areas.
31307 A value of nil means to show the text pointer. Other options are
31308 `arrow', `text', `hand', `vdrag', `hdrag', `nhdrag', `modeline', and
31310 Vvoid_text_area_pointer
= Qarrow
;
31312 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
31313 doc
: /* Non-nil means don't actually do any redisplay.
31314 This is used for internal purposes. */);
31315 Vinhibit_redisplay
= Qnil
;
31317 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
31318 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
31319 Vglobal_mode_string
= Qnil
;
31321 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
31322 doc
: /* Marker for where to display an arrow on top of the buffer text.
31323 This must be the beginning of a line in order to work.
31324 See also `overlay-arrow-string'. */);
31325 Voverlay_arrow_position
= Qnil
;
31327 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
31328 doc
: /* String to display as an arrow in non-window frames.
31329 See also `overlay-arrow-position'. */);
31330 Voverlay_arrow_string
= build_pure_c_string ("=>");
31332 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
31333 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
31334 The symbols on this list are examined during redisplay to determine
31335 where to display overlay arrows. */);
31336 Voverlay_arrow_variable_list
31337 = list1 (intern_c_string ("overlay-arrow-position"));
31339 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
31340 doc
: /* The number of lines to try scrolling a window by when point moves out.
31341 If that fails to bring point back on frame, point is centered instead.
31342 If this is zero, point is always centered after it moves off frame.
31343 If you want scrolling to always be a line at a time, you should set
31344 `scroll-conservatively' to a large value rather than set this to 1. */);
31346 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
31347 doc
: /* Scroll up to this many lines, to bring point back on screen.
31348 If point moves off-screen, redisplay will scroll by up to
31349 `scroll-conservatively' lines in order to bring point just barely
31350 onto the screen again. If that cannot be done, then redisplay
31351 recenters point as usual.
31353 If the value is greater than 100, redisplay will never recenter point,
31354 but will always scroll just enough text to bring point into view, even
31355 if you move far away.
31357 A value of zero means always recenter point if it moves off screen. */);
31358 scroll_conservatively
= 0;
31360 DEFVAR_INT ("scroll-margin", scroll_margin
,
31361 doc
: /* Number of lines of margin at the top and bottom of a window.
31362 Recenter the window whenever point gets within this many lines
31363 of the top or bottom of the window. */);
31366 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
31367 doc
: /* Pixels per inch value for non-window system displays.
31368 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
31369 Vdisplay_pixels_per_inch
= make_float (72.0);
31372 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
31375 DEFVAR_LISP ("truncate-partial-width-windows",
31376 Vtruncate_partial_width_windows
,
31377 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
31378 For an integer value, truncate lines in each window narrower than the
31379 full frame width, provided the window width is less than that integer;
31380 otherwise, respect the value of `truncate-lines'.
31382 For any other non-nil value, truncate lines in all windows that do
31383 not span the full frame width.
31385 A value of nil means to respect the value of `truncate-lines'.
31387 If `word-wrap' is enabled, you might want to reduce this. */);
31388 Vtruncate_partial_width_windows
= make_number (50);
31390 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
31391 doc
: /* Maximum buffer size for which line number should be displayed.
31392 If the buffer is bigger than this, the line number does not appear
31393 in the mode line. A value of nil means no limit. */);
31394 Vline_number_display_limit
= Qnil
;
31396 DEFVAR_INT ("line-number-display-limit-width",
31397 line_number_display_limit_width
,
31398 doc
: /* Maximum line width (in characters) for line number display.
31399 If the average length of the lines near point is bigger than this, then the
31400 line number may be omitted from the mode line. */);
31401 line_number_display_limit_width
= 200;
31403 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
31404 doc
: /* Non-nil means highlight region even in nonselected windows. */);
31405 highlight_nonselected_windows
= false;
31407 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
31408 doc
: /* Non-nil if more than one frame is visible on this display.
31409 Minibuffer-only frames don't count, but iconified frames do.
31410 This variable is not guaranteed to be accurate except while processing
31411 `frame-title-format' and `icon-title-format'. */);
31413 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
31414 doc
: /* Template for displaying the title bar of visible frames.
31415 (Assuming the window manager supports this feature.)
31417 This variable has the same structure as `mode-line-format', except that
31418 the %c and %l constructs are ignored. It is used only on frames for
31419 which no explicit name has been set (see `modify-frame-parameters'). */);
31421 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
31422 doc
: /* Template for displaying the title bar of an iconified frame.
31423 (Assuming the window manager supports this feature.)
31424 This variable has the same structure as `mode-line-format' (which see),
31425 and is used only on frames for which no explicit name has been set
31426 (see `modify-frame-parameters'). */);
31428 = Vframe_title_format
31429 = listn (CONSTYPE_PURE
, 3,
31430 intern_c_string ("multiple-frames"),
31431 build_pure_c_string ("%b"),
31432 listn (CONSTYPE_PURE
, 4,
31433 empty_unibyte_string
,
31434 intern_c_string ("invocation-name"),
31435 build_pure_c_string ("@"),
31436 intern_c_string ("system-name")));
31438 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
31439 doc
: /* Maximum number of lines to keep in the message log buffer.
31440 If nil, disable message logging. If t, log messages but don't truncate
31441 the buffer when it becomes large. */);
31442 Vmessage_log_max
= make_number (1000);
31444 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
31445 doc
: /* Functions called during redisplay, if window sizes have changed.
31446 The value should be a list of functions that take one argument.
31447 During the first part of redisplay, for each frame, if any of its windows
31448 have changed size since the last redisplay, or have been split or deleted,
31449 all the functions in the list are called, with the frame as argument.
31450 If redisplay decides to resize the minibuffer window, it calls these
31451 functions on behalf of that as well. */);
31452 Vwindow_size_change_functions
= Qnil
;
31454 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
31455 doc
: /* List of functions to call before redisplaying a window with scrolling.
31456 Each function is called with two arguments, the window and its new
31457 display-start position.
31458 These functions are called whenever the `window-start' marker is modified,
31459 either to point into another buffer (e.g. via `set-window-buffer') or another
31460 place in the same buffer.
31461 Note that the value of `window-end' is not valid when these functions are
31464 Warning: Do not use this feature to alter the way the window
31465 is scrolled. It is not designed for that, and such use probably won't
31467 Vwindow_scroll_functions
= Qnil
;
31469 DEFVAR_LISP ("window-text-change-functions",
31470 Vwindow_text_change_functions
,
31471 doc
: /* Functions to call in redisplay when text in the window might change. */);
31472 Vwindow_text_change_functions
= Qnil
;
31474 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
31475 doc
: /* Functions called when redisplay of a window reaches the end trigger.
31476 Each function is called with two arguments, the window and the end trigger value.
31477 See `set-window-redisplay-end-trigger'. */);
31478 Vredisplay_end_trigger_functions
= Qnil
;
31480 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
31481 doc
: /* Non-nil means autoselect window with mouse pointer.
31482 If nil, do not autoselect windows.
31483 A positive number means delay autoselection by that many seconds: a
31484 window is autoselected only after the mouse has remained in that
31485 window for the duration of the delay.
31486 A negative number has a similar effect, but causes windows to be
31487 autoselected only after the mouse has stopped moving. (Because of
31488 the way Emacs compares mouse events, you will occasionally wait twice
31489 that time before the window gets selected.)
31490 Any other value means to autoselect window instantaneously when the
31491 mouse pointer enters it.
31493 Autoselection selects the minibuffer only if it is active, and never
31494 unselects the minibuffer if it is active.
31496 When customizing this variable make sure that the actual value of
31497 `focus-follows-mouse' matches the behavior of your window manager. */);
31498 Vmouse_autoselect_window
= Qnil
;
31500 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
31501 doc
: /* Non-nil means automatically resize tool-bars.
31502 This dynamically changes the tool-bar's height to the minimum height
31503 that is needed to make all tool-bar items visible.
31504 If value is `grow-only', the tool-bar's height is only increased
31505 automatically; to decrease the tool-bar height, use \\[recenter]. */);
31506 Vauto_resize_tool_bars
= Qt
;
31508 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
31509 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
31510 auto_raise_tool_bar_buttons_p
= true;
31512 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
31513 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
31514 make_cursor_line_fully_visible_p
= true;
31516 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
31517 doc
: /* Border below tool-bar in pixels.
31518 If an integer, use it as the height of the border.
31519 If it is one of `internal-border-width' or `border-width', use the
31520 value of the corresponding frame parameter.
31521 Otherwise, no border is added below the tool-bar. */);
31522 Vtool_bar_border
= Qinternal_border_width
;
31524 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
31525 doc
: /* Margin around tool-bar buttons in pixels.
31526 If an integer, use that for both horizontal and vertical margins.
31527 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
31528 HORZ specifying the horizontal margin, and VERT specifying the
31529 vertical margin. */);
31530 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
31532 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
31533 doc
: /* Relief thickness of tool-bar buttons. */);
31534 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
31536 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
31537 doc
: /* Tool bar style to use.
31539 image - show images only
31540 text - show text only
31541 both - show both, text below image
31542 both-horiz - show text to the right of the image
31543 text-image-horiz - show text to the left of the image
31544 any other - use system default or image if no system default.
31546 This variable only affects the GTK+ toolkit version of Emacs. */);
31547 Vtool_bar_style
= Qnil
;
31549 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
31550 doc
: /* Maximum number of characters a label can have to be shown.
31551 The tool bar style must also show labels for this to have any effect, see
31552 `tool-bar-style'. */);
31553 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
31555 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
31556 doc
: /* List of functions to call to fontify regions of text.
31557 Each function is called with one argument POS. Functions must
31558 fontify a region starting at POS in the current buffer, and give
31559 fontified regions the property `fontified'. */);
31560 Vfontification_functions
= Qnil
;
31561 Fmake_variable_buffer_local (Qfontification_functions
);
31563 DEFVAR_BOOL ("unibyte-display-via-language-environment",
31564 unibyte_display_via_language_environment
,
31565 doc
: /* Non-nil means display unibyte text according to language environment.
31566 Specifically, this means that raw bytes in the range 160-255 decimal
31567 are displayed by converting them to the equivalent multibyte characters
31568 according to the current language environment. As a result, they are
31569 displayed according to the current fontset.
31571 Note that this variable affects only how these bytes are displayed,
31572 but does not change the fact they are interpreted as raw bytes. */);
31573 unibyte_display_via_language_environment
= false;
31575 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
31576 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
31577 If a float, it specifies a fraction of the mini-window frame's height.
31578 If an integer, it specifies a number of lines. */);
31579 Vmax_mini_window_height
= make_float (0.25);
31581 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
31582 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
31583 A value of nil means don't automatically resize mini-windows.
31584 A value of t means resize them to fit the text displayed in them.
31585 A value of `grow-only', the default, means let mini-windows grow only;
31586 they return to their normal size when the minibuffer is closed, or the
31587 echo area becomes empty. */);
31588 Vresize_mini_windows
= Qgrow_only
;
31590 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
31591 doc
: /* Alist specifying how to blink the cursor off.
31592 Each element has the form (ON-STATE . OFF-STATE). Whenever the
31593 `cursor-type' frame-parameter or variable equals ON-STATE,
31594 comparing using `equal', Emacs uses OFF-STATE to specify
31595 how to blink it off. ON-STATE and OFF-STATE are values for
31596 the `cursor-type' frame parameter.
31598 If a frame's ON-STATE has no entry in this list,
31599 the frame's other specifications determine how to blink the cursor off. */);
31600 Vblink_cursor_alist
= Qnil
;
31602 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
31603 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
31604 If non-nil, windows are automatically scrolled horizontally to make
31605 point visible. */);
31606 automatic_hscrolling_p
= true;
31607 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
31609 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
31610 doc
: /* How many columns away from the window edge point is allowed to get
31611 before automatic hscrolling will horizontally scroll the window. */);
31612 hscroll_margin
= 5;
31614 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
31615 doc
: /* How many columns to scroll the window when point gets too close to the edge.
31616 When point is less than `hscroll-margin' columns from the window
31617 edge, automatic hscrolling will scroll the window by the amount of columns
31618 determined by this variable. If its value is a positive integer, scroll that
31619 many columns. If it's a positive floating-point number, it specifies the
31620 fraction of the window's width to scroll. If it's nil or zero, point will be
31621 centered horizontally after the scroll. Any other value, including negative
31622 numbers, are treated as if the value were zero.
31624 Automatic hscrolling always moves point outside the scroll margin, so if
31625 point was more than scroll step columns inside the margin, the window will
31626 scroll more than the value given by the scroll step.
31628 Note that the lower bound for automatic hscrolling specified by `scroll-left'
31629 and `scroll-right' overrides this variable's effect. */);
31630 Vhscroll_step
= make_number (0);
31632 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
31633 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
31634 Bind this around calls to `message' to let it take effect. */);
31635 message_truncate_lines
= false;
31637 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
31638 doc
: /* Normal hook run to update the menu bar definitions.
31639 Redisplay runs this hook before it redisplays the menu bar.
31640 This is used to update menus such as Buffers, whose contents depend on
31642 Vmenu_bar_update_hook
= Qnil
;
31644 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
31645 doc
: /* Frame for which we are updating a menu.
31646 The enable predicate for a menu binding should check this variable. */);
31647 Vmenu_updating_frame
= Qnil
;
31649 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
31650 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
31651 inhibit_menubar_update
= false;
31653 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
31654 doc
: /* Prefix prepended to all continuation lines at display time.
31655 The value may be a string, an image, or a stretch-glyph; it is
31656 interpreted in the same way as the value of a `display' text property.
31658 This variable is overridden by any `wrap-prefix' text or overlay
31661 To add a prefix to non-continuation lines, use `line-prefix'. */);
31662 Vwrap_prefix
= Qnil
;
31663 DEFSYM (Qwrap_prefix
, "wrap-prefix");
31664 Fmake_variable_buffer_local (Qwrap_prefix
);
31666 DEFVAR_LISP ("line-prefix", Vline_prefix
,
31667 doc
: /* Prefix prepended to all non-continuation lines at display time.
31668 The value may be a string, an image, or a stretch-glyph; it is
31669 interpreted in the same way as the value of a `display' text property.
31671 This variable is overridden by any `line-prefix' text or overlay
31674 To add a prefix to continuation lines, use `wrap-prefix'. */);
31675 Vline_prefix
= Qnil
;
31676 DEFSYM (Qline_prefix
, "line-prefix");
31677 Fmake_variable_buffer_local (Qline_prefix
);
31679 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
31680 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
31681 inhibit_eval_during_redisplay
= false;
31683 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
31684 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
31685 inhibit_free_realized_faces
= false;
31687 DEFVAR_BOOL ("inhibit-bidi-mirroring", inhibit_bidi_mirroring
,
31688 doc
: /* Non-nil means don't mirror characters even when bidi context requires that.
31689 Intended for use during debugging and for testing bidi display;
31690 see biditest.el in the test suite. */);
31691 inhibit_bidi_mirroring
= false;
31694 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
31695 doc
: /* Inhibit try_window_id display optimization. */);
31696 inhibit_try_window_id
= false;
31698 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
31699 doc
: /* Inhibit try_window_reusing display optimization. */);
31700 inhibit_try_window_reusing
= false;
31702 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
31703 doc
: /* Inhibit try_cursor_movement display optimization. */);
31704 inhibit_try_cursor_movement
= false;
31705 #endif /* GLYPH_DEBUG */
31707 DEFVAR_INT ("overline-margin", overline_margin
,
31708 doc
: /* Space between overline and text, in pixels.
31709 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
31710 margin to the character height. */);
31711 overline_margin
= 2;
31713 DEFVAR_INT ("underline-minimum-offset",
31714 underline_minimum_offset
,
31715 doc
: /* Minimum distance between baseline and underline.
31716 This can improve legibility of underlined text at small font sizes,
31717 particularly when using variable `x-use-underline-position-properties'
31718 with fonts that specify an UNDERLINE_POSITION relatively close to the
31719 baseline. The default value is 1. */);
31720 underline_minimum_offset
= 1;
31722 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
31723 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
31724 This feature only works when on a window system that can change
31725 cursor shapes. */);
31726 display_hourglass_p
= true;
31728 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
31729 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
31730 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
31732 #ifdef HAVE_WINDOW_SYSTEM
31733 hourglass_atimer
= NULL
;
31734 hourglass_shown_p
= false;
31735 #endif /* HAVE_WINDOW_SYSTEM */
31737 /* Name of the face used to display glyphless characters. */
31738 DEFSYM (Qglyphless_char
, "glyphless-char");
31740 /* Method symbols for Vglyphless_char_display. */
31741 DEFSYM (Qhex_code
, "hex-code");
31742 DEFSYM (Qempty_box
, "empty-box");
31743 DEFSYM (Qthin_space
, "thin-space");
31744 DEFSYM (Qzero_width
, "zero-width");
31746 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
31747 doc
: /* Function run just before redisplay.
31748 It is called with one argument, which is the set of windows that are to
31749 be redisplayed. This set can be nil (meaning, only the selected window),
31750 or t (meaning all windows). */);
31751 Vpre_redisplay_function
= intern ("ignore");
31753 /* Symbol for the purpose of Vglyphless_char_display. */
31754 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
31755 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
31757 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
31758 doc
: /* Char-table defining glyphless characters.
31759 Each element, if non-nil, should be one of the following:
31760 an ASCII acronym string: display this string in a box
31761 `hex-code': display the hexadecimal code of a character in a box
31762 `empty-box': display as an empty box
31763 `thin-space': display as 1-pixel width space
31764 `zero-width': don't display
31765 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
31766 display method for graphical terminals and text terminals respectively.
31767 GRAPHICAL and TEXT should each have one of the values listed above.
31769 The char-table has one extra slot to control the display of a character for
31770 which no font is found. This slot only takes effect on graphical terminals.
31771 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
31772 `thin-space'. The default is `empty-box'.
31774 If a character has a non-nil entry in an active display table, the
31775 display table takes effect; in this case, Emacs does not consult
31776 `glyphless-char-display' at all. */);
31777 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
31778 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
31781 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
31782 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
31783 Vdebug_on_message
= Qnil
;
31785 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
31787 Vredisplay__all_windows_cause
= Fmake_hash_table (0, NULL
);
31789 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
31791 Vredisplay__mode_lines_cause
= Fmake_hash_table (0, NULL
);
31793 DEFVAR_LISP ("redisplay--variables", Vredisplay__variables
,
31794 doc
: /* A hash-table of variables changing which triggers a thorough redisplay. */);
31795 Vredisplay__variables
= Qnil
;
31799 /* Initialize this module when Emacs starts. */
31804 CHARPOS (this_line_start_pos
) = 0;
31806 if (!noninteractive
)
31808 struct window
*m
= XWINDOW (minibuf_window
);
31809 Lisp_Object frame
= m
->frame
;
31810 struct frame
*f
= XFRAME (frame
);
31811 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
31812 struct window
*r
= XWINDOW (root
);
31815 echo_area_window
= minibuf_window
;
31817 r
->top_line
= FRAME_TOP_MARGIN (f
);
31818 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
31819 r
->total_cols
= FRAME_COLS (f
);
31820 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31821 r
->total_lines
= FRAME_TOTAL_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
31822 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
31824 m
->top_line
= FRAME_TOTAL_LINES (f
) - 1;
31825 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
31826 m
->total_cols
= FRAME_COLS (f
);
31827 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31828 m
->total_lines
= 1;
31829 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
31831 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
31832 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
31833 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
31835 /* The default ellipsis glyphs `...'. */
31836 for (i
= 0; i
< 3; ++i
)
31837 default_invis_vector
[i
] = make_number ('.');
31841 /* Allocate the buffer for frame titles.
31842 Also used for `format-mode-line'. */
31844 mode_line_noprop_buf
= xmalloc (size
);
31845 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
31846 mode_line_noprop_ptr
= mode_line_noprop_buf
;
31847 mode_line_target
= MODE_LINE_DISPLAY
;
31850 help_echo_showing_p
= false;
31853 #ifdef HAVE_WINDOW_SYSTEM
31855 /* Platform-independent portion of hourglass implementation. */
31857 /* Timer function of hourglass_atimer. */
31860 show_hourglass (struct atimer
*timer
)
31862 /* The timer implementation will cancel this timer automatically
31863 after this function has run. Set hourglass_atimer to null
31864 so that we know the timer doesn't have to be canceled. */
31865 hourglass_atimer
= NULL
;
31867 if (!hourglass_shown_p
)
31869 Lisp_Object tail
, frame
;
31873 FOR_EACH_FRAME (tail
, frame
)
31875 struct frame
*f
= XFRAME (frame
);
31877 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31878 && FRAME_RIF (f
)->show_hourglass
)
31879 FRAME_RIF (f
)->show_hourglass (f
);
31882 hourglass_shown_p
= true;
31887 /* Cancel a currently active hourglass timer, and start a new one. */
31890 start_hourglass (void)
31892 struct timespec delay
;
31894 cancel_hourglass ();
31896 if (INTEGERP (Vhourglass_delay
)
31897 && XINT (Vhourglass_delay
) > 0)
31898 delay
= make_timespec (min (XINT (Vhourglass_delay
),
31899 TYPE_MAXIMUM (time_t)),
31901 else if (FLOATP (Vhourglass_delay
)
31902 && XFLOAT_DATA (Vhourglass_delay
) > 0)
31903 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
31905 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
31907 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
31908 show_hourglass
, NULL
);
31911 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
31915 cancel_hourglass (void)
31917 if (hourglass_atimer
)
31919 cancel_atimer (hourglass_atimer
);
31920 hourglass_atimer
= NULL
;
31923 if (hourglass_shown_p
)
31925 Lisp_Object tail
, frame
;
31929 FOR_EACH_FRAME (tail
, frame
)
31931 struct frame
*f
= XFRAME (frame
);
31933 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31934 && FRAME_RIF (f
)->hide_hourglass
)
31935 FRAME_RIF (f
)->hide_hourglass (f
);
31937 /* No cursors on non GUI frames - restore to stock arrow cursor. */
31938 else if (!FRAME_W32_P (f
))
31939 w32_arrow_cursor ();
31943 hourglass_shown_p
= false;
31948 #endif /* HAVE_WINDOW_SYSTEM */