1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2015 Free Software Foundation,
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code.
36 The following diagram shows how redisplay code is invoked. As you
37 can see, Lisp calls redisplay and vice versa. Under window systems
38 like X, some portions of the redisplay code are also called
39 asynchronously during mouse movement or expose events. It is very
40 important that these code parts do NOT use the C library (malloc,
41 free) because many C libraries under Unix are not reentrant. They
42 may also NOT call functions of the Lisp interpreter which could
43 change the interpreter's state. If you don't follow these rules,
44 you will encounter bugs which are very hard to explain.
46 +--------------+ redisplay +----------------+
47 | Lisp machine |---------------->| Redisplay code |<--+
48 +--------------+ (xdisp.c) +----------------+ |
50 +----------------------------------+ |
51 Don't use this path when called |
54 expose_window (asynchronous) |
56 X expose events -----+
58 What does redisplay do? Obviously, it has to figure out somehow what
59 has been changed since the last time the display has been updated,
60 and to make these changes visible. Preferably it would do that in
61 a moderately intelligent way, i.e. fast.
63 Changes in buffer text can be deduced from window and buffer
64 structures, and from some global variables like `beg_unchanged' and
65 `end_unchanged'. The contents of the display are additionally
66 recorded in a `glyph matrix', a two-dimensional matrix of glyph
67 structures. Each row in such a matrix corresponds to a line on the
68 display, and each glyph in a row corresponds to a column displaying
69 a character, an image, or what else. This matrix is called the
70 `current glyph matrix' or `current matrix' in redisplay
73 For buffer parts that have been changed since the last update, a
74 second glyph matrix is constructed, the so called `desired glyph
75 matrix' or short `desired matrix'. Current and desired matrix are
76 then compared to find a cheap way to update the display, e.g. by
77 reusing part of the display by scrolling lines.
79 You will find a lot of redisplay optimizations when you start
80 looking at the innards of redisplay. The overall goal of all these
81 optimizations is to make redisplay fast because it is done
82 frequently. Some of these optimizations are implemented by the
87 This function tries to update the display if the text in the
88 window did not change and did not scroll, only point moved, and
89 it did not move off the displayed portion of the text.
91 . try_window_reusing_current_matrix
93 This function reuses the current matrix of a window when text
94 has not changed, but the window start changed (e.g., due to
99 This function attempts to redisplay a window by reusing parts of
100 its existing display. It finds and reuses the part that was not
101 changed, and redraws the rest. (The "id" part in the function's
102 name stands for "insert/delete", not for "identification" or
107 This function performs the full redisplay of a single window
108 assuming that its fonts were not changed and that the cursor
109 will not end up in the scroll margins. (Loading fonts requires
110 re-adjustment of dimensions of glyph matrices, which makes this
111 method impossible to use.)
113 These optimizations are tried in sequence (some can be skipped if
114 it is known that they are not applicable). If none of the
115 optimizations were successful, redisplay calls redisplay_windows,
116 which performs a full redisplay of all windows.
118 Note that there's one more important optimization up Emacs's
119 sleeve, but it is related to actually redrawing the potentially
120 changed portions of the window/frame, not to reproducing the
121 desired matrices of those potentially changed portions. Namely,
122 the function update_frame and its subroutines, which you will find
123 in dispnew.c, compare the desired matrices with the current
124 matrices, and only redraw the portions that changed. So it could
125 happen that the functions in this file for some reason decide that
126 the entire desired matrix needs to be regenerated from scratch, and
127 still only parts of the Emacs display, or even nothing at all, will
128 be actually delivered to the glass, because update_frame has found
129 that the new and the old screen contents are similar or identical.
133 Desired matrices are always built per Emacs window. The function
134 `display_line' is the central function to look at if you are
135 interested. It constructs one row in a desired matrix given an
136 iterator structure containing both a buffer position and a
137 description of the environment in which the text is to be
138 displayed. But this is too early, read on.
140 Characters and pixmaps displayed for a range of buffer text depend
141 on various settings of buffers and windows, on overlays and text
142 properties, on display tables, on selective display. The good news
143 is that all this hairy stuff is hidden behind a small set of
144 interface functions taking an iterator structure (struct it)
147 Iteration over things to be displayed is then simple. It is
148 started by initializing an iterator with a call to init_iterator,
149 passing it the buffer position where to start iteration. For
150 iteration over strings, pass -1 as the position to init_iterator,
151 and call reseat_to_string when the string is ready, to initialize
152 the iterator for that string. Thereafter, calls to
153 get_next_display_element fill the iterator structure with relevant
154 information about the next thing to display. Calls to
155 set_iterator_to_next move the iterator to the next thing.
157 Besides this, an iterator also contains information about the
158 display environment in which glyphs for display elements are to be
159 produced. It has fields for the width and height of the display,
160 the information whether long lines are truncated or continued, a
161 current X and Y position, and lots of other stuff you can better
164 Glyphs in a desired matrix are normally constructed in a loop
165 calling get_next_display_element and then PRODUCE_GLYPHS. The call
166 to PRODUCE_GLYPHS will fill the iterator structure with pixel
167 information about the element being displayed and at the same time
168 produce glyphs for it. If the display element fits on the line
169 being displayed, set_iterator_to_next is called next, otherwise the
170 glyphs produced are discarded. The function display_line is the
171 workhorse of filling glyph rows in the desired matrix with glyphs.
172 In addition to producing glyphs, it also handles line truncation
173 and continuation, word wrap, and cursor positioning (for the
174 latter, see also set_cursor_from_row).
178 That just couldn't be all, could it? What about terminal types not
179 supporting operations on sub-windows of the screen? To update the
180 display on such a terminal, window-based glyph matrices are not
181 well suited. To be able to reuse part of the display (scrolling
182 lines up and down), we must instead have a view of the whole
183 screen. This is what `frame matrices' are for. They are a trick.
185 Frames on terminals like above have a glyph pool. Windows on such
186 a frame sub-allocate their glyph memory from their frame's glyph
187 pool. The frame itself is given its own glyph matrices. By
188 coincidence---or maybe something else---rows in window glyph
189 matrices are slices of corresponding rows in frame matrices. Thus
190 writing to window matrices implicitly updates a frame matrix which
191 provides us with the view of the whole screen that we originally
192 wanted to have without having to move many bytes around. To be
193 honest, there is a little bit more done, but not much more. If you
194 plan to extend that code, take a look at dispnew.c. The function
195 build_frame_matrix is a good starting point.
197 Bidirectional display.
199 Bidirectional display adds quite some hair to this already complex
200 design. The good news are that a large portion of that hairy stuff
201 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
202 reordering engine which is called by set_iterator_to_next and
203 returns the next character to display in the visual order. See
204 commentary on bidi.c for more details. As far as redisplay is
205 concerned, the effect of calling bidi_move_to_visually_next, the
206 main interface of the reordering engine, is that the iterator gets
207 magically placed on the buffer or string position that is to be
208 displayed next. In other words, a linear iteration through the
209 buffer/string is replaced with a non-linear one. All the rest of
210 the redisplay is oblivious to the bidi reordering.
212 Well, almost oblivious---there are still complications, most of
213 them due to the fact that buffer and string positions no longer
214 change monotonously with glyph indices in a glyph row. Moreover,
215 for continued lines, the buffer positions may not even be
216 monotonously changing with vertical positions. Also, accounting
217 for face changes, overlays, etc. becomes more complex because
218 non-linear iteration could potentially skip many positions with
219 changes, and then cross them again on the way back...
221 One other prominent effect of bidirectional display is that some
222 paragraphs of text need to be displayed starting at the right
223 margin of the window---the so-called right-to-left, or R2L
224 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
225 which have their reversed_p flag set. The bidi reordering engine
226 produces characters in such rows starting from the character which
227 should be the rightmost on display. PRODUCE_GLYPHS then reverses
228 the order, when it fills up the glyph row whose reversed_p flag is
229 set, by prepending each new glyph to what is already there, instead
230 of appending it. When the glyph row is complete, the function
231 extend_face_to_end_of_line fills the empty space to the left of the
232 leftmost character with special glyphs, which will display as,
233 well, empty. On text terminals, these special glyphs are simply
234 blank characters. On graphics terminals, there's a single stretch
235 glyph of a suitably computed width. Both the blanks and the
236 stretch glyph are given the face of the background of the line.
237 This way, the terminal-specific back-end can still draw the glyphs
238 left to right, even for R2L lines.
240 Bidirectional display and character compositions
242 Some scripts cannot be displayed by drawing each character
243 individually, because adjacent characters change each other's shape
244 on display. For example, Arabic and Indic scripts belong to this
247 Emacs display supports this by providing "character compositions",
248 most of which is implemented in composite.c. During the buffer
249 scan that delivers characters to PRODUCE_GLYPHS, if the next
250 character to be delivered is a composed character, the iteration
251 calls composition_reseat_it and next_element_from_composition. If
252 they succeed to compose the character with one or more of the
253 following characters, the whole sequence of characters that where
254 composed is recorded in the `struct composition_it' object that is
255 part of the buffer iterator. The composed sequence could produce
256 one or more font glyphs (called "grapheme clusters") on the screen.
257 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
258 in the direction corresponding to the current bidi scan direction
259 (recorded in the scan_dir member of the `struct bidi_it' object
260 that is part of the buffer iterator). In particular, if the bidi
261 iterator currently scans the buffer backwards, the grapheme
262 clusters are delivered back to front. This reorders the grapheme
263 clusters as appropriate for the current bidi context. Note that
264 this means that the grapheme clusters are always stored in the
265 LGSTRING object (see composite.c) in the logical order.
267 Moving an iterator in bidirectional text
268 without producing glyphs
270 Note one important detail mentioned above: that the bidi reordering
271 engine, driven by the iterator, produces characters in R2L rows
272 starting at the character that will be the rightmost on display.
273 As far as the iterator is concerned, the geometry of such rows is
274 still left to right, i.e. the iterator "thinks" the first character
275 is at the leftmost pixel position. The iterator does not know that
276 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
277 delivers. This is important when functions from the move_it_*
278 family are used to get to certain screen position or to match
279 screen coordinates with buffer coordinates: these functions use the
280 iterator geometry, which is left to right even in R2L paragraphs.
281 This works well with most callers of move_it_*, because they need
282 to get to a specific column, and columns are still numbered in the
283 reading order, i.e. the rightmost character in a R2L paragraph is
284 still column zero. But some callers do not get well with this; a
285 notable example is mouse clicks that need to find the character
286 that corresponds to certain pixel coordinates. See
287 buffer_posn_from_coords in dispnew.c for how this is handled. */
295 #include "keyboard.h"
298 #include "termchar.h"
299 #include "dispextern.h"
300 #include "character.h"
304 #include "commands.h"
308 #include "termhooks.h"
309 #include "termopts.h"
310 #include "intervals.h"
313 #include "region-cache.h"
316 #include "blockinput.h"
317 #ifdef HAVE_WINDOW_SYSTEM
319 #endif /* HAVE_WINDOW_SYSTEM */
321 #ifndef FRAME_X_OUTPUT
322 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
325 #define INFINITY 10000000
327 /* Holds the list (error). */
328 static Lisp_Object list_of_error
;
330 #ifdef HAVE_WINDOW_SYSTEM
332 /* Test if overflow newline into fringe. Called with iterator IT
333 at or past right window margin, and with IT->current_x set. */
335 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
336 (!NILP (Voverflow_newline_into_fringe) \
337 && FRAME_WINDOW_P ((IT)->f) \
338 && ((IT)->bidi_it.paragraph_dir == R2L \
339 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
340 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
341 && (IT)->current_x == (IT)->last_visible_x)
343 #else /* !HAVE_WINDOW_SYSTEM */
344 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
345 #endif /* HAVE_WINDOW_SYSTEM */
347 /* Test if the display element loaded in IT, or the underlying buffer
348 or string character, is a space or a TAB character. This is used
349 to determine where word wrapping can occur. */
351 #define IT_DISPLAYING_WHITESPACE(it) \
352 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
353 || ((STRINGP (it->string) \
354 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
355 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
357 && (it->s[IT_BYTEPOS (*it)] == ' ' \
358 || it->s[IT_BYTEPOS (*it)] == '\t')) \
359 || (IT_BYTEPOS (*it) < ZV_BYTE \
360 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
361 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
363 /* Non-zero means print newline to stdout before next mini-buffer
366 bool noninteractive_need_newline
;
368 /* Non-zero 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 /* Nonzero 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 /* Nonzero means multibyte characters were enabled when the echo area
434 message was specified. */
436 static bool message_enable_multibyte
;
438 /* Nonzero if we should redraw the mode lines on the next redisplay.
439 If it has value REDISPLAY_SOME, then only redisplay the mode lines where
440 the `redisplay' bit has been set. Otherwise, redisplay all mode lines
441 (the number used is then only used to track down the cause for this
444 int update_mode_lines
;
446 /* Nonzero if window sizes or contents other than selected-window have changed
447 since last redisplay that finished.
448 If it has value REDISPLAY_SOME, then only redisplay the windows where
449 the `redisplay' bit has been set. Otherwise, redisplay all windows
450 (the number used is then only used to track down the cause for this
453 int windows_or_buffers_changed
;
455 /* Nonzero after display_mode_line if %l was used and it displayed a
458 static bool line_number_displayed
;
460 /* The name of the *Messages* buffer, a string. */
462 static Lisp_Object Vmessages_buffer_name
;
464 /* Current, index 0, and last displayed echo area message. Either
465 buffers from echo_buffers, or nil to indicate no message. */
467 Lisp_Object echo_area_buffer
[2];
469 /* The buffers referenced from echo_area_buffer. */
471 static Lisp_Object echo_buffer
[2];
473 /* A vector saved used in with_area_buffer to reduce consing. */
475 static Lisp_Object Vwith_echo_area_save_vector
;
477 /* Non-zero means display_echo_area should display the last echo area
478 message again. Set by redisplay_preserve_echo_area. */
480 static bool display_last_displayed_message_p
;
482 /* Nonzero if echo area is being used by print; zero if being used by
485 static bool message_buf_print
;
487 /* Set to 1 in clear_message to make redisplay_internal aware
488 of an emptied echo area. */
490 static bool message_cleared_p
;
492 /* A scratch glyph row with contents used for generating truncation
493 glyphs. Also used in direct_output_for_insert. */
495 #define MAX_SCRATCH_GLYPHS 100
496 static struct glyph_row scratch_glyph_row
;
497 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
499 /* Ascent and height of the last line processed by move_it_to. */
501 static int last_height
;
503 /* Non-zero if there's a help-echo in the echo area. */
505 bool help_echo_showing_p
;
507 /* The maximum distance to look ahead for text properties. Values
508 that are too small let us call compute_char_face and similar
509 functions too often which is expensive. Values that are too large
510 let us call compute_char_face and alike too often because we
511 might not be interested in text properties that far away. */
513 #define TEXT_PROP_DISTANCE_LIMIT 100
515 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
516 iterator state and later restore it. This is needed because the
517 bidi iterator on bidi.c keeps a stacked cache of its states, which
518 is really a singleton. When we use scratch iterator objects to
519 move around the buffer, we can cause the bidi cache to be pushed or
520 popped, and therefore we need to restore the cache state when we
521 return to the original iterator. */
522 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
525 bidi_unshelve_cache (CACHE, 1); \
527 CACHE = bidi_shelve_cache (); \
530 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
532 if (pITORIG != pITCOPY) \
533 *(pITORIG) = *(pITCOPY); \
534 bidi_unshelve_cache (CACHE, 0); \
538 /* Functions to mark elements as needing redisplay. */
539 enum { REDISPLAY_SOME
= 2}; /* Arbitrary choice. */
542 redisplay_other_windows (void)
544 if (!windows_or_buffers_changed
)
545 windows_or_buffers_changed
= REDISPLAY_SOME
;
549 wset_redisplay (struct window
*w
)
551 /* Beware: selected_window can be nil during early stages. */
552 if (!EQ (make_lisp_ptr (w
, Lisp_Vectorlike
), selected_window
))
553 redisplay_other_windows ();
558 fset_redisplay (struct frame
*f
)
560 redisplay_other_windows ();
565 bset_redisplay (struct buffer
*b
)
567 int count
= buffer_window_count (b
);
570 /* ... it's visible in other window than selected, */
571 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
572 redisplay_other_windows ();
573 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
574 so that if we later set windows_or_buffers_changed, this buffer will
576 b
->text
->redisplay
= true;
581 bset_update_mode_line (struct buffer
*b
)
583 if (!update_mode_lines
)
584 update_mode_lines
= REDISPLAY_SOME
;
585 b
->text
->redisplay
= true;
590 /* Non-zero means print traces of redisplay if compiled with
591 GLYPH_DEBUG defined. */
593 bool trace_redisplay_p
;
595 #endif /* GLYPH_DEBUG */
597 #ifdef DEBUG_TRACE_MOVE
598 /* Non-zero means trace with TRACE_MOVE to stderr. */
601 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
603 #define TRACE_MOVE(x) (void) 0
606 /* Buffer being redisplayed -- for redisplay_window_error. */
608 static struct buffer
*displayed_buffer
;
610 /* Value returned from text property handlers (see below). */
615 HANDLED_RECOMPUTE_PROPS
,
616 HANDLED_OVERLAY_STRING_CONSUMED
,
620 /* A description of text properties that redisplay is interested
625 /* The name of the property. */
626 struct Lisp_Symbol
*name
;
628 /* A unique index for the property. */
631 /* A handler function called to set up iterator IT from the property
632 at IT's current position. Value is used to steer handle_stop. */
633 enum prop_handled (*handler
) (struct it
*it
);
636 static enum prop_handled
handle_face_prop (struct it
*);
637 static enum prop_handled
handle_invisible_prop (struct it
*);
638 static enum prop_handled
handle_display_prop (struct it
*);
639 static enum prop_handled
handle_composition_prop (struct it
*);
640 static enum prop_handled
handle_overlay_change (struct it
*);
641 static enum prop_handled
handle_fontified_prop (struct it
*);
643 /* Properties handled by iterators. */
645 static struct props it_props
[] =
647 {XSYMBOL_INIT (Qfontified
), FONTIFIED_PROP_IDX
, handle_fontified_prop
},
648 /* Handle `face' before `display' because some sub-properties of
649 `display' need to know the face. */
650 {XSYMBOL_INIT (Qface
), FACE_PROP_IDX
, handle_face_prop
},
651 {XSYMBOL_INIT (Qdisplay
), DISPLAY_PROP_IDX
, handle_display_prop
},
652 {XSYMBOL_INIT (Qinvisible
), INVISIBLE_PROP_IDX
, handle_invisible_prop
},
653 {XSYMBOL_INIT (Qcomposition
), COMPOSITION_PROP_IDX
, handle_composition_prop
},
657 /* Value is the position described by X. If X is a marker, value is
658 the marker_position of X. Otherwise, value is X. */
660 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
662 /* Enumeration returned by some move_it_.* functions internally. */
666 /* Not used. Undefined value. */
669 /* Move ended at the requested buffer position or ZV. */
670 MOVE_POS_MATCH_OR_ZV
,
672 /* Move ended at the requested X pixel position. */
675 /* Move within a line ended at the end of a line that must be
679 /* Move within a line ended at the end of a line that would
680 be displayed truncated. */
683 /* Move within a line ended at a line end. */
687 /* This counter is used to clear the face cache every once in a while
688 in redisplay_internal. It is incremented for each redisplay.
689 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
692 #define CLEAR_FACE_CACHE_COUNT 500
693 static int clear_face_cache_count
;
695 /* Similarly for the image cache. */
697 #ifdef HAVE_WINDOW_SYSTEM
698 #define CLEAR_IMAGE_CACHE_COUNT 101
699 static int clear_image_cache_count
;
701 /* Null glyph slice */
702 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
705 /* True while redisplay_internal is in progress. */
709 /* If a string, XTread_socket generates an event to display that string.
710 (The display is done in read_char.) */
712 Lisp_Object help_echo_string
;
713 Lisp_Object help_echo_window
;
714 Lisp_Object help_echo_object
;
715 ptrdiff_t help_echo_pos
;
717 /* Temporary variable for XTread_socket. */
719 Lisp_Object previous_help_echo_string
;
721 /* Platform-independent portion of hourglass implementation. */
723 #ifdef HAVE_WINDOW_SYSTEM
725 /* Non-zero means an hourglass cursor is currently shown. */
726 static bool hourglass_shown_p
;
728 /* If non-null, an asynchronous timer that, when it expires, displays
729 an hourglass cursor on all frames. */
730 static struct atimer
*hourglass_atimer
;
732 #endif /* HAVE_WINDOW_SYSTEM */
734 /* Default number of seconds to wait before displaying an hourglass
736 #define DEFAULT_HOURGLASS_DELAY 1
738 #ifdef HAVE_WINDOW_SYSTEM
740 /* Default pixel width of `thin-space' display method. */
741 #define THIN_SPACE_WIDTH 1
743 #endif /* HAVE_WINDOW_SYSTEM */
745 /* Function prototypes. */
747 static void setup_for_ellipsis (struct it
*, int);
748 static void set_iterator_to_next (struct it
*, int);
749 static void mark_window_display_accurate_1 (struct window
*, int);
750 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
751 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
752 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
753 static int cursor_row_p (struct glyph_row
*);
754 static int redisplay_mode_lines (Lisp_Object
, bool);
755 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
757 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
759 static void handle_line_prefix (struct it
*);
761 static void pint2str (char *, int, ptrdiff_t);
762 static void pint2hrstr (char *, int, ptrdiff_t);
763 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
765 static int text_outside_line_unchanged_p (struct window
*,
766 ptrdiff_t, ptrdiff_t);
767 static void store_mode_line_noprop_char (char);
768 static int store_mode_line_noprop (const char *, int, int);
769 static void handle_stop (struct it
*);
770 static void handle_stop_backwards (struct it
*, ptrdiff_t);
771 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
772 static void ensure_echo_area_buffers (void);
773 static void unwind_with_echo_area_buffer (Lisp_Object
);
774 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
775 static int with_echo_area_buffer (struct window
*, int,
776 int (*) (ptrdiff_t, Lisp_Object
),
777 ptrdiff_t, Lisp_Object
);
778 static void clear_garbaged_frames (void);
779 static int current_message_1 (ptrdiff_t, Lisp_Object
);
780 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
781 static void set_message (Lisp_Object
);
782 static int set_message_1 (ptrdiff_t, Lisp_Object
);
783 static int display_echo_area (struct window
*);
784 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
785 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
786 static void unwind_redisplay (void);
787 static int string_char_and_length (const unsigned char *, int *);
788 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
790 static int compute_window_start_on_continuation_line (struct window
*);
791 static void insert_left_trunc_glyphs (struct it
*);
792 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
794 static void extend_face_to_end_of_line (struct it
*);
795 static int append_space_for_newline (struct it
*, int);
796 static int cursor_row_fully_visible_p (struct window
*, int, int);
797 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
798 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
799 static int trailing_whitespace_p (ptrdiff_t);
800 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
801 static void push_it (struct it
*, struct text_pos
*);
802 static void iterate_out_of_display_property (struct it
*);
803 static void pop_it (struct it
*);
804 static void sync_frame_with_window_matrix_rows (struct window
*);
805 static void redisplay_internal (void);
806 static bool echo_area_display (bool);
807 static void redisplay_windows (Lisp_Object
);
808 static void redisplay_window (Lisp_Object
, bool);
809 static Lisp_Object
redisplay_window_error (Lisp_Object
);
810 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
811 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
812 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
813 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
815 static int update_menu_bar (struct frame
*, int, int);
816 static int try_window_reusing_current_matrix (struct window
*);
817 static int try_window_id (struct window
*);
818 static int display_line (struct it
*);
819 static int display_mode_lines (struct window
*);
820 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
821 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
822 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
823 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
824 static void display_menu_bar (struct window
*);
825 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
827 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
828 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
829 static void compute_line_metrics (struct it
*);
830 static void run_redisplay_end_trigger_hook (struct it
*);
831 static int get_overlay_strings (struct it
*, ptrdiff_t);
832 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
833 static void next_overlay_string (struct it
*);
834 static void reseat (struct it
*, struct text_pos
, int);
835 static void reseat_1 (struct it
*, struct text_pos
, int);
836 static void back_to_previous_visible_line_start (struct it
*);
837 static void reseat_at_next_visible_line_start (struct it
*, int);
838 static int next_element_from_ellipsis (struct it
*);
839 static int next_element_from_display_vector (struct it
*);
840 static int next_element_from_string (struct it
*);
841 static int next_element_from_c_string (struct it
*);
842 static int next_element_from_buffer (struct it
*);
843 static int next_element_from_composition (struct it
*);
844 static int next_element_from_image (struct it
*);
845 static int next_element_from_stretch (struct it
*);
846 static void load_overlay_strings (struct it
*, ptrdiff_t);
847 static int init_from_display_pos (struct it
*, struct window
*,
848 struct display_pos
*);
849 static void reseat_to_string (struct it
*, const char *,
850 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
851 static int get_next_display_element (struct it
*);
852 static enum move_it_result
853 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
854 enum move_operation_enum
);
855 static void get_visually_first_element (struct it
*);
856 static void init_to_row_start (struct it
*, struct window
*,
858 static int init_to_row_end (struct it
*, struct window
*,
860 static void back_to_previous_line_start (struct it
*);
861 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
862 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
863 Lisp_Object
, ptrdiff_t);
864 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
865 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
866 static ptrdiff_t number_of_chars (const char *, bool);
867 static void compute_stop_pos (struct it
*);
868 static void compute_string_pos (struct text_pos
*, struct text_pos
,
870 static int face_before_or_after_it_pos (struct it
*, int);
871 static ptrdiff_t next_overlay_change (ptrdiff_t);
872 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
873 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
874 static int handle_single_display_spec (struct it
*, Lisp_Object
,
875 Lisp_Object
, Lisp_Object
,
876 struct text_pos
*, ptrdiff_t, int, int);
877 static int underlying_face_id (struct it
*);
878 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
881 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
882 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
884 #ifdef HAVE_WINDOW_SYSTEM
886 static void x_consider_frame_title (Lisp_Object
);
887 static void update_tool_bar (struct frame
*, int);
888 static int redisplay_tool_bar (struct frame
*);
889 static void x_draw_bottom_divider (struct window
*w
);
890 static void notice_overwritten_cursor (struct window
*,
893 static void append_stretch_glyph (struct it
*, Lisp_Object
,
897 #endif /* HAVE_WINDOW_SYSTEM */
899 static void produce_special_glyphs (struct it
*, enum display_element_type
);
900 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
901 static bool coords_in_mouse_face_p (struct window
*, int, int);
905 /***********************************************************************
906 Window display dimensions
907 ***********************************************************************/
909 /* Return the bottom boundary y-position for text lines in window W.
910 This is the first y position at which a line cannot start.
911 It is relative to the top of the window.
913 This is the height of W minus the height of a mode line, if any. */
916 window_text_bottom_y (struct window
*w
)
918 int height
= WINDOW_PIXEL_HEIGHT (w
);
920 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
922 if (WINDOW_WANTS_MODELINE_P (w
))
923 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
925 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
930 /* Return the pixel width of display area AREA of window W.
931 ANY_AREA means return the total width of W, not including
932 fringes to the left and right of the window. */
935 window_box_width (struct window
*w
, enum glyph_row_area area
)
937 int width
= w
->pixel_width
;
939 if (!w
->pseudo_window_p
)
941 width
-= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
942 width
-= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
944 if (area
== TEXT_AREA
)
945 width
-= (WINDOW_MARGINS_WIDTH (w
)
946 + WINDOW_FRINGES_WIDTH (w
));
947 else if (area
== LEFT_MARGIN_AREA
)
948 width
= WINDOW_LEFT_MARGIN_WIDTH (w
);
949 else if (area
== RIGHT_MARGIN_AREA
)
950 width
= WINDOW_RIGHT_MARGIN_WIDTH (w
);
953 /* With wide margins, fringes, etc. we might end up with a negative
954 width, correct that here. */
955 return max (0, width
);
959 /* Return the pixel height of the display area of window W, not
960 including mode lines of W, if any. */
963 window_box_height (struct window
*w
)
965 struct frame
*f
= XFRAME (w
->frame
);
966 int height
= WINDOW_PIXEL_HEIGHT (w
);
968 eassert (height
>= 0);
970 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
971 height
-= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
973 /* Note: the code below that determines the mode-line/header-line
974 height is essentially the same as that contained in the macro
975 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
976 the appropriate glyph row has its `mode_line_p' flag set,
977 and if it doesn't, uses estimate_mode_line_height instead. */
979 if (WINDOW_WANTS_MODELINE_P (w
))
981 struct glyph_row
*ml_row
982 = (w
->current_matrix
&& w
->current_matrix
->rows
983 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
985 if (ml_row
&& ml_row
->mode_line_p
)
986 height
-= ml_row
->height
;
988 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
991 if (WINDOW_WANTS_HEADER_LINE_P (w
))
993 struct glyph_row
*hl_row
994 = (w
->current_matrix
&& w
->current_matrix
->rows
995 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
997 if (hl_row
&& hl_row
->mode_line_p
)
998 height
-= hl_row
->height
;
1000 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1003 /* With a very small font and a mode-line that's taller than
1004 default, we might end up with a negative height. */
1005 return max (0, height
);
1008 /* Return the window-relative coordinate of the left edge of display
1009 area AREA of window W. ANY_AREA means return the left edge of the
1010 whole window, to the right of the left fringe of W. */
1013 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1017 if (w
->pseudo_window_p
)
1020 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1022 if (area
== TEXT_AREA
)
1023 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1024 + window_box_width (w
, LEFT_MARGIN_AREA
));
1025 else if (area
== RIGHT_MARGIN_AREA
)
1026 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1027 + window_box_width (w
, LEFT_MARGIN_AREA
)
1028 + window_box_width (w
, TEXT_AREA
)
1029 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1031 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1032 else if (area
== LEFT_MARGIN_AREA
1033 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1034 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1036 /* Don't return more than the window's pixel width. */
1037 return min (x
, w
->pixel_width
);
1041 /* Return the window-relative coordinate of the right edge of display
1042 area AREA of window W. ANY_AREA means return the right edge of the
1043 whole window, to the left of the right fringe of W. */
1046 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1048 /* Don't return more than the window's pixel width. */
1049 return min (window_box_left_offset (w
, area
) + window_box_width (w
, area
),
1053 /* Return the frame-relative coordinate of the left edge of display
1054 area AREA of window W. ANY_AREA means return the left edge of the
1055 whole window, to the right of the left fringe of W. */
1058 window_box_left (struct window
*w
, enum glyph_row_area area
)
1060 struct frame
*f
= XFRAME (w
->frame
);
1063 if (w
->pseudo_window_p
)
1064 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1066 x
= (WINDOW_LEFT_EDGE_X (w
)
1067 + window_box_left_offset (w
, area
));
1073 /* Return the frame-relative coordinate of the right edge of display
1074 area AREA of window W. ANY_AREA means return the right edge of the
1075 whole window, to the left of the right fringe of W. */
1078 window_box_right (struct window
*w
, enum glyph_row_area area
)
1080 return window_box_left (w
, area
) + window_box_width (w
, area
);
1083 /* Get the bounding box of the display area AREA of window W, without
1084 mode lines, in frame-relative coordinates. ANY_AREA means the
1085 whole window, not including the left and right fringes of
1086 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1087 coordinates of the upper-left corner of the box. Return in
1088 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1091 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1092 int *box_y
, int *box_width
, int *box_height
)
1095 *box_width
= window_box_width (w
, area
);
1097 *box_height
= window_box_height (w
);
1099 *box_x
= window_box_left (w
, area
);
1102 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1103 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1104 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1108 #ifdef HAVE_WINDOW_SYSTEM
1110 /* Get the bounding box of the display area AREA of window W, without
1111 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1112 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1113 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1114 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1118 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1119 int *bottom_right_x
, int *bottom_right_y
)
1121 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1122 bottom_right_x
, bottom_right_y
);
1123 *bottom_right_x
+= *top_left_x
;
1124 *bottom_right_y
+= *top_left_y
;
1127 #endif /* HAVE_WINDOW_SYSTEM */
1129 /***********************************************************************
1131 ***********************************************************************/
1133 /* Return the bottom y-position of the line the iterator IT is in.
1134 This can modify IT's settings. */
1137 line_bottom_y (struct it
*it
)
1139 int line_height
= it
->max_ascent
+ it
->max_descent
;
1140 int line_top_y
= it
->current_y
;
1142 if (line_height
== 0)
1145 line_height
= last_height
;
1146 else if (IT_CHARPOS (*it
) < ZV
)
1148 move_it_by_lines (it
, 1);
1149 line_height
= (it
->max_ascent
|| it
->max_descent
1150 ? it
->max_ascent
+ it
->max_descent
1155 struct glyph_row
*row
= it
->glyph_row
;
1157 /* Use the default character height. */
1158 it
->glyph_row
= NULL
;
1159 it
->what
= IT_CHARACTER
;
1162 PRODUCE_GLYPHS (it
);
1163 line_height
= it
->ascent
+ it
->descent
;
1164 it
->glyph_row
= row
;
1168 return line_top_y
+ line_height
;
1171 DEFUN ("line-pixel-height", Fline_pixel_height
,
1172 Sline_pixel_height
, 0, 0, 0,
1173 doc
: /* Return height in pixels of text line in the selected window.
1175 Value is the height in pixels of the line at point. */)
1180 struct window
*w
= XWINDOW (selected_window
);
1181 struct buffer
*old_buffer
= NULL
;
1184 if (XBUFFER (w
->contents
) != current_buffer
)
1186 old_buffer
= current_buffer
;
1187 set_buffer_internal_1 (XBUFFER (w
->contents
));
1189 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1190 start_display (&it
, w
, pt
);
1191 it
.vpos
= it
.current_y
= 0;
1193 result
= make_number (line_bottom_y (&it
));
1195 set_buffer_internal_1 (old_buffer
);
1200 /* Return the default pixel height of text lines in window W. The
1201 value is the canonical height of the W frame's default font, plus
1202 any extra space required by the line-spacing variable or frame
1205 Implementation note: this ignores any line-spacing text properties
1206 put on the newline characters. This is because those properties
1207 only affect the _screen_ line ending in the newline (i.e., in a
1208 continued line, only the last screen line will be affected), which
1209 means only a small number of lines in a buffer can ever use this
1210 feature. Since this function is used to compute the default pixel
1211 equivalent of text lines in a window, we can safely ignore those
1212 few lines. For the same reasons, we ignore the line-height
1215 default_line_pixel_height (struct window
*w
)
1217 struct frame
*f
= WINDOW_XFRAME (w
);
1218 int height
= FRAME_LINE_HEIGHT (f
);
1220 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1222 struct buffer
*b
= XBUFFER (w
->contents
);
1223 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1226 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1229 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1230 height
+= XFASTINT (val
);
1231 else if (FLOATP (val
))
1233 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1240 height
+= f
->extra_line_spacing
;
1246 /* Subroutine of pos_visible_p below. Extracts a display string, if
1247 any, from the display spec given as its argument. */
1249 string_from_display_spec (Lisp_Object spec
)
1253 while (CONSP (spec
))
1255 if (STRINGP (XCAR (spec
)))
1260 else if (VECTORP (spec
))
1264 for (i
= 0; i
< ASIZE (spec
); i
++)
1266 if (STRINGP (AREF (spec
, i
)))
1267 return AREF (spec
, i
);
1276 /* Limit insanely large values of W->hscroll on frame F to the largest
1277 value that will still prevent first_visible_x and last_visible_x of
1278 'struct it' from overflowing an int. */
1280 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1282 ptrdiff_t window_hscroll
= w
->hscroll
;
1283 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1284 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1286 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1287 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1289 return window_hscroll
;
1292 /* Return 1 if position CHARPOS is visible in window W.
1293 CHARPOS < 0 means return info about WINDOW_END position.
1294 If visible, set *X and *Y to pixel coordinates of top left corner.
1295 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1296 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1299 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1300 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1303 void *itdata
= bidi_shelve_cache ();
1304 struct text_pos top
;
1306 struct buffer
*old_buffer
= NULL
;
1309 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1312 if (XBUFFER (w
->contents
) != current_buffer
)
1314 old_buffer
= current_buffer
;
1315 set_buffer_internal_1 (XBUFFER (w
->contents
));
1318 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1319 /* Scrolling a minibuffer window via scroll bar when the echo area
1320 shows long text sometimes resets the minibuffer contents behind
1322 if (CHARPOS (top
) > ZV
)
1323 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1325 /* Compute exact mode line heights. */
1326 if (WINDOW_WANTS_MODELINE_P (w
))
1328 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1329 BVAR (current_buffer
, mode_line_format
));
1331 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1332 w
->header_line_height
1333 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1334 BVAR (current_buffer
, header_line_format
));
1336 start_display (&it
, w
, top
);
1337 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1338 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1341 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
!= -1)
1342 && IT_CHARPOS (it
) >= charpos
)
1343 /* When scanning backwards under bidi iteration, move_it_to
1344 stops at or _before_ CHARPOS, because it stops at or to
1345 the _right_ of the character at CHARPOS. */
1346 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1347 && IT_CHARPOS (it
) <= charpos
)))
1349 /* We have reached CHARPOS, or passed it. How the call to
1350 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1351 or covered by a display property, move_it_to stops at the end
1352 of the invisible text, to the right of CHARPOS. (ii) If
1353 CHARPOS is in a display vector, move_it_to stops on its last
1355 int top_x
= it
.current_x
;
1356 int top_y
= it
.current_y
;
1357 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1360 void *save_it_data
= NULL
;
1362 /* Calling line_bottom_y may change it.method, it.position, etc. */
1363 SAVE_IT (save_it
, it
, save_it_data
);
1365 bottom_y
= line_bottom_y (&it
);
1366 if (top_y
< window_top_y
)
1367 visible_p
= bottom_y
> window_top_y
;
1368 else if (top_y
< it
.last_visible_y
)
1370 if (bottom_y
>= it
.last_visible_y
1371 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1372 && IT_CHARPOS (it
) < charpos
)
1374 /* When the last line of the window is scanned backwards
1375 under bidi iteration, we could be duped into thinking
1376 that we have passed CHARPOS, when in fact move_it_to
1377 simply stopped short of CHARPOS because it reached
1378 last_visible_y. To see if that's what happened, we call
1379 move_it_to again with a slightly larger vertical limit,
1380 and see if it actually moved vertically; if it did, we
1381 didn't really reach CHARPOS, which is beyond window end. */
1382 /* Why 10? because we don't know how many canonical lines
1383 will the height of the next line(s) be. So we guess. */
1384 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1386 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1387 MOVE_TO_POS
| MOVE_TO_Y
);
1388 if (it
.current_y
> top_y
)
1392 RESTORE_IT (&it
, &save_it
, save_it_data
);
1395 if (it
.method
== GET_FROM_DISPLAY_VECTOR
)
1397 /* We stopped on the last glyph of a display vector.
1398 Try and recompute. Hack alert! */
1399 if (charpos
< 2 || top
.charpos
>= charpos
)
1400 top_x
= it
.glyph_row
->x
;
1403 struct it it2
, it2_prev
;
1404 /* The idea is to get to the previous buffer
1405 position, consume the character there, and use
1406 the pixel coordinates we get after that. But if
1407 the previous buffer position is also displayed
1408 from a display vector, we need to consume all of
1409 the glyphs from that display vector. */
1410 start_display (&it2
, w
, top
);
1411 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1412 /* If we didn't get to CHARPOS - 1, there's some
1413 replacing display property at that position, and
1414 we stopped after it. That is exactly the place
1415 whose coordinates we want. */
1416 if (IT_CHARPOS (it2
) != charpos
- 1)
1420 /* Iterate until we get out of the display
1421 vector that displays the character at
1424 get_next_display_element (&it2
);
1425 PRODUCE_GLYPHS (&it2
);
1427 set_iterator_to_next (&it2
, 1);
1428 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1429 && IT_CHARPOS (it2
) < charpos
);
1431 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1432 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1433 top_x
= it
.glyph_row
->x
;
1436 top_x
= it2_prev
.current_x
;
1437 top_y
= it2_prev
.current_y
;
1441 else if (IT_CHARPOS (it
) != charpos
)
1443 Lisp_Object cpos
= make_number (charpos
);
1444 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1445 Lisp_Object string
= string_from_display_spec (spec
);
1446 struct text_pos tpos
;
1447 int replacing_spec_p
;
1448 bool newline_in_string
1450 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1452 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1455 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1456 charpos
, FRAME_WINDOW_P (it
.f
)));
1457 /* The tricky code below is needed because there's a
1458 discrepancy between move_it_to and how we set cursor
1459 when PT is at the beginning of a portion of text
1460 covered by a display property or an overlay with a
1461 display property, or the display line ends in a
1462 newline from a display string. move_it_to will stop
1463 _after_ such display strings, whereas
1464 set_cursor_from_row conspires with cursor_row_p to
1465 place the cursor on the first glyph produced from the
1468 /* We have overshoot PT because it is covered by a
1469 display property that replaces the text it covers.
1470 If the string includes embedded newlines, we are also
1471 in the wrong display line. Backtrack to the correct
1472 line, where the display property begins. */
1473 if (replacing_spec_p
)
1475 Lisp_Object startpos
, endpos
;
1476 EMACS_INT start
, end
;
1480 /* Find the first and the last buffer positions
1481 covered by the display string. */
1483 Fnext_single_char_property_change (cpos
, Qdisplay
,
1486 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1488 start
= XFASTINT (startpos
);
1489 end
= XFASTINT (endpos
);
1490 /* Move to the last buffer position before the
1491 display property. */
1492 start_display (&it3
, w
, top
);
1493 if (start
> CHARPOS (top
))
1494 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1495 /* Move forward one more line if the position before
1496 the display string is a newline or if it is the
1497 rightmost character on a line that is
1498 continued or word-wrapped. */
1499 if (it3
.method
== GET_FROM_BUFFER
1501 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1502 move_it_by_lines (&it3
, 1);
1503 else if (move_it_in_display_line_to (&it3
, -1,
1507 == MOVE_LINE_CONTINUED
)
1509 move_it_by_lines (&it3
, 1);
1510 /* When we are under word-wrap, the #$@%!
1511 move_it_by_lines moves 2 lines, so we need to
1513 if (it3
.line_wrap
== WORD_WRAP
)
1514 move_it_by_lines (&it3
, -1);
1517 /* Record the vertical coordinate of the display
1518 line where we wound up. */
1519 top_y
= it3
.current_y
;
1522 /* When characters are reordered for display,
1523 the character displayed to the left of the
1524 display string could be _after_ the display
1525 property in the logical order. Use the
1526 smallest vertical position of these two. */
1527 start_display (&it3
, w
, top
);
1528 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1529 if (it3
.current_y
< top_y
)
1530 top_y
= it3
.current_y
;
1532 /* Move from the top of the window to the beginning
1533 of the display line where the display string
1535 start_display (&it3
, w
, top
);
1536 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1537 /* If it3_moved stays zero after the 'while' loop
1538 below, that means we already were at a newline
1539 before the loop (e.g., the display string begins
1540 with a newline), so we don't need to (and cannot)
1541 inspect the glyphs of it3.glyph_row, because
1542 PRODUCE_GLYPHS will not produce anything for a
1543 newline, and thus it3.glyph_row stays at its
1544 stale content it got at top of the window. */
1546 /* Finally, advance the iterator until we hit the
1547 first display element whose character position is
1548 CHARPOS, or until the first newline from the
1549 display string, which signals the end of the
1551 while (get_next_display_element (&it3
))
1553 PRODUCE_GLYPHS (&it3
);
1554 if (IT_CHARPOS (it3
) == charpos
1555 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1558 set_iterator_to_next (&it3
, 0);
1560 top_x
= it3
.current_x
- it3
.pixel_width
;
1561 /* Normally, we would exit the above loop because we
1562 found the display element whose character
1563 position is CHARPOS. For the contingency that we
1564 didn't, and stopped at the first newline from the
1565 display string, move back over the glyphs
1566 produced from the string, until we find the
1567 rightmost glyph not from the string. */
1569 && newline_in_string
1570 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1572 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1573 + it3
.glyph_row
->used
[TEXT_AREA
];
1575 while (EQ ((g
- 1)->object
, string
))
1578 top_x
-= g
->pixel_width
;
1580 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1581 + it3
.glyph_row
->used
[TEXT_AREA
]);
1587 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1588 *rtop
= max (0, window_top_y
- top_y
);
1589 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1590 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1591 - max (top_y
, window_top_y
)));
1593 if (it
.bidi_it
.paragraph_dir
== R2L
)
1599 /* Either we were asked to provide info about WINDOW_END, or
1600 CHARPOS is in the partially visible glyph row at end of
1603 void *it2data
= NULL
;
1605 SAVE_IT (it2
, it
, it2data
);
1606 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1607 move_it_by_lines (&it
, 1);
1608 if (charpos
< IT_CHARPOS (it
)
1609 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1612 RESTORE_IT (&it2
, &it2
, it2data
);
1613 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1615 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1616 *rtop
= max (0, -it2
.current_y
);
1617 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1618 - it
.last_visible_y
));
1619 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1621 - max (it2
.current_y
,
1622 WINDOW_HEADER_LINE_HEIGHT (w
))));
1624 if (it2
.bidi_it
.paragraph_dir
== R2L
)
1628 bidi_unshelve_cache (it2data
, 1);
1630 bidi_unshelve_cache (itdata
, 0);
1633 set_buffer_internal_1 (old_buffer
);
1639 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1640 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1641 /* For lines in an R2L paragraph, we need to mirror the X pixel
1642 coordinate wrt the text area. For the reasons, see the
1643 commentary in buffer_posn_from_coords and the explanation of
1644 the geometry used by the move_it_* functions at the end of
1645 the large commentary near the beginning of this file. */
1647 *x
= window_box_width (w
, TEXT_AREA
) - *x
- 1;
1651 /* Debugging code. */
1653 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1654 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1656 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1663 /* Return the next character from STR. Return in *LEN the length of
1664 the character. This is like STRING_CHAR_AND_LENGTH but never
1665 returns an invalid character. If we find one, we return a `?', but
1666 with the length of the invalid character. */
1669 string_char_and_length (const unsigned char *str
, int *len
)
1673 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1674 if (!CHAR_VALID_P (c
))
1675 /* We may not change the length here because other places in Emacs
1676 don't use this function, i.e. they silently accept invalid
1685 /* Given a position POS containing a valid character and byte position
1686 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1688 static struct text_pos
1689 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1691 eassert (STRINGP (string
) && nchars
>= 0);
1693 if (STRING_MULTIBYTE (string
))
1695 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1700 string_char_and_length (p
, &len
);
1703 BYTEPOS (pos
) += len
;
1707 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1713 /* Value is the text position, i.e. character and byte position,
1714 for character position CHARPOS in STRING. */
1716 static struct text_pos
1717 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1719 struct text_pos pos
;
1720 eassert (STRINGP (string
));
1721 eassert (charpos
>= 0);
1722 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1727 /* Value is a text position, i.e. character and byte position, for
1728 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1729 means recognize multibyte characters. */
1731 static struct text_pos
1732 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1734 struct text_pos pos
;
1736 eassert (s
!= NULL
);
1737 eassert (charpos
>= 0);
1743 SET_TEXT_POS (pos
, 0, 0);
1746 string_char_and_length ((const unsigned char *) s
, &len
);
1749 BYTEPOS (pos
) += len
;
1753 SET_TEXT_POS (pos
, charpos
, charpos
);
1759 /* Value is the number of characters in C string S. MULTIBYTE_P
1760 non-zero means recognize multibyte characters. */
1763 number_of_chars (const char *s
, bool multibyte_p
)
1769 ptrdiff_t rest
= strlen (s
);
1771 const unsigned char *p
= (const unsigned char *) s
;
1773 for (nchars
= 0; rest
> 0; ++nchars
)
1775 string_char_and_length (p
, &len
);
1776 rest
-= len
, p
+= len
;
1780 nchars
= strlen (s
);
1786 /* Compute byte position NEWPOS->bytepos corresponding to
1787 NEWPOS->charpos. POS is a known position in string STRING.
1788 NEWPOS->charpos must be >= POS.charpos. */
1791 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1793 eassert (STRINGP (string
));
1794 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1796 if (STRING_MULTIBYTE (string
))
1797 *newpos
= string_pos_nchars_ahead (pos
, string
,
1798 CHARPOS (*newpos
) - CHARPOS (pos
));
1800 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1804 Return an estimation of the pixel height of mode or header lines on
1805 frame F. FACE_ID specifies what line's height to estimate. */
1808 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1810 #ifdef HAVE_WINDOW_SYSTEM
1811 if (FRAME_WINDOW_P (f
))
1813 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1815 /* This function is called so early when Emacs starts that the face
1816 cache and mode line face are not yet initialized. */
1817 if (FRAME_FACE_CACHE (f
))
1819 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1823 height
= FONT_HEIGHT (face
->font
);
1824 if (face
->box_line_width
> 0)
1825 height
+= 2 * face
->box_line_width
;
1836 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1837 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1838 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1839 not force the value into range. */
1842 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1843 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1846 #ifdef HAVE_WINDOW_SYSTEM
1847 if (FRAME_WINDOW_P (f
))
1849 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1850 even for negative values. */
1852 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1854 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1856 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1857 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1860 STORE_NATIVE_RECT (*bounds
,
1861 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1862 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1863 FRAME_COLUMN_WIDTH (f
) - 1,
1864 FRAME_LINE_HEIGHT (f
) - 1);
1866 /* PXW: Should we clip pixels before converting to columns/lines? */
1871 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1872 pix_x
= FRAME_TOTAL_COLS (f
);
1876 else if (pix_y
> FRAME_TOTAL_LINES (f
))
1877 pix_y
= FRAME_TOTAL_LINES (f
);
1887 /* Find the glyph under window-relative coordinates X/Y in window W.
1888 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1889 strings. Return in *HPOS and *VPOS the row and column number of
1890 the glyph found. Return in *AREA the glyph area containing X.
1891 Value is a pointer to the glyph found or null if X/Y is not on
1892 text, or we can't tell because W's current matrix is not up to
1895 static struct glyph
*
1896 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1897 int *dx
, int *dy
, int *area
)
1899 struct glyph
*glyph
, *end
;
1900 struct glyph_row
*row
= NULL
;
1903 /* Find row containing Y. Give up if some row is not enabled. */
1904 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1906 row
= MATRIX_ROW (w
->current_matrix
, i
);
1907 if (!row
->enabled_p
)
1909 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1916 /* Give up if Y is not in the window. */
1917 if (i
== w
->current_matrix
->nrows
)
1920 /* Get the glyph area containing X. */
1921 if (w
->pseudo_window_p
)
1928 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1930 *area
= LEFT_MARGIN_AREA
;
1931 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1933 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1936 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1940 *area
= RIGHT_MARGIN_AREA
;
1941 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1945 /* Find glyph containing X. */
1946 glyph
= row
->glyphs
[*area
];
1947 end
= glyph
+ row
->used
[*area
];
1949 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1951 x
-= glyph
->pixel_width
;
1961 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1964 *hpos
= glyph
- row
->glyphs
[*area
];
1968 /* Convert frame-relative x/y to coordinates relative to window W.
1969 Takes pseudo-windows into account. */
1972 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1974 if (w
->pseudo_window_p
)
1976 /* A pseudo-window is always full-width, and starts at the
1977 left edge of the frame, plus a frame border. */
1978 struct frame
*f
= XFRAME (w
->frame
);
1979 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1980 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1984 *x
-= WINDOW_LEFT_EDGE_X (w
);
1985 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1989 #ifdef HAVE_WINDOW_SYSTEM
1992 Return in RECTS[] at most N clipping rectangles for glyph string S.
1993 Return the number of stored rectangles. */
1996 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2003 if (s
->row
->full_width_p
)
2005 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2006 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2007 if (s
->row
->mode_line_p
)
2008 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
) - WINDOW_RIGHT_DIVIDER_WIDTH (s
->w
);
2010 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
);
2012 /* Unless displaying a mode or menu bar line, which are always
2013 fully visible, clip to the visible part of the row. */
2014 if (s
->w
->pseudo_window_p
)
2015 r
.height
= s
->row
->visible_height
;
2017 r
.height
= s
->height
;
2021 /* This is a text line that may be partially visible. */
2022 r
.x
= window_box_left (s
->w
, s
->area
);
2023 r
.width
= window_box_width (s
->w
, s
->area
);
2024 r
.height
= s
->row
->visible_height
;
2028 if (r
.x
< s
->clip_head
->x
)
2030 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2031 r
.width
-= s
->clip_head
->x
- r
.x
;
2034 r
.x
= s
->clip_head
->x
;
2037 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2039 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2040 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2045 /* If S draws overlapping rows, it's sufficient to use the top and
2046 bottom of the window for clipping because this glyph string
2047 intentionally draws over other lines. */
2048 if (s
->for_overlaps
)
2050 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2051 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2053 /* Alas, the above simple strategy does not work for the
2054 environments with anti-aliased text: if the same text is
2055 drawn onto the same place multiple times, it gets thicker.
2056 If the overlap we are processing is for the erased cursor, we
2057 take the intersection with the rectangle of the cursor. */
2058 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2060 XRectangle rc
, r_save
= r
;
2062 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2063 rc
.y
= s
->w
->phys_cursor
.y
;
2064 rc
.width
= s
->w
->phys_cursor_width
;
2065 rc
.height
= s
->w
->phys_cursor_height
;
2067 x_intersect_rectangles (&r_save
, &rc
, &r
);
2072 /* Don't use S->y for clipping because it doesn't take partially
2073 visible lines into account. For example, it can be negative for
2074 partially visible lines at the top of a window. */
2075 if (!s
->row
->full_width_p
2076 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2077 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2079 r
.y
= max (0, s
->row
->y
);
2082 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2084 /* If drawing the cursor, don't let glyph draw outside its
2085 advertised boundaries. Cleartype does this under some circumstances. */
2086 if (s
->hl
== DRAW_CURSOR
)
2088 struct glyph
*glyph
= s
->first_glyph
;
2093 if (r
.width
>= s
->x
- r
.x
)
2094 r
.width
-= s
->x
- r
.x
;
2095 else /* R2L hscrolled row with cursor outside text area */
2099 r
.width
= min (r
.width
, glyph
->pixel_width
);
2101 /* If r.y is below window bottom, ensure that we still see a cursor. */
2102 height
= min (glyph
->ascent
+ glyph
->descent
,
2103 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2104 max_y
= window_text_bottom_y (s
->w
) - height
;
2105 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2106 if (s
->ybase
- glyph
->ascent
> max_y
)
2113 /* Don't draw cursor glyph taller than our actual glyph. */
2114 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2115 if (height
< r
.height
)
2117 max_y
= r
.y
+ r
.height
;
2118 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2119 r
.height
= min (max_y
- r
.y
, height
);
2126 XRectangle r_save
= r
;
2128 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2132 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2133 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2135 #ifdef CONVERT_FROM_XRECT
2136 CONVERT_FROM_XRECT (r
, *rects
);
2144 /* If we are processing overlapping and allowed to return
2145 multiple clipping rectangles, we exclude the row of the glyph
2146 string from the clipping rectangle. This is to avoid drawing
2147 the same text on the environment with anti-aliasing. */
2148 #ifdef CONVERT_FROM_XRECT
2151 XRectangle
*rs
= rects
;
2153 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2155 if (s
->for_overlaps
& OVERLAPS_PRED
)
2158 if (r
.y
+ r
.height
> row_y
)
2161 rs
[i
].height
= row_y
- r
.y
;
2167 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2170 if (r
.y
< row_y
+ s
->row
->visible_height
)
2172 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2174 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2175 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2184 #ifdef CONVERT_FROM_XRECT
2185 for (i
= 0; i
< n
; i
++)
2186 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2193 Return in *NR the clipping rectangle for glyph string S. */
2196 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2198 get_glyph_string_clip_rects (s
, nr
, 1);
2203 Return the position and height of the phys cursor in window W.
2204 Set w->phys_cursor_width to width of phys cursor.
2208 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2209 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2211 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2212 int x
, y
, wd
, h
, h0
, y0
;
2214 /* Compute the width of the rectangle to draw. If on a stretch
2215 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2216 rectangle as wide as the glyph, but use a canonical character
2218 wd
= glyph
->pixel_width
;
2220 x
= w
->phys_cursor
.x
;
2227 if (glyph
->type
== STRETCH_GLYPH
2228 && !x_stretch_cursor_p
)
2229 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2230 w
->phys_cursor_width
= wd
;
2232 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2234 /* If y is below window bottom, ensure that we still see a cursor. */
2235 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2237 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2238 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2240 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2243 h
= max (h
- (y0
- y
) + 1, h0
);
2248 y0
= window_text_bottom_y (w
) - h0
;
2256 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2257 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2262 * Remember which glyph the mouse is over.
2266 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2270 struct glyph_row
*r
, *gr
, *end_row
;
2271 enum window_part part
;
2272 enum glyph_row_area area
;
2273 int x
, y
, width
, height
;
2275 /* Try to determine frame pixel position and size of the glyph under
2276 frame pixel coordinates X/Y on frame F. */
2278 if (window_resize_pixelwise
)
2283 else if (!f
->glyphs_initialized_p
2284 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2287 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2288 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2292 w
= XWINDOW (window
);
2293 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2294 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2296 x
= window_relative_x_coord (w
, part
, gx
);
2297 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2299 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2300 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2302 if (w
->pseudo_window_p
)
2305 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2311 case ON_LEFT_MARGIN
:
2312 area
= LEFT_MARGIN_AREA
;
2315 case ON_RIGHT_MARGIN
:
2316 area
= RIGHT_MARGIN_AREA
;
2319 case ON_HEADER_LINE
:
2321 gr
= (part
== ON_HEADER_LINE
2322 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2323 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2326 goto text_glyph_row_found
;
2333 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2334 if (r
->y
+ r
->height
> y
)
2340 text_glyph_row_found
:
2343 struct glyph
*g
= gr
->glyphs
[area
];
2344 struct glyph
*end
= g
+ gr
->used
[area
];
2346 height
= gr
->height
;
2347 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2348 if (gx
+ g
->pixel_width
> x
)
2353 if (g
->type
== IMAGE_GLYPH
)
2355 /* Don't remember when mouse is over image, as
2356 image may have hot-spots. */
2357 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2360 width
= g
->pixel_width
;
2364 /* Use nominal char spacing at end of line. */
2366 gx
+= (x
/ width
) * width
;
2369 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2371 gx
+= window_box_left_offset (w
, area
);
2372 /* Don't expand over the modeline to make sure the vertical
2373 drag cursor is shown early enough. */
2374 height
= min (height
,
2375 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2380 /* Use nominal line height at end of window. */
2381 gx
= (x
/ width
) * width
;
2383 gy
+= (y
/ height
) * height
;
2384 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2385 /* See comment above. */
2386 height
= min (height
,
2387 max (0, WINDOW_BOX_HEIGHT_NO_MODE_LINE (w
) - gy
));
2391 case ON_LEFT_FRINGE
:
2392 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2393 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2394 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2395 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2398 case ON_RIGHT_FRINGE
:
2399 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2400 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2401 : window_box_right_offset (w
, TEXT_AREA
));
2402 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
) == 0
2403 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
2404 && !WINDOW_RIGHTMOST_P (w
))
2405 if (gx
< WINDOW_PIXEL_WIDTH (w
) - width
)
2406 /* Make sure the vertical border can get her own glyph to the
2407 right of the one we build here. */
2408 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
) - width
;
2410 width
= WINDOW_PIXEL_WIDTH (w
) - gx
;
2412 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2416 case ON_VERTICAL_BORDER
:
2417 gx
= WINDOW_PIXEL_WIDTH (w
) - width
;
2420 case ON_VERTICAL_SCROLL_BAR
:
2421 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2423 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2424 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2425 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2427 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2431 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2432 if (r
->y
+ r
->height
> y
)
2439 height
= gr
->height
;
2442 /* Use nominal line height at end of window. */
2444 gy
+= (y
/ height
) * height
;
2448 case ON_RIGHT_DIVIDER
:
2449 gx
= WINDOW_PIXEL_WIDTH (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2450 width
= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
2452 /* The bottom divider prevails. */
2453 height
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2456 case ON_BOTTOM_DIVIDER
:
2458 width
= WINDOW_PIXEL_WIDTH (w
);
2459 gy
= WINDOW_PIXEL_HEIGHT (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2460 height
= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
2466 /* If there is no glyph under the mouse, then we divide the screen
2467 into a grid of the smallest glyph in the frame, and use that
2470 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2471 round down even for negative values. */
2477 gx
= (gx
/ width
) * width
;
2478 gy
= (gy
/ height
) * height
;
2484 gx
+= WINDOW_LEFT_EDGE_X (w
);
2485 gy
+= WINDOW_TOP_EDGE_Y (w
);
2488 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2490 /* Visible feedback for debugging. */
2493 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2494 f
->output_data
.x
->normal_gc
,
2495 gx
, gy
, width
, height
);
2501 #endif /* HAVE_WINDOW_SYSTEM */
2504 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2507 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2508 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2510 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2513 /***********************************************************************
2514 Lisp form evaluation
2515 ***********************************************************************/
2517 /* Error handler for safe_eval and safe_call. */
2520 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2522 add_to_log ("Error during redisplay: %S signaled %S",
2523 Flist (nargs
, args
), arg
);
2527 /* Call function FUNC with the rest of NARGS - 1 arguments
2528 following. Return the result, or nil if something went
2529 wrong. Prevent redisplay during the evaluation. */
2532 safe__call (bool inhibit_quit
, ptrdiff_t nargs
, Lisp_Object func
, va_list ap
)
2536 if (inhibit_eval_during_redisplay
)
2541 ptrdiff_t count
= SPECPDL_INDEX ();
2544 SAFE_ALLOCA_LISP (args
, nargs
);
2547 for (i
= 1; i
< nargs
; i
++)
2548 args
[i
] = va_arg (ap
, Lisp_Object
);
2550 specbind (Qinhibit_redisplay
, Qt
);
2552 specbind (Qinhibit_quit
, Qt
);
2553 /* Use Qt to ensure debugger does not run,
2554 so there is no possibility of wanting to redisplay. */
2555 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2558 val
= unbind_to (count
, val
);
2565 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2570 va_start (ap
, func
);
2571 retval
= safe__call (false, nargs
, func
, ap
);
2576 /* Call function FN with one argument ARG.
2577 Return the result, or nil if something went wrong. */
2580 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2582 return safe_call (2, fn
, arg
);
2586 safe__call1 (bool inhibit_quit
, Lisp_Object fn
, ...)
2592 retval
= safe__call (inhibit_quit
, 2, fn
, ap
);
2598 safe_eval (Lisp_Object sexpr
)
2600 return safe__call1 (false, Qeval
, sexpr
);
2604 safe__eval (bool inhibit_quit
, Lisp_Object sexpr
)
2606 return safe__call1 (inhibit_quit
, Qeval
, sexpr
);
2609 /* Call function FN with two arguments ARG1 and ARG2.
2610 Return the result, or nil if something went wrong. */
2613 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2615 return safe_call (3, fn
, arg1
, arg2
);
2620 /***********************************************************************
2622 ***********************************************************************/
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
)
2632 if (it
->method
== GET_FROM_STRING
)
2634 eassert (STRINGP (it
->string
));
2635 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2639 eassert (IT_STRING_CHARPOS (*it
) < 0);
2640 if (it
->method
== GET_FROM_BUFFER
)
2642 /* Check that character and byte positions agree. */
2643 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2648 eassert (it
->current
.dpvec_index
>= 0);
2650 eassert (it
->current
.dpvec_index
< 0);
2653 #define CHECK_IT(IT) check_it ((IT))
2657 #define CHECK_IT(IT) (void) 0
2662 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2664 /* Check that the window end of window W is what we expect it
2665 to be---the last row in the current matrix displaying text. */
2668 check_window_end (struct window
*w
)
2670 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2672 struct glyph_row
*row
;
2673 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2675 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2676 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2680 #define CHECK_WINDOW_END(W) check_window_end ((W))
2684 #define CHECK_WINDOW_END(W) (void) 0
2686 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2688 /***********************************************************************
2689 Iterator initialization
2690 ***********************************************************************/
2692 /* Initialize IT for displaying current_buffer in window W, starting
2693 at character position CHARPOS. CHARPOS < 0 means that no buffer
2694 position is specified which is useful when the iterator is assigned
2695 a position later. BYTEPOS is the byte position corresponding to
2698 If ROW is not null, calls to produce_glyphs with IT as parameter
2699 will produce glyphs in that row.
2701 BASE_FACE_ID is the id of a base face to use. It must be one of
2702 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2703 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2704 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2706 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2707 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2708 will be initialized to use the corresponding mode line glyph row of
2709 the desired matrix of W. */
2712 init_iterator (struct it
*it
, struct window
*w
,
2713 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2714 struct glyph_row
*row
, enum face_id base_face_id
)
2716 enum face_id remapped_base_face_id
= base_face_id
;
2718 /* Some precondition checks. */
2719 eassert (w
!= NULL
&& it
!= NULL
);
2720 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2723 /* If face attributes have been changed since the last redisplay,
2724 free realized faces now because they depend on face definitions
2725 that might have changed. Don't free faces while there might be
2726 desired matrices pending which reference these faces. */
2727 if (face_change_count
&& !inhibit_free_realized_faces
)
2729 face_change_count
= 0;
2730 free_all_realized_faces (Qnil
);
2733 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2734 if (! NILP (Vface_remapping_alist
))
2735 remapped_base_face_id
2736 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2738 /* Use one of the mode line rows of W's desired matrix if
2742 if (base_face_id
== MODE_LINE_FACE_ID
2743 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2744 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2745 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2746 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2750 memset (it
, 0, sizeof *it
);
2751 it
->current
.overlay_string_index
= -1;
2752 it
->current
.dpvec_index
= -1;
2753 it
->base_face_id
= remapped_base_face_id
;
2755 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2756 it
->paragraph_embedding
= L2R
;
2757 it
->bidi_it
.string
.lstring
= Qnil
;
2758 it
->bidi_it
.string
.s
= NULL
;
2759 it
->bidi_it
.string
.bufpos
= 0;
2762 /* The window in which we iterate over current_buffer: */
2763 XSETWINDOW (it
->window
, w
);
2765 it
->f
= XFRAME (w
->frame
);
2769 /* Extra space between lines (on window systems only). */
2770 if (base_face_id
== DEFAULT_FACE_ID
2771 && FRAME_WINDOW_P (it
->f
))
2773 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2774 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2775 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2776 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2777 * FRAME_LINE_HEIGHT (it
->f
));
2778 else if (it
->f
->extra_line_spacing
> 0)
2779 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2780 it
->max_extra_line_spacing
= 0;
2783 /* If realized faces have been removed, e.g. because of face
2784 attribute changes of named faces, recompute them. When running
2785 in batch mode, the face cache of the initial frame is null. If
2786 we happen to get called, make a dummy face cache. */
2787 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2788 init_frame_faces (it
->f
);
2789 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2790 recompute_basic_faces (it
->f
);
2792 /* Current value of the `slice', `space-width', and 'height' properties. */
2793 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2794 it
->space_width
= Qnil
;
2795 it
->font_height
= Qnil
;
2796 it
->override_ascent
= -1;
2798 /* Are control characters displayed as `^C'? */
2799 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2801 /* -1 means everything between a CR and the following line end
2802 is invisible. >0 means lines indented more than this value are
2804 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2806 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2808 : (!NILP (BVAR (current_buffer
, selective_display
))
2810 it
->selective_display_ellipsis_p
2811 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2813 /* Display table to use. */
2814 it
->dp
= window_display_table (w
);
2816 /* Are multibyte characters enabled in current_buffer? */
2817 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2819 /* Get the position at which the redisplay_end_trigger hook should
2820 be run, if it is to be run at all. */
2821 if (MARKERP (w
->redisplay_end_trigger
)
2822 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2823 it
->redisplay_end_trigger_charpos
2824 = marker_position (w
->redisplay_end_trigger
);
2825 else if (INTEGERP (w
->redisplay_end_trigger
))
2826 it
->redisplay_end_trigger_charpos
2827 = clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
),
2830 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2832 /* Are lines in the display truncated? */
2833 if (base_face_id
!= DEFAULT_FACE_ID
2835 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2836 && ((!NILP (Vtruncate_partial_width_windows
)
2837 && !INTEGERP (Vtruncate_partial_width_windows
))
2838 || (INTEGERP (Vtruncate_partial_width_windows
)
2839 /* PXW: Shall we do something about this? */
2840 && (WINDOW_TOTAL_COLS (it
->w
)
2841 < XINT (Vtruncate_partial_width_windows
))))))
2842 it
->line_wrap
= TRUNCATE
;
2843 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2844 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2845 ? WINDOW_WRAP
: WORD_WRAP
;
2847 it
->line_wrap
= TRUNCATE
;
2849 /* Get dimensions of truncation and continuation glyphs. These are
2850 displayed as fringe bitmaps under X, but we need them for such
2851 frames when the fringes are turned off. But leave the dimensions
2852 zero for tooltip frames, as these glyphs look ugly there and also
2853 sabotage calculations of tooltip dimensions in x-show-tip. */
2854 #ifdef HAVE_WINDOW_SYSTEM
2855 if (!(FRAME_WINDOW_P (it
->f
)
2856 && FRAMEP (tip_frame
)
2857 && it
->f
== XFRAME (tip_frame
)))
2860 if (it
->line_wrap
== TRUNCATE
)
2862 /* We will need the truncation glyph. */
2863 eassert (it
->glyph_row
== NULL
);
2864 produce_special_glyphs (it
, IT_TRUNCATION
);
2865 it
->truncation_pixel_width
= it
->pixel_width
;
2869 /* We will need the continuation glyph. */
2870 eassert (it
->glyph_row
== NULL
);
2871 produce_special_glyphs (it
, IT_CONTINUATION
);
2872 it
->continuation_pixel_width
= it
->pixel_width
;
2876 /* Reset these values to zero because the produce_special_glyphs
2877 above has changed them. */
2878 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2879 it
->phys_ascent
= it
->phys_descent
= 0;
2881 /* Set this after getting the dimensions of truncation and
2882 continuation glyphs, so that we don't produce glyphs when calling
2883 produce_special_glyphs, above. */
2884 it
->glyph_row
= row
;
2885 it
->area
= TEXT_AREA
;
2887 /* Get the dimensions of the display area. The display area
2888 consists of the visible window area plus a horizontally scrolled
2889 part to the left of the window. All x-values are relative to the
2890 start of this total display area. */
2891 if (base_face_id
!= DEFAULT_FACE_ID
)
2893 /* Mode lines, menu bar in terminal frames. */
2894 it
->first_visible_x
= 0;
2895 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2900 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2901 it
->last_visible_x
= (it
->first_visible_x
2902 + window_box_width (w
, TEXT_AREA
));
2904 /* If we truncate lines, leave room for the truncation glyph(s) at
2905 the right margin. Otherwise, leave room for the continuation
2906 glyph(s). Done only if the window has no right fringe. */
2907 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
2909 if (it
->line_wrap
== TRUNCATE
)
2910 it
->last_visible_x
-= it
->truncation_pixel_width
;
2912 it
->last_visible_x
-= it
->continuation_pixel_width
;
2915 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2916 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2919 /* Leave room for a border glyph. */
2920 if (!FRAME_WINDOW_P (it
->f
)
2921 && !WINDOW_RIGHTMOST_P (it
->w
))
2922 it
->last_visible_x
-= 1;
2924 it
->last_visible_y
= window_text_bottom_y (w
);
2926 /* For mode lines and alike, arrange for the first glyph having a
2927 left box line if the face specifies a box. */
2928 if (base_face_id
!= DEFAULT_FACE_ID
)
2932 it
->face_id
= remapped_base_face_id
;
2934 /* If we have a boxed mode line, make the first character appear
2935 with a left box line. */
2936 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2937 if (face
&& face
->box
!= FACE_NO_BOX
)
2938 it
->start_of_box_run_p
= true;
2941 /* If a buffer position was specified, set the iterator there,
2942 getting overlays and face properties from that position. */
2943 if (charpos
>= BUF_BEG (current_buffer
))
2945 it
->stop_charpos
= charpos
;
2946 it
->end_charpos
= ZV
;
2947 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2948 IT_CHARPOS (*it
) = charpos
;
2949 IT_BYTEPOS (*it
) = bytepos
;
2951 /* We will rely on `reseat' to set this up properly, via
2952 handle_face_prop. */
2953 it
->face_id
= it
->base_face_id
;
2955 it
->start
= it
->current
;
2956 /* Do we need to reorder bidirectional text? Not if this is a
2957 unibyte buffer: by definition, none of the single-byte
2958 characters are strong R2L, so no reordering is needed. And
2959 bidi.c doesn't support unibyte buffers anyway. Also, don't
2960 reorder while we are loading loadup.el, since the tables of
2961 character properties needed for reordering are not yet
2965 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2968 /* If we are to reorder bidirectional text, init the bidi
2972 /* Since we don't know at this point whether there will be
2973 any R2L lines in the window, we reserve space for
2974 truncation/continuation glyphs even if only the left
2975 fringe is absent. */
2976 if (base_face_id
== DEFAULT_FACE_ID
2977 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
2978 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
2980 if (it
->line_wrap
== TRUNCATE
)
2981 it
->last_visible_x
-= it
->truncation_pixel_width
;
2983 it
->last_visible_x
-= it
->continuation_pixel_width
;
2985 /* Note the paragraph direction that this buffer wants to
2987 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2989 it
->paragraph_embedding
= L2R
;
2990 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2992 it
->paragraph_embedding
= R2L
;
2994 it
->paragraph_embedding
= NEUTRAL_DIR
;
2995 bidi_unshelve_cache (NULL
, 0);
2996 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
3000 /* Compute faces etc. */
3001 reseat (it
, it
->current
.pos
, 1);
3008 /* Initialize IT for the display of window W with window start POS. */
3011 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
3013 struct glyph_row
*row
;
3014 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
3016 row
= w
->desired_matrix
->rows
+ first_vpos
;
3017 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
3018 it
->first_vpos
= first_vpos
;
3020 /* Don't reseat to previous visible line start if current start
3021 position is in a string or image. */
3022 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
3024 int start_at_line_beg_p
;
3025 int first_y
= it
->current_y
;
3027 /* If window start is not at a line start, skip forward to POS to
3028 get the correct continuation lines width. */
3029 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3030 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3031 if (!start_at_line_beg_p
)
3035 reseat_at_previous_visible_line_start (it
);
3036 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3038 new_x
= it
->current_x
+ it
->pixel_width
;
3040 /* If lines are continued, this line may end in the middle
3041 of a multi-glyph character (e.g. a control character
3042 displayed as \003, or in the middle of an overlay
3043 string). In this case move_it_to above will not have
3044 taken us to the start of the continuation line but to the
3045 end of the continued line. */
3046 if (it
->current_x
> 0
3047 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3048 && (/* And glyph doesn't fit on the line. */
3049 new_x
> it
->last_visible_x
3050 /* Or it fits exactly and we're on a window
3052 || (new_x
== it
->last_visible_x
3053 && FRAME_WINDOW_P (it
->f
)
3054 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3055 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3056 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3058 if ((it
->current
.dpvec_index
>= 0
3059 || it
->current
.overlay_string_index
>= 0)
3060 /* If we are on a newline from a display vector or
3061 overlay string, then we are already at the end of
3062 a screen line; no need to go to the next line in
3063 that case, as this line is not really continued.
3064 (If we do go to the next line, C-e will not DTRT.) */
3067 set_iterator_to_next (it
, 1);
3068 move_it_in_display_line_to (it
, -1, -1, 0);
3071 it
->continuation_lines_width
+= it
->current_x
;
3073 /* If the character at POS is displayed via a display
3074 vector, move_it_to above stops at the final glyph of
3075 IT->dpvec. To make the caller redisplay that character
3076 again (a.k.a. start at POS), we need to reset the
3077 dpvec_index to the beginning of IT->dpvec. */
3078 else if (it
->current
.dpvec_index
>= 0)
3079 it
->current
.dpvec_index
= 0;
3081 /* We're starting a new display line, not affected by the
3082 height of the continued line, so clear the appropriate
3083 fields in the iterator structure. */
3084 it
->max_ascent
= it
->max_descent
= 0;
3085 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3087 it
->current_y
= first_y
;
3089 it
->current_x
= it
->hpos
= 0;
3095 /* Return 1 if POS is a position in ellipses displayed for invisible
3096 text. W is the window we display, for text property lookup. */
3099 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3101 Lisp_Object prop
, window
;
3103 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3105 /* If POS specifies a position in a display vector, this might
3106 be for an ellipsis displayed for invisible text. We won't
3107 get the iterator set up for delivering that ellipsis unless
3108 we make sure that it gets aware of the invisible text. */
3109 if (pos
->dpvec_index
>= 0
3110 && pos
->overlay_string_index
< 0
3111 && CHARPOS (pos
->string_pos
) < 0
3113 && (XSETWINDOW (window
, w
),
3114 prop
= Fget_char_property (make_number (charpos
),
3115 Qinvisible
, window
),
3116 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3118 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3120 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3127 /* Initialize IT for stepping through current_buffer in window W,
3128 starting at position POS that includes overlay string and display
3129 vector/ control character translation position information. Value
3130 is zero if there are overlay strings with newlines at POS. */
3133 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3135 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3136 int i
, overlay_strings_with_newlines
= 0;
3138 /* If POS specifies a position in a display vector, this might
3139 be for an ellipsis displayed for invisible text. We won't
3140 get the iterator set up for delivering that ellipsis unless
3141 we make sure that it gets aware of the invisible text. */
3142 if (in_ellipses_for_invisible_text_p (pos
, w
))
3148 /* Keep in mind: the call to reseat in init_iterator skips invisible
3149 text, so we might end up at a position different from POS. This
3150 is only a problem when POS is a row start after a newline and an
3151 overlay starts there with an after-string, and the overlay has an
3152 invisible property. Since we don't skip invisible text in
3153 display_line and elsewhere immediately after consuming the
3154 newline before the row start, such a POS will not be in a string,
3155 but the call to init_iterator below will move us to the
3157 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3159 /* This only scans the current chunk -- it should scan all chunks.
3160 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3161 to 16 in 22.1 to make this a lesser problem. */
3162 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3164 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3165 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3167 while (s
< e
&& *s
!= '\n')
3172 overlay_strings_with_newlines
= 1;
3177 /* If position is within an overlay string, set up IT to the right
3179 if (pos
->overlay_string_index
>= 0)
3183 /* If the first overlay string happens to have a `display'
3184 property for an image, the iterator will be set up for that
3185 image, and we have to undo that setup first before we can
3186 correct the overlay string index. */
3187 if (it
->method
== GET_FROM_IMAGE
)
3190 /* We already have the first chunk of overlay strings in
3191 IT->overlay_strings. Load more until the one for
3192 pos->overlay_string_index is in IT->overlay_strings. */
3193 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3195 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3196 it
->current
.overlay_string_index
= 0;
3199 load_overlay_strings (it
, 0);
3200 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3204 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3205 relative_index
= (it
->current
.overlay_string_index
3206 % OVERLAY_STRING_CHUNK_SIZE
);
3207 it
->string
= it
->overlay_strings
[relative_index
];
3208 eassert (STRINGP (it
->string
));
3209 it
->current
.string_pos
= pos
->string_pos
;
3210 it
->method
= GET_FROM_STRING
;
3211 it
->end_charpos
= SCHARS (it
->string
);
3212 /* Set up the bidi iterator for this overlay string. */
3215 it
->bidi_it
.string
.lstring
= it
->string
;
3216 it
->bidi_it
.string
.s
= NULL
;
3217 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3218 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3219 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3220 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3221 it
->bidi_it
.w
= it
->w
;
3222 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3223 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3225 /* Synchronize the state of the bidi iterator with
3226 pos->string_pos. For any string position other than
3227 zero, this will be done automagically when we resume
3228 iteration over the string and get_visually_first_element
3229 is called. But if string_pos is zero, and the string is
3230 to be reordered for display, we need to resync manually,
3231 since it could be that the iteration state recorded in
3232 pos ended at string_pos of 0 moving backwards in string. */
3233 if (CHARPOS (pos
->string_pos
) == 0)
3235 get_visually_first_element (it
);
3236 if (IT_STRING_CHARPOS (*it
) != 0)
3239 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3240 bidi_move_to_visually_next (&it
->bidi_it
);
3241 } while (it
->bidi_it
.charpos
!= 0);
3243 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3244 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3248 if (CHARPOS (pos
->string_pos
) >= 0)
3250 /* Recorded position is not in an overlay string, but in another
3251 string. This can only be a string from a `display' property.
3252 IT should already be filled with that string. */
3253 it
->current
.string_pos
= pos
->string_pos
;
3254 eassert (STRINGP (it
->string
));
3256 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3257 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3260 /* Restore position in display vector translations, control
3261 character translations or ellipses. */
3262 if (pos
->dpvec_index
>= 0)
3264 if (it
->dpvec
== NULL
)
3265 get_next_display_element (it
);
3266 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3267 it
->current
.dpvec_index
= pos
->dpvec_index
;
3271 return !overlay_strings_with_newlines
;
3275 /* Initialize IT for stepping through current_buffer in window W
3276 starting at ROW->start. */
3279 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3281 init_from_display_pos (it
, w
, &row
->start
);
3282 it
->start
= row
->start
;
3283 it
->continuation_lines_width
= row
->continuation_lines_width
;
3288 /* Initialize IT for stepping through current_buffer in window W
3289 starting in the line following ROW, i.e. starting at ROW->end.
3290 Value is zero if there are overlay strings with newlines at ROW's
3294 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3298 if (init_from_display_pos (it
, w
, &row
->end
))
3300 if (row
->continued_p
)
3301 it
->continuation_lines_width
3302 = row
->continuation_lines_width
+ row
->pixel_width
;
3313 /***********************************************************************
3315 ***********************************************************************/
3317 /* Called when IT reaches IT->stop_charpos. Handle text property and
3318 overlay changes. Set IT->stop_charpos to the next position where
3322 handle_stop (struct it
*it
)
3324 enum prop_handled handled
;
3325 int handle_overlay_change_p
;
3329 it
->current
.dpvec_index
= -1;
3330 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3331 it
->ignore_overlay_strings_at_pos_p
= 0;
3334 /* Use face of preceding text for ellipsis (if invisible) */
3335 if (it
->selective_display_ellipsis_p
)
3336 it
->saved_face_id
= it
->face_id
;
3338 /* Here's the description of the semantics of, and the logic behind,
3339 the various HANDLED_* statuses:
3341 HANDLED_NORMALLY means the handler did its job, and the loop
3342 should proceed to calling the next handler in order.
3344 HANDLED_RECOMPUTE_PROPS means the handler caused a significant
3345 change in the properties and overlays at current position, so the
3346 loop should be restarted, to re-invoke the handlers that were
3347 already called. This happens when fontification-functions were
3348 called by handle_fontified_prop, and actually fontified
3349 something. Another case where HANDLED_RECOMPUTE_PROPS is
3350 returned is when we discover overlay strings that need to be
3351 displayed right away. The loop below will continue for as long
3352 as the status is HANDLED_RECOMPUTE_PROPS.
3354 HANDLED_RETURN means return immediately to the caller, to
3355 continue iteration without calling any further handlers. This is
3356 used when we need to act on some property right away, for example
3357 when we need to display the ellipsis or a replacing display
3358 property, such as display string or image.
3360 HANDLED_OVERLAY_STRING_CONSUMED means an overlay string was just
3361 consumed, and the handler switched to the next overlay string.
3362 This signals the loop below to refrain from looking for more
3363 overlays before all the overlay strings of the current overlay
3366 Some of the handlers called by the loop push the iterator state
3367 onto the stack (see 'push_it'), and arrange for the iteration to
3368 continue with another object, such as an image, a display string,
3369 or an overlay string. In most such cases, it->stop_charpos is
3370 set to the first character of the string, so that when the
3371 iteration resumes, this function will immediately be called
3372 again, to examine the properties at the beginning of the string.
3374 When a display or overlay string is exhausted, the iterator state
3375 is popped (see 'pop_it'), and iteration continues with the
3376 previous object. Again, in many such cases this function is
3377 called again to find the next position where properties might
3382 handled
= HANDLED_NORMALLY
;
3384 /* Call text property handlers. */
3385 for (p
= it_props
; p
->handler
; ++p
)
3387 handled
= p
->handler (it
);
3389 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3391 else if (handled
== HANDLED_RETURN
)
3393 /* We still want to show before and after strings from
3394 overlays even if the actual buffer text is replaced. */
3395 if (!handle_overlay_change_p
3397 /* Don't call get_overlay_strings_1 if we already
3398 have overlay strings loaded, because doing so
3399 will load them again and push the iterator state
3400 onto the stack one more time, which is not
3401 expected by the rest of the code that processes
3403 || (it
->current
.overlay_string_index
< 0
3404 ? !get_overlay_strings_1 (it
, 0, 0)
3408 setup_for_ellipsis (it
, 0);
3409 /* When handling a display spec, we might load an
3410 empty string. In that case, discard it here. We
3411 used to discard it in handle_single_display_spec,
3412 but that causes get_overlay_strings_1, above, to
3413 ignore overlay strings that we must check. */
3414 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3418 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3422 it
->ignore_overlay_strings_at_pos_p
= true;
3423 it
->string_from_display_prop_p
= 0;
3424 it
->from_disp_prop_p
= 0;
3425 handle_overlay_change_p
= 0;
3427 handled
= HANDLED_RECOMPUTE_PROPS
;
3430 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3431 handle_overlay_change_p
= 0;
3434 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3436 /* Don't check for overlay strings below when set to deliver
3437 characters from a display vector. */
3438 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3439 handle_overlay_change_p
= 0;
3441 /* Handle overlay changes.
3442 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3443 if it finds overlays. */
3444 if (handle_overlay_change_p
)
3445 handled
= handle_overlay_change (it
);
3450 setup_for_ellipsis (it
, 0);
3454 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3456 /* Determine where to stop next. */
3457 if (handled
== HANDLED_NORMALLY
)
3458 compute_stop_pos (it
);
3462 /* Compute IT->stop_charpos from text property and overlay change
3463 information for IT's current position. */
3466 compute_stop_pos (struct it
*it
)
3468 register INTERVAL iv
, next_iv
;
3469 Lisp_Object object
, limit
, position
;
3470 ptrdiff_t charpos
, bytepos
;
3472 if (STRINGP (it
->string
))
3474 /* Strings are usually short, so don't limit the search for
3476 it
->stop_charpos
= it
->end_charpos
;
3477 object
= it
->string
;
3479 charpos
= IT_STRING_CHARPOS (*it
);
3480 bytepos
= IT_STRING_BYTEPOS (*it
);
3486 /* If end_charpos is out of range for some reason, such as a
3487 misbehaving display function, rationalize it (Bug#5984). */
3488 if (it
->end_charpos
> ZV
)
3489 it
->end_charpos
= ZV
;
3490 it
->stop_charpos
= it
->end_charpos
;
3492 /* If next overlay change is in front of the current stop pos
3493 (which is IT->end_charpos), stop there. Note: value of
3494 next_overlay_change is point-max if no overlay change
3496 charpos
= IT_CHARPOS (*it
);
3497 bytepos
= IT_BYTEPOS (*it
);
3498 pos
= next_overlay_change (charpos
);
3499 if (pos
< it
->stop_charpos
)
3500 it
->stop_charpos
= pos
;
3502 /* Set up variables for computing the stop position from text
3503 property changes. */
3504 XSETBUFFER (object
, current_buffer
);
3505 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3508 /* Get the interval containing IT's position. Value is a null
3509 interval if there isn't such an interval. */
3510 position
= make_number (charpos
);
3511 iv
= validate_interval_range (object
, &position
, &position
, 0);
3514 Lisp_Object values_here
[LAST_PROP_IDX
];
3517 /* Get properties here. */
3518 for (p
= it_props
; p
->handler
; ++p
)
3519 values_here
[p
->idx
] = textget (iv
->plist
, make_lisp_symbol (p
->name
));
3521 /* Look for an interval following iv that has different
3523 for (next_iv
= next_interval (iv
);
3526 || XFASTINT (limit
) > next_iv
->position
));
3527 next_iv
= next_interval (next_iv
))
3529 for (p
= it_props
; p
->handler
; ++p
)
3531 Lisp_Object new_value
= textget (next_iv
->plist
,
3532 make_lisp_symbol (p
->name
));
3533 if (!EQ (values_here
[p
->idx
], new_value
))
3543 if (INTEGERP (limit
)
3544 && next_iv
->position
>= XFASTINT (limit
))
3545 /* No text property change up to limit. */
3546 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3548 /* Text properties change in next_iv. */
3549 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3553 if (it
->cmp_it
.id
< 0)
3555 ptrdiff_t stoppos
= it
->end_charpos
;
3557 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3559 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3560 stoppos
, it
->string
);
3563 eassert (STRINGP (it
->string
)
3564 || (it
->stop_charpos
>= BEGV
3565 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3569 /* Return the position of the next overlay change after POS in
3570 current_buffer. Value is point-max if no overlay change
3571 follows. This is like `next-overlay-change' but doesn't use
3575 next_overlay_change (ptrdiff_t pos
)
3577 ptrdiff_t i
, noverlays
;
3579 Lisp_Object
*overlays
;
3582 /* Get all overlays at the given position. */
3583 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3585 /* If any of these overlays ends before endpos,
3586 use its ending point instead. */
3587 for (i
= 0; i
< noverlays
; ++i
)
3592 oend
= OVERLAY_END (overlays
[i
]);
3593 oendpos
= OVERLAY_POSITION (oend
);
3594 endpos
= min (endpos
, oendpos
);
3601 /* How many characters forward to search for a display property or
3602 display string. Searching too far forward makes the bidi display
3603 sluggish, especially in small windows. */
3604 #define MAX_DISP_SCAN 250
3606 /* Return the character position of a display string at or after
3607 position specified by POSITION. If no display string exists at or
3608 after POSITION, return ZV. A display string is either an overlay
3609 with `display' property whose value is a string, or a `display'
3610 text property whose value is a string. STRING is data about the
3611 string to iterate; if STRING->lstring is nil, we are iterating a
3612 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3613 on a GUI frame. DISP_PROP is set to zero if we searched
3614 MAX_DISP_SCAN characters forward without finding any display
3615 strings, non-zero otherwise. It is set to 2 if the display string
3616 uses any kind of `(space ...)' spec that will produce a stretch of
3617 white space in the text area. */
3619 compute_display_string_pos (struct text_pos
*position
,
3620 struct bidi_string_data
*string
,
3622 int frame_window_p
, int *disp_prop
)
3624 /* OBJECT = nil means current buffer. */
3625 Lisp_Object object
, object1
;
3626 Lisp_Object pos
, spec
, limpos
;
3627 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3628 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3629 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3630 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3632 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3633 struct text_pos tpos
;
3636 if (string
&& STRINGP (string
->lstring
))
3637 object1
= object
= string
->lstring
;
3638 else if (w
&& !string_p
)
3640 XSETWINDOW (object
, w
);
3644 object1
= object
= Qnil
;
3649 /* We don't support display properties whose values are strings
3650 that have display string properties. */
3651 || string
->from_disp_str
3652 /* C strings cannot have display properties. */
3653 || (string
->s
&& !STRINGP (object
)))
3659 /* If the character at CHARPOS is where the display string begins,
3661 pos
= make_number (charpos
);
3662 if (STRINGP (object
))
3663 bufpos
= string
->bufpos
;
3667 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3669 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3672 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3680 /* Look forward for the first character with a `display' property
3681 that will replace the underlying text when displayed. */
3682 limpos
= make_number (lim
);
3684 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3685 CHARPOS (tpos
) = XFASTINT (pos
);
3686 if (CHARPOS (tpos
) >= lim
)
3691 if (STRINGP (object
))
3692 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3694 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3695 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3696 if (!STRINGP (object
))
3697 bufpos
= CHARPOS (tpos
);
3698 } while (NILP (spec
)
3699 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3700 bufpos
, frame_window_p
)));
3704 return CHARPOS (tpos
);
3707 /* Return the character position of the end of the display string that
3708 started at CHARPOS. If there's no display string at CHARPOS,
3709 return -1. A display string is either an overlay with `display'
3710 property whose value is a string or a `display' text property whose
3711 value is a string. */
3713 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3715 /* OBJECT = nil means current buffer. */
3716 Lisp_Object object
=
3717 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3718 Lisp_Object pos
= make_number (charpos
);
3720 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3722 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3725 /* It could happen that the display property or overlay was removed
3726 since we found it in compute_display_string_pos above. One way
3727 this can happen is if JIT font-lock was called (through
3728 handle_fontified_prop), and jit-lock-functions remove text
3729 properties or overlays from the portion of buffer that includes
3730 CHARPOS. Muse mode is known to do that, for example. In this
3731 case, we return -1 to the caller, to signal that no display
3732 string is actually present at CHARPOS. See bidi_fetch_char for
3733 how this is handled.
3735 An alternative would be to never look for display properties past
3736 it->stop_charpos. But neither compute_display_string_pos nor
3737 bidi_fetch_char that calls it know or care where the next
3739 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3742 /* Look forward for the first character where the `display' property
3744 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3746 return XFASTINT (pos
);
3751 /***********************************************************************
3753 ***********************************************************************/
3755 /* Handle changes in the `fontified' property of the current buffer by
3756 calling hook functions from Qfontification_functions to fontify
3759 static enum prop_handled
3760 handle_fontified_prop (struct it
*it
)
3762 Lisp_Object prop
, pos
;
3763 enum prop_handled handled
= HANDLED_NORMALLY
;
3765 if (!NILP (Vmemory_full
))
3768 /* Get the value of the `fontified' property at IT's current buffer
3769 position. (The `fontified' property doesn't have a special
3770 meaning in strings.) If the value is nil, call functions from
3771 Qfontification_functions. */
3772 if (!STRINGP (it
->string
)
3774 && !NILP (Vfontification_functions
)
3775 && !NILP (Vrun_hooks
)
3776 && (pos
= make_number (IT_CHARPOS (*it
)),
3777 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3778 /* Ignore the special cased nil value always present at EOB since
3779 no amount of fontifying will be able to change it. */
3780 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3782 ptrdiff_t count
= SPECPDL_INDEX ();
3784 struct buffer
*obuf
= current_buffer
;
3785 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3786 bool old_clip_changed
= current_buffer
->clip_changed
;
3788 val
= Vfontification_functions
;
3789 specbind (Qfontification_functions
, Qnil
);
3791 eassert (it
->end_charpos
== ZV
);
3793 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3794 safe_call1 (val
, pos
);
3797 Lisp_Object fns
, fn
;
3798 struct gcpro gcpro1
, gcpro2
;
3803 for (; CONSP (val
); val
= XCDR (val
))
3809 /* A value of t indicates this hook has a local
3810 binding; it means to run the global binding too.
3811 In a global value, t should not occur. If it
3812 does, we must ignore it to avoid an endless
3814 for (fns
= Fdefault_value (Qfontification_functions
);
3820 safe_call1 (fn
, pos
);
3824 safe_call1 (fn
, pos
);
3830 unbind_to (count
, Qnil
);
3832 /* Fontification functions routinely call `save-restriction'.
3833 Normally, this tags clip_changed, which can confuse redisplay
3834 (see discussion in Bug#6671). Since we don't perform any
3835 special handling of fontification changes in the case where
3836 `save-restriction' isn't called, there's no point doing so in
3837 this case either. So, if the buffer's restrictions are
3838 actually left unchanged, reset clip_changed. */
3839 if (obuf
== current_buffer
)
3841 if (begv
== BEGV
&& zv
== ZV
)
3842 current_buffer
->clip_changed
= old_clip_changed
;
3844 /* There isn't much we can reasonably do to protect against
3845 misbehaving fontification, but here's a fig leaf. */
3846 else if (BUFFER_LIVE_P (obuf
))
3847 set_buffer_internal_1 (obuf
);
3849 /* The fontification code may have added/removed text.
3850 It could do even a lot worse, but let's at least protect against
3851 the most obvious case where only the text past `pos' gets changed',
3852 as is/was done in grep.el where some escapes sequences are turned
3853 into face properties (bug#7876). */
3854 it
->end_charpos
= ZV
;
3856 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3857 something. This avoids an endless loop if they failed to
3858 fontify the text for which reason ever. */
3859 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3860 handled
= HANDLED_RECOMPUTE_PROPS
;
3868 /***********************************************************************
3870 ***********************************************************************/
3872 /* Set up iterator IT from face properties at its current position.
3873 Called from handle_stop. */
3875 static enum prop_handled
3876 handle_face_prop (struct it
*it
)
3879 ptrdiff_t next_stop
;
3881 if (!STRINGP (it
->string
))
3884 = face_at_buffer_position (it
->w
,
3888 + TEXT_PROP_DISTANCE_LIMIT
),
3889 0, it
->base_face_id
);
3891 /* Is this a start of a run of characters with box face?
3892 Caveat: this can be called for a freshly initialized
3893 iterator; face_id is -1 in this case. We know that the new
3894 face will not change until limit, i.e. if the new face has a
3895 box, all characters up to limit will have one. But, as
3896 usual, we don't know whether limit is really the end. */
3897 if (new_face_id
!= it
->face_id
)
3899 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3900 /* If it->face_id is -1, old_face below will be NULL, see
3901 the definition of FACE_FROM_ID. This will happen if this
3902 is the initial call that gets the face. */
3903 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3905 /* If the value of face_id of the iterator is -1, we have to
3906 look in front of IT's position and see whether there is a
3907 face there that's different from new_face_id. */
3908 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3910 int prev_face_id
= face_before_it_pos (it
);
3912 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3915 /* If the new face has a box, but the old face does not,
3916 this is the start of a run of characters with box face,
3917 i.e. this character has a shadow on the left side. */
3918 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3919 && (old_face
== NULL
|| !old_face
->box
));
3920 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3928 Lisp_Object from_overlay
3929 = (it
->current
.overlay_string_index
>= 0
3930 ? it
->string_overlays
[it
->current
.overlay_string_index
3931 % OVERLAY_STRING_CHUNK_SIZE
]
3934 /* See if we got to this string directly or indirectly from
3935 an overlay property. That includes the before-string or
3936 after-string of an overlay, strings in display properties
3937 provided by an overlay, their text properties, etc.
3939 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3940 if (! NILP (from_overlay
))
3941 for (i
= it
->sp
- 1; i
>= 0; i
--)
3943 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3945 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3946 % OVERLAY_STRING_CHUNK_SIZE
];
3947 else if (! NILP (it
->stack
[i
].from_overlay
))
3948 from_overlay
= it
->stack
[i
].from_overlay
;
3950 if (!NILP (from_overlay
))
3954 if (! NILP (from_overlay
))
3956 bufpos
= IT_CHARPOS (*it
);
3957 /* For a string from an overlay, the base face depends
3958 only on text properties and ignores overlays. */
3960 = face_for_overlay_string (it
->w
,
3964 + TEXT_PROP_DISTANCE_LIMIT
),
3972 /* For strings from a `display' property, use the face at
3973 IT's current buffer position as the base face to merge
3974 with, so that overlay strings appear in the same face as
3975 surrounding text, unless they specify their own faces.
3976 For strings from wrap-prefix and line-prefix properties,
3977 use the default face, possibly remapped via
3978 Vface_remapping_alist. */
3979 /* Note that the fact that we use the face at _buffer_
3980 position means that a 'display' property on an overlay
3981 string will not inherit the face of that overlay string,
3982 but will instead revert to the face of buffer text
3983 covered by the overlay. This is visible, e.g., when the
3984 overlay specifies a box face, but neither the buffer nor
3985 the display string do. This sounds like a design bug,
3986 but Emacs always did that since v21.1, so changing that
3987 might be a big deal. */
3988 base_face_id
= it
->string_from_prefix_prop_p
3989 ? (!NILP (Vface_remapping_alist
)
3990 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3992 : underlying_face_id (it
);
3995 new_face_id
= face_at_string_position (it
->w
,
3997 IT_STRING_CHARPOS (*it
),
4002 /* Is this a start of a run of characters with box? Caveat:
4003 this can be called for a freshly allocated iterator; face_id
4004 is -1 is this case. We know that the new face will not
4005 change until the next check pos, i.e. if the new face has a
4006 box, all characters up to that position will have a
4007 box. But, as usual, we don't know whether that position
4008 is really the end. */
4009 if (new_face_id
!= it
->face_id
)
4011 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
4012 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4014 /* If new face has a box but old face hasn't, this is the
4015 start of a run of characters with box, i.e. it has a
4016 shadow on the left side. */
4017 it
->start_of_box_run_p
4018 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
4019 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
4023 it
->face_id
= new_face_id
;
4024 return HANDLED_NORMALLY
;
4028 /* Return the ID of the face ``underlying'' IT's current position,
4029 which is in a string. If the iterator is associated with a
4030 buffer, return the face at IT's current buffer position.
4031 Otherwise, use the iterator's base_face_id. */
4034 underlying_face_id (struct it
*it
)
4036 int face_id
= it
->base_face_id
, i
;
4038 eassert (STRINGP (it
->string
));
4040 for (i
= it
->sp
- 1; i
>= 0; --i
)
4041 if (NILP (it
->stack
[i
].string
))
4042 face_id
= it
->stack
[i
].face_id
;
4048 /* Compute the face one character before or after the current position
4049 of IT, in the visual order. BEFORE_P non-zero means get the face
4050 in front (to the left in L2R paragraphs, to the right in R2L
4051 paragraphs) of IT's screen position. Value is the ID of the face. */
4054 face_before_or_after_it_pos (struct it
*it
, int before_p
)
4057 ptrdiff_t next_check_charpos
;
4059 void *it_copy_data
= NULL
;
4061 eassert (it
->s
== NULL
);
4063 if (STRINGP (it
->string
))
4065 ptrdiff_t bufpos
, charpos
;
4068 /* No face change past the end of the string (for the case
4069 we are padding with spaces). No face change before the
4071 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
4072 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4077 /* Set charpos to the position before or after IT's current
4078 position, in the logical order, which in the non-bidi
4079 case is the same as the visual order. */
4081 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4082 else if (it
->what
== IT_COMPOSITION
)
4083 /* For composition, we must check the character after the
4085 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4087 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4093 /* With bidi iteration, the character before the current
4094 in the visual order cannot be found by simple
4095 iteration, because "reverse" reordering is not
4096 supported. Instead, we need to use the move_it_*
4097 family of functions. */
4098 /* Ignore face changes before the first visible
4099 character on this display line. */
4100 if (it
->current_x
<= it
->first_visible_x
)
4102 SAVE_IT (it_copy
, *it
, it_copy_data
);
4103 /* Implementation note: Since move_it_in_display_line
4104 works in the iterator geometry, and thinks the first
4105 character is always the leftmost, even in R2L lines,
4106 we don't need to distinguish between the R2L and L2R
4108 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4109 it_copy
.current_x
- 1, MOVE_TO_X
);
4110 charpos
= IT_STRING_CHARPOS (it_copy
);
4111 RESTORE_IT (it
, it
, it_copy_data
);
4115 /* Set charpos to the string position of the character
4116 that comes after IT's current position in the visual
4118 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4122 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4124 charpos
= it_copy
.bidi_it
.charpos
;
4127 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4129 if (it
->current
.overlay_string_index
>= 0)
4130 bufpos
= IT_CHARPOS (*it
);
4134 base_face_id
= underlying_face_id (it
);
4136 /* Get the face for ASCII, or unibyte. */
4137 face_id
= face_at_string_position (it
->w
,
4141 &next_check_charpos
,
4144 /* Correct the face for charsets different from ASCII. Do it
4145 for the multibyte case only. The face returned above is
4146 suitable for unibyte text if IT->string is unibyte. */
4147 if (STRING_MULTIBYTE (it
->string
))
4149 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4150 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4152 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4154 c
= string_char_and_length (p
, &len
);
4155 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4160 struct text_pos pos
;
4162 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4163 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4166 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4167 pos
= it
->current
.pos
;
4172 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4175 if (it
->what
== IT_COMPOSITION
)
4177 /* For composition, we must check the position after
4179 pos
.charpos
+= it
->cmp_it
.nchars
;
4180 pos
.bytepos
+= it
->len
;
4183 INC_TEXT_POS (pos
, it
->multibyte_p
);
4190 /* With bidi iteration, the character before the current
4191 in the visual order cannot be found by simple
4192 iteration, because "reverse" reordering is not
4193 supported. Instead, we need to use the move_it_*
4194 family of functions. */
4195 /* Ignore face changes before the first visible
4196 character on this display line. */
4197 if (it
->current_x
<= it
->first_visible_x
)
4199 SAVE_IT (it_copy
, *it
, it_copy_data
);
4200 /* Implementation note: Since move_it_in_display_line
4201 works in the iterator geometry, and thinks the first
4202 character is always the leftmost, even in R2L lines,
4203 we don't need to distinguish between the R2L and L2R
4205 move_it_in_display_line (&it_copy
, ZV
,
4206 it_copy
.current_x
- 1, MOVE_TO_X
);
4207 pos
= it_copy
.current
.pos
;
4208 RESTORE_IT (it
, it
, it_copy_data
);
4212 /* Set charpos to the buffer position of the character
4213 that comes after IT's current position in the visual
4215 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4219 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4222 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4225 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4227 /* Determine face for CHARSET_ASCII, or unibyte. */
4228 face_id
= face_at_buffer_position (it
->w
,
4230 &next_check_charpos
,
4233 /* Correct the face for charsets different from ASCII. Do it
4234 for the multibyte case only. The face returned above is
4235 suitable for unibyte text if current_buffer is unibyte. */
4236 if (it
->multibyte_p
)
4238 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4239 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4240 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4249 /***********************************************************************
4251 ***********************************************************************/
4253 /* Set up iterator IT from invisible properties at its current
4254 position. Called from handle_stop. */
4256 static enum prop_handled
4257 handle_invisible_prop (struct it
*it
)
4259 enum prop_handled handled
= HANDLED_NORMALLY
;
4263 if (STRINGP (it
->string
))
4265 Lisp_Object end_charpos
, limit
, charpos
;
4267 /* Get the value of the invisible text property at the
4268 current position. Value will be nil if there is no such
4270 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4271 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4272 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4274 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4276 /* Record whether we have to display an ellipsis for the
4278 int display_ellipsis_p
= (invis_p
== 2);
4279 ptrdiff_t len
, endpos
;
4281 handled
= HANDLED_RECOMPUTE_PROPS
;
4283 /* Get the position at which the next visible text can be
4284 found in IT->string, if any. */
4285 endpos
= len
= SCHARS (it
->string
);
4286 XSETINT (limit
, len
);
4289 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4291 if (INTEGERP (end_charpos
))
4293 endpos
= XFASTINT (end_charpos
);
4294 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4295 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4297 display_ellipsis_p
= true;
4300 while (invis_p
&& endpos
< len
);
4302 if (display_ellipsis_p
)
4303 it
->ellipsis_p
= true;
4307 /* Text at END_CHARPOS is visible. Move IT there. */
4308 struct text_pos old
;
4311 old
= it
->current
.string_pos
;
4312 oldpos
= CHARPOS (old
);
4315 if (it
->bidi_it
.first_elt
4316 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4317 bidi_paragraph_init (it
->paragraph_embedding
,
4319 /* Bidi-iterate out of the invisible text. */
4322 bidi_move_to_visually_next (&it
->bidi_it
);
4324 while (oldpos
<= it
->bidi_it
.charpos
4325 && it
->bidi_it
.charpos
< endpos
);
4327 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4328 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4329 if (IT_CHARPOS (*it
) >= endpos
)
4330 it
->prev_stop
= endpos
;
4334 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4335 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4340 /* The rest of the string is invisible. If this is an
4341 overlay string, proceed with the next overlay string
4342 or whatever comes and return a character from there. */
4343 if (it
->current
.overlay_string_index
>= 0
4344 && !display_ellipsis_p
)
4346 next_overlay_string (it
);
4347 /* Don't check for overlay strings when we just
4348 finished processing them. */
4349 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4353 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4354 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4361 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4362 Lisp_Object pos
, overlay
;
4364 /* First of all, is there invisible text at this position? */
4365 tem
= start_charpos
= IT_CHARPOS (*it
);
4366 pos
= make_number (tem
);
4367 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4369 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4371 /* If we are on invisible text, skip over it. */
4372 if (invis_p
&& start_charpos
< it
->end_charpos
)
4374 /* Record whether we have to display an ellipsis for the
4376 int display_ellipsis_p
= invis_p
== 2;
4378 handled
= HANDLED_RECOMPUTE_PROPS
;
4380 /* Loop skipping over invisible text. The loop is left at
4381 ZV or with IT on the first char being visible again. */
4384 /* Try to skip some invisible text. Return value is the
4385 position reached which can be equal to where we start
4386 if there is nothing invisible there. This skips both
4387 over invisible text properties and overlays with
4388 invisible property. */
4389 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4391 /* If we skipped nothing at all we weren't at invisible
4392 text in the first place. If everything to the end of
4393 the buffer was skipped, end the loop. */
4394 if (newpos
== tem
|| newpos
>= ZV
)
4398 /* We skipped some characters but not necessarily
4399 all there are. Check if we ended up on visible
4400 text. Fget_char_property returns the property of
4401 the char before the given position, i.e. if we
4402 get invis_p = 0, this means that the char at
4403 newpos is visible. */
4404 pos
= make_number (newpos
);
4405 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4406 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4409 /* If we ended up on invisible text, proceed to
4410 skip starting with next_stop. */
4414 /* If there are adjacent invisible texts, don't lose the
4415 second one's ellipsis. */
4417 display_ellipsis_p
= true;
4421 /* The position newpos is now either ZV or on visible text. */
4424 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4426 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4428 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4430 /* If the invisible text ends on a newline or on a
4431 character after a newline, we can avoid the costly,
4432 character by character, bidi iteration to NEWPOS, and
4433 instead simply reseat the iterator there. That's
4434 because all bidi reordering information is tossed at
4435 the newline. This is a big win for modes that hide
4436 complete lines, like Outline, Org, etc. */
4437 if (on_newline
|| after_newline
)
4439 struct text_pos tpos
;
4440 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4442 SET_TEXT_POS (tpos
, newpos
, bpos
);
4443 reseat_1 (it
, tpos
, 0);
4444 /* If we reseat on a newline/ZV, we need to prep the
4445 bidi iterator for advancing to the next character
4446 after the newline/EOB, keeping the current paragraph
4447 direction (so that PRODUCE_GLYPHS does TRT wrt
4448 prepending/appending glyphs to a glyph row). */
4451 it
->bidi_it
.first_elt
= 0;
4452 it
->bidi_it
.paragraph_dir
= pdir
;
4453 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4454 it
->bidi_it
.nchars
= 1;
4455 it
->bidi_it
.ch_len
= 1;
4458 else /* Must use the slow method. */
4460 /* With bidi iteration, the region of invisible text
4461 could start and/or end in the middle of a
4462 non-base embedding level. Therefore, we need to
4463 skip invisible text using the bidi iterator,
4464 starting at IT's current position, until we find
4465 ourselves outside of the invisible text.
4466 Skipping invisible text _after_ bidi iteration
4467 avoids affecting the visual order of the
4468 displayed text when invisible properties are
4469 added or removed. */
4470 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4472 /* If we were `reseat'ed to a new paragraph,
4473 determine the paragraph base direction. We
4474 need to do it now because
4475 next_element_from_buffer may not have a
4476 chance to do it, if we are going to skip any
4477 text at the beginning, which resets the
4479 bidi_paragraph_init (it
->paragraph_embedding
,
4484 bidi_move_to_visually_next (&it
->bidi_it
);
4486 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4487 && it
->bidi_it
.charpos
< newpos
);
4488 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4489 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4490 /* If we overstepped NEWPOS, record its position in
4491 the iterator, so that we skip invisible text if
4492 later the bidi iteration lands us in the
4493 invisible region again. */
4494 if (IT_CHARPOS (*it
) >= newpos
)
4495 it
->prev_stop
= newpos
;
4500 IT_CHARPOS (*it
) = newpos
;
4501 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4504 /* If there are before-strings at the start of invisible
4505 text, and the text is invisible because of a text
4506 property, arrange to show before-strings because 20.x did
4507 it that way. (If the text is invisible because of an
4508 overlay property instead of a text property, this is
4509 already handled in the overlay code.) */
4511 && get_overlay_strings (it
, it
->stop_charpos
))
4513 handled
= HANDLED_RECOMPUTE_PROPS
;
4516 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4517 /* The call to get_overlay_strings above recomputes
4518 it->stop_charpos, but it only considers changes
4519 in properties and overlays beyond iterator's
4520 current position. This causes us to miss changes
4521 that happen exactly where the invisible property
4522 ended. So we play it safe here and force the
4523 iterator to check for potential stop positions
4524 immediately after the invisible text. Note that
4525 if get_overlay_strings returns non-zero, it
4526 normally also pushed the iterator stack, so we
4527 need to update the stop position in the slot
4528 below the current one. */
4529 it
->stack
[it
->sp
- 1].stop_charpos
4530 = CHARPOS (it
->stack
[it
->sp
- 1].current
.pos
);
4533 else if (display_ellipsis_p
)
4535 /* Make sure that the glyphs of the ellipsis will get
4536 correct `charpos' values. If we would not update
4537 it->position here, the glyphs would belong to the
4538 last visible character _before_ the invisible
4539 text, which confuses `set_cursor_from_row'.
4541 We use the last invisible position instead of the
4542 first because this way the cursor is always drawn on
4543 the first "." of the ellipsis, whenever PT is inside
4544 the invisible text. Otherwise the cursor would be
4545 placed _after_ the ellipsis when the point is after the
4546 first invisible character. */
4547 if (!STRINGP (it
->object
))
4549 it
->position
.charpos
= newpos
- 1;
4550 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4552 it
->ellipsis_p
= true;
4553 /* Let the ellipsis display before
4554 considering any properties of the following char.
4555 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4556 handled
= HANDLED_RETURN
;
4565 /* Make iterator IT return `...' next.
4566 Replaces LEN characters from buffer. */
4569 setup_for_ellipsis (struct it
*it
, int len
)
4571 /* Use the display table definition for `...'. Invalid glyphs
4572 will be handled by the method returning elements from dpvec. */
4573 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4575 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4576 it
->dpvec
= v
->contents
;
4577 it
->dpend
= v
->contents
+ v
->header
.size
;
4581 /* Default `...'. */
4582 it
->dpvec
= default_invis_vector
;
4583 it
->dpend
= default_invis_vector
+ 3;
4586 it
->dpvec_char_len
= len
;
4587 it
->current
.dpvec_index
= 0;
4588 it
->dpvec_face_id
= -1;
4590 /* Remember the current face id in case glyphs specify faces.
4591 IT's face is restored in set_iterator_to_next.
4592 saved_face_id was set to preceding char's face in handle_stop. */
4593 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4594 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4596 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4597 it
->ellipsis_p
= true;
4602 /***********************************************************************
4604 ***********************************************************************/
4606 /* Set up iterator IT from `display' property at its current position.
4607 Called from handle_stop.
4608 We return HANDLED_RETURN if some part of the display property
4609 overrides the display of the buffer text itself.
4610 Otherwise we return HANDLED_NORMALLY. */
4612 static enum prop_handled
4613 handle_display_prop (struct it
*it
)
4615 Lisp_Object propval
, object
, overlay
;
4616 struct text_pos
*position
;
4618 /* Nonzero if some property replaces the display of the text itself. */
4619 int display_replaced_p
= 0;
4621 if (STRINGP (it
->string
))
4623 object
= it
->string
;
4624 position
= &it
->current
.string_pos
;
4625 bufpos
= CHARPOS (it
->current
.pos
);
4629 XSETWINDOW (object
, it
->w
);
4630 position
= &it
->current
.pos
;
4631 bufpos
= CHARPOS (*position
);
4634 /* Reset those iterator values set from display property values. */
4635 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4636 it
->space_width
= Qnil
;
4637 it
->font_height
= Qnil
;
4640 /* We don't support recursive `display' properties, i.e. string
4641 values that have a string `display' property, that have a string
4642 `display' property etc. */
4643 if (!it
->string_from_display_prop_p
)
4644 it
->area
= TEXT_AREA
;
4646 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4647 Qdisplay
, object
, &overlay
);
4649 return HANDLED_NORMALLY
;
4650 /* Now OVERLAY is the overlay that gave us this property, or nil
4651 if it was a text property. */
4653 if (!STRINGP (it
->string
))
4654 object
= it
->w
->contents
;
4656 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4658 FRAME_WINDOW_P (it
->f
));
4660 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4663 /* Subroutine of handle_display_prop. Returns non-zero if the display
4664 specification in SPEC is a replacing specification, i.e. it would
4665 replace the text covered by `display' property with something else,
4666 such as an image or a display string. If SPEC includes any kind or
4667 `(space ...) specification, the value is 2; this is used by
4668 compute_display_string_pos, which see.
4670 See handle_single_display_spec for documentation of arguments.
4671 frame_window_p is non-zero if the window being redisplayed is on a
4672 GUI frame; this argument is used only if IT is NULL, see below.
4674 IT can be NULL, if this is called by the bidi reordering code
4675 through compute_display_string_pos, which see. In that case, this
4676 function only examines SPEC, but does not otherwise "handle" it, in
4677 the sense that it doesn't set up members of IT from the display
4680 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4681 Lisp_Object overlay
, struct text_pos
*position
,
4682 ptrdiff_t bufpos
, int frame_window_p
)
4684 int replacing_p
= 0;
4688 /* Simple specifications. */
4689 && !EQ (XCAR (spec
), Qimage
)
4690 && !EQ (XCAR (spec
), Qspace
)
4691 && !EQ (XCAR (spec
), Qwhen
)
4692 && !EQ (XCAR (spec
), Qslice
)
4693 && !EQ (XCAR (spec
), Qspace_width
)
4694 && !EQ (XCAR (spec
), Qheight
)
4695 && !EQ (XCAR (spec
), Qraise
)
4696 /* Marginal area specifications. */
4697 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4698 && !EQ (XCAR (spec
), Qleft_fringe
)
4699 && !EQ (XCAR (spec
), Qright_fringe
)
4700 && !NILP (XCAR (spec
)))
4702 for (; CONSP (spec
); spec
= XCDR (spec
))
4704 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4705 overlay
, position
, bufpos
,
4706 replacing_p
, frame_window_p
)))
4709 /* If some text in a string is replaced, `position' no
4710 longer points to the position of `object'. */
4711 if (!it
|| STRINGP (object
))
4716 else if (VECTORP (spec
))
4719 for (i
= 0; i
< ASIZE (spec
); ++i
)
4720 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4721 overlay
, position
, bufpos
,
4722 replacing_p
, frame_window_p
)))
4725 /* If some text in a string is replaced, `position' no
4726 longer points to the position of `object'. */
4727 if (!it
|| STRINGP (object
))
4733 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4734 position
, bufpos
, 0,
4742 /* Value is the position of the end of the `display' property starting
4743 at START_POS in OBJECT. */
4745 static struct text_pos
4746 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4749 struct text_pos end_pos
;
4751 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4752 Qdisplay
, object
, Qnil
);
4753 CHARPOS (end_pos
) = XFASTINT (end
);
4754 if (STRINGP (object
))
4755 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4757 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4763 /* Set up IT from a single `display' property specification SPEC. OBJECT
4764 is the object in which the `display' property was found. *POSITION
4765 is the position in OBJECT at which the `display' property was found.
4766 BUFPOS is the buffer position of OBJECT (different from POSITION if
4767 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4768 previously saw a display specification which already replaced text
4769 display with something else, for example an image; we ignore such
4770 properties after the first one has been processed.
4772 OVERLAY is the overlay this `display' property came from,
4773 or nil if it was a text property.
4775 If SPEC is a `space' or `image' specification, and in some other
4776 cases too, set *POSITION to the position where the `display'
4779 If IT is NULL, only examine the property specification in SPEC, but
4780 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4781 is intended to be displayed in a window on a GUI frame.
4783 Value is non-zero if something was found which replaces the display
4784 of buffer or string text. */
4787 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4788 Lisp_Object overlay
, struct text_pos
*position
,
4789 ptrdiff_t bufpos
, int display_replaced_p
,
4793 Lisp_Object location
, value
;
4794 struct text_pos start_pos
= *position
;
4797 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4798 If the result is non-nil, use VALUE instead of SPEC. */
4800 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4809 if (!NILP (form
) && !EQ (form
, Qt
))
4811 ptrdiff_t count
= SPECPDL_INDEX ();
4812 struct gcpro gcpro1
;
4814 /* Bind `object' to the object having the `display' property, a
4815 buffer or string. Bind `position' to the position in the
4816 object where the property was found, and `buffer-position'
4817 to the current position in the buffer. */
4820 XSETBUFFER (object
, current_buffer
);
4821 specbind (Qobject
, object
);
4822 specbind (Qposition
, make_number (CHARPOS (*position
)));
4823 specbind (Qbuffer_position
, make_number (bufpos
));
4825 form
= safe_eval (form
);
4827 unbind_to (count
, Qnil
);
4833 /* Handle `(height HEIGHT)' specifications. */
4835 && EQ (XCAR (spec
), Qheight
)
4836 && CONSP (XCDR (spec
)))
4840 if (!FRAME_WINDOW_P (it
->f
))
4843 it
->font_height
= XCAR (XCDR (spec
));
4844 if (!NILP (it
->font_height
))
4846 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4847 int new_height
= -1;
4849 if (CONSP (it
->font_height
)
4850 && (EQ (XCAR (it
->font_height
), Qplus
)
4851 || EQ (XCAR (it
->font_height
), Qminus
))
4852 && CONSP (XCDR (it
->font_height
))
4853 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4855 /* `(+ N)' or `(- N)' where N is an integer. */
4856 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4857 if (EQ (XCAR (it
->font_height
), Qplus
))
4859 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4861 else if (FUNCTIONP (it
->font_height
))
4863 /* Call function with current height as argument.
4864 Value is the new height. */
4866 height
= safe_call1 (it
->font_height
,
4867 face
->lface
[LFACE_HEIGHT_INDEX
]);
4868 if (NUMBERP (height
))
4869 new_height
= XFLOATINT (height
);
4871 else if (NUMBERP (it
->font_height
))
4873 /* Value is a multiple of the canonical char height. */
4876 f
= FACE_FROM_ID (it
->f
,
4877 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4878 new_height
= (XFLOATINT (it
->font_height
)
4879 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4883 /* Evaluate IT->font_height with `height' bound to the
4884 current specified height to get the new height. */
4885 ptrdiff_t count
= SPECPDL_INDEX ();
4887 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4888 value
= safe_eval (it
->font_height
);
4889 unbind_to (count
, Qnil
);
4891 if (NUMBERP (value
))
4892 new_height
= XFLOATINT (value
);
4896 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4903 /* Handle `(space-width WIDTH)'. */
4905 && EQ (XCAR (spec
), Qspace_width
)
4906 && CONSP (XCDR (spec
)))
4910 if (!FRAME_WINDOW_P (it
->f
))
4913 value
= XCAR (XCDR (spec
));
4914 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4915 it
->space_width
= value
;
4921 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4923 && EQ (XCAR (spec
), Qslice
))
4929 if (!FRAME_WINDOW_P (it
->f
))
4932 if (tem
= XCDR (spec
), CONSP (tem
))
4934 it
->slice
.x
= XCAR (tem
);
4935 if (tem
= XCDR (tem
), CONSP (tem
))
4937 it
->slice
.y
= XCAR (tem
);
4938 if (tem
= XCDR (tem
), CONSP (tem
))
4940 it
->slice
.width
= XCAR (tem
);
4941 if (tem
= XCDR (tem
), CONSP (tem
))
4942 it
->slice
.height
= XCAR (tem
);
4951 /* Handle `(raise FACTOR)'. */
4953 && EQ (XCAR (spec
), Qraise
)
4954 && CONSP (XCDR (spec
)))
4958 if (!FRAME_WINDOW_P (it
->f
))
4961 #ifdef HAVE_WINDOW_SYSTEM
4962 value
= XCAR (XCDR (spec
));
4963 if (NUMBERP (value
))
4965 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4966 it
->voffset
= - (XFLOATINT (value
)
4967 * (FONT_HEIGHT (face
->font
)));
4969 #endif /* HAVE_WINDOW_SYSTEM */
4975 /* Don't handle the other kinds of display specifications
4976 inside a string that we got from a `display' property. */
4977 if (it
&& it
->string_from_display_prop_p
)
4980 /* Characters having this form of property are not displayed, so
4981 we have to find the end of the property. */
4984 start_pos
= *position
;
4985 *position
= display_prop_end (it
, object
, start_pos
);
4989 /* Stop the scan at that end position--we assume that all
4990 text properties change there. */
4992 it
->stop_charpos
= position
->charpos
;
4994 /* Handle `(left-fringe BITMAP [FACE])'
4995 and `(right-fringe BITMAP [FACE])'. */
4997 && (EQ (XCAR (spec
), Qleft_fringe
)
4998 || EQ (XCAR (spec
), Qright_fringe
))
4999 && CONSP (XCDR (spec
)))
5005 if (!FRAME_WINDOW_P (it
->f
))
5006 /* If we return here, POSITION has been advanced
5007 across the text with this property. */
5009 /* Synchronize the bidi iterator with POSITION. This is
5010 needed because we are not going to push the iterator
5011 on behalf of this display property, so there will be
5012 no pop_it call to do this synchronization for us. */
5015 it
->position
= *position
;
5016 iterate_out_of_display_property (it
);
5017 *position
= it
->position
;
5019 /* If we were to display this fringe bitmap,
5020 next_element_from_image would have reset this flag.
5021 Do the same, to avoid affecting overlays that
5023 it
->ignore_overlay_strings_at_pos_p
= 0;
5027 else if (!frame_window_p
)
5030 #ifdef HAVE_WINDOW_SYSTEM
5031 value
= XCAR (XCDR (spec
));
5032 if (!SYMBOLP (value
)
5033 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
5034 /* If we return here, POSITION has been advanced
5035 across the text with this property. */
5037 if (it
&& it
->bidi_p
)
5039 it
->position
= *position
;
5040 iterate_out_of_display_property (it
);
5041 *position
= it
->position
;
5044 /* Reset this flag like next_element_from_image would. */
5045 it
->ignore_overlay_strings_at_pos_p
= 0;
5051 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
5053 if (CONSP (XCDR (XCDR (spec
))))
5055 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
5056 int face_id2
= lookup_derived_face (it
->f
, face_name
,
5062 /* Save current settings of IT so that we can restore them
5063 when we are finished with the glyph property value. */
5064 push_it (it
, position
);
5066 it
->area
= TEXT_AREA
;
5067 it
->what
= IT_IMAGE
;
5068 it
->image_id
= -1; /* no image */
5069 it
->position
= start_pos
;
5070 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5071 it
->method
= GET_FROM_IMAGE
;
5072 it
->from_overlay
= Qnil
;
5073 it
->face_id
= face_id
;
5074 it
->from_disp_prop_p
= true;
5076 /* Say that we haven't consumed the characters with
5077 `display' property yet. The call to pop_it in
5078 set_iterator_to_next will clean this up. */
5079 *position
= start_pos
;
5081 if (EQ (XCAR (spec
), Qleft_fringe
))
5083 it
->left_user_fringe_bitmap
= fringe_bitmap
;
5084 it
->left_user_fringe_face_id
= face_id
;
5088 it
->right_user_fringe_bitmap
= fringe_bitmap
;
5089 it
->right_user_fringe_face_id
= face_id
;
5092 #endif /* HAVE_WINDOW_SYSTEM */
5096 /* Prepare to handle `((margin left-margin) ...)',
5097 `((margin right-margin) ...)' and `((margin nil) ...)'
5098 prefixes for display specifications. */
5099 location
= Qunbound
;
5100 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5104 value
= XCDR (spec
);
5106 value
= XCAR (value
);
5109 if (EQ (XCAR (tem
), Qmargin
)
5110 && (tem
= XCDR (tem
),
5111 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5113 || EQ (tem
, Qleft_margin
)
5114 || EQ (tem
, Qright_margin
))))
5118 if (EQ (location
, Qunbound
))
5124 /* After this point, VALUE is the property after any
5125 margin prefix has been stripped. It must be a string,
5126 an image specification, or `(space ...)'.
5128 LOCATION specifies where to display: `left-margin',
5129 `right-margin' or nil. */
5131 valid_p
= (STRINGP (value
)
5132 #ifdef HAVE_WINDOW_SYSTEM
5133 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5134 && valid_image_p (value
))
5135 #endif /* not HAVE_WINDOW_SYSTEM */
5136 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5138 if (valid_p
&& !display_replaced_p
)
5144 /* Callers need to know whether the display spec is any kind
5145 of `(space ...)' spec that is about to affect text-area
5147 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5152 /* Save current settings of IT so that we can restore them
5153 when we are finished with the glyph property value. */
5154 push_it (it
, position
);
5155 it
->from_overlay
= overlay
;
5156 it
->from_disp_prop_p
= true;
5158 if (NILP (location
))
5159 it
->area
= TEXT_AREA
;
5160 else if (EQ (location
, Qleft_margin
))
5161 it
->area
= LEFT_MARGIN_AREA
;
5163 it
->area
= RIGHT_MARGIN_AREA
;
5165 if (STRINGP (value
))
5168 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5169 it
->current
.overlay_string_index
= -1;
5170 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5171 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5172 it
->method
= GET_FROM_STRING
;
5173 it
->stop_charpos
= 0;
5175 it
->base_level_stop
= 0;
5176 it
->string_from_display_prop_p
= true;
5177 /* Say that we haven't consumed the characters with
5178 `display' property yet. The call to pop_it in
5179 set_iterator_to_next will clean this up. */
5180 if (BUFFERP (object
))
5181 *position
= start_pos
;
5183 /* Force paragraph direction to be that of the parent
5184 object. If the parent object's paragraph direction is
5185 not yet determined, default to L2R. */
5186 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5187 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5189 it
->paragraph_embedding
= L2R
;
5191 /* Set up the bidi iterator for this display string. */
5194 it
->bidi_it
.string
.lstring
= it
->string
;
5195 it
->bidi_it
.string
.s
= NULL
;
5196 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5197 it
->bidi_it
.string
.bufpos
= bufpos
;
5198 it
->bidi_it
.string
.from_disp_str
= 1;
5199 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5200 it
->bidi_it
.w
= it
->w
;
5201 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5204 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5206 it
->method
= GET_FROM_STRETCH
;
5208 *position
= it
->position
= start_pos
;
5209 retval
= 1 + (it
->area
== TEXT_AREA
);
5211 #ifdef HAVE_WINDOW_SYSTEM
5214 it
->what
= IT_IMAGE
;
5215 it
->image_id
= lookup_image (it
->f
, value
);
5216 it
->position
= start_pos
;
5217 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5218 it
->method
= GET_FROM_IMAGE
;
5220 /* Say that we haven't consumed the characters with
5221 `display' property yet. The call to pop_it in
5222 set_iterator_to_next will clean this up. */
5223 *position
= start_pos
;
5225 #endif /* HAVE_WINDOW_SYSTEM */
5230 /* Invalid property or property not supported. Restore
5231 POSITION to what it was before. */
5232 *position
= start_pos
;
5236 /* Check if PROP is a display property value whose text should be
5237 treated as intangible. OVERLAY is the overlay from which PROP
5238 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5239 specify the buffer position covered by PROP. */
5242 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5243 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5245 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5246 struct text_pos position
;
5248 SET_TEXT_POS (position
, charpos
, bytepos
);
5249 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5250 &position
, charpos
, frame_window_p
);
5254 /* Return 1 if PROP is a display sub-property value containing STRING.
5256 Implementation note: this and the following function are really
5257 special cases of handle_display_spec and
5258 handle_single_display_spec, and should ideally use the same code.
5259 Until they do, these two pairs must be consistent and must be
5260 modified in sync. */
5263 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5265 if (EQ (string
, prop
))
5268 /* Skip over `when FORM'. */
5269 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5274 /* Actually, the condition following `when' should be eval'ed,
5275 like handle_single_display_spec does, and we should return
5276 zero if it evaluates to nil. However, this function is
5277 called only when the buffer was already displayed and some
5278 glyph in the glyph matrix was found to come from a display
5279 string. Therefore, the condition was already evaluated, and
5280 the result was non-nil, otherwise the display string wouldn't
5281 have been displayed and we would have never been called for
5282 this property. Thus, we can skip the evaluation and assume
5283 its result is non-nil. */
5288 /* Skip over `margin LOCATION'. */
5289 if (EQ (XCAR (prop
), Qmargin
))
5300 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5304 /* Return 1 if STRING appears in the `display' property PROP. */
5307 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5310 && !EQ (XCAR (prop
), Qwhen
)
5311 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5313 /* A list of sub-properties. */
5314 while (CONSP (prop
))
5316 if (single_display_spec_string_p (XCAR (prop
), string
))
5321 else if (VECTORP (prop
))
5323 /* A vector of sub-properties. */
5325 for (i
= 0; i
< ASIZE (prop
); ++i
)
5326 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5330 return single_display_spec_string_p (prop
, string
);
5335 /* Look for STRING in overlays and text properties in the current
5336 buffer, between character positions FROM and TO (excluding TO).
5337 BACK_P non-zero means look back (in this case, TO is supposed to be
5339 Value is the first character position where STRING was found, or
5340 zero if it wasn't found before hitting TO.
5342 This function may only use code that doesn't eval because it is
5343 called asynchronously from note_mouse_highlight. */
5346 string_buffer_position_lim (Lisp_Object string
,
5347 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5349 Lisp_Object limit
, prop
, pos
;
5352 pos
= make_number (max (from
, BEGV
));
5354 if (!back_p
) /* looking forward */
5356 limit
= make_number (min (to
, ZV
));
5357 while (!found
&& !EQ (pos
, limit
))
5359 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5360 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5363 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5367 else /* looking back */
5369 limit
= make_number (max (to
, BEGV
));
5370 while (!found
&& !EQ (pos
, limit
))
5372 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5373 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5376 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5381 return found
? XINT (pos
) : 0;
5384 /* Determine which buffer position in current buffer STRING comes from.
5385 AROUND_CHARPOS is an approximate position where it could come from.
5386 Value is the buffer position or 0 if it couldn't be determined.
5388 This function is necessary because we don't record buffer positions
5389 in glyphs generated from strings (to keep struct glyph small).
5390 This function may only use code that doesn't eval because it is
5391 called asynchronously from note_mouse_highlight. */
5394 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5396 const int MAX_DISTANCE
= 1000;
5397 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5398 around_charpos
+ MAX_DISTANCE
,
5402 found
= string_buffer_position_lim (string
, around_charpos
,
5403 around_charpos
- MAX_DISTANCE
, 1);
5409 /***********************************************************************
5410 `composition' property
5411 ***********************************************************************/
5413 /* Set up iterator IT from `composition' property at its current
5414 position. Called from handle_stop. */
5416 static enum prop_handled
5417 handle_composition_prop (struct it
*it
)
5419 Lisp_Object prop
, string
;
5420 ptrdiff_t pos
, pos_byte
, start
, end
;
5422 if (STRINGP (it
->string
))
5426 pos
= IT_STRING_CHARPOS (*it
);
5427 pos_byte
= IT_STRING_BYTEPOS (*it
);
5428 string
= it
->string
;
5429 s
= SDATA (string
) + pos_byte
;
5430 it
->c
= STRING_CHAR (s
);
5434 pos
= IT_CHARPOS (*it
);
5435 pos_byte
= IT_BYTEPOS (*it
);
5437 it
->c
= FETCH_CHAR (pos_byte
);
5440 /* If there's a valid composition and point is not inside of the
5441 composition (in the case that the composition is from the current
5442 buffer), draw a glyph composed from the composition components. */
5443 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5444 && composition_valid_p (start
, end
, prop
)
5445 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5448 /* As we can't handle this situation (perhaps font-lock added
5449 a new composition), we just return here hoping that next
5450 redisplay will detect this composition much earlier. */
5451 return HANDLED_NORMALLY
;
5454 if (STRINGP (it
->string
))
5455 pos_byte
= string_char_to_byte (it
->string
, start
);
5457 pos_byte
= CHAR_TO_BYTE (start
);
5459 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5462 if (it
->cmp_it
.id
>= 0)
5465 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5466 it
->cmp_it
.nglyphs
= -1;
5470 return HANDLED_NORMALLY
;
5475 /***********************************************************************
5477 ***********************************************************************/
5479 /* The following structure is used to record overlay strings for
5480 later sorting in load_overlay_strings. */
5482 struct overlay_entry
5484 Lisp_Object overlay
;
5491 /* Set up iterator IT from overlay strings at its current position.
5492 Called from handle_stop. */
5494 static enum prop_handled
5495 handle_overlay_change (struct it
*it
)
5497 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5498 return HANDLED_RECOMPUTE_PROPS
;
5500 return HANDLED_NORMALLY
;
5504 /* Set up the next overlay string for delivery by IT, if there is an
5505 overlay string to deliver. Called by set_iterator_to_next when the
5506 end of the current overlay string is reached. If there are more
5507 overlay strings to display, IT->string and
5508 IT->current.overlay_string_index are set appropriately here.
5509 Otherwise IT->string is set to nil. */
5512 next_overlay_string (struct it
*it
)
5514 ++it
->current
.overlay_string_index
;
5515 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5517 /* No more overlay strings. Restore IT's settings to what
5518 they were before overlay strings were processed, and
5519 continue to deliver from current_buffer. */
5521 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5524 || (NILP (it
->string
)
5525 && it
->method
== GET_FROM_BUFFER
5526 && it
->stop_charpos
>= BEGV
5527 && it
->stop_charpos
<= it
->end_charpos
));
5528 it
->current
.overlay_string_index
= -1;
5529 it
->n_overlay_strings
= 0;
5530 it
->overlay_strings_charpos
= -1;
5531 /* If there's an empty display string on the stack, pop the
5532 stack, to resync the bidi iterator with IT's position. Such
5533 empty strings are pushed onto the stack in
5534 get_overlay_strings_1. */
5535 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5538 /* If we're at the end of the buffer, record that we have
5539 processed the overlay strings there already, so that
5540 next_element_from_buffer doesn't try it again. */
5541 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5542 it
->overlay_strings_at_end_processed_p
= true;
5546 /* There are more overlay strings to process. If
5547 IT->current.overlay_string_index has advanced to a position
5548 where we must load IT->overlay_strings with more strings, do
5549 it. We must load at the IT->overlay_strings_charpos where
5550 IT->n_overlay_strings was originally computed; when invisible
5551 text is present, this might not be IT_CHARPOS (Bug#7016). */
5552 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5554 if (it
->current
.overlay_string_index
&& i
== 0)
5555 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5557 /* Initialize IT to deliver display elements from the overlay
5559 it
->string
= it
->overlay_strings
[i
];
5560 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5561 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5562 it
->method
= GET_FROM_STRING
;
5563 it
->stop_charpos
= 0;
5564 it
->end_charpos
= SCHARS (it
->string
);
5565 if (it
->cmp_it
.stop_pos
>= 0)
5566 it
->cmp_it
.stop_pos
= 0;
5568 it
->base_level_stop
= 0;
5570 /* Set up the bidi iterator for this overlay string. */
5573 it
->bidi_it
.string
.lstring
= it
->string
;
5574 it
->bidi_it
.string
.s
= NULL
;
5575 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5576 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5577 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5578 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5579 it
->bidi_it
.w
= it
->w
;
5580 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5588 /* Compare two overlay_entry structures E1 and E2. Used as a
5589 comparison function for qsort in load_overlay_strings. Overlay
5590 strings for the same position are sorted so that
5592 1. All after-strings come in front of before-strings, except
5593 when they come from the same overlay.
5595 2. Within after-strings, strings are sorted so that overlay strings
5596 from overlays with higher priorities come first.
5598 2. Within before-strings, strings are sorted so that overlay
5599 strings from overlays with higher priorities come last.
5601 Value is analogous to strcmp. */
5605 compare_overlay_entries (const void *e1
, const void *e2
)
5607 struct overlay_entry
const *entry1
= e1
;
5608 struct overlay_entry
const *entry2
= e2
;
5611 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5613 /* Let after-strings appear in front of before-strings if
5614 they come from different overlays. */
5615 if (EQ (entry1
->overlay
, entry2
->overlay
))
5616 result
= entry1
->after_string_p
? 1 : -1;
5618 result
= entry1
->after_string_p
? -1 : 1;
5620 else if (entry1
->priority
!= entry2
->priority
)
5622 if (entry1
->after_string_p
)
5623 /* After-strings sorted in order of decreasing priority. */
5624 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5626 /* Before-strings sorted in order of increasing priority. */
5627 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5636 /* Load the vector IT->overlay_strings with overlay strings from IT's
5637 current buffer position, or from CHARPOS if that is > 0. Set
5638 IT->n_overlays to the total number of overlay strings found.
5640 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5641 a time. On entry into load_overlay_strings,
5642 IT->current.overlay_string_index gives the number of overlay
5643 strings that have already been loaded by previous calls to this
5646 IT->add_overlay_start contains an additional overlay start
5647 position to consider for taking overlay strings from, if non-zero.
5648 This position comes into play when the overlay has an `invisible'
5649 property, and both before and after-strings. When we've skipped to
5650 the end of the overlay, because of its `invisible' property, we
5651 nevertheless want its before-string to appear.
5652 IT->add_overlay_start will contain the overlay start position
5655 Overlay strings are sorted so that after-string strings come in
5656 front of before-string strings. Within before and after-strings,
5657 strings are sorted by overlay priority. See also function
5658 compare_overlay_entries. */
5661 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5663 Lisp_Object overlay
, window
, str
, invisible
;
5664 struct Lisp_Overlay
*ov
;
5665 ptrdiff_t start
, end
;
5666 ptrdiff_t n
= 0, i
, j
;
5668 struct overlay_entry entriesbuf
[20];
5669 ptrdiff_t size
= ARRAYELTS (entriesbuf
);
5670 struct overlay_entry
*entries
= entriesbuf
;
5674 charpos
= IT_CHARPOS (*it
);
5676 /* Append the overlay string STRING of overlay OVERLAY to vector
5677 `entries' which has size `size' and currently contains `n'
5678 elements. AFTER_P non-zero means STRING is an after-string of
5680 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5683 Lisp_Object priority; \
5687 struct overlay_entry *old = entries; \
5688 SAFE_NALLOCA (entries, 2, size); \
5689 memcpy (entries, old, size * sizeof *entries); \
5693 entries[n].string = (STRING); \
5694 entries[n].overlay = (OVERLAY); \
5695 priority = Foverlay_get ((OVERLAY), Qpriority); \
5696 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5697 entries[n].after_string_p = (AFTER_P); \
5702 /* Process overlay before the overlay center. */
5703 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5705 XSETMISC (overlay
, ov
);
5706 eassert (OVERLAYP (overlay
));
5707 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5708 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5713 /* Skip this overlay if it doesn't start or end at IT's current
5715 if (end
!= charpos
&& start
!= charpos
)
5718 /* Skip this overlay if it doesn't apply to IT->w. */
5719 window
= Foverlay_get (overlay
, Qwindow
);
5720 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5723 /* If the text ``under'' the overlay is invisible, both before-
5724 and after-strings from this overlay are visible; start and
5725 end position are indistinguishable. */
5726 invisible
= Foverlay_get (overlay
, Qinvisible
);
5727 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5729 /* If overlay has a non-empty before-string, record it. */
5730 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5731 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5733 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5735 /* If overlay has a non-empty after-string, record it. */
5736 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5737 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5739 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5742 /* Process overlays after the overlay center. */
5743 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5745 XSETMISC (overlay
, ov
);
5746 eassert (OVERLAYP (overlay
));
5747 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5748 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5750 if (start
> charpos
)
5753 /* Skip this overlay if it doesn't start or end at IT's current
5755 if (end
!= charpos
&& start
!= charpos
)
5758 /* Skip this overlay if it doesn't apply to IT->w. */
5759 window
= Foverlay_get (overlay
, Qwindow
);
5760 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5763 /* If the text ``under'' the overlay is invisible, it has a zero
5764 dimension, and both before- and after-strings apply. */
5765 invisible
= Foverlay_get (overlay
, Qinvisible
);
5766 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5768 /* If overlay has a non-empty before-string, record it. */
5769 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5770 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5772 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5774 /* If overlay has a non-empty after-string, record it. */
5775 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5776 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5778 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5781 #undef RECORD_OVERLAY_STRING
5785 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5787 /* Record number of overlay strings, and where we computed it. */
5788 it
->n_overlay_strings
= n
;
5789 it
->overlay_strings_charpos
= charpos
;
5791 /* IT->current.overlay_string_index is the number of overlay strings
5792 that have already been consumed by IT. Copy some of the
5793 remaining overlay strings to IT->overlay_strings. */
5795 j
= it
->current
.overlay_string_index
;
5796 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5798 it
->overlay_strings
[i
] = entries
[j
].string
;
5799 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5807 /* Get the first chunk of overlay strings at IT's current buffer
5808 position, or at CHARPOS if that is > 0. Value is non-zero if at
5809 least one overlay string was found. */
5812 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5814 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5815 process. This fills IT->overlay_strings with strings, and sets
5816 IT->n_overlay_strings to the total number of strings to process.
5817 IT->pos.overlay_string_index has to be set temporarily to zero
5818 because load_overlay_strings needs this; it must be set to -1
5819 when no overlay strings are found because a zero value would
5820 indicate a position in the first overlay string. */
5821 it
->current
.overlay_string_index
= 0;
5822 load_overlay_strings (it
, charpos
);
5824 /* If we found overlay strings, set up IT to deliver display
5825 elements from the first one. Otherwise set up IT to deliver
5826 from current_buffer. */
5827 if (it
->n_overlay_strings
)
5829 /* Make sure we know settings in current_buffer, so that we can
5830 restore meaningful values when we're done with the overlay
5833 compute_stop_pos (it
);
5834 eassert (it
->face_id
>= 0);
5836 /* Save IT's settings. They are restored after all overlay
5837 strings have been processed. */
5838 eassert (!compute_stop_p
|| it
->sp
== 0);
5840 /* When called from handle_stop, there might be an empty display
5841 string loaded. In that case, don't bother saving it. But
5842 don't use this optimization with the bidi iterator, since we
5843 need the corresponding pop_it call to resync the bidi
5844 iterator's position with IT's position, after we are done
5845 with the overlay strings. (The corresponding call to pop_it
5846 in case of an empty display string is in
5847 next_overlay_string.) */
5849 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5852 /* Set up IT to deliver display elements from the first overlay
5854 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5855 it
->string
= it
->overlay_strings
[0];
5856 it
->from_overlay
= Qnil
;
5857 it
->stop_charpos
= 0;
5858 eassert (STRINGP (it
->string
));
5859 it
->end_charpos
= SCHARS (it
->string
);
5861 it
->base_level_stop
= 0;
5862 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5863 it
->method
= GET_FROM_STRING
;
5864 it
->from_disp_prop_p
= 0;
5866 /* Force paragraph direction to be that of the parent
5868 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5869 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5871 it
->paragraph_embedding
= L2R
;
5873 /* Set up the bidi iterator for this overlay string. */
5876 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5878 it
->bidi_it
.string
.lstring
= it
->string
;
5879 it
->bidi_it
.string
.s
= NULL
;
5880 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5881 it
->bidi_it
.string
.bufpos
= pos
;
5882 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5883 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5884 it
->bidi_it
.w
= it
->w
;
5885 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5890 it
->current
.overlay_string_index
= -1;
5895 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5898 it
->method
= GET_FROM_BUFFER
;
5900 (void) get_overlay_strings_1 (it
, charpos
, 1);
5904 /* Value is non-zero if we found at least one overlay string. */
5905 return STRINGP (it
->string
);
5910 /***********************************************************************
5911 Saving and restoring state
5912 ***********************************************************************/
5914 /* Save current settings of IT on IT->stack. Called, for example,
5915 before setting up IT for an overlay string, to be able to restore
5916 IT's settings to what they were after the overlay string has been
5917 processed. If POSITION is non-NULL, it is the position to save on
5918 the stack instead of IT->position. */
5921 push_it (struct it
*it
, struct text_pos
*position
)
5923 struct iterator_stack_entry
*p
;
5925 eassert (it
->sp
< IT_STACK_SIZE
);
5926 p
= it
->stack
+ it
->sp
;
5928 p
->stop_charpos
= it
->stop_charpos
;
5929 p
->prev_stop
= it
->prev_stop
;
5930 p
->base_level_stop
= it
->base_level_stop
;
5931 p
->cmp_it
= it
->cmp_it
;
5932 eassert (it
->face_id
>= 0);
5933 p
->face_id
= it
->face_id
;
5934 p
->string
= it
->string
;
5935 p
->method
= it
->method
;
5936 p
->from_overlay
= it
->from_overlay
;
5939 case GET_FROM_IMAGE
:
5940 p
->u
.image
.object
= it
->object
;
5941 p
->u
.image
.image_id
= it
->image_id
;
5942 p
->u
.image
.slice
= it
->slice
;
5944 case GET_FROM_STRETCH
:
5945 p
->u
.stretch
.object
= it
->object
;
5948 p
->position
= position
? *position
: it
->position
;
5949 p
->current
= it
->current
;
5950 p
->end_charpos
= it
->end_charpos
;
5951 p
->string_nchars
= it
->string_nchars
;
5953 p
->multibyte_p
= it
->multibyte_p
;
5954 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5955 p
->space_width
= it
->space_width
;
5956 p
->font_height
= it
->font_height
;
5957 p
->voffset
= it
->voffset
;
5958 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5959 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5960 p
->display_ellipsis_p
= 0;
5961 p
->line_wrap
= it
->line_wrap
;
5962 p
->bidi_p
= it
->bidi_p
;
5963 p
->paragraph_embedding
= it
->paragraph_embedding
;
5964 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5967 /* Save the state of the bidi iterator as well. */
5969 bidi_push_it (&it
->bidi_it
);
5973 iterate_out_of_display_property (struct it
*it
)
5975 int buffer_p
= !STRINGP (it
->string
);
5976 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5977 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5979 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5981 /* Maybe initialize paragraph direction. If we are at the beginning
5982 of a new paragraph, next_element_from_buffer may not have a
5983 chance to do that. */
5984 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5985 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5986 /* prev_stop can be zero, so check against BEGV as well. */
5987 while (it
->bidi_it
.charpos
>= bob
5988 && it
->prev_stop
<= it
->bidi_it
.charpos
5989 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5990 && it
->bidi_it
.charpos
< eob
)
5991 bidi_move_to_visually_next (&it
->bidi_it
);
5992 /* Record the stop_pos we just crossed, for when we cross it
5994 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5995 it
->prev_stop
= CHARPOS (it
->position
);
5996 /* If we ended up not where pop_it put us, resync IT's
5997 positional members with the bidi iterator. */
5998 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5999 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
6001 it
->current
.pos
= it
->position
;
6003 it
->current
.string_pos
= it
->position
;
6006 /* Restore IT's settings from IT->stack. Called, for example, when no
6007 more overlay strings must be processed, and we return to delivering
6008 display elements from a buffer, or when the end of a string from a
6009 `display' property is reached and we return to delivering display
6010 elements from an overlay string, or from a buffer. */
6013 pop_it (struct it
*it
)
6015 struct iterator_stack_entry
*p
;
6016 int from_display_prop
= it
->from_disp_prop_p
;
6018 eassert (it
->sp
> 0);
6020 p
= it
->stack
+ it
->sp
;
6021 it
->stop_charpos
= p
->stop_charpos
;
6022 it
->prev_stop
= p
->prev_stop
;
6023 it
->base_level_stop
= p
->base_level_stop
;
6024 it
->cmp_it
= p
->cmp_it
;
6025 it
->face_id
= p
->face_id
;
6026 it
->current
= p
->current
;
6027 it
->position
= p
->position
;
6028 it
->string
= p
->string
;
6029 it
->from_overlay
= p
->from_overlay
;
6030 if (NILP (it
->string
))
6031 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
6032 it
->method
= p
->method
;
6035 case GET_FROM_IMAGE
:
6036 it
->image_id
= p
->u
.image
.image_id
;
6037 it
->object
= p
->u
.image
.object
;
6038 it
->slice
= p
->u
.image
.slice
;
6040 case GET_FROM_STRETCH
:
6041 it
->object
= p
->u
.stretch
.object
;
6043 case GET_FROM_BUFFER
:
6044 it
->object
= it
->w
->contents
;
6046 case GET_FROM_STRING
:
6048 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6050 /* Restore the face_box_p flag, since it could have been
6051 overwritten by the face of the object that we just finished
6054 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
6055 it
->object
= it
->string
;
6058 case GET_FROM_DISPLAY_VECTOR
:
6060 it
->method
= GET_FROM_C_STRING
;
6061 else if (STRINGP (it
->string
))
6062 it
->method
= GET_FROM_STRING
;
6065 it
->method
= GET_FROM_BUFFER
;
6066 it
->object
= it
->w
->contents
;
6069 it
->end_charpos
= p
->end_charpos
;
6070 it
->string_nchars
= p
->string_nchars
;
6072 it
->multibyte_p
= p
->multibyte_p
;
6073 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
6074 it
->space_width
= p
->space_width
;
6075 it
->font_height
= p
->font_height
;
6076 it
->voffset
= p
->voffset
;
6077 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
6078 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
6079 it
->line_wrap
= p
->line_wrap
;
6080 it
->bidi_p
= p
->bidi_p
;
6081 it
->paragraph_embedding
= p
->paragraph_embedding
;
6082 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
6085 bidi_pop_it (&it
->bidi_it
);
6086 /* Bidi-iterate until we get out of the portion of text, if any,
6087 covered by a `display' text property or by an overlay with
6088 `display' property. (We cannot just jump there, because the
6089 internal coherency of the bidi iterator state can not be
6090 preserved across such jumps.) We also must determine the
6091 paragraph base direction if the overlay we just processed is
6092 at the beginning of a new paragraph. */
6093 if (from_display_prop
6094 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
6095 iterate_out_of_display_property (it
);
6097 eassert ((BUFFERP (it
->object
)
6098 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
6099 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6100 || (STRINGP (it
->object
)
6101 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
6102 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
6103 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6109 /***********************************************************************
6111 ***********************************************************************/
6113 /* Set IT's current position to the previous line start. */
6116 back_to_previous_line_start (struct it
*it
)
6118 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6121 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6125 /* Move IT to the next line start.
6127 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6128 we skipped over part of the text (as opposed to moving the iterator
6129 continuously over the text). Otherwise, don't change the value
6132 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6133 iterator on the newline, if it was found.
6135 Newlines may come from buffer text, overlay strings, or strings
6136 displayed via the `display' property. That's the reason we can't
6137 simply use find_newline_no_quit.
6139 Note that this function may not skip over invisible text that is so
6140 because of text properties and immediately follows a newline. If
6141 it would, function reseat_at_next_visible_line_start, when called
6142 from set_iterator_to_next, would effectively make invisible
6143 characters following a newline part of the wrong glyph row, which
6144 leads to wrong cursor motion. */
6147 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6148 struct bidi_it
*bidi_it_prev
)
6150 ptrdiff_t old_selective
;
6151 int newline_found_p
, n
;
6152 const int MAX_NEWLINE_DISTANCE
= 500;
6154 /* If already on a newline, just consume it to avoid unintended
6155 skipping over invisible text below. */
6156 if (it
->what
== IT_CHARACTER
6158 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6160 if (it
->bidi_p
&& bidi_it_prev
)
6161 *bidi_it_prev
= it
->bidi_it
;
6162 set_iterator_to_next (it
, 0);
6167 /* Don't handle selective display in the following. It's (a)
6168 unnecessary because it's done by the caller, and (b) leads to an
6169 infinite recursion because next_element_from_ellipsis indirectly
6170 calls this function. */
6171 old_selective
= it
->selective
;
6174 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6175 from buffer text. */
6176 for (n
= newline_found_p
= 0;
6177 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6178 n
+= STRINGP (it
->string
) ? 0 : 1)
6180 if (!get_next_display_element (it
))
6182 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6183 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6184 *bidi_it_prev
= it
->bidi_it
;
6185 set_iterator_to_next (it
, 0);
6188 /* If we didn't find a newline near enough, see if we can use a
6190 if (!newline_found_p
)
6192 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6193 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6197 eassert (!STRINGP (it
->string
));
6199 /* If there isn't any `display' property in sight, and no
6200 overlays, we can just use the position of the newline in
6202 if (it
->stop_charpos
>= limit
6203 || ((pos
= Fnext_single_property_change (make_number (start
),
6205 make_number (limit
)),
6207 && next_overlay_change (start
) == ZV
))
6211 IT_CHARPOS (*it
) = limit
;
6212 IT_BYTEPOS (*it
) = bytepos
;
6216 struct bidi_it bprev
;
6218 /* Help bidi.c avoid expensive searches for display
6219 properties and overlays, by telling it that there are
6220 none up to `limit'. */
6221 if (it
->bidi_it
.disp_pos
< limit
)
6223 it
->bidi_it
.disp_pos
= limit
;
6224 it
->bidi_it
.disp_prop
= 0;
6227 bprev
= it
->bidi_it
;
6228 bidi_move_to_visually_next (&it
->bidi_it
);
6229 } while (it
->bidi_it
.charpos
!= limit
);
6230 IT_CHARPOS (*it
) = limit
;
6231 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6233 *bidi_it_prev
= bprev
;
6235 *skipped_p
= newline_found_p
= true;
6239 while (get_next_display_element (it
)
6240 && !newline_found_p
)
6242 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6243 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6244 *bidi_it_prev
= it
->bidi_it
;
6245 set_iterator_to_next (it
, 0);
6250 it
->selective
= old_selective
;
6251 return newline_found_p
;
6255 /* Set IT's current position to the previous visible line start. Skip
6256 invisible text that is so either due to text properties or due to
6257 selective display. Caution: this does not change IT->current_x and
6261 back_to_previous_visible_line_start (struct it
*it
)
6263 while (IT_CHARPOS (*it
) > BEGV
)
6265 back_to_previous_line_start (it
);
6267 if (IT_CHARPOS (*it
) <= BEGV
)
6270 /* If selective > 0, then lines indented more than its value are
6272 if (it
->selective
> 0
6273 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6277 /* Check the newline before point for invisibility. */
6280 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6281 Qinvisible
, it
->window
);
6282 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6286 if (IT_CHARPOS (*it
) <= BEGV
)
6291 void *it2data
= NULL
;
6294 Lisp_Object val
, overlay
;
6296 SAVE_IT (it2
, *it
, it2data
);
6298 /* If newline is part of a composition, continue from start of composition */
6299 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6300 && beg
< IT_CHARPOS (*it
))
6303 /* If newline is replaced by a display property, find start of overlay
6304 or interval and continue search from that point. */
6305 pos
= --IT_CHARPOS (it2
);
6308 bidi_unshelve_cache (NULL
, 0);
6309 it2
.string_from_display_prop_p
= 0;
6310 it2
.from_disp_prop_p
= 0;
6311 if (handle_display_prop (&it2
) == HANDLED_RETURN
6312 && !NILP (val
= get_char_property_and_overlay
6313 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6314 && (OVERLAYP (overlay
)
6315 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6316 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6318 RESTORE_IT (it
, it
, it2data
);
6322 /* Newline is not replaced by anything -- so we are done. */
6323 RESTORE_IT (it
, it
, it2data
);
6329 IT_CHARPOS (*it
) = beg
;
6330 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6334 it
->continuation_lines_width
= 0;
6336 eassert (IT_CHARPOS (*it
) >= BEGV
);
6337 eassert (IT_CHARPOS (*it
) == BEGV
6338 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6343 /* Reseat iterator IT at the previous visible line start. Skip
6344 invisible text that is so either due to text properties or due to
6345 selective display. At the end, update IT's overlay information,
6346 face information etc. */
6349 reseat_at_previous_visible_line_start (struct it
*it
)
6351 back_to_previous_visible_line_start (it
);
6352 reseat (it
, it
->current
.pos
, 1);
6357 /* Reseat iterator IT on the next visible line start in the current
6358 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6359 preceding the line start. Skip over invisible text that is so
6360 because of selective display. Compute faces, overlays etc at the
6361 new position. Note that this function does not skip over text that
6362 is invisible because of text properties. */
6365 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6367 int newline_found_p
, skipped_p
= 0;
6368 struct bidi_it bidi_it_prev
;
6370 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6372 /* Skip over lines that are invisible because they are indented
6373 more than the value of IT->selective. */
6374 if (it
->selective
> 0)
6375 while (IT_CHARPOS (*it
) < ZV
6376 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6379 eassert (IT_BYTEPOS (*it
) == BEGV
6380 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6382 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6385 /* Position on the newline if that's what's requested. */
6386 if (on_newline_p
&& newline_found_p
)
6388 if (STRINGP (it
->string
))
6390 if (IT_STRING_CHARPOS (*it
) > 0)
6394 --IT_STRING_CHARPOS (*it
);
6395 --IT_STRING_BYTEPOS (*it
);
6399 /* We need to restore the bidi iterator to the state
6400 it had on the newline, and resync the IT's
6401 position with that. */
6402 it
->bidi_it
= bidi_it_prev
;
6403 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6404 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6408 else if (IT_CHARPOS (*it
) > BEGV
)
6417 /* We need to restore the bidi iterator to the state it
6418 had on the newline and resync IT with that. */
6419 it
->bidi_it
= bidi_it_prev
;
6420 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6421 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6423 reseat (it
, it
->current
.pos
, 0);
6427 reseat (it
, it
->current
.pos
, 0);
6434 /***********************************************************************
6435 Changing an iterator's position
6436 ***********************************************************************/
6438 /* Change IT's current position to POS in current_buffer. If FORCE_P
6439 is non-zero, always check for text properties at the new position.
6440 Otherwise, text properties are only looked up if POS >=
6441 IT->check_charpos of a property. */
6444 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6446 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6448 reseat_1 (it
, pos
, 0);
6450 /* Determine where to check text properties. Avoid doing it
6451 where possible because text property lookup is very expensive. */
6453 || CHARPOS (pos
) > it
->stop_charpos
6454 || CHARPOS (pos
) < original_pos
)
6458 /* For bidi iteration, we need to prime prev_stop and
6459 base_level_stop with our best estimations. */
6460 /* Implementation note: Of course, POS is not necessarily a
6461 stop position, so assigning prev_pos to it is a lie; we
6462 should have called compute_stop_backwards. However, if
6463 the current buffer does not include any R2L characters,
6464 that call would be a waste of cycles, because the
6465 iterator will never move back, and thus never cross this
6466 "fake" stop position. So we delay that backward search
6467 until the time we really need it, in next_element_from_buffer. */
6468 if (CHARPOS (pos
) != it
->prev_stop
)
6469 it
->prev_stop
= CHARPOS (pos
);
6470 if (CHARPOS (pos
) < it
->base_level_stop
)
6471 it
->base_level_stop
= 0; /* meaning it's unknown */
6477 it
->prev_stop
= it
->base_level_stop
= 0;
6486 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6487 IT->stop_pos to POS, also. */
6490 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6492 /* Don't call this function when scanning a C string. */
6493 eassert (it
->s
== NULL
);
6495 /* POS must be a reasonable value. */
6496 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6498 it
->current
.pos
= it
->position
= pos
;
6499 it
->end_charpos
= ZV
;
6501 it
->current
.dpvec_index
= -1;
6502 it
->current
.overlay_string_index
= -1;
6503 IT_STRING_CHARPOS (*it
) = -1;
6504 IT_STRING_BYTEPOS (*it
) = -1;
6506 it
->method
= GET_FROM_BUFFER
;
6507 it
->object
= it
->w
->contents
;
6508 it
->area
= TEXT_AREA
;
6509 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6511 it
->string_from_display_prop_p
= 0;
6512 it
->string_from_prefix_prop_p
= 0;
6514 it
->from_disp_prop_p
= 0;
6515 it
->face_before_selective_p
= 0;
6518 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6520 bidi_unshelve_cache (NULL
, 0);
6521 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6522 it
->bidi_it
.string
.s
= NULL
;
6523 it
->bidi_it
.string
.lstring
= Qnil
;
6524 it
->bidi_it
.string
.bufpos
= 0;
6525 it
->bidi_it
.string
.from_disp_str
= 0;
6526 it
->bidi_it
.string
.unibyte
= 0;
6527 it
->bidi_it
.w
= it
->w
;
6532 it
->stop_charpos
= CHARPOS (pos
);
6533 it
->base_level_stop
= CHARPOS (pos
);
6535 /* This make the information stored in it->cmp_it invalidate. */
6540 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6541 If S is non-null, it is a C string to iterate over. Otherwise,
6542 STRING gives a Lisp string to iterate over.
6544 If PRECISION > 0, don't return more then PRECISION number of
6545 characters from the string.
6547 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6548 characters have been returned. FIELD_WIDTH < 0 means an infinite
6551 MULTIBYTE = 0 means disable processing of multibyte characters,
6552 MULTIBYTE > 0 means enable it,
6553 MULTIBYTE < 0 means use IT->multibyte_p.
6555 IT must be initialized via a prior call to init_iterator before
6556 calling this function. */
6559 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6560 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6563 /* No text property checks performed by default, but see below. */
6564 it
->stop_charpos
= -1;
6566 /* Set iterator position and end position. */
6567 memset (&it
->current
, 0, sizeof it
->current
);
6568 it
->current
.overlay_string_index
= -1;
6569 it
->current
.dpvec_index
= -1;
6570 eassert (charpos
>= 0);
6572 /* If STRING is specified, use its multibyteness, otherwise use the
6573 setting of MULTIBYTE, if specified. */
6575 it
->multibyte_p
= multibyte
> 0;
6577 /* Bidirectional reordering of strings is controlled by the default
6578 value of bidi-display-reordering. Don't try to reorder while
6579 loading loadup.el, as the necessary character property tables are
6580 not yet available. */
6583 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6587 eassert (STRINGP (string
));
6588 it
->string
= string
;
6590 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6591 it
->method
= GET_FROM_STRING
;
6592 it
->current
.string_pos
= string_pos (charpos
, string
);
6596 it
->bidi_it
.string
.lstring
= string
;
6597 it
->bidi_it
.string
.s
= NULL
;
6598 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6599 it
->bidi_it
.string
.bufpos
= 0;
6600 it
->bidi_it
.string
.from_disp_str
= 0;
6601 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6602 it
->bidi_it
.w
= it
->w
;
6603 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6604 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6609 it
->s
= (const unsigned char *) s
;
6612 /* Note that we use IT->current.pos, not it->current.string_pos,
6613 for displaying C strings. */
6614 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6615 if (it
->multibyte_p
)
6617 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6618 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6622 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6623 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6628 it
->bidi_it
.string
.lstring
= Qnil
;
6629 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6630 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6631 it
->bidi_it
.string
.bufpos
= 0;
6632 it
->bidi_it
.string
.from_disp_str
= 0;
6633 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6634 it
->bidi_it
.w
= it
->w
;
6635 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6638 it
->method
= GET_FROM_C_STRING
;
6641 /* PRECISION > 0 means don't return more than PRECISION characters
6643 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6645 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6647 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6650 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6651 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6652 FIELD_WIDTH < 0 means infinite field width. This is useful for
6653 padding with `-' at the end of a mode line. */
6654 if (field_width
< 0)
6655 field_width
= INFINITY
;
6656 /* Implementation note: We deliberately don't enlarge
6657 it->bidi_it.string.schars here to fit it->end_charpos, because
6658 the bidi iterator cannot produce characters out of thin air. */
6659 if (field_width
> it
->end_charpos
- charpos
)
6660 it
->end_charpos
= charpos
+ field_width
;
6662 /* Use the standard display table for displaying strings. */
6663 if (DISP_TABLE_P (Vstandard_display_table
))
6664 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6666 it
->stop_charpos
= charpos
;
6667 it
->prev_stop
= charpos
;
6668 it
->base_level_stop
= 0;
6671 it
->bidi_it
.first_elt
= 1;
6672 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6673 it
->bidi_it
.disp_pos
= -1;
6675 if (s
== NULL
&& it
->multibyte_p
)
6677 ptrdiff_t endpos
= SCHARS (it
->string
);
6678 if (endpos
> it
->end_charpos
)
6679 endpos
= it
->end_charpos
;
6680 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6688 /***********************************************************************
6690 ***********************************************************************/
6692 /* Map enum it_method value to corresponding next_element_from_* function. */
6694 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6696 next_element_from_buffer
,
6697 next_element_from_display_vector
,
6698 next_element_from_string
,
6699 next_element_from_c_string
,
6700 next_element_from_image
,
6701 next_element_from_stretch
6704 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6707 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6708 (possibly with the following characters). */
6710 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6711 ((IT)->cmp_it.id >= 0 \
6712 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6713 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6714 END_CHARPOS, (IT)->w, \
6715 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6719 /* Lookup the char-table Vglyphless_char_display for character C (-1
6720 if we want information for no-font case), and return the display
6721 method symbol. By side-effect, update it->what and
6722 it->glyphless_method. This function is called from
6723 get_next_display_element for each character element, and from
6724 x_produce_glyphs when no suitable font was found. */
6727 lookup_glyphless_char_display (int c
, struct it
*it
)
6729 Lisp_Object glyphless_method
= Qnil
;
6731 if (CHAR_TABLE_P (Vglyphless_char_display
)
6732 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6736 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6737 if (CONSP (glyphless_method
))
6738 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6739 ? XCAR (glyphless_method
)
6740 : XCDR (glyphless_method
);
6743 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6747 if (NILP (glyphless_method
))
6750 /* The default is to display the character by a proper font. */
6752 /* The default for the no-font case is to display an empty box. */
6753 glyphless_method
= Qempty_box
;
6755 if (EQ (glyphless_method
, Qzero_width
))
6758 return glyphless_method
;
6759 /* This method can't be used for the no-font case. */
6760 glyphless_method
= Qempty_box
;
6762 if (EQ (glyphless_method
, Qthin_space
))
6763 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6764 else if (EQ (glyphless_method
, Qempty_box
))
6765 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6766 else if (EQ (glyphless_method
, Qhex_code
))
6767 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6768 else if (STRINGP (glyphless_method
))
6769 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6772 /* Invalid value. We use the default method. */
6773 glyphless_method
= Qnil
;
6776 it
->what
= IT_GLYPHLESS
;
6777 return glyphless_method
;
6780 /* Merge escape glyph face and cache the result. */
6782 static struct frame
*last_escape_glyph_frame
= NULL
;
6783 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6784 static int last_escape_glyph_merged_face_id
= 0;
6787 merge_escape_glyph_face (struct it
*it
)
6791 if (it
->f
== last_escape_glyph_frame
6792 && it
->face_id
== last_escape_glyph_face_id
)
6793 face_id
= last_escape_glyph_merged_face_id
;
6796 /* Merge the `escape-glyph' face into the current face. */
6797 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6798 last_escape_glyph_frame
= it
->f
;
6799 last_escape_glyph_face_id
= it
->face_id
;
6800 last_escape_glyph_merged_face_id
= face_id
;
6805 /* Likewise for glyphless glyph face. */
6807 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6808 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6809 static int last_glyphless_glyph_merged_face_id
= 0;
6812 merge_glyphless_glyph_face (struct it
*it
)
6816 if (it
->f
== last_glyphless_glyph_frame
6817 && it
->face_id
== last_glyphless_glyph_face_id
)
6818 face_id
= last_glyphless_glyph_merged_face_id
;
6821 /* Merge the `glyphless-char' face into the current face. */
6822 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6823 last_glyphless_glyph_frame
= it
->f
;
6824 last_glyphless_glyph_face_id
= it
->face_id
;
6825 last_glyphless_glyph_merged_face_id
= face_id
;
6830 /* Load IT's display element fields with information about the next
6831 display element from the current position of IT. Value is zero if
6832 end of buffer (or C string) is reached. */
6835 get_next_display_element (struct it
*it
)
6837 /* Non-zero means that we found a display element. Zero means that
6838 we hit the end of what we iterate over. Performance note: the
6839 function pointer `method' used here turns out to be faster than
6840 using a sequence of if-statements. */
6844 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6846 if (it
->what
== IT_CHARACTER
)
6848 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6849 and only if (a) the resolved directionality of that character
6851 /* FIXME: Do we need an exception for characters from display
6853 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
6854 && !inhibit_bidi_mirroring
)
6855 it
->c
= bidi_mirror_char (it
->c
);
6856 /* Map via display table or translate control characters.
6857 IT->c, IT->len etc. have been set to the next character by
6858 the function call above. If we have a display table, and it
6859 contains an entry for IT->c, translate it. Don't do this if
6860 IT->c itself comes from a display table, otherwise we could
6861 end up in an infinite recursion. (An alternative could be to
6862 count the recursion depth of this function and signal an
6863 error when a certain maximum depth is reached.) Is it worth
6865 if (success_p
&& it
->dpvec
== NULL
)
6868 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6869 int nonascii_space_p
= 0;
6870 int nonascii_hyphen_p
= 0;
6871 int c
= it
->c
; /* This is the character to display. */
6873 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6875 eassert (SINGLE_BYTE_CHAR_P (c
));
6876 if (unibyte_display_via_language_environment
)
6878 c
= DECODE_CHAR (unibyte
, c
);
6880 c
= BYTE8_TO_CHAR (it
->c
);
6883 c
= BYTE8_TO_CHAR (it
->c
);
6887 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6890 struct Lisp_Vector
*v
= XVECTOR (dv
);
6892 /* Return the first character from the display table
6893 entry, if not empty. If empty, don't display the
6894 current character. */
6897 it
->dpvec_char_len
= it
->len
;
6898 it
->dpvec
= v
->contents
;
6899 it
->dpend
= v
->contents
+ v
->header
.size
;
6900 it
->current
.dpvec_index
= 0;
6901 it
->dpvec_face_id
= -1;
6902 it
->saved_face_id
= it
->face_id
;
6903 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6908 set_iterator_to_next (it
, 0);
6913 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6915 if (it
->what
== IT_GLYPHLESS
)
6917 /* Don't display this character. */
6918 set_iterator_to_next (it
, 0);
6922 /* If `nobreak-char-display' is non-nil, we display
6923 non-ASCII spaces and hyphens specially. */
6924 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6927 nonascii_space_p
= true;
6928 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6929 nonascii_hyphen_p
= true;
6932 /* Translate control characters into `\003' or `^C' form.
6933 Control characters coming from a display table entry are
6934 currently not translated because we use IT->dpvec to hold
6935 the translation. This could easily be changed but I
6936 don't believe that it is worth doing.
6938 The characters handled by `nobreak-char-display' must be
6941 Non-printable characters and raw-byte characters are also
6942 translated to octal form. */
6943 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
6944 ? (it
->area
!= TEXT_AREA
6945 /* In mode line, treat \n, \t like other crl chars. */
6948 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6949 || (c
!= '\n' && c
!= '\t'))
6951 || nonascii_hyphen_p
6953 || ! CHAR_PRINTABLE_P (c
))))
6955 /* C is a control character, non-ASCII space/hyphen,
6956 raw-byte, or a non-printable character which must be
6957 displayed either as '\003' or as `^C' where the '\\'
6958 and '^' can be defined in the display table. Fill
6959 IT->ctl_chars with glyphs for what we have to
6960 display. Then, set IT->dpvec to these glyphs. */
6967 /* Handle control characters with ^. */
6969 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6973 g
= '^'; /* default glyph for Control */
6974 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6976 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6978 g
= GLYPH_CODE_CHAR (gc
);
6979 lface_id
= GLYPH_CODE_FACE (gc
);
6983 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6984 : merge_escape_glyph_face (it
));
6986 XSETINT (it
->ctl_chars
[0], g
);
6987 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6989 goto display_control
;
6992 /* Handle non-ascii space in the mode where it only gets
6995 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6997 /* Merge `nobreak-space' into the current face. */
6998 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
7000 XSETINT (it
->ctl_chars
[0], ' ');
7002 goto display_control
;
7005 /* Handle sequences that start with the "escape glyph". */
7007 /* the default escape glyph is \. */
7008 escape_glyph
= '\\';
7011 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
7013 escape_glyph
= GLYPH_CODE_CHAR (gc
);
7014 lface_id
= GLYPH_CODE_FACE (gc
);
7018 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
7019 : merge_escape_glyph_face (it
));
7021 /* Draw non-ASCII hyphen with just highlighting: */
7023 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
7025 XSETINT (it
->ctl_chars
[0], '-');
7027 goto display_control
;
7030 /* Draw non-ASCII space/hyphen with escape glyph: */
7032 if (nonascii_space_p
|| nonascii_hyphen_p
)
7034 XSETINT (it
->ctl_chars
[0], escape_glyph
);
7035 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
7037 goto display_control
;
7044 if (CHAR_BYTE8_P (c
))
7045 /* Display \200 instead of \17777600. */
7046 c
= CHAR_TO_BYTE8 (c
);
7047 len
= sprintf (str
, "%03o", c
);
7049 XSETINT (it
->ctl_chars
[0], escape_glyph
);
7050 for (i
= 0; i
< len
; i
++)
7051 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
7056 /* Set up IT->dpvec and return first character from it. */
7057 it
->dpvec_char_len
= it
->len
;
7058 it
->dpvec
= it
->ctl_chars
;
7059 it
->dpend
= it
->dpvec
+ ctl_len
;
7060 it
->current
.dpvec_index
= 0;
7061 it
->dpvec_face_id
= face_id
;
7062 it
->saved_face_id
= it
->face_id
;
7063 it
->method
= GET_FROM_DISPLAY_VECTOR
;
7067 it
->char_to_display
= c
;
7071 it
->char_to_display
= it
->c
;
7075 #ifdef HAVE_WINDOW_SYSTEM
7076 /* Adjust face id for a multibyte character. There are no multibyte
7077 character in unibyte text. */
7078 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
7081 && FRAME_WINDOW_P (it
->f
))
7083 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7085 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
7087 /* Automatic composition with glyph-string. */
7088 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
7090 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
7094 ptrdiff_t pos
= (it
->s
? -1
7095 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
7096 : IT_CHARPOS (*it
));
7099 if (it
->what
== IT_CHARACTER
)
7100 c
= it
->char_to_display
;
7103 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
7107 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7108 /* TAB in a composition means display glyphs with
7109 padding space on the left or right. */
7110 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7113 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7116 #endif /* HAVE_WINDOW_SYSTEM */
7119 /* Is this character the last one of a run of characters with
7120 box? If yes, set IT->end_of_box_run_p to 1. */
7124 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7126 int face_id
= underlying_face_id (it
);
7127 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7131 if (face
->box
== FACE_NO_BOX
)
7133 /* If the box comes from face properties in a
7134 display string, check faces in that string. */
7135 int string_face_id
= face_after_it_pos (it
);
7136 it
->end_of_box_run_p
7137 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7140 /* Otherwise, the box comes from the underlying face.
7141 If this is the last string character displayed, check
7142 the next buffer location. */
7143 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7144 /* n_overlay_strings is unreliable unless
7145 overlay_string_index is non-negative. */
7146 && ((it
->current
.overlay_string_index
>= 0
7147 && (it
->current
.overlay_string_index
7148 == it
->n_overlay_strings
- 1))
7149 /* A string from display property. */
7150 || it
->from_disp_prop_p
))
7154 struct text_pos pos
= it
->current
.pos
;
7156 /* For a string from a display property, the next
7157 buffer position is stored in the 'position'
7158 member of the iteration stack slot below the
7159 current one, see handle_single_display_spec. By
7160 contrast, it->current.pos was is not yet updated
7161 to point to that buffer position; that will
7162 happen in pop_it, after we finish displaying the
7163 current string. Note that we already checked
7164 above that it->sp is positive, so subtracting one
7166 if (it
->from_disp_prop_p
)
7167 pos
= (it
->stack
+ it
->sp
- 1)->position
;
7169 INC_TEXT_POS (pos
, it
->multibyte_p
);
7171 if (CHARPOS (pos
) >= ZV
)
7172 it
->end_of_box_run_p
= true;
7175 next_face_id
= face_at_buffer_position
7176 (it
->w
, CHARPOS (pos
), &ignore
,
7177 CHARPOS (pos
) + TEXT_PROP_DISTANCE_LIMIT
, 0, -1);
7178 it
->end_of_box_run_p
7179 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7185 /* next_element_from_display_vector sets this flag according to
7186 faces of the display vector glyphs, see there. */
7187 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7189 int face_id
= face_after_it_pos (it
);
7190 it
->end_of_box_run_p
7191 = (face_id
!= it
->face_id
7192 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7195 /* If we reached the end of the object we've been iterating (e.g., a
7196 display string or an overlay string), and there's something on
7197 IT->stack, proceed with what's on the stack. It doesn't make
7198 sense to return zero if there's unprocessed stuff on the stack,
7199 because otherwise that stuff will never be displayed. */
7200 if (!success_p
&& it
->sp
> 0)
7202 set_iterator_to_next (it
, 0);
7203 success_p
= get_next_display_element (it
);
7206 /* Value is 0 if end of buffer or string reached. */
7211 /* Move IT to the next display element.
7213 RESEAT_P non-zero means if called on a newline in buffer text,
7214 skip to the next visible line start.
7216 Functions get_next_display_element and set_iterator_to_next are
7217 separate because I find this arrangement easier to handle than a
7218 get_next_display_element function that also increments IT's
7219 position. The way it is we can first look at an iterator's current
7220 display element, decide whether it fits on a line, and if it does,
7221 increment the iterator position. The other way around we probably
7222 would either need a flag indicating whether the iterator has to be
7223 incremented the next time, or we would have to implement a
7224 decrement position function which would not be easy to write. */
7227 set_iterator_to_next (struct it
*it
, int reseat_p
)
7229 /* Reset flags indicating start and end of a sequence of characters
7230 with box. Reset them at the start of this function because
7231 moving the iterator to a new position might set them. */
7232 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7236 case GET_FROM_BUFFER
:
7237 /* The current display element of IT is a character from
7238 current_buffer. Advance in the buffer, and maybe skip over
7239 invisible lines that are so because of selective display. */
7240 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7241 reseat_at_next_visible_line_start (it
, 0);
7242 else if (it
->cmp_it
.id
>= 0)
7244 /* We are currently getting glyphs from a composition. */
7247 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7248 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7254 /* Update IT's char/byte positions to point to the first
7255 character of the next grapheme cluster, or to the
7256 character visually after the current composition. */
7257 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7258 bidi_move_to_visually_next (&it
->bidi_it
);
7259 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7260 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7263 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7264 && it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7266 /* Composition created while scanning forward. Proceed
7267 to the next grapheme cluster. */
7268 it
->cmp_it
.from
= it
->cmp_it
.to
;
7270 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7271 && it
->cmp_it
.from
> 0)
7273 /* Composition created while scanning backward. Proceed
7274 to the previous grapheme cluster. */
7275 it
->cmp_it
.to
= it
->cmp_it
.from
;
7279 /* No more grapheme clusters in this composition.
7280 Find the next stop position. */
7281 ptrdiff_t stop
= it
->end_charpos
;
7283 if (it
->bidi_it
.scan_dir
< 0)
7284 /* Now we are scanning backward and don't know
7287 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7288 IT_BYTEPOS (*it
), stop
, Qnil
);
7293 eassert (it
->len
!= 0);
7297 IT_BYTEPOS (*it
) += it
->len
;
7298 IT_CHARPOS (*it
) += 1;
7302 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7303 /* If this is a new paragraph, determine its base
7304 direction (a.k.a. its base embedding level). */
7305 if (it
->bidi_it
.new_paragraph
)
7306 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7307 bidi_move_to_visually_next (&it
->bidi_it
);
7308 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7309 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7310 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7312 /* As the scan direction was changed, we must
7313 re-compute the stop position for composition. */
7314 ptrdiff_t stop
= it
->end_charpos
;
7315 if (it
->bidi_it
.scan_dir
< 0)
7317 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7318 IT_BYTEPOS (*it
), stop
, Qnil
);
7321 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7325 case GET_FROM_C_STRING
:
7326 /* Current display element of IT is from a C string. */
7328 /* If the string position is beyond string's end, it means
7329 next_element_from_c_string is padding the string with
7330 blanks, in which case we bypass the bidi iterator,
7331 because it cannot deal with such virtual characters. */
7332 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7334 IT_BYTEPOS (*it
) += it
->len
;
7335 IT_CHARPOS (*it
) += 1;
7339 bidi_move_to_visually_next (&it
->bidi_it
);
7340 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7341 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7345 case GET_FROM_DISPLAY_VECTOR
:
7346 /* Current display element of IT is from a display table entry.
7347 Advance in the display table definition. Reset it to null if
7348 end reached, and continue with characters from buffers/
7350 ++it
->current
.dpvec_index
;
7352 /* Restore face of the iterator to what they were before the
7353 display vector entry (these entries may contain faces). */
7354 it
->face_id
= it
->saved_face_id
;
7356 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7358 int recheck_faces
= it
->ellipsis_p
;
7361 it
->method
= GET_FROM_C_STRING
;
7362 else if (STRINGP (it
->string
))
7363 it
->method
= GET_FROM_STRING
;
7366 it
->method
= GET_FROM_BUFFER
;
7367 it
->object
= it
->w
->contents
;
7371 it
->current
.dpvec_index
= -1;
7373 /* Skip over characters which were displayed via IT->dpvec. */
7374 if (it
->dpvec_char_len
< 0)
7375 reseat_at_next_visible_line_start (it
, 1);
7376 else if (it
->dpvec_char_len
> 0)
7378 if (it
->method
== GET_FROM_STRING
7379 && it
->current
.overlay_string_index
>= 0
7380 && it
->n_overlay_strings
> 0)
7381 it
->ignore_overlay_strings_at_pos_p
= true;
7382 it
->len
= it
->dpvec_char_len
;
7383 set_iterator_to_next (it
, reseat_p
);
7386 /* Maybe recheck faces after display vector. */
7388 it
->stop_charpos
= IT_CHARPOS (*it
);
7392 case GET_FROM_STRING
:
7393 /* Current display element is a character from a Lisp string. */
7394 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7395 /* Don't advance past string end. These conditions are true
7396 when set_iterator_to_next is called at the end of
7397 get_next_display_element, in which case the Lisp string is
7398 already exhausted, and all we want is pop the iterator
7400 if (it
->current
.overlay_string_index
>= 0)
7402 /* This is an overlay string, so there's no padding with
7403 spaces, and the number of characters in the string is
7404 where the string ends. */
7405 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7406 goto consider_string_end
;
7410 /* Not an overlay string. There could be padding, so test
7411 against it->end_charpos. */
7412 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7413 goto consider_string_end
;
7415 if (it
->cmp_it
.id
>= 0)
7417 /* We are delivering display elements from a composition.
7418 Update the string position past the grapheme cluster
7419 we've just processed. */
7422 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7423 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7429 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7430 bidi_move_to_visually_next (&it
->bidi_it
);
7431 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7432 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7435 /* Did we exhaust all the grapheme clusters of this
7437 if ((! it
->bidi_p
|| ! it
->cmp_it
.reversed_p
)
7438 && (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
))
7440 /* Not all the grapheme clusters were processed yet;
7441 advance to the next cluster. */
7442 it
->cmp_it
.from
= it
->cmp_it
.to
;
7444 else if ((it
->bidi_p
&& it
->cmp_it
.reversed_p
)
7445 && it
->cmp_it
.from
> 0)
7447 /* Likewise: advance to the next cluster, but going in
7448 the reverse direction. */
7449 it
->cmp_it
.to
= it
->cmp_it
.from
;
7453 /* This composition was fully processed; find the next
7454 candidate place for checking for composed
7456 /* Always limit string searches to the string length;
7457 any padding spaces are not part of the string, and
7458 there cannot be any compositions in that padding. */
7459 ptrdiff_t stop
= SCHARS (it
->string
);
7461 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
7463 else if (it
->end_charpos
< stop
)
7465 /* Cf. PRECISION in reseat_to_string: we might be
7466 limited in how many of the string characters we
7468 stop
= it
->end_charpos
;
7470 composition_compute_stop_pos (&it
->cmp_it
,
7471 IT_STRING_CHARPOS (*it
),
7472 IT_STRING_BYTEPOS (*it
), stop
,
7479 /* If the string position is beyond string's end, it
7480 means next_element_from_string is padding the string
7481 with blanks, in which case we bypass the bidi
7482 iterator, because it cannot deal with such virtual
7484 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7486 IT_STRING_BYTEPOS (*it
) += it
->len
;
7487 IT_STRING_CHARPOS (*it
) += 1;
7491 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7493 bidi_move_to_visually_next (&it
->bidi_it
);
7494 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7495 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7496 /* If the scan direction changes, we may need to update
7497 the place where to check for composed characters. */
7498 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7500 ptrdiff_t stop
= SCHARS (it
->string
);
7502 if (it
->bidi_it
.scan_dir
< 0)
7504 else if (it
->end_charpos
< stop
)
7505 stop
= it
->end_charpos
;
7507 composition_compute_stop_pos (&it
->cmp_it
,
7508 IT_STRING_CHARPOS (*it
),
7509 IT_STRING_BYTEPOS (*it
), stop
,
7515 consider_string_end
:
7517 if (it
->current
.overlay_string_index
>= 0)
7519 /* IT->string is an overlay string. Advance to the
7520 next, if there is one. */
7521 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7524 next_overlay_string (it
);
7526 setup_for_ellipsis (it
, 0);
7531 /* IT->string is not an overlay string. If we reached
7532 its end, and there is something on IT->stack, proceed
7533 with what is on the stack. This can be either another
7534 string, this time an overlay string, or a buffer. */
7535 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7539 if (it
->method
== GET_FROM_STRING
)
7540 goto consider_string_end
;
7545 case GET_FROM_IMAGE
:
7546 case GET_FROM_STRETCH
:
7547 /* The position etc with which we have to proceed are on
7548 the stack. The position may be at the end of a string,
7549 if the `display' property takes up the whole string. */
7550 eassert (it
->sp
> 0);
7552 if (it
->method
== GET_FROM_STRING
)
7553 goto consider_string_end
;
7557 /* There are no other methods defined, so this should be a bug. */
7561 eassert (it
->method
!= GET_FROM_STRING
7562 || (STRINGP (it
->string
)
7563 && IT_STRING_CHARPOS (*it
) >= 0));
7566 /* Load IT's display element fields with information about the next
7567 display element which comes from a display table entry or from the
7568 result of translating a control character to one of the forms `^C'
7571 IT->dpvec holds the glyphs to return as characters.
7572 IT->saved_face_id holds the face id before the display vector--it
7573 is restored into IT->face_id in set_iterator_to_next. */
7576 next_element_from_display_vector (struct it
*it
)
7579 int prev_face_id
= it
->face_id
;
7583 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7585 it
->face_id
= it
->saved_face_id
;
7587 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7588 That seemed totally bogus - so I changed it... */
7589 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7591 if (GLYPH_CODE_P (gc
))
7593 struct face
*this_face
, *prev_face
, *next_face
;
7595 it
->c
= GLYPH_CODE_CHAR (gc
);
7596 it
->len
= CHAR_BYTES (it
->c
);
7598 /* The entry may contain a face id to use. Such a face id is
7599 the id of a Lisp face, not a realized face. A face id of
7600 zero means no face is specified. */
7601 if (it
->dpvec_face_id
>= 0)
7602 it
->face_id
= it
->dpvec_face_id
;
7605 int lface_id
= GLYPH_CODE_FACE (gc
);
7607 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7611 /* Glyphs in the display vector could have the box face, so we
7612 need to set the related flags in the iterator, as
7614 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7615 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7617 /* Is this character the first character of a box-face run? */
7618 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7620 || prev_face
->box
== FACE_NO_BOX
));
7622 /* For the last character of the box-face run, we need to look
7623 either at the next glyph from the display vector, or at the
7624 face we saw before the display vector. */
7625 next_face_id
= it
->saved_face_id
;
7626 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7628 if (it
->dpvec_face_id
>= 0)
7629 next_face_id
= it
->dpvec_face_id
;
7633 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7636 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7640 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7641 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7643 || next_face
->box
== FACE_NO_BOX
));
7644 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7647 /* Display table entry is invalid. Return a space. */
7648 it
->c
= ' ', it
->len
= 1;
7650 /* Don't change position and object of the iterator here. They are
7651 still the values of the character that had this display table
7652 entry or was translated, and that's what we want. */
7653 it
->what
= IT_CHARACTER
;
7657 /* Get the first element of string/buffer in the visual order, after
7658 being reseated to a new position in a string or a buffer. */
7660 get_visually_first_element (struct it
*it
)
7662 int string_p
= STRINGP (it
->string
) || it
->s
;
7663 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7664 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7666 if (STRINGP (it
->string
))
7668 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7669 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7673 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7674 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7677 if (it
->bidi_it
.charpos
== eob
)
7679 /* Nothing to do, but reset the FIRST_ELT flag, like
7680 bidi_paragraph_init does, because we are not going to
7682 it
->bidi_it
.first_elt
= 0;
7684 else if (it
->bidi_it
.charpos
== bob
7686 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7687 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7689 /* If we are at the beginning of a line/string, we can produce
7690 the next element right away. */
7691 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7692 bidi_move_to_visually_next (&it
->bidi_it
);
7696 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7698 /* We need to prime the bidi iterator starting at the line's or
7699 string's beginning, before we will be able to produce the
7702 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7704 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7705 IT_BYTEPOS (*it
), -1,
7706 &it
->bidi_it
.bytepos
);
7707 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7710 /* Now return to buffer/string position where we were asked
7711 to get the next display element, and produce that. */
7712 bidi_move_to_visually_next (&it
->bidi_it
);
7714 while (it
->bidi_it
.bytepos
!= orig_bytepos
7715 && it
->bidi_it
.charpos
< eob
);
7718 /* Adjust IT's position information to where we ended up. */
7719 if (STRINGP (it
->string
))
7721 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7722 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7726 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7727 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7730 if (STRINGP (it
->string
) || !it
->s
)
7732 ptrdiff_t stop
, charpos
, bytepos
;
7734 if (STRINGP (it
->string
))
7737 stop
= SCHARS (it
->string
);
7738 if (stop
> it
->end_charpos
)
7739 stop
= it
->end_charpos
;
7740 charpos
= IT_STRING_CHARPOS (*it
);
7741 bytepos
= IT_STRING_BYTEPOS (*it
);
7745 stop
= it
->end_charpos
;
7746 charpos
= IT_CHARPOS (*it
);
7747 bytepos
= IT_BYTEPOS (*it
);
7749 if (it
->bidi_it
.scan_dir
< 0)
7751 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7756 /* Load IT with the next display element from Lisp string IT->string.
7757 IT->current.string_pos is the current position within the string.
7758 If IT->current.overlay_string_index >= 0, the Lisp string is an
7762 next_element_from_string (struct it
*it
)
7764 struct text_pos position
;
7766 eassert (STRINGP (it
->string
));
7767 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7768 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7769 position
= it
->current
.string_pos
;
7771 /* With bidi reordering, the character to display might not be the
7772 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7773 that we were reseat()ed to a new string, whose paragraph
7774 direction is not known. */
7775 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7777 get_visually_first_element (it
);
7778 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7781 /* Time to check for invisible text? */
7782 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7784 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7787 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7788 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7790 /* With bidi non-linear iteration, we could find
7791 ourselves far beyond the last computed stop_charpos,
7792 with several other stop positions in between that we
7793 missed. Scan them all now, in buffer's logical
7794 order, until we find and handle the last stop_charpos
7795 that precedes our current position. */
7796 handle_stop_backwards (it
, it
->stop_charpos
);
7797 return GET_NEXT_DISPLAY_ELEMENT (it
);
7803 /* Take note of the stop position we just moved
7804 across, for when we will move back across it. */
7805 it
->prev_stop
= it
->stop_charpos
;
7806 /* If we are at base paragraph embedding level, take
7807 note of the last stop position seen at this
7809 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7810 it
->base_level_stop
= it
->stop_charpos
;
7814 /* Since a handler may have changed IT->method, we must
7816 return GET_NEXT_DISPLAY_ELEMENT (it
);
7820 /* If we are before prev_stop, we may have overstepped
7821 on our way backwards a stop_pos, and if so, we need
7822 to handle that stop_pos. */
7823 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7824 /* We can sometimes back up for reasons that have nothing
7825 to do with bidi reordering. E.g., compositions. The
7826 code below is only needed when we are above the base
7827 embedding level, so test for that explicitly. */
7828 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7830 /* If we lost track of base_level_stop, we have no better
7831 place for handle_stop_backwards to start from than string
7832 beginning. This happens, e.g., when we were reseated to
7833 the previous screenful of text by vertical-motion. */
7834 if (it
->base_level_stop
<= 0
7835 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7836 it
->base_level_stop
= 0;
7837 handle_stop_backwards (it
, it
->base_level_stop
);
7838 return GET_NEXT_DISPLAY_ELEMENT (it
);
7842 if (it
->current
.overlay_string_index
>= 0)
7844 /* Get the next character from an overlay string. In overlay
7845 strings, there is no field width or padding with spaces to
7847 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7852 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7853 IT_STRING_BYTEPOS (*it
),
7854 it
->bidi_it
.scan_dir
< 0
7856 : SCHARS (it
->string
))
7857 && next_element_from_composition (it
))
7861 else if (STRING_MULTIBYTE (it
->string
))
7863 const unsigned char *s
= (SDATA (it
->string
)
7864 + IT_STRING_BYTEPOS (*it
));
7865 it
->c
= string_char_and_length (s
, &it
->len
);
7869 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7875 /* Get the next character from a Lisp string that is not an
7876 overlay string. Such strings come from the mode line, for
7877 example. We may have to pad with spaces, or truncate the
7878 string. See also next_element_from_c_string. */
7879 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7884 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7886 /* Pad with spaces. */
7887 it
->c
= ' ', it
->len
= 1;
7888 CHARPOS (position
) = BYTEPOS (position
) = -1;
7890 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7891 IT_STRING_BYTEPOS (*it
),
7892 it
->bidi_it
.scan_dir
< 0
7894 : it
->string_nchars
)
7895 && next_element_from_composition (it
))
7899 else if (STRING_MULTIBYTE (it
->string
))
7901 const unsigned char *s
= (SDATA (it
->string
)
7902 + IT_STRING_BYTEPOS (*it
));
7903 it
->c
= string_char_and_length (s
, &it
->len
);
7907 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7912 /* Record what we have and where it came from. */
7913 it
->what
= IT_CHARACTER
;
7914 it
->object
= it
->string
;
7915 it
->position
= position
;
7920 /* Load IT with next display element from C string IT->s.
7921 IT->string_nchars is the maximum number of characters to return
7922 from the string. IT->end_charpos may be greater than
7923 IT->string_nchars when this function is called, in which case we
7924 may have to return padding spaces. Value is zero if end of string
7925 reached, including padding spaces. */
7928 next_element_from_c_string (struct it
*it
)
7930 bool success_p
= true;
7933 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7934 it
->what
= IT_CHARACTER
;
7935 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7938 /* With bidi reordering, the character to display might not be the
7939 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7940 we were reseated to a new string, whose paragraph direction is
7942 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7943 get_visually_first_element (it
);
7945 /* IT's position can be greater than IT->string_nchars in case a
7946 field width or precision has been specified when the iterator was
7948 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7950 /* End of the game. */
7954 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7956 /* Pad with spaces. */
7957 it
->c
= ' ', it
->len
= 1;
7958 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7960 else if (it
->multibyte_p
)
7961 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7963 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7969 /* Set up IT to return characters from an ellipsis, if appropriate.
7970 The definition of the ellipsis glyphs may come from a display table
7971 entry. This function fills IT with the first glyph from the
7972 ellipsis if an ellipsis is to be displayed. */
7975 next_element_from_ellipsis (struct it
*it
)
7977 if (it
->selective_display_ellipsis_p
)
7978 setup_for_ellipsis (it
, it
->len
);
7981 /* The face at the current position may be different from the
7982 face we find after the invisible text. Remember what it
7983 was in IT->saved_face_id, and signal that it's there by
7984 setting face_before_selective_p. */
7985 it
->saved_face_id
= it
->face_id
;
7986 it
->method
= GET_FROM_BUFFER
;
7987 it
->object
= it
->w
->contents
;
7988 reseat_at_next_visible_line_start (it
, 1);
7989 it
->face_before_selective_p
= true;
7992 return GET_NEXT_DISPLAY_ELEMENT (it
);
7996 /* Deliver an image display element. The iterator IT is already
7997 filled with image information (done in handle_display_prop). Value
8002 next_element_from_image (struct it
*it
)
8004 it
->what
= IT_IMAGE
;
8005 it
->ignore_overlay_strings_at_pos_p
= 0;
8010 /* Fill iterator IT with next display element from a stretch glyph
8011 property. IT->object is the value of the text property. Value is
8015 next_element_from_stretch (struct it
*it
)
8017 it
->what
= IT_STRETCH
;
8021 /* Scan backwards from IT's current position until we find a stop
8022 position, or until BEGV. This is called when we find ourself
8023 before both the last known prev_stop and base_level_stop while
8024 reordering bidirectional text. */
8027 compute_stop_pos_backwards (struct it
*it
)
8029 const int SCAN_BACK_LIMIT
= 1000;
8030 struct text_pos pos
;
8031 struct display_pos save_current
= it
->current
;
8032 struct text_pos save_position
= it
->position
;
8033 ptrdiff_t charpos
= IT_CHARPOS (*it
);
8034 ptrdiff_t where_we_are
= charpos
;
8035 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
8036 ptrdiff_t save_end_pos
= it
->end_charpos
;
8038 eassert (NILP (it
->string
) && !it
->s
);
8039 eassert (it
->bidi_p
);
8043 it
->end_charpos
= min (charpos
+ 1, ZV
);
8044 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
8045 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
8046 reseat_1 (it
, pos
, 0);
8047 compute_stop_pos (it
);
8048 /* We must advance forward, right? */
8049 if (it
->stop_charpos
<= charpos
)
8052 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
8054 if (it
->stop_charpos
<= where_we_are
)
8055 it
->prev_stop
= it
->stop_charpos
;
8057 it
->prev_stop
= BEGV
;
8059 it
->current
= save_current
;
8060 it
->position
= save_position
;
8061 it
->stop_charpos
= save_stop_pos
;
8062 it
->end_charpos
= save_end_pos
;
8065 /* Scan forward from CHARPOS in the current buffer/string, until we
8066 find a stop position > current IT's position. Then handle the stop
8067 position before that. This is called when we bump into a stop
8068 position while reordering bidirectional text. CHARPOS should be
8069 the last previously processed stop_pos (or BEGV/0, if none were
8070 processed yet) whose position is less that IT's current
8074 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
8076 int bufp
= !STRINGP (it
->string
);
8077 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
8078 struct display_pos save_current
= it
->current
;
8079 struct text_pos save_position
= it
->position
;
8080 struct text_pos pos1
;
8081 ptrdiff_t next_stop
;
8083 /* Scan in strict logical order. */
8084 eassert (it
->bidi_p
);
8088 it
->prev_stop
= charpos
;
8091 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
8092 reseat_1 (it
, pos1
, 0);
8095 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
8096 compute_stop_pos (it
);
8097 /* We must advance forward, right? */
8098 if (it
->stop_charpos
<= it
->prev_stop
)
8100 charpos
= it
->stop_charpos
;
8102 while (charpos
<= where_we_are
);
8105 it
->current
= save_current
;
8106 it
->position
= save_position
;
8107 next_stop
= it
->stop_charpos
;
8108 it
->stop_charpos
= it
->prev_stop
;
8110 it
->stop_charpos
= next_stop
;
8113 /* Load IT with the next display element from current_buffer. Value
8114 is zero if end of buffer reached. IT->stop_charpos is the next
8115 position at which to stop and check for text properties or buffer
8119 next_element_from_buffer (struct it
*it
)
8121 bool success_p
= true;
8123 eassert (IT_CHARPOS (*it
) >= BEGV
);
8124 eassert (NILP (it
->string
) && !it
->s
);
8125 eassert (!it
->bidi_p
8126 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8127 && it
->bidi_it
.string
.s
== NULL
));
8129 /* With bidi reordering, the character to display might not be the
8130 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8131 we were reseat()ed to a new buffer position, which is potentially
8132 a different paragraph. */
8133 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8135 get_visually_first_element (it
);
8136 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8139 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8141 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8143 int overlay_strings_follow_p
;
8145 /* End of the game, except when overlay strings follow that
8146 haven't been returned yet. */
8147 if (it
->overlay_strings_at_end_processed_p
)
8148 overlay_strings_follow_p
= 0;
8151 it
->overlay_strings_at_end_processed_p
= true;
8152 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8155 if (overlay_strings_follow_p
)
8156 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8160 it
->position
= it
->current
.pos
;
8164 else if (!(!it
->bidi_p
8165 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8166 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8168 /* With bidi non-linear iteration, we could find ourselves
8169 far beyond the last computed stop_charpos, with several
8170 other stop positions in between that we missed. Scan
8171 them all now, in buffer's logical order, until we find
8172 and handle the last stop_charpos that precedes our
8173 current position. */
8174 handle_stop_backwards (it
, it
->stop_charpos
);
8175 return GET_NEXT_DISPLAY_ELEMENT (it
);
8181 /* Take note of the stop position we just moved across,
8182 for when we will move back across it. */
8183 it
->prev_stop
= it
->stop_charpos
;
8184 /* If we are at base paragraph embedding level, take
8185 note of the last stop position seen at this
8187 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8188 it
->base_level_stop
= it
->stop_charpos
;
8191 return GET_NEXT_DISPLAY_ELEMENT (it
);
8195 /* If we are before prev_stop, we may have overstepped on
8196 our way backwards a stop_pos, and if so, we need to
8197 handle that stop_pos. */
8198 && IT_CHARPOS (*it
) < it
->prev_stop
8199 /* We can sometimes back up for reasons that have nothing
8200 to do with bidi reordering. E.g., compositions. The
8201 code below is only needed when we are above the base
8202 embedding level, so test for that explicitly. */
8203 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8205 if (it
->base_level_stop
<= 0
8206 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8208 /* If we lost track of base_level_stop, we need to find
8209 prev_stop by looking backwards. This happens, e.g., when
8210 we were reseated to the previous screenful of text by
8212 it
->base_level_stop
= BEGV
;
8213 compute_stop_pos_backwards (it
);
8214 handle_stop_backwards (it
, it
->prev_stop
);
8217 handle_stop_backwards (it
, it
->base_level_stop
);
8218 return GET_NEXT_DISPLAY_ELEMENT (it
);
8222 /* No face changes, overlays etc. in sight, so just return a
8223 character from current_buffer. */
8227 /* We moved to the next buffer position, so any info about
8228 previously seen overlays is no longer valid. */
8229 it
->ignore_overlay_strings_at_pos_p
= 0;
8231 /* Maybe run the redisplay end trigger hook. Performance note:
8232 This doesn't seem to cost measurable time. */
8233 if (it
->redisplay_end_trigger_charpos
8235 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8236 run_redisplay_end_trigger_hook (it
);
8238 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8239 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8241 && next_element_from_composition (it
))
8246 /* Get the next character, maybe multibyte. */
8247 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8248 if (it
->multibyte_p
&& !ASCII_CHAR_P (*p
))
8249 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8251 it
->c
= *p
, it
->len
= 1;
8253 /* Record what we have and where it came from. */
8254 it
->what
= IT_CHARACTER
;
8255 it
->object
= it
->w
->contents
;
8256 it
->position
= it
->current
.pos
;
8258 /* Normally we return the character found above, except when we
8259 really want to return an ellipsis for selective display. */
8264 /* A value of selective > 0 means hide lines indented more
8265 than that number of columns. */
8266 if (it
->selective
> 0
8267 && IT_CHARPOS (*it
) + 1 < ZV
8268 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8269 IT_BYTEPOS (*it
) + 1,
8272 success_p
= next_element_from_ellipsis (it
);
8273 it
->dpvec_char_len
= -1;
8276 else if (it
->c
== '\r' && it
->selective
== -1)
8278 /* A value of selective == -1 means that everything from the
8279 CR to the end of the line is invisible, with maybe an
8280 ellipsis displayed for it. */
8281 success_p
= next_element_from_ellipsis (it
);
8282 it
->dpvec_char_len
= -1;
8287 /* Value is zero if end of buffer reached. */
8288 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8293 /* Run the redisplay end trigger hook for IT. */
8296 run_redisplay_end_trigger_hook (struct it
*it
)
8298 Lisp_Object args
[3];
8300 /* IT->glyph_row should be non-null, i.e. we should be actually
8301 displaying something, or otherwise we should not run the hook. */
8302 eassert (it
->glyph_row
);
8304 /* Set up hook arguments. */
8305 args
[0] = Qredisplay_end_trigger_functions
;
8306 args
[1] = it
->window
;
8307 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8308 it
->redisplay_end_trigger_charpos
= 0;
8310 /* Since we are *trying* to run these functions, don't try to run
8311 them again, even if they get an error. */
8312 wset_redisplay_end_trigger (it
->w
, Qnil
);
8313 Frun_hook_with_args (3, args
);
8315 /* Notice if it changed the face of the character we are on. */
8316 handle_face_prop (it
);
8320 /* Deliver a composition display element. Unlike the other
8321 next_element_from_XXX, this function is not registered in the array
8322 get_next_element[]. It is called from next_element_from_buffer and
8323 next_element_from_string when necessary. */
8326 next_element_from_composition (struct it
*it
)
8328 it
->what
= IT_COMPOSITION
;
8329 it
->len
= it
->cmp_it
.nbytes
;
8330 if (STRINGP (it
->string
))
8334 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8335 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8338 it
->position
= it
->current
.string_pos
;
8339 it
->object
= it
->string
;
8340 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8341 IT_STRING_BYTEPOS (*it
), it
->string
);
8347 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8348 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8351 if (it
->bidi_it
.new_paragraph
)
8352 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8353 /* Resync the bidi iterator with IT's new position.
8354 FIXME: this doesn't support bidirectional text. */
8355 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8356 bidi_move_to_visually_next (&it
->bidi_it
);
8360 it
->position
= it
->current
.pos
;
8361 it
->object
= it
->w
->contents
;
8362 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8363 IT_BYTEPOS (*it
), Qnil
);
8370 /***********************************************************************
8371 Moving an iterator without producing glyphs
8372 ***********************************************************************/
8374 /* Check if iterator is at a position corresponding to a valid buffer
8375 position after some move_it_ call. */
8377 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8378 ((it)->method == GET_FROM_STRING \
8379 ? IT_STRING_CHARPOS (*it) == 0 \
8383 /* Move iterator IT to a specified buffer or X position within one
8384 line on the display without producing glyphs.
8386 OP should be a bit mask including some or all of these bits:
8387 MOVE_TO_X: Stop upon reaching x-position TO_X.
8388 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8389 Regardless of OP's value, stop upon reaching the end of the display line.
8391 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8392 This means, in particular, that TO_X includes window's horizontal
8395 The return value has several possible values that
8396 say what condition caused the scan to stop:
8398 MOVE_POS_MATCH_OR_ZV
8399 - when TO_POS or ZV was reached.
8402 -when TO_X was reached before TO_POS or ZV were reached.
8405 - when we reached the end of the display area and the line must
8409 - when we reached the end of the display area and the line is
8413 - when we stopped at a line end, i.e. a newline or a CR and selective
8416 static enum move_it_result
8417 move_it_in_display_line_to (struct it
*it
,
8418 ptrdiff_t to_charpos
, int to_x
,
8419 enum move_operation_enum op
)
8421 enum move_it_result result
= MOVE_UNDEFINED
;
8422 struct glyph_row
*saved_glyph_row
;
8423 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8424 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8425 void *ppos_data
= NULL
;
8427 enum it_method prev_method
= it
->method
;
8428 ptrdiff_t closest_pos
IF_LINT (= 0), prev_pos
= IT_CHARPOS (*it
);
8429 int saw_smaller_pos
= prev_pos
< to_charpos
;
8431 /* Don't produce glyphs in produce_glyphs. */
8432 saved_glyph_row
= it
->glyph_row
;
8433 it
->glyph_row
= NULL
;
8435 /* Use wrap_it to save a copy of IT wherever a word wrap could
8436 occur. Use atpos_it to save a copy of IT at the desired buffer
8437 position, if found, so that we can scan ahead and check if the
8438 word later overshoots the window edge. Use atx_it similarly, for
8444 /* Use ppos_it under bidi reordering to save a copy of IT for the
8445 initial position. We restore that position in IT when we have
8446 scanned the entire display line without finding a match for
8447 TO_CHARPOS and all the character positions are greater than
8448 TO_CHARPOS. We then restart the scan from the initial position,
8449 and stop at CLOSEST_POS, which is a position > TO_CHARPOS that is
8450 the closest to TO_CHARPOS. */
8453 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8455 SAVE_IT (ppos_it
, *it
, ppos_data
);
8456 closest_pos
= IT_CHARPOS (*it
);
8462 #define BUFFER_POS_REACHED_P() \
8463 ((op & MOVE_TO_POS) != 0 \
8464 && BUFFERP (it->object) \
8465 && (IT_CHARPOS (*it) == to_charpos \
8467 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8468 && IT_CHARPOS (*it) > to_charpos) \
8469 || (it->what == IT_COMPOSITION \
8470 && ((IT_CHARPOS (*it) > to_charpos \
8471 && to_charpos >= it->cmp_it.charpos) \
8472 || (IT_CHARPOS (*it) < to_charpos \
8473 && to_charpos <= it->cmp_it.charpos)))) \
8474 && (it->method == GET_FROM_BUFFER \
8475 || (it->method == GET_FROM_DISPLAY_VECTOR \
8476 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8478 /* If there's a line-/wrap-prefix, handle it. */
8479 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8480 && it
->current_y
< it
->last_visible_y
)
8481 handle_line_prefix (it
);
8483 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8484 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8488 int x
, i
, ascent
= 0, descent
= 0;
8490 /* Utility macro to reset an iterator with x, ascent, and descent. */
8491 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8492 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8493 (IT)->max_descent = descent)
8495 /* Stop if we move beyond TO_CHARPOS (after an image or a
8496 display string or stretch glyph). */
8497 if ((op
& MOVE_TO_POS
) != 0
8498 && BUFFERP (it
->object
)
8499 && it
->method
== GET_FROM_BUFFER
8501 /* When the iterator is at base embedding level, we
8502 are guaranteed that characters are delivered for
8503 display in strictly increasing order of their
8504 buffer positions. */
8505 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8506 && IT_CHARPOS (*it
) > to_charpos
)
8508 && (prev_method
== GET_FROM_IMAGE
8509 || prev_method
== GET_FROM_STRETCH
8510 || prev_method
== GET_FROM_STRING
)
8511 /* Passed TO_CHARPOS from left to right. */
8512 && ((prev_pos
< to_charpos
8513 && IT_CHARPOS (*it
) > to_charpos
)
8514 /* Passed TO_CHARPOS from right to left. */
8515 || (prev_pos
> to_charpos
8516 && IT_CHARPOS (*it
) < to_charpos
)))))
8518 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8520 result
= MOVE_POS_MATCH_OR_ZV
;
8523 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8524 /* If wrap_it is valid, the current position might be in a
8525 word that is wrapped. So, save the iterator in
8526 atpos_it and continue to see if wrapping happens. */
8527 SAVE_IT (atpos_it
, *it
, atpos_data
);
8530 /* Stop when ZV reached.
8531 We used to stop here when TO_CHARPOS reached as well, but that is
8532 too soon if this glyph does not fit on this line. So we handle it
8533 explicitly below. */
8534 if (!get_next_display_element (it
))
8536 result
= MOVE_POS_MATCH_OR_ZV
;
8540 if (it
->line_wrap
== TRUNCATE
)
8542 if (BUFFER_POS_REACHED_P ())
8544 result
= MOVE_POS_MATCH_OR_ZV
;
8550 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
8552 if (IT_DISPLAYING_WHITESPACE (it
))
8556 /* We have reached a glyph that follows one or more
8557 whitespace characters. If the position is
8558 already found, we are done. */
8559 if (atpos_it
.sp
>= 0)
8561 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8562 result
= MOVE_POS_MATCH_OR_ZV
;
8567 RESTORE_IT (it
, &atx_it
, atx_data
);
8568 result
= MOVE_X_REACHED
;
8571 /* Otherwise, we can wrap here. */
8572 SAVE_IT (wrap_it
, *it
, wrap_data
);
8578 /* Remember the line height for the current line, in case
8579 the next element doesn't fit on the line. */
8580 ascent
= it
->max_ascent
;
8581 descent
= it
->max_descent
;
8583 /* The call to produce_glyphs will get the metrics of the
8584 display element IT is loaded with. Record the x-position
8585 before this display element, in case it doesn't fit on the
8589 PRODUCE_GLYPHS (it
);
8591 if (it
->area
!= TEXT_AREA
)
8593 prev_method
= it
->method
;
8594 if (it
->method
== GET_FROM_BUFFER
)
8595 prev_pos
= IT_CHARPOS (*it
);
8596 set_iterator_to_next (it
, 1);
8597 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8598 SET_TEXT_POS (this_line_min_pos
,
8599 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8601 && (op
& MOVE_TO_POS
)
8602 && IT_CHARPOS (*it
) > to_charpos
8603 && IT_CHARPOS (*it
) < closest_pos
)
8604 closest_pos
= IT_CHARPOS (*it
);
8608 /* The number of glyphs we get back in IT->nglyphs will normally
8609 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8610 character on a terminal frame, or (iii) a line end. For the
8611 second case, IT->nglyphs - 1 padding glyphs will be present.
8612 (On X frames, there is only one glyph produced for a
8613 composite character.)
8615 The behavior implemented below means, for continuation lines,
8616 that as many spaces of a TAB as fit on the current line are
8617 displayed there. For terminal frames, as many glyphs of a
8618 multi-glyph character are displayed in the current line, too.
8619 This is what the old redisplay code did, and we keep it that
8620 way. Under X, the whole shape of a complex character must
8621 fit on the line or it will be completely displayed in the
8624 Note that both for tabs and padding glyphs, all glyphs have
8628 /* More than one glyph or glyph doesn't fit on line. All
8629 glyphs have the same width. */
8630 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8632 int x_before_this_char
= x
;
8633 int hpos_before_this_char
= it
->hpos
;
8635 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8637 new_x
= x
+ single_glyph_width
;
8639 /* We want to leave anything reaching TO_X to the caller. */
8640 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8642 if (BUFFER_POS_REACHED_P ())
8644 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8645 goto buffer_pos_reached
;
8646 if (atpos_it
.sp
< 0)
8648 SAVE_IT (atpos_it
, *it
, atpos_data
);
8649 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8654 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8657 result
= MOVE_X_REACHED
;
8662 SAVE_IT (atx_it
, *it
, atx_data
);
8663 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8668 if (/* Lines are continued. */
8669 it
->line_wrap
!= TRUNCATE
8670 && (/* And glyph doesn't fit on the line. */
8671 new_x
> it
->last_visible_x
8672 /* Or it fits exactly and we're on a window
8674 || (new_x
== it
->last_visible_x
8675 && FRAME_WINDOW_P (it
->f
)
8676 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8677 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8678 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8680 if (/* IT->hpos == 0 means the very first glyph
8681 doesn't fit on the line, e.g. a wide image. */
8683 || (new_x
== it
->last_visible_x
8684 && FRAME_WINDOW_P (it
->f
)))
8687 it
->current_x
= new_x
;
8689 /* The character's last glyph just barely fits
8691 if (i
== it
->nglyphs
- 1)
8693 /* If this is the destination position,
8694 return a position *before* it in this row,
8695 now that we know it fits in this row. */
8696 if (BUFFER_POS_REACHED_P ())
8698 if (it
->line_wrap
!= WORD_WRAP
8701 it
->hpos
= hpos_before_this_char
;
8702 it
->current_x
= x_before_this_char
;
8703 result
= MOVE_POS_MATCH_OR_ZV
;
8706 if (it
->line_wrap
== WORD_WRAP
8709 SAVE_IT (atpos_it
, *it
, atpos_data
);
8710 atpos_it
.current_x
= x_before_this_char
;
8711 atpos_it
.hpos
= hpos_before_this_char
;
8715 prev_method
= it
->method
;
8716 if (it
->method
== GET_FROM_BUFFER
)
8717 prev_pos
= IT_CHARPOS (*it
);
8718 set_iterator_to_next (it
, 1);
8719 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8720 SET_TEXT_POS (this_line_min_pos
,
8721 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8722 /* On graphical terminals, newlines may
8723 "overflow" into the fringe if
8724 overflow-newline-into-fringe is non-nil.
8725 On text terminals, and on graphical
8726 terminals with no right margin, newlines
8727 may overflow into the last glyph on the
8729 if (!FRAME_WINDOW_P (it
->f
)
8731 && it
->bidi_it
.paragraph_dir
== R2L
)
8732 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8733 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8734 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8736 if (!get_next_display_element (it
))
8738 result
= MOVE_POS_MATCH_OR_ZV
;
8741 if (BUFFER_POS_REACHED_P ())
8743 if (ITERATOR_AT_END_OF_LINE_P (it
))
8744 result
= MOVE_POS_MATCH_OR_ZV
;
8746 result
= MOVE_LINE_CONTINUED
;
8749 if (ITERATOR_AT_END_OF_LINE_P (it
)
8750 && (it
->line_wrap
!= WORD_WRAP
8752 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)))
8754 result
= MOVE_NEWLINE_OR_CR
;
8761 IT_RESET_X_ASCENT_DESCENT (it
);
8763 if (wrap_it
.sp
>= 0)
8765 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8770 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8772 result
= MOVE_LINE_CONTINUED
;
8776 if (BUFFER_POS_REACHED_P ())
8778 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8779 goto buffer_pos_reached
;
8780 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8782 SAVE_IT (atpos_it
, *it
, atpos_data
);
8783 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8787 if (new_x
> it
->first_visible_x
)
8789 /* Glyph is visible. Increment number of glyphs that
8790 would be displayed. */
8795 if (result
!= MOVE_UNDEFINED
)
8798 else if (BUFFER_POS_REACHED_P ())
8801 IT_RESET_X_ASCENT_DESCENT (it
);
8802 result
= MOVE_POS_MATCH_OR_ZV
;
8805 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8807 /* Stop when TO_X specified and reached. This check is
8808 necessary here because of lines consisting of a line end,
8809 only. The line end will not produce any glyphs and we
8810 would never get MOVE_X_REACHED. */
8811 eassert (it
->nglyphs
== 0);
8812 result
= MOVE_X_REACHED
;
8816 /* Is this a line end? If yes, we're done. */
8817 if (ITERATOR_AT_END_OF_LINE_P (it
))
8819 /* If we are past TO_CHARPOS, but never saw any character
8820 positions smaller than TO_CHARPOS, return
8821 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8823 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8825 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8827 if (closest_pos
< ZV
)
8829 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8830 /* Don't recurse if closest_pos is equal to
8831 to_charpos, since we have just tried that. */
8832 if (closest_pos
!= to_charpos
)
8833 move_it_in_display_line_to (it
, closest_pos
, -1,
8835 result
= MOVE_POS_MATCH_OR_ZV
;
8838 goto buffer_pos_reached
;
8840 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8841 && IT_CHARPOS (*it
) > to_charpos
)
8842 goto buffer_pos_reached
;
8844 result
= MOVE_NEWLINE_OR_CR
;
8847 result
= MOVE_NEWLINE_OR_CR
;
8851 prev_method
= it
->method
;
8852 if (it
->method
== GET_FROM_BUFFER
)
8853 prev_pos
= IT_CHARPOS (*it
);
8854 /* The current display element has been consumed. Advance
8856 set_iterator_to_next (it
, 1);
8857 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8858 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8859 if (IT_CHARPOS (*it
) < to_charpos
)
8860 saw_smaller_pos
= 1;
8862 && (op
& MOVE_TO_POS
)
8863 && IT_CHARPOS (*it
) >= to_charpos
8864 && IT_CHARPOS (*it
) < closest_pos
)
8865 closest_pos
= IT_CHARPOS (*it
);
8867 /* Stop if lines are truncated and IT's current x-position is
8868 past the right edge of the window now. */
8869 if (it
->line_wrap
== TRUNCATE
8870 && it
->current_x
>= it
->last_visible_x
)
8872 if (!FRAME_WINDOW_P (it
->f
)
8873 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8874 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8875 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8876 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8880 if ((at_eob_p
= !get_next_display_element (it
))
8881 || BUFFER_POS_REACHED_P ()
8882 /* If we are past TO_CHARPOS, but never saw any
8883 character positions smaller than TO_CHARPOS,
8884 return MOVE_POS_MATCH_OR_ZV, like the
8885 unidirectional display did. */
8886 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8888 && IT_CHARPOS (*it
) > to_charpos
))
8891 && !BUFFER_POS_REACHED_P ()
8892 && !at_eob_p
&& closest_pos
< ZV
)
8894 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8895 if (closest_pos
!= to_charpos
)
8896 move_it_in_display_line_to (it
, closest_pos
, -1,
8899 result
= MOVE_POS_MATCH_OR_ZV
;
8902 if (ITERATOR_AT_END_OF_LINE_P (it
))
8904 result
= MOVE_NEWLINE_OR_CR
;
8908 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8910 && IT_CHARPOS (*it
) > to_charpos
)
8912 if (closest_pos
< ZV
)
8914 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8915 if (closest_pos
!= to_charpos
)
8916 move_it_in_display_line_to (it
, closest_pos
, -1,
8919 result
= MOVE_POS_MATCH_OR_ZV
;
8922 result
= MOVE_LINE_TRUNCATED
;
8925 #undef IT_RESET_X_ASCENT_DESCENT
8928 #undef BUFFER_POS_REACHED_P
8930 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8931 restore the saved iterator. */
8932 if (atpos_it
.sp
>= 0)
8933 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8934 else if (atx_it
.sp
>= 0)
8935 RESTORE_IT (it
, &atx_it
, atx_data
);
8940 bidi_unshelve_cache (atpos_data
, 1);
8942 bidi_unshelve_cache (atx_data
, 1);
8944 bidi_unshelve_cache (wrap_data
, 1);
8946 bidi_unshelve_cache (ppos_data
, 1);
8948 /* Restore the iterator settings altered at the beginning of this
8950 it
->glyph_row
= saved_glyph_row
;
8954 /* For external use. */
8956 move_it_in_display_line (struct it
*it
,
8957 ptrdiff_t to_charpos
, int to_x
,
8958 enum move_operation_enum op
)
8960 if (it
->line_wrap
== WORD_WRAP
8961 && (op
& MOVE_TO_X
))
8964 void *save_data
= NULL
;
8967 SAVE_IT (save_it
, *it
, save_data
);
8968 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8969 /* When word-wrap is on, TO_X may lie past the end
8970 of a wrapped line. Then it->current is the
8971 character on the next line, so backtrack to the
8972 space before the wrap point. */
8973 if (skip
== MOVE_LINE_CONTINUED
)
8975 int prev_x
= max (it
->current_x
- 1, 0);
8976 RESTORE_IT (it
, &save_it
, save_data
);
8977 move_it_in_display_line_to
8978 (it
, -1, prev_x
, MOVE_TO_X
);
8981 bidi_unshelve_cache (save_data
, 1);
8984 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8988 /* Move IT forward until it satisfies one or more of the criteria in
8989 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8991 OP is a bit-mask that specifies where to stop, and in particular,
8992 which of those four position arguments makes a difference. See the
8993 description of enum move_operation_enum.
8995 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8996 screen line, this function will set IT to the next position that is
8997 displayed to the right of TO_CHARPOS on the screen.
8999 Return the maximum pixel length of any line scanned but never more
9000 than it.last_visible_x. */
9003 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
9005 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
9006 int line_height
, line_start_x
= 0, reached
= 0;
9007 int max_current_x
= 0;
9008 void *backup_data
= NULL
;
9012 if (op
& MOVE_TO_VPOS
)
9014 /* If no TO_CHARPOS and no TO_X specified, stop at the
9015 start of the line TO_VPOS. */
9016 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
9018 if (it
->vpos
== to_vpos
)
9024 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
9028 /* TO_VPOS >= 0 means stop at TO_X in the line at
9029 TO_VPOS, or at TO_POS, whichever comes first. */
9030 if (it
->vpos
== to_vpos
)
9036 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
9038 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
9043 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
9045 /* We have reached TO_X but not in the line we want. */
9046 skip
= move_it_in_display_line_to (it
, to_charpos
,
9048 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9056 else if (op
& MOVE_TO_Y
)
9058 struct it it_backup
;
9060 if (it
->line_wrap
== WORD_WRAP
)
9061 SAVE_IT (it_backup
, *it
, backup_data
);
9063 /* TO_Y specified means stop at TO_X in the line containing
9064 TO_Y---or at TO_CHARPOS if this is reached first. The
9065 problem is that we can't really tell whether the line
9066 contains TO_Y before we have completely scanned it, and
9067 this may skip past TO_X. What we do is to first scan to
9070 If TO_X is not specified, use a TO_X of zero. The reason
9071 is to make the outcome of this function more predictable.
9072 If we didn't use TO_X == 0, we would stop at the end of
9073 the line which is probably not what a caller would expect
9075 skip
= move_it_in_display_line_to
9076 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
9077 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
9079 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
9080 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9082 else if (skip
== MOVE_X_REACHED
)
9084 /* If TO_X was reached, we want to know whether TO_Y is
9085 in the line. We know this is the case if the already
9086 scanned glyphs make the line tall enough. Otherwise,
9087 we must check by scanning the rest of the line. */
9088 line_height
= it
->max_ascent
+ it
->max_descent
;
9089 if (to_y
>= it
->current_y
9090 && to_y
< it
->current_y
+ line_height
)
9095 SAVE_IT (it_backup
, *it
, backup_data
);
9096 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
9097 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
9099 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
9100 line_height
= it
->max_ascent
+ it
->max_descent
;
9101 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9103 if (to_y
>= it
->current_y
9104 && to_y
< it
->current_y
+ line_height
)
9106 /* If TO_Y is in this line and TO_X was reached
9107 above, we scanned too far. We have to restore
9108 IT's settings to the ones before skipping. But
9109 keep the more accurate values of max_ascent and
9110 max_descent we've found while skipping the rest
9111 of the line, for the sake of callers, such as
9112 pos_visible_p, that need to know the line
9114 int max_ascent
= it
->max_ascent
;
9115 int max_descent
= it
->max_descent
;
9117 RESTORE_IT (it
, &it_backup
, backup_data
);
9118 it
->max_ascent
= max_ascent
;
9119 it
->max_descent
= max_descent
;
9125 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9131 /* Check whether TO_Y is in this line. */
9132 line_height
= it
->max_ascent
+ it
->max_descent
;
9133 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9135 if (to_y
>= it
->current_y
9136 && to_y
< it
->current_y
+ line_height
)
9138 if (to_y
> it
->current_y
)
9139 max_current_x
= max (it
->current_x
, max_current_x
);
9141 /* When word-wrap is on, TO_X may lie past the end
9142 of a wrapped line. Then it->current is the
9143 character on the next line, so backtrack to the
9144 space before the wrap point. */
9145 if (skip
== MOVE_LINE_CONTINUED
9146 && it
->line_wrap
== WORD_WRAP
)
9148 int prev_x
= max (it
->current_x
- 1, 0);
9149 RESTORE_IT (it
, &it_backup
, backup_data
);
9150 skip
= move_it_in_display_line_to
9151 (it
, -1, prev_x
, MOVE_TO_X
);
9160 max_current_x
= max (it
->current_x
, max_current_x
);
9164 else if (BUFFERP (it
->object
)
9165 && (it
->method
== GET_FROM_BUFFER
9166 || it
->method
== GET_FROM_STRETCH
)
9167 && IT_CHARPOS (*it
) >= to_charpos
9168 /* Under bidi iteration, a call to set_iterator_to_next
9169 can scan far beyond to_charpos if the initial
9170 portion of the next line needs to be reordered. In
9171 that case, give move_it_in_display_line_to another
9174 && it
->bidi_it
.scan_dir
== -1))
9175 skip
= MOVE_POS_MATCH_OR_ZV
;
9177 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9181 case MOVE_POS_MATCH_OR_ZV
:
9182 max_current_x
= max (it
->current_x
, max_current_x
);
9186 case MOVE_NEWLINE_OR_CR
:
9187 max_current_x
= max (it
->current_x
, max_current_x
);
9188 set_iterator_to_next (it
, 1);
9189 it
->continuation_lines_width
= 0;
9192 case MOVE_LINE_TRUNCATED
:
9193 max_current_x
= it
->last_visible_x
;
9194 it
->continuation_lines_width
= 0;
9195 reseat_at_next_visible_line_start (it
, 0);
9196 if ((op
& MOVE_TO_POS
) != 0
9197 && IT_CHARPOS (*it
) > to_charpos
)
9204 case MOVE_LINE_CONTINUED
:
9205 max_current_x
= it
->last_visible_x
;
9206 /* For continued lines ending in a tab, some of the glyphs
9207 associated with the tab are displayed on the current
9208 line. Since it->current_x does not include these glyphs,
9209 we use it->last_visible_x instead. */
9212 it
->continuation_lines_width
+= it
->last_visible_x
;
9213 /* When moving by vpos, ensure that the iterator really
9214 advances to the next line (bug#847, bug#969). Fixme:
9215 do we need to do this in other circumstances? */
9216 if (it
->current_x
!= it
->last_visible_x
9217 && (op
& MOVE_TO_VPOS
)
9218 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9220 line_start_x
= it
->current_x
+ it
->pixel_width
9221 - it
->last_visible_x
;
9222 if (FRAME_WINDOW_P (it
->f
))
9224 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
9225 struct font
*face_font
= face
->font
;
9227 /* When display_line produces a continued line
9228 that ends in a TAB, it skips a tab stop that
9229 is closer than the font's space character
9230 width (see x_produce_glyphs where it produces
9231 the stretch glyph which represents a TAB).
9232 We need to reproduce the same logic here. */
9233 eassert (face_font
);
9236 if (line_start_x
< face_font
->space_width
)
9238 += it
->tab_width
* face_font
->space_width
;
9241 set_iterator_to_next (it
, 0);
9245 it
->continuation_lines_width
+= it
->current_x
;
9252 /* Reset/increment for the next run. */
9253 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9254 it
->current_x
= line_start_x
;
9257 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9259 last_height
= it
->max_ascent
+ it
->max_descent
;
9260 it
->max_ascent
= it
->max_descent
= 0;
9265 /* On text terminals, we may stop at the end of a line in the middle
9266 of a multi-character glyph. If the glyph itself is continued,
9267 i.e. it is actually displayed on the next line, don't treat this
9268 stopping point as valid; move to the next line instead (unless
9269 that brings us offscreen). */
9270 if (!FRAME_WINDOW_P (it
->f
)
9272 && IT_CHARPOS (*it
) == to_charpos
9273 && it
->what
== IT_CHARACTER
9275 && it
->line_wrap
== WINDOW_WRAP
9276 && it
->current_x
== it
->last_visible_x
- 1
9279 && it
->vpos
< it
->w
->window_end_vpos
)
9281 it
->continuation_lines_width
+= it
->current_x
;
9282 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9283 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9285 last_height
= it
->max_ascent
+ it
->max_descent
;
9289 bidi_unshelve_cache (backup_data
, 1);
9291 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9293 return max_current_x
;
9297 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9299 If DY > 0, move IT backward at least that many pixels. DY = 0
9300 means move IT backward to the preceding line start or BEGV. This
9301 function may move over more than DY pixels if IT->current_y - DY
9302 ends up in the middle of a line; in this case IT->current_y will be
9303 set to the top of the line moved to. */
9306 move_it_vertically_backward (struct it
*it
, int dy
)
9310 void *it2data
= NULL
, *it3data
= NULL
;
9311 ptrdiff_t start_pos
;
9313 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9314 ptrdiff_t pos_limit
;
9319 start_pos
= IT_CHARPOS (*it
);
9321 /* Estimate how many newlines we must move back. */
9322 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9323 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9326 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9328 /* Set the iterator's position that many lines back. But don't go
9329 back more than NLINES full screen lines -- this wins a day with
9330 buffers which have very long lines. */
9331 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9332 back_to_previous_visible_line_start (it
);
9334 /* Reseat the iterator here. When moving backward, we don't want
9335 reseat to skip forward over invisible text, set up the iterator
9336 to deliver from overlay strings at the new position etc. So,
9337 use reseat_1 here. */
9338 reseat_1 (it
, it
->current
.pos
, 1);
9340 /* We are now surely at a line start. */
9341 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9342 reordering is in effect. */
9343 it
->continuation_lines_width
= 0;
9345 /* Move forward and see what y-distance we moved. First move to the
9346 start of the next line so that we get its height. We need this
9347 height to be able to tell whether we reached the specified
9349 SAVE_IT (it2
, *it
, it2data
);
9350 it2
.max_ascent
= it2
.max_descent
= 0;
9353 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9354 MOVE_TO_POS
| MOVE_TO_VPOS
);
9356 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9357 /* If we are in a display string which starts at START_POS,
9358 and that display string includes a newline, and we are
9359 right after that newline (i.e. at the beginning of a
9360 display line), exit the loop, because otherwise we will
9361 infloop, since move_it_to will see that it is already at
9362 START_POS and will not move. */
9363 || (it2
.method
== GET_FROM_STRING
9364 && IT_CHARPOS (it2
) == start_pos
9365 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9366 eassert (IT_CHARPOS (*it
) >= BEGV
);
9367 SAVE_IT (it3
, it2
, it3data
);
9369 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9370 eassert (IT_CHARPOS (*it
) >= BEGV
);
9371 /* H is the actual vertical distance from the position in *IT
9372 and the starting position. */
9373 h
= it2
.current_y
- it
->current_y
;
9374 /* NLINES is the distance in number of lines. */
9375 nlines
= it2
.vpos
- it
->vpos
;
9377 /* Correct IT's y and vpos position
9378 so that they are relative to the starting point. */
9384 /* DY == 0 means move to the start of the screen line. The
9385 value of nlines is > 0 if continuation lines were involved,
9386 or if the original IT position was at start of a line. */
9387 RESTORE_IT (it
, it
, it2data
);
9389 move_it_by_lines (it
, nlines
);
9390 /* The above code moves us to some position NLINES down,
9391 usually to its first glyph (leftmost in an L2R line), but
9392 that's not necessarily the start of the line, under bidi
9393 reordering. We want to get to the character position
9394 that is immediately after the newline of the previous
9397 && !it
->continuation_lines_width
9398 && !STRINGP (it
->string
)
9399 && IT_CHARPOS (*it
) > BEGV
9400 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9402 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9405 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9406 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9408 bidi_unshelve_cache (it3data
, 1);
9412 /* The y-position we try to reach, relative to *IT.
9413 Note that H has been subtracted in front of the if-statement. */
9414 int target_y
= it
->current_y
+ h
- dy
;
9415 int y0
= it3
.current_y
;
9419 RESTORE_IT (&it3
, &it3
, it3data
);
9420 y1
= line_bottom_y (&it3
);
9421 line_height
= y1
- y0
;
9422 RESTORE_IT (it
, it
, it2data
);
9423 /* If we did not reach target_y, try to move further backward if
9424 we can. If we moved too far backward, try to move forward. */
9425 if (target_y
< it
->current_y
9426 /* This is heuristic. In a window that's 3 lines high, with
9427 a line height of 13 pixels each, recentering with point
9428 on the bottom line will try to move -39/2 = 19 pixels
9429 backward. Try to avoid moving into the first line. */
9430 && (it
->current_y
- target_y
9431 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9432 && IT_CHARPOS (*it
) > BEGV
)
9434 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9435 target_y
- it
->current_y
));
9436 dy
= it
->current_y
- target_y
;
9437 goto move_further_back
;
9439 else if (target_y
>= it
->current_y
+ line_height
9440 && IT_CHARPOS (*it
) < ZV
)
9442 /* Should move forward by at least one line, maybe more.
9444 Note: Calling move_it_by_lines can be expensive on
9445 terminal frames, where compute_motion is used (via
9446 vmotion) to do the job, when there are very long lines
9447 and truncate-lines is nil. That's the reason for
9448 treating terminal frames specially here. */
9450 if (!FRAME_WINDOW_P (it
->f
))
9451 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9456 move_it_by_lines (it
, 1);
9458 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9465 /* Move IT by a specified amount of pixel lines DY. DY negative means
9466 move backwards. DY = 0 means move to start of screen line. At the
9467 end, IT will be on the start of a screen line. */
9470 move_it_vertically (struct it
*it
, int dy
)
9473 move_it_vertically_backward (it
, -dy
);
9476 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9477 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9478 MOVE_TO_POS
| MOVE_TO_Y
);
9479 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9481 /* If buffer ends in ZV without a newline, move to the start of
9482 the line to satisfy the post-condition. */
9483 if (IT_CHARPOS (*it
) == ZV
9485 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9486 move_it_by_lines (it
, 0);
9491 /* Move iterator IT past the end of the text line it is in. */
9494 move_it_past_eol (struct it
*it
)
9496 enum move_it_result rc
;
9498 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9499 if (rc
== MOVE_NEWLINE_OR_CR
)
9500 set_iterator_to_next (it
, 0);
9504 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9505 negative means move up. DVPOS == 0 means move to the start of the
9508 Optimization idea: If we would know that IT->f doesn't use
9509 a face with proportional font, we could be faster for
9510 truncate-lines nil. */
9513 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9516 /* The commented-out optimization uses vmotion on terminals. This
9517 gives bad results, because elements like it->what, on which
9518 callers such as pos_visible_p rely, aren't updated. */
9519 /* struct position pos;
9520 if (!FRAME_WINDOW_P (it->f))
9522 struct text_pos textpos;
9524 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9525 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9526 reseat (it, textpos, 1);
9527 it->vpos += pos.vpos;
9528 it->current_y += pos.vpos;
9534 /* DVPOS == 0 means move to the start of the screen line. */
9535 move_it_vertically_backward (it
, 0);
9536 /* Let next call to line_bottom_y calculate real line height. */
9541 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9542 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9544 /* Only move to the next buffer position if we ended up in a
9545 string from display property, not in an overlay string
9546 (before-string or after-string). That is because the
9547 latter don't conceal the underlying buffer position, so
9548 we can ask to move the iterator to the exact position we
9549 are interested in. Note that, even if we are already at
9550 IT_CHARPOS (*it), the call below is not a no-op, as it
9551 will detect that we are at the end of the string, pop the
9552 iterator, and compute it->current_x and it->hpos
9554 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9555 -1, -1, -1, MOVE_TO_POS
);
9561 void *it2data
= NULL
;
9562 ptrdiff_t start_charpos
, i
;
9564 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9565 bool hit_pos_limit
= false;
9566 ptrdiff_t pos_limit
;
9568 /* Start at the beginning of the screen line containing IT's
9569 position. This may actually move vertically backwards,
9570 in case of overlays, so adjust dvpos accordingly. */
9572 move_it_vertically_backward (it
, 0);
9575 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9576 screen lines, and reseat the iterator there. */
9577 start_charpos
= IT_CHARPOS (*it
);
9578 if (it
->line_wrap
== TRUNCATE
|| nchars_per_row
== 0)
9581 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9583 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9584 back_to_previous_visible_line_start (it
);
9585 if (i
> 0 && IT_CHARPOS (*it
) <= pos_limit
)
9586 hit_pos_limit
= true;
9587 reseat (it
, it
->current
.pos
, 1);
9589 /* Move further back if we end up in a string or an image. */
9590 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9592 /* First try to move to start of display line. */
9594 move_it_vertically_backward (it
, 0);
9596 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9598 /* If start of line is still in string or image,
9599 move further back. */
9600 back_to_previous_visible_line_start (it
);
9601 reseat (it
, it
->current
.pos
, 1);
9605 it
->current_x
= it
->hpos
= 0;
9607 /* Above call may have moved too far if continuation lines
9608 are involved. Scan forward and see if it did. */
9609 SAVE_IT (it2
, *it
, it2data
);
9610 it2
.vpos
= it2
.current_y
= 0;
9611 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9612 it
->vpos
-= it2
.vpos
;
9613 it
->current_y
-= it2
.current_y
;
9614 it
->current_x
= it
->hpos
= 0;
9616 /* If we moved too far back, move IT some lines forward. */
9617 if (it2
.vpos
> -dvpos
)
9619 int delta
= it2
.vpos
+ dvpos
;
9621 RESTORE_IT (&it2
, &it2
, it2data
);
9622 SAVE_IT (it2
, *it
, it2data
);
9623 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9624 /* Move back again if we got too far ahead. */
9625 if (IT_CHARPOS (*it
) >= start_charpos
)
9626 RESTORE_IT (it
, &it2
, it2data
);
9628 bidi_unshelve_cache (it2data
, 1);
9630 else if (hit_pos_limit
&& pos_limit
> BEGV
9631 && dvpos
< 0 && it2
.vpos
< -dvpos
)
9633 /* If we hit the limit, but still didn't make it far enough
9634 back, that means there's a display string with a newline
9635 covering a large chunk of text, and that caused
9636 back_to_previous_visible_line_start try to go too far.
9637 Punish those who commit such atrocities by going back
9638 until we've reached DVPOS, after lifting the limit, which
9639 could make it slow for very long lines. "If it hurts,
9642 RESTORE_IT (it
, it
, it2data
);
9643 for (i
= -dvpos
; i
> 0; --i
)
9645 back_to_previous_visible_line_start (it
);
9648 reseat_1 (it
, it
->current
.pos
, 1);
9651 RESTORE_IT (it
, it
, it2data
);
9655 /* Return true if IT points into the middle of a display vector. */
9658 in_display_vector_p (struct it
*it
)
9660 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9661 && it
->current
.dpvec_index
> 0
9662 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9665 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9666 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9667 WINDOW must be a live window and defaults to the selected one. The
9668 return value is a cons of the maximum pixel-width of any text line and
9669 the maximum pixel-height of all text lines.
9671 The optional argument FROM, if non-nil, specifies the first text
9672 position and defaults to the minimum accessible position of the buffer.
9673 If FROM is t, use the minimum accessible position that is not a newline
9674 character. TO, if non-nil, specifies the last text position and
9675 defaults to the maximum accessible position of the buffer. If TO is t,
9676 use the maximum accessible position that is not a newline character.
9678 The optional argument X-LIMIT, if non-nil, specifies the maximum text
9679 width that can be returned. X-LIMIT nil or omitted, means to use the
9680 pixel-width of WINDOW's body; use this if you do not intend to change
9681 the width of WINDOW. Use the maximum width WINDOW may assume if you
9682 intend to change WINDOW's width. In any case, text whose x-coordinate
9683 is beyond X-LIMIT is ignored. Since calculating the width of long lines
9684 can take some time, it's always a good idea to make this argument as
9685 small as possible; in particular, if the buffer contains long lines that
9686 shall be truncated anyway.
9688 The optional argument Y-LIMIT, if non-nil, specifies the maximum text
9689 height that can be returned. Text lines whose y-coordinate is beyond
9690 Y-LIMIT are ignored. Since calculating the text height of a large
9691 buffer can take some time, it makes sense to specify this argument if
9692 the size of the buffer is unknown.
9694 Optional argument MODE-AND-HEADER-LINE nil or omitted means do not
9695 include the height of the mode- or header-line of WINDOW in the return
9696 value. If it is either the symbol `mode-line' or `header-line', include
9697 only the height of that line, if present, in the return value. If t,
9698 include the height of both, if present, in the return value. */)
9699 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
, Lisp_Object y_limit
,
9700 Lisp_Object mode_and_header_line
)
9702 struct window
*w
= decode_live_window (window
);
9706 struct buffer
*old_buffer
= NULL
;
9707 ptrdiff_t start
, end
, pos
;
9708 struct text_pos startp
;
9709 void *itdata
= NULL
;
9710 int c
, max_y
= -1, x
= 0, y
= 0;
9716 if (b
!= current_buffer
)
9718 old_buffer
= current_buffer
;
9719 set_buffer_internal (b
);
9724 else if (EQ (from
, Qt
))
9727 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9728 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9730 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9735 CHECK_NUMBER_COERCE_MARKER (from
);
9736 start
= min (max (XINT (from
), BEGV
), ZV
);
9741 else if (EQ (to
, Qt
))
9744 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9745 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9747 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9752 CHECK_NUMBER_COERCE_MARKER (to
);
9753 end
= max (start
, min (XINT (to
), ZV
));
9756 if (!NILP (y_limit
))
9758 CHECK_NUMBER (y_limit
);
9759 max_y
= min (XINT (y_limit
), INT_MAX
);
9762 itdata
= bidi_shelve_cache ();
9763 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9764 start_display (&it
, w
, startp
);
9767 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9770 CHECK_NUMBER (x_limit
);
9771 it
.last_visible_x
= min (XINT (x_limit
), INFINITY
);
9772 /* Actually, we never want move_it_to stop at to_x. But to make
9773 sure that move_it_in_display_line_to always moves far enough,
9774 we set it to INT_MAX and specify MOVE_TO_X. */
9775 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9776 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9779 y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9781 if (!EQ (mode_and_header_line
, Qheader_line
)
9782 && !EQ (mode_and_header_line
, Qt
))
9783 /* Do not count the header-line which was counted automatically by
9785 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9787 if (EQ (mode_and_header_line
, Qmode_line
)
9788 || EQ (mode_and_header_line
, Qt
))
9789 /* Do count the mode-line which is not included automatically by
9791 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9793 bidi_unshelve_cache (itdata
, 0);
9796 set_buffer_internal (old_buffer
);
9798 return Fcons (make_number (x
), make_number (y
));
9801 /***********************************************************************
9803 ***********************************************************************/
9806 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9810 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9812 Lisp_Object args
[3];
9813 Lisp_Object msg
, fmt
;
9816 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9820 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9822 args
[0] = fmt
= build_string (format
);
9825 msg
= Fformat (3, args
);
9827 len
= SBYTES (msg
) + 1;
9828 buffer
= SAFE_ALLOCA (len
);
9829 memcpy (buffer
, SDATA (msg
), len
);
9831 message_dolog (buffer
, len
- 1, 1, 0);
9838 /* Output a newline in the *Messages* buffer if "needs" one. */
9841 message_log_maybe_newline (void)
9843 if (message_log_need_newline
)
9844 message_dolog ("", 0, 1, 0);
9848 /* Add a string M of length NBYTES to the message log, optionally
9849 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9850 true, means interpret the contents of M as multibyte. This
9851 function calls low-level routines in order to bypass text property
9852 hooks, etc. which might not be safe to run.
9854 This may GC (insert may run before/after change hooks),
9855 so the buffer M must NOT point to a Lisp string. */
9858 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9860 const unsigned char *msg
= (const unsigned char *) m
;
9862 if (!NILP (Vmemory_full
))
9865 if (!NILP (Vmessage_log_max
))
9867 struct buffer
*oldbuf
;
9868 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9869 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9870 ptrdiff_t point_at_end
= 0;
9871 ptrdiff_t zv_at_end
= 0;
9872 Lisp_Object old_deactivate_mark
;
9873 struct gcpro gcpro1
;
9875 old_deactivate_mark
= Vdeactivate_mark
;
9876 oldbuf
= current_buffer
;
9878 /* Ensure the Messages buffer exists, and switch to it.
9879 If we created it, set the major-mode. */
9882 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9884 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9887 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9888 call0 (intern ("messages-buffer-mode"));
9891 bset_undo_list (current_buffer
, Qt
);
9892 bset_cache_long_scans (current_buffer
, Qnil
);
9894 oldpoint
= message_dolog_marker1
;
9895 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9896 oldbegv
= message_dolog_marker2
;
9897 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9898 oldzv
= message_dolog_marker3
;
9899 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9900 GCPRO1 (old_deactivate_mark
);
9908 BEGV_BYTE
= BEG_BYTE
;
9911 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9913 /* Insert the string--maybe converting multibyte to single byte
9914 or vice versa, so that all the text fits the buffer. */
9916 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9922 /* Convert a multibyte string to single-byte
9923 for the *Message* buffer. */
9924 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9926 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9927 work
[0] = CHAR_TO_BYTE8 (c
);
9928 insert_1_both (work
, 1, 1, 1, 0, 0);
9931 else if (! multibyte
9932 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9936 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9937 /* Convert a single-byte string to multibyte
9938 for the *Message* buffer. */
9939 for (i
= 0; i
< nbytes
; i
++)
9942 MAKE_CHAR_MULTIBYTE (c
);
9943 char_bytes
= CHAR_STRING (c
, str
);
9944 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9948 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9952 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9955 insert_1_both ("\n", 1, 1, 1, 0, 0);
9957 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9959 this_bol_byte
= PT_BYTE
;
9961 /* See if this line duplicates the previous one.
9962 If so, combine duplicates. */
9965 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9967 prev_bol_byte
= PT_BYTE
;
9969 dups
= message_log_check_duplicate (prev_bol_byte
,
9973 del_range_both (prev_bol
, prev_bol_byte
,
9974 this_bol
, this_bol_byte
, 0);
9977 char dupstr
[sizeof " [ times]"
9978 + INT_STRLEN_BOUND (printmax_t
)];
9980 /* If you change this format, don't forget to also
9981 change message_log_check_duplicate. */
9982 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9983 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9984 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9989 /* If we have more than the desired maximum number of lines
9990 in the *Messages* buffer now, delete the oldest ones.
9991 This is safe because we don't have undo in this buffer. */
9993 if (NATNUMP (Vmessage_log_max
))
9995 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9996 -XFASTINT (Vmessage_log_max
) - 1, 0);
9997 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
10000 BEGV
= marker_position (oldbegv
);
10001 BEGV_BYTE
= marker_byte_position (oldbegv
);
10010 ZV
= marker_position (oldzv
);
10011 ZV_BYTE
= marker_byte_position (oldzv
);
10015 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
10017 /* We can't do Fgoto_char (oldpoint) because it will run some
10019 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
10020 marker_byte_position (oldpoint
));
10023 unchain_marker (XMARKER (oldpoint
));
10024 unchain_marker (XMARKER (oldbegv
));
10025 unchain_marker (XMARKER (oldzv
));
10027 /* We called insert_1_both above with its 5th argument (PREPARE)
10028 zero, which prevents insert_1_both from calling
10029 prepare_to_modify_buffer, which in turns prevents us from
10030 incrementing windows_or_buffers_changed even if *Messages* is
10031 shown in some window. So we must manually set
10032 windows_or_buffers_changed here to make up for that. */
10033 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
10034 bset_redisplay (current_buffer
);
10036 set_buffer_internal (oldbuf
);
10038 message_log_need_newline
= !nlflag
;
10039 Vdeactivate_mark
= old_deactivate_mark
;
10044 /* We are at the end of the buffer after just having inserted a newline.
10045 (Note: We depend on the fact we won't be crossing the gap.)
10046 Check to see if the most recent message looks a lot like the previous one.
10047 Return 0 if different, 1 if the new one should just replace it, or a
10048 value N > 1 if we should also append " [N times]". */
10051 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
10054 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
10056 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
10057 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
10059 for (i
= 0; i
< len
; i
++)
10061 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
10063 if (p1
[i
] != p2
[i
])
10069 if (*p1
++ == ' ' && *p1
++ == '[')
10072 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
10073 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
10080 /* Display an echo area message M with a specified length of NBYTES
10081 bytes. The string may include null characters. If M is not a
10082 string, clear out any existing message, and let the mini-buffer
10085 This function cancels echoing. */
10088 message3 (Lisp_Object m
)
10090 struct gcpro gcpro1
;
10093 clear_message (true, true);
10096 /* First flush out any partial line written with print. */
10097 message_log_maybe_newline ();
10100 ptrdiff_t nbytes
= SBYTES (m
);
10101 bool multibyte
= STRING_MULTIBYTE (m
);
10104 SAFE_ALLOCA_STRING (buffer
, m
);
10105 message_dolog (buffer
, nbytes
, 1, multibyte
);
10108 message3_nolog (m
);
10114 /* The non-logging version of message3.
10115 This does not cancel echoing, because it is used for echoing.
10116 Perhaps we need to make a separate function for echoing
10117 and make this cancel echoing. */
10120 message3_nolog (Lisp_Object m
)
10122 struct frame
*sf
= SELECTED_FRAME ();
10124 if (FRAME_INITIAL_P (sf
))
10126 if (noninteractive_need_newline
)
10127 putc ('\n', stderr
);
10128 noninteractive_need_newline
= 0;
10131 Lisp_Object s
= ENCODE_SYSTEM (m
);
10133 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
10135 if (cursor_in_echo_area
== 0)
10136 fprintf (stderr
, "\n");
10139 /* Error messages get reported properly by cmd_error, so this must be just an
10140 informative message; if the frame hasn't really been initialized yet, just
10142 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
10144 /* Get the frame containing the mini-buffer
10145 that the selected frame is using. */
10146 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10147 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
10148 struct frame
*f
= XFRAME (frame
);
10150 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
10151 Fmake_frame_visible (frame
);
10153 if (STRINGP (m
) && SCHARS (m
) > 0)
10156 if (minibuffer_auto_raise
)
10157 Fraise_frame (frame
);
10158 /* Assume we are not echoing.
10159 (If we are, echo_now will override this.) */
10160 echo_message_buffer
= Qnil
;
10163 clear_message (true, true);
10165 do_pending_window_change (false);
10166 echo_area_display (true);
10167 do_pending_window_change (false);
10168 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
10169 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
10174 /* Display a null-terminated echo area message M. If M is 0, clear
10175 out any existing message, and let the mini-buffer text show through.
10177 The buffer M must continue to exist until after the echo area gets
10178 cleared or some other message gets displayed there. Do not pass
10179 text that is stored in a Lisp string. Do not pass text in a buffer
10180 that was alloca'd. */
10183 message1 (const char *m
)
10185 message3 (m
? build_unibyte_string (m
) : Qnil
);
10189 /* The non-logging counterpart of message1. */
10192 message1_nolog (const char *m
)
10194 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10197 /* Display a message M which contains a single %s
10198 which gets replaced with STRING. */
10201 message_with_string (const char *m
, Lisp_Object string
, int log
)
10203 CHECK_STRING (string
);
10205 if (noninteractive
)
10209 /* ENCODE_SYSTEM below can GC and/or relocate the
10210 Lisp data, so make sure we don't use it here. */
10211 eassert (relocatable_string_data_p (m
) != 1);
10213 if (noninteractive_need_newline
)
10214 putc ('\n', stderr
);
10215 noninteractive_need_newline
= 0;
10216 fprintf (stderr
, m
, SDATA (ENCODE_SYSTEM (string
)));
10217 if (!cursor_in_echo_area
)
10218 fprintf (stderr
, "\n");
10222 else if (INTERACTIVE
)
10224 /* The frame whose minibuffer we're going to display the message on.
10225 It may be larger than the selected frame, so we need
10226 to use its buffer, not the selected frame's buffer. */
10227 Lisp_Object mini_window
;
10228 struct frame
*f
, *sf
= SELECTED_FRAME ();
10230 /* Get the frame containing the minibuffer
10231 that the selected frame is using. */
10232 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10233 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10235 /* Error messages get reported properly by cmd_error, so this must be
10236 just an informative message; if the frame hasn't really been
10237 initialized yet, just toss it. */
10238 if (f
->glyphs_initialized_p
)
10240 Lisp_Object args
[2], msg
;
10241 struct gcpro gcpro1
, gcpro2
;
10243 args
[0] = build_string (m
);
10244 args
[1] = msg
= string
;
10245 GCPRO2 (args
[0], msg
);
10248 msg
= Fformat (2, args
);
10253 message3_nolog (msg
);
10257 /* Print should start at the beginning of the message
10258 buffer next time. */
10259 message_buf_print
= 0;
10265 /* Dump an informative message to the minibuf. If M is 0, clear out
10266 any existing message, and let the mini-buffer text show through. */
10269 vmessage (const char *m
, va_list ap
)
10271 if (noninteractive
)
10275 if (noninteractive_need_newline
)
10276 putc ('\n', stderr
);
10277 noninteractive_need_newline
= 0;
10278 vfprintf (stderr
, m
, ap
);
10279 if (cursor_in_echo_area
== 0)
10280 fprintf (stderr
, "\n");
10284 else if (INTERACTIVE
)
10286 /* The frame whose mini-buffer we're going to display the message
10287 on. It may be larger than the selected frame, so we need to
10288 use its buffer, not the selected frame's buffer. */
10289 Lisp_Object mini_window
;
10290 struct frame
*f
, *sf
= SELECTED_FRAME ();
10292 /* Get the frame containing the mini-buffer
10293 that the selected frame is using. */
10294 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10295 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10297 /* Error messages get reported properly by cmd_error, so this must be
10298 just an informative message; if the frame hasn't really been
10299 initialized yet, just toss it. */
10300 if (f
->glyphs_initialized_p
)
10305 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10307 char *message_buf
= SAFE_ALLOCA (maxsize
+ 1);
10309 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10311 message3 (make_string (message_buf
, len
));
10317 /* Print should start at the beginning of the message
10318 buffer next time. */
10319 message_buf_print
= 0;
10325 message (const char *m
, ...)
10335 /* The non-logging version of message. */
10338 message_nolog (const char *m
, ...)
10340 Lisp_Object old_log_max
;
10343 old_log_max
= Vmessage_log_max
;
10344 Vmessage_log_max
= Qnil
;
10346 Vmessage_log_max
= old_log_max
;
10352 /* Display the current message in the current mini-buffer. This is
10353 only called from error handlers in process.c, and is not time
10357 update_echo_area (void)
10359 if (!NILP (echo_area_buffer
[0]))
10361 Lisp_Object string
;
10362 string
= Fcurrent_message ();
10368 /* Make sure echo area buffers in `echo_buffers' are live.
10369 If they aren't, make new ones. */
10372 ensure_echo_area_buffers (void)
10376 for (i
= 0; i
< 2; ++i
)
10377 if (!BUFFERP (echo_buffer
[i
])
10378 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10381 Lisp_Object old_buffer
;
10384 old_buffer
= echo_buffer
[i
];
10385 echo_buffer
[i
] = Fget_buffer_create
10386 (make_formatted_string (name
, " *Echo Area %d*", i
));
10387 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10388 /* to force word wrap in echo area -
10389 it was decided to postpone this*/
10390 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10392 for (j
= 0; j
< 2; ++j
)
10393 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10394 echo_area_buffer
[j
] = echo_buffer
[i
];
10399 /* Call FN with args A1..A2 with either the current or last displayed
10400 echo_area_buffer as current buffer.
10402 WHICH zero means use the current message buffer
10403 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10404 from echo_buffer[] and clear it.
10406 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10407 suitable buffer from echo_buffer[] and clear it.
10409 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10410 that the current message becomes the last displayed one, make
10411 choose a suitable buffer for echo_area_buffer[0], and clear it.
10413 Value is what FN returns. */
10416 with_echo_area_buffer (struct window
*w
, int which
,
10417 int (*fn
) (ptrdiff_t, Lisp_Object
),
10418 ptrdiff_t a1
, Lisp_Object a2
)
10420 Lisp_Object buffer
;
10421 int this_one
, the_other
, clear_buffer_p
, rc
;
10422 ptrdiff_t count
= SPECPDL_INDEX ();
10424 /* If buffers aren't live, make new ones. */
10425 ensure_echo_area_buffers ();
10427 clear_buffer_p
= 0;
10430 this_one
= 0, the_other
= 1;
10431 else if (which
> 0)
10432 this_one
= 1, the_other
= 0;
10435 this_one
= 0, the_other
= 1;
10436 clear_buffer_p
= true;
10438 /* We need a fresh one in case the current echo buffer equals
10439 the one containing the last displayed echo area message. */
10440 if (!NILP (echo_area_buffer
[this_one
])
10441 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10442 echo_area_buffer
[this_one
] = Qnil
;
10445 /* Choose a suitable buffer from echo_buffer[] is we don't
10447 if (NILP (echo_area_buffer
[this_one
]))
10449 echo_area_buffer
[this_one
]
10450 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10451 ? echo_buffer
[the_other
]
10452 : echo_buffer
[this_one
]);
10453 clear_buffer_p
= true;
10456 buffer
= echo_area_buffer
[this_one
];
10458 /* Don't get confused by reusing the buffer used for echoing
10459 for a different purpose. */
10460 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10463 record_unwind_protect (unwind_with_echo_area_buffer
,
10464 with_echo_area_buffer_unwind_data (w
));
10466 /* Make the echo area buffer current. Note that for display
10467 purposes, it is not necessary that the displayed window's buffer
10468 == current_buffer, except for text property lookup. So, let's
10469 only set that buffer temporarily here without doing a full
10470 Fset_window_buffer. We must also change w->pointm, though,
10471 because otherwise an assertions in unshow_buffer fails, and Emacs
10473 set_buffer_internal_1 (XBUFFER (buffer
));
10476 wset_buffer (w
, buffer
);
10477 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10478 set_marker_both (w
->old_pointm
, buffer
, BEG
, BEG_BYTE
);
10481 bset_undo_list (current_buffer
, Qt
);
10482 bset_read_only (current_buffer
, Qnil
);
10483 specbind (Qinhibit_read_only
, Qt
);
10484 specbind (Qinhibit_modification_hooks
, Qt
);
10486 if (clear_buffer_p
&& Z
> BEG
)
10487 del_range (BEG
, Z
);
10489 eassert (BEGV
>= BEG
);
10490 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10494 eassert (BEGV
>= BEG
);
10495 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10497 unbind_to (count
, Qnil
);
10502 /* Save state that should be preserved around the call to the function
10503 FN called in with_echo_area_buffer. */
10506 with_echo_area_buffer_unwind_data (struct window
*w
)
10509 Lisp_Object vector
, tmp
;
10511 /* Reduce consing by keeping one vector in
10512 Vwith_echo_area_save_vector. */
10513 vector
= Vwith_echo_area_save_vector
;
10514 Vwith_echo_area_save_vector
= Qnil
;
10517 vector
= Fmake_vector (make_number (11), Qnil
);
10519 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10520 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10521 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10525 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10526 ASET (vector
, i
, w
->contents
); ++i
;
10527 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10528 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10529 ASET (vector
, i
, make_number (marker_position (w
->old_pointm
))); ++i
;
10530 ASET (vector
, i
, make_number (marker_byte_position (w
->old_pointm
))); ++i
;
10531 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10532 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10537 for (; i
< end
; ++i
)
10538 ASET (vector
, i
, Qnil
);
10541 eassert (i
== ASIZE (vector
));
10546 /* Restore global state from VECTOR which was created by
10547 with_echo_area_buffer_unwind_data. */
10550 unwind_with_echo_area_buffer (Lisp_Object vector
)
10552 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10553 Vdeactivate_mark
= AREF (vector
, 1);
10554 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10556 if (WINDOWP (AREF (vector
, 3)))
10559 Lisp_Object buffer
;
10561 w
= XWINDOW (AREF (vector
, 3));
10562 buffer
= AREF (vector
, 4);
10564 wset_buffer (w
, buffer
);
10565 set_marker_both (w
->pointm
, buffer
,
10566 XFASTINT (AREF (vector
, 5)),
10567 XFASTINT (AREF (vector
, 6)));
10568 set_marker_both (w
->old_pointm
, buffer
,
10569 XFASTINT (AREF (vector
, 7)),
10570 XFASTINT (AREF (vector
, 8)));
10571 set_marker_both (w
->start
, buffer
,
10572 XFASTINT (AREF (vector
, 9)),
10573 XFASTINT (AREF (vector
, 10)));
10576 Vwith_echo_area_save_vector
= vector
;
10580 /* Set up the echo area for use by print functions. MULTIBYTE_P
10581 non-zero means we will print multibyte. */
10584 setup_echo_area_for_printing (int multibyte_p
)
10586 /* If we can't find an echo area any more, exit. */
10587 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10588 Fkill_emacs (Qnil
);
10590 ensure_echo_area_buffers ();
10592 if (!message_buf_print
)
10594 /* A message has been output since the last time we printed.
10595 Choose a fresh echo area buffer. */
10596 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10597 echo_area_buffer
[0] = echo_buffer
[1];
10599 echo_area_buffer
[0] = echo_buffer
[0];
10601 /* Switch to that buffer and clear it. */
10602 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10603 bset_truncate_lines (current_buffer
, Qnil
);
10607 ptrdiff_t count
= SPECPDL_INDEX ();
10608 specbind (Qinhibit_read_only
, Qt
);
10609 /* Note that undo recording is always disabled. */
10610 del_range (BEG
, Z
);
10611 unbind_to (count
, Qnil
);
10613 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10615 /* Set up the buffer for the multibyteness we need. */
10617 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10618 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10620 /* Raise the frame containing the echo area. */
10621 if (minibuffer_auto_raise
)
10623 struct frame
*sf
= SELECTED_FRAME ();
10624 Lisp_Object mini_window
;
10625 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10626 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10629 message_log_maybe_newline ();
10630 message_buf_print
= 1;
10634 if (NILP (echo_area_buffer
[0]))
10636 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10637 echo_area_buffer
[0] = echo_buffer
[1];
10639 echo_area_buffer
[0] = echo_buffer
[0];
10642 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10644 /* Someone switched buffers between print requests. */
10645 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10646 bset_truncate_lines (current_buffer
, Qnil
);
10652 /* Display an echo area message in window W. Value is non-zero if W's
10653 height is changed. If display_last_displayed_message_p is
10654 non-zero, display the message that was last displayed, otherwise
10655 display the current message. */
10658 display_echo_area (struct window
*w
)
10660 int i
, no_message_p
, window_height_changed_p
;
10662 /* Temporarily disable garbage collections while displaying the echo
10663 area. This is done because a GC can print a message itself.
10664 That message would modify the echo area buffer's contents while a
10665 redisplay of the buffer is going on, and seriously confuse
10667 ptrdiff_t count
= inhibit_garbage_collection ();
10669 /* If there is no message, we must call display_echo_area_1
10670 nevertheless because it resizes the window. But we will have to
10671 reset the echo_area_buffer in question to nil at the end because
10672 with_echo_area_buffer will sets it to an empty buffer. */
10673 i
= display_last_displayed_message_p
? 1 : 0;
10674 no_message_p
= NILP (echo_area_buffer
[i
]);
10676 window_height_changed_p
10677 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10678 display_echo_area_1
,
10679 (intptr_t) w
, Qnil
);
10682 echo_area_buffer
[i
] = Qnil
;
10684 unbind_to (count
, Qnil
);
10685 return window_height_changed_p
;
10689 /* Helper for display_echo_area. Display the current buffer which
10690 contains the current echo area message in window W, a mini-window,
10691 a pointer to which is passed in A1. A2..A4 are currently not used.
10692 Change the height of W so that all of the message is displayed.
10693 Value is non-zero if height of W was changed. */
10696 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10699 struct window
*w
= (struct window
*) i1
;
10700 Lisp_Object window
;
10701 struct text_pos start
;
10702 int window_height_changed_p
= 0;
10704 /* Do this before displaying, so that we have a large enough glyph
10705 matrix for the display. If we can't get enough space for the
10706 whole text, display the last N lines. That works by setting w->start. */
10707 window_height_changed_p
= resize_mini_window (w
, 0);
10709 /* Use the starting position chosen by resize_mini_window. */
10710 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10713 clear_glyph_matrix (w
->desired_matrix
);
10714 XSETWINDOW (window
, w
);
10715 try_window (window
, start
, 0);
10717 return window_height_changed_p
;
10721 /* Resize the echo area window to exactly the size needed for the
10722 currently displayed message, if there is one. If a mini-buffer
10723 is active, don't shrink it. */
10726 resize_echo_area_exactly (void)
10728 if (BUFFERP (echo_area_buffer
[0])
10729 && WINDOWP (echo_area_window
))
10731 struct window
*w
= XWINDOW (echo_area_window
);
10732 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10733 int resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10734 (intptr_t) w
, resize_exactly
);
10737 windows_or_buffers_changed
= 42;
10738 update_mode_lines
= 30;
10739 redisplay_internal ();
10745 /* Callback function for with_echo_area_buffer, when used from
10746 resize_echo_area_exactly. A1 contains a pointer to the window to
10747 resize, EXACTLY non-nil means resize the mini-window exactly to the
10748 size of the text displayed. A3 and A4 are not used. Value is what
10749 resize_mini_window returns. */
10752 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10755 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10759 /* Resize mini-window W to fit the size of its contents. EXACT_P
10760 means size the window exactly to the size needed. Otherwise, it's
10761 only enlarged until W's buffer is empty.
10763 Set W->start to the right place to begin display. If the whole
10764 contents fit, start at the beginning. Otherwise, start so as
10765 to make the end of the contents appear. This is particularly
10766 important for y-or-n-p, but seems desirable generally.
10768 Value is non-zero if the window height has been changed. */
10771 resize_mini_window (struct window
*w
, int exact_p
)
10773 struct frame
*f
= XFRAME (w
->frame
);
10774 int window_height_changed_p
= 0;
10776 eassert (MINI_WINDOW_P (w
));
10778 /* By default, start display at the beginning. */
10779 set_marker_both (w
->start
, w
->contents
,
10780 BUF_BEGV (XBUFFER (w
->contents
)),
10781 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10783 /* Don't resize windows while redisplaying a window; it would
10784 confuse redisplay functions when the size of the window they are
10785 displaying changes from under them. Such a resizing can happen,
10786 for instance, when which-func prints a long message while
10787 we are running fontification-functions. We're running these
10788 functions with safe_call which binds inhibit-redisplay to t. */
10789 if (!NILP (Vinhibit_redisplay
))
10792 /* Nil means don't try to resize. */
10793 if (NILP (Vresize_mini_windows
)
10794 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10797 if (!FRAME_MINIBUF_ONLY_P (f
))
10800 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10801 + WINDOW_PIXEL_HEIGHT (w
));
10802 int unit
= FRAME_LINE_HEIGHT (f
);
10803 int height
, max_height
;
10804 struct text_pos start
;
10805 struct buffer
*old_current_buffer
= NULL
;
10807 if (current_buffer
!= XBUFFER (w
->contents
))
10809 old_current_buffer
= current_buffer
;
10810 set_buffer_internal (XBUFFER (w
->contents
));
10813 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10815 /* Compute the max. number of lines specified by the user. */
10816 if (FLOATP (Vmax_mini_window_height
))
10817 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10818 else if (INTEGERP (Vmax_mini_window_height
))
10819 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10821 max_height
= total_height
/ 4;
10823 /* Correct that max. height if it's bogus. */
10824 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10826 /* Find out the height of the text in the window. */
10827 if (it
.line_wrap
== TRUNCATE
)
10832 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10833 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10834 height
= it
.current_y
+ last_height
;
10836 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10837 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10840 /* Compute a suitable window start. */
10841 if (height
> max_height
)
10843 height
= (max_height
/ unit
) * unit
;
10844 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10845 move_it_vertically_backward (&it
, height
- unit
);
10846 start
= it
.current
.pos
;
10849 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10850 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10852 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10854 /* Let it grow only, until we display an empty message, in which
10855 case the window shrinks again. */
10856 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10858 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10860 FRAME_WINDOWS_FROZEN (f
) = 1;
10861 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10862 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10864 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10865 && (exact_p
|| BEGV
== ZV
))
10867 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10869 FRAME_WINDOWS_FROZEN (f
) = 0;
10870 shrink_mini_window (w
, 1);
10871 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10876 /* Always resize to exact size needed. */
10877 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10879 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10881 FRAME_WINDOWS_FROZEN (f
) = 1;
10882 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10883 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10885 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
10887 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10889 FRAME_WINDOWS_FROZEN (f
) = 0;
10890 shrink_mini_window (w
, 1);
10894 FRAME_WINDOWS_FROZEN (f
) = 1;
10895 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10898 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10902 if (old_current_buffer
)
10903 set_buffer_internal (old_current_buffer
);
10906 return window_height_changed_p
;
10910 /* Value is the current message, a string, or nil if there is no
10911 current message. */
10914 current_message (void)
10918 if (!BUFFERP (echo_area_buffer
[0]))
10922 with_echo_area_buffer (0, 0, current_message_1
,
10923 (intptr_t) &msg
, Qnil
);
10925 echo_area_buffer
[0] = Qnil
;
10933 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10936 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10939 *msg
= make_buffer_string (BEG
, Z
, 1);
10946 /* Push the current message on Vmessage_stack for later restoration
10947 by restore_message. Value is non-zero if the current message isn't
10948 empty. This is a relatively infrequent operation, so it's not
10949 worth optimizing. */
10952 push_message (void)
10954 Lisp_Object msg
= current_message ();
10955 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10956 return STRINGP (msg
);
10960 /* Restore message display from the top of Vmessage_stack. */
10963 restore_message (void)
10965 eassert (CONSP (Vmessage_stack
));
10966 message3_nolog (XCAR (Vmessage_stack
));
10970 /* Handler for unwind-protect calling pop_message. */
10973 pop_message_unwind (void)
10975 /* Pop the top-most entry off Vmessage_stack. */
10976 eassert (CONSP (Vmessage_stack
));
10977 Vmessage_stack
= XCDR (Vmessage_stack
);
10981 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10982 exits. If the stack is not empty, we have a missing pop_message
10986 check_message_stack (void)
10988 if (!NILP (Vmessage_stack
))
10993 /* Truncate to NCHARS what will be displayed in the echo area the next
10994 time we display it---but don't redisplay it now. */
10997 truncate_echo_area (ptrdiff_t nchars
)
11000 echo_area_buffer
[0] = Qnil
;
11001 else if (!noninteractive
11003 && !NILP (echo_area_buffer
[0]))
11005 struct frame
*sf
= SELECTED_FRAME ();
11006 /* Error messages get reported properly by cmd_error, so this must be
11007 just an informative message; if the frame hasn't really been
11008 initialized yet, just toss it. */
11009 if (sf
->glyphs_initialized_p
)
11010 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
11015 /* Helper function for truncate_echo_area. Truncate the current
11016 message to at most NCHARS characters. */
11019 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
11021 if (BEG
+ nchars
< Z
)
11022 del_range (BEG
+ nchars
, Z
);
11024 echo_area_buffer
[0] = Qnil
;
11028 /* Set the current message to STRING. */
11031 set_message (Lisp_Object string
)
11033 eassert (STRINGP (string
));
11035 message_enable_multibyte
= STRING_MULTIBYTE (string
);
11037 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
11038 message_buf_print
= 0;
11039 help_echo_showing_p
= 0;
11041 if (STRINGP (Vdebug_on_message
)
11042 && STRINGP (string
)
11043 && fast_string_match (Vdebug_on_message
, string
) >= 0)
11044 call_debugger (list2 (Qerror
, string
));
11048 /* Helper function for set_message. First argument is ignored and second
11049 argument has the same meaning as for set_message.
11050 This function is called with the echo area buffer being current. */
11053 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
11055 eassert (STRINGP (string
));
11057 /* Change multibyteness of the echo buffer appropriately. */
11058 if (message_enable_multibyte
11059 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
11060 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
11062 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
11063 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
11064 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
11066 /* Insert new message at BEG. */
11067 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
11069 /* This function takes care of single/multibyte conversion.
11070 We just have to ensure that the echo area buffer has the right
11071 setting of enable_multibyte_characters. */
11072 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
11078 /* Clear messages. CURRENT_P non-zero means clear the current
11079 message. LAST_DISPLAYED_P non-zero means clear the message
11083 clear_message (bool current_p
, bool last_displayed_p
)
11087 echo_area_buffer
[0] = Qnil
;
11088 message_cleared_p
= true;
11091 if (last_displayed_p
)
11092 echo_area_buffer
[1] = Qnil
;
11094 message_buf_print
= 0;
11097 /* Clear garbaged frames.
11099 This function is used where the old redisplay called
11100 redraw_garbaged_frames which in turn called redraw_frame which in
11101 turn called clear_frame. The call to clear_frame was a source of
11102 flickering. I believe a clear_frame is not necessary. It should
11103 suffice in the new redisplay to invalidate all current matrices,
11104 and ensure a complete redisplay of all windows. */
11107 clear_garbaged_frames (void)
11109 if (frame_garbaged
)
11111 Lisp_Object tail
, frame
;
11113 FOR_EACH_FRAME (tail
, frame
)
11115 struct frame
*f
= XFRAME (frame
);
11117 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
11122 clear_current_matrices (f
);
11123 fset_redisplay (f
);
11124 f
->garbaged
= false;
11125 f
->resized_p
= false;
11129 frame_garbaged
= false;
11134 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
11135 is non-zero update selected_frame. Value is non-zero if the
11136 mini-windows height has been changed. */
11139 echo_area_display (bool update_frame_p
)
11141 Lisp_Object mini_window
;
11144 bool window_height_changed_p
= false;
11145 struct frame
*sf
= SELECTED_FRAME ();
11147 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
11148 w
= XWINDOW (mini_window
);
11149 f
= XFRAME (WINDOW_FRAME (w
));
11151 /* Don't display if frame is invisible or not yet initialized. */
11152 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
11155 #ifdef HAVE_WINDOW_SYSTEM
11156 /* When Emacs starts, selected_frame may be the initial terminal
11157 frame. If we let this through, a message would be displayed on
11159 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
11161 #endif /* HAVE_WINDOW_SYSTEM */
11163 /* Redraw garbaged frames. */
11164 clear_garbaged_frames ();
11166 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
11168 echo_area_window
= mini_window
;
11169 window_height_changed_p
= display_echo_area (w
);
11170 w
->must_be_updated_p
= true;
11172 /* Update the display, unless called from redisplay_internal.
11173 Also don't update the screen during redisplay itself. The
11174 update will happen at the end of redisplay, and an update
11175 here could cause confusion. */
11176 if (update_frame_p
&& !redisplaying_p
)
11180 /* If the display update has been interrupted by pending
11181 input, update mode lines in the frame. Due to the
11182 pending input, it might have been that redisplay hasn't
11183 been called, so that mode lines above the echo area are
11184 garbaged. This looks odd, so we prevent it here. */
11185 if (!display_completed
)
11186 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11188 if (window_height_changed_p
11189 /* Don't do this if Emacs is shutting down. Redisplay
11190 needs to run hooks. */
11191 && !NILP (Vrun_hooks
))
11193 /* Must update other windows. Likewise as in other
11194 cases, don't let this update be interrupted by
11196 ptrdiff_t count
= SPECPDL_INDEX ();
11197 specbind (Qredisplay_dont_pause
, Qt
);
11198 windows_or_buffers_changed
= 44;
11199 redisplay_internal ();
11200 unbind_to (count
, Qnil
);
11202 else if (FRAME_WINDOW_P (f
) && n
== 0)
11204 /* Window configuration is the same as before.
11205 Can do with a display update of the echo area,
11206 unless we displayed some mode lines. */
11207 update_single_window (w
);
11211 update_frame (f
, true, true);
11213 /* If cursor is in the echo area, make sure that the next
11214 redisplay displays the minibuffer, so that the cursor will
11215 be replaced with what the minibuffer wants. */
11216 if (cursor_in_echo_area
)
11217 wset_redisplay (XWINDOW (mini_window
));
11220 else if (!EQ (mini_window
, selected_window
))
11221 wset_redisplay (XWINDOW (mini_window
));
11223 /* Last displayed message is now the current message. */
11224 echo_area_buffer
[1] = echo_area_buffer
[0];
11225 /* Inform read_char that we're not echoing. */
11226 echo_message_buffer
= Qnil
;
11228 /* Prevent redisplay optimization in redisplay_internal by resetting
11229 this_line_start_pos. This is done because the mini-buffer now
11230 displays the message instead of its buffer text. */
11231 if (EQ (mini_window
, selected_window
))
11232 CHARPOS (this_line_start_pos
) = 0;
11234 return window_height_changed_p
;
11237 /* Nonzero if W's buffer was changed but not saved. */
11240 window_buffer_changed (struct window
*w
)
11242 struct buffer
*b
= XBUFFER (w
->contents
);
11244 eassert (BUFFER_LIVE_P (b
));
11246 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
));
11249 /* Nonzero if W has %c in its mode line and mode line should be updated. */
11252 mode_line_update_needed (struct window
*w
)
11254 return (w
->column_number_displayed
!= -1
11255 && !(PT
== w
->last_point
&& !window_outdated (w
))
11256 && (w
->column_number_displayed
!= current_column ()));
11259 /* Nonzero if window start of W is frozen and may not be changed during
11263 window_frozen_p (struct window
*w
)
11265 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11267 Lisp_Object window
;
11269 XSETWINDOW (window
, w
);
11270 if (MINI_WINDOW_P (w
))
11272 else if (EQ (window
, selected_window
))
11274 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11275 && EQ (window
, Vminibuf_scroll_window
))
11276 /* This special window can't be frozen too. */
11284 /***********************************************************************
11285 Mode Lines and Frame Titles
11286 ***********************************************************************/
11288 /* A buffer for constructing non-propertized mode-line strings and
11289 frame titles in it; allocated from the heap in init_xdisp and
11290 resized as needed in store_mode_line_noprop_char. */
11292 static char *mode_line_noprop_buf
;
11294 /* The buffer's end, and a current output position in it. */
11296 static char *mode_line_noprop_buf_end
;
11297 static char *mode_line_noprop_ptr
;
11299 #define MODE_LINE_NOPROP_LEN(start) \
11300 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11303 MODE_LINE_DISPLAY
= 0,
11307 } mode_line_target
;
11309 /* Alist that caches the results of :propertize.
11310 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11311 static Lisp_Object mode_line_proptrans_alist
;
11313 /* List of strings making up the mode-line. */
11314 static Lisp_Object mode_line_string_list
;
11316 /* Base face property when building propertized mode line string. */
11317 static Lisp_Object mode_line_string_face
;
11318 static Lisp_Object mode_line_string_face_prop
;
11321 /* Unwind data for mode line strings */
11323 static Lisp_Object Vmode_line_unwind_vector
;
11326 format_mode_line_unwind_data (struct frame
*target_frame
,
11327 struct buffer
*obuf
,
11329 int save_proptrans
)
11331 Lisp_Object vector
, tmp
;
11333 /* Reduce consing by keeping one vector in
11334 Vwith_echo_area_save_vector. */
11335 vector
= Vmode_line_unwind_vector
;
11336 Vmode_line_unwind_vector
= Qnil
;
11339 vector
= Fmake_vector (make_number (10), Qnil
);
11341 ASET (vector
, 0, make_number (mode_line_target
));
11342 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11343 ASET (vector
, 2, mode_line_string_list
);
11344 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11345 ASET (vector
, 4, mode_line_string_face
);
11346 ASET (vector
, 5, mode_line_string_face_prop
);
11349 XSETBUFFER (tmp
, obuf
);
11352 ASET (vector
, 6, tmp
);
11353 ASET (vector
, 7, owin
);
11356 /* Similarly to `with-selected-window', if the operation selects
11357 a window on another frame, we must restore that frame's
11358 selected window, and (for a tty) the top-frame. */
11359 ASET (vector
, 8, target_frame
->selected_window
);
11360 if (FRAME_TERMCAP_P (target_frame
))
11361 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11368 unwind_format_mode_line (Lisp_Object vector
)
11370 Lisp_Object old_window
= AREF (vector
, 7);
11371 Lisp_Object target_frame_window
= AREF (vector
, 8);
11372 Lisp_Object old_top_frame
= AREF (vector
, 9);
11374 mode_line_target
= XINT (AREF (vector
, 0));
11375 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11376 mode_line_string_list
= AREF (vector
, 2);
11377 if (! EQ (AREF (vector
, 3), Qt
))
11378 mode_line_proptrans_alist
= AREF (vector
, 3);
11379 mode_line_string_face
= AREF (vector
, 4);
11380 mode_line_string_face_prop
= AREF (vector
, 5);
11382 /* Select window before buffer, since it may change the buffer. */
11383 if (!NILP (old_window
))
11385 /* If the operation that we are unwinding had selected a window
11386 on a different frame, reset its frame-selected-window. For a
11387 text terminal, reset its top-frame if necessary. */
11388 if (!NILP (target_frame_window
))
11391 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11393 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11394 Fselect_window (target_frame_window
, Qt
);
11396 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11397 Fselect_frame (old_top_frame
, Qt
);
11400 Fselect_window (old_window
, Qt
);
11403 if (!NILP (AREF (vector
, 6)))
11405 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11406 ASET (vector
, 6, Qnil
);
11409 Vmode_line_unwind_vector
= vector
;
11413 /* Store a single character C for the frame title in mode_line_noprop_buf.
11414 Re-allocate mode_line_noprop_buf if necessary. */
11417 store_mode_line_noprop_char (char c
)
11419 /* If output position has reached the end of the allocated buffer,
11420 increase the buffer's size. */
11421 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11423 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11424 ptrdiff_t size
= len
;
11425 mode_line_noprop_buf
=
11426 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11427 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11428 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11431 *mode_line_noprop_ptr
++ = c
;
11435 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11436 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11437 characters that yield more columns than PRECISION; PRECISION <= 0
11438 means copy the whole string. Pad with spaces until FIELD_WIDTH
11439 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11440 pad. Called from display_mode_element when it is used to build a
11444 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11446 const unsigned char *str
= (const unsigned char *) string
;
11448 ptrdiff_t dummy
, nbytes
;
11450 /* Copy at most PRECISION chars from STR. */
11451 nbytes
= strlen (string
);
11452 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11454 store_mode_line_noprop_char (*str
++);
11456 /* Fill up with spaces until FIELD_WIDTH reached. */
11457 while (field_width
> 0
11458 && n
< field_width
)
11460 store_mode_line_noprop_char (' ');
11467 /***********************************************************************
11469 ***********************************************************************/
11471 #ifdef HAVE_WINDOW_SYSTEM
11473 /* Set the title of FRAME, if it has changed. The title format is
11474 Vicon_title_format if FRAME is iconified, otherwise it is
11475 frame_title_format. */
11478 x_consider_frame_title (Lisp_Object frame
)
11480 struct frame
*f
= XFRAME (frame
);
11482 if (FRAME_WINDOW_P (f
)
11483 || FRAME_MINIBUF_ONLY_P (f
)
11484 || f
->explicit_name
)
11486 /* Do we have more than one visible frame on this X display? */
11487 Lisp_Object tail
, other_frame
, fmt
;
11488 ptrdiff_t title_start
;
11492 ptrdiff_t count
= SPECPDL_INDEX ();
11494 FOR_EACH_FRAME (tail
, other_frame
)
11496 struct frame
*tf
= XFRAME (other_frame
);
11499 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11500 && !FRAME_MINIBUF_ONLY_P (tf
)
11501 && !EQ (other_frame
, tip_frame
)
11502 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11506 /* Set global variable indicating that multiple frames exist. */
11507 multiple_frames
= CONSP (tail
);
11509 /* Switch to the buffer of selected window of the frame. Set up
11510 mode_line_target so that display_mode_element will output into
11511 mode_line_noprop_buf; then display the title. */
11512 record_unwind_protect (unwind_format_mode_line
,
11513 format_mode_line_unwind_data
11514 (f
, current_buffer
, selected_window
, 0));
11516 Fselect_window (f
->selected_window
, Qt
);
11517 set_buffer_internal_1
11518 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11519 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11521 mode_line_target
= MODE_LINE_TITLE
;
11522 title_start
= MODE_LINE_NOPROP_LEN (0);
11523 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11524 NULL
, DEFAULT_FACE_ID
);
11525 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11526 len
= MODE_LINE_NOPROP_LEN (title_start
);
11527 title
= mode_line_noprop_buf
+ title_start
;
11528 unbind_to (count
, Qnil
);
11530 /* Set the title only if it's changed. This avoids consing in
11531 the common case where it hasn't. (If it turns out that we've
11532 already wasted too much time by walking through the list with
11533 display_mode_element, then we might need to optimize at a
11534 higher level than this.) */
11535 if (! STRINGP (f
->name
)
11536 || SBYTES (f
->name
) != len
11537 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11538 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11542 #endif /* not HAVE_WINDOW_SYSTEM */
11545 /***********************************************************************
11547 ***********************************************************************/
11549 /* Non-zero if we will not redisplay all visible windows. */
11550 #define REDISPLAY_SOME_P() \
11551 ((windows_or_buffers_changed == 0 \
11552 || windows_or_buffers_changed == REDISPLAY_SOME) \
11553 && (update_mode_lines == 0 \
11554 || update_mode_lines == REDISPLAY_SOME))
11556 /* Prepare for redisplay by updating menu-bar item lists when
11557 appropriate. This can call eval. */
11560 prepare_menu_bars (void)
11562 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11563 bool some_windows
= REDISPLAY_SOME_P ();
11564 struct gcpro gcpro1
, gcpro2
;
11565 Lisp_Object tooltip_frame
;
11567 #ifdef HAVE_WINDOW_SYSTEM
11568 tooltip_frame
= tip_frame
;
11570 tooltip_frame
= Qnil
;
11573 if (FUNCTIONP (Vpre_redisplay_function
))
11575 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11576 if (all_windows
&& some_windows
)
11578 Lisp_Object ws
= window_list ();
11579 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11581 Lisp_Object
this = XCAR (ws
);
11582 struct window
*w
= XWINDOW (this);
11584 || XFRAME (w
->frame
)->redisplay
11585 || XBUFFER (w
->contents
)->text
->redisplay
)
11587 windows
= Fcons (this, windows
);
11591 safe__call1 (true, Vpre_redisplay_function
, windows
);
11594 /* Update all frame titles based on their buffer names, etc. We do
11595 this before the menu bars so that the buffer-menu will show the
11596 up-to-date frame titles. */
11597 #ifdef HAVE_WINDOW_SYSTEM
11600 Lisp_Object tail
, frame
;
11602 FOR_EACH_FRAME (tail
, frame
)
11604 struct frame
*f
= XFRAME (frame
);
11605 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11609 && !XBUFFER (w
->contents
)->text
->redisplay
)
11612 if (!EQ (frame
, tooltip_frame
)
11613 && (FRAME_ICONIFIED_P (f
)
11614 || FRAME_VISIBLE_P (f
) == 1
11615 /* Exclude TTY frames that are obscured because they
11616 are not the top frame on their console. This is
11617 because x_consider_frame_title actually switches
11618 to the frame, which for TTY frames means it is
11619 marked as garbaged, and will be completely
11620 redrawn on the next redisplay cycle. This causes
11621 TTY frames to be completely redrawn, when there
11622 are more than one of them, even though nothing
11623 should be changed on display. */
11624 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11625 x_consider_frame_title (frame
);
11628 #endif /* HAVE_WINDOW_SYSTEM */
11630 /* Update the menu bar item lists, if appropriate. This has to be
11631 done before any actual redisplay or generation of display lines. */
11635 Lisp_Object tail
, frame
;
11636 ptrdiff_t count
= SPECPDL_INDEX ();
11637 /* 1 means that update_menu_bar has run its hooks
11638 so any further calls to update_menu_bar shouldn't do so again. */
11639 int menu_bar_hooks_run
= 0;
11641 record_unwind_save_match_data ();
11643 FOR_EACH_FRAME (tail
, frame
)
11645 struct frame
*f
= XFRAME (frame
);
11646 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11648 /* Ignore tooltip frame. */
11649 if (EQ (frame
, tooltip_frame
))
11655 && !XBUFFER (w
->contents
)->text
->redisplay
)
11658 /* If a window on this frame changed size, report that to
11659 the user and clear the size-change flag. */
11660 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11662 Lisp_Object functions
;
11664 /* Clear flag first in case we get an error below. */
11665 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11666 functions
= Vwindow_size_change_functions
;
11667 GCPRO2 (tail
, functions
);
11669 while (CONSP (functions
))
11671 if (!EQ (XCAR (functions
), Qt
))
11672 call1 (XCAR (functions
), frame
);
11673 functions
= XCDR (functions
);
11679 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11680 #ifdef HAVE_WINDOW_SYSTEM
11681 update_tool_bar (f
, 0);
11686 unbind_to (count
, Qnil
);
11690 struct frame
*sf
= SELECTED_FRAME ();
11691 update_menu_bar (sf
, 1, 0);
11692 #ifdef HAVE_WINDOW_SYSTEM
11693 update_tool_bar (sf
, 1);
11699 /* Update the menu bar item list for frame F. This has to be done
11700 before we start to fill in any display lines, because it can call
11703 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11705 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11706 already ran the menu bar hooks for this redisplay, so there
11707 is no need to run them again. The return value is the
11708 updated value of this flag, to pass to the next call. */
11711 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11713 Lisp_Object window
;
11714 register struct window
*w
;
11716 /* If called recursively during a menu update, do nothing. This can
11717 happen when, for instance, an activate-menubar-hook causes a
11719 if (inhibit_menubar_update
)
11722 window
= FRAME_SELECTED_WINDOW (f
);
11723 w
= XWINDOW (window
);
11725 if (FRAME_WINDOW_P (f
)
11727 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11728 || defined (HAVE_NS) || defined (USE_GTK)
11729 FRAME_EXTERNAL_MENU_BAR (f
)
11731 FRAME_MENU_BAR_LINES (f
) > 0
11733 : FRAME_MENU_BAR_LINES (f
) > 0)
11735 /* If the user has switched buffers or windows, we need to
11736 recompute to reflect the new bindings. But we'll
11737 recompute when update_mode_lines is set too; that means
11738 that people can use force-mode-line-update to request
11739 that the menu bar be recomputed. The adverse effect on
11740 the rest of the redisplay algorithm is about the same as
11741 windows_or_buffers_changed anyway. */
11742 if (windows_or_buffers_changed
11743 /* This used to test w->update_mode_line, but we believe
11744 there is no need to recompute the menu in that case. */
11745 || update_mode_lines
11746 || window_buffer_changed (w
))
11748 struct buffer
*prev
= current_buffer
;
11749 ptrdiff_t count
= SPECPDL_INDEX ();
11751 specbind (Qinhibit_menubar_update
, Qt
);
11753 set_buffer_internal_1 (XBUFFER (w
->contents
));
11754 if (save_match_data
)
11755 record_unwind_save_match_data ();
11756 if (NILP (Voverriding_local_map_menu_flag
))
11758 specbind (Qoverriding_terminal_local_map
, Qnil
);
11759 specbind (Qoverriding_local_map
, Qnil
);
11764 /* Run the Lucid hook. */
11765 safe_run_hooks (Qactivate_menubar_hook
);
11767 /* If it has changed current-menubar from previous value,
11768 really recompute the menu-bar from the value. */
11769 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11770 call0 (Qrecompute_lucid_menubar
);
11772 safe_run_hooks (Qmenu_bar_update_hook
);
11777 XSETFRAME (Vmenu_updating_frame
, f
);
11778 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11780 /* Redisplay the menu bar in case we changed it. */
11781 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11782 || defined (HAVE_NS) || defined (USE_GTK)
11783 if (FRAME_WINDOW_P (f
))
11785 #if defined (HAVE_NS)
11786 /* All frames on Mac OS share the same menubar. So only
11787 the selected frame should be allowed to set it. */
11788 if (f
== SELECTED_FRAME ())
11790 set_frame_menubar (f
, 0, 0);
11793 /* On a terminal screen, the menu bar is an ordinary screen
11794 line, and this makes it get updated. */
11795 w
->update_mode_line
= 1;
11796 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11797 /* In the non-toolkit version, the menu bar is an ordinary screen
11798 line, and this makes it get updated. */
11799 w
->update_mode_line
= 1;
11800 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11802 unbind_to (count
, Qnil
);
11803 set_buffer_internal_1 (prev
);
11810 /***********************************************************************
11812 ***********************************************************************/
11814 #ifdef HAVE_WINDOW_SYSTEM
11816 /* Select `frame' temporarily without running all the code in
11818 FIXME: Maybe do_switch_frame should be trimmed down similarly
11819 when `norecord' is set. */
11821 fast_set_selected_frame (Lisp_Object frame
)
11823 if (!EQ (selected_frame
, frame
))
11825 selected_frame
= frame
;
11826 selected_window
= XFRAME (frame
)->selected_window
;
11830 /* Update the tool-bar item list for frame F. This has to be done
11831 before we start to fill in any display lines. Called from
11832 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11833 and restore it here. */
11836 update_tool_bar (struct frame
*f
, int save_match_data
)
11838 #if defined (USE_GTK) || defined (HAVE_NS)
11839 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11841 int do_update
= (WINDOWP (f
->tool_bar_window
)
11842 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0);
11847 Lisp_Object window
;
11850 window
= FRAME_SELECTED_WINDOW (f
);
11851 w
= XWINDOW (window
);
11853 /* If the user has switched buffers or windows, we need to
11854 recompute to reflect the new bindings. But we'll
11855 recompute when update_mode_lines is set too; that means
11856 that people can use force-mode-line-update to request
11857 that the menu bar be recomputed. The adverse effect on
11858 the rest of the redisplay algorithm is about the same as
11859 windows_or_buffers_changed anyway. */
11860 if (windows_or_buffers_changed
11861 || w
->update_mode_line
11862 || update_mode_lines
11863 || window_buffer_changed (w
))
11865 struct buffer
*prev
= current_buffer
;
11866 ptrdiff_t count
= SPECPDL_INDEX ();
11867 Lisp_Object frame
, new_tool_bar
;
11868 int new_n_tool_bar
;
11869 struct gcpro gcpro1
;
11871 /* Set current_buffer to the buffer of the selected
11872 window of the frame, so that we get the right local
11874 set_buffer_internal_1 (XBUFFER (w
->contents
));
11876 /* Save match data, if we must. */
11877 if (save_match_data
)
11878 record_unwind_save_match_data ();
11880 /* Make sure that we don't accidentally use bogus keymaps. */
11881 if (NILP (Voverriding_local_map_menu_flag
))
11883 specbind (Qoverriding_terminal_local_map
, Qnil
);
11884 specbind (Qoverriding_local_map
, Qnil
);
11887 GCPRO1 (new_tool_bar
);
11889 /* We must temporarily set the selected frame to this frame
11890 before calling tool_bar_items, because the calculation of
11891 the tool-bar keymap uses the selected frame (see
11892 `tool-bar-make-keymap' in tool-bar.el). */
11893 eassert (EQ (selected_window
,
11894 /* Since we only explicitly preserve selected_frame,
11895 check that selected_window would be redundant. */
11896 XFRAME (selected_frame
)->selected_window
));
11897 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11898 XSETFRAME (frame
, f
);
11899 fast_set_selected_frame (frame
);
11901 /* Build desired tool-bar items from keymaps. */
11903 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11906 /* Redisplay the tool-bar if we changed it. */
11907 if (new_n_tool_bar
!= f
->n_tool_bar_items
11908 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11910 /* Redisplay that happens asynchronously due to an expose event
11911 may access f->tool_bar_items. Make sure we update both
11912 variables within BLOCK_INPUT so no such event interrupts. */
11914 fset_tool_bar_items (f
, new_tool_bar
);
11915 f
->n_tool_bar_items
= new_n_tool_bar
;
11916 w
->update_mode_line
= 1;
11922 unbind_to (count
, Qnil
);
11923 set_buffer_internal_1 (prev
);
11928 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11930 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11931 F's desired tool-bar contents. F->tool_bar_items must have
11932 been set up previously by calling prepare_menu_bars. */
11935 build_desired_tool_bar_string (struct frame
*f
)
11937 int i
, size
, size_needed
;
11938 struct gcpro gcpro1
, gcpro2
;
11939 Lisp_Object image
, plist
;
11941 image
= plist
= Qnil
;
11942 GCPRO2 (image
, plist
);
11944 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11945 Otherwise, make a new string. */
11947 /* The size of the string we might be able to reuse. */
11948 size
= (STRINGP (f
->desired_tool_bar_string
)
11949 ? SCHARS (f
->desired_tool_bar_string
)
11952 /* We need one space in the string for each image. */
11953 size_needed
= f
->n_tool_bar_items
;
11955 /* Reuse f->desired_tool_bar_string, if possible. */
11956 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11957 fset_desired_tool_bar_string
11958 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11961 AUTO_LIST4 (props
, Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11962 struct gcpro gcpro1
;
11964 Fremove_text_properties (make_number (0), make_number (size
),
11965 props
, f
->desired_tool_bar_string
);
11969 /* Put a `display' property on the string for the images to display,
11970 put a `menu_item' property on tool-bar items with a value that
11971 is the index of the item in F's tool-bar item vector. */
11972 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11974 #define PROP(IDX) \
11975 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11977 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11978 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11979 int hmargin
, vmargin
, relief
, idx
, end
;
11981 /* If image is a vector, choose the image according to the
11983 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11984 if (VECTORP (image
))
11988 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11989 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11992 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11993 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11995 eassert (ASIZE (image
) >= idx
);
11996 image
= AREF (image
, idx
);
12001 /* Ignore invalid image specifications. */
12002 if (!valid_image_p (image
))
12005 /* Display the tool-bar button pressed, or depressed. */
12006 plist
= Fcopy_sequence (XCDR (image
));
12008 /* Compute margin and relief to draw. */
12009 relief
= (tool_bar_button_relief
>= 0
12010 ? tool_bar_button_relief
12011 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
12012 hmargin
= vmargin
= relief
;
12014 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
12015 INT_MAX
- max (hmargin
, vmargin
)))
12017 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
12018 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
12020 else if (CONSP (Vtool_bar_button_margin
))
12022 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
12023 INT_MAX
- hmargin
))
12024 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
12026 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
12027 INT_MAX
- vmargin
))
12028 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
12031 if (auto_raise_tool_bar_buttons_p
)
12033 /* Add a `:relief' property to the image spec if the item is
12037 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
12044 /* If image is selected, display it pressed, i.e. with a
12045 negative relief. If it's not selected, display it with a
12047 plist
= Fplist_put (plist
, QCrelief
,
12049 ? make_number (-relief
)
12050 : make_number (relief
)));
12055 /* Put a margin around the image. */
12056 if (hmargin
|| vmargin
)
12058 if (hmargin
== vmargin
)
12059 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
12061 plist
= Fplist_put (plist
, QCmargin
,
12062 Fcons (make_number (hmargin
),
12063 make_number (vmargin
)));
12066 /* If button is not enabled, and we don't have special images
12067 for the disabled state, make the image appear disabled by
12068 applying an appropriate algorithm to it. */
12069 if (!enabled_p
&& idx
< 0)
12070 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
12072 /* Put a `display' text property on the string for the image to
12073 display. Put a `menu-item' property on the string that gives
12074 the start of this item's properties in the tool-bar items
12076 image
= Fcons (Qimage
, plist
);
12077 AUTO_LIST4 (props
, Qdisplay
, image
, Qmenu_item
,
12078 make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
12079 struct gcpro gcpro1
;
12082 /* Let the last image hide all remaining spaces in the tool bar
12083 string. The string can be longer than needed when we reuse a
12084 previous string. */
12085 if (i
+ 1 == f
->n_tool_bar_items
)
12086 end
= SCHARS (f
->desired_tool_bar_string
);
12089 Fadd_text_properties (make_number (i
), make_number (end
),
12090 props
, f
->desired_tool_bar_string
);
12099 /* Display one line of the tool-bar of frame IT->f.
12101 HEIGHT specifies the desired height of the tool-bar line.
12102 If the actual height of the glyph row is less than HEIGHT, the
12103 row's height is increased to HEIGHT, and the icons are centered
12104 vertically in the new height.
12106 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
12107 count a final empty row in case the tool-bar width exactly matches
12112 display_tool_bar_line (struct it
*it
, int height
)
12114 struct glyph_row
*row
= it
->glyph_row
;
12115 int max_x
= it
->last_visible_x
;
12116 struct glyph
*last
;
12118 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
12119 clear_glyph_row (row
);
12120 row
->enabled_p
= true;
12121 row
->y
= it
->current_y
;
12123 /* Note that this isn't made use of if the face hasn't a box,
12124 so there's no need to check the face here. */
12125 it
->start_of_box_run_p
= 1;
12127 while (it
->current_x
< max_x
)
12129 int x
, n_glyphs_before
, i
, nglyphs
;
12130 struct it it_before
;
12132 /* Get the next display element. */
12133 if (!get_next_display_element (it
))
12135 /* Don't count empty row if we are counting needed tool-bar lines. */
12136 if (height
< 0 && !it
->hpos
)
12141 /* Produce glyphs. */
12142 n_glyphs_before
= row
->used
[TEXT_AREA
];
12145 PRODUCE_GLYPHS (it
);
12147 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
12149 x
= it_before
.current_x
;
12150 while (i
< nglyphs
)
12152 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
12154 if (x
+ glyph
->pixel_width
> max_x
)
12156 /* Glyph doesn't fit on line. Backtrack. */
12157 row
->used
[TEXT_AREA
] = n_glyphs_before
;
12159 /* If this is the only glyph on this line, it will never fit on the
12160 tool-bar, so skip it. But ensure there is at least one glyph,
12161 so we don't accidentally disable the tool-bar. */
12162 if (n_glyphs_before
== 0
12163 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
12169 x
+= glyph
->pixel_width
;
12173 /* Stop at line end. */
12174 if (ITERATOR_AT_END_OF_LINE_P (it
))
12177 set_iterator_to_next (it
, 1);
12182 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12184 /* Use default face for the border below the tool bar.
12186 FIXME: When auto-resize-tool-bars is grow-only, there is
12187 no additional border below the possibly empty tool-bar lines.
12188 So to make the extra empty lines look "normal", we have to
12189 use the tool-bar face for the border too. */
12190 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12191 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12192 it
->face_id
= DEFAULT_FACE_ID
;
12194 extend_face_to_end_of_line (it
);
12195 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12196 last
->right_box_line_p
= 1;
12197 if (last
== row
->glyphs
[TEXT_AREA
])
12198 last
->left_box_line_p
= 1;
12200 /* Make line the desired height and center it vertically. */
12201 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12203 /* Don't add more than one line height. */
12204 height
%= FRAME_LINE_HEIGHT (it
->f
);
12205 it
->max_ascent
+= height
/ 2;
12206 it
->max_descent
+= (height
+ 1) / 2;
12209 compute_line_metrics (it
);
12211 /* If line is empty, make it occupy the rest of the tool-bar. */
12212 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12214 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12215 row
->visible_height
= row
->height
;
12216 row
->ascent
= row
->phys_ascent
= 0;
12217 row
->extra_line_spacing
= 0;
12220 row
->full_width_p
= 1;
12221 row
->continued_p
= 0;
12222 row
->truncated_on_left_p
= 0;
12223 row
->truncated_on_right_p
= 0;
12225 it
->current_x
= it
->hpos
= 0;
12226 it
->current_y
+= row
->height
;
12232 /* Value is the number of pixels needed to make all tool-bar items of
12233 frame F visible. The actual number of glyph rows needed is
12234 returned in *N_ROWS if non-NULL. */
12236 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12238 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12240 /* tool_bar_height is called from redisplay_tool_bar after building
12241 the desired matrix, so use (unused) mode-line row as temporary row to
12242 avoid destroying the first tool-bar row. */
12243 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12245 /* Initialize an iterator for iteration over
12246 F->desired_tool_bar_string in the tool-bar window of frame F. */
12247 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12248 temp_row
->reversed_p
= false;
12249 it
.first_visible_x
= 0;
12250 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12251 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12252 it
.paragraph_embedding
= L2R
;
12254 while (!ITERATOR_AT_END_P (&it
))
12256 clear_glyph_row (temp_row
);
12257 it
.glyph_row
= temp_row
;
12258 display_tool_bar_line (&it
, -1);
12260 clear_glyph_row (temp_row
);
12262 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12264 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12267 return it
.current_y
;
12269 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12272 #endif /* !USE_GTK && !HAVE_NS */
12274 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12276 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12277 If FRAME is nil or omitted, use the selected frame. Optional argument
12278 PIXELWISE non-nil means return the height of the tool bar in pixels. */)
12279 (Lisp_Object frame
, Lisp_Object pixelwise
)
12283 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12284 struct frame
*f
= decode_any_frame (frame
);
12286 if (WINDOWP (f
->tool_bar_window
)
12287 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12289 update_tool_bar (f
, 1);
12290 if (f
->n_tool_bar_items
)
12292 build_desired_tool_bar_string (f
);
12293 height
= tool_bar_height (f
, NULL
, NILP (pixelwise
) ? 0 : 1);
12298 return make_number (height
);
12302 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12303 height should be changed. */
12305 redisplay_tool_bar (struct frame
*f
)
12307 #if defined (USE_GTK) || defined (HAVE_NS)
12309 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12310 update_frame_tool_bar (f
);
12313 #else /* !USE_GTK && !HAVE_NS */
12317 struct glyph_row
*row
;
12319 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12320 do anything. This means you must start with tool-bar-lines
12321 non-zero to get the auto-sizing effect. Or in other words, you
12322 can turn off tool-bars by specifying tool-bar-lines zero. */
12323 if (!WINDOWP (f
->tool_bar_window
)
12324 || (w
= XWINDOW (f
->tool_bar_window
),
12325 WINDOW_TOTAL_LINES (w
) == 0))
12328 /* Set up an iterator for the tool-bar window. */
12329 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12330 it
.first_visible_x
= 0;
12331 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12332 row
= it
.glyph_row
;
12333 row
->reversed_p
= false;
12335 /* Build a string that represents the contents of the tool-bar. */
12336 build_desired_tool_bar_string (f
);
12337 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12338 /* FIXME: This should be controlled by a user option. But it
12339 doesn't make sense to have an R2L tool bar if the menu bar cannot
12340 be drawn also R2L, and making the menu bar R2L is tricky due
12341 toolkit-specific code that implements it. If an R2L tool bar is
12342 ever supported, display_tool_bar_line should also be augmented to
12343 call unproduce_glyphs like display_line and display_string
12345 it
.paragraph_embedding
= L2R
;
12347 if (f
->n_tool_bar_rows
== 0)
12349 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, 1);
12351 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12353 x_change_tool_bar_height (f
, new_height
);
12354 /* Always do that now. */
12355 clear_glyph_matrix (w
->desired_matrix
);
12356 f
->fonts_changed
= 1;
12361 /* Display as many lines as needed to display all tool-bar items. */
12363 if (f
->n_tool_bar_rows
> 0)
12365 int border
, rows
, height
, extra
;
12367 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12368 border
= XINT (Vtool_bar_border
);
12369 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12370 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12371 else if (EQ (Vtool_bar_border
, Qborder_width
))
12372 border
= f
->border_width
;
12378 rows
= f
->n_tool_bar_rows
;
12379 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12380 extra
= it
.last_visible_y
- border
- height
* rows
;
12382 while (it
.current_y
< it
.last_visible_y
)
12385 if (extra
> 0 && rows
-- > 0)
12387 h
= (extra
+ rows
- 1) / rows
;
12390 display_tool_bar_line (&it
, height
+ h
);
12395 while (it
.current_y
< it
.last_visible_y
)
12396 display_tool_bar_line (&it
, 0);
12399 /* It doesn't make much sense to try scrolling in the tool-bar
12400 window, so don't do it. */
12401 w
->desired_matrix
->no_scrolling_p
= 1;
12402 w
->must_be_updated_p
= 1;
12404 if (!NILP (Vauto_resize_tool_bars
))
12406 int change_height_p
= 0;
12408 /* If we couldn't display everything, change the tool-bar's
12409 height if there is room for more. */
12410 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
)
12411 change_height_p
= 1;
12413 /* We subtract 1 because display_tool_bar_line advances the
12414 glyph_row pointer before returning to its caller. We want to
12415 examine the last glyph row produced by
12416 display_tool_bar_line. */
12417 row
= it
.glyph_row
- 1;
12419 /* If there are blank lines at the end, except for a partially
12420 visible blank line at the end that is smaller than
12421 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12422 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12423 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12424 change_height_p
= 1;
12426 /* If row displays tool-bar items, but is partially visible,
12427 change the tool-bar's height. */
12428 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12429 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
)
12430 change_height_p
= 1;
12432 /* Resize windows as needed by changing the `tool-bar-lines'
12433 frame parameter. */
12434 if (change_height_p
)
12437 int new_height
= tool_bar_height (f
, &nrows
, 1);
12439 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12440 && !f
->minimize_tool_bar_window_p
)
12441 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12442 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12443 f
->minimize_tool_bar_window_p
= 0;
12445 if (change_height_p
)
12447 x_change_tool_bar_height (f
, new_height
);
12448 clear_glyph_matrix (w
->desired_matrix
);
12449 f
->n_tool_bar_rows
= nrows
;
12450 f
->fonts_changed
= 1;
12457 f
->minimize_tool_bar_window_p
= 0;
12460 #endif /* USE_GTK || HAVE_NS */
12463 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12465 /* Get information about the tool-bar item which is displayed in GLYPH
12466 on frame F. Return in *PROP_IDX the index where tool-bar item
12467 properties start in F->tool_bar_items. Value is zero if
12468 GLYPH doesn't display a tool-bar item. */
12471 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12477 /* This function can be called asynchronously, which means we must
12478 exclude any possibility that Fget_text_property signals an
12480 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12481 charpos
= max (0, charpos
);
12483 /* Get the text property `menu-item' at pos. The value of that
12484 property is the start index of this item's properties in
12485 F->tool_bar_items. */
12486 prop
= Fget_text_property (make_number (charpos
),
12487 Qmenu_item
, f
->current_tool_bar_string
);
12488 if (INTEGERP (prop
))
12490 *prop_idx
= XINT (prop
);
12500 /* Get information about the tool-bar item at position X/Y on frame F.
12501 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12502 the current matrix of the tool-bar window of F, or NULL if not
12503 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12504 item in F->tool_bar_items. Value is
12506 -1 if X/Y is not on a tool-bar item
12507 0 if X/Y is on the same item that was highlighted before.
12511 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12512 int *hpos
, int *vpos
, int *prop_idx
)
12514 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12515 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12518 /* Find the glyph under X/Y. */
12519 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12520 if (*glyph
== NULL
)
12523 /* Get the start of this tool-bar item's properties in
12524 f->tool_bar_items. */
12525 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12528 /* Is mouse on the highlighted item? */
12529 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12530 && *vpos
>= hlinfo
->mouse_face_beg_row
12531 && *vpos
<= hlinfo
->mouse_face_end_row
12532 && (*vpos
> hlinfo
->mouse_face_beg_row
12533 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12534 && (*vpos
< hlinfo
->mouse_face_end_row
12535 || *hpos
< hlinfo
->mouse_face_end_col
12536 || hlinfo
->mouse_face_past_end
))
12544 Handle mouse button event on the tool-bar of frame F, at
12545 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12546 0 for button release. MODIFIERS is event modifiers for button
12550 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12553 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12554 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12555 int hpos
, vpos
, prop_idx
;
12556 struct glyph
*glyph
;
12557 Lisp_Object enabled_p
;
12560 /* If not on the highlighted tool-bar item, and mouse-highlight is
12561 non-nil, return. This is so we generate the tool-bar button
12562 click only when the mouse button is released on the same item as
12563 where it was pressed. However, when mouse-highlight is disabled,
12564 generate the click when the button is released regardless of the
12565 highlight, since tool-bar items are not highlighted in that
12567 frame_to_window_pixel_xy (w
, &x
, &y
);
12568 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12570 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12573 /* When mouse-highlight is off, generate the click for the item
12574 where the button was pressed, disregarding where it was
12576 if (NILP (Vmouse_highlight
) && !down_p
)
12577 prop_idx
= f
->last_tool_bar_item
;
12579 /* If item is disabled, do nothing. */
12580 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12581 if (NILP (enabled_p
))
12586 /* Show item in pressed state. */
12587 if (!NILP (Vmouse_highlight
))
12588 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12589 f
->last_tool_bar_item
= prop_idx
;
12593 Lisp_Object key
, frame
;
12594 struct input_event event
;
12595 EVENT_INIT (event
);
12597 /* Show item in released state. */
12598 if (!NILP (Vmouse_highlight
))
12599 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12601 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12603 XSETFRAME (frame
, f
);
12604 event
.kind
= TOOL_BAR_EVENT
;
12605 event
.frame_or_window
= frame
;
12607 kbd_buffer_store_event (&event
);
12609 event
.kind
= TOOL_BAR_EVENT
;
12610 event
.frame_or_window
= frame
;
12612 event
.modifiers
= modifiers
;
12613 kbd_buffer_store_event (&event
);
12614 f
->last_tool_bar_item
= -1;
12619 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12620 tool-bar window-relative coordinates X/Y. Called from
12621 note_mouse_highlight. */
12624 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12626 Lisp_Object window
= f
->tool_bar_window
;
12627 struct window
*w
= XWINDOW (window
);
12628 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12629 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12631 struct glyph
*glyph
;
12632 struct glyph_row
*row
;
12634 Lisp_Object enabled_p
;
12636 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12637 int mouse_down_p
, rc
;
12639 /* Function note_mouse_highlight is called with negative X/Y
12640 values when mouse moves outside of the frame. */
12641 if (x
<= 0 || y
<= 0)
12643 clear_mouse_face (hlinfo
);
12647 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12650 /* Not on tool-bar item. */
12651 clear_mouse_face (hlinfo
);
12655 /* On same tool-bar item as before. */
12656 goto set_help_echo
;
12658 clear_mouse_face (hlinfo
);
12660 /* Mouse is down, but on different tool-bar item? */
12661 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12662 && f
== dpyinfo
->last_mouse_frame
);
12664 if (mouse_down_p
&& f
->last_tool_bar_item
!= prop_idx
)
12667 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12669 /* If tool-bar item is not enabled, don't highlight it. */
12670 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12671 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12673 /* Compute the x-position of the glyph. In front and past the
12674 image is a space. We include this in the highlighted area. */
12675 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12676 for (i
= x
= 0; i
< hpos
; ++i
)
12677 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12679 /* Record this as the current active region. */
12680 hlinfo
->mouse_face_beg_col
= hpos
;
12681 hlinfo
->mouse_face_beg_row
= vpos
;
12682 hlinfo
->mouse_face_beg_x
= x
;
12683 hlinfo
->mouse_face_past_end
= 0;
12685 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12686 hlinfo
->mouse_face_end_row
= vpos
;
12687 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12688 hlinfo
->mouse_face_window
= window
;
12689 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12691 /* Display it as active. */
12692 show_mouse_face (hlinfo
, draw
);
12697 /* Set help_echo_string to a help string to display for this tool-bar item.
12698 XTread_socket does the rest. */
12699 help_echo_object
= help_echo_window
= Qnil
;
12700 help_echo_pos
= -1;
12701 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12702 if (NILP (help_echo_string
))
12703 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12706 #endif /* !USE_GTK && !HAVE_NS */
12708 #endif /* HAVE_WINDOW_SYSTEM */
12712 /************************************************************************
12713 Horizontal scrolling
12714 ************************************************************************/
12716 static int hscroll_window_tree (Lisp_Object
);
12717 static int hscroll_windows (Lisp_Object
);
12719 /* For all leaf windows in the window tree rooted at WINDOW, set their
12720 hscroll value so that PT is (i) visible in the window, and (ii) so
12721 that it is not within a certain margin at the window's left and
12722 right border. Value is non-zero if any window's hscroll has been
12726 hscroll_window_tree (Lisp_Object window
)
12728 int hscrolled_p
= 0;
12729 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12730 int hscroll_step_abs
= 0;
12731 double hscroll_step_rel
= 0;
12733 if (hscroll_relative_p
)
12735 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12736 if (hscroll_step_rel
< 0)
12738 hscroll_relative_p
= 0;
12739 hscroll_step_abs
= 0;
12742 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12744 hscroll_step_abs
= XINT (Vhscroll_step
);
12745 if (hscroll_step_abs
< 0)
12746 hscroll_step_abs
= 0;
12749 hscroll_step_abs
= 0;
12751 while (WINDOWP (window
))
12753 struct window
*w
= XWINDOW (window
);
12755 if (WINDOWP (w
->contents
))
12756 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12757 else if (w
->cursor
.vpos
>= 0)
12760 int text_area_width
;
12761 struct glyph_row
*cursor_row
;
12762 struct glyph_row
*bottom_row
;
12765 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->desired_matrix
, w
);
12766 if (w
->cursor
.vpos
< bottom_row
- w
->desired_matrix
->rows
)
12767 cursor_row
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12769 cursor_row
= bottom_row
- 1;
12771 if (!cursor_row
->enabled_p
)
12773 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12774 if (w
->cursor
.vpos
< bottom_row
- w
->current_matrix
->rows
)
12775 cursor_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12777 cursor_row
= bottom_row
- 1;
12779 row_r2l_p
= cursor_row
->reversed_p
;
12781 text_area_width
= window_box_width (w
, TEXT_AREA
);
12783 /* Scroll when cursor is inside this scroll margin. */
12784 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12786 /* If the position of this window's point has explicitly
12787 changed, no more suspend auto hscrolling. */
12788 if (NILP (Fequal (Fwindow_point (window
), Fwindow_old_point (window
))))
12789 w
->suspend_auto_hscroll
= 0;
12791 /* Remember window point. */
12792 Fset_marker (w
->old_pointm
,
12793 ((w
== XWINDOW (selected_window
))
12794 ? make_number (BUF_PT (XBUFFER (w
->contents
)))
12795 : Fmarker_position (w
->pointm
)),
12798 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12799 && w
->suspend_auto_hscroll
== 0
12800 /* In some pathological cases, like restoring a window
12801 configuration into a frame that is much smaller than
12802 the one from which the configuration was saved, we
12803 get glyph rows whose start and end have zero buffer
12804 positions, which we cannot handle below. Just skip
12806 && CHARPOS (cursor_row
->start
.pos
) >= BUF_BEG (w
->contents
)
12807 /* For left-to-right rows, hscroll when cursor is either
12808 (i) inside the right hscroll margin, or (ii) if it is
12809 inside the left margin and the window is already
12812 && ((w
->hscroll
&& w
->cursor
.x
<= h_margin
)
12813 || (cursor_row
->enabled_p
12814 && cursor_row
->truncated_on_right_p
12815 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12816 /* For right-to-left rows, the logic is similar,
12817 except that rules for scrolling to left and right
12818 are reversed. E.g., if cursor.x <= h_margin, we
12819 need to hscroll "to the right" unconditionally,
12820 and that will scroll the screen to the left so as
12821 to reveal the next portion of the row. */
12823 && ((cursor_row
->enabled_p
12824 /* FIXME: It is confusing to set the
12825 truncated_on_right_p flag when R2L rows
12826 are actually truncated on the left. */
12827 && cursor_row
->truncated_on_right_p
12828 && w
->cursor
.x
<= h_margin
)
12830 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12834 struct buffer
*saved_current_buffer
;
12838 /* Find point in a display of infinite width. */
12839 saved_current_buffer
= current_buffer
;
12840 current_buffer
= XBUFFER (w
->contents
);
12842 if (w
== XWINDOW (selected_window
))
12845 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12847 /* Move iterator to pt starting at cursor_row->start in
12848 a line with infinite width. */
12849 init_to_row_start (&it
, w
, cursor_row
);
12850 it
.last_visible_x
= INFINITY
;
12851 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12852 current_buffer
= saved_current_buffer
;
12854 /* Position cursor in window. */
12855 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12856 hscroll
= max (0, (it
.current_x
12857 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12858 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12859 : (text_area_width
/ 2))))
12860 / FRAME_COLUMN_WIDTH (it
.f
);
12861 else if ((!row_r2l_p
12862 && w
->cursor
.x
>= text_area_width
- h_margin
)
12863 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12865 if (hscroll_relative_p
)
12866 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12869 wanted_x
= text_area_width
12870 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12873 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12877 if (hscroll_relative_p
)
12878 wanted_x
= text_area_width
* hscroll_step_rel
12881 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12884 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12886 hscroll
= max (hscroll
, w
->min_hscroll
);
12888 /* Don't prevent redisplay optimizations if hscroll
12889 hasn't changed, as it will unnecessarily slow down
12891 if (w
->hscroll
!= hscroll
)
12893 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12894 w
->hscroll
= hscroll
;
12903 /* Value is non-zero if hscroll of any leaf window has been changed. */
12904 return hscrolled_p
;
12908 /* Set hscroll so that cursor is visible and not inside horizontal
12909 scroll margins for all windows in the tree rooted at WINDOW. See
12910 also hscroll_window_tree above. Value is non-zero if any window's
12911 hscroll has been changed. If it has, desired matrices on the frame
12912 of WINDOW are cleared. */
12915 hscroll_windows (Lisp_Object window
)
12917 int hscrolled_p
= hscroll_window_tree (window
);
12919 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12920 return hscrolled_p
;
12925 /************************************************************************
12927 ************************************************************************/
12929 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12930 to a non-zero value. This is sometimes handy to have in a debugger
12935 /* First and last unchanged row for try_window_id. */
12937 static int debug_first_unchanged_at_end_vpos
;
12938 static int debug_last_unchanged_at_beg_vpos
;
12940 /* Delta vpos and y. */
12942 static int debug_dvpos
, debug_dy
;
12944 /* Delta in characters and bytes for try_window_id. */
12946 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12948 /* Values of window_end_pos and window_end_vpos at the end of
12951 static ptrdiff_t debug_end_vpos
;
12953 /* Append a string to W->desired_matrix->method. FMT is a printf
12954 format string. If trace_redisplay_p is true also printf the
12955 resulting string to stderr. */
12957 static void debug_method_add (struct window
*, char const *, ...)
12958 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12961 debug_method_add (struct window
*w
, char const *fmt
, ...)
12964 char *method
= w
->desired_matrix
->method
;
12965 int len
= strlen (method
);
12966 int size
= sizeof w
->desired_matrix
->method
;
12967 int remaining
= size
- len
- 1;
12970 if (len
&& remaining
)
12973 --remaining
, ++len
;
12976 va_start (ap
, fmt
);
12977 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12980 if (trace_redisplay_p
)
12981 fprintf (stderr
, "%p (%s): %s\n",
12983 ((BUFFERP (w
->contents
)
12984 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12985 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12990 #endif /* GLYPH_DEBUG */
12993 /* Value is non-zero if all changes in window W, which displays
12994 current_buffer, are in the text between START and END. START is a
12995 buffer position, END is given as a distance from Z. Used in
12996 redisplay_internal for display optimization. */
12999 text_outside_line_unchanged_p (struct window
*w
,
13000 ptrdiff_t start
, ptrdiff_t end
)
13002 int unchanged_p
= 1;
13004 /* If text or overlays have changed, see where. */
13005 if (window_outdated (w
))
13007 /* Gap in the line? */
13008 if (GPT
< start
|| Z
- GPT
< end
)
13011 /* Changes start in front of the line, or end after it? */
13013 && (BEG_UNCHANGED
< start
- 1
13014 || END_UNCHANGED
< end
))
13017 /* If selective display, can't optimize if changes start at the
13018 beginning of the line. */
13020 && INTEGERP (BVAR (current_buffer
, selective_display
))
13021 && XINT (BVAR (current_buffer
, selective_display
)) > 0
13022 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
13025 /* If there are overlays at the start or end of the line, these
13026 may have overlay strings with newlines in them. A change at
13027 START, for instance, may actually concern the display of such
13028 overlay strings as well, and they are displayed on different
13029 lines. So, quickly rule out this case. (For the future, it
13030 might be desirable to implement something more telling than
13031 just BEG/END_UNCHANGED.) */
13034 if (BEG
+ BEG_UNCHANGED
== start
13035 && overlay_touches_p (start
))
13037 if (END_UNCHANGED
== end
13038 && overlay_touches_p (Z
- end
))
13042 /* Under bidi reordering, adding or deleting a character in the
13043 beginning of a paragraph, before the first strong directional
13044 character, can change the base direction of the paragraph (unless
13045 the buffer specifies a fixed paragraph direction), which will
13046 require to redisplay the whole paragraph. It might be worthwhile
13047 to find the paragraph limits and widen the range of redisplayed
13048 lines to that, but for now just give up this optimization. */
13049 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
13050 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
13054 return unchanged_p
;
13058 /* Do a frame update, taking possible shortcuts into account. This is
13059 the main external entry point for redisplay.
13061 If the last redisplay displayed an echo area message and that message
13062 is no longer requested, we clear the echo area or bring back the
13063 mini-buffer if that is in use. */
13068 redisplay_internal ();
13073 overlay_arrow_string_or_property (Lisp_Object var
)
13077 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
13080 return Voverlay_arrow_string
;
13083 /* Return 1 if there are any overlay-arrows in current_buffer. */
13085 overlay_arrow_in_current_buffer_p (void)
13089 for (vlist
= Voverlay_arrow_variable_list
;
13091 vlist
= XCDR (vlist
))
13093 Lisp_Object var
= XCAR (vlist
);
13096 if (!SYMBOLP (var
))
13098 val
= find_symbol_value (var
);
13100 && current_buffer
== XMARKER (val
)->buffer
)
13107 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
13111 overlay_arrows_changed_p (void)
13115 for (vlist
= Voverlay_arrow_variable_list
;
13117 vlist
= XCDR (vlist
))
13119 Lisp_Object var
= XCAR (vlist
);
13120 Lisp_Object val
, pstr
;
13122 if (!SYMBOLP (var
))
13124 val
= find_symbol_value (var
);
13125 if (!MARKERP (val
))
13127 if (! EQ (COERCE_MARKER (val
),
13128 Fget (var
, Qlast_arrow_position
))
13129 || ! (pstr
= overlay_arrow_string_or_property (var
),
13130 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
13136 /* Mark overlay arrows to be updated on next redisplay. */
13139 update_overlay_arrows (int up_to_date
)
13143 for (vlist
= Voverlay_arrow_variable_list
;
13145 vlist
= XCDR (vlist
))
13147 Lisp_Object var
= XCAR (vlist
);
13149 if (!SYMBOLP (var
))
13152 if (up_to_date
> 0)
13154 Lisp_Object val
= find_symbol_value (var
);
13155 Fput (var
, Qlast_arrow_position
,
13156 COERCE_MARKER (val
));
13157 Fput (var
, Qlast_arrow_string
,
13158 overlay_arrow_string_or_property (var
));
13160 else if (up_to_date
< 0
13161 || !NILP (Fget (var
, Qlast_arrow_position
)))
13163 Fput (var
, Qlast_arrow_position
, Qt
);
13164 Fput (var
, Qlast_arrow_string
, Qt
);
13170 /* Return overlay arrow string to display at row.
13171 Return integer (bitmap number) for arrow bitmap in left fringe.
13172 Return nil if no overlay arrow. */
13175 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
13179 for (vlist
= Voverlay_arrow_variable_list
;
13181 vlist
= XCDR (vlist
))
13183 Lisp_Object var
= XCAR (vlist
);
13186 if (!SYMBOLP (var
))
13189 val
= find_symbol_value (var
);
13192 && current_buffer
== XMARKER (val
)->buffer
13193 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13195 if (FRAME_WINDOW_P (it
->f
)
13196 /* FIXME: if ROW->reversed_p is set, this should test
13197 the right fringe, not the left one. */
13198 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13200 #ifdef HAVE_WINDOW_SYSTEM
13201 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13204 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
13205 return make_number (fringe_bitmap
);
13208 return make_number (-1); /* Use default arrow bitmap. */
13210 return overlay_arrow_string_or_property (var
);
13217 /* Return 1 if point moved out of or into a composition. Otherwise
13218 return 0. PREV_BUF and PREV_PT are the last point buffer and
13219 position. BUF and PT are the current point buffer and position. */
13222 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13223 struct buffer
*buf
, ptrdiff_t pt
)
13225 ptrdiff_t start
, end
;
13227 Lisp_Object buffer
;
13229 XSETBUFFER (buffer
, buf
);
13230 /* Check a composition at the last point if point moved within the
13232 if (prev_buf
== buf
)
13235 /* Point didn't move. */
13238 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13239 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13240 && composition_valid_p (start
, end
, prop
)
13241 && start
< prev_pt
&& end
> prev_pt
)
13242 /* The last point was within the composition. Return 1 iff
13243 point moved out of the composition. */
13244 return (pt
<= start
|| pt
>= end
);
13247 /* Check a composition at the current point. */
13248 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13249 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13250 && composition_valid_p (start
, end
, prop
)
13251 && start
< pt
&& end
> pt
);
13254 /* Reconsider the clip changes of buffer which is displayed in W. */
13257 reconsider_clip_changes (struct window
*w
)
13259 struct buffer
*b
= XBUFFER (w
->contents
);
13261 if (b
->clip_changed
13262 && w
->window_end_valid
13263 && w
->current_matrix
->buffer
== b
13264 && w
->current_matrix
->zv
== BUF_ZV (b
)
13265 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13266 b
->clip_changed
= 0;
13268 /* If display wasn't paused, and W is not a tool bar window, see if
13269 point has been moved into or out of a composition. In that case,
13270 we set b->clip_changed to 1 to force updating the screen. If
13271 b->clip_changed has already been set to 1, we can skip this
13273 if (!b
->clip_changed
&& w
->window_end_valid
)
13275 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13276 ? PT
: marker_position (w
->pointm
));
13278 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13279 && check_point_in_composition (w
->current_matrix
->buffer
,
13280 w
->last_point
, b
, pt
))
13281 b
->clip_changed
= 1;
13286 propagate_buffer_redisplay (void)
13287 { /* Resetting b->text->redisplay is problematic!
13288 We can't just reset it in the case that some window that displays
13289 it has not been redisplayed; and such a window can stay
13290 unredisplayed for a long time if it's currently invisible.
13291 But we do want to reset it at the end of redisplay otherwise
13292 its displayed windows will keep being redisplayed over and over
13294 So we copy all b->text->redisplay flags up to their windows here,
13295 such that mark_window_display_accurate can safely reset
13296 b->text->redisplay. */
13297 Lisp_Object ws
= window_list ();
13298 for (; CONSP (ws
); ws
= XCDR (ws
))
13300 struct window
*thisw
= XWINDOW (XCAR (ws
));
13301 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13302 if (thisb
->text
->redisplay
)
13303 thisw
->redisplay
= true;
13307 #define STOP_POLLING \
13308 do { if (! polling_stopped_here) stop_polling (); \
13309 polling_stopped_here = 1; } while (0)
13311 #define RESUME_POLLING \
13312 do { if (polling_stopped_here) start_polling (); \
13313 polling_stopped_here = 0; } while (0)
13316 /* Perhaps in the future avoid recentering windows if it
13317 is not necessary; currently that causes some problems. */
13320 redisplay_internal (void)
13322 struct window
*w
= XWINDOW (selected_window
);
13326 bool must_finish
= 0, match_p
;
13327 struct text_pos tlbufpos
, tlendpos
;
13328 int number_of_visible_frames
;
13331 int polling_stopped_here
= 0;
13332 Lisp_Object tail
, frame
;
13334 /* True means redisplay has to consider all windows on all
13335 frames. False, only selected_window is considered. */
13336 bool consider_all_windows_p
;
13338 /* True means redisplay has to redisplay the miniwindow. */
13339 bool update_miniwindow_p
= false;
13341 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13343 /* No redisplay if running in batch mode or frame is not yet fully
13344 initialized, or redisplay is explicitly turned off by setting
13345 Vinhibit_redisplay. */
13346 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13347 || !NILP (Vinhibit_redisplay
))
13350 /* Don't examine these until after testing Vinhibit_redisplay.
13351 When Emacs is shutting down, perhaps because its connection to
13352 X has dropped, we should not look at them at all. */
13353 fr
= XFRAME (w
->frame
);
13354 sf
= SELECTED_FRAME ();
13356 if (!fr
->glyphs_initialized_p
)
13359 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13360 if (popup_activated ())
13364 /* I don't think this happens but let's be paranoid. */
13365 if (redisplaying_p
)
13368 /* Record a function that clears redisplaying_p
13369 when we leave this function. */
13370 count
= SPECPDL_INDEX ();
13371 record_unwind_protect_void (unwind_redisplay
);
13372 redisplaying_p
= 1;
13373 specbind (Qinhibit_free_realized_faces
, Qnil
);
13375 /* Record this function, so it appears on the profiler's backtraces. */
13376 record_in_backtrace (Qredisplay_internal
, 0, 0);
13378 FOR_EACH_FRAME (tail
, frame
)
13379 XFRAME (frame
)->already_hscrolled_p
= 0;
13382 /* Remember the currently selected window. */
13386 last_escape_glyph_frame
= NULL
;
13387 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13388 last_glyphless_glyph_frame
= NULL
;
13389 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13391 /* If face_change_count is non-zero, init_iterator will free all
13392 realized faces, which includes the faces referenced from current
13393 matrices. So, we can't reuse current matrices in this case. */
13394 if (face_change_count
)
13395 windows_or_buffers_changed
= 47;
13397 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13398 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13400 /* Since frames on a single ASCII terminal share the same
13401 display area, displaying a different frame means redisplay
13402 the whole thing. */
13403 SET_FRAME_GARBAGED (sf
);
13405 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13407 FRAME_TTY (sf
)->previous_frame
= sf
;
13410 /* Set the visible flags for all frames. Do this before checking for
13411 resized or garbaged frames; they want to know if their frames are
13412 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13413 number_of_visible_frames
= 0;
13415 FOR_EACH_FRAME (tail
, frame
)
13417 struct frame
*f
= XFRAME (frame
);
13419 if (FRAME_VISIBLE_P (f
))
13421 ++number_of_visible_frames
;
13422 /* Adjust matrices for visible frames only. */
13423 if (f
->fonts_changed
)
13425 adjust_frame_glyphs (f
);
13426 f
->fonts_changed
= 0;
13428 /* If cursor type has been changed on the frame
13429 other than selected, consider all frames. */
13430 if (f
!= sf
&& f
->cursor_type_changed
)
13431 update_mode_lines
= 31;
13433 clear_desired_matrices (f
);
13436 /* Notice any pending interrupt request to change frame size. */
13437 do_pending_window_change (true);
13439 /* do_pending_window_change could change the selected_window due to
13440 frame resizing which makes the selected window too small. */
13441 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13444 /* Clear frames marked as garbaged. */
13445 clear_garbaged_frames ();
13447 /* Build menubar and tool-bar items. */
13448 if (NILP (Vmemory_full
))
13449 prepare_menu_bars ();
13451 reconsider_clip_changes (w
);
13453 /* In most cases selected window displays current buffer. */
13454 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13457 /* Detect case that we need to write or remove a star in the mode line. */
13458 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13459 w
->update_mode_line
= 1;
13461 if (mode_line_update_needed (w
))
13462 w
->update_mode_line
= 1;
13464 /* If reconsider_clip_changes above decided that the narrowing
13465 in the current buffer changed, make sure all other windows
13466 showing that buffer will be redisplayed. */
13467 if (current_buffer
->clip_changed
)
13468 bset_update_mode_line (current_buffer
);
13471 /* Normally the message* functions will have already displayed and
13472 updated the echo area, but the frame may have been trashed, or
13473 the update may have been preempted, so display the echo area
13474 again here. Checking message_cleared_p captures the case that
13475 the echo area should be cleared. */
13476 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13477 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13478 || (message_cleared_p
13479 && minibuf_level
== 0
13480 /* If the mini-window is currently selected, this means the
13481 echo-area doesn't show through. */
13482 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13484 int window_height_changed_p
= echo_area_display (false);
13486 if (message_cleared_p
)
13487 update_miniwindow_p
= true;
13491 /* If we don't display the current message, don't clear the
13492 message_cleared_p flag, because, if we did, we wouldn't clear
13493 the echo area in the next redisplay which doesn't preserve
13495 if (!display_last_displayed_message_p
)
13496 message_cleared_p
= 0;
13498 if (window_height_changed_p
)
13500 windows_or_buffers_changed
= 50;
13502 /* If window configuration was changed, frames may have been
13503 marked garbaged. Clear them or we will experience
13504 surprises wrt scrolling. */
13505 clear_garbaged_frames ();
13508 else if (EQ (selected_window
, minibuf_window
)
13509 && (current_buffer
->clip_changed
|| window_outdated (w
))
13510 && resize_mini_window (w
, 0))
13512 /* Resized active mini-window to fit the size of what it is
13513 showing if its contents might have changed. */
13516 /* If window configuration was changed, frames may have been
13517 marked garbaged. Clear them or we will experience
13518 surprises wrt scrolling. */
13519 clear_garbaged_frames ();
13522 if (windows_or_buffers_changed
&& !update_mode_lines
)
13523 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13524 only the windows's contents needs to be refreshed, or whether the
13525 mode-lines also need a refresh. */
13526 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13527 ? REDISPLAY_SOME
: 32);
13529 /* If specs for an arrow have changed, do thorough redisplay
13530 to ensure we remove any arrow that should no longer exist. */
13531 if (overlay_arrows_changed_p ())
13532 /* Apparently, this is the only case where we update other windows,
13533 without updating other mode-lines. */
13534 windows_or_buffers_changed
= 49;
13536 consider_all_windows_p
= (update_mode_lines
13537 || windows_or_buffers_changed
);
13539 #define AINC(a,i) \
13540 if (VECTORP (a) && i >= 0 && i < ASIZE (a) && INTEGERP (AREF (a, i))) \
13541 ASET (a, i, make_number (1 + XINT (AREF (a, i))))
13543 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13544 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13546 /* Optimize the case that only the line containing the cursor in the
13547 selected window has changed. Variables starting with this_ are
13548 set in display_line and record information about the line
13549 containing the cursor. */
13550 tlbufpos
= this_line_start_pos
;
13551 tlendpos
= this_line_end_pos
;
13552 if (!consider_all_windows_p
13553 && CHARPOS (tlbufpos
) > 0
13554 && !w
->update_mode_line
13555 && !current_buffer
->clip_changed
13556 && !current_buffer
->prevent_redisplay_optimizations_p
13557 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13558 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13559 && !XFRAME (w
->frame
)->cursor_type_changed
13560 /* Make sure recorded data applies to current buffer, etc. */
13561 && this_line_buffer
== current_buffer
13564 && !w
->optional_new_start
13565 /* Point must be on the line that we have info recorded about. */
13566 && PT
>= CHARPOS (tlbufpos
)
13567 && PT
<= Z
- CHARPOS (tlendpos
)
13568 /* All text outside that line, including its final newline,
13569 must be unchanged. */
13570 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13571 CHARPOS (tlendpos
)))
13573 if (CHARPOS (tlbufpos
) > BEGV
13574 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13575 && (CHARPOS (tlbufpos
) == ZV
13576 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13577 /* Former continuation line has disappeared by becoming empty. */
13579 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13581 /* We have to handle the case of continuation around a
13582 wide-column character (see the comment in indent.c around
13585 For instance, in the following case:
13587 -------- Insert --------
13588 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13589 J_I_ ==> J_I_ `^^' are cursors.
13593 As we have to redraw the line above, we cannot use this
13597 int line_height_before
= this_line_pixel_height
;
13599 /* Note that start_display will handle the case that the
13600 line starting at tlbufpos is a continuation line. */
13601 start_display (&it
, w
, tlbufpos
);
13603 /* Implementation note: It this still necessary? */
13604 if (it
.current_x
!= this_line_start_x
)
13607 TRACE ((stderr
, "trying display optimization 1\n"));
13608 w
->cursor
.vpos
= -1;
13609 overlay_arrow_seen
= 0;
13610 it
.vpos
= this_line_vpos
;
13611 it
.current_y
= this_line_y
;
13612 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13613 display_line (&it
);
13615 /* If line contains point, is not continued,
13616 and ends at same distance from eob as before, we win. */
13617 if (w
->cursor
.vpos
>= 0
13618 /* Line is not continued, otherwise this_line_start_pos
13619 would have been set to 0 in display_line. */
13620 && CHARPOS (this_line_start_pos
)
13621 /* Line ends as before. */
13622 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13623 /* Line has same height as before. Otherwise other lines
13624 would have to be shifted up or down. */
13625 && this_line_pixel_height
== line_height_before
)
13627 /* If this is not the window's last line, we must adjust
13628 the charstarts of the lines below. */
13629 if (it
.current_y
< it
.last_visible_y
)
13631 struct glyph_row
*row
13632 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13633 ptrdiff_t delta
, delta_bytes
;
13635 /* We used to distinguish between two cases here,
13636 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13637 when the line ends in a newline or the end of the
13638 buffer's accessible portion. But both cases did
13639 the same, so they were collapsed. */
13641 - CHARPOS (tlendpos
)
13642 - MATRIX_ROW_START_CHARPOS (row
));
13643 delta_bytes
= (Z_BYTE
13644 - BYTEPOS (tlendpos
)
13645 - MATRIX_ROW_START_BYTEPOS (row
));
13647 increment_matrix_positions (w
->current_matrix
,
13648 this_line_vpos
+ 1,
13649 w
->current_matrix
->nrows
,
13650 delta
, delta_bytes
);
13653 /* If this row displays text now but previously didn't,
13654 or vice versa, w->window_end_vpos may have to be
13656 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13658 if (w
->window_end_vpos
< this_line_vpos
)
13659 w
->window_end_vpos
= this_line_vpos
;
13661 else if (w
->window_end_vpos
== this_line_vpos
13662 && this_line_vpos
> 0)
13663 w
->window_end_vpos
= this_line_vpos
- 1;
13664 w
->window_end_valid
= 0;
13666 /* Update hint: No need to try to scroll in update_window. */
13667 w
->desired_matrix
->no_scrolling_p
= 1;
13670 *w
->desired_matrix
->method
= 0;
13671 debug_method_add (w
, "optimization 1");
13673 #ifdef HAVE_WINDOW_SYSTEM
13674 update_window_fringes (w
, 0);
13681 else if (/* Cursor position hasn't changed. */
13682 PT
== w
->last_point
13683 /* Make sure the cursor was last displayed
13684 in this window. Otherwise we have to reposition it. */
13686 /* PXW: Must be converted to pixels, probably. */
13687 && 0 <= w
->cursor
.vpos
13688 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13692 do_pending_window_change (true);
13693 /* If selected_window changed, redisplay again. */
13694 if (WINDOWP (selected_window
)
13695 && (w
= XWINDOW (selected_window
)) != sw
)
13698 /* We used to always goto end_of_redisplay here, but this
13699 isn't enough if we have a blinking cursor. */
13700 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13701 goto end_of_redisplay
;
13705 /* If highlighting the region, or if the cursor is in the echo area,
13706 then we can't just move the cursor. */
13707 else if (NILP (Vshow_trailing_whitespace
)
13708 && !cursor_in_echo_area
)
13711 struct glyph_row
*row
;
13713 /* Skip from tlbufpos to PT and see where it is. Note that
13714 PT may be in invisible text. If so, we will end at the
13715 next visible position. */
13716 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13717 NULL
, DEFAULT_FACE_ID
);
13718 it
.current_x
= this_line_start_x
;
13719 it
.current_y
= this_line_y
;
13720 it
.vpos
= this_line_vpos
;
13722 /* The call to move_it_to stops in front of PT, but
13723 moves over before-strings. */
13724 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13726 if (it
.vpos
== this_line_vpos
13727 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13730 eassert (this_line_vpos
== it
.vpos
);
13731 eassert (this_line_y
== it
.current_y
);
13732 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13734 *w
->desired_matrix
->method
= 0;
13735 debug_method_add (w
, "optimization 3");
13744 /* Text changed drastically or point moved off of line. */
13745 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13748 CHARPOS (this_line_start_pos
) = 0;
13749 ++clear_face_cache_count
;
13750 #ifdef HAVE_WINDOW_SYSTEM
13751 ++clear_image_cache_count
;
13754 /* Build desired matrices, and update the display. If
13755 consider_all_windows_p is non-zero, do it for all windows on all
13756 frames. Otherwise do it for selected_window, only. */
13758 if (consider_all_windows_p
)
13760 FOR_EACH_FRAME (tail
, frame
)
13761 XFRAME (frame
)->updated_p
= 0;
13763 propagate_buffer_redisplay ();
13765 FOR_EACH_FRAME (tail
, frame
)
13767 struct frame
*f
= XFRAME (frame
);
13769 /* We don't have to do anything for unselected terminal
13771 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13772 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13777 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13780 /* Only GC scrollbars when we redisplay the whole frame. */
13781 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13782 /* Mark all the scroll bars to be removed; we'll redeem
13783 the ones we want when we redisplay their windows. */
13784 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13785 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13787 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13788 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13789 /* Remember that the invisible frames need to be redisplayed next
13790 time they're visible. */
13791 else if (!REDISPLAY_SOME_P ())
13792 f
->redisplay
= true;
13794 /* The X error handler may have deleted that frame. */
13795 if (!FRAME_LIVE_P (f
))
13798 /* Any scroll bars which redisplay_windows should have
13799 nuked should now go away. */
13800 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13801 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13803 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13805 /* If fonts changed on visible frame, display again. */
13806 if (f
->fonts_changed
)
13808 adjust_frame_glyphs (f
);
13809 f
->fonts_changed
= false;
13813 /* See if we have to hscroll. */
13814 if (!f
->already_hscrolled_p
)
13816 f
->already_hscrolled_p
= true;
13817 if (hscroll_windows (f
->root_window
))
13821 /* Prevent various kinds of signals during display
13822 update. stdio is not robust about handling
13823 signals, which can cause an apparent I/O error. */
13824 if (interrupt_input
)
13825 unrequest_sigio ();
13828 pending
|= update_frame (f
, false, false);
13829 f
->cursor_type_changed
= false;
13830 f
->updated_p
= true;
13835 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13839 /* Do the mark_window_display_accurate after all windows have
13840 been redisplayed because this call resets flags in buffers
13841 which are needed for proper redisplay. */
13842 FOR_EACH_FRAME (tail
, frame
)
13844 struct frame
*f
= XFRAME (frame
);
13847 f
->redisplay
= false;
13848 mark_window_display_accurate (f
->root_window
, 1);
13849 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13850 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13855 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13857 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13858 struct frame
*mini_frame
;
13860 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13861 /* Use list_of_error, not Qerror, so that
13862 we catch only errors and don't run the debugger. */
13863 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13865 redisplay_window_error
);
13866 if (update_miniwindow_p
)
13867 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13869 redisplay_window_error
);
13871 /* Compare desired and current matrices, perform output. */
13874 /* If fonts changed, display again. */
13875 if (sf
->fonts_changed
)
13878 /* Prevent various kinds of signals during display update.
13879 stdio is not robust about handling signals,
13880 which can cause an apparent I/O error. */
13881 if (interrupt_input
)
13882 unrequest_sigio ();
13885 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13887 if (hscroll_windows (selected_window
))
13890 XWINDOW (selected_window
)->must_be_updated_p
= true;
13891 pending
= update_frame (sf
, false, false);
13892 sf
->cursor_type_changed
= false;
13895 /* We may have called echo_area_display at the top of this
13896 function. If the echo area is on another frame, that may
13897 have put text on a frame other than the selected one, so the
13898 above call to update_frame would not have caught it. Catch
13900 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13901 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13903 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13905 XWINDOW (mini_window
)->must_be_updated_p
= true;
13906 pending
|= update_frame (mini_frame
, false, false);
13907 mini_frame
->cursor_type_changed
= false;
13908 if (!pending
&& hscroll_windows (mini_window
))
13913 /* If display was paused because of pending input, make sure we do a
13914 thorough update the next time. */
13917 /* Prevent the optimization at the beginning of
13918 redisplay_internal that tries a single-line update of the
13919 line containing the cursor in the selected window. */
13920 CHARPOS (this_line_start_pos
) = 0;
13922 /* Let the overlay arrow be updated the next time. */
13923 update_overlay_arrows (0);
13925 /* If we pause after scrolling, some rows in the current
13926 matrices of some windows are not valid. */
13927 if (!WINDOW_FULL_WIDTH_P (w
)
13928 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13929 update_mode_lines
= 36;
13933 if (!consider_all_windows_p
)
13935 /* This has already been done above if
13936 consider_all_windows_p is set. */
13937 if (XBUFFER (w
->contents
)->text
->redisplay
13938 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
13939 /* This can happen if b->text->redisplay was set during
13941 propagate_buffer_redisplay ();
13942 mark_window_display_accurate_1 (w
, 1);
13944 /* Say overlay arrows are up to date. */
13945 update_overlay_arrows (1);
13947 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13948 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13951 update_mode_lines
= 0;
13952 windows_or_buffers_changed
= 0;
13955 /* Start SIGIO interrupts coming again. Having them off during the
13956 code above makes it less likely one will discard output, but not
13957 impossible, since there might be stuff in the system buffer here.
13958 But it is much hairier to try to do anything about that. */
13959 if (interrupt_input
)
13963 /* If a frame has become visible which was not before, redisplay
13964 again, so that we display it. Expose events for such a frame
13965 (which it gets when becoming visible) don't call the parts of
13966 redisplay constructing glyphs, so simply exposing a frame won't
13967 display anything in this case. So, we have to display these
13968 frames here explicitly. */
13973 FOR_EACH_FRAME (tail
, frame
)
13975 if (XFRAME (frame
)->visible
)
13979 if (new_count
!= number_of_visible_frames
)
13980 windows_or_buffers_changed
= 52;
13983 /* Change frame size now if a change is pending. */
13984 do_pending_window_change (true);
13986 /* If we just did a pending size change, or have additional
13987 visible frames, or selected_window changed, redisplay again. */
13988 if ((windows_or_buffers_changed
&& !pending
)
13989 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13992 /* Clear the face and image caches.
13994 We used to do this only if consider_all_windows_p. But the cache
13995 needs to be cleared if a timer creates images in the current
13996 buffer (e.g. the test case in Bug#6230). */
13998 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
14000 clear_face_cache (false);
14001 clear_face_cache_count
= 0;
14004 #ifdef HAVE_WINDOW_SYSTEM
14005 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
14007 clear_image_caches (Qnil
);
14008 clear_image_cache_count
= 0;
14010 #endif /* HAVE_WINDOW_SYSTEM */
14014 ns_set_doc_edited ();
14016 if (interrupt_input
&& interrupts_deferred
)
14019 unbind_to (count
, Qnil
);
14024 /* Redisplay, but leave alone any recent echo area message unless
14025 another message has been requested in its place.
14027 This is useful in situations where you need to redisplay but no
14028 user action has occurred, making it inappropriate for the message
14029 area to be cleared. See tracking_off and
14030 wait_reading_process_output for examples of these situations.
14032 FROM_WHERE is an integer saying from where this function was
14033 called. This is useful for debugging. */
14036 redisplay_preserve_echo_area (int from_where
)
14038 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
14040 if (!NILP (echo_area_buffer
[1]))
14042 /* We have a previously displayed message, but no current
14043 message. Redisplay the previous message. */
14044 display_last_displayed_message_p
= true;
14045 redisplay_internal ();
14046 display_last_displayed_message_p
= false;
14049 redisplay_internal ();
14051 flush_frame (SELECTED_FRAME ());
14055 /* Function registered with record_unwind_protect in redisplay_internal. */
14058 unwind_redisplay (void)
14060 redisplaying_p
= 0;
14064 /* Mark the display of leaf window W as accurate or inaccurate.
14065 If ACCURATE_P is non-zero mark display of W as accurate. If
14066 ACCURATE_P is zero, arrange for W to be redisplayed the next
14067 time redisplay_internal is called. */
14070 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
14072 struct buffer
*b
= XBUFFER (w
->contents
);
14074 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
14075 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
14076 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
14080 b
->clip_changed
= false;
14081 b
->prevent_redisplay_optimizations_p
= false;
14082 eassert (buffer_window_count (b
) > 0);
14083 /* Resetting b->text->redisplay is problematic!
14084 In order to make it safer to do it here, redisplay_internal must
14085 have copied all b->text->redisplay to their respective windows. */
14086 b
->text
->redisplay
= false;
14088 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
14089 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
14090 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
14091 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
14093 w
->current_matrix
->buffer
= b
;
14094 w
->current_matrix
->begv
= BUF_BEGV (b
);
14095 w
->current_matrix
->zv
= BUF_ZV (b
);
14097 w
->last_cursor_vpos
= w
->cursor
.vpos
;
14098 w
->last_cursor_off_p
= w
->cursor_off_p
;
14100 if (w
== XWINDOW (selected_window
))
14101 w
->last_point
= BUF_PT (b
);
14103 w
->last_point
= marker_position (w
->pointm
);
14105 w
->window_end_valid
= true;
14106 w
->update_mode_line
= false;
14109 w
->redisplay
= !accurate_p
;
14113 /* Mark the display of windows in the window tree rooted at WINDOW as
14114 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
14115 windows as accurate. If ACCURATE_P is zero, arrange for windows to
14116 be redisplayed the next time redisplay_internal is called. */
14119 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
14123 for (; !NILP (window
); window
= w
->next
)
14125 w
= XWINDOW (window
);
14126 if (WINDOWP (w
->contents
))
14127 mark_window_display_accurate (w
->contents
, accurate_p
);
14129 mark_window_display_accurate_1 (w
, accurate_p
);
14133 update_overlay_arrows (1);
14135 /* Force a thorough redisplay the next time by setting
14136 last_arrow_position and last_arrow_string to t, which is
14137 unequal to any useful value of Voverlay_arrow_... */
14138 update_overlay_arrows (-1);
14142 /* Return value in display table DP (Lisp_Char_Table *) for character
14143 C. Since a display table doesn't have any parent, we don't have to
14144 follow parent. Do not call this function directly but use the
14145 macro DISP_CHAR_VECTOR. */
14148 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
14152 if (ASCII_CHAR_P (c
))
14155 if (SUB_CHAR_TABLE_P (val
))
14156 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
14162 XSETCHAR_TABLE (table
, dp
);
14163 val
= char_table_ref (table
, c
);
14172 /***********************************************************************
14174 ***********************************************************************/
14176 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
14179 redisplay_windows (Lisp_Object window
)
14181 while (!NILP (window
))
14183 struct window
*w
= XWINDOW (window
);
14185 if (WINDOWP (w
->contents
))
14186 redisplay_windows (w
->contents
);
14187 else if (BUFFERP (w
->contents
))
14189 displayed_buffer
= XBUFFER (w
->contents
);
14190 /* Use list_of_error, not Qerror, so that
14191 we catch only errors and don't run the debugger. */
14192 internal_condition_case_1 (redisplay_window_0
, window
,
14194 redisplay_window_error
);
14202 redisplay_window_error (Lisp_Object ignore
)
14204 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14209 redisplay_window_0 (Lisp_Object window
)
14211 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14212 redisplay_window (window
, false);
14217 redisplay_window_1 (Lisp_Object window
)
14219 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14220 redisplay_window (window
, true);
14225 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14226 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14227 which positions recorded in ROW differ from current buffer
14230 Return 0 if cursor is not on this row, 1 otherwise. */
14233 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14234 struct glyph_matrix
*matrix
,
14235 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14238 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14239 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14240 struct glyph
*cursor
= NULL
;
14241 /* The last known character position in row. */
14242 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14244 ptrdiff_t pt_old
= PT
- delta
;
14245 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14246 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14247 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14248 /* A glyph beyond the edge of TEXT_AREA which we should never
14250 struct glyph
*glyphs_end
= end
;
14251 /* Non-zero means we've found a match for cursor position, but that
14252 glyph has the avoid_cursor_p flag set. */
14253 int match_with_avoid_cursor
= 0;
14254 /* Non-zero means we've seen at least one glyph that came from a
14256 int string_seen
= 0;
14257 /* Largest and smallest buffer positions seen so far during scan of
14259 ptrdiff_t bpos_max
= pos_before
;
14260 ptrdiff_t bpos_min
= pos_after
;
14261 /* Last buffer position covered by an overlay string with an integer
14262 `cursor' property. */
14263 ptrdiff_t bpos_covered
= 0;
14264 /* Non-zero means the display string on which to display the cursor
14265 comes from a text property, not from an overlay. */
14266 int string_from_text_prop
= 0;
14268 /* Don't even try doing anything if called for a mode-line or
14269 header-line row, since the rest of the code isn't prepared to
14270 deal with such calamities. */
14271 eassert (!row
->mode_line_p
);
14272 if (row
->mode_line_p
)
14275 /* Skip over glyphs not having an object at the start and the end of
14276 the row. These are special glyphs like truncation marks on
14277 terminal frames. */
14278 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14280 if (!row
->reversed_p
)
14283 && INTEGERP (glyph
->object
)
14284 && glyph
->charpos
< 0)
14286 x
+= glyph
->pixel_width
;
14290 && INTEGERP ((end
- 1)->object
)
14291 /* CHARPOS is zero for blanks and stretch glyphs
14292 inserted by extend_face_to_end_of_line. */
14293 && (end
- 1)->charpos
<= 0)
14295 glyph_before
= glyph
- 1;
14302 /* If the glyph row is reversed, we need to process it from back
14303 to front, so swap the edge pointers. */
14304 glyphs_end
= end
= glyph
- 1;
14305 glyph
+= row
->used
[TEXT_AREA
] - 1;
14307 while (glyph
> end
+ 1
14308 && INTEGERP (glyph
->object
)
14309 && glyph
->charpos
< 0)
14312 x
-= glyph
->pixel_width
;
14314 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14316 /* By default, in reversed rows we put the cursor on the
14317 rightmost (first in the reading order) glyph. */
14318 for (g
= end
+ 1; g
< glyph
; g
++)
14319 x
+= g
->pixel_width
;
14321 && INTEGERP ((end
+ 1)->object
)
14322 && (end
+ 1)->charpos
<= 0)
14324 glyph_before
= glyph
+ 1;
14328 else if (row
->reversed_p
)
14330 /* In R2L rows that don't display text, put the cursor on the
14331 rightmost glyph. Case in point: an empty last line that is
14332 part of an R2L paragraph. */
14334 /* Avoid placing the cursor on the last glyph of the row, where
14335 on terminal frames we hold the vertical border between
14336 adjacent windows. */
14337 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14338 && !WINDOW_RIGHTMOST_P (w
)
14339 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14341 x
= -1; /* will be computed below, at label compute_x */
14344 /* Step 1: Try to find the glyph whose character position
14345 corresponds to point. If that's not possible, find 2 glyphs
14346 whose character positions are the closest to point, one before
14347 point, the other after it. */
14348 if (!row
->reversed_p
)
14349 while (/* not marched to end of glyph row */
14351 /* glyph was not inserted by redisplay for internal purposes */
14352 && !INTEGERP (glyph
->object
))
14354 if (BUFFERP (glyph
->object
))
14356 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14358 if (glyph
->charpos
> bpos_max
)
14359 bpos_max
= glyph
->charpos
;
14360 if (glyph
->charpos
< bpos_min
)
14361 bpos_min
= glyph
->charpos
;
14362 if (!glyph
->avoid_cursor_p
)
14364 /* If we hit point, we've found the glyph on which to
14365 display the cursor. */
14368 match_with_avoid_cursor
= 0;
14371 /* See if we've found a better approximation to
14372 POS_BEFORE or to POS_AFTER. */
14373 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14375 pos_before
= glyph
->charpos
;
14376 glyph_before
= glyph
;
14378 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14380 pos_after
= glyph
->charpos
;
14381 glyph_after
= glyph
;
14384 else if (dpos
== 0)
14385 match_with_avoid_cursor
= 1;
14387 else if (STRINGP (glyph
->object
))
14389 Lisp_Object chprop
;
14390 ptrdiff_t glyph_pos
= glyph
->charpos
;
14392 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14394 if (!NILP (chprop
))
14396 /* If the string came from a `display' text property,
14397 look up the buffer position of that property and
14398 use that position to update bpos_max, as if we
14399 actually saw such a position in one of the row's
14400 glyphs. This helps with supporting integer values
14401 of `cursor' property on the display string in
14402 situations where most or all of the row's buffer
14403 text is completely covered by display properties,
14404 so that no glyph with valid buffer positions is
14405 ever seen in the row. */
14406 ptrdiff_t prop_pos
=
14407 string_buffer_position_lim (glyph
->object
, pos_before
,
14410 if (prop_pos
>= pos_before
)
14411 bpos_max
= prop_pos
;
14413 if (INTEGERP (chprop
))
14415 bpos_covered
= bpos_max
+ XINT (chprop
);
14416 /* If the `cursor' property covers buffer positions up
14417 to and including point, we should display cursor on
14418 this glyph. Note that, if a `cursor' property on one
14419 of the string's characters has an integer value, we
14420 will break out of the loop below _before_ we get to
14421 the position match above. IOW, integer values of
14422 the `cursor' property override the "exact match for
14423 point" strategy of positioning the cursor. */
14424 /* Implementation note: bpos_max == pt_old when, e.g.,
14425 we are in an empty line, where bpos_max is set to
14426 MATRIX_ROW_START_CHARPOS, see above. */
14427 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14436 x
+= glyph
->pixel_width
;
14439 else if (glyph
> end
) /* row is reversed */
14440 while (!INTEGERP (glyph
->object
))
14442 if (BUFFERP (glyph
->object
))
14444 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14446 if (glyph
->charpos
> bpos_max
)
14447 bpos_max
= glyph
->charpos
;
14448 if (glyph
->charpos
< bpos_min
)
14449 bpos_min
= glyph
->charpos
;
14450 if (!glyph
->avoid_cursor_p
)
14454 match_with_avoid_cursor
= 0;
14457 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14459 pos_before
= glyph
->charpos
;
14460 glyph_before
= glyph
;
14462 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14464 pos_after
= glyph
->charpos
;
14465 glyph_after
= glyph
;
14468 else if (dpos
== 0)
14469 match_with_avoid_cursor
= 1;
14471 else if (STRINGP (glyph
->object
))
14473 Lisp_Object chprop
;
14474 ptrdiff_t glyph_pos
= glyph
->charpos
;
14476 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14478 if (!NILP (chprop
))
14480 ptrdiff_t prop_pos
=
14481 string_buffer_position_lim (glyph
->object
, pos_before
,
14484 if (prop_pos
>= pos_before
)
14485 bpos_max
= prop_pos
;
14487 if (INTEGERP (chprop
))
14489 bpos_covered
= bpos_max
+ XINT (chprop
);
14490 /* If the `cursor' property covers buffer positions up
14491 to and including point, we should display cursor on
14493 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14502 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14504 x
--; /* can't use any pixel_width */
14507 x
-= glyph
->pixel_width
;
14510 /* Step 2: If we didn't find an exact match for point, we need to
14511 look for a proper place to put the cursor among glyphs between
14512 GLYPH_BEFORE and GLYPH_AFTER. */
14513 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14514 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14515 && !(bpos_max
<= pt_old
&& pt_old
<= bpos_covered
))
14517 /* An empty line has a single glyph whose OBJECT is zero and
14518 whose CHARPOS is the position of a newline on that line.
14519 Note that on a TTY, there are more glyphs after that, which
14520 were produced by extend_face_to_end_of_line, but their
14521 CHARPOS is zero or negative. */
14523 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14524 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14525 /* On a TTY, continued and truncated rows also have a glyph at
14526 their end whose OBJECT is zero and whose CHARPOS is
14527 positive (the continuation and truncation glyphs), but such
14528 rows are obviously not "empty". */
14529 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14531 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14533 ptrdiff_t ellipsis_pos
;
14535 /* Scan back over the ellipsis glyphs. */
14536 if (!row
->reversed_p
)
14538 ellipsis_pos
= (glyph
- 1)->charpos
;
14539 while (glyph
> row
->glyphs
[TEXT_AREA
]
14540 && (glyph
- 1)->charpos
== ellipsis_pos
)
14541 glyph
--, x
-= glyph
->pixel_width
;
14542 /* That loop always goes one position too far, including
14543 the glyph before the ellipsis. So scan forward over
14545 x
+= glyph
->pixel_width
;
14548 else /* row is reversed */
14550 ellipsis_pos
= (glyph
+ 1)->charpos
;
14551 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14552 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14553 glyph
++, x
+= glyph
->pixel_width
;
14554 x
-= glyph
->pixel_width
;
14558 else if (match_with_avoid_cursor
)
14560 cursor
= glyph_after
;
14563 else if (string_seen
)
14565 int incr
= row
->reversed_p
? -1 : +1;
14567 /* Need to find the glyph that came out of a string which is
14568 present at point. That glyph is somewhere between
14569 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14570 positioned between POS_BEFORE and POS_AFTER in the
14572 struct glyph
*start
, *stop
;
14573 ptrdiff_t pos
= pos_before
;
14577 /* If the row ends in a newline from a display string,
14578 reordering could have moved the glyphs belonging to the
14579 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14580 in this case we extend the search to the last glyph in
14581 the row that was not inserted by redisplay. */
14582 if (row
->ends_in_newline_from_string_p
)
14585 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14588 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14589 correspond to POS_BEFORE and POS_AFTER, respectively. We
14590 need START and STOP in the order that corresponds to the
14591 row's direction as given by its reversed_p flag. If the
14592 directionality of characters between POS_BEFORE and
14593 POS_AFTER is the opposite of the row's base direction,
14594 these characters will have been reordered for display,
14595 and we need to reverse START and STOP. */
14596 if (!row
->reversed_p
)
14598 start
= min (glyph_before
, glyph_after
);
14599 stop
= max (glyph_before
, glyph_after
);
14603 start
= max (glyph_before
, glyph_after
);
14604 stop
= min (glyph_before
, glyph_after
);
14606 for (glyph
= start
+ incr
;
14607 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14610 /* Any glyphs that come from the buffer are here because
14611 of bidi reordering. Skip them, and only pay
14612 attention to glyphs that came from some string. */
14613 if (STRINGP (glyph
->object
))
14617 /* If the display property covers the newline, we
14618 need to search for it one position farther. */
14619 ptrdiff_t lim
= pos_after
14620 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14622 string_from_text_prop
= 0;
14623 str
= glyph
->object
;
14624 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14625 if (tem
== 0 /* from overlay */
14628 /* If the string from which this glyph came is
14629 found in the buffer at point, or at position
14630 that is closer to point than pos_after, then
14631 we've found the glyph we've been looking for.
14632 If it comes from an overlay (tem == 0), and
14633 it has the `cursor' property on one of its
14634 glyphs, record that glyph as a candidate for
14635 displaying the cursor. (As in the
14636 unidirectional version, we will display the
14637 cursor on the last candidate we find.) */
14640 || (tem
- pt_old
> 0 && tem
< pos_after
))
14642 /* The glyphs from this string could have
14643 been reordered. Find the one with the
14644 smallest string position. Or there could
14645 be a character in the string with the
14646 `cursor' property, which means display
14647 cursor on that character's glyph. */
14648 ptrdiff_t strpos
= glyph
->charpos
;
14653 string_from_text_prop
= 1;
14656 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14657 && EQ (glyph
->object
, str
);
14661 ptrdiff_t gpos
= glyph
->charpos
;
14663 cprop
= Fget_char_property (make_number (gpos
),
14671 if (tem
&& glyph
->charpos
< strpos
)
14673 strpos
= glyph
->charpos
;
14679 || (tem
- pt_old
> 0 && tem
< pos_after
))
14683 pos
= tem
+ 1; /* don't find previous instances */
14685 /* This string is not what we want; skip all of the
14686 glyphs that came from it. */
14687 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14688 && EQ (glyph
->object
, str
))
14695 /* If we reached the end of the line, and END was from a string,
14696 the cursor is not on this line. */
14698 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14699 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14700 && STRINGP (end
->object
)
14701 && row
->continued_p
)
14704 /* A truncated row may not include PT among its character positions.
14705 Setting the cursor inside the scroll margin will trigger
14706 recalculation of hscroll in hscroll_window_tree. But if a
14707 display string covers point, defer to the string-handling
14708 code below to figure this out. */
14709 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14711 cursor
= glyph_before
;
14714 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14715 /* Zero-width characters produce no glyphs. */
14717 && (row
->reversed_p
14718 ? glyph_after
> glyphs_end
14719 : glyph_after
< glyphs_end
)))
14721 cursor
= glyph_after
;
14727 if (cursor
!= NULL
)
14729 else if (glyph
== glyphs_end
14730 && pos_before
== pos_after
14731 && STRINGP ((row
->reversed_p
14732 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14733 : row
->glyphs
[TEXT_AREA
])->object
))
14735 /* If all the glyphs of this row came from strings, put the
14736 cursor on the first glyph of the row. This avoids having the
14737 cursor outside of the text area in this very rare and hard
14741 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14742 : row
->glyphs
[TEXT_AREA
];
14748 /* Need to compute x that corresponds to GLYPH. */
14749 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14751 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14753 x
+= g
->pixel_width
;
14757 /* ROW could be part of a continued line, which, under bidi
14758 reordering, might have other rows whose start and end charpos
14759 occlude point. Only set w->cursor if we found a better
14760 approximation to the cursor position than we have from previously
14761 examined candidate rows belonging to the same continued line. */
14762 if (/* We already have a candidate row. */
14763 w
->cursor
.vpos
>= 0
14764 /* That candidate is not the row we are processing. */
14765 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14766 /* Make sure cursor.vpos specifies a row whose start and end
14767 charpos occlude point, and it is valid candidate for being a
14768 cursor-row. This is because some callers of this function
14769 leave cursor.vpos at the row where the cursor was displayed
14770 during the last redisplay cycle. */
14771 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14772 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14773 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14776 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14778 /* Don't consider glyphs that are outside TEXT_AREA. */
14779 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14781 /* Keep the candidate whose buffer position is the closest to
14782 point or has the `cursor' property. */
14783 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14784 w
->cursor
.hpos
>= 0
14785 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14786 && ((BUFFERP (g1
->object
)
14787 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14788 || (BUFFERP (glyph
->object
)
14789 && eabs (g1
->charpos
- pt_old
)
14790 < eabs (glyph
->charpos
- pt_old
))))
14791 /* Previous candidate is a glyph from a string that has
14792 a non-nil `cursor' property. */
14793 || (STRINGP (g1
->object
)
14794 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14795 Qcursor
, g1
->object
))
14796 /* Previous candidate is from the same display
14797 string as this one, and the display string
14798 came from a text property. */
14799 || (EQ (g1
->object
, glyph
->object
)
14800 && string_from_text_prop
)
14801 /* this candidate is from newline and its
14802 position is not an exact match */
14803 || (INTEGERP (glyph
->object
)
14804 && glyph
->charpos
!= pt_old
)))))
14806 /* If this candidate gives an exact match, use that. */
14807 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14808 /* If this candidate is a glyph created for the
14809 terminating newline of a line, and point is on that
14810 newline, it wins because it's an exact match. */
14811 || (!row
->continued_p
14812 && INTEGERP (glyph
->object
)
14813 && glyph
->charpos
== 0
14814 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14815 /* Otherwise, keep the candidate that comes from a row
14816 spanning less buffer positions. This may win when one or
14817 both candidate positions are on glyphs that came from
14818 display strings, for which we cannot compare buffer
14820 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14821 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14822 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14825 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14827 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14828 w
->cursor
.y
= row
->y
+ dy
;
14830 if (w
== XWINDOW (selected_window
))
14832 if (!row
->continued_p
14833 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14836 this_line_buffer
= XBUFFER (w
->contents
);
14838 CHARPOS (this_line_start_pos
)
14839 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14840 BYTEPOS (this_line_start_pos
)
14841 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14843 CHARPOS (this_line_end_pos
)
14844 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14845 BYTEPOS (this_line_end_pos
)
14846 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14848 this_line_y
= w
->cursor
.y
;
14849 this_line_pixel_height
= row
->height
;
14850 this_line_vpos
= w
->cursor
.vpos
;
14851 this_line_start_x
= row
->x
;
14854 CHARPOS (this_line_start_pos
) = 0;
14861 /* Run window scroll functions, if any, for WINDOW with new window
14862 start STARTP. Sets the window start of WINDOW to that position.
14864 We assume that the window's buffer is really current. */
14866 static struct text_pos
14867 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14869 struct window
*w
= XWINDOW (window
);
14870 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14872 eassert (current_buffer
== XBUFFER (w
->contents
));
14874 if (!NILP (Vwindow_scroll_functions
))
14876 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14877 make_number (CHARPOS (startp
)));
14878 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14879 /* In case the hook functions switch buffers. */
14880 set_buffer_internal (XBUFFER (w
->contents
));
14887 /* Make sure the line containing the cursor is fully visible.
14888 A value of 1 means there is nothing to be done.
14889 (Either the line is fully visible, or it cannot be made so,
14890 or we cannot tell.)
14892 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14893 is higher than window.
14895 If CURRENT_MATRIX_P is non-zero, use the information from the
14896 window's current glyph matrix; otherwise use the desired glyph
14899 A value of 0 means the caller should do scrolling
14900 as if point had gone off the screen. */
14903 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14905 struct glyph_matrix
*matrix
;
14906 struct glyph_row
*row
;
14909 if (!make_cursor_line_fully_visible_p
)
14912 /* It's not always possible to find the cursor, e.g, when a window
14913 is full of overlay strings. Don't do anything in that case. */
14914 if (w
->cursor
.vpos
< 0)
14917 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14918 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14920 /* If the cursor row is not partially visible, there's nothing to do. */
14921 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14924 /* If the row the cursor is in is taller than the window's height,
14925 it's not clear what to do, so do nothing. */
14926 window_height
= window_box_height (w
);
14927 if (row
->height
>= window_height
)
14929 if (!force_p
|| MINI_WINDOW_P (w
)
14930 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14937 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14938 non-zero means only WINDOW is redisplayed in redisplay_internal.
14939 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14940 in redisplay_window to bring a partially visible line into view in
14941 the case that only the cursor has moved.
14943 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14944 last screen line's vertical height extends past the end of the screen.
14948 1 if scrolling succeeded
14950 0 if scrolling didn't find point.
14952 -1 if new fonts have been loaded so that we must interrupt
14953 redisplay, adjust glyph matrices, and try again. */
14959 SCROLLING_NEED_LARGER_MATRICES
14962 /* If scroll-conservatively is more than this, never recenter.
14964 If you change this, don't forget to update the doc string of
14965 `scroll-conservatively' and the Emacs manual. */
14966 #define SCROLL_LIMIT 100
14969 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14970 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14971 int temp_scroll_step
, int last_line_misfit
)
14973 struct window
*w
= XWINDOW (window
);
14974 struct frame
*f
= XFRAME (w
->frame
);
14975 struct text_pos pos
, startp
;
14977 int this_scroll_margin
, scroll_max
, rc
, height
;
14978 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14979 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14980 Lisp_Object aggressive
;
14981 /* We will never try scrolling more than this number of lines. */
14982 int scroll_limit
= SCROLL_LIMIT
;
14983 int frame_line_height
= default_line_pixel_height (w
);
14984 int window_total_lines
14985 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14988 debug_method_add (w
, "try_scrolling");
14991 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14993 /* Compute scroll margin height in pixels. We scroll when point is
14994 within this distance from the top or bottom of the window. */
14995 if (scroll_margin
> 0)
14996 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14997 * frame_line_height
;
14999 this_scroll_margin
= 0;
15001 /* Force arg_scroll_conservatively to have a reasonable value, to
15002 avoid scrolling too far away with slow move_it_* functions. Note
15003 that the user can supply scroll-conservatively equal to
15004 `most-positive-fixnum', which can be larger than INT_MAX. */
15005 if (arg_scroll_conservatively
> scroll_limit
)
15007 arg_scroll_conservatively
= scroll_limit
+ 1;
15008 scroll_max
= scroll_limit
* frame_line_height
;
15010 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
15011 /* Compute how much we should try to scroll maximally to bring
15012 point into view. */
15013 scroll_max
= (max (scroll_step
,
15014 max (arg_scroll_conservatively
, temp_scroll_step
))
15015 * frame_line_height
);
15016 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
15017 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
15018 /* We're trying to scroll because of aggressive scrolling but no
15019 scroll_step is set. Choose an arbitrary one. */
15020 scroll_max
= 10 * frame_line_height
;
15026 /* Decide whether to scroll down. */
15027 if (PT
> CHARPOS (startp
))
15029 int scroll_margin_y
;
15031 /* Compute the pixel ypos of the scroll margin, then move IT to
15032 either that ypos or PT, whichever comes first. */
15033 start_display (&it
, w
, startp
);
15034 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
15035 - frame_line_height
* extra_scroll_margin_lines
;
15036 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
15037 (MOVE_TO_POS
| MOVE_TO_Y
));
15039 if (PT
> CHARPOS (it
.current
.pos
))
15041 int y0
= line_bottom_y (&it
);
15042 /* Compute how many pixels below window bottom to stop searching
15043 for PT. This avoids costly search for PT that is far away if
15044 the user limited scrolling by a small number of lines, but
15045 always finds PT if scroll_conservatively is set to a large
15046 number, such as most-positive-fixnum. */
15047 int slack
= max (scroll_max
, 10 * frame_line_height
);
15048 int y_to_move
= it
.last_visible_y
+ slack
;
15050 /* Compute the distance from the scroll margin to PT or to
15051 the scroll limit, whichever comes first. This should
15052 include the height of the cursor line, to make that line
15054 move_it_to (&it
, PT
, -1, y_to_move
,
15055 -1, MOVE_TO_POS
| MOVE_TO_Y
);
15056 dy
= line_bottom_y (&it
) - y0
;
15058 if (dy
> scroll_max
)
15059 return SCROLLING_FAILED
;
15068 /* Point is in or below the bottom scroll margin, so move the
15069 window start down. If scrolling conservatively, move it just
15070 enough down to make point visible. If scroll_step is set,
15071 move it down by scroll_step. */
15072 if (arg_scroll_conservatively
)
15074 = min (max (dy
, frame_line_height
),
15075 frame_line_height
* arg_scroll_conservatively
);
15076 else if (scroll_step
|| temp_scroll_step
)
15077 amount_to_scroll
= scroll_max
;
15080 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
15081 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15082 if (NUMBERP (aggressive
))
15084 double float_amount
= XFLOATINT (aggressive
) * height
;
15085 int aggressive_scroll
= float_amount
;
15086 if (aggressive_scroll
== 0 && float_amount
> 0)
15087 aggressive_scroll
= 1;
15088 /* Don't let point enter the scroll margin near top of
15089 the window. This could happen if the value of
15090 scroll_up_aggressively is too large and there are
15091 non-zero margins, because scroll_up_aggressively
15092 means put point that fraction of window height
15093 _from_the_bottom_margin_. */
15094 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15095 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15096 amount_to_scroll
= dy
+ aggressive_scroll
;
15100 if (amount_to_scroll
<= 0)
15101 return SCROLLING_FAILED
;
15103 start_display (&it
, w
, startp
);
15104 if (arg_scroll_conservatively
<= scroll_limit
)
15105 move_it_vertically (&it
, amount_to_scroll
);
15108 /* Extra precision for users who set scroll-conservatively
15109 to a large number: make sure the amount we scroll
15110 the window start is never less than amount_to_scroll,
15111 which was computed as distance from window bottom to
15112 point. This matters when lines at window top and lines
15113 below window bottom have different height. */
15115 void *it1data
= NULL
;
15116 /* We use a temporary it1 because line_bottom_y can modify
15117 its argument, if it moves one line down; see there. */
15120 SAVE_IT (it1
, it
, it1data
);
15121 start_y
= line_bottom_y (&it1
);
15123 RESTORE_IT (&it
, &it
, it1data
);
15124 move_it_by_lines (&it
, 1);
15125 SAVE_IT (it1
, it
, it1data
);
15126 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
15129 /* If STARTP is unchanged, move it down another screen line. */
15130 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
15131 move_it_by_lines (&it
, 1);
15132 startp
= it
.current
.pos
;
15136 struct text_pos scroll_margin_pos
= startp
;
15139 /* See if point is inside the scroll margin at the top of the
15141 if (this_scroll_margin
)
15145 start_display (&it
, w
, startp
);
15146 y_start
= it
.current_y
;
15147 move_it_vertically (&it
, this_scroll_margin
);
15148 scroll_margin_pos
= it
.current
.pos
;
15149 /* If we didn't move enough before hitting ZV, request
15150 additional amount of scroll, to move point out of the
15152 if (IT_CHARPOS (it
) == ZV
15153 && it
.current_y
- y_start
< this_scroll_margin
)
15154 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
15157 if (PT
< CHARPOS (scroll_margin_pos
))
15159 /* Point is in the scroll margin at the top of the window or
15160 above what is displayed in the window. */
15163 /* Compute the vertical distance from PT to the scroll
15164 margin position. Move as far as scroll_max allows, or
15165 one screenful, or 10 screen lines, whichever is largest.
15166 Give up if distance is greater than scroll_max or if we
15167 didn't reach the scroll margin position. */
15168 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
15169 start_display (&it
, w
, pos
);
15171 y_to_move
= max (it
.last_visible_y
,
15172 max (scroll_max
, 10 * frame_line_height
));
15173 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
15175 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15176 dy
= it
.current_y
- y0
;
15177 if (dy
> scroll_max
15178 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
15179 return SCROLLING_FAILED
;
15181 /* Additional scroll for when ZV was too close to point. */
15184 /* Compute new window start. */
15185 start_display (&it
, w
, startp
);
15187 if (arg_scroll_conservatively
)
15188 amount_to_scroll
= max (dy
, frame_line_height
15189 * max (scroll_step
, temp_scroll_step
));
15190 else if (scroll_step
|| temp_scroll_step
)
15191 amount_to_scroll
= scroll_max
;
15194 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15195 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15196 if (NUMBERP (aggressive
))
15198 double float_amount
= XFLOATINT (aggressive
) * height
;
15199 int aggressive_scroll
= float_amount
;
15200 if (aggressive_scroll
== 0 && float_amount
> 0)
15201 aggressive_scroll
= 1;
15202 /* Don't let point enter the scroll margin near
15203 bottom of the window, if the value of
15204 scroll_down_aggressively happens to be too
15206 if (aggressive_scroll
+ 2 * this_scroll_margin
> height
)
15207 aggressive_scroll
= height
- 2 * this_scroll_margin
;
15208 amount_to_scroll
= dy
+ aggressive_scroll
;
15212 if (amount_to_scroll
<= 0)
15213 return SCROLLING_FAILED
;
15215 move_it_vertically_backward (&it
, amount_to_scroll
);
15216 startp
= it
.current
.pos
;
15220 /* Run window scroll functions. */
15221 startp
= run_window_scroll_functions (window
, startp
);
15223 /* Display the window. Give up if new fonts are loaded, or if point
15225 if (!try_window (window
, startp
, 0))
15226 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15227 else if (w
->cursor
.vpos
< 0)
15229 clear_glyph_matrix (w
->desired_matrix
);
15230 rc
= SCROLLING_FAILED
;
15234 /* Maybe forget recorded base line for line number display. */
15235 if (!just_this_one_p
15236 || current_buffer
->clip_changed
15237 || BEG_UNCHANGED
< CHARPOS (startp
))
15238 w
->base_line_number
= 0;
15240 /* If cursor ends up on a partially visible line,
15241 treat that as being off the bottom of the screen. */
15242 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
15243 /* It's possible that the cursor is on the first line of the
15244 buffer, which is partially obscured due to a vscroll
15245 (Bug#7537). In that case, avoid looping forever. */
15246 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15248 clear_glyph_matrix (w
->desired_matrix
);
15249 ++extra_scroll_margin_lines
;
15252 rc
= SCROLLING_SUCCESS
;
15259 /* Compute a suitable window start for window W if display of W starts
15260 on a continuation line. Value is non-zero if a new window start
15263 The new window start will be computed, based on W's width, starting
15264 from the start of the continued line. It is the start of the
15265 screen line with the minimum distance from the old start W->start. */
15268 compute_window_start_on_continuation_line (struct window
*w
)
15270 struct text_pos pos
, start_pos
;
15271 int window_start_changed_p
= 0;
15273 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15275 /* If window start is on a continuation line... Window start may be
15276 < BEGV in case there's invisible text at the start of the
15277 buffer (M-x rmail, for example). */
15278 if (CHARPOS (start_pos
) > BEGV
15279 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15282 struct glyph_row
*row
;
15284 /* Handle the case that the window start is out of range. */
15285 if (CHARPOS (start_pos
) < BEGV
)
15286 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15287 else if (CHARPOS (start_pos
) > ZV
)
15288 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15290 /* Find the start of the continued line. This should be fast
15291 because find_newline is fast (newline cache). */
15292 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
15293 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15294 row
, DEFAULT_FACE_ID
);
15295 reseat_at_previous_visible_line_start (&it
);
15297 /* If the line start is "too far" away from the window start,
15298 say it takes too much time to compute a new window start. */
15299 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15300 /* PXW: Do we need upper bounds here? */
15301 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15303 int min_distance
, distance
;
15305 /* Move forward by display lines to find the new window
15306 start. If window width was enlarged, the new start can
15307 be expected to be > the old start. If window width was
15308 decreased, the new window start will be < the old start.
15309 So, we're looking for the display line start with the
15310 minimum distance from the old window start. */
15311 pos
= it
.current
.pos
;
15312 min_distance
= INFINITY
;
15313 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15314 distance
< min_distance
)
15316 min_distance
= distance
;
15317 pos
= it
.current
.pos
;
15318 if (it
.line_wrap
== WORD_WRAP
)
15320 /* Under WORD_WRAP, move_it_by_lines is likely to
15321 overshoot and stop not at the first, but the
15322 second character from the left margin. So in
15323 that case, we need a more tight control on the X
15324 coordinate of the iterator than move_it_by_lines
15325 promises in its contract. The method is to first
15326 go to the last (rightmost) visible character of a
15327 line, then move to the leftmost character on the
15328 next line in a separate call. */
15329 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15330 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15331 move_it_to (&it
, ZV
, 0,
15332 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15333 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15336 move_it_by_lines (&it
, 1);
15339 /* Set the window start there. */
15340 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15341 window_start_changed_p
= 1;
15345 return window_start_changed_p
;
15349 /* Try cursor movement in case text has not changed in window WINDOW,
15350 with window start STARTP. Value is
15352 CURSOR_MOVEMENT_SUCCESS if successful
15354 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15356 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15357 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15358 we want to scroll as if scroll-step were set to 1. See the code.
15360 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15361 which case we have to abort this redisplay, and adjust matrices
15366 CURSOR_MOVEMENT_SUCCESS
,
15367 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15368 CURSOR_MOVEMENT_MUST_SCROLL
,
15369 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15373 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15375 struct window
*w
= XWINDOW (window
);
15376 struct frame
*f
= XFRAME (w
->frame
);
15377 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15380 if (inhibit_try_cursor_movement
)
15384 /* Previously, there was a check for Lisp integer in the
15385 if-statement below. Now, this field is converted to
15386 ptrdiff_t, thus zero means invalid position in a buffer. */
15387 eassert (w
->last_point
> 0);
15388 /* Likewise there was a check whether window_end_vpos is nil or larger
15389 than the window. Now window_end_vpos is int and so never nil, but
15390 let's leave eassert to check whether it fits in the window. */
15391 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15393 /* Handle case where text has not changed, only point, and it has
15394 not moved off the frame. */
15395 if (/* Point may be in this window. */
15396 PT
>= CHARPOS (startp
)
15397 /* Selective display hasn't changed. */
15398 && !current_buffer
->clip_changed
15399 /* Function force-mode-line-update is used to force a thorough
15400 redisplay. It sets either windows_or_buffers_changed or
15401 update_mode_lines. So don't take a shortcut here for these
15403 && !update_mode_lines
15404 && !windows_or_buffers_changed
15405 && !f
->cursor_type_changed
15406 && NILP (Vshow_trailing_whitespace
)
15407 /* This code is not used for mini-buffer for the sake of the case
15408 of redisplaying to replace an echo area message; since in
15409 that case the mini-buffer contents per se are usually
15410 unchanged. This code is of no real use in the mini-buffer
15411 since the handling of this_line_start_pos, etc., in redisplay
15412 handles the same cases. */
15413 && !EQ (window
, minibuf_window
)
15414 && (FRAME_WINDOW_P (f
)
15415 || !overlay_arrow_in_current_buffer_p ()))
15417 int this_scroll_margin
, top_scroll_margin
;
15418 struct glyph_row
*row
= NULL
;
15419 int frame_line_height
= default_line_pixel_height (w
);
15420 int window_total_lines
15421 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15424 debug_method_add (w
, "cursor movement");
15427 /* Scroll if point within this distance from the top or bottom
15428 of the window. This is a pixel value. */
15429 if (scroll_margin
> 0)
15431 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15432 this_scroll_margin
*= frame_line_height
;
15435 this_scroll_margin
= 0;
15437 top_scroll_margin
= this_scroll_margin
;
15438 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15439 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15441 /* Start with the row the cursor was displayed during the last
15442 not paused redisplay. Give up if that row is not valid. */
15443 if (w
->last_cursor_vpos
< 0
15444 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15445 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15448 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15449 if (row
->mode_line_p
)
15451 if (!row
->enabled_p
)
15452 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15455 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15457 int scroll_p
= 0, must_scroll
= 0;
15458 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15460 if (PT
> w
->last_point
)
15462 /* Point has moved forward. */
15463 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15464 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15466 eassert (row
->enabled_p
);
15470 /* If the end position of a row equals the start
15471 position of the next row, and PT is at that position,
15472 we would rather display cursor in the next line. */
15473 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15474 && MATRIX_ROW_END_CHARPOS (row
) == PT
15475 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15476 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15477 && !cursor_row_p (row
))
15480 /* If within the scroll margin, scroll. Note that
15481 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15482 the next line would be drawn, and that
15483 this_scroll_margin can be zero. */
15484 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15485 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15486 /* Line is completely visible last line in window
15487 and PT is to be set in the next line. */
15488 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15489 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15490 && !row
->ends_at_zv_p
15491 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15494 else if (PT
< w
->last_point
)
15496 /* Cursor has to be moved backward. Note that PT >=
15497 CHARPOS (startp) because of the outer if-statement. */
15498 while (!row
->mode_line_p
15499 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15500 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15501 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15502 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15503 row
> w
->current_matrix
->rows
15504 && (row
-1)->ends_in_newline_from_string_p
))))
15505 && (row
->y
> top_scroll_margin
15506 || CHARPOS (startp
) == BEGV
))
15508 eassert (row
->enabled_p
);
15512 /* Consider the following case: Window starts at BEGV,
15513 there is invisible, intangible text at BEGV, so that
15514 display starts at some point START > BEGV. It can
15515 happen that we are called with PT somewhere between
15516 BEGV and START. Try to handle that case. */
15517 if (row
< w
->current_matrix
->rows
15518 || row
->mode_line_p
)
15520 row
= w
->current_matrix
->rows
;
15521 if (row
->mode_line_p
)
15525 /* Due to newlines in overlay strings, we may have to
15526 skip forward over overlay strings. */
15527 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15528 && MATRIX_ROW_END_CHARPOS (row
) == PT
15529 && !cursor_row_p (row
))
15532 /* If within the scroll margin, scroll. */
15533 if (row
->y
< top_scroll_margin
15534 && CHARPOS (startp
) != BEGV
)
15539 /* Cursor did not move. So don't scroll even if cursor line
15540 is partially visible, as it was so before. */
15541 rc
= CURSOR_MOVEMENT_SUCCESS
;
15544 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15545 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15547 /* if PT is not in the glyph row, give up. */
15548 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15551 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15552 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15554 struct glyph_row
*row1
;
15556 /* If rows are bidi-reordered and point moved, back up
15557 until we find a row that does not belong to a
15558 continuation line. This is because we must consider
15559 all rows of a continued line as candidates for the
15560 new cursor positioning, since row start and end
15561 positions change non-linearly with vertical position
15563 /* FIXME: Revisit this when glyph ``spilling'' in
15564 continuation lines' rows is implemented for
15565 bidi-reordered rows. */
15566 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15567 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15570 /* If we hit the beginning of the displayed portion
15571 without finding the first row of a continued
15575 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15578 eassert (row
->enabled_p
);
15583 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15584 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15585 /* Make sure this isn't a header line by any chance, since
15586 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15587 && !row
->mode_line_p
15588 && make_cursor_line_fully_visible_p
)
15590 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15591 && !row
->ends_at_zv_p
15592 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15593 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15594 else if (row
->height
> window_box_height (w
))
15596 /* If we end up in a partially visible line, let's
15597 make it fully visible, except when it's taller
15598 than the window, in which case we can't do much
15601 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15605 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15606 if (!cursor_row_fully_visible_p (w
, 0, 1))
15607 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15609 rc
= CURSOR_MOVEMENT_SUCCESS
;
15613 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15614 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15615 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15617 /* With bidi-reordered rows, there could be more than
15618 one candidate row whose start and end positions
15619 occlude point. We need to let set_cursor_from_row
15620 find the best candidate. */
15621 /* FIXME: Revisit this when glyph ``spilling'' in
15622 continuation lines' rows is implemented for
15623 bidi-reordered rows. */
15628 int at_zv_p
= 0, exact_match_p
= 0;
15630 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15631 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15632 && cursor_row_p (row
))
15633 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15635 /* As soon as we've found the exact match for point,
15636 or the first suitable row whose ends_at_zv_p flag
15637 is set, we are done. */
15640 at_zv_p
= MATRIX_ROW (w
->current_matrix
,
15641 w
->cursor
.vpos
)->ends_at_zv_p
;
15643 && w
->cursor
.hpos
>= 0
15644 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15647 struct glyph_row
*candidate
=
15648 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15650 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15651 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15654 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15655 || (INTEGERP (g
->object
)
15656 && (g
->charpos
== PT
15657 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15659 if (at_zv_p
|| exact_match_p
)
15661 rc
= CURSOR_MOVEMENT_SUCCESS
;
15665 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15669 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15670 || row
->continued_p
)
15671 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15672 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15673 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15674 /* If we didn't find any candidate rows, or exited the
15675 loop before all the candidates were examined, signal
15676 to the caller that this method failed. */
15677 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15679 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15680 && !row
->continued_p
))
15681 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15683 rc
= CURSOR_MOVEMENT_SUCCESS
;
15689 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15691 rc
= CURSOR_MOVEMENT_SUCCESS
;
15696 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15697 && MATRIX_ROW_START_CHARPOS (row
) == PT
15698 && cursor_row_p (row
));
15708 set_vertical_scroll_bar (struct window
*w
)
15710 ptrdiff_t start
, end
, whole
;
15712 /* Calculate the start and end positions for the current window.
15713 At some point, it would be nice to choose between scrollbars
15714 which reflect the whole buffer size, with special markers
15715 indicating narrowing, and scrollbars which reflect only the
15718 Note that mini-buffers sometimes aren't displaying any text. */
15719 if (!MINI_WINDOW_P (w
)
15720 || (w
== XWINDOW (minibuf_window
)
15721 && NILP (echo_area_buffer
[0])))
15723 struct buffer
*buf
= XBUFFER (w
->contents
);
15724 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15725 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15726 /* I don't think this is guaranteed to be right. For the
15727 moment, we'll pretend it is. */
15728 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15732 if (whole
< (end
- start
))
15733 whole
= end
- start
;
15736 start
= end
= whole
= 0;
15738 /* Indicate what this scroll bar ought to be displaying now. */
15739 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15740 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15741 (w
, end
- start
, whole
, start
);
15746 set_horizontal_scroll_bar (struct window
*w
)
15748 int start
, end
, whole
, portion
;
15750 if (!MINI_WINDOW_P (w
)
15751 || (w
== XWINDOW (minibuf_window
)
15752 && NILP (echo_area_buffer
[0])))
15754 struct buffer
*b
= XBUFFER (w
->contents
);
15755 struct buffer
*old_buffer
= NULL
;
15757 struct text_pos startp
;
15759 if (b
!= current_buffer
)
15761 old_buffer
= current_buffer
;
15762 set_buffer_internal (b
);
15765 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15766 start_display (&it
, w
, startp
);
15767 it
.last_visible_x
= INT_MAX
;
15768 whole
= move_it_to (&it
, -1, INT_MAX
, window_box_height (w
), -1,
15769 MOVE_TO_X
| MOVE_TO_Y
);
15770 /* whole = move_it_to (&it, w->window_end_pos, INT_MAX,
15771 window_box_height (w), -1,
15772 MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); */
15774 start
= w
->hscroll
* FRAME_COLUMN_WIDTH (WINDOW_XFRAME (w
));
15775 end
= start
+ window_box_width (w
, TEXT_AREA
);
15776 portion
= end
- start
;
15777 /* After enlarging a horizontally scrolled window such that it
15778 gets at least as wide as the text it contains, make sure that
15779 the thumb doesn't fill the entire scroll bar so we can still
15780 drag it back to see the entire text. */
15781 whole
= max (whole
, end
);
15787 pdir
= Fcurrent_bidi_paragraph_direction (Qnil
);
15788 if (EQ (pdir
, Qright_to_left
))
15790 start
= whole
- end
;
15791 end
= start
+ portion
;
15796 set_buffer_internal (old_buffer
);
15799 start
= end
= whole
= portion
= 0;
15801 w
->hscroll_whole
= whole
;
15803 /* Indicate what this scroll bar ought to be displaying now. */
15804 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
15805 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_horizontal_scroll_bar_hook
)
15806 (w
, portion
, whole
, start
);
15810 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15811 selected_window is redisplayed.
15813 We can return without actually redisplaying the window if fonts has been
15814 changed on window's frame. In that case, redisplay_internal will retry.
15816 As one of the important parts of redisplaying a window, we need to
15817 decide whether the previous window-start position (stored in the
15818 window's w->start marker position) is still valid, and if it isn't,
15819 recompute it. Some details about that:
15821 . The previous window-start could be in a continuation line, in
15822 which case we need to recompute it when the window width
15823 changes. See compute_window_start_on_continuation_line and its
15826 . The text that changed since last redisplay could include the
15827 previous window-start position. In that case, we try to salvage
15828 what we can from the current glyph matrix by calling
15829 try_scrolling, which see.
15831 . Some Emacs command could force us to use a specific window-start
15832 position by setting the window's force_start flag, or gently
15833 propose doing that by setting the window's optional_new_start
15834 flag. In these cases, we try using the specified start point if
15835 that succeeds (i.e. the window desired matrix is successfully
15836 recomputed, and point location is within the window). In case
15837 of optional_new_start, we first check if the specified start
15838 position is feasible, i.e. if it will allow point to be
15839 displayed in the window. If using the specified start point
15840 fails, e.g., if new fonts are needed to be loaded, we abort the
15841 redisplay cycle and leave it up to the next cycle to figure out
15844 . Note that the window's force_start flag is sometimes set by
15845 redisplay itself, when it decides that the previous window start
15846 point is fine and should be kept. Search for "goto force_start"
15847 below to see the details. Like the values of window-start
15848 specified outside of redisplay, these internally-deduced values
15849 are tested for feasibility, and ignored if found to be
15852 . Note that the function try_window, used to completely redisplay
15853 a window, accepts the window's start point as its argument.
15854 This is used several times in the redisplay code to control
15855 where the window start will be, according to user options such
15856 as scroll-conservatively, and also to ensure the screen line
15857 showing point will be fully (as opposed to partially) visible on
15861 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
15863 struct window
*w
= XWINDOW (window
);
15864 struct frame
*f
= XFRAME (w
->frame
);
15865 struct buffer
*buffer
= XBUFFER (w
->contents
);
15866 struct buffer
*old
= current_buffer
;
15867 struct text_pos lpoint
, opoint
, startp
;
15868 int update_mode_line
;
15871 /* Record it now because it's overwritten. */
15872 bool current_matrix_up_to_date_p
= false;
15873 bool used_current_matrix_p
= false;
15874 /* This is less strict than current_matrix_up_to_date_p.
15875 It indicates that the buffer contents and narrowing are unchanged. */
15876 bool buffer_unchanged_p
= false;
15877 int temp_scroll_step
= 0;
15878 ptrdiff_t count
= SPECPDL_INDEX ();
15880 int centering_position
= -1;
15881 int last_line_misfit
= 0;
15882 ptrdiff_t beg_unchanged
, end_unchanged
;
15883 int frame_line_height
;
15885 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15889 *w
->desired_matrix
->method
= 0;
15892 if (!just_this_one_p
15893 && REDISPLAY_SOME_P ()
15896 && !buffer
->text
->redisplay
15897 && BUF_PT (buffer
) == w
->last_point
)
15900 /* Make sure that both W's markers are valid. */
15901 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15902 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15904 /* We come here again if we need to run window-text-change-functions
15907 reconsider_clip_changes (w
);
15908 frame_line_height
= default_line_pixel_height (w
);
15910 /* Has the mode line to be updated? */
15911 update_mode_line
= (w
->update_mode_line
15912 || update_mode_lines
15913 || buffer
->clip_changed
15914 || buffer
->prevent_redisplay_optimizations_p
);
15916 if (!just_this_one_p
)
15917 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
15918 cleverly elsewhere. */
15919 w
->must_be_updated_p
= true;
15921 if (MINI_WINDOW_P (w
))
15923 if (w
== XWINDOW (echo_area_window
)
15924 && !NILP (echo_area_buffer
[0]))
15926 if (update_mode_line
)
15927 /* We may have to update a tty frame's menu bar or a
15928 tool-bar. Example `M-x C-h C-h C-g'. */
15929 goto finish_menu_bars
;
15931 /* We've already displayed the echo area glyphs in this window. */
15932 goto finish_scroll_bars
;
15934 else if ((w
!= XWINDOW (minibuf_window
)
15935 || minibuf_level
== 0)
15936 /* When buffer is nonempty, redisplay window normally. */
15937 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15938 /* Quail displays non-mini buffers in minibuffer window.
15939 In that case, redisplay the window normally. */
15940 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15942 /* W is a mini-buffer window, but it's not active, so clear
15944 int yb
= window_text_bottom_y (w
);
15945 struct glyph_row
*row
;
15948 for (y
= 0, row
= w
->desired_matrix
->rows
;
15950 y
+= row
->height
, ++row
)
15951 blank_row (w
, row
, y
);
15952 goto finish_scroll_bars
;
15955 clear_glyph_matrix (w
->desired_matrix
);
15958 /* Otherwise set up data on this window; select its buffer and point
15960 /* Really select the buffer, for the sake of buffer-local
15962 set_buffer_internal_1 (XBUFFER (w
->contents
));
15964 current_matrix_up_to_date_p
15965 = (w
->window_end_valid
15966 && !current_buffer
->clip_changed
15967 && !current_buffer
->prevent_redisplay_optimizations_p
15968 && !window_outdated (w
));
15970 /* Run the window-text-change-functions
15971 if it is possible that the text on the screen has changed
15972 (either due to modification of the text, or any other reason). */
15973 if (!current_matrix_up_to_date_p
15974 && !NILP (Vwindow_text_change_functions
))
15976 safe_run_hooks (Qwindow_text_change_functions
);
15980 beg_unchanged
= BEG_UNCHANGED
;
15981 end_unchanged
= END_UNCHANGED
;
15983 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15985 specbind (Qinhibit_point_motion_hooks
, Qt
);
15988 = (w
->window_end_valid
15989 && !current_buffer
->clip_changed
15990 && !window_outdated (w
));
15992 /* When windows_or_buffers_changed is non-zero, we can't rely
15993 on the window end being valid, so set it to zero there. */
15994 if (windows_or_buffers_changed
)
15996 /* If window starts on a continuation line, maybe adjust the
15997 window start in case the window's width changed. */
15998 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15999 compute_window_start_on_continuation_line (w
);
16001 w
->window_end_valid
= false;
16002 /* If so, we also can't rely on current matrix
16003 and should not fool try_cursor_movement below. */
16004 current_matrix_up_to_date_p
= false;
16007 /* Some sanity checks. */
16008 CHECK_WINDOW_END (w
);
16009 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
16011 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
16014 if (mode_line_update_needed (w
))
16015 update_mode_line
= 1;
16017 /* Point refers normally to the selected window. For any other
16018 window, set up appropriate value. */
16019 if (!EQ (window
, selected_window
))
16021 ptrdiff_t new_pt
= marker_position (w
->pointm
);
16022 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
16027 new_pt_byte
= BEGV_BYTE
;
16028 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
16030 else if (new_pt
> (ZV
- 1))
16033 new_pt_byte
= ZV_BYTE
;
16034 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
16037 /* We don't use SET_PT so that the point-motion hooks don't run. */
16038 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
16041 /* If any of the character widths specified in the display table
16042 have changed, invalidate the width run cache. It's true that
16043 this may be a bit late to catch such changes, but the rest of
16044 redisplay goes (non-fatally) haywire when the display table is
16045 changed, so why should we worry about doing any better? */
16046 if (current_buffer
->width_run_cache
16047 || (current_buffer
->base_buffer
16048 && current_buffer
->base_buffer
->width_run_cache
))
16050 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
16052 if (! disptab_matches_widthtab
16053 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
16055 struct buffer
*buf
= current_buffer
;
16057 if (buf
->base_buffer
)
16058 buf
= buf
->base_buffer
;
16059 invalidate_region_cache (buf
, buf
->width_run_cache
, BEG
, Z
);
16060 recompute_width_table (current_buffer
, disptab
);
16064 /* If window-start is screwed up, choose a new one. */
16065 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
16068 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16070 /* If someone specified a new starting point but did not insist,
16071 check whether it can be used. */
16072 if ((w
->optional_new_start
|| window_frozen_p (w
))
16073 && CHARPOS (startp
) >= BEGV
16074 && CHARPOS (startp
) <= ZV
)
16076 ptrdiff_t it_charpos
;
16078 w
->optional_new_start
= 0;
16079 start_display (&it
, w
, startp
);
16080 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
16081 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
16082 /* Record IT's position now, since line_bottom_y might change
16084 it_charpos
= IT_CHARPOS (it
);
16085 /* Make sure we set the force_start flag only if the cursor row
16086 will be fully visible. Otherwise, the code under force_start
16087 label below will try to move point back into view, which is
16088 not what the code which sets optional_new_start wants. */
16089 if ((it
.current_y
== 0 || line_bottom_y (&it
) < it
.last_visible_y
)
16090 && !w
->force_start
)
16092 if (it_charpos
== PT
)
16093 w
->force_start
= 1;
16094 /* IT may overshoot PT if text at PT is invisible. */
16095 else if (it_charpos
> PT
&& CHARPOS (startp
) <= PT
)
16096 w
->force_start
= 1;
16098 if (w
->force_start
)
16100 if (window_frozen_p (w
))
16101 debug_method_add (w
, "set force_start from frozen window start");
16103 debug_method_add (w
, "set force_start from optional_new_start");
16111 /* Handle case where place to start displaying has been specified,
16112 unless the specified location is outside the accessible range. */
16113 if (w
->force_start
)
16115 /* We set this later on if we have to adjust point. */
16118 w
->force_start
= 0;
16120 w
->window_end_valid
= 0;
16122 /* Forget any recorded base line for line number display. */
16123 if (!buffer_unchanged_p
)
16124 w
->base_line_number
= 0;
16126 /* Redisplay the mode line. Select the buffer properly for that.
16127 Also, run the hook window-scroll-functions
16128 because we have scrolled. */
16129 /* Note, we do this after clearing force_start because
16130 if there's an error, it is better to forget about force_start
16131 than to get into an infinite loop calling the hook functions
16132 and having them get more errors. */
16133 if (!update_mode_line
16134 || ! NILP (Vwindow_scroll_functions
))
16136 update_mode_line
= 1;
16137 w
->update_mode_line
= 1;
16138 startp
= run_window_scroll_functions (window
, startp
);
16141 if (CHARPOS (startp
) < BEGV
)
16142 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
16143 else if (CHARPOS (startp
) > ZV
)
16144 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
16146 /* Redisplay, then check if cursor has been set during the
16147 redisplay. Give up if new fonts were loaded. */
16148 /* We used to issue a CHECK_MARGINS argument to try_window here,
16149 but this causes scrolling to fail when point begins inside
16150 the scroll margin (bug#148) -- cyd */
16151 if (!try_window (window
, startp
, 0))
16153 w
->force_start
= 1;
16154 clear_glyph_matrix (w
->desired_matrix
);
16155 goto need_larger_matrices
;
16158 if (w
->cursor
.vpos
< 0)
16160 /* If point does not appear, try to move point so it does
16161 appear. The desired matrix has been built above, so we
16162 can use it here. */
16163 new_vpos
= window_box_height (w
) / 2;
16166 if (!cursor_row_fully_visible_p (w
, 0, 0))
16168 /* Point does appear, but on a line partly visible at end of window.
16169 Move it back to a fully-visible line. */
16170 new_vpos
= window_box_height (w
);
16171 /* But if window_box_height suggests a Y coordinate that is
16172 not less than we already have, that line will clearly not
16173 be fully visible, so give up and scroll the display.
16174 This can happen when the default face uses a font whose
16175 dimensions are different from the frame's default
16177 if (new_vpos
>= w
->cursor
.y
)
16179 w
->cursor
.vpos
= -1;
16180 clear_glyph_matrix (w
->desired_matrix
);
16181 goto try_to_scroll
;
16184 else if (w
->cursor
.vpos
>= 0)
16186 /* Some people insist on not letting point enter the scroll
16187 margin, even though this part handles windows that didn't
16189 int window_total_lines
16190 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16191 int margin
= min (scroll_margin
, window_total_lines
/ 4);
16192 int pixel_margin
= margin
* frame_line_height
;
16193 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
16195 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
16196 below, which finds the row to move point to, advances by
16197 the Y coordinate of the _next_ row, see the definition of
16198 MATRIX_ROW_BOTTOM_Y. */
16199 if (w
->cursor
.vpos
< margin
+ header_line
)
16201 w
->cursor
.vpos
= -1;
16202 clear_glyph_matrix (w
->desired_matrix
);
16203 goto try_to_scroll
;
16207 int window_height
= window_box_height (w
);
16210 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
16211 if (w
->cursor
.y
>= window_height
- pixel_margin
)
16213 w
->cursor
.vpos
= -1;
16214 clear_glyph_matrix (w
->desired_matrix
);
16215 goto try_to_scroll
;
16220 /* If we need to move point for either of the above reasons,
16221 now actually do it. */
16224 struct glyph_row
*row
;
16226 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
16227 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
16230 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
16231 MATRIX_ROW_START_BYTEPOS (row
));
16233 if (w
!= XWINDOW (selected_window
))
16234 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
16235 else if (current_buffer
== old
)
16236 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
16238 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
16240 /* Re-run pre-redisplay-function so it can update the region
16241 according to the new position of point. */
16242 /* Other than the cursor, w's redisplay is done so we can set its
16243 redisplay to false. Also the buffer's redisplay can be set to
16244 false, since propagate_buffer_redisplay should have already
16245 propagated its info to `w' anyway. */
16246 w
->redisplay
= false;
16247 XBUFFER (w
->contents
)->text
->redisplay
= false;
16248 safe__call1 (true, Vpre_redisplay_function
, Fcons (window
, Qnil
));
16250 if (w
->redisplay
|| XBUFFER (w
->contents
)->text
->redisplay
)
16252 /* pre-redisplay-function made changes (e.g. move the region)
16253 that require another round of redisplay. */
16254 clear_glyph_matrix (w
->desired_matrix
);
16255 if (!try_window (window
, startp
, 0))
16256 goto need_larger_matrices
;
16259 if (w
->cursor
.vpos
< 0 || !cursor_row_fully_visible_p (w
, 0, 0))
16261 clear_glyph_matrix (w
->desired_matrix
);
16262 goto try_to_scroll
;
16266 debug_method_add (w
, "forced window start");
16271 /* Handle case where text has not changed, only point, and it has
16272 not moved off the frame, and we are not retrying after hscroll.
16273 (current_matrix_up_to_date_p is nonzero when retrying.) */
16274 if (current_matrix_up_to_date_p
16275 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
16276 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
16280 case CURSOR_MOVEMENT_SUCCESS
:
16281 used_current_matrix_p
= 1;
16284 case CURSOR_MOVEMENT_MUST_SCROLL
:
16285 goto try_to_scroll
;
16291 /* If current starting point was originally the beginning of a line
16292 but no longer is, find a new starting point. */
16293 else if (w
->start_at_line_beg
16294 && !(CHARPOS (startp
) <= BEGV
16295 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
16298 debug_method_add (w
, "recenter 1");
16303 /* Try scrolling with try_window_id. Value is > 0 if update has
16304 been done, it is -1 if we know that the same window start will
16305 not work. It is 0 if unsuccessful for some other reason. */
16306 else if ((tem
= try_window_id (w
)) != 0)
16309 debug_method_add (w
, "try_window_id %d", tem
);
16312 if (f
->fonts_changed
)
16313 goto need_larger_matrices
;
16317 /* Otherwise try_window_id has returned -1 which means that we
16318 don't want the alternative below this comment to execute. */
16320 else if (CHARPOS (startp
) >= BEGV
16321 && CHARPOS (startp
) <= ZV
16322 && PT
>= CHARPOS (startp
)
16323 && (CHARPOS (startp
) < ZV
16324 /* Avoid starting at end of buffer. */
16325 || CHARPOS (startp
) == BEGV
16326 || !window_outdated (w
)))
16328 int d1
, d2
, d5
, d6
;
16331 /* If first window line is a continuation line, and window start
16332 is inside the modified region, but the first change is before
16333 current window start, we must select a new window start.
16335 However, if this is the result of a down-mouse event (e.g. by
16336 extending the mouse-drag-overlay), we don't want to select a
16337 new window start, since that would change the position under
16338 the mouse, resulting in an unwanted mouse-movement rather
16339 than a simple mouse-click. */
16340 if (!w
->start_at_line_beg
16341 && NILP (do_mouse_tracking
)
16342 && CHARPOS (startp
) > BEGV
16343 && CHARPOS (startp
) > BEG
+ beg_unchanged
16344 && CHARPOS (startp
) <= Z
- end_unchanged
16345 /* Even if w->start_at_line_beg is nil, a new window may
16346 start at a line_beg, since that's how set_buffer_window
16347 sets it. So, we need to check the return value of
16348 compute_window_start_on_continuation_line. (See also
16350 && XMARKER (w
->start
)->buffer
== current_buffer
16351 && compute_window_start_on_continuation_line (w
)
16352 /* It doesn't make sense to force the window start like we
16353 do at label force_start if it is already known that point
16354 will not be fully visible in the resulting window, because
16355 doing so will move point from its correct position
16356 instead of scrolling the window to bring point into view.
16358 && pos_visible_p (w
, PT
, &d1
, &d2
, &rtop
, &rbot
, &d5
, &d6
)
16359 /* A very tall row could need more than the window height,
16360 in which case we accept that it is partially visible. */
16361 && (rtop
!= 0) == (rbot
!= 0))
16363 w
->force_start
= 1;
16364 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16366 debug_method_add (w
, "recomputed window start in continuation line");
16372 debug_method_add (w
, "same window start");
16375 /* Try to redisplay starting at same place as before.
16376 If point has not moved off frame, accept the results. */
16377 if (!current_matrix_up_to_date_p
16378 /* Don't use try_window_reusing_current_matrix in this case
16379 because a window scroll function can have changed the
16381 || !NILP (Vwindow_scroll_functions
)
16382 || MINI_WINDOW_P (w
)
16383 || !(used_current_matrix_p
16384 = try_window_reusing_current_matrix (w
)))
16386 IF_DEBUG (debug_method_add (w
, "1"));
16387 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16388 /* -1 means we need to scroll.
16389 0 means we need new matrices, but fonts_changed
16390 is set in that case, so we will detect it below. */
16391 goto try_to_scroll
;
16394 if (f
->fonts_changed
)
16395 goto need_larger_matrices
;
16397 if (w
->cursor
.vpos
>= 0)
16399 if (!just_this_one_p
16400 || current_buffer
->clip_changed
16401 || BEG_UNCHANGED
< CHARPOS (startp
))
16402 /* Forget any recorded base line for line number display. */
16403 w
->base_line_number
= 0;
16405 if (!cursor_row_fully_visible_p (w
, 1, 0))
16407 clear_glyph_matrix (w
->desired_matrix
);
16408 last_line_misfit
= 1;
16410 /* Drop through and scroll. */
16415 clear_glyph_matrix (w
->desired_matrix
);
16420 /* Redisplay the mode line. Select the buffer properly for that. */
16421 if (!update_mode_line
)
16423 update_mode_line
= 1;
16424 w
->update_mode_line
= 1;
16427 /* Try to scroll by specified few lines. */
16428 if ((scroll_conservatively
16429 || emacs_scroll_step
16430 || temp_scroll_step
16431 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16432 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16433 && CHARPOS (startp
) >= BEGV
16434 && CHARPOS (startp
) <= ZV
)
16436 /* The function returns -1 if new fonts were loaded, 1 if
16437 successful, 0 if not successful. */
16438 int ss
= try_scrolling (window
, just_this_one_p
,
16439 scroll_conservatively
,
16441 temp_scroll_step
, last_line_misfit
);
16444 case SCROLLING_SUCCESS
:
16447 case SCROLLING_NEED_LARGER_MATRICES
:
16448 goto need_larger_matrices
;
16450 case SCROLLING_FAILED
:
16458 /* Finally, just choose a place to start which positions point
16459 according to user preferences. */
16464 debug_method_add (w
, "recenter");
16467 /* Forget any previously recorded base line for line number display. */
16468 if (!buffer_unchanged_p
)
16469 w
->base_line_number
= 0;
16471 /* Determine the window start relative to point. */
16472 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16473 it
.current_y
= it
.last_visible_y
;
16474 if (centering_position
< 0)
16476 int window_total_lines
16477 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16479 = scroll_margin
> 0
16480 ? min (scroll_margin
, window_total_lines
/ 4)
16482 ptrdiff_t margin_pos
= CHARPOS (startp
);
16483 Lisp_Object aggressive
;
16486 /* If there is a scroll margin at the top of the window, find
16487 its character position. */
16489 /* Cannot call start_display if startp is not in the
16490 accessible region of the buffer. This can happen when we
16491 have just switched to a different buffer and/or changed
16492 its restriction. In that case, startp is initialized to
16493 the character position 1 (BEGV) because we did not yet
16494 have chance to display the buffer even once. */
16495 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16498 void *it1data
= NULL
;
16500 SAVE_IT (it1
, it
, it1data
);
16501 start_display (&it1
, w
, startp
);
16502 move_it_vertically (&it1
, margin
* frame_line_height
);
16503 margin_pos
= IT_CHARPOS (it1
);
16504 RESTORE_IT (&it
, &it
, it1data
);
16506 scrolling_up
= PT
> margin_pos
;
16509 ? BVAR (current_buffer
, scroll_up_aggressively
)
16510 : BVAR (current_buffer
, scroll_down_aggressively
);
16512 if (!MINI_WINDOW_P (w
)
16513 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16517 /* Setting scroll-conservatively overrides
16518 scroll-*-aggressively. */
16519 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16521 double float_amount
= XFLOATINT (aggressive
);
16523 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16524 if (pt_offset
== 0 && float_amount
> 0)
16526 if (pt_offset
&& margin
> 0)
16529 /* Compute how much to move the window start backward from
16530 point so that point will be displayed where the user
16534 centering_position
= it
.last_visible_y
;
16536 centering_position
-= pt_offset
;
16537 centering_position
-=
16538 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
16539 + WINDOW_HEADER_LINE_HEIGHT (w
);
16540 /* Don't let point enter the scroll margin near top of
16542 if (centering_position
< margin
* frame_line_height
)
16543 centering_position
= margin
* frame_line_height
;
16546 centering_position
= margin
* frame_line_height
+ pt_offset
;
16549 /* Set the window start half the height of the window backward
16551 centering_position
= window_box_height (w
) / 2;
16553 move_it_vertically_backward (&it
, centering_position
);
16555 eassert (IT_CHARPOS (it
) >= BEGV
);
16557 /* The function move_it_vertically_backward may move over more
16558 than the specified y-distance. If it->w is small, e.g. a
16559 mini-buffer window, we may end up in front of the window's
16560 display area. Start displaying at the start of the line
16561 containing PT in this case. */
16562 if (it
.current_y
<= 0)
16564 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16565 move_it_vertically_backward (&it
, 0);
16569 it
.current_x
= it
.hpos
= 0;
16571 /* Set the window start position here explicitly, to avoid an
16572 infinite loop in case the functions in window-scroll-functions
16574 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16576 /* Run scroll hooks. */
16577 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16579 /* Redisplay the window. */
16580 if (!current_matrix_up_to_date_p
16581 || windows_or_buffers_changed
16582 || f
->cursor_type_changed
16583 /* Don't use try_window_reusing_current_matrix in this case
16584 because it can have changed the buffer. */
16585 || !NILP (Vwindow_scroll_functions
)
16586 || !just_this_one_p
16587 || MINI_WINDOW_P (w
)
16588 || !(used_current_matrix_p
16589 = try_window_reusing_current_matrix (w
)))
16590 try_window (window
, startp
, 0);
16592 /* If new fonts have been loaded (due to fontsets), give up. We
16593 have to start a new redisplay since we need to re-adjust glyph
16595 if (f
->fonts_changed
)
16596 goto need_larger_matrices
;
16598 /* If cursor did not appear assume that the middle of the window is
16599 in the first line of the window. Do it again with the next line.
16600 (Imagine a window of height 100, displaying two lines of height
16601 60. Moving back 50 from it->last_visible_y will end in the first
16603 if (w
->cursor
.vpos
< 0)
16605 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16607 clear_glyph_matrix (w
->desired_matrix
);
16608 move_it_by_lines (&it
, 1);
16609 try_window (window
, it
.current
.pos
, 0);
16611 else if (PT
< IT_CHARPOS (it
))
16613 clear_glyph_matrix (w
->desired_matrix
);
16614 move_it_by_lines (&it
, -1);
16615 try_window (window
, it
.current
.pos
, 0);
16619 /* Not much we can do about it. */
16623 /* Consider the following case: Window starts at BEGV, there is
16624 invisible, intangible text at BEGV, so that display starts at
16625 some point START > BEGV. It can happen that we are called with
16626 PT somewhere between BEGV and START. Try to handle that case,
16627 and similar ones. */
16628 if (w
->cursor
.vpos
< 0)
16630 /* First, try locating the proper glyph row for PT. */
16631 struct glyph_row
*row
=
16632 row_containing_pos (w
, PT
, w
->current_matrix
->rows
, NULL
, 0);
16634 /* Sometimes point is at the beginning of invisible text that is
16635 before the 1st character displayed in the row. In that case,
16636 row_containing_pos fails to find the row, because no glyphs
16637 with appropriate buffer positions are present in the row.
16638 Therefore, we next try to find the row which shows the 1st
16639 position after the invisible text. */
16643 get_char_property_and_overlay (make_number (PT
), Qinvisible
,
16646 if (TEXT_PROP_MEANS_INVISIBLE (val
))
16649 Lisp_Object invis_end
=
16650 Fnext_single_char_property_change (make_number (PT
), Qinvisible
,
16653 if (NATNUMP (invis_end
))
16654 alt_pos
= XFASTINT (invis_end
);
16657 row
= row_containing_pos (w
, alt_pos
, w
->current_matrix
->rows
,
16661 /* Finally, fall back on the first row of the window after the
16662 header line (if any). This is slightly better than not
16663 displaying the cursor at all. */
16666 row
= w
->current_matrix
->rows
;
16667 if (row
->mode_line_p
)
16670 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16673 if (!cursor_row_fully_visible_p (w
, 0, 0))
16675 /* If vscroll is enabled, disable it and try again. */
16679 clear_glyph_matrix (w
->desired_matrix
);
16683 /* Users who set scroll-conservatively to a large number want
16684 point just above/below the scroll margin. If we ended up
16685 with point's row partially visible, move the window start to
16686 make that row fully visible and out of the margin. */
16687 if (scroll_conservatively
> SCROLL_LIMIT
)
16689 int window_total_lines
16690 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16693 ? min (scroll_margin
, window_total_lines
/ 4)
16695 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16697 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16698 clear_glyph_matrix (w
->desired_matrix
);
16699 if (1 == try_window (window
, it
.current
.pos
,
16700 TRY_WINDOW_CHECK_MARGINS
))
16704 /* If centering point failed to make the whole line visible,
16705 put point at the top instead. That has to make the whole line
16706 visible, if it can be done. */
16707 if (centering_position
== 0)
16710 clear_glyph_matrix (w
->desired_matrix
);
16711 centering_position
= 0;
16717 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16718 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16719 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16721 /* Display the mode line, if we must. */
16722 if ((update_mode_line
16723 /* If window not full width, must redo its mode line
16724 if (a) the window to its side is being redone and
16725 (b) we do a frame-based redisplay. This is a consequence
16726 of how inverted lines are drawn in frame-based redisplay. */
16727 || (!just_this_one_p
16728 && !FRAME_WINDOW_P (f
)
16729 && !WINDOW_FULL_WIDTH_P (w
))
16730 /* Line number to display. */
16731 || w
->base_line_pos
> 0
16732 /* Column number is displayed and different from the one displayed. */
16733 || (w
->column_number_displayed
!= -1
16734 && (w
->column_number_displayed
!= current_column ())))
16735 /* This means that the window has a mode line. */
16736 && (WINDOW_WANTS_MODELINE_P (w
)
16737 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16740 display_mode_lines (w
);
16742 /* If mode line height has changed, arrange for a thorough
16743 immediate redisplay using the correct mode line height. */
16744 if (WINDOW_WANTS_MODELINE_P (w
)
16745 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16747 f
->fonts_changed
= 1;
16748 w
->mode_line_height
= -1;
16749 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16750 = DESIRED_MODE_LINE_HEIGHT (w
);
16753 /* If header line height has changed, arrange for a thorough
16754 immediate redisplay using the correct header line height. */
16755 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16756 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16758 f
->fonts_changed
= 1;
16759 w
->header_line_height
= -1;
16760 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16761 = DESIRED_HEADER_LINE_HEIGHT (w
);
16764 if (f
->fonts_changed
)
16765 goto need_larger_matrices
;
16768 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16770 w
->base_line_pos
= 0;
16771 w
->base_line_number
= 0;
16776 /* When we reach a frame's selected window, redo the frame's menu bar. */
16777 if (update_mode_line
16778 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16780 int redisplay_menu_p
= 0;
16782 if (FRAME_WINDOW_P (f
))
16784 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16785 || defined (HAVE_NS) || defined (USE_GTK)
16786 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16788 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16792 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16794 if (redisplay_menu_p
)
16795 display_menu_bar (w
);
16797 #ifdef HAVE_WINDOW_SYSTEM
16798 if (FRAME_WINDOW_P (f
))
16800 #if defined (USE_GTK) || defined (HAVE_NS)
16801 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16802 redisplay_tool_bar (f
);
16804 if (WINDOWP (f
->tool_bar_window
)
16805 && (FRAME_TOOL_BAR_LINES (f
) > 0
16806 || !NILP (Vauto_resize_tool_bars
))
16807 && redisplay_tool_bar (f
))
16808 ignore_mouse_drag_p
= 1;
16814 #ifdef HAVE_WINDOW_SYSTEM
16815 if (FRAME_WINDOW_P (f
)
16816 && update_window_fringes (w
, (just_this_one_p
16817 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16818 || w
->pseudo_window_p
)))
16822 if (draw_window_fringes (w
, 1))
16824 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
16825 x_draw_right_divider (w
);
16827 x_draw_vertical_border (w
);
16833 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
16834 x_draw_bottom_divider (w
);
16835 #endif /* HAVE_WINDOW_SYSTEM */
16837 /* We go to this label, with fonts_changed set, if it is
16838 necessary to try again using larger glyph matrices.
16839 We have to redeem the scroll bar even in this case,
16840 because the loop in redisplay_internal expects that. */
16841 need_larger_matrices
:
16843 finish_scroll_bars
:
16845 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
) || WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
16847 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16848 /* Set the thumb's position and size. */
16849 set_vertical_scroll_bar (w
);
16851 if (WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
16852 /* Set the thumb's position and size. */
16853 set_horizontal_scroll_bar (w
);
16855 /* Note that we actually used the scroll bar attached to this
16856 window, so it shouldn't be deleted at the end of redisplay. */
16857 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16858 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16861 /* Restore current_buffer and value of point in it. The window
16862 update may have changed the buffer, so first make sure `opoint'
16863 is still valid (Bug#6177). */
16864 if (CHARPOS (opoint
) < BEGV
)
16865 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16866 else if (CHARPOS (opoint
) > ZV
)
16867 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16869 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16871 set_buffer_internal_1 (old
);
16872 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16873 shorter. This can be caused by log truncation in *Messages*. */
16874 if (CHARPOS (lpoint
) <= ZV
)
16875 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16877 unbind_to (count
, Qnil
);
16881 /* Build the complete desired matrix of WINDOW with a window start
16882 buffer position POS.
16884 Value is 1 if successful. It is zero if fonts were loaded during
16885 redisplay which makes re-adjusting glyph matrices necessary, and -1
16886 if point would appear in the scroll margins.
16887 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16888 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16892 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16894 struct window
*w
= XWINDOW (window
);
16896 struct glyph_row
*last_text_row
= NULL
;
16897 struct frame
*f
= XFRAME (w
->frame
);
16898 int frame_line_height
= default_line_pixel_height (w
);
16900 /* Make POS the new window start. */
16901 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16903 /* Mark cursor position as unknown. No overlay arrow seen. */
16904 w
->cursor
.vpos
= -1;
16905 overlay_arrow_seen
= 0;
16907 /* Initialize iterator and info to start at POS. */
16908 start_display (&it
, w
, pos
);
16909 it
.glyph_row
->reversed_p
= false;
16911 /* Display all lines of W. */
16912 while (it
.current_y
< it
.last_visible_y
)
16914 if (display_line (&it
))
16915 last_text_row
= it
.glyph_row
- 1;
16916 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16920 /* Don't let the cursor end in the scroll margins. */
16921 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16922 && !MINI_WINDOW_P (w
))
16924 int this_scroll_margin
;
16925 int window_total_lines
16926 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16928 if (scroll_margin
> 0)
16930 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16931 this_scroll_margin
*= frame_line_height
;
16934 this_scroll_margin
= 0;
16936 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16937 && w
->cursor
.y
< this_scroll_margin
16938 && CHARPOS (pos
) > BEGV
16939 && IT_CHARPOS (it
) < ZV
)
16940 /* rms: considering make_cursor_line_fully_visible_p here
16941 seems to give wrong results. We don't want to recenter
16942 when the last line is partly visible, we want to allow
16943 that case to be handled in the usual way. */
16944 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16946 w
->cursor
.vpos
= -1;
16947 clear_glyph_matrix (w
->desired_matrix
);
16952 /* If bottom moved off end of frame, change mode line percentage. */
16953 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16954 w
->update_mode_line
= 1;
16956 /* Set window_end_pos to the offset of the last character displayed
16957 on the window from the end of current_buffer. Set
16958 window_end_vpos to its row number. */
16961 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16962 adjust_window_ends (w
, last_text_row
, 0);
16964 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16965 w
->window_end_vpos
)));
16969 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16970 w
->window_end_pos
= Z
- ZV
;
16971 w
->window_end_vpos
= 0;
16974 /* But that is not valid info until redisplay finishes. */
16975 w
->window_end_valid
= 0;
16981 /************************************************************************
16982 Window redisplay reusing current matrix when buffer has not changed
16983 ************************************************************************/
16985 /* Try redisplay of window W showing an unchanged buffer with a
16986 different window start than the last time it was displayed by
16987 reusing its current matrix. Value is non-zero if successful.
16988 W->start is the new window start. */
16991 try_window_reusing_current_matrix (struct window
*w
)
16993 struct frame
*f
= XFRAME (w
->frame
);
16994 struct glyph_row
*bottom_row
;
16997 struct text_pos start
, new_start
;
16998 int nrows_scrolled
, i
;
16999 struct glyph_row
*last_text_row
;
17000 struct glyph_row
*last_reused_text_row
;
17001 struct glyph_row
*start_row
;
17002 int start_vpos
, min_y
, max_y
;
17005 if (inhibit_try_window_reusing
)
17009 if (/* This function doesn't handle terminal frames. */
17010 !FRAME_WINDOW_P (f
)
17011 /* Don't try to reuse the display if windows have been split
17013 || windows_or_buffers_changed
17014 || f
->cursor_type_changed
)
17017 /* Can't do this if showing trailing whitespace. */
17018 if (!NILP (Vshow_trailing_whitespace
))
17021 /* If top-line visibility has changed, give up. */
17022 if (WINDOW_WANTS_HEADER_LINE_P (w
)
17023 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
17026 /* Give up if old or new display is scrolled vertically. We could
17027 make this function handle this, but right now it doesn't. */
17028 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17029 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
17032 /* The variable new_start now holds the new window start. The old
17033 start `start' can be determined from the current matrix. */
17034 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
17035 start
= start_row
->minpos
;
17036 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17038 /* Clear the desired matrix for the display below. */
17039 clear_glyph_matrix (w
->desired_matrix
);
17041 if (CHARPOS (new_start
) <= CHARPOS (start
))
17043 /* Don't use this method if the display starts with an ellipsis
17044 displayed for invisible text. It's not easy to handle that case
17045 below, and it's certainly not worth the effort since this is
17046 not a frequent case. */
17047 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
17050 IF_DEBUG (debug_method_add (w
, "twu1"));
17052 /* Display up to a row that can be reused. The variable
17053 last_text_row is set to the last row displayed that displays
17054 text. Note that it.vpos == 0 if or if not there is a
17055 header-line; it's not the same as the MATRIX_ROW_VPOS! */
17056 start_display (&it
, w
, new_start
);
17057 w
->cursor
.vpos
= -1;
17058 last_text_row
= last_reused_text_row
= NULL
;
17060 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17062 /* If we have reached into the characters in the START row,
17063 that means the line boundaries have changed. So we
17064 can't start copying with the row START. Maybe it will
17065 work to start copying with the following row. */
17066 while (IT_CHARPOS (it
) > CHARPOS (start
))
17068 /* Advance to the next row as the "start". */
17070 start
= start_row
->minpos
;
17071 /* If there are no more rows to try, or just one, give up. */
17072 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
17073 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
17074 || CHARPOS (start
) == ZV
)
17076 clear_glyph_matrix (w
->desired_matrix
);
17080 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
17082 /* If we have reached alignment, we can copy the rest of the
17084 if (IT_CHARPOS (it
) == CHARPOS (start
)
17085 /* Don't accept "alignment" inside a display vector,
17086 since start_row could have started in the middle of
17087 that same display vector (thus their character
17088 positions match), and we have no way of telling if
17089 that is the case. */
17090 && it
.current
.dpvec_index
< 0)
17093 it
.glyph_row
->reversed_p
= false;
17094 if (display_line (&it
))
17095 last_text_row
= it
.glyph_row
- 1;
17099 /* A value of current_y < last_visible_y means that we stopped
17100 at the previous window start, which in turn means that we
17101 have at least one reusable row. */
17102 if (it
.current_y
< it
.last_visible_y
)
17104 struct glyph_row
*row
;
17106 /* IT.vpos always starts from 0; it counts text lines. */
17107 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
17109 /* Find PT if not already found in the lines displayed. */
17110 if (w
->cursor
.vpos
< 0)
17112 int dy
= it
.current_y
- start_row
->y
;
17114 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17115 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
17117 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
17118 dy
, nrows_scrolled
);
17121 clear_glyph_matrix (w
->desired_matrix
);
17126 /* Scroll the display. Do it before the current matrix is
17127 changed. The problem here is that update has not yet
17128 run, i.e. part of the current matrix is not up to date.
17129 scroll_run_hook will clear the cursor, and use the
17130 current matrix to get the height of the row the cursor is
17132 run
.current_y
= start_row
->y
;
17133 run
.desired_y
= it
.current_y
;
17134 run
.height
= it
.last_visible_y
- it
.current_y
;
17136 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
17139 FRAME_RIF (f
)->update_window_begin_hook (w
);
17140 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17141 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17142 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17146 /* Shift current matrix down by nrows_scrolled lines. */
17147 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17148 rotate_matrix (w
->current_matrix
,
17150 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17153 /* Disable lines that must be updated. */
17154 for (i
= 0; i
< nrows_scrolled
; ++i
)
17155 (start_row
+ i
)->enabled_p
= false;
17157 /* Re-compute Y positions. */
17158 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17159 max_y
= it
.last_visible_y
;
17160 for (row
= start_row
+ nrows_scrolled
;
17164 row
->y
= it
.current_y
;
17165 row
->visible_height
= row
->height
;
17167 if (row
->y
< min_y
)
17168 row
->visible_height
-= min_y
- row
->y
;
17169 if (row
->y
+ row
->height
> max_y
)
17170 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17171 if (row
->fringe_bitmap_periodic_p
)
17172 row
->redraw_fringe_bitmaps_p
= 1;
17174 it
.current_y
+= row
->height
;
17176 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17177 last_reused_text_row
= row
;
17178 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
17182 /* Disable lines in the current matrix which are now
17183 below the window. */
17184 for (++row
; row
< bottom_row
; ++row
)
17185 row
->enabled_p
= row
->mode_line_p
= 0;
17188 /* Update window_end_pos etc.; last_reused_text_row is the last
17189 reused row from the current matrix containing text, if any.
17190 The value of last_text_row is the last displayed line
17191 containing text. */
17192 if (last_reused_text_row
)
17193 adjust_window_ends (w
, last_reused_text_row
, 1);
17194 else if (last_text_row
)
17195 adjust_window_ends (w
, last_text_row
, 0);
17198 /* This window must be completely empty. */
17199 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
17200 w
->window_end_pos
= Z
- ZV
;
17201 w
->window_end_vpos
= 0;
17203 w
->window_end_valid
= 0;
17205 /* Update hint: don't try scrolling again in update_window. */
17206 w
->desired_matrix
->no_scrolling_p
= 1;
17209 debug_method_add (w
, "try_window_reusing_current_matrix 1");
17213 else if (CHARPOS (new_start
) > CHARPOS (start
))
17215 struct glyph_row
*pt_row
, *row
;
17216 struct glyph_row
*first_reusable_row
;
17217 struct glyph_row
*first_row_to_display
;
17219 int yb
= window_text_bottom_y (w
);
17221 /* Find the row starting at new_start, if there is one. Don't
17222 reuse a partially visible line at the end. */
17223 first_reusable_row
= start_row
;
17224 while (first_reusable_row
->enabled_p
17225 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
17226 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17227 < CHARPOS (new_start
)))
17228 ++first_reusable_row
;
17230 /* Give up if there is no row to reuse. */
17231 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
17232 || !first_reusable_row
->enabled_p
17233 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
17234 != CHARPOS (new_start
)))
17237 /* We can reuse fully visible rows beginning with
17238 first_reusable_row to the end of the window. Set
17239 first_row_to_display to the first row that cannot be reused.
17240 Set pt_row to the row containing point, if there is any. */
17242 for (first_row_to_display
= first_reusable_row
;
17243 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
17244 ++first_row_to_display
)
17246 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
17247 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17248 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
17249 && first_row_to_display
->ends_at_zv_p
17250 && pt_row
== NULL
)))
17251 pt_row
= first_row_to_display
;
17254 /* Start displaying at the start of first_row_to_display. */
17255 eassert (first_row_to_display
->y
< yb
);
17256 init_to_row_start (&it
, w
, first_row_to_display
);
17258 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
17260 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
17262 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
17263 + WINDOW_HEADER_LINE_HEIGHT (w
));
17265 /* Display lines beginning with first_row_to_display in the
17266 desired matrix. Set last_text_row to the last row displayed
17267 that displays text. */
17268 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
17269 if (pt_row
== NULL
)
17270 w
->cursor
.vpos
= -1;
17271 last_text_row
= NULL
;
17272 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17273 if (display_line (&it
))
17274 last_text_row
= it
.glyph_row
- 1;
17276 /* If point is in a reused row, adjust y and vpos of the cursor
17280 w
->cursor
.vpos
-= nrows_scrolled
;
17281 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
17284 /* Give up if point isn't in a row displayed or reused. (This
17285 also handles the case where w->cursor.vpos < nrows_scrolled
17286 after the calls to display_line, which can happen with scroll
17287 margins. See bug#1295.) */
17288 if (w
->cursor
.vpos
< 0)
17290 clear_glyph_matrix (w
->desired_matrix
);
17294 /* Scroll the display. */
17295 run
.current_y
= first_reusable_row
->y
;
17296 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17297 run
.height
= it
.last_visible_y
- run
.current_y
;
17298 dy
= run
.current_y
- run
.desired_y
;
17303 FRAME_RIF (f
)->update_window_begin_hook (w
);
17304 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17305 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17306 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17310 /* Adjust Y positions of reused rows. */
17311 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
17312 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
17313 max_y
= it
.last_visible_y
;
17314 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
17317 row
->visible_height
= row
->height
;
17318 if (row
->y
< min_y
)
17319 row
->visible_height
-= min_y
- row
->y
;
17320 if (row
->y
+ row
->height
> max_y
)
17321 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
17322 if (row
->fringe_bitmap_periodic_p
)
17323 row
->redraw_fringe_bitmaps_p
= 1;
17326 /* Scroll the current matrix. */
17327 eassert (nrows_scrolled
> 0);
17328 rotate_matrix (w
->current_matrix
,
17330 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
17333 /* Disable rows not reused. */
17334 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
17335 row
->enabled_p
= false;
17337 /* Point may have moved to a different line, so we cannot assume that
17338 the previous cursor position is valid; locate the correct row. */
17341 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
17343 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
17344 && !row
->ends_at_zv_p
;
17348 w
->cursor
.y
= row
->y
;
17350 if (row
< bottom_row
)
17352 /* Can't simply scan the row for point with
17353 bidi-reordered glyph rows. Let set_cursor_from_row
17354 figure out where to put the cursor, and if it fails,
17356 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
17358 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
17361 clear_glyph_matrix (w
->desired_matrix
);
17367 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
17368 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17371 && (!BUFFERP (glyph
->object
)
17372 || glyph
->charpos
< PT
);
17376 w
->cursor
.x
+= glyph
->pixel_width
;
17382 /* Adjust window end. A null value of last_text_row means that
17383 the window end is in reused rows which in turn means that
17384 only its vpos can have changed. */
17386 adjust_window_ends (w
, last_text_row
, 0);
17388 w
->window_end_vpos
-= nrows_scrolled
;
17390 w
->window_end_valid
= 0;
17391 w
->desired_matrix
->no_scrolling_p
= 1;
17394 debug_method_add (w
, "try_window_reusing_current_matrix 2");
17404 /************************************************************************
17405 Window redisplay reusing current matrix when buffer has changed
17406 ************************************************************************/
17408 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
17409 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17410 ptrdiff_t *, ptrdiff_t *);
17411 static struct glyph_row
*
17412 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17413 struct glyph_row
*);
17416 /* Return the last row in MATRIX displaying text. If row START is
17417 non-null, start searching with that row. IT gives the dimensions
17418 of the display. Value is null if matrix is empty; otherwise it is
17419 a pointer to the row found. */
17421 static struct glyph_row
*
17422 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17423 struct glyph_row
*start
)
17425 struct glyph_row
*row
, *row_found
;
17427 /* Set row_found to the last row in IT->w's current matrix
17428 displaying text. The loop looks funny but think of partially
17431 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17432 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17434 eassert (row
->enabled_p
);
17436 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17445 /* Return the last row in the current matrix of W that is not affected
17446 by changes at the start of current_buffer that occurred since W's
17447 current matrix was built. Value is null if no such row exists.
17449 BEG_UNCHANGED us the number of characters unchanged at the start of
17450 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17451 first changed character in current_buffer. Characters at positions <
17452 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17453 when the current matrix was built. */
17455 static struct glyph_row
*
17456 find_last_unchanged_at_beg_row (struct window
*w
)
17458 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17459 struct glyph_row
*row
;
17460 struct glyph_row
*row_found
= NULL
;
17461 int yb
= window_text_bottom_y (w
);
17463 /* Find the last row displaying unchanged text. */
17464 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17465 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17466 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17469 if (/* If row ends before first_changed_pos, it is unchanged,
17470 except in some case. */
17471 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17472 /* When row ends in ZV and we write at ZV it is not
17474 && !row
->ends_at_zv_p
17475 /* When first_changed_pos is the end of a continued line,
17476 row is not unchanged because it may be no longer
17478 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17479 && (row
->continued_p
17480 || row
->exact_window_width_line_p
))
17481 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17482 needs to be recomputed, so don't consider this row as
17483 unchanged. This happens when the last line was
17484 bidi-reordered and was killed immediately before this
17485 redisplay cycle. In that case, ROW->end stores the
17486 buffer position of the first visual-order character of
17487 the killed text, which is now beyond ZV. */
17488 && CHARPOS (row
->end
.pos
) <= ZV
)
17491 /* Stop if last visible row. */
17492 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17500 /* Find the first glyph row in the current matrix of W that is not
17501 affected by changes at the end of current_buffer since the
17502 time W's current matrix was built.
17504 Return in *DELTA the number of chars by which buffer positions in
17505 unchanged text at the end of current_buffer must be adjusted.
17507 Return in *DELTA_BYTES the corresponding number of bytes.
17509 Value is null if no such row exists, i.e. all rows are affected by
17512 static struct glyph_row
*
17513 find_first_unchanged_at_end_row (struct window
*w
,
17514 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17516 struct glyph_row
*row
;
17517 struct glyph_row
*row_found
= NULL
;
17519 *delta
= *delta_bytes
= 0;
17521 /* Display must not have been paused, otherwise the current matrix
17522 is not up to date. */
17523 eassert (w
->window_end_valid
);
17525 /* A value of window_end_pos >= END_UNCHANGED means that the window
17526 end is in the range of changed text. If so, there is no
17527 unchanged row at the end of W's current matrix. */
17528 if (w
->window_end_pos
>= END_UNCHANGED
)
17531 /* Set row to the last row in W's current matrix displaying text. */
17532 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17534 /* If matrix is entirely empty, no unchanged row exists. */
17535 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17537 /* The value of row is the last glyph row in the matrix having a
17538 meaningful buffer position in it. The end position of row
17539 corresponds to window_end_pos. This allows us to translate
17540 buffer positions in the current matrix to current buffer
17541 positions for characters not in changed text. */
17543 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17544 ptrdiff_t Z_BYTE_old
=
17545 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17546 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17547 struct glyph_row
*first_text_row
17548 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17550 *delta
= Z
- Z_old
;
17551 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17553 /* Set last_unchanged_pos to the buffer position of the last
17554 character in the buffer that has not been changed. Z is the
17555 index + 1 of the last character in current_buffer, i.e. by
17556 subtracting END_UNCHANGED we get the index of the last
17557 unchanged character, and we have to add BEG to get its buffer
17559 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17560 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17562 /* Search backward from ROW for a row displaying a line that
17563 starts at a minimum position >= last_unchanged_pos_old. */
17564 for (; row
> first_text_row
; --row
)
17566 /* This used to abort, but it can happen.
17567 It is ok to just stop the search instead here. KFS. */
17568 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17571 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17576 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17582 /* Make sure that glyph rows in the current matrix of window W
17583 reference the same glyph memory as corresponding rows in the
17584 frame's frame matrix. This function is called after scrolling W's
17585 current matrix on a terminal frame in try_window_id and
17586 try_window_reusing_current_matrix. */
17589 sync_frame_with_window_matrix_rows (struct window
*w
)
17591 struct frame
*f
= XFRAME (w
->frame
);
17592 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17594 /* Preconditions: W must be a leaf window and full-width. Its frame
17595 must have a frame matrix. */
17596 eassert (BUFFERP (w
->contents
));
17597 eassert (WINDOW_FULL_WIDTH_P (w
));
17598 eassert (!FRAME_WINDOW_P (f
));
17600 /* If W is a full-width window, glyph pointers in W's current matrix
17601 have, by definition, to be the same as glyph pointers in the
17602 corresponding frame matrix. Note that frame matrices have no
17603 marginal areas (see build_frame_matrix). */
17604 window_row
= w
->current_matrix
->rows
;
17605 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17606 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17607 while (window_row
< window_row_end
)
17609 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17610 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17612 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17613 frame_row
->glyphs
[TEXT_AREA
] = start
;
17614 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17615 frame_row
->glyphs
[LAST_AREA
] = end
;
17617 /* Disable frame rows whose corresponding window rows have
17618 been disabled in try_window_id. */
17619 if (!window_row
->enabled_p
)
17620 frame_row
->enabled_p
= false;
17622 ++window_row
, ++frame_row
;
17627 /* Find the glyph row in window W containing CHARPOS. Consider all
17628 rows between START and END (not inclusive). END null means search
17629 all rows to the end of the display area of W. Value is the row
17630 containing CHARPOS or null. */
17633 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17634 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17636 struct glyph_row
*row
= start
;
17637 struct glyph_row
*best_row
= NULL
;
17638 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17641 /* If we happen to start on a header-line, skip that. */
17642 if (row
->mode_line_p
)
17645 if ((end
&& row
>= end
) || !row
->enabled_p
)
17648 last_y
= window_text_bottom_y (w
) - dy
;
17652 /* Give up if we have gone too far. */
17653 if (end
&& row
>= end
)
17655 /* This formerly returned if they were equal.
17656 I think that both quantities are of a "last plus one" type;
17657 if so, when they are equal, the row is within the screen. -- rms. */
17658 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17661 /* If it is in this row, return this row. */
17662 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17663 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17664 /* The end position of a row equals the start
17665 position of the next row. If CHARPOS is there, we
17666 would rather consider it displayed in the next
17667 line, except when this line ends in ZV. */
17668 && !row_for_charpos_p (row
, charpos
)))
17669 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17673 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17674 || (!best_row
&& !row
->continued_p
))
17676 /* In bidi-reordered rows, there could be several rows whose
17677 edges surround CHARPOS, all of these rows belonging to
17678 the same continued line. We need to find the row which
17679 fits CHARPOS the best. */
17680 for (g
= row
->glyphs
[TEXT_AREA
];
17681 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17684 if (!STRINGP (g
->object
))
17686 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17688 mindif
= eabs (g
->charpos
- charpos
);
17690 /* Exact match always wins. */
17697 else if (best_row
&& !row
->continued_p
)
17704 /* Try to redisplay window W by reusing its existing display. W's
17705 current matrix must be up to date when this function is called,
17706 i.e. window_end_valid must be nonzero.
17710 >= 1 if successful, i.e. display has been updated
17712 1 means the changes were in front of a newline that precedes
17713 the window start, and the whole current matrix was reused
17714 2 means the changes were after the last position displayed
17715 in the window, and the whole current matrix was reused
17716 3 means portions of the current matrix were reused, while
17717 some of the screen lines were redrawn
17718 -1 if redisplay with same window start is known not to succeed
17719 0 if otherwise unsuccessful
17721 The following steps are performed:
17723 1. Find the last row in the current matrix of W that is not
17724 affected by changes at the start of current_buffer. If no such row
17727 2. Find the first row in W's current matrix that is not affected by
17728 changes at the end of current_buffer. Maybe there is no such row.
17730 3. Display lines beginning with the row + 1 found in step 1 to the
17731 row found in step 2 or, if step 2 didn't find a row, to the end of
17734 4. If cursor is not known to appear on the window, give up.
17736 5. If display stopped at the row found in step 2, scroll the
17737 display and current matrix as needed.
17739 6. Maybe display some lines at the end of W, if we must. This can
17740 happen under various circumstances, like a partially visible line
17741 becoming fully visible, or because newly displayed lines are displayed
17742 in smaller font sizes.
17744 7. Update W's window end information. */
17747 try_window_id (struct window
*w
)
17749 struct frame
*f
= XFRAME (w
->frame
);
17750 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17751 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17752 struct glyph_row
*last_unchanged_at_beg_row
;
17753 struct glyph_row
*first_unchanged_at_end_row
;
17754 struct glyph_row
*row
;
17755 struct glyph_row
*bottom_row
;
17758 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17760 struct text_pos start_pos
;
17762 int first_unchanged_at_end_vpos
= 0;
17763 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17764 struct text_pos start
;
17765 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17768 if (inhibit_try_window_id
)
17772 /* This is handy for debugging. */
17774 #define GIVE_UP(X) \
17776 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17780 #define GIVE_UP(X) return 0
17783 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17785 /* Don't use this for mini-windows because these can show
17786 messages and mini-buffers, and we don't handle that here. */
17787 if (MINI_WINDOW_P (w
))
17790 /* This flag is used to prevent redisplay optimizations. */
17791 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17794 /* This function's optimizations cannot be used if overlays have
17795 changed in the buffer displayed by the window, so give up if they
17797 if (w
->last_overlay_modified
!= OVERLAY_MODIFF
)
17800 /* Verify that narrowing has not changed.
17801 Also verify that we were not told to prevent redisplay optimizations.
17802 It would be nice to further
17803 reduce the number of cases where this prevents try_window_id. */
17804 if (current_buffer
->clip_changed
17805 || current_buffer
->prevent_redisplay_optimizations_p
)
17808 /* Window must either use window-based redisplay or be full width. */
17809 if (!FRAME_WINDOW_P (f
)
17810 && (!FRAME_LINE_INS_DEL_OK (f
)
17811 || !WINDOW_FULL_WIDTH_P (w
)))
17814 /* Give up if point is known NOT to appear in W. */
17815 if (PT
< CHARPOS (start
))
17818 /* Another way to prevent redisplay optimizations. */
17819 if (w
->last_modified
== 0)
17822 /* Verify that window is not hscrolled. */
17823 if (w
->hscroll
!= 0)
17826 /* Verify that display wasn't paused. */
17827 if (!w
->window_end_valid
)
17830 /* Likewise if highlighting trailing whitespace. */
17831 if (!NILP (Vshow_trailing_whitespace
))
17834 /* Can't use this if overlay arrow position and/or string have
17836 if (overlay_arrows_changed_p ())
17839 /* When word-wrap is on, adding a space to the first word of a
17840 wrapped line can change the wrap position, altering the line
17841 above it. It might be worthwhile to handle this more
17842 intelligently, but for now just redisplay from scratch. */
17843 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17846 /* Under bidi reordering, adding or deleting a character in the
17847 beginning of a paragraph, before the first strong directional
17848 character, can change the base direction of the paragraph (unless
17849 the buffer specifies a fixed paragraph direction), which will
17850 require to redisplay the whole paragraph. It might be worthwhile
17851 to find the paragraph limits and widen the range of redisplayed
17852 lines to that, but for now just give up this optimization and
17853 redisplay from scratch. */
17854 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17855 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17858 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17859 only if buffer has really changed. The reason is that the gap is
17860 initially at Z for freshly visited files. The code below would
17861 set end_unchanged to 0 in that case. */
17862 if (MODIFF
> SAVE_MODIFF
17863 /* This seems to happen sometimes after saving a buffer. */
17864 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17866 if (GPT
- BEG
< BEG_UNCHANGED
)
17867 BEG_UNCHANGED
= GPT
- BEG
;
17868 if (Z
- GPT
< END_UNCHANGED
)
17869 END_UNCHANGED
= Z
- GPT
;
17872 /* The position of the first and last character that has been changed. */
17873 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17874 last_changed_charpos
= Z
- END_UNCHANGED
;
17876 /* If window starts after a line end, and the last change is in
17877 front of that newline, then changes don't affect the display.
17878 This case happens with stealth-fontification. Note that although
17879 the display is unchanged, glyph positions in the matrix have to
17880 be adjusted, of course. */
17881 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17882 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17883 && ((last_changed_charpos
< CHARPOS (start
)
17884 && CHARPOS (start
) == BEGV
)
17885 || (last_changed_charpos
< CHARPOS (start
) - 1
17886 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17888 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17889 struct glyph_row
*r0
;
17891 /* Compute how many chars/bytes have been added to or removed
17892 from the buffer. */
17893 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17894 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17895 Z_delta
= Z
- Z_old
;
17896 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17898 /* Give up if PT is not in the window. Note that it already has
17899 been checked at the start of try_window_id that PT is not in
17900 front of the window start. */
17901 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17904 /* If window start is unchanged, we can reuse the whole matrix
17905 as is, after adjusting glyph positions. No need to compute
17906 the window end again, since its offset from Z hasn't changed. */
17907 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17908 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17909 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17910 /* PT must not be in a partially visible line. */
17911 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17912 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17914 /* Adjust positions in the glyph matrix. */
17915 if (Z_delta
|| Z_delta_bytes
)
17917 struct glyph_row
*r1
17918 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17919 increment_matrix_positions (w
->current_matrix
,
17920 MATRIX_ROW_VPOS (r0
, current_matrix
),
17921 MATRIX_ROW_VPOS (r1
, current_matrix
),
17922 Z_delta
, Z_delta_bytes
);
17925 /* Set the cursor. */
17926 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17928 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17933 /* Handle the case that changes are all below what is displayed in
17934 the window, and that PT is in the window. This shortcut cannot
17935 be taken if ZV is visible in the window, and text has been added
17936 there that is visible in the window. */
17937 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17938 /* ZV is not visible in the window, or there are no
17939 changes at ZV, actually. */
17940 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17941 || first_changed_charpos
== last_changed_charpos
))
17943 struct glyph_row
*r0
;
17945 /* Give up if PT is not in the window. Note that it already has
17946 been checked at the start of try_window_id that PT is not in
17947 front of the window start. */
17948 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17951 /* If window start is unchanged, we can reuse the whole matrix
17952 as is, without changing glyph positions since no text has
17953 been added/removed in front of the window end. */
17954 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17955 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17956 /* PT must not be in a partially visible line. */
17957 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17958 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17960 /* We have to compute the window end anew since text
17961 could have been added/removed after it. */
17962 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17963 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17965 /* Set the cursor. */
17966 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17968 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17973 /* Give up if window start is in the changed area.
17975 The condition used to read
17977 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17979 but why that was tested escapes me at the moment. */
17980 if (CHARPOS (start
) >= first_changed_charpos
17981 && CHARPOS (start
) <= last_changed_charpos
)
17984 /* Check that window start agrees with the start of the first glyph
17985 row in its current matrix. Check this after we know the window
17986 start is not in changed text, otherwise positions would not be
17988 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17989 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17992 /* Give up if the window ends in strings. Overlay strings
17993 at the end are difficult to handle, so don't try. */
17994 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17995 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17998 /* Compute the position at which we have to start displaying new
17999 lines. Some of the lines at the top of the window might be
18000 reusable because they are not displaying changed text. Find the
18001 last row in W's current matrix not affected by changes at the
18002 start of current_buffer. Value is null if changes start in the
18003 first line of window. */
18004 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
18005 if (last_unchanged_at_beg_row
)
18007 /* Avoid starting to display in the middle of a character, a TAB
18008 for instance. This is easier than to set up the iterator
18009 exactly, and it's not a frequent case, so the additional
18010 effort wouldn't really pay off. */
18011 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
18012 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
18013 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
18014 --last_unchanged_at_beg_row
;
18016 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
18019 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
18021 start_pos
= it
.current
.pos
;
18023 /* Start displaying new lines in the desired matrix at the same
18024 vpos we would use in the current matrix, i.e. below
18025 last_unchanged_at_beg_row. */
18026 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
18028 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18029 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
18031 eassert (it
.hpos
== 0 && it
.current_x
== 0);
18035 /* There are no reusable lines at the start of the window.
18036 Start displaying in the first text line. */
18037 start_display (&it
, w
, start
);
18038 it
.vpos
= it
.first_vpos
;
18039 start_pos
= it
.current
.pos
;
18042 /* Find the first row that is not affected by changes at the end of
18043 the buffer. Value will be null if there is no unchanged row, in
18044 which case we must redisplay to the end of the window. delta
18045 will be set to the value by which buffer positions beginning with
18046 first_unchanged_at_end_row have to be adjusted due to text
18048 first_unchanged_at_end_row
18049 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
18050 IF_DEBUG (debug_delta
= delta
);
18051 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
18053 /* Set stop_pos to the buffer position up to which we will have to
18054 display new lines. If first_unchanged_at_end_row != NULL, this
18055 is the buffer position of the start of the line displayed in that
18056 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
18057 that we don't stop at a buffer position. */
18059 if (first_unchanged_at_end_row
)
18061 eassert (last_unchanged_at_beg_row
== NULL
18062 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
18064 /* If this is a continuation line, move forward to the next one
18065 that isn't. Changes in lines above affect this line.
18066 Caution: this may move first_unchanged_at_end_row to a row
18067 not displaying text. */
18068 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
18069 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18070 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18071 < it
.last_visible_y
))
18072 ++first_unchanged_at_end_row
;
18074 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
18075 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
18076 >= it
.last_visible_y
))
18077 first_unchanged_at_end_row
= NULL
;
18080 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
18082 first_unchanged_at_end_vpos
18083 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
18084 eassert (stop_pos
>= Z
- END_UNCHANGED
);
18087 else if (last_unchanged_at_beg_row
== NULL
)
18093 /* Either there is no unchanged row at the end, or the one we have
18094 now displays text. This is a necessary condition for the window
18095 end pos calculation at the end of this function. */
18096 eassert (first_unchanged_at_end_row
== NULL
18097 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18099 debug_last_unchanged_at_beg_vpos
18100 = (last_unchanged_at_beg_row
18101 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
18103 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
18105 #endif /* GLYPH_DEBUG */
18108 /* Display new lines. Set last_text_row to the last new line
18109 displayed which has text on it, i.e. might end up as being the
18110 line where the window_end_vpos is. */
18111 w
->cursor
.vpos
= -1;
18112 last_text_row
= NULL
;
18113 overlay_arrow_seen
= 0;
18114 if (it
.current_y
< it
.last_visible_y
18115 && !f
->fonts_changed
18116 && (first_unchanged_at_end_row
== NULL
18117 || IT_CHARPOS (it
) < stop_pos
))
18118 it
.glyph_row
->reversed_p
= false;
18119 while (it
.current_y
< it
.last_visible_y
18120 && !f
->fonts_changed
18121 && (first_unchanged_at_end_row
== NULL
18122 || IT_CHARPOS (it
) < stop_pos
))
18124 if (display_line (&it
))
18125 last_text_row
= it
.glyph_row
- 1;
18128 if (f
->fonts_changed
)
18132 /* Compute differences in buffer positions, y-positions etc. for
18133 lines reused at the bottom of the window. Compute what we can
18135 if (first_unchanged_at_end_row
18136 /* No lines reused because we displayed everything up to the
18137 bottom of the window. */
18138 && it
.current_y
< it
.last_visible_y
)
18141 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
18143 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
18144 run
.current_y
= first_unchanged_at_end_row
->y
;
18145 run
.desired_y
= run
.current_y
+ dy
;
18146 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
18150 delta
= delta_bytes
= dvpos
= dy
18151 = run
.current_y
= run
.desired_y
= run
.height
= 0;
18152 first_unchanged_at_end_row
= NULL
;
18154 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
18157 /* Find the cursor if not already found. We have to decide whether
18158 PT will appear on this window (it sometimes doesn't, but this is
18159 not a very frequent case.) This decision has to be made before
18160 the current matrix is altered. A value of cursor.vpos < 0 means
18161 that PT is either in one of the lines beginning at
18162 first_unchanged_at_end_row or below the window. Don't care for
18163 lines that might be displayed later at the window end; as
18164 mentioned, this is not a frequent case. */
18165 if (w
->cursor
.vpos
< 0)
18167 /* Cursor in unchanged rows at the top? */
18168 if (PT
< CHARPOS (start_pos
)
18169 && last_unchanged_at_beg_row
)
18171 row
= row_containing_pos (w
, PT
,
18172 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
18173 last_unchanged_at_beg_row
+ 1, 0);
18175 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
18178 /* Start from first_unchanged_at_end_row looking for PT. */
18179 else if (first_unchanged_at_end_row
)
18181 row
= row_containing_pos (w
, PT
- delta
,
18182 first_unchanged_at_end_row
, NULL
, 0);
18184 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
18185 delta_bytes
, dy
, dvpos
);
18188 /* Give up if cursor was not found. */
18189 if (w
->cursor
.vpos
< 0)
18191 clear_glyph_matrix (w
->desired_matrix
);
18196 /* Don't let the cursor end in the scroll margins. */
18198 int this_scroll_margin
, cursor_height
;
18199 int frame_line_height
= default_line_pixel_height (w
);
18200 int window_total_lines
18201 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
18203 this_scroll_margin
=
18204 max (0, min (scroll_margin
, window_total_lines
/ 4));
18205 this_scroll_margin
*= frame_line_height
;
18206 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
18208 if ((w
->cursor
.y
< this_scroll_margin
18209 && CHARPOS (start
) > BEGV
)
18210 /* Old redisplay didn't take scroll margin into account at the bottom,
18211 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
18212 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
18213 ? cursor_height
+ this_scroll_margin
18214 : 1)) > it
.last_visible_y
)
18216 w
->cursor
.vpos
= -1;
18217 clear_glyph_matrix (w
->desired_matrix
);
18222 /* Scroll the display. Do it before changing the current matrix so
18223 that xterm.c doesn't get confused about where the cursor glyph is
18225 if (dy
&& run
.height
)
18229 if (FRAME_WINDOW_P (f
))
18231 FRAME_RIF (f
)->update_window_begin_hook (w
);
18232 FRAME_RIF (f
)->clear_window_mouse_face (w
);
18233 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
18234 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
18238 /* Terminal frame. In this case, dvpos gives the number of
18239 lines to scroll by; dvpos < 0 means scroll up. */
18241 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
18242 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
18243 int end
= (WINDOW_TOP_EDGE_LINE (w
)
18244 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
18245 + window_internal_height (w
));
18247 #if defined (HAVE_GPM) || defined (MSDOS)
18248 x_clear_window_mouse_face (w
);
18250 /* Perform the operation on the screen. */
18253 /* Scroll last_unchanged_at_beg_row to the end of the
18254 window down dvpos lines. */
18255 set_terminal_window (f
, end
);
18257 /* On dumb terminals delete dvpos lines at the end
18258 before inserting dvpos empty lines. */
18259 if (!FRAME_SCROLL_REGION_OK (f
))
18260 ins_del_lines (f
, end
- dvpos
, -dvpos
);
18262 /* Insert dvpos empty lines in front of
18263 last_unchanged_at_beg_row. */
18264 ins_del_lines (f
, from
, dvpos
);
18266 else if (dvpos
< 0)
18268 /* Scroll up last_unchanged_at_beg_vpos to the end of
18269 the window to last_unchanged_at_beg_vpos - |dvpos|. */
18270 set_terminal_window (f
, end
);
18272 /* Delete dvpos lines in front of
18273 last_unchanged_at_beg_vpos. ins_del_lines will set
18274 the cursor to the given vpos and emit |dvpos| delete
18276 ins_del_lines (f
, from
+ dvpos
, dvpos
);
18278 /* On a dumb terminal insert dvpos empty lines at the
18280 if (!FRAME_SCROLL_REGION_OK (f
))
18281 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
18284 set_terminal_window (f
, 0);
18290 /* Shift reused rows of the current matrix to the right position.
18291 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
18293 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
18294 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
18297 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
18298 bottom_vpos
, dvpos
);
18299 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
18302 else if (dvpos
> 0)
18304 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
18305 bottom_vpos
, dvpos
);
18306 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
18307 first_unchanged_at_end_vpos
+ dvpos
);
18310 /* For frame-based redisplay, make sure that current frame and window
18311 matrix are in sync with respect to glyph memory. */
18312 if (!FRAME_WINDOW_P (f
))
18313 sync_frame_with_window_matrix_rows (w
);
18315 /* Adjust buffer positions in reused rows. */
18316 if (delta
|| delta_bytes
)
18317 increment_matrix_positions (current_matrix
,
18318 first_unchanged_at_end_vpos
+ dvpos
,
18319 bottom_vpos
, delta
, delta_bytes
);
18321 /* Adjust Y positions. */
18323 shift_glyph_matrix (w
, current_matrix
,
18324 first_unchanged_at_end_vpos
+ dvpos
,
18327 if (first_unchanged_at_end_row
)
18329 first_unchanged_at_end_row
+= dvpos
;
18330 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
18331 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
18332 first_unchanged_at_end_row
= NULL
;
18335 /* If scrolling up, there may be some lines to display at the end of
18337 last_text_row_at_end
= NULL
;
18340 /* Scrolling up can leave for example a partially visible line
18341 at the end of the window to be redisplayed. */
18342 /* Set last_row to the glyph row in the current matrix where the
18343 window end line is found. It has been moved up or down in
18344 the matrix by dvpos. */
18345 int last_vpos
= w
->window_end_vpos
+ dvpos
;
18346 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
18348 /* If last_row is the window end line, it should display text. */
18349 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
18351 /* If window end line was partially visible before, begin
18352 displaying at that line. Otherwise begin displaying with the
18353 line following it. */
18354 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
18356 init_to_row_start (&it
, w
, last_row
);
18357 it
.vpos
= last_vpos
;
18358 it
.current_y
= last_row
->y
;
18362 init_to_row_end (&it
, w
, last_row
);
18363 it
.vpos
= 1 + last_vpos
;
18364 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
18368 /* We may start in a continuation line. If so, we have to
18369 get the right continuation_lines_width and current_x. */
18370 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
18371 it
.hpos
= it
.current_x
= 0;
18373 /* Display the rest of the lines at the window end. */
18374 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18375 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
18377 /* Is it always sure that the display agrees with lines in
18378 the current matrix? I don't think so, so we mark rows
18379 displayed invalid in the current matrix by setting their
18380 enabled_p flag to zero. */
18381 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
18382 if (display_line (&it
))
18383 last_text_row_at_end
= it
.glyph_row
- 1;
18387 /* Update window_end_pos and window_end_vpos. */
18388 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
18390 /* Window end line if one of the preserved rows from the current
18391 matrix. Set row to the last row displaying text in current
18392 matrix starting at first_unchanged_at_end_row, after
18394 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18395 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
18396 first_unchanged_at_end_row
);
18397 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
18398 adjust_window_ends (w
, row
, 1);
18399 eassert (w
->window_end_bytepos
>= 0);
18400 IF_DEBUG (debug_method_add (w
, "A"));
18402 else if (last_text_row_at_end
)
18404 adjust_window_ends (w
, last_text_row_at_end
, 0);
18405 eassert (w
->window_end_bytepos
>= 0);
18406 IF_DEBUG (debug_method_add (w
, "B"));
18408 else if (last_text_row
)
18410 /* We have displayed either to the end of the window or at the
18411 end of the window, i.e. the last row with text is to be found
18412 in the desired matrix. */
18413 adjust_window_ends (w
, last_text_row
, 0);
18414 eassert (w
->window_end_bytepos
>= 0);
18416 else if (first_unchanged_at_end_row
== NULL
18417 && last_text_row
== NULL
18418 && last_text_row_at_end
== NULL
)
18420 /* Displayed to end of window, but no line containing text was
18421 displayed. Lines were deleted at the end of the window. */
18422 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
18423 int vpos
= w
->window_end_vpos
;
18424 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
18425 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18428 row
== NULL
&& vpos
>= first_vpos
;
18429 --vpos
, --current_row
, --desired_row
)
18431 if (desired_row
->enabled_p
)
18433 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18436 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18440 eassert (row
!= NULL
);
18441 w
->window_end_vpos
= vpos
+ 1;
18442 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18443 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18444 eassert (w
->window_end_bytepos
>= 0);
18445 IF_DEBUG (debug_method_add (w
, "C"));
18450 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18451 debug_end_vpos
= w
->window_end_vpos
));
18453 /* Record that display has not been completed. */
18454 w
->window_end_valid
= 0;
18455 w
->desired_matrix
->no_scrolling_p
= 1;
18463 /***********************************************************************
18464 More debugging support
18465 ***********************************************************************/
18469 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18470 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18471 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18474 /* Dump the contents of glyph matrix MATRIX on stderr.
18476 GLYPHS 0 means don't show glyph contents.
18477 GLYPHS 1 means show glyphs in short form
18478 GLYPHS > 1 means show glyphs in long form. */
18481 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18484 for (i
= 0; i
< matrix
->nrows
; ++i
)
18485 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18489 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18490 the glyph row and area where the glyph comes from. */
18493 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18495 if (glyph
->type
== CHAR_GLYPH
18496 || glyph
->type
== GLYPHLESS_GLYPH
)
18499 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18500 glyph
- row
->glyphs
[TEXT_AREA
],
18501 (glyph
->type
== CHAR_GLYPH
18505 (BUFFERP (glyph
->object
)
18507 : (STRINGP (glyph
->object
)
18509 : (INTEGERP (glyph
->object
)
18512 glyph
->pixel_width
,
18514 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18518 glyph
->left_box_line_p
,
18519 glyph
->right_box_line_p
);
18521 else if (glyph
->type
== STRETCH_GLYPH
)
18524 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18525 glyph
- row
->glyphs
[TEXT_AREA
],
18528 (BUFFERP (glyph
->object
)
18530 : (STRINGP (glyph
->object
)
18532 : (INTEGERP (glyph
->object
)
18535 glyph
->pixel_width
,
18539 glyph
->left_box_line_p
,
18540 glyph
->right_box_line_p
);
18542 else if (glyph
->type
== IMAGE_GLYPH
)
18545 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18546 glyph
- row
->glyphs
[TEXT_AREA
],
18549 (BUFFERP (glyph
->object
)
18551 : (STRINGP (glyph
->object
)
18553 : (INTEGERP (glyph
->object
)
18556 glyph
->pixel_width
,
18560 glyph
->left_box_line_p
,
18561 glyph
->right_box_line_p
);
18563 else if (glyph
->type
== COMPOSITE_GLYPH
)
18566 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18567 glyph
- row
->glyphs
[TEXT_AREA
],
18570 (BUFFERP (glyph
->object
)
18572 : (STRINGP (glyph
->object
)
18574 : (INTEGERP (glyph
->object
)
18577 glyph
->pixel_width
,
18579 if (glyph
->u
.cmp
.automatic
)
18582 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18583 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18585 glyph
->left_box_line_p
,
18586 glyph
->right_box_line_p
);
18591 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18592 GLYPHS 0 means don't show glyph contents.
18593 GLYPHS 1 means show glyphs in short form
18594 GLYPHS > 1 means show glyphs in long form. */
18597 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18601 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18602 fprintf (stderr
, "==============================================================================\n");
18604 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18605 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18607 MATRIX_ROW_START_CHARPOS (row
),
18608 MATRIX_ROW_END_CHARPOS (row
),
18609 row
->used
[TEXT_AREA
],
18610 row
->contains_overlapping_glyphs_p
,
18612 row
->truncated_on_left_p
,
18613 row
->truncated_on_right_p
,
18615 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18616 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18619 row
->ends_in_middle_of_char_p
,
18620 row
->starts_in_middle_of_char_p
,
18626 row
->visible_height
,
18629 /* The next 3 lines should align to "Start" in the header. */
18630 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18631 row
->end
.overlay_string_index
,
18632 row
->continuation_lines_width
);
18633 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18634 CHARPOS (row
->start
.string_pos
),
18635 CHARPOS (row
->end
.string_pos
));
18636 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18637 row
->end
.dpvec_index
);
18644 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18646 struct glyph
*glyph
= row
->glyphs
[area
];
18647 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18649 /* Glyph for a line end in text. */
18650 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18653 if (glyph
< glyph_end
)
18654 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18656 for (; glyph
< glyph_end
; ++glyph
)
18657 dump_glyph (row
, glyph
, area
);
18660 else if (glyphs
== 1)
18663 char s
[SHRT_MAX
+ 4];
18665 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18669 for (i
= 0; i
< row
->used
[area
]; ++i
)
18671 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18672 if (i
== row
->used
[area
] - 1
18673 && area
== TEXT_AREA
18674 && INTEGERP (glyph
->object
)
18675 && glyph
->type
== CHAR_GLYPH
18676 && glyph
->u
.ch
== ' ')
18678 strcpy (&s
[i
], "[\\n]");
18681 else if (glyph
->type
== CHAR_GLYPH
18682 && glyph
->u
.ch
< 0x80
18683 && glyph
->u
.ch
>= ' ')
18684 s
[i
] = glyph
->u
.ch
;
18690 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18696 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18697 Sdump_glyph_matrix
, 0, 1, "p",
18698 doc
: /* Dump the current matrix of the selected window to stderr.
18699 Shows contents of glyph row structures. With non-nil
18700 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18701 glyphs in short form, otherwise show glyphs in long form.
18703 Interactively, no argument means show glyphs in short form;
18704 with numeric argument, its value is passed as the GLYPHS flag. */)
18705 (Lisp_Object glyphs
)
18707 struct window
*w
= XWINDOW (selected_window
);
18708 struct buffer
*buffer
= XBUFFER (w
->contents
);
18710 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18711 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18712 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18713 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18714 fprintf (stderr
, "=============================================\n");
18715 dump_glyph_matrix (w
->current_matrix
,
18716 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18721 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18722 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* Dump the current glyph matrix of the selected frame to stderr.
18723 Only text-mode frames have frame glyph matrices. */)
18726 struct frame
*f
= XFRAME (selected_frame
);
18728 if (f
->current_matrix
)
18729 dump_glyph_matrix (f
->current_matrix
, 1);
18731 fprintf (stderr
, "*** This frame doesn't have a frame glyph matrix ***\n");
18736 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18737 doc
: /* Dump glyph row ROW to stderr.
18738 GLYPH 0 means don't dump glyphs.
18739 GLYPH 1 means dump glyphs in short form.
18740 GLYPH > 1 or omitted means dump glyphs in long form. */)
18741 (Lisp_Object row
, Lisp_Object glyphs
)
18743 struct glyph_matrix
*matrix
;
18746 CHECK_NUMBER (row
);
18747 matrix
= XWINDOW (selected_window
)->current_matrix
;
18749 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18750 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18752 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18757 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18758 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18759 GLYPH 0 means don't dump glyphs.
18760 GLYPH 1 means dump glyphs in short form.
18761 GLYPH > 1 or omitted means dump glyphs in long form.
18763 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18765 (Lisp_Object row
, Lisp_Object glyphs
)
18767 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18768 struct frame
*sf
= SELECTED_FRAME ();
18769 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18772 CHECK_NUMBER (row
);
18774 if (vpos
>= 0 && vpos
< m
->nrows
)
18775 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18776 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18782 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18783 doc
: /* Toggle tracing of redisplay.
18784 With ARG, turn tracing on if and only if ARG is positive. */)
18788 trace_redisplay_p
= !trace_redisplay_p
;
18791 arg
= Fprefix_numeric_value (arg
);
18792 trace_redisplay_p
= XINT (arg
) > 0;
18799 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18800 doc
: /* Like `format', but print result to stderr.
18801 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18802 (ptrdiff_t nargs
, Lisp_Object
*args
)
18804 Lisp_Object s
= Fformat (nargs
, args
);
18805 fprintf (stderr
, "%s", SDATA (s
));
18809 #endif /* GLYPH_DEBUG */
18813 /***********************************************************************
18814 Building Desired Matrix Rows
18815 ***********************************************************************/
18817 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18818 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18820 static struct glyph_row
*
18821 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18823 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18824 struct buffer
*buffer
= XBUFFER (w
->contents
);
18825 struct buffer
*old
= current_buffer
;
18826 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18827 ptrdiff_t arrow_len
= SCHARS (overlay_arrow_string
);
18828 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18829 const unsigned char *p
;
18832 int n_glyphs_before
;
18834 set_buffer_temp (buffer
);
18835 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18836 scratch_glyph_row
.reversed_p
= false;
18837 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18838 SET_TEXT_POS (it
.position
, 0, 0);
18840 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18842 while (p
< arrow_end
)
18844 Lisp_Object face
, ilisp
;
18846 /* Get the next character. */
18848 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18851 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18852 if (! ASCII_CHAR_P (it
.c
))
18853 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18857 /* Get its face. */
18858 ilisp
= make_number (p
- arrow_string
);
18859 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18860 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18862 /* Compute its width, get its glyphs. */
18863 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18864 SET_TEXT_POS (it
.position
, -1, -1);
18865 PRODUCE_GLYPHS (&it
);
18867 /* If this character doesn't fit any more in the line, we have
18868 to remove some glyphs. */
18869 if (it
.current_x
> it
.last_visible_x
)
18871 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18876 set_buffer_temp (old
);
18877 return it
.glyph_row
;
18881 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18882 glyphs to insert is determined by produce_special_glyphs. */
18885 insert_left_trunc_glyphs (struct it
*it
)
18887 struct it truncate_it
;
18888 struct glyph
*from
, *end
, *to
, *toend
;
18890 eassert (!FRAME_WINDOW_P (it
->f
)
18891 || (!it
->glyph_row
->reversed_p
18892 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18893 || (it
->glyph_row
->reversed_p
18894 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18896 /* Get the truncation glyphs. */
18898 truncate_it
.current_x
= 0;
18899 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18900 truncate_it
.glyph_row
= &scratch_glyph_row
;
18901 truncate_it
.area
= TEXT_AREA
;
18902 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18903 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18904 truncate_it
.object
= make_number (0);
18905 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18907 /* Overwrite glyphs from IT with truncation glyphs. */
18908 if (!it
->glyph_row
->reversed_p
)
18910 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18912 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18913 end
= from
+ tused
;
18914 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18915 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18916 if (FRAME_WINDOW_P (it
->f
))
18918 /* On GUI frames, when variable-size fonts are displayed,
18919 the truncation glyphs may need more pixels than the row's
18920 glyphs they overwrite. We overwrite more glyphs to free
18921 enough screen real estate, and enlarge the stretch glyph
18922 on the right (see display_line), if there is one, to
18923 preserve the screen position of the truncation glyphs on
18926 struct glyph
*g
= to
;
18929 /* The first glyph could be partially visible, in which case
18930 it->glyph_row->x will be negative. But we want the left
18931 truncation glyphs to be aligned at the left margin of the
18932 window, so we override the x coordinate at which the row
18934 it
->glyph_row
->x
= 0;
18935 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18937 w
+= g
->pixel_width
;
18940 if (g
- to
- tused
> 0)
18942 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18943 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18945 used
= it
->glyph_row
->used
[TEXT_AREA
];
18946 if (it
->glyph_row
->truncated_on_right_p
18947 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18948 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18951 int extra
= w
- it
->truncation_pixel_width
;
18953 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18960 /* There may be padding glyphs left over. Overwrite them too. */
18961 if (!FRAME_WINDOW_P (it
->f
))
18963 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18965 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18972 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18976 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18978 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18979 that back to front. */
18980 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18981 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18982 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18983 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18984 if (FRAME_WINDOW_P (it
->f
))
18987 struct glyph
*g
= to
;
18989 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18991 w
+= g
->pixel_width
;
18994 if (to
- g
- tused
> 0)
18996 if (it
->glyph_row
->truncated_on_right_p
18997 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18998 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
19000 int extra
= w
- it
->truncation_pixel_width
;
19002 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
19006 while (from
>= end
&& to
>= toend
)
19008 if (!FRAME_WINDOW_P (it
->f
))
19010 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
19013 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
19014 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
19015 while (from
>= end
&& to
>= toend
)
19021 /* Need to free some room before prepending additional
19023 int move_by
= from
- end
+ 1;
19024 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19025 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
19027 for ( ; g
>= g0
; g
--)
19029 while (from
>= end
)
19031 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
19036 /* Compute the hash code for ROW. */
19038 row_hash (struct glyph_row
*row
)
19041 unsigned hashval
= 0;
19043 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
19044 for (k
= 0; k
< row
->used
[area
]; ++k
)
19045 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
19046 + row
->glyphs
[area
][k
].u
.val
19047 + row
->glyphs
[area
][k
].face_id
19048 + row
->glyphs
[area
][k
].padding_p
19049 + (row
->glyphs
[area
][k
].type
<< 2));
19054 /* Compute the pixel height and width of IT->glyph_row.
19056 Most of the time, ascent and height of a display line will be equal
19057 to the max_ascent and max_height values of the display iterator
19058 structure. This is not the case if
19060 1. We hit ZV without displaying anything. In this case, max_ascent
19061 and max_height will be zero.
19063 2. We have some glyphs that don't contribute to the line height.
19064 (The glyph row flag contributes_to_line_height_p is for future
19065 pixmap extensions).
19067 The first case is easily covered by using default values because in
19068 these cases, the line height does not really matter, except that it
19069 must not be zero. */
19072 compute_line_metrics (struct it
*it
)
19074 struct glyph_row
*row
= it
->glyph_row
;
19076 if (FRAME_WINDOW_P (it
->f
))
19078 int i
, min_y
, max_y
;
19080 /* The line may consist of one space only, that was added to
19081 place the cursor on it. If so, the row's height hasn't been
19083 if (row
->height
== 0)
19085 if (it
->max_ascent
+ it
->max_descent
== 0)
19086 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
19087 row
->ascent
= it
->max_ascent
;
19088 row
->height
= it
->max_ascent
+ it
->max_descent
;
19089 row
->phys_ascent
= it
->max_phys_ascent
;
19090 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19091 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19094 /* Compute the width of this line. */
19095 row
->pixel_width
= row
->x
;
19096 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
19097 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
19099 eassert (row
->pixel_width
>= 0);
19100 eassert (row
->ascent
>= 0 && row
->height
> 0);
19102 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
19103 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
19105 /* If first line's physical ascent is larger than its logical
19106 ascent, use the physical ascent, and make the row taller.
19107 This makes accented characters fully visible. */
19108 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
19109 && row
->phys_ascent
> row
->ascent
)
19111 row
->height
+= row
->phys_ascent
- row
->ascent
;
19112 row
->ascent
= row
->phys_ascent
;
19115 /* Compute how much of the line is visible. */
19116 row
->visible_height
= row
->height
;
19118 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
19119 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
19121 if (row
->y
< min_y
)
19122 row
->visible_height
-= min_y
- row
->y
;
19123 if (row
->y
+ row
->height
> max_y
)
19124 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
19128 row
->pixel_width
= row
->used
[TEXT_AREA
];
19129 if (row
->continued_p
)
19130 row
->pixel_width
-= it
->continuation_pixel_width
;
19131 else if (row
->truncated_on_right_p
)
19132 row
->pixel_width
-= it
->truncation_pixel_width
;
19133 row
->ascent
= row
->phys_ascent
= 0;
19134 row
->height
= row
->phys_height
= row
->visible_height
= 1;
19135 row
->extra_line_spacing
= 0;
19138 /* Compute a hash code for this row. */
19139 row
->hash
= row_hash (row
);
19141 it
->max_ascent
= it
->max_descent
= 0;
19142 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
19146 /* Append one space to the glyph row of iterator IT if doing a
19147 window-based redisplay. The space has the same face as
19148 IT->face_id. Value is non-zero if a space was added.
19150 This function is called to make sure that there is always one glyph
19151 at the end of a glyph row that the cursor can be set on under
19152 window-systems. (If there weren't such a glyph we would not know
19153 how wide and tall a box cursor should be displayed).
19155 At the same time this space let's a nicely handle clearing to the
19156 end of the line if the row ends in italic text. */
19159 append_space_for_newline (struct it
*it
, int default_face_p
)
19161 if (FRAME_WINDOW_P (it
->f
))
19163 int n
= it
->glyph_row
->used
[TEXT_AREA
];
19165 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
19166 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
19168 /* Save some values that must not be changed.
19169 Must save IT->c and IT->len because otherwise
19170 ITERATOR_AT_END_P wouldn't work anymore after
19171 append_space_for_newline has been called. */
19172 enum display_element_type saved_what
= it
->what
;
19173 int saved_c
= it
->c
, saved_len
= it
->len
;
19174 int saved_char_to_display
= it
->char_to_display
;
19175 int saved_x
= it
->current_x
;
19176 int saved_face_id
= it
->face_id
;
19177 int saved_box_end
= it
->end_of_box_run_p
;
19178 struct text_pos saved_pos
;
19179 Lisp_Object saved_object
;
19182 saved_object
= it
->object
;
19183 saved_pos
= it
->position
;
19185 it
->what
= IT_CHARACTER
;
19186 memset (&it
->position
, 0, sizeof it
->position
);
19187 it
->object
= make_number (0);
19188 it
->c
= it
->char_to_display
= ' ';
19191 /* If the default face was remapped, be sure to use the
19192 remapped face for the appended newline. */
19193 if (default_face_p
)
19194 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
19195 else if (it
->face_before_selective_p
)
19196 it
->face_id
= it
->saved_face_id
;
19197 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
19198 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
19199 /* In R2L rows, we will prepend a stretch glyph that will
19200 have the end_of_box_run_p flag set for it, so there's no
19201 need for the appended newline glyph to have that flag
19203 if (it
->glyph_row
->reversed_p
19204 /* But if the appended newline glyph goes all the way to
19205 the end of the row, there will be no stretch glyph,
19206 so leave the box flag set. */
19207 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
19208 it
->end_of_box_run_p
= 0;
19210 PRODUCE_GLYPHS (it
);
19212 it
->override_ascent
= -1;
19213 it
->constrain_row_ascent_descent_p
= 0;
19214 it
->current_x
= saved_x
;
19215 it
->object
= saved_object
;
19216 it
->position
= saved_pos
;
19217 it
->what
= saved_what
;
19218 it
->face_id
= saved_face_id
;
19219 it
->len
= saved_len
;
19221 it
->char_to_display
= saved_char_to_display
;
19222 it
->end_of_box_run_p
= saved_box_end
;
19231 /* Extend the face of the last glyph in the text area of IT->glyph_row
19232 to the end of the display line. Called from display_line. If the
19233 glyph row is empty, add a space glyph to it so that we know the
19234 face to draw. Set the glyph row flag fill_line_p. If the glyph
19235 row is R2L, prepend a stretch glyph to cover the empty space to the
19236 left of the leftmost glyph. */
19239 extend_face_to_end_of_line (struct it
*it
)
19241 struct face
*face
, *default_face
;
19242 struct frame
*f
= it
->f
;
19244 /* If line is already filled, do nothing. Non window-system frames
19245 get a grace of one more ``pixel'' because their characters are
19246 1-``pixel'' wide, so they hit the equality too early. This grace
19247 is needed only for R2L rows that are not continued, to produce
19248 one extra blank where we could display the cursor. */
19249 if ((it
->current_x
>= it
->last_visible_x
19250 + (!FRAME_WINDOW_P (f
)
19251 && it
->glyph_row
->reversed_p
19252 && !it
->glyph_row
->continued_p
))
19253 /* If the window has display margins, we will need to extend
19254 their face even if the text area is filled. */
19255 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19256 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
19259 /* The default face, possibly remapped. */
19260 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
19262 /* Face extension extends the background and box of IT->face_id
19263 to the end of the line. If the background equals the background
19264 of the frame, we don't have to do anything. */
19265 if (it
->face_before_selective_p
)
19266 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
19268 face
= FACE_FROM_ID (f
, it
->face_id
);
19270 if (FRAME_WINDOW_P (f
)
19271 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
19272 && face
->box
== FACE_NO_BOX
19273 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
19274 #ifdef HAVE_WINDOW_SYSTEM
19277 && !it
->glyph_row
->reversed_p
)
19280 /* Set the glyph row flag indicating that the face of the last glyph
19281 in the text area has to be drawn to the end of the text area. */
19282 it
->glyph_row
->fill_line_p
= 1;
19284 /* If current character of IT is not ASCII, make sure we have the
19285 ASCII face. This will be automatically undone the next time
19286 get_next_display_element returns a multibyte character. Note
19287 that the character will always be single byte in unibyte
19289 if (!ASCII_CHAR_P (it
->c
))
19291 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
19294 if (FRAME_WINDOW_P (f
))
19296 /* If the row is empty, add a space with the current face of IT,
19297 so that we know which face to draw. */
19298 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
19300 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
19301 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
19302 it
->glyph_row
->used
[TEXT_AREA
] = 1;
19304 /* Mode line and the header line don't have margins, and
19305 likewise the frame's tool-bar window, if there is any. */
19306 if (!(it
->glyph_row
->mode_line_p
19307 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
19308 || (WINDOWP (f
->tool_bar_window
)
19309 && it
->w
== XWINDOW (f
->tool_bar_window
))
19313 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19314 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
19316 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
19317 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
=
19319 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
19321 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19322 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
19324 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
19325 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
=
19327 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
19330 #ifdef HAVE_WINDOW_SYSTEM
19331 if (it
->glyph_row
->reversed_p
)
19333 /* Prepend a stretch glyph to the row, such that the
19334 rightmost glyph will be drawn flushed all the way to the
19335 right margin of the window. The stretch glyph that will
19336 occupy the empty space, if any, to the left of the
19338 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
19339 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
19340 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
19342 int row_width
, stretch_ascent
, stretch_width
;
19343 struct text_pos saved_pos
;
19344 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
19346 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
19347 row_width
+= g
->pixel_width
;
19349 /* FIXME: There are various minor display glitches in R2L
19350 rows when only one of the fringes is missing. The
19351 strange condition below produces the least bad effect. */
19352 if ((WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
19353 == (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0)
19354 || WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) != 0)
19355 stretch_width
= window_box_width (it
->w
, TEXT_AREA
);
19357 stretch_width
= it
->last_visible_x
- it
->first_visible_x
;
19358 stretch_width
-= row_width
;
19360 if (stretch_width
> 0)
19363 (((it
->ascent
+ it
->descent
)
19364 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
19365 saved_pos
= it
->position
;
19366 memset (&it
->position
, 0, sizeof it
->position
);
19367 saved_avoid_cursor
= it
->avoid_cursor_p
;
19368 it
->avoid_cursor_p
= 1;
19369 saved_face_id
= it
->face_id
;
19370 saved_box_start
= it
->start_of_box_run_p
;
19371 /* The last row's stretch glyph should get the default
19372 face, to avoid painting the rest of the window with
19373 the region face, if the region ends at ZV. */
19374 if (it
->glyph_row
->ends_at_zv_p
)
19375 it
->face_id
= default_face
->id
;
19377 it
->face_id
= face
->id
;
19378 it
->start_of_box_run_p
= 0;
19379 append_stretch_glyph (it
, make_number (0), stretch_width
,
19380 it
->ascent
+ it
->descent
, stretch_ascent
);
19381 it
->position
= saved_pos
;
19382 it
->avoid_cursor_p
= saved_avoid_cursor
;
19383 it
->face_id
= saved_face_id
;
19384 it
->start_of_box_run_p
= saved_box_start
;
19386 /* If stretch_width comes out negative, it means that the
19387 last glyph is only partially visible. In R2L rows, we
19388 want the leftmost glyph to be partially visible, so we
19389 need to give the row the corresponding left offset. */
19390 if (stretch_width
< 0)
19391 it
->glyph_row
->x
= stretch_width
;
19393 #endif /* HAVE_WINDOW_SYSTEM */
19397 /* Save some values that must not be changed. */
19398 int saved_x
= it
->current_x
;
19399 struct text_pos saved_pos
;
19400 Lisp_Object saved_object
;
19401 enum display_element_type saved_what
= it
->what
;
19402 int saved_face_id
= it
->face_id
;
19404 saved_object
= it
->object
;
19405 saved_pos
= it
->position
;
19407 it
->what
= IT_CHARACTER
;
19408 memset (&it
->position
, 0, sizeof it
->position
);
19409 it
->object
= make_number (0);
19410 it
->c
= it
->char_to_display
= ' ';
19413 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19414 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19415 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19416 && !it
->glyph_row
->mode_line_p
19417 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19419 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
19420 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
19422 for (it
->current_x
= 0; g
< e
; g
++)
19423 it
->current_x
+= g
->pixel_width
;
19425 it
->area
= LEFT_MARGIN_AREA
;
19426 it
->face_id
= default_face
->id
;
19427 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19428 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19430 PRODUCE_GLYPHS (it
);
19431 /* term.c:produce_glyphs advances it->current_x only for
19433 it
->current_x
+= it
->pixel_width
;
19436 it
->current_x
= saved_x
;
19437 it
->area
= TEXT_AREA
;
19440 /* The last row's blank glyphs should get the default face, to
19441 avoid painting the rest of the window with the region face,
19442 if the region ends at ZV. */
19443 if (it
->glyph_row
->ends_at_zv_p
)
19444 it
->face_id
= default_face
->id
;
19446 it
->face_id
= face
->id
;
19447 PRODUCE_GLYPHS (it
);
19449 while (it
->current_x
<= it
->last_visible_x
)
19450 PRODUCE_GLYPHS (it
);
19452 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19453 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19454 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19455 && !it
->glyph_row
->mode_line_p
19456 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19458 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
19459 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19461 for ( ; g
< e
; g
++)
19462 it
->current_x
+= g
->pixel_width
;
19464 it
->area
= RIGHT_MARGIN_AREA
;
19465 it
->face_id
= default_face
->id
;
19466 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19467 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19469 PRODUCE_GLYPHS (it
);
19470 it
->current_x
+= it
->pixel_width
;
19473 it
->area
= TEXT_AREA
;
19476 /* Don't count these blanks really. It would let us insert a left
19477 truncation glyph below and make us set the cursor on them, maybe. */
19478 it
->current_x
= saved_x
;
19479 it
->object
= saved_object
;
19480 it
->position
= saved_pos
;
19481 it
->what
= saved_what
;
19482 it
->face_id
= saved_face_id
;
19487 /* Value is non-zero if text starting at CHARPOS in current_buffer is
19488 trailing whitespace. */
19491 trailing_whitespace_p (ptrdiff_t charpos
)
19493 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19496 while (bytepos
< ZV_BYTE
19497 && (c
= FETCH_CHAR (bytepos
),
19498 c
== ' ' || c
== '\t'))
19501 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19503 if (bytepos
!= PT_BYTE
)
19510 /* Highlight trailing whitespace, if any, in ROW. */
19513 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19515 int used
= row
->used
[TEXT_AREA
];
19519 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19520 struct glyph
*glyph
= start
+ used
- 1;
19522 if (row
->reversed_p
)
19524 /* Right-to-left rows need to be processed in the opposite
19525 direction, so swap the edge pointers. */
19527 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19530 /* Skip over glyphs inserted to display the cursor at the
19531 end of a line, for extending the face of the last glyph
19532 to the end of the line on terminals, and for truncation
19533 and continuation glyphs. */
19534 if (!row
->reversed_p
)
19536 while (glyph
>= start
19537 && glyph
->type
== CHAR_GLYPH
19538 && INTEGERP (glyph
->object
))
19543 while (glyph
<= start
19544 && glyph
->type
== CHAR_GLYPH
19545 && INTEGERP (glyph
->object
))
19549 /* If last glyph is a space or stretch, and it's trailing
19550 whitespace, set the face of all trailing whitespace glyphs in
19551 IT->glyph_row to `trailing-whitespace'. */
19552 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19553 && BUFFERP (glyph
->object
)
19554 && (glyph
->type
== STRETCH_GLYPH
19555 || (glyph
->type
== CHAR_GLYPH
19556 && glyph
->u
.ch
== ' '))
19557 && trailing_whitespace_p (glyph
->charpos
))
19559 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
19563 if (!row
->reversed_p
)
19565 while (glyph
>= start
19566 && BUFFERP (glyph
->object
)
19567 && (glyph
->type
== STRETCH_GLYPH
19568 || (glyph
->type
== CHAR_GLYPH
19569 && glyph
->u
.ch
== ' ')))
19570 (glyph
--)->face_id
= face_id
;
19574 while (glyph
<= start
19575 && BUFFERP (glyph
->object
)
19576 && (glyph
->type
== STRETCH_GLYPH
19577 || (glyph
->type
== CHAR_GLYPH
19578 && glyph
->u
.ch
== ' ')))
19579 (glyph
++)->face_id
= face_id
;
19586 /* Value is non-zero if glyph row ROW should be
19587 considered to hold the buffer position CHARPOS. */
19590 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19594 if (charpos
== CHARPOS (row
->end
.pos
)
19595 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19597 /* Suppose the row ends on a string.
19598 Unless the row is continued, that means it ends on a newline
19599 in the string. If it's anything other than a display string
19600 (e.g., a before-string from an overlay), we don't want the
19601 cursor there. (This heuristic seems to give the optimal
19602 behavior for the various types of multi-line strings.)
19603 One exception: if the string has `cursor' property on one of
19604 its characters, we _do_ want the cursor there. */
19605 if (CHARPOS (row
->end
.string_pos
) >= 0)
19607 if (row
->continued_p
)
19611 /* Check for `display' property. */
19612 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19613 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19614 struct glyph
*glyph
;
19617 for (glyph
= end
; glyph
>= beg
; --glyph
)
19618 if (STRINGP (glyph
->object
))
19621 = Fget_char_property (make_number (charpos
),
19625 && display_prop_string_p (prop
, glyph
->object
));
19626 /* If there's a `cursor' property on one of the
19627 string's characters, this row is a cursor row,
19628 even though this is not a display string. */
19631 Lisp_Object s
= glyph
->object
;
19633 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19635 ptrdiff_t gpos
= glyph
->charpos
;
19637 if (!NILP (Fget_char_property (make_number (gpos
),
19649 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19651 /* If the row ends in middle of a real character,
19652 and the line is continued, we want the cursor here.
19653 That's because CHARPOS (ROW->end.pos) would equal
19654 PT if PT is before the character. */
19655 if (!row
->ends_in_ellipsis_p
)
19656 result
= row
->continued_p
;
19658 /* If the row ends in an ellipsis, then
19659 CHARPOS (ROW->end.pos) will equal point after the
19660 invisible text. We want that position to be displayed
19661 after the ellipsis. */
19664 /* If the row ends at ZV, display the cursor at the end of that
19665 row instead of at the start of the row below. */
19666 else if (row
->ends_at_zv_p
)
19675 /* Value is non-zero if glyph row ROW should be
19676 used to hold the cursor. */
19679 cursor_row_p (struct glyph_row
*row
)
19681 return row_for_charpos_p (row
, PT
);
19686 /* Push the property PROP so that it will be rendered at the current
19687 position in IT. Return 1 if PROP was successfully pushed, 0
19688 otherwise. Called from handle_line_prefix to handle the
19689 `line-prefix' and `wrap-prefix' properties. */
19692 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19694 struct text_pos pos
=
19695 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19697 eassert (it
->method
== GET_FROM_BUFFER
19698 || it
->method
== GET_FROM_DISPLAY_VECTOR
19699 || it
->method
== GET_FROM_STRING
);
19701 /* We need to save the current buffer/string position, so it will be
19702 restored by pop_it, because iterate_out_of_display_property
19703 depends on that being set correctly, but some situations leave
19704 it->position not yet set when this function is called. */
19705 push_it (it
, &pos
);
19707 if (STRINGP (prop
))
19709 if (SCHARS (prop
) == 0)
19716 it
->string_from_prefix_prop_p
= 1;
19717 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19718 it
->current
.overlay_string_index
= -1;
19719 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19720 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19721 it
->method
= GET_FROM_STRING
;
19722 it
->stop_charpos
= 0;
19724 it
->base_level_stop
= 0;
19726 /* Force paragraph direction to be that of the parent
19728 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19729 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19731 it
->paragraph_embedding
= L2R
;
19733 /* Set up the bidi iterator for this display string. */
19736 it
->bidi_it
.string
.lstring
= it
->string
;
19737 it
->bidi_it
.string
.s
= NULL
;
19738 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19739 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19740 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19741 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19742 it
->bidi_it
.w
= it
->w
;
19743 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19746 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19748 it
->method
= GET_FROM_STRETCH
;
19751 #ifdef HAVE_WINDOW_SYSTEM
19752 else if (IMAGEP (prop
))
19754 it
->what
= IT_IMAGE
;
19755 it
->image_id
= lookup_image (it
->f
, prop
);
19756 it
->method
= GET_FROM_IMAGE
;
19758 #endif /* HAVE_WINDOW_SYSTEM */
19761 pop_it (it
); /* bogus display property, give up */
19768 /* Return the character-property PROP at the current position in IT. */
19771 get_it_property (struct it
*it
, Lisp_Object prop
)
19773 Lisp_Object position
, object
= it
->object
;
19775 if (STRINGP (object
))
19776 position
= make_number (IT_STRING_CHARPOS (*it
));
19777 else if (BUFFERP (object
))
19779 position
= make_number (IT_CHARPOS (*it
));
19780 object
= it
->window
;
19785 return Fget_char_property (position
, prop
, object
);
19788 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19791 handle_line_prefix (struct it
*it
)
19793 Lisp_Object prefix
;
19795 if (it
->continuation_lines_width
> 0)
19797 prefix
= get_it_property (it
, Qwrap_prefix
);
19799 prefix
= Vwrap_prefix
;
19803 prefix
= get_it_property (it
, Qline_prefix
);
19805 prefix
= Vline_prefix
;
19807 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19809 /* If the prefix is wider than the window, and we try to wrap
19810 it, it would acquire its own wrap prefix, and so on till the
19811 iterator stack overflows. So, don't wrap the prefix. */
19812 it
->line_wrap
= TRUNCATE
;
19813 it
->avoid_cursor_p
= 1;
19819 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19820 only for R2L lines from display_line and display_string, when they
19821 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19822 the line/string needs to be continued on the next glyph row. */
19824 unproduce_glyphs (struct it
*it
, int n
)
19826 struct glyph
*glyph
, *end
;
19828 eassert (it
->glyph_row
);
19829 eassert (it
->glyph_row
->reversed_p
);
19830 eassert (it
->area
== TEXT_AREA
);
19831 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19833 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19834 n
= it
->glyph_row
->used
[TEXT_AREA
];
19835 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19836 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19837 for ( ; glyph
< end
; glyph
++)
19838 glyph
[-n
] = *glyph
;
19841 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19842 and ROW->maxpos. */
19844 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19845 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19846 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19848 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19849 lines' rows is implemented for bidi-reordered rows. */
19851 /* ROW->minpos is the value of min_pos, the minimal buffer position
19852 we have in ROW, or ROW->start.pos if that is smaller. */
19853 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19854 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19856 /* We didn't find buffer positions smaller than ROW->start, or
19857 didn't find _any_ valid buffer positions in any of the glyphs,
19858 so we must trust the iterator's computed positions. */
19859 row
->minpos
= row
->start
.pos
;
19862 max_pos
= CHARPOS (it
->current
.pos
);
19863 max_bpos
= BYTEPOS (it
->current
.pos
);
19866 /* Here are the various use-cases for ending the row, and the
19867 corresponding values for ROW->maxpos:
19869 Line ends in a newline from buffer eol_pos + 1
19870 Line is continued from buffer max_pos + 1
19871 Line is truncated on right it->current.pos
19872 Line ends in a newline from string max_pos + 1(*)
19873 (*) + 1 only when line ends in a forward scan
19874 Line is continued from string max_pos
19875 Line is continued from display vector max_pos
19876 Line is entirely from a string min_pos == max_pos
19877 Line is entirely from a display vector min_pos == max_pos
19878 Line that ends at ZV ZV
19880 If you discover other use-cases, please add them here as
19882 if (row
->ends_at_zv_p
)
19883 row
->maxpos
= it
->current
.pos
;
19884 else if (row
->used
[TEXT_AREA
])
19886 int seen_this_string
= 0;
19887 struct glyph_row
*r1
= row
- 1;
19889 /* Did we see the same display string on the previous row? */
19890 if (STRINGP (it
->object
)
19891 /* this is not the first row */
19892 && row
> it
->w
->desired_matrix
->rows
19893 /* previous row is not the header line */
19894 && !r1
->mode_line_p
19895 /* previous row also ends in a newline from a string */
19896 && r1
->ends_in_newline_from_string_p
)
19898 struct glyph
*start
, *end
;
19900 /* Search for the last glyph of the previous row that came
19901 from buffer or string. Depending on whether the row is
19902 L2R or R2L, we need to process it front to back or the
19903 other way round. */
19904 if (!r1
->reversed_p
)
19906 start
= r1
->glyphs
[TEXT_AREA
];
19907 end
= start
+ r1
->used
[TEXT_AREA
];
19908 /* Glyphs inserted by redisplay have an integer (zero)
19909 as their object. */
19911 && INTEGERP ((end
- 1)->object
)
19912 && (end
- 1)->charpos
<= 0)
19916 if (EQ ((end
- 1)->object
, it
->object
))
19917 seen_this_string
= 1;
19920 /* If all the glyphs of the previous row were inserted
19921 by redisplay, it means the previous row was
19922 produced from a single newline, which is only
19923 possible if that newline came from the same string
19924 as the one which produced this ROW. */
19925 seen_this_string
= 1;
19929 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19930 start
= end
+ r1
->used
[TEXT_AREA
];
19932 && INTEGERP ((end
+ 1)->object
)
19933 && (end
+ 1)->charpos
<= 0)
19937 if (EQ ((end
+ 1)->object
, it
->object
))
19938 seen_this_string
= 1;
19941 seen_this_string
= 1;
19944 /* Take note of each display string that covers a newline only
19945 once, the first time we see it. This is for when a display
19946 string includes more than one newline in it. */
19947 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19949 /* If we were scanning the buffer forward when we displayed
19950 the string, we want to account for at least one buffer
19951 position that belongs to this row (position covered by
19952 the display string), so that cursor positioning will
19953 consider this row as a candidate when point is at the end
19954 of the visual line represented by this row. This is not
19955 required when scanning back, because max_pos will already
19956 have a much larger value. */
19957 if (CHARPOS (row
->end
.pos
) > max_pos
)
19958 INC_BOTH (max_pos
, max_bpos
);
19959 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19961 else if (CHARPOS (it
->eol_pos
) > 0)
19962 SET_TEXT_POS (row
->maxpos
,
19963 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19964 else if (row
->continued_p
)
19966 /* If max_pos is different from IT's current position, it
19967 means IT->method does not belong to the display element
19968 at max_pos. However, it also means that the display
19969 element at max_pos was displayed in its entirety on this
19970 line, which is equivalent to saying that the next line
19971 starts at the next buffer position. */
19972 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19973 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19976 INC_BOTH (max_pos
, max_bpos
);
19977 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19980 else if (row
->truncated_on_right_p
)
19981 /* display_line already called reseat_at_next_visible_line_start,
19982 which puts the iterator at the beginning of the next line, in
19983 the logical order. */
19984 row
->maxpos
= it
->current
.pos
;
19985 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19986 /* A line that is entirely from a string/image/stretch... */
19987 row
->maxpos
= row
->minpos
;
19992 row
->maxpos
= it
->current
.pos
;
19995 /* Construct the glyph row IT->glyph_row in the desired matrix of
19996 IT->w from text at the current position of IT. See dispextern.h
19997 for an overview of struct it. Value is non-zero if
19998 IT->glyph_row displays text, as opposed to a line displaying ZV
20002 display_line (struct it
*it
)
20004 struct glyph_row
*row
= it
->glyph_row
;
20005 Lisp_Object overlay_arrow_string
;
20007 void *wrap_data
= NULL
;
20008 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
20009 int wrap_row_used
= -1;
20010 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
20011 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
20012 int wrap_row_extra_line_spacing
IF_LINT (= 0);
20013 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
20014 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
20016 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
20017 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
20018 bool pending_handle_line_prefix
= false;
20020 /* We always start displaying at hpos zero even if hscrolled. */
20021 eassert (it
->hpos
== 0 && it
->current_x
== 0);
20023 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
20024 >= it
->w
->desired_matrix
->nrows
)
20026 it
->w
->nrows_scale_factor
++;
20027 it
->f
->fonts_changed
= 1;
20031 /* Clear the result glyph row and enable it. */
20032 prepare_desired_row (it
->w
, row
, false);
20034 row
->y
= it
->current_y
;
20035 row
->start
= it
->start
;
20036 row
->continuation_lines_width
= it
->continuation_lines_width
;
20037 row
->displays_text_p
= 1;
20038 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
20039 it
->starts_in_middle_of_char_p
= 0;
20041 /* Arrange the overlays nicely for our purposes. Usually, we call
20042 display_line on only one line at a time, in which case this
20043 can't really hurt too much, or we call it on lines which appear
20044 one after another in the buffer, in which case all calls to
20045 recenter_overlay_lists but the first will be pretty cheap. */
20046 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
20048 /* Move over display elements that are not visible because we are
20049 hscrolled. This may stop at an x-position < IT->first_visible_x
20050 if the first glyph is partially visible or if we hit a line end. */
20051 if (it
->current_x
< it
->first_visible_x
)
20053 enum move_it_result move_result
;
20055 this_line_min_pos
= row
->start
.pos
;
20056 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
20057 MOVE_TO_POS
| MOVE_TO_X
);
20058 /* If we are under a large hscroll, move_it_in_display_line_to
20059 could hit the end of the line without reaching
20060 it->first_visible_x. Pretend that we did reach it. This is
20061 especially important on a TTY, where we will call
20062 extend_face_to_end_of_line, which needs to know how many
20063 blank glyphs to produce. */
20064 if (it
->current_x
< it
->first_visible_x
20065 && (move_result
== MOVE_NEWLINE_OR_CR
20066 || move_result
== MOVE_POS_MATCH_OR_ZV
))
20067 it
->current_x
= it
->first_visible_x
;
20069 /* Record the smallest positions seen while we moved over
20070 display elements that are not visible. This is needed by
20071 redisplay_internal for optimizing the case where the cursor
20072 stays inside the same line. The rest of this function only
20073 considers positions that are actually displayed, so
20074 RECORD_MAX_MIN_POS will not otherwise record positions that
20075 are hscrolled to the left of the left edge of the window. */
20076 min_pos
= CHARPOS (this_line_min_pos
);
20077 min_bpos
= BYTEPOS (this_line_min_pos
);
20079 else if (it
->area
== TEXT_AREA
)
20081 /* We only do this when not calling move_it_in_display_line_to
20082 above, because that function calls itself handle_line_prefix. */
20083 handle_line_prefix (it
);
20087 /* Line-prefix and wrap-prefix are always displayed in the text
20088 area. But if this is the first call to display_line after
20089 init_iterator, the iterator might have been set up to write
20090 into a marginal area, e.g. if the line begins with some
20091 display property that writes to the margins. So we need to
20092 wait with the call to handle_line_prefix until whatever
20093 writes to the margin has done its job. */
20094 pending_handle_line_prefix
= true;
20097 /* Get the initial row height. This is either the height of the
20098 text hscrolled, if there is any, or zero. */
20099 row
->ascent
= it
->max_ascent
;
20100 row
->height
= it
->max_ascent
+ it
->max_descent
;
20101 row
->phys_ascent
= it
->max_phys_ascent
;
20102 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
20103 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
20105 /* Utility macro to record max and min buffer positions seen until now. */
20106 #define RECORD_MAX_MIN_POS(IT) \
20109 int composition_p = !STRINGP ((IT)->string) \
20110 && ((IT)->what == IT_COMPOSITION); \
20111 ptrdiff_t current_pos = \
20112 composition_p ? (IT)->cmp_it.charpos \
20113 : IT_CHARPOS (*(IT)); \
20114 ptrdiff_t current_bpos = \
20115 composition_p ? CHAR_TO_BYTE (current_pos) \
20116 : IT_BYTEPOS (*(IT)); \
20117 if (current_pos < min_pos) \
20119 min_pos = current_pos; \
20120 min_bpos = current_bpos; \
20122 if (IT_CHARPOS (*it) > max_pos) \
20124 max_pos = IT_CHARPOS (*it); \
20125 max_bpos = IT_BYTEPOS (*it); \
20130 /* Loop generating characters. The loop is left with IT on the next
20131 character to display. */
20134 int n_glyphs_before
, hpos_before
, x_before
;
20136 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
20138 /* Retrieve the next thing to display. Value is zero if end of
20140 if (!get_next_display_element (it
))
20142 /* Maybe add a space at the end of this line that is used to
20143 display the cursor there under X. Set the charpos of the
20144 first glyph of blank lines not corresponding to any text
20146 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20147 row
->exact_window_width_line_p
= 1;
20148 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
20149 || row
->used
[TEXT_AREA
] == 0)
20151 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
20152 row
->displays_text_p
= 0;
20154 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
20155 && (!MINI_WINDOW_P (it
->w
)
20156 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
20157 row
->indicate_empty_line_p
= 1;
20160 it
->continuation_lines_width
= 0;
20161 row
->ends_at_zv_p
= 1;
20162 /* A row that displays right-to-left text must always have
20163 its last face extended all the way to the end of line,
20164 even if this row ends in ZV, because we still write to
20165 the screen left to right. We also need to extend the
20166 last face if the default face is remapped to some
20167 different face, otherwise the functions that clear
20168 portions of the screen will clear with the default face's
20169 background color. */
20170 if (row
->reversed_p
20171 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
20172 extend_face_to_end_of_line (it
);
20176 /* Now, get the metrics of what we want to display. This also
20177 generates glyphs in `row' (which is IT->glyph_row). */
20178 n_glyphs_before
= row
->used
[TEXT_AREA
];
20181 /* Remember the line height so far in case the next element doesn't
20182 fit on the line. */
20183 if (it
->line_wrap
!= TRUNCATE
)
20185 ascent
= it
->max_ascent
;
20186 descent
= it
->max_descent
;
20187 phys_ascent
= it
->max_phys_ascent
;
20188 phys_descent
= it
->max_phys_descent
;
20190 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
20192 if (IT_DISPLAYING_WHITESPACE (it
))
20196 SAVE_IT (wrap_it
, *it
, wrap_data
);
20198 wrap_row_used
= row
->used
[TEXT_AREA
];
20199 wrap_row_ascent
= row
->ascent
;
20200 wrap_row_height
= row
->height
;
20201 wrap_row_phys_ascent
= row
->phys_ascent
;
20202 wrap_row_phys_height
= row
->phys_height
;
20203 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
20204 wrap_row_min_pos
= min_pos
;
20205 wrap_row_min_bpos
= min_bpos
;
20206 wrap_row_max_pos
= max_pos
;
20207 wrap_row_max_bpos
= max_bpos
;
20213 PRODUCE_GLYPHS (it
);
20215 /* If this display element was in marginal areas, continue with
20217 if (it
->area
!= TEXT_AREA
)
20219 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20220 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20221 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20222 row
->phys_height
= max (row
->phys_height
,
20223 it
->max_phys_ascent
+ it
->max_phys_descent
);
20224 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20225 it
->max_extra_line_spacing
);
20226 set_iterator_to_next (it
, 1);
20227 /* If we didn't handle the line/wrap prefix above, and the
20228 call to set_iterator_to_next just switched to TEXT_AREA,
20229 process the prefix now. */
20230 if (it
->area
== TEXT_AREA
&& pending_handle_line_prefix
)
20232 pending_handle_line_prefix
= false;
20233 handle_line_prefix (it
);
20238 /* Does the display element fit on the line? If we truncate
20239 lines, we should draw past the right edge of the window. If
20240 we don't truncate, we want to stop so that we can display the
20241 continuation glyph before the right margin. If lines are
20242 continued, there are two possible strategies for characters
20243 resulting in more than 1 glyph (e.g. tabs): Display as many
20244 glyphs as possible in this line and leave the rest for the
20245 continuation line, or display the whole element in the next
20246 line. Original redisplay did the former, so we do it also. */
20247 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
20248 hpos_before
= it
->hpos
;
20251 if (/* Not a newline. */
20253 /* Glyphs produced fit entirely in the line. */
20254 && it
->current_x
< it
->last_visible_x
)
20256 it
->hpos
+= nglyphs
;
20257 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20258 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20259 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20260 row
->phys_height
= max (row
->phys_height
,
20261 it
->max_phys_ascent
+ it
->max_phys_descent
);
20262 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20263 it
->max_extra_line_spacing
);
20264 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
20265 /* In R2L rows, we arrange in extend_face_to_end_of_line
20266 to add a right offset to the line, by a suitable
20267 change to the stretch glyph that is the leftmost
20268 glyph of the line. */
20269 && !row
->reversed_p
)
20270 row
->x
= x
- it
->first_visible_x
;
20271 /* Record the maximum and minimum buffer positions seen so
20272 far in glyphs that will be displayed by this row. */
20274 RECORD_MAX_MIN_POS (it
);
20279 struct glyph
*glyph
;
20281 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
20283 /* Identify the glyphs added by the last call to
20284 PRODUCE_GLYPHS. In R2L rows, they are prepended to
20285 the previous glyphs. */
20286 if (!row
->reversed_p
)
20287 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
20289 glyph
= row
->glyphs
[TEXT_AREA
] + nglyphs
- 1 - i
;
20290 new_x
= x
+ glyph
->pixel_width
;
20292 if (/* Lines are continued. */
20293 it
->line_wrap
!= TRUNCATE
20294 && (/* Glyph doesn't fit on the line. */
20295 new_x
> it
->last_visible_x
20296 /* Or it fits exactly on a window system frame. */
20297 || (new_x
== it
->last_visible_x
20298 && FRAME_WINDOW_P (it
->f
)
20299 && (row
->reversed_p
20300 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20301 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
20303 /* End of a continued line. */
20306 || (new_x
== it
->last_visible_x
20307 && FRAME_WINDOW_P (it
->f
)
20308 && (row
->reversed_p
20309 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20310 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
20312 /* Current glyph is the only one on the line or
20313 fits exactly on the line. We must continue
20314 the line because we can't draw the cursor
20315 after the glyph. */
20316 row
->continued_p
= 1;
20317 it
->current_x
= new_x
;
20318 it
->continuation_lines_width
+= new_x
;
20320 if (i
== nglyphs
- 1)
20322 /* If line-wrap is on, check if a previous
20323 wrap point was found. */
20324 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
)
20325 && wrap_row_used
> 0
20326 /* Even if there is a previous wrap
20327 point, continue the line here as
20328 usual, if (i) the previous character
20329 was a space or tab AND (ii) the
20330 current character is not. */
20332 || IT_DISPLAYING_WHITESPACE (it
)))
20335 /* Record the maximum and minimum buffer
20336 positions seen so far in glyphs that will be
20337 displayed by this row. */
20339 RECORD_MAX_MIN_POS (it
);
20340 set_iterator_to_next (it
, 1);
20341 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20343 if (!get_next_display_element (it
))
20345 row
->exact_window_width_line_p
= 1;
20346 it
->continuation_lines_width
= 0;
20347 row
->continued_p
= 0;
20348 row
->ends_at_zv_p
= 1;
20350 else if (ITERATOR_AT_END_OF_LINE_P (it
))
20352 row
->continued_p
= 0;
20353 row
->exact_window_width_line_p
= 1;
20355 /* If line-wrap is on, check if a
20356 previous wrap point was found. */
20357 else if (wrap_row_used
> 0
20358 /* Even if there is a previous wrap
20359 point, continue the line here as
20360 usual, if (i) the previous character
20361 was a space or tab AND (ii) the
20362 current character is not. */
20364 || IT_DISPLAYING_WHITESPACE (it
)))
20369 else if (it
->bidi_p
)
20370 RECORD_MAX_MIN_POS (it
);
20371 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20372 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20373 extend_face_to_end_of_line (it
);
20375 else if (CHAR_GLYPH_PADDING_P (*glyph
)
20376 && !FRAME_WINDOW_P (it
->f
))
20378 /* A padding glyph that doesn't fit on this line.
20379 This means the whole character doesn't fit
20381 if (row
->reversed_p
)
20382 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20383 - n_glyphs_before
);
20384 row
->used
[TEXT_AREA
] = n_glyphs_before
;
20386 /* Fill the rest of the row with continuation
20387 glyphs like in 20.x. */
20388 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
20389 < row
->glyphs
[1 + TEXT_AREA
])
20390 produce_special_glyphs (it
, IT_CONTINUATION
);
20392 row
->continued_p
= 1;
20393 it
->current_x
= x_before
;
20394 it
->continuation_lines_width
+= x_before
;
20396 /* Restore the height to what it was before the
20397 element not fitting on the line. */
20398 it
->max_ascent
= ascent
;
20399 it
->max_descent
= descent
;
20400 it
->max_phys_ascent
= phys_ascent
;
20401 it
->max_phys_descent
= phys_descent
;
20402 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20403 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20404 extend_face_to_end_of_line (it
);
20406 else if (wrap_row_used
> 0)
20409 if (row
->reversed_p
)
20410 unproduce_glyphs (it
,
20411 row
->used
[TEXT_AREA
] - wrap_row_used
);
20412 RESTORE_IT (it
, &wrap_it
, wrap_data
);
20413 it
->continuation_lines_width
+= wrap_x
;
20414 row
->used
[TEXT_AREA
] = wrap_row_used
;
20415 row
->ascent
= wrap_row_ascent
;
20416 row
->height
= wrap_row_height
;
20417 row
->phys_ascent
= wrap_row_phys_ascent
;
20418 row
->phys_height
= wrap_row_phys_height
;
20419 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
20420 min_pos
= wrap_row_min_pos
;
20421 min_bpos
= wrap_row_min_bpos
;
20422 max_pos
= wrap_row_max_pos
;
20423 max_bpos
= wrap_row_max_bpos
;
20424 row
->continued_p
= 1;
20425 row
->ends_at_zv_p
= 0;
20426 row
->exact_window_width_line_p
= 0;
20427 it
->continuation_lines_width
+= x
;
20429 /* Make sure that a non-default face is extended
20430 up to the right margin of the window. */
20431 extend_face_to_end_of_line (it
);
20433 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
20435 /* A TAB that extends past the right edge of the
20436 window. This produces a single glyph on
20437 window system frames. We leave the glyph in
20438 this row and let it fill the row, but don't
20439 consume the TAB. */
20440 if ((row
->reversed_p
20441 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20442 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20443 produce_special_glyphs (it
, IT_CONTINUATION
);
20444 it
->continuation_lines_width
+= it
->last_visible_x
;
20445 row
->ends_in_middle_of_char_p
= 1;
20446 row
->continued_p
= 1;
20447 glyph
->pixel_width
= it
->last_visible_x
- x
;
20448 it
->starts_in_middle_of_char_p
= 1;
20449 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20450 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20451 extend_face_to_end_of_line (it
);
20455 /* Something other than a TAB that draws past
20456 the right edge of the window. Restore
20457 positions to values before the element. */
20458 if (row
->reversed_p
)
20459 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20460 - (n_glyphs_before
+ i
));
20461 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20463 /* Display continuation glyphs. */
20464 it
->current_x
= x_before
;
20465 it
->continuation_lines_width
+= x
;
20466 if (!FRAME_WINDOW_P (it
->f
)
20467 || (row
->reversed_p
20468 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20469 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20470 produce_special_glyphs (it
, IT_CONTINUATION
);
20471 row
->continued_p
= 1;
20473 extend_face_to_end_of_line (it
);
20475 if (nglyphs
> 1 && i
> 0)
20477 row
->ends_in_middle_of_char_p
= 1;
20478 it
->starts_in_middle_of_char_p
= 1;
20481 /* Restore the height to what it was before the
20482 element not fitting on the line. */
20483 it
->max_ascent
= ascent
;
20484 it
->max_descent
= descent
;
20485 it
->max_phys_ascent
= phys_ascent
;
20486 it
->max_phys_descent
= phys_descent
;
20491 else if (new_x
> it
->first_visible_x
)
20493 /* Increment number of glyphs actually displayed. */
20496 /* Record the maximum and minimum buffer positions
20497 seen so far in glyphs that will be displayed by
20500 RECORD_MAX_MIN_POS (it
);
20502 if (x
< it
->first_visible_x
&& !row
->reversed_p
)
20503 /* Glyph is partially visible, i.e. row starts at
20504 negative X position. Don't do that in R2L
20505 rows, where we arrange to add a right offset to
20506 the line in extend_face_to_end_of_line, by a
20507 suitable change to the stretch glyph that is
20508 the leftmost glyph of the line. */
20509 row
->x
= x
- it
->first_visible_x
;
20510 /* When the last glyph of an R2L row only fits
20511 partially on the line, we need to set row->x to a
20512 negative offset, so that the leftmost glyph is
20513 the one that is partially visible. But if we are
20514 going to produce the truncation glyph, this will
20515 be taken care of in produce_special_glyphs. */
20516 if (row
->reversed_p
20517 && new_x
> it
->last_visible_x
20518 && !(it
->line_wrap
== TRUNCATE
20519 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
20521 eassert (FRAME_WINDOW_P (it
->f
));
20522 row
->x
= it
->last_visible_x
- new_x
;
20527 /* Glyph is completely off the left margin of the
20528 window. This should not happen because of the
20529 move_it_in_display_line at the start of this
20530 function, unless the text display area of the
20531 window is empty. */
20532 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20535 /* Even if this display element produced no glyphs at all,
20536 we want to record its position. */
20537 if (it
->bidi_p
&& nglyphs
== 0)
20538 RECORD_MAX_MIN_POS (it
);
20540 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20541 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20542 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20543 row
->phys_height
= max (row
->phys_height
,
20544 it
->max_phys_ascent
+ it
->max_phys_descent
);
20545 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20546 it
->max_extra_line_spacing
);
20548 /* End of this display line if row is continued. */
20549 if (row
->continued_p
|| row
->ends_at_zv_p
)
20554 /* Is this a line end? If yes, we're also done, after making
20555 sure that a non-default face is extended up to the right
20556 margin of the window. */
20557 if (ITERATOR_AT_END_OF_LINE_P (it
))
20559 int used_before
= row
->used
[TEXT_AREA
];
20561 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
20563 /* Add a space at the end of the line that is used to
20564 display the cursor there. */
20565 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20566 append_space_for_newline (it
, 0);
20568 /* Extend the face to the end of the line. */
20569 extend_face_to_end_of_line (it
);
20571 /* Make sure we have the position. */
20572 if (used_before
== 0)
20573 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
20575 /* Record the position of the newline, for use in
20577 it
->eol_pos
= it
->current
.pos
;
20579 /* Consume the line end. This skips over invisible lines. */
20580 set_iterator_to_next (it
, 1);
20581 it
->continuation_lines_width
= 0;
20585 /* Proceed with next display element. Note that this skips
20586 over lines invisible because of selective display. */
20587 set_iterator_to_next (it
, 1);
20589 /* If we truncate lines, we are done when the last displayed
20590 glyphs reach past the right margin of the window. */
20591 if (it
->line_wrap
== TRUNCATE
20592 && ((FRAME_WINDOW_P (it
->f
)
20593 /* Images are preprocessed in produce_image_glyph such
20594 that they are cropped at the right edge of the
20595 window, so an image glyph will always end exactly at
20596 last_visible_x, even if there's no right fringe. */
20597 && ((row
->reversed_p
20598 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20599 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))
20600 || it
->what
== IT_IMAGE
))
20601 ? (it
->current_x
>= it
->last_visible_x
)
20602 : (it
->current_x
> it
->last_visible_x
)))
20604 /* Maybe add truncation glyphs. */
20605 if (!FRAME_WINDOW_P (it
->f
)
20606 || (row
->reversed_p
20607 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20608 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20612 if (!row
->reversed_p
)
20614 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20615 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20620 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20621 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20623 /* Remove any padding glyphs at the front of ROW, to
20624 make room for the truncation glyphs we will be
20625 adding below. The loop below always inserts at
20626 least one truncation glyph, so also remove the
20627 last glyph added to ROW. */
20628 unproduce_glyphs (it
, i
+ 1);
20629 /* Adjust i for the loop below. */
20630 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20633 /* produce_special_glyphs overwrites the last glyph, so
20634 we don't want that if we want to keep that last
20635 glyph, which means it's an image. */
20636 if (it
->current_x
> it
->last_visible_x
)
20638 it
->current_x
= x_before
;
20639 if (!FRAME_WINDOW_P (it
->f
))
20641 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20643 row
->used
[TEXT_AREA
] = i
;
20644 produce_special_glyphs (it
, IT_TRUNCATION
);
20649 row
->used
[TEXT_AREA
] = i
;
20650 produce_special_glyphs (it
, IT_TRUNCATION
);
20652 it
->hpos
= hpos_before
;
20655 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20657 /* Don't truncate if we can overflow newline into fringe. */
20658 if (!get_next_display_element (it
))
20660 it
->continuation_lines_width
= 0;
20661 row
->ends_at_zv_p
= 1;
20662 row
->exact_window_width_line_p
= 1;
20665 if (ITERATOR_AT_END_OF_LINE_P (it
))
20667 row
->exact_window_width_line_p
= 1;
20668 goto at_end_of_line
;
20670 it
->current_x
= x_before
;
20671 it
->hpos
= hpos_before
;
20674 row
->truncated_on_right_p
= 1;
20675 it
->continuation_lines_width
= 0;
20676 reseat_at_next_visible_line_start (it
, 0);
20677 /* We insist below that IT's position be at ZV because in
20678 bidi-reordered lines the character at visible line start
20679 might not be the character that follows the newline in
20680 the logical order. */
20681 if (IT_BYTEPOS (*it
) > BEG_BYTE
)
20682 row
->ends_at_zv_p
=
20683 IT_BYTEPOS (*it
) >= ZV_BYTE
&& FETCH_BYTE (ZV_BYTE
- 1) != '\n';
20685 row
->ends_at_zv_p
= false;
20691 bidi_unshelve_cache (wrap_data
, 1);
20693 /* If line is not empty and hscrolled, maybe insert truncation glyphs
20694 at the left window margin. */
20695 if (it
->first_visible_x
20696 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20698 if (!FRAME_WINDOW_P (it
->f
)
20699 || (((row
->reversed_p
20700 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20701 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20702 /* Don't let insert_left_trunc_glyphs overwrite the
20703 first glyph of the row if it is an image. */
20704 && row
->glyphs
[TEXT_AREA
]->type
!= IMAGE_GLYPH
))
20705 insert_left_trunc_glyphs (it
);
20706 row
->truncated_on_left_p
= 1;
20709 /* Remember the position at which this line ends.
20711 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20712 cannot be before the call to find_row_edges below, since that is
20713 where these positions are determined. */
20714 row
->end
= it
->current
;
20717 row
->minpos
= row
->start
.pos
;
20718 row
->maxpos
= row
->end
.pos
;
20722 /* ROW->minpos and ROW->maxpos must be the smallest and
20723 `1 + the largest' buffer positions in ROW. But if ROW was
20724 bidi-reordered, these two positions can be anywhere in the
20725 row, so we must determine them now. */
20726 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20729 /* If the start of this line is the overlay arrow-position, then
20730 mark this glyph row as the one containing the overlay arrow.
20731 This is clearly a mess with variable size fonts. It would be
20732 better to let it be displayed like cursors under X. */
20733 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20734 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20735 !NILP (overlay_arrow_string
)))
20737 /* Overlay arrow in window redisplay is a fringe bitmap. */
20738 if (STRINGP (overlay_arrow_string
))
20740 struct glyph_row
*arrow_row
20741 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20742 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20743 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20744 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20745 struct glyph
*p2
, *end
;
20747 /* Copy the arrow glyphs. */
20748 while (glyph
< arrow_end
)
20751 /* Throw away padding glyphs. */
20753 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20754 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20760 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20765 eassert (INTEGERP (overlay_arrow_string
));
20766 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20768 overlay_arrow_seen
= 1;
20771 /* Highlight trailing whitespace. */
20772 if (!NILP (Vshow_trailing_whitespace
))
20773 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20775 /* Compute pixel dimensions of this line. */
20776 compute_line_metrics (it
);
20778 /* Implementation note: No changes in the glyphs of ROW or in their
20779 faces can be done past this point, because compute_line_metrics
20780 computes ROW's hash value and stores it within the glyph_row
20783 /* Record whether this row ends inside an ellipsis. */
20784 row
->ends_in_ellipsis_p
20785 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20786 && it
->ellipsis_p
);
20788 /* Save fringe bitmaps in this row. */
20789 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20790 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20791 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20792 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20794 it
->left_user_fringe_bitmap
= 0;
20795 it
->left_user_fringe_face_id
= 0;
20796 it
->right_user_fringe_bitmap
= 0;
20797 it
->right_user_fringe_face_id
= 0;
20799 /* Maybe set the cursor. */
20800 cvpos
= it
->w
->cursor
.vpos
;
20802 /* In bidi-reordered rows, keep checking for proper cursor
20803 position even if one has been found already, because buffer
20804 positions in such rows change non-linearly with ROW->VPOS,
20805 when a line is continued. One exception: when we are at ZV,
20806 display cursor on the first suitable glyph row, since all
20807 the empty rows after that also have their position set to ZV. */
20808 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20809 lines' rows is implemented for bidi-reordered rows. */
20811 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20812 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20813 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20814 && cursor_row_p (row
))
20815 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20817 /* Prepare for the next line. This line starts horizontally at (X
20818 HPOS) = (0 0). Vertical positions are incremented. As a
20819 convenience for the caller, IT->glyph_row is set to the next
20821 it
->current_x
= it
->hpos
= 0;
20822 it
->current_y
+= row
->height
;
20823 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20826 /* The next row should by default use the same value of the
20827 reversed_p flag as this one. set_iterator_to_next decides when
20828 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20829 the flag accordingly. */
20830 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20831 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20832 it
->start
= row
->end
;
20833 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20835 #undef RECORD_MAX_MIN_POS
20838 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20839 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20840 doc
: /* Return paragraph direction at point in BUFFER.
20841 Value is either `left-to-right' or `right-to-left'.
20842 If BUFFER is omitted or nil, it defaults to the current buffer.
20844 Paragraph direction determines how the text in the paragraph is displayed.
20845 In left-to-right paragraphs, text begins at the left margin of the window
20846 and the reading direction is generally left to right. In right-to-left
20847 paragraphs, text begins at the right margin and is read from right to left.
20849 See also `bidi-paragraph-direction'. */)
20850 (Lisp_Object buffer
)
20852 struct buffer
*buf
= current_buffer
;
20853 struct buffer
*old
= buf
;
20855 if (! NILP (buffer
))
20857 CHECK_BUFFER (buffer
);
20858 buf
= XBUFFER (buffer
);
20861 if (NILP (BVAR (buf
, bidi_display_reordering
))
20862 || NILP (BVAR (buf
, enable_multibyte_characters
))
20863 /* When we are loading loadup.el, the character property tables
20864 needed for bidi iteration are not yet available. */
20865 || !NILP (Vpurify_flag
))
20866 return Qleft_to_right
;
20867 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20868 return BVAR (buf
, bidi_paragraph_direction
);
20871 /* Determine the direction from buffer text. We could try to
20872 use current_matrix if it is up to date, but this seems fast
20873 enough as it is. */
20874 struct bidi_it itb
;
20875 ptrdiff_t pos
= BUF_PT (buf
);
20876 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20878 void *itb_data
= bidi_shelve_cache ();
20880 set_buffer_temp (buf
);
20881 /* bidi_paragraph_init finds the base direction of the paragraph
20882 by searching forward from paragraph start. We need the base
20883 direction of the current or _previous_ paragraph, so we need
20884 to make sure we are within that paragraph. To that end, find
20885 the previous non-empty line. */
20886 if (pos
>= ZV
&& pos
> BEGV
)
20887 DEC_BOTH (pos
, bytepos
);
20888 AUTO_STRING (trailing_white_space
, "[\f\t ]*\n");
20889 if (fast_looking_at (trailing_white_space
,
20890 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20892 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20893 || c
== ' ' || c
== '\t' || c
== '\f')
20895 if (bytepos
<= BEGV_BYTE
)
20900 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20903 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20904 itb
.paragraph_dir
= NEUTRAL_DIR
;
20905 itb
.string
.s
= NULL
;
20906 itb
.string
.lstring
= Qnil
;
20907 itb
.string
.bufpos
= 0;
20908 itb
.string
.from_disp_str
= 0;
20909 itb
.string
.unibyte
= 0;
20910 /* We have no window to use here for ignoring window-specific
20911 overlays. Using NULL for window pointer will cause
20912 compute_display_string_pos to use the current buffer. */
20914 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20915 bidi_unshelve_cache (itb_data
, 0);
20916 set_buffer_temp (old
);
20917 switch (itb
.paragraph_dir
)
20920 return Qleft_to_right
;
20923 return Qright_to_left
;
20931 DEFUN ("bidi-find-overridden-directionality",
20932 Fbidi_find_overridden_directionality
,
20933 Sbidi_find_overridden_directionality
, 2, 3, 0,
20934 doc
: /* Return position between FROM and TO where directionality was overridden.
20936 This function returns the first character position in the specified
20937 region of OBJECT where there is a character whose `bidi-class' property
20938 is `L', but which was forced to display as `R' by a directional
20939 override, and likewise with characters whose `bidi-class' is `R'
20940 or `AL' that were forced to display as `L'.
20942 If no such character is found, the function returns nil.
20944 OBJECT is a Lisp string or buffer to search for overridden
20945 directionality, and defaults to the current buffer if nil or omitted.
20946 OBJECT can also be a window, in which case the function will search
20947 the buffer displayed in that window. Passing the window instead of
20948 a buffer is preferable when the buffer is displayed in some window,
20949 because this function will then be able to correctly account for
20950 window-specific overlays, which can affect the results.
20952 Strong directional characters `L', `R', and `AL' can have their
20953 intrinsic directionality overridden by directional override
20954 control characters RLO \(u+202e) and LRO \(u+202d). See the
20955 function `get-char-code-property' for a way to inquire about
20956 the `bidi-class' property of a character. */)
20957 (Lisp_Object from
, Lisp_Object to
, Lisp_Object object
)
20959 struct buffer
*buf
= current_buffer
;
20960 struct buffer
*old
= buf
;
20961 struct window
*w
= NULL
;
20962 bool frame_window_p
= FRAME_WINDOW_P (SELECTED_FRAME ());
20963 struct bidi_it itb
;
20964 ptrdiff_t from_pos
, to_pos
, from_bpos
;
20967 if (!NILP (object
))
20969 if (BUFFERP (object
))
20970 buf
= XBUFFER (object
);
20971 else if (WINDOWP (object
))
20973 w
= decode_live_window (object
);
20974 buf
= XBUFFER (w
->contents
);
20975 frame_window_p
= FRAME_WINDOW_P (XFRAME (w
->frame
));
20978 CHECK_STRING (object
);
20981 if (STRINGP (object
))
20983 /* Characters in unibyte strings are always treated by bidi.c as
20985 if (!STRING_MULTIBYTE (object
)
20986 /* When we are loading loadup.el, the character property
20987 tables needed for bidi iteration are not yet
20989 || !NILP (Vpurify_flag
))
20992 validate_subarray (object
, from
, to
, SCHARS (object
), &from_pos
, &to_pos
);
20993 if (from_pos
>= SCHARS (object
))
20996 /* Set up the bidi iterator. */
20997 itb_data
= bidi_shelve_cache ();
20998 itb
.paragraph_dir
= NEUTRAL_DIR
;
20999 itb
.string
.lstring
= object
;
21000 itb
.string
.s
= NULL
;
21001 itb
.string
.schars
= SCHARS (object
);
21002 itb
.string
.bufpos
= 0;
21003 itb
.string
.from_disp_str
= 0;
21004 itb
.string
.unibyte
= 0;
21006 bidi_init_it (0, 0, frame_window_p
, &itb
);
21010 /* Nothing this fancy can happen in unibyte buffers, or in a
21011 buffer that disabled reordering, or if FROM is at EOB. */
21012 if (NILP (BVAR (buf
, bidi_display_reordering
))
21013 || NILP (BVAR (buf
, enable_multibyte_characters
))
21014 /* When we are loading loadup.el, the character property
21015 tables needed for bidi iteration are not yet
21017 || !NILP (Vpurify_flag
))
21020 set_buffer_temp (buf
);
21021 validate_region (&from
, &to
);
21022 from_pos
= XINT (from
);
21023 to_pos
= XINT (to
);
21024 if (from_pos
>= ZV
)
21027 /* Set up the bidi iterator. */
21028 itb_data
= bidi_shelve_cache ();
21029 from_bpos
= CHAR_TO_BYTE (from_pos
);
21030 if (from_pos
== BEGV
)
21032 itb
.charpos
= BEGV
;
21033 itb
.bytepos
= BEGV_BYTE
;
21035 else if (FETCH_CHAR (from_bpos
- 1) == '\n')
21037 itb
.charpos
= from_pos
;
21038 itb
.bytepos
= from_bpos
;
21041 itb
.charpos
= find_newline_no_quit (from_pos
, CHAR_TO_BYTE (from_pos
),
21043 itb
.paragraph_dir
= NEUTRAL_DIR
;
21044 itb
.string
.s
= NULL
;
21045 itb
.string
.lstring
= Qnil
;
21046 itb
.string
.bufpos
= 0;
21047 itb
.string
.from_disp_str
= 0;
21048 itb
.string
.unibyte
= 0;
21050 bidi_init_it (itb
.charpos
, itb
.bytepos
, frame_window_p
, &itb
);
21055 /* For the purposes of this function, the actual base direction of
21056 the paragraph doesn't matter, so just set it to L2R. */
21057 bidi_paragraph_init (L2R
, &itb
, 0);
21058 while ((found
= bidi_find_first_overridden (&itb
)) < from_pos
)
21060 } while (found
== ZV
&& itb
.ch
== '\n' && itb
.charpos
< to_pos
);
21062 bidi_unshelve_cache (itb_data
, 0);
21063 set_buffer_temp (old
);
21065 return (from_pos
<= found
&& found
< to_pos
) ? make_number (found
) : Qnil
;
21068 DEFUN ("move-point-visually", Fmove_point_visually
,
21069 Smove_point_visually
, 1, 1, 0,
21070 doc
: /* Move point in the visual order in the specified DIRECTION.
21071 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
21074 Value is the new character position of point. */)
21075 (Lisp_Object direction
)
21077 struct window
*w
= XWINDOW (selected_window
);
21078 struct buffer
*b
= XBUFFER (w
->contents
);
21079 struct glyph_row
*row
;
21081 Lisp_Object paragraph_dir
;
21083 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
21084 (!(ROW)->continued_p \
21085 && INTEGERP ((GLYPH)->object) \
21086 && (GLYPH)->type == CHAR_GLYPH \
21087 && (GLYPH)->u.ch == ' ' \
21088 && (GLYPH)->charpos >= 0 \
21089 && !(GLYPH)->avoid_cursor_p)
21091 CHECK_NUMBER (direction
);
21092 dir
= XINT (direction
);
21098 /* If current matrix is up-to-date, we can use the information
21099 recorded in the glyphs, at least as long as the goal is on the
21101 if (w
->window_end_valid
21102 && !windows_or_buffers_changed
21104 && !b
->clip_changed
21105 && !b
->prevent_redisplay_optimizations_p
21106 && !window_outdated (w
)
21107 /* We rely below on the cursor coordinates to be up to date, but
21108 we cannot trust them if some command moved point since the
21109 last complete redisplay. */
21110 && w
->last_point
== BUF_PT (b
)
21111 && w
->cursor
.vpos
>= 0
21112 && w
->cursor
.vpos
< w
->current_matrix
->nrows
21113 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
21115 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
21116 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
21117 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
21119 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
21121 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
21123 SET_PT (g
->charpos
);
21124 w
->cursor
.vpos
= -1;
21125 return make_number (PT
);
21127 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
21131 if (BUFFERP (gpt
->object
))
21134 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
21135 new_pos
+= (row
->reversed_p
? -dir
: dir
);
21137 new_pos
-= (row
->reversed_p
? -dir
: dir
);
21139 else if (BUFFERP (g
->object
))
21140 new_pos
= g
->charpos
;
21144 w
->cursor
.vpos
= -1;
21145 return make_number (PT
);
21147 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
21149 /* Glyphs inserted at the end of a non-empty line for
21150 positioning the cursor have zero charpos, so we must
21151 deduce the value of point by other means. */
21152 if (g
->charpos
> 0)
21153 SET_PT (g
->charpos
);
21154 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
21156 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
21157 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21160 w
->cursor
.vpos
= -1;
21161 return make_number (PT
);
21164 if (g
== e
|| INTEGERP (g
->object
))
21166 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
21167 goto simulate_display
;
21168 if (!row
->reversed_p
)
21172 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
21173 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
21174 goto simulate_display
;
21178 if (row
->reversed_p
&& !row
->continued_p
)
21180 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21181 w
->cursor
.vpos
= -1;
21182 return make_number (PT
);
21184 g
= row
->glyphs
[TEXT_AREA
];
21185 e
= g
+ row
->used
[TEXT_AREA
];
21186 for ( ; g
< e
; g
++)
21188 if (BUFFERP (g
->object
)
21189 /* Empty lines have only one glyph, which stands
21190 for the newline, and whose charpos is the
21191 buffer position of the newline. */
21192 || ROW_GLYPH_NEWLINE_P (row
, g
)
21193 /* When the buffer ends in a newline, the line at
21194 EOB also has one glyph, but its charpos is -1. */
21195 || (row
->ends_at_zv_p
21196 && !row
->reversed_p
21197 && INTEGERP (g
->object
)
21198 && g
->type
== CHAR_GLYPH
21199 && g
->u
.ch
== ' '))
21201 if (g
->charpos
> 0)
21202 SET_PT (g
->charpos
);
21203 else if (!row
->reversed_p
21204 && row
->ends_at_zv_p
21209 w
->cursor
.vpos
= -1;
21210 return make_number (PT
);
21216 if (!row
->reversed_p
&& !row
->continued_p
)
21218 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
21219 w
->cursor
.vpos
= -1;
21220 return make_number (PT
);
21222 e
= row
->glyphs
[TEXT_AREA
];
21223 g
= e
+ row
->used
[TEXT_AREA
] - 1;
21224 for ( ; g
>= e
; g
--)
21226 if (BUFFERP (g
->object
)
21227 || (ROW_GLYPH_NEWLINE_P (row
, g
)
21229 /* Empty R2L lines on GUI frames have the buffer
21230 position of the newline stored in the stretch
21232 || g
->type
== STRETCH_GLYPH
21233 || (row
->ends_at_zv_p
21235 && INTEGERP (g
->object
)
21236 && g
->type
== CHAR_GLYPH
21237 && g
->u
.ch
== ' '))
21239 if (g
->charpos
> 0)
21240 SET_PT (g
->charpos
);
21241 else if (row
->reversed_p
21242 && row
->ends_at_zv_p
21247 w
->cursor
.vpos
= -1;
21248 return make_number (PT
);
21257 /* If we wind up here, we failed to move by using the glyphs, so we
21258 need to simulate display instead. */
21261 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
21263 paragraph_dir
= Qleft_to_right
;
21264 if (EQ (paragraph_dir
, Qright_to_left
))
21266 if (PT
<= BEGV
&& dir
< 0)
21267 xsignal0 (Qbeginning_of_buffer
);
21268 else if (PT
>= ZV
&& dir
> 0)
21269 xsignal0 (Qend_of_buffer
);
21272 struct text_pos pt
;
21274 int pt_x
, target_x
, pixel_width
, pt_vpos
;
21276 bool overshoot_expected
= false;
21277 bool target_is_eol_p
= false;
21279 /* Setup the arena. */
21280 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
21281 start_display (&it
, w
, pt
);
21283 if (it
.cmp_it
.id
< 0
21284 && it
.method
== GET_FROM_STRING
21285 && it
.area
== TEXT_AREA
21286 && it
.string_from_display_prop_p
21287 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
21288 overshoot_expected
= true;
21290 /* Find the X coordinate of point. We start from the beginning
21291 of this or previous line to make sure we are before point in
21292 the logical order (since the move_it_* functions can only
21295 reseat_at_previous_visible_line_start (&it
);
21296 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
21297 if (IT_CHARPOS (it
) != PT
)
21299 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
21300 -1, -1, -1, MOVE_TO_POS
);
21301 /* If we missed point because the character there is
21302 displayed out of a display vector that has more than one
21303 glyph, retry expecting overshoot. */
21304 if (it
.method
== GET_FROM_DISPLAY_VECTOR
21305 && it
.current
.dpvec_index
> 0
21306 && !overshoot_expected
)
21308 overshoot_expected
= true;
21311 else if (IT_CHARPOS (it
) != PT
&& !overshoot_expected
)
21312 move_it_in_display_line (&it
, PT
, -1, MOVE_TO_POS
);
21314 pt_x
= it
.current_x
;
21316 if (dir
> 0 || overshoot_expected
)
21318 struct glyph_row
*row
= it
.glyph_row
;
21320 /* When point is at beginning of line, we don't have
21321 information about the glyph there loaded into struct
21322 it. Calling get_next_display_element fixes that. */
21324 get_next_display_element (&it
);
21325 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21326 it
.glyph_row
= NULL
;
21327 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
21328 it
.glyph_row
= row
;
21329 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
21330 it, lest it will become out of sync with it's buffer
21332 it
.current_x
= pt_x
;
21335 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
21336 pixel_width
= it
.pixel_width
;
21337 if (overshoot_expected
&& at_eol_p
)
21339 else if (pixel_width
<= 0)
21342 /* If there's a display string (or something similar) at point,
21343 we are actually at the glyph to the left of point, so we need
21344 to correct the X coordinate. */
21345 if (overshoot_expected
)
21348 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
21350 pt_x
+= pixel_width
;
21353 /* Compute target X coordinate, either to the left or to the
21354 right of point. On TTY frames, all characters have the same
21355 pixel width of 1, so we can use that. On GUI frames we don't
21356 have an easy way of getting at the pixel width of the
21357 character to the left of point, so we use a different method
21358 of getting to that place. */
21360 target_x
= pt_x
+ pixel_width
;
21362 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
21364 /* Target X coordinate could be one line above or below the line
21365 of point, in which case we need to adjust the target X
21366 coordinate. Also, if moving to the left, we need to begin at
21367 the left edge of the point's screen line. */
21372 start_display (&it
, w
, pt
);
21373 reseat_at_previous_visible_line_start (&it
);
21374 it
.current_x
= it
.current_y
= it
.hpos
= 0;
21376 move_it_by_lines (&it
, pt_vpos
);
21380 move_it_by_lines (&it
, -1);
21381 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
21382 target_is_eol_p
= true;
21383 /* Under word-wrap, we don't know the x coordinate of
21384 the last character displayed on the previous line,
21385 which immediately precedes the wrap point. To find
21386 out its x coordinate, we try moving to the right
21387 margin of the window, which will stop at the wrap
21388 point, and then reset target_x to point at the
21389 character that precedes the wrap point. This is not
21390 needed on GUI frames, because (see below) there we
21391 move from the left margin one grapheme cluster at a
21392 time, and stop when we hit the wrap point. */
21393 if (!FRAME_WINDOW_P (it
.f
) && it
.line_wrap
== WORD_WRAP
)
21395 void *it_data
= NULL
;
21398 SAVE_IT (it2
, it
, it_data
);
21399 move_it_in_display_line_to (&it
, ZV
, target_x
,
21400 MOVE_TO_POS
| MOVE_TO_X
);
21401 /* If we arrived at target_x, that _is_ the last
21402 character on the previous line. */
21403 if (it
.current_x
!= target_x
)
21404 target_x
= it
.current_x
- 1;
21405 RESTORE_IT (&it
, &it2
, it_data
);
21412 || (target_x
>= it
.last_visible_x
21413 && it
.line_wrap
!= TRUNCATE
))
21416 move_it_by_lines (&it
, 0);
21417 move_it_by_lines (&it
, 1);
21422 /* Move to the target X coordinate. */
21423 #ifdef HAVE_WINDOW_SYSTEM
21424 /* On GUI frames, as we don't know the X coordinate of the
21425 character to the left of point, moving point to the left
21426 requires walking, one grapheme cluster at a time, until we
21427 find ourself at a place immediately to the left of the
21428 character at point. */
21429 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
21431 struct text_pos new_pos
;
21432 enum move_it_result rc
= MOVE_X_REACHED
;
21434 if (it
.current_x
== 0)
21435 get_next_display_element (&it
);
21436 if (it
.what
== IT_COMPOSITION
)
21438 new_pos
.charpos
= it
.cmp_it
.charpos
;
21439 new_pos
.bytepos
= -1;
21442 new_pos
= it
.current
.pos
;
21444 while (it
.current_x
+ it
.pixel_width
<= target_x
21445 && (rc
== MOVE_X_REACHED
21446 /* Under word-wrap, move_it_in_display_line_to
21447 stops at correct coordinates, but sometimes
21448 returns MOVE_POS_MATCH_OR_ZV. */
21449 || (it
.line_wrap
== WORD_WRAP
21450 && rc
== MOVE_POS_MATCH_OR_ZV
)))
21452 int new_x
= it
.current_x
+ it
.pixel_width
;
21454 /* For composed characters, we want the position of the
21455 first character in the grapheme cluster (usually, the
21456 composition's base character), whereas it.current
21457 might give us the position of the _last_ one, e.g. if
21458 the composition is rendered in reverse due to bidi
21460 if (it
.what
== IT_COMPOSITION
)
21462 new_pos
.charpos
= it
.cmp_it
.charpos
;
21463 new_pos
.bytepos
= -1;
21466 new_pos
= it
.current
.pos
;
21467 if (new_x
== it
.current_x
)
21469 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
21470 MOVE_TO_POS
| MOVE_TO_X
);
21471 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
21474 /* The previous position we saw in the loop is the one we
21476 if (new_pos
.bytepos
== -1)
21477 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
21478 it
.current
.pos
= new_pos
;
21482 if (it
.current_x
!= target_x
)
21483 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
21485 /* When lines are truncated, the above loop will stop at the
21486 window edge. But we want to get to the end of line, even if
21487 it is beyond the window edge; automatic hscroll will then
21488 scroll the window to show point as appropriate. */
21489 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
21490 && get_next_display_element (&it
))
21492 struct text_pos new_pos
= it
.current
.pos
;
21494 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
21496 set_iterator_to_next (&it
, 0);
21497 if (it
.method
== GET_FROM_BUFFER
)
21498 new_pos
= it
.current
.pos
;
21499 if (!get_next_display_element (&it
))
21503 it
.current
.pos
= new_pos
;
21506 /* If we ended up in a display string that covers point, move to
21507 buffer position to the right in the visual order. */
21510 while (IT_CHARPOS (it
) == PT
)
21512 set_iterator_to_next (&it
, 0);
21513 if (!get_next_display_element (&it
))
21518 /* Move point to that position. */
21519 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
21522 return make_number (PT
);
21524 #undef ROW_GLYPH_NEWLINE_P
21527 DEFUN ("bidi-resolved-levels", Fbidi_resolved_levels
,
21528 Sbidi_resolved_levels
, 0, 1, 0,
21529 doc
: /* Return the resolved bidirectional levels of characters at VPOS.
21531 The resolved levels are produced by the Emacs bidi reordering engine
21532 that implements the UBA, the Unicode Bidirectional Algorithm. Please
21533 read the Unicode Standard Annex 9 (UAX#9) for background information
21534 about these levels.
21536 VPOS is the zero-based number of the current window's screen line
21537 for which to produce the resolved levels. If VPOS is nil or omitted,
21538 it defaults to the screen line of point. If the window displays a
21539 header line, VPOS of zero will report on the header line, and first
21540 line of text in the window will have VPOS of 1.
21542 Value is an array of resolved levels, indexed by glyph number.
21543 Glyphs are numbered from zero starting from the beginning of the
21544 screen line, i.e. the left edge of the window for left-to-right lines
21545 and from the right edge for right-to-left lines. The resolved levels
21546 are produced only for the window's text area; text in display margins
21549 If the selected window's display is not up-to-date, or if the specified
21550 screen line does not display text, this function returns nil. It is
21551 highly recommended to bind this function to some simple key, like F8,
21552 in order to avoid these problems.
21554 This function exists mainly for testing the correctness of the
21555 Emacs UBA implementation, in particular with the test suite. */)
21558 struct window
*w
= XWINDOW (selected_window
);
21559 struct buffer
*b
= XBUFFER (w
->contents
);
21561 struct glyph_row
*row
;
21565 int d1
, d2
, d3
, d4
, d5
;
21567 pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &nrow
);
21571 CHECK_NUMBER_COERCE_MARKER (vpos
);
21572 nrow
= XINT (vpos
);
21575 /* We require up-to-date glyph matrix for this window. */
21576 if (w
->window_end_valid
21577 && !windows_or_buffers_changed
21579 && !b
->clip_changed
21580 && !b
->prevent_redisplay_optimizations_p
21581 && !window_outdated (w
)
21583 && nrow
< w
->current_matrix
->nrows
21584 && (row
= MATRIX_ROW (w
->current_matrix
, nrow
))->enabled_p
21585 && MATRIX_ROW_DISPLAYS_TEXT_P (row
))
21587 struct glyph
*g
, *e
, *g1
;
21589 Lisp_Object levels
;
21591 if (!row
->reversed_p
) /* Left-to-right glyph row. */
21593 g
= g1
= row
->glyphs
[TEXT_AREA
];
21594 e
= g
+ row
->used
[TEXT_AREA
];
21596 /* Skip over glyphs at the start of the row that was
21597 generated by redisplay for its own needs. */
21599 && INTEGERP (g
->object
)
21604 /* Count the "interesting" glyphs in this row. */
21605 for (nglyphs
= 0; g
< e
&& !INTEGERP (g
->object
); g
++)
21608 /* Create and fill the array. */
21609 levels
= make_uninit_vector (nglyphs
);
21610 for (i
= 0; g1
< g
; i
++, g1
++)
21611 ASET (levels
, i
, make_number (g1
->resolved_level
));
21613 else /* Right-to-left glyph row. */
21615 g
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
21616 e
= row
->glyphs
[TEXT_AREA
] - 1;
21618 && INTEGERP (g
->object
)
21622 for (nglyphs
= 0; g
> e
&& !INTEGERP (g
->object
); g
--)
21624 levels
= make_uninit_vector (nglyphs
);
21625 for (i
= 0; g1
> g
; i
++, g1
--)
21626 ASET (levels
, i
, make_number (g1
->resolved_level
));
21636 /***********************************************************************
21638 ***********************************************************************/
21640 /* Redisplay the menu bar in the frame for window W.
21642 The menu bar of X frames that don't have X toolkit support is
21643 displayed in a special window W->frame->menu_bar_window.
21645 The menu bar of terminal frames is treated specially as far as
21646 glyph matrices are concerned. Menu bar lines are not part of
21647 windows, so the update is done directly on the frame matrix rows
21648 for the menu bar. */
21651 display_menu_bar (struct window
*w
)
21653 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21658 /* Don't do all this for graphical frames. */
21660 if (FRAME_W32_P (f
))
21663 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
21669 if (FRAME_NS_P (f
))
21671 #endif /* HAVE_NS */
21673 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
21674 eassert (!FRAME_WINDOW_P (f
));
21675 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
21676 it
.first_visible_x
= 0;
21677 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
21678 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
21679 if (FRAME_WINDOW_P (f
))
21681 /* Menu bar lines are displayed in the desired matrix of the
21682 dummy window menu_bar_window. */
21683 struct window
*menu_w
;
21684 menu_w
= XWINDOW (f
->menu_bar_window
);
21685 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
21687 it
.first_visible_x
= 0;
21688 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
21691 #endif /* not USE_X_TOOLKIT and not USE_GTK */
21693 /* This is a TTY frame, i.e. character hpos/vpos are used as
21695 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
21697 it
.first_visible_x
= 0;
21698 it
.last_visible_x
= FRAME_COLS (f
);
21701 /* FIXME: This should be controlled by a user option. See the
21702 comments in redisplay_tool_bar and display_mode_line about
21704 it
.paragraph_embedding
= L2R
;
21706 /* Clear all rows of the menu bar. */
21707 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
21709 struct glyph_row
*row
= it
.glyph_row
+ i
;
21710 clear_glyph_row (row
);
21711 row
->enabled_p
= true;
21712 row
->full_width_p
= 1;
21713 row
->reversed_p
= false;
21716 /* Display all items of the menu bar. */
21717 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
21718 for (i
= 0; i
< ASIZE (items
); i
+= 4)
21720 Lisp_Object string
;
21722 /* Stop at nil string. */
21723 string
= AREF (items
, i
+ 1);
21727 /* Remember where item was displayed. */
21728 ASET (items
, i
+ 3, make_number (it
.hpos
));
21730 /* Display the item, pad with one space. */
21731 if (it
.current_x
< it
.last_visible_x
)
21732 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
21733 SCHARS (string
) + 1, 0, 0, -1);
21736 /* Fill out the line with spaces. */
21737 if (it
.current_x
< it
.last_visible_x
)
21738 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
21740 /* Compute the total height of the lines. */
21741 compute_line_metrics (&it
);
21744 /* Deep copy of a glyph row, including the glyphs. */
21746 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
21748 struct glyph
*pointers
[1 + LAST_AREA
];
21749 int to_used
= to
->used
[TEXT_AREA
];
21751 /* Save glyph pointers of TO. */
21752 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
21754 /* Do a structure assignment. */
21757 /* Restore original glyph pointers of TO. */
21758 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
21760 /* Copy the glyphs. */
21761 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
21762 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
21764 /* If we filled only part of the TO row, fill the rest with
21765 space_glyph (which will display as empty space). */
21766 if (to_used
> from
->used
[TEXT_AREA
])
21767 fill_up_frame_row_with_spaces (to
, to_used
);
21770 /* Display one menu item on a TTY, by overwriting the glyphs in the
21771 frame F's desired glyph matrix with glyphs produced from the menu
21772 item text. Called from term.c to display TTY drop-down menus one
21775 ITEM_TEXT is the menu item text as a C string.
21777 FACE_ID is the face ID to be used for this menu item. FACE_ID
21778 could specify one of 3 faces: a face for an enabled item, a face
21779 for a disabled item, or a face for a selected item.
21781 X and Y are coordinates of the first glyph in the frame's desired
21782 matrix to be overwritten by the menu item. Since this is a TTY, Y
21783 is the zero-based number of the glyph row and X is the zero-based
21784 glyph number in the row, starting from left, where to start
21785 displaying the item.
21787 SUBMENU non-zero means this menu item drops down a submenu, which
21788 should be indicated by displaying a proper visual cue after the
21792 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
21793 int x
, int y
, int submenu
)
21796 struct frame
*f
= SELECTED_FRAME ();
21797 struct window
*w
= XWINDOW (f
->selected_window
);
21798 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
21799 struct glyph_row
*row
;
21800 size_t item_len
= strlen (item_text
);
21802 eassert (FRAME_TERMCAP_P (f
));
21804 /* Don't write beyond the matrix's last row. This can happen for
21805 TTY screens that are not high enough to show the entire menu.
21806 (This is actually a bit of defensive programming, as
21807 tty_menu_display already limits the number of menu items to one
21808 less than the number of screen lines.) */
21809 if (y
>= f
->desired_matrix
->nrows
)
21812 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
21813 it
.first_visible_x
= 0;
21814 it
.last_visible_x
= FRAME_COLS (f
) - 1;
21815 row
= it
.glyph_row
;
21816 /* Start with the row contents from the current matrix. */
21817 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
21818 saved_width
= row
->full_width_p
;
21819 row
->full_width_p
= 1;
21820 saved_reversed
= row
->reversed_p
;
21821 row
->reversed_p
= 0;
21822 row
->enabled_p
= true;
21824 /* Arrange for the menu item glyphs to start at (X,Y) and have the
21826 eassert (x
< f
->desired_matrix
->matrix_w
);
21827 it
.current_x
= it
.hpos
= x
;
21828 it
.current_y
= it
.vpos
= y
;
21829 saved_used
= row
->used
[TEXT_AREA
];
21830 saved_truncated
= row
->truncated_on_right_p
;
21831 row
->used
[TEXT_AREA
] = x
;
21832 it
.face_id
= face_id
;
21833 it
.line_wrap
= TRUNCATE
;
21835 /* FIXME: This should be controlled by a user option. See the
21836 comments in redisplay_tool_bar and display_mode_line about this.
21837 Also, if paragraph_embedding could ever be R2L, changes will be
21838 needed to avoid shifting to the right the row characters in
21839 term.c:append_glyph. */
21840 it
.paragraph_embedding
= L2R
;
21842 /* Pad with a space on the left. */
21843 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
21845 /* Display the menu item, pad with spaces to WIDTH. */
21848 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21849 item_len
, 0, FRAME_COLS (f
) - 1, -1);
21851 /* Indicate with " >" that there's a submenu. */
21852 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
21853 FRAME_COLS (f
) - 1, -1);
21856 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21857 width
, 0, FRAME_COLS (f
) - 1, -1);
21859 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
21860 row
->truncated_on_right_p
= saved_truncated
;
21861 row
->hash
= row_hash (row
);
21862 row
->full_width_p
= saved_width
;
21863 row
->reversed_p
= saved_reversed
;
21866 /***********************************************************************
21868 ***********************************************************************/
21870 /* Redisplay mode lines in the window tree whose root is WINDOW. If
21871 FORCE is non-zero, redisplay mode lines unconditionally.
21872 Otherwise, redisplay only mode lines that are garbaged. Value is
21873 the number of windows whose mode lines were redisplayed. */
21876 redisplay_mode_lines (Lisp_Object window
, bool force
)
21880 while (!NILP (window
))
21882 struct window
*w
= XWINDOW (window
);
21884 if (WINDOWP (w
->contents
))
21885 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
21887 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
21888 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
21890 struct text_pos lpoint
;
21891 struct buffer
*old
= current_buffer
;
21893 /* Set the window's buffer for the mode line display. */
21894 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
21895 set_buffer_internal_1 (XBUFFER (w
->contents
));
21897 /* Point refers normally to the selected window. For any
21898 other window, set up appropriate value. */
21899 if (!EQ (window
, selected_window
))
21901 struct text_pos pt
;
21903 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
21904 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
21907 /* Display mode lines. */
21908 clear_glyph_matrix (w
->desired_matrix
);
21909 if (display_mode_lines (w
))
21912 /* Restore old settings. */
21913 set_buffer_internal_1 (old
);
21914 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
21924 /* Display the mode and/or header line of window W. Value is the
21925 sum number of mode lines and header lines displayed. */
21928 display_mode_lines (struct window
*w
)
21930 Lisp_Object old_selected_window
= selected_window
;
21931 Lisp_Object old_selected_frame
= selected_frame
;
21932 Lisp_Object new_frame
= w
->frame
;
21933 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
21936 selected_frame
= new_frame
;
21937 /* FIXME: If we were to allow the mode-line's computation changing the buffer
21938 or window's point, then we'd need select_window_1 here as well. */
21939 XSETWINDOW (selected_window
, w
);
21940 XFRAME (new_frame
)->selected_window
= selected_window
;
21942 /* These will be set while the mode line specs are processed. */
21943 line_number_displayed
= 0;
21944 w
->column_number_displayed
= -1;
21946 if (WINDOW_WANTS_MODELINE_P (w
))
21948 struct window
*sel_w
= XWINDOW (old_selected_window
);
21950 /* Select mode line face based on the real selected window. */
21951 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
21952 BVAR (current_buffer
, mode_line_format
));
21956 if (WINDOW_WANTS_HEADER_LINE_P (w
))
21958 display_mode_line (w
, HEADER_LINE_FACE_ID
,
21959 BVAR (current_buffer
, header_line_format
));
21963 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
21964 selected_frame
= old_selected_frame
;
21965 selected_window
= old_selected_window
;
21967 w
->must_be_updated_p
= true;
21972 /* Display mode or header line of window W. FACE_ID specifies which
21973 line to display; it is either MODE_LINE_FACE_ID or
21974 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
21975 display. Value is the pixel height of the mode/header line
21979 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
21983 ptrdiff_t count
= SPECPDL_INDEX ();
21985 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21986 /* Don't extend on a previously drawn mode-line.
21987 This may happen if called from pos_visible_p. */
21988 it
.glyph_row
->enabled_p
= false;
21989 prepare_desired_row (w
, it
.glyph_row
, true);
21991 it
.glyph_row
->mode_line_p
= 1;
21993 /* FIXME: This should be controlled by a user option. But
21994 supporting such an option is not trivial, since the mode line is
21995 made up of many separate strings. */
21996 it
.paragraph_embedding
= L2R
;
21998 record_unwind_protect (unwind_format_mode_line
,
21999 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
22001 mode_line_target
= MODE_LINE_DISPLAY
;
22003 /* Temporarily make frame's keyboard the current kboard so that
22004 kboard-local variables in the mode_line_format will get the right
22006 push_kboard (FRAME_KBOARD (it
.f
));
22007 record_unwind_save_match_data ();
22008 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
22011 unbind_to (count
, Qnil
);
22013 /* Fill up with spaces. */
22014 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
22016 compute_line_metrics (&it
);
22017 it
.glyph_row
->full_width_p
= 1;
22018 it
.glyph_row
->continued_p
= 0;
22019 it
.glyph_row
->truncated_on_left_p
= 0;
22020 it
.glyph_row
->truncated_on_right_p
= 0;
22022 /* Make a 3D mode-line have a shadow at its right end. */
22023 face
= FACE_FROM_ID (it
.f
, face_id
);
22024 extend_face_to_end_of_line (&it
);
22025 if (face
->box
!= FACE_NO_BOX
)
22027 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
22028 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
22029 last
->right_box_line_p
= 1;
22032 return it
.glyph_row
->height
;
22035 /* Move element ELT in LIST to the front of LIST.
22036 Return the updated list. */
22039 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
22041 register Lisp_Object tail
, prev
;
22042 register Lisp_Object tem
;
22046 while (CONSP (tail
))
22052 /* Splice out the link TAIL. */
22054 list
= XCDR (tail
);
22056 Fsetcdr (prev
, XCDR (tail
));
22058 /* Now make it the first. */
22059 Fsetcdr (tail
, list
);
22064 tail
= XCDR (tail
);
22068 /* Not found--return unchanged LIST. */
22072 /* Contribute ELT to the mode line for window IT->w. How it
22073 translates into text depends on its data type.
22075 IT describes the display environment in which we display, as usual.
22077 DEPTH is the depth in recursion. It is used to prevent
22078 infinite recursion here.
22080 FIELD_WIDTH is the number of characters the display of ELT should
22081 occupy in the mode line, and PRECISION is the maximum number of
22082 characters to display from ELT's representation. See
22083 display_string for details.
22085 Returns the hpos of the end of the text generated by ELT.
22087 PROPS is a property list to add to any string we encounter.
22089 If RISKY is nonzero, remove (disregard) any properties in any string
22090 we encounter, and ignore :eval and :propertize.
22092 The global variable `mode_line_target' determines whether the
22093 output is passed to `store_mode_line_noprop',
22094 `store_mode_line_string', or `display_string'. */
22097 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
22098 Lisp_Object elt
, Lisp_Object props
, int risky
)
22100 int n
= 0, field
, prec
;
22105 elt
= build_string ("*too-deep*");
22109 switch (XTYPE (elt
))
22113 /* A string: output it and check for %-constructs within it. */
22115 ptrdiff_t offset
= 0;
22117 if (SCHARS (elt
) > 0
22118 && (!NILP (props
) || risky
))
22120 Lisp_Object oprops
, aelt
;
22121 oprops
= Ftext_properties_at (make_number (0), elt
);
22123 /* If the starting string's properties are not what
22124 we want, translate the string. Also, if the string
22125 is risky, do that anyway. */
22127 if (NILP (Fequal (props
, oprops
)) || risky
)
22129 /* If the starting string has properties,
22130 merge the specified ones onto the existing ones. */
22131 if (! NILP (oprops
) && !risky
)
22135 oprops
= Fcopy_sequence (oprops
);
22137 while (CONSP (tem
))
22139 oprops
= Fplist_put (oprops
, XCAR (tem
),
22140 XCAR (XCDR (tem
)));
22141 tem
= XCDR (XCDR (tem
));
22146 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
22147 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
22149 /* AELT is what we want. Move it to the front
22150 without consing. */
22152 mode_line_proptrans_alist
22153 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
22159 /* If AELT has the wrong props, it is useless.
22160 so get rid of it. */
22162 mode_line_proptrans_alist
22163 = Fdelq (aelt
, mode_line_proptrans_alist
);
22165 elt
= Fcopy_sequence (elt
);
22166 Fset_text_properties (make_number (0), Flength (elt
),
22168 /* Add this item to mode_line_proptrans_alist. */
22169 mode_line_proptrans_alist
22170 = Fcons (Fcons (elt
, props
),
22171 mode_line_proptrans_alist
);
22172 /* Truncate mode_line_proptrans_alist
22173 to at most 50 elements. */
22174 tem
= Fnthcdr (make_number (50),
22175 mode_line_proptrans_alist
);
22177 XSETCDR (tem
, Qnil
);
22186 prec
= precision
- n
;
22187 switch (mode_line_target
)
22189 case MODE_LINE_NOPROP
:
22190 case MODE_LINE_TITLE
:
22191 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
22193 case MODE_LINE_STRING
:
22194 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
22196 case MODE_LINE_DISPLAY
:
22197 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
22198 0, prec
, 0, STRING_MULTIBYTE (elt
));
22205 /* Handle the non-literal case. */
22207 while ((precision
<= 0 || n
< precision
)
22208 && SREF (elt
, offset
) != 0
22209 && (mode_line_target
!= MODE_LINE_DISPLAY
22210 || it
->current_x
< it
->last_visible_x
))
22212 ptrdiff_t last_offset
= offset
;
22214 /* Advance to end of string or next format specifier. */
22215 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
22218 if (offset
- 1 != last_offset
)
22220 ptrdiff_t nchars
, nbytes
;
22222 /* Output to end of string or up to '%'. Field width
22223 is length of string. Don't output more than
22224 PRECISION allows us. */
22227 prec
= c_string_width (SDATA (elt
) + last_offset
,
22228 offset
- last_offset
, precision
- n
,
22231 switch (mode_line_target
)
22233 case MODE_LINE_NOPROP
:
22234 case MODE_LINE_TITLE
:
22235 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
22237 case MODE_LINE_STRING
:
22239 ptrdiff_t bytepos
= last_offset
;
22240 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22241 ptrdiff_t endpos
= (precision
<= 0
22242 ? string_byte_to_char (elt
, offset
)
22243 : charpos
+ nchars
);
22245 n
+= store_mode_line_string (NULL
,
22246 Fsubstring (elt
, make_number (charpos
),
22247 make_number (endpos
)),
22251 case MODE_LINE_DISPLAY
:
22253 ptrdiff_t bytepos
= last_offset
;
22254 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
22256 if (precision
<= 0)
22257 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
22258 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
22260 STRING_MULTIBYTE (elt
));
22265 else /* c == '%' */
22267 ptrdiff_t percent_position
= offset
;
22269 /* Get the specified minimum width. Zero means
22272 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
22273 field
= field
* 10 + c
- '0';
22275 /* Don't pad beyond the total padding allowed. */
22276 if (field_width
- n
> 0 && field
> field_width
- n
)
22277 field
= field_width
- n
;
22279 /* Note that either PRECISION <= 0 or N < PRECISION. */
22280 prec
= precision
- n
;
22283 n
+= display_mode_element (it
, depth
, field
, prec
,
22284 Vglobal_mode_string
, props
,
22289 ptrdiff_t bytepos
, charpos
;
22291 Lisp_Object string
;
22293 bytepos
= percent_position
;
22294 charpos
= (STRING_MULTIBYTE (elt
)
22295 ? string_byte_to_char (elt
, bytepos
)
22297 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
22298 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
22300 switch (mode_line_target
)
22302 case MODE_LINE_NOPROP
:
22303 case MODE_LINE_TITLE
:
22304 n
+= store_mode_line_noprop (spec
, field
, prec
);
22306 case MODE_LINE_STRING
:
22308 Lisp_Object tem
= build_string (spec
);
22309 props
= Ftext_properties_at (make_number (charpos
), elt
);
22310 /* Should only keep face property in props */
22311 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
22314 case MODE_LINE_DISPLAY
:
22316 int nglyphs_before
, nwritten
;
22318 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
22319 nwritten
= display_string (spec
, string
, elt
,
22324 /* Assign to the glyphs written above the
22325 string where the `%x' came from, position
22329 struct glyph
*glyph
22330 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
22334 for (i
= 0; i
< nwritten
; ++i
)
22336 glyph
[i
].object
= elt
;
22337 glyph
[i
].charpos
= charpos
;
22354 /* A symbol: process the value of the symbol recursively
22355 as if it appeared here directly. Avoid error if symbol void.
22356 Special case: if value of symbol is a string, output the string
22359 register Lisp_Object tem
;
22361 /* If the variable is not marked as risky to set
22362 then its contents are risky to use. */
22363 if (NILP (Fget (elt
, Qrisky_local_variable
)))
22366 tem
= Fboundp (elt
);
22369 tem
= Fsymbol_value (elt
);
22370 /* If value is a string, output that string literally:
22371 don't check for % within it. */
22375 if (!EQ (tem
, elt
))
22377 /* Give up right away for nil or t. */
22387 register Lisp_Object car
, tem
;
22389 /* A cons cell: five distinct cases.
22390 If first element is :eval or :propertize, do something special.
22391 If first element is a string or a cons, process all the elements
22392 and effectively concatenate them.
22393 If first element is a negative number, truncate displaying cdr to
22394 at most that many characters. If positive, pad (with spaces)
22395 to at least that many characters.
22396 If first element is a symbol, process the cadr or caddr recursively
22397 according to whether the symbol's value is non-nil or nil. */
22399 if (EQ (car
, QCeval
))
22401 /* An element of the form (:eval FORM) means evaluate FORM
22402 and use the result as mode line elements. */
22407 if (CONSP (XCDR (elt
)))
22410 spec
= safe__eval (true, XCAR (XCDR (elt
)));
22411 n
+= display_mode_element (it
, depth
, field_width
- n
,
22412 precision
- n
, spec
, props
,
22416 else if (EQ (car
, QCpropertize
))
22418 /* An element of the form (:propertize ELT PROPS...)
22419 means display ELT but applying properties PROPS. */
22424 if (CONSP (XCDR (elt
)))
22425 n
+= display_mode_element (it
, depth
, field_width
- n
,
22426 precision
- n
, XCAR (XCDR (elt
)),
22427 XCDR (XCDR (elt
)), risky
);
22429 else if (SYMBOLP (car
))
22431 tem
= Fboundp (car
);
22435 /* elt is now the cdr, and we know it is a cons cell.
22436 Use its car if CAR has a non-nil value. */
22439 tem
= Fsymbol_value (car
);
22446 /* Symbol's value is nil (or symbol is unbound)
22447 Get the cddr of the original list
22448 and if possible find the caddr and use that. */
22452 else if (!CONSP (elt
))
22457 else if (INTEGERP (car
))
22459 register int lim
= XINT (car
);
22463 /* Negative int means reduce maximum width. */
22464 if (precision
<= 0)
22467 precision
= min (precision
, -lim
);
22471 /* Padding specified. Don't let it be more than
22472 current maximum. */
22474 lim
= min (precision
, lim
);
22476 /* If that's more padding than already wanted, queue it.
22477 But don't reduce padding already specified even if
22478 that is beyond the current truncation point. */
22479 field_width
= max (lim
, field_width
);
22483 else if (STRINGP (car
) || CONSP (car
))
22485 Lisp_Object halftail
= elt
;
22489 && (precision
<= 0 || n
< precision
))
22491 n
+= display_mode_element (it
, depth
,
22492 /* Do padding only after the last
22493 element in the list. */
22494 (! CONSP (XCDR (elt
))
22497 precision
- n
, XCAR (elt
),
22501 if ((len
& 1) == 0)
22502 halftail
= XCDR (halftail
);
22503 /* Check for cycle. */
22504 if (EQ (halftail
, elt
))
22513 elt
= build_string ("*invalid*");
22517 /* Pad to FIELD_WIDTH. */
22518 if (field_width
> 0 && n
< field_width
)
22520 switch (mode_line_target
)
22522 case MODE_LINE_NOPROP
:
22523 case MODE_LINE_TITLE
:
22524 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
22526 case MODE_LINE_STRING
:
22527 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
22529 case MODE_LINE_DISPLAY
:
22530 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
22539 /* Store a mode-line string element in mode_line_string_list.
22541 If STRING is non-null, display that C string. Otherwise, the Lisp
22542 string LISP_STRING is displayed.
22544 FIELD_WIDTH is the minimum number of output glyphs to produce.
22545 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22546 with spaces. FIELD_WIDTH <= 0 means don't pad.
22548 PRECISION is the maximum number of characters to output from
22549 STRING. PRECISION <= 0 means don't truncate the string.
22551 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
22552 properties to the string.
22554 PROPS are the properties to add to the string.
22555 The mode_line_string_face face property is always added to the string.
22559 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
22560 int field_width
, int precision
, Lisp_Object props
)
22565 if (string
!= NULL
)
22567 len
= strlen (string
);
22568 if (precision
> 0 && len
> precision
)
22570 lisp_string
= make_string (string
, len
);
22572 props
= mode_line_string_face_prop
;
22573 else if (!NILP (mode_line_string_face
))
22575 Lisp_Object face
= Fplist_get (props
, Qface
);
22576 props
= Fcopy_sequence (props
);
22578 face
= mode_line_string_face
;
22580 face
= list2 (face
, mode_line_string_face
);
22581 props
= Fplist_put (props
, Qface
, face
);
22583 Fadd_text_properties (make_number (0), make_number (len
),
22584 props
, lisp_string
);
22588 len
= XFASTINT (Flength (lisp_string
));
22589 if (precision
> 0 && len
> precision
)
22592 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
22595 if (!NILP (mode_line_string_face
))
22599 props
= Ftext_properties_at (make_number (0), lisp_string
);
22600 face
= Fplist_get (props
, Qface
);
22602 face
= mode_line_string_face
;
22604 face
= list2 (face
, mode_line_string_face
);
22605 props
= list2 (Qface
, face
);
22607 lisp_string
= Fcopy_sequence (lisp_string
);
22610 Fadd_text_properties (make_number (0), make_number (len
),
22611 props
, lisp_string
);
22616 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22620 if (field_width
> len
)
22622 field_width
-= len
;
22623 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
22625 Fadd_text_properties (make_number (0), make_number (field_width
),
22626 props
, lisp_string
);
22627 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
22635 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
22637 doc
: /* Format a string out of a mode line format specification.
22638 First arg FORMAT specifies the mode line format (see `mode-line-format'
22639 for details) to use.
22641 By default, the format is evaluated for the currently selected window.
22643 Optional second arg FACE specifies the face property to put on all
22644 characters for which no face is specified. The value nil means the
22645 default face. The value t means whatever face the window's mode line
22646 currently uses (either `mode-line' or `mode-line-inactive',
22647 depending on whether the window is the selected window or not).
22648 An integer value means the value string has no text
22651 Optional third and fourth args WINDOW and BUFFER specify the window
22652 and buffer to use as the context for the formatting (defaults
22653 are the selected window and the WINDOW's buffer). */)
22654 (Lisp_Object format
, Lisp_Object face
,
22655 Lisp_Object window
, Lisp_Object buffer
)
22660 struct buffer
*old_buffer
= NULL
;
22662 int no_props
= INTEGERP (face
);
22663 ptrdiff_t count
= SPECPDL_INDEX ();
22665 int string_start
= 0;
22667 w
= decode_any_window (window
);
22668 XSETWINDOW (window
, w
);
22671 buffer
= w
->contents
;
22672 CHECK_BUFFER (buffer
);
22674 /* Make formatting the modeline a non-op when noninteractive, otherwise
22675 there will be problems later caused by a partially initialized frame. */
22676 if (NILP (format
) || noninteractive
)
22677 return empty_unibyte_string
;
22682 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
22683 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
22684 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
22685 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
22686 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
22687 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
22688 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
22691 old_buffer
= current_buffer
;
22693 /* Save things including mode_line_proptrans_alist,
22694 and set that to nil so that we don't alter the outer value. */
22695 record_unwind_protect (unwind_format_mode_line
,
22696 format_mode_line_unwind_data
22697 (XFRAME (WINDOW_FRAME (w
)),
22698 old_buffer
, selected_window
, 1));
22699 mode_line_proptrans_alist
= Qnil
;
22701 Fselect_window (window
, Qt
);
22702 set_buffer_internal_1 (XBUFFER (buffer
));
22704 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
22708 mode_line_target
= MODE_LINE_NOPROP
;
22709 mode_line_string_face_prop
= Qnil
;
22710 mode_line_string_list
= Qnil
;
22711 string_start
= MODE_LINE_NOPROP_LEN (0);
22715 mode_line_target
= MODE_LINE_STRING
;
22716 mode_line_string_list
= Qnil
;
22717 mode_line_string_face
= face
;
22718 mode_line_string_face_prop
22719 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
22722 push_kboard (FRAME_KBOARD (it
.f
));
22723 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
22728 len
= MODE_LINE_NOPROP_LEN (string_start
);
22729 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
22733 mode_line_string_list
= Fnreverse (mode_line_string_list
);
22734 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
22735 empty_unibyte_string
);
22738 unbind_to (count
, Qnil
);
22742 /* Write a null-terminated, right justified decimal representation of
22743 the positive integer D to BUF using a minimal field width WIDTH. */
22746 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
22748 register char *p
= buf
;
22756 *p
++ = d
% 10 + '0';
22761 for (width
-= (int) (p
- buf
); width
> 0; --width
)
22772 /* Write a null-terminated, right justified decimal and "human
22773 readable" representation of the nonnegative integer D to BUF using
22774 a minimal field width WIDTH. D should be smaller than 999.5e24. */
22776 static const char power_letter
[] =
22790 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
22792 /* We aim to represent the nonnegative integer D as
22793 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
22794 ptrdiff_t quotient
= d
;
22796 /* -1 means: do not use TENTHS. */
22800 /* Length of QUOTIENT.TENTHS as a string. */
22806 if (quotient
>= 1000)
22808 /* Scale to the appropriate EXPONENT. */
22811 remainder
= quotient
% 1000;
22815 while (quotient
>= 1000);
22817 /* Round to nearest and decide whether to use TENTHS or not. */
22820 tenths
= remainder
/ 100;
22821 if (remainder
% 100 >= 50)
22828 if (quotient
== 10)
22836 if (remainder
>= 500)
22838 if (quotient
< 999)
22849 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
22850 if (tenths
== -1 && quotient
<= 99)
22857 p
= psuffix
= buf
+ max (width
, length
);
22859 /* Print EXPONENT. */
22860 *psuffix
++ = power_letter
[exponent
];
22863 /* Print TENTHS. */
22866 *--p
= '0' + tenths
;
22870 /* Print QUOTIENT. */
22873 int digit
= quotient
% 10;
22874 *--p
= '0' + digit
;
22876 while ((quotient
/= 10) != 0);
22878 /* Print leading spaces. */
22883 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
22884 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
22885 type of CODING_SYSTEM. Return updated pointer into BUF. */
22887 static unsigned char invalid_eol_type
[] = "(*invalid*)";
22890 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
22893 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
22894 const unsigned char *eol_str
;
22896 /* The EOL conversion we are using. */
22897 Lisp_Object eoltype
;
22899 val
= CODING_SYSTEM_SPEC (coding_system
);
22902 if (!VECTORP (val
)) /* Not yet decided. */
22904 *buf
++ = multibyte
? '-' : ' ';
22906 eoltype
= eol_mnemonic_undecided
;
22907 /* Don't mention EOL conversion if it isn't decided. */
22912 Lisp_Object eolvalue
;
22914 attrs
= AREF (val
, 0);
22915 eolvalue
= AREF (val
, 2);
22918 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
22923 /* The EOL conversion that is normal on this system. */
22925 if (NILP (eolvalue
)) /* Not yet decided. */
22926 eoltype
= eol_mnemonic_undecided
;
22927 else if (VECTORP (eolvalue
)) /* Not yet decided. */
22928 eoltype
= eol_mnemonic_undecided
;
22929 else /* eolvalue is Qunix, Qdos, or Qmac. */
22930 eoltype
= (EQ (eolvalue
, Qunix
)
22931 ? eol_mnemonic_unix
22932 : (EQ (eolvalue
, Qdos
) == 1
22933 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
22939 /* Mention the EOL conversion if it is not the usual one. */
22940 if (STRINGP (eoltype
))
22942 eol_str
= SDATA (eoltype
);
22943 eol_str_len
= SBYTES (eoltype
);
22945 else if (CHARACTERP (eoltype
))
22947 int c
= XFASTINT (eoltype
);
22948 return buf
+ CHAR_STRING (c
, (unsigned char *) buf
);
22952 eol_str
= invalid_eol_type
;
22953 eol_str_len
= sizeof (invalid_eol_type
) - 1;
22955 memcpy (buf
, eol_str
, eol_str_len
);
22956 buf
+= eol_str_len
;
22962 /* Return a string for the output of a mode line %-spec for window W,
22963 generated by character C. FIELD_WIDTH > 0 means pad the string
22964 returned with spaces to that value. Return a Lisp string in
22965 *STRING if the resulting string is taken from that Lisp string.
22967 Note we operate on the current buffer for most purposes. */
22969 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
22971 static const char *
22972 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
22973 Lisp_Object
*string
)
22976 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22977 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
22978 /* We are going to use f->decode_mode_spec_buffer as the buffer to
22979 produce strings from numerical values, so limit preposterously
22980 large values of FIELD_WIDTH to avoid overrunning the buffer's
22981 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
22982 bytes plus the terminating null. */
22983 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
22984 struct buffer
*b
= current_buffer
;
22992 if (!NILP (BVAR (b
, read_only
)))
22994 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22999 /* This differs from %* only for a modified read-only buffer. */
23000 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23002 if (!NILP (BVAR (b
, read_only
)))
23007 /* This differs from %* in ignoring read-only-ness. */
23008 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
23020 if (command_loop_level
> 5)
23022 p
= decode_mode_spec_buf
;
23023 for (i
= 0; i
< command_loop_level
; i
++)
23026 return decode_mode_spec_buf
;
23034 if (command_loop_level
> 5)
23036 p
= decode_mode_spec_buf
;
23037 for (i
= 0; i
< command_loop_level
; i
++)
23040 return decode_mode_spec_buf
;
23047 /* Let lots_of_dashes be a string of infinite length. */
23048 if (mode_line_target
== MODE_LINE_NOPROP
23049 || mode_line_target
== MODE_LINE_STRING
)
23051 if (field_width
<= 0
23052 || field_width
> sizeof (lots_of_dashes
))
23054 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
23055 decode_mode_spec_buf
[i
] = '-';
23056 decode_mode_spec_buf
[i
] = '\0';
23057 return decode_mode_spec_buf
;
23060 return lots_of_dashes
;
23064 obj
= BVAR (b
, name
);
23068 /* %c and %l are ignored in `frame-title-format'.
23069 (In redisplay_internal, the frame title is drawn _before_ the
23070 windows are updated, so the stuff which depends on actual
23071 window contents (such as %l) may fail to render properly, or
23072 even crash emacs.) */
23073 if (mode_line_target
== MODE_LINE_TITLE
)
23077 ptrdiff_t col
= current_column ();
23078 w
->column_number_displayed
= col
;
23079 pint2str (decode_mode_spec_buf
, width
, col
);
23080 return decode_mode_spec_buf
;
23084 #if !defined SYSTEM_MALLOC && !defined HYBRID_MALLOC
23086 if (NILP (Vmemory_full
))
23089 return "!MEM FULL! ";
23096 /* %F displays the frame name. */
23097 if (!NILP (f
->title
))
23098 return SSDATA (f
->title
);
23099 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
23100 return SSDATA (f
->name
);
23104 obj
= BVAR (b
, filename
);
23109 ptrdiff_t size
= ZV
- BEGV
;
23110 pint2str (decode_mode_spec_buf
, width
, size
);
23111 return decode_mode_spec_buf
;
23116 ptrdiff_t size
= ZV
- BEGV
;
23117 pint2hrstr (decode_mode_spec_buf
, width
, size
);
23118 return decode_mode_spec_buf
;
23123 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
23124 ptrdiff_t topline
, nlines
, height
;
23127 /* %c and %l are ignored in `frame-title-format'. */
23128 if (mode_line_target
== MODE_LINE_TITLE
)
23131 startpos
= marker_position (w
->start
);
23132 startpos_byte
= marker_byte_position (w
->start
);
23133 height
= WINDOW_TOTAL_LINES (w
);
23135 /* If we decided that this buffer isn't suitable for line numbers,
23136 don't forget that too fast. */
23137 if (w
->base_line_pos
== -1)
23140 /* If the buffer is very big, don't waste time. */
23141 if (INTEGERP (Vline_number_display_limit
)
23142 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
23144 w
->base_line_pos
= 0;
23145 w
->base_line_number
= 0;
23149 if (w
->base_line_number
> 0
23150 && w
->base_line_pos
> 0
23151 && w
->base_line_pos
<= startpos
)
23153 line
= w
->base_line_number
;
23154 linepos
= w
->base_line_pos
;
23155 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
23160 linepos
= BUF_BEGV (b
);
23161 linepos_byte
= BUF_BEGV_BYTE (b
);
23164 /* Count lines from base line to window start position. */
23165 nlines
= display_count_lines (linepos_byte
,
23169 topline
= nlines
+ line
;
23171 /* Determine a new base line, if the old one is too close
23172 or too far away, or if we did not have one.
23173 "Too close" means it's plausible a scroll-down would
23174 go back past it. */
23175 if (startpos
== BUF_BEGV (b
))
23177 w
->base_line_number
= topline
;
23178 w
->base_line_pos
= BUF_BEGV (b
);
23180 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
23181 || linepos
== BUF_BEGV (b
))
23183 ptrdiff_t limit
= BUF_BEGV (b
);
23184 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
23185 ptrdiff_t position
;
23186 ptrdiff_t distance
=
23187 (height
* 2 + 30) * line_number_display_limit_width
;
23189 if (startpos
- distance
> limit
)
23191 limit
= startpos
- distance
;
23192 limit_byte
= CHAR_TO_BYTE (limit
);
23195 nlines
= display_count_lines (startpos_byte
,
23197 - (height
* 2 + 30),
23199 /* If we couldn't find the lines we wanted within
23200 line_number_display_limit_width chars per line,
23201 give up on line numbers for this window. */
23202 if (position
== limit_byte
&& limit
== startpos
- distance
)
23204 w
->base_line_pos
= -1;
23205 w
->base_line_number
= 0;
23209 w
->base_line_number
= topline
- nlines
;
23210 w
->base_line_pos
= BYTE_TO_CHAR (position
);
23213 /* Now count lines from the start pos to point. */
23214 nlines
= display_count_lines (startpos_byte
,
23215 PT_BYTE
, PT
, &junk
);
23217 /* Record that we did display the line number. */
23218 line_number_displayed
= 1;
23220 /* Make the string to show. */
23221 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
23222 return decode_mode_spec_buf
;
23225 char *p
= decode_mode_spec_buf
;
23226 int pad
= width
- 2;
23232 return decode_mode_spec_buf
;
23238 obj
= BVAR (b
, mode_name
);
23242 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
23248 ptrdiff_t pos
= marker_position (w
->start
);
23249 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23251 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
23253 if (pos
<= BUF_BEGV (b
))
23258 else if (pos
<= BUF_BEGV (b
))
23262 if (total
> 1000000)
23263 /* Do it differently for a large value, to avoid overflow. */
23264 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23266 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23267 /* We can't normally display a 3-digit number,
23268 so get us a 2-digit number that is close. */
23271 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23272 return decode_mode_spec_buf
;
23276 /* Display percentage of size above the bottom of the screen. */
23279 ptrdiff_t toppos
= marker_position (w
->start
);
23280 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
23281 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
23283 if (botpos
>= BUF_ZV (b
))
23285 if (toppos
<= BUF_BEGV (b
))
23292 if (total
> 1000000)
23293 /* Do it differently for a large value, to avoid overflow. */
23294 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
23296 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
23297 /* We can't normally display a 3-digit number,
23298 so get us a 2-digit number that is close. */
23301 if (toppos
<= BUF_BEGV (b
))
23302 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
23304 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
23305 return decode_mode_spec_buf
;
23310 /* status of process */
23311 obj
= Fget_buffer_process (Fcurrent_buffer ());
23313 return "no process";
23315 obj
= Fsymbol_name (Fprocess_status (obj
));
23321 ptrdiff_t count
= inhibit_garbage_collection ();
23322 Lisp_Object curdir
= BVAR (current_buffer
, directory
);
23323 Lisp_Object val
= Qnil
;
23325 if (STRINGP (curdir
))
23326 val
= call1 (intern ("file-remote-p"), curdir
);
23328 unbind_to (count
, Qnil
);
23337 /* coding-system (not including end-of-line format) */
23339 /* coding-system (including end-of-line type) */
23341 int eol_flag
= (c
== 'Z');
23342 char *p
= decode_mode_spec_buf
;
23344 if (! FRAME_WINDOW_P (f
))
23346 /* No need to mention EOL here--the terminal never needs
23347 to do EOL conversion. */
23348 p
= decode_mode_spec_coding (CODING_ID_NAME
23349 (FRAME_KEYBOARD_CODING (f
)->id
),
23351 p
= decode_mode_spec_coding (CODING_ID_NAME
23352 (FRAME_TERMINAL_CODING (f
)->id
),
23355 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
23358 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
23359 #ifdef subprocesses
23360 obj
= Fget_buffer_process (Fcurrent_buffer ());
23361 if (PROCESSP (obj
))
23363 p
= decode_mode_spec_coding
23364 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
23365 p
= decode_mode_spec_coding
23366 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
23368 #endif /* subprocesses */
23371 return decode_mode_spec_buf
;
23378 return SSDATA (obj
);
23385 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
23386 means count lines back from START_BYTE. But don't go beyond
23387 LIMIT_BYTE. Return the number of lines thus found (always
23390 Set *BYTE_POS_PTR to the byte position where we stopped. This is
23391 either the position COUNT lines after/before START_BYTE, if we
23392 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
23396 display_count_lines (ptrdiff_t start_byte
,
23397 ptrdiff_t limit_byte
, ptrdiff_t count
,
23398 ptrdiff_t *byte_pos_ptr
)
23400 register unsigned char *cursor
;
23401 unsigned char *base
;
23403 register ptrdiff_t ceiling
;
23404 register unsigned char *ceiling_addr
;
23405 ptrdiff_t orig_count
= count
;
23407 /* If we are not in selective display mode,
23408 check only for newlines. */
23409 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
23410 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
23414 while (start_byte
< limit_byte
)
23416 ceiling
= BUFFER_CEILING_OF (start_byte
);
23417 ceiling
= min (limit_byte
- 1, ceiling
);
23418 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
23419 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
23423 if (selective_display
)
23425 while (*cursor
!= '\n' && *cursor
!= 015
23426 && ++cursor
!= ceiling_addr
)
23428 if (cursor
== ceiling_addr
)
23433 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
23442 start_byte
+= cursor
- base
;
23443 *byte_pos_ptr
= start_byte
;
23447 while (cursor
< ceiling_addr
);
23449 start_byte
+= ceiling_addr
- base
;
23454 while (start_byte
> limit_byte
)
23456 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
23457 ceiling
= max (limit_byte
, ceiling
);
23458 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
23459 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
23462 if (selective_display
)
23464 while (--cursor
>= ceiling_addr
23465 && *cursor
!= '\n' && *cursor
!= 015)
23467 if (cursor
< ceiling_addr
)
23472 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
23479 start_byte
+= cursor
- base
+ 1;
23480 *byte_pos_ptr
= start_byte
;
23481 /* When scanning backwards, we should
23482 not count the newline posterior to which we stop. */
23483 return - orig_count
- 1;
23486 start_byte
+= ceiling_addr
- base
;
23490 *byte_pos_ptr
= limit_byte
;
23493 return - orig_count
+ count
;
23494 return orig_count
- count
;
23500 /***********************************************************************
23502 ***********************************************************************/
23504 /* Display a NUL-terminated string, starting with index START.
23506 If STRING is non-null, display that C string. Otherwise, the Lisp
23507 string LISP_STRING is displayed. There's a case that STRING is
23508 non-null and LISP_STRING is not nil. It means STRING is a string
23509 data of LISP_STRING. In that case, we display LISP_STRING while
23510 ignoring its text properties.
23512 If FACE_STRING is not nil, FACE_STRING_POS is a position in
23513 FACE_STRING. Display STRING or LISP_STRING with the face at
23514 FACE_STRING_POS in FACE_STRING:
23516 Display the string in the environment given by IT, but use the
23517 standard display table, temporarily.
23519 FIELD_WIDTH is the minimum number of output glyphs to produce.
23520 If STRING has fewer characters than FIELD_WIDTH, pad to the right
23521 with spaces. If STRING has more characters, more than FIELD_WIDTH
23522 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
23524 PRECISION is the maximum number of characters to output from
23525 STRING. PRECISION < 0 means don't truncate the string.
23527 This is roughly equivalent to printf format specifiers:
23529 FIELD_WIDTH PRECISION PRINTF
23530 ----------------------------------------
23536 MULTIBYTE zero means do not display multibyte chars, > 0 means do
23537 display them, and < 0 means obey the current buffer's value of
23538 enable_multibyte_characters.
23540 Value is the number of columns displayed. */
23543 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
23544 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
23545 int field_width
, int precision
, int max_x
, int multibyte
)
23547 int hpos_at_start
= it
->hpos
;
23548 int saved_face_id
= it
->face_id
;
23549 struct glyph_row
*row
= it
->glyph_row
;
23550 ptrdiff_t it_charpos
;
23552 /* Initialize the iterator IT for iteration over STRING beginning
23553 with index START. */
23554 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
23555 precision
, field_width
, multibyte
);
23556 if (string
&& STRINGP (lisp_string
))
23557 /* LISP_STRING is the one returned by decode_mode_spec. We should
23558 ignore its text properties. */
23559 it
->stop_charpos
= it
->end_charpos
;
23561 /* If displaying STRING, set up the face of the iterator from
23562 FACE_STRING, if that's given. */
23563 if (STRINGP (face_string
))
23569 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
23570 0, &endptr
, it
->base_face_id
, 0);
23571 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23572 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
23575 /* Set max_x to the maximum allowed X position. Don't let it go
23576 beyond the right edge of the window. */
23578 max_x
= it
->last_visible_x
;
23580 max_x
= min (max_x
, it
->last_visible_x
);
23582 /* Skip over display elements that are not visible. because IT->w is
23584 if (it
->current_x
< it
->first_visible_x
)
23585 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
23586 MOVE_TO_POS
| MOVE_TO_X
);
23588 row
->ascent
= it
->max_ascent
;
23589 row
->height
= it
->max_ascent
+ it
->max_descent
;
23590 row
->phys_ascent
= it
->max_phys_ascent
;
23591 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
23592 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
23594 if (STRINGP (it
->string
))
23595 it_charpos
= IT_STRING_CHARPOS (*it
);
23597 it_charpos
= IT_CHARPOS (*it
);
23599 /* This condition is for the case that we are called with current_x
23600 past last_visible_x. */
23601 while (it
->current_x
< max_x
)
23603 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
23605 /* Get the next display element. */
23606 if (!get_next_display_element (it
))
23609 /* Produce glyphs. */
23610 x_before
= it
->current_x
;
23611 n_glyphs_before
= row
->used
[TEXT_AREA
];
23612 PRODUCE_GLYPHS (it
);
23614 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
23617 while (i
< nglyphs
)
23619 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
23621 if (it
->line_wrap
!= TRUNCATE
23622 && x
+ glyph
->pixel_width
> max_x
)
23624 /* End of continued line or max_x reached. */
23625 if (CHAR_GLYPH_PADDING_P (*glyph
))
23627 /* A wide character is unbreakable. */
23628 if (row
->reversed_p
)
23629 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23630 - n_glyphs_before
);
23631 row
->used
[TEXT_AREA
] = n_glyphs_before
;
23632 it
->current_x
= x_before
;
23636 if (row
->reversed_p
)
23637 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
23638 - (n_glyphs_before
+ i
));
23639 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
23644 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
23646 /* Glyph is at least partially visible. */
23648 if (x
< it
->first_visible_x
)
23649 row
->x
= x
- it
->first_visible_x
;
23653 /* Glyph is off the left margin of the display area.
23654 Should not happen. */
23658 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
23659 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
23660 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
23661 row
->phys_height
= max (row
->phys_height
,
23662 it
->max_phys_ascent
+ it
->max_phys_descent
);
23663 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
23664 it
->max_extra_line_spacing
);
23665 x
+= glyph
->pixel_width
;
23669 /* Stop if max_x reached. */
23673 /* Stop at line ends. */
23674 if (ITERATOR_AT_END_OF_LINE_P (it
))
23676 it
->continuation_lines_width
= 0;
23680 set_iterator_to_next (it
, 1);
23681 if (STRINGP (it
->string
))
23682 it_charpos
= IT_STRING_CHARPOS (*it
);
23684 it_charpos
= IT_CHARPOS (*it
);
23686 /* Stop if truncating at the right edge. */
23687 if (it
->line_wrap
== TRUNCATE
23688 && it
->current_x
>= it
->last_visible_x
)
23690 /* Add truncation mark, but don't do it if the line is
23691 truncated at a padding space. */
23692 if (it_charpos
< it
->string_nchars
)
23694 if (!FRAME_WINDOW_P (it
->f
))
23698 if (it
->current_x
> it
->last_visible_x
)
23700 if (!row
->reversed_p
)
23702 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
23703 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
23708 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
23709 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
23711 unproduce_glyphs (it
, ii
+ 1);
23712 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
23714 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
23716 row
->used
[TEXT_AREA
] = ii
;
23717 produce_special_glyphs (it
, IT_TRUNCATION
);
23720 produce_special_glyphs (it
, IT_TRUNCATION
);
23722 row
->truncated_on_right_p
= 1;
23728 /* Maybe insert a truncation at the left. */
23729 if (it
->first_visible_x
23732 if (!FRAME_WINDOW_P (it
->f
)
23733 || (row
->reversed_p
23734 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23735 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
23736 insert_left_trunc_glyphs (it
);
23737 row
->truncated_on_left_p
= 1;
23740 it
->face_id
= saved_face_id
;
23742 /* Value is number of columns displayed. */
23743 return it
->hpos
- hpos_at_start
;
23748 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
23749 appears as an element of LIST or as the car of an element of LIST.
23750 If PROPVAL is a list, compare each element against LIST in that
23751 way, and return 1/2 if any element of PROPVAL is found in LIST.
23752 Otherwise return 0. This function cannot quit.
23753 The return value is 2 if the text is invisible but with an ellipsis
23754 and 1 if it's invisible and without an ellipsis. */
23757 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
23759 register Lisp_Object tail
, proptail
;
23761 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
23763 register Lisp_Object tem
;
23765 if (EQ (propval
, tem
))
23767 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
23768 return NILP (XCDR (tem
)) ? 1 : 2;
23771 if (CONSP (propval
))
23773 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
23775 Lisp_Object propelt
;
23776 propelt
= XCAR (proptail
);
23777 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
23779 register Lisp_Object tem
;
23781 if (EQ (propelt
, tem
))
23783 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
23784 return NILP (XCDR (tem
)) ? 1 : 2;
23792 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
23793 doc
: /* Non-nil if the property makes the text invisible.
23794 POS-OR-PROP can be a marker or number, in which case it is taken to be
23795 a position in the current buffer and the value of the `invisible' property
23796 is checked; or it can be some other value, which is then presumed to be the
23797 value of the `invisible' property of the text of interest.
23798 The non-nil value returned can be t for truly invisible text or something
23799 else if the text is replaced by an ellipsis. */)
23800 (Lisp_Object pos_or_prop
)
23803 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
23804 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
23806 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
23807 return (invis
== 0 ? Qnil
23809 : make_number (invis
));
23812 /* Calculate a width or height in pixels from a specification using
23813 the following elements:
23816 NUM - a (fractional) multiple of the default font width/height
23817 (NUM) - specifies exactly NUM pixels
23818 UNIT - a fixed number of pixels, see below.
23819 ELEMENT - size of a display element in pixels, see below.
23820 (NUM . SPEC) - equals NUM * SPEC
23821 (+ SPEC SPEC ...) - add pixel values
23822 (- SPEC SPEC ...) - subtract pixel values
23823 (- SPEC) - negate pixel value
23826 INT or FLOAT - a number constant
23827 SYMBOL - use symbol's (buffer local) variable binding.
23830 in - pixels per inch *)
23831 mm - pixels per 1/1000 meter *)
23832 cm - pixels per 1/100 meter *)
23833 width - width of current font in pixels.
23834 height - height of current font in pixels.
23836 *) using the ratio(s) defined in display-pixels-per-inch.
23840 left-fringe - left fringe width in pixels
23841 right-fringe - right fringe width in pixels
23843 left-margin - left margin width in pixels
23844 right-margin - right margin width in pixels
23846 scroll-bar - scroll-bar area width in pixels
23850 Pixels corresponding to 5 inches:
23853 Total width of non-text areas on left side of window (if scroll-bar is on left):
23854 '(space :width (+ left-fringe left-margin scroll-bar))
23856 Align to first text column (in header line):
23857 '(space :align-to 0)
23859 Align to middle of text area minus half the width of variable `my-image'
23860 containing a loaded image:
23861 '(space :align-to (0.5 . (- text my-image)))
23863 Width of left margin minus width of 1 character in the default font:
23864 '(space :width (- left-margin 1))
23866 Width of left margin minus width of 2 characters in the current font:
23867 '(space :width (- left-margin (2 . width)))
23869 Center 1 character over left-margin (in header line):
23870 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
23872 Different ways to express width of left fringe plus left margin minus one pixel:
23873 '(space :width (- (+ left-fringe left-margin) (1)))
23874 '(space :width (+ left-fringe left-margin (- (1))))
23875 '(space :width (+ left-fringe left-margin (-1)))
23880 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
23881 struct font
*font
, int width_p
, int *align_to
)
23885 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
23886 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
23889 return OK_PIXELS (0);
23891 eassert (FRAME_LIVE_P (it
->f
));
23893 if (SYMBOLP (prop
))
23895 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
23897 char *unit
= SSDATA (SYMBOL_NAME (prop
));
23899 if (unit
[0] == 'i' && unit
[1] == 'n')
23901 else if (unit
[0] == 'm' && unit
[1] == 'm')
23903 else if (unit
[0] == 'c' && unit
[1] == 'm')
23909 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
23910 : FRAME_RES_Y (it
->f
));
23913 return OK_PIXELS (ppi
/ pixels
);
23918 #ifdef HAVE_WINDOW_SYSTEM
23919 if (EQ (prop
, Qheight
))
23920 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
23921 if (EQ (prop
, Qwidth
))
23922 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
23924 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
23925 return OK_PIXELS (1);
23928 if (EQ (prop
, Qtext
))
23929 return OK_PIXELS (width_p
23930 ? window_box_width (it
->w
, TEXT_AREA
)
23931 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
23933 if (align_to
&& *align_to
< 0)
23936 if (EQ (prop
, Qleft
))
23937 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
23938 if (EQ (prop
, Qright
))
23939 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
23940 if (EQ (prop
, Qcenter
))
23941 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
23942 + window_box_width (it
->w
, TEXT_AREA
) / 2);
23943 if (EQ (prop
, Qleft_fringe
))
23944 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23945 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
23946 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
23947 if (EQ (prop
, Qright_fringe
))
23948 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23949 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23950 : window_box_right_offset (it
->w
, TEXT_AREA
));
23951 if (EQ (prop
, Qleft_margin
))
23952 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
23953 if (EQ (prop
, Qright_margin
))
23954 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
23955 if (EQ (prop
, Qscroll_bar
))
23956 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
23958 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23959 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23960 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23965 if (EQ (prop
, Qleft_fringe
))
23966 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
23967 if (EQ (prop
, Qright_fringe
))
23968 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
23969 if (EQ (prop
, Qleft_margin
))
23970 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
23971 if (EQ (prop
, Qright_margin
))
23972 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
23973 if (EQ (prop
, Qscroll_bar
))
23974 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
23977 prop
= buffer_local_value (prop
, it
->w
->contents
);
23978 if (EQ (prop
, Qunbound
))
23982 if (INTEGERP (prop
) || FLOATP (prop
))
23984 int base_unit
= (width_p
23985 ? FRAME_COLUMN_WIDTH (it
->f
)
23986 : FRAME_LINE_HEIGHT (it
->f
));
23987 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
23992 Lisp_Object car
= XCAR (prop
);
23993 Lisp_Object cdr
= XCDR (prop
);
23997 #ifdef HAVE_WINDOW_SYSTEM
23998 if (FRAME_WINDOW_P (it
->f
)
23999 && valid_image_p (prop
))
24001 ptrdiff_t id
= lookup_image (it
->f
, prop
);
24002 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
24004 return OK_PIXELS (width_p
? img
->width
: img
->height
);
24007 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
24013 while (CONSP (cdr
))
24015 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
24016 font
, width_p
, align_to
))
24019 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
24024 if (EQ (car
, Qminus
))
24026 return OK_PIXELS (pixels
);
24029 car
= buffer_local_value (car
, it
->w
->contents
);
24030 if (EQ (car
, Qunbound
))
24034 if (INTEGERP (car
) || FLOATP (car
))
24037 pixels
= XFLOATINT (car
);
24039 return OK_PIXELS (pixels
);
24040 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
24041 font
, width_p
, align_to
))
24042 return OK_PIXELS (pixels
* fact
);
24053 /***********************************************************************
24055 ***********************************************************************/
24057 #ifdef HAVE_WINDOW_SYSTEM
24062 dump_glyph_string (struct glyph_string
*s
)
24064 fprintf (stderr
, "glyph string\n");
24065 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
24066 s
->x
, s
->y
, s
->width
, s
->height
);
24067 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
24068 fprintf (stderr
, " hl = %d\n", s
->hl
);
24069 fprintf (stderr
, " left overhang = %d, right = %d\n",
24070 s
->left_overhang
, s
->right_overhang
);
24071 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
24072 fprintf (stderr
, " extends to end of line = %d\n",
24073 s
->extends_to_end_of_line_p
);
24074 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
24075 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
24078 #endif /* GLYPH_DEBUG */
24080 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
24081 of XChar2b structures for S; it can't be allocated in
24082 init_glyph_string because it must be allocated via `alloca'. W
24083 is the window on which S is drawn. ROW and AREA are the glyph row
24084 and area within the row from which S is constructed. START is the
24085 index of the first glyph structure covered by S. HL is a
24086 face-override for drawing S. */
24089 #define OPTIONAL_HDC(hdc) HDC hdc,
24090 #define DECLARE_HDC(hdc) HDC hdc;
24091 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
24092 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
24095 #ifndef OPTIONAL_HDC
24096 #define OPTIONAL_HDC(hdc)
24097 #define DECLARE_HDC(hdc)
24098 #define ALLOCATE_HDC(hdc, f)
24099 #define RELEASE_HDC(hdc, f)
24103 init_glyph_string (struct glyph_string
*s
,
24105 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
24106 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
24108 memset (s
, 0, sizeof *s
);
24110 s
->f
= XFRAME (w
->frame
);
24114 s
->display
= FRAME_X_DISPLAY (s
->f
);
24115 s
->window
= FRAME_X_WINDOW (s
->f
);
24116 s
->char2b
= char2b
;
24120 s
->first_glyph
= row
->glyphs
[area
] + start
;
24121 s
->height
= row
->height
;
24122 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
24123 s
->ybase
= s
->y
+ row
->ascent
;
24127 /* Append the list of glyph strings with head H and tail T to the list
24128 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
24131 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24132 struct glyph_string
*h
, struct glyph_string
*t
)
24146 /* Prepend the list of glyph strings with head H and tail T to the
24147 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
24151 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
24152 struct glyph_string
*h
, struct glyph_string
*t
)
24166 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
24167 Set *HEAD and *TAIL to the resulting list. */
24170 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
24171 struct glyph_string
*s
)
24173 s
->next
= s
->prev
= NULL
;
24174 append_glyph_string_lists (head
, tail
, s
, s
);
24178 /* Get face and two-byte form of character C in face FACE_ID on frame F.
24179 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
24180 make sure that X resources for the face returned are allocated.
24181 Value is a pointer to a realized face that is ready for display if
24182 DISPLAY_P is non-zero. */
24184 static struct face
*
24185 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
24186 XChar2b
*char2b
, int display_p
)
24188 struct face
*face
= FACE_FROM_ID (f
, face_id
);
24193 code
= face
->font
->driver
->encode_char (face
->font
, c
);
24195 if (code
== FONT_INVALID_CODE
)
24198 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24200 /* Make sure X resources of the face are allocated. */
24201 #ifdef HAVE_X_WINDOWS
24205 eassert (face
!= NULL
);
24206 prepare_face_for_display (f
, face
);
24213 /* Get face and two-byte form of character glyph GLYPH on frame F.
24214 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
24215 a pointer to a realized face that is ready for display. */
24217 static struct face
*
24218 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
24219 XChar2b
*char2b
, int *two_byte_p
)
24224 eassert (glyph
->type
== CHAR_GLYPH
);
24225 face
= FACE_FROM_ID (f
, glyph
->face_id
);
24227 /* Make sure X resources of the face are allocated. */
24228 eassert (face
!= NULL
);
24229 prepare_face_for_display (f
, face
);
24236 if (CHAR_BYTE8_P (glyph
->u
.ch
))
24237 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
24239 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
24241 if (code
== FONT_INVALID_CODE
)
24245 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24250 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
24251 Return 1 if FONT has a glyph for C, otherwise return 0. */
24254 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
24258 if (CHAR_BYTE8_P (c
))
24259 code
= CHAR_TO_BYTE8 (c
);
24261 code
= font
->driver
->encode_char (font
, c
);
24263 if (code
== FONT_INVALID_CODE
)
24265 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
24270 /* Fill glyph string S with composition components specified by S->cmp.
24272 BASE_FACE is the base face of the composition.
24273 S->cmp_from is the index of the first component for S.
24275 OVERLAPS non-zero means S should draw the foreground only, and use
24276 its physical height for clipping. See also draw_glyphs.
24278 Value is the index of a component not in S. */
24281 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
24285 /* For all glyphs of this composition, starting at the offset
24286 S->cmp_from, until we reach the end of the definition or encounter a
24287 glyph that requires the different face, add it to S. */
24292 s
->for_overlaps
= overlaps
;
24295 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
24297 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
24299 /* TAB in a composition means display glyphs with padding space
24300 on the left or right. */
24303 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
24306 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
24313 s
->font
= s
->face
->font
;
24315 else if (s
->face
!= face
)
24323 if (s
->face
== NULL
)
24325 s
->face
= base_face
->ascii_face
;
24326 s
->font
= s
->face
->font
;
24329 /* All glyph strings for the same composition has the same width,
24330 i.e. the width set for the first component of the composition. */
24331 s
->width
= s
->first_glyph
->pixel_width
;
24333 /* If the specified font could not be loaded, use the frame's
24334 default font, but record the fact that we couldn't load it in
24335 the glyph string so that we can draw rectangles for the
24336 characters of the glyph string. */
24337 if (s
->font
== NULL
)
24339 s
->font_not_found_p
= 1;
24340 s
->font
= FRAME_FONT (s
->f
);
24343 /* Adjust base line for subscript/superscript text. */
24344 s
->ybase
+= s
->first_glyph
->voffset
;
24346 /* This glyph string must always be drawn with 16-bit functions. */
24353 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
24354 int start
, int end
, int overlaps
)
24356 struct glyph
*glyph
, *last
;
24357 Lisp_Object lgstring
;
24360 s
->for_overlaps
= overlaps
;
24361 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24362 last
= s
->row
->glyphs
[s
->area
] + end
;
24363 s
->cmp_id
= glyph
->u
.cmp
.id
;
24364 s
->cmp_from
= glyph
->slice
.cmp
.from
;
24365 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
24366 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24367 lgstring
= composition_gstring_from_id (s
->cmp_id
);
24368 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
24370 while (glyph
< last
24371 && glyph
->u
.cmp
.automatic
24372 && glyph
->u
.cmp
.id
== s
->cmp_id
24373 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
24374 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
24376 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
24378 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
24379 unsigned code
= LGLYPH_CODE (lglyph
);
24381 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
24383 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
24384 return glyph
- s
->row
->glyphs
[s
->area
];
24388 /* Fill glyph string S from a sequence glyphs for glyphless characters.
24389 See the comment of fill_glyph_string for arguments.
24390 Value is the index of the first glyph not in S. */
24394 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
24395 int start
, int end
, int overlaps
)
24397 struct glyph
*glyph
, *last
;
24400 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
24401 s
->for_overlaps
= overlaps
;
24402 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24403 last
= s
->row
->glyphs
[s
->area
] + end
;
24404 voffset
= glyph
->voffset
;
24405 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24406 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
24408 s
->width
= glyph
->pixel_width
;
24410 while (glyph
< last
24411 && glyph
->type
== GLYPHLESS_GLYPH
24412 && glyph
->voffset
== voffset
24413 && glyph
->face_id
== face_id
)
24416 s
->width
+= glyph
->pixel_width
;
24419 s
->ybase
+= voffset
;
24420 return glyph
- s
->row
->glyphs
[s
->area
];
24424 /* Fill glyph string S from a sequence of character glyphs.
24426 FACE_ID is the face id of the string. START is the index of the
24427 first glyph to consider, END is the index of the last + 1.
24428 OVERLAPS non-zero means S should draw the foreground only, and use
24429 its physical height for clipping. See also draw_glyphs.
24431 Value is the index of the first glyph not in S. */
24434 fill_glyph_string (struct glyph_string
*s
, int face_id
,
24435 int start
, int end
, int overlaps
)
24437 struct glyph
*glyph
, *last
;
24439 int glyph_not_available_p
;
24441 eassert (s
->f
== XFRAME (s
->w
->frame
));
24442 eassert (s
->nchars
== 0);
24443 eassert (start
>= 0 && end
> start
);
24445 s
->for_overlaps
= overlaps
;
24446 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24447 last
= s
->row
->glyphs
[s
->area
] + end
;
24448 voffset
= glyph
->voffset
;
24449 s
->padding_p
= glyph
->padding_p
;
24450 glyph_not_available_p
= glyph
->glyph_not_available_p
;
24452 while (glyph
< last
24453 && glyph
->type
== CHAR_GLYPH
24454 && glyph
->voffset
== voffset
24455 /* Same face id implies same font, nowadays. */
24456 && glyph
->face_id
== face_id
24457 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
24461 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
24462 s
->char2b
+ s
->nchars
,
24464 s
->two_byte_p
= two_byte_p
;
24466 eassert (s
->nchars
<= end
- start
);
24467 s
->width
+= glyph
->pixel_width
;
24468 if (glyph
++->padding_p
!= s
->padding_p
)
24472 s
->font
= s
->face
->font
;
24474 /* If the specified font could not be loaded, use the frame's font,
24475 but record the fact that we couldn't load it in
24476 S->font_not_found_p so that we can draw rectangles for the
24477 characters of the glyph string. */
24478 if (s
->font
== NULL
|| glyph_not_available_p
)
24480 s
->font_not_found_p
= 1;
24481 s
->font
= FRAME_FONT (s
->f
);
24484 /* Adjust base line for subscript/superscript text. */
24485 s
->ybase
+= voffset
;
24487 eassert (s
->face
&& s
->face
->gc
);
24488 return glyph
- s
->row
->glyphs
[s
->area
];
24492 /* Fill glyph string S from image glyph S->first_glyph. */
24495 fill_image_glyph_string (struct glyph_string
*s
)
24497 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
24498 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
24500 s
->slice
= s
->first_glyph
->slice
.img
;
24501 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
24502 s
->font
= s
->face
->font
;
24503 s
->width
= s
->first_glyph
->pixel_width
;
24505 /* Adjust base line for subscript/superscript text. */
24506 s
->ybase
+= s
->first_glyph
->voffset
;
24510 /* Fill glyph string S from a sequence of stretch glyphs.
24512 START is the index of the first glyph to consider,
24513 END is the index of the last + 1.
24515 Value is the index of the first glyph not in S. */
24518 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
24520 struct glyph
*glyph
, *last
;
24521 int voffset
, face_id
;
24523 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
24525 glyph
= s
->row
->glyphs
[s
->area
] + start
;
24526 last
= s
->row
->glyphs
[s
->area
] + end
;
24527 face_id
= glyph
->face_id
;
24528 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
24529 s
->font
= s
->face
->font
;
24530 s
->width
= glyph
->pixel_width
;
24532 voffset
= glyph
->voffset
;
24536 && glyph
->type
== STRETCH_GLYPH
24537 && glyph
->voffset
== voffset
24538 && glyph
->face_id
== face_id
);
24540 s
->width
+= glyph
->pixel_width
;
24542 /* Adjust base line for subscript/superscript text. */
24543 s
->ybase
+= voffset
;
24545 /* The case that face->gc == 0 is handled when drawing the glyph
24546 string by calling prepare_face_for_display. */
24548 return glyph
- s
->row
->glyphs
[s
->area
];
24551 static struct font_metrics
*
24552 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
24554 static struct font_metrics metrics
;
24559 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
24560 if (code
== FONT_INVALID_CODE
)
24562 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
24567 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
24568 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
24569 assumed to be zero. */
24572 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
24574 *left
= *right
= 0;
24576 if (glyph
->type
== CHAR_GLYPH
)
24580 struct font_metrics
*pcm
;
24582 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
24583 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
24585 if (pcm
->rbearing
> pcm
->width
)
24586 *right
= pcm
->rbearing
- pcm
->width
;
24587 if (pcm
->lbearing
< 0)
24588 *left
= -pcm
->lbearing
;
24591 else if (glyph
->type
== COMPOSITE_GLYPH
)
24593 if (! glyph
->u
.cmp
.automatic
)
24595 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
24597 if (cmp
->rbearing
> cmp
->pixel_width
)
24598 *right
= cmp
->rbearing
- cmp
->pixel_width
;
24599 if (cmp
->lbearing
< 0)
24600 *left
= - cmp
->lbearing
;
24604 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
24605 struct font_metrics metrics
;
24607 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
24608 glyph
->slice
.cmp
.to
+ 1, &metrics
);
24609 if (metrics
.rbearing
> metrics
.width
)
24610 *right
= metrics
.rbearing
- metrics
.width
;
24611 if (metrics
.lbearing
< 0)
24612 *left
= - metrics
.lbearing
;
24618 /* Return the index of the first glyph preceding glyph string S that
24619 is overwritten by S because of S's left overhang. Value is -1
24620 if no glyphs are overwritten. */
24623 left_overwritten (struct glyph_string
*s
)
24627 if (s
->left_overhang
)
24630 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
24631 int first
= s
->first_glyph
- glyphs
;
24633 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
24634 x
-= glyphs
[i
].pixel_width
;
24645 /* Return the index of the first glyph preceding glyph string S that
24646 is overwriting S because of its right overhang. Value is -1 if no
24647 glyph in front of S overwrites S. */
24650 left_overwriting (struct glyph_string
*s
)
24653 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
24654 int first
= s
->first_glyph
- glyphs
;
24658 for (i
= first
- 1; i
>= 0; --i
)
24661 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
24664 x
-= glyphs
[i
].pixel_width
;
24671 /* Return the index of the last glyph following glyph string S that is
24672 overwritten by S because of S's right overhang. Value is -1 if
24673 no such glyph is found. */
24676 right_overwritten (struct glyph_string
*s
)
24680 if (s
->right_overhang
)
24683 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
24684 int first
= (s
->first_glyph
- glyphs
24685 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
24686 int end
= s
->row
->used
[s
->area
];
24688 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
24689 x
+= glyphs
[i
].pixel_width
;
24698 /* Return the index of the last glyph following glyph string S that
24699 overwrites S because of its left overhang. Value is negative
24700 if no such glyph is found. */
24703 right_overwriting (struct glyph_string
*s
)
24706 int end
= s
->row
->used
[s
->area
];
24707 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
24708 int first
= (s
->first_glyph
- glyphs
24709 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
24713 for (i
= first
; i
< end
; ++i
)
24716 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
24719 x
+= glyphs
[i
].pixel_width
;
24726 /* Set background width of glyph string S. START is the index of the
24727 first glyph following S. LAST_X is the right-most x-position + 1
24728 in the drawing area. */
24731 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
24733 /* If the face of this glyph string has to be drawn to the end of
24734 the drawing area, set S->extends_to_end_of_line_p. */
24736 if (start
== s
->row
->used
[s
->area
]
24737 && ((s
->row
->fill_line_p
24738 && (s
->hl
== DRAW_NORMAL_TEXT
24739 || s
->hl
== DRAW_IMAGE_RAISED
24740 || s
->hl
== DRAW_IMAGE_SUNKEN
))
24741 || s
->hl
== DRAW_MOUSE_FACE
))
24742 s
->extends_to_end_of_line_p
= 1;
24744 /* If S extends its face to the end of the line, set its
24745 background_width to the distance to the right edge of the drawing
24747 if (s
->extends_to_end_of_line_p
)
24748 s
->background_width
= last_x
- s
->x
+ 1;
24750 s
->background_width
= s
->width
;
24754 /* Compute overhangs and x-positions for glyph string S and its
24755 predecessors, or successors. X is the starting x-position for S.
24756 BACKWARD_P non-zero means process predecessors. */
24759 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
24765 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
24766 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
24776 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
24777 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
24787 /* The following macros are only called from draw_glyphs below.
24788 They reference the following parameters of that function directly:
24789 `w', `row', `area', and `overlap_p'
24790 as well as the following local variables:
24791 `s', `f', and `hdc' (in W32) */
24794 /* On W32, silently add local `hdc' variable to argument list of
24795 init_glyph_string. */
24796 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
24797 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
24799 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
24800 init_glyph_string (s, char2b, w, row, area, start, hl)
24803 /* Add a glyph string for a stretch glyph to the list of strings
24804 between HEAD and TAIL. START is the index of the stretch glyph in
24805 row area AREA of glyph row ROW. END is the index of the last glyph
24806 in that glyph row area. X is the current output position assigned
24807 to the new glyph string constructed. HL overrides that face of the
24808 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
24809 is the right-most x-position of the drawing area. */
24811 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
24812 and below -- keep them on one line. */
24813 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24816 s = alloca (sizeof *s); \
24817 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24818 START = fill_stretch_glyph_string (s, START, END); \
24819 append_glyph_string (&HEAD, &TAIL, s); \
24825 /* Add a glyph string for an image glyph to the list of strings
24826 between HEAD and TAIL. START is the index of the image glyph in
24827 row area AREA of glyph row ROW. END is the index of the last glyph
24828 in that glyph row area. X is the current output position assigned
24829 to the new glyph string constructed. HL overrides that face of the
24830 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
24831 is the right-most x-position of the drawing area. */
24833 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24836 s = alloca (sizeof *s); \
24837 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24838 fill_image_glyph_string (s); \
24839 append_glyph_string (&HEAD, &TAIL, s); \
24846 /* Add a glyph string for a sequence of character glyphs to the list
24847 of strings between HEAD and TAIL. START is the index of the first
24848 glyph in row area AREA of glyph row ROW that is part of the new
24849 glyph string. END is the index of the last glyph in that glyph row
24850 area. X is the current output position assigned to the new glyph
24851 string constructed. HL overrides that face of the glyph; e.g. it
24852 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
24853 right-most x-position of the drawing area. */
24855 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24861 face_id = (row)->glyphs[area][START].face_id; \
24863 s = alloca (sizeof *s); \
24864 SAFE_NALLOCA (char2b, 1, (END) - (START)); \
24865 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24866 append_glyph_string (&HEAD, &TAIL, s); \
24868 START = fill_glyph_string (s, face_id, START, END, overlaps); \
24873 /* Add a glyph string for a composite sequence to the list of strings
24874 between HEAD and TAIL. START is the index of the first glyph in
24875 row area AREA of glyph row ROW that is part of the new glyph
24876 string. END is the index of the last glyph in that glyph row area.
24877 X is the current output position assigned to the new glyph string
24878 constructed. HL overrides that face of the glyph; e.g. it is
24879 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
24880 x-position of the drawing area. */
24882 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24884 int face_id = (row)->glyphs[area][START].face_id; \
24885 struct face *base_face = FACE_FROM_ID (f, face_id); \
24886 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
24887 struct composition *cmp = composition_table[cmp_id]; \
24889 struct glyph_string *first_s = NULL; \
24892 SAFE_NALLOCA (char2b, 1, cmp->glyph_len); \
24894 /* Make glyph_strings for each glyph sequence that is drawable by \
24895 the same face, and append them to HEAD/TAIL. */ \
24896 for (n = 0; n < cmp->glyph_len;) \
24898 s = alloca (sizeof *s); \
24899 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24900 append_glyph_string (&(HEAD), &(TAIL), s); \
24906 n = fill_composite_glyph_string (s, base_face, overlaps); \
24914 /* Add a glyph string for a glyph-string sequence to the list of strings
24915 between HEAD and TAIL. */
24917 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24921 Lisp_Object gstring; \
24923 face_id = (row)->glyphs[area][START].face_id; \
24924 gstring = (composition_gstring_from_id \
24925 ((row)->glyphs[area][START].u.cmp.id)); \
24926 s = alloca (sizeof *s); \
24927 SAFE_NALLOCA (char2b, 1, LGSTRING_GLYPH_LEN (gstring)); \
24928 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24929 append_glyph_string (&(HEAD), &(TAIL), s); \
24931 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
24935 /* Add a glyph string for a sequence of glyphless character's glyphs
24936 to the list of strings between HEAD and TAIL. The meanings of
24937 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
24939 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24944 face_id = (row)->glyphs[area][START].face_id; \
24946 s = alloca (sizeof *s); \
24947 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24948 append_glyph_string (&HEAD, &TAIL, s); \
24950 START = fill_glyphless_glyph_string (s, face_id, START, END, \
24956 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
24957 of AREA of glyph row ROW on window W between indices START and END.
24958 HL overrides the face for drawing glyph strings, e.g. it is
24959 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
24960 x-positions of the drawing area.
24962 This is an ugly monster macro construct because we must use alloca
24963 to allocate glyph strings (because draw_glyphs can be called
24964 asynchronously). */
24966 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24969 HEAD = TAIL = NULL; \
24970 while (START < END) \
24972 struct glyph *first_glyph = (row)->glyphs[area] + START; \
24973 switch (first_glyph->type) \
24976 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
24980 case COMPOSITE_GLYPH: \
24981 if (first_glyph->u.cmp.automatic) \
24982 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
24985 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
24989 case STRETCH_GLYPH: \
24990 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
24994 case IMAGE_GLYPH: \
24995 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
24999 case GLYPHLESS_GLYPH: \
25000 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
25010 set_glyph_string_background_width (s, START, LAST_X); \
25017 /* Draw glyphs between START and END in AREA of ROW on window W,
25018 starting at x-position X. X is relative to AREA in W. HL is a
25019 face-override with the following meaning:
25021 DRAW_NORMAL_TEXT draw normally
25022 DRAW_CURSOR draw in cursor face
25023 DRAW_MOUSE_FACE draw in mouse face.
25024 DRAW_INVERSE_VIDEO draw in mode line face
25025 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
25026 DRAW_IMAGE_RAISED draw an image with a raised relief around it
25028 If OVERLAPS is non-zero, draw only the foreground of characters and
25029 clip to the physical height of ROW. Non-zero value also defines
25030 the overlapping part to be drawn:
25032 OVERLAPS_PRED overlap with preceding rows
25033 OVERLAPS_SUCC overlap with succeeding rows
25034 OVERLAPS_BOTH overlap with both preceding/succeeding rows
25035 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
25037 Value is the x-position reached, relative to AREA of W. */
25040 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
25041 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
25042 enum draw_glyphs_face hl
, int overlaps
)
25044 struct glyph_string
*head
, *tail
;
25045 struct glyph_string
*s
;
25046 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
25047 int i
, j
, x_reached
, last_x
, area_left
= 0;
25048 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
25051 ALLOCATE_HDC (hdc
, f
);
25053 /* Let's rather be paranoid than getting a SEGV. */
25054 end
= min (end
, row
->used
[area
]);
25055 start
= clip_to_bounds (0, start
, end
);
25057 /* Translate X to frame coordinates. Set last_x to the right
25058 end of the drawing area. */
25059 if (row
->full_width_p
)
25061 /* X is relative to the left edge of W, without scroll bars
25063 area_left
= WINDOW_LEFT_EDGE_X (w
);
25064 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
25065 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
25069 area_left
= window_box_left (w
, area
);
25070 last_x
= area_left
+ window_box_width (w
, area
);
25074 /* Build a doubly-linked list of glyph_string structures between
25075 head and tail from what we have to draw. Note that the macro
25076 BUILD_GLYPH_STRINGS will modify its start parameter. That's
25077 the reason we use a separate variable `i'. */
25080 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
25082 x_reached
= tail
->x
+ tail
->background_width
;
25086 /* If there are any glyphs with lbearing < 0 or rbearing > width in
25087 the row, redraw some glyphs in front or following the glyph
25088 strings built above. */
25089 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
25091 struct glyph_string
*h
, *t
;
25092 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25093 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
25094 int check_mouse_face
= 0;
25097 /* If mouse highlighting is on, we may need to draw adjacent
25098 glyphs using mouse-face highlighting. */
25099 if (area
== TEXT_AREA
&& row
->mouse_face_p
25100 && hlinfo
->mouse_face_beg_row
>= 0
25101 && hlinfo
->mouse_face_end_row
>= 0)
25103 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
25105 if (row_vpos
>= hlinfo
->mouse_face_beg_row
25106 && row_vpos
<= hlinfo
->mouse_face_end_row
)
25108 check_mouse_face
= 1;
25109 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
25110 ? hlinfo
->mouse_face_beg_col
: 0;
25111 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
25112 ? hlinfo
->mouse_face_end_col
25113 : row
->used
[TEXT_AREA
];
25117 /* Compute overhangs for all glyph strings. */
25118 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
25119 for (s
= head
; s
; s
= s
->next
)
25120 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
25122 /* Prepend glyph strings for glyphs in front of the first glyph
25123 string that are overwritten because of the first glyph
25124 string's left overhang. The background of all strings
25125 prepended must be drawn because the first glyph string
25127 i
= left_overwritten (head
);
25130 enum draw_glyphs_face overlap_hl
;
25132 /* If this row contains mouse highlighting, attempt to draw
25133 the overlapped glyphs with the correct highlight. This
25134 code fails if the overlap encompasses more than one glyph
25135 and mouse-highlight spans only some of these glyphs.
25136 However, making it work perfectly involves a lot more
25137 code, and I don't know if the pathological case occurs in
25138 practice, so we'll stick to this for now. --- cyd */
25139 if (check_mouse_face
25140 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25141 overlap_hl
= DRAW_MOUSE_FACE
;
25143 overlap_hl
= DRAW_NORMAL_TEXT
;
25145 if (hl
!= overlap_hl
)
25148 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
25149 overlap_hl
, dummy_x
, last_x
);
25151 compute_overhangs_and_x (t
, head
->x
, 1);
25152 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25153 if (clip_head
== NULL
)
25157 /* Prepend glyph strings for glyphs in front of the first glyph
25158 string that overwrite that glyph string because of their
25159 right overhang. For these strings, only the foreground must
25160 be drawn, because it draws over the glyph string at `head'.
25161 The background must not be drawn because this would overwrite
25162 right overhangs of preceding glyphs for which no glyph
25164 i
= left_overwriting (head
);
25167 enum draw_glyphs_face overlap_hl
;
25169 if (check_mouse_face
25170 && mouse_beg_col
< start
&& mouse_end_col
> i
)
25171 overlap_hl
= DRAW_MOUSE_FACE
;
25173 overlap_hl
= DRAW_NORMAL_TEXT
;
25175 if (hl
== overlap_hl
|| clip_head
== NULL
)
25177 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
25178 overlap_hl
, dummy_x
, last_x
);
25179 for (s
= h
; s
; s
= s
->next
)
25180 s
->background_filled_p
= 1;
25181 compute_overhangs_and_x (t
, head
->x
, 1);
25182 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
25185 /* Append glyphs strings for glyphs following the last glyph
25186 string tail that are overwritten by tail. The background of
25187 these strings has to be drawn because tail's foreground draws
25189 i
= right_overwritten (tail
);
25192 enum draw_glyphs_face overlap_hl
;
25194 if (check_mouse_face
25195 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25196 overlap_hl
= DRAW_MOUSE_FACE
;
25198 overlap_hl
= DRAW_NORMAL_TEXT
;
25200 if (hl
!= overlap_hl
)
25202 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25203 overlap_hl
, x
, last_x
);
25204 /* Because BUILD_GLYPH_STRINGS updates the first argument,
25205 we don't have `end = i;' here. */
25206 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
25207 append_glyph_string_lists (&head
, &tail
, h
, t
);
25208 if (clip_tail
== NULL
)
25212 /* Append glyph strings for glyphs following the last glyph
25213 string tail that overwrite tail. The foreground of such
25214 glyphs has to be drawn because it writes into the background
25215 of tail. The background must not be drawn because it could
25216 paint over the foreground of following glyphs. */
25217 i
= right_overwriting (tail
);
25220 enum draw_glyphs_face overlap_hl
;
25221 if (check_mouse_face
25222 && mouse_beg_col
< i
&& mouse_end_col
> end
)
25223 overlap_hl
= DRAW_MOUSE_FACE
;
25225 overlap_hl
= DRAW_NORMAL_TEXT
;
25227 if (hl
== overlap_hl
|| clip_tail
== NULL
)
25229 i
++; /* We must include the Ith glyph. */
25230 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
25231 overlap_hl
, x
, last_x
);
25232 for (s
= h
; s
; s
= s
->next
)
25233 s
->background_filled_p
= 1;
25234 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
25235 append_glyph_string_lists (&head
, &tail
, h
, t
);
25237 if (clip_head
|| clip_tail
)
25238 for (s
= head
; s
; s
= s
->next
)
25240 s
->clip_head
= clip_head
;
25241 s
->clip_tail
= clip_tail
;
25245 /* Draw all strings. */
25246 for (s
= head
; s
; s
= s
->next
)
25247 FRAME_RIF (f
)->draw_glyph_string (s
);
25250 /* When focus a sole frame and move horizontally, this sets on_p to 0
25251 causing a failure to erase prev cursor position. */
25252 if (area
== TEXT_AREA
25253 && !row
->full_width_p
25254 /* When drawing overlapping rows, only the glyph strings'
25255 foreground is drawn, which doesn't erase a cursor
25259 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
25260 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
25261 : (tail
? tail
->x
+ tail
->background_width
: x
));
25265 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
25266 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
25270 /* Value is the x-position up to which drawn, relative to AREA of W.
25271 This doesn't include parts drawn because of overhangs. */
25272 if (row
->full_width_p
)
25273 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
25275 x_reached
-= area_left
;
25277 RELEASE_HDC (hdc
, f
);
25283 /* Expand row matrix if too narrow. Don't expand if area
25286 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
25288 if (!it->f->fonts_changed \
25289 && (it->glyph_row->glyphs[area] \
25290 < it->glyph_row->glyphs[area + 1])) \
25292 it->w->ncols_scale_factor++; \
25293 it->f->fonts_changed = 1; \
25297 /* Store one glyph for IT->char_to_display in IT->glyph_row.
25298 Called from x_produce_glyphs when IT->glyph_row is non-null. */
25301 append_glyph (struct it
*it
)
25303 struct glyph
*glyph
;
25304 enum glyph_row_area area
= it
->area
;
25306 eassert (it
->glyph_row
);
25307 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
25309 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25310 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25312 /* If the glyph row is reversed, we need to prepend the glyph
25313 rather than append it. */
25314 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25318 /* Make room for the additional glyph. */
25319 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25321 glyph
= it
->glyph_row
->glyphs
[area
];
25323 glyph
->charpos
= CHARPOS (it
->position
);
25324 glyph
->object
= it
->object
;
25325 if (it
->pixel_width
> 0)
25327 glyph
->pixel_width
= it
->pixel_width
;
25328 glyph
->padding_p
= 0;
25332 /* Assure at least 1-pixel width. Otherwise, cursor can't
25333 be displayed correctly. */
25334 glyph
->pixel_width
= 1;
25335 glyph
->padding_p
= 1;
25337 glyph
->ascent
= it
->ascent
;
25338 glyph
->descent
= it
->descent
;
25339 glyph
->voffset
= it
->voffset
;
25340 glyph
->type
= CHAR_GLYPH
;
25341 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25342 glyph
->multibyte_p
= it
->multibyte_p
;
25343 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25345 /* In R2L rows, the left and the right box edges need to be
25346 drawn in reverse direction. */
25347 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25348 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25352 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25353 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25355 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25356 || it
->phys_descent
> it
->descent
);
25357 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
25358 glyph
->face_id
= it
->face_id
;
25359 glyph
->u
.ch
= it
->char_to_display
;
25360 glyph
->slice
.img
= null_glyph_slice
;
25361 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25364 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25365 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25366 glyph
->bidi_type
= it
->bidi_it
.type
;
25370 glyph
->resolved_level
= 0;
25371 glyph
->bidi_type
= UNKNOWN_BT
;
25373 ++it
->glyph_row
->used
[area
];
25376 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25379 /* Store one glyph for the composition IT->cmp_it.id in
25380 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
25384 append_composite_glyph (struct it
*it
)
25386 struct glyph
*glyph
;
25387 enum glyph_row_area area
= it
->area
;
25389 eassert (it
->glyph_row
);
25391 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25392 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25394 /* If the glyph row is reversed, we need to prepend the glyph
25395 rather than append it. */
25396 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
25400 /* Make room for the new glyph. */
25401 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
25403 glyph
= it
->glyph_row
->glyphs
[it
->area
];
25405 glyph
->charpos
= it
->cmp_it
.charpos
;
25406 glyph
->object
= it
->object
;
25407 glyph
->pixel_width
= it
->pixel_width
;
25408 glyph
->ascent
= it
->ascent
;
25409 glyph
->descent
= it
->descent
;
25410 glyph
->voffset
= it
->voffset
;
25411 glyph
->type
= COMPOSITE_GLYPH
;
25412 if (it
->cmp_it
.ch
< 0)
25414 glyph
->u
.cmp
.automatic
= 0;
25415 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25416 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
25420 glyph
->u
.cmp
.automatic
= 1;
25421 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
25422 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
25423 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
25425 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25426 glyph
->multibyte_p
= it
->multibyte_p
;
25427 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25429 /* In R2L rows, the left and the right box edges need to be
25430 drawn in reverse direction. */
25431 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25432 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25436 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25437 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25439 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25440 || it
->phys_descent
> it
->descent
);
25441 glyph
->padding_p
= 0;
25442 glyph
->glyph_not_available_p
= 0;
25443 glyph
->face_id
= it
->face_id
;
25444 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25447 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25448 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25449 glyph
->bidi_type
= it
->bidi_it
.type
;
25451 ++it
->glyph_row
->used
[area
];
25454 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25458 /* Change IT->ascent and IT->height according to the setting of
25462 take_vertical_position_into_account (struct it
*it
)
25466 if (it
->voffset
< 0)
25467 /* Increase the ascent so that we can display the text higher
25469 it
->ascent
-= it
->voffset
;
25471 /* Increase the descent so that we can display the text lower
25473 it
->descent
+= it
->voffset
;
25478 /* Produce glyphs/get display metrics for the image IT is loaded with.
25479 See the description of struct display_iterator in dispextern.h for
25480 an overview of struct display_iterator. */
25483 produce_image_glyph (struct it
*it
)
25487 int glyph_ascent
, crop
;
25488 struct glyph_slice slice
;
25490 eassert (it
->what
== IT_IMAGE
);
25492 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25494 /* Make sure X resources of the face is loaded. */
25495 prepare_face_for_display (it
->f
, face
);
25497 if (it
->image_id
< 0)
25499 /* Fringe bitmap. */
25500 it
->ascent
= it
->phys_ascent
= 0;
25501 it
->descent
= it
->phys_descent
= 0;
25502 it
->pixel_width
= 0;
25507 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
25509 /* Make sure X resources of the image is loaded. */
25510 prepare_image_for_display (it
->f
, img
);
25512 slice
.x
= slice
.y
= 0;
25513 slice
.width
= img
->width
;
25514 slice
.height
= img
->height
;
25516 if (INTEGERP (it
->slice
.x
))
25517 slice
.x
= XINT (it
->slice
.x
);
25518 else if (FLOATP (it
->slice
.x
))
25519 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
25521 if (INTEGERP (it
->slice
.y
))
25522 slice
.y
= XINT (it
->slice
.y
);
25523 else if (FLOATP (it
->slice
.y
))
25524 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
25526 if (INTEGERP (it
->slice
.width
))
25527 slice
.width
= XINT (it
->slice
.width
);
25528 else if (FLOATP (it
->slice
.width
))
25529 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
25531 if (INTEGERP (it
->slice
.height
))
25532 slice
.height
= XINT (it
->slice
.height
);
25533 else if (FLOATP (it
->slice
.height
))
25534 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
25536 if (slice
.x
>= img
->width
)
25537 slice
.x
= img
->width
;
25538 if (slice
.y
>= img
->height
)
25539 slice
.y
= img
->height
;
25540 if (slice
.x
+ slice
.width
>= img
->width
)
25541 slice
.width
= img
->width
- slice
.x
;
25542 if (slice
.y
+ slice
.height
> img
->height
)
25543 slice
.height
= img
->height
- slice
.y
;
25545 if (slice
.width
== 0 || slice
.height
== 0)
25548 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
25550 it
->descent
= slice
.height
- glyph_ascent
;
25552 it
->descent
+= img
->vmargin
;
25553 if (slice
.y
+ slice
.height
== img
->height
)
25554 it
->descent
+= img
->vmargin
;
25555 it
->phys_descent
= it
->descent
;
25557 it
->pixel_width
= slice
.width
;
25559 it
->pixel_width
+= img
->hmargin
;
25560 if (slice
.x
+ slice
.width
== img
->width
)
25561 it
->pixel_width
+= img
->hmargin
;
25563 /* It's quite possible for images to have an ascent greater than
25564 their height, so don't get confused in that case. */
25565 if (it
->descent
< 0)
25570 if (face
->box
!= FACE_NO_BOX
)
25572 if (face
->box_line_width
> 0)
25575 it
->ascent
+= face
->box_line_width
;
25576 if (slice
.y
+ slice
.height
== img
->height
)
25577 it
->descent
+= face
->box_line_width
;
25580 if (it
->start_of_box_run_p
&& slice
.x
== 0)
25581 it
->pixel_width
+= eabs (face
->box_line_width
);
25582 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
25583 it
->pixel_width
+= eabs (face
->box_line_width
);
25586 take_vertical_position_into_account (it
);
25588 /* Automatically crop wide image glyphs at right edge so we can
25589 draw the cursor on same display row. */
25590 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
25591 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
25593 it
->pixel_width
-= crop
;
25594 slice
.width
-= crop
;
25599 struct glyph
*glyph
;
25600 enum glyph_row_area area
= it
->area
;
25602 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25603 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25605 glyph
->charpos
= CHARPOS (it
->position
);
25606 glyph
->object
= it
->object
;
25607 glyph
->pixel_width
= it
->pixel_width
;
25608 glyph
->ascent
= glyph_ascent
;
25609 glyph
->descent
= it
->descent
;
25610 glyph
->voffset
= it
->voffset
;
25611 glyph
->type
= IMAGE_GLYPH
;
25612 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25613 glyph
->multibyte_p
= it
->multibyte_p
;
25614 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25616 /* In R2L rows, the left and the right box edges need to be
25617 drawn in reverse direction. */
25618 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25619 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25623 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25624 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25626 glyph
->overlaps_vertically_p
= 0;
25627 glyph
->padding_p
= 0;
25628 glyph
->glyph_not_available_p
= 0;
25629 glyph
->face_id
= it
->face_id
;
25630 glyph
->u
.img_id
= img
->id
;
25631 glyph
->slice
.img
= slice
;
25632 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25635 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25636 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25637 glyph
->bidi_type
= it
->bidi_it
.type
;
25639 ++it
->glyph_row
->used
[area
];
25642 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25647 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
25648 of the glyph, WIDTH and HEIGHT are the width and height of the
25649 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
25652 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
25653 int width
, int height
, int ascent
)
25655 struct glyph
*glyph
;
25656 enum glyph_row_area area
= it
->area
;
25658 eassert (ascent
>= 0 && ascent
<= height
);
25660 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25661 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25663 /* If the glyph row is reversed, we need to prepend the glyph
25664 rather than append it. */
25665 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25669 /* Make room for the additional glyph. */
25670 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25672 glyph
= it
->glyph_row
->glyphs
[area
];
25674 /* Decrease the width of the first glyph of the row that
25675 begins before first_visible_x (e.g., due to hscroll).
25676 This is so the overall width of the row becomes smaller
25677 by the scroll amount, and the stretch glyph appended by
25678 extend_face_to_end_of_line will be wider, to shift the
25679 row glyphs to the right. (In L2R rows, the corresponding
25680 left-shift effect is accomplished by setting row->x to a
25681 negative value, which won't work with R2L rows.)
25683 This must leave us with a positive value of WIDTH, since
25684 otherwise the call to move_it_in_display_line_to at the
25685 beginning of display_line would have got past the entire
25686 first glyph, and then it->current_x would have been
25687 greater or equal to it->first_visible_x. */
25688 if (it
->current_x
< it
->first_visible_x
)
25689 width
-= it
->first_visible_x
- it
->current_x
;
25690 eassert (width
> 0);
25692 glyph
->charpos
= CHARPOS (it
->position
);
25693 glyph
->object
= object
;
25694 glyph
->pixel_width
= width
;
25695 glyph
->ascent
= ascent
;
25696 glyph
->descent
= height
- ascent
;
25697 glyph
->voffset
= it
->voffset
;
25698 glyph
->type
= STRETCH_GLYPH
;
25699 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25700 glyph
->multibyte_p
= it
->multibyte_p
;
25701 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25703 /* In R2L rows, the left and the right box edges need to be
25704 drawn in reverse direction. */
25705 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25706 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25710 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25711 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25713 glyph
->overlaps_vertically_p
= 0;
25714 glyph
->padding_p
= 0;
25715 glyph
->glyph_not_available_p
= 0;
25716 glyph
->face_id
= it
->face_id
;
25717 glyph
->u
.stretch
.ascent
= ascent
;
25718 glyph
->u
.stretch
.height
= height
;
25719 glyph
->slice
.img
= null_glyph_slice
;
25720 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25723 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25724 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
25725 glyph
->bidi_type
= it
->bidi_it
.type
;
25729 glyph
->resolved_level
= 0;
25730 glyph
->bidi_type
= UNKNOWN_BT
;
25732 ++it
->glyph_row
->used
[area
];
25735 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25738 #endif /* HAVE_WINDOW_SYSTEM */
25740 /* Produce a stretch glyph for iterator IT. IT->object is the value
25741 of the glyph property displayed. The value must be a list
25742 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
25745 1. `:width WIDTH' specifies that the space should be WIDTH *
25746 canonical char width wide. WIDTH may be an integer or floating
25749 2. `:relative-width FACTOR' specifies that the width of the stretch
25750 should be computed from the width of the first character having the
25751 `glyph' property, and should be FACTOR times that width.
25753 3. `:align-to HPOS' specifies that the space should be wide enough
25754 to reach HPOS, a value in canonical character units.
25756 Exactly one of the above pairs must be present.
25758 4. `:height HEIGHT' specifies that the height of the stretch produced
25759 should be HEIGHT, measured in canonical character units.
25761 5. `:relative-height FACTOR' specifies that the height of the
25762 stretch should be FACTOR times the height of the characters having
25763 the glyph property.
25765 Either none or exactly one of 4 or 5 must be present.
25767 6. `:ascent ASCENT' specifies that ASCENT percent of the height
25768 of the stretch should be used for the ascent of the stretch.
25769 ASCENT must be in the range 0 <= ASCENT <= 100. */
25772 produce_stretch_glyph (struct it
*it
)
25774 /* (space :width WIDTH :height HEIGHT ...) */
25775 Lisp_Object prop
, plist
;
25776 int width
= 0, height
= 0, align_to
= -1;
25777 int zero_width_ok_p
= 0;
25779 struct font
*font
= NULL
;
25781 #ifdef HAVE_WINDOW_SYSTEM
25783 int zero_height_ok_p
= 0;
25785 if (FRAME_WINDOW_P (it
->f
))
25787 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25788 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25789 prepare_face_for_display (it
->f
, face
);
25793 /* List should start with `space'. */
25794 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
25795 plist
= XCDR (it
->object
);
25797 /* Compute the width of the stretch. */
25798 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
25799 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
25801 /* Absolute width `:width WIDTH' specified and valid. */
25802 zero_width_ok_p
= 1;
25805 #ifdef HAVE_WINDOW_SYSTEM
25806 else if (FRAME_WINDOW_P (it
->f
)
25807 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
25809 /* Relative width `:relative-width FACTOR' specified and valid.
25810 Compute the width of the characters having the `glyph'
25813 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
25816 if (it
->multibyte_p
)
25817 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
25820 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
25821 if (! ASCII_CHAR_P (it2
.c
))
25822 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
25825 it2
.glyph_row
= NULL
;
25826 it2
.what
= IT_CHARACTER
;
25827 x_produce_glyphs (&it2
);
25828 width
= NUMVAL (prop
) * it2
.pixel_width
;
25830 #endif /* HAVE_WINDOW_SYSTEM */
25831 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
25832 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
25834 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
25835 align_to
= (align_to
< 0
25837 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
25838 else if (align_to
< 0)
25839 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
25840 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
25841 zero_width_ok_p
= 1;
25844 /* Nothing specified -> width defaults to canonical char width. */
25845 width
= FRAME_COLUMN_WIDTH (it
->f
);
25847 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
25850 #ifdef HAVE_WINDOW_SYSTEM
25851 /* Compute height. */
25852 if (FRAME_WINDOW_P (it
->f
))
25854 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
25855 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
25858 zero_height_ok_p
= 1;
25860 else if (prop
= Fplist_get (plist
, QCrelative_height
),
25862 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
25864 height
= FONT_HEIGHT (font
);
25866 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
25869 /* Compute percentage of height used for ascent. If
25870 `:ascent ASCENT' is present and valid, use that. Otherwise,
25871 derive the ascent from the font in use. */
25872 if (prop
= Fplist_get (plist
, QCascent
),
25873 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
25874 ascent
= height
* NUMVAL (prop
) / 100.0;
25875 else if (!NILP (prop
)
25876 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
25877 ascent
= min (max (0, (int)tem
), height
);
25879 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
25882 #endif /* HAVE_WINDOW_SYSTEM */
25885 if (width
> 0 && it
->line_wrap
!= TRUNCATE
25886 && it
->current_x
+ width
> it
->last_visible_x
)
25888 width
= it
->last_visible_x
- it
->current_x
;
25889 #ifdef HAVE_WINDOW_SYSTEM
25890 /* Subtract one more pixel from the stretch width, but only on
25891 GUI frames, since on a TTY each glyph is one "pixel" wide. */
25892 width
-= FRAME_WINDOW_P (it
->f
);
25896 if (width
> 0 && height
> 0 && it
->glyph_row
)
25898 Lisp_Object o_object
= it
->object
;
25899 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
25902 if (!STRINGP (object
))
25903 object
= it
->w
->contents
;
25904 #ifdef HAVE_WINDOW_SYSTEM
25905 if (FRAME_WINDOW_P (it
->f
))
25906 append_stretch_glyph (it
, object
, width
, height
, ascent
);
25910 it
->object
= object
;
25911 it
->char_to_display
= ' ';
25912 it
->pixel_width
= it
->len
= 1;
25914 tty_append_glyph (it
);
25915 it
->object
= o_object
;
25919 it
->pixel_width
= width
;
25920 #ifdef HAVE_WINDOW_SYSTEM
25921 if (FRAME_WINDOW_P (it
->f
))
25923 it
->ascent
= it
->phys_ascent
= ascent
;
25924 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
25925 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
25926 take_vertical_position_into_account (it
);
25930 it
->nglyphs
= width
;
25933 /* Get information about special display element WHAT in an
25934 environment described by IT. WHAT is one of IT_TRUNCATION or
25935 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
25936 non-null glyph_row member. This function ensures that fields like
25937 face_id, c, len of IT are left untouched. */
25940 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
25947 temp_it
.object
= make_number (0);
25948 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
25950 if (what
== IT_CONTINUATION
)
25952 /* Continuation glyph. For R2L lines, we mirror it by hand. */
25953 if (it
->bidi_it
.paragraph_dir
== R2L
)
25954 SET_GLYPH_FROM_CHAR (glyph
, '/');
25956 SET_GLYPH_FROM_CHAR (glyph
, '\\');
25958 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25960 /* FIXME: Should we mirror GC for R2L lines? */
25961 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25962 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25965 else if (what
== IT_TRUNCATION
)
25967 /* Truncation glyph. */
25968 SET_GLYPH_FROM_CHAR (glyph
, '$');
25970 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25972 /* FIXME: Should we mirror GC for R2L lines? */
25973 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25974 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25980 #ifdef HAVE_WINDOW_SYSTEM
25981 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
25982 is turned off, we precede the truncation/continuation glyphs by a
25983 stretch glyph whose width is computed such that these special
25984 glyphs are aligned at the window margin, even when very different
25985 fonts are used in different glyph rows. */
25986 if (FRAME_WINDOW_P (temp_it
.f
)
25987 /* init_iterator calls this with it->glyph_row == NULL, and it
25988 wants only the pixel width of the truncation/continuation
25990 && temp_it
.glyph_row
25991 /* insert_left_trunc_glyphs calls us at the beginning of the
25992 row, and it has its own calculation of the stretch glyph
25994 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
25995 && (temp_it
.glyph_row
->reversed_p
25996 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
25997 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
25999 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
26001 if (stretch_width
> 0)
26003 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
26004 struct font
*font
=
26005 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
26006 int stretch_ascent
=
26007 (((temp_it
.ascent
+ temp_it
.descent
)
26008 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
26010 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
26011 temp_it
.ascent
+ temp_it
.descent
,
26018 temp_it
.what
= IT_CHARACTER
;
26019 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
26020 temp_it
.face_id
= GLYPH_FACE (glyph
);
26021 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
26023 PRODUCE_GLYPHS (&temp_it
);
26024 it
->pixel_width
= temp_it
.pixel_width
;
26025 it
->nglyphs
= temp_it
.nglyphs
;
26028 #ifdef HAVE_WINDOW_SYSTEM
26030 /* Calculate line-height and line-spacing properties.
26031 An integer value specifies explicit pixel value.
26032 A float value specifies relative value to current face height.
26033 A cons (float . face-name) specifies relative value to
26034 height of specified face font.
26036 Returns height in pixels, or nil. */
26040 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
26041 int boff
, int override
)
26043 Lisp_Object face_name
= Qnil
;
26044 int ascent
, descent
, height
;
26046 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
26051 face_name
= XCAR (val
);
26053 if (!NUMBERP (val
))
26054 val
= make_number (1);
26055 if (NILP (face_name
))
26057 height
= it
->ascent
+ it
->descent
;
26062 if (NILP (face_name
))
26064 font
= FRAME_FONT (it
->f
);
26065 boff
= FRAME_BASELINE_OFFSET (it
->f
);
26067 else if (EQ (face_name
, Qt
))
26076 face_id
= lookup_named_face (it
->f
, face_name
, 0);
26078 return make_number (-1);
26080 face
= FACE_FROM_ID (it
->f
, face_id
);
26083 return make_number (-1);
26084 boff
= font
->baseline_offset
;
26085 if (font
->vertical_centering
)
26086 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26089 ascent
= FONT_BASE (font
) + boff
;
26090 descent
= FONT_DESCENT (font
) - boff
;
26094 it
->override_ascent
= ascent
;
26095 it
->override_descent
= descent
;
26096 it
->override_boff
= boff
;
26099 height
= ascent
+ descent
;
26103 height
= (int)(XFLOAT_DATA (val
) * height
);
26104 else if (INTEGERP (val
))
26105 height
*= XINT (val
);
26107 return make_number (height
);
26111 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
26112 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
26113 and only if this is for a character for which no font was found.
26115 If the display method (it->glyphless_method) is
26116 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
26117 length of the acronym or the hexadecimal string, UPPER_XOFF and
26118 UPPER_YOFF are pixel offsets for the upper part of the string,
26119 LOWER_XOFF and LOWER_YOFF are for the lower part.
26121 For the other display methods, LEN through LOWER_YOFF are zero. */
26124 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
26125 short upper_xoff
, short upper_yoff
,
26126 short lower_xoff
, short lower_yoff
)
26128 struct glyph
*glyph
;
26129 enum glyph_row_area area
= it
->area
;
26131 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
26132 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
26134 /* If the glyph row is reversed, we need to prepend the glyph
26135 rather than append it. */
26136 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26140 /* Make room for the additional glyph. */
26141 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
26143 glyph
= it
->glyph_row
->glyphs
[area
];
26145 glyph
->charpos
= CHARPOS (it
->position
);
26146 glyph
->object
= it
->object
;
26147 glyph
->pixel_width
= it
->pixel_width
;
26148 glyph
->ascent
= it
->ascent
;
26149 glyph
->descent
= it
->descent
;
26150 glyph
->voffset
= it
->voffset
;
26151 glyph
->type
= GLYPHLESS_GLYPH
;
26152 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
26153 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
26154 glyph
->u
.glyphless
.len
= len
;
26155 glyph
->u
.glyphless
.ch
= it
->c
;
26156 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
26157 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
26158 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
26159 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
26160 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
26161 glyph
->multibyte_p
= it
->multibyte_p
;
26162 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
26164 /* In R2L rows, the left and the right box edges need to be
26165 drawn in reverse direction. */
26166 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
26167 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
26171 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
26172 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
26174 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
26175 || it
->phys_descent
> it
->descent
);
26176 glyph
->padding_p
= 0;
26177 glyph
->glyph_not_available_p
= 0;
26178 glyph
->face_id
= face_id
;
26179 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
26182 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
26183 eassert ((it
->bidi_it
.type
& 7) == it
->bidi_it
.type
);
26184 glyph
->bidi_type
= it
->bidi_it
.type
;
26186 ++it
->glyph_row
->used
[area
];
26189 IT_EXPAND_MATRIX_WIDTH (it
, area
);
26193 /* Produce a glyph for a glyphless character for iterator IT.
26194 IT->glyphless_method specifies which method to use for displaying
26195 the character. See the description of enum
26196 glyphless_display_method in dispextern.h for the detail.
26198 FOR_NO_FONT is nonzero if and only if this is for a character for
26199 which no font was found. ACRONYM, if non-nil, is an acronym string
26200 for the character. */
26203 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
26208 int base_width
, base_height
, width
, height
;
26209 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
26212 /* Get the metrics of the base font. We always refer to the current
26214 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
26215 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26216 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
26217 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
26218 base_height
= it
->ascent
+ it
->descent
;
26219 base_width
= font
->average_width
;
26221 face_id
= merge_glyphless_glyph_face (it
);
26223 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
26225 it
->pixel_width
= THIN_SPACE_WIDTH
;
26227 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26229 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
26231 width
= CHAR_WIDTH (it
->c
);
26234 else if (width
> 4)
26236 it
->pixel_width
= base_width
* width
;
26238 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
26244 unsigned int code
[6];
26246 int ascent
, descent
;
26247 struct font_metrics metrics_upper
, metrics_lower
;
26249 face
= FACE_FROM_ID (it
->f
, face_id
);
26250 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
26251 prepare_face_for_display (it
->f
, face
);
26253 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
26255 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
26256 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
26257 if (CONSP (acronym
))
26258 acronym
= XCAR (acronym
);
26259 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
26263 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
26264 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
26267 for (len
= 0; str
[len
] && ASCII_CHAR_P (str
[len
]) && len
< 6; len
++)
26268 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
26269 upper_len
= (len
+ 1) / 2;
26270 font
->driver
->text_extents (font
, code
, upper_len
,
26272 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
26277 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
26278 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
26279 upper_xoff
= upper_yoff
= 2; /* the typical case */
26280 if (base_width
>= width
)
26282 /* Align the upper to the left, the lower to the right. */
26283 it
->pixel_width
= base_width
;
26284 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
26288 /* Center the shorter one. */
26289 it
->pixel_width
= width
;
26290 if (metrics_upper
.width
>= metrics_lower
.width
)
26291 lower_xoff
= (width
- metrics_lower
.width
) / 2;
26294 /* FIXME: This code doesn't look right. It formerly was
26295 missing the "lower_xoff = 0;", which couldn't have
26296 been right since it left lower_xoff uninitialized. */
26298 upper_xoff
= (width
- metrics_upper
.width
) / 2;
26302 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
26303 top, bottom, and between upper and lower strings. */
26304 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
26305 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
26306 /* Center vertically.
26307 H:base_height, D:base_descent
26308 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
26310 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
26311 descent = D - H/2 + h/2;
26312 lower_yoff = descent - 2 - ld;
26313 upper_yoff = lower_yoff - la - 1 - ud; */
26314 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
26315 descent
= it
->descent
- (base_height
- height
) / 2;
26316 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
26317 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
26318 - metrics_upper
.descent
);
26319 /* Don't make the height shorter than the base height. */
26320 if (height
> base_height
)
26322 it
->ascent
= ascent
;
26323 it
->descent
= descent
;
26327 it
->phys_ascent
= it
->ascent
;
26328 it
->phys_descent
= it
->descent
;
26330 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
26331 upper_xoff
, upper_yoff
,
26332 lower_xoff
, lower_yoff
);
26334 take_vertical_position_into_account (it
);
26339 Produce glyphs/get display metrics for the display element IT is
26340 loaded with. See the description of struct it in dispextern.h
26341 for an overview of struct it. */
26344 x_produce_glyphs (struct it
*it
)
26346 int extra_line_spacing
= it
->extra_line_spacing
;
26348 it
->glyph_not_available_p
= 0;
26350 if (it
->what
== IT_CHARACTER
)
26353 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26354 struct font
*font
= face
->font
;
26355 struct font_metrics
*pcm
= NULL
;
26356 int boff
; /* Baseline offset. */
26360 /* When no suitable font is found, display this character by
26361 the method specified in the first extra slot of
26362 Vglyphless_char_display. */
26363 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
26365 eassert (it
->what
== IT_GLYPHLESS
);
26366 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
26370 boff
= font
->baseline_offset
;
26371 if (font
->vertical_centering
)
26372 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26374 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
26380 if (it
->override_ascent
>= 0)
26382 it
->ascent
= it
->override_ascent
;
26383 it
->descent
= it
->override_descent
;
26384 boff
= it
->override_boff
;
26388 it
->ascent
= FONT_BASE (font
) + boff
;
26389 it
->descent
= FONT_DESCENT (font
) - boff
;
26392 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
26394 pcm
= get_per_char_metric (font
, &char2b
);
26395 if (pcm
->width
== 0
26396 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
26402 it
->phys_ascent
= pcm
->ascent
+ boff
;
26403 it
->phys_descent
= pcm
->descent
- boff
;
26404 it
->pixel_width
= pcm
->width
;
26408 it
->glyph_not_available_p
= 1;
26409 it
->phys_ascent
= it
->ascent
;
26410 it
->phys_descent
= it
->descent
;
26411 it
->pixel_width
= font
->space_width
;
26414 if (it
->constrain_row_ascent_descent_p
)
26416 if (it
->descent
> it
->max_descent
)
26418 it
->ascent
+= it
->descent
- it
->max_descent
;
26419 it
->descent
= it
->max_descent
;
26421 if (it
->ascent
> it
->max_ascent
)
26423 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
26424 it
->ascent
= it
->max_ascent
;
26426 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
26427 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
26428 extra_line_spacing
= 0;
26431 /* If this is a space inside a region of text with
26432 `space-width' property, change its width. */
26433 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
26435 it
->pixel_width
*= XFLOATINT (it
->space_width
);
26437 /* If face has a box, add the box thickness to the character
26438 height. If character has a box line to the left and/or
26439 right, add the box line width to the character's width. */
26440 if (face
->box
!= FACE_NO_BOX
)
26442 int thick
= face
->box_line_width
;
26446 it
->ascent
+= thick
;
26447 it
->descent
+= thick
;
26452 if (it
->start_of_box_run_p
)
26453 it
->pixel_width
+= thick
;
26454 if (it
->end_of_box_run_p
)
26455 it
->pixel_width
+= thick
;
26458 /* If face has an overline, add the height of the overline
26459 (1 pixel) and a 1 pixel margin to the character height. */
26460 if (face
->overline_p
)
26461 it
->ascent
+= overline_margin
;
26463 if (it
->constrain_row_ascent_descent_p
)
26465 if (it
->ascent
> it
->max_ascent
)
26466 it
->ascent
= it
->max_ascent
;
26467 if (it
->descent
> it
->max_descent
)
26468 it
->descent
= it
->max_descent
;
26471 take_vertical_position_into_account (it
);
26473 /* If we have to actually produce glyphs, do it. */
26478 /* Translate a space with a `space-width' property
26479 into a stretch glyph. */
26480 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
26481 / FONT_HEIGHT (font
));
26482 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
26483 it
->ascent
+ it
->descent
, ascent
);
26488 /* If characters with lbearing or rbearing are displayed
26489 in this line, record that fact in a flag of the
26490 glyph row. This is used to optimize X output code. */
26491 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
26492 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26494 if (! stretched_p
&& it
->pixel_width
== 0)
26495 /* We assure that all visible glyphs have at least 1-pixel
26497 it
->pixel_width
= 1;
26499 else if (it
->char_to_display
== '\n')
26501 /* A newline has no width, but we need the height of the
26502 line. But if previous part of the line sets a height,
26503 don't increase that height. */
26505 Lisp_Object height
;
26506 Lisp_Object total_height
= Qnil
;
26508 it
->override_ascent
= -1;
26509 it
->pixel_width
= 0;
26512 height
= get_it_property (it
, Qline_height
);
26513 /* Split (line-height total-height) list. */
26515 && CONSP (XCDR (height
))
26516 && NILP (XCDR (XCDR (height
))))
26518 total_height
= XCAR (XCDR (height
));
26519 height
= XCAR (height
);
26521 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
26523 if (it
->override_ascent
>= 0)
26525 it
->ascent
= it
->override_ascent
;
26526 it
->descent
= it
->override_descent
;
26527 boff
= it
->override_boff
;
26531 it
->ascent
= FONT_BASE (font
) + boff
;
26532 it
->descent
= FONT_DESCENT (font
) - boff
;
26535 if (EQ (height
, Qt
))
26537 if (it
->descent
> it
->max_descent
)
26539 it
->ascent
+= it
->descent
- it
->max_descent
;
26540 it
->descent
= it
->max_descent
;
26542 if (it
->ascent
> it
->max_ascent
)
26544 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
26545 it
->ascent
= it
->max_ascent
;
26547 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
26548 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
26549 it
->constrain_row_ascent_descent_p
= 1;
26550 extra_line_spacing
= 0;
26554 Lisp_Object spacing
;
26556 it
->phys_ascent
= it
->ascent
;
26557 it
->phys_descent
= it
->descent
;
26559 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
26560 && face
->box
!= FACE_NO_BOX
26561 && face
->box_line_width
> 0)
26563 it
->ascent
+= face
->box_line_width
;
26564 it
->descent
+= face
->box_line_width
;
26567 && XINT (height
) > it
->ascent
+ it
->descent
)
26568 it
->ascent
= XINT (height
) - it
->descent
;
26570 if (!NILP (total_height
))
26571 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
26574 spacing
= get_it_property (it
, Qline_spacing
);
26575 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
26577 if (INTEGERP (spacing
))
26579 extra_line_spacing
= XINT (spacing
);
26580 if (!NILP (total_height
))
26581 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
26585 else /* i.e. (it->char_to_display == '\t') */
26587 if (font
->space_width
> 0)
26589 int tab_width
= it
->tab_width
* font
->space_width
;
26590 int x
= it
->current_x
+ it
->continuation_lines_width
;
26591 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
26593 /* If the distance from the current position to the next tab
26594 stop is less than a space character width, use the
26595 tab stop after that. */
26596 if (next_tab_x
- x
< font
->space_width
)
26597 next_tab_x
+= tab_width
;
26599 it
->pixel_width
= next_tab_x
- x
;
26601 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
26602 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
26606 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
26607 it
->ascent
+ it
->descent
, it
->ascent
);
26612 it
->pixel_width
= 0;
26617 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
26619 /* A static composition.
26621 Note: A composition is represented as one glyph in the
26622 glyph matrix. There are no padding glyphs.
26624 Important note: pixel_width, ascent, and descent are the
26625 values of what is drawn by draw_glyphs (i.e. the values of
26626 the overall glyphs composed). */
26627 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26628 int boff
; /* baseline offset */
26629 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
26630 int glyph_len
= cmp
->glyph_len
;
26631 struct font
*font
= face
->font
;
26635 /* If we have not yet calculated pixel size data of glyphs of
26636 the composition for the current face font, calculate them
26637 now. Theoretically, we have to check all fonts for the
26638 glyphs, but that requires much time and memory space. So,
26639 here we check only the font of the first glyph. This may
26640 lead to incorrect display, but it's very rare, and C-l
26641 (recenter-top-bottom) can correct the display anyway. */
26642 if (! cmp
->font
|| cmp
->font
!= font
)
26644 /* Ascent and descent of the font of the first character
26645 of this composition (adjusted by baseline offset).
26646 Ascent and descent of overall glyphs should not be less
26647 than these, respectively. */
26648 int font_ascent
, font_descent
, font_height
;
26649 /* Bounding box of the overall glyphs. */
26650 int leftmost
, rightmost
, lowest
, highest
;
26651 int lbearing
, rbearing
;
26652 int i
, width
, ascent
, descent
;
26653 int left_padded
= 0, right_padded
= 0;
26654 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
26656 struct font_metrics
*pcm
;
26657 int font_not_found_p
;
26660 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
26661 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
26663 if (glyph_len
< cmp
->glyph_len
)
26665 for (i
= 0; i
< glyph_len
; i
++)
26667 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
26669 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
26674 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
26675 : IT_CHARPOS (*it
));
26676 /* If no suitable font is found, use the default font. */
26677 font_not_found_p
= font
== NULL
;
26678 if (font_not_found_p
)
26680 face
= face
->ascii_face
;
26683 boff
= font
->baseline_offset
;
26684 if (font
->vertical_centering
)
26685 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
26686 font_ascent
= FONT_BASE (font
) + boff
;
26687 font_descent
= FONT_DESCENT (font
) - boff
;
26688 font_height
= FONT_HEIGHT (font
);
26693 if (! font_not_found_p
)
26695 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
26697 pcm
= get_per_char_metric (font
, &char2b
);
26700 /* Initialize the bounding box. */
26703 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
26704 ascent
= pcm
->ascent
;
26705 descent
= pcm
->descent
;
26706 lbearing
= pcm
->lbearing
;
26707 rbearing
= pcm
->rbearing
;
26711 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
26712 ascent
= FONT_BASE (font
);
26713 descent
= FONT_DESCENT (font
);
26720 lowest
= - descent
+ boff
;
26721 highest
= ascent
+ boff
;
26723 if (! font_not_found_p
26724 && font
->default_ascent
26725 && CHAR_TABLE_P (Vuse_default_ascent
)
26726 && !NILP (Faref (Vuse_default_ascent
,
26727 make_number (it
->char_to_display
))))
26728 highest
= font
->default_ascent
+ boff
;
26730 /* Draw the first glyph at the normal position. It may be
26731 shifted to right later if some other glyphs are drawn
26733 cmp
->offsets
[i
* 2] = 0;
26734 cmp
->offsets
[i
* 2 + 1] = boff
;
26735 cmp
->lbearing
= lbearing
;
26736 cmp
->rbearing
= rbearing
;
26738 /* Set cmp->offsets for the remaining glyphs. */
26739 for (i
++; i
< glyph_len
; i
++)
26741 int left
, right
, btm
, top
;
26742 int ch
= COMPOSITION_GLYPH (cmp
, i
);
26744 struct face
*this_face
;
26748 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
26749 this_face
= FACE_FROM_ID (it
->f
, face_id
);
26750 font
= this_face
->font
;
26756 get_char_face_and_encoding (it
->f
, ch
, face_id
,
26758 pcm
= get_per_char_metric (font
, &char2b
);
26761 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
26764 width
= pcm
->width
;
26765 ascent
= pcm
->ascent
;
26766 descent
= pcm
->descent
;
26767 lbearing
= pcm
->lbearing
;
26768 rbearing
= pcm
->rbearing
;
26769 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
26771 /* Relative composition with or without
26772 alternate chars. */
26773 left
= (leftmost
+ rightmost
- width
) / 2;
26774 btm
= - descent
+ boff
;
26775 if (font
->relative_compose
26776 && (! CHAR_TABLE_P (Vignore_relative_composition
)
26777 || NILP (Faref (Vignore_relative_composition
,
26778 make_number (ch
)))))
26781 if (- descent
>= font
->relative_compose
)
26782 /* One extra pixel between two glyphs. */
26784 else if (ascent
<= 0)
26785 /* One extra pixel between two glyphs. */
26786 btm
= lowest
- 1 - ascent
- descent
;
26791 /* A composition rule is specified by an integer
26792 value that encodes global and new reference
26793 points (GREF and NREF). GREF and NREF are
26794 specified by numbers as below:
26796 0---1---2 -- ascent
26800 9--10--11 -- center
26802 ---3---4---5--- baseline
26804 6---7---8 -- descent
26806 int rule
= COMPOSITION_RULE (cmp
, i
);
26807 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
26809 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
26810 grefx
= gref
% 3, nrefx
= nref
% 3;
26811 grefy
= gref
/ 3, nrefy
= nref
/ 3;
26813 xoff
= font_height
* (xoff
- 128) / 256;
26815 yoff
= font_height
* (yoff
- 128) / 256;
26818 + grefx
* (rightmost
- leftmost
) / 2
26819 - nrefx
* width
/ 2
26822 btm
= ((grefy
== 0 ? highest
26824 : grefy
== 2 ? lowest
26825 : (highest
+ lowest
) / 2)
26826 - (nrefy
== 0 ? ascent
+ descent
26827 : nrefy
== 1 ? descent
- boff
26829 : (ascent
+ descent
) / 2)
26833 cmp
->offsets
[i
* 2] = left
;
26834 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
26836 /* Update the bounding box of the overall glyphs. */
26839 right
= left
+ width
;
26840 if (left
< leftmost
)
26842 if (right
> rightmost
)
26845 top
= btm
+ descent
+ ascent
;
26851 if (cmp
->lbearing
> left
+ lbearing
)
26852 cmp
->lbearing
= left
+ lbearing
;
26853 if (cmp
->rbearing
< left
+ rbearing
)
26854 cmp
->rbearing
= left
+ rbearing
;
26858 /* If there are glyphs whose x-offsets are negative,
26859 shift all glyphs to the right and make all x-offsets
26863 for (i
= 0; i
< cmp
->glyph_len
; i
++)
26864 cmp
->offsets
[i
* 2] -= leftmost
;
26865 rightmost
-= leftmost
;
26866 cmp
->lbearing
-= leftmost
;
26867 cmp
->rbearing
-= leftmost
;
26870 if (left_padded
&& cmp
->lbearing
< 0)
26872 for (i
= 0; i
< cmp
->glyph_len
; i
++)
26873 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
26874 rightmost
-= cmp
->lbearing
;
26875 cmp
->rbearing
-= cmp
->lbearing
;
26878 if (right_padded
&& rightmost
< cmp
->rbearing
)
26880 rightmost
= cmp
->rbearing
;
26883 cmp
->pixel_width
= rightmost
;
26884 cmp
->ascent
= highest
;
26885 cmp
->descent
= - lowest
;
26886 if (cmp
->ascent
< font_ascent
)
26887 cmp
->ascent
= font_ascent
;
26888 if (cmp
->descent
< font_descent
)
26889 cmp
->descent
= font_descent
;
26893 && (cmp
->lbearing
< 0
26894 || cmp
->rbearing
> cmp
->pixel_width
))
26895 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26897 it
->pixel_width
= cmp
->pixel_width
;
26898 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
26899 it
->descent
= it
->phys_descent
= cmp
->descent
;
26900 if (face
->box
!= FACE_NO_BOX
)
26902 int thick
= face
->box_line_width
;
26906 it
->ascent
+= thick
;
26907 it
->descent
+= thick
;
26912 if (it
->start_of_box_run_p
)
26913 it
->pixel_width
+= thick
;
26914 if (it
->end_of_box_run_p
)
26915 it
->pixel_width
+= thick
;
26918 /* If face has an overline, add the height of the overline
26919 (1 pixel) and a 1 pixel margin to the character height. */
26920 if (face
->overline_p
)
26921 it
->ascent
+= overline_margin
;
26923 take_vertical_position_into_account (it
);
26924 if (it
->ascent
< 0)
26926 if (it
->descent
< 0)
26929 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
26930 append_composite_glyph (it
);
26932 else if (it
->what
== IT_COMPOSITION
)
26934 /* A dynamic (automatic) composition. */
26935 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26936 Lisp_Object gstring
;
26937 struct font_metrics metrics
;
26941 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
26943 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
26946 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
26947 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26948 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
26949 it
->descent
= it
->phys_descent
= metrics
.descent
;
26950 if (face
->box
!= FACE_NO_BOX
)
26952 int thick
= face
->box_line_width
;
26956 it
->ascent
+= thick
;
26957 it
->descent
+= thick
;
26962 if (it
->start_of_box_run_p
)
26963 it
->pixel_width
+= thick
;
26964 if (it
->end_of_box_run_p
)
26965 it
->pixel_width
+= thick
;
26967 /* If face has an overline, add the height of the overline
26968 (1 pixel) and a 1 pixel margin to the character height. */
26969 if (face
->overline_p
)
26970 it
->ascent
+= overline_margin
;
26971 take_vertical_position_into_account (it
);
26972 if (it
->ascent
< 0)
26974 if (it
->descent
< 0)
26978 append_composite_glyph (it
);
26980 else if (it
->what
== IT_GLYPHLESS
)
26981 produce_glyphless_glyph (it
, 0, Qnil
);
26982 else if (it
->what
== IT_IMAGE
)
26983 produce_image_glyph (it
);
26984 else if (it
->what
== IT_STRETCH
)
26985 produce_stretch_glyph (it
);
26988 /* Accumulate dimensions. Note: can't assume that it->descent > 0
26989 because this isn't true for images with `:ascent 100'. */
26990 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
26991 if (it
->area
== TEXT_AREA
)
26992 it
->current_x
+= it
->pixel_width
;
26994 if (extra_line_spacing
> 0)
26996 it
->descent
+= extra_line_spacing
;
26997 if (extra_line_spacing
> it
->max_extra_line_spacing
)
26998 it
->max_extra_line_spacing
= extra_line_spacing
;
27001 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
27002 it
->max_descent
= max (it
->max_descent
, it
->descent
);
27003 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
27004 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
27008 Output LEN glyphs starting at START at the nominal cursor position.
27009 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
27010 being updated, and UPDATED_AREA is the area of that row being updated. */
27013 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27014 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27016 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
27018 eassert (updated_row
);
27019 /* When the window is hscrolled, cursor hpos can legitimately be out
27020 of bounds, but we draw the cursor at the corresponding window
27021 margin in that case. */
27022 if (!updated_row
->reversed_p
&& chpos
< 0)
27024 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
27025 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
27029 /* Write glyphs. */
27031 hpos
= start
- updated_row
->glyphs
[updated_area
];
27032 x
= draw_glyphs (w
, w
->output_cursor
.x
,
27033 updated_row
, updated_area
,
27035 DRAW_NORMAL_TEXT
, 0);
27037 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
27038 if (updated_area
== TEXT_AREA
27039 && w
->phys_cursor_on_p
27040 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
27042 && chpos
< hpos
+ len
)
27043 w
->phys_cursor_on_p
= 0;
27047 /* Advance the output cursor. */
27048 w
->output_cursor
.hpos
+= len
;
27049 w
->output_cursor
.x
= x
;
27054 Insert LEN glyphs from START at the nominal cursor position. */
27057 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
27058 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
27061 int line_height
, shift_by_width
, shifted_region_width
;
27062 struct glyph_row
*row
;
27063 struct glyph
*glyph
;
27064 int frame_x
, frame_y
;
27067 eassert (updated_row
);
27069 f
= XFRAME (WINDOW_FRAME (w
));
27071 /* Get the height of the line we are in. */
27073 line_height
= row
->height
;
27075 /* Get the width of the glyphs to insert. */
27076 shift_by_width
= 0;
27077 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
27078 shift_by_width
+= glyph
->pixel_width
;
27080 /* Get the width of the region to shift right. */
27081 shifted_region_width
= (window_box_width (w
, updated_area
)
27082 - w
->output_cursor
.x
27086 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
27087 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
27089 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
27090 line_height
, shift_by_width
);
27092 /* Write the glyphs. */
27093 hpos
= start
- row
->glyphs
[updated_area
];
27094 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
27096 DRAW_NORMAL_TEXT
, 0);
27098 /* Advance the output cursor. */
27099 w
->output_cursor
.hpos
+= len
;
27100 w
->output_cursor
.x
+= shift_by_width
;
27106 Erase the current text line from the nominal cursor position
27107 (inclusive) to pixel column TO_X (exclusive). The idea is that
27108 everything from TO_X onward is already erased.
27110 TO_X is a pixel position relative to UPDATED_AREA of currently
27111 updated window W. TO_X == -1 means clear to the end of this area. */
27114 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
27115 enum glyph_row_area updated_area
, int to_x
)
27118 int max_x
, min_y
, max_y
;
27119 int from_x
, from_y
, to_y
;
27121 eassert (updated_row
);
27122 f
= XFRAME (w
->frame
);
27124 if (updated_row
->full_width_p
)
27125 max_x
= (WINDOW_PIXEL_WIDTH (w
)
27126 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
27128 max_x
= window_box_width (w
, updated_area
);
27129 max_y
= window_text_bottom_y (w
);
27131 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
27132 of window. For TO_X > 0, truncate to end of drawing area. */
27138 to_x
= min (to_x
, max_x
);
27140 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
27142 /* Notice if the cursor will be cleared by this operation. */
27143 if (!updated_row
->full_width_p
)
27144 notice_overwritten_cursor (w
, updated_area
,
27145 w
->output_cursor
.x
, -1,
27147 MATRIX_ROW_BOTTOM_Y (updated_row
));
27149 from_x
= w
->output_cursor
.x
;
27151 /* Translate to frame coordinates. */
27152 if (updated_row
->full_width_p
)
27154 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
27155 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
27159 int area_left
= window_box_left (w
, updated_area
);
27160 from_x
+= area_left
;
27164 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
27165 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
27166 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
27168 /* Prevent inadvertently clearing to end of the X window. */
27169 if (to_x
> from_x
&& to_y
> from_y
)
27172 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
27173 to_x
- from_x
, to_y
- from_y
);
27178 #endif /* HAVE_WINDOW_SYSTEM */
27182 /***********************************************************************
27184 ***********************************************************************/
27186 /* Value is the internal representation of the specified cursor type
27187 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
27188 of the bar cursor. */
27190 static enum text_cursor_kinds
27191 get_specified_cursor_type (Lisp_Object arg
, int *width
)
27193 enum text_cursor_kinds type
;
27198 if (EQ (arg
, Qbox
))
27199 return FILLED_BOX_CURSOR
;
27201 if (EQ (arg
, Qhollow
))
27202 return HOLLOW_BOX_CURSOR
;
27204 if (EQ (arg
, Qbar
))
27211 && EQ (XCAR (arg
), Qbar
)
27212 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27214 *width
= XINT (XCDR (arg
));
27218 if (EQ (arg
, Qhbar
))
27221 return HBAR_CURSOR
;
27225 && EQ (XCAR (arg
), Qhbar
)
27226 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
27228 *width
= XINT (XCDR (arg
));
27229 return HBAR_CURSOR
;
27232 /* Treat anything unknown as "hollow box cursor".
27233 It was bad to signal an error; people have trouble fixing
27234 .Xdefaults with Emacs, when it has something bad in it. */
27235 type
= HOLLOW_BOX_CURSOR
;
27240 /* Set the default cursor types for specified frame. */
27242 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
27247 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
27248 FRAME_CURSOR_WIDTH (f
) = width
;
27250 /* By default, set up the blink-off state depending on the on-state. */
27252 tem
= Fassoc (arg
, Vblink_cursor_alist
);
27255 FRAME_BLINK_OFF_CURSOR (f
)
27256 = get_specified_cursor_type (XCDR (tem
), &width
);
27257 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
27260 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
27262 /* Make sure the cursor gets redrawn. */
27263 f
->cursor_type_changed
= 1;
27267 #ifdef HAVE_WINDOW_SYSTEM
27269 /* Return the cursor we want to be displayed in window W. Return
27270 width of bar/hbar cursor through WIDTH arg. Return with
27271 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
27272 (i.e. if the `system caret' should track this cursor).
27274 In a mini-buffer window, we want the cursor only to appear if we
27275 are reading input from this window. For the selected window, we
27276 want the cursor type given by the frame parameter or buffer local
27277 setting of cursor-type. If explicitly marked off, draw no cursor.
27278 In all other cases, we want a hollow box cursor. */
27280 static enum text_cursor_kinds
27281 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
27282 int *active_cursor
)
27284 struct frame
*f
= XFRAME (w
->frame
);
27285 struct buffer
*b
= XBUFFER (w
->contents
);
27286 int cursor_type
= DEFAULT_CURSOR
;
27287 Lisp_Object alt_cursor
;
27288 int non_selected
= 0;
27290 *active_cursor
= 1;
27293 if (cursor_in_echo_area
27294 && FRAME_HAS_MINIBUF_P (f
)
27295 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
27297 if (w
== XWINDOW (echo_area_window
))
27299 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
27301 *width
= FRAME_CURSOR_WIDTH (f
);
27302 return FRAME_DESIRED_CURSOR (f
);
27305 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27308 *active_cursor
= 0;
27312 /* Detect a nonselected window or nonselected frame. */
27313 else if (w
!= XWINDOW (f
->selected_window
)
27314 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
27316 *active_cursor
= 0;
27318 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
27324 /* Never display a cursor in a window in which cursor-type is nil. */
27325 if (NILP (BVAR (b
, cursor_type
)))
27328 /* Get the normal cursor type for this window. */
27329 if (EQ (BVAR (b
, cursor_type
), Qt
))
27331 cursor_type
= FRAME_DESIRED_CURSOR (f
);
27332 *width
= FRAME_CURSOR_WIDTH (f
);
27335 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
27337 /* Use cursor-in-non-selected-windows instead
27338 for non-selected window or frame. */
27341 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
27342 if (!EQ (Qt
, alt_cursor
))
27343 return get_specified_cursor_type (alt_cursor
, width
);
27344 /* t means modify the normal cursor type. */
27345 if (cursor_type
== FILLED_BOX_CURSOR
)
27346 cursor_type
= HOLLOW_BOX_CURSOR
;
27347 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
27349 return cursor_type
;
27352 /* Use normal cursor if not blinked off. */
27353 if (!w
->cursor_off_p
)
27355 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27357 if (cursor_type
== FILLED_BOX_CURSOR
)
27359 /* Using a block cursor on large images can be very annoying.
27360 So use a hollow cursor for "large" images.
27361 If image is not transparent (no mask), also use hollow cursor. */
27362 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27363 if (img
!= NULL
&& IMAGEP (img
->spec
))
27365 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
27366 where N = size of default frame font size.
27367 This should cover most of the "tiny" icons people may use. */
27369 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
27370 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
27371 cursor_type
= HOLLOW_BOX_CURSOR
;
27374 else if (cursor_type
!= NO_CURSOR
)
27376 /* Display current only supports BOX and HOLLOW cursors for images.
27377 So for now, unconditionally use a HOLLOW cursor when cursor is
27378 not a solid box cursor. */
27379 cursor_type
= HOLLOW_BOX_CURSOR
;
27382 return cursor_type
;
27385 /* Cursor is blinked off, so determine how to "toggle" it. */
27387 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
27388 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
27389 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
27391 /* Then see if frame has specified a specific blink off cursor type. */
27392 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
27394 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
27395 return FRAME_BLINK_OFF_CURSOR (f
);
27399 /* Some people liked having a permanently visible blinking cursor,
27400 while others had very strong opinions against it. So it was
27401 decided to remove it. KFS 2003-09-03 */
27403 /* Finally perform built-in cursor blinking:
27404 filled box <-> hollow box
27405 wide [h]bar <-> narrow [h]bar
27406 narrow [h]bar <-> no cursor
27407 other type <-> no cursor */
27409 if (cursor_type
== FILLED_BOX_CURSOR
)
27410 return HOLLOW_BOX_CURSOR
;
27412 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
27415 return cursor_type
;
27423 /* Notice when the text cursor of window W has been completely
27424 overwritten by a drawing operation that outputs glyphs in AREA
27425 starting at X0 and ending at X1 in the line starting at Y0 and
27426 ending at Y1. X coordinates are area-relative. X1 < 0 means all
27427 the rest of the line after X0 has been written. Y coordinates
27428 are window-relative. */
27431 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
27432 int x0
, int x1
, int y0
, int y1
)
27434 int cx0
, cx1
, cy0
, cy1
;
27435 struct glyph_row
*row
;
27437 if (!w
->phys_cursor_on_p
)
27439 if (area
!= TEXT_AREA
)
27442 if (w
->phys_cursor
.vpos
< 0
27443 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
27444 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
27445 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
27448 if (row
->cursor_in_fringe_p
)
27450 row
->cursor_in_fringe_p
= 0;
27451 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
27452 w
->phys_cursor_on_p
= 0;
27456 cx0
= w
->phys_cursor
.x
;
27457 cx1
= cx0
+ w
->phys_cursor_width
;
27458 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
27461 /* The cursor image will be completely removed from the
27462 screen if the output area intersects the cursor area in
27463 y-direction. When we draw in [y0 y1[, and some part of
27464 the cursor is at y < y0, that part must have been drawn
27465 before. When scrolling, the cursor is erased before
27466 actually scrolling, so we don't come here. When not
27467 scrolling, the rows above the old cursor row must have
27468 changed, and in this case these rows must have written
27469 over the cursor image.
27471 Likewise if part of the cursor is below y1, with the
27472 exception of the cursor being in the first blank row at
27473 the buffer and window end because update_text_area
27474 doesn't draw that row. (Except when it does, but
27475 that's handled in update_text_area.) */
27477 cy0
= w
->phys_cursor
.y
;
27478 cy1
= cy0
+ w
->phys_cursor_height
;
27479 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
27482 w
->phys_cursor_on_p
= 0;
27485 #endif /* HAVE_WINDOW_SYSTEM */
27488 /************************************************************************
27490 ************************************************************************/
27492 #ifdef HAVE_WINDOW_SYSTEM
27495 Fix the display of area AREA of overlapping row ROW in window W
27496 with respect to the overlapping part OVERLAPS. */
27499 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
27500 enum glyph_row_area area
, int overlaps
)
27507 for (i
= 0; i
< row
->used
[area
];)
27509 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
27511 int start
= i
, start_x
= x
;
27515 x
+= row
->glyphs
[area
][i
].pixel_width
;
27518 while (i
< row
->used
[area
]
27519 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
27521 draw_glyphs (w
, start_x
, row
, area
,
27523 DRAW_NORMAL_TEXT
, overlaps
);
27527 x
+= row
->glyphs
[area
][i
].pixel_width
;
27537 Draw the cursor glyph of window W in glyph row ROW. See the
27538 comment of draw_glyphs for the meaning of HL. */
27541 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
27542 enum draw_glyphs_face hl
)
27544 /* If cursor hpos is out of bounds, don't draw garbage. This can
27545 happen in mini-buffer windows when switching between echo area
27546 glyphs and mini-buffer. */
27547 if ((row
->reversed_p
27548 ? (w
->phys_cursor
.hpos
>= 0)
27549 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
27551 int on_p
= w
->phys_cursor_on_p
;
27553 int hpos
= w
->phys_cursor
.hpos
;
27555 /* When the window is hscrolled, cursor hpos can legitimately be
27556 out of bounds, but we draw the cursor at the corresponding
27557 window margin in that case. */
27558 if (!row
->reversed_p
&& hpos
< 0)
27560 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27561 hpos
= row
->used
[TEXT_AREA
] - 1;
27563 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
27565 w
->phys_cursor_on_p
= on_p
;
27567 if (hl
== DRAW_CURSOR
)
27568 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
27569 /* When we erase the cursor, and ROW is overlapped by other
27570 rows, make sure that these overlapping parts of other rows
27572 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
27574 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
27576 if (row
> w
->current_matrix
->rows
27577 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
27578 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
27579 OVERLAPS_ERASED_CURSOR
);
27581 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
27582 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
27583 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
27584 OVERLAPS_ERASED_CURSOR
);
27590 /* Erase the image of a cursor of window W from the screen. */
27593 erase_phys_cursor (struct window
*w
)
27595 struct frame
*f
= XFRAME (w
->frame
);
27596 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27597 int hpos
= w
->phys_cursor
.hpos
;
27598 int vpos
= w
->phys_cursor
.vpos
;
27599 int mouse_face_here_p
= 0;
27600 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
27601 struct glyph_row
*cursor_row
;
27602 struct glyph
*cursor_glyph
;
27603 enum draw_glyphs_face hl
;
27605 /* No cursor displayed or row invalidated => nothing to do on the
27607 if (w
->phys_cursor_type
== NO_CURSOR
)
27608 goto mark_cursor_off
;
27610 /* VPOS >= active_glyphs->nrows means that window has been resized.
27611 Don't bother to erase the cursor. */
27612 if (vpos
>= active_glyphs
->nrows
)
27613 goto mark_cursor_off
;
27615 /* If row containing cursor is marked invalid, there is nothing we
27617 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
27618 if (!cursor_row
->enabled_p
)
27619 goto mark_cursor_off
;
27621 /* If line spacing is > 0, old cursor may only be partially visible in
27622 window after split-window. So adjust visible height. */
27623 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
27624 window_text_bottom_y (w
) - cursor_row
->y
);
27626 /* If row is completely invisible, don't attempt to delete a cursor which
27627 isn't there. This can happen if cursor is at top of a window, and
27628 we switch to a buffer with a header line in that window. */
27629 if (cursor_row
->visible_height
<= 0)
27630 goto mark_cursor_off
;
27632 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
27633 if (cursor_row
->cursor_in_fringe_p
)
27635 cursor_row
->cursor_in_fringe_p
= 0;
27636 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
27637 goto mark_cursor_off
;
27640 /* This can happen when the new row is shorter than the old one.
27641 In this case, either draw_glyphs or clear_end_of_line
27642 should have cleared the cursor. Note that we wouldn't be
27643 able to erase the cursor in this case because we don't have a
27644 cursor glyph at hand. */
27645 if ((cursor_row
->reversed_p
27646 ? (w
->phys_cursor
.hpos
< 0)
27647 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
27648 goto mark_cursor_off
;
27650 /* When the window is hscrolled, cursor hpos can legitimately be out
27651 of bounds, but we draw the cursor at the corresponding window
27652 margin in that case. */
27653 if (!cursor_row
->reversed_p
&& hpos
< 0)
27655 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
27656 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
27658 /* If the cursor is in the mouse face area, redisplay that when
27659 we clear the cursor. */
27660 if (! NILP (hlinfo
->mouse_face_window
)
27661 && coords_in_mouse_face_p (w
, hpos
, vpos
)
27662 /* Don't redraw the cursor's spot in mouse face if it is at the
27663 end of a line (on a newline). The cursor appears there, but
27664 mouse highlighting does not. */
27665 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
27666 mouse_face_here_p
= 1;
27668 /* Maybe clear the display under the cursor. */
27669 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
27672 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
27675 cursor_glyph
= get_phys_cursor_glyph (w
);
27676 if (cursor_glyph
== NULL
)
27677 goto mark_cursor_off
;
27679 width
= cursor_glyph
->pixel_width
;
27680 x
= w
->phys_cursor
.x
;
27686 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
27687 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
27688 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
27691 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
27694 /* Erase the cursor by redrawing the character underneath it. */
27695 if (mouse_face_here_p
)
27696 hl
= DRAW_MOUSE_FACE
;
27698 hl
= DRAW_NORMAL_TEXT
;
27699 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
27702 w
->phys_cursor_on_p
= 0;
27703 w
->phys_cursor_type
= NO_CURSOR
;
27708 Display or clear cursor of window W. If ON is zero, clear the
27709 cursor. If it is non-zero, display the cursor. If ON is nonzero,
27710 where to put the cursor is specified by HPOS, VPOS, X and Y. */
27713 display_and_set_cursor (struct window
*w
, bool on
,
27714 int hpos
, int vpos
, int x
, int y
)
27716 struct frame
*f
= XFRAME (w
->frame
);
27717 int new_cursor_type
;
27718 int new_cursor_width
;
27720 struct glyph_row
*glyph_row
;
27721 struct glyph
*glyph
;
27723 /* This is pointless on invisible frames, and dangerous on garbaged
27724 windows and frames; in the latter case, the frame or window may
27725 be in the midst of changing its size, and x and y may be off the
27727 if (! FRAME_VISIBLE_P (f
)
27728 || FRAME_GARBAGED_P (f
)
27729 || vpos
>= w
->current_matrix
->nrows
27730 || hpos
>= w
->current_matrix
->matrix_w
)
27733 /* If cursor is off and we want it off, return quickly. */
27734 if (!on
&& !w
->phys_cursor_on_p
)
27737 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27738 /* If cursor row is not enabled, we don't really know where to
27739 display the cursor. */
27740 if (!glyph_row
->enabled_p
)
27742 w
->phys_cursor_on_p
= 0;
27747 if (!glyph_row
->exact_window_width_line_p
27748 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
27749 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
27751 eassert (input_blocked_p ());
27753 /* Set new_cursor_type to the cursor we want to be displayed. */
27754 new_cursor_type
= get_window_cursor_type (w
, glyph
,
27755 &new_cursor_width
, &active_cursor
);
27757 /* If cursor is currently being shown and we don't want it to be or
27758 it is in the wrong place, or the cursor type is not what we want,
27760 if (w
->phys_cursor_on_p
27762 || w
->phys_cursor
.x
!= x
27763 || w
->phys_cursor
.y
!= y
27764 /* HPOS can be negative in R2L rows whose
27765 exact_window_width_line_p flag is set (i.e. their newline
27766 would "overflow into the fringe"). */
27768 || new_cursor_type
!= w
->phys_cursor_type
27769 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
27770 && new_cursor_width
!= w
->phys_cursor_width
)))
27771 erase_phys_cursor (w
);
27773 /* Don't check phys_cursor_on_p here because that flag is only set
27774 to zero in some cases where we know that the cursor has been
27775 completely erased, to avoid the extra work of erasing the cursor
27776 twice. In other words, phys_cursor_on_p can be 1 and the cursor
27777 still not be visible, or it has only been partly erased. */
27780 w
->phys_cursor_ascent
= glyph_row
->ascent
;
27781 w
->phys_cursor_height
= glyph_row
->height
;
27783 /* Set phys_cursor_.* before x_draw_.* is called because some
27784 of them may need the information. */
27785 w
->phys_cursor
.x
= x
;
27786 w
->phys_cursor
.y
= glyph_row
->y
;
27787 w
->phys_cursor
.hpos
= hpos
;
27788 w
->phys_cursor
.vpos
= vpos
;
27791 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
27792 new_cursor_type
, new_cursor_width
,
27793 on
, active_cursor
);
27797 /* Switch the display of W's cursor on or off, according to the value
27801 update_window_cursor (struct window
*w
, bool on
)
27803 /* Don't update cursor in windows whose frame is in the process
27804 of being deleted. */
27805 if (w
->current_matrix
)
27807 int hpos
= w
->phys_cursor
.hpos
;
27808 int vpos
= w
->phys_cursor
.vpos
;
27809 struct glyph_row
*row
;
27811 if (vpos
>= w
->current_matrix
->nrows
27812 || hpos
>= w
->current_matrix
->matrix_w
)
27815 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27817 /* When the window is hscrolled, cursor hpos can legitimately be
27818 out of bounds, but we draw the cursor at the corresponding
27819 window margin in that case. */
27820 if (!row
->reversed_p
&& hpos
< 0)
27822 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27823 hpos
= row
->used
[TEXT_AREA
] - 1;
27826 display_and_set_cursor (w
, on
, hpos
, vpos
,
27827 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27833 /* Call update_window_cursor with parameter ON_P on all leaf windows
27834 in the window tree rooted at W. */
27837 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
27841 if (WINDOWP (w
->contents
))
27842 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
27844 update_window_cursor (w
, on_p
);
27846 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
27852 Display the cursor on window W, or clear it, according to ON_P.
27853 Don't change the cursor's position. */
27856 x_update_cursor (struct frame
*f
, bool on_p
)
27858 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
27863 Clear the cursor of window W to background color, and mark the
27864 cursor as not shown. This is used when the text where the cursor
27865 is about to be rewritten. */
27868 x_clear_cursor (struct window
*w
)
27870 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
27871 update_window_cursor (w
, 0);
27874 #endif /* HAVE_WINDOW_SYSTEM */
27876 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
27879 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
27880 int start_hpos
, int end_hpos
,
27881 enum draw_glyphs_face draw
)
27883 #ifdef HAVE_WINDOW_SYSTEM
27884 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
27886 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
27890 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
27891 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
27895 /* Display the active region described by mouse_face_* according to DRAW. */
27898 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
27900 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
27901 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27903 if (/* If window is in the process of being destroyed, don't bother
27905 w
->current_matrix
!= NULL
27906 /* Don't update mouse highlight if hidden. */
27907 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
27908 /* Recognize when we are called to operate on rows that don't exist
27909 anymore. This can happen when a window is split. */
27910 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
27912 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
27913 struct glyph_row
*row
, *first
, *last
;
27915 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
27916 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
27918 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
27920 int start_hpos
, end_hpos
, start_x
;
27922 /* For all but the first row, the highlight starts at column 0. */
27925 /* R2L rows have BEG and END in reversed order, but the
27926 screen drawing geometry is always left to right. So
27927 we need to mirror the beginning and end of the
27928 highlighted area in R2L rows. */
27929 if (!row
->reversed_p
)
27931 start_hpos
= hlinfo
->mouse_face_beg_col
;
27932 start_x
= hlinfo
->mouse_face_beg_x
;
27934 else if (row
== last
)
27936 start_hpos
= hlinfo
->mouse_face_end_col
;
27937 start_x
= hlinfo
->mouse_face_end_x
;
27945 else if (row
->reversed_p
&& row
== last
)
27947 start_hpos
= hlinfo
->mouse_face_end_col
;
27948 start_x
= hlinfo
->mouse_face_end_x
;
27958 if (!row
->reversed_p
)
27959 end_hpos
= hlinfo
->mouse_face_end_col
;
27960 else if (row
== first
)
27961 end_hpos
= hlinfo
->mouse_face_beg_col
;
27964 end_hpos
= row
->used
[TEXT_AREA
];
27965 if (draw
== DRAW_NORMAL_TEXT
)
27966 row
->fill_line_p
= 1; /* Clear to end of line */
27969 else if (row
->reversed_p
&& row
== first
)
27970 end_hpos
= hlinfo
->mouse_face_beg_col
;
27973 end_hpos
= row
->used
[TEXT_AREA
];
27974 if (draw
== DRAW_NORMAL_TEXT
)
27975 row
->fill_line_p
= 1; /* Clear to end of line */
27978 if (end_hpos
> start_hpos
)
27980 draw_row_with_mouse_face (w
, start_x
, row
,
27981 start_hpos
, end_hpos
, draw
);
27984 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
27988 #ifdef HAVE_WINDOW_SYSTEM
27989 /* When we've written over the cursor, arrange for it to
27990 be displayed again. */
27991 if (FRAME_WINDOW_P (f
)
27992 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
27994 int hpos
= w
->phys_cursor
.hpos
;
27996 /* When the window is hscrolled, cursor hpos can legitimately be
27997 out of bounds, but we draw the cursor at the corresponding
27998 window margin in that case. */
27999 if (!row
->reversed_p
&& hpos
< 0)
28001 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28002 hpos
= row
->used
[TEXT_AREA
] - 1;
28005 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
28006 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
28009 #endif /* HAVE_WINDOW_SYSTEM */
28012 #ifdef HAVE_WINDOW_SYSTEM
28013 /* Change the mouse cursor. */
28014 if (FRAME_WINDOW_P (f
) && NILP (do_mouse_tracking
))
28016 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
28017 if (draw
== DRAW_NORMAL_TEXT
28018 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
28019 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
28022 if (draw
== DRAW_MOUSE_FACE
)
28023 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
28025 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
28027 #endif /* HAVE_WINDOW_SYSTEM */
28031 Clear out the mouse-highlighted active region.
28032 Redraw it un-highlighted first. Value is non-zero if mouse
28033 face was actually drawn unhighlighted. */
28036 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
28040 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
28042 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
28046 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28047 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28048 hlinfo
->mouse_face_window
= Qnil
;
28049 hlinfo
->mouse_face_overlay
= Qnil
;
28053 /* Return true if the coordinates HPOS and VPOS on windows W are
28054 within the mouse face on that window. */
28056 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
28058 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28060 /* Quickly resolve the easy cases. */
28061 if (!(WINDOWP (hlinfo
->mouse_face_window
)
28062 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
28064 if (vpos
< hlinfo
->mouse_face_beg_row
28065 || vpos
> hlinfo
->mouse_face_end_row
)
28067 if (vpos
> hlinfo
->mouse_face_beg_row
28068 && vpos
< hlinfo
->mouse_face_end_row
)
28071 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
28073 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28075 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
28078 else if ((vpos
== hlinfo
->mouse_face_beg_row
28079 && hpos
>= hlinfo
->mouse_face_beg_col
)
28080 || (vpos
== hlinfo
->mouse_face_end_row
28081 && hpos
< hlinfo
->mouse_face_end_col
))
28086 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
28088 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
28091 else if ((vpos
== hlinfo
->mouse_face_beg_row
28092 && hpos
<= hlinfo
->mouse_face_beg_col
)
28093 || (vpos
== hlinfo
->mouse_face_end_row
28094 && hpos
> hlinfo
->mouse_face_end_col
))
28102 True if physical cursor of window W is within mouse face. */
28105 cursor_in_mouse_face_p (struct window
*w
)
28107 int hpos
= w
->phys_cursor
.hpos
;
28108 int vpos
= w
->phys_cursor
.vpos
;
28109 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
28111 /* When the window is hscrolled, cursor hpos can legitimately be out
28112 of bounds, but we draw the cursor at the corresponding window
28113 margin in that case. */
28114 if (!row
->reversed_p
&& hpos
< 0)
28116 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
28117 hpos
= row
->used
[TEXT_AREA
] - 1;
28119 return coords_in_mouse_face_p (w
, hpos
, vpos
);
28124 /* Find the glyph rows START_ROW and END_ROW of window W that display
28125 characters between buffer positions START_CHARPOS and END_CHARPOS
28126 (excluding END_CHARPOS). DISP_STRING is a display string that
28127 covers these buffer positions. This is similar to
28128 row_containing_pos, but is more accurate when bidi reordering makes
28129 buffer positions change non-linearly with glyph rows. */
28131 rows_from_pos_range (struct window
*w
,
28132 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
28133 Lisp_Object disp_string
,
28134 struct glyph_row
**start
, struct glyph_row
**end
)
28136 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28137 int last_y
= window_text_bottom_y (w
);
28138 struct glyph_row
*row
;
28143 while (!first
->enabled_p
28144 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
28147 /* Find the START row. */
28149 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
28152 /* A row can potentially be the START row if the range of the
28153 characters it displays intersects the range
28154 [START_CHARPOS..END_CHARPOS). */
28155 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
28156 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
28157 /* See the commentary in row_containing_pos, for the
28158 explanation of the complicated way to check whether
28159 some position is beyond the end of the characters
28160 displayed by a row. */
28161 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28162 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28163 && !row
->ends_at_zv_p
28164 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
28165 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
28166 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
28167 && !row
->ends_at_zv_p
28168 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
28170 /* Found a candidate row. Now make sure at least one of the
28171 glyphs it displays has a charpos from the range
28172 [START_CHARPOS..END_CHARPOS).
28174 This is not obvious because bidi reordering could make
28175 buffer positions of a row be 1,2,3,102,101,100, and if we
28176 want to highlight characters in [50..60), we don't want
28177 this row, even though [50..60) does intersect [1..103),
28178 the range of character positions given by the row's start
28179 and end positions. */
28180 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
28181 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
28185 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
28186 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28187 /* A glyph that comes from DISP_STRING is by
28188 definition to be highlighted. */
28189 || EQ (g
->object
, disp_string
))
28198 /* Find the END row. */
28200 /* If the last row is partially visible, start looking for END
28201 from that row, instead of starting from FIRST. */
28202 && !(row
->enabled_p
28203 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
28205 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
28207 struct glyph_row
*next
= row
+ 1;
28208 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
28210 if (!next
->enabled_p
28211 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
28212 /* The first row >= START whose range of displayed characters
28213 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
28214 is the row END + 1. */
28215 || (start_charpos
< next_start
28216 && end_charpos
< next_start
)
28217 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28218 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28219 && !next
->ends_at_zv_p
28220 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
28221 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
28222 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
28223 && !next
->ends_at_zv_p
28224 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
28231 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
28232 but none of the characters it displays are in the range, it is
28234 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
28235 struct glyph
*s
= g
;
28236 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
28240 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
28241 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
28242 /* If the buffer position of the first glyph in
28243 the row is equal to END_CHARPOS, it means
28244 the last character to be highlighted is the
28245 newline of ROW, and we must consider NEXT as
28247 || (((!next
->reversed_p
&& g
== s
)
28248 || (next
->reversed_p
&& g
== e
- 1))
28249 && (g
->charpos
== end_charpos
28250 /* Special case for when NEXT is an
28251 empty line at ZV. */
28252 || (g
->charpos
== -1
28253 && !row
->ends_at_zv_p
28254 && next_start
== end_charpos
)))))
28255 /* A glyph that comes from DISP_STRING is by
28256 definition to be highlighted. */
28257 || EQ (g
->object
, disp_string
))
28266 /* The first row that ends at ZV must be the last to be
28268 else if (next
->ends_at_zv_p
)
28277 /* This function sets the mouse_face_* elements of HLINFO, assuming
28278 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
28279 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
28280 for the overlay or run of text properties specifying the mouse
28281 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
28282 before-string and after-string that must also be highlighted.
28283 DISP_STRING, if non-nil, is a display string that may cover some
28284 or all of the highlighted text. */
28287 mouse_face_from_buffer_pos (Lisp_Object window
,
28288 Mouse_HLInfo
*hlinfo
,
28289 ptrdiff_t mouse_charpos
,
28290 ptrdiff_t start_charpos
,
28291 ptrdiff_t end_charpos
,
28292 Lisp_Object before_string
,
28293 Lisp_Object after_string
,
28294 Lisp_Object disp_string
)
28296 struct window
*w
= XWINDOW (window
);
28297 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28298 struct glyph_row
*r1
, *r2
;
28299 struct glyph
*glyph
, *end
;
28300 ptrdiff_t ignore
, pos
;
28303 eassert (NILP (disp_string
) || STRINGP (disp_string
));
28304 eassert (NILP (before_string
) || STRINGP (before_string
));
28305 eassert (NILP (after_string
) || STRINGP (after_string
));
28307 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
28308 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
28310 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28311 /* If the before-string or display-string contains newlines,
28312 rows_from_pos_range skips to its last row. Move back. */
28313 if (!NILP (before_string
) || !NILP (disp_string
))
28315 struct glyph_row
*prev
;
28316 while ((prev
= r1
- 1, prev
>= first
)
28317 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
28318 && prev
->used
[TEXT_AREA
] > 0)
28320 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
28321 glyph
= beg
+ prev
->used
[TEXT_AREA
];
28322 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
28324 || !(EQ (glyph
->object
, before_string
)
28325 || EQ (glyph
->object
, disp_string
)))
28332 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28333 hlinfo
->mouse_face_past_end
= 1;
28335 else if (!NILP (after_string
))
28337 /* If the after-string has newlines, advance to its last row. */
28338 struct glyph_row
*next
;
28339 struct glyph_row
*last
28340 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
28342 for (next
= r2
+ 1;
28344 && next
->used
[TEXT_AREA
] > 0
28345 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
28349 /* The rest of the display engine assumes that mouse_face_beg_row is
28350 either above mouse_face_end_row or identical to it. But with
28351 bidi-reordered continued lines, the row for START_CHARPOS could
28352 be below the row for END_CHARPOS. If so, swap the rows and store
28353 them in correct order. */
28356 struct glyph_row
*tem
= r2
;
28362 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
28363 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
28365 /* For a bidi-reordered row, the positions of BEFORE_STRING,
28366 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
28367 could be anywhere in the row and in any order. The strategy
28368 below is to find the leftmost and the rightmost glyph that
28369 belongs to either of these 3 strings, or whose position is
28370 between START_CHARPOS and END_CHARPOS, and highlight all the
28371 glyphs between those two. This may cover more than just the text
28372 between START_CHARPOS and END_CHARPOS if the range of characters
28373 strides the bidi level boundary, e.g. if the beginning is in R2L
28374 text while the end is in L2R text or vice versa. */
28375 if (!r1
->reversed_p
)
28377 /* This row is in a left to right paragraph. Scan it left to
28379 glyph
= r1
->glyphs
[TEXT_AREA
];
28380 end
= glyph
+ r1
->used
[TEXT_AREA
];
28383 /* Skip truncation glyphs at the start of the glyph row. */
28384 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
28386 && INTEGERP (glyph
->object
)
28387 && glyph
->charpos
< 0;
28389 x
+= glyph
->pixel_width
;
28391 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
28392 or DISP_STRING, and the first glyph from buffer whose
28393 position is between START_CHARPOS and END_CHARPOS. */
28395 && !INTEGERP (glyph
->object
)
28396 && !EQ (glyph
->object
, disp_string
)
28397 && !(BUFFERP (glyph
->object
)
28398 && (glyph
->charpos
>= start_charpos
28399 && glyph
->charpos
< end_charpos
));
28402 /* BEFORE_STRING or AFTER_STRING are only relevant if they
28403 are present at buffer positions between START_CHARPOS and
28404 END_CHARPOS, or if they come from an overlay. */
28405 if (EQ (glyph
->object
, before_string
))
28407 pos
= string_buffer_position (before_string
,
28409 /* If pos == 0, it means before_string came from an
28410 overlay, not from a buffer position. */
28411 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28414 else if (EQ (glyph
->object
, after_string
))
28416 pos
= string_buffer_position (after_string
, end_charpos
);
28417 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28420 x
+= glyph
->pixel_width
;
28422 hlinfo
->mouse_face_beg_x
= x
;
28423 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
28427 /* This row is in a right to left paragraph. Scan it right to
28431 end
= r1
->glyphs
[TEXT_AREA
] - 1;
28432 glyph
= end
+ r1
->used
[TEXT_AREA
];
28434 /* Skip truncation glyphs at the start of the glyph row. */
28435 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
28437 && INTEGERP (glyph
->object
)
28438 && glyph
->charpos
< 0;
28442 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
28443 or DISP_STRING, and the first glyph from buffer whose
28444 position is between START_CHARPOS and END_CHARPOS. */
28446 && !INTEGERP (glyph
->object
)
28447 && !EQ (glyph
->object
, disp_string
)
28448 && !(BUFFERP (glyph
->object
)
28449 && (glyph
->charpos
>= start_charpos
28450 && glyph
->charpos
< end_charpos
));
28453 /* BEFORE_STRING or AFTER_STRING are only relevant if they
28454 are present at buffer positions between START_CHARPOS and
28455 END_CHARPOS, or if they come from an overlay. */
28456 if (EQ (glyph
->object
, before_string
))
28458 pos
= string_buffer_position (before_string
, start_charpos
);
28459 /* If pos == 0, it means before_string came from an
28460 overlay, not from a buffer position. */
28461 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28464 else if (EQ (glyph
->object
, after_string
))
28466 pos
= string_buffer_position (after_string
, end_charpos
);
28467 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28472 glyph
++; /* first glyph to the right of the highlighted area */
28473 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
28474 x
+= g
->pixel_width
;
28475 hlinfo
->mouse_face_beg_x
= x
;
28476 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
28479 /* If the highlight ends in a different row, compute GLYPH and END
28480 for the end row. Otherwise, reuse the values computed above for
28481 the row where the highlight begins. */
28484 if (!r2
->reversed_p
)
28486 glyph
= r2
->glyphs
[TEXT_AREA
];
28487 end
= glyph
+ r2
->used
[TEXT_AREA
];
28492 end
= r2
->glyphs
[TEXT_AREA
] - 1;
28493 glyph
= end
+ r2
->used
[TEXT_AREA
];
28497 if (!r2
->reversed_p
)
28499 /* Skip truncation and continuation glyphs near the end of the
28500 row, and also blanks and stretch glyphs inserted by
28501 extend_face_to_end_of_line. */
28503 && INTEGERP ((end
- 1)->object
))
28505 /* Scan the rest of the glyph row from the end, looking for the
28506 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
28507 DISP_STRING, or whose position is between START_CHARPOS
28511 && !INTEGERP (end
->object
)
28512 && !EQ (end
->object
, disp_string
)
28513 && !(BUFFERP (end
->object
)
28514 && (end
->charpos
>= start_charpos
28515 && end
->charpos
< end_charpos
));
28518 /* BEFORE_STRING or AFTER_STRING are only relevant if they
28519 are present at buffer positions between START_CHARPOS and
28520 END_CHARPOS, or if they come from an overlay. */
28521 if (EQ (end
->object
, before_string
))
28523 pos
= string_buffer_position (before_string
, start_charpos
);
28524 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28527 else if (EQ (end
->object
, after_string
))
28529 pos
= string_buffer_position (after_string
, end_charpos
);
28530 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28534 /* Find the X coordinate of the last glyph to be highlighted. */
28535 for (; glyph
<= end
; ++glyph
)
28536 x
+= glyph
->pixel_width
;
28538 hlinfo
->mouse_face_end_x
= x
;
28539 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
28543 /* Skip truncation and continuation glyphs near the end of the
28544 row, and also blanks and stretch glyphs inserted by
28545 extend_face_to_end_of_line. */
28549 && INTEGERP (end
->object
))
28551 x
+= end
->pixel_width
;
28554 /* Scan the rest of the glyph row from the end, looking for the
28555 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
28556 DISP_STRING, or whose position is between START_CHARPOS
28560 && !INTEGERP (end
->object
)
28561 && !EQ (end
->object
, disp_string
)
28562 && !(BUFFERP (end
->object
)
28563 && (end
->charpos
>= start_charpos
28564 && end
->charpos
< end_charpos
));
28567 /* BEFORE_STRING or AFTER_STRING are only relevant if they
28568 are present at buffer positions between START_CHARPOS and
28569 END_CHARPOS, or if they come from an overlay. */
28570 if (EQ (end
->object
, before_string
))
28572 pos
= string_buffer_position (before_string
, start_charpos
);
28573 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28576 else if (EQ (end
->object
, after_string
))
28578 pos
= string_buffer_position (after_string
, end_charpos
);
28579 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
28582 x
+= end
->pixel_width
;
28584 /* If we exited the above loop because we arrived at the last
28585 glyph of the row, and its buffer position is still not in
28586 range, it means the last character in range is the preceding
28587 newline. Bump the end column and x values to get past the
28590 && BUFFERP (end
->object
)
28591 && (end
->charpos
< start_charpos
28592 || end
->charpos
>= end_charpos
))
28594 x
+= end
->pixel_width
;
28597 hlinfo
->mouse_face_end_x
= x
;
28598 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
28601 hlinfo
->mouse_face_window
= window
;
28602 hlinfo
->mouse_face_face_id
28603 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
28605 !hlinfo
->mouse_face_hidden
, -1);
28606 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28609 /* The following function is not used anymore (replaced with
28610 mouse_face_from_string_pos), but I leave it here for the time
28611 being, in case someone would. */
28613 #if 0 /* not used */
28615 /* Find the position of the glyph for position POS in OBJECT in
28616 window W's current matrix, and return in *X, *Y the pixel
28617 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
28619 RIGHT_P non-zero means return the position of the right edge of the
28620 glyph, RIGHT_P zero means return the left edge position.
28622 If no glyph for POS exists in the matrix, return the position of
28623 the glyph with the next smaller position that is in the matrix, if
28624 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
28625 exists in the matrix, return the position of the glyph with the
28626 next larger position in OBJECT.
28628 Value is non-zero if a glyph was found. */
28631 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
28632 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
28634 int yb
= window_text_bottom_y (w
);
28635 struct glyph_row
*r
;
28636 struct glyph
*best_glyph
= NULL
;
28637 struct glyph_row
*best_row
= NULL
;
28640 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28641 r
->enabled_p
&& r
->y
< yb
;
28644 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
28645 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
28648 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
28649 if (EQ (g
->object
, object
))
28651 if (g
->charpos
== pos
)
28658 else if (best_glyph
== NULL
28659 || ((eabs (g
->charpos
- pos
)
28660 < eabs (best_glyph
->charpos
- pos
))
28663 : g
->charpos
> pos
)))
28677 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
28681 *x
+= best_glyph
->pixel_width
;
28686 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
28689 return best_glyph
!= NULL
;
28691 #endif /* not used */
28693 /* Find the positions of the first and the last glyphs in window W's
28694 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
28695 (assumed to be a string), and return in HLINFO's mouse_face_*
28696 members the pixel and column/row coordinates of those glyphs. */
28699 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
28700 Lisp_Object object
,
28701 ptrdiff_t startpos
, ptrdiff_t endpos
)
28703 int yb
= window_text_bottom_y (w
);
28704 struct glyph_row
*r
;
28705 struct glyph
*g
, *e
;
28709 /* Find the glyph row with at least one position in the range
28710 [STARTPOS..ENDPOS), and the first glyph in that row whose
28711 position belongs to that range. */
28712 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
28713 r
->enabled_p
&& r
->y
< yb
;
28716 if (!r
->reversed_p
)
28718 g
= r
->glyphs
[TEXT_AREA
];
28719 e
= g
+ r
->used
[TEXT_AREA
];
28720 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
28721 if (EQ (g
->object
, object
)
28722 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
28724 hlinfo
->mouse_face_beg_row
28725 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
28726 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
28727 hlinfo
->mouse_face_beg_x
= gx
;
28736 e
= r
->glyphs
[TEXT_AREA
];
28737 g
= e
+ r
->used
[TEXT_AREA
];
28738 for ( ; g
> e
; --g
)
28739 if (EQ ((g
-1)->object
, object
)
28740 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
28742 hlinfo
->mouse_face_beg_row
28743 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
28744 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
28745 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
28746 gx
+= g1
->pixel_width
;
28747 hlinfo
->mouse_face_beg_x
= gx
;
28759 /* Starting with the next row, look for the first row which does NOT
28760 include any glyphs whose positions are in the range. */
28761 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
28763 g
= r
->glyphs
[TEXT_AREA
];
28764 e
= g
+ r
->used
[TEXT_AREA
];
28766 for ( ; g
< e
; ++g
)
28767 if (EQ (g
->object
, object
)
28768 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
28777 /* The highlighted region ends on the previous row. */
28780 /* Set the end row. */
28781 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
28783 /* Compute and set the end column and the end column's horizontal
28784 pixel coordinate. */
28785 if (!r
->reversed_p
)
28787 g
= r
->glyphs
[TEXT_AREA
];
28788 e
= g
+ r
->used
[TEXT_AREA
];
28789 for ( ; e
> g
; --e
)
28790 if (EQ ((e
-1)->object
, object
)
28791 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
28793 hlinfo
->mouse_face_end_col
= e
- g
;
28795 for (gx
= r
->x
; g
< e
; ++g
)
28796 gx
+= g
->pixel_width
;
28797 hlinfo
->mouse_face_end_x
= gx
;
28801 e
= r
->glyphs
[TEXT_AREA
];
28802 g
= e
+ r
->used
[TEXT_AREA
];
28803 for (gx
= r
->x
; e
< g
; ++e
)
28805 if (EQ (e
->object
, object
)
28806 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
28808 gx
+= e
->pixel_width
;
28810 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
28811 hlinfo
->mouse_face_end_x
= gx
;
28815 #ifdef HAVE_WINDOW_SYSTEM
28817 /* See if position X, Y is within a hot-spot of an image. */
28820 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
28822 if (!CONSP (hot_spot
))
28825 if (EQ (XCAR (hot_spot
), Qrect
))
28827 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
28828 Lisp_Object rect
= XCDR (hot_spot
);
28832 if (!CONSP (XCAR (rect
)))
28834 if (!CONSP (XCDR (rect
)))
28836 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
28838 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
28840 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
28842 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
28846 else if (EQ (XCAR (hot_spot
), Qcircle
))
28848 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
28849 Lisp_Object circ
= XCDR (hot_spot
);
28850 Lisp_Object lr
, lx0
, ly0
;
28852 && CONSP (XCAR (circ
))
28853 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
28854 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
28855 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
28857 double r
= XFLOATINT (lr
);
28858 double dx
= XINT (lx0
) - x
;
28859 double dy
= XINT (ly0
) - y
;
28860 return (dx
* dx
+ dy
* dy
<= r
* r
);
28863 else if (EQ (XCAR (hot_spot
), Qpoly
))
28865 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
28866 if (VECTORP (XCDR (hot_spot
)))
28868 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
28869 Lisp_Object
*poly
= v
->contents
;
28870 ptrdiff_t n
= v
->header
.size
;
28873 Lisp_Object lx
, ly
;
28876 /* Need an even number of coordinates, and at least 3 edges. */
28877 if (n
< 6 || n
& 1)
28880 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
28881 If count is odd, we are inside polygon. Pixels on edges
28882 may or may not be included depending on actual geometry of the
28884 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
28885 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
28887 x0
= XINT (lx
), y0
= XINT (ly
);
28888 for (i
= 0; i
< n
; i
+= 2)
28890 int x1
= x0
, y1
= y0
;
28891 if ((lx
= poly
[i
], !INTEGERP (lx
))
28892 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
28894 x0
= XINT (lx
), y0
= XINT (ly
);
28896 /* Does this segment cross the X line? */
28904 if (y
> y0
&& y
> y1
)
28906 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
28916 find_hot_spot (Lisp_Object map
, int x
, int y
)
28918 while (CONSP (map
))
28920 if (CONSP (XCAR (map
))
28921 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
28929 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
28931 doc
: /* Lookup in image map MAP coordinates X and Y.
28932 An image map is an alist where each element has the format (AREA ID PLIST).
28933 An AREA is specified as either a rectangle, a circle, or a polygon:
28934 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
28935 pixel coordinates of the upper left and bottom right corners.
28936 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
28937 and the radius of the circle; r may be a float or integer.
28938 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
28939 vector describes one corner in the polygon.
28940 Returns the alist element for the first matching AREA in MAP. */)
28941 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
28949 return find_hot_spot (map
,
28950 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
28951 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
28955 /* Display frame CURSOR, optionally using shape defined by POINTER. */
28957 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
28959 /* Do not change cursor shape while dragging mouse. */
28960 if (!NILP (do_mouse_tracking
))
28963 if (!NILP (pointer
))
28965 if (EQ (pointer
, Qarrow
))
28966 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28967 else if (EQ (pointer
, Qhand
))
28968 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
28969 else if (EQ (pointer
, Qtext
))
28970 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28971 else if (EQ (pointer
, intern ("hdrag")))
28972 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28973 else if (EQ (pointer
, intern ("nhdrag")))
28974 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28975 #ifdef HAVE_X_WINDOWS
28976 else if (EQ (pointer
, intern ("vdrag")))
28977 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28979 else if (EQ (pointer
, intern ("hourglass")))
28980 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
28981 else if (EQ (pointer
, Qmodeline
))
28982 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
28984 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28987 if (cursor
!= No_Cursor
)
28988 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
28991 #endif /* HAVE_WINDOW_SYSTEM */
28993 /* Take proper action when mouse has moved to the mode or header line
28994 or marginal area AREA of window W, x-position X and y-position Y.
28995 X is relative to the start of the text display area of W, so the
28996 width of bitmap areas and scroll bars must be subtracted to get a
28997 position relative to the start of the mode line. */
29000 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
29001 enum window_part area
)
29003 struct window
*w
= XWINDOW (window
);
29004 struct frame
*f
= XFRAME (w
->frame
);
29005 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29006 #ifdef HAVE_WINDOW_SYSTEM
29007 Display_Info
*dpyinfo
;
29009 Cursor cursor
= No_Cursor
;
29010 Lisp_Object pointer
= Qnil
;
29011 int dx
, dy
, width
, height
;
29013 Lisp_Object string
, object
= Qnil
;
29014 Lisp_Object pos
IF_LINT (= Qnil
), help
;
29016 Lisp_Object mouse_face
;
29017 int original_x_pixel
= x
;
29018 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
29019 struct glyph_row
*row
IF_LINT (= 0);
29021 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
29026 /* Kludge alert: mode_line_string takes X/Y in pixels, but
29027 returns them in row/column units! */
29028 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
29029 &object
, &dx
, &dy
, &width
, &height
);
29031 row
= (area
== ON_MODE_LINE
29032 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
29033 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
29035 /* Find the glyph under the mouse pointer. */
29036 if (row
->mode_line_p
&& row
->enabled_p
)
29038 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
29039 end
= glyph
+ row
->used
[TEXT_AREA
];
29041 for (x0
= original_x_pixel
;
29042 glyph
< end
&& x0
>= glyph
->pixel_width
;
29044 x0
-= glyph
->pixel_width
;
29052 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
29053 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
29054 returns them in row/column units! */
29055 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
29056 &object
, &dx
, &dy
, &width
, &height
);
29061 #ifdef HAVE_WINDOW_SYSTEM
29062 if (IMAGEP (object
))
29064 Lisp_Object image_map
, hotspot
;
29065 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
29067 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
29069 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
29073 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
29074 If so, we could look for mouse-enter, mouse-leave
29075 properties in PLIST (and do something...). */
29076 hotspot
= XCDR (hotspot
);
29077 if (CONSP (hotspot
)
29078 && (plist
= XCAR (hotspot
), CONSP (plist
)))
29080 pointer
= Fplist_get (plist
, Qpointer
);
29081 if (NILP (pointer
))
29083 help
= Fplist_get (plist
, Qhelp_echo
);
29086 help_echo_string
= help
;
29087 XSETWINDOW (help_echo_window
, w
);
29088 help_echo_object
= w
->contents
;
29089 help_echo_pos
= charpos
;
29093 if (NILP (pointer
))
29094 pointer
= Fplist_get (XCDR (object
), QCpointer
);
29096 #endif /* HAVE_WINDOW_SYSTEM */
29098 if (STRINGP (string
))
29099 pos
= make_number (charpos
);
29101 /* Set the help text and mouse pointer. If the mouse is on a part
29102 of the mode line without any text (e.g. past the right edge of
29103 the mode line text), use the default help text and pointer. */
29104 if (STRINGP (string
) || area
== ON_MODE_LINE
)
29106 /* Arrange to display the help by setting the global variables
29107 help_echo_string, help_echo_object, and help_echo_pos. */
29110 if (STRINGP (string
))
29111 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
29115 help_echo_string
= help
;
29116 XSETWINDOW (help_echo_window
, w
);
29117 help_echo_object
= string
;
29118 help_echo_pos
= charpos
;
29120 else if (area
== ON_MODE_LINE
)
29122 Lisp_Object default_help
29123 = buffer_local_value (Qmode_line_default_help_echo
,
29126 if (STRINGP (default_help
))
29128 help_echo_string
= default_help
;
29129 XSETWINDOW (help_echo_window
, w
);
29130 help_echo_object
= Qnil
;
29131 help_echo_pos
= -1;
29136 #ifdef HAVE_WINDOW_SYSTEM
29137 /* Change the mouse pointer according to what is under it. */
29138 if (FRAME_WINDOW_P (f
))
29140 bool draggable
= (! WINDOW_BOTTOMMOST_P (w
)
29142 || NILP (Vresize_mini_windows
));
29144 dpyinfo
= FRAME_DISPLAY_INFO (f
);
29145 if (STRINGP (string
))
29147 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29149 if (NILP (pointer
))
29150 pointer
= Fget_text_property (pos
, Qpointer
, string
);
29152 /* Change the mouse pointer according to what is under X/Y. */
29154 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
29157 map
= Fget_text_property (pos
, Qlocal_map
, string
);
29158 if (!KEYMAPP (map
))
29159 map
= Fget_text_property (pos
, Qkeymap
, string
);
29160 if (!KEYMAPP (map
) && draggable
)
29161 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
29164 else if (draggable
)
29165 /* Default mode-line pointer. */
29166 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
29171 /* Change the mouse face according to what is under X/Y. */
29172 if (STRINGP (string
))
29174 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
29175 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
29176 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
29181 struct glyph
* tmp_glyph
;
29185 int total_pixel_width
;
29186 ptrdiff_t begpos
, endpos
, ignore
;
29190 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
29191 Qmouse_face
, string
, Qnil
);
29197 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
29199 endpos
= SCHARS (string
);
29203 /* Calculate the glyph position GPOS of GLYPH in the
29204 displayed string, relative to the beginning of the
29205 highlighted part of the string.
29207 Note: GPOS is different from CHARPOS. CHARPOS is the
29208 position of GLYPH in the internal string object. A mode
29209 line string format has structures which are converted to
29210 a flattened string by the Emacs Lisp interpreter. The
29211 internal string is an element of those structures. The
29212 displayed string is the flattened string. */
29213 tmp_glyph
= row_start_glyph
;
29214 while (tmp_glyph
< glyph
29215 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29216 && begpos
<= tmp_glyph
->charpos
29217 && tmp_glyph
->charpos
< endpos
)))
29219 gpos
= glyph
- tmp_glyph
;
29221 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
29222 the highlighted part of the displayed string to which
29223 GLYPH belongs. Note: GSEQ_LENGTH is different from
29224 SCHARS (STRING), because the latter returns the length of
29225 the internal string. */
29226 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
29228 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
29229 && begpos
<= tmp_glyph
->charpos
29230 && tmp_glyph
->charpos
< endpos
));
29233 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
29235 /* Calculate the total pixel width of all the glyphs between
29236 the beginning of the highlighted area and GLYPH. */
29237 total_pixel_width
= 0;
29238 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
29239 total_pixel_width
+= tmp_glyph
->pixel_width
;
29241 /* Pre calculation of re-rendering position. Note: X is in
29242 column units here, after the call to mode_line_string or
29243 marginal_area_string. */
29245 vpos
= (area
== ON_MODE_LINE
29246 ? (w
->current_matrix
)->nrows
- 1
29249 /* If GLYPH's position is included in the region that is
29250 already drawn in mouse face, we have nothing to do. */
29251 if ( EQ (window
, hlinfo
->mouse_face_window
)
29252 && (!row
->reversed_p
29253 ? (hlinfo
->mouse_face_beg_col
<= hpos
29254 && hpos
< hlinfo
->mouse_face_end_col
)
29255 /* In R2L rows we swap BEG and END, see below. */
29256 : (hlinfo
->mouse_face_end_col
<= hpos
29257 && hpos
< hlinfo
->mouse_face_beg_col
))
29258 && hlinfo
->mouse_face_beg_row
== vpos
)
29261 if (clear_mouse_face (hlinfo
))
29262 cursor
= No_Cursor
;
29264 if (!row
->reversed_p
)
29266 hlinfo
->mouse_face_beg_col
= hpos
;
29267 hlinfo
->mouse_face_beg_x
= original_x_pixel
29268 - (total_pixel_width
+ dx
);
29269 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
29270 hlinfo
->mouse_face_end_x
= 0;
29274 /* In R2L rows, show_mouse_face expects BEG and END
29275 coordinates to be swapped. */
29276 hlinfo
->mouse_face_end_col
= hpos
;
29277 hlinfo
->mouse_face_end_x
= original_x_pixel
29278 - (total_pixel_width
+ dx
);
29279 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
29280 hlinfo
->mouse_face_beg_x
= 0;
29283 hlinfo
->mouse_face_beg_row
= vpos
;
29284 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
29285 hlinfo
->mouse_face_past_end
= 0;
29286 hlinfo
->mouse_face_window
= window
;
29288 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
29293 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29295 if (NILP (pointer
))
29298 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
29299 clear_mouse_face (hlinfo
);
29301 #ifdef HAVE_WINDOW_SYSTEM
29302 if (FRAME_WINDOW_P (f
))
29303 define_frame_cursor1 (f
, cursor
, pointer
);
29309 Take proper action when the mouse has moved to position X, Y on
29310 frame F with regards to highlighting portions of display that have
29311 mouse-face properties. Also de-highlight portions of display where
29312 the mouse was before, set the mouse pointer shape as appropriate
29313 for the mouse coordinates, and activate help echo (tooltips).
29314 X and Y can be negative or out of range. */
29317 note_mouse_highlight (struct frame
*f
, int x
, int y
)
29319 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29320 enum window_part part
= ON_NOTHING
;
29321 Lisp_Object window
;
29323 Cursor cursor
= No_Cursor
;
29324 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
29327 /* When a menu is active, don't highlight because this looks odd. */
29328 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
29329 if (popup_activated ())
29333 if (!f
->glyphs_initialized_p
29334 || f
->pointer_invisible
)
29337 hlinfo
->mouse_face_mouse_x
= x
;
29338 hlinfo
->mouse_face_mouse_y
= y
;
29339 hlinfo
->mouse_face_mouse_frame
= f
;
29341 if (hlinfo
->mouse_face_defer
)
29344 /* Which window is that in? */
29345 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
29347 /* If displaying active text in another window, clear that. */
29348 if (! EQ (window
, hlinfo
->mouse_face_window
)
29349 /* Also clear if we move out of text area in same window. */
29350 || (!NILP (hlinfo
->mouse_face_window
)
29353 && part
!= ON_MODE_LINE
29354 && part
!= ON_HEADER_LINE
))
29355 clear_mouse_face (hlinfo
);
29357 /* Not on a window -> return. */
29358 if (!WINDOWP (window
))
29361 /* Reset help_echo_string. It will get recomputed below. */
29362 help_echo_string
= Qnil
;
29364 /* Convert to window-relative pixel coordinates. */
29365 w
= XWINDOW (window
);
29366 frame_to_window_pixel_xy (w
, &x
, &y
);
29368 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
29369 /* Handle tool-bar window differently since it doesn't display a
29371 if (EQ (window
, f
->tool_bar_window
))
29373 note_tool_bar_highlight (f
, x
, y
);
29378 /* Mouse is on the mode, header line or margin? */
29379 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
29380 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
29382 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
29384 #ifdef HAVE_WINDOW_SYSTEM
29385 if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
29387 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29388 /* Show non-text cursor (Bug#16647). */
29396 #ifdef HAVE_WINDOW_SYSTEM
29397 if (part
== ON_VERTICAL_BORDER
)
29399 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29400 help_echo_string
= build_string ("drag-mouse-1: resize");
29402 else if (part
== ON_RIGHT_DIVIDER
)
29404 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
29405 help_echo_string
= build_string ("drag-mouse-1: resize");
29407 else if (part
== ON_BOTTOM_DIVIDER
)
29408 if (! WINDOW_BOTTOMMOST_P (w
)
29410 || NILP (Vresize_mini_windows
))
29412 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
29413 help_echo_string
= build_string ("drag-mouse-1: resize");
29416 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29417 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
29418 || part
== ON_VERTICAL_SCROLL_BAR
29419 || part
== ON_HORIZONTAL_SCROLL_BAR
)
29420 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29422 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
29425 /* Are we in a window whose display is up to date?
29426 And verify the buffer's text has not changed. */
29427 b
= XBUFFER (w
->contents
);
29428 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
29430 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
29432 struct glyph
*glyph
;
29433 Lisp_Object object
;
29434 Lisp_Object mouse_face
= Qnil
, position
;
29435 Lisp_Object
*overlay_vec
= NULL
;
29436 ptrdiff_t i
, noverlays
;
29437 struct buffer
*obuf
;
29438 ptrdiff_t obegv
, ozv
;
29441 /* Find the glyph under X/Y. */
29442 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
29444 #ifdef HAVE_WINDOW_SYSTEM
29445 /* Look for :pointer property on image. */
29446 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
29448 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
29449 if (img
!= NULL
&& IMAGEP (img
->spec
))
29451 Lisp_Object image_map
, hotspot
;
29452 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
29454 && (hotspot
= find_hot_spot (image_map
,
29455 glyph
->slice
.img
.x
+ dx
,
29456 glyph
->slice
.img
.y
+ dy
),
29458 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
29462 /* Could check XCAR (hotspot) to see if we enter/leave
29464 If so, we could look for mouse-enter, mouse-leave
29465 properties in PLIST (and do something...). */
29466 hotspot
= XCDR (hotspot
);
29467 if (CONSP (hotspot
)
29468 && (plist
= XCAR (hotspot
), CONSP (plist
)))
29470 pointer
= Fplist_get (plist
, Qpointer
);
29471 if (NILP (pointer
))
29473 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
29474 if (!NILP (help_echo_string
))
29476 help_echo_window
= window
;
29477 help_echo_object
= glyph
->object
;
29478 help_echo_pos
= glyph
->charpos
;
29482 if (NILP (pointer
))
29483 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
29486 #endif /* HAVE_WINDOW_SYSTEM */
29488 /* Clear mouse face if X/Y not over text. */
29490 || area
!= TEXT_AREA
29491 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
29492 /* Glyph's OBJECT is an integer for glyphs inserted by the
29493 display engine for its internal purposes, like truncation
29494 and continuation glyphs and blanks beyond the end of
29495 line's text on text terminals. If we are over such a
29496 glyph, we are not over any text. */
29497 || INTEGERP (glyph
->object
)
29498 /* R2L rows have a stretch glyph at their front, which
29499 stands for no text, whereas L2R rows have no glyphs at
29500 all beyond the end of text. Treat such stretch glyphs
29501 like we do with NULL glyphs in L2R rows. */
29502 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
29503 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
29504 && glyph
->type
== STRETCH_GLYPH
29505 && glyph
->avoid_cursor_p
))
29507 if (clear_mouse_face (hlinfo
))
29508 cursor
= No_Cursor
;
29509 #ifdef HAVE_WINDOW_SYSTEM
29510 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
29512 if (area
!= TEXT_AREA
)
29513 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
29515 pointer
= Vvoid_text_area_pointer
;
29521 pos
= glyph
->charpos
;
29522 object
= glyph
->object
;
29523 if (!STRINGP (object
) && !BUFFERP (object
))
29526 /* If we get an out-of-range value, return now; avoid an error. */
29527 if (BUFFERP (object
) && pos
> BUF_Z (b
))
29530 /* Make the window's buffer temporarily current for
29531 overlays_at and compute_char_face. */
29532 obuf
= current_buffer
;
29533 current_buffer
= b
;
29539 /* Is this char mouse-active or does it have help-echo? */
29540 position
= make_number (pos
);
29544 if (BUFFERP (object
))
29546 /* Put all the overlays we want in a vector in overlay_vec. */
29547 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
29548 /* Sort overlays into increasing priority order. */
29549 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
29554 if (NILP (Vmouse_highlight
))
29556 clear_mouse_face (hlinfo
);
29557 goto check_help_echo
;
29560 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
29563 cursor
= No_Cursor
;
29565 /* Check mouse-face highlighting. */
29567 /* If there exists an overlay with mouse-face overlapping
29568 the one we are currently highlighting, we have to
29569 check if we enter the overlapping overlay, and then
29570 highlight only that. */
29571 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
29572 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
29574 /* Find the highest priority overlay with a mouse-face. */
29575 Lisp_Object overlay
= Qnil
;
29576 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
29578 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
29579 if (!NILP (mouse_face
))
29580 overlay
= overlay_vec
[i
];
29583 /* If we're highlighting the same overlay as before, there's
29584 no need to do that again. */
29585 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
29586 goto check_help_echo
;
29587 hlinfo
->mouse_face_overlay
= overlay
;
29589 /* Clear the display of the old active region, if any. */
29590 if (clear_mouse_face (hlinfo
))
29591 cursor
= No_Cursor
;
29593 /* If no overlay applies, get a text property. */
29594 if (NILP (overlay
))
29595 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
29597 /* Next, compute the bounds of the mouse highlighting and
29599 if (!NILP (mouse_face
) && STRINGP (object
))
29601 /* The mouse-highlighting comes from a display string
29602 with a mouse-face. */
29606 s
= Fprevious_single_property_change
29607 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
29608 e
= Fnext_single_property_change
29609 (position
, Qmouse_face
, object
, Qnil
);
29611 s
= make_number (0);
29613 e
= make_number (SCHARS (object
));
29614 mouse_face_from_string_pos (w
, hlinfo
, object
,
29615 XINT (s
), XINT (e
));
29616 hlinfo
->mouse_face_past_end
= 0;
29617 hlinfo
->mouse_face_window
= window
;
29618 hlinfo
->mouse_face_face_id
29619 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
29620 glyph
->face_id
, 1);
29621 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
29622 cursor
= No_Cursor
;
29626 /* The mouse-highlighting, if any, comes from an overlay
29627 or text property in the buffer. */
29628 Lisp_Object buffer
IF_LINT (= Qnil
);
29629 Lisp_Object disp_string
IF_LINT (= Qnil
);
29631 if (STRINGP (object
))
29633 /* If we are on a display string with no mouse-face,
29634 check if the text under it has one. */
29635 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
29636 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
29637 pos
= string_buffer_position (object
, start
);
29640 mouse_face
= get_char_property_and_overlay
29641 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
29642 buffer
= w
->contents
;
29643 disp_string
= object
;
29649 disp_string
= Qnil
;
29652 if (!NILP (mouse_face
))
29654 Lisp_Object before
, after
;
29655 Lisp_Object before_string
, after_string
;
29656 /* To correctly find the limits of mouse highlight
29657 in a bidi-reordered buffer, we must not use the
29658 optimization of limiting the search in
29659 previous-single-property-change and
29660 next-single-property-change, because
29661 rows_from_pos_range needs the real start and end
29662 positions to DTRT in this case. That's because
29663 the first row visible in a window does not
29664 necessarily display the character whose position
29665 is the smallest. */
29667 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
29668 ? Fmarker_position (w
->start
)
29671 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
29672 ? make_number (BUF_Z (XBUFFER (buffer
))
29673 - w
->window_end_pos
)
29676 if (NILP (overlay
))
29678 /* Handle the text property case. */
29679 before
= Fprevious_single_property_change
29680 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
29681 after
= Fnext_single_property_change
29682 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
29683 before_string
= after_string
= Qnil
;
29687 /* Handle the overlay case. */
29688 before
= Foverlay_start (overlay
);
29689 after
= Foverlay_end (overlay
);
29690 before_string
= Foverlay_get (overlay
, Qbefore_string
);
29691 after_string
= Foverlay_get (overlay
, Qafter_string
);
29693 if (!STRINGP (before_string
)) before_string
= Qnil
;
29694 if (!STRINGP (after_string
)) after_string
= Qnil
;
29697 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
29700 : XFASTINT (before
),
29702 ? BUF_Z (XBUFFER (buffer
))
29703 : XFASTINT (after
),
29704 before_string
, after_string
,
29706 cursor
= No_Cursor
;
29713 /* Look for a `help-echo' property. */
29714 if (NILP (help_echo_string
)) {
29715 Lisp_Object help
, overlay
;
29717 /* Check overlays first. */
29718 help
= overlay
= Qnil
;
29719 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
29721 overlay
= overlay_vec
[i
];
29722 help
= Foverlay_get (overlay
, Qhelp_echo
);
29727 help_echo_string
= help
;
29728 help_echo_window
= window
;
29729 help_echo_object
= overlay
;
29730 help_echo_pos
= pos
;
29734 Lisp_Object obj
= glyph
->object
;
29735 ptrdiff_t charpos
= glyph
->charpos
;
29737 /* Try text properties. */
29740 && charpos
< SCHARS (obj
))
29742 help
= Fget_text_property (make_number (charpos
),
29746 /* If the string itself doesn't specify a help-echo,
29747 see if the buffer text ``under'' it does. */
29748 struct glyph_row
*r
29749 = MATRIX_ROW (w
->current_matrix
, vpos
);
29750 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
29751 ptrdiff_t p
= string_buffer_position (obj
, start
);
29754 help
= Fget_char_property (make_number (p
),
29755 Qhelp_echo
, w
->contents
);
29764 else if (BUFFERP (obj
)
29767 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
29772 help_echo_string
= help
;
29773 help_echo_window
= window
;
29774 help_echo_object
= obj
;
29775 help_echo_pos
= charpos
;
29780 #ifdef HAVE_WINDOW_SYSTEM
29781 /* Look for a `pointer' property. */
29782 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
29784 /* Check overlays first. */
29785 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
29786 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
29788 if (NILP (pointer
))
29790 Lisp_Object obj
= glyph
->object
;
29791 ptrdiff_t charpos
= glyph
->charpos
;
29793 /* Try text properties. */
29796 && charpos
< SCHARS (obj
))
29798 pointer
= Fget_text_property (make_number (charpos
),
29800 if (NILP (pointer
))
29802 /* If the string itself doesn't specify a pointer,
29803 see if the buffer text ``under'' it does. */
29804 struct glyph_row
*r
29805 = MATRIX_ROW (w
->current_matrix
, vpos
);
29806 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
29807 ptrdiff_t p
= string_buffer_position (obj
, start
);
29809 pointer
= Fget_char_property (make_number (p
),
29810 Qpointer
, w
->contents
);
29813 else if (BUFFERP (obj
)
29816 pointer
= Fget_text_property (make_number (charpos
),
29820 #endif /* HAVE_WINDOW_SYSTEM */
29824 current_buffer
= obuf
;
29830 #ifdef HAVE_WINDOW_SYSTEM
29831 if (FRAME_WINDOW_P (f
))
29832 define_frame_cursor1 (f
, cursor
, pointer
);
29834 /* This is here to prevent a compiler error, about "label at end of
29835 compound statement". */
29842 Clear any mouse-face on window W. This function is part of the
29843 redisplay interface, and is called from try_window_id and similar
29844 functions to ensure the mouse-highlight is off. */
29847 x_clear_window_mouse_face (struct window
*w
)
29849 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
29850 Lisp_Object window
;
29853 XSETWINDOW (window
, w
);
29854 if (EQ (window
, hlinfo
->mouse_face_window
))
29855 clear_mouse_face (hlinfo
);
29861 Just discard the mouse face information for frame F, if any.
29862 This is used when the size of F is changed. */
29865 cancel_mouse_face (struct frame
*f
)
29867 Lisp_Object window
;
29868 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29870 window
= hlinfo
->mouse_face_window
;
29871 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
29872 reset_mouse_highlight (hlinfo
);
29877 /***********************************************************************
29879 ***********************************************************************/
29881 #ifdef HAVE_WINDOW_SYSTEM
29883 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
29884 which intersects rectangle R. R is in window-relative coordinates. */
29887 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
29888 enum glyph_row_area area
)
29890 struct glyph
*first
= row
->glyphs
[area
];
29891 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
29892 struct glyph
*last
;
29893 int first_x
, start_x
, x
;
29895 if (area
== TEXT_AREA
&& row
->fill_line_p
)
29896 /* If row extends face to end of line write the whole line. */
29897 draw_glyphs (w
, 0, row
, area
,
29898 0, row
->used
[area
],
29899 DRAW_NORMAL_TEXT
, 0);
29902 /* Set START_X to the window-relative start position for drawing glyphs of
29903 AREA. The first glyph of the text area can be partially visible.
29904 The first glyphs of other areas cannot. */
29905 start_x
= window_box_left_offset (w
, area
);
29907 if (area
== TEXT_AREA
)
29910 /* Find the first glyph that must be redrawn. */
29912 && x
+ first
->pixel_width
< r
->x
)
29914 x
+= first
->pixel_width
;
29918 /* Find the last one. */
29922 && x
< r
->x
+ r
->width
)
29924 x
+= last
->pixel_width
;
29930 draw_glyphs (w
, first_x
- start_x
, row
, area
,
29931 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
29932 DRAW_NORMAL_TEXT
, 0);
29937 /* Redraw the parts of the glyph row ROW on window W intersecting
29938 rectangle R. R is in window-relative coordinates. Value is
29939 non-zero if mouse-face was overwritten. */
29942 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
29944 eassert (row
->enabled_p
);
29946 if (row
->mode_line_p
|| w
->pseudo_window_p
)
29947 draw_glyphs (w
, 0, row
, TEXT_AREA
,
29948 0, row
->used
[TEXT_AREA
],
29949 DRAW_NORMAL_TEXT
, 0);
29952 if (row
->used
[LEFT_MARGIN_AREA
])
29953 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
29954 if (row
->used
[TEXT_AREA
])
29955 expose_area (w
, row
, r
, TEXT_AREA
);
29956 if (row
->used
[RIGHT_MARGIN_AREA
])
29957 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
29958 draw_row_fringe_bitmaps (w
, row
);
29961 return row
->mouse_face_p
;
29965 /* Redraw those parts of glyphs rows during expose event handling that
29966 overlap other rows. Redrawing of an exposed line writes over parts
29967 of lines overlapping that exposed line; this function fixes that.
29969 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
29970 row in W's current matrix that is exposed and overlaps other rows.
29971 LAST_OVERLAPPING_ROW is the last such row. */
29974 expose_overlaps (struct window
*w
,
29975 struct glyph_row
*first_overlapping_row
,
29976 struct glyph_row
*last_overlapping_row
,
29979 struct glyph_row
*row
;
29981 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
29982 if (row
->overlapping_p
)
29984 eassert (row
->enabled_p
&& !row
->mode_line_p
);
29987 if (row
->used
[LEFT_MARGIN_AREA
])
29988 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
29990 if (row
->used
[TEXT_AREA
])
29991 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
29993 if (row
->used
[RIGHT_MARGIN_AREA
])
29994 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
30000 /* Return non-zero if W's cursor intersects rectangle R. */
30003 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
30005 XRectangle cr
, result
;
30006 struct glyph
*cursor_glyph
;
30007 struct glyph_row
*row
;
30009 if (w
->phys_cursor
.vpos
>= 0
30010 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
30011 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
30013 && row
->cursor_in_fringe_p
)
30015 /* Cursor is in the fringe. */
30016 cr
.x
= window_box_right_offset (w
,
30017 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
30018 ? RIGHT_MARGIN_AREA
30021 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
30022 cr
.height
= row
->height
;
30023 return x_intersect_rectangles (&cr
, r
, &result
);
30026 cursor_glyph
= get_phys_cursor_glyph (w
);
30029 /* r is relative to W's box, but w->phys_cursor.x is relative
30030 to left edge of W's TEXT area. Adjust it. */
30031 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
30032 cr
.y
= w
->phys_cursor
.y
;
30033 cr
.width
= cursor_glyph
->pixel_width
;
30034 cr
.height
= w
->phys_cursor_height
;
30035 /* ++KFS: W32 version used W32-specific IntersectRect here, but
30036 I assume the effect is the same -- and this is portable. */
30037 return x_intersect_rectangles (&cr
, r
, &result
);
30039 /* If we don't understand the format, pretend we're not in the hot-spot. */
30045 Draw a vertical window border to the right of window W if W doesn't
30046 have vertical scroll bars. */
30049 x_draw_vertical_border (struct window
*w
)
30051 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30053 /* We could do better, if we knew what type of scroll-bar the adjacent
30054 windows (on either side) have... But we don't :-(
30055 However, I think this works ok. ++KFS 2003-04-25 */
30057 /* Redraw borders between horizontally adjacent windows. Don't
30058 do it for frames with vertical scroll bars because either the
30059 right scroll bar of a window, or the left scroll bar of its
30060 neighbor will suffice as a border. */
30061 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
30064 /* Note: It is necessary to redraw both the left and the right
30065 borders, for when only this single window W is being
30067 if (!WINDOW_RIGHTMOST_P (w
)
30068 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
30070 int x0
, x1
, y0
, y1
;
30072 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30075 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30078 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
30081 if (!WINDOW_LEFTMOST_P (w
)
30082 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
30084 int x0
, x1
, y0
, y1
;
30086 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
30089 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
30092 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
30097 /* Draw window dividers for window W. */
30100 x_draw_right_divider (struct window
*w
)
30102 struct frame
*f
= WINDOW_XFRAME (w
);
30104 if (w
->mini
|| w
->pseudo_window_p
)
30106 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30108 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
30109 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30110 int y0
= WINDOW_TOP_EDGE_Y (w
);
30111 /* The bottom divider prevails. */
30112 int y1
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30114 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30119 x_draw_bottom_divider (struct window
*w
)
30121 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
30123 if (w
->mini
|| w
->pseudo_window_p
)
30125 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30127 int x0
= WINDOW_LEFT_EDGE_X (w
);
30128 int x1
= WINDOW_RIGHT_EDGE_X (w
);
30129 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
30130 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
30132 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
30136 /* Redraw the part of window W intersection rectangle FR. Pixel
30137 coordinates in FR are frame-relative. Call this function with
30138 input blocked. Value is non-zero if the exposure overwrites
30142 expose_window (struct window
*w
, XRectangle
*fr
)
30144 struct frame
*f
= XFRAME (w
->frame
);
30146 int mouse_face_overwritten_p
= 0;
30148 /* If window is not yet fully initialized, do nothing. This can
30149 happen when toolkit scroll bars are used and a window is split.
30150 Reconfiguring the scroll bar will generate an expose for a newly
30152 if (w
->current_matrix
== NULL
)
30155 /* When we're currently updating the window, display and current
30156 matrix usually don't agree. Arrange for a thorough display
30158 if (w
->must_be_updated_p
)
30160 SET_FRAME_GARBAGED (f
);
30164 /* Frame-relative pixel rectangle of W. */
30165 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
30166 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
30167 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
30168 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
30170 if (x_intersect_rectangles (fr
, &wr
, &r
))
30172 int yb
= window_text_bottom_y (w
);
30173 struct glyph_row
*row
;
30174 int cursor_cleared_p
, phys_cursor_on_p
;
30175 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
30177 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
30178 r
.x
, r
.y
, r
.width
, r
.height
));
30180 /* Convert to window coordinates. */
30181 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
30182 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
30184 /* Turn off the cursor. */
30185 if (!w
->pseudo_window_p
30186 && phys_cursor_in_rect_p (w
, &r
))
30188 x_clear_cursor (w
);
30189 cursor_cleared_p
= 1;
30192 cursor_cleared_p
= 0;
30194 /* If the row containing the cursor extends face to end of line,
30195 then expose_area might overwrite the cursor outside the
30196 rectangle and thus notice_overwritten_cursor might clear
30197 w->phys_cursor_on_p. We remember the original value and
30198 check later if it is changed. */
30199 phys_cursor_on_p
= w
->phys_cursor_on_p
;
30201 /* Update lines intersecting rectangle R. */
30202 first_overlapping_row
= last_overlapping_row
= NULL
;
30203 for (row
= w
->current_matrix
->rows
;
30208 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
30210 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
30211 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
30212 || (r
.y
>= y0
&& r
.y
< y1
)
30213 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
30215 /* A header line may be overlapping, but there is no need
30216 to fix overlapping areas for them. KFS 2005-02-12 */
30217 if (row
->overlapping_p
&& !row
->mode_line_p
)
30219 if (first_overlapping_row
== NULL
)
30220 first_overlapping_row
= row
;
30221 last_overlapping_row
= row
;
30225 if (expose_line (w
, row
, &r
))
30226 mouse_face_overwritten_p
= 1;
30229 else if (row
->overlapping_p
)
30231 /* We must redraw a row overlapping the exposed area. */
30233 ? y0
+ row
->phys_height
> r
.y
30234 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
30236 if (first_overlapping_row
== NULL
)
30237 first_overlapping_row
= row
;
30238 last_overlapping_row
= row
;
30246 /* Display the mode line if there is one. */
30247 if (WINDOW_WANTS_MODELINE_P (w
)
30248 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
30250 && row
->y
< r
.y
+ r
.height
)
30252 if (expose_line (w
, row
, &r
))
30253 mouse_face_overwritten_p
= 1;
30256 if (!w
->pseudo_window_p
)
30258 /* Fix the display of overlapping rows. */
30259 if (first_overlapping_row
)
30260 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
30263 /* Draw border between windows. */
30264 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
30265 x_draw_right_divider (w
);
30267 x_draw_vertical_border (w
);
30269 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
30270 x_draw_bottom_divider (w
);
30272 /* Turn the cursor on again. */
30273 if (cursor_cleared_p
30274 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
30275 update_window_cursor (w
, 1);
30279 return mouse_face_overwritten_p
;
30284 /* Redraw (parts) of all windows in the window tree rooted at W that
30285 intersect R. R contains frame pixel coordinates. Value is
30286 non-zero if the exposure overwrites mouse-face. */
30289 expose_window_tree (struct window
*w
, XRectangle
*r
)
30291 struct frame
*f
= XFRAME (w
->frame
);
30292 int mouse_face_overwritten_p
= 0;
30294 while (w
&& !FRAME_GARBAGED_P (f
))
30296 if (WINDOWP (w
->contents
))
30297 mouse_face_overwritten_p
30298 |= expose_window_tree (XWINDOW (w
->contents
), r
);
30300 mouse_face_overwritten_p
|= expose_window (w
, r
);
30302 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
30305 return mouse_face_overwritten_p
;
30310 Redisplay an exposed area of frame F. X and Y are the upper-left
30311 corner of the exposed rectangle. W and H are width and height of
30312 the exposed area. All are pixel values. W or H zero means redraw
30313 the entire frame. */
30316 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
30319 int mouse_face_overwritten_p
= 0;
30321 TRACE ((stderr
, "expose_frame "));
30323 /* No need to redraw if frame will be redrawn soon. */
30324 if (FRAME_GARBAGED_P (f
))
30326 TRACE ((stderr
, " garbaged\n"));
30330 /* If basic faces haven't been realized yet, there is no point in
30331 trying to redraw anything. This can happen when we get an expose
30332 event while Emacs is starting, e.g. by moving another window. */
30333 if (FRAME_FACE_CACHE (f
) == NULL
30334 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
30336 TRACE ((stderr
, " no faces\n"));
30340 if (w
== 0 || h
== 0)
30343 r
.width
= FRAME_TEXT_WIDTH (f
);
30344 r
.height
= FRAME_TEXT_HEIGHT (f
);
30354 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
30355 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
30357 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
30358 if (WINDOWP (f
->tool_bar_window
))
30359 mouse_face_overwritten_p
30360 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
30363 #ifdef HAVE_X_WINDOWS
30365 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
30366 if (WINDOWP (f
->menu_bar_window
))
30367 mouse_face_overwritten_p
30368 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
30369 #endif /* not USE_X_TOOLKIT and not USE_GTK */
30373 /* Some window managers support a focus-follows-mouse style with
30374 delayed raising of frames. Imagine a partially obscured frame,
30375 and moving the mouse into partially obscured mouse-face on that
30376 frame. The visible part of the mouse-face will be highlighted,
30377 then the WM raises the obscured frame. With at least one WM, KDE
30378 2.1, Emacs is not getting any event for the raising of the frame
30379 (even tried with SubstructureRedirectMask), only Expose events.
30380 These expose events will draw text normally, i.e. not
30381 highlighted. Which means we must redo the highlight here.
30382 Subsume it under ``we love X''. --gerd 2001-08-15 */
30383 /* Included in Windows version because Windows most likely does not
30384 do the right thing if any third party tool offers
30385 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
30386 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
30388 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
30389 if (f
== hlinfo
->mouse_face_mouse_frame
)
30391 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
30392 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
30393 clear_mouse_face (hlinfo
);
30394 note_mouse_highlight (f
, mouse_x
, mouse_y
);
30401 Determine the intersection of two rectangles R1 and R2. Return
30402 the intersection in *RESULT. Value is non-zero if RESULT is not
30406 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
30408 XRectangle
*left
, *right
;
30409 XRectangle
*upper
, *lower
;
30410 int intersection_p
= 0;
30412 /* Rearrange so that R1 is the left-most rectangle. */
30414 left
= r1
, right
= r2
;
30416 left
= r2
, right
= r1
;
30418 /* X0 of the intersection is right.x0, if this is inside R1,
30419 otherwise there is no intersection. */
30420 if (right
->x
<= left
->x
+ left
->width
)
30422 result
->x
= right
->x
;
30424 /* The right end of the intersection is the minimum of
30425 the right ends of left and right. */
30426 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
30429 /* Same game for Y. */
30431 upper
= r1
, lower
= r2
;
30433 upper
= r2
, lower
= r1
;
30435 /* The upper end of the intersection is lower.y0, if this is inside
30436 of upper. Otherwise, there is no intersection. */
30437 if (lower
->y
<= upper
->y
+ upper
->height
)
30439 result
->y
= lower
->y
;
30441 /* The lower end of the intersection is the minimum of the lower
30442 ends of upper and lower. */
30443 result
->height
= (min (lower
->y
+ lower
->height
,
30444 upper
->y
+ upper
->height
)
30446 intersection_p
= 1;
30450 return intersection_p
;
30453 #endif /* HAVE_WINDOW_SYSTEM */
30456 /***********************************************************************
30458 ***********************************************************************/
30461 syms_of_xdisp (void)
30463 Vwith_echo_area_save_vector
= Qnil
;
30464 staticpro (&Vwith_echo_area_save_vector
);
30466 Vmessage_stack
= Qnil
;
30467 staticpro (&Vmessage_stack
);
30469 /* Non-nil means don't actually do any redisplay. */
30470 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
30472 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
30474 message_dolog_marker1
= Fmake_marker ();
30475 staticpro (&message_dolog_marker1
);
30476 message_dolog_marker2
= Fmake_marker ();
30477 staticpro (&message_dolog_marker2
);
30478 message_dolog_marker3
= Fmake_marker ();
30479 staticpro (&message_dolog_marker3
);
30482 defsubr (&Sdump_frame_glyph_matrix
);
30483 defsubr (&Sdump_glyph_matrix
);
30484 defsubr (&Sdump_glyph_row
);
30485 defsubr (&Sdump_tool_bar_row
);
30486 defsubr (&Strace_redisplay
);
30487 defsubr (&Strace_to_stderr
);
30489 #ifdef HAVE_WINDOW_SYSTEM
30490 defsubr (&Stool_bar_height
);
30491 defsubr (&Slookup_image_map
);
30493 defsubr (&Sline_pixel_height
);
30494 defsubr (&Sformat_mode_line
);
30495 defsubr (&Sinvisible_p
);
30496 defsubr (&Scurrent_bidi_paragraph_direction
);
30497 defsubr (&Swindow_text_pixel_size
);
30498 defsubr (&Smove_point_visually
);
30499 defsubr (&Sbidi_find_overridden_directionality
);
30501 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
30502 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
30503 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
30504 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
30505 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
30506 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
30507 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
30508 DEFSYM (Qeval
, "eval");
30509 DEFSYM (QCdata
, ":data");
30511 /* Names of text properties relevant for redisplay. */
30512 DEFSYM (Qdisplay
, "display");
30513 DEFSYM (Qspace_width
, "space-width");
30514 DEFSYM (Qraise
, "raise");
30515 DEFSYM (Qslice
, "slice");
30516 DEFSYM (Qspace
, "space");
30517 DEFSYM (Qmargin
, "margin");
30518 DEFSYM (Qpointer
, "pointer");
30519 DEFSYM (Qleft_margin
, "left-margin");
30520 DEFSYM (Qright_margin
, "right-margin");
30521 DEFSYM (Qcenter
, "center");
30522 DEFSYM (Qline_height
, "line-height");
30523 DEFSYM (QCalign_to
, ":align-to");
30524 DEFSYM (QCrelative_width
, ":relative-width");
30525 DEFSYM (QCrelative_height
, ":relative-height");
30526 DEFSYM (QCeval
, ":eval");
30527 DEFSYM (QCpropertize
, ":propertize");
30528 DEFSYM (QCfile
, ":file");
30529 DEFSYM (Qfontified
, "fontified");
30530 DEFSYM (Qfontification_functions
, "fontification-functions");
30532 /* Name of the face used to highlight trailing whitespace. */
30533 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
30535 /* Name and number of the face used to highlight escape glyphs. */
30536 DEFSYM (Qescape_glyph
, "escape-glyph");
30538 /* Name and number of the face used to highlight non-breaking spaces. */
30539 DEFSYM (Qnobreak_space
, "nobreak-space");
30541 /* The symbol 'image' which is the car of the lists used to represent
30542 images in Lisp. Also a tool bar style. */
30543 DEFSYM (Qimage
, "image");
30545 /* Tool bar styles. */
30546 DEFSYM (Qtext
, "text");
30547 DEFSYM (Qboth
, "both");
30548 DEFSYM (Qboth_horiz
, "both-horiz");
30549 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
30551 /* The image map types. */
30552 DEFSYM (QCmap
, ":map");
30553 DEFSYM (QCpointer
, ":pointer");
30554 DEFSYM (Qrect
, "rect");
30555 DEFSYM (Qcircle
, "circle");
30556 DEFSYM (Qpoly
, "poly");
30558 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
30559 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
30560 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
30562 DEFSYM (Qgrow_only
, "grow-only");
30563 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
30564 DEFSYM (Qposition
, "position");
30565 DEFSYM (Qbuffer_position
, "buffer-position");
30566 DEFSYM (Qobject
, "object");
30568 /* Cursor shapes. */
30569 DEFSYM (Qbar
, "bar");
30570 DEFSYM (Qhbar
, "hbar");
30571 DEFSYM (Qbox
, "box");
30572 DEFSYM (Qhollow
, "hollow");
30574 /* Pointer shapes. */
30575 DEFSYM (Qhand
, "hand");
30576 DEFSYM (Qarrow
, "arrow");
30579 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
30581 list_of_error
= list1 (list2 (intern_c_string ("error"),
30582 intern_c_string ("void-variable")));
30583 staticpro (&list_of_error
);
30585 /* Values of those variables at last redisplay are stored as
30586 properties on 'overlay-arrow-position' symbol. However, if
30587 Voverlay_arrow_position is a marker, last-arrow-position is its
30588 numerical position. */
30589 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
30590 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
30592 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
30593 properties on a symbol in overlay-arrow-variable-list. */
30594 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
30595 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
30597 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
30598 staticpro (&echo_buffer
[0]);
30599 staticpro (&echo_buffer
[1]);
30601 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
30602 staticpro (&echo_area_buffer
[0]);
30603 staticpro (&echo_area_buffer
[1]);
30605 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
30606 staticpro (&Vmessages_buffer_name
);
30608 mode_line_proptrans_alist
= Qnil
;
30609 staticpro (&mode_line_proptrans_alist
);
30610 mode_line_string_list
= Qnil
;
30611 staticpro (&mode_line_string_list
);
30612 mode_line_string_face
= Qnil
;
30613 staticpro (&mode_line_string_face
);
30614 mode_line_string_face_prop
= Qnil
;
30615 staticpro (&mode_line_string_face_prop
);
30616 Vmode_line_unwind_vector
= Qnil
;
30617 staticpro (&Vmode_line_unwind_vector
);
30619 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
30621 help_echo_string
= Qnil
;
30622 staticpro (&help_echo_string
);
30623 help_echo_object
= Qnil
;
30624 staticpro (&help_echo_object
);
30625 help_echo_window
= Qnil
;
30626 staticpro (&help_echo_window
);
30627 previous_help_echo_string
= Qnil
;
30628 staticpro (&previous_help_echo_string
);
30629 help_echo_pos
= -1;
30631 DEFSYM (Qright_to_left
, "right-to-left");
30632 DEFSYM (Qleft_to_right
, "left-to-right");
30633 defsubr (&Sbidi_resolved_levels
);
30635 #ifdef HAVE_WINDOW_SYSTEM
30636 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
30637 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
30638 For example, if a block cursor is over a tab, it will be drawn as
30639 wide as that tab on the display. */);
30640 x_stretch_cursor_p
= 0;
30643 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
30644 doc
: /* Non-nil means highlight trailing whitespace.
30645 The face used for trailing whitespace is `trailing-whitespace'. */);
30646 Vshow_trailing_whitespace
= Qnil
;
30648 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
30649 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
30650 If the value is t, Emacs highlights non-ASCII chars which have the
30651 same appearance as an ASCII space or hyphen, using the `nobreak-space'
30652 or `escape-glyph' face respectively.
30654 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
30655 U+2011 (non-breaking hyphen) are affected.
30657 Any other non-nil value means to display these characters as a escape
30658 glyph followed by an ordinary space or hyphen.
30660 A value of nil means no special handling of these characters. */);
30661 Vnobreak_char_display
= Qt
;
30663 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
30664 doc
: /* The pointer shape to show in void text areas.
30665 A value of nil means to show the text pointer. Other options are
30666 `arrow', `text', `hand', `vdrag', `hdrag', `nhdrag', `modeline', and
30668 Vvoid_text_area_pointer
= Qarrow
;
30670 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
30671 doc
: /* Non-nil means don't actually do any redisplay.
30672 This is used for internal purposes. */);
30673 Vinhibit_redisplay
= Qnil
;
30675 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
30676 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
30677 Vglobal_mode_string
= Qnil
;
30679 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
30680 doc
: /* Marker for where to display an arrow on top of the buffer text.
30681 This must be the beginning of a line in order to work.
30682 See also `overlay-arrow-string'. */);
30683 Voverlay_arrow_position
= Qnil
;
30685 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
30686 doc
: /* String to display as an arrow in non-window frames.
30687 See also `overlay-arrow-position'. */);
30688 Voverlay_arrow_string
= build_pure_c_string ("=>");
30690 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
30691 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
30692 The symbols on this list are examined during redisplay to determine
30693 where to display overlay arrows. */);
30694 Voverlay_arrow_variable_list
30695 = list1 (intern_c_string ("overlay-arrow-position"));
30697 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
30698 doc
: /* The number of lines to try scrolling a window by when point moves out.
30699 If that fails to bring point back on frame, point is centered instead.
30700 If this is zero, point is always centered after it moves off frame.
30701 If you want scrolling to always be a line at a time, you should set
30702 `scroll-conservatively' to a large value rather than set this to 1. */);
30704 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
30705 doc
: /* Scroll up to this many lines, to bring point back on screen.
30706 If point moves off-screen, redisplay will scroll by up to
30707 `scroll-conservatively' lines in order to bring point just barely
30708 onto the screen again. If that cannot be done, then redisplay
30709 recenters point as usual.
30711 If the value is greater than 100, redisplay will never recenter point,
30712 but will always scroll just enough text to bring point into view, even
30713 if you move far away.
30715 A value of zero means always recenter point if it moves off screen. */);
30716 scroll_conservatively
= 0;
30718 DEFVAR_INT ("scroll-margin", scroll_margin
,
30719 doc
: /* Number of lines of margin at the top and bottom of a window.
30720 Recenter the window whenever point gets within this many lines
30721 of the top or bottom of the window. */);
30724 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
30725 doc
: /* Pixels per inch value for non-window system displays.
30726 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
30727 Vdisplay_pixels_per_inch
= make_float (72.0);
30730 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
30733 DEFVAR_LISP ("truncate-partial-width-windows",
30734 Vtruncate_partial_width_windows
,
30735 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
30736 For an integer value, truncate lines in each window narrower than the
30737 full frame width, provided the window width is less than that integer;
30738 otherwise, respect the value of `truncate-lines'.
30740 For any other non-nil value, truncate lines in all windows that do
30741 not span the full frame width.
30743 A value of nil means to respect the value of `truncate-lines'.
30745 If `word-wrap' is enabled, you might want to reduce this. */);
30746 Vtruncate_partial_width_windows
= make_number (50);
30748 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
30749 doc
: /* Maximum buffer size for which line number should be displayed.
30750 If the buffer is bigger than this, the line number does not appear
30751 in the mode line. A value of nil means no limit. */);
30752 Vline_number_display_limit
= Qnil
;
30754 DEFVAR_INT ("line-number-display-limit-width",
30755 line_number_display_limit_width
,
30756 doc
: /* Maximum line width (in characters) for line number display.
30757 If the average length of the lines near point is bigger than this, then the
30758 line number may be omitted from the mode line. */);
30759 line_number_display_limit_width
= 200;
30761 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
30762 doc
: /* Non-nil means highlight region even in nonselected windows. */);
30763 highlight_nonselected_windows
= 0;
30765 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
30766 doc
: /* Non-nil if more than one frame is visible on this display.
30767 Minibuffer-only frames don't count, but iconified frames do.
30768 This variable is not guaranteed to be accurate except while processing
30769 `frame-title-format' and `icon-title-format'. */);
30771 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
30772 doc
: /* Template for displaying the title bar of visible frames.
30773 \(Assuming the window manager supports this feature.)
30775 This variable has the same structure as `mode-line-format', except that
30776 the %c and %l constructs are ignored. It is used only on frames for
30777 which no explicit name has been set \(see `modify-frame-parameters'). */);
30779 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
30780 doc
: /* Template for displaying the title bar of an iconified frame.
30781 \(Assuming the window manager supports this feature.)
30782 This variable has the same structure as `mode-line-format' (which see),
30783 and is used only on frames for which no explicit name has been set
30784 \(see `modify-frame-parameters'). */);
30786 = Vframe_title_format
30787 = listn (CONSTYPE_PURE
, 3,
30788 intern_c_string ("multiple-frames"),
30789 build_pure_c_string ("%b"),
30790 listn (CONSTYPE_PURE
, 4,
30791 empty_unibyte_string
,
30792 intern_c_string ("invocation-name"),
30793 build_pure_c_string ("@"),
30794 intern_c_string ("system-name")));
30796 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
30797 doc
: /* Maximum number of lines to keep in the message log buffer.
30798 If nil, disable message logging. If t, log messages but don't truncate
30799 the buffer when it becomes large. */);
30800 Vmessage_log_max
= make_number (1000);
30802 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
30803 doc
: /* Functions called before redisplay, if window sizes have changed.
30804 The value should be a list of functions that take one argument.
30805 Just before redisplay, for each frame, if any of its windows have changed
30806 size since the last redisplay, or have been split or deleted,
30807 all the functions in the list are called, with the frame as argument. */);
30808 Vwindow_size_change_functions
= Qnil
;
30810 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
30811 doc
: /* List of functions to call before redisplaying a window with scrolling.
30812 Each function is called with two arguments, the window and its new
30813 display-start position.
30814 These functions are called whenever the `window-start' marker is modified,
30815 either to point into another buffer (e.g. via `set-window-buffer') or another
30816 place in the same buffer.
30817 Note that the value of `window-end' is not valid when these functions are
30820 Warning: Do not use this feature to alter the way the window
30821 is scrolled. It is not designed for that, and such use probably won't
30823 Vwindow_scroll_functions
= Qnil
;
30825 DEFVAR_LISP ("window-text-change-functions",
30826 Vwindow_text_change_functions
,
30827 doc
: /* Functions to call in redisplay when text in the window might change. */);
30828 Vwindow_text_change_functions
= Qnil
;
30830 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
30831 doc
: /* Functions called when redisplay of a window reaches the end trigger.
30832 Each function is called with two arguments, the window and the end trigger value.
30833 See `set-window-redisplay-end-trigger'. */);
30834 Vredisplay_end_trigger_functions
= Qnil
;
30836 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
30837 doc
: /* Non-nil means autoselect window with mouse pointer.
30838 If nil, do not autoselect windows.
30839 A positive number means delay autoselection by that many seconds: a
30840 window is autoselected only after the mouse has remained in that
30841 window for the duration of the delay.
30842 A negative number has a similar effect, but causes windows to be
30843 autoselected only after the mouse has stopped moving. \(Because of
30844 the way Emacs compares mouse events, you will occasionally wait twice
30845 that time before the window gets selected.\)
30846 Any other value means to autoselect window instantaneously when the
30847 mouse pointer enters it.
30849 Autoselection selects the minibuffer only if it is active, and never
30850 unselects the minibuffer if it is active.
30852 When customizing this variable make sure that the actual value of
30853 `focus-follows-mouse' matches the behavior of your window manager. */);
30854 Vmouse_autoselect_window
= Qnil
;
30856 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
30857 doc
: /* Non-nil means automatically resize tool-bars.
30858 This dynamically changes the tool-bar's height to the minimum height
30859 that is needed to make all tool-bar items visible.
30860 If value is `grow-only', the tool-bar's height is only increased
30861 automatically; to decrease the tool-bar height, use \\[recenter]. */);
30862 Vauto_resize_tool_bars
= Qt
;
30864 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
30865 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
30866 auto_raise_tool_bar_buttons_p
= 1;
30868 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
30869 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
30870 make_cursor_line_fully_visible_p
= 1;
30872 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
30873 doc
: /* Border below tool-bar in pixels.
30874 If an integer, use it as the height of the border.
30875 If it is one of `internal-border-width' or `border-width', use the
30876 value of the corresponding frame parameter.
30877 Otherwise, no border is added below the tool-bar. */);
30878 Vtool_bar_border
= Qinternal_border_width
;
30880 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
30881 doc
: /* Margin around tool-bar buttons in pixels.
30882 If an integer, use that for both horizontal and vertical margins.
30883 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
30884 HORZ specifying the horizontal margin, and VERT specifying the
30885 vertical margin. */);
30886 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
30888 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
30889 doc
: /* Relief thickness of tool-bar buttons. */);
30890 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
30892 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
30893 doc
: /* Tool bar style to use.
30895 image - show images only
30896 text - show text only
30897 both - show both, text below image
30898 both-horiz - show text to the right of the image
30899 text-image-horiz - show text to the left of the image
30900 any other - use system default or image if no system default.
30902 This variable only affects the GTK+ toolkit version of Emacs. */);
30903 Vtool_bar_style
= Qnil
;
30905 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
30906 doc
: /* Maximum number of characters a label can have to be shown.
30907 The tool bar style must also show labels for this to have any effect, see
30908 `tool-bar-style'. */);
30909 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
30911 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
30912 doc
: /* List of functions to call to fontify regions of text.
30913 Each function is called with one argument POS. Functions must
30914 fontify a region starting at POS in the current buffer, and give
30915 fontified regions the property `fontified'. */);
30916 Vfontification_functions
= Qnil
;
30917 Fmake_variable_buffer_local (Qfontification_functions
);
30919 DEFVAR_BOOL ("unibyte-display-via-language-environment",
30920 unibyte_display_via_language_environment
,
30921 doc
: /* Non-nil means display unibyte text according to language environment.
30922 Specifically, this means that raw bytes in the range 160-255 decimal
30923 are displayed by converting them to the equivalent multibyte characters
30924 according to the current language environment. As a result, they are
30925 displayed according to the current fontset.
30927 Note that this variable affects only how these bytes are displayed,
30928 but does not change the fact they are interpreted as raw bytes. */);
30929 unibyte_display_via_language_environment
= 0;
30931 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
30932 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
30933 If a float, it specifies a fraction of the mini-window frame's height.
30934 If an integer, it specifies a number of lines. */);
30935 Vmax_mini_window_height
= make_float (0.25);
30937 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
30938 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
30939 A value of nil means don't automatically resize mini-windows.
30940 A value of t means resize them to fit the text displayed in them.
30941 A value of `grow-only', the default, means let mini-windows grow only;
30942 they return to their normal size when the minibuffer is closed, or the
30943 echo area becomes empty. */);
30944 Vresize_mini_windows
= Qgrow_only
;
30946 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
30947 doc
: /* Alist specifying how to blink the cursor off.
30948 Each element has the form (ON-STATE . OFF-STATE). Whenever the
30949 `cursor-type' frame-parameter or variable equals ON-STATE,
30950 comparing using `equal', Emacs uses OFF-STATE to specify
30951 how to blink it off. ON-STATE and OFF-STATE are values for
30952 the `cursor-type' frame parameter.
30954 If a frame's ON-STATE has no entry in this list,
30955 the frame's other specifications determine how to blink the cursor off. */);
30956 Vblink_cursor_alist
= Qnil
;
30958 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
30959 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
30960 If non-nil, windows are automatically scrolled horizontally to make
30961 point visible. */);
30962 automatic_hscrolling_p
= 1;
30963 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
30965 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
30966 doc
: /* How many columns away from the window edge point is allowed to get
30967 before automatic hscrolling will horizontally scroll the window. */);
30968 hscroll_margin
= 5;
30970 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
30971 doc
: /* How many columns to scroll the window when point gets too close to the edge.
30972 When point is less than `hscroll-margin' columns from the window
30973 edge, automatic hscrolling will scroll the window by the amount of columns
30974 determined by this variable. If its value is a positive integer, scroll that
30975 many columns. If it's a positive floating-point number, it specifies the
30976 fraction of the window's width to scroll. If it's nil or zero, point will be
30977 centered horizontally after the scroll. Any other value, including negative
30978 numbers, are treated as if the value were zero.
30980 Automatic hscrolling always moves point outside the scroll margin, so if
30981 point was more than scroll step columns inside the margin, the window will
30982 scroll more than the value given by the scroll step.
30984 Note that the lower bound for automatic hscrolling specified by `scroll-left'
30985 and `scroll-right' overrides this variable's effect. */);
30986 Vhscroll_step
= make_number (0);
30988 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
30989 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
30990 Bind this around calls to `message' to let it take effect. */);
30991 message_truncate_lines
= 0;
30993 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
30994 doc
: /* Normal hook run to update the menu bar definitions.
30995 Redisplay runs this hook before it redisplays the menu bar.
30996 This is used to update menus such as Buffers, whose contents depend on
30998 Vmenu_bar_update_hook
= Qnil
;
31000 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
31001 doc
: /* Frame for which we are updating a menu.
31002 The enable predicate for a menu binding should check this variable. */);
31003 Vmenu_updating_frame
= Qnil
;
31005 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
31006 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
31007 inhibit_menubar_update
= 0;
31009 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
31010 doc
: /* Prefix prepended to all continuation lines at display time.
31011 The value may be a string, an image, or a stretch-glyph; it is
31012 interpreted in the same way as the value of a `display' text property.
31014 This variable is overridden by any `wrap-prefix' text or overlay
31017 To add a prefix to non-continuation lines, use `line-prefix'. */);
31018 Vwrap_prefix
= Qnil
;
31019 DEFSYM (Qwrap_prefix
, "wrap-prefix");
31020 Fmake_variable_buffer_local (Qwrap_prefix
);
31022 DEFVAR_LISP ("line-prefix", Vline_prefix
,
31023 doc
: /* Prefix prepended to all non-continuation lines at display time.
31024 The value may be a string, an image, or a stretch-glyph; it is
31025 interpreted in the same way as the value of a `display' text property.
31027 This variable is overridden by any `line-prefix' text or overlay
31030 To add a prefix to continuation lines, use `wrap-prefix'. */);
31031 Vline_prefix
= Qnil
;
31032 DEFSYM (Qline_prefix
, "line-prefix");
31033 Fmake_variable_buffer_local (Qline_prefix
);
31035 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
31036 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
31037 inhibit_eval_during_redisplay
= 0;
31039 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
31040 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
31041 inhibit_free_realized_faces
= 0;
31043 DEFVAR_BOOL ("inhibit-bidi-mirroring", inhibit_bidi_mirroring
,
31044 doc
: /* Non-nil means don't mirror characters even when bidi context requires that.
31045 Intended for use during debugging and for testing bidi display;
31046 see biditest.el in the test suite. */);
31047 inhibit_bidi_mirroring
= 0;
31050 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
31051 doc
: /* Inhibit try_window_id display optimization. */);
31052 inhibit_try_window_id
= 0;
31054 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
31055 doc
: /* Inhibit try_window_reusing display optimization. */);
31056 inhibit_try_window_reusing
= 0;
31058 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
31059 doc
: /* Inhibit try_cursor_movement display optimization. */);
31060 inhibit_try_cursor_movement
= 0;
31061 #endif /* GLYPH_DEBUG */
31063 DEFVAR_INT ("overline-margin", overline_margin
,
31064 doc
: /* Space between overline and text, in pixels.
31065 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
31066 margin to the character height. */);
31067 overline_margin
= 2;
31069 DEFVAR_INT ("underline-minimum-offset",
31070 underline_minimum_offset
,
31071 doc
: /* Minimum distance between baseline and underline.
31072 This can improve legibility of underlined text at small font sizes,
31073 particularly when using variable `x-use-underline-position-properties'
31074 with fonts that specify an UNDERLINE_POSITION relatively close to the
31075 baseline. The default value is 1. */);
31076 underline_minimum_offset
= 1;
31078 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
31079 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
31080 This feature only works when on a window system that can change
31081 cursor shapes. */);
31082 display_hourglass_p
= 1;
31084 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
31085 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
31086 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
31088 #ifdef HAVE_WINDOW_SYSTEM
31089 hourglass_atimer
= NULL
;
31090 hourglass_shown_p
= 0;
31091 #endif /* HAVE_WINDOW_SYSTEM */
31093 /* Name of the face used to display glyphless characters. */
31094 DEFSYM (Qglyphless_char
, "glyphless-char");
31096 /* Method symbols for Vglyphless_char_display. */
31097 DEFSYM (Qhex_code
, "hex-code");
31098 DEFSYM (Qempty_box
, "empty-box");
31099 DEFSYM (Qthin_space
, "thin-space");
31100 DEFSYM (Qzero_width
, "zero-width");
31102 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
31103 doc
: /* Function run just before redisplay.
31104 It is called with one argument, which is the set of windows that are to
31105 be redisplayed. This set can be nil (meaning, only the selected window),
31106 or t (meaning all windows). */);
31107 Vpre_redisplay_function
= intern ("ignore");
31109 /* Symbol for the purpose of Vglyphless_char_display. */
31110 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
31111 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
31113 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
31114 doc
: /* Char-table defining glyphless characters.
31115 Each element, if non-nil, should be one of the following:
31116 an ASCII acronym string: display this string in a box
31117 `hex-code': display the hexadecimal code of a character in a box
31118 `empty-box': display as an empty box
31119 `thin-space': display as 1-pixel width space
31120 `zero-width': don't display
31121 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
31122 display method for graphical terminals and text terminals respectively.
31123 GRAPHICAL and TEXT should each have one of the values listed above.
31125 The char-table has one extra slot to control the display of a character for
31126 which no font is found. This slot only takes effect on graphical terminals.
31127 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
31128 `thin-space'. The default is `empty-box'.
31130 If a character has a non-nil entry in an active display table, the
31131 display table takes effect; in this case, Emacs does not consult
31132 `glyphless-char-display' at all. */);
31133 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
31134 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
31137 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
31138 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
31139 Vdebug_on_message
= Qnil
;
31141 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
31143 Vredisplay__all_windows_cause
31144 = Fmake_vector (make_number (100), make_number (0));
31146 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
31148 Vredisplay__mode_lines_cause
31149 = Fmake_vector (make_number (100), make_number (0));
31153 /* Initialize this module when Emacs starts. */
31158 CHARPOS (this_line_start_pos
) = 0;
31160 if (!noninteractive
)
31162 struct window
*m
= XWINDOW (minibuf_window
);
31163 Lisp_Object frame
= m
->frame
;
31164 struct frame
*f
= XFRAME (frame
);
31165 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
31166 struct window
*r
= XWINDOW (root
);
31169 echo_area_window
= minibuf_window
;
31171 r
->top_line
= FRAME_TOP_MARGIN (f
);
31172 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
31173 r
->total_cols
= FRAME_COLS (f
);
31174 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31175 r
->total_lines
= FRAME_TOTAL_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
31176 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
31178 m
->top_line
= FRAME_TOTAL_LINES (f
) - 1;
31179 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
31180 m
->total_cols
= FRAME_COLS (f
);
31181 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
31182 m
->total_lines
= 1;
31183 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
31185 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
31186 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
31187 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
31189 /* The default ellipsis glyphs `...'. */
31190 for (i
= 0; i
< 3; ++i
)
31191 default_invis_vector
[i
] = make_number ('.');
31195 /* Allocate the buffer for frame titles.
31196 Also used for `format-mode-line'. */
31198 mode_line_noprop_buf
= xmalloc (size
);
31199 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
31200 mode_line_noprop_ptr
= mode_line_noprop_buf
;
31201 mode_line_target
= MODE_LINE_DISPLAY
;
31204 help_echo_showing_p
= 0;
31207 #ifdef HAVE_WINDOW_SYSTEM
31209 /* Platform-independent portion of hourglass implementation. */
31211 /* Timer function of hourglass_atimer. */
31214 show_hourglass (struct atimer
*timer
)
31216 /* The timer implementation will cancel this timer automatically
31217 after this function has run. Set hourglass_atimer to null
31218 so that we know the timer doesn't have to be canceled. */
31219 hourglass_atimer
= NULL
;
31221 if (!hourglass_shown_p
)
31223 Lisp_Object tail
, frame
;
31227 FOR_EACH_FRAME (tail
, frame
)
31229 struct frame
*f
= XFRAME (frame
);
31231 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31232 && FRAME_RIF (f
)->show_hourglass
)
31233 FRAME_RIF (f
)->show_hourglass (f
);
31236 hourglass_shown_p
= 1;
31241 /* Cancel a currently active hourglass timer, and start a new one. */
31244 start_hourglass (void)
31246 struct timespec delay
;
31248 cancel_hourglass ();
31250 if (INTEGERP (Vhourglass_delay
)
31251 && XINT (Vhourglass_delay
) > 0)
31252 delay
= make_timespec (min (XINT (Vhourglass_delay
),
31253 TYPE_MAXIMUM (time_t)),
31255 else if (FLOATP (Vhourglass_delay
)
31256 && XFLOAT_DATA (Vhourglass_delay
) > 0)
31257 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
31259 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
31261 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
31262 show_hourglass
, NULL
);
31265 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
31269 cancel_hourglass (void)
31271 if (hourglass_atimer
)
31273 cancel_atimer (hourglass_atimer
);
31274 hourglass_atimer
= NULL
;
31277 if (hourglass_shown_p
)
31279 Lisp_Object tail
, frame
;
31283 FOR_EACH_FRAME (tail
, frame
)
31285 struct frame
*f
= XFRAME (frame
);
31287 if (FRAME_LIVE_P (f
) && FRAME_WINDOW_P (f
)
31288 && FRAME_RIF (f
)->hide_hourglass
)
31289 FRAME_RIF (f
)->hide_hourglass (f
);
31291 /* No cursors on non GUI frames - restore to stock arrow cursor. */
31292 else if (!FRAME_W32_P (f
))
31293 w32_arrow_cursor ();
31297 hourglass_shown_p
= 0;
31302 #endif /* HAVE_WINDOW_SYSTEM */