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
->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 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 position > CHARPOS that is the closest to CHARPOS. We restore
8334 that position in IT when we have scanned the entire display line
8335 without finding a match for CHARPOS and all the character
8336 positions are greater than CHARPOS. */
8339 SAVE_IT (ppos_it
, *it
, ppos_data
);
8340 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8341 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8342 SAVE_IT (ppos_it
, *it
, ppos_data
);
8345 #define BUFFER_POS_REACHED_P() \
8346 ((op & MOVE_TO_POS) != 0 \
8347 && BUFFERP (it->object) \
8348 && (IT_CHARPOS (*it) == to_charpos \
8350 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8351 && IT_CHARPOS (*it) > to_charpos) \
8352 || (it->what == IT_COMPOSITION \
8353 && ((IT_CHARPOS (*it) > to_charpos \
8354 && to_charpos >= it->cmp_it.charpos) \
8355 || (IT_CHARPOS (*it) < to_charpos \
8356 && to_charpos <= it->cmp_it.charpos)))) \
8357 && (it->method == GET_FROM_BUFFER \
8358 || (it->method == GET_FROM_DISPLAY_VECTOR \
8359 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8361 /* If there's a line-/wrap-prefix, handle it. */
8362 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8363 && it
->current_y
< it
->last_visible_y
)
8364 handle_line_prefix (it
);
8366 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8367 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8371 int x
, i
, ascent
= 0, descent
= 0;
8373 /* Utility macro to reset an iterator with x, ascent, and descent. */
8374 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8375 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8376 (IT)->max_descent = descent)
8378 /* Stop if we move beyond TO_CHARPOS (after an image or a
8379 display string or stretch glyph). */
8380 if ((op
& MOVE_TO_POS
) != 0
8381 && BUFFERP (it
->object
)
8382 && it
->method
== GET_FROM_BUFFER
8384 /* When the iterator is at base embedding level, we
8385 are guaranteed that characters are delivered for
8386 display in strictly increasing order of their
8387 buffer positions. */
8388 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8389 && IT_CHARPOS (*it
) > to_charpos
)
8391 && (prev_method
== GET_FROM_IMAGE
8392 || prev_method
== GET_FROM_STRETCH
8393 || prev_method
== GET_FROM_STRING
)
8394 /* Passed TO_CHARPOS from left to right. */
8395 && ((prev_pos
< to_charpos
8396 && IT_CHARPOS (*it
) > to_charpos
)
8397 /* Passed TO_CHARPOS from right to left. */
8398 || (prev_pos
> to_charpos
8399 && IT_CHARPOS (*it
) < to_charpos
)))))
8401 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8403 result
= MOVE_POS_MATCH_OR_ZV
;
8406 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8407 /* If wrap_it is valid, the current position might be in a
8408 word that is wrapped. So, save the iterator in
8409 atpos_it and continue to see if wrapping happens. */
8410 SAVE_IT (atpos_it
, *it
, atpos_data
);
8413 /* Stop when ZV reached.
8414 We used to stop here when TO_CHARPOS reached as well, but that is
8415 too soon if this glyph does not fit on this line. So we handle it
8416 explicitly below. */
8417 if (!get_next_display_element (it
))
8419 result
= MOVE_POS_MATCH_OR_ZV
;
8423 if (it
->line_wrap
== TRUNCATE
)
8425 if (BUFFER_POS_REACHED_P ())
8427 result
= MOVE_POS_MATCH_OR_ZV
;
8433 if (it
->line_wrap
== WORD_WRAP
)
8435 if (IT_DISPLAYING_WHITESPACE (it
))
8439 /* We have reached a glyph that follows one or more
8440 whitespace characters. If the position is
8441 already found, we are done. */
8442 if (atpos_it
.sp
>= 0)
8444 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8445 result
= MOVE_POS_MATCH_OR_ZV
;
8450 RESTORE_IT (it
, &atx_it
, atx_data
);
8451 result
= MOVE_X_REACHED
;
8454 /* Otherwise, we can wrap here. */
8455 SAVE_IT (wrap_it
, *it
, wrap_data
);
8461 /* Remember the line height for the current line, in case
8462 the next element doesn't fit on the line. */
8463 ascent
= it
->max_ascent
;
8464 descent
= it
->max_descent
;
8466 /* The call to produce_glyphs will get the metrics of the
8467 display element IT is loaded with. Record the x-position
8468 before this display element, in case it doesn't fit on the
8472 PRODUCE_GLYPHS (it
);
8474 if (it
->area
!= TEXT_AREA
)
8476 prev_method
= it
->method
;
8477 if (it
->method
== GET_FROM_BUFFER
)
8478 prev_pos
= IT_CHARPOS (*it
);
8479 set_iterator_to_next (it
, 1);
8480 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8481 SET_TEXT_POS (this_line_min_pos
,
8482 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8484 && (op
& MOVE_TO_POS
)
8485 && IT_CHARPOS (*it
) > to_charpos
8486 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8487 SAVE_IT (ppos_it
, *it
, ppos_data
);
8491 /* The number of glyphs we get back in IT->nglyphs will normally
8492 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8493 character on a terminal frame, or (iii) a line end. For the
8494 second case, IT->nglyphs - 1 padding glyphs will be present.
8495 (On X frames, there is only one glyph produced for a
8496 composite character.)
8498 The behavior implemented below means, for continuation lines,
8499 that as many spaces of a TAB as fit on the current line are
8500 displayed there. For terminal frames, as many glyphs of a
8501 multi-glyph character are displayed in the current line, too.
8502 This is what the old redisplay code did, and we keep it that
8503 way. Under X, the whole shape of a complex character must
8504 fit on the line or it will be completely displayed in the
8507 Note that both for tabs and padding glyphs, all glyphs have
8511 /* More than one glyph or glyph doesn't fit on line. All
8512 glyphs have the same width. */
8513 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8515 int x_before_this_char
= x
;
8516 int hpos_before_this_char
= it
->hpos
;
8518 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8520 new_x
= x
+ single_glyph_width
;
8522 /* We want to leave anything reaching TO_X to the caller. */
8523 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8525 if (BUFFER_POS_REACHED_P ())
8527 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8528 goto buffer_pos_reached
;
8529 if (atpos_it
.sp
< 0)
8531 SAVE_IT (atpos_it
, *it
, atpos_data
);
8532 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8537 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8540 result
= MOVE_X_REACHED
;
8545 SAVE_IT (atx_it
, *it
, atx_data
);
8546 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8551 if (/* Lines are continued. */
8552 it
->line_wrap
!= TRUNCATE
8553 && (/* And glyph doesn't fit on the line. */
8554 new_x
> it
->last_visible_x
8555 /* Or it fits exactly and we're on a window
8557 || (new_x
== it
->last_visible_x
8558 && FRAME_WINDOW_P (it
->f
)
8559 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8560 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8561 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8563 if (/* IT->hpos == 0 means the very first glyph
8564 doesn't fit on the line, e.g. a wide image. */
8566 || (new_x
== it
->last_visible_x
8567 && FRAME_WINDOW_P (it
->f
)))
8570 it
->current_x
= new_x
;
8572 /* The character's last glyph just barely fits
8574 if (i
== it
->nglyphs
- 1)
8576 /* If this is the destination position,
8577 return a position *before* it in this row,
8578 now that we know it fits in this row. */
8579 if (BUFFER_POS_REACHED_P ())
8581 if (it
->line_wrap
!= WORD_WRAP
8584 it
->hpos
= hpos_before_this_char
;
8585 it
->current_x
= x_before_this_char
;
8586 result
= MOVE_POS_MATCH_OR_ZV
;
8589 if (it
->line_wrap
== WORD_WRAP
8592 SAVE_IT (atpos_it
, *it
, atpos_data
);
8593 atpos_it
.current_x
= x_before_this_char
;
8594 atpos_it
.hpos
= hpos_before_this_char
;
8598 prev_method
= it
->method
;
8599 if (it
->method
== GET_FROM_BUFFER
)
8600 prev_pos
= IT_CHARPOS (*it
);
8601 set_iterator_to_next (it
, 1);
8602 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8603 SET_TEXT_POS (this_line_min_pos
,
8604 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8605 /* On graphical terminals, newlines may
8606 "overflow" into the fringe if
8607 overflow-newline-into-fringe is non-nil.
8608 On text terminals, and on graphical
8609 terminals with no right margin, newlines
8610 may overflow into the last glyph on the
8612 if (!FRAME_WINDOW_P (it
->f
)
8614 && it
->bidi_it
.paragraph_dir
== R2L
)
8615 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8616 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8617 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8619 if (!get_next_display_element (it
))
8621 result
= MOVE_POS_MATCH_OR_ZV
;
8624 if (BUFFER_POS_REACHED_P ())
8626 if (ITERATOR_AT_END_OF_LINE_P (it
))
8627 result
= MOVE_POS_MATCH_OR_ZV
;
8629 result
= MOVE_LINE_CONTINUED
;
8632 if (ITERATOR_AT_END_OF_LINE_P (it
)
8633 && (it
->line_wrap
!= WORD_WRAP
8636 result
= MOVE_NEWLINE_OR_CR
;
8643 IT_RESET_X_ASCENT_DESCENT (it
);
8645 if (wrap_it
.sp
>= 0)
8647 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8652 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8654 result
= MOVE_LINE_CONTINUED
;
8658 if (BUFFER_POS_REACHED_P ())
8660 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8661 goto buffer_pos_reached
;
8662 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8664 SAVE_IT (atpos_it
, *it
, atpos_data
);
8665 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8669 if (new_x
> it
->first_visible_x
)
8671 /* Glyph is visible. Increment number of glyphs that
8672 would be displayed. */
8677 if (result
!= MOVE_UNDEFINED
)
8680 else if (BUFFER_POS_REACHED_P ())
8683 IT_RESET_X_ASCENT_DESCENT (it
);
8684 result
= MOVE_POS_MATCH_OR_ZV
;
8687 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8689 /* Stop when TO_X specified and reached. This check is
8690 necessary here because of lines consisting of a line end,
8691 only. The line end will not produce any glyphs and we
8692 would never get MOVE_X_REACHED. */
8693 eassert (it
->nglyphs
== 0);
8694 result
= MOVE_X_REACHED
;
8698 /* Is this a line end? If yes, we're done. */
8699 if (ITERATOR_AT_END_OF_LINE_P (it
))
8701 /* If we are past TO_CHARPOS, but never saw any character
8702 positions smaller than TO_CHARPOS, return
8703 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8705 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8707 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8709 if (IT_CHARPOS (ppos_it
) < ZV
)
8711 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8712 result
= MOVE_POS_MATCH_OR_ZV
;
8715 goto buffer_pos_reached
;
8717 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8718 && IT_CHARPOS (*it
) > to_charpos
)
8719 goto buffer_pos_reached
;
8721 result
= MOVE_NEWLINE_OR_CR
;
8724 result
= MOVE_NEWLINE_OR_CR
;
8728 prev_method
= it
->method
;
8729 if (it
->method
== GET_FROM_BUFFER
)
8730 prev_pos
= IT_CHARPOS (*it
);
8731 /* The current display element has been consumed. Advance
8733 set_iterator_to_next (it
, 1);
8734 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8735 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8736 if (IT_CHARPOS (*it
) < to_charpos
)
8737 saw_smaller_pos
= 1;
8739 && (op
& MOVE_TO_POS
)
8740 && IT_CHARPOS (*it
) >= to_charpos
8741 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8742 SAVE_IT (ppos_it
, *it
, ppos_data
);
8744 /* Stop if lines are truncated and IT's current x-position is
8745 past the right edge of the window now. */
8746 if (it
->line_wrap
== TRUNCATE
8747 && it
->current_x
>= it
->last_visible_x
)
8749 if (!FRAME_WINDOW_P (it
->f
)
8750 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8751 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8752 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8753 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8757 if ((at_eob_p
= !get_next_display_element (it
))
8758 || BUFFER_POS_REACHED_P ()
8759 /* If we are past TO_CHARPOS, but never saw any
8760 character positions smaller than TO_CHARPOS,
8761 return MOVE_POS_MATCH_OR_ZV, like the
8762 unidirectional display did. */
8763 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8765 && IT_CHARPOS (*it
) > to_charpos
))
8768 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8769 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8770 result
= MOVE_POS_MATCH_OR_ZV
;
8773 if (ITERATOR_AT_END_OF_LINE_P (it
))
8775 result
= MOVE_NEWLINE_OR_CR
;
8779 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8781 && IT_CHARPOS (*it
) > to_charpos
)
8783 if (IT_CHARPOS (ppos_it
) < ZV
)
8784 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8785 result
= MOVE_POS_MATCH_OR_ZV
;
8788 result
= MOVE_LINE_TRUNCATED
;
8791 #undef IT_RESET_X_ASCENT_DESCENT
8794 #undef BUFFER_POS_REACHED_P
8796 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8797 restore the saved iterator. */
8798 if (atpos_it
.sp
>= 0)
8799 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8800 else if (atx_it
.sp
>= 0)
8801 RESTORE_IT (it
, &atx_it
, atx_data
);
8806 bidi_unshelve_cache (atpos_data
, 1);
8808 bidi_unshelve_cache (atx_data
, 1);
8810 bidi_unshelve_cache (wrap_data
, 1);
8812 bidi_unshelve_cache (ppos_data
, 1);
8814 /* Restore the iterator settings altered at the beginning of this
8816 it
->glyph_row
= saved_glyph_row
;
8820 /* For external use. */
8822 move_it_in_display_line (struct it
*it
,
8823 ptrdiff_t to_charpos
, int to_x
,
8824 enum move_operation_enum op
)
8826 if (it
->line_wrap
== WORD_WRAP
8827 && (op
& MOVE_TO_X
))
8830 void *save_data
= NULL
;
8833 SAVE_IT (save_it
, *it
, save_data
);
8834 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8835 /* When word-wrap is on, TO_X may lie past the end
8836 of a wrapped line. Then it->current is the
8837 character on the next line, so backtrack to the
8838 space before the wrap point. */
8839 if (skip
== MOVE_LINE_CONTINUED
)
8841 int prev_x
= max (it
->current_x
- 1, 0);
8842 RESTORE_IT (it
, &save_it
, save_data
);
8843 move_it_in_display_line_to
8844 (it
, -1, prev_x
, MOVE_TO_X
);
8847 bidi_unshelve_cache (save_data
, 1);
8850 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8854 /* Move IT forward until it satisfies one or more of the criteria in
8855 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8857 OP is a bit-mask that specifies where to stop, and in particular,
8858 which of those four position arguments makes a difference. See the
8859 description of enum move_operation_enum.
8861 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8862 screen line, this function will set IT to the next position that is
8863 displayed to the right of TO_CHARPOS on the screen.
8865 Return the maximum pixel length of any line scanned but never more
8866 than it.last_visible_x. */
8869 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8871 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8872 int line_height
, line_start_x
= 0, reached
= 0;
8873 int max_current_x
= 0;
8874 void *backup_data
= NULL
;
8878 if (op
& MOVE_TO_VPOS
)
8880 /* If no TO_CHARPOS and no TO_X specified, stop at the
8881 start of the line TO_VPOS. */
8882 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8884 if (it
->vpos
== to_vpos
)
8890 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8894 /* TO_VPOS >= 0 means stop at TO_X in the line at
8895 TO_VPOS, or at TO_POS, whichever comes first. */
8896 if (it
->vpos
== to_vpos
)
8902 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8904 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8909 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8911 /* We have reached TO_X but not in the line we want. */
8912 skip
= move_it_in_display_line_to (it
, to_charpos
,
8914 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8922 else if (op
& MOVE_TO_Y
)
8924 struct it it_backup
;
8926 if (it
->line_wrap
== WORD_WRAP
)
8927 SAVE_IT (it_backup
, *it
, backup_data
);
8929 /* TO_Y specified means stop at TO_X in the line containing
8930 TO_Y---or at TO_CHARPOS if this is reached first. The
8931 problem is that we can't really tell whether the line
8932 contains TO_Y before we have completely scanned it, and
8933 this may skip past TO_X. What we do is to first scan to
8936 If TO_X is not specified, use a TO_X of zero. The reason
8937 is to make the outcome of this function more predictable.
8938 If we didn't use TO_X == 0, we would stop at the end of
8939 the line which is probably not what a caller would expect
8941 skip
= move_it_in_display_line_to
8942 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8943 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8945 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8946 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8948 else if (skip
== MOVE_X_REACHED
)
8950 /* If TO_X was reached, we want to know whether TO_Y is
8951 in the line. We know this is the case if the already
8952 scanned glyphs make the line tall enough. Otherwise,
8953 we must check by scanning the rest of the line. */
8954 line_height
= it
->max_ascent
+ it
->max_descent
;
8955 if (to_y
>= it
->current_y
8956 && to_y
< it
->current_y
+ line_height
)
8961 SAVE_IT (it_backup
, *it
, backup_data
);
8962 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8963 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8965 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8966 line_height
= it
->max_ascent
+ it
->max_descent
;
8967 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8969 if (to_y
>= it
->current_y
8970 && to_y
< it
->current_y
+ line_height
)
8972 /* If TO_Y is in this line and TO_X was reached
8973 above, we scanned too far. We have to restore
8974 IT's settings to the ones before skipping. But
8975 keep the more accurate values of max_ascent and
8976 max_descent we've found while skipping the rest
8977 of the line, for the sake of callers, such as
8978 pos_visible_p, that need to know the line
8980 int max_ascent
= it
->max_ascent
;
8981 int max_descent
= it
->max_descent
;
8983 RESTORE_IT (it
, &it_backup
, backup_data
);
8984 it
->max_ascent
= max_ascent
;
8985 it
->max_descent
= max_descent
;
8991 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8997 /* Check whether TO_Y is in this line. */
8998 line_height
= it
->max_ascent
+ it
->max_descent
;
8999 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
9001 if (to_y
>= it
->current_y
9002 && to_y
< it
->current_y
+ line_height
)
9004 if (to_y
> it
->current_y
)
9005 max_current_x
= max (it
->current_x
, max_current_x
);
9007 /* When word-wrap is on, TO_X may lie past the end
9008 of a wrapped line. Then it->current is the
9009 character on the next line, so backtrack to the
9010 space before the wrap point. */
9011 if (skip
== MOVE_LINE_CONTINUED
9012 && it
->line_wrap
== WORD_WRAP
)
9014 int prev_x
= max (it
->current_x
- 1, 0);
9015 RESTORE_IT (it
, &it_backup
, backup_data
);
9016 skip
= move_it_in_display_line_to
9017 (it
, -1, prev_x
, MOVE_TO_X
);
9026 max_current_x
= max (it
->current_x
, max_current_x
);
9030 else if (BUFFERP (it
->object
)
9031 && (it
->method
== GET_FROM_BUFFER
9032 || it
->method
== GET_FROM_STRETCH
)
9033 && IT_CHARPOS (*it
) >= to_charpos
9034 /* Under bidi iteration, a call to set_iterator_to_next
9035 can scan far beyond to_charpos if the initial
9036 portion of the next line needs to be reordered. In
9037 that case, give move_it_in_display_line_to another
9040 && it
->bidi_it
.scan_dir
== -1))
9041 skip
= MOVE_POS_MATCH_OR_ZV
;
9043 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9047 case MOVE_POS_MATCH_OR_ZV
:
9048 max_current_x
= max (it
->current_x
, max_current_x
);
9052 case MOVE_NEWLINE_OR_CR
:
9053 max_current_x
= max (it
->current_x
, max_current_x
);
9054 set_iterator_to_next (it
, 1);
9055 it
->continuation_lines_width
= 0;
9058 case MOVE_LINE_TRUNCATED
:
9059 max_current_x
= it
->last_visible_x
;
9060 it
->continuation_lines_width
= 0;
9061 reseat_at_next_visible_line_start (it
, 0);
9062 if ((op
& MOVE_TO_POS
) != 0
9063 && IT_CHARPOS (*it
) > to_charpos
)
9070 case MOVE_LINE_CONTINUED
:
9071 max_current_x
= it
->last_visible_x
;
9072 /* For continued lines ending in a tab, some of the glyphs
9073 associated with the tab are displayed on the current
9074 line. Since it->current_x does not include these glyphs,
9075 we use it->last_visible_x instead. */
9078 it
->continuation_lines_width
+= it
->last_visible_x
;
9079 /* When moving by vpos, ensure that the iterator really
9080 advances to the next line (bug#847, bug#969). Fixme:
9081 do we need to do this in other circumstances? */
9082 if (it
->current_x
!= it
->last_visible_x
9083 && (op
& MOVE_TO_VPOS
)
9084 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9086 line_start_x
= it
->current_x
+ it
->pixel_width
9087 - it
->last_visible_x
;
9088 set_iterator_to_next (it
, 0);
9092 it
->continuation_lines_width
+= it
->current_x
;
9099 /* Reset/increment for the next run. */
9100 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9101 it
->current_x
= line_start_x
;
9104 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9106 last_height
= it
->max_ascent
+ it
->max_descent
;
9107 it
->max_ascent
= it
->max_descent
= 0;
9112 /* On text terminals, we may stop at the end of a line in the middle
9113 of a multi-character glyph. If the glyph itself is continued,
9114 i.e. it is actually displayed on the next line, don't treat this
9115 stopping point as valid; move to the next line instead (unless
9116 that brings us offscreen). */
9117 if (!FRAME_WINDOW_P (it
->f
)
9119 && IT_CHARPOS (*it
) == to_charpos
9120 && it
->what
== IT_CHARACTER
9122 && it
->line_wrap
== WINDOW_WRAP
9123 && it
->current_x
== it
->last_visible_x
- 1
9126 && it
->vpos
< it
->w
->window_end_vpos
)
9128 it
->continuation_lines_width
+= it
->current_x
;
9129 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9130 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9132 last_height
= it
->max_ascent
+ it
->max_descent
;
9136 bidi_unshelve_cache (backup_data
, 1);
9138 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9140 return max_current_x
;
9144 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9146 If DY > 0, move IT backward at least that many pixels. DY = 0
9147 means move IT backward to the preceding line start or BEGV. This
9148 function may move over more than DY pixels if IT->current_y - DY
9149 ends up in the middle of a line; in this case IT->current_y will be
9150 set to the top of the line moved to. */
9153 move_it_vertically_backward (struct it
*it
, int dy
)
9157 void *it2data
= NULL
, *it3data
= NULL
;
9158 ptrdiff_t start_pos
;
9160 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9161 ptrdiff_t pos_limit
;
9166 start_pos
= IT_CHARPOS (*it
);
9168 /* Estimate how many newlines we must move back. */
9169 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9170 if (it
->line_wrap
== TRUNCATE
)
9173 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9175 /* Set the iterator's position that many lines back. But don't go
9176 back more than NLINES full screen lines -- this wins a day with
9177 buffers which have very long lines. */
9178 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9179 back_to_previous_visible_line_start (it
);
9181 /* Reseat the iterator here. When moving backward, we don't want
9182 reseat to skip forward over invisible text, set up the iterator
9183 to deliver from overlay strings at the new position etc. So,
9184 use reseat_1 here. */
9185 reseat_1 (it
, it
->current
.pos
, 1);
9187 /* We are now surely at a line start. */
9188 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9189 reordering is in effect. */
9190 it
->continuation_lines_width
= 0;
9192 /* Move forward and see what y-distance we moved. First move to the
9193 start of the next line so that we get its height. We need this
9194 height to be able to tell whether we reached the specified
9196 SAVE_IT (it2
, *it
, it2data
);
9197 it2
.max_ascent
= it2
.max_descent
= 0;
9200 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9201 MOVE_TO_POS
| MOVE_TO_VPOS
);
9203 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9204 /* If we are in a display string which starts at START_POS,
9205 and that display string includes a newline, and we are
9206 right after that newline (i.e. at the beginning of a
9207 display line), exit the loop, because otherwise we will
9208 infloop, since move_it_to will see that it is already at
9209 START_POS and will not move. */
9210 || (it2
.method
== GET_FROM_STRING
9211 && IT_CHARPOS (it2
) == start_pos
9212 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9213 eassert (IT_CHARPOS (*it
) >= BEGV
);
9214 SAVE_IT (it3
, it2
, it3data
);
9216 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9217 eassert (IT_CHARPOS (*it
) >= BEGV
);
9218 /* H is the actual vertical distance from the position in *IT
9219 and the starting position. */
9220 h
= it2
.current_y
- it
->current_y
;
9221 /* NLINES is the distance in number of lines. */
9222 nlines
= it2
.vpos
- it
->vpos
;
9224 /* Correct IT's y and vpos position
9225 so that they are relative to the starting point. */
9231 /* DY == 0 means move to the start of the screen line. The
9232 value of nlines is > 0 if continuation lines were involved,
9233 or if the original IT position was at start of a line. */
9234 RESTORE_IT (it
, it
, it2data
);
9236 move_it_by_lines (it
, nlines
);
9237 /* The above code moves us to some position NLINES down,
9238 usually to its first glyph (leftmost in an L2R line), but
9239 that's not necessarily the start of the line, under bidi
9240 reordering. We want to get to the character position
9241 that is immediately after the newline of the previous
9244 && !it
->continuation_lines_width
9245 && !STRINGP (it
->string
)
9246 && IT_CHARPOS (*it
) > BEGV
9247 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9249 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9252 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9253 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9255 bidi_unshelve_cache (it3data
, 1);
9259 /* The y-position we try to reach, relative to *IT.
9260 Note that H has been subtracted in front of the if-statement. */
9261 int target_y
= it
->current_y
+ h
- dy
;
9262 int y0
= it3
.current_y
;
9266 RESTORE_IT (&it3
, &it3
, it3data
);
9267 y1
= line_bottom_y (&it3
);
9268 line_height
= y1
- y0
;
9269 RESTORE_IT (it
, it
, it2data
);
9270 /* If we did not reach target_y, try to move further backward if
9271 we can. If we moved too far backward, try to move forward. */
9272 if (target_y
< it
->current_y
9273 /* This is heuristic. In a window that's 3 lines high, with
9274 a line height of 13 pixels each, recentering with point
9275 on the bottom line will try to move -39/2 = 19 pixels
9276 backward. Try to avoid moving into the first line. */
9277 && (it
->current_y
- target_y
9278 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9279 && IT_CHARPOS (*it
) > BEGV
)
9281 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9282 target_y
- it
->current_y
));
9283 dy
= it
->current_y
- target_y
;
9284 goto move_further_back
;
9286 else if (target_y
>= it
->current_y
+ line_height
9287 && IT_CHARPOS (*it
) < ZV
)
9289 /* Should move forward by at least one line, maybe more.
9291 Note: Calling move_it_by_lines can be expensive on
9292 terminal frames, where compute_motion is used (via
9293 vmotion) to do the job, when there are very long lines
9294 and truncate-lines is nil. That's the reason for
9295 treating terminal frames specially here. */
9297 if (!FRAME_WINDOW_P (it
->f
))
9298 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9303 move_it_by_lines (it
, 1);
9305 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9312 /* Move IT by a specified amount of pixel lines DY. DY negative means
9313 move backwards. DY = 0 means move to start of screen line. At the
9314 end, IT will be on the start of a screen line. */
9317 move_it_vertically (struct it
*it
, int dy
)
9320 move_it_vertically_backward (it
, -dy
);
9323 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9324 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9325 MOVE_TO_POS
| MOVE_TO_Y
);
9326 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9328 /* If buffer ends in ZV without a newline, move to the start of
9329 the line to satisfy the post-condition. */
9330 if (IT_CHARPOS (*it
) == ZV
9332 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9333 move_it_by_lines (it
, 0);
9338 /* Move iterator IT past the end of the text line it is in. */
9341 move_it_past_eol (struct it
*it
)
9343 enum move_it_result rc
;
9345 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9346 if (rc
== MOVE_NEWLINE_OR_CR
)
9347 set_iterator_to_next (it
, 0);
9351 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9352 negative means move up. DVPOS == 0 means move to the start of the
9355 Optimization idea: If we would know that IT->f doesn't use
9356 a face with proportional font, we could be faster for
9357 truncate-lines nil. */
9360 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9363 /* The commented-out optimization uses vmotion on terminals. This
9364 gives bad results, because elements like it->what, on which
9365 callers such as pos_visible_p rely, aren't updated. */
9366 /* struct position pos;
9367 if (!FRAME_WINDOW_P (it->f))
9369 struct text_pos textpos;
9371 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9372 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9373 reseat (it, textpos, 1);
9374 it->vpos += pos.vpos;
9375 it->current_y += pos.vpos;
9381 /* DVPOS == 0 means move to the start of the screen line. */
9382 move_it_vertically_backward (it
, 0);
9383 /* Let next call to line_bottom_y calculate real line height. */
9388 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9389 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9391 /* Only move to the next buffer position if we ended up in a
9392 string from display property, not in an overlay string
9393 (before-string or after-string). That is because the
9394 latter don't conceal the underlying buffer position, so
9395 we can ask to move the iterator to the exact position we
9396 are interested in. Note that, even if we are already at
9397 IT_CHARPOS (*it), the call below is not a no-op, as it
9398 will detect that we are at the end of the string, pop the
9399 iterator, and compute it->current_x and it->hpos
9401 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9402 -1, -1, -1, MOVE_TO_POS
);
9408 void *it2data
= NULL
;
9409 ptrdiff_t start_charpos
, i
;
9411 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9412 ptrdiff_t pos_limit
;
9414 /* Start at the beginning of the screen line containing IT's
9415 position. This may actually move vertically backwards,
9416 in case of overlays, so adjust dvpos accordingly. */
9418 move_it_vertically_backward (it
, 0);
9421 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9422 screen lines, and reseat the iterator there. */
9423 start_charpos
= IT_CHARPOS (*it
);
9424 if (it
->line_wrap
== TRUNCATE
)
9427 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9428 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9429 back_to_previous_visible_line_start (it
);
9430 reseat (it
, it
->current
.pos
, 1);
9432 /* Move further back if we end up in a string or an image. */
9433 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9435 /* First try to move to start of display line. */
9437 move_it_vertically_backward (it
, 0);
9439 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9441 /* If start of line is still in string or image,
9442 move further back. */
9443 back_to_previous_visible_line_start (it
);
9444 reseat (it
, it
->current
.pos
, 1);
9448 it
->current_x
= it
->hpos
= 0;
9450 /* Above call may have moved too far if continuation lines
9451 are involved. Scan forward and see if it did. */
9452 SAVE_IT (it2
, *it
, it2data
);
9453 it2
.vpos
= it2
.current_y
= 0;
9454 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9455 it
->vpos
-= it2
.vpos
;
9456 it
->current_y
-= it2
.current_y
;
9457 it
->current_x
= it
->hpos
= 0;
9459 /* If we moved too far back, move IT some lines forward. */
9460 if (it2
.vpos
> -dvpos
)
9462 int delta
= it2
.vpos
+ dvpos
;
9464 RESTORE_IT (&it2
, &it2
, it2data
);
9465 SAVE_IT (it2
, *it
, it2data
);
9466 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9467 /* Move back again if we got too far ahead. */
9468 if (IT_CHARPOS (*it
) >= start_charpos
)
9469 RESTORE_IT (it
, &it2
, it2data
);
9471 bidi_unshelve_cache (it2data
, 1);
9474 RESTORE_IT (it
, it
, it2data
);
9478 /* Return true if IT points into the middle of a display vector. */
9481 in_display_vector_p (struct it
*it
)
9483 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9484 && it
->current
.dpvec_index
> 0
9485 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9488 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size
, Swindow_text_pixel_size
, 0, 6, 0,
9489 doc
: /* Return the size of the text of WINDOW's buffer in pixels.
9490 WINDOW must be a live window and defaults to the selected one. The
9491 return value is a cons of the maximum pixel-width of any text line and
9492 the maximum pixel-height of all text lines.
9494 The optional argument FROM, if non-nil, specifies the first text
9495 position and defaults to the minimum accessible position of the buffer.
9496 If FROM is t, use the minimum accessible position that is not a newline
9497 character. TO, if non-nil, specifies the last text position and
9498 defaults to the maximum accessible position of the buffer. If TO is t,
9499 use the maximum accessible position that is not a newline character.
9501 The optional argument X_LIMIT, if non-nil, specifies the maximum text
9502 width that can be returned. X_LIMIT nil or omitted, means to use the
9503 pixel-width of WINDOW's body; use this if you do not intend to change
9504 the width of WINDOW. Use the maximum width WINDOW may assume if you
9505 intend to change WINDOW's width.
9507 The optional argument Y_LIMIT, if non-nil, specifies the maximum text
9508 height that can be returned. Text lines whose y-coordinate is beyond
9509 Y_LIMIT are ignored. Since calculating the text height of a large
9510 buffer can take some time, it makes sense to specify this argument if
9511 the size of the buffer is unknown.
9513 Optional argument MODE_AND_HEADER_LINE nil or omitted means do not
9514 include the height of the mode- or header-line of WINDOW in the return
9515 value. If it is either the symbol `mode-line' or `header-line', include
9516 only the height of that line, if present, in the return value. If t,
9517 include the height of both, if present, in the return value. */)
9518 (Lisp_Object window
, Lisp_Object from
, Lisp_Object to
, Lisp_Object x_limit
, Lisp_Object y_limit
,
9519 Lisp_Object mode_and_header_line
)
9521 struct window
*w
= decode_live_window (window
);
9525 struct buffer
*old_buffer
= NULL
;
9526 ptrdiff_t start
, end
, pos
;
9527 struct text_pos startp
;
9528 void *itdata
= NULL
;
9529 int c
, max_y
= -1, x
= 0, y
= 0;
9535 if (b
!= current_buffer
)
9537 old_buffer
= current_buffer
;
9538 set_buffer_internal (b
);
9543 else if (EQ (from
, Qt
))
9546 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
))
9547 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9549 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9554 CHECK_NUMBER_COERCE_MARKER (from
);
9555 start
= min (max (XINT (from
), BEGV
), ZV
);
9560 else if (EQ (to
, Qt
))
9563 while ((pos
-- > BEGV
) && (c
= FETCH_CHAR (pos
))
9564 && (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r'))
9566 while ((pos
++ < ZV
) && (c
= FETCH_CHAR (pos
)) && (c
== ' ' || c
== '\t'))
9571 CHECK_NUMBER_COERCE_MARKER (to
);
9572 end
= max (start
, min (XINT (to
), ZV
));
9575 if (!NILP (y_limit
))
9577 CHECK_NUMBER (y_limit
);
9578 max_y
= min (XINT (y_limit
), INT_MAX
);
9581 itdata
= bidi_shelve_cache ();
9582 SET_TEXT_POS (startp
, start
, CHAR_TO_BYTE (start
));
9583 start_display (&it
, w
, startp
);
9586 x
= move_it_to (&it
, end
, -1, max_y
, -1, MOVE_TO_POS
| MOVE_TO_Y
);
9589 CHECK_NUMBER (x_limit
);
9590 it
.last_visible_x
= min (XINT (x_limit
), INFINITY
);
9591 /* Actually, we never want move_it_to stop at to_x. But to make
9592 sure that move_it_in_display_line_to always moves far enough,
9593 we set it to INT_MAX and specify MOVE_TO_X. */
9594 x
= move_it_to (&it
, end
, INT_MAX
, max_y
, -1,
9595 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
9598 y
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
9600 if (!EQ (mode_and_header_line
, Qheader_line
)
9601 && !EQ (mode_and_header_line
, Qt
))
9602 /* Do not count the header-line which was counted automatically by
9604 y
= y
- WINDOW_HEADER_LINE_HEIGHT (w
);
9606 if (EQ (mode_and_header_line
, Qmode_line
)
9607 || EQ (mode_and_header_line
, Qt
))
9608 /* Do count the mode-line which is not included automatically by
9610 y
= y
+ WINDOW_MODE_LINE_HEIGHT (w
);
9612 bidi_unshelve_cache (itdata
, 0);
9615 set_buffer_internal (old_buffer
);
9617 return Fcons (make_number (x
), make_number (y
));
9620 /***********************************************************************
9622 ***********************************************************************/
9625 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9629 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9631 Lisp_Object args
[3];
9632 Lisp_Object msg
, fmt
;
9635 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9639 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9641 args
[0] = fmt
= build_string (format
);
9644 msg
= Fformat (3, args
);
9646 len
= SBYTES (msg
) + 1;
9647 buffer
= SAFE_ALLOCA (len
);
9648 memcpy (buffer
, SDATA (msg
), len
);
9650 message_dolog (buffer
, len
- 1, 1, 0);
9657 /* Output a newline in the *Messages* buffer if "needs" one. */
9660 message_log_maybe_newline (void)
9662 if (message_log_need_newline
)
9663 message_dolog ("", 0, 1, 0);
9667 /* Add a string M of length NBYTES to the message log, optionally
9668 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9669 true, means interpret the contents of M as multibyte. This
9670 function calls low-level routines in order to bypass text property
9671 hooks, etc. which might not be safe to run.
9673 This may GC (insert may run before/after change hooks),
9674 so the buffer M must NOT point to a Lisp string. */
9677 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9679 const unsigned char *msg
= (const unsigned char *) m
;
9681 if (!NILP (Vmemory_full
))
9684 if (!NILP (Vmessage_log_max
))
9686 struct buffer
*oldbuf
;
9687 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9688 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9689 ptrdiff_t point_at_end
= 0;
9690 ptrdiff_t zv_at_end
= 0;
9691 Lisp_Object old_deactivate_mark
;
9692 struct gcpro gcpro1
;
9694 old_deactivate_mark
= Vdeactivate_mark
;
9695 oldbuf
= current_buffer
;
9697 /* Ensure the Messages buffer exists, and switch to it.
9698 If we created it, set the major-mode. */
9701 if (NILP (Fget_buffer (Vmessages_buffer_name
))) newbuffer
= 1;
9703 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9706 && !NILP (Ffboundp (intern ("messages-buffer-mode"))))
9707 call0 (intern ("messages-buffer-mode"));
9710 bset_undo_list (current_buffer
, Qt
);
9711 bset_cache_long_scans (current_buffer
, Qnil
);
9713 oldpoint
= message_dolog_marker1
;
9714 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9715 oldbegv
= message_dolog_marker2
;
9716 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9717 oldzv
= message_dolog_marker3
;
9718 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9719 GCPRO1 (old_deactivate_mark
);
9727 BEGV_BYTE
= BEG_BYTE
;
9730 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9732 /* Insert the string--maybe converting multibyte to single byte
9733 or vice versa, so that all the text fits the buffer. */
9735 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9741 /* Convert a multibyte string to single-byte
9742 for the *Message* buffer. */
9743 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9745 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9746 work
[0] = (ASCII_CHAR_P (c
)
9748 : multibyte_char_to_unibyte (c
));
9749 insert_1_both (work
, 1, 1, 1, 0, 0);
9752 else if (! multibyte
9753 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9757 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9758 /* Convert a single-byte string to multibyte
9759 for the *Message* buffer. */
9760 for (i
= 0; i
< nbytes
; i
++)
9763 MAKE_CHAR_MULTIBYTE (c
);
9764 char_bytes
= CHAR_STRING (c
, str
);
9765 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9769 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9773 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9776 insert_1_both ("\n", 1, 1, 1, 0, 0);
9778 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9780 this_bol_byte
= PT_BYTE
;
9782 /* See if this line duplicates the previous one.
9783 If so, combine duplicates. */
9786 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9788 prev_bol_byte
= PT_BYTE
;
9790 dups
= message_log_check_duplicate (prev_bol_byte
,
9794 del_range_both (prev_bol
, prev_bol_byte
,
9795 this_bol
, this_bol_byte
, 0);
9798 char dupstr
[sizeof " [ times]"
9799 + INT_STRLEN_BOUND (printmax_t
)];
9801 /* If you change this format, don't forget to also
9802 change message_log_check_duplicate. */
9803 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9804 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9805 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9810 /* If we have more than the desired maximum number of lines
9811 in the *Messages* buffer now, delete the oldest ones.
9812 This is safe because we don't have undo in this buffer. */
9814 if (NATNUMP (Vmessage_log_max
))
9816 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9817 -XFASTINT (Vmessage_log_max
) - 1, 0);
9818 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9821 BEGV
= marker_position (oldbegv
);
9822 BEGV_BYTE
= marker_byte_position (oldbegv
);
9831 ZV
= marker_position (oldzv
);
9832 ZV_BYTE
= marker_byte_position (oldzv
);
9836 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9838 /* We can't do Fgoto_char (oldpoint) because it will run some
9840 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9841 marker_byte_position (oldpoint
));
9844 unchain_marker (XMARKER (oldpoint
));
9845 unchain_marker (XMARKER (oldbegv
));
9846 unchain_marker (XMARKER (oldzv
));
9848 /* We called insert_1_both above with its 5th argument (PREPARE)
9849 zero, which prevents insert_1_both from calling
9850 prepare_to_modify_buffer, which in turns prevents us from
9851 incrementing windows_or_buffers_changed even if *Messages* is
9852 shown in some window. So we must manually set
9853 windows_or_buffers_changed here to make up for that. */
9854 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9855 bset_redisplay (current_buffer
);
9857 set_buffer_internal (oldbuf
);
9859 message_log_need_newline
= !nlflag
;
9860 Vdeactivate_mark
= old_deactivate_mark
;
9865 /* We are at the end of the buffer after just having inserted a newline.
9866 (Note: We depend on the fact we won't be crossing the gap.)
9867 Check to see if the most recent message looks a lot like the previous one.
9868 Return 0 if different, 1 if the new one should just replace it, or a
9869 value N > 1 if we should also append " [N times]". */
9872 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9875 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9877 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9878 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9880 for (i
= 0; i
< len
; i
++)
9882 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9890 if (*p1
++ == ' ' && *p1
++ == '[')
9893 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9894 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9901 /* Display an echo area message M with a specified length of NBYTES
9902 bytes. The string may include null characters. If M is not a
9903 string, clear out any existing message, and let the mini-buffer
9906 This function cancels echoing. */
9909 message3 (Lisp_Object m
)
9911 struct gcpro gcpro1
;
9914 clear_message (true, true);
9917 /* First flush out any partial line written with print. */
9918 message_log_maybe_newline ();
9921 ptrdiff_t nbytes
= SBYTES (m
);
9922 bool multibyte
= STRING_MULTIBYTE (m
);
9924 char *buffer
= SAFE_ALLOCA (nbytes
);
9925 memcpy (buffer
, SDATA (m
), nbytes
);
9926 message_dolog (buffer
, nbytes
, 1, multibyte
);
9935 /* The non-logging version of message3.
9936 This does not cancel echoing, because it is used for echoing.
9937 Perhaps we need to make a separate function for echoing
9938 and make this cancel echoing. */
9941 message3_nolog (Lisp_Object m
)
9943 struct frame
*sf
= SELECTED_FRAME ();
9945 if (FRAME_INITIAL_P (sf
))
9947 if (noninteractive_need_newline
)
9948 putc ('\n', stderr
);
9949 noninteractive_need_newline
= 0;
9952 Lisp_Object s
= ENCODE_SYSTEM (m
);
9954 fwrite (SDATA (s
), SBYTES (s
), 1, stderr
);
9956 if (cursor_in_echo_area
== 0)
9957 fprintf (stderr
, "\n");
9960 /* Error messages get reported properly by cmd_error, so this must be just an
9961 informative message; if the frame hasn't really been initialized yet, just
9963 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9965 /* Get the frame containing the mini-buffer
9966 that the selected frame is using. */
9967 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9968 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9969 struct frame
*f
= XFRAME (frame
);
9971 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9972 Fmake_frame_visible (frame
);
9974 if (STRINGP (m
) && SCHARS (m
) > 0)
9977 if (minibuffer_auto_raise
)
9978 Fraise_frame (frame
);
9979 /* Assume we are not echoing.
9980 (If we are, echo_now will override this.) */
9981 echo_message_buffer
= Qnil
;
9984 clear_message (true, true);
9986 do_pending_window_change (0);
9987 echo_area_display (1);
9988 do_pending_window_change (0);
9989 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9990 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9995 /* Display a null-terminated echo area message M. If M is 0, clear
9996 out any existing message, and let the mini-buffer text show through.
9998 The buffer M must continue to exist until after the echo area gets
9999 cleared or some other message gets displayed there. Do not pass
10000 text that is stored in a Lisp string. Do not pass text in a buffer
10001 that was alloca'd. */
10004 message1 (const char *m
)
10006 message3 (m
? build_unibyte_string (m
) : Qnil
);
10010 /* The non-logging counterpart of message1. */
10013 message1_nolog (const char *m
)
10015 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
10018 /* Display a message M which contains a single %s
10019 which gets replaced with STRING. */
10022 message_with_string (const char *m
, Lisp_Object string
, int log
)
10024 CHECK_STRING (string
);
10026 if (noninteractive
)
10030 /* ENCODE_SYSTEM below can GC and/or relocate the Lisp
10031 String whose data pointer might be passed to us in M. So
10032 we use a local copy. */
10033 char *fmt
= xstrdup (m
);
10035 if (noninteractive_need_newline
)
10036 putc ('\n', stderr
);
10037 noninteractive_need_newline
= 0;
10038 fprintf (stderr
, fmt
, SDATA (ENCODE_SYSTEM (string
)));
10039 if (!cursor_in_echo_area
)
10040 fprintf (stderr
, "\n");
10045 else if (INTERACTIVE
)
10047 /* The frame whose minibuffer we're going to display the message on.
10048 It may be larger than the selected frame, so we need
10049 to use its buffer, not the selected frame's buffer. */
10050 Lisp_Object mini_window
;
10051 struct frame
*f
, *sf
= SELECTED_FRAME ();
10053 /* Get the frame containing the minibuffer
10054 that the selected frame is using. */
10055 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10056 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10058 /* Error messages get reported properly by cmd_error, so this must be
10059 just an informative message; if the frame hasn't really been
10060 initialized yet, just toss it. */
10061 if (f
->glyphs_initialized_p
)
10063 Lisp_Object args
[2], msg
;
10064 struct gcpro gcpro1
, gcpro2
;
10066 args
[0] = build_string (m
);
10067 args
[1] = msg
= string
;
10068 GCPRO2 (args
[0], msg
);
10071 msg
= Fformat (2, args
);
10076 message3_nolog (msg
);
10080 /* Print should start at the beginning of the message
10081 buffer next time. */
10082 message_buf_print
= 0;
10088 /* Dump an informative message to the minibuf. If M is 0, clear out
10089 any existing message, and let the mini-buffer text show through. */
10092 vmessage (const char *m
, va_list ap
)
10094 if (noninteractive
)
10098 if (noninteractive_need_newline
)
10099 putc ('\n', stderr
);
10100 noninteractive_need_newline
= 0;
10101 vfprintf (stderr
, m
, ap
);
10102 if (cursor_in_echo_area
== 0)
10103 fprintf (stderr
, "\n");
10107 else if (INTERACTIVE
)
10109 /* The frame whose mini-buffer we're going to display the message
10110 on. It may be larger than the selected frame, so we need to
10111 use its buffer, not the selected frame's buffer. */
10112 Lisp_Object mini_window
;
10113 struct frame
*f
, *sf
= SELECTED_FRAME ();
10115 /* Get the frame containing the mini-buffer
10116 that the selected frame is using. */
10117 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10118 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
10120 /* Error messages get reported properly by cmd_error, so this must be
10121 just an informative message; if the frame hasn't really been
10122 initialized yet, just toss it. */
10123 if (f
->glyphs_initialized_p
)
10128 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
10129 char *message_buf
= alloca (maxsize
+ 1);
10131 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
10133 message3 (make_string (message_buf
, len
));
10138 /* Print should start at the beginning of the message
10139 buffer next time. */
10140 message_buf_print
= 0;
10146 message (const char *m
, ...)
10156 /* The non-logging version of message. */
10159 message_nolog (const char *m
, ...)
10161 Lisp_Object old_log_max
;
10164 old_log_max
= Vmessage_log_max
;
10165 Vmessage_log_max
= Qnil
;
10167 Vmessage_log_max
= old_log_max
;
10173 /* Display the current message in the current mini-buffer. This is
10174 only called from error handlers in process.c, and is not time
10178 update_echo_area (void)
10180 if (!NILP (echo_area_buffer
[0]))
10182 Lisp_Object string
;
10183 string
= Fcurrent_message ();
10189 /* Make sure echo area buffers in `echo_buffers' are live.
10190 If they aren't, make new ones. */
10193 ensure_echo_area_buffers (void)
10197 for (i
= 0; i
< 2; ++i
)
10198 if (!BUFFERP (echo_buffer
[i
])
10199 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10202 Lisp_Object old_buffer
;
10205 old_buffer
= echo_buffer
[i
];
10206 echo_buffer
[i
] = Fget_buffer_create
10207 (make_formatted_string (name
, " *Echo Area %d*", i
));
10208 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10209 /* to force word wrap in echo area -
10210 it was decided to postpone this*/
10211 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10213 for (j
= 0; j
< 2; ++j
)
10214 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10215 echo_area_buffer
[j
] = echo_buffer
[i
];
10220 /* Call FN with args A1..A2 with either the current or last displayed
10221 echo_area_buffer as current buffer.
10223 WHICH zero means use the current message buffer
10224 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10225 from echo_buffer[] and clear it.
10227 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10228 suitable buffer from echo_buffer[] and clear it.
10230 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10231 that the current message becomes the last displayed one, make
10232 choose a suitable buffer for echo_area_buffer[0], and clear it.
10234 Value is what FN returns. */
10237 with_echo_area_buffer (struct window
*w
, int which
,
10238 int (*fn
) (ptrdiff_t, Lisp_Object
),
10239 ptrdiff_t a1
, Lisp_Object a2
)
10241 Lisp_Object buffer
;
10242 int this_one
, the_other
, clear_buffer_p
, rc
;
10243 ptrdiff_t count
= SPECPDL_INDEX ();
10245 /* If buffers aren't live, make new ones. */
10246 ensure_echo_area_buffers ();
10248 clear_buffer_p
= 0;
10251 this_one
= 0, the_other
= 1;
10252 else if (which
> 0)
10253 this_one
= 1, the_other
= 0;
10256 this_one
= 0, the_other
= 1;
10257 clear_buffer_p
= true;
10259 /* We need a fresh one in case the current echo buffer equals
10260 the one containing the last displayed echo area message. */
10261 if (!NILP (echo_area_buffer
[this_one
])
10262 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10263 echo_area_buffer
[this_one
] = Qnil
;
10266 /* Choose a suitable buffer from echo_buffer[] is we don't
10268 if (NILP (echo_area_buffer
[this_one
]))
10270 echo_area_buffer
[this_one
]
10271 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10272 ? echo_buffer
[the_other
]
10273 : echo_buffer
[this_one
]);
10274 clear_buffer_p
= true;
10277 buffer
= echo_area_buffer
[this_one
];
10279 /* Don't get confused by reusing the buffer used for echoing
10280 for a different purpose. */
10281 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10284 record_unwind_protect (unwind_with_echo_area_buffer
,
10285 with_echo_area_buffer_unwind_data (w
));
10287 /* Make the echo area buffer current. Note that for display
10288 purposes, it is not necessary that the displayed window's buffer
10289 == current_buffer, except for text property lookup. So, let's
10290 only set that buffer temporarily here without doing a full
10291 Fset_window_buffer. We must also change w->pointm, though,
10292 because otherwise an assertions in unshow_buffer fails, and Emacs
10294 set_buffer_internal_1 (XBUFFER (buffer
));
10297 wset_buffer (w
, buffer
);
10298 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10301 bset_undo_list (current_buffer
, Qt
);
10302 bset_read_only (current_buffer
, Qnil
);
10303 specbind (Qinhibit_read_only
, Qt
);
10304 specbind (Qinhibit_modification_hooks
, Qt
);
10306 if (clear_buffer_p
&& Z
> BEG
)
10307 del_range (BEG
, Z
);
10309 eassert (BEGV
>= BEG
);
10310 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10314 eassert (BEGV
>= BEG
);
10315 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10317 unbind_to (count
, Qnil
);
10322 /* Save state that should be preserved around the call to the function
10323 FN called in with_echo_area_buffer. */
10326 with_echo_area_buffer_unwind_data (struct window
*w
)
10329 Lisp_Object vector
, tmp
;
10331 /* Reduce consing by keeping one vector in
10332 Vwith_echo_area_save_vector. */
10333 vector
= Vwith_echo_area_save_vector
;
10334 Vwith_echo_area_save_vector
= Qnil
;
10337 vector
= Fmake_vector (make_number (9), Qnil
);
10339 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10340 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10341 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10345 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10346 ASET (vector
, i
, w
->contents
); ++i
;
10347 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10348 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10349 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10350 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10355 for (; i
< end
; ++i
)
10356 ASET (vector
, i
, Qnil
);
10359 eassert (i
== ASIZE (vector
));
10364 /* Restore global state from VECTOR which was created by
10365 with_echo_area_buffer_unwind_data. */
10368 unwind_with_echo_area_buffer (Lisp_Object vector
)
10370 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10371 Vdeactivate_mark
= AREF (vector
, 1);
10372 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10374 if (WINDOWP (AREF (vector
, 3)))
10377 Lisp_Object buffer
;
10379 w
= XWINDOW (AREF (vector
, 3));
10380 buffer
= AREF (vector
, 4);
10382 wset_buffer (w
, buffer
);
10383 set_marker_both (w
->pointm
, buffer
,
10384 XFASTINT (AREF (vector
, 5)),
10385 XFASTINT (AREF (vector
, 6)));
10386 set_marker_both (w
->start
, buffer
,
10387 XFASTINT (AREF (vector
, 7)),
10388 XFASTINT (AREF (vector
, 8)));
10391 Vwith_echo_area_save_vector
= vector
;
10395 /* Set up the echo area for use by print functions. MULTIBYTE_P
10396 non-zero means we will print multibyte. */
10399 setup_echo_area_for_printing (int multibyte_p
)
10401 /* If we can't find an echo area any more, exit. */
10402 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10403 Fkill_emacs (Qnil
);
10405 ensure_echo_area_buffers ();
10407 if (!message_buf_print
)
10409 /* A message has been output since the last time we printed.
10410 Choose a fresh echo area buffer. */
10411 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10412 echo_area_buffer
[0] = echo_buffer
[1];
10414 echo_area_buffer
[0] = echo_buffer
[0];
10416 /* Switch to that buffer and clear it. */
10417 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10418 bset_truncate_lines (current_buffer
, Qnil
);
10422 ptrdiff_t count
= SPECPDL_INDEX ();
10423 specbind (Qinhibit_read_only
, Qt
);
10424 /* Note that undo recording is always disabled. */
10425 del_range (BEG
, Z
);
10426 unbind_to (count
, Qnil
);
10428 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10430 /* Set up the buffer for the multibyteness we need. */
10432 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10433 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10435 /* Raise the frame containing the echo area. */
10436 if (minibuffer_auto_raise
)
10438 struct frame
*sf
= SELECTED_FRAME ();
10439 Lisp_Object mini_window
;
10440 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10441 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10444 message_log_maybe_newline ();
10445 message_buf_print
= 1;
10449 if (NILP (echo_area_buffer
[0]))
10451 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10452 echo_area_buffer
[0] = echo_buffer
[1];
10454 echo_area_buffer
[0] = echo_buffer
[0];
10457 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10459 /* Someone switched buffers between print requests. */
10460 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10461 bset_truncate_lines (current_buffer
, Qnil
);
10467 /* Display an echo area message in window W. Value is non-zero if W's
10468 height is changed. If display_last_displayed_message_p is
10469 non-zero, display the message that was last displayed, otherwise
10470 display the current message. */
10473 display_echo_area (struct window
*w
)
10475 int i
, no_message_p
, window_height_changed_p
;
10477 /* Temporarily disable garbage collections while displaying the echo
10478 area. This is done because a GC can print a message itself.
10479 That message would modify the echo area buffer's contents while a
10480 redisplay of the buffer is going on, and seriously confuse
10482 ptrdiff_t count
= inhibit_garbage_collection ();
10484 /* If there is no message, we must call display_echo_area_1
10485 nevertheless because it resizes the window. But we will have to
10486 reset the echo_area_buffer in question to nil at the end because
10487 with_echo_area_buffer will sets it to an empty buffer. */
10488 i
= display_last_displayed_message_p
? 1 : 0;
10489 no_message_p
= NILP (echo_area_buffer
[i
]);
10491 window_height_changed_p
10492 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10493 display_echo_area_1
,
10494 (intptr_t) w
, Qnil
);
10497 echo_area_buffer
[i
] = Qnil
;
10499 unbind_to (count
, Qnil
);
10500 return window_height_changed_p
;
10504 /* Helper for display_echo_area. Display the current buffer which
10505 contains the current echo area message in window W, a mini-window,
10506 a pointer to which is passed in A1. A2..A4 are currently not used.
10507 Change the height of W so that all of the message is displayed.
10508 Value is non-zero if height of W was changed. */
10511 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10514 struct window
*w
= (struct window
*) i1
;
10515 Lisp_Object window
;
10516 struct text_pos start
;
10517 int window_height_changed_p
= 0;
10519 /* Do this before displaying, so that we have a large enough glyph
10520 matrix for the display. If we can't get enough space for the
10521 whole text, display the last N lines. That works by setting w->start. */
10522 window_height_changed_p
= resize_mini_window (w
, 0);
10524 /* Use the starting position chosen by resize_mini_window. */
10525 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10528 clear_glyph_matrix (w
->desired_matrix
);
10529 XSETWINDOW (window
, w
);
10530 try_window (window
, start
, 0);
10532 return window_height_changed_p
;
10536 /* Resize the echo area window to exactly the size needed for the
10537 currently displayed message, if there is one. If a mini-buffer
10538 is active, don't shrink it. */
10541 resize_echo_area_exactly (void)
10543 if (BUFFERP (echo_area_buffer
[0])
10544 && WINDOWP (echo_area_window
))
10546 struct window
*w
= XWINDOW (echo_area_window
);
10547 Lisp_Object resize_exactly
= (minibuf_level
== 0 ? Qt
: Qnil
);
10548 int resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10549 (intptr_t) w
, resize_exactly
);
10552 windows_or_buffers_changed
= 42;
10553 update_mode_lines
= 30;
10554 redisplay_internal ();
10560 /* Callback function for with_echo_area_buffer, when used from
10561 resize_echo_area_exactly. A1 contains a pointer to the window to
10562 resize, EXACTLY non-nil means resize the mini-window exactly to the
10563 size of the text displayed. A3 and A4 are not used. Value is what
10564 resize_mini_window returns. */
10567 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10570 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10574 /* Resize mini-window W to fit the size of its contents. EXACT_P
10575 means size the window exactly to the size needed. Otherwise, it's
10576 only enlarged until W's buffer is empty.
10578 Set W->start to the right place to begin display. If the whole
10579 contents fit, start at the beginning. Otherwise, start so as
10580 to make the end of the contents appear. This is particularly
10581 important for y-or-n-p, but seems desirable generally.
10583 Value is non-zero if the window height has been changed. */
10586 resize_mini_window (struct window
*w
, int exact_p
)
10588 struct frame
*f
= XFRAME (w
->frame
);
10589 int window_height_changed_p
= 0;
10591 eassert (MINI_WINDOW_P (w
));
10593 /* By default, start display at the beginning. */
10594 set_marker_both (w
->start
, w
->contents
,
10595 BUF_BEGV (XBUFFER (w
->contents
)),
10596 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10598 /* Don't resize windows while redisplaying a window; it would
10599 confuse redisplay functions when the size of the window they are
10600 displaying changes from under them. Such a resizing can happen,
10601 for instance, when which-func prints a long message while
10602 we are running fontification-functions. We're running these
10603 functions with safe_call which binds inhibit-redisplay to t. */
10604 if (!NILP (Vinhibit_redisplay
))
10607 /* Nil means don't try to resize. */
10608 if (NILP (Vresize_mini_windows
)
10609 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10612 if (!FRAME_MINIBUF_ONLY_P (f
))
10615 int total_height
= (WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_ROOT_WINDOW (f
)))
10616 + WINDOW_PIXEL_HEIGHT (w
));
10617 int unit
= FRAME_LINE_HEIGHT (f
);
10618 int height
, max_height
;
10619 struct text_pos start
;
10620 struct buffer
*old_current_buffer
= NULL
;
10622 if (current_buffer
!= XBUFFER (w
->contents
))
10624 old_current_buffer
= current_buffer
;
10625 set_buffer_internal (XBUFFER (w
->contents
));
10628 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10630 /* Compute the max. number of lines specified by the user. */
10631 if (FLOATP (Vmax_mini_window_height
))
10632 max_height
= XFLOATINT (Vmax_mini_window_height
) * total_height
;
10633 else if (INTEGERP (Vmax_mini_window_height
))
10634 max_height
= XINT (Vmax_mini_window_height
) * unit
;
10636 max_height
= total_height
/ 4;
10638 /* Correct that max. height if it's bogus. */
10639 max_height
= clip_to_bounds (unit
, max_height
, total_height
);
10641 /* Find out the height of the text in the window. */
10642 if (it
.line_wrap
== TRUNCATE
)
10647 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10648 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10649 height
= it
.current_y
+ last_height
;
10651 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10652 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10655 /* Compute a suitable window start. */
10656 if (height
> max_height
)
10658 height
= (max_height
/ unit
) * unit
;
10659 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10660 move_it_vertically_backward (&it
, height
- unit
);
10661 start
= it
.current
.pos
;
10664 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10665 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10667 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10669 /* Let it grow only, until we display an empty message, in which
10670 case the window shrinks again. */
10671 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10673 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10675 FRAME_WINDOWS_FROZEN (f
) = 1;
10676 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10677 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10679 else if (height
< WINDOW_PIXEL_HEIGHT (w
)
10680 && (exact_p
|| BEGV
== ZV
))
10682 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10684 FRAME_WINDOWS_FROZEN (f
) = 0;
10685 shrink_mini_window (w
, 1);
10686 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10691 /* Always resize to exact size needed. */
10692 if (height
> WINDOW_PIXEL_HEIGHT (w
))
10694 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10696 FRAME_WINDOWS_FROZEN (f
) = 1;
10697 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10698 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10700 else if (height
< WINDOW_PIXEL_HEIGHT (w
))
10702 int old_height
= WINDOW_PIXEL_HEIGHT (w
);
10704 FRAME_WINDOWS_FROZEN (f
) = 0;
10705 shrink_mini_window (w
, 1);
10709 FRAME_WINDOWS_FROZEN (f
) = 1;
10710 grow_mini_window (w
, height
- WINDOW_PIXEL_HEIGHT (w
), 1);
10713 window_height_changed_p
= WINDOW_PIXEL_HEIGHT (w
) != old_height
;
10717 if (old_current_buffer
)
10718 set_buffer_internal (old_current_buffer
);
10721 return window_height_changed_p
;
10725 /* Value is the current message, a string, or nil if there is no
10726 current message. */
10729 current_message (void)
10733 if (!BUFFERP (echo_area_buffer
[0]))
10737 with_echo_area_buffer (0, 0, current_message_1
,
10738 (intptr_t) &msg
, Qnil
);
10740 echo_area_buffer
[0] = Qnil
;
10748 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10751 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10754 *msg
= make_buffer_string (BEG
, Z
, 1);
10761 /* Push the current message on Vmessage_stack for later restoration
10762 by restore_message. Value is non-zero if the current message isn't
10763 empty. This is a relatively infrequent operation, so it's not
10764 worth optimizing. */
10767 push_message (void)
10769 Lisp_Object msg
= current_message ();
10770 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10771 return STRINGP (msg
);
10775 /* Restore message display from the top of Vmessage_stack. */
10778 restore_message (void)
10780 eassert (CONSP (Vmessage_stack
));
10781 message3_nolog (XCAR (Vmessage_stack
));
10785 /* Handler for unwind-protect calling pop_message. */
10788 pop_message_unwind (void)
10790 /* Pop the top-most entry off Vmessage_stack. */
10791 eassert (CONSP (Vmessage_stack
));
10792 Vmessage_stack
= XCDR (Vmessage_stack
);
10796 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10797 exits. If the stack is not empty, we have a missing pop_message
10801 check_message_stack (void)
10803 if (!NILP (Vmessage_stack
))
10808 /* Truncate to NCHARS what will be displayed in the echo area the next
10809 time we display it---but don't redisplay it now. */
10812 truncate_echo_area (ptrdiff_t nchars
)
10815 echo_area_buffer
[0] = Qnil
;
10816 else if (!noninteractive
10818 && !NILP (echo_area_buffer
[0]))
10820 struct frame
*sf
= SELECTED_FRAME ();
10821 /* Error messages get reported properly by cmd_error, so this must be
10822 just an informative message; if the frame hasn't really been
10823 initialized yet, just toss it. */
10824 if (sf
->glyphs_initialized_p
)
10825 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10830 /* Helper function for truncate_echo_area. Truncate the current
10831 message to at most NCHARS characters. */
10834 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10836 if (BEG
+ nchars
< Z
)
10837 del_range (BEG
+ nchars
, Z
);
10839 echo_area_buffer
[0] = Qnil
;
10843 /* Set the current message to STRING. */
10846 set_message (Lisp_Object string
)
10848 eassert (STRINGP (string
));
10850 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10852 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10853 message_buf_print
= 0;
10854 help_echo_showing_p
= 0;
10856 if (STRINGP (Vdebug_on_message
)
10857 && STRINGP (string
)
10858 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10859 call_debugger (list2 (Qerror
, string
));
10863 /* Helper function for set_message. First argument is ignored and second
10864 argument has the same meaning as for set_message.
10865 This function is called with the echo area buffer being current. */
10868 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10870 eassert (STRINGP (string
));
10872 /* Change multibyteness of the echo buffer appropriately. */
10873 if (message_enable_multibyte
10874 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10875 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10877 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10878 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10879 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10881 /* Insert new message at BEG. */
10882 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10884 /* This function takes care of single/multibyte conversion.
10885 We just have to ensure that the echo area buffer has the right
10886 setting of enable_multibyte_characters. */
10887 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10893 /* Clear messages. CURRENT_P non-zero means clear the current
10894 message. LAST_DISPLAYED_P non-zero means clear the message
10898 clear_message (bool current_p
, bool last_displayed_p
)
10902 echo_area_buffer
[0] = Qnil
;
10903 message_cleared_p
= true;
10906 if (last_displayed_p
)
10907 echo_area_buffer
[1] = Qnil
;
10909 message_buf_print
= 0;
10912 /* Clear garbaged frames.
10914 This function is used where the old redisplay called
10915 redraw_garbaged_frames which in turn called redraw_frame which in
10916 turn called clear_frame. The call to clear_frame was a source of
10917 flickering. I believe a clear_frame is not necessary. It should
10918 suffice in the new redisplay to invalidate all current matrices,
10919 and ensure a complete redisplay of all windows. */
10922 clear_garbaged_frames (void)
10924 if (frame_garbaged
)
10926 Lisp_Object tail
, frame
;
10928 FOR_EACH_FRAME (tail
, frame
)
10930 struct frame
*f
= XFRAME (frame
);
10932 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10937 clear_current_matrices (f
);
10938 fset_redisplay (f
);
10939 f
->garbaged
= false;
10940 f
->resized_p
= false;
10944 frame_garbaged
= false;
10949 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10950 is non-zero update selected_frame. Value is non-zero if the
10951 mini-windows height has been changed. */
10954 echo_area_display (int update_frame_p
)
10956 Lisp_Object mini_window
;
10959 int window_height_changed_p
= 0;
10960 struct frame
*sf
= SELECTED_FRAME ();
10962 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10963 w
= XWINDOW (mini_window
);
10964 f
= XFRAME (WINDOW_FRAME (w
));
10966 /* Don't display if frame is invisible or not yet initialized. */
10967 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10970 #ifdef HAVE_WINDOW_SYSTEM
10971 /* When Emacs starts, selected_frame may be the initial terminal
10972 frame. If we let this through, a message would be displayed on
10974 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10976 #endif /* HAVE_WINDOW_SYSTEM */
10978 /* Redraw garbaged frames. */
10979 clear_garbaged_frames ();
10981 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10983 echo_area_window
= mini_window
;
10984 window_height_changed_p
= display_echo_area (w
);
10985 w
->must_be_updated_p
= true;
10987 /* Update the display, unless called from redisplay_internal.
10988 Also don't update the screen during redisplay itself. The
10989 update will happen at the end of redisplay, and an update
10990 here could cause confusion. */
10991 if (update_frame_p
&& !redisplaying_p
)
10995 /* If the display update has been interrupted by pending
10996 input, update mode lines in the frame. Due to the
10997 pending input, it might have been that redisplay hasn't
10998 been called, so that mode lines above the echo area are
10999 garbaged. This looks odd, so we prevent it here. */
11000 if (!display_completed
)
11001 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), false);
11003 if (window_height_changed_p
11004 /* Don't do this if Emacs is shutting down. Redisplay
11005 needs to run hooks. */
11006 && !NILP (Vrun_hooks
))
11008 /* Must update other windows. Likewise as in other
11009 cases, don't let this update be interrupted by
11011 ptrdiff_t count
= SPECPDL_INDEX ();
11012 specbind (Qredisplay_dont_pause
, Qt
);
11013 windows_or_buffers_changed
= 44;
11014 redisplay_internal ();
11015 unbind_to (count
, Qnil
);
11017 else if (FRAME_WINDOW_P (f
) && n
== 0)
11019 /* Window configuration is the same as before.
11020 Can do with a display update of the echo area,
11021 unless we displayed some mode lines. */
11022 update_single_window (w
, 1);
11026 update_frame (f
, 1, 1);
11028 /* If cursor is in the echo area, make sure that the next
11029 redisplay displays the minibuffer, so that the cursor will
11030 be replaced with what the minibuffer wants. */
11031 if (cursor_in_echo_area
)
11032 wset_redisplay (XWINDOW (mini_window
));
11035 else if (!EQ (mini_window
, selected_window
))
11036 wset_redisplay (XWINDOW (mini_window
));
11038 /* Last displayed message is now the current message. */
11039 echo_area_buffer
[1] = echo_area_buffer
[0];
11040 /* Inform read_char that we're not echoing. */
11041 echo_message_buffer
= Qnil
;
11043 /* Prevent redisplay optimization in redisplay_internal by resetting
11044 this_line_start_pos. This is done because the mini-buffer now
11045 displays the message instead of its buffer text. */
11046 if (EQ (mini_window
, selected_window
))
11047 CHARPOS (this_line_start_pos
) = 0;
11049 return window_height_changed_p
;
11052 /* Nonzero if W's buffer was changed but not saved. */
11055 window_buffer_changed (struct window
*w
)
11057 struct buffer
*b
= XBUFFER (w
->contents
);
11059 eassert (BUFFER_LIVE_P (b
));
11061 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
));
11064 /* Nonzero if W has %c in its mode line and mode line should be updated. */
11067 mode_line_update_needed (struct window
*w
)
11069 return (w
->column_number_displayed
!= -1
11070 && !(PT
== w
->last_point
&& !window_outdated (w
))
11071 && (w
->column_number_displayed
!= current_column ()));
11074 /* Nonzero if window start of W is frozen and may not be changed during
11078 window_frozen_p (struct window
*w
)
11080 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
11082 Lisp_Object window
;
11084 XSETWINDOW (window
, w
);
11085 if (MINI_WINDOW_P (w
))
11087 else if (EQ (window
, selected_window
))
11089 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
11090 && EQ (window
, Vminibuf_scroll_window
))
11091 /* This special window can't be frozen too. */
11099 /***********************************************************************
11100 Mode Lines and Frame Titles
11101 ***********************************************************************/
11103 /* A buffer for constructing non-propertized mode-line strings and
11104 frame titles in it; allocated from the heap in init_xdisp and
11105 resized as needed in store_mode_line_noprop_char. */
11107 static char *mode_line_noprop_buf
;
11109 /* The buffer's end, and a current output position in it. */
11111 static char *mode_line_noprop_buf_end
;
11112 static char *mode_line_noprop_ptr
;
11114 #define MODE_LINE_NOPROP_LEN(start) \
11115 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
11118 MODE_LINE_DISPLAY
= 0,
11122 } mode_line_target
;
11124 /* Alist that caches the results of :propertize.
11125 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
11126 static Lisp_Object mode_line_proptrans_alist
;
11128 /* List of strings making up the mode-line. */
11129 static Lisp_Object mode_line_string_list
;
11131 /* Base face property when building propertized mode line string. */
11132 static Lisp_Object mode_line_string_face
;
11133 static Lisp_Object mode_line_string_face_prop
;
11136 /* Unwind data for mode line strings */
11138 static Lisp_Object Vmode_line_unwind_vector
;
11141 format_mode_line_unwind_data (struct frame
*target_frame
,
11142 struct buffer
*obuf
,
11144 int save_proptrans
)
11146 Lisp_Object vector
, tmp
;
11148 /* Reduce consing by keeping one vector in
11149 Vwith_echo_area_save_vector. */
11150 vector
= Vmode_line_unwind_vector
;
11151 Vmode_line_unwind_vector
= Qnil
;
11154 vector
= Fmake_vector (make_number (10), Qnil
);
11156 ASET (vector
, 0, make_number (mode_line_target
));
11157 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11158 ASET (vector
, 2, mode_line_string_list
);
11159 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11160 ASET (vector
, 4, mode_line_string_face
);
11161 ASET (vector
, 5, mode_line_string_face_prop
);
11164 XSETBUFFER (tmp
, obuf
);
11167 ASET (vector
, 6, tmp
);
11168 ASET (vector
, 7, owin
);
11171 /* Similarly to `with-selected-window', if the operation selects
11172 a window on another frame, we must restore that frame's
11173 selected window, and (for a tty) the top-frame. */
11174 ASET (vector
, 8, target_frame
->selected_window
);
11175 if (FRAME_TERMCAP_P (target_frame
))
11176 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11183 unwind_format_mode_line (Lisp_Object vector
)
11185 Lisp_Object old_window
= AREF (vector
, 7);
11186 Lisp_Object target_frame_window
= AREF (vector
, 8);
11187 Lisp_Object old_top_frame
= AREF (vector
, 9);
11189 mode_line_target
= XINT (AREF (vector
, 0));
11190 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11191 mode_line_string_list
= AREF (vector
, 2);
11192 if (! EQ (AREF (vector
, 3), Qt
))
11193 mode_line_proptrans_alist
= AREF (vector
, 3);
11194 mode_line_string_face
= AREF (vector
, 4);
11195 mode_line_string_face_prop
= AREF (vector
, 5);
11197 /* Select window before buffer, since it may change the buffer. */
11198 if (!NILP (old_window
))
11200 /* If the operation that we are unwinding had selected a window
11201 on a different frame, reset its frame-selected-window. For a
11202 text terminal, reset its top-frame if necessary. */
11203 if (!NILP (target_frame_window
))
11206 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11208 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11209 Fselect_window (target_frame_window
, Qt
);
11211 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11212 Fselect_frame (old_top_frame
, Qt
);
11215 Fselect_window (old_window
, Qt
);
11218 if (!NILP (AREF (vector
, 6)))
11220 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11221 ASET (vector
, 6, Qnil
);
11224 Vmode_line_unwind_vector
= vector
;
11228 /* Store a single character C for the frame title in mode_line_noprop_buf.
11229 Re-allocate mode_line_noprop_buf if necessary. */
11232 store_mode_line_noprop_char (char c
)
11234 /* If output position has reached the end of the allocated buffer,
11235 increase the buffer's size. */
11236 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11238 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11239 ptrdiff_t size
= len
;
11240 mode_line_noprop_buf
=
11241 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11242 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11243 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11246 *mode_line_noprop_ptr
++ = c
;
11250 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11251 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11252 characters that yield more columns than PRECISION; PRECISION <= 0
11253 means copy the whole string. Pad with spaces until FIELD_WIDTH
11254 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11255 pad. Called from display_mode_element when it is used to build a
11259 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11261 const unsigned char *str
= (const unsigned char *) string
;
11263 ptrdiff_t dummy
, nbytes
;
11265 /* Copy at most PRECISION chars from STR. */
11266 nbytes
= strlen (string
);
11267 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11269 store_mode_line_noprop_char (*str
++);
11271 /* Fill up with spaces until FIELD_WIDTH reached. */
11272 while (field_width
> 0
11273 && n
< field_width
)
11275 store_mode_line_noprop_char (' ');
11282 /***********************************************************************
11284 ***********************************************************************/
11286 #ifdef HAVE_WINDOW_SYSTEM
11288 /* Set the title of FRAME, if it has changed. The title format is
11289 Vicon_title_format if FRAME is iconified, otherwise it is
11290 frame_title_format. */
11293 x_consider_frame_title (Lisp_Object frame
)
11295 struct frame
*f
= XFRAME (frame
);
11297 if (FRAME_WINDOW_P (f
)
11298 || FRAME_MINIBUF_ONLY_P (f
)
11299 || f
->explicit_name
)
11301 /* Do we have more than one visible frame on this X display? */
11302 Lisp_Object tail
, other_frame
, fmt
;
11303 ptrdiff_t title_start
;
11307 ptrdiff_t count
= SPECPDL_INDEX ();
11309 FOR_EACH_FRAME (tail
, other_frame
)
11311 struct frame
*tf
= XFRAME (other_frame
);
11314 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11315 && !FRAME_MINIBUF_ONLY_P (tf
)
11316 && !EQ (other_frame
, tip_frame
)
11317 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11321 /* Set global variable indicating that multiple frames exist. */
11322 multiple_frames
= CONSP (tail
);
11324 /* Switch to the buffer of selected window of the frame. Set up
11325 mode_line_target so that display_mode_element will output into
11326 mode_line_noprop_buf; then display the title. */
11327 record_unwind_protect (unwind_format_mode_line
,
11328 format_mode_line_unwind_data
11329 (f
, current_buffer
, selected_window
, 0));
11331 Fselect_window (f
->selected_window
, Qt
);
11332 set_buffer_internal_1
11333 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11334 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11336 mode_line_target
= MODE_LINE_TITLE
;
11337 title_start
= MODE_LINE_NOPROP_LEN (0);
11338 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11339 NULL
, DEFAULT_FACE_ID
);
11340 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11341 len
= MODE_LINE_NOPROP_LEN (title_start
);
11342 title
= mode_line_noprop_buf
+ title_start
;
11343 unbind_to (count
, Qnil
);
11345 /* Set the title only if it's changed. This avoids consing in
11346 the common case where it hasn't. (If it turns out that we've
11347 already wasted too much time by walking through the list with
11348 display_mode_element, then we might need to optimize at a
11349 higher level than this.) */
11350 if (! STRINGP (f
->name
)
11351 || SBYTES (f
->name
) != len
11352 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11353 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11357 #endif /* not HAVE_WINDOW_SYSTEM */
11360 /***********************************************************************
11362 ***********************************************************************/
11364 /* Non-zero if we will not redisplay all visible windows. */
11365 #define REDISPLAY_SOME_P() \
11366 ((windows_or_buffers_changed == 0 \
11367 || windows_or_buffers_changed == REDISPLAY_SOME) \
11368 && (update_mode_lines == 0 \
11369 || update_mode_lines == REDISPLAY_SOME))
11371 /* Prepare for redisplay by updating menu-bar item lists when
11372 appropriate. This can call eval. */
11375 prepare_menu_bars (void)
11377 bool all_windows
= windows_or_buffers_changed
|| update_mode_lines
;
11378 bool some_windows
= REDISPLAY_SOME_P ();
11379 struct gcpro gcpro1
, gcpro2
;
11380 Lisp_Object tooltip_frame
;
11382 #ifdef HAVE_WINDOW_SYSTEM
11383 tooltip_frame
= tip_frame
;
11385 tooltip_frame
= Qnil
;
11388 if (FUNCTIONP (Vpre_redisplay_function
))
11390 Lisp_Object windows
= all_windows
? Qt
: Qnil
;
11391 if (all_windows
&& some_windows
)
11393 Lisp_Object ws
= window_list ();
11394 for (windows
= Qnil
; CONSP (ws
); ws
= XCDR (ws
))
11396 Lisp_Object
this = XCAR (ws
);
11397 struct window
*w
= XWINDOW (this);
11399 || XFRAME (w
->frame
)->redisplay
11400 || XBUFFER (w
->contents
)->text
->redisplay
)
11402 windows
= Fcons (this, windows
);
11406 safe_call1 (Vpre_redisplay_function
, windows
);
11409 /* Update all frame titles based on their buffer names, etc. We do
11410 this before the menu bars so that the buffer-menu will show the
11411 up-to-date frame titles. */
11412 #ifdef HAVE_WINDOW_SYSTEM
11415 Lisp_Object tail
, frame
;
11417 FOR_EACH_FRAME (tail
, frame
)
11419 struct frame
*f
= XFRAME (frame
);
11420 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11424 && !XBUFFER (w
->contents
)->text
->redisplay
)
11427 if (!EQ (frame
, tooltip_frame
)
11428 && (FRAME_ICONIFIED_P (f
)
11429 || FRAME_VISIBLE_P (f
) == 1
11430 /* Exclude TTY frames that are obscured because they
11431 are not the top frame on their console. This is
11432 because x_consider_frame_title actually switches
11433 to the frame, which for TTY frames means it is
11434 marked as garbaged, and will be completely
11435 redrawn on the next redisplay cycle. This causes
11436 TTY frames to be completely redrawn, when there
11437 are more than one of them, even though nothing
11438 should be changed on display. */
11439 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11440 x_consider_frame_title (frame
);
11443 #endif /* HAVE_WINDOW_SYSTEM */
11445 /* Update the menu bar item lists, if appropriate. This has to be
11446 done before any actual redisplay or generation of display lines. */
11450 Lisp_Object tail
, frame
;
11451 ptrdiff_t count
= SPECPDL_INDEX ();
11452 /* 1 means that update_menu_bar has run its hooks
11453 so any further calls to update_menu_bar shouldn't do so again. */
11454 int menu_bar_hooks_run
= 0;
11456 record_unwind_save_match_data ();
11458 FOR_EACH_FRAME (tail
, frame
)
11460 struct frame
*f
= XFRAME (frame
);
11461 struct window
*w
= XWINDOW (FRAME_SELECTED_WINDOW (f
));
11463 /* Ignore tooltip frame. */
11464 if (EQ (frame
, tooltip_frame
))
11470 && !XBUFFER (w
->contents
)->text
->redisplay
)
11473 /* If a window on this frame changed size, report that to
11474 the user and clear the size-change flag. */
11475 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11477 Lisp_Object functions
;
11479 /* Clear flag first in case we get an error below. */
11480 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11481 functions
= Vwindow_size_change_functions
;
11482 GCPRO2 (tail
, functions
);
11484 while (CONSP (functions
))
11486 if (!EQ (XCAR (functions
), Qt
))
11487 call1 (XCAR (functions
), frame
);
11488 functions
= XCDR (functions
);
11494 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11495 #ifdef HAVE_WINDOW_SYSTEM
11496 update_tool_bar (f
, 0);
11499 if (windows_or_buffers_changed
11502 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11507 unbind_to (count
, Qnil
);
11511 struct frame
*sf
= SELECTED_FRAME ();
11512 update_menu_bar (sf
, 1, 0);
11513 #ifdef HAVE_WINDOW_SYSTEM
11514 update_tool_bar (sf
, 1);
11520 /* Update the menu bar item list for frame F. This has to be done
11521 before we start to fill in any display lines, because it can call
11524 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11526 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11527 already ran the menu bar hooks for this redisplay, so there
11528 is no need to run them again. The return value is the
11529 updated value of this flag, to pass to the next call. */
11532 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11534 Lisp_Object window
;
11535 register struct window
*w
;
11537 /* If called recursively during a menu update, do nothing. This can
11538 happen when, for instance, an activate-menubar-hook causes a
11540 if (inhibit_menubar_update
)
11543 window
= FRAME_SELECTED_WINDOW (f
);
11544 w
= XWINDOW (window
);
11546 if (FRAME_WINDOW_P (f
)
11548 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11549 || defined (HAVE_NS) || defined (USE_GTK)
11550 FRAME_EXTERNAL_MENU_BAR (f
)
11552 FRAME_MENU_BAR_LINES (f
) > 0
11554 : FRAME_MENU_BAR_LINES (f
) > 0)
11556 /* If the user has switched buffers or windows, we need to
11557 recompute to reflect the new bindings. But we'll
11558 recompute when update_mode_lines is set too; that means
11559 that people can use force-mode-line-update to request
11560 that the menu bar be recomputed. The adverse effect on
11561 the rest of the redisplay algorithm is about the same as
11562 windows_or_buffers_changed anyway. */
11563 if (windows_or_buffers_changed
11564 /* This used to test w->update_mode_line, but we believe
11565 there is no need to recompute the menu in that case. */
11566 || update_mode_lines
11567 || window_buffer_changed (w
))
11569 struct buffer
*prev
= current_buffer
;
11570 ptrdiff_t count
= SPECPDL_INDEX ();
11572 specbind (Qinhibit_menubar_update
, Qt
);
11574 set_buffer_internal_1 (XBUFFER (w
->contents
));
11575 if (save_match_data
)
11576 record_unwind_save_match_data ();
11577 if (NILP (Voverriding_local_map_menu_flag
))
11579 specbind (Qoverriding_terminal_local_map
, Qnil
);
11580 specbind (Qoverriding_local_map
, Qnil
);
11585 /* Run the Lucid hook. */
11586 safe_run_hooks (Qactivate_menubar_hook
);
11588 /* If it has changed current-menubar from previous value,
11589 really recompute the menu-bar from the value. */
11590 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11591 call0 (Qrecompute_lucid_menubar
);
11593 safe_run_hooks (Qmenu_bar_update_hook
);
11598 XSETFRAME (Vmenu_updating_frame
, f
);
11599 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11601 /* Redisplay the menu bar in case we changed it. */
11602 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11603 || defined (HAVE_NS) || defined (USE_GTK)
11604 if (FRAME_WINDOW_P (f
))
11606 #if defined (HAVE_NS)
11607 /* All frames on Mac OS share the same menubar. So only
11608 the selected frame should be allowed to set it. */
11609 if (f
== SELECTED_FRAME ())
11611 set_frame_menubar (f
, 0, 0);
11614 /* On a terminal screen, the menu bar is an ordinary screen
11615 line, and this makes it get updated. */
11616 w
->update_mode_line
= 1;
11617 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11618 /* In the non-toolkit version, the menu bar is an ordinary screen
11619 line, and this makes it get updated. */
11620 w
->update_mode_line
= 1;
11621 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11623 unbind_to (count
, Qnil
);
11624 set_buffer_internal_1 (prev
);
11631 /***********************************************************************
11633 ***********************************************************************/
11635 #ifdef HAVE_WINDOW_SYSTEM
11637 /* Tool-bar item index of the item on which a mouse button was pressed
11640 int last_tool_bar_item
;
11642 /* Select `frame' temporarily without running all the code in
11644 FIXME: Maybe do_switch_frame should be trimmed down similarly
11645 when `norecord' is set. */
11647 fast_set_selected_frame (Lisp_Object frame
)
11649 if (!EQ (selected_frame
, frame
))
11651 selected_frame
= frame
;
11652 selected_window
= XFRAME (frame
)->selected_window
;
11656 /* Update the tool-bar item list for frame F. This has to be done
11657 before we start to fill in any display lines. Called from
11658 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11659 and restore it here. */
11662 update_tool_bar (struct frame
*f
, int save_match_data
)
11664 #if defined (USE_GTK) || defined (HAVE_NS)
11665 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11667 int do_update
= (WINDOWP (f
->tool_bar_window
)
11668 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0);
11673 Lisp_Object window
;
11676 window
= FRAME_SELECTED_WINDOW (f
);
11677 w
= XWINDOW (window
);
11679 /* If the user has switched buffers or windows, we need to
11680 recompute to reflect the new bindings. But we'll
11681 recompute when update_mode_lines is set too; that means
11682 that people can use force-mode-line-update to request
11683 that the menu bar be recomputed. The adverse effect on
11684 the rest of the redisplay algorithm is about the same as
11685 windows_or_buffers_changed anyway. */
11686 if (windows_or_buffers_changed
11687 || w
->update_mode_line
11688 || update_mode_lines
11689 || window_buffer_changed (w
))
11691 struct buffer
*prev
= current_buffer
;
11692 ptrdiff_t count
= SPECPDL_INDEX ();
11693 Lisp_Object frame
, new_tool_bar
;
11694 int new_n_tool_bar
;
11695 struct gcpro gcpro1
;
11697 /* Set current_buffer to the buffer of the selected
11698 window of the frame, so that we get the right local
11700 set_buffer_internal_1 (XBUFFER (w
->contents
));
11702 /* Save match data, if we must. */
11703 if (save_match_data
)
11704 record_unwind_save_match_data ();
11706 /* Make sure that we don't accidentally use bogus keymaps. */
11707 if (NILP (Voverriding_local_map_menu_flag
))
11709 specbind (Qoverriding_terminal_local_map
, Qnil
);
11710 specbind (Qoverriding_local_map
, Qnil
);
11713 GCPRO1 (new_tool_bar
);
11715 /* We must temporarily set the selected frame to this frame
11716 before calling tool_bar_items, because the calculation of
11717 the tool-bar keymap uses the selected frame (see
11718 `tool-bar-make-keymap' in tool-bar.el). */
11719 eassert (EQ (selected_window
,
11720 /* Since we only explicitly preserve selected_frame,
11721 check that selected_window would be redundant. */
11722 XFRAME (selected_frame
)->selected_window
));
11723 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11724 XSETFRAME (frame
, f
);
11725 fast_set_selected_frame (frame
);
11727 /* Build desired tool-bar items from keymaps. */
11729 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11732 /* Redisplay the tool-bar if we changed it. */
11733 if (new_n_tool_bar
!= f
->n_tool_bar_items
11734 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11736 /* Redisplay that happens asynchronously due to an expose event
11737 may access f->tool_bar_items. Make sure we update both
11738 variables within BLOCK_INPUT so no such event interrupts. */
11740 fset_tool_bar_items (f
, new_tool_bar
);
11741 f
->n_tool_bar_items
= new_n_tool_bar
;
11742 w
->update_mode_line
= 1;
11748 unbind_to (count
, Qnil
);
11749 set_buffer_internal_1 (prev
);
11754 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
11756 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11757 F's desired tool-bar contents. F->tool_bar_items must have
11758 been set up previously by calling prepare_menu_bars. */
11761 build_desired_tool_bar_string (struct frame
*f
)
11763 int i
, size
, size_needed
;
11764 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11765 Lisp_Object image
, plist
, props
;
11767 image
= plist
= props
= Qnil
;
11768 GCPRO3 (image
, plist
, props
);
11770 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11771 Otherwise, make a new string. */
11773 /* The size of the string we might be able to reuse. */
11774 size
= (STRINGP (f
->desired_tool_bar_string
)
11775 ? SCHARS (f
->desired_tool_bar_string
)
11778 /* We need one space in the string for each image. */
11779 size_needed
= f
->n_tool_bar_items
;
11781 /* Reuse f->desired_tool_bar_string, if possible. */
11782 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11783 fset_desired_tool_bar_string
11784 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11787 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11788 Fremove_text_properties (make_number (0), make_number (size
),
11789 props
, f
->desired_tool_bar_string
);
11792 /* Put a `display' property on the string for the images to display,
11793 put a `menu_item' property on tool-bar items with a value that
11794 is the index of the item in F's tool-bar item vector. */
11795 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11797 #define PROP(IDX) \
11798 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11800 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11801 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11802 int hmargin
, vmargin
, relief
, idx
, end
;
11804 /* If image is a vector, choose the image according to the
11806 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11807 if (VECTORP (image
))
11811 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11812 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11815 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11816 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11818 eassert (ASIZE (image
) >= idx
);
11819 image
= AREF (image
, idx
);
11824 /* Ignore invalid image specifications. */
11825 if (!valid_image_p (image
))
11828 /* Display the tool-bar button pressed, or depressed. */
11829 plist
= Fcopy_sequence (XCDR (image
));
11831 /* Compute margin and relief to draw. */
11832 relief
= (tool_bar_button_relief
>= 0
11833 ? tool_bar_button_relief
11834 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11835 hmargin
= vmargin
= relief
;
11837 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11838 INT_MAX
- max (hmargin
, vmargin
)))
11840 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11841 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11843 else if (CONSP (Vtool_bar_button_margin
))
11845 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11846 INT_MAX
- hmargin
))
11847 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11849 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11850 INT_MAX
- vmargin
))
11851 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11854 if (auto_raise_tool_bar_buttons_p
)
11856 /* Add a `:relief' property to the image spec if the item is
11860 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11867 /* If image is selected, display it pressed, i.e. with a
11868 negative relief. If it's not selected, display it with a
11870 plist
= Fplist_put (plist
, QCrelief
,
11872 ? make_number (-relief
)
11873 : make_number (relief
)));
11878 /* Put a margin around the image. */
11879 if (hmargin
|| vmargin
)
11881 if (hmargin
== vmargin
)
11882 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11884 plist
= Fplist_put (plist
, QCmargin
,
11885 Fcons (make_number (hmargin
),
11886 make_number (vmargin
)));
11889 /* If button is not enabled, and we don't have special images
11890 for the disabled state, make the image appear disabled by
11891 applying an appropriate algorithm to it. */
11892 if (!enabled_p
&& idx
< 0)
11893 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11895 /* Put a `display' text property on the string for the image to
11896 display. Put a `menu-item' property on the string that gives
11897 the start of this item's properties in the tool-bar items
11899 image
= Fcons (Qimage
, plist
);
11900 props
= list4 (Qdisplay
, image
,
11901 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11903 /* Let the last image hide all remaining spaces in the tool bar
11904 string. The string can be longer than needed when we reuse a
11905 previous string. */
11906 if (i
+ 1 == f
->n_tool_bar_items
)
11907 end
= SCHARS (f
->desired_tool_bar_string
);
11910 Fadd_text_properties (make_number (i
), make_number (end
),
11911 props
, f
->desired_tool_bar_string
);
11919 /* Display one line of the tool-bar of frame IT->f.
11921 HEIGHT specifies the desired height of the tool-bar line.
11922 If the actual height of the glyph row is less than HEIGHT, the
11923 row's height is increased to HEIGHT, and the icons are centered
11924 vertically in the new height.
11926 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11927 count a final empty row in case the tool-bar width exactly matches
11932 display_tool_bar_line (struct it
*it
, int height
)
11934 struct glyph_row
*row
= it
->glyph_row
;
11935 int max_x
= it
->last_visible_x
;
11936 struct glyph
*last
;
11938 /* Don't extend on a previously drawn tool bar items (Bug#16058). */
11939 clear_glyph_row (row
);
11940 row
->enabled_p
= true;
11941 row
->y
= it
->current_y
;
11943 /* Note that this isn't made use of if the face hasn't a box,
11944 so there's no need to check the face here. */
11945 it
->start_of_box_run_p
= 1;
11947 while (it
->current_x
< max_x
)
11949 int x
, n_glyphs_before
, i
, nglyphs
;
11950 struct it it_before
;
11952 /* Get the next display element. */
11953 if (!get_next_display_element (it
))
11955 /* Don't count empty row if we are counting needed tool-bar lines. */
11956 if (height
< 0 && !it
->hpos
)
11961 /* Produce glyphs. */
11962 n_glyphs_before
= row
->used
[TEXT_AREA
];
11965 PRODUCE_GLYPHS (it
);
11967 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11969 x
= it_before
.current_x
;
11970 while (i
< nglyphs
)
11972 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11974 if (x
+ glyph
->pixel_width
> max_x
)
11976 /* Glyph doesn't fit on line. Backtrack. */
11977 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11979 /* If this is the only glyph on this line, it will never fit on the
11980 tool-bar, so skip it. But ensure there is at least one glyph,
11981 so we don't accidentally disable the tool-bar. */
11982 if (n_glyphs_before
== 0
11983 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11989 x
+= glyph
->pixel_width
;
11993 /* Stop at line end. */
11994 if (ITERATOR_AT_END_OF_LINE_P (it
))
11997 set_iterator_to_next (it
, 1);
12002 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
12004 /* Use default face for the border below the tool bar.
12006 FIXME: When auto-resize-tool-bars is grow-only, there is
12007 no additional border below the possibly empty tool-bar lines.
12008 So to make the extra empty lines look "normal", we have to
12009 use the tool-bar face for the border too. */
12010 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12011 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
12012 it
->face_id
= DEFAULT_FACE_ID
;
12014 extend_face_to_end_of_line (it
);
12015 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
12016 last
->right_box_line_p
= 1;
12017 if (last
== row
->glyphs
[TEXT_AREA
])
12018 last
->left_box_line_p
= 1;
12020 /* Make line the desired height and center it vertically. */
12021 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
12023 /* Don't add more than one line height. */
12024 height
%= FRAME_LINE_HEIGHT (it
->f
);
12025 it
->max_ascent
+= height
/ 2;
12026 it
->max_descent
+= (height
+ 1) / 2;
12029 compute_line_metrics (it
);
12031 /* If line is empty, make it occupy the rest of the tool-bar. */
12032 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
12034 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
12035 row
->visible_height
= row
->height
;
12036 row
->ascent
= row
->phys_ascent
= 0;
12037 row
->extra_line_spacing
= 0;
12040 row
->full_width_p
= 1;
12041 row
->continued_p
= 0;
12042 row
->truncated_on_left_p
= 0;
12043 row
->truncated_on_right_p
= 0;
12045 it
->current_x
= it
->hpos
= 0;
12046 it
->current_y
+= row
->height
;
12052 /* Max tool-bar height. Basically, this is what makes all other windows
12053 disappear when the frame gets too small. Rethink this! */
12055 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
12056 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
12058 /* Value is the number of pixels needed to make all tool-bar items of
12059 frame F visible. The actual number of glyph rows needed is
12060 returned in *N_ROWS if non-NULL. */
12063 tool_bar_height (struct frame
*f
, int *n_rows
, bool pixelwise
)
12065 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12067 /* tool_bar_height is called from redisplay_tool_bar after building
12068 the desired matrix, so use (unused) mode-line row as temporary row to
12069 avoid destroying the first tool-bar row. */
12070 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
12072 /* Initialize an iterator for iteration over
12073 F->desired_tool_bar_string in the tool-bar window of frame F. */
12074 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
12075 it
.first_visible_x
= 0;
12076 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12077 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12078 it
.paragraph_embedding
= L2R
;
12080 while (!ITERATOR_AT_END_P (&it
))
12082 clear_glyph_row (temp_row
);
12083 it
.glyph_row
= temp_row
;
12084 display_tool_bar_line (&it
, -1);
12086 clear_glyph_row (temp_row
);
12088 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
12090 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
12093 return it
.current_y
;
12095 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
12098 #endif /* !USE_GTK && !HAVE_NS */
12100 #if defined USE_GTK || defined HAVE_NS
12101 EXFUN (Ftool_bar_height
, 2) ATTRIBUTE_CONST
;
12102 EXFUN (Ftool_bar_lines_needed
, 1) ATTRIBUTE_CONST
;
12105 DEFUN ("tool-bar-height", Ftool_bar_height
, Stool_bar_height
,
12107 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
12108 If FRAME is nil or omitted, use the selected frame. Optional argument
12109 PIXELWISE non-nil means return the height of the tool bar in pixels. */)
12110 (Lisp_Object frame
, Lisp_Object pixelwise
)
12114 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12115 struct frame
*f
= decode_any_frame (frame
);
12117 if (WINDOWP (f
->tool_bar_window
)
12118 && WINDOW_PIXEL_HEIGHT (XWINDOW (f
->tool_bar_window
)) > 0)
12120 update_tool_bar (f
, 1);
12121 if (f
->n_tool_bar_items
)
12123 build_desired_tool_bar_string (f
);
12124 height
= tool_bar_height (f
, NULL
, NILP (pixelwise
) ? 0 : 1);
12129 return make_number (height
);
12133 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
12134 height should be changed. */
12137 redisplay_tool_bar (struct frame
*f
)
12139 #if defined (USE_GTK) || defined (HAVE_NS)
12141 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12142 update_frame_tool_bar (f
);
12145 #else /* !USE_GTK && !HAVE_NS */
12149 struct glyph_row
*row
;
12151 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12152 do anything. This means you must start with tool-bar-lines
12153 non-zero to get the auto-sizing effect. Or in other words, you
12154 can turn off tool-bars by specifying tool-bar-lines zero. */
12155 if (!WINDOWP (f
->tool_bar_window
)
12156 || (w
= XWINDOW (f
->tool_bar_window
),
12157 WINDOW_PIXEL_HEIGHT (w
) == 0))
12160 /* Set up an iterator for the tool-bar window. */
12161 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12162 it
.first_visible_x
= 0;
12163 it
.last_visible_x
= WINDOW_PIXEL_WIDTH (w
);
12164 row
= it
.glyph_row
;
12166 /* Build a string that represents the contents of the tool-bar. */
12167 build_desired_tool_bar_string (f
);
12168 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12169 /* FIXME: This should be controlled by a user option. But it
12170 doesn't make sense to have an R2L tool bar if the menu bar cannot
12171 be drawn also R2L, and making the menu bar R2L is tricky due
12172 toolkit-specific code that implements it. If an R2L tool bar is
12173 ever supported, display_tool_bar_line should also be augmented to
12174 call unproduce_glyphs like display_line and display_string
12176 it
.paragraph_embedding
= L2R
;
12178 if (f
->n_tool_bar_rows
== 0)
12180 int new_height
= tool_bar_height (f
, &f
->n_tool_bar_rows
, 1);
12182 if (new_height
!= WINDOW_PIXEL_HEIGHT (w
))
12185 int new_lines
= ((new_height
+ FRAME_LINE_HEIGHT (f
) - 1)
12186 / FRAME_LINE_HEIGHT (f
));
12188 XSETFRAME (frame
, f
);
12189 Fmodify_frame_parameters (frame
,
12190 list1 (Fcons (Qtool_bar_lines
,
12191 make_number (new_lines
))));
12192 /* Always do that now. */
12193 clear_glyph_matrix (w
->desired_matrix
);
12194 f
->fonts_changed
= 1;
12199 /* Display as many lines as needed to display all tool-bar items. */
12201 if (f
->n_tool_bar_rows
> 0)
12203 int border
, rows
, height
, extra
;
12205 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12206 border
= XINT (Vtool_bar_border
);
12207 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12208 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12209 else if (EQ (Vtool_bar_border
, Qborder_width
))
12210 border
= f
->border_width
;
12216 rows
= f
->n_tool_bar_rows
;
12217 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12218 extra
= it
.last_visible_y
- border
- height
* rows
;
12220 while (it
.current_y
< it
.last_visible_y
)
12223 if (extra
> 0 && rows
-- > 0)
12225 h
= (extra
+ rows
- 1) / rows
;
12228 display_tool_bar_line (&it
, height
+ h
);
12233 while (it
.current_y
< it
.last_visible_y
)
12234 display_tool_bar_line (&it
, 0);
12237 /* It doesn't make much sense to try scrolling in the tool-bar
12238 window, so don't do it. */
12239 w
->desired_matrix
->no_scrolling_p
= 1;
12240 w
->must_be_updated_p
= 1;
12242 if (!NILP (Vauto_resize_tool_bars
))
12244 /* Do we really allow the toolbar to occupy the whole frame? */
12245 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12246 int change_height_p
= 0;
12248 /* If we couldn't display everything, change the tool-bar's
12249 height if there is room for more. */
12250 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12251 && it
.current_y
< max_tool_bar_height
)
12252 change_height_p
= 1;
12254 /* We subtract 1 because display_tool_bar_line advances the
12255 glyph_row pointer before returning to its caller. We want to
12256 examine the last glyph row produced by
12257 display_tool_bar_line. */
12258 row
= it
.glyph_row
- 1;
12260 /* If there are blank lines at the end, except for a partially
12261 visible blank line at the end that is smaller than
12262 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12263 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12264 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12265 change_height_p
= 1;
12267 /* If row displays tool-bar items, but is partially visible,
12268 change the tool-bar's height. */
12269 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12270 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12271 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12272 change_height_p
= 1;
12274 /* Resize windows as needed by changing the `tool-bar-lines'
12275 frame parameter. */
12276 if (change_height_p
)
12280 int new_height
= tool_bar_height (f
, &nrows
, 1);
12282 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12283 && !f
->minimize_tool_bar_window_p
)
12284 ? (new_height
> WINDOW_PIXEL_HEIGHT (w
))
12285 : (new_height
!= WINDOW_PIXEL_HEIGHT (w
)));
12286 f
->minimize_tool_bar_window_p
= 0;
12288 if (change_height_p
)
12290 /* Current size of the tool-bar window in canonical line
12292 int old_lines
= WINDOW_TOTAL_LINES (w
);
12293 /* Required size of the tool-bar window in canonical
12295 int new_lines
= ((new_height
+ FRAME_LINE_HEIGHT (f
) - 1)
12296 / FRAME_LINE_HEIGHT (f
));
12297 /* Maximum size of the tool-bar window in canonical line
12298 units that this frame can allow. */
12300 WINDOW_TOTAL_LINES (XWINDOW (FRAME_ROOT_WINDOW (f
))) - 1;
12302 /* Don't try to change the tool-bar window size and set
12303 the fonts_changed flag unless really necessary. That
12304 flag causes redisplay to give up and retry
12305 redisplaying the frame from scratch, so setting it
12306 unnecessarily can lead to nasty redisplay loops. */
12307 if (new_lines
<= max_lines
12308 && eabs (new_lines
- old_lines
) >= 1)
12310 XSETFRAME (frame
, f
);
12311 Fmodify_frame_parameters (frame
,
12312 list1 (Fcons (Qtool_bar_lines
,
12313 make_number (new_lines
))));
12314 clear_glyph_matrix (w
->desired_matrix
);
12315 f
->n_tool_bar_rows
= nrows
;
12316 f
->fonts_changed
= 1;
12323 f
->minimize_tool_bar_window_p
= 0;
12326 #endif /* USE_GTK || HAVE_NS */
12329 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
12331 /* Get information about the tool-bar item which is displayed in GLYPH
12332 on frame F. Return in *PROP_IDX the index where tool-bar item
12333 properties start in F->tool_bar_items. Value is zero if
12334 GLYPH doesn't display a tool-bar item. */
12337 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12343 /* This function can be called asynchronously, which means we must
12344 exclude any possibility that Fget_text_property signals an
12346 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12347 charpos
= max (0, charpos
);
12349 /* Get the text property `menu-item' at pos. The value of that
12350 property is the start index of this item's properties in
12351 F->tool_bar_items. */
12352 prop
= Fget_text_property (make_number (charpos
),
12353 Qmenu_item
, f
->current_tool_bar_string
);
12354 if (INTEGERP (prop
))
12356 *prop_idx
= XINT (prop
);
12366 /* Get information about the tool-bar item at position X/Y on frame F.
12367 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12368 the current matrix of the tool-bar window of F, or NULL if not
12369 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12370 item in F->tool_bar_items. Value is
12372 -1 if X/Y is not on a tool-bar item
12373 0 if X/Y is on the same item that was highlighted before.
12377 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12378 int *hpos
, int *vpos
, int *prop_idx
)
12380 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12381 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12384 /* Find the glyph under X/Y. */
12385 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12386 if (*glyph
== NULL
)
12389 /* Get the start of this tool-bar item's properties in
12390 f->tool_bar_items. */
12391 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12394 /* Is mouse on the highlighted item? */
12395 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12396 && *vpos
>= hlinfo
->mouse_face_beg_row
12397 && *vpos
<= hlinfo
->mouse_face_end_row
12398 && (*vpos
> hlinfo
->mouse_face_beg_row
12399 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12400 && (*vpos
< hlinfo
->mouse_face_end_row
12401 || *hpos
< hlinfo
->mouse_face_end_col
12402 || hlinfo
->mouse_face_past_end
))
12410 Handle mouse button event on the tool-bar of frame F, at
12411 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12412 0 for button release. MODIFIERS is event modifiers for button
12416 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12419 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12420 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12421 int hpos
, vpos
, prop_idx
;
12422 struct glyph
*glyph
;
12423 Lisp_Object enabled_p
;
12426 /* If not on the highlighted tool-bar item, and mouse-highlight is
12427 non-nil, return. This is so we generate the tool-bar button
12428 click only when the mouse button is released on the same item as
12429 where it was pressed. However, when mouse-highlight is disabled,
12430 generate the click when the button is released regardless of the
12431 highlight, since tool-bar items are not highlighted in that
12433 frame_to_window_pixel_xy (w
, &x
, &y
);
12434 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12436 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12439 /* When mouse-highlight is off, generate the click for the item
12440 where the button was pressed, disregarding where it was
12442 if (NILP (Vmouse_highlight
) && !down_p
)
12443 prop_idx
= last_tool_bar_item
;
12445 /* If item is disabled, do nothing. */
12446 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12447 if (NILP (enabled_p
))
12452 /* Show item in pressed state. */
12453 if (!NILP (Vmouse_highlight
))
12454 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12455 last_tool_bar_item
= prop_idx
;
12459 Lisp_Object key
, frame
;
12460 struct input_event event
;
12461 EVENT_INIT (event
);
12463 /* Show item in released state. */
12464 if (!NILP (Vmouse_highlight
))
12465 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12467 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12469 XSETFRAME (frame
, f
);
12470 event
.kind
= TOOL_BAR_EVENT
;
12471 event
.frame_or_window
= frame
;
12473 kbd_buffer_store_event (&event
);
12475 event
.kind
= TOOL_BAR_EVENT
;
12476 event
.frame_or_window
= frame
;
12478 event
.modifiers
= modifiers
;
12479 kbd_buffer_store_event (&event
);
12480 last_tool_bar_item
= -1;
12485 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12486 tool-bar window-relative coordinates X/Y. Called from
12487 note_mouse_highlight. */
12490 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12492 Lisp_Object window
= f
->tool_bar_window
;
12493 struct window
*w
= XWINDOW (window
);
12494 Display_Info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
12495 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12497 struct glyph
*glyph
;
12498 struct glyph_row
*row
;
12500 Lisp_Object enabled_p
;
12502 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12503 int mouse_down_p
, rc
;
12505 /* Function note_mouse_highlight is called with negative X/Y
12506 values when mouse moves outside of the frame. */
12507 if (x
<= 0 || y
<= 0)
12509 clear_mouse_face (hlinfo
);
12513 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12516 /* Not on tool-bar item. */
12517 clear_mouse_face (hlinfo
);
12521 /* On same tool-bar item as before. */
12522 goto set_help_echo
;
12524 clear_mouse_face (hlinfo
);
12526 /* Mouse is down, but on different tool-bar item? */
12527 mouse_down_p
= (x_mouse_grabbed (dpyinfo
)
12528 && f
== dpyinfo
->last_mouse_frame
);
12531 && last_tool_bar_item
!= prop_idx
)
12534 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12536 /* If tool-bar item is not enabled, don't highlight it. */
12537 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12538 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12540 /* Compute the x-position of the glyph. In front and past the
12541 image is a space. We include this in the highlighted area. */
12542 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12543 for (i
= x
= 0; i
< hpos
; ++i
)
12544 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12546 /* Record this as the current active region. */
12547 hlinfo
->mouse_face_beg_col
= hpos
;
12548 hlinfo
->mouse_face_beg_row
= vpos
;
12549 hlinfo
->mouse_face_beg_x
= x
;
12550 hlinfo
->mouse_face_past_end
= 0;
12552 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12553 hlinfo
->mouse_face_end_row
= vpos
;
12554 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12555 hlinfo
->mouse_face_window
= window
;
12556 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12558 /* Display it as active. */
12559 show_mouse_face (hlinfo
, draw
);
12564 /* Set help_echo_string to a help string to display for this tool-bar item.
12565 XTread_socket does the rest. */
12566 help_echo_object
= help_echo_window
= Qnil
;
12567 help_echo_pos
= -1;
12568 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12569 if (NILP (help_echo_string
))
12570 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12573 #endif /* !USE_GTK && !HAVE_NS */
12575 #endif /* HAVE_WINDOW_SYSTEM */
12579 /************************************************************************
12580 Horizontal scrolling
12581 ************************************************************************/
12583 static int hscroll_window_tree (Lisp_Object
);
12584 static int hscroll_windows (Lisp_Object
);
12586 /* For all leaf windows in the window tree rooted at WINDOW, set their
12587 hscroll value so that PT is (i) visible in the window, and (ii) so
12588 that it is not within a certain margin at the window's left and
12589 right border. Value is non-zero if any window's hscroll has been
12593 hscroll_window_tree (Lisp_Object window
)
12595 int hscrolled_p
= 0;
12596 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12597 int hscroll_step_abs
= 0;
12598 double hscroll_step_rel
= 0;
12600 if (hscroll_relative_p
)
12602 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12603 if (hscroll_step_rel
< 0)
12605 hscroll_relative_p
= 0;
12606 hscroll_step_abs
= 0;
12609 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12611 hscroll_step_abs
= XINT (Vhscroll_step
);
12612 if (hscroll_step_abs
< 0)
12613 hscroll_step_abs
= 0;
12616 hscroll_step_abs
= 0;
12618 while (WINDOWP (window
))
12620 struct window
*w
= XWINDOW (window
);
12622 if (WINDOWP (w
->contents
))
12623 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12624 else if (w
->cursor
.vpos
>= 0)
12627 int text_area_width
;
12628 struct glyph_row
*cursor_row
;
12629 struct glyph_row
*bottom_row
;
12632 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->desired_matrix
, w
);
12633 if (w
->cursor
.vpos
< bottom_row
- w
->desired_matrix
->rows
)
12634 cursor_row
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12636 cursor_row
= bottom_row
- 1;
12638 if (!cursor_row
->enabled_p
)
12640 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
12641 if (w
->cursor
.vpos
< bottom_row
- w
->current_matrix
->rows
)
12642 cursor_row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12644 cursor_row
= bottom_row
- 1;
12646 row_r2l_p
= cursor_row
->reversed_p
;
12648 text_area_width
= window_box_width (w
, TEXT_AREA
);
12650 /* Scroll when cursor is inside this scroll margin. */
12651 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12653 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12654 /* For left-to-right rows, hscroll when cursor is either
12655 (i) inside the right hscroll margin, or (ii) if it is
12656 inside the left margin and the window is already
12660 && w
->cursor
.x
<= h_margin
)
12661 || (cursor_row
->enabled_p
12662 && cursor_row
->truncated_on_right_p
12663 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12664 /* For right-to-left rows, the logic is similar,
12665 except that rules for scrolling to left and right
12666 are reversed. E.g., if cursor.x <= h_margin, we
12667 need to hscroll "to the right" unconditionally,
12668 and that will scroll the screen to the left so as
12669 to reveal the next portion of the row. */
12671 && ((cursor_row
->enabled_p
12672 /* FIXME: It is confusing to set the
12673 truncated_on_right_p flag when R2L rows
12674 are actually truncated on the left. */
12675 && cursor_row
->truncated_on_right_p
12676 && w
->cursor
.x
<= h_margin
)
12678 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12682 struct buffer
*saved_current_buffer
;
12686 /* Find point in a display of infinite width. */
12687 saved_current_buffer
= current_buffer
;
12688 current_buffer
= XBUFFER (w
->contents
);
12690 if (w
== XWINDOW (selected_window
))
12693 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12695 /* Move iterator to pt starting at cursor_row->start in
12696 a line with infinite width. */
12697 init_to_row_start (&it
, w
, cursor_row
);
12698 it
.last_visible_x
= INFINITY
;
12699 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12700 current_buffer
= saved_current_buffer
;
12702 /* Position cursor in window. */
12703 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12704 hscroll
= max (0, (it
.current_x
12705 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12706 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12707 : (text_area_width
/ 2))))
12708 / FRAME_COLUMN_WIDTH (it
.f
);
12709 else if ((!row_r2l_p
12710 && w
->cursor
.x
>= text_area_width
- h_margin
)
12711 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12713 if (hscroll_relative_p
)
12714 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12717 wanted_x
= text_area_width
12718 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12721 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12725 if (hscroll_relative_p
)
12726 wanted_x
= text_area_width
* hscroll_step_rel
12729 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12732 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12734 hscroll
= max (hscroll
, w
->min_hscroll
);
12736 /* Don't prevent redisplay optimizations if hscroll
12737 hasn't changed, as it will unnecessarily slow down
12739 if (w
->hscroll
!= hscroll
)
12741 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12742 w
->hscroll
= hscroll
;
12751 /* Value is non-zero if hscroll of any leaf window has been changed. */
12752 return hscrolled_p
;
12756 /* Set hscroll so that cursor is visible and not inside horizontal
12757 scroll margins for all windows in the tree rooted at WINDOW. See
12758 also hscroll_window_tree above. Value is non-zero if any window's
12759 hscroll has been changed. If it has, desired matrices on the frame
12760 of WINDOW are cleared. */
12763 hscroll_windows (Lisp_Object window
)
12765 int hscrolled_p
= hscroll_window_tree (window
);
12767 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12768 return hscrolled_p
;
12773 /************************************************************************
12775 ************************************************************************/
12777 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12778 to a non-zero value. This is sometimes handy to have in a debugger
12783 /* First and last unchanged row for try_window_id. */
12785 static int debug_first_unchanged_at_end_vpos
;
12786 static int debug_last_unchanged_at_beg_vpos
;
12788 /* Delta vpos and y. */
12790 static int debug_dvpos
, debug_dy
;
12792 /* Delta in characters and bytes for try_window_id. */
12794 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12796 /* Values of window_end_pos and window_end_vpos at the end of
12799 static ptrdiff_t debug_end_vpos
;
12801 /* Append a string to W->desired_matrix->method. FMT is a printf
12802 format string. If trace_redisplay_p is true also printf the
12803 resulting string to stderr. */
12805 static void debug_method_add (struct window
*, char const *, ...)
12806 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12809 debug_method_add (struct window
*w
, char const *fmt
, ...)
12812 char *method
= w
->desired_matrix
->method
;
12813 int len
= strlen (method
);
12814 int size
= sizeof w
->desired_matrix
->method
;
12815 int remaining
= size
- len
- 1;
12818 if (len
&& remaining
)
12821 --remaining
, ++len
;
12824 va_start (ap
, fmt
);
12825 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12828 if (trace_redisplay_p
)
12829 fprintf (stderr
, "%p (%s): %s\n",
12831 ((BUFFERP (w
->contents
)
12832 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12833 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12838 #endif /* GLYPH_DEBUG */
12841 /* Value is non-zero if all changes in window W, which displays
12842 current_buffer, are in the text between START and END. START is a
12843 buffer position, END is given as a distance from Z. Used in
12844 redisplay_internal for display optimization. */
12847 text_outside_line_unchanged_p (struct window
*w
,
12848 ptrdiff_t start
, ptrdiff_t end
)
12850 int unchanged_p
= 1;
12852 /* If text or overlays have changed, see where. */
12853 if (window_outdated (w
))
12855 /* Gap in the line? */
12856 if (GPT
< start
|| Z
- GPT
< end
)
12859 /* Changes start in front of the line, or end after it? */
12861 && (BEG_UNCHANGED
< start
- 1
12862 || END_UNCHANGED
< end
))
12865 /* If selective display, can't optimize if changes start at the
12866 beginning of the line. */
12868 && INTEGERP (BVAR (current_buffer
, selective_display
))
12869 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12870 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12873 /* If there are overlays at the start or end of the line, these
12874 may have overlay strings with newlines in them. A change at
12875 START, for instance, may actually concern the display of such
12876 overlay strings as well, and they are displayed on different
12877 lines. So, quickly rule out this case. (For the future, it
12878 might be desirable to implement something more telling than
12879 just BEG/END_UNCHANGED.) */
12882 if (BEG
+ BEG_UNCHANGED
== start
12883 && overlay_touches_p (start
))
12885 if (END_UNCHANGED
== end
12886 && overlay_touches_p (Z
- end
))
12890 /* Under bidi reordering, adding or deleting a character in the
12891 beginning of a paragraph, before the first strong directional
12892 character, can change the base direction of the paragraph (unless
12893 the buffer specifies a fixed paragraph direction), which will
12894 require to redisplay the whole paragraph. It might be worthwhile
12895 to find the paragraph limits and widen the range of redisplayed
12896 lines to that, but for now just give up this optimization. */
12897 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12898 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12902 return unchanged_p
;
12906 /* Do a frame update, taking possible shortcuts into account. This is
12907 the main external entry point for redisplay.
12909 If the last redisplay displayed an echo area message and that message
12910 is no longer requested, we clear the echo area or bring back the
12911 mini-buffer if that is in use. */
12916 redisplay_internal ();
12921 overlay_arrow_string_or_property (Lisp_Object var
)
12925 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12928 return Voverlay_arrow_string
;
12931 /* Return 1 if there are any overlay-arrows in current_buffer. */
12933 overlay_arrow_in_current_buffer_p (void)
12937 for (vlist
= Voverlay_arrow_variable_list
;
12939 vlist
= XCDR (vlist
))
12941 Lisp_Object var
= XCAR (vlist
);
12944 if (!SYMBOLP (var
))
12946 val
= find_symbol_value (var
);
12948 && current_buffer
== XMARKER (val
)->buffer
)
12955 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12959 overlay_arrows_changed_p (void)
12963 for (vlist
= Voverlay_arrow_variable_list
;
12965 vlist
= XCDR (vlist
))
12967 Lisp_Object var
= XCAR (vlist
);
12968 Lisp_Object val
, pstr
;
12970 if (!SYMBOLP (var
))
12972 val
= find_symbol_value (var
);
12973 if (!MARKERP (val
))
12975 if (! EQ (COERCE_MARKER (val
),
12976 Fget (var
, Qlast_arrow_position
))
12977 || ! (pstr
= overlay_arrow_string_or_property (var
),
12978 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12984 /* Mark overlay arrows to be updated on next redisplay. */
12987 update_overlay_arrows (int up_to_date
)
12991 for (vlist
= Voverlay_arrow_variable_list
;
12993 vlist
= XCDR (vlist
))
12995 Lisp_Object var
= XCAR (vlist
);
12997 if (!SYMBOLP (var
))
13000 if (up_to_date
> 0)
13002 Lisp_Object val
= find_symbol_value (var
);
13003 Fput (var
, Qlast_arrow_position
,
13004 COERCE_MARKER (val
));
13005 Fput (var
, Qlast_arrow_string
,
13006 overlay_arrow_string_or_property (var
));
13008 else if (up_to_date
< 0
13009 || !NILP (Fget (var
, Qlast_arrow_position
)))
13011 Fput (var
, Qlast_arrow_position
, Qt
);
13012 Fput (var
, Qlast_arrow_string
, Qt
);
13018 /* Return overlay arrow string to display at row.
13019 Return integer (bitmap number) for arrow bitmap in left fringe.
13020 Return nil if no overlay arrow. */
13023 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
13027 for (vlist
= Voverlay_arrow_variable_list
;
13029 vlist
= XCDR (vlist
))
13031 Lisp_Object var
= XCAR (vlist
);
13034 if (!SYMBOLP (var
))
13037 val
= find_symbol_value (var
);
13040 && current_buffer
== XMARKER (val
)->buffer
13041 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
13043 if (FRAME_WINDOW_P (it
->f
)
13044 /* FIXME: if ROW->reversed_p is set, this should test
13045 the right fringe, not the left one. */
13046 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
13048 #ifdef HAVE_WINDOW_SYSTEM
13049 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
13052 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
13053 return make_number (fringe_bitmap
);
13056 return make_number (-1); /* Use default arrow bitmap. */
13058 return overlay_arrow_string_or_property (var
);
13065 /* Return 1 if point moved out of or into a composition. Otherwise
13066 return 0. PREV_BUF and PREV_PT are the last point buffer and
13067 position. BUF and PT are the current point buffer and position. */
13070 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
13071 struct buffer
*buf
, ptrdiff_t pt
)
13073 ptrdiff_t start
, end
;
13075 Lisp_Object buffer
;
13077 XSETBUFFER (buffer
, buf
);
13078 /* Check a composition at the last point if point moved within the
13080 if (prev_buf
== buf
)
13083 /* Point didn't move. */
13086 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
13087 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
13088 && composition_valid_p (start
, end
, prop
)
13089 && start
< prev_pt
&& end
> prev_pt
)
13090 /* The last point was within the composition. Return 1 iff
13091 point moved out of the composition. */
13092 return (pt
<= start
|| pt
>= end
);
13095 /* Check a composition at the current point. */
13096 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
13097 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
13098 && composition_valid_p (start
, end
, prop
)
13099 && start
< pt
&& end
> pt
);
13102 /* Reconsider the clip changes of buffer which is displayed in W. */
13105 reconsider_clip_changes (struct window
*w
)
13107 struct buffer
*b
= XBUFFER (w
->contents
);
13109 if (b
->clip_changed
13110 && w
->window_end_valid
13111 && w
->current_matrix
->buffer
== b
13112 && w
->current_matrix
->zv
== BUF_ZV (b
)
13113 && w
->current_matrix
->begv
== BUF_BEGV (b
))
13114 b
->clip_changed
= 0;
13116 /* If display wasn't paused, and W is not a tool bar window, see if
13117 point has been moved into or out of a composition. In that case,
13118 we set b->clip_changed to 1 to force updating the screen. If
13119 b->clip_changed has already been set to 1, we can skip this
13121 if (!b
->clip_changed
&& w
->window_end_valid
)
13123 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
13124 ? PT
: marker_position (w
->pointm
));
13126 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
13127 && check_point_in_composition (w
->current_matrix
->buffer
,
13128 w
->last_point
, b
, pt
))
13129 b
->clip_changed
= 1;
13134 propagate_buffer_redisplay (void)
13135 { /* Resetting b->text->redisplay is problematic!
13136 We can't just reset it in the case that some window that displays
13137 it has not been redisplayed; and such a window can stay
13138 unredisplayed for a long time if it's currently invisible.
13139 But we do want to reset it at the end of redisplay otherwise
13140 its displayed windows will keep being redisplayed over and over
13142 So we copy all b->text->redisplay flags up to their windows here,
13143 such that mark_window_display_accurate can safely reset
13144 b->text->redisplay. */
13145 Lisp_Object ws
= window_list ();
13146 for (; CONSP (ws
); ws
= XCDR (ws
))
13148 struct window
*thisw
= XWINDOW (XCAR (ws
));
13149 struct buffer
*thisb
= XBUFFER (thisw
->contents
);
13150 if (thisb
->text
->redisplay
)
13151 thisw
->redisplay
= true;
13155 #define STOP_POLLING \
13156 do { if (! polling_stopped_here) stop_polling (); \
13157 polling_stopped_here = 1; } while (0)
13159 #define RESUME_POLLING \
13160 do { if (polling_stopped_here) start_polling (); \
13161 polling_stopped_here = 0; } while (0)
13164 /* Perhaps in the future avoid recentering windows if it
13165 is not necessary; currently that causes some problems. */
13168 redisplay_internal (void)
13170 struct window
*w
= XWINDOW (selected_window
);
13174 bool must_finish
= 0, match_p
;
13175 struct text_pos tlbufpos
, tlendpos
;
13176 int number_of_visible_frames
;
13179 int polling_stopped_here
= 0;
13180 Lisp_Object tail
, frame
;
13182 /* True means redisplay has to consider all windows on all
13183 frames. False, only selected_window is considered. */
13184 bool consider_all_windows_p
;
13186 /* True means redisplay has to redisplay the miniwindow. */
13187 bool update_miniwindow_p
= false;
13189 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13191 /* No redisplay if running in batch mode or frame is not yet fully
13192 initialized, or redisplay is explicitly turned off by setting
13193 Vinhibit_redisplay. */
13194 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13195 || !NILP (Vinhibit_redisplay
))
13198 /* Don't examine these until after testing Vinhibit_redisplay.
13199 When Emacs is shutting down, perhaps because its connection to
13200 X has dropped, we should not look at them at all. */
13201 fr
= XFRAME (w
->frame
);
13202 sf
= SELECTED_FRAME ();
13204 if (!fr
->glyphs_initialized_p
)
13207 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13208 if (popup_activated ())
13212 /* I don't think this happens but let's be paranoid. */
13213 if (redisplaying_p
)
13216 /* Record a function that clears redisplaying_p
13217 when we leave this function. */
13218 count
= SPECPDL_INDEX ();
13219 record_unwind_protect_void (unwind_redisplay
);
13220 redisplaying_p
= 1;
13221 specbind (Qinhibit_free_realized_faces
, Qnil
);
13223 /* Record this function, so it appears on the profiler's backtraces. */
13224 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
13226 FOR_EACH_FRAME (tail
, frame
)
13227 XFRAME (frame
)->already_hscrolled_p
= 0;
13230 /* Remember the currently selected window. */
13234 last_escape_glyph_frame
= NULL
;
13235 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13236 last_glyphless_glyph_frame
= NULL
;
13237 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13239 /* If face_change_count is non-zero, init_iterator will free all
13240 realized faces, which includes the faces referenced from current
13241 matrices. So, we can't reuse current matrices in this case. */
13242 if (face_change_count
)
13243 windows_or_buffers_changed
= 47;
13245 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13246 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13248 /* Since frames on a single ASCII terminal share the same
13249 display area, displaying a different frame means redisplay
13250 the whole thing. */
13251 SET_FRAME_GARBAGED (sf
);
13253 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13255 FRAME_TTY (sf
)->previous_frame
= sf
;
13258 /* Set the visible flags for all frames. Do this before checking for
13259 resized or garbaged frames; they want to know if their frames are
13260 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13261 number_of_visible_frames
= 0;
13263 FOR_EACH_FRAME (tail
, frame
)
13265 struct frame
*f
= XFRAME (frame
);
13267 if (FRAME_VISIBLE_P (f
))
13269 ++number_of_visible_frames
;
13270 /* Adjust matrices for visible frames only. */
13271 if (f
->fonts_changed
)
13273 adjust_frame_glyphs (f
);
13274 f
->fonts_changed
= 0;
13276 /* If cursor type has been changed on the frame
13277 other than selected, consider all frames. */
13278 if (f
!= sf
&& f
->cursor_type_changed
)
13279 update_mode_lines
= 31;
13281 clear_desired_matrices (f
);
13284 /* Notice any pending interrupt request to change frame size. */
13285 do_pending_window_change (1);
13287 /* do_pending_window_change could change the selected_window due to
13288 frame resizing which makes the selected window too small. */
13289 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13292 /* Clear frames marked as garbaged. */
13293 clear_garbaged_frames ();
13295 /* Build menubar and tool-bar items. */
13296 if (NILP (Vmemory_full
))
13297 prepare_menu_bars ();
13299 reconsider_clip_changes (w
);
13301 /* In most cases selected window displays current buffer. */
13302 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13305 /* Detect case that we need to write or remove a star in the mode line. */
13306 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13307 w
->update_mode_line
= 1;
13309 if (mode_line_update_needed (w
))
13310 w
->update_mode_line
= 1;
13313 /* Normally the message* functions will have already displayed and
13314 updated the echo area, but the frame may have been trashed, or
13315 the update may have been preempted, so display the echo area
13316 again here. Checking message_cleared_p captures the case that
13317 the echo area should be cleared. */
13318 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13319 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13320 || (message_cleared_p
13321 && minibuf_level
== 0
13322 /* If the mini-window is currently selected, this means the
13323 echo-area doesn't show through. */
13324 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13326 int window_height_changed_p
= echo_area_display (0);
13328 if (message_cleared_p
)
13329 update_miniwindow_p
= true;
13333 /* If we don't display the current message, don't clear the
13334 message_cleared_p flag, because, if we did, we wouldn't clear
13335 the echo area in the next redisplay which doesn't preserve
13337 if (!display_last_displayed_message_p
)
13338 message_cleared_p
= 0;
13340 if (window_height_changed_p
)
13342 windows_or_buffers_changed
= 50;
13344 /* If window configuration was changed, frames may have been
13345 marked garbaged. Clear them or we will experience
13346 surprises wrt scrolling. */
13347 clear_garbaged_frames ();
13350 else if (EQ (selected_window
, minibuf_window
)
13351 && (current_buffer
->clip_changed
|| window_outdated (w
))
13352 && resize_mini_window (w
, 0))
13354 /* Resized active mini-window to fit the size of what it is
13355 showing if its contents might have changed. */
13358 /* If window configuration was changed, frames may have been
13359 marked garbaged. Clear them or we will experience
13360 surprises wrt scrolling. */
13361 clear_garbaged_frames ();
13364 if (windows_or_buffers_changed
&& !update_mode_lines
)
13365 /* Code that sets windows_or_buffers_changed doesn't distinguish whether
13366 only the windows's contents needs to be refreshed, or whether the
13367 mode-lines also need a refresh. */
13368 update_mode_lines
= (windows_or_buffers_changed
== REDISPLAY_SOME
13369 ? REDISPLAY_SOME
: 32);
13371 /* If specs for an arrow have changed, do thorough redisplay
13372 to ensure we remove any arrow that should no longer exist. */
13373 if (overlay_arrows_changed_p ())
13374 /* Apparently, this is the only case where we update other windows,
13375 without updating other mode-lines. */
13376 windows_or_buffers_changed
= 49;
13378 consider_all_windows_p
= (update_mode_lines
13379 || windows_or_buffers_changed
);
13381 #define AINC(a,i) \
13382 if (VECTORP (a) && i >= 0 && i < ASIZE (a) && INTEGERP (AREF (a, i))) \
13383 ASET (a, i, make_number (1 + XINT (AREF (a, i))))
13385 AINC (Vredisplay__all_windows_cause
, windows_or_buffers_changed
);
13386 AINC (Vredisplay__mode_lines_cause
, update_mode_lines
);
13388 /* Optimize the case that only the line containing the cursor in the
13389 selected window has changed. Variables starting with this_ are
13390 set in display_line and record information about the line
13391 containing the cursor. */
13392 tlbufpos
= this_line_start_pos
;
13393 tlendpos
= this_line_end_pos
;
13394 if (!consider_all_windows_p
13395 && CHARPOS (tlbufpos
) > 0
13396 && !w
->update_mode_line
13397 && !current_buffer
->clip_changed
13398 && !current_buffer
->prevent_redisplay_optimizations_p
13399 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13400 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13401 && !XFRAME (w
->frame
)->cursor_type_changed
13402 /* Make sure recorded data applies to current buffer, etc. */
13403 && this_line_buffer
== current_buffer
13406 && !w
->optional_new_start
13407 /* Point must be on the line that we have info recorded about. */
13408 && PT
>= CHARPOS (tlbufpos
)
13409 && PT
<= Z
- CHARPOS (tlendpos
)
13410 /* All text outside that line, including its final newline,
13411 must be unchanged. */
13412 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13413 CHARPOS (tlendpos
)))
13415 if (CHARPOS (tlbufpos
) > BEGV
13416 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13417 && (CHARPOS (tlbufpos
) == ZV
13418 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13419 /* Former continuation line has disappeared by becoming empty. */
13421 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13423 /* We have to handle the case of continuation around a
13424 wide-column character (see the comment in indent.c around
13427 For instance, in the following case:
13429 -------- Insert --------
13430 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13431 J_I_ ==> J_I_ `^^' are cursors.
13435 As we have to redraw the line above, we cannot use this
13439 int line_height_before
= this_line_pixel_height
;
13441 /* Note that start_display will handle the case that the
13442 line starting at tlbufpos is a continuation line. */
13443 start_display (&it
, w
, tlbufpos
);
13445 /* Implementation note: It this still necessary? */
13446 if (it
.current_x
!= this_line_start_x
)
13449 TRACE ((stderr
, "trying display optimization 1\n"));
13450 w
->cursor
.vpos
= -1;
13451 overlay_arrow_seen
= 0;
13452 it
.vpos
= this_line_vpos
;
13453 it
.current_y
= this_line_y
;
13454 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13455 display_line (&it
);
13457 /* If line contains point, is not continued,
13458 and ends at same distance from eob as before, we win. */
13459 if (w
->cursor
.vpos
>= 0
13460 /* Line is not continued, otherwise this_line_start_pos
13461 would have been set to 0 in display_line. */
13462 && CHARPOS (this_line_start_pos
)
13463 /* Line ends as before. */
13464 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13465 /* Line has same height as before. Otherwise other lines
13466 would have to be shifted up or down. */
13467 && this_line_pixel_height
== line_height_before
)
13469 /* If this is not the window's last line, we must adjust
13470 the charstarts of the lines below. */
13471 if (it
.current_y
< it
.last_visible_y
)
13473 struct glyph_row
*row
13474 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13475 ptrdiff_t delta
, delta_bytes
;
13477 /* We used to distinguish between two cases here,
13478 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13479 when the line ends in a newline or the end of the
13480 buffer's accessible portion. But both cases did
13481 the same, so they were collapsed. */
13483 - CHARPOS (tlendpos
)
13484 - MATRIX_ROW_START_CHARPOS (row
));
13485 delta_bytes
= (Z_BYTE
13486 - BYTEPOS (tlendpos
)
13487 - MATRIX_ROW_START_BYTEPOS (row
));
13489 increment_matrix_positions (w
->current_matrix
,
13490 this_line_vpos
+ 1,
13491 w
->current_matrix
->nrows
,
13492 delta
, delta_bytes
);
13495 /* If this row displays text now but previously didn't,
13496 or vice versa, w->window_end_vpos may have to be
13498 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13500 if (w
->window_end_vpos
< this_line_vpos
)
13501 w
->window_end_vpos
= this_line_vpos
;
13503 else if (w
->window_end_vpos
== this_line_vpos
13504 && this_line_vpos
> 0)
13505 w
->window_end_vpos
= this_line_vpos
- 1;
13506 w
->window_end_valid
= 0;
13508 /* Update hint: No need to try to scroll in update_window. */
13509 w
->desired_matrix
->no_scrolling_p
= 1;
13512 *w
->desired_matrix
->method
= 0;
13513 debug_method_add (w
, "optimization 1");
13515 #ifdef HAVE_WINDOW_SYSTEM
13516 update_window_fringes (w
, 0);
13523 else if (/* Cursor position hasn't changed. */
13524 PT
== w
->last_point
13525 /* Make sure the cursor was last displayed
13526 in this window. Otherwise we have to reposition it. */
13528 /* PXW: Must be converted to pixels, probably. */
13529 && 0 <= w
->cursor
.vpos
13530 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13534 do_pending_window_change (1);
13535 /* If selected_window changed, redisplay again. */
13536 if (WINDOWP (selected_window
)
13537 && (w
= XWINDOW (selected_window
)) != sw
)
13540 /* We used to always goto end_of_redisplay here, but this
13541 isn't enough if we have a blinking cursor. */
13542 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13543 goto end_of_redisplay
;
13547 /* If highlighting the region, or if the cursor is in the echo area,
13548 then we can't just move the cursor. */
13549 else if (NILP (Vshow_trailing_whitespace
)
13550 && !cursor_in_echo_area
)
13553 struct glyph_row
*row
;
13555 /* Skip from tlbufpos to PT and see where it is. Note that
13556 PT may be in invisible text. If so, we will end at the
13557 next visible position. */
13558 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13559 NULL
, DEFAULT_FACE_ID
);
13560 it
.current_x
= this_line_start_x
;
13561 it
.current_y
= this_line_y
;
13562 it
.vpos
= this_line_vpos
;
13564 /* The call to move_it_to stops in front of PT, but
13565 moves over before-strings. */
13566 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13568 if (it
.vpos
== this_line_vpos
13569 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13572 eassert (this_line_vpos
== it
.vpos
);
13573 eassert (this_line_y
== it
.current_y
);
13574 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13576 *w
->desired_matrix
->method
= 0;
13577 debug_method_add (w
, "optimization 3");
13586 /* Text changed drastically or point moved off of line. */
13587 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, false);
13590 CHARPOS (this_line_start_pos
) = 0;
13591 ++clear_face_cache_count
;
13592 #ifdef HAVE_WINDOW_SYSTEM
13593 ++clear_image_cache_count
;
13596 /* Build desired matrices, and update the display. If
13597 consider_all_windows_p is non-zero, do it for all windows on all
13598 frames. Otherwise do it for selected_window, only. */
13600 if (consider_all_windows_p
)
13602 FOR_EACH_FRAME (tail
, frame
)
13603 XFRAME (frame
)->updated_p
= 0;
13605 propagate_buffer_redisplay ();
13607 FOR_EACH_FRAME (tail
, frame
)
13609 struct frame
*f
= XFRAME (frame
);
13611 /* We don't have to do anything for unselected terminal
13613 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13614 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13619 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13622 /* Only GC scrollbars when we redisplay the whole frame. */
13623 = f
->redisplay
|| !REDISPLAY_SOME_P ();
13624 /* Mark all the scroll bars to be removed; we'll redeem
13625 the ones we want when we redisplay their windows. */
13626 if (gcscrollbars
&& FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13627 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13629 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13630 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13631 /* Remember that the invisible frames need to be redisplayed next
13632 time they're visible. */
13633 else if (!REDISPLAY_SOME_P ())
13634 f
->redisplay
= true;
13636 /* The X error handler may have deleted that frame. */
13637 if (!FRAME_LIVE_P (f
))
13640 /* Any scroll bars which redisplay_windows should have
13641 nuked should now go away. */
13642 if (gcscrollbars
&& FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13643 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13645 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13647 /* If fonts changed on visible frame, display again. */
13648 if (f
->fonts_changed
)
13650 adjust_frame_glyphs (f
);
13651 f
->fonts_changed
= 0;
13655 /* See if we have to hscroll. */
13656 if (!f
->already_hscrolled_p
)
13658 f
->already_hscrolled_p
= 1;
13659 if (hscroll_windows (f
->root_window
))
13663 /* Prevent various kinds of signals during display
13664 update. stdio is not robust about handling
13665 signals, which can cause an apparent I/O error. */
13666 if (interrupt_input
)
13667 unrequest_sigio ();
13670 pending
|= update_frame (f
, 0, 0);
13671 f
->cursor_type_changed
= 0;
13677 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13681 /* Do the mark_window_display_accurate after all windows have
13682 been redisplayed because this call resets flags in buffers
13683 which are needed for proper redisplay. */
13684 FOR_EACH_FRAME (tail
, frame
)
13686 struct frame
*f
= XFRAME (frame
);
13689 f
->redisplay
= false;
13690 mark_window_display_accurate (f
->root_window
, 1);
13691 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13692 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13697 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13699 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13700 struct frame
*mini_frame
;
13702 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13703 /* Use list_of_error, not Qerror, so that
13704 we catch only errors and don't run the debugger. */
13705 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13707 redisplay_window_error
);
13708 if (update_miniwindow_p
)
13709 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13711 redisplay_window_error
);
13713 /* Compare desired and current matrices, perform output. */
13716 /* If fonts changed, display again. */
13717 if (sf
->fonts_changed
)
13720 /* Prevent various kinds of signals during display update.
13721 stdio is not robust about handling signals,
13722 which can cause an apparent I/O error. */
13723 if (interrupt_input
)
13724 unrequest_sigio ();
13727 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13729 if (hscroll_windows (selected_window
))
13732 XWINDOW (selected_window
)->must_be_updated_p
= true;
13733 pending
= update_frame (sf
, 0, 0);
13734 sf
->cursor_type_changed
= 0;
13737 /* We may have called echo_area_display at the top of this
13738 function. If the echo area is on another frame, that may
13739 have put text on a frame other than the selected one, so the
13740 above call to update_frame would not have caught it. Catch
13742 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13743 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13745 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13747 XWINDOW (mini_window
)->must_be_updated_p
= true;
13748 pending
|= update_frame (mini_frame
, 0, 0);
13749 mini_frame
->cursor_type_changed
= 0;
13750 if (!pending
&& hscroll_windows (mini_window
))
13755 /* If display was paused because of pending input, make sure we do a
13756 thorough update the next time. */
13759 /* Prevent the optimization at the beginning of
13760 redisplay_internal that tries a single-line update of the
13761 line containing the cursor in the selected window. */
13762 CHARPOS (this_line_start_pos
) = 0;
13764 /* Let the overlay arrow be updated the next time. */
13765 update_overlay_arrows (0);
13767 /* If we pause after scrolling, some rows in the current
13768 matrices of some windows are not valid. */
13769 if (!WINDOW_FULL_WIDTH_P (w
)
13770 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13771 update_mode_lines
= 36;
13775 if (!consider_all_windows_p
)
13777 /* This has already been done above if
13778 consider_all_windows_p is set. */
13779 if (XBUFFER (w
->contents
)->text
->redisplay
13780 && buffer_window_count (XBUFFER (w
->contents
)) > 1)
13781 /* This can happen if b->text->redisplay was set during
13783 propagate_buffer_redisplay ();
13784 mark_window_display_accurate_1 (w
, 1);
13786 /* Say overlay arrows are up to date. */
13787 update_overlay_arrows (1);
13789 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13790 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13793 update_mode_lines
= 0;
13794 windows_or_buffers_changed
= 0;
13797 /* Start SIGIO interrupts coming again. Having them off during the
13798 code above makes it less likely one will discard output, but not
13799 impossible, since there might be stuff in the system buffer here.
13800 But it is much hairier to try to do anything about that. */
13801 if (interrupt_input
)
13805 /* If a frame has become visible which was not before, redisplay
13806 again, so that we display it. Expose events for such a frame
13807 (which it gets when becoming visible) don't call the parts of
13808 redisplay constructing glyphs, so simply exposing a frame won't
13809 display anything in this case. So, we have to display these
13810 frames here explicitly. */
13815 FOR_EACH_FRAME (tail
, frame
)
13817 if (XFRAME (frame
)->visible
)
13821 if (new_count
!= number_of_visible_frames
)
13822 windows_or_buffers_changed
= 52;
13825 /* Change frame size now if a change is pending. */
13826 do_pending_window_change (1);
13828 /* If we just did a pending size change, or have additional
13829 visible frames, or selected_window changed, redisplay again. */
13830 if ((windows_or_buffers_changed
&& !pending
)
13831 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13834 /* Clear the face and image caches.
13836 We used to do this only if consider_all_windows_p. But the cache
13837 needs to be cleared if a timer creates images in the current
13838 buffer (e.g. the test case in Bug#6230). */
13840 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13842 clear_face_cache (0);
13843 clear_face_cache_count
= 0;
13846 #ifdef HAVE_WINDOW_SYSTEM
13847 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13849 clear_image_caches (Qnil
);
13850 clear_image_cache_count
= 0;
13852 #endif /* HAVE_WINDOW_SYSTEM */
13855 if (interrupt_input
&& interrupts_deferred
)
13858 unbind_to (count
, Qnil
);
13863 /* Redisplay, but leave alone any recent echo area message unless
13864 another message has been requested in its place.
13866 This is useful in situations where you need to redisplay but no
13867 user action has occurred, making it inappropriate for the message
13868 area to be cleared. See tracking_off and
13869 wait_reading_process_output for examples of these situations.
13871 FROM_WHERE is an integer saying from where this function was
13872 called. This is useful for debugging. */
13875 redisplay_preserve_echo_area (int from_where
)
13877 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13879 if (!NILP (echo_area_buffer
[1]))
13881 /* We have a previously displayed message, but no current
13882 message. Redisplay the previous message. */
13883 display_last_displayed_message_p
= 1;
13884 redisplay_internal ();
13885 display_last_displayed_message_p
= 0;
13888 redisplay_internal ();
13890 flush_frame (SELECTED_FRAME ());
13894 /* Function registered with record_unwind_protect in redisplay_internal. */
13897 unwind_redisplay (void)
13899 redisplaying_p
= 0;
13903 /* Mark the display of leaf window W as accurate or inaccurate.
13904 If ACCURATE_P is non-zero mark display of W as accurate. If
13905 ACCURATE_P is zero, arrange for W to be redisplayed the next
13906 time redisplay_internal is called. */
13909 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13911 struct buffer
*b
= XBUFFER (w
->contents
);
13913 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13914 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13915 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13919 b
->clip_changed
= false;
13920 b
->prevent_redisplay_optimizations_p
= false;
13921 eassert (buffer_window_count (b
) > 0);
13922 /* Resetting b->text->redisplay is problematic!
13923 In order to make it safer to do it here, redisplay_internal must
13924 have copied all b->text->redisplay to their respective windows. */
13925 b
->text
->redisplay
= false;
13927 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13928 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13929 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13930 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13932 w
->current_matrix
->buffer
= b
;
13933 w
->current_matrix
->begv
= BUF_BEGV (b
);
13934 w
->current_matrix
->zv
= BUF_ZV (b
);
13936 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13937 w
->last_cursor_off_p
= w
->cursor_off_p
;
13939 if (w
== XWINDOW (selected_window
))
13940 w
->last_point
= BUF_PT (b
);
13942 w
->last_point
= marker_position (w
->pointm
);
13944 w
->window_end_valid
= true;
13945 w
->update_mode_line
= false;
13948 w
->redisplay
= !accurate_p
;
13952 /* Mark the display of windows in the window tree rooted at WINDOW as
13953 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13954 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13955 be redisplayed the next time redisplay_internal is called. */
13958 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13962 for (; !NILP (window
); window
= w
->next
)
13964 w
= XWINDOW (window
);
13965 if (WINDOWP (w
->contents
))
13966 mark_window_display_accurate (w
->contents
, accurate_p
);
13968 mark_window_display_accurate_1 (w
, accurate_p
);
13972 update_overlay_arrows (1);
13974 /* Force a thorough redisplay the next time by setting
13975 last_arrow_position and last_arrow_string to t, which is
13976 unequal to any useful value of Voverlay_arrow_... */
13977 update_overlay_arrows (-1);
13981 /* Return value in display table DP (Lisp_Char_Table *) for character
13982 C. Since a display table doesn't have any parent, we don't have to
13983 follow parent. Do not call this function directly but use the
13984 macro DISP_CHAR_VECTOR. */
13987 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13991 if (ASCII_CHAR_P (c
))
13994 if (SUB_CHAR_TABLE_P (val
))
13995 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
14001 XSETCHAR_TABLE (table
, dp
);
14002 val
= char_table_ref (table
, c
);
14011 /***********************************************************************
14013 ***********************************************************************/
14015 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
14018 redisplay_windows (Lisp_Object window
)
14020 while (!NILP (window
))
14022 struct window
*w
= XWINDOW (window
);
14024 if (WINDOWP (w
->contents
))
14025 redisplay_windows (w
->contents
);
14026 else if (BUFFERP (w
->contents
))
14028 displayed_buffer
= XBUFFER (w
->contents
);
14029 /* Use list_of_error, not Qerror, so that
14030 we catch only errors and don't run the debugger. */
14031 internal_condition_case_1 (redisplay_window_0
, window
,
14033 redisplay_window_error
);
14041 redisplay_window_error (Lisp_Object ignore
)
14043 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
14048 redisplay_window_0 (Lisp_Object window
)
14050 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14051 redisplay_window (window
, false);
14056 redisplay_window_1 (Lisp_Object window
)
14058 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
14059 redisplay_window (window
, true);
14064 /* Set cursor position of W. PT is assumed to be displayed in ROW.
14065 DELTA and DELTA_BYTES are the numbers of characters and bytes by
14066 which positions recorded in ROW differ from current buffer
14069 Return 0 if cursor is not on this row, 1 otherwise. */
14072 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
14073 struct glyph_matrix
*matrix
,
14074 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
14077 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
14078 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
14079 struct glyph
*cursor
= NULL
;
14080 /* The last known character position in row. */
14081 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14083 ptrdiff_t pt_old
= PT
- delta
;
14084 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
14085 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14086 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
14087 /* A glyph beyond the edge of TEXT_AREA which we should never
14089 struct glyph
*glyphs_end
= end
;
14090 /* Non-zero means we've found a match for cursor position, but that
14091 glyph has the avoid_cursor_p flag set. */
14092 int match_with_avoid_cursor
= 0;
14093 /* Non-zero means we've seen at least one glyph that came from a
14095 int string_seen
= 0;
14096 /* Largest and smallest buffer positions seen so far during scan of
14098 ptrdiff_t bpos_max
= pos_before
;
14099 ptrdiff_t bpos_min
= pos_after
;
14100 /* Last buffer position covered by an overlay string with an integer
14101 `cursor' property. */
14102 ptrdiff_t bpos_covered
= 0;
14103 /* Non-zero means the display string on which to display the cursor
14104 comes from a text property, not from an overlay. */
14105 int string_from_text_prop
= 0;
14107 /* Don't even try doing anything if called for a mode-line or
14108 header-line row, since the rest of the code isn't prepared to
14109 deal with such calamities. */
14110 eassert (!row
->mode_line_p
);
14111 if (row
->mode_line_p
)
14114 /* Skip over glyphs not having an object at the start and the end of
14115 the row. These are special glyphs like truncation marks on
14116 terminal frames. */
14117 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
14119 if (!row
->reversed_p
)
14122 && INTEGERP (glyph
->object
)
14123 && glyph
->charpos
< 0)
14125 x
+= glyph
->pixel_width
;
14129 && INTEGERP ((end
- 1)->object
)
14130 /* CHARPOS is zero for blanks and stretch glyphs
14131 inserted by extend_face_to_end_of_line. */
14132 && (end
- 1)->charpos
<= 0)
14134 glyph_before
= glyph
- 1;
14141 /* If the glyph row is reversed, we need to process it from back
14142 to front, so swap the edge pointers. */
14143 glyphs_end
= end
= glyph
- 1;
14144 glyph
+= row
->used
[TEXT_AREA
] - 1;
14146 while (glyph
> end
+ 1
14147 && INTEGERP (glyph
->object
)
14148 && glyph
->charpos
< 0)
14151 x
-= glyph
->pixel_width
;
14153 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14155 /* By default, in reversed rows we put the cursor on the
14156 rightmost (first in the reading order) glyph. */
14157 for (g
= end
+ 1; g
< glyph
; g
++)
14158 x
+= g
->pixel_width
;
14160 && INTEGERP ((end
+ 1)->object
)
14161 && (end
+ 1)->charpos
<= 0)
14163 glyph_before
= glyph
+ 1;
14167 else if (row
->reversed_p
)
14169 /* In R2L rows that don't display text, put the cursor on the
14170 rightmost glyph. Case in point: an empty last line that is
14171 part of an R2L paragraph. */
14173 /* Avoid placing the cursor on the last glyph of the row, where
14174 on terminal frames we hold the vertical border between
14175 adjacent windows. */
14176 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14177 && !WINDOW_RIGHTMOST_P (w
)
14178 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14180 x
= -1; /* will be computed below, at label compute_x */
14183 /* Step 1: Try to find the glyph whose character position
14184 corresponds to point. If that's not possible, find 2 glyphs
14185 whose character positions are the closest to point, one before
14186 point, the other after it. */
14187 if (!row
->reversed_p
)
14188 while (/* not marched to end of glyph row */
14190 /* glyph was not inserted by redisplay for internal purposes */
14191 && !INTEGERP (glyph
->object
))
14193 if (BUFFERP (glyph
->object
))
14195 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14197 if (glyph
->charpos
> bpos_max
)
14198 bpos_max
= glyph
->charpos
;
14199 if (glyph
->charpos
< bpos_min
)
14200 bpos_min
= glyph
->charpos
;
14201 if (!glyph
->avoid_cursor_p
)
14203 /* If we hit point, we've found the glyph on which to
14204 display the cursor. */
14207 match_with_avoid_cursor
= 0;
14210 /* See if we've found a better approximation to
14211 POS_BEFORE or to POS_AFTER. */
14212 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14214 pos_before
= glyph
->charpos
;
14215 glyph_before
= glyph
;
14217 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14219 pos_after
= glyph
->charpos
;
14220 glyph_after
= glyph
;
14223 else if (dpos
== 0)
14224 match_with_avoid_cursor
= 1;
14226 else if (STRINGP (glyph
->object
))
14228 Lisp_Object chprop
;
14229 ptrdiff_t glyph_pos
= glyph
->charpos
;
14231 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14233 if (!NILP (chprop
))
14235 /* If the string came from a `display' text property,
14236 look up the buffer position of that property and
14237 use that position to update bpos_max, as if we
14238 actually saw such a position in one of the row's
14239 glyphs. This helps with supporting integer values
14240 of `cursor' property on the display string in
14241 situations where most or all of the row's buffer
14242 text is completely covered by display properties,
14243 so that no glyph with valid buffer positions is
14244 ever seen in the row. */
14245 ptrdiff_t prop_pos
=
14246 string_buffer_position_lim (glyph
->object
, pos_before
,
14249 if (prop_pos
>= pos_before
)
14250 bpos_max
= prop_pos
- 1;
14252 if (INTEGERP (chprop
))
14254 bpos_covered
= bpos_max
+ XINT (chprop
);
14255 /* If the `cursor' property covers buffer positions up
14256 to and including point, we should display cursor on
14257 this glyph. Note that, if a `cursor' property on one
14258 of the string's characters has an integer value, we
14259 will break out of the loop below _before_ we get to
14260 the position match above. IOW, integer values of
14261 the `cursor' property override the "exact match for
14262 point" strategy of positioning the cursor. */
14263 /* Implementation note: bpos_max == pt_old when, e.g.,
14264 we are in an empty line, where bpos_max is set to
14265 MATRIX_ROW_START_CHARPOS, see above. */
14266 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14275 x
+= glyph
->pixel_width
;
14278 else if (glyph
> end
) /* row is reversed */
14279 while (!INTEGERP (glyph
->object
))
14281 if (BUFFERP (glyph
->object
))
14283 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14285 if (glyph
->charpos
> bpos_max
)
14286 bpos_max
= glyph
->charpos
;
14287 if (glyph
->charpos
< bpos_min
)
14288 bpos_min
= glyph
->charpos
;
14289 if (!glyph
->avoid_cursor_p
)
14293 match_with_avoid_cursor
= 0;
14296 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14298 pos_before
= glyph
->charpos
;
14299 glyph_before
= glyph
;
14301 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14303 pos_after
= glyph
->charpos
;
14304 glyph_after
= glyph
;
14307 else if (dpos
== 0)
14308 match_with_avoid_cursor
= 1;
14310 else if (STRINGP (glyph
->object
))
14312 Lisp_Object chprop
;
14313 ptrdiff_t glyph_pos
= glyph
->charpos
;
14315 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14317 if (!NILP (chprop
))
14319 ptrdiff_t prop_pos
=
14320 string_buffer_position_lim (glyph
->object
, pos_before
,
14323 if (prop_pos
>= pos_before
)
14324 bpos_max
= prop_pos
- 1;
14326 if (INTEGERP (chprop
))
14328 bpos_covered
= bpos_max
+ XINT (chprop
);
14329 /* If the `cursor' property covers buffer positions up
14330 to and including point, we should display cursor on
14332 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14341 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14343 x
--; /* can't use any pixel_width */
14346 x
-= glyph
->pixel_width
;
14349 /* Step 2: If we didn't find an exact match for point, we need to
14350 look for a proper place to put the cursor among glyphs between
14351 GLYPH_BEFORE and GLYPH_AFTER. */
14352 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14353 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14354 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14356 /* An empty line has a single glyph whose OBJECT is zero and
14357 whose CHARPOS is the position of a newline on that line.
14358 Note that on a TTY, there are more glyphs after that, which
14359 were produced by extend_face_to_end_of_line, but their
14360 CHARPOS is zero or negative. */
14362 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14363 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14364 /* On a TTY, continued and truncated rows also have a glyph at
14365 their end whose OBJECT is zero and whose CHARPOS is
14366 positive (the continuation and truncation glyphs), but such
14367 rows are obviously not "empty". */
14368 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14370 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14372 ptrdiff_t ellipsis_pos
;
14374 /* Scan back over the ellipsis glyphs. */
14375 if (!row
->reversed_p
)
14377 ellipsis_pos
= (glyph
- 1)->charpos
;
14378 while (glyph
> row
->glyphs
[TEXT_AREA
]
14379 && (glyph
- 1)->charpos
== ellipsis_pos
)
14380 glyph
--, x
-= glyph
->pixel_width
;
14381 /* That loop always goes one position too far, including
14382 the glyph before the ellipsis. So scan forward over
14384 x
+= glyph
->pixel_width
;
14387 else /* row is reversed */
14389 ellipsis_pos
= (glyph
+ 1)->charpos
;
14390 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14391 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14392 glyph
++, x
+= glyph
->pixel_width
;
14393 x
-= glyph
->pixel_width
;
14397 else if (match_with_avoid_cursor
)
14399 cursor
= glyph_after
;
14402 else if (string_seen
)
14404 int incr
= row
->reversed_p
? -1 : +1;
14406 /* Need to find the glyph that came out of a string which is
14407 present at point. That glyph is somewhere between
14408 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14409 positioned between POS_BEFORE and POS_AFTER in the
14411 struct glyph
*start
, *stop
;
14412 ptrdiff_t pos
= pos_before
;
14416 /* If the row ends in a newline from a display string,
14417 reordering could have moved the glyphs belonging to the
14418 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14419 in this case we extend the search to the last glyph in
14420 the row that was not inserted by redisplay. */
14421 if (row
->ends_in_newline_from_string_p
)
14424 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14427 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14428 correspond to POS_BEFORE and POS_AFTER, respectively. We
14429 need START and STOP in the order that corresponds to the
14430 row's direction as given by its reversed_p flag. If the
14431 directionality of characters between POS_BEFORE and
14432 POS_AFTER is the opposite of the row's base direction,
14433 these characters will have been reordered for display,
14434 and we need to reverse START and STOP. */
14435 if (!row
->reversed_p
)
14437 start
= min (glyph_before
, glyph_after
);
14438 stop
= max (glyph_before
, glyph_after
);
14442 start
= max (glyph_before
, glyph_after
);
14443 stop
= min (glyph_before
, glyph_after
);
14445 for (glyph
= start
+ incr
;
14446 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14449 /* Any glyphs that come from the buffer are here because
14450 of bidi reordering. Skip them, and only pay
14451 attention to glyphs that came from some string. */
14452 if (STRINGP (glyph
->object
))
14456 /* If the display property covers the newline, we
14457 need to search for it one position farther. */
14458 ptrdiff_t lim
= pos_after
14459 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14461 string_from_text_prop
= 0;
14462 str
= glyph
->object
;
14463 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14464 if (tem
== 0 /* from overlay */
14467 /* If the string from which this glyph came is
14468 found in the buffer at point, or at position
14469 that is closer to point than pos_after, then
14470 we've found the glyph we've been looking for.
14471 If it comes from an overlay (tem == 0), and
14472 it has the `cursor' property on one of its
14473 glyphs, record that glyph as a candidate for
14474 displaying the cursor. (As in the
14475 unidirectional version, we will display the
14476 cursor on the last candidate we find.) */
14479 || (tem
- pt_old
> 0 && tem
< pos_after
))
14481 /* The glyphs from this string could have
14482 been reordered. Find the one with the
14483 smallest string position. Or there could
14484 be a character in the string with the
14485 `cursor' property, which means display
14486 cursor on that character's glyph. */
14487 ptrdiff_t strpos
= glyph
->charpos
;
14492 string_from_text_prop
= 1;
14495 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14496 && EQ (glyph
->object
, str
);
14500 ptrdiff_t gpos
= glyph
->charpos
;
14502 cprop
= Fget_char_property (make_number (gpos
),
14510 if (tem
&& glyph
->charpos
< strpos
)
14512 strpos
= glyph
->charpos
;
14518 || (tem
- pt_old
> 0 && tem
< pos_after
))
14522 pos
= tem
+ 1; /* don't find previous instances */
14524 /* This string is not what we want; skip all of the
14525 glyphs that came from it. */
14526 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14527 && EQ (glyph
->object
, str
))
14534 /* If we reached the end of the line, and END was from a string,
14535 the cursor is not on this line. */
14537 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14538 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14539 && STRINGP (end
->object
)
14540 && row
->continued_p
)
14543 /* A truncated row may not include PT among its character positions.
14544 Setting the cursor inside the scroll margin will trigger
14545 recalculation of hscroll in hscroll_window_tree. But if a
14546 display string covers point, defer to the string-handling
14547 code below to figure this out. */
14548 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14550 cursor
= glyph_before
;
14553 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14554 /* Zero-width characters produce no glyphs. */
14556 && (row
->reversed_p
14557 ? glyph_after
> glyphs_end
14558 : glyph_after
< glyphs_end
)))
14560 cursor
= glyph_after
;
14566 if (cursor
!= NULL
)
14568 else if (glyph
== glyphs_end
14569 && pos_before
== pos_after
14570 && STRINGP ((row
->reversed_p
14571 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14572 : row
->glyphs
[TEXT_AREA
])->object
))
14574 /* If all the glyphs of this row came from strings, put the
14575 cursor on the first glyph of the row. This avoids having the
14576 cursor outside of the text area in this very rare and hard
14580 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14581 : row
->glyphs
[TEXT_AREA
];
14587 /* Need to compute x that corresponds to GLYPH. */
14588 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14590 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14592 x
+= g
->pixel_width
;
14596 /* ROW could be part of a continued line, which, under bidi
14597 reordering, might have other rows whose start and end charpos
14598 occlude point. Only set w->cursor if we found a better
14599 approximation to the cursor position than we have from previously
14600 examined candidate rows belonging to the same continued line. */
14601 if (/* We already have a candidate row. */
14602 w
->cursor
.vpos
>= 0
14603 /* That candidate is not the row we are processing. */
14604 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14605 /* Make sure cursor.vpos specifies a row whose start and end
14606 charpos occlude point, and it is valid candidate for being a
14607 cursor-row. This is because some callers of this function
14608 leave cursor.vpos at the row where the cursor was displayed
14609 during the last redisplay cycle. */
14610 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14611 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14612 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14615 = MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14617 /* Don't consider glyphs that are outside TEXT_AREA. */
14618 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14620 /* Keep the candidate whose buffer position is the closest to
14621 point or has the `cursor' property. */
14622 if (/* Previous candidate is a glyph in TEXT_AREA of that row. */
14623 w
->cursor
.hpos
>= 0
14624 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14625 && ((BUFFERP (g1
->object
)
14626 && (g1
->charpos
== pt_old
/* An exact match always wins. */
14627 || (BUFFERP (glyph
->object
)
14628 && eabs (g1
->charpos
- pt_old
)
14629 < eabs (glyph
->charpos
- pt_old
))))
14630 /* Previous candidate is a glyph from a string that has
14631 a non-nil `cursor' property. */
14632 || (STRINGP (g1
->object
)
14633 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14634 Qcursor
, g1
->object
))
14635 /* Previous candidate is from the same display
14636 string as this one, and the display string
14637 came from a text property. */
14638 || (EQ (g1
->object
, glyph
->object
)
14639 && string_from_text_prop
)
14640 /* this candidate is from newline and its
14641 position is not an exact match */
14642 || (INTEGERP (glyph
->object
)
14643 && glyph
->charpos
!= pt_old
)))))
14645 /* If this candidate gives an exact match, use that. */
14646 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14647 /* If this candidate is a glyph created for the
14648 terminating newline of a line, and point is on that
14649 newline, it wins because it's an exact match. */
14650 || (!row
->continued_p
14651 && INTEGERP (glyph
->object
)
14652 && glyph
->charpos
== 0
14653 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14654 /* Otherwise, keep the candidate that comes from a row
14655 spanning less buffer positions. This may win when one or
14656 both candidate positions are on glyphs that came from
14657 display strings, for which we cannot compare buffer
14659 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14660 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14661 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14664 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14666 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14667 w
->cursor
.y
= row
->y
+ dy
;
14669 if (w
== XWINDOW (selected_window
))
14671 if (!row
->continued_p
14672 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14675 this_line_buffer
= XBUFFER (w
->contents
);
14677 CHARPOS (this_line_start_pos
)
14678 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14679 BYTEPOS (this_line_start_pos
)
14680 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14682 CHARPOS (this_line_end_pos
)
14683 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14684 BYTEPOS (this_line_end_pos
)
14685 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14687 this_line_y
= w
->cursor
.y
;
14688 this_line_pixel_height
= row
->height
;
14689 this_line_vpos
= w
->cursor
.vpos
;
14690 this_line_start_x
= row
->x
;
14693 CHARPOS (this_line_start_pos
) = 0;
14700 /* Run window scroll functions, if any, for WINDOW with new window
14701 start STARTP. Sets the window start of WINDOW to that position.
14703 We assume that the window's buffer is really current. */
14705 static struct text_pos
14706 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14708 struct window
*w
= XWINDOW (window
);
14709 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14711 eassert (current_buffer
== XBUFFER (w
->contents
));
14713 if (!NILP (Vwindow_scroll_functions
))
14715 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14716 make_number (CHARPOS (startp
)));
14717 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14718 /* In case the hook functions switch buffers. */
14719 set_buffer_internal (XBUFFER (w
->contents
));
14726 /* Make sure the line containing the cursor is fully visible.
14727 A value of 1 means there is nothing to be done.
14728 (Either the line is fully visible, or it cannot be made so,
14729 or we cannot tell.)
14731 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14732 is higher than window.
14734 A value of 0 means the caller should do scrolling
14735 as if point had gone off the screen. */
14738 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14740 struct glyph_matrix
*matrix
;
14741 struct glyph_row
*row
;
14744 if (!make_cursor_line_fully_visible_p
)
14747 /* It's not always possible to find the cursor, e.g, when a window
14748 is full of overlay strings. Don't do anything in that case. */
14749 if (w
->cursor
.vpos
< 0)
14752 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14753 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14755 /* If the cursor row is not partially visible, there's nothing to do. */
14756 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14759 /* If the row the cursor is in is taller than the window's height,
14760 it's not clear what to do, so do nothing. */
14761 window_height
= window_box_height (w
);
14762 if (row
->height
>= window_height
)
14764 if (!force_p
|| MINI_WINDOW_P (w
)
14765 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14772 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14773 non-zero means only WINDOW is redisplayed in redisplay_internal.
14774 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14775 in redisplay_window to bring a partially visible line into view in
14776 the case that only the cursor has moved.
14778 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14779 last screen line's vertical height extends past the end of the screen.
14783 1 if scrolling succeeded
14785 0 if scrolling didn't find point.
14787 -1 if new fonts have been loaded so that we must interrupt
14788 redisplay, adjust glyph matrices, and try again. */
14794 SCROLLING_NEED_LARGER_MATRICES
14797 /* If scroll-conservatively is more than this, never recenter.
14799 If you change this, don't forget to update the doc string of
14800 `scroll-conservatively' and the Emacs manual. */
14801 #define SCROLL_LIMIT 100
14804 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14805 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14806 int temp_scroll_step
, int last_line_misfit
)
14808 struct window
*w
= XWINDOW (window
);
14809 struct frame
*f
= XFRAME (w
->frame
);
14810 struct text_pos pos
, startp
;
14812 int this_scroll_margin
, scroll_max
, rc
, height
;
14813 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14814 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14815 Lisp_Object aggressive
;
14816 /* We will never try scrolling more than this number of lines. */
14817 int scroll_limit
= SCROLL_LIMIT
;
14818 int frame_line_height
= default_line_pixel_height (w
);
14819 int window_total_lines
14820 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14823 debug_method_add (w
, "try_scrolling");
14826 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14828 /* Compute scroll margin height in pixels. We scroll when point is
14829 within this distance from the top or bottom of the window. */
14830 if (scroll_margin
> 0)
14831 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14832 * frame_line_height
;
14834 this_scroll_margin
= 0;
14836 /* Force arg_scroll_conservatively to have a reasonable value, to
14837 avoid scrolling too far away with slow move_it_* functions. Note
14838 that the user can supply scroll-conservatively equal to
14839 `most-positive-fixnum', which can be larger than INT_MAX. */
14840 if (arg_scroll_conservatively
> scroll_limit
)
14842 arg_scroll_conservatively
= scroll_limit
+ 1;
14843 scroll_max
= scroll_limit
* frame_line_height
;
14845 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14846 /* Compute how much we should try to scroll maximally to bring
14847 point into view. */
14848 scroll_max
= (max (scroll_step
,
14849 max (arg_scroll_conservatively
, temp_scroll_step
))
14850 * frame_line_height
);
14851 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14852 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14853 /* We're trying to scroll because of aggressive scrolling but no
14854 scroll_step is set. Choose an arbitrary one. */
14855 scroll_max
= 10 * frame_line_height
;
14861 /* Decide whether to scroll down. */
14862 if (PT
> CHARPOS (startp
))
14864 int scroll_margin_y
;
14866 /* Compute the pixel ypos of the scroll margin, then move IT to
14867 either that ypos or PT, whichever comes first. */
14868 start_display (&it
, w
, startp
);
14869 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14870 - frame_line_height
* extra_scroll_margin_lines
;
14871 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14872 (MOVE_TO_POS
| MOVE_TO_Y
));
14874 if (PT
> CHARPOS (it
.current
.pos
))
14876 int y0
= line_bottom_y (&it
);
14877 /* Compute how many pixels below window bottom to stop searching
14878 for PT. This avoids costly search for PT that is far away if
14879 the user limited scrolling by a small number of lines, but
14880 always finds PT if scroll_conservatively is set to a large
14881 number, such as most-positive-fixnum. */
14882 int slack
= max (scroll_max
, 10 * frame_line_height
);
14883 int y_to_move
= it
.last_visible_y
+ slack
;
14885 /* Compute the distance from the scroll margin to PT or to
14886 the scroll limit, whichever comes first. This should
14887 include the height of the cursor line, to make that line
14889 move_it_to (&it
, PT
, -1, y_to_move
,
14890 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14891 dy
= line_bottom_y (&it
) - y0
;
14893 if (dy
> scroll_max
)
14894 return SCROLLING_FAILED
;
14903 /* Point is in or below the bottom scroll margin, so move the
14904 window start down. If scrolling conservatively, move it just
14905 enough down to make point visible. If scroll_step is set,
14906 move it down by scroll_step. */
14907 if (arg_scroll_conservatively
)
14909 = min (max (dy
, frame_line_height
),
14910 frame_line_height
* arg_scroll_conservatively
);
14911 else if (scroll_step
|| temp_scroll_step
)
14912 amount_to_scroll
= scroll_max
;
14915 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14916 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14917 if (NUMBERP (aggressive
))
14919 double float_amount
= XFLOATINT (aggressive
) * height
;
14920 int aggressive_scroll
= float_amount
;
14921 if (aggressive_scroll
== 0 && float_amount
> 0)
14922 aggressive_scroll
= 1;
14923 /* Don't let point enter the scroll margin near top of
14924 the window. This could happen if the value of
14925 scroll_up_aggressively is too large and there are
14926 non-zero margins, because scroll_up_aggressively
14927 means put point that fraction of window height
14928 _from_the_bottom_margin_. */
14929 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14930 aggressive_scroll
= height
- 2*this_scroll_margin
;
14931 amount_to_scroll
= dy
+ aggressive_scroll
;
14935 if (amount_to_scroll
<= 0)
14936 return SCROLLING_FAILED
;
14938 start_display (&it
, w
, startp
);
14939 if (arg_scroll_conservatively
<= scroll_limit
)
14940 move_it_vertically (&it
, amount_to_scroll
);
14943 /* Extra precision for users who set scroll-conservatively
14944 to a large number: make sure the amount we scroll
14945 the window start is never less than amount_to_scroll,
14946 which was computed as distance from window bottom to
14947 point. This matters when lines at window top and lines
14948 below window bottom have different height. */
14950 void *it1data
= NULL
;
14951 /* We use a temporary it1 because line_bottom_y can modify
14952 its argument, if it moves one line down; see there. */
14955 SAVE_IT (it1
, it
, it1data
);
14956 start_y
= line_bottom_y (&it1
);
14958 RESTORE_IT (&it
, &it
, it1data
);
14959 move_it_by_lines (&it
, 1);
14960 SAVE_IT (it1
, it
, it1data
);
14961 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14964 /* If STARTP is unchanged, move it down another screen line. */
14965 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14966 move_it_by_lines (&it
, 1);
14967 startp
= it
.current
.pos
;
14971 struct text_pos scroll_margin_pos
= startp
;
14974 /* See if point is inside the scroll margin at the top of the
14976 if (this_scroll_margin
)
14980 start_display (&it
, w
, startp
);
14981 y_start
= it
.current_y
;
14982 move_it_vertically (&it
, this_scroll_margin
);
14983 scroll_margin_pos
= it
.current
.pos
;
14984 /* If we didn't move enough before hitting ZV, request
14985 additional amount of scroll, to move point out of the
14987 if (IT_CHARPOS (it
) == ZV
14988 && it
.current_y
- y_start
< this_scroll_margin
)
14989 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14992 if (PT
< CHARPOS (scroll_margin_pos
))
14994 /* Point is in the scroll margin at the top of the window or
14995 above what is displayed in the window. */
14998 /* Compute the vertical distance from PT to the scroll
14999 margin position. Move as far as scroll_max allows, or
15000 one screenful, or 10 screen lines, whichever is largest.
15001 Give up if distance is greater than scroll_max or if we
15002 didn't reach the scroll margin position. */
15003 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
15004 start_display (&it
, w
, pos
);
15006 y_to_move
= max (it
.last_visible_y
,
15007 max (scroll_max
, 10 * frame_line_height
));
15008 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
15010 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15011 dy
= it
.current_y
- y0
;
15012 if (dy
> scroll_max
15013 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
15014 return SCROLLING_FAILED
;
15016 /* Additional scroll for when ZV was too close to point. */
15019 /* Compute new window start. */
15020 start_display (&it
, w
, startp
);
15022 if (arg_scroll_conservatively
)
15023 amount_to_scroll
= max (dy
, frame_line_height
*
15024 max (scroll_step
, temp_scroll_step
));
15025 else if (scroll_step
|| temp_scroll_step
)
15026 amount_to_scroll
= scroll_max
;
15029 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
15030 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
15031 if (NUMBERP (aggressive
))
15033 double float_amount
= XFLOATINT (aggressive
) * height
;
15034 int aggressive_scroll
= float_amount
;
15035 if (aggressive_scroll
== 0 && float_amount
> 0)
15036 aggressive_scroll
= 1;
15037 /* Don't let point enter the scroll margin near
15038 bottom of the window, if the value of
15039 scroll_down_aggressively happens to be too
15041 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
15042 aggressive_scroll
= height
- 2*this_scroll_margin
;
15043 amount_to_scroll
= dy
+ aggressive_scroll
;
15047 if (amount_to_scroll
<= 0)
15048 return SCROLLING_FAILED
;
15050 move_it_vertically_backward (&it
, amount_to_scroll
);
15051 startp
= it
.current
.pos
;
15055 /* Run window scroll functions. */
15056 startp
= run_window_scroll_functions (window
, startp
);
15058 /* Display the window. Give up if new fonts are loaded, or if point
15060 if (!try_window (window
, startp
, 0))
15061 rc
= SCROLLING_NEED_LARGER_MATRICES
;
15062 else if (w
->cursor
.vpos
< 0)
15064 clear_glyph_matrix (w
->desired_matrix
);
15065 rc
= SCROLLING_FAILED
;
15069 /* Maybe forget recorded base line for line number display. */
15070 if (!just_this_one_p
15071 || current_buffer
->clip_changed
15072 || BEG_UNCHANGED
< CHARPOS (startp
))
15073 w
->base_line_number
= 0;
15075 /* If cursor ends up on a partially visible line,
15076 treat that as being off the bottom of the screen. */
15077 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
15078 /* It's possible that the cursor is on the first line of the
15079 buffer, which is partially obscured due to a vscroll
15080 (Bug#7537). In that case, avoid looping forever. */
15081 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
15083 clear_glyph_matrix (w
->desired_matrix
);
15084 ++extra_scroll_margin_lines
;
15087 rc
= SCROLLING_SUCCESS
;
15094 /* Compute a suitable window start for window W if display of W starts
15095 on a continuation line. Value is non-zero if a new window start
15098 The new window start will be computed, based on W's width, starting
15099 from the start of the continued line. It is the start of the
15100 screen line with the minimum distance from the old start W->start. */
15103 compute_window_start_on_continuation_line (struct window
*w
)
15105 struct text_pos pos
, start_pos
;
15106 int window_start_changed_p
= 0;
15108 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
15110 /* If window start is on a continuation line... Window start may be
15111 < BEGV in case there's invisible text at the start of the
15112 buffer (M-x rmail, for example). */
15113 if (CHARPOS (start_pos
) > BEGV
15114 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
15117 struct glyph_row
*row
;
15119 /* Handle the case that the window start is out of range. */
15120 if (CHARPOS (start_pos
) < BEGV
)
15121 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
15122 else if (CHARPOS (start_pos
) > ZV
)
15123 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
15125 /* Find the start of the continued line. This should be fast
15126 because find_newline is fast (newline cache). */
15127 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
15128 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
15129 row
, DEFAULT_FACE_ID
);
15130 reseat_at_previous_visible_line_start (&it
);
15132 /* If the line start is "too far" away from the window start,
15133 say it takes too much time to compute a new window start. */
15134 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15135 /* PXW: Do we need upper bounds here? */
15136 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15138 int min_distance
, distance
;
15140 /* Move forward by display lines to find the new window
15141 start. If window width was enlarged, the new start can
15142 be expected to be > the old start. If window width was
15143 decreased, the new window start will be < the old start.
15144 So, we're looking for the display line start with the
15145 minimum distance from the old window start. */
15146 pos
= it
.current
.pos
;
15147 min_distance
= INFINITY
;
15148 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15149 distance
< min_distance
)
15151 min_distance
= distance
;
15152 pos
= it
.current
.pos
;
15153 if (it
.line_wrap
== WORD_WRAP
)
15155 /* Under WORD_WRAP, move_it_by_lines is likely to
15156 overshoot and stop not at the first, but the
15157 second character from the left margin. So in
15158 that case, we need a more tight control on the X
15159 coordinate of the iterator than move_it_by_lines
15160 promises in its contract. The method is to first
15161 go to the last (rightmost) visible character of a
15162 line, then move to the leftmost character on the
15163 next line in a separate call. */
15164 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
15165 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15166 move_it_to (&it
, ZV
, 0,
15167 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
15168 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15171 move_it_by_lines (&it
, 1);
15174 /* Set the window start there. */
15175 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15176 window_start_changed_p
= 1;
15180 return window_start_changed_p
;
15184 /* Try cursor movement in case text has not changed in window WINDOW,
15185 with window start STARTP. Value is
15187 CURSOR_MOVEMENT_SUCCESS if successful
15189 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15191 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15192 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15193 we want to scroll as if scroll-step were set to 1. See the code.
15195 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15196 which case we have to abort this redisplay, and adjust matrices
15201 CURSOR_MOVEMENT_SUCCESS
,
15202 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15203 CURSOR_MOVEMENT_MUST_SCROLL
,
15204 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15208 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15210 struct window
*w
= XWINDOW (window
);
15211 struct frame
*f
= XFRAME (w
->frame
);
15212 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15215 if (inhibit_try_cursor_movement
)
15219 /* Previously, there was a check for Lisp integer in the
15220 if-statement below. Now, this field is converted to
15221 ptrdiff_t, thus zero means invalid position in a buffer. */
15222 eassert (w
->last_point
> 0);
15223 /* Likewise there was a check whether window_end_vpos is nil or larger
15224 than the window. Now window_end_vpos is int and so never nil, but
15225 let's leave eassert to check whether it fits in the window. */
15226 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
15228 /* Handle case where text has not changed, only point, and it has
15229 not moved off the frame. */
15230 if (/* Point may be in this window. */
15231 PT
>= CHARPOS (startp
)
15232 /* Selective display hasn't changed. */
15233 && !current_buffer
->clip_changed
15234 /* Function force-mode-line-update is used to force a thorough
15235 redisplay. It sets either windows_or_buffers_changed or
15236 update_mode_lines. So don't take a shortcut here for these
15238 && !update_mode_lines
15239 && !windows_or_buffers_changed
15240 && !f
->cursor_type_changed
15241 && NILP (Vshow_trailing_whitespace
)
15242 /* This code is not used for mini-buffer for the sake of the case
15243 of redisplaying to replace an echo area message; since in
15244 that case the mini-buffer contents per se are usually
15245 unchanged. This code is of no real use in the mini-buffer
15246 since the handling of this_line_start_pos, etc., in redisplay
15247 handles the same cases. */
15248 && !EQ (window
, minibuf_window
)
15249 && (FRAME_WINDOW_P (f
)
15250 || !overlay_arrow_in_current_buffer_p ()))
15252 int this_scroll_margin
, top_scroll_margin
;
15253 struct glyph_row
*row
= NULL
;
15254 int frame_line_height
= default_line_pixel_height (w
);
15255 int window_total_lines
15256 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15259 debug_method_add (w
, "cursor movement");
15262 /* Scroll if point within this distance from the top or bottom
15263 of the window. This is a pixel value. */
15264 if (scroll_margin
> 0)
15266 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15267 this_scroll_margin
*= frame_line_height
;
15270 this_scroll_margin
= 0;
15272 top_scroll_margin
= this_scroll_margin
;
15273 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15274 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15276 /* Start with the row the cursor was displayed during the last
15277 not paused redisplay. Give up if that row is not valid. */
15278 if (w
->last_cursor_vpos
< 0
15279 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15280 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15283 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15284 if (row
->mode_line_p
)
15286 if (!row
->enabled_p
)
15287 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15290 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15292 int scroll_p
= 0, must_scroll
= 0;
15293 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15295 if (PT
> w
->last_point
)
15297 /* Point has moved forward. */
15298 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15299 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15301 eassert (row
->enabled_p
);
15305 /* If the end position of a row equals the start
15306 position of the next row, and PT is at that position,
15307 we would rather display cursor in the next line. */
15308 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15309 && MATRIX_ROW_END_CHARPOS (row
) == PT
15310 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15311 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15312 && !cursor_row_p (row
))
15315 /* If within the scroll margin, scroll. Note that
15316 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15317 the next line would be drawn, and that
15318 this_scroll_margin can be zero. */
15319 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15320 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15321 /* Line is completely visible last line in window
15322 and PT is to be set in the next line. */
15323 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15324 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15325 && !row
->ends_at_zv_p
15326 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15329 else if (PT
< w
->last_point
)
15331 /* Cursor has to be moved backward. Note that PT >=
15332 CHARPOS (startp) because of the outer if-statement. */
15333 while (!row
->mode_line_p
15334 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15335 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15336 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15337 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15338 row
> w
->current_matrix
->rows
15339 && (row
-1)->ends_in_newline_from_string_p
))))
15340 && (row
->y
> top_scroll_margin
15341 || CHARPOS (startp
) == BEGV
))
15343 eassert (row
->enabled_p
);
15347 /* Consider the following case: Window starts at BEGV,
15348 there is invisible, intangible text at BEGV, so that
15349 display starts at some point START > BEGV. It can
15350 happen that we are called with PT somewhere between
15351 BEGV and START. Try to handle that case. */
15352 if (row
< w
->current_matrix
->rows
15353 || row
->mode_line_p
)
15355 row
= w
->current_matrix
->rows
;
15356 if (row
->mode_line_p
)
15360 /* Due to newlines in overlay strings, we may have to
15361 skip forward over overlay strings. */
15362 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15363 && MATRIX_ROW_END_CHARPOS (row
) == PT
15364 && !cursor_row_p (row
))
15367 /* If within the scroll margin, scroll. */
15368 if (row
->y
< top_scroll_margin
15369 && CHARPOS (startp
) != BEGV
)
15374 /* Cursor did not move. So don't scroll even if cursor line
15375 is partially visible, as it was so before. */
15376 rc
= CURSOR_MOVEMENT_SUCCESS
;
15379 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15380 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15382 /* if PT is not in the glyph row, give up. */
15383 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15386 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15387 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15389 struct glyph_row
*row1
;
15391 /* If rows are bidi-reordered and point moved, back up
15392 until we find a row that does not belong to a
15393 continuation line. This is because we must consider
15394 all rows of a continued line as candidates for the
15395 new cursor positioning, since row start and end
15396 positions change non-linearly with vertical position
15398 /* FIXME: Revisit this when glyph ``spilling'' in
15399 continuation lines' rows is implemented for
15400 bidi-reordered rows. */
15401 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15402 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15405 /* If we hit the beginning of the displayed portion
15406 without finding the first row of a continued
15410 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15413 eassert (row
->enabled_p
);
15418 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15419 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15420 /* Make sure this isn't a header line by any chance, since
15421 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15422 && !row
->mode_line_p
15423 && make_cursor_line_fully_visible_p
)
15425 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15426 && !row
->ends_at_zv_p
15427 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15428 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15429 else if (row
->height
> window_box_height (w
))
15431 /* If we end up in a partially visible line, let's
15432 make it fully visible, except when it's taller
15433 than the window, in which case we can't do much
15436 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15440 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15441 if (!cursor_row_fully_visible_p (w
, 0, 1))
15442 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15444 rc
= CURSOR_MOVEMENT_SUCCESS
;
15448 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15449 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15450 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15452 /* With bidi-reordered rows, there could be more than
15453 one candidate row whose start and end positions
15454 occlude point. We need to let set_cursor_from_row
15455 find the best candidate. */
15456 /* FIXME: Revisit this when glyph ``spilling'' in
15457 continuation lines' rows is implemented for
15458 bidi-reordered rows. */
15463 int at_zv_p
= 0, exact_match_p
= 0;
15465 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15466 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15467 && cursor_row_p (row
))
15468 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15470 /* As soon as we've found the exact match for point,
15471 or the first suitable row whose ends_at_zv_p flag
15472 is set, we are done. */
15474 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15476 && w
->cursor
.hpos
>= 0
15477 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15480 struct glyph_row
*candidate
=
15481 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15483 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15484 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15487 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15488 || (INTEGERP (g
->object
)
15489 && (g
->charpos
== PT
15490 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15492 if (rv
&& (at_zv_p
|| exact_match_p
))
15494 rc
= CURSOR_MOVEMENT_SUCCESS
;
15497 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15501 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15502 || row
->continued_p
)
15503 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15504 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15505 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15506 /* If we didn't find any candidate rows, or exited the
15507 loop before all the candidates were examined, signal
15508 to the caller that this method failed. */
15509 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15511 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15512 && !row
->continued_p
))
15513 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15515 rc
= CURSOR_MOVEMENT_SUCCESS
;
15521 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15523 rc
= CURSOR_MOVEMENT_SUCCESS
;
15528 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15529 && MATRIX_ROW_START_CHARPOS (row
) == PT
15530 && cursor_row_p (row
));
15538 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15542 set_vertical_scroll_bar (struct window
*w
)
15544 ptrdiff_t start
, end
, whole
;
15546 /* Calculate the start and end positions for the current window.
15547 At some point, it would be nice to choose between scrollbars
15548 which reflect the whole buffer size, with special markers
15549 indicating narrowing, and scrollbars which reflect only the
15552 Note that mini-buffers sometimes aren't displaying any text. */
15553 if (!MINI_WINDOW_P (w
)
15554 || (w
== XWINDOW (minibuf_window
)
15555 && NILP (echo_area_buffer
[0])))
15557 struct buffer
*buf
= XBUFFER (w
->contents
);
15558 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15559 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15560 /* I don't think this is guaranteed to be right. For the
15561 moment, we'll pretend it is. */
15562 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15566 if (whole
< (end
- start
))
15567 whole
= end
- start
;
15570 start
= end
= whole
= 0;
15572 /* Indicate what this scroll bar ought to be displaying now. */
15573 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15574 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15575 (w
, end
- start
, whole
, start
);
15579 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15580 selected_window is redisplayed.
15582 We can return without actually redisplaying the window if fonts has been
15583 changed on window's frame. In that case, redisplay_internal will retry. */
15586 redisplay_window (Lisp_Object window
, bool just_this_one_p
)
15588 struct window
*w
= XWINDOW (window
);
15589 struct frame
*f
= XFRAME (w
->frame
);
15590 struct buffer
*buffer
= XBUFFER (w
->contents
);
15591 struct buffer
*old
= current_buffer
;
15592 struct text_pos lpoint
, opoint
, startp
;
15593 int update_mode_line
;
15596 /* Record it now because it's overwritten. */
15597 bool current_matrix_up_to_date_p
= false;
15598 bool used_current_matrix_p
= false;
15599 /* This is less strict than current_matrix_up_to_date_p.
15600 It indicates that the buffer contents and narrowing are unchanged. */
15601 bool buffer_unchanged_p
= false;
15602 int temp_scroll_step
= 0;
15603 ptrdiff_t count
= SPECPDL_INDEX ();
15605 int centering_position
= -1;
15606 int last_line_misfit
= 0;
15607 ptrdiff_t beg_unchanged
, end_unchanged
;
15608 int frame_line_height
;
15610 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15614 *w
->desired_matrix
->method
= 0;
15617 if (!just_this_one_p
15618 && REDISPLAY_SOME_P ()
15621 && !buffer
->text
->redisplay
15622 && BUF_PT (buffer
) == w
->last_point
)
15625 /* Make sure that both W's markers are valid. */
15626 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15627 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15630 reconsider_clip_changes (w
);
15631 frame_line_height
= default_line_pixel_height (w
);
15633 /* Has the mode line to be updated? */
15634 update_mode_line
= (w
->update_mode_line
15635 || update_mode_lines
15636 || buffer
->clip_changed
15637 || buffer
->prevent_redisplay_optimizations_p
);
15639 if (!just_this_one_p
)
15640 /* If `just_this_one_p' is set, we apparently set must_be_updated_p more
15641 cleverly elsewhere. */
15642 w
->must_be_updated_p
= true;
15644 if (MINI_WINDOW_P (w
))
15646 if (w
== XWINDOW (echo_area_window
)
15647 && !NILP (echo_area_buffer
[0]))
15649 if (update_mode_line
)
15650 /* We may have to update a tty frame's menu bar or a
15651 tool-bar. Example `M-x C-h C-h C-g'. */
15652 goto finish_menu_bars
;
15654 /* We've already displayed the echo area glyphs in this window. */
15655 goto finish_scroll_bars
;
15657 else if ((w
!= XWINDOW (minibuf_window
)
15658 || minibuf_level
== 0)
15659 /* When buffer is nonempty, redisplay window normally. */
15660 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15661 /* Quail displays non-mini buffers in minibuffer window.
15662 In that case, redisplay the window normally. */
15663 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15665 /* W is a mini-buffer window, but it's not active, so clear
15667 int yb
= window_text_bottom_y (w
);
15668 struct glyph_row
*row
;
15671 for (y
= 0, row
= w
->desired_matrix
->rows
;
15673 y
+= row
->height
, ++row
)
15674 blank_row (w
, row
, y
);
15675 goto finish_scroll_bars
;
15678 clear_glyph_matrix (w
->desired_matrix
);
15681 /* Otherwise set up data on this window; select its buffer and point
15683 /* Really select the buffer, for the sake of buffer-local
15685 set_buffer_internal_1 (XBUFFER (w
->contents
));
15687 current_matrix_up_to_date_p
15688 = (w
->window_end_valid
15689 && !current_buffer
->clip_changed
15690 && !current_buffer
->prevent_redisplay_optimizations_p
15691 && !window_outdated (w
));
15693 /* Run the window-bottom-change-functions
15694 if it is possible that the text on the screen has changed
15695 (either due to modification of the text, or any other reason). */
15696 if (!current_matrix_up_to_date_p
15697 && !NILP (Vwindow_text_change_functions
))
15699 safe_run_hooks (Qwindow_text_change_functions
);
15703 beg_unchanged
= BEG_UNCHANGED
;
15704 end_unchanged
= END_UNCHANGED
;
15706 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15708 specbind (Qinhibit_point_motion_hooks
, Qt
);
15711 = (w
->window_end_valid
15712 && !current_buffer
->clip_changed
15713 && !window_outdated (w
));
15715 /* When windows_or_buffers_changed is non-zero, we can't rely
15716 on the window end being valid, so set it to zero there. */
15717 if (windows_or_buffers_changed
)
15719 /* If window starts on a continuation line, maybe adjust the
15720 window start in case the window's width changed. */
15721 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15722 compute_window_start_on_continuation_line (w
);
15724 w
->window_end_valid
= false;
15725 /* If so, we also can't rely on current matrix
15726 and should not fool try_cursor_movement below. */
15727 current_matrix_up_to_date_p
= false;
15730 /* Some sanity checks. */
15731 CHECK_WINDOW_END (w
);
15732 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15734 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15737 if (mode_line_update_needed (w
))
15738 update_mode_line
= 1;
15740 /* Point refers normally to the selected window. For any other
15741 window, set up appropriate value. */
15742 if (!EQ (window
, selected_window
))
15744 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15745 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15749 new_pt_byte
= BEGV_BYTE
;
15750 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15752 else if (new_pt
> (ZV
- 1))
15755 new_pt_byte
= ZV_BYTE
;
15756 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15759 /* We don't use SET_PT so that the point-motion hooks don't run. */
15760 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15763 /* If any of the character widths specified in the display table
15764 have changed, invalidate the width run cache. It's true that
15765 this may be a bit late to catch such changes, but the rest of
15766 redisplay goes (non-fatally) haywire when the display table is
15767 changed, so why should we worry about doing any better? */
15768 if (current_buffer
->width_run_cache
15769 || (current_buffer
->base_buffer
15770 && current_buffer
->base_buffer
->width_run_cache
))
15772 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15774 if (! disptab_matches_widthtab
15775 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15777 struct buffer
*buf
= current_buffer
;
15779 if (buf
->base_buffer
)
15780 buf
= buf
->base_buffer
;
15781 invalidate_region_cache (buf
, buf
->width_run_cache
, BEG
, Z
);
15782 recompute_width_table (current_buffer
, disptab
);
15786 /* If window-start is screwed up, choose a new one. */
15787 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15790 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15792 /* If someone specified a new starting point but did not insist,
15793 check whether it can be used. */
15794 if (w
->optional_new_start
15795 && CHARPOS (startp
) >= BEGV
15796 && CHARPOS (startp
) <= ZV
)
15798 w
->optional_new_start
= 0;
15799 start_display (&it
, w
, startp
);
15800 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15801 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15802 if (IT_CHARPOS (it
) == PT
)
15803 w
->force_start
= 1;
15804 /* IT may overshoot PT if text at PT is invisible. */
15805 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15806 w
->force_start
= 1;
15811 /* Handle case where place to start displaying has been specified,
15812 unless the specified location is outside the accessible range. */
15813 if (w
->force_start
|| window_frozen_p (w
))
15815 /* We set this later on if we have to adjust point. */
15818 w
->force_start
= 0;
15820 w
->window_end_valid
= 0;
15822 /* Forget any recorded base line for line number display. */
15823 if (!buffer_unchanged_p
)
15824 w
->base_line_number
= 0;
15826 /* Redisplay the mode line. Select the buffer properly for that.
15827 Also, run the hook window-scroll-functions
15828 because we have scrolled. */
15829 /* Note, we do this after clearing force_start because
15830 if there's an error, it is better to forget about force_start
15831 than to get into an infinite loop calling the hook functions
15832 and having them get more errors. */
15833 if (!update_mode_line
15834 || ! NILP (Vwindow_scroll_functions
))
15836 update_mode_line
= 1;
15837 w
->update_mode_line
= 1;
15838 startp
= run_window_scroll_functions (window
, startp
);
15841 if (CHARPOS (startp
) < BEGV
)
15842 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15843 else if (CHARPOS (startp
) > ZV
)
15844 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15846 /* Redisplay, then check if cursor has been set during the
15847 redisplay. Give up if new fonts were loaded. */
15848 /* We used to issue a CHECK_MARGINS argument to try_window here,
15849 but this causes scrolling to fail when point begins inside
15850 the scroll margin (bug#148) -- cyd */
15851 if (!try_window (window
, startp
, 0))
15853 w
->force_start
= 1;
15854 clear_glyph_matrix (w
->desired_matrix
);
15855 goto need_larger_matrices
;
15858 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15860 /* If point does not appear, try to move point so it does
15861 appear. The desired matrix has been built above, so we
15862 can use it here. */
15863 new_vpos
= window_box_height (w
) / 2;
15866 if (!cursor_row_fully_visible_p (w
, 0, 0))
15868 /* Point does appear, but on a line partly visible at end of window.
15869 Move it back to a fully-visible line. */
15870 new_vpos
= window_box_height (w
);
15872 else if (w
->cursor
.vpos
>= 0)
15874 /* Some people insist on not letting point enter the scroll
15875 margin, even though this part handles windows that didn't
15877 int window_total_lines
15878 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15879 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15880 int pixel_margin
= margin
* frame_line_height
;
15881 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15883 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15884 below, which finds the row to move point to, advances by
15885 the Y coordinate of the _next_ row, see the definition of
15886 MATRIX_ROW_BOTTOM_Y. */
15887 if (w
->cursor
.vpos
< margin
+ header_line
)
15889 w
->cursor
.vpos
= -1;
15890 clear_glyph_matrix (w
->desired_matrix
);
15891 goto try_to_scroll
;
15895 int window_height
= window_box_height (w
);
15898 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15899 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15901 w
->cursor
.vpos
= -1;
15902 clear_glyph_matrix (w
->desired_matrix
);
15903 goto try_to_scroll
;
15908 /* If we need to move point for either of the above reasons,
15909 now actually do it. */
15912 struct glyph_row
*row
;
15914 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15915 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15918 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15919 MATRIX_ROW_START_BYTEPOS (row
));
15921 if (w
!= XWINDOW (selected_window
))
15922 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15923 else if (current_buffer
== old
)
15924 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15926 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15928 /* If we are highlighting the region, then we just changed
15929 the region, so redisplay to show it. */
15930 /* FIXME: We need to (re)run pre-redisplay-function! */
15931 /* if (markpos_of_region () >= 0)
15933 clear_glyph_matrix (w->desired_matrix);
15934 if (!try_window (window, startp, 0))
15935 goto need_larger_matrices;
15941 debug_method_add (w
, "forced window start");
15946 /* Handle case where text has not changed, only point, and it has
15947 not moved off the frame, and we are not retrying after hscroll.
15948 (current_matrix_up_to_date_p is nonzero when retrying.) */
15949 if (current_matrix_up_to_date_p
15950 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15951 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15955 case CURSOR_MOVEMENT_SUCCESS
:
15956 used_current_matrix_p
= 1;
15959 case CURSOR_MOVEMENT_MUST_SCROLL
:
15960 goto try_to_scroll
;
15966 /* If current starting point was originally the beginning of a line
15967 but no longer is, find a new starting point. */
15968 else if (w
->start_at_line_beg
15969 && !(CHARPOS (startp
) <= BEGV
15970 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15973 debug_method_add (w
, "recenter 1");
15978 /* Try scrolling with try_window_id. Value is > 0 if update has
15979 been done, it is -1 if we know that the same window start will
15980 not work. It is 0 if unsuccessful for some other reason. */
15981 else if ((tem
= try_window_id (w
)) != 0)
15984 debug_method_add (w
, "try_window_id %d", tem
);
15987 if (f
->fonts_changed
)
15988 goto need_larger_matrices
;
15992 /* Otherwise try_window_id has returned -1 which means that we
15993 don't want the alternative below this comment to execute. */
15995 else if (CHARPOS (startp
) >= BEGV
15996 && CHARPOS (startp
) <= ZV
15997 && PT
>= CHARPOS (startp
)
15998 && (CHARPOS (startp
) < ZV
15999 /* Avoid starting at end of buffer. */
16000 || CHARPOS (startp
) == BEGV
16001 || !window_outdated (w
)))
16003 int d1
, d2
, d3
, d4
, d5
, d6
;
16005 /* If first window line is a continuation line, and window start
16006 is inside the modified region, but the first change is before
16007 current window start, we must select a new window start.
16009 However, if this is the result of a down-mouse event (e.g. by
16010 extending the mouse-drag-overlay), we don't want to select a
16011 new window start, since that would change the position under
16012 the mouse, resulting in an unwanted mouse-movement rather
16013 than a simple mouse-click. */
16014 if (!w
->start_at_line_beg
16015 && NILP (do_mouse_tracking
)
16016 && CHARPOS (startp
) > BEGV
16017 && CHARPOS (startp
) > BEG
+ beg_unchanged
16018 && CHARPOS (startp
) <= Z
- end_unchanged
16019 /* Even if w->start_at_line_beg is nil, a new window may
16020 start at a line_beg, since that's how set_buffer_window
16021 sets it. So, we need to check the return value of
16022 compute_window_start_on_continuation_line. (See also
16024 && XMARKER (w
->start
)->buffer
== current_buffer
16025 && compute_window_start_on_continuation_line (w
)
16026 /* It doesn't make sense to force the window start like we
16027 do at label force_start if it is already known that point
16028 will not be visible in the resulting window, because
16029 doing so will move point from its correct position
16030 instead of scrolling the window to bring point into view.
16032 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
16034 w
->force_start
= 1;
16035 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16040 debug_method_add (w
, "same window start");
16043 /* Try to redisplay starting at same place as before.
16044 If point has not moved off frame, accept the results. */
16045 if (!current_matrix_up_to_date_p
16046 /* Don't use try_window_reusing_current_matrix in this case
16047 because a window scroll function can have changed the
16049 || !NILP (Vwindow_scroll_functions
)
16050 || MINI_WINDOW_P (w
)
16051 || !(used_current_matrix_p
16052 = try_window_reusing_current_matrix (w
)))
16054 IF_DEBUG (debug_method_add (w
, "1"));
16055 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
16056 /* -1 means we need to scroll.
16057 0 means we need new matrices, but fonts_changed
16058 is set in that case, so we will detect it below. */
16059 goto try_to_scroll
;
16062 if (f
->fonts_changed
)
16063 goto need_larger_matrices
;
16065 if (w
->cursor
.vpos
>= 0)
16067 if (!just_this_one_p
16068 || current_buffer
->clip_changed
16069 || BEG_UNCHANGED
< CHARPOS (startp
))
16070 /* Forget any recorded base line for line number display. */
16071 w
->base_line_number
= 0;
16073 if (!cursor_row_fully_visible_p (w
, 1, 0))
16075 clear_glyph_matrix (w
->desired_matrix
);
16076 last_line_misfit
= 1;
16078 /* Drop through and scroll. */
16083 clear_glyph_matrix (w
->desired_matrix
);
16088 /* Redisplay the mode line. Select the buffer properly for that. */
16089 if (!update_mode_line
)
16091 update_mode_line
= 1;
16092 w
->update_mode_line
= 1;
16095 /* Try to scroll by specified few lines. */
16096 if ((scroll_conservatively
16097 || emacs_scroll_step
16098 || temp_scroll_step
16099 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
16100 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
16101 && CHARPOS (startp
) >= BEGV
16102 && CHARPOS (startp
) <= ZV
)
16104 /* The function returns -1 if new fonts were loaded, 1 if
16105 successful, 0 if not successful. */
16106 int ss
= try_scrolling (window
, just_this_one_p
,
16107 scroll_conservatively
,
16109 temp_scroll_step
, last_line_misfit
);
16112 case SCROLLING_SUCCESS
:
16115 case SCROLLING_NEED_LARGER_MATRICES
:
16116 goto need_larger_matrices
;
16118 case SCROLLING_FAILED
:
16126 /* Finally, just choose a place to start which positions point
16127 according to user preferences. */
16132 debug_method_add (w
, "recenter");
16135 /* Forget any previously recorded base line for line number display. */
16136 if (!buffer_unchanged_p
)
16137 w
->base_line_number
= 0;
16139 /* Determine the window start relative to point. */
16140 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16141 it
.current_y
= it
.last_visible_y
;
16142 if (centering_position
< 0)
16144 int window_total_lines
16145 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16148 ? min (scroll_margin
, window_total_lines
/ 4)
16150 ptrdiff_t margin_pos
= CHARPOS (startp
);
16151 Lisp_Object aggressive
;
16154 /* If there is a scroll margin at the top of the window, find
16155 its character position. */
16157 /* Cannot call start_display if startp is not in the
16158 accessible region of the buffer. This can happen when we
16159 have just switched to a different buffer and/or changed
16160 its restriction. In that case, startp is initialized to
16161 the character position 1 (BEGV) because we did not yet
16162 have chance to display the buffer even once. */
16163 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
16166 void *it1data
= NULL
;
16168 SAVE_IT (it1
, it
, it1data
);
16169 start_display (&it1
, w
, startp
);
16170 move_it_vertically (&it1
, margin
* frame_line_height
);
16171 margin_pos
= IT_CHARPOS (it1
);
16172 RESTORE_IT (&it
, &it
, it1data
);
16174 scrolling_up
= PT
> margin_pos
;
16177 ? BVAR (current_buffer
, scroll_up_aggressively
)
16178 : BVAR (current_buffer
, scroll_down_aggressively
);
16180 if (!MINI_WINDOW_P (w
)
16181 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16185 /* Setting scroll-conservatively overrides
16186 scroll-*-aggressively. */
16187 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16189 double float_amount
= XFLOATINT (aggressive
);
16191 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16192 if (pt_offset
== 0 && float_amount
> 0)
16194 if (pt_offset
&& margin
> 0)
16197 /* Compute how much to move the window start backward from
16198 point so that point will be displayed where the user
16202 centering_position
= it
.last_visible_y
;
16204 centering_position
-= pt_offset
;
16205 centering_position
-=
16206 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
16207 + WINDOW_HEADER_LINE_HEIGHT (w
);
16208 /* Don't let point enter the scroll margin near top of
16210 if (centering_position
< margin
* frame_line_height
)
16211 centering_position
= margin
* frame_line_height
;
16214 centering_position
= margin
* frame_line_height
+ pt_offset
;
16217 /* Set the window start half the height of the window backward
16219 centering_position
= window_box_height (w
) / 2;
16221 move_it_vertically_backward (&it
, centering_position
);
16223 eassert (IT_CHARPOS (it
) >= BEGV
);
16225 /* The function move_it_vertically_backward may move over more
16226 than the specified y-distance. If it->w is small, e.g. a
16227 mini-buffer window, we may end up in front of the window's
16228 display area. Start displaying at the start of the line
16229 containing PT in this case. */
16230 if (it
.current_y
<= 0)
16232 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16233 move_it_vertically_backward (&it
, 0);
16237 it
.current_x
= it
.hpos
= 0;
16239 /* Set the window start position here explicitly, to avoid an
16240 infinite loop in case the functions in window-scroll-functions
16242 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16244 /* Run scroll hooks. */
16245 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16247 /* Redisplay the window. */
16248 if (!current_matrix_up_to_date_p
16249 || windows_or_buffers_changed
16250 || f
->cursor_type_changed
16251 /* Don't use try_window_reusing_current_matrix in this case
16252 because it can have changed the buffer. */
16253 || !NILP (Vwindow_scroll_functions
)
16254 || !just_this_one_p
16255 || MINI_WINDOW_P (w
)
16256 || !(used_current_matrix_p
16257 = try_window_reusing_current_matrix (w
)))
16258 try_window (window
, startp
, 0);
16260 /* If new fonts have been loaded (due to fontsets), give up. We
16261 have to start a new redisplay since we need to re-adjust glyph
16263 if (f
->fonts_changed
)
16264 goto need_larger_matrices
;
16266 /* If cursor did not appear assume that the middle of the window is
16267 in the first line of the window. Do it again with the next line.
16268 (Imagine a window of height 100, displaying two lines of height
16269 60. Moving back 50 from it->last_visible_y will end in the first
16271 if (w
->cursor
.vpos
< 0)
16273 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16275 clear_glyph_matrix (w
->desired_matrix
);
16276 move_it_by_lines (&it
, 1);
16277 try_window (window
, it
.current
.pos
, 0);
16279 else if (PT
< IT_CHARPOS (it
))
16281 clear_glyph_matrix (w
->desired_matrix
);
16282 move_it_by_lines (&it
, -1);
16283 try_window (window
, it
.current
.pos
, 0);
16287 /* Not much we can do about it. */
16291 /* Consider the following case: Window starts at BEGV, there is
16292 invisible, intangible text at BEGV, so that display starts at
16293 some point START > BEGV. It can happen that we are called with
16294 PT somewhere between BEGV and START. Try to handle that case. */
16295 if (w
->cursor
.vpos
< 0)
16297 struct glyph_row
*row
= w
->current_matrix
->rows
;
16298 if (row
->mode_line_p
)
16300 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16303 if (!cursor_row_fully_visible_p (w
, 0, 0))
16305 /* If vscroll is enabled, disable it and try again. */
16309 clear_glyph_matrix (w
->desired_matrix
);
16313 /* Users who set scroll-conservatively to a large number want
16314 point just above/below the scroll margin. If we ended up
16315 with point's row partially visible, move the window start to
16316 make that row fully visible and out of the margin. */
16317 if (scroll_conservatively
> SCROLL_LIMIT
)
16319 int window_total_lines
16320 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16323 ? min (scroll_margin
, window_total_lines
/ 4)
16325 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16327 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16328 clear_glyph_matrix (w
->desired_matrix
);
16329 if (1 == try_window (window
, it
.current
.pos
,
16330 TRY_WINDOW_CHECK_MARGINS
))
16334 /* If centering point failed to make the whole line visible,
16335 put point at the top instead. That has to make the whole line
16336 visible, if it can be done. */
16337 if (centering_position
== 0)
16340 clear_glyph_matrix (w
->desired_matrix
);
16341 centering_position
= 0;
16347 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16348 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16349 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16351 /* Display the mode line, if we must. */
16352 if ((update_mode_line
16353 /* If window not full width, must redo its mode line
16354 if (a) the window to its side is being redone and
16355 (b) we do a frame-based redisplay. This is a consequence
16356 of how inverted lines are drawn in frame-based redisplay. */
16357 || (!just_this_one_p
16358 && !FRAME_WINDOW_P (f
)
16359 && !WINDOW_FULL_WIDTH_P (w
))
16360 /* Line number to display. */
16361 || w
->base_line_pos
> 0
16362 /* Column number is displayed and different from the one displayed. */
16363 || (w
->column_number_displayed
!= -1
16364 && (w
->column_number_displayed
!= current_column ())))
16365 /* This means that the window has a mode line. */
16366 && (WINDOW_WANTS_MODELINE_P (w
)
16367 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16370 display_mode_lines (w
);
16372 /* If mode line height has changed, arrange for a thorough
16373 immediate redisplay using the correct mode line height. */
16374 if (WINDOW_WANTS_MODELINE_P (w
)
16375 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16377 f
->fonts_changed
= 1;
16378 w
->mode_line_height
= -1;
16379 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16380 = DESIRED_MODE_LINE_HEIGHT (w
);
16383 /* If header line height has changed, arrange for a thorough
16384 immediate redisplay using the correct header line height. */
16385 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16386 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16388 f
->fonts_changed
= 1;
16389 w
->header_line_height
= -1;
16390 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16391 = DESIRED_HEADER_LINE_HEIGHT (w
);
16394 if (f
->fonts_changed
)
16395 goto need_larger_matrices
;
16398 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16400 w
->base_line_pos
= 0;
16401 w
->base_line_number
= 0;
16406 /* When we reach a frame's selected window, redo the frame's menu bar. */
16407 if (update_mode_line
16408 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16410 int redisplay_menu_p
= 0;
16412 if (FRAME_WINDOW_P (f
))
16414 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16415 || defined (HAVE_NS) || defined (USE_GTK)
16416 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16418 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16422 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16424 if (redisplay_menu_p
)
16425 display_menu_bar (w
);
16427 #ifdef HAVE_WINDOW_SYSTEM
16428 if (FRAME_WINDOW_P (f
))
16430 #if defined (USE_GTK) || defined (HAVE_NS)
16431 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16432 redisplay_tool_bar (f
);
16434 if (WINDOWP (f
->tool_bar_window
)
16435 && (FRAME_TOOL_BAR_HEIGHT (f
) > 0
16436 || !NILP (Vauto_resize_tool_bars
))
16437 && redisplay_tool_bar (f
))
16438 ignore_mouse_drag_p
= 1;
16444 #ifdef HAVE_WINDOW_SYSTEM
16445 if (FRAME_WINDOW_P (f
)
16446 && update_window_fringes (w
, (just_this_one_p
16447 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16448 || w
->pseudo_window_p
)))
16452 if (draw_window_fringes (w
, 1))
16454 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
16455 x_draw_right_divider (w
);
16457 x_draw_vertical_border (w
);
16463 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
16464 x_draw_bottom_divider (w
);
16465 #endif /* HAVE_WINDOW_SYSTEM */
16467 /* We go to this label, with fonts_changed set, if it is
16468 necessary to try again using larger glyph matrices.
16469 We have to redeem the scroll bar even in this case,
16470 because the loop in redisplay_internal expects that. */
16471 need_larger_matrices
:
16473 finish_scroll_bars
:
16475 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16477 /* Set the thumb's position and size. */
16478 set_vertical_scroll_bar (w
);
16480 /* Note that we actually used the scroll bar attached to this
16481 window, so it shouldn't be deleted at the end of redisplay. */
16482 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16483 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16486 /* Restore current_buffer and value of point in it. The window
16487 update may have changed the buffer, so first make sure `opoint'
16488 is still valid (Bug#6177). */
16489 if (CHARPOS (opoint
) < BEGV
)
16490 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16491 else if (CHARPOS (opoint
) > ZV
)
16492 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16494 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16496 set_buffer_internal_1 (old
);
16497 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16498 shorter. This can be caused by log truncation in *Messages*. */
16499 if (CHARPOS (lpoint
) <= ZV
)
16500 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16502 unbind_to (count
, Qnil
);
16506 /* Build the complete desired matrix of WINDOW with a window start
16507 buffer position POS.
16509 Value is 1 if successful. It is zero if fonts were loaded during
16510 redisplay which makes re-adjusting glyph matrices necessary, and -1
16511 if point would appear in the scroll margins.
16512 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16513 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16517 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16519 struct window
*w
= XWINDOW (window
);
16521 struct glyph_row
*last_text_row
= NULL
;
16522 struct frame
*f
= XFRAME (w
->frame
);
16523 int frame_line_height
= default_line_pixel_height (w
);
16525 /* Make POS the new window start. */
16526 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16528 /* Mark cursor position as unknown. No overlay arrow seen. */
16529 w
->cursor
.vpos
= -1;
16530 overlay_arrow_seen
= 0;
16532 /* Initialize iterator and info to start at POS. */
16533 start_display (&it
, w
, pos
);
16535 /* Display all lines of W. */
16536 while (it
.current_y
< it
.last_visible_y
)
16538 if (display_line (&it
))
16539 last_text_row
= it
.glyph_row
- 1;
16540 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16544 /* Don't let the cursor end in the scroll margins. */
16545 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16546 && !MINI_WINDOW_P (w
))
16548 int this_scroll_margin
;
16549 int window_total_lines
16550 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16552 if (scroll_margin
> 0)
16554 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16555 this_scroll_margin
*= frame_line_height
;
16558 this_scroll_margin
= 0;
16560 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16561 && w
->cursor
.y
< this_scroll_margin
16562 && CHARPOS (pos
) > BEGV
16563 && IT_CHARPOS (it
) < ZV
)
16564 /* rms: considering make_cursor_line_fully_visible_p here
16565 seems to give wrong results. We don't want to recenter
16566 when the last line is partly visible, we want to allow
16567 that case to be handled in the usual way. */
16568 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16570 w
->cursor
.vpos
= -1;
16571 clear_glyph_matrix (w
->desired_matrix
);
16576 /* If bottom moved off end of frame, change mode line percentage. */
16577 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16578 w
->update_mode_line
= 1;
16580 /* Set window_end_pos to the offset of the last character displayed
16581 on the window from the end of current_buffer. Set
16582 window_end_vpos to its row number. */
16585 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16586 adjust_window_ends (w
, last_text_row
, 0);
16588 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16589 w
->window_end_vpos
)));
16593 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16594 w
->window_end_pos
= Z
- ZV
;
16595 w
->window_end_vpos
= 0;
16598 /* But that is not valid info until redisplay finishes. */
16599 w
->window_end_valid
= 0;
16605 /************************************************************************
16606 Window redisplay reusing current matrix when buffer has not changed
16607 ************************************************************************/
16609 /* Try redisplay of window W showing an unchanged buffer with a
16610 different window start than the last time it was displayed by
16611 reusing its current matrix. Value is non-zero if successful.
16612 W->start is the new window start. */
16615 try_window_reusing_current_matrix (struct window
*w
)
16617 struct frame
*f
= XFRAME (w
->frame
);
16618 struct glyph_row
*bottom_row
;
16621 struct text_pos start
, new_start
;
16622 int nrows_scrolled
, i
;
16623 struct glyph_row
*last_text_row
;
16624 struct glyph_row
*last_reused_text_row
;
16625 struct glyph_row
*start_row
;
16626 int start_vpos
, min_y
, max_y
;
16629 if (inhibit_try_window_reusing
)
16633 if (/* This function doesn't handle terminal frames. */
16634 !FRAME_WINDOW_P (f
)
16635 /* Don't try to reuse the display if windows have been split
16637 || windows_or_buffers_changed
16638 || f
->cursor_type_changed
)
16641 /* Can't do this if showing trailing whitespace. */
16642 if (!NILP (Vshow_trailing_whitespace
))
16645 /* If top-line visibility has changed, give up. */
16646 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16647 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16650 /* Give up if old or new display is scrolled vertically. We could
16651 make this function handle this, but right now it doesn't. */
16652 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16653 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16656 /* The variable new_start now holds the new window start. The old
16657 start `start' can be determined from the current matrix. */
16658 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16659 start
= start_row
->minpos
;
16660 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16662 /* Clear the desired matrix for the display below. */
16663 clear_glyph_matrix (w
->desired_matrix
);
16665 if (CHARPOS (new_start
) <= CHARPOS (start
))
16667 /* Don't use this method if the display starts with an ellipsis
16668 displayed for invisible text. It's not easy to handle that case
16669 below, and it's certainly not worth the effort since this is
16670 not a frequent case. */
16671 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16674 IF_DEBUG (debug_method_add (w
, "twu1"));
16676 /* Display up to a row that can be reused. The variable
16677 last_text_row is set to the last row displayed that displays
16678 text. Note that it.vpos == 0 if or if not there is a
16679 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16680 start_display (&it
, w
, new_start
);
16681 w
->cursor
.vpos
= -1;
16682 last_text_row
= last_reused_text_row
= NULL
;
16684 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16686 /* If we have reached into the characters in the START row,
16687 that means the line boundaries have changed. So we
16688 can't start copying with the row START. Maybe it will
16689 work to start copying with the following row. */
16690 while (IT_CHARPOS (it
) > CHARPOS (start
))
16692 /* Advance to the next row as the "start". */
16694 start
= start_row
->minpos
;
16695 /* If there are no more rows to try, or just one, give up. */
16696 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16697 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16698 || CHARPOS (start
) == ZV
)
16700 clear_glyph_matrix (w
->desired_matrix
);
16704 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16706 /* If we have reached alignment, we can copy the rest of the
16708 if (IT_CHARPOS (it
) == CHARPOS (start
)
16709 /* Don't accept "alignment" inside a display vector,
16710 since start_row could have started in the middle of
16711 that same display vector (thus their character
16712 positions match), and we have no way of telling if
16713 that is the case. */
16714 && it
.current
.dpvec_index
< 0)
16717 if (display_line (&it
))
16718 last_text_row
= it
.glyph_row
- 1;
16722 /* A value of current_y < last_visible_y means that we stopped
16723 at the previous window start, which in turn means that we
16724 have at least one reusable row. */
16725 if (it
.current_y
< it
.last_visible_y
)
16727 struct glyph_row
*row
;
16729 /* IT.vpos always starts from 0; it counts text lines. */
16730 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16732 /* Find PT if not already found in the lines displayed. */
16733 if (w
->cursor
.vpos
< 0)
16735 int dy
= it
.current_y
- start_row
->y
;
16737 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16738 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16740 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16741 dy
, nrows_scrolled
);
16744 clear_glyph_matrix (w
->desired_matrix
);
16749 /* Scroll the display. Do it before the current matrix is
16750 changed. The problem here is that update has not yet
16751 run, i.e. part of the current matrix is not up to date.
16752 scroll_run_hook will clear the cursor, and use the
16753 current matrix to get the height of the row the cursor is
16755 run
.current_y
= start_row
->y
;
16756 run
.desired_y
= it
.current_y
;
16757 run
.height
= it
.last_visible_y
- it
.current_y
;
16759 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16762 FRAME_RIF (f
)->update_window_begin_hook (w
);
16763 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16764 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16765 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16769 /* Shift current matrix down by nrows_scrolled lines. */
16770 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16771 rotate_matrix (w
->current_matrix
,
16773 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16776 /* Disable lines that must be updated. */
16777 for (i
= 0; i
< nrows_scrolled
; ++i
)
16778 (start_row
+ i
)->enabled_p
= false;
16780 /* Re-compute Y positions. */
16781 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16782 max_y
= it
.last_visible_y
;
16783 for (row
= start_row
+ nrows_scrolled
;
16787 row
->y
= it
.current_y
;
16788 row
->visible_height
= row
->height
;
16790 if (row
->y
< min_y
)
16791 row
->visible_height
-= min_y
- row
->y
;
16792 if (row
->y
+ row
->height
> max_y
)
16793 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16794 if (row
->fringe_bitmap_periodic_p
)
16795 row
->redraw_fringe_bitmaps_p
= 1;
16797 it
.current_y
+= row
->height
;
16799 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16800 last_reused_text_row
= row
;
16801 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16805 /* Disable lines in the current matrix which are now
16806 below the window. */
16807 for (++row
; row
< bottom_row
; ++row
)
16808 row
->enabled_p
= row
->mode_line_p
= 0;
16811 /* Update window_end_pos etc.; last_reused_text_row is the last
16812 reused row from the current matrix containing text, if any.
16813 The value of last_text_row is the last displayed line
16814 containing text. */
16815 if (last_reused_text_row
)
16816 adjust_window_ends (w
, last_reused_text_row
, 1);
16817 else if (last_text_row
)
16818 adjust_window_ends (w
, last_text_row
, 0);
16821 /* This window must be completely empty. */
16822 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16823 w
->window_end_pos
= Z
- ZV
;
16824 w
->window_end_vpos
= 0;
16826 w
->window_end_valid
= 0;
16828 /* Update hint: don't try scrolling again in update_window. */
16829 w
->desired_matrix
->no_scrolling_p
= 1;
16832 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16836 else if (CHARPOS (new_start
) > CHARPOS (start
))
16838 struct glyph_row
*pt_row
, *row
;
16839 struct glyph_row
*first_reusable_row
;
16840 struct glyph_row
*first_row_to_display
;
16842 int yb
= window_text_bottom_y (w
);
16844 /* Find the row starting at new_start, if there is one. Don't
16845 reuse a partially visible line at the end. */
16846 first_reusable_row
= start_row
;
16847 while (first_reusable_row
->enabled_p
16848 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16849 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16850 < CHARPOS (new_start
)))
16851 ++first_reusable_row
;
16853 /* Give up if there is no row to reuse. */
16854 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16855 || !first_reusable_row
->enabled_p
16856 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16857 != CHARPOS (new_start
)))
16860 /* We can reuse fully visible rows beginning with
16861 first_reusable_row to the end of the window. Set
16862 first_row_to_display to the first row that cannot be reused.
16863 Set pt_row to the row containing point, if there is any. */
16865 for (first_row_to_display
= first_reusable_row
;
16866 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16867 ++first_row_to_display
)
16869 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16870 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16871 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16872 && first_row_to_display
->ends_at_zv_p
16873 && pt_row
== NULL
)))
16874 pt_row
= first_row_to_display
;
16877 /* Start displaying at the start of first_row_to_display. */
16878 eassert (first_row_to_display
->y
< yb
);
16879 init_to_row_start (&it
, w
, first_row_to_display
);
16881 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16883 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16885 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16886 + WINDOW_HEADER_LINE_HEIGHT (w
));
16888 /* Display lines beginning with first_row_to_display in the
16889 desired matrix. Set last_text_row to the last row displayed
16890 that displays text. */
16891 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16892 if (pt_row
== NULL
)
16893 w
->cursor
.vpos
= -1;
16894 last_text_row
= NULL
;
16895 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16896 if (display_line (&it
))
16897 last_text_row
= it
.glyph_row
- 1;
16899 /* If point is in a reused row, adjust y and vpos of the cursor
16903 w
->cursor
.vpos
-= nrows_scrolled
;
16904 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16907 /* Give up if point isn't in a row displayed or reused. (This
16908 also handles the case where w->cursor.vpos < nrows_scrolled
16909 after the calls to display_line, which can happen with scroll
16910 margins. See bug#1295.) */
16911 if (w
->cursor
.vpos
< 0)
16913 clear_glyph_matrix (w
->desired_matrix
);
16917 /* Scroll the display. */
16918 run
.current_y
= first_reusable_row
->y
;
16919 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16920 run
.height
= it
.last_visible_y
- run
.current_y
;
16921 dy
= run
.current_y
- run
.desired_y
;
16926 FRAME_RIF (f
)->update_window_begin_hook (w
);
16927 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16928 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16929 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16933 /* Adjust Y positions of reused rows. */
16934 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16935 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16936 max_y
= it
.last_visible_y
;
16937 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16940 row
->visible_height
= row
->height
;
16941 if (row
->y
< min_y
)
16942 row
->visible_height
-= min_y
- row
->y
;
16943 if (row
->y
+ row
->height
> max_y
)
16944 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16945 if (row
->fringe_bitmap_periodic_p
)
16946 row
->redraw_fringe_bitmaps_p
= 1;
16949 /* Scroll the current matrix. */
16950 eassert (nrows_scrolled
> 0);
16951 rotate_matrix (w
->current_matrix
,
16953 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16956 /* Disable rows not reused. */
16957 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16958 row
->enabled_p
= false;
16960 /* Point may have moved to a different line, so we cannot assume that
16961 the previous cursor position is valid; locate the correct row. */
16964 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16966 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16967 && !row
->ends_at_zv_p
;
16971 w
->cursor
.y
= row
->y
;
16973 if (row
< bottom_row
)
16975 /* Can't simply scan the row for point with
16976 bidi-reordered glyph rows. Let set_cursor_from_row
16977 figure out where to put the cursor, and if it fails,
16979 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16981 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16984 clear_glyph_matrix (w
->desired_matrix
);
16990 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16991 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16994 && (!BUFFERP (glyph
->object
)
16995 || glyph
->charpos
< PT
);
16999 w
->cursor
.x
+= glyph
->pixel_width
;
17005 /* Adjust window end. A null value of last_text_row means that
17006 the window end is in reused rows which in turn means that
17007 only its vpos can have changed. */
17009 adjust_window_ends (w
, last_text_row
, 0);
17011 w
->window_end_vpos
-= nrows_scrolled
;
17013 w
->window_end_valid
= 0;
17014 w
->desired_matrix
->no_scrolling_p
= 1;
17017 debug_method_add (w
, "try_window_reusing_current_matrix 2");
17027 /************************************************************************
17028 Window redisplay reusing current matrix when buffer has changed
17029 ************************************************************************/
17031 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
17032 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
17033 ptrdiff_t *, ptrdiff_t *);
17034 static struct glyph_row
*
17035 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
17036 struct glyph_row
*);
17039 /* Return the last row in MATRIX displaying text. If row START is
17040 non-null, start searching with that row. IT gives the dimensions
17041 of the display. Value is null if matrix is empty; otherwise it is
17042 a pointer to the row found. */
17044 static struct glyph_row
*
17045 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
17046 struct glyph_row
*start
)
17048 struct glyph_row
*row
, *row_found
;
17050 /* Set row_found to the last row in IT->w's current matrix
17051 displaying text. The loop looks funny but think of partially
17054 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
17055 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17057 eassert (row
->enabled_p
);
17059 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
17068 /* Return the last row in the current matrix of W that is not affected
17069 by changes at the start of current_buffer that occurred since W's
17070 current matrix was built. Value is null if no such row exists.
17072 BEG_UNCHANGED us the number of characters unchanged at the start of
17073 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
17074 first changed character in current_buffer. Characters at positions <
17075 BEG + BEG_UNCHANGED are at the same buffer positions as they were
17076 when the current matrix was built. */
17078 static struct glyph_row
*
17079 find_last_unchanged_at_beg_row (struct window
*w
)
17081 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
17082 struct glyph_row
*row
;
17083 struct glyph_row
*row_found
= NULL
;
17084 int yb
= window_text_bottom_y (w
);
17086 /* Find the last row displaying unchanged text. */
17087 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17088 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17089 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
17092 if (/* If row ends before first_changed_pos, it is unchanged,
17093 except in some case. */
17094 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
17095 /* When row ends in ZV and we write at ZV it is not
17097 && !row
->ends_at_zv_p
17098 /* When first_changed_pos is the end of a continued line,
17099 row is not unchanged because it may be no longer
17101 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
17102 && (row
->continued_p
17103 || row
->exact_window_width_line_p
))
17104 /* If ROW->end is beyond ZV, then ROW->end is outdated and
17105 needs to be recomputed, so don't consider this row as
17106 unchanged. This happens when the last line was
17107 bidi-reordered and was killed immediately before this
17108 redisplay cycle. In that case, ROW->end stores the
17109 buffer position of the first visual-order character of
17110 the killed text, which is now beyond ZV. */
17111 && CHARPOS (row
->end
.pos
) <= ZV
)
17114 /* Stop if last visible row. */
17115 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
17123 /* Find the first glyph row in the current matrix of W that is not
17124 affected by changes at the end of current_buffer since the
17125 time W's current matrix was built.
17127 Return in *DELTA the number of chars by which buffer positions in
17128 unchanged text at the end of current_buffer must be adjusted.
17130 Return in *DELTA_BYTES the corresponding number of bytes.
17132 Value is null if no such row exists, i.e. all rows are affected by
17135 static struct glyph_row
*
17136 find_first_unchanged_at_end_row (struct window
*w
,
17137 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
17139 struct glyph_row
*row
;
17140 struct glyph_row
*row_found
= NULL
;
17142 *delta
= *delta_bytes
= 0;
17144 /* Display must not have been paused, otherwise the current matrix
17145 is not up to date. */
17146 eassert (w
->window_end_valid
);
17148 /* A value of window_end_pos >= END_UNCHANGED means that the window
17149 end is in the range of changed text. If so, there is no
17150 unchanged row at the end of W's current matrix. */
17151 if (w
->window_end_pos
>= END_UNCHANGED
)
17154 /* Set row to the last row in W's current matrix displaying text. */
17155 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17157 /* If matrix is entirely empty, no unchanged row exists. */
17158 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17160 /* The value of row is the last glyph row in the matrix having a
17161 meaningful buffer position in it. The end position of row
17162 corresponds to window_end_pos. This allows us to translate
17163 buffer positions in the current matrix to current buffer
17164 positions for characters not in changed text. */
17166 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17167 ptrdiff_t Z_BYTE_old
=
17168 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17169 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17170 struct glyph_row
*first_text_row
17171 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17173 *delta
= Z
- Z_old
;
17174 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17176 /* Set last_unchanged_pos to the buffer position of the last
17177 character in the buffer that has not been changed. Z is the
17178 index + 1 of the last character in current_buffer, i.e. by
17179 subtracting END_UNCHANGED we get the index of the last
17180 unchanged character, and we have to add BEG to get its buffer
17182 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17183 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17185 /* Search backward from ROW for a row displaying a line that
17186 starts at a minimum position >= last_unchanged_pos_old. */
17187 for (; row
> first_text_row
; --row
)
17189 /* This used to abort, but it can happen.
17190 It is ok to just stop the search instead here. KFS. */
17191 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17194 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17199 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17205 /* Make sure that glyph rows in the current matrix of window W
17206 reference the same glyph memory as corresponding rows in the
17207 frame's frame matrix. This function is called after scrolling W's
17208 current matrix on a terminal frame in try_window_id and
17209 try_window_reusing_current_matrix. */
17212 sync_frame_with_window_matrix_rows (struct window
*w
)
17214 struct frame
*f
= XFRAME (w
->frame
);
17215 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17217 /* Preconditions: W must be a leaf window and full-width. Its frame
17218 must have a frame matrix. */
17219 eassert (BUFFERP (w
->contents
));
17220 eassert (WINDOW_FULL_WIDTH_P (w
));
17221 eassert (!FRAME_WINDOW_P (f
));
17223 /* If W is a full-width window, glyph pointers in W's current matrix
17224 have, by definition, to be the same as glyph pointers in the
17225 corresponding frame matrix. Note that frame matrices have no
17226 marginal areas (see build_frame_matrix). */
17227 window_row
= w
->current_matrix
->rows
;
17228 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17229 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17230 while (window_row
< window_row_end
)
17232 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17233 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17235 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17236 frame_row
->glyphs
[TEXT_AREA
] = start
;
17237 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17238 frame_row
->glyphs
[LAST_AREA
] = end
;
17240 /* Disable frame rows whose corresponding window rows have
17241 been disabled in try_window_id. */
17242 if (!window_row
->enabled_p
)
17243 frame_row
->enabled_p
= false;
17245 ++window_row
, ++frame_row
;
17250 /* Find the glyph row in window W containing CHARPOS. Consider all
17251 rows between START and END (not inclusive). END null means search
17252 all rows to the end of the display area of W. Value is the row
17253 containing CHARPOS or null. */
17256 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17257 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17259 struct glyph_row
*row
= start
;
17260 struct glyph_row
*best_row
= NULL
;
17261 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17264 /* If we happen to start on a header-line, skip that. */
17265 if (row
->mode_line_p
)
17268 if ((end
&& row
>= end
) || !row
->enabled_p
)
17271 last_y
= window_text_bottom_y (w
) - dy
;
17275 /* Give up if we have gone too far. */
17276 if (end
&& row
>= end
)
17278 /* This formerly returned if they were equal.
17279 I think that both quantities are of a "last plus one" type;
17280 if so, when they are equal, the row is within the screen. -- rms. */
17281 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17284 /* If it is in this row, return this row. */
17285 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17286 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17287 /* The end position of a row equals the start
17288 position of the next row. If CHARPOS is there, we
17289 would rather consider it displayed in the next
17290 line, except when this line ends in ZV. */
17291 && !row_for_charpos_p (row
, charpos
)))
17292 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17296 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17297 || (!best_row
&& !row
->continued_p
))
17299 /* In bidi-reordered rows, there could be several rows whose
17300 edges surround CHARPOS, all of these rows belonging to
17301 the same continued line. We need to find the row which
17302 fits CHARPOS the best. */
17303 for (g
= row
->glyphs
[TEXT_AREA
];
17304 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17307 if (!STRINGP (g
->object
))
17309 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17311 mindif
= eabs (g
->charpos
- charpos
);
17313 /* Exact match always wins. */
17320 else if (best_row
&& !row
->continued_p
)
17327 /* Try to redisplay window W by reusing its existing display. W's
17328 current matrix must be up to date when this function is called,
17329 i.e. window_end_valid must be nonzero.
17333 >= 1 if successful, i.e. display has been updated
17335 1 means the changes were in front of a newline that precedes
17336 the window start, and the whole current matrix was reused
17337 2 means the changes were after the last position displayed
17338 in the window, and the whole current matrix was reused
17339 3 means portions of the current matrix were reused, while
17340 some of the screen lines were redrawn
17341 -1 if redisplay with same window start is known not to succeed
17342 0 if otherwise unsuccessful
17344 The following steps are performed:
17346 1. Find the last row in the current matrix of W that is not
17347 affected by changes at the start of current_buffer. If no such row
17350 2. Find the first row in W's current matrix that is not affected by
17351 changes at the end of current_buffer. Maybe there is no such row.
17353 3. Display lines beginning with the row + 1 found in step 1 to the
17354 row found in step 2 or, if step 2 didn't find a row, to the end of
17357 4. If cursor is not known to appear on the window, give up.
17359 5. If display stopped at the row found in step 2, scroll the
17360 display and current matrix as needed.
17362 6. Maybe display some lines at the end of W, if we must. This can
17363 happen under various circumstances, like a partially visible line
17364 becoming fully visible, or because newly displayed lines are displayed
17365 in smaller font sizes.
17367 7. Update W's window end information. */
17370 try_window_id (struct window
*w
)
17372 struct frame
*f
= XFRAME (w
->frame
);
17373 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17374 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17375 struct glyph_row
*last_unchanged_at_beg_row
;
17376 struct glyph_row
*first_unchanged_at_end_row
;
17377 struct glyph_row
*row
;
17378 struct glyph_row
*bottom_row
;
17381 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17383 struct text_pos start_pos
;
17385 int first_unchanged_at_end_vpos
= 0;
17386 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17387 struct text_pos start
;
17388 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17391 if (inhibit_try_window_id
)
17395 /* This is handy for debugging. */
17397 #define GIVE_UP(X) \
17399 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17403 #define GIVE_UP(X) return 0
17406 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17408 /* Don't use this for mini-windows because these can show
17409 messages and mini-buffers, and we don't handle that here. */
17410 if (MINI_WINDOW_P (w
))
17413 /* This flag is used to prevent redisplay optimizations. */
17414 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17417 /* This function's optimizations cannot be used if overlays have
17418 changed in the buffer displayed by the window, so give up if they
17420 if (w
->last_overlay_modified
!= OVERLAY_MODIFF
)
17423 /* Verify that narrowing has not changed.
17424 Also verify that we were not told to prevent redisplay optimizations.
17425 It would be nice to further
17426 reduce the number of cases where this prevents try_window_id. */
17427 if (current_buffer
->clip_changed
17428 || current_buffer
->prevent_redisplay_optimizations_p
)
17431 /* Window must either use window-based redisplay or be full width. */
17432 if (!FRAME_WINDOW_P (f
)
17433 && (!FRAME_LINE_INS_DEL_OK (f
)
17434 || !WINDOW_FULL_WIDTH_P (w
)))
17437 /* Give up if point is known NOT to appear in W. */
17438 if (PT
< CHARPOS (start
))
17441 /* Another way to prevent redisplay optimizations. */
17442 if (w
->last_modified
== 0)
17445 /* Verify that window is not hscrolled. */
17446 if (w
->hscroll
!= 0)
17449 /* Verify that display wasn't paused. */
17450 if (!w
->window_end_valid
)
17453 /* Likewise if highlighting trailing whitespace. */
17454 if (!NILP (Vshow_trailing_whitespace
))
17457 /* Can't use this if overlay arrow position and/or string have
17459 if (overlay_arrows_changed_p ())
17462 /* When word-wrap is on, adding a space to the first word of a
17463 wrapped line can change the wrap position, altering the line
17464 above it. It might be worthwhile to handle this more
17465 intelligently, but for now just redisplay from scratch. */
17466 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17469 /* Under bidi reordering, adding or deleting a character in the
17470 beginning of a paragraph, before the first strong directional
17471 character, can change the base direction of the paragraph (unless
17472 the buffer specifies a fixed paragraph direction), which will
17473 require to redisplay the whole paragraph. It might be worthwhile
17474 to find the paragraph limits and widen the range of redisplayed
17475 lines to that, but for now just give up this optimization and
17476 redisplay from scratch. */
17477 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17478 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17481 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17482 only if buffer has really changed. The reason is that the gap is
17483 initially at Z for freshly visited files. The code below would
17484 set end_unchanged to 0 in that case. */
17485 if (MODIFF
> SAVE_MODIFF
17486 /* This seems to happen sometimes after saving a buffer. */
17487 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17489 if (GPT
- BEG
< BEG_UNCHANGED
)
17490 BEG_UNCHANGED
= GPT
- BEG
;
17491 if (Z
- GPT
< END_UNCHANGED
)
17492 END_UNCHANGED
= Z
- GPT
;
17495 /* The position of the first and last character that has been changed. */
17496 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17497 last_changed_charpos
= Z
- END_UNCHANGED
;
17499 /* If window starts after a line end, and the last change is in
17500 front of that newline, then changes don't affect the display.
17501 This case happens with stealth-fontification. Note that although
17502 the display is unchanged, glyph positions in the matrix have to
17503 be adjusted, of course. */
17504 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17505 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17506 && ((last_changed_charpos
< CHARPOS (start
)
17507 && CHARPOS (start
) == BEGV
)
17508 || (last_changed_charpos
< CHARPOS (start
) - 1
17509 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17511 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17512 struct glyph_row
*r0
;
17514 /* Compute how many chars/bytes have been added to or removed
17515 from the buffer. */
17516 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17517 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17518 Z_delta
= Z
- Z_old
;
17519 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17521 /* Give up if PT is not in the window. Note that it already has
17522 been checked at the start of try_window_id that PT is not in
17523 front of the window start. */
17524 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17527 /* If window start is unchanged, we can reuse the whole matrix
17528 as is, after adjusting glyph positions. No need to compute
17529 the window end again, since its offset from Z hasn't changed. */
17530 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17531 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17532 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17533 /* PT must not be in a partially visible line. */
17534 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17535 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17537 /* Adjust positions in the glyph matrix. */
17538 if (Z_delta
|| Z_delta_bytes
)
17540 struct glyph_row
*r1
17541 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17542 increment_matrix_positions (w
->current_matrix
,
17543 MATRIX_ROW_VPOS (r0
, current_matrix
),
17544 MATRIX_ROW_VPOS (r1
, current_matrix
),
17545 Z_delta
, Z_delta_bytes
);
17548 /* Set the cursor. */
17549 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17551 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17556 /* Handle the case that changes are all below what is displayed in
17557 the window, and that PT is in the window. This shortcut cannot
17558 be taken if ZV is visible in the window, and text has been added
17559 there that is visible in the window. */
17560 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17561 /* ZV is not visible in the window, or there are no
17562 changes at ZV, actually. */
17563 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17564 || first_changed_charpos
== last_changed_charpos
))
17566 struct glyph_row
*r0
;
17568 /* Give up if PT is not in the window. Note that it already has
17569 been checked at the start of try_window_id that PT is not in
17570 front of the window start. */
17571 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17574 /* If window start is unchanged, we can reuse the whole matrix
17575 as is, without changing glyph positions since no text has
17576 been added/removed in front of the window end. */
17577 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17578 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17579 /* PT must not be in a partially visible line. */
17580 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17581 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17583 /* We have to compute the window end anew since text
17584 could have been added/removed after it. */
17585 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17586 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17588 /* Set the cursor. */
17589 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17591 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17596 /* Give up if window start is in the changed area.
17598 The condition used to read
17600 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17602 but why that was tested escapes me at the moment. */
17603 if (CHARPOS (start
) >= first_changed_charpos
17604 && CHARPOS (start
) <= last_changed_charpos
)
17607 /* Check that window start agrees with the start of the first glyph
17608 row in its current matrix. Check this after we know the window
17609 start is not in changed text, otherwise positions would not be
17611 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17612 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17615 /* Give up if the window ends in strings. Overlay strings
17616 at the end are difficult to handle, so don't try. */
17617 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17618 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17621 /* Compute the position at which we have to start displaying new
17622 lines. Some of the lines at the top of the window might be
17623 reusable because they are not displaying changed text. Find the
17624 last row in W's current matrix not affected by changes at the
17625 start of current_buffer. Value is null if changes start in the
17626 first line of window. */
17627 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17628 if (last_unchanged_at_beg_row
)
17630 /* Avoid starting to display in the middle of a character, a TAB
17631 for instance. This is easier than to set up the iterator
17632 exactly, and it's not a frequent case, so the additional
17633 effort wouldn't really pay off. */
17634 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17635 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17636 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17637 --last_unchanged_at_beg_row
;
17639 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17642 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17644 start_pos
= it
.current
.pos
;
17646 /* Start displaying new lines in the desired matrix at the same
17647 vpos we would use in the current matrix, i.e. below
17648 last_unchanged_at_beg_row. */
17649 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17651 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17652 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17654 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17658 /* There are no reusable lines at the start of the window.
17659 Start displaying in the first text line. */
17660 start_display (&it
, w
, start
);
17661 it
.vpos
= it
.first_vpos
;
17662 start_pos
= it
.current
.pos
;
17665 /* Find the first row that is not affected by changes at the end of
17666 the buffer. Value will be null if there is no unchanged row, in
17667 which case we must redisplay to the end of the window. delta
17668 will be set to the value by which buffer positions beginning with
17669 first_unchanged_at_end_row have to be adjusted due to text
17671 first_unchanged_at_end_row
17672 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17673 IF_DEBUG (debug_delta
= delta
);
17674 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17676 /* Set stop_pos to the buffer position up to which we will have to
17677 display new lines. If first_unchanged_at_end_row != NULL, this
17678 is the buffer position of the start of the line displayed in that
17679 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17680 that we don't stop at a buffer position. */
17682 if (first_unchanged_at_end_row
)
17684 eassert (last_unchanged_at_beg_row
== NULL
17685 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17687 /* If this is a continuation line, move forward to the next one
17688 that isn't. Changes in lines above affect this line.
17689 Caution: this may move first_unchanged_at_end_row to a row
17690 not displaying text. */
17691 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17692 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17693 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17694 < it
.last_visible_y
))
17695 ++first_unchanged_at_end_row
;
17697 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17698 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17699 >= it
.last_visible_y
))
17700 first_unchanged_at_end_row
= NULL
;
17703 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17705 first_unchanged_at_end_vpos
17706 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17707 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17710 else if (last_unchanged_at_beg_row
== NULL
)
17716 /* Either there is no unchanged row at the end, or the one we have
17717 now displays text. This is a necessary condition for the window
17718 end pos calculation at the end of this function. */
17719 eassert (first_unchanged_at_end_row
== NULL
17720 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17722 debug_last_unchanged_at_beg_vpos
17723 = (last_unchanged_at_beg_row
17724 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17726 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17728 #endif /* GLYPH_DEBUG */
17731 /* Display new lines. Set last_text_row to the last new line
17732 displayed which has text on it, i.e. might end up as being the
17733 line where the window_end_vpos is. */
17734 w
->cursor
.vpos
= -1;
17735 last_text_row
= NULL
;
17736 overlay_arrow_seen
= 0;
17737 while (it
.current_y
< it
.last_visible_y
17738 && !f
->fonts_changed
17739 && (first_unchanged_at_end_row
== NULL
17740 || IT_CHARPOS (it
) < stop_pos
))
17742 if (display_line (&it
))
17743 last_text_row
= it
.glyph_row
- 1;
17746 if (f
->fonts_changed
)
17750 /* Compute differences in buffer positions, y-positions etc. for
17751 lines reused at the bottom of the window. Compute what we can
17753 if (first_unchanged_at_end_row
17754 /* No lines reused because we displayed everything up to the
17755 bottom of the window. */
17756 && it
.current_y
< it
.last_visible_y
)
17759 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17761 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17762 run
.current_y
= first_unchanged_at_end_row
->y
;
17763 run
.desired_y
= run
.current_y
+ dy
;
17764 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17768 delta
= delta_bytes
= dvpos
= dy
17769 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17770 first_unchanged_at_end_row
= NULL
;
17772 IF_DEBUG ((debug_dvpos
= dvpos
, debug_dy
= dy
));
17775 /* Find the cursor if not already found. We have to decide whether
17776 PT will appear on this window (it sometimes doesn't, but this is
17777 not a very frequent case.) This decision has to be made before
17778 the current matrix is altered. A value of cursor.vpos < 0 means
17779 that PT is either in one of the lines beginning at
17780 first_unchanged_at_end_row or below the window. Don't care for
17781 lines that might be displayed later at the window end; as
17782 mentioned, this is not a frequent case. */
17783 if (w
->cursor
.vpos
< 0)
17785 /* Cursor in unchanged rows at the top? */
17786 if (PT
< CHARPOS (start_pos
)
17787 && last_unchanged_at_beg_row
)
17789 row
= row_containing_pos (w
, PT
,
17790 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17791 last_unchanged_at_beg_row
+ 1, 0);
17793 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17796 /* Start from first_unchanged_at_end_row looking for PT. */
17797 else if (first_unchanged_at_end_row
)
17799 row
= row_containing_pos (w
, PT
- delta
,
17800 first_unchanged_at_end_row
, NULL
, 0);
17802 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17803 delta_bytes
, dy
, dvpos
);
17806 /* Give up if cursor was not found. */
17807 if (w
->cursor
.vpos
< 0)
17809 clear_glyph_matrix (w
->desired_matrix
);
17814 /* Don't let the cursor end in the scroll margins. */
17816 int this_scroll_margin
, cursor_height
;
17817 int frame_line_height
= default_line_pixel_height (w
);
17818 int window_total_lines
17819 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17821 this_scroll_margin
=
17822 max (0, min (scroll_margin
, window_total_lines
/ 4));
17823 this_scroll_margin
*= frame_line_height
;
17824 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17826 if ((w
->cursor
.y
< this_scroll_margin
17827 && CHARPOS (start
) > BEGV
)
17828 /* Old redisplay didn't take scroll margin into account at the bottom,
17829 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17830 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17831 ? cursor_height
+ this_scroll_margin
17832 : 1)) > it
.last_visible_y
)
17834 w
->cursor
.vpos
= -1;
17835 clear_glyph_matrix (w
->desired_matrix
);
17840 /* Scroll the display. Do it before changing the current matrix so
17841 that xterm.c doesn't get confused about where the cursor glyph is
17843 if (dy
&& run
.height
)
17847 if (FRAME_WINDOW_P (f
))
17849 FRAME_RIF (f
)->update_window_begin_hook (w
);
17850 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17851 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17852 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17856 /* Terminal frame. In this case, dvpos gives the number of
17857 lines to scroll by; dvpos < 0 means scroll up. */
17859 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17860 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17861 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17862 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17863 + window_internal_height (w
));
17865 #if defined (HAVE_GPM) || defined (MSDOS)
17866 x_clear_window_mouse_face (w
);
17868 /* Perform the operation on the screen. */
17871 /* Scroll last_unchanged_at_beg_row to the end of the
17872 window down dvpos lines. */
17873 set_terminal_window (f
, end
);
17875 /* On dumb terminals delete dvpos lines at the end
17876 before inserting dvpos empty lines. */
17877 if (!FRAME_SCROLL_REGION_OK (f
))
17878 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17880 /* Insert dvpos empty lines in front of
17881 last_unchanged_at_beg_row. */
17882 ins_del_lines (f
, from
, dvpos
);
17884 else if (dvpos
< 0)
17886 /* Scroll up last_unchanged_at_beg_vpos to the end of
17887 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17888 set_terminal_window (f
, end
);
17890 /* Delete dvpos lines in front of
17891 last_unchanged_at_beg_vpos. ins_del_lines will set
17892 the cursor to the given vpos and emit |dvpos| delete
17894 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17896 /* On a dumb terminal insert dvpos empty lines at the
17898 if (!FRAME_SCROLL_REGION_OK (f
))
17899 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17902 set_terminal_window (f
, 0);
17908 /* Shift reused rows of the current matrix to the right position.
17909 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17911 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17912 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17915 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17916 bottom_vpos
, dvpos
);
17917 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17920 else if (dvpos
> 0)
17922 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17923 bottom_vpos
, dvpos
);
17924 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17925 first_unchanged_at_end_vpos
+ dvpos
);
17928 /* For frame-based redisplay, make sure that current frame and window
17929 matrix are in sync with respect to glyph memory. */
17930 if (!FRAME_WINDOW_P (f
))
17931 sync_frame_with_window_matrix_rows (w
);
17933 /* Adjust buffer positions in reused rows. */
17934 if (delta
|| delta_bytes
)
17935 increment_matrix_positions (current_matrix
,
17936 first_unchanged_at_end_vpos
+ dvpos
,
17937 bottom_vpos
, delta
, delta_bytes
);
17939 /* Adjust Y positions. */
17941 shift_glyph_matrix (w
, current_matrix
,
17942 first_unchanged_at_end_vpos
+ dvpos
,
17945 if (first_unchanged_at_end_row
)
17947 first_unchanged_at_end_row
+= dvpos
;
17948 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17949 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17950 first_unchanged_at_end_row
= NULL
;
17953 /* If scrolling up, there may be some lines to display at the end of
17955 last_text_row_at_end
= NULL
;
17958 /* Scrolling up can leave for example a partially visible line
17959 at the end of the window to be redisplayed. */
17960 /* Set last_row to the glyph row in the current matrix where the
17961 window end line is found. It has been moved up or down in
17962 the matrix by dvpos. */
17963 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17964 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17966 /* If last_row is the window end line, it should display text. */
17967 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17969 /* If window end line was partially visible before, begin
17970 displaying at that line. Otherwise begin displaying with the
17971 line following it. */
17972 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17974 init_to_row_start (&it
, w
, last_row
);
17975 it
.vpos
= last_vpos
;
17976 it
.current_y
= last_row
->y
;
17980 init_to_row_end (&it
, w
, last_row
);
17981 it
.vpos
= 1 + last_vpos
;
17982 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17986 /* We may start in a continuation line. If so, we have to
17987 get the right continuation_lines_width and current_x. */
17988 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17989 it
.hpos
= it
.current_x
= 0;
17991 /* Display the rest of the lines at the window end. */
17992 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17993 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17995 /* Is it always sure that the display agrees with lines in
17996 the current matrix? I don't think so, so we mark rows
17997 displayed invalid in the current matrix by setting their
17998 enabled_p flag to zero. */
17999 SET_MATRIX_ROW_ENABLED_P (w
->current_matrix
, it
.vpos
, false);
18000 if (display_line (&it
))
18001 last_text_row_at_end
= it
.glyph_row
- 1;
18005 /* Update window_end_pos and window_end_vpos. */
18006 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
18008 /* Window end line if one of the preserved rows from the current
18009 matrix. Set row to the last row displaying text in current
18010 matrix starting at first_unchanged_at_end_row, after
18012 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
18013 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
18014 first_unchanged_at_end_row
);
18015 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
18016 adjust_window_ends (w
, row
, 1);
18017 eassert (w
->window_end_bytepos
>= 0);
18018 IF_DEBUG (debug_method_add (w
, "A"));
18020 else if (last_text_row_at_end
)
18022 adjust_window_ends (w
, last_text_row_at_end
, 0);
18023 eassert (w
->window_end_bytepos
>= 0);
18024 IF_DEBUG (debug_method_add (w
, "B"));
18026 else if (last_text_row
)
18028 /* We have displayed either to the end of the window or at the
18029 end of the window, i.e. the last row with text is to be found
18030 in the desired matrix. */
18031 adjust_window_ends (w
, last_text_row
, 0);
18032 eassert (w
->window_end_bytepos
>= 0);
18034 else if (first_unchanged_at_end_row
== NULL
18035 && last_text_row
== NULL
18036 && last_text_row_at_end
== NULL
)
18038 /* Displayed to end of window, but no line containing text was
18039 displayed. Lines were deleted at the end of the window. */
18040 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
18041 int vpos
= w
->window_end_vpos
;
18042 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
18043 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
18046 row
== NULL
&& vpos
>= first_vpos
;
18047 --vpos
, --current_row
, --desired_row
)
18049 if (desired_row
->enabled_p
)
18051 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
18054 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
18058 eassert (row
!= NULL
);
18059 w
->window_end_vpos
= vpos
+ 1;
18060 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
18061 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
18062 eassert (w
->window_end_bytepos
>= 0);
18063 IF_DEBUG (debug_method_add (w
, "C"));
18068 IF_DEBUG ((debug_end_pos
= w
->window_end_pos
,
18069 debug_end_vpos
= w
->window_end_vpos
));
18071 /* Record that display has not been completed. */
18072 w
->window_end_valid
= 0;
18073 w
->desired_matrix
->no_scrolling_p
= 1;
18081 /***********************************************************************
18082 More debugging support
18083 ***********************************************************************/
18087 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
18088 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
18089 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
18092 /* Dump the contents of glyph matrix MATRIX on stderr.
18094 GLYPHS 0 means don't show glyph contents.
18095 GLYPHS 1 means show glyphs in short form
18096 GLYPHS > 1 means show glyphs in long form. */
18099 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
18102 for (i
= 0; i
< matrix
->nrows
; ++i
)
18103 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
18107 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
18108 the glyph row and area where the glyph comes from. */
18111 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
18113 if (glyph
->type
== CHAR_GLYPH
18114 || glyph
->type
== GLYPHLESS_GLYPH
)
18117 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18118 glyph
- row
->glyphs
[TEXT_AREA
],
18119 (glyph
->type
== CHAR_GLYPH
18123 (BUFFERP (glyph
->object
)
18125 : (STRINGP (glyph
->object
)
18127 : (INTEGERP (glyph
->object
)
18130 glyph
->pixel_width
,
18132 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
18136 glyph
->left_box_line_p
,
18137 glyph
->right_box_line_p
);
18139 else if (glyph
->type
== STRETCH_GLYPH
)
18142 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18143 glyph
- row
->glyphs
[TEXT_AREA
],
18146 (BUFFERP (glyph
->object
)
18148 : (STRINGP (glyph
->object
)
18150 : (INTEGERP (glyph
->object
)
18153 glyph
->pixel_width
,
18157 glyph
->left_box_line_p
,
18158 glyph
->right_box_line_p
);
18160 else if (glyph
->type
== IMAGE_GLYPH
)
18163 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
18164 glyph
- row
->glyphs
[TEXT_AREA
],
18167 (BUFFERP (glyph
->object
)
18169 : (STRINGP (glyph
->object
)
18171 : (INTEGERP (glyph
->object
)
18174 glyph
->pixel_width
,
18178 glyph
->left_box_line_p
,
18179 glyph
->right_box_line_p
);
18181 else if (glyph
->type
== COMPOSITE_GLYPH
)
18184 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
18185 glyph
- row
->glyphs
[TEXT_AREA
],
18188 (BUFFERP (glyph
->object
)
18190 : (STRINGP (glyph
->object
)
18192 : (INTEGERP (glyph
->object
)
18195 glyph
->pixel_width
,
18197 if (glyph
->u
.cmp
.automatic
)
18200 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18201 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18203 glyph
->left_box_line_p
,
18204 glyph
->right_box_line_p
);
18209 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18210 GLYPHS 0 means don't show glyph contents.
18211 GLYPHS 1 means show glyphs in short form
18212 GLYPHS > 1 means show glyphs in long form. */
18215 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18219 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18220 fprintf (stderr
, "==============================================================================\n");
18222 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18223 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18225 MATRIX_ROW_START_CHARPOS (row
),
18226 MATRIX_ROW_END_CHARPOS (row
),
18227 row
->used
[TEXT_AREA
],
18228 row
->contains_overlapping_glyphs_p
,
18230 row
->truncated_on_left_p
,
18231 row
->truncated_on_right_p
,
18233 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18234 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18237 row
->ends_in_middle_of_char_p
,
18238 row
->starts_in_middle_of_char_p
,
18244 row
->visible_height
,
18247 /* The next 3 lines should align to "Start" in the header. */
18248 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18249 row
->end
.overlay_string_index
,
18250 row
->continuation_lines_width
);
18251 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18252 CHARPOS (row
->start
.string_pos
),
18253 CHARPOS (row
->end
.string_pos
));
18254 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18255 row
->end
.dpvec_index
);
18262 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18264 struct glyph
*glyph
= row
->glyphs
[area
];
18265 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18267 /* Glyph for a line end in text. */
18268 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18271 if (glyph
< glyph_end
)
18272 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18274 for (; glyph
< glyph_end
; ++glyph
)
18275 dump_glyph (row
, glyph
, area
);
18278 else if (glyphs
== 1)
18282 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18284 char *s
= alloca (row
->used
[area
] + 4);
18287 for (i
= 0; i
< row
->used
[area
]; ++i
)
18289 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18290 if (i
== row
->used
[area
] - 1
18291 && area
== TEXT_AREA
18292 && INTEGERP (glyph
->object
)
18293 && glyph
->type
== CHAR_GLYPH
18294 && glyph
->u
.ch
== ' ')
18296 strcpy (&s
[i
], "[\\n]");
18299 else if (glyph
->type
== CHAR_GLYPH
18300 && glyph
->u
.ch
< 0x80
18301 && glyph
->u
.ch
>= ' ')
18302 s
[i
] = glyph
->u
.ch
;
18308 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18314 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18315 Sdump_glyph_matrix
, 0, 1, "p",
18316 doc
: /* Dump the current matrix of the selected window to stderr.
18317 Shows contents of glyph row structures. With non-nil
18318 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18319 glyphs in short form, otherwise show glyphs in long form. */)
18320 (Lisp_Object glyphs
)
18322 struct window
*w
= XWINDOW (selected_window
);
18323 struct buffer
*buffer
= XBUFFER (w
->contents
);
18325 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18326 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18327 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18328 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18329 fprintf (stderr
, "=============================================\n");
18330 dump_glyph_matrix (w
->current_matrix
,
18331 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18336 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18337 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18340 struct frame
*f
= XFRAME (selected_frame
);
18341 dump_glyph_matrix (f
->current_matrix
, 1);
18346 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18347 doc
: /* Dump glyph row ROW to stderr.
18348 GLYPH 0 means don't dump glyphs.
18349 GLYPH 1 means dump glyphs in short form.
18350 GLYPH > 1 or omitted means dump glyphs in long form. */)
18351 (Lisp_Object row
, Lisp_Object glyphs
)
18353 struct glyph_matrix
*matrix
;
18356 CHECK_NUMBER (row
);
18357 matrix
= XWINDOW (selected_window
)->current_matrix
;
18359 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18360 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18362 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18367 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18368 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18369 GLYPH 0 means don't dump glyphs.
18370 GLYPH 1 means dump glyphs in short form.
18371 GLYPH > 1 or omitted means dump glyphs in long form.
18373 If there's no tool-bar, or if the tool-bar is not drawn by Emacs,
18375 (Lisp_Object row
, Lisp_Object glyphs
)
18377 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18378 struct frame
*sf
= SELECTED_FRAME ();
18379 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18382 CHECK_NUMBER (row
);
18384 if (vpos
>= 0 && vpos
< m
->nrows
)
18385 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18386 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18392 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18393 doc
: /* Toggle tracing of redisplay.
18394 With ARG, turn tracing on if and only if ARG is positive. */)
18398 trace_redisplay_p
= !trace_redisplay_p
;
18401 arg
= Fprefix_numeric_value (arg
);
18402 trace_redisplay_p
= XINT (arg
) > 0;
18409 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18410 doc
: /* Like `format', but print result to stderr.
18411 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18412 (ptrdiff_t nargs
, Lisp_Object
*args
)
18414 Lisp_Object s
= Fformat (nargs
, args
);
18415 fprintf (stderr
, "%s", SDATA (s
));
18419 #endif /* GLYPH_DEBUG */
18423 /***********************************************************************
18424 Building Desired Matrix Rows
18425 ***********************************************************************/
18427 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18428 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18430 static struct glyph_row
*
18431 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18433 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18434 struct buffer
*buffer
= XBUFFER (w
->contents
);
18435 struct buffer
*old
= current_buffer
;
18436 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18437 int arrow_len
= SCHARS (overlay_arrow_string
);
18438 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18439 const unsigned char *p
;
18442 int n_glyphs_before
;
18444 set_buffer_temp (buffer
);
18445 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18446 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18447 SET_TEXT_POS (it
.position
, 0, 0);
18449 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18451 while (p
< arrow_end
)
18453 Lisp_Object face
, ilisp
;
18455 /* Get the next character. */
18457 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18460 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18461 if (! ASCII_CHAR_P (it
.c
))
18462 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18466 /* Get its face. */
18467 ilisp
= make_number (p
- arrow_string
);
18468 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18469 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18471 /* Compute its width, get its glyphs. */
18472 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18473 SET_TEXT_POS (it
.position
, -1, -1);
18474 PRODUCE_GLYPHS (&it
);
18476 /* If this character doesn't fit any more in the line, we have
18477 to remove some glyphs. */
18478 if (it
.current_x
> it
.last_visible_x
)
18480 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18485 set_buffer_temp (old
);
18486 return it
.glyph_row
;
18490 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18491 glyphs to insert is determined by produce_special_glyphs. */
18494 insert_left_trunc_glyphs (struct it
*it
)
18496 struct it truncate_it
;
18497 struct glyph
*from
, *end
, *to
, *toend
;
18499 eassert (!FRAME_WINDOW_P (it
->f
)
18500 || (!it
->glyph_row
->reversed_p
18501 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18502 || (it
->glyph_row
->reversed_p
18503 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18505 /* Get the truncation glyphs. */
18507 truncate_it
.current_x
= 0;
18508 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18509 truncate_it
.glyph_row
= &scratch_glyph_row
;
18510 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18511 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18512 truncate_it
.object
= make_number (0);
18513 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18515 /* Overwrite glyphs from IT with truncation glyphs. */
18516 if (!it
->glyph_row
->reversed_p
)
18518 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18520 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18521 end
= from
+ tused
;
18522 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18523 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18524 if (FRAME_WINDOW_P (it
->f
))
18526 /* On GUI frames, when variable-size fonts are displayed,
18527 the truncation glyphs may need more pixels than the row's
18528 glyphs they overwrite. We overwrite more glyphs to free
18529 enough screen real estate, and enlarge the stretch glyph
18530 on the right (see display_line), if there is one, to
18531 preserve the screen position of the truncation glyphs on
18534 struct glyph
*g
= to
;
18537 /* The first glyph could be partially visible, in which case
18538 it->glyph_row->x will be negative. But we want the left
18539 truncation glyphs to be aligned at the left margin of the
18540 window, so we override the x coordinate at which the row
18542 it
->glyph_row
->x
= 0;
18543 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18545 w
+= g
->pixel_width
;
18548 if (g
- to
- tused
> 0)
18550 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18551 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18553 used
= it
->glyph_row
->used
[TEXT_AREA
];
18554 if (it
->glyph_row
->truncated_on_right_p
18555 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18556 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18559 int extra
= w
- it
->truncation_pixel_width
;
18561 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18568 /* There may be padding glyphs left over. Overwrite them too. */
18569 if (!FRAME_WINDOW_P (it
->f
))
18571 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18573 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18580 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18584 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18586 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18587 that back to front. */
18588 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18589 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18590 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18591 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18592 if (FRAME_WINDOW_P (it
->f
))
18595 struct glyph
*g
= to
;
18597 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18599 w
+= g
->pixel_width
;
18602 if (to
- g
- tused
> 0)
18604 if (it
->glyph_row
->truncated_on_right_p
18605 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18606 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18608 int extra
= w
- it
->truncation_pixel_width
;
18610 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18614 while (from
>= end
&& to
>= toend
)
18616 if (!FRAME_WINDOW_P (it
->f
))
18618 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18621 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18622 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18623 while (from
>= end
&& to
>= toend
)
18629 /* Need to free some room before prepending additional
18631 int move_by
= from
- end
+ 1;
18632 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18633 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18635 for ( ; g
>= g0
; g
--)
18637 while (from
>= end
)
18639 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18644 /* Compute the hash code for ROW. */
18646 row_hash (struct glyph_row
*row
)
18649 unsigned hashval
= 0;
18651 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18652 for (k
= 0; k
< row
->used
[area
]; ++k
)
18653 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18654 + row
->glyphs
[area
][k
].u
.val
18655 + row
->glyphs
[area
][k
].face_id
18656 + row
->glyphs
[area
][k
].padding_p
18657 + (row
->glyphs
[area
][k
].type
<< 2));
18662 /* Compute the pixel height and width of IT->glyph_row.
18664 Most of the time, ascent and height of a display line will be equal
18665 to the max_ascent and max_height values of the display iterator
18666 structure. This is not the case if
18668 1. We hit ZV without displaying anything. In this case, max_ascent
18669 and max_height will be zero.
18671 2. We have some glyphs that don't contribute to the line height.
18672 (The glyph row flag contributes_to_line_height_p is for future
18673 pixmap extensions).
18675 The first case is easily covered by using default values because in
18676 these cases, the line height does not really matter, except that it
18677 must not be zero. */
18680 compute_line_metrics (struct it
*it
)
18682 struct glyph_row
*row
= it
->glyph_row
;
18684 if (FRAME_WINDOW_P (it
->f
))
18686 int i
, min_y
, max_y
;
18688 /* The line may consist of one space only, that was added to
18689 place the cursor on it. If so, the row's height hasn't been
18691 if (row
->height
== 0)
18693 if (it
->max_ascent
+ it
->max_descent
== 0)
18694 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18695 row
->ascent
= it
->max_ascent
;
18696 row
->height
= it
->max_ascent
+ it
->max_descent
;
18697 row
->phys_ascent
= it
->max_phys_ascent
;
18698 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18699 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18702 /* Compute the width of this line. */
18703 row
->pixel_width
= row
->x
;
18704 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18705 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18707 eassert (row
->pixel_width
>= 0);
18708 eassert (row
->ascent
>= 0 && row
->height
> 0);
18710 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18711 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18713 /* If first line's physical ascent is larger than its logical
18714 ascent, use the physical ascent, and make the row taller.
18715 This makes accented characters fully visible. */
18716 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18717 && row
->phys_ascent
> row
->ascent
)
18719 row
->height
+= row
->phys_ascent
- row
->ascent
;
18720 row
->ascent
= row
->phys_ascent
;
18723 /* Compute how much of the line is visible. */
18724 row
->visible_height
= row
->height
;
18726 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18727 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18729 if (row
->y
< min_y
)
18730 row
->visible_height
-= min_y
- row
->y
;
18731 if (row
->y
+ row
->height
> max_y
)
18732 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18736 row
->pixel_width
= row
->used
[TEXT_AREA
];
18737 if (row
->continued_p
)
18738 row
->pixel_width
-= it
->continuation_pixel_width
;
18739 else if (row
->truncated_on_right_p
)
18740 row
->pixel_width
-= it
->truncation_pixel_width
;
18741 row
->ascent
= row
->phys_ascent
= 0;
18742 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18743 row
->extra_line_spacing
= 0;
18746 /* Compute a hash code for this row. */
18747 row
->hash
= row_hash (row
);
18749 it
->max_ascent
= it
->max_descent
= 0;
18750 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18754 /* Append one space to the glyph row of iterator IT if doing a
18755 window-based redisplay. The space has the same face as
18756 IT->face_id. Value is non-zero if a space was added.
18758 This function is called to make sure that there is always one glyph
18759 at the end of a glyph row that the cursor can be set on under
18760 window-systems. (If there weren't such a glyph we would not know
18761 how wide and tall a box cursor should be displayed).
18763 At the same time this space let's a nicely handle clearing to the
18764 end of the line if the row ends in italic text. */
18767 append_space_for_newline (struct it
*it
, int default_face_p
)
18769 if (FRAME_WINDOW_P (it
->f
))
18771 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18773 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18774 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18776 /* Save some values that must not be changed.
18777 Must save IT->c and IT->len because otherwise
18778 ITERATOR_AT_END_P wouldn't work anymore after
18779 append_space_for_newline has been called. */
18780 enum display_element_type saved_what
= it
->what
;
18781 int saved_c
= it
->c
, saved_len
= it
->len
;
18782 int saved_char_to_display
= it
->char_to_display
;
18783 int saved_x
= it
->current_x
;
18784 int saved_face_id
= it
->face_id
;
18785 int saved_box_end
= it
->end_of_box_run_p
;
18786 struct text_pos saved_pos
;
18787 Lisp_Object saved_object
;
18790 saved_object
= it
->object
;
18791 saved_pos
= it
->position
;
18793 it
->what
= IT_CHARACTER
;
18794 memset (&it
->position
, 0, sizeof it
->position
);
18795 it
->object
= make_number (0);
18796 it
->c
= it
->char_to_display
= ' ';
18799 /* If the default face was remapped, be sure to use the
18800 remapped face for the appended newline. */
18801 if (default_face_p
)
18802 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18803 else if (it
->face_before_selective_p
)
18804 it
->face_id
= it
->saved_face_id
;
18805 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18806 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18807 /* In R2L rows, we will prepend a stretch glyph that will
18808 have the end_of_box_run_p flag set for it, so there's no
18809 need for the appended newline glyph to have that flag
18811 if (it
->glyph_row
->reversed_p
18812 /* But if the appended newline glyph goes all the way to
18813 the end of the row, there will be no stretch glyph,
18814 so leave the box flag set. */
18815 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18816 it
->end_of_box_run_p
= 0;
18818 PRODUCE_GLYPHS (it
);
18820 it
->override_ascent
= -1;
18821 it
->constrain_row_ascent_descent_p
= 0;
18822 it
->current_x
= saved_x
;
18823 it
->object
= saved_object
;
18824 it
->position
= saved_pos
;
18825 it
->what
= saved_what
;
18826 it
->face_id
= saved_face_id
;
18827 it
->len
= saved_len
;
18829 it
->char_to_display
= saved_char_to_display
;
18830 it
->end_of_box_run_p
= saved_box_end
;
18839 /* Extend the face of the last glyph in the text area of IT->glyph_row
18840 to the end of the display line. Called from display_line. If the
18841 glyph row is empty, add a space glyph to it so that we know the
18842 face to draw. Set the glyph row flag fill_line_p. If the glyph
18843 row is R2L, prepend a stretch glyph to cover the empty space to the
18844 left of the leftmost glyph. */
18847 extend_face_to_end_of_line (struct it
*it
)
18849 struct face
*face
, *default_face
;
18850 struct frame
*f
= it
->f
;
18852 /* If line is already filled, do nothing. Non window-system frames
18853 get a grace of one more ``pixel'' because their characters are
18854 1-``pixel'' wide, so they hit the equality too early. This grace
18855 is needed only for R2L rows that are not continued, to produce
18856 one extra blank where we could display the cursor. */
18857 if ((it
->current_x
>= it
->last_visible_x
18858 + (!FRAME_WINDOW_P (f
)
18859 && it
->glyph_row
->reversed_p
18860 && !it
->glyph_row
->continued_p
))
18861 /* If the window has display margins, we will need to extend
18862 their face even if the text area is filled. */
18863 && !(WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
18864 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0))
18867 /* The default face, possibly remapped. */
18868 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18870 /* Face extension extends the background and box of IT->face_id
18871 to the end of the line. If the background equals the background
18872 of the frame, we don't have to do anything. */
18873 if (it
->face_before_selective_p
)
18874 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18876 face
= FACE_FROM_ID (f
, it
->face_id
);
18878 if (FRAME_WINDOW_P (f
)
18879 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18880 && face
->box
== FACE_NO_BOX
18881 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18882 #ifdef HAVE_WINDOW_SYSTEM
18885 && !it
->glyph_row
->reversed_p
)
18888 /* Set the glyph row flag indicating that the face of the last glyph
18889 in the text area has to be drawn to the end of the text area. */
18890 it
->glyph_row
->fill_line_p
= 1;
18892 /* If current character of IT is not ASCII, make sure we have the
18893 ASCII face. This will be automatically undone the next time
18894 get_next_display_element returns a multibyte character. Note
18895 that the character will always be single byte in unibyte
18897 if (!ASCII_CHAR_P (it
->c
))
18899 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18902 if (FRAME_WINDOW_P (f
))
18904 /* If the row is empty, add a space with the current face of IT,
18905 so that we know which face to draw. */
18906 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18908 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18909 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18910 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18912 /* Mode line and the header line don't have margins, and
18913 likewise the frame's tool-bar window, if there is any. */
18914 if (!(it
->glyph_row
->mode_line_p
18915 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
18916 || (WINDOWP (f
->tool_bar_window
)
18917 && it
->w
== XWINDOW (f
->tool_bar_window
))
18921 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
18922 && it
->glyph_row
->used
[LEFT_MARGIN_AREA
] == 0)
18924 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0] = space_glyph
;
18925 it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
][0].face_id
=
18927 it
->glyph_row
->used
[LEFT_MARGIN_AREA
] = 1;
18929 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
18930 && it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] == 0)
18932 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0] = space_glyph
;
18933 it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
][0].face_id
=
18935 it
->glyph_row
->used
[RIGHT_MARGIN_AREA
] = 1;
18938 #ifdef HAVE_WINDOW_SYSTEM
18939 if (it
->glyph_row
->reversed_p
)
18941 /* Prepend a stretch glyph to the row, such that the
18942 rightmost glyph will be drawn flushed all the way to the
18943 right margin of the window. The stretch glyph that will
18944 occupy the empty space, if any, to the left of the
18946 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18947 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18948 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18950 int row_width
, stretch_ascent
, stretch_width
;
18951 struct text_pos saved_pos
;
18952 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18954 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18955 row_width
+= g
->pixel_width
;
18956 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18957 if (stretch_width
> 0)
18960 (((it
->ascent
+ it
->descent
)
18961 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18962 saved_pos
= it
->position
;
18963 memset (&it
->position
, 0, sizeof it
->position
);
18964 saved_avoid_cursor
= it
->avoid_cursor_p
;
18965 it
->avoid_cursor_p
= 1;
18966 saved_face_id
= it
->face_id
;
18967 saved_box_start
= it
->start_of_box_run_p
;
18968 /* The last row's stretch glyph should get the default
18969 face, to avoid painting the rest of the window with
18970 the region face, if the region ends at ZV. */
18971 if (it
->glyph_row
->ends_at_zv_p
)
18972 it
->face_id
= default_face
->id
;
18974 it
->face_id
= face
->id
;
18975 it
->start_of_box_run_p
= 0;
18976 append_stretch_glyph (it
, make_number (0), stretch_width
,
18977 it
->ascent
+ it
->descent
, stretch_ascent
);
18978 it
->position
= saved_pos
;
18979 it
->avoid_cursor_p
= saved_avoid_cursor
;
18980 it
->face_id
= saved_face_id
;
18981 it
->start_of_box_run_p
= saved_box_start
;
18984 #endif /* HAVE_WINDOW_SYSTEM */
18988 /* Save some values that must not be changed. */
18989 int saved_x
= it
->current_x
;
18990 struct text_pos saved_pos
;
18991 Lisp_Object saved_object
;
18992 enum display_element_type saved_what
= it
->what
;
18993 int saved_face_id
= it
->face_id
;
18995 saved_object
= it
->object
;
18996 saved_pos
= it
->position
;
18998 it
->what
= IT_CHARACTER
;
18999 memset (&it
->position
, 0, sizeof it
->position
);
19000 it
->object
= make_number (0);
19001 it
->c
= it
->char_to_display
= ' ';
19004 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19005 && (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19006 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19007 && !it
->glyph_row
->mode_line_p
19008 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19010 struct glyph
*g
= it
->glyph_row
->glyphs
[LEFT_MARGIN_AREA
];
19011 struct glyph
*e
= g
+ it
->glyph_row
->used
[LEFT_MARGIN_AREA
];
19013 for (it
->current_x
= 0; g
< e
; g
++)
19014 it
->current_x
+= g
->pixel_width
;
19016 it
->area
= LEFT_MARGIN_AREA
;
19017 it
->face_id
= default_face
->id
;
19018 while (it
->glyph_row
->used
[LEFT_MARGIN_AREA
]
19019 < WINDOW_LEFT_MARGIN_WIDTH (it
->w
))
19021 PRODUCE_GLYPHS (it
);
19022 /* term.c:produce_glyphs advances it->current_x only for
19024 it
->current_x
+= it
->pixel_width
;
19027 it
->current_x
= saved_x
;
19028 it
->area
= TEXT_AREA
;
19031 /* The last row's blank glyphs should get the default face, to
19032 avoid painting the rest of the window with the region face,
19033 if the region ends at ZV. */
19034 if (it
->glyph_row
->ends_at_zv_p
)
19035 it
->face_id
= default_face
->id
;
19037 it
->face_id
= face
->id
;
19038 PRODUCE_GLYPHS (it
);
19040 while (it
->current_x
<= it
->last_visible_x
)
19041 PRODUCE_GLYPHS (it
);
19043 if (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0
19044 && (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19045 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19046 && !it
->glyph_row
->mode_line_p
19047 && default_face
->background
!= FRAME_BACKGROUND_PIXEL (f
))
19049 struct glyph
*g
= it
->glyph_row
->glyphs
[RIGHT_MARGIN_AREA
];
19050 struct glyph
*e
= g
+ it
->glyph_row
->used
[RIGHT_MARGIN_AREA
];
19052 for ( ; g
< e
; g
++)
19053 it
->current_x
+= g
->pixel_width
;
19055 it
->area
= RIGHT_MARGIN_AREA
;
19056 it
->face_id
= default_face
->id
;
19057 while (it
->glyph_row
->used
[RIGHT_MARGIN_AREA
]
19058 < WINDOW_RIGHT_MARGIN_WIDTH (it
->w
))
19060 PRODUCE_GLYPHS (it
);
19061 it
->current_x
+= it
->pixel_width
;
19064 it
->area
= TEXT_AREA
;
19067 /* Don't count these blanks really. It would let us insert a left
19068 truncation glyph below and make us set the cursor on them, maybe. */
19069 it
->current_x
= saved_x
;
19070 it
->object
= saved_object
;
19071 it
->position
= saved_pos
;
19072 it
->what
= saved_what
;
19073 it
->face_id
= saved_face_id
;
19078 /* Value is non-zero if text starting at CHARPOS in current_buffer is
19079 trailing whitespace. */
19082 trailing_whitespace_p (ptrdiff_t charpos
)
19084 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
19087 while (bytepos
< ZV_BYTE
19088 && (c
= FETCH_CHAR (bytepos
),
19089 c
== ' ' || c
== '\t'))
19092 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
19094 if (bytepos
!= PT_BYTE
)
19101 /* Highlight trailing whitespace, if any, in ROW. */
19104 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
19106 int used
= row
->used
[TEXT_AREA
];
19110 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
19111 struct glyph
*glyph
= start
+ used
- 1;
19113 if (row
->reversed_p
)
19115 /* Right-to-left rows need to be processed in the opposite
19116 direction, so swap the edge pointers. */
19118 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
19121 /* Skip over glyphs inserted to display the cursor at the
19122 end of a line, for extending the face of the last glyph
19123 to the end of the line on terminals, and for truncation
19124 and continuation glyphs. */
19125 if (!row
->reversed_p
)
19127 while (glyph
>= start
19128 && glyph
->type
== CHAR_GLYPH
19129 && INTEGERP (glyph
->object
))
19134 while (glyph
<= start
19135 && glyph
->type
== CHAR_GLYPH
19136 && INTEGERP (glyph
->object
))
19140 /* If last glyph is a space or stretch, and it's trailing
19141 whitespace, set the face of all trailing whitespace glyphs in
19142 IT->glyph_row to `trailing-whitespace'. */
19143 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
19144 && BUFFERP (glyph
->object
)
19145 && (glyph
->type
== STRETCH_GLYPH
19146 || (glyph
->type
== CHAR_GLYPH
19147 && glyph
->u
.ch
== ' '))
19148 && trailing_whitespace_p (glyph
->charpos
))
19150 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
19154 if (!row
->reversed_p
)
19156 while (glyph
>= start
19157 && BUFFERP (glyph
->object
)
19158 && (glyph
->type
== STRETCH_GLYPH
19159 || (glyph
->type
== CHAR_GLYPH
19160 && glyph
->u
.ch
== ' ')))
19161 (glyph
--)->face_id
= face_id
;
19165 while (glyph
<= start
19166 && BUFFERP (glyph
->object
)
19167 && (glyph
->type
== STRETCH_GLYPH
19168 || (glyph
->type
== CHAR_GLYPH
19169 && glyph
->u
.ch
== ' ')))
19170 (glyph
++)->face_id
= face_id
;
19177 /* Value is non-zero if glyph row ROW should be
19178 considered to hold the buffer position CHARPOS. */
19181 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
19185 if (charpos
== CHARPOS (row
->end
.pos
)
19186 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
19188 /* Suppose the row ends on a string.
19189 Unless the row is continued, that means it ends on a newline
19190 in the string. If it's anything other than a display string
19191 (e.g., a before-string from an overlay), we don't want the
19192 cursor there. (This heuristic seems to give the optimal
19193 behavior for the various types of multi-line strings.)
19194 One exception: if the string has `cursor' property on one of
19195 its characters, we _do_ want the cursor there. */
19196 if (CHARPOS (row
->end
.string_pos
) >= 0)
19198 if (row
->continued_p
)
19202 /* Check for `display' property. */
19203 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
19204 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
19205 struct glyph
*glyph
;
19208 for (glyph
= end
; glyph
>= beg
; --glyph
)
19209 if (STRINGP (glyph
->object
))
19212 = Fget_char_property (make_number (charpos
),
19216 && display_prop_string_p (prop
, glyph
->object
));
19217 /* If there's a `cursor' property on one of the
19218 string's characters, this row is a cursor row,
19219 even though this is not a display string. */
19222 Lisp_Object s
= glyph
->object
;
19224 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
19226 ptrdiff_t gpos
= glyph
->charpos
;
19228 if (!NILP (Fget_char_property (make_number (gpos
),
19240 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
19242 /* If the row ends in middle of a real character,
19243 and the line is continued, we want the cursor here.
19244 That's because CHARPOS (ROW->end.pos) would equal
19245 PT if PT is before the character. */
19246 if (!row
->ends_in_ellipsis_p
)
19247 result
= row
->continued_p
;
19249 /* If the row ends in an ellipsis, then
19250 CHARPOS (ROW->end.pos) will equal point after the
19251 invisible text. We want that position to be displayed
19252 after the ellipsis. */
19255 /* If the row ends at ZV, display the cursor at the end of that
19256 row instead of at the start of the row below. */
19257 else if (row
->ends_at_zv_p
)
19266 /* Value is non-zero if glyph row ROW should be
19267 used to hold the cursor. */
19270 cursor_row_p (struct glyph_row
*row
)
19272 return row_for_charpos_p (row
, PT
);
19277 /* Push the property PROP so that it will be rendered at the current
19278 position in IT. Return 1 if PROP was successfully pushed, 0
19279 otherwise. Called from handle_line_prefix to handle the
19280 `line-prefix' and `wrap-prefix' properties. */
19283 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19285 struct text_pos pos
=
19286 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19288 eassert (it
->method
== GET_FROM_BUFFER
19289 || it
->method
== GET_FROM_DISPLAY_VECTOR
19290 || it
->method
== GET_FROM_STRING
);
19292 /* We need to save the current buffer/string position, so it will be
19293 restored by pop_it, because iterate_out_of_display_property
19294 depends on that being set correctly, but some situations leave
19295 it->position not yet set when this function is called. */
19296 push_it (it
, &pos
);
19298 if (STRINGP (prop
))
19300 if (SCHARS (prop
) == 0)
19307 it
->string_from_prefix_prop_p
= 1;
19308 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19309 it
->current
.overlay_string_index
= -1;
19310 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19311 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19312 it
->method
= GET_FROM_STRING
;
19313 it
->stop_charpos
= 0;
19315 it
->base_level_stop
= 0;
19317 /* Force paragraph direction to be that of the parent
19319 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19320 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19322 it
->paragraph_embedding
= L2R
;
19324 /* Set up the bidi iterator for this display string. */
19327 it
->bidi_it
.string
.lstring
= it
->string
;
19328 it
->bidi_it
.string
.s
= NULL
;
19329 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19330 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19331 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19332 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19333 it
->bidi_it
.w
= it
->w
;
19334 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19337 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19339 it
->method
= GET_FROM_STRETCH
;
19342 #ifdef HAVE_WINDOW_SYSTEM
19343 else if (IMAGEP (prop
))
19345 it
->what
= IT_IMAGE
;
19346 it
->image_id
= lookup_image (it
->f
, prop
);
19347 it
->method
= GET_FROM_IMAGE
;
19349 #endif /* HAVE_WINDOW_SYSTEM */
19352 pop_it (it
); /* bogus display property, give up */
19359 /* Return the character-property PROP at the current position in IT. */
19362 get_it_property (struct it
*it
, Lisp_Object prop
)
19364 Lisp_Object position
, object
= it
->object
;
19366 if (STRINGP (object
))
19367 position
= make_number (IT_STRING_CHARPOS (*it
));
19368 else if (BUFFERP (object
))
19370 position
= make_number (IT_CHARPOS (*it
));
19371 object
= it
->window
;
19376 return Fget_char_property (position
, prop
, object
);
19379 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19382 handle_line_prefix (struct it
*it
)
19384 Lisp_Object prefix
;
19386 if (it
->continuation_lines_width
> 0)
19388 prefix
= get_it_property (it
, Qwrap_prefix
);
19390 prefix
= Vwrap_prefix
;
19394 prefix
= get_it_property (it
, Qline_prefix
);
19396 prefix
= Vline_prefix
;
19398 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19400 /* If the prefix is wider than the window, and we try to wrap
19401 it, it would acquire its own wrap prefix, and so on till the
19402 iterator stack overflows. So, don't wrap the prefix. */
19403 it
->line_wrap
= TRUNCATE
;
19404 it
->avoid_cursor_p
= 1;
19410 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19411 only for R2L lines from display_line and display_string, when they
19412 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19413 the line/string needs to be continued on the next glyph row. */
19415 unproduce_glyphs (struct it
*it
, int n
)
19417 struct glyph
*glyph
, *end
;
19419 eassert (it
->glyph_row
);
19420 eassert (it
->glyph_row
->reversed_p
);
19421 eassert (it
->area
== TEXT_AREA
);
19422 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19424 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19425 n
= it
->glyph_row
->used
[TEXT_AREA
];
19426 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19427 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19428 for ( ; glyph
< end
; glyph
++)
19429 glyph
[-n
] = *glyph
;
19432 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19433 and ROW->maxpos. */
19435 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19436 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19437 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19439 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19440 lines' rows is implemented for bidi-reordered rows. */
19442 /* ROW->minpos is the value of min_pos, the minimal buffer position
19443 we have in ROW, or ROW->start.pos if that is smaller. */
19444 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19445 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19447 /* We didn't find buffer positions smaller than ROW->start, or
19448 didn't find _any_ valid buffer positions in any of the glyphs,
19449 so we must trust the iterator's computed positions. */
19450 row
->minpos
= row
->start
.pos
;
19453 max_pos
= CHARPOS (it
->current
.pos
);
19454 max_bpos
= BYTEPOS (it
->current
.pos
);
19457 /* Here are the various use-cases for ending the row, and the
19458 corresponding values for ROW->maxpos:
19460 Line ends in a newline from buffer eol_pos + 1
19461 Line is continued from buffer max_pos + 1
19462 Line is truncated on right it->current.pos
19463 Line ends in a newline from string max_pos + 1(*)
19464 (*) + 1 only when line ends in a forward scan
19465 Line is continued from string max_pos
19466 Line is continued from display vector max_pos
19467 Line is entirely from a string min_pos == max_pos
19468 Line is entirely from a display vector min_pos == max_pos
19469 Line that ends at ZV ZV
19471 If you discover other use-cases, please add them here as
19473 if (row
->ends_at_zv_p
)
19474 row
->maxpos
= it
->current
.pos
;
19475 else if (row
->used
[TEXT_AREA
])
19477 int seen_this_string
= 0;
19478 struct glyph_row
*r1
= row
- 1;
19480 /* Did we see the same display string on the previous row? */
19481 if (STRINGP (it
->object
)
19482 /* this is not the first row */
19483 && row
> it
->w
->desired_matrix
->rows
19484 /* previous row is not the header line */
19485 && !r1
->mode_line_p
19486 /* previous row also ends in a newline from a string */
19487 && r1
->ends_in_newline_from_string_p
)
19489 struct glyph
*start
, *end
;
19491 /* Search for the last glyph of the previous row that came
19492 from buffer or string. Depending on whether the row is
19493 L2R or R2L, we need to process it front to back or the
19494 other way round. */
19495 if (!r1
->reversed_p
)
19497 start
= r1
->glyphs
[TEXT_AREA
];
19498 end
= start
+ r1
->used
[TEXT_AREA
];
19499 /* Glyphs inserted by redisplay have an integer (zero)
19500 as their object. */
19502 && INTEGERP ((end
- 1)->object
)
19503 && (end
- 1)->charpos
<= 0)
19507 if (EQ ((end
- 1)->object
, it
->object
))
19508 seen_this_string
= 1;
19511 /* If all the glyphs of the previous row were inserted
19512 by redisplay, it means the previous row was
19513 produced from a single newline, which is only
19514 possible if that newline came from the same string
19515 as the one which produced this ROW. */
19516 seen_this_string
= 1;
19520 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19521 start
= end
+ r1
->used
[TEXT_AREA
];
19523 && INTEGERP ((end
+ 1)->object
)
19524 && (end
+ 1)->charpos
<= 0)
19528 if (EQ ((end
+ 1)->object
, it
->object
))
19529 seen_this_string
= 1;
19532 seen_this_string
= 1;
19535 /* Take note of each display string that covers a newline only
19536 once, the first time we see it. This is for when a display
19537 string includes more than one newline in it. */
19538 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19540 /* If we were scanning the buffer forward when we displayed
19541 the string, we want to account for at least one buffer
19542 position that belongs to this row (position covered by
19543 the display string), so that cursor positioning will
19544 consider this row as a candidate when point is at the end
19545 of the visual line represented by this row. This is not
19546 required when scanning back, because max_pos will already
19547 have a much larger value. */
19548 if (CHARPOS (row
->end
.pos
) > max_pos
)
19549 INC_BOTH (max_pos
, max_bpos
);
19550 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19552 else if (CHARPOS (it
->eol_pos
) > 0)
19553 SET_TEXT_POS (row
->maxpos
,
19554 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19555 else if (row
->continued_p
)
19557 /* If max_pos is different from IT's current position, it
19558 means IT->method does not belong to the display element
19559 at max_pos. However, it also means that the display
19560 element at max_pos was displayed in its entirety on this
19561 line, which is equivalent to saying that the next line
19562 starts at the next buffer position. */
19563 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19564 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19567 INC_BOTH (max_pos
, max_bpos
);
19568 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19571 else if (row
->truncated_on_right_p
)
19572 /* display_line already called reseat_at_next_visible_line_start,
19573 which puts the iterator at the beginning of the next line, in
19574 the logical order. */
19575 row
->maxpos
= it
->current
.pos
;
19576 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19577 /* A line that is entirely from a string/image/stretch... */
19578 row
->maxpos
= row
->minpos
;
19583 row
->maxpos
= it
->current
.pos
;
19586 /* Construct the glyph row IT->glyph_row in the desired matrix of
19587 IT->w from text at the current position of IT. See dispextern.h
19588 for an overview of struct it. Value is non-zero if
19589 IT->glyph_row displays text, as opposed to a line displaying ZV
19593 display_line (struct it
*it
)
19595 struct glyph_row
*row
= it
->glyph_row
;
19596 Lisp_Object overlay_arrow_string
;
19598 void *wrap_data
= NULL
;
19599 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19600 int wrap_row_used
= -1;
19601 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19602 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19603 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19604 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19605 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19607 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19608 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19610 /* We always start displaying at hpos zero even if hscrolled. */
19611 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19613 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19614 >= it
->w
->desired_matrix
->nrows
)
19616 it
->w
->nrows_scale_factor
++;
19617 it
->f
->fonts_changed
= 1;
19621 /* Clear the result glyph row and enable it. */
19622 prepare_desired_row (row
);
19624 row
->y
= it
->current_y
;
19625 row
->start
= it
->start
;
19626 row
->continuation_lines_width
= it
->continuation_lines_width
;
19627 row
->displays_text_p
= 1;
19628 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19629 it
->starts_in_middle_of_char_p
= 0;
19631 /* Arrange the overlays nicely for our purposes. Usually, we call
19632 display_line on only one line at a time, in which case this
19633 can't really hurt too much, or we call it on lines which appear
19634 one after another in the buffer, in which case all calls to
19635 recenter_overlay_lists but the first will be pretty cheap. */
19636 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19638 /* Move over display elements that are not visible because we are
19639 hscrolled. This may stop at an x-position < IT->first_visible_x
19640 if the first glyph is partially visible or if we hit a line end. */
19641 if (it
->current_x
< it
->first_visible_x
)
19643 enum move_it_result move_result
;
19645 this_line_min_pos
= row
->start
.pos
;
19646 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19647 MOVE_TO_POS
| MOVE_TO_X
);
19648 /* If we are under a large hscroll, move_it_in_display_line_to
19649 could hit the end of the line without reaching
19650 it->first_visible_x. Pretend that we did reach it. This is
19651 especially important on a TTY, where we will call
19652 extend_face_to_end_of_line, which needs to know how many
19653 blank glyphs to produce. */
19654 if (it
->current_x
< it
->first_visible_x
19655 && (move_result
== MOVE_NEWLINE_OR_CR
19656 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19657 it
->current_x
= it
->first_visible_x
;
19659 /* Record the smallest positions seen while we moved over
19660 display elements that are not visible. This is needed by
19661 redisplay_internal for optimizing the case where the cursor
19662 stays inside the same line. The rest of this function only
19663 considers positions that are actually displayed, so
19664 RECORD_MAX_MIN_POS will not otherwise record positions that
19665 are hscrolled to the left of the left edge of the window. */
19666 min_pos
= CHARPOS (this_line_min_pos
);
19667 min_bpos
= BYTEPOS (this_line_min_pos
);
19671 /* We only do this when not calling `move_it_in_display_line_to'
19672 above, because move_it_in_display_line_to calls
19673 handle_line_prefix itself. */
19674 handle_line_prefix (it
);
19677 /* Get the initial row height. This is either the height of the
19678 text hscrolled, if there is any, or zero. */
19679 row
->ascent
= it
->max_ascent
;
19680 row
->height
= it
->max_ascent
+ it
->max_descent
;
19681 row
->phys_ascent
= it
->max_phys_ascent
;
19682 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19683 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19685 /* Utility macro to record max and min buffer positions seen until now. */
19686 #define RECORD_MAX_MIN_POS(IT) \
19689 int composition_p = !STRINGP ((IT)->string) \
19690 && ((IT)->what == IT_COMPOSITION); \
19691 ptrdiff_t current_pos = \
19692 composition_p ? (IT)->cmp_it.charpos \
19693 : IT_CHARPOS (*(IT)); \
19694 ptrdiff_t current_bpos = \
19695 composition_p ? CHAR_TO_BYTE (current_pos) \
19696 : IT_BYTEPOS (*(IT)); \
19697 if (current_pos < min_pos) \
19699 min_pos = current_pos; \
19700 min_bpos = current_bpos; \
19702 if (IT_CHARPOS (*it) > max_pos) \
19704 max_pos = IT_CHARPOS (*it); \
19705 max_bpos = IT_BYTEPOS (*it); \
19710 /* Loop generating characters. The loop is left with IT on the next
19711 character to display. */
19714 int n_glyphs_before
, hpos_before
, x_before
;
19716 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19718 /* Retrieve the next thing to display. Value is zero if end of
19720 if (!get_next_display_element (it
))
19722 /* Maybe add a space at the end of this line that is used to
19723 display the cursor there under X. Set the charpos of the
19724 first glyph of blank lines not corresponding to any text
19726 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19727 row
->exact_window_width_line_p
= 1;
19728 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19729 || row
->used
[TEXT_AREA
] == 0)
19731 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19732 row
->displays_text_p
= 0;
19734 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19735 && (!MINI_WINDOW_P (it
->w
)
19736 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19737 row
->indicate_empty_line_p
= 1;
19740 it
->continuation_lines_width
= 0;
19741 row
->ends_at_zv_p
= 1;
19742 /* A row that displays right-to-left text must always have
19743 its last face extended all the way to the end of line,
19744 even if this row ends in ZV, because we still write to
19745 the screen left to right. We also need to extend the
19746 last face if the default face is remapped to some
19747 different face, otherwise the functions that clear
19748 portions of the screen will clear with the default face's
19749 background color. */
19750 if (row
->reversed_p
19751 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19752 extend_face_to_end_of_line (it
);
19756 /* Now, get the metrics of what we want to display. This also
19757 generates glyphs in `row' (which is IT->glyph_row). */
19758 n_glyphs_before
= row
->used
[TEXT_AREA
];
19761 /* Remember the line height so far in case the next element doesn't
19762 fit on the line. */
19763 if (it
->line_wrap
!= TRUNCATE
)
19765 ascent
= it
->max_ascent
;
19766 descent
= it
->max_descent
;
19767 phys_ascent
= it
->max_phys_ascent
;
19768 phys_descent
= it
->max_phys_descent
;
19770 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19772 if (IT_DISPLAYING_WHITESPACE (it
))
19776 SAVE_IT (wrap_it
, *it
, wrap_data
);
19778 wrap_row_used
= row
->used
[TEXT_AREA
];
19779 wrap_row_ascent
= row
->ascent
;
19780 wrap_row_height
= row
->height
;
19781 wrap_row_phys_ascent
= row
->phys_ascent
;
19782 wrap_row_phys_height
= row
->phys_height
;
19783 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19784 wrap_row_min_pos
= min_pos
;
19785 wrap_row_min_bpos
= min_bpos
;
19786 wrap_row_max_pos
= max_pos
;
19787 wrap_row_max_bpos
= max_bpos
;
19793 PRODUCE_GLYPHS (it
);
19795 /* If this display element was in marginal areas, continue with
19797 if (it
->area
!= TEXT_AREA
)
19799 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19800 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19801 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19802 row
->phys_height
= max (row
->phys_height
,
19803 it
->max_phys_ascent
+ it
->max_phys_descent
);
19804 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19805 it
->max_extra_line_spacing
);
19806 set_iterator_to_next (it
, 1);
19810 /* Does the display element fit on the line? If we truncate
19811 lines, we should draw past the right edge of the window. If
19812 we don't truncate, we want to stop so that we can display the
19813 continuation glyph before the right margin. If lines are
19814 continued, there are two possible strategies for characters
19815 resulting in more than 1 glyph (e.g. tabs): Display as many
19816 glyphs as possible in this line and leave the rest for the
19817 continuation line, or display the whole element in the next
19818 line. Original redisplay did the former, so we do it also. */
19819 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19820 hpos_before
= it
->hpos
;
19823 if (/* Not a newline. */
19825 /* Glyphs produced fit entirely in the line. */
19826 && it
->current_x
< it
->last_visible_x
)
19828 it
->hpos
+= nglyphs
;
19829 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19830 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19831 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19832 row
->phys_height
= max (row
->phys_height
,
19833 it
->max_phys_ascent
+ it
->max_phys_descent
);
19834 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19835 it
->max_extra_line_spacing
);
19836 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19837 row
->x
= x
- it
->first_visible_x
;
19838 /* Record the maximum and minimum buffer positions seen so
19839 far in glyphs that will be displayed by this row. */
19841 RECORD_MAX_MIN_POS (it
);
19846 struct glyph
*glyph
;
19848 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19850 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19851 new_x
= x
+ glyph
->pixel_width
;
19853 if (/* Lines are continued. */
19854 it
->line_wrap
!= TRUNCATE
19855 && (/* Glyph doesn't fit on the line. */
19856 new_x
> it
->last_visible_x
19857 /* Or it fits exactly on a window system frame. */
19858 || (new_x
== it
->last_visible_x
19859 && FRAME_WINDOW_P (it
->f
)
19860 && (row
->reversed_p
19861 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19862 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19864 /* End of a continued line. */
19867 || (new_x
== it
->last_visible_x
19868 && FRAME_WINDOW_P (it
->f
)
19869 && (row
->reversed_p
19870 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19871 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19873 /* Current glyph is the only one on the line or
19874 fits exactly on the line. We must continue
19875 the line because we can't draw the cursor
19876 after the glyph. */
19877 row
->continued_p
= 1;
19878 it
->current_x
= new_x
;
19879 it
->continuation_lines_width
+= new_x
;
19881 if (i
== nglyphs
- 1)
19883 /* If line-wrap is on, check if a previous
19884 wrap point was found. */
19885 if (wrap_row_used
> 0
19886 /* Even if there is a previous wrap
19887 point, continue the line here as
19888 usual, if (i) the previous character
19889 was a space or tab AND (ii) the
19890 current character is not. */
19892 || IT_DISPLAYING_WHITESPACE (it
)))
19895 /* Record the maximum and minimum buffer
19896 positions seen so far in glyphs that will be
19897 displayed by this row. */
19899 RECORD_MAX_MIN_POS (it
);
19900 set_iterator_to_next (it
, 1);
19901 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19903 if (!get_next_display_element (it
))
19905 row
->exact_window_width_line_p
= 1;
19906 it
->continuation_lines_width
= 0;
19907 row
->continued_p
= 0;
19908 row
->ends_at_zv_p
= 1;
19910 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19912 row
->continued_p
= 0;
19913 row
->exact_window_width_line_p
= 1;
19917 else if (it
->bidi_p
)
19918 RECORD_MAX_MIN_POS (it
);
19919 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19920 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
19921 extend_face_to_end_of_line (it
);
19923 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19924 && !FRAME_WINDOW_P (it
->f
))
19926 /* A padding glyph that doesn't fit on this line.
19927 This means the whole character doesn't fit
19929 if (row
->reversed_p
)
19930 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19931 - n_glyphs_before
);
19932 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19934 /* Fill the rest of the row with continuation
19935 glyphs like in 20.x. */
19936 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19937 < row
->glyphs
[1 + TEXT_AREA
])
19938 produce_special_glyphs (it
, IT_CONTINUATION
);
19940 row
->continued_p
= 1;
19941 it
->current_x
= x_before
;
19942 it
->continuation_lines_width
+= x_before
;
19944 /* Restore the height to what it was before the
19945 element not fitting on the line. */
19946 it
->max_ascent
= ascent
;
19947 it
->max_descent
= descent
;
19948 it
->max_phys_ascent
= phys_ascent
;
19949 it
->max_phys_descent
= phys_descent
;
19950 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19951 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
19952 extend_face_to_end_of_line (it
);
19954 else if (wrap_row_used
> 0)
19957 if (row
->reversed_p
)
19958 unproduce_glyphs (it
,
19959 row
->used
[TEXT_AREA
] - wrap_row_used
);
19960 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19961 it
->continuation_lines_width
+= wrap_x
;
19962 row
->used
[TEXT_AREA
] = wrap_row_used
;
19963 row
->ascent
= wrap_row_ascent
;
19964 row
->height
= wrap_row_height
;
19965 row
->phys_ascent
= wrap_row_phys_ascent
;
19966 row
->phys_height
= wrap_row_phys_height
;
19967 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19968 min_pos
= wrap_row_min_pos
;
19969 min_bpos
= wrap_row_min_bpos
;
19970 max_pos
= wrap_row_max_pos
;
19971 max_bpos
= wrap_row_max_bpos
;
19972 row
->continued_p
= 1;
19973 row
->ends_at_zv_p
= 0;
19974 row
->exact_window_width_line_p
= 0;
19975 it
->continuation_lines_width
+= x
;
19977 /* Make sure that a non-default face is extended
19978 up to the right margin of the window. */
19979 extend_face_to_end_of_line (it
);
19981 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19983 /* A TAB that extends past the right edge of the
19984 window. This produces a single glyph on
19985 window system frames. We leave the glyph in
19986 this row and let it fill the row, but don't
19987 consume the TAB. */
19988 if ((row
->reversed_p
19989 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19990 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19991 produce_special_glyphs (it
, IT_CONTINUATION
);
19992 it
->continuation_lines_width
+= it
->last_visible_x
;
19993 row
->ends_in_middle_of_char_p
= 1;
19994 row
->continued_p
= 1;
19995 glyph
->pixel_width
= it
->last_visible_x
- x
;
19996 it
->starts_in_middle_of_char_p
= 1;
19997 if (WINDOW_LEFT_MARGIN_WIDTH (it
->w
) > 0
19998 || WINDOW_RIGHT_MARGIN_WIDTH (it
->w
) > 0)
19999 extend_face_to_end_of_line (it
);
20003 /* Something other than a TAB that draws past
20004 the right edge of the window. Restore
20005 positions to values before the element. */
20006 if (row
->reversed_p
)
20007 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
20008 - (n_glyphs_before
+ i
));
20009 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
20011 /* Display continuation glyphs. */
20012 it
->current_x
= x_before
;
20013 it
->continuation_lines_width
+= x
;
20014 if (!FRAME_WINDOW_P (it
->f
)
20015 || (row
->reversed_p
20016 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20017 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20018 produce_special_glyphs (it
, IT_CONTINUATION
);
20019 row
->continued_p
= 1;
20021 extend_face_to_end_of_line (it
);
20023 if (nglyphs
> 1 && i
> 0)
20025 row
->ends_in_middle_of_char_p
= 1;
20026 it
->starts_in_middle_of_char_p
= 1;
20029 /* Restore the height to what it was before the
20030 element not fitting on the line. */
20031 it
->max_ascent
= ascent
;
20032 it
->max_descent
= descent
;
20033 it
->max_phys_ascent
= phys_ascent
;
20034 it
->max_phys_descent
= phys_descent
;
20039 else if (new_x
> it
->first_visible_x
)
20041 /* Increment number of glyphs actually displayed. */
20044 /* Record the maximum and minimum buffer positions
20045 seen so far in glyphs that will be displayed by
20048 RECORD_MAX_MIN_POS (it
);
20050 if (x
< it
->first_visible_x
)
20051 /* Glyph is partially visible, i.e. row starts at
20052 negative X position. */
20053 row
->x
= x
- it
->first_visible_x
;
20057 /* Glyph is completely off the left margin of the
20058 window. This should not happen because of the
20059 move_it_in_display_line at the start of this
20060 function, unless the text display area of the
20061 window is empty. */
20062 eassert (it
->first_visible_x
<= it
->last_visible_x
);
20065 /* Even if this display element produced no glyphs at all,
20066 we want to record its position. */
20067 if (it
->bidi_p
&& nglyphs
== 0)
20068 RECORD_MAX_MIN_POS (it
);
20070 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
20071 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
20072 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
20073 row
->phys_height
= max (row
->phys_height
,
20074 it
->max_phys_ascent
+ it
->max_phys_descent
);
20075 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
20076 it
->max_extra_line_spacing
);
20078 /* End of this display line if row is continued. */
20079 if (row
->continued_p
|| row
->ends_at_zv_p
)
20084 /* Is this a line end? If yes, we're also done, after making
20085 sure that a non-default face is extended up to the right
20086 margin of the window. */
20087 if (ITERATOR_AT_END_OF_LINE_P (it
))
20089 int used_before
= row
->used
[TEXT_AREA
];
20091 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
20093 /* Add a space at the end of the line that is used to
20094 display the cursor there. */
20095 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20096 append_space_for_newline (it
, 0);
20098 /* Extend the face to the end of the line. */
20099 extend_face_to_end_of_line (it
);
20101 /* Make sure we have the position. */
20102 if (used_before
== 0)
20103 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
20105 /* Record the position of the newline, for use in
20107 it
->eol_pos
= it
->current
.pos
;
20109 /* Consume the line end. This skips over invisible lines. */
20110 set_iterator_to_next (it
, 1);
20111 it
->continuation_lines_width
= 0;
20115 /* Proceed with next display element. Note that this skips
20116 over lines invisible because of selective display. */
20117 set_iterator_to_next (it
, 1);
20119 /* If we truncate lines, we are done when the last displayed
20120 glyphs reach past the right margin of the window. */
20121 if (it
->line_wrap
== TRUNCATE
20122 && ((FRAME_WINDOW_P (it
->f
)
20123 /* Images are preprocessed in produce_image_glyph such
20124 that they are cropped at the right edge of the
20125 window, so an image glyph will always end exactly at
20126 last_visible_x, even if there's no right fringe. */
20127 && (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) || it
->what
== IT_IMAGE
))
20128 ? (it
->current_x
>= it
->last_visible_x
)
20129 : (it
->current_x
> it
->last_visible_x
)))
20131 /* Maybe add truncation glyphs. */
20132 if (!FRAME_WINDOW_P (it
->f
)
20133 || (row
->reversed_p
20134 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
20135 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
20139 if (!row
->reversed_p
)
20141 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
20142 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20147 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
20148 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
20150 /* Remove any padding glyphs at the front of ROW, to
20151 make room for the truncation glyphs we will be
20152 adding below. The loop below always inserts at
20153 least one truncation glyph, so also remove the
20154 last glyph added to ROW. */
20155 unproduce_glyphs (it
, i
+ 1);
20156 /* Adjust i for the loop below. */
20157 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
20160 /* produce_special_glyphs overwrites the last glyph, so
20161 we don't want that if we want to keep that last
20162 glyph, which means it's an image. */
20163 if (it
->current_x
> it
->last_visible_x
)
20165 it
->current_x
= x_before
;
20166 if (!FRAME_WINDOW_P (it
->f
))
20168 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
20170 row
->used
[TEXT_AREA
] = i
;
20171 produce_special_glyphs (it
, IT_TRUNCATION
);
20176 row
->used
[TEXT_AREA
] = i
;
20177 produce_special_glyphs (it
, IT_TRUNCATION
);
20179 it
->hpos
= hpos_before
;
20182 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
20184 /* Don't truncate if we can overflow newline into fringe. */
20185 if (!get_next_display_element (it
))
20187 it
->continuation_lines_width
= 0;
20188 row
->ends_at_zv_p
= 1;
20189 row
->exact_window_width_line_p
= 1;
20192 if (ITERATOR_AT_END_OF_LINE_P (it
))
20194 row
->exact_window_width_line_p
= 1;
20195 goto at_end_of_line
;
20197 it
->current_x
= x_before
;
20198 it
->hpos
= hpos_before
;
20201 row
->truncated_on_right_p
= 1;
20202 it
->continuation_lines_width
= 0;
20203 reseat_at_next_visible_line_start (it
, 0);
20204 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
20210 bidi_unshelve_cache (wrap_data
, 1);
20212 /* If line is not empty and hscrolled, maybe insert truncation glyphs
20213 at the left window margin. */
20214 if (it
->first_visible_x
20215 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
20217 if (!FRAME_WINDOW_P (it
->f
)
20218 || (((row
->reversed_p
20219 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
20220 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
20221 /* Don't let insert_left_trunc_glyphs overwrite the
20222 first glyph of the row if it is an image. */
20223 && row
->glyphs
[TEXT_AREA
]->type
!= IMAGE_GLYPH
))
20224 insert_left_trunc_glyphs (it
);
20225 row
->truncated_on_left_p
= 1;
20228 /* Remember the position at which this line ends.
20230 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
20231 cannot be before the call to find_row_edges below, since that is
20232 where these positions are determined. */
20233 row
->end
= it
->current
;
20236 row
->minpos
= row
->start
.pos
;
20237 row
->maxpos
= row
->end
.pos
;
20241 /* ROW->minpos and ROW->maxpos must be the smallest and
20242 `1 + the largest' buffer positions in ROW. But if ROW was
20243 bidi-reordered, these two positions can be anywhere in the
20244 row, so we must determine them now. */
20245 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
20248 /* If the start of this line is the overlay arrow-position, then
20249 mark this glyph row as the one containing the overlay arrow.
20250 This is clearly a mess with variable size fonts. It would be
20251 better to let it be displayed like cursors under X. */
20252 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
20253 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
20254 !NILP (overlay_arrow_string
)))
20256 /* Overlay arrow in window redisplay is a fringe bitmap. */
20257 if (STRINGP (overlay_arrow_string
))
20259 struct glyph_row
*arrow_row
20260 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
20261 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
20262 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
20263 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
20264 struct glyph
*p2
, *end
;
20266 /* Copy the arrow glyphs. */
20267 while (glyph
< arrow_end
)
20270 /* Throw away padding glyphs. */
20272 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
20273 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20279 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20284 eassert (INTEGERP (overlay_arrow_string
));
20285 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20287 overlay_arrow_seen
= 1;
20290 /* Highlight trailing whitespace. */
20291 if (!NILP (Vshow_trailing_whitespace
))
20292 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20294 /* Compute pixel dimensions of this line. */
20295 compute_line_metrics (it
);
20297 /* Implementation note: No changes in the glyphs of ROW or in their
20298 faces can be done past this point, because compute_line_metrics
20299 computes ROW's hash value and stores it within the glyph_row
20302 /* Record whether this row ends inside an ellipsis. */
20303 row
->ends_in_ellipsis_p
20304 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20305 && it
->ellipsis_p
);
20307 /* Save fringe bitmaps in this row. */
20308 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20309 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20310 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20311 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20313 it
->left_user_fringe_bitmap
= 0;
20314 it
->left_user_fringe_face_id
= 0;
20315 it
->right_user_fringe_bitmap
= 0;
20316 it
->right_user_fringe_face_id
= 0;
20318 /* Maybe set the cursor. */
20319 cvpos
= it
->w
->cursor
.vpos
;
20321 /* In bidi-reordered rows, keep checking for proper cursor
20322 position even if one has been found already, because buffer
20323 positions in such rows change non-linearly with ROW->VPOS,
20324 when a line is continued. One exception: when we are at ZV,
20325 display cursor on the first suitable glyph row, since all
20326 the empty rows after that also have their position set to ZV. */
20327 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20328 lines' rows is implemented for bidi-reordered rows. */
20330 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20331 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20332 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20333 && cursor_row_p (row
))
20334 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20336 /* Prepare for the next line. This line starts horizontally at (X
20337 HPOS) = (0 0). Vertical positions are incremented. As a
20338 convenience for the caller, IT->glyph_row is set to the next
20340 it
->current_x
= it
->hpos
= 0;
20341 it
->current_y
+= row
->height
;
20342 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20345 /* The next row should by default use the same value of the
20346 reversed_p flag as this one. set_iterator_to_next decides when
20347 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20348 the flag accordingly. */
20349 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20350 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20351 it
->start
= row
->end
;
20352 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20354 #undef RECORD_MAX_MIN_POS
20357 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20358 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20359 doc
: /* Return paragraph direction at point in BUFFER.
20360 Value is either `left-to-right' or `right-to-left'.
20361 If BUFFER is omitted or nil, it defaults to the current buffer.
20363 Paragraph direction determines how the text in the paragraph is displayed.
20364 In left-to-right paragraphs, text begins at the left margin of the window
20365 and the reading direction is generally left to right. In right-to-left
20366 paragraphs, text begins at the right margin and is read from right to left.
20368 See also `bidi-paragraph-direction'. */)
20369 (Lisp_Object buffer
)
20371 struct buffer
*buf
= current_buffer
;
20372 struct buffer
*old
= buf
;
20374 if (! NILP (buffer
))
20376 CHECK_BUFFER (buffer
);
20377 buf
= XBUFFER (buffer
);
20380 if (NILP (BVAR (buf
, bidi_display_reordering
))
20381 || NILP (BVAR (buf
, enable_multibyte_characters
))
20382 /* When we are loading loadup.el, the character property tables
20383 needed for bidi iteration are not yet available. */
20384 || !NILP (Vpurify_flag
))
20385 return Qleft_to_right
;
20386 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20387 return BVAR (buf
, bidi_paragraph_direction
);
20390 /* Determine the direction from buffer text. We could try to
20391 use current_matrix if it is up to date, but this seems fast
20392 enough as it is. */
20393 struct bidi_it itb
;
20394 ptrdiff_t pos
= BUF_PT (buf
);
20395 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20397 void *itb_data
= bidi_shelve_cache ();
20399 set_buffer_temp (buf
);
20400 /* bidi_paragraph_init finds the base direction of the paragraph
20401 by searching forward from paragraph start. We need the base
20402 direction of the current or _previous_ paragraph, so we need
20403 to make sure we are within that paragraph. To that end, find
20404 the previous non-empty line. */
20405 if (pos
>= ZV
&& pos
> BEGV
)
20406 DEC_BOTH (pos
, bytepos
);
20407 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20408 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20410 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20411 || c
== ' ' || c
== '\t' || c
== '\f')
20413 if (bytepos
<= BEGV_BYTE
)
20418 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20421 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20422 itb
.paragraph_dir
= NEUTRAL_DIR
;
20423 itb
.string
.s
= NULL
;
20424 itb
.string
.lstring
= Qnil
;
20425 itb
.string
.bufpos
= 0;
20426 itb
.string
.from_disp_str
= 0;
20427 itb
.string
.unibyte
= 0;
20428 /* We have no window to use here for ignoring window-specific
20429 overlays. Using NULL for window pointer will cause
20430 compute_display_string_pos to use the current buffer. */
20432 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20433 bidi_unshelve_cache (itb_data
, 0);
20434 set_buffer_temp (old
);
20435 switch (itb
.paragraph_dir
)
20438 return Qleft_to_right
;
20441 return Qright_to_left
;
20449 DEFUN ("move-point-visually", Fmove_point_visually
,
20450 Smove_point_visually
, 1, 1, 0,
20451 doc
: /* Move point in the visual order in the specified DIRECTION.
20452 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20455 Value is the new character position of point. */)
20456 (Lisp_Object direction
)
20458 struct window
*w
= XWINDOW (selected_window
);
20459 struct buffer
*b
= XBUFFER (w
->contents
);
20460 struct glyph_row
*row
;
20462 Lisp_Object paragraph_dir
;
20464 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20465 (!(ROW)->continued_p \
20466 && INTEGERP ((GLYPH)->object) \
20467 && (GLYPH)->type == CHAR_GLYPH \
20468 && (GLYPH)->u.ch == ' ' \
20469 && (GLYPH)->charpos >= 0 \
20470 && !(GLYPH)->avoid_cursor_p)
20472 CHECK_NUMBER (direction
);
20473 dir
= XINT (direction
);
20479 /* If current matrix is up-to-date, we can use the information
20480 recorded in the glyphs, at least as long as the goal is on the
20482 if (w
->window_end_valid
20483 && !windows_or_buffers_changed
20485 && !b
->clip_changed
20486 && !b
->prevent_redisplay_optimizations_p
20487 && !window_outdated (w
)
20488 && w
->cursor
.vpos
>= 0
20489 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20490 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20492 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20493 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20494 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20496 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20498 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20500 SET_PT (g
->charpos
);
20501 w
->cursor
.vpos
= -1;
20502 return make_number (PT
);
20504 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20508 if (BUFFERP (gpt
->object
))
20511 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20512 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20514 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20516 else if (BUFFERP (g
->object
))
20517 new_pos
= g
->charpos
;
20521 w
->cursor
.vpos
= -1;
20522 return make_number (PT
);
20524 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20526 /* Glyphs inserted at the end of a non-empty line for
20527 positioning the cursor have zero charpos, so we must
20528 deduce the value of point by other means. */
20529 if (g
->charpos
> 0)
20530 SET_PT (g
->charpos
);
20531 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20533 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20534 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20537 w
->cursor
.vpos
= -1;
20538 return make_number (PT
);
20541 if (g
== e
|| INTEGERP (g
->object
))
20543 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20544 goto simulate_display
;
20545 if (!row
->reversed_p
)
20549 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20550 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20551 goto simulate_display
;
20555 if (row
->reversed_p
&& !row
->continued_p
)
20557 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20558 w
->cursor
.vpos
= -1;
20559 return make_number (PT
);
20561 g
= row
->glyphs
[TEXT_AREA
];
20562 e
= g
+ row
->used
[TEXT_AREA
];
20563 for ( ; g
< e
; g
++)
20565 if (BUFFERP (g
->object
)
20566 /* Empty lines have only one glyph, which stands
20567 for the newline, and whose charpos is the
20568 buffer position of the newline. */
20569 || ROW_GLYPH_NEWLINE_P (row
, g
)
20570 /* When the buffer ends in a newline, the line at
20571 EOB also has one glyph, but its charpos is -1. */
20572 || (row
->ends_at_zv_p
20573 && !row
->reversed_p
20574 && INTEGERP (g
->object
)
20575 && g
->type
== CHAR_GLYPH
20576 && g
->u
.ch
== ' '))
20578 if (g
->charpos
> 0)
20579 SET_PT (g
->charpos
);
20580 else if (!row
->reversed_p
20581 && row
->ends_at_zv_p
20586 w
->cursor
.vpos
= -1;
20587 return make_number (PT
);
20593 if (!row
->reversed_p
&& !row
->continued_p
)
20595 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20596 w
->cursor
.vpos
= -1;
20597 return make_number (PT
);
20599 e
= row
->glyphs
[TEXT_AREA
];
20600 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20601 for ( ; g
>= e
; g
--)
20603 if (BUFFERP (g
->object
)
20604 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20606 /* Empty R2L lines on GUI frames have the buffer
20607 position of the newline stored in the stretch
20609 || g
->type
== STRETCH_GLYPH
20610 || (row
->ends_at_zv_p
20612 && INTEGERP (g
->object
)
20613 && g
->type
== CHAR_GLYPH
20614 && g
->u
.ch
== ' '))
20616 if (g
->charpos
> 0)
20617 SET_PT (g
->charpos
);
20618 else if (row
->reversed_p
20619 && row
->ends_at_zv_p
20624 w
->cursor
.vpos
= -1;
20625 return make_number (PT
);
20634 /* If we wind up here, we failed to move by using the glyphs, so we
20635 need to simulate display instead. */
20638 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20640 paragraph_dir
= Qleft_to_right
;
20641 if (EQ (paragraph_dir
, Qright_to_left
))
20643 if (PT
<= BEGV
&& dir
< 0)
20644 xsignal0 (Qbeginning_of_buffer
);
20645 else if (PT
>= ZV
&& dir
> 0)
20646 xsignal0 (Qend_of_buffer
);
20649 struct text_pos pt
;
20651 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20653 bool overshoot_expected
= false;
20654 bool target_is_eol_p
= false;
20656 /* Setup the arena. */
20657 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20658 start_display (&it
, w
, pt
);
20660 if (it
.cmp_it
.id
< 0
20661 && it
.method
== GET_FROM_STRING
20662 && it
.area
== TEXT_AREA
20663 && it
.string_from_display_prop_p
20664 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20665 overshoot_expected
= true;
20667 /* Find the X coordinate of point. We start from the beginning
20668 of this or previous line to make sure we are before point in
20669 the logical order (since the move_it_* functions can only
20672 reseat_at_previous_visible_line_start (&it
);
20673 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20674 if (IT_CHARPOS (it
) != PT
)
20676 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20677 -1, -1, -1, MOVE_TO_POS
);
20678 /* If we missed point because the character there is
20679 displayed out of a display vector that has more than one
20680 glyph, retry expecting overshoot. */
20681 if (it
.method
== GET_FROM_DISPLAY_VECTOR
20682 && it
.current
.dpvec_index
> 0
20683 && !overshoot_expected
)
20685 overshoot_expected
= true;
20688 else if (IT_CHARPOS (it
) != PT
&& !overshoot_expected
)
20689 move_it_in_display_line (&it
, PT
, -1, MOVE_TO_POS
);
20691 pt_x
= it
.current_x
;
20693 if (dir
> 0 || overshoot_expected
)
20695 struct glyph_row
*row
= it
.glyph_row
;
20697 /* When point is at beginning of line, we don't have
20698 information about the glyph there loaded into struct
20699 it. Calling get_next_display_element fixes that. */
20701 get_next_display_element (&it
);
20702 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20703 it
.glyph_row
= NULL
;
20704 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20705 it
.glyph_row
= row
;
20706 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20707 it, lest it will become out of sync with it's buffer
20709 it
.current_x
= pt_x
;
20712 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20713 pixel_width
= it
.pixel_width
;
20714 if (overshoot_expected
&& at_eol_p
)
20716 else if (pixel_width
<= 0)
20719 /* If there's a display string (or something similar) at point,
20720 we are actually at the glyph to the left of point, so we need
20721 to correct the X coordinate. */
20722 if (overshoot_expected
)
20725 pt_x
+= pixel_width
* it
.bidi_it
.scan_dir
;
20727 pt_x
+= pixel_width
;
20730 /* Compute target X coordinate, either to the left or to the
20731 right of point. On TTY frames, all characters have the same
20732 pixel width of 1, so we can use that. On GUI frames we don't
20733 have an easy way of getting at the pixel width of the
20734 character to the left of point, so we use a different method
20735 of getting to that place. */
20737 target_x
= pt_x
+ pixel_width
;
20739 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20741 /* Target X coordinate could be one line above or below the line
20742 of point, in which case we need to adjust the target X
20743 coordinate. Also, if moving to the left, we need to begin at
20744 the left edge of the point's screen line. */
20749 start_display (&it
, w
, pt
);
20750 reseat_at_previous_visible_line_start (&it
);
20751 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20753 move_it_by_lines (&it
, pt_vpos
);
20757 move_it_by_lines (&it
, -1);
20758 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20759 target_is_eol_p
= true;
20765 || (target_x
>= it
.last_visible_x
20766 && it
.line_wrap
!= TRUNCATE
))
20769 move_it_by_lines (&it
, 0);
20770 move_it_by_lines (&it
, 1);
20775 /* Move to the target X coordinate. */
20776 #ifdef HAVE_WINDOW_SYSTEM
20777 /* On GUI frames, as we don't know the X coordinate of the
20778 character to the left of point, moving point to the left
20779 requires walking, one grapheme cluster at a time, until we
20780 find ourself at a place immediately to the left of the
20781 character at point. */
20782 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20784 struct text_pos new_pos
;
20785 enum move_it_result rc
= MOVE_X_REACHED
;
20787 if (it
.current_x
== 0)
20788 get_next_display_element (&it
);
20789 if (it
.what
== IT_COMPOSITION
)
20791 new_pos
.charpos
= it
.cmp_it
.charpos
;
20792 new_pos
.bytepos
= -1;
20795 new_pos
= it
.current
.pos
;
20797 while (it
.current_x
+ it
.pixel_width
<= target_x
20798 && rc
== MOVE_X_REACHED
)
20800 int new_x
= it
.current_x
+ it
.pixel_width
;
20802 /* For composed characters, we want the position of the
20803 first character in the grapheme cluster (usually, the
20804 composition's base character), whereas it.current
20805 might give us the position of the _last_ one, e.g. if
20806 the composition is rendered in reverse due to bidi
20808 if (it
.what
== IT_COMPOSITION
)
20810 new_pos
.charpos
= it
.cmp_it
.charpos
;
20811 new_pos
.bytepos
= -1;
20814 new_pos
= it
.current
.pos
;
20815 if (new_x
== it
.current_x
)
20817 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20818 MOVE_TO_POS
| MOVE_TO_X
);
20819 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20822 /* The previous position we saw in the loop is the one we
20824 if (new_pos
.bytepos
== -1)
20825 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20826 it
.current
.pos
= new_pos
;
20830 if (it
.current_x
!= target_x
)
20831 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20833 /* When lines are truncated, the above loop will stop at the
20834 window edge. But we want to get to the end of line, even if
20835 it is beyond the window edge; automatic hscroll will then
20836 scroll the window to show point as appropriate. */
20837 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20838 && get_next_display_element (&it
))
20840 struct text_pos new_pos
= it
.current
.pos
;
20842 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20844 set_iterator_to_next (&it
, 0);
20845 if (it
.method
== GET_FROM_BUFFER
)
20846 new_pos
= it
.current
.pos
;
20847 if (!get_next_display_element (&it
))
20851 it
.current
.pos
= new_pos
;
20854 /* If we ended up in a display string that covers point, move to
20855 buffer position to the right in the visual order. */
20858 while (IT_CHARPOS (it
) == PT
)
20860 set_iterator_to_next (&it
, 0);
20861 if (!get_next_display_element (&it
))
20866 /* Move point to that position. */
20867 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20870 return make_number (PT
);
20872 #undef ROW_GLYPH_NEWLINE_P
20876 /***********************************************************************
20878 ***********************************************************************/
20880 /* Redisplay the menu bar in the frame for window W.
20882 The menu bar of X frames that don't have X toolkit support is
20883 displayed in a special window W->frame->menu_bar_window.
20885 The menu bar of terminal frames is treated specially as far as
20886 glyph matrices are concerned. Menu bar lines are not part of
20887 windows, so the update is done directly on the frame matrix rows
20888 for the menu bar. */
20891 display_menu_bar (struct window
*w
)
20893 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20898 /* Don't do all this for graphical frames. */
20900 if (FRAME_W32_P (f
))
20903 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20909 if (FRAME_NS_P (f
))
20911 #endif /* HAVE_NS */
20913 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20914 eassert (!FRAME_WINDOW_P (f
));
20915 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20916 it
.first_visible_x
= 0;
20917 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
20918 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20919 if (FRAME_WINDOW_P (f
))
20921 /* Menu bar lines are displayed in the desired matrix of the
20922 dummy window menu_bar_window. */
20923 struct window
*menu_w
;
20924 menu_w
= XWINDOW (f
->menu_bar_window
);
20925 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20927 it
.first_visible_x
= 0;
20928 it
.last_visible_x
= FRAME_PIXEL_WIDTH (f
);
20931 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20933 /* This is a TTY frame, i.e. character hpos/vpos are used as
20935 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20937 it
.first_visible_x
= 0;
20938 it
.last_visible_x
= FRAME_COLS (f
);
20941 /* FIXME: This should be controlled by a user option. See the
20942 comments in redisplay_tool_bar and display_mode_line about
20944 it
.paragraph_embedding
= L2R
;
20946 /* Clear all rows of the menu bar. */
20947 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20949 struct glyph_row
*row
= it
.glyph_row
+ i
;
20950 clear_glyph_row (row
);
20951 row
->enabled_p
= true;
20952 row
->full_width_p
= 1;
20955 /* Display all items of the menu bar. */
20956 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20957 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20959 Lisp_Object string
;
20961 /* Stop at nil string. */
20962 string
= AREF (items
, i
+ 1);
20966 /* Remember where item was displayed. */
20967 ASET (items
, i
+ 3, make_number (it
.hpos
));
20969 /* Display the item, pad with one space. */
20970 if (it
.current_x
< it
.last_visible_x
)
20971 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20972 SCHARS (string
) + 1, 0, 0, -1);
20975 /* Fill out the line with spaces. */
20976 if (it
.current_x
< it
.last_visible_x
)
20977 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20979 /* Compute the total height of the lines. */
20980 compute_line_metrics (&it
);
20983 /* Deep copy of a glyph row, including the glyphs. */
20985 deep_copy_glyph_row (struct glyph_row
*to
, struct glyph_row
*from
)
20987 struct glyph
*pointers
[1 + LAST_AREA
];
20988 int to_used
= to
->used
[TEXT_AREA
];
20990 /* Save glyph pointers of TO. */
20991 memcpy (pointers
, to
->glyphs
, sizeof to
->glyphs
);
20993 /* Do a structure assignment. */
20996 /* Restore original glyph pointers of TO. */
20997 memcpy (to
->glyphs
, pointers
, sizeof to
->glyphs
);
20999 /* Copy the glyphs. */
21000 memcpy (to
->glyphs
[TEXT_AREA
], from
->glyphs
[TEXT_AREA
],
21001 min (from
->used
[TEXT_AREA
], to_used
) * sizeof (struct glyph
));
21003 /* If we filled only part of the TO row, fill the rest with
21004 space_glyph (which will display as empty space). */
21005 if (to_used
> from
->used
[TEXT_AREA
])
21006 fill_up_frame_row_with_spaces (to
, to_used
);
21009 /* Display one menu item on a TTY, by overwriting the glyphs in the
21010 frame F's desired glyph matrix with glyphs produced from the menu
21011 item text. Called from term.c to display TTY drop-down menus one
21014 ITEM_TEXT is the menu item text as a C string.
21016 FACE_ID is the face ID to be used for this menu item. FACE_ID
21017 could specify one of 3 faces: a face for an enabled item, a face
21018 for a disabled item, or a face for a selected item.
21020 X and Y are coordinates of the first glyph in the frame's desired
21021 matrix to be overwritten by the menu item. Since this is a TTY, Y
21022 is the zero-based number of the glyph row and X is the zero-based
21023 glyph number in the row, starting from left, where to start
21024 displaying the item.
21026 SUBMENU non-zero means this menu item drops down a submenu, which
21027 should be indicated by displaying a proper visual cue after the
21031 display_tty_menu_item (const char *item_text
, int width
, int face_id
,
21032 int x
, int y
, int submenu
)
21035 struct frame
*f
= SELECTED_FRAME ();
21036 struct window
*w
= XWINDOW (f
->selected_window
);
21037 int saved_used
, saved_truncated
, saved_width
, saved_reversed
;
21038 struct glyph_row
*row
;
21039 size_t item_len
= strlen (item_text
);
21041 eassert (FRAME_TERMCAP_P (f
));
21043 /* Don't write beyond the matrix's last row. This can happen for
21044 TTY screens that are not high enough to show the entire menu.
21045 (This is actually a bit of defensive programming, as
21046 tty_menu_display already limits the number of menu items to one
21047 less than the number of screen lines.) */
21048 if (y
>= f
->desired_matrix
->nrows
)
21051 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
+ y
, MENU_FACE_ID
);
21052 it
.first_visible_x
= 0;
21053 it
.last_visible_x
= FRAME_COLS (f
) - 1;
21054 row
= it
.glyph_row
;
21055 /* Start with the row contents from the current matrix. */
21056 deep_copy_glyph_row (row
, f
->current_matrix
->rows
+ y
);
21057 saved_width
= row
->full_width_p
;
21058 row
->full_width_p
= 1;
21059 saved_reversed
= row
->reversed_p
;
21060 row
->reversed_p
= 0;
21061 row
->enabled_p
= true;
21063 /* Arrange for the menu item glyphs to start at (X,Y) and have the
21065 eassert (x
< f
->desired_matrix
->matrix_w
);
21066 it
.current_x
= it
.hpos
= x
;
21067 it
.current_y
= it
.vpos
= y
;
21068 saved_used
= row
->used
[TEXT_AREA
];
21069 saved_truncated
= row
->truncated_on_right_p
;
21070 row
->used
[TEXT_AREA
] = x
;
21071 it
.face_id
= face_id
;
21072 it
.line_wrap
= TRUNCATE
;
21074 /* FIXME: This should be controlled by a user option. See the
21075 comments in redisplay_tool_bar and display_mode_line about this.
21076 Also, if paragraph_embedding could ever be R2L, changes will be
21077 needed to avoid shifting to the right the row characters in
21078 term.c:append_glyph. */
21079 it
.paragraph_embedding
= L2R
;
21081 /* Pad with a space on the left. */
21082 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 1, 0, FRAME_COLS (f
) - 1, -1);
21084 /* Display the menu item, pad with spaces to WIDTH. */
21087 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21088 item_len
, 0, FRAME_COLS (f
) - 1, -1);
21090 /* Indicate with " >" that there's a submenu. */
21091 display_string (" >", Qnil
, Qnil
, 0, 0, &it
, width
, 0,
21092 FRAME_COLS (f
) - 1, -1);
21095 display_string (item_text
, Qnil
, Qnil
, 0, 0, &it
,
21096 width
, 0, FRAME_COLS (f
) - 1, -1);
21098 row
->used
[TEXT_AREA
] = max (saved_used
, row
->used
[TEXT_AREA
]);
21099 row
->truncated_on_right_p
= saved_truncated
;
21100 row
->hash
= row_hash (row
);
21101 row
->full_width_p
= saved_width
;
21102 row
->reversed_p
= saved_reversed
;
21105 /***********************************************************************
21107 ***********************************************************************/
21109 /* Redisplay mode lines in the window tree whose root is WINDOW. If
21110 FORCE is non-zero, redisplay mode lines unconditionally.
21111 Otherwise, redisplay only mode lines that are garbaged. Value is
21112 the number of windows whose mode lines were redisplayed. */
21115 redisplay_mode_lines (Lisp_Object window
, bool force
)
21119 while (!NILP (window
))
21121 struct window
*w
= XWINDOW (window
);
21123 if (WINDOWP (w
->contents
))
21124 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
21126 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
21127 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
21129 struct text_pos lpoint
;
21130 struct buffer
*old
= current_buffer
;
21132 /* Set the window's buffer for the mode line display. */
21133 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
21134 set_buffer_internal_1 (XBUFFER (w
->contents
));
21136 /* Point refers normally to the selected window. For any
21137 other window, set up appropriate value. */
21138 if (!EQ (window
, selected_window
))
21140 struct text_pos pt
;
21142 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
21143 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
21146 /* Display mode lines. */
21147 clear_glyph_matrix (w
->desired_matrix
);
21148 if (display_mode_lines (w
))
21151 /* Restore old settings. */
21152 set_buffer_internal_1 (old
);
21153 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
21163 /* Display the mode and/or header line of window W. Value is the
21164 sum number of mode lines and header lines displayed. */
21167 display_mode_lines (struct window
*w
)
21169 Lisp_Object old_selected_window
= selected_window
;
21170 Lisp_Object old_selected_frame
= selected_frame
;
21171 Lisp_Object new_frame
= w
->frame
;
21172 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
21175 selected_frame
= new_frame
;
21176 /* FIXME: If we were to allow the mode-line's computation changing the buffer
21177 or window's point, then we'd need select_window_1 here as well. */
21178 XSETWINDOW (selected_window
, w
);
21179 XFRAME (new_frame
)->selected_window
= selected_window
;
21181 /* These will be set while the mode line specs are processed. */
21182 line_number_displayed
= 0;
21183 w
->column_number_displayed
= -1;
21185 if (WINDOW_WANTS_MODELINE_P (w
))
21187 struct window
*sel_w
= XWINDOW (old_selected_window
);
21189 /* Select mode line face based on the real selected window. */
21190 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
21191 BVAR (current_buffer
, mode_line_format
));
21195 if (WINDOW_WANTS_HEADER_LINE_P (w
))
21197 display_mode_line (w
, HEADER_LINE_FACE_ID
,
21198 BVAR (current_buffer
, header_line_format
));
21202 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
21203 selected_frame
= old_selected_frame
;
21204 selected_window
= old_selected_window
;
21206 w
->must_be_updated_p
= true;
21211 /* Display mode or header line of window W. FACE_ID specifies which
21212 line to display; it is either MODE_LINE_FACE_ID or
21213 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
21214 display. Value is the pixel height of the mode/header line
21218 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
21222 ptrdiff_t count
= SPECPDL_INDEX ();
21224 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21225 /* Don't extend on a previously drawn mode-line.
21226 This may happen if called from pos_visible_p. */
21227 it
.glyph_row
->enabled_p
= false;
21228 prepare_desired_row (it
.glyph_row
);
21230 it
.glyph_row
->mode_line_p
= 1;
21232 /* FIXME: This should be controlled by a user option. But
21233 supporting such an option is not trivial, since the mode line is
21234 made up of many separate strings. */
21235 it
.paragraph_embedding
= L2R
;
21237 record_unwind_protect (unwind_format_mode_line
,
21238 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
21240 mode_line_target
= MODE_LINE_DISPLAY
;
21242 /* Temporarily make frame's keyboard the current kboard so that
21243 kboard-local variables in the mode_line_format will get the right
21245 push_kboard (FRAME_KBOARD (it
.f
));
21246 record_unwind_save_match_data ();
21247 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21250 unbind_to (count
, Qnil
);
21252 /* Fill up with spaces. */
21253 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
21255 compute_line_metrics (&it
);
21256 it
.glyph_row
->full_width_p
= 1;
21257 it
.glyph_row
->continued_p
= 0;
21258 it
.glyph_row
->truncated_on_left_p
= 0;
21259 it
.glyph_row
->truncated_on_right_p
= 0;
21261 /* Make a 3D mode-line have a shadow at its right end. */
21262 face
= FACE_FROM_ID (it
.f
, face_id
);
21263 extend_face_to_end_of_line (&it
);
21264 if (face
->box
!= FACE_NO_BOX
)
21266 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
21267 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
21268 last
->right_box_line_p
= 1;
21271 return it
.glyph_row
->height
;
21274 /* Move element ELT in LIST to the front of LIST.
21275 Return the updated list. */
21278 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
21280 register Lisp_Object tail
, prev
;
21281 register Lisp_Object tem
;
21285 while (CONSP (tail
))
21291 /* Splice out the link TAIL. */
21293 list
= XCDR (tail
);
21295 Fsetcdr (prev
, XCDR (tail
));
21297 /* Now make it the first. */
21298 Fsetcdr (tail
, list
);
21303 tail
= XCDR (tail
);
21307 /* Not found--return unchanged LIST. */
21311 /* Contribute ELT to the mode line for window IT->w. How it
21312 translates into text depends on its data type.
21314 IT describes the display environment in which we display, as usual.
21316 DEPTH is the depth in recursion. It is used to prevent
21317 infinite recursion here.
21319 FIELD_WIDTH is the number of characters the display of ELT should
21320 occupy in the mode line, and PRECISION is the maximum number of
21321 characters to display from ELT's representation. See
21322 display_string for details.
21324 Returns the hpos of the end of the text generated by ELT.
21326 PROPS is a property list to add to any string we encounter.
21328 If RISKY is nonzero, remove (disregard) any properties in any string
21329 we encounter, and ignore :eval and :propertize.
21331 The global variable `mode_line_target' determines whether the
21332 output is passed to `store_mode_line_noprop',
21333 `store_mode_line_string', or `display_string'. */
21336 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
21337 Lisp_Object elt
, Lisp_Object props
, int risky
)
21339 int n
= 0, field
, prec
;
21344 elt
= build_string ("*too-deep*");
21348 switch (XTYPE (elt
))
21352 /* A string: output it and check for %-constructs within it. */
21354 ptrdiff_t offset
= 0;
21356 if (SCHARS (elt
) > 0
21357 && (!NILP (props
) || risky
))
21359 Lisp_Object oprops
, aelt
;
21360 oprops
= Ftext_properties_at (make_number (0), elt
);
21362 /* If the starting string's properties are not what
21363 we want, translate the string. Also, if the string
21364 is risky, do that anyway. */
21366 if (NILP (Fequal (props
, oprops
)) || risky
)
21368 /* If the starting string has properties,
21369 merge the specified ones onto the existing ones. */
21370 if (! NILP (oprops
) && !risky
)
21374 oprops
= Fcopy_sequence (oprops
);
21376 while (CONSP (tem
))
21378 oprops
= Fplist_put (oprops
, XCAR (tem
),
21379 XCAR (XCDR (tem
)));
21380 tem
= XCDR (XCDR (tem
));
21385 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
21386 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
21388 /* AELT is what we want. Move it to the front
21389 without consing. */
21391 mode_line_proptrans_alist
21392 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
21398 /* If AELT has the wrong props, it is useless.
21399 so get rid of it. */
21401 mode_line_proptrans_alist
21402 = Fdelq (aelt
, mode_line_proptrans_alist
);
21404 elt
= Fcopy_sequence (elt
);
21405 Fset_text_properties (make_number (0), Flength (elt
),
21407 /* Add this item to mode_line_proptrans_alist. */
21408 mode_line_proptrans_alist
21409 = Fcons (Fcons (elt
, props
),
21410 mode_line_proptrans_alist
);
21411 /* Truncate mode_line_proptrans_alist
21412 to at most 50 elements. */
21413 tem
= Fnthcdr (make_number (50),
21414 mode_line_proptrans_alist
);
21416 XSETCDR (tem
, Qnil
);
21425 prec
= precision
- n
;
21426 switch (mode_line_target
)
21428 case MODE_LINE_NOPROP
:
21429 case MODE_LINE_TITLE
:
21430 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
21432 case MODE_LINE_STRING
:
21433 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
21435 case MODE_LINE_DISPLAY
:
21436 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
21437 0, prec
, 0, STRING_MULTIBYTE (elt
));
21444 /* Handle the non-literal case. */
21446 while ((precision
<= 0 || n
< precision
)
21447 && SREF (elt
, offset
) != 0
21448 && (mode_line_target
!= MODE_LINE_DISPLAY
21449 || it
->current_x
< it
->last_visible_x
))
21451 ptrdiff_t last_offset
= offset
;
21453 /* Advance to end of string or next format specifier. */
21454 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
21457 if (offset
- 1 != last_offset
)
21459 ptrdiff_t nchars
, nbytes
;
21461 /* Output to end of string or up to '%'. Field width
21462 is length of string. Don't output more than
21463 PRECISION allows us. */
21466 prec
= c_string_width (SDATA (elt
) + last_offset
,
21467 offset
- last_offset
, precision
- n
,
21470 switch (mode_line_target
)
21472 case MODE_LINE_NOPROP
:
21473 case MODE_LINE_TITLE
:
21474 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21476 case MODE_LINE_STRING
:
21478 ptrdiff_t bytepos
= last_offset
;
21479 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21480 ptrdiff_t endpos
= (precision
<= 0
21481 ? string_byte_to_char (elt
, offset
)
21482 : charpos
+ nchars
);
21484 n
+= store_mode_line_string (NULL
,
21485 Fsubstring (elt
, make_number (charpos
),
21486 make_number (endpos
)),
21490 case MODE_LINE_DISPLAY
:
21492 ptrdiff_t bytepos
= last_offset
;
21493 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21495 if (precision
<= 0)
21496 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21497 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21499 STRING_MULTIBYTE (elt
));
21504 else /* c == '%' */
21506 ptrdiff_t percent_position
= offset
;
21508 /* Get the specified minimum width. Zero means
21511 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21512 field
= field
* 10 + c
- '0';
21514 /* Don't pad beyond the total padding allowed. */
21515 if (field_width
- n
> 0 && field
> field_width
- n
)
21516 field
= field_width
- n
;
21518 /* Note that either PRECISION <= 0 or N < PRECISION. */
21519 prec
= precision
- n
;
21522 n
+= display_mode_element (it
, depth
, field
, prec
,
21523 Vglobal_mode_string
, props
,
21528 ptrdiff_t bytepos
, charpos
;
21530 Lisp_Object string
;
21532 bytepos
= percent_position
;
21533 charpos
= (STRING_MULTIBYTE (elt
)
21534 ? string_byte_to_char (elt
, bytepos
)
21536 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21537 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21539 switch (mode_line_target
)
21541 case MODE_LINE_NOPROP
:
21542 case MODE_LINE_TITLE
:
21543 n
+= store_mode_line_noprop (spec
, field
, prec
);
21545 case MODE_LINE_STRING
:
21547 Lisp_Object tem
= build_string (spec
);
21548 props
= Ftext_properties_at (make_number (charpos
), elt
);
21549 /* Should only keep face property in props */
21550 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21553 case MODE_LINE_DISPLAY
:
21555 int nglyphs_before
, nwritten
;
21557 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21558 nwritten
= display_string (spec
, string
, elt
,
21563 /* Assign to the glyphs written above the
21564 string where the `%x' came from, position
21568 struct glyph
*glyph
21569 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21573 for (i
= 0; i
< nwritten
; ++i
)
21575 glyph
[i
].object
= elt
;
21576 glyph
[i
].charpos
= charpos
;
21593 /* A symbol: process the value of the symbol recursively
21594 as if it appeared here directly. Avoid error if symbol void.
21595 Special case: if value of symbol is a string, output the string
21598 register Lisp_Object tem
;
21600 /* If the variable is not marked as risky to set
21601 then its contents are risky to use. */
21602 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21605 tem
= Fboundp (elt
);
21608 tem
= Fsymbol_value (elt
);
21609 /* If value is a string, output that string literally:
21610 don't check for % within it. */
21614 if (!EQ (tem
, elt
))
21616 /* Give up right away for nil or t. */
21626 register Lisp_Object car
, tem
;
21628 /* A cons cell: five distinct cases.
21629 If first element is :eval or :propertize, do something special.
21630 If first element is a string or a cons, process all the elements
21631 and effectively concatenate them.
21632 If first element is a negative number, truncate displaying cdr to
21633 at most that many characters. If positive, pad (with spaces)
21634 to at least that many characters.
21635 If first element is a symbol, process the cadr or caddr recursively
21636 according to whether the symbol's value is non-nil or nil. */
21638 if (EQ (car
, QCeval
))
21640 /* An element of the form (:eval FORM) means evaluate FORM
21641 and use the result as mode line elements. */
21646 if (CONSP (XCDR (elt
)))
21649 spec
= safe_eval (XCAR (XCDR (elt
)));
21650 n
+= display_mode_element (it
, depth
, field_width
- n
,
21651 precision
- n
, spec
, props
,
21655 else if (EQ (car
, QCpropertize
))
21657 /* An element of the form (:propertize ELT PROPS...)
21658 means display ELT but applying properties PROPS. */
21663 if (CONSP (XCDR (elt
)))
21664 n
+= display_mode_element (it
, depth
, field_width
- n
,
21665 precision
- n
, XCAR (XCDR (elt
)),
21666 XCDR (XCDR (elt
)), risky
);
21668 else if (SYMBOLP (car
))
21670 tem
= Fboundp (car
);
21674 /* elt is now the cdr, and we know it is a cons cell.
21675 Use its car if CAR has a non-nil value. */
21678 tem
= Fsymbol_value (car
);
21685 /* Symbol's value is nil (or symbol is unbound)
21686 Get the cddr of the original list
21687 and if possible find the caddr and use that. */
21691 else if (!CONSP (elt
))
21696 else if (INTEGERP (car
))
21698 register int lim
= XINT (car
);
21702 /* Negative int means reduce maximum width. */
21703 if (precision
<= 0)
21706 precision
= min (precision
, -lim
);
21710 /* Padding specified. Don't let it be more than
21711 current maximum. */
21713 lim
= min (precision
, lim
);
21715 /* If that's more padding than already wanted, queue it.
21716 But don't reduce padding already specified even if
21717 that is beyond the current truncation point. */
21718 field_width
= max (lim
, field_width
);
21722 else if (STRINGP (car
) || CONSP (car
))
21724 Lisp_Object halftail
= elt
;
21728 && (precision
<= 0 || n
< precision
))
21730 n
+= display_mode_element (it
, depth
,
21731 /* Do padding only after the last
21732 element in the list. */
21733 (! CONSP (XCDR (elt
))
21736 precision
- n
, XCAR (elt
),
21740 if ((len
& 1) == 0)
21741 halftail
= XCDR (halftail
);
21742 /* Check for cycle. */
21743 if (EQ (halftail
, elt
))
21752 elt
= build_string ("*invalid*");
21756 /* Pad to FIELD_WIDTH. */
21757 if (field_width
> 0 && n
< field_width
)
21759 switch (mode_line_target
)
21761 case MODE_LINE_NOPROP
:
21762 case MODE_LINE_TITLE
:
21763 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21765 case MODE_LINE_STRING
:
21766 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21768 case MODE_LINE_DISPLAY
:
21769 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21778 /* Store a mode-line string element in mode_line_string_list.
21780 If STRING is non-null, display that C string. Otherwise, the Lisp
21781 string LISP_STRING is displayed.
21783 FIELD_WIDTH is the minimum number of output glyphs to produce.
21784 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21785 with spaces. FIELD_WIDTH <= 0 means don't pad.
21787 PRECISION is the maximum number of characters to output from
21788 STRING. PRECISION <= 0 means don't truncate the string.
21790 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21791 properties to the string.
21793 PROPS are the properties to add to the string.
21794 The mode_line_string_face face property is always added to the string.
21798 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21799 int field_width
, int precision
, Lisp_Object props
)
21804 if (string
!= NULL
)
21806 len
= strlen (string
);
21807 if (precision
> 0 && len
> precision
)
21809 lisp_string
= make_string (string
, len
);
21811 props
= mode_line_string_face_prop
;
21812 else if (!NILP (mode_line_string_face
))
21814 Lisp_Object face
= Fplist_get (props
, Qface
);
21815 props
= Fcopy_sequence (props
);
21817 face
= mode_line_string_face
;
21819 face
= list2 (face
, mode_line_string_face
);
21820 props
= Fplist_put (props
, Qface
, face
);
21822 Fadd_text_properties (make_number (0), make_number (len
),
21823 props
, lisp_string
);
21827 len
= XFASTINT (Flength (lisp_string
));
21828 if (precision
> 0 && len
> precision
)
21831 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21834 if (!NILP (mode_line_string_face
))
21838 props
= Ftext_properties_at (make_number (0), lisp_string
);
21839 face
= Fplist_get (props
, Qface
);
21841 face
= mode_line_string_face
;
21843 face
= list2 (face
, mode_line_string_face
);
21844 props
= list2 (Qface
, face
);
21846 lisp_string
= Fcopy_sequence (lisp_string
);
21849 Fadd_text_properties (make_number (0), make_number (len
),
21850 props
, lisp_string
);
21855 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21859 if (field_width
> len
)
21861 field_width
-= len
;
21862 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21864 Fadd_text_properties (make_number (0), make_number (field_width
),
21865 props
, lisp_string
);
21866 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21874 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21876 doc
: /* Format a string out of a mode line format specification.
21877 First arg FORMAT specifies the mode line format (see `mode-line-format'
21878 for details) to use.
21880 By default, the format is evaluated for the currently selected window.
21882 Optional second arg FACE specifies the face property to put on all
21883 characters for which no face is specified. The value nil means the
21884 default face. The value t means whatever face the window's mode line
21885 currently uses (either `mode-line' or `mode-line-inactive',
21886 depending on whether the window is the selected window or not).
21887 An integer value means the value string has no text
21890 Optional third and fourth args WINDOW and BUFFER specify the window
21891 and buffer to use as the context for the formatting (defaults
21892 are the selected window and the WINDOW's buffer). */)
21893 (Lisp_Object format
, Lisp_Object face
,
21894 Lisp_Object window
, Lisp_Object buffer
)
21899 struct buffer
*old_buffer
= NULL
;
21901 int no_props
= INTEGERP (face
);
21902 ptrdiff_t count
= SPECPDL_INDEX ();
21904 int string_start
= 0;
21906 w
= decode_any_window (window
);
21907 XSETWINDOW (window
, w
);
21910 buffer
= w
->contents
;
21911 CHECK_BUFFER (buffer
);
21913 /* Make formatting the modeline a non-op when noninteractive, otherwise
21914 there will be problems later caused by a partially initialized frame. */
21915 if (NILP (format
) || noninteractive
)
21916 return empty_unibyte_string
;
21921 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21922 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21923 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21924 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21925 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21926 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21927 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21930 old_buffer
= current_buffer
;
21932 /* Save things including mode_line_proptrans_alist,
21933 and set that to nil so that we don't alter the outer value. */
21934 record_unwind_protect (unwind_format_mode_line
,
21935 format_mode_line_unwind_data
21936 (XFRAME (WINDOW_FRAME (w
)),
21937 old_buffer
, selected_window
, 1));
21938 mode_line_proptrans_alist
= Qnil
;
21940 Fselect_window (window
, Qt
);
21941 set_buffer_internal_1 (XBUFFER (buffer
));
21943 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21947 mode_line_target
= MODE_LINE_NOPROP
;
21948 mode_line_string_face_prop
= Qnil
;
21949 mode_line_string_list
= Qnil
;
21950 string_start
= MODE_LINE_NOPROP_LEN (0);
21954 mode_line_target
= MODE_LINE_STRING
;
21955 mode_line_string_list
= Qnil
;
21956 mode_line_string_face
= face
;
21957 mode_line_string_face_prop
21958 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21961 push_kboard (FRAME_KBOARD (it
.f
));
21962 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21967 len
= MODE_LINE_NOPROP_LEN (string_start
);
21968 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21972 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21973 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21974 empty_unibyte_string
);
21977 unbind_to (count
, Qnil
);
21981 /* Write a null-terminated, right justified decimal representation of
21982 the positive integer D to BUF using a minimal field width WIDTH. */
21985 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21987 register char *p
= buf
;
21995 *p
++ = d
% 10 + '0';
22000 for (width
-= (int) (p
- buf
); width
> 0; --width
)
22011 /* Write a null-terminated, right justified decimal and "human
22012 readable" representation of the nonnegative integer D to BUF using
22013 a minimal field width WIDTH. D should be smaller than 999.5e24. */
22015 static const char power_letter
[] =
22029 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
22031 /* We aim to represent the nonnegative integer D as
22032 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
22033 ptrdiff_t quotient
= d
;
22035 /* -1 means: do not use TENTHS. */
22039 /* Length of QUOTIENT.TENTHS as a string. */
22045 if (quotient
>= 1000)
22047 /* Scale to the appropriate EXPONENT. */
22050 remainder
= quotient
% 1000;
22054 while (quotient
>= 1000);
22056 /* Round to nearest and decide whether to use TENTHS or not. */
22059 tenths
= remainder
/ 100;
22060 if (remainder
% 100 >= 50)
22067 if (quotient
== 10)
22075 if (remainder
>= 500)
22077 if (quotient
< 999)
22088 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
22089 if (tenths
== -1 && quotient
<= 99)
22096 p
= psuffix
= buf
+ max (width
, length
);
22098 /* Print EXPONENT. */
22099 *psuffix
++ = power_letter
[exponent
];
22102 /* Print TENTHS. */
22105 *--p
= '0' + tenths
;
22109 /* Print QUOTIENT. */
22112 int digit
= quotient
% 10;
22113 *--p
= '0' + digit
;
22115 while ((quotient
/= 10) != 0);
22117 /* Print leading spaces. */
22122 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
22123 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
22124 type of CODING_SYSTEM. Return updated pointer into BUF. */
22126 static unsigned char invalid_eol_type
[] = "(*invalid*)";
22129 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
22132 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
22133 const unsigned char *eol_str
;
22135 /* The EOL conversion we are using. */
22136 Lisp_Object eoltype
;
22138 val
= CODING_SYSTEM_SPEC (coding_system
);
22141 if (!VECTORP (val
)) /* Not yet decided. */
22143 *buf
++ = multibyte
? '-' : ' ';
22145 eoltype
= eol_mnemonic_undecided
;
22146 /* Don't mention EOL conversion if it isn't decided. */
22151 Lisp_Object eolvalue
;
22153 attrs
= AREF (val
, 0);
22154 eolvalue
= AREF (val
, 2);
22157 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
22162 /* The EOL conversion that is normal on this system. */
22164 if (NILP (eolvalue
)) /* Not yet decided. */
22165 eoltype
= eol_mnemonic_undecided
;
22166 else if (VECTORP (eolvalue
)) /* Not yet decided. */
22167 eoltype
= eol_mnemonic_undecided
;
22168 else /* eolvalue is Qunix, Qdos, or Qmac. */
22169 eoltype
= (EQ (eolvalue
, Qunix
)
22170 ? eol_mnemonic_unix
22171 : (EQ (eolvalue
, Qdos
) == 1
22172 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
22178 /* Mention the EOL conversion if it is not the usual one. */
22179 if (STRINGP (eoltype
))
22181 eol_str
= SDATA (eoltype
);
22182 eol_str_len
= SBYTES (eoltype
);
22184 else if (CHARACTERP (eoltype
))
22186 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
22187 int c
= XFASTINT (eoltype
);
22188 eol_str_len
= CHAR_STRING (c
, tmp
);
22193 eol_str
= invalid_eol_type
;
22194 eol_str_len
= sizeof (invalid_eol_type
) - 1;
22196 memcpy (buf
, eol_str
, eol_str_len
);
22197 buf
+= eol_str_len
;
22203 /* Return a string for the output of a mode line %-spec for window W,
22204 generated by character C. FIELD_WIDTH > 0 means pad the string
22205 returned with spaces to that value. Return a Lisp string in
22206 *STRING if the resulting string is taken from that Lisp string.
22208 Note we operate on the current buffer for most purposes. */
22210 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
22212 static const char *
22213 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
22214 Lisp_Object
*string
)
22217 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
22218 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
22219 /* We are going to use f->decode_mode_spec_buffer as the buffer to
22220 produce strings from numerical values, so limit preposterously
22221 large values of FIELD_WIDTH to avoid overrunning the buffer's
22222 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
22223 bytes plus the terminating null. */
22224 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
22225 struct buffer
*b
= current_buffer
;
22233 if (!NILP (BVAR (b
, read_only
)))
22235 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22240 /* This differs from %* only for a modified read-only buffer. */
22241 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22243 if (!NILP (BVAR (b
, read_only
)))
22248 /* This differs from %* in ignoring read-only-ness. */
22249 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
22261 if (command_loop_level
> 5)
22263 p
= decode_mode_spec_buf
;
22264 for (i
= 0; i
< command_loop_level
; i
++)
22267 return decode_mode_spec_buf
;
22275 if (command_loop_level
> 5)
22277 p
= decode_mode_spec_buf
;
22278 for (i
= 0; i
< command_loop_level
; i
++)
22281 return decode_mode_spec_buf
;
22288 /* Let lots_of_dashes be a string of infinite length. */
22289 if (mode_line_target
== MODE_LINE_NOPROP
22290 || mode_line_target
== MODE_LINE_STRING
)
22292 if (field_width
<= 0
22293 || field_width
> sizeof (lots_of_dashes
))
22295 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
22296 decode_mode_spec_buf
[i
] = '-';
22297 decode_mode_spec_buf
[i
] = '\0';
22298 return decode_mode_spec_buf
;
22301 return lots_of_dashes
;
22305 obj
= BVAR (b
, name
);
22309 /* %c and %l are ignored in `frame-title-format'.
22310 (In redisplay_internal, the frame title is drawn _before_ the
22311 windows are updated, so the stuff which depends on actual
22312 window contents (such as %l) may fail to render properly, or
22313 even crash emacs.) */
22314 if (mode_line_target
== MODE_LINE_TITLE
)
22318 ptrdiff_t col
= current_column ();
22319 w
->column_number_displayed
= col
;
22320 pint2str (decode_mode_spec_buf
, width
, col
);
22321 return decode_mode_spec_buf
;
22325 #ifndef SYSTEM_MALLOC
22327 if (NILP (Vmemory_full
))
22330 return "!MEM FULL! ";
22337 /* %F displays the frame name. */
22338 if (!NILP (f
->title
))
22339 return SSDATA (f
->title
);
22340 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
22341 return SSDATA (f
->name
);
22345 obj
= BVAR (b
, filename
);
22350 ptrdiff_t size
= ZV
- BEGV
;
22351 pint2str (decode_mode_spec_buf
, width
, size
);
22352 return decode_mode_spec_buf
;
22357 ptrdiff_t size
= ZV
- BEGV
;
22358 pint2hrstr (decode_mode_spec_buf
, width
, size
);
22359 return decode_mode_spec_buf
;
22364 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
22365 ptrdiff_t topline
, nlines
, height
;
22368 /* %c and %l are ignored in `frame-title-format'. */
22369 if (mode_line_target
== MODE_LINE_TITLE
)
22372 startpos
= marker_position (w
->start
);
22373 startpos_byte
= marker_byte_position (w
->start
);
22374 height
= WINDOW_TOTAL_LINES (w
);
22376 /* If we decided that this buffer isn't suitable for line numbers,
22377 don't forget that too fast. */
22378 if (w
->base_line_pos
== -1)
22381 /* If the buffer is very big, don't waste time. */
22382 if (INTEGERP (Vline_number_display_limit
)
22383 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
22385 w
->base_line_pos
= 0;
22386 w
->base_line_number
= 0;
22390 if (w
->base_line_number
> 0
22391 && w
->base_line_pos
> 0
22392 && w
->base_line_pos
<= startpos
)
22394 line
= w
->base_line_number
;
22395 linepos
= w
->base_line_pos
;
22396 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
22401 linepos
= BUF_BEGV (b
);
22402 linepos_byte
= BUF_BEGV_BYTE (b
);
22405 /* Count lines from base line to window start position. */
22406 nlines
= display_count_lines (linepos_byte
,
22410 topline
= nlines
+ line
;
22412 /* Determine a new base line, if the old one is too close
22413 or too far away, or if we did not have one.
22414 "Too close" means it's plausible a scroll-down would
22415 go back past it. */
22416 if (startpos
== BUF_BEGV (b
))
22418 w
->base_line_number
= topline
;
22419 w
->base_line_pos
= BUF_BEGV (b
);
22421 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
22422 || linepos
== BUF_BEGV (b
))
22424 ptrdiff_t limit
= BUF_BEGV (b
);
22425 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
22426 ptrdiff_t position
;
22427 ptrdiff_t distance
=
22428 (height
* 2 + 30) * line_number_display_limit_width
;
22430 if (startpos
- distance
> limit
)
22432 limit
= startpos
- distance
;
22433 limit_byte
= CHAR_TO_BYTE (limit
);
22436 nlines
= display_count_lines (startpos_byte
,
22438 - (height
* 2 + 30),
22440 /* If we couldn't find the lines we wanted within
22441 line_number_display_limit_width chars per line,
22442 give up on line numbers for this window. */
22443 if (position
== limit_byte
&& limit
== startpos
- distance
)
22445 w
->base_line_pos
= -1;
22446 w
->base_line_number
= 0;
22450 w
->base_line_number
= topline
- nlines
;
22451 w
->base_line_pos
= BYTE_TO_CHAR (position
);
22454 /* Now count lines from the start pos to point. */
22455 nlines
= display_count_lines (startpos_byte
,
22456 PT_BYTE
, PT
, &junk
);
22458 /* Record that we did display the line number. */
22459 line_number_displayed
= 1;
22461 /* Make the string to show. */
22462 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
22463 return decode_mode_spec_buf
;
22466 char* p
= decode_mode_spec_buf
;
22467 int pad
= width
- 2;
22473 return decode_mode_spec_buf
;
22479 obj
= BVAR (b
, mode_name
);
22483 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22489 ptrdiff_t pos
= marker_position (w
->start
);
22490 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22492 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
22494 if (pos
<= BUF_BEGV (b
))
22499 else if (pos
<= BUF_BEGV (b
))
22503 if (total
> 1000000)
22504 /* Do it differently for a large value, to avoid overflow. */
22505 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22507 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22508 /* We can't normally display a 3-digit number,
22509 so get us a 2-digit number that is close. */
22512 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22513 return decode_mode_spec_buf
;
22517 /* Display percentage of size above the bottom of the screen. */
22520 ptrdiff_t toppos
= marker_position (w
->start
);
22521 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
22522 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22524 if (botpos
>= BUF_ZV (b
))
22526 if (toppos
<= BUF_BEGV (b
))
22533 if (total
> 1000000)
22534 /* Do it differently for a large value, to avoid overflow. */
22535 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22537 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22538 /* We can't normally display a 3-digit number,
22539 so get us a 2-digit number that is close. */
22542 if (toppos
<= BUF_BEGV (b
))
22543 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22545 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22546 return decode_mode_spec_buf
;
22551 /* status of process */
22552 obj
= Fget_buffer_process (Fcurrent_buffer ());
22554 return "no process";
22556 obj
= Fsymbol_name (Fprocess_status (obj
));
22562 ptrdiff_t count
= inhibit_garbage_collection ();
22563 Lisp_Object val
= call1 (intern ("file-remote-p"),
22564 BVAR (current_buffer
, directory
));
22565 unbind_to (count
, Qnil
);
22574 /* coding-system (not including end-of-line format) */
22576 /* coding-system (including end-of-line type) */
22578 int eol_flag
= (c
== 'Z');
22579 char *p
= decode_mode_spec_buf
;
22581 if (! FRAME_WINDOW_P (f
))
22583 /* No need to mention EOL here--the terminal never needs
22584 to do EOL conversion. */
22585 p
= decode_mode_spec_coding (CODING_ID_NAME
22586 (FRAME_KEYBOARD_CODING (f
)->id
),
22588 p
= decode_mode_spec_coding (CODING_ID_NAME
22589 (FRAME_TERMINAL_CODING (f
)->id
),
22592 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22595 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22596 #ifdef subprocesses
22597 obj
= Fget_buffer_process (Fcurrent_buffer ());
22598 if (PROCESSP (obj
))
22600 p
= decode_mode_spec_coding
22601 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22602 p
= decode_mode_spec_coding
22603 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22605 #endif /* subprocesses */
22608 return decode_mode_spec_buf
;
22615 return SSDATA (obj
);
22622 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22623 means count lines back from START_BYTE. But don't go beyond
22624 LIMIT_BYTE. Return the number of lines thus found (always
22627 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22628 either the position COUNT lines after/before START_BYTE, if we
22629 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22633 display_count_lines (ptrdiff_t start_byte
,
22634 ptrdiff_t limit_byte
, ptrdiff_t count
,
22635 ptrdiff_t *byte_pos_ptr
)
22637 register unsigned char *cursor
;
22638 unsigned char *base
;
22640 register ptrdiff_t ceiling
;
22641 register unsigned char *ceiling_addr
;
22642 ptrdiff_t orig_count
= count
;
22644 /* If we are not in selective display mode,
22645 check only for newlines. */
22646 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22647 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22651 while (start_byte
< limit_byte
)
22653 ceiling
= BUFFER_CEILING_OF (start_byte
);
22654 ceiling
= min (limit_byte
- 1, ceiling
);
22655 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22656 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22660 if (selective_display
)
22662 while (*cursor
!= '\n' && *cursor
!= 015
22663 && ++cursor
!= ceiling_addr
)
22665 if (cursor
== ceiling_addr
)
22670 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22679 start_byte
+= cursor
- base
;
22680 *byte_pos_ptr
= start_byte
;
22684 while (cursor
< ceiling_addr
);
22686 start_byte
+= ceiling_addr
- base
;
22691 while (start_byte
> limit_byte
)
22693 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22694 ceiling
= max (limit_byte
, ceiling
);
22695 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22696 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22699 if (selective_display
)
22701 while (--cursor
>= ceiling_addr
22702 && *cursor
!= '\n' && *cursor
!= 015)
22704 if (cursor
< ceiling_addr
)
22709 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22716 start_byte
+= cursor
- base
+ 1;
22717 *byte_pos_ptr
= start_byte
;
22718 /* When scanning backwards, we should
22719 not count the newline posterior to which we stop. */
22720 return - orig_count
- 1;
22723 start_byte
+= ceiling_addr
- base
;
22727 *byte_pos_ptr
= limit_byte
;
22730 return - orig_count
+ count
;
22731 return orig_count
- count
;
22737 /***********************************************************************
22739 ***********************************************************************/
22741 /* Display a NUL-terminated string, starting with index START.
22743 If STRING is non-null, display that C string. Otherwise, the Lisp
22744 string LISP_STRING is displayed. There's a case that STRING is
22745 non-null and LISP_STRING is not nil. It means STRING is a string
22746 data of LISP_STRING. In that case, we display LISP_STRING while
22747 ignoring its text properties.
22749 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22750 FACE_STRING. Display STRING or LISP_STRING with the face at
22751 FACE_STRING_POS in FACE_STRING:
22753 Display the string in the environment given by IT, but use the
22754 standard display table, temporarily.
22756 FIELD_WIDTH is the minimum number of output glyphs to produce.
22757 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22758 with spaces. If STRING has more characters, more than FIELD_WIDTH
22759 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22761 PRECISION is the maximum number of characters to output from
22762 STRING. PRECISION < 0 means don't truncate the string.
22764 This is roughly equivalent to printf format specifiers:
22766 FIELD_WIDTH PRECISION PRINTF
22767 ----------------------------------------
22773 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22774 display them, and < 0 means obey the current buffer's value of
22775 enable_multibyte_characters.
22777 Value is the number of columns displayed. */
22780 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22781 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22782 int field_width
, int precision
, int max_x
, int multibyte
)
22784 int hpos_at_start
= it
->hpos
;
22785 int saved_face_id
= it
->face_id
;
22786 struct glyph_row
*row
= it
->glyph_row
;
22787 ptrdiff_t it_charpos
;
22789 /* Initialize the iterator IT for iteration over STRING beginning
22790 with index START. */
22791 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22792 precision
, field_width
, multibyte
);
22793 if (string
&& STRINGP (lisp_string
))
22794 /* LISP_STRING is the one returned by decode_mode_spec. We should
22795 ignore its text properties. */
22796 it
->stop_charpos
= it
->end_charpos
;
22798 /* If displaying STRING, set up the face of the iterator from
22799 FACE_STRING, if that's given. */
22800 if (STRINGP (face_string
))
22806 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22807 0, &endptr
, it
->base_face_id
, 0);
22808 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22809 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22812 /* Set max_x to the maximum allowed X position. Don't let it go
22813 beyond the right edge of the window. */
22815 max_x
= it
->last_visible_x
;
22817 max_x
= min (max_x
, it
->last_visible_x
);
22819 /* Skip over display elements that are not visible. because IT->w is
22821 if (it
->current_x
< it
->first_visible_x
)
22822 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22823 MOVE_TO_POS
| MOVE_TO_X
);
22825 row
->ascent
= it
->max_ascent
;
22826 row
->height
= it
->max_ascent
+ it
->max_descent
;
22827 row
->phys_ascent
= it
->max_phys_ascent
;
22828 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22829 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22831 if (STRINGP (it
->string
))
22832 it_charpos
= IT_STRING_CHARPOS (*it
);
22834 it_charpos
= IT_CHARPOS (*it
);
22836 /* This condition is for the case that we are called with current_x
22837 past last_visible_x. */
22838 while (it
->current_x
< max_x
)
22840 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22842 /* Get the next display element. */
22843 if (!get_next_display_element (it
))
22846 /* Produce glyphs. */
22847 x_before
= it
->current_x
;
22848 n_glyphs_before
= row
->used
[TEXT_AREA
];
22849 PRODUCE_GLYPHS (it
);
22851 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22854 while (i
< nglyphs
)
22856 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22858 if (it
->line_wrap
!= TRUNCATE
22859 && x
+ glyph
->pixel_width
> max_x
)
22861 /* End of continued line or max_x reached. */
22862 if (CHAR_GLYPH_PADDING_P (*glyph
))
22864 /* A wide character is unbreakable. */
22865 if (row
->reversed_p
)
22866 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22867 - n_glyphs_before
);
22868 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22869 it
->current_x
= x_before
;
22873 if (row
->reversed_p
)
22874 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22875 - (n_glyphs_before
+ i
));
22876 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22881 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22883 /* Glyph is at least partially visible. */
22885 if (x
< it
->first_visible_x
)
22886 row
->x
= x
- it
->first_visible_x
;
22890 /* Glyph is off the left margin of the display area.
22891 Should not happen. */
22895 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22896 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22897 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22898 row
->phys_height
= max (row
->phys_height
,
22899 it
->max_phys_ascent
+ it
->max_phys_descent
);
22900 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22901 it
->max_extra_line_spacing
);
22902 x
+= glyph
->pixel_width
;
22906 /* Stop if max_x reached. */
22910 /* Stop at line ends. */
22911 if (ITERATOR_AT_END_OF_LINE_P (it
))
22913 it
->continuation_lines_width
= 0;
22917 set_iterator_to_next (it
, 1);
22918 if (STRINGP (it
->string
))
22919 it_charpos
= IT_STRING_CHARPOS (*it
);
22921 it_charpos
= IT_CHARPOS (*it
);
22923 /* Stop if truncating at the right edge. */
22924 if (it
->line_wrap
== TRUNCATE
22925 && it
->current_x
>= it
->last_visible_x
)
22927 /* Add truncation mark, but don't do it if the line is
22928 truncated at a padding space. */
22929 if (it_charpos
< it
->string_nchars
)
22931 if (!FRAME_WINDOW_P (it
->f
))
22935 if (it
->current_x
> it
->last_visible_x
)
22937 if (!row
->reversed_p
)
22939 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22940 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22945 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22946 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22948 unproduce_glyphs (it
, ii
+ 1);
22949 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22951 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22953 row
->used
[TEXT_AREA
] = ii
;
22954 produce_special_glyphs (it
, IT_TRUNCATION
);
22957 produce_special_glyphs (it
, IT_TRUNCATION
);
22959 row
->truncated_on_right_p
= 1;
22965 /* Maybe insert a truncation at the left. */
22966 if (it
->first_visible_x
22969 if (!FRAME_WINDOW_P (it
->f
)
22970 || (row
->reversed_p
22971 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22972 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22973 insert_left_trunc_glyphs (it
);
22974 row
->truncated_on_left_p
= 1;
22977 it
->face_id
= saved_face_id
;
22979 /* Value is number of columns displayed. */
22980 return it
->hpos
- hpos_at_start
;
22985 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22986 appears as an element of LIST or as the car of an element of LIST.
22987 If PROPVAL is a list, compare each element against LIST in that
22988 way, and return 1/2 if any element of PROPVAL is found in LIST.
22989 Otherwise return 0. This function cannot quit.
22990 The return value is 2 if the text is invisible but with an ellipsis
22991 and 1 if it's invisible and without an ellipsis. */
22994 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22996 register Lisp_Object tail
, proptail
;
22998 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
23000 register Lisp_Object tem
;
23002 if (EQ (propval
, tem
))
23004 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
23005 return NILP (XCDR (tem
)) ? 1 : 2;
23008 if (CONSP (propval
))
23010 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
23012 Lisp_Object propelt
;
23013 propelt
= XCAR (proptail
);
23014 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
23016 register Lisp_Object tem
;
23018 if (EQ (propelt
, tem
))
23020 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
23021 return NILP (XCDR (tem
)) ? 1 : 2;
23029 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
23030 doc
: /* Non-nil if the property makes the text invisible.
23031 POS-OR-PROP can be a marker or number, in which case it is taken to be
23032 a position in the current buffer and the value of the `invisible' property
23033 is checked; or it can be some other value, which is then presumed to be the
23034 value of the `invisible' property of the text of interest.
23035 The non-nil value returned can be t for truly invisible text or something
23036 else if the text is replaced by an ellipsis. */)
23037 (Lisp_Object pos_or_prop
)
23040 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
23041 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
23043 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
23044 return (invis
== 0 ? Qnil
23046 : make_number (invis
));
23049 /* Calculate a width or height in pixels from a specification using
23050 the following elements:
23053 NUM - a (fractional) multiple of the default font width/height
23054 (NUM) - specifies exactly NUM pixels
23055 UNIT - a fixed number of pixels, see below.
23056 ELEMENT - size of a display element in pixels, see below.
23057 (NUM . SPEC) - equals NUM * SPEC
23058 (+ SPEC SPEC ...) - add pixel values
23059 (- SPEC SPEC ...) - subtract pixel values
23060 (- SPEC) - negate pixel value
23063 INT or FLOAT - a number constant
23064 SYMBOL - use symbol's (buffer local) variable binding.
23067 in - pixels per inch *)
23068 mm - pixels per 1/1000 meter *)
23069 cm - pixels per 1/100 meter *)
23070 width - width of current font in pixels.
23071 height - height of current font in pixels.
23073 *) using the ratio(s) defined in display-pixels-per-inch.
23077 left-fringe - left fringe width in pixels
23078 right-fringe - right fringe width in pixels
23080 left-margin - left margin width in pixels
23081 right-margin - right margin width in pixels
23083 scroll-bar - scroll-bar area width in pixels
23087 Pixels corresponding to 5 inches:
23090 Total width of non-text areas on left side of window (if scroll-bar is on left):
23091 '(space :width (+ left-fringe left-margin scroll-bar))
23093 Align to first text column (in header line):
23094 '(space :align-to 0)
23096 Align to middle of text area minus half the width of variable `my-image'
23097 containing a loaded image:
23098 '(space :align-to (0.5 . (- text my-image)))
23100 Width of left margin minus width of 1 character in the default font:
23101 '(space :width (- left-margin 1))
23103 Width of left margin minus width of 2 characters in the current font:
23104 '(space :width (- left-margin (2 . width)))
23106 Center 1 character over left-margin (in header line):
23107 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
23109 Different ways to express width of left fringe plus left margin minus one pixel:
23110 '(space :width (- (+ left-fringe left-margin) (1)))
23111 '(space :width (+ left-fringe left-margin (- (1))))
23112 '(space :width (+ left-fringe left-margin (-1)))
23117 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
23118 struct font
*font
, int width_p
, int *align_to
)
23122 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
23123 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
23126 return OK_PIXELS (0);
23128 eassert (FRAME_LIVE_P (it
->f
));
23130 if (SYMBOLP (prop
))
23132 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
23134 char *unit
= SSDATA (SYMBOL_NAME (prop
));
23136 if (unit
[0] == 'i' && unit
[1] == 'n')
23138 else if (unit
[0] == 'm' && unit
[1] == 'm')
23140 else if (unit
[0] == 'c' && unit
[1] == 'm')
23146 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
23147 : FRAME_RES_Y (it
->f
));
23150 return OK_PIXELS (ppi
/ pixels
);
23155 #ifdef HAVE_WINDOW_SYSTEM
23156 if (EQ (prop
, Qheight
))
23157 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
23158 if (EQ (prop
, Qwidth
))
23159 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
23161 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
23162 return OK_PIXELS (1);
23165 if (EQ (prop
, Qtext
))
23166 return OK_PIXELS (width_p
23167 ? window_box_width (it
->w
, TEXT_AREA
)
23168 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
23170 if (align_to
&& *align_to
< 0)
23173 if (EQ (prop
, Qleft
))
23174 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
23175 if (EQ (prop
, Qright
))
23176 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
23177 if (EQ (prop
, Qcenter
))
23178 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
23179 + window_box_width (it
->w
, TEXT_AREA
) / 2);
23180 if (EQ (prop
, Qleft_fringe
))
23181 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23182 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
23183 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
23184 if (EQ (prop
, Qright_fringe
))
23185 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23186 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23187 : window_box_right_offset (it
->w
, TEXT_AREA
));
23188 if (EQ (prop
, Qleft_margin
))
23189 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
23190 if (EQ (prop
, Qright_margin
))
23191 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
23192 if (EQ (prop
, Qscroll_bar
))
23193 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
23195 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
23196 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
23197 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
23202 if (EQ (prop
, Qleft_fringe
))
23203 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
23204 if (EQ (prop
, Qright_fringe
))
23205 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
23206 if (EQ (prop
, Qleft_margin
))
23207 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
23208 if (EQ (prop
, Qright_margin
))
23209 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
23210 if (EQ (prop
, Qscroll_bar
))
23211 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
23214 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
23215 if (EQ (prop
, Qunbound
))
23219 if (INTEGERP (prop
) || FLOATP (prop
))
23221 int base_unit
= (width_p
23222 ? FRAME_COLUMN_WIDTH (it
->f
)
23223 : FRAME_LINE_HEIGHT (it
->f
));
23224 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
23229 Lisp_Object car
= XCAR (prop
);
23230 Lisp_Object cdr
= XCDR (prop
);
23234 #ifdef HAVE_WINDOW_SYSTEM
23235 if (FRAME_WINDOW_P (it
->f
)
23236 && valid_image_p (prop
))
23238 ptrdiff_t id
= lookup_image (it
->f
, prop
);
23239 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
23241 return OK_PIXELS (width_p
? img
->width
: img
->height
);
23244 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
23250 while (CONSP (cdr
))
23252 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
23253 font
, width_p
, align_to
))
23256 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
23261 if (EQ (car
, Qminus
))
23263 return OK_PIXELS (pixels
);
23266 car
= buffer_local_value_1 (car
, it
->w
->contents
);
23267 if (EQ (car
, Qunbound
))
23271 if (INTEGERP (car
) || FLOATP (car
))
23274 pixels
= XFLOATINT (car
);
23276 return OK_PIXELS (pixels
);
23277 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
23278 font
, width_p
, align_to
))
23279 return OK_PIXELS (pixels
* fact
);
23290 /***********************************************************************
23292 ***********************************************************************/
23294 #ifdef HAVE_WINDOW_SYSTEM
23299 dump_glyph_string (struct glyph_string
*s
)
23301 fprintf (stderr
, "glyph string\n");
23302 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
23303 s
->x
, s
->y
, s
->width
, s
->height
);
23304 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
23305 fprintf (stderr
, " hl = %d\n", s
->hl
);
23306 fprintf (stderr
, " left overhang = %d, right = %d\n",
23307 s
->left_overhang
, s
->right_overhang
);
23308 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
23309 fprintf (stderr
, " extends to end of line = %d\n",
23310 s
->extends_to_end_of_line_p
);
23311 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
23312 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
23315 #endif /* GLYPH_DEBUG */
23317 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
23318 of XChar2b structures for S; it can't be allocated in
23319 init_glyph_string because it must be allocated via `alloca'. W
23320 is the window on which S is drawn. ROW and AREA are the glyph row
23321 and area within the row from which S is constructed. START is the
23322 index of the first glyph structure covered by S. HL is a
23323 face-override for drawing S. */
23326 #define OPTIONAL_HDC(hdc) HDC hdc,
23327 #define DECLARE_HDC(hdc) HDC hdc;
23328 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
23329 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
23332 #ifndef OPTIONAL_HDC
23333 #define OPTIONAL_HDC(hdc)
23334 #define DECLARE_HDC(hdc)
23335 #define ALLOCATE_HDC(hdc, f)
23336 #define RELEASE_HDC(hdc, f)
23340 init_glyph_string (struct glyph_string
*s
,
23342 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
23343 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
23345 memset (s
, 0, sizeof *s
);
23347 s
->f
= XFRAME (w
->frame
);
23351 s
->display
= FRAME_X_DISPLAY (s
->f
);
23352 s
->window
= FRAME_X_WINDOW (s
->f
);
23353 s
->char2b
= char2b
;
23357 s
->first_glyph
= row
->glyphs
[area
] + start
;
23358 s
->height
= row
->height
;
23359 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
23360 s
->ybase
= s
->y
+ row
->ascent
;
23364 /* Append the list of glyph strings with head H and tail T to the list
23365 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
23368 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23369 struct glyph_string
*h
, struct glyph_string
*t
)
23383 /* Prepend the list of glyph strings with head H and tail T to the
23384 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
23388 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
23389 struct glyph_string
*h
, struct glyph_string
*t
)
23403 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
23404 Set *HEAD and *TAIL to the resulting list. */
23407 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
23408 struct glyph_string
*s
)
23410 s
->next
= s
->prev
= NULL
;
23411 append_glyph_string_lists (head
, tail
, s
, s
);
23415 /* Get face and two-byte form of character C in face FACE_ID on frame F.
23416 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
23417 make sure that X resources for the face returned are allocated.
23418 Value is a pointer to a realized face that is ready for display if
23419 DISPLAY_P is non-zero. */
23421 static struct face
*
23422 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
23423 XChar2b
*char2b
, int display_p
)
23425 struct face
*face
= FACE_FROM_ID (f
, face_id
);
23430 code
= face
->font
->driver
->encode_char (face
->font
, c
);
23432 if (code
== FONT_INVALID_CODE
)
23435 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23437 /* Make sure X resources of the face are allocated. */
23438 #ifdef HAVE_X_WINDOWS
23442 eassert (face
!= NULL
);
23443 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23450 /* Get face and two-byte form of character glyph GLYPH on frame F.
23451 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
23452 a pointer to a realized face that is ready for display. */
23454 static struct face
*
23455 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
23456 XChar2b
*char2b
, int *two_byte_p
)
23461 eassert (glyph
->type
== CHAR_GLYPH
);
23462 face
= FACE_FROM_ID (f
, glyph
->face_id
);
23464 /* Make sure X resources of the face are allocated. */
23465 eassert (face
!= NULL
);
23466 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23473 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23474 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23476 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23478 if (code
== FONT_INVALID_CODE
)
23482 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23487 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23488 Return 1 if FONT has a glyph for C, otherwise return 0. */
23491 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23495 if (CHAR_BYTE8_P (c
))
23496 code
= CHAR_TO_BYTE8 (c
);
23498 code
= font
->driver
->encode_char (font
, c
);
23500 if (code
== FONT_INVALID_CODE
)
23502 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23507 /* Fill glyph string S with composition components specified by S->cmp.
23509 BASE_FACE is the base face of the composition.
23510 S->cmp_from is the index of the first component for S.
23512 OVERLAPS non-zero means S should draw the foreground only, and use
23513 its physical height for clipping. See also draw_glyphs.
23515 Value is the index of a component not in S. */
23518 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23522 /* For all glyphs of this composition, starting at the offset
23523 S->cmp_from, until we reach the end of the definition or encounter a
23524 glyph that requires the different face, add it to S. */
23529 s
->for_overlaps
= overlaps
;
23532 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23534 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23536 /* TAB in a composition means display glyphs with padding space
23537 on the left or right. */
23540 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23543 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23550 s
->font
= s
->face
->font
;
23552 else if (s
->face
!= face
)
23560 if (s
->face
== NULL
)
23562 s
->face
= base_face
->ascii_face
;
23563 s
->font
= s
->face
->font
;
23566 /* All glyph strings for the same composition has the same width,
23567 i.e. the width set for the first component of the composition. */
23568 s
->width
= s
->first_glyph
->pixel_width
;
23570 /* If the specified font could not be loaded, use the frame's
23571 default font, but record the fact that we couldn't load it in
23572 the glyph string so that we can draw rectangles for the
23573 characters of the glyph string. */
23574 if (s
->font
== NULL
)
23576 s
->font_not_found_p
= 1;
23577 s
->font
= FRAME_FONT (s
->f
);
23580 /* Adjust base line for subscript/superscript text. */
23581 s
->ybase
+= s
->first_glyph
->voffset
;
23583 /* This glyph string must always be drawn with 16-bit functions. */
23590 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23591 int start
, int end
, int overlaps
)
23593 struct glyph
*glyph
, *last
;
23594 Lisp_Object lgstring
;
23597 s
->for_overlaps
= overlaps
;
23598 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23599 last
= s
->row
->glyphs
[s
->area
] + end
;
23600 s
->cmp_id
= glyph
->u
.cmp
.id
;
23601 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23602 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23603 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23604 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23605 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23607 while (glyph
< last
23608 && glyph
->u
.cmp
.automatic
23609 && glyph
->u
.cmp
.id
== s
->cmp_id
23610 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23611 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23613 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23615 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23616 unsigned code
= LGLYPH_CODE (lglyph
);
23618 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23620 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23621 return glyph
- s
->row
->glyphs
[s
->area
];
23625 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23626 See the comment of fill_glyph_string for arguments.
23627 Value is the index of the first glyph not in S. */
23631 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23632 int start
, int end
, int overlaps
)
23634 struct glyph
*glyph
, *last
;
23637 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23638 s
->for_overlaps
= overlaps
;
23639 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23640 last
= s
->row
->glyphs
[s
->area
] + end
;
23641 voffset
= glyph
->voffset
;
23642 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23643 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23645 s
->width
= glyph
->pixel_width
;
23647 while (glyph
< last
23648 && glyph
->type
== GLYPHLESS_GLYPH
23649 && glyph
->voffset
== voffset
23650 && glyph
->face_id
== face_id
)
23653 s
->width
+= glyph
->pixel_width
;
23656 s
->ybase
+= voffset
;
23657 return glyph
- s
->row
->glyphs
[s
->area
];
23661 /* Fill glyph string S from a sequence of character glyphs.
23663 FACE_ID is the face id of the string. START is the index of the
23664 first glyph to consider, END is the index of the last + 1.
23665 OVERLAPS non-zero means S should draw the foreground only, and use
23666 its physical height for clipping. See also draw_glyphs.
23668 Value is the index of the first glyph not in S. */
23671 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23672 int start
, int end
, int overlaps
)
23674 struct glyph
*glyph
, *last
;
23676 int glyph_not_available_p
;
23678 eassert (s
->f
== XFRAME (s
->w
->frame
));
23679 eassert (s
->nchars
== 0);
23680 eassert (start
>= 0 && end
> start
);
23682 s
->for_overlaps
= overlaps
;
23683 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23684 last
= s
->row
->glyphs
[s
->area
] + end
;
23685 voffset
= glyph
->voffset
;
23686 s
->padding_p
= glyph
->padding_p
;
23687 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23689 while (glyph
< last
23690 && glyph
->type
== CHAR_GLYPH
23691 && glyph
->voffset
== voffset
23692 /* Same face id implies same font, nowadays. */
23693 && glyph
->face_id
== face_id
23694 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23698 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23699 s
->char2b
+ s
->nchars
,
23701 s
->two_byte_p
= two_byte_p
;
23703 eassert (s
->nchars
<= end
- start
);
23704 s
->width
+= glyph
->pixel_width
;
23705 if (glyph
++->padding_p
!= s
->padding_p
)
23709 s
->font
= s
->face
->font
;
23711 /* If the specified font could not be loaded, use the frame's font,
23712 but record the fact that we couldn't load it in
23713 S->font_not_found_p so that we can draw rectangles for the
23714 characters of the glyph string. */
23715 if (s
->font
== NULL
|| glyph_not_available_p
)
23717 s
->font_not_found_p
= 1;
23718 s
->font
= FRAME_FONT (s
->f
);
23721 /* Adjust base line for subscript/superscript text. */
23722 s
->ybase
+= voffset
;
23724 eassert (s
->face
&& s
->face
->gc
);
23725 return glyph
- s
->row
->glyphs
[s
->area
];
23729 /* Fill glyph string S from image glyph S->first_glyph. */
23732 fill_image_glyph_string (struct glyph_string
*s
)
23734 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23735 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23737 s
->slice
= s
->first_glyph
->slice
.img
;
23738 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23739 s
->font
= s
->face
->font
;
23740 s
->width
= s
->first_glyph
->pixel_width
;
23742 /* Adjust base line for subscript/superscript text. */
23743 s
->ybase
+= s
->first_glyph
->voffset
;
23747 /* Fill glyph string S from a sequence of stretch glyphs.
23749 START is the index of the first glyph to consider,
23750 END is the index of the last + 1.
23752 Value is the index of the first glyph not in S. */
23755 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23757 struct glyph
*glyph
, *last
;
23758 int voffset
, face_id
;
23760 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23762 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23763 last
= s
->row
->glyphs
[s
->area
] + end
;
23764 face_id
= glyph
->face_id
;
23765 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23766 s
->font
= s
->face
->font
;
23767 s
->width
= glyph
->pixel_width
;
23769 voffset
= glyph
->voffset
;
23773 && glyph
->type
== STRETCH_GLYPH
23774 && glyph
->voffset
== voffset
23775 && glyph
->face_id
== face_id
);
23777 s
->width
+= glyph
->pixel_width
;
23779 /* Adjust base line for subscript/superscript text. */
23780 s
->ybase
+= voffset
;
23782 /* The case that face->gc == 0 is handled when drawing the glyph
23783 string by calling PREPARE_FACE_FOR_DISPLAY. */
23785 return glyph
- s
->row
->glyphs
[s
->area
];
23788 static struct font_metrics
*
23789 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23791 static struct font_metrics metrics
;
23796 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23797 if (code
== FONT_INVALID_CODE
)
23799 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23804 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23805 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23806 assumed to be zero. */
23809 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23811 *left
= *right
= 0;
23813 if (glyph
->type
== CHAR_GLYPH
)
23817 struct font_metrics
*pcm
;
23819 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23820 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23822 if (pcm
->rbearing
> pcm
->width
)
23823 *right
= pcm
->rbearing
- pcm
->width
;
23824 if (pcm
->lbearing
< 0)
23825 *left
= -pcm
->lbearing
;
23828 else if (glyph
->type
== COMPOSITE_GLYPH
)
23830 if (! glyph
->u
.cmp
.automatic
)
23832 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23834 if (cmp
->rbearing
> cmp
->pixel_width
)
23835 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23836 if (cmp
->lbearing
< 0)
23837 *left
= - cmp
->lbearing
;
23841 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23842 struct font_metrics metrics
;
23844 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23845 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23846 if (metrics
.rbearing
> metrics
.width
)
23847 *right
= metrics
.rbearing
- metrics
.width
;
23848 if (metrics
.lbearing
< 0)
23849 *left
= - metrics
.lbearing
;
23855 /* Return the index of the first glyph preceding glyph string S that
23856 is overwritten by S because of S's left overhang. Value is -1
23857 if no glyphs are overwritten. */
23860 left_overwritten (struct glyph_string
*s
)
23864 if (s
->left_overhang
)
23867 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23868 int first
= s
->first_glyph
- glyphs
;
23870 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23871 x
-= glyphs
[i
].pixel_width
;
23882 /* Return the index of the first glyph preceding glyph string S that
23883 is overwriting S because of its right overhang. Value is -1 if no
23884 glyph in front of S overwrites S. */
23887 left_overwriting (struct glyph_string
*s
)
23890 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23891 int first
= s
->first_glyph
- glyphs
;
23895 for (i
= first
- 1; i
>= 0; --i
)
23898 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23901 x
-= glyphs
[i
].pixel_width
;
23908 /* Return the index of the last glyph following glyph string S that is
23909 overwritten by S because of S's right overhang. Value is -1 if
23910 no such glyph is found. */
23913 right_overwritten (struct glyph_string
*s
)
23917 if (s
->right_overhang
)
23920 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23921 int first
= (s
->first_glyph
- glyphs
23922 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23923 int end
= s
->row
->used
[s
->area
];
23925 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23926 x
+= glyphs
[i
].pixel_width
;
23935 /* Return the index of the last glyph following glyph string S that
23936 overwrites S because of its left overhang. Value is negative
23937 if no such glyph is found. */
23940 right_overwriting (struct glyph_string
*s
)
23943 int end
= s
->row
->used
[s
->area
];
23944 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23945 int first
= (s
->first_glyph
- glyphs
23946 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23950 for (i
= first
; i
< end
; ++i
)
23953 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23956 x
+= glyphs
[i
].pixel_width
;
23963 /* Set background width of glyph string S. START is the index of the
23964 first glyph following S. LAST_X is the right-most x-position + 1
23965 in the drawing area. */
23968 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23970 /* If the face of this glyph string has to be drawn to the end of
23971 the drawing area, set S->extends_to_end_of_line_p. */
23973 if (start
== s
->row
->used
[s
->area
]
23974 && ((s
->row
->fill_line_p
23975 && (s
->hl
== DRAW_NORMAL_TEXT
23976 || s
->hl
== DRAW_IMAGE_RAISED
23977 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23978 || s
->hl
== DRAW_MOUSE_FACE
))
23979 s
->extends_to_end_of_line_p
= 1;
23981 /* If S extends its face to the end of the line, set its
23982 background_width to the distance to the right edge of the drawing
23984 if (s
->extends_to_end_of_line_p
)
23985 s
->background_width
= last_x
- s
->x
+ 1;
23987 s
->background_width
= s
->width
;
23991 /* Compute overhangs and x-positions for glyph string S and its
23992 predecessors, or successors. X is the starting x-position for S.
23993 BACKWARD_P non-zero means process predecessors. */
23996 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
24002 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
24003 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
24013 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
24014 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
24024 /* The following macros are only called from draw_glyphs below.
24025 They reference the following parameters of that function directly:
24026 `w', `row', `area', and `overlap_p'
24027 as well as the following local variables:
24028 `s', `f', and `hdc' (in W32) */
24031 /* On W32, silently add local `hdc' variable to argument list of
24032 init_glyph_string. */
24033 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
24034 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
24036 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
24037 init_glyph_string (s, char2b, w, row, area, start, hl)
24040 /* Add a glyph string for a stretch glyph to the list of strings
24041 between HEAD and TAIL. START is the index of the stretch glyph in
24042 row area AREA of glyph row ROW. END is the index of the last glyph
24043 in that glyph row area. X is the current output position assigned
24044 to the new glyph string constructed. HL overrides that face of the
24045 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
24046 is the right-most x-position of the drawing area. */
24048 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
24049 and below -- keep them on one line. */
24050 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24053 s = alloca (sizeof *s); \
24054 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24055 START = fill_stretch_glyph_string (s, START, END); \
24056 append_glyph_string (&HEAD, &TAIL, s); \
24062 /* Add a glyph string for an image glyph to the list of strings
24063 between HEAD and TAIL. START is the index of the image glyph in
24064 row area AREA of glyph row ROW. END is the index of the last glyph
24065 in that glyph row area. X is the current output position assigned
24066 to the new glyph string constructed. HL overrides that face of the
24067 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
24068 is the right-most x-position of the drawing area. */
24070 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24073 s = alloca (sizeof *s); \
24074 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24075 fill_image_glyph_string (s); \
24076 append_glyph_string (&HEAD, &TAIL, s); \
24083 /* Add a glyph string for a sequence of character glyphs to the list
24084 of strings between HEAD and TAIL. START is the index of the first
24085 glyph in row area AREA of glyph row ROW that is part of the new
24086 glyph string. END is the index of the last glyph in that glyph row
24087 area. X is the current output position assigned to the new glyph
24088 string constructed. HL overrides that face of the glyph; e.g. it
24089 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
24090 right-most x-position of the drawing area. */
24092 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24098 face_id = (row)->glyphs[area][START].face_id; \
24100 s = alloca (sizeof *s); \
24101 char2b = alloca ((END - START) * sizeof *char2b); \
24102 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24103 append_glyph_string (&HEAD, &TAIL, s); \
24105 START = fill_glyph_string (s, face_id, START, END, overlaps); \
24110 /* Add a glyph string for a composite sequence to the list of strings
24111 between HEAD and TAIL. START is the index of the first glyph in
24112 row area AREA of glyph row ROW that is part of the new glyph
24113 string. END is the index of the last glyph in that glyph row area.
24114 X is the current output position assigned to the new glyph string
24115 constructed. HL overrides that face of the glyph; e.g. it is
24116 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
24117 x-position of the drawing area. */
24119 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24121 int face_id = (row)->glyphs[area][START].face_id; \
24122 struct face *base_face = FACE_FROM_ID (f, face_id); \
24123 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
24124 struct composition *cmp = composition_table[cmp_id]; \
24126 struct glyph_string *first_s = NULL; \
24129 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
24131 /* Make glyph_strings for each glyph sequence that is drawable by \
24132 the same face, and append them to HEAD/TAIL. */ \
24133 for (n = 0; n < cmp->glyph_len;) \
24135 s = alloca (sizeof *s); \
24136 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24137 append_glyph_string (&(HEAD), &(TAIL), s); \
24143 n = fill_composite_glyph_string (s, base_face, overlaps); \
24151 /* Add a glyph string for a glyph-string sequence to the list of strings
24152 between HEAD and TAIL. */
24154 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24158 Lisp_Object gstring; \
24160 face_id = (row)->glyphs[area][START].face_id; \
24161 gstring = (composition_gstring_from_id \
24162 ((row)->glyphs[area][START].u.cmp.id)); \
24163 s = alloca (sizeof *s); \
24164 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
24165 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
24166 append_glyph_string (&(HEAD), &(TAIL), s); \
24168 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
24172 /* Add a glyph string for a sequence of glyphless character's glyphs
24173 to the list of strings between HEAD and TAIL. The meanings of
24174 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
24176 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
24181 face_id = (row)->glyphs[area][START].face_id; \
24183 s = alloca (sizeof *s); \
24184 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
24185 append_glyph_string (&HEAD, &TAIL, s); \
24187 START = fill_glyphless_glyph_string (s, face_id, START, END, \
24193 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
24194 of AREA of glyph row ROW on window W between indices START and END.
24195 HL overrides the face for drawing glyph strings, e.g. it is
24196 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
24197 x-positions of the drawing area.
24199 This is an ugly monster macro construct because we must use alloca
24200 to allocate glyph strings (because draw_glyphs can be called
24201 asynchronously). */
24203 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
24206 HEAD = TAIL = NULL; \
24207 while (START < END) \
24209 struct glyph *first_glyph = (row)->glyphs[area] + START; \
24210 switch (first_glyph->type) \
24213 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
24217 case COMPOSITE_GLYPH: \
24218 if (first_glyph->u.cmp.automatic) \
24219 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
24222 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
24226 case STRETCH_GLYPH: \
24227 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
24231 case IMAGE_GLYPH: \
24232 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
24236 case GLYPHLESS_GLYPH: \
24237 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
24247 set_glyph_string_background_width (s, START, LAST_X); \
24254 /* Draw glyphs between START and END in AREA of ROW on window W,
24255 starting at x-position X. X is relative to AREA in W. HL is a
24256 face-override with the following meaning:
24258 DRAW_NORMAL_TEXT draw normally
24259 DRAW_CURSOR draw in cursor face
24260 DRAW_MOUSE_FACE draw in mouse face.
24261 DRAW_INVERSE_VIDEO draw in mode line face
24262 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
24263 DRAW_IMAGE_RAISED draw an image with a raised relief around it
24265 If OVERLAPS is non-zero, draw only the foreground of characters and
24266 clip to the physical height of ROW. Non-zero value also defines
24267 the overlapping part to be drawn:
24269 OVERLAPS_PRED overlap with preceding rows
24270 OVERLAPS_SUCC overlap with succeeding rows
24271 OVERLAPS_BOTH overlap with both preceding/succeeding rows
24272 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
24274 Value is the x-position reached, relative to AREA of W. */
24277 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
24278 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
24279 enum draw_glyphs_face hl
, int overlaps
)
24281 struct glyph_string
*head
, *tail
;
24282 struct glyph_string
*s
;
24283 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
24284 int i
, j
, x_reached
, last_x
, area_left
= 0;
24285 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
24288 ALLOCATE_HDC (hdc
, f
);
24290 /* Let's rather be paranoid than getting a SEGV. */
24291 end
= min (end
, row
->used
[area
]);
24292 start
= clip_to_bounds (0, start
, end
);
24294 /* Translate X to frame coordinates. Set last_x to the right
24295 end of the drawing area. */
24296 if (row
->full_width_p
)
24298 /* X is relative to the left edge of W, without scroll bars
24300 area_left
= WINDOW_LEFT_EDGE_X (w
);
24301 last_x
= (WINDOW_LEFT_EDGE_X (w
) + WINDOW_PIXEL_WIDTH (w
)
24302 - (row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
24306 area_left
= window_box_left (w
, area
);
24307 last_x
= area_left
+ window_box_width (w
, area
);
24311 /* Build a doubly-linked list of glyph_string structures between
24312 head and tail from what we have to draw. Note that the macro
24313 BUILD_GLYPH_STRINGS will modify its start parameter. That's
24314 the reason we use a separate variable `i'. */
24316 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
24318 x_reached
= tail
->x
+ tail
->background_width
;
24322 /* If there are any glyphs with lbearing < 0 or rbearing > width in
24323 the row, redraw some glyphs in front or following the glyph
24324 strings built above. */
24325 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
24327 struct glyph_string
*h
, *t
;
24328 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
24329 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
24330 int check_mouse_face
= 0;
24333 /* If mouse highlighting is on, we may need to draw adjacent
24334 glyphs using mouse-face highlighting. */
24335 if (area
== TEXT_AREA
&& row
->mouse_face_p
24336 && hlinfo
->mouse_face_beg_row
>= 0
24337 && hlinfo
->mouse_face_end_row
>= 0)
24339 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
24341 if (row_vpos
>= hlinfo
->mouse_face_beg_row
24342 && row_vpos
<= hlinfo
->mouse_face_end_row
)
24344 check_mouse_face
= 1;
24345 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
24346 ? hlinfo
->mouse_face_beg_col
: 0;
24347 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
24348 ? hlinfo
->mouse_face_end_col
24349 : row
->used
[TEXT_AREA
];
24353 /* Compute overhangs for all glyph strings. */
24354 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
24355 for (s
= head
; s
; s
= s
->next
)
24356 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
24358 /* Prepend glyph strings for glyphs in front of the first glyph
24359 string that are overwritten because of the first glyph
24360 string's left overhang. The background of all strings
24361 prepended must be drawn because the first glyph string
24363 i
= left_overwritten (head
);
24366 enum draw_glyphs_face overlap_hl
;
24368 /* If this row contains mouse highlighting, attempt to draw
24369 the overlapped glyphs with the correct highlight. This
24370 code fails if the overlap encompasses more than one glyph
24371 and mouse-highlight spans only some of these glyphs.
24372 However, making it work perfectly involves a lot more
24373 code, and I don't know if the pathological case occurs in
24374 practice, so we'll stick to this for now. --- cyd */
24375 if (check_mouse_face
24376 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24377 overlap_hl
= DRAW_MOUSE_FACE
;
24379 overlap_hl
= DRAW_NORMAL_TEXT
;
24382 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
24383 overlap_hl
, dummy_x
, last_x
);
24385 compute_overhangs_and_x (t
, head
->x
, 1);
24386 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24390 /* Prepend glyph strings for glyphs in front of the first glyph
24391 string that overwrite that glyph string because of their
24392 right overhang. For these strings, only the foreground must
24393 be drawn, because it draws over the glyph string at `head'.
24394 The background must not be drawn because this would overwrite
24395 right overhangs of preceding glyphs for which no glyph
24397 i
= left_overwriting (head
);
24400 enum draw_glyphs_face overlap_hl
;
24402 if (check_mouse_face
24403 && mouse_beg_col
< start
&& mouse_end_col
> i
)
24404 overlap_hl
= DRAW_MOUSE_FACE
;
24406 overlap_hl
= DRAW_NORMAL_TEXT
;
24409 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
24410 overlap_hl
, dummy_x
, last_x
);
24411 for (s
= h
; s
; s
= s
->next
)
24412 s
->background_filled_p
= 1;
24413 compute_overhangs_and_x (t
, head
->x
, 1);
24414 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
24417 /* Append glyphs strings for glyphs following the last glyph
24418 string tail that are overwritten by tail. The background of
24419 these strings has to be drawn because tail's foreground draws
24421 i
= right_overwritten (tail
);
24424 enum draw_glyphs_face overlap_hl
;
24426 if (check_mouse_face
24427 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24428 overlap_hl
= DRAW_MOUSE_FACE
;
24430 overlap_hl
= DRAW_NORMAL_TEXT
;
24432 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24433 overlap_hl
, x
, last_x
);
24434 /* Because BUILD_GLYPH_STRINGS updates the first argument,
24435 we don't have `end = i;' here. */
24436 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24437 append_glyph_string_lists (&head
, &tail
, h
, t
);
24441 /* Append glyph strings for glyphs following the last glyph
24442 string tail that overwrite tail. The foreground of such
24443 glyphs has to be drawn because it writes into the background
24444 of tail. The background must not be drawn because it could
24445 paint over the foreground of following glyphs. */
24446 i
= right_overwriting (tail
);
24449 enum draw_glyphs_face overlap_hl
;
24450 if (check_mouse_face
24451 && mouse_beg_col
< i
&& mouse_end_col
> end
)
24452 overlap_hl
= DRAW_MOUSE_FACE
;
24454 overlap_hl
= DRAW_NORMAL_TEXT
;
24457 i
++; /* We must include the Ith glyph. */
24458 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
24459 overlap_hl
, x
, last_x
);
24460 for (s
= h
; s
; s
= s
->next
)
24461 s
->background_filled_p
= 1;
24462 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
24463 append_glyph_string_lists (&head
, &tail
, h
, t
);
24465 if (clip_head
|| clip_tail
)
24466 for (s
= head
; s
; s
= s
->next
)
24468 s
->clip_head
= clip_head
;
24469 s
->clip_tail
= clip_tail
;
24473 /* Draw all strings. */
24474 for (s
= head
; s
; s
= s
->next
)
24475 FRAME_RIF (f
)->draw_glyph_string (s
);
24478 /* When focus a sole frame and move horizontally, this sets on_p to 0
24479 causing a failure to erase prev cursor position. */
24480 if (area
== TEXT_AREA
24481 && !row
->full_width_p
24482 /* When drawing overlapping rows, only the glyph strings'
24483 foreground is drawn, which doesn't erase a cursor
24487 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24488 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24489 : (tail
? tail
->x
+ tail
->background_width
: x
));
24493 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24494 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24498 /* Value is the x-position up to which drawn, relative to AREA of W.
24499 This doesn't include parts drawn because of overhangs. */
24500 if (row
->full_width_p
)
24501 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24503 x_reached
-= area_left
;
24505 RELEASE_HDC (hdc
, f
);
24510 /* Expand row matrix if too narrow. Don't expand if area
24513 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24515 if (!it->f->fonts_changed \
24516 && (it->glyph_row->glyphs[area] \
24517 < it->glyph_row->glyphs[area + 1])) \
24519 it->w->ncols_scale_factor++; \
24520 it->f->fonts_changed = 1; \
24524 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24525 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24528 append_glyph (struct it
*it
)
24530 struct glyph
*glyph
;
24531 enum glyph_row_area area
= it
->area
;
24533 eassert (it
->glyph_row
);
24534 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24536 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24537 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24539 /* If the glyph row is reversed, we need to prepend the glyph
24540 rather than append it. */
24541 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24545 /* Make room for the additional glyph. */
24546 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24548 glyph
= it
->glyph_row
->glyphs
[area
];
24550 glyph
->charpos
= CHARPOS (it
->position
);
24551 glyph
->object
= it
->object
;
24552 if (it
->pixel_width
> 0)
24554 glyph
->pixel_width
= it
->pixel_width
;
24555 glyph
->padding_p
= 0;
24559 /* Assure at least 1-pixel width. Otherwise, cursor can't
24560 be displayed correctly. */
24561 glyph
->pixel_width
= 1;
24562 glyph
->padding_p
= 1;
24564 glyph
->ascent
= it
->ascent
;
24565 glyph
->descent
= it
->descent
;
24566 glyph
->voffset
= it
->voffset
;
24567 glyph
->type
= CHAR_GLYPH
;
24568 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24569 glyph
->multibyte_p
= it
->multibyte_p
;
24570 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24572 /* In R2L rows, the left and the right box edges need to be
24573 drawn in reverse direction. */
24574 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24575 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24579 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24580 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24582 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24583 || it
->phys_descent
> it
->descent
);
24584 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24585 glyph
->face_id
= it
->face_id
;
24586 glyph
->u
.ch
= it
->char_to_display
;
24587 glyph
->slice
.img
= null_glyph_slice
;
24588 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24591 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24592 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24594 glyph
->bidi_type
= it
->bidi_it
.type
;
24598 glyph
->resolved_level
= 0;
24599 glyph
->bidi_type
= UNKNOWN_BT
;
24601 ++it
->glyph_row
->used
[area
];
24604 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24607 /* Store one glyph for the composition IT->cmp_it.id in
24608 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24612 append_composite_glyph (struct it
*it
)
24614 struct glyph
*glyph
;
24615 enum glyph_row_area area
= it
->area
;
24617 eassert (it
->glyph_row
);
24619 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24620 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24622 /* If the glyph row is reversed, we need to prepend the glyph
24623 rather than append it. */
24624 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24628 /* Make room for the new glyph. */
24629 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24631 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24633 glyph
->charpos
= it
->cmp_it
.charpos
;
24634 glyph
->object
= it
->object
;
24635 glyph
->pixel_width
= it
->pixel_width
;
24636 glyph
->ascent
= it
->ascent
;
24637 glyph
->descent
= it
->descent
;
24638 glyph
->voffset
= it
->voffset
;
24639 glyph
->type
= COMPOSITE_GLYPH
;
24640 if (it
->cmp_it
.ch
< 0)
24642 glyph
->u
.cmp
.automatic
= 0;
24643 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24644 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24648 glyph
->u
.cmp
.automatic
= 1;
24649 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24650 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24651 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24653 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24654 glyph
->multibyte_p
= it
->multibyte_p
;
24655 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24657 /* In R2L rows, the left and the right box edges need to be
24658 drawn in reverse direction. */
24659 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24660 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24664 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24665 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24667 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24668 || it
->phys_descent
> it
->descent
);
24669 glyph
->padding_p
= 0;
24670 glyph
->glyph_not_available_p
= 0;
24671 glyph
->face_id
= it
->face_id
;
24672 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24675 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24676 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24678 glyph
->bidi_type
= it
->bidi_it
.type
;
24680 ++it
->glyph_row
->used
[area
];
24683 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24687 /* Change IT->ascent and IT->height according to the setting of
24691 take_vertical_position_into_account (struct it
*it
)
24695 if (it
->voffset
< 0)
24696 /* Increase the ascent so that we can display the text higher
24698 it
->ascent
-= it
->voffset
;
24700 /* Increase the descent so that we can display the text lower
24702 it
->descent
+= it
->voffset
;
24707 /* Produce glyphs/get display metrics for the image IT is loaded with.
24708 See the description of struct display_iterator in dispextern.h for
24709 an overview of struct display_iterator. */
24712 produce_image_glyph (struct it
*it
)
24716 int glyph_ascent
, crop
;
24717 struct glyph_slice slice
;
24719 eassert (it
->what
== IT_IMAGE
);
24721 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24723 /* Make sure X resources of the face is loaded. */
24724 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24726 if (it
->image_id
< 0)
24728 /* Fringe bitmap. */
24729 it
->ascent
= it
->phys_ascent
= 0;
24730 it
->descent
= it
->phys_descent
= 0;
24731 it
->pixel_width
= 0;
24736 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24738 /* Make sure X resources of the image is loaded. */
24739 prepare_image_for_display (it
->f
, img
);
24741 slice
.x
= slice
.y
= 0;
24742 slice
.width
= img
->width
;
24743 slice
.height
= img
->height
;
24745 if (INTEGERP (it
->slice
.x
))
24746 slice
.x
= XINT (it
->slice
.x
);
24747 else if (FLOATP (it
->slice
.x
))
24748 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24750 if (INTEGERP (it
->slice
.y
))
24751 slice
.y
= XINT (it
->slice
.y
);
24752 else if (FLOATP (it
->slice
.y
))
24753 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24755 if (INTEGERP (it
->slice
.width
))
24756 slice
.width
= XINT (it
->slice
.width
);
24757 else if (FLOATP (it
->slice
.width
))
24758 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24760 if (INTEGERP (it
->slice
.height
))
24761 slice
.height
= XINT (it
->slice
.height
);
24762 else if (FLOATP (it
->slice
.height
))
24763 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24765 if (slice
.x
>= img
->width
)
24766 slice
.x
= img
->width
;
24767 if (slice
.y
>= img
->height
)
24768 slice
.y
= img
->height
;
24769 if (slice
.x
+ slice
.width
>= img
->width
)
24770 slice
.width
= img
->width
- slice
.x
;
24771 if (slice
.y
+ slice
.height
> img
->height
)
24772 slice
.height
= img
->height
- slice
.y
;
24774 if (slice
.width
== 0 || slice
.height
== 0)
24777 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24779 it
->descent
= slice
.height
- glyph_ascent
;
24781 it
->descent
+= img
->vmargin
;
24782 if (slice
.y
+ slice
.height
== img
->height
)
24783 it
->descent
+= img
->vmargin
;
24784 it
->phys_descent
= it
->descent
;
24786 it
->pixel_width
= slice
.width
;
24788 it
->pixel_width
+= img
->hmargin
;
24789 if (slice
.x
+ slice
.width
== img
->width
)
24790 it
->pixel_width
+= img
->hmargin
;
24792 /* It's quite possible for images to have an ascent greater than
24793 their height, so don't get confused in that case. */
24794 if (it
->descent
< 0)
24799 if (face
->box
!= FACE_NO_BOX
)
24801 if (face
->box_line_width
> 0)
24804 it
->ascent
+= face
->box_line_width
;
24805 if (slice
.y
+ slice
.height
== img
->height
)
24806 it
->descent
+= face
->box_line_width
;
24809 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24810 it
->pixel_width
+= eabs (face
->box_line_width
);
24811 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24812 it
->pixel_width
+= eabs (face
->box_line_width
);
24815 take_vertical_position_into_account (it
);
24817 /* Automatically crop wide image glyphs at right edge so we can
24818 draw the cursor on same display row. */
24819 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24820 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24822 it
->pixel_width
-= crop
;
24823 slice
.width
-= crop
;
24828 struct glyph
*glyph
;
24829 enum glyph_row_area area
= it
->area
;
24831 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24832 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24834 glyph
->charpos
= CHARPOS (it
->position
);
24835 glyph
->object
= it
->object
;
24836 glyph
->pixel_width
= it
->pixel_width
;
24837 glyph
->ascent
= glyph_ascent
;
24838 glyph
->descent
= it
->descent
;
24839 glyph
->voffset
= it
->voffset
;
24840 glyph
->type
= IMAGE_GLYPH
;
24841 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24842 glyph
->multibyte_p
= it
->multibyte_p
;
24843 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24845 /* In R2L rows, the left and the right box edges need to be
24846 drawn in reverse direction. */
24847 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24848 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24852 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24853 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24855 glyph
->overlaps_vertically_p
= 0;
24856 glyph
->padding_p
= 0;
24857 glyph
->glyph_not_available_p
= 0;
24858 glyph
->face_id
= it
->face_id
;
24859 glyph
->u
.img_id
= img
->id
;
24860 glyph
->slice
.img
= slice
;
24861 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24864 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24865 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24867 glyph
->bidi_type
= it
->bidi_it
.type
;
24869 ++it
->glyph_row
->used
[area
];
24872 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24877 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24878 of the glyph, WIDTH and HEIGHT are the width and height of the
24879 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24882 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24883 int width
, int height
, int ascent
)
24885 struct glyph
*glyph
;
24886 enum glyph_row_area area
= it
->area
;
24888 eassert (ascent
>= 0 && ascent
<= height
);
24890 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24891 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24893 /* If the glyph row is reversed, we need to prepend the glyph
24894 rather than append it. */
24895 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24899 /* Make room for the additional glyph. */
24900 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24902 glyph
= it
->glyph_row
->glyphs
[area
];
24904 glyph
->charpos
= CHARPOS (it
->position
);
24905 glyph
->object
= object
;
24906 glyph
->pixel_width
= width
;
24907 glyph
->ascent
= ascent
;
24908 glyph
->descent
= height
- ascent
;
24909 glyph
->voffset
= it
->voffset
;
24910 glyph
->type
= STRETCH_GLYPH
;
24911 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24912 glyph
->multibyte_p
= it
->multibyte_p
;
24913 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24915 /* In R2L rows, the left and the right box edges need to be
24916 drawn in reverse direction. */
24917 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24918 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24922 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24923 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24925 glyph
->overlaps_vertically_p
= 0;
24926 glyph
->padding_p
= 0;
24927 glyph
->glyph_not_available_p
= 0;
24928 glyph
->face_id
= it
->face_id
;
24929 glyph
->u
.stretch
.ascent
= ascent
;
24930 glyph
->u
.stretch
.height
= height
;
24931 glyph
->slice
.img
= null_glyph_slice
;
24932 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24935 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24936 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24938 glyph
->bidi_type
= it
->bidi_it
.type
;
24942 glyph
->resolved_level
= 0;
24943 glyph
->bidi_type
= UNKNOWN_BT
;
24945 ++it
->glyph_row
->used
[area
];
24948 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24951 #endif /* HAVE_WINDOW_SYSTEM */
24953 /* Produce a stretch glyph for iterator IT. IT->object is the value
24954 of the glyph property displayed. The value must be a list
24955 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24958 1. `:width WIDTH' specifies that the space should be WIDTH *
24959 canonical char width wide. WIDTH may be an integer or floating
24962 2. `:relative-width FACTOR' specifies that the width of the stretch
24963 should be computed from the width of the first character having the
24964 `glyph' property, and should be FACTOR times that width.
24966 3. `:align-to HPOS' specifies that the space should be wide enough
24967 to reach HPOS, a value in canonical character units.
24969 Exactly one of the above pairs must be present.
24971 4. `:height HEIGHT' specifies that the height of the stretch produced
24972 should be HEIGHT, measured in canonical character units.
24974 5. `:relative-height FACTOR' specifies that the height of the
24975 stretch should be FACTOR times the height of the characters having
24976 the glyph property.
24978 Either none or exactly one of 4 or 5 must be present.
24980 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24981 of the stretch should be used for the ascent of the stretch.
24982 ASCENT must be in the range 0 <= ASCENT <= 100. */
24985 produce_stretch_glyph (struct it
*it
)
24987 /* (space :width WIDTH :height HEIGHT ...) */
24988 Lisp_Object prop
, plist
;
24989 int width
= 0, height
= 0, align_to
= -1;
24990 int zero_width_ok_p
= 0;
24992 struct font
*font
= NULL
;
24994 #ifdef HAVE_WINDOW_SYSTEM
24996 int zero_height_ok_p
= 0;
24998 if (FRAME_WINDOW_P (it
->f
))
25000 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25001 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25002 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25006 /* List should start with `space'. */
25007 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
25008 plist
= XCDR (it
->object
);
25010 /* Compute the width of the stretch. */
25011 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
25012 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
25014 /* Absolute width `:width WIDTH' specified and valid. */
25015 zero_width_ok_p
= 1;
25018 #ifdef HAVE_WINDOW_SYSTEM
25019 else if (FRAME_WINDOW_P (it
->f
)
25020 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
25022 /* Relative width `:relative-width FACTOR' specified and valid.
25023 Compute the width of the characters having the `glyph'
25026 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
25029 if (it
->multibyte_p
)
25030 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
25033 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
25034 if (! ASCII_CHAR_P (it2
.c
))
25035 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
25038 it2
.glyph_row
= NULL
;
25039 it2
.what
= IT_CHARACTER
;
25040 x_produce_glyphs (&it2
);
25041 width
= NUMVAL (prop
) * it2
.pixel_width
;
25043 #endif /* HAVE_WINDOW_SYSTEM */
25044 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
25045 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
25047 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
25048 align_to
= (align_to
< 0
25050 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
25051 else if (align_to
< 0)
25052 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
25053 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
25054 zero_width_ok_p
= 1;
25057 /* Nothing specified -> width defaults to canonical char width. */
25058 width
= FRAME_COLUMN_WIDTH (it
->f
);
25060 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
25063 #ifdef HAVE_WINDOW_SYSTEM
25064 /* Compute height. */
25065 if (FRAME_WINDOW_P (it
->f
))
25067 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
25068 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
25071 zero_height_ok_p
= 1;
25073 else if (prop
= Fplist_get (plist
, QCrelative_height
),
25075 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
25077 height
= FONT_HEIGHT (font
);
25079 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
25082 /* Compute percentage of height used for ascent. If
25083 `:ascent ASCENT' is present and valid, use that. Otherwise,
25084 derive the ascent from the font in use. */
25085 if (prop
= Fplist_get (plist
, QCascent
),
25086 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
25087 ascent
= height
* NUMVAL (prop
) / 100.0;
25088 else if (!NILP (prop
)
25089 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
25090 ascent
= min (max (0, (int)tem
), height
);
25092 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
25095 #endif /* HAVE_WINDOW_SYSTEM */
25098 if (width
> 0 && it
->line_wrap
!= TRUNCATE
25099 && it
->current_x
+ width
> it
->last_visible_x
)
25101 width
= it
->last_visible_x
- it
->current_x
;
25102 #ifdef HAVE_WINDOW_SYSTEM
25103 /* Subtract one more pixel from the stretch width, but only on
25104 GUI frames, since on a TTY each glyph is one "pixel" wide. */
25105 width
-= FRAME_WINDOW_P (it
->f
);
25109 if (width
> 0 && height
> 0 && it
->glyph_row
)
25111 Lisp_Object o_object
= it
->object
;
25112 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
25115 if (!STRINGP (object
))
25116 object
= it
->w
->contents
;
25117 #ifdef HAVE_WINDOW_SYSTEM
25118 if (FRAME_WINDOW_P (it
->f
))
25119 append_stretch_glyph (it
, object
, width
, height
, ascent
);
25123 it
->object
= object
;
25124 it
->char_to_display
= ' ';
25125 it
->pixel_width
= it
->len
= 1;
25127 tty_append_glyph (it
);
25128 it
->object
= o_object
;
25132 it
->pixel_width
= width
;
25133 #ifdef HAVE_WINDOW_SYSTEM
25134 if (FRAME_WINDOW_P (it
->f
))
25136 it
->ascent
= it
->phys_ascent
= ascent
;
25137 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
25138 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
25139 take_vertical_position_into_account (it
);
25143 it
->nglyphs
= width
;
25146 /* Get information about special display element WHAT in an
25147 environment described by IT. WHAT is one of IT_TRUNCATION or
25148 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
25149 non-null glyph_row member. This function ensures that fields like
25150 face_id, c, len of IT are left untouched. */
25153 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
25160 temp_it
.object
= make_number (0);
25161 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
25163 if (what
== IT_CONTINUATION
)
25165 /* Continuation glyph. For R2L lines, we mirror it by hand. */
25166 if (it
->bidi_it
.paragraph_dir
== R2L
)
25167 SET_GLYPH_FROM_CHAR (glyph
, '/');
25169 SET_GLYPH_FROM_CHAR (glyph
, '\\');
25171 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25173 /* FIXME: Should we mirror GC for R2L lines? */
25174 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25175 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25178 else if (what
== IT_TRUNCATION
)
25180 /* Truncation glyph. */
25181 SET_GLYPH_FROM_CHAR (glyph
, '$');
25183 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
25185 /* FIXME: Should we mirror GC for R2L lines? */
25186 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
25187 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
25193 #ifdef HAVE_WINDOW_SYSTEM
25194 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
25195 is turned off, we precede the truncation/continuation glyphs by a
25196 stretch glyph whose width is computed such that these special
25197 glyphs are aligned at the window margin, even when very different
25198 fonts are used in different glyph rows. */
25199 if (FRAME_WINDOW_P (temp_it
.f
)
25200 /* init_iterator calls this with it->glyph_row == NULL, and it
25201 wants only the pixel width of the truncation/continuation
25203 && temp_it
.glyph_row
25204 /* insert_left_trunc_glyphs calls us at the beginning of the
25205 row, and it has its own calculation of the stretch glyph
25207 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
25208 && (temp_it
.glyph_row
->reversed_p
25209 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
25210 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
25212 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
25214 if (stretch_width
> 0)
25216 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
25217 struct font
*font
=
25218 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
25219 int stretch_ascent
=
25220 (((temp_it
.ascent
+ temp_it
.descent
)
25221 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
25223 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
25224 temp_it
.ascent
+ temp_it
.descent
,
25231 temp_it
.what
= IT_CHARACTER
;
25233 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
25234 temp_it
.face_id
= GLYPH_FACE (glyph
);
25235 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
25237 PRODUCE_GLYPHS (&temp_it
);
25238 it
->pixel_width
= temp_it
.pixel_width
;
25239 it
->nglyphs
= temp_it
.pixel_width
;
25242 #ifdef HAVE_WINDOW_SYSTEM
25244 /* Calculate line-height and line-spacing properties.
25245 An integer value specifies explicit pixel value.
25246 A float value specifies relative value to current face height.
25247 A cons (float . face-name) specifies relative value to
25248 height of specified face font.
25250 Returns height in pixels, or nil. */
25254 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
25255 int boff
, int override
)
25257 Lisp_Object face_name
= Qnil
;
25258 int ascent
, descent
, height
;
25260 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
25265 face_name
= XCAR (val
);
25267 if (!NUMBERP (val
))
25268 val
= make_number (1);
25269 if (NILP (face_name
))
25271 height
= it
->ascent
+ it
->descent
;
25276 if (NILP (face_name
))
25278 font
= FRAME_FONT (it
->f
);
25279 boff
= FRAME_BASELINE_OFFSET (it
->f
);
25281 else if (EQ (face_name
, Qt
))
25290 face_id
= lookup_named_face (it
->f
, face_name
, 0);
25292 return make_number (-1);
25294 face
= FACE_FROM_ID (it
->f
, face_id
);
25297 return make_number (-1);
25298 boff
= font
->baseline_offset
;
25299 if (font
->vertical_centering
)
25300 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25303 ascent
= FONT_BASE (font
) + boff
;
25304 descent
= FONT_DESCENT (font
) - boff
;
25308 it
->override_ascent
= ascent
;
25309 it
->override_descent
= descent
;
25310 it
->override_boff
= boff
;
25313 height
= ascent
+ descent
;
25317 height
= (int)(XFLOAT_DATA (val
) * height
);
25318 else if (INTEGERP (val
))
25319 height
*= XINT (val
);
25321 return make_number (height
);
25325 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
25326 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
25327 and only if this is for a character for which no font was found.
25329 If the display method (it->glyphless_method) is
25330 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
25331 length of the acronym or the hexadecimal string, UPPER_XOFF and
25332 UPPER_YOFF are pixel offsets for the upper part of the string,
25333 LOWER_XOFF and LOWER_YOFF are for the lower part.
25335 For the other display methods, LEN through LOWER_YOFF are zero. */
25338 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
25339 short upper_xoff
, short upper_yoff
,
25340 short lower_xoff
, short lower_yoff
)
25342 struct glyph
*glyph
;
25343 enum glyph_row_area area
= it
->area
;
25345 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
25346 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
25348 /* If the glyph row is reversed, we need to prepend the glyph
25349 rather than append it. */
25350 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25354 /* Make room for the additional glyph. */
25355 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
25357 glyph
= it
->glyph_row
->glyphs
[area
];
25359 glyph
->charpos
= CHARPOS (it
->position
);
25360 glyph
->object
= it
->object
;
25361 glyph
->pixel_width
= it
->pixel_width
;
25362 glyph
->ascent
= it
->ascent
;
25363 glyph
->descent
= it
->descent
;
25364 glyph
->voffset
= it
->voffset
;
25365 glyph
->type
= GLYPHLESS_GLYPH
;
25366 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
25367 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
25368 glyph
->u
.glyphless
.len
= len
;
25369 glyph
->u
.glyphless
.ch
= it
->c
;
25370 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
25371 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
25372 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
25373 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
25374 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
25375 glyph
->multibyte_p
= it
->multibyte_p
;
25376 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
25378 /* In R2L rows, the left and the right box edges need to be
25379 drawn in reverse direction. */
25380 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
25381 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
25385 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
25386 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
25388 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
25389 || it
->phys_descent
> it
->descent
);
25390 glyph
->padding_p
= 0;
25391 glyph
->glyph_not_available_p
= 0;
25392 glyph
->face_id
= face_id
;
25393 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
25396 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
25397 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
25399 glyph
->bidi_type
= it
->bidi_it
.type
;
25401 ++it
->glyph_row
->used
[area
];
25404 IT_EXPAND_MATRIX_WIDTH (it
, area
);
25408 /* Produce a glyph for a glyphless character for iterator IT.
25409 IT->glyphless_method specifies which method to use for displaying
25410 the character. See the description of enum
25411 glyphless_display_method in dispextern.h for the detail.
25413 FOR_NO_FONT is nonzero if and only if this is for a character for
25414 which no font was found. ACRONYM, if non-nil, is an acronym string
25415 for the character. */
25418 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
25423 int base_width
, base_height
, width
, height
;
25424 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
25427 /* Get the metrics of the base font. We always refer to the current
25429 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
25430 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25431 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
25432 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
25433 base_height
= it
->ascent
+ it
->descent
;
25434 base_width
= font
->average_width
;
25436 face_id
= merge_glyphless_glyph_face (it
);
25438 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
25440 it
->pixel_width
= THIN_SPACE_WIDTH
;
25442 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25444 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
25446 width
= CHAR_WIDTH (it
->c
);
25449 else if (width
> 4)
25451 it
->pixel_width
= base_width
* width
;
25453 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25459 unsigned int code
[6];
25461 int ascent
, descent
;
25462 struct font_metrics metrics_upper
, metrics_lower
;
25464 face
= FACE_FROM_ID (it
->f
, face_id
);
25465 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25466 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25468 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25470 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25471 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25472 if (CONSP (acronym
))
25473 acronym
= XCAR (acronym
);
25474 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25478 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25479 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25482 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25483 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25484 upper_len
= (len
+ 1) / 2;
25485 font
->driver
->text_extents (font
, code
, upper_len
,
25487 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25492 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25493 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25494 upper_xoff
= upper_yoff
= 2; /* the typical case */
25495 if (base_width
>= width
)
25497 /* Align the upper to the left, the lower to the right. */
25498 it
->pixel_width
= base_width
;
25499 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25503 /* Center the shorter one. */
25504 it
->pixel_width
= width
;
25505 if (metrics_upper
.width
>= metrics_lower
.width
)
25506 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25509 /* FIXME: This code doesn't look right. It formerly was
25510 missing the "lower_xoff = 0;", which couldn't have
25511 been right since it left lower_xoff uninitialized. */
25513 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25517 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25518 top, bottom, and between upper and lower strings. */
25519 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25520 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25521 /* Center vertically.
25522 H:base_height, D:base_descent
25523 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25525 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25526 descent = D - H/2 + h/2;
25527 lower_yoff = descent - 2 - ld;
25528 upper_yoff = lower_yoff - la - 1 - ud; */
25529 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25530 descent
= it
->descent
- (base_height
- height
) / 2;
25531 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25532 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25533 - metrics_upper
.descent
);
25534 /* Don't make the height shorter than the base height. */
25535 if (height
> base_height
)
25537 it
->ascent
= ascent
;
25538 it
->descent
= descent
;
25542 it
->phys_ascent
= it
->ascent
;
25543 it
->phys_descent
= it
->descent
;
25545 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25546 upper_xoff
, upper_yoff
,
25547 lower_xoff
, lower_yoff
);
25549 take_vertical_position_into_account (it
);
25554 Produce glyphs/get display metrics for the display element IT is
25555 loaded with. See the description of struct it in dispextern.h
25556 for an overview of struct it. */
25559 x_produce_glyphs (struct it
*it
)
25561 int extra_line_spacing
= it
->extra_line_spacing
;
25563 it
->glyph_not_available_p
= 0;
25565 if (it
->what
== IT_CHARACTER
)
25568 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25569 struct font
*font
= face
->font
;
25570 struct font_metrics
*pcm
= NULL
;
25571 int boff
; /* Baseline offset. */
25575 /* When no suitable font is found, display this character by
25576 the method specified in the first extra slot of
25577 Vglyphless_char_display. */
25578 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25580 eassert (it
->what
== IT_GLYPHLESS
);
25581 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25585 boff
= font
->baseline_offset
;
25586 if (font
->vertical_centering
)
25587 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25589 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25595 if (it
->override_ascent
>= 0)
25597 it
->ascent
= it
->override_ascent
;
25598 it
->descent
= it
->override_descent
;
25599 boff
= it
->override_boff
;
25603 it
->ascent
= FONT_BASE (font
) + boff
;
25604 it
->descent
= FONT_DESCENT (font
) - boff
;
25607 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25609 pcm
= get_per_char_metric (font
, &char2b
);
25610 if (pcm
->width
== 0
25611 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25617 it
->phys_ascent
= pcm
->ascent
+ boff
;
25618 it
->phys_descent
= pcm
->descent
- boff
;
25619 it
->pixel_width
= pcm
->width
;
25623 it
->glyph_not_available_p
= 1;
25624 it
->phys_ascent
= it
->ascent
;
25625 it
->phys_descent
= it
->descent
;
25626 it
->pixel_width
= font
->space_width
;
25629 if (it
->constrain_row_ascent_descent_p
)
25631 if (it
->descent
> it
->max_descent
)
25633 it
->ascent
+= it
->descent
- it
->max_descent
;
25634 it
->descent
= it
->max_descent
;
25636 if (it
->ascent
> it
->max_ascent
)
25638 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25639 it
->ascent
= it
->max_ascent
;
25641 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25642 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25643 extra_line_spacing
= 0;
25646 /* If this is a space inside a region of text with
25647 `space-width' property, change its width. */
25648 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25650 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25652 /* If face has a box, add the box thickness to the character
25653 height. If character has a box line to the left and/or
25654 right, add the box line width to the character's width. */
25655 if (face
->box
!= FACE_NO_BOX
)
25657 int thick
= face
->box_line_width
;
25661 it
->ascent
+= thick
;
25662 it
->descent
+= thick
;
25667 if (it
->start_of_box_run_p
)
25668 it
->pixel_width
+= thick
;
25669 if (it
->end_of_box_run_p
)
25670 it
->pixel_width
+= thick
;
25673 /* If face has an overline, add the height of the overline
25674 (1 pixel) and a 1 pixel margin to the character height. */
25675 if (face
->overline_p
)
25676 it
->ascent
+= overline_margin
;
25678 if (it
->constrain_row_ascent_descent_p
)
25680 if (it
->ascent
> it
->max_ascent
)
25681 it
->ascent
= it
->max_ascent
;
25682 if (it
->descent
> it
->max_descent
)
25683 it
->descent
= it
->max_descent
;
25686 take_vertical_position_into_account (it
);
25688 /* If we have to actually produce glyphs, do it. */
25693 /* Translate a space with a `space-width' property
25694 into a stretch glyph. */
25695 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25696 / FONT_HEIGHT (font
));
25697 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25698 it
->ascent
+ it
->descent
, ascent
);
25703 /* If characters with lbearing or rbearing are displayed
25704 in this line, record that fact in a flag of the
25705 glyph row. This is used to optimize X output code. */
25706 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25707 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25709 if (! stretched_p
&& it
->pixel_width
== 0)
25710 /* We assure that all visible glyphs have at least 1-pixel
25712 it
->pixel_width
= 1;
25714 else if (it
->char_to_display
== '\n')
25716 /* A newline has no width, but we need the height of the
25717 line. But if previous part of the line sets a height,
25718 don't increase that height. */
25720 Lisp_Object height
;
25721 Lisp_Object total_height
= Qnil
;
25723 it
->override_ascent
= -1;
25724 it
->pixel_width
= 0;
25727 height
= get_it_property (it
, Qline_height
);
25728 /* Split (line-height total-height) list. */
25730 && CONSP (XCDR (height
))
25731 && NILP (XCDR (XCDR (height
))))
25733 total_height
= XCAR (XCDR (height
));
25734 height
= XCAR (height
);
25736 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25738 if (it
->override_ascent
>= 0)
25740 it
->ascent
= it
->override_ascent
;
25741 it
->descent
= it
->override_descent
;
25742 boff
= it
->override_boff
;
25746 it
->ascent
= FONT_BASE (font
) + boff
;
25747 it
->descent
= FONT_DESCENT (font
) - boff
;
25750 if (EQ (height
, Qt
))
25752 if (it
->descent
> it
->max_descent
)
25754 it
->ascent
+= it
->descent
- it
->max_descent
;
25755 it
->descent
= it
->max_descent
;
25757 if (it
->ascent
> it
->max_ascent
)
25759 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25760 it
->ascent
= it
->max_ascent
;
25762 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25763 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25764 it
->constrain_row_ascent_descent_p
= 1;
25765 extra_line_spacing
= 0;
25769 Lisp_Object spacing
;
25771 it
->phys_ascent
= it
->ascent
;
25772 it
->phys_descent
= it
->descent
;
25774 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25775 && face
->box
!= FACE_NO_BOX
25776 && face
->box_line_width
> 0)
25778 it
->ascent
+= face
->box_line_width
;
25779 it
->descent
+= face
->box_line_width
;
25782 && XINT (height
) > it
->ascent
+ it
->descent
)
25783 it
->ascent
= XINT (height
) - it
->descent
;
25785 if (!NILP (total_height
))
25786 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25789 spacing
= get_it_property (it
, Qline_spacing
);
25790 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25792 if (INTEGERP (spacing
))
25794 extra_line_spacing
= XINT (spacing
);
25795 if (!NILP (total_height
))
25796 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25800 else /* i.e. (it->char_to_display == '\t') */
25802 if (font
->space_width
> 0)
25804 int tab_width
= it
->tab_width
* font
->space_width
;
25805 int x
= it
->current_x
+ it
->continuation_lines_width
;
25806 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25808 /* If the distance from the current position to the next tab
25809 stop is less than a space character width, use the
25810 tab stop after that. */
25811 if (next_tab_x
- x
< font
->space_width
)
25812 next_tab_x
+= tab_width
;
25814 it
->pixel_width
= next_tab_x
- x
;
25816 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25817 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25821 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25822 it
->ascent
+ it
->descent
, it
->ascent
);
25827 it
->pixel_width
= 0;
25832 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25834 /* A static composition.
25836 Note: A composition is represented as one glyph in the
25837 glyph matrix. There are no padding glyphs.
25839 Important note: pixel_width, ascent, and descent are the
25840 values of what is drawn by draw_glyphs (i.e. the values of
25841 the overall glyphs composed). */
25842 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25843 int boff
; /* baseline offset */
25844 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25845 int glyph_len
= cmp
->glyph_len
;
25846 struct font
*font
= face
->font
;
25850 /* If we have not yet calculated pixel size data of glyphs of
25851 the composition for the current face font, calculate them
25852 now. Theoretically, we have to check all fonts for the
25853 glyphs, but that requires much time and memory space. So,
25854 here we check only the font of the first glyph. This may
25855 lead to incorrect display, but it's very rare, and C-l
25856 (recenter-top-bottom) can correct the display anyway. */
25857 if (! cmp
->font
|| cmp
->font
!= font
)
25859 /* Ascent and descent of the font of the first character
25860 of this composition (adjusted by baseline offset).
25861 Ascent and descent of overall glyphs should not be less
25862 than these, respectively. */
25863 int font_ascent
, font_descent
, font_height
;
25864 /* Bounding box of the overall glyphs. */
25865 int leftmost
, rightmost
, lowest
, highest
;
25866 int lbearing
, rbearing
;
25867 int i
, width
, ascent
, descent
;
25868 int left_padded
= 0, right_padded
= 0;
25869 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25871 struct font_metrics
*pcm
;
25872 int font_not_found_p
;
25875 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25876 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25878 if (glyph_len
< cmp
->glyph_len
)
25880 for (i
= 0; i
< glyph_len
; i
++)
25882 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25884 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25889 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25890 : IT_CHARPOS (*it
));
25891 /* If no suitable font is found, use the default font. */
25892 font_not_found_p
= font
== NULL
;
25893 if (font_not_found_p
)
25895 face
= face
->ascii_face
;
25898 boff
= font
->baseline_offset
;
25899 if (font
->vertical_centering
)
25900 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25901 font_ascent
= FONT_BASE (font
) + boff
;
25902 font_descent
= FONT_DESCENT (font
) - boff
;
25903 font_height
= FONT_HEIGHT (font
);
25908 if (! font_not_found_p
)
25910 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25912 pcm
= get_per_char_metric (font
, &char2b
);
25915 /* Initialize the bounding box. */
25918 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25919 ascent
= pcm
->ascent
;
25920 descent
= pcm
->descent
;
25921 lbearing
= pcm
->lbearing
;
25922 rbearing
= pcm
->rbearing
;
25926 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25927 ascent
= FONT_BASE (font
);
25928 descent
= FONT_DESCENT (font
);
25935 lowest
= - descent
+ boff
;
25936 highest
= ascent
+ boff
;
25938 if (! font_not_found_p
25939 && font
->default_ascent
25940 && CHAR_TABLE_P (Vuse_default_ascent
)
25941 && !NILP (Faref (Vuse_default_ascent
,
25942 make_number (it
->char_to_display
))))
25943 highest
= font
->default_ascent
+ boff
;
25945 /* Draw the first glyph at the normal position. It may be
25946 shifted to right later if some other glyphs are drawn
25948 cmp
->offsets
[i
* 2] = 0;
25949 cmp
->offsets
[i
* 2 + 1] = boff
;
25950 cmp
->lbearing
= lbearing
;
25951 cmp
->rbearing
= rbearing
;
25953 /* Set cmp->offsets for the remaining glyphs. */
25954 for (i
++; i
< glyph_len
; i
++)
25956 int left
, right
, btm
, top
;
25957 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25959 struct face
*this_face
;
25963 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25964 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25965 font
= this_face
->font
;
25971 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25973 pcm
= get_per_char_metric (font
, &char2b
);
25976 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25979 width
= pcm
->width
;
25980 ascent
= pcm
->ascent
;
25981 descent
= pcm
->descent
;
25982 lbearing
= pcm
->lbearing
;
25983 rbearing
= pcm
->rbearing
;
25984 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25986 /* Relative composition with or without
25987 alternate chars. */
25988 left
= (leftmost
+ rightmost
- width
) / 2;
25989 btm
= - descent
+ boff
;
25990 if (font
->relative_compose
25991 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25992 || NILP (Faref (Vignore_relative_composition
,
25993 make_number (ch
)))))
25996 if (- descent
>= font
->relative_compose
)
25997 /* One extra pixel between two glyphs. */
25999 else if (ascent
<= 0)
26000 /* One extra pixel between two glyphs. */
26001 btm
= lowest
- 1 - ascent
- descent
;
26006 /* A composition rule is specified by an integer
26007 value that encodes global and new reference
26008 points (GREF and NREF). GREF and NREF are
26009 specified by numbers as below:
26011 0---1---2 -- ascent
26015 9--10--11 -- center
26017 ---3---4---5--- baseline
26019 6---7---8 -- descent
26021 int rule
= COMPOSITION_RULE (cmp
, i
);
26022 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
26024 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
26025 grefx
= gref
% 3, nrefx
= nref
% 3;
26026 grefy
= gref
/ 3, nrefy
= nref
/ 3;
26028 xoff
= font_height
* (xoff
- 128) / 256;
26030 yoff
= font_height
* (yoff
- 128) / 256;
26033 + grefx
* (rightmost
- leftmost
) / 2
26034 - nrefx
* width
/ 2
26037 btm
= ((grefy
== 0 ? highest
26039 : grefy
== 2 ? lowest
26040 : (highest
+ lowest
) / 2)
26041 - (nrefy
== 0 ? ascent
+ descent
26042 : nrefy
== 1 ? descent
- boff
26044 : (ascent
+ descent
) / 2)
26048 cmp
->offsets
[i
* 2] = left
;
26049 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
26051 /* Update the bounding box of the overall glyphs. */
26054 right
= left
+ width
;
26055 if (left
< leftmost
)
26057 if (right
> rightmost
)
26060 top
= btm
+ descent
+ ascent
;
26066 if (cmp
->lbearing
> left
+ lbearing
)
26067 cmp
->lbearing
= left
+ lbearing
;
26068 if (cmp
->rbearing
< left
+ rbearing
)
26069 cmp
->rbearing
= left
+ rbearing
;
26073 /* If there are glyphs whose x-offsets are negative,
26074 shift all glyphs to the right and make all x-offsets
26078 for (i
= 0; i
< cmp
->glyph_len
; i
++)
26079 cmp
->offsets
[i
* 2] -= leftmost
;
26080 rightmost
-= leftmost
;
26081 cmp
->lbearing
-= leftmost
;
26082 cmp
->rbearing
-= leftmost
;
26085 if (left_padded
&& cmp
->lbearing
< 0)
26087 for (i
= 0; i
< cmp
->glyph_len
; i
++)
26088 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
26089 rightmost
-= cmp
->lbearing
;
26090 cmp
->rbearing
-= cmp
->lbearing
;
26093 if (right_padded
&& rightmost
< cmp
->rbearing
)
26095 rightmost
= cmp
->rbearing
;
26098 cmp
->pixel_width
= rightmost
;
26099 cmp
->ascent
= highest
;
26100 cmp
->descent
= - lowest
;
26101 if (cmp
->ascent
< font_ascent
)
26102 cmp
->ascent
= font_ascent
;
26103 if (cmp
->descent
< font_descent
)
26104 cmp
->descent
= font_descent
;
26108 && (cmp
->lbearing
< 0
26109 || cmp
->rbearing
> cmp
->pixel_width
))
26110 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26112 it
->pixel_width
= cmp
->pixel_width
;
26113 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
26114 it
->descent
= it
->phys_descent
= cmp
->descent
;
26115 if (face
->box
!= FACE_NO_BOX
)
26117 int thick
= face
->box_line_width
;
26121 it
->ascent
+= thick
;
26122 it
->descent
+= thick
;
26127 if (it
->start_of_box_run_p
)
26128 it
->pixel_width
+= thick
;
26129 if (it
->end_of_box_run_p
)
26130 it
->pixel_width
+= thick
;
26133 /* If face has an overline, add the height of the overline
26134 (1 pixel) and a 1 pixel margin to the character height. */
26135 if (face
->overline_p
)
26136 it
->ascent
+= overline_margin
;
26138 take_vertical_position_into_account (it
);
26139 if (it
->ascent
< 0)
26141 if (it
->descent
< 0)
26144 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
26145 append_composite_glyph (it
);
26147 else if (it
->what
== IT_COMPOSITION
)
26149 /* A dynamic (automatic) composition. */
26150 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
26151 Lisp_Object gstring
;
26152 struct font_metrics metrics
;
26156 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
26158 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
26161 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
26162 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
26163 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
26164 it
->descent
= it
->phys_descent
= metrics
.descent
;
26165 if (face
->box
!= FACE_NO_BOX
)
26167 int thick
= face
->box_line_width
;
26171 it
->ascent
+= thick
;
26172 it
->descent
+= thick
;
26177 if (it
->start_of_box_run_p
)
26178 it
->pixel_width
+= thick
;
26179 if (it
->end_of_box_run_p
)
26180 it
->pixel_width
+= thick
;
26182 /* If face has an overline, add the height of the overline
26183 (1 pixel) and a 1 pixel margin to the character height. */
26184 if (face
->overline_p
)
26185 it
->ascent
+= overline_margin
;
26186 take_vertical_position_into_account (it
);
26187 if (it
->ascent
< 0)
26189 if (it
->descent
< 0)
26193 append_composite_glyph (it
);
26195 else if (it
->what
== IT_GLYPHLESS
)
26196 produce_glyphless_glyph (it
, 0, Qnil
);
26197 else if (it
->what
== IT_IMAGE
)
26198 produce_image_glyph (it
);
26199 else if (it
->what
== IT_STRETCH
)
26200 produce_stretch_glyph (it
);
26203 /* Accumulate dimensions. Note: can't assume that it->descent > 0
26204 because this isn't true for images with `:ascent 100'. */
26205 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
26206 if (it
->area
== TEXT_AREA
)
26207 it
->current_x
+= it
->pixel_width
;
26209 if (extra_line_spacing
> 0)
26211 it
->descent
+= extra_line_spacing
;
26212 if (extra_line_spacing
> it
->max_extra_line_spacing
)
26213 it
->max_extra_line_spacing
= extra_line_spacing
;
26216 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
26217 it
->max_descent
= max (it
->max_descent
, it
->descent
);
26218 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
26219 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
26223 Output LEN glyphs starting at START at the nominal cursor position.
26224 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
26225 being updated, and UPDATED_AREA is the area of that row being updated. */
26228 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26229 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26231 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
26233 eassert (updated_row
);
26234 /* When the window is hscrolled, cursor hpos can legitimately be out
26235 of bounds, but we draw the cursor at the corresponding window
26236 margin in that case. */
26237 if (!updated_row
->reversed_p
&& chpos
< 0)
26239 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
26240 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
26244 /* Write glyphs. */
26246 hpos
= start
- updated_row
->glyphs
[updated_area
];
26247 x
= draw_glyphs (w
, w
->output_cursor
.x
,
26248 updated_row
, updated_area
,
26250 DRAW_NORMAL_TEXT
, 0);
26252 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
26253 if (updated_area
== TEXT_AREA
26254 && w
->phys_cursor_on_p
26255 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
26257 && chpos
< hpos
+ len
)
26258 w
->phys_cursor_on_p
= 0;
26262 /* Advance the output cursor. */
26263 w
->output_cursor
.hpos
+= len
;
26264 w
->output_cursor
.x
= x
;
26269 Insert LEN glyphs from START at the nominal cursor position. */
26272 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
26273 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
26276 int line_height
, shift_by_width
, shifted_region_width
;
26277 struct glyph_row
*row
;
26278 struct glyph
*glyph
;
26279 int frame_x
, frame_y
;
26282 eassert (updated_row
);
26284 f
= XFRAME (WINDOW_FRAME (w
));
26286 /* Get the height of the line we are in. */
26288 line_height
= row
->height
;
26290 /* Get the width of the glyphs to insert. */
26291 shift_by_width
= 0;
26292 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
26293 shift_by_width
+= glyph
->pixel_width
;
26295 /* Get the width of the region to shift right. */
26296 shifted_region_width
= (window_box_width (w
, updated_area
)
26297 - w
->output_cursor
.x
26301 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
26302 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
26304 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
26305 line_height
, shift_by_width
);
26307 /* Write the glyphs. */
26308 hpos
= start
- row
->glyphs
[updated_area
];
26309 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
26311 DRAW_NORMAL_TEXT
, 0);
26313 /* Advance the output cursor. */
26314 w
->output_cursor
.hpos
+= len
;
26315 w
->output_cursor
.x
+= shift_by_width
;
26321 Erase the current text line from the nominal cursor position
26322 (inclusive) to pixel column TO_X (exclusive). The idea is that
26323 everything from TO_X onward is already erased.
26325 TO_X is a pixel position relative to UPDATED_AREA of currently
26326 updated window W. TO_X == -1 means clear to the end of this area. */
26329 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
26330 enum glyph_row_area updated_area
, int to_x
)
26333 int max_x
, min_y
, max_y
;
26334 int from_x
, from_y
, to_y
;
26336 eassert (updated_row
);
26337 f
= XFRAME (w
->frame
);
26339 if (updated_row
->full_width_p
)
26340 max_x
= (WINDOW_PIXEL_WIDTH (w
)
26341 - (updated_row
->mode_line_p
? WINDOW_RIGHT_DIVIDER_WIDTH (w
) : 0));
26343 max_x
= window_box_width (w
, updated_area
);
26344 max_y
= window_text_bottom_y (w
);
26346 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
26347 of window. For TO_X > 0, truncate to end of drawing area. */
26353 to_x
= min (to_x
, max_x
);
26355 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
26357 /* Notice if the cursor will be cleared by this operation. */
26358 if (!updated_row
->full_width_p
)
26359 notice_overwritten_cursor (w
, updated_area
,
26360 w
->output_cursor
.x
, -1,
26362 MATRIX_ROW_BOTTOM_Y (updated_row
));
26364 from_x
= w
->output_cursor
.x
;
26366 /* Translate to frame coordinates. */
26367 if (updated_row
->full_width_p
)
26369 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
26370 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
26374 int area_left
= window_box_left (w
, updated_area
);
26375 from_x
+= area_left
;
26379 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
26380 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
26381 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
26383 /* Prevent inadvertently clearing to end of the X window. */
26384 if (to_x
> from_x
&& to_y
> from_y
)
26387 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
26388 to_x
- from_x
, to_y
- from_y
);
26393 #endif /* HAVE_WINDOW_SYSTEM */
26397 /***********************************************************************
26399 ***********************************************************************/
26401 /* Value is the internal representation of the specified cursor type
26402 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
26403 of the bar cursor. */
26405 static enum text_cursor_kinds
26406 get_specified_cursor_type (Lisp_Object arg
, int *width
)
26408 enum text_cursor_kinds type
;
26413 if (EQ (arg
, Qbox
))
26414 return FILLED_BOX_CURSOR
;
26416 if (EQ (arg
, Qhollow
))
26417 return HOLLOW_BOX_CURSOR
;
26419 if (EQ (arg
, Qbar
))
26426 && EQ (XCAR (arg
), Qbar
)
26427 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26429 *width
= XINT (XCDR (arg
));
26433 if (EQ (arg
, Qhbar
))
26436 return HBAR_CURSOR
;
26440 && EQ (XCAR (arg
), Qhbar
)
26441 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
26443 *width
= XINT (XCDR (arg
));
26444 return HBAR_CURSOR
;
26447 /* Treat anything unknown as "hollow box cursor".
26448 It was bad to signal an error; people have trouble fixing
26449 .Xdefaults with Emacs, when it has something bad in it. */
26450 type
= HOLLOW_BOX_CURSOR
;
26455 /* Set the default cursor types for specified frame. */
26457 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26462 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26463 FRAME_CURSOR_WIDTH (f
) = width
;
26465 /* By default, set up the blink-off state depending on the on-state. */
26467 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26470 FRAME_BLINK_OFF_CURSOR (f
)
26471 = get_specified_cursor_type (XCDR (tem
), &width
);
26472 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26475 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26477 /* Make sure the cursor gets redrawn. */
26478 f
->cursor_type_changed
= 1;
26482 #ifdef HAVE_WINDOW_SYSTEM
26484 /* Return the cursor we want to be displayed in window W. Return
26485 width of bar/hbar cursor through WIDTH arg. Return with
26486 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26487 (i.e. if the `system caret' should track this cursor).
26489 In a mini-buffer window, we want the cursor only to appear if we
26490 are reading input from this window. For the selected window, we
26491 want the cursor type given by the frame parameter or buffer local
26492 setting of cursor-type. If explicitly marked off, draw no cursor.
26493 In all other cases, we want a hollow box cursor. */
26495 static enum text_cursor_kinds
26496 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26497 int *active_cursor
)
26499 struct frame
*f
= XFRAME (w
->frame
);
26500 struct buffer
*b
= XBUFFER (w
->contents
);
26501 int cursor_type
= DEFAULT_CURSOR
;
26502 Lisp_Object alt_cursor
;
26503 int non_selected
= 0;
26505 *active_cursor
= 1;
26508 if (cursor_in_echo_area
26509 && FRAME_HAS_MINIBUF_P (f
)
26510 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26512 if (w
== XWINDOW (echo_area_window
))
26514 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26516 *width
= FRAME_CURSOR_WIDTH (f
);
26517 return FRAME_DESIRED_CURSOR (f
);
26520 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26523 *active_cursor
= 0;
26527 /* Detect a nonselected window or nonselected frame. */
26528 else if (w
!= XWINDOW (f
->selected_window
)
26529 || f
!= FRAME_DISPLAY_INFO (f
)->x_highlight_frame
)
26531 *active_cursor
= 0;
26533 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26539 /* Never display a cursor in a window in which cursor-type is nil. */
26540 if (NILP (BVAR (b
, cursor_type
)))
26543 /* Get the normal cursor type for this window. */
26544 if (EQ (BVAR (b
, cursor_type
), Qt
))
26546 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26547 *width
= FRAME_CURSOR_WIDTH (f
);
26550 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26552 /* Use cursor-in-non-selected-windows instead
26553 for non-selected window or frame. */
26556 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26557 if (!EQ (Qt
, alt_cursor
))
26558 return get_specified_cursor_type (alt_cursor
, width
);
26559 /* t means modify the normal cursor type. */
26560 if (cursor_type
== FILLED_BOX_CURSOR
)
26561 cursor_type
= HOLLOW_BOX_CURSOR
;
26562 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26564 return cursor_type
;
26567 /* Use normal cursor if not blinked off. */
26568 if (!w
->cursor_off_p
)
26570 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26572 if (cursor_type
== FILLED_BOX_CURSOR
)
26574 /* Using a block cursor on large images can be very annoying.
26575 So use a hollow cursor for "large" images.
26576 If image is not transparent (no mask), also use hollow cursor. */
26577 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26578 if (img
!= NULL
&& IMAGEP (img
->spec
))
26580 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26581 where N = size of default frame font size.
26582 This should cover most of the "tiny" icons people may use. */
26584 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26585 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26586 cursor_type
= HOLLOW_BOX_CURSOR
;
26589 else if (cursor_type
!= NO_CURSOR
)
26591 /* Display current only supports BOX and HOLLOW cursors for images.
26592 So for now, unconditionally use a HOLLOW cursor when cursor is
26593 not a solid box cursor. */
26594 cursor_type
= HOLLOW_BOX_CURSOR
;
26597 return cursor_type
;
26600 /* Cursor is blinked off, so determine how to "toggle" it. */
26602 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26603 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26604 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26606 /* Then see if frame has specified a specific blink off cursor type. */
26607 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26609 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26610 return FRAME_BLINK_OFF_CURSOR (f
);
26614 /* Some people liked having a permanently visible blinking cursor,
26615 while others had very strong opinions against it. So it was
26616 decided to remove it. KFS 2003-09-03 */
26618 /* Finally perform built-in cursor blinking:
26619 filled box <-> hollow box
26620 wide [h]bar <-> narrow [h]bar
26621 narrow [h]bar <-> no cursor
26622 other type <-> no cursor */
26624 if (cursor_type
== FILLED_BOX_CURSOR
)
26625 return HOLLOW_BOX_CURSOR
;
26627 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26630 return cursor_type
;
26638 /* Notice when the text cursor of window W has been completely
26639 overwritten by a drawing operation that outputs glyphs in AREA
26640 starting at X0 and ending at X1 in the line starting at Y0 and
26641 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26642 the rest of the line after X0 has been written. Y coordinates
26643 are window-relative. */
26646 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26647 int x0
, int x1
, int y0
, int y1
)
26649 int cx0
, cx1
, cy0
, cy1
;
26650 struct glyph_row
*row
;
26652 if (!w
->phys_cursor_on_p
)
26654 if (area
!= TEXT_AREA
)
26657 if (w
->phys_cursor
.vpos
< 0
26658 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26659 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26660 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26663 if (row
->cursor_in_fringe_p
)
26665 row
->cursor_in_fringe_p
= 0;
26666 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26667 w
->phys_cursor_on_p
= 0;
26671 cx0
= w
->phys_cursor
.x
;
26672 cx1
= cx0
+ w
->phys_cursor_width
;
26673 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26676 /* The cursor image will be completely removed from the
26677 screen if the output area intersects the cursor area in
26678 y-direction. When we draw in [y0 y1[, and some part of
26679 the cursor is at y < y0, that part must have been drawn
26680 before. When scrolling, the cursor is erased before
26681 actually scrolling, so we don't come here. When not
26682 scrolling, the rows above the old cursor row must have
26683 changed, and in this case these rows must have written
26684 over the cursor image.
26686 Likewise if part of the cursor is below y1, with the
26687 exception of the cursor being in the first blank row at
26688 the buffer and window end because update_text_area
26689 doesn't draw that row. (Except when it does, but
26690 that's handled in update_text_area.) */
26692 cy0
= w
->phys_cursor
.y
;
26693 cy1
= cy0
+ w
->phys_cursor_height
;
26694 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26697 w
->phys_cursor_on_p
= 0;
26700 #endif /* HAVE_WINDOW_SYSTEM */
26703 /************************************************************************
26705 ************************************************************************/
26707 #ifdef HAVE_WINDOW_SYSTEM
26710 Fix the display of area AREA of overlapping row ROW in window W
26711 with respect to the overlapping part OVERLAPS. */
26714 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26715 enum glyph_row_area area
, int overlaps
)
26722 for (i
= 0; i
< row
->used
[area
];)
26724 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26726 int start
= i
, start_x
= x
;
26730 x
+= row
->glyphs
[area
][i
].pixel_width
;
26733 while (i
< row
->used
[area
]
26734 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26736 draw_glyphs (w
, start_x
, row
, area
,
26738 DRAW_NORMAL_TEXT
, overlaps
);
26742 x
+= row
->glyphs
[area
][i
].pixel_width
;
26752 Draw the cursor glyph of window W in glyph row ROW. See the
26753 comment of draw_glyphs for the meaning of HL. */
26756 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26757 enum draw_glyphs_face hl
)
26759 /* If cursor hpos is out of bounds, don't draw garbage. This can
26760 happen in mini-buffer windows when switching between echo area
26761 glyphs and mini-buffer. */
26762 if ((row
->reversed_p
26763 ? (w
->phys_cursor
.hpos
>= 0)
26764 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26766 int on_p
= w
->phys_cursor_on_p
;
26768 int hpos
= w
->phys_cursor
.hpos
;
26770 /* When the window is hscrolled, cursor hpos can legitimately be
26771 out of bounds, but we draw the cursor at the corresponding
26772 window margin in that case. */
26773 if (!row
->reversed_p
&& hpos
< 0)
26775 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26776 hpos
= row
->used
[TEXT_AREA
] - 1;
26778 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26780 w
->phys_cursor_on_p
= on_p
;
26782 if (hl
== DRAW_CURSOR
)
26783 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26784 /* When we erase the cursor, and ROW is overlapped by other
26785 rows, make sure that these overlapping parts of other rows
26787 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26789 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26791 if (row
> w
->current_matrix
->rows
26792 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26793 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26794 OVERLAPS_ERASED_CURSOR
);
26796 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26797 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26798 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26799 OVERLAPS_ERASED_CURSOR
);
26805 /* Erase the image of a cursor of window W from the screen. */
26811 erase_phys_cursor (struct window
*w
)
26813 struct frame
*f
= XFRAME (w
->frame
);
26814 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26815 int hpos
= w
->phys_cursor
.hpos
;
26816 int vpos
= w
->phys_cursor
.vpos
;
26817 int mouse_face_here_p
= 0;
26818 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26819 struct glyph_row
*cursor_row
;
26820 struct glyph
*cursor_glyph
;
26821 enum draw_glyphs_face hl
;
26823 /* No cursor displayed or row invalidated => nothing to do on the
26825 if (w
->phys_cursor_type
== NO_CURSOR
)
26826 goto mark_cursor_off
;
26828 /* VPOS >= active_glyphs->nrows means that window has been resized.
26829 Don't bother to erase the cursor. */
26830 if (vpos
>= active_glyphs
->nrows
)
26831 goto mark_cursor_off
;
26833 /* If row containing cursor is marked invalid, there is nothing we
26835 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26836 if (!cursor_row
->enabled_p
)
26837 goto mark_cursor_off
;
26839 /* If line spacing is > 0, old cursor may only be partially visible in
26840 window after split-window. So adjust visible height. */
26841 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26842 window_text_bottom_y (w
) - cursor_row
->y
);
26844 /* If row is completely invisible, don't attempt to delete a cursor which
26845 isn't there. This can happen if cursor is at top of a window, and
26846 we switch to a buffer with a header line in that window. */
26847 if (cursor_row
->visible_height
<= 0)
26848 goto mark_cursor_off
;
26850 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26851 if (cursor_row
->cursor_in_fringe_p
)
26853 cursor_row
->cursor_in_fringe_p
= 0;
26854 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26855 goto mark_cursor_off
;
26858 /* This can happen when the new row is shorter than the old one.
26859 In this case, either draw_glyphs or clear_end_of_line
26860 should have cleared the cursor. Note that we wouldn't be
26861 able to erase the cursor in this case because we don't have a
26862 cursor glyph at hand. */
26863 if ((cursor_row
->reversed_p
26864 ? (w
->phys_cursor
.hpos
< 0)
26865 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26866 goto mark_cursor_off
;
26868 /* When the window is hscrolled, cursor hpos can legitimately be out
26869 of bounds, but we draw the cursor at the corresponding window
26870 margin in that case. */
26871 if (!cursor_row
->reversed_p
&& hpos
< 0)
26873 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26874 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26876 /* If the cursor is in the mouse face area, redisplay that when
26877 we clear the cursor. */
26878 if (! NILP (hlinfo
->mouse_face_window
)
26879 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26880 /* Don't redraw the cursor's spot in mouse face if it is at the
26881 end of a line (on a newline). The cursor appears there, but
26882 mouse highlighting does not. */
26883 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26884 mouse_face_here_p
= 1;
26886 /* Maybe clear the display under the cursor. */
26887 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26890 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26893 cursor_glyph
= get_phys_cursor_glyph (w
);
26894 if (cursor_glyph
== NULL
)
26895 goto mark_cursor_off
;
26897 width
= cursor_glyph
->pixel_width
;
26898 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26899 x
= w
->phys_cursor
.x
;
26901 width
-= left_x
- x
;
26902 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26903 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26904 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26907 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26910 /* Erase the cursor by redrawing the character underneath it. */
26911 if (mouse_face_here_p
)
26912 hl
= DRAW_MOUSE_FACE
;
26914 hl
= DRAW_NORMAL_TEXT
;
26915 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26918 w
->phys_cursor_on_p
= 0;
26919 w
->phys_cursor_type
= NO_CURSOR
;
26924 Display or clear cursor of window W. If ON is zero, clear the
26925 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26926 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26929 display_and_set_cursor (struct window
*w
, bool on
,
26930 int hpos
, int vpos
, int x
, int y
)
26932 struct frame
*f
= XFRAME (w
->frame
);
26933 int new_cursor_type
;
26934 int new_cursor_width
;
26936 struct glyph_row
*glyph_row
;
26937 struct glyph
*glyph
;
26939 /* This is pointless on invisible frames, and dangerous on garbaged
26940 windows and frames; in the latter case, the frame or window may
26941 be in the midst of changing its size, and x and y may be off the
26943 if (! FRAME_VISIBLE_P (f
)
26944 || FRAME_GARBAGED_P (f
)
26945 || vpos
>= w
->current_matrix
->nrows
26946 || hpos
>= w
->current_matrix
->matrix_w
)
26949 /* If cursor is off and we want it off, return quickly. */
26950 if (!on
&& !w
->phys_cursor_on_p
)
26953 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26954 /* If cursor row is not enabled, we don't really know where to
26955 display the cursor. */
26956 if (!glyph_row
->enabled_p
)
26958 w
->phys_cursor_on_p
= 0;
26963 if (!glyph_row
->exact_window_width_line_p
26964 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26965 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26967 eassert (input_blocked_p ());
26969 /* Set new_cursor_type to the cursor we want to be displayed. */
26970 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26971 &new_cursor_width
, &active_cursor
);
26973 /* If cursor is currently being shown and we don't want it to be or
26974 it is in the wrong place, or the cursor type is not what we want,
26976 if (w
->phys_cursor_on_p
26978 || w
->phys_cursor
.x
!= x
26979 || w
->phys_cursor
.y
!= y
26980 || new_cursor_type
!= w
->phys_cursor_type
26981 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26982 && new_cursor_width
!= w
->phys_cursor_width
)))
26983 erase_phys_cursor (w
);
26985 /* Don't check phys_cursor_on_p here because that flag is only set
26986 to zero in some cases where we know that the cursor has been
26987 completely erased, to avoid the extra work of erasing the cursor
26988 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26989 still not be visible, or it has only been partly erased. */
26992 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26993 w
->phys_cursor_height
= glyph_row
->height
;
26995 /* Set phys_cursor_.* before x_draw_.* is called because some
26996 of them may need the information. */
26997 w
->phys_cursor
.x
= x
;
26998 w
->phys_cursor
.y
= glyph_row
->y
;
26999 w
->phys_cursor
.hpos
= hpos
;
27000 w
->phys_cursor
.vpos
= vpos
;
27003 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
27004 new_cursor_type
, new_cursor_width
,
27005 on
, active_cursor
);
27009 /* Switch the display of W's cursor on or off, according to the value
27013 update_window_cursor (struct window
*w
, bool on
)
27015 /* Don't update cursor in windows whose frame is in the process
27016 of being deleted. */
27017 if (w
->current_matrix
)
27019 int hpos
= w
->phys_cursor
.hpos
;
27020 int vpos
= w
->phys_cursor
.vpos
;
27021 struct glyph_row
*row
;
27023 if (vpos
>= w
->current_matrix
->nrows
27024 || hpos
>= w
->current_matrix
->matrix_w
)
27027 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27029 /* When the window is hscrolled, cursor hpos can legitimately be
27030 out of bounds, but we draw the cursor at the corresponding
27031 window margin in that case. */
27032 if (!row
->reversed_p
&& hpos
< 0)
27034 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27035 hpos
= row
->used
[TEXT_AREA
] - 1;
27038 display_and_set_cursor (w
, on
, hpos
, vpos
,
27039 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27045 /* Call update_window_cursor with parameter ON_P on all leaf windows
27046 in the window tree rooted at W. */
27049 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
27053 if (WINDOWP (w
->contents
))
27054 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
27056 update_window_cursor (w
, on_p
);
27058 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
27064 Display the cursor on window W, or clear it, according to ON_P.
27065 Don't change the cursor's position. */
27068 x_update_cursor (struct frame
*f
, bool on_p
)
27070 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
27075 Clear the cursor of window W to background color, and mark the
27076 cursor as not shown. This is used when the text where the cursor
27077 is about to be rewritten. */
27080 x_clear_cursor (struct window
*w
)
27082 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
27083 update_window_cursor (w
, 0);
27086 #endif /* HAVE_WINDOW_SYSTEM */
27088 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
27091 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
27092 int start_hpos
, int end_hpos
,
27093 enum draw_glyphs_face draw
)
27095 #ifdef HAVE_WINDOW_SYSTEM
27096 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
27098 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
27102 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
27103 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
27107 /* Display the active region described by mouse_face_* according to DRAW. */
27110 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
27112 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
27113 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
27115 if (/* If window is in the process of being destroyed, don't bother
27117 w
->current_matrix
!= NULL
27118 /* Don't update mouse highlight if hidden */
27119 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
27120 /* Recognize when we are called to operate on rows that don't exist
27121 anymore. This can happen when a window is split. */
27122 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
27124 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
27125 struct glyph_row
*row
, *first
, *last
;
27127 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
27128 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
27130 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
27132 int start_hpos
, end_hpos
, start_x
;
27134 /* For all but the first row, the highlight starts at column 0. */
27137 /* R2L rows have BEG and END in reversed order, but the
27138 screen drawing geometry is always left to right. So
27139 we need to mirror the beginning and end of the
27140 highlighted area in R2L rows. */
27141 if (!row
->reversed_p
)
27143 start_hpos
= hlinfo
->mouse_face_beg_col
;
27144 start_x
= hlinfo
->mouse_face_beg_x
;
27146 else if (row
== last
)
27148 start_hpos
= hlinfo
->mouse_face_end_col
;
27149 start_x
= hlinfo
->mouse_face_end_x
;
27157 else if (row
->reversed_p
&& row
== last
)
27159 start_hpos
= hlinfo
->mouse_face_end_col
;
27160 start_x
= hlinfo
->mouse_face_end_x
;
27170 if (!row
->reversed_p
)
27171 end_hpos
= hlinfo
->mouse_face_end_col
;
27172 else if (row
== first
)
27173 end_hpos
= hlinfo
->mouse_face_beg_col
;
27176 end_hpos
= row
->used
[TEXT_AREA
];
27177 if (draw
== DRAW_NORMAL_TEXT
)
27178 row
->fill_line_p
= 1; /* Clear to end of line */
27181 else if (row
->reversed_p
&& row
== first
)
27182 end_hpos
= hlinfo
->mouse_face_beg_col
;
27185 end_hpos
= row
->used
[TEXT_AREA
];
27186 if (draw
== DRAW_NORMAL_TEXT
)
27187 row
->fill_line_p
= 1; /* Clear to end of line */
27190 if (end_hpos
> start_hpos
)
27192 draw_row_with_mouse_face (w
, start_x
, row
,
27193 start_hpos
, end_hpos
, draw
);
27196 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
27200 #ifdef HAVE_WINDOW_SYSTEM
27201 /* When we've written over the cursor, arrange for it to
27202 be displayed again. */
27203 if (FRAME_WINDOW_P (f
)
27204 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
27206 int hpos
= w
->phys_cursor
.hpos
;
27208 /* When the window is hscrolled, cursor hpos can legitimately be
27209 out of bounds, but we draw the cursor at the corresponding
27210 window margin in that case. */
27211 if (!row
->reversed_p
&& hpos
< 0)
27213 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27214 hpos
= row
->used
[TEXT_AREA
] - 1;
27217 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
27218 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
27221 #endif /* HAVE_WINDOW_SYSTEM */
27224 #ifdef HAVE_WINDOW_SYSTEM
27225 /* Change the mouse cursor. */
27226 if (FRAME_WINDOW_P (f
))
27228 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
27229 if (draw
== DRAW_NORMAL_TEXT
27230 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
27231 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
27234 if (draw
== DRAW_MOUSE_FACE
)
27235 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
27237 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
27239 #endif /* HAVE_WINDOW_SYSTEM */
27243 Clear out the mouse-highlighted active region.
27244 Redraw it un-highlighted first. Value is non-zero if mouse
27245 face was actually drawn unhighlighted. */
27248 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
27252 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
27254 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
27258 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
27259 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
27260 hlinfo
->mouse_face_window
= Qnil
;
27261 hlinfo
->mouse_face_overlay
= Qnil
;
27265 /* Return true if the coordinates HPOS and VPOS on windows W are
27266 within the mouse face on that window. */
27268 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
27270 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
27272 /* Quickly resolve the easy cases. */
27273 if (!(WINDOWP (hlinfo
->mouse_face_window
)
27274 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
27276 if (vpos
< hlinfo
->mouse_face_beg_row
27277 || vpos
> hlinfo
->mouse_face_end_row
)
27279 if (vpos
> hlinfo
->mouse_face_beg_row
27280 && vpos
< hlinfo
->mouse_face_end_row
)
27283 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
27285 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27287 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
27290 else if ((vpos
== hlinfo
->mouse_face_beg_row
27291 && hpos
>= hlinfo
->mouse_face_beg_col
)
27292 || (vpos
== hlinfo
->mouse_face_end_row
27293 && hpos
< hlinfo
->mouse_face_end_col
))
27298 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
27300 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
27303 else if ((vpos
== hlinfo
->mouse_face_beg_row
27304 && hpos
<= hlinfo
->mouse_face_beg_col
)
27305 || (vpos
== hlinfo
->mouse_face_end_row
27306 && hpos
> hlinfo
->mouse_face_end_col
))
27314 True if physical cursor of window W is within mouse face. */
27317 cursor_in_mouse_face_p (struct window
*w
)
27319 int hpos
= w
->phys_cursor
.hpos
;
27320 int vpos
= w
->phys_cursor
.vpos
;
27321 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
27323 /* When the window is hscrolled, cursor hpos can legitimately be out
27324 of bounds, but we draw the cursor at the corresponding window
27325 margin in that case. */
27326 if (!row
->reversed_p
&& hpos
< 0)
27328 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
27329 hpos
= row
->used
[TEXT_AREA
] - 1;
27331 return coords_in_mouse_face_p (w
, hpos
, vpos
);
27336 /* Find the glyph rows START_ROW and END_ROW of window W that display
27337 characters between buffer positions START_CHARPOS and END_CHARPOS
27338 (excluding END_CHARPOS). DISP_STRING is a display string that
27339 covers these buffer positions. This is similar to
27340 row_containing_pos, but is more accurate when bidi reordering makes
27341 buffer positions change non-linearly with glyph rows. */
27343 rows_from_pos_range (struct window
*w
,
27344 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
27345 Lisp_Object disp_string
,
27346 struct glyph_row
**start
, struct glyph_row
**end
)
27348 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27349 int last_y
= window_text_bottom_y (w
);
27350 struct glyph_row
*row
;
27355 while (!first
->enabled_p
27356 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
27359 /* Find the START row. */
27361 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
27364 /* A row can potentially be the START row if the range of the
27365 characters it displays intersects the range
27366 [START_CHARPOS..END_CHARPOS). */
27367 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
27368 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
27369 /* See the commentary in row_containing_pos, for the
27370 explanation of the complicated way to check whether
27371 some position is beyond the end of the characters
27372 displayed by a row. */
27373 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27374 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27375 && !row
->ends_at_zv_p
27376 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
27377 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
27378 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
27379 && !row
->ends_at_zv_p
27380 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
27382 /* Found a candidate row. Now make sure at least one of the
27383 glyphs it displays has a charpos from the range
27384 [START_CHARPOS..END_CHARPOS).
27386 This is not obvious because bidi reordering could make
27387 buffer positions of a row be 1,2,3,102,101,100, and if we
27388 want to highlight characters in [50..60), we don't want
27389 this row, even though [50..60) does intersect [1..103),
27390 the range of character positions given by the row's start
27391 and end positions. */
27392 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
27393 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
27397 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27398 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27399 /* A glyph that comes from DISP_STRING is by
27400 definition to be highlighted. */
27401 || EQ (g
->object
, disp_string
))
27410 /* Find the END row. */
27412 /* If the last row is partially visible, start looking for END
27413 from that row, instead of starting from FIRST. */
27414 && !(row
->enabled_p
27415 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
27417 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
27419 struct glyph_row
*next
= row
+ 1;
27420 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
27422 if (!next
->enabled_p
27423 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
27424 /* The first row >= START whose range of displayed characters
27425 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
27426 is the row END + 1. */
27427 || (start_charpos
< next_start
27428 && end_charpos
< next_start
)
27429 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27430 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27431 && !next
->ends_at_zv_p
27432 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
27433 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
27434 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
27435 && !next
->ends_at_zv_p
27436 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
27443 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
27444 but none of the characters it displays are in the range, it is
27446 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
27447 struct glyph
*s
= g
;
27448 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
27452 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
27453 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
27454 /* If the buffer position of the first glyph in
27455 the row is equal to END_CHARPOS, it means
27456 the last character to be highlighted is the
27457 newline of ROW, and we must consider NEXT as
27459 || (((!next
->reversed_p
&& g
== s
)
27460 || (next
->reversed_p
&& g
== e
- 1))
27461 && (g
->charpos
== end_charpos
27462 /* Special case for when NEXT is an
27463 empty line at ZV. */
27464 || (g
->charpos
== -1
27465 && !row
->ends_at_zv_p
27466 && next_start
== end_charpos
)))))
27467 /* A glyph that comes from DISP_STRING is by
27468 definition to be highlighted. */
27469 || EQ (g
->object
, disp_string
))
27478 /* The first row that ends at ZV must be the last to be
27480 else if (next
->ends_at_zv_p
)
27489 /* This function sets the mouse_face_* elements of HLINFO, assuming
27490 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27491 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27492 for the overlay or run of text properties specifying the mouse
27493 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27494 before-string and after-string that must also be highlighted.
27495 DISP_STRING, if non-nil, is a display string that may cover some
27496 or all of the highlighted text. */
27499 mouse_face_from_buffer_pos (Lisp_Object window
,
27500 Mouse_HLInfo
*hlinfo
,
27501 ptrdiff_t mouse_charpos
,
27502 ptrdiff_t start_charpos
,
27503 ptrdiff_t end_charpos
,
27504 Lisp_Object before_string
,
27505 Lisp_Object after_string
,
27506 Lisp_Object disp_string
)
27508 struct window
*w
= XWINDOW (window
);
27509 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27510 struct glyph_row
*r1
, *r2
;
27511 struct glyph
*glyph
, *end
;
27512 ptrdiff_t ignore
, pos
;
27515 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27516 eassert (NILP (before_string
) || STRINGP (before_string
));
27517 eassert (NILP (after_string
) || STRINGP (after_string
));
27519 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27520 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27522 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27523 /* If the before-string or display-string contains newlines,
27524 rows_from_pos_range skips to its last row. Move back. */
27525 if (!NILP (before_string
) || !NILP (disp_string
))
27527 struct glyph_row
*prev
;
27528 while ((prev
= r1
- 1, prev
>= first
)
27529 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27530 && prev
->used
[TEXT_AREA
] > 0)
27532 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27533 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27534 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27536 || !(EQ (glyph
->object
, before_string
)
27537 || EQ (glyph
->object
, disp_string
)))
27544 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27545 hlinfo
->mouse_face_past_end
= 1;
27547 else if (!NILP (after_string
))
27549 /* If the after-string has newlines, advance to its last row. */
27550 struct glyph_row
*next
;
27551 struct glyph_row
*last
27552 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27554 for (next
= r2
+ 1;
27556 && next
->used
[TEXT_AREA
] > 0
27557 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27561 /* The rest of the display engine assumes that mouse_face_beg_row is
27562 either above mouse_face_end_row or identical to it. But with
27563 bidi-reordered continued lines, the row for START_CHARPOS could
27564 be below the row for END_CHARPOS. If so, swap the rows and store
27565 them in correct order. */
27568 struct glyph_row
*tem
= r2
;
27574 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27575 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27577 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27578 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27579 could be anywhere in the row and in any order. The strategy
27580 below is to find the leftmost and the rightmost glyph that
27581 belongs to either of these 3 strings, or whose position is
27582 between START_CHARPOS and END_CHARPOS, and highlight all the
27583 glyphs between those two. This may cover more than just the text
27584 between START_CHARPOS and END_CHARPOS if the range of characters
27585 strides the bidi level boundary, e.g. if the beginning is in R2L
27586 text while the end is in L2R text or vice versa. */
27587 if (!r1
->reversed_p
)
27589 /* This row is in a left to right paragraph. Scan it left to
27591 glyph
= r1
->glyphs
[TEXT_AREA
];
27592 end
= glyph
+ r1
->used
[TEXT_AREA
];
27595 /* Skip truncation glyphs at the start of the glyph row. */
27596 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27598 && INTEGERP (glyph
->object
)
27599 && glyph
->charpos
< 0;
27601 x
+= glyph
->pixel_width
;
27603 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27604 or DISP_STRING, and the first glyph from buffer whose
27605 position is between START_CHARPOS and END_CHARPOS. */
27607 && !INTEGERP (glyph
->object
)
27608 && !EQ (glyph
->object
, disp_string
)
27609 && !(BUFFERP (glyph
->object
)
27610 && (glyph
->charpos
>= start_charpos
27611 && glyph
->charpos
< end_charpos
));
27614 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27615 are present at buffer positions between START_CHARPOS and
27616 END_CHARPOS, or if they come from an overlay. */
27617 if (EQ (glyph
->object
, before_string
))
27619 pos
= string_buffer_position (before_string
,
27621 /* If pos == 0, it means before_string came from an
27622 overlay, not from a buffer position. */
27623 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27626 else if (EQ (glyph
->object
, after_string
))
27628 pos
= string_buffer_position (after_string
, end_charpos
);
27629 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27632 x
+= glyph
->pixel_width
;
27634 hlinfo
->mouse_face_beg_x
= x
;
27635 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27639 /* This row is in a right to left paragraph. Scan it right to
27643 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27644 glyph
= end
+ r1
->used
[TEXT_AREA
];
27646 /* Skip truncation glyphs at the start of the glyph row. */
27647 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27649 && INTEGERP (glyph
->object
)
27650 && glyph
->charpos
< 0;
27654 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27655 or DISP_STRING, and the first glyph from buffer whose
27656 position is between START_CHARPOS and END_CHARPOS. */
27658 && !INTEGERP (glyph
->object
)
27659 && !EQ (glyph
->object
, disp_string
)
27660 && !(BUFFERP (glyph
->object
)
27661 && (glyph
->charpos
>= start_charpos
27662 && glyph
->charpos
< end_charpos
));
27665 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27666 are present at buffer positions between START_CHARPOS and
27667 END_CHARPOS, or if they come from an overlay. */
27668 if (EQ (glyph
->object
, before_string
))
27670 pos
= string_buffer_position (before_string
, start_charpos
);
27671 /* If pos == 0, it means before_string came from an
27672 overlay, not from a buffer position. */
27673 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27676 else if (EQ (glyph
->object
, after_string
))
27678 pos
= string_buffer_position (after_string
, end_charpos
);
27679 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27684 glyph
++; /* first glyph to the right of the highlighted area */
27685 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27686 x
+= g
->pixel_width
;
27687 hlinfo
->mouse_face_beg_x
= x
;
27688 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27691 /* If the highlight ends in a different row, compute GLYPH and END
27692 for the end row. Otherwise, reuse the values computed above for
27693 the row where the highlight begins. */
27696 if (!r2
->reversed_p
)
27698 glyph
= r2
->glyphs
[TEXT_AREA
];
27699 end
= glyph
+ r2
->used
[TEXT_AREA
];
27704 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27705 glyph
= end
+ r2
->used
[TEXT_AREA
];
27709 if (!r2
->reversed_p
)
27711 /* Skip truncation and continuation glyphs near the end of the
27712 row, and also blanks and stretch glyphs inserted by
27713 extend_face_to_end_of_line. */
27715 && INTEGERP ((end
- 1)->object
))
27717 /* Scan the rest of the glyph row from the end, looking for the
27718 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27719 DISP_STRING, or whose position is between START_CHARPOS
27723 && !INTEGERP (end
->object
)
27724 && !EQ (end
->object
, disp_string
)
27725 && !(BUFFERP (end
->object
)
27726 && (end
->charpos
>= start_charpos
27727 && end
->charpos
< end_charpos
));
27730 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27731 are present at buffer positions between START_CHARPOS and
27732 END_CHARPOS, or if they come from an overlay. */
27733 if (EQ (end
->object
, before_string
))
27735 pos
= string_buffer_position (before_string
, start_charpos
);
27736 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27739 else if (EQ (end
->object
, after_string
))
27741 pos
= string_buffer_position (after_string
, end_charpos
);
27742 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27746 /* Find the X coordinate of the last glyph to be highlighted. */
27747 for (; glyph
<= end
; ++glyph
)
27748 x
+= glyph
->pixel_width
;
27750 hlinfo
->mouse_face_end_x
= x
;
27751 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27755 /* Skip truncation and continuation glyphs near the end of the
27756 row, and also blanks and stretch glyphs inserted by
27757 extend_face_to_end_of_line. */
27761 && INTEGERP (end
->object
))
27763 x
+= end
->pixel_width
;
27766 /* Scan the rest of the glyph row from the end, looking for the
27767 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27768 DISP_STRING, or whose position is between START_CHARPOS
27772 && !INTEGERP (end
->object
)
27773 && !EQ (end
->object
, disp_string
)
27774 && !(BUFFERP (end
->object
)
27775 && (end
->charpos
>= start_charpos
27776 && end
->charpos
< end_charpos
));
27779 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27780 are present at buffer positions between START_CHARPOS and
27781 END_CHARPOS, or if they come from an overlay. */
27782 if (EQ (end
->object
, before_string
))
27784 pos
= string_buffer_position (before_string
, start_charpos
);
27785 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27788 else if (EQ (end
->object
, after_string
))
27790 pos
= string_buffer_position (after_string
, end_charpos
);
27791 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27794 x
+= end
->pixel_width
;
27796 /* If we exited the above loop because we arrived at the last
27797 glyph of the row, and its buffer position is still not in
27798 range, it means the last character in range is the preceding
27799 newline. Bump the end column and x values to get past the
27802 && BUFFERP (end
->object
)
27803 && (end
->charpos
< start_charpos
27804 || end
->charpos
>= end_charpos
))
27806 x
+= end
->pixel_width
;
27809 hlinfo
->mouse_face_end_x
= x
;
27810 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27813 hlinfo
->mouse_face_window
= window
;
27814 hlinfo
->mouse_face_face_id
27815 = face_at_buffer_position (w
, mouse_charpos
, &ignore
,
27817 !hlinfo
->mouse_face_hidden
, -1);
27818 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27821 /* The following function is not used anymore (replaced with
27822 mouse_face_from_string_pos), but I leave it here for the time
27823 being, in case someone would. */
27825 #if 0 /* not used */
27827 /* Find the position of the glyph for position POS in OBJECT in
27828 window W's current matrix, and return in *X, *Y the pixel
27829 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27831 RIGHT_P non-zero means return the position of the right edge of the
27832 glyph, RIGHT_P zero means return the left edge position.
27834 If no glyph for POS exists in the matrix, return the position of
27835 the glyph with the next smaller position that is in the matrix, if
27836 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27837 exists in the matrix, return the position of the glyph with the
27838 next larger position in OBJECT.
27840 Value is non-zero if a glyph was found. */
27843 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27844 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27846 int yb
= window_text_bottom_y (w
);
27847 struct glyph_row
*r
;
27848 struct glyph
*best_glyph
= NULL
;
27849 struct glyph_row
*best_row
= NULL
;
27852 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27853 r
->enabled_p
&& r
->y
< yb
;
27856 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27857 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27860 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27861 if (EQ (g
->object
, object
))
27863 if (g
->charpos
== pos
)
27870 else if (best_glyph
== NULL
27871 || ((eabs (g
->charpos
- pos
)
27872 < eabs (best_glyph
->charpos
- pos
))
27875 : g
->charpos
> pos
)))
27889 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27893 *x
+= best_glyph
->pixel_width
;
27898 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27901 return best_glyph
!= NULL
;
27903 #endif /* not used */
27905 /* Find the positions of the first and the last glyphs in window W's
27906 current matrix that occlude positions [STARTPOS..ENDPOS) in OBJECT
27907 (assumed to be a string), and return in HLINFO's mouse_face_*
27908 members the pixel and column/row coordinates of those glyphs. */
27911 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27912 Lisp_Object object
,
27913 ptrdiff_t startpos
, ptrdiff_t endpos
)
27915 int yb
= window_text_bottom_y (w
);
27916 struct glyph_row
*r
;
27917 struct glyph
*g
, *e
;
27921 /* Find the glyph row with at least one position in the range
27922 [STARTPOS..ENDPOS), and the first glyph in that row whose
27923 position belongs to that range. */
27924 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27925 r
->enabled_p
&& r
->y
< yb
;
27928 if (!r
->reversed_p
)
27930 g
= r
->glyphs
[TEXT_AREA
];
27931 e
= g
+ r
->used
[TEXT_AREA
];
27932 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27933 if (EQ (g
->object
, object
)
27934 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27936 hlinfo
->mouse_face_beg_row
27937 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27938 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27939 hlinfo
->mouse_face_beg_x
= gx
;
27948 e
= r
->glyphs
[TEXT_AREA
];
27949 g
= e
+ r
->used
[TEXT_AREA
];
27950 for ( ; g
> e
; --g
)
27951 if (EQ ((g
-1)->object
, object
)
27952 && startpos
<= (g
-1)->charpos
&& (g
-1)->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 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27958 gx
+= g1
->pixel_width
;
27959 hlinfo
->mouse_face_beg_x
= gx
;
27971 /* Starting with the next row, look for the first row which does NOT
27972 include any glyphs whose positions are in the range. */
27973 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27975 g
= r
->glyphs
[TEXT_AREA
];
27976 e
= g
+ r
->used
[TEXT_AREA
];
27978 for ( ; g
< e
; ++g
)
27979 if (EQ (g
->object
, object
)
27980 && startpos
<= g
->charpos
&& g
->charpos
< endpos
)
27989 /* The highlighted region ends on the previous row. */
27992 /* Set the end row. */
27993 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27995 /* Compute and set the end column and the end column's horizontal
27996 pixel coordinate. */
27997 if (!r
->reversed_p
)
27999 g
= r
->glyphs
[TEXT_AREA
];
28000 e
= g
+ r
->used
[TEXT_AREA
];
28001 for ( ; e
> g
; --e
)
28002 if (EQ ((e
-1)->object
, object
)
28003 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
< endpos
)
28005 hlinfo
->mouse_face_end_col
= e
- g
;
28007 for (gx
= r
->x
; g
< e
; ++g
)
28008 gx
+= g
->pixel_width
;
28009 hlinfo
->mouse_face_end_x
= gx
;
28013 e
= r
->glyphs
[TEXT_AREA
];
28014 g
= e
+ r
->used
[TEXT_AREA
];
28015 for (gx
= r
->x
; e
< g
; ++e
)
28017 if (EQ (e
->object
, object
)
28018 && startpos
<= e
->charpos
&& e
->charpos
< endpos
)
28020 gx
+= e
->pixel_width
;
28022 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
28023 hlinfo
->mouse_face_end_x
= gx
;
28027 #ifdef HAVE_WINDOW_SYSTEM
28029 /* See if position X, Y is within a hot-spot of an image. */
28032 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
28034 if (!CONSP (hot_spot
))
28037 if (EQ (XCAR (hot_spot
), Qrect
))
28039 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
28040 Lisp_Object rect
= XCDR (hot_spot
);
28044 if (!CONSP (XCAR (rect
)))
28046 if (!CONSP (XCDR (rect
)))
28048 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
28050 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
28052 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
28054 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
28058 else if (EQ (XCAR (hot_spot
), Qcircle
))
28060 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
28061 Lisp_Object circ
= XCDR (hot_spot
);
28062 Lisp_Object lr
, lx0
, ly0
;
28064 && CONSP (XCAR (circ
))
28065 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
28066 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
28067 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
28069 double r
= XFLOATINT (lr
);
28070 double dx
= XINT (lx0
) - x
;
28071 double dy
= XINT (ly0
) - y
;
28072 return (dx
* dx
+ dy
* dy
<= r
* r
);
28075 else if (EQ (XCAR (hot_spot
), Qpoly
))
28077 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
28078 if (VECTORP (XCDR (hot_spot
)))
28080 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
28081 Lisp_Object
*poly
= v
->contents
;
28082 ptrdiff_t n
= v
->header
.size
;
28085 Lisp_Object lx
, ly
;
28088 /* Need an even number of coordinates, and at least 3 edges. */
28089 if (n
< 6 || n
& 1)
28092 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
28093 If count is odd, we are inside polygon. Pixels on edges
28094 may or may not be included depending on actual geometry of the
28096 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
28097 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
28099 x0
= XINT (lx
), y0
= XINT (ly
);
28100 for (i
= 0; i
< n
; i
+= 2)
28102 int x1
= x0
, y1
= y0
;
28103 if ((lx
= poly
[i
], !INTEGERP (lx
))
28104 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
28106 x0
= XINT (lx
), y0
= XINT (ly
);
28108 /* Does this segment cross the X line? */
28116 if (y
> y0
&& y
> y1
)
28118 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
28128 find_hot_spot (Lisp_Object map
, int x
, int y
)
28130 while (CONSP (map
))
28132 if (CONSP (XCAR (map
))
28133 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
28141 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
28143 doc
: /* Lookup in image map MAP coordinates X and Y.
28144 An image map is an alist where each element has the format (AREA ID PLIST).
28145 An AREA is specified as either a rectangle, a circle, or a polygon:
28146 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
28147 pixel coordinates of the upper left and bottom right corners.
28148 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
28149 and the radius of the circle; r may be a float or integer.
28150 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
28151 vector describes one corner in the polygon.
28152 Returns the alist element for the first matching AREA in MAP. */)
28153 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
28161 return find_hot_spot (map
,
28162 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
28163 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
28167 /* Display frame CURSOR, optionally using shape defined by POINTER. */
28169 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
28171 /* Do not change cursor shape while dragging mouse. */
28172 if (!NILP (do_mouse_tracking
))
28175 if (!NILP (pointer
))
28177 if (EQ (pointer
, Qarrow
))
28178 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28179 else if (EQ (pointer
, Qhand
))
28180 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
28181 else if (EQ (pointer
, Qtext
))
28182 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28183 else if (EQ (pointer
, intern ("hdrag")))
28184 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28185 else if (EQ (pointer
, intern ("nhdrag")))
28186 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28187 #ifdef HAVE_X_WINDOWS
28188 else if (EQ (pointer
, intern ("vdrag")))
28189 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28191 else if (EQ (pointer
, intern ("hourglass")))
28192 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
28193 else if (EQ (pointer
, Qmodeline
))
28194 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
28196 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28199 if (cursor
!= No_Cursor
)
28200 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
28203 #endif /* HAVE_WINDOW_SYSTEM */
28205 /* Take proper action when mouse has moved to the mode or header line
28206 or marginal area AREA of window W, x-position X and y-position Y.
28207 X is relative to the start of the text display area of W, so the
28208 width of bitmap areas and scroll bars must be subtracted to get a
28209 position relative to the start of the mode line. */
28212 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
28213 enum window_part area
)
28215 struct window
*w
= XWINDOW (window
);
28216 struct frame
*f
= XFRAME (w
->frame
);
28217 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28218 #ifdef HAVE_WINDOW_SYSTEM
28219 Display_Info
*dpyinfo
;
28221 Cursor cursor
= No_Cursor
;
28222 Lisp_Object pointer
= Qnil
;
28223 int dx
, dy
, width
, height
;
28225 Lisp_Object string
, object
= Qnil
;
28226 Lisp_Object pos
IF_LINT (= Qnil
), help
;
28228 Lisp_Object mouse_face
;
28229 int original_x_pixel
= x
;
28230 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
28231 struct glyph_row
*row
IF_LINT (= 0);
28233 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
28238 /* Kludge alert: mode_line_string takes X/Y in pixels, but
28239 returns them in row/column units! */
28240 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
28241 &object
, &dx
, &dy
, &width
, &height
);
28243 row
= (area
== ON_MODE_LINE
28244 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
28245 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
28247 /* Find the glyph under the mouse pointer. */
28248 if (row
->mode_line_p
&& row
->enabled_p
)
28250 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
28251 end
= glyph
+ row
->used
[TEXT_AREA
];
28253 for (x0
= original_x_pixel
;
28254 glyph
< end
&& x0
>= glyph
->pixel_width
;
28256 x0
-= glyph
->pixel_width
;
28264 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
28265 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
28266 returns them in row/column units! */
28267 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
28268 &object
, &dx
, &dy
, &width
, &height
);
28273 #ifdef HAVE_WINDOW_SYSTEM
28274 if (IMAGEP (object
))
28276 Lisp_Object image_map
, hotspot
;
28277 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
28279 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
28281 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28285 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
28286 If so, we could look for mouse-enter, mouse-leave
28287 properties in PLIST (and do something...). */
28288 hotspot
= XCDR (hotspot
);
28289 if (CONSP (hotspot
)
28290 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28292 pointer
= Fplist_get (plist
, Qpointer
);
28293 if (NILP (pointer
))
28295 help
= Fplist_get (plist
, Qhelp_echo
);
28298 help_echo_string
= help
;
28299 XSETWINDOW (help_echo_window
, w
);
28300 help_echo_object
= w
->contents
;
28301 help_echo_pos
= charpos
;
28305 if (NILP (pointer
))
28306 pointer
= Fplist_get (XCDR (object
), QCpointer
);
28308 #endif /* HAVE_WINDOW_SYSTEM */
28310 if (STRINGP (string
))
28311 pos
= make_number (charpos
);
28313 /* Set the help text and mouse pointer. If the mouse is on a part
28314 of the mode line without any text (e.g. past the right edge of
28315 the mode line text), use the default help text and pointer. */
28316 if (STRINGP (string
) || area
== ON_MODE_LINE
)
28318 /* Arrange to display the help by setting the global variables
28319 help_echo_string, help_echo_object, and help_echo_pos. */
28322 if (STRINGP (string
))
28323 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
28327 help_echo_string
= help
;
28328 XSETWINDOW (help_echo_window
, w
);
28329 help_echo_object
= string
;
28330 help_echo_pos
= charpos
;
28332 else if (area
== ON_MODE_LINE
)
28334 Lisp_Object default_help
28335 = buffer_local_value_1 (Qmode_line_default_help_echo
,
28338 if (STRINGP (default_help
))
28340 help_echo_string
= default_help
;
28341 XSETWINDOW (help_echo_window
, w
);
28342 help_echo_object
= Qnil
;
28343 help_echo_pos
= -1;
28348 #ifdef HAVE_WINDOW_SYSTEM
28349 /* Change the mouse pointer according to what is under it. */
28350 if (FRAME_WINDOW_P (f
))
28352 dpyinfo
= FRAME_DISPLAY_INFO (f
);
28353 if (STRINGP (string
))
28355 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28357 if (NILP (pointer
))
28358 pointer
= Fget_text_property (pos
, Qpointer
, string
);
28360 /* Change the mouse pointer according to what is under X/Y. */
28362 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
28365 map
= Fget_text_property (pos
, Qlocal_map
, string
);
28366 if (!KEYMAPP (map
))
28367 map
= Fget_text_property (pos
, Qkeymap
, string
);
28368 if (!KEYMAPP (map
))
28369 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
28373 /* Default mode-line pointer. */
28374 cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
28379 /* Change the mouse face according to what is under X/Y. */
28380 if (STRINGP (string
))
28382 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
28383 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
28384 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28389 struct glyph
* tmp_glyph
;
28393 int total_pixel_width
;
28394 ptrdiff_t begpos
, endpos
, ignore
;
28398 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
28399 Qmouse_face
, string
, Qnil
);
28405 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
28407 endpos
= SCHARS (string
);
28411 /* Calculate the glyph position GPOS of GLYPH in the
28412 displayed string, relative to the beginning of the
28413 highlighted part of the string.
28415 Note: GPOS is different from CHARPOS. CHARPOS is the
28416 position of GLYPH in the internal string object. A mode
28417 line string format has structures which are converted to
28418 a flattened string by the Emacs Lisp interpreter. The
28419 internal string is an element of those structures. The
28420 displayed string is the flattened string. */
28421 tmp_glyph
= row_start_glyph
;
28422 while (tmp_glyph
< glyph
28423 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28424 && begpos
<= tmp_glyph
->charpos
28425 && tmp_glyph
->charpos
< endpos
)))
28427 gpos
= glyph
- tmp_glyph
;
28429 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
28430 the highlighted part of the displayed string to which
28431 GLYPH belongs. Note: GSEQ_LENGTH is different from
28432 SCHARS (STRING), because the latter returns the length of
28433 the internal string. */
28434 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
28436 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
28437 && begpos
<= tmp_glyph
->charpos
28438 && tmp_glyph
->charpos
< endpos
));
28441 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
28443 /* Calculate the total pixel width of all the glyphs between
28444 the beginning of the highlighted area and GLYPH. */
28445 total_pixel_width
= 0;
28446 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
28447 total_pixel_width
+= tmp_glyph
->pixel_width
;
28449 /* Pre calculation of re-rendering position. Note: X is in
28450 column units here, after the call to mode_line_string or
28451 marginal_area_string. */
28453 vpos
= (area
== ON_MODE_LINE
28454 ? (w
->current_matrix
)->nrows
- 1
28457 /* If GLYPH's position is included in the region that is
28458 already drawn in mouse face, we have nothing to do. */
28459 if ( EQ (window
, hlinfo
->mouse_face_window
)
28460 && (!row
->reversed_p
28461 ? (hlinfo
->mouse_face_beg_col
<= hpos
28462 && hpos
< hlinfo
->mouse_face_end_col
)
28463 /* In R2L rows we swap BEG and END, see below. */
28464 : (hlinfo
->mouse_face_end_col
<= hpos
28465 && hpos
< hlinfo
->mouse_face_beg_col
))
28466 && hlinfo
->mouse_face_beg_row
== vpos
)
28469 if (clear_mouse_face (hlinfo
))
28470 cursor
= No_Cursor
;
28472 if (!row
->reversed_p
)
28474 hlinfo
->mouse_face_beg_col
= hpos
;
28475 hlinfo
->mouse_face_beg_x
= original_x_pixel
28476 - (total_pixel_width
+ dx
);
28477 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28478 hlinfo
->mouse_face_end_x
= 0;
28482 /* In R2L rows, show_mouse_face expects BEG and END
28483 coordinates to be swapped. */
28484 hlinfo
->mouse_face_end_col
= hpos
;
28485 hlinfo
->mouse_face_end_x
= original_x_pixel
28486 - (total_pixel_width
+ dx
);
28487 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28488 hlinfo
->mouse_face_beg_x
= 0;
28491 hlinfo
->mouse_face_beg_row
= vpos
;
28492 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28493 hlinfo
->mouse_face_past_end
= 0;
28494 hlinfo
->mouse_face_window
= window
;
28496 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28501 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28503 if (NILP (pointer
))
28506 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28507 clear_mouse_face (hlinfo
);
28509 #ifdef HAVE_WINDOW_SYSTEM
28510 if (FRAME_WINDOW_P (f
))
28511 define_frame_cursor1 (f
, cursor
, pointer
);
28517 Take proper action when the mouse has moved to position X, Y on
28518 frame F with regards to highlighting portions of display that have
28519 mouse-face properties. Also de-highlight portions of display where
28520 the mouse was before, set the mouse pointer shape as appropriate
28521 for the mouse coordinates, and activate help echo (tooltips).
28522 X and Y can be negative or out of range. */
28525 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28527 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28528 enum window_part part
= ON_NOTHING
;
28529 Lisp_Object window
;
28531 Cursor cursor
= No_Cursor
;
28532 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28535 /* When a menu is active, don't highlight because this looks odd. */
28536 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28537 if (popup_activated ())
28541 if (!f
->glyphs_initialized_p
28542 || f
->pointer_invisible
)
28545 hlinfo
->mouse_face_mouse_x
= x
;
28546 hlinfo
->mouse_face_mouse_y
= y
;
28547 hlinfo
->mouse_face_mouse_frame
= f
;
28549 if (hlinfo
->mouse_face_defer
)
28552 /* Which window is that in? */
28553 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28555 /* If displaying active text in another window, clear that. */
28556 if (! EQ (window
, hlinfo
->mouse_face_window
)
28557 /* Also clear if we move out of text area in same window. */
28558 || (!NILP (hlinfo
->mouse_face_window
)
28561 && part
!= ON_MODE_LINE
28562 && part
!= ON_HEADER_LINE
))
28563 clear_mouse_face (hlinfo
);
28565 /* Not on a window -> return. */
28566 if (!WINDOWP (window
))
28569 /* Reset help_echo_string. It will get recomputed below. */
28570 help_echo_string
= Qnil
;
28572 /* Convert to window-relative pixel coordinates. */
28573 w
= XWINDOW (window
);
28574 frame_to_window_pixel_xy (w
, &x
, &y
);
28576 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
28577 /* Handle tool-bar window differently since it doesn't display a
28579 if (EQ (window
, f
->tool_bar_window
))
28581 note_tool_bar_highlight (f
, x
, y
);
28586 /* Mouse is on the mode, header line or margin? */
28587 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28588 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28590 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28592 #ifdef HAVE_WINDOW_SYSTEM
28593 if (part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28595 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28596 /* Show non-text cursor (Bug#16647). */
28604 #ifdef HAVE_WINDOW_SYSTEM
28605 if (part
== ON_VERTICAL_BORDER
)
28607 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28608 help_echo_string
= build_string ("drag-mouse-1: resize");
28610 else if (part
== ON_RIGHT_DIVIDER
)
28612 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28613 help_echo_string
= build_string ("drag-mouse-1: resize");
28615 else if (part
== ON_BOTTOM_DIVIDER
)
28617 cursor
= FRAME_X_OUTPUT (f
)->vertical_drag_cursor
;
28618 help_echo_string
= build_string ("drag-mouse-1: resize");
28620 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28621 || part
== ON_SCROLL_BAR
)
28622 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28624 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28627 /* Are we in a window whose display is up to date?
28628 And verify the buffer's text has not changed. */
28629 b
= XBUFFER (w
->contents
);
28630 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28632 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28634 struct glyph
*glyph
;
28635 Lisp_Object object
;
28636 Lisp_Object mouse_face
= Qnil
, position
;
28637 Lisp_Object
*overlay_vec
= NULL
;
28638 ptrdiff_t i
, noverlays
;
28639 struct buffer
*obuf
;
28640 ptrdiff_t obegv
, ozv
;
28643 /* Find the glyph under X/Y. */
28644 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28646 #ifdef HAVE_WINDOW_SYSTEM
28647 /* Look for :pointer property on image. */
28648 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28650 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28651 if (img
!= NULL
&& IMAGEP (img
->spec
))
28653 Lisp_Object image_map
, hotspot
;
28654 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28656 && (hotspot
= find_hot_spot (image_map
,
28657 glyph
->slice
.img
.x
+ dx
,
28658 glyph
->slice
.img
.y
+ dy
),
28660 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28664 /* Could check XCAR (hotspot) to see if we enter/leave
28666 If so, we could look for mouse-enter, mouse-leave
28667 properties in PLIST (and do something...). */
28668 hotspot
= XCDR (hotspot
);
28669 if (CONSP (hotspot
)
28670 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28672 pointer
= Fplist_get (plist
, Qpointer
);
28673 if (NILP (pointer
))
28675 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28676 if (!NILP (help_echo_string
))
28678 help_echo_window
= window
;
28679 help_echo_object
= glyph
->object
;
28680 help_echo_pos
= glyph
->charpos
;
28684 if (NILP (pointer
))
28685 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28688 #endif /* HAVE_WINDOW_SYSTEM */
28690 /* Clear mouse face if X/Y not over text. */
28692 || area
!= TEXT_AREA
28693 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28694 /* Glyph's OBJECT is an integer for glyphs inserted by the
28695 display engine for its internal purposes, like truncation
28696 and continuation glyphs and blanks beyond the end of
28697 line's text on text terminals. If we are over such a
28698 glyph, we are not over any text. */
28699 || INTEGERP (glyph
->object
)
28700 /* R2L rows have a stretch glyph at their front, which
28701 stands for no text, whereas L2R rows have no glyphs at
28702 all beyond the end of text. Treat such stretch glyphs
28703 like we do with NULL glyphs in L2R rows. */
28704 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28705 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28706 && glyph
->type
== STRETCH_GLYPH
28707 && glyph
->avoid_cursor_p
))
28709 if (clear_mouse_face (hlinfo
))
28710 cursor
= No_Cursor
;
28711 #ifdef HAVE_WINDOW_SYSTEM
28712 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28714 if (area
!= TEXT_AREA
)
28715 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28717 pointer
= Vvoid_text_area_pointer
;
28723 pos
= glyph
->charpos
;
28724 object
= glyph
->object
;
28725 if (!STRINGP (object
) && !BUFFERP (object
))
28728 /* If we get an out-of-range value, return now; avoid an error. */
28729 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28732 /* Make the window's buffer temporarily current for
28733 overlays_at and compute_char_face. */
28734 obuf
= current_buffer
;
28735 current_buffer
= b
;
28741 /* Is this char mouse-active or does it have help-echo? */
28742 position
= make_number (pos
);
28744 if (BUFFERP (object
))
28746 /* Put all the overlays we want in a vector in overlay_vec. */
28747 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28748 /* Sort overlays into increasing priority order. */
28749 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28754 if (NILP (Vmouse_highlight
))
28756 clear_mouse_face (hlinfo
);
28757 goto check_help_echo
;
28760 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28763 cursor
= No_Cursor
;
28765 /* Check mouse-face highlighting. */
28767 /* If there exists an overlay with mouse-face overlapping
28768 the one we are currently highlighting, we have to
28769 check if we enter the overlapping overlay, and then
28770 highlight only that. */
28771 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28772 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28774 /* Find the highest priority overlay with a mouse-face. */
28775 Lisp_Object overlay
= Qnil
;
28776 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28778 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28779 if (!NILP (mouse_face
))
28780 overlay
= overlay_vec
[i
];
28783 /* If we're highlighting the same overlay as before, there's
28784 no need to do that again. */
28785 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28786 goto check_help_echo
;
28787 hlinfo
->mouse_face_overlay
= overlay
;
28789 /* Clear the display of the old active region, if any. */
28790 if (clear_mouse_face (hlinfo
))
28791 cursor
= No_Cursor
;
28793 /* If no overlay applies, get a text property. */
28794 if (NILP (overlay
))
28795 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28797 /* Next, compute the bounds of the mouse highlighting and
28799 if (!NILP (mouse_face
) && STRINGP (object
))
28801 /* The mouse-highlighting comes from a display string
28802 with a mouse-face. */
28806 s
= Fprevious_single_property_change
28807 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28808 e
= Fnext_single_property_change
28809 (position
, Qmouse_face
, object
, Qnil
);
28811 s
= make_number (0);
28813 e
= make_number (SCHARS (object
));
28814 mouse_face_from_string_pos (w
, hlinfo
, object
,
28815 XINT (s
), XINT (e
));
28816 hlinfo
->mouse_face_past_end
= 0;
28817 hlinfo
->mouse_face_window
= window
;
28818 hlinfo
->mouse_face_face_id
28819 = face_at_string_position (w
, object
, pos
, 0, &ignore
,
28820 glyph
->face_id
, 1);
28821 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28822 cursor
= No_Cursor
;
28826 /* The mouse-highlighting, if any, comes from an overlay
28827 or text property in the buffer. */
28828 Lisp_Object buffer
IF_LINT (= Qnil
);
28829 Lisp_Object disp_string
IF_LINT (= Qnil
);
28831 if (STRINGP (object
))
28833 /* If we are on a display string with no mouse-face,
28834 check if the text under it has one. */
28835 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28836 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28837 pos
= string_buffer_position (object
, start
);
28840 mouse_face
= get_char_property_and_overlay
28841 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28842 buffer
= w
->contents
;
28843 disp_string
= object
;
28849 disp_string
= Qnil
;
28852 if (!NILP (mouse_face
))
28854 Lisp_Object before
, after
;
28855 Lisp_Object before_string
, after_string
;
28856 /* To correctly find the limits of mouse highlight
28857 in a bidi-reordered buffer, we must not use the
28858 optimization of limiting the search in
28859 previous-single-property-change and
28860 next-single-property-change, because
28861 rows_from_pos_range needs the real start and end
28862 positions to DTRT in this case. That's because
28863 the first row visible in a window does not
28864 necessarily display the character whose position
28865 is the smallest. */
28867 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28868 ? Fmarker_position (w
->start
)
28871 = NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28872 ? make_number (BUF_Z (XBUFFER (buffer
))
28873 - w
->window_end_pos
)
28876 if (NILP (overlay
))
28878 /* Handle the text property case. */
28879 before
= Fprevious_single_property_change
28880 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28881 after
= Fnext_single_property_change
28882 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28883 before_string
= after_string
= Qnil
;
28887 /* Handle the overlay case. */
28888 before
= Foverlay_start (overlay
);
28889 after
= Foverlay_end (overlay
);
28890 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28891 after_string
= Foverlay_get (overlay
, Qafter_string
);
28893 if (!STRINGP (before_string
)) before_string
= Qnil
;
28894 if (!STRINGP (after_string
)) after_string
= Qnil
;
28897 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28900 : XFASTINT (before
),
28902 ? BUF_Z (XBUFFER (buffer
))
28903 : XFASTINT (after
),
28904 before_string
, after_string
,
28906 cursor
= No_Cursor
;
28913 /* Look for a `help-echo' property. */
28914 if (NILP (help_echo_string
)) {
28915 Lisp_Object help
, overlay
;
28917 /* Check overlays first. */
28918 help
= overlay
= Qnil
;
28919 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28921 overlay
= overlay_vec
[i
];
28922 help
= Foverlay_get (overlay
, Qhelp_echo
);
28927 help_echo_string
= help
;
28928 help_echo_window
= window
;
28929 help_echo_object
= overlay
;
28930 help_echo_pos
= pos
;
28934 Lisp_Object obj
= glyph
->object
;
28935 ptrdiff_t charpos
= glyph
->charpos
;
28937 /* Try text properties. */
28940 && charpos
< SCHARS (obj
))
28942 help
= Fget_text_property (make_number (charpos
),
28946 /* If the string itself doesn't specify a help-echo,
28947 see if the buffer text ``under'' it does. */
28948 struct glyph_row
*r
28949 = MATRIX_ROW (w
->current_matrix
, vpos
);
28950 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28951 ptrdiff_t p
= string_buffer_position (obj
, start
);
28954 help
= Fget_char_property (make_number (p
),
28955 Qhelp_echo
, w
->contents
);
28964 else if (BUFFERP (obj
)
28967 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28972 help_echo_string
= help
;
28973 help_echo_window
= window
;
28974 help_echo_object
= obj
;
28975 help_echo_pos
= charpos
;
28980 #ifdef HAVE_WINDOW_SYSTEM
28981 /* Look for a `pointer' property. */
28982 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28984 /* Check overlays first. */
28985 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28986 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28988 if (NILP (pointer
))
28990 Lisp_Object obj
= glyph
->object
;
28991 ptrdiff_t charpos
= glyph
->charpos
;
28993 /* Try text properties. */
28996 && charpos
< SCHARS (obj
))
28998 pointer
= Fget_text_property (make_number (charpos
),
29000 if (NILP (pointer
))
29002 /* If the string itself doesn't specify a pointer,
29003 see if the buffer text ``under'' it does. */
29004 struct glyph_row
*r
29005 = MATRIX_ROW (w
->current_matrix
, vpos
);
29006 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
29007 ptrdiff_t p
= string_buffer_position (obj
, start
);
29009 pointer
= Fget_char_property (make_number (p
),
29010 Qpointer
, w
->contents
);
29013 else if (BUFFERP (obj
)
29016 pointer
= Fget_text_property (make_number (charpos
),
29020 #endif /* HAVE_WINDOW_SYSTEM */
29024 current_buffer
= obuf
;
29029 #ifdef HAVE_WINDOW_SYSTEM
29030 if (FRAME_WINDOW_P (f
))
29031 define_frame_cursor1 (f
, cursor
, pointer
);
29033 /* This is here to prevent a compiler error, about "label at end of
29034 compound statement". */
29041 Clear any mouse-face on window W. This function is part of the
29042 redisplay interface, and is called from try_window_id and similar
29043 functions to ensure the mouse-highlight is off. */
29046 x_clear_window_mouse_face (struct window
*w
)
29048 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
29049 Lisp_Object window
;
29052 XSETWINDOW (window
, w
);
29053 if (EQ (window
, hlinfo
->mouse_face_window
))
29054 clear_mouse_face (hlinfo
);
29060 Just discard the mouse face information for frame F, if any.
29061 This is used when the size of F is changed. */
29064 cancel_mouse_face (struct frame
*f
)
29066 Lisp_Object window
;
29067 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29069 window
= hlinfo
->mouse_face_window
;
29070 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
29071 reset_mouse_highlight (hlinfo
);
29076 /***********************************************************************
29078 ***********************************************************************/
29080 #ifdef HAVE_WINDOW_SYSTEM
29082 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
29083 which intersects rectangle R. R is in window-relative coordinates. */
29086 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
29087 enum glyph_row_area area
)
29089 struct glyph
*first
= row
->glyphs
[area
];
29090 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
29091 struct glyph
*last
;
29092 int first_x
, start_x
, x
;
29094 if (area
== TEXT_AREA
&& row
->fill_line_p
)
29095 /* If row extends face to end of line write the whole line. */
29096 draw_glyphs (w
, 0, row
, area
,
29097 0, row
->used
[area
],
29098 DRAW_NORMAL_TEXT
, 0);
29101 /* Set START_X to the window-relative start position for drawing glyphs of
29102 AREA. The first glyph of the text area can be partially visible.
29103 The first glyphs of other areas cannot. */
29104 start_x
= window_box_left_offset (w
, area
);
29106 if (area
== TEXT_AREA
)
29109 /* Find the first glyph that must be redrawn. */
29111 && x
+ first
->pixel_width
< r
->x
)
29113 x
+= first
->pixel_width
;
29117 /* Find the last one. */
29121 && x
< r
->x
+ r
->width
)
29123 x
+= last
->pixel_width
;
29129 draw_glyphs (w
, first_x
- start_x
, row
, area
,
29130 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
29131 DRAW_NORMAL_TEXT
, 0);
29136 /* Redraw the parts of the glyph row ROW on window W intersecting
29137 rectangle R. R is in window-relative coordinates. Value is
29138 non-zero if mouse-face was overwritten. */
29141 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
29143 eassert (row
->enabled_p
);
29145 if (row
->mode_line_p
|| w
->pseudo_window_p
)
29146 draw_glyphs (w
, 0, row
, TEXT_AREA
,
29147 0, row
->used
[TEXT_AREA
],
29148 DRAW_NORMAL_TEXT
, 0);
29151 if (row
->used
[LEFT_MARGIN_AREA
])
29152 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
29153 if (row
->used
[TEXT_AREA
])
29154 expose_area (w
, row
, r
, TEXT_AREA
);
29155 if (row
->used
[RIGHT_MARGIN_AREA
])
29156 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
29157 draw_row_fringe_bitmaps (w
, row
);
29160 return row
->mouse_face_p
;
29164 /* Redraw those parts of glyphs rows during expose event handling that
29165 overlap other rows. Redrawing of an exposed line writes over parts
29166 of lines overlapping that exposed line; this function fixes that.
29168 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
29169 row in W's current matrix that is exposed and overlaps other rows.
29170 LAST_OVERLAPPING_ROW is the last such row. */
29173 expose_overlaps (struct window
*w
,
29174 struct glyph_row
*first_overlapping_row
,
29175 struct glyph_row
*last_overlapping_row
,
29178 struct glyph_row
*row
;
29180 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
29181 if (row
->overlapping_p
)
29183 eassert (row
->enabled_p
&& !row
->mode_line_p
);
29186 if (row
->used
[LEFT_MARGIN_AREA
])
29187 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
29189 if (row
->used
[TEXT_AREA
])
29190 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
29192 if (row
->used
[RIGHT_MARGIN_AREA
])
29193 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
29199 /* Return non-zero if W's cursor intersects rectangle R. */
29202 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
29204 XRectangle cr
, result
;
29205 struct glyph
*cursor_glyph
;
29206 struct glyph_row
*row
;
29208 if (w
->phys_cursor
.vpos
>= 0
29209 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
29210 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
29212 && row
->cursor_in_fringe_p
)
29214 /* Cursor is in the fringe. */
29215 cr
.x
= window_box_right_offset (w
,
29216 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
29217 ? RIGHT_MARGIN_AREA
29220 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
29221 cr
.height
= row
->height
;
29222 return x_intersect_rectangles (&cr
, r
, &result
);
29225 cursor_glyph
= get_phys_cursor_glyph (w
);
29228 /* r is relative to W's box, but w->phys_cursor.x is relative
29229 to left edge of W's TEXT area. Adjust it. */
29230 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
29231 cr
.y
= w
->phys_cursor
.y
;
29232 cr
.width
= cursor_glyph
->pixel_width
;
29233 cr
.height
= w
->phys_cursor_height
;
29234 /* ++KFS: W32 version used W32-specific IntersectRect here, but
29235 I assume the effect is the same -- and this is portable. */
29236 return x_intersect_rectangles (&cr
, r
, &result
);
29238 /* If we don't understand the format, pretend we're not in the hot-spot. */
29244 Draw a vertical window border to the right of window W if W doesn't
29245 have vertical scroll bars. */
29248 x_draw_vertical_border (struct window
*w
)
29250 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29252 /* We could do better, if we knew what type of scroll-bar the adjacent
29253 windows (on either side) have... But we don't :-(
29254 However, I think this works ok. ++KFS 2003-04-25 */
29256 /* Redraw borders between horizontally adjacent windows. Don't
29257 do it for frames with vertical scroll bars because either the
29258 right scroll bar of a window, or the left scroll bar of its
29259 neighbor will suffice as a border. */
29260 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
) || FRAME_RIGHT_DIVIDER_WIDTH (f
))
29263 /* Note: It is necessary to redraw both the left and the right
29264 borders, for when only this single window W is being
29266 if (!WINDOW_RIGHTMOST_P (w
)
29267 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
29269 int x0
, x1
, y0
, y1
;
29271 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29274 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29277 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
29280 if (!WINDOW_LEFTMOST_P (w
)
29281 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
29283 int x0
, x1
, y0
, y1
;
29285 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
29288 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
29291 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
29296 /* Draw window dividers for window W. */
29299 x_draw_right_divider (struct window
*w
)
29301 struct frame
*f
= WINDOW_XFRAME (w
);
29303 if (w
->mini
|| w
->pseudo_window_p
)
29305 else if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29307 int x0
= WINDOW_RIGHT_EDGE_X (w
) - WINDOW_RIGHT_DIVIDER_WIDTH (w
);
29308 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29309 int y0
= WINDOW_TOP_EDGE_Y (w
);
29310 /* The bottom divider prevails. */
29311 int y1
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
29313 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29318 x_draw_bottom_divider (struct window
*w
)
29320 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
29322 if (w
->mini
|| w
->pseudo_window_p
)
29324 else if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29326 int x0
= WINDOW_LEFT_EDGE_X (w
);
29327 int x1
= WINDOW_RIGHT_EDGE_X (w
);
29328 int y0
= WINDOW_BOTTOM_EDGE_Y (w
) - WINDOW_BOTTOM_DIVIDER_WIDTH (w
);
29329 int y1
= WINDOW_BOTTOM_EDGE_Y (w
);
29331 FRAME_RIF (f
)->draw_window_divider (w
, x0
, x1
, y0
, y1
);
29335 /* Redraw the part of window W intersection rectangle FR. Pixel
29336 coordinates in FR are frame-relative. Call this function with
29337 input blocked. Value is non-zero if the exposure overwrites
29341 expose_window (struct window
*w
, XRectangle
*fr
)
29343 struct frame
*f
= XFRAME (w
->frame
);
29345 int mouse_face_overwritten_p
= 0;
29347 /* If window is not yet fully initialized, do nothing. This can
29348 happen when toolkit scroll bars are used and a window is split.
29349 Reconfiguring the scroll bar will generate an expose for a newly
29351 if (w
->current_matrix
== NULL
)
29354 /* When we're currently updating the window, display and current
29355 matrix usually don't agree. Arrange for a thorough display
29357 if (w
->must_be_updated_p
)
29359 SET_FRAME_GARBAGED (f
);
29363 /* Frame-relative pixel rectangle of W. */
29364 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
29365 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
29366 wr
.width
= WINDOW_PIXEL_WIDTH (w
);
29367 wr
.height
= WINDOW_PIXEL_HEIGHT (w
);
29369 if (x_intersect_rectangles (fr
, &wr
, &r
))
29371 int yb
= window_text_bottom_y (w
);
29372 struct glyph_row
*row
;
29373 int cursor_cleared_p
, phys_cursor_on_p
;
29374 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
29376 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
29377 r
.x
, r
.y
, r
.width
, r
.height
));
29379 /* Convert to window coordinates. */
29380 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
29381 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
29383 /* Turn off the cursor. */
29384 if (!w
->pseudo_window_p
29385 && phys_cursor_in_rect_p (w
, &r
))
29387 x_clear_cursor (w
);
29388 cursor_cleared_p
= 1;
29391 cursor_cleared_p
= 0;
29393 /* If the row containing the cursor extends face to end of line,
29394 then expose_area might overwrite the cursor outside the
29395 rectangle and thus notice_overwritten_cursor might clear
29396 w->phys_cursor_on_p. We remember the original value and
29397 check later if it is changed. */
29398 phys_cursor_on_p
= w
->phys_cursor_on_p
;
29400 /* Update lines intersecting rectangle R. */
29401 first_overlapping_row
= last_overlapping_row
= NULL
;
29402 for (row
= w
->current_matrix
->rows
;
29407 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
29409 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
29410 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
29411 || (r
.y
>= y0
&& r
.y
< y1
)
29412 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
29414 /* A header line may be overlapping, but there is no need
29415 to fix overlapping areas for them. KFS 2005-02-12 */
29416 if (row
->overlapping_p
&& !row
->mode_line_p
)
29418 if (first_overlapping_row
== NULL
)
29419 first_overlapping_row
= row
;
29420 last_overlapping_row
= row
;
29424 if (expose_line (w
, row
, &r
))
29425 mouse_face_overwritten_p
= 1;
29428 else if (row
->overlapping_p
)
29430 /* We must redraw a row overlapping the exposed area. */
29432 ? y0
+ row
->phys_height
> r
.y
29433 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
29435 if (first_overlapping_row
== NULL
)
29436 first_overlapping_row
= row
;
29437 last_overlapping_row
= row
;
29445 /* Display the mode line if there is one. */
29446 if (WINDOW_WANTS_MODELINE_P (w
)
29447 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
29449 && row
->y
< r
.y
+ r
.height
)
29451 if (expose_line (w
, row
, &r
))
29452 mouse_face_overwritten_p
= 1;
29455 if (!w
->pseudo_window_p
)
29457 /* Fix the display of overlapping rows. */
29458 if (first_overlapping_row
)
29459 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
29462 /* Draw border between windows. */
29463 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
29464 x_draw_right_divider (w
);
29466 x_draw_vertical_border (w
);
29468 if (WINDOW_BOTTOM_DIVIDER_WIDTH (w
))
29469 x_draw_bottom_divider (w
);
29471 /* Turn the cursor on again. */
29472 if (cursor_cleared_p
29473 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
29474 update_window_cursor (w
, 1);
29478 return mouse_face_overwritten_p
;
29483 /* Redraw (parts) of all windows in the window tree rooted at W that
29484 intersect R. R contains frame pixel coordinates. Value is
29485 non-zero if the exposure overwrites mouse-face. */
29488 expose_window_tree (struct window
*w
, XRectangle
*r
)
29490 struct frame
*f
= XFRAME (w
->frame
);
29491 int mouse_face_overwritten_p
= 0;
29493 while (w
&& !FRAME_GARBAGED_P (f
))
29495 if (WINDOWP (w
->contents
))
29496 mouse_face_overwritten_p
29497 |= expose_window_tree (XWINDOW (w
->contents
), r
);
29499 mouse_face_overwritten_p
|= expose_window (w
, r
);
29501 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
29504 return mouse_face_overwritten_p
;
29509 Redisplay an exposed area of frame F. X and Y are the upper-left
29510 corner of the exposed rectangle. W and H are width and height of
29511 the exposed area. All are pixel values. W or H zero means redraw
29512 the entire frame. */
29515 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29518 int mouse_face_overwritten_p
= 0;
29520 TRACE ((stderr
, "expose_frame "));
29522 /* No need to redraw if frame will be redrawn soon. */
29523 if (FRAME_GARBAGED_P (f
))
29525 TRACE ((stderr
, " garbaged\n"));
29529 /* If basic faces haven't been realized yet, there is no point in
29530 trying to redraw anything. This can happen when we get an expose
29531 event while Emacs is starting, e.g. by moving another window. */
29532 if (FRAME_FACE_CACHE (f
) == NULL
29533 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29535 TRACE ((stderr
, " no faces\n"));
29539 if (w
== 0 || h
== 0)
29542 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29543 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29553 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29554 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29556 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
29557 if (WINDOWP (f
->tool_bar_window
))
29558 mouse_face_overwritten_p
29559 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29562 #ifdef HAVE_X_WINDOWS
29564 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29565 if (WINDOWP (f
->menu_bar_window
))
29566 mouse_face_overwritten_p
29567 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29568 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29572 /* Some window managers support a focus-follows-mouse style with
29573 delayed raising of frames. Imagine a partially obscured frame,
29574 and moving the mouse into partially obscured mouse-face on that
29575 frame. The visible part of the mouse-face will be highlighted,
29576 then the WM raises the obscured frame. With at least one WM, KDE
29577 2.1, Emacs is not getting any event for the raising of the frame
29578 (even tried with SubstructureRedirectMask), only Expose events.
29579 These expose events will draw text normally, i.e. not
29580 highlighted. Which means we must redo the highlight here.
29581 Subsume it under ``we love X''. --gerd 2001-08-15 */
29582 /* Included in Windows version because Windows most likely does not
29583 do the right thing if any third party tool offers
29584 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29585 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29587 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29588 if (f
== hlinfo
->mouse_face_mouse_frame
)
29590 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29591 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29592 clear_mouse_face (hlinfo
);
29593 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29600 Determine the intersection of two rectangles R1 and R2. Return
29601 the intersection in *RESULT. Value is non-zero if RESULT is not
29605 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29607 XRectangle
*left
, *right
;
29608 XRectangle
*upper
, *lower
;
29609 int intersection_p
= 0;
29611 /* Rearrange so that R1 is the left-most rectangle. */
29613 left
= r1
, right
= r2
;
29615 left
= r2
, right
= r1
;
29617 /* X0 of the intersection is right.x0, if this is inside R1,
29618 otherwise there is no intersection. */
29619 if (right
->x
<= left
->x
+ left
->width
)
29621 result
->x
= right
->x
;
29623 /* The right end of the intersection is the minimum of
29624 the right ends of left and right. */
29625 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29628 /* Same game for Y. */
29630 upper
= r1
, lower
= r2
;
29632 upper
= r2
, lower
= r1
;
29634 /* The upper end of the intersection is lower.y0, if this is inside
29635 of upper. Otherwise, there is no intersection. */
29636 if (lower
->y
<= upper
->y
+ upper
->height
)
29638 result
->y
= lower
->y
;
29640 /* The lower end of the intersection is the minimum of the lower
29641 ends of upper and lower. */
29642 result
->height
= (min (lower
->y
+ lower
->height
,
29643 upper
->y
+ upper
->height
)
29645 intersection_p
= 1;
29649 return intersection_p
;
29652 #endif /* HAVE_WINDOW_SYSTEM */
29655 /***********************************************************************
29657 ***********************************************************************/
29660 syms_of_xdisp (void)
29662 Vwith_echo_area_save_vector
= Qnil
;
29663 staticpro (&Vwith_echo_area_save_vector
);
29665 Vmessage_stack
= Qnil
;
29666 staticpro (&Vmessage_stack
);
29668 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29669 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29671 message_dolog_marker1
= Fmake_marker ();
29672 staticpro (&message_dolog_marker1
);
29673 message_dolog_marker2
= Fmake_marker ();
29674 staticpro (&message_dolog_marker2
);
29675 message_dolog_marker3
= Fmake_marker ();
29676 staticpro (&message_dolog_marker3
);
29679 defsubr (&Sdump_frame_glyph_matrix
);
29680 defsubr (&Sdump_glyph_matrix
);
29681 defsubr (&Sdump_glyph_row
);
29682 defsubr (&Sdump_tool_bar_row
);
29683 defsubr (&Strace_redisplay
);
29684 defsubr (&Strace_to_stderr
);
29686 #ifdef HAVE_WINDOW_SYSTEM
29687 defsubr (&Stool_bar_height
);
29688 defsubr (&Slookup_image_map
);
29690 defsubr (&Sline_pixel_height
);
29691 defsubr (&Sformat_mode_line
);
29692 defsubr (&Sinvisible_p
);
29693 defsubr (&Scurrent_bidi_paragraph_direction
);
29694 defsubr (&Swindow_text_pixel_size
);
29695 defsubr (&Smove_point_visually
);
29697 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29698 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29699 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29700 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29701 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29702 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29703 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29704 DEFSYM (Qeval
, "eval");
29705 DEFSYM (QCdata
, ":data");
29706 DEFSYM (Qdisplay
, "display");
29707 DEFSYM (Qspace_width
, "space-width");
29708 DEFSYM (Qraise
, "raise");
29709 DEFSYM (Qslice
, "slice");
29710 DEFSYM (Qspace
, "space");
29711 DEFSYM (Qmargin
, "margin");
29712 DEFSYM (Qpointer
, "pointer");
29713 DEFSYM (Qleft_margin
, "left-margin");
29714 DEFSYM (Qright_margin
, "right-margin");
29715 DEFSYM (Qcenter
, "center");
29716 DEFSYM (Qline_height
, "line-height");
29717 DEFSYM (QCalign_to
, ":align-to");
29718 DEFSYM (QCrelative_width
, ":relative-width");
29719 DEFSYM (QCrelative_height
, ":relative-height");
29720 DEFSYM (QCeval
, ":eval");
29721 DEFSYM (QCpropertize
, ":propertize");
29722 DEFSYM (QCfile
, ":file");
29723 DEFSYM (Qfontified
, "fontified");
29724 DEFSYM (Qfontification_functions
, "fontification-functions");
29725 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29726 DEFSYM (Qescape_glyph
, "escape-glyph");
29727 DEFSYM (Qnobreak_space
, "nobreak-space");
29728 DEFSYM (Qimage
, "image");
29729 DEFSYM (Qtext
, "text");
29730 DEFSYM (Qboth
, "both");
29731 DEFSYM (Qboth_horiz
, "both-horiz");
29732 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29733 DEFSYM (QCmap
, ":map");
29734 DEFSYM (QCpointer
, ":pointer");
29735 DEFSYM (Qrect
, "rect");
29736 DEFSYM (Qcircle
, "circle");
29737 DEFSYM (Qpoly
, "poly");
29738 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29739 DEFSYM (Qgrow_only
, "grow-only");
29740 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29741 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29742 DEFSYM (Qposition
, "position");
29743 DEFSYM (Qbuffer_position
, "buffer-position");
29744 DEFSYM (Qobject
, "object");
29745 DEFSYM (Qbar
, "bar");
29746 DEFSYM (Qhbar
, "hbar");
29747 DEFSYM (Qbox
, "box");
29748 DEFSYM (Qhollow
, "hollow");
29749 DEFSYM (Qhand
, "hand");
29750 DEFSYM (Qarrow
, "arrow");
29751 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29753 list_of_error
= list1 (list2 (intern_c_string ("error"),
29754 intern_c_string ("void-variable")));
29755 staticpro (&list_of_error
);
29757 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29758 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29759 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29760 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29762 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29763 staticpro (&echo_buffer
[0]);
29764 staticpro (&echo_buffer
[1]);
29766 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29767 staticpro (&echo_area_buffer
[0]);
29768 staticpro (&echo_area_buffer
[1]);
29770 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29771 staticpro (&Vmessages_buffer_name
);
29773 mode_line_proptrans_alist
= Qnil
;
29774 staticpro (&mode_line_proptrans_alist
);
29775 mode_line_string_list
= Qnil
;
29776 staticpro (&mode_line_string_list
);
29777 mode_line_string_face
= Qnil
;
29778 staticpro (&mode_line_string_face
);
29779 mode_line_string_face_prop
= Qnil
;
29780 staticpro (&mode_line_string_face_prop
);
29781 Vmode_line_unwind_vector
= Qnil
;
29782 staticpro (&Vmode_line_unwind_vector
);
29784 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29786 help_echo_string
= Qnil
;
29787 staticpro (&help_echo_string
);
29788 help_echo_object
= Qnil
;
29789 staticpro (&help_echo_object
);
29790 help_echo_window
= Qnil
;
29791 staticpro (&help_echo_window
);
29792 previous_help_echo_string
= Qnil
;
29793 staticpro (&previous_help_echo_string
);
29794 help_echo_pos
= -1;
29796 DEFSYM (Qright_to_left
, "right-to-left");
29797 DEFSYM (Qleft_to_right
, "left-to-right");
29799 #ifdef HAVE_WINDOW_SYSTEM
29800 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29801 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29802 For example, if a block cursor is over a tab, it will be drawn as
29803 wide as that tab on the display. */);
29804 x_stretch_cursor_p
= 0;
29807 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29808 doc
: /* Non-nil means highlight trailing whitespace.
29809 The face used for trailing whitespace is `trailing-whitespace'. */);
29810 Vshow_trailing_whitespace
= Qnil
;
29812 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29813 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29814 If the value is t, Emacs highlights non-ASCII chars which have the
29815 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29816 or `escape-glyph' face respectively.
29818 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29819 U+2011 (non-breaking hyphen) are affected.
29821 Any other non-nil value means to display these characters as a escape
29822 glyph followed by an ordinary space or hyphen.
29824 A value of nil means no special handling of these characters. */);
29825 Vnobreak_char_display
= Qt
;
29827 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29828 doc
: /* The pointer shape to show in void text areas.
29829 A value of nil means to show the text pointer. Other options are `arrow',
29830 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29831 Vvoid_text_area_pointer
= Qarrow
;
29833 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29834 doc
: /* Non-nil means don't actually do any redisplay.
29835 This is used for internal purposes. */);
29836 Vinhibit_redisplay
= Qnil
;
29838 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29839 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29840 Vglobal_mode_string
= Qnil
;
29842 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29843 doc
: /* Marker for where to display an arrow on top of the buffer text.
29844 This must be the beginning of a line in order to work.
29845 See also `overlay-arrow-string'. */);
29846 Voverlay_arrow_position
= Qnil
;
29848 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29849 doc
: /* String to display as an arrow in non-window frames.
29850 See also `overlay-arrow-position'. */);
29851 Voverlay_arrow_string
= build_pure_c_string ("=>");
29853 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29854 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29855 The symbols on this list are examined during redisplay to determine
29856 where to display overlay arrows. */);
29857 Voverlay_arrow_variable_list
29858 = list1 (intern_c_string ("overlay-arrow-position"));
29860 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29861 doc
: /* The number of lines to try scrolling a window by when point moves out.
29862 If that fails to bring point back on frame, point is centered instead.
29863 If this is zero, point is always centered after it moves off frame.
29864 If you want scrolling to always be a line at a time, you should set
29865 `scroll-conservatively' to a large value rather than set this to 1. */);
29867 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29868 doc
: /* Scroll up to this many lines, to bring point back on screen.
29869 If point moves off-screen, redisplay will scroll by up to
29870 `scroll-conservatively' lines in order to bring point just barely
29871 onto the screen again. If that cannot be done, then redisplay
29872 recenters point as usual.
29874 If the value is greater than 100, redisplay will never recenter point,
29875 but will always scroll just enough text to bring point into view, even
29876 if you move far away.
29878 A value of zero means always recenter point if it moves off screen. */);
29879 scroll_conservatively
= 0;
29881 DEFVAR_INT ("scroll-margin", scroll_margin
,
29882 doc
: /* Number of lines of margin at the top and bottom of a window.
29883 Recenter the window whenever point gets within this many lines
29884 of the top or bottom of the window. */);
29887 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29888 doc
: /* Pixels per inch value for non-window system displays.
29889 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29890 Vdisplay_pixels_per_inch
= make_float (72.0);
29893 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29896 DEFVAR_LISP ("truncate-partial-width-windows",
29897 Vtruncate_partial_width_windows
,
29898 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29899 For an integer value, truncate lines in each window narrower than the
29900 full frame width, provided the window width is less than that integer;
29901 otherwise, respect the value of `truncate-lines'.
29903 For any other non-nil value, truncate lines in all windows that do
29904 not span the full frame width.
29906 A value of nil means to respect the value of `truncate-lines'.
29908 If `word-wrap' is enabled, you might want to reduce this. */);
29909 Vtruncate_partial_width_windows
= make_number (50);
29911 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29912 doc
: /* Maximum buffer size for which line number should be displayed.
29913 If the buffer is bigger than this, the line number does not appear
29914 in the mode line. A value of nil means no limit. */);
29915 Vline_number_display_limit
= Qnil
;
29917 DEFVAR_INT ("line-number-display-limit-width",
29918 line_number_display_limit_width
,
29919 doc
: /* Maximum line width (in characters) for line number display.
29920 If the average length of the lines near point is bigger than this, then the
29921 line number may be omitted from the mode line. */);
29922 line_number_display_limit_width
= 200;
29924 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29925 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29926 highlight_nonselected_windows
= 0;
29928 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29929 doc
: /* Non-nil if more than one frame is visible on this display.
29930 Minibuffer-only frames don't count, but iconified frames do.
29931 This variable is not guaranteed to be accurate except while processing
29932 `frame-title-format' and `icon-title-format'. */);
29934 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29935 doc
: /* Template for displaying the title bar of visible frames.
29936 \(Assuming the window manager supports this feature.)
29938 This variable has the same structure as `mode-line-format', except that
29939 the %c and %l constructs are ignored. It is used only on frames for
29940 which no explicit name has been set \(see `modify-frame-parameters'). */);
29942 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29943 doc
: /* Template for displaying the title bar of an iconified frame.
29944 \(Assuming the window manager supports this feature.)
29945 This variable has the same structure as `mode-line-format' (which see),
29946 and is used only on frames for which no explicit name has been set
29947 \(see `modify-frame-parameters'). */);
29949 = Vframe_title_format
29950 = listn (CONSTYPE_PURE
, 3,
29951 intern_c_string ("multiple-frames"),
29952 build_pure_c_string ("%b"),
29953 listn (CONSTYPE_PURE
, 4,
29954 empty_unibyte_string
,
29955 intern_c_string ("invocation-name"),
29956 build_pure_c_string ("@"),
29957 intern_c_string ("system-name")));
29959 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29960 doc
: /* Maximum number of lines to keep in the message log buffer.
29961 If nil, disable message logging. If t, log messages but don't truncate
29962 the buffer when it becomes large. */);
29963 Vmessage_log_max
= make_number (1000);
29965 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29966 doc
: /* Functions called before redisplay, if window sizes have changed.
29967 The value should be a list of functions that take one argument.
29968 Just before redisplay, for each frame, if any of its windows have changed
29969 size since the last redisplay, or have been split or deleted,
29970 all the functions in the list are called, with the frame as argument. */);
29971 Vwindow_size_change_functions
= Qnil
;
29973 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29974 doc
: /* List of functions to call before redisplaying a window with scrolling.
29975 Each function is called with two arguments, the window and its new
29976 display-start position. Note that these functions are also called by
29977 `set-window-buffer'. Also note that the value of `window-end' is not
29978 valid when these functions are called.
29980 Warning: Do not use this feature to alter the way the window
29981 is scrolled. It is not designed for that, and such use probably won't
29983 Vwindow_scroll_functions
= Qnil
;
29985 DEFVAR_LISP ("window-text-change-functions",
29986 Vwindow_text_change_functions
,
29987 doc
: /* Functions to call in redisplay when text in the window might change. */);
29988 Vwindow_text_change_functions
= Qnil
;
29990 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29991 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29992 Each function is called with two arguments, the window and the end trigger value.
29993 See `set-window-redisplay-end-trigger'. */);
29994 Vredisplay_end_trigger_functions
= Qnil
;
29996 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29997 doc
: /* Non-nil means autoselect window with mouse pointer.
29998 If nil, do not autoselect windows.
29999 A positive number means delay autoselection by that many seconds: a
30000 window is autoselected only after the mouse has remained in that
30001 window for the duration of the delay.
30002 A negative number has a similar effect, but causes windows to be
30003 autoselected only after the mouse has stopped moving. \(Because of
30004 the way Emacs compares mouse events, you will occasionally wait twice
30005 that time before the window gets selected.\)
30006 Any other value means to autoselect window instantaneously when the
30007 mouse pointer enters it.
30009 Autoselection selects the minibuffer only if it is active, and never
30010 unselects the minibuffer if it is active.
30012 When customizing this variable make sure that the actual value of
30013 `focus-follows-mouse' matches the behavior of your window manager. */);
30014 Vmouse_autoselect_window
= Qnil
;
30016 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
30017 doc
: /* Non-nil means automatically resize tool-bars.
30018 This dynamically changes the tool-bar's height to the minimum height
30019 that is needed to make all tool-bar items visible.
30020 If value is `grow-only', the tool-bar's height is only increased
30021 automatically; to decrease the tool-bar height, use \\[recenter]. */);
30022 Vauto_resize_tool_bars
= Qt
;
30024 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
30025 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
30026 auto_raise_tool_bar_buttons_p
= 1;
30028 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
30029 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
30030 make_cursor_line_fully_visible_p
= 1;
30032 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
30033 doc
: /* Border below tool-bar in pixels.
30034 If an integer, use it as the height of the border.
30035 If it is one of `internal-border-width' or `border-width', use the
30036 value of the corresponding frame parameter.
30037 Otherwise, no border is added below the tool-bar. */);
30038 Vtool_bar_border
= Qinternal_border_width
;
30040 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
30041 doc
: /* Margin around tool-bar buttons in pixels.
30042 If an integer, use that for both horizontal and vertical margins.
30043 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
30044 HORZ specifying the horizontal margin, and VERT specifying the
30045 vertical margin. */);
30046 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
30048 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
30049 doc
: /* Relief thickness of tool-bar buttons. */);
30050 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
30052 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
30053 doc
: /* Tool bar style to use.
30055 image - show images only
30056 text - show text only
30057 both - show both, text below image
30058 both-horiz - show text to the right of the image
30059 text-image-horiz - show text to the left of the image
30060 any other - use system default or image if no system default.
30062 This variable only affects the GTK+ toolkit version of Emacs. */);
30063 Vtool_bar_style
= Qnil
;
30065 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
30066 doc
: /* Maximum number of characters a label can have to be shown.
30067 The tool bar style must also show labels for this to have any effect, see
30068 `tool-bar-style'. */);
30069 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
30071 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
30072 doc
: /* List of functions to call to fontify regions of text.
30073 Each function is called with one argument POS. Functions must
30074 fontify a region starting at POS in the current buffer, and give
30075 fontified regions the property `fontified'. */);
30076 Vfontification_functions
= Qnil
;
30077 Fmake_variable_buffer_local (Qfontification_functions
);
30079 DEFVAR_BOOL ("unibyte-display-via-language-environment",
30080 unibyte_display_via_language_environment
,
30081 doc
: /* Non-nil means display unibyte text according to language environment.
30082 Specifically, this means that raw bytes in the range 160-255 decimal
30083 are displayed by converting them to the equivalent multibyte characters
30084 according to the current language environment. As a result, they are
30085 displayed according to the current fontset.
30087 Note that this variable affects only how these bytes are displayed,
30088 but does not change the fact they are interpreted as raw bytes. */);
30089 unibyte_display_via_language_environment
= 0;
30091 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
30092 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
30093 If a float, it specifies a fraction of the mini-window frame's height.
30094 If an integer, it specifies a number of lines. */);
30095 Vmax_mini_window_height
= make_float (0.25);
30097 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
30098 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
30099 A value of nil means don't automatically resize mini-windows.
30100 A value of t means resize them to fit the text displayed in them.
30101 A value of `grow-only', the default, means let mini-windows grow only;
30102 they return to their normal size when the minibuffer is closed, or the
30103 echo area becomes empty. */);
30104 Vresize_mini_windows
= Qgrow_only
;
30106 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
30107 doc
: /* Alist specifying how to blink the cursor off.
30108 Each element has the form (ON-STATE . OFF-STATE). Whenever the
30109 `cursor-type' frame-parameter or variable equals ON-STATE,
30110 comparing using `equal', Emacs uses OFF-STATE to specify
30111 how to blink it off. ON-STATE and OFF-STATE are values for
30112 the `cursor-type' frame parameter.
30114 If a frame's ON-STATE has no entry in this list,
30115 the frame's other specifications determine how to blink the cursor off. */);
30116 Vblink_cursor_alist
= Qnil
;
30118 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
30119 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
30120 If non-nil, windows are automatically scrolled horizontally to make
30121 point visible. */);
30122 automatic_hscrolling_p
= 1;
30123 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
30125 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
30126 doc
: /* How many columns away from the window edge point is allowed to get
30127 before automatic hscrolling will horizontally scroll the window. */);
30128 hscroll_margin
= 5;
30130 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
30131 doc
: /* How many columns to scroll the window when point gets too close to the edge.
30132 When point is less than `hscroll-margin' columns from the window
30133 edge, automatic hscrolling will scroll the window by the amount of columns
30134 determined by this variable. If its value is a positive integer, scroll that
30135 many columns. If it's a positive floating-point number, it specifies the
30136 fraction of the window's width to scroll. If it's nil or zero, point will be
30137 centered horizontally after the scroll. Any other value, including negative
30138 numbers, are treated as if the value were zero.
30140 Automatic hscrolling always moves point outside the scroll margin, so if
30141 point was more than scroll step columns inside the margin, the window will
30142 scroll more than the value given by the scroll step.
30144 Note that the lower bound for automatic hscrolling specified by `scroll-left'
30145 and `scroll-right' overrides this variable's effect. */);
30146 Vhscroll_step
= make_number (0);
30148 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
30149 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
30150 Bind this around calls to `message' to let it take effect. */);
30151 message_truncate_lines
= 0;
30153 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
30154 doc
: /* Normal hook run to update the menu bar definitions.
30155 Redisplay runs this hook before it redisplays the menu bar.
30156 This is used to update menus such as Buffers, whose contents depend on
30158 Vmenu_bar_update_hook
= Qnil
;
30160 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
30161 doc
: /* Frame for which we are updating a menu.
30162 The enable predicate for a menu binding should check this variable. */);
30163 Vmenu_updating_frame
= Qnil
;
30165 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
30166 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
30167 inhibit_menubar_update
= 0;
30169 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
30170 doc
: /* Prefix prepended to all continuation lines at display time.
30171 The value may be a string, an image, or a stretch-glyph; it is
30172 interpreted in the same way as the value of a `display' text property.
30174 This variable is overridden by any `wrap-prefix' text or overlay
30177 To add a prefix to non-continuation lines, use `line-prefix'. */);
30178 Vwrap_prefix
= Qnil
;
30179 DEFSYM (Qwrap_prefix
, "wrap-prefix");
30180 Fmake_variable_buffer_local (Qwrap_prefix
);
30182 DEFVAR_LISP ("line-prefix", Vline_prefix
,
30183 doc
: /* Prefix prepended to all non-continuation lines at display time.
30184 The value may be a string, an image, or a stretch-glyph; it is
30185 interpreted in the same way as the value of a `display' text property.
30187 This variable is overridden by any `line-prefix' text or overlay
30190 To add a prefix to continuation lines, use `wrap-prefix'. */);
30191 Vline_prefix
= Qnil
;
30192 DEFSYM (Qline_prefix
, "line-prefix");
30193 Fmake_variable_buffer_local (Qline_prefix
);
30195 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
30196 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
30197 inhibit_eval_during_redisplay
= 0;
30199 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
30200 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
30201 inhibit_free_realized_faces
= 0;
30204 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
30205 doc
: /* Inhibit try_window_id display optimization. */);
30206 inhibit_try_window_id
= 0;
30208 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
30209 doc
: /* Inhibit try_window_reusing display optimization. */);
30210 inhibit_try_window_reusing
= 0;
30212 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
30213 doc
: /* Inhibit try_cursor_movement display optimization. */);
30214 inhibit_try_cursor_movement
= 0;
30215 #endif /* GLYPH_DEBUG */
30217 DEFVAR_INT ("overline-margin", overline_margin
,
30218 doc
: /* Space between overline and text, in pixels.
30219 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
30220 margin to the character height. */);
30221 overline_margin
= 2;
30223 DEFVAR_INT ("underline-minimum-offset",
30224 underline_minimum_offset
,
30225 doc
: /* Minimum distance between baseline and underline.
30226 This can improve legibility of underlined text at small font sizes,
30227 particularly when using variable `x-use-underline-position-properties'
30228 with fonts that specify an UNDERLINE_POSITION relatively close to the
30229 baseline. The default value is 1. */);
30230 underline_minimum_offset
= 1;
30232 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
30233 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
30234 This feature only works when on a window system that can change
30235 cursor shapes. */);
30236 display_hourglass_p
= 1;
30238 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
30239 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
30240 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
30242 #ifdef HAVE_WINDOW_SYSTEM
30243 hourglass_atimer
= NULL
;
30244 hourglass_shown_p
= 0;
30245 #endif /* HAVE_WINDOW_SYSTEM */
30247 DEFSYM (Qglyphless_char
, "glyphless-char");
30248 DEFSYM (Qhex_code
, "hex-code");
30249 DEFSYM (Qempty_box
, "empty-box");
30250 DEFSYM (Qthin_space
, "thin-space");
30251 DEFSYM (Qzero_width
, "zero-width");
30253 DEFVAR_LISP ("pre-redisplay-function", Vpre_redisplay_function
,
30254 doc
: /* Function run just before redisplay.
30255 It is called with one argument, which is the set of windows that are to
30256 be redisplayed. This set can be nil (meaning, only the selected window),
30257 or t (meaning all windows). */);
30258 Vpre_redisplay_function
= intern ("ignore");
30260 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
30261 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
30263 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
30264 doc
: /* Char-table defining glyphless characters.
30265 Each element, if non-nil, should be one of the following:
30266 an ASCII acronym string: display this string in a box
30267 `hex-code': display the hexadecimal code of a character in a box
30268 `empty-box': display as an empty box
30269 `thin-space': display as 1-pixel width space
30270 `zero-width': don't display
30271 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
30272 display method for graphical terminals and text terminals respectively.
30273 GRAPHICAL and TEXT should each have one of the values listed above.
30275 The char-table has one extra slot to control the display of a character for
30276 which no font is found. This slot only takes effect on graphical terminals.
30277 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
30278 `thin-space'. The default is `empty-box'.
30280 If a character has a non-nil entry in an active display table, the
30281 display table takes effect; in this case, Emacs does not consult
30282 `glyphless-char-display' at all. */);
30283 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
30284 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
30287 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
30288 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
30289 Vdebug_on_message
= Qnil
;
30291 DEFVAR_LISP ("redisplay--all-windows-cause", Vredisplay__all_windows_cause
,
30293 Vredisplay__all_windows_cause
30294 = Fmake_vector (make_number (100), make_number (0));
30296 DEFVAR_LISP ("redisplay--mode-lines-cause", Vredisplay__mode_lines_cause
,
30298 Vredisplay__mode_lines_cause
30299 = Fmake_vector (make_number (100), make_number (0));
30303 /* Initialize this module when Emacs starts. */
30308 CHARPOS (this_line_start_pos
) = 0;
30310 if (!noninteractive
)
30312 struct window
*m
= XWINDOW (minibuf_window
);
30313 Lisp_Object frame
= m
->frame
;
30314 struct frame
*f
= XFRAME (frame
);
30315 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
30316 struct window
*r
= XWINDOW (root
);
30319 echo_area_window
= minibuf_window
;
30321 r
->top_line
= FRAME_TOP_MARGIN (f
);
30322 r
->pixel_top
= r
->top_line
* FRAME_LINE_HEIGHT (f
);
30323 r
->total_cols
= FRAME_COLS (f
);
30324 r
->pixel_width
= r
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30325 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
30326 r
->pixel_height
= r
->total_lines
* FRAME_LINE_HEIGHT (f
);
30328 m
->top_line
= FRAME_LINES (f
) - 1;
30329 m
->pixel_top
= m
->top_line
* FRAME_LINE_HEIGHT (f
);
30330 m
->total_cols
= FRAME_COLS (f
);
30331 m
->pixel_width
= m
->total_cols
* FRAME_COLUMN_WIDTH (f
);
30332 m
->total_lines
= 1;
30333 m
->pixel_height
= m
->total_lines
* FRAME_LINE_HEIGHT (f
);
30335 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
30336 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
30337 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
30339 /* The default ellipsis glyphs `...'. */
30340 for (i
= 0; i
< 3; ++i
)
30341 default_invis_vector
[i
] = make_number ('.');
30345 /* Allocate the buffer for frame titles.
30346 Also used for `format-mode-line'. */
30348 mode_line_noprop_buf
= xmalloc (size
);
30349 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
30350 mode_line_noprop_ptr
= mode_line_noprop_buf
;
30351 mode_line_target
= MODE_LINE_DISPLAY
;
30354 help_echo_showing_p
= 0;
30357 #ifdef HAVE_WINDOW_SYSTEM
30359 /* Platform-independent portion of hourglass implementation. */
30361 /* Cancel a currently active hourglass timer, and start a new one. */
30363 start_hourglass (void)
30365 struct timespec delay
;
30367 cancel_hourglass ();
30369 if (INTEGERP (Vhourglass_delay
)
30370 && XINT (Vhourglass_delay
) > 0)
30371 delay
= make_timespec (min (XINT (Vhourglass_delay
),
30372 TYPE_MAXIMUM (time_t)),
30374 else if (FLOATP (Vhourglass_delay
)
30375 && XFLOAT_DATA (Vhourglass_delay
) > 0)
30376 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
30378 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
30382 extern void w32_note_current_window (void);
30383 w32_note_current_window ();
30385 #endif /* HAVE_NTGUI */
30387 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
30388 show_hourglass
, NULL
);
30392 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
30395 cancel_hourglass (void)
30397 if (hourglass_atimer
)
30399 cancel_atimer (hourglass_atimer
);
30400 hourglass_atimer
= NULL
;
30403 if (hourglass_shown_p
)
30407 #endif /* HAVE_WINDOW_SYSTEM */