1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2014 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.
105 This function performs the full redisplay of a single window
106 assuming that its fonts were not changed and that the cursor
107 will not end up in the scroll margins. (Loading fonts requires
108 re-adjustment of dimensions of glyph matrices, which makes this
109 method impossible to use.)
111 These optimizations are tried in sequence (some can be skipped if
112 it is known that they are not applicable). If none of the
113 optimizations were successful, redisplay calls redisplay_windows,
114 which performs a full redisplay of all windows.
118 Desired matrices are always built per Emacs window. The function
119 `display_line' is the central function to look at if you are
120 interested. It constructs one row in a desired matrix given an
121 iterator structure containing both a buffer position and a
122 description of the environment in which the text is to be
123 displayed. But this is too early, read on.
125 Characters and pixmaps displayed for a range of buffer text depend
126 on various settings of buffers and windows, on overlays and text
127 properties, on display tables, on selective display. The good news
128 is that all this hairy stuff is hidden behind a small set of
129 interface functions taking an iterator structure (struct it)
132 Iteration over things to be displayed is then simple. It is
133 started by initializing an iterator with a call to init_iterator,
134 passing it the buffer position where to start iteration. For
135 iteration over strings, pass -1 as the position to init_iterator,
136 and call reseat_to_string when the string is ready, to initialize
137 the iterator for that string. Thereafter, calls to
138 get_next_display_element fill the iterator structure with relevant
139 information about the next thing to display. Calls to
140 set_iterator_to_next move the iterator to the next thing.
142 Besides this, an iterator also contains information about the
143 display environment in which glyphs for display elements are to be
144 produced. It has fields for the width and height of the display,
145 the information whether long lines are truncated or continued, a
146 current X and Y position, and lots of other stuff you can better
149 Glyphs in a desired matrix are normally constructed in a loop
150 calling get_next_display_element and then PRODUCE_GLYPHS. The call
151 to PRODUCE_GLYPHS will fill the iterator structure with pixel
152 information about the element being displayed and at the same time
153 produce glyphs for it. If the display element fits on the line
154 being displayed, set_iterator_to_next is called next, otherwise the
155 glyphs produced are discarded. The function display_line is the
156 workhorse of filling glyph rows in the desired matrix with glyphs.
157 In addition to producing glyphs, it also handles line truncation
158 and continuation, word wrap, and cursor positioning (for the
159 latter, see also set_cursor_from_row).
163 That just couldn't be all, could it? What about terminal types not
164 supporting operations on sub-windows of the screen? To update the
165 display on such a terminal, window-based glyph matrices are not
166 well suited. To be able to reuse part of the display (scrolling
167 lines up and down), we must instead have a view of the whole
168 screen. This is what `frame matrices' are for. They are a trick.
170 Frames on terminals like above have a glyph pool. Windows on such
171 a frame sub-allocate their glyph memory from their frame's glyph
172 pool. The frame itself is given its own glyph matrices. By
173 coincidence---or maybe something else---rows in window glyph
174 matrices are slices of corresponding rows in frame matrices. Thus
175 writing to window matrices implicitly updates a frame matrix which
176 provides us with the view of the whole screen that we originally
177 wanted to have without having to move many bytes around. To be
178 honest, there is a little bit more done, but not much more. If you
179 plan to extend that code, take a look at dispnew.c. The function
180 build_frame_matrix is a good starting point.
182 Bidirectional display.
184 Bidirectional display adds quite some hair to this already complex
185 design. The good news are that a large portion of that hairy stuff
186 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
187 reordering engine which is called by set_iterator_to_next and
188 returns the next character to display in the visual order. See
189 commentary on bidi.c for more details. As far as redisplay is
190 concerned, the effect of calling bidi_move_to_visually_next, the
191 main interface of the reordering engine, is that the iterator gets
192 magically placed on the buffer or string position that is to be
193 displayed next. In other words, a linear iteration through the
194 buffer/string is replaced with a non-linear one. All the rest of
195 the redisplay is oblivious to the bidi reordering.
197 Well, almost oblivious---there are still complications, most of
198 them due to the fact that buffer and string positions no longer
199 change monotonously with glyph indices in a glyph row. Moreover,
200 for continued lines, the buffer positions may not even be
201 monotonously changing with vertical positions. Also, accounting
202 for face changes, overlays, etc. becomes more complex because
203 non-linear iteration could potentially skip many positions with
204 changes, and then cross them again on the way back...
206 One other prominent effect of bidirectional display is that some
207 paragraphs of text need to be displayed starting at the right
208 margin of the window---the so-called right-to-left, or R2L
209 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
210 which have their reversed_p flag set. The bidi reordering engine
211 produces characters in such rows starting from the character which
212 should be the rightmost on display. PRODUCE_GLYPHS then reverses
213 the order, when it fills up the glyph row whose reversed_p flag is
214 set, by prepending each new glyph to what is already there, instead
215 of appending it. When the glyph row is complete, the function
216 extend_face_to_end_of_line fills the empty space to the left of the
217 leftmost character with special glyphs, which will display as,
218 well, empty. On text terminals, these special glyphs are simply
219 blank characters. On graphics terminals, there's a single stretch
220 glyph of a suitably computed width. Both the blanks and the
221 stretch glyph are given the face of the background of the line.
222 This way, the terminal-specific back-end can still draw the glyphs
223 left to right, even for R2L lines.
225 Bidirectional display and character compositions
227 Some scripts cannot be displayed by drawing each character
228 individually, because adjacent characters change each other's shape
229 on display. For example, Arabic and Indic scripts belong to this
232 Emacs display supports this by providing "character compositions",
233 most of which is implemented in composite.c. During the buffer
234 scan that delivers characters to PRODUCE_GLYPHS, if the next
235 character to be delivered is a composed character, the iteration
236 calls composition_reseat_it and next_element_from_composition. If
237 they succeed to compose the character with one or more of the
238 following characters, the whole sequence of characters that where
239 composed is recorded in the `struct composition_it' object that is
240 part of the buffer iterator. The composed sequence could produce
241 one or more font glyphs (called "grapheme clusters") on the screen.
242 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
243 in the direction corresponding to the current bidi scan direction
244 (recorded in the scan_dir member of the `struct bidi_it' object
245 that is part of the buffer iterator). In particular, if the bidi
246 iterator currently scans the buffer backwards, the grapheme
247 clusters are delivered back to front. This reorders the grapheme
248 clusters as appropriate for the current bidi context. Note that
249 this means that the grapheme clusters are always stored in the
250 LGSTRING object (see composite.c) in the logical order.
252 Moving an iterator in bidirectional text
253 without producing glyphs
255 Note one important detail mentioned above: that the bidi reordering
256 engine, driven by the iterator, produces characters in R2L rows
257 starting at the character that will be the rightmost on display.
258 As far as the iterator is concerned, the geometry of such rows is
259 still left to right, i.e. the iterator "thinks" the first character
260 is at the leftmost pixel position. The iterator does not know that
261 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
262 delivers. This is important when functions from the move_it_*
263 family are used to get to certain screen position or to match
264 screen coordinates with buffer coordinates: these functions use the
265 iterator geometry, which is left to right even in R2L paragraphs.
266 This works well with most callers of move_it_*, because they need
267 to get to a specific column, and columns are still numbered in the
268 reading order, i.e. the rightmost character in a R2L paragraph is
269 still column zero. But some callers do not get well with this; a
270 notable example is mouse clicks that need to find the character
271 that corresponds to certain pixel coordinates. See
272 buffer_posn_from_coords in dispnew.c for how this is handled. */
280 #include "keyboard.h"
283 #include "termchar.h"
284 #include "dispextern.h"
285 #include "character.h"
289 #include "commands.h"
293 #include "termhooks.h"
294 #include "termopts.h"
295 #include "intervals.h"
298 #include "region-cache.h"
301 #include "blockinput.h"
302 #ifdef HAVE_WINDOW_SYSTEM
304 #endif /* HAVE_WINDOW_SYSTEM */
306 #ifndef FRAME_X_OUTPUT
307 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
310 #define INFINITY 10000000
312 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
313 Lisp_Object Qwindow_scroll_functions
;
314 static Lisp_Object Qwindow_text_change_functions
;
315 static Lisp_Object Qredisplay_end_trigger_functions
;
316 Lisp_Object Qinhibit_point_motion_hooks
;
317 static Lisp_Object QCeval
, QCpropertize
;
318 Lisp_Object QCfile
, QCdata
;
319 static Lisp_Object Qfontified
;
320 static Lisp_Object Qgrow_only
;
321 static Lisp_Object Qinhibit_eval_during_redisplay
;
322 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
323 static Lisp_Object Qright_to_left
, Qleft_to_right
;
326 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
328 /* Pointer shapes. */
329 static Lisp_Object Qarrow
, Qhand
;
332 /* Holds the list (error). */
333 static Lisp_Object list_of_error
;
335 static Lisp_Object Qfontification_functions
;
337 static Lisp_Object Qwrap_prefix
;
338 static Lisp_Object Qline_prefix
;
339 static Lisp_Object Qredisplay_internal
;
341 /* Non-nil means don't actually do any redisplay. */
343 Lisp_Object Qinhibit_redisplay
;
345 /* Names of text properties relevant for redisplay. */
347 Lisp_Object Qdisplay
;
349 Lisp_Object Qspace
, QCalign_to
;
350 static Lisp_Object QCrelative_width
, QCrelative_height
;
351 Lisp_Object Qleft_margin
, Qright_margin
;
352 static Lisp_Object Qspace_width
, Qraise
;
353 static Lisp_Object Qslice
;
355 static Lisp_Object Qmargin
, Qpointer
;
356 static Lisp_Object Qline_height
;
358 #ifdef HAVE_WINDOW_SYSTEM
360 /* Test if overflow newline into fringe. Called with iterator IT
361 at or past right window margin, and with IT->current_x set. */
363 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
364 (!NILP (Voverflow_newline_into_fringe) \
365 && FRAME_WINDOW_P ((IT)->f) \
366 && ((IT)->bidi_it.paragraph_dir == R2L \
367 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
368 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
369 && (IT)->current_x == (IT)->last_visible_x)
371 #else /* !HAVE_WINDOW_SYSTEM */
372 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
373 #endif /* HAVE_WINDOW_SYSTEM */
375 /* Test if the display element loaded in IT, or the underlying buffer
376 or string character, is a space or a TAB character. This is used
377 to determine where word wrapping can occur. */
379 #define IT_DISPLAYING_WHITESPACE(it) \
380 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
381 || ((STRINGP (it->string) \
382 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
383 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
385 && (it->s[IT_BYTEPOS (*it)] == ' ' \
386 || it->s[IT_BYTEPOS (*it)] == '\t')) \
387 || (IT_BYTEPOS (*it) < ZV_BYTE \
388 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
389 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
391 /* Name of the face used to highlight trailing whitespace. */
393 static Lisp_Object Qtrailing_whitespace
;
395 /* Name and number of the face used to highlight escape glyphs. */
397 static Lisp_Object Qescape_glyph
;
399 /* Name and number of the face used to highlight non-breaking spaces. */
401 static Lisp_Object Qnobreak_space
;
403 /* The symbol `image' which is the car of the lists used to represent
404 images in Lisp. Also a tool bar style. */
408 /* The image map types. */
410 static Lisp_Object QCpointer
;
411 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
413 /* Tool bar styles */
414 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
416 /* Non-zero means print newline to stdout before next mini-buffer
419 bool noninteractive_need_newline
;
421 /* Non-zero means print newline to message log before next message. */
423 static bool message_log_need_newline
;
425 /* Three markers that message_dolog uses.
426 It could allocate them itself, but that causes trouble
427 in handling memory-full errors. */
428 static Lisp_Object message_dolog_marker1
;
429 static Lisp_Object message_dolog_marker2
;
430 static Lisp_Object message_dolog_marker3
;
432 /* The buffer position of the first character appearing entirely or
433 partially on the line of the selected window which contains the
434 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
435 redisplay optimization in redisplay_internal. */
437 static struct text_pos this_line_start_pos
;
439 /* Number of characters past the end of the line above, including the
440 terminating newline. */
442 static struct text_pos this_line_end_pos
;
444 /* The vertical positions and the height of this line. */
446 static int this_line_vpos
;
447 static int this_line_y
;
448 static int this_line_pixel_height
;
450 /* X position at which this display line starts. Usually zero;
451 negative if first character is partially visible. */
453 static int this_line_start_x
;
455 /* The smallest character position seen by move_it_* functions as they
456 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
457 hscrolled lines, see display_line. */
459 static struct text_pos this_line_min_pos
;
461 /* Buffer that this_line_.* variables are referring to. */
463 static struct buffer
*this_line_buffer
;
466 /* Values of those variables at last redisplay are stored as
467 properties on `overlay-arrow-position' symbol. However, if
468 Voverlay_arrow_position is a marker, last-arrow-position is its
469 numerical position. */
471 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
473 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
474 properties on a symbol in overlay-arrow-variable-list. */
476 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
478 Lisp_Object Qmenu_bar_update_hook
;
480 /* Nonzero if an overlay arrow has been displayed in this window. */
482 static bool overlay_arrow_seen
;
484 /* Vector containing glyphs for an ellipsis `...'. */
486 static Lisp_Object default_invis_vector
[3];
488 /* This is the window where the echo area message was displayed. It
489 is always a mini-buffer window, but it may not be the same window
490 currently active as a mini-buffer. */
492 Lisp_Object echo_area_window
;
494 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
495 pushes the current message and the value of
496 message_enable_multibyte on the stack, the function restore_message
497 pops the stack and displays MESSAGE again. */
499 static Lisp_Object Vmessage_stack
;
501 /* Nonzero means multibyte characters were enabled when the echo area
502 message was specified. */
504 static bool message_enable_multibyte
;
506 /* Nonzero if we should redraw the mode lines on the next redisplay.
507 If it has value REDISPLAY_SOME, then only redisplay the mode lines where
508 the `redisplay' bit has been set. Otherwise, redisplay all mode lines
509 (the number used is then only used to track down the cause for this
512 int update_mode_lines
;
514 /* Nonzero if window sizes or contents other than selected-window have changed
515 since last redisplay that finished.
516 If it has value REDISPLAY_SOME, then only redisplay the windows where
517 the `redisplay' bit has been set. Otherwise, redisplay all windows
518 (the number used is then only used to track down the cause for this
521 int windows_or_buffers_changed
;
523 /* Nonzero after display_mode_line if %l was used and it displayed a
526 static bool line_number_displayed
;
528 /* The name of the *Messages* buffer, a string. */
530 static Lisp_Object Vmessages_buffer_name
;
532 /* Current, index 0, and last displayed echo area message. Either
533 buffers from echo_buffers, or nil to indicate no message. */
535 Lisp_Object echo_area_buffer
[2];
537 /* The buffers referenced from echo_area_buffer. */
539 static Lisp_Object echo_buffer
[2];
541 /* A vector saved used in with_area_buffer to reduce consing. */
543 static Lisp_Object Vwith_echo_area_save_vector
;
545 /* Non-zero means display_echo_area should display the last echo area
546 message again. Set by redisplay_preserve_echo_area. */
548 static bool display_last_displayed_message_p
;
550 /* Nonzero if echo area is being used by print; zero if being used by
553 static bool message_buf_print
;
555 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
557 static Lisp_Object Qinhibit_menubar_update
;
558 static Lisp_Object Qmessage_truncate_lines
;
560 /* Set to 1 in clear_message to make redisplay_internal aware
561 of an emptied echo area. */
563 static bool message_cleared_p
;
565 /* A scratch glyph row with contents used for generating truncation
566 glyphs. Also used in direct_output_for_insert. */
568 #define MAX_SCRATCH_GLYPHS 100
569 static struct glyph_row scratch_glyph_row
;
570 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
572 /* Ascent and height of the last line processed by move_it_to. */
574 static int last_height
;
576 /* Non-zero if there's a help-echo in the echo area. */
578 bool help_echo_showing_p
;
580 /* The maximum distance to look ahead for text properties. Values
581 that are too small let us call compute_char_face and similar
582 functions too often which is expensive. Values that are too large
583 let us call compute_char_face and alike too often because we
584 might not be interested in text properties that far away. */
586 #define TEXT_PROP_DISTANCE_LIMIT 100
588 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
589 iterator state and later restore it. This is needed because the
590 bidi iterator on bidi.c keeps a stacked cache of its states, which
591 is really a singleton. When we use scratch iterator objects to
592 move around the buffer, we can cause the bidi cache to be pushed or
593 popped, and therefore we need to restore the cache state when we
594 return to the original iterator. */
595 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
598 bidi_unshelve_cache (CACHE, 1); \
600 CACHE = bidi_shelve_cache (); \
603 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
605 if (pITORIG != pITCOPY) \
606 *(pITORIG) = *(pITCOPY); \
607 bidi_unshelve_cache (CACHE, 0); \
611 /* Functions to mark elements as needing redisplay. */
612 enum { REDISPLAY_SOME
= 2}; /* Arbitrary choice. */
615 redisplay_other_windows (void)
617 if (!windows_or_buffers_changed
)
618 windows_or_buffers_changed
= REDISPLAY_SOME
;
622 wset_redisplay (struct window
*w
)
624 /* Beware: selected_window can be nil during early stages. */
625 if (!EQ (make_lisp_ptr (w
, Lisp_Vectorlike
), selected_window
))
626 redisplay_other_windows ();
631 fset_redisplay (struct frame
*f
)
633 redisplay_other_windows ();
638 bset_redisplay (struct buffer
*b
)
640 int count
= buffer_window_count (b
);
643 /* ... it's visible in other window than selected, */
644 if (count
> 1 || b
!= XBUFFER (XWINDOW (selected_window
)->contents
))
645 redisplay_other_windows ();
646 /* Even if we don't set windows_or_buffers_changed, do set `redisplay'
647 so that if we later set windows_or_buffers_changed, this buffer will
649 b
->text
->redisplay
= true;
654 bset_update_mode_line (struct buffer
*b
)
656 if (!update_mode_lines
)
657 update_mode_lines
= REDISPLAY_SOME
;
658 b
->text
->redisplay
= true;
663 /* Non-zero means print traces of redisplay if compiled with
664 GLYPH_DEBUG defined. */
666 bool trace_redisplay_p
;
668 #endif /* GLYPH_DEBUG */
670 #ifdef DEBUG_TRACE_MOVE
671 /* Non-zero means trace with TRACE_MOVE to stderr. */
674 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
676 #define TRACE_MOVE(x) (void) 0
679 static Lisp_Object Qauto_hscroll_mode
;
681 /* Buffer being redisplayed -- for redisplay_window_error. */
683 static struct buffer
*displayed_buffer
;
685 /* Value returned from text property handlers (see below). */
690 HANDLED_RECOMPUTE_PROPS
,
691 HANDLED_OVERLAY_STRING_CONSUMED
,
695 /* A description of text properties that redisplay is interested
700 /* The name of the property. */
703 /* A unique index for the property. */
706 /* A handler function called to set up iterator IT from the property
707 at IT's current position. Value is used to steer handle_stop. */
708 enum prop_handled (*handler
) (struct it
*it
);
711 static enum prop_handled
handle_face_prop (struct it
*);
712 static enum prop_handled
handle_invisible_prop (struct it
*);
713 static enum prop_handled
handle_display_prop (struct it
*);
714 static enum prop_handled
handle_composition_prop (struct it
*);
715 static enum prop_handled
handle_overlay_change (struct it
*);
716 static enum prop_handled
handle_fontified_prop (struct it
*);
718 /* Properties handled by iterators. */
720 static struct props it_props
[] =
722 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
723 /* Handle `face' before `display' because some sub-properties of
724 `display' need to know the face. */
725 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
726 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
727 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
728 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
732 /* Value is the position described by X. If X is a marker, value is
733 the marker_position of X. Otherwise, value is X. */
735 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
737 /* Enumeration returned by some move_it_.* functions internally. */
741 /* Not used. Undefined value. */
744 /* Move ended at the requested buffer position or ZV. */
745 MOVE_POS_MATCH_OR_ZV
,
747 /* Move ended at the requested X pixel position. */
750 /* Move within a line ended at the end of a line that must be
754 /* Move within a line ended at the end of a line that would
755 be displayed truncated. */
758 /* Move within a line ended at a line end. */
762 /* This counter is used to clear the face cache every once in a while
763 in redisplay_internal. It is incremented for each redisplay.
764 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
767 #define CLEAR_FACE_CACHE_COUNT 500
768 static int clear_face_cache_count
;
770 /* Similarly for the image cache. */
772 #ifdef HAVE_WINDOW_SYSTEM
773 #define CLEAR_IMAGE_CACHE_COUNT 101
774 static int clear_image_cache_count
;
776 /* Null glyph slice */
777 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
780 /* True while redisplay_internal is in progress. */
784 static Lisp_Object Qinhibit_free_realized_faces
;
785 static Lisp_Object Qmode_line_default_help_echo
;
787 /* If a string, XTread_socket generates an event to display that string.
788 (The display is done in read_char.) */
790 Lisp_Object help_echo_string
;
791 Lisp_Object help_echo_window
;
792 Lisp_Object help_echo_object
;
793 ptrdiff_t help_echo_pos
;
795 /* Temporary variable for XTread_socket. */
797 Lisp_Object previous_help_echo_string
;
799 /* Platform-independent portion of hourglass implementation. */
801 #ifdef HAVE_WINDOW_SYSTEM
803 /* Non-zero means an hourglass cursor is currently shown. */
804 bool hourglass_shown_p
;
806 /* If non-null, an asynchronous timer that, when it expires, displays
807 an hourglass cursor on all frames. */
808 struct atimer
*hourglass_atimer
;
810 #endif /* HAVE_WINDOW_SYSTEM */
812 /* Name of the face used to display glyphless characters. */
813 static Lisp_Object Qglyphless_char
;
815 /* Symbol for the purpose of Vglyphless_char_display. */
816 static Lisp_Object Qglyphless_char_display
;
818 /* Method symbols for Vglyphless_char_display. */
819 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
821 /* Default number of seconds to wait before displaying an hourglass
823 #define DEFAULT_HOURGLASS_DELAY 1
825 #ifdef HAVE_WINDOW_SYSTEM
827 /* Default pixel width of `thin-space' display method. */
828 #define THIN_SPACE_WIDTH 1
830 #endif /* HAVE_WINDOW_SYSTEM */
832 /* Function prototypes. */
834 static void setup_for_ellipsis (struct it
*, int);
835 static void set_iterator_to_next (struct it
*, int);
836 static void mark_window_display_accurate_1 (struct window
*, int);
837 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
838 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
839 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
840 static int cursor_row_p (struct glyph_row
*);
841 static int redisplay_mode_lines (Lisp_Object
, bool);
842 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
844 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
846 static void handle_line_prefix (struct it
*);
848 static void pint2str (char *, int, ptrdiff_t);
849 static void pint2hrstr (char *, int, ptrdiff_t);
850 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
852 static int text_outside_line_unchanged_p (struct window
*,
853 ptrdiff_t, ptrdiff_t);
854 static void store_mode_line_noprop_char (char);
855 static int store_mode_line_noprop (const char *, int, int);
856 static void handle_stop (struct it
*);
857 static void handle_stop_backwards (struct it
*, ptrdiff_t);
858 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
859 static void ensure_echo_area_buffers (void);
860 static void unwind_with_echo_area_buffer (Lisp_Object
);
861 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
862 static int with_echo_area_buffer (struct window
*, int,
863 int (*) (ptrdiff_t, Lisp_Object
),
864 ptrdiff_t, Lisp_Object
);
865 static void clear_garbaged_frames (void);
866 static int current_message_1 (ptrdiff_t, Lisp_Object
);
867 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
868 static void set_message (Lisp_Object
);
869 static int set_message_1 (ptrdiff_t, Lisp_Object
);
870 static int display_echo_area (struct window
*);
871 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
872 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
873 static void unwind_redisplay (void);
874 static int string_char_and_length (const unsigned char *, int *);
875 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
877 static int compute_window_start_on_continuation_line (struct window
*);
878 static void insert_left_trunc_glyphs (struct it
*);
879 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
881 static void extend_face_to_end_of_line (struct it
*);
882 static int append_space_for_newline (struct it
*, int);
883 static int cursor_row_fully_visible_p (struct window
*, int, int);
884 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
885 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
886 static int trailing_whitespace_p (ptrdiff_t);
887 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
888 static void push_it (struct it
*, struct text_pos
*);
889 static void iterate_out_of_display_property (struct it
*);
890 static void pop_it (struct it
*);
891 static void sync_frame_with_window_matrix_rows (struct window
*);
892 static void redisplay_internal (void);
893 static int echo_area_display (int);
894 static void redisplay_windows (Lisp_Object
);
895 static void redisplay_window (Lisp_Object
, bool);
896 static Lisp_Object
redisplay_window_error (Lisp_Object
);
897 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
898 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
899 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
900 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
902 static int update_menu_bar (struct frame
*, int, int);
903 static int try_window_reusing_current_matrix (struct window
*);
904 static int try_window_id (struct window
*);
905 static int display_line (struct it
*);
906 static int display_mode_lines (struct window
*);
907 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
908 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
909 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
910 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
911 static void display_menu_bar (struct window
*);
912 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
914 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
915 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
916 static void compute_line_metrics (struct it
*);
917 static void run_redisplay_end_trigger_hook (struct it
*);
918 static int get_overlay_strings (struct it
*, ptrdiff_t);
919 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
920 static void next_overlay_string (struct it
*);
921 static void reseat (struct it
*, struct text_pos
, int);
922 static void reseat_1 (struct it
*, struct text_pos
, int);
923 static void back_to_previous_visible_line_start (struct it
*);
924 static void reseat_at_next_visible_line_start (struct it
*, int);
925 static int next_element_from_ellipsis (struct it
*);
926 static int next_element_from_display_vector (struct it
*);
927 static int next_element_from_string (struct it
*);
928 static int next_element_from_c_string (struct it
*);
929 static int next_element_from_buffer (struct it
*);
930 static int next_element_from_composition (struct it
*);
931 static int next_element_from_image (struct it
*);
932 static int next_element_from_stretch (struct it
*);
933 static void load_overlay_strings (struct it
*, ptrdiff_t);
934 static int init_from_display_pos (struct it
*, struct window
*,
935 struct display_pos
*);
936 static void reseat_to_string (struct it
*, const char *,
937 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
938 static int get_next_display_element (struct it
*);
939 static enum move_it_result
940 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
941 enum move_operation_enum
);
942 static void get_visually_first_element (struct it
*);
943 static void init_to_row_start (struct it
*, struct window
*,
945 static int init_to_row_end (struct it
*, struct window
*,
947 static void back_to_previous_line_start (struct it
*);
948 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
949 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
950 Lisp_Object
, ptrdiff_t);
951 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
952 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
953 static ptrdiff_t number_of_chars (const char *, bool);
954 static void compute_stop_pos (struct it
*);
955 static void compute_string_pos (struct text_pos
*, struct text_pos
,
957 static int face_before_or_after_it_pos (struct it
*, int);
958 static ptrdiff_t next_overlay_change (ptrdiff_t);
959 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
960 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
961 static int handle_single_display_spec (struct it
*, Lisp_Object
,
962 Lisp_Object
, Lisp_Object
,
963 struct text_pos
*, ptrdiff_t, int, int);
964 static int underlying_face_id (struct it
*);
965 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
968 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
969 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
971 #ifdef HAVE_WINDOW_SYSTEM
973 static void x_consider_frame_title (Lisp_Object
);
974 static void update_tool_bar (struct frame
*, int);
975 static int redisplay_tool_bar (struct frame
*);
976 static void x_draw_bottom_divider (struct window
*w
);
977 static void notice_overwritten_cursor (struct window
*,
980 static void append_stretch_glyph (struct it
*, Lisp_Object
,
984 #endif /* HAVE_WINDOW_SYSTEM */
986 static void produce_special_glyphs (struct it
*, enum display_element_type
);
987 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
988 static bool coords_in_mouse_face_p (struct window
*, int, int);
992 /***********************************************************************
993 Window display dimensions
994 ***********************************************************************/
996 /* Return the bottom boundary y-position for text lines in window W.
997 This is the first y position at which a line cannot start.
998 It is relative to the top of the window.
1000 This is the height of W minus the height of a mode line, if any. */
1003 window_text_bottom_y (struct window
*w
)
1005 int height
= WINDOW_PIXEL_HEIGHT (w
);
1007 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
1009 if (WINDOW_WANTS_MODELINE_P (w
))
1010 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
1015 /* Return the pixel width of display area AREA of window W.
1016 ANY_AREA means return the total width of W, not including
1017 fringes to the left and right of the window. */
1020 window_box_width (struct window
*w
, enum glyph_row_area area
)
1022 int width
= w
->pixel_width
;
1024 if (!w
->pseudo_window_p
)
1026 width
-= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
1027 width
-= WINDOW_RIGHT_DIVIDER_WIDTH (w
);
1029 if (area
== TEXT_AREA
)
1030 width
-= (WINDOW_MARGINS_WIDTH (w
)
1031 + WINDOW_FRINGES_WIDTH (w
));
1032 else if (area
== LEFT_MARGIN_AREA
)
1033 width
= WINDOW_LEFT_MARGIN_WIDTH (w
);
1034 else if (area
== RIGHT_MARGIN_AREA
)
1035 width
= WINDOW_RIGHT_MARGIN_WIDTH (w
);
1038 /* With wide margins, fringes, etc. we might end up with a negative
1039 width, correct that here. */
1040 return max (0, width
);
1044 /* Return the pixel height of the display area of window W, not
1045 including mode lines of W, if any. */
1048 window_box_height (struct window
*w
)
1050 struct frame
*f
= XFRAME (w
->frame
);
1051 int height
= WINDOW_PIXEL_HEIGHT (w
);
1053 eassert (height
>= 0);
1055 height
-= WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
1057 /* Note: the code below that determines the mode-line/header-line
1058 height is essentially the same as that contained in the macro
1059 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1060 the appropriate glyph row has its `mode_line_p' flag set,
1061 and if it doesn't, uses estimate_mode_line_height instead. */
1063 if (WINDOW_WANTS_MODELINE_P (w
))
1065 struct glyph_row
*ml_row
1066 = (w
->current_matrix
&& w
->current_matrix
->rows
1067 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1069 if (ml_row
&& ml_row
->mode_line_p
)
1070 height
-= ml_row
->height
;
1072 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1075 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1077 struct glyph_row
*hl_row
1078 = (w
->current_matrix
&& w
->current_matrix
->rows
1079 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1081 if (hl_row
&& hl_row
->mode_line_p
)
1082 height
-= hl_row
->height
;
1084 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1087 /* With a very small font and a mode-line that's taller than
1088 default, we might end up with a negative height. */
1089 return max (0, height
);
1092 /* Return the window-relative coordinate of the left edge of display
1093 area AREA of window W. ANY_AREA means return the left edge of the
1094 whole window, to the right of the left fringe of W. */
1097 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1101 if (w
->pseudo_window_p
)
1104 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1106 if (area
== TEXT_AREA
)
1107 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1108 + window_box_width (w
, LEFT_MARGIN_AREA
));
1109 else if (area
== RIGHT_MARGIN_AREA
)
1110 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1111 + window_box_width (w
, LEFT_MARGIN_AREA
)
1112 + window_box_width (w
, TEXT_AREA
)
1113 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1115 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1116 else if (area
== LEFT_MARGIN_AREA
1117 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1118 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1120 /* Don't return more than the window's pixel width. */
1121 return min (x
, w
->pixel_width
);
1125 /* Return the window-relative coordinate of the right edge of display
1126 area AREA of window W. ANY_AREA means return the right edge of the
1127 whole window, to the left of the right fringe of W. */
1130 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1132 /* Don't return more than the window's pixel width. */
1133 return min (window_box_left_offset (w
, area
) + window_box_width (w
, area
),
1137 /* Return the frame-relative coordinate of the left edge of display
1138 area AREA of window W. ANY_AREA means return the left edge of the
1139 whole window, to the right of the left fringe of W. */
1142 window_box_left (struct window
*w
, enum glyph_row_area area
)
1144 struct frame
*f
= XFRAME (w
->frame
);
1147 if (w
->pseudo_window_p
)
1148 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1150 x
= (WINDOW_LEFT_EDGE_X (w
)
1151 + window_box_left_offset (w
, area
));
1157 /* Return the frame-relative coordinate of the right edge of display
1158 area AREA of window W. ANY_AREA means return the right edge of the
1159 whole window, to the left of the right fringe of W. */
1162 window_box_right (struct window
*w
, enum glyph_row_area area
)
1164 return window_box_left (w
, area
) + window_box_width (w
, area
);
1167 /* Get the bounding box of the display area AREA of window W, without
1168 mode lines, in frame-relative coordinates. ANY_AREA means the
1169 whole window, not including the left and right fringes of
1170 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1171 coordinates of the upper-left corner of the box. Return in
1172 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1175 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1176 int *box_y
, int *box_width
, int *box_height
)
1179 *box_width
= window_box_width (w
, area
);
1181 *box_height
= window_box_height (w
);
1183 *box_x
= window_box_left (w
, area
);
1186 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1187 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1188 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1192 #ifdef HAVE_WINDOW_SYSTEM
1194 /* Get the bounding box of the display area AREA of window W, without
1195 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1196 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1197 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1198 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1202 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1203 int *bottom_right_x
, int *bottom_right_y
)
1205 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1206 bottom_right_x
, bottom_right_y
);
1207 *bottom_right_x
+= *top_left_x
;
1208 *bottom_right_y
+= *top_left_y
;
1211 #endif /* HAVE_WINDOW_SYSTEM */
1213 /***********************************************************************
1215 ***********************************************************************/
1217 /* Return the bottom y-position of the line the iterator IT is in.
1218 This can modify IT's settings. */
1221 line_bottom_y (struct it
*it
)
1223 int line_height
= it
->max_ascent
+ it
->max_descent
;
1224 int line_top_y
= it
->current_y
;
1226 if (line_height
== 0)
1229 line_height
= last_height
;
1230 else if (IT_CHARPOS (*it
) < ZV
)
1232 move_it_by_lines (it
, 1);
1233 line_height
= (it
->max_ascent
|| it
->max_descent
1234 ? it
->max_ascent
+ it
->max_descent
1239 struct glyph_row
*row
= it
->glyph_row
;
1241 /* Use the default character height. */
1242 it
->glyph_row
= NULL
;
1243 it
->what
= IT_CHARACTER
;
1246 PRODUCE_GLYPHS (it
);
1247 line_height
= it
->ascent
+ it
->descent
;
1248 it
->glyph_row
= row
;
1252 return line_top_y
+ line_height
;
1255 DEFUN ("line-pixel-height", Fline_pixel_height
,
1256 Sline_pixel_height
, 0, 0, 0,
1257 doc
: /* Return height in pixels of text line in the selected window.
1259 Value is the height in pixels of the line at point. */)
1264 struct window
*w
= XWINDOW (selected_window
);
1266 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1267 start_display (&it
, w
, pt
);
1268 it
.vpos
= it
.current_y
= 0;
1270 return make_number (line_bottom_y (&it
));
1273 /* Return the default pixel height of text lines in window W. The
1274 value is the canonical height of the W frame's default font, plus
1275 any extra space required by the line-spacing variable or frame
1278 Implementation note: this ignores any line-spacing text properties
1279 put on the newline characters. This is because those properties
1280 only affect the _screen_ line ending in the newline (i.e., in a
1281 continued line, only the last screen line will be affected), which
1282 means only a small number of lines in a buffer can ever use this
1283 feature. Since this function is used to compute the default pixel
1284 equivalent of text lines in a window, we can safely ignore those
1285 few lines. For the same reasons, we ignore the line-height
1288 default_line_pixel_height (struct window
*w
)
1290 struct frame
*f
= WINDOW_XFRAME (w
);
1291 int height
= FRAME_LINE_HEIGHT (f
);
1293 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1295 struct buffer
*b
= XBUFFER (w
->contents
);
1296 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1299 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1302 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1303 height
+= XFASTINT (val
);
1304 else if (FLOATP (val
))
1306 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1313 height
+= f
->extra_line_spacing
;
1319 /* Subroutine of pos_visible_p below. Extracts a display string, if
1320 any, from the display spec given as its argument. */
1322 string_from_display_spec (Lisp_Object spec
)
1326 while (CONSP (spec
))
1328 if (STRINGP (XCAR (spec
)))
1333 else if (VECTORP (spec
))
1337 for (i
= 0; i
< ASIZE (spec
); i
++)
1339 if (STRINGP (AREF (spec
, i
)))
1340 return AREF (spec
, i
);
1349 /* Limit insanely large values of W->hscroll on frame F to the largest
1350 value that will still prevent first_visible_x and last_visible_x of
1351 'struct it' from overflowing an int. */
1353 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1355 ptrdiff_t window_hscroll
= w
->hscroll
;
1356 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1357 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1359 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1360 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1362 return window_hscroll
;
1365 /* Return 1 if position CHARPOS is visible in window W.
1366 CHARPOS < 0 means return info about WINDOW_END position.
1367 If visible, set *X and *Y to pixel coordinates of top left corner.
1368 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1369 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1372 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1373 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1376 void *itdata
= bidi_shelve_cache ();
1377 struct text_pos top
;
1379 struct buffer
*old_buffer
= NULL
;
1381 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1384 if (XBUFFER (w
->contents
) != current_buffer
)
1386 old_buffer
= current_buffer
;
1387 set_buffer_internal_1 (XBUFFER (w
->contents
));
1390 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1391 /* Scrolling a minibuffer window via scroll bar when the echo area
1392 shows long text sometimes resets the minibuffer contents behind
1394 if (CHARPOS (top
) > ZV
)
1395 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1397 /* Compute exact mode line heights. */
1398 if (WINDOW_WANTS_MODELINE_P (w
))
1400 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1401 BVAR (current_buffer
, mode_line_format
));
1403 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1404 w
->header_line_height
1405 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1406 BVAR (current_buffer
, header_line_format
));
1408 start_display (&it
, w
, top
);
1409 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1410 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1413 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1414 && IT_CHARPOS (it
) >= charpos
)
1415 /* When scanning backwards under bidi iteration, move_it_to
1416 stops at or _before_ CHARPOS, because it stops at or to
1417 the _right_ of the character at CHARPOS. */
1418 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1419 && IT_CHARPOS (it
) <= charpos
)))
1421 /* We have reached CHARPOS, or passed it. How the call to
1422 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1423 or covered by a display property, move_it_to stops at the end
1424 of the invisible text, to the right of CHARPOS. (ii) If
1425 CHARPOS is in a display vector, move_it_to stops on its last
1427 int top_x
= it
.current_x
;
1428 int top_y
= it
.current_y
;
1429 /* Calling line_bottom_y may change it.method, it.position, etc. */
1430 enum it_method it_method
= it
.method
;
1431 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1432 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1434 if (top_y
< window_top_y
)
1435 visible_p
= bottom_y
> window_top_y
;
1436 else if (top_y
< it
.last_visible_y
)
1438 if (bottom_y
>= it
.last_visible_y
1439 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1440 && IT_CHARPOS (it
) < charpos
)
1442 /* When the last line of the window is scanned backwards
1443 under bidi iteration, we could be duped into thinking
1444 that we have passed CHARPOS, when in fact move_it_to
1445 simply stopped short of CHARPOS because it reached
1446 last_visible_y. To see if that's what happened, we call
1447 move_it_to again with a slightly larger vertical limit,
1448 and see if it actually moved vertically; if it did, we
1449 didn't really reach CHARPOS, which is beyond window end. */
1450 struct it save_it
= it
;
1451 /* Why 10? because we don't know how many canonical lines
1452 will the height of the next line(s) be. So we guess. */
1453 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1455 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1456 MOVE_TO_POS
| MOVE_TO_Y
);
1457 if (it
.current_y
> top_y
)
1464 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1466 /* We stopped on the last glyph of a display vector.
1467 Try and recompute. Hack alert! */
1468 if (charpos
< 2 || top
.charpos
>= charpos
)
1469 top_x
= it
.glyph_row
->x
;
1472 struct it it2
, it2_prev
;
1473 /* The idea is to get to the previous buffer
1474 position, consume the character there, and use
1475 the pixel coordinates we get after that. But if
1476 the previous buffer position is also displayed
1477 from a display vector, we need to consume all of
1478 the glyphs from that display vector. */
1479 start_display (&it2
, w
, top
);
1480 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1481 /* If we didn't get to CHARPOS - 1, there's some
1482 replacing display property at that position, and
1483 we stopped after it. That is exactly the place
1484 whose coordinates we want. */
1485 if (IT_CHARPOS (it2
) != charpos
- 1)
1489 /* Iterate until we get out of the display
1490 vector that displays the character at
1493 get_next_display_element (&it2
);
1494 PRODUCE_GLYPHS (&it2
);
1496 set_iterator_to_next (&it2
, 1);
1497 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1498 && IT_CHARPOS (it2
) < charpos
);
1500 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1501 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1502 top_x
= it
.glyph_row
->x
;
1505 top_x
= it2_prev
.current_x
;
1506 top_y
= it2_prev
.current_y
;
1510 else if (IT_CHARPOS (it
) != charpos
)
1512 Lisp_Object cpos
= make_number (charpos
);
1513 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1514 Lisp_Object string
= string_from_display_spec (spec
);
1515 struct text_pos tpos
;
1516 int replacing_spec_p
;
1517 bool newline_in_string
1519 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1521 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1524 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1525 charpos
, FRAME_WINDOW_P (it
.f
)));
1526 /* The tricky code below is needed because there's a
1527 discrepancy between move_it_to and how we set cursor
1528 when PT is at the beginning of a portion of text
1529 covered by a display property or an overlay with a
1530 display property, or the display line ends in a
1531 newline from a display string. move_it_to will stop
1532 _after_ such display strings, whereas
1533 set_cursor_from_row conspires with cursor_row_p to
1534 place the cursor on the first glyph produced from the
1537 /* We have overshoot PT because it is covered by a
1538 display property that replaces the text it covers.
1539 If the string includes embedded newlines, we are also
1540 in the wrong display line. Backtrack to the correct
1541 line, where the display property begins. */
1542 if (replacing_spec_p
)
1544 Lisp_Object startpos
, endpos
;
1545 EMACS_INT start
, end
;
1549 /* Find the first and the last buffer positions
1550 covered by the display string. */
1552 Fnext_single_char_property_change (cpos
, Qdisplay
,
1555 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1557 start
= XFASTINT (startpos
);
1558 end
= XFASTINT (endpos
);
1559 /* Move to the last buffer position before the
1560 display property. */
1561 start_display (&it3
, w
, top
);
1562 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1563 /* Move forward one more line if the position before
1564 the display string is a newline or if it is the
1565 rightmost character on a line that is
1566 continued or word-wrapped. */
1567 if (it3
.method
== GET_FROM_BUFFER
1569 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1570 move_it_by_lines (&it3
, 1);
1571 else if (move_it_in_display_line_to (&it3
, -1,
1575 == MOVE_LINE_CONTINUED
)
1577 move_it_by_lines (&it3
, 1);
1578 /* When we are under word-wrap, the #$@%!
1579 move_it_by_lines moves 2 lines, so we need to
1581 if (it3
.line_wrap
== WORD_WRAP
)
1582 move_it_by_lines (&it3
, -1);
1585 /* Record the vertical coordinate of the display
1586 line where we wound up. */
1587 top_y
= it3
.current_y
;
1590 /* When characters are reordered for display,
1591 the character displayed to the left of the
1592 display string could be _after_ the display
1593 property in the logical order. Use the
1594 smallest vertical position of these two. */
1595 start_display (&it3
, w
, top
);
1596 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1597 if (it3
.current_y
< top_y
)
1598 top_y
= it3
.current_y
;
1600 /* Move from the top of the window to the beginning
1601 of the display line where the display string
1603 start_display (&it3
, w
, top
);
1604 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1605 /* If it3_moved stays zero after the 'while' loop
1606 below, that means we already were at a newline
1607 before the loop (e.g., the display string begins
1608 with a newline), so we don't need to (and cannot)
1609 inspect the glyphs of it3.glyph_row, because
1610 PRODUCE_GLYPHS will not produce anything for a
1611 newline, and thus it3.glyph_row stays at its
1612 stale content it got at top of the window. */
1614 /* Finally, advance the iterator until we hit the
1615 first display element whose character position is
1616 CHARPOS, or until the first newline from the
1617 display string, which signals the end of the
1619 while (get_next_display_element (&it3
))
1621 PRODUCE_GLYPHS (&it3
);
1622 if (IT_CHARPOS (it3
) == charpos
1623 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1626 set_iterator_to_next (&it3
, 0);
1628 top_x
= it3
.current_x
- it3
.pixel_width
;
1629 /* Normally, we would exit the above loop because we
1630 found the display element whose character
1631 position is CHARPOS. For the contingency that we
1632 didn't, and stopped at the first newline from the
1633 display string, move back over the glyphs
1634 produced from the string, until we find the
1635 rightmost glyph not from the string. */
1637 && newline_in_string
1638 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1640 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1641 + it3
.glyph_row
->used
[TEXT_AREA
];
1643 while (EQ ((g
- 1)->object
, string
))
1646 top_x
-= g
->pixel_width
;
1648 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1649 + it3
.glyph_row
->used
[TEXT_AREA
]);
1655 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1656 *rtop
= max (0, window_top_y
- top_y
);
1657 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1658 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1659 - max (top_y
, window_top_y
)));
1665 /* We were asked to provide info about WINDOW_END. */
1667 void *it2data
= NULL
;
1669 SAVE_IT (it2
, it
, it2data
);
1670 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1671 move_it_by_lines (&it
, 1);
1672 if (charpos
< IT_CHARPOS (it
)
1673 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1676 RESTORE_IT (&it2
, &it2
, it2data
);
1677 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1679 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1680 *rtop
= max (0, -it2
.current_y
);
1681 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1682 - it
.last_visible_y
));
1683 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1685 - max (it2
.current_y
,
1686 WINDOW_HEADER_LINE_HEIGHT (w
))));
1690 bidi_unshelve_cache (it2data
, 1);
1692 bidi_unshelve_cache (itdata
, 0);
1695 set_buffer_internal_1 (old_buffer
);
1697 if (visible_p
&& w
->hscroll
> 0)
1699 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1700 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1703 /* Debugging code. */
1705 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1706 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1708 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1715 /* Return the next character from STR. Return in *LEN the length of
1716 the character. This is like STRING_CHAR_AND_LENGTH but never
1717 returns an invalid character. If we find one, we return a `?', but
1718 with the length of the invalid character. */
1721 string_char_and_length (const unsigned char *str
, int *len
)
1725 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1726 if (!CHAR_VALID_P (c
))
1727 /* We may not change the length here because other places in Emacs
1728 don't use this function, i.e. they silently accept invalid
1737 /* Given a position POS containing a valid character and byte position
1738 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1740 static struct text_pos
1741 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1743 eassert (STRINGP (string
) && nchars
>= 0);
1745 if (STRING_MULTIBYTE (string
))
1747 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1752 string_char_and_length (p
, &len
);
1755 BYTEPOS (pos
) += len
;
1759 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1765 /* Value is the text position, i.e. character and byte position,
1766 for character position CHARPOS in STRING. */
1768 static struct text_pos
1769 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1771 struct text_pos pos
;
1772 eassert (STRINGP (string
));
1773 eassert (charpos
>= 0);
1774 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1779 /* Value is a text position, i.e. character and byte position, for
1780 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1781 means recognize multibyte characters. */
1783 static struct text_pos
1784 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1786 struct text_pos pos
;
1788 eassert (s
!= NULL
);
1789 eassert (charpos
>= 0);
1795 SET_TEXT_POS (pos
, 0, 0);
1798 string_char_and_length ((const unsigned char *) s
, &len
);
1801 BYTEPOS (pos
) += len
;
1805 SET_TEXT_POS (pos
, charpos
, charpos
);
1811 /* Value is the number of characters in C string S. MULTIBYTE_P
1812 non-zero means recognize multibyte characters. */
1815 number_of_chars (const char *s
, bool multibyte_p
)
1821 ptrdiff_t rest
= strlen (s
);
1823 const unsigned char *p
= (const unsigned char *) s
;
1825 for (nchars
= 0; rest
> 0; ++nchars
)
1827 string_char_and_length (p
, &len
);
1828 rest
-= len
, p
+= len
;
1832 nchars
= strlen (s
);
1838 /* Compute byte position NEWPOS->bytepos corresponding to
1839 NEWPOS->charpos. POS is a known position in string STRING.
1840 NEWPOS->charpos must be >= POS.charpos. */
1843 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1845 eassert (STRINGP (string
));
1846 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1848 if (STRING_MULTIBYTE (string
))
1849 *newpos
= string_pos_nchars_ahead (pos
, string
,
1850 CHARPOS (*newpos
) - CHARPOS (pos
));
1852 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1856 Return an estimation of the pixel height of mode or header lines on
1857 frame F. FACE_ID specifies what line's height to estimate. */
1860 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1862 #ifdef HAVE_WINDOW_SYSTEM
1863 if (FRAME_WINDOW_P (f
))
1865 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1867 /* This function is called so early when Emacs starts that the face
1868 cache and mode line face are not yet initialized. */
1869 if (FRAME_FACE_CACHE (f
))
1871 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1875 height
= FONT_HEIGHT (face
->font
);
1876 if (face
->box_line_width
> 0)
1877 height
+= 2 * face
->box_line_width
;
1888 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1889 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1890 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1891 not force the value into range. */
1894 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1895 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1898 #ifdef HAVE_WINDOW_SYSTEM
1899 if (FRAME_WINDOW_P (f
))
1901 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1902 even for negative values. */
1904 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1906 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1908 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1909 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1912 STORE_NATIVE_RECT (*bounds
,
1913 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1914 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1915 FRAME_COLUMN_WIDTH (f
) - 1,
1916 FRAME_LINE_HEIGHT (f
) - 1);
1918 /* PXW: Should we clip pixels before converting to columns/lines? */
1923 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1924 pix_x
= FRAME_TOTAL_COLS (f
);
1928 else if (pix_y
> FRAME_LINES (f
))
1929 pix_y
= FRAME_LINES (f
);
1939 /* Find the glyph under window-relative coordinates X/Y in window W.
1940 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1941 strings. Return in *HPOS and *VPOS the row and column number of
1942 the glyph found. Return in *AREA the glyph area containing X.
1943 Value is a pointer to the glyph found or null if X/Y is not on
1944 text, or we can't tell because W's current matrix is not up to
1947 static struct glyph
*
1948 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1949 int *dx
, int *dy
, int *area
)
1951 struct glyph
*glyph
, *end
;
1952 struct glyph_row
*row
= NULL
;
1955 /* Find row containing Y. Give up if some row is not enabled. */
1956 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1958 row
= MATRIX_ROW (w
->current_matrix
, i
);
1959 if (!row
->enabled_p
)
1961 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1968 /* Give up if Y is not in the window. */
1969 if (i
== w
->current_matrix
->nrows
)
1972 /* Get the glyph area containing X. */
1973 if (w
->pseudo_window_p
)
1980 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1982 *area
= LEFT_MARGIN_AREA
;
1983 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1985 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1988 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1992 *area
= RIGHT_MARGIN_AREA
;
1993 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1997 /* Find glyph containing X. */
1998 glyph
= row
->glyphs
[*area
];
1999 end
= glyph
+ row
->used
[*area
];
2001 while (glyph
< end
&& x
>= glyph
->pixel_width
)
2003 x
-= glyph
->pixel_width
;
2013 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
2016 *hpos
= glyph
- row
->glyphs
[*area
];
2020 /* Convert frame-relative x/y to coordinates relative to window W.
2021 Takes pseudo-windows into account. */
2024 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
2026 if (w
->pseudo_window_p
)
2028 /* A pseudo-window is always full-width, and starts at the
2029 left edge of the frame, plus a frame border. */
2030 struct frame
*f
= XFRAME (w
->frame
);
2031 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
2032 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2036 *x
-= WINDOW_LEFT_EDGE_X (w
);
2037 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2041 #ifdef HAVE_WINDOW_SYSTEM
2044 Return in RECTS[] at most N clipping rectangles for glyph string S.
2045 Return the number of stored rectangles. */
2048 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2055 if (s
->row
->full_width_p
)
2057 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2058 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2059 if (s
->row
->mode_line_p
)
2060 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
) - WINDOW_RIGHT_DIVIDER_WIDTH (s
->w
);
2062 r
.width
= WINDOW_PIXEL_WIDTH (s
->w
);
2064 /* Unless displaying a mode or menu bar line, which are always
2065 fully visible, clip to the visible part of the row. */
2066 if (s
->w
->pseudo_window_p
)
2067 r
.height
= s
->row
->visible_height
;
2069 r
.height
= s
->height
;
2073 /* This is a text line that may be partially visible. */
2074 r
.x
= window_box_left (s
->w
, s
->area
);
2075 r
.width
= window_box_width (s
->w
, s
->area
);
2076 r
.height
= s
->row
->visible_height
;
2080 if (r
.x
< s
->clip_head
->x
)
2082 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2083 r
.width
-= s
->clip_head
->x
- r
.x
;
2086 r
.x
= s
->clip_head
->x
;
2089 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2091 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2092 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2097 /* If S draws overlapping rows, it's sufficient to use the top and
2098 bottom of the window for clipping because this glyph string
2099 intentionally draws over other lines. */
2100 if (s
->for_overlaps
)
2102 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2103 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2105 /* Alas, the above simple strategy does not work for the
2106 environments with anti-aliased text: if the same text is
2107 drawn onto the same place multiple times, it gets thicker.
2108 If the overlap we are processing is for the erased cursor, we
2109 take the intersection with the rectangle of the cursor. */
2110 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2112 XRectangle rc
, r_save
= r
;
2114 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2115 rc
.y
= s
->w
->phys_cursor
.y
;
2116 rc
.width
= s
->w
->phys_cursor_width
;
2117 rc
.height
= s
->w
->phys_cursor_height
;
2119 x_intersect_rectangles (&r_save
, &rc
, &r
);
2124 /* Don't use S->y for clipping because it doesn't take partially
2125 visible lines into account. For example, it can be negative for
2126 partially visible lines at the top of a window. */
2127 if (!s
->row
->full_width_p
2128 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2129 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2131 r
.y
= max (0, s
->row
->y
);
2134 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2136 /* If drawing the cursor, don't let glyph draw outside its
2137 advertised boundaries. Cleartype does this under some circumstances. */
2138 if (s
->hl
== DRAW_CURSOR
)
2140 struct glyph
*glyph
= s
->first_glyph
;
2145 r
.width
-= s
->x
- r
.x
;
2148 r
.width
= min (r
.width
, glyph
->pixel_width
);
2150 /* If r.y is below window bottom, ensure that we still see a cursor. */
2151 height
= min (glyph
->ascent
+ glyph
->descent
,
2152 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2153 max_y
= window_text_bottom_y (s
->w
) - height
;
2154 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2155 if (s
->ybase
- glyph
->ascent
> max_y
)
2162 /* Don't draw cursor glyph taller than our actual glyph. */
2163 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2164 if (height
< r
.height
)
2166 max_y
= r
.y
+ r
.height
;
2167 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2168 r
.height
= min (max_y
- r
.y
, height
);
2175 XRectangle r_save
= r
;
2177 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2181 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2182 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2184 #ifdef CONVERT_FROM_XRECT
2185 CONVERT_FROM_XRECT (r
, *rects
);
2193 /* If we are processing overlapping and allowed to return
2194 multiple clipping rectangles, we exclude the row of the glyph
2195 string from the clipping rectangle. This is to avoid drawing
2196 the same text on the environment with anti-aliasing. */
2197 #ifdef CONVERT_FROM_XRECT
2200 XRectangle
*rs
= rects
;
2202 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2204 if (s
->for_overlaps
& OVERLAPS_PRED
)
2207 if (r
.y
+ r
.height
> row_y
)
2210 rs
[i
].height
= row_y
- r
.y
;
2216 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2219 if (r
.y
< row_y
+ s
->row
->visible_height
)
2221 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2223 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2224 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2233 #ifdef CONVERT_FROM_XRECT
2234 for (i
= 0; i
< n
; i
++)
2235 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2242 Return in *NR the clipping rectangle for glyph string S. */
2245 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2247 get_glyph_string_clip_rects (s
, nr
, 1);
2252 Return the position and height of the phys cursor in window W.
2253 Set w->phys_cursor_width to width of phys cursor.
2257 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2258 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2260 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2261 int x
, y
, wd
, h
, h0
, y0
;
2263 /* Compute the width of the rectangle to draw. If on a stretch
2264 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2265 rectangle as wide as the glyph, but use a canonical character
2267 wd
= glyph
->pixel_width
- 1;
2268 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2272 x
= w
->phys_cursor
.x
;
2279 if (glyph
->type
== STRETCH_GLYPH
2280 && !x_stretch_cursor_p
)
2281 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2282 w
->phys_cursor_width
= wd
;
2284 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2286 /* If y is below window bottom, ensure that we still see a cursor. */
2287 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2289 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2290 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2292 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2295 h
= max (h
- (y0
- y
) + 1, h0
);
2300 y0
= window_text_bottom_y (w
) - h0
;
2308 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2309 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2314 * Remember which glyph the mouse is over.
2318 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2322 struct glyph_row
*r
, *gr
, *end_row
;
2323 enum window_part part
;
2324 enum glyph_row_area area
;
2325 int x
, y
, width
, height
;
2327 /* Try to determine frame pixel position and size of the glyph under
2328 frame pixel coordinates X/Y on frame F. */
2330 if (window_resize_pixelwise
)
2335 else if (!f
->glyphs_initialized_p
2336 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2339 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2340 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2344 w
= XWINDOW (window
);
2345 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2346 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2348 x
= window_relative_x_coord (w
, part
, gx
);
2349 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2351 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2352 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2354 if (w
->pseudo_window_p
)
2357 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2363 case ON_LEFT_MARGIN
:
2364 area
= LEFT_MARGIN_AREA
;
2367 case ON_RIGHT_MARGIN
:
2368 area
= RIGHT_MARGIN_AREA
;
2371 case ON_HEADER_LINE
:
2373 gr
= (part
== ON_HEADER_LINE
2374 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2375 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2378 goto text_glyph_row_found
;
2385 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2386 if (r
->y
+ r
->height
> y
)
2392 text_glyph_row_found
:
2395 struct glyph
*g
= gr
->glyphs
[area
];
2396 struct glyph
*end
= g
+ gr
->used
[area
];
2398 height
= gr
->height
;
2399 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2400 if (gx
+ g
->pixel_width
> x
)
2405 if (g
->type
== IMAGE_GLYPH
)
2407 /* Don't remember when mouse is over image, as
2408 image may have hot-spots. */
2409 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2412 width
= g
->pixel_width
;
2416 /* Use nominal char spacing at end of line. */
2418 gx
+= (x
/ width
) * width
;
2421 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2422 gx
+= window_box_left_offset (w
, area
);
2426 /* Use nominal line height at end of window. */
2427 gx
= (x
/ width
) * width
;
2429 gy
+= (y
/ height
) * height
;
2433 case ON_LEFT_FRINGE
:
2434 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2435 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2436 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2437 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2440 case ON_RIGHT_FRINGE
:
2441 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2442 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2443 : window_box_right_offset (w
, TEXT_AREA
));
2444 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2448 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2450 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2451 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2452 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2454 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2458 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2459 if (r
->y
+ r
->height
> y
)
2466 height
= gr
->height
;
2469 /* Use nominal line height at end of window. */
2471 gy
+= (y
/ height
) * height
;
2478 /* If there is no glyph under the mouse, then we divide the screen
2479 into a grid of the smallest glyph in the frame, and use that
2482 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2483 round down even for negative values. */
2489 gx
= (gx
/ width
) * width
;
2490 gy
= (gy
/ height
) * height
;
2495 gx
+= WINDOW_LEFT_EDGE_X (w
);
2496 gy
+= WINDOW_TOP_EDGE_Y (w
);
2499 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2501 /* Visible feedback for debugging. */
2504 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2505 f
->output_data
.x
->normal_gc
,
2506 gx
, gy
, width
, height
);
2512 #endif /* HAVE_WINDOW_SYSTEM */
2515 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2518 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2519 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2521 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2524 /***********************************************************************
2525 Lisp form evaluation
2526 ***********************************************************************/
2528 /* Error handler for safe_eval and safe_call. */
2531 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2533 add_to_log ("Error during redisplay: %S signaled %S",
2534 Flist (nargs
, args
), arg
);
2538 /* Call function FUNC with the rest of NARGS - 1 arguments
2539 following. Return the result, or nil if something went
2540 wrong. Prevent redisplay during the evaluation. */
2543 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2547 if (inhibit_eval_during_redisplay
)
2553 ptrdiff_t count
= SPECPDL_INDEX ();
2554 struct gcpro gcpro1
;
2555 Lisp_Object
*args
= alloca (nargs
* word_size
);
2558 va_start (ap
, func
);
2559 for (i
= 1; i
< nargs
; i
++)
2560 args
[i
] = va_arg (ap
, Lisp_Object
);
2564 gcpro1
.nvars
= nargs
;
2565 specbind (Qinhibit_redisplay
, Qt
);
2566 /* Use Qt to ensure debugger does not run,
2567 so there is no possibility of wanting to redisplay. */
2568 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2571 val
= unbind_to (count
, val
);
2578 /* Call function FN with one argument ARG.
2579 Return the result, or nil if something went wrong. */
2582 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2584 return safe_call (2, fn
, arg
);
2587 static Lisp_Object Qeval
;
2590 safe_eval (Lisp_Object sexpr
)
2592 return safe_call1 (Qeval
, sexpr
);
2595 /* Call function FN with two arguments ARG1 and ARG2.
2596 Return the result, or nil if something went wrong. */
2599 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2601 return safe_call (3, fn
, arg1
, arg2
);
2606 /***********************************************************************
2608 ***********************************************************************/
2612 /* Define CHECK_IT to perform sanity checks on iterators.
2613 This is for debugging. It is too slow to do unconditionally. */
2616 check_it (struct it
*it
)
2618 if (it
->method
== GET_FROM_STRING
)
2620 eassert (STRINGP (it
->string
));
2621 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2625 eassert (IT_STRING_CHARPOS (*it
) < 0);
2626 if (it
->method
== GET_FROM_BUFFER
)
2628 /* Check that character and byte positions agree. */
2629 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2634 eassert (it
->current
.dpvec_index
>= 0);
2636 eassert (it
->current
.dpvec_index
< 0);
2639 #define CHECK_IT(IT) check_it ((IT))
2643 #define CHECK_IT(IT) (void) 0
2648 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2650 /* Check that the window end of window W is what we expect it
2651 to be---the last row in the current matrix displaying text. */
2654 check_window_end (struct window
*w
)
2656 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2658 struct glyph_row
*row
;
2659 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2661 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2662 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2666 #define CHECK_WINDOW_END(W) check_window_end ((W))
2670 #define CHECK_WINDOW_END(W) (void) 0
2672 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2674 /***********************************************************************
2675 Iterator initialization
2676 ***********************************************************************/
2678 /* Initialize IT for displaying current_buffer in window W, starting
2679 at character position CHARPOS. CHARPOS < 0 means that no buffer
2680 position is specified which is useful when the iterator is assigned
2681 a position later. BYTEPOS is the byte position corresponding to
2684 If ROW is not null, calls to produce_glyphs with IT as parameter
2685 will produce glyphs in that row.
2687 BASE_FACE_ID is the id of a base face to use. It must be one of
2688 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2689 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2690 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2692 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2693 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2694 will be initialized to use the corresponding mode line glyph row of
2695 the desired matrix of W. */
2698 init_iterator (struct it
*it
, struct window
*w
,
2699 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2700 struct glyph_row
*row
, enum face_id base_face_id
)
2702 enum face_id remapped_base_face_id
= base_face_id
;
2704 /* Some precondition checks. */
2705 eassert (w
!= NULL
&& it
!= NULL
);
2706 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2709 /* If face attributes have been changed since the last redisplay,
2710 free realized faces now because they depend on face definitions
2711 that might have changed. Don't free faces while there might be
2712 desired matrices pending which reference these faces. */
2713 if (face_change_count
&& !inhibit_free_realized_faces
)
2715 face_change_count
= 0;
2716 free_all_realized_faces (Qnil
);
2719 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2720 if (! NILP (Vface_remapping_alist
))
2721 remapped_base_face_id
2722 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2724 /* Use one of the mode line rows of W's desired matrix if
2728 if (base_face_id
== MODE_LINE_FACE_ID
2729 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2730 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2731 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2732 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2736 memset (it
, 0, sizeof *it
);
2737 it
->current
.overlay_string_index
= -1;
2738 it
->current
.dpvec_index
= -1;
2739 it
->base_face_id
= remapped_base_face_id
;
2741 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2742 it
->paragraph_embedding
= L2R
;
2743 it
->bidi_it
.string
.lstring
= Qnil
;
2744 it
->bidi_it
.string
.s
= NULL
;
2745 it
->bidi_it
.string
.bufpos
= 0;
2748 /* The window in which we iterate over current_buffer: */
2749 XSETWINDOW (it
->window
, w
);
2751 it
->f
= XFRAME (w
->frame
);
2755 /* Extra space between lines (on window systems only). */
2756 if (base_face_id
== DEFAULT_FACE_ID
2757 && FRAME_WINDOW_P (it
->f
))
2759 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2760 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2761 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2762 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2763 * FRAME_LINE_HEIGHT (it
->f
));
2764 else if (it
->f
->extra_line_spacing
> 0)
2765 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2766 it
->max_extra_line_spacing
= 0;
2769 /* If realized faces have been removed, e.g. because of face
2770 attribute changes of named faces, recompute them. When running
2771 in batch mode, the face cache of the initial frame is null. If
2772 we happen to get called, make a dummy face cache. */
2773 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2774 init_frame_faces (it
->f
);
2775 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2776 recompute_basic_faces (it
->f
);
2778 /* Current value of the `slice', `space-width', and 'height' properties. */
2779 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2780 it
->space_width
= Qnil
;
2781 it
->font_height
= Qnil
;
2782 it
->override_ascent
= -1;
2784 /* Are control characters displayed as `^C'? */
2785 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2787 /* -1 means everything between a CR and the following line end
2788 is invisible. >0 means lines indented more than this value are
2790 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2792 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2794 : (!NILP (BVAR (current_buffer
, selective_display
))
2796 it
->selective_display_ellipsis_p
2797 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2799 /* Display table to use. */
2800 it
->dp
= window_display_table (w
);
2802 /* Are multibyte characters enabled in current_buffer? */
2803 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2805 /* Get the position at which the redisplay_end_trigger hook should
2806 be run, if it is to be run at all. */
2807 if (MARKERP (w
->redisplay_end_trigger
)
2808 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2809 it
->redisplay_end_trigger_charpos
2810 = marker_position (w
->redisplay_end_trigger
);
2811 else if (INTEGERP (w
->redisplay_end_trigger
))
2812 it
->redisplay_end_trigger_charpos
2813 = clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
),
2816 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2818 /* Are lines in the display truncated? */
2819 if (base_face_id
!= DEFAULT_FACE_ID
2821 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2822 && ((!NILP (Vtruncate_partial_width_windows
)
2823 && !INTEGERP (Vtruncate_partial_width_windows
))
2824 || (INTEGERP (Vtruncate_partial_width_windows
)
2825 /* PXW: Shall we do something about this? */
2826 && (WINDOW_TOTAL_COLS (it
->w
)
2827 < XINT (Vtruncate_partial_width_windows
))))))
2828 it
->line_wrap
= TRUNCATE
;
2829 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2830 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2831 ? WINDOW_WRAP
: WORD_WRAP
;
2833 it
->line_wrap
= TRUNCATE
;
2835 /* Get dimensions of truncation and continuation glyphs. These are
2836 displayed as fringe bitmaps under X, but we need them for such
2837 frames when the fringes are turned off. But leave the dimensions
2838 zero for tooltip frames, as these glyphs look ugly there and also
2839 sabotage calculations of tooltip dimensions in x-show-tip. */
2840 #ifdef HAVE_WINDOW_SYSTEM
2841 if (!(FRAME_WINDOW_P (it
->f
)
2842 && FRAMEP (tip_frame
)
2843 && it
->f
== XFRAME (tip_frame
)))
2846 if (it
->line_wrap
== TRUNCATE
)
2848 /* We will need the truncation glyph. */
2849 eassert (it
->glyph_row
== NULL
);
2850 produce_special_glyphs (it
, IT_TRUNCATION
);
2851 it
->truncation_pixel_width
= it
->pixel_width
;
2855 /* We will need the continuation glyph. */
2856 eassert (it
->glyph_row
== NULL
);
2857 produce_special_glyphs (it
, IT_CONTINUATION
);
2858 it
->continuation_pixel_width
= it
->pixel_width
;
2862 /* Reset these values to zero because the produce_special_glyphs
2863 above has changed them. */
2864 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2865 it
->phys_ascent
= it
->phys_descent
= 0;
2867 /* Set this after getting the dimensions of truncation and
2868 continuation glyphs, so that we don't produce glyphs when calling
2869 produce_special_glyphs, above. */
2870 it
->glyph_row
= row
;
2871 it
->area
= TEXT_AREA
;
2873 /* Forget any previous info about this row being reversed. */
2875 it
->glyph_row
->reversed_p
= 0;
2877 /* Get the dimensions of the display area. The display area
2878 consists of the visible window area plus a horizontally scrolled
2879 part to the left of the window. All x-values are relative to the
2880 start of this total display area. */
2881 if (base_face_id
!= DEFAULT_FACE_ID
)
2883 /* Mode lines, menu bar in terminal frames. */
2884 it
->first_visible_x
= 0;
2885 it
->last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
2890 = window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2891 it
->last_visible_x
= (it
->first_visible_x
2892 + window_box_width (w
, TEXT_AREA
));
2894 /* If we truncate lines, leave room for the truncation glyph(s) at
2895 the right margin. Otherwise, leave room for the continuation
2896 glyph(s). Done only if the window has no fringes. Since we
2897 don't know at this point whether there will be any R2L lines in
2898 the window, we reserve space for truncation/continuation glyphs
2899 even if only one of the fringes is absent. */
2900 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2901 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2903 if (it
->line_wrap
== TRUNCATE
)
2904 it
->last_visible_x
-= it
->truncation_pixel_width
;
2906 it
->last_visible_x
-= it
->continuation_pixel_width
;
2909 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2910 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2913 /* Leave room for a border glyph. */
2914 if (!FRAME_WINDOW_P (it
->f
)
2915 && !WINDOW_RIGHTMOST_P (it
->w
))
2916 it
->last_visible_x
-= 1;
2918 it
->last_visible_y
= window_text_bottom_y (w
);
2920 /* For mode lines and alike, arrange for the first glyph having a
2921 left box line if the face specifies a box. */
2922 if (base_face_id
!= DEFAULT_FACE_ID
)
2926 it
->face_id
= remapped_base_face_id
;
2928 /* If we have a boxed mode line, make the first character appear
2929 with a left box line. */
2930 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2931 if (face
&& face
->box
!= FACE_NO_BOX
)
2932 it
->start_of_box_run_p
= true;
2935 /* If a buffer position was specified, set the iterator there,
2936 getting overlays and face properties from that position. */
2937 if (charpos
>= BUF_BEG (current_buffer
))
2939 it
->end_charpos
= ZV
;
2940 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2941 IT_CHARPOS (*it
) = charpos
;
2942 IT_BYTEPOS (*it
) = bytepos
;
2944 /* We will rely on `reseat' to set this up properly, via
2945 handle_face_prop. */
2946 it
->face_id
= it
->base_face_id
;
2948 it
->start
= it
->current
;
2949 /* Do we need to reorder bidirectional text? Not if this is a
2950 unibyte buffer: by definition, none of the single-byte
2951 characters are strong R2L, so no reordering is needed. And
2952 bidi.c doesn't support unibyte buffers anyway. Also, don't
2953 reorder while we are loading loadup.el, since the tables of
2954 character properties needed for reordering are not yet
2958 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2961 /* If we are to reorder bidirectional text, init the bidi
2965 /* Note the paragraph direction that this buffer wants to
2967 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2969 it
->paragraph_embedding
= L2R
;
2970 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2972 it
->paragraph_embedding
= R2L
;
2974 it
->paragraph_embedding
= NEUTRAL_DIR
;
2975 bidi_unshelve_cache (NULL
, 0);
2976 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2980 /* Compute faces etc. */
2981 reseat (it
, it
->current
.pos
, 1);
2988 /* Initialize IT for the display of window W with window start POS. */
2991 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2993 struct glyph_row
*row
;
2994 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2996 row
= w
->desired_matrix
->rows
+ first_vpos
;
2997 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2998 it
->first_vpos
= first_vpos
;
3000 /* Don't reseat to previous visible line start if current start
3001 position is in a string or image. */
3002 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
3004 int start_at_line_beg_p
;
3005 int first_y
= it
->current_y
;
3007 /* If window start is not at a line start, skip forward to POS to
3008 get the correct continuation lines width. */
3009 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
3010 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
3011 if (!start_at_line_beg_p
)
3015 reseat_at_previous_visible_line_start (it
);
3016 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3018 new_x
= it
->current_x
+ it
->pixel_width
;
3020 /* If lines are continued, this line may end in the middle
3021 of a multi-glyph character (e.g. a control character
3022 displayed as \003, or in the middle of an overlay
3023 string). In this case move_it_to above will not have
3024 taken us to the start of the continuation line but to the
3025 end of the continued line. */
3026 if (it
->current_x
> 0
3027 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3028 && (/* And glyph doesn't fit on the line. */
3029 new_x
> it
->last_visible_x
3030 /* Or it fits exactly and we're on a window
3032 || (new_x
== it
->last_visible_x
3033 && FRAME_WINDOW_P (it
->f
)
3034 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3035 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3036 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3038 if ((it
->current
.dpvec_index
>= 0
3039 || it
->current
.overlay_string_index
>= 0)
3040 /* If we are on a newline from a display vector or
3041 overlay string, then we are already at the end of
3042 a screen line; no need to go to the next line in
3043 that case, as this line is not really continued.
3044 (If we do go to the next line, C-e will not DTRT.) */
3047 set_iterator_to_next (it
, 1);
3048 move_it_in_display_line_to (it
, -1, -1, 0);
3051 it
->continuation_lines_width
+= it
->current_x
;
3053 /* If the character at POS is displayed via a display
3054 vector, move_it_to above stops at the final glyph of
3055 IT->dpvec. To make the caller redisplay that character
3056 again (a.k.a. start at POS), we need to reset the
3057 dpvec_index to the beginning of IT->dpvec. */
3058 else if (it
->current
.dpvec_index
>= 0)
3059 it
->current
.dpvec_index
= 0;
3061 /* We're starting a new display line, not affected by the
3062 height of the continued line, so clear the appropriate
3063 fields in the iterator structure. */
3064 it
->max_ascent
= it
->max_descent
= 0;
3065 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3067 it
->current_y
= first_y
;
3069 it
->current_x
= it
->hpos
= 0;
3075 /* Return 1 if POS is a position in ellipses displayed for invisible
3076 text. W is the window we display, for text property lookup. */
3079 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3081 Lisp_Object prop
, window
;
3083 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3085 /* If POS specifies a position in a display vector, this might
3086 be for an ellipsis displayed for invisible text. We won't
3087 get the iterator set up for delivering that ellipsis unless
3088 we make sure that it gets aware of the invisible text. */
3089 if (pos
->dpvec_index
>= 0
3090 && pos
->overlay_string_index
< 0
3091 && CHARPOS (pos
->string_pos
) < 0
3093 && (XSETWINDOW (window
, w
),
3094 prop
= Fget_char_property (make_number (charpos
),
3095 Qinvisible
, window
),
3096 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3098 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3100 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3107 /* Initialize IT for stepping through current_buffer in window W,
3108 starting at position POS that includes overlay string and display
3109 vector/ control character translation position information. Value
3110 is zero if there are overlay strings with newlines at POS. */
3113 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3115 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3116 int i
, overlay_strings_with_newlines
= 0;
3118 /* If POS specifies a position in a display vector, this might
3119 be for an ellipsis displayed for invisible text. We won't
3120 get the iterator set up for delivering that ellipsis unless
3121 we make sure that it gets aware of the invisible text. */
3122 if (in_ellipses_for_invisible_text_p (pos
, w
))
3128 /* Keep in mind: the call to reseat in init_iterator skips invisible
3129 text, so we might end up at a position different from POS. This
3130 is only a problem when POS is a row start after a newline and an
3131 overlay starts there with an after-string, and the overlay has an
3132 invisible property. Since we don't skip invisible text in
3133 display_line and elsewhere immediately after consuming the
3134 newline before the row start, such a POS will not be in a string,
3135 but the call to init_iterator below will move us to the
3137 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3139 /* This only scans the current chunk -- it should scan all chunks.
3140 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3141 to 16 in 22.1 to make this a lesser problem. */
3142 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3144 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3145 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3147 while (s
< e
&& *s
!= '\n')
3152 overlay_strings_with_newlines
= 1;
3157 /* If position is within an overlay string, set up IT to the right
3159 if (pos
->overlay_string_index
>= 0)
3163 /* If the first overlay string happens to have a `display'
3164 property for an image, the iterator will be set up for that
3165 image, and we have to undo that setup first before we can
3166 correct the overlay string index. */
3167 if (it
->method
== GET_FROM_IMAGE
)
3170 /* We already have the first chunk of overlay strings in
3171 IT->overlay_strings. Load more until the one for
3172 pos->overlay_string_index is in IT->overlay_strings. */
3173 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3175 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3176 it
->current
.overlay_string_index
= 0;
3179 load_overlay_strings (it
, 0);
3180 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3184 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3185 relative_index
= (it
->current
.overlay_string_index
3186 % OVERLAY_STRING_CHUNK_SIZE
);
3187 it
->string
= it
->overlay_strings
[relative_index
];
3188 eassert (STRINGP (it
->string
));
3189 it
->current
.string_pos
= pos
->string_pos
;
3190 it
->method
= GET_FROM_STRING
;
3191 it
->end_charpos
= SCHARS (it
->string
);
3192 /* Set up the bidi iterator for this overlay string. */
3195 it
->bidi_it
.string
.lstring
= it
->string
;
3196 it
->bidi_it
.string
.s
= NULL
;
3197 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3198 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3199 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3200 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3201 it
->bidi_it
.w
= it
->w
;
3202 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3203 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3205 /* Synchronize the state of the bidi iterator with
3206 pos->string_pos. For any string position other than
3207 zero, this will be done automagically when we resume
3208 iteration over the string and get_visually_first_element
3209 is called. But if string_pos is zero, and the string is
3210 to be reordered for display, we need to resync manually,
3211 since it could be that the iteration state recorded in
3212 pos ended at string_pos of 0 moving backwards in string. */
3213 if (CHARPOS (pos
->string_pos
) == 0)
3215 get_visually_first_element (it
);
3216 if (IT_STRING_CHARPOS (*it
) != 0)
3219 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3220 bidi_move_to_visually_next (&it
->bidi_it
);
3221 } while (it
->bidi_it
.charpos
!= 0);
3223 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3224 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3228 if (CHARPOS (pos
->string_pos
) >= 0)
3230 /* Recorded position is not in an overlay string, but in another
3231 string. This can only be a string from a `display' property.
3232 IT should already be filled with that string. */
3233 it
->current
.string_pos
= pos
->string_pos
;
3234 eassert (STRINGP (it
->string
));
3236 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3237 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3240 /* Restore position in display vector translations, control
3241 character translations or ellipses. */
3242 if (pos
->dpvec_index
>= 0)
3244 if (it
->dpvec
== NULL
)
3245 get_next_display_element (it
);
3246 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3247 it
->current
.dpvec_index
= pos
->dpvec_index
;
3251 return !overlay_strings_with_newlines
;
3255 /* Initialize IT for stepping through current_buffer in window W
3256 starting at ROW->start. */
3259 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3261 init_from_display_pos (it
, w
, &row
->start
);
3262 it
->start
= row
->start
;
3263 it
->continuation_lines_width
= row
->continuation_lines_width
;
3268 /* Initialize IT for stepping through current_buffer in window W
3269 starting in the line following ROW, i.e. starting at ROW->end.
3270 Value is zero if there are overlay strings with newlines at ROW's
3274 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3278 if (init_from_display_pos (it
, w
, &row
->end
))
3280 if (row
->continued_p
)
3281 it
->continuation_lines_width
3282 = row
->continuation_lines_width
+ row
->pixel_width
;
3293 /***********************************************************************
3295 ***********************************************************************/
3297 /* Called when IT reaches IT->stop_charpos. Handle text property and
3298 overlay changes. Set IT->stop_charpos to the next position where
3302 handle_stop (struct it
*it
)
3304 enum prop_handled handled
;
3305 int handle_overlay_change_p
;
3309 it
->current
.dpvec_index
= -1;
3310 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3311 it
->ignore_overlay_strings_at_pos_p
= 0;
3314 /* Use face of preceding text for ellipsis (if invisible) */
3315 if (it
->selective_display_ellipsis_p
)
3316 it
->saved_face_id
= it
->face_id
;
3320 handled
= HANDLED_NORMALLY
;
3322 /* Call text property handlers. */
3323 for (p
= it_props
; p
->handler
; ++p
)
3325 handled
= p
->handler (it
);
3327 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3329 else if (handled
== HANDLED_RETURN
)
3331 /* We still want to show before and after strings from
3332 overlays even if the actual buffer text is replaced. */
3333 if (!handle_overlay_change_p
3335 /* Don't call get_overlay_strings_1 if we already
3336 have overlay strings loaded, because doing so
3337 will load them again and push the iterator state
3338 onto the stack one more time, which is not
3339 expected by the rest of the code that processes
3341 || (it
->current
.overlay_string_index
< 0
3342 ? !get_overlay_strings_1 (it
, 0, 0)
3346 setup_for_ellipsis (it
, 0);
3347 /* When handling a display spec, we might load an
3348 empty string. In that case, discard it here. We
3349 used to discard it in handle_single_display_spec,
3350 but that causes get_overlay_strings_1, above, to
3351 ignore overlay strings that we must check. */
3352 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3356 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3360 it
->ignore_overlay_strings_at_pos_p
= true;
3361 it
->string_from_display_prop_p
= 0;
3362 it
->from_disp_prop_p
= 0;
3363 handle_overlay_change_p
= 0;
3365 handled
= HANDLED_RECOMPUTE_PROPS
;
3368 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3369 handle_overlay_change_p
= 0;
3372 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3374 /* Don't check for overlay strings below when set to deliver
3375 characters from a display vector. */
3376 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3377 handle_overlay_change_p
= 0;
3379 /* Handle overlay changes.
3380 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3381 if it finds overlays. */
3382 if (handle_overlay_change_p
)
3383 handled
= handle_overlay_change (it
);
3388 setup_for_ellipsis (it
, 0);
3392 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3394 /* Determine where to stop next. */
3395 if (handled
== HANDLED_NORMALLY
)
3396 compute_stop_pos (it
);
3400 /* Compute IT->stop_charpos from text property and overlay change
3401 information for IT's current position. */
3404 compute_stop_pos (struct it
*it
)
3406 register INTERVAL iv
, next_iv
;
3407 Lisp_Object object
, limit
, position
;
3408 ptrdiff_t charpos
, bytepos
;
3410 if (STRINGP (it
->string
))
3412 /* Strings are usually short, so don't limit the search for
3414 it
->stop_charpos
= it
->end_charpos
;
3415 object
= it
->string
;
3417 charpos
= IT_STRING_CHARPOS (*it
);
3418 bytepos
= IT_STRING_BYTEPOS (*it
);
3424 /* If end_charpos is out of range for some reason, such as a
3425 misbehaving display function, rationalize it (Bug#5984). */
3426 if (it
->end_charpos
> ZV
)
3427 it
->end_charpos
= ZV
;
3428 it
->stop_charpos
= it
->end_charpos
;
3430 /* If next overlay change is in front of the current stop pos
3431 (which is IT->end_charpos), stop there. Note: value of
3432 next_overlay_change is point-max if no overlay change
3434 charpos
= IT_CHARPOS (*it
);
3435 bytepos
= IT_BYTEPOS (*it
);
3436 pos
= next_overlay_change (charpos
);
3437 if (pos
< it
->stop_charpos
)
3438 it
->stop_charpos
= pos
;
3440 /* Set up variables for computing the stop position from text
3441 property changes. */
3442 XSETBUFFER (object
, current_buffer
);
3443 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3446 /* Get the interval containing IT's position. Value is a null
3447 interval if there isn't such an interval. */
3448 position
= make_number (charpos
);
3449 iv
= validate_interval_range (object
, &position
, &position
, 0);
3452 Lisp_Object values_here
[LAST_PROP_IDX
];
3455 /* Get properties here. */
3456 for (p
= it_props
; p
->handler
; ++p
)
3457 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3459 /* Look for an interval following iv that has different
3461 for (next_iv
= next_interval (iv
);
3464 || XFASTINT (limit
) > next_iv
->position
));
3465 next_iv
= next_interval (next_iv
))
3467 for (p
= it_props
; p
->handler
; ++p
)
3469 Lisp_Object new_value
;
3471 new_value
= textget (next_iv
->plist
, *p
->name
);
3472 if (!EQ (values_here
[p
->idx
], new_value
))
3482 if (INTEGERP (limit
)
3483 && next_iv
->position
>= XFASTINT (limit
))
3484 /* No text property change up to limit. */
3485 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3487 /* Text properties change in next_iv. */
3488 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3492 if (it
->cmp_it
.id
< 0)
3494 ptrdiff_t stoppos
= it
->end_charpos
;
3496 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3498 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3499 stoppos
, it
->string
);
3502 eassert (STRINGP (it
->string
)
3503 || (it
->stop_charpos
>= BEGV
3504 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3508 /* Return the position of the next overlay change after POS in
3509 current_buffer. Value is point-max if no overlay change
3510 follows. This is like `next-overlay-change' but doesn't use
3514 next_overlay_change (ptrdiff_t pos
)
3516 ptrdiff_t i
, noverlays
;
3518 Lisp_Object
*overlays
;
3520 /* Get all overlays at the given position. */
3521 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3523 /* If any of these overlays ends before endpos,
3524 use its ending point instead. */
3525 for (i
= 0; i
< noverlays
; ++i
)
3530 oend
= OVERLAY_END (overlays
[i
]);
3531 oendpos
= OVERLAY_POSITION (oend
);
3532 endpos
= min (endpos
, oendpos
);
3538 /* How many characters forward to search for a display property or
3539 display string. Searching too far forward makes the bidi display
3540 sluggish, especially in small windows. */
3541 #define MAX_DISP_SCAN 250
3543 /* Return the character position of a display string at or after
3544 position specified by POSITION. If no display string exists at or
3545 after POSITION, return ZV. A display string is either an overlay
3546 with `display' property whose value is a string, or a `display'
3547 text property whose value is a string. STRING is data about the
3548 string to iterate; if STRING->lstring is nil, we are iterating a
3549 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3550 on a GUI frame. DISP_PROP is set to zero if we searched
3551 MAX_DISP_SCAN characters forward without finding any display
3552 strings, non-zero otherwise. It is set to 2 if the display string
3553 uses any kind of `(space ...)' spec that will produce a stretch of
3554 white space in the text area. */
3556 compute_display_string_pos (struct text_pos
*position
,
3557 struct bidi_string_data
*string
,
3559 int frame_window_p
, int *disp_prop
)
3561 /* OBJECT = nil means current buffer. */
3562 Lisp_Object object
, object1
;
3563 Lisp_Object pos
, spec
, limpos
;
3564 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3565 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3566 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3567 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3569 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3570 struct text_pos tpos
;
3573 if (string
&& STRINGP (string
->lstring
))
3574 object1
= object
= string
->lstring
;
3575 else if (w
&& !string_p
)
3577 XSETWINDOW (object
, w
);
3581 object1
= object
= Qnil
;
3586 /* We don't support display properties whose values are strings
3587 that have display string properties. */
3588 || string
->from_disp_str
3589 /* C strings cannot have display properties. */
3590 || (string
->s
&& !STRINGP (object
)))
3596 /* If the character at CHARPOS is where the display string begins,
3598 pos
= make_number (charpos
);
3599 if (STRINGP (object
))
3600 bufpos
= string
->bufpos
;
3604 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3606 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3609 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3617 /* Look forward for the first character with a `display' property
3618 that will replace the underlying text when displayed. */
3619 limpos
= make_number (lim
);
3621 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3622 CHARPOS (tpos
) = XFASTINT (pos
);
3623 if (CHARPOS (tpos
) >= lim
)
3628 if (STRINGP (object
))
3629 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3631 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3632 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3633 if (!STRINGP (object
))
3634 bufpos
= CHARPOS (tpos
);
3635 } while (NILP (spec
)
3636 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3637 bufpos
, frame_window_p
)));
3641 return CHARPOS (tpos
);
3644 /* Return the character position of the end of the display string that
3645 started at CHARPOS. If there's no display string at CHARPOS,
3646 return -1. A display string is either an overlay with `display'
3647 property whose value is a string or a `display' text property whose
3648 value is a string. */
3650 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3652 /* OBJECT = nil means current buffer. */
3653 Lisp_Object object
=
3654 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3655 Lisp_Object pos
= make_number (charpos
);
3657 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3659 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3662 /* It could happen that the display property or overlay was removed
3663 since we found it in compute_display_string_pos above. One way
3664 this can happen is if JIT font-lock was called (through
3665 handle_fontified_prop), and jit-lock-functions remove text
3666 properties or overlays from the portion of buffer that includes
3667 CHARPOS. Muse mode is known to do that, for example. In this
3668 case, we return -1 to the caller, to signal that no display
3669 string is actually present at CHARPOS. See bidi_fetch_char for
3670 how this is handled.
3672 An alternative would be to never look for display properties past
3673 it->stop_charpos. But neither compute_display_string_pos nor
3674 bidi_fetch_char that calls it know or care where the next
3676 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3679 /* Look forward for the first character where the `display' property
3681 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3683 return XFASTINT (pos
);
3688 /***********************************************************************
3690 ***********************************************************************/
3692 /* Handle changes in the `fontified' property of the current buffer by
3693 calling hook functions from Qfontification_functions to fontify
3696 static enum prop_handled
3697 handle_fontified_prop (struct it
*it
)
3699 Lisp_Object prop
, pos
;
3700 enum prop_handled handled
= HANDLED_NORMALLY
;
3702 if (!NILP (Vmemory_full
))
3705 /* Get the value of the `fontified' property at IT's current buffer
3706 position. (The `fontified' property doesn't have a special
3707 meaning in strings.) If the value is nil, call functions from
3708 Qfontification_functions. */
3709 if (!STRINGP (it
->string
)
3711 && !NILP (Vfontification_functions
)
3712 && !NILP (Vrun_hooks
)
3713 && (pos
= make_number (IT_CHARPOS (*it
)),
3714 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3715 /* Ignore the special cased nil value always present at EOB since
3716 no amount of fontifying will be able to change it. */
3717 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3719 ptrdiff_t count
= SPECPDL_INDEX ();
3721 struct buffer
*obuf
= current_buffer
;
3722 ptrdiff_t begv
= BEGV
, zv
= ZV
;
3723 bool old_clip_changed
= current_buffer
->clip_changed
;
3725 val
= Vfontification_functions
;
3726 specbind (Qfontification_functions
, Qnil
);
3728 eassert (it
->end_charpos
== ZV
);
3730 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3731 safe_call1 (val
, pos
);
3734 Lisp_Object fns
, fn
;
3735 struct gcpro gcpro1
, gcpro2
;
3740 for (; CONSP (val
); val
= XCDR (val
))
3746 /* A value of t indicates this hook has a local
3747 binding; it means to run the global binding too.
3748 In a global value, t should not occur. If it
3749 does, we must ignore it to avoid an endless
3751 for (fns
= Fdefault_value (Qfontification_functions
);
3757 safe_call1 (fn
, pos
);
3761 safe_call1 (fn
, pos
);
3767 unbind_to (count
, Qnil
);
3769 /* Fontification functions routinely call `save-restriction'.
3770 Normally, this tags clip_changed, which can confuse redisplay
3771 (see discussion in Bug#6671). Since we don't perform any
3772 special handling of fontification changes in the case where
3773 `save-restriction' isn't called, there's no point doing so in
3774 this case either. So, if the buffer's restrictions are
3775 actually left unchanged, reset clip_changed. */
3776 if (obuf
== current_buffer
)
3778 if (begv
== BEGV
&& zv
== ZV
)
3779 current_buffer
->clip_changed
= old_clip_changed
;
3781 /* There isn't much we can reasonably do to protect against
3782 misbehaving fontification, but here's a fig leaf. */
3783 else if (BUFFER_LIVE_P (obuf
))
3784 set_buffer_internal_1 (obuf
);
3786 /* The fontification code may have added/removed text.
3787 It could do even a lot worse, but let's at least protect against
3788 the most obvious case where only the text past `pos' gets changed',
3789 as is/was done in grep.el where some escapes sequences are turned
3790 into face properties (bug#7876). */
3791 it
->end_charpos
= ZV
;
3793 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3794 something. This avoids an endless loop if they failed to
3795 fontify the text for which reason ever. */
3796 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3797 handled
= HANDLED_RECOMPUTE_PROPS
;
3805 /***********************************************************************
3807 ***********************************************************************/
3809 /* Set up iterator IT from face properties at its current position.
3810 Called from handle_stop. */
3812 static enum prop_handled
3813 handle_face_prop (struct it
*it
)
3816 ptrdiff_t next_stop
;
3818 if (!STRINGP (it
->string
))
3821 = face_at_buffer_position (it
->w
,
3825 + TEXT_PROP_DISTANCE_LIMIT
),
3826 0, it
->base_face_id
);
3828 /* Is this a start of a run of characters with box face?
3829 Caveat: this can be called for a freshly initialized
3830 iterator; face_id is -1 in this case. We know that the new
3831 face will not change until limit, i.e. if the new face has a
3832 box, all characters up to limit will have one. But, as
3833 usual, we don't know whether limit is really the end. */
3834 if (new_face_id
!= it
->face_id
)
3836 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3837 /* If it->face_id is -1, old_face below will be NULL, see
3838 the definition of FACE_FROM_ID. This will happen if this
3839 is the initial call that gets the face. */
3840 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3842 /* If the value of face_id of the iterator is -1, we have to
3843 look in front of IT's position and see whether there is a
3844 face there that's different from new_face_id. */
3845 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3847 int prev_face_id
= face_before_it_pos (it
);
3849 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3852 /* If the new face has a box, but the old face does not,
3853 this is the start of a run of characters with box face,
3854 i.e. this character has a shadow on the left side. */
3855 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3856 && (old_face
== NULL
|| !old_face
->box
));
3857 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3865 Lisp_Object from_overlay
3866 = (it
->current
.overlay_string_index
>= 0
3867 ? it
->string_overlays
[it
->current
.overlay_string_index
3868 % OVERLAY_STRING_CHUNK_SIZE
]
3871 /* See if we got to this string directly or indirectly from
3872 an overlay property. That includes the before-string or
3873 after-string of an overlay, strings in display properties
3874 provided by an overlay, their text properties, etc.
3876 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3877 if (! NILP (from_overlay
))
3878 for (i
= it
->sp
- 1; i
>= 0; i
--)
3880 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3882 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3883 % OVERLAY_STRING_CHUNK_SIZE
];
3884 else if (! NILP (it
->stack
[i
].from_overlay
))
3885 from_overlay
= it
->stack
[i
].from_overlay
;
3887 if (!NILP (from_overlay
))
3891 if (! NILP (from_overlay
))
3893 bufpos
= IT_CHARPOS (*it
);
3894 /* For a string from an overlay, the base face depends
3895 only on text properties and ignores overlays. */
3897 = face_for_overlay_string (it
->w
,
3901 + TEXT_PROP_DISTANCE_LIMIT
),
3909 /* For strings from a `display' property, use the face at
3910 IT's current buffer position as the base face to merge
3911 with, so that overlay strings appear in the same face as
3912 surrounding text, unless they specify their own faces.
3913 For strings from wrap-prefix and line-prefix properties,
3914 use the default face, possibly remapped via
3915 Vface_remapping_alist. */
3916 base_face_id
= it
->string_from_prefix_prop_p
3917 ? (!NILP (Vface_remapping_alist
)
3918 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3920 : underlying_face_id (it
);
3923 new_face_id
= face_at_string_position (it
->w
,
3925 IT_STRING_CHARPOS (*it
),
3930 /* Is this a start of a run of characters with box? Caveat:
3931 this can be called for a freshly allocated iterator; face_id
3932 is -1 is this case. We know that the new face will not
3933 change until the next check pos, i.e. if the new face has a
3934 box, all characters up to that position will have a
3935 box. But, as usual, we don't know whether that position
3936 is really the end. */
3937 if (new_face_id
!= it
->face_id
)
3939 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3940 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3942 /* If new face has a box but old face hasn't, this is the
3943 start of a run of characters with box, i.e. it has a
3944 shadow on the left side. */
3945 it
->start_of_box_run_p
3946 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3947 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3951 it
->face_id
= new_face_id
;
3952 return HANDLED_NORMALLY
;
3956 /* Return the ID of the face ``underlying'' IT's current position,
3957 which is in a string. If the iterator is associated with a
3958 buffer, return the face at IT's current buffer position.
3959 Otherwise, use the iterator's base_face_id. */
3962 underlying_face_id (struct it
*it
)
3964 int face_id
= it
->base_face_id
, i
;
3966 eassert (STRINGP (it
->string
));
3968 for (i
= it
->sp
- 1; i
>= 0; --i
)
3969 if (NILP (it
->stack
[i
].string
))
3970 face_id
= it
->stack
[i
].face_id
;
3976 /* Compute the face one character before or after the current position
3977 of IT, in the visual order. BEFORE_P non-zero means get the face
3978 in front (to the left in L2R paragraphs, to the right in R2L
3979 paragraphs) of IT's screen position. Value is the ID of the face. */
3982 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3985 ptrdiff_t next_check_charpos
;
3987 void *it_copy_data
= NULL
;
3989 eassert (it
->s
== NULL
);
3991 if (STRINGP (it
->string
))
3993 ptrdiff_t bufpos
, charpos
;
3996 /* No face change past the end of the string (for the case
3997 we are padding with spaces). No face change before the
3999 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
4000 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4005 /* Set charpos to the position before or after IT's current
4006 position, in the logical order, which in the non-bidi
4007 case is the same as the visual order. */
4009 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4010 else if (it
->what
== IT_COMPOSITION
)
4011 /* For composition, we must check the character after the
4013 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4015 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4021 /* With bidi iteration, the character before the current
4022 in the visual order cannot be found by simple
4023 iteration, because "reverse" reordering is not
4024 supported. Instead, we need to use the move_it_*
4025 family of functions. */
4026 /* Ignore face changes before the first visible
4027 character on this display line. */
4028 if (it
->current_x
<= it
->first_visible_x
)
4030 SAVE_IT (it_copy
, *it
, it_copy_data
);
4031 /* Implementation note: Since move_it_in_display_line
4032 works in the iterator geometry, and thinks the first
4033 character is always the leftmost, even in R2L lines,
4034 we don't need to distinguish between the R2L and L2R
4036 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4037 it_copy
.current_x
- 1, MOVE_TO_X
);
4038 charpos
= IT_STRING_CHARPOS (it_copy
);
4039 RESTORE_IT (it
, it
, it_copy_data
);
4043 /* Set charpos to the string position of the character
4044 that comes after IT's current position in the visual
4046 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4050 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4052 charpos
= it_copy
.bidi_it
.charpos
;
4055 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4057 if (it
->current
.overlay_string_index
>= 0)
4058 bufpos
= IT_CHARPOS (*it
);
4062 base_face_id
= underlying_face_id (it
);
4064 /* Get the face for ASCII, or unibyte. */
4065 face_id
= face_at_string_position (it
->w
,
4069 &next_check_charpos
,
4072 /* Correct the face for charsets different from ASCII. Do it
4073 for the multibyte case only. The face returned above is
4074 suitable for unibyte text if IT->string is unibyte. */
4075 if (STRING_MULTIBYTE (it
->string
))
4077 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4078 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4080 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4082 c
= string_char_and_length (p
, &len
);
4083 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4088 struct text_pos pos
;
4090 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4091 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4094 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4095 pos
= it
->current
.pos
;
4100 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4103 if (it
->what
== IT_COMPOSITION
)
4105 /* For composition, we must check the position after
4107 pos
.charpos
+= it
->cmp_it
.nchars
;
4108 pos
.bytepos
+= it
->len
;
4111 INC_TEXT_POS (pos
, it
->multibyte_p
);
4118 /* With bidi iteration, the character before the current
4119 in the visual order cannot be found by simple
4120 iteration, because "reverse" reordering is not
4121 supported. Instead, we need to use the move_it_*
4122 family of functions. */
4123 /* Ignore face changes before the first visible
4124 character on this display line. */
4125 if (it
->current_x
<= it
->first_visible_x
)
4127 SAVE_IT (it_copy
, *it
, it_copy_data
);
4128 /* Implementation note: Since move_it_in_display_line
4129 works in the iterator geometry, and thinks the first
4130 character is always the leftmost, even in R2L lines,
4131 we don't need to distinguish between the R2L and L2R
4133 move_it_in_display_line (&it_copy
, ZV
,
4134 it_copy
.current_x
- 1, MOVE_TO_X
);
4135 pos
= it_copy
.current
.pos
;
4136 RESTORE_IT (it
, it
, it_copy_data
);
4140 /* Set charpos to the buffer position of the character
4141 that comes after IT's current position in the visual
4143 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4147 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4150 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4153 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4155 /* Determine face for CHARSET_ASCII, or unibyte. */
4156 face_id
= face_at_buffer_position (it
->w
,
4158 &next_check_charpos
,
4161 /* Correct the face for charsets different from ASCII. Do it
4162 for the multibyte case only. The face returned above is
4163 suitable for unibyte text if current_buffer is unibyte. */
4164 if (it
->multibyte_p
)
4166 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4167 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4168 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4177 /***********************************************************************
4179 ***********************************************************************/
4181 /* Set up iterator IT from invisible properties at its current
4182 position. Called from handle_stop. */
4184 static enum prop_handled
4185 handle_invisible_prop (struct it
*it
)
4187 enum prop_handled handled
= HANDLED_NORMALLY
;
4191 if (STRINGP (it
->string
))
4193 Lisp_Object end_charpos
, limit
, charpos
;
4195 /* Get the value of the invisible text property at the
4196 current position. Value will be nil if there is no such
4198 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4199 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4200 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4202 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4204 /* Record whether we have to display an ellipsis for the
4206 int display_ellipsis_p
= (invis_p
== 2);
4207 ptrdiff_t len
, endpos
;
4209 handled
= HANDLED_RECOMPUTE_PROPS
;
4211 /* Get the position at which the next visible text can be
4212 found in IT->string, if any. */
4213 endpos
= len
= SCHARS (it
->string
);
4214 XSETINT (limit
, len
);
4217 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4219 if (INTEGERP (end_charpos
))
4221 endpos
= XFASTINT (end_charpos
);
4222 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4223 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4225 display_ellipsis_p
= true;
4228 while (invis_p
&& endpos
< len
);
4230 if (display_ellipsis_p
)
4231 it
->ellipsis_p
= true;
4235 /* Text at END_CHARPOS is visible. Move IT there. */
4236 struct text_pos old
;
4239 old
= it
->current
.string_pos
;
4240 oldpos
= CHARPOS (old
);
4243 if (it
->bidi_it
.first_elt
4244 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4245 bidi_paragraph_init (it
->paragraph_embedding
,
4247 /* Bidi-iterate out of the invisible text. */
4250 bidi_move_to_visually_next (&it
->bidi_it
);
4252 while (oldpos
<= it
->bidi_it
.charpos
4253 && it
->bidi_it
.charpos
< endpos
);
4255 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4256 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4257 if (IT_CHARPOS (*it
) >= endpos
)
4258 it
->prev_stop
= endpos
;
4262 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4263 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4268 /* The rest of the string is invisible. If this is an
4269 overlay string, proceed with the next overlay string
4270 or whatever comes and return a character from there. */
4271 if (it
->current
.overlay_string_index
>= 0
4272 && !display_ellipsis_p
)
4274 next_overlay_string (it
);
4275 /* Don't check for overlay strings when we just
4276 finished processing them. */
4277 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4281 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4282 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4289 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4290 Lisp_Object pos
, overlay
;
4292 /* First of all, is there invisible text at this position? */
4293 tem
= start_charpos
= IT_CHARPOS (*it
);
4294 pos
= make_number (tem
);
4295 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4297 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4299 /* If we are on invisible text, skip over it. */
4300 if (invis_p
&& start_charpos
< it
->end_charpos
)
4302 /* Record whether we have to display an ellipsis for the
4304 int display_ellipsis_p
= invis_p
== 2;
4306 handled
= HANDLED_RECOMPUTE_PROPS
;
4308 /* Loop skipping over invisible text. The loop is left at
4309 ZV or with IT on the first char being visible again. */
4312 /* Try to skip some invisible text. Return value is the
4313 position reached which can be equal to where we start
4314 if there is nothing invisible there. This skips both
4315 over invisible text properties and overlays with
4316 invisible property. */
4317 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4319 /* If we skipped nothing at all we weren't at invisible
4320 text in the first place. If everything to the end of
4321 the buffer was skipped, end the loop. */
4322 if (newpos
== tem
|| newpos
>= ZV
)
4326 /* We skipped some characters but not necessarily
4327 all there are. Check if we ended up on visible
4328 text. Fget_char_property returns the property of
4329 the char before the given position, i.e. if we
4330 get invis_p = 0, this means that the char at
4331 newpos is visible. */
4332 pos
= make_number (newpos
);
4333 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4334 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4337 /* If we ended up on invisible text, proceed to
4338 skip starting with next_stop. */
4342 /* If there are adjacent invisible texts, don't lose the
4343 second one's ellipsis. */
4345 display_ellipsis_p
= true;
4349 /* The position newpos is now either ZV or on visible text. */
4352 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4354 = bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4356 = newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4358 /* If the invisible text ends on a newline or on a
4359 character after a newline, we can avoid the costly,
4360 character by character, bidi iteration to NEWPOS, and
4361 instead simply reseat the iterator there. That's
4362 because all bidi reordering information is tossed at
4363 the newline. This is a big win for modes that hide
4364 complete lines, like Outline, Org, etc. */
4365 if (on_newline
|| after_newline
)
4367 struct text_pos tpos
;
4368 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4370 SET_TEXT_POS (tpos
, newpos
, bpos
);
4371 reseat_1 (it
, tpos
, 0);
4372 /* If we reseat on a newline/ZV, we need to prep the
4373 bidi iterator for advancing to the next character
4374 after the newline/EOB, keeping the current paragraph
4375 direction (so that PRODUCE_GLYPHS does TRT wrt
4376 prepending/appending glyphs to a glyph row). */
4379 it
->bidi_it
.first_elt
= 0;
4380 it
->bidi_it
.paragraph_dir
= pdir
;
4381 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4382 it
->bidi_it
.nchars
= 1;
4383 it
->bidi_it
.ch_len
= 1;
4386 else /* Must use the slow method. */
4388 /* With bidi iteration, the region of invisible text
4389 could start and/or end in the middle of a
4390 non-base embedding level. Therefore, we need to
4391 skip invisible text using the bidi iterator,
4392 starting at IT's current position, until we find
4393 ourselves outside of the invisible text.
4394 Skipping invisible text _after_ bidi iteration
4395 avoids affecting the visual order of the
4396 displayed text when invisible properties are
4397 added or removed. */
4398 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4400 /* If we were `reseat'ed to a new paragraph,
4401 determine the paragraph base direction. We
4402 need to do it now because
4403 next_element_from_buffer may not have a
4404 chance to do it, if we are going to skip any
4405 text at the beginning, which resets the
4407 bidi_paragraph_init (it
->paragraph_embedding
,
4412 bidi_move_to_visually_next (&it
->bidi_it
);
4414 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4415 && it
->bidi_it
.charpos
< newpos
);
4416 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4417 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4418 /* If we overstepped NEWPOS, record its position in
4419 the iterator, so that we skip invisible text if
4420 later the bidi iteration lands us in the
4421 invisible region again. */
4422 if (IT_CHARPOS (*it
) >= newpos
)
4423 it
->prev_stop
= newpos
;
4428 IT_CHARPOS (*it
) = newpos
;
4429 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4432 /* If there are before-strings at the start of invisible
4433 text, and the text is invisible because of a text
4434 property, arrange to show before-strings because 20.x did
4435 it that way. (If the text is invisible because of an
4436 overlay property instead of a text property, this is
4437 already handled in the overlay code.) */
4439 && get_overlay_strings (it
, it
->stop_charpos
))
4441 handled
= HANDLED_RECOMPUTE_PROPS
;
4442 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4444 else if (display_ellipsis_p
)
4446 /* Make sure that the glyphs of the ellipsis will get
4447 correct `charpos' values. If we would not update
4448 it->position here, the glyphs would belong to the
4449 last visible character _before_ the invisible
4450 text, which confuses `set_cursor_from_row'.
4452 We use the last invisible position instead of the
4453 first because this way the cursor is always drawn on
4454 the first "." of the ellipsis, whenever PT is inside
4455 the invisible text. Otherwise the cursor would be
4456 placed _after_ the ellipsis when the point is after the
4457 first invisible character. */
4458 if (!STRINGP (it
->object
))
4460 it
->position
.charpos
= newpos
- 1;
4461 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4463 it
->ellipsis_p
= true;
4464 /* Let the ellipsis display before
4465 considering any properties of the following char.
4466 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4467 handled
= HANDLED_RETURN
;
4476 /* Make iterator IT return `...' next.
4477 Replaces LEN characters from buffer. */
4480 setup_for_ellipsis (struct it
*it
, int len
)
4482 /* Use the display table definition for `...'. Invalid glyphs
4483 will be handled by the method returning elements from dpvec. */
4484 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4486 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4487 it
->dpvec
= v
->contents
;
4488 it
->dpend
= v
->contents
+ v
->header
.size
;
4492 /* Default `...'. */
4493 it
->dpvec
= default_invis_vector
;
4494 it
->dpend
= default_invis_vector
+ 3;
4497 it
->dpvec_char_len
= len
;
4498 it
->current
.dpvec_index
= 0;
4499 it
->dpvec_face_id
= -1;
4501 /* Remember the current face id in case glyphs specify faces.
4502 IT's face is restored in set_iterator_to_next.
4503 saved_face_id was set to preceding char's face in handle_stop. */
4504 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4505 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4507 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4508 it
->ellipsis_p
= true;
4513 /***********************************************************************
4515 ***********************************************************************/
4517 /* Set up iterator IT from `display' property at its current position.
4518 Called from handle_stop.
4519 We return HANDLED_RETURN if some part of the display property
4520 overrides the display of the buffer text itself.
4521 Otherwise we return HANDLED_NORMALLY. */
4523 static enum prop_handled
4524 handle_display_prop (struct it
*it
)
4526 Lisp_Object propval
, object
, overlay
;
4527 struct text_pos
*position
;
4529 /* Nonzero if some property replaces the display of the text itself. */
4530 int display_replaced_p
= 0;
4532 if (STRINGP (it
->string
))
4534 object
= it
->string
;
4535 position
= &it
->current
.string_pos
;
4536 bufpos
= CHARPOS (it
->current
.pos
);
4540 XSETWINDOW (object
, it
->w
);
4541 position
= &it
->current
.pos
;
4542 bufpos
= CHARPOS (*position
);
4545 /* Reset those iterator values set from display property values. */
4546 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4547 it
->space_width
= Qnil
;
4548 it
->font_height
= Qnil
;
4551 /* We don't support recursive `display' properties, i.e. string
4552 values that have a string `display' property, that have a string
4553 `display' property etc. */
4554 if (!it
->string_from_display_prop_p
)
4555 it
->area
= TEXT_AREA
;
4557 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4558 Qdisplay
, object
, &overlay
);
4560 return HANDLED_NORMALLY
;
4561 /* Now OVERLAY is the overlay that gave us this property, or nil
4562 if it was a text property. */
4564 if (!STRINGP (it
->string
))
4565 object
= it
->w
->contents
;
4567 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4569 FRAME_WINDOW_P (it
->f
));
4571 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4574 /* Subroutine of handle_display_prop. Returns non-zero if the display
4575 specification in SPEC is a replacing specification, i.e. it would
4576 replace the text covered by `display' property with something else,
4577 such as an image or a display string. If SPEC includes any kind or
4578 `(space ...) specification, the value is 2; this is used by
4579 compute_display_string_pos, which see.
4581 See handle_single_display_spec for documentation of arguments.
4582 frame_window_p is non-zero if the window being redisplayed is on a
4583 GUI frame; this argument is used only if IT is NULL, see below.
4585 IT can be NULL, if this is called by the bidi reordering code
4586 through compute_display_string_pos, which see. In that case, this
4587 function only examines SPEC, but does not otherwise "handle" it, in
4588 the sense that it doesn't set up members of IT from the display
4591 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4592 Lisp_Object overlay
, struct text_pos
*position
,
4593 ptrdiff_t bufpos
, int frame_window_p
)
4595 int replacing_p
= 0;
4599 /* Simple specifications. */
4600 && !EQ (XCAR (spec
), Qimage
)
4601 && !EQ (XCAR (spec
), Qspace
)
4602 && !EQ (XCAR (spec
), Qwhen
)
4603 && !EQ (XCAR (spec
), Qslice
)
4604 && !EQ (XCAR (spec
), Qspace_width
)
4605 && !EQ (XCAR (spec
), Qheight
)
4606 && !EQ (XCAR (spec
), Qraise
)
4607 /* Marginal area specifications. */
4608 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4609 && !EQ (XCAR (spec
), Qleft_fringe
)
4610 && !EQ (XCAR (spec
), Qright_fringe
)
4611 && !NILP (XCAR (spec
)))
4613 for (; CONSP (spec
); spec
= XCDR (spec
))
4615 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4616 overlay
, position
, bufpos
,
4617 replacing_p
, frame_window_p
)))
4620 /* If some text in a string is replaced, `position' no
4621 longer points to the position of `object'. */
4622 if (!it
|| STRINGP (object
))
4627 else if (VECTORP (spec
))
4630 for (i
= 0; i
< ASIZE (spec
); ++i
)
4631 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4632 overlay
, position
, bufpos
,
4633 replacing_p
, frame_window_p
)))
4636 /* If some text in a string is replaced, `position' no
4637 longer points to the position of `object'. */
4638 if (!it
|| STRINGP (object
))
4644 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4645 position
, bufpos
, 0,
4653 /* Value is the position of the end of the `display' property starting
4654 at START_POS in OBJECT. */
4656 static struct text_pos
4657 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4660 struct text_pos end_pos
;
4662 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4663 Qdisplay
, object
, Qnil
);
4664 CHARPOS (end_pos
) = XFASTINT (end
);
4665 if (STRINGP (object
))
4666 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4668 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4674 /* Set up IT from a single `display' property specification SPEC. OBJECT
4675 is the object in which the `display' property was found. *POSITION
4676 is the position in OBJECT at which the `display' property was found.
4677 BUFPOS is the buffer position of OBJECT (different from POSITION if
4678 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4679 previously saw a display specification which already replaced text
4680 display with something else, for example an image; we ignore such
4681 properties after the first one has been processed.
4683 OVERLAY is the overlay this `display' property came from,
4684 or nil if it was a text property.
4686 If SPEC is a `space' or `image' specification, and in some other
4687 cases too, set *POSITION to the position where the `display'
4690 If IT is NULL, only examine the property specification in SPEC, but
4691 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4692 is intended to be displayed in a window on a GUI frame.
4694 Value is non-zero if something was found which replaces the display
4695 of buffer or string text. */
4698 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4699 Lisp_Object overlay
, struct text_pos
*position
,
4700 ptrdiff_t bufpos
, int display_replaced_p
,
4704 Lisp_Object location
, value
;
4705 struct text_pos start_pos
= *position
;
4708 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4709 If the result is non-nil, use VALUE instead of SPEC. */
4711 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4720 if (!NILP (form
) && !EQ (form
, Qt
))
4722 ptrdiff_t count
= SPECPDL_INDEX ();
4723 struct gcpro gcpro1
;
4725 /* Bind `object' to the object having the `display' property, a
4726 buffer or string. Bind `position' to the position in the
4727 object where the property was found, and `buffer-position'
4728 to the current position in the buffer. */
4731 XSETBUFFER (object
, current_buffer
);
4732 specbind (Qobject
, object
);
4733 specbind (Qposition
, make_number (CHARPOS (*position
)));
4734 specbind (Qbuffer_position
, make_number (bufpos
));
4736 form
= safe_eval (form
);
4738 unbind_to (count
, Qnil
);
4744 /* Handle `(height HEIGHT)' specifications. */
4746 && EQ (XCAR (spec
), Qheight
)
4747 && CONSP (XCDR (spec
)))
4751 if (!FRAME_WINDOW_P (it
->f
))
4754 it
->font_height
= XCAR (XCDR (spec
));
4755 if (!NILP (it
->font_height
))
4757 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4758 int new_height
= -1;
4760 if (CONSP (it
->font_height
)
4761 && (EQ (XCAR (it
->font_height
), Qplus
)
4762 || EQ (XCAR (it
->font_height
), Qminus
))
4763 && CONSP (XCDR (it
->font_height
))
4764 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4766 /* `(+ N)' or `(- N)' where N is an integer. */
4767 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4768 if (EQ (XCAR (it
->font_height
), Qplus
))
4770 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4772 else if (FUNCTIONP (it
->font_height
))
4774 /* Call function with current height as argument.
4775 Value is the new height. */
4777 height
= safe_call1 (it
->font_height
,
4778 face
->lface
[LFACE_HEIGHT_INDEX
]);
4779 if (NUMBERP (height
))
4780 new_height
= XFLOATINT (height
);
4782 else if (NUMBERP (it
->font_height
))
4784 /* Value is a multiple of the canonical char height. */
4787 f
= FACE_FROM_ID (it
->f
,
4788 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4789 new_height
= (XFLOATINT (it
->font_height
)
4790 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4794 /* Evaluate IT->font_height with `height' bound to the
4795 current specified height to get the new height. */
4796 ptrdiff_t count
= SPECPDL_INDEX ();
4798 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4799 value
= safe_eval (it
->font_height
);
4800 unbind_to (count
, Qnil
);
4802 if (NUMBERP (value
))
4803 new_height
= XFLOATINT (value
);
4807 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4814 /* Handle `(space-width WIDTH)'. */
4816 && EQ (XCAR (spec
), Qspace_width
)
4817 && CONSP (XCDR (spec
)))
4821 if (!FRAME_WINDOW_P (it
->f
))
4824 value
= XCAR (XCDR (spec
));
4825 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4826 it
->space_width
= value
;
4832 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4834 && EQ (XCAR (spec
), Qslice
))
4840 if (!FRAME_WINDOW_P (it
->f
))
4843 if (tem
= XCDR (spec
), CONSP (tem
))
4845 it
->slice
.x
= XCAR (tem
);
4846 if (tem
= XCDR (tem
), CONSP (tem
))
4848 it
->slice
.y
= XCAR (tem
);
4849 if (tem
= XCDR (tem
), CONSP (tem
))
4851 it
->slice
.width
= XCAR (tem
);
4852 if (tem
= XCDR (tem
), CONSP (tem
))
4853 it
->slice
.height
= XCAR (tem
);
4862 /* Handle `(raise FACTOR)'. */
4864 && EQ (XCAR (spec
), Qraise
)
4865 && CONSP (XCDR (spec
)))
4869 if (!FRAME_WINDOW_P (it
->f
))
4872 #ifdef HAVE_WINDOW_SYSTEM
4873 value
= XCAR (XCDR (spec
));
4874 if (NUMBERP (value
))
4876 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4877 it
->voffset
= - (XFLOATINT (value
)
4878 * (FONT_HEIGHT (face
->font
)));
4880 #endif /* HAVE_WINDOW_SYSTEM */
4886 /* Don't handle the other kinds of display specifications
4887 inside a string that we got from a `display' property. */
4888 if (it
&& it
->string_from_display_prop_p
)
4891 /* Characters having this form of property are not displayed, so
4892 we have to find the end of the property. */
4895 start_pos
= *position
;
4896 *position
= display_prop_end (it
, object
, start_pos
);
4900 /* Stop the scan at that end position--we assume that all
4901 text properties change there. */
4903 it
->stop_charpos
= position
->charpos
;
4905 /* Handle `(left-fringe BITMAP [FACE])'
4906 and `(right-fringe BITMAP [FACE])'. */
4908 && (EQ (XCAR (spec
), Qleft_fringe
)
4909 || EQ (XCAR (spec
), Qright_fringe
))
4910 && CONSP (XCDR (spec
)))
4916 if (!FRAME_WINDOW_P (it
->f
))
4917 /* If we return here, POSITION has been advanced
4918 across the text with this property. */
4920 /* Synchronize the bidi iterator with POSITION. This is
4921 needed because we are not going to push the iterator
4922 on behalf of this display property, so there will be
4923 no pop_it call to do this synchronization for us. */
4926 it
->position
= *position
;
4927 iterate_out_of_display_property (it
);
4928 *position
= it
->position
;
4933 else if (!frame_window_p
)
4936 #ifdef HAVE_WINDOW_SYSTEM
4937 value
= XCAR (XCDR (spec
));
4938 if (!SYMBOLP (value
)
4939 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4940 /* If we return here, POSITION has been advanced
4941 across the text with this property. */
4943 if (it
&& it
->bidi_p
)
4945 it
->position
= *position
;
4946 iterate_out_of_display_property (it
);
4947 *position
= it
->position
;
4954 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4956 if (CONSP (XCDR (XCDR (spec
))))
4958 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4959 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4965 /* Save current settings of IT so that we can restore them
4966 when we are finished with the glyph property value. */
4967 push_it (it
, position
);
4969 it
->area
= TEXT_AREA
;
4970 it
->what
= IT_IMAGE
;
4971 it
->image_id
= -1; /* no image */
4972 it
->position
= start_pos
;
4973 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4974 it
->method
= GET_FROM_IMAGE
;
4975 it
->from_overlay
= Qnil
;
4976 it
->face_id
= face_id
;
4977 it
->from_disp_prop_p
= true;
4979 /* Say that we haven't consumed the characters with
4980 `display' property yet. The call to pop_it in
4981 set_iterator_to_next will clean this up. */
4982 *position
= start_pos
;
4984 if (EQ (XCAR (spec
), Qleft_fringe
))
4986 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4987 it
->left_user_fringe_face_id
= face_id
;
4991 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4992 it
->right_user_fringe_face_id
= face_id
;
4995 #endif /* HAVE_WINDOW_SYSTEM */
4999 /* Prepare to handle `((margin left-margin) ...)',
5000 `((margin right-margin) ...)' and `((margin nil) ...)'
5001 prefixes for display specifications. */
5002 location
= Qunbound
;
5003 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5007 value
= XCDR (spec
);
5009 value
= XCAR (value
);
5012 if (EQ (XCAR (tem
), Qmargin
)
5013 && (tem
= XCDR (tem
),
5014 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5016 || EQ (tem
, Qleft_margin
)
5017 || EQ (tem
, Qright_margin
))))
5021 if (EQ (location
, Qunbound
))
5027 /* After this point, VALUE is the property after any
5028 margin prefix has been stripped. It must be a string,
5029 an image specification, or `(space ...)'.
5031 LOCATION specifies where to display: `left-margin',
5032 `right-margin' or nil. */
5034 valid_p
= (STRINGP (value
)
5035 #ifdef HAVE_WINDOW_SYSTEM
5036 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5037 && valid_image_p (value
))
5038 #endif /* not HAVE_WINDOW_SYSTEM */
5039 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5041 if (valid_p
&& !display_replaced_p
)
5047 /* Callers need to know whether the display spec is any kind
5048 of `(space ...)' spec that is about to affect text-area
5050 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5055 /* Save current settings of IT so that we can restore them
5056 when we are finished with the glyph property value. */
5057 push_it (it
, position
);
5058 it
->from_overlay
= overlay
;
5059 it
->from_disp_prop_p
= true;
5061 if (NILP (location
))
5062 it
->area
= TEXT_AREA
;
5063 else if (EQ (location
, Qleft_margin
))
5064 it
->area
= LEFT_MARGIN_AREA
;
5066 it
->area
= RIGHT_MARGIN_AREA
;
5068 if (STRINGP (value
))
5071 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5072 it
->current
.overlay_string_index
= -1;
5073 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5074 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5075 it
->method
= GET_FROM_STRING
;
5076 it
->stop_charpos
= 0;
5078 it
->base_level_stop
= 0;
5079 it
->string_from_display_prop_p
= true;
5080 /* Say that we haven't consumed the characters with
5081 `display' property yet. The call to pop_it in
5082 set_iterator_to_next will clean this up. */
5083 if (BUFFERP (object
))
5084 *position
= start_pos
;
5086 /* Force paragraph direction to be that of the parent
5087 object. If the parent object's paragraph direction is
5088 not yet determined, default to L2R. */
5089 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5090 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5092 it
->paragraph_embedding
= L2R
;
5094 /* Set up the bidi iterator for this display string. */
5097 it
->bidi_it
.string
.lstring
= it
->string
;
5098 it
->bidi_it
.string
.s
= NULL
;
5099 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5100 it
->bidi_it
.string
.bufpos
= bufpos
;
5101 it
->bidi_it
.string
.from_disp_str
= 1;
5102 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5103 it
->bidi_it
.w
= it
->w
;
5104 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5107 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5109 it
->method
= GET_FROM_STRETCH
;
5111 *position
= it
->position
= start_pos
;
5112 retval
= 1 + (it
->area
== TEXT_AREA
);
5114 #ifdef HAVE_WINDOW_SYSTEM
5117 it
->what
= IT_IMAGE
;
5118 it
->image_id
= lookup_image (it
->f
, value
);
5119 it
->position
= start_pos
;
5120 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5121 it
->method
= GET_FROM_IMAGE
;
5123 /* Say that we haven't consumed the characters with
5124 `display' property yet. The call to pop_it in
5125 set_iterator_to_next will clean this up. */
5126 *position
= start_pos
;
5128 #endif /* HAVE_WINDOW_SYSTEM */
5133 /* Invalid property or property not supported. Restore
5134 POSITION to what it was before. */
5135 *position
= start_pos
;
5139 /* Check if PROP is a display property value whose text should be
5140 treated as intangible. OVERLAY is the overlay from which PROP
5141 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5142 specify the buffer position covered by PROP. */
5145 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5146 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5148 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5149 struct text_pos position
;
5151 SET_TEXT_POS (position
, charpos
, bytepos
);
5152 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5153 &position
, charpos
, frame_window_p
);
5157 /* Return 1 if PROP is a display sub-property value containing STRING.
5159 Implementation note: this and the following function are really
5160 special cases of handle_display_spec and
5161 handle_single_display_spec, and should ideally use the same code.
5162 Until they do, these two pairs must be consistent and must be
5163 modified in sync. */
5166 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5168 if (EQ (string
, prop
))
5171 /* Skip over `when FORM'. */
5172 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5177 /* Actually, the condition following `when' should be eval'ed,
5178 like handle_single_display_spec does, and we should return
5179 zero if it evaluates to nil. However, this function is
5180 called only when the buffer was already displayed and some
5181 glyph in the glyph matrix was found to come from a display
5182 string. Therefore, the condition was already evaluated, and
5183 the result was non-nil, otherwise the display string wouldn't
5184 have been displayed and we would have never been called for
5185 this property. Thus, we can skip the evaluation and assume
5186 its result is non-nil. */
5191 /* Skip over `margin LOCATION'. */
5192 if (EQ (XCAR (prop
), Qmargin
))
5203 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5207 /* Return 1 if STRING appears in the `display' property PROP. */
5210 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5213 && !EQ (XCAR (prop
), Qwhen
)
5214 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5216 /* A list of sub-properties. */
5217 while (CONSP (prop
))
5219 if (single_display_spec_string_p (XCAR (prop
), string
))
5224 else if (VECTORP (prop
))
5226 /* A vector of sub-properties. */
5228 for (i
= 0; i
< ASIZE (prop
); ++i
)
5229 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5233 return single_display_spec_string_p (prop
, string
);
5238 /* Look for STRING in overlays and text properties in the current
5239 buffer, between character positions FROM and TO (excluding TO).
5240 BACK_P non-zero means look back (in this case, TO is supposed to be
5242 Value is the first character position where STRING was found, or
5243 zero if it wasn't found before hitting TO.
5245 This function may only use code that doesn't eval because it is
5246 called asynchronously from note_mouse_highlight. */
5249 string_buffer_position_lim (Lisp_Object string
,
5250 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5252 Lisp_Object limit
, prop
, pos
;
5255 pos
= make_number (max (from
, BEGV
));
5257 if (!back_p
) /* looking forward */
5259 limit
= make_number (min (to
, ZV
));
5260 while (!found
&& !EQ (pos
, limit
))
5262 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5263 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5266 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5270 else /* looking back */
5272 limit
= make_number (max (to
, BEGV
));
5273 while (!found
&& !EQ (pos
, limit
))
5275 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5276 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5279 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5284 return found
? XINT (pos
) : 0;
5287 /* Determine which buffer position in current buffer STRING comes from.
5288 AROUND_CHARPOS is an approximate position where it could come from.
5289 Value is the buffer position or 0 if it couldn't be determined.
5291 This function is necessary because we don't record buffer positions
5292 in glyphs generated from strings (to keep struct glyph small).
5293 This function may only use code that doesn't eval because it is
5294 called asynchronously from note_mouse_highlight. */
5297 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5299 const int MAX_DISTANCE
= 1000;
5300 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5301 around_charpos
+ MAX_DISTANCE
,
5305 found
= string_buffer_position_lim (string
, around_charpos
,
5306 around_charpos
- MAX_DISTANCE
, 1);
5312 /***********************************************************************
5313 `composition' property
5314 ***********************************************************************/
5316 /* Set up iterator IT from `composition' property at its current
5317 position. Called from handle_stop. */
5319 static enum prop_handled
5320 handle_composition_prop (struct it
*it
)
5322 Lisp_Object prop
, string
;
5323 ptrdiff_t pos
, pos_byte
, start
, end
;
5325 if (STRINGP (it
->string
))
5329 pos
= IT_STRING_CHARPOS (*it
);
5330 pos_byte
= IT_STRING_BYTEPOS (*it
);
5331 string
= it
->string
;
5332 s
= SDATA (string
) + pos_byte
;
5333 it
->c
= STRING_CHAR (s
);
5337 pos
= IT_CHARPOS (*it
);
5338 pos_byte
= IT_BYTEPOS (*it
);
5340 it
->c
= FETCH_CHAR (pos_byte
);
5343 /* If there's a valid composition and point is not inside of the
5344 composition (in the case that the composition is from the current
5345 buffer), draw a glyph composed from the composition components. */
5346 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5347 && composition_valid_p (start
, end
, prop
)
5348 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5351 /* As we can't handle this situation (perhaps font-lock added
5352 a new composition), we just return here hoping that next
5353 redisplay will detect this composition much earlier. */
5354 return HANDLED_NORMALLY
;
5357 if (STRINGP (it
->string
))
5358 pos_byte
= string_char_to_byte (it
->string
, start
);
5360 pos_byte
= CHAR_TO_BYTE (start
);
5362 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5365 if (it
->cmp_it
.id
>= 0)
5368 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5369 it
->cmp_it
.nglyphs
= -1;
5373 return HANDLED_NORMALLY
;
5378 /***********************************************************************
5380 ***********************************************************************/
5382 /* The following structure is used to record overlay strings for
5383 later sorting in load_overlay_strings. */
5385 struct overlay_entry
5387 Lisp_Object overlay
;
5394 /* Set up iterator IT from overlay strings at its current position.
5395 Called from handle_stop. */
5397 static enum prop_handled
5398 handle_overlay_change (struct it
*it
)
5400 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5401 return HANDLED_RECOMPUTE_PROPS
;
5403 return HANDLED_NORMALLY
;
5407 /* Set up the next overlay string for delivery by IT, if there is an
5408 overlay string to deliver. Called by set_iterator_to_next when the
5409 end of the current overlay string is reached. If there are more
5410 overlay strings to display, IT->string and
5411 IT->current.overlay_string_index are set appropriately here.
5412 Otherwise IT->string is set to nil. */
5415 next_overlay_string (struct it
*it
)
5417 ++it
->current
.overlay_string_index
;
5418 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5420 /* No more overlay strings. Restore IT's settings to what
5421 they were before overlay strings were processed, and
5422 continue to deliver from current_buffer. */
5424 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5427 || (NILP (it
->string
)
5428 && it
->method
== GET_FROM_BUFFER
5429 && it
->stop_charpos
>= BEGV
5430 && it
->stop_charpos
<= it
->end_charpos
));
5431 it
->current
.overlay_string_index
= -1;
5432 it
->n_overlay_strings
= 0;
5433 it
->overlay_strings_charpos
= -1;
5434 /* If there's an empty display string on the stack, pop the
5435 stack, to resync the bidi iterator with IT's position. Such
5436 empty strings are pushed onto the stack in
5437 get_overlay_strings_1. */
5438 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5441 /* If we're at the end of the buffer, record that we have
5442 processed the overlay strings there already, so that
5443 next_element_from_buffer doesn't try it again. */
5444 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5445 it
->overlay_strings_at_end_processed_p
= true;
5449 /* There are more overlay strings to process. If
5450 IT->current.overlay_string_index has advanced to a position
5451 where we must load IT->overlay_strings with more strings, do
5452 it. We must load at the IT->overlay_strings_charpos where
5453 IT->n_overlay_strings was originally computed; when invisible
5454 text is present, this might not be IT_CHARPOS (Bug#7016). */
5455 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5457 if (it
->current
.overlay_string_index
&& i
== 0)
5458 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5460 /* Initialize IT to deliver display elements from the overlay
5462 it
->string
= it
->overlay_strings
[i
];
5463 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5464 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5465 it
->method
= GET_FROM_STRING
;
5466 it
->stop_charpos
= 0;
5467 it
->end_charpos
= SCHARS (it
->string
);
5468 if (it
->cmp_it
.stop_pos
>= 0)
5469 it
->cmp_it
.stop_pos
= 0;
5471 it
->base_level_stop
= 0;
5473 /* Set up the bidi iterator for this overlay string. */
5476 it
->bidi_it
.string
.lstring
= it
->string
;
5477 it
->bidi_it
.string
.s
= NULL
;
5478 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5479 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5480 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5481 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5482 it
->bidi_it
.w
= it
->w
;
5483 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5491 /* Compare two overlay_entry structures E1 and E2. Used as a
5492 comparison function for qsort in load_overlay_strings. Overlay
5493 strings for the same position are sorted so that
5495 1. All after-strings come in front of before-strings, except
5496 when they come from the same overlay.
5498 2. Within after-strings, strings are sorted so that overlay strings
5499 from overlays with higher priorities come first.
5501 2. Within before-strings, strings are sorted so that overlay
5502 strings from overlays with higher priorities come last.
5504 Value is analogous to strcmp. */
5508 compare_overlay_entries (const void *e1
, const void *e2
)
5510 struct overlay_entry
const *entry1
= e1
;
5511 struct overlay_entry
const *entry2
= e2
;
5514 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5516 /* Let after-strings appear in front of before-strings if
5517 they come from different overlays. */
5518 if (EQ (entry1
->overlay
, entry2
->overlay
))
5519 result
= entry1
->after_string_p
? 1 : -1;
5521 result
= entry1
->after_string_p
? -1 : 1;
5523 else if (entry1
->priority
!= entry2
->priority
)
5525 if (entry1
->after_string_p
)
5526 /* After-strings sorted in order of decreasing priority. */
5527 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5529 /* Before-strings sorted in order of increasing priority. */
5530 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5539 /* Load the vector IT->overlay_strings with overlay strings from IT's
5540 current buffer position, or from CHARPOS if that is > 0. Set
5541 IT->n_overlays to the total number of overlay strings found.
5543 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5544 a time. On entry into load_overlay_strings,
5545 IT->current.overlay_string_index gives the number of overlay
5546 strings that have already been loaded by previous calls to this
5549 IT->add_overlay_start contains an additional overlay start
5550 position to consider for taking overlay strings from, if non-zero.
5551 This position comes into play when the overlay has an `invisible'
5552 property, and both before and after-strings. When we've skipped to
5553 the end of the overlay, because of its `invisible' property, we
5554 nevertheless want its before-string to appear.
5555 IT->add_overlay_start will contain the overlay start position
5558 Overlay strings are sorted so that after-string strings come in
5559 front of before-string strings. Within before and after-strings,
5560 strings are sorted by overlay priority. See also function
5561 compare_overlay_entries. */
5564 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5566 Lisp_Object overlay
, window
, str
, invisible
;
5567 struct Lisp_Overlay
*ov
;
5568 ptrdiff_t start
, end
;
5569 ptrdiff_t size
= 20;
5570 ptrdiff_t n
= 0, i
, j
;
5572 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5576 charpos
= IT_CHARPOS (*it
);
5578 /* Append the overlay string STRING of overlay OVERLAY to vector
5579 `entries' which has size `size' and currently contains `n'
5580 elements. AFTER_P non-zero means STRING is an after-string of
5582 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5585 Lisp_Object priority; \
5589 struct overlay_entry *old = entries; \
5590 SAFE_NALLOCA (entries, 2, size); \
5591 memcpy (entries, old, size * sizeof *entries); \
5595 entries[n].string = (STRING); \
5596 entries[n].overlay = (OVERLAY); \
5597 priority = Foverlay_get ((OVERLAY), Qpriority); \
5598 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5599 entries[n].after_string_p = (AFTER_P); \
5604 /* Process overlay before the overlay center. */
5605 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5607 XSETMISC (overlay
, ov
);
5608 eassert (OVERLAYP (overlay
));
5609 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5610 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5615 /* Skip this overlay if it doesn't start or end at IT's current
5617 if (end
!= charpos
&& start
!= charpos
)
5620 /* Skip this overlay if it doesn't apply to IT->w. */
5621 window
= Foverlay_get (overlay
, Qwindow
);
5622 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5625 /* If the text ``under'' the overlay is invisible, both before-
5626 and after-strings from this overlay are visible; start and
5627 end position are indistinguishable. */
5628 invisible
= Foverlay_get (overlay
, Qinvisible
);
5629 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5631 /* If overlay has a non-empty before-string, record it. */
5632 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5633 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5635 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5637 /* If overlay has a non-empty after-string, record it. */
5638 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5639 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5641 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5644 /* Process overlays after the overlay center. */
5645 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5647 XSETMISC (overlay
, ov
);
5648 eassert (OVERLAYP (overlay
));
5649 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5650 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5652 if (start
> charpos
)
5655 /* Skip this overlay if it doesn't start or end at IT's current
5657 if (end
!= charpos
&& start
!= charpos
)
5660 /* Skip this overlay if it doesn't apply to IT->w. */
5661 window
= Foverlay_get (overlay
, Qwindow
);
5662 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5665 /* If the text ``under'' the overlay is invisible, it has a zero
5666 dimension, and both before- and after-strings apply. */
5667 invisible
= Foverlay_get (overlay
, Qinvisible
);
5668 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5670 /* If overlay has a non-empty before-string, record it. */
5671 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5672 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5674 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5676 /* If overlay has a non-empty after-string, record it. */
5677 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5678 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5680 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5683 #undef RECORD_OVERLAY_STRING
5687 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5689 /* Record number of overlay strings, and where we computed it. */
5690 it
->n_overlay_strings
= n
;
5691 it
->overlay_strings_charpos
= charpos
;
5693 /* IT->current.overlay_string_index is the number of overlay strings
5694 that have already been consumed by IT. Copy some of the
5695 remaining overlay strings to IT->overlay_strings. */
5697 j
= it
->current
.overlay_string_index
;
5698 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5700 it
->overlay_strings
[i
] = entries
[j
].string
;
5701 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5709 /* Get the first chunk of overlay strings at IT's current buffer
5710 position, or at CHARPOS if that is > 0. Value is non-zero if at
5711 least one overlay string was found. */
5714 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5716 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5717 process. This fills IT->overlay_strings with strings, and sets
5718 IT->n_overlay_strings to the total number of strings to process.
5719 IT->pos.overlay_string_index has to be set temporarily to zero
5720 because load_overlay_strings needs this; it must be set to -1
5721 when no overlay strings are found because a zero value would
5722 indicate a position in the first overlay string. */
5723 it
->current
.overlay_string_index
= 0;
5724 load_overlay_strings (it
, charpos
);
5726 /* If we found overlay strings, set up IT to deliver display
5727 elements from the first one. Otherwise set up IT to deliver
5728 from current_buffer. */
5729 if (it
->n_overlay_strings
)
5731 /* Make sure we know settings in current_buffer, so that we can
5732 restore meaningful values when we're done with the overlay
5735 compute_stop_pos (it
);
5736 eassert (it
->face_id
>= 0);
5738 /* Save IT's settings. They are restored after all overlay
5739 strings have been processed. */
5740 eassert (!compute_stop_p
|| it
->sp
== 0);
5742 /* When called from handle_stop, there might be an empty display
5743 string loaded. In that case, don't bother saving it. But
5744 don't use this optimization with the bidi iterator, since we
5745 need the corresponding pop_it call to resync the bidi
5746 iterator's position with IT's position, after we are done
5747 with the overlay strings. (The corresponding call to pop_it
5748 in case of an empty display string is in
5749 next_overlay_string.) */
5751 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5754 /* Set up IT to deliver display elements from the first overlay
5756 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5757 it
->string
= it
->overlay_strings
[0];
5758 it
->from_overlay
= Qnil
;
5759 it
->stop_charpos
= 0;
5760 eassert (STRINGP (it
->string
));
5761 it
->end_charpos
= SCHARS (it
->string
);
5763 it
->base_level_stop
= 0;
5764 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5765 it
->method
= GET_FROM_STRING
;
5766 it
->from_disp_prop_p
= 0;
5768 /* Force paragraph direction to be that of the parent
5770 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5771 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5773 it
->paragraph_embedding
= L2R
;
5775 /* Set up the bidi iterator for this overlay string. */
5778 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5780 it
->bidi_it
.string
.lstring
= it
->string
;
5781 it
->bidi_it
.string
.s
= NULL
;
5782 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5783 it
->bidi_it
.string
.bufpos
= pos
;
5784 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5785 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5786 it
->bidi_it
.w
= it
->w
;
5787 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5792 it
->current
.overlay_string_index
= -1;
5797 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5800 it
->method
= GET_FROM_BUFFER
;
5802 (void) get_overlay_strings_1 (it
, charpos
, 1);
5806 /* Value is non-zero if we found at least one overlay string. */
5807 return STRINGP (it
->string
);
5812 /***********************************************************************
5813 Saving and restoring state
5814 ***********************************************************************/
5816 /* Save current settings of IT on IT->stack. Called, for example,
5817 before setting up IT for an overlay string, to be able to restore
5818 IT's settings to what they were after the overlay string has been
5819 processed. If POSITION is non-NULL, it is the position to save on
5820 the stack instead of IT->position. */
5823 push_it (struct it
*it
, struct text_pos
*position
)
5825 struct iterator_stack_entry
*p
;
5827 eassert (it
->sp
< IT_STACK_SIZE
);
5828 p
= it
->stack
+ it
->sp
;
5830 p
->stop_charpos
= it
->stop_charpos
;
5831 p
->prev_stop
= it
->prev_stop
;
5832 p
->base_level_stop
= it
->base_level_stop
;
5833 p
->cmp_it
= it
->cmp_it
;
5834 eassert (it
->face_id
>= 0);
5835 p
->face_id
= it
->face_id
;
5836 p
->string
= it
->string
;
5837 p
->method
= it
->method
;
5838 p
->from_overlay
= it
->from_overlay
;
5841 case GET_FROM_IMAGE
:
5842 p
->u
.image
.object
= it
->object
;
5843 p
->u
.image
.image_id
= it
->image_id
;
5844 p
->u
.image
.slice
= it
->slice
;
5846 case GET_FROM_STRETCH
:
5847 p
->u
.stretch
.object
= it
->object
;
5850 p
->position
= position
? *position
: it
->position
;
5851 p
->current
= it
->current
;
5852 p
->end_charpos
= it
->end_charpos
;
5853 p
->string_nchars
= it
->string_nchars
;
5855 p
->multibyte_p
= it
->multibyte_p
;
5856 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5857 p
->space_width
= it
->space_width
;
5858 p
->font_height
= it
->font_height
;
5859 p
->voffset
= it
->voffset
;
5860 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5861 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5862 p
->display_ellipsis_p
= 0;
5863 p
->line_wrap
= it
->line_wrap
;
5864 p
->bidi_p
= it
->bidi_p
;
5865 p
->paragraph_embedding
= it
->paragraph_embedding
;
5866 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5869 /* Save the state of the bidi iterator as well. */
5871 bidi_push_it (&it
->bidi_it
);
5875 iterate_out_of_display_property (struct it
*it
)
5877 int buffer_p
= !STRINGP (it
->string
);
5878 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5879 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5881 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5883 /* Maybe initialize paragraph direction. If we are at the beginning
5884 of a new paragraph, next_element_from_buffer may not have a
5885 chance to do that. */
5886 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5887 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5888 /* prev_stop can be zero, so check against BEGV as well. */
5889 while (it
->bidi_it
.charpos
>= bob
5890 && it
->prev_stop
<= it
->bidi_it
.charpos
5891 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5892 && it
->bidi_it
.charpos
< eob
)
5893 bidi_move_to_visually_next (&it
->bidi_it
);
5894 /* Record the stop_pos we just crossed, for when we cross it
5896 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5897 it
->prev_stop
= CHARPOS (it
->position
);
5898 /* If we ended up not where pop_it put us, resync IT's
5899 positional members with the bidi iterator. */
5900 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5901 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5903 it
->current
.pos
= it
->position
;
5905 it
->current
.string_pos
= it
->position
;
5908 /* Restore IT's settings from IT->stack. Called, for example, when no
5909 more overlay strings must be processed, and we return to delivering
5910 display elements from a buffer, or when the end of a string from a
5911 `display' property is reached and we return to delivering display
5912 elements from an overlay string, or from a buffer. */
5915 pop_it (struct it
*it
)
5917 struct iterator_stack_entry
*p
;
5918 int from_display_prop
= it
->from_disp_prop_p
;
5920 eassert (it
->sp
> 0);
5922 p
= it
->stack
+ it
->sp
;
5923 it
->stop_charpos
= p
->stop_charpos
;
5924 it
->prev_stop
= p
->prev_stop
;
5925 it
->base_level_stop
= p
->base_level_stop
;
5926 it
->cmp_it
= p
->cmp_it
;
5927 it
->face_id
= p
->face_id
;
5928 it
->current
= p
->current
;
5929 it
->position
= p
->position
;
5930 it
->string
= p
->string
;
5931 it
->from_overlay
= p
->from_overlay
;
5932 if (NILP (it
->string
))
5933 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5934 it
->method
= p
->method
;
5937 case GET_FROM_IMAGE
:
5938 it
->image_id
= p
->u
.image
.image_id
;
5939 it
->object
= p
->u
.image
.object
;
5940 it
->slice
= p
->u
.image
.slice
;
5942 case GET_FROM_STRETCH
:
5943 it
->object
= p
->u
.stretch
.object
;
5945 case GET_FROM_BUFFER
:
5946 it
->object
= it
->w
->contents
;
5948 case GET_FROM_STRING
:
5949 it
->object
= it
->string
;
5951 case GET_FROM_DISPLAY_VECTOR
:
5953 it
->method
= GET_FROM_C_STRING
;
5954 else if (STRINGP (it
->string
))
5955 it
->method
= GET_FROM_STRING
;
5958 it
->method
= GET_FROM_BUFFER
;
5959 it
->object
= it
->w
->contents
;
5962 it
->end_charpos
= p
->end_charpos
;
5963 it
->string_nchars
= p
->string_nchars
;
5965 it
->multibyte_p
= p
->multibyte_p
;
5966 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5967 it
->space_width
= p
->space_width
;
5968 it
->font_height
= p
->font_height
;
5969 it
->voffset
= p
->voffset
;
5970 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5971 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5972 it
->line_wrap
= p
->line_wrap
;
5973 it
->bidi_p
= p
->bidi_p
;
5974 it
->paragraph_embedding
= p
->paragraph_embedding
;
5975 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5978 bidi_pop_it (&it
->bidi_it
);
5979 /* Bidi-iterate until we get out of the portion of text, if any,
5980 covered by a `display' text property or by an overlay with
5981 `display' property. (We cannot just jump there, because the
5982 internal coherency of the bidi iterator state can not be
5983 preserved across such jumps.) We also must determine the
5984 paragraph base direction if the overlay we just processed is
5985 at the beginning of a new paragraph. */
5986 if (from_display_prop
5987 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5988 iterate_out_of_display_property (it
);
5990 eassert ((BUFFERP (it
->object
)
5991 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5992 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5993 || (STRINGP (it
->object
)
5994 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5995 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5996 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6002 /***********************************************************************
6004 ***********************************************************************/
6006 /* Set IT's current position to the previous line start. */
6009 back_to_previous_line_start (struct it
*it
)
6011 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6014 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6018 /* Move IT to the next line start.
6020 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6021 we skipped over part of the text (as opposed to moving the iterator
6022 continuously over the text). Otherwise, don't change the value
6025 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6026 iterator on the newline, if it was found.
6028 Newlines may come from buffer text, overlay strings, or strings
6029 displayed via the `display' property. That's the reason we can't
6030 simply use find_newline_no_quit.
6032 Note that this function may not skip over invisible text that is so
6033 because of text properties and immediately follows a newline. If
6034 it would, function reseat_at_next_visible_line_start, when called
6035 from set_iterator_to_next, would effectively make invisible
6036 characters following a newline part of the wrong glyph row, which
6037 leads to wrong cursor motion. */
6040 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6041 struct bidi_it
*bidi_it_prev
)
6043 ptrdiff_t old_selective
;
6044 int newline_found_p
, n
;
6045 const int MAX_NEWLINE_DISTANCE
= 500;
6047 /* If already on a newline, just consume it to avoid unintended
6048 skipping over invisible text below. */
6049 if (it
->what
== IT_CHARACTER
6051 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6053 if (it
->bidi_p
&& bidi_it_prev
)
6054 *bidi_it_prev
= it
->bidi_it
;
6055 set_iterator_to_next (it
, 0);
6060 /* Don't handle selective display in the following. It's (a)
6061 unnecessary because it's done by the caller, and (b) leads to an
6062 infinite recursion because next_element_from_ellipsis indirectly
6063 calls this function. */
6064 old_selective
= it
->selective
;
6067 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6068 from buffer text. */
6069 for (n
= newline_found_p
= 0;
6070 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6071 n
+= STRINGP (it
->string
) ? 0 : 1)
6073 if (!get_next_display_element (it
))
6075 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6076 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6077 *bidi_it_prev
= it
->bidi_it
;
6078 set_iterator_to_next (it
, 0);
6081 /* If we didn't find a newline near enough, see if we can use a
6083 if (!newline_found_p
)
6085 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6086 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6090 eassert (!STRINGP (it
->string
));
6092 /* If there isn't any `display' property in sight, and no
6093 overlays, we can just use the position of the newline in
6095 if (it
->stop_charpos
>= limit
6096 || ((pos
= Fnext_single_property_change (make_number (start
),
6098 make_number (limit
)),
6100 && next_overlay_change (start
) == ZV
))
6104 IT_CHARPOS (*it
) = limit
;
6105 IT_BYTEPOS (*it
) = bytepos
;
6109 struct bidi_it bprev
;
6111 /* Help bidi.c avoid expensive searches for display
6112 properties and overlays, by telling it that there are
6113 none up to `limit'. */
6114 if (it
->bidi_it
.disp_pos
< limit
)
6116 it
->bidi_it
.disp_pos
= limit
;
6117 it
->bidi_it
.disp_prop
= 0;
6120 bprev
= it
->bidi_it
;
6121 bidi_move_to_visually_next (&it
->bidi_it
);
6122 } while (it
->bidi_it
.charpos
!= limit
);
6123 IT_CHARPOS (*it
) = limit
;
6124 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6126 *bidi_it_prev
= bprev
;
6128 *skipped_p
= newline_found_p
= true;
6132 while (get_next_display_element (it
)
6133 && !newline_found_p
)
6135 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6136 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6137 *bidi_it_prev
= it
->bidi_it
;
6138 set_iterator_to_next (it
, 0);
6143 it
->selective
= old_selective
;
6144 return newline_found_p
;
6148 /* Set IT's current position to the previous visible line start. Skip
6149 invisible text that is so either due to text properties or due to
6150 selective display. Caution: this does not change IT->current_x and
6154 back_to_previous_visible_line_start (struct it
*it
)
6156 while (IT_CHARPOS (*it
) > BEGV
)
6158 back_to_previous_line_start (it
);
6160 if (IT_CHARPOS (*it
) <= BEGV
)
6163 /* If selective > 0, then lines indented more than its value are
6165 if (it
->selective
> 0
6166 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6170 /* Check the newline before point for invisibility. */
6173 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6174 Qinvisible
, it
->window
);
6175 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6179 if (IT_CHARPOS (*it
) <= BEGV
)
6184 void *it2data
= NULL
;
6187 Lisp_Object val
, overlay
;
6189 SAVE_IT (it2
, *it
, it2data
);
6191 /* If newline is part of a composition, continue from start of composition */
6192 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6193 && beg
< IT_CHARPOS (*it
))
6196 /* If newline is replaced by a display property, find start of overlay
6197 or interval and continue search from that point. */
6198 pos
= --IT_CHARPOS (it2
);
6201 bidi_unshelve_cache (NULL
, 0);
6202 it2
.string_from_display_prop_p
= 0;
6203 it2
.from_disp_prop_p
= 0;
6204 if (handle_display_prop (&it2
) == HANDLED_RETURN
6205 && !NILP (val
= get_char_property_and_overlay
6206 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6207 && (OVERLAYP (overlay
)
6208 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6209 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6211 RESTORE_IT (it
, it
, it2data
);
6215 /* Newline is not replaced by anything -- so we are done. */
6216 RESTORE_IT (it
, it
, it2data
);
6222 IT_CHARPOS (*it
) = beg
;
6223 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6227 it
->continuation_lines_width
= 0;
6229 eassert (IT_CHARPOS (*it
) >= BEGV
);
6230 eassert (IT_CHARPOS (*it
) == BEGV
6231 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6236 /* Reseat iterator IT at the previous visible line start. Skip
6237 invisible text that is so either due to text properties or due to
6238 selective display. At the end, update IT's overlay information,
6239 face information etc. */
6242 reseat_at_previous_visible_line_start (struct it
*it
)
6244 back_to_previous_visible_line_start (it
);
6245 reseat (it
, it
->current
.pos
, 1);
6250 /* Reseat iterator IT on the next visible line start in the current
6251 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6252 preceding the line start. Skip over invisible text that is so
6253 because of selective display. Compute faces, overlays etc at the
6254 new position. Note that this function does not skip over text that
6255 is invisible because of text properties. */
6258 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6260 int newline_found_p
, skipped_p
= 0;
6261 struct bidi_it bidi_it_prev
;
6263 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6265 /* Skip over lines that are invisible because they are indented
6266 more than the value of IT->selective. */
6267 if (it
->selective
> 0)
6268 while (IT_CHARPOS (*it
) < ZV
6269 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6272 eassert (IT_BYTEPOS (*it
) == BEGV
6273 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6275 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6278 /* Position on the newline if that's what's requested. */
6279 if (on_newline_p
&& newline_found_p
)
6281 if (STRINGP (it
->string
))
6283 if (IT_STRING_CHARPOS (*it
) > 0)
6287 --IT_STRING_CHARPOS (*it
);
6288 --IT_STRING_BYTEPOS (*it
);
6292 /* We need to restore the bidi iterator to the state
6293 it had on the newline, and resync the IT's
6294 position with that. */
6295 it
->bidi_it
= bidi_it_prev
;
6296 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6297 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6301 else if (IT_CHARPOS (*it
) > BEGV
)
6310 /* We need to restore the bidi iterator to the state it
6311 had on the newline and resync IT with that. */
6312 it
->bidi_it
= bidi_it_prev
;
6313 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6314 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6316 reseat (it
, it
->current
.pos
, 0);
6320 reseat (it
, it
->current
.pos
, 0);
6327 /***********************************************************************
6328 Changing an iterator's position
6329 ***********************************************************************/
6331 /* Change IT's current position to POS in current_buffer. If FORCE_P
6332 is non-zero, always check for text properties at the new position.
6333 Otherwise, text properties are only looked up if POS >=
6334 IT->check_charpos of a property. */
6337 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6339 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6341 reseat_1 (it
, pos
, 0);
6343 /* Determine where to check text properties. Avoid doing it
6344 where possible because text property lookup is very expensive. */
6346 || CHARPOS (pos
) > it
->stop_charpos
6347 || CHARPOS (pos
) < original_pos
)
6351 /* For bidi iteration, we need to prime prev_stop and
6352 base_level_stop with our best estimations. */
6353 /* Implementation note: Of course, POS is not necessarily a
6354 stop position, so assigning prev_pos to it is a lie; we
6355 should have called compute_stop_backwards. However, if
6356 the current buffer does not include any R2L characters,
6357 that call would be a waste of cycles, because the
6358 iterator will never move back, and thus never cross this
6359 "fake" stop position. So we delay that backward search
6360 until the time we really need it, in next_element_from_buffer. */
6361 if (CHARPOS (pos
) != it
->prev_stop
)
6362 it
->prev_stop
= CHARPOS (pos
);
6363 if (CHARPOS (pos
) < it
->base_level_stop
)
6364 it
->base_level_stop
= 0; /* meaning it's unknown */
6370 it
->prev_stop
= it
->base_level_stop
= 0;
6379 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6380 IT->stop_pos to POS, also. */
6383 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6385 /* Don't call this function when scanning a C string. */
6386 eassert (it
->s
== NULL
);
6388 /* POS must be a reasonable value. */
6389 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6391 it
->current
.pos
= it
->position
= pos
;
6392 it
->end_charpos
= ZV
;
6394 it
->current
.dpvec_index
= -1;
6395 it
->current
.overlay_string_index
= -1;
6396 IT_STRING_CHARPOS (*it
) = -1;
6397 IT_STRING_BYTEPOS (*it
) = -1;
6399 it
->method
= GET_FROM_BUFFER
;
6400 it
->object
= it
->w
->contents
;
6401 it
->area
= TEXT_AREA
;
6402 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6404 it
->string_from_display_prop_p
= 0;
6405 it
->string_from_prefix_prop_p
= 0;
6407 it
->from_disp_prop_p
= 0;
6408 it
->face_before_selective_p
= 0;
6411 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6413 bidi_unshelve_cache (NULL
, 0);
6414 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6415 it
->bidi_it
.string
.s
= NULL
;
6416 it
->bidi_it
.string
.lstring
= Qnil
;
6417 it
->bidi_it
.string
.bufpos
= 0;
6418 it
->bidi_it
.string
.from_disp_str
= 0;
6419 it
->bidi_it
.string
.unibyte
= 0;
6420 it
->bidi_it
.w
= it
->w
;
6425 it
->stop_charpos
= CHARPOS (pos
);
6426 it
->base_level_stop
= CHARPOS (pos
);
6428 /* This make the information stored in it->cmp_it invalidate. */
6433 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6434 If S is non-null, it is a C string to iterate over. Otherwise,
6435 STRING gives a Lisp string to iterate over.
6437 If PRECISION > 0, don't return more then PRECISION number of
6438 characters from the string.
6440 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6441 characters have been returned. FIELD_WIDTH < 0 means an infinite
6444 MULTIBYTE = 0 means disable processing of multibyte characters,
6445 MULTIBYTE > 0 means enable it,
6446 MULTIBYTE < 0 means use IT->multibyte_p.
6448 IT must be initialized via a prior call to init_iterator before
6449 calling this function. */
6452 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6453 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6456 /* No text property checks performed by default, but see below. */
6457 it
->stop_charpos
= -1;
6459 /* Set iterator position and end position. */
6460 memset (&it
->current
, 0, sizeof it
->current
);
6461 it
->current
.overlay_string_index
= -1;
6462 it
->current
.dpvec_index
= -1;
6463 eassert (charpos
>= 0);
6465 /* If STRING is specified, use its multibyteness, otherwise use the
6466 setting of MULTIBYTE, if specified. */
6468 it
->multibyte_p
= multibyte
> 0;
6470 /* Bidirectional reordering of strings is controlled by the default
6471 value of bidi-display-reordering. Don't try to reorder while
6472 loading loadup.el, as the necessary character property tables are
6473 not yet available. */
6476 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6480 eassert (STRINGP (string
));
6481 it
->string
= string
;
6483 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6484 it
->method
= GET_FROM_STRING
;
6485 it
->current
.string_pos
= string_pos (charpos
, string
);
6489 it
->bidi_it
.string
.lstring
= string
;
6490 it
->bidi_it
.string
.s
= NULL
;
6491 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6492 it
->bidi_it
.string
.bufpos
= 0;
6493 it
->bidi_it
.string
.from_disp_str
= 0;
6494 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6495 it
->bidi_it
.w
= it
->w
;
6496 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6497 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6502 it
->s
= (const unsigned char *) s
;
6505 /* Note that we use IT->current.pos, not it->current.string_pos,
6506 for displaying C strings. */
6507 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6508 if (it
->multibyte_p
)
6510 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6511 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6515 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6516 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6521 it
->bidi_it
.string
.lstring
= Qnil
;
6522 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6523 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6524 it
->bidi_it
.string
.bufpos
= 0;
6525 it
->bidi_it
.string
.from_disp_str
= 0;
6526 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6527 it
->bidi_it
.w
= it
->w
;
6528 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6531 it
->method
= GET_FROM_C_STRING
;
6534 /* PRECISION > 0 means don't return more than PRECISION characters
6536 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6538 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6540 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6543 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6544 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6545 FIELD_WIDTH < 0 means infinite field width. This is useful for
6546 padding with `-' at the end of a mode line. */
6547 if (field_width
< 0)
6548 field_width
= INFINITY
;
6549 /* Implementation note: We deliberately don't enlarge
6550 it->bidi_it.string.schars here to fit it->end_charpos, because
6551 the bidi iterator cannot produce characters out of thin air. */
6552 if (field_width
> it
->end_charpos
- charpos
)
6553 it
->end_charpos
= charpos
+ field_width
;
6555 /* Use the standard display table for displaying strings. */
6556 if (DISP_TABLE_P (Vstandard_display_table
))
6557 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6559 it
->stop_charpos
= charpos
;
6560 it
->prev_stop
= charpos
;
6561 it
->base_level_stop
= 0;
6564 it
->bidi_it
.first_elt
= 1;
6565 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6566 it
->bidi_it
.disp_pos
= -1;
6568 if (s
== NULL
&& it
->multibyte_p
)
6570 ptrdiff_t endpos
= SCHARS (it
->string
);
6571 if (endpos
> it
->end_charpos
)
6572 endpos
= it
->end_charpos
;
6573 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6581 /***********************************************************************
6583 ***********************************************************************/
6585 /* Map enum it_method value to corresponding next_element_from_* function. */
6587 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6589 next_element_from_buffer
,
6590 next_element_from_display_vector
,
6591 next_element_from_string
,
6592 next_element_from_c_string
,
6593 next_element_from_image
,
6594 next_element_from_stretch
6597 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6600 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6601 (possibly with the following characters). */
6603 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6604 ((IT)->cmp_it.id >= 0 \
6605 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6606 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6607 END_CHARPOS, (IT)->w, \
6608 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6612 /* Lookup the char-table Vglyphless_char_display for character C (-1
6613 if we want information for no-font case), and return the display
6614 method symbol. By side-effect, update it->what and
6615 it->glyphless_method. This function is called from
6616 get_next_display_element for each character element, and from
6617 x_produce_glyphs when no suitable font was found. */
6620 lookup_glyphless_char_display (int c
, struct it
*it
)
6622 Lisp_Object glyphless_method
= Qnil
;
6624 if (CHAR_TABLE_P (Vglyphless_char_display
)
6625 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6629 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6630 if (CONSP (glyphless_method
))
6631 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6632 ? XCAR (glyphless_method
)
6633 : XCDR (glyphless_method
);
6636 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6640 if (NILP (glyphless_method
))
6643 /* The default is to display the character by a proper font. */
6645 /* The default for the no-font case is to display an empty box. */
6646 glyphless_method
= Qempty_box
;
6648 if (EQ (glyphless_method
, Qzero_width
))
6651 return glyphless_method
;
6652 /* This method can't be used for the no-font case. */
6653 glyphless_method
= Qempty_box
;
6655 if (EQ (glyphless_method
, Qthin_space
))
6656 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6657 else if (EQ (glyphless_method
, Qempty_box
))
6658 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6659 else if (EQ (glyphless_method
, Qhex_code
))
6660 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6661 else if (STRINGP (glyphless_method
))
6662 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6665 /* Invalid value. We use the default method. */
6666 glyphless_method
= Qnil
;
6669 it
->what
= IT_GLYPHLESS
;
6670 return glyphless_method
;
6673 /* Merge escape glyph face and cache the result. */
6675 static struct frame
*last_escape_glyph_frame
= NULL
;
6676 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6677 static int last_escape_glyph_merged_face_id
= 0;
6680 merge_escape_glyph_face (struct it
*it
)
6684 if (it
->f
== last_escape_glyph_frame
6685 && it
->face_id
== last_escape_glyph_face_id
)
6686 face_id
= last_escape_glyph_merged_face_id
;
6689 /* Merge the `escape-glyph' face into the current face. */
6690 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6691 last_escape_glyph_frame
= it
->f
;
6692 last_escape_glyph_face_id
= it
->face_id
;
6693 last_escape_glyph_merged_face_id
= face_id
;
6698 /* Likewise for glyphless glyph face. */
6700 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6701 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6702 static int last_glyphless_glyph_merged_face_id
= 0;
6705 merge_glyphless_glyph_face (struct it
*it
)
6709 if (it
->f
== last_glyphless_glyph_frame
6710 && it
->face_id
== last_glyphless_glyph_face_id
)
6711 face_id
= last_glyphless_glyph_merged_face_id
;
6714 /* Merge the `glyphless-char' face into the current face. */
6715 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6716 last_glyphless_glyph_frame
= it
->f
;
6717 last_glyphless_glyph_face_id
= it
->face_id
;
6718 last_glyphless_glyph_merged_face_id
= face_id
;
6723 /* Load IT's display element fields with information about the next
6724 display element from the current position of IT. Value is zero if
6725 end of buffer (or C string) is reached. */
6728 get_next_display_element (struct it
*it
)
6730 /* Non-zero means that we found a display element. Zero means that
6731 we hit the end of what we iterate over. Performance note: the
6732 function pointer `method' used here turns out to be faster than
6733 using a sequence of if-statements. */
6737 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6739 if (it
->what
== IT_CHARACTER
)
6741 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6742 and only if (a) the resolved directionality of that character
6744 /* FIXME: Do we need an exception for characters from display
6746 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6747 it
->c
= bidi_mirror_char (it
->c
);
6748 /* Map via display table or translate control characters.
6749 IT->c, IT->len etc. have been set to the next character by
6750 the function call above. If we have a display table, and it
6751 contains an entry for IT->c, translate it. Don't do this if
6752 IT->c itself comes from a display table, otherwise we could
6753 end up in an infinite recursion. (An alternative could be to
6754 count the recursion depth of this function and signal an
6755 error when a certain maximum depth is reached.) Is it worth
6757 if (success_p
&& it
->dpvec
== NULL
)
6760 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6761 int nonascii_space_p
= 0;
6762 int nonascii_hyphen_p
= 0;
6763 int c
= it
->c
; /* This is the character to display. */
6765 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6767 eassert (SINGLE_BYTE_CHAR_P (c
));
6768 if (unibyte_display_via_language_environment
)
6770 c
= DECODE_CHAR (unibyte
, c
);
6772 c
= BYTE8_TO_CHAR (it
->c
);
6775 c
= BYTE8_TO_CHAR (it
->c
);
6779 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6782 struct Lisp_Vector
*v
= XVECTOR (dv
);
6784 /* Return the first character from the display table
6785 entry, if not empty. If empty, don't display the
6786 current character. */
6789 it
->dpvec_char_len
= it
->len
;
6790 it
->dpvec
= v
->contents
;
6791 it
->dpend
= v
->contents
+ v
->header
.size
;
6792 it
->current
.dpvec_index
= 0;
6793 it
->dpvec_face_id
= -1;
6794 it
->saved_face_id
= it
->face_id
;
6795 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6800 set_iterator_to_next (it
, 0);
6805 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6807 if (it
->what
== IT_GLYPHLESS
)
6809 /* Don't display this character. */
6810 set_iterator_to_next (it
, 0);
6814 /* If `nobreak-char-display' is non-nil, we display
6815 non-ASCII spaces and hyphens specially. */
6816 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6819 nonascii_space_p
= true;
6820 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6821 nonascii_hyphen_p
= true;
6824 /* Translate control characters into `\003' or `^C' form.
6825 Control characters coming from a display table entry are
6826 currently not translated because we use IT->dpvec to hold
6827 the translation. This could easily be changed but I
6828 don't believe that it is worth doing.
6830 The characters handled by `nobreak-char-display' must be
6833 Non-printable characters and raw-byte characters are also
6834 translated to octal form. */
6835 if (((c
< ' ' || c
== 127) /* ASCII control chars. */
6836 ? (it
->area
!= TEXT_AREA
6837 /* In mode line, treat \n, \t like other crl chars. */
6840 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6841 || (c
!= '\n' && c
!= '\t'))
6843 || nonascii_hyphen_p
6845 || ! CHAR_PRINTABLE_P (c
))))
6847 /* C is a control character, non-ASCII space/hyphen,
6848 raw-byte, or a non-printable character which must be
6849 displayed either as '\003' or as `^C' where the '\\'
6850 and '^' can be defined in the display table. Fill
6851 IT->ctl_chars with glyphs for what we have to
6852 display. Then, set IT->dpvec to these glyphs. */
6859 /* Handle control characters with ^. */
6861 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6865 g
= '^'; /* default glyph for Control */
6866 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6868 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6870 g
= GLYPH_CODE_CHAR (gc
);
6871 lface_id
= GLYPH_CODE_FACE (gc
);
6875 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6876 : merge_escape_glyph_face (it
));
6878 XSETINT (it
->ctl_chars
[0], g
);
6879 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6881 goto display_control
;
6884 /* Handle non-ascii space in the mode where it only gets
6887 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6889 /* Merge `nobreak-space' into the current face. */
6890 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6892 XSETINT (it
->ctl_chars
[0], ' ');
6894 goto display_control
;
6897 /* Handle sequences that start with the "escape glyph". */
6899 /* the default escape glyph is \. */
6900 escape_glyph
= '\\';
6903 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6905 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6906 lface_id
= GLYPH_CODE_FACE (gc
);
6910 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6911 : merge_escape_glyph_face (it
));
6913 /* Draw non-ASCII hyphen with just highlighting: */
6915 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6917 XSETINT (it
->ctl_chars
[0], '-');
6919 goto display_control
;
6922 /* Draw non-ASCII space/hyphen with escape glyph: */
6924 if (nonascii_space_p
|| nonascii_hyphen_p
)
6926 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6927 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6929 goto display_control
;
6936 if (CHAR_BYTE8_P (c
))
6937 /* Display \200 instead of \17777600. */
6938 c
= CHAR_TO_BYTE8 (c
);
6939 len
= sprintf (str
, "%03o", c
);
6941 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6942 for (i
= 0; i
< len
; i
++)
6943 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6948 /* Set up IT->dpvec and return first character from it. */
6949 it
->dpvec_char_len
= it
->len
;
6950 it
->dpvec
= it
->ctl_chars
;
6951 it
->dpend
= it
->dpvec
+ ctl_len
;
6952 it
->current
.dpvec_index
= 0;
6953 it
->dpvec_face_id
= face_id
;
6954 it
->saved_face_id
= it
->face_id
;
6955 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6959 it
->char_to_display
= c
;
6963 it
->char_to_display
= it
->c
;
6967 #ifdef HAVE_WINDOW_SYSTEM
6968 /* Adjust face id for a multibyte character. There are no multibyte
6969 character in unibyte text. */
6970 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6973 && FRAME_WINDOW_P (it
->f
))
6975 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6977 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6979 /* Automatic composition with glyph-string. */
6980 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6982 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6986 ptrdiff_t pos
= (it
->s
? -1
6987 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6988 : IT_CHARPOS (*it
));
6991 if (it
->what
== IT_CHARACTER
)
6992 c
= it
->char_to_display
;
6995 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6999 for (i
= 0; i
< cmp
->glyph_len
; i
++)
7000 /* TAB in a composition means display glyphs with
7001 padding space on the left or right. */
7002 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7005 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7008 #endif /* HAVE_WINDOW_SYSTEM */
7011 /* Is this character the last one of a run of characters with
7012 box? If yes, set IT->end_of_box_run_p to 1. */
7016 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7018 int face_id
= underlying_face_id (it
);
7019 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7023 if (face
->box
== FACE_NO_BOX
)
7025 /* If the box comes from face properties in a
7026 display string, check faces in that string. */
7027 int string_face_id
= face_after_it_pos (it
);
7028 it
->end_of_box_run_p
7029 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7032 /* Otherwise, the box comes from the underlying face.
7033 If this is the last string character displayed, check
7034 the next buffer location. */
7035 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7036 && (it
->current
.overlay_string_index
7037 == it
->n_overlay_strings
- 1))
7041 struct text_pos pos
= it
->current
.pos
;
7042 INC_TEXT_POS (pos
, it
->multibyte_p
);
7044 next_face_id
= face_at_buffer_position
7045 (it
->w
, CHARPOS (pos
), &ignore
,
7046 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7048 it
->end_of_box_run_p
7049 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7054 /* next_element_from_display_vector sets this flag according to
7055 faces of the display vector glyphs, see there. */
7056 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7058 int face_id
= face_after_it_pos (it
);
7059 it
->end_of_box_run_p
7060 = (face_id
!= it
->face_id
7061 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7064 /* If we reached the end of the object we've been iterating (e.g., a
7065 display string or an overlay string), and there's something on
7066 IT->stack, proceed with what's on the stack. It doesn't make
7067 sense to return zero if there's unprocessed stuff on the stack,
7068 because otherwise that stuff will never be displayed. */
7069 if (!success_p
&& it
->sp
> 0)
7071 set_iterator_to_next (it
, 0);
7072 success_p
= get_next_display_element (it
);
7075 /* Value is 0 if end of buffer or string reached. */
7080 /* Move IT to the next display element.
7082 RESEAT_P non-zero means if called on a newline in buffer text,
7083 skip to the next visible line start.
7085 Functions get_next_display_element and set_iterator_to_next are
7086 separate because I find this arrangement easier to handle than a
7087 get_next_display_element function that also increments IT's
7088 position. The way it is we can first look at an iterator's current
7089 display element, decide whether it fits on a line, and if it does,
7090 increment the iterator position. The other way around we probably
7091 would either need a flag indicating whether the iterator has to be
7092 incremented the next time, or we would have to implement a
7093 decrement position function which would not be easy to write. */
7096 set_iterator_to_next (struct it
*it
, int reseat_p
)
7098 /* Reset flags indicating start and end of a sequence of characters
7099 with box. Reset them at the start of this function because
7100 moving the iterator to a new position might set them. */
7101 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7105 case GET_FROM_BUFFER
:
7106 /* The current display element of IT is a character from
7107 current_buffer. Advance in the buffer, and maybe skip over
7108 invisible lines that are so because of selective display. */
7109 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7110 reseat_at_next_visible_line_start (it
, 0);
7111 else if (it
->cmp_it
.id
>= 0)
7113 /* We are currently getting glyphs from a composition. */
7118 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7119 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7120 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7122 it
->cmp_it
.from
= it
->cmp_it
.to
;
7127 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7129 it
->end_charpos
, Qnil
);
7132 else if (! it
->cmp_it
.reversed_p
)
7134 /* Composition created while scanning forward. */
7135 /* Update IT's char/byte positions to point to the first
7136 character of the next grapheme cluster, or to the
7137 character visually after the current composition. */
7138 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7139 bidi_move_to_visually_next (&it
->bidi_it
);
7140 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7141 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7143 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7145 /* Proceed to the next grapheme cluster. */
7146 it
->cmp_it
.from
= it
->cmp_it
.to
;
7150 /* No more grapheme clusters in this composition.
7151 Find the next stop position. */
7152 ptrdiff_t stop
= it
->end_charpos
;
7153 if (it
->bidi_it
.scan_dir
< 0)
7154 /* Now we are scanning backward and don't know
7157 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7158 IT_BYTEPOS (*it
), stop
, Qnil
);
7163 /* Composition created while scanning backward. */
7164 /* Update IT's char/byte positions to point to the last
7165 character of the previous grapheme cluster, or the
7166 character visually after the current composition. */
7167 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7168 bidi_move_to_visually_next (&it
->bidi_it
);
7169 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7170 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7171 if (it
->cmp_it
.from
> 0)
7173 /* Proceed to the previous grapheme cluster. */
7174 it
->cmp_it
.to
= it
->cmp_it
.from
;
7178 /* No more grapheme clusters in this composition.
7179 Find the next stop position. */
7180 ptrdiff_t stop
= it
->end_charpos
;
7181 if (it
->bidi_it
.scan_dir
< 0)
7182 /* Now we are scanning backward and don't know
7185 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7186 IT_BYTEPOS (*it
), stop
, Qnil
);
7192 eassert (it
->len
!= 0);
7196 IT_BYTEPOS (*it
) += it
->len
;
7197 IT_CHARPOS (*it
) += 1;
7201 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7202 /* If this is a new paragraph, determine its base
7203 direction (a.k.a. its base embedding level). */
7204 if (it
->bidi_it
.new_paragraph
)
7205 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7206 bidi_move_to_visually_next (&it
->bidi_it
);
7207 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7208 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7209 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7211 /* As the scan direction was changed, we must
7212 re-compute the stop position for composition. */
7213 ptrdiff_t stop
= it
->end_charpos
;
7214 if (it
->bidi_it
.scan_dir
< 0)
7216 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7217 IT_BYTEPOS (*it
), stop
, Qnil
);
7220 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7224 case GET_FROM_C_STRING
:
7225 /* Current display element of IT is from a C string. */
7227 /* If the string position is beyond string's end, it means
7228 next_element_from_c_string is padding the string with
7229 blanks, in which case we bypass the bidi iterator,
7230 because it cannot deal with such virtual characters. */
7231 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7233 IT_BYTEPOS (*it
) += it
->len
;
7234 IT_CHARPOS (*it
) += 1;
7238 bidi_move_to_visually_next (&it
->bidi_it
);
7239 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7240 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7244 case GET_FROM_DISPLAY_VECTOR
:
7245 /* Current display element of IT is from a display table entry.
7246 Advance in the display table definition. Reset it to null if
7247 end reached, and continue with characters from buffers/
7249 ++it
->current
.dpvec_index
;
7251 /* Restore face of the iterator to what they were before the
7252 display vector entry (these entries may contain faces). */
7253 it
->face_id
= it
->saved_face_id
;
7255 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7257 int recheck_faces
= it
->ellipsis_p
;
7260 it
->method
= GET_FROM_C_STRING
;
7261 else if (STRINGP (it
->string
))
7262 it
->method
= GET_FROM_STRING
;
7265 it
->method
= GET_FROM_BUFFER
;
7266 it
->object
= it
->w
->contents
;
7270 it
->current
.dpvec_index
= -1;
7272 /* Skip over characters which were displayed via IT->dpvec. */
7273 if (it
->dpvec_char_len
< 0)
7274 reseat_at_next_visible_line_start (it
, 1);
7275 else if (it
->dpvec_char_len
> 0)
7277 if (it
->method
== GET_FROM_STRING
7278 && it
->current
.overlay_string_index
>= 0
7279 && it
->n_overlay_strings
> 0)
7280 it
->ignore_overlay_strings_at_pos_p
= true;
7281 it
->len
= it
->dpvec_char_len
;
7282 set_iterator_to_next (it
, reseat_p
);
7285 /* Maybe recheck faces after display vector. */
7287 it
->stop_charpos
= IT_CHARPOS (*it
);
7291 case GET_FROM_STRING
:
7292 /* Current display element is a character from a Lisp string. */
7293 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7294 /* Don't advance past string end. These conditions are true
7295 when set_iterator_to_next is called at the end of
7296 get_next_display_element, in which case the Lisp string is
7297 already exhausted, and all we want is pop the iterator
7299 if (it
->current
.overlay_string_index
>= 0)
7301 /* This is an overlay string, so there's no padding with
7302 spaces, and the number of characters in the string is
7303 where the string ends. */
7304 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7305 goto consider_string_end
;
7309 /* Not an overlay string. There could be padding, so test
7310 against it->end_charpos. */
7311 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7312 goto consider_string_end
;
7314 if (it
->cmp_it
.id
>= 0)
7320 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7321 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7322 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7323 it
->cmp_it
.from
= it
->cmp_it
.to
;
7327 composition_compute_stop_pos (&it
->cmp_it
,
7328 IT_STRING_CHARPOS (*it
),
7329 IT_STRING_BYTEPOS (*it
),
7330 it
->end_charpos
, it
->string
);
7333 else if (! it
->cmp_it
.reversed_p
)
7335 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7336 bidi_move_to_visually_next (&it
->bidi_it
);
7337 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7338 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7340 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7341 it
->cmp_it
.from
= it
->cmp_it
.to
;
7344 ptrdiff_t stop
= it
->end_charpos
;
7345 if (it
->bidi_it
.scan_dir
< 0)
7347 composition_compute_stop_pos (&it
->cmp_it
,
7348 IT_STRING_CHARPOS (*it
),
7349 IT_STRING_BYTEPOS (*it
), stop
,
7355 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7356 bidi_move_to_visually_next (&it
->bidi_it
);
7357 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7358 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7359 if (it
->cmp_it
.from
> 0)
7360 it
->cmp_it
.to
= it
->cmp_it
.from
;
7363 ptrdiff_t stop
= it
->end_charpos
;
7364 if (it
->bidi_it
.scan_dir
< 0)
7366 composition_compute_stop_pos (&it
->cmp_it
,
7367 IT_STRING_CHARPOS (*it
),
7368 IT_STRING_BYTEPOS (*it
), stop
,
7376 /* If the string position is beyond string's end, it
7377 means next_element_from_string is padding the string
7378 with blanks, in which case we bypass the bidi
7379 iterator, because it cannot deal with such virtual
7381 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7383 IT_STRING_BYTEPOS (*it
) += it
->len
;
7384 IT_STRING_CHARPOS (*it
) += 1;
7388 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7390 bidi_move_to_visually_next (&it
->bidi_it
);
7391 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7392 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7393 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7395 ptrdiff_t stop
= it
->end_charpos
;
7397 if (it
->bidi_it
.scan_dir
< 0)
7399 composition_compute_stop_pos (&it
->cmp_it
,
7400 IT_STRING_CHARPOS (*it
),
7401 IT_STRING_BYTEPOS (*it
), stop
,
7407 consider_string_end
:
7409 if (it
->current
.overlay_string_index
>= 0)
7411 /* IT->string is an overlay string. Advance to the
7412 next, if there is one. */
7413 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7416 next_overlay_string (it
);
7418 setup_for_ellipsis (it
, 0);
7423 /* IT->string is not an overlay string. If we reached
7424 its end, and there is something on IT->stack, proceed
7425 with what is on the stack. This can be either another
7426 string, this time an overlay string, or a buffer. */
7427 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7431 if (it
->method
== GET_FROM_STRING
)
7432 goto consider_string_end
;
7437 case GET_FROM_IMAGE
:
7438 case GET_FROM_STRETCH
:
7439 /* The position etc with which we have to proceed are on
7440 the stack. The position may be at the end of a string,
7441 if the `display' property takes up the whole string. */
7442 eassert (it
->sp
> 0);
7444 if (it
->method
== GET_FROM_STRING
)
7445 goto consider_string_end
;
7449 /* There are no other methods defined, so this should be a bug. */
7453 eassert (it
->method
!= GET_FROM_STRING
7454 || (STRINGP (it
->string
)
7455 && IT_STRING_CHARPOS (*it
) >= 0));
7458 /* Load IT's display element fields with information about the next
7459 display element which comes from a display table entry or from the
7460 result of translating a control character to one of the forms `^C'
7463 IT->dpvec holds the glyphs to return as characters.
7464 IT->saved_face_id holds the face id before the display vector--it
7465 is restored into IT->face_id in set_iterator_to_next. */
7468 next_element_from_display_vector (struct it
*it
)
7471 int prev_face_id
= it
->face_id
;
7475 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7477 it
->face_id
= it
->saved_face_id
;
7479 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7480 That seemed totally bogus - so I changed it... */
7481 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7483 if (GLYPH_CODE_P (gc
))
7485 struct face
*this_face
, *prev_face
, *next_face
;
7487 it
->c
= GLYPH_CODE_CHAR (gc
);
7488 it
->len
= CHAR_BYTES (it
->c
);
7490 /* The entry may contain a face id to use. Such a face id is
7491 the id of a Lisp face, not a realized face. A face id of
7492 zero means no face is specified. */
7493 if (it
->dpvec_face_id
>= 0)
7494 it
->face_id
= it
->dpvec_face_id
;
7497 int lface_id
= GLYPH_CODE_FACE (gc
);
7499 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7503 /* Glyphs in the display vector could have the box face, so we
7504 need to set the related flags in the iterator, as
7506 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7507 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7509 /* Is this character the first character of a box-face run? */
7510 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7512 || prev_face
->box
== FACE_NO_BOX
));
7514 /* For the last character of the box-face run, we need to look
7515 either at the next glyph from the display vector, or at the
7516 face we saw before the display vector. */
7517 next_face_id
= it
->saved_face_id
;
7518 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7520 if (it
->dpvec_face_id
>= 0)
7521 next_face_id
= it
->dpvec_face_id
;
7525 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7528 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7532 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7533 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7535 || next_face
->box
== FACE_NO_BOX
));
7536 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7539 /* Display table entry is invalid. Return a space. */
7540 it
->c
= ' ', it
->len
= 1;
7542 /* Don't change position and object of the iterator here. They are
7543 still the values of the character that had this display table
7544 entry or was translated, and that's what we want. */
7545 it
->what
= IT_CHARACTER
;
7549 /* Get the first element of string/buffer in the visual order, after
7550 being reseated to a new position in a string or a buffer. */
7552 get_visually_first_element (struct it
*it
)
7554 int string_p
= STRINGP (it
->string
) || it
->s
;
7555 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7556 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7558 if (STRINGP (it
->string
))
7560 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7561 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7565 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7566 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7569 if (it
->bidi_it
.charpos
== eob
)
7571 /* Nothing to do, but reset the FIRST_ELT flag, like
7572 bidi_paragraph_init does, because we are not going to
7574 it
->bidi_it
.first_elt
= 0;
7576 else if (it
->bidi_it
.charpos
== bob
7578 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7579 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7581 /* If we are at the beginning of a line/string, we can produce
7582 the next element right away. */
7583 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7584 bidi_move_to_visually_next (&it
->bidi_it
);
7588 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7590 /* We need to prime the bidi iterator starting at the line's or
7591 string's beginning, before we will be able to produce the
7594 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7596 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7597 IT_BYTEPOS (*it
), -1,
7598 &it
->bidi_it
.bytepos
);
7599 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7602 /* Now return to buffer/string position where we were asked
7603 to get the next display element, and produce that. */
7604 bidi_move_to_visually_next (&it
->bidi_it
);
7606 while (it
->bidi_it
.bytepos
!= orig_bytepos
7607 && it
->bidi_it
.charpos
< eob
);
7610 /* Adjust IT's position information to where we ended up. */
7611 if (STRINGP (it
->string
))
7613 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7614 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7618 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7619 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7622 if (STRINGP (it
->string
) || !it
->s
)
7624 ptrdiff_t stop
, charpos
, bytepos
;
7626 if (STRINGP (it
->string
))
7629 stop
= SCHARS (it
->string
);
7630 if (stop
> it
->end_charpos
)
7631 stop
= it
->end_charpos
;
7632 charpos
= IT_STRING_CHARPOS (*it
);
7633 bytepos
= IT_STRING_BYTEPOS (*it
);
7637 stop
= it
->end_charpos
;
7638 charpos
= IT_CHARPOS (*it
);
7639 bytepos
= IT_BYTEPOS (*it
);
7641 if (it
->bidi_it
.scan_dir
< 0)
7643 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7648 /* Load IT with the next display element from Lisp string IT->string.
7649 IT->current.string_pos is the current position within the string.
7650 If IT->current.overlay_string_index >= 0, the Lisp string is an
7654 next_element_from_string (struct it
*it
)
7656 struct text_pos position
;
7658 eassert (STRINGP (it
->string
));
7659 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7660 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7661 position
= it
->current
.string_pos
;
7663 /* With bidi reordering, the character to display might not be the
7664 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7665 that we were reseat()ed to a new string, whose paragraph
7666 direction is not known. */
7667 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7669 get_visually_first_element (it
);
7670 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7673 /* Time to check for invisible text? */
7674 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7676 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7679 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7680 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7682 /* With bidi non-linear iteration, we could find
7683 ourselves far beyond the last computed stop_charpos,
7684 with several other stop positions in between that we
7685 missed. Scan them all now, in buffer's logical
7686 order, until we find and handle the last stop_charpos
7687 that precedes our current position. */
7688 handle_stop_backwards (it
, it
->stop_charpos
);
7689 return GET_NEXT_DISPLAY_ELEMENT (it
);
7695 /* Take note of the stop position we just moved
7696 across, for when we will move back across it. */
7697 it
->prev_stop
= it
->stop_charpos
;
7698 /* If we are at base paragraph embedding level, take
7699 note of the last stop position seen at this
7701 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7702 it
->base_level_stop
= it
->stop_charpos
;
7706 /* Since a handler may have changed IT->method, we must
7708 return GET_NEXT_DISPLAY_ELEMENT (it
);
7712 /* If we are before prev_stop, we may have overstepped
7713 on our way backwards a stop_pos, and if so, we need
7714 to handle that stop_pos. */
7715 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7716 /* We can sometimes back up for reasons that have nothing
7717 to do with bidi reordering. E.g., compositions. The
7718 code below is only needed when we are above the base
7719 embedding level, so test for that explicitly. */
7720 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7722 /* If we lost track of base_level_stop, we have no better
7723 place for handle_stop_backwards to start from than string
7724 beginning. This happens, e.g., when we were reseated to
7725 the previous screenful of text by vertical-motion. */
7726 if (it
->base_level_stop
<= 0
7727 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7728 it
->base_level_stop
= 0;
7729 handle_stop_backwards (it
, it
->base_level_stop
);
7730 return GET_NEXT_DISPLAY_ELEMENT (it
);
7734 if (it
->current
.overlay_string_index
>= 0)
7736 /* Get the next character from an overlay string. In overlay
7737 strings, there is no field width or padding with spaces to
7739 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7744 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7745 IT_STRING_BYTEPOS (*it
),
7746 it
->bidi_it
.scan_dir
< 0
7748 : SCHARS (it
->string
))
7749 && next_element_from_composition (it
))
7753 else if (STRING_MULTIBYTE (it
->string
))
7755 const unsigned char *s
= (SDATA (it
->string
)
7756 + IT_STRING_BYTEPOS (*it
));
7757 it
->c
= string_char_and_length (s
, &it
->len
);
7761 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7767 /* Get the next character from a Lisp string that is not an
7768 overlay string. Such strings come from the mode line, for
7769 example. We may have to pad with spaces, or truncate the
7770 string. See also next_element_from_c_string. */
7771 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7776 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7778 /* Pad with spaces. */
7779 it
->c
= ' ', it
->len
= 1;
7780 CHARPOS (position
) = BYTEPOS (position
) = -1;
7782 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7783 IT_STRING_BYTEPOS (*it
),
7784 it
->bidi_it
.scan_dir
< 0
7786 : it
->string_nchars
)
7787 && next_element_from_composition (it
))
7791 else if (STRING_MULTIBYTE (it
->string
))
7793 const unsigned char *s
= (SDATA (it
->string
)
7794 + IT_STRING_BYTEPOS (*it
));
7795 it
->c
= string_char_and_length (s
, &it
->len
);
7799 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7804 /* Record what we have and where it came from. */
7805 it
->what
= IT_CHARACTER
;
7806 it
->object
= it
->string
;
7807 it
->position
= position
;
7812 /* Load IT with next display element from C string IT->s.
7813 IT->string_nchars is the maximum number of characters to return
7814 from the string. IT->end_charpos may be greater than
7815 IT->string_nchars when this function is called, in which case we
7816 may have to return padding spaces. Value is zero if end of string
7817 reached, including padding spaces. */
7820 next_element_from_c_string (struct it
*it
)
7822 bool success_p
= true;
7825 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7826 it
->what
= IT_CHARACTER
;
7827 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7830 /* With bidi reordering, the character to display might not be the
7831 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7832 we were reseated to a new string, whose paragraph direction is
7834 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7835 get_visually_first_element (it
);
7837 /* IT's position can be greater than IT->string_nchars in case a
7838 field width or precision has been specified when the iterator was
7840 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7842 /* End of the game. */
7846 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7848 /* Pad with spaces. */
7849 it
->c
= ' ', it
->len
= 1;
7850 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7852 else if (it
->multibyte_p
)
7853 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7855 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7861 /* Set up IT to return characters from an ellipsis, if appropriate.
7862 The definition of the ellipsis glyphs may come from a display table
7863 entry. This function fills IT with the first glyph from the
7864 ellipsis if an ellipsis is to be displayed. */
7867 next_element_from_ellipsis (struct it
*it
)
7869 if (it
->selective_display_ellipsis_p
)
7870 setup_for_ellipsis (it
, it
->len
);
7873 /* The face at the current position may be different from the
7874 face we find after the invisible text. Remember what it
7875 was in IT->saved_face_id, and signal that it's there by
7876 setting face_before_selective_p. */
7877 it
->saved_face_id
= it
->face_id
;
7878 it
->method
= GET_FROM_BUFFER
;
7879 it
->object
= it
->w
->contents
;
7880 reseat_at_next_visible_line_start (it
, 1);
7881 it
->face_before_selective_p
= true;
7884 return GET_NEXT_DISPLAY_ELEMENT (it
);
7888 /* Deliver an image display element. The iterator IT is already
7889 filled with image information (done in handle_display_prop). Value
7894 next_element_from_image (struct it
*it
)
7896 it
->what
= IT_IMAGE
;
7897 it
->ignore_overlay_strings_at_pos_p
= 0;
7902 /* Fill iterator IT with next display element from a stretch glyph
7903 property. IT->object is the value of the text property. Value is
7907 next_element_from_stretch (struct it
*it
)
7909 it
->what
= IT_STRETCH
;
7913 /* Scan backwards from IT's current position until we find a stop
7914 position, or until BEGV. This is called when we find ourself
7915 before both the last known prev_stop and base_level_stop while
7916 reordering bidirectional text. */
7919 compute_stop_pos_backwards (struct it
*it
)
7921 const int SCAN_BACK_LIMIT
= 1000;
7922 struct text_pos pos
;
7923 struct display_pos save_current
= it
->current
;
7924 struct text_pos save_position
= it
->position
;
7925 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7926 ptrdiff_t where_we_are
= charpos
;
7927 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7928 ptrdiff_t save_end_pos
= it
->end_charpos
;
7930 eassert (NILP (it
->string
) && !it
->s
);
7931 eassert (it
->bidi_p
);
7935 it
->end_charpos
= min (charpos
+ 1, ZV
);
7936 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7937 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7938 reseat_1 (it
, pos
, 0);
7939 compute_stop_pos (it
);
7940 /* We must advance forward, right? */
7941 if (it
->stop_charpos
<= charpos
)
7944 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7946 if (it
->stop_charpos
<= where_we_are
)
7947 it
->prev_stop
= it
->stop_charpos
;
7949 it
->prev_stop
= BEGV
;
7951 it
->current
= save_current
;
7952 it
->position
= save_position
;
7953 it
->stop_charpos
= save_stop_pos
;
7954 it
->end_charpos
= save_end_pos
;
7957 /* Scan forward from CHARPOS in the current buffer/string, until we
7958 find a stop position > current IT's position. Then handle the stop
7959 position before that. This is called when we bump into a stop
7960 position while reordering bidirectional text. CHARPOS should be
7961 the last previously processed stop_pos (or BEGV/0, if none were
7962 processed yet) whose position is less that IT's current
7966 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7968 int bufp
= !STRINGP (it
->string
);
7969 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7970 struct display_pos save_current
= it
->current
;
7971 struct text_pos save_position
= it
->position
;
7972 struct text_pos pos1
;
7973 ptrdiff_t next_stop
;
7975 /* Scan in strict logical order. */
7976 eassert (it
->bidi_p
);
7980 it
->prev_stop
= charpos
;
7983 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7984 reseat_1 (it
, pos1
, 0);
7987 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7988 compute_stop_pos (it
);
7989 /* We must advance forward, right? */
7990 if (it
->stop_charpos
<= it
->prev_stop
)
7992 charpos
= it
->stop_charpos
;
7994 while (charpos
<= where_we_are
);
7997 it
->current
= save_current
;
7998 it
->position
= save_position
;
7999 next_stop
= it
->stop_charpos
;
8000 it
->stop_charpos
= it
->prev_stop
;
8002 it
->stop_charpos
= next_stop
;
8005 /* Load IT with the next display element from current_buffer. Value
8006 is zero if end of buffer reached. IT->stop_charpos is the next
8007 position at which to stop and check for text properties or buffer
8011 next_element_from_buffer (struct it
*it
)
8013 bool success_p
= true;
8015 eassert (IT_CHARPOS (*it
) >= BEGV
);
8016 eassert (NILP (it
->string
) && !it
->s
);
8017 eassert (!it
->bidi_p
8018 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8019 && it
->bidi_it
.string
.s
== NULL
));
8021 /* With bidi reordering, the character to display might not be the
8022 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8023 we were reseat()ed to a new buffer position, which is potentially
8024 a different paragraph. */
8025 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8027 get_visually_first_element (it
);
8028 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8031 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8033 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8035 int overlay_strings_follow_p
;
8037 /* End of the game, except when overlay strings follow that
8038 haven't been returned yet. */
8039 if (it
->overlay_strings_at_end_processed_p
)
8040 overlay_strings_follow_p
= 0;
8043 it
->overlay_strings_at_end_processed_p
= true;
8044 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8047 if (overlay_strings_follow_p
)
8048 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8052 it
->position
= it
->current
.pos
;
8056 else if (!(!it
->bidi_p
8057 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8058 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8060 /* With bidi non-linear iteration, we could find ourselves
8061 far beyond the last computed stop_charpos, with several
8062 other stop positions in between that we missed. Scan
8063 them all now, in buffer's logical order, until we find
8064 and handle the last stop_charpos that precedes our
8065 current position. */
8066 handle_stop_backwards (it
, it
->stop_charpos
);
8067 return GET_NEXT_DISPLAY_ELEMENT (it
);
8073 /* Take note of the stop position we just moved across,
8074 for when we will move back across it. */
8075 it
->prev_stop
= it
->stop_charpos
;
8076 /* If we are at base paragraph embedding level, take
8077 note of the last stop position seen at this
8079 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8080 it
->base_level_stop
= it
->stop_charpos
;
8083 return GET_NEXT_DISPLAY_ELEMENT (it
);
8087 /* If we are before prev_stop, we may have overstepped on
8088 our way backwards a stop_pos, and if so, we need to
8089 handle that stop_pos. */
8090 && IT_CHARPOS (*it
) < it
->prev_stop
8091 /* We can sometimes back up for reasons that have nothing
8092 to do with bidi reordering. E.g., compositions. The
8093 code below is only needed when we are above the base
8094 embedding level, so test for that explicitly. */
8095 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8097 if (it
->base_level_stop
<= 0
8098 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8100 /* If we lost track of base_level_stop, we need to find
8101 prev_stop by looking backwards. This happens, e.g., when
8102 we were reseated to the previous screenful of text by
8104 it
->base_level_stop
= BEGV
;
8105 compute_stop_pos_backwards (it
);
8106 handle_stop_backwards (it
, it
->prev_stop
);
8109 handle_stop_backwards (it
, it
->base_level_stop
);
8110 return GET_NEXT_DISPLAY_ELEMENT (it
);
8114 /* No face changes, overlays etc. in sight, so just return a
8115 character from current_buffer. */
8119 /* Maybe run the redisplay end trigger hook. Performance note:
8120 This doesn't seem to cost measurable time. */
8121 if (it
->redisplay_end_trigger_charpos
8123 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8124 run_redisplay_end_trigger_hook (it
);
8126 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8127 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8129 && next_element_from_composition (it
))
8134 /* Get the next character, maybe multibyte. */
8135 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8136 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8137 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8139 it
->c
= *p
, it
->len
= 1;
8141 /* Record what we have and where it came from. */
8142 it
->what
= IT_CHARACTER
;
8143 it
->object
= it
->w
->contents
;
8144 it
->position
= it
->current
.pos
;
8146 /* Normally we return the character found above, except when we
8147 really want to return an ellipsis for selective display. */
8152 /* A value of selective > 0 means hide lines indented more
8153 than that number of columns. */
8154 if (it
->selective
> 0
8155 && IT_CHARPOS (*it
) + 1 < ZV
8156 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8157 IT_BYTEPOS (*it
) + 1,
8160 success_p
= next_element_from_ellipsis (it
);
8161 it
->dpvec_char_len
= -1;
8164 else if (it
->c
== '\r' && it
->selective
== -1)
8166 /* A value of selective == -1 means that everything from the
8167 CR to the end of the line is invisible, with maybe an
8168 ellipsis displayed for it. */
8169 success_p
= next_element_from_ellipsis (it
);
8170 it
->dpvec_char_len
= -1;
8175 /* Value is zero if end of buffer reached. */
8176 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8181 /* Run the redisplay end trigger hook for IT. */
8184 run_redisplay_end_trigger_hook (struct it
*it
)
8186 Lisp_Object args
[3];
8188 /* IT->glyph_row should be non-null, i.e. we should be actually
8189 displaying something, or otherwise we should not run the hook. */
8190 eassert (it
->glyph_row
);
8192 /* Set up hook arguments. */
8193 args
[0] = Qredisplay_end_trigger_functions
;
8194 args
[1] = it
->window
;
8195 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8196 it
->redisplay_end_trigger_charpos
= 0;
8198 /* Since we are *trying* to run these functions, don't try to run
8199 them again, even if they get an error. */
8200 wset_redisplay_end_trigger (it
->w
, Qnil
);
8201 Frun_hook_with_args (3, args
);
8203 /* Notice if it changed the face of the character we are on. */
8204 handle_face_prop (it
);
8208 /* Deliver a composition display element. Unlike the other
8209 next_element_from_XXX, this function is not registered in the array
8210 get_next_element[]. It is called from next_element_from_buffer and
8211 next_element_from_string when necessary. */
8214 next_element_from_composition (struct it
*it
)
8216 it
->what
= IT_COMPOSITION
;
8217 it
->len
= it
->cmp_it
.nbytes
;
8218 if (STRINGP (it
->string
))
8222 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8223 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8226 it
->position
= it
->current
.string_pos
;
8227 it
->object
= it
->string
;
8228 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8229 IT_STRING_BYTEPOS (*it
), it
->string
);
8235 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8236 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8239 if (it
->bidi_it
.new_paragraph
)
8240 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8241 /* Resync the bidi iterator with IT's new position.
8242 FIXME: this doesn't support bidirectional text. */
8243 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8244 bidi_move_to_visually_next (&it
->bidi_it
);
8248 it
->position
= it
->current
.pos
;
8249 it
->object
= it
->w
->contents
;
8250 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8251 IT_BYTEPOS (*it
), Qnil
);
8258 /***********************************************************************
8259 Moving an iterator without producing glyphs
8260 ***********************************************************************/
8262 /* Check if iterator is at a position corresponding to a valid buffer
8263 position after some move_it_ call. */
8265 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8266 ((it)->method == GET_FROM_STRING \
8267 ? IT_STRING_CHARPOS (*it) == 0 \
8271 /* Move iterator IT to a specified buffer or X position within one
8272 line on the display without producing glyphs.
8274 OP should be a bit mask including some or all of these bits:
8275 MOVE_TO_X: Stop upon reaching x-position TO_X.
8276 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8277 Regardless of OP's value, stop upon reaching the end of the display line.
8279 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8280 This means, in particular, that TO_X includes window's horizontal
8283 The return value has several possible values that
8284 say what condition caused the scan to stop:
8286 MOVE_POS_MATCH_OR_ZV
8287 - when TO_POS or ZV was reached.
8290 -when TO_X was reached before TO_POS or ZV were reached.
8293 - when we reached the end of the display area and the line must
8297 - when we reached the end of the display area and the line is
8301 - when we stopped at a line end, i.e. a newline or a CR and selective
8304 static enum move_it_result
8305 move_it_in_display_line_to (struct it
*it
,
8306 ptrdiff_t to_charpos
, int to_x
,
8307 enum move_operation_enum op
)
8309 enum move_it_result result
= MOVE_UNDEFINED
;
8310 struct glyph_row
*saved_glyph_row
;
8311 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8312 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8313 void *ppos_data
= NULL
;
8315 enum it_method prev_method
= it
->method
;
8316 ptrdiff_t closest_pos
, prev_pos
= IT_CHARPOS (*it
);
8317 int saw_smaller_pos
= prev_pos
< to_charpos
;
8319 /* Don't produce glyphs in produce_glyphs. */
8320 saved_glyph_row
= it
->glyph_row
;
8321 it
->glyph_row
= NULL
;
8323 /* Use wrap_it to save a copy of IT wherever a word wrap could
8324 occur. Use atpos_it to save a copy of IT at the desired buffer
8325 position, if found, so that we can scan ahead and check if the
8326 word later overshoots the window edge. Use atx_it similarly, for
8332 /* Use ppos_it under bidi reordering to save a copy of IT for the
8333 initial position. We restore that position in IT when we have
8334 scanned the entire display line without finding a match for
8335 TO_CHARPOS and all the character positions are greater than
8336 TO_CHARPOS. We then restart the scan from the initial position,
8337 and stop at CLOSEST_POS, which is a position > TO_CHARPOS that is
8338 the closest to TO_CHARPOS. */
8341 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8343 SAVE_IT (ppos_it
, *it
, ppos_data
);
8344 closest_pos
= IT_CHARPOS (*it
);
8350 #define BUFFER_POS_REACHED_P() \
8351 ((op & MOVE_TO_POS) != 0 \
8352 && BUFFERP (it->object) \
8353 && (IT_CHARPOS (*it) == to_charpos \
8355 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8356 && IT_CHARPOS (*it) > to_charpos) \
8357 || (it->what == IT_COMPOSITION \
8358 && ((IT_CHARPOS (*it) > to_charpos \
8359 && to_charpos >= it->cmp_it.charpos) \
8360 || (IT_CHARPOS (*it) < to_charpos \
8361 && to_charpos <= it->cmp_it.charpos)))) \
8362 && (it->method == GET_FROM_BUFFER \
8363 || (it->method == GET_FROM_DISPLAY_VECTOR \
8364 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8366 /* If there's a line-/wrap-prefix, handle it. */
8367 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8368 && it
->current_y
< it
->last_visible_y
)
8369 handle_line_prefix (it
);
8371 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8372 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8376 int x
, i
, ascent
= 0, descent
= 0;
8378 /* Utility macro to reset an iterator with x, ascent, and descent. */
8379 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8380 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8381 (IT)->max_descent = descent)
8383 /* Stop if we move beyond TO_CHARPOS (after an image or a
8384 display string or stretch glyph). */
8385 if ((op
& MOVE_TO_POS
) != 0
8386 && BUFFERP (it
->object
)
8387 && it
->method
== GET_FROM_BUFFER
8389 /* When the iterator is at base embedding level, we
8390 are guaranteed that characters are delivered for
8391 display in strictly increasing order of their
8392 buffer positions. */
8393 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8394 && IT_CHARPOS (*it
) > to_charpos
)
8396 && (prev_method
== GET_FROM_IMAGE
8397 || prev_method
== GET_FROM_STRETCH
8398 || prev_method
== GET_FROM_STRING
)
8399 /* Passed TO_CHARPOS from left to right. */
8400 && ((prev_pos
< to_charpos
8401 && IT_CHARPOS (*it
) > to_charpos
)
8402 /* Passed TO_CHARPOS from right to left. */
8403 || (prev_pos
> to_charpos
8404 && IT_CHARPOS (*it
) < to_charpos
)))))
8406 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8408 result
= MOVE_POS_MATCH_OR_ZV
;
8411 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8412 /* If wrap_it is valid, the current position might be in a
8413 word that is wrapped. So, save the iterator in
8414 atpos_it and continue to see if wrapping happens. */
8415 SAVE_IT (atpos_it
, *it
, atpos_data
);
8418 /* Stop when ZV reached.
8419 We used to stop here when TO_CHARPOS reached as well, but that is
8420 too soon if this glyph does not fit on this line. So we handle it
8421 explicitly below. */
8422 if (!get_next_display_element (it
))
8424 result
= MOVE_POS_MATCH_OR_ZV
;
8428 if (it
->line_wrap
== TRUNCATE
)
8430 if (BUFFER_POS_REACHED_P ())
8432 result
= MOVE_POS_MATCH_OR_ZV
;
8438 if (it
->line_wrap
== WORD_WRAP
)
8440 if (IT_DISPLAYING_WHITESPACE (it
))
8444 /* We have reached a glyph that follows one or more
8445 whitespace characters. If the position is
8446 already found, we are done. */
8447 if (atpos_it
.sp
>= 0)
8449 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8450 result
= MOVE_POS_MATCH_OR_ZV
;
8455 RESTORE_IT (it
, &atx_it
, atx_data
);
8456 result
= MOVE_X_REACHED
;
8459 /* Otherwise, we can wrap here. */
8460 SAVE_IT (wrap_it
, *it
, wrap_data
);
8466 /* Remember the line height for the current line, in case
8467 the next element doesn't fit on the line. */
8468 ascent
= it
->max_ascent
;
8469 descent
= it
->max_descent
;
8471 /* The call to produce_glyphs will get the metrics of the
8472 display element IT is loaded with. Record the x-position
8473 before this display element, in case it doesn't fit on the
8477 PRODUCE_GLYPHS (it
);
8479 if (it
->area
!= TEXT_AREA
)
8481 prev_method
= it
->method
;
8482 if (it
->method
== GET_FROM_BUFFER
)
8483 prev_pos
= IT_CHARPOS (*it
);
8484 set_iterator_to_next (it
, 1);
8485 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8486 SET_TEXT_POS (this_line_min_pos
,
8487 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8489 && (op
& MOVE_TO_POS
)
8490 && IT_CHARPOS (*it
) > to_charpos
8491 && IT_CHARPOS (*it
) < closest_pos
)
8492 closest_pos
= IT_CHARPOS (*it
);
8496 /* The number of glyphs we get back in IT->nglyphs will normally
8497 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8498 character on a terminal frame, or (iii) a line end. For the
8499 second case, IT->nglyphs - 1 padding glyphs will be present.
8500 (On X frames, there is only one glyph produced for a
8501 composite character.)
8503 The behavior implemented below means, for continuation lines,
8504 that as many spaces of a TAB as fit on the current line are
8505 displayed there. For terminal frames, as many glyphs of a
8506 multi-glyph character are displayed in the current line, too.
8507 This is what the old redisplay code did, and we keep it that
8508 way. Under X, the whole shape of a complex character must
8509 fit on the line or it will be completely displayed in the
8512 Note that both for tabs and padding glyphs, all glyphs have
8516 /* More than one glyph or glyph doesn't fit on line. All
8517 glyphs have the same width. */
8518 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8520 int x_before_this_char
= x
;
8521 int hpos_before_this_char
= it
->hpos
;
8523 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8525 new_x
= x
+ single_glyph_width
;
8527 /* We want to leave anything reaching TO_X to the caller. */
8528 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8530 if (BUFFER_POS_REACHED_P ())
8532 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8533 goto buffer_pos_reached
;
8534 if (atpos_it
.sp
< 0)
8536 SAVE_IT (atpos_it
, *it
, atpos_data
);
8537 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8542 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8545 result
= MOVE_X_REACHED
;
8550 SAVE_IT (atx_it
, *it
, atx_data
);
8551 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8556 if (/* Lines are continued. */
8557 it
->line_wrap
!= TRUNCATE
8558 && (/* And glyph doesn't fit on the line. */
8559 new_x
> it
->last_visible_x
8560 /* Or it fits exactly and we're on a window
8562 || (new_x
== it
->last_visible_x
8563 && FRAME_WINDOW_P (it
->f
)
8564 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8565 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8566 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8568 if (/* IT->hpos == 0 means the very first glyph
8569 doesn't fit on the line, e.g. a wide image. */
8571 || (new_x
== it
->last_visible_x
8572 && FRAME_WINDOW_P (it
->f
)))
8575 it
->current_x
= new_x
;
8577 /* The character's last glyph just barely fits
8579 if (i
== it
->nglyphs
- 1)
8581 /* If this is the destination position,
8582 return a position *before* it in this row,
8583 now that we know it fits in this row. */
8584 if (BUFFER_POS_REACHED_P ())
8586 if (it
->line_wrap
!= WORD_WRAP
8589 it
->hpos
= hpos_before_this_char
;
8590 it
->current_x
= x_before_this_char
;
8591 result
= MOVE_POS_MATCH_OR_ZV
;
8594 if (it
->line_wrap
== WORD_WRAP
8597 SAVE_IT (atpos_it
, *it
, atpos_data
);
8598 atpos_it
.current_x
= x_before_this_char
;
8599 atpos_it
.hpos
= hpos_before_this_char
;
8603 prev_method
= it
->method
;
8604 if (it
->method
== GET_FROM_BUFFER
)
8605 prev_pos
= IT_CHARPOS (*it
);
8606 set_iterator_to_next (it
, 1);
8607 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8608 SET_TEXT_POS (this_line_min_pos
,
8609 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8610 /* On graphical terminals, newlines may
8611 "overflow" into the fringe if
8612 overflow-newline-into-fringe is non-nil.
8613 On text terminals, and on graphical
8614 terminals with no right margin, newlines
8615 may overflow into the last glyph on the
8617 if (!FRAME_WINDOW_P (it
->f
)
8619 && it
->bidi_it
.paragraph_dir
== R2L
)
8620 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8621 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8622 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8624 if (!get_next_display_element (it
))
8626 result
= MOVE_POS_MATCH_OR_ZV
;
8629 if (BUFFER_POS_REACHED_P ())
8631 if (ITERATOR_AT_END_OF_LINE_P (it
))
8632 result
= MOVE_POS_MATCH_OR_ZV
;
8634 result
= MOVE_LINE_CONTINUED
;
8637 if (ITERATOR_AT_END_OF_LINE_P (it
)
8638 && (it
->line_wrap
!= WORD_WRAP
8641 result
= MOVE_NEWLINE_OR_CR
;
8648 IT_RESET_X_ASCENT_DESCENT (it
);
8650 if (wrap_it
.sp
>= 0)
8652 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8657 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8659 result
= MOVE_LINE_CONTINUED
;
8663 if (BUFFER_POS_REACHED_P ())
8665 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8666 goto buffer_pos_reached
;
8667 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8669 SAVE_IT (atpos_it
, *it
, atpos_data
);
8670 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8674 if (new_x
> it
->first_visible_x
)
8676 /* Glyph is visible. Increment number of glyphs that
8677 would be displayed. */
8682 if (result
!= MOVE_UNDEFINED
)
8685 else if (BUFFER_POS_REACHED_P ())
8688 IT_RESET_X_ASCENT_DESCENT (it
);
8689 result
= MOVE_POS_MATCH_OR_ZV
;
8692 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8694 /* Stop when TO_X specified and reached. This check is
8695 necessary here because of lines consisting of a line end,
8696 only. The line end will not produce any glyphs and we
8697 would never get MOVE_X_REACHED. */
8698 eassert (it
->nglyphs
== 0);
8699 result
= MOVE_X_REACHED
;
8703 /* Is this a line end? If yes, we're done. */
8704 if (ITERATOR_AT_END_OF_LINE_P (it
))
8706 /* If we are past TO_CHARPOS, but never saw any character
8707 positions smaller than TO_CHARPOS, return
8708 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8710 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8712 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8714 if (closest_pos
< ZV
)
8716 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8717 move_it_in_display_line_to (it
, closest_pos
, -1,
8719 result
= MOVE_POS_MATCH_OR_ZV
;
8722 goto buffer_pos_reached
;
8724 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8725 && IT_CHARPOS (*it
) > to_charpos
)
8726 goto buffer_pos_reached
;
8728 result
= MOVE_NEWLINE_OR_CR
;
8731 result
= MOVE_NEWLINE_OR_CR
;
8735 prev_method
= it
->method
;
8736 if (it
->method
== GET_FROM_BUFFER
)
8737 prev_pos
= IT_CHARPOS (*it
);
8738 /* The current display element has been consumed. Advance
8740 set_iterator_to_next (it
, 1);
8741 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8742 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8743 if (IT_CHARPOS (*it
) < to_charpos
)
8744 saw_smaller_pos
= 1;
8746 && (op
& MOVE_TO_POS
)
8747 && IT_CHARPOS (*it
) >= to_charpos
8748 && IT_CHARPOS (*it
) < closest_pos
)
8749 closest_pos
= IT_CHARPOS (*it
);
8751 /* Stop if lines are truncated and IT's current x-position is
8752 past the right edge of the window now. */
8753 if (it
->line_wrap
== TRUNCATE
8754 && it
->current_x
>= it
->last_visible_x
)
8756 if (!FRAME_WINDOW_P (it
->f
)
8757 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8758 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8759 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8760 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8764 if ((at_eob_p
= !get_next_display_element (it
))
8765 || BUFFER_POS_REACHED_P ()
8766 /* If we are past TO_CHARPOS, but never saw any
8767 character positions smaller than TO_CHARPOS,
8768 return MOVE_POS_MATCH_OR_ZV, like the
8769 unidirectional display did. */
8770 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8772 && IT_CHARPOS (*it
) > to_charpos
))
8775 && !BUFFER_POS_REACHED_P ()
8776 && !at_eob_p
&& closest_pos
< ZV
)
8778 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8779 move_it_in_display_line_to (it
, closest_pos
, -1,
8782 result
= MOVE_POS_MATCH_OR_ZV
;
8785 if (ITERATOR_AT_END_OF_LINE_P (it
))
8787 result
= MOVE_NEWLINE_OR_CR
;
8791 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8793 && IT_CHARPOS (*it
) > to_charpos
)
8795 if (closest_pos
< ZV
)
8797 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8798 move_it_in_display_line_to (it
, closest_pos
, -1, MOVE_TO_POS
);
8800 result
= MOVE_POS_MATCH_OR_ZV
;
8803 result
= MOVE_LINE_TRUNCATED
;
8806 #undef IT_RESET_X_ASCENT_DESCENT
8809 #undef BUFFER_POS_REACHED_P
8811 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8812 restore the saved iterator. */
8813 if (atpos_it
.sp
>= 0)
8814 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8815 else if (atx_it
.sp
>= 0)
8816 RESTORE_IT (it
, &atx_it
, atx_data
);
8821 bidi_unshelve_cache (atpos_data
, 1);
8823 bidi_unshelve_cache (atx_data
, 1);
8825 bidi_unshelve_cache (wrap_data
, 1);
8827 bidi_unshelve_cache (ppos_data
, 1);
8829 /* Restore the iterator settings altered at the beginning of this
8831 it
->glyph_row
= saved_glyph_row
;
8835 /* For external use. */
8837 move_it_in_display_line (struct it
*it
,
8838 ptrdiff_t to_charpos
, int to_x
,
8839 enum move_operation_enum op
)
8841 if (it
->line_wrap
== WORD_WRAP
8842 && (op
& MOVE_TO_X
))
8845 void *save_data
= NULL
;
8848 SAVE_IT (save_it
, *it
, save_data
);
8849 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8850 /* When word-wrap is on, TO_X may lie past the end
8851 of a wrapped line. Then it->current is the
8852 character on the next line, so backtrack to the
8853 space before the wrap point. */
8854 if (skip
== MOVE_LINE_CONTINUED
)
8856 int prev_x
= max (it
->current_x
- 1, 0);
8857 RESTORE_IT (it
, &save_it
, save_data
);
8858 move_it_in_display_line_to
8859 (it
, -1, prev_x
, MOVE_TO_X
);
8862 bidi_unshelve_cache (save_data
, 1);
8865 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8869 /* Move IT forward until it satisfies one or more of the criteria in
8870 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8872 OP is a bit-mask that specifies where to stop, and in particular,
8873 which of those four position arguments makes a difference. See the
8874 description of enum move_operation_enum.
8876 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8877 screen line, this function will set IT to the next position that is
8878 displayed to the right of TO_CHARPOS on the screen.
8880 Return the maximum pixel length of any line scanned but never more
8881 than it.last_visible_x. */
8884 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8886 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8887 int line_height
, line_start_x
= 0, reached
= 0;
8888 int max_current_x
= 0;
8889 void *backup_data
= NULL
;
8893 if (op
& MOVE_TO_VPOS
)
8895 /* If no TO_CHARPOS and no TO_X specified, stop at the
8896 start of the line TO_VPOS. */
8897 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8899 if (it
->vpos
== to_vpos
)
8905 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8909 /* TO_VPOS >= 0 means stop at TO_X in the line at
8910 TO_VPOS, or at TO_POS, whichever comes first. */
8911 if (it
->vpos
== to_vpos
)
8917 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8919 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8924 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8926 /* We have reached TO_X but not in the line we want. */
8927 skip
= move_it_in_display_line_to (it
, to_charpos
,
8929 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8937 else if (op
& MOVE_TO_Y
)
8939 struct it it_backup
;
8941 if (it
->line_wrap
== WORD_WRAP
)
8942 SAVE_IT (it_backup
, *it
, backup_data
);
8944 /* TO_Y specified means stop at TO_X in the line containing
8945 TO_Y---or at TO_CHARPOS if this is reached first. The
8946 problem is that we can't really tell whether the line
8947 contains TO_Y before we have completely scanned it, and
8948 this may skip past TO_X. What we do is to first scan to
8951 If TO_X is not specified, use a TO_X of zero. The reason
8952 is to make the outcome of this function more predictable.
8953 If we didn't use TO_X == 0, we would stop at the end of
8954 the line which is probably not what a caller would expect
8956 skip
= move_it_in_display_line_to
8957 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8958 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8960 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8961 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8963 else if (skip
== MOVE_X_REACHED
)
8965 /* If TO_X was reached, we want to know whether TO_Y is
8966 in the line. We know this is the case if the already
8967 scanned glyphs make the line tall enough. Otherwise,
8968 we must check by scanning the rest of the line. */
8969 line_height
= it
->max_ascent
+ it
->max_descent
;
8970 if (to_y
>= it
->current_y
8971 && to_y
< it
->current_y
+ line_height
)
8976 SAVE_IT (it_backup
, *it
, backup_data
);
8977 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8978 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8980 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8981 line_height
= it
->max_ascent
+ it
->max_descent
;
8982 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8984 if (to_y
>= it
->current_y
8985 && to_y
< it
->current_y
+ line_height
)
8987 /* If TO_Y is in this line and TO_X was reached
8988 above, we scanned too far. We have to restore
8989 IT's settings to the ones before skipping. But
8990 keep the more accurate values of max_ascent and
8991 max_descent we've found while skipping the rest
8992 of the line, for the sake of callers, such as
8993 pos_visible_p, that need to know the line
8995 int max_ascent
= it
->max_ascent
;
8996 int max_descent
= it
->max_descent
;
8998 RESTORE_IT (it
, &it_backup
, backup_data
);
8999 it
->max_ascent
= max_ascent
;
9000 it
->max_descent
= max_descent
;
9006 if (skip
== MOVE_POS_MATCH_OR_ZV
)
9012 /* Check whether TO_Y is in this line. */
9013 line_height
= it
->max_ascent
+ it
->max_descent
;
9014 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9016 if (to_y
>= it
->current_y
9017 && to_y
< it
->current_y
+ line_height
)
9019 if (to_y
> it
->current_y
)
9020 max_current_x
= max (it
->current_x
, max_current_x
);
9022 /* When word-wrap is on, TO_X may lie past the end
9023 of a wrapped line. Then it->current is the
9024 character on the next line, so backtrack to the
9025 space before the wrap point. */
9026 if (skip
== MOVE_LINE_CONTINUED
9027 && it
->line_wrap
== WORD_WRAP
)
9029 int prev_x
= max (it
->current_x
- 1, 0);
9030 RESTORE_IT (it
, &it_backup
, backup_data
);
9031 skip
= move_it_in_display_line_to
9032 (it
, -1, prev_x
, MOVE_TO_X
);
9041 max_current_x
= max (it
->current_x
, max_current_x
);
9045 else if (BUFFERP (it
->object
)
9046 && (it
->method
== GET_FROM_BUFFER
9047 || it
->method
== GET_FROM_STRETCH
)
9048 && IT_CHARPOS (*it
) >= to_charpos
9049 /* Under bidi iteration, a call to set_iterator_to_next
9050 can scan far beyond to_charpos if the initial
9051 portion of the next line needs to be reordered. In
9052 that case, give move_it_in_display_line_to another
9055 && it
->bidi_it
.scan_dir
== -1))
9056 skip
= MOVE_POS_MATCH_OR_ZV
;
9058 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9062 case MOVE_POS_MATCH_OR_ZV
:
9063 max_current_x
= max (it
->current_x
, max_current_x
);
9067 case MOVE_NEWLINE_OR_CR
:
9068 max_current_x
= max (it
->current_x
, max_current_x
);
9069 set_iterator_to_next (it
, 1);
9070 it
->continuation_lines_width
= 0;
9073 case MOVE_LINE_TRUNCATED
:
9074 max_current_x
= it
->last_visible_x
;
9075 it
->continuation_lines_width
= 0;
9076 reseat_at_next_visible_line_start (it
, 0);
9077 if ((op
& MOVE_TO_POS
) != 0
9078 && IT_CHARPOS (*it
) > to_charpos
)
9085 case MOVE_LINE_CONTINUED
:
9086 max_current_x
= it
->last_visible_x
;
9087 /* For continued lines ending in a tab, some of the glyphs
9088 associated with the tab are displayed on the current
9089 line. Since it->current_x does not include these glyphs,
9090 we use it->last_visible_x instead. */
9093 it
->continuation_lines_width
+= it
->last_visible_x
;
9094 /* When moving by vpos, ensure that the iterator really
9095 advances to the next line (bug#847, bug#969). Fixme:
9096 do we need to do this in other circumstances? */
9097 if (it
->current_x
!= it
->last_visible_x
9098 && (op
& MOVE_TO_VPOS
)
9099 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9101 line_start_x
= it
->current_x
+ it
->pixel_width
9102 - it
->last_visible_x
;
9103 set_iterator_to_next (it
, 0);
9107 it
->continuation_lines_width
+= it
->current_x
;
9114 /* Reset/increment for the next run. */
9115 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9116 it
->current_x
= line_start_x
;
9119 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9121 last_height
= it
->max_ascent
+ it
->max_descent
;
9122 it
->max_ascent
= it
->max_descent
= 0;
9127 /* On text terminals, we may stop at the end of a line in the middle
9128 of a multi-character glyph. If the glyph itself is continued,
9129 i.e. it is actually displayed on the next line, don't treat this
9130 stopping point as valid; move to the next line instead (unless
9131 that brings us offscreen). */
9132 if (!FRAME_WINDOW_P (it
->f
)
9134 && IT_CHARPOS (*it
) == to_charpos
9135 && it
->what
== IT_CHARACTER
9137 && it
->line_wrap
== WINDOW_WRAP
9138 && it
->current_x
== it
->last_visible_x
- 1
9141 && it
->vpos
< it
->w
->window_end_vpos
)
9143 it
->continuation_lines_width
+= it
->current_x
;
9144 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9145 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9147 last_height
= it
->max_ascent
+ it
->max_descent
;
9151 bidi_unshelve_cache (backup_data
, 1);
9153 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9155 return max_current_x
;
9159 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9161 If DY > 0, move IT backward at least that many pixels. DY = 0
9162 means move IT backward to the preceding line start or BEGV. This
9163 function may move over more than DY pixels if IT->current_y - DY
9164 ends up in the middle of a line; in this case IT->current_y will be
9165 set to the top of the line moved to. */
9168 move_it_vertically_backward (struct it
*it
, int dy
)
9172 void *it2data
= NULL
, *it3data
= NULL
;
9173 ptrdiff_t start_pos
;
9175 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9176 ptrdiff_t pos_limit
;
9181 start_pos
= IT_CHARPOS (*it
);
9183 /* Estimate how many newlines we must move back. */
9184 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9185 if (it
->line_wrap
== TRUNCATE
)
9188 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9190 /* Set the iterator's position that many lines back. But don't go
9191 back more than NLINES full screen lines -- this wins a day with
9192 buffers which have very long lines. */
9193 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9194 back_to_previous_visible_line_start (it
);
9196 /* Reseat the iterator here. When moving backward, we don't want
9197 reseat to skip forward over invisible text, set up the iterator
9198 to deliver from overlay strings at the new position etc. So,
9199 use reseat_1 here. */
9200 reseat_1 (it
, it
->current
.pos
, 1);
9202 /* We are now surely at a line start. */
9203 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9204 reordering is in effect. */
9205 it
->continuation_lines_width
= 0;
9207 /* Move forward and see what y-distance we moved. First move to the
9208 start of the next line so that we get its height. We need this
9209 height to be able to tell whether we reached the specified
9211 SAVE_IT (it2
, *it
, it2data
);
9212 it2
.max_ascent
= it2
.max_descent
= 0;
9215 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9216 MOVE_TO_POS
| MOVE_TO_VPOS
);
9218 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9219 /* If we are in a display string which starts at START_POS,
9220 and that display string includes a newline, and we are
9221 right after that newline (i.e. at the beginning of a
9222 display line), exit the loop, because otherwise we will
9223 infloop, since move_it_to will see that it is already at
9224 START_POS and will not move. */
9225 || (it2
.method
== GET_FROM_STRING
9226 && IT_CHARPOS (it2
) == start_pos
9227 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9228 eassert (IT_CHARPOS (*it
) >= BEGV
);
9229 SAVE_IT (it3
, it2
, it3data
);
9231 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9232 eassert (IT_CHARPOS (*it
) >= BEGV
);
9233 /* H is the actual vertical distance from the position in *IT
9234 and the starting position. */
9235 h
= it2
.current_y
- it
->current_y
;
9236 /* NLINES is the distance in number of lines. */
9237 nlines
= it2
.vpos
- it
->vpos
;
9239 /* Correct IT's y and vpos position
9240 so that they are relative to the starting point. */
9246 /* DY == 0 means move to the start of the screen line. The
9247 value of nlines is > 0 if continuation lines were involved,
9248 or if the original IT position was at start of a line. */
9249 RESTORE_IT (it
, it
, it2data
);
9251 move_it_by_lines (it
, nlines
);
9252 /* The above code moves us to some position NLINES down,
9253 usually to its first glyph (leftmost in an L2R line), but
9254 that's not necessarily the start of the line, under bidi
9255 reordering. We want to get to the character position
9256 that is immediately after the newline of the previous
9259 && !it
->continuation_lines_width
9260 && !STRINGP (it
->string
)
9261 && IT_CHARPOS (*it
) > BEGV
9262 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9264 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9267 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9268 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9270 bidi_unshelve_cache (it3data
, 1);
9274 /* The y-position we try to reach, relative to *IT.
9275 Note that H has been subtracted in front of the if-statement. */
9276 int target_y
= it
->current_y
+ h
- dy
;
9277 int y0
= it3
.current_y
;
9281 RESTORE_IT (&it3
, &it3
, it3data
);
9282 y1
= line_bottom_y (&it3
);
9283 line_height
= y1
- y0
;
9284 RESTORE_IT (it
, it
, it2data
);
9285 /* If we did not reach target_y, try to move further backward if
9286 we can. If we moved too far backward, try to move forward. */
9287 if (target_y
< it
->current_y
9288 /* This is heuristic. In a window that's 3 lines high, with
9289 a line height of 13 pixels each, recentering with point
9290 on the bottom line will try to move -39/2 = 19 pixels
9291 backward. Try to avoid moving into the first line. */
9292 && (it
->current_y
- target_y
9293 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9294 && IT_CHARPOS (*it
) > BEGV
)
9296 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9297 target_y
- it
->current_y
));
9298 dy
= it
->current_y
- target_y
;
9299 goto move_further_back
;
9301 else if (target_y
>= it
->current_y
+ line_height
9302 && IT_CHARPOS (*it
) < ZV
)
9304 /* Should move forward by at least one line, maybe more.
9306 Note: Calling move_it_by_lines can be expensive on
9307 terminal frames, where compute_motion is used (via
9308 vmotion) to do the job, when there are very long lines
9309 and truncate-lines is nil. That's the reason for
9310 treating terminal frames specially here. */
9312 if (!FRAME_WINDOW_P (it
->f
))
9313 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9318 move_it_by_lines (it
, 1);
9320 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9327 /* Move IT by a specified amount of pixel lines DY. DY negative means
9328 move backwards. DY = 0 means move to start of screen line. At the
9329 end, IT will be on the start of a screen line. */
9332 move_it_vertically (struct it
*it
, int dy
)
9335 move_it_vertically_backward (it
, -dy
);
9338 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9339 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9340 MOVE_TO_POS
| MOVE_TO_Y
);
9341 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9343 /* If buffer ends in ZV without a newline, move to the start of
9344 the line to satisfy the post-condition. */
9345 if (IT_CHARPOS (*it
) == ZV
9347 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9348 move_it_by_lines (it
, 0);
9353 /* Move iterator IT past the end of the text line it is in. */
9356 move_it_past_eol (struct it
*it
)
9358 enum move_it_result rc
;
9360 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9361 if (rc
== MOVE_NEWLINE_OR_CR
)
9362 set_iterator_to_next (it
, 0);
9366 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9367 negative means move up. DVPOS == 0 means move to the start of the
9370 Optimization idea: If we would know that IT->f doesn't use
9371 a face with proportional font, we could be faster for
9372 truncate-lines nil. */
9375 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9378 /* The commented-out optimization uses vmotion on terminals. This
9379 gives bad results, because elements like it->what, on which
9380 callers such as pos_visible_p rely, aren't updated. */
9381 /* struct position pos;
9382 if (!FRAME_WINDOW_P (it->f))
9384 struct text_pos textpos;
9386 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9387 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9388 reseat (it, textpos, 1);
9389 it->vpos += pos.vpos;
9390 it->current_y += pos.vpos;
9396 /* DVPOS == 0 means move to the start of the screen line. */
9397 move_it_vertically_backward (it
, 0);
9398 /* Let next call to line_bottom_y calculate real line height. */
9403 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9404 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9406 /* Only move to the next buffer position if we ended up in a
9407 string from display property, not in an overlay string
9408 (before-string or after-string). That is because the
9409 latter don't conceal the underlying buffer position, so
9410 we can ask to move the iterator to the exact position we
9411 are interested in. Note that, even if we are already at
9412 IT_CHARPOS (*it), the call below is not a no-op, as it
9413 will detect that we are at the end of the string, pop the
9414 iterator, and compute it->current_x and it->hpos
9416 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9417 -1, -1, -1, MOVE_TO_POS
);
9423 void *it2data
= NULL
;
9424 ptrdiff_t start_charpos
, i
;
9426 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9427 ptrdiff_t pos_limit
;
9429 /* Start at the beginning of the screen line containing IT's
9430 position. This may actually move vertically backwards,
9431 in case of overlays, so adjust dvpos accordingly. */
9433 move_it_vertically_backward (it
, 0);
9436 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9437 screen lines, and reseat the iterator there. */
9438 start_charpos
= IT_CHARPOS (*it
);
9439 if (it
->line_wrap
== TRUNCATE
)
9442 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9443 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9444 back_to_previous_visible_line_start (it
);
9445 reseat (it
, it
->current
.pos
, 1);
9447 /* Move further back if we end up in a string or an image. */
9448 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9450 /* First try to move to start of display line. */
9452 move_it_vertically_backward (it
, 0);
9454 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9456 /* If start of line is still in string or image,
9457 move further back. */
9458 back_to_previous_visible_line_start (it
);
9459 reseat (it
, it
->current
.pos
, 1);
9463 it
->current_x
= it
->hpos
= 0;
9465 /* Above call may have moved too far if continuation lines
9466 are involved. Scan forward and see if it did. */
9467 SAVE_IT (it2
, *it
, it2data
);
9468 it2
.vpos
= it2
.current_y
= 0;
9469 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9470 it
->vpos
-= it2
.vpos
;
9471 it
->current_y
-= it2
.current_y
;
9472 it
->current_x
= it
->hpos
= 0;
9474 /* If we moved too far back, move IT some lines forward. */
9475 if (it2
.vpos
> -dvpos
)
9477 int delta
= it2
.vpos
+ dvpos
;
9479 RESTORE_IT (&it2
, &it2
, it2data
);
9480 SAVE_IT (it2
, *it
, it2data
);
9481 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9482 /* Move back again if we got too far ahead. */
9483 if (IT_CHARPOS (*it
) >= start_charpos
)
9484 RESTORE_IT (it
, &it2
, it2data
);
9486 bidi_unshelve_cache (it2data
, 1);
9489 RESTORE_IT (it
, it
, it2data
);
9493 /* Return true if IT points into the middle of a display vector. */
9496 in_display_vector_p (struct it
*it
)
9498 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9499 && it
->current
.dpvec_index
> 0
9500 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9503 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9504 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9505 WINDOW must be a live window and defaults to the selected one. The
9506 return value is a cons of the maximum pixel-width of any text line and
9507 the maximum pixel-height of all text lines.
9509 The optional argument FROM, if non-nil, specifies the first text
9510 position and defaults to the minimum accessible position of the buffer.
9511 If FROM is t, use the minimum accessible position that is not a newline
9512 character. TO, if non-nil, specifies the last text position and
9513 defaults to the maximum accessible position of the buffer. If TO is t,
9514 use the maximum accessible position that is not a newline character.
9516 The optional argument X_LIMIT, if non-nil, specifies the maximum text
9517 width that can be returned. X_LIMIT nil or omitted, means to use the
9518 pixel-width of WINDOW's body; use this if you do not intend to change
9519 the width of WINDOW. Use the maximum width WINDOW may assume if you
9520 intend to change WINDOW's width.
9522 The optional argument Y_LIMIT, if non-nil, specifies the maximum text
9523 height that can be returned. Text lines whose y-coordinate is beyond
9524 Y_LIMIT are ignored. Since calculating the text height of a large
9525 buffer can take some time, it makes sense to specify this argument if
9526 the size of the buffer is unknown.
9528 Optional argument MODE_AND_HEADER_LINE nil or omitted means do not
9529 include the height of the mode- or header-line of WINDOW in the return
9530 value. If it is either the symbol `mode-line' or `header-line', include
9531 only the height of that line, if present, in the return value. If t,
9532 include the height of both, if present, in the return value. */)
9533 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
, Lisp_Object y_limit
,
9534 Lisp_Object mode_and_header_line
)
9536 struct window
*w
= decode_live_window (window
);
9540 struct buffer
*old_buffer
= NULL
;
9541 ptrdiff_t start
, end
, pos
;
9542 struct text_pos startp
;
9543 void *itdata
= NULL
;
9544 int c
, max_y
= -1, x
= 0, y
= 0;
9550 if (b
!= current_buffer
)
9552 old_buffer
= current_buffer
;
9553 set_buffer_internal (b
);
9558 else if (EQ (from
, Qt
))
9561 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9562 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9564 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9569 CHECK_NUMBER_COERCE_MARKER (from
);
9570 start
= min (max (XINT (from
), BEGV
), ZV
);
9575 else if (EQ (to
, Qt
))
9578 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9579 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9581 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9586 CHECK_NUMBER_COERCE_MARKER (to
);
9587 end
= max (start
, min (XINT (to
), ZV
));
9590 if (!NILP (y_limit
))
9592 CHECK_NUMBER (y_limit
);
9593 max_y
= min (XINT (y_limit
), INT_MAX
);
9596 itdata
= bidi_shelve_cache ();
9597 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9598 start_display (&it
, w
, startp
);
9601 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9604 CHECK_NUMBER (x_limit
);
9605 it
.last_visible_x
= min (XINT (x_limit
), INFINITY
);
9606 /* Actually, we never want move_it_to stop at to_x. But to make
9607 sure that move_it_in_display_line_to always moves far enough,
9608 we set it to INT_MAX and specify MOVE_TO_X. */
9609 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9610 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9613 y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9615 if (!EQ (mode_and_header_line
, Qheader_line
)
9616 && !EQ (mode_and_header_line
, Qt
))
9617 /* Do not count the header-line which was counted automatically by
9619 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9621 if (EQ (mode_and_header_line
, Qmode_line
)
9622 || EQ (mode_and_header_line
, Qt
))
9623 /* Do count the mode-line which is not included automatically by
9625 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9627 bidi_unshelve_cache (itdata
, 0);
9630 set_buffer_internal (old_buffer
);
9632 return Fcons (make_number (x
), make_number (y
));
9635 /***********************************************************************
9637 ***********************************************************************/
9640 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9644 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9646 Lisp_Object args
[3];
9647 Lisp_Object msg
, fmt
;
9650 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9654 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9656 args
[0] = fmt
= build_string (format
);
9659 msg
= Fformat (3, args
);
9661 len
= SBYTES (msg
) + 1;
9662 buffer
= SAFE_ALLOCA (len
);
9663 memcpy (buffer
, SDATA (msg
), len
);
9665 message_dolog (buffer
, len
- 1, 1, 0);
9672 /* Output a newline in the *Messages* buffer if "needs" one. */
9675 message_log_maybe_newline (void)
9677 if (message_log_need_newline
)
9678 message_dolog ("", 0, 1, 0);
9682 /* Add a string M of length NBYTES to the message log, optionally
9683 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9684 true, means interpret the contents of M as multibyte. This
9685 function calls low-level routines in order to bypass text property
9686 hooks, etc. which might not be safe to run.
9688 This may GC (insert may run before/after change hooks),
9689 so the buffer M must NOT point to a Lisp string. */
9692 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9694 const unsigned char *msg
= (const unsigned char *) m
;
9696 if (!NILP (Vmemory_full
))
9699 if (!NILP (Vmessage_log_max
))
9701 struct buffer
*oldbuf
;
9702 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9703 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9704 ptrdiff_t point_at_end
= 0;
9705 ptrdiff_t zv_at_end
= 0;
9706 Lisp_Object old_deactivate_mark
;
9707 struct gcpro gcpro1
;
9709 old_deactivate_mark
= Vdeactivate_mark
;
9710 oldbuf
= current_buffer
;
9712 /* Ensure the Messages buffer exists, and switch to it.
9713 If we created it, set the major-mode. */
9716 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9718 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9721 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9722 call0 (intern ("messages-buffer-mode"));
9725 bset_undo_list (current_buffer
, Qt
);
9726 bset_cache_long_scans (current_buffer
, Qnil
);
9728 oldpoint
= message_dolog_marker1
;
9729 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9730 oldbegv
= message_dolog_marker2
;
9731 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9732 oldzv
= message_dolog_marker3
;
9733 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9734 GCPRO1 (old_deactivate_mark
);
9742 BEGV_BYTE
= BEG_BYTE
;
9745 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9747 /* Insert the string--maybe converting multibyte to single byte
9748 or vice versa, so that all the text fits the buffer. */
9750 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9756 /* Convert a multibyte string to single-byte
9757 for the *Message* buffer. */
9758 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9760 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9761 work
[0] = (ASCII_CHAR_P (c
)
9763 : multibyte_char_to_unibyte (c
));
9764 insert_1_both (work
, 1, 1, 1, 0, 0);
9767 else if (! multibyte
9768 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9772 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9773 /* Convert a single-byte string to multibyte
9774 for the *Message* buffer. */
9775 for (i
= 0; i
< nbytes
; i
++)
9778 MAKE_CHAR_MULTIBYTE (c
);
9779 char_bytes
= CHAR_STRING (c
, str
);
9780 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9784 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9788 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9791 insert_1_both ("\n", 1, 1, 1, 0, 0);
9793 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9795 this_bol_byte
= PT_BYTE
;
9797 /* See if this line duplicates the previous one.
9798 If so, combine duplicates. */
9801 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9803 prev_bol_byte
= PT_BYTE
;
9805 dups
= message_log_check_duplicate (prev_bol_byte
,
9809 del_range_both (prev_bol
, prev_bol_byte
,
9810 this_bol
, this_bol_byte
, 0);
9813 char dupstr
[sizeof " [ times]"
9814 + INT_STRLEN_BOUND (printmax_t
)];
9816 /* If you change this format, don't forget to also
9817 change message_log_check_duplicate. */
9818 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9819 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9820 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9825 /* If we have more than the desired maximum number of lines
9826 in the *Messages* buffer now, delete the oldest ones.
9827 This is safe because we don't have undo in this buffer. */
9829 if (NATNUMP (Vmessage_log_max
))
9831 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9832 -XFASTINT (Vmessage_log_max
) - 1, 0);
9833 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9836 BEGV
= marker_position (oldbegv
);
9837 BEGV_BYTE
= marker_byte_position (oldbegv
);
9846 ZV
= marker_position (oldzv
);
9847 ZV_BYTE
= marker_byte_position (oldzv
);
9851 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9853 /* We can't do Fgoto_char (oldpoint) because it will run some
9855 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9856 marker_byte_position (oldpoint
));
9859 unchain_marker (XMARKER (oldpoint
));
9860 unchain_marker (XMARKER (oldbegv
));
9861 unchain_marker (XMARKER (oldzv
));
9863 /* We called insert_1_both above with its 5th argument (PREPARE)
9864 zero, which prevents insert_1_both from calling
9865 prepare_to_modify_buffer, which in turns prevents us from
9866 incrementing windows_or_buffers_changed even if *Messages* is
9867 shown in some window. So we must manually set
9868 windows_or_buffers_changed here to make up for that. */
9869 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9870 bset_redisplay (current_buffer
);
9872 set_buffer_internal (oldbuf
);
9874 message_log_need_newline
= !nlflag
;
9875 Vdeactivate_mark
= old_deactivate_mark
;
9880 /* We are at the end of the buffer after just having inserted a newline.
9881 (Note: We depend on the fact we won't be crossing the gap.)
9882 Check to see if the most recent message looks a lot like the previous one.
9883 Return 0 if different, 1 if the new one should just replace it, or a
9884 value N > 1 if we should also append " [N times]". */
9887 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9890 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9892 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9893 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9895 for (i
= 0; i
< len
; i
++)
9897 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9905 if (*p1
++ == ' ' && *p1
++ == '[')
9908 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9909 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9916 /* Display an echo area message M with a specified length of NBYTES
9917 bytes. The string may include null characters. If M is not a
9918 string, clear out any existing message, and let the mini-buffer
9921 This function cancels echoing. */
9924 message3 (Lisp_Object m
)
9926 struct gcpro gcpro1
;
9929 clear_message (true, true);
9932 /* First flush out any partial line written with print. */
9933 message_log_maybe_newline ();
9936 ptrdiff_t nbytes
= SBYTES (m
);
9937 bool multibyte
= STRING_MULTIBYTE (m
);
9939 char *buffer
= SAFE_ALLOCA (nbytes
);
9940 memcpy (buffer
, SDATA (m
), nbytes
);
9941 message_dolog (buffer
, nbytes
, 1, multibyte
);
9950 /* The non-logging version of message3.
9951 This does not cancel echoing, because it is used for echoing.
9952 Perhaps we need to make a separate function for echoing
9953 and make this cancel echoing. */
9956 message3_nolog (Lisp_Object m
)
9958 struct frame
*sf
= SELECTED_FRAME ();
9960 if (FRAME_INITIAL_P (sf
))
9962 if (noninteractive_need_newline
)
9963 putc ('\n', stderr
);
9964 noninteractive_need_newline
= 0;
9967 Lisp_Object s
= ENCODE_SYSTEM (m
);
9969 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
9971 if (cursor_in_echo_area
== 0)
9972 fprintf (stderr
, "\n");
9975 /* Error messages get reported properly by cmd_error, so this must be just an
9976 informative message; if the frame hasn't really been initialized yet, just
9978 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9980 /* Get the frame containing the mini-buffer
9981 that the selected frame is using. */
9982 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9983 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9984 struct frame
*f
= XFRAME (frame
);
9986 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9987 Fmake_frame_visible (frame
);
9989 if (STRINGP (m
) && SCHARS (m
) > 0)
9992 if (minibuffer_auto_raise
)
9993 Fraise_frame (frame
);
9994 /* Assume we are not echoing.
9995 (If we are, echo_now will override this.) */
9996 echo_message_buffer
= Qnil
;
9999 clear_message (true, true);
10001 do_pending_window_change (0);
10002 echo_area_display (1);
10003 do_pending_window_change (0);
10004 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
10005 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
10010 /* Display a null-terminated echo area message M. If M is 0, clear
10011 out any existing message, and let the mini-buffer text show through.
10013 The buffer M must continue to exist until after the echo area gets
10014 cleared or some other message gets displayed there. Do not pass
10015 text that is stored in a Lisp string. Do not pass text in a buffer
10016 that was alloca'd. */
10019 message1 (const char *m
)
10021 message3 (m
? build_unibyte_string (m
) : Qnil
);
10025 /* The non-logging counterpart of message1. */
10028 message1_nolog (const char *m
)
10030 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10033 /* Display a message M which contains a single %s
10034 which gets replaced with STRING. */
10037 message_with_string (const char *m
, Lisp_Object string
, int log
)
10039 CHECK_STRING (string
);
10041 if (noninteractive
)
10045 /* ENCODE_SYSTEM below can GC and/or relocate the Lisp
10046 String whose data pointer might be passed to us in M. So
10047 we use a local copy. */
10048 char *fmt
= xstrdup (m
);
10050 if (noninteractive_need_newline
)
10051 putc ('\n', stderr
);
10052 noninteractive_need_newline
= 0;
10053 fprintf (stderr
, fmt
, SDATA (ENCODE_SYSTEM (string
)));
10054 if (!cursor_in_echo_area
)
10055 fprintf (stderr
, "\n");
10060 else if (INTERACTIVE
)
10062 /* The frame whose minibuffer we're going to display the message on.
10063 It may be larger than the selected frame, so we need
10064 to use its buffer, not the selected frame's buffer. */
10065 Lisp_Object mini_window
;
10066 struct frame
*f
, *sf
= SELECTED_FRAME ();
10068 /* Get the frame containing the minibuffer
10069 that the selected frame is using. */
10070 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10071 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10073 /* Error messages get reported properly by cmd_error, so this must be
10074 just an informative message; if the frame hasn't really been
10075 initialized yet, just toss it. */
10076 if (f
->glyphs_initialized_p
)
10078 Lisp_Object args
[2], msg
;
10079 struct gcpro gcpro1
, gcpro2
;
10081 args
[0] = build_string (m
);
10082 args
[1] = msg
= string
;
10083 GCPRO2 (args
[0], msg
);
10086 msg
= Fformat (2, args
);
10091 message3_nolog (msg
);
10095 /* Print should start at the beginning of the message
10096 buffer next time. */
10097 message_buf_print
= 0;
10103 /* Dump an informative message to the minibuf. If M is 0, clear out
10104 any existing message, and let the mini-buffer text show through. */
10107 vmessage (const char *m
, va_list ap
)
10109 if (noninteractive
)
10113 if (noninteractive_need_newline
)
10114 putc ('\n', stderr
);
10115 noninteractive_need_newline
= 0;
10116 vfprintf (stderr
, m
, ap
);
10117 if (cursor_in_echo_area
== 0)
10118 fprintf (stderr
, "\n");
10122 else if (INTERACTIVE
)
10124 /* The frame whose mini-buffer we're going to display the message
10125 on. It may be larger than the selected frame, so we need to
10126 use its buffer, not the selected frame's buffer. */
10127 Lisp_Object mini_window
;
10128 struct frame
*f
, *sf
= SELECTED_FRAME ();
10130 /* Get the frame containing the mini-buffer
10131 that the selected frame is using. */
10132 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10133 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10135 /* Error messages get reported properly by cmd_error, so this must be
10136 just an informative message; if the frame hasn't really been
10137 initialized yet, just toss it. */
10138 if (f
->glyphs_initialized_p
)
10143 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10144 char *message_buf
= alloca (maxsize
+ 1);
10146 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10148 message3 (make_string (message_buf
, len
));
10153 /* Print should start at the beginning of the message
10154 buffer next time. */
10155 message_buf_print
= 0;
10161 message (const char *m
, ...)
10171 /* The non-logging version of message. */
10174 message_nolog (const char *m
, ...)
10176 Lisp_Object old_log_max
;
10179 old_log_max
= Vmessage_log_max
;
10180 Vmessage_log_max
= Qnil
;
10182 Vmessage_log_max
= old_log_max
;
10188 /* Display the current message in the current mini-buffer. This is
10189 only called from error handlers in process.c, and is not time
10193 update_echo_area (void)
10195 if (!NILP (echo_area_buffer
[0]))
10197 Lisp_Object string
;
10198 string
= Fcurrent_message ();
10204 /* Make sure echo area buffers in `echo_buffers' are live.
10205 If they aren't, make new ones. */
10208 ensure_echo_area_buffers (void)
10212 for (i
= 0; i
< 2; ++i
)
10213 if (!BUFFERP (echo_buffer
[i
])
10214 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10217 Lisp_Object old_buffer
;
10220 old_buffer
= echo_buffer
[i
];
10221 echo_buffer
[i
] = Fget_buffer_create
10222 (make_formatted_string (name
, " *Echo Area %d*", i
));
10223 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10224 /* to force word wrap in echo area -
10225 it was decided to postpone this*/
10226 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10228 for (j
= 0; j
< 2; ++j
)
10229 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10230 echo_area_buffer
[j
] = echo_buffer
[i
];
10235 /* Call FN with args A1..A2 with either the current or last displayed
10236 echo_area_buffer as current buffer.
10238 WHICH zero means use the current message buffer
10239 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10240 from echo_buffer[] and clear it.
10242 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10243 suitable buffer from echo_buffer[] and clear it.
10245 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10246 that the current message becomes the last displayed one, make
10247 choose a suitable buffer for echo_area_buffer[0], and clear it.
10249 Value is what FN returns. */
10252 with_echo_area_buffer (struct window
*w
, int which
,
10253 int (*fn
) (ptrdiff_t, Lisp_Object
),
10254 ptrdiff_t a1
, Lisp_Object a2
)
10256 Lisp_Object buffer
;
10257 int this_one
, the_other
, clear_buffer_p
, rc
;
10258 ptrdiff_t count
= SPECPDL_INDEX ();
10260 /* If buffers aren't live, make new ones. */
10261 ensure_echo_area_buffers ();
10263 clear_buffer_p
= 0;
10266 this_one
= 0, the_other
= 1;
10267 else if (which
> 0)
10268 this_one
= 1, the_other
= 0;
10271 this_one
= 0, the_other
= 1;
10272 clear_buffer_p
= true;
10274 /* We need a fresh one in case the current echo buffer equals
10275 the one containing the last displayed echo area message. */
10276 if (!NILP (echo_area_buffer
[this_one
])
10277 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10278 echo_area_buffer
[this_one
] = Qnil
;
10281 /* Choose a suitable buffer from echo_buffer[] is we don't
10283 if (NILP (echo_area_buffer
[this_one
]))
10285 echo_area_buffer
[this_one
]
10286 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10287 ? echo_buffer
[the_other
]
10288 : echo_buffer
[this_one
]);
10289 clear_buffer_p
= true;
10292 buffer
= echo_area_buffer
[this_one
];
10294 /* Don't get confused by reusing the buffer used for echoing
10295 for a different purpose. */
10296 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10299 record_unwind_protect (unwind_with_echo_area_buffer
,
10300 with_echo_area_buffer_unwind_data (w
));
10302 /* Make the echo area buffer current. Note that for display
10303 purposes, it is not necessary that the displayed window's buffer
10304 == current_buffer, except for text property lookup. So, let's
10305 only set that buffer temporarily here without doing a full
10306 Fset_window_buffer. We must also change w->pointm, though,
10307 because otherwise an assertions in unshow_buffer fails, and Emacs
10309 set_buffer_internal_1 (XBUFFER (buffer
));
10312 wset_buffer (w
, buffer
);
10313 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10316 bset_undo_list (current_buffer
, Qt
);
10317 bset_read_only (current_buffer
, Qnil
);
10318 specbind (Qinhibit_read_only
, Qt
);
10319 specbind (Qinhibit_modification_hooks
, Qt
);
10321 if (clear_buffer_p
&& Z
> BEG
)
10322 del_range (BEG
, Z
);
10324 eassert (BEGV
>= BEG
);
10325 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10329 eassert (BEGV
>= BEG
);
10330 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10332 unbind_to (count
, Qnil
);
10337 /* Save state that should be preserved around the call to the function
10338 FN called in with_echo_area_buffer. */
10341 with_echo_area_buffer_unwind_data (struct window
*w
)
10344 Lisp_Object vector
, tmp
;
10346 /* Reduce consing by keeping one vector in
10347 Vwith_echo_area_save_vector. */
10348 vector
= Vwith_echo_area_save_vector
;
10349 Vwith_echo_area_save_vector
= Qnil
;
10352 vector
= Fmake_vector (make_number (9), Qnil
);
10354 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10355 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10356 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10360 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10361 ASET (vector
, i
, w
->contents
); ++i
;
10362 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10363 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10364 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10365 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10370 for (; i
< end
; ++i
)
10371 ASET (vector
, i
, Qnil
);
10374 eassert (i
== ASIZE (vector
));
10379 /* Restore global state from VECTOR which was created by
10380 with_echo_area_buffer_unwind_data. */
10383 unwind_with_echo_area_buffer (Lisp_Object vector
)
10385 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10386 Vdeactivate_mark
= AREF (vector
, 1);
10387 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10389 if (WINDOWP (AREF (vector
, 3)))
10392 Lisp_Object buffer
;
10394 w
= XWINDOW (AREF (vector
, 3));
10395 buffer
= AREF (vector
, 4);
10397 wset_buffer (w
, buffer
);
10398 set_marker_both (w
->pointm
, buffer
,
10399 XFASTINT (AREF (vector
, 5)),
10400 XFASTINT (AREF (vector
, 6)));
10401 set_marker_both (w
->start
, buffer
,
10402 XFASTINT (AREF (vector
, 7)),
10403 XFASTINT (AREF (vector
, 8)));
10406 Vwith_echo_area_save_vector
= vector
;
10410 /* Set up the echo area for use by print functions. MULTIBYTE_P
10411 non-zero means we will print multibyte. */
10414 setup_echo_area_for_printing (int multibyte_p
)
10416 /* If we can't find an echo area any more, exit. */
10417 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10418 Fkill_emacs (Qnil
);
10420 ensure_echo_area_buffers ();
10422 if (!message_buf_print
)
10424 /* A message has been output since the last time we printed.
10425 Choose a fresh echo area buffer. */
10426 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10427 echo_area_buffer
[0] = echo_buffer
[1];
10429 echo_area_buffer
[0] = echo_buffer
[0];
10431 /* Switch to that buffer and clear it. */
10432 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10433 bset_truncate_lines (current_buffer
, Qnil
);
10437 ptrdiff_t count
= SPECPDL_INDEX ();
10438 specbind (Qinhibit_read_only
, Qt
);
10439 /* Note that undo recording is always disabled. */
10440 del_range (BEG
, Z
);
10441 unbind_to (count
, Qnil
);
10443 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10445 /* Set up the buffer for the multibyteness we need. */
10447 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10448 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10450 /* Raise the frame containing the echo area. */
10451 if (minibuffer_auto_raise
)
10453 struct frame
*sf
= SELECTED_FRAME ();
10454 Lisp_Object mini_window
;
10455 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10456 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10459 message_log_maybe_newline ();
10460 message_buf_print
= 1;
10464 if (NILP (echo_area_buffer
[0]))
10466 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10467 echo_area_buffer
[0] = echo_buffer
[1];
10469 echo_area_buffer
[0] = echo_buffer
[0];
10472 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10474 /* Someone switched buffers between print requests. */
10475 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10476 bset_truncate_lines (current_buffer
, Qnil
);
10482 /* Display an echo area message in window W. Value is non-zero if W's
10483 height is changed. If display_last_displayed_message_p is
10484 non-zero, display the message that was last displayed, otherwise
10485 display the current message. */
10488 display_echo_area (struct window
*w
)
10490 int i
, no_message_p
, window_height_changed_p
;
10492 /* Temporarily disable garbage collections while displaying the echo
10493 area. This is done because a GC can print a message itself.
10494 That message would modify the echo area buffer's contents while a
10495 redisplay of the buffer is going on, and seriously confuse
10497 ptrdiff_t count
= inhibit_garbage_collection ();
10499 /* If there is no message, we must call display_echo_area_1
10500 nevertheless because it resizes the window. But we will have to
10501 reset the echo_area_buffer in question to nil at the end because
10502 with_echo_area_buffer will sets it to an empty buffer. */
10503 i
= display_last_displayed_message_p
? 1 : 0;
10504 no_message_p
= NILP (echo_area_buffer
[i
]);
10506 window_height_changed_p
10507 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10508 display_echo_area_1
,
10509 (intptr_t) w
, Qnil
);
10512 echo_area_buffer
[i
] = Qnil
;
10514 unbind_to (count
, Qnil
);
10515 return window_height_changed_p
;
10519 /* Helper for display_echo_area. Display the current buffer which
10520 contains the current echo area message in window W, a mini-window,
10521 a pointer to which is passed in A1. A2..A4 are currently not used.
10522 Change the height of W so that all of the message is displayed.
10523 Value is non-zero if height of W was changed. */
10526 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10529 struct window
*w
= (struct window
*) i1
;
10530 Lisp_Object window
;
10531 struct text_pos start
;
10532 int window_height_changed_p
= 0;
10534 /* Do this before displaying, so that we have a large enough glyph
10535 matrix for the display. If we can't get enough space for the
10536 whole text, display the last N lines. That works by setting w->start. */
10537 window_height_changed_p
= resize_mini_window (w
, 0);
10539 /* Use the starting position chosen by resize_mini_window. */
10540 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10543 clear_glyph_matrix (w
->desired_matrix
);
10544 XSETWINDOW (window
, w
);
10545 try_window (window
, start
, 0);
10547 return window_height_changed_p
;
10551 /* Resize the echo area window to exactly the size needed for the
10552 currently displayed message, if there is one. If a mini-buffer
10553 is active, don't shrink it. */
10556 resize_echo_area_exactly (void)
10558 if (BUFFERP (echo_area_buffer
[0])
10559 && WINDOWP (echo_area_window
))
10561 struct window
*w
= XWINDOW (echo_area_window
);
10562 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10563 int resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10564 (intptr_t) w
, resize_exactly
);
10567 windows_or_buffers_changed
= 42;
10568 update_mode_lines
= 30;
10569 redisplay_internal ();
10575 /* Callback function for with_echo_area_buffer, when used from
10576 resize_echo_area_exactly. A1 contains a pointer to the window to
10577 resize, EXACTLY non-nil means resize the mini-window exactly to the
10578 size of the text displayed. A3 and A4 are not used. Value is what
10579 resize_mini_window returns. */
10582 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10585 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10589 /* Resize mini-window W to fit the size of its contents. EXACT_P
10590 means size the window exactly to the size needed. Otherwise, it's
10591 only enlarged until W's buffer is empty.
10593 Set W->start to the right place to begin display. If the whole
10594 contents fit, start at the beginning. Otherwise, start so as
10595 to make the end of the contents appear. This is particularly
10596 important for y-or-n-p, but seems desirable generally.
10598 Value is non-zero if the window height has been changed. */
10601 resize_mini_window (struct window
*w
, int exact_p
)
10603 struct frame
*f
= XFRAME (w
->frame
);
10604 int window_height_changed_p
= 0;
10606 eassert (MINI_WINDOW_P (w
));
10608 /* By default, start display at the beginning. */
10609 set_marker_both (w
->start
, w
->contents
,
10610 BUF_BEGV (XBUFFER (w
->contents
)),
10611 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10613 /* Don't resize windows while redisplaying a window; it would
10614 confuse redisplay functions when the size of the window they are
10615 displaying changes from under them. Such a resizing can happen,
10616 for instance, when which-func prints a long message while
10617 we are running fontification-functions. We're running these
10618 functions with safe_call which binds inhibit-redisplay to t. */
10619 if (!NILP (Vinhibit_redisplay
))
10622 /* Nil means don't try to resize. */
10623 if (NILP (Vresize_mini_windows
)
10624 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10627 if (!FRAME_MINIBUF_ONLY_P (f
))
10630 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10631 + WINDOW_PIXEL_HEIGHT (w
));
10632 int unit
= FRAME_LINE_HEIGHT (f
);
10633 int height
, max_height
;
10634 struct text_pos start
;
10635 struct buffer
*old_current_buffer
= NULL
;
10637 if (current_buffer
!= XBUFFER (w
->contents
))
10639 old_current_buffer
= current_buffer
;
10640 set_buffer_internal (XBUFFER (w
->contents
));
10643 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10645 /* Compute the max. number of lines specified by the user. */
10646 if (FLOATP (Vmax_mini_window_height
))
10647 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10648 else if (INTEGERP (Vmax_mini_window_height
))
10649 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10651 max_height
= total_height
/ 4;
10653 /* Correct that max. height if it's bogus. */
10654 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10656 /* Find out the height of the text in the window. */
10657 if (it
.line_wrap
== TRUNCATE
)
10662 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10663 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10664 height
= it
.current_y
+ last_height
;
10666 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10667 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10670 /* Compute a suitable window start. */
10671 if (height
> max_height
)
10673 height
= (max_height
/ unit
) * unit
;
10674 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10675 move_it_vertically_backward (&it
, height
- unit
);
10676 start
= it
.current
.pos
;
10679 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10680 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10682 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10684 /* Let it grow only, until we display an empty message, in which
10685 case the window shrinks again. */
10686 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10688 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10690 FRAME_WINDOWS_FROZEN (f
) = 1;
10691 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10692 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10694 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10695 && (exact_p
|| BEGV
== ZV
))
10697 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10699 FRAME_WINDOWS_FROZEN (f
) = 0;
10700 shrink_mini_window (w
, 1);
10701 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10706 /* Always resize to exact size needed. */
10707 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10709 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10711 FRAME_WINDOWS_FROZEN (f
) = 1;
10712 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10713 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10715 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
10717 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10719 FRAME_WINDOWS_FROZEN (f
) = 0;
10720 shrink_mini_window (w
, 1);
10724 FRAME_WINDOWS_FROZEN (f
) = 1;
10725 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10728 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10732 if (old_current_buffer
)
10733 set_buffer_internal (old_current_buffer
);
10736 return window_height_changed_p
;
10740 /* Value is the current message, a string, or nil if there is no
10741 current message. */
10744 current_message (void)
10748 if (!BUFFERP (echo_area_buffer
[0]))
10752 with_echo_area_buffer (0, 0, current_message_1
,
10753 (intptr_t) &msg
, Qnil
);
10755 echo_area_buffer
[0] = Qnil
;
10763 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10766 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10769 *msg
= make_buffer_string (BEG
, Z
, 1);
10776 /* Push the current message on Vmessage_stack for later restoration
10777 by restore_message. Value is non-zero if the current message isn't
10778 empty. This is a relatively infrequent operation, so it's not
10779 worth optimizing. */
10782 push_message (void)
10784 Lisp_Object msg
= current_message ();
10785 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10786 return STRINGP (msg
);
10790 /* Restore message display from the top of Vmessage_stack. */
10793 restore_message (void)
10795 eassert (CONSP (Vmessage_stack
));
10796 message3_nolog (XCAR (Vmessage_stack
));
10800 /* Handler for unwind-protect calling pop_message. */
10803 pop_message_unwind (void)
10805 /* Pop the top-most entry off Vmessage_stack. */
10806 eassert (CONSP (Vmessage_stack
));
10807 Vmessage_stack
= XCDR (Vmessage_stack
);
10811 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10812 exits. If the stack is not empty, we have a missing pop_message
10816 check_message_stack (void)
10818 if (!NILP (Vmessage_stack
))
10823 /* Truncate to NCHARS what will be displayed in the echo area the next
10824 time we display it---but don't redisplay it now. */
10827 truncate_echo_area (ptrdiff_t nchars
)
10830 echo_area_buffer
[0] = Qnil
;
10831 else if (!noninteractive
10833 && !NILP (echo_area_buffer
[0]))
10835 struct frame
*sf
= SELECTED_FRAME ();
10836 /* Error messages get reported properly by cmd_error, so this must be
10837 just an informative message; if the frame hasn't really been
10838 initialized yet, just toss it. */
10839 if (sf
->glyphs_initialized_p
)
10840 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10845 /* Helper function for truncate_echo_area. Truncate the current
10846 message to at most NCHARS characters. */
10849 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10851 if (BEG
+ nchars
< Z
)
10852 del_range (BEG
+ nchars
, Z
);
10854 echo_area_buffer
[0] = Qnil
;
10858 /* Set the current message to STRING. */
10861 set_message (Lisp_Object string
)
10863 eassert (STRINGP (string
));
10865 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10867 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10868 message_buf_print
= 0;
10869 help_echo_showing_p
= 0;
10871 if (STRINGP (Vdebug_on_message
)
10872 && STRINGP (string
)
10873 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10874 call_debugger (list2 (Qerror
, string
));
10878 /* Helper function for set_message. First argument is ignored and second
10879 argument has the same meaning as for set_message.
10880 This function is called with the echo area buffer being current. */
10883 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10885 eassert (STRINGP (string
));
10887 /* Change multibyteness of the echo buffer appropriately. */
10888 if (message_enable_multibyte
10889 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10890 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10892 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10893 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10894 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10896 /* Insert new message at BEG. */
10897 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10899 /* This function takes care of single/multibyte conversion.
10900 We just have to ensure that the echo area buffer has the right
10901 setting of enable_multibyte_characters. */
10902 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10908 /* Clear messages. CURRENT_P non-zero means clear the current
10909 message. LAST_DISPLAYED_P non-zero means clear the message
10913 clear_message (bool current_p
, bool last_displayed_p
)
10917 echo_area_buffer
[0] = Qnil
;
10918 message_cleared_p
= true;
10921 if (last_displayed_p
)
10922 echo_area_buffer
[1] = Qnil
;
10924 message_buf_print
= 0;
10927 /* Clear garbaged frames.
10929 This function is used where the old redisplay called
10930 redraw_garbaged_frames which in turn called redraw_frame which in
10931 turn called clear_frame. The call to clear_frame was a source of
10932 flickering. I believe a clear_frame is not necessary. It should
10933 suffice in the new redisplay to invalidate all current matrices,
10934 and ensure a complete redisplay of all windows. */
10937 clear_garbaged_frames (void)
10939 if (frame_garbaged
)
10941 Lisp_Object tail
, frame
;
10943 FOR_EACH_FRAME (tail
, frame
)
10945 struct frame
*f
= XFRAME (frame
);
10947 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10952 clear_current_matrices (f
);
10953 fset_redisplay (f
);
10954 f
->garbaged
= false;
10955 f
->resized_p
= false;
10959 frame_garbaged
= false;
10964 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10965 is non-zero update selected_frame. Value is non-zero if the
10966 mini-windows height has been changed. */
10969 echo_area_display (int update_frame_p
)
10971 Lisp_Object mini_window
;
10974 int window_height_changed_p
= 0;
10975 struct frame
*sf
= SELECTED_FRAME ();
10977 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10978 w
= XWINDOW (mini_window
);
10979 f
= XFRAME (WINDOW_FRAME (w
));
10981 /* Don't display if frame is invisible or not yet initialized. */
10982 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10985 #ifdef HAVE_WINDOW_SYSTEM
10986 /* When Emacs starts, selected_frame may be the initial terminal
10987 frame. If we let this through, a message would be displayed on
10989 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10991 #endif /* HAVE_WINDOW_SYSTEM */
10993 /* Redraw garbaged frames. */
10994 clear_garbaged_frames ();
10996 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10998 echo_area_window
= mini_window
;
10999 window_height_changed_p
= display_echo_area (w
);
11000 w
->must_be_updated_p
= true;
11002 /* Update the display, unless called from redisplay_internal.
11003 Also don't update the screen during redisplay itself. The
11004 update will happen at the end of redisplay, and an update
11005 here could cause confusion. */
11006 if (update_frame_p
&& !redisplaying_p
)
11010 /* If the display update has been interrupted by pending
11011 input, update mode lines in the frame. Due to the
11012 pending input, it might have been that redisplay hasn't
11013 been called, so that mode lines above the echo area are
11014 garbaged. This looks odd, so we prevent it here. */
11015 if (!display_completed
)
11016 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11018 if (window_height_changed_p
11019 /* Don't do this if Emacs is shutting down. Redisplay
11020 needs to run hooks. */
11021 && !NILP (Vrun_hooks
))
11023 /* Must update other windows. Likewise as in other
11024 cases, don't let this update be interrupted by
11026 ptrdiff_t count
= SPECPDL_INDEX ();
11027 specbind (Qredisplay_dont_pause
, Qt
);
11028 windows_or_buffers_changed
= 44;
11029 redisplay_internal ();
11030 unbind_to (count
, Qnil
);
11032 else if (FRAME_WINDOW_P (f
) && n
== 0)
11034 /* Window configuration is the same as before.
11035 Can do with a display update of the echo area,
11036 unless we displayed some mode lines. */
11037 update_single_window (w
, 1);
11041 update_frame (f
, 1, 1);
11043 /* If cursor is in the echo area, make sure that the next
11044 redisplay displays the minibuffer, so that the cursor will
11045 be replaced with what the minibuffer wants. */
11046 if (cursor_in_echo_area
)
11047 wset_redisplay (XWINDOW (mini_window
));
11050 else if (!EQ (mini_window
, selected_window
))
11051 wset_redisplay (XWINDOW (mini_window
));
11053 /* Last displayed message is now the current message. */
11054 echo_area_buffer
[1] = echo_area_buffer
[0];
11055 /* Inform read_char that we're not echoing. */
11056 echo_message_buffer
= Qnil
;
11058 /* Prevent redisplay optimization in redisplay_internal by resetting
11059 this_line_start_pos. This is done because the mini-buffer now
11060 displays the message instead of its buffer text. */
11061 if (EQ (mini_window
, selected_window
))
11062 CHARPOS (this_line_start_pos
) = 0;
11064 return window_height_changed_p
;
11067 /* Nonzero if W's buffer was changed but not saved. */
11070 window_buffer_changed (struct window
*w
)
11072 struct buffer
*b
= XBUFFER (w
->contents
);
11074 eassert (BUFFER_LIVE_P (b
));
11076 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
));
11079 /* Nonzero if W has %c in its mode line and mode line should be updated. */
11082 mode_line_update_needed (struct window
*w
)
11084 return (w
->column_number_displayed
!= -1
11085 && !(PT
== w
->last_point
&& !window_outdated (w
))
11086 && (w
->column_number_displayed
!= current_column ()));
11089 /* Nonzero if window start of W is frozen and may not be changed during
11093 window_frozen_p (struct window
*w
)
11095 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11097 Lisp_Object window
;
11099 XSETWINDOW (window
, w
);
11100 if (MINI_WINDOW_P (w
))
11102 else if (EQ (window
, selected_window
))
11104 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11105 && EQ (window
, Vminibuf_scroll_window
))
11106 /* This special window can't be frozen too. */
11114 /***********************************************************************
11115 Mode Lines and Frame Titles
11116 ***********************************************************************/
11118 /* A buffer for constructing non-propertized mode-line strings and
11119 frame titles in it; allocated from the heap in init_xdisp and
11120 resized as needed in store_mode_line_noprop_char. */
11122 static char *mode_line_noprop_buf
;
11124 /* The buffer's end, and a current output position in it. */
11126 static char *mode_line_noprop_buf_end
;
11127 static char *mode_line_noprop_ptr
;
11129 #define MODE_LINE_NOPROP_LEN(start) \
11130 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11133 MODE_LINE_DISPLAY
= 0,
11137 } mode_line_target
;
11139 /* Alist that caches the results of :propertize.
11140 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11141 static Lisp_Object mode_line_proptrans_alist
;
11143 /* List of strings making up the mode-line. */
11144 static Lisp_Object mode_line_string_list
;
11146 /* Base face property when building propertized mode line string. */
11147 static Lisp_Object mode_line_string_face
;
11148 static Lisp_Object mode_line_string_face_prop
;
11151 /* Unwind data for mode line strings */
11153 static Lisp_Object Vmode_line_unwind_vector
;
11156 format_mode_line_unwind_data (struct frame
*target_frame
,
11157 struct buffer
*obuf
,
11159 int save_proptrans
)
11161 Lisp_Object vector
, tmp
;
11163 /* Reduce consing by keeping one vector in
11164 Vwith_echo_area_save_vector. */
11165 vector
= Vmode_line_unwind_vector
;
11166 Vmode_line_unwind_vector
= Qnil
;
11169 vector
= Fmake_vector (make_number (10), Qnil
);
11171 ASET (vector
, 0, make_number (mode_line_target
));
11172 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11173 ASET (vector
, 2, mode_line_string_list
);
11174 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11175 ASET (vector
, 4, mode_line_string_face
);
11176 ASET (vector
, 5, mode_line_string_face_prop
);
11179 XSETBUFFER (tmp
, obuf
);
11182 ASET (vector
, 6, tmp
);
11183 ASET (vector
, 7, owin
);
11186 /* Similarly to `with-selected-window', if the operation selects
11187 a window on another frame, we must restore that frame's
11188 selected window, and (for a tty) the top-frame. */
11189 ASET (vector
, 8, target_frame
->selected_window
);
11190 if (FRAME_TERMCAP_P (target_frame
))
11191 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11198 unwind_format_mode_line (Lisp_Object vector
)
11200 Lisp_Object old_window
= AREF (vector
, 7);
11201 Lisp_Object target_frame_window
= AREF (vector
, 8);
11202 Lisp_Object old_top_frame
= AREF (vector
, 9);
11204 mode_line_target
= XINT (AREF (vector
, 0));
11205 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11206 mode_line_string_list
= AREF (vector
, 2);
11207 if (! EQ (AREF (vector
, 3), Qt
))
11208 mode_line_proptrans_alist
= AREF (vector
, 3);
11209 mode_line_string_face
= AREF (vector
, 4);
11210 mode_line_string_face_prop
= AREF (vector
, 5);
11212 /* Select window before buffer, since it may change the buffer. */
11213 if (!NILP (old_window
))
11215 /* If the operation that we are unwinding had selected a window
11216 on a different frame, reset its frame-selected-window. For a
11217 text terminal, reset its top-frame if necessary. */
11218 if (!NILP (target_frame_window
))
11221 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11223 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11224 Fselect_window (target_frame_window
, Qt
);
11226 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11227 Fselect_frame (old_top_frame
, Qt
);
11230 Fselect_window (old_window
, Qt
);
11233 if (!NILP (AREF (vector
, 6)))
11235 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11236 ASET (vector
, 6, Qnil
);
11239 Vmode_line_unwind_vector
= vector
;
11243 /* Store a single character C for the frame title in mode_line_noprop_buf.
11244 Re-allocate mode_line_noprop_buf if necessary. */
11247 store_mode_line_noprop_char (char c
)
11249 /* If output position has reached the end of the allocated buffer,
11250 increase the buffer's size. */
11251 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11253 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11254 ptrdiff_t size
= len
;
11255 mode_line_noprop_buf
=
11256 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11257 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11258 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11261 *mode_line_noprop_ptr
++ = c
;
11265 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11266 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11267 characters that yield more columns than PRECISION; PRECISION <= 0
11268 means copy the whole string. Pad with spaces until FIELD_WIDTH
11269 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11270 pad. Called from display_mode_element when it is used to build a
11274 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11276 const unsigned char *str
= (const unsigned char *) string
;
11278 ptrdiff_t dummy
, nbytes
;
11280 /* Copy at most PRECISION chars from STR. */
11281 nbytes
= strlen (string
);
11282 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11284 store_mode_line_noprop_char (*str
++);
11286 /* Fill up with spaces until FIELD_WIDTH reached. */
11287 while (field_width
> 0
11288 && n
< field_width
)
11290 store_mode_line_noprop_char (' ');
11297 /***********************************************************************
11299 ***********************************************************************/
11301 #ifdef HAVE_WINDOW_SYSTEM
11303 /* Set the title of FRAME, if it has changed. The title format is
11304 Vicon_title_format if FRAME is iconified, otherwise it is
11305 frame_title_format. */
11308 x_consider_frame_title (Lisp_Object frame
)
11310 struct frame
*f
= XFRAME (frame
);
11312 if (FRAME_WINDOW_P (f
)
11313 || FRAME_MINIBUF_ONLY_P (f
)
11314 || f
->explicit_name
)
11316 /* Do we have more than one visible frame on this X display? */
11317 Lisp_Object tail
, other_frame
, fmt
;
11318 ptrdiff_t title_start
;
11322 ptrdiff_t count
= SPECPDL_INDEX ();
11324 FOR_EACH_FRAME (tail
, other_frame
)
11326 struct frame
*tf
= XFRAME (other_frame
);
11329 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11330 && !FRAME_MINIBUF_ONLY_P (tf
)
11331 && !EQ (other_frame
, tip_frame
)
11332 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11336 /* Set global variable indicating that multiple frames exist. */
11337 multiple_frames
= CONSP (tail
);
11339 /* Switch to the buffer of selected window of the frame. Set up
11340 mode_line_target so that display_mode_element will output into
11341 mode_line_noprop_buf; then display the title. */
11342 record_unwind_protect (unwind_format_mode_line
,
11343 format_mode_line_unwind_data
11344 (f
, current_buffer
, selected_window
, 0));
11346 Fselect_window (f
->selected_window
, Qt
);
11347 set_buffer_internal_1
11348 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11349 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11351 mode_line_target
= MODE_LINE_TITLE
;
11352 title_start
= MODE_LINE_NOPROP_LEN (0);
11353 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11354 NULL
, DEFAULT_FACE_ID
);
11355 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11356 len
= MODE_LINE_NOPROP_LEN (title_start
);
11357 title
= mode_line_noprop_buf
+ title_start
;
11358 unbind_to (count
, Qnil
);
11360 /* Set the title only if it's changed. This avoids consing in
11361 the common case where it hasn't. (If it turns out that we've
11362 already wasted too much time by walking through the list with
11363 display_mode_element, then we might need to optimize at a
11364 higher level than this.) */
11365 if (! STRINGP (f
->name
)
11366 || SBYTES (f
->name
) != len
11367 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11368 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11372 #endif /* not HAVE_WINDOW_SYSTEM */
11375 /***********************************************************************
11377 ***********************************************************************/
11379 /* Non-zero if we will not redisplay all visible windows. */
11380 #define REDISPLAY_SOME_P() \
11381 ((windows_or_buffers_changed == 0 \
11382 || windows_or_buffers_changed == REDISPLAY_SOME) \
11383 && (update_mode_lines == 0 \
11384 || update_mode_lines == REDISPLAY_SOME))
11386 /* Prepare for redisplay by updating menu-bar item lists when
11387 appropriate. This can call eval. */
11390 prepare_menu_bars (void)
11392 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11393 bool some_windows
= REDISPLAY_SOME_P ();
11394 struct gcpro gcpro1
, gcpro2
;
11395 Lisp_Object tooltip_frame
;
11397 #ifdef HAVE_WINDOW_SYSTEM
11398 tooltip_frame
= tip_frame
;
11400 tooltip_frame
= Qnil
;
11403 if (FUNCTIONP (Vpre_redisplay_function
))
11405 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11406 if (all_windows
&& some_windows
)
11408 Lisp_Object ws
= window_list ();
11409 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11411 Lisp_Object
this = XCAR (ws
);
11412 struct window
*w
= XWINDOW (this);
11414 || XFRAME (w
->frame
)->redisplay
11415 || XBUFFER (w
->contents
)->text
->redisplay
)
11417 windows
= Fcons (this, windows
);
11421 safe_call1 (Vpre_redisplay_function
, windows
);
11424 /* Update all frame titles based on their buffer names, etc. We do
11425 this before the menu bars so that the buffer-menu will show the
11426 up-to-date frame titles. */
11427 #ifdef HAVE_WINDOW_SYSTEM
11430 Lisp_Object tail
, frame
;
11432 FOR_EACH_FRAME (tail
, frame
)
11434 struct frame
*f
= XFRAME (frame
);
11435 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11439 && !XBUFFER (w
->contents
)->text
->redisplay
)
11442 if (!EQ (frame
, tooltip_frame
)
11443 && (FRAME_ICONIFIED_P (f
)
11444 || FRAME_VISIBLE_P (f
) == 1
11445 /* Exclude TTY frames that are obscured because they
11446 are not the top frame on their console. This is
11447 because x_consider_frame_title actually switches
11448 to the frame, which for TTY frames means it is
11449 marked as garbaged, and will be completely
11450 redrawn on the next redisplay cycle. This causes
11451 TTY frames to be completely redrawn, when there
11452 are more than one of them, even though nothing
11453 should be changed on display. */
11454 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11455 x_consider_frame_title (frame
);
11458 #endif /* HAVE_WINDOW_SYSTEM */
11460 /* Update the menu bar item lists, if appropriate. This has to be
11461 done before any actual redisplay or generation of display lines. */
11465 Lisp_Object tail
, frame
;
11466 ptrdiff_t count
= SPECPDL_INDEX ();
11467 /* 1 means that update_menu_bar has run its hooks
11468 so any further calls to update_menu_bar shouldn't do so again. */
11469 int menu_bar_hooks_run
= 0;
11471 record_unwind_save_match_data ();
11473 FOR_EACH_FRAME (tail
, frame
)
11475 struct frame
*f
= XFRAME (frame
);
11476 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11478 /* Ignore tooltip frame. */
11479 if (EQ (frame
, tooltip_frame
))
11485 && !XBUFFER (w
->contents
)->text
->redisplay
)
11488 /* If a window on this frame changed size, report that to
11489 the user and clear the size-change flag. */
11490 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11492 Lisp_Object functions
;
11494 /* Clear flag first in case we get an error below. */
11495 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11496 functions
= Vwindow_size_change_functions
;
11497 GCPRO2 (tail
, functions
);
11499 while (CONSP (functions
))
11501 if (!EQ (XCAR (functions
), Qt
))
11502 call1 (XCAR (functions
), frame
);
11503 functions
= XCDR (functions
);
11509 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11510 #ifdef HAVE_WINDOW_SYSTEM
11511 update_tool_bar (f
, 0);
11514 if (windows_or_buffers_changed
11517 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11522 unbind_to (count
, Qnil
);
11526 struct frame
*sf
= SELECTED_FRAME ();
11527 update_menu_bar (sf
, 1, 0);
11528 #ifdef HAVE_WINDOW_SYSTEM
11529 update_tool_bar (sf
, 1);
11535 /* Update the menu bar item list for frame F. This has to be done
11536 before we start to fill in any display lines, because it can call
11539 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11541 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11542 already ran the menu bar hooks for this redisplay, so there
11543 is no need to run them again. The return value is the
11544 updated value of this flag, to pass to the next call. */
11547 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11549 Lisp_Object window
;
11550 register struct window
*w
;
11552 /* If called recursively during a menu update, do nothing. This can
11553 happen when, for instance, an activate-menubar-hook causes a
11555 if (inhibit_menubar_update
)
11558 window
= FRAME_SELECTED_WINDOW (f
);
11559 w
= XWINDOW (window
);
11561 if (FRAME_WINDOW_P (f
)
11563 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11564 || defined (HAVE_NS) || defined (USE_GTK)
11565 FRAME_EXTERNAL_MENU_BAR (f
)
11567 FRAME_MENU_BAR_LINES (f
) > 0
11569 : FRAME_MENU_BAR_LINES (f
) > 0)
11571 /* If the user has switched buffers or windows, we need to
11572 recompute to reflect the new bindings. But we'll
11573 recompute when update_mode_lines is set too; that means
11574 that people can use force-mode-line-update to request
11575 that the menu bar be recomputed. The adverse effect on
11576 the rest of the redisplay algorithm is about the same as
11577 windows_or_buffers_changed anyway. */
11578 if (windows_or_buffers_changed
11579 /* This used to test w->update_mode_line, but we believe
11580 there is no need to recompute the menu in that case. */
11581 || update_mode_lines
11582 || window_buffer_changed (w
))
11584 struct buffer
*prev
= current_buffer
;
11585 ptrdiff_t count
= SPECPDL_INDEX ();
11587 specbind (Qinhibit_menubar_update
, Qt
);
11589 set_buffer_internal_1 (XBUFFER (w
->contents
));
11590 if (save_match_data
)
11591 record_unwind_save_match_data ();
11592 if (NILP (Voverriding_local_map_menu_flag
))
11594 specbind (Qoverriding_terminal_local_map
, Qnil
);
11595 specbind (Qoverriding_local_map
, Qnil
);
11600 /* Run the Lucid hook. */
11601 safe_run_hooks (Qactivate_menubar_hook
);
11603 /* If it has changed current-menubar from previous value,
11604 really recompute the menu-bar from the value. */
11605 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11606 call0 (Qrecompute_lucid_menubar
);
11608 safe_run_hooks (Qmenu_bar_update_hook
);
11613 XSETFRAME (Vmenu_updating_frame
, f
);
11614 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11616 /* Redisplay the menu bar in case we changed it. */
11617 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11618 || defined (HAVE_NS) || defined (USE_GTK)
11619 if (FRAME_WINDOW_P (f
))
11621 #if defined (HAVE_NS)
11622 /* All frames on Mac OS share the same menubar. So only
11623 the selected frame should be allowed to set it. */
11624 if (f
== SELECTED_FRAME ())
11626 set_frame_menubar (f
, 0, 0);
11629 /* On a terminal screen, the menu bar is an ordinary screen
11630 line, and this makes it get updated. */
11631 w
->update_mode_line
= 1;
11632 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11633 /* In the non-toolkit version, the menu bar is an ordinary screen
11634 line, and this makes it get updated. */
11635 w
->update_mode_line
= 1;
11636 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11638 unbind_to (count
, Qnil
);
11639 set_buffer_internal_1 (prev
);
11646 /***********************************************************************
11648 ***********************************************************************/
11650 #ifdef HAVE_WINDOW_SYSTEM
11652 /* Tool-bar item index of the item on which a mouse button was pressed
11655 int last_tool_bar_item
;
11657 /* Select `frame' temporarily without running all the code in
11659 FIXME: Maybe do_switch_frame should be trimmed down similarly
11660 when `norecord' is set. */
11662 fast_set_selected_frame (Lisp_Object frame
)
11664 if (!EQ (selected_frame
, frame
))
11666 selected_frame
= frame
;
11667 selected_window
= XFRAME (frame
)->selected_window
;
11671 /* Update the tool-bar item list for frame F. This has to be done
11672 before we start to fill in any display lines. Called from
11673 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11674 and restore it here. */
11677 update_tool_bar (struct frame
*f
, int save_match_data
)
11679 #if defined (USE_GTK) || defined (HAVE_NS)
11680 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11682 int do_update
= (WINDOWP (f
->tool_bar_window
)
11683 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0);
11688 Lisp_Object window
;
11691 window
= FRAME_SELECTED_WINDOW (f
);
11692 w
= XWINDOW (window
);
11694 /* If the user has switched buffers or windows, we need to
11695 recompute to reflect the new bindings. But we'll
11696 recompute when update_mode_lines is set too; that means
11697 that people can use force-mode-line-update to request
11698 that the menu bar be recomputed. The adverse effect on
11699 the rest of the redisplay algorithm is about the same as
11700 windows_or_buffers_changed anyway. */
11701 if (windows_or_buffers_changed
11702 || w
->update_mode_line
11703 || update_mode_lines
11704 || window_buffer_changed (w
))
11706 struct buffer
*prev
= current_buffer
;
11707 ptrdiff_t count
= SPECPDL_INDEX ();
11708 Lisp_Object frame
, new_tool_bar
;
11709 int new_n_tool_bar
;
11710 struct gcpro gcpro1
;
11712 /* Set current_buffer to the buffer of the selected
11713 window of the frame, so that we get the right local
11715 set_buffer_internal_1 (XBUFFER (w
->contents
));
11717 /* Save match data, if we must. */
11718 if (save_match_data
)
11719 record_unwind_save_match_data ();
11721 /* Make sure that we don't accidentally use bogus keymaps. */
11722 if (NILP (Voverriding_local_map_menu_flag
))
11724 specbind (Qoverriding_terminal_local_map
, Qnil
);
11725 specbind (Qoverriding_local_map
, Qnil
);
11728 GCPRO1 (new_tool_bar
);
11730 /* We must temporarily set the selected frame to this frame
11731 before calling tool_bar_items, because the calculation of
11732 the tool-bar keymap uses the selected frame (see
11733 `tool-bar-make-keymap' in tool-bar.el). */
11734 eassert (EQ (selected_window
,
11735 /* Since we only explicitly preserve selected_frame,
11736 check that selected_window would be redundant. */
11737 XFRAME (selected_frame
)->selected_window
));
11738 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11739 XSETFRAME (frame
, f
);
11740 fast_set_selected_frame (frame
);
11742 /* Build desired tool-bar items from keymaps. */
11744 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11747 /* Redisplay the tool-bar if we changed it. */
11748 if (new_n_tool_bar
!= f
->n_tool_bar_items
11749 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11751 /* Redisplay that happens asynchronously due to an expose event
11752 may access f->tool_bar_items. Make sure we update both
11753 variables within BLOCK_INPUT so no such event interrupts. */
11755 fset_tool_bar_items (f
, new_tool_bar
);
11756 f
->n_tool_bar_items
= new_n_tool_bar
;
11757 w
->update_mode_line
= 1;
11763 unbind_to (count
, Qnil
);
11764 set_buffer_internal_1 (prev
);
11769 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11771 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11772 F's desired tool-bar contents. F->tool_bar_items must have
11773 been set up previously by calling prepare_menu_bars. */
11776 build_desired_tool_bar_string (struct frame
*f
)
11778 int i
, size
, size_needed
;
11779 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11780 Lisp_Object image
, plist
, props
;
11782 image
= plist
= props
= Qnil
;
11783 GCPRO3 (image
, plist
, props
);
11785 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11786 Otherwise, make a new string. */
11788 /* The size of the string we might be able to reuse. */
11789 size
= (STRINGP (f
->desired_tool_bar_string
)
11790 ? SCHARS (f
->desired_tool_bar_string
)
11793 /* We need one space in the string for each image. */
11794 size_needed
= f
->n_tool_bar_items
;
11796 /* Reuse f->desired_tool_bar_string, if possible. */
11797 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11798 fset_desired_tool_bar_string
11799 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11802 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11803 Fremove_text_properties (make_number (0), make_number (size
),
11804 props
, f
->desired_tool_bar_string
);
11807 /* Put a `display' property on the string for the images to display,
11808 put a `menu_item' property on tool-bar items with a value that
11809 is the index of the item in F's tool-bar item vector. */
11810 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11812 #define PROP(IDX) \
11813 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11815 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11816 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11817 int hmargin
, vmargin
, relief
, idx
, end
;
11819 /* If image is a vector, choose the image according to the
11821 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11822 if (VECTORP (image
))
11826 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11827 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11830 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11831 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11833 eassert (ASIZE (image
) >= idx
);
11834 image
= AREF (image
, idx
);
11839 /* Ignore invalid image specifications. */
11840 if (!valid_image_p (image
))
11843 /* Display the tool-bar button pressed, or depressed. */
11844 plist
= Fcopy_sequence (XCDR (image
));
11846 /* Compute margin and relief to draw. */
11847 relief
= (tool_bar_button_relief
>= 0
11848 ? tool_bar_button_relief
11849 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11850 hmargin
= vmargin
= relief
;
11852 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11853 INT_MAX
- max (hmargin
, vmargin
)))
11855 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11856 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11858 else if (CONSP (Vtool_bar_button_margin
))
11860 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11861 INT_MAX
- hmargin
))
11862 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11864 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11865 INT_MAX
- vmargin
))
11866 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11869 if (auto_raise_tool_bar_buttons_p
)
11871 /* Add a `:relief' property to the image spec if the item is
11875 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11882 /* If image is selected, display it pressed, i.e. with a
11883 negative relief. If it's not selected, display it with a
11885 plist
= Fplist_put (plist
, QCrelief
,
11887 ? make_number (-relief
)
11888 : make_number (relief
)));
11893 /* Put a margin around the image. */
11894 if (hmargin
|| vmargin
)
11896 if (hmargin
== vmargin
)
11897 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11899 plist
= Fplist_put (plist
, QCmargin
,
11900 Fcons (make_number (hmargin
),
11901 make_number (vmargin
)));
11904 /* If button is not enabled, and we don't have special images
11905 for the disabled state, make the image appear disabled by
11906 applying an appropriate algorithm to it. */
11907 if (!enabled_p
&& idx
< 0)
11908 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11910 /* Put a `display' text property on the string for the image to
11911 display. Put a `menu-item' property on the string that gives
11912 the start of this item's properties in the tool-bar items
11914 image
= Fcons (Qimage
, plist
);
11915 props
= list4 (Qdisplay
, image
,
11916 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11918 /* Let the last image hide all remaining spaces in the tool bar
11919 string. The string can be longer than needed when we reuse a
11920 previous string. */
11921 if (i
+ 1 == f
->n_tool_bar_items
)
11922 end
= SCHARS (f
->desired_tool_bar_string
);
11925 Fadd_text_properties (make_number (i
), make_number (end
),
11926 props
, f
->desired_tool_bar_string
);
11934 /* Display one line of the tool-bar of frame IT->f.
11936 HEIGHT specifies the desired height of the tool-bar line.
11937 If the actual height of the glyph row is less than HEIGHT, the
11938 row's height is increased to HEIGHT, and the icons are centered
11939 vertically in the new height.
11941 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11942 count a final empty row in case the tool-bar width exactly matches
11947 display_tool_bar_line (struct it
*it
, int height
)
11949 struct glyph_row
*row
= it
->glyph_row
;
11950 int max_x
= it
->last_visible_x
;
11951 struct glyph
*last
;
11953 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
11954 clear_glyph_row (row
);
11955 row
->enabled_p
= true;
11956 row
->y
= it
->current_y
;
11958 /* Note that this isn't made use of if the face hasn't a box,
11959 so there's no need to check the face here. */
11960 it
->start_of_box_run_p
= 1;
11962 while (it
->current_x
< max_x
)
11964 int x
, n_glyphs_before
, i
, nglyphs
;
11965 struct it it_before
;
11967 /* Get the next display element. */
11968 if (!get_next_display_element (it
))
11970 /* Don't count empty row if we are counting needed tool-bar lines. */
11971 if (height
< 0 && !it
->hpos
)
11976 /* Produce glyphs. */
11977 n_glyphs_before
= row
->used
[TEXT_AREA
];
11980 PRODUCE_GLYPHS (it
);
11982 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11984 x
= it_before
.current_x
;
11985 while (i
< nglyphs
)
11987 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11989 if (x
+ glyph
->pixel_width
> max_x
)
11991 /* Glyph doesn't fit on line. Backtrack. */
11992 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11994 /* If this is the only glyph on this line, it will never fit on the
11995 tool-bar, so skip it. But ensure there is at least one glyph,
11996 so we don't accidentally disable the tool-bar. */
11997 if (n_glyphs_before
== 0
11998 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
12004 x
+= glyph
->pixel_width
;
12008 /* Stop at line end. */
12009 if (ITERATOR_AT_END_OF_LINE_P (it
))
12012 set_iterator_to_next (it
, 1);
12017 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12019 /* Use default face for the border below the tool bar.
12021 FIXME: When auto-resize-tool-bars is grow-only, there is
12022 no additional border below the possibly empty tool-bar lines.
12023 So to make the extra empty lines look "normal", we have to
12024 use the tool-bar face for the border too. */
12025 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12026 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12027 it
->face_id
= DEFAULT_FACE_ID
;
12029 extend_face_to_end_of_line (it
);
12030 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12031 last
->right_box_line_p
= 1;
12032 if (last
== row
->glyphs
[TEXT_AREA
])
12033 last
->left_box_line_p
= 1;
12035 /* Make line the desired height and center it vertically. */
12036 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12038 /* Don't add more than one line height. */
12039 height
%= FRAME_LINE_HEIGHT (it
->f
);
12040 it
->max_ascent
+= height
/ 2;
12041 it
->max_descent
+= (height
+ 1) / 2;
12044 compute_line_metrics (it
);
12046 /* If line is empty, make it occupy the rest of the tool-bar. */
12047 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12049 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12050 row
->visible_height
= row
->height
;
12051 row
->ascent
= row
->phys_ascent
= 0;
12052 row
->extra_line_spacing
= 0;
12055 row
->full_width_p
= 1;
12056 row
->continued_p
= 0;
12057 row
->truncated_on_left_p
= 0;
12058 row
->truncated_on_right_p
= 0;
12060 it
->current_x
= it
->hpos
= 0;
12061 it
->current_y
+= row
->height
;
12067 /* Max tool-bar height. Basically, this is what makes all other windows
12068 disappear when the frame gets too small. Rethink this! */
12070 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
12071 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
12073 /* Value is the number of pixels needed to make all tool-bar items of
12074 frame F visible. The actual number of glyph rows needed is
12075 returned in *N_ROWS if non-NULL. */
12078 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12080 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12082 /* tool_bar_height is called from redisplay_tool_bar after building
12083 the desired matrix, so use (unused) mode-line row as temporary row to
12084 avoid destroying the first tool-bar row. */
12085 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12087 /* Initialize an iterator for iteration over
12088 F->desired_tool_bar_string in the tool-bar window of frame F. */
12089 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12090 it
.first_visible_x
= 0;
12091 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12092 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12093 it
.paragraph_embedding
= L2R
;
12095 while (!ITERATOR_AT_END_P (&it
))
12097 clear_glyph_row (temp_row
);
12098 it
.glyph_row
= temp_row
;
12099 display_tool_bar_line (&it
, -1);
12101 clear_glyph_row (temp_row
);
12103 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12105 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12108 return it
.current_y
;
12110 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12113 #endif /* !USE_GTK && !HAVE_NS */
12115 #if defined USE_GTK || defined HAVE_NS
12116 EXFUN (Ftool_bar_height
, 2) ATTRIBUTE_CONST
;
12117 EXFUN (Ftool_bar_lines_needed
, 1) ATTRIBUTE_CONST
;
12120 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12122 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12123 If FRAME is nil or omitted, use the selected frame. Optional argument
12124 PIXELWISE non-nil means return the height of the tool bar in pixels. */)
12125 (Lisp_Object frame
, Lisp_Object pixelwise
)
12129 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12130 struct frame
*f
= decode_any_frame (frame
);
12132 if (WINDOWP (f
->tool_bar_window
)
12133 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12135 update_tool_bar (f
, 1);
12136 if (f
->n_tool_bar_items
)
12138 build_desired_tool_bar_string (f
);
12139 height
= tool_bar_height (f
, NULL
, NILP (pixelwise
) ? 0 : 1);
12144 return make_number (height
);
12148 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12149 height should be changed. */
12152 redisplay_tool_bar (struct frame
*f
)
12154 #if defined (USE_GTK) || defined (HAVE_NS)
12156 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12157 update_frame_tool_bar (f
);
12160 #else /* !USE_GTK && !HAVE_NS */
12164 struct glyph_row
*row
;
12166 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12167 do anything. This means you must start with tool-bar-lines
12168 non-zero to get the auto-sizing effect. Or in other words, you
12169 can turn off tool-bars by specifying tool-bar-lines zero. */
12170 if (!WINDOWP (f
->tool_bar_window
)
12171 || (w
= XWINDOW (f
->tool_bar_window
),
12172 WINDOW_PIXEL_HEIGHT (w
) == 0))
12175 /* Set up an iterator for the tool-bar window. */
12176 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12177 it
.first_visible_x
= 0;
12178 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12179 row
= it
.glyph_row
;
12181 /* Build a string that represents the contents of the tool-bar. */
12182 build_desired_tool_bar_string (f
);
12183 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12184 /* FIXME: This should be controlled by a user option. But it
12185 doesn't make sense to have an R2L tool bar if the menu bar cannot
12186 be drawn also R2L, and making the menu bar R2L is tricky due
12187 toolkit-specific code that implements it. If an R2L tool bar is
12188 ever supported, display_tool_bar_line should also be augmented to
12189 call unproduce_glyphs like display_line and display_string
12191 it
.paragraph_embedding
= L2R
;
12193 if (f
->n_tool_bar_rows
== 0)
12195 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, 1);
12197 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12200 int new_lines
= ((new_height
+ FRAME_LINE_HEIGHT (f
) - 1)
12201 / FRAME_LINE_HEIGHT (f
));
12203 XSETFRAME (frame
, f
);
12204 Fmodify_frame_parameters (frame
,
12205 list1 (Fcons (Qtool_bar_lines
,
12206 make_number (new_lines
))));
12207 /* Always do that now. */
12208 clear_glyph_matrix (w
->desired_matrix
);
12209 f
->fonts_changed
= 1;
12214 /* Display as many lines as needed to display all tool-bar items. */
12216 if (f
->n_tool_bar_rows
> 0)
12218 int border
, rows
, height
, extra
;
12220 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12221 border
= XINT (Vtool_bar_border
);
12222 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12223 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12224 else if (EQ (Vtool_bar_border
, Qborder_width
))
12225 border
= f
->border_width
;
12231 rows
= f
->n_tool_bar_rows
;
12232 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12233 extra
= it
.last_visible_y
- border
- height
* rows
;
12235 while (it
.current_y
< it
.last_visible_y
)
12238 if (extra
> 0 && rows
-- > 0)
12240 h
= (extra
+ rows
- 1) / rows
;
12243 display_tool_bar_line (&it
, height
+ h
);
12248 while (it
.current_y
< it
.last_visible_y
)
12249 display_tool_bar_line (&it
, 0);
12252 /* It doesn't make much sense to try scrolling in the tool-bar
12253 window, so don't do it. */
12254 w
->desired_matrix
->no_scrolling_p
= 1;
12255 w
->must_be_updated_p
= 1;
12257 if (!NILP (Vauto_resize_tool_bars
))
12259 /* Do we really allow the toolbar to occupy the whole frame? */
12260 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12261 int change_height_p
= 0;
12263 /* If we couldn't display everything, change the tool-bar's
12264 height if there is room for more. */
12265 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12266 && it
.current_y
< max_tool_bar_height
)
12267 change_height_p
= 1;
12269 /* We subtract 1 because display_tool_bar_line advances the
12270 glyph_row pointer before returning to its caller. We want to
12271 examine the last glyph row produced by
12272 display_tool_bar_line. */
12273 row
= it
.glyph_row
- 1;
12275 /* If there are blank lines at the end, except for a partially
12276 visible blank line at the end that is smaller than
12277 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12278 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12279 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12280 change_height_p
= 1;
12282 /* If row displays tool-bar items, but is partially visible,
12283 change the tool-bar's height. */
12284 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12285 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12286 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12287 change_height_p
= 1;
12289 /* Resize windows as needed by changing the `tool-bar-lines'
12290 frame parameter. */
12291 if (change_height_p
)
12295 int new_height
= tool_bar_height (f
, &nrows
, 1);
12297 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12298 && !f
->minimize_tool_bar_window_p
)
12299 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12300 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12301 f
->minimize_tool_bar_window_p
= 0;
12303 if (change_height_p
)
12305 /* Current size of the tool-bar window in canonical line
12307 int old_lines
= WINDOW_TOTAL_LINES (w
);
12308 /* Required size of the tool-bar window in canonical
12310 int new_lines
= ((new_height
+ FRAME_LINE_HEIGHT (f
) - 1)
12311 / FRAME_LINE_HEIGHT (f
));
12312 /* Maximum size of the tool-bar window in canonical line
12313 units that this frame can allow. */
12315 WINDOW_TOTAL_LINES (XWINDOW (FRAME_ROOT_WINDOW (f
))) - 1;
12317 /* Don't try to change the tool-bar window size and set
12318 the fonts_changed flag unless really necessary. That
12319 flag causes redisplay to give up and retry
12320 redisplaying the frame from scratch, so setting it
12321 unnecessarily can lead to nasty redisplay loops. */
12322 if (new_lines
<= max_lines
12323 && eabs (new_lines
- old_lines
) >= 1)
12325 XSETFRAME (frame
, f
);
12326 Fmodify_frame_parameters (frame
,
12327 list1 (Fcons (Qtool_bar_lines
,
12328 make_number (new_lines
))));
12329 clear_glyph_matrix (w
->desired_matrix
);
12330 f
->n_tool_bar_rows
= nrows
;
12331 f
->fonts_changed
= 1;
12338 f
->minimize_tool_bar_window_p
= 0;
12341 #endif /* USE_GTK || HAVE_NS */
12344 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12346 /* Get information about the tool-bar item which is displayed in GLYPH
12347 on frame F. Return in *PROP_IDX the index where tool-bar item
12348 properties start in F->tool_bar_items. Value is zero if
12349 GLYPH doesn't display a tool-bar item. */
12352 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12358 /* This function can be called asynchronously, which means we must
12359 exclude any possibility that Fget_text_property signals an
12361 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12362 charpos
= max (0, charpos
);
12364 /* Get the text property `menu-item' at pos. The value of that
12365 property is the start index of this item's properties in
12366 F->tool_bar_items. */
12367 prop
= Fget_text_property (make_number (charpos
),
12368 Qmenu_item
, f
->current_tool_bar_string
);
12369 if (INTEGERP (prop
))
12371 *prop_idx
= XINT (prop
);
12381 /* Get information about the tool-bar item at position X/Y on frame F.
12382 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12383 the current matrix of the tool-bar window of F, or NULL if not
12384 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12385 item in F->tool_bar_items. Value is
12387 -1 if X/Y is not on a tool-bar item
12388 0 if X/Y is on the same item that was highlighted before.
12392 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12393 int *hpos
, int *vpos
, int *prop_idx
)
12395 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12396 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12399 /* Find the glyph under X/Y. */
12400 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12401 if (*glyph
== NULL
)
12404 /* Get the start of this tool-bar item's properties in
12405 f->tool_bar_items. */
12406 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12409 /* Is mouse on the highlighted item? */
12410 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12411 && *vpos
>= hlinfo
->mouse_face_beg_row
12412 && *vpos
<= hlinfo
->mouse_face_end_row
12413 && (*vpos
> hlinfo
->mouse_face_beg_row
12414 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12415 && (*vpos
< hlinfo
->mouse_face_end_row
12416 || *hpos
< hlinfo
->mouse_face_end_col
12417 || hlinfo
->mouse_face_past_end
))
12425 Handle mouse button event on the tool-bar of frame F, at
12426 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12427 0 for button release. MODIFIERS is event modifiers for button
12431 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12434 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12435 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12436 int hpos
, vpos
, prop_idx
;
12437 struct glyph
*glyph
;
12438 Lisp_Object enabled_p
;
12441 /* If not on the highlighted tool-bar item, and mouse-highlight is
12442 non-nil, return. This is so we generate the tool-bar button
12443 click only when the mouse button is released on the same item as
12444 where it was pressed. However, when mouse-highlight is disabled,
12445 generate the click when the button is released regardless of the
12446 highlight, since tool-bar items are not highlighted in that
12448 frame_to_window_pixel_xy (w
, &x
, &y
);
12449 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12451 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12454 /* When mouse-highlight is off, generate the click for the item
12455 where the button was pressed, disregarding where it was
12457 if (NILP (Vmouse_highlight
) && !down_p
)
12458 prop_idx
= last_tool_bar_item
;
12460 /* If item is disabled, do nothing. */
12461 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12462 if (NILP (enabled_p
))
12467 /* Show item in pressed state. */
12468 if (!NILP (Vmouse_highlight
))
12469 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12470 last_tool_bar_item
= prop_idx
;
12474 Lisp_Object key
, frame
;
12475 struct input_event event
;
12476 EVENT_INIT (event
);
12478 /* Show item in released state. */
12479 if (!NILP (Vmouse_highlight
))
12480 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12482 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12484 XSETFRAME (frame
, f
);
12485 event
.kind
= TOOL_BAR_EVENT
;
12486 event
.frame_or_window
= frame
;
12488 kbd_buffer_store_event (&event
);
12490 event
.kind
= TOOL_BAR_EVENT
;
12491 event
.frame_or_window
= frame
;
12493 event
.modifiers
= modifiers
;
12494 kbd_buffer_store_event (&event
);
12495 last_tool_bar_item
= -1;
12500 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12501 tool-bar window-relative coordinates X/Y. Called from
12502 note_mouse_highlight. */
12505 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12507 Lisp_Object window
= f
->tool_bar_window
;
12508 struct window
*w
= XWINDOW (window
);
12509 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12510 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12512 struct glyph
*glyph
;
12513 struct glyph_row
*row
;
12515 Lisp_Object enabled_p
;
12517 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12518 int mouse_down_p
, rc
;
12520 /* Function note_mouse_highlight is called with negative X/Y
12521 values when mouse moves outside of the frame. */
12522 if (x
<= 0 || y
<= 0)
12524 clear_mouse_face (hlinfo
);
12528 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12531 /* Not on tool-bar item. */
12532 clear_mouse_face (hlinfo
);
12536 /* On same tool-bar item as before. */
12537 goto set_help_echo
;
12539 clear_mouse_face (hlinfo
);
12541 /* Mouse is down, but on different tool-bar item? */
12542 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12543 && f
== dpyinfo
->last_mouse_frame
);
12546 && last_tool_bar_item
!= prop_idx
)
12549 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12551 /* If tool-bar item is not enabled, don't highlight it. */
12552 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12553 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12555 /* Compute the x-position of the glyph. In front and past the
12556 image is a space. We include this in the highlighted area. */
12557 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12558 for (i
= x
= 0; i
< hpos
; ++i
)
12559 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12561 /* Record this as the current active region. */
12562 hlinfo
->mouse_face_beg_col
= hpos
;
12563 hlinfo
->mouse_face_beg_row
= vpos
;
12564 hlinfo
->mouse_face_beg_x
= x
;
12565 hlinfo
->mouse_face_past_end
= 0;
12567 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12568 hlinfo
->mouse_face_end_row
= vpos
;
12569 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12570 hlinfo
->mouse_face_window
= window
;
12571 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12573 /* Display it as active. */
12574 show_mouse_face (hlinfo
, draw
);
12579 /* Set help_echo_string to a help string to display for this tool-bar item.
12580 XTread_socket does the rest. */
12581 help_echo_object
= help_echo_window
= Qnil
;
12582 help_echo_pos
= -1;
12583 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12584 if (NILP (help_echo_string
))
12585 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12588 #endif /* !USE_GTK && !HAVE_NS */
12590 #endif /* HAVE_WINDOW_SYSTEM */
12594 /************************************************************************
12595 Horizontal scrolling
12596 ************************************************************************/
12598 static int hscroll_window_tree (Lisp_Object
);
12599 static int hscroll_windows (Lisp_Object
);
12601 /* For all leaf windows in the window tree rooted at WINDOW, set their
12602 hscroll value so that PT is (i) visible in the window, and (ii) so
12603 that it is not within a certain margin at the window's left and
12604 right border. Value is non-zero if any window's hscroll has been
12608 hscroll_window_tree (Lisp_Object window
)
12610 int hscrolled_p
= 0;
12611 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12612 int hscroll_step_abs
= 0;
12613 double hscroll_step_rel
= 0;
12615 if (hscroll_relative_p
)
12617 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12618 if (hscroll_step_rel
< 0)
12620 hscroll_relative_p
= 0;
12621 hscroll_step_abs
= 0;
12624 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12626 hscroll_step_abs
= XINT (Vhscroll_step
);
12627 if (hscroll_step_abs
< 0)
12628 hscroll_step_abs
= 0;
12631 hscroll_step_abs
= 0;
12633 while (WINDOWP (window
))
12635 struct window
*w
= XWINDOW (window
);
12637 if (WINDOWP (w
->contents
))
12638 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12639 else if (w
->cursor
.vpos
>= 0)
12642 int text_area_width
;
12643 struct glyph_row
*cursor_row
;
12644 struct glyph_row
*bottom_row
;
12647 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->desired_matrix
, w
);
12648 if (w
->cursor
.vpos
< bottom_row
- w
->desired_matrix
->rows
)
12649 cursor_row
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12651 cursor_row
= bottom_row
- 1;
12653 if (!cursor_row
->enabled_p
)
12655 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12656 if (w
->cursor
.vpos
< bottom_row
- w
->current_matrix
->rows
)
12657 cursor_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12659 cursor_row
= bottom_row
- 1;
12661 row_r2l_p
= cursor_row
->reversed_p
;
12663 text_area_width
= window_box_width (w
, TEXT_AREA
);
12665 /* Scroll when cursor is inside this scroll margin. */
12666 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12668 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12669 /* For left-to-right rows, hscroll when cursor is either
12670 (i) inside the right hscroll margin, or (ii) if it is
12671 inside the left margin and the window is already
12675 && w
->cursor
.x
<= h_margin
)
12676 || (cursor_row
->enabled_p
12677 && cursor_row
->truncated_on_right_p
12678 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12679 /* For right-to-left rows, the logic is similar,
12680 except that rules for scrolling to left and right
12681 are reversed. E.g., if cursor.x <= h_margin, we
12682 need to hscroll "to the right" unconditionally,
12683 and that will scroll the screen to the left so as
12684 to reveal the next portion of the row. */
12686 && ((cursor_row
->enabled_p
12687 /* FIXME: It is confusing to set the
12688 truncated_on_right_p flag when R2L rows
12689 are actually truncated on the left. */
12690 && cursor_row
->truncated_on_right_p
12691 && w
->cursor
.x
<= h_margin
)
12693 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12697 struct buffer
*saved_current_buffer
;
12701 /* Find point in a display of infinite width. */
12702 saved_current_buffer
= current_buffer
;
12703 current_buffer
= XBUFFER (w
->contents
);
12705 if (w
== XWINDOW (selected_window
))
12708 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12710 /* Move iterator to pt starting at cursor_row->start in
12711 a line with infinite width. */
12712 init_to_row_start (&it
, w
, cursor_row
);
12713 it
.last_visible_x
= INFINITY
;
12714 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12715 current_buffer
= saved_current_buffer
;
12717 /* Position cursor in window. */
12718 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12719 hscroll
= max (0, (it
.current_x
12720 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12721 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12722 : (text_area_width
/ 2))))
12723 / FRAME_COLUMN_WIDTH (it
.f
);
12724 else if ((!row_r2l_p
12725 && w
->cursor
.x
>= text_area_width
- h_margin
)
12726 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12728 if (hscroll_relative_p
)
12729 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12732 wanted_x
= text_area_width
12733 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12736 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12740 if (hscroll_relative_p
)
12741 wanted_x
= text_area_width
* hscroll_step_rel
12744 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12747 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12749 hscroll
= max (hscroll
, w
->min_hscroll
);
12751 /* Don't prevent redisplay optimizations if hscroll
12752 hasn't changed, as it will unnecessarily slow down
12754 if (w
->hscroll
!= hscroll
)
12756 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12757 w
->hscroll
= hscroll
;
12766 /* Value is non-zero if hscroll of any leaf window has been changed. */
12767 return hscrolled_p
;
12771 /* Set hscroll so that cursor is visible and not inside horizontal
12772 scroll margins for all windows in the tree rooted at WINDOW. See
12773 also hscroll_window_tree above. Value is non-zero if any window's
12774 hscroll has been changed. If it has, desired matrices on the frame
12775 of WINDOW are cleared. */
12778 hscroll_windows (Lisp_Object window
)
12780 int hscrolled_p
= hscroll_window_tree (window
);
12782 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12783 return hscrolled_p
;
12788 /************************************************************************
12790 ************************************************************************/
12792 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12793 to a non-zero value. This is sometimes handy to have in a debugger
12798 /* First and last unchanged row for try_window_id. */
12800 static int debug_first_unchanged_at_end_vpos
;
12801 static int debug_last_unchanged_at_beg_vpos
;
12803 /* Delta vpos and y. */
12805 static int debug_dvpos
, debug_dy
;
12807 /* Delta in characters and bytes for try_window_id. */
12809 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12811 /* Values of window_end_pos and window_end_vpos at the end of
12814 static ptrdiff_t debug_end_vpos
;
12816 /* Append a string to W->desired_matrix->method. FMT is a printf
12817 format string. If trace_redisplay_p is true also printf the
12818 resulting string to stderr. */
12820 static void debug_method_add (struct window
*, char const *, ...)
12821 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12824 debug_method_add (struct window
*w
, char const *fmt
, ...)
12827 char *method
= w
->desired_matrix
->method
;
12828 int len
= strlen (method
);
12829 int size
= sizeof w
->desired_matrix
->method
;
12830 int remaining
= size
- len
- 1;
12833 if (len
&& remaining
)
12836 --remaining
, ++len
;
12839 va_start (ap
, fmt
);
12840 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12843 if (trace_redisplay_p
)
12844 fprintf (stderr
, "%p (%s): %s\n",
12846 ((BUFFERP (w
->contents
)
12847 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12848 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12853 #endif /* GLYPH_DEBUG */
12856 /* Value is non-zero if all changes in window W, which displays
12857 current_buffer, are in the text between START and END. START is a
12858 buffer position, END is given as a distance from Z. Used in
12859 redisplay_internal for display optimization. */
12862 text_outside_line_unchanged_p (struct window
*w
,
12863 ptrdiff_t start
, ptrdiff_t end
)
12865 int unchanged_p
= 1;
12867 /* If text or overlays have changed, see where. */
12868 if (window_outdated (w
))
12870 /* Gap in the line? */
12871 if (GPT
< start
|| Z
- GPT
< end
)
12874 /* Changes start in front of the line, or end after it? */
12876 && (BEG_UNCHANGED
< start
- 1
12877 || END_UNCHANGED
< end
))
12880 /* If selective display, can't optimize if changes start at the
12881 beginning of the line. */
12883 && INTEGERP (BVAR (current_buffer
, selective_display
))
12884 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12885 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12888 /* If there are overlays at the start or end of the line, these
12889 may have overlay strings with newlines in them. A change at
12890 START, for instance, may actually concern the display of such
12891 overlay strings as well, and they are displayed on different
12892 lines. So, quickly rule out this case. (For the future, it
12893 might be desirable to implement something more telling than
12894 just BEG/END_UNCHANGED.) */
12897 if (BEG
+ BEG_UNCHANGED
== start
12898 && overlay_touches_p (start
))
12900 if (END_UNCHANGED
== end
12901 && overlay_touches_p (Z
- end
))
12905 /* Under bidi reordering, adding or deleting a character in the
12906 beginning of a paragraph, before the first strong directional
12907 character, can change the base direction of the paragraph (unless
12908 the buffer specifies a fixed paragraph direction), which will
12909 require to redisplay the whole paragraph. It might be worthwhile
12910 to find the paragraph limits and widen the range of redisplayed
12911 lines to that, but for now just give up this optimization. */
12912 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12913 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12917 return unchanged_p
;
12921 /* Do a frame update, taking possible shortcuts into account. This is
12922 the main external entry point for redisplay.
12924 If the last redisplay displayed an echo area message and that message
12925 is no longer requested, we clear the echo area or bring back the
12926 mini-buffer if that is in use. */
12931 redisplay_internal ();
12936 overlay_arrow_string_or_property (Lisp_Object var
)
12940 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12943 return Voverlay_arrow_string
;
12946 /* Return 1 if there are any overlay-arrows in current_buffer. */
12948 overlay_arrow_in_current_buffer_p (void)
12952 for (vlist
= Voverlay_arrow_variable_list
;
12954 vlist
= XCDR (vlist
))
12956 Lisp_Object var
= XCAR (vlist
);
12959 if (!SYMBOLP (var
))
12961 val
= find_symbol_value (var
);
12963 && current_buffer
== XMARKER (val
)->buffer
)
12970 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12974 overlay_arrows_changed_p (void)
12978 for (vlist
= Voverlay_arrow_variable_list
;
12980 vlist
= XCDR (vlist
))
12982 Lisp_Object var
= XCAR (vlist
);
12983 Lisp_Object val
, pstr
;
12985 if (!SYMBOLP (var
))
12987 val
= find_symbol_value (var
);
12988 if (!MARKERP (val
))
12990 if (! EQ (COERCE_MARKER (val
),
12991 Fget (var
, Qlast_arrow_position
))
12992 || ! (pstr
= overlay_arrow_string_or_property (var
),
12993 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12999 /* Mark overlay arrows to be updated on next redisplay. */
13002 update_overlay_arrows (int up_to_date
)
13006 for (vlist
= Voverlay_arrow_variable_list
;
13008 vlist
= XCDR (vlist
))
13010 Lisp_Object var
= XCAR (vlist
);
13012 if (!SYMBOLP (var
))
13015 if (up_to_date
> 0)
13017 Lisp_Object val
= find_symbol_value (var
);
13018 Fput (var
, Qlast_arrow_position
,
13019 COERCE_MARKER (val
));
13020 Fput (var
, Qlast_arrow_string
,
13021 overlay_arrow_string_or_property (var
));
13023 else if (up_to_date
< 0
13024 || !NILP (Fget (var
, Qlast_arrow_position
)))
13026 Fput (var
, Qlast_arrow_position
, Qt
);
13027 Fput (var
, Qlast_arrow_string
, Qt
);
13033 /* Return overlay arrow string to display at row.
13034 Return integer (bitmap number) for arrow bitmap in left fringe.
13035 Return nil if no overlay arrow. */
13038 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
13042 for (vlist
= Voverlay_arrow_variable_list
;
13044 vlist
= XCDR (vlist
))
13046 Lisp_Object var
= XCAR (vlist
);
13049 if (!SYMBOLP (var
))
13052 val
= find_symbol_value (var
);
13055 && current_buffer
== XMARKER (val
)->buffer
13056 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13058 if (FRAME_WINDOW_P (it
->f
)
13059 /* FIXME: if ROW->reversed_p is set, this should test
13060 the right fringe, not the left one. */
13061 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13063 #ifdef HAVE_WINDOW_SYSTEM
13064 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13067 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
13068 return make_number (fringe_bitmap
);
13071 return make_number (-1); /* Use default arrow bitmap. */
13073 return overlay_arrow_string_or_property (var
);
13080 /* Return 1 if point moved out of or into a composition. Otherwise
13081 return 0. PREV_BUF and PREV_PT are the last point buffer and
13082 position. BUF and PT are the current point buffer and position. */
13085 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13086 struct buffer
*buf
, ptrdiff_t pt
)
13088 ptrdiff_t start
, end
;
13090 Lisp_Object buffer
;
13092 XSETBUFFER (buffer
, buf
);
13093 /* Check a composition at the last point if point moved within the
13095 if (prev_buf
== buf
)
13098 /* Point didn't move. */
13101 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13102 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13103 && composition_valid_p (start
, end
, prop
)
13104 && start
< prev_pt
&& end
> prev_pt
)
13105 /* The last point was within the composition. Return 1 iff
13106 point moved out of the composition. */
13107 return (pt
<= start
|| pt
>= end
);
13110 /* Check a composition at the current point. */
13111 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13112 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13113 && composition_valid_p (start
, end
, prop
)
13114 && start
< pt
&& end
> pt
);
13117 /* Reconsider the clip changes of buffer which is displayed in W. */
13120 reconsider_clip_changes (struct window
*w
)
13122 struct buffer
*b
= XBUFFER (w
->contents
);
13124 if (b
->clip_changed
13125 && w
->window_end_valid
13126 && w
->current_matrix
->buffer
== b
13127 && w
->current_matrix
->zv
== BUF_ZV (b
)
13128 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13129 b
->clip_changed
= 0;
13131 /* If display wasn't paused, and W is not a tool bar window, see if
13132 point has been moved into or out of a composition. In that case,
13133 we set b->clip_changed to 1 to force updating the screen. If
13134 b->clip_changed has already been set to 1, we can skip this
13136 if (!b
->clip_changed
&& w
->window_end_valid
)
13138 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13139 ? PT
: marker_position (w
->pointm
));
13141 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13142 && check_point_in_composition (w
->current_matrix
->buffer
,
13143 w
->last_point
, b
, pt
))
13144 b
->clip_changed
= 1;
13149 propagate_buffer_redisplay (void)
13150 { /* Resetting b->text->redisplay is problematic!
13151 We can't just reset it in the case that some window that displays
13152 it has not been redisplayed; and such a window can stay
13153 unredisplayed for a long time if it's currently invisible.
13154 But we do want to reset it at the end of redisplay otherwise
13155 its displayed windows will keep being redisplayed over and over
13157 So we copy all b->text->redisplay flags up to their windows here,
13158 such that mark_window_display_accurate can safely reset
13159 b->text->redisplay. */
13160 Lisp_Object ws
= window_list ();
13161 for (; CONSP (ws
); ws
= XCDR (ws
))
13163 struct window
*thisw
= XWINDOW (XCAR (ws
));
13164 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13165 if (thisb
->text
->redisplay
)
13166 thisw
->redisplay
= true;
13170 #define STOP_POLLING \
13171 do { if (! polling_stopped_here) stop_polling (); \
13172 polling_stopped_here = 1; } while (0)
13174 #define RESUME_POLLING \
13175 do { if (polling_stopped_here) start_polling (); \
13176 polling_stopped_here = 0; } while (0)
13179 /* Perhaps in the future avoid recentering windows if it
13180 is not necessary; currently that causes some problems. */
13183 redisplay_internal (void)
13185 struct window
*w
= XWINDOW (selected_window
);
13189 bool must_finish
= 0, match_p
;
13190 struct text_pos tlbufpos
, tlendpos
;
13191 int number_of_visible_frames
;
13194 int polling_stopped_here
= 0;
13195 Lisp_Object tail
, frame
;
13197 /* True means redisplay has to consider all windows on all
13198 frames. False, only selected_window is considered. */
13199 bool consider_all_windows_p
;
13201 /* True means redisplay has to redisplay the miniwindow. */
13202 bool update_miniwindow_p
= false;
13204 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13206 /* No redisplay if running in batch mode or frame is not yet fully
13207 initialized, or redisplay is explicitly turned off by setting
13208 Vinhibit_redisplay. */
13209 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13210 || !NILP (Vinhibit_redisplay
))
13213 /* Don't examine these until after testing Vinhibit_redisplay.
13214 When Emacs is shutting down, perhaps because its connection to
13215 X has dropped, we should not look at them at all. */
13216 fr
= XFRAME (w
->frame
);
13217 sf
= SELECTED_FRAME ();
13219 if (!fr
->glyphs_initialized_p
)
13222 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13223 if (popup_activated ())
13227 /* I don't think this happens but let's be paranoid. */
13228 if (redisplaying_p
)
13231 /* Record a function that clears redisplaying_p
13232 when we leave this function. */
13233 count
= SPECPDL_INDEX ();
13234 record_unwind_protect_void (unwind_redisplay
);
13235 redisplaying_p
= 1;
13236 specbind (Qinhibit_free_realized_faces
, Qnil
);
13238 /* Record this function, so it appears on the profiler's backtraces. */
13239 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
13241 FOR_EACH_FRAME (tail
, frame
)
13242 XFRAME (frame
)->already_hscrolled_p
= 0;
13245 /* Remember the currently selected window. */
13249 last_escape_glyph_frame
= NULL
;
13250 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13251 last_glyphless_glyph_frame
= NULL
;
13252 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13254 /* If face_change_count is non-zero, init_iterator will free all
13255 realized faces, which includes the faces referenced from current
13256 matrices. So, we can't reuse current matrices in this case. */
13257 if (face_change_count
)
13258 windows_or_buffers_changed
= 47;
13260 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13261 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13263 /* Since frames on a single ASCII terminal share the same
13264 display area, displaying a different frame means redisplay
13265 the whole thing. */
13266 SET_FRAME_GARBAGED (sf
);
13268 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13270 FRAME_TTY (sf
)->previous_frame
= sf
;
13273 /* Set the visible flags for all frames. Do this before checking for
13274 resized or garbaged frames; they want to know if their frames are
13275 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13276 number_of_visible_frames
= 0;
13278 FOR_EACH_FRAME (tail
, frame
)
13280 struct frame
*f
= XFRAME (frame
);
13282 if (FRAME_VISIBLE_P (f
))
13284 ++number_of_visible_frames
;
13285 /* Adjust matrices for visible frames only. */
13286 if (f
->fonts_changed
)
13288 adjust_frame_glyphs (f
);
13289 f
->fonts_changed
= 0;
13291 /* If cursor type has been changed on the frame
13292 other than selected, consider all frames. */
13293 if (f
!= sf
&& f
->cursor_type_changed
)
13294 update_mode_lines
= 31;
13296 clear_desired_matrices (f
);
13299 /* Notice any pending interrupt request to change frame size. */
13300 do_pending_window_change (1);
13302 /* do_pending_window_change could change the selected_window due to
13303 frame resizing which makes the selected window too small. */
13304 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13307 /* Clear frames marked as garbaged. */
13308 clear_garbaged_frames ();
13310 /* Build menubar and tool-bar items. */
13311 if (NILP (Vmemory_full
))
13312 prepare_menu_bars ();
13314 reconsider_clip_changes (w
);
13316 /* In most cases selected window displays current buffer. */
13317 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13320 /* Detect case that we need to write or remove a star in the mode line. */
13321 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13322 w
->update_mode_line
= 1;
13324 if (mode_line_update_needed (w
))
13325 w
->update_mode_line
= 1;
13328 /* Normally the message* functions will have already displayed and
13329 updated the echo area, but the frame may have been trashed, or
13330 the update may have been preempted, so display the echo area
13331 again here. Checking message_cleared_p captures the case that
13332 the echo area should be cleared. */
13333 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13334 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13335 || (message_cleared_p
13336 && minibuf_level
== 0
13337 /* If the mini-window is currently selected, this means the
13338 echo-area doesn't show through. */
13339 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13341 int window_height_changed_p
= echo_area_display (0);
13343 if (message_cleared_p
)
13344 update_miniwindow_p
= true;
13348 /* If we don't display the current message, don't clear the
13349 message_cleared_p flag, because, if we did, we wouldn't clear
13350 the echo area in the next redisplay which doesn't preserve
13352 if (!display_last_displayed_message_p
)
13353 message_cleared_p
= 0;
13355 if (window_height_changed_p
)
13357 windows_or_buffers_changed
= 50;
13359 /* If window configuration was changed, frames may have been
13360 marked garbaged. Clear them or we will experience
13361 surprises wrt scrolling. */
13362 clear_garbaged_frames ();
13365 else if (EQ (selected_window
, minibuf_window
)
13366 && (current_buffer
->clip_changed
|| window_outdated (w
))
13367 && resize_mini_window (w
, 0))
13369 /* Resized active mini-window to fit the size of what it is
13370 showing if its contents might have changed. */
13373 /* If window configuration was changed, frames may have been
13374 marked garbaged. Clear them or we will experience
13375 surprises wrt scrolling. */
13376 clear_garbaged_frames ();
13379 if (windows_or_buffers_changed
&& !update_mode_lines
)
13380 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13381 only the windows's contents needs to be refreshed, or whether the
13382 mode-lines also need a refresh. */
13383 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13384 ? REDISPLAY_SOME
: 32);
13386 /* If specs for an arrow have changed, do thorough redisplay
13387 to ensure we remove any arrow that should no longer exist. */
13388 if (overlay_arrows_changed_p ())
13389 /* Apparently, this is the only case where we update other windows,
13390 without updating other mode-lines. */
13391 windows_or_buffers_changed
= 49;
13393 consider_all_windows_p
= (update_mode_lines
13394 || windows_or_buffers_changed
);
13396 #define AINC(a,i) \
13397 if (VECTORP (a) && i >= 0 && i < ASIZE (a) && INTEGERP (AREF (a, i))) \
13398 ASET (a, i, make_number (1 + XINT (AREF (a, i))))
13400 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13401 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13403 /* Optimize the case that only the line containing the cursor in the
13404 selected window has changed. Variables starting with this_ are
13405 set in display_line and record information about the line
13406 containing the cursor. */
13407 tlbufpos
= this_line_start_pos
;
13408 tlendpos
= this_line_end_pos
;
13409 if (!consider_all_windows_p
13410 && CHARPOS (tlbufpos
) > 0
13411 && !w
->update_mode_line
13412 && !current_buffer
->clip_changed
13413 && !current_buffer
->prevent_redisplay_optimizations_p
13414 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13415 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13416 && !XFRAME (w
->frame
)->cursor_type_changed
13417 /* Make sure recorded data applies to current buffer, etc. */
13418 && this_line_buffer
== current_buffer
13421 && !w
->optional_new_start
13422 /* Point must be on the line that we have info recorded about. */
13423 && PT
>= CHARPOS (tlbufpos
)
13424 && PT
<= Z
- CHARPOS (tlendpos
)
13425 /* All text outside that line, including its final newline,
13426 must be unchanged. */
13427 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13428 CHARPOS (tlendpos
)))
13430 if (CHARPOS (tlbufpos
) > BEGV
13431 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13432 && (CHARPOS (tlbufpos
) == ZV
13433 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13434 /* Former continuation line has disappeared by becoming empty. */
13436 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13438 /* We have to handle the case of continuation around a
13439 wide-column character (see the comment in indent.c around
13442 For instance, in the following case:
13444 -------- Insert --------
13445 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13446 J_I_ ==> J_I_ `^^' are cursors.
13450 As we have to redraw the line above, we cannot use this
13454 int line_height_before
= this_line_pixel_height
;
13456 /* Note that start_display will handle the case that the
13457 line starting at tlbufpos is a continuation line. */
13458 start_display (&it
, w
, tlbufpos
);
13460 /* Implementation note: It this still necessary? */
13461 if (it
.current_x
!= this_line_start_x
)
13464 TRACE ((stderr
, "trying display optimization 1\n"));
13465 w
->cursor
.vpos
= -1;
13466 overlay_arrow_seen
= 0;
13467 it
.vpos
= this_line_vpos
;
13468 it
.current_y
= this_line_y
;
13469 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13470 display_line (&it
);
13472 /* If line contains point, is not continued,
13473 and ends at same distance from eob as before, we win. */
13474 if (w
->cursor
.vpos
>= 0
13475 /* Line is not continued, otherwise this_line_start_pos
13476 would have been set to 0 in display_line. */
13477 && CHARPOS (this_line_start_pos
)
13478 /* Line ends as before. */
13479 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13480 /* Line has same height as before. Otherwise other lines
13481 would have to be shifted up or down. */
13482 && this_line_pixel_height
== line_height_before
)
13484 /* If this is not the window's last line, we must adjust
13485 the charstarts of the lines below. */
13486 if (it
.current_y
< it
.last_visible_y
)
13488 struct glyph_row
*row
13489 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13490 ptrdiff_t delta
, delta_bytes
;
13492 /* We used to distinguish between two cases here,
13493 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13494 when the line ends in a newline or the end of the
13495 buffer's accessible portion. But both cases did
13496 the same, so they were collapsed. */
13498 - CHARPOS (tlendpos
)
13499 - MATRIX_ROW_START_CHARPOS (row
));
13500 delta_bytes
= (Z_BYTE
13501 - BYTEPOS (tlendpos
)
13502 - MATRIX_ROW_START_BYTEPOS (row
));
13504 increment_matrix_positions (w
->current_matrix
,
13505 this_line_vpos
+ 1,
13506 w
->current_matrix
->nrows
,
13507 delta
, delta_bytes
);
13510 /* If this row displays text now but previously didn't,
13511 or vice versa, w->window_end_vpos may have to be
13513 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13515 if (w
->window_end_vpos
< this_line_vpos
)
13516 w
->window_end_vpos
= this_line_vpos
;
13518 else if (w
->window_end_vpos
== this_line_vpos
13519 && this_line_vpos
> 0)
13520 w
->window_end_vpos
= this_line_vpos
- 1;
13521 w
->window_end_valid
= 0;
13523 /* Update hint: No need to try to scroll in update_window. */
13524 w
->desired_matrix
->no_scrolling_p
= 1;
13527 *w
->desired_matrix
->method
= 0;
13528 debug_method_add (w
, "optimization 1");
13530 #ifdef HAVE_WINDOW_SYSTEM
13531 update_window_fringes (w
, 0);
13538 else if (/* Cursor position hasn't changed. */
13539 PT
== w
->last_point
13540 /* Make sure the cursor was last displayed
13541 in this window. Otherwise we have to reposition it. */
13543 /* PXW: Must be converted to pixels, probably. */
13544 && 0 <= w
->cursor
.vpos
13545 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13549 do_pending_window_change (1);
13550 /* If selected_window changed, redisplay again. */
13551 if (WINDOWP (selected_window
)
13552 && (w
= XWINDOW (selected_window
)) != sw
)
13555 /* We used to always goto end_of_redisplay here, but this
13556 isn't enough if we have a blinking cursor. */
13557 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13558 goto end_of_redisplay
;
13562 /* If highlighting the region, or if the cursor is in the echo area,
13563 then we can't just move the cursor. */
13564 else if (NILP (Vshow_trailing_whitespace
)
13565 && !cursor_in_echo_area
)
13568 struct glyph_row
*row
;
13570 /* Skip from tlbufpos to PT and see where it is. Note that
13571 PT may be in invisible text. If so, we will end at the
13572 next visible position. */
13573 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13574 NULL
, DEFAULT_FACE_ID
);
13575 it
.current_x
= this_line_start_x
;
13576 it
.current_y
= this_line_y
;
13577 it
.vpos
= this_line_vpos
;
13579 /* The call to move_it_to stops in front of PT, but
13580 moves over before-strings. */
13581 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13583 if (it
.vpos
== this_line_vpos
13584 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13587 eassert (this_line_vpos
== it
.vpos
);
13588 eassert (this_line_y
== it
.current_y
);
13589 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13591 *w
->desired_matrix
->method
= 0;
13592 debug_method_add (w
, "optimization 3");
13601 /* Text changed drastically or point moved off of line. */
13602 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13605 CHARPOS (this_line_start_pos
) = 0;
13606 ++clear_face_cache_count
;
13607 #ifdef HAVE_WINDOW_SYSTEM
13608 ++clear_image_cache_count
;
13611 /* Build desired matrices, and update the display. If
13612 consider_all_windows_p is non-zero, do it for all windows on all
13613 frames. Otherwise do it for selected_window, only. */
13615 if (consider_all_windows_p
)
13617 FOR_EACH_FRAME (tail
, frame
)
13618 XFRAME (frame
)->updated_p
= 0;
13620 propagate_buffer_redisplay ();
13622 FOR_EACH_FRAME (tail
, frame
)
13624 struct frame
*f
= XFRAME (frame
);
13626 /* We don't have to do anything for unselected terminal
13628 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13629 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13634 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13637 /* Only GC scrollbars when we redisplay the whole frame. */
13638 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13639 /* Mark all the scroll bars to be removed; we'll redeem
13640 the ones we want when we redisplay their windows. */
13641 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13642 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13644 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13645 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13646 /* Remember that the invisible frames need to be redisplayed next
13647 time they're visible. */
13648 else if (!REDISPLAY_SOME_P ())
13649 f
->redisplay
= true;
13651 /* The X error handler may have deleted that frame. */
13652 if (!FRAME_LIVE_P (f
))
13655 /* Any scroll bars which redisplay_windows should have
13656 nuked should now go away. */
13657 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13658 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13660 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13662 /* If fonts changed on visible frame, display again. */
13663 if (f
->fonts_changed
)
13665 adjust_frame_glyphs (f
);
13666 f
->fonts_changed
= 0;
13670 /* See if we have to hscroll. */
13671 if (!f
->already_hscrolled_p
)
13673 f
->already_hscrolled_p
= 1;
13674 if (hscroll_windows (f
->root_window
))
13678 /* Prevent various kinds of signals during display
13679 update. stdio is not robust about handling
13680 signals, which can cause an apparent I/O error. */
13681 if (interrupt_input
)
13682 unrequest_sigio ();
13685 pending
|= update_frame (f
, 0, 0);
13686 f
->cursor_type_changed
= 0;
13692 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13696 /* Do the mark_window_display_accurate after all windows have
13697 been redisplayed because this call resets flags in buffers
13698 which are needed for proper redisplay. */
13699 FOR_EACH_FRAME (tail
, frame
)
13701 struct frame
*f
= XFRAME (frame
);
13704 f
->redisplay
= false;
13705 mark_window_display_accurate (f
->root_window
, 1);
13706 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13707 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13712 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13714 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13715 struct frame
*mini_frame
;
13717 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13718 /* Use list_of_error, not Qerror, so that
13719 we catch only errors and don't run the debugger. */
13720 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13722 redisplay_window_error
);
13723 if (update_miniwindow_p
)
13724 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13726 redisplay_window_error
);
13728 /* Compare desired and current matrices, perform output. */
13731 /* If fonts changed, display again. */
13732 if (sf
->fonts_changed
)
13735 /* Prevent various kinds of signals during display update.
13736 stdio is not robust about handling signals,
13737 which can cause an apparent I/O error. */
13738 if (interrupt_input
)
13739 unrequest_sigio ();
13742 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13744 if (hscroll_windows (selected_window
))
13747 XWINDOW (selected_window
)->must_be_updated_p
= true;
13748 pending
= update_frame (sf
, 0, 0);
13749 sf
->cursor_type_changed
= 0;
13752 /* We may have called echo_area_display at the top of this
13753 function. If the echo area is on another frame, that may
13754 have put text on a frame other than the selected one, so the
13755 above call to update_frame would not have caught it. Catch
13757 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13758 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13760 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13762 XWINDOW (mini_window
)->must_be_updated_p
= true;
13763 pending
|= update_frame (mini_frame
, 0, 0);
13764 mini_frame
->cursor_type_changed
= 0;
13765 if (!pending
&& hscroll_windows (mini_window
))
13770 /* If display was paused because of pending input, make sure we do a
13771 thorough update the next time. */
13774 /* Prevent the optimization at the beginning of
13775 redisplay_internal that tries a single-line update of the
13776 line containing the cursor in the selected window. */
13777 CHARPOS (this_line_start_pos
) = 0;
13779 /* Let the overlay arrow be updated the next time. */
13780 update_overlay_arrows (0);
13782 /* If we pause after scrolling, some rows in the current
13783 matrices of some windows are not valid. */
13784 if (!WINDOW_FULL_WIDTH_P (w
)
13785 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13786 update_mode_lines
= 36;
13790 if (!consider_all_windows_p
)
13792 /* This has already been done above if
13793 consider_all_windows_p is set. */
13794 if (XBUFFER (w
->contents
)->text
->redisplay
13795 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
13796 /* This can happen if b->text->redisplay was set during
13798 propagate_buffer_redisplay ();
13799 mark_window_display_accurate_1 (w
, 1);
13801 /* Say overlay arrows are up to date. */
13802 update_overlay_arrows (1);
13804 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13805 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13808 update_mode_lines
= 0;
13809 windows_or_buffers_changed
= 0;
13812 /* Start SIGIO interrupts coming again. Having them off during the
13813 code above makes it less likely one will discard output, but not
13814 impossible, since there might be stuff in the system buffer here.
13815 But it is much hairier to try to do anything about that. */
13816 if (interrupt_input
)
13820 /* If a frame has become visible which was not before, redisplay
13821 again, so that we display it. Expose events for such a frame
13822 (which it gets when becoming visible) don't call the parts of
13823 redisplay constructing glyphs, so simply exposing a frame won't
13824 display anything in this case. So, we have to display these
13825 frames here explicitly. */
13830 FOR_EACH_FRAME (tail
, frame
)
13832 if (XFRAME (frame
)->visible
)
13836 if (new_count
!= number_of_visible_frames
)
13837 windows_or_buffers_changed
= 52;
13840 /* Change frame size now if a change is pending. */
13841 do_pending_window_change (1);
13843 /* If we just did a pending size change, or have additional
13844 visible frames, or selected_window changed, redisplay again. */
13845 if ((windows_or_buffers_changed
&& !pending
)
13846 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13849 /* Clear the face and image caches.
13851 We used to do this only if consider_all_windows_p. But the cache
13852 needs to be cleared if a timer creates images in the current
13853 buffer (e.g. the test case in Bug#6230). */
13855 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13857 clear_face_cache (0);
13858 clear_face_cache_count
= 0;
13861 #ifdef HAVE_WINDOW_SYSTEM
13862 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13864 clear_image_caches (Qnil
);
13865 clear_image_cache_count
= 0;
13867 #endif /* HAVE_WINDOW_SYSTEM */
13870 if (interrupt_input
&& interrupts_deferred
)
13873 unbind_to (count
, Qnil
);
13878 /* Redisplay, but leave alone any recent echo area message unless
13879 another message has been requested in its place.
13881 This is useful in situations where you need to redisplay but no
13882 user action has occurred, making it inappropriate for the message
13883 area to be cleared. See tracking_off and
13884 wait_reading_process_output for examples of these situations.
13886 FROM_WHERE is an integer saying from where this function was
13887 called. This is useful for debugging. */
13890 redisplay_preserve_echo_area (int from_where
)
13892 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13894 if (!NILP (echo_area_buffer
[1]))
13896 /* We have a previously displayed message, but no current
13897 message. Redisplay the previous message. */
13898 display_last_displayed_message_p
= 1;
13899 redisplay_internal ();
13900 display_last_displayed_message_p
= 0;
13903 redisplay_internal ();
13905 flush_frame (SELECTED_FRAME ());
13909 /* Function registered with record_unwind_protect in redisplay_internal. */
13912 unwind_redisplay (void)
13914 redisplaying_p
= 0;
13918 /* Mark the display of leaf window W as accurate or inaccurate.
13919 If ACCURATE_P is non-zero mark display of W as accurate. If
13920 ACCURATE_P is zero, arrange for W to be redisplayed the next
13921 time redisplay_internal is called. */
13924 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13926 struct buffer
*b
= XBUFFER (w
->contents
);
13928 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13929 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13930 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13934 b
->clip_changed
= false;
13935 b
->prevent_redisplay_optimizations_p
= false;
13936 eassert (buffer_window_count (b
) > 0);
13937 /* Resetting b->text->redisplay is problematic!
13938 In order to make it safer to do it here, redisplay_internal must
13939 have copied all b->text->redisplay to their respective windows. */
13940 b
->text
->redisplay
= false;
13942 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13943 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13944 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13945 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13947 w
->current_matrix
->buffer
= b
;
13948 w
->current_matrix
->begv
= BUF_BEGV (b
);
13949 w
->current_matrix
->zv
= BUF_ZV (b
);
13951 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13952 w
->last_cursor_off_p
= w
->cursor_off_p
;
13954 if (w
== XWINDOW (selected_window
))
13955 w
->last_point
= BUF_PT (b
);
13957 w
->last_point
= marker_position (w
->pointm
);
13959 w
->window_end_valid
= true;
13960 w
->update_mode_line
= false;
13963 w
->redisplay
= !accurate_p
;
13967 /* Mark the display of windows in the window tree rooted at WINDOW as
13968 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13969 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13970 be redisplayed the next time redisplay_internal is called. */
13973 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13977 for (; !NILP (window
); window
= w
->next
)
13979 w
= XWINDOW (window
);
13980 if (WINDOWP (w
->contents
))
13981 mark_window_display_accurate (w
->contents
, accurate_p
);
13983 mark_window_display_accurate_1 (w
, accurate_p
);
13987 update_overlay_arrows (1);
13989 /* Force a thorough redisplay the next time by setting
13990 last_arrow_position and last_arrow_string to t, which is
13991 unequal to any useful value of Voverlay_arrow_... */
13992 update_overlay_arrows (-1);
13996 /* Return value in display table DP (Lisp_Char_Table *) for character
13997 C. Since a display table doesn't have any parent, we don't have to
13998 follow parent. Do not call this function directly but use the
13999 macro DISP_CHAR_VECTOR. */
14002 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
14006 if (ASCII_CHAR_P (c
))
14009 if (SUB_CHAR_TABLE_P (val
))
14010 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
14016 XSETCHAR_TABLE (table
, dp
);
14017 val
= char_table_ref (table
, c
);
14026 /***********************************************************************
14028 ***********************************************************************/
14030 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
14033 redisplay_windows (Lisp_Object window
)
14035 while (!NILP (window
))
14037 struct window
*w
= XWINDOW (window
);
14039 if (WINDOWP (w
->contents
))
14040 redisplay_windows (w
->contents
);
14041 else if (BUFFERP (w
->contents
))
14043 displayed_buffer
= XBUFFER (w
->contents
);
14044 /* Use list_of_error, not Qerror, so that
14045 we catch only errors and don't run the debugger. */
14046 internal_condition_case_1 (redisplay_window_0
, window
,
14048 redisplay_window_error
);
14056 redisplay_window_error (Lisp_Object ignore
)
14058 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14063 redisplay_window_0 (Lisp_Object window
)
14065 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14066 redisplay_window (window
, false);
14071 redisplay_window_1 (Lisp_Object window
)
14073 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14074 redisplay_window (window
, true);
14079 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14080 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14081 which positions recorded in ROW differ from current buffer
14084 Return 0 if cursor is not on this row, 1 otherwise. */
14087 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14088 struct glyph_matrix
*matrix
,
14089 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14092 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14093 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14094 struct glyph
*cursor
= NULL
;
14095 /* The last known character position in row. */
14096 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14098 ptrdiff_t pt_old
= PT
- delta
;
14099 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14100 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14101 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14102 /* A glyph beyond the edge of TEXT_AREA which we should never
14104 struct glyph
*glyphs_end
= end
;
14105 /* Non-zero means we've found a match for cursor position, but that
14106 glyph has the avoid_cursor_p flag set. */
14107 int match_with_avoid_cursor
= 0;
14108 /* Non-zero means we've seen at least one glyph that came from a
14110 int string_seen
= 0;
14111 /* Largest and smallest buffer positions seen so far during scan of
14113 ptrdiff_t bpos_max
= pos_before
;
14114 ptrdiff_t bpos_min
= pos_after
;
14115 /* Last buffer position covered by an overlay string with an integer
14116 `cursor' property. */
14117 ptrdiff_t bpos_covered
= 0;
14118 /* Non-zero means the display string on which to display the cursor
14119 comes from a text property, not from an overlay. */
14120 int string_from_text_prop
= 0;
14122 /* Don't even try doing anything if called for a mode-line or
14123 header-line row, since the rest of the code isn't prepared to
14124 deal with such calamities. */
14125 eassert (!row
->mode_line_p
);
14126 if (row
->mode_line_p
)
14129 /* Skip over glyphs not having an object at the start and the end of
14130 the row. These are special glyphs like truncation marks on
14131 terminal frames. */
14132 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14134 if (!row
->reversed_p
)
14137 && INTEGERP (glyph
->object
)
14138 && glyph
->charpos
< 0)
14140 x
+= glyph
->pixel_width
;
14144 && INTEGERP ((end
- 1)->object
)
14145 /* CHARPOS is zero for blanks and stretch glyphs
14146 inserted by extend_face_to_end_of_line. */
14147 && (end
- 1)->charpos
<= 0)
14149 glyph_before
= glyph
- 1;
14156 /* If the glyph row is reversed, we need to process it from back
14157 to front, so swap the edge pointers. */
14158 glyphs_end
= end
= glyph
- 1;
14159 glyph
+= row
->used
[TEXT_AREA
] - 1;
14161 while (glyph
> end
+ 1
14162 && INTEGERP (glyph
->object
)
14163 && glyph
->charpos
< 0)
14166 x
-= glyph
->pixel_width
;
14168 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14170 /* By default, in reversed rows we put the cursor on the
14171 rightmost (first in the reading order) glyph. */
14172 for (g
= end
+ 1; g
< glyph
; g
++)
14173 x
+= g
->pixel_width
;
14175 && INTEGERP ((end
+ 1)->object
)
14176 && (end
+ 1)->charpos
<= 0)
14178 glyph_before
= glyph
+ 1;
14182 else if (row
->reversed_p
)
14184 /* In R2L rows that don't display text, put the cursor on the
14185 rightmost glyph. Case in point: an empty last line that is
14186 part of an R2L paragraph. */
14188 /* Avoid placing the cursor on the last glyph of the row, where
14189 on terminal frames we hold the vertical border between
14190 adjacent windows. */
14191 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14192 && !WINDOW_RIGHTMOST_P (w
)
14193 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14195 x
= -1; /* will be computed below, at label compute_x */
14198 /* Step 1: Try to find the glyph whose character position
14199 corresponds to point. If that's not possible, find 2 glyphs
14200 whose character positions are the closest to point, one before
14201 point, the other after it. */
14202 if (!row
->reversed_p
)
14203 while (/* not marched to end of glyph row */
14205 /* glyph was not inserted by redisplay for internal purposes */
14206 && !INTEGERP (glyph
->object
))
14208 if (BUFFERP (glyph
->object
))
14210 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14212 if (glyph
->charpos
> bpos_max
)
14213 bpos_max
= glyph
->charpos
;
14214 if (glyph
->charpos
< bpos_min
)
14215 bpos_min
= glyph
->charpos
;
14216 if (!glyph
->avoid_cursor_p
)
14218 /* If we hit point, we've found the glyph on which to
14219 display the cursor. */
14222 match_with_avoid_cursor
= 0;
14225 /* See if we've found a better approximation to
14226 POS_BEFORE or to POS_AFTER. */
14227 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14229 pos_before
= glyph
->charpos
;
14230 glyph_before
= glyph
;
14232 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14234 pos_after
= glyph
->charpos
;
14235 glyph_after
= glyph
;
14238 else if (dpos
== 0)
14239 match_with_avoid_cursor
= 1;
14241 else if (STRINGP (glyph
->object
))
14243 Lisp_Object chprop
;
14244 ptrdiff_t glyph_pos
= glyph
->charpos
;
14246 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14248 if (!NILP (chprop
))
14250 /* If the string came from a `display' text property,
14251 look up the buffer position of that property and
14252 use that position to update bpos_max, as if we
14253 actually saw such a position in one of the row's
14254 glyphs. This helps with supporting integer values
14255 of `cursor' property on the display string in
14256 situations where most or all of the row's buffer
14257 text is completely covered by display properties,
14258 so that no glyph with valid buffer positions is
14259 ever seen in the row. */
14260 ptrdiff_t prop_pos
=
14261 string_buffer_position_lim (glyph
->object
, pos_before
,
14264 if (prop_pos
>= pos_before
)
14265 bpos_max
= prop_pos
- 1;
14267 if (INTEGERP (chprop
))
14269 bpos_covered
= bpos_max
+ XINT (chprop
);
14270 /* If the `cursor' property covers buffer positions up
14271 to and including point, we should display cursor on
14272 this glyph. Note that, if a `cursor' property on one
14273 of the string's characters has an integer value, we
14274 will break out of the loop below _before_ we get to
14275 the position match above. IOW, integer values of
14276 the `cursor' property override the "exact match for
14277 point" strategy of positioning the cursor. */
14278 /* Implementation note: bpos_max == pt_old when, e.g.,
14279 we are in an empty line, where bpos_max is set to
14280 MATRIX_ROW_START_CHARPOS, see above. */
14281 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14290 x
+= glyph
->pixel_width
;
14293 else if (glyph
> end
) /* row is reversed */
14294 while (!INTEGERP (glyph
->object
))
14296 if (BUFFERP (glyph
->object
))
14298 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14300 if (glyph
->charpos
> bpos_max
)
14301 bpos_max
= glyph
->charpos
;
14302 if (glyph
->charpos
< bpos_min
)
14303 bpos_min
= glyph
->charpos
;
14304 if (!glyph
->avoid_cursor_p
)
14308 match_with_avoid_cursor
= 0;
14311 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14313 pos_before
= glyph
->charpos
;
14314 glyph_before
= glyph
;
14316 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14318 pos_after
= glyph
->charpos
;
14319 glyph_after
= glyph
;
14322 else if (dpos
== 0)
14323 match_with_avoid_cursor
= 1;
14325 else if (STRINGP (glyph
->object
))
14327 Lisp_Object chprop
;
14328 ptrdiff_t glyph_pos
= glyph
->charpos
;
14330 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14332 if (!NILP (chprop
))
14334 ptrdiff_t prop_pos
=
14335 string_buffer_position_lim (glyph
->object
, pos_before
,
14338 if (prop_pos
>= pos_before
)
14339 bpos_max
= prop_pos
- 1;
14341 if (INTEGERP (chprop
))
14343 bpos_covered
= bpos_max
+ XINT (chprop
);
14344 /* If the `cursor' property covers buffer positions up
14345 to and including point, we should display cursor on
14347 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14356 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14358 x
--; /* can't use any pixel_width */
14361 x
-= glyph
->pixel_width
;
14364 /* Step 2: If we didn't find an exact match for point, we need to
14365 look for a proper place to put the cursor among glyphs between
14366 GLYPH_BEFORE and GLYPH_AFTER. */
14367 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14368 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14369 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14371 /* An empty line has a single glyph whose OBJECT is zero and
14372 whose CHARPOS is the position of a newline on that line.
14373 Note that on a TTY, there are more glyphs after that, which
14374 were produced by extend_face_to_end_of_line, but their
14375 CHARPOS is zero or negative. */
14377 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14378 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14379 /* On a TTY, continued and truncated rows also have a glyph at
14380 their end whose OBJECT is zero and whose CHARPOS is
14381 positive (the continuation and truncation glyphs), but such
14382 rows are obviously not "empty". */
14383 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14385 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14387 ptrdiff_t ellipsis_pos
;
14389 /* Scan back over the ellipsis glyphs. */
14390 if (!row
->reversed_p
)
14392 ellipsis_pos
= (glyph
- 1)->charpos
;
14393 while (glyph
> row
->glyphs
[TEXT_AREA
]
14394 && (glyph
- 1)->charpos
== ellipsis_pos
)
14395 glyph
--, x
-= glyph
->pixel_width
;
14396 /* That loop always goes one position too far, including
14397 the glyph before the ellipsis. So scan forward over
14399 x
+= glyph
->pixel_width
;
14402 else /* row is reversed */
14404 ellipsis_pos
= (glyph
+ 1)->charpos
;
14405 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14406 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14407 glyph
++, x
+= glyph
->pixel_width
;
14408 x
-= glyph
->pixel_width
;
14412 else if (match_with_avoid_cursor
)
14414 cursor
= glyph_after
;
14417 else if (string_seen
)
14419 int incr
= row
->reversed_p
? -1 : +1;
14421 /* Need to find the glyph that came out of a string which is
14422 present at point. That glyph is somewhere between
14423 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14424 positioned between POS_BEFORE and POS_AFTER in the
14426 struct glyph
*start
, *stop
;
14427 ptrdiff_t pos
= pos_before
;
14431 /* If the row ends in a newline from a display string,
14432 reordering could have moved the glyphs belonging to the
14433 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14434 in this case we extend the search to the last glyph in
14435 the row that was not inserted by redisplay. */
14436 if (row
->ends_in_newline_from_string_p
)
14439 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14442 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14443 correspond to POS_BEFORE and POS_AFTER, respectively. We
14444 need START and STOP in the order that corresponds to the
14445 row's direction as given by its reversed_p flag. If the
14446 directionality of characters between POS_BEFORE and
14447 POS_AFTER is the opposite of the row's base direction,
14448 these characters will have been reordered for display,
14449 and we need to reverse START and STOP. */
14450 if (!row
->reversed_p
)
14452 start
= min (glyph_before
, glyph_after
);
14453 stop
= max (glyph_before
, glyph_after
);
14457 start
= max (glyph_before
, glyph_after
);
14458 stop
= min (glyph_before
, glyph_after
);
14460 for (glyph
= start
+ incr
;
14461 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14464 /* Any glyphs that come from the buffer are here because
14465 of bidi reordering. Skip them, and only pay
14466 attention to glyphs that came from some string. */
14467 if (STRINGP (glyph
->object
))
14471 /* If the display property covers the newline, we
14472 need to search for it one position farther. */
14473 ptrdiff_t lim
= pos_after
14474 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14476 string_from_text_prop
= 0;
14477 str
= glyph
->object
;
14478 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14479 if (tem
== 0 /* from overlay */
14482 /* If the string from which this glyph came is
14483 found in the buffer at point, or at position
14484 that is closer to point than pos_after, then
14485 we've found the glyph we've been looking for.
14486 If it comes from an overlay (tem == 0), and
14487 it has the `cursor' property on one of its
14488 glyphs, record that glyph as a candidate for
14489 displaying the cursor. (As in the
14490 unidirectional version, we will display the
14491 cursor on the last candidate we find.) */
14494 || (tem
- pt_old
> 0 && tem
< pos_after
))
14496 /* The glyphs from this string could have
14497 been reordered. Find the one with the
14498 smallest string position. Or there could
14499 be a character in the string with the
14500 `cursor' property, which means display
14501 cursor on that character's glyph. */
14502 ptrdiff_t strpos
= glyph
->charpos
;
14507 string_from_text_prop
= 1;
14510 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14511 && EQ (glyph
->object
, str
);
14515 ptrdiff_t gpos
= glyph
->charpos
;
14517 cprop
= Fget_char_property (make_number (gpos
),
14525 if (tem
&& glyph
->charpos
< strpos
)
14527 strpos
= glyph
->charpos
;
14533 || (tem
- pt_old
> 0 && tem
< pos_after
))
14537 pos
= tem
+ 1; /* don't find previous instances */
14539 /* This string is not what we want; skip all of the
14540 glyphs that came from it. */
14541 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14542 && EQ (glyph
->object
, str
))
14549 /* If we reached the end of the line, and END was from a string,
14550 the cursor is not on this line. */
14552 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14553 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14554 && STRINGP (end
->object
)
14555 && row
->continued_p
)
14558 /* A truncated row may not include PT among its character positions.
14559 Setting the cursor inside the scroll margin will trigger
14560 recalculation of hscroll in hscroll_window_tree. But if a
14561 display string covers point, defer to the string-handling
14562 code below to figure this out. */
14563 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14565 cursor
= glyph_before
;
14568 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14569 /* Zero-width characters produce no glyphs. */
14571 && (row
->reversed_p
14572 ? glyph_after
> glyphs_end
14573 : glyph_after
< glyphs_end
)))
14575 cursor
= glyph_after
;
14581 if (cursor
!= NULL
)
14583 else if (glyph
== glyphs_end
14584 && pos_before
== pos_after
14585 && STRINGP ((row
->reversed_p
14586 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14587 : row
->glyphs
[TEXT_AREA
])->object
))
14589 /* If all the glyphs of this row came from strings, put the
14590 cursor on the first glyph of the row. This avoids having the
14591 cursor outside of the text area in this very rare and hard
14595 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14596 : row
->glyphs
[TEXT_AREA
];
14602 /* Need to compute x that corresponds to GLYPH. */
14603 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14605 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14607 x
+= g
->pixel_width
;
14611 /* ROW could be part of a continued line, which, under bidi
14612 reordering, might have other rows whose start and end charpos
14613 occlude point. Only set w->cursor if we found a better
14614 approximation to the cursor position than we have from previously
14615 examined candidate rows belonging to the same continued line. */
14616 if (/* We already have a candidate row. */
14617 w
->cursor
.vpos
>= 0
14618 /* That candidate is not the row we are processing. */
14619 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14620 /* Make sure cursor.vpos specifies a row whose start and end
14621 charpos occlude point, and it is valid candidate for being a
14622 cursor-row. This is because some callers of this function
14623 leave cursor.vpos at the row where the cursor was displayed
14624 during the last redisplay cycle. */
14625 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14626 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14627 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14630 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14632 /* Don't consider glyphs that are outside TEXT_AREA. */
14633 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14635 /* Keep the candidate whose buffer position is the closest to
14636 point or has the `cursor' property. */
14637 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14638 w
->cursor
.hpos
>= 0
14639 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14640 && ((BUFFERP (g1
->object
)
14641 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14642 || (BUFFERP (glyph
->object
)
14643 && eabs (g1
->charpos
- pt_old
)
14644 < eabs (glyph
->charpos
- pt_old
))))
14645 /* Previous candidate is a glyph from a string that has
14646 a non-nil `cursor' property. */
14647 || (STRINGP (g1
->object
)
14648 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14649 Qcursor
, g1
->object
))
14650 /* Previous candidate is from the same display
14651 string as this one, and the display string
14652 came from a text property. */
14653 || (EQ (g1
->object
, glyph
->object
)
14654 && string_from_text_prop
)
14655 /* this candidate is from newline and its
14656 position is not an exact match */
14657 || (INTEGERP (glyph
->object
)
14658 && glyph
->charpos
!= pt_old
)))))
14660 /* If this candidate gives an exact match, use that. */
14661 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14662 /* If this candidate is a glyph created for the
14663 terminating newline of a line, and point is on that
14664 newline, it wins because it's an exact match. */
14665 || (!row
->continued_p
14666 && INTEGERP (glyph
->object
)
14667 && glyph
->charpos
== 0
14668 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14669 /* Otherwise, keep the candidate that comes from a row
14670 spanning less buffer positions. This may win when one or
14671 both candidate positions are on glyphs that came from
14672 display strings, for which we cannot compare buffer
14674 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14675 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14676 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14679 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14681 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14682 w
->cursor
.y
= row
->y
+ dy
;
14684 if (w
== XWINDOW (selected_window
))
14686 if (!row
->continued_p
14687 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14690 this_line_buffer
= XBUFFER (w
->contents
);
14692 CHARPOS (this_line_start_pos
)
14693 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14694 BYTEPOS (this_line_start_pos
)
14695 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14697 CHARPOS (this_line_end_pos
)
14698 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14699 BYTEPOS (this_line_end_pos
)
14700 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14702 this_line_y
= w
->cursor
.y
;
14703 this_line_pixel_height
= row
->height
;
14704 this_line_vpos
= w
->cursor
.vpos
;
14705 this_line_start_x
= row
->x
;
14708 CHARPOS (this_line_start_pos
) = 0;
14715 /* Run window scroll functions, if any, for WINDOW with new window
14716 start STARTP. Sets the window start of WINDOW to that position.
14718 We assume that the window's buffer is really current. */
14720 static struct text_pos
14721 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14723 struct window
*w
= XWINDOW (window
);
14724 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14726 eassert (current_buffer
== XBUFFER (w
->contents
));
14728 if (!NILP (Vwindow_scroll_functions
))
14730 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14731 make_number (CHARPOS (startp
)));
14732 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14733 /* In case the hook functions switch buffers. */
14734 set_buffer_internal (XBUFFER (w
->contents
));
14741 /* Make sure the line containing the cursor is fully visible.
14742 A value of 1 means there is nothing to be done.
14743 (Either the line is fully visible, or it cannot be made so,
14744 or we cannot tell.)
14746 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14747 is higher than window.
14749 A value of 0 means the caller should do scrolling
14750 as if point had gone off the screen. */
14753 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14755 struct glyph_matrix
*matrix
;
14756 struct glyph_row
*row
;
14759 if (!make_cursor_line_fully_visible_p
)
14762 /* It's not always possible to find the cursor, e.g, when a window
14763 is full of overlay strings. Don't do anything in that case. */
14764 if (w
->cursor
.vpos
< 0)
14767 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14768 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14770 /* If the cursor row is not partially visible, there's nothing to do. */
14771 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14774 /* If the row the cursor is in is taller than the window's height,
14775 it's not clear what to do, so do nothing. */
14776 window_height
= window_box_height (w
);
14777 if (row
->height
>= window_height
)
14779 if (!force_p
|| MINI_WINDOW_P (w
)
14780 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14787 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14788 non-zero means only WINDOW is redisplayed in redisplay_internal.
14789 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14790 in redisplay_window to bring a partially visible line into view in
14791 the case that only the cursor has moved.
14793 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14794 last screen line's vertical height extends past the end of the screen.
14798 1 if scrolling succeeded
14800 0 if scrolling didn't find point.
14802 -1 if new fonts have been loaded so that we must interrupt
14803 redisplay, adjust glyph matrices, and try again. */
14809 SCROLLING_NEED_LARGER_MATRICES
14812 /* If scroll-conservatively is more than this, never recenter.
14814 If you change this, don't forget to update the doc string of
14815 `scroll-conservatively' and the Emacs manual. */
14816 #define SCROLL_LIMIT 100
14819 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14820 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14821 int temp_scroll_step
, int last_line_misfit
)
14823 struct window
*w
= XWINDOW (window
);
14824 struct frame
*f
= XFRAME (w
->frame
);
14825 struct text_pos pos
, startp
;
14827 int this_scroll_margin
, scroll_max
, rc
, height
;
14828 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14829 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14830 Lisp_Object aggressive
;
14831 /* We will never try scrolling more than this number of lines. */
14832 int scroll_limit
= SCROLL_LIMIT
;
14833 int frame_line_height
= default_line_pixel_height (w
);
14834 int window_total_lines
14835 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14838 debug_method_add (w
, "try_scrolling");
14841 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14843 /* Compute scroll margin height in pixels. We scroll when point is
14844 within this distance from the top or bottom of the window. */
14845 if (scroll_margin
> 0)
14846 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14847 * frame_line_height
;
14849 this_scroll_margin
= 0;
14851 /* Force arg_scroll_conservatively to have a reasonable value, to
14852 avoid scrolling too far away with slow move_it_* functions. Note
14853 that the user can supply scroll-conservatively equal to
14854 `most-positive-fixnum', which can be larger than INT_MAX. */
14855 if (arg_scroll_conservatively
> scroll_limit
)
14857 arg_scroll_conservatively
= scroll_limit
+ 1;
14858 scroll_max
= scroll_limit
* frame_line_height
;
14860 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14861 /* Compute how much we should try to scroll maximally to bring
14862 point into view. */
14863 scroll_max
= (max (scroll_step
,
14864 max (arg_scroll_conservatively
, temp_scroll_step
))
14865 * frame_line_height
);
14866 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14867 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14868 /* We're trying to scroll because of aggressive scrolling but no
14869 scroll_step is set. Choose an arbitrary one. */
14870 scroll_max
= 10 * frame_line_height
;
14876 /* Decide whether to scroll down. */
14877 if (PT
> CHARPOS (startp
))
14879 int scroll_margin_y
;
14881 /* Compute the pixel ypos of the scroll margin, then move IT to
14882 either that ypos or PT, whichever comes first. */
14883 start_display (&it
, w
, startp
);
14884 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14885 - frame_line_height
* extra_scroll_margin_lines
;
14886 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14887 (MOVE_TO_POS
| MOVE_TO_Y
));
14889 if (PT
> CHARPOS (it
.current
.pos
))
14891 int y0
= line_bottom_y (&it
);
14892 /* Compute how many pixels below window bottom to stop searching
14893 for PT. This avoids costly search for PT that is far away if
14894 the user limited scrolling by a small number of lines, but
14895 always finds PT if scroll_conservatively is set to a large
14896 number, such as most-positive-fixnum. */
14897 int slack
= max (scroll_max
, 10 * frame_line_height
);
14898 int y_to_move
= it
.last_visible_y
+ slack
;
14900 /* Compute the distance from the scroll margin to PT or to
14901 the scroll limit, whichever comes first. This should
14902 include the height of the cursor line, to make that line
14904 move_it_to (&it
, PT
, -1, y_to_move
,
14905 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14906 dy
= line_bottom_y (&it
) - y0
;
14908 if (dy
> scroll_max
)
14909 return SCROLLING_FAILED
;
14918 /* Point is in or below the bottom scroll margin, so move the
14919 window start down. If scrolling conservatively, move it just
14920 enough down to make point visible. If scroll_step is set,
14921 move it down by scroll_step. */
14922 if (arg_scroll_conservatively
)
14924 = min (max (dy
, frame_line_height
),
14925 frame_line_height
* arg_scroll_conservatively
);
14926 else if (scroll_step
|| temp_scroll_step
)
14927 amount_to_scroll
= scroll_max
;
14930 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14931 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14932 if (NUMBERP (aggressive
))
14934 double float_amount
= XFLOATINT (aggressive
) * height
;
14935 int aggressive_scroll
= float_amount
;
14936 if (aggressive_scroll
== 0 && float_amount
> 0)
14937 aggressive_scroll
= 1;
14938 /* Don't let point enter the scroll margin near top of
14939 the window. This could happen if the value of
14940 scroll_up_aggressively is too large and there are
14941 non-zero margins, because scroll_up_aggressively
14942 means put point that fraction of window height
14943 _from_the_bottom_margin_. */
14944 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14945 aggressive_scroll
= height
- 2*this_scroll_margin
;
14946 amount_to_scroll
= dy
+ aggressive_scroll
;
14950 if (amount_to_scroll
<= 0)
14951 return SCROLLING_FAILED
;
14953 start_display (&it
, w
, startp
);
14954 if (arg_scroll_conservatively
<= scroll_limit
)
14955 move_it_vertically (&it
, amount_to_scroll
);
14958 /* Extra precision for users who set scroll-conservatively
14959 to a large number: make sure the amount we scroll
14960 the window start is never less than amount_to_scroll,
14961 which was computed as distance from window bottom to
14962 point. This matters when lines at window top and lines
14963 below window bottom have different height. */
14965 void *it1data
= NULL
;
14966 /* We use a temporary it1 because line_bottom_y can modify
14967 its argument, if it moves one line down; see there. */
14970 SAVE_IT (it1
, it
, it1data
);
14971 start_y
= line_bottom_y (&it1
);
14973 RESTORE_IT (&it
, &it
, it1data
);
14974 move_it_by_lines (&it
, 1);
14975 SAVE_IT (it1
, it
, it1data
);
14976 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14979 /* If STARTP is unchanged, move it down another screen line. */
14980 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14981 move_it_by_lines (&it
, 1);
14982 startp
= it
.current
.pos
;
14986 struct text_pos scroll_margin_pos
= startp
;
14989 /* See if point is inside the scroll margin at the top of the
14991 if (this_scroll_margin
)
14995 start_display (&it
, w
, startp
);
14996 y_start
= it
.current_y
;
14997 move_it_vertically (&it
, this_scroll_margin
);
14998 scroll_margin_pos
= it
.current
.pos
;
14999 /* If we didn't move enough before hitting ZV, request
15000 additional amount of scroll, to move point out of the
15002 if (IT_CHARPOS (it
) == ZV
15003 && it
.current_y
- y_start
< this_scroll_margin
)
15004 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
15007 if (PT
< CHARPOS (scroll_margin_pos
))
15009 /* Point is in the scroll margin at the top of the window or
15010 above what is displayed in the window. */
15013 /* Compute the vertical distance from PT to the scroll
15014 margin position. Move as far as scroll_max allows, or
15015 one screenful, or 10 screen lines, whichever is largest.
15016 Give up if distance is greater than scroll_max or if we
15017 didn't reach the scroll margin position. */
15018 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
15019 start_display (&it
, w
, pos
);
15021 y_to_move
= max (it
.last_visible_y
,
15022 max (scroll_max
, 10 * frame_line_height
));
15023 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
15025 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15026 dy
= it
.current_y
- y0
;
15027 if (dy
> scroll_max
15028 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
15029 return SCROLLING_FAILED
;
15031 /* Additional scroll for when ZV was too close to point. */
15034 /* Compute new window start. */
15035 start_display (&it
, w
, startp
);
15037 if (arg_scroll_conservatively
)
15038 amount_to_scroll
= max (dy
, frame_line_height
*
15039 max (scroll_step
, temp_scroll_step
));
15040 else if (scroll_step
|| temp_scroll_step
)
15041 amount_to_scroll
= scroll_max
;
15044 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15045 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15046 if (NUMBERP (aggressive
))
15048 double float_amount
= XFLOATINT (aggressive
) * height
;
15049 int aggressive_scroll
= float_amount
;
15050 if (aggressive_scroll
== 0 && float_amount
> 0)
15051 aggressive_scroll
= 1;
15052 /* Don't let point enter the scroll margin near
15053 bottom of the window, if the value of
15054 scroll_down_aggressively happens to be too
15056 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
15057 aggressive_scroll
= height
- 2*this_scroll_margin
;
15058 amount_to_scroll
= dy
+ aggressive_scroll
;
15062 if (amount_to_scroll
<= 0)
15063 return SCROLLING_FAILED
;
15065 move_it_vertically_backward (&it
, amount_to_scroll
);
15066 startp
= it
.current
.pos
;
15070 /* Run window scroll functions. */
15071 startp
= run_window_scroll_functions (window
, startp
);
15073 /* Display the window. Give up if new fonts are loaded, or if point
15075 if (!try_window (window
, startp
, 0))
15076 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15077 else if (w
->cursor
.vpos
< 0)
15079 clear_glyph_matrix (w
->desired_matrix
);
15080 rc
= SCROLLING_FAILED
;
15084 /* Maybe forget recorded base line for line number display. */
15085 if (!just_this_one_p
15086 || current_buffer
->clip_changed
15087 || BEG_UNCHANGED
< CHARPOS (startp
))
15088 w
->base_line_number
= 0;
15090 /* If cursor ends up on a partially visible line,
15091 treat that as being off the bottom of the screen. */
15092 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
15093 /* It's possible that the cursor is on the first line of the
15094 buffer, which is partially obscured due to a vscroll
15095 (Bug#7537). In that case, avoid looping forever. */
15096 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15098 clear_glyph_matrix (w
->desired_matrix
);
15099 ++extra_scroll_margin_lines
;
15102 rc
= SCROLLING_SUCCESS
;
15109 /* Compute a suitable window start for window W if display of W starts
15110 on a continuation line. Value is non-zero if a new window start
15113 The new window start will be computed, based on W's width, starting
15114 from the start of the continued line. It is the start of the
15115 screen line with the minimum distance from the old start W->start. */
15118 compute_window_start_on_continuation_line (struct window
*w
)
15120 struct text_pos pos
, start_pos
;
15121 int window_start_changed_p
= 0;
15123 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15125 /* If window start is on a continuation line... Window start may be
15126 < BEGV in case there's invisible text at the start of the
15127 buffer (M-x rmail, for example). */
15128 if (CHARPOS (start_pos
) > BEGV
15129 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15132 struct glyph_row
*row
;
15134 /* Handle the case that the window start is out of range. */
15135 if (CHARPOS (start_pos
) < BEGV
)
15136 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15137 else if (CHARPOS (start_pos
) > ZV
)
15138 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15140 /* Find the start of the continued line. This should be fast
15141 because find_newline is fast (newline cache). */
15142 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
15143 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15144 row
, DEFAULT_FACE_ID
);
15145 reseat_at_previous_visible_line_start (&it
);
15147 /* If the line start is "too far" away from the window start,
15148 say it takes too much time to compute a new window start. */
15149 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15150 /* PXW: Do we need upper bounds here? */
15151 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15153 int min_distance
, distance
;
15155 /* Move forward by display lines to find the new window
15156 start. If window width was enlarged, the new start can
15157 be expected to be > the old start. If window width was
15158 decreased, the new window start will be < the old start.
15159 So, we're looking for the display line start with the
15160 minimum distance from the old window start. */
15161 pos
= it
.current
.pos
;
15162 min_distance
= INFINITY
;
15163 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15164 distance
< min_distance
)
15166 min_distance
= distance
;
15167 pos
= it
.current
.pos
;
15168 if (it
.line_wrap
== WORD_WRAP
)
15170 /* Under WORD_WRAP, move_it_by_lines is likely to
15171 overshoot and stop not at the first, but the
15172 second character from the left margin. So in
15173 that case, we need a more tight control on the X
15174 coordinate of the iterator than move_it_by_lines
15175 promises in its contract. The method is to first
15176 go to the last (rightmost) visible character of a
15177 line, then move to the leftmost character on the
15178 next line in a separate call. */
15179 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15180 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15181 move_it_to (&it
, ZV
, 0,
15182 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15183 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15186 move_it_by_lines (&it
, 1);
15189 /* Set the window start there. */
15190 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15191 window_start_changed_p
= 1;
15195 return window_start_changed_p
;
15199 /* Try cursor movement in case text has not changed in window WINDOW,
15200 with window start STARTP. Value is
15202 CURSOR_MOVEMENT_SUCCESS if successful
15204 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15206 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15207 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15208 we want to scroll as if scroll-step were set to 1. See the code.
15210 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15211 which case we have to abort this redisplay, and adjust matrices
15216 CURSOR_MOVEMENT_SUCCESS
,
15217 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15218 CURSOR_MOVEMENT_MUST_SCROLL
,
15219 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15223 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15225 struct window
*w
= XWINDOW (window
);
15226 struct frame
*f
= XFRAME (w
->frame
);
15227 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15230 if (inhibit_try_cursor_movement
)
15234 /* Previously, there was a check for Lisp integer in the
15235 if-statement below. Now, this field is converted to
15236 ptrdiff_t, thus zero means invalid position in a buffer. */
15237 eassert (w
->last_point
> 0);
15238 /* Likewise there was a check whether window_end_vpos is nil or larger
15239 than the window. Now window_end_vpos is int and so never nil, but
15240 let's leave eassert to check whether it fits in the window. */
15241 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15243 /* Handle case where text has not changed, only point, and it has
15244 not moved off the frame. */
15245 if (/* Point may be in this window. */
15246 PT
>= CHARPOS (startp
)
15247 /* Selective display hasn't changed. */
15248 && !current_buffer
->clip_changed
15249 /* Function force-mode-line-update is used to force a thorough
15250 redisplay. It sets either windows_or_buffers_changed or
15251 update_mode_lines. So don't take a shortcut here for these
15253 && !update_mode_lines
15254 && !windows_or_buffers_changed
15255 && !f
->cursor_type_changed
15256 && NILP (Vshow_trailing_whitespace
)
15257 /* This code is not used for mini-buffer for the sake of the case
15258 of redisplaying to replace an echo area message; since in
15259 that case the mini-buffer contents per se are usually
15260 unchanged. This code is of no real use in the mini-buffer
15261 since the handling of this_line_start_pos, etc., in redisplay
15262 handles the same cases. */
15263 && !EQ (window
, minibuf_window
)
15264 && (FRAME_WINDOW_P (f
)
15265 || !overlay_arrow_in_current_buffer_p ()))
15267 int this_scroll_margin
, top_scroll_margin
;
15268 struct glyph_row
*row
= NULL
;
15269 int frame_line_height
= default_line_pixel_height (w
);
15270 int window_total_lines
15271 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15274 debug_method_add (w
, "cursor movement");
15277 /* Scroll if point within this distance from the top or bottom
15278 of the window. This is a pixel value. */
15279 if (scroll_margin
> 0)
15281 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15282 this_scroll_margin
*= frame_line_height
;
15285 this_scroll_margin
= 0;
15287 top_scroll_margin
= this_scroll_margin
;
15288 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15289 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15291 /* Start with the row the cursor was displayed during the last
15292 not paused redisplay. Give up if that row is not valid. */
15293 if (w
->last_cursor_vpos
< 0
15294 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15295 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15298 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15299 if (row
->mode_line_p
)
15301 if (!row
->enabled_p
)
15302 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15305 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15307 int scroll_p
= 0, must_scroll
= 0;
15308 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15310 if (PT
> w
->last_point
)
15312 /* Point has moved forward. */
15313 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15314 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15316 eassert (row
->enabled_p
);
15320 /* If the end position of a row equals the start
15321 position of the next row, and PT is at that position,
15322 we would rather display cursor in the next line. */
15323 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15324 && MATRIX_ROW_END_CHARPOS (row
) == PT
15325 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15326 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15327 && !cursor_row_p (row
))
15330 /* If within the scroll margin, scroll. Note that
15331 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15332 the next line would be drawn, and that
15333 this_scroll_margin can be zero. */
15334 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15335 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15336 /* Line is completely visible last line in window
15337 and PT is to be set in the next line. */
15338 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15339 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15340 && !row
->ends_at_zv_p
15341 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15344 else if (PT
< w
->last_point
)
15346 /* Cursor has to be moved backward. Note that PT >=
15347 CHARPOS (startp) because of the outer if-statement. */
15348 while (!row
->mode_line_p
15349 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15350 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15351 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15352 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15353 row
> w
->current_matrix
->rows
15354 && (row
-1)->ends_in_newline_from_string_p
))))
15355 && (row
->y
> top_scroll_margin
15356 || CHARPOS (startp
) == BEGV
))
15358 eassert (row
->enabled_p
);
15362 /* Consider the following case: Window starts at BEGV,
15363 there is invisible, intangible text at BEGV, so that
15364 display starts at some point START > BEGV. It can
15365 happen that we are called with PT somewhere between
15366 BEGV and START. Try to handle that case. */
15367 if (row
< w
->current_matrix
->rows
15368 || row
->mode_line_p
)
15370 row
= w
->current_matrix
->rows
;
15371 if (row
->mode_line_p
)
15375 /* Due to newlines in overlay strings, we may have to
15376 skip forward over overlay strings. */
15377 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15378 && MATRIX_ROW_END_CHARPOS (row
) == PT
15379 && !cursor_row_p (row
))
15382 /* If within the scroll margin, scroll. */
15383 if (row
->y
< top_scroll_margin
15384 && CHARPOS (startp
) != BEGV
)
15389 /* Cursor did not move. So don't scroll even if cursor line
15390 is partially visible, as it was so before. */
15391 rc
= CURSOR_MOVEMENT_SUCCESS
;
15394 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15395 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15397 /* if PT is not in the glyph row, give up. */
15398 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15401 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15402 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15404 struct glyph_row
*row1
;
15406 /* If rows are bidi-reordered and point moved, back up
15407 until we find a row that does not belong to a
15408 continuation line. This is because we must consider
15409 all rows of a continued line as candidates for the
15410 new cursor positioning, since row start and end
15411 positions change non-linearly with vertical position
15413 /* FIXME: Revisit this when glyph ``spilling'' in
15414 continuation lines' rows is implemented for
15415 bidi-reordered rows. */
15416 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15417 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15420 /* If we hit the beginning of the displayed portion
15421 without finding the first row of a continued
15425 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15428 eassert (row
->enabled_p
);
15433 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15434 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15435 /* Make sure this isn't a header line by any chance, since
15436 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15437 && !row
->mode_line_p
15438 && make_cursor_line_fully_visible_p
)
15440 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15441 && !row
->ends_at_zv_p
15442 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15443 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15444 else if (row
->height
> window_box_height (w
))
15446 /* If we end up in a partially visible line, let's
15447 make it fully visible, except when it's taller
15448 than the window, in which case we can't do much
15451 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15455 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15456 if (!cursor_row_fully_visible_p (w
, 0, 1))
15457 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15459 rc
= CURSOR_MOVEMENT_SUCCESS
;
15463 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15464 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15465 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15467 /* With bidi-reordered rows, there could be more than
15468 one candidate row whose start and end positions
15469 occlude point. We need to let set_cursor_from_row
15470 find the best candidate. */
15471 /* FIXME: Revisit this when glyph ``spilling'' in
15472 continuation lines' rows is implemented for
15473 bidi-reordered rows. */
15478 int at_zv_p
= 0, exact_match_p
= 0;
15480 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15481 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15482 && cursor_row_p (row
))
15483 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15485 /* As soon as we've found the exact match for point,
15486 or the first suitable row whose ends_at_zv_p flag
15487 is set, we are done. */
15490 at_zv_p
= MATRIX_ROW (w
->current_matrix
,
15491 w
->cursor
.vpos
)->ends_at_zv_p
;
15493 && w
->cursor
.hpos
>= 0
15494 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15497 struct glyph_row
*candidate
=
15498 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15500 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15501 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15504 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15505 || (INTEGERP (g
->object
)
15506 && (g
->charpos
== PT
15507 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15509 if (at_zv_p
|| exact_match_p
)
15511 rc
= CURSOR_MOVEMENT_SUCCESS
;
15515 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15519 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15520 || row
->continued_p
)
15521 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15522 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15523 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15524 /* If we didn't find any candidate rows, or exited the
15525 loop before all the candidates were examined, signal
15526 to the caller that this method failed. */
15527 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15529 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15530 && !row
->continued_p
))
15531 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15533 rc
= CURSOR_MOVEMENT_SUCCESS
;
15539 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15541 rc
= CURSOR_MOVEMENT_SUCCESS
;
15546 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15547 && MATRIX_ROW_START_CHARPOS (row
) == PT
15548 && cursor_row_p (row
));
15556 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15560 set_vertical_scroll_bar (struct window
*w
)
15562 ptrdiff_t start
, end
, whole
;
15564 /* Calculate the start and end positions for the current window.
15565 At some point, it would be nice to choose between scrollbars
15566 which reflect the whole buffer size, with special markers
15567 indicating narrowing, and scrollbars which reflect only the
15570 Note that mini-buffers sometimes aren't displaying any text. */
15571 if (!MINI_WINDOW_P (w
)
15572 || (w
== XWINDOW (minibuf_window
)
15573 && NILP (echo_area_buffer
[0])))
15575 struct buffer
*buf
= XBUFFER (w
->contents
);
15576 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15577 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15578 /* I don't think this is guaranteed to be right. For the
15579 moment, we'll pretend it is. */
15580 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15584 if (whole
< (end
- start
))
15585 whole
= end
- start
;
15588 start
= end
= whole
= 0;
15590 /* Indicate what this scroll bar ought to be displaying now. */
15591 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15592 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15593 (w
, end
- start
, whole
, start
);
15597 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15598 selected_window is redisplayed.
15600 We can return without actually redisplaying the window if fonts has been
15601 changed on window's frame. In that case, redisplay_internal will retry. */
15604 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
15606 struct window
*w
= XWINDOW (window
);
15607 struct frame
*f
= XFRAME (w
->frame
);
15608 struct buffer
*buffer
= XBUFFER (w
->contents
);
15609 struct buffer
*old
= current_buffer
;
15610 struct text_pos lpoint
, opoint
, startp
;
15611 int update_mode_line
;
15614 /* Record it now because it's overwritten. */
15615 bool current_matrix_up_to_date_p
= false;
15616 bool used_current_matrix_p
= false;
15617 /* This is less strict than current_matrix_up_to_date_p.
15618 It indicates that the buffer contents and narrowing are unchanged. */
15619 bool buffer_unchanged_p
= false;
15620 int temp_scroll_step
= 0;
15621 ptrdiff_t count
= SPECPDL_INDEX ();
15623 int centering_position
= -1;
15624 int last_line_misfit
= 0;
15625 ptrdiff_t beg_unchanged
, end_unchanged
;
15626 int frame_line_height
;
15628 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15632 *w
->desired_matrix
->method
= 0;
15635 if (!just_this_one_p
15636 && REDISPLAY_SOME_P ()
15639 && !buffer
->text
->redisplay
15640 && BUF_PT (buffer
) == w
->last_point
)
15643 /* Make sure that both W's markers are valid. */
15644 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15645 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15648 reconsider_clip_changes (w
);
15649 frame_line_height
= default_line_pixel_height (w
);
15651 /* Has the mode line to be updated? */
15652 update_mode_line
= (w
->update_mode_line
15653 || update_mode_lines
15654 || buffer
->clip_changed
15655 || buffer
->prevent_redisplay_optimizations_p
);
15657 if (!just_this_one_p
)
15658 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
15659 cleverly elsewhere. */
15660 w
->must_be_updated_p
= true;
15662 if (MINI_WINDOW_P (w
))
15664 if (w
== XWINDOW (echo_area_window
)
15665 && !NILP (echo_area_buffer
[0]))
15667 if (update_mode_line
)
15668 /* We may have to update a tty frame's menu bar or a
15669 tool-bar. Example `M-x C-h C-h C-g'. */
15670 goto finish_menu_bars
;
15672 /* We've already displayed the echo area glyphs in this window. */
15673 goto finish_scroll_bars
;
15675 else if ((w
!= XWINDOW (minibuf_window
)
15676 || minibuf_level
== 0)
15677 /* When buffer is nonempty, redisplay window normally. */
15678 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15679 /* Quail displays non-mini buffers in minibuffer window.
15680 In that case, redisplay the window normally. */
15681 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15683 /* W is a mini-buffer window, but it's not active, so clear
15685 int yb
= window_text_bottom_y (w
);
15686 struct glyph_row
*row
;
15689 for (y
= 0, row
= w
->desired_matrix
->rows
;
15691 y
+= row
->height
, ++row
)
15692 blank_row (w
, row
, y
);
15693 goto finish_scroll_bars
;
15696 clear_glyph_matrix (w
->desired_matrix
);
15699 /* Otherwise set up data on this window; select its buffer and point
15701 /* Really select the buffer, for the sake of buffer-local
15703 set_buffer_internal_1 (XBUFFER (w
->contents
));
15705 current_matrix_up_to_date_p
15706 = (w
->window_end_valid
15707 && !current_buffer
->clip_changed
15708 && !current_buffer
->prevent_redisplay_optimizations_p
15709 && !window_outdated (w
));
15711 /* Run the window-bottom-change-functions
15712 if it is possible that the text on the screen has changed
15713 (either due to modification of the text, or any other reason). */
15714 if (!current_matrix_up_to_date_p
15715 && !NILP (Vwindow_text_change_functions
))
15717 safe_run_hooks (Qwindow_text_change_functions
);
15721 beg_unchanged
= BEG_UNCHANGED
;
15722 end_unchanged
= END_UNCHANGED
;
15724 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15726 specbind (Qinhibit_point_motion_hooks
, Qt
);
15729 = (w
->window_end_valid
15730 && !current_buffer
->clip_changed
15731 && !window_outdated (w
));
15733 /* When windows_or_buffers_changed is non-zero, we can't rely
15734 on the window end being valid, so set it to zero there. */
15735 if (windows_or_buffers_changed
)
15737 /* If window starts on a continuation line, maybe adjust the
15738 window start in case the window's width changed. */
15739 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15740 compute_window_start_on_continuation_line (w
);
15742 w
->window_end_valid
= false;
15743 /* If so, we also can't rely on current matrix
15744 and should not fool try_cursor_movement below. */
15745 current_matrix_up_to_date_p
= false;
15748 /* Some sanity checks. */
15749 CHECK_WINDOW_END (w
);
15750 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15752 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15755 if (mode_line_update_needed (w
))
15756 update_mode_line
= 1;
15758 /* Point refers normally to the selected window. For any other
15759 window, set up appropriate value. */
15760 if (!EQ (window
, selected_window
))
15762 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15763 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15767 new_pt_byte
= BEGV_BYTE
;
15768 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15770 else if (new_pt
> (ZV
- 1))
15773 new_pt_byte
= ZV_BYTE
;
15774 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15777 /* We don't use SET_PT so that the point-motion hooks don't run. */
15778 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15781 /* If any of the character widths specified in the display table
15782 have changed, invalidate the width run cache. It's true that
15783 this may be a bit late to catch such changes, but the rest of
15784 redisplay goes (non-fatally) haywire when the display table is
15785 changed, so why should we worry about doing any better? */
15786 if (current_buffer
->width_run_cache
15787 || (current_buffer
->base_buffer
15788 && current_buffer
->base_buffer
->width_run_cache
))
15790 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15792 if (! disptab_matches_widthtab
15793 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15795 struct buffer
*buf
= current_buffer
;
15797 if (buf
->base_buffer
)
15798 buf
= buf
->base_buffer
;
15799 invalidate_region_cache (buf
, buf
->width_run_cache
, BEG
, Z
);
15800 recompute_width_table (current_buffer
, disptab
);
15804 /* If window-start is screwed up, choose a new one. */
15805 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15808 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15810 /* If someone specified a new starting point but did not insist,
15811 check whether it can be used. */
15812 if (w
->optional_new_start
15813 && CHARPOS (startp
) >= BEGV
15814 && CHARPOS (startp
) <= ZV
)
15816 w
->optional_new_start
= 0;
15817 start_display (&it
, w
, startp
);
15818 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15819 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15820 if (IT_CHARPOS (it
) == PT
)
15821 w
->force_start
= 1;
15822 /* IT may overshoot PT if text at PT is invisible. */
15823 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15824 w
->force_start
= 1;
15829 /* Handle case where place to start displaying has been specified,
15830 unless the specified location is outside the accessible range. */
15831 if (w
->force_start
|| window_frozen_p (w
))
15833 /* We set this later on if we have to adjust point. */
15836 w
->force_start
= 0;
15838 w
->window_end_valid
= 0;
15840 /* Forget any recorded base line for line number display. */
15841 if (!buffer_unchanged_p
)
15842 w
->base_line_number
= 0;
15844 /* Redisplay the mode line. Select the buffer properly for that.
15845 Also, run the hook window-scroll-functions
15846 because we have scrolled. */
15847 /* Note, we do this after clearing force_start because
15848 if there's an error, it is better to forget about force_start
15849 than to get into an infinite loop calling the hook functions
15850 and having them get more errors. */
15851 if (!update_mode_line
15852 || ! NILP (Vwindow_scroll_functions
))
15854 update_mode_line
= 1;
15855 w
->update_mode_line
= 1;
15856 startp
= run_window_scroll_functions (window
, startp
);
15859 if (CHARPOS (startp
) < BEGV
)
15860 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15861 else if (CHARPOS (startp
) > ZV
)
15862 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15864 /* Redisplay, then check if cursor has been set during the
15865 redisplay. Give up if new fonts were loaded. */
15866 /* We used to issue a CHECK_MARGINS argument to try_window here,
15867 but this causes scrolling to fail when point begins inside
15868 the scroll margin (bug#148) -- cyd */
15869 if (!try_window (window
, startp
, 0))
15871 w
->force_start
= 1;
15872 clear_glyph_matrix (w
->desired_matrix
);
15873 goto need_larger_matrices
;
15876 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15878 /* If point does not appear, try to move point so it does
15879 appear. The desired matrix has been built above, so we
15880 can use it here. */
15881 new_vpos
= window_box_height (w
) / 2;
15884 if (!cursor_row_fully_visible_p (w
, 0, 0))
15886 /* Point does appear, but on a line partly visible at end of window.
15887 Move it back to a fully-visible line. */
15888 new_vpos
= window_box_height (w
);
15890 else if (w
->cursor
.vpos
>= 0)
15892 /* Some people insist on not letting point enter the scroll
15893 margin, even though this part handles windows that didn't
15895 int window_total_lines
15896 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15897 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15898 int pixel_margin
= margin
* frame_line_height
;
15899 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15901 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15902 below, which finds the row to move point to, advances by
15903 the Y coordinate of the _next_ row, see the definition of
15904 MATRIX_ROW_BOTTOM_Y. */
15905 if (w
->cursor
.vpos
< margin
+ header_line
)
15907 w
->cursor
.vpos
= -1;
15908 clear_glyph_matrix (w
->desired_matrix
);
15909 goto try_to_scroll
;
15913 int window_height
= window_box_height (w
);
15916 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15917 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15919 w
->cursor
.vpos
= -1;
15920 clear_glyph_matrix (w
->desired_matrix
);
15921 goto try_to_scroll
;
15926 /* If we need to move point for either of the above reasons,
15927 now actually do it. */
15930 struct glyph_row
*row
;
15932 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15933 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15936 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15937 MATRIX_ROW_START_BYTEPOS (row
));
15939 if (w
!= XWINDOW (selected_window
))
15940 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15941 else if (current_buffer
== old
)
15942 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15944 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15946 /* If we are highlighting the region, then we just changed
15947 the region, so redisplay to show it. */
15948 /* FIXME: We need to (re)run pre-redisplay-function! */
15949 /* if (markpos_of_region () >= 0)
15951 clear_glyph_matrix (w->desired_matrix);
15952 if (!try_window (window, startp, 0))
15953 goto need_larger_matrices;
15959 debug_method_add (w
, "forced window start");
15964 /* Handle case where text has not changed, only point, and it has
15965 not moved off the frame, and we are not retrying after hscroll.
15966 (current_matrix_up_to_date_p is nonzero when retrying.) */
15967 if (current_matrix_up_to_date_p
15968 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15969 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15973 case CURSOR_MOVEMENT_SUCCESS
:
15974 used_current_matrix_p
= 1;
15977 case CURSOR_MOVEMENT_MUST_SCROLL
:
15978 goto try_to_scroll
;
15984 /* If current starting point was originally the beginning of a line
15985 but no longer is, find a new starting point. */
15986 else if (w
->start_at_line_beg
15987 && !(CHARPOS (startp
) <= BEGV
15988 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15991 debug_method_add (w
, "recenter 1");
15996 /* Try scrolling with try_window_id. Value is > 0 if update has
15997 been done, it is -1 if we know that the same window start will
15998 not work. It is 0 if unsuccessful for some other reason. */
15999 else if ((tem
= try_window_id (w
)) != 0)
16002 debug_method_add (w
, "try_window_id %d", tem
);
16005 if (f
->fonts_changed
)
16006 goto need_larger_matrices
;
16010 /* Otherwise try_window_id has returned -1 which means that we
16011 don't want the alternative below this comment to execute. */
16013 else if (CHARPOS (startp
) >= BEGV
16014 && CHARPOS (startp
) <= ZV
16015 && PT
>= CHARPOS (startp
)
16016 && (CHARPOS (startp
) < ZV
16017 /* Avoid starting at end of buffer. */
16018 || CHARPOS (startp
) == BEGV
16019 || !window_outdated (w
)))
16021 int d1
, d2
, d3
, d4
, d5
, d6
;
16023 /* If first window line is a continuation line, and window start
16024 is inside the modified region, but the first change is before
16025 current window start, we must select a new window start.
16027 However, if this is the result of a down-mouse event (e.g. by
16028 extending the mouse-drag-overlay), we don't want to select a
16029 new window start, since that would change the position under
16030 the mouse, resulting in an unwanted mouse-movement rather
16031 than a simple mouse-click. */
16032 if (!w
->start_at_line_beg
16033 && NILP (do_mouse_tracking
)
16034 && CHARPOS (startp
) > BEGV
16035 && CHARPOS (startp
) > BEG
+ beg_unchanged
16036 && CHARPOS (startp
) <= Z
- end_unchanged
16037 /* Even if w->start_at_line_beg is nil, a new window may
16038 start at a line_beg, since that's how set_buffer_window
16039 sets it. So, we need to check the return value of
16040 compute_window_start_on_continuation_line. (See also
16042 && XMARKER (w
->start
)->buffer
== current_buffer
16043 && compute_window_start_on_continuation_line (w
)
16044 /* It doesn't make sense to force the window start like we
16045 do at label force_start if it is already known that point
16046 will not be visible in the resulting window, because
16047 doing so will move point from its correct position
16048 instead of scrolling the window to bring point into view.
16050 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
16052 w
->force_start
= 1;
16053 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16058 debug_method_add (w
, "same window start");
16061 /* Try to redisplay starting at same place as before.
16062 If point has not moved off frame, accept the results. */
16063 if (!current_matrix_up_to_date_p
16064 /* Don't use try_window_reusing_current_matrix in this case
16065 because a window scroll function can have changed the
16067 || !NILP (Vwindow_scroll_functions
)
16068 || MINI_WINDOW_P (w
)
16069 || !(used_current_matrix_p
16070 = try_window_reusing_current_matrix (w
)))
16072 IF_DEBUG (debug_method_add (w
, "1"));
16073 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16074 /* -1 means we need to scroll.
16075 0 means we need new matrices, but fonts_changed
16076 is set in that case, so we will detect it below. */
16077 goto try_to_scroll
;
16080 if (f
->fonts_changed
)
16081 goto need_larger_matrices
;
16083 if (w
->cursor
.vpos
>= 0)
16085 if (!just_this_one_p
16086 || current_buffer
->clip_changed
16087 || BEG_UNCHANGED
< CHARPOS (startp
))
16088 /* Forget any recorded base line for line number display. */
16089 w
->base_line_number
= 0;
16091 if (!cursor_row_fully_visible_p (w
, 1, 0))
16093 clear_glyph_matrix (w
->desired_matrix
);
16094 last_line_misfit
= 1;
16096 /* Drop through and scroll. */
16101 clear_glyph_matrix (w
->desired_matrix
);
16106 /* Redisplay the mode line. Select the buffer properly for that. */
16107 if (!update_mode_line
)
16109 update_mode_line
= 1;
16110 w
->update_mode_line
= 1;
16113 /* Try to scroll by specified few lines. */
16114 if ((scroll_conservatively
16115 || emacs_scroll_step
16116 || temp_scroll_step
16117 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16118 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16119 && CHARPOS (startp
) >= BEGV
16120 && CHARPOS (startp
) <= ZV
)
16122 /* The function returns -1 if new fonts were loaded, 1 if
16123 successful, 0 if not successful. */
16124 int ss
= try_scrolling (window
, just_this_one_p
,
16125 scroll_conservatively
,
16127 temp_scroll_step
, last_line_misfit
);
16130 case SCROLLING_SUCCESS
:
16133 case SCROLLING_NEED_LARGER_MATRICES
:
16134 goto need_larger_matrices
;
16136 case SCROLLING_FAILED
:
16144 /* Finally, just choose a place to start which positions point
16145 according to user preferences. */
16150 debug_method_add (w
, "recenter");
16153 /* Forget any previously recorded base line for line number display. */
16154 if (!buffer_unchanged_p
)
16155 w
->base_line_number
= 0;
16157 /* Determine the window start relative to point. */
16158 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16159 it
.current_y
= it
.last_visible_y
;
16160 if (centering_position
< 0)
16162 int window_total_lines
16163 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16166 ? min (scroll_margin
, window_total_lines
/ 4)
16168 ptrdiff_t margin_pos
= CHARPOS (startp
);
16169 Lisp_Object aggressive
;
16172 /* If there is a scroll margin at the top of the window, find
16173 its character position. */
16175 /* Cannot call start_display if startp is not in the
16176 accessible region of the buffer. This can happen when we
16177 have just switched to a different buffer and/or changed
16178 its restriction. In that case, startp is initialized to
16179 the character position 1 (BEGV) because we did not yet
16180 have chance to display the buffer even once. */
16181 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16184 void *it1data
= NULL
;
16186 SAVE_IT (it1
, it
, it1data
);
16187 start_display (&it1
, w
, startp
);
16188 move_it_vertically (&it1
, margin
* frame_line_height
);
16189 margin_pos
= IT_CHARPOS (it1
);
16190 RESTORE_IT (&it
, &it
, it1data
);
16192 scrolling_up
= PT
> margin_pos
;
16195 ? BVAR (current_buffer
, scroll_up_aggressively
)
16196 : BVAR (current_buffer
, scroll_down_aggressively
);
16198 if (!MINI_WINDOW_P (w
)
16199 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16203 /* Setting scroll-conservatively overrides
16204 scroll-*-aggressively. */
16205 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16207 double float_amount
= XFLOATINT (aggressive
);
16209 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16210 if (pt_offset
== 0 && float_amount
> 0)
16212 if (pt_offset
&& margin
> 0)
16215 /* Compute how much to move the window start backward from
16216 point so that point will be displayed where the user
16220 centering_position
= it
.last_visible_y
;
16222 centering_position
-= pt_offset
;
16223 centering_position
-=
16224 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
16225 + WINDOW_HEADER_LINE_HEIGHT (w
);
16226 /* Don't let point enter the scroll margin near top of
16228 if (centering_position
< margin
* frame_line_height
)
16229 centering_position
= margin
* frame_line_height
;
16232 centering_position
= margin
* frame_line_height
+ pt_offset
;
16235 /* Set the window start half the height of the window backward
16237 centering_position
= window_box_height (w
) / 2;
16239 move_it_vertically_backward (&it
, centering_position
);
16241 eassert (IT_CHARPOS (it
) >= BEGV
);
16243 /* The function move_it_vertically_backward may move over more
16244 than the specified y-distance. If it->w is small, e.g. a
16245 mini-buffer window, we may end up in front of the window's
16246 display area. Start displaying at the start of the line
16247 containing PT in this case. */
16248 if (it
.current_y
<= 0)
16250 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16251 move_it_vertically_backward (&it
, 0);
16255 it
.current_x
= it
.hpos
= 0;
16257 /* Set the window start position here explicitly, to avoid an
16258 infinite loop in case the functions in window-scroll-functions
16260 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16262 /* Run scroll hooks. */
16263 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16265 /* Redisplay the window. */
16266 if (!current_matrix_up_to_date_p
16267 || windows_or_buffers_changed
16268 || f
->cursor_type_changed
16269 /* Don't use try_window_reusing_current_matrix in this case
16270 because it can have changed the buffer. */
16271 || !NILP (Vwindow_scroll_functions
)
16272 || !just_this_one_p
16273 || MINI_WINDOW_P (w
)
16274 || !(used_current_matrix_p
16275 = try_window_reusing_current_matrix (w
)))
16276 try_window (window
, startp
, 0);
16278 /* If new fonts have been loaded (due to fontsets), give up. We
16279 have to start a new redisplay since we need to re-adjust glyph
16281 if (f
->fonts_changed
)
16282 goto need_larger_matrices
;
16284 /* If cursor did not appear assume that the middle of the window is
16285 in the first line of the window. Do it again with the next line.
16286 (Imagine a window of height 100, displaying two lines of height
16287 60. Moving back 50 from it->last_visible_y will end in the first
16289 if (w
->cursor
.vpos
< 0)
16291 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16293 clear_glyph_matrix (w
->desired_matrix
);
16294 move_it_by_lines (&it
, 1);
16295 try_window (window
, it
.current
.pos
, 0);
16297 else if (PT
< IT_CHARPOS (it
))
16299 clear_glyph_matrix (w
->desired_matrix
);
16300 move_it_by_lines (&it
, -1);
16301 try_window (window
, it
.current
.pos
, 0);
16305 /* Not much we can do about it. */
16309 /* Consider the following case: Window starts at BEGV, there is
16310 invisible, intangible text at BEGV, so that display starts at
16311 some point START > BEGV. It can happen that we are called with
16312 PT somewhere between BEGV and START. Try to handle that case. */
16313 if (w
->cursor
.vpos
< 0)
16315 struct glyph_row
*row
= w
->current_matrix
->rows
;
16316 if (row
->mode_line_p
)
16318 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16321 if (!cursor_row_fully_visible_p (w
, 0, 0))
16323 /* If vscroll is enabled, disable it and try again. */
16327 clear_glyph_matrix (w
->desired_matrix
);
16331 /* Users who set scroll-conservatively to a large number want
16332 point just above/below the scroll margin. If we ended up
16333 with point's row partially visible, move the window start to
16334 make that row fully visible and out of the margin. */
16335 if (scroll_conservatively
> SCROLL_LIMIT
)
16337 int window_total_lines
16338 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16341 ? min (scroll_margin
, window_total_lines
/ 4)
16343 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16345 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16346 clear_glyph_matrix (w
->desired_matrix
);
16347 if (1 == try_window (window
, it
.current
.pos
,
16348 TRY_WINDOW_CHECK_MARGINS
))
16352 /* If centering point failed to make the whole line visible,
16353 put point at the top instead. That has to make the whole line
16354 visible, if it can be done. */
16355 if (centering_position
== 0)
16358 clear_glyph_matrix (w
->desired_matrix
);
16359 centering_position
= 0;
16365 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16366 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16367 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16369 /* Display the mode line, if we must. */
16370 if ((update_mode_line
16371 /* If window not full width, must redo its mode line
16372 if (a) the window to its side is being redone and
16373 (b) we do a frame-based redisplay. This is a consequence
16374 of how inverted lines are drawn in frame-based redisplay. */
16375 || (!just_this_one_p
16376 && !FRAME_WINDOW_P (f
)
16377 && !WINDOW_FULL_WIDTH_P (w
))
16378 /* Line number to display. */
16379 || w
->base_line_pos
> 0
16380 /* Column number is displayed and different from the one displayed. */
16381 || (w
->column_number_displayed
!= -1
16382 && (w
->column_number_displayed
!= current_column ())))
16383 /* This means that the window has a mode line. */
16384 && (WINDOW_WANTS_MODELINE_P (w
)
16385 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16388 display_mode_lines (w
);
16390 /* If mode line height has changed, arrange for a thorough
16391 immediate redisplay using the correct mode line height. */
16392 if (WINDOW_WANTS_MODELINE_P (w
)
16393 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16395 f
->fonts_changed
= 1;
16396 w
->mode_line_height
= -1;
16397 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16398 = DESIRED_MODE_LINE_HEIGHT (w
);
16401 /* If header line height has changed, arrange for a thorough
16402 immediate redisplay using the correct header line height. */
16403 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16404 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16406 f
->fonts_changed
= 1;
16407 w
->header_line_height
= -1;
16408 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16409 = DESIRED_HEADER_LINE_HEIGHT (w
);
16412 if (f
->fonts_changed
)
16413 goto need_larger_matrices
;
16416 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16418 w
->base_line_pos
= 0;
16419 w
->base_line_number
= 0;
16424 /* When we reach a frame's selected window, redo the frame's menu bar. */
16425 if (update_mode_line
16426 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16428 int redisplay_menu_p
= 0;
16430 if (FRAME_WINDOW_P (f
))
16432 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16433 || defined (HAVE_NS) || defined (USE_GTK)
16434 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16436 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16440 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16442 if (redisplay_menu_p
)
16443 display_menu_bar (w
);
16445 #ifdef HAVE_WINDOW_SYSTEM
16446 if (FRAME_WINDOW_P (f
))
16448 #if defined (USE_GTK) || defined (HAVE_NS)
16449 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16450 redisplay_tool_bar (f
);
16452 if (WINDOWP (f
->tool_bar_window
)
16453 && (FRAME_TOOL_BAR_HEIGHT (f
) > 0
16454 || !NILP (Vauto_resize_tool_bars
))
16455 && redisplay_tool_bar (f
))
16456 ignore_mouse_drag_p
= 1;
16462 #ifdef HAVE_WINDOW_SYSTEM
16463 if (FRAME_WINDOW_P (f
)
16464 && update_window_fringes (w
, (just_this_one_p
16465 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16466 || w
->pseudo_window_p
)))
16470 if (draw_window_fringes (w
, 1))
16472 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
16473 x_draw_right_divider (w
);
16475 x_draw_vertical_border (w
);
16481 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
16482 x_draw_bottom_divider (w
);
16483 #endif /* HAVE_WINDOW_SYSTEM */
16485 /* We go to this label, with fonts_changed set, if it is
16486 necessary to try again using larger glyph matrices.
16487 We have to redeem the scroll bar even in this case,
16488 because the loop in redisplay_internal expects that. */
16489 need_larger_matrices
:
16491 finish_scroll_bars
:
16493 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16495 /* Set the thumb's position and size. */
16496 set_vertical_scroll_bar (w
);
16498 /* Note that we actually used the scroll bar attached to this
16499 window, so it shouldn't be deleted at the end of redisplay. */
16500 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16501 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16504 /* Restore current_buffer and value of point in it. The window
16505 update may have changed the buffer, so first make sure `opoint'
16506 is still valid (Bug#6177). */
16507 if (CHARPOS (opoint
) < BEGV
)
16508 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16509 else if (CHARPOS (opoint
) > ZV
)
16510 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16512 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16514 set_buffer_internal_1 (old
);
16515 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16516 shorter. This can be caused by log truncation in *Messages*. */
16517 if (CHARPOS (lpoint
) <= ZV
)
16518 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16520 unbind_to (count
, Qnil
);
16524 /* Build the complete desired matrix of WINDOW with a window start
16525 buffer position POS.
16527 Value is 1 if successful. It is zero if fonts were loaded during
16528 redisplay which makes re-adjusting glyph matrices necessary, and -1
16529 if point would appear in the scroll margins.
16530 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16531 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16535 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16537 struct window
*w
= XWINDOW (window
);
16539 struct glyph_row
*last_text_row
= NULL
;
16540 struct frame
*f
= XFRAME (w
->frame
);
16541 int frame_line_height
= default_line_pixel_height (w
);
16543 /* Make POS the new window start. */
16544 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16546 /* Mark cursor position as unknown. No overlay arrow seen. */
16547 w
->cursor
.vpos
= -1;
16548 overlay_arrow_seen
= 0;
16550 /* Initialize iterator and info to start at POS. */
16551 start_display (&it
, w
, pos
);
16553 /* Display all lines of W. */
16554 while (it
.current_y
< it
.last_visible_y
)
16556 if (display_line (&it
))
16557 last_text_row
= it
.glyph_row
- 1;
16558 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16562 /* Don't let the cursor end in the scroll margins. */
16563 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16564 && !MINI_WINDOW_P (w
))
16566 int this_scroll_margin
;
16567 int window_total_lines
16568 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16570 if (scroll_margin
> 0)
16572 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16573 this_scroll_margin
*= frame_line_height
;
16576 this_scroll_margin
= 0;
16578 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16579 && w
->cursor
.y
< this_scroll_margin
16580 && CHARPOS (pos
) > BEGV
16581 && IT_CHARPOS (it
) < ZV
)
16582 /* rms: considering make_cursor_line_fully_visible_p here
16583 seems to give wrong results. We don't want to recenter
16584 when the last line is partly visible, we want to allow
16585 that case to be handled in the usual way. */
16586 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16588 w
->cursor
.vpos
= -1;
16589 clear_glyph_matrix (w
->desired_matrix
);
16594 /* If bottom moved off end of frame, change mode line percentage. */
16595 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16596 w
->update_mode_line
= 1;
16598 /* Set window_end_pos to the offset of the last character displayed
16599 on the window from the end of current_buffer. Set
16600 window_end_vpos to its row number. */
16603 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16604 adjust_window_ends (w
, last_text_row
, 0);
16606 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16607 w
->window_end_vpos
)));
16611 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16612 w
->window_end_pos
= Z
- ZV
;
16613 w
->window_end_vpos
= 0;
16616 /* But that is not valid info until redisplay finishes. */
16617 w
->window_end_valid
= 0;
16623 /************************************************************************
16624 Window redisplay reusing current matrix when buffer has not changed
16625 ************************************************************************/
16627 /* Try redisplay of window W showing an unchanged buffer with a
16628 different window start than the last time it was displayed by
16629 reusing its current matrix. Value is non-zero if successful.
16630 W->start is the new window start. */
16633 try_window_reusing_current_matrix (struct window
*w
)
16635 struct frame
*f
= XFRAME (w
->frame
);
16636 struct glyph_row
*bottom_row
;
16639 struct text_pos start
, new_start
;
16640 int nrows_scrolled
, i
;
16641 struct glyph_row
*last_text_row
;
16642 struct glyph_row
*last_reused_text_row
;
16643 struct glyph_row
*start_row
;
16644 int start_vpos
, min_y
, max_y
;
16647 if (inhibit_try_window_reusing
)
16651 if (/* This function doesn't handle terminal frames. */
16652 !FRAME_WINDOW_P (f
)
16653 /* Don't try to reuse the display if windows have been split
16655 || windows_or_buffers_changed
16656 || f
->cursor_type_changed
)
16659 /* Can't do this if showing trailing whitespace. */
16660 if (!NILP (Vshow_trailing_whitespace
))
16663 /* If top-line visibility has changed, give up. */
16664 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16665 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16668 /* Give up if old or new display is scrolled vertically. We could
16669 make this function handle this, but right now it doesn't. */
16670 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16671 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16674 /* The variable new_start now holds the new window start. The old
16675 start `start' can be determined from the current matrix. */
16676 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16677 start
= start_row
->minpos
;
16678 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16680 /* Clear the desired matrix for the display below. */
16681 clear_glyph_matrix (w
->desired_matrix
);
16683 if (CHARPOS (new_start
) <= CHARPOS (start
))
16685 /* Don't use this method if the display starts with an ellipsis
16686 displayed for invisible text. It's not easy to handle that case
16687 below, and it's certainly not worth the effort since this is
16688 not a frequent case. */
16689 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16692 IF_DEBUG (debug_method_add (w
, "twu1"));
16694 /* Display up to a row that can be reused. The variable
16695 last_text_row is set to the last row displayed that displays
16696 text. Note that it.vpos == 0 if or if not there is a
16697 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16698 start_display (&it
, w
, new_start
);
16699 w
->cursor
.vpos
= -1;
16700 last_text_row
= last_reused_text_row
= NULL
;
16702 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16704 /* If we have reached into the characters in the START row,
16705 that means the line boundaries have changed. So we
16706 can't start copying with the row START. Maybe it will
16707 work to start copying with the following row. */
16708 while (IT_CHARPOS (it
) > CHARPOS (start
))
16710 /* Advance to the next row as the "start". */
16712 start
= start_row
->minpos
;
16713 /* If there are no more rows to try, or just one, give up. */
16714 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16715 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16716 || CHARPOS (start
) == ZV
)
16718 clear_glyph_matrix (w
->desired_matrix
);
16722 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16724 /* If we have reached alignment, we can copy the rest of the
16726 if (IT_CHARPOS (it
) == CHARPOS (start
)
16727 /* Don't accept "alignment" inside a display vector,
16728 since start_row could have started in the middle of
16729 that same display vector (thus their character
16730 positions match), and we have no way of telling if
16731 that is the case. */
16732 && it
.current
.dpvec_index
< 0)
16735 if (display_line (&it
))
16736 last_text_row
= it
.glyph_row
- 1;
16740 /* A value of current_y < last_visible_y means that we stopped
16741 at the previous window start, which in turn means that we
16742 have at least one reusable row. */
16743 if (it
.current_y
< it
.last_visible_y
)
16745 struct glyph_row
*row
;
16747 /* IT.vpos always starts from 0; it counts text lines. */
16748 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16750 /* Find PT if not already found in the lines displayed. */
16751 if (w
->cursor
.vpos
< 0)
16753 int dy
= it
.current_y
- start_row
->y
;
16755 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16756 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16758 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16759 dy
, nrows_scrolled
);
16762 clear_glyph_matrix (w
->desired_matrix
);
16767 /* Scroll the display. Do it before the current matrix is
16768 changed. The problem here is that update has not yet
16769 run, i.e. part of the current matrix is not up to date.
16770 scroll_run_hook will clear the cursor, and use the
16771 current matrix to get the height of the row the cursor is
16773 run
.current_y
= start_row
->y
;
16774 run
.desired_y
= it
.current_y
;
16775 run
.height
= it
.last_visible_y
- it
.current_y
;
16777 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16780 FRAME_RIF (f
)->update_window_begin_hook (w
);
16781 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16782 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16783 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16787 /* Shift current matrix down by nrows_scrolled lines. */
16788 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16789 rotate_matrix (w
->current_matrix
,
16791 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16794 /* Disable lines that must be updated. */
16795 for (i
= 0; i
< nrows_scrolled
; ++i
)
16796 (start_row
+ i
)->enabled_p
= false;
16798 /* Re-compute Y positions. */
16799 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16800 max_y
= it
.last_visible_y
;
16801 for (row
= start_row
+ nrows_scrolled
;
16805 row
->y
= it
.current_y
;
16806 row
->visible_height
= row
->height
;
16808 if (row
->y
< min_y
)
16809 row
->visible_height
-= min_y
- row
->y
;
16810 if (row
->y
+ row
->height
> max_y
)
16811 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16812 if (row
->fringe_bitmap_periodic_p
)
16813 row
->redraw_fringe_bitmaps_p
= 1;
16815 it
.current_y
+= row
->height
;
16817 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16818 last_reused_text_row
= row
;
16819 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16823 /* Disable lines in the current matrix which are now
16824 below the window. */
16825 for (++row
; row
< bottom_row
; ++row
)
16826 row
->enabled_p
= row
->mode_line_p
= 0;
16829 /* Update window_end_pos etc.; last_reused_text_row is the last
16830 reused row from the current matrix containing text, if any.
16831 The value of last_text_row is the last displayed line
16832 containing text. */
16833 if (last_reused_text_row
)
16834 adjust_window_ends (w
, last_reused_text_row
, 1);
16835 else if (last_text_row
)
16836 adjust_window_ends (w
, last_text_row
, 0);
16839 /* This window must be completely empty. */
16840 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16841 w
->window_end_pos
= Z
- ZV
;
16842 w
->window_end_vpos
= 0;
16844 w
->window_end_valid
= 0;
16846 /* Update hint: don't try scrolling again in update_window. */
16847 w
->desired_matrix
->no_scrolling_p
= 1;
16850 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16854 else if (CHARPOS (new_start
) > CHARPOS (start
))
16856 struct glyph_row
*pt_row
, *row
;
16857 struct glyph_row
*first_reusable_row
;
16858 struct glyph_row
*first_row_to_display
;
16860 int yb
= window_text_bottom_y (w
);
16862 /* Find the row starting at new_start, if there is one. Don't
16863 reuse a partially visible line at the end. */
16864 first_reusable_row
= start_row
;
16865 while (first_reusable_row
->enabled_p
16866 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16867 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16868 < CHARPOS (new_start
)))
16869 ++first_reusable_row
;
16871 /* Give up if there is no row to reuse. */
16872 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16873 || !first_reusable_row
->enabled_p
16874 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16875 != CHARPOS (new_start
)))
16878 /* We can reuse fully visible rows beginning with
16879 first_reusable_row to the end of the window. Set
16880 first_row_to_display to the first row that cannot be reused.
16881 Set pt_row to the row containing point, if there is any. */
16883 for (first_row_to_display
= first_reusable_row
;
16884 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16885 ++first_row_to_display
)
16887 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16888 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16889 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16890 && first_row_to_display
->ends_at_zv_p
16891 && pt_row
== NULL
)))
16892 pt_row
= first_row_to_display
;
16895 /* Start displaying at the start of first_row_to_display. */
16896 eassert (first_row_to_display
->y
< yb
);
16897 init_to_row_start (&it
, w
, first_row_to_display
);
16899 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16901 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16903 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16904 + WINDOW_HEADER_LINE_HEIGHT (w
));
16906 /* Display lines beginning with first_row_to_display in the
16907 desired matrix. Set last_text_row to the last row displayed
16908 that displays text. */
16909 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16910 if (pt_row
== NULL
)
16911 w
->cursor
.vpos
= -1;
16912 last_text_row
= NULL
;
16913 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16914 if (display_line (&it
))
16915 last_text_row
= it
.glyph_row
- 1;
16917 /* If point is in a reused row, adjust y and vpos of the cursor
16921 w
->cursor
.vpos
-= nrows_scrolled
;
16922 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16925 /* Give up if point isn't in a row displayed or reused. (This
16926 also handles the case where w->cursor.vpos < nrows_scrolled
16927 after the calls to display_line, which can happen with scroll
16928 margins. See bug#1295.) */
16929 if (w
->cursor
.vpos
< 0)
16931 clear_glyph_matrix (w
->desired_matrix
);
16935 /* Scroll the display. */
16936 run
.current_y
= first_reusable_row
->y
;
16937 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16938 run
.height
= it
.last_visible_y
- run
.current_y
;
16939 dy
= run
.current_y
- run
.desired_y
;
16944 FRAME_RIF (f
)->update_window_begin_hook (w
);
16945 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16946 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16947 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16951 /* Adjust Y positions of reused rows. */
16952 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16953 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16954 max_y
= it
.last_visible_y
;
16955 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16958 row
->visible_height
= row
->height
;
16959 if (row
->y
< min_y
)
16960 row
->visible_height
-= min_y
- row
->y
;
16961 if (row
->y
+ row
->height
> max_y
)
16962 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16963 if (row
->fringe_bitmap_periodic_p
)
16964 row
->redraw_fringe_bitmaps_p
= 1;
16967 /* Scroll the current matrix. */
16968 eassert (nrows_scrolled
> 0);
16969 rotate_matrix (w
->current_matrix
,
16971 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16974 /* Disable rows not reused. */
16975 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16976 row
->enabled_p
= false;
16978 /* Point may have moved to a different line, so we cannot assume that
16979 the previous cursor position is valid; locate the correct row. */
16982 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16984 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16985 && !row
->ends_at_zv_p
;
16989 w
->cursor
.y
= row
->y
;
16991 if (row
< bottom_row
)
16993 /* Can't simply scan the row for point with
16994 bidi-reordered glyph rows. Let set_cursor_from_row
16995 figure out where to put the cursor, and if it fails,
16997 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16999 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
17002 clear_glyph_matrix (w
->desired_matrix
);
17008 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
17009 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17012 && (!BUFFERP (glyph
->object
)
17013 || glyph
->charpos
< PT
);
17017 w
->cursor
.x
+= glyph
->pixel_width
;
17023 /* Adjust window end. A null value of last_text_row means that
17024 the window end is in reused rows which in turn means that
17025 only its vpos can have changed. */
17027 adjust_window_ends (w
, last_text_row
, 0);
17029 w
->window_end_vpos
-= nrows_scrolled
;
17031 w
->window_end_valid
= 0;
17032 w
->desired_matrix
->no_scrolling_p
= 1;
17035 debug_method_add (w
, "try_window_reusing_current_matrix 2");
17045 /************************************************************************
17046 Window redisplay reusing current matrix when buffer has changed
17047 ************************************************************************/
17049 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
17050 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17051 ptrdiff_t *, ptrdiff_t *);
17052 static struct glyph_row
*
17053 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17054 struct glyph_row
*);
17057 /* Return the last row in MATRIX displaying text. If row START is
17058 non-null, start searching with that row. IT gives the dimensions
17059 of the display. Value is null if matrix is empty; otherwise it is
17060 a pointer to the row found. */
17062 static struct glyph_row
*
17063 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17064 struct glyph_row
*start
)
17066 struct glyph_row
*row
, *row_found
;
17068 /* Set row_found to the last row in IT->w's current matrix
17069 displaying text. The loop looks funny but think of partially
17072 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17073 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17075 eassert (row
->enabled_p
);
17077 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17086 /* Return the last row in the current matrix of W that is not affected
17087 by changes at the start of current_buffer that occurred since W's
17088 current matrix was built. Value is null if no such row exists.
17090 BEG_UNCHANGED us the number of characters unchanged at the start of
17091 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17092 first changed character in current_buffer. Characters at positions <
17093 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17094 when the current matrix was built. */
17096 static struct glyph_row
*
17097 find_last_unchanged_at_beg_row (struct window
*w
)
17099 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17100 struct glyph_row
*row
;
17101 struct glyph_row
*row_found
= NULL
;
17102 int yb
= window_text_bottom_y (w
);
17104 /* Find the last row displaying unchanged text. */
17105 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17106 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17107 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17110 if (/* If row ends before first_changed_pos, it is unchanged,
17111 except in some case. */
17112 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17113 /* When row ends in ZV and we write at ZV it is not
17115 && !row
->ends_at_zv_p
17116 /* When first_changed_pos is the end of a continued line,
17117 row is not unchanged because it may be no longer
17119 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17120 && (row
->continued_p
17121 || row
->exact_window_width_line_p
))
17122 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17123 needs to be recomputed, so don't consider this row as
17124 unchanged. This happens when the last line was
17125 bidi-reordered and was killed immediately before this
17126 redisplay cycle. In that case, ROW->end stores the
17127 buffer position of the first visual-order character of
17128 the killed text, which is now beyond ZV. */
17129 && CHARPOS (row
->end
.pos
) <= ZV
)
17132 /* Stop if last visible row. */
17133 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17141 /* Find the first glyph row in the current matrix of W that is not
17142 affected by changes at the end of current_buffer since the
17143 time W's current matrix was built.
17145 Return in *DELTA the number of chars by which buffer positions in
17146 unchanged text at the end of current_buffer must be adjusted.
17148 Return in *DELTA_BYTES the corresponding number of bytes.
17150 Value is null if no such row exists, i.e. all rows are affected by
17153 static struct glyph_row
*
17154 find_first_unchanged_at_end_row (struct window
*w
,
17155 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17157 struct glyph_row
*row
;
17158 struct glyph_row
*row_found
= NULL
;
17160 *delta
= *delta_bytes
= 0;
17162 /* Display must not have been paused, otherwise the current matrix
17163 is not up to date. */
17164 eassert (w
->window_end_valid
);
17166 /* A value of window_end_pos >= END_UNCHANGED means that the window
17167 end is in the range of changed text. If so, there is no
17168 unchanged row at the end of W's current matrix. */
17169 if (w
->window_end_pos
>= END_UNCHANGED
)
17172 /* Set row to the last row in W's current matrix displaying text. */
17173 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17175 /* If matrix is entirely empty, no unchanged row exists. */
17176 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17178 /* The value of row is the last glyph row in the matrix having a
17179 meaningful buffer position in it. The end position of row
17180 corresponds to window_end_pos. This allows us to translate
17181 buffer positions in the current matrix to current buffer
17182 positions for characters not in changed text. */
17184 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17185 ptrdiff_t Z_BYTE_old
=
17186 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17187 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17188 struct glyph_row
*first_text_row
17189 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17191 *delta
= Z
- Z_old
;
17192 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17194 /* Set last_unchanged_pos to the buffer position of the last
17195 character in the buffer that has not been changed. Z is the
17196 index + 1 of the last character in current_buffer, i.e. by
17197 subtracting END_UNCHANGED we get the index of the last
17198 unchanged character, and we have to add BEG to get its buffer
17200 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17201 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17203 /* Search backward from ROW for a row displaying a line that
17204 starts at a minimum position >= last_unchanged_pos_old. */
17205 for (; row
> first_text_row
; --row
)
17207 /* This used to abort, but it can happen.
17208 It is ok to just stop the search instead here. KFS. */
17209 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17212 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17217 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17223 /* Make sure that glyph rows in the current matrix of window W
17224 reference the same glyph memory as corresponding rows in the
17225 frame's frame matrix. This function is called after scrolling W's
17226 current matrix on a terminal frame in try_window_id and
17227 try_window_reusing_current_matrix. */
17230 sync_frame_with_window_matrix_rows (struct window
*w
)
17232 struct frame
*f
= XFRAME (w
->frame
);
17233 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17235 /* Preconditions: W must be a leaf window and full-width. Its frame
17236 must have a frame matrix. */
17237 eassert (BUFFERP (w
->contents
));
17238 eassert (WINDOW_FULL_WIDTH_P (w
));
17239 eassert (!FRAME_WINDOW_P (f
));
17241 /* If W is a full-width window, glyph pointers in W's current matrix
17242 have, by definition, to be the same as glyph pointers in the
17243 corresponding frame matrix. Note that frame matrices have no
17244 marginal areas (see build_frame_matrix). */
17245 window_row
= w
->current_matrix
->rows
;
17246 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17247 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17248 while (window_row
< window_row_end
)
17250 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17251 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17253 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17254 frame_row
->glyphs
[TEXT_AREA
] = start
;
17255 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17256 frame_row
->glyphs
[LAST_AREA
] = end
;
17258 /* Disable frame rows whose corresponding window rows have
17259 been disabled in try_window_id. */
17260 if (!window_row
->enabled_p
)
17261 frame_row
->enabled_p
= false;
17263 ++window_row
, ++frame_row
;
17268 /* Find the glyph row in window W containing CHARPOS. Consider all
17269 rows between START and END (not inclusive). END null means search
17270 all rows to the end of the display area of W. Value is the row
17271 containing CHARPOS or null. */
17274 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17275 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17277 struct glyph_row
*row
= start
;
17278 struct glyph_row
*best_row
= NULL
;
17279 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17282 /* If we happen to start on a header-line, skip that. */
17283 if (row
->mode_line_p
)
17286 if ((end
&& row
>= end
) || !row
->enabled_p
)
17289 last_y
= window_text_bottom_y (w
) - dy
;
17293 /* Give up if we have gone too far. */
17294 if (end
&& row
>= end
)
17296 /* This formerly returned if they were equal.
17297 I think that both quantities are of a "last plus one" type;
17298 if so, when they are equal, the row is within the screen. -- rms. */
17299 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17302 /* If it is in this row, return this row. */
17303 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17304 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17305 /* The end position of a row equals the start
17306 position of the next row. If CHARPOS is there, we
17307 would rather consider it displayed in the next
17308 line, except when this line ends in ZV. */
17309 && !row_for_charpos_p (row
, charpos
)))
17310 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17314 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17315 || (!best_row
&& !row
->continued_p
))
17317 /* In bidi-reordered rows, there could be several rows whose
17318 edges surround CHARPOS, all of these rows belonging to
17319 the same continued line. We need to find the row which
17320 fits CHARPOS the best. */
17321 for (g
= row
->glyphs
[TEXT_AREA
];
17322 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17325 if (!STRINGP (g
->object
))
17327 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17329 mindif
= eabs (g
->charpos
- charpos
);
17331 /* Exact match always wins. */
17338 else if (best_row
&& !row
->continued_p
)
17345 /* Try to redisplay window W by reusing its existing display. W's
17346 current matrix must be up to date when this function is called,
17347 i.e. window_end_valid must be nonzero.
17351 >= 1 if successful, i.e. display has been updated
17353 1 means the changes were in front of a newline that precedes
17354 the window start, and the whole current matrix was reused
17355 2 means the changes were after the last position displayed
17356 in the window, and the whole current matrix was reused
17357 3 means portions of the current matrix were reused, while
17358 some of the screen lines were redrawn
17359 -1 if redisplay with same window start is known not to succeed
17360 0 if otherwise unsuccessful
17362 The following steps are performed:
17364 1. Find the last row in the current matrix of W that is not
17365 affected by changes at the start of current_buffer. If no such row
17368 2. Find the first row in W's current matrix that is not affected by
17369 changes at the end of current_buffer. Maybe there is no such row.
17371 3. Display lines beginning with the row + 1 found in step 1 to the
17372 row found in step 2 or, if step 2 didn't find a row, to the end of
17375 4. If cursor is not known to appear on the window, give up.
17377 5. If display stopped at the row found in step 2, scroll the
17378 display and current matrix as needed.
17380 6. Maybe display some lines at the end of W, if we must. This can
17381 happen under various circumstances, like a partially visible line
17382 becoming fully visible, or because newly displayed lines are displayed
17383 in smaller font sizes.
17385 7. Update W's window end information. */
17388 try_window_id (struct window
*w
)
17390 struct frame
*f
= XFRAME (w
->frame
);
17391 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17392 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17393 struct glyph_row
*last_unchanged_at_beg_row
;
17394 struct glyph_row
*first_unchanged_at_end_row
;
17395 struct glyph_row
*row
;
17396 struct glyph_row
*bottom_row
;
17399 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17401 struct text_pos start_pos
;
17403 int first_unchanged_at_end_vpos
= 0;
17404 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17405 struct text_pos start
;
17406 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17409 if (inhibit_try_window_id
)
17413 /* This is handy for debugging. */
17415 #define GIVE_UP(X) \
17417 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17421 #define GIVE_UP(X) return 0
17424 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17426 /* Don't use this for mini-windows because these can show
17427 messages and mini-buffers, and we don't handle that here. */
17428 if (MINI_WINDOW_P (w
))
17431 /* This flag is used to prevent redisplay optimizations. */
17432 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17435 /* This function's optimizations cannot be used if overlays have
17436 changed in the buffer displayed by the window, so give up if they
17438 if (w
->last_overlay_modified
!= OVERLAY_MODIFF
)
17441 /* Verify that narrowing has not changed.
17442 Also verify that we were not told to prevent redisplay optimizations.
17443 It would be nice to further
17444 reduce the number of cases where this prevents try_window_id. */
17445 if (current_buffer
->clip_changed
17446 || current_buffer
->prevent_redisplay_optimizations_p
)
17449 /* Window must either use window-based redisplay or be full width. */
17450 if (!FRAME_WINDOW_P (f
)
17451 && (!FRAME_LINE_INS_DEL_OK (f
)
17452 || !WINDOW_FULL_WIDTH_P (w
)))
17455 /* Give up if point is known NOT to appear in W. */
17456 if (PT
< CHARPOS (start
))
17459 /* Another way to prevent redisplay optimizations. */
17460 if (w
->last_modified
== 0)
17463 /* Verify that window is not hscrolled. */
17464 if (w
->hscroll
!= 0)
17467 /* Verify that display wasn't paused. */
17468 if (!w
->window_end_valid
)
17471 /* Likewise if highlighting trailing whitespace. */
17472 if (!NILP (Vshow_trailing_whitespace
))
17475 /* Can't use this if overlay arrow position and/or string have
17477 if (overlay_arrows_changed_p ())
17480 /* When word-wrap is on, adding a space to the first word of a
17481 wrapped line can change the wrap position, altering the line
17482 above it. It might be worthwhile to handle this more
17483 intelligently, but for now just redisplay from scratch. */
17484 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17487 /* Under bidi reordering, adding or deleting a character in the
17488 beginning of a paragraph, before the first strong directional
17489 character, can change the base direction of the paragraph (unless
17490 the buffer specifies a fixed paragraph direction), which will
17491 require to redisplay the whole paragraph. It might be worthwhile
17492 to find the paragraph limits and widen the range of redisplayed
17493 lines to that, but for now just give up this optimization and
17494 redisplay from scratch. */
17495 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17496 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17499 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17500 only if buffer has really changed. The reason is that the gap is
17501 initially at Z for freshly visited files. The code below would
17502 set end_unchanged to 0 in that case. */
17503 if (MODIFF
> SAVE_MODIFF
17504 /* This seems to happen sometimes after saving a buffer. */
17505 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17507 if (GPT
- BEG
< BEG_UNCHANGED
)
17508 BEG_UNCHANGED
= GPT
- BEG
;
17509 if (Z
- GPT
< END_UNCHANGED
)
17510 END_UNCHANGED
= Z
- GPT
;
17513 /* The position of the first and last character that has been changed. */
17514 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17515 last_changed_charpos
= Z
- END_UNCHANGED
;
17517 /* If window starts after a line end, and the last change is in
17518 front of that newline, then changes don't affect the display.
17519 This case happens with stealth-fontification. Note that although
17520 the display is unchanged, glyph positions in the matrix have to
17521 be adjusted, of course. */
17522 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17523 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17524 && ((last_changed_charpos
< CHARPOS (start
)
17525 && CHARPOS (start
) == BEGV
)
17526 || (last_changed_charpos
< CHARPOS (start
) - 1
17527 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17529 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17530 struct glyph_row
*r0
;
17532 /* Compute how many chars/bytes have been added to or removed
17533 from the buffer. */
17534 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17535 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17536 Z_delta
= Z
- Z_old
;
17537 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17539 /* Give up if PT is not in the window. Note that it already has
17540 been checked at the start of try_window_id that PT is not in
17541 front of the window start. */
17542 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17545 /* If window start is unchanged, we can reuse the whole matrix
17546 as is, after adjusting glyph positions. No need to compute
17547 the window end again, since its offset from Z hasn't changed. */
17548 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17549 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17550 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17551 /* PT must not be in a partially visible line. */
17552 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17553 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17555 /* Adjust positions in the glyph matrix. */
17556 if (Z_delta
|| Z_delta_bytes
)
17558 struct glyph_row
*r1
17559 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17560 increment_matrix_positions (w
->current_matrix
,
17561 MATRIX_ROW_VPOS (r0
, current_matrix
),
17562 MATRIX_ROW_VPOS (r1
, current_matrix
),
17563 Z_delta
, Z_delta_bytes
);
17566 /* Set the cursor. */
17567 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17569 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17574 /* Handle the case that changes are all below what is displayed in
17575 the window, and that PT is in the window. This shortcut cannot
17576 be taken if ZV is visible in the window, and text has been added
17577 there that is visible in the window. */
17578 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17579 /* ZV is not visible in the window, or there are no
17580 changes at ZV, actually. */
17581 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17582 || first_changed_charpos
== last_changed_charpos
))
17584 struct glyph_row
*r0
;
17586 /* Give up if PT is not in the window. Note that it already has
17587 been checked at the start of try_window_id that PT is not in
17588 front of the window start. */
17589 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17592 /* If window start is unchanged, we can reuse the whole matrix
17593 as is, without changing glyph positions since no text has
17594 been added/removed in front of the window end. */
17595 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17596 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17597 /* PT must not be in a partially visible line. */
17598 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17599 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17601 /* We have to compute the window end anew since text
17602 could have been added/removed after it. */
17603 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17604 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17606 /* Set the cursor. */
17607 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17609 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17614 /* Give up if window start is in the changed area.
17616 The condition used to read
17618 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17620 but why that was tested escapes me at the moment. */
17621 if (CHARPOS (start
) >= first_changed_charpos
17622 && CHARPOS (start
) <= last_changed_charpos
)
17625 /* Check that window start agrees with the start of the first glyph
17626 row in its current matrix. Check this after we know the window
17627 start is not in changed text, otherwise positions would not be
17629 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17630 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17633 /* Give up if the window ends in strings. Overlay strings
17634 at the end are difficult to handle, so don't try. */
17635 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17636 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17639 /* Compute the position at which we have to start displaying new
17640 lines. Some of the lines at the top of the window might be
17641 reusable because they are not displaying changed text. Find the
17642 last row in W's current matrix not affected by changes at the
17643 start of current_buffer. Value is null if changes start in the
17644 first line of window. */
17645 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17646 if (last_unchanged_at_beg_row
)
17648 /* Avoid starting to display in the middle of a character, a TAB
17649 for instance. This is easier than to set up the iterator
17650 exactly, and it's not a frequent case, so the additional
17651 effort wouldn't really pay off. */
17652 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17653 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17654 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17655 --last_unchanged_at_beg_row
;
17657 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17660 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17662 start_pos
= it
.current
.pos
;
17664 /* Start displaying new lines in the desired matrix at the same
17665 vpos we would use in the current matrix, i.e. below
17666 last_unchanged_at_beg_row. */
17667 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17669 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17670 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17672 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17676 /* There are no reusable lines at the start of the window.
17677 Start displaying in the first text line. */
17678 start_display (&it
, w
, start
);
17679 it
.vpos
= it
.first_vpos
;
17680 start_pos
= it
.current
.pos
;
17683 /* Find the first row that is not affected by changes at the end of
17684 the buffer. Value will be null if there is no unchanged row, in
17685 which case we must redisplay to the end of the window. delta
17686 will be set to the value by which buffer positions beginning with
17687 first_unchanged_at_end_row have to be adjusted due to text
17689 first_unchanged_at_end_row
17690 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17691 IF_DEBUG (debug_delta
= delta
);
17692 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17694 /* Set stop_pos to the buffer position up to which we will have to
17695 display new lines. If first_unchanged_at_end_row != NULL, this
17696 is the buffer position of the start of the line displayed in that
17697 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17698 that we don't stop at a buffer position. */
17700 if (first_unchanged_at_end_row
)
17702 eassert (last_unchanged_at_beg_row
== NULL
17703 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17705 /* If this is a continuation line, move forward to the next one
17706 that isn't. Changes in lines above affect this line.
17707 Caution: this may move first_unchanged_at_end_row to a row
17708 not displaying text. */
17709 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17710 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17711 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17712 < it
.last_visible_y
))
17713 ++first_unchanged_at_end_row
;
17715 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17716 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17717 >= it
.last_visible_y
))
17718 first_unchanged_at_end_row
= NULL
;
17721 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17723 first_unchanged_at_end_vpos
17724 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17725 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17728 else if (last_unchanged_at_beg_row
== NULL
)
17734 /* Either there is no unchanged row at the end, or the one we have
17735 now displays text. This is a necessary condition for the window
17736 end pos calculation at the end of this function. */
17737 eassert (first_unchanged_at_end_row
== NULL
17738 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17740 debug_last_unchanged_at_beg_vpos
17741 = (last_unchanged_at_beg_row
17742 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17744 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17746 #endif /* GLYPH_DEBUG */
17749 /* Display new lines. Set last_text_row to the last new line
17750 displayed which has text on it, i.e. might end up as being the
17751 line where the window_end_vpos is. */
17752 w
->cursor
.vpos
= -1;
17753 last_text_row
= NULL
;
17754 overlay_arrow_seen
= 0;
17755 while (it
.current_y
< it
.last_visible_y
17756 && !f
->fonts_changed
17757 && (first_unchanged_at_end_row
== NULL
17758 || IT_CHARPOS (it
) < stop_pos
))
17760 if (display_line (&it
))
17761 last_text_row
= it
.glyph_row
- 1;
17764 if (f
->fonts_changed
)
17768 /* Compute differences in buffer positions, y-positions etc. for
17769 lines reused at the bottom of the window. Compute what we can
17771 if (first_unchanged_at_end_row
17772 /* No lines reused because we displayed everything up to the
17773 bottom of the window. */
17774 && it
.current_y
< it
.last_visible_y
)
17777 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17779 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17780 run
.current_y
= first_unchanged_at_end_row
->y
;
17781 run
.desired_y
= run
.current_y
+ dy
;
17782 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17786 delta
= delta_bytes
= dvpos
= dy
17787 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17788 first_unchanged_at_end_row
= NULL
;
17790 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
17793 /* Find the cursor if not already found. We have to decide whether
17794 PT will appear on this window (it sometimes doesn't, but this is
17795 not a very frequent case.) This decision has to be made before
17796 the current matrix is altered. A value of cursor.vpos < 0 means
17797 that PT is either in one of the lines beginning at
17798 first_unchanged_at_end_row or below the window. Don't care for
17799 lines that might be displayed later at the window end; as
17800 mentioned, this is not a frequent case. */
17801 if (w
->cursor
.vpos
< 0)
17803 /* Cursor in unchanged rows at the top? */
17804 if (PT
< CHARPOS (start_pos
)
17805 && last_unchanged_at_beg_row
)
17807 row
= row_containing_pos (w
, PT
,
17808 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17809 last_unchanged_at_beg_row
+ 1, 0);
17811 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17814 /* Start from first_unchanged_at_end_row looking for PT. */
17815 else if (first_unchanged_at_end_row
)
17817 row
= row_containing_pos (w
, PT
- delta
,
17818 first_unchanged_at_end_row
, NULL
, 0);
17820 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17821 delta_bytes
, dy
, dvpos
);
17824 /* Give up if cursor was not found. */
17825 if (w
->cursor
.vpos
< 0)
17827 clear_glyph_matrix (w
->desired_matrix
);
17832 /* Don't let the cursor end in the scroll margins. */
17834 int this_scroll_margin
, cursor_height
;
17835 int frame_line_height
= default_line_pixel_height (w
);
17836 int window_total_lines
17837 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17839 this_scroll_margin
=
17840 max (0, min (scroll_margin
, window_total_lines
/ 4));
17841 this_scroll_margin
*= frame_line_height
;
17842 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17844 if ((w
->cursor
.y
< this_scroll_margin
17845 && CHARPOS (start
) > BEGV
)
17846 /* Old redisplay didn't take scroll margin into account at the bottom,
17847 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17848 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17849 ? cursor_height
+ this_scroll_margin
17850 : 1)) > it
.last_visible_y
)
17852 w
->cursor
.vpos
= -1;
17853 clear_glyph_matrix (w
->desired_matrix
);
17858 /* Scroll the display. Do it before changing the current matrix so
17859 that xterm.c doesn't get confused about where the cursor glyph is
17861 if (dy
&& run
.height
)
17865 if (FRAME_WINDOW_P (f
))
17867 FRAME_RIF (f
)->update_window_begin_hook (w
);
17868 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17869 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17870 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17874 /* Terminal frame. In this case, dvpos gives the number of
17875 lines to scroll by; dvpos < 0 means scroll up. */
17877 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17878 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17879 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17880 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17881 + window_internal_height (w
));
17883 #if defined (HAVE_GPM) || defined (MSDOS)
17884 x_clear_window_mouse_face (w
);
17886 /* Perform the operation on the screen. */
17889 /* Scroll last_unchanged_at_beg_row to the end of the
17890 window down dvpos lines. */
17891 set_terminal_window (f
, end
);
17893 /* On dumb terminals delete dvpos lines at the end
17894 before inserting dvpos empty lines. */
17895 if (!FRAME_SCROLL_REGION_OK (f
))
17896 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17898 /* Insert dvpos empty lines in front of
17899 last_unchanged_at_beg_row. */
17900 ins_del_lines (f
, from
, dvpos
);
17902 else if (dvpos
< 0)
17904 /* Scroll up last_unchanged_at_beg_vpos to the end of
17905 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17906 set_terminal_window (f
, end
);
17908 /* Delete dvpos lines in front of
17909 last_unchanged_at_beg_vpos. ins_del_lines will set
17910 the cursor to the given vpos and emit |dvpos| delete
17912 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17914 /* On a dumb terminal insert dvpos empty lines at the
17916 if (!FRAME_SCROLL_REGION_OK (f
))
17917 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17920 set_terminal_window (f
, 0);
17926 /* Shift reused rows of the current matrix to the right position.
17927 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17929 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17930 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17933 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17934 bottom_vpos
, dvpos
);
17935 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17938 else if (dvpos
> 0)
17940 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17941 bottom_vpos
, dvpos
);
17942 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17943 first_unchanged_at_end_vpos
+ dvpos
);
17946 /* For frame-based redisplay, make sure that current frame and window
17947 matrix are in sync with respect to glyph memory. */
17948 if (!FRAME_WINDOW_P (f
))
17949 sync_frame_with_window_matrix_rows (w
);
17951 /* Adjust buffer positions in reused rows. */
17952 if (delta
|| delta_bytes
)
17953 increment_matrix_positions (current_matrix
,
17954 first_unchanged_at_end_vpos
+ dvpos
,
17955 bottom_vpos
, delta
, delta_bytes
);
17957 /* Adjust Y positions. */
17959 shift_glyph_matrix (w
, current_matrix
,
17960 first_unchanged_at_end_vpos
+ dvpos
,
17963 if (first_unchanged_at_end_row
)
17965 first_unchanged_at_end_row
+= dvpos
;
17966 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17967 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17968 first_unchanged_at_end_row
= NULL
;
17971 /* If scrolling up, there may be some lines to display at the end of
17973 last_text_row_at_end
= NULL
;
17976 /* Scrolling up can leave for example a partially visible line
17977 at the end of the window to be redisplayed. */
17978 /* Set last_row to the glyph row in the current matrix where the
17979 window end line is found. It has been moved up or down in
17980 the matrix by dvpos. */
17981 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17982 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17984 /* If last_row is the window end line, it should display text. */
17985 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17987 /* If window end line was partially visible before, begin
17988 displaying at that line. Otherwise begin displaying with the
17989 line following it. */
17990 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17992 init_to_row_start (&it
, w
, last_row
);
17993 it
.vpos
= last_vpos
;
17994 it
.current_y
= last_row
->y
;
17998 init_to_row_end (&it
, w
, last_row
);
17999 it
.vpos
= 1 + last_vpos
;
18000 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
18004 /* We may start in a continuation line. If so, we have to
18005 get the right continuation_lines_width and current_x. */
18006 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
18007 it
.hpos
= it
.current_x
= 0;
18009 /* Display the rest of the lines at the window end. */
18010 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
18011 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
18013 /* Is it always sure that the display agrees with lines in
18014 the current matrix? I don't think so, so we mark rows
18015 displayed invalid in the current matrix by setting their
18016 enabled_p flag to zero. */
18017 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
18018 if (display_line (&it
))
18019 last_text_row_at_end
= it
.glyph_row
- 1;
18023 /* Update window_end_pos and window_end_vpos. */
18024 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
18026 /* Window end line if one of the preserved rows from the current
18027 matrix. Set row to the last row displaying text in current
18028 matrix starting at first_unchanged_at_end_row, after
18030 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18031 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
18032 first_unchanged_at_end_row
);
18033 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
18034 adjust_window_ends (w
, row
, 1);
18035 eassert (w
->window_end_bytepos
>= 0);
18036 IF_DEBUG (debug_method_add (w
, "A"));
18038 else if (last_text_row_at_end
)
18040 adjust_window_ends (w
, last_text_row_at_end
, 0);
18041 eassert (w
->window_end_bytepos
>= 0);
18042 IF_DEBUG (debug_method_add (w
, "B"));
18044 else if (last_text_row
)
18046 /* We have displayed either to the end of the window or at the
18047 end of the window, i.e. the last row with text is to be found
18048 in the desired matrix. */
18049 adjust_window_ends (w
, last_text_row
, 0);
18050 eassert (w
->window_end_bytepos
>= 0);
18052 else if (first_unchanged_at_end_row
== NULL
18053 && last_text_row
== NULL
18054 && last_text_row_at_end
== NULL
)
18056 /* Displayed to end of window, but no line containing text was
18057 displayed. Lines were deleted at the end of the window. */
18058 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
18059 int vpos
= w
->window_end_vpos
;
18060 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
18061 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18064 row
== NULL
&& vpos
>= first_vpos
;
18065 --vpos
, --current_row
, --desired_row
)
18067 if (desired_row
->enabled_p
)
18069 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18072 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18076 eassert (row
!= NULL
);
18077 w
->window_end_vpos
= vpos
+ 1;
18078 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18079 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18080 eassert (w
->window_end_bytepos
>= 0);
18081 IF_DEBUG (debug_method_add (w
, "C"));
18086 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18087 debug_end_vpos
= w
->window_end_vpos
));
18089 /* Record that display has not been completed. */
18090 w
->window_end_valid
= 0;
18091 w
->desired_matrix
->no_scrolling_p
= 1;
18099 /***********************************************************************
18100 More debugging support
18101 ***********************************************************************/
18105 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18106 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18107 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18110 /* Dump the contents of glyph matrix MATRIX on stderr.
18112 GLYPHS 0 means don't show glyph contents.
18113 GLYPHS 1 means show glyphs in short form
18114 GLYPHS > 1 means show glyphs in long form. */
18117 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18120 for (i
= 0; i
< matrix
->nrows
; ++i
)
18121 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18125 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18126 the glyph row and area where the glyph comes from. */
18129 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18131 if (glyph
->type
== CHAR_GLYPH
18132 || glyph
->type
== GLYPHLESS_GLYPH
)
18135 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18136 glyph
- row
->glyphs
[TEXT_AREA
],
18137 (glyph
->type
== CHAR_GLYPH
18141 (BUFFERP (glyph
->object
)
18143 : (STRINGP (glyph
->object
)
18145 : (INTEGERP (glyph
->object
)
18148 glyph
->pixel_width
,
18150 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18154 glyph
->left_box_line_p
,
18155 glyph
->right_box_line_p
);
18157 else if (glyph
->type
== STRETCH_GLYPH
)
18160 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18161 glyph
- row
->glyphs
[TEXT_AREA
],
18164 (BUFFERP (glyph
->object
)
18166 : (STRINGP (glyph
->object
)
18168 : (INTEGERP (glyph
->object
)
18171 glyph
->pixel_width
,
18175 glyph
->left_box_line_p
,
18176 glyph
->right_box_line_p
);
18178 else if (glyph
->type
== IMAGE_GLYPH
)
18181 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18182 glyph
- row
->glyphs
[TEXT_AREA
],
18185 (BUFFERP (glyph
->object
)
18187 : (STRINGP (glyph
->object
)
18189 : (INTEGERP (glyph
->object
)
18192 glyph
->pixel_width
,
18196 glyph
->left_box_line_p
,
18197 glyph
->right_box_line_p
);
18199 else if (glyph
->type
== COMPOSITE_GLYPH
)
18202 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18203 glyph
- row
->glyphs
[TEXT_AREA
],
18206 (BUFFERP (glyph
->object
)
18208 : (STRINGP (glyph
->object
)
18210 : (INTEGERP (glyph
->object
)
18213 glyph
->pixel_width
,
18215 if (glyph
->u
.cmp
.automatic
)
18218 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18219 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18221 glyph
->left_box_line_p
,
18222 glyph
->right_box_line_p
);
18227 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18228 GLYPHS 0 means don't show glyph contents.
18229 GLYPHS 1 means show glyphs in short form
18230 GLYPHS > 1 means show glyphs in long form. */
18233 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18237 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18238 fprintf (stderr
, "==============================================================================\n");
18240 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18241 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18243 MATRIX_ROW_START_CHARPOS (row
),
18244 MATRIX_ROW_END_CHARPOS (row
),
18245 row
->used
[TEXT_AREA
],
18246 row
->contains_overlapping_glyphs_p
,
18248 row
->truncated_on_left_p
,
18249 row
->truncated_on_right_p
,
18251 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18252 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18255 row
->ends_in_middle_of_char_p
,
18256 row
->starts_in_middle_of_char_p
,
18262 row
->visible_height
,
18265 /* The next 3 lines should align to "Start" in the header. */
18266 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18267 row
->end
.overlay_string_index
,
18268 row
->continuation_lines_width
);
18269 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18270 CHARPOS (row
->start
.string_pos
),
18271 CHARPOS (row
->end
.string_pos
));
18272 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18273 row
->end
.dpvec_index
);
18280 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18282 struct glyph
*glyph
= row
->glyphs
[area
];
18283 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18285 /* Glyph for a line end in text. */
18286 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18289 if (glyph
< glyph_end
)
18290 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18292 for (; glyph
< glyph_end
; ++glyph
)
18293 dump_glyph (row
, glyph
, area
);
18296 else if (glyphs
== 1)
18300 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18302 char *s
= alloca (row
->used
[area
] + 4);
18305 for (i
= 0; i
< row
->used
[area
]; ++i
)
18307 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18308 if (i
== row
->used
[area
] - 1
18309 && area
== TEXT_AREA
18310 && INTEGERP (glyph
->object
)
18311 && glyph
->type
== CHAR_GLYPH
18312 && glyph
->u
.ch
== ' ')
18314 strcpy (&s
[i
], "[\\n]");
18317 else if (glyph
->type
== CHAR_GLYPH
18318 && glyph
->u
.ch
< 0x80
18319 && glyph
->u
.ch
>= ' ')
18320 s
[i
] = glyph
->u
.ch
;
18326 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18332 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18333 Sdump_glyph_matrix
, 0, 1, "p",
18334 doc
: /* Dump the current matrix of the selected window to stderr.
18335 Shows contents of glyph row structures. With non-nil
18336 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18337 glyphs in short form, otherwise show glyphs in long form. */)
18338 (Lisp_Object glyphs
)
18340 struct window
*w
= XWINDOW (selected_window
);
18341 struct buffer
*buffer
= XBUFFER (w
->contents
);
18343 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18344 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18345 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18346 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18347 fprintf (stderr
, "=============================================\n");
18348 dump_glyph_matrix (w
->current_matrix
,
18349 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18354 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18355 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18358 struct frame
*f
= XFRAME (selected_frame
);
18359 dump_glyph_matrix (f
->current_matrix
, 1);
18364 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18365 doc
: /* Dump glyph row ROW to stderr.
18366 GLYPH 0 means don't dump glyphs.
18367 GLYPH 1 means dump glyphs in short form.
18368 GLYPH > 1 or omitted means dump glyphs in long form. */)
18369 (Lisp_Object row
, Lisp_Object glyphs
)
18371 struct glyph_matrix
*matrix
;
18374 CHECK_NUMBER (row
);
18375 matrix
= XWINDOW (selected_window
)->current_matrix
;
18377 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18378 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18380 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18385 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18386 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18387 GLYPH 0 means don't dump glyphs.
18388 GLYPH 1 means dump glyphs in short form.
18389 GLYPH > 1 or omitted means dump glyphs in long form.
18391 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18393 (Lisp_Object row
, Lisp_Object glyphs
)
18395 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18396 struct frame
*sf
= SELECTED_FRAME ();
18397 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18400 CHECK_NUMBER (row
);
18402 if (vpos
>= 0 && vpos
< m
->nrows
)
18403 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18404 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18410 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18411 doc
: /* Toggle tracing of redisplay.
18412 With ARG, turn tracing on if and only if ARG is positive. */)
18416 trace_redisplay_p
= !trace_redisplay_p
;
18419 arg
= Fprefix_numeric_value (arg
);
18420 trace_redisplay_p
= XINT (arg
) > 0;
18427 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18428 doc
: /* Like `format', but print result to stderr.
18429 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18430 (ptrdiff_t nargs
, Lisp_Object
*args
)
18432 Lisp_Object s
= Fformat (nargs
, args
);
18433 fprintf (stderr
, "%s", SDATA (s
));
18437 #endif /* GLYPH_DEBUG */
18441 /***********************************************************************
18442 Building Desired Matrix Rows
18443 ***********************************************************************/
18445 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18446 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18448 static struct glyph_row
*
18449 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18451 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18452 struct buffer
*buffer
= XBUFFER (w
->contents
);
18453 struct buffer
*old
= current_buffer
;
18454 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18455 int arrow_len
= SCHARS (overlay_arrow_string
);
18456 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18457 const unsigned char *p
;
18460 int n_glyphs_before
;
18462 set_buffer_temp (buffer
);
18463 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18464 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18465 SET_TEXT_POS (it
.position
, 0, 0);
18467 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18469 while (p
< arrow_end
)
18471 Lisp_Object face
, ilisp
;
18473 /* Get the next character. */
18475 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18478 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18479 if (! ASCII_CHAR_P (it
.c
))
18480 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18484 /* Get its face. */
18485 ilisp
= make_number (p
- arrow_string
);
18486 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18487 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18489 /* Compute its width, get its glyphs. */
18490 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18491 SET_TEXT_POS (it
.position
, -1, -1);
18492 PRODUCE_GLYPHS (&it
);
18494 /* If this character doesn't fit any more in the line, we have
18495 to remove some glyphs. */
18496 if (it
.current_x
> it
.last_visible_x
)
18498 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18503 set_buffer_temp (old
);
18504 return it
.glyph_row
;
18508 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18509 glyphs to insert is determined by produce_special_glyphs. */
18512 insert_left_trunc_glyphs (struct it
*it
)
18514 struct it truncate_it
;
18515 struct glyph
*from
, *end
, *to
, *toend
;
18517 eassert (!FRAME_WINDOW_P (it
->f
)
18518 || (!it
->glyph_row
->reversed_p
18519 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18520 || (it
->glyph_row
->reversed_p
18521 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18523 /* Get the truncation glyphs. */
18525 truncate_it
.current_x
= 0;
18526 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18527 truncate_it
.glyph_row
= &scratch_glyph_row
;
18528 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18529 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18530 truncate_it
.object
= make_number (0);
18531 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18533 /* Overwrite glyphs from IT with truncation glyphs. */
18534 if (!it
->glyph_row
->reversed_p
)
18536 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18538 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18539 end
= from
+ tused
;
18540 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18541 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18542 if (FRAME_WINDOW_P (it
->f
))
18544 /* On GUI frames, when variable-size fonts are displayed,
18545 the truncation glyphs may need more pixels than the row's
18546 glyphs they overwrite. We overwrite more glyphs to free
18547 enough screen real estate, and enlarge the stretch glyph
18548 on the right (see display_line), if there is one, to
18549 preserve the screen position of the truncation glyphs on
18552 struct glyph
*g
= to
;
18555 /* The first glyph could be partially visible, in which case
18556 it->glyph_row->x will be negative. But we want the left
18557 truncation glyphs to be aligned at the left margin of the
18558 window, so we override the x coordinate at which the row
18560 it
->glyph_row
->x
= 0;
18561 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18563 w
+= g
->pixel_width
;
18566 if (g
- to
- tused
> 0)
18568 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18569 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18571 used
= it
->glyph_row
->used
[TEXT_AREA
];
18572 if (it
->glyph_row
->truncated_on_right_p
18573 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18574 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18577 int extra
= w
- it
->truncation_pixel_width
;
18579 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18586 /* There may be padding glyphs left over. Overwrite them too. */
18587 if (!FRAME_WINDOW_P (it
->f
))
18589 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18591 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18598 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18602 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18604 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18605 that back to front. */
18606 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18607 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18608 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18609 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18610 if (FRAME_WINDOW_P (it
->f
))
18613 struct glyph
*g
= to
;
18615 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18617 w
+= g
->pixel_width
;
18620 if (to
- g
- tused
> 0)
18622 if (it
->glyph_row
->truncated_on_right_p
18623 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18624 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18626 int extra
= w
- it
->truncation_pixel_width
;
18628 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18632 while (from
>= end
&& to
>= toend
)
18634 if (!FRAME_WINDOW_P (it
->f
))
18636 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18639 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18640 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18641 while (from
>= end
&& to
>= toend
)
18647 /* Need to free some room before prepending additional
18649 int move_by
= from
- end
+ 1;
18650 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18651 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18653 for ( ; g
>= g0
; g
--)
18655 while (from
>= end
)
18657 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18662 /* Compute the hash code for ROW. */
18664 row_hash (struct glyph_row
*row
)
18667 unsigned hashval
= 0;
18669 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18670 for (k
= 0; k
< row
->used
[area
]; ++k
)
18671 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18672 + row
->glyphs
[area
][k
].u
.val
18673 + row
->glyphs
[area
][k
].face_id
18674 + row
->glyphs
[area
][k
].padding_p
18675 + (row
->glyphs
[area
][k
].type
<< 2));
18680 /* Compute the pixel height and width of IT->glyph_row.
18682 Most of the time, ascent and height of a display line will be equal
18683 to the max_ascent and max_height values of the display iterator
18684 structure. This is not the case if
18686 1. We hit ZV without displaying anything. In this case, max_ascent
18687 and max_height will be zero.
18689 2. We have some glyphs that don't contribute to the line height.
18690 (The glyph row flag contributes_to_line_height_p is for future
18691 pixmap extensions).
18693 The first case is easily covered by using default values because in
18694 these cases, the line height does not really matter, except that it
18695 must not be zero. */
18698 compute_line_metrics (struct it
*it
)
18700 struct glyph_row
*row
= it
->glyph_row
;
18702 if (FRAME_WINDOW_P (it
->f
))
18704 int i
, min_y
, max_y
;
18706 /* The line may consist of one space only, that was added to
18707 place the cursor on it. If so, the row's height hasn't been
18709 if (row
->height
== 0)
18711 if (it
->max_ascent
+ it
->max_descent
== 0)
18712 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18713 row
->ascent
= it
->max_ascent
;
18714 row
->height
= it
->max_ascent
+ it
->max_descent
;
18715 row
->phys_ascent
= it
->max_phys_ascent
;
18716 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18717 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18720 /* Compute the width of this line. */
18721 row
->pixel_width
= row
->x
;
18722 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18723 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18725 eassert (row
->pixel_width
>= 0);
18726 eassert (row
->ascent
>= 0 && row
->height
> 0);
18728 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18729 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18731 /* If first line's physical ascent is larger than its logical
18732 ascent, use the physical ascent, and make the row taller.
18733 This makes accented characters fully visible. */
18734 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18735 && row
->phys_ascent
> row
->ascent
)
18737 row
->height
+= row
->phys_ascent
- row
->ascent
;
18738 row
->ascent
= row
->phys_ascent
;
18741 /* Compute how much of the line is visible. */
18742 row
->visible_height
= row
->height
;
18744 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18745 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18747 if (row
->y
< min_y
)
18748 row
->visible_height
-= min_y
- row
->y
;
18749 if (row
->y
+ row
->height
> max_y
)
18750 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18754 row
->pixel_width
= row
->used
[TEXT_AREA
];
18755 if (row
->continued_p
)
18756 row
->pixel_width
-= it
->continuation_pixel_width
;
18757 else if (row
->truncated_on_right_p
)
18758 row
->pixel_width
-= it
->truncation_pixel_width
;
18759 row
->ascent
= row
->phys_ascent
= 0;
18760 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18761 row
->extra_line_spacing
= 0;
18764 /* Compute a hash code for this row. */
18765 row
->hash
= row_hash (row
);
18767 it
->max_ascent
= it
->max_descent
= 0;
18768 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18772 /* Append one space to the glyph row of iterator IT if doing a
18773 window-based redisplay. The space has the same face as
18774 IT->face_id. Value is non-zero if a space was added.
18776 This function is called to make sure that there is always one glyph
18777 at the end of a glyph row that the cursor can be set on under
18778 window-systems. (If there weren't such a glyph we would not know
18779 how wide and tall a box cursor should be displayed).
18781 At the same time this space let's a nicely handle clearing to the
18782 end of the line if the row ends in italic text. */
18785 append_space_for_newline (struct it
*it
, int default_face_p
)
18787 if (FRAME_WINDOW_P (it
->f
))
18789 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18791 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18792 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18794 /* Save some values that must not be changed.
18795 Must save IT->c and IT->len because otherwise
18796 ITERATOR_AT_END_P wouldn't work anymore after
18797 append_space_for_newline has been called. */
18798 enum display_element_type saved_what
= it
->what
;
18799 int saved_c
= it
->c
, saved_len
= it
->len
;
18800 int saved_char_to_display
= it
->char_to_display
;
18801 int saved_x
= it
->current_x
;
18802 int saved_face_id
= it
->face_id
;
18803 int saved_box_end
= it
->end_of_box_run_p
;
18804 struct text_pos saved_pos
;
18805 Lisp_Object saved_object
;
18808 saved_object
= it
->object
;
18809 saved_pos
= it
->position
;
18811 it
->what
= IT_CHARACTER
;
18812 memset (&it
->position
, 0, sizeof it
->position
);
18813 it
->object
= make_number (0);
18814 it
->c
= it
->char_to_display
= ' ';
18817 /* If the default face was remapped, be sure to use the
18818 remapped face for the appended newline. */
18819 if (default_face_p
)
18820 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18821 else if (it
->face_before_selective_p
)
18822 it
->face_id
= it
->saved_face_id
;
18823 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18824 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18825 /* In R2L rows, we will prepend a stretch glyph that will
18826 have the end_of_box_run_p flag set for it, so there's no
18827 need for the appended newline glyph to have that flag
18829 if (it
->glyph_row
->reversed_p
18830 /* But if the appended newline glyph goes all the way to
18831 the end of the row, there will be no stretch glyph,
18832 so leave the box flag set. */
18833 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18834 it
->end_of_box_run_p
= 0;
18836 PRODUCE_GLYPHS (it
);
18838 it
->override_ascent
= -1;
18839 it
->constrain_row_ascent_descent_p
= 0;
18840 it
->current_x
= saved_x
;
18841 it
->object
= saved_object
;
18842 it
->position
= saved_pos
;
18843 it
->what
= saved_what
;
18844 it
->face_id
= saved_face_id
;
18845 it
->len
= saved_len
;
18847 it
->char_to_display
= saved_char_to_display
;
18848 it
->end_of_box_run_p
= saved_box_end
;
18857 /* Extend the face of the last glyph in the text area of IT->glyph_row
18858 to the end of the display line. Called from display_line. If the
18859 glyph row is empty, add a space glyph to it so that we know the
18860 face to draw. Set the glyph row flag fill_line_p. If the glyph
18861 row is R2L, prepend a stretch glyph to cover the empty space to the
18862 left of the leftmost glyph. */
18865 extend_face_to_end_of_line (struct it
*it
)
18867 struct face
*face
, *default_face
;
18868 struct frame
*f
= it
->f
;
18870 /* If line is already filled, do nothing. Non window-system frames
18871 get a grace of one more ``pixel'' because their characters are
18872 1-``pixel'' wide, so they hit the equality too early. This grace
18873 is needed only for R2L rows that are not continued, to produce
18874 one extra blank where we could display the cursor. */
18875 if ((it
->current_x
>= it
->last_visible_x
18876 + (!FRAME_WINDOW_P (f
)
18877 && it
->glyph_row
->reversed_p
18878 && !it
->glyph_row
->continued_p
))
18879 /* If the window has display margins, we will need to extend
18880 their face even if the text area is filled. */
18881 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
18882 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
18885 /* The default face, possibly remapped. */
18886 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18888 /* Face extension extends the background and box of IT->face_id
18889 to the end of the line. If the background equals the background
18890 of the frame, we don't have to do anything. */
18891 if (it
->face_before_selective_p
)
18892 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18894 face
= FACE_FROM_ID (f
, it
->face_id
);
18896 if (FRAME_WINDOW_P (f
)
18897 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18898 && face
->box
== FACE_NO_BOX
18899 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18900 #ifdef HAVE_WINDOW_SYSTEM
18903 && !it
->glyph_row
->reversed_p
)
18906 /* Set the glyph row flag indicating that the face of the last glyph
18907 in the text area has to be drawn to the end of the text area. */
18908 it
->glyph_row
->fill_line_p
= 1;
18910 /* If current character of IT is not ASCII, make sure we have the
18911 ASCII face. This will be automatically undone the next time
18912 get_next_display_element returns a multibyte character. Note
18913 that the character will always be single byte in unibyte
18915 if (!ASCII_CHAR_P (it
->c
))
18917 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18920 if (FRAME_WINDOW_P (f
))
18922 /* If the row is empty, add a space with the current face of IT,
18923 so that we know which face to draw. */
18924 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18926 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18927 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18928 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18930 /* Mode line and the header line don't have margins, and
18931 likewise the frame's tool-bar window, if there is any. */
18932 if (!(it
->glyph_row
->mode_line_p
18933 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18934 || (WINDOWP (f
->tool_bar_window
)
18935 && it
->w
== XWINDOW (f
->tool_bar_window
))
18939 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
18940 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
18942 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
18943 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
=
18945 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
18947 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
18948 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
18950 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
18951 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
=
18953 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
18956 #ifdef HAVE_WINDOW_SYSTEM
18957 if (it
->glyph_row
->reversed_p
)
18959 /* Prepend a stretch glyph to the row, such that the
18960 rightmost glyph will be drawn flushed all the way to the
18961 right margin of the window. The stretch glyph that will
18962 occupy the empty space, if any, to the left of the
18964 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18965 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18966 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18968 int row_width
, stretch_ascent
, stretch_width
;
18969 struct text_pos saved_pos
;
18970 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18972 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18973 row_width
+= g
->pixel_width
;
18974 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18975 if (stretch_width
> 0)
18978 (((it
->ascent
+ it
->descent
)
18979 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18980 saved_pos
= it
->position
;
18981 memset (&it
->position
, 0, sizeof it
->position
);
18982 saved_avoid_cursor
= it
->avoid_cursor_p
;
18983 it
->avoid_cursor_p
= 1;
18984 saved_face_id
= it
->face_id
;
18985 saved_box_start
= it
->start_of_box_run_p
;
18986 /* The last row's stretch glyph should get the default
18987 face, to avoid painting the rest of the window with
18988 the region face, if the region ends at ZV. */
18989 if (it
->glyph_row
->ends_at_zv_p
)
18990 it
->face_id
= default_face
->id
;
18992 it
->face_id
= face
->id
;
18993 it
->start_of_box_run_p
= 0;
18994 append_stretch_glyph (it
, make_number (0), stretch_width
,
18995 it
->ascent
+ it
->descent
, stretch_ascent
);
18996 it
->position
= saved_pos
;
18997 it
->avoid_cursor_p
= saved_avoid_cursor
;
18998 it
->face_id
= saved_face_id
;
18999 it
->start_of_box_run_p
= saved_box_start
;
19002 #endif /* HAVE_WINDOW_SYSTEM */
19006 /* Save some values that must not be changed. */
19007 int saved_x
= it
->current_x
;
19008 struct text_pos saved_pos
;
19009 Lisp_Object saved_object
;
19010 enum display_element_type saved_what
= it
->what
;
19011 int saved_face_id
= it
->face_id
;
19013 saved_object
= it
->object
;
19014 saved_pos
= it
->position
;
19016 it
->what
= IT_CHARACTER
;
19017 memset (&it
->position
, 0, sizeof it
->position
);
19018 it
->object
= make_number (0);
19019 it
->c
= it
->char_to_display
= ' ';
19022 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19023 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19024 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19025 && !it
->glyph_row
->mode_line_p
19026 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19028 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
19029 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
19031 for (it
->current_x
= 0; g
< e
; g
++)
19032 it
->current_x
+= g
->pixel_width
;
19034 it
->area
= LEFT_MARGIN_AREA
;
19035 it
->face_id
= default_face
->id
;
19036 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19037 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19039 PRODUCE_GLYPHS (it
);
19040 /* term.c:produce_glyphs advances it->current_x only for
19042 it
->current_x
+= it
->pixel_width
;
19045 it
->current_x
= saved_x
;
19046 it
->area
= TEXT_AREA
;
19049 /* The last row's blank glyphs should get the default face, to
19050 avoid painting the rest of the window with the region face,
19051 if the region ends at ZV. */
19052 if (it
->glyph_row
->ends_at_zv_p
)
19053 it
->face_id
= default_face
->id
;
19055 it
->face_id
= face
->id
;
19056 PRODUCE_GLYPHS (it
);
19058 while (it
->current_x
<= it
->last_visible_x
)
19059 PRODUCE_GLYPHS (it
);
19061 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19062 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19063 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19064 && !it
->glyph_row
->mode_line_p
19065 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19067 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
19068 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19070 for ( ; g
< e
; g
++)
19071 it
->current_x
+= g
->pixel_width
;
19073 it
->area
= RIGHT_MARGIN_AREA
;
19074 it
->face_id
= default_face
->id
;
19075 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19076 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19078 PRODUCE_GLYPHS (it
);
19079 it
->current_x
+= it
->pixel_width
;
19082 it
->area
= TEXT_AREA
;
19085 /* Don't count these blanks really. It would let us insert a left
19086 truncation glyph below and make us set the cursor on them, maybe. */
19087 it
->current_x
= saved_x
;
19088 it
->object
= saved_object
;
19089 it
->position
= saved_pos
;
19090 it
->what
= saved_what
;
19091 it
->face_id
= saved_face_id
;
19096 /* Value is non-zero if text starting at CHARPOS in current_buffer is
19097 trailing whitespace. */
19100 trailing_whitespace_p (ptrdiff_t charpos
)
19102 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19105 while (bytepos
< ZV_BYTE
19106 && (c
= FETCH_CHAR (bytepos
),
19107 c
== ' ' || c
== '\t'))
19110 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19112 if (bytepos
!= PT_BYTE
)
19119 /* Highlight trailing whitespace, if any, in ROW. */
19122 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19124 int used
= row
->used
[TEXT_AREA
];
19128 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19129 struct glyph
*glyph
= start
+ used
- 1;
19131 if (row
->reversed_p
)
19133 /* Right-to-left rows need to be processed in the opposite
19134 direction, so swap the edge pointers. */
19136 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19139 /* Skip over glyphs inserted to display the cursor at the
19140 end of a line, for extending the face of the last glyph
19141 to the end of the line on terminals, and for truncation
19142 and continuation glyphs. */
19143 if (!row
->reversed_p
)
19145 while (glyph
>= start
19146 && glyph
->type
== CHAR_GLYPH
19147 && INTEGERP (glyph
->object
))
19152 while (glyph
<= start
19153 && glyph
->type
== CHAR_GLYPH
19154 && INTEGERP (glyph
->object
))
19158 /* If last glyph is a space or stretch, and it's trailing
19159 whitespace, set the face of all trailing whitespace glyphs in
19160 IT->glyph_row to `trailing-whitespace'. */
19161 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19162 && BUFFERP (glyph
->object
)
19163 && (glyph
->type
== STRETCH_GLYPH
19164 || (glyph
->type
== CHAR_GLYPH
19165 && glyph
->u
.ch
== ' '))
19166 && trailing_whitespace_p (glyph
->charpos
))
19168 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
19172 if (!row
->reversed_p
)
19174 while (glyph
>= start
19175 && BUFFERP (glyph
->object
)
19176 && (glyph
->type
== STRETCH_GLYPH
19177 || (glyph
->type
== CHAR_GLYPH
19178 && glyph
->u
.ch
== ' ')))
19179 (glyph
--)->face_id
= face_id
;
19183 while (glyph
<= start
19184 && BUFFERP (glyph
->object
)
19185 && (glyph
->type
== STRETCH_GLYPH
19186 || (glyph
->type
== CHAR_GLYPH
19187 && glyph
->u
.ch
== ' ')))
19188 (glyph
++)->face_id
= face_id
;
19195 /* Value is non-zero if glyph row ROW should be
19196 considered to hold the buffer position CHARPOS. */
19199 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19203 if (charpos
== CHARPOS (row
->end
.pos
)
19204 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19206 /* Suppose the row ends on a string.
19207 Unless the row is continued, that means it ends on a newline
19208 in the string. If it's anything other than a display string
19209 (e.g., a before-string from an overlay), we don't want the
19210 cursor there. (This heuristic seems to give the optimal
19211 behavior for the various types of multi-line strings.)
19212 One exception: if the string has `cursor' property on one of
19213 its characters, we _do_ want the cursor there. */
19214 if (CHARPOS (row
->end
.string_pos
) >= 0)
19216 if (row
->continued_p
)
19220 /* Check for `display' property. */
19221 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19222 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19223 struct glyph
*glyph
;
19226 for (glyph
= end
; glyph
>= beg
; --glyph
)
19227 if (STRINGP (glyph
->object
))
19230 = Fget_char_property (make_number (charpos
),
19234 && display_prop_string_p (prop
, glyph
->object
));
19235 /* If there's a `cursor' property on one of the
19236 string's characters, this row is a cursor row,
19237 even though this is not a display string. */
19240 Lisp_Object s
= glyph
->object
;
19242 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19244 ptrdiff_t gpos
= glyph
->charpos
;
19246 if (!NILP (Fget_char_property (make_number (gpos
),
19258 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19260 /* If the row ends in middle of a real character,
19261 and the line is continued, we want the cursor here.
19262 That's because CHARPOS (ROW->end.pos) would equal
19263 PT if PT is before the character. */
19264 if (!row
->ends_in_ellipsis_p
)
19265 result
= row
->continued_p
;
19267 /* If the row ends in an ellipsis, then
19268 CHARPOS (ROW->end.pos) will equal point after the
19269 invisible text. We want that position to be displayed
19270 after the ellipsis. */
19273 /* If the row ends at ZV, display the cursor at the end of that
19274 row instead of at the start of the row below. */
19275 else if (row
->ends_at_zv_p
)
19284 /* Value is non-zero if glyph row ROW should be
19285 used to hold the cursor. */
19288 cursor_row_p (struct glyph_row
*row
)
19290 return row_for_charpos_p (row
, PT
);
19295 /* Push the property PROP so that it will be rendered at the current
19296 position in IT. Return 1 if PROP was successfully pushed, 0
19297 otherwise. Called from handle_line_prefix to handle the
19298 `line-prefix' and `wrap-prefix' properties. */
19301 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19303 struct text_pos pos
=
19304 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19306 eassert (it
->method
== GET_FROM_BUFFER
19307 || it
->method
== GET_FROM_DISPLAY_VECTOR
19308 || it
->method
== GET_FROM_STRING
);
19310 /* We need to save the current buffer/string position, so it will be
19311 restored by pop_it, because iterate_out_of_display_property
19312 depends on that being set correctly, but some situations leave
19313 it->position not yet set when this function is called. */
19314 push_it (it
, &pos
);
19316 if (STRINGP (prop
))
19318 if (SCHARS (prop
) == 0)
19325 it
->string_from_prefix_prop_p
= 1;
19326 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19327 it
->current
.overlay_string_index
= -1;
19328 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19329 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19330 it
->method
= GET_FROM_STRING
;
19331 it
->stop_charpos
= 0;
19333 it
->base_level_stop
= 0;
19335 /* Force paragraph direction to be that of the parent
19337 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19338 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19340 it
->paragraph_embedding
= L2R
;
19342 /* Set up the bidi iterator for this display string. */
19345 it
->bidi_it
.string
.lstring
= it
->string
;
19346 it
->bidi_it
.string
.s
= NULL
;
19347 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19348 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19349 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19350 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19351 it
->bidi_it
.w
= it
->w
;
19352 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19355 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19357 it
->method
= GET_FROM_STRETCH
;
19360 #ifdef HAVE_WINDOW_SYSTEM
19361 else if (IMAGEP (prop
))
19363 it
->what
= IT_IMAGE
;
19364 it
->image_id
= lookup_image (it
->f
, prop
);
19365 it
->method
= GET_FROM_IMAGE
;
19367 #endif /* HAVE_WINDOW_SYSTEM */
19370 pop_it (it
); /* bogus display property, give up */
19377 /* Return the character-property PROP at the current position in IT. */
19380 get_it_property (struct it
*it
, Lisp_Object prop
)
19382 Lisp_Object position
, object
= it
->object
;
19384 if (STRINGP (object
))
19385 position
= make_number (IT_STRING_CHARPOS (*it
));
19386 else if (BUFFERP (object
))
19388 position
= make_number (IT_CHARPOS (*it
));
19389 object
= it
->window
;
19394 return Fget_char_property (position
, prop
, object
);
19397 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19400 handle_line_prefix (struct it
*it
)
19402 Lisp_Object prefix
;
19404 if (it
->continuation_lines_width
> 0)
19406 prefix
= get_it_property (it
, Qwrap_prefix
);
19408 prefix
= Vwrap_prefix
;
19412 prefix
= get_it_property (it
, Qline_prefix
);
19414 prefix
= Vline_prefix
;
19416 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19418 /* If the prefix is wider than the window, and we try to wrap
19419 it, it would acquire its own wrap prefix, and so on till the
19420 iterator stack overflows. So, don't wrap the prefix. */
19421 it
->line_wrap
= TRUNCATE
;
19422 it
->avoid_cursor_p
= 1;
19428 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19429 only for R2L lines from display_line and display_string, when they
19430 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19431 the line/string needs to be continued on the next glyph row. */
19433 unproduce_glyphs (struct it
*it
, int n
)
19435 struct glyph
*glyph
, *end
;
19437 eassert (it
->glyph_row
);
19438 eassert (it
->glyph_row
->reversed_p
);
19439 eassert (it
->area
== TEXT_AREA
);
19440 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19442 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19443 n
= it
->glyph_row
->used
[TEXT_AREA
];
19444 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19445 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19446 for ( ; glyph
< end
; glyph
++)
19447 glyph
[-n
] = *glyph
;
19450 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19451 and ROW->maxpos. */
19453 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19454 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19455 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19457 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19458 lines' rows is implemented for bidi-reordered rows. */
19460 /* ROW->minpos is the value of min_pos, the minimal buffer position
19461 we have in ROW, or ROW->start.pos if that is smaller. */
19462 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19463 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19465 /* We didn't find buffer positions smaller than ROW->start, or
19466 didn't find _any_ valid buffer positions in any of the glyphs,
19467 so we must trust the iterator's computed positions. */
19468 row
->minpos
= row
->start
.pos
;
19471 max_pos
= CHARPOS (it
->current
.pos
);
19472 max_bpos
= BYTEPOS (it
->current
.pos
);
19475 /* Here are the various use-cases for ending the row, and the
19476 corresponding values for ROW->maxpos:
19478 Line ends in a newline from buffer eol_pos + 1
19479 Line is continued from buffer max_pos + 1
19480 Line is truncated on right it->current.pos
19481 Line ends in a newline from string max_pos + 1(*)
19482 (*) + 1 only when line ends in a forward scan
19483 Line is continued from string max_pos
19484 Line is continued from display vector max_pos
19485 Line is entirely from a string min_pos == max_pos
19486 Line is entirely from a display vector min_pos == max_pos
19487 Line that ends at ZV ZV
19489 If you discover other use-cases, please add them here as
19491 if (row
->ends_at_zv_p
)
19492 row
->maxpos
= it
->current
.pos
;
19493 else if (row
->used
[TEXT_AREA
])
19495 int seen_this_string
= 0;
19496 struct glyph_row
*r1
= row
- 1;
19498 /* Did we see the same display string on the previous row? */
19499 if (STRINGP (it
->object
)
19500 /* this is not the first row */
19501 && row
> it
->w
->desired_matrix
->rows
19502 /* previous row is not the header line */
19503 && !r1
->mode_line_p
19504 /* previous row also ends in a newline from a string */
19505 && r1
->ends_in_newline_from_string_p
)
19507 struct glyph
*start
, *end
;
19509 /* Search for the last glyph of the previous row that came
19510 from buffer or string. Depending on whether the row is
19511 L2R or R2L, we need to process it front to back or the
19512 other way round. */
19513 if (!r1
->reversed_p
)
19515 start
= r1
->glyphs
[TEXT_AREA
];
19516 end
= start
+ r1
->used
[TEXT_AREA
];
19517 /* Glyphs inserted by redisplay have an integer (zero)
19518 as their object. */
19520 && INTEGERP ((end
- 1)->object
)
19521 && (end
- 1)->charpos
<= 0)
19525 if (EQ ((end
- 1)->object
, it
->object
))
19526 seen_this_string
= 1;
19529 /* If all the glyphs of the previous row were inserted
19530 by redisplay, it means the previous row was
19531 produced from a single newline, which is only
19532 possible if that newline came from the same string
19533 as the one which produced this ROW. */
19534 seen_this_string
= 1;
19538 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19539 start
= end
+ r1
->used
[TEXT_AREA
];
19541 && INTEGERP ((end
+ 1)->object
)
19542 && (end
+ 1)->charpos
<= 0)
19546 if (EQ ((end
+ 1)->object
, it
->object
))
19547 seen_this_string
= 1;
19550 seen_this_string
= 1;
19553 /* Take note of each display string that covers a newline only
19554 once, the first time we see it. This is for when a display
19555 string includes more than one newline in it. */
19556 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19558 /* If we were scanning the buffer forward when we displayed
19559 the string, we want to account for at least one buffer
19560 position that belongs to this row (position covered by
19561 the display string), so that cursor positioning will
19562 consider this row as a candidate when point is at the end
19563 of the visual line represented by this row. This is not
19564 required when scanning back, because max_pos will already
19565 have a much larger value. */
19566 if (CHARPOS (row
->end
.pos
) > max_pos
)
19567 INC_BOTH (max_pos
, max_bpos
);
19568 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19570 else if (CHARPOS (it
->eol_pos
) > 0)
19571 SET_TEXT_POS (row
->maxpos
,
19572 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19573 else if (row
->continued_p
)
19575 /* If max_pos is different from IT's current position, it
19576 means IT->method does not belong to the display element
19577 at max_pos. However, it also means that the display
19578 element at max_pos was displayed in its entirety on this
19579 line, which is equivalent to saying that the next line
19580 starts at the next buffer position. */
19581 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19582 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19585 INC_BOTH (max_pos
, max_bpos
);
19586 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19589 else if (row
->truncated_on_right_p
)
19590 /* display_line already called reseat_at_next_visible_line_start,
19591 which puts the iterator at the beginning of the next line, in
19592 the logical order. */
19593 row
->maxpos
= it
->current
.pos
;
19594 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19595 /* A line that is entirely from a string/image/stretch... */
19596 row
->maxpos
= row
->minpos
;
19601 row
->maxpos
= it
->current
.pos
;
19604 /* Construct the glyph row IT->glyph_row in the desired matrix of
19605 IT->w from text at the current position of IT. See dispextern.h
19606 for an overview of struct it. Value is non-zero if
19607 IT->glyph_row displays text, as opposed to a line displaying ZV
19611 display_line (struct it
*it
)
19613 struct glyph_row
*row
= it
->glyph_row
;
19614 Lisp_Object overlay_arrow_string
;
19616 void *wrap_data
= NULL
;
19617 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19618 int wrap_row_used
= -1;
19619 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19620 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19621 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19622 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19623 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19625 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19626 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19628 /* We always start displaying at hpos zero even if hscrolled. */
19629 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19631 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19632 >= it
->w
->desired_matrix
->nrows
)
19634 it
->w
->nrows_scale_factor
++;
19635 it
->f
->fonts_changed
= 1;
19639 /* Clear the result glyph row and enable it. */
19640 prepare_desired_row (row
);
19642 row
->y
= it
->current_y
;
19643 row
->start
= it
->start
;
19644 row
->continuation_lines_width
= it
->continuation_lines_width
;
19645 row
->displays_text_p
= 1;
19646 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19647 it
->starts_in_middle_of_char_p
= 0;
19649 /* Arrange the overlays nicely for our purposes. Usually, we call
19650 display_line on only one line at a time, in which case this
19651 can't really hurt too much, or we call it on lines which appear
19652 one after another in the buffer, in which case all calls to
19653 recenter_overlay_lists but the first will be pretty cheap. */
19654 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19656 /* Move over display elements that are not visible because we are
19657 hscrolled. This may stop at an x-position < IT->first_visible_x
19658 if the first glyph is partially visible or if we hit a line end. */
19659 if (it
->current_x
< it
->first_visible_x
)
19661 enum move_it_result move_result
;
19663 this_line_min_pos
= row
->start
.pos
;
19664 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19665 MOVE_TO_POS
| MOVE_TO_X
);
19666 /* If we are under a large hscroll, move_it_in_display_line_to
19667 could hit the end of the line without reaching
19668 it->first_visible_x. Pretend that we did reach it. This is
19669 especially important on a TTY, where we will call
19670 extend_face_to_end_of_line, which needs to know how many
19671 blank glyphs to produce. */
19672 if (it
->current_x
< it
->first_visible_x
19673 && (move_result
== MOVE_NEWLINE_OR_CR
19674 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19675 it
->current_x
= it
->first_visible_x
;
19677 /* Record the smallest positions seen while we moved over
19678 display elements that are not visible. This is needed by
19679 redisplay_internal for optimizing the case where the cursor
19680 stays inside the same line. The rest of this function only
19681 considers positions that are actually displayed, so
19682 RECORD_MAX_MIN_POS will not otherwise record positions that
19683 are hscrolled to the left of the left edge of the window. */
19684 min_pos
= CHARPOS (this_line_min_pos
);
19685 min_bpos
= BYTEPOS (this_line_min_pos
);
19689 /* We only do this when not calling `move_it_in_display_line_to'
19690 above, because move_it_in_display_line_to calls
19691 handle_line_prefix itself. */
19692 handle_line_prefix (it
);
19695 /* Get the initial row height. This is either the height of the
19696 text hscrolled, if there is any, or zero. */
19697 row
->ascent
= it
->max_ascent
;
19698 row
->height
= it
->max_ascent
+ it
->max_descent
;
19699 row
->phys_ascent
= it
->max_phys_ascent
;
19700 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19701 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19703 /* Utility macro to record max and min buffer positions seen until now. */
19704 #define RECORD_MAX_MIN_POS(IT) \
19707 int composition_p = !STRINGP ((IT)->string) \
19708 && ((IT)->what == IT_COMPOSITION); \
19709 ptrdiff_t current_pos = \
19710 composition_p ? (IT)->cmp_it.charpos \
19711 : IT_CHARPOS (*(IT)); \
19712 ptrdiff_t current_bpos = \
19713 composition_p ? CHAR_TO_BYTE (current_pos) \
19714 : IT_BYTEPOS (*(IT)); \
19715 if (current_pos < min_pos) \
19717 min_pos = current_pos; \
19718 min_bpos = current_bpos; \
19720 if (IT_CHARPOS (*it) > max_pos) \
19722 max_pos = IT_CHARPOS (*it); \
19723 max_bpos = IT_BYTEPOS (*it); \
19728 /* Loop generating characters. The loop is left with IT on the next
19729 character to display. */
19732 int n_glyphs_before
, hpos_before
, x_before
;
19734 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19736 /* Retrieve the next thing to display. Value is zero if end of
19738 if (!get_next_display_element (it
))
19740 /* Maybe add a space at the end of this line that is used to
19741 display the cursor there under X. Set the charpos of the
19742 first glyph of blank lines not corresponding to any text
19744 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19745 row
->exact_window_width_line_p
= 1;
19746 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19747 || row
->used
[TEXT_AREA
] == 0)
19749 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19750 row
->displays_text_p
= 0;
19752 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19753 && (!MINI_WINDOW_P (it
->w
)
19754 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19755 row
->indicate_empty_line_p
= 1;
19758 it
->continuation_lines_width
= 0;
19759 row
->ends_at_zv_p
= 1;
19760 /* A row that displays right-to-left text must always have
19761 its last face extended all the way to the end of line,
19762 even if this row ends in ZV, because we still write to
19763 the screen left to right. We also need to extend the
19764 last face if the default face is remapped to some
19765 different face, otherwise the functions that clear
19766 portions of the screen will clear with the default face's
19767 background color. */
19768 if (row
->reversed_p
19769 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19770 extend_face_to_end_of_line (it
);
19774 /* Now, get the metrics of what we want to display. This also
19775 generates glyphs in `row' (which is IT->glyph_row). */
19776 n_glyphs_before
= row
->used
[TEXT_AREA
];
19779 /* Remember the line height so far in case the next element doesn't
19780 fit on the line. */
19781 if (it
->line_wrap
!= TRUNCATE
)
19783 ascent
= it
->max_ascent
;
19784 descent
= it
->max_descent
;
19785 phys_ascent
= it
->max_phys_ascent
;
19786 phys_descent
= it
->max_phys_descent
;
19788 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19790 if (IT_DISPLAYING_WHITESPACE (it
))
19794 SAVE_IT (wrap_it
, *it
, wrap_data
);
19796 wrap_row_used
= row
->used
[TEXT_AREA
];
19797 wrap_row_ascent
= row
->ascent
;
19798 wrap_row_height
= row
->height
;
19799 wrap_row_phys_ascent
= row
->phys_ascent
;
19800 wrap_row_phys_height
= row
->phys_height
;
19801 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19802 wrap_row_min_pos
= min_pos
;
19803 wrap_row_min_bpos
= min_bpos
;
19804 wrap_row_max_pos
= max_pos
;
19805 wrap_row_max_bpos
= max_bpos
;
19811 PRODUCE_GLYPHS (it
);
19813 /* If this display element was in marginal areas, continue with
19815 if (it
->area
!= TEXT_AREA
)
19817 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19818 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19819 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19820 row
->phys_height
= max (row
->phys_height
,
19821 it
->max_phys_ascent
+ it
->max_phys_descent
);
19822 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19823 it
->max_extra_line_spacing
);
19824 set_iterator_to_next (it
, 1);
19828 /* Does the display element fit on the line? If we truncate
19829 lines, we should draw past the right edge of the window. If
19830 we don't truncate, we want to stop so that we can display the
19831 continuation glyph before the right margin. If lines are
19832 continued, there are two possible strategies for characters
19833 resulting in more than 1 glyph (e.g. tabs): Display as many
19834 glyphs as possible in this line and leave the rest for the
19835 continuation line, or display the whole element in the next
19836 line. Original redisplay did the former, so we do it also. */
19837 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19838 hpos_before
= it
->hpos
;
19841 if (/* Not a newline. */
19843 /* Glyphs produced fit entirely in the line. */
19844 && it
->current_x
< it
->last_visible_x
)
19846 it
->hpos
+= nglyphs
;
19847 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19848 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19849 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19850 row
->phys_height
= max (row
->phys_height
,
19851 it
->max_phys_ascent
+ it
->max_phys_descent
);
19852 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19853 it
->max_extra_line_spacing
);
19854 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19855 row
->x
= x
- it
->first_visible_x
;
19856 /* Record the maximum and minimum buffer positions seen so
19857 far in glyphs that will be displayed by this row. */
19859 RECORD_MAX_MIN_POS (it
);
19864 struct glyph
*glyph
;
19866 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19868 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19869 new_x
= x
+ glyph
->pixel_width
;
19871 if (/* Lines are continued. */
19872 it
->line_wrap
!= TRUNCATE
19873 && (/* Glyph doesn't fit on the line. */
19874 new_x
> it
->last_visible_x
19875 /* Or it fits exactly on a window system frame. */
19876 || (new_x
== it
->last_visible_x
19877 && FRAME_WINDOW_P (it
->f
)
19878 && (row
->reversed_p
19879 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19880 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19882 /* End of a continued line. */
19885 || (new_x
== it
->last_visible_x
19886 && FRAME_WINDOW_P (it
->f
)
19887 && (row
->reversed_p
19888 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19889 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19891 /* Current glyph is the only one on the line or
19892 fits exactly on the line. We must continue
19893 the line because we can't draw the cursor
19894 after the glyph. */
19895 row
->continued_p
= 1;
19896 it
->current_x
= new_x
;
19897 it
->continuation_lines_width
+= new_x
;
19899 if (i
== nglyphs
- 1)
19901 /* If line-wrap is on, check if a previous
19902 wrap point was found. */
19903 if (wrap_row_used
> 0
19904 /* Even if there is a previous wrap
19905 point, continue the line here as
19906 usual, if (i) the previous character
19907 was a space or tab AND (ii) the
19908 current character is not. */
19910 || IT_DISPLAYING_WHITESPACE (it
)))
19913 /* Record the maximum and minimum buffer
19914 positions seen so far in glyphs that will be
19915 displayed by this row. */
19917 RECORD_MAX_MIN_POS (it
);
19918 set_iterator_to_next (it
, 1);
19919 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19921 if (!get_next_display_element (it
))
19923 row
->exact_window_width_line_p
= 1;
19924 it
->continuation_lines_width
= 0;
19925 row
->continued_p
= 0;
19926 row
->ends_at_zv_p
= 1;
19928 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19930 row
->continued_p
= 0;
19931 row
->exact_window_width_line_p
= 1;
19935 else if (it
->bidi_p
)
19936 RECORD_MAX_MIN_POS (it
);
19937 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19938 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
19939 extend_face_to_end_of_line (it
);
19941 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19942 && !FRAME_WINDOW_P (it
->f
))
19944 /* A padding glyph that doesn't fit on this line.
19945 This means the whole character doesn't fit
19947 if (row
->reversed_p
)
19948 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19949 - n_glyphs_before
);
19950 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19952 /* Fill the rest of the row with continuation
19953 glyphs like in 20.x. */
19954 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19955 < row
->glyphs
[1 + TEXT_AREA
])
19956 produce_special_glyphs (it
, IT_CONTINUATION
);
19958 row
->continued_p
= 1;
19959 it
->current_x
= x_before
;
19960 it
->continuation_lines_width
+= x_before
;
19962 /* Restore the height to what it was before the
19963 element not fitting on the line. */
19964 it
->max_ascent
= ascent
;
19965 it
->max_descent
= descent
;
19966 it
->max_phys_ascent
= phys_ascent
;
19967 it
->max_phys_descent
= phys_descent
;
19968 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19969 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
19970 extend_face_to_end_of_line (it
);
19972 else if (wrap_row_used
> 0)
19975 if (row
->reversed_p
)
19976 unproduce_glyphs (it
,
19977 row
->used
[TEXT_AREA
] - wrap_row_used
);
19978 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19979 it
->continuation_lines_width
+= wrap_x
;
19980 row
->used
[TEXT_AREA
] = wrap_row_used
;
19981 row
->ascent
= wrap_row_ascent
;
19982 row
->height
= wrap_row_height
;
19983 row
->phys_ascent
= wrap_row_phys_ascent
;
19984 row
->phys_height
= wrap_row_phys_height
;
19985 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19986 min_pos
= wrap_row_min_pos
;
19987 min_bpos
= wrap_row_min_bpos
;
19988 max_pos
= wrap_row_max_pos
;
19989 max_bpos
= wrap_row_max_bpos
;
19990 row
->continued_p
= 1;
19991 row
->ends_at_zv_p
= 0;
19992 row
->exact_window_width_line_p
= 0;
19993 it
->continuation_lines_width
+= x
;
19995 /* Make sure that a non-default face is extended
19996 up to the right margin of the window. */
19997 extend_face_to_end_of_line (it
);
19999 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
20001 /* A TAB that extends past the right edge of the
20002 window. This produces a single glyph on
20003 window system frames. We leave the glyph in
20004 this row and let it fill the row, but don't
20005 consume the TAB. */
20006 if ((row
->reversed_p
20007 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20008 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20009 produce_special_glyphs (it
, IT_CONTINUATION
);
20010 it
->continuation_lines_width
+= it
->last_visible_x
;
20011 row
->ends_in_middle_of_char_p
= 1;
20012 row
->continued_p
= 1;
20013 glyph
->pixel_width
= it
->last_visible_x
- x
;
20014 it
->starts_in_middle_of_char_p
= 1;
20015 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
20016 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
20017 extend_face_to_end_of_line (it
);
20021 /* Something other than a TAB that draws past
20022 the right edge of the window. Restore
20023 positions to values before the element. */
20024 if (row
->reversed_p
)
20025 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20026 - (n_glyphs_before
+ i
));
20027 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20029 /* Display continuation glyphs. */
20030 it
->current_x
= x_before
;
20031 it
->continuation_lines_width
+= x
;
20032 if (!FRAME_WINDOW_P (it
->f
)
20033 || (row
->reversed_p
20034 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20035 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20036 produce_special_glyphs (it
, IT_CONTINUATION
);
20037 row
->continued_p
= 1;
20039 extend_face_to_end_of_line (it
);
20041 if (nglyphs
> 1 && i
> 0)
20043 row
->ends_in_middle_of_char_p
= 1;
20044 it
->starts_in_middle_of_char_p
= 1;
20047 /* Restore the height to what it was before the
20048 element not fitting on the line. */
20049 it
->max_ascent
= ascent
;
20050 it
->max_descent
= descent
;
20051 it
->max_phys_ascent
= phys_ascent
;
20052 it
->max_phys_descent
= phys_descent
;
20057 else if (new_x
> it
->first_visible_x
)
20059 /* Increment number of glyphs actually displayed. */
20062 /* Record the maximum and minimum buffer positions
20063 seen so far in glyphs that will be displayed by
20066 RECORD_MAX_MIN_POS (it
);
20068 if (x
< it
->first_visible_x
)
20069 /* Glyph is partially visible, i.e. row starts at
20070 negative X position. */
20071 row
->x
= x
- it
->first_visible_x
;
20075 /* Glyph is completely off the left margin of the
20076 window. This should not happen because of the
20077 move_it_in_display_line at the start of this
20078 function, unless the text display area of the
20079 window is empty. */
20080 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20083 /* Even if this display element produced no glyphs at all,
20084 we want to record its position. */
20085 if (it
->bidi_p
&& nglyphs
== 0)
20086 RECORD_MAX_MIN_POS (it
);
20088 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20089 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20090 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20091 row
->phys_height
= max (row
->phys_height
,
20092 it
->max_phys_ascent
+ it
->max_phys_descent
);
20093 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20094 it
->max_extra_line_spacing
);
20096 /* End of this display line if row is continued. */
20097 if (row
->continued_p
|| row
->ends_at_zv_p
)
20102 /* Is this a line end? If yes, we're also done, after making
20103 sure that a non-default face is extended up to the right
20104 margin of the window. */
20105 if (ITERATOR_AT_END_OF_LINE_P (it
))
20107 int used_before
= row
->used
[TEXT_AREA
];
20109 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
20111 /* Add a space at the end of the line that is used to
20112 display the cursor there. */
20113 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20114 append_space_for_newline (it
, 0);
20116 /* Extend the face to the end of the line. */
20117 extend_face_to_end_of_line (it
);
20119 /* Make sure we have the position. */
20120 if (used_before
== 0)
20121 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
20123 /* Record the position of the newline, for use in
20125 it
->eol_pos
= it
->current
.pos
;
20127 /* Consume the line end. This skips over invisible lines. */
20128 set_iterator_to_next (it
, 1);
20129 it
->continuation_lines_width
= 0;
20133 /* Proceed with next display element. Note that this skips
20134 over lines invisible because of selective display. */
20135 set_iterator_to_next (it
, 1);
20137 /* If we truncate lines, we are done when the last displayed
20138 glyphs reach past the right margin of the window. */
20139 if (it
->line_wrap
== TRUNCATE
20140 && ((FRAME_WINDOW_P (it
->f
)
20141 /* Images are preprocessed in produce_image_glyph such
20142 that they are cropped at the right edge of the
20143 window, so an image glyph will always end exactly at
20144 last_visible_x, even if there's no right fringe. */
20145 && (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) || it
->what
== IT_IMAGE
))
20146 ? (it
->current_x
>= it
->last_visible_x
)
20147 : (it
->current_x
> it
->last_visible_x
)))
20149 /* Maybe add truncation glyphs. */
20150 if (!FRAME_WINDOW_P (it
->f
)
20151 || (row
->reversed_p
20152 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20153 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20157 if (!row
->reversed_p
)
20159 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20160 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20165 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20166 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20168 /* Remove any padding glyphs at the front of ROW, to
20169 make room for the truncation glyphs we will be
20170 adding below. The loop below always inserts at
20171 least one truncation glyph, so also remove the
20172 last glyph added to ROW. */
20173 unproduce_glyphs (it
, i
+ 1);
20174 /* Adjust i for the loop below. */
20175 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20178 /* produce_special_glyphs overwrites the last glyph, so
20179 we don't want that if we want to keep that last
20180 glyph, which means it's an image. */
20181 if (it
->current_x
> it
->last_visible_x
)
20183 it
->current_x
= x_before
;
20184 if (!FRAME_WINDOW_P (it
->f
))
20186 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20188 row
->used
[TEXT_AREA
] = i
;
20189 produce_special_glyphs (it
, IT_TRUNCATION
);
20194 row
->used
[TEXT_AREA
] = i
;
20195 produce_special_glyphs (it
, IT_TRUNCATION
);
20197 it
->hpos
= hpos_before
;
20200 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20202 /* Don't truncate if we can overflow newline into fringe. */
20203 if (!get_next_display_element (it
))
20205 it
->continuation_lines_width
= 0;
20206 row
->ends_at_zv_p
= 1;
20207 row
->exact_window_width_line_p
= 1;
20210 if (ITERATOR_AT_END_OF_LINE_P (it
))
20212 row
->exact_window_width_line_p
= 1;
20213 goto at_end_of_line
;
20215 it
->current_x
= x_before
;
20216 it
->hpos
= hpos_before
;
20219 row
->truncated_on_right_p
= 1;
20220 it
->continuation_lines_width
= 0;
20221 reseat_at_next_visible_line_start (it
, 0);
20222 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
20228 bidi_unshelve_cache (wrap_data
, 1);
20230 /* If line is not empty and hscrolled, maybe insert truncation glyphs
20231 at the left window margin. */
20232 if (it
->first_visible_x
20233 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20235 if (!FRAME_WINDOW_P (it
->f
)
20236 || (((row
->reversed_p
20237 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20238 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20239 /* Don't let insert_left_trunc_glyphs overwrite the
20240 first glyph of the row if it is an image. */
20241 && row
->glyphs
[TEXT_AREA
]->type
!= IMAGE_GLYPH
))
20242 insert_left_trunc_glyphs (it
);
20243 row
->truncated_on_left_p
= 1;
20246 /* Remember the position at which this line ends.
20248 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20249 cannot be before the call to find_row_edges below, since that is
20250 where these positions are determined. */
20251 row
->end
= it
->current
;
20254 row
->minpos
= row
->start
.pos
;
20255 row
->maxpos
= row
->end
.pos
;
20259 /* ROW->minpos and ROW->maxpos must be the smallest and
20260 `1 + the largest' buffer positions in ROW. But if ROW was
20261 bidi-reordered, these two positions can be anywhere in the
20262 row, so we must determine them now. */
20263 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20266 /* If the start of this line is the overlay arrow-position, then
20267 mark this glyph row as the one containing the overlay arrow.
20268 This is clearly a mess with variable size fonts. It would be
20269 better to let it be displayed like cursors under X. */
20270 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20271 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20272 !NILP (overlay_arrow_string
)))
20274 /* Overlay arrow in window redisplay is a fringe bitmap. */
20275 if (STRINGP (overlay_arrow_string
))
20277 struct glyph_row
*arrow_row
20278 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20279 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20280 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20281 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20282 struct glyph
*p2
, *end
;
20284 /* Copy the arrow glyphs. */
20285 while (glyph
< arrow_end
)
20288 /* Throw away padding glyphs. */
20290 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20291 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20297 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20302 eassert (INTEGERP (overlay_arrow_string
));
20303 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20305 overlay_arrow_seen
= 1;
20308 /* Highlight trailing whitespace. */
20309 if (!NILP (Vshow_trailing_whitespace
))
20310 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20312 /* Compute pixel dimensions of this line. */
20313 compute_line_metrics (it
);
20315 /* Implementation note: No changes in the glyphs of ROW or in their
20316 faces can be done past this point, because compute_line_metrics
20317 computes ROW's hash value and stores it within the glyph_row
20320 /* Record whether this row ends inside an ellipsis. */
20321 row
->ends_in_ellipsis_p
20322 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20323 && it
->ellipsis_p
);
20325 /* Save fringe bitmaps in this row. */
20326 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20327 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20328 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20329 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20331 it
->left_user_fringe_bitmap
= 0;
20332 it
->left_user_fringe_face_id
= 0;
20333 it
->right_user_fringe_bitmap
= 0;
20334 it
->right_user_fringe_face_id
= 0;
20336 /* Maybe set the cursor. */
20337 cvpos
= it
->w
->cursor
.vpos
;
20339 /* In bidi-reordered rows, keep checking for proper cursor
20340 position even if one has been found already, because buffer
20341 positions in such rows change non-linearly with ROW->VPOS,
20342 when a line is continued. One exception: when we are at ZV,
20343 display cursor on the first suitable glyph row, since all
20344 the empty rows after that also have their position set to ZV. */
20345 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20346 lines' rows is implemented for bidi-reordered rows. */
20348 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20349 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20350 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20351 && cursor_row_p (row
))
20352 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20354 /* Prepare for the next line. This line starts horizontally at (X
20355 HPOS) = (0 0). Vertical positions are incremented. As a
20356 convenience for the caller, IT->glyph_row is set to the next
20358 it
->current_x
= it
->hpos
= 0;
20359 it
->current_y
+= row
->height
;
20360 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20363 /* The next row should by default use the same value of the
20364 reversed_p flag as this one. set_iterator_to_next decides when
20365 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20366 the flag accordingly. */
20367 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20368 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20369 it
->start
= row
->end
;
20370 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20372 #undef RECORD_MAX_MIN_POS
20375 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20376 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20377 doc
: /* Return paragraph direction at point in BUFFER.
20378 Value is either `left-to-right' or `right-to-left'.
20379 If BUFFER is omitted or nil, it defaults to the current buffer.
20381 Paragraph direction determines how the text in the paragraph is displayed.
20382 In left-to-right paragraphs, text begins at the left margin of the window
20383 and the reading direction is generally left to right. In right-to-left
20384 paragraphs, text begins at the right margin and is read from right to left.
20386 See also `bidi-paragraph-direction'. */)
20387 (Lisp_Object buffer
)
20389 struct buffer
*buf
= current_buffer
;
20390 struct buffer
*old
= buf
;
20392 if (! NILP (buffer
))
20394 CHECK_BUFFER (buffer
);
20395 buf
= XBUFFER (buffer
);
20398 if (NILP (BVAR (buf
, bidi_display_reordering
))
20399 || NILP (BVAR (buf
, enable_multibyte_characters
))
20400 /* When we are loading loadup.el, the character property tables
20401 needed for bidi iteration are not yet available. */
20402 || !NILP (Vpurify_flag
))
20403 return Qleft_to_right
;
20404 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20405 return BVAR (buf
, bidi_paragraph_direction
);
20408 /* Determine the direction from buffer text. We could try to
20409 use current_matrix if it is up to date, but this seems fast
20410 enough as it is. */
20411 struct bidi_it itb
;
20412 ptrdiff_t pos
= BUF_PT (buf
);
20413 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20415 void *itb_data
= bidi_shelve_cache ();
20417 set_buffer_temp (buf
);
20418 /* bidi_paragraph_init finds the base direction of the paragraph
20419 by searching forward from paragraph start. We need the base
20420 direction of the current or _previous_ paragraph, so we need
20421 to make sure we are within that paragraph. To that end, find
20422 the previous non-empty line. */
20423 if (pos
>= ZV
&& pos
> BEGV
)
20424 DEC_BOTH (pos
, bytepos
);
20425 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20426 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20428 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20429 || c
== ' ' || c
== '\t' || c
== '\f')
20431 if (bytepos
<= BEGV_BYTE
)
20436 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20439 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20440 itb
.paragraph_dir
= NEUTRAL_DIR
;
20441 itb
.string
.s
= NULL
;
20442 itb
.string
.lstring
= Qnil
;
20443 itb
.string
.bufpos
= 0;
20444 itb
.string
.from_disp_str
= 0;
20445 itb
.string
.unibyte
= 0;
20446 /* We have no window to use here for ignoring window-specific
20447 overlays. Using NULL for window pointer will cause
20448 compute_display_string_pos to use the current buffer. */
20450 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20451 bidi_unshelve_cache (itb_data
, 0);
20452 set_buffer_temp (old
);
20453 switch (itb
.paragraph_dir
)
20456 return Qleft_to_right
;
20459 return Qright_to_left
;
20467 DEFUN ("move-point-visually", Fmove_point_visually
,
20468 Smove_point_visually
, 1, 1, 0,
20469 doc
: /* Move point in the visual order in the specified DIRECTION.
20470 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20473 Value is the new character position of point. */)
20474 (Lisp_Object direction
)
20476 struct window
*w
= XWINDOW (selected_window
);
20477 struct buffer
*b
= XBUFFER (w
->contents
);
20478 struct glyph_row
*row
;
20480 Lisp_Object paragraph_dir
;
20482 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20483 (!(ROW)->continued_p \
20484 && INTEGERP ((GLYPH)->object) \
20485 && (GLYPH)->type == CHAR_GLYPH \
20486 && (GLYPH)->u.ch == ' ' \
20487 && (GLYPH)->charpos >= 0 \
20488 && !(GLYPH)->avoid_cursor_p)
20490 CHECK_NUMBER (direction
);
20491 dir
= XINT (direction
);
20497 /* If current matrix is up-to-date, we can use the information
20498 recorded in the glyphs, at least as long as the goal is on the
20500 if (w
->window_end_valid
20501 && !windows_or_buffers_changed
20503 && !b
->clip_changed
20504 && !b
->prevent_redisplay_optimizations_p
20505 && !window_outdated (w
)
20506 && w
->cursor
.vpos
>= 0
20507 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20508 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20510 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20511 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20512 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20514 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20516 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20518 SET_PT (g
->charpos
);
20519 w
->cursor
.vpos
= -1;
20520 return make_number (PT
);
20522 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20526 if (BUFFERP (gpt
->object
))
20529 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20530 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20532 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20534 else if (BUFFERP (g
->object
))
20535 new_pos
= g
->charpos
;
20539 w
->cursor
.vpos
= -1;
20540 return make_number (PT
);
20542 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20544 /* Glyphs inserted at the end of a non-empty line for
20545 positioning the cursor have zero charpos, so we must
20546 deduce the value of point by other means. */
20547 if (g
->charpos
> 0)
20548 SET_PT (g
->charpos
);
20549 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20551 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20552 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20555 w
->cursor
.vpos
= -1;
20556 return make_number (PT
);
20559 if (g
== e
|| INTEGERP (g
->object
))
20561 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20562 goto simulate_display
;
20563 if (!row
->reversed_p
)
20567 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20568 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20569 goto simulate_display
;
20573 if (row
->reversed_p
&& !row
->continued_p
)
20575 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20576 w
->cursor
.vpos
= -1;
20577 return make_number (PT
);
20579 g
= row
->glyphs
[TEXT_AREA
];
20580 e
= g
+ row
->used
[TEXT_AREA
];
20581 for ( ; g
< e
; g
++)
20583 if (BUFFERP (g
->object
)
20584 /* Empty lines have only one glyph, which stands
20585 for the newline, and whose charpos is the
20586 buffer position of the newline. */
20587 || ROW_GLYPH_NEWLINE_P (row
, g
)
20588 /* When the buffer ends in a newline, the line at
20589 EOB also has one glyph, but its charpos is -1. */
20590 || (row
->ends_at_zv_p
20591 && !row
->reversed_p
20592 && INTEGERP (g
->object
)
20593 && g
->type
== CHAR_GLYPH
20594 && g
->u
.ch
== ' '))
20596 if (g
->charpos
> 0)
20597 SET_PT (g
->charpos
);
20598 else if (!row
->reversed_p
20599 && row
->ends_at_zv_p
20604 w
->cursor
.vpos
= -1;
20605 return make_number (PT
);
20611 if (!row
->reversed_p
&& !row
->continued_p
)
20613 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20614 w
->cursor
.vpos
= -1;
20615 return make_number (PT
);
20617 e
= row
->glyphs
[TEXT_AREA
];
20618 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20619 for ( ; g
>= e
; g
--)
20621 if (BUFFERP (g
->object
)
20622 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20624 /* Empty R2L lines on GUI frames have the buffer
20625 position of the newline stored in the stretch
20627 || g
->type
== STRETCH_GLYPH
20628 || (row
->ends_at_zv_p
20630 && INTEGERP (g
->object
)
20631 && g
->type
== CHAR_GLYPH
20632 && g
->u
.ch
== ' '))
20634 if (g
->charpos
> 0)
20635 SET_PT (g
->charpos
);
20636 else if (row
->reversed_p
20637 && row
->ends_at_zv_p
20642 w
->cursor
.vpos
= -1;
20643 return make_number (PT
);
20652 /* If we wind up here, we failed to move by using the glyphs, so we
20653 need to simulate display instead. */
20656 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20658 paragraph_dir
= Qleft_to_right
;
20659 if (EQ (paragraph_dir
, Qright_to_left
))
20661 if (PT
<= BEGV
&& dir
< 0)
20662 xsignal0 (Qbeginning_of_buffer
);
20663 else if (PT
>= ZV
&& dir
> 0)
20664 xsignal0 (Qend_of_buffer
);
20667 struct text_pos pt
;
20669 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20671 bool overshoot_expected
= false;
20672 bool target_is_eol_p
= false;
20674 /* Setup the arena. */
20675 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20676 start_display (&it
, w
, pt
);
20678 if (it
.cmp_it
.id
< 0
20679 && it
.method
== GET_FROM_STRING
20680 && it
.area
== TEXT_AREA
20681 && it
.string_from_display_prop_p
20682 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20683 overshoot_expected
= true;
20685 /* Find the X coordinate of point. We start from the beginning
20686 of this or previous line to make sure we are before point in
20687 the logical order (since the move_it_* functions can only
20690 reseat_at_previous_visible_line_start (&it
);
20691 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20692 if (IT_CHARPOS (it
) != PT
)
20694 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20695 -1, -1, -1, MOVE_TO_POS
);
20696 /* If we missed point because the character there is
20697 displayed out of a display vector that has more than one
20698 glyph, retry expecting overshoot. */
20699 if (it
.method
== GET_FROM_DISPLAY_VECTOR
20700 && it
.current
.dpvec_index
> 0
20701 && !overshoot_expected
)
20703 overshoot_expected
= true;
20706 else if (IT_CHARPOS (it
) != PT
&& !overshoot_expected
)
20707 move_it_in_display_line (&it
, PT
, -1, MOVE_TO_POS
);
20709 pt_x
= it
.current_x
;
20711 if (dir
> 0 || overshoot_expected
)
20713 struct glyph_row
*row
= it
.glyph_row
;
20715 /* When point is at beginning of line, we don't have
20716 information about the glyph there loaded into struct
20717 it. Calling get_next_display_element fixes that. */
20719 get_next_display_element (&it
);
20720 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20721 it
.glyph_row
= NULL
;
20722 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20723 it
.glyph_row
= row
;
20724 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20725 it, lest it will become out of sync with it's buffer
20727 it
.current_x
= pt_x
;
20730 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20731 pixel_width
= it
.pixel_width
;
20732 if (overshoot_expected
&& at_eol_p
)
20734 else if (pixel_width
<= 0)
20737 /* If there's a display string (or something similar) at point,
20738 we are actually at the glyph to the left of point, so we need
20739 to correct the X coordinate. */
20740 if (overshoot_expected
)
20743 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
20745 pt_x
+= pixel_width
;
20748 /* Compute target X coordinate, either to the left or to the
20749 right of point. On TTY frames, all characters have the same
20750 pixel width of 1, so we can use that. On GUI frames we don't
20751 have an easy way of getting at the pixel width of the
20752 character to the left of point, so we use a different method
20753 of getting to that place. */
20755 target_x
= pt_x
+ pixel_width
;
20757 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20759 /* Target X coordinate could be one line above or below the line
20760 of point, in which case we need to adjust the target X
20761 coordinate. Also, if moving to the left, we need to begin at
20762 the left edge of the point's screen line. */
20767 start_display (&it
, w
, pt
);
20768 reseat_at_previous_visible_line_start (&it
);
20769 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20771 move_it_by_lines (&it
, pt_vpos
);
20775 move_it_by_lines (&it
, -1);
20776 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20777 target_is_eol_p
= true;
20783 || (target_x
>= it
.last_visible_x
20784 && it
.line_wrap
!= TRUNCATE
))
20787 move_it_by_lines (&it
, 0);
20788 move_it_by_lines (&it
, 1);
20793 /* Move to the target X coordinate. */
20794 #ifdef HAVE_WINDOW_SYSTEM
20795 /* On GUI frames, as we don't know the X coordinate of the
20796 character to the left of point, moving point to the left
20797 requires walking, one grapheme cluster at a time, until we
20798 find ourself at a place immediately to the left of the
20799 character at point. */
20800 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20802 struct text_pos new_pos
;
20803 enum move_it_result rc
= MOVE_X_REACHED
;
20805 if (it
.current_x
== 0)
20806 get_next_display_element (&it
);
20807 if (it
.what
== IT_COMPOSITION
)
20809 new_pos
.charpos
= it
.cmp_it
.charpos
;
20810 new_pos
.bytepos
= -1;
20813 new_pos
= it
.current
.pos
;
20815 while (it
.current_x
+ it
.pixel_width
<= target_x
20816 && rc
== MOVE_X_REACHED
)
20818 int new_x
= it
.current_x
+ it
.pixel_width
;
20820 /* For composed characters, we want the position of the
20821 first character in the grapheme cluster (usually, the
20822 composition's base character), whereas it.current
20823 might give us the position of the _last_ one, e.g. if
20824 the composition is rendered in reverse due to bidi
20826 if (it
.what
== IT_COMPOSITION
)
20828 new_pos
.charpos
= it
.cmp_it
.charpos
;
20829 new_pos
.bytepos
= -1;
20832 new_pos
= it
.current
.pos
;
20833 if (new_x
== it
.current_x
)
20835 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20836 MOVE_TO_POS
| MOVE_TO_X
);
20837 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20840 /* The previous position we saw in the loop is the one we
20842 if (new_pos
.bytepos
== -1)
20843 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20844 it
.current
.pos
= new_pos
;
20848 if (it
.current_x
!= target_x
)
20849 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20851 /* When lines are truncated, the above loop will stop at the
20852 window edge. But we want to get to the end of line, even if
20853 it is beyond the window edge; automatic hscroll will then
20854 scroll the window to show point as appropriate. */
20855 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20856 && get_next_display_element (&it
))
20858 struct text_pos new_pos
= it
.current
.pos
;
20860 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20862 set_iterator_to_next (&it
, 0);
20863 if (it
.method
== GET_FROM_BUFFER
)
20864 new_pos
= it
.current
.pos
;
20865 if (!get_next_display_element (&it
))
20869 it
.current
.pos
= new_pos
;
20872 /* If we ended up in a display string that covers point, move to
20873 buffer position to the right in the visual order. */
20876 while (IT_CHARPOS (it
) == PT
)
20878 set_iterator_to_next (&it
, 0);
20879 if (!get_next_display_element (&it
))
20884 /* Move point to that position. */
20885 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20888 return make_number (PT
);
20890 #undef ROW_GLYPH_NEWLINE_P
20894 /***********************************************************************
20896 ***********************************************************************/
20898 /* Redisplay the menu bar in the frame for window W.
20900 The menu bar of X frames that don't have X toolkit support is
20901 displayed in a special window W->frame->menu_bar_window.
20903 The menu bar of terminal frames is treated specially as far as
20904 glyph matrices are concerned. Menu bar lines are not part of
20905 windows, so the update is done directly on the frame matrix rows
20906 for the menu bar. */
20909 display_menu_bar (struct window
*w
)
20911 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20916 /* Don't do all this for graphical frames. */
20918 if (FRAME_W32_P (f
))
20921 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20927 if (FRAME_NS_P (f
))
20929 #endif /* HAVE_NS */
20931 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20932 eassert (!FRAME_WINDOW_P (f
));
20933 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20934 it
.first_visible_x
= 0;
20935 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
20936 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20937 if (FRAME_WINDOW_P (f
))
20939 /* Menu bar lines are displayed in the desired matrix of the
20940 dummy window menu_bar_window. */
20941 struct window
*menu_w
;
20942 menu_w
= XWINDOW (f
->menu_bar_window
);
20943 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20945 it
.first_visible_x
= 0;
20946 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
20949 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20951 /* This is a TTY frame, i.e. character hpos/vpos are used as
20953 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20955 it
.first_visible_x
= 0;
20956 it
.last_visible_x
= FRAME_COLS (f
);
20959 /* FIXME: This should be controlled by a user option. See the
20960 comments in redisplay_tool_bar and display_mode_line about
20962 it
.paragraph_embedding
= L2R
;
20964 /* Clear all rows of the menu bar. */
20965 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20967 struct glyph_row
*row
= it
.glyph_row
+ i
;
20968 clear_glyph_row (row
);
20969 row
->enabled_p
= true;
20970 row
->full_width_p
= 1;
20973 /* Display all items of the menu bar. */
20974 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20975 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20977 Lisp_Object string
;
20979 /* Stop at nil string. */
20980 string
= AREF (items
, i
+ 1);
20984 /* Remember where item was displayed. */
20985 ASET (items
, i
+ 3, make_number (it
.hpos
));
20987 /* Display the item, pad with one space. */
20988 if (it
.current_x
< it
.last_visible_x
)
20989 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20990 SCHARS (string
) + 1, 0, 0, -1);
20993 /* Fill out the line with spaces. */
20994 if (it
.current_x
< it
.last_visible_x
)
20995 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20997 /* Compute the total height of the lines. */
20998 compute_line_metrics (&it
);
21001 /* Deep copy of a glyph row, including the glyphs. */
21003 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
21005 struct glyph
*pointers
[1 + LAST_AREA
];
21006 int to_used
= to
->used
[TEXT_AREA
];
21008 /* Save glyph pointers of TO. */
21009 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
21011 /* Do a structure assignment. */
21014 /* Restore original glyph pointers of TO. */
21015 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
21017 /* Copy the glyphs. */
21018 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
21019 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
21021 /* If we filled only part of the TO row, fill the rest with
21022 space_glyph (which will display as empty space). */
21023 if (to_used
> from
->used
[TEXT_AREA
])
21024 fill_up_frame_row_with_spaces (to
, to_used
);
21027 /* Display one menu item on a TTY, by overwriting the glyphs in the
21028 frame F's desired glyph matrix with glyphs produced from the menu
21029 item text. Called from term.c to display TTY drop-down menus one
21032 ITEM_TEXT is the menu item text as a C string.
21034 FACE_ID is the face ID to be used for this menu item. FACE_ID
21035 could specify one of 3 faces: a face for an enabled item, a face
21036 for a disabled item, or a face for a selected item.
21038 X and Y are coordinates of the first glyph in the frame's desired
21039 matrix to be overwritten by the menu item. Since this is a TTY, Y
21040 is the zero-based number of the glyph row and X is the zero-based
21041 glyph number in the row, starting from left, where to start
21042 displaying the item.
21044 SUBMENU non-zero means this menu item drops down a submenu, which
21045 should be indicated by displaying a proper visual cue after the
21049 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
21050 int x
, int y
, int submenu
)
21053 struct frame
*f
= SELECTED_FRAME ();
21054 struct window
*w
= XWINDOW (f
->selected_window
);
21055 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
21056 struct glyph_row
*row
;
21057 size_t item_len
= strlen (item_text
);
21059 eassert (FRAME_TERMCAP_P (f
));
21061 /* Don't write beyond the matrix's last row. This can happen for
21062 TTY screens that are not high enough to show the entire menu.
21063 (This is actually a bit of defensive programming, as
21064 tty_menu_display already limits the number of menu items to one
21065 less than the number of screen lines.) */
21066 if (y
>= f
->desired_matrix
->nrows
)
21069 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
21070 it
.first_visible_x
= 0;
21071 it
.last_visible_x
= FRAME_COLS (f
) - 1;
21072 row
= it
.glyph_row
;
21073 /* Start with the row contents from the current matrix. */
21074 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
21075 saved_width
= row
->full_width_p
;
21076 row
->full_width_p
= 1;
21077 saved_reversed
= row
->reversed_p
;
21078 row
->reversed_p
= 0;
21079 row
->enabled_p
= true;
21081 /* Arrange for the menu item glyphs to start at (X,Y) and have the
21083 eassert (x
< f
->desired_matrix
->matrix_w
);
21084 it
.current_x
= it
.hpos
= x
;
21085 it
.current_y
= it
.vpos
= y
;
21086 saved_used
= row
->used
[TEXT_AREA
];
21087 saved_truncated
= row
->truncated_on_right_p
;
21088 row
->used
[TEXT_AREA
] = x
;
21089 it
.face_id
= face_id
;
21090 it
.line_wrap
= TRUNCATE
;
21092 /* FIXME: This should be controlled by a user option. See the
21093 comments in redisplay_tool_bar and display_mode_line about this.
21094 Also, if paragraph_embedding could ever be R2L, changes will be
21095 needed to avoid shifting to the right the row characters in
21096 term.c:append_glyph. */
21097 it
.paragraph_embedding
= L2R
;
21099 /* Pad with a space on the left. */
21100 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
21102 /* Display the menu item, pad with spaces to WIDTH. */
21105 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21106 item_len
, 0, FRAME_COLS (f
) - 1, -1);
21108 /* Indicate with " >" that there's a submenu. */
21109 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
21110 FRAME_COLS (f
) - 1, -1);
21113 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21114 width
, 0, FRAME_COLS (f
) - 1, -1);
21116 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
21117 row
->truncated_on_right_p
= saved_truncated
;
21118 row
->hash
= row_hash (row
);
21119 row
->full_width_p
= saved_width
;
21120 row
->reversed_p
= saved_reversed
;
21123 /***********************************************************************
21125 ***********************************************************************/
21127 /* Redisplay mode lines in the window tree whose root is WINDOW. If
21128 FORCE is non-zero, redisplay mode lines unconditionally.
21129 Otherwise, redisplay only mode lines that are garbaged. Value is
21130 the number of windows whose mode lines were redisplayed. */
21133 redisplay_mode_lines (Lisp_Object window
, bool force
)
21137 while (!NILP (window
))
21139 struct window
*w
= XWINDOW (window
);
21141 if (WINDOWP (w
->contents
))
21142 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
21144 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
21145 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
21147 struct text_pos lpoint
;
21148 struct buffer
*old
= current_buffer
;
21150 /* Set the window's buffer for the mode line display. */
21151 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
21152 set_buffer_internal_1 (XBUFFER (w
->contents
));
21154 /* Point refers normally to the selected window. For any
21155 other window, set up appropriate value. */
21156 if (!EQ (window
, selected_window
))
21158 struct text_pos pt
;
21160 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
21161 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
21164 /* Display mode lines. */
21165 clear_glyph_matrix (w
->desired_matrix
);
21166 if (display_mode_lines (w
))
21169 /* Restore old settings. */
21170 set_buffer_internal_1 (old
);
21171 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
21181 /* Display the mode and/or header line of window W. Value is the
21182 sum number of mode lines and header lines displayed. */
21185 display_mode_lines (struct window
*w
)
21187 Lisp_Object old_selected_window
= selected_window
;
21188 Lisp_Object old_selected_frame
= selected_frame
;
21189 Lisp_Object new_frame
= w
->frame
;
21190 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
21193 selected_frame
= new_frame
;
21194 /* FIXME: If we were to allow the mode-line's computation changing the buffer
21195 or window's point, then we'd need select_window_1 here as well. */
21196 XSETWINDOW (selected_window
, w
);
21197 XFRAME (new_frame
)->selected_window
= selected_window
;
21199 /* These will be set while the mode line specs are processed. */
21200 line_number_displayed
= 0;
21201 w
->column_number_displayed
= -1;
21203 if (WINDOW_WANTS_MODELINE_P (w
))
21205 struct window
*sel_w
= XWINDOW (old_selected_window
);
21207 /* Select mode line face based on the real selected window. */
21208 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
21209 BVAR (current_buffer
, mode_line_format
));
21213 if (WINDOW_WANTS_HEADER_LINE_P (w
))
21215 display_mode_line (w
, HEADER_LINE_FACE_ID
,
21216 BVAR (current_buffer
, header_line_format
));
21220 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
21221 selected_frame
= old_selected_frame
;
21222 selected_window
= old_selected_window
;
21224 w
->must_be_updated_p
= true;
21229 /* Display mode or header line of window W. FACE_ID specifies which
21230 line to display; it is either MODE_LINE_FACE_ID or
21231 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
21232 display. Value is the pixel height of the mode/header line
21236 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
21240 ptrdiff_t count
= SPECPDL_INDEX ();
21242 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21243 /* Don't extend on a previously drawn mode-line.
21244 This may happen if called from pos_visible_p. */
21245 it
.glyph_row
->enabled_p
= false;
21246 prepare_desired_row (it
.glyph_row
);
21248 it
.glyph_row
->mode_line_p
= 1;
21250 /* FIXME: This should be controlled by a user option. But
21251 supporting such an option is not trivial, since the mode line is
21252 made up of many separate strings. */
21253 it
.paragraph_embedding
= L2R
;
21255 record_unwind_protect (unwind_format_mode_line
,
21256 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
21258 mode_line_target
= MODE_LINE_DISPLAY
;
21260 /* Temporarily make frame's keyboard the current kboard so that
21261 kboard-local variables in the mode_line_format will get the right
21263 push_kboard (FRAME_KBOARD (it
.f
));
21264 record_unwind_save_match_data ();
21265 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21268 unbind_to (count
, Qnil
);
21270 /* Fill up with spaces. */
21271 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
21273 compute_line_metrics (&it
);
21274 it
.glyph_row
->full_width_p
= 1;
21275 it
.glyph_row
->continued_p
= 0;
21276 it
.glyph_row
->truncated_on_left_p
= 0;
21277 it
.glyph_row
->truncated_on_right_p
= 0;
21279 /* Make a 3D mode-line have a shadow at its right end. */
21280 face
= FACE_FROM_ID (it
.f
, face_id
);
21281 extend_face_to_end_of_line (&it
);
21282 if (face
->box
!= FACE_NO_BOX
)
21284 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
21285 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
21286 last
->right_box_line_p
= 1;
21289 return it
.glyph_row
->height
;
21292 /* Move element ELT in LIST to the front of LIST.
21293 Return the updated list. */
21296 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
21298 register Lisp_Object tail
, prev
;
21299 register Lisp_Object tem
;
21303 while (CONSP (tail
))
21309 /* Splice out the link TAIL. */
21311 list
= XCDR (tail
);
21313 Fsetcdr (prev
, XCDR (tail
));
21315 /* Now make it the first. */
21316 Fsetcdr (tail
, list
);
21321 tail
= XCDR (tail
);
21325 /* Not found--return unchanged LIST. */
21329 /* Contribute ELT to the mode line for window IT->w. How it
21330 translates into text depends on its data type.
21332 IT describes the display environment in which we display, as usual.
21334 DEPTH is the depth in recursion. It is used to prevent
21335 infinite recursion here.
21337 FIELD_WIDTH is the number of characters the display of ELT should
21338 occupy in the mode line, and PRECISION is the maximum number of
21339 characters to display from ELT's representation. See
21340 display_string for details.
21342 Returns the hpos of the end of the text generated by ELT.
21344 PROPS is a property list to add to any string we encounter.
21346 If RISKY is nonzero, remove (disregard) any properties in any string
21347 we encounter, and ignore :eval and :propertize.
21349 The global variable `mode_line_target' determines whether the
21350 output is passed to `store_mode_line_noprop',
21351 `store_mode_line_string', or `display_string'. */
21354 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
21355 Lisp_Object elt
, Lisp_Object props
, int risky
)
21357 int n
= 0, field
, prec
;
21362 elt
= build_string ("*too-deep*");
21366 switch (XTYPE (elt
))
21370 /* A string: output it and check for %-constructs within it. */
21372 ptrdiff_t offset
= 0;
21374 if (SCHARS (elt
) > 0
21375 && (!NILP (props
) || risky
))
21377 Lisp_Object oprops
, aelt
;
21378 oprops
= Ftext_properties_at (make_number (0), elt
);
21380 /* If the starting string's properties are not what
21381 we want, translate the string. Also, if the string
21382 is risky, do that anyway. */
21384 if (NILP (Fequal (props
, oprops
)) || risky
)
21386 /* If the starting string has properties,
21387 merge the specified ones onto the existing ones. */
21388 if (! NILP (oprops
) && !risky
)
21392 oprops
= Fcopy_sequence (oprops
);
21394 while (CONSP (tem
))
21396 oprops
= Fplist_put (oprops
, XCAR (tem
),
21397 XCAR (XCDR (tem
)));
21398 tem
= XCDR (XCDR (tem
));
21403 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21404 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21406 /* AELT is what we want. Move it to the front
21407 without consing. */
21409 mode_line_proptrans_alist
21410 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21416 /* If AELT has the wrong props, it is useless.
21417 so get rid of it. */
21419 mode_line_proptrans_alist
21420 = Fdelq (aelt
, mode_line_proptrans_alist
);
21422 elt
= Fcopy_sequence (elt
);
21423 Fset_text_properties (make_number (0), Flength (elt
),
21425 /* Add this item to mode_line_proptrans_alist. */
21426 mode_line_proptrans_alist
21427 = Fcons (Fcons (elt
, props
),
21428 mode_line_proptrans_alist
);
21429 /* Truncate mode_line_proptrans_alist
21430 to at most 50 elements. */
21431 tem
= Fnthcdr (make_number (50),
21432 mode_line_proptrans_alist
);
21434 XSETCDR (tem
, Qnil
);
21443 prec
= precision
- n
;
21444 switch (mode_line_target
)
21446 case MODE_LINE_NOPROP
:
21447 case MODE_LINE_TITLE
:
21448 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21450 case MODE_LINE_STRING
:
21451 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21453 case MODE_LINE_DISPLAY
:
21454 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21455 0, prec
, 0, STRING_MULTIBYTE (elt
));
21462 /* Handle the non-literal case. */
21464 while ((precision
<= 0 || n
< precision
)
21465 && SREF (elt
, offset
) != 0
21466 && (mode_line_target
!= MODE_LINE_DISPLAY
21467 || it
->current_x
< it
->last_visible_x
))
21469 ptrdiff_t last_offset
= offset
;
21471 /* Advance to end of string or next format specifier. */
21472 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21475 if (offset
- 1 != last_offset
)
21477 ptrdiff_t nchars
, nbytes
;
21479 /* Output to end of string or up to '%'. Field width
21480 is length of string. Don't output more than
21481 PRECISION allows us. */
21484 prec
= c_string_width (SDATA (elt
) + last_offset
,
21485 offset
- last_offset
, precision
- n
,
21488 switch (mode_line_target
)
21490 case MODE_LINE_NOPROP
:
21491 case MODE_LINE_TITLE
:
21492 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21494 case MODE_LINE_STRING
:
21496 ptrdiff_t bytepos
= last_offset
;
21497 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21498 ptrdiff_t endpos
= (precision
<= 0
21499 ? string_byte_to_char (elt
, offset
)
21500 : charpos
+ nchars
);
21502 n
+= store_mode_line_string (NULL
,
21503 Fsubstring (elt
, make_number (charpos
),
21504 make_number (endpos
)),
21508 case MODE_LINE_DISPLAY
:
21510 ptrdiff_t bytepos
= last_offset
;
21511 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21513 if (precision
<= 0)
21514 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21515 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21517 STRING_MULTIBYTE (elt
));
21522 else /* c == '%' */
21524 ptrdiff_t percent_position
= offset
;
21526 /* Get the specified minimum width. Zero means
21529 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21530 field
= field
* 10 + c
- '0';
21532 /* Don't pad beyond the total padding allowed. */
21533 if (field_width
- n
> 0 && field
> field_width
- n
)
21534 field
= field_width
- n
;
21536 /* Note that either PRECISION <= 0 or N < PRECISION. */
21537 prec
= precision
- n
;
21540 n
+= display_mode_element (it
, depth
, field
, prec
,
21541 Vglobal_mode_string
, props
,
21546 ptrdiff_t bytepos
, charpos
;
21548 Lisp_Object string
;
21550 bytepos
= percent_position
;
21551 charpos
= (STRING_MULTIBYTE (elt
)
21552 ? string_byte_to_char (elt
, bytepos
)
21554 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21555 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21557 switch (mode_line_target
)
21559 case MODE_LINE_NOPROP
:
21560 case MODE_LINE_TITLE
:
21561 n
+= store_mode_line_noprop (spec
, field
, prec
);
21563 case MODE_LINE_STRING
:
21565 Lisp_Object tem
= build_string (spec
);
21566 props
= Ftext_properties_at (make_number (charpos
), elt
);
21567 /* Should only keep face property in props */
21568 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21571 case MODE_LINE_DISPLAY
:
21573 int nglyphs_before
, nwritten
;
21575 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21576 nwritten
= display_string (spec
, string
, elt
,
21581 /* Assign to the glyphs written above the
21582 string where the `%x' came from, position
21586 struct glyph
*glyph
21587 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21591 for (i
= 0; i
< nwritten
; ++i
)
21593 glyph
[i
].object
= elt
;
21594 glyph
[i
].charpos
= charpos
;
21611 /* A symbol: process the value of the symbol recursively
21612 as if it appeared here directly. Avoid error if symbol void.
21613 Special case: if value of symbol is a string, output the string
21616 register Lisp_Object tem
;
21618 /* If the variable is not marked as risky to set
21619 then its contents are risky to use. */
21620 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21623 tem
= Fboundp (elt
);
21626 tem
= Fsymbol_value (elt
);
21627 /* If value is a string, output that string literally:
21628 don't check for % within it. */
21632 if (!EQ (tem
, elt
))
21634 /* Give up right away for nil or t. */
21644 register Lisp_Object car
, tem
;
21646 /* A cons cell: five distinct cases.
21647 If first element is :eval or :propertize, do something special.
21648 If first element is a string or a cons, process all the elements
21649 and effectively concatenate them.
21650 If first element is a negative number, truncate displaying cdr to
21651 at most that many characters. If positive, pad (with spaces)
21652 to at least that many characters.
21653 If first element is a symbol, process the cadr or caddr recursively
21654 according to whether the symbol's value is non-nil or nil. */
21656 if (EQ (car
, QCeval
))
21658 /* An element of the form (:eval FORM) means evaluate FORM
21659 and use the result as mode line elements. */
21664 if (CONSP (XCDR (elt
)))
21667 spec
= safe_eval (XCAR (XCDR (elt
)));
21668 n
+= display_mode_element (it
, depth
, field_width
- n
,
21669 precision
- n
, spec
, props
,
21673 else if (EQ (car
, QCpropertize
))
21675 /* An element of the form (:propertize ELT PROPS...)
21676 means display ELT but applying properties PROPS. */
21681 if (CONSP (XCDR (elt
)))
21682 n
+= display_mode_element (it
, depth
, field_width
- n
,
21683 precision
- n
, XCAR (XCDR (elt
)),
21684 XCDR (XCDR (elt
)), risky
);
21686 else if (SYMBOLP (car
))
21688 tem
= Fboundp (car
);
21692 /* elt is now the cdr, and we know it is a cons cell.
21693 Use its car if CAR has a non-nil value. */
21696 tem
= Fsymbol_value (car
);
21703 /* Symbol's value is nil (or symbol is unbound)
21704 Get the cddr of the original list
21705 and if possible find the caddr and use that. */
21709 else if (!CONSP (elt
))
21714 else if (INTEGERP (car
))
21716 register int lim
= XINT (car
);
21720 /* Negative int means reduce maximum width. */
21721 if (precision
<= 0)
21724 precision
= min (precision
, -lim
);
21728 /* Padding specified. Don't let it be more than
21729 current maximum. */
21731 lim
= min (precision
, lim
);
21733 /* If that's more padding than already wanted, queue it.
21734 But don't reduce padding already specified even if
21735 that is beyond the current truncation point. */
21736 field_width
= max (lim
, field_width
);
21740 else if (STRINGP (car
) || CONSP (car
))
21742 Lisp_Object halftail
= elt
;
21746 && (precision
<= 0 || n
< precision
))
21748 n
+= display_mode_element (it
, depth
,
21749 /* Do padding only after the last
21750 element in the list. */
21751 (! CONSP (XCDR (elt
))
21754 precision
- n
, XCAR (elt
),
21758 if ((len
& 1) == 0)
21759 halftail
= XCDR (halftail
);
21760 /* Check for cycle. */
21761 if (EQ (halftail
, elt
))
21770 elt
= build_string ("*invalid*");
21774 /* Pad to FIELD_WIDTH. */
21775 if (field_width
> 0 && n
< field_width
)
21777 switch (mode_line_target
)
21779 case MODE_LINE_NOPROP
:
21780 case MODE_LINE_TITLE
:
21781 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21783 case MODE_LINE_STRING
:
21784 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21786 case MODE_LINE_DISPLAY
:
21787 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21796 /* Store a mode-line string element in mode_line_string_list.
21798 If STRING is non-null, display that C string. Otherwise, the Lisp
21799 string LISP_STRING is displayed.
21801 FIELD_WIDTH is the minimum number of output glyphs to produce.
21802 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21803 with spaces. FIELD_WIDTH <= 0 means don't pad.
21805 PRECISION is the maximum number of characters to output from
21806 STRING. PRECISION <= 0 means don't truncate the string.
21808 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21809 properties to the string.
21811 PROPS are the properties to add to the string.
21812 The mode_line_string_face face property is always added to the string.
21816 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21817 int field_width
, int precision
, Lisp_Object props
)
21822 if (string
!= NULL
)
21824 len
= strlen (string
);
21825 if (precision
> 0 && len
> precision
)
21827 lisp_string
= make_string (string
, len
);
21829 props
= mode_line_string_face_prop
;
21830 else if (!NILP (mode_line_string_face
))
21832 Lisp_Object face
= Fplist_get (props
, Qface
);
21833 props
= Fcopy_sequence (props
);
21835 face
= mode_line_string_face
;
21837 face
= list2 (face
, mode_line_string_face
);
21838 props
= Fplist_put (props
, Qface
, face
);
21840 Fadd_text_properties (make_number (0), make_number (len
),
21841 props
, lisp_string
);
21845 len
= XFASTINT (Flength (lisp_string
));
21846 if (precision
> 0 && len
> precision
)
21849 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21852 if (!NILP (mode_line_string_face
))
21856 props
= Ftext_properties_at (make_number (0), lisp_string
);
21857 face
= Fplist_get (props
, Qface
);
21859 face
= mode_line_string_face
;
21861 face
= list2 (face
, mode_line_string_face
);
21862 props
= list2 (Qface
, face
);
21864 lisp_string
= Fcopy_sequence (lisp_string
);
21867 Fadd_text_properties (make_number (0), make_number (len
),
21868 props
, lisp_string
);
21873 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21877 if (field_width
> len
)
21879 field_width
-= len
;
21880 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21882 Fadd_text_properties (make_number (0), make_number (field_width
),
21883 props
, lisp_string
);
21884 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21892 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21894 doc
: /* Format a string out of a mode line format specification.
21895 First arg FORMAT specifies the mode line format (see `mode-line-format'
21896 for details) to use.
21898 By default, the format is evaluated for the currently selected window.
21900 Optional second arg FACE specifies the face property to put on all
21901 characters for which no face is specified. The value nil means the
21902 default face. The value t means whatever face the window's mode line
21903 currently uses (either `mode-line' or `mode-line-inactive',
21904 depending on whether the window is the selected window or not).
21905 An integer value means the value string has no text
21908 Optional third and fourth args WINDOW and BUFFER specify the window
21909 and buffer to use as the context for the formatting (defaults
21910 are the selected window and the WINDOW's buffer). */)
21911 (Lisp_Object format
, Lisp_Object face
,
21912 Lisp_Object window
, Lisp_Object buffer
)
21917 struct buffer
*old_buffer
= NULL
;
21919 int no_props
= INTEGERP (face
);
21920 ptrdiff_t count
= SPECPDL_INDEX ();
21922 int string_start
= 0;
21924 w
= decode_any_window (window
);
21925 XSETWINDOW (window
, w
);
21928 buffer
= w
->contents
;
21929 CHECK_BUFFER (buffer
);
21931 /* Make formatting the modeline a non-op when noninteractive, otherwise
21932 there will be problems later caused by a partially initialized frame. */
21933 if (NILP (format
) || noninteractive
)
21934 return empty_unibyte_string
;
21939 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21940 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21941 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21942 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21943 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21944 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21945 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21948 old_buffer
= current_buffer
;
21950 /* Save things including mode_line_proptrans_alist,
21951 and set that to nil so that we don't alter the outer value. */
21952 record_unwind_protect (unwind_format_mode_line
,
21953 format_mode_line_unwind_data
21954 (XFRAME (WINDOW_FRAME (w
)),
21955 old_buffer
, selected_window
, 1));
21956 mode_line_proptrans_alist
= Qnil
;
21958 Fselect_window (window
, Qt
);
21959 set_buffer_internal_1 (XBUFFER (buffer
));
21961 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21965 mode_line_target
= MODE_LINE_NOPROP
;
21966 mode_line_string_face_prop
= Qnil
;
21967 mode_line_string_list
= Qnil
;
21968 string_start
= MODE_LINE_NOPROP_LEN (0);
21972 mode_line_target
= MODE_LINE_STRING
;
21973 mode_line_string_list
= Qnil
;
21974 mode_line_string_face
= face
;
21975 mode_line_string_face_prop
21976 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21979 push_kboard (FRAME_KBOARD (it
.f
));
21980 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21985 len
= MODE_LINE_NOPROP_LEN (string_start
);
21986 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21990 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21991 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21992 empty_unibyte_string
);
21995 unbind_to (count
, Qnil
);
21999 /* Write a null-terminated, right justified decimal representation of
22000 the positive integer D to BUF using a minimal field width WIDTH. */
22003 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
22005 register char *p
= buf
;
22013 *p
++ = d
% 10 + '0';
22018 for (width
-= (int) (p
- buf
); width
> 0; --width
)
22029 /* Write a null-terminated, right justified decimal and "human
22030 readable" representation of the nonnegative integer D to BUF using
22031 a minimal field width WIDTH. D should be smaller than 999.5e24. */
22033 static const char power_letter
[] =
22047 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
22049 /* We aim to represent the nonnegative integer D as
22050 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
22051 ptrdiff_t quotient
= d
;
22053 /* -1 means: do not use TENTHS. */
22057 /* Length of QUOTIENT.TENTHS as a string. */
22063 if (quotient
>= 1000)
22065 /* Scale to the appropriate EXPONENT. */
22068 remainder
= quotient
% 1000;
22072 while (quotient
>= 1000);
22074 /* Round to nearest and decide whether to use TENTHS or not. */
22077 tenths
= remainder
/ 100;
22078 if (remainder
% 100 >= 50)
22085 if (quotient
== 10)
22093 if (remainder
>= 500)
22095 if (quotient
< 999)
22106 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
22107 if (tenths
== -1 && quotient
<= 99)
22114 p
= psuffix
= buf
+ max (width
, length
);
22116 /* Print EXPONENT. */
22117 *psuffix
++ = power_letter
[exponent
];
22120 /* Print TENTHS. */
22123 *--p
= '0' + tenths
;
22127 /* Print QUOTIENT. */
22130 int digit
= quotient
% 10;
22131 *--p
= '0' + digit
;
22133 while ((quotient
/= 10) != 0);
22135 /* Print leading spaces. */
22140 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
22141 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
22142 type of CODING_SYSTEM. Return updated pointer into BUF. */
22144 static unsigned char invalid_eol_type
[] = "(*invalid*)";
22147 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
22150 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
22151 const unsigned char *eol_str
;
22153 /* The EOL conversion we are using. */
22154 Lisp_Object eoltype
;
22156 val
= CODING_SYSTEM_SPEC (coding_system
);
22159 if (!VECTORP (val
)) /* Not yet decided. */
22161 *buf
++ = multibyte
? '-' : ' ';
22163 eoltype
= eol_mnemonic_undecided
;
22164 /* Don't mention EOL conversion if it isn't decided. */
22169 Lisp_Object eolvalue
;
22171 attrs
= AREF (val
, 0);
22172 eolvalue
= AREF (val
, 2);
22175 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
22180 /* The EOL conversion that is normal on this system. */
22182 if (NILP (eolvalue
)) /* Not yet decided. */
22183 eoltype
= eol_mnemonic_undecided
;
22184 else if (VECTORP (eolvalue
)) /* Not yet decided. */
22185 eoltype
= eol_mnemonic_undecided
;
22186 else /* eolvalue is Qunix, Qdos, or Qmac. */
22187 eoltype
= (EQ (eolvalue
, Qunix
)
22188 ? eol_mnemonic_unix
22189 : (EQ (eolvalue
, Qdos
) == 1
22190 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
22196 /* Mention the EOL conversion if it is not the usual one. */
22197 if (STRINGP (eoltype
))
22199 eol_str
= SDATA (eoltype
);
22200 eol_str_len
= SBYTES (eoltype
);
22202 else if (CHARACTERP (eoltype
))
22204 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
22205 int c
= XFASTINT (eoltype
);
22206 eol_str_len
= CHAR_STRING (c
, tmp
);
22211 eol_str
= invalid_eol_type
;
22212 eol_str_len
= sizeof (invalid_eol_type
) - 1;
22214 memcpy (buf
, eol_str
, eol_str_len
);
22215 buf
+= eol_str_len
;
22221 /* Return a string for the output of a mode line %-spec for window W,
22222 generated by character C. FIELD_WIDTH > 0 means pad the string
22223 returned with spaces to that value. Return a Lisp string in
22224 *STRING if the resulting string is taken from that Lisp string.
22226 Note we operate on the current buffer for most purposes. */
22228 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
22230 static const char *
22231 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
22232 Lisp_Object
*string
)
22235 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22236 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
22237 /* We are going to use f->decode_mode_spec_buffer as the buffer to
22238 produce strings from numerical values, so limit preposterously
22239 large values of FIELD_WIDTH to avoid overrunning the buffer's
22240 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
22241 bytes plus the terminating null. */
22242 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
22243 struct buffer
*b
= current_buffer
;
22251 if (!NILP (BVAR (b
, read_only
)))
22253 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22258 /* This differs from %* only for a modified read-only buffer. */
22259 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22261 if (!NILP (BVAR (b
, read_only
)))
22266 /* This differs from %* in ignoring read-only-ness. */
22267 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22279 if (command_loop_level
> 5)
22281 p
= decode_mode_spec_buf
;
22282 for (i
= 0; i
< command_loop_level
; i
++)
22285 return decode_mode_spec_buf
;
22293 if (command_loop_level
> 5)
22295 p
= decode_mode_spec_buf
;
22296 for (i
= 0; i
< command_loop_level
; i
++)
22299 return decode_mode_spec_buf
;
22306 /* Let lots_of_dashes be a string of infinite length. */
22307 if (mode_line_target
== MODE_LINE_NOPROP
22308 || mode_line_target
== MODE_LINE_STRING
)
22310 if (field_width
<= 0
22311 || field_width
> sizeof (lots_of_dashes
))
22313 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
22314 decode_mode_spec_buf
[i
] = '-';
22315 decode_mode_spec_buf
[i
] = '\0';
22316 return decode_mode_spec_buf
;
22319 return lots_of_dashes
;
22323 obj
= BVAR (b
, name
);
22327 /* %c and %l are ignored in `frame-title-format'.
22328 (In redisplay_internal, the frame title is drawn _before_ the
22329 windows are updated, so the stuff which depends on actual
22330 window contents (such as %l) may fail to render properly, or
22331 even crash emacs.) */
22332 if (mode_line_target
== MODE_LINE_TITLE
)
22336 ptrdiff_t col
= current_column ();
22337 w
->column_number_displayed
= col
;
22338 pint2str (decode_mode_spec_buf
, width
, col
);
22339 return decode_mode_spec_buf
;
22343 #ifndef SYSTEM_MALLOC
22345 if (NILP (Vmemory_full
))
22348 return "!MEM FULL! ";
22355 /* %F displays the frame name. */
22356 if (!NILP (f
->title
))
22357 return SSDATA (f
->title
);
22358 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
22359 return SSDATA (f
->name
);
22363 obj
= BVAR (b
, filename
);
22368 ptrdiff_t size
= ZV
- BEGV
;
22369 pint2str (decode_mode_spec_buf
, width
, size
);
22370 return decode_mode_spec_buf
;
22375 ptrdiff_t size
= ZV
- BEGV
;
22376 pint2hrstr (decode_mode_spec_buf
, width
, size
);
22377 return decode_mode_spec_buf
;
22382 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
22383 ptrdiff_t topline
, nlines
, height
;
22386 /* %c and %l are ignored in `frame-title-format'. */
22387 if (mode_line_target
== MODE_LINE_TITLE
)
22390 startpos
= marker_position (w
->start
);
22391 startpos_byte
= marker_byte_position (w
->start
);
22392 height
= WINDOW_TOTAL_LINES (w
);
22394 /* If we decided that this buffer isn't suitable for line numbers,
22395 don't forget that too fast. */
22396 if (w
->base_line_pos
== -1)
22399 /* If the buffer is very big, don't waste time. */
22400 if (INTEGERP (Vline_number_display_limit
)
22401 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22403 w
->base_line_pos
= 0;
22404 w
->base_line_number
= 0;
22408 if (w
->base_line_number
> 0
22409 && w
->base_line_pos
> 0
22410 && w
->base_line_pos
<= startpos
)
22412 line
= w
->base_line_number
;
22413 linepos
= w
->base_line_pos
;
22414 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22419 linepos
= BUF_BEGV (b
);
22420 linepos_byte
= BUF_BEGV_BYTE (b
);
22423 /* Count lines from base line to window start position. */
22424 nlines
= display_count_lines (linepos_byte
,
22428 topline
= nlines
+ line
;
22430 /* Determine a new base line, if the old one is too close
22431 or too far away, or if we did not have one.
22432 "Too close" means it's plausible a scroll-down would
22433 go back past it. */
22434 if (startpos
== BUF_BEGV (b
))
22436 w
->base_line_number
= topline
;
22437 w
->base_line_pos
= BUF_BEGV (b
);
22439 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22440 || linepos
== BUF_BEGV (b
))
22442 ptrdiff_t limit
= BUF_BEGV (b
);
22443 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22444 ptrdiff_t position
;
22445 ptrdiff_t distance
=
22446 (height
* 2 + 30) * line_number_display_limit_width
;
22448 if (startpos
- distance
> limit
)
22450 limit
= startpos
- distance
;
22451 limit_byte
= CHAR_TO_BYTE (limit
);
22454 nlines
= display_count_lines (startpos_byte
,
22456 - (height
* 2 + 30),
22458 /* If we couldn't find the lines we wanted within
22459 line_number_display_limit_width chars per line,
22460 give up on line numbers for this window. */
22461 if (position
== limit_byte
&& limit
== startpos
- distance
)
22463 w
->base_line_pos
= -1;
22464 w
->base_line_number
= 0;
22468 w
->base_line_number
= topline
- nlines
;
22469 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22472 /* Now count lines from the start pos to point. */
22473 nlines
= display_count_lines (startpos_byte
,
22474 PT_BYTE
, PT
, &junk
);
22476 /* Record that we did display the line number. */
22477 line_number_displayed
= 1;
22479 /* Make the string to show. */
22480 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22481 return decode_mode_spec_buf
;
22484 char* p
= decode_mode_spec_buf
;
22485 int pad
= width
- 2;
22491 return decode_mode_spec_buf
;
22497 obj
= BVAR (b
, mode_name
);
22501 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22507 ptrdiff_t pos
= marker_position (w
->start
);
22508 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22510 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22512 if (pos
<= BUF_BEGV (b
))
22517 else if (pos
<= BUF_BEGV (b
))
22521 if (total
> 1000000)
22522 /* Do it differently for a large value, to avoid overflow. */
22523 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22525 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22526 /* We can't normally display a 3-digit number,
22527 so get us a 2-digit number that is close. */
22530 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22531 return decode_mode_spec_buf
;
22535 /* Display percentage of size above the bottom of the screen. */
22538 ptrdiff_t toppos
= marker_position (w
->start
);
22539 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22540 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22542 if (botpos
>= BUF_ZV (b
))
22544 if (toppos
<= BUF_BEGV (b
))
22551 if (total
> 1000000)
22552 /* Do it differently for a large value, to avoid overflow. */
22553 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22555 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22556 /* We can't normally display a 3-digit number,
22557 so get us a 2-digit number that is close. */
22560 if (toppos
<= BUF_BEGV (b
))
22561 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22563 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22564 return decode_mode_spec_buf
;
22569 /* status of process */
22570 obj
= Fget_buffer_process (Fcurrent_buffer ());
22572 return "no process";
22574 obj
= Fsymbol_name (Fprocess_status (obj
));
22580 ptrdiff_t count
= inhibit_garbage_collection ();
22581 Lisp_Object val
= call1 (intern ("file-remote-p"),
22582 BVAR (current_buffer
, directory
));
22583 unbind_to (count
, Qnil
);
22592 /* coding-system (not including end-of-line format) */
22594 /* coding-system (including end-of-line type) */
22596 int eol_flag
= (c
== 'Z');
22597 char *p
= decode_mode_spec_buf
;
22599 if (! FRAME_WINDOW_P (f
))
22601 /* No need to mention EOL here--the terminal never needs
22602 to do EOL conversion. */
22603 p
= decode_mode_spec_coding (CODING_ID_NAME
22604 (FRAME_KEYBOARD_CODING (f
)->id
),
22606 p
= decode_mode_spec_coding (CODING_ID_NAME
22607 (FRAME_TERMINAL_CODING (f
)->id
),
22610 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22613 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22614 #ifdef subprocesses
22615 obj
= Fget_buffer_process (Fcurrent_buffer ());
22616 if (PROCESSP (obj
))
22618 p
= decode_mode_spec_coding
22619 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22620 p
= decode_mode_spec_coding
22621 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22623 #endif /* subprocesses */
22626 return decode_mode_spec_buf
;
22633 return SSDATA (obj
);
22640 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22641 means count lines back from START_BYTE. But don't go beyond
22642 LIMIT_BYTE. Return the number of lines thus found (always
22645 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22646 either the position COUNT lines after/before START_BYTE, if we
22647 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22651 display_count_lines (ptrdiff_t start_byte
,
22652 ptrdiff_t limit_byte
, ptrdiff_t count
,
22653 ptrdiff_t *byte_pos_ptr
)
22655 register unsigned char *cursor
;
22656 unsigned char *base
;
22658 register ptrdiff_t ceiling
;
22659 register unsigned char *ceiling_addr
;
22660 ptrdiff_t orig_count
= count
;
22662 /* If we are not in selective display mode,
22663 check only for newlines. */
22664 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22665 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22669 while (start_byte
< limit_byte
)
22671 ceiling
= BUFFER_CEILING_OF (start_byte
);
22672 ceiling
= min (limit_byte
- 1, ceiling
);
22673 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22674 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22678 if (selective_display
)
22680 while (*cursor
!= '\n' && *cursor
!= 015
22681 && ++cursor
!= ceiling_addr
)
22683 if (cursor
== ceiling_addr
)
22688 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22697 start_byte
+= cursor
- base
;
22698 *byte_pos_ptr
= start_byte
;
22702 while (cursor
< ceiling_addr
);
22704 start_byte
+= ceiling_addr
- base
;
22709 while (start_byte
> limit_byte
)
22711 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22712 ceiling
= max (limit_byte
, ceiling
);
22713 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22714 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22717 if (selective_display
)
22719 while (--cursor
>= ceiling_addr
22720 && *cursor
!= '\n' && *cursor
!= 015)
22722 if (cursor
< ceiling_addr
)
22727 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22734 start_byte
+= cursor
- base
+ 1;
22735 *byte_pos_ptr
= start_byte
;
22736 /* When scanning backwards, we should
22737 not count the newline posterior to which we stop. */
22738 return - orig_count
- 1;
22741 start_byte
+= ceiling_addr
- base
;
22745 *byte_pos_ptr
= limit_byte
;
22748 return - orig_count
+ count
;
22749 return orig_count
- count
;
22755 /***********************************************************************
22757 ***********************************************************************/
22759 /* Display a NUL-terminated string, starting with index START.
22761 If STRING is non-null, display that C string. Otherwise, the Lisp
22762 string LISP_STRING is displayed. There's a case that STRING is
22763 non-null and LISP_STRING is not nil. It means STRING is a string
22764 data of LISP_STRING. In that case, we display LISP_STRING while
22765 ignoring its text properties.
22767 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22768 FACE_STRING. Display STRING or LISP_STRING with the face at
22769 FACE_STRING_POS in FACE_STRING:
22771 Display the string in the environment given by IT, but use the
22772 standard display table, temporarily.
22774 FIELD_WIDTH is the minimum number of output glyphs to produce.
22775 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22776 with spaces. If STRING has more characters, more than FIELD_WIDTH
22777 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22779 PRECISION is the maximum number of characters to output from
22780 STRING. PRECISION < 0 means don't truncate the string.
22782 This is roughly equivalent to printf format specifiers:
22784 FIELD_WIDTH PRECISION PRINTF
22785 ----------------------------------------
22791 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22792 display them, and < 0 means obey the current buffer's value of
22793 enable_multibyte_characters.
22795 Value is the number of columns displayed. */
22798 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22799 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22800 int field_width
, int precision
, int max_x
, int multibyte
)
22802 int hpos_at_start
= it
->hpos
;
22803 int saved_face_id
= it
->face_id
;
22804 struct glyph_row
*row
= it
->glyph_row
;
22805 ptrdiff_t it_charpos
;
22807 /* Initialize the iterator IT for iteration over STRING beginning
22808 with index START. */
22809 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22810 precision
, field_width
, multibyte
);
22811 if (string
&& STRINGP (lisp_string
))
22812 /* LISP_STRING is the one returned by decode_mode_spec. We should
22813 ignore its text properties. */
22814 it
->stop_charpos
= it
->end_charpos
;
22816 /* If displaying STRING, set up the face of the iterator from
22817 FACE_STRING, if that's given. */
22818 if (STRINGP (face_string
))
22824 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22825 0, &endptr
, it
->base_face_id
, 0);
22826 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22827 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22830 /* Set max_x to the maximum allowed X position. Don't let it go
22831 beyond the right edge of the window. */
22833 max_x
= it
->last_visible_x
;
22835 max_x
= min (max_x
, it
->last_visible_x
);
22837 /* Skip over display elements that are not visible. because IT->w is
22839 if (it
->current_x
< it
->first_visible_x
)
22840 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22841 MOVE_TO_POS
| MOVE_TO_X
);
22843 row
->ascent
= it
->max_ascent
;
22844 row
->height
= it
->max_ascent
+ it
->max_descent
;
22845 row
->phys_ascent
= it
->max_phys_ascent
;
22846 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22847 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22849 if (STRINGP (it
->string
))
22850 it_charpos
= IT_STRING_CHARPOS (*it
);
22852 it_charpos
= IT_CHARPOS (*it
);
22854 /* This condition is for the case that we are called with current_x
22855 past last_visible_x. */
22856 while (it
->current_x
< max_x
)
22858 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22860 /* Get the next display element. */
22861 if (!get_next_display_element (it
))
22864 /* Produce glyphs. */
22865 x_before
= it
->current_x
;
22866 n_glyphs_before
= row
->used
[TEXT_AREA
];
22867 PRODUCE_GLYPHS (it
);
22869 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22872 while (i
< nglyphs
)
22874 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22876 if (it
->line_wrap
!= TRUNCATE
22877 && x
+ glyph
->pixel_width
> max_x
)
22879 /* End of continued line or max_x reached. */
22880 if (CHAR_GLYPH_PADDING_P (*glyph
))
22882 /* A wide character is unbreakable. */
22883 if (row
->reversed_p
)
22884 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22885 - n_glyphs_before
);
22886 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22887 it
->current_x
= x_before
;
22891 if (row
->reversed_p
)
22892 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22893 - (n_glyphs_before
+ i
));
22894 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22899 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22901 /* Glyph is at least partially visible. */
22903 if (x
< it
->first_visible_x
)
22904 row
->x
= x
- it
->first_visible_x
;
22908 /* Glyph is off the left margin of the display area.
22909 Should not happen. */
22913 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22914 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22915 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22916 row
->phys_height
= max (row
->phys_height
,
22917 it
->max_phys_ascent
+ it
->max_phys_descent
);
22918 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22919 it
->max_extra_line_spacing
);
22920 x
+= glyph
->pixel_width
;
22924 /* Stop if max_x reached. */
22928 /* Stop at line ends. */
22929 if (ITERATOR_AT_END_OF_LINE_P (it
))
22931 it
->continuation_lines_width
= 0;
22935 set_iterator_to_next (it
, 1);
22936 if (STRINGP (it
->string
))
22937 it_charpos
= IT_STRING_CHARPOS (*it
);
22939 it_charpos
= IT_CHARPOS (*it
);
22941 /* Stop if truncating at the right edge. */
22942 if (it
->line_wrap
== TRUNCATE
22943 && it
->current_x
>= it
->last_visible_x
)
22945 /* Add truncation mark, but don't do it if the line is
22946 truncated at a padding space. */
22947 if (it_charpos
< it
->string_nchars
)
22949 if (!FRAME_WINDOW_P (it
->f
))
22953 if (it
->current_x
> it
->last_visible_x
)
22955 if (!row
->reversed_p
)
22957 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22958 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22963 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22964 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22966 unproduce_glyphs (it
, ii
+ 1);
22967 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22969 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22971 row
->used
[TEXT_AREA
] = ii
;
22972 produce_special_glyphs (it
, IT_TRUNCATION
);
22975 produce_special_glyphs (it
, IT_TRUNCATION
);
22977 row
->truncated_on_right_p
= 1;
22983 /* Maybe insert a truncation at the left. */
22984 if (it
->first_visible_x
22987 if (!FRAME_WINDOW_P (it
->f
)
22988 || (row
->reversed_p
22989 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22990 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22991 insert_left_trunc_glyphs (it
);
22992 row
->truncated_on_left_p
= 1;
22995 it
->face_id
= saved_face_id
;
22997 /* Value is number of columns displayed. */
22998 return it
->hpos
- hpos_at_start
;
23003 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
23004 appears as an element of LIST or as the car of an element of LIST.
23005 If PROPVAL is a list, compare each element against LIST in that
23006 way, and return 1/2 if any element of PROPVAL is found in LIST.
23007 Otherwise return 0. This function cannot quit.
23008 The return value is 2 if the text is invisible but with an ellipsis
23009 and 1 if it's invisible and without an ellipsis. */
23012 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
23014 register Lisp_Object tail
, proptail
;
23016 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
23018 register Lisp_Object tem
;
23020 if (EQ (propval
, tem
))
23022 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
23023 return NILP (XCDR (tem
)) ? 1 : 2;
23026 if (CONSP (propval
))
23028 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
23030 Lisp_Object propelt
;
23031 propelt
= XCAR (proptail
);
23032 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
23034 register Lisp_Object tem
;
23036 if (EQ (propelt
, tem
))
23038 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
23039 return NILP (XCDR (tem
)) ? 1 : 2;
23047 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
23048 doc
: /* Non-nil if the property makes the text invisible.
23049 POS-OR-PROP can be a marker or number, in which case it is taken to be
23050 a position in the current buffer and the value of the `invisible' property
23051 is checked; or it can be some other value, which is then presumed to be the
23052 value of the `invisible' property of the text of interest.
23053 The non-nil value returned can be t for truly invisible text or something
23054 else if the text is replaced by an ellipsis. */)
23055 (Lisp_Object pos_or_prop
)
23058 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
23059 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
23061 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
23062 return (invis
== 0 ? Qnil
23064 : make_number (invis
));
23067 /* Calculate a width or height in pixels from a specification using
23068 the following elements:
23071 NUM - a (fractional) multiple of the default font width/height
23072 (NUM) - specifies exactly NUM pixels
23073 UNIT - a fixed number of pixels, see below.
23074 ELEMENT - size of a display element in pixels, see below.
23075 (NUM . SPEC) - equals NUM * SPEC
23076 (+ SPEC SPEC ...) - add pixel values
23077 (- SPEC SPEC ...) - subtract pixel values
23078 (- SPEC) - negate pixel value
23081 INT or FLOAT - a number constant
23082 SYMBOL - use symbol's (buffer local) variable binding.
23085 in - pixels per inch *)
23086 mm - pixels per 1/1000 meter *)
23087 cm - pixels per 1/100 meter *)
23088 width - width of current font in pixels.
23089 height - height of current font in pixels.
23091 *) using the ratio(s) defined in display-pixels-per-inch.
23095 left-fringe - left fringe width in pixels
23096 right-fringe - right fringe width in pixels
23098 left-margin - left margin width in pixels
23099 right-margin - right margin width in pixels
23101 scroll-bar - scroll-bar area width in pixels
23105 Pixels corresponding to 5 inches:
23108 Total width of non-text areas on left side of window (if scroll-bar is on left):
23109 '(space :width (+ left-fringe left-margin scroll-bar))
23111 Align to first text column (in header line):
23112 '(space :align-to 0)
23114 Align to middle of text area minus half the width of variable `my-image'
23115 containing a loaded image:
23116 '(space :align-to (0.5 . (- text my-image)))
23118 Width of left margin minus width of 1 character in the default font:
23119 '(space :width (- left-margin 1))
23121 Width of left margin minus width of 2 characters in the current font:
23122 '(space :width (- left-margin (2 . width)))
23124 Center 1 character over left-margin (in header line):
23125 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
23127 Different ways to express width of left fringe plus left margin minus one pixel:
23128 '(space :width (- (+ left-fringe left-margin) (1)))
23129 '(space :width (+ left-fringe left-margin (- (1))))
23130 '(space :width (+ left-fringe left-margin (-1)))
23135 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
23136 struct font
*font
, int width_p
, int *align_to
)
23140 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
23141 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
23144 return OK_PIXELS (0);
23146 eassert (FRAME_LIVE_P (it
->f
));
23148 if (SYMBOLP (prop
))
23150 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
23152 char *unit
= SSDATA (SYMBOL_NAME (prop
));
23154 if (unit
[0] == 'i' && unit
[1] == 'n')
23156 else if (unit
[0] == 'm' && unit
[1] == 'm')
23158 else if (unit
[0] == 'c' && unit
[1] == 'm')
23164 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
23165 : FRAME_RES_Y (it
->f
));
23168 return OK_PIXELS (ppi
/ pixels
);
23173 #ifdef HAVE_WINDOW_SYSTEM
23174 if (EQ (prop
, Qheight
))
23175 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
23176 if (EQ (prop
, Qwidth
))
23177 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
23179 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
23180 return OK_PIXELS (1);
23183 if (EQ (prop
, Qtext
))
23184 return OK_PIXELS (width_p
23185 ? window_box_width (it
->w
, TEXT_AREA
)
23186 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
23188 if (align_to
&& *align_to
< 0)
23191 if (EQ (prop
, Qleft
))
23192 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
23193 if (EQ (prop
, Qright
))
23194 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
23195 if (EQ (prop
, Qcenter
))
23196 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
23197 + window_box_width (it
->w
, TEXT_AREA
) / 2);
23198 if (EQ (prop
, Qleft_fringe
))
23199 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23200 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
23201 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
23202 if (EQ (prop
, Qright_fringe
))
23203 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23204 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23205 : window_box_right_offset (it
->w
, TEXT_AREA
));
23206 if (EQ (prop
, Qleft_margin
))
23207 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
23208 if (EQ (prop
, Qright_margin
))
23209 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
23210 if (EQ (prop
, Qscroll_bar
))
23211 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
23213 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23214 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23215 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23220 if (EQ (prop
, Qleft_fringe
))
23221 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
23222 if (EQ (prop
, Qright_fringe
))
23223 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
23224 if (EQ (prop
, Qleft_margin
))
23225 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
23226 if (EQ (prop
, Qright_margin
))
23227 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
23228 if (EQ (prop
, Qscroll_bar
))
23229 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
23232 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
23233 if (EQ (prop
, Qunbound
))
23237 if (INTEGERP (prop
) || FLOATP (prop
))
23239 int base_unit
= (width_p
23240 ? FRAME_COLUMN_WIDTH (it
->f
)
23241 : FRAME_LINE_HEIGHT (it
->f
));
23242 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
23247 Lisp_Object car
= XCAR (prop
);
23248 Lisp_Object cdr
= XCDR (prop
);
23252 #ifdef HAVE_WINDOW_SYSTEM
23253 if (FRAME_WINDOW_P (it
->f
)
23254 && valid_image_p (prop
))
23256 ptrdiff_t id
= lookup_image (it
->f
, prop
);
23257 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
23259 return OK_PIXELS (width_p
? img
->width
: img
->height
);
23262 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
23268 while (CONSP (cdr
))
23270 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
23271 font
, width_p
, align_to
))
23274 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
23279 if (EQ (car
, Qminus
))
23281 return OK_PIXELS (pixels
);
23284 car
= buffer_local_value_1 (car
, it
->w
->contents
);
23285 if (EQ (car
, Qunbound
))
23289 if (INTEGERP (car
) || FLOATP (car
))
23292 pixels
= XFLOATINT (car
);
23294 return OK_PIXELS (pixels
);
23295 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
23296 font
, width_p
, align_to
))
23297 return OK_PIXELS (pixels
* fact
);
23308 /***********************************************************************
23310 ***********************************************************************/
23312 #ifdef HAVE_WINDOW_SYSTEM
23317 dump_glyph_string (struct glyph_string
*s
)
23319 fprintf (stderr
, "glyph string\n");
23320 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
23321 s
->x
, s
->y
, s
->width
, s
->height
);
23322 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
23323 fprintf (stderr
, " hl = %d\n", s
->hl
);
23324 fprintf (stderr
, " left overhang = %d, right = %d\n",
23325 s
->left_overhang
, s
->right_overhang
);
23326 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
23327 fprintf (stderr
, " extends to end of line = %d\n",
23328 s
->extends_to_end_of_line_p
);
23329 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
23330 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
23333 #endif /* GLYPH_DEBUG */
23335 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
23336 of XChar2b structures for S; it can't be allocated in
23337 init_glyph_string because it must be allocated via `alloca'. W
23338 is the window on which S is drawn. ROW and AREA are the glyph row
23339 and area within the row from which S is constructed. START is the
23340 index of the first glyph structure covered by S. HL is a
23341 face-override for drawing S. */
23344 #define OPTIONAL_HDC(hdc) HDC hdc,
23345 #define DECLARE_HDC(hdc) HDC hdc;
23346 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
23347 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
23350 #ifndef OPTIONAL_HDC
23351 #define OPTIONAL_HDC(hdc)
23352 #define DECLARE_HDC(hdc)
23353 #define ALLOCATE_HDC(hdc, f)
23354 #define RELEASE_HDC(hdc, f)
23358 init_glyph_string (struct glyph_string
*s
,
23360 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
23361 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
23363 memset (s
, 0, sizeof *s
);
23365 s
->f
= XFRAME (w
->frame
);
23369 s
->display
= FRAME_X_DISPLAY (s
->f
);
23370 s
->window
= FRAME_X_WINDOW (s
->f
);
23371 s
->char2b
= char2b
;
23375 s
->first_glyph
= row
->glyphs
[area
] + start
;
23376 s
->height
= row
->height
;
23377 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
23378 s
->ybase
= s
->y
+ row
->ascent
;
23382 /* Append the list of glyph strings with head H and tail T to the list
23383 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
23386 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23387 struct glyph_string
*h
, struct glyph_string
*t
)
23401 /* Prepend the list of glyph strings with head H and tail T to the
23402 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23406 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23407 struct glyph_string
*h
, struct glyph_string
*t
)
23421 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23422 Set *HEAD and *TAIL to the resulting list. */
23425 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23426 struct glyph_string
*s
)
23428 s
->next
= s
->prev
= NULL
;
23429 append_glyph_string_lists (head
, tail
, s
, s
);
23433 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23434 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23435 make sure that X resources for the face returned are allocated.
23436 Value is a pointer to a realized face that is ready for display if
23437 DISPLAY_P is non-zero. */
23439 static struct face
*
23440 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23441 XChar2b
*char2b
, int display_p
)
23443 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23448 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23450 if (code
== FONT_INVALID_CODE
)
23453 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23455 /* Make sure X resources of the face are allocated. */
23456 #ifdef HAVE_X_WINDOWS
23460 eassert (face
!= NULL
);
23461 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23468 /* Get face and two-byte form of character glyph GLYPH on frame F.
23469 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23470 a pointer to a realized face that is ready for display. */
23472 static struct face
*
23473 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23474 XChar2b
*char2b
, int *two_byte_p
)
23479 eassert (glyph
->type
== CHAR_GLYPH
);
23480 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23482 /* Make sure X resources of the face are allocated. */
23483 eassert (face
!= NULL
);
23484 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23491 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23492 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23494 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23496 if (code
== FONT_INVALID_CODE
)
23500 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23505 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23506 Return 1 if FONT has a glyph for C, otherwise return 0. */
23509 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23513 if (CHAR_BYTE8_P (c
))
23514 code
= CHAR_TO_BYTE8 (c
);
23516 code
= font
->driver
->encode_char (font
, c
);
23518 if (code
== FONT_INVALID_CODE
)
23520 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23525 /* Fill glyph string S with composition components specified by S->cmp.
23527 BASE_FACE is the base face of the composition.
23528 S->cmp_from is the index of the first component for S.
23530 OVERLAPS non-zero means S should draw the foreground only, and use
23531 its physical height for clipping. See also draw_glyphs.
23533 Value is the index of a component not in S. */
23536 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23540 /* For all glyphs of this composition, starting at the offset
23541 S->cmp_from, until we reach the end of the definition or encounter a
23542 glyph that requires the different face, add it to S. */
23547 s
->for_overlaps
= overlaps
;
23550 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23552 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23554 /* TAB in a composition means display glyphs with padding space
23555 on the left or right. */
23558 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23561 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23568 s
->font
= s
->face
->font
;
23570 else if (s
->face
!= face
)
23578 if (s
->face
== NULL
)
23580 s
->face
= base_face
->ascii_face
;
23581 s
->font
= s
->face
->font
;
23584 /* All glyph strings for the same composition has the same width,
23585 i.e. the width set for the first component of the composition. */
23586 s
->width
= s
->first_glyph
->pixel_width
;
23588 /* If the specified font could not be loaded, use the frame's
23589 default font, but record the fact that we couldn't load it in
23590 the glyph string so that we can draw rectangles for the
23591 characters of the glyph string. */
23592 if (s
->font
== NULL
)
23594 s
->font_not_found_p
= 1;
23595 s
->font
= FRAME_FONT (s
->f
);
23598 /* Adjust base line for subscript/superscript text. */
23599 s
->ybase
+= s
->first_glyph
->voffset
;
23601 /* This glyph string must always be drawn with 16-bit functions. */
23608 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23609 int start
, int end
, int overlaps
)
23611 struct glyph
*glyph
, *last
;
23612 Lisp_Object lgstring
;
23615 s
->for_overlaps
= overlaps
;
23616 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23617 last
= s
->row
->glyphs
[s
->area
] + end
;
23618 s
->cmp_id
= glyph
->u
.cmp
.id
;
23619 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23620 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23621 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23622 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23623 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23625 while (glyph
< last
23626 && glyph
->u
.cmp
.automatic
23627 && glyph
->u
.cmp
.id
== s
->cmp_id
23628 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23629 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23631 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23633 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23634 unsigned code
= LGLYPH_CODE (lglyph
);
23636 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23638 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23639 return glyph
- s
->row
->glyphs
[s
->area
];
23643 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23644 See the comment of fill_glyph_string for arguments.
23645 Value is the index of the first glyph not in S. */
23649 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23650 int start
, int end
, int overlaps
)
23652 struct glyph
*glyph
, *last
;
23655 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23656 s
->for_overlaps
= overlaps
;
23657 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23658 last
= s
->row
->glyphs
[s
->area
] + end
;
23659 voffset
= glyph
->voffset
;
23660 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23661 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23663 s
->width
= glyph
->pixel_width
;
23665 while (glyph
< last
23666 && glyph
->type
== GLYPHLESS_GLYPH
23667 && glyph
->voffset
== voffset
23668 && glyph
->face_id
== face_id
)
23671 s
->width
+= glyph
->pixel_width
;
23674 s
->ybase
+= voffset
;
23675 return glyph
- s
->row
->glyphs
[s
->area
];
23679 /* Fill glyph string S from a sequence of character glyphs.
23681 FACE_ID is the face id of the string. START is the index of the
23682 first glyph to consider, END is the index of the last + 1.
23683 OVERLAPS non-zero means S should draw the foreground only, and use
23684 its physical height for clipping. See also draw_glyphs.
23686 Value is the index of the first glyph not in S. */
23689 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23690 int start
, int end
, int overlaps
)
23692 struct glyph
*glyph
, *last
;
23694 int glyph_not_available_p
;
23696 eassert (s
->f
== XFRAME (s
->w
->frame
));
23697 eassert (s
->nchars
== 0);
23698 eassert (start
>= 0 && end
> start
);
23700 s
->for_overlaps
= overlaps
;
23701 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23702 last
= s
->row
->glyphs
[s
->area
] + end
;
23703 voffset
= glyph
->voffset
;
23704 s
->padding_p
= glyph
->padding_p
;
23705 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23707 while (glyph
< last
23708 && glyph
->type
== CHAR_GLYPH
23709 && glyph
->voffset
== voffset
23710 /* Same face id implies same font, nowadays. */
23711 && glyph
->face_id
== face_id
23712 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23716 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23717 s
->char2b
+ s
->nchars
,
23719 s
->two_byte_p
= two_byte_p
;
23721 eassert (s
->nchars
<= end
- start
);
23722 s
->width
+= glyph
->pixel_width
;
23723 if (glyph
++->padding_p
!= s
->padding_p
)
23727 s
->font
= s
->face
->font
;
23729 /* If the specified font could not be loaded, use the frame's font,
23730 but record the fact that we couldn't load it in
23731 S->font_not_found_p so that we can draw rectangles for the
23732 characters of the glyph string. */
23733 if (s
->font
== NULL
|| glyph_not_available_p
)
23735 s
->font_not_found_p
= 1;
23736 s
->font
= FRAME_FONT (s
->f
);
23739 /* Adjust base line for subscript/superscript text. */
23740 s
->ybase
+= voffset
;
23742 eassert (s
->face
&& s
->face
->gc
);
23743 return glyph
- s
->row
->glyphs
[s
->area
];
23747 /* Fill glyph string S from image glyph S->first_glyph. */
23750 fill_image_glyph_string (struct glyph_string
*s
)
23752 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23753 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23755 s
->slice
= s
->first_glyph
->slice
.img
;
23756 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23757 s
->font
= s
->face
->font
;
23758 s
->width
= s
->first_glyph
->pixel_width
;
23760 /* Adjust base line for subscript/superscript text. */
23761 s
->ybase
+= s
->first_glyph
->voffset
;
23765 /* Fill glyph string S from a sequence of stretch glyphs.
23767 START is the index of the first glyph to consider,
23768 END is the index of the last + 1.
23770 Value is the index of the first glyph not in S. */
23773 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23775 struct glyph
*glyph
, *last
;
23776 int voffset
, face_id
;
23778 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23780 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23781 last
= s
->row
->glyphs
[s
->area
] + end
;
23782 face_id
= glyph
->face_id
;
23783 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23784 s
->font
= s
->face
->font
;
23785 s
->width
= glyph
->pixel_width
;
23787 voffset
= glyph
->voffset
;
23791 && glyph
->type
== STRETCH_GLYPH
23792 && glyph
->voffset
== voffset
23793 && glyph
->face_id
== face_id
);
23795 s
->width
+= glyph
->pixel_width
;
23797 /* Adjust base line for subscript/superscript text. */
23798 s
->ybase
+= voffset
;
23800 /* The case that face->gc == 0 is handled when drawing the glyph
23801 string by calling PREPARE_FACE_FOR_DISPLAY. */
23803 return glyph
- s
->row
->glyphs
[s
->area
];
23806 static struct font_metrics
*
23807 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23809 static struct font_metrics metrics
;
23814 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23815 if (code
== FONT_INVALID_CODE
)
23817 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23822 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23823 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23824 assumed to be zero. */
23827 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23829 *left
= *right
= 0;
23831 if (glyph
->type
== CHAR_GLYPH
)
23835 struct font_metrics
*pcm
;
23837 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23838 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23840 if (pcm
->rbearing
> pcm
->width
)
23841 *right
= pcm
->rbearing
- pcm
->width
;
23842 if (pcm
->lbearing
< 0)
23843 *left
= -pcm
->lbearing
;
23846 else if (glyph
->type
== COMPOSITE_GLYPH
)
23848 if (! glyph
->u
.cmp
.automatic
)
23850 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23852 if (cmp
->rbearing
> cmp
->pixel_width
)
23853 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23854 if (cmp
->lbearing
< 0)
23855 *left
= - cmp
->lbearing
;
23859 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23860 struct font_metrics metrics
;
23862 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23863 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23864 if (metrics
.rbearing
> metrics
.width
)
23865 *right
= metrics
.rbearing
- metrics
.width
;
23866 if (metrics
.lbearing
< 0)
23867 *left
= - metrics
.lbearing
;
23873 /* Return the index of the first glyph preceding glyph string S that
23874 is overwritten by S because of S's left overhang. Value is -1
23875 if no glyphs are overwritten. */
23878 left_overwritten (struct glyph_string
*s
)
23882 if (s
->left_overhang
)
23885 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23886 int first
= s
->first_glyph
- glyphs
;
23888 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23889 x
-= glyphs
[i
].pixel_width
;
23900 /* Return the index of the first glyph preceding glyph string S that
23901 is overwriting S because of its right overhang. Value is -1 if no
23902 glyph in front of S overwrites S. */
23905 left_overwriting (struct glyph_string
*s
)
23908 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23909 int first
= s
->first_glyph
- glyphs
;
23913 for (i
= first
- 1; i
>= 0; --i
)
23916 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23919 x
-= glyphs
[i
].pixel_width
;
23926 /* Return the index of the last glyph following glyph string S that is
23927 overwritten by S because of S's right overhang. Value is -1 if
23928 no such glyph is found. */
23931 right_overwritten (struct glyph_string
*s
)
23935 if (s
->right_overhang
)
23938 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23939 int first
= (s
->first_glyph
- glyphs
23940 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23941 int end
= s
->row
->used
[s
->area
];
23943 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23944 x
+= glyphs
[i
].pixel_width
;
23953 /* Return the index of the last glyph following glyph string S that
23954 overwrites S because of its left overhang. Value is negative
23955 if no such glyph is found. */
23958 right_overwriting (struct glyph_string
*s
)
23961 int end
= s
->row
->used
[s
->area
];
23962 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23963 int first
= (s
->first_glyph
- glyphs
23964 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23968 for (i
= first
; i
< end
; ++i
)
23971 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23974 x
+= glyphs
[i
].pixel_width
;
23981 /* Set background width of glyph string S. START is the index of the
23982 first glyph following S. LAST_X is the right-most x-position + 1
23983 in the drawing area. */
23986 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23988 /* If the face of this glyph string has to be drawn to the end of
23989 the drawing area, set S->extends_to_end_of_line_p. */
23991 if (start
== s
->row
->used
[s
->area
]
23992 && ((s
->row
->fill_line_p
23993 && (s
->hl
== DRAW_NORMAL_TEXT
23994 || s
->hl
== DRAW_IMAGE_RAISED
23995 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23996 || s
->hl
== DRAW_MOUSE_FACE
))
23997 s
->extends_to_end_of_line_p
= 1;
23999 /* If S extends its face to the end of the line, set its
24000 background_width to the distance to the right edge of the drawing
24002 if (s
->extends_to_end_of_line_p
)
24003 s
->background_width
= last_x
- s
->x
+ 1;
24005 s
->background_width
= s
->width
;
24009 /* Compute overhangs and x-positions for glyph string S and its
24010 predecessors, or successors. X is the starting x-position for S.
24011 BACKWARD_P non-zero means process predecessors. */
24014 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
24020 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
24021 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
24031 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
24032 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
24042 /* The following macros are only called from draw_glyphs below.
24043 They reference the following parameters of that function directly:
24044 `w', `row', `area', and `overlap_p'
24045 as well as the following local variables:
24046 `s', `f', and `hdc' (in W32) */
24049 /* On W32, silently add local `hdc' variable to argument list of
24050 init_glyph_string. */
24051 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
24052 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
24054 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
24055 init_glyph_string (s, char2b, w, row, area, start, hl)
24058 /* Add a glyph string for a stretch glyph to the list of strings
24059 between HEAD and TAIL. START is the index of the stretch glyph in
24060 row area AREA of glyph row ROW. END is the index of the last glyph
24061 in that glyph row area. X is the current output position assigned
24062 to the new glyph string constructed. HL overrides that face of the
24063 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
24064 is the right-most x-position of the drawing area. */
24066 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
24067 and below -- keep them on one line. */
24068 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24071 s = alloca (sizeof *s); \
24072 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24073 START = fill_stretch_glyph_string (s, START, END); \
24074 append_glyph_string (&HEAD, &TAIL, s); \
24080 /* Add a glyph string for an image glyph to the list of strings
24081 between HEAD and TAIL. START is the index of the image glyph in
24082 row area AREA of glyph row ROW. END is the index of the last glyph
24083 in that glyph row area. X is the current output position assigned
24084 to the new glyph string constructed. HL overrides that face of the
24085 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
24086 is the right-most x-position of the drawing area. */
24088 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24091 s = alloca (sizeof *s); \
24092 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24093 fill_image_glyph_string (s); \
24094 append_glyph_string (&HEAD, &TAIL, s); \
24101 /* Add a glyph string for a sequence of character glyphs to the list
24102 of strings between HEAD and TAIL. START is the index of the first
24103 glyph in row area AREA of glyph row ROW that is part of the new
24104 glyph string. END is the index of the last glyph in that glyph row
24105 area. X is the current output position assigned to the new glyph
24106 string constructed. HL overrides that face of the glyph; e.g. it
24107 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
24108 right-most x-position of the drawing area. */
24110 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24116 face_id = (row)->glyphs[area][START].face_id; \
24118 s = alloca (sizeof *s); \
24119 char2b = alloca ((END - START) * sizeof *char2b); \
24120 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24121 append_glyph_string (&HEAD, &TAIL, s); \
24123 START = fill_glyph_string (s, face_id, START, END, overlaps); \
24128 /* Add a glyph string for a composite sequence to the list of strings
24129 between HEAD and TAIL. START is the index of the first glyph in
24130 row area AREA of glyph row ROW that is part of the new glyph
24131 string. END is the index of the last glyph in that glyph row area.
24132 X is the current output position assigned to the new glyph string
24133 constructed. HL overrides that face of the glyph; e.g. it is
24134 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
24135 x-position of the drawing area. */
24137 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24139 int face_id = (row)->glyphs[area][START].face_id; \
24140 struct face *base_face = FACE_FROM_ID (f, face_id); \
24141 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
24142 struct composition *cmp = composition_table[cmp_id]; \
24144 struct glyph_string *first_s = NULL; \
24147 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
24149 /* Make glyph_strings for each glyph sequence that is drawable by \
24150 the same face, and append them to HEAD/TAIL. */ \
24151 for (n = 0; n < cmp->glyph_len;) \
24153 s = alloca (sizeof *s); \
24154 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24155 append_glyph_string (&(HEAD), &(TAIL), s); \
24161 n = fill_composite_glyph_string (s, base_face, overlaps); \
24169 /* Add a glyph string for a glyph-string sequence to the list of strings
24170 between HEAD and TAIL. */
24172 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24176 Lisp_Object gstring; \
24178 face_id = (row)->glyphs[area][START].face_id; \
24179 gstring = (composition_gstring_from_id \
24180 ((row)->glyphs[area][START].u.cmp.id)); \
24181 s = alloca (sizeof *s); \
24182 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
24183 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24184 append_glyph_string (&(HEAD), &(TAIL), s); \
24186 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
24190 /* Add a glyph string for a sequence of glyphless character's glyphs
24191 to the list of strings between HEAD and TAIL. The meanings of
24192 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
24194 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24199 face_id = (row)->glyphs[area][START].face_id; \
24201 s = alloca (sizeof *s); \
24202 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24203 append_glyph_string (&HEAD, &TAIL, s); \
24205 START = fill_glyphless_glyph_string (s, face_id, START, END, \
24211 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
24212 of AREA of glyph row ROW on window W between indices START and END.
24213 HL overrides the face for drawing glyph strings, e.g. it is
24214 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
24215 x-positions of the drawing area.
24217 This is an ugly monster macro construct because we must use alloca
24218 to allocate glyph strings (because draw_glyphs can be called
24219 asynchronously). */
24221 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24224 HEAD = TAIL = NULL; \
24225 while (START < END) \
24227 struct glyph *first_glyph = (row)->glyphs[area] + START; \
24228 switch (first_glyph->type) \
24231 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
24235 case COMPOSITE_GLYPH: \
24236 if (first_glyph->u.cmp.automatic) \
24237 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
24240 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
24244 case STRETCH_GLYPH: \
24245 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
24249 case IMAGE_GLYPH: \
24250 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
24254 case GLYPHLESS_GLYPH: \
24255 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
24265 set_glyph_string_background_width (s, START, LAST_X); \
24272 /* Draw glyphs between START and END in AREA of ROW on window W,
24273 starting at x-position X. X is relative to AREA in W. HL is a
24274 face-override with the following meaning:
24276 DRAW_NORMAL_TEXT draw normally
24277 DRAW_CURSOR draw in cursor face
24278 DRAW_MOUSE_FACE draw in mouse face.
24279 DRAW_INVERSE_VIDEO draw in mode line face
24280 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
24281 DRAW_IMAGE_RAISED draw an image with a raised relief around it
24283 If OVERLAPS is non-zero, draw only the foreground of characters and
24284 clip to the physical height of ROW. Non-zero value also defines
24285 the overlapping part to be drawn:
24287 OVERLAPS_PRED overlap with preceding rows
24288 OVERLAPS_SUCC overlap with succeeding rows
24289 OVERLAPS_BOTH overlap with both preceding/succeeding rows
24290 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
24292 Value is the x-position reached, relative to AREA of W. */
24295 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
24296 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
24297 enum draw_glyphs_face hl
, int overlaps
)
24299 struct glyph_string
*head
, *tail
;
24300 struct glyph_string
*s
;
24301 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
24302 int i
, j
, x_reached
, last_x
, area_left
= 0;
24303 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24306 ALLOCATE_HDC (hdc
, f
);
24308 /* Let's rather be paranoid than getting a SEGV. */
24309 end
= min (end
, row
->used
[area
]);
24310 start
= clip_to_bounds (0, start
, end
);
24312 /* Translate X to frame coordinates. Set last_x to the right
24313 end of the drawing area. */
24314 if (row
->full_width_p
)
24316 /* X is relative to the left edge of W, without scroll bars
24318 area_left
= WINDOW_LEFT_EDGE_X (w
);
24319 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
24320 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
24324 area_left
= window_box_left (w
, area
);
24325 last_x
= area_left
+ window_box_width (w
, area
);
24329 /* Build a doubly-linked list of glyph_string structures between
24330 head and tail from what we have to draw. Note that the macro
24331 BUILD_GLYPH_STRINGS will modify its start parameter. That's
24332 the reason we use a separate variable `i'. */
24334 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
24336 x_reached
= tail
->x
+ tail
->background_width
;
24340 /* If there are any glyphs with lbearing < 0 or rbearing > width in
24341 the row, redraw some glyphs in front or following the glyph
24342 strings built above. */
24343 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
24345 struct glyph_string
*h
, *t
;
24346 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24347 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
24348 int check_mouse_face
= 0;
24351 /* If mouse highlighting is on, we may need to draw adjacent
24352 glyphs using mouse-face highlighting. */
24353 if (area
== TEXT_AREA
&& row
->mouse_face_p
24354 && hlinfo
->mouse_face_beg_row
>= 0
24355 && hlinfo
->mouse_face_end_row
>= 0)
24357 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
24359 if (row_vpos
>= hlinfo
->mouse_face_beg_row
24360 && row_vpos
<= hlinfo
->mouse_face_end_row
)
24362 check_mouse_face
= 1;
24363 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
24364 ? hlinfo
->mouse_face_beg_col
: 0;
24365 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
24366 ? hlinfo
->mouse_face_end_col
24367 : row
->used
[TEXT_AREA
];
24371 /* Compute overhangs for all glyph strings. */
24372 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
24373 for (s
= head
; s
; s
= s
->next
)
24374 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
24376 /* Prepend glyph strings for glyphs in front of the first glyph
24377 string that are overwritten because of the first glyph
24378 string's left overhang. The background of all strings
24379 prepended must be drawn because the first glyph string
24381 i
= left_overwritten (head
);
24384 enum draw_glyphs_face overlap_hl
;
24386 /* If this row contains mouse highlighting, attempt to draw
24387 the overlapped glyphs with the correct highlight. This
24388 code fails if the overlap encompasses more than one glyph
24389 and mouse-highlight spans only some of these glyphs.
24390 However, making it work perfectly involves a lot more
24391 code, and I don't know if the pathological case occurs in
24392 practice, so we'll stick to this for now. --- cyd */
24393 if (check_mouse_face
24394 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24395 overlap_hl
= DRAW_MOUSE_FACE
;
24397 overlap_hl
= DRAW_NORMAL_TEXT
;
24400 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24401 overlap_hl
, dummy_x
, last_x
);
24403 compute_overhangs_and_x (t
, head
->x
, 1);
24404 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24408 /* Prepend glyph strings for glyphs in front of the first glyph
24409 string that overwrite that glyph string because of their
24410 right overhang. For these strings, only the foreground must
24411 be drawn, because it draws over the glyph string at `head'.
24412 The background must not be drawn because this would overwrite
24413 right overhangs of preceding glyphs for which no glyph
24415 i
= left_overwriting (head
);
24418 enum draw_glyphs_face overlap_hl
;
24420 if (check_mouse_face
24421 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24422 overlap_hl
= DRAW_MOUSE_FACE
;
24424 overlap_hl
= DRAW_NORMAL_TEXT
;
24427 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24428 overlap_hl
, dummy_x
, last_x
);
24429 for (s
= h
; s
; s
= s
->next
)
24430 s
->background_filled_p
= 1;
24431 compute_overhangs_and_x (t
, head
->x
, 1);
24432 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24435 /* Append glyphs strings for glyphs following the last glyph
24436 string tail that are overwritten by tail. The background of
24437 these strings has to be drawn because tail's foreground draws
24439 i
= right_overwritten (tail
);
24442 enum draw_glyphs_face overlap_hl
;
24444 if (check_mouse_face
24445 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24446 overlap_hl
= DRAW_MOUSE_FACE
;
24448 overlap_hl
= DRAW_NORMAL_TEXT
;
24450 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24451 overlap_hl
, x
, last_x
);
24452 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24453 we don't have `end = i;' here. */
24454 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24455 append_glyph_string_lists (&head
, &tail
, h
, t
);
24459 /* Append glyph strings for glyphs following the last glyph
24460 string tail that overwrite tail. The foreground of such
24461 glyphs has to be drawn because it writes into the background
24462 of tail. The background must not be drawn because it could
24463 paint over the foreground of following glyphs. */
24464 i
= right_overwriting (tail
);
24467 enum draw_glyphs_face overlap_hl
;
24468 if (check_mouse_face
24469 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24470 overlap_hl
= DRAW_MOUSE_FACE
;
24472 overlap_hl
= DRAW_NORMAL_TEXT
;
24475 i
++; /* We must include the Ith glyph. */
24476 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24477 overlap_hl
, x
, last_x
);
24478 for (s
= h
; s
; s
= s
->next
)
24479 s
->background_filled_p
= 1;
24480 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24481 append_glyph_string_lists (&head
, &tail
, h
, t
);
24483 if (clip_head
|| clip_tail
)
24484 for (s
= head
; s
; s
= s
->next
)
24486 s
->clip_head
= clip_head
;
24487 s
->clip_tail
= clip_tail
;
24491 /* Draw all strings. */
24492 for (s
= head
; s
; s
= s
->next
)
24493 FRAME_RIF (f
)->draw_glyph_string (s
);
24496 /* When focus a sole frame and move horizontally, this sets on_p to 0
24497 causing a failure to erase prev cursor position. */
24498 if (area
== TEXT_AREA
24499 && !row
->full_width_p
24500 /* When drawing overlapping rows, only the glyph strings'
24501 foreground is drawn, which doesn't erase a cursor
24505 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24506 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24507 : (tail
? tail
->x
+ tail
->background_width
: x
));
24511 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24512 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24516 /* Value is the x-position up to which drawn, relative to AREA of W.
24517 This doesn't include parts drawn because of overhangs. */
24518 if (row
->full_width_p
)
24519 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24521 x_reached
-= area_left
;
24523 RELEASE_HDC (hdc
, f
);
24528 /* Expand row matrix if too narrow. Don't expand if area
24531 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24533 if (!it->f->fonts_changed \
24534 && (it->glyph_row->glyphs[area] \
24535 < it->glyph_row->glyphs[area + 1])) \
24537 it->w->ncols_scale_factor++; \
24538 it->f->fonts_changed = 1; \
24542 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24543 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24546 append_glyph (struct it
*it
)
24548 struct glyph
*glyph
;
24549 enum glyph_row_area area
= it
->area
;
24551 eassert (it
->glyph_row
);
24552 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24554 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24555 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24557 /* If the glyph row is reversed, we need to prepend the glyph
24558 rather than append it. */
24559 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24563 /* Make room for the additional glyph. */
24564 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24566 glyph
= it
->glyph_row
->glyphs
[area
];
24568 glyph
->charpos
= CHARPOS (it
->position
);
24569 glyph
->object
= it
->object
;
24570 if (it
->pixel_width
> 0)
24572 glyph
->pixel_width
= it
->pixel_width
;
24573 glyph
->padding_p
= 0;
24577 /* Assure at least 1-pixel width. Otherwise, cursor can't
24578 be displayed correctly. */
24579 glyph
->pixel_width
= 1;
24580 glyph
->padding_p
= 1;
24582 glyph
->ascent
= it
->ascent
;
24583 glyph
->descent
= it
->descent
;
24584 glyph
->voffset
= it
->voffset
;
24585 glyph
->type
= CHAR_GLYPH
;
24586 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24587 glyph
->multibyte_p
= it
->multibyte_p
;
24588 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24590 /* In R2L rows, the left and the right box edges need to be
24591 drawn in reverse direction. */
24592 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24593 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24597 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24598 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24600 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24601 || it
->phys_descent
> it
->descent
);
24602 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24603 glyph
->face_id
= it
->face_id
;
24604 glyph
->u
.ch
= it
->char_to_display
;
24605 glyph
->slice
.img
= null_glyph_slice
;
24606 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24609 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24610 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24612 glyph
->bidi_type
= it
->bidi_it
.type
;
24616 glyph
->resolved_level
= 0;
24617 glyph
->bidi_type
= UNKNOWN_BT
;
24619 ++it
->glyph_row
->used
[area
];
24622 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24625 /* Store one glyph for the composition IT->cmp_it.id in
24626 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24630 append_composite_glyph (struct it
*it
)
24632 struct glyph
*glyph
;
24633 enum glyph_row_area area
= it
->area
;
24635 eassert (it
->glyph_row
);
24637 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24638 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24640 /* If the glyph row is reversed, we need to prepend the glyph
24641 rather than append it. */
24642 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24646 /* Make room for the new glyph. */
24647 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24649 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24651 glyph
->charpos
= it
->cmp_it
.charpos
;
24652 glyph
->object
= it
->object
;
24653 glyph
->pixel_width
= it
->pixel_width
;
24654 glyph
->ascent
= it
->ascent
;
24655 glyph
->descent
= it
->descent
;
24656 glyph
->voffset
= it
->voffset
;
24657 glyph
->type
= COMPOSITE_GLYPH
;
24658 if (it
->cmp_it
.ch
< 0)
24660 glyph
->u
.cmp
.automatic
= 0;
24661 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24662 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24666 glyph
->u
.cmp
.automatic
= 1;
24667 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24668 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24669 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24671 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24672 glyph
->multibyte_p
= it
->multibyte_p
;
24673 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24675 /* In R2L rows, the left and the right box edges need to be
24676 drawn in reverse direction. */
24677 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24678 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24682 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24683 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24685 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24686 || it
->phys_descent
> it
->descent
);
24687 glyph
->padding_p
= 0;
24688 glyph
->glyph_not_available_p
= 0;
24689 glyph
->face_id
= it
->face_id
;
24690 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24693 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24694 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24696 glyph
->bidi_type
= it
->bidi_it
.type
;
24698 ++it
->glyph_row
->used
[area
];
24701 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24705 /* Change IT->ascent and IT->height according to the setting of
24709 take_vertical_position_into_account (struct it
*it
)
24713 if (it
->voffset
< 0)
24714 /* Increase the ascent so that we can display the text higher
24716 it
->ascent
-= it
->voffset
;
24718 /* Increase the descent so that we can display the text lower
24720 it
->descent
+= it
->voffset
;
24725 /* Produce glyphs/get display metrics for the image IT is loaded with.
24726 See the description of struct display_iterator in dispextern.h for
24727 an overview of struct display_iterator. */
24730 produce_image_glyph (struct it
*it
)
24734 int glyph_ascent
, crop
;
24735 struct glyph_slice slice
;
24737 eassert (it
->what
== IT_IMAGE
);
24739 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24741 /* Make sure X resources of the face is loaded. */
24742 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24744 if (it
->image_id
< 0)
24746 /* Fringe bitmap. */
24747 it
->ascent
= it
->phys_ascent
= 0;
24748 it
->descent
= it
->phys_descent
= 0;
24749 it
->pixel_width
= 0;
24754 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24756 /* Make sure X resources of the image is loaded. */
24757 prepare_image_for_display (it
->f
, img
);
24759 slice
.x
= slice
.y
= 0;
24760 slice
.width
= img
->width
;
24761 slice
.height
= img
->height
;
24763 if (INTEGERP (it
->slice
.x
))
24764 slice
.x
= XINT (it
->slice
.x
);
24765 else if (FLOATP (it
->slice
.x
))
24766 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24768 if (INTEGERP (it
->slice
.y
))
24769 slice
.y
= XINT (it
->slice
.y
);
24770 else if (FLOATP (it
->slice
.y
))
24771 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24773 if (INTEGERP (it
->slice
.width
))
24774 slice
.width
= XINT (it
->slice
.width
);
24775 else if (FLOATP (it
->slice
.width
))
24776 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24778 if (INTEGERP (it
->slice
.height
))
24779 slice
.height
= XINT (it
->slice
.height
);
24780 else if (FLOATP (it
->slice
.height
))
24781 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24783 if (slice
.x
>= img
->width
)
24784 slice
.x
= img
->width
;
24785 if (slice
.y
>= img
->height
)
24786 slice
.y
= img
->height
;
24787 if (slice
.x
+ slice
.width
>= img
->width
)
24788 slice
.width
= img
->width
- slice
.x
;
24789 if (slice
.y
+ slice
.height
> img
->height
)
24790 slice
.height
= img
->height
- slice
.y
;
24792 if (slice
.width
== 0 || slice
.height
== 0)
24795 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24797 it
->descent
= slice
.height
- glyph_ascent
;
24799 it
->descent
+= img
->vmargin
;
24800 if (slice
.y
+ slice
.height
== img
->height
)
24801 it
->descent
+= img
->vmargin
;
24802 it
->phys_descent
= it
->descent
;
24804 it
->pixel_width
= slice
.width
;
24806 it
->pixel_width
+= img
->hmargin
;
24807 if (slice
.x
+ slice
.width
== img
->width
)
24808 it
->pixel_width
+= img
->hmargin
;
24810 /* It's quite possible for images to have an ascent greater than
24811 their height, so don't get confused in that case. */
24812 if (it
->descent
< 0)
24817 if (face
->box
!= FACE_NO_BOX
)
24819 if (face
->box_line_width
> 0)
24822 it
->ascent
+= face
->box_line_width
;
24823 if (slice
.y
+ slice
.height
== img
->height
)
24824 it
->descent
+= face
->box_line_width
;
24827 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24828 it
->pixel_width
+= eabs (face
->box_line_width
);
24829 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24830 it
->pixel_width
+= eabs (face
->box_line_width
);
24833 take_vertical_position_into_account (it
);
24835 /* Automatically crop wide image glyphs at right edge so we can
24836 draw the cursor on same display row. */
24837 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24838 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24840 it
->pixel_width
-= crop
;
24841 slice
.width
-= crop
;
24846 struct glyph
*glyph
;
24847 enum glyph_row_area area
= it
->area
;
24849 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24850 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24852 glyph
->charpos
= CHARPOS (it
->position
);
24853 glyph
->object
= it
->object
;
24854 glyph
->pixel_width
= it
->pixel_width
;
24855 glyph
->ascent
= glyph_ascent
;
24856 glyph
->descent
= it
->descent
;
24857 glyph
->voffset
= it
->voffset
;
24858 glyph
->type
= IMAGE_GLYPH
;
24859 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24860 glyph
->multibyte_p
= it
->multibyte_p
;
24861 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24863 /* In R2L rows, the left and the right box edges need to be
24864 drawn in reverse direction. */
24865 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24866 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24870 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24871 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24873 glyph
->overlaps_vertically_p
= 0;
24874 glyph
->padding_p
= 0;
24875 glyph
->glyph_not_available_p
= 0;
24876 glyph
->face_id
= it
->face_id
;
24877 glyph
->u
.img_id
= img
->id
;
24878 glyph
->slice
.img
= slice
;
24879 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24882 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24883 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24885 glyph
->bidi_type
= it
->bidi_it
.type
;
24887 ++it
->glyph_row
->used
[area
];
24890 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24895 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24896 of the glyph, WIDTH and HEIGHT are the width and height of the
24897 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24900 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24901 int width
, int height
, int ascent
)
24903 struct glyph
*glyph
;
24904 enum glyph_row_area area
= it
->area
;
24906 eassert (ascent
>= 0 && ascent
<= height
);
24908 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24909 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24911 /* If the glyph row is reversed, we need to prepend the glyph
24912 rather than append it. */
24913 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24917 /* Make room for the additional glyph. */
24918 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24920 glyph
= it
->glyph_row
->glyphs
[area
];
24922 glyph
->charpos
= CHARPOS (it
->position
);
24923 glyph
->object
= object
;
24924 glyph
->pixel_width
= width
;
24925 glyph
->ascent
= ascent
;
24926 glyph
->descent
= height
- ascent
;
24927 glyph
->voffset
= it
->voffset
;
24928 glyph
->type
= STRETCH_GLYPH
;
24929 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24930 glyph
->multibyte_p
= it
->multibyte_p
;
24931 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24933 /* In R2L rows, the left and the right box edges need to be
24934 drawn in reverse direction. */
24935 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24936 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24940 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24941 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24943 glyph
->overlaps_vertically_p
= 0;
24944 glyph
->padding_p
= 0;
24945 glyph
->glyph_not_available_p
= 0;
24946 glyph
->face_id
= it
->face_id
;
24947 glyph
->u
.stretch
.ascent
= ascent
;
24948 glyph
->u
.stretch
.height
= height
;
24949 glyph
->slice
.img
= null_glyph_slice
;
24950 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24953 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24954 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24956 glyph
->bidi_type
= it
->bidi_it
.type
;
24960 glyph
->resolved_level
= 0;
24961 glyph
->bidi_type
= UNKNOWN_BT
;
24963 ++it
->glyph_row
->used
[area
];
24966 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24969 #endif /* HAVE_WINDOW_SYSTEM */
24971 /* Produce a stretch glyph for iterator IT. IT->object is the value
24972 of the glyph property displayed. The value must be a list
24973 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24976 1. `:width WIDTH' specifies that the space should be WIDTH *
24977 canonical char width wide. WIDTH may be an integer or floating
24980 2. `:relative-width FACTOR' specifies that the width of the stretch
24981 should be computed from the width of the first character having the
24982 `glyph' property, and should be FACTOR times that width.
24984 3. `:align-to HPOS' specifies that the space should be wide enough
24985 to reach HPOS, a value in canonical character units.
24987 Exactly one of the above pairs must be present.
24989 4. `:height HEIGHT' specifies that the height of the stretch produced
24990 should be HEIGHT, measured in canonical character units.
24992 5. `:relative-height FACTOR' specifies that the height of the
24993 stretch should be FACTOR times the height of the characters having
24994 the glyph property.
24996 Either none or exactly one of 4 or 5 must be present.
24998 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24999 of the stretch should be used for the ascent of the stretch.
25000 ASCENT must be in the range 0 <= ASCENT <= 100. */
25003 produce_stretch_glyph (struct it
*it
)
25005 /* (space :width WIDTH :height HEIGHT ...) */
25006 Lisp_Object prop
, plist
;
25007 int width
= 0, height
= 0, align_to
= -1;
25008 int zero_width_ok_p
= 0;
25010 struct font
*font
= NULL
;
25012 #ifdef HAVE_WINDOW_SYSTEM
25014 int zero_height_ok_p
= 0;
25016 if (FRAME_WINDOW_P (it
->f
))
25018 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25019 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25020 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25024 /* List should start with `space'. */
25025 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
25026 plist
= XCDR (it
->object
);
25028 /* Compute the width of the stretch. */
25029 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
25030 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
25032 /* Absolute width `:width WIDTH' specified and valid. */
25033 zero_width_ok_p
= 1;
25036 #ifdef HAVE_WINDOW_SYSTEM
25037 else if (FRAME_WINDOW_P (it
->f
)
25038 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
25040 /* Relative width `:relative-width FACTOR' specified and valid.
25041 Compute the width of the characters having the `glyph'
25044 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
25047 if (it
->multibyte_p
)
25048 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
25051 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
25052 if (! ASCII_CHAR_P (it2
.c
))
25053 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
25056 it2
.glyph_row
= NULL
;
25057 it2
.what
= IT_CHARACTER
;
25058 x_produce_glyphs (&it2
);
25059 width
= NUMVAL (prop
) * it2
.pixel_width
;
25061 #endif /* HAVE_WINDOW_SYSTEM */
25062 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
25063 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
25065 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
25066 align_to
= (align_to
< 0
25068 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
25069 else if (align_to
< 0)
25070 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
25071 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
25072 zero_width_ok_p
= 1;
25075 /* Nothing specified -> width defaults to canonical char width. */
25076 width
= FRAME_COLUMN_WIDTH (it
->f
);
25078 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
25081 #ifdef HAVE_WINDOW_SYSTEM
25082 /* Compute height. */
25083 if (FRAME_WINDOW_P (it
->f
))
25085 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
25086 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
25089 zero_height_ok_p
= 1;
25091 else if (prop
= Fplist_get (plist
, QCrelative_height
),
25093 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
25095 height
= FONT_HEIGHT (font
);
25097 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
25100 /* Compute percentage of height used for ascent. If
25101 `:ascent ASCENT' is present and valid, use that. Otherwise,
25102 derive the ascent from the font in use. */
25103 if (prop
= Fplist_get (plist
, QCascent
),
25104 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
25105 ascent
= height
* NUMVAL (prop
) / 100.0;
25106 else if (!NILP (prop
)
25107 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
25108 ascent
= min (max (0, (int)tem
), height
);
25110 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
25113 #endif /* HAVE_WINDOW_SYSTEM */
25116 if (width
> 0 && it
->line_wrap
!= TRUNCATE
25117 && it
->current_x
+ width
> it
->last_visible_x
)
25119 width
= it
->last_visible_x
- it
->current_x
;
25120 #ifdef HAVE_WINDOW_SYSTEM
25121 /* Subtract one more pixel from the stretch width, but only on
25122 GUI frames, since on a TTY each glyph is one "pixel" wide. */
25123 width
-= FRAME_WINDOW_P (it
->f
);
25127 if (width
> 0 && height
> 0 && it
->glyph_row
)
25129 Lisp_Object o_object
= it
->object
;
25130 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
25133 if (!STRINGP (object
))
25134 object
= it
->w
->contents
;
25135 #ifdef HAVE_WINDOW_SYSTEM
25136 if (FRAME_WINDOW_P (it
->f
))
25137 append_stretch_glyph (it
, object
, width
, height
, ascent
);
25141 it
->object
= object
;
25142 it
->char_to_display
= ' ';
25143 it
->pixel_width
= it
->len
= 1;
25145 tty_append_glyph (it
);
25146 it
->object
= o_object
;
25150 it
->pixel_width
= width
;
25151 #ifdef HAVE_WINDOW_SYSTEM
25152 if (FRAME_WINDOW_P (it
->f
))
25154 it
->ascent
= it
->phys_ascent
= ascent
;
25155 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
25156 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
25157 take_vertical_position_into_account (it
);
25161 it
->nglyphs
= width
;
25164 /* Get information about special display element WHAT in an
25165 environment described by IT. WHAT is one of IT_TRUNCATION or
25166 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
25167 non-null glyph_row member. This function ensures that fields like
25168 face_id, c, len of IT are left untouched. */
25171 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
25178 temp_it
.object
= make_number (0);
25179 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
25181 if (what
== IT_CONTINUATION
)
25183 /* Continuation glyph. For R2L lines, we mirror it by hand. */
25184 if (it
->bidi_it
.paragraph_dir
== R2L
)
25185 SET_GLYPH_FROM_CHAR (glyph
, '/');
25187 SET_GLYPH_FROM_CHAR (glyph
, '\\');
25189 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25191 /* FIXME: Should we mirror GC for R2L lines? */
25192 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25193 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25196 else if (what
== IT_TRUNCATION
)
25198 /* Truncation glyph. */
25199 SET_GLYPH_FROM_CHAR (glyph
, '$');
25201 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25203 /* FIXME: Should we mirror GC for R2L lines? */
25204 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25205 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25211 #ifdef HAVE_WINDOW_SYSTEM
25212 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
25213 is turned off, we precede the truncation/continuation glyphs by a
25214 stretch glyph whose width is computed such that these special
25215 glyphs are aligned at the window margin, even when very different
25216 fonts are used in different glyph rows. */
25217 if (FRAME_WINDOW_P (temp_it
.f
)
25218 /* init_iterator calls this with it->glyph_row == NULL, and it
25219 wants only the pixel width of the truncation/continuation
25221 && temp_it
.glyph_row
25222 /* insert_left_trunc_glyphs calls us at the beginning of the
25223 row, and it has its own calculation of the stretch glyph
25225 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
25226 && (temp_it
.glyph_row
->reversed_p
25227 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
25228 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
25230 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
25232 if (stretch_width
> 0)
25234 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
25235 struct font
*font
=
25236 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
25237 int stretch_ascent
=
25238 (((temp_it
.ascent
+ temp_it
.descent
)
25239 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
25241 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
25242 temp_it
.ascent
+ temp_it
.descent
,
25249 temp_it
.what
= IT_CHARACTER
;
25251 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
25252 temp_it
.face_id
= GLYPH_FACE (glyph
);
25253 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
25255 PRODUCE_GLYPHS (&temp_it
);
25256 it
->pixel_width
= temp_it
.pixel_width
;
25257 it
->nglyphs
= temp_it
.pixel_width
;
25260 #ifdef HAVE_WINDOW_SYSTEM
25262 /* Calculate line-height and line-spacing properties.
25263 An integer value specifies explicit pixel value.
25264 A float value specifies relative value to current face height.
25265 A cons (float . face-name) specifies relative value to
25266 height of specified face font.
25268 Returns height in pixels, or nil. */
25272 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
25273 int boff
, int override
)
25275 Lisp_Object face_name
= Qnil
;
25276 int ascent
, descent
, height
;
25278 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
25283 face_name
= XCAR (val
);
25285 if (!NUMBERP (val
))
25286 val
= make_number (1);
25287 if (NILP (face_name
))
25289 height
= it
->ascent
+ it
->descent
;
25294 if (NILP (face_name
))
25296 font
= FRAME_FONT (it
->f
);
25297 boff
= FRAME_BASELINE_OFFSET (it
->f
);
25299 else if (EQ (face_name
, Qt
))
25308 face_id
= lookup_named_face (it
->f
, face_name
, 0);
25310 return make_number (-1);
25312 face
= FACE_FROM_ID (it
->f
, face_id
);
25315 return make_number (-1);
25316 boff
= font
->baseline_offset
;
25317 if (font
->vertical_centering
)
25318 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25321 ascent
= FONT_BASE (font
) + boff
;
25322 descent
= FONT_DESCENT (font
) - boff
;
25326 it
->override_ascent
= ascent
;
25327 it
->override_descent
= descent
;
25328 it
->override_boff
= boff
;
25331 height
= ascent
+ descent
;
25335 height
= (int)(XFLOAT_DATA (val
) * height
);
25336 else if (INTEGERP (val
))
25337 height
*= XINT (val
);
25339 return make_number (height
);
25343 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
25344 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
25345 and only if this is for a character for which no font was found.
25347 If the display method (it->glyphless_method) is
25348 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
25349 length of the acronym or the hexadecimal string, UPPER_XOFF and
25350 UPPER_YOFF are pixel offsets for the upper part of the string,
25351 LOWER_XOFF and LOWER_YOFF are for the lower part.
25353 For the other display methods, LEN through LOWER_YOFF are zero. */
25356 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
25357 short upper_xoff
, short upper_yoff
,
25358 short lower_xoff
, short lower_yoff
)
25360 struct glyph
*glyph
;
25361 enum glyph_row_area area
= it
->area
;
25363 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25364 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25366 /* If the glyph row is reversed, we need to prepend the glyph
25367 rather than append it. */
25368 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25372 /* Make room for the additional glyph. */
25373 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25375 glyph
= it
->glyph_row
->glyphs
[area
];
25377 glyph
->charpos
= CHARPOS (it
->position
);
25378 glyph
->object
= it
->object
;
25379 glyph
->pixel_width
= it
->pixel_width
;
25380 glyph
->ascent
= it
->ascent
;
25381 glyph
->descent
= it
->descent
;
25382 glyph
->voffset
= it
->voffset
;
25383 glyph
->type
= GLYPHLESS_GLYPH
;
25384 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
25385 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
25386 glyph
->u
.glyphless
.len
= len
;
25387 glyph
->u
.glyphless
.ch
= it
->c
;
25388 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25389 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25390 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25391 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25392 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25393 glyph
->multibyte_p
= it
->multibyte_p
;
25394 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25396 /* In R2L rows, the left and the right box edges need to be
25397 drawn in reverse direction. */
25398 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25399 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25403 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25404 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25406 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25407 || it
->phys_descent
> it
->descent
);
25408 glyph
->padding_p
= 0;
25409 glyph
->glyph_not_available_p
= 0;
25410 glyph
->face_id
= face_id
;
25411 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25414 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25415 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25417 glyph
->bidi_type
= it
->bidi_it
.type
;
25419 ++it
->glyph_row
->used
[area
];
25422 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25426 /* Produce a glyph for a glyphless character for iterator IT.
25427 IT->glyphless_method specifies which method to use for displaying
25428 the character. See the description of enum
25429 glyphless_display_method in dispextern.h for the detail.
25431 FOR_NO_FONT is nonzero if and only if this is for a character for
25432 which no font was found. ACRONYM, if non-nil, is an acronym string
25433 for the character. */
25436 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25441 int base_width
, base_height
, width
, height
;
25442 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25445 /* Get the metrics of the base font. We always refer to the current
25447 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25448 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25449 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25450 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25451 base_height
= it
->ascent
+ it
->descent
;
25452 base_width
= font
->average_width
;
25454 face_id
= merge_glyphless_glyph_face (it
);
25456 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25458 it
->pixel_width
= THIN_SPACE_WIDTH
;
25460 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25462 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25464 width
= CHAR_WIDTH (it
->c
);
25467 else if (width
> 4)
25469 it
->pixel_width
= base_width
* width
;
25471 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25477 unsigned int code
[6];
25479 int ascent
, descent
;
25480 struct font_metrics metrics_upper
, metrics_lower
;
25482 face
= FACE_FROM_ID (it
->f
, face_id
);
25483 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25484 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25486 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25488 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25489 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25490 if (CONSP (acronym
))
25491 acronym
= XCAR (acronym
);
25492 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25496 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25497 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25500 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25501 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25502 upper_len
= (len
+ 1) / 2;
25503 font
->driver
->text_extents (font
, code
, upper_len
,
25505 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25510 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25511 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25512 upper_xoff
= upper_yoff
= 2; /* the typical case */
25513 if (base_width
>= width
)
25515 /* Align the upper to the left, the lower to the right. */
25516 it
->pixel_width
= base_width
;
25517 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25521 /* Center the shorter one. */
25522 it
->pixel_width
= width
;
25523 if (metrics_upper
.width
>= metrics_lower
.width
)
25524 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25527 /* FIXME: This code doesn't look right. It formerly was
25528 missing the "lower_xoff = 0;", which couldn't have
25529 been right since it left lower_xoff uninitialized. */
25531 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25535 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25536 top, bottom, and between upper and lower strings. */
25537 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25538 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25539 /* Center vertically.
25540 H:base_height, D:base_descent
25541 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25543 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25544 descent = D - H/2 + h/2;
25545 lower_yoff = descent - 2 - ld;
25546 upper_yoff = lower_yoff - la - 1 - ud; */
25547 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25548 descent
= it
->descent
- (base_height
- height
) / 2;
25549 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25550 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25551 - metrics_upper
.descent
);
25552 /* Don't make the height shorter than the base height. */
25553 if (height
> base_height
)
25555 it
->ascent
= ascent
;
25556 it
->descent
= descent
;
25560 it
->phys_ascent
= it
->ascent
;
25561 it
->phys_descent
= it
->descent
;
25563 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25564 upper_xoff
, upper_yoff
,
25565 lower_xoff
, lower_yoff
);
25567 take_vertical_position_into_account (it
);
25572 Produce glyphs/get display metrics for the display element IT is
25573 loaded with. See the description of struct it in dispextern.h
25574 for an overview of struct it. */
25577 x_produce_glyphs (struct it
*it
)
25579 int extra_line_spacing
= it
->extra_line_spacing
;
25581 it
->glyph_not_available_p
= 0;
25583 if (it
->what
== IT_CHARACTER
)
25586 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25587 struct font
*font
= face
->font
;
25588 struct font_metrics
*pcm
= NULL
;
25589 int boff
; /* Baseline offset. */
25593 /* When no suitable font is found, display this character by
25594 the method specified in the first extra slot of
25595 Vglyphless_char_display. */
25596 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25598 eassert (it
->what
== IT_GLYPHLESS
);
25599 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25603 boff
= font
->baseline_offset
;
25604 if (font
->vertical_centering
)
25605 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25607 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25613 if (it
->override_ascent
>= 0)
25615 it
->ascent
= it
->override_ascent
;
25616 it
->descent
= it
->override_descent
;
25617 boff
= it
->override_boff
;
25621 it
->ascent
= FONT_BASE (font
) + boff
;
25622 it
->descent
= FONT_DESCENT (font
) - boff
;
25625 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25627 pcm
= get_per_char_metric (font
, &char2b
);
25628 if (pcm
->width
== 0
25629 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25635 it
->phys_ascent
= pcm
->ascent
+ boff
;
25636 it
->phys_descent
= pcm
->descent
- boff
;
25637 it
->pixel_width
= pcm
->width
;
25641 it
->glyph_not_available_p
= 1;
25642 it
->phys_ascent
= it
->ascent
;
25643 it
->phys_descent
= it
->descent
;
25644 it
->pixel_width
= font
->space_width
;
25647 if (it
->constrain_row_ascent_descent_p
)
25649 if (it
->descent
> it
->max_descent
)
25651 it
->ascent
+= it
->descent
- it
->max_descent
;
25652 it
->descent
= it
->max_descent
;
25654 if (it
->ascent
> it
->max_ascent
)
25656 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25657 it
->ascent
= it
->max_ascent
;
25659 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25660 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25661 extra_line_spacing
= 0;
25664 /* If this is a space inside a region of text with
25665 `space-width' property, change its width. */
25666 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25668 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25670 /* If face has a box, add the box thickness to the character
25671 height. If character has a box line to the left and/or
25672 right, add the box line width to the character's width. */
25673 if (face
->box
!= FACE_NO_BOX
)
25675 int thick
= face
->box_line_width
;
25679 it
->ascent
+= thick
;
25680 it
->descent
+= thick
;
25685 if (it
->start_of_box_run_p
)
25686 it
->pixel_width
+= thick
;
25687 if (it
->end_of_box_run_p
)
25688 it
->pixel_width
+= thick
;
25691 /* If face has an overline, add the height of the overline
25692 (1 pixel) and a 1 pixel margin to the character height. */
25693 if (face
->overline_p
)
25694 it
->ascent
+= overline_margin
;
25696 if (it
->constrain_row_ascent_descent_p
)
25698 if (it
->ascent
> it
->max_ascent
)
25699 it
->ascent
= it
->max_ascent
;
25700 if (it
->descent
> it
->max_descent
)
25701 it
->descent
= it
->max_descent
;
25704 take_vertical_position_into_account (it
);
25706 /* If we have to actually produce glyphs, do it. */
25711 /* Translate a space with a `space-width' property
25712 into a stretch glyph. */
25713 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25714 / FONT_HEIGHT (font
));
25715 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25716 it
->ascent
+ it
->descent
, ascent
);
25721 /* If characters with lbearing or rbearing are displayed
25722 in this line, record that fact in a flag of the
25723 glyph row. This is used to optimize X output code. */
25724 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25725 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25727 if (! stretched_p
&& it
->pixel_width
== 0)
25728 /* We assure that all visible glyphs have at least 1-pixel
25730 it
->pixel_width
= 1;
25732 else if (it
->char_to_display
== '\n')
25734 /* A newline has no width, but we need the height of the
25735 line. But if previous part of the line sets a height,
25736 don't increase that height. */
25738 Lisp_Object height
;
25739 Lisp_Object total_height
= Qnil
;
25741 it
->override_ascent
= -1;
25742 it
->pixel_width
= 0;
25745 height
= get_it_property (it
, Qline_height
);
25746 /* Split (line-height total-height) list. */
25748 && CONSP (XCDR (height
))
25749 && NILP (XCDR (XCDR (height
))))
25751 total_height
= XCAR (XCDR (height
));
25752 height
= XCAR (height
);
25754 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25756 if (it
->override_ascent
>= 0)
25758 it
->ascent
= it
->override_ascent
;
25759 it
->descent
= it
->override_descent
;
25760 boff
= it
->override_boff
;
25764 it
->ascent
= FONT_BASE (font
) + boff
;
25765 it
->descent
= FONT_DESCENT (font
) - boff
;
25768 if (EQ (height
, Qt
))
25770 if (it
->descent
> it
->max_descent
)
25772 it
->ascent
+= it
->descent
- it
->max_descent
;
25773 it
->descent
= it
->max_descent
;
25775 if (it
->ascent
> it
->max_ascent
)
25777 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25778 it
->ascent
= it
->max_ascent
;
25780 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25781 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25782 it
->constrain_row_ascent_descent_p
= 1;
25783 extra_line_spacing
= 0;
25787 Lisp_Object spacing
;
25789 it
->phys_ascent
= it
->ascent
;
25790 it
->phys_descent
= it
->descent
;
25792 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25793 && face
->box
!= FACE_NO_BOX
25794 && face
->box_line_width
> 0)
25796 it
->ascent
+= face
->box_line_width
;
25797 it
->descent
+= face
->box_line_width
;
25800 && XINT (height
) > it
->ascent
+ it
->descent
)
25801 it
->ascent
= XINT (height
) - it
->descent
;
25803 if (!NILP (total_height
))
25804 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25807 spacing
= get_it_property (it
, Qline_spacing
);
25808 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25810 if (INTEGERP (spacing
))
25812 extra_line_spacing
= XINT (spacing
);
25813 if (!NILP (total_height
))
25814 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25818 else /* i.e. (it->char_to_display == '\t') */
25820 if (font
->space_width
> 0)
25822 int tab_width
= it
->tab_width
* font
->space_width
;
25823 int x
= it
->current_x
+ it
->continuation_lines_width
;
25824 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25826 /* If the distance from the current position to the next tab
25827 stop is less than a space character width, use the
25828 tab stop after that. */
25829 if (next_tab_x
- x
< font
->space_width
)
25830 next_tab_x
+= tab_width
;
25832 it
->pixel_width
= next_tab_x
- x
;
25834 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25835 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25839 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25840 it
->ascent
+ it
->descent
, it
->ascent
);
25845 it
->pixel_width
= 0;
25850 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25852 /* A static composition.
25854 Note: A composition is represented as one glyph in the
25855 glyph matrix. There are no padding glyphs.
25857 Important note: pixel_width, ascent, and descent are the
25858 values of what is drawn by draw_glyphs (i.e. the values of
25859 the overall glyphs composed). */
25860 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25861 int boff
; /* baseline offset */
25862 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25863 int glyph_len
= cmp
->glyph_len
;
25864 struct font
*font
= face
->font
;
25868 /* If we have not yet calculated pixel size data of glyphs of
25869 the composition for the current face font, calculate them
25870 now. Theoretically, we have to check all fonts for the
25871 glyphs, but that requires much time and memory space. So,
25872 here we check only the font of the first glyph. This may
25873 lead to incorrect display, but it's very rare, and C-l
25874 (recenter-top-bottom) can correct the display anyway. */
25875 if (! cmp
->font
|| cmp
->font
!= font
)
25877 /* Ascent and descent of the font of the first character
25878 of this composition (adjusted by baseline offset).
25879 Ascent and descent of overall glyphs should not be less
25880 than these, respectively. */
25881 int font_ascent
, font_descent
, font_height
;
25882 /* Bounding box of the overall glyphs. */
25883 int leftmost
, rightmost
, lowest
, highest
;
25884 int lbearing
, rbearing
;
25885 int i
, width
, ascent
, descent
;
25886 int left_padded
= 0, right_padded
= 0;
25887 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25889 struct font_metrics
*pcm
;
25890 int font_not_found_p
;
25893 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25894 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25896 if (glyph_len
< cmp
->glyph_len
)
25898 for (i
= 0; i
< glyph_len
; i
++)
25900 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25902 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25907 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25908 : IT_CHARPOS (*it
));
25909 /* If no suitable font is found, use the default font. */
25910 font_not_found_p
= font
== NULL
;
25911 if (font_not_found_p
)
25913 face
= face
->ascii_face
;
25916 boff
= font
->baseline_offset
;
25917 if (font
->vertical_centering
)
25918 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25919 font_ascent
= FONT_BASE (font
) + boff
;
25920 font_descent
= FONT_DESCENT (font
) - boff
;
25921 font_height
= FONT_HEIGHT (font
);
25926 if (! font_not_found_p
)
25928 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25930 pcm
= get_per_char_metric (font
, &char2b
);
25933 /* Initialize the bounding box. */
25936 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25937 ascent
= pcm
->ascent
;
25938 descent
= pcm
->descent
;
25939 lbearing
= pcm
->lbearing
;
25940 rbearing
= pcm
->rbearing
;
25944 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25945 ascent
= FONT_BASE (font
);
25946 descent
= FONT_DESCENT (font
);
25953 lowest
= - descent
+ boff
;
25954 highest
= ascent
+ boff
;
25956 if (! font_not_found_p
25957 && font
->default_ascent
25958 && CHAR_TABLE_P (Vuse_default_ascent
)
25959 && !NILP (Faref (Vuse_default_ascent
,
25960 make_number (it
->char_to_display
))))
25961 highest
= font
->default_ascent
+ boff
;
25963 /* Draw the first glyph at the normal position. It may be
25964 shifted to right later if some other glyphs are drawn
25966 cmp
->offsets
[i
* 2] = 0;
25967 cmp
->offsets
[i
* 2 + 1] = boff
;
25968 cmp
->lbearing
= lbearing
;
25969 cmp
->rbearing
= rbearing
;
25971 /* Set cmp->offsets for the remaining glyphs. */
25972 for (i
++; i
< glyph_len
; i
++)
25974 int left
, right
, btm
, top
;
25975 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25977 struct face
*this_face
;
25981 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25982 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25983 font
= this_face
->font
;
25989 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25991 pcm
= get_per_char_metric (font
, &char2b
);
25994 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25997 width
= pcm
->width
;
25998 ascent
= pcm
->ascent
;
25999 descent
= pcm
->descent
;
26000 lbearing
= pcm
->lbearing
;
26001 rbearing
= pcm
->rbearing
;
26002 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
26004 /* Relative composition with or without
26005 alternate chars. */
26006 left
= (leftmost
+ rightmost
- width
) / 2;
26007 btm
= - descent
+ boff
;
26008 if (font
->relative_compose
26009 && (! CHAR_TABLE_P (Vignore_relative_composition
)
26010 || NILP (Faref (Vignore_relative_composition
,
26011 make_number (ch
)))))
26014 if (- descent
>= font
->relative_compose
)
26015 /* One extra pixel between two glyphs. */
26017 else if (ascent
<= 0)
26018 /* One extra pixel between two glyphs. */
26019 btm
= lowest
- 1 - ascent
- descent
;
26024 /* A composition rule is specified by an integer
26025 value that encodes global and new reference
26026 points (GREF and NREF). GREF and NREF are
26027 specified by numbers as below:
26029 0---1---2 -- ascent
26033 9--10--11 -- center
26035 ---3---4---5--- baseline
26037 6---7---8 -- descent
26039 int rule
= COMPOSITION_RULE (cmp
, i
);
26040 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
26042 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
26043 grefx
= gref
% 3, nrefx
= nref
% 3;
26044 grefy
= gref
/ 3, nrefy
= nref
/ 3;
26046 xoff
= font_height
* (xoff
- 128) / 256;
26048 yoff
= font_height
* (yoff
- 128) / 256;
26051 + grefx
* (rightmost
- leftmost
) / 2
26052 - nrefx
* width
/ 2
26055 btm
= ((grefy
== 0 ? highest
26057 : grefy
== 2 ? lowest
26058 : (highest
+ lowest
) / 2)
26059 - (nrefy
== 0 ? ascent
+ descent
26060 : nrefy
== 1 ? descent
- boff
26062 : (ascent
+ descent
) / 2)
26066 cmp
->offsets
[i
* 2] = left
;
26067 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
26069 /* Update the bounding box of the overall glyphs. */
26072 right
= left
+ width
;
26073 if (left
< leftmost
)
26075 if (right
> rightmost
)
26078 top
= btm
+ descent
+ ascent
;
26084 if (cmp
->lbearing
> left
+ lbearing
)
26085 cmp
->lbearing
= left
+ lbearing
;
26086 if (cmp
->rbearing
< left
+ rbearing
)
26087 cmp
->rbearing
= left
+ rbearing
;
26091 /* If there are glyphs whose x-offsets are negative,
26092 shift all glyphs to the right and make all x-offsets
26096 for (i
= 0; i
< cmp
->glyph_len
; i
++)
26097 cmp
->offsets
[i
* 2] -= leftmost
;
26098 rightmost
-= leftmost
;
26099 cmp
->lbearing
-= leftmost
;
26100 cmp
->rbearing
-= leftmost
;
26103 if (left_padded
&& cmp
->lbearing
< 0)
26105 for (i
= 0; i
< cmp
->glyph_len
; i
++)
26106 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
26107 rightmost
-= cmp
->lbearing
;
26108 cmp
->rbearing
-= cmp
->lbearing
;
26111 if (right_padded
&& rightmost
< cmp
->rbearing
)
26113 rightmost
= cmp
->rbearing
;
26116 cmp
->pixel_width
= rightmost
;
26117 cmp
->ascent
= highest
;
26118 cmp
->descent
= - lowest
;
26119 if (cmp
->ascent
< font_ascent
)
26120 cmp
->ascent
= font_ascent
;
26121 if (cmp
->descent
< font_descent
)
26122 cmp
->descent
= font_descent
;
26126 && (cmp
->lbearing
< 0
26127 || cmp
->rbearing
> cmp
->pixel_width
))
26128 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26130 it
->pixel_width
= cmp
->pixel_width
;
26131 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
26132 it
->descent
= it
->phys_descent
= cmp
->descent
;
26133 if (face
->box
!= FACE_NO_BOX
)
26135 int thick
= face
->box_line_width
;
26139 it
->ascent
+= thick
;
26140 it
->descent
+= thick
;
26145 if (it
->start_of_box_run_p
)
26146 it
->pixel_width
+= thick
;
26147 if (it
->end_of_box_run_p
)
26148 it
->pixel_width
+= thick
;
26151 /* If face has an overline, add the height of the overline
26152 (1 pixel) and a 1 pixel margin to the character height. */
26153 if (face
->overline_p
)
26154 it
->ascent
+= overline_margin
;
26156 take_vertical_position_into_account (it
);
26157 if (it
->ascent
< 0)
26159 if (it
->descent
< 0)
26162 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
26163 append_composite_glyph (it
);
26165 else if (it
->what
== IT_COMPOSITION
)
26167 /* A dynamic (automatic) composition. */
26168 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26169 Lisp_Object gstring
;
26170 struct font_metrics metrics
;
26174 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
26176 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
26179 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
26180 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26181 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
26182 it
->descent
= it
->phys_descent
= metrics
.descent
;
26183 if (face
->box
!= FACE_NO_BOX
)
26185 int thick
= face
->box_line_width
;
26189 it
->ascent
+= thick
;
26190 it
->descent
+= thick
;
26195 if (it
->start_of_box_run_p
)
26196 it
->pixel_width
+= thick
;
26197 if (it
->end_of_box_run_p
)
26198 it
->pixel_width
+= thick
;
26200 /* If face has an overline, add the height of the overline
26201 (1 pixel) and a 1 pixel margin to the character height. */
26202 if (face
->overline_p
)
26203 it
->ascent
+= overline_margin
;
26204 take_vertical_position_into_account (it
);
26205 if (it
->ascent
< 0)
26207 if (it
->descent
< 0)
26211 append_composite_glyph (it
);
26213 else if (it
->what
== IT_GLYPHLESS
)
26214 produce_glyphless_glyph (it
, 0, Qnil
);
26215 else if (it
->what
== IT_IMAGE
)
26216 produce_image_glyph (it
);
26217 else if (it
->what
== IT_STRETCH
)
26218 produce_stretch_glyph (it
);
26221 /* Accumulate dimensions. Note: can't assume that it->descent > 0
26222 because this isn't true for images with `:ascent 100'. */
26223 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
26224 if (it
->area
== TEXT_AREA
)
26225 it
->current_x
+= it
->pixel_width
;
26227 if (extra_line_spacing
> 0)
26229 it
->descent
+= extra_line_spacing
;
26230 if (extra_line_spacing
> it
->max_extra_line_spacing
)
26231 it
->max_extra_line_spacing
= extra_line_spacing
;
26234 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
26235 it
->max_descent
= max (it
->max_descent
, it
->descent
);
26236 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
26237 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
26241 Output LEN glyphs starting at START at the nominal cursor position.
26242 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
26243 being updated, and UPDATED_AREA is the area of that row being updated. */
26246 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26247 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26249 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
26251 eassert (updated_row
);
26252 /* When the window is hscrolled, cursor hpos can legitimately be out
26253 of bounds, but we draw the cursor at the corresponding window
26254 margin in that case. */
26255 if (!updated_row
->reversed_p
&& chpos
< 0)
26257 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
26258 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
26262 /* Write glyphs. */
26264 hpos
= start
- updated_row
->glyphs
[updated_area
];
26265 x
= draw_glyphs (w
, w
->output_cursor
.x
,
26266 updated_row
, updated_area
,
26268 DRAW_NORMAL_TEXT
, 0);
26270 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
26271 if (updated_area
== TEXT_AREA
26272 && w
->phys_cursor_on_p
26273 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
26275 && chpos
< hpos
+ len
)
26276 w
->phys_cursor_on_p
= 0;
26280 /* Advance the output cursor. */
26281 w
->output_cursor
.hpos
+= len
;
26282 w
->output_cursor
.x
= x
;
26287 Insert LEN glyphs from START at the nominal cursor position. */
26290 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26291 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26294 int line_height
, shift_by_width
, shifted_region_width
;
26295 struct glyph_row
*row
;
26296 struct glyph
*glyph
;
26297 int frame_x
, frame_y
;
26300 eassert (updated_row
);
26302 f
= XFRAME (WINDOW_FRAME (w
));
26304 /* Get the height of the line we are in. */
26306 line_height
= row
->height
;
26308 /* Get the width of the glyphs to insert. */
26309 shift_by_width
= 0;
26310 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
26311 shift_by_width
+= glyph
->pixel_width
;
26313 /* Get the width of the region to shift right. */
26314 shifted_region_width
= (window_box_width (w
, updated_area
)
26315 - w
->output_cursor
.x
26319 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
26320 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
26322 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
26323 line_height
, shift_by_width
);
26325 /* Write the glyphs. */
26326 hpos
= start
- row
->glyphs
[updated_area
];
26327 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
26329 DRAW_NORMAL_TEXT
, 0);
26331 /* Advance the output cursor. */
26332 w
->output_cursor
.hpos
+= len
;
26333 w
->output_cursor
.x
+= shift_by_width
;
26339 Erase the current text line from the nominal cursor position
26340 (inclusive) to pixel column TO_X (exclusive). The idea is that
26341 everything from TO_X onward is already erased.
26343 TO_X is a pixel position relative to UPDATED_AREA of currently
26344 updated window W. TO_X == -1 means clear to the end of this area. */
26347 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
26348 enum glyph_row_area updated_area
, int to_x
)
26351 int max_x
, min_y
, max_y
;
26352 int from_x
, from_y
, to_y
;
26354 eassert (updated_row
);
26355 f
= XFRAME (w
->frame
);
26357 if (updated_row
->full_width_p
)
26358 max_x
= (WINDOW_PIXEL_WIDTH (w
)
26359 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
26361 max_x
= window_box_width (w
, updated_area
);
26362 max_y
= window_text_bottom_y (w
);
26364 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
26365 of window. For TO_X > 0, truncate to end of drawing area. */
26371 to_x
= min (to_x
, max_x
);
26373 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
26375 /* Notice if the cursor will be cleared by this operation. */
26376 if (!updated_row
->full_width_p
)
26377 notice_overwritten_cursor (w
, updated_area
,
26378 w
->output_cursor
.x
, -1,
26380 MATRIX_ROW_BOTTOM_Y (updated_row
));
26382 from_x
= w
->output_cursor
.x
;
26384 /* Translate to frame coordinates. */
26385 if (updated_row
->full_width_p
)
26387 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
26388 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26392 int area_left
= window_box_left (w
, updated_area
);
26393 from_x
+= area_left
;
26397 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26398 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
26399 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26401 /* Prevent inadvertently clearing to end of the X window. */
26402 if (to_x
> from_x
&& to_y
> from_y
)
26405 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26406 to_x
- from_x
, to_y
- from_y
);
26411 #endif /* HAVE_WINDOW_SYSTEM */
26415 /***********************************************************************
26417 ***********************************************************************/
26419 /* Value is the internal representation of the specified cursor type
26420 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26421 of the bar cursor. */
26423 static enum text_cursor_kinds
26424 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26426 enum text_cursor_kinds type
;
26431 if (EQ (arg
, Qbox
))
26432 return FILLED_BOX_CURSOR
;
26434 if (EQ (arg
, Qhollow
))
26435 return HOLLOW_BOX_CURSOR
;
26437 if (EQ (arg
, Qbar
))
26444 && EQ (XCAR (arg
), Qbar
)
26445 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26447 *width
= XINT (XCDR (arg
));
26451 if (EQ (arg
, Qhbar
))
26454 return HBAR_CURSOR
;
26458 && EQ (XCAR (arg
), Qhbar
)
26459 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26461 *width
= XINT (XCDR (arg
));
26462 return HBAR_CURSOR
;
26465 /* Treat anything unknown as "hollow box cursor".
26466 It was bad to signal an error; people have trouble fixing
26467 .Xdefaults with Emacs, when it has something bad in it. */
26468 type
= HOLLOW_BOX_CURSOR
;
26473 /* Set the default cursor types for specified frame. */
26475 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26480 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26481 FRAME_CURSOR_WIDTH (f
) = width
;
26483 /* By default, set up the blink-off state depending on the on-state. */
26485 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26488 FRAME_BLINK_OFF_CURSOR (f
)
26489 = get_specified_cursor_type (XCDR (tem
), &width
);
26490 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26493 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26495 /* Make sure the cursor gets redrawn. */
26496 f
->cursor_type_changed
= 1;
26500 #ifdef HAVE_WINDOW_SYSTEM
26502 /* Return the cursor we want to be displayed in window W. Return
26503 width of bar/hbar cursor through WIDTH arg. Return with
26504 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26505 (i.e. if the `system caret' should track this cursor).
26507 In a mini-buffer window, we want the cursor only to appear if we
26508 are reading input from this window. For the selected window, we
26509 want the cursor type given by the frame parameter or buffer local
26510 setting of cursor-type. If explicitly marked off, draw no cursor.
26511 In all other cases, we want a hollow box cursor. */
26513 static enum text_cursor_kinds
26514 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26515 int *active_cursor
)
26517 struct frame
*f
= XFRAME (w
->frame
);
26518 struct buffer
*b
= XBUFFER (w
->contents
);
26519 int cursor_type
= DEFAULT_CURSOR
;
26520 Lisp_Object alt_cursor
;
26521 int non_selected
= 0;
26523 *active_cursor
= 1;
26526 if (cursor_in_echo_area
26527 && FRAME_HAS_MINIBUF_P (f
)
26528 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26530 if (w
== XWINDOW (echo_area_window
))
26532 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26534 *width
= FRAME_CURSOR_WIDTH (f
);
26535 return FRAME_DESIRED_CURSOR (f
);
26538 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26541 *active_cursor
= 0;
26545 /* Detect a nonselected window or nonselected frame. */
26546 else if (w
!= XWINDOW (f
->selected_window
)
26547 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26549 *active_cursor
= 0;
26551 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26557 /* Never display a cursor in a window in which cursor-type is nil. */
26558 if (NILP (BVAR (b
, cursor_type
)))
26561 /* Get the normal cursor type for this window. */
26562 if (EQ (BVAR (b
, cursor_type
), Qt
))
26564 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26565 *width
= FRAME_CURSOR_WIDTH (f
);
26568 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26570 /* Use cursor-in-non-selected-windows instead
26571 for non-selected window or frame. */
26574 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26575 if (!EQ (Qt
, alt_cursor
))
26576 return get_specified_cursor_type (alt_cursor
, width
);
26577 /* t means modify the normal cursor type. */
26578 if (cursor_type
== FILLED_BOX_CURSOR
)
26579 cursor_type
= HOLLOW_BOX_CURSOR
;
26580 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26582 return cursor_type
;
26585 /* Use normal cursor if not blinked off. */
26586 if (!w
->cursor_off_p
)
26588 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26590 if (cursor_type
== FILLED_BOX_CURSOR
)
26592 /* Using a block cursor on large images can be very annoying.
26593 So use a hollow cursor for "large" images.
26594 If image is not transparent (no mask), also use hollow cursor. */
26595 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26596 if (img
!= NULL
&& IMAGEP (img
->spec
))
26598 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26599 where N = size of default frame font size.
26600 This should cover most of the "tiny" icons people may use. */
26602 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26603 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26604 cursor_type
= HOLLOW_BOX_CURSOR
;
26607 else if (cursor_type
!= NO_CURSOR
)
26609 /* Display current only supports BOX and HOLLOW cursors for images.
26610 So for now, unconditionally use a HOLLOW cursor when cursor is
26611 not a solid box cursor. */
26612 cursor_type
= HOLLOW_BOX_CURSOR
;
26615 return cursor_type
;
26618 /* Cursor is blinked off, so determine how to "toggle" it. */
26620 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26621 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26622 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26624 /* Then see if frame has specified a specific blink off cursor type. */
26625 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26627 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26628 return FRAME_BLINK_OFF_CURSOR (f
);
26632 /* Some people liked having a permanently visible blinking cursor,
26633 while others had very strong opinions against it. So it was
26634 decided to remove it. KFS 2003-09-03 */
26636 /* Finally perform built-in cursor blinking:
26637 filled box <-> hollow box
26638 wide [h]bar <-> narrow [h]bar
26639 narrow [h]bar <-> no cursor
26640 other type <-> no cursor */
26642 if (cursor_type
== FILLED_BOX_CURSOR
)
26643 return HOLLOW_BOX_CURSOR
;
26645 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26648 return cursor_type
;
26656 /* Notice when the text cursor of window W has been completely
26657 overwritten by a drawing operation that outputs glyphs in AREA
26658 starting at X0 and ending at X1 in the line starting at Y0 and
26659 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26660 the rest of the line after X0 has been written. Y coordinates
26661 are window-relative. */
26664 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26665 int x0
, int x1
, int y0
, int y1
)
26667 int cx0
, cx1
, cy0
, cy1
;
26668 struct glyph_row
*row
;
26670 if (!w
->phys_cursor_on_p
)
26672 if (area
!= TEXT_AREA
)
26675 if (w
->phys_cursor
.vpos
< 0
26676 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26677 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26678 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26681 if (row
->cursor_in_fringe_p
)
26683 row
->cursor_in_fringe_p
= 0;
26684 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26685 w
->phys_cursor_on_p
= 0;
26689 cx0
= w
->phys_cursor
.x
;
26690 cx1
= cx0
+ w
->phys_cursor_width
;
26691 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26694 /* The cursor image will be completely removed from the
26695 screen if the output area intersects the cursor area in
26696 y-direction. When we draw in [y0 y1[, and some part of
26697 the cursor is at y < y0, that part must have been drawn
26698 before. When scrolling, the cursor is erased before
26699 actually scrolling, so we don't come here. When not
26700 scrolling, the rows above the old cursor row must have
26701 changed, and in this case these rows must have written
26702 over the cursor image.
26704 Likewise if part of the cursor is below y1, with the
26705 exception of the cursor being in the first blank row at
26706 the buffer and window end because update_text_area
26707 doesn't draw that row. (Except when it does, but
26708 that's handled in update_text_area.) */
26710 cy0
= w
->phys_cursor
.y
;
26711 cy1
= cy0
+ w
->phys_cursor_height
;
26712 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26715 w
->phys_cursor_on_p
= 0;
26718 #endif /* HAVE_WINDOW_SYSTEM */
26721 /************************************************************************
26723 ************************************************************************/
26725 #ifdef HAVE_WINDOW_SYSTEM
26728 Fix the display of area AREA of overlapping row ROW in window W
26729 with respect to the overlapping part OVERLAPS. */
26732 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26733 enum glyph_row_area area
, int overlaps
)
26740 for (i
= 0; i
< row
->used
[area
];)
26742 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26744 int start
= i
, start_x
= x
;
26748 x
+= row
->glyphs
[area
][i
].pixel_width
;
26751 while (i
< row
->used
[area
]
26752 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26754 draw_glyphs (w
, start_x
, row
, area
,
26756 DRAW_NORMAL_TEXT
, overlaps
);
26760 x
+= row
->glyphs
[area
][i
].pixel_width
;
26770 Draw the cursor glyph of window W in glyph row ROW. See the
26771 comment of draw_glyphs for the meaning of HL. */
26774 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26775 enum draw_glyphs_face hl
)
26777 /* If cursor hpos is out of bounds, don't draw garbage. This can
26778 happen in mini-buffer windows when switching between echo area
26779 glyphs and mini-buffer. */
26780 if ((row
->reversed_p
26781 ? (w
->phys_cursor
.hpos
>= 0)
26782 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26784 int on_p
= w
->phys_cursor_on_p
;
26786 int hpos
= w
->phys_cursor
.hpos
;
26788 /* When the window is hscrolled, cursor hpos can legitimately be
26789 out of bounds, but we draw the cursor at the corresponding
26790 window margin in that case. */
26791 if (!row
->reversed_p
&& hpos
< 0)
26793 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26794 hpos
= row
->used
[TEXT_AREA
] - 1;
26796 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26798 w
->phys_cursor_on_p
= on_p
;
26800 if (hl
== DRAW_CURSOR
)
26801 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26802 /* When we erase the cursor, and ROW is overlapped by other
26803 rows, make sure that these overlapping parts of other rows
26805 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26807 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26809 if (row
> w
->current_matrix
->rows
26810 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26811 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26812 OVERLAPS_ERASED_CURSOR
);
26814 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26815 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26816 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26817 OVERLAPS_ERASED_CURSOR
);
26823 /* Erase the image of a cursor of window W from the screen. */
26829 erase_phys_cursor (struct window
*w
)
26831 struct frame
*f
= XFRAME (w
->frame
);
26832 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26833 int hpos
= w
->phys_cursor
.hpos
;
26834 int vpos
= w
->phys_cursor
.vpos
;
26835 int mouse_face_here_p
= 0;
26836 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26837 struct glyph_row
*cursor_row
;
26838 struct glyph
*cursor_glyph
;
26839 enum draw_glyphs_face hl
;
26841 /* No cursor displayed or row invalidated => nothing to do on the
26843 if (w
->phys_cursor_type
== NO_CURSOR
)
26844 goto mark_cursor_off
;
26846 /* VPOS >= active_glyphs->nrows means that window has been resized.
26847 Don't bother to erase the cursor. */
26848 if (vpos
>= active_glyphs
->nrows
)
26849 goto mark_cursor_off
;
26851 /* If row containing cursor is marked invalid, there is nothing we
26853 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26854 if (!cursor_row
->enabled_p
)
26855 goto mark_cursor_off
;
26857 /* If line spacing is > 0, old cursor may only be partially visible in
26858 window after split-window. So adjust visible height. */
26859 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26860 window_text_bottom_y (w
) - cursor_row
->y
);
26862 /* If row is completely invisible, don't attempt to delete a cursor which
26863 isn't there. This can happen if cursor is at top of a window, and
26864 we switch to a buffer with a header line in that window. */
26865 if (cursor_row
->visible_height
<= 0)
26866 goto mark_cursor_off
;
26868 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26869 if (cursor_row
->cursor_in_fringe_p
)
26871 cursor_row
->cursor_in_fringe_p
= 0;
26872 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26873 goto mark_cursor_off
;
26876 /* This can happen when the new row is shorter than the old one.
26877 In this case, either draw_glyphs or clear_end_of_line
26878 should have cleared the cursor. Note that we wouldn't be
26879 able to erase the cursor in this case because we don't have a
26880 cursor glyph at hand. */
26881 if ((cursor_row
->reversed_p
26882 ? (w
->phys_cursor
.hpos
< 0)
26883 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26884 goto mark_cursor_off
;
26886 /* When the window is hscrolled, cursor hpos can legitimately be out
26887 of bounds, but we draw the cursor at the corresponding window
26888 margin in that case. */
26889 if (!cursor_row
->reversed_p
&& hpos
< 0)
26891 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26892 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26894 /* If the cursor is in the mouse face area, redisplay that when
26895 we clear the cursor. */
26896 if (! NILP (hlinfo
->mouse_face_window
)
26897 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26898 /* Don't redraw the cursor's spot in mouse face if it is at the
26899 end of a line (on a newline). The cursor appears there, but
26900 mouse highlighting does not. */
26901 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26902 mouse_face_here_p
= 1;
26904 /* Maybe clear the display under the cursor. */
26905 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26908 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26911 cursor_glyph
= get_phys_cursor_glyph (w
);
26912 if (cursor_glyph
== NULL
)
26913 goto mark_cursor_off
;
26915 width
= cursor_glyph
->pixel_width
;
26916 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26917 x
= w
->phys_cursor
.x
;
26919 width
-= left_x
- x
;
26920 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26921 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26922 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26925 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26928 /* Erase the cursor by redrawing the character underneath it. */
26929 if (mouse_face_here_p
)
26930 hl
= DRAW_MOUSE_FACE
;
26932 hl
= DRAW_NORMAL_TEXT
;
26933 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26936 w
->phys_cursor_on_p
= 0;
26937 w
->phys_cursor_type
= NO_CURSOR
;
26942 Display or clear cursor of window W. If ON is zero, clear the
26943 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26944 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26947 display_and_set_cursor (struct window
*w
, bool on
,
26948 int hpos
, int vpos
, int x
, int y
)
26950 struct frame
*f
= XFRAME (w
->frame
);
26951 int new_cursor_type
;
26952 int new_cursor_width
;
26954 struct glyph_row
*glyph_row
;
26955 struct glyph
*glyph
;
26957 /* This is pointless on invisible frames, and dangerous on garbaged
26958 windows and frames; in the latter case, the frame or window may
26959 be in the midst of changing its size, and x and y may be off the
26961 if (! FRAME_VISIBLE_P (f
)
26962 || FRAME_GARBAGED_P (f
)
26963 || vpos
>= w
->current_matrix
->nrows
26964 || hpos
>= w
->current_matrix
->matrix_w
)
26967 /* If cursor is off and we want it off, return quickly. */
26968 if (!on
&& !w
->phys_cursor_on_p
)
26971 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26972 /* If cursor row is not enabled, we don't really know where to
26973 display the cursor. */
26974 if (!glyph_row
->enabled_p
)
26976 w
->phys_cursor_on_p
= 0;
26981 if (!glyph_row
->exact_window_width_line_p
26982 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26983 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26985 eassert (input_blocked_p ());
26987 /* Set new_cursor_type to the cursor we want to be displayed. */
26988 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26989 &new_cursor_width
, &active_cursor
);
26991 /* If cursor is currently being shown and we don't want it to be or
26992 it is in the wrong place, or the cursor type is not what we want,
26994 if (w
->phys_cursor_on_p
26996 || w
->phys_cursor
.x
!= x
26997 || w
->phys_cursor
.y
!= y
26998 || new_cursor_type
!= w
->phys_cursor_type
26999 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
27000 && new_cursor_width
!= w
->phys_cursor_width
)))
27001 erase_phys_cursor (w
);
27003 /* Don't check phys_cursor_on_p here because that flag is only set
27004 to zero in some cases where we know that the cursor has been
27005 completely erased, to avoid the extra work of erasing the cursor
27006 twice. In other words, phys_cursor_on_p can be 1 and the cursor
27007 still not be visible, or it has only been partly erased. */
27010 w
->phys_cursor_ascent
= glyph_row
->ascent
;
27011 w
->phys_cursor_height
= glyph_row
->height
;
27013 /* Set phys_cursor_.* before x_draw_.* is called because some
27014 of them may need the information. */
27015 w
->phys_cursor
.x
= x
;
27016 w
->phys_cursor
.y
= glyph_row
->y
;
27017 w
->phys_cursor
.hpos
= hpos
;
27018 w
->phys_cursor
.vpos
= vpos
;
27021 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
27022 new_cursor_type
, new_cursor_width
,
27023 on
, active_cursor
);
27027 /* Switch the display of W's cursor on or off, according to the value
27031 update_window_cursor (struct window
*w
, bool on
)
27033 /* Don't update cursor in windows whose frame is in the process
27034 of being deleted. */
27035 if (w
->current_matrix
)
27037 int hpos
= w
->phys_cursor
.hpos
;
27038 int vpos
= w
->phys_cursor
.vpos
;
27039 struct glyph_row
*row
;
27041 if (vpos
>= w
->current_matrix
->nrows
27042 || hpos
>= w
->current_matrix
->matrix_w
)
27045 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27047 /* When the window is hscrolled, cursor hpos can legitimately be
27048 out of bounds, but we draw the cursor at the corresponding
27049 window margin in that case. */
27050 if (!row
->reversed_p
&& hpos
< 0)
27052 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27053 hpos
= row
->used
[TEXT_AREA
] - 1;
27056 display_and_set_cursor (w
, on
, hpos
, vpos
,
27057 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27063 /* Call update_window_cursor with parameter ON_P on all leaf windows
27064 in the window tree rooted at W. */
27067 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
27071 if (WINDOWP (w
->contents
))
27072 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
27074 update_window_cursor (w
, on_p
);
27076 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
27082 Display the cursor on window W, or clear it, according to ON_P.
27083 Don't change the cursor's position. */
27086 x_update_cursor (struct frame
*f
, bool on_p
)
27088 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
27093 Clear the cursor of window W to background color, and mark the
27094 cursor as not shown. This is used when the text where the cursor
27095 is about to be rewritten. */
27098 x_clear_cursor (struct window
*w
)
27100 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
27101 update_window_cursor (w
, 0);
27104 #endif /* HAVE_WINDOW_SYSTEM */
27106 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
27109 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
27110 int start_hpos
, int end_hpos
,
27111 enum draw_glyphs_face draw
)
27113 #ifdef HAVE_WINDOW_SYSTEM
27114 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
27116 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
27120 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
27121 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
27125 /* Display the active region described by mouse_face_* according to DRAW. */
27128 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
27130 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
27131 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27133 if (/* If window is in the process of being destroyed, don't bother
27135 w
->current_matrix
!= NULL
27136 /* Don't update mouse highlight if hidden */
27137 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
27138 /* Recognize when we are called to operate on rows that don't exist
27139 anymore. This can happen when a window is split. */
27140 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
27142 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
27143 struct glyph_row
*row
, *first
, *last
;
27145 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
27146 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
27148 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
27150 int start_hpos
, end_hpos
, start_x
;
27152 /* For all but the first row, the highlight starts at column 0. */
27155 /* R2L rows have BEG and END in reversed order, but the
27156 screen drawing geometry is always left to right. So
27157 we need to mirror the beginning and end of the
27158 highlighted area in R2L rows. */
27159 if (!row
->reversed_p
)
27161 start_hpos
= hlinfo
->mouse_face_beg_col
;
27162 start_x
= hlinfo
->mouse_face_beg_x
;
27164 else if (row
== last
)
27166 start_hpos
= hlinfo
->mouse_face_end_col
;
27167 start_x
= hlinfo
->mouse_face_end_x
;
27175 else if (row
->reversed_p
&& row
== last
)
27177 start_hpos
= hlinfo
->mouse_face_end_col
;
27178 start_x
= hlinfo
->mouse_face_end_x
;
27188 if (!row
->reversed_p
)
27189 end_hpos
= hlinfo
->mouse_face_end_col
;
27190 else if (row
== first
)
27191 end_hpos
= hlinfo
->mouse_face_beg_col
;
27194 end_hpos
= row
->used
[TEXT_AREA
];
27195 if (draw
== DRAW_NORMAL_TEXT
)
27196 row
->fill_line_p
= 1; /* Clear to end of line */
27199 else if (row
->reversed_p
&& row
== first
)
27200 end_hpos
= hlinfo
->mouse_face_beg_col
;
27203 end_hpos
= row
->used
[TEXT_AREA
];
27204 if (draw
== DRAW_NORMAL_TEXT
)
27205 row
->fill_line_p
= 1; /* Clear to end of line */
27208 if (end_hpos
> start_hpos
)
27210 draw_row_with_mouse_face (w
, start_x
, row
,
27211 start_hpos
, end_hpos
, draw
);
27214 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
27218 #ifdef HAVE_WINDOW_SYSTEM
27219 /* When we've written over the cursor, arrange for it to
27220 be displayed again. */
27221 if (FRAME_WINDOW_P (f
)
27222 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
27224 int hpos
= w
->phys_cursor
.hpos
;
27226 /* When the window is hscrolled, cursor hpos can legitimately be
27227 out of bounds, but we draw the cursor at the corresponding
27228 window margin in that case. */
27229 if (!row
->reversed_p
&& hpos
< 0)
27231 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27232 hpos
= row
->used
[TEXT_AREA
] - 1;
27235 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
27236 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27239 #endif /* HAVE_WINDOW_SYSTEM */
27242 #ifdef HAVE_WINDOW_SYSTEM
27243 /* Change the mouse cursor. */
27244 if (FRAME_WINDOW_P (f
))
27246 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
27247 if (draw
== DRAW_NORMAL_TEXT
27248 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
27249 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
27252 if (draw
== DRAW_MOUSE_FACE
)
27253 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
27255 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
27257 #endif /* HAVE_WINDOW_SYSTEM */
27261 Clear out the mouse-highlighted active region.
27262 Redraw it un-highlighted first. Value is non-zero if mouse
27263 face was actually drawn unhighlighted. */
27266 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
27270 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
27272 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
27276 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27277 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27278 hlinfo
->mouse_face_window
= Qnil
;
27279 hlinfo
->mouse_face_overlay
= Qnil
;
27283 /* Return true if the coordinates HPOS and VPOS on windows W are
27284 within the mouse face on that window. */
27286 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
27288 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27290 /* Quickly resolve the easy cases. */
27291 if (!(WINDOWP (hlinfo
->mouse_face_window
)
27292 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
27294 if (vpos
< hlinfo
->mouse_face_beg_row
27295 || vpos
> hlinfo
->mouse_face_end_row
)
27297 if (vpos
> hlinfo
->mouse_face_beg_row
27298 && vpos
< hlinfo
->mouse_face_end_row
)
27301 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
27303 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27305 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
27308 else if ((vpos
== hlinfo
->mouse_face_beg_row
27309 && hpos
>= hlinfo
->mouse_face_beg_col
)
27310 || (vpos
== hlinfo
->mouse_face_end_row
27311 && hpos
< hlinfo
->mouse_face_end_col
))
27316 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27318 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
27321 else if ((vpos
== hlinfo
->mouse_face_beg_row
27322 && hpos
<= hlinfo
->mouse_face_beg_col
)
27323 || (vpos
== hlinfo
->mouse_face_end_row
27324 && hpos
> hlinfo
->mouse_face_end_col
))
27332 True if physical cursor of window W is within mouse face. */
27335 cursor_in_mouse_face_p (struct window
*w
)
27337 int hpos
= w
->phys_cursor
.hpos
;
27338 int vpos
= w
->phys_cursor
.vpos
;
27339 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27341 /* When the window is hscrolled, cursor hpos can legitimately be out
27342 of bounds, but we draw the cursor at the corresponding window
27343 margin in that case. */
27344 if (!row
->reversed_p
&& hpos
< 0)
27346 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27347 hpos
= row
->used
[TEXT_AREA
] - 1;
27349 return coords_in_mouse_face_p (w
, hpos
, vpos
);
27354 /* Find the glyph rows START_ROW and END_ROW of window W that display
27355 characters between buffer positions START_CHARPOS and END_CHARPOS
27356 (excluding END_CHARPOS). DISP_STRING is a display string that
27357 covers these buffer positions. This is similar to
27358 row_containing_pos, but is more accurate when bidi reordering makes
27359 buffer positions change non-linearly with glyph rows. */
27361 rows_from_pos_range (struct window
*w
,
27362 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
27363 Lisp_Object disp_string
,
27364 struct glyph_row
**start
, struct glyph_row
**end
)
27366 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27367 int last_y
= window_text_bottom_y (w
);
27368 struct glyph_row
*row
;
27373 while (!first
->enabled_p
27374 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
27377 /* Find the START row. */
27379 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
27382 /* A row can potentially be the START row if the range of the
27383 characters it displays intersects the range
27384 [START_CHARPOS..END_CHARPOS). */
27385 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
27386 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
27387 /* See the commentary in row_containing_pos, for the
27388 explanation of the complicated way to check whether
27389 some position is beyond the end of the characters
27390 displayed by a row. */
27391 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27392 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27393 && !row
->ends_at_zv_p
27394 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27395 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27396 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27397 && !row
->ends_at_zv_p
27398 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27400 /* Found a candidate row. Now make sure at least one of the
27401 glyphs it displays has a charpos from the range
27402 [START_CHARPOS..END_CHARPOS).
27404 This is not obvious because bidi reordering could make
27405 buffer positions of a row be 1,2,3,102,101,100, and if we
27406 want to highlight characters in [50..60), we don't want
27407 this row, even though [50..60) does intersect [1..103),
27408 the range of character positions given by the row's start
27409 and end positions. */
27410 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27411 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27415 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27416 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27417 /* A glyph that comes from DISP_STRING is by
27418 definition to be highlighted. */
27419 || EQ (g
->object
, disp_string
))
27428 /* Find the END row. */
27430 /* If the last row is partially visible, start looking for END
27431 from that row, instead of starting from FIRST. */
27432 && !(row
->enabled_p
27433 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27435 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27437 struct glyph_row
*next
= row
+ 1;
27438 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27440 if (!next
->enabled_p
27441 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27442 /* The first row >= START whose range of displayed characters
27443 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27444 is the row END + 1. */
27445 || (start_charpos
< next_start
27446 && end_charpos
< next_start
)
27447 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27448 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27449 && !next
->ends_at_zv_p
27450 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27451 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27452 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27453 && !next
->ends_at_zv_p
27454 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27461 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27462 but none of the characters it displays are in the range, it is
27464 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27465 struct glyph
*s
= g
;
27466 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27470 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27471 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27472 /* If the buffer position of the first glyph in
27473 the row is equal to END_CHARPOS, it means
27474 the last character to be highlighted is the
27475 newline of ROW, and we must consider NEXT as
27477 || (((!next
->reversed_p
&& g
== s
)
27478 || (next
->reversed_p
&& g
== e
- 1))
27479 && (g
->charpos
== end_charpos
27480 /* Special case for when NEXT is an
27481 empty line at ZV. */
27482 || (g
->charpos
== -1
27483 && !row
->ends_at_zv_p
27484 && next_start
== end_charpos
)))))
27485 /* A glyph that comes from DISP_STRING is by
27486 definition to be highlighted. */
27487 || EQ (g
->object
, disp_string
))
27496 /* The first row that ends at ZV must be the last to be
27498 else if (next
->ends_at_zv_p
)
27507 /* This function sets the mouse_face_* elements of HLINFO, assuming
27508 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27509 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27510 for the overlay or run of text properties specifying the mouse
27511 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27512 before-string and after-string that must also be highlighted.
27513 DISP_STRING, if non-nil, is a display string that may cover some
27514 or all of the highlighted text. */
27517 mouse_face_from_buffer_pos (Lisp_Object window
,
27518 Mouse_HLInfo
*hlinfo
,
27519 ptrdiff_t mouse_charpos
,
27520 ptrdiff_t start_charpos
,
27521 ptrdiff_t end_charpos
,
27522 Lisp_Object before_string
,
27523 Lisp_Object after_string
,
27524 Lisp_Object disp_string
)
27526 struct window
*w
= XWINDOW (window
);
27527 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27528 struct glyph_row
*r1
, *r2
;
27529 struct glyph
*glyph
, *end
;
27530 ptrdiff_t ignore
, pos
;
27533 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27534 eassert (NILP (before_string
) || STRINGP (before_string
));
27535 eassert (NILP (after_string
) || STRINGP (after_string
));
27537 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27538 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27540 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27541 /* If the before-string or display-string contains newlines,
27542 rows_from_pos_range skips to its last row. Move back. */
27543 if (!NILP (before_string
) || !NILP (disp_string
))
27545 struct glyph_row
*prev
;
27546 while ((prev
= r1
- 1, prev
>= first
)
27547 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27548 && prev
->used
[TEXT_AREA
] > 0)
27550 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27551 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27552 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27554 || !(EQ (glyph
->object
, before_string
)
27555 || EQ (glyph
->object
, disp_string
)))
27562 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27563 hlinfo
->mouse_face_past_end
= 1;
27565 else if (!NILP (after_string
))
27567 /* If the after-string has newlines, advance to its last row. */
27568 struct glyph_row
*next
;
27569 struct glyph_row
*last
27570 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27572 for (next
= r2
+ 1;
27574 && next
->used
[TEXT_AREA
] > 0
27575 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27579 /* The rest of the display engine assumes that mouse_face_beg_row is
27580 either above mouse_face_end_row or identical to it. But with
27581 bidi-reordered continued lines, the row for START_CHARPOS could
27582 be below the row for END_CHARPOS. If so, swap the rows and store
27583 them in correct order. */
27586 struct glyph_row
*tem
= r2
;
27592 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27593 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27595 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27596 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27597 could be anywhere in the row and in any order. The strategy
27598 below is to find the leftmost and the rightmost glyph that
27599 belongs to either of these 3 strings, or whose position is
27600 between START_CHARPOS and END_CHARPOS, and highlight all the
27601 glyphs between those two. This may cover more than just the text
27602 between START_CHARPOS and END_CHARPOS if the range of characters
27603 strides the bidi level boundary, e.g. if the beginning is in R2L
27604 text while the end is in L2R text or vice versa. */
27605 if (!r1
->reversed_p
)
27607 /* This row is in a left to right paragraph. Scan it left to
27609 glyph
= r1
->glyphs
[TEXT_AREA
];
27610 end
= glyph
+ r1
->used
[TEXT_AREA
];
27613 /* Skip truncation glyphs at the start of the glyph row. */
27614 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27616 && INTEGERP (glyph
->object
)
27617 && glyph
->charpos
< 0;
27619 x
+= glyph
->pixel_width
;
27621 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27622 or DISP_STRING, and the first glyph from buffer whose
27623 position is between START_CHARPOS and END_CHARPOS. */
27625 && !INTEGERP (glyph
->object
)
27626 && !EQ (glyph
->object
, disp_string
)
27627 && !(BUFFERP (glyph
->object
)
27628 && (glyph
->charpos
>= start_charpos
27629 && glyph
->charpos
< end_charpos
));
27632 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27633 are present at buffer positions between START_CHARPOS and
27634 END_CHARPOS, or if they come from an overlay. */
27635 if (EQ (glyph
->object
, before_string
))
27637 pos
= string_buffer_position (before_string
,
27639 /* If pos == 0, it means before_string came from an
27640 overlay, not from a buffer position. */
27641 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27644 else if (EQ (glyph
->object
, after_string
))
27646 pos
= string_buffer_position (after_string
, end_charpos
);
27647 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27650 x
+= glyph
->pixel_width
;
27652 hlinfo
->mouse_face_beg_x
= x
;
27653 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27657 /* This row is in a right to left paragraph. Scan it right to
27661 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27662 glyph
= end
+ r1
->used
[TEXT_AREA
];
27664 /* Skip truncation glyphs at the start of the glyph row. */
27665 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27667 && INTEGERP (glyph
->object
)
27668 && glyph
->charpos
< 0;
27672 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27673 or DISP_STRING, and the first glyph from buffer whose
27674 position is between START_CHARPOS and END_CHARPOS. */
27676 && !INTEGERP (glyph
->object
)
27677 && !EQ (glyph
->object
, disp_string
)
27678 && !(BUFFERP (glyph
->object
)
27679 && (glyph
->charpos
>= start_charpos
27680 && glyph
->charpos
< end_charpos
));
27683 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27684 are present at buffer positions between START_CHARPOS and
27685 END_CHARPOS, or if they come from an overlay. */
27686 if (EQ (glyph
->object
, before_string
))
27688 pos
= string_buffer_position (before_string
, start_charpos
);
27689 /* If pos == 0, it means before_string came from an
27690 overlay, not from a buffer position. */
27691 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27694 else if (EQ (glyph
->object
, after_string
))
27696 pos
= string_buffer_position (after_string
, end_charpos
);
27697 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27702 glyph
++; /* first glyph to the right of the highlighted area */
27703 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27704 x
+= g
->pixel_width
;
27705 hlinfo
->mouse_face_beg_x
= x
;
27706 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27709 /* If the highlight ends in a different row, compute GLYPH and END
27710 for the end row. Otherwise, reuse the values computed above for
27711 the row where the highlight begins. */
27714 if (!r2
->reversed_p
)
27716 glyph
= r2
->glyphs
[TEXT_AREA
];
27717 end
= glyph
+ r2
->used
[TEXT_AREA
];
27722 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27723 glyph
= end
+ r2
->used
[TEXT_AREA
];
27727 if (!r2
->reversed_p
)
27729 /* Skip truncation and continuation glyphs near the end of the
27730 row, and also blanks and stretch glyphs inserted by
27731 extend_face_to_end_of_line. */
27733 && INTEGERP ((end
- 1)->object
))
27735 /* Scan the rest of the glyph row from the end, looking for the
27736 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27737 DISP_STRING, or whose position is between START_CHARPOS
27741 && !INTEGERP (end
->object
)
27742 && !EQ (end
->object
, disp_string
)
27743 && !(BUFFERP (end
->object
)
27744 && (end
->charpos
>= start_charpos
27745 && end
->charpos
< end_charpos
));
27748 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27749 are present at buffer positions between START_CHARPOS and
27750 END_CHARPOS, or if they come from an overlay. */
27751 if (EQ (end
->object
, before_string
))
27753 pos
= string_buffer_position (before_string
, start_charpos
);
27754 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27757 else if (EQ (end
->object
, after_string
))
27759 pos
= string_buffer_position (after_string
, end_charpos
);
27760 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27764 /* Find the X coordinate of the last glyph to be highlighted. */
27765 for (; glyph
<= end
; ++glyph
)
27766 x
+= glyph
->pixel_width
;
27768 hlinfo
->mouse_face_end_x
= x
;
27769 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27773 /* Skip truncation and continuation glyphs near the end of the
27774 row, and also blanks and stretch glyphs inserted by
27775 extend_face_to_end_of_line. */
27779 && INTEGERP (end
->object
))
27781 x
+= end
->pixel_width
;
27784 /* Scan the rest of the glyph row from the end, looking for the
27785 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27786 DISP_STRING, or whose position is between START_CHARPOS
27790 && !INTEGERP (end
->object
)
27791 && !EQ (end
->object
, disp_string
)
27792 && !(BUFFERP (end
->object
)
27793 && (end
->charpos
>= start_charpos
27794 && end
->charpos
< end_charpos
));
27797 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27798 are present at buffer positions between START_CHARPOS and
27799 END_CHARPOS, or if they come from an overlay. */
27800 if (EQ (end
->object
, before_string
))
27802 pos
= string_buffer_position (before_string
, start_charpos
);
27803 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27806 else if (EQ (end
->object
, after_string
))
27808 pos
= string_buffer_position (after_string
, end_charpos
);
27809 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27812 x
+= end
->pixel_width
;
27814 /* If we exited the above loop because we arrived at the last
27815 glyph of the row, and its buffer position is still not in
27816 range, it means the last character in range is the preceding
27817 newline. Bump the end column and x values to get past the
27820 && BUFFERP (end
->object
)
27821 && (end
->charpos
< start_charpos
27822 || end
->charpos
>= end_charpos
))
27824 x
+= end
->pixel_width
;
27827 hlinfo
->mouse_face_end_x
= x
;
27828 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27831 hlinfo
->mouse_face_window
= window
;
27832 hlinfo
->mouse_face_face_id
27833 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
27835 !hlinfo
->mouse_face_hidden
, -1);
27836 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27839 /* The following function is not used anymore (replaced with
27840 mouse_face_from_string_pos), but I leave it here for the time
27841 being, in case someone would. */
27843 #if 0 /* not used */
27845 /* Find the position of the glyph for position POS in OBJECT in
27846 window W's current matrix, and return in *X, *Y the pixel
27847 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27849 RIGHT_P non-zero means return the position of the right edge of the
27850 glyph, RIGHT_P zero means return the left edge position.
27852 If no glyph for POS exists in the matrix, return the position of
27853 the glyph with the next smaller position that is in the matrix, if
27854 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27855 exists in the matrix, return the position of the glyph with the
27856 next larger position in OBJECT.
27858 Value is non-zero if a glyph was found. */
27861 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27862 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27864 int yb
= window_text_bottom_y (w
);
27865 struct glyph_row
*r
;
27866 struct glyph
*best_glyph
= NULL
;
27867 struct glyph_row
*best_row
= NULL
;
27870 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27871 r
->enabled_p
&& r
->y
< yb
;
27874 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27875 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27878 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27879 if (EQ (g
->object
, object
))
27881 if (g
->charpos
== pos
)
27888 else if (best_glyph
== NULL
27889 || ((eabs (g
->charpos
- pos
)
27890 < eabs (best_glyph
->charpos
- pos
))
27893 : g
->charpos
> pos
)))
27907 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27911 *x
+= best_glyph
->pixel_width
;
27916 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27919 return best_glyph
!= NULL
;
27921 #endif /* not used */
27923 /* Find the positions of the first and the last glyphs in window W's
27924 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27925 (assumed to be a string), and return in HLINFO's mouse_face_*
27926 members the pixel and column/row coordinates of those glyphs. */
27929 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27930 Lisp_Object object
,
27931 ptrdiff_t startpos
, ptrdiff_t endpos
)
27933 int yb
= window_text_bottom_y (w
);
27934 struct glyph_row
*r
;
27935 struct glyph
*g
, *e
;
27939 /* Find the glyph row with at least one position in the range
27940 [STARTPOS..ENDPOS), and the first glyph in that row whose
27941 position belongs to that range. */
27942 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27943 r
->enabled_p
&& r
->y
< yb
;
27946 if (!r
->reversed_p
)
27948 g
= r
->glyphs
[TEXT_AREA
];
27949 e
= g
+ r
->used
[TEXT_AREA
];
27950 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27951 if (EQ (g
->object
, object
)
27952 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27954 hlinfo
->mouse_face_beg_row
27955 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27956 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27957 hlinfo
->mouse_face_beg_x
= gx
;
27966 e
= r
->glyphs
[TEXT_AREA
];
27967 g
= e
+ r
->used
[TEXT_AREA
];
27968 for ( ; g
> e
; --g
)
27969 if (EQ ((g
-1)->object
, object
)
27970 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
< endpos
)
27972 hlinfo
->mouse_face_beg_row
27973 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27974 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27975 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27976 gx
+= g1
->pixel_width
;
27977 hlinfo
->mouse_face_beg_x
= gx
;
27989 /* Starting with the next row, look for the first row which does NOT
27990 include any glyphs whose positions are in the range. */
27991 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27993 g
= r
->glyphs
[TEXT_AREA
];
27994 e
= g
+ r
->used
[TEXT_AREA
];
27996 for ( ; g
< e
; ++g
)
27997 if (EQ (g
->object
, object
)
27998 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
28007 /* The highlighted region ends on the previous row. */
28010 /* Set the end row. */
28011 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
28013 /* Compute and set the end column and the end column's horizontal
28014 pixel coordinate. */
28015 if (!r
->reversed_p
)
28017 g
= r
->glyphs
[TEXT_AREA
];
28018 e
= g
+ r
->used
[TEXT_AREA
];
28019 for ( ; e
> g
; --e
)
28020 if (EQ ((e
-1)->object
, object
)
28021 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
28023 hlinfo
->mouse_face_end_col
= e
- g
;
28025 for (gx
= r
->x
; g
< e
; ++g
)
28026 gx
+= g
->pixel_width
;
28027 hlinfo
->mouse_face_end_x
= gx
;
28031 e
= r
->glyphs
[TEXT_AREA
];
28032 g
= e
+ r
->used
[TEXT_AREA
];
28033 for (gx
= r
->x
; e
< g
; ++e
)
28035 if (EQ (e
->object
, object
)
28036 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
28038 gx
+= e
->pixel_width
;
28040 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
28041 hlinfo
->mouse_face_end_x
= gx
;
28045 #ifdef HAVE_WINDOW_SYSTEM
28047 /* See if position X, Y is within a hot-spot of an image. */
28050 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
28052 if (!CONSP (hot_spot
))
28055 if (EQ (XCAR (hot_spot
), Qrect
))
28057 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
28058 Lisp_Object rect
= XCDR (hot_spot
);
28062 if (!CONSP (XCAR (rect
)))
28064 if (!CONSP (XCDR (rect
)))
28066 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
28068 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
28070 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
28072 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
28076 else if (EQ (XCAR (hot_spot
), Qcircle
))
28078 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
28079 Lisp_Object circ
= XCDR (hot_spot
);
28080 Lisp_Object lr
, lx0
, ly0
;
28082 && CONSP (XCAR (circ
))
28083 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
28084 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
28085 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
28087 double r
= XFLOATINT (lr
);
28088 double dx
= XINT (lx0
) - x
;
28089 double dy
= XINT (ly0
) - y
;
28090 return (dx
* dx
+ dy
* dy
<= r
* r
);
28093 else if (EQ (XCAR (hot_spot
), Qpoly
))
28095 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
28096 if (VECTORP (XCDR (hot_spot
)))
28098 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
28099 Lisp_Object
*poly
= v
->contents
;
28100 ptrdiff_t n
= v
->header
.size
;
28103 Lisp_Object lx
, ly
;
28106 /* Need an even number of coordinates, and at least 3 edges. */
28107 if (n
< 6 || n
& 1)
28110 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
28111 If count is odd, we are inside polygon. Pixels on edges
28112 may or may not be included depending on actual geometry of the
28114 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
28115 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
28117 x0
= XINT (lx
), y0
= XINT (ly
);
28118 for (i
= 0; i
< n
; i
+= 2)
28120 int x1
= x0
, y1
= y0
;
28121 if ((lx
= poly
[i
], !INTEGERP (lx
))
28122 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
28124 x0
= XINT (lx
), y0
= XINT (ly
);
28126 /* Does this segment cross the X line? */
28134 if (y
> y0
&& y
> y1
)
28136 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
28146 find_hot_spot (Lisp_Object map
, int x
, int y
)
28148 while (CONSP (map
))
28150 if (CONSP (XCAR (map
))
28151 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
28159 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
28161 doc
: /* Lookup in image map MAP coordinates X and Y.
28162 An image map is an alist where each element has the format (AREA ID PLIST).
28163 An AREA is specified as either a rectangle, a circle, or a polygon:
28164 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
28165 pixel coordinates of the upper left and bottom right corners.
28166 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
28167 and the radius of the circle; r may be a float or integer.
28168 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
28169 vector describes one corner in the polygon.
28170 Returns the alist element for the first matching AREA in MAP. */)
28171 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
28179 return find_hot_spot (map
,
28180 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
28181 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
28185 /* Display frame CURSOR, optionally using shape defined by POINTER. */
28187 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
28189 /* Do not change cursor shape while dragging mouse. */
28190 if (!NILP (do_mouse_tracking
))
28193 if (!NILP (pointer
))
28195 if (EQ (pointer
, Qarrow
))
28196 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28197 else if (EQ (pointer
, Qhand
))
28198 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
28199 else if (EQ (pointer
, Qtext
))
28200 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28201 else if (EQ (pointer
, intern ("hdrag")))
28202 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28203 else if (EQ (pointer
, intern ("nhdrag")))
28204 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28205 #ifdef HAVE_X_WINDOWS
28206 else if (EQ (pointer
, intern ("vdrag")))
28207 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28209 else if (EQ (pointer
, intern ("hourglass")))
28210 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
28211 else if (EQ (pointer
, Qmodeline
))
28212 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
28214 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28217 if (cursor
!= No_Cursor
)
28218 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
28221 #endif /* HAVE_WINDOW_SYSTEM */
28223 /* Take proper action when mouse has moved to the mode or header line
28224 or marginal area AREA of window W, x-position X and y-position Y.
28225 X is relative to the start of the text display area of W, so the
28226 width of bitmap areas and scroll bars must be subtracted to get a
28227 position relative to the start of the mode line. */
28230 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
28231 enum window_part area
)
28233 struct window
*w
= XWINDOW (window
);
28234 struct frame
*f
= XFRAME (w
->frame
);
28235 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28236 #ifdef HAVE_WINDOW_SYSTEM
28237 Display_Info
*dpyinfo
;
28239 Cursor cursor
= No_Cursor
;
28240 Lisp_Object pointer
= Qnil
;
28241 int dx
, dy
, width
, height
;
28243 Lisp_Object string
, object
= Qnil
;
28244 Lisp_Object pos
IF_LINT (= Qnil
), help
;
28246 Lisp_Object mouse_face
;
28247 int original_x_pixel
= x
;
28248 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
28249 struct glyph_row
*row
IF_LINT (= 0);
28251 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
28256 /* Kludge alert: mode_line_string takes X/Y in pixels, but
28257 returns them in row/column units! */
28258 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
28259 &object
, &dx
, &dy
, &width
, &height
);
28261 row
= (area
== ON_MODE_LINE
28262 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
28263 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
28265 /* Find the glyph under the mouse pointer. */
28266 if (row
->mode_line_p
&& row
->enabled_p
)
28268 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
28269 end
= glyph
+ row
->used
[TEXT_AREA
];
28271 for (x0
= original_x_pixel
;
28272 glyph
< end
&& x0
>= glyph
->pixel_width
;
28274 x0
-= glyph
->pixel_width
;
28282 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
28283 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
28284 returns them in row/column units! */
28285 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
28286 &object
, &dx
, &dy
, &width
, &height
);
28291 #ifdef HAVE_WINDOW_SYSTEM
28292 if (IMAGEP (object
))
28294 Lisp_Object image_map
, hotspot
;
28295 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
28297 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
28299 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28303 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
28304 If so, we could look for mouse-enter, mouse-leave
28305 properties in PLIST (and do something...). */
28306 hotspot
= XCDR (hotspot
);
28307 if (CONSP (hotspot
)
28308 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28310 pointer
= Fplist_get (plist
, Qpointer
);
28311 if (NILP (pointer
))
28313 help
= Fplist_get (plist
, Qhelp_echo
);
28316 help_echo_string
= help
;
28317 XSETWINDOW (help_echo_window
, w
);
28318 help_echo_object
= w
->contents
;
28319 help_echo_pos
= charpos
;
28323 if (NILP (pointer
))
28324 pointer
= Fplist_get (XCDR (object
), QCpointer
);
28326 #endif /* HAVE_WINDOW_SYSTEM */
28328 if (STRINGP (string
))
28329 pos
= make_number (charpos
);
28331 /* Set the help text and mouse pointer. If the mouse is on a part
28332 of the mode line without any text (e.g. past the right edge of
28333 the mode line text), use the default help text and pointer. */
28334 if (STRINGP (string
) || area
== ON_MODE_LINE
)
28336 /* Arrange to display the help by setting the global variables
28337 help_echo_string, help_echo_object, and help_echo_pos. */
28340 if (STRINGP (string
))
28341 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
28345 help_echo_string
= help
;
28346 XSETWINDOW (help_echo_window
, w
);
28347 help_echo_object
= string
;
28348 help_echo_pos
= charpos
;
28350 else if (area
== ON_MODE_LINE
)
28352 Lisp_Object default_help
28353 = buffer_local_value_1 (Qmode_line_default_help_echo
,
28356 if (STRINGP (default_help
))
28358 help_echo_string
= default_help
;
28359 XSETWINDOW (help_echo_window
, w
);
28360 help_echo_object
= Qnil
;
28361 help_echo_pos
= -1;
28366 #ifdef HAVE_WINDOW_SYSTEM
28367 /* Change the mouse pointer according to what is under it. */
28368 if (FRAME_WINDOW_P (f
))
28370 dpyinfo
= FRAME_DISPLAY_INFO (f
);
28371 if (STRINGP (string
))
28373 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28375 if (NILP (pointer
))
28376 pointer
= Fget_text_property (pos
, Qpointer
, string
);
28378 /* Change the mouse pointer according to what is under X/Y. */
28380 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
28383 map
= Fget_text_property (pos
, Qlocal_map
, string
);
28384 if (!KEYMAPP (map
))
28385 map
= Fget_text_property (pos
, Qkeymap
, string
);
28386 if (!KEYMAPP (map
))
28387 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28391 /* Default mode-line pointer. */
28392 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28397 /* Change the mouse face according to what is under X/Y. */
28398 if (STRINGP (string
))
28400 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28401 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28402 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28407 struct glyph
* tmp_glyph
;
28411 int total_pixel_width
;
28412 ptrdiff_t begpos
, endpos
, ignore
;
28416 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28417 Qmouse_face
, string
, Qnil
);
28423 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28425 endpos
= SCHARS (string
);
28429 /* Calculate the glyph position GPOS of GLYPH in the
28430 displayed string, relative to the beginning of the
28431 highlighted part of the string.
28433 Note: GPOS is different from CHARPOS. CHARPOS is the
28434 position of GLYPH in the internal string object. A mode
28435 line string format has structures which are converted to
28436 a flattened string by the Emacs Lisp interpreter. The
28437 internal string is an element of those structures. The
28438 displayed string is the flattened string. */
28439 tmp_glyph
= row_start_glyph
;
28440 while (tmp_glyph
< glyph
28441 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28442 && begpos
<= tmp_glyph
->charpos
28443 && tmp_glyph
->charpos
< endpos
)))
28445 gpos
= glyph
- tmp_glyph
;
28447 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28448 the highlighted part of the displayed string to which
28449 GLYPH belongs. Note: GSEQ_LENGTH is different from
28450 SCHARS (STRING), because the latter returns the length of
28451 the internal string. */
28452 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28454 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28455 && begpos
<= tmp_glyph
->charpos
28456 && tmp_glyph
->charpos
< endpos
));
28459 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28461 /* Calculate the total pixel width of all the glyphs between
28462 the beginning of the highlighted area and GLYPH. */
28463 total_pixel_width
= 0;
28464 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28465 total_pixel_width
+= tmp_glyph
->pixel_width
;
28467 /* Pre calculation of re-rendering position. Note: X is in
28468 column units here, after the call to mode_line_string or
28469 marginal_area_string. */
28471 vpos
= (area
== ON_MODE_LINE
28472 ? (w
->current_matrix
)->nrows
- 1
28475 /* If GLYPH's position is included in the region that is
28476 already drawn in mouse face, we have nothing to do. */
28477 if ( EQ (window
, hlinfo
->mouse_face_window
)
28478 && (!row
->reversed_p
28479 ? (hlinfo
->mouse_face_beg_col
<= hpos
28480 && hpos
< hlinfo
->mouse_face_end_col
)
28481 /* In R2L rows we swap BEG and END, see below. */
28482 : (hlinfo
->mouse_face_end_col
<= hpos
28483 && hpos
< hlinfo
->mouse_face_beg_col
))
28484 && hlinfo
->mouse_face_beg_row
== vpos
)
28487 if (clear_mouse_face (hlinfo
))
28488 cursor
= No_Cursor
;
28490 if (!row
->reversed_p
)
28492 hlinfo
->mouse_face_beg_col
= hpos
;
28493 hlinfo
->mouse_face_beg_x
= original_x_pixel
28494 - (total_pixel_width
+ dx
);
28495 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28496 hlinfo
->mouse_face_end_x
= 0;
28500 /* In R2L rows, show_mouse_face expects BEG and END
28501 coordinates to be swapped. */
28502 hlinfo
->mouse_face_end_col
= hpos
;
28503 hlinfo
->mouse_face_end_x
= original_x_pixel
28504 - (total_pixel_width
+ dx
);
28505 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28506 hlinfo
->mouse_face_beg_x
= 0;
28509 hlinfo
->mouse_face_beg_row
= vpos
;
28510 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28511 hlinfo
->mouse_face_past_end
= 0;
28512 hlinfo
->mouse_face_window
= window
;
28514 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28519 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28521 if (NILP (pointer
))
28524 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28525 clear_mouse_face (hlinfo
);
28527 #ifdef HAVE_WINDOW_SYSTEM
28528 if (FRAME_WINDOW_P (f
))
28529 define_frame_cursor1 (f
, cursor
, pointer
);
28535 Take proper action when the mouse has moved to position X, Y on
28536 frame F with regards to highlighting portions of display that have
28537 mouse-face properties. Also de-highlight portions of display where
28538 the mouse was before, set the mouse pointer shape as appropriate
28539 for the mouse coordinates, and activate help echo (tooltips).
28540 X and Y can be negative or out of range. */
28543 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28545 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28546 enum window_part part
= ON_NOTHING
;
28547 Lisp_Object window
;
28549 Cursor cursor
= No_Cursor
;
28550 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28553 /* When a menu is active, don't highlight because this looks odd. */
28554 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28555 if (popup_activated ())
28559 if (!f
->glyphs_initialized_p
28560 || f
->pointer_invisible
)
28563 hlinfo
->mouse_face_mouse_x
= x
;
28564 hlinfo
->mouse_face_mouse_y
= y
;
28565 hlinfo
->mouse_face_mouse_frame
= f
;
28567 if (hlinfo
->mouse_face_defer
)
28570 /* Which window is that in? */
28571 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28573 /* If displaying active text in another window, clear that. */
28574 if (! EQ (window
, hlinfo
->mouse_face_window
)
28575 /* Also clear if we move out of text area in same window. */
28576 || (!NILP (hlinfo
->mouse_face_window
)
28579 && part
!= ON_MODE_LINE
28580 && part
!= ON_HEADER_LINE
))
28581 clear_mouse_face (hlinfo
);
28583 /* Not on a window -> return. */
28584 if (!WINDOWP (window
))
28587 /* Reset help_echo_string. It will get recomputed below. */
28588 help_echo_string
= Qnil
;
28590 /* Convert to window-relative pixel coordinates. */
28591 w
= XWINDOW (window
);
28592 frame_to_window_pixel_xy (w
, &x
, &y
);
28594 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28595 /* Handle tool-bar window differently since it doesn't display a
28597 if (EQ (window
, f
->tool_bar_window
))
28599 note_tool_bar_highlight (f
, x
, y
);
28604 /* Mouse is on the mode, header line or margin? */
28605 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28606 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28608 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28610 #ifdef HAVE_WINDOW_SYSTEM
28611 if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28613 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28614 /* Show non-text cursor (Bug#16647). */
28622 #ifdef HAVE_WINDOW_SYSTEM
28623 if (part
== ON_VERTICAL_BORDER
)
28625 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28626 help_echo_string
= build_string ("drag-mouse-1: resize");
28628 else if (part
== ON_RIGHT_DIVIDER
)
28630 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28631 help_echo_string
= build_string ("drag-mouse-1: resize");
28633 else if (part
== ON_BOTTOM_DIVIDER
)
28635 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28636 help_echo_string
= build_string ("drag-mouse-1: resize");
28638 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28639 || part
== ON_SCROLL_BAR
)
28640 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28642 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28645 /* Are we in a window whose display is up to date?
28646 And verify the buffer's text has not changed. */
28647 b
= XBUFFER (w
->contents
);
28648 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28650 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28652 struct glyph
*glyph
;
28653 Lisp_Object object
;
28654 Lisp_Object mouse_face
= Qnil
, position
;
28655 Lisp_Object
*overlay_vec
= NULL
;
28656 ptrdiff_t i
, noverlays
;
28657 struct buffer
*obuf
;
28658 ptrdiff_t obegv
, ozv
;
28661 /* Find the glyph under X/Y. */
28662 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28664 #ifdef HAVE_WINDOW_SYSTEM
28665 /* Look for :pointer property on image. */
28666 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28668 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28669 if (img
!= NULL
&& IMAGEP (img
->spec
))
28671 Lisp_Object image_map
, hotspot
;
28672 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28674 && (hotspot
= find_hot_spot (image_map
,
28675 glyph
->slice
.img
.x
+ dx
,
28676 glyph
->slice
.img
.y
+ dy
),
28678 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28682 /* Could check XCAR (hotspot) to see if we enter/leave
28684 If so, we could look for mouse-enter, mouse-leave
28685 properties in PLIST (and do something...). */
28686 hotspot
= XCDR (hotspot
);
28687 if (CONSP (hotspot
)
28688 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28690 pointer
= Fplist_get (plist
, Qpointer
);
28691 if (NILP (pointer
))
28693 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28694 if (!NILP (help_echo_string
))
28696 help_echo_window
= window
;
28697 help_echo_object
= glyph
->object
;
28698 help_echo_pos
= glyph
->charpos
;
28702 if (NILP (pointer
))
28703 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28706 #endif /* HAVE_WINDOW_SYSTEM */
28708 /* Clear mouse face if X/Y not over text. */
28710 || area
!= TEXT_AREA
28711 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28712 /* Glyph's OBJECT is an integer for glyphs inserted by the
28713 display engine for its internal purposes, like truncation
28714 and continuation glyphs and blanks beyond the end of
28715 line's text on text terminals. If we are over such a
28716 glyph, we are not over any text. */
28717 || INTEGERP (glyph
->object
)
28718 /* R2L rows have a stretch glyph at their front, which
28719 stands for no text, whereas L2R rows have no glyphs at
28720 all beyond the end of text. Treat such stretch glyphs
28721 like we do with NULL glyphs in L2R rows. */
28722 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28723 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28724 && glyph
->type
== STRETCH_GLYPH
28725 && glyph
->avoid_cursor_p
))
28727 if (clear_mouse_face (hlinfo
))
28728 cursor
= No_Cursor
;
28729 #ifdef HAVE_WINDOW_SYSTEM
28730 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28732 if (area
!= TEXT_AREA
)
28733 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28735 pointer
= Vvoid_text_area_pointer
;
28741 pos
= glyph
->charpos
;
28742 object
= glyph
->object
;
28743 if (!STRINGP (object
) && !BUFFERP (object
))
28746 /* If we get an out-of-range value, return now; avoid an error. */
28747 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28750 /* Make the window's buffer temporarily current for
28751 overlays_at and compute_char_face. */
28752 obuf
= current_buffer
;
28753 current_buffer
= b
;
28759 /* Is this char mouse-active or does it have help-echo? */
28760 position
= make_number (pos
);
28762 if (BUFFERP (object
))
28764 /* Put all the overlays we want in a vector in overlay_vec. */
28765 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28766 /* Sort overlays into increasing priority order. */
28767 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28772 if (NILP (Vmouse_highlight
))
28774 clear_mouse_face (hlinfo
);
28775 goto check_help_echo
;
28778 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28781 cursor
= No_Cursor
;
28783 /* Check mouse-face highlighting. */
28785 /* If there exists an overlay with mouse-face overlapping
28786 the one we are currently highlighting, we have to
28787 check if we enter the overlapping overlay, and then
28788 highlight only that. */
28789 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28790 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28792 /* Find the highest priority overlay with a mouse-face. */
28793 Lisp_Object overlay
= Qnil
;
28794 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28796 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28797 if (!NILP (mouse_face
))
28798 overlay
= overlay_vec
[i
];
28801 /* If we're highlighting the same overlay as before, there's
28802 no need to do that again. */
28803 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28804 goto check_help_echo
;
28805 hlinfo
->mouse_face_overlay
= overlay
;
28807 /* Clear the display of the old active region, if any. */
28808 if (clear_mouse_face (hlinfo
))
28809 cursor
= No_Cursor
;
28811 /* If no overlay applies, get a text property. */
28812 if (NILP (overlay
))
28813 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28815 /* Next, compute the bounds of the mouse highlighting and
28817 if (!NILP (mouse_face
) && STRINGP (object
))
28819 /* The mouse-highlighting comes from a display string
28820 with a mouse-face. */
28824 s
= Fprevious_single_property_change
28825 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28826 e
= Fnext_single_property_change
28827 (position
, Qmouse_face
, object
, Qnil
);
28829 s
= make_number (0);
28831 e
= make_number (SCHARS (object
));
28832 mouse_face_from_string_pos (w
, hlinfo
, object
,
28833 XINT (s
), XINT (e
));
28834 hlinfo
->mouse_face_past_end
= 0;
28835 hlinfo
->mouse_face_window
= window
;
28836 hlinfo
->mouse_face_face_id
28837 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
28838 glyph
->face_id
, 1);
28839 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28840 cursor
= No_Cursor
;
28844 /* The mouse-highlighting, if any, comes from an overlay
28845 or text property in the buffer. */
28846 Lisp_Object buffer
IF_LINT (= Qnil
);
28847 Lisp_Object disp_string
IF_LINT (= Qnil
);
28849 if (STRINGP (object
))
28851 /* If we are on a display string with no mouse-face,
28852 check if the text under it has one. */
28853 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28854 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28855 pos
= string_buffer_position (object
, start
);
28858 mouse_face
= get_char_property_and_overlay
28859 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28860 buffer
= w
->contents
;
28861 disp_string
= object
;
28867 disp_string
= Qnil
;
28870 if (!NILP (mouse_face
))
28872 Lisp_Object before
, after
;
28873 Lisp_Object before_string
, after_string
;
28874 /* To correctly find the limits of mouse highlight
28875 in a bidi-reordered buffer, we must not use the
28876 optimization of limiting the search in
28877 previous-single-property-change and
28878 next-single-property-change, because
28879 rows_from_pos_range needs the real start and end
28880 positions to DTRT in this case. That's because
28881 the first row visible in a window does not
28882 necessarily display the character whose position
28883 is the smallest. */
28885 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28886 ? Fmarker_position (w
->start
)
28889 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28890 ? make_number (BUF_Z (XBUFFER (buffer
))
28891 - w
->window_end_pos
)
28894 if (NILP (overlay
))
28896 /* Handle the text property case. */
28897 before
= Fprevious_single_property_change
28898 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28899 after
= Fnext_single_property_change
28900 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28901 before_string
= after_string
= Qnil
;
28905 /* Handle the overlay case. */
28906 before
= Foverlay_start (overlay
);
28907 after
= Foverlay_end (overlay
);
28908 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28909 after_string
= Foverlay_get (overlay
, Qafter_string
);
28911 if (!STRINGP (before_string
)) before_string
= Qnil
;
28912 if (!STRINGP (after_string
)) after_string
= Qnil
;
28915 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28918 : XFASTINT (before
),
28920 ? BUF_Z (XBUFFER (buffer
))
28921 : XFASTINT (after
),
28922 before_string
, after_string
,
28924 cursor
= No_Cursor
;
28931 /* Look for a `help-echo' property. */
28932 if (NILP (help_echo_string
)) {
28933 Lisp_Object help
, overlay
;
28935 /* Check overlays first. */
28936 help
= overlay
= Qnil
;
28937 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28939 overlay
= overlay_vec
[i
];
28940 help
= Foverlay_get (overlay
, Qhelp_echo
);
28945 help_echo_string
= help
;
28946 help_echo_window
= window
;
28947 help_echo_object
= overlay
;
28948 help_echo_pos
= pos
;
28952 Lisp_Object obj
= glyph
->object
;
28953 ptrdiff_t charpos
= glyph
->charpos
;
28955 /* Try text properties. */
28958 && charpos
< SCHARS (obj
))
28960 help
= Fget_text_property (make_number (charpos
),
28964 /* If the string itself doesn't specify a help-echo,
28965 see if the buffer text ``under'' it does. */
28966 struct glyph_row
*r
28967 = MATRIX_ROW (w
->current_matrix
, vpos
);
28968 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28969 ptrdiff_t p
= string_buffer_position (obj
, start
);
28972 help
= Fget_char_property (make_number (p
),
28973 Qhelp_echo
, w
->contents
);
28982 else if (BUFFERP (obj
)
28985 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28990 help_echo_string
= help
;
28991 help_echo_window
= window
;
28992 help_echo_object
= obj
;
28993 help_echo_pos
= charpos
;
28998 #ifdef HAVE_WINDOW_SYSTEM
28999 /* Look for a `pointer' property. */
29000 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
29002 /* Check overlays first. */
29003 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
29004 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
29006 if (NILP (pointer
))
29008 Lisp_Object obj
= glyph
->object
;
29009 ptrdiff_t charpos
= glyph
->charpos
;
29011 /* Try text properties. */
29014 && charpos
< SCHARS (obj
))
29016 pointer
= Fget_text_property (make_number (charpos
),
29018 if (NILP (pointer
))
29020 /* If the string itself doesn't specify a pointer,
29021 see if the buffer text ``under'' it does. */
29022 struct glyph_row
*r
29023 = MATRIX_ROW (w
->current_matrix
, vpos
);
29024 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
29025 ptrdiff_t p
= string_buffer_position (obj
, start
);
29027 pointer
= Fget_char_property (make_number (p
),
29028 Qpointer
, w
->contents
);
29031 else if (BUFFERP (obj
)
29034 pointer
= Fget_text_property (make_number (charpos
),
29038 #endif /* HAVE_WINDOW_SYSTEM */
29042 current_buffer
= obuf
;
29047 #ifdef HAVE_WINDOW_SYSTEM
29048 if (FRAME_WINDOW_P (f
))
29049 define_frame_cursor1 (f
, cursor
, pointer
);
29051 /* This is here to prevent a compiler error, about "label at end of
29052 compound statement". */
29059 Clear any mouse-face on window W. This function is part of the
29060 redisplay interface, and is called from try_window_id and similar
29061 functions to ensure the mouse-highlight is off. */
29064 x_clear_window_mouse_face (struct window
*w
)
29066 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
29067 Lisp_Object window
;
29070 XSETWINDOW (window
, w
);
29071 if (EQ (window
, hlinfo
->mouse_face_window
))
29072 clear_mouse_face (hlinfo
);
29078 Just discard the mouse face information for frame F, if any.
29079 This is used when the size of F is changed. */
29082 cancel_mouse_face (struct frame
*f
)
29084 Lisp_Object window
;
29085 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29087 window
= hlinfo
->mouse_face_window
;
29088 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
29089 reset_mouse_highlight (hlinfo
);
29094 /***********************************************************************
29096 ***********************************************************************/
29098 #ifdef HAVE_WINDOW_SYSTEM
29100 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
29101 which intersects rectangle R. R is in window-relative coordinates. */
29104 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
29105 enum glyph_row_area area
)
29107 struct glyph
*first
= row
->glyphs
[area
];
29108 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
29109 struct glyph
*last
;
29110 int first_x
, start_x
, x
;
29112 if (area
== TEXT_AREA
&& row
->fill_line_p
)
29113 /* If row extends face to end of line write the whole line. */
29114 draw_glyphs (w
, 0, row
, area
,
29115 0, row
->used
[area
],
29116 DRAW_NORMAL_TEXT
, 0);
29119 /* Set START_X to the window-relative start position for drawing glyphs of
29120 AREA. The first glyph of the text area can be partially visible.
29121 The first glyphs of other areas cannot. */
29122 start_x
= window_box_left_offset (w
, area
);
29124 if (area
== TEXT_AREA
)
29127 /* Find the first glyph that must be redrawn. */
29129 && x
+ first
->pixel_width
< r
->x
)
29131 x
+= first
->pixel_width
;
29135 /* Find the last one. */
29139 && x
< r
->x
+ r
->width
)
29141 x
+= last
->pixel_width
;
29147 draw_glyphs (w
, first_x
- start_x
, row
, area
,
29148 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
29149 DRAW_NORMAL_TEXT
, 0);
29154 /* Redraw the parts of the glyph row ROW on window W intersecting
29155 rectangle R. R is in window-relative coordinates. Value is
29156 non-zero if mouse-face was overwritten. */
29159 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
29161 eassert (row
->enabled_p
);
29163 if (row
->mode_line_p
|| w
->pseudo_window_p
)
29164 draw_glyphs (w
, 0, row
, TEXT_AREA
,
29165 0, row
->used
[TEXT_AREA
],
29166 DRAW_NORMAL_TEXT
, 0);
29169 if (row
->used
[LEFT_MARGIN_AREA
])
29170 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
29171 if (row
->used
[TEXT_AREA
])
29172 expose_area (w
, row
, r
, TEXT_AREA
);
29173 if (row
->used
[RIGHT_MARGIN_AREA
])
29174 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
29175 draw_row_fringe_bitmaps (w
, row
);
29178 return row
->mouse_face_p
;
29182 /* Redraw those parts of glyphs rows during expose event handling that
29183 overlap other rows. Redrawing of an exposed line writes over parts
29184 of lines overlapping that exposed line; this function fixes that.
29186 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
29187 row in W's current matrix that is exposed and overlaps other rows.
29188 LAST_OVERLAPPING_ROW is the last such row. */
29191 expose_overlaps (struct window
*w
,
29192 struct glyph_row
*first_overlapping_row
,
29193 struct glyph_row
*last_overlapping_row
,
29196 struct glyph_row
*row
;
29198 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
29199 if (row
->overlapping_p
)
29201 eassert (row
->enabled_p
&& !row
->mode_line_p
);
29204 if (row
->used
[LEFT_MARGIN_AREA
])
29205 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
29207 if (row
->used
[TEXT_AREA
])
29208 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
29210 if (row
->used
[RIGHT_MARGIN_AREA
])
29211 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
29217 /* Return non-zero if W's cursor intersects rectangle R. */
29220 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
29222 XRectangle cr
, result
;
29223 struct glyph
*cursor_glyph
;
29224 struct glyph_row
*row
;
29226 if (w
->phys_cursor
.vpos
>= 0
29227 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
29228 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
29230 && row
->cursor_in_fringe_p
)
29232 /* Cursor is in the fringe. */
29233 cr
.x
= window_box_right_offset (w
,
29234 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
29235 ? RIGHT_MARGIN_AREA
29238 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
29239 cr
.height
= row
->height
;
29240 return x_intersect_rectangles (&cr
, r
, &result
);
29243 cursor_glyph
= get_phys_cursor_glyph (w
);
29246 /* r is relative to W's box, but w->phys_cursor.x is relative
29247 to left edge of W's TEXT area. Adjust it. */
29248 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
29249 cr
.y
= w
->phys_cursor
.y
;
29250 cr
.width
= cursor_glyph
->pixel_width
;
29251 cr
.height
= w
->phys_cursor_height
;
29252 /* ++KFS: W32 version used W32-specific IntersectRect here, but
29253 I assume the effect is the same -- and this is portable. */
29254 return x_intersect_rectangles (&cr
, r
, &result
);
29256 /* If we don't understand the format, pretend we're not in the hot-spot. */
29262 Draw a vertical window border to the right of window W if W doesn't
29263 have vertical scroll bars. */
29266 x_draw_vertical_border (struct window
*w
)
29268 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29270 /* We could do better, if we knew what type of scroll-bar the adjacent
29271 windows (on either side) have... But we don't :-(
29272 However, I think this works ok. ++KFS 2003-04-25 */
29274 /* Redraw borders between horizontally adjacent windows. Don't
29275 do it for frames with vertical scroll bars because either the
29276 right scroll bar of a window, or the left scroll bar of its
29277 neighbor will suffice as a border. */
29278 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
29281 /* Note: It is necessary to redraw both the left and the right
29282 borders, for when only this single window W is being
29284 if (!WINDOW_RIGHTMOST_P (w
)
29285 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
29287 int x0
, x1
, y0
, y1
;
29289 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29292 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29295 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
29298 if (!WINDOW_LEFTMOST_P (w
)
29299 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
29301 int x0
, x1
, y0
, y1
;
29303 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29306 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29309 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
29314 /* Draw window dividers for window W. */
29317 x_draw_right_divider (struct window
*w
)
29319 struct frame
*f
= WINDOW_XFRAME (w
);
29321 if (w
->mini
|| w
->pseudo_window_p
)
29323 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29325 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
29326 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29327 int y0
= WINDOW_TOP_EDGE_Y (w
);
29328 /* The bottom divider prevails. */
29329 int y1
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
29331 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29336 x_draw_bottom_divider (struct window
*w
)
29338 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29340 if (w
->mini
|| w
->pseudo_window_p
)
29342 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29344 int x0
= WINDOW_LEFT_EDGE_X (w
);
29345 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29346 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
29347 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
29349 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29353 /* Redraw the part of window W intersection rectangle FR. Pixel
29354 coordinates in FR are frame-relative. Call this function with
29355 input blocked. Value is non-zero if the exposure overwrites
29359 expose_window (struct window
*w
, XRectangle
*fr
)
29361 struct frame
*f
= XFRAME (w
->frame
);
29363 int mouse_face_overwritten_p
= 0;
29365 /* If window is not yet fully initialized, do nothing. This can
29366 happen when toolkit scroll bars are used and a window is split.
29367 Reconfiguring the scroll bar will generate an expose for a newly
29369 if (w
->current_matrix
== NULL
)
29372 /* When we're currently updating the window, display and current
29373 matrix usually don't agree. Arrange for a thorough display
29375 if (w
->must_be_updated_p
)
29377 SET_FRAME_GARBAGED (f
);
29381 /* Frame-relative pixel rectangle of W. */
29382 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
29383 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
29384 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
29385 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
29387 if (x_intersect_rectangles (fr
, &wr
, &r
))
29389 int yb
= window_text_bottom_y (w
);
29390 struct glyph_row
*row
;
29391 int cursor_cleared_p
, phys_cursor_on_p
;
29392 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
29394 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
29395 r
.x
, r
.y
, r
.width
, r
.height
));
29397 /* Convert to window coordinates. */
29398 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
29399 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
29401 /* Turn off the cursor. */
29402 if (!w
->pseudo_window_p
29403 && phys_cursor_in_rect_p (w
, &r
))
29405 x_clear_cursor (w
);
29406 cursor_cleared_p
= 1;
29409 cursor_cleared_p
= 0;
29411 /* If the row containing the cursor extends face to end of line,
29412 then expose_area might overwrite the cursor outside the
29413 rectangle and thus notice_overwritten_cursor might clear
29414 w->phys_cursor_on_p. We remember the original value and
29415 check later if it is changed. */
29416 phys_cursor_on_p
= w
->phys_cursor_on_p
;
29418 /* Update lines intersecting rectangle R. */
29419 first_overlapping_row
= last_overlapping_row
= NULL
;
29420 for (row
= w
->current_matrix
->rows
;
29425 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
29427 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
29428 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
29429 || (r
.y
>= y0
&& r
.y
< y1
)
29430 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
29432 /* A header line may be overlapping, but there is no need
29433 to fix overlapping areas for them. KFS 2005-02-12 */
29434 if (row
->overlapping_p
&& !row
->mode_line_p
)
29436 if (first_overlapping_row
== NULL
)
29437 first_overlapping_row
= row
;
29438 last_overlapping_row
= row
;
29442 if (expose_line (w
, row
, &r
))
29443 mouse_face_overwritten_p
= 1;
29446 else if (row
->overlapping_p
)
29448 /* We must redraw a row overlapping the exposed area. */
29450 ? y0
+ row
->phys_height
> r
.y
29451 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29453 if (first_overlapping_row
== NULL
)
29454 first_overlapping_row
= row
;
29455 last_overlapping_row
= row
;
29463 /* Display the mode line if there is one. */
29464 if (WINDOW_WANTS_MODELINE_P (w
)
29465 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29467 && row
->y
< r
.y
+ r
.height
)
29469 if (expose_line (w
, row
, &r
))
29470 mouse_face_overwritten_p
= 1;
29473 if (!w
->pseudo_window_p
)
29475 /* Fix the display of overlapping rows. */
29476 if (first_overlapping_row
)
29477 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29480 /* Draw border between windows. */
29481 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29482 x_draw_right_divider (w
);
29484 x_draw_vertical_border (w
);
29486 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29487 x_draw_bottom_divider (w
);
29489 /* Turn the cursor on again. */
29490 if (cursor_cleared_p
29491 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29492 update_window_cursor (w
, 1);
29496 return mouse_face_overwritten_p
;
29501 /* Redraw (parts) of all windows in the window tree rooted at W that
29502 intersect R. R contains frame pixel coordinates. Value is
29503 non-zero if the exposure overwrites mouse-face. */
29506 expose_window_tree (struct window
*w
, XRectangle
*r
)
29508 struct frame
*f
= XFRAME (w
->frame
);
29509 int mouse_face_overwritten_p
= 0;
29511 while (w
&& !FRAME_GARBAGED_P (f
))
29513 if (WINDOWP (w
->contents
))
29514 mouse_face_overwritten_p
29515 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29517 mouse_face_overwritten_p
|= expose_window (w
, r
);
29519 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29522 return mouse_face_overwritten_p
;
29527 Redisplay an exposed area of frame F. X and Y are the upper-left
29528 corner of the exposed rectangle. W and H are width and height of
29529 the exposed area. All are pixel values. W or H zero means redraw
29530 the entire frame. */
29533 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29536 int mouse_face_overwritten_p
= 0;
29538 TRACE ((stderr
, "expose_frame "));
29540 /* No need to redraw if frame will be redrawn soon. */
29541 if (FRAME_GARBAGED_P (f
))
29543 TRACE ((stderr
, " garbaged\n"));
29547 /* If basic faces haven't been realized yet, there is no point in
29548 trying to redraw anything. This can happen when we get an expose
29549 event while Emacs is starting, e.g. by moving another window. */
29550 if (FRAME_FACE_CACHE (f
) == NULL
29551 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29553 TRACE ((stderr
, " no faces\n"));
29557 if (w
== 0 || h
== 0)
29560 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29561 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29571 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29572 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29574 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
29575 if (WINDOWP (f
->tool_bar_window
))
29576 mouse_face_overwritten_p
29577 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29580 #ifdef HAVE_X_WINDOWS
29582 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29583 if (WINDOWP (f
->menu_bar_window
))
29584 mouse_face_overwritten_p
29585 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29586 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29590 /* Some window managers support a focus-follows-mouse style with
29591 delayed raising of frames. Imagine a partially obscured frame,
29592 and moving the mouse into partially obscured mouse-face on that
29593 frame. The visible part of the mouse-face will be highlighted,
29594 then the WM raises the obscured frame. With at least one WM, KDE
29595 2.1, Emacs is not getting any event for the raising of the frame
29596 (even tried with SubstructureRedirectMask), only Expose events.
29597 These expose events will draw text normally, i.e. not
29598 highlighted. Which means we must redo the highlight here.
29599 Subsume it under ``we love X''. --gerd 2001-08-15 */
29600 /* Included in Windows version because Windows most likely does not
29601 do the right thing if any third party tool offers
29602 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29603 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29605 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29606 if (f
== hlinfo
->mouse_face_mouse_frame
)
29608 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29609 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29610 clear_mouse_face (hlinfo
);
29611 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29618 Determine the intersection of two rectangles R1 and R2. Return
29619 the intersection in *RESULT. Value is non-zero if RESULT is not
29623 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29625 XRectangle
*left
, *right
;
29626 XRectangle
*upper
, *lower
;
29627 int intersection_p
= 0;
29629 /* Rearrange so that R1 is the left-most rectangle. */
29631 left
= r1
, right
= r2
;
29633 left
= r2
, right
= r1
;
29635 /* X0 of the intersection is right.x0, if this is inside R1,
29636 otherwise there is no intersection. */
29637 if (right
->x
<= left
->x
+ left
->width
)
29639 result
->x
= right
->x
;
29641 /* The right end of the intersection is the minimum of
29642 the right ends of left and right. */
29643 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29646 /* Same game for Y. */
29648 upper
= r1
, lower
= r2
;
29650 upper
= r2
, lower
= r1
;
29652 /* The upper end of the intersection is lower.y0, if this is inside
29653 of upper. Otherwise, there is no intersection. */
29654 if (lower
->y
<= upper
->y
+ upper
->height
)
29656 result
->y
= lower
->y
;
29658 /* The lower end of the intersection is the minimum of the lower
29659 ends of upper and lower. */
29660 result
->height
= (min (lower
->y
+ lower
->height
,
29661 upper
->y
+ upper
->height
)
29663 intersection_p
= 1;
29667 return intersection_p
;
29670 #endif /* HAVE_WINDOW_SYSTEM */
29673 /***********************************************************************
29675 ***********************************************************************/
29678 syms_of_xdisp (void)
29680 Vwith_echo_area_save_vector
= Qnil
;
29681 staticpro (&Vwith_echo_area_save_vector
);
29683 Vmessage_stack
= Qnil
;
29684 staticpro (&Vmessage_stack
);
29686 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29687 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29689 message_dolog_marker1
= Fmake_marker ();
29690 staticpro (&message_dolog_marker1
);
29691 message_dolog_marker2
= Fmake_marker ();
29692 staticpro (&message_dolog_marker2
);
29693 message_dolog_marker3
= Fmake_marker ();
29694 staticpro (&message_dolog_marker3
);
29697 defsubr (&Sdump_frame_glyph_matrix
);
29698 defsubr (&Sdump_glyph_matrix
);
29699 defsubr (&Sdump_glyph_row
);
29700 defsubr (&Sdump_tool_bar_row
);
29701 defsubr (&Strace_redisplay
);
29702 defsubr (&Strace_to_stderr
);
29704 #ifdef HAVE_WINDOW_SYSTEM
29705 defsubr (&Stool_bar_height
);
29706 defsubr (&Slookup_image_map
);
29708 defsubr (&Sline_pixel_height
);
29709 defsubr (&Sformat_mode_line
);
29710 defsubr (&Sinvisible_p
);
29711 defsubr (&Scurrent_bidi_paragraph_direction
);
29712 defsubr (&Swindow_text_pixel_size
);
29713 defsubr (&Smove_point_visually
);
29715 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29716 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29717 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29718 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29719 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29720 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29721 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29722 DEFSYM (Qeval
, "eval");
29723 DEFSYM (QCdata
, ":data");
29724 DEFSYM (Qdisplay
, "display");
29725 DEFSYM (Qspace_width
, "space-width");
29726 DEFSYM (Qraise
, "raise");
29727 DEFSYM (Qslice
, "slice");
29728 DEFSYM (Qspace
, "space");
29729 DEFSYM (Qmargin
, "margin");
29730 DEFSYM (Qpointer
, "pointer");
29731 DEFSYM (Qleft_margin
, "left-margin");
29732 DEFSYM (Qright_margin
, "right-margin");
29733 DEFSYM (Qcenter
, "center");
29734 DEFSYM (Qline_height
, "line-height");
29735 DEFSYM (QCalign_to
, ":align-to");
29736 DEFSYM (QCrelative_width
, ":relative-width");
29737 DEFSYM (QCrelative_height
, ":relative-height");
29738 DEFSYM (QCeval
, ":eval");
29739 DEFSYM (QCpropertize
, ":propertize");
29740 DEFSYM (QCfile
, ":file");
29741 DEFSYM (Qfontified
, "fontified");
29742 DEFSYM (Qfontification_functions
, "fontification-functions");
29743 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29744 DEFSYM (Qescape_glyph
, "escape-glyph");
29745 DEFSYM (Qnobreak_space
, "nobreak-space");
29746 DEFSYM (Qimage
, "image");
29747 DEFSYM (Qtext
, "text");
29748 DEFSYM (Qboth
, "both");
29749 DEFSYM (Qboth_horiz
, "both-horiz");
29750 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29751 DEFSYM (QCmap
, ":map");
29752 DEFSYM (QCpointer
, ":pointer");
29753 DEFSYM (Qrect
, "rect");
29754 DEFSYM (Qcircle
, "circle");
29755 DEFSYM (Qpoly
, "poly");
29756 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29757 DEFSYM (Qgrow_only
, "grow-only");
29758 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29759 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29760 DEFSYM (Qposition
, "position");
29761 DEFSYM (Qbuffer_position
, "buffer-position");
29762 DEFSYM (Qobject
, "object");
29763 DEFSYM (Qbar
, "bar");
29764 DEFSYM (Qhbar
, "hbar");
29765 DEFSYM (Qbox
, "box");
29766 DEFSYM (Qhollow
, "hollow");
29767 DEFSYM (Qhand
, "hand");
29768 DEFSYM (Qarrow
, "arrow");
29769 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29771 list_of_error
= list1 (list2 (intern_c_string ("error"),
29772 intern_c_string ("void-variable")));
29773 staticpro (&list_of_error
);
29775 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29776 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29777 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29778 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29780 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29781 staticpro (&echo_buffer
[0]);
29782 staticpro (&echo_buffer
[1]);
29784 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29785 staticpro (&echo_area_buffer
[0]);
29786 staticpro (&echo_area_buffer
[1]);
29788 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29789 staticpro (&Vmessages_buffer_name
);
29791 mode_line_proptrans_alist
= Qnil
;
29792 staticpro (&mode_line_proptrans_alist
);
29793 mode_line_string_list
= Qnil
;
29794 staticpro (&mode_line_string_list
);
29795 mode_line_string_face
= Qnil
;
29796 staticpro (&mode_line_string_face
);
29797 mode_line_string_face_prop
= Qnil
;
29798 staticpro (&mode_line_string_face_prop
);
29799 Vmode_line_unwind_vector
= Qnil
;
29800 staticpro (&Vmode_line_unwind_vector
);
29802 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29804 help_echo_string
= Qnil
;
29805 staticpro (&help_echo_string
);
29806 help_echo_object
= Qnil
;
29807 staticpro (&help_echo_object
);
29808 help_echo_window
= Qnil
;
29809 staticpro (&help_echo_window
);
29810 previous_help_echo_string
= Qnil
;
29811 staticpro (&previous_help_echo_string
);
29812 help_echo_pos
= -1;
29814 DEFSYM (Qright_to_left
, "right-to-left");
29815 DEFSYM (Qleft_to_right
, "left-to-right");
29817 #ifdef HAVE_WINDOW_SYSTEM
29818 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29819 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29820 For example, if a block cursor is over a tab, it will be drawn as
29821 wide as that tab on the display. */);
29822 x_stretch_cursor_p
= 0;
29825 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29826 doc
: /* Non-nil means highlight trailing whitespace.
29827 The face used for trailing whitespace is `trailing-whitespace'. */);
29828 Vshow_trailing_whitespace
= Qnil
;
29830 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29831 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29832 If the value is t, Emacs highlights non-ASCII chars which have the
29833 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29834 or `escape-glyph' face respectively.
29836 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29837 U+2011 (non-breaking hyphen) are affected.
29839 Any other non-nil value means to display these characters as a escape
29840 glyph followed by an ordinary space or hyphen.
29842 A value of nil means no special handling of these characters. */);
29843 Vnobreak_char_display
= Qt
;
29845 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29846 doc
: /* The pointer shape to show in void text areas.
29847 A value of nil means to show the text pointer. Other options are `arrow',
29848 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29849 Vvoid_text_area_pointer
= Qarrow
;
29851 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29852 doc
: /* Non-nil means don't actually do any redisplay.
29853 This is used for internal purposes. */);
29854 Vinhibit_redisplay
= Qnil
;
29856 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29857 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29858 Vglobal_mode_string
= Qnil
;
29860 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29861 doc
: /* Marker for where to display an arrow on top of the buffer text.
29862 This must be the beginning of a line in order to work.
29863 See also `overlay-arrow-string'. */);
29864 Voverlay_arrow_position
= Qnil
;
29866 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29867 doc
: /* String to display as an arrow in non-window frames.
29868 See also `overlay-arrow-position'. */);
29869 Voverlay_arrow_string
= build_pure_c_string ("=>");
29871 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29872 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29873 The symbols on this list are examined during redisplay to determine
29874 where to display overlay arrows. */);
29875 Voverlay_arrow_variable_list
29876 = list1 (intern_c_string ("overlay-arrow-position"));
29878 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29879 doc
: /* The number of lines to try scrolling a window by when point moves out.
29880 If that fails to bring point back on frame, point is centered instead.
29881 If this is zero, point is always centered after it moves off frame.
29882 If you want scrolling to always be a line at a time, you should set
29883 `scroll-conservatively' to a large value rather than set this to 1. */);
29885 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29886 doc
: /* Scroll up to this many lines, to bring point back on screen.
29887 If point moves off-screen, redisplay will scroll by up to
29888 `scroll-conservatively' lines in order to bring point just barely
29889 onto the screen again. If that cannot be done, then redisplay
29890 recenters point as usual.
29892 If the value is greater than 100, redisplay will never recenter point,
29893 but will always scroll just enough text to bring point into view, even
29894 if you move far away.
29896 A value of zero means always recenter point if it moves off screen. */);
29897 scroll_conservatively
= 0;
29899 DEFVAR_INT ("scroll-margin", scroll_margin
,
29900 doc
: /* Number of lines of margin at the top and bottom of a window.
29901 Recenter the window whenever point gets within this many lines
29902 of the top or bottom of the window. */);
29905 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29906 doc
: /* Pixels per inch value for non-window system displays.
29907 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29908 Vdisplay_pixels_per_inch
= make_float (72.0);
29911 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29914 DEFVAR_LISP ("truncate-partial-width-windows",
29915 Vtruncate_partial_width_windows
,
29916 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29917 For an integer value, truncate lines in each window narrower than the
29918 full frame width, provided the window width is less than that integer;
29919 otherwise, respect the value of `truncate-lines'.
29921 For any other non-nil value, truncate lines in all windows that do
29922 not span the full frame width.
29924 A value of nil means to respect the value of `truncate-lines'.
29926 If `word-wrap' is enabled, you might want to reduce this. */);
29927 Vtruncate_partial_width_windows
= make_number (50);
29929 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29930 doc
: /* Maximum buffer size for which line number should be displayed.
29931 If the buffer is bigger than this, the line number does not appear
29932 in the mode line. A value of nil means no limit. */);
29933 Vline_number_display_limit
= Qnil
;
29935 DEFVAR_INT ("line-number-display-limit-width",
29936 line_number_display_limit_width
,
29937 doc
: /* Maximum line width (in characters) for line number display.
29938 If the average length of the lines near point is bigger than this, then the
29939 line number may be omitted from the mode line. */);
29940 line_number_display_limit_width
= 200;
29942 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29943 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29944 highlight_nonselected_windows
= 0;
29946 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29947 doc
: /* Non-nil if more than one frame is visible on this display.
29948 Minibuffer-only frames don't count, but iconified frames do.
29949 This variable is not guaranteed to be accurate except while processing
29950 `frame-title-format' and `icon-title-format'. */);
29952 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29953 doc
: /* Template for displaying the title bar of visible frames.
29954 \(Assuming the window manager supports this feature.)
29956 This variable has the same structure as `mode-line-format', except that
29957 the %c and %l constructs are ignored. It is used only on frames for
29958 which no explicit name has been set \(see `modify-frame-parameters'). */);
29960 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29961 doc
: /* Template for displaying the title bar of an iconified frame.
29962 \(Assuming the window manager supports this feature.)
29963 This variable has the same structure as `mode-line-format' (which see),
29964 and is used only on frames for which no explicit name has been set
29965 \(see `modify-frame-parameters'). */);
29967 = Vframe_title_format
29968 = listn (CONSTYPE_PURE
, 3,
29969 intern_c_string ("multiple-frames"),
29970 build_pure_c_string ("%b"),
29971 listn (CONSTYPE_PURE
, 4,
29972 empty_unibyte_string
,
29973 intern_c_string ("invocation-name"),
29974 build_pure_c_string ("@"),
29975 intern_c_string ("system-name")));
29977 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29978 doc
: /* Maximum number of lines to keep in the message log buffer.
29979 If nil, disable message logging. If t, log messages but don't truncate
29980 the buffer when it becomes large. */);
29981 Vmessage_log_max
= make_number (1000);
29983 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29984 doc
: /* Functions called before redisplay, if window sizes have changed.
29985 The value should be a list of functions that take one argument.
29986 Just before redisplay, for each frame, if any of its windows have changed
29987 size since the last redisplay, or have been split or deleted,
29988 all the functions in the list are called, with the frame as argument. */);
29989 Vwindow_size_change_functions
= Qnil
;
29991 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29992 doc
: /* List of functions to call before redisplaying a window with scrolling.
29993 Each function is called with two arguments, the window and its new
29994 display-start position. Note that these functions are also called by
29995 `set-window-buffer'. Also note that the value of `window-end' is not
29996 valid when these functions are called.
29998 Warning: Do not use this feature to alter the way the window
29999 is scrolled. It is not designed for that, and such use probably won't
30001 Vwindow_scroll_functions
= Qnil
;
30003 DEFVAR_LISP ("window-text-change-functions",
30004 Vwindow_text_change_functions
,
30005 doc
: /* Functions to call in redisplay when text in the window might change. */);
30006 Vwindow_text_change_functions
= Qnil
;
30008 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
30009 doc
: /* Functions called when redisplay of a window reaches the end trigger.
30010 Each function is called with two arguments, the window and the end trigger value.
30011 See `set-window-redisplay-end-trigger'. */);
30012 Vredisplay_end_trigger_functions
= Qnil
;
30014 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
30015 doc
: /* Non-nil means autoselect window with mouse pointer.
30016 If nil, do not autoselect windows.
30017 A positive number means delay autoselection by that many seconds: a
30018 window is autoselected only after the mouse has remained in that
30019 window for the duration of the delay.
30020 A negative number has a similar effect, but causes windows to be
30021 autoselected only after the mouse has stopped moving. \(Because of
30022 the way Emacs compares mouse events, you will occasionally wait twice
30023 that time before the window gets selected.\)
30024 Any other value means to autoselect window instantaneously when the
30025 mouse pointer enters it.
30027 Autoselection selects the minibuffer only if it is active, and never
30028 unselects the minibuffer if it is active.
30030 When customizing this variable make sure that the actual value of
30031 `focus-follows-mouse' matches the behavior of your window manager. */);
30032 Vmouse_autoselect_window
= Qnil
;
30034 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
30035 doc
: /* Non-nil means automatically resize tool-bars.
30036 This dynamically changes the tool-bar's height to the minimum height
30037 that is needed to make all tool-bar items visible.
30038 If value is `grow-only', the tool-bar's height is only increased
30039 automatically; to decrease the tool-bar height, use \\[recenter]. */);
30040 Vauto_resize_tool_bars
= Qt
;
30042 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
30043 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
30044 auto_raise_tool_bar_buttons_p
= 1;
30046 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
30047 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
30048 make_cursor_line_fully_visible_p
= 1;
30050 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
30051 doc
: /* Border below tool-bar in pixels.
30052 If an integer, use it as the height of the border.
30053 If it is one of `internal-border-width' or `border-width', use the
30054 value of the corresponding frame parameter.
30055 Otherwise, no border is added below the tool-bar. */);
30056 Vtool_bar_border
= Qinternal_border_width
;
30058 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
30059 doc
: /* Margin around tool-bar buttons in pixels.
30060 If an integer, use that for both horizontal and vertical margins.
30061 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
30062 HORZ specifying the horizontal margin, and VERT specifying the
30063 vertical margin. */);
30064 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
30066 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
30067 doc
: /* Relief thickness of tool-bar buttons. */);
30068 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
30070 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
30071 doc
: /* Tool bar style to use.
30073 image - show images only
30074 text - show text only
30075 both - show both, text below image
30076 both-horiz - show text to the right of the image
30077 text-image-horiz - show text to the left of the image
30078 any other - use system default or image if no system default.
30080 This variable only affects the GTK+ toolkit version of Emacs. */);
30081 Vtool_bar_style
= Qnil
;
30083 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
30084 doc
: /* Maximum number of characters a label can have to be shown.
30085 The tool bar style must also show labels for this to have any effect, see
30086 `tool-bar-style'. */);
30087 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
30089 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
30090 doc
: /* List of functions to call to fontify regions of text.
30091 Each function is called with one argument POS. Functions must
30092 fontify a region starting at POS in the current buffer, and give
30093 fontified regions the property `fontified'. */);
30094 Vfontification_functions
= Qnil
;
30095 Fmake_variable_buffer_local (Qfontification_functions
);
30097 DEFVAR_BOOL ("unibyte-display-via-language-environment",
30098 unibyte_display_via_language_environment
,
30099 doc
: /* Non-nil means display unibyte text according to language environment.
30100 Specifically, this means that raw bytes in the range 160-255 decimal
30101 are displayed by converting them to the equivalent multibyte characters
30102 according to the current language environment. As a result, they are
30103 displayed according to the current fontset.
30105 Note that this variable affects only how these bytes are displayed,
30106 but does not change the fact they are interpreted as raw bytes. */);
30107 unibyte_display_via_language_environment
= 0;
30109 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
30110 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
30111 If a float, it specifies a fraction of the mini-window frame's height.
30112 If an integer, it specifies a number of lines. */);
30113 Vmax_mini_window_height
= make_float (0.25);
30115 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
30116 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
30117 A value of nil means don't automatically resize mini-windows.
30118 A value of t means resize them to fit the text displayed in them.
30119 A value of `grow-only', the default, means let mini-windows grow only;
30120 they return to their normal size when the minibuffer is closed, or the
30121 echo area becomes empty. */);
30122 Vresize_mini_windows
= Qgrow_only
;
30124 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
30125 doc
: /* Alist specifying how to blink the cursor off.
30126 Each element has the form (ON-STATE . OFF-STATE). Whenever the
30127 `cursor-type' frame-parameter or variable equals ON-STATE,
30128 comparing using `equal', Emacs uses OFF-STATE to specify
30129 how to blink it off. ON-STATE and OFF-STATE are values for
30130 the `cursor-type' frame parameter.
30132 If a frame's ON-STATE has no entry in this list,
30133 the frame's other specifications determine how to blink the cursor off. */);
30134 Vblink_cursor_alist
= Qnil
;
30136 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
30137 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
30138 If non-nil, windows are automatically scrolled horizontally to make
30139 point visible. */);
30140 automatic_hscrolling_p
= 1;
30141 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
30143 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
30144 doc
: /* How many columns away from the window edge point is allowed to get
30145 before automatic hscrolling will horizontally scroll the window. */);
30146 hscroll_margin
= 5;
30148 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
30149 doc
: /* How many columns to scroll the window when point gets too close to the edge.
30150 When point is less than `hscroll-margin' columns from the window
30151 edge, automatic hscrolling will scroll the window by the amount of columns
30152 determined by this variable. If its value is a positive integer, scroll that
30153 many columns. If it's a positive floating-point number, it specifies the
30154 fraction of the window's width to scroll. If it's nil or zero, point will be
30155 centered horizontally after the scroll. Any other value, including negative
30156 numbers, are treated as if the value were zero.
30158 Automatic hscrolling always moves point outside the scroll margin, so if
30159 point was more than scroll step columns inside the margin, the window will
30160 scroll more than the value given by the scroll step.
30162 Note that the lower bound for automatic hscrolling specified by `scroll-left'
30163 and `scroll-right' overrides this variable's effect. */);
30164 Vhscroll_step
= make_number (0);
30166 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
30167 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
30168 Bind this around calls to `message' to let it take effect. */);
30169 message_truncate_lines
= 0;
30171 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
30172 doc
: /* Normal hook run to update the menu bar definitions.
30173 Redisplay runs this hook before it redisplays the menu bar.
30174 This is used to update menus such as Buffers, whose contents depend on
30176 Vmenu_bar_update_hook
= Qnil
;
30178 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
30179 doc
: /* Frame for which we are updating a menu.
30180 The enable predicate for a menu binding should check this variable. */);
30181 Vmenu_updating_frame
= Qnil
;
30183 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
30184 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
30185 inhibit_menubar_update
= 0;
30187 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
30188 doc
: /* Prefix prepended to all continuation lines at display time.
30189 The value may be a string, an image, or a stretch-glyph; it is
30190 interpreted in the same way as the value of a `display' text property.
30192 This variable is overridden by any `wrap-prefix' text or overlay
30195 To add a prefix to non-continuation lines, use `line-prefix'. */);
30196 Vwrap_prefix
= Qnil
;
30197 DEFSYM (Qwrap_prefix
, "wrap-prefix");
30198 Fmake_variable_buffer_local (Qwrap_prefix
);
30200 DEFVAR_LISP ("line-prefix", Vline_prefix
,
30201 doc
: /* Prefix prepended to all non-continuation lines at display time.
30202 The value may be a string, an image, or a stretch-glyph; it is
30203 interpreted in the same way as the value of a `display' text property.
30205 This variable is overridden by any `line-prefix' text or overlay
30208 To add a prefix to continuation lines, use `wrap-prefix'. */);
30209 Vline_prefix
= Qnil
;
30210 DEFSYM (Qline_prefix
, "line-prefix");
30211 Fmake_variable_buffer_local (Qline_prefix
);
30213 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
30214 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
30215 inhibit_eval_during_redisplay
= 0;
30217 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
30218 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
30219 inhibit_free_realized_faces
= 0;
30222 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
30223 doc
: /* Inhibit try_window_id display optimization. */);
30224 inhibit_try_window_id
= 0;
30226 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
30227 doc
: /* Inhibit try_window_reusing display optimization. */);
30228 inhibit_try_window_reusing
= 0;
30230 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
30231 doc
: /* Inhibit try_cursor_movement display optimization. */);
30232 inhibit_try_cursor_movement
= 0;
30233 #endif /* GLYPH_DEBUG */
30235 DEFVAR_INT ("overline-margin", overline_margin
,
30236 doc
: /* Space between overline and text, in pixels.
30237 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
30238 margin to the character height. */);
30239 overline_margin
= 2;
30241 DEFVAR_INT ("underline-minimum-offset",
30242 underline_minimum_offset
,
30243 doc
: /* Minimum distance between baseline and underline.
30244 This can improve legibility of underlined text at small font sizes,
30245 particularly when using variable `x-use-underline-position-properties'
30246 with fonts that specify an UNDERLINE_POSITION relatively close to the
30247 baseline. The default value is 1. */);
30248 underline_minimum_offset
= 1;
30250 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
30251 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
30252 This feature only works when on a window system that can change
30253 cursor shapes. */);
30254 display_hourglass_p
= 1;
30256 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
30257 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
30258 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
30260 #ifdef HAVE_WINDOW_SYSTEM
30261 hourglass_atimer
= NULL
;
30262 hourglass_shown_p
= 0;
30263 #endif /* HAVE_WINDOW_SYSTEM */
30265 DEFSYM (Qglyphless_char
, "glyphless-char");
30266 DEFSYM (Qhex_code
, "hex-code");
30267 DEFSYM (Qempty_box
, "empty-box");
30268 DEFSYM (Qthin_space
, "thin-space");
30269 DEFSYM (Qzero_width
, "zero-width");
30271 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
30272 doc
: /* Function run just before redisplay.
30273 It is called with one argument, which is the set of windows that are to
30274 be redisplayed. This set can be nil (meaning, only the selected window),
30275 or t (meaning all windows). */);
30276 Vpre_redisplay_function
= intern ("ignore");
30278 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
30279 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
30281 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
30282 doc
: /* Char-table defining glyphless characters.
30283 Each element, if non-nil, should be one of the following:
30284 an ASCII acronym string: display this string in a box
30285 `hex-code': display the hexadecimal code of a character in a box
30286 `empty-box': display as an empty box
30287 `thin-space': display as 1-pixel width space
30288 `zero-width': don't display
30289 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
30290 display method for graphical terminals and text terminals respectively.
30291 GRAPHICAL and TEXT should each have one of the values listed above.
30293 The char-table has one extra slot to control the display of a character for
30294 which no font is found. This slot only takes effect on graphical terminals.
30295 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
30296 `thin-space'. The default is `empty-box'.
30298 If a character has a non-nil entry in an active display table, the
30299 display table takes effect; in this case, Emacs does not consult
30300 `glyphless-char-display' at all. */);
30301 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
30302 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
30305 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
30306 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
30307 Vdebug_on_message
= Qnil
;
30309 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
30311 Vredisplay__all_windows_cause
30312 = Fmake_vector (make_number (100), make_number (0));
30314 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
30316 Vredisplay__mode_lines_cause
30317 = Fmake_vector (make_number (100), make_number (0));
30321 /* Initialize this module when Emacs starts. */
30326 CHARPOS (this_line_start_pos
) = 0;
30328 if (!noninteractive
)
30330 struct window
*m
= XWINDOW (minibuf_window
);
30331 Lisp_Object frame
= m
->frame
;
30332 struct frame
*f
= XFRAME (frame
);
30333 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
30334 struct window
*r
= XWINDOW (root
);
30337 echo_area_window
= minibuf_window
;
30339 r
->top_line
= FRAME_TOP_MARGIN (f
);
30340 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
30341 r
->total_cols
= FRAME_COLS (f
);
30342 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30343 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
30344 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
30346 m
->top_line
= FRAME_LINES (f
) - 1;
30347 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
30348 m
->total_cols
= FRAME_COLS (f
);
30349 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30350 m
->total_lines
= 1;
30351 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
30353 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
30354 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
30355 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
30357 /* The default ellipsis glyphs `...'. */
30358 for (i
= 0; i
< 3; ++i
)
30359 default_invis_vector
[i
] = make_number ('.');
30363 /* Allocate the buffer for frame titles.
30364 Also used for `format-mode-line'. */
30366 mode_line_noprop_buf
= xmalloc (size
);
30367 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
30368 mode_line_noprop_ptr
= mode_line_noprop_buf
;
30369 mode_line_target
= MODE_LINE_DISPLAY
;
30372 help_echo_showing_p
= 0;
30375 #ifdef HAVE_WINDOW_SYSTEM
30377 /* Platform-independent portion of hourglass implementation. */
30379 /* Cancel a currently active hourglass timer, and start a new one. */
30381 start_hourglass (void)
30383 struct timespec delay
;
30385 cancel_hourglass ();
30387 if (INTEGERP (Vhourglass_delay
)
30388 && XINT (Vhourglass_delay
) > 0)
30389 delay
= make_timespec (min (XINT (Vhourglass_delay
),
30390 TYPE_MAXIMUM (time_t)),
30392 else if (FLOATP (Vhourglass_delay
)
30393 && XFLOAT_DATA (Vhourglass_delay
) > 0)
30394 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
30396 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
30400 extern void w32_note_current_window (void);
30401 w32_note_current_window ();
30403 #endif /* HAVE_NTGUI */
30405 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
30406 show_hourglass
, NULL
);
30410 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
30413 cancel_hourglass (void)
30415 if (hourglass_atimer
)
30417 cancel_atimer (hourglass_atimer
);
30418 hourglass_atimer
= NULL
;
30421 if (hourglass_shown_p
)
30425 #endif /* HAVE_WINDOW_SYSTEM */