1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2013 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"
303 #ifdef HAVE_X_WINDOWS
318 #ifndef FRAME_X_OUTPUT
319 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
322 #define INFINITY 10000000
324 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
325 Lisp_Object Qwindow_scroll_functions
;
326 static Lisp_Object Qwindow_text_change_functions
;
327 static Lisp_Object Qredisplay_end_trigger_functions
;
328 Lisp_Object Qinhibit_point_motion_hooks
;
329 static Lisp_Object QCeval
, QCpropertize
;
330 Lisp_Object QCfile
, QCdata
;
331 static Lisp_Object Qfontified
;
332 static Lisp_Object Qgrow_only
;
333 static Lisp_Object Qinhibit_eval_during_redisplay
;
334 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
335 static Lisp_Object Qright_to_left
, Qleft_to_right
;
338 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
340 /* Pointer shapes. */
341 static Lisp_Object Qarrow
, Qhand
;
344 /* Holds the list (error). */
345 static Lisp_Object list_of_error
;
347 static Lisp_Object Qfontification_functions
;
349 static Lisp_Object Qwrap_prefix
;
350 static Lisp_Object Qline_prefix
;
351 static Lisp_Object Qredisplay_internal
;
353 /* Non-nil means don't actually do any redisplay. */
355 Lisp_Object Qinhibit_redisplay
;
357 /* Names of text properties relevant for redisplay. */
359 Lisp_Object Qdisplay
;
361 Lisp_Object Qspace
, QCalign_to
;
362 static Lisp_Object QCrelative_width
, QCrelative_height
;
363 Lisp_Object Qleft_margin
, Qright_margin
;
364 static Lisp_Object Qspace_width
, Qraise
;
365 static Lisp_Object Qslice
;
367 static Lisp_Object Qmargin
, Qpointer
;
368 static Lisp_Object Qline_height
;
370 /* These setters are used only in this file, so they can be private. */
372 wset_base_line_number (struct window
*w
, Lisp_Object val
)
374 w
->base_line_number
= val
;
377 wset_base_line_pos (struct window
*w
, Lisp_Object val
)
379 w
->base_line_pos
= val
;
382 wset_column_number_displayed (struct window
*w
, Lisp_Object val
)
384 w
->column_number_displayed
= val
;
387 wset_region_showing (struct window
*w
, Lisp_Object val
)
389 w
->region_showing
= val
;
392 #ifdef HAVE_WINDOW_SYSTEM
394 /* Test if overflow newline into fringe. Called with iterator IT
395 at or past right window margin, and with IT->current_x set. */
397 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
398 (!NILP (Voverflow_newline_into_fringe) \
399 && FRAME_WINDOW_P ((IT)->f) \
400 && ((IT)->bidi_it.paragraph_dir == R2L \
401 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
402 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
403 && (IT)->current_x == (IT)->last_visible_x \
404 && (IT)->line_wrap != WORD_WRAP)
406 #else /* !HAVE_WINDOW_SYSTEM */
407 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
408 #endif /* HAVE_WINDOW_SYSTEM */
410 /* Test if the display element loaded in IT, or the underlying buffer
411 or string character, is a space or a TAB character. This is used
412 to determine where word wrapping can occur. */
414 #define IT_DISPLAYING_WHITESPACE(it) \
415 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
416 || ((STRINGP (it->string) \
417 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
418 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
420 && (it->s[IT_BYTEPOS (*it)] == ' ' \
421 || it->s[IT_BYTEPOS (*it)] == '\t')) \
422 || (IT_BYTEPOS (*it) < ZV_BYTE \
423 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
424 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
426 /* Name of the face used to highlight trailing whitespace. */
428 static Lisp_Object Qtrailing_whitespace
;
430 /* Name and number of the face used to highlight escape glyphs. */
432 static Lisp_Object Qescape_glyph
;
434 /* Name and number of the face used to highlight non-breaking spaces. */
436 static Lisp_Object Qnobreak_space
;
438 /* The symbol `image' which is the car of the lists used to represent
439 images in Lisp. Also a tool bar style. */
443 /* The image map types. */
445 static Lisp_Object QCpointer
;
446 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
448 /* Tool bar styles */
449 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
451 /* Non-zero means print newline to stdout before next mini-buffer
454 int noninteractive_need_newline
;
456 /* Non-zero means print newline to message log before next message. */
458 static int message_log_need_newline
;
460 /* Three markers that message_dolog uses.
461 It could allocate them itself, but that causes trouble
462 in handling memory-full errors. */
463 static Lisp_Object message_dolog_marker1
;
464 static Lisp_Object message_dolog_marker2
;
465 static Lisp_Object message_dolog_marker3
;
467 /* The buffer position of the first character appearing entirely or
468 partially on the line of the selected window which contains the
469 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
470 redisplay optimization in redisplay_internal. */
472 static struct text_pos this_line_start_pos
;
474 /* Number of characters past the end of the line above, including the
475 terminating newline. */
477 static struct text_pos this_line_end_pos
;
479 /* The vertical positions and the height of this line. */
481 static int this_line_vpos
;
482 static int this_line_y
;
483 static int this_line_pixel_height
;
485 /* X position at which this display line starts. Usually zero;
486 negative if first character is partially visible. */
488 static int this_line_start_x
;
490 /* The smallest character position seen by move_it_* functions as they
491 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
492 hscrolled lines, see display_line. */
494 static struct text_pos this_line_min_pos
;
496 /* Buffer that this_line_.* variables are referring to. */
498 static struct buffer
*this_line_buffer
;
501 /* Values of those variables at last redisplay are stored as
502 properties on `overlay-arrow-position' symbol. However, if
503 Voverlay_arrow_position is a marker, last-arrow-position is its
504 numerical position. */
506 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
508 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
509 properties on a symbol in overlay-arrow-variable-list. */
511 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
513 Lisp_Object Qmenu_bar_update_hook
;
515 /* Nonzero if an overlay arrow has been displayed in this window. */
517 static int overlay_arrow_seen
;
519 /* Vector containing glyphs for an ellipsis `...'. */
521 static Lisp_Object default_invis_vector
[3];
523 /* This is the window where the echo area message was displayed. It
524 is always a mini-buffer window, but it may not be the same window
525 currently active as a mini-buffer. */
527 Lisp_Object echo_area_window
;
529 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
530 pushes the current message and the value of
531 message_enable_multibyte on the stack, the function restore_message
532 pops the stack and displays MESSAGE again. */
534 static Lisp_Object Vmessage_stack
;
536 /* Nonzero means multibyte characters were enabled when the echo area
537 message was specified. */
539 static int message_enable_multibyte
;
541 /* Nonzero if we should redraw the mode lines on the next redisplay. */
543 int update_mode_lines
;
545 /* Nonzero if window sizes or contents have changed since last
546 redisplay that finished. */
548 int windows_or_buffers_changed
;
550 /* Nonzero means a frame's cursor type has been changed. */
552 int cursor_type_changed
;
554 /* Nonzero after display_mode_line if %l was used and it displayed a
557 static int line_number_displayed
;
559 /* The name of the *Messages* buffer, a string. */
561 static Lisp_Object Vmessages_buffer_name
;
563 /* Current, index 0, and last displayed echo area message. Either
564 buffers from echo_buffers, or nil to indicate no message. */
566 Lisp_Object echo_area_buffer
[2];
568 /* The buffers referenced from echo_area_buffer. */
570 static Lisp_Object echo_buffer
[2];
572 /* A vector saved used in with_area_buffer to reduce consing. */
574 static Lisp_Object Vwith_echo_area_save_vector
;
576 /* Non-zero means display_echo_area should display the last echo area
577 message again. Set by redisplay_preserve_echo_area. */
579 static int display_last_displayed_message_p
;
581 /* Nonzero if echo area is being used by print; zero if being used by
584 static int message_buf_print
;
586 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
588 static Lisp_Object Qinhibit_menubar_update
;
589 static Lisp_Object Qmessage_truncate_lines
;
591 /* Set to 1 in clear_message to make redisplay_internal aware
592 of an emptied echo area. */
594 static int message_cleared_p
;
596 /* A scratch glyph row with contents used for generating truncation
597 glyphs. Also used in direct_output_for_insert. */
599 #define MAX_SCRATCH_GLYPHS 100
600 static struct glyph_row scratch_glyph_row
;
601 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
603 /* Ascent and height of the last line processed by move_it_to. */
605 static int last_max_ascent
, last_height
;
607 /* Non-zero if there's a help-echo in the echo area. */
609 int help_echo_showing_p
;
611 /* If >= 0, computed, exact values of mode-line and header-line height
612 to use in the macros CURRENT_MODE_LINE_HEIGHT and
613 CURRENT_HEADER_LINE_HEIGHT. */
615 int current_mode_line_height
, current_header_line_height
;
617 /* The maximum distance to look ahead for text properties. Values
618 that are too small let us call compute_char_face and similar
619 functions too often which is expensive. Values that are too large
620 let us call compute_char_face and alike too often because we
621 might not be interested in text properties that far away. */
623 #define TEXT_PROP_DISTANCE_LIMIT 100
625 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
626 iterator state and later restore it. This is needed because the
627 bidi iterator on bidi.c keeps a stacked cache of its states, which
628 is really a singleton. When we use scratch iterator objects to
629 move around the buffer, we can cause the bidi cache to be pushed or
630 popped, and therefore we need to restore the cache state when we
631 return to the original iterator. */
632 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
635 bidi_unshelve_cache (CACHE, 1); \
637 CACHE = bidi_shelve_cache (); \
640 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
642 if (pITORIG != pITCOPY) \
643 *(pITORIG) = *(pITCOPY); \
644 bidi_unshelve_cache (CACHE, 0); \
650 /* Non-zero means print traces of redisplay if compiled with
651 GLYPH_DEBUG defined. */
653 int trace_redisplay_p
;
655 #endif /* GLYPH_DEBUG */
657 #ifdef DEBUG_TRACE_MOVE
658 /* Non-zero means trace with TRACE_MOVE to stderr. */
661 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
663 #define TRACE_MOVE(x) (void) 0
666 static Lisp_Object Qauto_hscroll_mode
;
668 /* Buffer being redisplayed -- for redisplay_window_error. */
670 static struct buffer
*displayed_buffer
;
672 /* Value returned from text property handlers (see below). */
677 HANDLED_RECOMPUTE_PROPS
,
678 HANDLED_OVERLAY_STRING_CONSUMED
,
682 /* A description of text properties that redisplay is interested
687 /* The name of the property. */
690 /* A unique index for the property. */
693 /* A handler function called to set up iterator IT from the property
694 at IT's current position. Value is used to steer handle_stop. */
695 enum prop_handled (*handler
) (struct it
*it
);
698 static enum prop_handled
handle_face_prop (struct it
*);
699 static enum prop_handled
handle_invisible_prop (struct it
*);
700 static enum prop_handled
handle_display_prop (struct it
*);
701 static enum prop_handled
handle_composition_prop (struct it
*);
702 static enum prop_handled
handle_overlay_change (struct it
*);
703 static enum prop_handled
handle_fontified_prop (struct it
*);
705 /* Properties handled by iterators. */
707 static struct props it_props
[] =
709 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
710 /* Handle `face' before `display' because some sub-properties of
711 `display' need to know the face. */
712 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
713 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
714 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
715 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
719 /* Value is the position described by X. If X is a marker, value is
720 the marker_position of X. Otherwise, value is X. */
722 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
724 /* Enumeration returned by some move_it_.* functions internally. */
728 /* Not used. Undefined value. */
731 /* Move ended at the requested buffer position or ZV. */
732 MOVE_POS_MATCH_OR_ZV
,
734 /* Move ended at the requested X pixel position. */
737 /* Move within a line ended at the end of a line that must be
741 /* Move within a line ended at the end of a line that would
742 be displayed truncated. */
745 /* Move within a line ended at a line end. */
749 /* This counter is used to clear the face cache every once in a while
750 in redisplay_internal. It is incremented for each redisplay.
751 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
754 #define CLEAR_FACE_CACHE_COUNT 500
755 static int clear_face_cache_count
;
757 /* Similarly for the image cache. */
759 #ifdef HAVE_WINDOW_SYSTEM
760 #define CLEAR_IMAGE_CACHE_COUNT 101
761 static int clear_image_cache_count
;
763 /* Null glyph slice */
764 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
767 /* True while redisplay_internal is in progress. */
771 static Lisp_Object Qinhibit_free_realized_faces
;
772 static Lisp_Object Qmode_line_default_help_echo
;
774 /* If a string, XTread_socket generates an event to display that string.
775 (The display is done in read_char.) */
777 Lisp_Object help_echo_string
;
778 Lisp_Object help_echo_window
;
779 Lisp_Object help_echo_object
;
780 ptrdiff_t help_echo_pos
;
782 /* Temporary variable for XTread_socket. */
784 Lisp_Object previous_help_echo_string
;
786 /* Platform-independent portion of hourglass implementation. */
788 /* Non-zero means an hourglass cursor is currently shown. */
789 int hourglass_shown_p
;
791 /* If non-null, an asynchronous timer that, when it expires, displays
792 an hourglass cursor on all frames. */
793 struct atimer
*hourglass_atimer
;
795 /* Name of the face used to display glyphless characters. */
796 Lisp_Object Qglyphless_char
;
798 /* Symbol for the purpose of Vglyphless_char_display. */
799 static Lisp_Object Qglyphless_char_display
;
801 /* Method symbols for Vglyphless_char_display. */
802 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
804 /* Default pixel width of `thin-space' display method. */
805 #define THIN_SPACE_WIDTH 1
807 /* Default number of seconds to wait before displaying an hourglass
809 #define DEFAULT_HOURGLASS_DELAY 1
812 /* Function prototypes. */
814 static void setup_for_ellipsis (struct it
*, int);
815 static void set_iterator_to_next (struct it
*, int);
816 static void mark_window_display_accurate_1 (struct window
*, int);
817 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
818 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
819 static int cursor_row_p (struct glyph_row
*);
820 static int redisplay_mode_lines (Lisp_Object
, int);
821 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
823 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
825 static void handle_line_prefix (struct it
*);
827 static void pint2str (char *, int, ptrdiff_t);
828 static void pint2hrstr (char *, int, ptrdiff_t);
829 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
831 static void reconsider_clip_changes (struct window
*, struct buffer
*);
832 static int text_outside_line_unchanged_p (struct window
*,
833 ptrdiff_t, ptrdiff_t);
834 static void store_mode_line_noprop_char (char);
835 static int store_mode_line_noprop (const char *, int, int);
836 static void handle_stop (struct it
*);
837 static void handle_stop_backwards (struct it
*, ptrdiff_t);
838 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
839 static void ensure_echo_area_buffers (void);
840 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
841 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
842 static int with_echo_area_buffer (struct window
*, int,
843 int (*) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
844 ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
845 static void clear_garbaged_frames (void);
846 static int current_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
847 static void pop_message (void);
848 static int truncate_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
849 static void set_message (const char *, Lisp_Object
, ptrdiff_t, int);
850 static int set_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
851 static int display_echo_area (struct window
*);
852 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
853 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
854 static Lisp_Object
unwind_redisplay (Lisp_Object
);
855 static int string_char_and_length (const unsigned char *, int *);
856 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
858 static int compute_window_start_on_continuation_line (struct window
*);
859 static void insert_left_trunc_glyphs (struct it
*);
860 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
862 static void extend_face_to_end_of_line (struct it
*);
863 static int append_space_for_newline (struct it
*, int);
864 static int cursor_row_fully_visible_p (struct window
*, int, int);
865 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
866 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
867 static int trailing_whitespace_p (ptrdiff_t);
868 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
869 static void push_it (struct it
*, struct text_pos
*);
870 static void iterate_out_of_display_property (struct it
*);
871 static void pop_it (struct it
*);
872 static void sync_frame_with_window_matrix_rows (struct window
*);
873 static void redisplay_internal (void);
874 static int echo_area_display (int);
875 static void redisplay_windows (Lisp_Object
);
876 static void redisplay_window (Lisp_Object
, int);
877 static Lisp_Object
redisplay_window_error (Lisp_Object
);
878 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
879 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
880 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
881 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
883 static int update_menu_bar (struct frame
*, int, int);
884 static int try_window_reusing_current_matrix (struct window
*);
885 static int try_window_id (struct window
*);
886 static int display_line (struct it
*);
887 static int display_mode_lines (struct window
*);
888 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
889 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
890 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
891 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
892 static void display_menu_bar (struct window
*);
893 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
895 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
896 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
897 static void compute_line_metrics (struct it
*);
898 static void run_redisplay_end_trigger_hook (struct it
*);
899 static int get_overlay_strings (struct it
*, ptrdiff_t);
900 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
901 static void next_overlay_string (struct it
*);
902 static void reseat (struct it
*, struct text_pos
, int);
903 static void reseat_1 (struct it
*, struct text_pos
, int);
904 static void back_to_previous_visible_line_start (struct it
*);
905 void reseat_at_previous_visible_line_start (struct it
*);
906 static void reseat_at_next_visible_line_start (struct it
*, int);
907 static int next_element_from_ellipsis (struct it
*);
908 static int next_element_from_display_vector (struct it
*);
909 static int next_element_from_string (struct it
*);
910 static int next_element_from_c_string (struct it
*);
911 static int next_element_from_buffer (struct it
*);
912 static int next_element_from_composition (struct it
*);
913 static int next_element_from_image (struct it
*);
914 static int next_element_from_stretch (struct it
*);
915 static void load_overlay_strings (struct it
*, ptrdiff_t);
916 static int init_from_display_pos (struct it
*, struct window
*,
917 struct display_pos
*);
918 static void reseat_to_string (struct it
*, const char *,
919 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
920 static int get_next_display_element (struct it
*);
921 static enum move_it_result
922 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
923 enum move_operation_enum
);
924 void move_it_vertically_backward (struct it
*, int);
925 static void get_visually_first_element (struct it
*);
926 static void init_to_row_start (struct it
*, struct window
*,
928 static int init_to_row_end (struct it
*, struct window
*,
930 static void back_to_previous_line_start (struct it
*);
931 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
932 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
933 Lisp_Object
, ptrdiff_t);
934 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
935 static struct text_pos
c_string_pos (ptrdiff_t, const char *, int);
936 static ptrdiff_t number_of_chars (const char *, int);
937 static void compute_stop_pos (struct it
*);
938 static void compute_string_pos (struct text_pos
*, struct text_pos
,
940 static int face_before_or_after_it_pos (struct it
*, int);
941 static ptrdiff_t next_overlay_change (ptrdiff_t);
942 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
943 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
944 static int handle_single_display_spec (struct it
*, Lisp_Object
,
945 Lisp_Object
, Lisp_Object
,
946 struct text_pos
*, ptrdiff_t, int, int);
947 static int underlying_face_id (struct it
*);
948 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
951 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
952 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
954 #ifdef HAVE_WINDOW_SYSTEM
956 static void x_consider_frame_title (Lisp_Object
);
957 static int tool_bar_lines_needed (struct frame
*, int *);
958 static void update_tool_bar (struct frame
*, int);
959 static void build_desired_tool_bar_string (struct frame
*f
);
960 static int redisplay_tool_bar (struct frame
*);
961 static void display_tool_bar_line (struct it
*, int);
962 static void notice_overwritten_cursor (struct window
*,
965 static void append_stretch_glyph (struct it
*, Lisp_Object
,
969 #endif /* HAVE_WINDOW_SYSTEM */
971 static void produce_special_glyphs (struct it
*, enum display_element_type
);
972 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
973 static int coords_in_mouse_face_p (struct window
*, int, int);
977 /***********************************************************************
978 Window display dimensions
979 ***********************************************************************/
981 /* Return the bottom boundary y-position for text lines in window W.
982 This is the first y position at which a line cannot start.
983 It is relative to the top of the window.
985 This is the height of W minus the height of a mode line, if any. */
988 window_text_bottom_y (struct window
*w
)
990 int height
= WINDOW_TOTAL_HEIGHT (w
);
992 if (WINDOW_WANTS_MODELINE_P (w
))
993 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
997 /* Return the pixel width of display area AREA of window W. AREA < 0
998 means return the total width of W, not including fringes to
999 the left and right of the window. */
1002 window_box_width (struct window
*w
, int area
)
1004 int cols
= XFASTINT (w
->total_cols
);
1007 if (!w
->pseudo_window_p
)
1009 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
1011 if (area
== TEXT_AREA
)
1013 if (INTEGERP (w
->left_margin_cols
))
1014 cols
-= XFASTINT (w
->left_margin_cols
);
1015 if (INTEGERP (w
->right_margin_cols
))
1016 cols
-= XFASTINT (w
->right_margin_cols
);
1017 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
1019 else if (area
== LEFT_MARGIN_AREA
)
1021 cols
= (INTEGERP (w
->left_margin_cols
)
1022 ? XFASTINT (w
->left_margin_cols
) : 0);
1025 else if (area
== RIGHT_MARGIN_AREA
)
1027 cols
= (INTEGERP (w
->right_margin_cols
)
1028 ? XFASTINT (w
->right_margin_cols
) : 0);
1033 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1037 /* Return the pixel height of the display area of window W, not
1038 including mode lines of W, if any. */
1041 window_box_height (struct window
*w
)
1043 struct frame
*f
= XFRAME (w
->frame
);
1044 int height
= WINDOW_TOTAL_HEIGHT (w
);
1046 eassert (height
>= 0);
1048 /* Note: the code below that determines the mode-line/header-line
1049 height is essentially the same as that contained in the macro
1050 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1051 the appropriate glyph row has its `mode_line_p' flag set,
1052 and if it doesn't, uses estimate_mode_line_height instead. */
1054 if (WINDOW_WANTS_MODELINE_P (w
))
1056 struct glyph_row
*ml_row
1057 = (w
->current_matrix
&& w
->current_matrix
->rows
1058 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1060 if (ml_row
&& ml_row
->mode_line_p
)
1061 height
-= ml_row
->height
;
1063 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1066 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1068 struct glyph_row
*hl_row
1069 = (w
->current_matrix
&& w
->current_matrix
->rows
1070 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1072 if (hl_row
&& hl_row
->mode_line_p
)
1073 height
-= hl_row
->height
;
1075 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1078 /* With a very small font and a mode-line that's taller than
1079 default, we might end up with a negative height. */
1080 return max (0, height
);
1083 /* Return the window-relative coordinate of the left edge of display
1084 area AREA of window W. AREA < 0 means return the left edge of the
1085 whole window, to the right of the left fringe of W. */
1088 window_box_left_offset (struct window
*w
, int area
)
1092 if (w
->pseudo_window_p
)
1095 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1097 if (area
== TEXT_AREA
)
1098 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1099 + window_box_width (w
, LEFT_MARGIN_AREA
));
1100 else if (area
== RIGHT_MARGIN_AREA
)
1101 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1102 + window_box_width (w
, LEFT_MARGIN_AREA
)
1103 + window_box_width (w
, TEXT_AREA
)
1104 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1106 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1107 else if (area
== LEFT_MARGIN_AREA
1108 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1109 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1115 /* Return the window-relative coordinate of the right edge of display
1116 area AREA of window W. AREA < 0 means return the right edge of the
1117 whole window, to the left of the right fringe of W. */
1120 window_box_right_offset (struct window
*w
, int area
)
1122 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1125 /* Return the frame-relative coordinate of the left edge of display
1126 area AREA of window W. AREA < 0 means return the left edge of the
1127 whole window, to the right of the left fringe of W. */
1130 window_box_left (struct window
*w
, int area
)
1132 struct frame
*f
= XFRAME (w
->frame
);
1135 if (w
->pseudo_window_p
)
1136 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1138 x
= (WINDOW_LEFT_EDGE_X (w
)
1139 + window_box_left_offset (w
, area
));
1145 /* Return the frame-relative coordinate of the right edge of display
1146 area AREA of window W. AREA < 0 means return the right edge of the
1147 whole window, to the left of the right fringe of W. */
1150 window_box_right (struct window
*w
, int area
)
1152 return window_box_left (w
, area
) + window_box_width (w
, area
);
1155 /* Get the bounding box of the display area AREA of window W, without
1156 mode lines, in frame-relative coordinates. AREA < 0 means the
1157 whole window, not including the left and right fringes of
1158 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1159 coordinates of the upper-left corner of the box. Return in
1160 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1163 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1164 int *box_width
, int *box_height
)
1167 *box_width
= window_box_width (w
, area
);
1169 *box_height
= window_box_height (w
);
1171 *box_x
= window_box_left (w
, area
);
1174 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1175 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1176 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1181 /* Get the bounding box of the display area AREA of window W, without
1182 mode lines. AREA < 0 means the whole window, not including the
1183 left and right fringe of the window. Return in *TOP_LEFT_X
1184 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1185 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1186 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1190 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1191 int *bottom_right_x
, int *bottom_right_y
)
1193 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1195 *bottom_right_x
+= *top_left_x
;
1196 *bottom_right_y
+= *top_left_y
;
1201 /***********************************************************************
1203 ***********************************************************************/
1205 /* Return the bottom y-position of the line the iterator IT is in.
1206 This can modify IT's settings. */
1209 line_bottom_y (struct it
*it
)
1211 int line_height
= it
->max_ascent
+ it
->max_descent
;
1212 int line_top_y
= it
->current_y
;
1214 if (line_height
== 0)
1217 line_height
= last_height
;
1218 else if (IT_CHARPOS (*it
) < ZV
)
1220 move_it_by_lines (it
, 1);
1221 line_height
= (it
->max_ascent
|| it
->max_descent
1222 ? it
->max_ascent
+ it
->max_descent
1227 struct glyph_row
*row
= it
->glyph_row
;
1229 /* Use the default character height. */
1230 it
->glyph_row
= NULL
;
1231 it
->what
= IT_CHARACTER
;
1234 PRODUCE_GLYPHS (it
);
1235 line_height
= it
->ascent
+ it
->descent
;
1236 it
->glyph_row
= row
;
1240 return line_top_y
+ line_height
;
1243 /* Subroutine of pos_visible_p below. Extracts a display string, if
1244 any, from the display spec given as its argument. */
1246 string_from_display_spec (Lisp_Object spec
)
1250 while (CONSP (spec
))
1252 if (STRINGP (XCAR (spec
)))
1257 else if (VECTORP (spec
))
1261 for (i
= 0; i
< ASIZE (spec
); i
++)
1263 if (STRINGP (AREF (spec
, i
)))
1264 return AREF (spec
, i
);
1273 /* Limit insanely large values of W->hscroll on frame F to the largest
1274 value that will still prevent first_visible_x and last_visible_x of
1275 'struct it' from overflowing an int. */
1277 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1279 ptrdiff_t window_hscroll
= w
->hscroll
;
1280 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1281 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1283 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1284 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1286 return window_hscroll
;
1289 /* Return 1 if position CHARPOS is visible in window W.
1290 CHARPOS < 0 means return info about WINDOW_END position.
1291 If visible, set *X and *Y to pixel coordinates of top left corner.
1292 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1293 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1296 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1297 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1300 void *itdata
= bidi_shelve_cache ();
1301 struct text_pos top
;
1303 struct buffer
*old_buffer
= NULL
;
1305 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1308 if (XBUFFER (w
->buffer
) != current_buffer
)
1310 old_buffer
= current_buffer
;
1311 set_buffer_internal_1 (XBUFFER (w
->buffer
));
1314 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1315 /* Scrolling a minibuffer window via scroll bar when the echo area
1316 shows long text sometimes resets the minibuffer contents behind
1318 if (CHARPOS (top
) > ZV
)
1319 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1321 /* Compute exact mode line heights. */
1322 if (WINDOW_WANTS_MODELINE_P (w
))
1323 current_mode_line_height
1324 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1325 BVAR (current_buffer
, mode_line_format
));
1327 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1328 current_header_line_height
1329 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1330 BVAR (current_buffer
, header_line_format
));
1332 start_display (&it
, w
, top
);
1333 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1334 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1337 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1338 && IT_CHARPOS (it
) >= charpos
)
1339 /* When scanning backwards under bidi iteration, move_it_to
1340 stops at or _before_ CHARPOS, because it stops at or to
1341 the _right_ of the character at CHARPOS. */
1342 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1343 && IT_CHARPOS (it
) <= charpos
)))
1345 /* We have reached CHARPOS, or passed it. How the call to
1346 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1347 or covered by a display property, move_it_to stops at the end
1348 of the invisible text, to the right of CHARPOS. (ii) If
1349 CHARPOS is in a display vector, move_it_to stops on its last
1351 int top_x
= it
.current_x
;
1352 int top_y
= it
.current_y
;
1353 /* Calling line_bottom_y may change it.method, it.position, etc. */
1354 enum it_method it_method
= it
.method
;
1355 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1356 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1358 if (top_y
< window_top_y
)
1359 visible_p
= bottom_y
> window_top_y
;
1360 else if (top_y
< it
.last_visible_y
)
1362 if (bottom_y
>= it
.last_visible_y
1363 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1364 && IT_CHARPOS (it
) < charpos
)
1366 /* When the last line of the window is scanned backwards
1367 under bidi iteration, we could be duped into thinking
1368 that we have passed CHARPOS, when in fact move_it_to
1369 simply stopped short of CHARPOS because it reached
1370 last_visible_y. To see if that's what happened, we call
1371 move_it_to again with a slightly larger vertical limit,
1372 and see if it actually moved vertically; if it did, we
1373 didn't really reach CHARPOS, which is beyond window end. */
1374 struct it save_it
= it
;
1375 /* Why 10? because we don't know how many canonical lines
1376 will the height of the next line(s) be. So we guess. */
1377 int ten_more_lines
=
1378 10 * FRAME_LINE_HEIGHT (XFRAME (WINDOW_FRAME (w
)));
1380 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1381 MOVE_TO_POS
| MOVE_TO_Y
);
1382 if (it
.current_y
> top_y
)
1389 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1391 /* We stopped on the last glyph of a display vector.
1392 Try and recompute. Hack alert! */
1393 if (charpos
< 2 || top
.charpos
>= charpos
)
1394 top_x
= it
.glyph_row
->x
;
1398 start_display (&it2
, w
, top
);
1399 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1400 get_next_display_element (&it2
);
1401 PRODUCE_GLYPHS (&it2
);
1402 if (ITERATOR_AT_END_OF_LINE_P (&it2
)
1403 || it2
.current_x
> it2
.last_visible_x
)
1404 top_x
= it
.glyph_row
->x
;
1407 top_x
= it2
.current_x
;
1408 top_y
= it2
.current_y
;
1412 else if (IT_CHARPOS (it
) != charpos
)
1414 Lisp_Object cpos
= make_number (charpos
);
1415 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1416 Lisp_Object string
= string_from_display_spec (spec
);
1417 int newline_in_string
= 0;
1419 if (STRINGP (string
))
1421 const char *s
= SSDATA (string
);
1422 const char *e
= s
+ SBYTES (string
);
1427 newline_in_string
= 1;
1432 /* The tricky code below is needed because there's a
1433 discrepancy between move_it_to and how we set cursor
1434 when the display line ends in a newline from a
1435 display string. move_it_to will stop _after_ such
1436 display strings, whereas set_cursor_from_row
1437 conspires with cursor_row_p to place the cursor on
1438 the first glyph produced from the display string. */
1440 /* We have overshoot PT because it is covered by a
1441 display property whose value is a string. If the
1442 string includes embedded newlines, we are also in the
1443 wrong display line. Backtrack to the correct line,
1444 where the display string begins. */
1445 if (newline_in_string
)
1447 Lisp_Object startpos
, endpos
;
1448 EMACS_INT start
, end
;
1452 /* Find the first and the last buffer positions
1453 covered by the display string. */
1455 Fnext_single_char_property_change (cpos
, Qdisplay
,
1458 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1460 start
= XFASTINT (startpos
);
1461 end
= XFASTINT (endpos
);
1462 /* Move to the last buffer position before the
1463 display property. */
1464 start_display (&it3
, w
, top
);
1465 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1466 /* Move forward one more line if the position before
1467 the display string is a newline or if it is the
1468 rightmost character on a line that is
1469 continued or word-wrapped. */
1470 if (it3
.method
== GET_FROM_BUFFER
1472 move_it_by_lines (&it3
, 1);
1473 else if (move_it_in_display_line_to (&it3
, -1,
1477 == MOVE_LINE_CONTINUED
)
1479 move_it_by_lines (&it3
, 1);
1480 /* When we are under word-wrap, the #$@%!
1481 move_it_by_lines moves 2 lines, so we need to
1483 if (it3
.line_wrap
== WORD_WRAP
)
1484 move_it_by_lines (&it3
, -1);
1487 /* Record the vertical coordinate of the display
1488 line where we wound up. */
1489 top_y
= it3
.current_y
;
1492 /* When characters are reordered for display,
1493 the character displayed to the left of the
1494 display string could be _after_ the display
1495 property in the logical order. Use the
1496 smallest vertical position of these two. */
1497 start_display (&it3
, w
, top
);
1498 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1499 if (it3
.current_y
< top_y
)
1500 top_y
= it3
.current_y
;
1502 /* Move from the top of the window to the beginning
1503 of the display line where the display string
1505 start_display (&it3
, w
, top
);
1506 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1507 /* If it3_moved stays zero after the 'while' loop
1508 below, that means we already were at a newline
1509 before the loop (e.g., the display string begins
1510 with a newline), so we don't need to (and cannot)
1511 inspect the glyphs of it3.glyph_row, because
1512 PRODUCE_GLYPHS will not produce anything for a
1513 newline, and thus it3.glyph_row stays at its
1514 stale content it got at top of the window. */
1516 /* Finally, advance the iterator until we hit the
1517 first display element whose character position is
1518 CHARPOS, or until the first newline from the
1519 display string, which signals the end of the
1521 while (get_next_display_element (&it3
))
1523 PRODUCE_GLYPHS (&it3
);
1524 if (IT_CHARPOS (it3
) == charpos
1525 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1528 set_iterator_to_next (&it3
, 0);
1530 top_x
= it3
.current_x
- it3
.pixel_width
;
1531 /* Normally, we would exit the above loop because we
1532 found the display element whose character
1533 position is CHARPOS. For the contingency that we
1534 didn't, and stopped at the first newline from the
1535 display string, move back over the glyphs
1536 produced from the string, until we find the
1537 rightmost glyph not from the string. */
1539 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1541 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1542 + it3
.glyph_row
->used
[TEXT_AREA
];
1544 while (EQ ((g
- 1)->object
, string
))
1547 top_x
-= g
->pixel_width
;
1549 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1550 + it3
.glyph_row
->used
[TEXT_AREA
]);
1556 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1557 *rtop
= max (0, window_top_y
- top_y
);
1558 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1559 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1560 - max (top_y
, window_top_y
)));
1566 /* We were asked to provide info about WINDOW_END. */
1568 void *it2data
= NULL
;
1570 SAVE_IT (it2
, it
, it2data
);
1571 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1572 move_it_by_lines (&it
, 1);
1573 if (charpos
< IT_CHARPOS (it
)
1574 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1577 RESTORE_IT (&it2
, &it2
, it2data
);
1578 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1580 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1581 *rtop
= max (0, -it2
.current_y
);
1582 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1583 - it
.last_visible_y
));
1584 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1586 - max (it2
.current_y
,
1587 WINDOW_HEADER_LINE_HEIGHT (w
))));
1591 bidi_unshelve_cache (it2data
, 1);
1593 bidi_unshelve_cache (itdata
, 0);
1596 set_buffer_internal_1 (old_buffer
);
1598 current_header_line_height
= current_mode_line_height
= -1;
1600 if (visible_p
&& w
->hscroll
> 0)
1602 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1603 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1606 /* Debugging code. */
1608 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1609 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1611 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1618 /* Return the next character from STR. Return in *LEN the length of
1619 the character. This is like STRING_CHAR_AND_LENGTH but never
1620 returns an invalid character. If we find one, we return a `?', but
1621 with the length of the invalid character. */
1624 string_char_and_length (const unsigned char *str
, int *len
)
1628 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1629 if (!CHAR_VALID_P (c
))
1630 /* We may not change the length here because other places in Emacs
1631 don't use this function, i.e. they silently accept invalid
1640 /* Given a position POS containing a valid character and byte position
1641 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1643 static struct text_pos
1644 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1646 eassert (STRINGP (string
) && nchars
>= 0);
1648 if (STRING_MULTIBYTE (string
))
1650 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1655 string_char_and_length (p
, &len
);
1658 BYTEPOS (pos
) += len
;
1662 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1668 /* Value is the text position, i.e. character and byte position,
1669 for character position CHARPOS in STRING. */
1671 static struct text_pos
1672 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1674 struct text_pos pos
;
1675 eassert (STRINGP (string
));
1676 eassert (charpos
>= 0);
1677 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1682 /* Value is a text position, i.e. character and byte position, for
1683 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1684 means recognize multibyte characters. */
1686 static struct text_pos
1687 c_string_pos (ptrdiff_t charpos
, const char *s
, int multibyte_p
)
1689 struct text_pos pos
;
1691 eassert (s
!= NULL
);
1692 eassert (charpos
>= 0);
1698 SET_TEXT_POS (pos
, 0, 0);
1701 string_char_and_length ((const unsigned char *) s
, &len
);
1704 BYTEPOS (pos
) += len
;
1708 SET_TEXT_POS (pos
, charpos
, charpos
);
1714 /* Value is the number of characters in C string S. MULTIBYTE_P
1715 non-zero means recognize multibyte characters. */
1718 number_of_chars (const char *s
, int multibyte_p
)
1724 ptrdiff_t rest
= strlen (s
);
1726 const unsigned char *p
= (const unsigned char *) s
;
1728 for (nchars
= 0; rest
> 0; ++nchars
)
1730 string_char_and_length (p
, &len
);
1731 rest
-= len
, p
+= len
;
1735 nchars
= strlen (s
);
1741 /* Compute byte position NEWPOS->bytepos corresponding to
1742 NEWPOS->charpos. POS is a known position in string STRING.
1743 NEWPOS->charpos must be >= POS.charpos. */
1746 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1748 eassert (STRINGP (string
));
1749 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1751 if (STRING_MULTIBYTE (string
))
1752 *newpos
= string_pos_nchars_ahead (pos
, string
,
1753 CHARPOS (*newpos
) - CHARPOS (pos
));
1755 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1759 Return an estimation of the pixel height of mode or header lines on
1760 frame F. FACE_ID specifies what line's height to estimate. */
1763 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1765 #ifdef HAVE_WINDOW_SYSTEM
1766 if (FRAME_WINDOW_P (f
))
1768 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1770 /* This function is called so early when Emacs starts that the face
1771 cache and mode line face are not yet initialized. */
1772 if (FRAME_FACE_CACHE (f
))
1774 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1778 height
= FONT_HEIGHT (face
->font
);
1779 if (face
->box_line_width
> 0)
1780 height
+= 2 * face
->box_line_width
;
1791 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1792 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1793 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1794 not force the value into range. */
1797 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1798 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1801 #ifdef HAVE_WINDOW_SYSTEM
1802 if (FRAME_WINDOW_P (f
))
1804 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1805 even for negative values. */
1807 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1809 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1811 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1812 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1815 STORE_NATIVE_RECT (*bounds
,
1816 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1817 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1818 FRAME_COLUMN_WIDTH (f
) - 1,
1819 FRAME_LINE_HEIGHT (f
) - 1);
1825 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1826 pix_x
= FRAME_TOTAL_COLS (f
);
1830 else if (pix_y
> FRAME_LINES (f
))
1831 pix_y
= FRAME_LINES (f
);
1841 /* Find the glyph under window-relative coordinates X/Y in window W.
1842 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1843 strings. Return in *HPOS and *VPOS the row and column number of
1844 the glyph found. Return in *AREA the glyph area containing X.
1845 Value is a pointer to the glyph found or null if X/Y is not on
1846 text, or we can't tell because W's current matrix is not up to
1851 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1852 int *dx
, int *dy
, int *area
)
1854 struct glyph
*glyph
, *end
;
1855 struct glyph_row
*row
= NULL
;
1858 /* Find row containing Y. Give up if some row is not enabled. */
1859 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1861 row
= MATRIX_ROW (w
->current_matrix
, i
);
1862 if (!row
->enabled_p
)
1864 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1871 /* Give up if Y is not in the window. */
1872 if (i
== w
->current_matrix
->nrows
)
1875 /* Get the glyph area containing X. */
1876 if (w
->pseudo_window_p
)
1883 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1885 *area
= LEFT_MARGIN_AREA
;
1886 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1888 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1891 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1895 *area
= RIGHT_MARGIN_AREA
;
1896 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1900 /* Find glyph containing X. */
1901 glyph
= row
->glyphs
[*area
];
1902 end
= glyph
+ row
->used
[*area
];
1904 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1906 x
-= glyph
->pixel_width
;
1916 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1919 *hpos
= glyph
- row
->glyphs
[*area
];
1923 /* Convert frame-relative x/y to coordinates relative to window W.
1924 Takes pseudo-windows into account. */
1927 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1929 if (w
->pseudo_window_p
)
1931 /* A pseudo-window is always full-width, and starts at the
1932 left edge of the frame, plus a frame border. */
1933 struct frame
*f
= XFRAME (w
->frame
);
1934 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1935 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1939 *x
-= WINDOW_LEFT_EDGE_X (w
);
1940 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1944 #ifdef HAVE_WINDOW_SYSTEM
1947 Return in RECTS[] at most N clipping rectangles for glyph string S.
1948 Return the number of stored rectangles. */
1951 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1958 if (s
->row
->full_width_p
)
1960 /* Draw full-width. X coordinates are relative to S->w->left_col. */
1961 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
1962 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
1964 /* Unless displaying a mode or menu bar line, which are always
1965 fully visible, clip to the visible part of the row. */
1966 if (s
->w
->pseudo_window_p
)
1967 r
.height
= s
->row
->visible_height
;
1969 r
.height
= s
->height
;
1973 /* This is a text line that may be partially visible. */
1974 r
.x
= window_box_left (s
->w
, s
->area
);
1975 r
.width
= window_box_width (s
->w
, s
->area
);
1976 r
.height
= s
->row
->visible_height
;
1980 if (r
.x
< s
->clip_head
->x
)
1982 if (r
.width
>= s
->clip_head
->x
- r
.x
)
1983 r
.width
-= s
->clip_head
->x
- r
.x
;
1986 r
.x
= s
->clip_head
->x
;
1989 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
1991 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
1992 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
1997 /* If S draws overlapping rows, it's sufficient to use the top and
1998 bottom of the window for clipping because this glyph string
1999 intentionally draws over other lines. */
2000 if (s
->for_overlaps
)
2002 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2003 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2005 /* Alas, the above simple strategy does not work for the
2006 environments with anti-aliased text: if the same text is
2007 drawn onto the same place multiple times, it gets thicker.
2008 If the overlap we are processing is for the erased cursor, we
2009 take the intersection with the rectangle of the cursor. */
2010 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2012 XRectangle rc
, r_save
= r
;
2014 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2015 rc
.y
= s
->w
->phys_cursor
.y
;
2016 rc
.width
= s
->w
->phys_cursor_width
;
2017 rc
.height
= s
->w
->phys_cursor_height
;
2019 x_intersect_rectangles (&r_save
, &rc
, &r
);
2024 /* Don't use S->y for clipping because it doesn't take partially
2025 visible lines into account. For example, it can be negative for
2026 partially visible lines at the top of a window. */
2027 if (!s
->row
->full_width_p
2028 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2029 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2031 r
.y
= max (0, s
->row
->y
);
2034 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2036 /* If drawing the cursor, don't let glyph draw outside its
2037 advertised boundaries. Cleartype does this under some circumstances. */
2038 if (s
->hl
== DRAW_CURSOR
)
2040 struct glyph
*glyph
= s
->first_glyph
;
2045 r
.width
-= s
->x
- r
.x
;
2048 r
.width
= min (r
.width
, glyph
->pixel_width
);
2050 /* If r.y is below window bottom, ensure that we still see a cursor. */
2051 height
= min (glyph
->ascent
+ glyph
->descent
,
2052 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2053 max_y
= window_text_bottom_y (s
->w
) - height
;
2054 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2055 if (s
->ybase
- glyph
->ascent
> max_y
)
2062 /* Don't draw cursor glyph taller than our actual glyph. */
2063 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2064 if (height
< r
.height
)
2066 max_y
= r
.y
+ r
.height
;
2067 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2068 r
.height
= min (max_y
- r
.y
, height
);
2075 XRectangle r_save
= r
;
2077 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2081 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2082 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2084 #ifdef CONVERT_FROM_XRECT
2085 CONVERT_FROM_XRECT (r
, *rects
);
2093 /* If we are processing overlapping and allowed to return
2094 multiple clipping rectangles, we exclude the row of the glyph
2095 string from the clipping rectangle. This is to avoid drawing
2096 the same text on the environment with anti-aliasing. */
2097 #ifdef CONVERT_FROM_XRECT
2100 XRectangle
*rs
= rects
;
2102 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2104 if (s
->for_overlaps
& OVERLAPS_PRED
)
2107 if (r
.y
+ r
.height
> row_y
)
2110 rs
[i
].height
= row_y
- r
.y
;
2116 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2119 if (r
.y
< row_y
+ s
->row
->visible_height
)
2121 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2123 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2124 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2133 #ifdef CONVERT_FROM_XRECT
2134 for (i
= 0; i
< n
; i
++)
2135 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2142 Return in *NR the clipping rectangle for glyph string S. */
2145 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2147 get_glyph_string_clip_rects (s
, nr
, 1);
2152 Return the position and height of the phys cursor in window W.
2153 Set w->phys_cursor_width to width of phys cursor.
2157 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2158 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2160 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2161 int x
, y
, wd
, h
, h0
, y0
;
2163 /* Compute the width of the rectangle to draw. If on a stretch
2164 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2165 rectangle as wide as the glyph, but use a canonical character
2167 wd
= glyph
->pixel_width
- 1;
2168 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2172 x
= w
->phys_cursor
.x
;
2179 if (glyph
->type
== STRETCH_GLYPH
2180 && !x_stretch_cursor_p
)
2181 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2182 w
->phys_cursor_width
= wd
;
2184 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2186 /* If y is below window bottom, ensure that we still see a cursor. */
2187 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2189 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2190 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2192 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2195 h
= max (h
- (y0
- y
) + 1, h0
);
2200 y0
= window_text_bottom_y (w
) - h0
;
2208 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2209 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2214 * Remember which glyph the mouse is over.
2218 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2222 struct glyph_row
*r
, *gr
, *end_row
;
2223 enum window_part part
;
2224 enum glyph_row_area area
;
2225 int x
, y
, width
, height
;
2227 /* Try to determine frame pixel position and size of the glyph under
2228 frame pixel coordinates X/Y on frame F. */
2230 if (!f
->glyphs_initialized_p
2231 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2234 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2235 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2239 w
= XWINDOW (window
);
2240 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2241 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2243 x
= window_relative_x_coord (w
, part
, gx
);
2244 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2246 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2247 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2249 if (w
->pseudo_window_p
)
2252 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2258 case ON_LEFT_MARGIN
:
2259 area
= LEFT_MARGIN_AREA
;
2262 case ON_RIGHT_MARGIN
:
2263 area
= RIGHT_MARGIN_AREA
;
2266 case ON_HEADER_LINE
:
2268 gr
= (part
== ON_HEADER_LINE
2269 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2270 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2273 goto text_glyph_row_found
;
2280 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2281 if (r
->y
+ r
->height
> y
)
2287 text_glyph_row_found
:
2290 struct glyph
*g
= gr
->glyphs
[area
];
2291 struct glyph
*end
= g
+ gr
->used
[area
];
2293 height
= gr
->height
;
2294 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2295 if (gx
+ g
->pixel_width
> x
)
2300 if (g
->type
== IMAGE_GLYPH
)
2302 /* Don't remember when mouse is over image, as
2303 image may have hot-spots. */
2304 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2307 width
= g
->pixel_width
;
2311 /* Use nominal char spacing at end of line. */
2313 gx
+= (x
/ width
) * width
;
2316 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2317 gx
+= window_box_left_offset (w
, area
);
2321 /* Use nominal line height at end of window. */
2322 gx
= (x
/ width
) * width
;
2324 gy
+= (y
/ height
) * height
;
2328 case ON_LEFT_FRINGE
:
2329 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2330 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2331 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2332 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2335 case ON_RIGHT_FRINGE
:
2336 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2337 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2338 : window_box_right_offset (w
, TEXT_AREA
));
2339 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2343 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2345 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2346 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2347 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2349 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2353 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2354 if (r
->y
+ r
->height
> y
)
2361 height
= gr
->height
;
2364 /* Use nominal line height at end of window. */
2366 gy
+= (y
/ height
) * height
;
2373 /* If there is no glyph under the mouse, then we divide the screen
2374 into a grid of the smallest glyph in the frame, and use that
2377 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2378 round down even for negative values. */
2384 gx
= (gx
/ width
) * width
;
2385 gy
= (gy
/ height
) * height
;
2390 gx
+= WINDOW_LEFT_EDGE_X (w
);
2391 gy
+= WINDOW_TOP_EDGE_Y (w
);
2394 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2396 /* Visible feedback for debugging. */
2399 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2400 f
->output_data
.x
->normal_gc
,
2401 gx
, gy
, width
, height
);
2407 #endif /* HAVE_WINDOW_SYSTEM */
2410 /***********************************************************************
2411 Lisp form evaluation
2412 ***********************************************************************/
2414 /* Error handler for safe_eval and safe_call. */
2417 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2419 add_to_log ("Error during redisplay: %S signaled %S",
2420 Flist (nargs
, args
), arg
);
2424 /* Call function FUNC with the rest of NARGS - 1 arguments
2425 following. Return the result, or nil if something went
2426 wrong. Prevent redisplay during the evaluation. */
2429 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2433 if (inhibit_eval_during_redisplay
)
2439 ptrdiff_t count
= SPECPDL_INDEX ();
2440 struct gcpro gcpro1
;
2441 Lisp_Object
*args
= alloca (nargs
* word_size
);
2444 va_start (ap
, func
);
2445 for (i
= 1; i
< nargs
; i
++)
2446 args
[i
] = va_arg (ap
, Lisp_Object
);
2450 gcpro1
.nvars
= nargs
;
2451 specbind (Qinhibit_redisplay
, Qt
);
2452 /* Use Qt to ensure debugger does not run,
2453 so there is no possibility of wanting to redisplay. */
2454 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2457 val
= unbind_to (count
, val
);
2464 /* Call function FN with one argument ARG.
2465 Return the result, or nil if something went wrong. */
2468 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2470 return safe_call (2, fn
, arg
);
2473 static Lisp_Object Qeval
;
2476 safe_eval (Lisp_Object sexpr
)
2478 return safe_call1 (Qeval
, sexpr
);
2481 /* Call function FN with two arguments ARG1 and ARG2.
2482 Return the result, or nil if something went wrong. */
2485 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2487 return safe_call (3, fn
, arg1
, arg2
);
2492 /***********************************************************************
2494 ***********************************************************************/
2498 /* Define CHECK_IT to perform sanity checks on iterators.
2499 This is for debugging. It is too slow to do unconditionally. */
2502 check_it (struct it
*it
)
2504 if (it
->method
== GET_FROM_STRING
)
2506 eassert (STRINGP (it
->string
));
2507 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2511 eassert (IT_STRING_CHARPOS (*it
) < 0);
2512 if (it
->method
== GET_FROM_BUFFER
)
2514 /* Check that character and byte positions agree. */
2515 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2520 eassert (it
->current
.dpvec_index
>= 0);
2522 eassert (it
->current
.dpvec_index
< 0);
2525 #define CHECK_IT(IT) check_it ((IT))
2529 #define CHECK_IT(IT) (void) 0
2534 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2536 /* Check that the window end of window W is what we expect it
2537 to be---the last row in the current matrix displaying text. */
2540 check_window_end (struct window
*w
)
2542 if (!MINI_WINDOW_P (w
)
2543 && !NILP (w
->window_end_valid
))
2545 struct glyph_row
*row
;
2546 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2547 XFASTINT (w
->window_end_vpos
)),
2549 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2550 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2554 #define CHECK_WINDOW_END(W) check_window_end ((W))
2558 #define CHECK_WINDOW_END(W) (void) 0
2560 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2562 /* Return mark position if current buffer has the region of non-zero length,
2566 markpos_of_region (void)
2568 if (!NILP (Vtransient_mark_mode
)
2569 && !NILP (BVAR (current_buffer
, mark_active
))
2570 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2572 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2580 /***********************************************************************
2581 Iterator initialization
2582 ***********************************************************************/
2584 /* Initialize IT for displaying current_buffer in window W, starting
2585 at character position CHARPOS. CHARPOS < 0 means that no buffer
2586 position is specified which is useful when the iterator is assigned
2587 a position later. BYTEPOS is the byte position corresponding to
2588 CHARPOS. BYTEPOS < 0 means compute it from CHARPOS.
2590 If ROW is not null, calls to produce_glyphs with IT as parameter
2591 will produce glyphs in that row.
2593 BASE_FACE_ID is the id of a base face to use. It must be one of
2594 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2595 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2596 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2598 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2599 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2600 will be initialized to use the corresponding mode line glyph row of
2601 the desired matrix of W. */
2604 init_iterator (struct it
*it
, struct window
*w
,
2605 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2606 struct glyph_row
*row
, enum face_id base_face_id
)
2609 enum face_id remapped_base_face_id
= base_face_id
;
2611 /* Some precondition checks. */
2612 eassert (w
!= NULL
&& it
!= NULL
);
2613 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2616 /* If face attributes have been changed since the last redisplay,
2617 free realized faces now because they depend on face definitions
2618 that might have changed. Don't free faces while there might be
2619 desired matrices pending which reference these faces. */
2620 if (face_change_count
&& !inhibit_free_realized_faces
)
2622 face_change_count
= 0;
2623 free_all_realized_faces (Qnil
);
2626 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2627 if (! NILP (Vface_remapping_alist
))
2628 remapped_base_face_id
2629 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2631 /* Use one of the mode line rows of W's desired matrix if
2635 if (base_face_id
== MODE_LINE_FACE_ID
2636 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2637 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2638 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2639 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2643 memset (it
, 0, sizeof *it
);
2644 it
->current
.overlay_string_index
= -1;
2645 it
->current
.dpvec_index
= -1;
2646 it
->base_face_id
= remapped_base_face_id
;
2648 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2649 it
->paragraph_embedding
= L2R
;
2650 it
->bidi_it
.string
.lstring
= Qnil
;
2651 it
->bidi_it
.string
.s
= NULL
;
2652 it
->bidi_it
.string
.bufpos
= 0;
2654 /* The window in which we iterate over current_buffer: */
2655 XSETWINDOW (it
->window
, w
);
2657 it
->f
= XFRAME (w
->frame
);
2661 /* Extra space between lines (on window systems only). */
2662 if (base_face_id
== DEFAULT_FACE_ID
2663 && FRAME_WINDOW_P (it
->f
))
2665 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2666 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2667 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2668 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2669 * FRAME_LINE_HEIGHT (it
->f
));
2670 else if (it
->f
->extra_line_spacing
> 0)
2671 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2672 it
->max_extra_line_spacing
= 0;
2675 /* If realized faces have been removed, e.g. because of face
2676 attribute changes of named faces, recompute them. When running
2677 in batch mode, the face cache of the initial frame is null. If
2678 we happen to get called, make a dummy face cache. */
2679 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2680 init_frame_faces (it
->f
);
2681 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2682 recompute_basic_faces (it
->f
);
2684 /* Current value of the `slice', `space-width', and 'height' properties. */
2685 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2686 it
->space_width
= Qnil
;
2687 it
->font_height
= Qnil
;
2688 it
->override_ascent
= -1;
2690 /* Are control characters displayed as `^C'? */
2691 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2693 /* -1 means everything between a CR and the following line end
2694 is invisible. >0 means lines indented more than this value are
2696 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2698 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2700 : (!NILP (BVAR (current_buffer
, selective_display
))
2702 it
->selective_display_ellipsis_p
2703 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2705 /* Display table to use. */
2706 it
->dp
= window_display_table (w
);
2708 /* Are multibyte characters enabled in current_buffer? */
2709 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2711 /* If visible region is of non-zero length, set IT->region_beg_charpos
2712 and IT->region_end_charpos to the start and end of a visible region
2713 in window IT->w. Set both to -1 to indicate no region. */
2714 markpos
= markpos_of_region ();
2716 /* Maybe highlight only in selected window. */
2717 && (/* Either show region everywhere. */
2718 highlight_nonselected_windows
2719 /* Or show region in the selected window. */
2720 || w
== XWINDOW (selected_window
)
2721 /* Or show the region if we are in the mini-buffer and W is
2722 the window the mini-buffer refers to. */
2723 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2724 && WINDOWP (minibuf_selected_window
)
2725 && w
== XWINDOW (minibuf_selected_window
))))
2727 it
->region_beg_charpos
= min (PT
, markpos
);
2728 it
->region_end_charpos
= max (PT
, markpos
);
2731 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2733 /* Get the position at which the redisplay_end_trigger hook should
2734 be run, if it is to be run at all. */
2735 if (MARKERP (w
->redisplay_end_trigger
)
2736 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2737 it
->redisplay_end_trigger_charpos
2738 = marker_position (w
->redisplay_end_trigger
);
2739 else if (INTEGERP (w
->redisplay_end_trigger
))
2740 it
->redisplay_end_trigger_charpos
=
2741 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2743 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2745 /* Are lines in the display truncated? */
2746 if (base_face_id
!= DEFAULT_FACE_ID
2748 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2749 && ((!NILP (Vtruncate_partial_width_windows
)
2750 && !INTEGERP (Vtruncate_partial_width_windows
))
2751 || (INTEGERP (Vtruncate_partial_width_windows
)
2752 && (WINDOW_TOTAL_COLS (it
->w
)
2753 < XINT (Vtruncate_partial_width_windows
))))))
2754 it
->line_wrap
= TRUNCATE
;
2755 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2756 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2757 ? WINDOW_WRAP
: WORD_WRAP
;
2759 it
->line_wrap
= TRUNCATE
;
2761 /* Get dimensions of truncation and continuation glyphs. These are
2762 displayed as fringe bitmaps under X, but we need them for such
2763 frames when the fringes are turned off. But leave the dimensions
2764 zero for tooltip frames, as these glyphs look ugly there and also
2765 sabotage calculations of tooltip dimensions in x-show-tip. */
2766 #ifdef HAVE_WINDOW_SYSTEM
2767 if (!(FRAME_WINDOW_P (it
->f
)
2768 && FRAMEP (tip_frame
)
2769 && it
->f
== XFRAME (tip_frame
)))
2772 if (it
->line_wrap
== TRUNCATE
)
2774 /* We will need the truncation glyph. */
2775 eassert (it
->glyph_row
== NULL
);
2776 produce_special_glyphs (it
, IT_TRUNCATION
);
2777 it
->truncation_pixel_width
= it
->pixel_width
;
2781 /* We will need the continuation glyph. */
2782 eassert (it
->glyph_row
== NULL
);
2783 produce_special_glyphs (it
, IT_CONTINUATION
);
2784 it
->continuation_pixel_width
= it
->pixel_width
;
2788 /* Reset these values to zero because the produce_special_glyphs
2789 above has changed them. */
2790 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2791 it
->phys_ascent
= it
->phys_descent
= 0;
2793 /* Set this after getting the dimensions of truncation and
2794 continuation glyphs, so that we don't produce glyphs when calling
2795 produce_special_glyphs, above. */
2796 it
->glyph_row
= row
;
2797 it
->area
= TEXT_AREA
;
2799 /* Forget any previous info about this row being reversed. */
2801 it
->glyph_row
->reversed_p
= 0;
2803 /* Get the dimensions of the display area. The display area
2804 consists of the visible window area plus a horizontally scrolled
2805 part to the left of the window. All x-values are relative to the
2806 start of this total display area. */
2807 if (base_face_id
!= DEFAULT_FACE_ID
)
2809 /* Mode lines, menu bar in terminal frames. */
2810 it
->first_visible_x
= 0;
2811 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2815 it
->first_visible_x
=
2816 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2817 it
->last_visible_x
= (it
->first_visible_x
2818 + window_box_width (w
, TEXT_AREA
));
2820 /* If we truncate lines, leave room for the truncation glyph(s) at
2821 the right margin. Otherwise, leave room for the continuation
2822 glyph(s). Done only if the window has no fringes. Since we
2823 don't know at this point whether there will be any R2L lines in
2824 the window, we reserve space for truncation/continuation glyphs
2825 even if only one of the fringes is absent. */
2826 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2827 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2829 if (it
->line_wrap
== TRUNCATE
)
2830 it
->last_visible_x
-= it
->truncation_pixel_width
;
2832 it
->last_visible_x
-= it
->continuation_pixel_width
;
2835 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2836 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2839 /* Leave room for a border glyph. */
2840 if (!FRAME_WINDOW_P (it
->f
)
2841 && !WINDOW_RIGHTMOST_P (it
->w
))
2842 it
->last_visible_x
-= 1;
2844 it
->last_visible_y
= window_text_bottom_y (w
);
2846 /* For mode lines and alike, arrange for the first glyph having a
2847 left box line if the face specifies a box. */
2848 if (base_face_id
!= DEFAULT_FACE_ID
)
2852 it
->face_id
= remapped_base_face_id
;
2854 /* If we have a boxed mode line, make the first character appear
2855 with a left box line. */
2856 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2857 if (face
->box
!= FACE_NO_BOX
)
2858 it
->start_of_box_run_p
= 1;
2861 /* If a buffer position was specified, set the iterator there,
2862 getting overlays and face properties from that position. */
2863 if (charpos
>= BUF_BEG (current_buffer
))
2865 it
->end_charpos
= ZV
;
2866 IT_CHARPOS (*it
) = charpos
;
2868 /* We will rely on `reseat' to set this up properly, via
2869 handle_face_prop. */
2870 it
->face_id
= it
->base_face_id
;
2872 /* Compute byte position if not specified. */
2873 if (bytepos
< charpos
)
2874 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (charpos
);
2876 IT_BYTEPOS (*it
) = bytepos
;
2878 it
->start
= it
->current
;
2879 /* Do we need to reorder bidirectional text? Not if this is a
2880 unibyte buffer: by definition, none of the single-byte
2881 characters are strong R2L, so no reordering is needed. And
2882 bidi.c doesn't support unibyte buffers anyway. Also, don't
2883 reorder while we are loading loadup.el, since the tables of
2884 character properties needed for reordering are not yet
2888 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2891 /* If we are to reorder bidirectional text, init the bidi
2895 /* Note the paragraph direction that this buffer wants to
2897 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2899 it
->paragraph_embedding
= L2R
;
2900 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2902 it
->paragraph_embedding
= R2L
;
2904 it
->paragraph_embedding
= NEUTRAL_DIR
;
2905 bidi_unshelve_cache (NULL
, 0);
2906 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2910 /* Compute faces etc. */
2911 reseat (it
, it
->current
.pos
, 1);
2918 /* Initialize IT for the display of window W with window start POS. */
2921 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2923 struct glyph_row
*row
;
2924 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2926 row
= w
->desired_matrix
->rows
+ first_vpos
;
2927 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2928 it
->first_vpos
= first_vpos
;
2930 /* Don't reseat to previous visible line start if current start
2931 position is in a string or image. */
2932 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2934 int start_at_line_beg_p
;
2935 int first_y
= it
->current_y
;
2937 /* If window start is not at a line start, skip forward to POS to
2938 get the correct continuation lines width. */
2939 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2940 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2941 if (!start_at_line_beg_p
)
2945 reseat_at_previous_visible_line_start (it
);
2946 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2948 new_x
= it
->current_x
+ it
->pixel_width
;
2950 /* If lines are continued, this line may end in the middle
2951 of a multi-glyph character (e.g. a control character
2952 displayed as \003, or in the middle of an overlay
2953 string). In this case move_it_to above will not have
2954 taken us to the start of the continuation line but to the
2955 end of the continued line. */
2956 if (it
->current_x
> 0
2957 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
2958 && (/* And glyph doesn't fit on the line. */
2959 new_x
> it
->last_visible_x
2960 /* Or it fits exactly and we're on a window
2962 || (new_x
== it
->last_visible_x
2963 && FRAME_WINDOW_P (it
->f
)
2964 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
2965 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
2966 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
2968 if ((it
->current
.dpvec_index
>= 0
2969 || it
->current
.overlay_string_index
>= 0)
2970 /* If we are on a newline from a display vector or
2971 overlay string, then we are already at the end of
2972 a screen line; no need to go to the next line in
2973 that case, as this line is not really continued.
2974 (If we do go to the next line, C-e will not DTRT.) */
2977 set_iterator_to_next (it
, 1);
2978 move_it_in_display_line_to (it
, -1, -1, 0);
2981 it
->continuation_lines_width
+= it
->current_x
;
2983 /* If the character at POS is displayed via a display
2984 vector, move_it_to above stops at the final glyph of
2985 IT->dpvec. To make the caller redisplay that character
2986 again (a.k.a. start at POS), we need to reset the
2987 dpvec_index to the beginning of IT->dpvec. */
2988 else if (it
->current
.dpvec_index
>= 0)
2989 it
->current
.dpvec_index
= 0;
2991 /* We're starting a new display line, not affected by the
2992 height of the continued line, so clear the appropriate
2993 fields in the iterator structure. */
2994 it
->max_ascent
= it
->max_descent
= 0;
2995 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
2997 it
->current_y
= first_y
;
2999 it
->current_x
= it
->hpos
= 0;
3005 /* Return 1 if POS is a position in ellipses displayed for invisible
3006 text. W is the window we display, for text property lookup. */
3009 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3011 Lisp_Object prop
, window
;
3013 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3015 /* If POS specifies a position in a display vector, this might
3016 be for an ellipsis displayed for invisible text. We won't
3017 get the iterator set up for delivering that ellipsis unless
3018 we make sure that it gets aware of the invisible text. */
3019 if (pos
->dpvec_index
>= 0
3020 && pos
->overlay_string_index
< 0
3021 && CHARPOS (pos
->string_pos
) < 0
3023 && (XSETWINDOW (window
, w
),
3024 prop
= Fget_char_property (make_number (charpos
),
3025 Qinvisible
, window
),
3026 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3028 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3030 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3037 /* Initialize IT for stepping through current_buffer in window W,
3038 starting at position POS that includes overlay string and display
3039 vector/ control character translation position information. Value
3040 is zero if there are overlay strings with newlines at POS. */
3043 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3045 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3046 int i
, overlay_strings_with_newlines
= 0;
3048 /* If POS specifies a position in a display vector, this might
3049 be for an ellipsis displayed for invisible text. We won't
3050 get the iterator set up for delivering that ellipsis unless
3051 we make sure that it gets aware of the invisible text. */
3052 if (in_ellipses_for_invisible_text_p (pos
, w
))
3058 /* Keep in mind: the call to reseat in init_iterator skips invisible
3059 text, so we might end up at a position different from POS. This
3060 is only a problem when POS is a row start after a newline and an
3061 overlay starts there with an after-string, and the overlay has an
3062 invisible property. Since we don't skip invisible text in
3063 display_line and elsewhere immediately after consuming the
3064 newline before the row start, such a POS will not be in a string,
3065 but the call to init_iterator below will move us to the
3067 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3069 /* This only scans the current chunk -- it should scan all chunks.
3070 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3071 to 16 in 22.1 to make this a lesser problem. */
3072 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3074 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3075 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3077 while (s
< e
&& *s
!= '\n')
3082 overlay_strings_with_newlines
= 1;
3087 /* If position is within an overlay string, set up IT to the right
3089 if (pos
->overlay_string_index
>= 0)
3093 /* If the first overlay string happens to have a `display'
3094 property for an image, the iterator will be set up for that
3095 image, and we have to undo that setup first before we can
3096 correct the overlay string index. */
3097 if (it
->method
== GET_FROM_IMAGE
)
3100 /* We already have the first chunk of overlay strings in
3101 IT->overlay_strings. Load more until the one for
3102 pos->overlay_string_index is in IT->overlay_strings. */
3103 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3105 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3106 it
->current
.overlay_string_index
= 0;
3109 load_overlay_strings (it
, 0);
3110 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3114 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3115 relative_index
= (it
->current
.overlay_string_index
3116 % OVERLAY_STRING_CHUNK_SIZE
);
3117 it
->string
= it
->overlay_strings
[relative_index
];
3118 eassert (STRINGP (it
->string
));
3119 it
->current
.string_pos
= pos
->string_pos
;
3120 it
->method
= GET_FROM_STRING
;
3121 it
->end_charpos
= SCHARS (it
->string
);
3122 /* Set up the bidi iterator for this overlay string. */
3125 it
->bidi_it
.string
.lstring
= it
->string
;
3126 it
->bidi_it
.string
.s
= NULL
;
3127 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3128 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3129 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3130 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3131 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3132 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3134 /* Synchronize the state of the bidi iterator with
3135 pos->string_pos. For any string position other than
3136 zero, this will be done automagically when we resume
3137 iteration over the string and get_visually_first_element
3138 is called. But if string_pos is zero, and the string is
3139 to be reordered for display, we need to resync manually,
3140 since it could be that the iteration state recorded in
3141 pos ended at string_pos of 0 moving backwards in string. */
3142 if (CHARPOS (pos
->string_pos
) == 0)
3144 get_visually_first_element (it
);
3145 if (IT_STRING_CHARPOS (*it
) != 0)
3148 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3149 bidi_move_to_visually_next (&it
->bidi_it
);
3150 } while (it
->bidi_it
.charpos
!= 0);
3152 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3153 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3157 if (CHARPOS (pos
->string_pos
) >= 0)
3159 /* Recorded position is not in an overlay string, but in another
3160 string. This can only be a string from a `display' property.
3161 IT should already be filled with that string. */
3162 it
->current
.string_pos
= pos
->string_pos
;
3163 eassert (STRINGP (it
->string
));
3165 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3166 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3169 /* Restore position in display vector translations, control
3170 character translations or ellipses. */
3171 if (pos
->dpvec_index
>= 0)
3173 if (it
->dpvec
== NULL
)
3174 get_next_display_element (it
);
3175 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3176 it
->current
.dpvec_index
= pos
->dpvec_index
;
3180 return !overlay_strings_with_newlines
;
3184 /* Initialize IT for stepping through current_buffer in window W
3185 starting at ROW->start. */
3188 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3190 init_from_display_pos (it
, w
, &row
->start
);
3191 it
->start
= row
->start
;
3192 it
->continuation_lines_width
= row
->continuation_lines_width
;
3197 /* Initialize IT for stepping through current_buffer in window W
3198 starting in the line following ROW, i.e. starting at ROW->end.
3199 Value is zero if there are overlay strings with newlines at ROW's
3203 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3207 if (init_from_display_pos (it
, w
, &row
->end
))
3209 if (row
->continued_p
)
3210 it
->continuation_lines_width
3211 = row
->continuation_lines_width
+ row
->pixel_width
;
3222 /***********************************************************************
3224 ***********************************************************************/
3226 /* Called when IT reaches IT->stop_charpos. Handle text property and
3227 overlay changes. Set IT->stop_charpos to the next position where
3231 handle_stop (struct it
*it
)
3233 enum prop_handled handled
;
3234 int handle_overlay_change_p
;
3238 it
->current
.dpvec_index
= -1;
3239 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3240 it
->ignore_overlay_strings_at_pos_p
= 0;
3243 /* Use face of preceding text for ellipsis (if invisible) */
3244 if (it
->selective_display_ellipsis_p
)
3245 it
->saved_face_id
= it
->face_id
;
3249 handled
= HANDLED_NORMALLY
;
3251 /* Call text property handlers. */
3252 for (p
= it_props
; p
->handler
; ++p
)
3254 handled
= p
->handler (it
);
3256 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3258 else if (handled
== HANDLED_RETURN
)
3260 /* We still want to show before and after strings from
3261 overlays even if the actual buffer text is replaced. */
3262 if (!handle_overlay_change_p
3264 /* Don't call get_overlay_strings_1 if we already
3265 have overlay strings loaded, because doing so
3266 will load them again and push the iterator state
3267 onto the stack one more time, which is not
3268 expected by the rest of the code that processes
3270 || (it
->current
.overlay_string_index
< 0
3271 ? !get_overlay_strings_1 (it
, 0, 0)
3275 setup_for_ellipsis (it
, 0);
3276 /* When handling a display spec, we might load an
3277 empty string. In that case, discard it here. We
3278 used to discard it in handle_single_display_spec,
3279 but that causes get_overlay_strings_1, above, to
3280 ignore overlay strings that we must check. */
3281 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3285 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3289 it
->ignore_overlay_strings_at_pos_p
= 1;
3290 it
->string_from_display_prop_p
= 0;
3291 it
->from_disp_prop_p
= 0;
3292 handle_overlay_change_p
= 0;
3294 handled
= HANDLED_RECOMPUTE_PROPS
;
3297 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3298 handle_overlay_change_p
= 0;
3301 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3303 /* Don't check for overlay strings below when set to deliver
3304 characters from a display vector. */
3305 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3306 handle_overlay_change_p
= 0;
3308 /* Handle overlay changes.
3309 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3310 if it finds overlays. */
3311 if (handle_overlay_change_p
)
3312 handled
= handle_overlay_change (it
);
3317 setup_for_ellipsis (it
, 0);
3321 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3323 /* Determine where to stop next. */
3324 if (handled
== HANDLED_NORMALLY
)
3325 compute_stop_pos (it
);
3329 /* Compute IT->stop_charpos from text property and overlay change
3330 information for IT's current position. */
3333 compute_stop_pos (struct it
*it
)
3335 register INTERVAL iv
, next_iv
;
3336 Lisp_Object object
, limit
, position
;
3337 ptrdiff_t charpos
, bytepos
;
3339 if (STRINGP (it
->string
))
3341 /* Strings are usually short, so don't limit the search for
3343 it
->stop_charpos
= it
->end_charpos
;
3344 object
= it
->string
;
3346 charpos
= IT_STRING_CHARPOS (*it
);
3347 bytepos
= IT_STRING_BYTEPOS (*it
);
3353 /* If end_charpos is out of range for some reason, such as a
3354 misbehaving display function, rationalize it (Bug#5984). */
3355 if (it
->end_charpos
> ZV
)
3356 it
->end_charpos
= ZV
;
3357 it
->stop_charpos
= it
->end_charpos
;
3359 /* If next overlay change is in front of the current stop pos
3360 (which is IT->end_charpos), stop there. Note: value of
3361 next_overlay_change is point-max if no overlay change
3363 charpos
= IT_CHARPOS (*it
);
3364 bytepos
= IT_BYTEPOS (*it
);
3365 pos
= next_overlay_change (charpos
);
3366 if (pos
< it
->stop_charpos
)
3367 it
->stop_charpos
= pos
;
3369 /* If showing the region, we have to stop at the region
3370 start or end because the face might change there. */
3371 if (it
->region_beg_charpos
> 0)
3373 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3374 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3375 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3376 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3379 /* Set up variables for computing the stop position from text
3380 property changes. */
3381 XSETBUFFER (object
, current_buffer
);
3382 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3385 /* Get the interval containing IT's position. Value is a null
3386 interval if there isn't such an interval. */
3387 position
= make_number (charpos
);
3388 iv
= validate_interval_range (object
, &position
, &position
, 0);
3391 Lisp_Object values_here
[LAST_PROP_IDX
];
3394 /* Get properties here. */
3395 for (p
= it_props
; p
->handler
; ++p
)
3396 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3398 /* Look for an interval following iv that has different
3400 for (next_iv
= next_interval (iv
);
3403 || XFASTINT (limit
) > next_iv
->position
));
3404 next_iv
= next_interval (next_iv
))
3406 for (p
= it_props
; p
->handler
; ++p
)
3408 Lisp_Object new_value
;
3410 new_value
= textget (next_iv
->plist
, *p
->name
);
3411 if (!EQ (values_here
[p
->idx
], new_value
))
3421 if (INTEGERP (limit
)
3422 && next_iv
->position
>= XFASTINT (limit
))
3423 /* No text property change up to limit. */
3424 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3426 /* Text properties change in next_iv. */
3427 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3431 if (it
->cmp_it
.id
< 0)
3433 ptrdiff_t stoppos
= it
->end_charpos
;
3435 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3437 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3438 stoppos
, it
->string
);
3441 eassert (STRINGP (it
->string
)
3442 || (it
->stop_charpos
>= BEGV
3443 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3447 /* Return the position of the next overlay change after POS in
3448 current_buffer. Value is point-max if no overlay change
3449 follows. This is like `next-overlay-change' but doesn't use
3453 next_overlay_change (ptrdiff_t pos
)
3455 ptrdiff_t i
, noverlays
;
3457 Lisp_Object
*overlays
;
3459 /* Get all overlays at the given position. */
3460 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3462 /* If any of these overlays ends before endpos,
3463 use its ending point instead. */
3464 for (i
= 0; i
< noverlays
; ++i
)
3469 oend
= OVERLAY_END (overlays
[i
]);
3470 oendpos
= OVERLAY_POSITION (oend
);
3471 endpos
= min (endpos
, oendpos
);
3477 /* How many characters forward to search for a display property or
3478 display string. Searching too far forward makes the bidi display
3479 sluggish, especially in small windows. */
3480 #define MAX_DISP_SCAN 250
3482 /* Return the character position of a display string at or after
3483 position specified by POSITION. If no display string exists at or
3484 after POSITION, return ZV. A display string is either an overlay
3485 with `display' property whose value is a string, or a `display'
3486 text property whose value is a string. STRING is data about the
3487 string to iterate; if STRING->lstring is nil, we are iterating a
3488 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3489 on a GUI frame. DISP_PROP is set to zero if we searched
3490 MAX_DISP_SCAN characters forward without finding any display
3491 strings, non-zero otherwise. It is set to 2 if the display string
3492 uses any kind of `(space ...)' spec that will produce a stretch of
3493 white space in the text area. */
3495 compute_display_string_pos (struct text_pos
*position
,
3496 struct bidi_string_data
*string
,
3497 int frame_window_p
, int *disp_prop
)
3499 /* OBJECT = nil means current buffer. */
3500 Lisp_Object object
=
3501 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3502 Lisp_Object pos
, spec
, limpos
;
3503 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3504 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3505 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3506 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3508 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3509 struct text_pos tpos
;
3515 /* We don't support display properties whose values are strings
3516 that have display string properties. */
3517 || string
->from_disp_str
3518 /* C strings cannot have display properties. */
3519 || (string
->s
&& !STRINGP (object
)))
3525 /* If the character at CHARPOS is where the display string begins,
3527 pos
= make_number (charpos
);
3528 if (STRINGP (object
))
3529 bufpos
= string
->bufpos
;
3533 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3535 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3538 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3546 /* Look forward for the first character with a `display' property
3547 that will replace the underlying text when displayed. */
3548 limpos
= make_number (lim
);
3550 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, limpos
);
3551 CHARPOS (tpos
) = XFASTINT (pos
);
3552 if (CHARPOS (tpos
) >= lim
)
3557 if (STRINGP (object
))
3558 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3560 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3561 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3562 if (!STRINGP (object
))
3563 bufpos
= CHARPOS (tpos
);
3564 } while (NILP (spec
)
3565 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3566 bufpos
, frame_window_p
)));
3570 return CHARPOS (tpos
);
3573 /* Return the character position of the end of the display string that
3574 started at CHARPOS. If there's no display string at CHARPOS,
3575 return -1. A display string is either an overlay with `display'
3576 property whose value is a string or a `display' text property whose
3577 value is a string. */
3579 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3581 /* OBJECT = nil means current buffer. */
3582 Lisp_Object object
=
3583 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3584 Lisp_Object pos
= make_number (charpos
);
3586 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3588 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3591 /* It could happen that the display property or overlay was removed
3592 since we found it in compute_display_string_pos above. One way
3593 this can happen is if JIT font-lock was called (through
3594 handle_fontified_prop), and jit-lock-functions remove text
3595 properties or overlays from the portion of buffer that includes
3596 CHARPOS. Muse mode is known to do that, for example. In this
3597 case, we return -1 to the caller, to signal that no display
3598 string is actually present at CHARPOS. See bidi_fetch_char for
3599 how this is handled.
3601 An alternative would be to never look for display properties past
3602 it->stop_charpos. But neither compute_display_string_pos nor
3603 bidi_fetch_char that calls it know or care where the next
3605 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3608 /* Look forward for the first character where the `display' property
3610 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3612 return XFASTINT (pos
);
3617 /***********************************************************************
3619 ***********************************************************************/
3621 /* Handle changes in the `fontified' property of the current buffer by
3622 calling hook functions from Qfontification_functions to fontify
3625 static enum prop_handled
3626 handle_fontified_prop (struct it
*it
)
3628 Lisp_Object prop
, pos
;
3629 enum prop_handled handled
= HANDLED_NORMALLY
;
3631 if (!NILP (Vmemory_full
))
3634 /* Get the value of the `fontified' property at IT's current buffer
3635 position. (The `fontified' property doesn't have a special
3636 meaning in strings.) If the value is nil, call functions from
3637 Qfontification_functions. */
3638 if (!STRINGP (it
->string
)
3640 && !NILP (Vfontification_functions
)
3641 && !NILP (Vrun_hooks
)
3642 && (pos
= make_number (IT_CHARPOS (*it
)),
3643 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3644 /* Ignore the special cased nil value always present at EOB since
3645 no amount of fontifying will be able to change it. */
3646 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3648 ptrdiff_t count
= SPECPDL_INDEX ();
3650 struct buffer
*obuf
= current_buffer
;
3651 int begv
= BEGV
, zv
= ZV
;
3652 int old_clip_changed
= current_buffer
->clip_changed
;
3654 val
= Vfontification_functions
;
3655 specbind (Qfontification_functions
, Qnil
);
3657 eassert (it
->end_charpos
== ZV
);
3659 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3660 safe_call1 (val
, pos
);
3663 Lisp_Object fns
, fn
;
3664 struct gcpro gcpro1
, gcpro2
;
3669 for (; CONSP (val
); val
= XCDR (val
))
3675 /* A value of t indicates this hook has a local
3676 binding; it means to run the global binding too.
3677 In a global value, t should not occur. If it
3678 does, we must ignore it to avoid an endless
3680 for (fns
= Fdefault_value (Qfontification_functions
);
3686 safe_call1 (fn
, pos
);
3690 safe_call1 (fn
, pos
);
3696 unbind_to (count
, Qnil
);
3698 /* Fontification functions routinely call `save-restriction'.
3699 Normally, this tags clip_changed, which can confuse redisplay
3700 (see discussion in Bug#6671). Since we don't perform any
3701 special handling of fontification changes in the case where
3702 `save-restriction' isn't called, there's no point doing so in
3703 this case either. So, if the buffer's restrictions are
3704 actually left unchanged, reset clip_changed. */
3705 if (obuf
== current_buffer
)
3707 if (begv
== BEGV
&& zv
== ZV
)
3708 current_buffer
->clip_changed
= old_clip_changed
;
3710 /* There isn't much we can reasonably do to protect against
3711 misbehaving fontification, but here's a fig leaf. */
3712 else if (BUFFER_LIVE_P (obuf
))
3713 set_buffer_internal_1 (obuf
);
3715 /* The fontification code may have added/removed text.
3716 It could do even a lot worse, but let's at least protect against
3717 the most obvious case where only the text past `pos' gets changed',
3718 as is/was done in grep.el where some escapes sequences are turned
3719 into face properties (bug#7876). */
3720 it
->end_charpos
= ZV
;
3722 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3723 something. This avoids an endless loop if they failed to
3724 fontify the text for which reason ever. */
3725 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3726 handled
= HANDLED_RECOMPUTE_PROPS
;
3734 /***********************************************************************
3736 ***********************************************************************/
3738 /* Set up iterator IT from face properties at its current position.
3739 Called from handle_stop. */
3741 static enum prop_handled
3742 handle_face_prop (struct it
*it
)
3745 ptrdiff_t next_stop
;
3747 if (!STRINGP (it
->string
))
3750 = face_at_buffer_position (it
->w
,
3752 it
->region_beg_charpos
,
3753 it
->region_end_charpos
,
3756 + TEXT_PROP_DISTANCE_LIMIT
),
3757 0, it
->base_face_id
);
3759 /* Is this a start of a run of characters with box face?
3760 Caveat: this can be called for a freshly initialized
3761 iterator; face_id is -1 in this case. We know that the new
3762 face will not change until limit, i.e. if the new face has a
3763 box, all characters up to limit will have one. But, as
3764 usual, we don't know whether limit is really the end. */
3765 if (new_face_id
!= it
->face_id
)
3767 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3768 /* If it->face_id is -1, old_face below will be NULL, see
3769 the definition of FACE_FROM_ID. This will happen if this
3770 is the initial call that gets the face. */
3771 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3773 /* If the value of face_id of the iterator is -1, we have to
3774 look in front of IT's position and see whether there is a
3775 face there that's different from new_face_id. */
3776 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3778 int prev_face_id
= face_before_it_pos (it
);
3780 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3783 /* If the new face has a box, but the old face does not,
3784 this is the start of a run of characters with box face,
3785 i.e. this character has a shadow on the left side. */
3786 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3787 && (old_face
== NULL
|| !old_face
->box
));
3788 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3796 Lisp_Object from_overlay
3797 = (it
->current
.overlay_string_index
>= 0
3798 ? it
->string_overlays
[it
->current
.overlay_string_index
3799 % OVERLAY_STRING_CHUNK_SIZE
]
3802 /* See if we got to this string directly or indirectly from
3803 an overlay property. That includes the before-string or
3804 after-string of an overlay, strings in display properties
3805 provided by an overlay, their text properties, etc.
3807 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3808 if (! NILP (from_overlay
))
3809 for (i
= it
->sp
- 1; i
>= 0; i
--)
3811 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3813 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3814 % OVERLAY_STRING_CHUNK_SIZE
];
3815 else if (! NILP (it
->stack
[i
].from_overlay
))
3816 from_overlay
= it
->stack
[i
].from_overlay
;
3818 if (!NILP (from_overlay
))
3822 if (! NILP (from_overlay
))
3824 bufpos
= IT_CHARPOS (*it
);
3825 /* For a string from an overlay, the base face depends
3826 only on text properties and ignores overlays. */
3828 = face_for_overlay_string (it
->w
,
3830 it
->region_beg_charpos
,
3831 it
->region_end_charpos
,
3834 + TEXT_PROP_DISTANCE_LIMIT
),
3842 /* For strings from a `display' property, use the face at
3843 IT's current buffer position as the base face to merge
3844 with, so that overlay strings appear in the same face as
3845 surrounding text, unless they specify their own
3847 base_face_id
= it
->string_from_prefix_prop_p
3849 : underlying_face_id (it
);
3852 new_face_id
= face_at_string_position (it
->w
,
3854 IT_STRING_CHARPOS (*it
),
3856 it
->region_beg_charpos
,
3857 it
->region_end_charpos
,
3861 /* Is this a start of a run of characters with box? Caveat:
3862 this can be called for a freshly allocated iterator; face_id
3863 is -1 is this case. We know that the new face will not
3864 change until the next check pos, i.e. if the new face has a
3865 box, all characters up to that position will have a
3866 box. But, as usual, we don't know whether that position
3867 is really the end. */
3868 if (new_face_id
!= it
->face_id
)
3870 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3871 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3873 /* If new face has a box but old face hasn't, this is the
3874 start of a run of characters with box, i.e. it has a
3875 shadow on the left side. */
3876 it
->start_of_box_run_p
3877 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3878 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3882 it
->face_id
= new_face_id
;
3883 return HANDLED_NORMALLY
;
3887 /* Return the ID of the face ``underlying'' IT's current position,
3888 which is in a string. If the iterator is associated with a
3889 buffer, return the face at IT's current buffer position.
3890 Otherwise, use the iterator's base_face_id. */
3893 underlying_face_id (struct it
*it
)
3895 int face_id
= it
->base_face_id
, i
;
3897 eassert (STRINGP (it
->string
));
3899 for (i
= it
->sp
- 1; i
>= 0; --i
)
3900 if (NILP (it
->stack
[i
].string
))
3901 face_id
= it
->stack
[i
].face_id
;
3907 /* Compute the face one character before or after the current position
3908 of IT, in the visual order. BEFORE_P non-zero means get the face
3909 in front (to the left in L2R paragraphs, to the right in R2L
3910 paragraphs) of IT's screen position. Value is the ID of the face. */
3913 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3916 ptrdiff_t next_check_charpos
;
3918 void *it_copy_data
= NULL
;
3920 eassert (it
->s
== NULL
);
3922 if (STRINGP (it
->string
))
3924 ptrdiff_t bufpos
, charpos
;
3927 /* No face change past the end of the string (for the case
3928 we are padding with spaces). No face change before the
3930 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3931 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3936 /* Set charpos to the position before or after IT's current
3937 position, in the logical order, which in the non-bidi
3938 case is the same as the visual order. */
3940 charpos
= IT_STRING_CHARPOS (*it
) - 1;
3941 else if (it
->what
== IT_COMPOSITION
)
3942 /* For composition, we must check the character after the
3944 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
3946 charpos
= IT_STRING_CHARPOS (*it
) + 1;
3952 /* With bidi iteration, the character before the current
3953 in the visual order cannot be found by simple
3954 iteration, because "reverse" reordering is not
3955 supported. Instead, we need to use the move_it_*
3956 family of functions. */
3957 /* Ignore face changes before the first visible
3958 character on this display line. */
3959 if (it
->current_x
<= it
->first_visible_x
)
3961 SAVE_IT (it_copy
, *it
, it_copy_data
);
3962 /* Implementation note: Since move_it_in_display_line
3963 works in the iterator geometry, and thinks the first
3964 character is always the leftmost, even in R2L lines,
3965 we don't need to distinguish between the R2L and L2R
3967 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
3968 it_copy
.current_x
- 1, MOVE_TO_X
);
3969 charpos
= IT_STRING_CHARPOS (it_copy
);
3970 RESTORE_IT (it
, it
, it_copy_data
);
3974 /* Set charpos to the string position of the character
3975 that comes after IT's current position in the visual
3977 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
3981 bidi_move_to_visually_next (&it_copy
.bidi_it
);
3983 charpos
= it_copy
.bidi_it
.charpos
;
3986 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
3988 if (it
->current
.overlay_string_index
>= 0)
3989 bufpos
= IT_CHARPOS (*it
);
3993 base_face_id
= underlying_face_id (it
);
3995 /* Get the face for ASCII, or unibyte. */
3996 face_id
= face_at_string_position (it
->w
,
4000 it
->region_beg_charpos
,
4001 it
->region_end_charpos
,
4002 &next_check_charpos
,
4005 /* Correct the face for charsets different from ASCII. Do it
4006 for the multibyte case only. The face returned above is
4007 suitable for unibyte text if IT->string is unibyte. */
4008 if (STRING_MULTIBYTE (it
->string
))
4010 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4011 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4013 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4015 c
= string_char_and_length (p
, &len
);
4016 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4021 struct text_pos pos
;
4023 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4024 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4027 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4028 pos
= it
->current
.pos
;
4033 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4036 if (it
->what
== IT_COMPOSITION
)
4038 /* For composition, we must check the position after
4040 pos
.charpos
+= it
->cmp_it
.nchars
;
4041 pos
.bytepos
+= it
->len
;
4044 INC_TEXT_POS (pos
, it
->multibyte_p
);
4051 /* With bidi iteration, the character before the current
4052 in the visual order cannot be found by simple
4053 iteration, because "reverse" reordering is not
4054 supported. Instead, we need to use the move_it_*
4055 family of functions. */
4056 /* Ignore face changes before the first visible
4057 character on this display line. */
4058 if (it
->current_x
<= it
->first_visible_x
)
4060 SAVE_IT (it_copy
, *it
, it_copy_data
);
4061 /* Implementation note: Since move_it_in_display_line
4062 works in the iterator geometry, and thinks the first
4063 character is always the leftmost, even in R2L lines,
4064 we don't need to distinguish between the R2L and L2R
4066 move_it_in_display_line (&it_copy
, ZV
,
4067 it_copy
.current_x
- 1, MOVE_TO_X
);
4068 pos
= it_copy
.current
.pos
;
4069 RESTORE_IT (it
, it
, it_copy_data
);
4073 /* Set charpos to the buffer position of the character
4074 that comes after IT's current position in the visual
4076 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4080 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4083 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4086 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4088 /* Determine face for CHARSET_ASCII, or unibyte. */
4089 face_id
= face_at_buffer_position (it
->w
,
4091 it
->region_beg_charpos
,
4092 it
->region_end_charpos
,
4093 &next_check_charpos
,
4096 /* Correct the face for charsets different from ASCII. Do it
4097 for the multibyte case only. The face returned above is
4098 suitable for unibyte text if current_buffer is unibyte. */
4099 if (it
->multibyte_p
)
4101 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4102 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4103 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4112 /***********************************************************************
4114 ***********************************************************************/
4116 /* Set up iterator IT from invisible properties at its current
4117 position. Called from handle_stop. */
4119 static enum prop_handled
4120 handle_invisible_prop (struct it
*it
)
4122 enum prop_handled handled
= HANDLED_NORMALLY
;
4126 if (STRINGP (it
->string
))
4128 Lisp_Object end_charpos
, limit
, charpos
;
4130 /* Get the value of the invisible text property at the
4131 current position. Value will be nil if there is no such
4133 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4134 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4135 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4137 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4139 /* Record whether we have to display an ellipsis for the
4141 int display_ellipsis_p
= (invis_p
== 2);
4142 ptrdiff_t len
, endpos
;
4144 handled
= HANDLED_RECOMPUTE_PROPS
;
4146 /* Get the position at which the next visible text can be
4147 found in IT->string, if any. */
4148 endpos
= len
= SCHARS (it
->string
);
4149 XSETINT (limit
, len
);
4152 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4154 if (INTEGERP (end_charpos
))
4156 endpos
= XFASTINT (end_charpos
);
4157 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4158 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4160 display_ellipsis_p
= 1;
4163 while (invis_p
&& endpos
< len
);
4165 if (display_ellipsis_p
)
4170 /* Text at END_CHARPOS is visible. Move IT there. */
4171 struct text_pos old
;
4174 old
= it
->current
.string_pos
;
4175 oldpos
= CHARPOS (old
);
4178 if (it
->bidi_it
.first_elt
4179 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4180 bidi_paragraph_init (it
->paragraph_embedding
,
4182 /* Bidi-iterate out of the invisible text. */
4185 bidi_move_to_visually_next (&it
->bidi_it
);
4187 while (oldpos
<= it
->bidi_it
.charpos
4188 && it
->bidi_it
.charpos
< endpos
);
4190 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4191 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4192 if (IT_CHARPOS (*it
) >= endpos
)
4193 it
->prev_stop
= endpos
;
4197 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4198 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4203 /* The rest of the string is invisible. If this is an
4204 overlay string, proceed with the next overlay string
4205 or whatever comes and return a character from there. */
4206 if (it
->current
.overlay_string_index
>= 0
4207 && !display_ellipsis_p
)
4209 next_overlay_string (it
);
4210 /* Don't check for overlay strings when we just
4211 finished processing them. */
4212 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4216 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4217 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4224 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4225 Lisp_Object pos
, overlay
;
4227 /* First of all, is there invisible text at this position? */
4228 tem
= start_charpos
= IT_CHARPOS (*it
);
4229 pos
= make_number (tem
);
4230 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4232 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4234 /* If we are on invisible text, skip over it. */
4235 if (invis_p
&& start_charpos
< it
->end_charpos
)
4237 /* Record whether we have to display an ellipsis for the
4239 int display_ellipsis_p
= invis_p
== 2;
4241 handled
= HANDLED_RECOMPUTE_PROPS
;
4243 /* Loop skipping over invisible text. The loop is left at
4244 ZV or with IT on the first char being visible again. */
4247 /* Try to skip some invisible text. Return value is the
4248 position reached which can be equal to where we start
4249 if there is nothing invisible there. This skips both
4250 over invisible text properties and overlays with
4251 invisible property. */
4252 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4254 /* If we skipped nothing at all we weren't at invisible
4255 text in the first place. If everything to the end of
4256 the buffer was skipped, end the loop. */
4257 if (newpos
== tem
|| newpos
>= ZV
)
4261 /* We skipped some characters but not necessarily
4262 all there are. Check if we ended up on visible
4263 text. Fget_char_property returns the property of
4264 the char before the given position, i.e. if we
4265 get invis_p = 0, this means that the char at
4266 newpos is visible. */
4267 pos
= make_number (newpos
);
4268 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4269 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4272 /* If we ended up on invisible text, proceed to
4273 skip starting with next_stop. */
4277 /* If there are adjacent invisible texts, don't lose the
4278 second one's ellipsis. */
4280 display_ellipsis_p
= 1;
4284 /* The position newpos is now either ZV or on visible text. */
4287 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4289 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4291 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4293 /* If the invisible text ends on a newline or on a
4294 character after a newline, we can avoid the costly,
4295 character by character, bidi iteration to NEWPOS, and
4296 instead simply reseat the iterator there. That's
4297 because all bidi reordering information is tossed at
4298 the newline. This is a big win for modes that hide
4299 complete lines, like Outline, Org, etc. */
4300 if (on_newline
|| after_newline
)
4302 struct text_pos tpos
;
4303 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4305 SET_TEXT_POS (tpos
, newpos
, bpos
);
4306 reseat_1 (it
, tpos
, 0);
4307 /* If we reseat on a newline/ZV, we need to prep the
4308 bidi iterator for advancing to the next character
4309 after the newline/EOB, keeping the current paragraph
4310 direction (so that PRODUCE_GLYPHS does TRT wrt
4311 prepending/appending glyphs to a glyph row). */
4314 it
->bidi_it
.first_elt
= 0;
4315 it
->bidi_it
.paragraph_dir
= pdir
;
4316 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4317 it
->bidi_it
.nchars
= 1;
4318 it
->bidi_it
.ch_len
= 1;
4321 else /* Must use the slow method. */
4323 /* With bidi iteration, the region of invisible text
4324 could start and/or end in the middle of a
4325 non-base embedding level. Therefore, we need to
4326 skip invisible text using the bidi iterator,
4327 starting at IT's current position, until we find
4328 ourselves outside of the invisible text.
4329 Skipping invisible text _after_ bidi iteration
4330 avoids affecting the visual order of the
4331 displayed text when invisible properties are
4332 added or removed. */
4333 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4335 /* If we were `reseat'ed to a new paragraph,
4336 determine the paragraph base direction. We
4337 need to do it now because
4338 next_element_from_buffer may not have a
4339 chance to do it, if we are going to skip any
4340 text at the beginning, which resets the
4342 bidi_paragraph_init (it
->paragraph_embedding
,
4347 bidi_move_to_visually_next (&it
->bidi_it
);
4349 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4350 && it
->bidi_it
.charpos
< newpos
);
4351 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4352 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4353 /* If we overstepped NEWPOS, record its position in
4354 the iterator, so that we skip invisible text if
4355 later the bidi iteration lands us in the
4356 invisible region again. */
4357 if (IT_CHARPOS (*it
) >= newpos
)
4358 it
->prev_stop
= newpos
;
4363 IT_CHARPOS (*it
) = newpos
;
4364 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4367 /* If there are before-strings at the start of invisible
4368 text, and the text is invisible because of a text
4369 property, arrange to show before-strings because 20.x did
4370 it that way. (If the text is invisible because of an
4371 overlay property instead of a text property, this is
4372 already handled in the overlay code.) */
4374 && get_overlay_strings (it
, it
->stop_charpos
))
4376 handled
= HANDLED_RECOMPUTE_PROPS
;
4377 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4379 else if (display_ellipsis_p
)
4381 /* Make sure that the glyphs of the ellipsis will get
4382 correct `charpos' values. If we would not update
4383 it->position here, the glyphs would belong to the
4384 last visible character _before_ the invisible
4385 text, which confuses `set_cursor_from_row'.
4387 We use the last invisible position instead of the
4388 first because this way the cursor is always drawn on
4389 the first "." of the ellipsis, whenever PT is inside
4390 the invisible text. Otherwise the cursor would be
4391 placed _after_ the ellipsis when the point is after the
4392 first invisible character. */
4393 if (!STRINGP (it
->object
))
4395 it
->position
.charpos
= newpos
- 1;
4396 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4399 /* Let the ellipsis display before
4400 considering any properties of the following char.
4401 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4402 handled
= HANDLED_RETURN
;
4411 /* Make iterator IT return `...' next.
4412 Replaces LEN characters from buffer. */
4415 setup_for_ellipsis (struct it
*it
, int len
)
4417 /* Use the display table definition for `...'. Invalid glyphs
4418 will be handled by the method returning elements from dpvec. */
4419 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4421 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4422 it
->dpvec
= v
->contents
;
4423 it
->dpend
= v
->contents
+ v
->header
.size
;
4427 /* Default `...'. */
4428 it
->dpvec
= default_invis_vector
;
4429 it
->dpend
= default_invis_vector
+ 3;
4432 it
->dpvec_char_len
= len
;
4433 it
->current
.dpvec_index
= 0;
4434 it
->dpvec_face_id
= -1;
4436 /* Remember the current face id in case glyphs specify faces.
4437 IT's face is restored in set_iterator_to_next.
4438 saved_face_id was set to preceding char's face in handle_stop. */
4439 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4440 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4442 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4448 /***********************************************************************
4450 ***********************************************************************/
4452 /* Set up iterator IT from `display' property at its current position.
4453 Called from handle_stop.
4454 We return HANDLED_RETURN if some part of the display property
4455 overrides the display of the buffer text itself.
4456 Otherwise we return HANDLED_NORMALLY. */
4458 static enum prop_handled
4459 handle_display_prop (struct it
*it
)
4461 Lisp_Object propval
, object
, overlay
;
4462 struct text_pos
*position
;
4464 /* Nonzero if some property replaces the display of the text itself. */
4465 int display_replaced_p
= 0;
4467 if (STRINGP (it
->string
))
4469 object
= it
->string
;
4470 position
= &it
->current
.string_pos
;
4471 bufpos
= CHARPOS (it
->current
.pos
);
4475 XSETWINDOW (object
, it
->w
);
4476 position
= &it
->current
.pos
;
4477 bufpos
= CHARPOS (*position
);
4480 /* Reset those iterator values set from display property values. */
4481 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4482 it
->space_width
= Qnil
;
4483 it
->font_height
= Qnil
;
4486 /* We don't support recursive `display' properties, i.e. string
4487 values that have a string `display' property, that have a string
4488 `display' property etc. */
4489 if (!it
->string_from_display_prop_p
)
4490 it
->area
= TEXT_AREA
;
4492 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4493 Qdisplay
, object
, &overlay
);
4495 return HANDLED_NORMALLY
;
4496 /* Now OVERLAY is the overlay that gave us this property, or nil
4497 if it was a text property. */
4499 if (!STRINGP (it
->string
))
4500 object
= it
->w
->buffer
;
4502 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4504 FRAME_WINDOW_P (it
->f
));
4506 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4509 /* Subroutine of handle_display_prop. Returns non-zero if the display
4510 specification in SPEC is a replacing specification, i.e. it would
4511 replace the text covered by `display' property with something else,
4512 such as an image or a display string. If SPEC includes any kind or
4513 `(space ...) specification, the value is 2; this is used by
4514 compute_display_string_pos, which see.
4516 See handle_single_display_spec for documentation of arguments.
4517 frame_window_p is non-zero if the window being redisplayed is on a
4518 GUI frame; this argument is used only if IT is NULL, see below.
4520 IT can be NULL, if this is called by the bidi reordering code
4521 through compute_display_string_pos, which see. In that case, this
4522 function only examines SPEC, but does not otherwise "handle" it, in
4523 the sense that it doesn't set up members of IT from the display
4526 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4527 Lisp_Object overlay
, struct text_pos
*position
,
4528 ptrdiff_t bufpos
, int frame_window_p
)
4530 int replacing_p
= 0;
4534 /* Simple specifications. */
4535 && !EQ (XCAR (spec
), Qimage
)
4536 && !EQ (XCAR (spec
), Qspace
)
4537 && !EQ (XCAR (spec
), Qwhen
)
4538 && !EQ (XCAR (spec
), Qslice
)
4539 && !EQ (XCAR (spec
), Qspace_width
)
4540 && !EQ (XCAR (spec
), Qheight
)
4541 && !EQ (XCAR (spec
), Qraise
)
4542 /* Marginal area specifications. */
4543 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4544 && !EQ (XCAR (spec
), Qleft_fringe
)
4545 && !EQ (XCAR (spec
), Qright_fringe
)
4546 && !NILP (XCAR (spec
)))
4548 for (; CONSP (spec
); spec
= XCDR (spec
))
4550 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4551 overlay
, position
, bufpos
,
4552 replacing_p
, frame_window_p
)))
4555 /* If some text in a string is replaced, `position' no
4556 longer points to the position of `object'. */
4557 if (!it
|| STRINGP (object
))
4562 else if (VECTORP (spec
))
4565 for (i
= 0; i
< ASIZE (spec
); ++i
)
4566 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4567 overlay
, position
, bufpos
,
4568 replacing_p
, frame_window_p
)))
4571 /* If some text in a string is replaced, `position' no
4572 longer points to the position of `object'. */
4573 if (!it
|| STRINGP (object
))
4579 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4580 position
, bufpos
, 0,
4588 /* Value is the position of the end of the `display' property starting
4589 at START_POS in OBJECT. */
4591 static struct text_pos
4592 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4595 struct text_pos end_pos
;
4597 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4598 Qdisplay
, object
, Qnil
);
4599 CHARPOS (end_pos
) = XFASTINT (end
);
4600 if (STRINGP (object
))
4601 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4603 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4609 /* Set up IT from a single `display' property specification SPEC. OBJECT
4610 is the object in which the `display' property was found. *POSITION
4611 is the position in OBJECT at which the `display' property was found.
4612 BUFPOS is the buffer position of OBJECT (different from POSITION if
4613 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4614 previously saw a display specification which already replaced text
4615 display with something else, for example an image; we ignore such
4616 properties after the first one has been processed.
4618 OVERLAY is the overlay this `display' property came from,
4619 or nil if it was a text property.
4621 If SPEC is a `space' or `image' specification, and in some other
4622 cases too, set *POSITION to the position where the `display'
4625 If IT is NULL, only examine the property specification in SPEC, but
4626 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4627 is intended to be displayed in a window on a GUI frame.
4629 Value is non-zero if something was found which replaces the display
4630 of buffer or string text. */
4633 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4634 Lisp_Object overlay
, struct text_pos
*position
,
4635 ptrdiff_t bufpos
, int display_replaced_p
,
4639 Lisp_Object location
, value
;
4640 struct text_pos start_pos
= *position
;
4643 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4644 If the result is non-nil, use VALUE instead of SPEC. */
4646 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4655 if (!NILP (form
) && !EQ (form
, Qt
))
4657 ptrdiff_t count
= SPECPDL_INDEX ();
4658 struct gcpro gcpro1
;
4660 /* Bind `object' to the object having the `display' property, a
4661 buffer or string. Bind `position' to the position in the
4662 object where the property was found, and `buffer-position'
4663 to the current position in the buffer. */
4666 XSETBUFFER (object
, current_buffer
);
4667 specbind (Qobject
, object
);
4668 specbind (Qposition
, make_number (CHARPOS (*position
)));
4669 specbind (Qbuffer_position
, make_number (bufpos
));
4671 form
= safe_eval (form
);
4673 unbind_to (count
, Qnil
);
4679 /* Handle `(height HEIGHT)' specifications. */
4681 && EQ (XCAR (spec
), Qheight
)
4682 && CONSP (XCDR (spec
)))
4686 if (!FRAME_WINDOW_P (it
->f
))
4689 it
->font_height
= XCAR (XCDR (spec
));
4690 if (!NILP (it
->font_height
))
4692 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4693 int new_height
= -1;
4695 if (CONSP (it
->font_height
)
4696 && (EQ (XCAR (it
->font_height
), Qplus
)
4697 || EQ (XCAR (it
->font_height
), Qminus
))
4698 && CONSP (XCDR (it
->font_height
))
4699 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4701 /* `(+ N)' or `(- N)' where N is an integer. */
4702 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4703 if (EQ (XCAR (it
->font_height
), Qplus
))
4705 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4707 else if (FUNCTIONP (it
->font_height
))
4709 /* Call function with current height as argument.
4710 Value is the new height. */
4712 height
= safe_call1 (it
->font_height
,
4713 face
->lface
[LFACE_HEIGHT_INDEX
]);
4714 if (NUMBERP (height
))
4715 new_height
= XFLOATINT (height
);
4717 else if (NUMBERP (it
->font_height
))
4719 /* Value is a multiple of the canonical char height. */
4722 f
= FACE_FROM_ID (it
->f
,
4723 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4724 new_height
= (XFLOATINT (it
->font_height
)
4725 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4729 /* Evaluate IT->font_height with `height' bound to the
4730 current specified height to get the new height. */
4731 ptrdiff_t count
= SPECPDL_INDEX ();
4733 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4734 value
= safe_eval (it
->font_height
);
4735 unbind_to (count
, Qnil
);
4737 if (NUMBERP (value
))
4738 new_height
= XFLOATINT (value
);
4742 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4749 /* Handle `(space-width WIDTH)'. */
4751 && EQ (XCAR (spec
), Qspace_width
)
4752 && CONSP (XCDR (spec
)))
4756 if (!FRAME_WINDOW_P (it
->f
))
4759 value
= XCAR (XCDR (spec
));
4760 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4761 it
->space_width
= value
;
4767 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4769 && EQ (XCAR (spec
), Qslice
))
4775 if (!FRAME_WINDOW_P (it
->f
))
4778 if (tem
= XCDR (spec
), CONSP (tem
))
4780 it
->slice
.x
= XCAR (tem
);
4781 if (tem
= XCDR (tem
), CONSP (tem
))
4783 it
->slice
.y
= XCAR (tem
);
4784 if (tem
= XCDR (tem
), CONSP (tem
))
4786 it
->slice
.width
= XCAR (tem
);
4787 if (tem
= XCDR (tem
), CONSP (tem
))
4788 it
->slice
.height
= XCAR (tem
);
4797 /* Handle `(raise FACTOR)'. */
4799 && EQ (XCAR (spec
), Qraise
)
4800 && CONSP (XCDR (spec
)))
4804 if (!FRAME_WINDOW_P (it
->f
))
4807 #ifdef HAVE_WINDOW_SYSTEM
4808 value
= XCAR (XCDR (spec
));
4809 if (NUMBERP (value
))
4811 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4812 it
->voffset
= - (XFLOATINT (value
)
4813 * (FONT_HEIGHT (face
->font
)));
4815 #endif /* HAVE_WINDOW_SYSTEM */
4821 /* Don't handle the other kinds of display specifications
4822 inside a string that we got from a `display' property. */
4823 if (it
&& it
->string_from_display_prop_p
)
4826 /* Characters having this form of property are not displayed, so
4827 we have to find the end of the property. */
4830 start_pos
= *position
;
4831 *position
= display_prop_end (it
, object
, start_pos
);
4835 /* Stop the scan at that end position--we assume that all
4836 text properties change there. */
4838 it
->stop_charpos
= position
->charpos
;
4840 /* Handle `(left-fringe BITMAP [FACE])'
4841 and `(right-fringe BITMAP [FACE])'. */
4843 && (EQ (XCAR (spec
), Qleft_fringe
)
4844 || EQ (XCAR (spec
), Qright_fringe
))
4845 && CONSP (XCDR (spec
)))
4851 if (!FRAME_WINDOW_P (it
->f
))
4852 /* If we return here, POSITION has been advanced
4853 across the text with this property. */
4855 /* Synchronize the bidi iterator with POSITION. This is
4856 needed because we are not going to push the iterator
4857 on behalf of this display property, so there will be
4858 no pop_it call to do this synchronization for us. */
4861 it
->position
= *position
;
4862 iterate_out_of_display_property (it
);
4863 *position
= it
->position
;
4868 else if (!frame_window_p
)
4871 #ifdef HAVE_WINDOW_SYSTEM
4872 value
= XCAR (XCDR (spec
));
4873 if (!SYMBOLP (value
)
4874 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4875 /* If we return here, POSITION has been advanced
4876 across the text with this property. */
4878 if (it
&& it
->bidi_p
)
4880 it
->position
= *position
;
4881 iterate_out_of_display_property (it
);
4882 *position
= it
->position
;
4889 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4891 if (CONSP (XCDR (XCDR (spec
))))
4893 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4894 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4900 /* Save current settings of IT so that we can restore them
4901 when we are finished with the glyph property value. */
4902 push_it (it
, position
);
4904 it
->area
= TEXT_AREA
;
4905 it
->what
= IT_IMAGE
;
4906 it
->image_id
= -1; /* no image */
4907 it
->position
= start_pos
;
4908 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
4909 it
->method
= GET_FROM_IMAGE
;
4910 it
->from_overlay
= Qnil
;
4911 it
->face_id
= face_id
;
4912 it
->from_disp_prop_p
= 1;
4914 /* Say that we haven't consumed the characters with
4915 `display' property yet. The call to pop_it in
4916 set_iterator_to_next will clean this up. */
4917 *position
= start_pos
;
4919 if (EQ (XCAR (spec
), Qleft_fringe
))
4921 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4922 it
->left_user_fringe_face_id
= face_id
;
4926 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4927 it
->right_user_fringe_face_id
= face_id
;
4930 #endif /* HAVE_WINDOW_SYSTEM */
4934 /* Prepare to handle `((margin left-margin) ...)',
4935 `((margin right-margin) ...)' and `((margin nil) ...)'
4936 prefixes for display specifications. */
4937 location
= Qunbound
;
4938 if (CONSP (spec
) && CONSP (XCAR (spec
)))
4942 value
= XCDR (spec
);
4944 value
= XCAR (value
);
4947 if (EQ (XCAR (tem
), Qmargin
)
4948 && (tem
= XCDR (tem
),
4949 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
4951 || EQ (tem
, Qleft_margin
)
4952 || EQ (tem
, Qright_margin
))))
4956 if (EQ (location
, Qunbound
))
4962 /* After this point, VALUE is the property after any
4963 margin prefix has been stripped. It must be a string,
4964 an image specification, or `(space ...)'.
4966 LOCATION specifies where to display: `left-margin',
4967 `right-margin' or nil. */
4969 valid_p
= (STRINGP (value
)
4970 #ifdef HAVE_WINDOW_SYSTEM
4971 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
4972 && valid_image_p (value
))
4973 #endif /* not HAVE_WINDOW_SYSTEM */
4974 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
4976 if (valid_p
&& !display_replaced_p
)
4982 /* Callers need to know whether the display spec is any kind
4983 of `(space ...)' spec that is about to affect text-area
4985 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
4990 /* Save current settings of IT so that we can restore them
4991 when we are finished with the glyph property value. */
4992 push_it (it
, position
);
4993 it
->from_overlay
= overlay
;
4994 it
->from_disp_prop_p
= 1;
4996 if (NILP (location
))
4997 it
->area
= TEXT_AREA
;
4998 else if (EQ (location
, Qleft_margin
))
4999 it
->area
= LEFT_MARGIN_AREA
;
5001 it
->area
= RIGHT_MARGIN_AREA
;
5003 if (STRINGP (value
))
5006 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5007 it
->current
.overlay_string_index
= -1;
5008 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5009 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5010 it
->method
= GET_FROM_STRING
;
5011 it
->stop_charpos
= 0;
5013 it
->base_level_stop
= 0;
5014 it
->string_from_display_prop_p
= 1;
5015 /* Say that we haven't consumed the characters with
5016 `display' property yet. The call to pop_it in
5017 set_iterator_to_next will clean this up. */
5018 if (BUFFERP (object
))
5019 *position
= start_pos
;
5021 /* Force paragraph direction to be that of the parent
5022 object. If the parent object's paragraph direction is
5023 not yet determined, default to L2R. */
5024 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5025 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5027 it
->paragraph_embedding
= L2R
;
5029 /* Set up the bidi iterator for this display string. */
5032 it
->bidi_it
.string
.lstring
= it
->string
;
5033 it
->bidi_it
.string
.s
= NULL
;
5034 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5035 it
->bidi_it
.string
.bufpos
= bufpos
;
5036 it
->bidi_it
.string
.from_disp_str
= 1;
5037 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5038 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5041 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5043 it
->method
= GET_FROM_STRETCH
;
5045 *position
= it
->position
= start_pos
;
5046 retval
= 1 + (it
->area
== TEXT_AREA
);
5048 #ifdef HAVE_WINDOW_SYSTEM
5051 it
->what
= IT_IMAGE
;
5052 it
->image_id
= lookup_image (it
->f
, value
);
5053 it
->position
= start_pos
;
5054 it
->object
= NILP (object
) ? it
->w
->buffer
: object
;
5055 it
->method
= GET_FROM_IMAGE
;
5057 /* Say that we haven't consumed the characters with
5058 `display' property yet. The call to pop_it in
5059 set_iterator_to_next will clean this up. */
5060 *position
= start_pos
;
5062 #endif /* HAVE_WINDOW_SYSTEM */
5067 /* Invalid property or property not supported. Restore
5068 POSITION to what it was before. */
5069 *position
= start_pos
;
5073 /* Check if PROP is a display property value whose text should be
5074 treated as intangible. OVERLAY is the overlay from which PROP
5075 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5076 specify the buffer position covered by PROP. */
5079 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5080 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5082 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5083 struct text_pos position
;
5085 SET_TEXT_POS (position
, charpos
, bytepos
);
5086 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5087 &position
, charpos
, frame_window_p
);
5091 /* Return 1 if PROP is a display sub-property value containing STRING.
5093 Implementation note: this and the following function are really
5094 special cases of handle_display_spec and
5095 handle_single_display_spec, and should ideally use the same code.
5096 Until they do, these two pairs must be consistent and must be
5097 modified in sync. */
5100 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5102 if (EQ (string
, prop
))
5105 /* Skip over `when FORM'. */
5106 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5111 /* Actually, the condition following `when' should be eval'ed,
5112 like handle_single_display_spec does, and we should return
5113 zero if it evaluates to nil. However, this function is
5114 called only when the buffer was already displayed and some
5115 glyph in the glyph matrix was found to come from a display
5116 string. Therefore, the condition was already evaluated, and
5117 the result was non-nil, otherwise the display string wouldn't
5118 have been displayed and we would have never been called for
5119 this property. Thus, we can skip the evaluation and assume
5120 its result is non-nil. */
5125 /* Skip over `margin LOCATION'. */
5126 if (EQ (XCAR (prop
), Qmargin
))
5137 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5141 /* Return 1 if STRING appears in the `display' property PROP. */
5144 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5147 && !EQ (XCAR (prop
), Qwhen
)
5148 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5150 /* A list of sub-properties. */
5151 while (CONSP (prop
))
5153 if (single_display_spec_string_p (XCAR (prop
), string
))
5158 else if (VECTORP (prop
))
5160 /* A vector of sub-properties. */
5162 for (i
= 0; i
< ASIZE (prop
); ++i
)
5163 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5167 return single_display_spec_string_p (prop
, string
);
5172 /* Look for STRING in overlays and text properties in the current
5173 buffer, between character positions FROM and TO (excluding TO).
5174 BACK_P non-zero means look back (in this case, TO is supposed to be
5176 Value is the first character position where STRING was found, or
5177 zero if it wasn't found before hitting TO.
5179 This function may only use code that doesn't eval because it is
5180 called asynchronously from note_mouse_highlight. */
5183 string_buffer_position_lim (Lisp_Object string
,
5184 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5186 Lisp_Object limit
, prop
, pos
;
5189 pos
= make_number (max (from
, BEGV
));
5191 if (!back_p
) /* looking forward */
5193 limit
= make_number (min (to
, ZV
));
5194 while (!found
&& !EQ (pos
, limit
))
5196 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5197 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5200 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5204 else /* looking back */
5206 limit
= make_number (max (to
, BEGV
));
5207 while (!found
&& !EQ (pos
, limit
))
5209 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5210 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5213 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5218 return found
? XINT (pos
) : 0;
5221 /* Determine which buffer position in current buffer STRING comes from.
5222 AROUND_CHARPOS is an approximate position where it could come from.
5223 Value is the buffer position or 0 if it couldn't be determined.
5225 This function is necessary because we don't record buffer positions
5226 in glyphs generated from strings (to keep struct glyph small).
5227 This function may only use code that doesn't eval because it is
5228 called asynchronously from note_mouse_highlight. */
5231 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5233 const int MAX_DISTANCE
= 1000;
5234 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5235 around_charpos
+ MAX_DISTANCE
,
5239 found
= string_buffer_position_lim (string
, around_charpos
,
5240 around_charpos
- MAX_DISTANCE
, 1);
5246 /***********************************************************************
5247 `composition' property
5248 ***********************************************************************/
5250 /* Set up iterator IT from `composition' property at its current
5251 position. Called from handle_stop. */
5253 static enum prop_handled
5254 handle_composition_prop (struct it
*it
)
5256 Lisp_Object prop
, string
;
5257 ptrdiff_t pos
, pos_byte
, start
, end
;
5259 if (STRINGP (it
->string
))
5263 pos
= IT_STRING_CHARPOS (*it
);
5264 pos_byte
= IT_STRING_BYTEPOS (*it
);
5265 string
= it
->string
;
5266 s
= SDATA (string
) + pos_byte
;
5267 it
->c
= STRING_CHAR (s
);
5271 pos
= IT_CHARPOS (*it
);
5272 pos_byte
= IT_BYTEPOS (*it
);
5274 it
->c
= FETCH_CHAR (pos_byte
);
5277 /* If there's a valid composition and point is not inside of the
5278 composition (in the case that the composition is from the current
5279 buffer), draw a glyph composed from the composition components. */
5280 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5281 && COMPOSITION_VALID_P (start
, end
, prop
)
5282 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5285 /* As we can't handle this situation (perhaps font-lock added
5286 a new composition), we just return here hoping that next
5287 redisplay will detect this composition much earlier. */
5288 return HANDLED_NORMALLY
;
5291 if (STRINGP (it
->string
))
5292 pos_byte
= string_char_to_byte (it
->string
, start
);
5294 pos_byte
= CHAR_TO_BYTE (start
);
5296 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5299 if (it
->cmp_it
.id
>= 0)
5302 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5303 it
->cmp_it
.nglyphs
= -1;
5307 return HANDLED_NORMALLY
;
5312 /***********************************************************************
5314 ***********************************************************************/
5316 /* The following structure is used to record overlay strings for
5317 later sorting in load_overlay_strings. */
5319 struct overlay_entry
5321 Lisp_Object overlay
;
5328 /* Set up iterator IT from overlay strings at its current position.
5329 Called from handle_stop. */
5331 static enum prop_handled
5332 handle_overlay_change (struct it
*it
)
5334 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5335 return HANDLED_RECOMPUTE_PROPS
;
5337 return HANDLED_NORMALLY
;
5341 /* Set up the next overlay string for delivery by IT, if there is an
5342 overlay string to deliver. Called by set_iterator_to_next when the
5343 end of the current overlay string is reached. If there are more
5344 overlay strings to display, IT->string and
5345 IT->current.overlay_string_index are set appropriately here.
5346 Otherwise IT->string is set to nil. */
5349 next_overlay_string (struct it
*it
)
5351 ++it
->current
.overlay_string_index
;
5352 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5354 /* No more overlay strings. Restore IT's settings to what
5355 they were before overlay strings were processed, and
5356 continue to deliver from current_buffer. */
5358 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5361 || (NILP (it
->string
)
5362 && it
->method
== GET_FROM_BUFFER
5363 && it
->stop_charpos
>= BEGV
5364 && it
->stop_charpos
<= it
->end_charpos
));
5365 it
->current
.overlay_string_index
= -1;
5366 it
->n_overlay_strings
= 0;
5367 it
->overlay_strings_charpos
= -1;
5368 /* If there's an empty display string on the stack, pop the
5369 stack, to resync the bidi iterator with IT's position. Such
5370 empty strings are pushed onto the stack in
5371 get_overlay_strings_1. */
5372 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5375 /* If we're at the end of the buffer, record that we have
5376 processed the overlay strings there already, so that
5377 next_element_from_buffer doesn't try it again. */
5378 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5379 it
->overlay_strings_at_end_processed_p
= 1;
5383 /* There are more overlay strings to process. If
5384 IT->current.overlay_string_index has advanced to a position
5385 where we must load IT->overlay_strings with more strings, do
5386 it. We must load at the IT->overlay_strings_charpos where
5387 IT->n_overlay_strings was originally computed; when invisible
5388 text is present, this might not be IT_CHARPOS (Bug#7016). */
5389 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5391 if (it
->current
.overlay_string_index
&& i
== 0)
5392 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5394 /* Initialize IT to deliver display elements from the overlay
5396 it
->string
= it
->overlay_strings
[i
];
5397 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5398 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5399 it
->method
= GET_FROM_STRING
;
5400 it
->stop_charpos
= 0;
5401 it
->end_charpos
= SCHARS (it
->string
);
5402 if (it
->cmp_it
.stop_pos
>= 0)
5403 it
->cmp_it
.stop_pos
= 0;
5405 it
->base_level_stop
= 0;
5407 /* Set up the bidi iterator for this overlay string. */
5410 it
->bidi_it
.string
.lstring
= it
->string
;
5411 it
->bidi_it
.string
.s
= NULL
;
5412 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5413 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5414 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5415 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5416 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5424 /* Compare two overlay_entry structures E1 and E2. Used as a
5425 comparison function for qsort in load_overlay_strings. Overlay
5426 strings for the same position are sorted so that
5428 1. All after-strings come in front of before-strings, except
5429 when they come from the same overlay.
5431 2. Within after-strings, strings are sorted so that overlay strings
5432 from overlays with higher priorities come first.
5434 2. Within before-strings, strings are sorted so that overlay
5435 strings from overlays with higher priorities come last.
5437 Value is analogous to strcmp. */
5441 compare_overlay_entries (const void *e1
, const void *e2
)
5443 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5444 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5447 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5449 /* Let after-strings appear in front of before-strings if
5450 they come from different overlays. */
5451 if (EQ (entry1
->overlay
, entry2
->overlay
))
5452 result
= entry1
->after_string_p
? 1 : -1;
5454 result
= entry1
->after_string_p
? -1 : 1;
5456 else if (entry1
->priority
!= entry2
->priority
)
5458 if (entry1
->after_string_p
)
5459 /* After-strings sorted in order of decreasing priority. */
5460 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5462 /* Before-strings sorted in order of increasing priority. */
5463 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5472 /* Load the vector IT->overlay_strings with overlay strings from IT's
5473 current buffer position, or from CHARPOS if that is > 0. Set
5474 IT->n_overlays to the total number of overlay strings found.
5476 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5477 a time. On entry into load_overlay_strings,
5478 IT->current.overlay_string_index gives the number of overlay
5479 strings that have already been loaded by previous calls to this
5482 IT->add_overlay_start contains an additional overlay start
5483 position to consider for taking overlay strings from, if non-zero.
5484 This position comes into play when the overlay has an `invisible'
5485 property, and both before and after-strings. When we've skipped to
5486 the end of the overlay, because of its `invisible' property, we
5487 nevertheless want its before-string to appear.
5488 IT->add_overlay_start will contain the overlay start position
5491 Overlay strings are sorted so that after-string strings come in
5492 front of before-string strings. Within before and after-strings,
5493 strings are sorted by overlay priority. See also function
5494 compare_overlay_entries. */
5497 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5499 Lisp_Object overlay
, window
, str
, invisible
;
5500 struct Lisp_Overlay
*ov
;
5501 ptrdiff_t start
, end
;
5502 ptrdiff_t size
= 20;
5503 ptrdiff_t n
= 0, i
, j
;
5505 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5509 charpos
= IT_CHARPOS (*it
);
5511 /* Append the overlay string STRING of overlay OVERLAY to vector
5512 `entries' which has size `size' and currently contains `n'
5513 elements. AFTER_P non-zero means STRING is an after-string of
5515 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5518 Lisp_Object priority; \
5522 struct overlay_entry *old = entries; \
5523 SAFE_NALLOCA (entries, 2, size); \
5524 memcpy (entries, old, size * sizeof *entries); \
5528 entries[n].string = (STRING); \
5529 entries[n].overlay = (OVERLAY); \
5530 priority = Foverlay_get ((OVERLAY), Qpriority); \
5531 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5532 entries[n].after_string_p = (AFTER_P); \
5537 /* Process overlay before the overlay center. */
5538 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5540 XSETMISC (overlay
, ov
);
5541 eassert (OVERLAYP (overlay
));
5542 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5543 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5548 /* Skip this overlay if it doesn't start or end at IT's current
5550 if (end
!= charpos
&& start
!= charpos
)
5553 /* Skip this overlay if it doesn't apply to IT->w. */
5554 window
= Foverlay_get (overlay
, Qwindow
);
5555 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5558 /* If the text ``under'' the overlay is invisible, both before-
5559 and after-strings from this overlay are visible; start and
5560 end position are indistinguishable. */
5561 invisible
= Foverlay_get (overlay
, Qinvisible
);
5562 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5564 /* If overlay has a non-empty before-string, record it. */
5565 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5566 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5568 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5570 /* If overlay has a non-empty after-string, record it. */
5571 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5572 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5574 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5577 /* Process overlays after the overlay center. */
5578 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5580 XSETMISC (overlay
, ov
);
5581 eassert (OVERLAYP (overlay
));
5582 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5583 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5585 if (start
> charpos
)
5588 /* Skip this overlay if it doesn't start or end at IT's current
5590 if (end
!= charpos
&& start
!= charpos
)
5593 /* Skip this overlay if it doesn't apply to IT->w. */
5594 window
= Foverlay_get (overlay
, Qwindow
);
5595 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5598 /* If the text ``under'' the overlay is invisible, it has a zero
5599 dimension, and both before- and after-strings apply. */
5600 invisible
= Foverlay_get (overlay
, Qinvisible
);
5601 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5603 /* If overlay has a non-empty before-string, record it. */
5604 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5605 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5607 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5609 /* If overlay has a non-empty after-string, record it. */
5610 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5611 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5613 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5616 #undef RECORD_OVERLAY_STRING
5620 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5622 /* Record number of overlay strings, and where we computed it. */
5623 it
->n_overlay_strings
= n
;
5624 it
->overlay_strings_charpos
= charpos
;
5626 /* IT->current.overlay_string_index is the number of overlay strings
5627 that have already been consumed by IT. Copy some of the
5628 remaining overlay strings to IT->overlay_strings. */
5630 j
= it
->current
.overlay_string_index
;
5631 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5633 it
->overlay_strings
[i
] = entries
[j
].string
;
5634 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5642 /* Get the first chunk of overlay strings at IT's current buffer
5643 position, or at CHARPOS if that is > 0. Value is non-zero if at
5644 least one overlay string was found. */
5647 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5649 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5650 process. This fills IT->overlay_strings with strings, and sets
5651 IT->n_overlay_strings to the total number of strings to process.
5652 IT->pos.overlay_string_index has to be set temporarily to zero
5653 because load_overlay_strings needs this; it must be set to -1
5654 when no overlay strings are found because a zero value would
5655 indicate a position in the first overlay string. */
5656 it
->current
.overlay_string_index
= 0;
5657 load_overlay_strings (it
, charpos
);
5659 /* If we found overlay strings, set up IT to deliver display
5660 elements from the first one. Otherwise set up IT to deliver
5661 from current_buffer. */
5662 if (it
->n_overlay_strings
)
5664 /* Make sure we know settings in current_buffer, so that we can
5665 restore meaningful values when we're done with the overlay
5668 compute_stop_pos (it
);
5669 eassert (it
->face_id
>= 0);
5671 /* Save IT's settings. They are restored after all overlay
5672 strings have been processed. */
5673 eassert (!compute_stop_p
|| it
->sp
== 0);
5675 /* When called from handle_stop, there might be an empty display
5676 string loaded. In that case, don't bother saving it. But
5677 don't use this optimization with the bidi iterator, since we
5678 need the corresponding pop_it call to resync the bidi
5679 iterator's position with IT's position, after we are done
5680 with the overlay strings. (The corresponding call to pop_it
5681 in case of an empty display string is in
5682 next_overlay_string.) */
5684 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5687 /* Set up IT to deliver display elements from the first overlay
5689 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5690 it
->string
= it
->overlay_strings
[0];
5691 it
->from_overlay
= Qnil
;
5692 it
->stop_charpos
= 0;
5693 eassert (STRINGP (it
->string
));
5694 it
->end_charpos
= SCHARS (it
->string
);
5696 it
->base_level_stop
= 0;
5697 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5698 it
->method
= GET_FROM_STRING
;
5699 it
->from_disp_prop_p
= 0;
5701 /* Force paragraph direction to be that of the parent
5703 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5704 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5706 it
->paragraph_embedding
= L2R
;
5708 /* Set up the bidi iterator for this overlay string. */
5711 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5713 it
->bidi_it
.string
.lstring
= it
->string
;
5714 it
->bidi_it
.string
.s
= NULL
;
5715 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5716 it
->bidi_it
.string
.bufpos
= pos
;
5717 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5718 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5719 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5724 it
->current
.overlay_string_index
= -1;
5729 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5732 it
->method
= GET_FROM_BUFFER
;
5734 (void) get_overlay_strings_1 (it
, charpos
, 1);
5738 /* Value is non-zero if we found at least one overlay string. */
5739 return STRINGP (it
->string
);
5744 /***********************************************************************
5745 Saving and restoring state
5746 ***********************************************************************/
5748 /* Save current settings of IT on IT->stack. Called, for example,
5749 before setting up IT for an overlay string, to be able to restore
5750 IT's settings to what they were after the overlay string has been
5751 processed. If POSITION is non-NULL, it is the position to save on
5752 the stack instead of IT->position. */
5755 push_it (struct it
*it
, struct text_pos
*position
)
5757 struct iterator_stack_entry
*p
;
5759 eassert (it
->sp
< IT_STACK_SIZE
);
5760 p
= it
->stack
+ it
->sp
;
5762 p
->stop_charpos
= it
->stop_charpos
;
5763 p
->prev_stop
= it
->prev_stop
;
5764 p
->base_level_stop
= it
->base_level_stop
;
5765 p
->cmp_it
= it
->cmp_it
;
5766 eassert (it
->face_id
>= 0);
5767 p
->face_id
= it
->face_id
;
5768 p
->string
= it
->string
;
5769 p
->method
= it
->method
;
5770 p
->from_overlay
= it
->from_overlay
;
5773 case GET_FROM_IMAGE
:
5774 p
->u
.image
.object
= it
->object
;
5775 p
->u
.image
.image_id
= it
->image_id
;
5776 p
->u
.image
.slice
= it
->slice
;
5778 case GET_FROM_STRETCH
:
5779 p
->u
.stretch
.object
= it
->object
;
5782 p
->position
= position
? *position
: it
->position
;
5783 p
->current
= it
->current
;
5784 p
->end_charpos
= it
->end_charpos
;
5785 p
->string_nchars
= it
->string_nchars
;
5787 p
->multibyte_p
= it
->multibyte_p
;
5788 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5789 p
->space_width
= it
->space_width
;
5790 p
->font_height
= it
->font_height
;
5791 p
->voffset
= it
->voffset
;
5792 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5793 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5794 p
->display_ellipsis_p
= 0;
5795 p
->line_wrap
= it
->line_wrap
;
5796 p
->bidi_p
= it
->bidi_p
;
5797 p
->paragraph_embedding
= it
->paragraph_embedding
;
5798 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5801 /* Save the state of the bidi iterator as well. */
5803 bidi_push_it (&it
->bidi_it
);
5807 iterate_out_of_display_property (struct it
*it
)
5809 int buffer_p
= !STRINGP (it
->string
);
5810 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5811 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5813 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5815 /* Maybe initialize paragraph direction. If we are at the beginning
5816 of a new paragraph, next_element_from_buffer may not have a
5817 chance to do that. */
5818 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5819 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5820 /* prev_stop can be zero, so check against BEGV as well. */
5821 while (it
->bidi_it
.charpos
>= bob
5822 && it
->prev_stop
<= it
->bidi_it
.charpos
5823 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5824 && it
->bidi_it
.charpos
< eob
)
5825 bidi_move_to_visually_next (&it
->bidi_it
);
5826 /* Record the stop_pos we just crossed, for when we cross it
5828 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5829 it
->prev_stop
= CHARPOS (it
->position
);
5830 /* If we ended up not where pop_it put us, resync IT's
5831 positional members with the bidi iterator. */
5832 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5833 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5835 it
->current
.pos
= it
->position
;
5837 it
->current
.string_pos
= it
->position
;
5840 /* Restore IT's settings from IT->stack. Called, for example, when no
5841 more overlay strings must be processed, and we return to delivering
5842 display elements from a buffer, or when the end of a string from a
5843 `display' property is reached and we return to delivering display
5844 elements from an overlay string, or from a buffer. */
5847 pop_it (struct it
*it
)
5849 struct iterator_stack_entry
*p
;
5850 int from_display_prop
= it
->from_disp_prop_p
;
5852 eassert (it
->sp
> 0);
5854 p
= it
->stack
+ it
->sp
;
5855 it
->stop_charpos
= p
->stop_charpos
;
5856 it
->prev_stop
= p
->prev_stop
;
5857 it
->base_level_stop
= p
->base_level_stop
;
5858 it
->cmp_it
= p
->cmp_it
;
5859 it
->face_id
= p
->face_id
;
5860 it
->current
= p
->current
;
5861 it
->position
= p
->position
;
5862 it
->string
= p
->string
;
5863 it
->from_overlay
= p
->from_overlay
;
5864 if (NILP (it
->string
))
5865 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5866 it
->method
= p
->method
;
5869 case GET_FROM_IMAGE
:
5870 it
->image_id
= p
->u
.image
.image_id
;
5871 it
->object
= p
->u
.image
.object
;
5872 it
->slice
= p
->u
.image
.slice
;
5874 case GET_FROM_STRETCH
:
5875 it
->object
= p
->u
.stretch
.object
;
5877 case GET_FROM_BUFFER
:
5878 it
->object
= it
->w
->buffer
;
5880 case GET_FROM_STRING
:
5881 it
->object
= it
->string
;
5883 case GET_FROM_DISPLAY_VECTOR
:
5885 it
->method
= GET_FROM_C_STRING
;
5886 else if (STRINGP (it
->string
))
5887 it
->method
= GET_FROM_STRING
;
5890 it
->method
= GET_FROM_BUFFER
;
5891 it
->object
= it
->w
->buffer
;
5894 it
->end_charpos
= p
->end_charpos
;
5895 it
->string_nchars
= p
->string_nchars
;
5897 it
->multibyte_p
= p
->multibyte_p
;
5898 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5899 it
->space_width
= p
->space_width
;
5900 it
->font_height
= p
->font_height
;
5901 it
->voffset
= p
->voffset
;
5902 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5903 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5904 it
->line_wrap
= p
->line_wrap
;
5905 it
->bidi_p
= p
->bidi_p
;
5906 it
->paragraph_embedding
= p
->paragraph_embedding
;
5907 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5910 bidi_pop_it (&it
->bidi_it
);
5911 /* Bidi-iterate until we get out of the portion of text, if any,
5912 covered by a `display' text property or by an overlay with
5913 `display' property. (We cannot just jump there, because the
5914 internal coherency of the bidi iterator state can not be
5915 preserved across such jumps.) We also must determine the
5916 paragraph base direction if the overlay we just processed is
5917 at the beginning of a new paragraph. */
5918 if (from_display_prop
5919 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5920 iterate_out_of_display_property (it
);
5922 eassert ((BUFFERP (it
->object
)
5923 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5924 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5925 || (STRINGP (it
->object
)
5926 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5927 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5928 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5934 /***********************************************************************
5936 ***********************************************************************/
5938 /* Set IT's current position to the previous line start. */
5941 back_to_previous_line_start (struct it
*it
)
5943 IT_CHARPOS (*it
) = find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
5944 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (IT_CHARPOS (*it
));
5948 /* Move IT to the next line start.
5950 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
5951 we skipped over part of the text (as opposed to moving the iterator
5952 continuously over the text). Otherwise, don't change the value
5955 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
5956 iterator on the newline, if it was found.
5958 Newlines may come from buffer text, overlay strings, or strings
5959 displayed via the `display' property. That's the reason we can't
5960 simply use find_next_newline_no_quit.
5962 Note that this function may not skip over invisible text that is so
5963 because of text properties and immediately follows a newline. If
5964 it would, function reseat_at_next_visible_line_start, when called
5965 from set_iterator_to_next, would effectively make invisible
5966 characters following a newline part of the wrong glyph row, which
5967 leads to wrong cursor motion. */
5970 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
5971 struct bidi_it
*bidi_it_prev
)
5973 ptrdiff_t old_selective
;
5974 int newline_found_p
, n
;
5975 const int MAX_NEWLINE_DISTANCE
= 500;
5977 /* If already on a newline, just consume it to avoid unintended
5978 skipping over invisible text below. */
5979 if (it
->what
== IT_CHARACTER
5981 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
5983 if (it
->bidi_p
&& bidi_it_prev
)
5984 *bidi_it_prev
= it
->bidi_it
;
5985 set_iterator_to_next (it
, 0);
5990 /* Don't handle selective display in the following. It's (a)
5991 unnecessary because it's done by the caller, and (b) leads to an
5992 infinite recursion because next_element_from_ellipsis indirectly
5993 calls this function. */
5994 old_selective
= it
->selective
;
5997 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
5998 from buffer text. */
5999 for (n
= newline_found_p
= 0;
6000 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6001 n
+= STRINGP (it
->string
) ? 0 : 1)
6003 if (!get_next_display_element (it
))
6005 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6006 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6007 *bidi_it_prev
= it
->bidi_it
;
6008 set_iterator_to_next (it
, 0);
6011 /* If we didn't find a newline near enough, see if we can use a
6013 if (!newline_found_p
)
6015 ptrdiff_t start
= IT_CHARPOS (*it
);
6016 ptrdiff_t limit
= find_next_newline_no_quit (start
, 1);
6019 eassert (!STRINGP (it
->string
));
6021 /* If there isn't any `display' property in sight, and no
6022 overlays, we can just use the position of the newline in
6024 if (it
->stop_charpos
>= limit
6025 || ((pos
= Fnext_single_property_change (make_number (start
),
6027 make_number (limit
)),
6029 && next_overlay_change (start
) == ZV
))
6033 IT_CHARPOS (*it
) = limit
;
6034 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (limit
);
6038 struct bidi_it bprev
;
6040 /* Help bidi.c avoid expensive searches for display
6041 properties and overlays, by telling it that there are
6042 none up to `limit'. */
6043 if (it
->bidi_it
.disp_pos
< limit
)
6045 it
->bidi_it
.disp_pos
= limit
;
6046 it
->bidi_it
.disp_prop
= 0;
6049 bprev
= it
->bidi_it
;
6050 bidi_move_to_visually_next (&it
->bidi_it
);
6051 } while (it
->bidi_it
.charpos
!= limit
);
6052 IT_CHARPOS (*it
) = limit
;
6053 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6055 *bidi_it_prev
= bprev
;
6057 *skipped_p
= newline_found_p
= 1;
6061 while (get_next_display_element (it
)
6062 && !newline_found_p
)
6064 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6065 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6066 *bidi_it_prev
= it
->bidi_it
;
6067 set_iterator_to_next (it
, 0);
6072 it
->selective
= old_selective
;
6073 return newline_found_p
;
6077 /* Set IT's current position to the previous visible line start. Skip
6078 invisible text that is so either due to text properties or due to
6079 selective display. Caution: this does not change IT->current_x and
6083 back_to_previous_visible_line_start (struct it
*it
)
6085 while (IT_CHARPOS (*it
) > BEGV
)
6087 back_to_previous_line_start (it
);
6089 if (IT_CHARPOS (*it
) <= BEGV
)
6092 /* If selective > 0, then lines indented more than its value are
6094 if (it
->selective
> 0
6095 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6099 /* Check the newline before point for invisibility. */
6102 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6103 Qinvisible
, it
->window
);
6104 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6108 if (IT_CHARPOS (*it
) <= BEGV
)
6113 void *it2data
= NULL
;
6116 Lisp_Object val
, overlay
;
6118 SAVE_IT (it2
, *it
, it2data
);
6120 /* If newline is part of a composition, continue from start of composition */
6121 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6122 && beg
< IT_CHARPOS (*it
))
6125 /* If newline is replaced by a display property, find start of overlay
6126 or interval and continue search from that point. */
6127 pos
= --IT_CHARPOS (it2
);
6130 bidi_unshelve_cache (NULL
, 0);
6131 it2
.string_from_display_prop_p
= 0;
6132 it2
.from_disp_prop_p
= 0;
6133 if (handle_display_prop (&it2
) == HANDLED_RETURN
6134 && !NILP (val
= get_char_property_and_overlay
6135 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6136 && (OVERLAYP (overlay
)
6137 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6138 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6140 RESTORE_IT (it
, it
, it2data
);
6144 /* Newline is not replaced by anything -- so we are done. */
6145 RESTORE_IT (it
, it
, it2data
);
6151 IT_CHARPOS (*it
) = beg
;
6152 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6156 it
->continuation_lines_width
= 0;
6158 eassert (IT_CHARPOS (*it
) >= BEGV
);
6159 eassert (IT_CHARPOS (*it
) == BEGV
6160 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6165 /* Reseat iterator IT at the previous visible line start. Skip
6166 invisible text that is so either due to text properties or due to
6167 selective display. At the end, update IT's overlay information,
6168 face information etc. */
6171 reseat_at_previous_visible_line_start (struct it
*it
)
6173 back_to_previous_visible_line_start (it
);
6174 reseat (it
, it
->current
.pos
, 1);
6179 /* Reseat iterator IT on the next visible line start in the current
6180 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6181 preceding the line start. Skip over invisible text that is so
6182 because of selective display. Compute faces, overlays etc at the
6183 new position. Note that this function does not skip over text that
6184 is invisible because of text properties. */
6187 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6189 int newline_found_p
, skipped_p
= 0;
6190 struct bidi_it bidi_it_prev
;
6192 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6194 /* Skip over lines that are invisible because they are indented
6195 more than the value of IT->selective. */
6196 if (it
->selective
> 0)
6197 while (IT_CHARPOS (*it
) < ZV
6198 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6201 eassert (IT_BYTEPOS (*it
) == BEGV
6202 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6204 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6207 /* Position on the newline if that's what's requested. */
6208 if (on_newline_p
&& newline_found_p
)
6210 if (STRINGP (it
->string
))
6212 if (IT_STRING_CHARPOS (*it
) > 0)
6216 --IT_STRING_CHARPOS (*it
);
6217 --IT_STRING_BYTEPOS (*it
);
6221 /* We need to restore the bidi iterator to the state
6222 it had on the newline, and resync the IT's
6223 position with that. */
6224 it
->bidi_it
= bidi_it_prev
;
6225 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6226 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6230 else if (IT_CHARPOS (*it
) > BEGV
)
6239 /* We need to restore the bidi iterator to the state it
6240 had on the newline and resync IT with that. */
6241 it
->bidi_it
= bidi_it_prev
;
6242 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6243 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6245 reseat (it
, it
->current
.pos
, 0);
6249 reseat (it
, it
->current
.pos
, 0);
6256 /***********************************************************************
6257 Changing an iterator's position
6258 ***********************************************************************/
6260 /* Change IT's current position to POS in current_buffer. If FORCE_P
6261 is non-zero, always check for text properties at the new position.
6262 Otherwise, text properties are only looked up if POS >=
6263 IT->check_charpos of a property. */
6266 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6268 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6270 reseat_1 (it
, pos
, 0);
6272 /* Determine where to check text properties. Avoid doing it
6273 where possible because text property lookup is very expensive. */
6275 || CHARPOS (pos
) > it
->stop_charpos
6276 || CHARPOS (pos
) < original_pos
)
6280 /* For bidi iteration, we need to prime prev_stop and
6281 base_level_stop with our best estimations. */
6282 /* Implementation note: Of course, POS is not necessarily a
6283 stop position, so assigning prev_pos to it is a lie; we
6284 should have called compute_stop_backwards. However, if
6285 the current buffer does not include any R2L characters,
6286 that call would be a waste of cycles, because the
6287 iterator will never move back, and thus never cross this
6288 "fake" stop position. So we delay that backward search
6289 until the time we really need it, in next_element_from_buffer. */
6290 if (CHARPOS (pos
) != it
->prev_stop
)
6291 it
->prev_stop
= CHARPOS (pos
);
6292 if (CHARPOS (pos
) < it
->base_level_stop
)
6293 it
->base_level_stop
= 0; /* meaning it's unknown */
6299 it
->prev_stop
= it
->base_level_stop
= 0;
6308 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6309 IT->stop_pos to POS, also. */
6312 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6314 /* Don't call this function when scanning a C string. */
6315 eassert (it
->s
== NULL
);
6317 /* POS must be a reasonable value. */
6318 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6320 it
->current
.pos
= it
->position
= pos
;
6321 it
->end_charpos
= ZV
;
6323 it
->current
.dpvec_index
= -1;
6324 it
->current
.overlay_string_index
= -1;
6325 IT_STRING_CHARPOS (*it
) = -1;
6326 IT_STRING_BYTEPOS (*it
) = -1;
6328 it
->method
= GET_FROM_BUFFER
;
6329 it
->object
= it
->w
->buffer
;
6330 it
->area
= TEXT_AREA
;
6331 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6333 it
->string_from_display_prop_p
= 0;
6334 it
->string_from_prefix_prop_p
= 0;
6336 it
->from_disp_prop_p
= 0;
6337 it
->face_before_selective_p
= 0;
6340 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6342 bidi_unshelve_cache (NULL
, 0);
6343 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6344 it
->bidi_it
.string
.s
= NULL
;
6345 it
->bidi_it
.string
.lstring
= Qnil
;
6346 it
->bidi_it
.string
.bufpos
= 0;
6347 it
->bidi_it
.string
.unibyte
= 0;
6352 it
->stop_charpos
= CHARPOS (pos
);
6353 it
->base_level_stop
= CHARPOS (pos
);
6355 /* This make the information stored in it->cmp_it invalidate. */
6360 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6361 If S is non-null, it is a C string to iterate over. Otherwise,
6362 STRING gives a Lisp string to iterate over.
6364 If PRECISION > 0, don't return more then PRECISION number of
6365 characters from the string.
6367 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6368 characters have been returned. FIELD_WIDTH < 0 means an infinite
6371 MULTIBYTE = 0 means disable processing of multibyte characters,
6372 MULTIBYTE > 0 means enable it,
6373 MULTIBYTE < 0 means use IT->multibyte_p.
6375 IT must be initialized via a prior call to init_iterator before
6376 calling this function. */
6379 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6380 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6383 /* No region in strings. */
6384 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6386 /* No text property checks performed by default, but see below. */
6387 it
->stop_charpos
= -1;
6389 /* Set iterator position and end position. */
6390 memset (&it
->current
, 0, sizeof it
->current
);
6391 it
->current
.overlay_string_index
= -1;
6392 it
->current
.dpvec_index
= -1;
6393 eassert (charpos
>= 0);
6395 /* If STRING is specified, use its multibyteness, otherwise use the
6396 setting of MULTIBYTE, if specified. */
6398 it
->multibyte_p
= multibyte
> 0;
6400 /* Bidirectional reordering of strings is controlled by the default
6401 value of bidi-display-reordering. Don't try to reorder while
6402 loading loadup.el, as the necessary character property tables are
6403 not yet available. */
6406 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6410 eassert (STRINGP (string
));
6411 it
->string
= string
;
6413 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6414 it
->method
= GET_FROM_STRING
;
6415 it
->current
.string_pos
= string_pos (charpos
, string
);
6419 it
->bidi_it
.string
.lstring
= string
;
6420 it
->bidi_it
.string
.s
= NULL
;
6421 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6422 it
->bidi_it
.string
.bufpos
= 0;
6423 it
->bidi_it
.string
.from_disp_str
= 0;
6424 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6425 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6426 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6431 it
->s
= (const unsigned char *) s
;
6434 /* Note that we use IT->current.pos, not it->current.string_pos,
6435 for displaying C strings. */
6436 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6437 if (it
->multibyte_p
)
6439 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6440 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6444 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6445 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6450 it
->bidi_it
.string
.lstring
= Qnil
;
6451 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6452 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6453 it
->bidi_it
.string
.bufpos
= 0;
6454 it
->bidi_it
.string
.from_disp_str
= 0;
6455 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6456 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6459 it
->method
= GET_FROM_C_STRING
;
6462 /* PRECISION > 0 means don't return more than PRECISION characters
6464 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6466 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6468 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6471 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6472 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6473 FIELD_WIDTH < 0 means infinite field width. This is useful for
6474 padding with `-' at the end of a mode line. */
6475 if (field_width
< 0)
6476 field_width
= INFINITY
;
6477 /* Implementation note: We deliberately don't enlarge
6478 it->bidi_it.string.schars here to fit it->end_charpos, because
6479 the bidi iterator cannot produce characters out of thin air. */
6480 if (field_width
> it
->end_charpos
- charpos
)
6481 it
->end_charpos
= charpos
+ field_width
;
6483 /* Use the standard display table for displaying strings. */
6484 if (DISP_TABLE_P (Vstandard_display_table
))
6485 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6487 it
->stop_charpos
= charpos
;
6488 it
->prev_stop
= charpos
;
6489 it
->base_level_stop
= 0;
6492 it
->bidi_it
.first_elt
= 1;
6493 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6494 it
->bidi_it
.disp_pos
= -1;
6496 if (s
== NULL
&& it
->multibyte_p
)
6498 ptrdiff_t endpos
= SCHARS (it
->string
);
6499 if (endpos
> it
->end_charpos
)
6500 endpos
= it
->end_charpos
;
6501 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6509 /***********************************************************************
6511 ***********************************************************************/
6513 /* Map enum it_method value to corresponding next_element_from_* function. */
6515 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6517 next_element_from_buffer
,
6518 next_element_from_display_vector
,
6519 next_element_from_string
,
6520 next_element_from_c_string
,
6521 next_element_from_image
,
6522 next_element_from_stretch
6525 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6528 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6529 (possibly with the following characters). */
6531 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6532 ((IT)->cmp_it.id >= 0 \
6533 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6534 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6535 END_CHARPOS, (IT)->w, \
6536 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6540 /* Lookup the char-table Vglyphless_char_display for character C (-1
6541 if we want information for no-font case), and return the display
6542 method symbol. By side-effect, update it->what and
6543 it->glyphless_method. This function is called from
6544 get_next_display_element for each character element, and from
6545 x_produce_glyphs when no suitable font was found. */
6548 lookup_glyphless_char_display (int c
, struct it
*it
)
6550 Lisp_Object glyphless_method
= Qnil
;
6552 if (CHAR_TABLE_P (Vglyphless_char_display
)
6553 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6557 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6558 if (CONSP (glyphless_method
))
6559 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6560 ? XCAR (glyphless_method
)
6561 : XCDR (glyphless_method
);
6564 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6568 if (NILP (glyphless_method
))
6571 /* The default is to display the character by a proper font. */
6573 /* The default for the no-font case is to display an empty box. */
6574 glyphless_method
= Qempty_box
;
6576 if (EQ (glyphless_method
, Qzero_width
))
6579 return glyphless_method
;
6580 /* This method can't be used for the no-font case. */
6581 glyphless_method
= Qempty_box
;
6583 if (EQ (glyphless_method
, Qthin_space
))
6584 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6585 else if (EQ (glyphless_method
, Qempty_box
))
6586 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6587 else if (EQ (glyphless_method
, Qhex_code
))
6588 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6589 else if (STRINGP (glyphless_method
))
6590 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6593 /* Invalid value. We use the default method. */
6594 glyphless_method
= Qnil
;
6597 it
->what
= IT_GLYPHLESS
;
6598 return glyphless_method
;
6601 /* Load IT's display element fields with information about the next
6602 display element from the current position of IT. Value is zero if
6603 end of buffer (or C string) is reached. */
6605 static struct frame
*last_escape_glyph_frame
= NULL
;
6606 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6607 static int last_escape_glyph_merged_face_id
= 0;
6609 struct frame
*last_glyphless_glyph_frame
= NULL
;
6610 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6611 int last_glyphless_glyph_merged_face_id
= 0;
6614 get_next_display_element (struct it
*it
)
6616 /* Non-zero means that we found a display element. Zero means that
6617 we hit the end of what we iterate over. Performance note: the
6618 function pointer `method' used here turns out to be faster than
6619 using a sequence of if-statements. */
6623 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6625 if (it
->what
== IT_CHARACTER
)
6627 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6628 and only if (a) the resolved directionality of that character
6630 /* FIXME: Do we need an exception for characters from display
6632 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6633 it
->c
= bidi_mirror_char (it
->c
);
6634 /* Map via display table or translate control characters.
6635 IT->c, IT->len etc. have been set to the next character by
6636 the function call above. If we have a display table, and it
6637 contains an entry for IT->c, translate it. Don't do this if
6638 IT->c itself comes from a display table, otherwise we could
6639 end up in an infinite recursion. (An alternative could be to
6640 count the recursion depth of this function and signal an
6641 error when a certain maximum depth is reached.) Is it worth
6643 if (success_p
&& it
->dpvec
== NULL
)
6646 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6647 int nonascii_space_p
= 0;
6648 int nonascii_hyphen_p
= 0;
6649 int c
= it
->c
; /* This is the character to display. */
6651 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6653 eassert (SINGLE_BYTE_CHAR_P (c
));
6654 if (unibyte_display_via_language_environment
)
6656 c
= DECODE_CHAR (unibyte
, c
);
6658 c
= BYTE8_TO_CHAR (it
->c
);
6661 c
= BYTE8_TO_CHAR (it
->c
);
6665 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6668 struct Lisp_Vector
*v
= XVECTOR (dv
);
6670 /* Return the first character from the display table
6671 entry, if not empty. If empty, don't display the
6672 current character. */
6675 it
->dpvec_char_len
= it
->len
;
6676 it
->dpvec
= v
->contents
;
6677 it
->dpend
= v
->contents
+ v
->header
.size
;
6678 it
->current
.dpvec_index
= 0;
6679 it
->dpvec_face_id
= -1;
6680 it
->saved_face_id
= it
->face_id
;
6681 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6686 set_iterator_to_next (it
, 0);
6691 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6693 if (it
->what
== IT_GLYPHLESS
)
6695 /* Don't display this character. */
6696 set_iterator_to_next (it
, 0);
6700 /* If `nobreak-char-display' is non-nil, we display
6701 non-ASCII spaces and hyphens specially. */
6702 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6705 nonascii_space_p
= 1;
6706 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6707 nonascii_hyphen_p
= 1;
6710 /* Translate control characters into `\003' or `^C' form.
6711 Control characters coming from a display table entry are
6712 currently not translated because we use IT->dpvec to hold
6713 the translation. This could easily be changed but I
6714 don't believe that it is worth doing.
6716 The characters handled by `nobreak-char-display' must be
6719 Non-printable characters and raw-byte characters are also
6720 translated to octal form. */
6721 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6722 ? (it
->area
!= TEXT_AREA
6723 /* In mode line, treat \n, \t like other crl chars. */
6726 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6727 || (c
!= '\n' && c
!= '\t'))
6729 || nonascii_hyphen_p
6731 || ! CHAR_PRINTABLE_P (c
))))
6733 /* C is a control character, non-ASCII space/hyphen,
6734 raw-byte, or a non-printable character which must be
6735 displayed either as '\003' or as `^C' where the '\\'
6736 and '^' can be defined in the display table. Fill
6737 IT->ctl_chars with glyphs for what we have to
6738 display. Then, set IT->dpvec to these glyphs. */
6745 /* Handle control characters with ^. */
6747 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6751 g
= '^'; /* default glyph for Control */
6752 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6754 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6756 g
= GLYPH_CODE_CHAR (gc
);
6757 lface_id
= GLYPH_CODE_FACE (gc
);
6761 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6763 else if (it
->f
== last_escape_glyph_frame
6764 && it
->face_id
== last_escape_glyph_face_id
)
6766 face_id
= last_escape_glyph_merged_face_id
;
6770 /* Merge the escape-glyph face into the current face. */
6771 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6773 last_escape_glyph_frame
= it
->f
;
6774 last_escape_glyph_face_id
= it
->face_id
;
6775 last_escape_glyph_merged_face_id
= face_id
;
6778 XSETINT (it
->ctl_chars
[0], g
);
6779 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6781 goto display_control
;
6784 /* Handle non-ascii space in the mode where it only gets
6787 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6789 /* Merge `nobreak-space' into the current face. */
6790 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6792 XSETINT (it
->ctl_chars
[0], ' ');
6794 goto display_control
;
6797 /* Handle sequences that start with the "escape glyph". */
6799 /* the default escape glyph is \. */
6800 escape_glyph
= '\\';
6803 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6805 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6806 lface_id
= GLYPH_CODE_FACE (gc
);
6810 /* The display table specified a face.
6811 Merge it into face_id and also into escape_glyph. */
6812 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6815 else if (it
->f
== last_escape_glyph_frame
6816 && it
->face_id
== last_escape_glyph_face_id
)
6818 face_id
= last_escape_glyph_merged_face_id
;
6822 /* Merge the escape-glyph face into the current face. */
6823 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6825 last_escape_glyph_frame
= it
->f
;
6826 last_escape_glyph_face_id
= it
->face_id
;
6827 last_escape_glyph_merged_face_id
= face_id
;
6830 /* Draw non-ASCII hyphen with just highlighting: */
6832 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6834 XSETINT (it
->ctl_chars
[0], '-');
6836 goto display_control
;
6839 /* Draw non-ASCII space/hyphen with escape glyph: */
6841 if (nonascii_space_p
|| nonascii_hyphen_p
)
6843 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6844 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6846 goto display_control
;
6853 if (CHAR_BYTE8_P (c
))
6854 /* Display \200 instead of \17777600. */
6855 c
= CHAR_TO_BYTE8 (c
);
6856 len
= sprintf (str
, "%03o", c
);
6858 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6859 for (i
= 0; i
< len
; i
++)
6860 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6865 /* Set up IT->dpvec and return first character from it. */
6866 it
->dpvec_char_len
= it
->len
;
6867 it
->dpvec
= it
->ctl_chars
;
6868 it
->dpend
= it
->dpvec
+ ctl_len
;
6869 it
->current
.dpvec_index
= 0;
6870 it
->dpvec_face_id
= face_id
;
6871 it
->saved_face_id
= it
->face_id
;
6872 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6876 it
->char_to_display
= c
;
6880 it
->char_to_display
= it
->c
;
6884 /* Adjust face id for a multibyte character. There are no multibyte
6885 character in unibyte text. */
6886 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6889 && FRAME_WINDOW_P (it
->f
))
6891 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6893 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6895 /* Automatic composition with glyph-string. */
6896 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6898 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6902 ptrdiff_t pos
= (it
->s
? -1
6903 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6904 : IT_CHARPOS (*it
));
6907 if (it
->what
== IT_CHARACTER
)
6908 c
= it
->char_to_display
;
6911 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6915 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6916 /* TAB in a composition means display glyphs with
6917 padding space on the left or right. */
6918 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6921 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
6926 /* Is this character the last one of a run of characters with
6927 box? If yes, set IT->end_of_box_run_p to 1. */
6931 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
6933 int face_id
= underlying_face_id (it
);
6934 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
6938 if (face
->box
== FACE_NO_BOX
)
6940 /* If the box comes from face properties in a
6941 display string, check faces in that string. */
6942 int string_face_id
= face_after_it_pos (it
);
6943 it
->end_of_box_run_p
6944 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
6947 /* Otherwise, the box comes from the underlying face.
6948 If this is the last string character displayed, check
6949 the next buffer location. */
6950 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
6951 && (it
->current
.overlay_string_index
6952 == it
->n_overlay_strings
- 1))
6956 struct text_pos pos
= it
->current
.pos
;
6957 INC_TEXT_POS (pos
, it
->multibyte_p
);
6959 next_face_id
= face_at_buffer_position
6960 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
6961 it
->region_end_charpos
, &ignore
,
6962 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
6964 it
->end_of_box_run_p
6965 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
6972 int face_id
= face_after_it_pos (it
);
6973 it
->end_of_box_run_p
6974 = (face_id
!= it
->face_id
6975 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
6978 /* If we reached the end of the object we've been iterating (e.g., a
6979 display string or an overlay string), and there's something on
6980 IT->stack, proceed with what's on the stack. It doesn't make
6981 sense to return zero if there's unprocessed stuff on the stack,
6982 because otherwise that stuff will never be displayed. */
6983 if (!success_p
&& it
->sp
> 0)
6985 set_iterator_to_next (it
, 0);
6986 success_p
= get_next_display_element (it
);
6989 /* Value is 0 if end of buffer or string reached. */
6994 /* Move IT to the next display element.
6996 RESEAT_P non-zero means if called on a newline in buffer text,
6997 skip to the next visible line start.
6999 Functions get_next_display_element and set_iterator_to_next are
7000 separate because I find this arrangement easier to handle than a
7001 get_next_display_element function that also increments IT's
7002 position. The way it is we can first look at an iterator's current
7003 display element, decide whether it fits on a line, and if it does,
7004 increment the iterator position. The other way around we probably
7005 would either need a flag indicating whether the iterator has to be
7006 incremented the next time, or we would have to implement a
7007 decrement position function which would not be easy to write. */
7010 set_iterator_to_next (struct it
*it
, int reseat_p
)
7012 /* Reset flags indicating start and end of a sequence of characters
7013 with box. Reset them at the start of this function because
7014 moving the iterator to a new position might set them. */
7015 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7019 case GET_FROM_BUFFER
:
7020 /* The current display element of IT is a character from
7021 current_buffer. Advance in the buffer, and maybe skip over
7022 invisible lines that are so because of selective display. */
7023 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7024 reseat_at_next_visible_line_start (it
, 0);
7025 else if (it
->cmp_it
.id
>= 0)
7027 /* We are currently getting glyphs from a composition. */
7032 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7033 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7034 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7036 it
->cmp_it
.from
= it
->cmp_it
.to
;
7041 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7043 it
->end_charpos
, Qnil
);
7046 else if (! it
->cmp_it
.reversed_p
)
7048 /* Composition created while scanning forward. */
7049 /* Update IT's char/byte positions to point to the first
7050 character of the next grapheme cluster, or to the
7051 character visually after the current composition. */
7052 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7053 bidi_move_to_visually_next (&it
->bidi_it
);
7054 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7055 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7057 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7059 /* Proceed to the next grapheme cluster. */
7060 it
->cmp_it
.from
= it
->cmp_it
.to
;
7064 /* No more grapheme clusters in this composition.
7065 Find the next stop position. */
7066 ptrdiff_t stop
= it
->end_charpos
;
7067 if (it
->bidi_it
.scan_dir
< 0)
7068 /* Now we are scanning backward and don't know
7071 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7072 IT_BYTEPOS (*it
), stop
, Qnil
);
7077 /* Composition created while scanning backward. */
7078 /* Update IT's char/byte positions to point to the last
7079 character of the previous grapheme cluster, or the
7080 character visually after the current composition. */
7081 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7082 bidi_move_to_visually_next (&it
->bidi_it
);
7083 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7084 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7085 if (it
->cmp_it
.from
> 0)
7087 /* Proceed to the previous grapheme cluster. */
7088 it
->cmp_it
.to
= it
->cmp_it
.from
;
7092 /* No more grapheme clusters in this composition.
7093 Find the next stop position. */
7094 ptrdiff_t stop
= it
->end_charpos
;
7095 if (it
->bidi_it
.scan_dir
< 0)
7096 /* Now we are scanning backward and don't know
7099 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7100 IT_BYTEPOS (*it
), stop
, Qnil
);
7106 eassert (it
->len
!= 0);
7110 IT_BYTEPOS (*it
) += it
->len
;
7111 IT_CHARPOS (*it
) += 1;
7115 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7116 /* If this is a new paragraph, determine its base
7117 direction (a.k.a. its base embedding level). */
7118 if (it
->bidi_it
.new_paragraph
)
7119 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7120 bidi_move_to_visually_next (&it
->bidi_it
);
7121 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7122 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7123 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7125 /* As the scan direction was changed, we must
7126 re-compute the stop position for composition. */
7127 ptrdiff_t stop
= it
->end_charpos
;
7128 if (it
->bidi_it
.scan_dir
< 0)
7130 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7131 IT_BYTEPOS (*it
), stop
, Qnil
);
7134 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7138 case GET_FROM_C_STRING
:
7139 /* Current display element of IT is from a C string. */
7141 /* If the string position is beyond string's end, it means
7142 next_element_from_c_string is padding the string with
7143 blanks, in which case we bypass the bidi iterator,
7144 because it cannot deal with such virtual characters. */
7145 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7147 IT_BYTEPOS (*it
) += it
->len
;
7148 IT_CHARPOS (*it
) += 1;
7152 bidi_move_to_visually_next (&it
->bidi_it
);
7153 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7154 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7158 case GET_FROM_DISPLAY_VECTOR
:
7159 /* Current display element of IT is from a display table entry.
7160 Advance in the display table definition. Reset it to null if
7161 end reached, and continue with characters from buffers/
7163 ++it
->current
.dpvec_index
;
7165 /* Restore face of the iterator to what they were before the
7166 display vector entry (these entries may contain faces). */
7167 it
->face_id
= it
->saved_face_id
;
7169 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7171 int recheck_faces
= it
->ellipsis_p
;
7174 it
->method
= GET_FROM_C_STRING
;
7175 else if (STRINGP (it
->string
))
7176 it
->method
= GET_FROM_STRING
;
7179 it
->method
= GET_FROM_BUFFER
;
7180 it
->object
= it
->w
->buffer
;
7184 it
->current
.dpvec_index
= -1;
7186 /* Skip over characters which were displayed via IT->dpvec. */
7187 if (it
->dpvec_char_len
< 0)
7188 reseat_at_next_visible_line_start (it
, 1);
7189 else if (it
->dpvec_char_len
> 0)
7191 if (it
->method
== GET_FROM_STRING
7192 && it
->n_overlay_strings
> 0)
7193 it
->ignore_overlay_strings_at_pos_p
= 1;
7194 it
->len
= it
->dpvec_char_len
;
7195 set_iterator_to_next (it
, reseat_p
);
7198 /* Maybe recheck faces after display vector */
7200 it
->stop_charpos
= IT_CHARPOS (*it
);
7204 case GET_FROM_STRING
:
7205 /* Current display element is a character from a Lisp string. */
7206 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7207 /* Don't advance past string end. These conditions are true
7208 when set_iterator_to_next is called at the end of
7209 get_next_display_element, in which case the Lisp string is
7210 already exhausted, and all we want is pop the iterator
7212 if (it
->current
.overlay_string_index
>= 0)
7214 /* This is an overlay string, so there's no padding with
7215 spaces, and the number of characters in the string is
7216 where the string ends. */
7217 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7218 goto consider_string_end
;
7222 /* Not an overlay string. There could be padding, so test
7223 against it->end_charpos . */
7224 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7225 goto consider_string_end
;
7227 if (it
->cmp_it
.id
>= 0)
7233 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7234 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7235 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7236 it
->cmp_it
.from
= it
->cmp_it
.to
;
7240 composition_compute_stop_pos (&it
->cmp_it
,
7241 IT_STRING_CHARPOS (*it
),
7242 IT_STRING_BYTEPOS (*it
),
7243 it
->end_charpos
, it
->string
);
7246 else if (! it
->cmp_it
.reversed_p
)
7248 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7249 bidi_move_to_visually_next (&it
->bidi_it
);
7250 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7251 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7253 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7254 it
->cmp_it
.from
= it
->cmp_it
.to
;
7257 ptrdiff_t stop
= it
->end_charpos
;
7258 if (it
->bidi_it
.scan_dir
< 0)
7260 composition_compute_stop_pos (&it
->cmp_it
,
7261 IT_STRING_CHARPOS (*it
),
7262 IT_STRING_BYTEPOS (*it
), stop
,
7268 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7269 bidi_move_to_visually_next (&it
->bidi_it
);
7270 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7271 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7272 if (it
->cmp_it
.from
> 0)
7273 it
->cmp_it
.to
= it
->cmp_it
.from
;
7276 ptrdiff_t stop
= it
->end_charpos
;
7277 if (it
->bidi_it
.scan_dir
< 0)
7279 composition_compute_stop_pos (&it
->cmp_it
,
7280 IT_STRING_CHARPOS (*it
),
7281 IT_STRING_BYTEPOS (*it
), stop
,
7289 /* If the string position is beyond string's end, it
7290 means next_element_from_string is padding the string
7291 with blanks, in which case we bypass the bidi
7292 iterator, because it cannot deal with such virtual
7294 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7296 IT_STRING_BYTEPOS (*it
) += it
->len
;
7297 IT_STRING_CHARPOS (*it
) += 1;
7301 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7303 bidi_move_to_visually_next (&it
->bidi_it
);
7304 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7305 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7306 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7308 ptrdiff_t stop
= it
->end_charpos
;
7310 if (it
->bidi_it
.scan_dir
< 0)
7312 composition_compute_stop_pos (&it
->cmp_it
,
7313 IT_STRING_CHARPOS (*it
),
7314 IT_STRING_BYTEPOS (*it
), stop
,
7320 consider_string_end
:
7322 if (it
->current
.overlay_string_index
>= 0)
7324 /* IT->string is an overlay string. Advance to the
7325 next, if there is one. */
7326 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7329 next_overlay_string (it
);
7331 setup_for_ellipsis (it
, 0);
7336 /* IT->string is not an overlay string. If we reached
7337 its end, and there is something on IT->stack, proceed
7338 with what is on the stack. This can be either another
7339 string, this time an overlay string, or a buffer. */
7340 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7344 if (it
->method
== GET_FROM_STRING
)
7345 goto consider_string_end
;
7350 case GET_FROM_IMAGE
:
7351 case GET_FROM_STRETCH
:
7352 /* The position etc with which we have to proceed are on
7353 the stack. The position may be at the end of a string,
7354 if the `display' property takes up the whole string. */
7355 eassert (it
->sp
> 0);
7357 if (it
->method
== GET_FROM_STRING
)
7358 goto consider_string_end
;
7362 /* There are no other methods defined, so this should be a bug. */
7366 eassert (it
->method
!= GET_FROM_STRING
7367 || (STRINGP (it
->string
)
7368 && IT_STRING_CHARPOS (*it
) >= 0));
7371 /* Load IT's display element fields with information about the next
7372 display element which comes from a display table entry or from the
7373 result of translating a control character to one of the forms `^C'
7376 IT->dpvec holds the glyphs to return as characters.
7377 IT->saved_face_id holds the face id before the display vector--it
7378 is restored into IT->face_id in set_iterator_to_next. */
7381 next_element_from_display_vector (struct it
*it
)
7386 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7388 it
->face_id
= it
->saved_face_id
;
7390 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7391 That seemed totally bogus - so I changed it... */
7392 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7394 if (GLYPH_CODE_P (gc
))
7396 it
->c
= GLYPH_CODE_CHAR (gc
);
7397 it
->len
= CHAR_BYTES (it
->c
);
7399 /* The entry may contain a face id to use. Such a face id is
7400 the id of a Lisp face, not a realized face. A face id of
7401 zero means no face is specified. */
7402 if (it
->dpvec_face_id
>= 0)
7403 it
->face_id
= it
->dpvec_face_id
;
7406 int lface_id
= GLYPH_CODE_FACE (gc
);
7408 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7413 /* Display table entry is invalid. Return a space. */
7414 it
->c
= ' ', it
->len
= 1;
7416 /* Don't change position and object of the iterator here. They are
7417 still the values of the character that had this display table
7418 entry or was translated, and that's what we want. */
7419 it
->what
= IT_CHARACTER
;
7423 /* Get the first element of string/buffer in the visual order, after
7424 being reseated to a new position in a string or a buffer. */
7426 get_visually_first_element (struct it
*it
)
7428 int string_p
= STRINGP (it
->string
) || it
->s
;
7429 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7430 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7432 if (STRINGP (it
->string
))
7434 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7435 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7439 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7440 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7443 if (it
->bidi_it
.charpos
== eob
)
7445 /* Nothing to do, but reset the FIRST_ELT flag, like
7446 bidi_paragraph_init does, because we are not going to
7448 it
->bidi_it
.first_elt
= 0;
7450 else if (it
->bidi_it
.charpos
== bob
7452 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7453 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7455 /* If we are at the beginning of a line/string, we can produce
7456 the next element right away. */
7457 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7458 bidi_move_to_visually_next (&it
->bidi_it
);
7462 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7464 /* We need to prime the bidi iterator starting at the line's or
7465 string's beginning, before we will be able to produce the
7468 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7471 it
->bidi_it
.charpos
= find_next_newline_no_quit (IT_CHARPOS (*it
),
7473 it
->bidi_it
.bytepos
= CHAR_TO_BYTE (it
->bidi_it
.charpos
);
7475 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7478 /* Now return to buffer/string position where we were asked
7479 to get the next display element, and produce that. */
7480 bidi_move_to_visually_next (&it
->bidi_it
);
7482 while (it
->bidi_it
.bytepos
!= orig_bytepos
7483 && it
->bidi_it
.charpos
< eob
);
7486 /* Adjust IT's position information to where we ended up. */
7487 if (STRINGP (it
->string
))
7489 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7490 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7494 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7495 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7498 if (STRINGP (it
->string
) || !it
->s
)
7500 ptrdiff_t stop
, charpos
, bytepos
;
7502 if (STRINGP (it
->string
))
7505 stop
= SCHARS (it
->string
);
7506 if (stop
> it
->end_charpos
)
7507 stop
= it
->end_charpos
;
7508 charpos
= IT_STRING_CHARPOS (*it
);
7509 bytepos
= IT_STRING_BYTEPOS (*it
);
7513 stop
= it
->end_charpos
;
7514 charpos
= IT_CHARPOS (*it
);
7515 bytepos
= IT_BYTEPOS (*it
);
7517 if (it
->bidi_it
.scan_dir
< 0)
7519 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7524 /* Load IT with the next display element from Lisp string IT->string.
7525 IT->current.string_pos is the current position within the string.
7526 If IT->current.overlay_string_index >= 0, the Lisp string is an
7530 next_element_from_string (struct it
*it
)
7532 struct text_pos position
;
7534 eassert (STRINGP (it
->string
));
7535 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7536 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7537 position
= it
->current
.string_pos
;
7539 /* With bidi reordering, the character to display might not be the
7540 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7541 that we were reseat()ed to a new string, whose paragraph
7542 direction is not known. */
7543 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7545 get_visually_first_element (it
);
7546 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7549 /* Time to check for invisible text? */
7550 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7552 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7555 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7556 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7558 /* With bidi non-linear iteration, we could find
7559 ourselves far beyond the last computed stop_charpos,
7560 with several other stop positions in between that we
7561 missed. Scan them all now, in buffer's logical
7562 order, until we find and handle the last stop_charpos
7563 that precedes our current position. */
7564 handle_stop_backwards (it
, it
->stop_charpos
);
7565 return GET_NEXT_DISPLAY_ELEMENT (it
);
7571 /* Take note of the stop position we just moved
7572 across, for when we will move back across it. */
7573 it
->prev_stop
= it
->stop_charpos
;
7574 /* If we are at base paragraph embedding level, take
7575 note of the last stop position seen at this
7577 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7578 it
->base_level_stop
= it
->stop_charpos
;
7582 /* Since a handler may have changed IT->method, we must
7584 return GET_NEXT_DISPLAY_ELEMENT (it
);
7588 /* If we are before prev_stop, we may have overstepped
7589 on our way backwards a stop_pos, and if so, we need
7590 to handle that stop_pos. */
7591 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7592 /* We can sometimes back up for reasons that have nothing
7593 to do with bidi reordering. E.g., compositions. The
7594 code below is only needed when we are above the base
7595 embedding level, so test for that explicitly. */
7596 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7598 /* If we lost track of base_level_stop, we have no better
7599 place for handle_stop_backwards to start from than string
7600 beginning. This happens, e.g., when we were reseated to
7601 the previous screenful of text by vertical-motion. */
7602 if (it
->base_level_stop
<= 0
7603 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7604 it
->base_level_stop
= 0;
7605 handle_stop_backwards (it
, it
->base_level_stop
);
7606 return GET_NEXT_DISPLAY_ELEMENT (it
);
7610 if (it
->current
.overlay_string_index
>= 0)
7612 /* Get the next character from an overlay string. In overlay
7613 strings, there is no field width or padding with spaces to
7615 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7620 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7621 IT_STRING_BYTEPOS (*it
),
7622 it
->bidi_it
.scan_dir
< 0
7624 : SCHARS (it
->string
))
7625 && next_element_from_composition (it
))
7629 else if (STRING_MULTIBYTE (it
->string
))
7631 const unsigned char *s
= (SDATA (it
->string
)
7632 + IT_STRING_BYTEPOS (*it
));
7633 it
->c
= string_char_and_length (s
, &it
->len
);
7637 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7643 /* Get the next character from a Lisp string that is not an
7644 overlay string. Such strings come from the mode line, for
7645 example. We may have to pad with spaces, or truncate the
7646 string. See also next_element_from_c_string. */
7647 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7652 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7654 /* Pad with spaces. */
7655 it
->c
= ' ', it
->len
= 1;
7656 CHARPOS (position
) = BYTEPOS (position
) = -1;
7658 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7659 IT_STRING_BYTEPOS (*it
),
7660 it
->bidi_it
.scan_dir
< 0
7662 : it
->string_nchars
)
7663 && next_element_from_composition (it
))
7667 else if (STRING_MULTIBYTE (it
->string
))
7669 const unsigned char *s
= (SDATA (it
->string
)
7670 + IT_STRING_BYTEPOS (*it
));
7671 it
->c
= string_char_and_length (s
, &it
->len
);
7675 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7680 /* Record what we have and where it came from. */
7681 it
->what
= IT_CHARACTER
;
7682 it
->object
= it
->string
;
7683 it
->position
= position
;
7688 /* Load IT with next display element from C string IT->s.
7689 IT->string_nchars is the maximum number of characters to return
7690 from the string. IT->end_charpos may be greater than
7691 IT->string_nchars when this function is called, in which case we
7692 may have to return padding spaces. Value is zero if end of string
7693 reached, including padding spaces. */
7696 next_element_from_c_string (struct it
*it
)
7701 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7702 it
->what
= IT_CHARACTER
;
7703 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7706 /* With bidi reordering, the character to display might not be the
7707 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7708 we were reseated to a new string, whose paragraph direction is
7710 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7711 get_visually_first_element (it
);
7713 /* IT's position can be greater than IT->string_nchars in case a
7714 field width or precision has been specified when the iterator was
7716 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7718 /* End of the game. */
7722 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7724 /* Pad with spaces. */
7725 it
->c
= ' ', it
->len
= 1;
7726 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7728 else if (it
->multibyte_p
)
7729 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7731 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7737 /* Set up IT to return characters from an ellipsis, if appropriate.
7738 The definition of the ellipsis glyphs may come from a display table
7739 entry. This function fills IT with the first glyph from the
7740 ellipsis if an ellipsis is to be displayed. */
7743 next_element_from_ellipsis (struct it
*it
)
7745 if (it
->selective_display_ellipsis_p
)
7746 setup_for_ellipsis (it
, it
->len
);
7749 /* The face at the current position may be different from the
7750 face we find after the invisible text. Remember what it
7751 was in IT->saved_face_id, and signal that it's there by
7752 setting face_before_selective_p. */
7753 it
->saved_face_id
= it
->face_id
;
7754 it
->method
= GET_FROM_BUFFER
;
7755 it
->object
= it
->w
->buffer
;
7756 reseat_at_next_visible_line_start (it
, 1);
7757 it
->face_before_selective_p
= 1;
7760 return GET_NEXT_DISPLAY_ELEMENT (it
);
7764 /* Deliver an image display element. The iterator IT is already
7765 filled with image information (done in handle_display_prop). Value
7770 next_element_from_image (struct it
*it
)
7772 it
->what
= IT_IMAGE
;
7773 it
->ignore_overlay_strings_at_pos_p
= 0;
7778 /* Fill iterator IT with next display element from a stretch glyph
7779 property. IT->object is the value of the text property. Value is
7783 next_element_from_stretch (struct it
*it
)
7785 it
->what
= IT_STRETCH
;
7789 /* Scan backwards from IT's current position until we find a stop
7790 position, or until BEGV. This is called when we find ourself
7791 before both the last known prev_stop and base_level_stop while
7792 reordering bidirectional text. */
7795 compute_stop_pos_backwards (struct it
*it
)
7797 const int SCAN_BACK_LIMIT
= 1000;
7798 struct text_pos pos
;
7799 struct display_pos save_current
= it
->current
;
7800 struct text_pos save_position
= it
->position
;
7801 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7802 ptrdiff_t where_we_are
= charpos
;
7803 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7804 ptrdiff_t save_end_pos
= it
->end_charpos
;
7806 eassert (NILP (it
->string
) && !it
->s
);
7807 eassert (it
->bidi_p
);
7811 it
->end_charpos
= min (charpos
+ 1, ZV
);
7812 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7813 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7814 reseat_1 (it
, pos
, 0);
7815 compute_stop_pos (it
);
7816 /* We must advance forward, right? */
7817 if (it
->stop_charpos
<= charpos
)
7820 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7822 if (it
->stop_charpos
<= where_we_are
)
7823 it
->prev_stop
= it
->stop_charpos
;
7825 it
->prev_stop
= BEGV
;
7827 it
->current
= save_current
;
7828 it
->position
= save_position
;
7829 it
->stop_charpos
= save_stop_pos
;
7830 it
->end_charpos
= save_end_pos
;
7833 /* Scan forward from CHARPOS in the current buffer/string, until we
7834 find a stop position > current IT's position. Then handle the stop
7835 position before that. This is called when we bump into a stop
7836 position while reordering bidirectional text. CHARPOS should be
7837 the last previously processed stop_pos (or BEGV/0, if none were
7838 processed yet) whose position is less that IT's current
7842 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7844 int bufp
= !STRINGP (it
->string
);
7845 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7846 struct display_pos save_current
= it
->current
;
7847 struct text_pos save_position
= it
->position
;
7848 struct text_pos pos1
;
7849 ptrdiff_t next_stop
;
7851 /* Scan in strict logical order. */
7852 eassert (it
->bidi_p
);
7856 it
->prev_stop
= charpos
;
7859 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7860 reseat_1 (it
, pos1
, 0);
7863 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7864 compute_stop_pos (it
);
7865 /* We must advance forward, right? */
7866 if (it
->stop_charpos
<= it
->prev_stop
)
7868 charpos
= it
->stop_charpos
;
7870 while (charpos
<= where_we_are
);
7873 it
->current
= save_current
;
7874 it
->position
= save_position
;
7875 next_stop
= it
->stop_charpos
;
7876 it
->stop_charpos
= it
->prev_stop
;
7878 it
->stop_charpos
= next_stop
;
7881 /* Load IT with the next display element from current_buffer. Value
7882 is zero if end of buffer reached. IT->stop_charpos is the next
7883 position at which to stop and check for text properties or buffer
7887 next_element_from_buffer (struct it
*it
)
7891 eassert (IT_CHARPOS (*it
) >= BEGV
);
7892 eassert (NILP (it
->string
) && !it
->s
);
7893 eassert (!it
->bidi_p
7894 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7895 && it
->bidi_it
.string
.s
== NULL
));
7897 /* With bidi reordering, the character to display might not be the
7898 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7899 we were reseat()ed to a new buffer position, which is potentially
7900 a different paragraph. */
7901 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7903 get_visually_first_element (it
);
7904 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7907 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7909 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7911 int overlay_strings_follow_p
;
7913 /* End of the game, except when overlay strings follow that
7914 haven't been returned yet. */
7915 if (it
->overlay_strings_at_end_processed_p
)
7916 overlay_strings_follow_p
= 0;
7919 it
->overlay_strings_at_end_processed_p
= 1;
7920 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7923 if (overlay_strings_follow_p
)
7924 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
7928 it
->position
= it
->current
.pos
;
7932 else if (!(!it
->bidi_p
7933 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7934 || IT_CHARPOS (*it
) == it
->stop_charpos
))
7936 /* With bidi non-linear iteration, we could find ourselves
7937 far beyond the last computed stop_charpos, with several
7938 other stop positions in between that we missed. Scan
7939 them all now, in buffer's logical order, until we find
7940 and handle the last stop_charpos that precedes our
7941 current position. */
7942 handle_stop_backwards (it
, it
->stop_charpos
);
7943 return GET_NEXT_DISPLAY_ELEMENT (it
);
7949 /* Take note of the stop position we just moved across,
7950 for when we will move back across it. */
7951 it
->prev_stop
= it
->stop_charpos
;
7952 /* If we are at base paragraph embedding level, take
7953 note of the last stop position seen at this
7955 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7956 it
->base_level_stop
= it
->stop_charpos
;
7959 return GET_NEXT_DISPLAY_ELEMENT (it
);
7963 /* If we are before prev_stop, we may have overstepped on
7964 our way backwards a stop_pos, and if so, we need to
7965 handle that stop_pos. */
7966 && IT_CHARPOS (*it
) < it
->prev_stop
7967 /* We can sometimes back up for reasons that have nothing
7968 to do with bidi reordering. E.g., compositions. The
7969 code below is only needed when we are above the base
7970 embedding level, so test for that explicitly. */
7971 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7973 if (it
->base_level_stop
<= 0
7974 || IT_CHARPOS (*it
) < it
->base_level_stop
)
7976 /* If we lost track of base_level_stop, we need to find
7977 prev_stop by looking backwards. This happens, e.g., when
7978 we were reseated to the previous screenful of text by
7980 it
->base_level_stop
= BEGV
;
7981 compute_stop_pos_backwards (it
);
7982 handle_stop_backwards (it
, it
->prev_stop
);
7985 handle_stop_backwards (it
, it
->base_level_stop
);
7986 return GET_NEXT_DISPLAY_ELEMENT (it
);
7990 /* No face changes, overlays etc. in sight, so just return a
7991 character from current_buffer. */
7995 /* Maybe run the redisplay end trigger hook. Performance note:
7996 This doesn't seem to cost measurable time. */
7997 if (it
->redisplay_end_trigger_charpos
7999 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8000 run_redisplay_end_trigger_hook (it
);
8002 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8003 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8005 && next_element_from_composition (it
))
8010 /* Get the next character, maybe multibyte. */
8011 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8012 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8013 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8015 it
->c
= *p
, it
->len
= 1;
8017 /* Record what we have and where it came from. */
8018 it
->what
= IT_CHARACTER
;
8019 it
->object
= it
->w
->buffer
;
8020 it
->position
= it
->current
.pos
;
8022 /* Normally we return the character found above, except when we
8023 really want to return an ellipsis for selective display. */
8028 /* A value of selective > 0 means hide lines indented more
8029 than that number of columns. */
8030 if (it
->selective
> 0
8031 && IT_CHARPOS (*it
) + 1 < ZV
8032 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8033 IT_BYTEPOS (*it
) + 1,
8036 success_p
= next_element_from_ellipsis (it
);
8037 it
->dpvec_char_len
= -1;
8040 else if (it
->c
== '\r' && it
->selective
== -1)
8042 /* A value of selective == -1 means that everything from the
8043 CR to the end of the line is invisible, with maybe an
8044 ellipsis displayed for it. */
8045 success_p
= next_element_from_ellipsis (it
);
8046 it
->dpvec_char_len
= -1;
8051 /* Value is zero if end of buffer reached. */
8052 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8057 /* Run the redisplay end trigger hook for IT. */
8060 run_redisplay_end_trigger_hook (struct it
*it
)
8062 Lisp_Object args
[3];
8064 /* IT->glyph_row should be non-null, i.e. we should be actually
8065 displaying something, or otherwise we should not run the hook. */
8066 eassert (it
->glyph_row
);
8068 /* Set up hook arguments. */
8069 args
[0] = Qredisplay_end_trigger_functions
;
8070 args
[1] = it
->window
;
8071 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8072 it
->redisplay_end_trigger_charpos
= 0;
8074 /* Since we are *trying* to run these functions, don't try to run
8075 them again, even if they get an error. */
8076 wset_redisplay_end_trigger (it
->w
, Qnil
);
8077 Frun_hook_with_args (3, args
);
8079 /* Notice if it changed the face of the character we are on. */
8080 handle_face_prop (it
);
8084 /* Deliver a composition display element. Unlike the other
8085 next_element_from_XXX, this function is not registered in the array
8086 get_next_element[]. It is called from next_element_from_buffer and
8087 next_element_from_string when necessary. */
8090 next_element_from_composition (struct it
*it
)
8092 it
->what
= IT_COMPOSITION
;
8093 it
->len
= it
->cmp_it
.nbytes
;
8094 if (STRINGP (it
->string
))
8098 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8099 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8102 it
->position
= it
->current
.string_pos
;
8103 it
->object
= it
->string
;
8104 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8105 IT_STRING_BYTEPOS (*it
), it
->string
);
8111 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8112 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8115 if (it
->bidi_it
.new_paragraph
)
8116 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8117 /* Resync the bidi iterator with IT's new position.
8118 FIXME: this doesn't support bidirectional text. */
8119 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8120 bidi_move_to_visually_next (&it
->bidi_it
);
8124 it
->position
= it
->current
.pos
;
8125 it
->object
= it
->w
->buffer
;
8126 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8127 IT_BYTEPOS (*it
), Qnil
);
8134 /***********************************************************************
8135 Moving an iterator without producing glyphs
8136 ***********************************************************************/
8138 /* Check if iterator is at a position corresponding to a valid buffer
8139 position after some move_it_ call. */
8141 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8142 ((it)->method == GET_FROM_STRING \
8143 ? IT_STRING_CHARPOS (*it) == 0 \
8147 /* Move iterator IT to a specified buffer or X position within one
8148 line on the display without producing glyphs.
8150 OP should be a bit mask including some or all of these bits:
8151 MOVE_TO_X: Stop upon reaching x-position TO_X.
8152 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8153 Regardless of OP's value, stop upon reaching the end of the display line.
8155 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8156 This means, in particular, that TO_X includes window's horizontal
8159 The return value has several possible values that
8160 say what condition caused the scan to stop:
8162 MOVE_POS_MATCH_OR_ZV
8163 - when TO_POS or ZV was reached.
8166 -when TO_X was reached before TO_POS or ZV were reached.
8169 - when we reached the end of the display area and the line must
8173 - when we reached the end of the display area and the line is
8177 - when we stopped at a line end, i.e. a newline or a CR and selective
8180 static enum move_it_result
8181 move_it_in_display_line_to (struct it
*it
,
8182 ptrdiff_t to_charpos
, int to_x
,
8183 enum move_operation_enum op
)
8185 enum move_it_result result
= MOVE_UNDEFINED
;
8186 struct glyph_row
*saved_glyph_row
;
8187 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8188 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8189 void *ppos_data
= NULL
;
8191 enum it_method prev_method
= it
->method
;
8192 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8193 int saw_smaller_pos
= prev_pos
< to_charpos
;
8195 /* Don't produce glyphs in produce_glyphs. */
8196 saved_glyph_row
= it
->glyph_row
;
8197 it
->glyph_row
= NULL
;
8199 /* Use wrap_it to save a copy of IT wherever a word wrap could
8200 occur. Use atpos_it to save a copy of IT at the desired buffer
8201 position, if found, so that we can scan ahead and check if the
8202 word later overshoots the window edge. Use atx_it similarly, for
8208 /* Use ppos_it under bidi reordering to save a copy of IT for the
8209 position > CHARPOS that is the closest to CHARPOS. We restore
8210 that position in IT when we have scanned the entire display line
8211 without finding a match for CHARPOS and all the character
8212 positions are greater than CHARPOS. */
8215 SAVE_IT (ppos_it
, *it
, ppos_data
);
8216 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8217 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8218 SAVE_IT (ppos_it
, *it
, ppos_data
);
8221 #define BUFFER_POS_REACHED_P() \
8222 ((op & MOVE_TO_POS) != 0 \
8223 && BUFFERP (it->object) \
8224 && (IT_CHARPOS (*it) == to_charpos \
8226 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8227 && IT_CHARPOS (*it) > to_charpos) \
8228 || (it->what == IT_COMPOSITION \
8229 && ((IT_CHARPOS (*it) > to_charpos \
8230 && to_charpos >= it->cmp_it.charpos) \
8231 || (IT_CHARPOS (*it) < to_charpos \
8232 && to_charpos <= it->cmp_it.charpos)))) \
8233 && (it->method == GET_FROM_BUFFER \
8234 || (it->method == GET_FROM_DISPLAY_VECTOR \
8235 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8237 /* If there's a line-/wrap-prefix, handle it. */
8238 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8239 && it
->current_y
< it
->last_visible_y
)
8240 handle_line_prefix (it
);
8242 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8243 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8247 int x
, i
, ascent
= 0, descent
= 0;
8249 /* Utility macro to reset an iterator with x, ascent, and descent. */
8250 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8251 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8252 (IT)->max_descent = descent)
8254 /* Stop if we move beyond TO_CHARPOS (after an image or a
8255 display string or stretch glyph). */
8256 if ((op
& MOVE_TO_POS
) != 0
8257 && BUFFERP (it
->object
)
8258 && it
->method
== GET_FROM_BUFFER
8260 /* When the iterator is at base embedding level, we
8261 are guaranteed that characters are delivered for
8262 display in strictly increasing order of their
8263 buffer positions. */
8264 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8265 && IT_CHARPOS (*it
) > to_charpos
)
8267 && (prev_method
== GET_FROM_IMAGE
8268 || prev_method
== GET_FROM_STRETCH
8269 || prev_method
== GET_FROM_STRING
)
8270 /* Passed TO_CHARPOS from left to right. */
8271 && ((prev_pos
< to_charpos
8272 && IT_CHARPOS (*it
) > to_charpos
)
8273 /* Passed TO_CHARPOS from right to left. */
8274 || (prev_pos
> to_charpos
8275 && IT_CHARPOS (*it
) < to_charpos
)))))
8277 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8279 result
= MOVE_POS_MATCH_OR_ZV
;
8282 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8283 /* If wrap_it is valid, the current position might be in a
8284 word that is wrapped. So, save the iterator in
8285 atpos_it and continue to see if wrapping happens. */
8286 SAVE_IT (atpos_it
, *it
, atpos_data
);
8289 /* Stop when ZV reached.
8290 We used to stop here when TO_CHARPOS reached as well, but that is
8291 too soon if this glyph does not fit on this line. So we handle it
8292 explicitly below. */
8293 if (!get_next_display_element (it
))
8295 result
= MOVE_POS_MATCH_OR_ZV
;
8299 if (it
->line_wrap
== TRUNCATE
)
8301 if (BUFFER_POS_REACHED_P ())
8303 result
= MOVE_POS_MATCH_OR_ZV
;
8309 if (it
->line_wrap
== WORD_WRAP
)
8311 if (IT_DISPLAYING_WHITESPACE (it
))
8315 /* We have reached a glyph that follows one or more
8316 whitespace characters. If the position is
8317 already found, we are done. */
8318 if (atpos_it
.sp
>= 0)
8320 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8321 result
= MOVE_POS_MATCH_OR_ZV
;
8326 RESTORE_IT (it
, &atx_it
, atx_data
);
8327 result
= MOVE_X_REACHED
;
8330 /* Otherwise, we can wrap here. */
8331 SAVE_IT (wrap_it
, *it
, wrap_data
);
8337 /* Remember the line height for the current line, in case
8338 the next element doesn't fit on the line. */
8339 ascent
= it
->max_ascent
;
8340 descent
= it
->max_descent
;
8342 /* The call to produce_glyphs will get the metrics of the
8343 display element IT is loaded with. Record the x-position
8344 before this display element, in case it doesn't fit on the
8348 PRODUCE_GLYPHS (it
);
8350 if (it
->area
!= TEXT_AREA
)
8352 prev_method
= it
->method
;
8353 if (it
->method
== GET_FROM_BUFFER
)
8354 prev_pos
= IT_CHARPOS (*it
);
8355 set_iterator_to_next (it
, 1);
8356 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8357 SET_TEXT_POS (this_line_min_pos
,
8358 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8360 && (op
& MOVE_TO_POS
)
8361 && IT_CHARPOS (*it
) > to_charpos
8362 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8363 SAVE_IT (ppos_it
, *it
, ppos_data
);
8367 /* The number of glyphs we get back in IT->nglyphs will normally
8368 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8369 character on a terminal frame, or (iii) a line end. For the
8370 second case, IT->nglyphs - 1 padding glyphs will be present.
8371 (On X frames, there is only one glyph produced for a
8372 composite character.)
8374 The behavior implemented below means, for continuation lines,
8375 that as many spaces of a TAB as fit on the current line are
8376 displayed there. For terminal frames, as many glyphs of a
8377 multi-glyph character are displayed in the current line, too.
8378 This is what the old redisplay code did, and we keep it that
8379 way. Under X, the whole shape of a complex character must
8380 fit on the line or it will be completely displayed in the
8383 Note that both for tabs and padding glyphs, all glyphs have
8387 /* More than one glyph or glyph doesn't fit on line. All
8388 glyphs have the same width. */
8389 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8391 int x_before_this_char
= x
;
8392 int hpos_before_this_char
= it
->hpos
;
8394 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8396 new_x
= x
+ single_glyph_width
;
8398 /* We want to leave anything reaching TO_X to the caller. */
8399 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8401 if (BUFFER_POS_REACHED_P ())
8403 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8404 goto buffer_pos_reached
;
8405 if (atpos_it
.sp
< 0)
8407 SAVE_IT (atpos_it
, *it
, atpos_data
);
8408 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8413 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8416 result
= MOVE_X_REACHED
;
8421 SAVE_IT (atx_it
, *it
, atx_data
);
8422 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8427 if (/* Lines are continued. */
8428 it
->line_wrap
!= TRUNCATE
8429 && (/* And glyph doesn't fit on the line. */
8430 new_x
> it
->last_visible_x
8431 /* Or it fits exactly and we're on a window
8433 || (new_x
== it
->last_visible_x
8434 && FRAME_WINDOW_P (it
->f
)
8435 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8436 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8437 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8439 if (/* IT->hpos == 0 means the very first glyph
8440 doesn't fit on the line, e.g. a wide image. */
8442 || (new_x
== it
->last_visible_x
8443 && FRAME_WINDOW_P (it
->f
)))
8446 it
->current_x
= new_x
;
8448 /* The character's last glyph just barely fits
8450 if (i
== it
->nglyphs
- 1)
8452 /* If this is the destination position,
8453 return a position *before* it in this row,
8454 now that we know it fits in this row. */
8455 if (BUFFER_POS_REACHED_P ())
8457 if (it
->line_wrap
!= WORD_WRAP
8460 it
->hpos
= hpos_before_this_char
;
8461 it
->current_x
= x_before_this_char
;
8462 result
= MOVE_POS_MATCH_OR_ZV
;
8465 if (it
->line_wrap
== WORD_WRAP
8468 SAVE_IT (atpos_it
, *it
, atpos_data
);
8469 atpos_it
.current_x
= x_before_this_char
;
8470 atpos_it
.hpos
= hpos_before_this_char
;
8474 prev_method
= it
->method
;
8475 if (it
->method
== GET_FROM_BUFFER
)
8476 prev_pos
= IT_CHARPOS (*it
);
8477 set_iterator_to_next (it
, 1);
8478 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8479 SET_TEXT_POS (this_line_min_pos
,
8480 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8481 /* On graphical terminals, newlines may
8482 "overflow" into the fringe if
8483 overflow-newline-into-fringe is non-nil.
8484 On text terminals, and on graphical
8485 terminals with no right margin, newlines
8486 may overflow into the last glyph on the
8488 if (!FRAME_WINDOW_P (it
->f
)
8490 && it
->bidi_it
.paragraph_dir
== R2L
)
8491 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8492 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8493 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8495 if (!get_next_display_element (it
))
8497 result
= MOVE_POS_MATCH_OR_ZV
;
8500 if (BUFFER_POS_REACHED_P ())
8502 if (ITERATOR_AT_END_OF_LINE_P (it
))
8503 result
= MOVE_POS_MATCH_OR_ZV
;
8505 result
= MOVE_LINE_CONTINUED
;
8508 if (ITERATOR_AT_END_OF_LINE_P (it
))
8510 result
= MOVE_NEWLINE_OR_CR
;
8517 IT_RESET_X_ASCENT_DESCENT (it
);
8519 if (wrap_it
.sp
>= 0)
8521 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8526 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8528 result
= MOVE_LINE_CONTINUED
;
8532 if (BUFFER_POS_REACHED_P ())
8534 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8535 goto buffer_pos_reached
;
8536 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8538 SAVE_IT (atpos_it
, *it
, atpos_data
);
8539 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8543 if (new_x
> it
->first_visible_x
)
8545 /* Glyph is visible. Increment number of glyphs that
8546 would be displayed. */
8551 if (result
!= MOVE_UNDEFINED
)
8554 else if (BUFFER_POS_REACHED_P ())
8557 IT_RESET_X_ASCENT_DESCENT (it
);
8558 result
= MOVE_POS_MATCH_OR_ZV
;
8561 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8563 /* Stop when TO_X specified and reached. This check is
8564 necessary here because of lines consisting of a line end,
8565 only. The line end will not produce any glyphs and we
8566 would never get MOVE_X_REACHED. */
8567 eassert (it
->nglyphs
== 0);
8568 result
= MOVE_X_REACHED
;
8572 /* Is this a line end? If yes, we're done. */
8573 if (ITERATOR_AT_END_OF_LINE_P (it
))
8575 /* If we are past TO_CHARPOS, but never saw any character
8576 positions smaller than TO_CHARPOS, return
8577 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8579 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8581 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8583 if (IT_CHARPOS (ppos_it
) < ZV
)
8585 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8586 result
= MOVE_POS_MATCH_OR_ZV
;
8589 goto buffer_pos_reached
;
8591 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8592 && IT_CHARPOS (*it
) > to_charpos
)
8593 goto buffer_pos_reached
;
8595 result
= MOVE_NEWLINE_OR_CR
;
8598 result
= MOVE_NEWLINE_OR_CR
;
8602 prev_method
= it
->method
;
8603 if (it
->method
== GET_FROM_BUFFER
)
8604 prev_pos
= IT_CHARPOS (*it
);
8605 /* The current display element has been consumed. Advance
8607 set_iterator_to_next (it
, 1);
8608 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8609 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8610 if (IT_CHARPOS (*it
) < to_charpos
)
8611 saw_smaller_pos
= 1;
8613 && (op
& MOVE_TO_POS
)
8614 && IT_CHARPOS (*it
) >= to_charpos
8615 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8616 SAVE_IT (ppos_it
, *it
, ppos_data
);
8618 /* Stop if lines are truncated and IT's current x-position is
8619 past the right edge of the window now. */
8620 if (it
->line_wrap
== TRUNCATE
8621 && it
->current_x
>= it
->last_visible_x
)
8623 if (!FRAME_WINDOW_P (it
->f
)
8624 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8625 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8626 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8627 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8631 if ((at_eob_p
= !get_next_display_element (it
))
8632 || BUFFER_POS_REACHED_P ()
8633 /* If we are past TO_CHARPOS, but never saw any
8634 character positions smaller than TO_CHARPOS,
8635 return MOVE_POS_MATCH_OR_ZV, like the
8636 unidirectional display did. */
8637 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8639 && IT_CHARPOS (*it
) > to_charpos
))
8642 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8643 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8644 result
= MOVE_POS_MATCH_OR_ZV
;
8647 if (ITERATOR_AT_END_OF_LINE_P (it
))
8649 result
= MOVE_NEWLINE_OR_CR
;
8653 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8655 && IT_CHARPOS (*it
) > to_charpos
)
8657 if (IT_CHARPOS (ppos_it
) < ZV
)
8658 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8659 result
= MOVE_POS_MATCH_OR_ZV
;
8662 result
= MOVE_LINE_TRUNCATED
;
8665 #undef IT_RESET_X_ASCENT_DESCENT
8668 #undef BUFFER_POS_REACHED_P
8670 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8671 restore the saved iterator. */
8672 if (atpos_it
.sp
>= 0)
8673 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8674 else if (atx_it
.sp
>= 0)
8675 RESTORE_IT (it
, &atx_it
, atx_data
);
8680 bidi_unshelve_cache (atpos_data
, 1);
8682 bidi_unshelve_cache (atx_data
, 1);
8684 bidi_unshelve_cache (wrap_data
, 1);
8686 bidi_unshelve_cache (ppos_data
, 1);
8688 /* Restore the iterator settings altered at the beginning of this
8690 it
->glyph_row
= saved_glyph_row
;
8694 /* For external use. */
8696 move_it_in_display_line (struct it
*it
,
8697 ptrdiff_t to_charpos
, int to_x
,
8698 enum move_operation_enum op
)
8700 if (it
->line_wrap
== WORD_WRAP
8701 && (op
& MOVE_TO_X
))
8704 void *save_data
= NULL
;
8707 SAVE_IT (save_it
, *it
, save_data
);
8708 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8709 /* When word-wrap is on, TO_X may lie past the end
8710 of a wrapped line. Then it->current is the
8711 character on the next line, so backtrack to the
8712 space before the wrap point. */
8713 if (skip
== MOVE_LINE_CONTINUED
)
8715 int prev_x
= max (it
->current_x
- 1, 0);
8716 RESTORE_IT (it
, &save_it
, save_data
);
8717 move_it_in_display_line_to
8718 (it
, -1, prev_x
, MOVE_TO_X
);
8721 bidi_unshelve_cache (save_data
, 1);
8724 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8728 /* Move IT forward until it satisfies one or more of the criteria in
8729 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8731 OP is a bit-mask that specifies where to stop, and in particular,
8732 which of those four position arguments makes a difference. See the
8733 description of enum move_operation_enum.
8735 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8736 screen line, this function will set IT to the next position that is
8737 displayed to the right of TO_CHARPOS on the screen. */
8740 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8742 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8743 int line_height
, line_start_x
= 0, reached
= 0;
8744 void *backup_data
= NULL
;
8748 if (op
& MOVE_TO_VPOS
)
8750 /* If no TO_CHARPOS and no TO_X specified, stop at the
8751 start of the line TO_VPOS. */
8752 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8754 if (it
->vpos
== to_vpos
)
8760 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8764 /* TO_VPOS >= 0 means stop at TO_X in the line at
8765 TO_VPOS, or at TO_POS, whichever comes first. */
8766 if (it
->vpos
== to_vpos
)
8772 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8774 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8779 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8781 /* We have reached TO_X but not in the line we want. */
8782 skip
= move_it_in_display_line_to (it
, to_charpos
,
8784 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8792 else if (op
& MOVE_TO_Y
)
8794 struct it it_backup
;
8796 if (it
->line_wrap
== WORD_WRAP
)
8797 SAVE_IT (it_backup
, *it
, backup_data
);
8799 /* TO_Y specified means stop at TO_X in the line containing
8800 TO_Y---or at TO_CHARPOS if this is reached first. The
8801 problem is that we can't really tell whether the line
8802 contains TO_Y before we have completely scanned it, and
8803 this may skip past TO_X. What we do is to first scan to
8806 If TO_X is not specified, use a TO_X of zero. The reason
8807 is to make the outcome of this function more predictable.
8808 If we didn't use TO_X == 0, we would stop at the end of
8809 the line which is probably not what a caller would expect
8811 skip
= move_it_in_display_line_to
8812 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8813 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8815 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8816 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8818 else if (skip
== MOVE_X_REACHED
)
8820 /* If TO_X was reached, we want to know whether TO_Y is
8821 in the line. We know this is the case if the already
8822 scanned glyphs make the line tall enough. Otherwise,
8823 we must check by scanning the rest of the line. */
8824 line_height
= it
->max_ascent
+ it
->max_descent
;
8825 if (to_y
>= it
->current_y
8826 && to_y
< it
->current_y
+ line_height
)
8831 SAVE_IT (it_backup
, *it
, backup_data
);
8832 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8833 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8835 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8836 line_height
= it
->max_ascent
+ it
->max_descent
;
8837 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8839 if (to_y
>= it
->current_y
8840 && to_y
< it
->current_y
+ line_height
)
8842 /* If TO_Y is in this line and TO_X was reached
8843 above, we scanned too far. We have to restore
8844 IT's settings to the ones before skipping. But
8845 keep the more accurate values of max_ascent and
8846 max_descent we've found while skipping the rest
8847 of the line, for the sake of callers, such as
8848 pos_visible_p, that need to know the line
8850 int max_ascent
= it
->max_ascent
;
8851 int max_descent
= it
->max_descent
;
8853 RESTORE_IT (it
, &it_backup
, backup_data
);
8854 it
->max_ascent
= max_ascent
;
8855 it
->max_descent
= max_descent
;
8861 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8867 /* Check whether TO_Y is in this line. */
8868 line_height
= it
->max_ascent
+ it
->max_descent
;
8869 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8871 if (to_y
>= it
->current_y
8872 && to_y
< it
->current_y
+ line_height
)
8874 /* When word-wrap is on, TO_X may lie past the end
8875 of a wrapped line. Then it->current is the
8876 character on the next line, so backtrack to the
8877 space before the wrap point. */
8878 if (skip
== MOVE_LINE_CONTINUED
8879 && it
->line_wrap
== WORD_WRAP
)
8881 int prev_x
= max (it
->current_x
- 1, 0);
8882 RESTORE_IT (it
, &it_backup
, backup_data
);
8883 skip
= move_it_in_display_line_to
8884 (it
, -1, prev_x
, MOVE_TO_X
);
8893 else if (BUFFERP (it
->object
)
8894 && (it
->method
== GET_FROM_BUFFER
8895 || it
->method
== GET_FROM_STRETCH
)
8896 && IT_CHARPOS (*it
) >= to_charpos
8897 /* Under bidi iteration, a call to set_iterator_to_next
8898 can scan far beyond to_charpos if the initial
8899 portion of the next line needs to be reordered. In
8900 that case, give move_it_in_display_line_to another
8903 && it
->bidi_it
.scan_dir
== -1))
8904 skip
= MOVE_POS_MATCH_OR_ZV
;
8906 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8910 case MOVE_POS_MATCH_OR_ZV
:
8914 case MOVE_NEWLINE_OR_CR
:
8915 set_iterator_to_next (it
, 1);
8916 it
->continuation_lines_width
= 0;
8919 case MOVE_LINE_TRUNCATED
:
8920 it
->continuation_lines_width
= 0;
8921 reseat_at_next_visible_line_start (it
, 0);
8922 if ((op
& MOVE_TO_POS
) != 0
8923 && IT_CHARPOS (*it
) > to_charpos
)
8930 case MOVE_LINE_CONTINUED
:
8931 /* For continued lines ending in a tab, some of the glyphs
8932 associated with the tab are displayed on the current
8933 line. Since it->current_x does not include these glyphs,
8934 we use it->last_visible_x instead. */
8937 it
->continuation_lines_width
+= it
->last_visible_x
;
8938 /* When moving by vpos, ensure that the iterator really
8939 advances to the next line (bug#847, bug#969). Fixme:
8940 do we need to do this in other circumstances? */
8941 if (it
->current_x
!= it
->last_visible_x
8942 && (op
& MOVE_TO_VPOS
)
8943 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
8945 line_start_x
= it
->current_x
+ it
->pixel_width
8946 - it
->last_visible_x
;
8947 set_iterator_to_next (it
, 0);
8951 it
->continuation_lines_width
+= it
->current_x
;
8958 /* Reset/increment for the next run. */
8959 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
8960 it
->current_x
= line_start_x
;
8963 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8965 last_height
= it
->max_ascent
+ it
->max_descent
;
8966 last_max_ascent
= it
->max_ascent
;
8967 it
->max_ascent
= it
->max_descent
= 0;
8972 /* On text terminals, we may stop at the end of a line in the middle
8973 of a multi-character glyph. If the glyph itself is continued,
8974 i.e. it is actually displayed on the next line, don't treat this
8975 stopping point as valid; move to the next line instead (unless
8976 that brings us offscreen). */
8977 if (!FRAME_WINDOW_P (it
->f
)
8979 && IT_CHARPOS (*it
) == to_charpos
8980 && it
->what
== IT_CHARACTER
8982 && it
->line_wrap
== WINDOW_WRAP
8983 && it
->current_x
== it
->last_visible_x
- 1
8986 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
8988 it
->continuation_lines_width
+= it
->current_x
;
8989 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
8990 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
8992 last_height
= it
->max_ascent
+ it
->max_descent
;
8993 last_max_ascent
= it
->max_ascent
;
8997 bidi_unshelve_cache (backup_data
, 1);
8999 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9003 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9005 If DY > 0, move IT backward at least that many pixels. DY = 0
9006 means move IT backward to the preceding line start or BEGV. This
9007 function may move over more than DY pixels if IT->current_y - DY
9008 ends up in the middle of a line; in this case IT->current_y will be
9009 set to the top of the line moved to. */
9012 move_it_vertically_backward (struct it
*it
, int dy
)
9016 void *it2data
= NULL
, *it3data
= NULL
;
9017 ptrdiff_t start_pos
;
9022 start_pos
= IT_CHARPOS (*it
);
9024 /* Estimate how many newlines we must move back. */
9025 nlines
= max (1, dy
/ FRAME_LINE_HEIGHT (it
->f
));
9027 /* Set the iterator's position that many lines back. */
9028 while (nlines
-- && IT_CHARPOS (*it
) > BEGV
)
9029 back_to_previous_visible_line_start (it
);
9031 /* Reseat the iterator here. When moving backward, we don't want
9032 reseat to skip forward over invisible text, set up the iterator
9033 to deliver from overlay strings at the new position etc. So,
9034 use reseat_1 here. */
9035 reseat_1 (it
, it
->current
.pos
, 1);
9037 /* We are now surely at a line start. */
9038 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9039 reordering is in effect. */
9040 it
->continuation_lines_width
= 0;
9042 /* Move forward and see what y-distance we moved. First move to the
9043 start of the next line so that we get its height. We need this
9044 height to be able to tell whether we reached the specified
9046 SAVE_IT (it2
, *it
, it2data
);
9047 it2
.max_ascent
= it2
.max_descent
= 0;
9050 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9051 MOVE_TO_POS
| MOVE_TO_VPOS
);
9053 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9054 /* If we are in a display string which starts at START_POS,
9055 and that display string includes a newline, and we are
9056 right after that newline (i.e. at the beginning of a
9057 display line), exit the loop, because otherwise we will
9058 infloop, since move_it_to will see that it is already at
9059 START_POS and will not move. */
9060 || (it2
.method
== GET_FROM_STRING
9061 && IT_CHARPOS (it2
) == start_pos
9062 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9063 eassert (IT_CHARPOS (*it
) >= BEGV
);
9064 SAVE_IT (it3
, it2
, it3data
);
9066 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9067 eassert (IT_CHARPOS (*it
) >= BEGV
);
9068 /* H is the actual vertical distance from the position in *IT
9069 and the starting position. */
9070 h
= it2
.current_y
- it
->current_y
;
9071 /* NLINES is the distance in number of lines. */
9072 nlines
= it2
.vpos
- it
->vpos
;
9074 /* Correct IT's y and vpos position
9075 so that they are relative to the starting point. */
9081 /* DY == 0 means move to the start of the screen line. The
9082 value of nlines is > 0 if continuation lines were involved,
9083 or if the original IT position was at start of a line. */
9084 RESTORE_IT (it
, it
, it2data
);
9086 move_it_by_lines (it
, nlines
);
9087 /* The above code moves us to some position NLINES down,
9088 usually to its first glyph (leftmost in an L2R line), but
9089 that's not necessarily the start of the line, under bidi
9090 reordering. We want to get to the character position
9091 that is immediately after the newline of the previous
9094 && !it
->continuation_lines_width
9095 && !STRINGP (it
->string
)
9096 && IT_CHARPOS (*it
) > BEGV
9097 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9100 find_next_newline_no_quit (IT_CHARPOS (*it
) - 1, -1);
9102 move_it_to (it
, nl_pos
, -1, -1, -1, MOVE_TO_POS
);
9104 bidi_unshelve_cache (it3data
, 1);
9108 /* The y-position we try to reach, relative to *IT.
9109 Note that H has been subtracted in front of the if-statement. */
9110 int target_y
= it
->current_y
+ h
- dy
;
9111 int y0
= it3
.current_y
;
9115 RESTORE_IT (&it3
, &it3
, it3data
);
9116 y1
= line_bottom_y (&it3
);
9117 line_height
= y1
- y0
;
9118 RESTORE_IT (it
, it
, it2data
);
9119 /* If we did not reach target_y, try to move further backward if
9120 we can. If we moved too far backward, try to move forward. */
9121 if (target_y
< it
->current_y
9122 /* This is heuristic. In a window that's 3 lines high, with
9123 a line height of 13 pixels each, recentering with point
9124 on the bottom line will try to move -39/2 = 19 pixels
9125 backward. Try to avoid moving into the first line. */
9126 && (it
->current_y
- target_y
9127 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9128 && IT_CHARPOS (*it
) > BEGV
)
9130 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9131 target_y
- it
->current_y
));
9132 dy
= it
->current_y
- target_y
;
9133 goto move_further_back
;
9135 else if (target_y
>= it
->current_y
+ line_height
9136 && IT_CHARPOS (*it
) < ZV
)
9138 /* Should move forward by at least one line, maybe more.
9140 Note: Calling move_it_by_lines can be expensive on
9141 terminal frames, where compute_motion is used (via
9142 vmotion) to do the job, when there are very long lines
9143 and truncate-lines is nil. That's the reason for
9144 treating terminal frames specially here. */
9146 if (!FRAME_WINDOW_P (it
->f
))
9147 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9152 move_it_by_lines (it
, 1);
9154 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9161 /* Move IT by a specified amount of pixel lines DY. DY negative means
9162 move backwards. DY = 0 means move to start of screen line. At the
9163 end, IT will be on the start of a screen line. */
9166 move_it_vertically (struct it
*it
, int dy
)
9169 move_it_vertically_backward (it
, -dy
);
9172 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9173 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9174 MOVE_TO_POS
| MOVE_TO_Y
);
9175 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9177 /* If buffer ends in ZV without a newline, move to the start of
9178 the line to satisfy the post-condition. */
9179 if (IT_CHARPOS (*it
) == ZV
9181 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9182 move_it_by_lines (it
, 0);
9187 /* Move iterator IT past the end of the text line it is in. */
9190 move_it_past_eol (struct it
*it
)
9192 enum move_it_result rc
;
9194 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9195 if (rc
== MOVE_NEWLINE_OR_CR
)
9196 set_iterator_to_next (it
, 0);
9200 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9201 negative means move up. DVPOS == 0 means move to the start of the
9204 Optimization idea: If we would know that IT->f doesn't use
9205 a face with proportional font, we could be faster for
9206 truncate-lines nil. */
9209 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9212 /* The commented-out optimization uses vmotion on terminals. This
9213 gives bad results, because elements like it->what, on which
9214 callers such as pos_visible_p rely, aren't updated. */
9215 /* struct position pos;
9216 if (!FRAME_WINDOW_P (it->f))
9218 struct text_pos textpos;
9220 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9221 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9222 reseat (it, textpos, 1);
9223 it->vpos += pos.vpos;
9224 it->current_y += pos.vpos;
9230 /* DVPOS == 0 means move to the start of the screen line. */
9231 move_it_vertically_backward (it
, 0);
9232 /* Let next call to line_bottom_y calculate real line height */
9237 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9238 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9240 /* Only move to the next buffer position if we ended up in a
9241 string from display property, not in an overlay string
9242 (before-string or after-string). That is because the
9243 latter don't conceal the underlying buffer position, so
9244 we can ask to move the iterator to the exact position we
9245 are interested in. Note that, even if we are already at
9246 IT_CHARPOS (*it), the call below is not a no-op, as it
9247 will detect that we are at the end of the string, pop the
9248 iterator, and compute it->current_x and it->hpos
9250 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9251 -1, -1, -1, MOVE_TO_POS
);
9257 void *it2data
= NULL
;
9258 ptrdiff_t start_charpos
, i
;
9260 /* Start at the beginning of the screen line containing IT's
9261 position. This may actually move vertically backwards,
9262 in case of overlays, so adjust dvpos accordingly. */
9264 move_it_vertically_backward (it
, 0);
9267 /* Go back -DVPOS visible lines and reseat the iterator there. */
9268 start_charpos
= IT_CHARPOS (*it
);
9269 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > BEGV
; --i
)
9270 back_to_previous_visible_line_start (it
);
9271 reseat (it
, it
->current
.pos
, 1);
9273 /* Move further back if we end up in a string or an image. */
9274 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9276 /* First try to move to start of display line. */
9278 move_it_vertically_backward (it
, 0);
9280 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9282 /* If start of line is still in string or image,
9283 move further back. */
9284 back_to_previous_visible_line_start (it
);
9285 reseat (it
, it
->current
.pos
, 1);
9289 it
->current_x
= it
->hpos
= 0;
9291 /* Above call may have moved too far if continuation lines
9292 are involved. Scan forward and see if it did. */
9293 SAVE_IT (it2
, *it
, it2data
);
9294 it2
.vpos
= it2
.current_y
= 0;
9295 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9296 it
->vpos
-= it2
.vpos
;
9297 it
->current_y
-= it2
.current_y
;
9298 it
->current_x
= it
->hpos
= 0;
9300 /* If we moved too far back, move IT some lines forward. */
9301 if (it2
.vpos
> -dvpos
)
9303 int delta
= it2
.vpos
+ dvpos
;
9305 RESTORE_IT (&it2
, &it2
, it2data
);
9306 SAVE_IT (it2
, *it
, it2data
);
9307 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9308 /* Move back again if we got too far ahead. */
9309 if (IT_CHARPOS (*it
) >= start_charpos
)
9310 RESTORE_IT (it
, &it2
, it2data
);
9312 bidi_unshelve_cache (it2data
, 1);
9315 RESTORE_IT (it
, it
, it2data
);
9319 /* Return 1 if IT points into the middle of a display vector. */
9322 in_display_vector_p (struct it
*it
)
9324 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9325 && it
->current
.dpvec_index
> 0
9326 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9330 /***********************************************************************
9332 ***********************************************************************/
9335 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9339 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9341 Lisp_Object args
[3];
9342 Lisp_Object msg
, fmt
;
9345 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9349 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9351 args
[0] = fmt
= build_string (format
);
9354 msg
= Fformat (3, args
);
9356 len
= SBYTES (msg
) + 1;
9357 buffer
= SAFE_ALLOCA (len
);
9358 memcpy (buffer
, SDATA (msg
), len
);
9360 message_dolog (buffer
, len
- 1, 1, 0);
9367 /* Output a newline in the *Messages* buffer if "needs" one. */
9370 message_log_maybe_newline (void)
9372 if (message_log_need_newline
)
9373 message_dolog ("", 0, 1, 0);
9377 /* Add a string M of length NBYTES to the message log, optionally
9378 terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if
9379 nonzero, means interpret the contents of M as multibyte. This
9380 function calls low-level routines in order to bypass text property
9381 hooks, etc. which might not be safe to run.
9383 This may GC (insert may run before/after change hooks),
9384 so the buffer M must NOT point to a Lisp string. */
9387 message_dolog (const char *m
, ptrdiff_t nbytes
, int nlflag
, int multibyte
)
9389 const unsigned char *msg
= (const unsigned char *) m
;
9391 if (!NILP (Vmemory_full
))
9394 if (!NILP (Vmessage_log_max
))
9396 struct buffer
*oldbuf
;
9397 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9398 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9399 ptrdiff_t point_at_end
= 0;
9400 ptrdiff_t zv_at_end
= 0;
9401 Lisp_Object old_deactivate_mark
;
9403 struct gcpro gcpro1
;
9405 old_deactivate_mark
= Vdeactivate_mark
;
9406 oldbuf
= current_buffer
;
9407 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9408 bset_undo_list (current_buffer
, Qt
);
9410 oldpoint
= message_dolog_marker1
;
9411 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9412 oldbegv
= message_dolog_marker2
;
9413 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9414 oldzv
= message_dolog_marker3
;
9415 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9416 GCPRO1 (old_deactivate_mark
);
9424 BEGV_BYTE
= BEG_BYTE
;
9427 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9429 /* Insert the string--maybe converting multibyte to single byte
9430 or vice versa, so that all the text fits the buffer. */
9432 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9438 /* Convert a multibyte string to single-byte
9439 for the *Message* buffer. */
9440 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9442 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9443 work
[0] = (ASCII_CHAR_P (c
)
9445 : multibyte_char_to_unibyte (c
));
9446 insert_1_both (work
, 1, 1, 1, 0, 0);
9449 else if (! multibyte
9450 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9454 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9455 /* Convert a single-byte string to multibyte
9456 for the *Message* buffer. */
9457 for (i
= 0; i
< nbytes
; i
++)
9460 MAKE_CHAR_MULTIBYTE (c
);
9461 char_bytes
= CHAR_STRING (c
, str
);
9462 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9466 insert_1 (m
, nbytes
, 1, 0, 0);
9470 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9472 insert_1 ("\n", 1, 1, 0, 0);
9474 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9476 this_bol_byte
= PT_BYTE
;
9478 /* See if this line duplicates the previous one.
9479 If so, combine duplicates. */
9482 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9484 prev_bol_byte
= PT_BYTE
;
9486 dups
= message_log_check_duplicate (prev_bol_byte
,
9490 del_range_both (prev_bol
, prev_bol_byte
,
9491 this_bol
, this_bol_byte
, 0);
9494 char dupstr
[sizeof " [ times]"
9495 + INT_STRLEN_BOUND (printmax_t
)];
9497 /* If you change this format, don't forget to also
9498 change message_log_check_duplicate. */
9499 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9500 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9501 insert_1 (dupstr
, duplen
, 1, 0, 1);
9506 /* If we have more than the desired maximum number of lines
9507 in the *Messages* buffer now, delete the oldest ones.
9508 This is safe because we don't have undo in this buffer. */
9510 if (NATNUMP (Vmessage_log_max
))
9512 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9513 -XFASTINT (Vmessage_log_max
) - 1, 0);
9514 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9517 BEGV
= marker_position (oldbegv
);
9518 BEGV_BYTE
= marker_byte_position (oldbegv
);
9527 ZV
= marker_position (oldzv
);
9528 ZV_BYTE
= marker_byte_position (oldzv
);
9532 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9534 /* We can't do Fgoto_char (oldpoint) because it will run some
9536 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9537 marker_byte_position (oldpoint
));
9540 unchain_marker (XMARKER (oldpoint
));
9541 unchain_marker (XMARKER (oldbegv
));
9542 unchain_marker (XMARKER (oldzv
));
9544 shown
= buffer_window_count (current_buffer
) > 0;
9545 set_buffer_internal (oldbuf
);
9547 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9548 message_log_need_newline
= !nlflag
;
9549 Vdeactivate_mark
= old_deactivate_mark
;
9554 /* We are at the end of the buffer after just having inserted a newline.
9555 (Note: We depend on the fact we won't be crossing the gap.)
9556 Check to see if the most recent message looks a lot like the previous one.
9557 Return 0 if different, 1 if the new one should just replace it, or a
9558 value N > 1 if we should also append " [N times]". */
9561 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9564 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9566 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9567 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9569 for (i
= 0; i
< len
; i
++)
9571 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9579 if (*p1
++ == ' ' && *p1
++ == '[')
9582 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9583 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9590 /* Display an echo area message M with a specified length of NBYTES
9591 bytes. The string may include null characters. If M is 0, clear
9592 out any existing message, and let the mini-buffer text show
9595 This may GC, so the buffer M must NOT point to a Lisp string. */
9598 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9600 /* First flush out any partial line written with print. */
9601 message_log_maybe_newline ();
9603 message_dolog (m
, nbytes
, 1, multibyte
);
9604 message2_nolog (m
, nbytes
, multibyte
);
9608 /* The non-logging counterpart of message2. */
9611 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9613 struct frame
*sf
= SELECTED_FRAME ();
9614 message_enable_multibyte
= multibyte
;
9616 if (FRAME_INITIAL_P (sf
))
9618 if (noninteractive_need_newline
)
9619 putc ('\n', stderr
);
9620 noninteractive_need_newline
= 0;
9622 fwrite (m
, nbytes
, 1, stderr
);
9623 if (cursor_in_echo_area
== 0)
9624 fprintf (stderr
, "\n");
9627 /* A null message buffer means that the frame hasn't really been
9628 initialized yet. Error messages get reported properly by
9629 cmd_error, so this must be just an informative message; toss it. */
9630 else if (INTERACTIVE
9631 && sf
->glyphs_initialized_p
9632 && FRAME_MESSAGE_BUF (sf
))
9634 Lisp_Object mini_window
;
9637 /* Get the frame containing the mini-buffer
9638 that the selected frame is using. */
9639 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9640 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9642 FRAME_SAMPLE_VISIBILITY (f
);
9643 if (FRAME_VISIBLE_P (sf
)
9644 && ! FRAME_VISIBLE_P (f
))
9645 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9649 set_message (m
, Qnil
, nbytes
, multibyte
);
9650 if (minibuffer_auto_raise
)
9651 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9654 clear_message (1, 1);
9656 do_pending_window_change (0);
9657 echo_area_display (1);
9658 do_pending_window_change (0);
9659 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9660 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9665 /* Display an echo area message M with a specified length of NBYTES
9666 bytes. The string may include null characters. If M is not a
9667 string, clear out any existing message, and let the mini-buffer
9670 This function cancels echoing. */
9673 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9675 struct gcpro gcpro1
;
9678 clear_message (1,1);
9681 /* First flush out any partial line written with print. */
9682 message_log_maybe_newline ();
9686 char *buffer
= SAFE_ALLOCA (nbytes
);
9687 memcpy (buffer
, SDATA (m
), nbytes
);
9688 message_dolog (buffer
, nbytes
, 1, multibyte
);
9691 message3_nolog (m
, nbytes
, multibyte
);
9697 /* The non-logging version of message3.
9698 This does not cancel echoing, because it is used for echoing.
9699 Perhaps we need to make a separate function for echoing
9700 and make this cancel echoing. */
9703 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9705 struct frame
*sf
= SELECTED_FRAME ();
9706 message_enable_multibyte
= multibyte
;
9708 if (FRAME_INITIAL_P (sf
))
9710 if (noninteractive_need_newline
)
9711 putc ('\n', stderr
);
9712 noninteractive_need_newline
= 0;
9714 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9715 if (cursor_in_echo_area
== 0)
9716 fprintf (stderr
, "\n");
9719 /* A null message buffer means that the frame hasn't really been
9720 initialized yet. Error messages get reported properly by
9721 cmd_error, so this must be just an informative message; toss it. */
9722 else if (INTERACTIVE
9723 && sf
->glyphs_initialized_p
9724 && FRAME_MESSAGE_BUF (sf
))
9726 Lisp_Object mini_window
;
9730 /* Get the frame containing the mini-buffer
9731 that the selected frame is using. */
9732 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9733 frame
= XWINDOW (mini_window
)->frame
;
9736 FRAME_SAMPLE_VISIBILITY (f
);
9737 if (FRAME_VISIBLE_P (sf
)
9738 && !FRAME_VISIBLE_P (f
))
9739 Fmake_frame_visible (frame
);
9741 if (STRINGP (m
) && SCHARS (m
) > 0)
9743 set_message (NULL
, m
, nbytes
, multibyte
);
9744 if (minibuffer_auto_raise
)
9745 Fraise_frame (frame
);
9746 /* Assume we are not echoing.
9747 (If we are, echo_now will override this.) */
9748 echo_message_buffer
= Qnil
;
9751 clear_message (1, 1);
9753 do_pending_window_change (0);
9754 echo_area_display (1);
9755 do_pending_window_change (0);
9756 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9757 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9762 /* Display a null-terminated echo area message M. If M is 0, clear
9763 out any existing message, and let the mini-buffer text show through.
9765 The buffer M must continue to exist until after the echo area gets
9766 cleared or some other message gets displayed there. Do not pass
9767 text that is stored in a Lisp string. Do not pass text in a buffer
9768 that was alloca'd. */
9771 message1 (const char *m
)
9773 message2 (m
, (m
? strlen (m
) : 0), 0);
9777 /* The non-logging counterpart of message1. */
9780 message1_nolog (const char *m
)
9782 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9785 /* Display a message M which contains a single %s
9786 which gets replaced with STRING. */
9789 message_with_string (const char *m
, Lisp_Object string
, int log
)
9791 CHECK_STRING (string
);
9797 if (noninteractive_need_newline
)
9798 putc ('\n', stderr
);
9799 noninteractive_need_newline
= 0;
9800 fprintf (stderr
, m
, SDATA (string
));
9801 if (!cursor_in_echo_area
)
9802 fprintf (stderr
, "\n");
9806 else if (INTERACTIVE
)
9808 /* The frame whose minibuffer we're going to display the message on.
9809 It may be larger than the selected frame, so we need
9810 to use its buffer, not the selected frame's buffer. */
9811 Lisp_Object mini_window
;
9812 struct frame
*f
, *sf
= SELECTED_FRAME ();
9814 /* Get the frame containing the minibuffer
9815 that the selected frame is using. */
9816 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9817 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9819 /* A null message buffer means that the frame hasn't really been
9820 initialized yet. Error messages get reported properly by
9821 cmd_error, so this must be just an informative message; toss it. */
9822 if (FRAME_MESSAGE_BUF (f
))
9824 Lisp_Object args
[2], msg
;
9825 struct gcpro gcpro1
, gcpro2
;
9827 args
[0] = build_string (m
);
9828 args
[1] = msg
= string
;
9829 GCPRO2 (args
[0], msg
);
9832 msg
= Fformat (2, args
);
9835 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9837 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9841 /* Print should start at the beginning of the message
9842 buffer next time. */
9843 message_buf_print
= 0;
9849 /* Dump an informative message to the minibuf. If M is 0, clear out
9850 any existing message, and let the mini-buffer text show through. */
9853 vmessage (const char *m
, va_list ap
)
9859 if (noninteractive_need_newline
)
9860 putc ('\n', stderr
);
9861 noninteractive_need_newline
= 0;
9862 vfprintf (stderr
, m
, ap
);
9863 if (cursor_in_echo_area
== 0)
9864 fprintf (stderr
, "\n");
9868 else if (INTERACTIVE
)
9870 /* The frame whose mini-buffer we're going to display the message
9871 on. It may be larger than the selected frame, so we need to
9872 use its buffer, not the selected frame's buffer. */
9873 Lisp_Object mini_window
;
9874 struct frame
*f
, *sf
= SELECTED_FRAME ();
9876 /* Get the frame containing the mini-buffer
9877 that the selected frame is using. */
9878 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9879 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9881 /* A null message buffer means that the frame hasn't really been
9882 initialized yet. Error messages get reported properly by
9883 cmd_error, so this must be just an informative message; toss
9885 if (FRAME_MESSAGE_BUF (f
))
9891 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9892 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9894 message2 (FRAME_MESSAGE_BUF (f
), len
, 1);
9899 /* Print should start at the beginning of the message
9900 buffer next time. */
9901 message_buf_print
= 0;
9907 message (const char *m
, ...)
9917 /* The non-logging version of message. */
9920 message_nolog (const char *m
, ...)
9922 Lisp_Object old_log_max
;
9925 old_log_max
= Vmessage_log_max
;
9926 Vmessage_log_max
= Qnil
;
9928 Vmessage_log_max
= old_log_max
;
9934 /* Display the current message in the current mini-buffer. This is
9935 only called from error handlers in process.c, and is not time
9939 update_echo_area (void)
9941 if (!NILP (echo_area_buffer
[0]))
9944 string
= Fcurrent_message ();
9945 message3 (string
, SBYTES (string
),
9946 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9951 /* Make sure echo area buffers in `echo_buffers' are live.
9952 If they aren't, make new ones. */
9955 ensure_echo_area_buffers (void)
9959 for (i
= 0; i
< 2; ++i
)
9960 if (!BUFFERP (echo_buffer
[i
])
9961 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9964 Lisp_Object old_buffer
;
9967 old_buffer
= echo_buffer
[i
];
9968 echo_buffer
[i
] = Fget_buffer_create
9969 (make_formatted_string (name
, " *Echo Area %d*", i
));
9970 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9971 /* to force word wrap in echo area -
9972 it was decided to postpone this*/
9973 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9975 for (j
= 0; j
< 2; ++j
)
9976 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9977 echo_area_buffer
[j
] = echo_buffer
[i
];
9982 /* Call FN with args A1..A4 with either the current or last displayed
9983 echo_area_buffer as current buffer.
9985 WHICH zero means use the current message buffer
9986 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9987 from echo_buffer[] and clear it.
9989 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9990 suitable buffer from echo_buffer[] and clear it.
9992 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9993 that the current message becomes the last displayed one, make
9994 choose a suitable buffer for echo_area_buffer[0], and clear it.
9996 Value is what FN returns. */
9999 with_echo_area_buffer (struct window
*w
, int which
,
10000 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
10001 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10003 Lisp_Object buffer
;
10004 int this_one
, the_other
, clear_buffer_p
, rc
;
10005 ptrdiff_t count
= SPECPDL_INDEX ();
10007 /* If buffers aren't live, make new ones. */
10008 ensure_echo_area_buffers ();
10010 clear_buffer_p
= 0;
10013 this_one
= 0, the_other
= 1;
10014 else if (which
> 0)
10015 this_one
= 1, the_other
= 0;
10018 this_one
= 0, the_other
= 1;
10019 clear_buffer_p
= 1;
10021 /* We need a fresh one in case the current echo buffer equals
10022 the one containing the last displayed echo area message. */
10023 if (!NILP (echo_area_buffer
[this_one
])
10024 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10025 echo_area_buffer
[this_one
] = Qnil
;
10028 /* Choose a suitable buffer from echo_buffer[] is we don't
10030 if (NILP (echo_area_buffer
[this_one
]))
10032 echo_area_buffer
[this_one
]
10033 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10034 ? echo_buffer
[the_other
]
10035 : echo_buffer
[this_one
]);
10036 clear_buffer_p
= 1;
10039 buffer
= echo_area_buffer
[this_one
];
10041 /* Don't get confused by reusing the buffer used for echoing
10042 for a different purpose. */
10043 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10046 record_unwind_protect (unwind_with_echo_area_buffer
,
10047 with_echo_area_buffer_unwind_data (w
));
10049 /* Make the echo area buffer current. Note that for display
10050 purposes, it is not necessary that the displayed window's buffer
10051 == current_buffer, except for text property lookup. So, let's
10052 only set that buffer temporarily here without doing a full
10053 Fset_window_buffer. We must also change w->pointm, though,
10054 because otherwise an assertions in unshow_buffer fails, and Emacs
10056 set_buffer_internal_1 (XBUFFER (buffer
));
10059 wset_buffer (w
, buffer
);
10060 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10063 bset_undo_list (current_buffer
, Qt
);
10064 bset_read_only (current_buffer
, Qnil
);
10065 specbind (Qinhibit_read_only
, Qt
);
10066 specbind (Qinhibit_modification_hooks
, Qt
);
10068 if (clear_buffer_p
&& Z
> BEG
)
10069 del_range (BEG
, Z
);
10071 eassert (BEGV
>= BEG
);
10072 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10074 rc
= fn (a1
, a2
, a3
, a4
);
10076 eassert (BEGV
>= BEG
);
10077 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10079 unbind_to (count
, Qnil
);
10084 /* Save state that should be preserved around the call to the function
10085 FN called in with_echo_area_buffer. */
10088 with_echo_area_buffer_unwind_data (struct window
*w
)
10091 Lisp_Object vector
, tmp
;
10093 /* Reduce consing by keeping one vector in
10094 Vwith_echo_area_save_vector. */
10095 vector
= Vwith_echo_area_save_vector
;
10096 Vwith_echo_area_save_vector
= Qnil
;
10099 vector
= Fmake_vector (make_number (7), Qnil
);
10101 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10102 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10103 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10107 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10108 ASET (vector
, i
, w
->buffer
); ++i
;
10109 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10110 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10115 for (; i
< end
; ++i
)
10116 ASET (vector
, i
, Qnil
);
10119 eassert (i
== ASIZE (vector
));
10124 /* Restore global state from VECTOR which was created by
10125 with_echo_area_buffer_unwind_data. */
10128 unwind_with_echo_area_buffer (Lisp_Object vector
)
10130 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10131 Vdeactivate_mark
= AREF (vector
, 1);
10132 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10134 if (WINDOWP (AREF (vector
, 3)))
10137 Lisp_Object buffer
, charpos
, bytepos
;
10139 w
= XWINDOW (AREF (vector
, 3));
10140 buffer
= AREF (vector
, 4);
10141 charpos
= AREF (vector
, 5);
10142 bytepos
= AREF (vector
, 6);
10144 wset_buffer (w
, buffer
);
10145 set_marker_both (w
->pointm
, buffer
,
10146 XFASTINT (charpos
), XFASTINT (bytepos
));
10149 Vwith_echo_area_save_vector
= vector
;
10154 /* Set up the echo area for use by print functions. MULTIBYTE_P
10155 non-zero means we will print multibyte. */
10158 setup_echo_area_for_printing (int multibyte_p
)
10160 /* If we can't find an echo area any more, exit. */
10161 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10162 Fkill_emacs (Qnil
);
10164 ensure_echo_area_buffers ();
10166 if (!message_buf_print
)
10168 /* A message has been output since the last time we printed.
10169 Choose a fresh echo area buffer. */
10170 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10171 echo_area_buffer
[0] = echo_buffer
[1];
10173 echo_area_buffer
[0] = echo_buffer
[0];
10175 /* Switch to that buffer and clear it. */
10176 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10177 bset_truncate_lines (current_buffer
, Qnil
);
10181 ptrdiff_t count
= SPECPDL_INDEX ();
10182 specbind (Qinhibit_read_only
, Qt
);
10183 /* Note that undo recording is always disabled. */
10184 del_range (BEG
, Z
);
10185 unbind_to (count
, Qnil
);
10187 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10189 /* Set up the buffer for the multibyteness we need. */
10191 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10192 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10194 /* Raise the frame containing the echo area. */
10195 if (minibuffer_auto_raise
)
10197 struct frame
*sf
= SELECTED_FRAME ();
10198 Lisp_Object mini_window
;
10199 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10200 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10203 message_log_maybe_newline ();
10204 message_buf_print
= 1;
10208 if (NILP (echo_area_buffer
[0]))
10210 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10211 echo_area_buffer
[0] = echo_buffer
[1];
10213 echo_area_buffer
[0] = echo_buffer
[0];
10216 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10218 /* Someone switched buffers between print requests. */
10219 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10220 bset_truncate_lines (current_buffer
, Qnil
);
10226 /* Display an echo area message in window W. Value is non-zero if W's
10227 height is changed. If display_last_displayed_message_p is
10228 non-zero, display the message that was last displayed, otherwise
10229 display the current message. */
10232 display_echo_area (struct window
*w
)
10234 int i
, no_message_p
, window_height_changed_p
;
10236 /* Temporarily disable garbage collections while displaying the echo
10237 area. This is done because a GC can print a message itself.
10238 That message would modify the echo area buffer's contents while a
10239 redisplay of the buffer is going on, and seriously confuse
10241 ptrdiff_t count
= inhibit_garbage_collection ();
10243 /* If there is no message, we must call display_echo_area_1
10244 nevertheless because it resizes the window. But we will have to
10245 reset the echo_area_buffer in question to nil at the end because
10246 with_echo_area_buffer will sets it to an empty buffer. */
10247 i
= display_last_displayed_message_p
? 1 : 0;
10248 no_message_p
= NILP (echo_area_buffer
[i
]);
10250 window_height_changed_p
10251 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10252 display_echo_area_1
,
10253 (intptr_t) w
, Qnil
, 0, 0);
10256 echo_area_buffer
[i
] = Qnil
;
10258 unbind_to (count
, Qnil
);
10259 return window_height_changed_p
;
10263 /* Helper for display_echo_area. Display the current buffer which
10264 contains the current echo area message in window W, a mini-window,
10265 a pointer to which is passed in A1. A2..A4 are currently not used.
10266 Change the height of W so that all of the message is displayed.
10267 Value is non-zero if height of W was changed. */
10270 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10273 struct window
*w
= (struct window
*) i1
;
10274 Lisp_Object window
;
10275 struct text_pos start
;
10276 int window_height_changed_p
= 0;
10278 /* Do this before displaying, so that we have a large enough glyph
10279 matrix for the display. If we can't get enough space for the
10280 whole text, display the last N lines. That works by setting w->start. */
10281 window_height_changed_p
= resize_mini_window (w
, 0);
10283 /* Use the starting position chosen by resize_mini_window. */
10284 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10287 clear_glyph_matrix (w
->desired_matrix
);
10288 XSETWINDOW (window
, w
);
10289 try_window (window
, start
, 0);
10291 return window_height_changed_p
;
10295 /* Resize the echo area window to exactly the size needed for the
10296 currently displayed message, if there is one. If a mini-buffer
10297 is active, don't shrink it. */
10300 resize_echo_area_exactly (void)
10302 if (BUFFERP (echo_area_buffer
[0])
10303 && WINDOWP (echo_area_window
))
10305 struct window
*w
= XWINDOW (echo_area_window
);
10307 Lisp_Object resize_exactly
;
10309 if (minibuf_level
== 0)
10310 resize_exactly
= Qt
;
10312 resize_exactly
= Qnil
;
10314 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10315 (intptr_t) w
, resize_exactly
,
10319 ++windows_or_buffers_changed
;
10320 ++update_mode_lines
;
10321 redisplay_internal ();
10327 /* Callback function for with_echo_area_buffer, when used from
10328 resize_echo_area_exactly. A1 contains a pointer to the window to
10329 resize, EXACTLY non-nil means resize the mini-window exactly to the
10330 size of the text displayed. A3 and A4 are not used. Value is what
10331 resize_mini_window returns. */
10334 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10337 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10341 /* Resize mini-window W to fit the size of its contents. EXACT_P
10342 means size the window exactly to the size needed. Otherwise, it's
10343 only enlarged until W's buffer is empty.
10345 Set W->start to the right place to begin display. If the whole
10346 contents fit, start at the beginning. Otherwise, start so as
10347 to make the end of the contents appear. This is particularly
10348 important for y-or-n-p, but seems desirable generally.
10350 Value is non-zero if the window height has been changed. */
10353 resize_mini_window (struct window
*w
, int exact_p
)
10355 struct frame
*f
= XFRAME (w
->frame
);
10356 int window_height_changed_p
= 0;
10358 eassert (MINI_WINDOW_P (w
));
10360 /* By default, start display at the beginning. */
10361 set_marker_both (w
->start
, w
->buffer
,
10362 BUF_BEGV (XBUFFER (w
->buffer
)),
10363 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10365 /* Don't resize windows while redisplaying a window; it would
10366 confuse redisplay functions when the size of the window they are
10367 displaying changes from under them. Such a resizing can happen,
10368 for instance, when which-func prints a long message while
10369 we are running fontification-functions. We're running these
10370 functions with safe_call which binds inhibit-redisplay to t. */
10371 if (!NILP (Vinhibit_redisplay
))
10374 /* Nil means don't try to resize. */
10375 if (NILP (Vresize_mini_windows
)
10376 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10379 if (!FRAME_MINIBUF_ONLY_P (f
))
10382 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10383 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10385 EMACS_INT max_height
;
10386 int unit
= FRAME_LINE_HEIGHT (f
);
10387 struct text_pos start
;
10388 struct buffer
*old_current_buffer
= NULL
;
10390 if (current_buffer
!= XBUFFER (w
->buffer
))
10392 old_current_buffer
= current_buffer
;
10393 set_buffer_internal (XBUFFER (w
->buffer
));
10396 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10398 /* Compute the max. number of lines specified by the user. */
10399 if (FLOATP (Vmax_mini_window_height
))
10400 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10401 else if (INTEGERP (Vmax_mini_window_height
))
10402 max_height
= XINT (Vmax_mini_window_height
);
10404 max_height
= total_height
/ 4;
10406 /* Correct that max. height if it's bogus. */
10407 max_height
= clip_to_bounds (1, max_height
, total_height
);
10409 /* Find out the height of the text in the window. */
10410 if (it
.line_wrap
== TRUNCATE
)
10415 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10416 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10417 height
= it
.current_y
+ last_height
;
10419 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10420 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10421 height
= (height
+ unit
- 1) / unit
;
10424 /* Compute a suitable window start. */
10425 if (height
> max_height
)
10427 height
= max_height
;
10428 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10429 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10430 start
= it
.current
.pos
;
10433 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10434 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10436 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10438 /* Let it grow only, until we display an empty message, in which
10439 case the window shrinks again. */
10440 if (height
> WINDOW_TOTAL_LINES (w
))
10442 int old_height
= WINDOW_TOTAL_LINES (w
);
10443 freeze_window_starts (f
, 1);
10444 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10445 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10447 else if (height
< WINDOW_TOTAL_LINES (w
)
10448 && (exact_p
|| BEGV
== ZV
))
10450 int old_height
= WINDOW_TOTAL_LINES (w
);
10451 freeze_window_starts (f
, 0);
10452 shrink_mini_window (w
);
10453 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10458 /* Always resize to exact size needed. */
10459 if (height
> WINDOW_TOTAL_LINES (w
))
10461 int old_height
= WINDOW_TOTAL_LINES (w
);
10462 freeze_window_starts (f
, 1);
10463 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10464 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10466 else if (height
< WINDOW_TOTAL_LINES (w
))
10468 int old_height
= WINDOW_TOTAL_LINES (w
);
10469 freeze_window_starts (f
, 0);
10470 shrink_mini_window (w
);
10474 freeze_window_starts (f
, 1);
10475 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10478 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10482 if (old_current_buffer
)
10483 set_buffer_internal (old_current_buffer
);
10486 return window_height_changed_p
;
10490 /* Value is the current message, a string, or nil if there is no
10491 current message. */
10494 current_message (void)
10498 if (!BUFFERP (echo_area_buffer
[0]))
10502 with_echo_area_buffer (0, 0, current_message_1
,
10503 (intptr_t) &msg
, Qnil
, 0, 0);
10505 echo_area_buffer
[0] = Qnil
;
10513 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10516 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10519 *msg
= make_buffer_string (BEG
, Z
, 1);
10526 /* Push the current message on Vmessage_stack for later restoration
10527 by restore_message. Value is non-zero if the current message isn't
10528 empty. This is a relatively infrequent operation, so it's not
10529 worth optimizing. */
10532 push_message (void)
10534 Lisp_Object msg
= current_message ();
10535 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10536 return STRINGP (msg
);
10540 /* Restore message display from the top of Vmessage_stack. */
10543 restore_message (void)
10547 eassert (CONSP (Vmessage_stack
));
10548 msg
= XCAR (Vmessage_stack
);
10550 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10552 message3_nolog (msg
, 0, 0);
10556 /* Handler for record_unwind_protect calling pop_message. */
10559 pop_message_unwind (Lisp_Object dummy
)
10565 /* Pop the top-most entry off Vmessage_stack. */
10570 eassert (CONSP (Vmessage_stack
));
10571 Vmessage_stack
= XCDR (Vmessage_stack
);
10575 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10576 exits. If the stack is not empty, we have a missing pop_message
10580 check_message_stack (void)
10582 if (!NILP (Vmessage_stack
))
10587 /* Truncate to NCHARS what will be displayed in the echo area the next
10588 time we display it---but don't redisplay it now. */
10591 truncate_echo_area (ptrdiff_t nchars
)
10594 echo_area_buffer
[0] = Qnil
;
10595 /* A null message buffer means that the frame hasn't really been
10596 initialized yet. Error messages get reported properly by
10597 cmd_error, so this must be just an informative message; toss it. */
10598 else if (!noninteractive
10600 && !NILP (echo_area_buffer
[0]))
10602 struct frame
*sf
= SELECTED_FRAME ();
10603 if (FRAME_MESSAGE_BUF (sf
))
10604 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10609 /* Helper function for truncate_echo_area. Truncate the current
10610 message to at most NCHARS characters. */
10613 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10615 if (BEG
+ nchars
< Z
)
10616 del_range (BEG
+ nchars
, Z
);
10618 echo_area_buffer
[0] = Qnil
;
10622 /* Set the current message to a substring of S or STRING.
10624 If STRING is a Lisp string, set the message to the first NBYTES
10625 bytes from STRING. NBYTES zero means use the whole string. If
10626 STRING is multibyte, the message will be displayed multibyte.
10628 If S is not null, set the message to the first LEN bytes of S. LEN
10629 zero means use the whole string. MULTIBYTE_P non-zero means S is
10630 multibyte. Display the message multibyte in that case.
10632 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10633 to t before calling set_message_1 (which calls insert).
10637 set_message (const char *s
, Lisp_Object string
,
10638 ptrdiff_t nbytes
, int multibyte_p
)
10640 message_enable_multibyte
10641 = ((s
&& multibyte_p
)
10642 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10644 with_echo_area_buffer (0, -1, set_message_1
,
10645 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10646 message_buf_print
= 0;
10647 help_echo_showing_p
= 0;
10649 if (STRINGP (Vdebug_on_message
)
10650 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10651 call_debugger (list2 (Qerror
, string
));
10655 /* Helper function for set_message. Arguments have the same meaning
10656 as there, with A1 corresponding to S and A2 corresponding to STRING
10657 This function is called with the echo area buffer being
10661 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10664 const char *s
= (const char *) i1
;
10665 const unsigned char *msg
= (const unsigned char *) s
;
10666 Lisp_Object string
= a2
;
10668 /* Change multibyteness of the echo buffer appropriately. */
10669 if (message_enable_multibyte
10670 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10671 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10673 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10674 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10675 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10677 /* Insert new message at BEG. */
10678 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10680 if (STRINGP (string
))
10685 nbytes
= SBYTES (string
);
10686 nchars
= string_byte_to_char (string
, nbytes
);
10688 /* This function takes care of single/multibyte conversion. We
10689 just have to ensure that the echo area buffer has the right
10690 setting of enable_multibyte_characters. */
10691 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10696 nbytes
= strlen (s
);
10698 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10700 /* Convert from multi-byte to single-byte. */
10705 /* Convert a multibyte string to single-byte. */
10706 for (i
= 0; i
< nbytes
; i
+= n
)
10708 c
= string_char_and_length (msg
+ i
, &n
);
10709 work
[0] = (ASCII_CHAR_P (c
)
10711 : multibyte_char_to_unibyte (c
));
10712 insert_1_both (work
, 1, 1, 1, 0, 0);
10715 else if (!multibyte_p
10716 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10718 /* Convert from single-byte to multi-byte. */
10721 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10723 /* Convert a single-byte string to multibyte. */
10724 for (i
= 0; i
< nbytes
; i
++)
10727 MAKE_CHAR_MULTIBYTE (c
);
10728 n
= CHAR_STRING (c
, str
);
10729 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10733 insert_1 (s
, nbytes
, 1, 0, 0);
10740 /* Clear messages. CURRENT_P non-zero means clear the current
10741 message. LAST_DISPLAYED_P non-zero means clear the message
10745 clear_message (int current_p
, int last_displayed_p
)
10749 echo_area_buffer
[0] = Qnil
;
10750 message_cleared_p
= 1;
10753 if (last_displayed_p
)
10754 echo_area_buffer
[1] = Qnil
;
10756 message_buf_print
= 0;
10759 /* Clear garbaged frames.
10761 This function is used where the old redisplay called
10762 redraw_garbaged_frames which in turn called redraw_frame which in
10763 turn called clear_frame. The call to clear_frame was a source of
10764 flickering. I believe a clear_frame is not necessary. It should
10765 suffice in the new redisplay to invalidate all current matrices,
10766 and ensure a complete redisplay of all windows. */
10769 clear_garbaged_frames (void)
10771 if (frame_garbaged
)
10773 Lisp_Object tail
, frame
;
10774 int changed_count
= 0;
10776 FOR_EACH_FRAME (tail
, frame
)
10778 struct frame
*f
= XFRAME (frame
);
10780 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10785 f
->force_flush_display_p
= 1;
10787 clear_current_matrices (f
);
10794 frame_garbaged
= 0;
10796 ++windows_or_buffers_changed
;
10801 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10802 is non-zero update selected_frame. Value is non-zero if the
10803 mini-windows height has been changed. */
10806 echo_area_display (int update_frame_p
)
10808 Lisp_Object mini_window
;
10811 int window_height_changed_p
= 0;
10812 struct frame
*sf
= SELECTED_FRAME ();
10814 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10815 w
= XWINDOW (mini_window
);
10816 f
= XFRAME (WINDOW_FRAME (w
));
10818 /* Don't display if frame is invisible or not yet initialized. */
10819 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10822 #ifdef HAVE_WINDOW_SYSTEM
10823 /* When Emacs starts, selected_frame may be the initial terminal
10824 frame. If we let this through, a message would be displayed on
10826 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10828 #endif /* HAVE_WINDOW_SYSTEM */
10830 /* Redraw garbaged frames. */
10831 clear_garbaged_frames ();
10833 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10835 echo_area_window
= mini_window
;
10836 window_height_changed_p
= display_echo_area (w
);
10837 w
->must_be_updated_p
= 1;
10839 /* Update the display, unless called from redisplay_internal.
10840 Also don't update the screen during redisplay itself. The
10841 update will happen at the end of redisplay, and an update
10842 here could cause confusion. */
10843 if (update_frame_p
&& !redisplaying_p
)
10847 /* If the display update has been interrupted by pending
10848 input, update mode lines in the frame. Due to the
10849 pending input, it might have been that redisplay hasn't
10850 been called, so that mode lines above the echo area are
10851 garbaged. This looks odd, so we prevent it here. */
10852 if (!display_completed
)
10853 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10855 if (window_height_changed_p
10856 /* Don't do this if Emacs is shutting down. Redisplay
10857 needs to run hooks. */
10858 && !NILP (Vrun_hooks
))
10860 /* Must update other windows. Likewise as in other
10861 cases, don't let this update be interrupted by
10863 ptrdiff_t count
= SPECPDL_INDEX ();
10864 specbind (Qredisplay_dont_pause
, Qt
);
10865 windows_or_buffers_changed
= 1;
10866 redisplay_internal ();
10867 unbind_to (count
, Qnil
);
10869 else if (FRAME_WINDOW_P (f
) && n
== 0)
10871 /* Window configuration is the same as before.
10872 Can do with a display update of the echo area,
10873 unless we displayed some mode lines. */
10874 update_single_window (w
, 1);
10875 FRAME_RIF (f
)->flush_display (f
);
10878 update_frame (f
, 1, 1);
10880 /* If cursor is in the echo area, make sure that the next
10881 redisplay displays the minibuffer, so that the cursor will
10882 be replaced with what the minibuffer wants. */
10883 if (cursor_in_echo_area
)
10884 ++windows_or_buffers_changed
;
10887 else if (!EQ (mini_window
, selected_window
))
10888 windows_or_buffers_changed
++;
10890 /* Last displayed message is now the current message. */
10891 echo_area_buffer
[1] = echo_area_buffer
[0];
10892 /* Inform read_char that we're not echoing. */
10893 echo_message_buffer
= Qnil
;
10895 /* Prevent redisplay optimization in redisplay_internal by resetting
10896 this_line_start_pos. This is done because the mini-buffer now
10897 displays the message instead of its buffer text. */
10898 if (EQ (mini_window
, selected_window
))
10899 CHARPOS (this_line_start_pos
) = 0;
10901 return window_height_changed_p
;
10904 /* Nonzero if the current window's buffer is shown in more than one
10905 window and was modified since last redisplay. */
10908 buffer_shared_and_changed (void)
10910 return (buffer_window_count (current_buffer
) > 1
10911 && UNCHANGED_MODIFIED
< MODIFF
);
10914 /* Nonzero if W doesn't reflect the actual state of current buffer due
10915 to its text or overlays change. FIXME: this may be called when
10916 XBUFFER (w->buffer) != current_buffer, which looks suspicious. */
10919 window_outdated (struct window
*w
)
10921 return (w
->last_modified
< MODIFF
10922 || w
->last_overlay_modified
< OVERLAY_MODIFF
);
10925 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10926 is enabled and mark of W's buffer was changed since last W's update. */
10929 window_buffer_changed (struct window
*w
)
10931 struct buffer
*b
= XBUFFER (w
->buffer
);
10933 eassert (BUFFER_LIVE_P (b
));
10935 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10936 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10937 != !NILP (w
->region_showing
)));
10940 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10943 mode_line_update_needed (struct window
*w
)
10945 return (!NILP (w
->column_number_displayed
)
10946 && !(PT
== w
->last_point
&& !window_outdated (w
))
10947 && (XFASTINT (w
->column_number_displayed
) != current_column ()));
10950 /***********************************************************************
10951 Mode Lines and Frame Titles
10952 ***********************************************************************/
10954 /* A buffer for constructing non-propertized mode-line strings and
10955 frame titles in it; allocated from the heap in init_xdisp and
10956 resized as needed in store_mode_line_noprop_char. */
10958 static char *mode_line_noprop_buf
;
10960 /* The buffer's end, and a current output position in it. */
10962 static char *mode_line_noprop_buf_end
;
10963 static char *mode_line_noprop_ptr
;
10965 #define MODE_LINE_NOPROP_LEN(start) \
10966 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10969 MODE_LINE_DISPLAY
= 0,
10973 } mode_line_target
;
10975 /* Alist that caches the results of :propertize.
10976 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10977 static Lisp_Object mode_line_proptrans_alist
;
10979 /* List of strings making up the mode-line. */
10980 static Lisp_Object mode_line_string_list
;
10982 /* Base face property when building propertized mode line string. */
10983 static Lisp_Object mode_line_string_face
;
10984 static Lisp_Object mode_line_string_face_prop
;
10987 /* Unwind data for mode line strings */
10989 static Lisp_Object Vmode_line_unwind_vector
;
10992 format_mode_line_unwind_data (struct frame
*target_frame
,
10993 struct buffer
*obuf
,
10995 int save_proptrans
)
10997 Lisp_Object vector
, tmp
;
10999 /* Reduce consing by keeping one vector in
11000 Vwith_echo_area_save_vector. */
11001 vector
= Vmode_line_unwind_vector
;
11002 Vmode_line_unwind_vector
= Qnil
;
11005 vector
= Fmake_vector (make_number (10), Qnil
);
11007 ASET (vector
, 0, make_number (mode_line_target
));
11008 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11009 ASET (vector
, 2, mode_line_string_list
);
11010 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11011 ASET (vector
, 4, mode_line_string_face
);
11012 ASET (vector
, 5, mode_line_string_face_prop
);
11015 XSETBUFFER (tmp
, obuf
);
11018 ASET (vector
, 6, tmp
);
11019 ASET (vector
, 7, owin
);
11022 /* Similarly to `with-selected-window', if the operation selects
11023 a window on another frame, we must restore that frame's
11024 selected window, and (for a tty) the top-frame. */
11025 ASET (vector
, 8, target_frame
->selected_window
);
11026 if (FRAME_TERMCAP_P (target_frame
))
11027 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11034 unwind_format_mode_line (Lisp_Object vector
)
11036 Lisp_Object old_window
= AREF (vector
, 7);
11037 Lisp_Object target_frame_window
= AREF (vector
, 8);
11038 Lisp_Object old_top_frame
= AREF (vector
, 9);
11040 mode_line_target
= XINT (AREF (vector
, 0));
11041 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11042 mode_line_string_list
= AREF (vector
, 2);
11043 if (! EQ (AREF (vector
, 3), Qt
))
11044 mode_line_proptrans_alist
= AREF (vector
, 3);
11045 mode_line_string_face
= AREF (vector
, 4);
11046 mode_line_string_face_prop
= AREF (vector
, 5);
11048 /* Select window before buffer, since it may change the buffer. */
11049 if (!NILP (old_window
))
11051 /* If the operation that we are unwinding had selected a window
11052 on a different frame, reset its frame-selected-window. For a
11053 text terminal, reset its top-frame if necessary. */
11054 if (!NILP (target_frame_window
))
11057 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11059 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11060 Fselect_window (target_frame_window
, Qt
);
11062 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11063 Fselect_frame (old_top_frame
, Qt
);
11066 Fselect_window (old_window
, Qt
);
11069 if (!NILP (AREF (vector
, 6)))
11071 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11072 ASET (vector
, 6, Qnil
);
11075 Vmode_line_unwind_vector
= vector
;
11080 /* Store a single character C for the frame title in mode_line_noprop_buf.
11081 Re-allocate mode_line_noprop_buf if necessary. */
11084 store_mode_line_noprop_char (char c
)
11086 /* If output position has reached the end of the allocated buffer,
11087 increase the buffer's size. */
11088 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11090 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11091 ptrdiff_t size
= len
;
11092 mode_line_noprop_buf
=
11093 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11094 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11095 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11098 *mode_line_noprop_ptr
++ = c
;
11102 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11103 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11104 characters that yield more columns than PRECISION; PRECISION <= 0
11105 means copy the whole string. Pad with spaces until FIELD_WIDTH
11106 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11107 pad. Called from display_mode_element when it is used to build a
11111 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11113 const unsigned char *str
= (const unsigned char *) string
;
11115 ptrdiff_t dummy
, nbytes
;
11117 /* Copy at most PRECISION chars from STR. */
11118 nbytes
= strlen (string
);
11119 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11121 store_mode_line_noprop_char (*str
++);
11123 /* Fill up with spaces until FIELD_WIDTH reached. */
11124 while (field_width
> 0
11125 && n
< field_width
)
11127 store_mode_line_noprop_char (' ');
11134 /***********************************************************************
11136 ***********************************************************************/
11138 #ifdef HAVE_WINDOW_SYSTEM
11140 /* Set the title of FRAME, if it has changed. The title format is
11141 Vicon_title_format if FRAME is iconified, otherwise it is
11142 frame_title_format. */
11145 x_consider_frame_title (Lisp_Object frame
)
11147 struct frame
*f
= XFRAME (frame
);
11149 if (FRAME_WINDOW_P (f
)
11150 || FRAME_MINIBUF_ONLY_P (f
)
11151 || f
->explicit_name
)
11153 /* Do we have more than one visible frame on this X display? */
11154 Lisp_Object tail
, other_frame
, fmt
;
11155 ptrdiff_t title_start
;
11159 ptrdiff_t count
= SPECPDL_INDEX ();
11161 FOR_EACH_FRAME (tail
, other_frame
)
11163 struct frame
*tf
= XFRAME (other_frame
);
11166 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11167 && !FRAME_MINIBUF_ONLY_P (tf
)
11168 && !EQ (other_frame
, tip_frame
)
11169 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11173 /* Set global variable indicating that multiple frames exist. */
11174 multiple_frames
= CONSP (tail
);
11176 /* Switch to the buffer of selected window of the frame. Set up
11177 mode_line_target so that display_mode_element will output into
11178 mode_line_noprop_buf; then display the title. */
11179 record_unwind_protect (unwind_format_mode_line
,
11180 format_mode_line_unwind_data
11181 (f
, current_buffer
, selected_window
, 0));
11183 Fselect_window (f
->selected_window
, Qt
);
11184 set_buffer_internal_1
11185 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11186 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11188 mode_line_target
= MODE_LINE_TITLE
;
11189 title_start
= MODE_LINE_NOPROP_LEN (0);
11190 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11191 NULL
, DEFAULT_FACE_ID
);
11192 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11193 len
= MODE_LINE_NOPROP_LEN (title_start
);
11194 title
= mode_line_noprop_buf
+ title_start
;
11195 unbind_to (count
, Qnil
);
11197 /* Set the title only if it's changed. This avoids consing in
11198 the common case where it hasn't. (If it turns out that we've
11199 already wasted too much time by walking through the list with
11200 display_mode_element, then we might need to optimize at a
11201 higher level than this.) */
11202 if (! STRINGP (f
->name
)
11203 || SBYTES (f
->name
) != len
11204 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11205 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11209 #endif /* not HAVE_WINDOW_SYSTEM */
11212 /***********************************************************************
11214 ***********************************************************************/
11217 /* Prepare for redisplay by updating menu-bar item lists when
11218 appropriate. This can call eval. */
11221 prepare_menu_bars (void)
11224 struct gcpro gcpro1
, gcpro2
;
11226 Lisp_Object tooltip_frame
;
11228 #ifdef HAVE_WINDOW_SYSTEM
11229 tooltip_frame
= tip_frame
;
11231 tooltip_frame
= Qnil
;
11234 /* Update all frame titles based on their buffer names, etc. We do
11235 this before the menu bars so that the buffer-menu will show the
11236 up-to-date frame titles. */
11237 #ifdef HAVE_WINDOW_SYSTEM
11238 if (windows_or_buffers_changed
|| update_mode_lines
)
11240 Lisp_Object tail
, frame
;
11242 FOR_EACH_FRAME (tail
, frame
)
11244 f
= XFRAME (frame
);
11245 if (!EQ (frame
, tooltip_frame
)
11246 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11247 x_consider_frame_title (frame
);
11250 #endif /* HAVE_WINDOW_SYSTEM */
11252 /* Update the menu bar item lists, if appropriate. This has to be
11253 done before any actual redisplay or generation of display lines. */
11254 all_windows
= (update_mode_lines
11255 || buffer_shared_and_changed ()
11256 || windows_or_buffers_changed
);
11259 Lisp_Object tail
, frame
;
11260 ptrdiff_t count
= SPECPDL_INDEX ();
11261 /* 1 means that update_menu_bar has run its hooks
11262 so any further calls to update_menu_bar shouldn't do so again. */
11263 int menu_bar_hooks_run
= 0;
11265 record_unwind_save_match_data ();
11267 FOR_EACH_FRAME (tail
, frame
)
11269 f
= XFRAME (frame
);
11271 /* Ignore tooltip frame. */
11272 if (EQ (frame
, tooltip_frame
))
11275 /* If a window on this frame changed size, report that to
11276 the user and clear the size-change flag. */
11277 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11279 Lisp_Object functions
;
11281 /* Clear flag first in case we get an error below. */
11282 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11283 functions
= Vwindow_size_change_functions
;
11284 GCPRO2 (tail
, functions
);
11286 while (CONSP (functions
))
11288 if (!EQ (XCAR (functions
), Qt
))
11289 call1 (XCAR (functions
), frame
);
11290 functions
= XCDR (functions
);
11296 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11297 #ifdef HAVE_WINDOW_SYSTEM
11298 update_tool_bar (f
, 0);
11301 if (windows_or_buffers_changed
11304 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->buffer
));
11309 unbind_to (count
, Qnil
);
11313 struct frame
*sf
= SELECTED_FRAME ();
11314 update_menu_bar (sf
, 1, 0);
11315 #ifdef HAVE_WINDOW_SYSTEM
11316 update_tool_bar (sf
, 1);
11322 /* Update the menu bar item list for frame F. This has to be done
11323 before we start to fill in any display lines, because it can call
11326 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11328 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11329 already ran the menu bar hooks for this redisplay, so there
11330 is no need to run them again. The return value is the
11331 updated value of this flag, to pass to the next call. */
11334 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11336 Lisp_Object window
;
11337 register struct window
*w
;
11339 /* If called recursively during a menu update, do nothing. This can
11340 happen when, for instance, an activate-menubar-hook causes a
11342 if (inhibit_menubar_update
)
11345 window
= FRAME_SELECTED_WINDOW (f
);
11346 w
= XWINDOW (window
);
11348 if (FRAME_WINDOW_P (f
)
11350 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11351 || defined (HAVE_NS) || defined (USE_GTK)
11352 FRAME_EXTERNAL_MENU_BAR (f
)
11354 FRAME_MENU_BAR_LINES (f
) > 0
11356 : FRAME_MENU_BAR_LINES (f
) > 0)
11358 /* If the user has switched buffers or windows, we need to
11359 recompute to reflect the new bindings. But we'll
11360 recompute when update_mode_lines is set too; that means
11361 that people can use force-mode-line-update to request
11362 that the menu bar be recomputed. The adverse effect on
11363 the rest of the redisplay algorithm is about the same as
11364 windows_or_buffers_changed anyway. */
11365 if (windows_or_buffers_changed
11366 /* This used to test w->update_mode_line, but we believe
11367 there is no need to recompute the menu in that case. */
11368 || update_mode_lines
11369 || window_buffer_changed (w
))
11371 struct buffer
*prev
= current_buffer
;
11372 ptrdiff_t count
= SPECPDL_INDEX ();
11374 specbind (Qinhibit_menubar_update
, Qt
);
11376 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11377 if (save_match_data
)
11378 record_unwind_save_match_data ();
11379 if (NILP (Voverriding_local_map_menu_flag
))
11381 specbind (Qoverriding_terminal_local_map
, Qnil
);
11382 specbind (Qoverriding_local_map
, Qnil
);
11387 /* Run the Lucid hook. */
11388 safe_run_hooks (Qactivate_menubar_hook
);
11390 /* If it has changed current-menubar from previous value,
11391 really recompute the menu-bar from the value. */
11392 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11393 call0 (Qrecompute_lucid_menubar
);
11395 safe_run_hooks (Qmenu_bar_update_hook
);
11400 XSETFRAME (Vmenu_updating_frame
, f
);
11401 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11403 /* Redisplay the menu bar in case we changed it. */
11404 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11405 || defined (HAVE_NS) || defined (USE_GTK)
11406 if (FRAME_WINDOW_P (f
))
11408 #if defined (HAVE_NS)
11409 /* All frames on Mac OS share the same menubar. So only
11410 the selected frame should be allowed to set it. */
11411 if (f
== SELECTED_FRAME ())
11413 set_frame_menubar (f
, 0, 0);
11416 /* On a terminal screen, the menu bar is an ordinary screen
11417 line, and this makes it get updated. */
11418 w
->update_mode_line
= 1;
11419 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11420 /* In the non-toolkit version, the menu bar is an ordinary screen
11421 line, and this makes it get updated. */
11422 w
->update_mode_line
= 1;
11423 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11425 unbind_to (count
, Qnil
);
11426 set_buffer_internal_1 (prev
);
11435 /***********************************************************************
11437 ***********************************************************************/
11439 #ifdef HAVE_WINDOW_SYSTEM
11442 Nominal cursor position -- where to draw output.
11443 HPOS and VPOS are window relative glyph matrix coordinates.
11444 X and Y are window relative pixel coordinates. */
11446 struct cursor_pos output_cursor
;
11450 Set the global variable output_cursor to CURSOR. All cursor
11451 positions are relative to updated_window. */
11454 set_output_cursor (struct cursor_pos
*cursor
)
11456 output_cursor
.hpos
= cursor
->hpos
;
11457 output_cursor
.vpos
= cursor
->vpos
;
11458 output_cursor
.x
= cursor
->x
;
11459 output_cursor
.y
= cursor
->y
;
11464 Set a nominal cursor position.
11466 HPOS and VPOS are column/row positions in a window glyph matrix. X
11467 and Y are window text area relative pixel positions.
11469 If this is done during an update, updated_window will contain the
11470 window that is being updated and the position is the future output
11471 cursor position for that window. If updated_window is null, use
11472 selected_window and display the cursor at the given position. */
11475 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11479 /* If updated_window is not set, work on selected_window. */
11480 if (updated_window
)
11481 w
= updated_window
;
11483 w
= XWINDOW (selected_window
);
11485 /* Set the output cursor. */
11486 output_cursor
.hpos
= hpos
;
11487 output_cursor
.vpos
= vpos
;
11488 output_cursor
.x
= x
;
11489 output_cursor
.y
= y
;
11491 /* If not called as part of an update, really display the cursor.
11492 This will also set the cursor position of W. */
11493 if (updated_window
== NULL
)
11496 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11497 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11498 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11503 #endif /* HAVE_WINDOW_SYSTEM */
11506 /***********************************************************************
11508 ***********************************************************************/
11510 #ifdef HAVE_WINDOW_SYSTEM
11512 /* Where the mouse was last time we reported a mouse event. */
11514 FRAME_PTR last_mouse_frame
;
11516 /* Tool-bar item index of the item on which a mouse button was pressed
11519 int last_tool_bar_item
;
11521 /* Select `frame' temporarily without running all the code in
11523 FIXME: Maybe do_switch_frame should be trimmed down similarly
11524 when `norecord' is set. */
11526 fast_set_selected_frame (Lisp_Object frame
)
11528 if (!EQ (selected_frame
, frame
))
11530 selected_frame
= frame
;
11531 selected_window
= XFRAME (frame
)->selected_window
;
11536 /* Update the tool-bar item list for frame F. This has to be done
11537 before we start to fill in any display lines. Called from
11538 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11539 and restore it here. */
11542 update_tool_bar (struct frame
*f
, int save_match_data
)
11544 #if defined (USE_GTK) || defined (HAVE_NS)
11545 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11547 int do_update
= WINDOWP (f
->tool_bar_window
)
11548 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11553 Lisp_Object window
;
11556 window
= FRAME_SELECTED_WINDOW (f
);
11557 w
= XWINDOW (window
);
11559 /* If the user has switched buffers or windows, we need to
11560 recompute to reflect the new bindings. But we'll
11561 recompute when update_mode_lines is set too; that means
11562 that people can use force-mode-line-update to request
11563 that the menu bar be recomputed. The adverse effect on
11564 the rest of the redisplay algorithm is about the same as
11565 windows_or_buffers_changed anyway. */
11566 if (windows_or_buffers_changed
11567 || w
->update_mode_line
11568 || update_mode_lines
11569 || window_buffer_changed (w
))
11571 struct buffer
*prev
= current_buffer
;
11572 ptrdiff_t count
= SPECPDL_INDEX ();
11573 Lisp_Object frame
, new_tool_bar
;
11574 int new_n_tool_bar
;
11575 struct gcpro gcpro1
;
11577 /* Set current_buffer to the buffer of the selected
11578 window of the frame, so that we get the right local
11580 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11582 /* Save match data, if we must. */
11583 if (save_match_data
)
11584 record_unwind_save_match_data ();
11586 /* Make sure that we don't accidentally use bogus keymaps. */
11587 if (NILP (Voverriding_local_map_menu_flag
))
11589 specbind (Qoverriding_terminal_local_map
, Qnil
);
11590 specbind (Qoverriding_local_map
, Qnil
);
11593 GCPRO1 (new_tool_bar
);
11595 /* We must temporarily set the selected frame to this frame
11596 before calling tool_bar_items, because the calculation of
11597 the tool-bar keymap uses the selected frame (see
11598 `tool-bar-make-keymap' in tool-bar.el). */
11599 eassert (EQ (selected_window
,
11600 /* Since we only explicitly preserve selected_frame,
11601 check that selected_window would be redundant. */
11602 XFRAME (selected_frame
)->selected_window
));
11603 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11604 XSETFRAME (frame
, f
);
11605 fast_set_selected_frame (frame
);
11607 /* Build desired tool-bar items from keymaps. */
11609 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11612 /* Redisplay the tool-bar if we changed it. */
11613 if (new_n_tool_bar
!= f
->n_tool_bar_items
11614 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11616 /* Redisplay that happens asynchronously due to an expose event
11617 may access f->tool_bar_items. Make sure we update both
11618 variables within BLOCK_INPUT so no such event interrupts. */
11620 fset_tool_bar_items (f
, new_tool_bar
);
11621 f
->n_tool_bar_items
= new_n_tool_bar
;
11622 w
->update_mode_line
= 1;
11628 unbind_to (count
, Qnil
);
11629 set_buffer_internal_1 (prev
);
11635 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11636 F's desired tool-bar contents. F->tool_bar_items must have
11637 been set up previously by calling prepare_menu_bars. */
11640 build_desired_tool_bar_string (struct frame
*f
)
11642 int i
, size
, size_needed
;
11643 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11644 Lisp_Object image
, plist
, props
;
11646 image
= plist
= props
= Qnil
;
11647 GCPRO3 (image
, plist
, props
);
11649 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11650 Otherwise, make a new string. */
11652 /* The size of the string we might be able to reuse. */
11653 size
= (STRINGP (f
->desired_tool_bar_string
)
11654 ? SCHARS (f
->desired_tool_bar_string
)
11657 /* We need one space in the string for each image. */
11658 size_needed
= f
->n_tool_bar_items
;
11660 /* Reuse f->desired_tool_bar_string, if possible. */
11661 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11662 fset_desired_tool_bar_string
11663 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11666 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11667 Fremove_text_properties (make_number (0), make_number (size
),
11668 props
, f
->desired_tool_bar_string
);
11671 /* Put a `display' property on the string for the images to display,
11672 put a `menu_item' property on tool-bar items with a value that
11673 is the index of the item in F's tool-bar item vector. */
11674 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11676 #define PROP(IDX) \
11677 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11679 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11680 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11681 int hmargin
, vmargin
, relief
, idx
, end
;
11683 /* If image is a vector, choose the image according to the
11685 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11686 if (VECTORP (image
))
11690 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11691 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11694 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11695 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11697 eassert (ASIZE (image
) >= idx
);
11698 image
= AREF (image
, idx
);
11703 /* Ignore invalid image specifications. */
11704 if (!valid_image_p (image
))
11707 /* Display the tool-bar button pressed, or depressed. */
11708 plist
= Fcopy_sequence (XCDR (image
));
11710 /* Compute margin and relief to draw. */
11711 relief
= (tool_bar_button_relief
>= 0
11712 ? tool_bar_button_relief
11713 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11714 hmargin
= vmargin
= relief
;
11716 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11717 INT_MAX
- max (hmargin
, vmargin
)))
11719 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11720 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11722 else if (CONSP (Vtool_bar_button_margin
))
11724 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11725 INT_MAX
- hmargin
))
11726 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11728 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11729 INT_MAX
- vmargin
))
11730 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11733 if (auto_raise_tool_bar_buttons_p
)
11735 /* Add a `:relief' property to the image spec if the item is
11739 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11746 /* If image is selected, display it pressed, i.e. with a
11747 negative relief. If it's not selected, display it with a
11749 plist
= Fplist_put (plist
, QCrelief
,
11751 ? make_number (-relief
)
11752 : make_number (relief
)));
11757 /* Put a margin around the image. */
11758 if (hmargin
|| vmargin
)
11760 if (hmargin
== vmargin
)
11761 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11763 plist
= Fplist_put (plist
, QCmargin
,
11764 Fcons (make_number (hmargin
),
11765 make_number (vmargin
)));
11768 /* If button is not enabled, and we don't have special images
11769 for the disabled state, make the image appear disabled by
11770 applying an appropriate algorithm to it. */
11771 if (!enabled_p
&& idx
< 0)
11772 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11774 /* Put a `display' text property on the string for the image to
11775 display. Put a `menu-item' property on the string that gives
11776 the start of this item's properties in the tool-bar items
11778 image
= Fcons (Qimage
, plist
);
11779 props
= list4 (Qdisplay
, image
,
11780 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11782 /* Let the last image hide all remaining spaces in the tool bar
11783 string. The string can be longer than needed when we reuse a
11784 previous string. */
11785 if (i
+ 1 == f
->n_tool_bar_items
)
11786 end
= SCHARS (f
->desired_tool_bar_string
);
11789 Fadd_text_properties (make_number (i
), make_number (end
),
11790 props
, f
->desired_tool_bar_string
);
11798 /* Display one line of the tool-bar of frame IT->f.
11800 HEIGHT specifies the desired height of the tool-bar line.
11801 If the actual height of the glyph row is less than HEIGHT, the
11802 row's height is increased to HEIGHT, and the icons are centered
11803 vertically in the new height.
11805 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11806 count a final empty row in case the tool-bar width exactly matches
11811 display_tool_bar_line (struct it
*it
, int height
)
11813 struct glyph_row
*row
= it
->glyph_row
;
11814 int max_x
= it
->last_visible_x
;
11815 struct glyph
*last
;
11817 prepare_desired_row (row
);
11818 row
->y
= it
->current_y
;
11820 /* Note that this isn't made use of if the face hasn't a box,
11821 so there's no need to check the face here. */
11822 it
->start_of_box_run_p
= 1;
11824 while (it
->current_x
< max_x
)
11826 int x
, n_glyphs_before
, i
, nglyphs
;
11827 struct it it_before
;
11829 /* Get the next display element. */
11830 if (!get_next_display_element (it
))
11832 /* Don't count empty row if we are counting needed tool-bar lines. */
11833 if (height
< 0 && !it
->hpos
)
11838 /* Produce glyphs. */
11839 n_glyphs_before
= row
->used
[TEXT_AREA
];
11842 PRODUCE_GLYPHS (it
);
11844 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11846 x
= it_before
.current_x
;
11847 while (i
< nglyphs
)
11849 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11851 if (x
+ glyph
->pixel_width
> max_x
)
11853 /* Glyph doesn't fit on line. Backtrack. */
11854 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11856 /* If this is the only glyph on this line, it will never fit on the
11857 tool-bar, so skip it. But ensure there is at least one glyph,
11858 so we don't accidentally disable the tool-bar. */
11859 if (n_glyphs_before
== 0
11860 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11866 x
+= glyph
->pixel_width
;
11870 /* Stop at line end. */
11871 if (ITERATOR_AT_END_OF_LINE_P (it
))
11874 set_iterator_to_next (it
, 1);
11879 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11881 /* Use default face for the border below the tool bar.
11883 FIXME: When auto-resize-tool-bars is grow-only, there is
11884 no additional border below the possibly empty tool-bar lines.
11885 So to make the extra empty lines look "normal", we have to
11886 use the tool-bar face for the border too. */
11887 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11888 it
->face_id
= DEFAULT_FACE_ID
;
11890 extend_face_to_end_of_line (it
);
11891 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11892 last
->right_box_line_p
= 1;
11893 if (last
== row
->glyphs
[TEXT_AREA
])
11894 last
->left_box_line_p
= 1;
11896 /* Make line the desired height and center it vertically. */
11897 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11899 /* Don't add more than one line height. */
11900 height
%= FRAME_LINE_HEIGHT (it
->f
);
11901 it
->max_ascent
+= height
/ 2;
11902 it
->max_descent
+= (height
+ 1) / 2;
11905 compute_line_metrics (it
);
11907 /* If line is empty, make it occupy the rest of the tool-bar. */
11908 if (!row
->displays_text_p
)
11910 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11911 row
->visible_height
= row
->height
;
11912 row
->ascent
= row
->phys_ascent
= 0;
11913 row
->extra_line_spacing
= 0;
11916 row
->full_width_p
= 1;
11917 row
->continued_p
= 0;
11918 row
->truncated_on_left_p
= 0;
11919 row
->truncated_on_right_p
= 0;
11921 it
->current_x
= it
->hpos
= 0;
11922 it
->current_y
+= row
->height
;
11928 /* Max tool-bar height. */
11930 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11931 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11933 /* Value is the number of screen lines needed to make all tool-bar
11934 items of frame F visible. The number of actual rows needed is
11935 returned in *N_ROWS if non-NULL. */
11938 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11940 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11942 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11943 the desired matrix, so use (unused) mode-line row as temporary row to
11944 avoid destroying the first tool-bar row. */
11945 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11947 /* Initialize an iterator for iteration over
11948 F->desired_tool_bar_string in the tool-bar window of frame F. */
11949 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11950 it
.first_visible_x
= 0;
11951 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11952 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11953 it
.paragraph_embedding
= L2R
;
11955 while (!ITERATOR_AT_END_P (&it
))
11957 clear_glyph_row (temp_row
);
11958 it
.glyph_row
= temp_row
;
11959 display_tool_bar_line (&it
, -1);
11961 clear_glyph_row (temp_row
);
11963 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11965 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11967 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11971 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11973 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11974 If FRAME is nil or omitted, use the selected frame. */)
11975 (Lisp_Object frame
)
11977 struct frame
*f
= decode_any_frame (frame
);
11981 if (WINDOWP (f
->tool_bar_window
)
11982 && (w
= XWINDOW (f
->tool_bar_window
),
11983 WINDOW_TOTAL_LINES (w
) > 0))
11985 update_tool_bar (f
, 1);
11986 if (f
->n_tool_bar_items
)
11988 build_desired_tool_bar_string (f
);
11989 nlines
= tool_bar_lines_needed (f
, NULL
);
11993 return make_number (nlines
);
11997 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11998 height should be changed. */
12001 redisplay_tool_bar (struct frame
*f
)
12005 struct glyph_row
*row
;
12007 #if defined (USE_GTK) || defined (HAVE_NS)
12008 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12009 update_frame_tool_bar (f
);
12013 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12014 do anything. This means you must start with tool-bar-lines
12015 non-zero to get the auto-sizing effect. Or in other words, you
12016 can turn off tool-bars by specifying tool-bar-lines zero. */
12017 if (!WINDOWP (f
->tool_bar_window
)
12018 || (w
= XWINDOW (f
->tool_bar_window
),
12019 WINDOW_TOTAL_LINES (w
) == 0))
12022 /* Set up an iterator for the tool-bar window. */
12023 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12024 it
.first_visible_x
= 0;
12025 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12026 row
= it
.glyph_row
;
12028 /* Build a string that represents the contents of the tool-bar. */
12029 build_desired_tool_bar_string (f
);
12030 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12031 /* FIXME: This should be controlled by a user option. But it
12032 doesn't make sense to have an R2L tool bar if the menu bar cannot
12033 be drawn also R2L, and making the menu bar R2L is tricky due
12034 toolkit-specific code that implements it. If an R2L tool bar is
12035 ever supported, display_tool_bar_line should also be augmented to
12036 call unproduce_glyphs like display_line and display_string
12038 it
.paragraph_embedding
= L2R
;
12040 if (f
->n_tool_bar_rows
== 0)
12044 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
12045 nlines
!= WINDOW_TOTAL_LINES (w
)))
12048 int old_height
= WINDOW_TOTAL_LINES (w
);
12050 XSETFRAME (frame
, f
);
12051 Fmodify_frame_parameters (frame
,
12052 Fcons (Fcons (Qtool_bar_lines
,
12053 make_number (nlines
)),
12055 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12057 clear_glyph_matrix (w
->desired_matrix
);
12058 fonts_changed_p
= 1;
12064 /* Display as many lines as needed to display all tool-bar items. */
12066 if (f
->n_tool_bar_rows
> 0)
12068 int border
, rows
, height
, extra
;
12070 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12071 border
= XINT (Vtool_bar_border
);
12072 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12073 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12074 else if (EQ (Vtool_bar_border
, Qborder_width
))
12075 border
= f
->border_width
;
12081 rows
= f
->n_tool_bar_rows
;
12082 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12083 extra
= it
.last_visible_y
- border
- height
* rows
;
12085 while (it
.current_y
< it
.last_visible_y
)
12088 if (extra
> 0 && rows
-- > 0)
12090 h
= (extra
+ rows
- 1) / rows
;
12093 display_tool_bar_line (&it
, height
+ h
);
12098 while (it
.current_y
< it
.last_visible_y
)
12099 display_tool_bar_line (&it
, 0);
12102 /* It doesn't make much sense to try scrolling in the tool-bar
12103 window, so don't do it. */
12104 w
->desired_matrix
->no_scrolling_p
= 1;
12105 w
->must_be_updated_p
= 1;
12107 if (!NILP (Vauto_resize_tool_bars
))
12109 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12110 int change_height_p
= 0;
12112 /* If we couldn't display everything, change the tool-bar's
12113 height if there is room for more. */
12114 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12115 && it
.current_y
< max_tool_bar_height
)
12116 change_height_p
= 1;
12118 row
= it
.glyph_row
- 1;
12120 /* If there are blank lines at the end, except for a partially
12121 visible blank line at the end that is smaller than
12122 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12123 if (!row
->displays_text_p
12124 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12125 change_height_p
= 1;
12127 /* If row displays tool-bar items, but is partially visible,
12128 change the tool-bar's height. */
12129 if (row
->displays_text_p
12130 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12131 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12132 change_height_p
= 1;
12134 /* Resize windows as needed by changing the `tool-bar-lines'
12135 frame parameter. */
12136 if (change_height_p
)
12139 int old_height
= WINDOW_TOTAL_LINES (w
);
12141 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12143 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12144 && !f
->minimize_tool_bar_window_p
)
12145 ? (nlines
> old_height
)
12146 : (nlines
!= old_height
));
12147 f
->minimize_tool_bar_window_p
= 0;
12149 if (change_height_p
)
12151 XSETFRAME (frame
, f
);
12152 Fmodify_frame_parameters (frame
,
12153 Fcons (Fcons (Qtool_bar_lines
,
12154 make_number (nlines
)),
12156 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12158 clear_glyph_matrix (w
->desired_matrix
);
12159 f
->n_tool_bar_rows
= nrows
;
12160 fonts_changed_p
= 1;
12167 f
->minimize_tool_bar_window_p
= 0;
12172 /* Get information about the tool-bar item which is displayed in GLYPH
12173 on frame F. Return in *PROP_IDX the index where tool-bar item
12174 properties start in F->tool_bar_items. Value is zero if
12175 GLYPH doesn't display a tool-bar item. */
12178 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12184 /* This function can be called asynchronously, which means we must
12185 exclude any possibility that Fget_text_property signals an
12187 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12188 charpos
= max (0, charpos
);
12190 /* Get the text property `menu-item' at pos. The value of that
12191 property is the start index of this item's properties in
12192 F->tool_bar_items. */
12193 prop
= Fget_text_property (make_number (charpos
),
12194 Qmenu_item
, f
->current_tool_bar_string
);
12195 if (INTEGERP (prop
))
12197 *prop_idx
= XINT (prop
);
12207 /* Get information about the tool-bar item at position X/Y on frame F.
12208 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12209 the current matrix of the tool-bar window of F, or NULL if not
12210 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12211 item in F->tool_bar_items. Value is
12213 -1 if X/Y is not on a tool-bar item
12214 0 if X/Y is on the same item that was highlighted before.
12218 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12219 int *hpos
, int *vpos
, int *prop_idx
)
12221 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12222 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12225 /* Find the glyph under X/Y. */
12226 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12227 if (*glyph
== NULL
)
12230 /* Get the start of this tool-bar item's properties in
12231 f->tool_bar_items. */
12232 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12235 /* Is mouse on the highlighted item? */
12236 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12237 && *vpos
>= hlinfo
->mouse_face_beg_row
12238 && *vpos
<= hlinfo
->mouse_face_end_row
12239 && (*vpos
> hlinfo
->mouse_face_beg_row
12240 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12241 && (*vpos
< hlinfo
->mouse_face_end_row
12242 || *hpos
< hlinfo
->mouse_face_end_col
12243 || hlinfo
->mouse_face_past_end
))
12251 Handle mouse button event on the tool-bar of frame F, at
12252 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12253 0 for button release. MODIFIERS is event modifiers for button
12257 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12260 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12261 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12262 int hpos
, vpos
, prop_idx
;
12263 struct glyph
*glyph
;
12264 Lisp_Object enabled_p
;
12266 /* If not on the highlighted tool-bar item, return. */
12267 frame_to_window_pixel_xy (w
, &x
, &y
);
12268 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12271 /* If item is disabled, do nothing. */
12272 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12273 if (NILP (enabled_p
))
12278 /* Show item in pressed state. */
12279 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12280 last_tool_bar_item
= prop_idx
;
12284 Lisp_Object key
, frame
;
12285 struct input_event event
;
12286 EVENT_INIT (event
);
12288 /* Show item in released state. */
12289 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12291 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12293 XSETFRAME (frame
, f
);
12294 event
.kind
= TOOL_BAR_EVENT
;
12295 event
.frame_or_window
= frame
;
12297 kbd_buffer_store_event (&event
);
12299 event
.kind
= TOOL_BAR_EVENT
;
12300 event
.frame_or_window
= frame
;
12302 event
.modifiers
= modifiers
;
12303 kbd_buffer_store_event (&event
);
12304 last_tool_bar_item
= -1;
12309 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12310 tool-bar window-relative coordinates X/Y. Called from
12311 note_mouse_highlight. */
12314 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12316 Lisp_Object window
= f
->tool_bar_window
;
12317 struct window
*w
= XWINDOW (window
);
12318 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12319 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12321 struct glyph
*glyph
;
12322 struct glyph_row
*row
;
12324 Lisp_Object enabled_p
;
12326 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12327 int mouse_down_p
, rc
;
12329 /* Function note_mouse_highlight is called with negative X/Y
12330 values when mouse moves outside of the frame. */
12331 if (x
<= 0 || y
<= 0)
12333 clear_mouse_face (hlinfo
);
12337 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12340 /* Not on tool-bar item. */
12341 clear_mouse_face (hlinfo
);
12345 /* On same tool-bar item as before. */
12346 goto set_help_echo
;
12348 clear_mouse_face (hlinfo
);
12350 /* Mouse is down, but on different tool-bar item? */
12351 mouse_down_p
= (dpyinfo
->grabbed
12352 && f
== last_mouse_frame
12353 && FRAME_LIVE_P (f
));
12355 && last_tool_bar_item
!= prop_idx
)
12358 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12360 /* If tool-bar item is not enabled, don't highlight it. */
12361 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12362 if (!NILP (enabled_p
))
12364 /* Compute the x-position of the glyph. In front and past the
12365 image is a space. We include this in the highlighted area. */
12366 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12367 for (i
= x
= 0; i
< hpos
; ++i
)
12368 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12370 /* Record this as the current active region. */
12371 hlinfo
->mouse_face_beg_col
= hpos
;
12372 hlinfo
->mouse_face_beg_row
= vpos
;
12373 hlinfo
->mouse_face_beg_x
= x
;
12374 hlinfo
->mouse_face_beg_y
= row
->y
;
12375 hlinfo
->mouse_face_past_end
= 0;
12377 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12378 hlinfo
->mouse_face_end_row
= vpos
;
12379 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12380 hlinfo
->mouse_face_end_y
= row
->y
;
12381 hlinfo
->mouse_face_window
= window
;
12382 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12384 /* Display it as active. */
12385 show_mouse_face (hlinfo
, draw
);
12390 /* Set help_echo_string to a help string to display for this tool-bar item.
12391 XTread_socket does the rest. */
12392 help_echo_object
= help_echo_window
= Qnil
;
12393 help_echo_pos
= -1;
12394 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12395 if (NILP (help_echo_string
))
12396 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12399 #endif /* HAVE_WINDOW_SYSTEM */
12403 /************************************************************************
12404 Horizontal scrolling
12405 ************************************************************************/
12407 static int hscroll_window_tree (Lisp_Object
);
12408 static int hscroll_windows (Lisp_Object
);
12410 /* For all leaf windows in the window tree rooted at WINDOW, set their
12411 hscroll value so that PT is (i) visible in the window, and (ii) so
12412 that it is not within a certain margin at the window's left and
12413 right border. Value is non-zero if any window's hscroll has been
12417 hscroll_window_tree (Lisp_Object window
)
12419 int hscrolled_p
= 0;
12420 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12421 int hscroll_step_abs
= 0;
12422 double hscroll_step_rel
= 0;
12424 if (hscroll_relative_p
)
12426 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12427 if (hscroll_step_rel
< 0)
12429 hscroll_relative_p
= 0;
12430 hscroll_step_abs
= 0;
12433 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12435 hscroll_step_abs
= XINT (Vhscroll_step
);
12436 if (hscroll_step_abs
< 0)
12437 hscroll_step_abs
= 0;
12440 hscroll_step_abs
= 0;
12442 while (WINDOWP (window
))
12444 struct window
*w
= XWINDOW (window
);
12446 if (WINDOWP (w
->hchild
))
12447 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12448 else if (WINDOWP (w
->vchild
))
12449 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12450 else if (w
->cursor
.vpos
>= 0)
12453 int text_area_width
;
12454 struct glyph_row
*current_cursor_row
12455 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12456 struct glyph_row
*desired_cursor_row
12457 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12458 struct glyph_row
*cursor_row
12459 = (desired_cursor_row
->enabled_p
12460 ? desired_cursor_row
12461 : current_cursor_row
);
12462 int row_r2l_p
= cursor_row
->reversed_p
;
12464 text_area_width
= window_box_width (w
, TEXT_AREA
);
12466 /* Scroll when cursor is inside this scroll margin. */
12467 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12469 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12470 /* For left-to-right rows, hscroll when cursor is either
12471 (i) inside the right hscroll margin, or (ii) if it is
12472 inside the left margin and the window is already
12476 && w
->cursor
.x
<= h_margin
)
12477 || (cursor_row
->enabled_p
12478 && cursor_row
->truncated_on_right_p
12479 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12480 /* For right-to-left rows, the logic is similar,
12481 except that rules for scrolling to left and right
12482 are reversed. E.g., if cursor.x <= h_margin, we
12483 need to hscroll "to the right" unconditionally,
12484 and that will scroll the screen to the left so as
12485 to reveal the next portion of the row. */
12487 && ((cursor_row
->enabled_p
12488 /* FIXME: It is confusing to set the
12489 truncated_on_right_p flag when R2L rows
12490 are actually truncated on the left. */
12491 && cursor_row
->truncated_on_right_p
12492 && w
->cursor
.x
<= h_margin
)
12494 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12498 struct buffer
*saved_current_buffer
;
12502 /* Find point in a display of infinite width. */
12503 saved_current_buffer
= current_buffer
;
12504 current_buffer
= XBUFFER (w
->buffer
);
12506 if (w
== XWINDOW (selected_window
))
12509 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12511 /* Move iterator to pt starting at cursor_row->start in
12512 a line with infinite width. */
12513 init_to_row_start (&it
, w
, cursor_row
);
12514 it
.last_visible_x
= INFINITY
;
12515 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12516 current_buffer
= saved_current_buffer
;
12518 /* Position cursor in window. */
12519 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12520 hscroll
= max (0, (it
.current_x
12521 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12522 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12523 : (text_area_width
/ 2))))
12524 / FRAME_COLUMN_WIDTH (it
.f
);
12525 else if ((!row_r2l_p
12526 && w
->cursor
.x
>= text_area_width
- h_margin
)
12527 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12529 if (hscroll_relative_p
)
12530 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12533 wanted_x
= text_area_width
12534 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12537 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12541 if (hscroll_relative_p
)
12542 wanted_x
= text_area_width
* hscroll_step_rel
12545 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12548 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12550 hscroll
= max (hscroll
, w
->min_hscroll
);
12552 /* Don't prevent redisplay optimizations if hscroll
12553 hasn't changed, as it will unnecessarily slow down
12555 if (w
->hscroll
!= hscroll
)
12557 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12558 w
->hscroll
= hscroll
;
12567 /* Value is non-zero if hscroll of any leaf window has been changed. */
12568 return hscrolled_p
;
12572 /* Set hscroll so that cursor is visible and not inside horizontal
12573 scroll margins for all windows in the tree rooted at WINDOW. See
12574 also hscroll_window_tree above. Value is non-zero if any window's
12575 hscroll has been changed. If it has, desired matrices on the frame
12576 of WINDOW are cleared. */
12579 hscroll_windows (Lisp_Object window
)
12581 int hscrolled_p
= hscroll_window_tree (window
);
12583 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12584 return hscrolled_p
;
12589 /************************************************************************
12591 ************************************************************************/
12593 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12594 to a non-zero value. This is sometimes handy to have in a debugger
12599 /* First and last unchanged row for try_window_id. */
12601 static int debug_first_unchanged_at_end_vpos
;
12602 static int debug_last_unchanged_at_beg_vpos
;
12604 /* Delta vpos and y. */
12606 static int debug_dvpos
, debug_dy
;
12608 /* Delta in characters and bytes for try_window_id. */
12610 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12612 /* Values of window_end_pos and window_end_vpos at the end of
12615 static ptrdiff_t debug_end_vpos
;
12617 /* Append a string to W->desired_matrix->method. FMT is a printf
12618 format string. If trace_redisplay_p is non-zero also printf the
12619 resulting string to stderr. */
12621 static void debug_method_add (struct window
*, char const *, ...)
12622 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12625 debug_method_add (struct window
*w
, char const *fmt
, ...)
12627 char *method
= w
->desired_matrix
->method
;
12628 int len
= strlen (method
);
12629 int size
= sizeof w
->desired_matrix
->method
;
12630 int remaining
= size
- len
- 1;
12633 if (len
&& remaining
)
12636 --remaining
, ++len
;
12639 va_start (ap
, fmt
);
12640 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12643 if (trace_redisplay_p
)
12644 fprintf (stderr
, "%p (%s): %s\n",
12646 ((BUFFERP (w
->buffer
)
12647 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12648 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12653 #endif /* GLYPH_DEBUG */
12656 /* Value is non-zero if all changes in window W, which displays
12657 current_buffer, are in the text between START and END. START is a
12658 buffer position, END is given as a distance from Z. Used in
12659 redisplay_internal for display optimization. */
12662 text_outside_line_unchanged_p (struct window
*w
,
12663 ptrdiff_t start
, ptrdiff_t end
)
12665 int unchanged_p
= 1;
12667 /* If text or overlays have changed, see where. */
12668 if (window_outdated (w
))
12670 /* Gap in the line? */
12671 if (GPT
< start
|| Z
- GPT
< end
)
12674 /* Changes start in front of the line, or end after it? */
12676 && (BEG_UNCHANGED
< start
- 1
12677 || END_UNCHANGED
< end
))
12680 /* If selective display, can't optimize if changes start at the
12681 beginning of the line. */
12683 && INTEGERP (BVAR (current_buffer
, selective_display
))
12684 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12685 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12688 /* If there are overlays at the start or end of the line, these
12689 may have overlay strings with newlines in them. A change at
12690 START, for instance, may actually concern the display of such
12691 overlay strings as well, and they are displayed on different
12692 lines. So, quickly rule out this case. (For the future, it
12693 might be desirable to implement something more telling than
12694 just BEG/END_UNCHANGED.) */
12697 if (BEG
+ BEG_UNCHANGED
== start
12698 && overlay_touches_p (start
))
12700 if (END_UNCHANGED
== end
12701 && overlay_touches_p (Z
- end
))
12705 /* Under bidi reordering, adding or deleting a character in the
12706 beginning of a paragraph, before the first strong directional
12707 character, can change the base direction of the paragraph (unless
12708 the buffer specifies a fixed paragraph direction), which will
12709 require to redisplay the whole paragraph. It might be worthwhile
12710 to find the paragraph limits and widen the range of redisplayed
12711 lines to that, but for now just give up this optimization. */
12712 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12713 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12717 return unchanged_p
;
12721 /* Do a frame update, taking possible shortcuts into account. This is
12722 the main external entry point for redisplay.
12724 If the last redisplay displayed an echo area message and that message
12725 is no longer requested, we clear the echo area or bring back the
12726 mini-buffer if that is in use. */
12731 redisplay_internal ();
12736 overlay_arrow_string_or_property (Lisp_Object var
)
12740 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12743 return Voverlay_arrow_string
;
12746 /* Return 1 if there are any overlay-arrows in current_buffer. */
12748 overlay_arrow_in_current_buffer_p (void)
12752 for (vlist
= Voverlay_arrow_variable_list
;
12754 vlist
= XCDR (vlist
))
12756 Lisp_Object var
= XCAR (vlist
);
12759 if (!SYMBOLP (var
))
12761 val
= find_symbol_value (var
);
12763 && current_buffer
== XMARKER (val
)->buffer
)
12770 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12774 overlay_arrows_changed_p (void)
12778 for (vlist
= Voverlay_arrow_variable_list
;
12780 vlist
= XCDR (vlist
))
12782 Lisp_Object var
= XCAR (vlist
);
12783 Lisp_Object val
, pstr
;
12785 if (!SYMBOLP (var
))
12787 val
= find_symbol_value (var
);
12788 if (!MARKERP (val
))
12790 if (! EQ (COERCE_MARKER (val
),
12791 Fget (var
, Qlast_arrow_position
))
12792 || ! (pstr
= overlay_arrow_string_or_property (var
),
12793 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12799 /* Mark overlay arrows to be updated on next redisplay. */
12802 update_overlay_arrows (int up_to_date
)
12806 for (vlist
= Voverlay_arrow_variable_list
;
12808 vlist
= XCDR (vlist
))
12810 Lisp_Object var
= XCAR (vlist
);
12812 if (!SYMBOLP (var
))
12815 if (up_to_date
> 0)
12817 Lisp_Object val
= find_symbol_value (var
);
12818 Fput (var
, Qlast_arrow_position
,
12819 COERCE_MARKER (val
));
12820 Fput (var
, Qlast_arrow_string
,
12821 overlay_arrow_string_or_property (var
));
12823 else if (up_to_date
< 0
12824 || !NILP (Fget (var
, Qlast_arrow_position
)))
12826 Fput (var
, Qlast_arrow_position
, Qt
);
12827 Fput (var
, Qlast_arrow_string
, Qt
);
12833 /* Return overlay arrow string to display at row.
12834 Return integer (bitmap number) for arrow bitmap in left fringe.
12835 Return nil if no overlay arrow. */
12838 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12842 for (vlist
= Voverlay_arrow_variable_list
;
12844 vlist
= XCDR (vlist
))
12846 Lisp_Object var
= XCAR (vlist
);
12849 if (!SYMBOLP (var
))
12852 val
= find_symbol_value (var
);
12855 && current_buffer
== XMARKER (val
)->buffer
12856 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12858 if (FRAME_WINDOW_P (it
->f
)
12859 /* FIXME: if ROW->reversed_p is set, this should test
12860 the right fringe, not the left one. */
12861 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12863 #ifdef HAVE_WINDOW_SYSTEM
12864 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12867 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12868 return make_number (fringe_bitmap
);
12871 return make_number (-1); /* Use default arrow bitmap. */
12873 return overlay_arrow_string_or_property (var
);
12880 /* Return 1 if point moved out of or into a composition. Otherwise
12881 return 0. PREV_BUF and PREV_PT are the last point buffer and
12882 position. BUF and PT are the current point buffer and position. */
12885 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12886 struct buffer
*buf
, ptrdiff_t pt
)
12888 ptrdiff_t start
, end
;
12890 Lisp_Object buffer
;
12892 XSETBUFFER (buffer
, buf
);
12893 /* Check a composition at the last point if point moved within the
12895 if (prev_buf
== buf
)
12898 /* Point didn't move. */
12901 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12902 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12903 && COMPOSITION_VALID_P (start
, end
, prop
)
12904 && start
< prev_pt
&& end
> prev_pt
)
12905 /* The last point was within the composition. Return 1 iff
12906 point moved out of the composition. */
12907 return (pt
<= start
|| pt
>= end
);
12910 /* Check a composition at the current point. */
12911 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12912 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12913 && COMPOSITION_VALID_P (start
, end
, prop
)
12914 && start
< pt
&& end
> pt
);
12918 /* Reconsider the setting of B->clip_changed which is displayed
12922 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12924 if (b
->clip_changed
12925 && !NILP (w
->window_end_valid
)
12926 && w
->current_matrix
->buffer
== b
12927 && w
->current_matrix
->zv
== BUF_ZV (b
)
12928 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12929 b
->clip_changed
= 0;
12931 /* If display wasn't paused, and W is not a tool bar window, see if
12932 point has been moved into or out of a composition. In that case,
12933 we set b->clip_changed to 1 to force updating the screen. If
12934 b->clip_changed has already been set to 1, we can skip this
12936 if (!b
->clip_changed
12937 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12941 if (w
== XWINDOW (selected_window
))
12944 pt
= marker_position (w
->pointm
);
12946 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12947 || pt
!= w
->last_point
)
12948 && check_point_in_composition (w
->current_matrix
->buffer
,
12950 XBUFFER (w
->buffer
), pt
))
12951 b
->clip_changed
= 1;
12956 #define STOP_POLLING \
12957 do { if (! polling_stopped_here) stop_polling (); \
12958 polling_stopped_here = 1; } while (0)
12960 #define RESUME_POLLING \
12961 do { if (polling_stopped_here) start_polling (); \
12962 polling_stopped_here = 0; } while (0)
12965 /* Perhaps in the future avoid recentering windows if it
12966 is not necessary; currently that causes some problems. */
12969 redisplay_internal (void)
12971 struct window
*w
= XWINDOW (selected_window
);
12975 int must_finish
= 0;
12976 struct text_pos tlbufpos
, tlendpos
;
12977 int number_of_visible_frames
;
12978 ptrdiff_t count
, count1
;
12980 int polling_stopped_here
= 0;
12981 Lisp_Object tail
, frame
;
12982 struct backtrace backtrace
;
12984 /* Non-zero means redisplay has to consider all windows on all
12985 frames. Zero means, only selected_window is considered. */
12986 int consider_all_windows_p
;
12988 /* Non-zero means redisplay has to redisplay the miniwindow. */
12989 int update_miniwindow_p
= 0;
12991 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12993 /* No redisplay if running in batch mode or frame is not yet fully
12994 initialized, or redisplay is explicitly turned off by setting
12995 Vinhibit_redisplay. */
12996 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12997 || !NILP (Vinhibit_redisplay
))
13000 /* Don't examine these until after testing Vinhibit_redisplay.
13001 When Emacs is shutting down, perhaps because its connection to
13002 X has dropped, we should not look at them at all. */
13003 fr
= XFRAME (w
->frame
);
13004 sf
= SELECTED_FRAME ();
13006 if (!fr
->glyphs_initialized_p
)
13009 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13010 if (popup_activated ())
13014 /* I don't think this happens but let's be paranoid. */
13015 if (redisplaying_p
)
13018 /* Record a function that clears redisplaying_p
13019 when we leave this function. */
13020 count
= SPECPDL_INDEX ();
13021 record_unwind_protect (unwind_redisplay
, selected_frame
);
13022 redisplaying_p
= 1;
13023 specbind (Qinhibit_free_realized_faces
, Qnil
);
13025 /* Record this function, so it appears on the profiler's backtraces. */
13026 backtrace
.next
= backtrace_list
;
13027 backtrace
.function
= Qredisplay_internal
;
13028 backtrace
.args
= &Qnil
;
13029 backtrace
.nargs
= 0;
13030 backtrace
.debug_on_exit
= 0;
13031 backtrace_list
= &backtrace
;
13033 FOR_EACH_FRAME (tail
, frame
)
13034 XFRAME (frame
)->already_hscrolled_p
= 0;
13037 /* Remember the currently selected window. */
13041 reconsider_clip_changes (w
, current_buffer
);
13042 last_escape_glyph_frame
= NULL
;
13043 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13044 last_glyphless_glyph_frame
= NULL
;
13045 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13047 /* If new fonts have been loaded that make a glyph matrix adjustment
13048 necessary, do it. */
13049 if (fonts_changed_p
)
13051 adjust_glyphs (NULL
);
13052 ++windows_or_buffers_changed
;
13053 fonts_changed_p
= 0;
13056 /* If face_change_count is non-zero, init_iterator will free all
13057 realized faces, which includes the faces referenced from current
13058 matrices. So, we can't reuse current matrices in this case. */
13059 if (face_change_count
)
13060 ++windows_or_buffers_changed
;
13062 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13063 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13065 /* Since frames on a single ASCII terminal share the same
13066 display area, displaying a different frame means redisplay
13067 the whole thing. */
13068 windows_or_buffers_changed
++;
13069 SET_FRAME_GARBAGED (sf
);
13071 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13073 FRAME_TTY (sf
)->previous_frame
= sf
;
13076 /* Set the visible flags for all frames. Do this before checking for
13077 resized or garbaged frames; they want to know if their frames are
13078 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13079 number_of_visible_frames
= 0;
13081 FOR_EACH_FRAME (tail
, frame
)
13083 struct frame
*f
= XFRAME (frame
);
13085 FRAME_SAMPLE_VISIBILITY (f
);
13086 if (FRAME_VISIBLE_P (f
))
13087 ++number_of_visible_frames
;
13088 clear_desired_matrices (f
);
13091 /* Notice any pending interrupt request to change frame size. */
13092 do_pending_window_change (1);
13094 /* do_pending_window_change could change the selected_window due to
13095 frame resizing which makes the selected window too small. */
13096 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13099 reconsider_clip_changes (w
, current_buffer
);
13102 /* Clear frames marked as garbaged. */
13103 clear_garbaged_frames ();
13105 /* Build menubar and tool-bar items. */
13106 if (NILP (Vmemory_full
))
13107 prepare_menu_bars ();
13109 if (windows_or_buffers_changed
)
13110 update_mode_lines
++;
13112 /* Detect case that we need to write or remove a star in the mode line. */
13113 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13115 w
->update_mode_line
= 1;
13116 if (buffer_shared_and_changed ())
13117 update_mode_lines
++;
13120 /* Avoid invocation of point motion hooks by `current_column' below. */
13121 count1
= SPECPDL_INDEX ();
13122 specbind (Qinhibit_point_motion_hooks
, Qt
);
13124 if (mode_line_update_needed (w
))
13125 w
->update_mode_line
= 1;
13127 unbind_to (count1
, Qnil
);
13129 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
13131 consider_all_windows_p
= (update_mode_lines
13132 || buffer_shared_and_changed ()
13133 || cursor_type_changed
);
13135 /* If specs for an arrow have changed, do thorough redisplay
13136 to ensure we remove any arrow that should no longer exist. */
13137 if (overlay_arrows_changed_p ())
13138 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13140 /* Normally the message* functions will have already displayed and
13141 updated the echo area, but the frame may have been trashed, or
13142 the update may have been preempted, so display the echo area
13143 again here. Checking message_cleared_p captures the case that
13144 the echo area should be cleared. */
13145 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13146 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13147 || (message_cleared_p
13148 && minibuf_level
== 0
13149 /* If the mini-window is currently selected, this means the
13150 echo-area doesn't show through. */
13151 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13153 int window_height_changed_p
= echo_area_display (0);
13155 if (message_cleared_p
)
13156 update_miniwindow_p
= 1;
13160 /* If we don't display the current message, don't clear the
13161 message_cleared_p flag, because, if we did, we wouldn't clear
13162 the echo area in the next redisplay which doesn't preserve
13164 if (!display_last_displayed_message_p
)
13165 message_cleared_p
= 0;
13167 if (fonts_changed_p
)
13169 else if (window_height_changed_p
)
13171 consider_all_windows_p
= 1;
13172 ++update_mode_lines
;
13173 ++windows_or_buffers_changed
;
13175 /* If window configuration was changed, frames may have been
13176 marked garbaged. Clear them or we will experience
13177 surprises wrt scrolling. */
13178 clear_garbaged_frames ();
13181 else if (EQ (selected_window
, minibuf_window
)
13182 && (current_buffer
->clip_changed
|| window_outdated (w
))
13183 && resize_mini_window (w
, 0))
13185 /* Resized active mini-window to fit the size of what it is
13186 showing if its contents might have changed. */
13188 /* FIXME: this causes all frames to be updated, which seems unnecessary
13189 since only the current frame needs to be considered. This function
13190 needs to be rewritten with two variables, consider_all_windows and
13191 consider_all_frames. */
13192 consider_all_windows_p
= 1;
13193 ++windows_or_buffers_changed
;
13194 ++update_mode_lines
;
13196 /* If window configuration was changed, frames may have been
13197 marked garbaged. Clear them or we will experience
13198 surprises wrt scrolling. */
13199 clear_garbaged_frames ();
13203 /* If showing the region, and mark has changed, we must redisplay
13204 the whole window. The assignment to this_line_start_pos prevents
13205 the optimization directly below this if-statement. */
13206 if (((!NILP (Vtransient_mark_mode
)
13207 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13208 != !NILP (w
->region_showing
))
13209 || (!NILP (w
->region_showing
)
13210 && !EQ (w
->region_showing
,
13211 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13212 CHARPOS (this_line_start_pos
) = 0;
13214 /* Optimize the case that only the line containing the cursor in the
13215 selected window has changed. Variables starting with this_ are
13216 set in display_line and record information about the line
13217 containing the cursor. */
13218 tlbufpos
= this_line_start_pos
;
13219 tlendpos
= this_line_end_pos
;
13220 if (!consider_all_windows_p
13221 && CHARPOS (tlbufpos
) > 0
13222 && !w
->update_mode_line
13223 && !current_buffer
->clip_changed
13224 && !current_buffer
->prevent_redisplay_optimizations_p
13225 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13226 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13227 /* Make sure recorded data applies to current buffer, etc. */
13228 && this_line_buffer
== current_buffer
13229 && current_buffer
== XBUFFER (w
->buffer
)
13231 && !w
->optional_new_start
13232 /* Point must be on the line that we have info recorded about. */
13233 && PT
>= CHARPOS (tlbufpos
)
13234 && PT
<= Z
- CHARPOS (tlendpos
)
13235 /* All text outside that line, including its final newline,
13236 must be unchanged. */
13237 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13238 CHARPOS (tlendpos
)))
13240 if (CHARPOS (tlbufpos
) > BEGV
13241 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13242 && (CHARPOS (tlbufpos
) == ZV
13243 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13244 /* Former continuation line has disappeared by becoming empty. */
13246 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13248 /* We have to handle the case of continuation around a
13249 wide-column character (see the comment in indent.c around
13252 For instance, in the following case:
13254 -------- Insert --------
13255 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13256 J_I_ ==> J_I_ `^^' are cursors.
13260 As we have to redraw the line above, we cannot use this
13264 int line_height_before
= this_line_pixel_height
;
13266 /* Note that start_display will handle the case that the
13267 line starting at tlbufpos is a continuation line. */
13268 start_display (&it
, w
, tlbufpos
);
13270 /* Implementation note: It this still necessary? */
13271 if (it
.current_x
!= this_line_start_x
)
13274 TRACE ((stderr
, "trying display optimization 1\n"));
13275 w
->cursor
.vpos
= -1;
13276 overlay_arrow_seen
= 0;
13277 it
.vpos
= this_line_vpos
;
13278 it
.current_y
= this_line_y
;
13279 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13280 display_line (&it
);
13282 /* If line contains point, is not continued,
13283 and ends at same distance from eob as before, we win. */
13284 if (w
->cursor
.vpos
>= 0
13285 /* Line is not continued, otherwise this_line_start_pos
13286 would have been set to 0 in display_line. */
13287 && CHARPOS (this_line_start_pos
)
13288 /* Line ends as before. */
13289 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13290 /* Line has same height as before. Otherwise other lines
13291 would have to be shifted up or down. */
13292 && this_line_pixel_height
== line_height_before
)
13294 /* If this is not the window's last line, we must adjust
13295 the charstarts of the lines below. */
13296 if (it
.current_y
< it
.last_visible_y
)
13298 struct glyph_row
*row
13299 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13300 ptrdiff_t delta
, delta_bytes
;
13302 /* We used to distinguish between two cases here,
13303 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13304 when the line ends in a newline or the end of the
13305 buffer's accessible portion. But both cases did
13306 the same, so they were collapsed. */
13308 - CHARPOS (tlendpos
)
13309 - MATRIX_ROW_START_CHARPOS (row
));
13310 delta_bytes
= (Z_BYTE
13311 - BYTEPOS (tlendpos
)
13312 - MATRIX_ROW_START_BYTEPOS (row
));
13314 increment_matrix_positions (w
->current_matrix
,
13315 this_line_vpos
+ 1,
13316 w
->current_matrix
->nrows
,
13317 delta
, delta_bytes
);
13320 /* If this row displays text now but previously didn't,
13321 or vice versa, w->window_end_vpos may have to be
13323 if ((it
.glyph_row
- 1)->displays_text_p
)
13325 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13326 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13328 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13329 && this_line_vpos
> 0)
13330 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13331 wset_window_end_valid (w
, Qnil
);
13333 /* Update hint: No need to try to scroll in update_window. */
13334 w
->desired_matrix
->no_scrolling_p
= 1;
13337 *w
->desired_matrix
->method
= 0;
13338 debug_method_add (w
, "optimization 1");
13340 #ifdef HAVE_WINDOW_SYSTEM
13341 update_window_fringes (w
, 0);
13348 else if (/* Cursor position hasn't changed. */
13349 PT
== w
->last_point
13350 /* Make sure the cursor was last displayed
13351 in this window. Otherwise we have to reposition it. */
13352 && 0 <= w
->cursor
.vpos
13353 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13357 do_pending_window_change (1);
13358 /* If selected_window changed, redisplay again. */
13359 if (WINDOWP (selected_window
)
13360 && (w
= XWINDOW (selected_window
)) != sw
)
13363 /* We used to always goto end_of_redisplay here, but this
13364 isn't enough if we have a blinking cursor. */
13365 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13366 goto end_of_redisplay
;
13370 /* If highlighting the region, or if the cursor is in the echo area,
13371 then we can't just move the cursor. */
13372 else if (! (!NILP (Vtransient_mark_mode
)
13373 && !NILP (BVAR (current_buffer
, mark_active
)))
13374 && (EQ (selected_window
,
13375 BVAR (current_buffer
, last_selected_window
))
13376 || highlight_nonselected_windows
)
13377 && NILP (w
->region_showing
)
13378 && NILP (Vshow_trailing_whitespace
)
13379 && !cursor_in_echo_area
)
13382 struct glyph_row
*row
;
13384 /* Skip from tlbufpos to PT and see where it is. Note that
13385 PT may be in invisible text. If so, we will end at the
13386 next visible position. */
13387 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13388 NULL
, DEFAULT_FACE_ID
);
13389 it
.current_x
= this_line_start_x
;
13390 it
.current_y
= this_line_y
;
13391 it
.vpos
= this_line_vpos
;
13393 /* The call to move_it_to stops in front of PT, but
13394 moves over before-strings. */
13395 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13397 if (it
.vpos
== this_line_vpos
13398 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13401 eassert (this_line_vpos
== it
.vpos
);
13402 eassert (this_line_y
== it
.current_y
);
13403 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13405 *w
->desired_matrix
->method
= 0;
13406 debug_method_add (w
, "optimization 3");
13415 /* Text changed drastically or point moved off of line. */
13416 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13419 CHARPOS (this_line_start_pos
) = 0;
13420 consider_all_windows_p
|= buffer_shared_and_changed ();
13421 ++clear_face_cache_count
;
13422 #ifdef HAVE_WINDOW_SYSTEM
13423 ++clear_image_cache_count
;
13426 /* Build desired matrices, and update the display. If
13427 consider_all_windows_p is non-zero, do it for all windows on all
13428 frames. Otherwise do it for selected_window, only. */
13430 if (consider_all_windows_p
)
13432 FOR_EACH_FRAME (tail
, frame
)
13433 XFRAME (frame
)->updated_p
= 0;
13435 FOR_EACH_FRAME (tail
, frame
)
13437 struct frame
*f
= XFRAME (frame
);
13439 /* We don't have to do anything for unselected terminal
13441 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13442 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13445 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13447 /* Mark all the scroll bars to be removed; we'll redeem
13448 the ones we want when we redisplay their windows. */
13449 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13450 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13452 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13453 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13455 /* The X error handler may have deleted that frame. */
13456 if (!FRAME_LIVE_P (f
))
13459 /* Any scroll bars which redisplay_windows should have
13460 nuked should now go away. */
13461 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13462 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13464 /* If fonts changed, display again. */
13465 /* ??? rms: I suspect it is a mistake to jump all the way
13466 back to retry here. It should just retry this frame. */
13467 if (fonts_changed_p
)
13470 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13472 /* See if we have to hscroll. */
13473 if (!f
->already_hscrolled_p
)
13475 f
->already_hscrolled_p
= 1;
13476 if (hscroll_windows (f
->root_window
))
13480 /* Prevent various kinds of signals during display
13481 update. stdio is not robust about handling
13482 signals, which can cause an apparent I/O
13484 if (interrupt_input
)
13485 unrequest_sigio ();
13488 /* Update the display. */
13489 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13490 pending
|= update_frame (f
, 0, 0);
13496 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13500 /* Do the mark_window_display_accurate after all windows have
13501 been redisplayed because this call resets flags in buffers
13502 which are needed for proper redisplay. */
13503 FOR_EACH_FRAME (tail
, frame
)
13505 struct frame
*f
= XFRAME (frame
);
13508 mark_window_display_accurate (f
->root_window
, 1);
13509 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13510 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13515 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13517 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13518 struct frame
*mini_frame
;
13520 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13521 /* Use list_of_error, not Qerror, so that
13522 we catch only errors and don't run the debugger. */
13523 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13525 redisplay_window_error
);
13526 if (update_miniwindow_p
)
13527 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13529 redisplay_window_error
);
13531 /* Compare desired and current matrices, perform output. */
13534 /* If fonts changed, display again. */
13535 if (fonts_changed_p
)
13538 /* Prevent various kinds of signals during display update.
13539 stdio is not robust about handling signals,
13540 which can cause an apparent I/O error. */
13541 if (interrupt_input
)
13542 unrequest_sigio ();
13545 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13547 if (hscroll_windows (selected_window
))
13550 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13551 pending
= update_frame (sf
, 0, 0);
13554 /* We may have called echo_area_display at the top of this
13555 function. If the echo area is on another frame, that may
13556 have put text on a frame other than the selected one, so the
13557 above call to update_frame would not have caught it. Catch
13559 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13560 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13562 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13564 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13565 pending
|= update_frame (mini_frame
, 0, 0);
13566 if (!pending
&& hscroll_windows (mini_window
))
13571 /* If display was paused because of pending input, make sure we do a
13572 thorough update the next time. */
13575 /* Prevent the optimization at the beginning of
13576 redisplay_internal that tries a single-line update of the
13577 line containing the cursor in the selected window. */
13578 CHARPOS (this_line_start_pos
) = 0;
13580 /* Let the overlay arrow be updated the next time. */
13581 update_overlay_arrows (0);
13583 /* If we pause after scrolling, some rows in the current
13584 matrices of some windows are not valid. */
13585 if (!WINDOW_FULL_WIDTH_P (w
)
13586 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13587 update_mode_lines
= 1;
13591 if (!consider_all_windows_p
)
13593 /* This has already been done above if
13594 consider_all_windows_p is set. */
13595 mark_window_display_accurate_1 (w
, 1);
13597 /* Say overlay arrows are up to date. */
13598 update_overlay_arrows (1);
13600 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13601 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13604 update_mode_lines
= 0;
13605 windows_or_buffers_changed
= 0;
13606 cursor_type_changed
= 0;
13609 /* Start SIGIO interrupts coming again. Having them off during the
13610 code above makes it less likely one will discard output, but not
13611 impossible, since there might be stuff in the system buffer here.
13612 But it is much hairier to try to do anything about that. */
13613 if (interrupt_input
)
13617 /* If a frame has become visible which was not before, redisplay
13618 again, so that we display it. Expose events for such a frame
13619 (which it gets when becoming visible) don't call the parts of
13620 redisplay constructing glyphs, so simply exposing a frame won't
13621 display anything in this case. So, we have to display these
13622 frames here explicitly. */
13627 FOR_EACH_FRAME (tail
, frame
)
13629 int this_is_visible
= 0;
13631 if (XFRAME (frame
)->visible
)
13632 this_is_visible
= 1;
13633 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13634 if (XFRAME (frame
)->visible
)
13635 this_is_visible
= 1;
13637 if (this_is_visible
)
13641 if (new_count
!= number_of_visible_frames
)
13642 windows_or_buffers_changed
++;
13645 /* Change frame size now if a change is pending. */
13646 do_pending_window_change (1);
13648 /* If we just did a pending size change, or have additional
13649 visible frames, or selected_window changed, redisplay again. */
13650 if ((windows_or_buffers_changed
&& !pending
)
13651 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13654 /* Clear the face and image caches.
13656 We used to do this only if consider_all_windows_p. But the cache
13657 needs to be cleared if a timer creates images in the current
13658 buffer (e.g. the test case in Bug#6230). */
13660 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13662 clear_face_cache (0);
13663 clear_face_cache_count
= 0;
13666 #ifdef HAVE_WINDOW_SYSTEM
13667 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13669 clear_image_caches (Qnil
);
13670 clear_image_cache_count
= 0;
13672 #endif /* HAVE_WINDOW_SYSTEM */
13675 backtrace_list
= backtrace
.next
;
13676 unbind_to (count
, Qnil
);
13681 /* Redisplay, but leave alone any recent echo area message unless
13682 another message has been requested in its place.
13684 This is useful in situations where you need to redisplay but no
13685 user action has occurred, making it inappropriate for the message
13686 area to be cleared. See tracking_off and
13687 wait_reading_process_output for examples of these situations.
13689 FROM_WHERE is an integer saying from where this function was
13690 called. This is useful for debugging. */
13693 redisplay_preserve_echo_area (int from_where
)
13695 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13697 if (!NILP (echo_area_buffer
[1]))
13699 /* We have a previously displayed message, but no current
13700 message. Redisplay the previous message. */
13701 display_last_displayed_message_p
= 1;
13702 redisplay_internal ();
13703 display_last_displayed_message_p
= 0;
13706 redisplay_internal ();
13708 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13709 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13710 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13714 /* Function registered with record_unwind_protect in redisplay_internal.
13715 Clear redisplaying_p. Also select the previously selected frame. */
13718 unwind_redisplay (Lisp_Object old_frame
)
13720 redisplaying_p
= 0;
13725 /* Mark the display of window W as accurate or inaccurate. If
13726 ACCURATE_P is non-zero mark display of W as accurate. If
13727 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13728 redisplay_internal is called. */
13731 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13733 if (BUFFERP (w
->buffer
))
13735 struct buffer
*b
= XBUFFER (w
->buffer
);
13737 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13738 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13740 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13744 b
->clip_changed
= 0;
13745 b
->prevent_redisplay_optimizations_p
= 0;
13747 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13748 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13749 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13750 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13752 w
->current_matrix
->buffer
= b
;
13753 w
->current_matrix
->begv
= BUF_BEGV (b
);
13754 w
->current_matrix
->zv
= BUF_ZV (b
);
13756 w
->last_cursor
= w
->cursor
;
13757 w
->last_cursor_off_p
= w
->cursor_off_p
;
13759 if (w
== XWINDOW (selected_window
))
13760 w
->last_point
= BUF_PT (b
);
13762 w
->last_point
= marker_position (w
->pointm
);
13768 wset_window_end_valid (w
, w
->buffer
);
13769 w
->update_mode_line
= 0;
13774 /* Mark the display of windows in the window tree rooted at WINDOW as
13775 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13776 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13777 be redisplayed the next time redisplay_internal is called. */
13780 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13784 for (; !NILP (window
); window
= w
->next
)
13786 w
= XWINDOW (window
);
13787 mark_window_display_accurate_1 (w
, accurate_p
);
13789 if (!NILP (w
->vchild
))
13790 mark_window_display_accurate (w
->vchild
, accurate_p
);
13791 if (!NILP (w
->hchild
))
13792 mark_window_display_accurate (w
->hchild
, accurate_p
);
13797 update_overlay_arrows (1);
13801 /* Force a thorough redisplay the next time by setting
13802 last_arrow_position and last_arrow_string to t, which is
13803 unequal to any useful value of Voverlay_arrow_... */
13804 update_overlay_arrows (-1);
13809 /* Return value in display table DP (Lisp_Char_Table *) for character
13810 C. Since a display table doesn't have any parent, we don't have to
13811 follow parent. Do not call this function directly but use the
13812 macro DISP_CHAR_VECTOR. */
13815 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13819 if (ASCII_CHAR_P (c
))
13822 if (SUB_CHAR_TABLE_P (val
))
13823 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13829 XSETCHAR_TABLE (table
, dp
);
13830 val
= char_table_ref (table
, c
);
13839 /***********************************************************************
13841 ***********************************************************************/
13843 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13846 redisplay_windows (Lisp_Object window
)
13848 while (!NILP (window
))
13850 struct window
*w
= XWINDOW (window
);
13852 if (!NILP (w
->hchild
))
13853 redisplay_windows (w
->hchild
);
13854 else if (!NILP (w
->vchild
))
13855 redisplay_windows (w
->vchild
);
13856 else if (!NILP (w
->buffer
))
13858 displayed_buffer
= XBUFFER (w
->buffer
);
13859 /* Use list_of_error, not Qerror, so that
13860 we catch only errors and don't run the debugger. */
13861 internal_condition_case_1 (redisplay_window_0
, window
,
13863 redisplay_window_error
);
13871 redisplay_window_error (Lisp_Object ignore
)
13873 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13878 redisplay_window_0 (Lisp_Object window
)
13880 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13881 redisplay_window (window
, 0);
13886 redisplay_window_1 (Lisp_Object window
)
13888 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13889 redisplay_window (window
, 1);
13894 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13895 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13896 which positions recorded in ROW differ from current buffer
13899 Return 0 if cursor is not on this row, 1 otherwise. */
13902 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13903 struct glyph_matrix
*matrix
,
13904 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13907 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13908 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13909 struct glyph
*cursor
= NULL
;
13910 /* The last known character position in row. */
13911 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13913 ptrdiff_t pt_old
= PT
- delta
;
13914 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13915 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13916 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13917 /* A glyph beyond the edge of TEXT_AREA which we should never
13919 struct glyph
*glyphs_end
= end
;
13920 /* Non-zero means we've found a match for cursor position, but that
13921 glyph has the avoid_cursor_p flag set. */
13922 int match_with_avoid_cursor
= 0;
13923 /* Non-zero means we've seen at least one glyph that came from a
13925 int string_seen
= 0;
13926 /* Largest and smallest buffer positions seen so far during scan of
13928 ptrdiff_t bpos_max
= pos_before
;
13929 ptrdiff_t bpos_min
= pos_after
;
13930 /* Last buffer position covered by an overlay string with an integer
13931 `cursor' property. */
13932 ptrdiff_t bpos_covered
= 0;
13933 /* Non-zero means the display string on which to display the cursor
13934 comes from a text property, not from an overlay. */
13935 int string_from_text_prop
= 0;
13937 /* Don't even try doing anything if called for a mode-line or
13938 header-line row, since the rest of the code isn't prepared to
13939 deal with such calamities. */
13940 eassert (!row
->mode_line_p
);
13941 if (row
->mode_line_p
)
13944 /* Skip over glyphs not having an object at the start and the end of
13945 the row. These are special glyphs like truncation marks on
13946 terminal frames. */
13947 if (row
->displays_text_p
)
13949 if (!row
->reversed_p
)
13952 && INTEGERP (glyph
->object
)
13953 && glyph
->charpos
< 0)
13955 x
+= glyph
->pixel_width
;
13959 && INTEGERP ((end
- 1)->object
)
13960 /* CHARPOS is zero for blanks and stretch glyphs
13961 inserted by extend_face_to_end_of_line. */
13962 && (end
- 1)->charpos
<= 0)
13964 glyph_before
= glyph
- 1;
13971 /* If the glyph row is reversed, we need to process it from back
13972 to front, so swap the edge pointers. */
13973 glyphs_end
= end
= glyph
- 1;
13974 glyph
+= row
->used
[TEXT_AREA
] - 1;
13976 while (glyph
> end
+ 1
13977 && INTEGERP (glyph
->object
)
13978 && glyph
->charpos
< 0)
13981 x
-= glyph
->pixel_width
;
13983 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13985 /* By default, in reversed rows we put the cursor on the
13986 rightmost (first in the reading order) glyph. */
13987 for (g
= end
+ 1; g
< glyph
; g
++)
13988 x
+= g
->pixel_width
;
13990 && INTEGERP ((end
+ 1)->object
)
13991 && (end
+ 1)->charpos
<= 0)
13993 glyph_before
= glyph
+ 1;
13997 else if (row
->reversed_p
)
13999 /* In R2L rows that don't display text, put the cursor on the
14000 rightmost glyph. Case in point: an empty last line that is
14001 part of an R2L paragraph. */
14003 /* Avoid placing the cursor on the last glyph of the row, where
14004 on terminal frames we hold the vertical border between
14005 adjacent windows. */
14006 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14007 && !WINDOW_RIGHTMOST_P (w
)
14008 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14010 x
= -1; /* will be computed below, at label compute_x */
14013 /* Step 1: Try to find the glyph whose character position
14014 corresponds to point. If that's not possible, find 2 glyphs
14015 whose character positions are the closest to point, one before
14016 point, the other after it. */
14017 if (!row
->reversed_p
)
14018 while (/* not marched to end of glyph row */
14020 /* glyph was not inserted by redisplay for internal purposes */
14021 && !INTEGERP (glyph
->object
))
14023 if (BUFFERP (glyph
->object
))
14025 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14027 if (glyph
->charpos
> bpos_max
)
14028 bpos_max
= glyph
->charpos
;
14029 if (glyph
->charpos
< bpos_min
)
14030 bpos_min
= glyph
->charpos
;
14031 if (!glyph
->avoid_cursor_p
)
14033 /* If we hit point, we've found the glyph on which to
14034 display the cursor. */
14037 match_with_avoid_cursor
= 0;
14040 /* See if we've found a better approximation to
14041 POS_BEFORE or to POS_AFTER. */
14042 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14044 pos_before
= glyph
->charpos
;
14045 glyph_before
= glyph
;
14047 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14049 pos_after
= glyph
->charpos
;
14050 glyph_after
= glyph
;
14053 else if (dpos
== 0)
14054 match_with_avoid_cursor
= 1;
14056 else if (STRINGP (glyph
->object
))
14058 Lisp_Object chprop
;
14059 ptrdiff_t glyph_pos
= glyph
->charpos
;
14061 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14063 if (!NILP (chprop
))
14065 /* If the string came from a `display' text property,
14066 look up the buffer position of that property and
14067 use that position to update bpos_max, as if we
14068 actually saw such a position in one of the row's
14069 glyphs. This helps with supporting integer values
14070 of `cursor' property on the display string in
14071 situations where most or all of the row's buffer
14072 text is completely covered by display properties,
14073 so that no glyph with valid buffer positions is
14074 ever seen in the row. */
14075 ptrdiff_t prop_pos
=
14076 string_buffer_position_lim (glyph
->object
, pos_before
,
14079 if (prop_pos
>= pos_before
)
14080 bpos_max
= prop_pos
- 1;
14082 if (INTEGERP (chprop
))
14084 bpos_covered
= bpos_max
+ XINT (chprop
);
14085 /* If the `cursor' property covers buffer positions up
14086 to and including point, we should display cursor on
14087 this glyph. Note that, if a `cursor' property on one
14088 of the string's characters has an integer value, we
14089 will break out of the loop below _before_ we get to
14090 the position match above. IOW, integer values of
14091 the `cursor' property override the "exact match for
14092 point" strategy of positioning the cursor. */
14093 /* Implementation note: bpos_max == pt_old when, e.g.,
14094 we are in an empty line, where bpos_max is set to
14095 MATRIX_ROW_START_CHARPOS, see above. */
14096 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14105 x
+= glyph
->pixel_width
;
14108 else if (glyph
> end
) /* row is reversed */
14109 while (!INTEGERP (glyph
->object
))
14111 if (BUFFERP (glyph
->object
))
14113 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14115 if (glyph
->charpos
> bpos_max
)
14116 bpos_max
= glyph
->charpos
;
14117 if (glyph
->charpos
< bpos_min
)
14118 bpos_min
= glyph
->charpos
;
14119 if (!glyph
->avoid_cursor_p
)
14123 match_with_avoid_cursor
= 0;
14126 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14128 pos_before
= glyph
->charpos
;
14129 glyph_before
= glyph
;
14131 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14133 pos_after
= glyph
->charpos
;
14134 glyph_after
= glyph
;
14137 else if (dpos
== 0)
14138 match_with_avoid_cursor
= 1;
14140 else if (STRINGP (glyph
->object
))
14142 Lisp_Object chprop
;
14143 ptrdiff_t glyph_pos
= glyph
->charpos
;
14145 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14147 if (!NILP (chprop
))
14149 ptrdiff_t prop_pos
=
14150 string_buffer_position_lim (glyph
->object
, pos_before
,
14153 if (prop_pos
>= pos_before
)
14154 bpos_max
= prop_pos
- 1;
14156 if (INTEGERP (chprop
))
14158 bpos_covered
= bpos_max
+ XINT (chprop
);
14159 /* If the `cursor' property covers buffer positions up
14160 to and including point, we should display cursor on
14162 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14171 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14173 x
--; /* can't use any pixel_width */
14176 x
-= glyph
->pixel_width
;
14179 /* Step 2: If we didn't find an exact match for point, we need to
14180 look for a proper place to put the cursor among glyphs between
14181 GLYPH_BEFORE and GLYPH_AFTER. */
14182 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14183 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14184 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14186 /* An empty line has a single glyph whose OBJECT is zero and
14187 whose CHARPOS is the position of a newline on that line.
14188 Note that on a TTY, there are more glyphs after that, which
14189 were produced by extend_face_to_end_of_line, but their
14190 CHARPOS is zero or negative. */
14192 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14193 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14194 /* On a TTY, continued and truncated rows also have a glyph at
14195 their end whose OBJECT is zero and whose CHARPOS is
14196 positive (the continuation and truncation glyphs), but such
14197 rows are obviously not "empty". */
14198 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14200 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14202 ptrdiff_t ellipsis_pos
;
14204 /* Scan back over the ellipsis glyphs. */
14205 if (!row
->reversed_p
)
14207 ellipsis_pos
= (glyph
- 1)->charpos
;
14208 while (glyph
> row
->glyphs
[TEXT_AREA
]
14209 && (glyph
- 1)->charpos
== ellipsis_pos
)
14210 glyph
--, x
-= glyph
->pixel_width
;
14211 /* That loop always goes one position too far, including
14212 the glyph before the ellipsis. So scan forward over
14214 x
+= glyph
->pixel_width
;
14217 else /* row is reversed */
14219 ellipsis_pos
= (glyph
+ 1)->charpos
;
14220 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14221 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14222 glyph
++, x
+= glyph
->pixel_width
;
14223 x
-= glyph
->pixel_width
;
14227 else if (match_with_avoid_cursor
)
14229 cursor
= glyph_after
;
14232 else if (string_seen
)
14234 int incr
= row
->reversed_p
? -1 : +1;
14236 /* Need to find the glyph that came out of a string which is
14237 present at point. That glyph is somewhere between
14238 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14239 positioned between POS_BEFORE and POS_AFTER in the
14241 struct glyph
*start
, *stop
;
14242 ptrdiff_t pos
= pos_before
;
14246 /* If the row ends in a newline from a display string,
14247 reordering could have moved the glyphs belonging to the
14248 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14249 in this case we extend the search to the last glyph in
14250 the row that was not inserted by redisplay. */
14251 if (row
->ends_in_newline_from_string_p
)
14254 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14257 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14258 correspond to POS_BEFORE and POS_AFTER, respectively. We
14259 need START and STOP in the order that corresponds to the
14260 row's direction as given by its reversed_p flag. If the
14261 directionality of characters between POS_BEFORE and
14262 POS_AFTER is the opposite of the row's base direction,
14263 these characters will have been reordered for display,
14264 and we need to reverse START and STOP. */
14265 if (!row
->reversed_p
)
14267 start
= min (glyph_before
, glyph_after
);
14268 stop
= max (glyph_before
, glyph_after
);
14272 start
= max (glyph_before
, glyph_after
);
14273 stop
= min (glyph_before
, glyph_after
);
14275 for (glyph
= start
+ incr
;
14276 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14279 /* Any glyphs that come from the buffer are here because
14280 of bidi reordering. Skip them, and only pay
14281 attention to glyphs that came from some string. */
14282 if (STRINGP (glyph
->object
))
14286 /* If the display property covers the newline, we
14287 need to search for it one position farther. */
14288 ptrdiff_t lim
= pos_after
14289 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14291 string_from_text_prop
= 0;
14292 str
= glyph
->object
;
14293 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14294 if (tem
== 0 /* from overlay */
14297 /* If the string from which this glyph came is
14298 found in the buffer at point, or at position
14299 that is closer to point than pos_after, then
14300 we've found the glyph we've been looking for.
14301 If it comes from an overlay (tem == 0), and
14302 it has the `cursor' property on one of its
14303 glyphs, record that glyph as a candidate for
14304 displaying the cursor. (As in the
14305 unidirectional version, we will display the
14306 cursor on the last candidate we find.) */
14309 || (tem
- pt_old
> 0 && tem
< pos_after
))
14311 /* The glyphs from this string could have
14312 been reordered. Find the one with the
14313 smallest string position. Or there could
14314 be a character in the string with the
14315 `cursor' property, which means display
14316 cursor on that character's glyph. */
14317 ptrdiff_t strpos
= glyph
->charpos
;
14322 string_from_text_prop
= 1;
14325 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14326 && EQ (glyph
->object
, str
);
14330 ptrdiff_t gpos
= glyph
->charpos
;
14332 cprop
= Fget_char_property (make_number (gpos
),
14340 if (tem
&& glyph
->charpos
< strpos
)
14342 strpos
= glyph
->charpos
;
14348 || (tem
- pt_old
> 0 && tem
< pos_after
))
14352 pos
= tem
+ 1; /* don't find previous instances */
14354 /* This string is not what we want; skip all of the
14355 glyphs that came from it. */
14356 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14357 && EQ (glyph
->object
, str
))
14364 /* If we reached the end of the line, and END was from a string,
14365 the cursor is not on this line. */
14367 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14368 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14369 && STRINGP (end
->object
)
14370 && row
->continued_p
)
14373 /* A truncated row may not include PT among its character positions.
14374 Setting the cursor inside the scroll margin will trigger
14375 recalculation of hscroll in hscroll_window_tree. But if a
14376 display string covers point, defer to the string-handling
14377 code below to figure this out. */
14378 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14380 cursor
= glyph_before
;
14383 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14384 /* Zero-width characters produce no glyphs. */
14386 && (row
->reversed_p
14387 ? glyph_after
> glyphs_end
14388 : glyph_after
< glyphs_end
)))
14390 cursor
= glyph_after
;
14396 if (cursor
!= NULL
)
14398 else if (glyph
== glyphs_end
14399 && pos_before
== pos_after
14400 && STRINGP ((row
->reversed_p
14401 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14402 : row
->glyphs
[TEXT_AREA
])->object
))
14404 /* If all the glyphs of this row came from strings, put the
14405 cursor on the first glyph of the row. This avoids having the
14406 cursor outside of the text area in this very rare and hard
14410 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14411 : row
->glyphs
[TEXT_AREA
];
14417 /* Need to compute x that corresponds to GLYPH. */
14418 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14420 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14422 x
+= g
->pixel_width
;
14426 /* ROW could be part of a continued line, which, under bidi
14427 reordering, might have other rows whose start and end charpos
14428 occlude point. Only set w->cursor if we found a better
14429 approximation to the cursor position than we have from previously
14430 examined candidate rows belonging to the same continued line. */
14431 if (/* we already have a candidate row */
14432 w
->cursor
.vpos
>= 0
14433 /* that candidate is not the row we are processing */
14434 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14435 /* Make sure cursor.vpos specifies a row whose start and end
14436 charpos occlude point, and it is valid candidate for being a
14437 cursor-row. This is because some callers of this function
14438 leave cursor.vpos at the row where the cursor was displayed
14439 during the last redisplay cycle. */
14440 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14441 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14442 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14445 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14447 /* Don't consider glyphs that are outside TEXT_AREA. */
14448 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14450 /* Keep the candidate whose buffer position is the closest to
14451 point or has the `cursor' property. */
14452 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14453 w
->cursor
.hpos
>= 0
14454 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14455 && ((BUFFERP (g1
->object
)
14456 && (g1
->charpos
== pt_old
/* an exact match always wins */
14457 || (BUFFERP (glyph
->object
)
14458 && eabs (g1
->charpos
- pt_old
)
14459 < eabs (glyph
->charpos
- pt_old
))))
14460 /* previous candidate is a glyph from a string that has
14461 a non-nil `cursor' property */
14462 || (STRINGP (g1
->object
)
14463 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14464 Qcursor
, g1
->object
))
14465 /* previous candidate is from the same display
14466 string as this one, and the display string
14467 came from a text property */
14468 || (EQ (g1
->object
, glyph
->object
)
14469 && string_from_text_prop
)
14470 /* this candidate is from newline and its
14471 position is not an exact match */
14472 || (INTEGERP (glyph
->object
)
14473 && glyph
->charpos
!= pt_old
)))))
14475 /* If this candidate gives an exact match, use that. */
14476 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14477 /* If this candidate is a glyph created for the
14478 terminating newline of a line, and point is on that
14479 newline, it wins because it's an exact match. */
14480 || (!row
->continued_p
14481 && INTEGERP (glyph
->object
)
14482 && glyph
->charpos
== 0
14483 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14484 /* Otherwise, keep the candidate that comes from a row
14485 spanning less buffer positions. This may win when one or
14486 both candidate positions are on glyphs that came from
14487 display strings, for which we cannot compare buffer
14489 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14490 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14491 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14494 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14496 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14497 w
->cursor
.y
= row
->y
+ dy
;
14499 if (w
== XWINDOW (selected_window
))
14501 if (!row
->continued_p
14502 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14505 this_line_buffer
= XBUFFER (w
->buffer
);
14507 CHARPOS (this_line_start_pos
)
14508 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14509 BYTEPOS (this_line_start_pos
)
14510 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14512 CHARPOS (this_line_end_pos
)
14513 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14514 BYTEPOS (this_line_end_pos
)
14515 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14517 this_line_y
= w
->cursor
.y
;
14518 this_line_pixel_height
= row
->height
;
14519 this_line_vpos
= w
->cursor
.vpos
;
14520 this_line_start_x
= row
->x
;
14523 CHARPOS (this_line_start_pos
) = 0;
14530 /* Run window scroll functions, if any, for WINDOW with new window
14531 start STARTP. Sets the window start of WINDOW to that position.
14533 We assume that the window's buffer is really current. */
14535 static struct text_pos
14536 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14538 struct window
*w
= XWINDOW (window
);
14539 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14541 if (current_buffer
!= XBUFFER (w
->buffer
))
14544 if (!NILP (Vwindow_scroll_functions
))
14546 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14547 make_number (CHARPOS (startp
)));
14548 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14549 /* In case the hook functions switch buffers. */
14550 set_buffer_internal (XBUFFER (w
->buffer
));
14557 /* Make sure the line containing the cursor is fully visible.
14558 A value of 1 means there is nothing to be done.
14559 (Either the line is fully visible, or it cannot be made so,
14560 or we cannot tell.)
14562 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14563 is higher than window.
14565 A value of 0 means the caller should do scrolling
14566 as if point had gone off the screen. */
14569 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14571 struct glyph_matrix
*matrix
;
14572 struct glyph_row
*row
;
14575 if (!make_cursor_line_fully_visible_p
)
14578 /* It's not always possible to find the cursor, e.g, when a window
14579 is full of overlay strings. Don't do anything in that case. */
14580 if (w
->cursor
.vpos
< 0)
14583 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14584 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14586 /* If the cursor row is not partially visible, there's nothing to do. */
14587 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14590 /* If the row the cursor is in is taller than the window's height,
14591 it's not clear what to do, so do nothing. */
14592 window_height
= window_box_height (w
);
14593 if (row
->height
>= window_height
)
14595 if (!force_p
|| MINI_WINDOW_P (w
)
14596 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14603 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14604 non-zero means only WINDOW is redisplayed in redisplay_internal.
14605 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14606 in redisplay_window to bring a partially visible line into view in
14607 the case that only the cursor has moved.
14609 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14610 last screen line's vertical height extends past the end of the screen.
14614 1 if scrolling succeeded
14616 0 if scrolling didn't find point.
14618 -1 if new fonts have been loaded so that we must interrupt
14619 redisplay, adjust glyph matrices, and try again. */
14625 SCROLLING_NEED_LARGER_MATRICES
14628 /* If scroll-conservatively is more than this, never recenter.
14630 If you change this, don't forget to update the doc string of
14631 `scroll-conservatively' and the Emacs manual. */
14632 #define SCROLL_LIMIT 100
14635 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14636 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14637 int temp_scroll_step
, int last_line_misfit
)
14639 struct window
*w
= XWINDOW (window
);
14640 struct frame
*f
= XFRAME (w
->frame
);
14641 struct text_pos pos
, startp
;
14643 int this_scroll_margin
, scroll_max
, rc
, height
;
14644 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14645 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14646 Lisp_Object aggressive
;
14647 /* We will never try scrolling more than this number of lines. */
14648 int scroll_limit
= SCROLL_LIMIT
;
14651 debug_method_add (w
, "try_scrolling");
14654 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14656 /* Compute scroll margin height in pixels. We scroll when point is
14657 within this distance from the top or bottom of the window. */
14658 if (scroll_margin
> 0)
14659 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14660 * FRAME_LINE_HEIGHT (f
);
14662 this_scroll_margin
= 0;
14664 /* Force arg_scroll_conservatively to have a reasonable value, to
14665 avoid scrolling too far away with slow move_it_* functions. Note
14666 that the user can supply scroll-conservatively equal to
14667 `most-positive-fixnum', which can be larger than INT_MAX. */
14668 if (arg_scroll_conservatively
> scroll_limit
)
14670 arg_scroll_conservatively
= scroll_limit
+ 1;
14671 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14673 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14674 /* Compute how much we should try to scroll maximally to bring
14675 point into view. */
14676 scroll_max
= (max (scroll_step
,
14677 max (arg_scroll_conservatively
, temp_scroll_step
))
14678 * FRAME_LINE_HEIGHT (f
));
14679 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14680 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14681 /* We're trying to scroll because of aggressive scrolling but no
14682 scroll_step is set. Choose an arbitrary one. */
14683 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14689 /* Decide whether to scroll down. */
14690 if (PT
> CHARPOS (startp
))
14692 int scroll_margin_y
;
14694 /* Compute the pixel ypos of the scroll margin, then move IT to
14695 either that ypos or PT, whichever comes first. */
14696 start_display (&it
, w
, startp
);
14697 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14698 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14699 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14700 (MOVE_TO_POS
| MOVE_TO_Y
));
14702 if (PT
> CHARPOS (it
.current
.pos
))
14704 int y0
= line_bottom_y (&it
);
14705 /* Compute how many pixels below window bottom to stop searching
14706 for PT. This avoids costly search for PT that is far away if
14707 the user limited scrolling by a small number of lines, but
14708 always finds PT if scroll_conservatively is set to a large
14709 number, such as most-positive-fixnum. */
14710 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14711 int y_to_move
= it
.last_visible_y
+ slack
;
14713 /* Compute the distance from the scroll margin to PT or to
14714 the scroll limit, whichever comes first. This should
14715 include the height of the cursor line, to make that line
14717 move_it_to (&it
, PT
, -1, y_to_move
,
14718 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14719 dy
= line_bottom_y (&it
) - y0
;
14721 if (dy
> scroll_max
)
14722 return SCROLLING_FAILED
;
14731 /* Point is in or below the bottom scroll margin, so move the
14732 window start down. If scrolling conservatively, move it just
14733 enough down to make point visible. If scroll_step is set,
14734 move it down by scroll_step. */
14735 if (arg_scroll_conservatively
)
14737 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14738 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14739 else if (scroll_step
|| temp_scroll_step
)
14740 amount_to_scroll
= scroll_max
;
14743 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14744 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14745 if (NUMBERP (aggressive
))
14747 double float_amount
= XFLOATINT (aggressive
) * height
;
14748 int aggressive_scroll
= float_amount
;
14749 if (aggressive_scroll
== 0 && float_amount
> 0)
14750 aggressive_scroll
= 1;
14751 /* Don't let point enter the scroll margin near top of
14752 the window. This could happen if the value of
14753 scroll_up_aggressively is too large and there are
14754 non-zero margins, because scroll_up_aggressively
14755 means put point that fraction of window height
14756 _from_the_bottom_margin_. */
14757 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14758 aggressive_scroll
= height
- 2*this_scroll_margin
;
14759 amount_to_scroll
= dy
+ aggressive_scroll
;
14763 if (amount_to_scroll
<= 0)
14764 return SCROLLING_FAILED
;
14766 start_display (&it
, w
, startp
);
14767 if (arg_scroll_conservatively
<= scroll_limit
)
14768 move_it_vertically (&it
, amount_to_scroll
);
14771 /* Extra precision for users who set scroll-conservatively
14772 to a large number: make sure the amount we scroll
14773 the window start is never less than amount_to_scroll,
14774 which was computed as distance from window bottom to
14775 point. This matters when lines at window top and lines
14776 below window bottom have different height. */
14778 void *it1data
= NULL
;
14779 /* We use a temporary it1 because line_bottom_y can modify
14780 its argument, if it moves one line down; see there. */
14783 SAVE_IT (it1
, it
, it1data
);
14784 start_y
= line_bottom_y (&it1
);
14786 RESTORE_IT (&it
, &it
, it1data
);
14787 move_it_by_lines (&it
, 1);
14788 SAVE_IT (it1
, it
, it1data
);
14789 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14792 /* If STARTP is unchanged, move it down another screen line. */
14793 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14794 move_it_by_lines (&it
, 1);
14795 startp
= it
.current
.pos
;
14799 struct text_pos scroll_margin_pos
= startp
;
14801 /* See if point is inside the scroll margin at the top of the
14803 if (this_scroll_margin
)
14805 start_display (&it
, w
, startp
);
14806 move_it_vertically (&it
, this_scroll_margin
);
14807 scroll_margin_pos
= it
.current
.pos
;
14810 if (PT
< CHARPOS (scroll_margin_pos
))
14812 /* Point is in the scroll margin at the top of the window or
14813 above what is displayed in the window. */
14816 /* Compute the vertical distance from PT to the scroll
14817 margin position. Move as far as scroll_max allows, or
14818 one screenful, or 10 screen lines, whichever is largest.
14819 Give up if distance is greater than scroll_max or if we
14820 didn't reach the scroll margin position. */
14821 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14822 start_display (&it
, w
, pos
);
14824 y_to_move
= max (it
.last_visible_y
,
14825 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14826 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14828 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14829 dy
= it
.current_y
- y0
;
14830 if (dy
> scroll_max
14831 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14832 return SCROLLING_FAILED
;
14834 /* Compute new window start. */
14835 start_display (&it
, w
, startp
);
14837 if (arg_scroll_conservatively
)
14838 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14839 max (scroll_step
, temp_scroll_step
));
14840 else if (scroll_step
|| temp_scroll_step
)
14841 amount_to_scroll
= scroll_max
;
14844 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14845 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14846 if (NUMBERP (aggressive
))
14848 double float_amount
= XFLOATINT (aggressive
) * height
;
14849 int aggressive_scroll
= float_amount
;
14850 if (aggressive_scroll
== 0 && float_amount
> 0)
14851 aggressive_scroll
= 1;
14852 /* Don't let point enter the scroll margin near
14853 bottom of the window, if the value of
14854 scroll_down_aggressively happens to be too
14856 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14857 aggressive_scroll
= height
- 2*this_scroll_margin
;
14858 amount_to_scroll
= dy
+ aggressive_scroll
;
14862 if (amount_to_scroll
<= 0)
14863 return SCROLLING_FAILED
;
14865 move_it_vertically_backward (&it
, amount_to_scroll
);
14866 startp
= it
.current
.pos
;
14870 /* Run window scroll functions. */
14871 startp
= run_window_scroll_functions (window
, startp
);
14873 /* Display the window. Give up if new fonts are loaded, or if point
14875 if (!try_window (window
, startp
, 0))
14876 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14877 else if (w
->cursor
.vpos
< 0)
14879 clear_glyph_matrix (w
->desired_matrix
);
14880 rc
= SCROLLING_FAILED
;
14884 /* Maybe forget recorded base line for line number display. */
14885 if (!just_this_one_p
14886 || current_buffer
->clip_changed
14887 || BEG_UNCHANGED
< CHARPOS (startp
))
14888 wset_base_line_number (w
, Qnil
);
14890 /* If cursor ends up on a partially visible line,
14891 treat that as being off the bottom of the screen. */
14892 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14893 /* It's possible that the cursor is on the first line of the
14894 buffer, which is partially obscured due to a vscroll
14895 (Bug#7537). In that case, avoid looping forever . */
14896 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14898 clear_glyph_matrix (w
->desired_matrix
);
14899 ++extra_scroll_margin_lines
;
14902 rc
= SCROLLING_SUCCESS
;
14909 /* Compute a suitable window start for window W if display of W starts
14910 on a continuation line. Value is non-zero if a new window start
14913 The new window start will be computed, based on W's width, starting
14914 from the start of the continued line. It is the start of the
14915 screen line with the minimum distance from the old start W->start. */
14918 compute_window_start_on_continuation_line (struct window
*w
)
14920 struct text_pos pos
, start_pos
;
14921 int window_start_changed_p
= 0;
14923 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14925 /* If window start is on a continuation line... Window start may be
14926 < BEGV in case there's invisible text at the start of the
14927 buffer (M-x rmail, for example). */
14928 if (CHARPOS (start_pos
) > BEGV
14929 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14932 struct glyph_row
*row
;
14934 /* Handle the case that the window start is out of range. */
14935 if (CHARPOS (start_pos
) < BEGV
)
14936 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14937 else if (CHARPOS (start_pos
) > ZV
)
14938 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14940 /* Find the start of the continued line. This should be fast
14941 because scan_buffer is fast (newline cache). */
14942 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14943 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14944 row
, DEFAULT_FACE_ID
);
14945 reseat_at_previous_visible_line_start (&it
);
14947 /* If the line start is "too far" away from the window start,
14948 say it takes too much time to compute a new window start. */
14949 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14950 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14952 int min_distance
, distance
;
14954 /* Move forward by display lines to find the new window
14955 start. If window width was enlarged, the new start can
14956 be expected to be > the old start. If window width was
14957 decreased, the new window start will be < the old start.
14958 So, we're looking for the display line start with the
14959 minimum distance from the old window start. */
14960 pos
= it
.current
.pos
;
14961 min_distance
= INFINITY
;
14962 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14963 distance
< min_distance
)
14965 min_distance
= distance
;
14966 pos
= it
.current
.pos
;
14967 move_it_by_lines (&it
, 1);
14970 /* Set the window start there. */
14971 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14972 window_start_changed_p
= 1;
14976 return window_start_changed_p
;
14980 /* Try cursor movement in case text has not changed in window WINDOW,
14981 with window start STARTP. Value is
14983 CURSOR_MOVEMENT_SUCCESS if successful
14985 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14987 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14988 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14989 we want to scroll as if scroll-step were set to 1. See the code.
14991 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14992 which case we have to abort this redisplay, and adjust matrices
14997 CURSOR_MOVEMENT_SUCCESS
,
14998 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14999 CURSOR_MOVEMENT_MUST_SCROLL
,
15000 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15004 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15006 struct window
*w
= XWINDOW (window
);
15007 struct frame
*f
= XFRAME (w
->frame
);
15008 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15011 if (inhibit_try_cursor_movement
)
15015 /* Previously, there was a check for Lisp integer in the
15016 if-statement below. Now, this field is converted to
15017 ptrdiff_t, thus zero means invalid position in a buffer. */
15018 eassert (w
->last_point
> 0);
15020 /* Handle case where text has not changed, only point, and it has
15021 not moved off the frame. */
15022 if (/* Point may be in this window. */
15023 PT
>= CHARPOS (startp
)
15024 /* Selective display hasn't changed. */
15025 && !current_buffer
->clip_changed
15026 /* Function force-mode-line-update is used to force a thorough
15027 redisplay. It sets either windows_or_buffers_changed or
15028 update_mode_lines. So don't take a shortcut here for these
15030 && !update_mode_lines
15031 && !windows_or_buffers_changed
15032 && !cursor_type_changed
15033 /* Can't use this case if highlighting a region. When a
15034 region exists, cursor movement has to do more than just
15036 && markpos_of_region () < 0
15037 && NILP (w
->region_showing
)
15038 && NILP (Vshow_trailing_whitespace
)
15039 /* This code is not used for mini-buffer for the sake of the case
15040 of redisplaying to replace an echo area message; since in
15041 that case the mini-buffer contents per se are usually
15042 unchanged. This code is of no real use in the mini-buffer
15043 since the handling of this_line_start_pos, etc., in redisplay
15044 handles the same cases. */
15045 && !EQ (window
, minibuf_window
)
15046 /* When splitting windows or for new windows, it happens that
15047 redisplay is called with a nil window_end_vpos or one being
15048 larger than the window. This should really be fixed in
15049 window.c. I don't have this on my list, now, so we do
15050 approximately the same as the old redisplay code. --gerd. */
15051 && INTEGERP (w
->window_end_vpos
)
15052 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
15053 && (FRAME_WINDOW_P (f
)
15054 || !overlay_arrow_in_current_buffer_p ()))
15056 int this_scroll_margin
, top_scroll_margin
;
15057 struct glyph_row
*row
= NULL
;
15060 debug_method_add (w
, "cursor movement");
15063 /* Scroll if point within this distance from the top or bottom
15064 of the window. This is a pixel value. */
15065 if (scroll_margin
> 0)
15067 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15068 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15071 this_scroll_margin
= 0;
15073 top_scroll_margin
= this_scroll_margin
;
15074 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15075 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15077 /* Start with the row the cursor was displayed during the last
15078 not paused redisplay. Give up if that row is not valid. */
15079 if (w
->last_cursor
.vpos
< 0
15080 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15081 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15084 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15085 if (row
->mode_line_p
)
15087 if (!row
->enabled_p
)
15088 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15091 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15093 int scroll_p
= 0, must_scroll
= 0;
15094 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15096 if (PT
> w
->last_point
)
15098 /* Point has moved forward. */
15099 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15100 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15102 eassert (row
->enabled_p
);
15106 /* If the end position of a row equals the start
15107 position of the next row, and PT is at that position,
15108 we would rather display cursor in the next line. */
15109 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15110 && MATRIX_ROW_END_CHARPOS (row
) == PT
15111 && row
< w
->current_matrix
->rows
15112 + w
->current_matrix
->nrows
- 1
15113 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15114 && !cursor_row_p (row
))
15117 /* If within the scroll margin, scroll. Note that
15118 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15119 the next line would be drawn, and that
15120 this_scroll_margin can be zero. */
15121 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15122 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15123 /* Line is completely visible last line in window
15124 and PT is to be set in the next line. */
15125 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15126 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15127 && !row
->ends_at_zv_p
15128 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15131 else if (PT
< w
->last_point
)
15133 /* Cursor has to be moved backward. Note that PT >=
15134 CHARPOS (startp) because of the outer if-statement. */
15135 while (!row
->mode_line_p
15136 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15137 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15138 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15139 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15140 row
> w
->current_matrix
->rows
15141 && (row
-1)->ends_in_newline_from_string_p
))))
15142 && (row
->y
> top_scroll_margin
15143 || CHARPOS (startp
) == BEGV
))
15145 eassert (row
->enabled_p
);
15149 /* Consider the following case: Window starts at BEGV,
15150 there is invisible, intangible text at BEGV, so that
15151 display starts at some point START > BEGV. It can
15152 happen that we are called with PT somewhere between
15153 BEGV and START. Try to handle that case. */
15154 if (row
< w
->current_matrix
->rows
15155 || row
->mode_line_p
)
15157 row
= w
->current_matrix
->rows
;
15158 if (row
->mode_line_p
)
15162 /* Due to newlines in overlay strings, we may have to
15163 skip forward over overlay strings. */
15164 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15165 && MATRIX_ROW_END_CHARPOS (row
) == PT
15166 && !cursor_row_p (row
))
15169 /* If within the scroll margin, scroll. */
15170 if (row
->y
< top_scroll_margin
15171 && CHARPOS (startp
) != BEGV
)
15176 /* Cursor did not move. So don't scroll even if cursor line
15177 is partially visible, as it was so before. */
15178 rc
= CURSOR_MOVEMENT_SUCCESS
;
15181 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15182 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15184 /* if PT is not in the glyph row, give up. */
15185 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15188 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15189 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15191 struct glyph_row
*row1
;
15193 /* If rows are bidi-reordered and point moved, back up
15194 until we find a row that does not belong to a
15195 continuation line. This is because we must consider
15196 all rows of a continued line as candidates for the
15197 new cursor positioning, since row start and end
15198 positions change non-linearly with vertical position
15200 /* FIXME: Revisit this when glyph ``spilling'' in
15201 continuation lines' rows is implemented for
15202 bidi-reordered rows. */
15203 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15204 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15207 /* If we hit the beginning of the displayed portion
15208 without finding the first row of a continued
15212 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15215 eassert (row
->enabled_p
);
15220 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15221 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15222 /* Make sure this isn't a header line by any chance, since
15223 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15224 && !row
->mode_line_p
15225 && make_cursor_line_fully_visible_p
)
15227 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15228 && !row
->ends_at_zv_p
15229 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15230 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15231 else if (row
->height
> window_box_height (w
))
15233 /* If we end up in a partially visible line, let's
15234 make it fully visible, except when it's taller
15235 than the window, in which case we can't do much
15238 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15242 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15243 if (!cursor_row_fully_visible_p (w
, 0, 1))
15244 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15246 rc
= CURSOR_MOVEMENT_SUCCESS
;
15250 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15251 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15252 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15254 /* With bidi-reordered rows, there could be more than
15255 one candidate row whose start and end positions
15256 occlude point. We need to let set_cursor_from_row
15257 find the best candidate. */
15258 /* FIXME: Revisit this when glyph ``spilling'' in
15259 continuation lines' rows is implemented for
15260 bidi-reordered rows. */
15265 int at_zv_p
= 0, exact_match_p
= 0;
15267 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15268 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15269 && cursor_row_p (row
))
15270 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15272 /* As soon as we've found the exact match for point,
15273 or the first suitable row whose ends_at_zv_p flag
15274 is set, we are done. */
15276 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15278 && w
->cursor
.hpos
>= 0
15279 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15282 struct glyph_row
*candidate
=
15283 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15285 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15286 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15289 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15290 || (INTEGERP (g
->object
)
15291 && (g
->charpos
== PT
15292 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15294 if (rv
&& (at_zv_p
|| exact_match_p
))
15296 rc
= CURSOR_MOVEMENT_SUCCESS
;
15299 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15303 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15304 || row
->continued_p
)
15305 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15306 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15307 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15308 /* If we didn't find any candidate rows, or exited the
15309 loop before all the candidates were examined, signal
15310 to the caller that this method failed. */
15311 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15313 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15314 && !row
->continued_p
))
15315 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15317 rc
= CURSOR_MOVEMENT_SUCCESS
;
15323 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15325 rc
= CURSOR_MOVEMENT_SUCCESS
;
15330 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15331 && MATRIX_ROW_START_CHARPOS (row
) == PT
15332 && cursor_row_p (row
));
15340 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15344 set_vertical_scroll_bar (struct window
*w
)
15346 ptrdiff_t start
, end
, whole
;
15348 /* Calculate the start and end positions for the current window.
15349 At some point, it would be nice to choose between scrollbars
15350 which reflect the whole buffer size, with special markers
15351 indicating narrowing, and scrollbars which reflect only the
15354 Note that mini-buffers sometimes aren't displaying any text. */
15355 if (!MINI_WINDOW_P (w
)
15356 || (w
== XWINDOW (minibuf_window
)
15357 && NILP (echo_area_buffer
[0])))
15359 struct buffer
*buf
= XBUFFER (w
->buffer
);
15360 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15361 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15362 /* I don't think this is guaranteed to be right. For the
15363 moment, we'll pretend it is. */
15364 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15368 if (whole
< (end
- start
))
15369 whole
= end
- start
;
15372 start
= end
= whole
= 0;
15374 /* Indicate what this scroll bar ought to be displaying now. */
15375 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15376 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15377 (w
, end
- start
, whole
, start
);
15381 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15382 selected_window is redisplayed.
15384 We can return without actually redisplaying the window if
15385 fonts_changed_p. In that case, redisplay_internal will
15389 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15391 struct window
*w
= XWINDOW (window
);
15392 struct frame
*f
= XFRAME (w
->frame
);
15393 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15394 struct buffer
*old
= current_buffer
;
15395 struct text_pos lpoint
, opoint
, startp
;
15396 int update_mode_line
;
15399 /* Record it now because it's overwritten. */
15400 int current_matrix_up_to_date_p
= 0;
15401 int used_current_matrix_p
= 0;
15402 /* This is less strict than current_matrix_up_to_date_p.
15403 It indicates that the buffer contents and narrowing are unchanged. */
15404 int buffer_unchanged_p
= 0;
15405 int temp_scroll_step
= 0;
15406 ptrdiff_t count
= SPECPDL_INDEX ();
15408 int centering_position
= -1;
15409 int last_line_misfit
= 0;
15410 ptrdiff_t beg_unchanged
, end_unchanged
;
15412 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15415 /* W must be a leaf window here. */
15416 eassert (!NILP (w
->buffer
));
15418 *w
->desired_matrix
->method
= 0;
15422 reconsider_clip_changes (w
, buffer
);
15424 /* Has the mode line to be updated? */
15425 update_mode_line
= (w
->update_mode_line
15426 || update_mode_lines
15427 || buffer
->clip_changed
15428 || buffer
->prevent_redisplay_optimizations_p
);
15430 if (MINI_WINDOW_P (w
))
15432 if (w
== XWINDOW (echo_area_window
)
15433 && !NILP (echo_area_buffer
[0]))
15435 if (update_mode_line
)
15436 /* We may have to update a tty frame's menu bar or a
15437 tool-bar. Example `M-x C-h C-h C-g'. */
15438 goto finish_menu_bars
;
15440 /* We've already displayed the echo area glyphs in this window. */
15441 goto finish_scroll_bars
;
15443 else if ((w
!= XWINDOW (minibuf_window
)
15444 || minibuf_level
== 0)
15445 /* When buffer is nonempty, redisplay window normally. */
15446 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15447 /* Quail displays non-mini buffers in minibuffer window.
15448 In that case, redisplay the window normally. */
15449 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15451 /* W is a mini-buffer window, but it's not active, so clear
15453 int yb
= window_text_bottom_y (w
);
15454 struct glyph_row
*row
;
15457 for (y
= 0, row
= w
->desired_matrix
->rows
;
15459 y
+= row
->height
, ++row
)
15460 blank_row (w
, row
, y
);
15461 goto finish_scroll_bars
;
15464 clear_glyph_matrix (w
->desired_matrix
);
15467 /* Otherwise set up data on this window; select its buffer and point
15469 /* Really select the buffer, for the sake of buffer-local
15471 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15473 current_matrix_up_to_date_p
15474 = (!NILP (w
->window_end_valid
)
15475 && !current_buffer
->clip_changed
15476 && !current_buffer
->prevent_redisplay_optimizations_p
15477 && !window_outdated (w
));
15479 /* Run the window-bottom-change-functions
15480 if it is possible that the text on the screen has changed
15481 (either due to modification of the text, or any other reason). */
15482 if (!current_matrix_up_to_date_p
15483 && !NILP (Vwindow_text_change_functions
))
15485 safe_run_hooks (Qwindow_text_change_functions
);
15489 beg_unchanged
= BEG_UNCHANGED
;
15490 end_unchanged
= END_UNCHANGED
;
15492 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15494 specbind (Qinhibit_point_motion_hooks
, Qt
);
15497 = (!NILP (w
->window_end_valid
)
15498 && !current_buffer
->clip_changed
15499 && !window_outdated (w
));
15501 /* When windows_or_buffers_changed is non-zero, we can't rely on
15502 the window end being valid, so set it to nil there. */
15503 if (windows_or_buffers_changed
)
15505 /* If window starts on a continuation line, maybe adjust the
15506 window start in case the window's width changed. */
15507 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15508 compute_window_start_on_continuation_line (w
);
15510 wset_window_end_valid (w
, Qnil
);
15513 /* Some sanity checks. */
15514 CHECK_WINDOW_END (w
);
15515 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15517 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15520 if (mode_line_update_needed (w
))
15521 update_mode_line
= 1;
15523 /* Point refers normally to the selected window. For any other
15524 window, set up appropriate value. */
15525 if (!EQ (window
, selected_window
))
15527 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15528 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15532 new_pt_byte
= BEGV_BYTE
;
15533 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15535 else if (new_pt
> (ZV
- 1))
15538 new_pt_byte
= ZV_BYTE
;
15539 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15542 /* We don't use SET_PT so that the point-motion hooks don't run. */
15543 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15546 /* If any of the character widths specified in the display table
15547 have changed, invalidate the width run cache. It's true that
15548 this may be a bit late to catch such changes, but the rest of
15549 redisplay goes (non-fatally) haywire when the display table is
15550 changed, so why should we worry about doing any better? */
15551 if (current_buffer
->width_run_cache
)
15553 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15555 if (! disptab_matches_widthtab
15556 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15558 invalidate_region_cache (current_buffer
,
15559 current_buffer
->width_run_cache
,
15561 recompute_width_table (current_buffer
, disptab
);
15565 /* If window-start is screwed up, choose a new one. */
15566 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15569 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15571 /* If someone specified a new starting point but did not insist,
15572 check whether it can be used. */
15573 if (w
->optional_new_start
15574 && CHARPOS (startp
) >= BEGV
15575 && CHARPOS (startp
) <= ZV
)
15577 w
->optional_new_start
= 0;
15578 start_display (&it
, w
, startp
);
15579 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15580 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15581 if (IT_CHARPOS (it
) == PT
)
15582 w
->force_start
= 1;
15583 /* IT may overshoot PT if text at PT is invisible. */
15584 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15585 w
->force_start
= 1;
15590 /* Handle case where place to start displaying has been specified,
15591 unless the specified location is outside the accessible range. */
15592 if (w
->force_start
|| w
->frozen_window_start_p
)
15594 /* We set this later on if we have to adjust point. */
15597 w
->force_start
= 0;
15599 wset_window_end_valid (w
, Qnil
);
15601 /* Forget any recorded base line for line number display. */
15602 if (!buffer_unchanged_p
)
15603 wset_base_line_number (w
, Qnil
);
15605 /* Redisplay the mode line. Select the buffer properly for that.
15606 Also, run the hook window-scroll-functions
15607 because we have scrolled. */
15608 /* Note, we do this after clearing force_start because
15609 if there's an error, it is better to forget about force_start
15610 than to get into an infinite loop calling the hook functions
15611 and having them get more errors. */
15612 if (!update_mode_line
15613 || ! NILP (Vwindow_scroll_functions
))
15615 update_mode_line
= 1;
15616 w
->update_mode_line
= 1;
15617 startp
= run_window_scroll_functions (window
, startp
);
15620 w
->last_modified
= 0;
15621 w
->last_overlay_modified
= 0;
15622 if (CHARPOS (startp
) < BEGV
)
15623 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15624 else if (CHARPOS (startp
) > ZV
)
15625 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15627 /* Redisplay, then check if cursor has been set during the
15628 redisplay. Give up if new fonts were loaded. */
15629 /* We used to issue a CHECK_MARGINS argument to try_window here,
15630 but this causes scrolling to fail when point begins inside
15631 the scroll margin (bug#148) -- cyd */
15632 if (!try_window (window
, startp
, 0))
15634 w
->force_start
= 1;
15635 clear_glyph_matrix (w
->desired_matrix
);
15636 goto need_larger_matrices
;
15639 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15641 /* If point does not appear, try to move point so it does
15642 appear. The desired matrix has been built above, so we
15643 can use it here. */
15644 new_vpos
= window_box_height (w
) / 2;
15647 if (!cursor_row_fully_visible_p (w
, 0, 0))
15649 /* Point does appear, but on a line partly visible at end of window.
15650 Move it back to a fully-visible line. */
15651 new_vpos
= window_box_height (w
);
15653 else if (w
->cursor
.vpos
>=0)
15655 /* Some people insist on not letting point enter the scroll
15656 margin, even though this part handles windows that didn't
15658 int margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15659 int pixel_margin
= margin
* FRAME_LINE_HEIGHT (f
);
15660 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15662 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15663 below, which finds the row to move point to, advances by
15664 the Y coordinate of the _next_ row, see the definition of
15665 MATRIX_ROW_BOTTOM_Y. */
15666 if (w
->cursor
.vpos
< margin
+ header_line
)
15668 = pixel_margin
+ (header_line
15669 ? CURRENT_HEADER_LINE_HEIGHT (w
)
15670 : 0) + FRAME_LINE_HEIGHT (f
);
15673 int window_height
= window_box_height (w
);
15676 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15677 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15678 new_vpos
= window_height
- pixel_margin
;
15682 /* If we need to move point for either of the above reasons,
15683 now actually do it. */
15686 struct glyph_row
*row
;
15688 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15689 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15692 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15693 MATRIX_ROW_START_BYTEPOS (row
));
15695 if (w
!= XWINDOW (selected_window
))
15696 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15697 else if (current_buffer
== old
)
15698 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15700 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15702 /* If we are highlighting the region, then we just changed
15703 the region, so redisplay to show it. */
15704 if (0 <= markpos_of_region ())
15706 clear_glyph_matrix (w
->desired_matrix
);
15707 if (!try_window (window
, startp
, 0))
15708 goto need_larger_matrices
;
15713 debug_method_add (w
, "forced window start");
15718 /* Handle case where text has not changed, only point, and it has
15719 not moved off the frame, and we are not retrying after hscroll.
15720 (current_matrix_up_to_date_p is nonzero when retrying.) */
15721 if (current_matrix_up_to_date_p
15722 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15723 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15727 case CURSOR_MOVEMENT_SUCCESS
:
15728 used_current_matrix_p
= 1;
15731 case CURSOR_MOVEMENT_MUST_SCROLL
:
15732 goto try_to_scroll
;
15738 /* If current starting point was originally the beginning of a line
15739 but no longer is, find a new starting point. */
15740 else if (w
->start_at_line_beg
15741 && !(CHARPOS (startp
) <= BEGV
15742 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15745 debug_method_add (w
, "recenter 1");
15750 /* Try scrolling with try_window_id. Value is > 0 if update has
15751 been done, it is -1 if we know that the same window start will
15752 not work. It is 0 if unsuccessful for some other reason. */
15753 else if ((tem
= try_window_id (w
)) != 0)
15756 debug_method_add (w
, "try_window_id %d", tem
);
15759 if (fonts_changed_p
)
15760 goto need_larger_matrices
;
15764 /* Otherwise try_window_id has returned -1 which means that we
15765 don't want the alternative below this comment to execute. */
15767 else if (CHARPOS (startp
) >= BEGV
15768 && CHARPOS (startp
) <= ZV
15769 && PT
>= CHARPOS (startp
)
15770 && (CHARPOS (startp
) < ZV
15771 /* Avoid starting at end of buffer. */
15772 || CHARPOS (startp
) == BEGV
15773 || !window_outdated (w
)))
15775 int d1
, d2
, d3
, d4
, d5
, d6
;
15777 /* If first window line is a continuation line, and window start
15778 is inside the modified region, but the first change is before
15779 current window start, we must select a new window start.
15781 However, if this is the result of a down-mouse event (e.g. by
15782 extending the mouse-drag-overlay), we don't want to select a
15783 new window start, since that would change the position under
15784 the mouse, resulting in an unwanted mouse-movement rather
15785 than a simple mouse-click. */
15786 if (!w
->start_at_line_beg
15787 && NILP (do_mouse_tracking
)
15788 && CHARPOS (startp
) > BEGV
15789 && CHARPOS (startp
) > BEG
+ beg_unchanged
15790 && CHARPOS (startp
) <= Z
- end_unchanged
15791 /* Even if w->start_at_line_beg is nil, a new window may
15792 start at a line_beg, since that's how set_buffer_window
15793 sets it. So, we need to check the return value of
15794 compute_window_start_on_continuation_line. (See also
15796 && XMARKER (w
->start
)->buffer
== current_buffer
15797 && compute_window_start_on_continuation_line (w
)
15798 /* It doesn't make sense to force the window start like we
15799 do at label force_start if it is already known that point
15800 will not be visible in the resulting window, because
15801 doing so will move point from its correct position
15802 instead of scrolling the window to bring point into view.
15804 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15806 w
->force_start
= 1;
15807 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15812 debug_method_add (w
, "same window start");
15815 /* Try to redisplay starting at same place as before.
15816 If point has not moved off frame, accept the results. */
15817 if (!current_matrix_up_to_date_p
15818 /* Don't use try_window_reusing_current_matrix in this case
15819 because a window scroll function can have changed the
15821 || !NILP (Vwindow_scroll_functions
)
15822 || MINI_WINDOW_P (w
)
15823 || !(used_current_matrix_p
15824 = try_window_reusing_current_matrix (w
)))
15826 IF_DEBUG (debug_method_add (w
, "1"));
15827 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15828 /* -1 means we need to scroll.
15829 0 means we need new matrices, but fonts_changed_p
15830 is set in that case, so we will detect it below. */
15831 goto try_to_scroll
;
15834 if (fonts_changed_p
)
15835 goto need_larger_matrices
;
15837 if (w
->cursor
.vpos
>= 0)
15839 if (!just_this_one_p
15840 || current_buffer
->clip_changed
15841 || BEG_UNCHANGED
< CHARPOS (startp
))
15842 /* Forget any recorded base line for line number display. */
15843 wset_base_line_number (w
, Qnil
);
15845 if (!cursor_row_fully_visible_p (w
, 1, 0))
15847 clear_glyph_matrix (w
->desired_matrix
);
15848 last_line_misfit
= 1;
15850 /* Drop through and scroll. */
15855 clear_glyph_matrix (w
->desired_matrix
);
15860 w
->last_modified
= 0;
15861 w
->last_overlay_modified
= 0;
15863 /* Redisplay the mode line. Select the buffer properly for that. */
15864 if (!update_mode_line
)
15866 update_mode_line
= 1;
15867 w
->update_mode_line
= 1;
15870 /* Try to scroll by specified few lines. */
15871 if ((scroll_conservatively
15872 || emacs_scroll_step
15873 || temp_scroll_step
15874 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15875 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15876 && CHARPOS (startp
) >= BEGV
15877 && CHARPOS (startp
) <= ZV
)
15879 /* The function returns -1 if new fonts were loaded, 1 if
15880 successful, 0 if not successful. */
15881 int ss
= try_scrolling (window
, just_this_one_p
,
15882 scroll_conservatively
,
15884 temp_scroll_step
, last_line_misfit
);
15887 case SCROLLING_SUCCESS
:
15890 case SCROLLING_NEED_LARGER_MATRICES
:
15891 goto need_larger_matrices
;
15893 case SCROLLING_FAILED
:
15901 /* Finally, just choose a place to start which positions point
15902 according to user preferences. */
15907 debug_method_add (w
, "recenter");
15910 /* w->vscroll = 0; */
15912 /* Forget any previously recorded base line for line number display. */
15913 if (!buffer_unchanged_p
)
15914 wset_base_line_number (w
, Qnil
);
15916 /* Determine the window start relative to point. */
15917 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15918 it
.current_y
= it
.last_visible_y
;
15919 if (centering_position
< 0)
15923 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15925 ptrdiff_t margin_pos
= CHARPOS (startp
);
15926 Lisp_Object aggressive
;
15929 /* If there is a scroll margin at the top of the window, find
15930 its character position. */
15932 /* Cannot call start_display if startp is not in the
15933 accessible region of the buffer. This can happen when we
15934 have just switched to a different buffer and/or changed
15935 its restriction. In that case, startp is initialized to
15936 the character position 1 (BEGV) because we did not yet
15937 have chance to display the buffer even once. */
15938 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15941 void *it1data
= NULL
;
15943 SAVE_IT (it1
, it
, it1data
);
15944 start_display (&it1
, w
, startp
);
15945 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15946 margin_pos
= IT_CHARPOS (it1
);
15947 RESTORE_IT (&it
, &it
, it1data
);
15949 scrolling_up
= PT
> margin_pos
;
15952 ? BVAR (current_buffer
, scroll_up_aggressively
)
15953 : BVAR (current_buffer
, scroll_down_aggressively
);
15955 if (!MINI_WINDOW_P (w
)
15956 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15960 /* Setting scroll-conservatively overrides
15961 scroll-*-aggressively. */
15962 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15964 double float_amount
= XFLOATINT (aggressive
);
15966 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15967 if (pt_offset
== 0 && float_amount
> 0)
15969 if (pt_offset
&& margin
> 0)
15972 /* Compute how much to move the window start backward from
15973 point so that point will be displayed where the user
15977 centering_position
= it
.last_visible_y
;
15979 centering_position
-= pt_offset
;
15980 centering_position
-=
15981 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
15982 + WINDOW_HEADER_LINE_HEIGHT (w
);
15983 /* Don't let point enter the scroll margin near top of
15985 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
15986 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
15989 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
15992 /* Set the window start half the height of the window backward
15994 centering_position
= window_box_height (w
) / 2;
15996 move_it_vertically_backward (&it
, centering_position
);
15998 eassert (IT_CHARPOS (it
) >= BEGV
);
16000 /* The function move_it_vertically_backward may move over more
16001 than the specified y-distance. If it->w is small, e.g. a
16002 mini-buffer window, we may end up in front of the window's
16003 display area. Start displaying at the start of the line
16004 containing PT in this case. */
16005 if (it
.current_y
<= 0)
16007 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16008 move_it_vertically_backward (&it
, 0);
16012 it
.current_x
= it
.hpos
= 0;
16014 /* Set the window start position here explicitly, to avoid an
16015 infinite loop in case the functions in window-scroll-functions
16017 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16019 /* Run scroll hooks. */
16020 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16022 /* Redisplay the window. */
16023 if (!current_matrix_up_to_date_p
16024 || windows_or_buffers_changed
16025 || cursor_type_changed
16026 /* Don't use try_window_reusing_current_matrix in this case
16027 because it can have changed the buffer. */
16028 || !NILP (Vwindow_scroll_functions
)
16029 || !just_this_one_p
16030 || MINI_WINDOW_P (w
)
16031 || !(used_current_matrix_p
16032 = try_window_reusing_current_matrix (w
)))
16033 try_window (window
, startp
, 0);
16035 /* If new fonts have been loaded (due to fontsets), give up. We
16036 have to start a new redisplay since we need to re-adjust glyph
16038 if (fonts_changed_p
)
16039 goto need_larger_matrices
;
16041 /* If cursor did not appear assume that the middle of the window is
16042 in the first line of the window. Do it again with the next line.
16043 (Imagine a window of height 100, displaying two lines of height
16044 60. Moving back 50 from it->last_visible_y will end in the first
16046 if (w
->cursor
.vpos
< 0)
16048 if (!NILP (w
->window_end_valid
)
16049 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
16051 clear_glyph_matrix (w
->desired_matrix
);
16052 move_it_by_lines (&it
, 1);
16053 try_window (window
, it
.current
.pos
, 0);
16055 else if (PT
< IT_CHARPOS (it
))
16057 clear_glyph_matrix (w
->desired_matrix
);
16058 move_it_by_lines (&it
, -1);
16059 try_window (window
, it
.current
.pos
, 0);
16063 /* Not much we can do about it. */
16067 /* Consider the following case: Window starts at BEGV, there is
16068 invisible, intangible text at BEGV, so that display starts at
16069 some point START > BEGV. It can happen that we are called with
16070 PT somewhere between BEGV and START. Try to handle that case. */
16071 if (w
->cursor
.vpos
< 0)
16073 struct glyph_row
*row
= w
->current_matrix
->rows
;
16074 if (row
->mode_line_p
)
16076 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16079 if (!cursor_row_fully_visible_p (w
, 0, 0))
16081 /* If vscroll is enabled, disable it and try again. */
16085 clear_glyph_matrix (w
->desired_matrix
);
16089 /* Users who set scroll-conservatively to a large number want
16090 point just above/below the scroll margin. If we ended up
16091 with point's row partially visible, move the window start to
16092 make that row fully visible and out of the margin. */
16093 if (scroll_conservatively
> SCROLL_LIMIT
)
16097 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16099 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
16101 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16102 clear_glyph_matrix (w
->desired_matrix
);
16103 if (1 == try_window (window
, it
.current
.pos
,
16104 TRY_WINDOW_CHECK_MARGINS
))
16108 /* If centering point failed to make the whole line visible,
16109 put point at the top instead. That has to make the whole line
16110 visible, if it can be done. */
16111 if (centering_position
== 0)
16114 clear_glyph_matrix (w
->desired_matrix
);
16115 centering_position
= 0;
16121 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16122 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16123 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16125 /* Display the mode line, if we must. */
16126 if ((update_mode_line
16127 /* If window not full width, must redo its mode line
16128 if (a) the window to its side is being redone and
16129 (b) we do a frame-based redisplay. This is a consequence
16130 of how inverted lines are drawn in frame-based redisplay. */
16131 || (!just_this_one_p
16132 && !FRAME_WINDOW_P (f
)
16133 && !WINDOW_FULL_WIDTH_P (w
))
16134 /* Line number to display. */
16135 || INTEGERP (w
->base_line_pos
)
16136 /* Column number is displayed and different from the one displayed. */
16137 || (!NILP (w
->column_number_displayed
)
16138 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
16139 /* This means that the window has a mode line. */
16140 && (WINDOW_WANTS_MODELINE_P (w
)
16141 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16143 display_mode_lines (w
);
16145 /* If mode line height has changed, arrange for a thorough
16146 immediate redisplay using the correct mode line height. */
16147 if (WINDOW_WANTS_MODELINE_P (w
)
16148 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16150 fonts_changed_p
= 1;
16151 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16152 = DESIRED_MODE_LINE_HEIGHT (w
);
16155 /* If header line height has changed, arrange for a thorough
16156 immediate redisplay using the correct header line height. */
16157 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16158 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16160 fonts_changed_p
= 1;
16161 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16162 = DESIRED_HEADER_LINE_HEIGHT (w
);
16165 if (fonts_changed_p
)
16166 goto need_larger_matrices
;
16169 if (!line_number_displayed
16170 && !BUFFERP (w
->base_line_pos
))
16172 wset_base_line_pos (w
, Qnil
);
16173 wset_base_line_number (w
, Qnil
);
16178 /* When we reach a frame's selected window, redo the frame's menu bar. */
16179 if (update_mode_line
16180 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16182 int redisplay_menu_p
= 0;
16184 if (FRAME_WINDOW_P (f
))
16186 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16187 || defined (HAVE_NS) || defined (USE_GTK)
16188 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16190 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16194 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16196 if (redisplay_menu_p
)
16197 display_menu_bar (w
);
16199 #ifdef HAVE_WINDOW_SYSTEM
16200 if (FRAME_WINDOW_P (f
))
16202 #if defined (USE_GTK) || defined (HAVE_NS)
16203 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16204 redisplay_tool_bar (f
);
16206 if (WINDOWP (f
->tool_bar_window
)
16207 && (FRAME_TOOL_BAR_LINES (f
) > 0
16208 || !NILP (Vauto_resize_tool_bars
))
16209 && redisplay_tool_bar (f
))
16210 ignore_mouse_drag_p
= 1;
16216 #ifdef HAVE_WINDOW_SYSTEM
16217 if (FRAME_WINDOW_P (f
)
16218 && update_window_fringes (w
, (just_this_one_p
16219 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16220 || w
->pseudo_window_p
)))
16224 if (draw_window_fringes (w
, 1))
16225 x_draw_vertical_border (w
);
16229 #endif /* HAVE_WINDOW_SYSTEM */
16231 /* We go to this label, with fonts_changed_p set,
16232 if it is necessary to try again using larger glyph matrices.
16233 We have to redeem the scroll bar even in this case,
16234 because the loop in redisplay_internal expects that. */
16235 need_larger_matrices
:
16237 finish_scroll_bars
:
16239 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16241 /* Set the thumb's position and size. */
16242 set_vertical_scroll_bar (w
);
16244 /* Note that we actually used the scroll bar attached to this
16245 window, so it shouldn't be deleted at the end of redisplay. */
16246 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16247 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16250 /* Restore current_buffer and value of point in it. The window
16251 update may have changed the buffer, so first make sure `opoint'
16252 is still valid (Bug#6177). */
16253 if (CHARPOS (opoint
) < BEGV
)
16254 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16255 else if (CHARPOS (opoint
) > ZV
)
16256 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16258 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16260 set_buffer_internal_1 (old
);
16261 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16262 shorter. This can be caused by log truncation in *Messages*. */
16263 if (CHARPOS (lpoint
) <= ZV
)
16264 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16266 unbind_to (count
, Qnil
);
16270 /* Build the complete desired matrix of WINDOW with a window start
16271 buffer position POS.
16273 Value is 1 if successful. It is zero if fonts were loaded during
16274 redisplay which makes re-adjusting glyph matrices necessary, and -1
16275 if point would appear in the scroll margins.
16276 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16277 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16281 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16283 struct window
*w
= XWINDOW (window
);
16285 struct glyph_row
*last_text_row
= NULL
;
16286 struct frame
*f
= XFRAME (w
->frame
);
16288 /* Make POS the new window start. */
16289 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16291 /* Mark cursor position as unknown. No overlay arrow seen. */
16292 w
->cursor
.vpos
= -1;
16293 overlay_arrow_seen
= 0;
16295 /* Initialize iterator and info to start at POS. */
16296 start_display (&it
, w
, pos
);
16298 /* Display all lines of W. */
16299 while (it
.current_y
< it
.last_visible_y
)
16301 if (display_line (&it
))
16302 last_text_row
= it
.glyph_row
- 1;
16303 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16307 /* Don't let the cursor end in the scroll margins. */
16308 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16309 && !MINI_WINDOW_P (w
))
16311 int this_scroll_margin
;
16313 if (scroll_margin
> 0)
16315 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16316 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16319 this_scroll_margin
= 0;
16321 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16322 && w
->cursor
.y
< this_scroll_margin
16323 && CHARPOS (pos
) > BEGV
16324 && IT_CHARPOS (it
) < ZV
)
16325 /* rms: considering make_cursor_line_fully_visible_p here
16326 seems to give wrong results. We don't want to recenter
16327 when the last line is partly visible, we want to allow
16328 that case to be handled in the usual way. */
16329 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16331 w
->cursor
.vpos
= -1;
16332 clear_glyph_matrix (w
->desired_matrix
);
16337 /* If bottom moved off end of frame, change mode line percentage. */
16338 if (XFASTINT (w
->window_end_pos
) <= 0
16339 && Z
!= IT_CHARPOS (it
))
16340 w
->update_mode_line
= 1;
16342 /* Set window_end_pos to the offset of the last character displayed
16343 on the window from the end of current_buffer. Set
16344 window_end_vpos to its row number. */
16347 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16348 w
->window_end_bytepos
16349 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16350 wset_window_end_pos
16351 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16352 wset_window_end_vpos
16353 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16355 (MATRIX_ROW (w
->desired_matrix
,
16356 XFASTINT (w
->window_end_vpos
))->displays_text_p
);
16360 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16361 wset_window_end_pos (w
, make_number (Z
- ZV
));
16362 wset_window_end_vpos (w
, make_number (0));
16365 /* But that is not valid info until redisplay finishes. */
16366 wset_window_end_valid (w
, Qnil
);
16372 /************************************************************************
16373 Window redisplay reusing current matrix when buffer has not changed
16374 ************************************************************************/
16376 /* Try redisplay of window W showing an unchanged buffer with a
16377 different window start than the last time it was displayed by
16378 reusing its current matrix. Value is non-zero if successful.
16379 W->start is the new window start. */
16382 try_window_reusing_current_matrix (struct window
*w
)
16384 struct frame
*f
= XFRAME (w
->frame
);
16385 struct glyph_row
*bottom_row
;
16388 struct text_pos start
, new_start
;
16389 int nrows_scrolled
, i
;
16390 struct glyph_row
*last_text_row
;
16391 struct glyph_row
*last_reused_text_row
;
16392 struct glyph_row
*start_row
;
16393 int start_vpos
, min_y
, max_y
;
16396 if (inhibit_try_window_reusing
)
16400 if (/* This function doesn't handle terminal frames. */
16401 !FRAME_WINDOW_P (f
)
16402 /* Don't try to reuse the display if windows have been split
16404 || windows_or_buffers_changed
16405 || cursor_type_changed
)
16408 /* Can't do this if region may have changed. */
16409 if (0 <= markpos_of_region ()
16410 || !NILP (w
->region_showing
)
16411 || !NILP (Vshow_trailing_whitespace
))
16414 /* If top-line visibility has changed, give up. */
16415 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16416 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16419 /* Give up if old or new display is scrolled vertically. We could
16420 make this function handle this, but right now it doesn't. */
16421 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16422 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16425 /* The variable new_start now holds the new window start. The old
16426 start `start' can be determined from the current matrix. */
16427 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16428 start
= start_row
->minpos
;
16429 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16431 /* Clear the desired matrix for the display below. */
16432 clear_glyph_matrix (w
->desired_matrix
);
16434 if (CHARPOS (new_start
) <= CHARPOS (start
))
16436 /* Don't use this method if the display starts with an ellipsis
16437 displayed for invisible text. It's not easy to handle that case
16438 below, and it's certainly not worth the effort since this is
16439 not a frequent case. */
16440 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16443 IF_DEBUG (debug_method_add (w
, "twu1"));
16445 /* Display up to a row that can be reused. The variable
16446 last_text_row is set to the last row displayed that displays
16447 text. Note that it.vpos == 0 if or if not there is a
16448 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16449 start_display (&it
, w
, new_start
);
16450 w
->cursor
.vpos
= -1;
16451 last_text_row
= last_reused_text_row
= NULL
;
16453 while (it
.current_y
< it
.last_visible_y
16454 && !fonts_changed_p
)
16456 /* If we have reached into the characters in the START row,
16457 that means the line boundaries have changed. So we
16458 can't start copying with the row START. Maybe it will
16459 work to start copying with the following row. */
16460 while (IT_CHARPOS (it
) > CHARPOS (start
))
16462 /* Advance to the next row as the "start". */
16464 start
= start_row
->minpos
;
16465 /* If there are no more rows to try, or just one, give up. */
16466 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16467 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16468 || CHARPOS (start
) == ZV
)
16470 clear_glyph_matrix (w
->desired_matrix
);
16474 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16476 /* If we have reached alignment, we can copy the rest of the
16478 if (IT_CHARPOS (it
) == CHARPOS (start
)
16479 /* Don't accept "alignment" inside a display vector,
16480 since start_row could have started in the middle of
16481 that same display vector (thus their character
16482 positions match), and we have no way of telling if
16483 that is the case. */
16484 && it
.current
.dpvec_index
< 0)
16487 if (display_line (&it
))
16488 last_text_row
= it
.glyph_row
- 1;
16492 /* A value of current_y < last_visible_y means that we stopped
16493 at the previous window start, which in turn means that we
16494 have at least one reusable row. */
16495 if (it
.current_y
< it
.last_visible_y
)
16497 struct glyph_row
*row
;
16499 /* IT.vpos always starts from 0; it counts text lines. */
16500 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16502 /* Find PT if not already found in the lines displayed. */
16503 if (w
->cursor
.vpos
< 0)
16505 int dy
= it
.current_y
- start_row
->y
;
16507 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16508 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16510 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16511 dy
, nrows_scrolled
);
16514 clear_glyph_matrix (w
->desired_matrix
);
16519 /* Scroll the display. Do it before the current matrix is
16520 changed. The problem here is that update has not yet
16521 run, i.e. part of the current matrix is not up to date.
16522 scroll_run_hook will clear the cursor, and use the
16523 current matrix to get the height of the row the cursor is
16525 run
.current_y
= start_row
->y
;
16526 run
.desired_y
= it
.current_y
;
16527 run
.height
= it
.last_visible_y
- it
.current_y
;
16529 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16532 FRAME_RIF (f
)->update_window_begin_hook (w
);
16533 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16534 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16535 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16539 /* Shift current matrix down by nrows_scrolled lines. */
16540 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16541 rotate_matrix (w
->current_matrix
,
16543 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16546 /* Disable lines that must be updated. */
16547 for (i
= 0; i
< nrows_scrolled
; ++i
)
16548 (start_row
+ i
)->enabled_p
= 0;
16550 /* Re-compute Y positions. */
16551 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16552 max_y
= it
.last_visible_y
;
16553 for (row
= start_row
+ nrows_scrolled
;
16557 row
->y
= it
.current_y
;
16558 row
->visible_height
= row
->height
;
16560 if (row
->y
< min_y
)
16561 row
->visible_height
-= min_y
- row
->y
;
16562 if (row
->y
+ row
->height
> max_y
)
16563 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16564 if (row
->fringe_bitmap_periodic_p
)
16565 row
->redraw_fringe_bitmaps_p
= 1;
16567 it
.current_y
+= row
->height
;
16569 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16570 last_reused_text_row
= row
;
16571 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16575 /* Disable lines in the current matrix which are now
16576 below the window. */
16577 for (++row
; row
< bottom_row
; ++row
)
16578 row
->enabled_p
= row
->mode_line_p
= 0;
16581 /* Update window_end_pos etc.; last_reused_text_row is the last
16582 reused row from the current matrix containing text, if any.
16583 The value of last_text_row is the last displayed line
16584 containing text. */
16585 if (last_reused_text_row
)
16587 w
->window_end_bytepos
16588 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16589 wset_window_end_pos
16591 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16592 wset_window_end_vpos
16593 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16594 w
->current_matrix
)));
16596 else if (last_text_row
)
16598 w
->window_end_bytepos
16599 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16600 wset_window_end_pos
16601 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16602 wset_window_end_vpos
16603 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16604 w
->desired_matrix
)));
16608 /* This window must be completely empty. */
16609 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16610 wset_window_end_pos (w
, make_number (Z
- ZV
));
16611 wset_window_end_vpos (w
, make_number (0));
16613 wset_window_end_valid (w
, Qnil
);
16615 /* Update hint: don't try scrolling again in update_window. */
16616 w
->desired_matrix
->no_scrolling_p
= 1;
16619 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16623 else if (CHARPOS (new_start
) > CHARPOS (start
))
16625 struct glyph_row
*pt_row
, *row
;
16626 struct glyph_row
*first_reusable_row
;
16627 struct glyph_row
*first_row_to_display
;
16629 int yb
= window_text_bottom_y (w
);
16631 /* Find the row starting at new_start, if there is one. Don't
16632 reuse a partially visible line at the end. */
16633 first_reusable_row
= start_row
;
16634 while (first_reusable_row
->enabled_p
16635 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16636 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16637 < CHARPOS (new_start
)))
16638 ++first_reusable_row
;
16640 /* Give up if there is no row to reuse. */
16641 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16642 || !first_reusable_row
->enabled_p
16643 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16644 != CHARPOS (new_start
)))
16647 /* We can reuse fully visible rows beginning with
16648 first_reusable_row to the end of the window. Set
16649 first_row_to_display to the first row that cannot be reused.
16650 Set pt_row to the row containing point, if there is any. */
16652 for (first_row_to_display
= first_reusable_row
;
16653 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16654 ++first_row_to_display
)
16656 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16657 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16658 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16659 && first_row_to_display
->ends_at_zv_p
16660 && pt_row
== NULL
)))
16661 pt_row
= first_row_to_display
;
16664 /* Start displaying at the start of first_row_to_display. */
16665 eassert (first_row_to_display
->y
< yb
);
16666 init_to_row_start (&it
, w
, first_row_to_display
);
16668 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16670 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16672 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16673 + WINDOW_HEADER_LINE_HEIGHT (w
));
16675 /* Display lines beginning with first_row_to_display in the
16676 desired matrix. Set last_text_row to the last row displayed
16677 that displays text. */
16678 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16679 if (pt_row
== NULL
)
16680 w
->cursor
.vpos
= -1;
16681 last_text_row
= NULL
;
16682 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16683 if (display_line (&it
))
16684 last_text_row
= it
.glyph_row
- 1;
16686 /* If point is in a reused row, adjust y and vpos of the cursor
16690 w
->cursor
.vpos
-= nrows_scrolled
;
16691 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16694 /* Give up if point isn't in a row displayed or reused. (This
16695 also handles the case where w->cursor.vpos < nrows_scrolled
16696 after the calls to display_line, which can happen with scroll
16697 margins. See bug#1295.) */
16698 if (w
->cursor
.vpos
< 0)
16700 clear_glyph_matrix (w
->desired_matrix
);
16704 /* Scroll the display. */
16705 run
.current_y
= first_reusable_row
->y
;
16706 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16707 run
.height
= it
.last_visible_y
- run
.current_y
;
16708 dy
= run
.current_y
- run
.desired_y
;
16713 FRAME_RIF (f
)->update_window_begin_hook (w
);
16714 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16715 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16716 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16720 /* Adjust Y positions of reused rows. */
16721 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16722 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16723 max_y
= it
.last_visible_y
;
16724 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16727 row
->visible_height
= row
->height
;
16728 if (row
->y
< min_y
)
16729 row
->visible_height
-= min_y
- row
->y
;
16730 if (row
->y
+ row
->height
> max_y
)
16731 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16732 if (row
->fringe_bitmap_periodic_p
)
16733 row
->redraw_fringe_bitmaps_p
= 1;
16736 /* Scroll the current matrix. */
16737 eassert (nrows_scrolled
> 0);
16738 rotate_matrix (w
->current_matrix
,
16740 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16743 /* Disable rows not reused. */
16744 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16745 row
->enabled_p
= 0;
16747 /* Point may have moved to a different line, so we cannot assume that
16748 the previous cursor position is valid; locate the correct row. */
16751 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16753 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16754 && !row
->ends_at_zv_p
;
16758 w
->cursor
.y
= row
->y
;
16760 if (row
< bottom_row
)
16762 /* Can't simply scan the row for point with
16763 bidi-reordered glyph rows. Let set_cursor_from_row
16764 figure out where to put the cursor, and if it fails,
16766 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16768 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16771 clear_glyph_matrix (w
->desired_matrix
);
16777 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16778 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16781 && (!BUFFERP (glyph
->object
)
16782 || glyph
->charpos
< PT
);
16786 w
->cursor
.x
+= glyph
->pixel_width
;
16792 /* Adjust window end. A null value of last_text_row means that
16793 the window end is in reused rows which in turn means that
16794 only its vpos can have changed. */
16797 w
->window_end_bytepos
16798 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16799 wset_window_end_pos
16800 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16801 wset_window_end_vpos
16802 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16803 w
->desired_matrix
)));
16807 wset_window_end_vpos
16808 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16811 wset_window_end_valid (w
, Qnil
);
16812 w
->desired_matrix
->no_scrolling_p
= 1;
16815 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16825 /************************************************************************
16826 Window redisplay reusing current matrix when buffer has changed
16827 ************************************************************************/
16829 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16830 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16831 ptrdiff_t *, ptrdiff_t *);
16832 static struct glyph_row
*
16833 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16834 struct glyph_row
*);
16837 /* Return the last row in MATRIX displaying text. If row START is
16838 non-null, start searching with that row. IT gives the dimensions
16839 of the display. Value is null if matrix is empty; otherwise it is
16840 a pointer to the row found. */
16842 static struct glyph_row
*
16843 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16844 struct glyph_row
*start
)
16846 struct glyph_row
*row
, *row_found
;
16848 /* Set row_found to the last row in IT->w's current matrix
16849 displaying text. The loop looks funny but think of partially
16852 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16853 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16855 eassert (row
->enabled_p
);
16857 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16866 /* Return the last row in the current matrix of W that is not affected
16867 by changes at the start of current_buffer that occurred since W's
16868 current matrix was built. Value is null if no such row exists.
16870 BEG_UNCHANGED us the number of characters unchanged at the start of
16871 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16872 first changed character in current_buffer. Characters at positions <
16873 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16874 when the current matrix was built. */
16876 static struct glyph_row
*
16877 find_last_unchanged_at_beg_row (struct window
*w
)
16879 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16880 struct glyph_row
*row
;
16881 struct glyph_row
*row_found
= NULL
;
16882 int yb
= window_text_bottom_y (w
);
16884 /* Find the last row displaying unchanged text. */
16885 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16886 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16887 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16890 if (/* If row ends before first_changed_pos, it is unchanged,
16891 except in some case. */
16892 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16893 /* When row ends in ZV and we write at ZV it is not
16895 && !row
->ends_at_zv_p
16896 /* When first_changed_pos is the end of a continued line,
16897 row is not unchanged because it may be no longer
16899 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16900 && (row
->continued_p
16901 || row
->exact_window_width_line_p
))
16902 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16903 needs to be recomputed, so don't consider this row as
16904 unchanged. This happens when the last line was
16905 bidi-reordered and was killed immediately before this
16906 redisplay cycle. In that case, ROW->end stores the
16907 buffer position of the first visual-order character of
16908 the killed text, which is now beyond ZV. */
16909 && CHARPOS (row
->end
.pos
) <= ZV
)
16912 /* Stop if last visible row. */
16913 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16921 /* Find the first glyph row in the current matrix of W that is not
16922 affected by changes at the end of current_buffer since the
16923 time W's current matrix was built.
16925 Return in *DELTA the number of chars by which buffer positions in
16926 unchanged text at the end of current_buffer must be adjusted.
16928 Return in *DELTA_BYTES the corresponding number of bytes.
16930 Value is null if no such row exists, i.e. all rows are affected by
16933 static struct glyph_row
*
16934 find_first_unchanged_at_end_row (struct window
*w
,
16935 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16937 struct glyph_row
*row
;
16938 struct glyph_row
*row_found
= NULL
;
16940 *delta
= *delta_bytes
= 0;
16942 /* Display must not have been paused, otherwise the current matrix
16943 is not up to date. */
16944 eassert (!NILP (w
->window_end_valid
));
16946 /* A value of window_end_pos >= END_UNCHANGED means that the window
16947 end is in the range of changed text. If so, there is no
16948 unchanged row at the end of W's current matrix. */
16949 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16952 /* Set row to the last row in W's current matrix displaying text. */
16953 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16955 /* If matrix is entirely empty, no unchanged row exists. */
16956 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16958 /* The value of row is the last glyph row in the matrix having a
16959 meaningful buffer position in it. The end position of row
16960 corresponds to window_end_pos. This allows us to translate
16961 buffer positions in the current matrix to current buffer
16962 positions for characters not in changed text. */
16964 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16965 ptrdiff_t Z_BYTE_old
=
16966 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16967 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16968 struct glyph_row
*first_text_row
16969 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16971 *delta
= Z
- Z_old
;
16972 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16974 /* Set last_unchanged_pos to the buffer position of the last
16975 character in the buffer that has not been changed. Z is the
16976 index + 1 of the last character in current_buffer, i.e. by
16977 subtracting END_UNCHANGED we get the index of the last
16978 unchanged character, and we have to add BEG to get its buffer
16980 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16981 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16983 /* Search backward from ROW for a row displaying a line that
16984 starts at a minimum position >= last_unchanged_pos_old. */
16985 for (; row
> first_text_row
; --row
)
16987 /* This used to abort, but it can happen.
16988 It is ok to just stop the search instead here. KFS. */
16989 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16992 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16997 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17003 /* Make sure that glyph rows in the current matrix of window W
17004 reference the same glyph memory as corresponding rows in the
17005 frame's frame matrix. This function is called after scrolling W's
17006 current matrix on a terminal frame in try_window_id and
17007 try_window_reusing_current_matrix. */
17010 sync_frame_with_window_matrix_rows (struct window
*w
)
17012 struct frame
*f
= XFRAME (w
->frame
);
17013 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17015 /* Preconditions: W must be a leaf window and full-width. Its frame
17016 must have a frame matrix. */
17017 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
17018 eassert (WINDOW_FULL_WIDTH_P (w
));
17019 eassert (!FRAME_WINDOW_P (f
));
17021 /* If W is a full-width window, glyph pointers in W's current matrix
17022 have, by definition, to be the same as glyph pointers in the
17023 corresponding frame matrix. Note that frame matrices have no
17024 marginal areas (see build_frame_matrix). */
17025 window_row
= w
->current_matrix
->rows
;
17026 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17027 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17028 while (window_row
< window_row_end
)
17030 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17031 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17033 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17034 frame_row
->glyphs
[TEXT_AREA
] = start
;
17035 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17036 frame_row
->glyphs
[LAST_AREA
] = end
;
17038 /* Disable frame rows whose corresponding window rows have
17039 been disabled in try_window_id. */
17040 if (!window_row
->enabled_p
)
17041 frame_row
->enabled_p
= 0;
17043 ++window_row
, ++frame_row
;
17048 /* Find the glyph row in window W containing CHARPOS. Consider all
17049 rows between START and END (not inclusive). END null means search
17050 all rows to the end of the display area of W. Value is the row
17051 containing CHARPOS or null. */
17054 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17055 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17057 struct glyph_row
*row
= start
;
17058 struct glyph_row
*best_row
= NULL
;
17059 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
17062 /* If we happen to start on a header-line, skip that. */
17063 if (row
->mode_line_p
)
17066 if ((end
&& row
>= end
) || !row
->enabled_p
)
17069 last_y
= window_text_bottom_y (w
) - dy
;
17073 /* Give up if we have gone too far. */
17074 if (end
&& row
>= end
)
17076 /* This formerly returned if they were equal.
17077 I think that both quantities are of a "last plus one" type;
17078 if so, when they are equal, the row is within the screen. -- rms. */
17079 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17082 /* If it is in this row, return this row. */
17083 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17084 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17085 /* The end position of a row equals the start
17086 position of the next row. If CHARPOS is there, we
17087 would rather display it in the next line, except
17088 when this line ends in ZV. */
17089 && !row
->ends_at_zv_p
17090 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
17091 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17095 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17096 || (!best_row
&& !row
->continued_p
))
17098 /* In bidi-reordered rows, there could be several rows
17099 occluding point, all of them belonging to the same
17100 continued line. We need to find the row which fits
17101 CHARPOS the best. */
17102 for (g
= row
->glyphs
[TEXT_AREA
];
17103 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17106 if (!STRINGP (g
->object
))
17108 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17110 mindif
= eabs (g
->charpos
- charpos
);
17112 /* Exact match always wins. */
17119 else if (best_row
&& !row
->continued_p
)
17126 /* Try to redisplay window W by reusing its existing display. W's
17127 current matrix must be up to date when this function is called,
17128 i.e. window_end_valid must not be nil.
17132 1 if display has been updated
17133 0 if otherwise unsuccessful
17134 -1 if redisplay with same window start is known not to succeed
17136 The following steps are performed:
17138 1. Find the last row in the current matrix of W that is not
17139 affected by changes at the start of current_buffer. If no such row
17142 2. Find the first row in W's current matrix that is not affected by
17143 changes at the end of current_buffer. Maybe there is no such row.
17145 3. Display lines beginning with the row + 1 found in step 1 to the
17146 row found in step 2 or, if step 2 didn't find a row, to the end of
17149 4. If cursor is not known to appear on the window, give up.
17151 5. If display stopped at the row found in step 2, scroll the
17152 display and current matrix as needed.
17154 6. Maybe display some lines at the end of W, if we must. This can
17155 happen under various circumstances, like a partially visible line
17156 becoming fully visible, or because newly displayed lines are displayed
17157 in smaller font sizes.
17159 7. Update W's window end information. */
17162 try_window_id (struct window
*w
)
17164 struct frame
*f
= XFRAME (w
->frame
);
17165 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17166 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17167 struct glyph_row
*last_unchanged_at_beg_row
;
17168 struct glyph_row
*first_unchanged_at_end_row
;
17169 struct glyph_row
*row
;
17170 struct glyph_row
*bottom_row
;
17173 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17175 struct text_pos start_pos
;
17177 int first_unchanged_at_end_vpos
= 0;
17178 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17179 struct text_pos start
;
17180 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17183 if (inhibit_try_window_id
)
17187 /* This is handy for debugging. */
17189 #define GIVE_UP(X) \
17191 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17195 #define GIVE_UP(X) return 0
17198 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17200 /* Don't use this for mini-windows because these can show
17201 messages and mini-buffers, and we don't handle that here. */
17202 if (MINI_WINDOW_P (w
))
17205 /* This flag is used to prevent redisplay optimizations. */
17206 if (windows_or_buffers_changed
|| cursor_type_changed
)
17209 /* Verify that narrowing has not changed.
17210 Also verify that we were not told to prevent redisplay optimizations.
17211 It would be nice to further
17212 reduce the number of cases where this prevents try_window_id. */
17213 if (current_buffer
->clip_changed
17214 || current_buffer
->prevent_redisplay_optimizations_p
)
17217 /* Window must either use window-based redisplay or be full width. */
17218 if (!FRAME_WINDOW_P (f
)
17219 && (!FRAME_LINE_INS_DEL_OK (f
)
17220 || !WINDOW_FULL_WIDTH_P (w
)))
17223 /* Give up if point is known NOT to appear in W. */
17224 if (PT
< CHARPOS (start
))
17227 /* Another way to prevent redisplay optimizations. */
17228 if (w
->last_modified
== 0)
17231 /* Verify that window is not hscrolled. */
17232 if (w
->hscroll
!= 0)
17235 /* Verify that display wasn't paused. */
17236 if (NILP (w
->window_end_valid
))
17239 /* Can't use this if highlighting a region because a cursor movement
17240 will do more than just set the cursor. */
17241 if (0 <= markpos_of_region ())
17244 /* Likewise if highlighting trailing whitespace. */
17245 if (!NILP (Vshow_trailing_whitespace
))
17248 /* Likewise if showing a region. */
17249 if (!NILP (w
->region_showing
))
17252 /* Can't use this if overlay arrow position and/or string have
17254 if (overlay_arrows_changed_p ())
17257 /* When word-wrap is on, adding a space to the first word of a
17258 wrapped line can change the wrap position, altering the line
17259 above it. It might be worthwhile to handle this more
17260 intelligently, but for now just redisplay from scratch. */
17261 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17264 /* Under bidi reordering, adding or deleting a character in the
17265 beginning of a paragraph, before the first strong directional
17266 character, can change the base direction of the paragraph (unless
17267 the buffer specifies a fixed paragraph direction), which will
17268 require to redisplay the whole paragraph. It might be worthwhile
17269 to find the paragraph limits and widen the range of redisplayed
17270 lines to that, but for now just give up this optimization and
17271 redisplay from scratch. */
17272 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17273 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17276 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17277 only if buffer has really changed. The reason is that the gap is
17278 initially at Z for freshly visited files. The code below would
17279 set end_unchanged to 0 in that case. */
17280 if (MODIFF
> SAVE_MODIFF
17281 /* This seems to happen sometimes after saving a buffer. */
17282 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17284 if (GPT
- BEG
< BEG_UNCHANGED
)
17285 BEG_UNCHANGED
= GPT
- BEG
;
17286 if (Z
- GPT
< END_UNCHANGED
)
17287 END_UNCHANGED
= Z
- GPT
;
17290 /* The position of the first and last character that has been changed. */
17291 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17292 last_changed_charpos
= Z
- END_UNCHANGED
;
17294 /* If window starts after a line end, and the last change is in
17295 front of that newline, then changes don't affect the display.
17296 This case happens with stealth-fontification. Note that although
17297 the display is unchanged, glyph positions in the matrix have to
17298 be adjusted, of course. */
17299 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17300 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17301 && ((last_changed_charpos
< CHARPOS (start
)
17302 && CHARPOS (start
) == BEGV
)
17303 || (last_changed_charpos
< CHARPOS (start
) - 1
17304 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17306 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17307 struct glyph_row
*r0
;
17309 /* Compute how many chars/bytes have been added to or removed
17310 from the buffer. */
17311 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17312 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17313 Z_delta
= Z
- Z_old
;
17314 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17316 /* Give up if PT is not in the window. Note that it already has
17317 been checked at the start of try_window_id that PT is not in
17318 front of the window start. */
17319 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17322 /* If window start is unchanged, we can reuse the whole matrix
17323 as is, after adjusting glyph positions. No need to compute
17324 the window end again, since its offset from Z hasn't changed. */
17325 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17326 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17327 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17328 /* PT must not be in a partially visible line. */
17329 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17330 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17332 /* Adjust positions in the glyph matrix. */
17333 if (Z_delta
|| Z_delta_bytes
)
17335 struct glyph_row
*r1
17336 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17337 increment_matrix_positions (w
->current_matrix
,
17338 MATRIX_ROW_VPOS (r0
, current_matrix
),
17339 MATRIX_ROW_VPOS (r1
, current_matrix
),
17340 Z_delta
, Z_delta_bytes
);
17343 /* Set the cursor. */
17344 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17346 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17353 /* Handle the case that changes are all below what is displayed in
17354 the window, and that PT is in the window. This shortcut cannot
17355 be taken if ZV is visible in the window, and text has been added
17356 there that is visible in the window. */
17357 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17358 /* ZV is not visible in the window, or there are no
17359 changes at ZV, actually. */
17360 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17361 || first_changed_charpos
== last_changed_charpos
))
17363 struct glyph_row
*r0
;
17365 /* Give up if PT is not in the window. Note that it already has
17366 been checked at the start of try_window_id that PT is not in
17367 front of the window start. */
17368 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17371 /* If window start is unchanged, we can reuse the whole matrix
17372 as is, without changing glyph positions since no text has
17373 been added/removed in front of the window end. */
17374 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17375 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17376 /* PT must not be in a partially visible line. */
17377 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17378 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17380 /* We have to compute the window end anew since text
17381 could have been added/removed after it. */
17382 wset_window_end_pos
17383 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17384 w
->window_end_bytepos
17385 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17387 /* Set the cursor. */
17388 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17390 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17397 /* Give up if window start is in the changed area.
17399 The condition used to read
17401 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17403 but why that was tested escapes me at the moment. */
17404 if (CHARPOS (start
) >= first_changed_charpos
17405 && CHARPOS (start
) <= last_changed_charpos
)
17408 /* Check that window start agrees with the start of the first glyph
17409 row in its current matrix. Check this after we know the window
17410 start is not in changed text, otherwise positions would not be
17412 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17413 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17416 /* Give up if the window ends in strings. Overlay strings
17417 at the end are difficult to handle, so don't try. */
17418 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17419 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17422 /* Compute the position at which we have to start displaying new
17423 lines. Some of the lines at the top of the window might be
17424 reusable because they are not displaying changed text. Find the
17425 last row in W's current matrix not affected by changes at the
17426 start of current_buffer. Value is null if changes start in the
17427 first line of window. */
17428 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17429 if (last_unchanged_at_beg_row
)
17431 /* Avoid starting to display in the middle of a character, a TAB
17432 for instance. This is easier than to set up the iterator
17433 exactly, and it's not a frequent case, so the additional
17434 effort wouldn't really pay off. */
17435 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17436 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17437 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17438 --last_unchanged_at_beg_row
;
17440 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17443 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17445 start_pos
= it
.current
.pos
;
17447 /* Start displaying new lines in the desired matrix at the same
17448 vpos we would use in the current matrix, i.e. below
17449 last_unchanged_at_beg_row. */
17450 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17452 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17453 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17455 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17459 /* There are no reusable lines at the start of the window.
17460 Start displaying in the first text line. */
17461 start_display (&it
, w
, start
);
17462 it
.vpos
= it
.first_vpos
;
17463 start_pos
= it
.current
.pos
;
17466 /* Find the first row that is not affected by changes at the end of
17467 the buffer. Value will be null if there is no unchanged row, in
17468 which case we must redisplay to the end of the window. delta
17469 will be set to the value by which buffer positions beginning with
17470 first_unchanged_at_end_row have to be adjusted due to text
17472 first_unchanged_at_end_row
17473 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17474 IF_DEBUG (debug_delta
= delta
);
17475 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17477 /* Set stop_pos to the buffer position up to which we will have to
17478 display new lines. If first_unchanged_at_end_row != NULL, this
17479 is the buffer position of the start of the line displayed in that
17480 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17481 that we don't stop at a buffer position. */
17483 if (first_unchanged_at_end_row
)
17485 eassert (last_unchanged_at_beg_row
== NULL
17486 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17488 /* If this is a continuation line, move forward to the next one
17489 that isn't. Changes in lines above affect this line.
17490 Caution: this may move first_unchanged_at_end_row to a row
17491 not displaying text. */
17492 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17493 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17494 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17495 < it
.last_visible_y
))
17496 ++first_unchanged_at_end_row
;
17498 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17499 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17500 >= it
.last_visible_y
))
17501 first_unchanged_at_end_row
= NULL
;
17504 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17506 first_unchanged_at_end_vpos
17507 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17508 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17511 else if (last_unchanged_at_beg_row
== NULL
)
17517 /* Either there is no unchanged row at the end, or the one we have
17518 now displays text. This is a necessary condition for the window
17519 end pos calculation at the end of this function. */
17520 eassert (first_unchanged_at_end_row
== NULL
17521 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17523 debug_last_unchanged_at_beg_vpos
17524 = (last_unchanged_at_beg_row
17525 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17527 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17529 #endif /* GLYPH_DEBUG */
17532 /* Display new lines. Set last_text_row to the last new line
17533 displayed which has text on it, i.e. might end up as being the
17534 line where the window_end_vpos is. */
17535 w
->cursor
.vpos
= -1;
17536 last_text_row
= NULL
;
17537 overlay_arrow_seen
= 0;
17538 while (it
.current_y
< it
.last_visible_y
17539 && !fonts_changed_p
17540 && (first_unchanged_at_end_row
== NULL
17541 || IT_CHARPOS (it
) < stop_pos
))
17543 if (display_line (&it
))
17544 last_text_row
= it
.glyph_row
- 1;
17547 if (fonts_changed_p
)
17551 /* Compute differences in buffer positions, y-positions etc. for
17552 lines reused at the bottom of the window. Compute what we can
17554 if (first_unchanged_at_end_row
17555 /* No lines reused because we displayed everything up to the
17556 bottom of the window. */
17557 && it
.current_y
< it
.last_visible_y
)
17560 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17562 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17563 run
.current_y
= first_unchanged_at_end_row
->y
;
17564 run
.desired_y
= run
.current_y
+ dy
;
17565 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17569 delta
= delta_bytes
= dvpos
= dy
17570 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17571 first_unchanged_at_end_row
= NULL
;
17573 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17576 /* Find the cursor if not already found. We have to decide whether
17577 PT will appear on this window (it sometimes doesn't, but this is
17578 not a very frequent case.) This decision has to be made before
17579 the current matrix is altered. A value of cursor.vpos < 0 means
17580 that PT is either in one of the lines beginning at
17581 first_unchanged_at_end_row or below the window. Don't care for
17582 lines that might be displayed later at the window end; as
17583 mentioned, this is not a frequent case. */
17584 if (w
->cursor
.vpos
< 0)
17586 /* Cursor in unchanged rows at the top? */
17587 if (PT
< CHARPOS (start_pos
)
17588 && last_unchanged_at_beg_row
)
17590 row
= row_containing_pos (w
, PT
,
17591 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17592 last_unchanged_at_beg_row
+ 1, 0);
17594 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17597 /* Start from first_unchanged_at_end_row looking for PT. */
17598 else if (first_unchanged_at_end_row
)
17600 row
= row_containing_pos (w
, PT
- delta
,
17601 first_unchanged_at_end_row
, NULL
, 0);
17603 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17604 delta_bytes
, dy
, dvpos
);
17607 /* Give up if cursor was not found. */
17608 if (w
->cursor
.vpos
< 0)
17610 clear_glyph_matrix (w
->desired_matrix
);
17615 /* Don't let the cursor end in the scroll margins. */
17617 int this_scroll_margin
, cursor_height
;
17619 this_scroll_margin
=
17620 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17621 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17622 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17624 if ((w
->cursor
.y
< this_scroll_margin
17625 && CHARPOS (start
) > BEGV
)
17626 /* Old redisplay didn't take scroll margin into account at the bottom,
17627 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17628 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17629 ? cursor_height
+ this_scroll_margin
17630 : 1)) > it
.last_visible_y
)
17632 w
->cursor
.vpos
= -1;
17633 clear_glyph_matrix (w
->desired_matrix
);
17638 /* Scroll the display. Do it before changing the current matrix so
17639 that xterm.c doesn't get confused about where the cursor glyph is
17641 if (dy
&& run
.height
)
17645 if (FRAME_WINDOW_P (f
))
17647 FRAME_RIF (f
)->update_window_begin_hook (w
);
17648 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17649 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17650 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17654 /* Terminal frame. In this case, dvpos gives the number of
17655 lines to scroll by; dvpos < 0 means scroll up. */
17657 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17658 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17659 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17660 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17661 + window_internal_height (w
));
17663 #if defined (HAVE_GPM) || defined (MSDOS)
17664 x_clear_window_mouse_face (w
);
17666 /* Perform the operation on the screen. */
17669 /* Scroll last_unchanged_at_beg_row to the end of the
17670 window down dvpos lines. */
17671 set_terminal_window (f
, end
);
17673 /* On dumb terminals delete dvpos lines at the end
17674 before inserting dvpos empty lines. */
17675 if (!FRAME_SCROLL_REGION_OK (f
))
17676 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17678 /* Insert dvpos empty lines in front of
17679 last_unchanged_at_beg_row. */
17680 ins_del_lines (f
, from
, dvpos
);
17682 else if (dvpos
< 0)
17684 /* Scroll up last_unchanged_at_beg_vpos to the end of
17685 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17686 set_terminal_window (f
, end
);
17688 /* Delete dvpos lines in front of
17689 last_unchanged_at_beg_vpos. ins_del_lines will set
17690 the cursor to the given vpos and emit |dvpos| delete
17692 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17694 /* On a dumb terminal insert dvpos empty lines at the
17696 if (!FRAME_SCROLL_REGION_OK (f
))
17697 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17700 set_terminal_window (f
, 0);
17706 /* Shift reused rows of the current matrix to the right position.
17707 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17709 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17710 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17713 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17714 bottom_vpos
, dvpos
);
17715 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17718 else if (dvpos
> 0)
17720 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17721 bottom_vpos
, dvpos
);
17722 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17723 first_unchanged_at_end_vpos
+ dvpos
);
17726 /* For frame-based redisplay, make sure that current frame and window
17727 matrix are in sync with respect to glyph memory. */
17728 if (!FRAME_WINDOW_P (f
))
17729 sync_frame_with_window_matrix_rows (w
);
17731 /* Adjust buffer positions in reused rows. */
17732 if (delta
|| delta_bytes
)
17733 increment_matrix_positions (current_matrix
,
17734 first_unchanged_at_end_vpos
+ dvpos
,
17735 bottom_vpos
, delta
, delta_bytes
);
17737 /* Adjust Y positions. */
17739 shift_glyph_matrix (w
, current_matrix
,
17740 first_unchanged_at_end_vpos
+ dvpos
,
17743 if (first_unchanged_at_end_row
)
17745 first_unchanged_at_end_row
+= dvpos
;
17746 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17747 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17748 first_unchanged_at_end_row
= NULL
;
17751 /* If scrolling up, there may be some lines to display at the end of
17753 last_text_row_at_end
= NULL
;
17756 /* Scrolling up can leave for example a partially visible line
17757 at the end of the window to be redisplayed. */
17758 /* Set last_row to the glyph row in the current matrix where the
17759 window end line is found. It has been moved up or down in
17760 the matrix by dvpos. */
17761 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17762 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17764 /* If last_row is the window end line, it should display text. */
17765 eassert (last_row
->displays_text_p
);
17767 /* If window end line was partially visible before, begin
17768 displaying at that line. Otherwise begin displaying with the
17769 line following it. */
17770 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17772 init_to_row_start (&it
, w
, last_row
);
17773 it
.vpos
= last_vpos
;
17774 it
.current_y
= last_row
->y
;
17778 init_to_row_end (&it
, w
, last_row
);
17779 it
.vpos
= 1 + last_vpos
;
17780 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17784 /* We may start in a continuation line. If so, we have to
17785 get the right continuation_lines_width and current_x. */
17786 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17787 it
.hpos
= it
.current_x
= 0;
17789 /* Display the rest of the lines at the window end. */
17790 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17791 while (it
.current_y
< it
.last_visible_y
17792 && !fonts_changed_p
)
17794 /* Is it always sure that the display agrees with lines in
17795 the current matrix? I don't think so, so we mark rows
17796 displayed invalid in the current matrix by setting their
17797 enabled_p flag to zero. */
17798 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17799 if (display_line (&it
))
17800 last_text_row_at_end
= it
.glyph_row
- 1;
17804 /* Update window_end_pos and window_end_vpos. */
17805 if (first_unchanged_at_end_row
17806 && !last_text_row_at_end
)
17808 /* Window end line if one of the preserved rows from the current
17809 matrix. Set row to the last row displaying text in current
17810 matrix starting at first_unchanged_at_end_row, after
17812 eassert (first_unchanged_at_end_row
->displays_text_p
);
17813 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17814 first_unchanged_at_end_row
);
17815 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17817 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17818 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17819 wset_window_end_vpos
17820 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17821 eassert (w
->window_end_bytepos
>= 0);
17822 IF_DEBUG (debug_method_add (w
, "A"));
17824 else if (last_text_row_at_end
)
17826 wset_window_end_pos
17827 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17828 w
->window_end_bytepos
17829 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17830 wset_window_end_vpos
17831 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17833 eassert (w
->window_end_bytepos
>= 0);
17834 IF_DEBUG (debug_method_add (w
, "B"));
17836 else if (last_text_row
)
17838 /* We have displayed either to the end of the window or at the
17839 end of the window, i.e. the last row with text is to be found
17840 in the desired matrix. */
17841 wset_window_end_pos
17842 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17843 w
->window_end_bytepos
17844 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17845 wset_window_end_vpos
17846 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17847 eassert (w
->window_end_bytepos
>= 0);
17849 else if (first_unchanged_at_end_row
== NULL
17850 && last_text_row
== NULL
17851 && last_text_row_at_end
== NULL
)
17853 /* Displayed to end of window, but no line containing text was
17854 displayed. Lines were deleted at the end of the window. */
17855 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17856 int vpos
= XFASTINT (w
->window_end_vpos
);
17857 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17858 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17861 row
== NULL
&& vpos
>= first_vpos
;
17862 --vpos
, --current_row
, --desired_row
)
17864 if (desired_row
->enabled_p
)
17866 if (desired_row
->displays_text_p
)
17869 else if (current_row
->displays_text_p
)
17873 eassert (row
!= NULL
);
17874 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17875 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17876 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17877 eassert (w
->window_end_bytepos
>= 0);
17878 IF_DEBUG (debug_method_add (w
, "C"));
17883 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17884 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17886 /* Record that display has not been completed. */
17887 wset_window_end_valid (w
, Qnil
);
17888 w
->desired_matrix
->no_scrolling_p
= 1;
17896 /***********************************************************************
17897 More debugging support
17898 ***********************************************************************/
17902 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17903 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17904 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17907 /* Dump the contents of glyph matrix MATRIX on stderr.
17909 GLYPHS 0 means don't show glyph contents.
17910 GLYPHS 1 means show glyphs in short form
17911 GLYPHS > 1 means show glyphs in long form. */
17914 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17917 for (i
= 0; i
< matrix
->nrows
; ++i
)
17918 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17922 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17923 the glyph row and area where the glyph comes from. */
17926 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17928 if (glyph
->type
== CHAR_GLYPH
)
17931 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17932 glyph
- row
->glyphs
[TEXT_AREA
],
17935 (BUFFERP (glyph
->object
)
17937 : (STRINGP (glyph
->object
)
17940 glyph
->pixel_width
,
17942 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17946 glyph
->left_box_line_p
,
17947 glyph
->right_box_line_p
);
17949 else if (glyph
->type
== STRETCH_GLYPH
)
17952 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17953 glyph
- row
->glyphs
[TEXT_AREA
],
17956 (BUFFERP (glyph
->object
)
17958 : (STRINGP (glyph
->object
)
17961 glyph
->pixel_width
,
17965 glyph
->left_box_line_p
,
17966 glyph
->right_box_line_p
);
17968 else if (glyph
->type
== IMAGE_GLYPH
)
17971 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17972 glyph
- row
->glyphs
[TEXT_AREA
],
17975 (BUFFERP (glyph
->object
)
17977 : (STRINGP (glyph
->object
)
17980 glyph
->pixel_width
,
17984 glyph
->left_box_line_p
,
17985 glyph
->right_box_line_p
);
17987 else if (glyph
->type
== COMPOSITE_GLYPH
)
17990 " %5td %4c %6"pI
"d %c %3d 0x%05x",
17991 glyph
- row
->glyphs
[TEXT_AREA
],
17994 (BUFFERP (glyph
->object
)
17996 : (STRINGP (glyph
->object
)
17999 glyph
->pixel_width
,
18001 if (glyph
->u
.cmp
.automatic
)
18004 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18005 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18007 glyph
->left_box_line_p
,
18008 glyph
->right_box_line_p
);
18013 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18014 GLYPHS 0 means don't show glyph contents.
18015 GLYPHS 1 means show glyphs in short form
18016 GLYPHS > 1 means show glyphs in long form. */
18019 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18023 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18024 fprintf (stderr
, "======================================================================\n");
18026 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18027 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18029 MATRIX_ROW_START_CHARPOS (row
),
18030 MATRIX_ROW_END_CHARPOS (row
),
18031 row
->used
[TEXT_AREA
],
18032 row
->contains_overlapping_glyphs_p
,
18034 row
->truncated_on_left_p
,
18035 row
->truncated_on_right_p
,
18037 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18038 row
->displays_text_p
,
18041 row
->ends_in_middle_of_char_p
,
18042 row
->starts_in_middle_of_char_p
,
18048 row
->visible_height
,
18051 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18052 row
->end
.overlay_string_index
,
18053 row
->continuation_lines_width
);
18054 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
18055 CHARPOS (row
->start
.string_pos
),
18056 CHARPOS (row
->end
.string_pos
));
18057 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
18058 row
->end
.dpvec_index
);
18065 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18067 struct glyph
*glyph
= row
->glyphs
[area
];
18068 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18070 /* Glyph for a line end in text. */
18071 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18074 if (glyph
< glyph_end
)
18075 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
18077 for (; glyph
< glyph_end
; ++glyph
)
18078 dump_glyph (row
, glyph
, area
);
18081 else if (glyphs
== 1)
18085 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18087 char *s
= alloca (row
->used
[area
] + 1);
18090 for (i
= 0; i
< row
->used
[area
]; ++i
)
18092 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18093 if (glyph
->type
== CHAR_GLYPH
18094 && glyph
->u
.ch
< 0x80
18095 && glyph
->u
.ch
>= ' ')
18096 s
[i
] = glyph
->u
.ch
;
18102 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18108 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18109 Sdump_glyph_matrix
, 0, 1, "p",
18110 doc
: /* Dump the current matrix of the selected window to stderr.
18111 Shows contents of glyph row structures. With non-nil
18112 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18113 glyphs in short form, otherwise show glyphs in long form. */)
18114 (Lisp_Object glyphs
)
18116 struct window
*w
= XWINDOW (selected_window
);
18117 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18119 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18120 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18121 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18122 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18123 fprintf (stderr
, "=============================================\n");
18124 dump_glyph_matrix (w
->current_matrix
,
18125 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18130 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18131 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18134 struct frame
*f
= XFRAME (selected_frame
);
18135 dump_glyph_matrix (f
->current_matrix
, 1);
18140 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18141 doc
: /* Dump glyph row ROW to stderr.
18142 GLYPH 0 means don't dump glyphs.
18143 GLYPH 1 means dump glyphs in short form.
18144 GLYPH > 1 or omitted means dump glyphs in long form. */)
18145 (Lisp_Object row
, Lisp_Object glyphs
)
18147 struct glyph_matrix
*matrix
;
18150 CHECK_NUMBER (row
);
18151 matrix
= XWINDOW (selected_window
)->current_matrix
;
18153 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18154 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18156 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18161 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18162 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18163 GLYPH 0 means don't dump glyphs.
18164 GLYPH 1 means dump glyphs in short form.
18165 GLYPH > 1 or omitted means dump glyphs in long form. */)
18166 (Lisp_Object row
, Lisp_Object glyphs
)
18168 struct frame
*sf
= SELECTED_FRAME ();
18169 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18172 CHECK_NUMBER (row
);
18174 if (vpos
>= 0 && vpos
< m
->nrows
)
18175 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18176 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18181 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18182 doc
: /* Toggle tracing of redisplay.
18183 With ARG, turn tracing on if and only if ARG is positive. */)
18187 trace_redisplay_p
= !trace_redisplay_p
;
18190 arg
= Fprefix_numeric_value (arg
);
18191 trace_redisplay_p
= XINT (arg
) > 0;
18198 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18199 doc
: /* Like `format', but print result to stderr.
18200 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18201 (ptrdiff_t nargs
, Lisp_Object
*args
)
18203 Lisp_Object s
= Fformat (nargs
, args
);
18204 fprintf (stderr
, "%s", SDATA (s
));
18208 #endif /* GLYPH_DEBUG */
18212 /***********************************************************************
18213 Building Desired Matrix Rows
18214 ***********************************************************************/
18216 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18217 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18219 static struct glyph_row
*
18220 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18222 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18223 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18224 struct buffer
*old
= current_buffer
;
18225 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18226 int arrow_len
= SCHARS (overlay_arrow_string
);
18227 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18228 const unsigned char *p
;
18231 int n_glyphs_before
;
18233 set_buffer_temp (buffer
);
18234 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18235 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18236 SET_TEXT_POS (it
.position
, 0, 0);
18238 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18240 while (p
< arrow_end
)
18242 Lisp_Object face
, ilisp
;
18244 /* Get the next character. */
18246 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18249 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18250 if (! ASCII_CHAR_P (it
.c
))
18251 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18255 /* Get its face. */
18256 ilisp
= make_number (p
- arrow_string
);
18257 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18258 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18260 /* Compute its width, get its glyphs. */
18261 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18262 SET_TEXT_POS (it
.position
, -1, -1);
18263 PRODUCE_GLYPHS (&it
);
18265 /* If this character doesn't fit any more in the line, we have
18266 to remove some glyphs. */
18267 if (it
.current_x
> it
.last_visible_x
)
18269 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18274 set_buffer_temp (old
);
18275 return it
.glyph_row
;
18279 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18280 glyphs to insert is determined by produce_special_glyphs. */
18283 insert_left_trunc_glyphs (struct it
*it
)
18285 struct it truncate_it
;
18286 struct glyph
*from
, *end
, *to
, *toend
;
18288 eassert (!FRAME_WINDOW_P (it
->f
)
18289 || (!it
->glyph_row
->reversed_p
18290 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18291 || (it
->glyph_row
->reversed_p
18292 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18294 /* Get the truncation glyphs. */
18296 truncate_it
.current_x
= 0;
18297 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18298 truncate_it
.glyph_row
= &scratch_glyph_row
;
18299 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18300 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18301 truncate_it
.object
= make_number (0);
18302 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18304 /* Overwrite glyphs from IT with truncation glyphs. */
18305 if (!it
->glyph_row
->reversed_p
)
18307 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18309 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18310 end
= from
+ tused
;
18311 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18312 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18313 if (FRAME_WINDOW_P (it
->f
))
18315 /* On GUI frames, when variable-size fonts are displayed,
18316 the truncation glyphs may need more pixels than the row's
18317 glyphs they overwrite. We overwrite more glyphs to free
18318 enough screen real estate, and enlarge the stretch glyph
18319 on the right (see display_line), if there is one, to
18320 preserve the screen position of the truncation glyphs on
18323 struct glyph
*g
= to
;
18326 /* The first glyph could be partially visible, in which case
18327 it->glyph_row->x will be negative. But we want the left
18328 truncation glyphs to be aligned at the left margin of the
18329 window, so we override the x coordinate at which the row
18331 it
->glyph_row
->x
= 0;
18332 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18334 w
+= g
->pixel_width
;
18337 if (g
- to
- tused
> 0)
18339 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18340 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18342 used
= it
->glyph_row
->used
[TEXT_AREA
];
18343 if (it
->glyph_row
->truncated_on_right_p
18344 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18345 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18348 int extra
= w
- it
->truncation_pixel_width
;
18350 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18357 /* There may be padding glyphs left over. Overwrite them too. */
18358 if (!FRAME_WINDOW_P (it
->f
))
18360 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18362 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18369 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18373 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18375 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18376 that back to front. */
18377 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18378 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18379 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18380 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18381 if (FRAME_WINDOW_P (it
->f
))
18384 struct glyph
*g
= to
;
18386 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18388 w
+= g
->pixel_width
;
18391 if (to
- g
- tused
> 0)
18393 if (it
->glyph_row
->truncated_on_right_p
18394 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18395 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18397 int extra
= w
- it
->truncation_pixel_width
;
18399 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18403 while (from
>= end
&& to
>= toend
)
18405 if (!FRAME_WINDOW_P (it
->f
))
18407 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18410 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18411 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18412 while (from
>= end
&& to
>= toend
)
18418 /* Need to free some room before prepending additional
18420 int move_by
= from
- end
+ 1;
18421 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18422 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18424 for ( ; g
>= g0
; g
--)
18426 while (from
>= end
)
18428 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18433 /* Compute the hash code for ROW. */
18435 row_hash (struct glyph_row
*row
)
18438 unsigned hashval
= 0;
18440 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18441 for (k
= 0; k
< row
->used
[area
]; ++k
)
18442 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18443 + row
->glyphs
[area
][k
].u
.val
18444 + row
->glyphs
[area
][k
].face_id
18445 + row
->glyphs
[area
][k
].padding_p
18446 + (row
->glyphs
[area
][k
].type
<< 2));
18451 /* Compute the pixel height and width of IT->glyph_row.
18453 Most of the time, ascent and height of a display line will be equal
18454 to the max_ascent and max_height values of the display iterator
18455 structure. This is not the case if
18457 1. We hit ZV without displaying anything. In this case, max_ascent
18458 and max_height will be zero.
18460 2. We have some glyphs that don't contribute to the line height.
18461 (The glyph row flag contributes_to_line_height_p is for future
18462 pixmap extensions).
18464 The first case is easily covered by using default values because in
18465 these cases, the line height does not really matter, except that it
18466 must not be zero. */
18469 compute_line_metrics (struct it
*it
)
18471 struct glyph_row
*row
= it
->glyph_row
;
18473 if (FRAME_WINDOW_P (it
->f
))
18475 int i
, min_y
, max_y
;
18477 /* The line may consist of one space only, that was added to
18478 place the cursor on it. If so, the row's height hasn't been
18480 if (row
->height
== 0)
18482 if (it
->max_ascent
+ it
->max_descent
== 0)
18483 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18484 row
->ascent
= it
->max_ascent
;
18485 row
->height
= it
->max_ascent
+ it
->max_descent
;
18486 row
->phys_ascent
= it
->max_phys_ascent
;
18487 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18488 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18491 /* Compute the width of this line. */
18492 row
->pixel_width
= row
->x
;
18493 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18494 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18496 eassert (row
->pixel_width
>= 0);
18497 eassert (row
->ascent
>= 0 && row
->height
> 0);
18499 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18500 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18502 /* If first line's physical ascent is larger than its logical
18503 ascent, use the physical ascent, and make the row taller.
18504 This makes accented characters fully visible. */
18505 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18506 && row
->phys_ascent
> row
->ascent
)
18508 row
->height
+= row
->phys_ascent
- row
->ascent
;
18509 row
->ascent
= row
->phys_ascent
;
18512 /* Compute how much of the line is visible. */
18513 row
->visible_height
= row
->height
;
18515 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18516 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18518 if (row
->y
< min_y
)
18519 row
->visible_height
-= min_y
- row
->y
;
18520 if (row
->y
+ row
->height
> max_y
)
18521 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18525 row
->pixel_width
= row
->used
[TEXT_AREA
];
18526 if (row
->continued_p
)
18527 row
->pixel_width
-= it
->continuation_pixel_width
;
18528 else if (row
->truncated_on_right_p
)
18529 row
->pixel_width
-= it
->truncation_pixel_width
;
18530 row
->ascent
= row
->phys_ascent
= 0;
18531 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18532 row
->extra_line_spacing
= 0;
18535 /* Compute a hash code for this row. */
18536 row
->hash
= row_hash (row
);
18538 it
->max_ascent
= it
->max_descent
= 0;
18539 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18543 /* Append one space to the glyph row of iterator IT if doing a
18544 window-based redisplay. The space has the same face as
18545 IT->face_id. Value is non-zero if a space was added.
18547 This function is called to make sure that there is always one glyph
18548 at the end of a glyph row that the cursor can be set on under
18549 window-systems. (If there weren't such a glyph we would not know
18550 how wide and tall a box cursor should be displayed).
18552 At the same time this space let's a nicely handle clearing to the
18553 end of the line if the row ends in italic text. */
18556 append_space_for_newline (struct it
*it
, int default_face_p
)
18558 if (FRAME_WINDOW_P (it
->f
))
18560 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18562 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18563 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18565 /* Save some values that must not be changed.
18566 Must save IT->c and IT->len because otherwise
18567 ITERATOR_AT_END_P wouldn't work anymore after
18568 append_space_for_newline has been called. */
18569 enum display_element_type saved_what
= it
->what
;
18570 int saved_c
= it
->c
, saved_len
= it
->len
;
18571 int saved_char_to_display
= it
->char_to_display
;
18572 int saved_x
= it
->current_x
;
18573 int saved_face_id
= it
->face_id
;
18574 int saved_box_end
= it
->end_of_box_run_p
;
18575 struct text_pos saved_pos
;
18576 Lisp_Object saved_object
;
18579 saved_object
= it
->object
;
18580 saved_pos
= it
->position
;
18582 it
->what
= IT_CHARACTER
;
18583 memset (&it
->position
, 0, sizeof it
->position
);
18584 it
->object
= make_number (0);
18585 it
->c
= it
->char_to_display
= ' ';
18588 /* If the default face was remapped, be sure to use the
18589 remapped face for the appended newline. */
18590 if (default_face_p
)
18591 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18592 else if (it
->face_before_selective_p
)
18593 it
->face_id
= it
->saved_face_id
;
18594 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18595 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18596 /* In R2L rows, we will prepend a stretch glyph that will
18597 have the end_of_box_run_p flag set for it, so there's no
18598 need for the appended newline glyph to have that flag
18600 if (it
->glyph_row
->reversed_p
18601 /* But if the appended newline glyph goes all the way to
18602 the end of the row, there will be no stretch glyph,
18603 so leave the box flag set. */
18604 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18605 it
->end_of_box_run_p
= 0;
18607 PRODUCE_GLYPHS (it
);
18609 it
->override_ascent
= -1;
18610 it
->constrain_row_ascent_descent_p
= 0;
18611 it
->current_x
= saved_x
;
18612 it
->object
= saved_object
;
18613 it
->position
= saved_pos
;
18614 it
->what
= saved_what
;
18615 it
->face_id
= saved_face_id
;
18616 it
->len
= saved_len
;
18618 it
->char_to_display
= saved_char_to_display
;
18619 it
->end_of_box_run_p
= saved_box_end
;
18628 /* Extend the face of the last glyph in the text area of IT->glyph_row
18629 to the end of the display line. Called from display_line. If the
18630 glyph row is empty, add a space glyph to it so that we know the
18631 face to draw. Set the glyph row flag fill_line_p. If the glyph
18632 row is R2L, prepend a stretch glyph to cover the empty space to the
18633 left of the leftmost glyph. */
18636 extend_face_to_end_of_line (struct it
*it
)
18638 struct face
*face
, *default_face
;
18639 struct frame
*f
= it
->f
;
18641 /* If line is already filled, do nothing. Non window-system frames
18642 get a grace of one more ``pixel'' because their characters are
18643 1-``pixel'' wide, so they hit the equality too early. This grace
18644 is needed only for R2L rows that are not continued, to produce
18645 one extra blank where we could display the cursor. */
18646 if (it
->current_x
>= it
->last_visible_x
18647 + (!FRAME_WINDOW_P (f
)
18648 && it
->glyph_row
->reversed_p
18649 && !it
->glyph_row
->continued_p
))
18652 /* The default face, possibly remapped. */
18653 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18655 /* Face extension extends the background and box of IT->face_id
18656 to the end of the line. If the background equals the background
18657 of the frame, we don't have to do anything. */
18658 if (it
->face_before_selective_p
)
18659 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18661 face
= FACE_FROM_ID (f
, it
->face_id
);
18663 if (FRAME_WINDOW_P (f
)
18664 && it
->glyph_row
->displays_text_p
18665 && face
->box
== FACE_NO_BOX
18666 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18668 && !it
->glyph_row
->reversed_p
)
18671 /* Set the glyph row flag indicating that the face of the last glyph
18672 in the text area has to be drawn to the end of the text area. */
18673 it
->glyph_row
->fill_line_p
= 1;
18675 /* If current character of IT is not ASCII, make sure we have the
18676 ASCII face. This will be automatically undone the next time
18677 get_next_display_element returns a multibyte character. Note
18678 that the character will always be single byte in unibyte
18680 if (!ASCII_CHAR_P (it
->c
))
18682 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18685 if (FRAME_WINDOW_P (f
))
18687 /* If the row is empty, add a space with the current face of IT,
18688 so that we know which face to draw. */
18689 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18691 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18692 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18693 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18695 #ifdef HAVE_WINDOW_SYSTEM
18696 if (it
->glyph_row
->reversed_p
)
18698 /* Prepend a stretch glyph to the row, such that the
18699 rightmost glyph will be drawn flushed all the way to the
18700 right margin of the window. The stretch glyph that will
18701 occupy the empty space, if any, to the left of the
18703 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18704 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18705 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18707 int row_width
, stretch_ascent
, stretch_width
;
18708 struct text_pos saved_pos
;
18709 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18711 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18712 row_width
+= g
->pixel_width
;
18713 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18714 if (stretch_width
> 0)
18717 (((it
->ascent
+ it
->descent
)
18718 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18719 saved_pos
= it
->position
;
18720 memset (&it
->position
, 0, sizeof it
->position
);
18721 saved_avoid_cursor
= it
->avoid_cursor_p
;
18722 it
->avoid_cursor_p
= 1;
18723 saved_face_id
= it
->face_id
;
18724 saved_box_start
= it
->start_of_box_run_p
;
18725 /* The last row's stretch glyph should get the default
18726 face, to avoid painting the rest of the window with
18727 the region face, if the region ends at ZV. */
18728 if (it
->glyph_row
->ends_at_zv_p
)
18729 it
->face_id
= default_face
->id
;
18731 it
->face_id
= face
->id
;
18732 it
->start_of_box_run_p
= 0;
18733 append_stretch_glyph (it
, make_number (0), stretch_width
,
18734 it
->ascent
+ it
->descent
, stretch_ascent
);
18735 it
->position
= saved_pos
;
18736 it
->avoid_cursor_p
= saved_avoid_cursor
;
18737 it
->face_id
= saved_face_id
;
18738 it
->start_of_box_run_p
= saved_box_start
;
18741 #endif /* HAVE_WINDOW_SYSTEM */
18745 /* Save some values that must not be changed. */
18746 int saved_x
= it
->current_x
;
18747 struct text_pos saved_pos
;
18748 Lisp_Object saved_object
;
18749 enum display_element_type saved_what
= it
->what
;
18750 int saved_face_id
= it
->face_id
;
18752 saved_object
= it
->object
;
18753 saved_pos
= it
->position
;
18755 it
->what
= IT_CHARACTER
;
18756 memset (&it
->position
, 0, sizeof it
->position
);
18757 it
->object
= make_number (0);
18758 it
->c
= it
->char_to_display
= ' ';
18760 /* The last row's blank glyphs should get the default face, to
18761 avoid painting the rest of the window with the region face,
18762 if the region ends at ZV. */
18763 if (it
->glyph_row
->ends_at_zv_p
)
18764 it
->face_id
= default_face
->id
;
18766 it
->face_id
= face
->id
;
18768 PRODUCE_GLYPHS (it
);
18770 while (it
->current_x
<= it
->last_visible_x
)
18771 PRODUCE_GLYPHS (it
);
18773 /* Don't count these blanks really. It would let us insert a left
18774 truncation glyph below and make us set the cursor on them, maybe. */
18775 it
->current_x
= saved_x
;
18776 it
->object
= saved_object
;
18777 it
->position
= saved_pos
;
18778 it
->what
= saved_what
;
18779 it
->face_id
= saved_face_id
;
18784 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18785 trailing whitespace. */
18788 trailing_whitespace_p (ptrdiff_t charpos
)
18790 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18793 while (bytepos
< ZV_BYTE
18794 && (c
= FETCH_CHAR (bytepos
),
18795 c
== ' ' || c
== '\t'))
18798 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18800 if (bytepos
!= PT_BYTE
)
18807 /* Highlight trailing whitespace, if any, in ROW. */
18810 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18812 int used
= row
->used
[TEXT_AREA
];
18816 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18817 struct glyph
*glyph
= start
+ used
- 1;
18819 if (row
->reversed_p
)
18821 /* Right-to-left rows need to be processed in the opposite
18822 direction, so swap the edge pointers. */
18824 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18827 /* Skip over glyphs inserted to display the cursor at the
18828 end of a line, for extending the face of the last glyph
18829 to the end of the line on terminals, and for truncation
18830 and continuation glyphs. */
18831 if (!row
->reversed_p
)
18833 while (glyph
>= start
18834 && glyph
->type
== CHAR_GLYPH
18835 && INTEGERP (glyph
->object
))
18840 while (glyph
<= start
18841 && glyph
->type
== CHAR_GLYPH
18842 && INTEGERP (glyph
->object
))
18846 /* If last glyph is a space or stretch, and it's trailing
18847 whitespace, set the face of all trailing whitespace glyphs in
18848 IT->glyph_row to `trailing-whitespace'. */
18849 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18850 && BUFFERP (glyph
->object
)
18851 && (glyph
->type
== STRETCH_GLYPH
18852 || (glyph
->type
== CHAR_GLYPH
18853 && glyph
->u
.ch
== ' '))
18854 && trailing_whitespace_p (glyph
->charpos
))
18856 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18860 if (!row
->reversed_p
)
18862 while (glyph
>= start
18863 && BUFFERP (glyph
->object
)
18864 && (glyph
->type
== STRETCH_GLYPH
18865 || (glyph
->type
== CHAR_GLYPH
18866 && glyph
->u
.ch
== ' ')))
18867 (glyph
--)->face_id
= face_id
;
18871 while (glyph
<= start
18872 && BUFFERP (glyph
->object
)
18873 && (glyph
->type
== STRETCH_GLYPH
18874 || (glyph
->type
== CHAR_GLYPH
18875 && glyph
->u
.ch
== ' ')))
18876 (glyph
++)->face_id
= face_id
;
18883 /* Value is non-zero if glyph row ROW should be
18884 used to hold the cursor. */
18887 cursor_row_p (struct glyph_row
*row
)
18891 if (PT
== CHARPOS (row
->end
.pos
)
18892 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18894 /* Suppose the row ends on a string.
18895 Unless the row is continued, that means it ends on a newline
18896 in the string. If it's anything other than a display string
18897 (e.g., a before-string from an overlay), we don't want the
18898 cursor there. (This heuristic seems to give the optimal
18899 behavior for the various types of multi-line strings.)
18900 One exception: if the string has `cursor' property on one of
18901 its characters, we _do_ want the cursor there. */
18902 if (CHARPOS (row
->end
.string_pos
) >= 0)
18904 if (row
->continued_p
)
18908 /* Check for `display' property. */
18909 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18910 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18911 struct glyph
*glyph
;
18914 for (glyph
= end
; glyph
>= beg
; --glyph
)
18915 if (STRINGP (glyph
->object
))
18918 = Fget_char_property (make_number (PT
),
18922 && display_prop_string_p (prop
, glyph
->object
));
18923 /* If there's a `cursor' property on one of the
18924 string's characters, this row is a cursor row,
18925 even though this is not a display string. */
18928 Lisp_Object s
= glyph
->object
;
18930 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18932 ptrdiff_t gpos
= glyph
->charpos
;
18934 if (!NILP (Fget_char_property (make_number (gpos
),
18946 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18948 /* If the row ends in middle of a real character,
18949 and the line is continued, we want the cursor here.
18950 That's because CHARPOS (ROW->end.pos) would equal
18951 PT if PT is before the character. */
18952 if (!row
->ends_in_ellipsis_p
)
18953 result
= row
->continued_p
;
18955 /* If the row ends in an ellipsis, then
18956 CHARPOS (ROW->end.pos) will equal point after the
18957 invisible text. We want that position to be displayed
18958 after the ellipsis. */
18961 /* If the row ends at ZV, display the cursor at the end of that
18962 row instead of at the start of the row below. */
18963 else if (row
->ends_at_zv_p
)
18974 /* Push the property PROP so that it will be rendered at the current
18975 position in IT. Return 1 if PROP was successfully pushed, 0
18976 otherwise. Called from handle_line_prefix to handle the
18977 `line-prefix' and `wrap-prefix' properties. */
18980 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18982 struct text_pos pos
=
18983 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18985 eassert (it
->method
== GET_FROM_BUFFER
18986 || it
->method
== GET_FROM_DISPLAY_VECTOR
18987 || it
->method
== GET_FROM_STRING
);
18989 /* We need to save the current buffer/string position, so it will be
18990 restored by pop_it, because iterate_out_of_display_property
18991 depends on that being set correctly, but some situations leave
18992 it->position not yet set when this function is called. */
18993 push_it (it
, &pos
);
18995 if (STRINGP (prop
))
18997 if (SCHARS (prop
) == 0)
19004 it
->string_from_prefix_prop_p
= 1;
19005 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19006 it
->current
.overlay_string_index
= -1;
19007 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19008 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19009 it
->method
= GET_FROM_STRING
;
19010 it
->stop_charpos
= 0;
19012 it
->base_level_stop
= 0;
19014 /* Force paragraph direction to be that of the parent
19016 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19017 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19019 it
->paragraph_embedding
= L2R
;
19021 /* Set up the bidi iterator for this display string. */
19024 it
->bidi_it
.string
.lstring
= it
->string
;
19025 it
->bidi_it
.string
.s
= NULL
;
19026 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19027 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19028 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19029 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19030 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19033 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19035 it
->method
= GET_FROM_STRETCH
;
19038 #ifdef HAVE_WINDOW_SYSTEM
19039 else if (IMAGEP (prop
))
19041 it
->what
= IT_IMAGE
;
19042 it
->image_id
= lookup_image (it
->f
, prop
);
19043 it
->method
= GET_FROM_IMAGE
;
19045 #endif /* HAVE_WINDOW_SYSTEM */
19048 pop_it (it
); /* bogus display property, give up */
19055 /* Return the character-property PROP at the current position in IT. */
19058 get_it_property (struct it
*it
, Lisp_Object prop
)
19060 Lisp_Object position
;
19062 if (STRINGP (it
->object
))
19063 position
= make_number (IT_STRING_CHARPOS (*it
));
19064 else if (BUFFERP (it
->object
))
19065 position
= make_number (IT_CHARPOS (*it
));
19069 return Fget_char_property (position
, prop
, it
->object
);
19072 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19075 handle_line_prefix (struct it
*it
)
19077 Lisp_Object prefix
;
19079 if (it
->continuation_lines_width
> 0)
19081 prefix
= get_it_property (it
, Qwrap_prefix
);
19083 prefix
= Vwrap_prefix
;
19087 prefix
= get_it_property (it
, Qline_prefix
);
19089 prefix
= Vline_prefix
;
19091 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19093 /* If the prefix is wider than the window, and we try to wrap
19094 it, it would acquire its own wrap prefix, and so on till the
19095 iterator stack overflows. So, don't wrap the prefix. */
19096 it
->line_wrap
= TRUNCATE
;
19097 it
->avoid_cursor_p
= 1;
19103 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19104 only for R2L lines from display_line and display_string, when they
19105 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19106 the line/string needs to be continued on the next glyph row. */
19108 unproduce_glyphs (struct it
*it
, int n
)
19110 struct glyph
*glyph
, *end
;
19112 eassert (it
->glyph_row
);
19113 eassert (it
->glyph_row
->reversed_p
);
19114 eassert (it
->area
== TEXT_AREA
);
19115 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19117 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19118 n
= it
->glyph_row
->used
[TEXT_AREA
];
19119 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19120 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19121 for ( ; glyph
< end
; glyph
++)
19122 glyph
[-n
] = *glyph
;
19125 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19126 and ROW->maxpos. */
19128 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19129 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19130 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19132 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19133 lines' rows is implemented for bidi-reordered rows. */
19135 /* ROW->minpos is the value of min_pos, the minimal buffer position
19136 we have in ROW, or ROW->start.pos if that is smaller. */
19137 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19138 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19140 /* We didn't find buffer positions smaller than ROW->start, or
19141 didn't find _any_ valid buffer positions in any of the glyphs,
19142 so we must trust the iterator's computed positions. */
19143 row
->minpos
= row
->start
.pos
;
19146 max_pos
= CHARPOS (it
->current
.pos
);
19147 max_bpos
= BYTEPOS (it
->current
.pos
);
19150 /* Here are the various use-cases for ending the row, and the
19151 corresponding values for ROW->maxpos:
19153 Line ends in a newline from buffer eol_pos + 1
19154 Line is continued from buffer max_pos + 1
19155 Line is truncated on right it->current.pos
19156 Line ends in a newline from string max_pos + 1(*)
19157 (*) + 1 only when line ends in a forward scan
19158 Line is continued from string max_pos
19159 Line is continued from display vector max_pos
19160 Line is entirely from a string min_pos == max_pos
19161 Line is entirely from a display vector min_pos == max_pos
19162 Line that ends at ZV ZV
19164 If you discover other use-cases, please add them here as
19166 if (row
->ends_at_zv_p
)
19167 row
->maxpos
= it
->current
.pos
;
19168 else if (row
->used
[TEXT_AREA
])
19170 int seen_this_string
= 0;
19171 struct glyph_row
*r1
= row
- 1;
19173 /* Did we see the same display string on the previous row? */
19174 if (STRINGP (it
->object
)
19175 /* this is not the first row */
19176 && row
> it
->w
->desired_matrix
->rows
19177 /* previous row is not the header line */
19178 && !r1
->mode_line_p
19179 /* previous row also ends in a newline from a string */
19180 && r1
->ends_in_newline_from_string_p
)
19182 struct glyph
*start
, *end
;
19184 /* Search for the last glyph of the previous row that came
19185 from buffer or string. Depending on whether the row is
19186 L2R or R2L, we need to process it front to back or the
19187 other way round. */
19188 if (!r1
->reversed_p
)
19190 start
= r1
->glyphs
[TEXT_AREA
];
19191 end
= start
+ r1
->used
[TEXT_AREA
];
19192 /* Glyphs inserted by redisplay have an integer (zero)
19193 as their object. */
19195 && INTEGERP ((end
- 1)->object
)
19196 && (end
- 1)->charpos
<= 0)
19200 if (EQ ((end
- 1)->object
, it
->object
))
19201 seen_this_string
= 1;
19204 /* If all the glyphs of the previous row were inserted
19205 by redisplay, it means the previous row was
19206 produced from a single newline, which is only
19207 possible if that newline came from the same string
19208 as the one which produced this ROW. */
19209 seen_this_string
= 1;
19213 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19214 start
= end
+ r1
->used
[TEXT_AREA
];
19216 && INTEGERP ((end
+ 1)->object
)
19217 && (end
+ 1)->charpos
<= 0)
19221 if (EQ ((end
+ 1)->object
, it
->object
))
19222 seen_this_string
= 1;
19225 seen_this_string
= 1;
19228 /* Take note of each display string that covers a newline only
19229 once, the first time we see it. This is for when a display
19230 string includes more than one newline in it. */
19231 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19233 /* If we were scanning the buffer forward when we displayed
19234 the string, we want to account for at least one buffer
19235 position that belongs to this row (position covered by
19236 the display string), so that cursor positioning will
19237 consider this row as a candidate when point is at the end
19238 of the visual line represented by this row. This is not
19239 required when scanning back, because max_pos will already
19240 have a much larger value. */
19241 if (CHARPOS (row
->end
.pos
) > max_pos
)
19242 INC_BOTH (max_pos
, max_bpos
);
19243 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19245 else if (CHARPOS (it
->eol_pos
) > 0)
19246 SET_TEXT_POS (row
->maxpos
,
19247 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19248 else if (row
->continued_p
)
19250 /* If max_pos is different from IT's current position, it
19251 means IT->method does not belong to the display element
19252 at max_pos. However, it also means that the display
19253 element at max_pos was displayed in its entirety on this
19254 line, which is equivalent to saying that the next line
19255 starts at the next buffer position. */
19256 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19257 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19260 INC_BOTH (max_pos
, max_bpos
);
19261 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19264 else if (row
->truncated_on_right_p
)
19265 /* display_line already called reseat_at_next_visible_line_start,
19266 which puts the iterator at the beginning of the next line, in
19267 the logical order. */
19268 row
->maxpos
= it
->current
.pos
;
19269 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19270 /* A line that is entirely from a string/image/stretch... */
19271 row
->maxpos
= row
->minpos
;
19276 row
->maxpos
= it
->current
.pos
;
19279 /* Construct the glyph row IT->glyph_row in the desired matrix of
19280 IT->w from text at the current position of IT. See dispextern.h
19281 for an overview of struct it. Value is non-zero if
19282 IT->glyph_row displays text, as opposed to a line displaying ZV
19286 display_line (struct it
*it
)
19288 struct glyph_row
*row
= it
->glyph_row
;
19289 Lisp_Object overlay_arrow_string
;
19291 void *wrap_data
= NULL
;
19292 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19293 int wrap_row_used
= -1;
19294 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19295 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19296 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19297 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19298 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19300 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19301 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19303 /* We always start displaying at hpos zero even if hscrolled. */
19304 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19306 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19307 >= it
->w
->desired_matrix
->nrows
)
19309 it
->w
->nrows_scale_factor
++;
19310 fonts_changed_p
= 1;
19314 /* Is IT->w showing the region? */
19315 wset_region_showing (it
->w
, it
->region_beg_charpos
> 0 ? Qt
: Qnil
);
19317 /* Clear the result glyph row and enable it. */
19318 prepare_desired_row (row
);
19320 row
->y
= it
->current_y
;
19321 row
->start
= it
->start
;
19322 row
->continuation_lines_width
= it
->continuation_lines_width
;
19323 row
->displays_text_p
= 1;
19324 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19325 it
->starts_in_middle_of_char_p
= 0;
19327 /* Arrange the overlays nicely for our purposes. Usually, we call
19328 display_line on only one line at a time, in which case this
19329 can't really hurt too much, or we call it on lines which appear
19330 one after another in the buffer, in which case all calls to
19331 recenter_overlay_lists but the first will be pretty cheap. */
19332 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19334 /* Move over display elements that are not visible because we are
19335 hscrolled. This may stop at an x-position < IT->first_visible_x
19336 if the first glyph is partially visible or if we hit a line end. */
19337 if (it
->current_x
< it
->first_visible_x
)
19339 enum move_it_result move_result
;
19341 this_line_min_pos
= row
->start
.pos
;
19342 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19343 MOVE_TO_POS
| MOVE_TO_X
);
19344 /* If we are under a large hscroll, move_it_in_display_line_to
19345 could hit the end of the line without reaching
19346 it->first_visible_x. Pretend that we did reach it. This is
19347 especially important on a TTY, where we will call
19348 extend_face_to_end_of_line, which needs to know how many
19349 blank glyphs to produce. */
19350 if (it
->current_x
< it
->first_visible_x
19351 && (move_result
== MOVE_NEWLINE_OR_CR
19352 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19353 it
->current_x
= it
->first_visible_x
;
19355 /* Record the smallest positions seen while we moved over
19356 display elements that are not visible. This is needed by
19357 redisplay_internal for optimizing the case where the cursor
19358 stays inside the same line. The rest of this function only
19359 considers positions that are actually displayed, so
19360 RECORD_MAX_MIN_POS will not otherwise record positions that
19361 are hscrolled to the left of the left edge of the window. */
19362 min_pos
= CHARPOS (this_line_min_pos
);
19363 min_bpos
= BYTEPOS (this_line_min_pos
);
19367 /* We only do this when not calling `move_it_in_display_line_to'
19368 above, because move_it_in_display_line_to calls
19369 handle_line_prefix itself. */
19370 handle_line_prefix (it
);
19373 /* Get the initial row height. This is either the height of the
19374 text hscrolled, if there is any, or zero. */
19375 row
->ascent
= it
->max_ascent
;
19376 row
->height
= it
->max_ascent
+ it
->max_descent
;
19377 row
->phys_ascent
= it
->max_phys_ascent
;
19378 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19379 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19381 /* Utility macro to record max and min buffer positions seen until now. */
19382 #define RECORD_MAX_MIN_POS(IT) \
19385 int composition_p = !STRINGP ((IT)->string) \
19386 && ((IT)->what == IT_COMPOSITION); \
19387 ptrdiff_t current_pos = \
19388 composition_p ? (IT)->cmp_it.charpos \
19389 : IT_CHARPOS (*(IT)); \
19390 ptrdiff_t current_bpos = \
19391 composition_p ? CHAR_TO_BYTE (current_pos) \
19392 : IT_BYTEPOS (*(IT)); \
19393 if (current_pos < min_pos) \
19395 min_pos = current_pos; \
19396 min_bpos = current_bpos; \
19398 if (IT_CHARPOS (*it) > max_pos) \
19400 max_pos = IT_CHARPOS (*it); \
19401 max_bpos = IT_BYTEPOS (*it); \
19406 /* Loop generating characters. The loop is left with IT on the next
19407 character to display. */
19410 int n_glyphs_before
, hpos_before
, x_before
;
19412 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19414 /* Retrieve the next thing to display. Value is zero if end of
19416 if (!get_next_display_element (it
))
19418 /* Maybe add a space at the end of this line that is used to
19419 display the cursor there under X. Set the charpos of the
19420 first glyph of blank lines not corresponding to any text
19422 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19423 row
->exact_window_width_line_p
= 1;
19424 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19425 || row
->used
[TEXT_AREA
] == 0)
19427 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19428 row
->displays_text_p
= 0;
19430 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19431 && (!MINI_WINDOW_P (it
->w
)
19432 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19433 row
->indicate_empty_line_p
= 1;
19436 it
->continuation_lines_width
= 0;
19437 row
->ends_at_zv_p
= 1;
19438 /* A row that displays right-to-left text must always have
19439 its last face extended all the way to the end of line,
19440 even if this row ends in ZV, because we still write to
19441 the screen left to right. We also need to extend the
19442 last face if the default face is remapped to some
19443 different face, otherwise the functions that clear
19444 portions of the screen will clear with the default face's
19445 background color. */
19446 if (row
->reversed_p
19447 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19448 extend_face_to_end_of_line (it
);
19452 /* Now, get the metrics of what we want to display. This also
19453 generates glyphs in `row' (which is IT->glyph_row). */
19454 n_glyphs_before
= row
->used
[TEXT_AREA
];
19457 /* Remember the line height so far in case the next element doesn't
19458 fit on the line. */
19459 if (it
->line_wrap
!= TRUNCATE
)
19461 ascent
= it
->max_ascent
;
19462 descent
= it
->max_descent
;
19463 phys_ascent
= it
->max_phys_ascent
;
19464 phys_descent
= it
->max_phys_descent
;
19466 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19468 if (IT_DISPLAYING_WHITESPACE (it
))
19472 SAVE_IT (wrap_it
, *it
, wrap_data
);
19474 wrap_row_used
= row
->used
[TEXT_AREA
];
19475 wrap_row_ascent
= row
->ascent
;
19476 wrap_row_height
= row
->height
;
19477 wrap_row_phys_ascent
= row
->phys_ascent
;
19478 wrap_row_phys_height
= row
->phys_height
;
19479 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19480 wrap_row_min_pos
= min_pos
;
19481 wrap_row_min_bpos
= min_bpos
;
19482 wrap_row_max_pos
= max_pos
;
19483 wrap_row_max_bpos
= max_bpos
;
19489 PRODUCE_GLYPHS (it
);
19491 /* If this display element was in marginal areas, continue with
19493 if (it
->area
!= TEXT_AREA
)
19495 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19496 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19497 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19498 row
->phys_height
= max (row
->phys_height
,
19499 it
->max_phys_ascent
+ it
->max_phys_descent
);
19500 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19501 it
->max_extra_line_spacing
);
19502 set_iterator_to_next (it
, 1);
19506 /* Does the display element fit on the line? If we truncate
19507 lines, we should draw past the right edge of the window. If
19508 we don't truncate, we want to stop so that we can display the
19509 continuation glyph before the right margin. If lines are
19510 continued, there are two possible strategies for characters
19511 resulting in more than 1 glyph (e.g. tabs): Display as many
19512 glyphs as possible in this line and leave the rest for the
19513 continuation line, or display the whole element in the next
19514 line. Original redisplay did the former, so we do it also. */
19515 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19516 hpos_before
= it
->hpos
;
19519 if (/* Not a newline. */
19521 /* Glyphs produced fit entirely in the line. */
19522 && it
->current_x
< it
->last_visible_x
)
19524 it
->hpos
+= nglyphs
;
19525 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19526 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19527 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19528 row
->phys_height
= max (row
->phys_height
,
19529 it
->max_phys_ascent
+ it
->max_phys_descent
);
19530 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19531 it
->max_extra_line_spacing
);
19532 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19533 row
->x
= x
- it
->first_visible_x
;
19534 /* Record the maximum and minimum buffer positions seen so
19535 far in glyphs that will be displayed by this row. */
19537 RECORD_MAX_MIN_POS (it
);
19542 struct glyph
*glyph
;
19544 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19546 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19547 new_x
= x
+ glyph
->pixel_width
;
19549 if (/* Lines are continued. */
19550 it
->line_wrap
!= TRUNCATE
19551 && (/* Glyph doesn't fit on the line. */
19552 new_x
> it
->last_visible_x
19553 /* Or it fits exactly on a window system frame. */
19554 || (new_x
== it
->last_visible_x
19555 && FRAME_WINDOW_P (it
->f
)
19556 && (row
->reversed_p
19557 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19558 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19560 /* End of a continued line. */
19563 || (new_x
== it
->last_visible_x
19564 && FRAME_WINDOW_P (it
->f
)
19565 && (row
->reversed_p
19566 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19567 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19569 /* Current glyph is the only one on the line or
19570 fits exactly on the line. We must continue
19571 the line because we can't draw the cursor
19572 after the glyph. */
19573 row
->continued_p
= 1;
19574 it
->current_x
= new_x
;
19575 it
->continuation_lines_width
+= new_x
;
19577 if (i
== nglyphs
- 1)
19579 /* If line-wrap is on, check if a previous
19580 wrap point was found. */
19581 if (wrap_row_used
> 0
19582 /* Even if there is a previous wrap
19583 point, continue the line here as
19584 usual, if (i) the previous character
19585 was a space or tab AND (ii) the
19586 current character is not. */
19588 || IT_DISPLAYING_WHITESPACE (it
)))
19591 /* Record the maximum and minimum buffer
19592 positions seen so far in glyphs that will be
19593 displayed by this row. */
19595 RECORD_MAX_MIN_POS (it
);
19596 set_iterator_to_next (it
, 1);
19597 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19599 if (!get_next_display_element (it
))
19601 row
->exact_window_width_line_p
= 1;
19602 it
->continuation_lines_width
= 0;
19603 row
->continued_p
= 0;
19604 row
->ends_at_zv_p
= 1;
19606 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19608 row
->continued_p
= 0;
19609 row
->exact_window_width_line_p
= 1;
19613 else if (it
->bidi_p
)
19614 RECORD_MAX_MIN_POS (it
);
19616 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19617 && !FRAME_WINDOW_P (it
->f
))
19619 /* A padding glyph that doesn't fit on this line.
19620 This means the whole character doesn't fit
19622 if (row
->reversed_p
)
19623 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19624 - n_glyphs_before
);
19625 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19627 /* Fill the rest of the row with continuation
19628 glyphs like in 20.x. */
19629 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19630 < row
->glyphs
[1 + TEXT_AREA
])
19631 produce_special_glyphs (it
, IT_CONTINUATION
);
19633 row
->continued_p
= 1;
19634 it
->current_x
= x_before
;
19635 it
->continuation_lines_width
+= x_before
;
19637 /* Restore the height to what it was before the
19638 element not fitting on the line. */
19639 it
->max_ascent
= ascent
;
19640 it
->max_descent
= descent
;
19641 it
->max_phys_ascent
= phys_ascent
;
19642 it
->max_phys_descent
= phys_descent
;
19644 else if (wrap_row_used
> 0)
19647 if (row
->reversed_p
)
19648 unproduce_glyphs (it
,
19649 row
->used
[TEXT_AREA
] - wrap_row_used
);
19650 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19651 it
->continuation_lines_width
+= wrap_x
;
19652 row
->used
[TEXT_AREA
] = wrap_row_used
;
19653 row
->ascent
= wrap_row_ascent
;
19654 row
->height
= wrap_row_height
;
19655 row
->phys_ascent
= wrap_row_phys_ascent
;
19656 row
->phys_height
= wrap_row_phys_height
;
19657 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19658 min_pos
= wrap_row_min_pos
;
19659 min_bpos
= wrap_row_min_bpos
;
19660 max_pos
= wrap_row_max_pos
;
19661 max_bpos
= wrap_row_max_bpos
;
19662 row
->continued_p
= 1;
19663 row
->ends_at_zv_p
= 0;
19664 row
->exact_window_width_line_p
= 0;
19665 it
->continuation_lines_width
+= x
;
19667 /* Make sure that a non-default face is extended
19668 up to the right margin of the window. */
19669 extend_face_to_end_of_line (it
);
19671 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19673 /* A TAB that extends past the right edge of the
19674 window. This produces a single glyph on
19675 window system frames. We leave the glyph in
19676 this row and let it fill the row, but don't
19677 consume the TAB. */
19678 if ((row
->reversed_p
19679 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19680 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19681 produce_special_glyphs (it
, IT_CONTINUATION
);
19682 it
->continuation_lines_width
+= it
->last_visible_x
;
19683 row
->ends_in_middle_of_char_p
= 1;
19684 row
->continued_p
= 1;
19685 glyph
->pixel_width
= it
->last_visible_x
- x
;
19686 it
->starts_in_middle_of_char_p
= 1;
19690 /* Something other than a TAB that draws past
19691 the right edge of the window. Restore
19692 positions to values before the element. */
19693 if (row
->reversed_p
)
19694 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19695 - (n_glyphs_before
+ i
));
19696 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19698 /* Display continuation glyphs. */
19699 it
->current_x
= x_before
;
19700 it
->continuation_lines_width
+= x
;
19701 if (!FRAME_WINDOW_P (it
->f
)
19702 || (row
->reversed_p
19703 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19704 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19705 produce_special_glyphs (it
, IT_CONTINUATION
);
19706 row
->continued_p
= 1;
19708 extend_face_to_end_of_line (it
);
19710 if (nglyphs
> 1 && i
> 0)
19712 row
->ends_in_middle_of_char_p
= 1;
19713 it
->starts_in_middle_of_char_p
= 1;
19716 /* Restore the height to what it was before the
19717 element not fitting on the line. */
19718 it
->max_ascent
= ascent
;
19719 it
->max_descent
= descent
;
19720 it
->max_phys_ascent
= phys_ascent
;
19721 it
->max_phys_descent
= phys_descent
;
19726 else if (new_x
> it
->first_visible_x
)
19728 /* Increment number of glyphs actually displayed. */
19731 /* Record the maximum and minimum buffer positions
19732 seen so far in glyphs that will be displayed by
19735 RECORD_MAX_MIN_POS (it
);
19737 if (x
< it
->first_visible_x
)
19738 /* Glyph is partially visible, i.e. row starts at
19739 negative X position. */
19740 row
->x
= x
- it
->first_visible_x
;
19744 /* Glyph is completely off the left margin of the
19745 window. This should not happen because of the
19746 move_it_in_display_line at the start of this
19747 function, unless the text display area of the
19748 window is empty. */
19749 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19752 /* Even if this display element produced no glyphs at all,
19753 we want to record its position. */
19754 if (it
->bidi_p
&& nglyphs
== 0)
19755 RECORD_MAX_MIN_POS (it
);
19757 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19758 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19759 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19760 row
->phys_height
= max (row
->phys_height
,
19761 it
->max_phys_ascent
+ it
->max_phys_descent
);
19762 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19763 it
->max_extra_line_spacing
);
19765 /* End of this display line if row is continued. */
19766 if (row
->continued_p
|| row
->ends_at_zv_p
)
19771 /* Is this a line end? If yes, we're also done, after making
19772 sure that a non-default face is extended up to the right
19773 margin of the window. */
19774 if (ITERATOR_AT_END_OF_LINE_P (it
))
19776 int used_before
= row
->used
[TEXT_AREA
];
19778 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19780 /* Add a space at the end of the line that is used to
19781 display the cursor there. */
19782 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19783 append_space_for_newline (it
, 0);
19785 /* Extend the face to the end of the line. */
19786 extend_face_to_end_of_line (it
);
19788 /* Make sure we have the position. */
19789 if (used_before
== 0)
19790 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19792 /* Record the position of the newline, for use in
19794 it
->eol_pos
= it
->current
.pos
;
19796 /* Consume the line end. This skips over invisible lines. */
19797 set_iterator_to_next (it
, 1);
19798 it
->continuation_lines_width
= 0;
19802 /* Proceed with next display element. Note that this skips
19803 over lines invisible because of selective display. */
19804 set_iterator_to_next (it
, 1);
19806 /* If we truncate lines, we are done when the last displayed
19807 glyphs reach past the right margin of the window. */
19808 if (it
->line_wrap
== TRUNCATE
19809 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19810 ? (it
->current_x
>= it
->last_visible_x
)
19811 : (it
->current_x
> it
->last_visible_x
)))
19813 /* Maybe add truncation glyphs. */
19814 if (!FRAME_WINDOW_P (it
->f
)
19815 || (row
->reversed_p
19816 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19817 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19821 if (!row
->reversed_p
)
19823 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19824 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19829 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19830 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19832 /* Remove any padding glyphs at the front of ROW, to
19833 make room for the truncation glyphs we will be
19834 adding below. The loop below always inserts at
19835 least one truncation glyph, so also remove the
19836 last glyph added to ROW. */
19837 unproduce_glyphs (it
, i
+ 1);
19838 /* Adjust i for the loop below. */
19839 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19842 it
->current_x
= x_before
;
19843 if (!FRAME_WINDOW_P (it
->f
))
19845 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19847 row
->used
[TEXT_AREA
] = i
;
19848 produce_special_glyphs (it
, IT_TRUNCATION
);
19853 row
->used
[TEXT_AREA
] = i
;
19854 produce_special_glyphs (it
, IT_TRUNCATION
);
19857 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19859 /* Don't truncate if we can overflow newline into fringe. */
19860 if (!get_next_display_element (it
))
19862 it
->continuation_lines_width
= 0;
19863 row
->ends_at_zv_p
= 1;
19864 row
->exact_window_width_line_p
= 1;
19867 if (ITERATOR_AT_END_OF_LINE_P (it
))
19869 row
->exact_window_width_line_p
= 1;
19870 goto at_end_of_line
;
19872 it
->current_x
= x_before
;
19875 row
->truncated_on_right_p
= 1;
19876 it
->continuation_lines_width
= 0;
19877 reseat_at_next_visible_line_start (it
, 0);
19878 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19879 it
->hpos
= hpos_before
;
19885 bidi_unshelve_cache (wrap_data
, 1);
19887 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19888 at the left window margin. */
19889 if (it
->first_visible_x
19890 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19892 if (!FRAME_WINDOW_P (it
->f
)
19893 || (row
->reversed_p
19894 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19895 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19896 insert_left_trunc_glyphs (it
);
19897 row
->truncated_on_left_p
= 1;
19900 /* Remember the position at which this line ends.
19902 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19903 cannot be before the call to find_row_edges below, since that is
19904 where these positions are determined. */
19905 row
->end
= it
->current
;
19908 row
->minpos
= row
->start
.pos
;
19909 row
->maxpos
= row
->end
.pos
;
19913 /* ROW->minpos and ROW->maxpos must be the smallest and
19914 `1 + the largest' buffer positions in ROW. But if ROW was
19915 bidi-reordered, these two positions can be anywhere in the
19916 row, so we must determine them now. */
19917 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19920 /* If the start of this line is the overlay arrow-position, then
19921 mark this glyph row as the one containing the overlay arrow.
19922 This is clearly a mess with variable size fonts. It would be
19923 better to let it be displayed like cursors under X. */
19924 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19925 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19926 !NILP (overlay_arrow_string
)))
19928 /* Overlay arrow in window redisplay is a fringe bitmap. */
19929 if (STRINGP (overlay_arrow_string
))
19931 struct glyph_row
*arrow_row
19932 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19933 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19934 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19935 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19936 struct glyph
*p2
, *end
;
19938 /* Copy the arrow glyphs. */
19939 while (glyph
< arrow_end
)
19942 /* Throw away padding glyphs. */
19944 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19945 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19951 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19956 eassert (INTEGERP (overlay_arrow_string
));
19957 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19959 overlay_arrow_seen
= 1;
19962 /* Highlight trailing whitespace. */
19963 if (!NILP (Vshow_trailing_whitespace
))
19964 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19966 /* Compute pixel dimensions of this line. */
19967 compute_line_metrics (it
);
19969 /* Implementation note: No changes in the glyphs of ROW or in their
19970 faces can be done past this point, because compute_line_metrics
19971 computes ROW's hash value and stores it within the glyph_row
19974 /* Record whether this row ends inside an ellipsis. */
19975 row
->ends_in_ellipsis_p
19976 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19977 && it
->ellipsis_p
);
19979 /* Save fringe bitmaps in this row. */
19980 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19981 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19982 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19983 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19985 it
->left_user_fringe_bitmap
= 0;
19986 it
->left_user_fringe_face_id
= 0;
19987 it
->right_user_fringe_bitmap
= 0;
19988 it
->right_user_fringe_face_id
= 0;
19990 /* Maybe set the cursor. */
19991 cvpos
= it
->w
->cursor
.vpos
;
19993 /* In bidi-reordered rows, keep checking for proper cursor
19994 position even if one has been found already, because buffer
19995 positions in such rows change non-linearly with ROW->VPOS,
19996 when a line is continued. One exception: when we are at ZV,
19997 display cursor on the first suitable glyph row, since all
19998 the empty rows after that also have their position set to ZV. */
19999 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20000 lines' rows is implemented for bidi-reordered rows. */
20002 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20003 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20004 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20005 && cursor_row_p (row
))
20006 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20008 /* Prepare for the next line. This line starts horizontally at (X
20009 HPOS) = (0 0). Vertical positions are incremented. As a
20010 convenience for the caller, IT->glyph_row is set to the next
20012 it
->current_x
= it
->hpos
= 0;
20013 it
->current_y
+= row
->height
;
20014 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20017 /* The next row should by default use the same value of the
20018 reversed_p flag as this one. set_iterator_to_next decides when
20019 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20020 the flag accordingly. */
20021 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20022 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20023 it
->start
= row
->end
;
20024 return row
->displays_text_p
;
20026 #undef RECORD_MAX_MIN_POS
20029 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20030 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20031 doc
: /* Return paragraph direction at point in BUFFER.
20032 Value is either `left-to-right' or `right-to-left'.
20033 If BUFFER is omitted or nil, it defaults to the current buffer.
20035 Paragraph direction determines how the text in the paragraph is displayed.
20036 In left-to-right paragraphs, text begins at the left margin of the window
20037 and the reading direction is generally left to right. In right-to-left
20038 paragraphs, text begins at the right margin and is read from right to left.
20040 See also `bidi-paragraph-direction'. */)
20041 (Lisp_Object buffer
)
20043 struct buffer
*buf
= current_buffer
;
20044 struct buffer
*old
= buf
;
20046 if (! NILP (buffer
))
20048 CHECK_BUFFER (buffer
);
20049 buf
= XBUFFER (buffer
);
20052 if (NILP (BVAR (buf
, bidi_display_reordering
))
20053 || NILP (BVAR (buf
, enable_multibyte_characters
))
20054 /* When we are loading loadup.el, the character property tables
20055 needed for bidi iteration are not yet available. */
20056 || !NILP (Vpurify_flag
))
20057 return Qleft_to_right
;
20058 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20059 return BVAR (buf
, bidi_paragraph_direction
);
20062 /* Determine the direction from buffer text. We could try to
20063 use current_matrix if it is up to date, but this seems fast
20064 enough as it is. */
20065 struct bidi_it itb
;
20066 ptrdiff_t pos
= BUF_PT (buf
);
20067 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20069 void *itb_data
= bidi_shelve_cache ();
20071 set_buffer_temp (buf
);
20072 /* bidi_paragraph_init finds the base direction of the paragraph
20073 by searching forward from paragraph start. We need the base
20074 direction of the current or _previous_ paragraph, so we need
20075 to make sure we are within that paragraph. To that end, find
20076 the previous non-empty line. */
20077 if (pos
>= ZV
&& pos
> BEGV
)
20080 bytepos
= CHAR_TO_BYTE (pos
);
20082 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20083 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20085 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20086 || c
== ' ' || c
== '\t' || c
== '\f')
20088 if (bytepos
<= BEGV_BYTE
)
20093 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20096 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20097 itb
.paragraph_dir
= NEUTRAL_DIR
;
20098 itb
.string
.s
= NULL
;
20099 itb
.string
.lstring
= Qnil
;
20100 itb
.string
.bufpos
= 0;
20101 itb
.string
.unibyte
= 0;
20102 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20103 bidi_unshelve_cache (itb_data
, 0);
20104 set_buffer_temp (old
);
20105 switch (itb
.paragraph_dir
)
20108 return Qleft_to_right
;
20111 return Qright_to_left
;
20121 /***********************************************************************
20123 ***********************************************************************/
20125 /* Redisplay the menu bar in the frame for window W.
20127 The menu bar of X frames that don't have X toolkit support is
20128 displayed in a special window W->frame->menu_bar_window.
20130 The menu bar of terminal frames is treated specially as far as
20131 glyph matrices are concerned. Menu bar lines are not part of
20132 windows, so the update is done directly on the frame matrix rows
20133 for the menu bar. */
20136 display_menu_bar (struct window
*w
)
20138 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20143 /* Don't do all this for graphical frames. */
20145 if (FRAME_W32_P (f
))
20148 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20154 if (FRAME_NS_P (f
))
20156 #endif /* HAVE_NS */
20158 #ifdef USE_X_TOOLKIT
20159 eassert (!FRAME_WINDOW_P (f
));
20160 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20161 it
.first_visible_x
= 0;
20162 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20163 #else /* not USE_X_TOOLKIT */
20164 if (FRAME_WINDOW_P (f
))
20166 /* Menu bar lines are displayed in the desired matrix of the
20167 dummy window menu_bar_window. */
20168 struct window
*menu_w
;
20169 eassert (WINDOWP (f
->menu_bar_window
));
20170 menu_w
= XWINDOW (f
->menu_bar_window
);
20171 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20173 it
.first_visible_x
= 0;
20174 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20178 /* This is a TTY frame, i.e. character hpos/vpos are used as
20180 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20182 it
.first_visible_x
= 0;
20183 it
.last_visible_x
= FRAME_COLS (f
);
20185 #endif /* not USE_X_TOOLKIT */
20187 /* FIXME: This should be controlled by a user option. See the
20188 comments in redisplay_tool_bar and display_mode_line about
20190 it
.paragraph_embedding
= L2R
;
20192 /* Clear all rows of the menu bar. */
20193 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20195 struct glyph_row
*row
= it
.glyph_row
+ i
;
20196 clear_glyph_row (row
);
20197 row
->enabled_p
= 1;
20198 row
->full_width_p
= 1;
20201 /* Display all items of the menu bar. */
20202 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20203 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20205 Lisp_Object string
;
20207 /* Stop at nil string. */
20208 string
= AREF (items
, i
+ 1);
20212 /* Remember where item was displayed. */
20213 ASET (items
, i
+ 3, make_number (it
.hpos
));
20215 /* Display the item, pad with one space. */
20216 if (it
.current_x
< it
.last_visible_x
)
20217 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20218 SCHARS (string
) + 1, 0, 0, -1);
20221 /* Fill out the line with spaces. */
20222 if (it
.current_x
< it
.last_visible_x
)
20223 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20225 /* Compute the total height of the lines. */
20226 compute_line_metrics (&it
);
20231 /***********************************************************************
20233 ***********************************************************************/
20235 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20236 FORCE is non-zero, redisplay mode lines unconditionally.
20237 Otherwise, redisplay only mode lines that are garbaged. Value is
20238 the number of windows whose mode lines were redisplayed. */
20241 redisplay_mode_lines (Lisp_Object window
, int force
)
20245 while (!NILP (window
))
20247 struct window
*w
= XWINDOW (window
);
20249 if (WINDOWP (w
->hchild
))
20250 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20251 else if (WINDOWP (w
->vchild
))
20252 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20254 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20255 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20257 struct text_pos lpoint
;
20258 struct buffer
*old
= current_buffer
;
20260 /* Set the window's buffer for the mode line display. */
20261 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20262 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20264 /* Point refers normally to the selected window. For any
20265 other window, set up appropriate value. */
20266 if (!EQ (window
, selected_window
))
20268 struct text_pos pt
;
20270 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20271 if (CHARPOS (pt
) < BEGV
)
20272 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20273 else if (CHARPOS (pt
) > (ZV
- 1))
20274 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20276 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20279 /* Display mode lines. */
20280 clear_glyph_matrix (w
->desired_matrix
);
20281 if (display_mode_lines (w
))
20284 w
->must_be_updated_p
= 1;
20287 /* Restore old settings. */
20288 set_buffer_internal_1 (old
);
20289 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20299 /* Display the mode and/or header line of window W. Value is the
20300 sum number of mode lines and header lines displayed. */
20303 display_mode_lines (struct window
*w
)
20305 Lisp_Object old_selected_window
= selected_window
;
20306 Lisp_Object old_selected_frame
= selected_frame
;
20307 Lisp_Object new_frame
= w
->frame
;
20308 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20311 selected_frame
= new_frame
;
20312 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20313 or window's point, then we'd need select_window_1 here as well. */
20314 XSETWINDOW (selected_window
, w
);
20315 XFRAME (new_frame
)->selected_window
= selected_window
;
20317 /* These will be set while the mode line specs are processed. */
20318 line_number_displayed
= 0;
20319 wset_column_number_displayed (w
, Qnil
);
20321 if (WINDOW_WANTS_MODELINE_P (w
))
20323 struct window
*sel_w
= XWINDOW (old_selected_window
);
20325 /* Select mode line face based on the real selected window. */
20326 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20327 BVAR (current_buffer
, mode_line_format
));
20331 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20333 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20334 BVAR (current_buffer
, header_line_format
));
20338 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20339 selected_frame
= old_selected_frame
;
20340 selected_window
= old_selected_window
;
20345 /* Display mode or header line of window W. FACE_ID specifies which
20346 line to display; it is either MODE_LINE_FACE_ID or
20347 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20348 display. Value is the pixel height of the mode/header line
20352 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20356 ptrdiff_t count
= SPECPDL_INDEX ();
20358 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20359 /* Don't extend on a previously drawn mode-line.
20360 This may happen if called from pos_visible_p. */
20361 it
.glyph_row
->enabled_p
= 0;
20362 prepare_desired_row (it
.glyph_row
);
20364 it
.glyph_row
->mode_line_p
= 1;
20366 /* FIXME: This should be controlled by a user option. But
20367 supporting such an option is not trivial, since the mode line is
20368 made up of many separate strings. */
20369 it
.paragraph_embedding
= L2R
;
20371 record_unwind_protect (unwind_format_mode_line
,
20372 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20374 mode_line_target
= MODE_LINE_DISPLAY
;
20376 /* Temporarily make frame's keyboard the current kboard so that
20377 kboard-local variables in the mode_line_format will get the right
20379 push_kboard (FRAME_KBOARD (it
.f
));
20380 record_unwind_save_match_data ();
20381 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20384 unbind_to (count
, Qnil
);
20386 /* Fill up with spaces. */
20387 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20389 compute_line_metrics (&it
);
20390 it
.glyph_row
->full_width_p
= 1;
20391 it
.glyph_row
->continued_p
= 0;
20392 it
.glyph_row
->truncated_on_left_p
= 0;
20393 it
.glyph_row
->truncated_on_right_p
= 0;
20395 /* Make a 3D mode-line have a shadow at its right end. */
20396 face
= FACE_FROM_ID (it
.f
, face_id
);
20397 extend_face_to_end_of_line (&it
);
20398 if (face
->box
!= FACE_NO_BOX
)
20400 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20401 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20402 last
->right_box_line_p
= 1;
20405 return it
.glyph_row
->height
;
20408 /* Move element ELT in LIST to the front of LIST.
20409 Return the updated list. */
20412 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20414 register Lisp_Object tail
, prev
;
20415 register Lisp_Object tem
;
20419 while (CONSP (tail
))
20425 /* Splice out the link TAIL. */
20427 list
= XCDR (tail
);
20429 Fsetcdr (prev
, XCDR (tail
));
20431 /* Now make it the first. */
20432 Fsetcdr (tail
, list
);
20437 tail
= XCDR (tail
);
20441 /* Not found--return unchanged LIST. */
20445 /* Contribute ELT to the mode line for window IT->w. How it
20446 translates into text depends on its data type.
20448 IT describes the display environment in which we display, as usual.
20450 DEPTH is the depth in recursion. It is used to prevent
20451 infinite recursion here.
20453 FIELD_WIDTH is the number of characters the display of ELT should
20454 occupy in the mode line, and PRECISION is the maximum number of
20455 characters to display from ELT's representation. See
20456 display_string for details.
20458 Returns the hpos of the end of the text generated by ELT.
20460 PROPS is a property list to add to any string we encounter.
20462 If RISKY is nonzero, remove (disregard) any properties in any string
20463 we encounter, and ignore :eval and :propertize.
20465 The global variable `mode_line_target' determines whether the
20466 output is passed to `store_mode_line_noprop',
20467 `store_mode_line_string', or `display_string'. */
20470 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20471 Lisp_Object elt
, Lisp_Object props
, int risky
)
20473 int n
= 0, field
, prec
;
20478 elt
= build_string ("*too-deep*");
20482 switch (XTYPE (elt
))
20486 /* A string: output it and check for %-constructs within it. */
20488 ptrdiff_t offset
= 0;
20490 if (SCHARS (elt
) > 0
20491 && (!NILP (props
) || risky
))
20493 Lisp_Object oprops
, aelt
;
20494 oprops
= Ftext_properties_at (make_number (0), elt
);
20496 /* If the starting string's properties are not what
20497 we want, translate the string. Also, if the string
20498 is risky, do that anyway. */
20500 if (NILP (Fequal (props
, oprops
)) || risky
)
20502 /* If the starting string has properties,
20503 merge the specified ones onto the existing ones. */
20504 if (! NILP (oprops
) && !risky
)
20508 oprops
= Fcopy_sequence (oprops
);
20510 while (CONSP (tem
))
20512 oprops
= Fplist_put (oprops
, XCAR (tem
),
20513 XCAR (XCDR (tem
)));
20514 tem
= XCDR (XCDR (tem
));
20519 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20520 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20522 /* AELT is what we want. Move it to the front
20523 without consing. */
20525 mode_line_proptrans_alist
20526 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20532 /* If AELT has the wrong props, it is useless.
20533 so get rid of it. */
20535 mode_line_proptrans_alist
20536 = Fdelq (aelt
, mode_line_proptrans_alist
);
20538 elt
= Fcopy_sequence (elt
);
20539 Fset_text_properties (make_number (0), Flength (elt
),
20541 /* Add this item to mode_line_proptrans_alist. */
20542 mode_line_proptrans_alist
20543 = Fcons (Fcons (elt
, props
),
20544 mode_line_proptrans_alist
);
20545 /* Truncate mode_line_proptrans_alist
20546 to at most 50 elements. */
20547 tem
= Fnthcdr (make_number (50),
20548 mode_line_proptrans_alist
);
20550 XSETCDR (tem
, Qnil
);
20559 prec
= precision
- n
;
20560 switch (mode_line_target
)
20562 case MODE_LINE_NOPROP
:
20563 case MODE_LINE_TITLE
:
20564 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20566 case MODE_LINE_STRING
:
20567 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20569 case MODE_LINE_DISPLAY
:
20570 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20571 0, prec
, 0, STRING_MULTIBYTE (elt
));
20578 /* Handle the non-literal case. */
20580 while ((precision
<= 0 || n
< precision
)
20581 && SREF (elt
, offset
) != 0
20582 && (mode_line_target
!= MODE_LINE_DISPLAY
20583 || it
->current_x
< it
->last_visible_x
))
20585 ptrdiff_t last_offset
= offset
;
20587 /* Advance to end of string or next format specifier. */
20588 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20591 if (offset
- 1 != last_offset
)
20593 ptrdiff_t nchars
, nbytes
;
20595 /* Output to end of string or up to '%'. Field width
20596 is length of string. Don't output more than
20597 PRECISION allows us. */
20600 prec
= c_string_width (SDATA (elt
) + last_offset
,
20601 offset
- last_offset
, precision
- n
,
20604 switch (mode_line_target
)
20606 case MODE_LINE_NOPROP
:
20607 case MODE_LINE_TITLE
:
20608 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20610 case MODE_LINE_STRING
:
20612 ptrdiff_t bytepos
= last_offset
;
20613 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20614 ptrdiff_t endpos
= (precision
<= 0
20615 ? string_byte_to_char (elt
, offset
)
20616 : charpos
+ nchars
);
20618 n
+= store_mode_line_string (NULL
,
20619 Fsubstring (elt
, make_number (charpos
),
20620 make_number (endpos
)),
20624 case MODE_LINE_DISPLAY
:
20626 ptrdiff_t bytepos
= last_offset
;
20627 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20629 if (precision
<= 0)
20630 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20631 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20633 STRING_MULTIBYTE (elt
));
20638 else /* c == '%' */
20640 ptrdiff_t percent_position
= offset
;
20642 /* Get the specified minimum width. Zero means
20645 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20646 field
= field
* 10 + c
- '0';
20648 /* Don't pad beyond the total padding allowed. */
20649 if (field_width
- n
> 0 && field
> field_width
- n
)
20650 field
= field_width
- n
;
20652 /* Note that either PRECISION <= 0 or N < PRECISION. */
20653 prec
= precision
- n
;
20656 n
+= display_mode_element (it
, depth
, field
, prec
,
20657 Vglobal_mode_string
, props
,
20662 ptrdiff_t bytepos
, charpos
;
20664 Lisp_Object string
;
20666 bytepos
= percent_position
;
20667 charpos
= (STRING_MULTIBYTE (elt
)
20668 ? string_byte_to_char (elt
, bytepos
)
20670 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20671 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20673 switch (mode_line_target
)
20675 case MODE_LINE_NOPROP
:
20676 case MODE_LINE_TITLE
:
20677 n
+= store_mode_line_noprop (spec
, field
, prec
);
20679 case MODE_LINE_STRING
:
20681 Lisp_Object tem
= build_string (spec
);
20682 props
= Ftext_properties_at (make_number (charpos
), elt
);
20683 /* Should only keep face property in props */
20684 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20687 case MODE_LINE_DISPLAY
:
20689 int nglyphs_before
, nwritten
;
20691 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20692 nwritten
= display_string (spec
, string
, elt
,
20697 /* Assign to the glyphs written above the
20698 string where the `%x' came from, position
20702 struct glyph
*glyph
20703 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20707 for (i
= 0; i
< nwritten
; ++i
)
20709 glyph
[i
].object
= elt
;
20710 glyph
[i
].charpos
= charpos
;
20727 /* A symbol: process the value of the symbol recursively
20728 as if it appeared here directly. Avoid error if symbol void.
20729 Special case: if value of symbol is a string, output the string
20732 register Lisp_Object tem
;
20734 /* If the variable is not marked as risky to set
20735 then its contents are risky to use. */
20736 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20739 tem
= Fboundp (elt
);
20742 tem
= Fsymbol_value (elt
);
20743 /* If value is a string, output that string literally:
20744 don't check for % within it. */
20748 if (!EQ (tem
, elt
))
20750 /* Give up right away for nil or t. */
20760 register Lisp_Object car
, tem
;
20762 /* A cons cell: five distinct cases.
20763 If first element is :eval or :propertize, do something special.
20764 If first element is a string or a cons, process all the elements
20765 and effectively concatenate them.
20766 If first element is a negative number, truncate displaying cdr to
20767 at most that many characters. If positive, pad (with spaces)
20768 to at least that many characters.
20769 If first element is a symbol, process the cadr or caddr recursively
20770 according to whether the symbol's value is non-nil or nil. */
20772 if (EQ (car
, QCeval
))
20774 /* An element of the form (:eval FORM) means evaluate FORM
20775 and use the result as mode line elements. */
20780 if (CONSP (XCDR (elt
)))
20783 spec
= safe_eval (XCAR (XCDR (elt
)));
20784 n
+= display_mode_element (it
, depth
, field_width
- n
,
20785 precision
- n
, spec
, props
,
20789 else if (EQ (car
, QCpropertize
))
20791 /* An element of the form (:propertize ELT PROPS...)
20792 means display ELT but applying properties PROPS. */
20797 if (CONSP (XCDR (elt
)))
20798 n
+= display_mode_element (it
, depth
, field_width
- n
,
20799 precision
- n
, XCAR (XCDR (elt
)),
20800 XCDR (XCDR (elt
)), risky
);
20802 else if (SYMBOLP (car
))
20804 tem
= Fboundp (car
);
20808 /* elt is now the cdr, and we know it is a cons cell.
20809 Use its car if CAR has a non-nil value. */
20812 tem
= Fsymbol_value (car
);
20819 /* Symbol's value is nil (or symbol is unbound)
20820 Get the cddr of the original list
20821 and if possible find the caddr and use that. */
20825 else if (!CONSP (elt
))
20830 else if (INTEGERP (car
))
20832 register int lim
= XINT (car
);
20836 /* Negative int means reduce maximum width. */
20837 if (precision
<= 0)
20840 precision
= min (precision
, -lim
);
20844 /* Padding specified. Don't let it be more than
20845 current maximum. */
20847 lim
= min (precision
, lim
);
20849 /* If that's more padding than already wanted, queue it.
20850 But don't reduce padding already specified even if
20851 that is beyond the current truncation point. */
20852 field_width
= max (lim
, field_width
);
20856 else if (STRINGP (car
) || CONSP (car
))
20858 Lisp_Object halftail
= elt
;
20862 && (precision
<= 0 || n
< precision
))
20864 n
+= display_mode_element (it
, depth
,
20865 /* Do padding only after the last
20866 element in the list. */
20867 (! CONSP (XCDR (elt
))
20870 precision
- n
, XCAR (elt
),
20874 if ((len
& 1) == 0)
20875 halftail
= XCDR (halftail
);
20876 /* Check for cycle. */
20877 if (EQ (halftail
, elt
))
20886 elt
= build_string ("*invalid*");
20890 /* Pad to FIELD_WIDTH. */
20891 if (field_width
> 0 && n
< field_width
)
20893 switch (mode_line_target
)
20895 case MODE_LINE_NOPROP
:
20896 case MODE_LINE_TITLE
:
20897 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20899 case MODE_LINE_STRING
:
20900 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20902 case MODE_LINE_DISPLAY
:
20903 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20912 /* Store a mode-line string element in mode_line_string_list.
20914 If STRING is non-null, display that C string. Otherwise, the Lisp
20915 string LISP_STRING is displayed.
20917 FIELD_WIDTH is the minimum number of output glyphs to produce.
20918 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20919 with spaces. FIELD_WIDTH <= 0 means don't pad.
20921 PRECISION is the maximum number of characters to output from
20922 STRING. PRECISION <= 0 means don't truncate the string.
20924 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20925 properties to the string.
20927 PROPS are the properties to add to the string.
20928 The mode_line_string_face face property is always added to the string.
20932 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20933 int field_width
, int precision
, Lisp_Object props
)
20938 if (string
!= NULL
)
20940 len
= strlen (string
);
20941 if (precision
> 0 && len
> precision
)
20943 lisp_string
= make_string (string
, len
);
20945 props
= mode_line_string_face_prop
;
20946 else if (!NILP (mode_line_string_face
))
20948 Lisp_Object face
= Fplist_get (props
, Qface
);
20949 props
= Fcopy_sequence (props
);
20951 face
= mode_line_string_face
;
20953 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20954 props
= Fplist_put (props
, Qface
, face
);
20956 Fadd_text_properties (make_number (0), make_number (len
),
20957 props
, lisp_string
);
20961 len
= XFASTINT (Flength (lisp_string
));
20962 if (precision
> 0 && len
> precision
)
20965 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
20968 if (!NILP (mode_line_string_face
))
20972 props
= Ftext_properties_at (make_number (0), lisp_string
);
20973 face
= Fplist_get (props
, Qface
);
20975 face
= mode_line_string_face
;
20977 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
20978 props
= Fcons (Qface
, Fcons (face
, Qnil
));
20980 lisp_string
= Fcopy_sequence (lisp_string
);
20983 Fadd_text_properties (make_number (0), make_number (len
),
20984 props
, lisp_string
);
20989 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
20993 if (field_width
> len
)
20995 field_width
-= len
;
20996 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
20998 Fadd_text_properties (make_number (0), make_number (field_width
),
20999 props
, lisp_string
);
21000 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21008 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21010 doc
: /* Format a string out of a mode line format specification.
21011 First arg FORMAT specifies the mode line format (see `mode-line-format'
21012 for details) to use.
21014 By default, the format is evaluated for the currently selected window.
21016 Optional second arg FACE specifies the face property to put on all
21017 characters for which no face is specified. The value nil means the
21018 default face. The value t means whatever face the window's mode line
21019 currently uses (either `mode-line' or `mode-line-inactive',
21020 depending on whether the window is the selected window or not).
21021 An integer value means the value string has no text
21024 Optional third and fourth args WINDOW and BUFFER specify the window
21025 and buffer to use as the context for the formatting (defaults
21026 are the selected window and the WINDOW's buffer). */)
21027 (Lisp_Object format
, Lisp_Object face
,
21028 Lisp_Object window
, Lisp_Object buffer
)
21033 struct buffer
*old_buffer
= NULL
;
21035 int no_props
= INTEGERP (face
);
21036 ptrdiff_t count
= SPECPDL_INDEX ();
21038 int string_start
= 0;
21040 w
= decode_any_window (window
);
21041 XSETWINDOW (window
, w
);
21044 buffer
= w
->buffer
;
21045 CHECK_BUFFER (buffer
);
21047 /* Make formatting the modeline a non-op when noninteractive, otherwise
21048 there will be problems later caused by a partially initialized frame. */
21049 if (NILP (format
) || noninteractive
)
21050 return empty_unibyte_string
;
21055 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21056 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21057 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21058 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21059 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21060 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21061 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21064 old_buffer
= current_buffer
;
21066 /* Save things including mode_line_proptrans_alist,
21067 and set that to nil so that we don't alter the outer value. */
21068 record_unwind_protect (unwind_format_mode_line
,
21069 format_mode_line_unwind_data
21070 (XFRAME (WINDOW_FRAME (w
)),
21071 old_buffer
, selected_window
, 1));
21072 mode_line_proptrans_alist
= Qnil
;
21074 Fselect_window (window
, Qt
);
21075 set_buffer_internal_1 (XBUFFER (buffer
));
21077 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21081 mode_line_target
= MODE_LINE_NOPROP
;
21082 mode_line_string_face_prop
= Qnil
;
21083 mode_line_string_list
= Qnil
;
21084 string_start
= MODE_LINE_NOPROP_LEN (0);
21088 mode_line_target
= MODE_LINE_STRING
;
21089 mode_line_string_list
= Qnil
;
21090 mode_line_string_face
= face
;
21091 mode_line_string_face_prop
21092 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
21095 push_kboard (FRAME_KBOARD (it
.f
));
21096 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21101 len
= MODE_LINE_NOPROP_LEN (string_start
);
21102 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21106 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21107 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21108 empty_unibyte_string
);
21111 unbind_to (count
, Qnil
);
21115 /* Write a null-terminated, right justified decimal representation of
21116 the positive integer D to BUF using a minimal field width WIDTH. */
21119 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21121 register char *p
= buf
;
21129 *p
++ = d
% 10 + '0';
21134 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21145 /* Write a null-terminated, right justified decimal and "human
21146 readable" representation of the nonnegative integer D to BUF using
21147 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21149 static const char power_letter
[] =
21163 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21165 /* We aim to represent the nonnegative integer D as
21166 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21167 ptrdiff_t quotient
= d
;
21169 /* -1 means: do not use TENTHS. */
21173 /* Length of QUOTIENT.TENTHS as a string. */
21179 if (1000 <= quotient
)
21181 /* Scale to the appropriate EXPONENT. */
21184 remainder
= quotient
% 1000;
21188 while (1000 <= quotient
);
21190 /* Round to nearest and decide whether to use TENTHS or not. */
21193 tenths
= remainder
/ 100;
21194 if (50 <= remainder
% 100)
21201 if (quotient
== 10)
21209 if (500 <= remainder
)
21211 if (quotient
< 999)
21222 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21223 if (tenths
== -1 && quotient
<= 99)
21230 p
= psuffix
= buf
+ max (width
, length
);
21232 /* Print EXPONENT. */
21233 *psuffix
++ = power_letter
[exponent
];
21236 /* Print TENTHS. */
21239 *--p
= '0' + tenths
;
21243 /* Print QUOTIENT. */
21246 int digit
= quotient
% 10;
21247 *--p
= '0' + digit
;
21249 while ((quotient
/= 10) != 0);
21251 /* Print leading spaces. */
21256 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21257 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21258 type of CODING_SYSTEM. Return updated pointer into BUF. */
21260 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21263 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21266 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21267 const unsigned char *eol_str
;
21269 /* The EOL conversion we are using. */
21270 Lisp_Object eoltype
;
21272 val
= CODING_SYSTEM_SPEC (coding_system
);
21275 if (!VECTORP (val
)) /* Not yet decided. */
21277 *buf
++ = multibyte
? '-' : ' ';
21279 eoltype
= eol_mnemonic_undecided
;
21280 /* Don't mention EOL conversion if it isn't decided. */
21285 Lisp_Object eolvalue
;
21287 attrs
= AREF (val
, 0);
21288 eolvalue
= AREF (val
, 2);
21291 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21296 /* The EOL conversion that is normal on this system. */
21298 if (NILP (eolvalue
)) /* Not yet decided. */
21299 eoltype
= eol_mnemonic_undecided
;
21300 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21301 eoltype
= eol_mnemonic_undecided
;
21302 else /* eolvalue is Qunix, Qdos, or Qmac. */
21303 eoltype
= (EQ (eolvalue
, Qunix
)
21304 ? eol_mnemonic_unix
21305 : (EQ (eolvalue
, Qdos
) == 1
21306 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21312 /* Mention the EOL conversion if it is not the usual one. */
21313 if (STRINGP (eoltype
))
21315 eol_str
= SDATA (eoltype
);
21316 eol_str_len
= SBYTES (eoltype
);
21318 else if (CHARACTERP (eoltype
))
21320 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21321 int c
= XFASTINT (eoltype
);
21322 eol_str_len
= CHAR_STRING (c
, tmp
);
21327 eol_str
= invalid_eol_type
;
21328 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21330 memcpy (buf
, eol_str
, eol_str_len
);
21331 buf
+= eol_str_len
;
21337 /* Return a string for the output of a mode line %-spec for window W,
21338 generated by character C. FIELD_WIDTH > 0 means pad the string
21339 returned with spaces to that value. Return a Lisp string in
21340 *STRING if the resulting string is taken from that Lisp string.
21342 Note we operate on the current buffer for most purposes,
21343 the exception being w->base_line_pos. */
21345 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21347 static const char *
21348 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21349 Lisp_Object
*string
)
21352 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21353 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21354 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21355 produce strings from numerical values, so limit preposterously
21356 large values of FIELD_WIDTH to avoid overrunning the buffer's
21357 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21358 bytes plus the terminating null. */
21359 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21360 struct buffer
*b
= current_buffer
;
21368 if (!NILP (BVAR (b
, read_only
)))
21370 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21375 /* This differs from %* only for a modified read-only buffer. */
21376 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21378 if (!NILP (BVAR (b
, read_only
)))
21383 /* This differs from %* in ignoring read-only-ness. */
21384 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21396 if (command_loop_level
> 5)
21398 p
= decode_mode_spec_buf
;
21399 for (i
= 0; i
< command_loop_level
; i
++)
21402 return decode_mode_spec_buf
;
21410 if (command_loop_level
> 5)
21412 p
= decode_mode_spec_buf
;
21413 for (i
= 0; i
< command_loop_level
; i
++)
21416 return decode_mode_spec_buf
;
21423 /* Let lots_of_dashes be a string of infinite length. */
21424 if (mode_line_target
== MODE_LINE_NOPROP
21425 || mode_line_target
== MODE_LINE_STRING
)
21427 if (field_width
<= 0
21428 || field_width
> sizeof (lots_of_dashes
))
21430 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21431 decode_mode_spec_buf
[i
] = '-';
21432 decode_mode_spec_buf
[i
] = '\0';
21433 return decode_mode_spec_buf
;
21436 return lots_of_dashes
;
21440 obj
= BVAR (b
, name
);
21444 /* %c and %l are ignored in `frame-title-format'.
21445 (In redisplay_internal, the frame title is drawn _before_ the
21446 windows are updated, so the stuff which depends on actual
21447 window contents (such as %l) may fail to render properly, or
21448 even crash emacs.) */
21449 if (mode_line_target
== MODE_LINE_TITLE
)
21453 ptrdiff_t col
= current_column ();
21454 wset_column_number_displayed (w
, make_number (col
));
21455 pint2str (decode_mode_spec_buf
, width
, col
);
21456 return decode_mode_spec_buf
;
21460 #ifndef SYSTEM_MALLOC
21462 if (NILP (Vmemory_full
))
21465 return "!MEM FULL! ";
21472 /* %F displays the frame name. */
21473 if (!NILP (f
->title
))
21474 return SSDATA (f
->title
);
21475 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21476 return SSDATA (f
->name
);
21480 obj
= BVAR (b
, filename
);
21485 ptrdiff_t size
= ZV
- BEGV
;
21486 pint2str (decode_mode_spec_buf
, width
, size
);
21487 return decode_mode_spec_buf
;
21492 ptrdiff_t size
= ZV
- BEGV
;
21493 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21494 return decode_mode_spec_buf
;
21499 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21500 ptrdiff_t topline
, nlines
, height
;
21503 /* %c and %l are ignored in `frame-title-format'. */
21504 if (mode_line_target
== MODE_LINE_TITLE
)
21507 startpos
= marker_position (w
->start
);
21508 startpos_byte
= marker_byte_position (w
->start
);
21509 height
= WINDOW_TOTAL_LINES (w
);
21511 /* If we decided that this buffer isn't suitable for line numbers,
21512 don't forget that too fast. */
21513 if (EQ (w
->base_line_pos
, w
->buffer
))
21515 /* But do forget it, if the window shows a different buffer now. */
21516 else if (BUFFERP (w
->base_line_pos
))
21517 wset_base_line_pos (w
, Qnil
);
21519 /* If the buffer is very big, don't waste time. */
21520 if (INTEGERP (Vline_number_display_limit
)
21521 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21523 wset_base_line_pos (w
, Qnil
);
21524 wset_base_line_number (w
, Qnil
);
21528 if (INTEGERP (w
->base_line_number
)
21529 && INTEGERP (w
->base_line_pos
)
21530 && XFASTINT (w
->base_line_pos
) <= startpos
)
21532 line
= XFASTINT (w
->base_line_number
);
21533 linepos
= XFASTINT (w
->base_line_pos
);
21534 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21539 linepos
= BUF_BEGV (b
);
21540 linepos_byte
= BUF_BEGV_BYTE (b
);
21543 /* Count lines from base line to window start position. */
21544 nlines
= display_count_lines (linepos_byte
,
21548 topline
= nlines
+ line
;
21550 /* Determine a new base line, if the old one is too close
21551 or too far away, or if we did not have one.
21552 "Too close" means it's plausible a scroll-down would
21553 go back past it. */
21554 if (startpos
== BUF_BEGV (b
))
21556 wset_base_line_number (w
, make_number (topline
));
21557 wset_base_line_pos (w
, make_number (BUF_BEGV (b
)));
21559 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21560 || linepos
== BUF_BEGV (b
))
21562 ptrdiff_t limit
= BUF_BEGV (b
);
21563 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21564 ptrdiff_t position
;
21565 ptrdiff_t distance
=
21566 (height
* 2 + 30) * line_number_display_limit_width
;
21568 if (startpos
- distance
> limit
)
21570 limit
= startpos
- distance
;
21571 limit_byte
= CHAR_TO_BYTE (limit
);
21574 nlines
= display_count_lines (startpos_byte
,
21576 - (height
* 2 + 30),
21578 /* If we couldn't find the lines we wanted within
21579 line_number_display_limit_width chars per line,
21580 give up on line numbers for this window. */
21581 if (position
== limit_byte
&& limit
== startpos
- distance
)
21583 wset_base_line_pos (w
, w
->buffer
);
21584 wset_base_line_number (w
, Qnil
);
21588 wset_base_line_number (w
, make_number (topline
- nlines
));
21589 wset_base_line_pos (w
, make_number (BYTE_TO_CHAR (position
)));
21592 /* Now count lines from the start pos to point. */
21593 nlines
= display_count_lines (startpos_byte
,
21594 PT_BYTE
, PT
, &junk
);
21596 /* Record that we did display the line number. */
21597 line_number_displayed
= 1;
21599 /* Make the string to show. */
21600 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21601 return decode_mode_spec_buf
;
21604 char* p
= decode_mode_spec_buf
;
21605 int pad
= width
- 2;
21611 return decode_mode_spec_buf
;
21617 obj
= BVAR (b
, mode_name
);
21621 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21627 ptrdiff_t pos
= marker_position (w
->start
);
21628 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21630 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21632 if (pos
<= BUF_BEGV (b
))
21637 else if (pos
<= BUF_BEGV (b
))
21641 if (total
> 1000000)
21642 /* Do it differently for a large value, to avoid overflow. */
21643 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21645 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21646 /* We can't normally display a 3-digit number,
21647 so get us a 2-digit number that is close. */
21650 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21651 return decode_mode_spec_buf
;
21655 /* Display percentage of size above the bottom of the screen. */
21658 ptrdiff_t toppos
= marker_position (w
->start
);
21659 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21660 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21662 if (botpos
>= BUF_ZV (b
))
21664 if (toppos
<= BUF_BEGV (b
))
21671 if (total
> 1000000)
21672 /* Do it differently for a large value, to avoid overflow. */
21673 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21675 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21676 /* We can't normally display a 3-digit number,
21677 so get us a 2-digit number that is close. */
21680 if (toppos
<= BUF_BEGV (b
))
21681 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21683 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21684 return decode_mode_spec_buf
;
21689 /* status of process */
21690 obj
= Fget_buffer_process (Fcurrent_buffer ());
21692 return "no process";
21694 obj
= Fsymbol_name (Fprocess_status (obj
));
21700 ptrdiff_t count
= inhibit_garbage_collection ();
21701 Lisp_Object val
= call1 (intern ("file-remote-p"),
21702 BVAR (current_buffer
, directory
));
21703 unbind_to (count
, Qnil
);
21711 case 't': /* indicate TEXT or BINARY */
21715 /* coding-system (not including end-of-line format) */
21717 /* coding-system (including end-of-line type) */
21719 int eol_flag
= (c
== 'Z');
21720 char *p
= decode_mode_spec_buf
;
21722 if (! FRAME_WINDOW_P (f
))
21724 /* No need to mention EOL here--the terminal never needs
21725 to do EOL conversion. */
21726 p
= decode_mode_spec_coding (CODING_ID_NAME
21727 (FRAME_KEYBOARD_CODING (f
)->id
),
21729 p
= decode_mode_spec_coding (CODING_ID_NAME
21730 (FRAME_TERMINAL_CODING (f
)->id
),
21733 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21736 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21737 #ifdef subprocesses
21738 obj
= Fget_buffer_process (Fcurrent_buffer ());
21739 if (PROCESSP (obj
))
21741 p
= decode_mode_spec_coding
21742 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21743 p
= decode_mode_spec_coding
21744 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21746 #endif /* subprocesses */
21749 return decode_mode_spec_buf
;
21756 return SSDATA (obj
);
21763 /* Count up to COUNT lines starting from START_BYTE.
21764 But don't go beyond LIMIT_BYTE.
21765 Return the number of lines thus found (always nonnegative).
21767 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21770 display_count_lines (ptrdiff_t start_byte
,
21771 ptrdiff_t limit_byte
, ptrdiff_t count
,
21772 ptrdiff_t *byte_pos_ptr
)
21774 register unsigned char *cursor
;
21775 unsigned char *base
;
21777 register ptrdiff_t ceiling
;
21778 register unsigned char *ceiling_addr
;
21779 ptrdiff_t orig_count
= count
;
21781 /* If we are not in selective display mode,
21782 check only for newlines. */
21783 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21784 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21788 while (start_byte
< limit_byte
)
21790 ceiling
= BUFFER_CEILING_OF (start_byte
);
21791 ceiling
= min (limit_byte
- 1, ceiling
);
21792 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21793 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21796 if (selective_display
)
21797 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21800 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21803 if (cursor
!= ceiling_addr
)
21807 start_byte
+= cursor
- base
+ 1;
21808 *byte_pos_ptr
= start_byte
;
21812 if (++cursor
== ceiling_addr
)
21818 start_byte
+= cursor
- base
;
21823 while (start_byte
> limit_byte
)
21825 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21826 ceiling
= max (limit_byte
, ceiling
);
21827 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21828 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21831 if (selective_display
)
21832 while (--cursor
!= ceiling_addr
21833 && *cursor
!= '\n' && *cursor
!= 015)
21836 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21839 if (cursor
!= ceiling_addr
)
21843 start_byte
+= cursor
- base
+ 1;
21844 *byte_pos_ptr
= start_byte
;
21845 /* When scanning backwards, we should
21846 not count the newline posterior to which we stop. */
21847 return - orig_count
- 1;
21853 /* Here we add 1 to compensate for the last decrement
21854 of CURSOR, which took it past the valid range. */
21855 start_byte
+= cursor
- base
+ 1;
21859 *byte_pos_ptr
= limit_byte
;
21862 return - orig_count
+ count
;
21863 return orig_count
- count
;
21869 /***********************************************************************
21871 ***********************************************************************/
21873 /* Display a NUL-terminated string, starting with index START.
21875 If STRING is non-null, display that C string. Otherwise, the Lisp
21876 string LISP_STRING is displayed. There's a case that STRING is
21877 non-null and LISP_STRING is not nil. It means STRING is a string
21878 data of LISP_STRING. In that case, we display LISP_STRING while
21879 ignoring its text properties.
21881 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21882 FACE_STRING. Display STRING or LISP_STRING with the face at
21883 FACE_STRING_POS in FACE_STRING:
21885 Display the string in the environment given by IT, but use the
21886 standard display table, temporarily.
21888 FIELD_WIDTH is the minimum number of output glyphs to produce.
21889 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21890 with spaces. If STRING has more characters, more than FIELD_WIDTH
21891 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21893 PRECISION is the maximum number of characters to output from
21894 STRING. PRECISION < 0 means don't truncate the string.
21896 This is roughly equivalent to printf format specifiers:
21898 FIELD_WIDTH PRECISION PRINTF
21899 ----------------------------------------
21905 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21906 display them, and < 0 means obey the current buffer's value of
21907 enable_multibyte_characters.
21909 Value is the number of columns displayed. */
21912 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21913 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21914 int field_width
, int precision
, int max_x
, int multibyte
)
21916 int hpos_at_start
= it
->hpos
;
21917 int saved_face_id
= it
->face_id
;
21918 struct glyph_row
*row
= it
->glyph_row
;
21919 ptrdiff_t it_charpos
;
21921 /* Initialize the iterator IT for iteration over STRING beginning
21922 with index START. */
21923 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21924 precision
, field_width
, multibyte
);
21925 if (string
&& STRINGP (lisp_string
))
21926 /* LISP_STRING is the one returned by decode_mode_spec. We should
21927 ignore its text properties. */
21928 it
->stop_charpos
= it
->end_charpos
;
21930 /* If displaying STRING, set up the face of the iterator from
21931 FACE_STRING, if that's given. */
21932 if (STRINGP (face_string
))
21938 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21939 0, it
->region_beg_charpos
,
21940 it
->region_end_charpos
,
21941 &endptr
, it
->base_face_id
, 0);
21942 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21943 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21946 /* Set max_x to the maximum allowed X position. Don't let it go
21947 beyond the right edge of the window. */
21949 max_x
= it
->last_visible_x
;
21951 max_x
= min (max_x
, it
->last_visible_x
);
21953 /* Skip over display elements that are not visible. because IT->w is
21955 if (it
->current_x
< it
->first_visible_x
)
21956 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
21957 MOVE_TO_POS
| MOVE_TO_X
);
21959 row
->ascent
= it
->max_ascent
;
21960 row
->height
= it
->max_ascent
+ it
->max_descent
;
21961 row
->phys_ascent
= it
->max_phys_ascent
;
21962 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
21963 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
21965 if (STRINGP (it
->string
))
21966 it_charpos
= IT_STRING_CHARPOS (*it
);
21968 it_charpos
= IT_CHARPOS (*it
);
21970 /* This condition is for the case that we are called with current_x
21971 past last_visible_x. */
21972 while (it
->current_x
< max_x
)
21974 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
21976 /* Get the next display element. */
21977 if (!get_next_display_element (it
))
21980 /* Produce glyphs. */
21981 x_before
= it
->current_x
;
21982 n_glyphs_before
= row
->used
[TEXT_AREA
];
21983 PRODUCE_GLYPHS (it
);
21985 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
21988 while (i
< nglyphs
)
21990 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
21992 if (it
->line_wrap
!= TRUNCATE
21993 && x
+ glyph
->pixel_width
> max_x
)
21995 /* End of continued line or max_x reached. */
21996 if (CHAR_GLYPH_PADDING_P (*glyph
))
21998 /* A wide character is unbreakable. */
21999 if (row
->reversed_p
)
22000 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22001 - n_glyphs_before
);
22002 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22003 it
->current_x
= x_before
;
22007 if (row
->reversed_p
)
22008 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22009 - (n_glyphs_before
+ i
));
22010 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22015 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22017 /* Glyph is at least partially visible. */
22019 if (x
< it
->first_visible_x
)
22020 row
->x
= x
- it
->first_visible_x
;
22024 /* Glyph is off the left margin of the display area.
22025 Should not happen. */
22029 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22030 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22031 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22032 row
->phys_height
= max (row
->phys_height
,
22033 it
->max_phys_ascent
+ it
->max_phys_descent
);
22034 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22035 it
->max_extra_line_spacing
);
22036 x
+= glyph
->pixel_width
;
22040 /* Stop if max_x reached. */
22044 /* Stop at line ends. */
22045 if (ITERATOR_AT_END_OF_LINE_P (it
))
22047 it
->continuation_lines_width
= 0;
22051 set_iterator_to_next (it
, 1);
22052 if (STRINGP (it
->string
))
22053 it_charpos
= IT_STRING_CHARPOS (*it
);
22055 it_charpos
= IT_CHARPOS (*it
);
22057 /* Stop if truncating at the right edge. */
22058 if (it
->line_wrap
== TRUNCATE
22059 && it
->current_x
>= it
->last_visible_x
)
22061 /* Add truncation mark, but don't do it if the line is
22062 truncated at a padding space. */
22063 if (it_charpos
< it
->string_nchars
)
22065 if (!FRAME_WINDOW_P (it
->f
))
22069 if (it
->current_x
> it
->last_visible_x
)
22071 if (!row
->reversed_p
)
22073 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22074 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22079 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22080 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22082 unproduce_glyphs (it
, ii
+ 1);
22083 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22085 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22087 row
->used
[TEXT_AREA
] = ii
;
22088 produce_special_glyphs (it
, IT_TRUNCATION
);
22091 produce_special_glyphs (it
, IT_TRUNCATION
);
22093 row
->truncated_on_right_p
= 1;
22099 /* Maybe insert a truncation at the left. */
22100 if (it
->first_visible_x
22103 if (!FRAME_WINDOW_P (it
->f
)
22104 || (row
->reversed_p
22105 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22106 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22107 insert_left_trunc_glyphs (it
);
22108 row
->truncated_on_left_p
= 1;
22111 it
->face_id
= saved_face_id
;
22113 /* Value is number of columns displayed. */
22114 return it
->hpos
- hpos_at_start
;
22119 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22120 appears as an element of LIST or as the car of an element of LIST.
22121 If PROPVAL is a list, compare each element against LIST in that
22122 way, and return 1/2 if any element of PROPVAL is found in LIST.
22123 Otherwise return 0. This function cannot quit.
22124 The return value is 2 if the text is invisible but with an ellipsis
22125 and 1 if it's invisible and without an ellipsis. */
22128 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22130 register Lisp_Object tail
, proptail
;
22132 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22134 register Lisp_Object tem
;
22136 if (EQ (propval
, tem
))
22138 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22139 return NILP (XCDR (tem
)) ? 1 : 2;
22142 if (CONSP (propval
))
22144 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22146 Lisp_Object propelt
;
22147 propelt
= XCAR (proptail
);
22148 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22150 register Lisp_Object tem
;
22152 if (EQ (propelt
, tem
))
22154 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22155 return NILP (XCDR (tem
)) ? 1 : 2;
22163 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22164 doc
: /* Non-nil if the property makes the text invisible.
22165 POS-OR-PROP can be a marker or number, in which case it is taken to be
22166 a position in the current buffer and the value of the `invisible' property
22167 is checked; or it can be some other value, which is then presumed to be the
22168 value of the `invisible' property of the text of interest.
22169 The non-nil value returned can be t for truly invisible text or something
22170 else if the text is replaced by an ellipsis. */)
22171 (Lisp_Object pos_or_prop
)
22174 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22175 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22177 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22178 return (invis
== 0 ? Qnil
22180 : make_number (invis
));
22183 /* Calculate a width or height in pixels from a specification using
22184 the following elements:
22187 NUM - a (fractional) multiple of the default font width/height
22188 (NUM) - specifies exactly NUM pixels
22189 UNIT - a fixed number of pixels, see below.
22190 ELEMENT - size of a display element in pixels, see below.
22191 (NUM . SPEC) - equals NUM * SPEC
22192 (+ SPEC SPEC ...) - add pixel values
22193 (- SPEC SPEC ...) - subtract pixel values
22194 (- SPEC) - negate pixel value
22197 INT or FLOAT - a number constant
22198 SYMBOL - use symbol's (buffer local) variable binding.
22201 in - pixels per inch *)
22202 mm - pixels per 1/1000 meter *)
22203 cm - pixels per 1/100 meter *)
22204 width - width of current font in pixels.
22205 height - height of current font in pixels.
22207 *) using the ratio(s) defined in display-pixels-per-inch.
22211 left-fringe - left fringe width in pixels
22212 right-fringe - right fringe width in pixels
22214 left-margin - left margin width in pixels
22215 right-margin - right margin width in pixels
22217 scroll-bar - scroll-bar area width in pixels
22221 Pixels corresponding to 5 inches:
22224 Total width of non-text areas on left side of window (if scroll-bar is on left):
22225 '(space :width (+ left-fringe left-margin scroll-bar))
22227 Align to first text column (in header line):
22228 '(space :align-to 0)
22230 Align to middle of text area minus half the width of variable `my-image'
22231 containing a loaded image:
22232 '(space :align-to (0.5 . (- text my-image)))
22234 Width of left margin minus width of 1 character in the default font:
22235 '(space :width (- left-margin 1))
22237 Width of left margin minus width of 2 characters in the current font:
22238 '(space :width (- left-margin (2 . width)))
22240 Center 1 character over left-margin (in header line):
22241 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22243 Different ways to express width of left fringe plus left margin minus one pixel:
22244 '(space :width (- (+ left-fringe left-margin) (1)))
22245 '(space :width (+ left-fringe left-margin (- (1))))
22246 '(space :width (+ left-fringe left-margin (-1)))
22250 #define NUMVAL(X) \
22251 ((INTEGERP (X) || FLOATP (X)) \
22256 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22257 struct font
*font
, int width_p
, int *align_to
)
22261 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22262 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22265 return OK_PIXELS (0);
22267 eassert (FRAME_LIVE_P (it
->f
));
22269 if (SYMBOLP (prop
))
22271 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22273 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22275 if (unit
[0] == 'i' && unit
[1] == 'n')
22277 else if (unit
[0] == 'm' && unit
[1] == 'm')
22279 else if (unit
[0] == 'c' && unit
[1] == 'm')
22286 #ifdef HAVE_WINDOW_SYSTEM
22287 if (FRAME_WINDOW_P (it
->f
)
22289 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22290 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22292 return OK_PIXELS (ppi
/ pixels
);
22295 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22296 || (CONSP (Vdisplay_pixels_per_inch
)
22298 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22299 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22301 return OK_PIXELS (ppi
/ pixels
);
22307 #ifdef HAVE_WINDOW_SYSTEM
22308 if (EQ (prop
, Qheight
))
22309 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22310 if (EQ (prop
, Qwidth
))
22311 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22313 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22314 return OK_PIXELS (1);
22317 if (EQ (prop
, Qtext
))
22318 return OK_PIXELS (width_p
22319 ? window_box_width (it
->w
, TEXT_AREA
)
22320 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22322 if (align_to
&& *align_to
< 0)
22325 if (EQ (prop
, Qleft
))
22326 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22327 if (EQ (prop
, Qright
))
22328 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22329 if (EQ (prop
, Qcenter
))
22330 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22331 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22332 if (EQ (prop
, Qleft_fringe
))
22333 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22334 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22335 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22336 if (EQ (prop
, Qright_fringe
))
22337 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22338 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22339 : window_box_right_offset (it
->w
, TEXT_AREA
));
22340 if (EQ (prop
, Qleft_margin
))
22341 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22342 if (EQ (prop
, Qright_margin
))
22343 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22344 if (EQ (prop
, Qscroll_bar
))
22345 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22347 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22348 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22349 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22354 if (EQ (prop
, Qleft_fringe
))
22355 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22356 if (EQ (prop
, Qright_fringe
))
22357 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22358 if (EQ (prop
, Qleft_margin
))
22359 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22360 if (EQ (prop
, Qright_margin
))
22361 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22362 if (EQ (prop
, Qscroll_bar
))
22363 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22366 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22367 if (EQ (prop
, Qunbound
))
22371 if (INTEGERP (prop
) || FLOATP (prop
))
22373 int base_unit
= (width_p
22374 ? FRAME_COLUMN_WIDTH (it
->f
)
22375 : FRAME_LINE_HEIGHT (it
->f
));
22376 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22381 Lisp_Object car
= XCAR (prop
);
22382 Lisp_Object cdr
= XCDR (prop
);
22386 #ifdef HAVE_WINDOW_SYSTEM
22387 if (FRAME_WINDOW_P (it
->f
)
22388 && valid_image_p (prop
))
22390 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22391 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22393 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22396 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22402 while (CONSP (cdr
))
22404 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22405 font
, width_p
, align_to
))
22408 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22413 if (EQ (car
, Qminus
))
22415 return OK_PIXELS (pixels
);
22418 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22419 if (EQ (car
, Qunbound
))
22423 if (INTEGERP (car
) || FLOATP (car
))
22426 pixels
= XFLOATINT (car
);
22428 return OK_PIXELS (pixels
);
22429 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22430 font
, width_p
, align_to
))
22431 return OK_PIXELS (pixels
* fact
);
22442 /***********************************************************************
22444 ***********************************************************************/
22446 #ifdef HAVE_WINDOW_SYSTEM
22451 dump_glyph_string (struct glyph_string
*s
)
22453 fprintf (stderr
, "glyph string\n");
22454 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22455 s
->x
, s
->y
, s
->width
, s
->height
);
22456 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22457 fprintf (stderr
, " hl = %d\n", s
->hl
);
22458 fprintf (stderr
, " left overhang = %d, right = %d\n",
22459 s
->left_overhang
, s
->right_overhang
);
22460 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22461 fprintf (stderr
, " extends to end of line = %d\n",
22462 s
->extends_to_end_of_line_p
);
22463 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22464 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22467 #endif /* GLYPH_DEBUG */
22469 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22470 of XChar2b structures for S; it can't be allocated in
22471 init_glyph_string because it must be allocated via `alloca'. W
22472 is the window on which S is drawn. ROW and AREA are the glyph row
22473 and area within the row from which S is constructed. START is the
22474 index of the first glyph structure covered by S. HL is a
22475 face-override for drawing S. */
22478 #define OPTIONAL_HDC(hdc) HDC hdc,
22479 #define DECLARE_HDC(hdc) HDC hdc;
22480 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22481 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22484 #ifndef OPTIONAL_HDC
22485 #define OPTIONAL_HDC(hdc)
22486 #define DECLARE_HDC(hdc)
22487 #define ALLOCATE_HDC(hdc, f)
22488 #define RELEASE_HDC(hdc, f)
22492 init_glyph_string (struct glyph_string
*s
,
22494 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22495 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22497 memset (s
, 0, sizeof *s
);
22499 s
->f
= XFRAME (w
->frame
);
22503 s
->display
= FRAME_X_DISPLAY (s
->f
);
22504 s
->window
= FRAME_X_WINDOW (s
->f
);
22505 s
->char2b
= char2b
;
22509 s
->first_glyph
= row
->glyphs
[area
] + start
;
22510 s
->height
= row
->height
;
22511 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22512 s
->ybase
= s
->y
+ row
->ascent
;
22516 /* Append the list of glyph strings with head H and tail T to the list
22517 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22520 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22521 struct glyph_string
*h
, struct glyph_string
*t
)
22535 /* Prepend the list of glyph strings with head H and tail T to the
22536 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22540 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22541 struct glyph_string
*h
, struct glyph_string
*t
)
22555 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22556 Set *HEAD and *TAIL to the resulting list. */
22559 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22560 struct glyph_string
*s
)
22562 s
->next
= s
->prev
= NULL
;
22563 append_glyph_string_lists (head
, tail
, s
, s
);
22567 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22568 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22569 make sure that X resources for the face returned are allocated.
22570 Value is a pointer to a realized face that is ready for display if
22571 DISPLAY_P is non-zero. */
22573 static struct face
*
22574 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22575 XChar2b
*char2b
, int display_p
)
22577 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22581 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22583 if (code
!= FONT_INVALID_CODE
)
22584 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22586 STORE_XCHAR2B (char2b
, 0, 0);
22589 /* Make sure X resources of the face are allocated. */
22590 #ifdef HAVE_X_WINDOWS
22594 eassert (face
!= NULL
);
22595 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22602 /* Get face and two-byte form of character glyph GLYPH on frame F.
22603 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22604 a pointer to a realized face that is ready for display. */
22606 static struct face
*
22607 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22608 XChar2b
*char2b
, int *two_byte_p
)
22612 eassert (glyph
->type
== CHAR_GLYPH
);
22613 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22622 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22623 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22625 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22627 if (code
!= FONT_INVALID_CODE
)
22628 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22630 STORE_XCHAR2B (char2b
, 0, 0);
22633 /* Make sure X resources of the face are allocated. */
22634 eassert (face
!= NULL
);
22635 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22640 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22641 Return 1 if FONT has a glyph for C, otherwise return 0. */
22644 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22648 if (CHAR_BYTE8_P (c
))
22649 code
= CHAR_TO_BYTE8 (c
);
22651 code
= font
->driver
->encode_char (font
, c
);
22653 if (code
== FONT_INVALID_CODE
)
22655 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22660 /* Fill glyph string S with composition components specified by S->cmp.
22662 BASE_FACE is the base face of the composition.
22663 S->cmp_from is the index of the first component for S.
22665 OVERLAPS non-zero means S should draw the foreground only, and use
22666 its physical height for clipping. See also draw_glyphs.
22668 Value is the index of a component not in S. */
22671 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22675 /* For all glyphs of this composition, starting at the offset
22676 S->cmp_from, until we reach the end of the definition or encounter a
22677 glyph that requires the different face, add it to S. */
22682 s
->for_overlaps
= overlaps
;
22685 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22687 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22689 /* TAB in a composition means display glyphs with padding space
22690 on the left or right. */
22693 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22696 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22703 s
->font
= s
->face
->font
;
22705 else if (s
->face
!= face
)
22713 if (s
->face
== NULL
)
22715 s
->face
= base_face
->ascii_face
;
22716 s
->font
= s
->face
->font
;
22719 /* All glyph strings for the same composition has the same width,
22720 i.e. the width set for the first component of the composition. */
22721 s
->width
= s
->first_glyph
->pixel_width
;
22723 /* If the specified font could not be loaded, use the frame's
22724 default font, but record the fact that we couldn't load it in
22725 the glyph string so that we can draw rectangles for the
22726 characters of the glyph string. */
22727 if (s
->font
== NULL
)
22729 s
->font_not_found_p
= 1;
22730 s
->font
= FRAME_FONT (s
->f
);
22733 /* Adjust base line for subscript/superscript text. */
22734 s
->ybase
+= s
->first_glyph
->voffset
;
22736 /* This glyph string must always be drawn with 16-bit functions. */
22743 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22744 int start
, int end
, int overlaps
)
22746 struct glyph
*glyph
, *last
;
22747 Lisp_Object lgstring
;
22750 s
->for_overlaps
= overlaps
;
22751 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22752 last
= s
->row
->glyphs
[s
->area
] + end
;
22753 s
->cmp_id
= glyph
->u
.cmp
.id
;
22754 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22755 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22756 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22757 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22758 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22760 while (glyph
< last
22761 && glyph
->u
.cmp
.automatic
22762 && glyph
->u
.cmp
.id
== s
->cmp_id
22763 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22764 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22766 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22768 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22769 unsigned code
= LGLYPH_CODE (lglyph
);
22771 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22773 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22774 return glyph
- s
->row
->glyphs
[s
->area
];
22778 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22779 See the comment of fill_glyph_string for arguments.
22780 Value is the index of the first glyph not in S. */
22784 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22785 int start
, int end
, int overlaps
)
22787 struct glyph
*glyph
, *last
;
22790 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22791 s
->for_overlaps
= overlaps
;
22792 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22793 last
= s
->row
->glyphs
[s
->area
] + end
;
22794 voffset
= glyph
->voffset
;
22795 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22796 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22798 s
->width
= glyph
->pixel_width
;
22800 while (glyph
< last
22801 && glyph
->type
== GLYPHLESS_GLYPH
22802 && glyph
->voffset
== voffset
22803 && glyph
->face_id
== face_id
)
22806 s
->width
+= glyph
->pixel_width
;
22809 s
->ybase
+= voffset
;
22810 return glyph
- s
->row
->glyphs
[s
->area
];
22814 /* Fill glyph string S from a sequence of character glyphs.
22816 FACE_ID is the face id of the string. START is the index of the
22817 first glyph to consider, END is the index of the last + 1.
22818 OVERLAPS non-zero means S should draw the foreground only, and use
22819 its physical height for clipping. See also draw_glyphs.
22821 Value is the index of the first glyph not in S. */
22824 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22825 int start
, int end
, int overlaps
)
22827 struct glyph
*glyph
, *last
;
22829 int glyph_not_available_p
;
22831 eassert (s
->f
== XFRAME (s
->w
->frame
));
22832 eassert (s
->nchars
== 0);
22833 eassert (start
>= 0 && end
> start
);
22835 s
->for_overlaps
= overlaps
;
22836 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22837 last
= s
->row
->glyphs
[s
->area
] + end
;
22838 voffset
= glyph
->voffset
;
22839 s
->padding_p
= glyph
->padding_p
;
22840 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22842 while (glyph
< last
22843 && glyph
->type
== CHAR_GLYPH
22844 && glyph
->voffset
== voffset
22845 /* Same face id implies same font, nowadays. */
22846 && glyph
->face_id
== face_id
22847 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22851 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22852 s
->char2b
+ s
->nchars
,
22854 s
->two_byte_p
= two_byte_p
;
22856 eassert (s
->nchars
<= end
- start
);
22857 s
->width
+= glyph
->pixel_width
;
22858 if (glyph
++->padding_p
!= s
->padding_p
)
22862 s
->font
= s
->face
->font
;
22864 /* If the specified font could not be loaded, use the frame's font,
22865 but record the fact that we couldn't load it in
22866 S->font_not_found_p so that we can draw rectangles for the
22867 characters of the glyph string. */
22868 if (s
->font
== NULL
|| glyph_not_available_p
)
22870 s
->font_not_found_p
= 1;
22871 s
->font
= FRAME_FONT (s
->f
);
22874 /* Adjust base line for subscript/superscript text. */
22875 s
->ybase
+= voffset
;
22877 eassert (s
->face
&& s
->face
->gc
);
22878 return glyph
- s
->row
->glyphs
[s
->area
];
22882 /* Fill glyph string S from image glyph S->first_glyph. */
22885 fill_image_glyph_string (struct glyph_string
*s
)
22887 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22888 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22890 s
->slice
= s
->first_glyph
->slice
.img
;
22891 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22892 s
->font
= s
->face
->font
;
22893 s
->width
= s
->first_glyph
->pixel_width
;
22895 /* Adjust base line for subscript/superscript text. */
22896 s
->ybase
+= s
->first_glyph
->voffset
;
22900 /* Fill glyph string S from a sequence of stretch glyphs.
22902 START is the index of the first glyph to consider,
22903 END is the index of the last + 1.
22905 Value is the index of the first glyph not in S. */
22908 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22910 struct glyph
*glyph
, *last
;
22911 int voffset
, face_id
;
22913 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22915 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22916 last
= s
->row
->glyphs
[s
->area
] + end
;
22917 face_id
= glyph
->face_id
;
22918 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22919 s
->font
= s
->face
->font
;
22920 s
->width
= glyph
->pixel_width
;
22922 voffset
= glyph
->voffset
;
22926 && glyph
->type
== STRETCH_GLYPH
22927 && glyph
->voffset
== voffset
22928 && glyph
->face_id
== face_id
);
22930 s
->width
+= glyph
->pixel_width
;
22932 /* Adjust base line for subscript/superscript text. */
22933 s
->ybase
+= voffset
;
22935 /* The case that face->gc == 0 is handled when drawing the glyph
22936 string by calling PREPARE_FACE_FOR_DISPLAY. */
22938 return glyph
- s
->row
->glyphs
[s
->area
];
22941 static struct font_metrics
*
22942 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22944 static struct font_metrics metrics
;
22945 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22947 if (! font
|| code
== FONT_INVALID_CODE
)
22949 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
22954 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
22955 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
22956 assumed to be zero. */
22959 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
22961 *left
= *right
= 0;
22963 if (glyph
->type
== CHAR_GLYPH
)
22967 struct font_metrics
*pcm
;
22969 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
22970 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
22972 if (pcm
->rbearing
> pcm
->width
)
22973 *right
= pcm
->rbearing
- pcm
->width
;
22974 if (pcm
->lbearing
< 0)
22975 *left
= -pcm
->lbearing
;
22978 else if (glyph
->type
== COMPOSITE_GLYPH
)
22980 if (! glyph
->u
.cmp
.automatic
)
22982 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
22984 if (cmp
->rbearing
> cmp
->pixel_width
)
22985 *right
= cmp
->rbearing
- cmp
->pixel_width
;
22986 if (cmp
->lbearing
< 0)
22987 *left
= - cmp
->lbearing
;
22991 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
22992 struct font_metrics metrics
;
22994 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
22995 glyph
->slice
.cmp
.to
+ 1, &metrics
);
22996 if (metrics
.rbearing
> metrics
.width
)
22997 *right
= metrics
.rbearing
- metrics
.width
;
22998 if (metrics
.lbearing
< 0)
22999 *left
= - metrics
.lbearing
;
23005 /* Return the index of the first glyph preceding glyph string S that
23006 is overwritten by S because of S's left overhang. Value is -1
23007 if no glyphs are overwritten. */
23010 left_overwritten (struct glyph_string
*s
)
23014 if (s
->left_overhang
)
23017 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23018 int first
= s
->first_glyph
- glyphs
;
23020 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23021 x
-= glyphs
[i
].pixel_width
;
23032 /* Return the index of the first glyph preceding glyph string S that
23033 is overwriting S because of its right overhang. Value is -1 if no
23034 glyph in front of S overwrites S. */
23037 left_overwriting (struct glyph_string
*s
)
23040 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23041 int first
= s
->first_glyph
- glyphs
;
23045 for (i
= first
- 1; i
>= 0; --i
)
23048 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23051 x
-= glyphs
[i
].pixel_width
;
23058 /* Return the index of the last glyph following glyph string S that is
23059 overwritten by S because of S's right overhang. Value is -1 if
23060 no such glyph is found. */
23063 right_overwritten (struct glyph_string
*s
)
23067 if (s
->right_overhang
)
23070 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23071 int first
= (s
->first_glyph
- glyphs
23072 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23073 int end
= s
->row
->used
[s
->area
];
23075 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23076 x
+= glyphs
[i
].pixel_width
;
23085 /* Return the index of the last glyph following glyph string S that
23086 overwrites S because of its left overhang. Value is negative
23087 if no such glyph is found. */
23090 right_overwriting (struct glyph_string
*s
)
23093 int end
= s
->row
->used
[s
->area
];
23094 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23095 int first
= (s
->first_glyph
- glyphs
23096 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23100 for (i
= first
; i
< end
; ++i
)
23103 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23106 x
+= glyphs
[i
].pixel_width
;
23113 /* Set background width of glyph string S. START is the index of the
23114 first glyph following S. LAST_X is the right-most x-position + 1
23115 in the drawing area. */
23118 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23120 /* If the face of this glyph string has to be drawn to the end of
23121 the drawing area, set S->extends_to_end_of_line_p. */
23123 if (start
== s
->row
->used
[s
->area
]
23124 && s
->area
== TEXT_AREA
23125 && ((s
->row
->fill_line_p
23126 && (s
->hl
== DRAW_NORMAL_TEXT
23127 || s
->hl
== DRAW_IMAGE_RAISED
23128 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23129 || s
->hl
== DRAW_MOUSE_FACE
))
23130 s
->extends_to_end_of_line_p
= 1;
23132 /* If S extends its face to the end of the line, set its
23133 background_width to the distance to the right edge of the drawing
23135 if (s
->extends_to_end_of_line_p
)
23136 s
->background_width
= last_x
- s
->x
+ 1;
23138 s
->background_width
= s
->width
;
23142 /* Compute overhangs and x-positions for glyph string S and its
23143 predecessors, or successors. X is the starting x-position for S.
23144 BACKWARD_P non-zero means process predecessors. */
23147 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23153 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23154 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23164 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23165 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23175 /* The following macros are only called from draw_glyphs below.
23176 They reference the following parameters of that function directly:
23177 `w', `row', `area', and `overlap_p'
23178 as well as the following local variables:
23179 `s', `f', and `hdc' (in W32) */
23182 /* On W32, silently add local `hdc' variable to argument list of
23183 init_glyph_string. */
23184 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23185 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23187 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23188 init_glyph_string (s, char2b, w, row, area, start, hl)
23191 /* Add a glyph string for a stretch glyph to the list of strings
23192 between HEAD and TAIL. START is the index of the stretch glyph in
23193 row area AREA of glyph row ROW. END is the index of the last glyph
23194 in that glyph row area. X is the current output position assigned
23195 to the new glyph string constructed. HL overrides that face of the
23196 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23197 is the right-most x-position of the drawing area. */
23199 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23200 and below -- keep them on one line. */
23201 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23204 s = alloca (sizeof *s); \
23205 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23206 START = fill_stretch_glyph_string (s, START, END); \
23207 append_glyph_string (&HEAD, &TAIL, s); \
23213 /* Add a glyph string for an image glyph to the list of strings
23214 between HEAD and TAIL. START is the index of the image glyph in
23215 row area AREA of glyph row ROW. END is the index of the last glyph
23216 in that glyph row area. X is the current output position assigned
23217 to the new glyph string constructed. HL overrides that face of the
23218 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23219 is the right-most x-position of the drawing area. */
23221 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23224 s = alloca (sizeof *s); \
23225 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23226 fill_image_glyph_string (s); \
23227 append_glyph_string (&HEAD, &TAIL, s); \
23234 /* Add a glyph string for a sequence of character glyphs to the list
23235 of strings between HEAD and TAIL. START is the index of the first
23236 glyph in row area AREA of glyph row ROW that is part of the new
23237 glyph string. END is the index of the last glyph in that glyph row
23238 area. X is the current output position assigned to the new glyph
23239 string constructed. HL overrides that face of the glyph; e.g. it
23240 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23241 right-most x-position of the drawing area. */
23243 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23249 face_id = (row)->glyphs[area][START].face_id; \
23251 s = alloca (sizeof *s); \
23252 char2b = alloca ((END - START) * sizeof *char2b); \
23253 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23254 append_glyph_string (&HEAD, &TAIL, s); \
23256 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23261 /* Add a glyph string for a composite sequence to the list of strings
23262 between HEAD and TAIL. START is the index of the first glyph in
23263 row area AREA of glyph row ROW that is part of the new glyph
23264 string. END is the index of the last glyph in that glyph row area.
23265 X is the current output position assigned to the new glyph string
23266 constructed. HL overrides that face of the glyph; e.g. it is
23267 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23268 x-position of the drawing area. */
23270 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23272 int face_id = (row)->glyphs[area][START].face_id; \
23273 struct face *base_face = FACE_FROM_ID (f, face_id); \
23274 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23275 struct composition *cmp = composition_table[cmp_id]; \
23277 struct glyph_string *first_s = NULL; \
23280 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23282 /* Make glyph_strings for each glyph sequence that is drawable by \
23283 the same face, and append them to HEAD/TAIL. */ \
23284 for (n = 0; n < cmp->glyph_len;) \
23286 s = alloca (sizeof *s); \
23287 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23288 append_glyph_string (&(HEAD), &(TAIL), s); \
23294 n = fill_composite_glyph_string (s, base_face, overlaps); \
23302 /* Add a glyph string for a glyph-string sequence to the list of strings
23303 between HEAD and TAIL. */
23305 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23309 Lisp_Object gstring; \
23311 face_id = (row)->glyphs[area][START].face_id; \
23312 gstring = (composition_gstring_from_id \
23313 ((row)->glyphs[area][START].u.cmp.id)); \
23314 s = alloca (sizeof *s); \
23315 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23316 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23317 append_glyph_string (&(HEAD), &(TAIL), s); \
23319 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23323 /* Add a glyph string for a sequence of glyphless character's glyphs
23324 to the list of strings between HEAD and TAIL. The meanings of
23325 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23327 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23332 face_id = (row)->glyphs[area][START].face_id; \
23334 s = alloca (sizeof *s); \
23335 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23336 append_glyph_string (&HEAD, &TAIL, s); \
23338 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23344 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23345 of AREA of glyph row ROW on window W between indices START and END.
23346 HL overrides the face for drawing glyph strings, e.g. it is
23347 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23348 x-positions of the drawing area.
23350 This is an ugly monster macro construct because we must use alloca
23351 to allocate glyph strings (because draw_glyphs can be called
23352 asynchronously). */
23354 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23357 HEAD = TAIL = NULL; \
23358 while (START < END) \
23360 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23361 switch (first_glyph->type) \
23364 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23368 case COMPOSITE_GLYPH: \
23369 if (first_glyph->u.cmp.automatic) \
23370 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23373 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23377 case STRETCH_GLYPH: \
23378 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23382 case IMAGE_GLYPH: \
23383 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23387 case GLYPHLESS_GLYPH: \
23388 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23398 set_glyph_string_background_width (s, START, LAST_X); \
23405 /* Draw glyphs between START and END in AREA of ROW on window W,
23406 starting at x-position X. X is relative to AREA in W. HL is a
23407 face-override with the following meaning:
23409 DRAW_NORMAL_TEXT draw normally
23410 DRAW_CURSOR draw in cursor face
23411 DRAW_MOUSE_FACE draw in mouse face.
23412 DRAW_INVERSE_VIDEO draw in mode line face
23413 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23414 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23416 If OVERLAPS is non-zero, draw only the foreground of characters and
23417 clip to the physical height of ROW. Non-zero value also defines
23418 the overlapping part to be drawn:
23420 OVERLAPS_PRED overlap with preceding rows
23421 OVERLAPS_SUCC overlap with succeeding rows
23422 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23423 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23425 Value is the x-position reached, relative to AREA of W. */
23428 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23429 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23430 enum draw_glyphs_face hl
, int overlaps
)
23432 struct glyph_string
*head
, *tail
;
23433 struct glyph_string
*s
;
23434 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23435 int i
, j
, x_reached
, last_x
, area_left
= 0;
23436 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23439 ALLOCATE_HDC (hdc
, f
);
23441 /* Let's rather be paranoid than getting a SEGV. */
23442 end
= min (end
, row
->used
[area
]);
23443 start
= clip_to_bounds (0, start
, end
);
23445 /* Translate X to frame coordinates. Set last_x to the right
23446 end of the drawing area. */
23447 if (row
->full_width_p
)
23449 /* X is relative to the left edge of W, without scroll bars
23451 area_left
= WINDOW_LEFT_EDGE_X (w
);
23452 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23456 area_left
= window_box_left (w
, area
);
23457 last_x
= area_left
+ window_box_width (w
, area
);
23461 /* Build a doubly-linked list of glyph_string structures between
23462 head and tail from what we have to draw. Note that the macro
23463 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23464 the reason we use a separate variable `i'. */
23466 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23468 x_reached
= tail
->x
+ tail
->background_width
;
23472 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23473 the row, redraw some glyphs in front or following the glyph
23474 strings built above. */
23475 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23477 struct glyph_string
*h
, *t
;
23478 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23479 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23480 int check_mouse_face
= 0;
23483 /* If mouse highlighting is on, we may need to draw adjacent
23484 glyphs using mouse-face highlighting. */
23485 if (area
== TEXT_AREA
&& row
->mouse_face_p
23486 && hlinfo
->mouse_face_beg_row
>= 0
23487 && hlinfo
->mouse_face_end_row
>= 0)
23489 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23491 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23492 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23494 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23496 check_mouse_face
= 1;
23497 mouse_beg_col
= (row
== mouse_beg_row
)
23498 ? hlinfo
->mouse_face_beg_col
: 0;
23499 mouse_end_col
= (row
== mouse_end_row
)
23500 ? hlinfo
->mouse_face_end_col
23501 : row
->used
[TEXT_AREA
];
23505 /* Compute overhangs for all glyph strings. */
23506 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23507 for (s
= head
; s
; s
= s
->next
)
23508 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23510 /* Prepend glyph strings for glyphs in front of the first glyph
23511 string that are overwritten because of the first glyph
23512 string's left overhang. The background of all strings
23513 prepended must be drawn because the first glyph string
23515 i
= left_overwritten (head
);
23518 enum draw_glyphs_face overlap_hl
;
23520 /* If this row contains mouse highlighting, attempt to draw
23521 the overlapped glyphs with the correct highlight. This
23522 code fails if the overlap encompasses more than one glyph
23523 and mouse-highlight spans only some of these glyphs.
23524 However, making it work perfectly involves a lot more
23525 code, and I don't know if the pathological case occurs in
23526 practice, so we'll stick to this for now. --- cyd */
23527 if (check_mouse_face
23528 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23529 overlap_hl
= DRAW_MOUSE_FACE
;
23531 overlap_hl
= DRAW_NORMAL_TEXT
;
23534 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23535 overlap_hl
, dummy_x
, last_x
);
23537 compute_overhangs_and_x (t
, head
->x
, 1);
23538 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23542 /* Prepend glyph strings for glyphs in front of the first glyph
23543 string that overwrite that glyph string because of their
23544 right overhang. For these strings, only the foreground must
23545 be drawn, because it draws over the glyph string at `head'.
23546 The background must not be drawn because this would overwrite
23547 right overhangs of preceding glyphs for which no glyph
23549 i
= left_overwriting (head
);
23552 enum draw_glyphs_face overlap_hl
;
23554 if (check_mouse_face
23555 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23556 overlap_hl
= DRAW_MOUSE_FACE
;
23558 overlap_hl
= DRAW_NORMAL_TEXT
;
23561 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23562 overlap_hl
, dummy_x
, last_x
);
23563 for (s
= h
; s
; s
= s
->next
)
23564 s
->background_filled_p
= 1;
23565 compute_overhangs_and_x (t
, head
->x
, 1);
23566 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23569 /* Append glyphs strings for glyphs following the last glyph
23570 string tail that are overwritten by tail. The background of
23571 these strings has to be drawn because tail's foreground draws
23573 i
= right_overwritten (tail
);
23576 enum draw_glyphs_face overlap_hl
;
23578 if (check_mouse_face
23579 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23580 overlap_hl
= DRAW_MOUSE_FACE
;
23582 overlap_hl
= DRAW_NORMAL_TEXT
;
23584 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23585 overlap_hl
, x
, last_x
);
23586 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23587 we don't have `end = i;' here. */
23588 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23589 append_glyph_string_lists (&head
, &tail
, h
, t
);
23593 /* Append glyph strings for glyphs following the last glyph
23594 string tail that overwrite tail. The foreground of such
23595 glyphs has to be drawn because it writes into the background
23596 of tail. The background must not be drawn because it could
23597 paint over the foreground of following glyphs. */
23598 i
= right_overwriting (tail
);
23601 enum draw_glyphs_face overlap_hl
;
23602 if (check_mouse_face
23603 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23604 overlap_hl
= DRAW_MOUSE_FACE
;
23606 overlap_hl
= DRAW_NORMAL_TEXT
;
23609 i
++; /* We must include the Ith glyph. */
23610 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23611 overlap_hl
, x
, last_x
);
23612 for (s
= h
; s
; s
= s
->next
)
23613 s
->background_filled_p
= 1;
23614 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23615 append_glyph_string_lists (&head
, &tail
, h
, t
);
23617 if (clip_head
|| clip_tail
)
23618 for (s
= head
; s
; s
= s
->next
)
23620 s
->clip_head
= clip_head
;
23621 s
->clip_tail
= clip_tail
;
23625 /* Draw all strings. */
23626 for (s
= head
; s
; s
= s
->next
)
23627 FRAME_RIF (f
)->draw_glyph_string (s
);
23630 /* When focus a sole frame and move horizontally, this sets on_p to 0
23631 causing a failure to erase prev cursor position. */
23632 if (area
== TEXT_AREA
23633 && !row
->full_width_p
23634 /* When drawing overlapping rows, only the glyph strings'
23635 foreground is drawn, which doesn't erase a cursor
23639 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23640 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23641 : (tail
? tail
->x
+ tail
->background_width
: x
));
23645 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23646 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23650 /* Value is the x-position up to which drawn, relative to AREA of W.
23651 This doesn't include parts drawn because of overhangs. */
23652 if (row
->full_width_p
)
23653 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23655 x_reached
-= area_left
;
23657 RELEASE_HDC (hdc
, f
);
23662 /* Expand row matrix if too narrow. Don't expand if area
23665 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23667 if (!fonts_changed_p \
23668 && (it->glyph_row->glyphs[area] \
23669 < it->glyph_row->glyphs[area + 1])) \
23671 it->w->ncols_scale_factor++; \
23672 fonts_changed_p = 1; \
23676 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23677 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23680 append_glyph (struct it
*it
)
23682 struct glyph
*glyph
;
23683 enum glyph_row_area area
= it
->area
;
23685 eassert (it
->glyph_row
);
23686 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23688 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23689 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23691 /* If the glyph row is reversed, we need to prepend the glyph
23692 rather than append it. */
23693 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23697 /* Make room for the additional glyph. */
23698 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23700 glyph
= it
->glyph_row
->glyphs
[area
];
23702 glyph
->charpos
= CHARPOS (it
->position
);
23703 glyph
->object
= it
->object
;
23704 if (it
->pixel_width
> 0)
23706 glyph
->pixel_width
= it
->pixel_width
;
23707 glyph
->padding_p
= 0;
23711 /* Assure at least 1-pixel width. Otherwise, cursor can't
23712 be displayed correctly. */
23713 glyph
->pixel_width
= 1;
23714 glyph
->padding_p
= 1;
23716 glyph
->ascent
= it
->ascent
;
23717 glyph
->descent
= it
->descent
;
23718 glyph
->voffset
= it
->voffset
;
23719 glyph
->type
= CHAR_GLYPH
;
23720 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23721 glyph
->multibyte_p
= it
->multibyte_p
;
23722 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23724 /* In R2L rows, the left and the right box edges need to be
23725 drawn in reverse direction. */
23726 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23727 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23731 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23732 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23734 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23735 || it
->phys_descent
> it
->descent
);
23736 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23737 glyph
->face_id
= it
->face_id
;
23738 glyph
->u
.ch
= it
->char_to_display
;
23739 glyph
->slice
.img
= null_glyph_slice
;
23740 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23743 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23744 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23746 glyph
->bidi_type
= it
->bidi_it
.type
;
23750 glyph
->resolved_level
= 0;
23751 glyph
->bidi_type
= UNKNOWN_BT
;
23753 ++it
->glyph_row
->used
[area
];
23756 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23759 /* Store one glyph for the composition IT->cmp_it.id in
23760 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23764 append_composite_glyph (struct it
*it
)
23766 struct glyph
*glyph
;
23767 enum glyph_row_area area
= it
->area
;
23769 eassert (it
->glyph_row
);
23771 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23772 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23774 /* If the glyph row is reversed, we need to prepend the glyph
23775 rather than append it. */
23776 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23780 /* Make room for the new glyph. */
23781 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23783 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23785 glyph
->charpos
= it
->cmp_it
.charpos
;
23786 glyph
->object
= it
->object
;
23787 glyph
->pixel_width
= it
->pixel_width
;
23788 glyph
->ascent
= it
->ascent
;
23789 glyph
->descent
= it
->descent
;
23790 glyph
->voffset
= it
->voffset
;
23791 glyph
->type
= COMPOSITE_GLYPH
;
23792 if (it
->cmp_it
.ch
< 0)
23794 glyph
->u
.cmp
.automatic
= 0;
23795 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23796 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23800 glyph
->u
.cmp
.automatic
= 1;
23801 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23802 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23803 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23805 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23806 glyph
->multibyte_p
= it
->multibyte_p
;
23807 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23809 /* In R2L rows, the left and the right box edges need to be
23810 drawn in reverse direction. */
23811 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23812 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23816 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23817 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23819 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23820 || it
->phys_descent
> it
->descent
);
23821 glyph
->padding_p
= 0;
23822 glyph
->glyph_not_available_p
= 0;
23823 glyph
->face_id
= it
->face_id
;
23824 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23827 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23828 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23830 glyph
->bidi_type
= it
->bidi_it
.type
;
23832 ++it
->glyph_row
->used
[area
];
23835 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23839 /* Change IT->ascent and IT->height according to the setting of
23843 take_vertical_position_into_account (struct it
*it
)
23847 if (it
->voffset
< 0)
23848 /* Increase the ascent so that we can display the text higher
23850 it
->ascent
-= it
->voffset
;
23852 /* Increase the descent so that we can display the text lower
23854 it
->descent
+= it
->voffset
;
23859 /* Produce glyphs/get display metrics for the image IT is loaded with.
23860 See the description of struct display_iterator in dispextern.h for
23861 an overview of struct display_iterator. */
23864 produce_image_glyph (struct it
*it
)
23868 int glyph_ascent
, crop
;
23869 struct glyph_slice slice
;
23871 eassert (it
->what
== IT_IMAGE
);
23873 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23875 /* Make sure X resources of the face is loaded. */
23876 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23878 if (it
->image_id
< 0)
23880 /* Fringe bitmap. */
23881 it
->ascent
= it
->phys_ascent
= 0;
23882 it
->descent
= it
->phys_descent
= 0;
23883 it
->pixel_width
= 0;
23888 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23890 /* Make sure X resources of the image is loaded. */
23891 prepare_image_for_display (it
->f
, img
);
23893 slice
.x
= slice
.y
= 0;
23894 slice
.width
= img
->width
;
23895 slice
.height
= img
->height
;
23897 if (INTEGERP (it
->slice
.x
))
23898 slice
.x
= XINT (it
->slice
.x
);
23899 else if (FLOATP (it
->slice
.x
))
23900 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23902 if (INTEGERP (it
->slice
.y
))
23903 slice
.y
= XINT (it
->slice
.y
);
23904 else if (FLOATP (it
->slice
.y
))
23905 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23907 if (INTEGERP (it
->slice
.width
))
23908 slice
.width
= XINT (it
->slice
.width
);
23909 else if (FLOATP (it
->slice
.width
))
23910 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23912 if (INTEGERP (it
->slice
.height
))
23913 slice
.height
= XINT (it
->slice
.height
);
23914 else if (FLOATP (it
->slice
.height
))
23915 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23917 if (slice
.x
>= img
->width
)
23918 slice
.x
= img
->width
;
23919 if (slice
.y
>= img
->height
)
23920 slice
.y
= img
->height
;
23921 if (slice
.x
+ slice
.width
>= img
->width
)
23922 slice
.width
= img
->width
- slice
.x
;
23923 if (slice
.y
+ slice
.height
> img
->height
)
23924 slice
.height
= img
->height
- slice
.y
;
23926 if (slice
.width
== 0 || slice
.height
== 0)
23929 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23931 it
->descent
= slice
.height
- glyph_ascent
;
23933 it
->descent
+= img
->vmargin
;
23934 if (slice
.y
+ slice
.height
== img
->height
)
23935 it
->descent
+= img
->vmargin
;
23936 it
->phys_descent
= it
->descent
;
23938 it
->pixel_width
= slice
.width
;
23940 it
->pixel_width
+= img
->hmargin
;
23941 if (slice
.x
+ slice
.width
== img
->width
)
23942 it
->pixel_width
+= img
->hmargin
;
23944 /* It's quite possible for images to have an ascent greater than
23945 their height, so don't get confused in that case. */
23946 if (it
->descent
< 0)
23951 if (face
->box
!= FACE_NO_BOX
)
23953 if (face
->box_line_width
> 0)
23956 it
->ascent
+= face
->box_line_width
;
23957 if (slice
.y
+ slice
.height
== img
->height
)
23958 it
->descent
+= face
->box_line_width
;
23961 if (it
->start_of_box_run_p
&& slice
.x
== 0)
23962 it
->pixel_width
+= eabs (face
->box_line_width
);
23963 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
23964 it
->pixel_width
+= eabs (face
->box_line_width
);
23967 take_vertical_position_into_account (it
);
23969 /* Automatically crop wide image glyphs at right edge so we can
23970 draw the cursor on same display row. */
23971 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
23972 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
23974 it
->pixel_width
-= crop
;
23975 slice
.width
-= crop
;
23980 struct glyph
*glyph
;
23981 enum glyph_row_area area
= it
->area
;
23983 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23984 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23986 glyph
->charpos
= CHARPOS (it
->position
);
23987 glyph
->object
= it
->object
;
23988 glyph
->pixel_width
= it
->pixel_width
;
23989 glyph
->ascent
= glyph_ascent
;
23990 glyph
->descent
= it
->descent
;
23991 glyph
->voffset
= it
->voffset
;
23992 glyph
->type
= IMAGE_GLYPH
;
23993 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23994 glyph
->multibyte_p
= it
->multibyte_p
;
23995 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23997 /* In R2L rows, the left and the right box edges need to be
23998 drawn in reverse direction. */
23999 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24000 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24004 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24005 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24007 glyph
->overlaps_vertically_p
= 0;
24008 glyph
->padding_p
= 0;
24009 glyph
->glyph_not_available_p
= 0;
24010 glyph
->face_id
= it
->face_id
;
24011 glyph
->u
.img_id
= img
->id
;
24012 glyph
->slice
.img
= slice
;
24013 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24016 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24017 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24019 glyph
->bidi_type
= it
->bidi_it
.type
;
24021 ++it
->glyph_row
->used
[area
];
24024 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24029 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24030 of the glyph, WIDTH and HEIGHT are the width and height of the
24031 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24034 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24035 int width
, int height
, int ascent
)
24037 struct glyph
*glyph
;
24038 enum glyph_row_area area
= it
->area
;
24040 eassert (ascent
>= 0 && ascent
<= height
);
24042 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24043 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24045 /* If the glyph row is reversed, we need to prepend the glyph
24046 rather than append it. */
24047 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24051 /* Make room for the additional glyph. */
24052 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24054 glyph
= it
->glyph_row
->glyphs
[area
];
24056 glyph
->charpos
= CHARPOS (it
->position
);
24057 glyph
->object
= object
;
24058 glyph
->pixel_width
= width
;
24059 glyph
->ascent
= ascent
;
24060 glyph
->descent
= height
- ascent
;
24061 glyph
->voffset
= it
->voffset
;
24062 glyph
->type
= STRETCH_GLYPH
;
24063 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24064 glyph
->multibyte_p
= it
->multibyte_p
;
24065 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24067 /* In R2L rows, the left and the right box edges need to be
24068 drawn in reverse direction. */
24069 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24070 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24074 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24075 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24077 glyph
->overlaps_vertically_p
= 0;
24078 glyph
->padding_p
= 0;
24079 glyph
->glyph_not_available_p
= 0;
24080 glyph
->face_id
= it
->face_id
;
24081 glyph
->u
.stretch
.ascent
= ascent
;
24082 glyph
->u
.stretch
.height
= height
;
24083 glyph
->slice
.img
= null_glyph_slice
;
24084 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24087 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24088 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24090 glyph
->bidi_type
= it
->bidi_it
.type
;
24094 glyph
->resolved_level
= 0;
24095 glyph
->bidi_type
= UNKNOWN_BT
;
24097 ++it
->glyph_row
->used
[area
];
24100 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24103 #endif /* HAVE_WINDOW_SYSTEM */
24105 /* Produce a stretch glyph for iterator IT. IT->object is the value
24106 of the glyph property displayed. The value must be a list
24107 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24110 1. `:width WIDTH' specifies that the space should be WIDTH *
24111 canonical char width wide. WIDTH may be an integer or floating
24114 2. `:relative-width FACTOR' specifies that the width of the stretch
24115 should be computed from the width of the first character having the
24116 `glyph' property, and should be FACTOR times that width.
24118 3. `:align-to HPOS' specifies that the space should be wide enough
24119 to reach HPOS, a value in canonical character units.
24121 Exactly one of the above pairs must be present.
24123 4. `:height HEIGHT' specifies that the height of the stretch produced
24124 should be HEIGHT, measured in canonical character units.
24126 5. `:relative-height FACTOR' specifies that the height of the
24127 stretch should be FACTOR times the height of the characters having
24128 the glyph property.
24130 Either none or exactly one of 4 or 5 must be present.
24132 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24133 of the stretch should be used for the ascent of the stretch.
24134 ASCENT must be in the range 0 <= ASCENT <= 100. */
24137 produce_stretch_glyph (struct it
*it
)
24139 /* (space :width WIDTH :height HEIGHT ...) */
24140 Lisp_Object prop
, plist
;
24141 int width
= 0, height
= 0, align_to
= -1;
24142 int zero_width_ok_p
= 0;
24144 struct font
*font
= NULL
;
24146 #ifdef HAVE_WINDOW_SYSTEM
24148 int zero_height_ok_p
= 0;
24150 if (FRAME_WINDOW_P (it
->f
))
24152 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24153 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24154 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24158 /* List should start with `space'. */
24159 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24160 plist
= XCDR (it
->object
);
24162 /* Compute the width of the stretch. */
24163 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24164 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24166 /* Absolute width `:width WIDTH' specified and valid. */
24167 zero_width_ok_p
= 1;
24170 #ifdef HAVE_WINDOW_SYSTEM
24171 else if (FRAME_WINDOW_P (it
->f
)
24172 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24174 /* Relative width `:relative-width FACTOR' specified and valid.
24175 Compute the width of the characters having the `glyph'
24178 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24181 if (it
->multibyte_p
)
24182 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24185 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24186 if (! ASCII_CHAR_P (it2
.c
))
24187 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24190 it2
.glyph_row
= NULL
;
24191 it2
.what
= IT_CHARACTER
;
24192 x_produce_glyphs (&it2
);
24193 width
= NUMVAL (prop
) * it2
.pixel_width
;
24195 #endif /* HAVE_WINDOW_SYSTEM */
24196 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24197 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24199 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24200 align_to
= (align_to
< 0
24202 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24203 else if (align_to
< 0)
24204 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24205 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24206 zero_width_ok_p
= 1;
24209 /* Nothing specified -> width defaults to canonical char width. */
24210 width
= FRAME_COLUMN_WIDTH (it
->f
);
24212 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24215 #ifdef HAVE_WINDOW_SYSTEM
24216 /* Compute height. */
24217 if (FRAME_WINDOW_P (it
->f
))
24219 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24220 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24223 zero_height_ok_p
= 1;
24225 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24227 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24229 height
= FONT_HEIGHT (font
);
24231 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24234 /* Compute percentage of height used for ascent. If
24235 `:ascent ASCENT' is present and valid, use that. Otherwise,
24236 derive the ascent from the font in use. */
24237 if (prop
= Fplist_get (plist
, QCascent
),
24238 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24239 ascent
= height
* NUMVAL (prop
) / 100.0;
24240 else if (!NILP (prop
)
24241 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24242 ascent
= min (max (0, (int)tem
), height
);
24244 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24247 #endif /* HAVE_WINDOW_SYSTEM */
24250 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24251 && it
->current_x
+ width
> it
->last_visible_x
)
24253 width
= it
->last_visible_x
- it
->current_x
;
24254 #ifdef HAVE_WINDOW_SYSTEM
24255 /* Subtract one more pixel from the stretch width, but only on
24256 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24257 width
-= FRAME_WINDOW_P (it
->f
);
24261 if (width
> 0 && height
> 0 && it
->glyph_row
)
24263 Lisp_Object o_object
= it
->object
;
24264 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24267 if (!STRINGP (object
))
24268 object
= it
->w
->buffer
;
24269 #ifdef HAVE_WINDOW_SYSTEM
24270 if (FRAME_WINDOW_P (it
->f
))
24271 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24275 it
->object
= object
;
24276 it
->char_to_display
= ' ';
24277 it
->pixel_width
= it
->len
= 1;
24279 tty_append_glyph (it
);
24280 it
->object
= o_object
;
24284 it
->pixel_width
= width
;
24285 #ifdef HAVE_WINDOW_SYSTEM
24286 if (FRAME_WINDOW_P (it
->f
))
24288 it
->ascent
= it
->phys_ascent
= ascent
;
24289 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24290 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24291 take_vertical_position_into_account (it
);
24295 it
->nglyphs
= width
;
24298 /* Get information about special display element WHAT in an
24299 environment described by IT. WHAT is one of IT_TRUNCATION or
24300 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24301 non-null glyph_row member. This function ensures that fields like
24302 face_id, c, len of IT are left untouched. */
24305 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24312 temp_it
.object
= make_number (0);
24313 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24315 if (what
== IT_CONTINUATION
)
24317 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24318 if (it
->bidi_it
.paragraph_dir
== R2L
)
24319 SET_GLYPH_FROM_CHAR (glyph
, '/');
24321 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24323 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24325 /* FIXME: Should we mirror GC for R2L lines? */
24326 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24327 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24330 else if (what
== IT_TRUNCATION
)
24332 /* Truncation glyph. */
24333 SET_GLYPH_FROM_CHAR (glyph
, '$');
24335 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24337 /* FIXME: Should we mirror GC for R2L lines? */
24338 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24339 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24345 #ifdef HAVE_WINDOW_SYSTEM
24346 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24347 is turned off, we precede the truncation/continuation glyphs by a
24348 stretch glyph whose width is computed such that these special
24349 glyphs are aligned at the window margin, even when very different
24350 fonts are used in different glyph rows. */
24351 if (FRAME_WINDOW_P (temp_it
.f
)
24352 /* init_iterator calls this with it->glyph_row == NULL, and it
24353 wants only the pixel width of the truncation/continuation
24355 && temp_it
.glyph_row
24356 /* insert_left_trunc_glyphs calls us at the beginning of the
24357 row, and it has its own calculation of the stretch glyph
24359 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24360 && (temp_it
.glyph_row
->reversed_p
24361 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24362 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24364 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24366 if (stretch_width
> 0)
24368 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24369 struct font
*font
=
24370 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24371 int stretch_ascent
=
24372 (((temp_it
.ascent
+ temp_it
.descent
)
24373 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24375 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24376 temp_it
.ascent
+ temp_it
.descent
,
24383 temp_it
.what
= IT_CHARACTER
;
24385 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24386 temp_it
.face_id
= GLYPH_FACE (glyph
);
24387 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24389 PRODUCE_GLYPHS (&temp_it
);
24390 it
->pixel_width
= temp_it
.pixel_width
;
24391 it
->nglyphs
= temp_it
.pixel_width
;
24394 #ifdef HAVE_WINDOW_SYSTEM
24396 /* Calculate line-height and line-spacing properties.
24397 An integer value specifies explicit pixel value.
24398 A float value specifies relative value to current face height.
24399 A cons (float . face-name) specifies relative value to
24400 height of specified face font.
24402 Returns height in pixels, or nil. */
24406 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24407 int boff
, int override
)
24409 Lisp_Object face_name
= Qnil
;
24410 int ascent
, descent
, height
;
24412 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24417 face_name
= XCAR (val
);
24419 if (!NUMBERP (val
))
24420 val
= make_number (1);
24421 if (NILP (face_name
))
24423 height
= it
->ascent
+ it
->descent
;
24428 if (NILP (face_name
))
24430 font
= FRAME_FONT (it
->f
);
24431 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24433 else if (EQ (face_name
, Qt
))
24442 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24444 return make_number (-1);
24446 face
= FACE_FROM_ID (it
->f
, face_id
);
24449 return make_number (-1);
24450 boff
= font
->baseline_offset
;
24451 if (font
->vertical_centering
)
24452 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24455 ascent
= FONT_BASE (font
) + boff
;
24456 descent
= FONT_DESCENT (font
) - boff
;
24460 it
->override_ascent
= ascent
;
24461 it
->override_descent
= descent
;
24462 it
->override_boff
= boff
;
24465 height
= ascent
+ descent
;
24469 height
= (int)(XFLOAT_DATA (val
) * height
);
24470 else if (INTEGERP (val
))
24471 height
*= XINT (val
);
24473 return make_number (height
);
24477 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24478 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24479 and only if this is for a character for which no font was found.
24481 If the display method (it->glyphless_method) is
24482 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24483 length of the acronym or the hexadecimal string, UPPER_XOFF and
24484 UPPER_YOFF are pixel offsets for the upper part of the string,
24485 LOWER_XOFF and LOWER_YOFF are for the lower part.
24487 For the other display methods, LEN through LOWER_YOFF are zero. */
24490 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24491 short upper_xoff
, short upper_yoff
,
24492 short lower_xoff
, short lower_yoff
)
24494 struct glyph
*glyph
;
24495 enum glyph_row_area area
= it
->area
;
24497 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24498 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24500 /* If the glyph row is reversed, we need to prepend the glyph
24501 rather than append it. */
24502 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24506 /* Make room for the additional glyph. */
24507 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24509 glyph
= it
->glyph_row
->glyphs
[area
];
24511 glyph
->charpos
= CHARPOS (it
->position
);
24512 glyph
->object
= it
->object
;
24513 glyph
->pixel_width
= it
->pixel_width
;
24514 glyph
->ascent
= it
->ascent
;
24515 glyph
->descent
= it
->descent
;
24516 glyph
->voffset
= it
->voffset
;
24517 glyph
->type
= GLYPHLESS_GLYPH
;
24518 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24519 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24520 glyph
->u
.glyphless
.len
= len
;
24521 glyph
->u
.glyphless
.ch
= it
->c
;
24522 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24523 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24524 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24525 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24526 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24527 glyph
->multibyte_p
= it
->multibyte_p
;
24528 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24530 /* In R2L rows, the left and the right box edges need to be
24531 drawn in reverse direction. */
24532 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24533 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24537 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24538 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24540 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24541 || it
->phys_descent
> it
->descent
);
24542 glyph
->padding_p
= 0;
24543 glyph
->glyph_not_available_p
= 0;
24544 glyph
->face_id
= face_id
;
24545 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24548 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24549 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24551 glyph
->bidi_type
= it
->bidi_it
.type
;
24553 ++it
->glyph_row
->used
[area
];
24556 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24560 /* Produce a glyph for a glyphless character for iterator IT.
24561 IT->glyphless_method specifies which method to use for displaying
24562 the character. See the description of enum
24563 glyphless_display_method in dispextern.h for the detail.
24565 FOR_NO_FONT is nonzero if and only if this is for a character for
24566 which no font was found. ACRONYM, if non-nil, is an acronym string
24567 for the character. */
24570 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24575 int base_width
, base_height
, width
, height
;
24576 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24579 /* Get the metrics of the base font. We always refer to the current
24581 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24582 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24583 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24584 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24585 base_height
= it
->ascent
+ it
->descent
;
24586 base_width
= font
->average_width
;
24588 /* Get a face ID for the glyph by utilizing a cache (the same way as
24589 done for `escape-glyph' in get_next_display_element). */
24590 if (it
->f
== last_glyphless_glyph_frame
24591 && it
->face_id
== last_glyphless_glyph_face_id
)
24593 face_id
= last_glyphless_glyph_merged_face_id
;
24597 /* Merge the `glyphless-char' face into the current face. */
24598 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24599 last_glyphless_glyph_frame
= it
->f
;
24600 last_glyphless_glyph_face_id
= it
->face_id
;
24601 last_glyphless_glyph_merged_face_id
= face_id
;
24604 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24606 it
->pixel_width
= THIN_SPACE_WIDTH
;
24608 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24610 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24612 width
= CHAR_WIDTH (it
->c
);
24615 else if (width
> 4)
24617 it
->pixel_width
= base_width
* width
;
24619 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24625 unsigned int code
[6];
24627 int ascent
, descent
;
24628 struct font_metrics metrics_upper
, metrics_lower
;
24630 face
= FACE_FROM_ID (it
->f
, face_id
);
24631 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24632 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24634 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24636 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24637 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24638 if (CONSP (acronym
))
24639 acronym
= XCAR (acronym
);
24640 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24644 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24645 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24648 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24649 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24650 upper_len
= (len
+ 1) / 2;
24651 font
->driver
->text_extents (font
, code
, upper_len
,
24653 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24658 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24659 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24660 upper_xoff
= upper_yoff
= 2; /* the typical case */
24661 if (base_width
>= width
)
24663 /* Align the upper to the left, the lower to the right. */
24664 it
->pixel_width
= base_width
;
24665 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24669 /* Center the shorter one. */
24670 it
->pixel_width
= width
;
24671 if (metrics_upper
.width
>= metrics_lower
.width
)
24672 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24675 /* FIXME: This code doesn't look right. It formerly was
24676 missing the "lower_xoff = 0;", which couldn't have
24677 been right since it left lower_xoff uninitialized. */
24679 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24683 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24684 top, bottom, and between upper and lower strings. */
24685 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24686 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24687 /* Center vertically.
24688 H:base_height, D:base_descent
24689 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24691 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24692 descent = D - H/2 + h/2;
24693 lower_yoff = descent - 2 - ld;
24694 upper_yoff = lower_yoff - la - 1 - ud; */
24695 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24696 descent
= it
->descent
- (base_height
- height
) / 2;
24697 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24698 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24699 - metrics_upper
.descent
);
24700 /* Don't make the height shorter than the base height. */
24701 if (height
> base_height
)
24703 it
->ascent
= ascent
;
24704 it
->descent
= descent
;
24708 it
->phys_ascent
= it
->ascent
;
24709 it
->phys_descent
= it
->descent
;
24711 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24712 upper_xoff
, upper_yoff
,
24713 lower_xoff
, lower_yoff
);
24715 take_vertical_position_into_account (it
);
24720 Produce glyphs/get display metrics for the display element IT is
24721 loaded with. See the description of struct it in dispextern.h
24722 for an overview of struct it. */
24725 x_produce_glyphs (struct it
*it
)
24727 int extra_line_spacing
= it
->extra_line_spacing
;
24729 it
->glyph_not_available_p
= 0;
24731 if (it
->what
== IT_CHARACTER
)
24734 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24735 struct font
*font
= face
->font
;
24736 struct font_metrics
*pcm
= NULL
;
24737 int boff
; /* baseline offset */
24741 /* When no suitable font is found, display this character by
24742 the method specified in the first extra slot of
24743 Vglyphless_char_display. */
24744 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24746 eassert (it
->what
== IT_GLYPHLESS
);
24747 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24751 boff
= font
->baseline_offset
;
24752 if (font
->vertical_centering
)
24753 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24755 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24761 if (it
->override_ascent
>= 0)
24763 it
->ascent
= it
->override_ascent
;
24764 it
->descent
= it
->override_descent
;
24765 boff
= it
->override_boff
;
24769 it
->ascent
= FONT_BASE (font
) + boff
;
24770 it
->descent
= FONT_DESCENT (font
) - boff
;
24773 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24775 pcm
= get_per_char_metric (font
, &char2b
);
24776 if (pcm
->width
== 0
24777 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24783 it
->phys_ascent
= pcm
->ascent
+ boff
;
24784 it
->phys_descent
= pcm
->descent
- boff
;
24785 it
->pixel_width
= pcm
->width
;
24789 it
->glyph_not_available_p
= 1;
24790 it
->phys_ascent
= it
->ascent
;
24791 it
->phys_descent
= it
->descent
;
24792 it
->pixel_width
= font
->space_width
;
24795 if (it
->constrain_row_ascent_descent_p
)
24797 if (it
->descent
> it
->max_descent
)
24799 it
->ascent
+= it
->descent
- it
->max_descent
;
24800 it
->descent
= it
->max_descent
;
24802 if (it
->ascent
> it
->max_ascent
)
24804 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24805 it
->ascent
= it
->max_ascent
;
24807 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24808 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24809 extra_line_spacing
= 0;
24812 /* If this is a space inside a region of text with
24813 `space-width' property, change its width. */
24814 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24816 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24818 /* If face has a box, add the box thickness to the character
24819 height. If character has a box line to the left and/or
24820 right, add the box line width to the character's width. */
24821 if (face
->box
!= FACE_NO_BOX
)
24823 int thick
= face
->box_line_width
;
24827 it
->ascent
+= thick
;
24828 it
->descent
+= thick
;
24833 if (it
->start_of_box_run_p
)
24834 it
->pixel_width
+= thick
;
24835 if (it
->end_of_box_run_p
)
24836 it
->pixel_width
+= thick
;
24839 /* If face has an overline, add the height of the overline
24840 (1 pixel) and a 1 pixel margin to the character height. */
24841 if (face
->overline_p
)
24842 it
->ascent
+= overline_margin
;
24844 if (it
->constrain_row_ascent_descent_p
)
24846 if (it
->ascent
> it
->max_ascent
)
24847 it
->ascent
= it
->max_ascent
;
24848 if (it
->descent
> it
->max_descent
)
24849 it
->descent
= it
->max_descent
;
24852 take_vertical_position_into_account (it
);
24854 /* If we have to actually produce glyphs, do it. */
24859 /* Translate a space with a `space-width' property
24860 into a stretch glyph. */
24861 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24862 / FONT_HEIGHT (font
));
24863 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24864 it
->ascent
+ it
->descent
, ascent
);
24869 /* If characters with lbearing or rbearing are displayed
24870 in this line, record that fact in a flag of the
24871 glyph row. This is used to optimize X output code. */
24872 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24873 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24875 if (! stretched_p
&& it
->pixel_width
== 0)
24876 /* We assure that all visible glyphs have at least 1-pixel
24878 it
->pixel_width
= 1;
24880 else if (it
->char_to_display
== '\n')
24882 /* A newline has no width, but we need the height of the
24883 line. But if previous part of the line sets a height,
24884 don't increase that height */
24886 Lisp_Object height
;
24887 Lisp_Object total_height
= Qnil
;
24889 it
->override_ascent
= -1;
24890 it
->pixel_width
= 0;
24893 height
= get_it_property (it
, Qline_height
);
24894 /* Split (line-height total-height) list */
24896 && CONSP (XCDR (height
))
24897 && NILP (XCDR (XCDR (height
))))
24899 total_height
= XCAR (XCDR (height
));
24900 height
= XCAR (height
);
24902 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24904 if (it
->override_ascent
>= 0)
24906 it
->ascent
= it
->override_ascent
;
24907 it
->descent
= it
->override_descent
;
24908 boff
= it
->override_boff
;
24912 it
->ascent
= FONT_BASE (font
) + boff
;
24913 it
->descent
= FONT_DESCENT (font
) - boff
;
24916 if (EQ (height
, Qt
))
24918 if (it
->descent
> it
->max_descent
)
24920 it
->ascent
+= it
->descent
- it
->max_descent
;
24921 it
->descent
= it
->max_descent
;
24923 if (it
->ascent
> it
->max_ascent
)
24925 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24926 it
->ascent
= it
->max_ascent
;
24928 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24929 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24930 it
->constrain_row_ascent_descent_p
= 1;
24931 extra_line_spacing
= 0;
24935 Lisp_Object spacing
;
24937 it
->phys_ascent
= it
->ascent
;
24938 it
->phys_descent
= it
->descent
;
24940 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24941 && face
->box
!= FACE_NO_BOX
24942 && face
->box_line_width
> 0)
24944 it
->ascent
+= face
->box_line_width
;
24945 it
->descent
+= face
->box_line_width
;
24948 && XINT (height
) > it
->ascent
+ it
->descent
)
24949 it
->ascent
= XINT (height
) - it
->descent
;
24951 if (!NILP (total_height
))
24952 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
24955 spacing
= get_it_property (it
, Qline_spacing
);
24956 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
24958 if (INTEGERP (spacing
))
24960 extra_line_spacing
= XINT (spacing
);
24961 if (!NILP (total_height
))
24962 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
24966 else /* i.e. (it->char_to_display == '\t') */
24968 if (font
->space_width
> 0)
24970 int tab_width
= it
->tab_width
* font
->space_width
;
24971 int x
= it
->current_x
+ it
->continuation_lines_width
;
24972 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
24974 /* If the distance from the current position to the next tab
24975 stop is less than a space character width, use the
24976 tab stop after that. */
24977 if (next_tab_x
- x
< font
->space_width
)
24978 next_tab_x
+= tab_width
;
24980 it
->pixel_width
= next_tab_x
- x
;
24982 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
24983 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
24987 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24988 it
->ascent
+ it
->descent
, it
->ascent
);
24993 it
->pixel_width
= 0;
24998 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25000 /* A static composition.
25002 Note: A composition is represented as one glyph in the
25003 glyph matrix. There are no padding glyphs.
25005 Important note: pixel_width, ascent, and descent are the
25006 values of what is drawn by draw_glyphs (i.e. the values of
25007 the overall glyphs composed). */
25008 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25009 int boff
; /* baseline offset */
25010 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25011 int glyph_len
= cmp
->glyph_len
;
25012 struct font
*font
= face
->font
;
25016 /* If we have not yet calculated pixel size data of glyphs of
25017 the composition for the current face font, calculate them
25018 now. Theoretically, we have to check all fonts for the
25019 glyphs, but that requires much time and memory space. So,
25020 here we check only the font of the first glyph. This may
25021 lead to incorrect display, but it's very rare, and C-l
25022 (recenter-top-bottom) can correct the display anyway. */
25023 if (! cmp
->font
|| cmp
->font
!= font
)
25025 /* Ascent and descent of the font of the first character
25026 of this composition (adjusted by baseline offset).
25027 Ascent and descent of overall glyphs should not be less
25028 than these, respectively. */
25029 int font_ascent
, font_descent
, font_height
;
25030 /* Bounding box of the overall glyphs. */
25031 int leftmost
, rightmost
, lowest
, highest
;
25032 int lbearing
, rbearing
;
25033 int i
, width
, ascent
, descent
;
25034 int left_padded
= 0, right_padded
= 0;
25035 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25037 struct font_metrics
*pcm
;
25038 int font_not_found_p
;
25041 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25042 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25044 if (glyph_len
< cmp
->glyph_len
)
25046 for (i
= 0; i
< glyph_len
; i
++)
25048 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25050 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25055 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25056 : IT_CHARPOS (*it
));
25057 /* If no suitable font is found, use the default font. */
25058 font_not_found_p
= font
== NULL
;
25059 if (font_not_found_p
)
25061 face
= face
->ascii_face
;
25064 boff
= font
->baseline_offset
;
25065 if (font
->vertical_centering
)
25066 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25067 font_ascent
= FONT_BASE (font
) + boff
;
25068 font_descent
= FONT_DESCENT (font
) - boff
;
25069 font_height
= FONT_HEIGHT (font
);
25074 if (! font_not_found_p
)
25076 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25078 pcm
= get_per_char_metric (font
, &char2b
);
25081 /* Initialize the bounding box. */
25084 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25085 ascent
= pcm
->ascent
;
25086 descent
= pcm
->descent
;
25087 lbearing
= pcm
->lbearing
;
25088 rbearing
= pcm
->rbearing
;
25092 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25093 ascent
= FONT_BASE (font
);
25094 descent
= FONT_DESCENT (font
);
25101 lowest
= - descent
+ boff
;
25102 highest
= ascent
+ boff
;
25104 if (! font_not_found_p
25105 && font
->default_ascent
25106 && CHAR_TABLE_P (Vuse_default_ascent
)
25107 && !NILP (Faref (Vuse_default_ascent
,
25108 make_number (it
->char_to_display
))))
25109 highest
= font
->default_ascent
+ boff
;
25111 /* Draw the first glyph at the normal position. It may be
25112 shifted to right later if some other glyphs are drawn
25114 cmp
->offsets
[i
* 2] = 0;
25115 cmp
->offsets
[i
* 2 + 1] = boff
;
25116 cmp
->lbearing
= lbearing
;
25117 cmp
->rbearing
= rbearing
;
25119 /* Set cmp->offsets for the remaining glyphs. */
25120 for (i
++; i
< glyph_len
; i
++)
25122 int left
, right
, btm
, top
;
25123 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25125 struct face
*this_face
;
25129 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25130 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25131 font
= this_face
->font
;
25137 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25139 pcm
= get_per_char_metric (font
, &char2b
);
25142 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25145 width
= pcm
->width
;
25146 ascent
= pcm
->ascent
;
25147 descent
= pcm
->descent
;
25148 lbearing
= pcm
->lbearing
;
25149 rbearing
= pcm
->rbearing
;
25150 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25152 /* Relative composition with or without
25153 alternate chars. */
25154 left
= (leftmost
+ rightmost
- width
) / 2;
25155 btm
= - descent
+ boff
;
25156 if (font
->relative_compose
25157 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25158 || NILP (Faref (Vignore_relative_composition
,
25159 make_number (ch
)))))
25162 if (- descent
>= font
->relative_compose
)
25163 /* One extra pixel between two glyphs. */
25165 else if (ascent
<= 0)
25166 /* One extra pixel between two glyphs. */
25167 btm
= lowest
- 1 - ascent
- descent
;
25172 /* A composition rule is specified by an integer
25173 value that encodes global and new reference
25174 points (GREF and NREF). GREF and NREF are
25175 specified by numbers as below:
25177 0---1---2 -- ascent
25181 9--10--11 -- center
25183 ---3---4---5--- baseline
25185 6---7---8 -- descent
25187 int rule
= COMPOSITION_RULE (cmp
, i
);
25188 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25190 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25191 grefx
= gref
% 3, nrefx
= nref
% 3;
25192 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25194 xoff
= font_height
* (xoff
- 128) / 256;
25196 yoff
= font_height
* (yoff
- 128) / 256;
25199 + grefx
* (rightmost
- leftmost
) / 2
25200 - nrefx
* width
/ 2
25203 btm
= ((grefy
== 0 ? highest
25205 : grefy
== 2 ? lowest
25206 : (highest
+ lowest
) / 2)
25207 - (nrefy
== 0 ? ascent
+ descent
25208 : nrefy
== 1 ? descent
- boff
25210 : (ascent
+ descent
) / 2)
25214 cmp
->offsets
[i
* 2] = left
;
25215 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25217 /* Update the bounding box of the overall glyphs. */
25220 right
= left
+ width
;
25221 if (left
< leftmost
)
25223 if (right
> rightmost
)
25226 top
= btm
+ descent
+ ascent
;
25232 if (cmp
->lbearing
> left
+ lbearing
)
25233 cmp
->lbearing
= left
+ lbearing
;
25234 if (cmp
->rbearing
< left
+ rbearing
)
25235 cmp
->rbearing
= left
+ rbearing
;
25239 /* If there are glyphs whose x-offsets are negative,
25240 shift all glyphs to the right and make all x-offsets
25244 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25245 cmp
->offsets
[i
* 2] -= leftmost
;
25246 rightmost
-= leftmost
;
25247 cmp
->lbearing
-= leftmost
;
25248 cmp
->rbearing
-= leftmost
;
25251 if (left_padded
&& cmp
->lbearing
< 0)
25253 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25254 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25255 rightmost
-= cmp
->lbearing
;
25256 cmp
->rbearing
-= cmp
->lbearing
;
25259 if (right_padded
&& rightmost
< cmp
->rbearing
)
25261 rightmost
= cmp
->rbearing
;
25264 cmp
->pixel_width
= rightmost
;
25265 cmp
->ascent
= highest
;
25266 cmp
->descent
= - lowest
;
25267 if (cmp
->ascent
< font_ascent
)
25268 cmp
->ascent
= font_ascent
;
25269 if (cmp
->descent
< font_descent
)
25270 cmp
->descent
= font_descent
;
25274 && (cmp
->lbearing
< 0
25275 || cmp
->rbearing
> cmp
->pixel_width
))
25276 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25278 it
->pixel_width
= cmp
->pixel_width
;
25279 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25280 it
->descent
= it
->phys_descent
= cmp
->descent
;
25281 if (face
->box
!= FACE_NO_BOX
)
25283 int thick
= face
->box_line_width
;
25287 it
->ascent
+= thick
;
25288 it
->descent
+= thick
;
25293 if (it
->start_of_box_run_p
)
25294 it
->pixel_width
+= thick
;
25295 if (it
->end_of_box_run_p
)
25296 it
->pixel_width
+= thick
;
25299 /* If face has an overline, add the height of the overline
25300 (1 pixel) and a 1 pixel margin to the character height. */
25301 if (face
->overline_p
)
25302 it
->ascent
+= overline_margin
;
25304 take_vertical_position_into_account (it
);
25305 if (it
->ascent
< 0)
25307 if (it
->descent
< 0)
25310 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25311 append_composite_glyph (it
);
25313 else if (it
->what
== IT_COMPOSITION
)
25315 /* A dynamic (automatic) composition. */
25316 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25317 Lisp_Object gstring
;
25318 struct font_metrics metrics
;
25322 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25324 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25327 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25328 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25329 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25330 it
->descent
= it
->phys_descent
= metrics
.descent
;
25331 if (face
->box
!= FACE_NO_BOX
)
25333 int thick
= face
->box_line_width
;
25337 it
->ascent
+= thick
;
25338 it
->descent
+= thick
;
25343 if (it
->start_of_box_run_p
)
25344 it
->pixel_width
+= thick
;
25345 if (it
->end_of_box_run_p
)
25346 it
->pixel_width
+= thick
;
25348 /* If face has an overline, add the height of the overline
25349 (1 pixel) and a 1 pixel margin to the character height. */
25350 if (face
->overline_p
)
25351 it
->ascent
+= overline_margin
;
25352 take_vertical_position_into_account (it
);
25353 if (it
->ascent
< 0)
25355 if (it
->descent
< 0)
25359 append_composite_glyph (it
);
25361 else if (it
->what
== IT_GLYPHLESS
)
25362 produce_glyphless_glyph (it
, 0, Qnil
);
25363 else if (it
->what
== IT_IMAGE
)
25364 produce_image_glyph (it
);
25365 else if (it
->what
== IT_STRETCH
)
25366 produce_stretch_glyph (it
);
25369 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25370 because this isn't true for images with `:ascent 100'. */
25371 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25372 if (it
->area
== TEXT_AREA
)
25373 it
->current_x
+= it
->pixel_width
;
25375 if (extra_line_spacing
> 0)
25377 it
->descent
+= extra_line_spacing
;
25378 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25379 it
->max_extra_line_spacing
= extra_line_spacing
;
25382 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25383 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25384 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25385 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25389 Output LEN glyphs starting at START at the nominal cursor position.
25390 Advance the nominal cursor over the text. The global variable
25391 updated_window contains the window being updated, updated_row is
25392 the glyph row being updated, and updated_area is the area of that
25393 row being updated. */
25396 x_write_glyphs (struct glyph
*start
, int len
)
25398 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25400 eassert (updated_window
&& updated_row
);
25401 /* When the window is hscrolled, cursor hpos can legitimately be out
25402 of bounds, but we draw the cursor at the corresponding window
25403 margin in that case. */
25404 if (!updated_row
->reversed_p
&& chpos
< 0)
25406 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25407 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25411 /* Write glyphs. */
25413 hpos
= start
- updated_row
->glyphs
[updated_area
];
25414 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25415 updated_row
, updated_area
,
25417 DRAW_NORMAL_TEXT
, 0);
25419 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25420 if (updated_area
== TEXT_AREA
25421 && updated_window
->phys_cursor_on_p
25422 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25424 && chpos
< hpos
+ len
)
25425 updated_window
->phys_cursor_on_p
= 0;
25429 /* Advance the output cursor. */
25430 output_cursor
.hpos
+= len
;
25431 output_cursor
.x
= x
;
25436 Insert LEN glyphs from START at the nominal cursor position. */
25439 x_insert_glyphs (struct glyph
*start
, int len
)
25443 int line_height
, shift_by_width
, shifted_region_width
;
25444 struct glyph_row
*row
;
25445 struct glyph
*glyph
;
25446 int frame_x
, frame_y
;
25449 eassert (updated_window
&& updated_row
);
25451 w
= updated_window
;
25452 f
= XFRAME (WINDOW_FRAME (w
));
25454 /* Get the height of the line we are in. */
25456 line_height
= row
->height
;
25458 /* Get the width of the glyphs to insert. */
25459 shift_by_width
= 0;
25460 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25461 shift_by_width
+= glyph
->pixel_width
;
25463 /* Get the width of the region to shift right. */
25464 shifted_region_width
= (window_box_width (w
, updated_area
)
25469 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25470 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25472 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25473 line_height
, shift_by_width
);
25475 /* Write the glyphs. */
25476 hpos
= start
- row
->glyphs
[updated_area
];
25477 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25479 DRAW_NORMAL_TEXT
, 0);
25481 /* Advance the output cursor. */
25482 output_cursor
.hpos
+= len
;
25483 output_cursor
.x
+= shift_by_width
;
25489 Erase the current text line from the nominal cursor position
25490 (inclusive) to pixel column TO_X (exclusive). The idea is that
25491 everything from TO_X onward is already erased.
25493 TO_X is a pixel position relative to updated_area of
25494 updated_window. TO_X == -1 means clear to the end of this area. */
25497 x_clear_end_of_line (int to_x
)
25500 struct window
*w
= updated_window
;
25501 int max_x
, min_y
, max_y
;
25502 int from_x
, from_y
, to_y
;
25504 eassert (updated_window
&& updated_row
);
25505 f
= XFRAME (w
->frame
);
25507 if (updated_row
->full_width_p
)
25508 max_x
= WINDOW_TOTAL_WIDTH (w
);
25510 max_x
= window_box_width (w
, updated_area
);
25511 max_y
= window_text_bottom_y (w
);
25513 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25514 of window. For TO_X > 0, truncate to end of drawing area. */
25520 to_x
= min (to_x
, max_x
);
25522 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25524 /* Notice if the cursor will be cleared by this operation. */
25525 if (!updated_row
->full_width_p
)
25526 notice_overwritten_cursor (w
, updated_area
,
25527 output_cursor
.x
, -1,
25529 MATRIX_ROW_BOTTOM_Y (updated_row
));
25531 from_x
= output_cursor
.x
;
25533 /* Translate to frame coordinates. */
25534 if (updated_row
->full_width_p
)
25536 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25537 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25541 int area_left
= window_box_left (w
, updated_area
);
25542 from_x
+= area_left
;
25546 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25547 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25548 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25550 /* Prevent inadvertently clearing to end of the X window. */
25551 if (to_x
> from_x
&& to_y
> from_y
)
25554 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25555 to_x
- from_x
, to_y
- from_y
);
25560 #endif /* HAVE_WINDOW_SYSTEM */
25564 /***********************************************************************
25566 ***********************************************************************/
25568 /* Value is the internal representation of the specified cursor type
25569 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25570 of the bar cursor. */
25572 static enum text_cursor_kinds
25573 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25575 enum text_cursor_kinds type
;
25580 if (EQ (arg
, Qbox
))
25581 return FILLED_BOX_CURSOR
;
25583 if (EQ (arg
, Qhollow
))
25584 return HOLLOW_BOX_CURSOR
;
25586 if (EQ (arg
, Qbar
))
25593 && EQ (XCAR (arg
), Qbar
)
25594 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25596 *width
= XINT (XCDR (arg
));
25600 if (EQ (arg
, Qhbar
))
25603 return HBAR_CURSOR
;
25607 && EQ (XCAR (arg
), Qhbar
)
25608 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25610 *width
= XINT (XCDR (arg
));
25611 return HBAR_CURSOR
;
25614 /* Treat anything unknown as "hollow box cursor".
25615 It was bad to signal an error; people have trouble fixing
25616 .Xdefaults with Emacs, when it has something bad in it. */
25617 type
= HOLLOW_BOX_CURSOR
;
25622 /* Set the default cursor types for specified frame. */
25624 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25629 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25630 FRAME_CURSOR_WIDTH (f
) = width
;
25632 /* By default, set up the blink-off state depending on the on-state. */
25634 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25637 FRAME_BLINK_OFF_CURSOR (f
)
25638 = get_specified_cursor_type (XCDR (tem
), &width
);
25639 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25642 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25646 #ifdef HAVE_WINDOW_SYSTEM
25648 /* Return the cursor we want to be displayed in window W. Return
25649 width of bar/hbar cursor through WIDTH arg. Return with
25650 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25651 (i.e. if the `system caret' should track this cursor).
25653 In a mini-buffer window, we want the cursor only to appear if we
25654 are reading input from this window. For the selected window, we
25655 want the cursor type given by the frame parameter or buffer local
25656 setting of cursor-type. If explicitly marked off, draw no cursor.
25657 In all other cases, we want a hollow box cursor. */
25659 static enum text_cursor_kinds
25660 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25661 int *active_cursor
)
25663 struct frame
*f
= XFRAME (w
->frame
);
25664 struct buffer
*b
= XBUFFER (w
->buffer
);
25665 int cursor_type
= DEFAULT_CURSOR
;
25666 Lisp_Object alt_cursor
;
25667 int non_selected
= 0;
25669 *active_cursor
= 1;
25672 if (cursor_in_echo_area
25673 && FRAME_HAS_MINIBUF_P (f
)
25674 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25676 if (w
== XWINDOW (echo_area_window
))
25678 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25680 *width
= FRAME_CURSOR_WIDTH (f
);
25681 return FRAME_DESIRED_CURSOR (f
);
25684 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25687 *active_cursor
= 0;
25691 /* Detect a nonselected window or nonselected frame. */
25692 else if (w
!= XWINDOW (f
->selected_window
)
25693 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25695 *active_cursor
= 0;
25697 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25703 /* Never display a cursor in a window in which cursor-type is nil. */
25704 if (NILP (BVAR (b
, cursor_type
)))
25707 /* Get the normal cursor type for this window. */
25708 if (EQ (BVAR (b
, cursor_type
), Qt
))
25710 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25711 *width
= FRAME_CURSOR_WIDTH (f
);
25714 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25716 /* Use cursor-in-non-selected-windows instead
25717 for non-selected window or frame. */
25720 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25721 if (!EQ (Qt
, alt_cursor
))
25722 return get_specified_cursor_type (alt_cursor
, width
);
25723 /* t means modify the normal cursor type. */
25724 if (cursor_type
== FILLED_BOX_CURSOR
)
25725 cursor_type
= HOLLOW_BOX_CURSOR
;
25726 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25728 return cursor_type
;
25731 /* Use normal cursor if not blinked off. */
25732 if (!w
->cursor_off_p
)
25734 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25736 if (cursor_type
== FILLED_BOX_CURSOR
)
25738 /* Using a block cursor on large images can be very annoying.
25739 So use a hollow cursor for "large" images.
25740 If image is not transparent (no mask), also use hollow cursor. */
25741 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25742 if (img
!= NULL
&& IMAGEP (img
->spec
))
25744 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25745 where N = size of default frame font size.
25746 This should cover most of the "tiny" icons people may use. */
25748 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25749 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25750 cursor_type
= HOLLOW_BOX_CURSOR
;
25753 else if (cursor_type
!= NO_CURSOR
)
25755 /* Display current only supports BOX and HOLLOW cursors for images.
25756 So for now, unconditionally use a HOLLOW cursor when cursor is
25757 not a solid box cursor. */
25758 cursor_type
= HOLLOW_BOX_CURSOR
;
25761 return cursor_type
;
25764 /* Cursor is blinked off, so determine how to "toggle" it. */
25766 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25767 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25768 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25770 /* Then see if frame has specified a specific blink off cursor type. */
25771 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25773 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25774 return FRAME_BLINK_OFF_CURSOR (f
);
25778 /* Some people liked having a permanently visible blinking cursor,
25779 while others had very strong opinions against it. So it was
25780 decided to remove it. KFS 2003-09-03 */
25782 /* Finally perform built-in cursor blinking:
25783 filled box <-> hollow box
25784 wide [h]bar <-> narrow [h]bar
25785 narrow [h]bar <-> no cursor
25786 other type <-> no cursor */
25788 if (cursor_type
== FILLED_BOX_CURSOR
)
25789 return HOLLOW_BOX_CURSOR
;
25791 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25794 return cursor_type
;
25802 /* Notice when the text cursor of window W has been completely
25803 overwritten by a drawing operation that outputs glyphs in AREA
25804 starting at X0 and ending at X1 in the line starting at Y0 and
25805 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25806 the rest of the line after X0 has been written. Y coordinates
25807 are window-relative. */
25810 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25811 int x0
, int x1
, int y0
, int y1
)
25813 int cx0
, cx1
, cy0
, cy1
;
25814 struct glyph_row
*row
;
25816 if (!w
->phys_cursor_on_p
)
25818 if (area
!= TEXT_AREA
)
25821 if (w
->phys_cursor
.vpos
< 0
25822 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25823 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25824 !(row
->enabled_p
&& row
->displays_text_p
)))
25827 if (row
->cursor_in_fringe_p
)
25829 row
->cursor_in_fringe_p
= 0;
25830 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25831 w
->phys_cursor_on_p
= 0;
25835 cx0
= w
->phys_cursor
.x
;
25836 cx1
= cx0
+ w
->phys_cursor_width
;
25837 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25840 /* The cursor image will be completely removed from the
25841 screen if the output area intersects the cursor area in
25842 y-direction. When we draw in [y0 y1[, and some part of
25843 the cursor is at y < y0, that part must have been drawn
25844 before. When scrolling, the cursor is erased before
25845 actually scrolling, so we don't come here. When not
25846 scrolling, the rows above the old cursor row must have
25847 changed, and in this case these rows must have written
25848 over the cursor image.
25850 Likewise if part of the cursor is below y1, with the
25851 exception of the cursor being in the first blank row at
25852 the buffer and window end because update_text_area
25853 doesn't draw that row. (Except when it does, but
25854 that's handled in update_text_area.) */
25856 cy0
= w
->phys_cursor
.y
;
25857 cy1
= cy0
+ w
->phys_cursor_height
;
25858 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25861 w
->phys_cursor_on_p
= 0;
25864 #endif /* HAVE_WINDOW_SYSTEM */
25867 /************************************************************************
25869 ************************************************************************/
25871 #ifdef HAVE_WINDOW_SYSTEM
25874 Fix the display of area AREA of overlapping row ROW in window W
25875 with respect to the overlapping part OVERLAPS. */
25878 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25879 enum glyph_row_area area
, int overlaps
)
25886 for (i
= 0; i
< row
->used
[area
];)
25888 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25890 int start
= i
, start_x
= x
;
25894 x
+= row
->glyphs
[area
][i
].pixel_width
;
25897 while (i
< row
->used
[area
]
25898 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25900 draw_glyphs (w
, start_x
, row
, area
,
25902 DRAW_NORMAL_TEXT
, overlaps
);
25906 x
+= row
->glyphs
[area
][i
].pixel_width
;
25916 Draw the cursor glyph of window W in glyph row ROW. See the
25917 comment of draw_glyphs for the meaning of HL. */
25920 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25921 enum draw_glyphs_face hl
)
25923 /* If cursor hpos is out of bounds, don't draw garbage. This can
25924 happen in mini-buffer windows when switching between echo area
25925 glyphs and mini-buffer. */
25926 if ((row
->reversed_p
25927 ? (w
->phys_cursor
.hpos
>= 0)
25928 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25930 int on_p
= w
->phys_cursor_on_p
;
25932 int hpos
= w
->phys_cursor
.hpos
;
25934 /* When the window is hscrolled, cursor hpos can legitimately be
25935 out of bounds, but we draw the cursor at the corresponding
25936 window margin in that case. */
25937 if (!row
->reversed_p
&& hpos
< 0)
25939 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25940 hpos
= row
->used
[TEXT_AREA
] - 1;
25942 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25944 w
->phys_cursor_on_p
= on_p
;
25946 if (hl
== DRAW_CURSOR
)
25947 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25948 /* When we erase the cursor, and ROW is overlapped by other
25949 rows, make sure that these overlapping parts of other rows
25951 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25953 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25955 if (row
> w
->current_matrix
->rows
25956 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
25957 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
25958 OVERLAPS_ERASED_CURSOR
);
25960 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
25961 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
25962 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
25963 OVERLAPS_ERASED_CURSOR
);
25970 Erase the image of a cursor of window W from the screen. */
25973 erase_phys_cursor (struct window
*w
)
25975 struct frame
*f
= XFRAME (w
->frame
);
25976 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
25977 int hpos
= w
->phys_cursor
.hpos
;
25978 int vpos
= w
->phys_cursor
.vpos
;
25979 int mouse_face_here_p
= 0;
25980 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
25981 struct glyph_row
*cursor_row
;
25982 struct glyph
*cursor_glyph
;
25983 enum draw_glyphs_face hl
;
25985 /* No cursor displayed or row invalidated => nothing to do on the
25987 if (w
->phys_cursor_type
== NO_CURSOR
)
25988 goto mark_cursor_off
;
25990 /* VPOS >= active_glyphs->nrows means that window has been resized.
25991 Don't bother to erase the cursor. */
25992 if (vpos
>= active_glyphs
->nrows
)
25993 goto mark_cursor_off
;
25995 /* If row containing cursor is marked invalid, there is nothing we
25997 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
25998 if (!cursor_row
->enabled_p
)
25999 goto mark_cursor_off
;
26001 /* If line spacing is > 0, old cursor may only be partially visible in
26002 window after split-window. So adjust visible height. */
26003 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26004 window_text_bottom_y (w
) - cursor_row
->y
);
26006 /* If row is completely invisible, don't attempt to delete a cursor which
26007 isn't there. This can happen if cursor is at top of a window, and
26008 we switch to a buffer with a header line in that window. */
26009 if (cursor_row
->visible_height
<= 0)
26010 goto mark_cursor_off
;
26012 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26013 if (cursor_row
->cursor_in_fringe_p
)
26015 cursor_row
->cursor_in_fringe_p
= 0;
26016 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26017 goto mark_cursor_off
;
26020 /* This can happen when the new row is shorter than the old one.
26021 In this case, either draw_glyphs or clear_end_of_line
26022 should have cleared the cursor. Note that we wouldn't be
26023 able to erase the cursor in this case because we don't have a
26024 cursor glyph at hand. */
26025 if ((cursor_row
->reversed_p
26026 ? (w
->phys_cursor
.hpos
< 0)
26027 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26028 goto mark_cursor_off
;
26030 /* When the window is hscrolled, cursor hpos can legitimately be out
26031 of bounds, but we draw the cursor at the corresponding window
26032 margin in that case. */
26033 if (!cursor_row
->reversed_p
&& hpos
< 0)
26035 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26036 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26038 /* If the cursor is in the mouse face area, redisplay that when
26039 we clear the cursor. */
26040 if (! NILP (hlinfo
->mouse_face_window
)
26041 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26042 /* Don't redraw the cursor's spot in mouse face if it is at the
26043 end of a line (on a newline). The cursor appears there, but
26044 mouse highlighting does not. */
26045 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26046 mouse_face_here_p
= 1;
26048 /* Maybe clear the display under the cursor. */
26049 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26052 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26055 cursor_glyph
= get_phys_cursor_glyph (w
);
26056 if (cursor_glyph
== NULL
)
26057 goto mark_cursor_off
;
26059 width
= cursor_glyph
->pixel_width
;
26060 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26061 x
= w
->phys_cursor
.x
;
26063 width
-= left_x
- x
;
26064 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26065 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26066 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26069 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26072 /* Erase the cursor by redrawing the character underneath it. */
26073 if (mouse_face_here_p
)
26074 hl
= DRAW_MOUSE_FACE
;
26076 hl
= DRAW_NORMAL_TEXT
;
26077 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26080 w
->phys_cursor_on_p
= 0;
26081 w
->phys_cursor_type
= NO_CURSOR
;
26086 Display or clear cursor of window W. If ON is zero, clear the
26087 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26088 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26091 display_and_set_cursor (struct window
*w
, int on
,
26092 int hpos
, int vpos
, int x
, int y
)
26094 struct frame
*f
= XFRAME (w
->frame
);
26095 int new_cursor_type
;
26096 int new_cursor_width
;
26098 struct glyph_row
*glyph_row
;
26099 struct glyph
*glyph
;
26101 /* This is pointless on invisible frames, and dangerous on garbaged
26102 windows and frames; in the latter case, the frame or window may
26103 be in the midst of changing its size, and x and y may be off the
26105 if (! FRAME_VISIBLE_P (f
)
26106 || FRAME_GARBAGED_P (f
)
26107 || vpos
>= w
->current_matrix
->nrows
26108 || hpos
>= w
->current_matrix
->matrix_w
)
26111 /* If cursor is off and we want it off, return quickly. */
26112 if (!on
&& !w
->phys_cursor_on_p
)
26115 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26116 /* If cursor row is not enabled, we don't really know where to
26117 display the cursor. */
26118 if (!glyph_row
->enabled_p
)
26120 w
->phys_cursor_on_p
= 0;
26125 if (!glyph_row
->exact_window_width_line_p
26126 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26127 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26129 eassert (input_blocked_p ());
26131 /* Set new_cursor_type to the cursor we want to be displayed. */
26132 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26133 &new_cursor_width
, &active_cursor
);
26135 /* If cursor is currently being shown and we don't want it to be or
26136 it is in the wrong place, or the cursor type is not what we want,
26138 if (w
->phys_cursor_on_p
26140 || w
->phys_cursor
.x
!= x
26141 || w
->phys_cursor
.y
!= y
26142 || new_cursor_type
!= w
->phys_cursor_type
26143 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26144 && new_cursor_width
!= w
->phys_cursor_width
)))
26145 erase_phys_cursor (w
);
26147 /* Don't check phys_cursor_on_p here because that flag is only set
26148 to zero in some cases where we know that the cursor has been
26149 completely erased, to avoid the extra work of erasing the cursor
26150 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26151 still not be visible, or it has only been partly erased. */
26154 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26155 w
->phys_cursor_height
= glyph_row
->height
;
26157 /* Set phys_cursor_.* before x_draw_.* is called because some
26158 of them may need the information. */
26159 w
->phys_cursor
.x
= x
;
26160 w
->phys_cursor
.y
= glyph_row
->y
;
26161 w
->phys_cursor
.hpos
= hpos
;
26162 w
->phys_cursor
.vpos
= vpos
;
26165 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26166 new_cursor_type
, new_cursor_width
,
26167 on
, active_cursor
);
26171 /* Switch the display of W's cursor on or off, according to the value
26175 update_window_cursor (struct window
*w
, int on
)
26177 /* Don't update cursor in windows whose frame is in the process
26178 of being deleted. */
26179 if (w
->current_matrix
)
26181 int hpos
= w
->phys_cursor
.hpos
;
26182 int vpos
= w
->phys_cursor
.vpos
;
26183 struct glyph_row
*row
;
26185 if (vpos
>= w
->current_matrix
->nrows
26186 || hpos
>= w
->current_matrix
->matrix_w
)
26189 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26191 /* When the window is hscrolled, cursor hpos can legitimately be
26192 out of bounds, but we draw the cursor at the corresponding
26193 window margin in that case. */
26194 if (!row
->reversed_p
&& hpos
< 0)
26196 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26197 hpos
= row
->used
[TEXT_AREA
] - 1;
26200 display_and_set_cursor (w
, on
, hpos
, vpos
,
26201 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26207 /* Call update_window_cursor with parameter ON_P on all leaf windows
26208 in the window tree rooted at W. */
26211 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26215 if (!NILP (w
->hchild
))
26216 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
26217 else if (!NILP (w
->vchild
))
26218 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
26220 update_window_cursor (w
, on_p
);
26222 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26228 Display the cursor on window W, or clear it, according to ON_P.
26229 Don't change the cursor's position. */
26232 x_update_cursor (struct frame
*f
, int on_p
)
26234 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26239 Clear the cursor of window W to background color, and mark the
26240 cursor as not shown. This is used when the text where the cursor
26241 is about to be rewritten. */
26244 x_clear_cursor (struct window
*w
)
26246 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26247 update_window_cursor (w
, 0);
26250 #endif /* HAVE_WINDOW_SYSTEM */
26252 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26255 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26256 int start_hpos
, int end_hpos
,
26257 enum draw_glyphs_face draw
)
26259 #ifdef HAVE_WINDOW_SYSTEM
26260 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26262 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26266 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26267 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26271 /* Display the active region described by mouse_face_* according to DRAW. */
26274 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26276 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26277 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26279 if (/* If window is in the process of being destroyed, don't bother
26281 w
->current_matrix
!= NULL
26282 /* Don't update mouse highlight if hidden */
26283 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26284 /* Recognize when we are called to operate on rows that don't exist
26285 anymore. This can happen when a window is split. */
26286 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26288 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26289 struct glyph_row
*row
, *first
, *last
;
26291 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26292 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26294 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26296 int start_hpos
, end_hpos
, start_x
;
26298 /* For all but the first row, the highlight starts at column 0. */
26301 /* R2L rows have BEG and END in reversed order, but the
26302 screen drawing geometry is always left to right. So
26303 we need to mirror the beginning and end of the
26304 highlighted area in R2L rows. */
26305 if (!row
->reversed_p
)
26307 start_hpos
= hlinfo
->mouse_face_beg_col
;
26308 start_x
= hlinfo
->mouse_face_beg_x
;
26310 else if (row
== last
)
26312 start_hpos
= hlinfo
->mouse_face_end_col
;
26313 start_x
= hlinfo
->mouse_face_end_x
;
26321 else if (row
->reversed_p
&& row
== last
)
26323 start_hpos
= hlinfo
->mouse_face_end_col
;
26324 start_x
= hlinfo
->mouse_face_end_x
;
26334 if (!row
->reversed_p
)
26335 end_hpos
= hlinfo
->mouse_face_end_col
;
26336 else if (row
== first
)
26337 end_hpos
= hlinfo
->mouse_face_beg_col
;
26340 end_hpos
= row
->used
[TEXT_AREA
];
26341 if (draw
== DRAW_NORMAL_TEXT
)
26342 row
->fill_line_p
= 1; /* Clear to end of line */
26345 else if (row
->reversed_p
&& row
== first
)
26346 end_hpos
= hlinfo
->mouse_face_beg_col
;
26349 end_hpos
= row
->used
[TEXT_AREA
];
26350 if (draw
== DRAW_NORMAL_TEXT
)
26351 row
->fill_line_p
= 1; /* Clear to end of line */
26354 if (end_hpos
> start_hpos
)
26356 draw_row_with_mouse_face (w
, start_x
, row
,
26357 start_hpos
, end_hpos
, draw
);
26360 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26364 #ifdef HAVE_WINDOW_SYSTEM
26365 /* When we've written over the cursor, arrange for it to
26366 be displayed again. */
26367 if (FRAME_WINDOW_P (f
)
26368 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26370 int hpos
= w
->phys_cursor
.hpos
;
26372 /* When the window is hscrolled, cursor hpos can legitimately be
26373 out of bounds, but we draw the cursor at the corresponding
26374 window margin in that case. */
26375 if (!row
->reversed_p
&& hpos
< 0)
26377 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26378 hpos
= row
->used
[TEXT_AREA
] - 1;
26381 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26382 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26385 #endif /* HAVE_WINDOW_SYSTEM */
26388 #ifdef HAVE_WINDOW_SYSTEM
26389 /* Change the mouse cursor. */
26390 if (FRAME_WINDOW_P (f
))
26392 if (draw
== DRAW_NORMAL_TEXT
26393 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26394 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26395 else if (draw
== DRAW_MOUSE_FACE
)
26396 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26398 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26400 #endif /* HAVE_WINDOW_SYSTEM */
26404 Clear out the mouse-highlighted active region.
26405 Redraw it un-highlighted first. Value is non-zero if mouse
26406 face was actually drawn unhighlighted. */
26409 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26413 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26415 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26419 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26420 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26421 hlinfo
->mouse_face_window
= Qnil
;
26422 hlinfo
->mouse_face_overlay
= Qnil
;
26426 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26427 within the mouse face on that window. */
26429 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26431 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26433 /* Quickly resolve the easy cases. */
26434 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26435 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26437 if (vpos
< hlinfo
->mouse_face_beg_row
26438 || vpos
> hlinfo
->mouse_face_end_row
)
26440 if (vpos
> hlinfo
->mouse_face_beg_row
26441 && vpos
< hlinfo
->mouse_face_end_row
)
26444 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26446 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26448 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26451 else if ((vpos
== hlinfo
->mouse_face_beg_row
26452 && hpos
>= hlinfo
->mouse_face_beg_col
)
26453 || (vpos
== hlinfo
->mouse_face_end_row
26454 && hpos
< hlinfo
->mouse_face_end_col
))
26459 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26461 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26464 else if ((vpos
== hlinfo
->mouse_face_beg_row
26465 && hpos
<= hlinfo
->mouse_face_beg_col
)
26466 || (vpos
== hlinfo
->mouse_face_end_row
26467 && hpos
> hlinfo
->mouse_face_end_col
))
26475 Non-zero if physical cursor of window W is within mouse face. */
26478 cursor_in_mouse_face_p (struct window
*w
)
26480 int hpos
= w
->phys_cursor
.hpos
;
26481 int vpos
= w
->phys_cursor
.vpos
;
26482 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26484 /* When the window is hscrolled, cursor hpos can legitimately be out
26485 of bounds, but we draw the cursor at the corresponding window
26486 margin in that case. */
26487 if (!row
->reversed_p
&& hpos
< 0)
26489 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26490 hpos
= row
->used
[TEXT_AREA
] - 1;
26492 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26497 /* Find the glyph rows START_ROW and END_ROW of window W that display
26498 characters between buffer positions START_CHARPOS and END_CHARPOS
26499 (excluding END_CHARPOS). DISP_STRING is a display string that
26500 covers these buffer positions. This is similar to
26501 row_containing_pos, but is more accurate when bidi reordering makes
26502 buffer positions change non-linearly with glyph rows. */
26504 rows_from_pos_range (struct window
*w
,
26505 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26506 Lisp_Object disp_string
,
26507 struct glyph_row
**start
, struct glyph_row
**end
)
26509 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26510 int last_y
= window_text_bottom_y (w
);
26511 struct glyph_row
*row
;
26516 while (!first
->enabled_p
26517 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26520 /* Find the START row. */
26522 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26525 /* A row can potentially be the START row if the range of the
26526 characters it displays intersects the range
26527 [START_CHARPOS..END_CHARPOS). */
26528 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26529 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26530 /* See the commentary in row_containing_pos, for the
26531 explanation of the complicated way to check whether
26532 some position is beyond the end of the characters
26533 displayed by a row. */
26534 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26535 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26536 && !row
->ends_at_zv_p
26537 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26538 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26539 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26540 && !row
->ends_at_zv_p
26541 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26543 /* Found a candidate row. Now make sure at least one of the
26544 glyphs it displays has a charpos from the range
26545 [START_CHARPOS..END_CHARPOS).
26547 This is not obvious because bidi reordering could make
26548 buffer positions of a row be 1,2,3,102,101,100, and if we
26549 want to highlight characters in [50..60), we don't want
26550 this row, even though [50..60) does intersect [1..103),
26551 the range of character positions given by the row's start
26552 and end positions. */
26553 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26554 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26558 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26559 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26560 /* A glyph that comes from DISP_STRING is by
26561 definition to be highlighted. */
26562 || EQ (g
->object
, disp_string
))
26571 /* Find the END row. */
26573 /* If the last row is partially visible, start looking for END
26574 from that row, instead of starting from FIRST. */
26575 && !(row
->enabled_p
26576 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26578 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26580 struct glyph_row
*next
= row
+ 1;
26581 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26583 if (!next
->enabled_p
26584 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26585 /* The first row >= START whose range of displayed characters
26586 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26587 is the row END + 1. */
26588 || (start_charpos
< next_start
26589 && end_charpos
< next_start
)
26590 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26591 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26592 && !next
->ends_at_zv_p
26593 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26594 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26595 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26596 && !next
->ends_at_zv_p
26597 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26604 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26605 but none of the characters it displays are in the range, it is
26607 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26608 struct glyph
*s
= g
;
26609 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26613 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26614 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26615 /* If the buffer position of the first glyph in
26616 the row is equal to END_CHARPOS, it means
26617 the last character to be highlighted is the
26618 newline of ROW, and we must consider NEXT as
26620 || (((!next
->reversed_p
&& g
== s
)
26621 || (next
->reversed_p
&& g
== e
- 1))
26622 && (g
->charpos
== end_charpos
26623 /* Special case for when NEXT is an
26624 empty line at ZV. */
26625 || (g
->charpos
== -1
26626 && !row
->ends_at_zv_p
26627 && next_start
== end_charpos
)))))
26628 /* A glyph that comes from DISP_STRING is by
26629 definition to be highlighted. */
26630 || EQ (g
->object
, disp_string
))
26639 /* The first row that ends at ZV must be the last to be
26641 else if (next
->ends_at_zv_p
)
26650 /* This function sets the mouse_face_* elements of HLINFO, assuming
26651 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26652 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26653 for the overlay or run of text properties specifying the mouse
26654 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26655 before-string and after-string that must also be highlighted.
26656 DISP_STRING, if non-nil, is a display string that may cover some
26657 or all of the highlighted text. */
26660 mouse_face_from_buffer_pos (Lisp_Object window
,
26661 Mouse_HLInfo
*hlinfo
,
26662 ptrdiff_t mouse_charpos
,
26663 ptrdiff_t start_charpos
,
26664 ptrdiff_t end_charpos
,
26665 Lisp_Object before_string
,
26666 Lisp_Object after_string
,
26667 Lisp_Object disp_string
)
26669 struct window
*w
= XWINDOW (window
);
26670 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26671 struct glyph_row
*r1
, *r2
;
26672 struct glyph
*glyph
, *end
;
26673 ptrdiff_t ignore
, pos
;
26676 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26677 eassert (NILP (before_string
) || STRINGP (before_string
));
26678 eassert (NILP (after_string
) || STRINGP (after_string
));
26680 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26681 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26683 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26684 /* If the before-string or display-string contains newlines,
26685 rows_from_pos_range skips to its last row. Move back. */
26686 if (!NILP (before_string
) || !NILP (disp_string
))
26688 struct glyph_row
*prev
;
26689 while ((prev
= r1
- 1, prev
>= first
)
26690 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26691 && prev
->used
[TEXT_AREA
] > 0)
26693 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26694 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26695 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26697 || !(EQ (glyph
->object
, before_string
)
26698 || EQ (glyph
->object
, disp_string
)))
26705 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26706 hlinfo
->mouse_face_past_end
= 1;
26708 else if (!NILP (after_string
))
26710 /* If the after-string has newlines, advance to its last row. */
26711 struct glyph_row
*next
;
26712 struct glyph_row
*last
26713 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26715 for (next
= r2
+ 1;
26717 && next
->used
[TEXT_AREA
] > 0
26718 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26722 /* The rest of the display engine assumes that mouse_face_beg_row is
26723 either above mouse_face_end_row or identical to it. But with
26724 bidi-reordered continued lines, the row for START_CHARPOS could
26725 be below the row for END_CHARPOS. If so, swap the rows and store
26726 them in correct order. */
26729 struct glyph_row
*tem
= r2
;
26735 hlinfo
->mouse_face_beg_y
= r1
->y
;
26736 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26737 hlinfo
->mouse_face_end_y
= r2
->y
;
26738 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26740 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26741 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26742 could be anywhere in the row and in any order. The strategy
26743 below is to find the leftmost and the rightmost glyph that
26744 belongs to either of these 3 strings, or whose position is
26745 between START_CHARPOS and END_CHARPOS, and highlight all the
26746 glyphs between those two. This may cover more than just the text
26747 between START_CHARPOS and END_CHARPOS if the range of characters
26748 strides the bidi level boundary, e.g. if the beginning is in R2L
26749 text while the end is in L2R text or vice versa. */
26750 if (!r1
->reversed_p
)
26752 /* This row is in a left to right paragraph. Scan it left to
26754 glyph
= r1
->glyphs
[TEXT_AREA
];
26755 end
= glyph
+ r1
->used
[TEXT_AREA
];
26758 /* Skip truncation glyphs at the start of the glyph row. */
26759 if (r1
->displays_text_p
)
26761 && INTEGERP (glyph
->object
)
26762 && glyph
->charpos
< 0;
26764 x
+= glyph
->pixel_width
;
26766 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26767 or DISP_STRING, and the first glyph from buffer whose
26768 position is between START_CHARPOS and END_CHARPOS. */
26770 && !INTEGERP (glyph
->object
)
26771 && !EQ (glyph
->object
, disp_string
)
26772 && !(BUFFERP (glyph
->object
)
26773 && (glyph
->charpos
>= start_charpos
26774 && glyph
->charpos
< end_charpos
));
26777 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26778 are present at buffer positions between START_CHARPOS and
26779 END_CHARPOS, or if they come from an overlay. */
26780 if (EQ (glyph
->object
, before_string
))
26782 pos
= string_buffer_position (before_string
,
26784 /* If pos == 0, it means before_string came from an
26785 overlay, not from a buffer position. */
26786 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26789 else if (EQ (glyph
->object
, after_string
))
26791 pos
= string_buffer_position (after_string
, end_charpos
);
26792 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26795 x
+= glyph
->pixel_width
;
26797 hlinfo
->mouse_face_beg_x
= x
;
26798 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26802 /* This row is in a right to left paragraph. Scan it right to
26806 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26807 glyph
= end
+ r1
->used
[TEXT_AREA
];
26809 /* Skip truncation glyphs at the start of the glyph row. */
26810 if (r1
->displays_text_p
)
26812 && INTEGERP (glyph
->object
)
26813 && glyph
->charpos
< 0;
26817 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26818 or DISP_STRING, and the first glyph from buffer whose
26819 position is between START_CHARPOS and END_CHARPOS. */
26821 && !INTEGERP (glyph
->object
)
26822 && !EQ (glyph
->object
, disp_string
)
26823 && !(BUFFERP (glyph
->object
)
26824 && (glyph
->charpos
>= start_charpos
26825 && glyph
->charpos
< end_charpos
));
26828 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26829 are present at buffer positions between START_CHARPOS and
26830 END_CHARPOS, or if they come from an overlay. */
26831 if (EQ (glyph
->object
, before_string
))
26833 pos
= string_buffer_position (before_string
, start_charpos
);
26834 /* If pos == 0, it means before_string came from an
26835 overlay, not from a buffer position. */
26836 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26839 else if (EQ (glyph
->object
, after_string
))
26841 pos
= string_buffer_position (after_string
, end_charpos
);
26842 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26847 glyph
++; /* first glyph to the right of the highlighted area */
26848 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26849 x
+= g
->pixel_width
;
26850 hlinfo
->mouse_face_beg_x
= x
;
26851 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26854 /* If the highlight ends in a different row, compute GLYPH and END
26855 for the end row. Otherwise, reuse the values computed above for
26856 the row where the highlight begins. */
26859 if (!r2
->reversed_p
)
26861 glyph
= r2
->glyphs
[TEXT_AREA
];
26862 end
= glyph
+ r2
->used
[TEXT_AREA
];
26867 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26868 glyph
= end
+ r2
->used
[TEXT_AREA
];
26872 if (!r2
->reversed_p
)
26874 /* Skip truncation and continuation glyphs near the end of the
26875 row, and also blanks and stretch glyphs inserted by
26876 extend_face_to_end_of_line. */
26878 && INTEGERP ((end
- 1)->object
))
26880 /* Scan the rest of the glyph row from the end, looking for the
26881 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26882 DISP_STRING, or whose position is between START_CHARPOS
26886 && !INTEGERP (end
->object
)
26887 && !EQ (end
->object
, disp_string
)
26888 && !(BUFFERP (end
->object
)
26889 && (end
->charpos
>= start_charpos
26890 && end
->charpos
< end_charpos
));
26893 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26894 are present at buffer positions between START_CHARPOS and
26895 END_CHARPOS, or if they come from an overlay. */
26896 if (EQ (end
->object
, before_string
))
26898 pos
= string_buffer_position (before_string
, start_charpos
);
26899 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26902 else if (EQ (end
->object
, after_string
))
26904 pos
= string_buffer_position (after_string
, end_charpos
);
26905 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26909 /* Find the X coordinate of the last glyph to be highlighted. */
26910 for (; glyph
<= end
; ++glyph
)
26911 x
+= glyph
->pixel_width
;
26913 hlinfo
->mouse_face_end_x
= x
;
26914 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26918 /* Skip truncation and continuation glyphs near the end of the
26919 row, and also blanks and stretch glyphs inserted by
26920 extend_face_to_end_of_line. */
26924 && INTEGERP (end
->object
))
26926 x
+= end
->pixel_width
;
26929 /* Scan the rest of the glyph row from the end, looking for the
26930 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26931 DISP_STRING, or whose position is between START_CHARPOS
26935 && !INTEGERP (end
->object
)
26936 && !EQ (end
->object
, disp_string
)
26937 && !(BUFFERP (end
->object
)
26938 && (end
->charpos
>= start_charpos
26939 && end
->charpos
< end_charpos
));
26942 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26943 are present at buffer positions between START_CHARPOS and
26944 END_CHARPOS, or if they come from an overlay. */
26945 if (EQ (end
->object
, before_string
))
26947 pos
= string_buffer_position (before_string
, start_charpos
);
26948 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26951 else if (EQ (end
->object
, after_string
))
26953 pos
= string_buffer_position (after_string
, end_charpos
);
26954 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26957 x
+= end
->pixel_width
;
26959 /* If we exited the above loop because we arrived at the last
26960 glyph of the row, and its buffer position is still not in
26961 range, it means the last character in range is the preceding
26962 newline. Bump the end column and x values to get past the
26965 && BUFFERP (end
->object
)
26966 && (end
->charpos
< start_charpos
26967 || end
->charpos
>= end_charpos
))
26969 x
+= end
->pixel_width
;
26972 hlinfo
->mouse_face_end_x
= x
;
26973 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
26976 hlinfo
->mouse_face_window
= window
;
26977 hlinfo
->mouse_face_face_id
26978 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
26980 !hlinfo
->mouse_face_hidden
, -1);
26981 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
26984 /* The following function is not used anymore (replaced with
26985 mouse_face_from_string_pos), but I leave it here for the time
26986 being, in case someone would. */
26988 #if 0 /* not used */
26990 /* Find the position of the glyph for position POS in OBJECT in
26991 window W's current matrix, and return in *X, *Y the pixel
26992 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
26994 RIGHT_P non-zero means return the position of the right edge of the
26995 glyph, RIGHT_P zero means return the left edge position.
26997 If no glyph for POS exists in the matrix, return the position of
26998 the glyph with the next smaller position that is in the matrix, if
26999 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27000 exists in the matrix, return the position of the glyph with the
27001 next larger position in OBJECT.
27003 Value is non-zero if a glyph was found. */
27006 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27007 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27009 int yb
= window_text_bottom_y (w
);
27010 struct glyph_row
*r
;
27011 struct glyph
*best_glyph
= NULL
;
27012 struct glyph_row
*best_row
= NULL
;
27015 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27016 r
->enabled_p
&& r
->y
< yb
;
27019 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27020 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27023 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27024 if (EQ (g
->object
, object
))
27026 if (g
->charpos
== pos
)
27033 else if (best_glyph
== NULL
27034 || ((eabs (g
->charpos
- pos
)
27035 < eabs (best_glyph
->charpos
- pos
))
27038 : g
->charpos
> pos
)))
27052 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27056 *x
+= best_glyph
->pixel_width
;
27061 *vpos
= best_row
- w
->current_matrix
->rows
;
27064 return best_glyph
!= NULL
;
27066 #endif /* not used */
27068 /* Find the positions of the first and the last glyphs in window W's
27069 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27070 (assumed to be a string), and return in HLINFO's mouse_face_*
27071 members the pixel and column/row coordinates of those glyphs. */
27074 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27075 Lisp_Object object
,
27076 ptrdiff_t startpos
, ptrdiff_t endpos
)
27078 int yb
= window_text_bottom_y (w
);
27079 struct glyph_row
*r
;
27080 struct glyph
*g
, *e
;
27084 /* Find the glyph row with at least one position in the range
27085 [STARTPOS..ENDPOS], and the first glyph in that row whose
27086 position belongs to that range. */
27087 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27088 r
->enabled_p
&& r
->y
< yb
;
27091 if (!r
->reversed_p
)
27093 g
= r
->glyphs
[TEXT_AREA
];
27094 e
= g
+ r
->used
[TEXT_AREA
];
27095 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27096 if (EQ (g
->object
, object
)
27097 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27099 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27100 hlinfo
->mouse_face_beg_y
= r
->y
;
27101 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27102 hlinfo
->mouse_face_beg_x
= gx
;
27111 e
= r
->glyphs
[TEXT_AREA
];
27112 g
= e
+ r
->used
[TEXT_AREA
];
27113 for ( ; g
> e
; --g
)
27114 if (EQ ((g
-1)->object
, object
)
27115 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27117 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27118 hlinfo
->mouse_face_beg_y
= r
->y
;
27119 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27120 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27121 gx
+= g1
->pixel_width
;
27122 hlinfo
->mouse_face_beg_x
= gx
;
27134 /* Starting with the next row, look for the first row which does NOT
27135 include any glyphs whose positions are in the range. */
27136 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27138 g
= r
->glyphs
[TEXT_AREA
];
27139 e
= g
+ r
->used
[TEXT_AREA
];
27141 for ( ; g
< e
; ++g
)
27142 if (EQ (g
->object
, object
)
27143 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27152 /* The highlighted region ends on the previous row. */
27155 /* Set the end row and its vertical pixel coordinate. */
27156 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
27157 hlinfo
->mouse_face_end_y
= r
->y
;
27159 /* Compute and set the end column and the end column's horizontal
27160 pixel coordinate. */
27161 if (!r
->reversed_p
)
27163 g
= r
->glyphs
[TEXT_AREA
];
27164 e
= g
+ r
->used
[TEXT_AREA
];
27165 for ( ; e
> g
; --e
)
27166 if (EQ ((e
-1)->object
, object
)
27167 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27169 hlinfo
->mouse_face_end_col
= e
- g
;
27171 for (gx
= r
->x
; g
< e
; ++g
)
27172 gx
+= g
->pixel_width
;
27173 hlinfo
->mouse_face_end_x
= gx
;
27177 e
= r
->glyphs
[TEXT_AREA
];
27178 g
= e
+ r
->used
[TEXT_AREA
];
27179 for (gx
= r
->x
; e
< g
; ++e
)
27181 if (EQ (e
->object
, object
)
27182 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27184 gx
+= e
->pixel_width
;
27186 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27187 hlinfo
->mouse_face_end_x
= gx
;
27191 #ifdef HAVE_WINDOW_SYSTEM
27193 /* See if position X, Y is within a hot-spot of an image. */
27196 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27198 if (!CONSP (hot_spot
))
27201 if (EQ (XCAR (hot_spot
), Qrect
))
27203 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27204 Lisp_Object rect
= XCDR (hot_spot
);
27208 if (!CONSP (XCAR (rect
)))
27210 if (!CONSP (XCDR (rect
)))
27212 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27214 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27216 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27218 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27222 else if (EQ (XCAR (hot_spot
), Qcircle
))
27224 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27225 Lisp_Object circ
= XCDR (hot_spot
);
27226 Lisp_Object lr
, lx0
, ly0
;
27228 && CONSP (XCAR (circ
))
27229 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27230 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27231 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27233 double r
= XFLOATINT (lr
);
27234 double dx
= XINT (lx0
) - x
;
27235 double dy
= XINT (ly0
) - y
;
27236 return (dx
* dx
+ dy
* dy
<= r
* r
);
27239 else if (EQ (XCAR (hot_spot
), Qpoly
))
27241 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27242 if (VECTORP (XCDR (hot_spot
)))
27244 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27245 Lisp_Object
*poly
= v
->contents
;
27246 ptrdiff_t n
= v
->header
.size
;
27249 Lisp_Object lx
, ly
;
27252 /* Need an even number of coordinates, and at least 3 edges. */
27253 if (n
< 6 || n
& 1)
27256 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27257 If count is odd, we are inside polygon. Pixels on edges
27258 may or may not be included depending on actual geometry of the
27260 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27261 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27263 x0
= XINT (lx
), y0
= XINT (ly
);
27264 for (i
= 0; i
< n
; i
+= 2)
27266 int x1
= x0
, y1
= y0
;
27267 if ((lx
= poly
[i
], !INTEGERP (lx
))
27268 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27270 x0
= XINT (lx
), y0
= XINT (ly
);
27272 /* Does this segment cross the X line? */
27280 if (y
> y0
&& y
> y1
)
27282 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27292 find_hot_spot (Lisp_Object map
, int x
, int y
)
27294 while (CONSP (map
))
27296 if (CONSP (XCAR (map
))
27297 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27305 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27307 doc
: /* Lookup in image map MAP coordinates X and Y.
27308 An image map is an alist where each element has the format (AREA ID PLIST).
27309 An AREA is specified as either a rectangle, a circle, or a polygon:
27310 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27311 pixel coordinates of the upper left and bottom right corners.
27312 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27313 and the radius of the circle; r may be a float or integer.
27314 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27315 vector describes one corner in the polygon.
27316 Returns the alist element for the first matching AREA in MAP. */)
27317 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27325 return find_hot_spot (map
,
27326 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27327 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27331 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27333 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27335 /* Do not change cursor shape while dragging mouse. */
27336 if (!NILP (do_mouse_tracking
))
27339 if (!NILP (pointer
))
27341 if (EQ (pointer
, Qarrow
))
27342 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27343 else if (EQ (pointer
, Qhand
))
27344 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27345 else if (EQ (pointer
, Qtext
))
27346 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27347 else if (EQ (pointer
, intern ("hdrag")))
27348 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27349 #ifdef HAVE_X_WINDOWS
27350 else if (EQ (pointer
, intern ("vdrag")))
27351 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27353 else if (EQ (pointer
, intern ("hourglass")))
27354 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27355 else if (EQ (pointer
, Qmodeline
))
27356 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27358 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27361 if (cursor
!= No_Cursor
)
27362 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27365 #endif /* HAVE_WINDOW_SYSTEM */
27367 /* Take proper action when mouse has moved to the mode or header line
27368 or marginal area AREA of window W, x-position X and y-position Y.
27369 X is relative to the start of the text display area of W, so the
27370 width of bitmap areas and scroll bars must be subtracted to get a
27371 position relative to the start of the mode line. */
27374 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27375 enum window_part area
)
27377 struct window
*w
= XWINDOW (window
);
27378 struct frame
*f
= XFRAME (w
->frame
);
27379 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27380 #ifdef HAVE_WINDOW_SYSTEM
27381 Display_Info
*dpyinfo
;
27383 Cursor cursor
= No_Cursor
;
27384 Lisp_Object pointer
= Qnil
;
27385 int dx
, dy
, width
, height
;
27387 Lisp_Object string
, object
= Qnil
;
27388 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27390 Lisp_Object mouse_face
;
27391 int original_x_pixel
= x
;
27392 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27393 struct glyph_row
*row
IF_LINT (= 0);
27395 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27400 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27401 returns them in row/column units! */
27402 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27403 &object
, &dx
, &dy
, &width
, &height
);
27405 row
= (area
== ON_MODE_LINE
27406 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27407 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27409 /* Find the glyph under the mouse pointer. */
27410 if (row
->mode_line_p
&& row
->enabled_p
)
27412 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27413 end
= glyph
+ row
->used
[TEXT_AREA
];
27415 for (x0
= original_x_pixel
;
27416 glyph
< end
&& x0
>= glyph
->pixel_width
;
27418 x0
-= glyph
->pixel_width
;
27426 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27427 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27428 returns them in row/column units! */
27429 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27430 &object
, &dx
, &dy
, &width
, &height
);
27435 #ifdef HAVE_WINDOW_SYSTEM
27436 if (IMAGEP (object
))
27438 Lisp_Object image_map
, hotspot
;
27439 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27441 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27443 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27447 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27448 If so, we could look for mouse-enter, mouse-leave
27449 properties in PLIST (and do something...). */
27450 hotspot
= XCDR (hotspot
);
27451 if (CONSP (hotspot
)
27452 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27454 pointer
= Fplist_get (plist
, Qpointer
);
27455 if (NILP (pointer
))
27457 help
= Fplist_get (plist
, Qhelp_echo
);
27460 help_echo_string
= help
;
27461 XSETWINDOW (help_echo_window
, w
);
27462 help_echo_object
= w
->buffer
;
27463 help_echo_pos
= charpos
;
27467 if (NILP (pointer
))
27468 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27470 #endif /* HAVE_WINDOW_SYSTEM */
27472 if (STRINGP (string
))
27473 pos
= make_number (charpos
);
27475 /* Set the help text and mouse pointer. If the mouse is on a part
27476 of the mode line without any text (e.g. past the right edge of
27477 the mode line text), use the default help text and pointer. */
27478 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27480 /* Arrange to display the help by setting the global variables
27481 help_echo_string, help_echo_object, and help_echo_pos. */
27484 if (STRINGP (string
))
27485 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27489 help_echo_string
= help
;
27490 XSETWINDOW (help_echo_window
, w
);
27491 help_echo_object
= string
;
27492 help_echo_pos
= charpos
;
27494 else if (area
== ON_MODE_LINE
)
27496 Lisp_Object default_help
27497 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27500 if (STRINGP (default_help
))
27502 help_echo_string
= default_help
;
27503 XSETWINDOW (help_echo_window
, w
);
27504 help_echo_object
= Qnil
;
27505 help_echo_pos
= -1;
27510 #ifdef HAVE_WINDOW_SYSTEM
27511 /* Change the mouse pointer according to what is under it. */
27512 if (FRAME_WINDOW_P (f
))
27514 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27515 if (STRINGP (string
))
27517 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27519 if (NILP (pointer
))
27520 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27522 /* Change the mouse pointer according to what is under X/Y. */
27524 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27527 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27528 if (!KEYMAPP (map
))
27529 map
= Fget_text_property (pos
, Qkeymap
, string
);
27530 if (!KEYMAPP (map
))
27531 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27535 /* Default mode-line pointer. */
27536 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27541 /* Change the mouse face according to what is under X/Y. */
27542 if (STRINGP (string
))
27544 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27545 if (!NILP (mouse_face
)
27546 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27551 struct glyph
* tmp_glyph
;
27555 int total_pixel_width
;
27556 ptrdiff_t begpos
, endpos
, ignore
;
27560 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27561 Qmouse_face
, string
, Qnil
);
27567 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27569 endpos
= SCHARS (string
);
27573 /* Calculate the glyph position GPOS of GLYPH in the
27574 displayed string, relative to the beginning of the
27575 highlighted part of the string.
27577 Note: GPOS is different from CHARPOS. CHARPOS is the
27578 position of GLYPH in the internal string object. A mode
27579 line string format has structures which are converted to
27580 a flattened string by the Emacs Lisp interpreter. The
27581 internal string is an element of those structures. The
27582 displayed string is the flattened string. */
27583 tmp_glyph
= row_start_glyph
;
27584 while (tmp_glyph
< glyph
27585 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27586 && begpos
<= tmp_glyph
->charpos
27587 && tmp_glyph
->charpos
< endpos
)))
27589 gpos
= glyph
- tmp_glyph
;
27591 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27592 the highlighted part of the displayed string to which
27593 GLYPH belongs. Note: GSEQ_LENGTH is different from
27594 SCHARS (STRING), because the latter returns the length of
27595 the internal string. */
27596 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27598 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27599 && begpos
<= tmp_glyph
->charpos
27600 && tmp_glyph
->charpos
< endpos
));
27603 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27605 /* Calculate the total pixel width of all the glyphs between
27606 the beginning of the highlighted area and GLYPH. */
27607 total_pixel_width
= 0;
27608 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27609 total_pixel_width
+= tmp_glyph
->pixel_width
;
27611 /* Pre calculation of re-rendering position. Note: X is in
27612 column units here, after the call to mode_line_string or
27613 marginal_area_string. */
27615 vpos
= (area
== ON_MODE_LINE
27616 ? (w
->current_matrix
)->nrows
- 1
27619 /* If GLYPH's position is included in the region that is
27620 already drawn in mouse face, we have nothing to do. */
27621 if ( EQ (window
, hlinfo
->mouse_face_window
)
27622 && (!row
->reversed_p
27623 ? (hlinfo
->mouse_face_beg_col
<= hpos
27624 && hpos
< hlinfo
->mouse_face_end_col
)
27625 /* In R2L rows we swap BEG and END, see below. */
27626 : (hlinfo
->mouse_face_end_col
<= hpos
27627 && hpos
< hlinfo
->mouse_face_beg_col
))
27628 && hlinfo
->mouse_face_beg_row
== vpos
)
27631 if (clear_mouse_face (hlinfo
))
27632 cursor
= No_Cursor
;
27634 if (!row
->reversed_p
)
27636 hlinfo
->mouse_face_beg_col
= hpos
;
27637 hlinfo
->mouse_face_beg_x
= original_x_pixel
27638 - (total_pixel_width
+ dx
);
27639 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27640 hlinfo
->mouse_face_end_x
= 0;
27644 /* In R2L rows, show_mouse_face expects BEG and END
27645 coordinates to be swapped. */
27646 hlinfo
->mouse_face_end_col
= hpos
;
27647 hlinfo
->mouse_face_end_x
= original_x_pixel
27648 - (total_pixel_width
+ dx
);
27649 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27650 hlinfo
->mouse_face_beg_x
= 0;
27653 hlinfo
->mouse_face_beg_row
= vpos
;
27654 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27655 hlinfo
->mouse_face_beg_y
= 0;
27656 hlinfo
->mouse_face_end_y
= 0;
27657 hlinfo
->mouse_face_past_end
= 0;
27658 hlinfo
->mouse_face_window
= window
;
27660 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27666 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27668 if (NILP (pointer
))
27671 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27672 clear_mouse_face (hlinfo
);
27674 #ifdef HAVE_WINDOW_SYSTEM
27675 if (FRAME_WINDOW_P (f
))
27676 define_frame_cursor1 (f
, cursor
, pointer
);
27682 Take proper action when the mouse has moved to position X, Y on
27683 frame F as regards highlighting characters that have mouse-face
27684 properties. Also de-highlighting chars where the mouse was before.
27685 X and Y can be negative or out of range. */
27688 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27690 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27691 enum window_part part
= ON_NOTHING
;
27692 Lisp_Object window
;
27694 Cursor cursor
= No_Cursor
;
27695 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27698 /* When a menu is active, don't highlight because this looks odd. */
27699 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27700 if (popup_activated ())
27704 if (NILP (Vmouse_highlight
)
27705 || !f
->glyphs_initialized_p
27706 || f
->pointer_invisible
)
27709 hlinfo
->mouse_face_mouse_x
= x
;
27710 hlinfo
->mouse_face_mouse_y
= y
;
27711 hlinfo
->mouse_face_mouse_frame
= f
;
27713 if (hlinfo
->mouse_face_defer
)
27716 /* Which window is that in? */
27717 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27719 /* If displaying active text in another window, clear that. */
27720 if (! EQ (window
, hlinfo
->mouse_face_window
)
27721 /* Also clear if we move out of text area in same window. */
27722 || (!NILP (hlinfo
->mouse_face_window
)
27725 && part
!= ON_MODE_LINE
27726 && part
!= ON_HEADER_LINE
))
27727 clear_mouse_face (hlinfo
);
27729 /* Not on a window -> return. */
27730 if (!WINDOWP (window
))
27733 /* Reset help_echo_string. It will get recomputed below. */
27734 help_echo_string
= Qnil
;
27736 /* Convert to window-relative pixel coordinates. */
27737 w
= XWINDOW (window
);
27738 frame_to_window_pixel_xy (w
, &x
, &y
);
27740 #ifdef HAVE_WINDOW_SYSTEM
27741 /* Handle tool-bar window differently since it doesn't display a
27743 if (EQ (window
, f
->tool_bar_window
))
27745 note_tool_bar_highlight (f
, x
, y
);
27750 /* Mouse is on the mode, header line or margin? */
27751 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27752 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27754 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27758 #ifdef HAVE_WINDOW_SYSTEM
27759 if (part
== ON_VERTICAL_BORDER
)
27761 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27762 help_echo_string
= build_string ("drag-mouse-1: resize");
27764 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27765 || part
== ON_SCROLL_BAR
)
27766 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27768 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27771 /* Are we in a window whose display is up to date?
27772 And verify the buffer's text has not changed. */
27773 b
= XBUFFER (w
->buffer
);
27774 if (part
== ON_TEXT
27775 && EQ (w
->window_end_valid
, w
->buffer
)
27776 && w
->last_modified
== BUF_MODIFF (b
)
27777 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27779 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27781 struct glyph
*glyph
;
27782 Lisp_Object object
;
27783 Lisp_Object mouse_face
= Qnil
, position
;
27784 Lisp_Object
*overlay_vec
= NULL
;
27785 ptrdiff_t i
, noverlays
;
27786 struct buffer
*obuf
;
27787 ptrdiff_t obegv
, ozv
;
27790 /* Find the glyph under X/Y. */
27791 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27793 #ifdef HAVE_WINDOW_SYSTEM
27794 /* Look for :pointer property on image. */
27795 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27797 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27798 if (img
!= NULL
&& IMAGEP (img
->spec
))
27800 Lisp_Object image_map
, hotspot
;
27801 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27803 && (hotspot
= find_hot_spot (image_map
,
27804 glyph
->slice
.img
.x
+ dx
,
27805 glyph
->slice
.img
.y
+ dy
),
27807 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27811 /* Could check XCAR (hotspot) to see if we enter/leave
27813 If so, we could look for mouse-enter, mouse-leave
27814 properties in PLIST (and do something...). */
27815 hotspot
= XCDR (hotspot
);
27816 if (CONSP (hotspot
)
27817 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27819 pointer
= Fplist_get (plist
, Qpointer
);
27820 if (NILP (pointer
))
27822 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27823 if (!NILP (help_echo_string
))
27825 help_echo_window
= window
;
27826 help_echo_object
= glyph
->object
;
27827 help_echo_pos
= glyph
->charpos
;
27831 if (NILP (pointer
))
27832 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27835 #endif /* HAVE_WINDOW_SYSTEM */
27837 /* Clear mouse face if X/Y not over text. */
27839 || area
!= TEXT_AREA
27840 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27841 /* Glyph's OBJECT is an integer for glyphs inserted by the
27842 display engine for its internal purposes, like truncation
27843 and continuation glyphs and blanks beyond the end of
27844 line's text on text terminals. If we are over such a
27845 glyph, we are not over any text. */
27846 || INTEGERP (glyph
->object
)
27847 /* R2L rows have a stretch glyph at their front, which
27848 stands for no text, whereas L2R rows have no glyphs at
27849 all beyond the end of text. Treat such stretch glyphs
27850 like we do with NULL glyphs in L2R rows. */
27851 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27852 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27853 && glyph
->type
== STRETCH_GLYPH
27854 && glyph
->avoid_cursor_p
))
27856 if (clear_mouse_face (hlinfo
))
27857 cursor
= No_Cursor
;
27858 #ifdef HAVE_WINDOW_SYSTEM
27859 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27861 if (area
!= TEXT_AREA
)
27862 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27864 pointer
= Vvoid_text_area_pointer
;
27870 pos
= glyph
->charpos
;
27871 object
= glyph
->object
;
27872 if (!STRINGP (object
) && !BUFFERP (object
))
27875 /* If we get an out-of-range value, return now; avoid an error. */
27876 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27879 /* Make the window's buffer temporarily current for
27880 overlays_at and compute_char_face. */
27881 obuf
= current_buffer
;
27882 current_buffer
= b
;
27888 /* Is this char mouse-active or does it have help-echo? */
27889 position
= make_number (pos
);
27891 if (BUFFERP (object
))
27893 /* Put all the overlays we want in a vector in overlay_vec. */
27894 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27895 /* Sort overlays into increasing priority order. */
27896 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27901 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27904 cursor
= No_Cursor
;
27906 /* Check mouse-face highlighting. */
27908 /* If there exists an overlay with mouse-face overlapping
27909 the one we are currently highlighting, we have to
27910 check if we enter the overlapping overlay, and then
27911 highlight only that. */
27912 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27913 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27915 /* Find the highest priority overlay with a mouse-face. */
27916 Lisp_Object overlay
= Qnil
;
27917 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27919 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27920 if (!NILP (mouse_face
))
27921 overlay
= overlay_vec
[i
];
27924 /* If we're highlighting the same overlay as before, there's
27925 no need to do that again. */
27926 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27927 goto check_help_echo
;
27928 hlinfo
->mouse_face_overlay
= overlay
;
27930 /* Clear the display of the old active region, if any. */
27931 if (clear_mouse_face (hlinfo
))
27932 cursor
= No_Cursor
;
27934 /* If no overlay applies, get a text property. */
27935 if (NILP (overlay
))
27936 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27938 /* Next, compute the bounds of the mouse highlighting and
27940 if (!NILP (mouse_face
) && STRINGP (object
))
27942 /* The mouse-highlighting comes from a display string
27943 with a mouse-face. */
27947 s
= Fprevious_single_property_change
27948 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27949 e
= Fnext_single_property_change
27950 (position
, Qmouse_face
, object
, Qnil
);
27952 s
= make_number (0);
27954 e
= make_number (SCHARS (object
) - 1);
27955 mouse_face_from_string_pos (w
, hlinfo
, object
,
27956 XINT (s
), XINT (e
));
27957 hlinfo
->mouse_face_past_end
= 0;
27958 hlinfo
->mouse_face_window
= window
;
27959 hlinfo
->mouse_face_face_id
27960 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
27961 glyph
->face_id
, 1);
27962 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27963 cursor
= No_Cursor
;
27967 /* The mouse-highlighting, if any, comes from an overlay
27968 or text property in the buffer. */
27969 Lisp_Object buffer
IF_LINT (= Qnil
);
27970 Lisp_Object disp_string
IF_LINT (= Qnil
);
27972 if (STRINGP (object
))
27974 /* If we are on a display string with no mouse-face,
27975 check if the text under it has one. */
27976 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
27977 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
27978 pos
= string_buffer_position (object
, start
);
27981 mouse_face
= get_char_property_and_overlay
27982 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
27983 buffer
= w
->buffer
;
27984 disp_string
= object
;
27990 disp_string
= Qnil
;
27993 if (!NILP (mouse_face
))
27995 Lisp_Object before
, after
;
27996 Lisp_Object before_string
, after_string
;
27997 /* To correctly find the limits of mouse highlight
27998 in a bidi-reordered buffer, we must not use the
27999 optimization of limiting the search in
28000 previous-single-property-change and
28001 next-single-property-change, because
28002 rows_from_pos_range needs the real start and end
28003 positions to DTRT in this case. That's because
28004 the first row visible in a window does not
28005 necessarily display the character whose position
28006 is the smallest. */
28008 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28009 ? Fmarker_position (w
->start
)
28012 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28013 ? make_number (BUF_Z (XBUFFER (buffer
))
28014 - XFASTINT (w
->window_end_pos
))
28017 if (NILP (overlay
))
28019 /* Handle the text property case. */
28020 before
= Fprevious_single_property_change
28021 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28022 after
= Fnext_single_property_change
28023 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28024 before_string
= after_string
= Qnil
;
28028 /* Handle the overlay case. */
28029 before
= Foverlay_start (overlay
);
28030 after
= Foverlay_end (overlay
);
28031 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28032 after_string
= Foverlay_get (overlay
, Qafter_string
);
28034 if (!STRINGP (before_string
)) before_string
= Qnil
;
28035 if (!STRINGP (after_string
)) after_string
= Qnil
;
28038 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28041 : XFASTINT (before
),
28043 ? BUF_Z (XBUFFER (buffer
))
28044 : XFASTINT (after
),
28045 before_string
, after_string
,
28047 cursor
= No_Cursor
;
28054 /* Look for a `help-echo' property. */
28055 if (NILP (help_echo_string
)) {
28056 Lisp_Object help
, overlay
;
28058 /* Check overlays first. */
28059 help
= overlay
= Qnil
;
28060 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28062 overlay
= overlay_vec
[i
];
28063 help
= Foverlay_get (overlay
, Qhelp_echo
);
28068 help_echo_string
= help
;
28069 help_echo_window
= window
;
28070 help_echo_object
= overlay
;
28071 help_echo_pos
= pos
;
28075 Lisp_Object obj
= glyph
->object
;
28076 ptrdiff_t charpos
= glyph
->charpos
;
28078 /* Try text properties. */
28081 && charpos
< SCHARS (obj
))
28083 help
= Fget_text_property (make_number (charpos
),
28087 /* If the string itself doesn't specify a help-echo,
28088 see if the buffer text ``under'' it does. */
28089 struct glyph_row
*r
28090 = MATRIX_ROW (w
->current_matrix
, vpos
);
28091 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28092 ptrdiff_t p
= string_buffer_position (obj
, start
);
28095 help
= Fget_char_property (make_number (p
),
28096 Qhelp_echo
, w
->buffer
);
28105 else if (BUFFERP (obj
)
28108 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28113 help_echo_string
= help
;
28114 help_echo_window
= window
;
28115 help_echo_object
= obj
;
28116 help_echo_pos
= charpos
;
28121 #ifdef HAVE_WINDOW_SYSTEM
28122 /* Look for a `pointer' property. */
28123 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28125 /* Check overlays first. */
28126 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28127 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28129 if (NILP (pointer
))
28131 Lisp_Object obj
= glyph
->object
;
28132 ptrdiff_t charpos
= glyph
->charpos
;
28134 /* Try text properties. */
28137 && charpos
< SCHARS (obj
))
28139 pointer
= Fget_text_property (make_number (charpos
),
28141 if (NILP (pointer
))
28143 /* If the string itself doesn't specify a pointer,
28144 see if the buffer text ``under'' it does. */
28145 struct glyph_row
*r
28146 = MATRIX_ROW (w
->current_matrix
, vpos
);
28147 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28148 ptrdiff_t p
= string_buffer_position (obj
, start
);
28150 pointer
= Fget_char_property (make_number (p
),
28151 Qpointer
, w
->buffer
);
28154 else if (BUFFERP (obj
)
28157 pointer
= Fget_text_property (make_number (charpos
),
28161 #endif /* HAVE_WINDOW_SYSTEM */
28165 current_buffer
= obuf
;
28170 #ifdef HAVE_WINDOW_SYSTEM
28171 if (FRAME_WINDOW_P (f
))
28172 define_frame_cursor1 (f
, cursor
, pointer
);
28174 /* This is here to prevent a compiler error, about "label at end of
28175 compound statement". */
28182 Clear any mouse-face on window W. This function is part of the
28183 redisplay interface, and is called from try_window_id and similar
28184 functions to ensure the mouse-highlight is off. */
28187 x_clear_window_mouse_face (struct window
*w
)
28189 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28190 Lisp_Object window
;
28193 XSETWINDOW (window
, w
);
28194 if (EQ (window
, hlinfo
->mouse_face_window
))
28195 clear_mouse_face (hlinfo
);
28201 Just discard the mouse face information for frame F, if any.
28202 This is used when the size of F is changed. */
28205 cancel_mouse_face (struct frame
*f
)
28207 Lisp_Object window
;
28208 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28210 window
= hlinfo
->mouse_face_window
;
28211 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28213 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28214 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28215 hlinfo
->mouse_face_window
= Qnil
;
28221 /***********************************************************************
28223 ***********************************************************************/
28225 #ifdef HAVE_WINDOW_SYSTEM
28227 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28228 which intersects rectangle R. R is in window-relative coordinates. */
28231 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28232 enum glyph_row_area area
)
28234 struct glyph
*first
= row
->glyphs
[area
];
28235 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28236 struct glyph
*last
;
28237 int first_x
, start_x
, x
;
28239 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28240 /* If row extends face to end of line write the whole line. */
28241 draw_glyphs (w
, 0, row
, area
,
28242 0, row
->used
[area
],
28243 DRAW_NORMAL_TEXT
, 0);
28246 /* Set START_X to the window-relative start position for drawing glyphs of
28247 AREA. The first glyph of the text area can be partially visible.
28248 The first glyphs of other areas cannot. */
28249 start_x
= window_box_left_offset (w
, area
);
28251 if (area
== TEXT_AREA
)
28254 /* Find the first glyph that must be redrawn. */
28256 && x
+ first
->pixel_width
< r
->x
)
28258 x
+= first
->pixel_width
;
28262 /* Find the last one. */
28266 && x
< r
->x
+ r
->width
)
28268 x
+= last
->pixel_width
;
28274 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28275 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28276 DRAW_NORMAL_TEXT
, 0);
28281 /* Redraw the parts of the glyph row ROW on window W intersecting
28282 rectangle R. R is in window-relative coordinates. Value is
28283 non-zero if mouse-face was overwritten. */
28286 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28288 eassert (row
->enabled_p
);
28290 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28291 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28292 0, row
->used
[TEXT_AREA
],
28293 DRAW_NORMAL_TEXT
, 0);
28296 if (row
->used
[LEFT_MARGIN_AREA
])
28297 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28298 if (row
->used
[TEXT_AREA
])
28299 expose_area (w
, row
, r
, TEXT_AREA
);
28300 if (row
->used
[RIGHT_MARGIN_AREA
])
28301 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28302 draw_row_fringe_bitmaps (w
, row
);
28305 return row
->mouse_face_p
;
28309 /* Redraw those parts of glyphs rows during expose event handling that
28310 overlap other rows. Redrawing of an exposed line writes over parts
28311 of lines overlapping that exposed line; this function fixes that.
28313 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28314 row in W's current matrix that is exposed and overlaps other rows.
28315 LAST_OVERLAPPING_ROW is the last such row. */
28318 expose_overlaps (struct window
*w
,
28319 struct glyph_row
*first_overlapping_row
,
28320 struct glyph_row
*last_overlapping_row
,
28323 struct glyph_row
*row
;
28325 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28326 if (row
->overlapping_p
)
28328 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28331 if (row
->used
[LEFT_MARGIN_AREA
])
28332 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28334 if (row
->used
[TEXT_AREA
])
28335 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28337 if (row
->used
[RIGHT_MARGIN_AREA
])
28338 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28344 /* Return non-zero if W's cursor intersects rectangle R. */
28347 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28349 XRectangle cr
, result
;
28350 struct glyph
*cursor_glyph
;
28351 struct glyph_row
*row
;
28353 if (w
->phys_cursor
.vpos
>= 0
28354 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28355 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28357 && row
->cursor_in_fringe_p
)
28359 /* Cursor is in the fringe. */
28360 cr
.x
= window_box_right_offset (w
,
28361 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28362 ? RIGHT_MARGIN_AREA
28365 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28366 cr
.height
= row
->height
;
28367 return x_intersect_rectangles (&cr
, r
, &result
);
28370 cursor_glyph
= get_phys_cursor_glyph (w
);
28373 /* r is relative to W's box, but w->phys_cursor.x is relative
28374 to left edge of W's TEXT area. Adjust it. */
28375 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28376 cr
.y
= w
->phys_cursor
.y
;
28377 cr
.width
= cursor_glyph
->pixel_width
;
28378 cr
.height
= w
->phys_cursor_height
;
28379 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28380 I assume the effect is the same -- and this is portable. */
28381 return x_intersect_rectangles (&cr
, r
, &result
);
28383 /* If we don't understand the format, pretend we're not in the hot-spot. */
28389 Draw a vertical window border to the right of window W if W doesn't
28390 have vertical scroll bars. */
28393 x_draw_vertical_border (struct window
*w
)
28395 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28397 /* We could do better, if we knew what type of scroll-bar the adjacent
28398 windows (on either side) have... But we don't :-(
28399 However, I think this works ok. ++KFS 2003-04-25 */
28401 /* Redraw borders between horizontally adjacent windows. Don't
28402 do it for frames with vertical scroll bars because either the
28403 right scroll bar of a window, or the left scroll bar of its
28404 neighbor will suffice as a border. */
28405 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28408 if (!WINDOW_RIGHTMOST_P (w
)
28409 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28411 int x0
, x1
, y0
, y1
;
28413 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28416 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28419 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28421 else if (!WINDOW_LEFTMOST_P (w
)
28422 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28424 int x0
, x1
, y0
, y1
;
28426 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28429 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28432 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28437 /* Redraw the part of window W intersection rectangle FR. Pixel
28438 coordinates in FR are frame-relative. Call this function with
28439 input blocked. Value is non-zero if the exposure overwrites
28443 expose_window (struct window
*w
, XRectangle
*fr
)
28445 struct frame
*f
= XFRAME (w
->frame
);
28447 int mouse_face_overwritten_p
= 0;
28449 /* If window is not yet fully initialized, do nothing. This can
28450 happen when toolkit scroll bars are used and a window is split.
28451 Reconfiguring the scroll bar will generate an expose for a newly
28453 if (w
->current_matrix
== NULL
)
28456 /* When we're currently updating the window, display and current
28457 matrix usually don't agree. Arrange for a thorough display
28459 if (w
== updated_window
)
28461 SET_FRAME_GARBAGED (f
);
28465 /* Frame-relative pixel rectangle of W. */
28466 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28467 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28468 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28469 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28471 if (x_intersect_rectangles (fr
, &wr
, &r
))
28473 int yb
= window_text_bottom_y (w
);
28474 struct glyph_row
*row
;
28475 int cursor_cleared_p
, phys_cursor_on_p
;
28476 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28478 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28479 r
.x
, r
.y
, r
.width
, r
.height
));
28481 /* Convert to window coordinates. */
28482 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28483 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28485 /* Turn off the cursor. */
28486 if (!w
->pseudo_window_p
28487 && phys_cursor_in_rect_p (w
, &r
))
28489 x_clear_cursor (w
);
28490 cursor_cleared_p
= 1;
28493 cursor_cleared_p
= 0;
28495 /* If the row containing the cursor extends face to end of line,
28496 then expose_area might overwrite the cursor outside the
28497 rectangle and thus notice_overwritten_cursor might clear
28498 w->phys_cursor_on_p. We remember the original value and
28499 check later if it is changed. */
28500 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28502 /* Update lines intersecting rectangle R. */
28503 first_overlapping_row
= last_overlapping_row
= NULL
;
28504 for (row
= w
->current_matrix
->rows
;
28509 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28511 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28512 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28513 || (r
.y
>= y0
&& r
.y
< y1
)
28514 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28516 /* A header line may be overlapping, but there is no need
28517 to fix overlapping areas for them. KFS 2005-02-12 */
28518 if (row
->overlapping_p
&& !row
->mode_line_p
)
28520 if (first_overlapping_row
== NULL
)
28521 first_overlapping_row
= row
;
28522 last_overlapping_row
= row
;
28526 if (expose_line (w
, row
, &r
))
28527 mouse_face_overwritten_p
= 1;
28530 else if (row
->overlapping_p
)
28532 /* We must redraw a row overlapping the exposed area. */
28534 ? y0
+ row
->phys_height
> r
.y
28535 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28537 if (first_overlapping_row
== NULL
)
28538 first_overlapping_row
= row
;
28539 last_overlapping_row
= row
;
28547 /* Display the mode line if there is one. */
28548 if (WINDOW_WANTS_MODELINE_P (w
)
28549 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28551 && row
->y
< r
.y
+ r
.height
)
28553 if (expose_line (w
, row
, &r
))
28554 mouse_face_overwritten_p
= 1;
28557 if (!w
->pseudo_window_p
)
28559 /* Fix the display of overlapping rows. */
28560 if (first_overlapping_row
)
28561 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28564 /* Draw border between windows. */
28565 x_draw_vertical_border (w
);
28567 /* Turn the cursor on again. */
28568 if (cursor_cleared_p
28569 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28570 update_window_cursor (w
, 1);
28574 return mouse_face_overwritten_p
;
28579 /* Redraw (parts) of all windows in the window tree rooted at W that
28580 intersect R. R contains frame pixel coordinates. Value is
28581 non-zero if the exposure overwrites mouse-face. */
28584 expose_window_tree (struct window
*w
, XRectangle
*r
)
28586 struct frame
*f
= XFRAME (w
->frame
);
28587 int mouse_face_overwritten_p
= 0;
28589 while (w
&& !FRAME_GARBAGED_P (f
))
28591 if (!NILP (w
->hchild
))
28592 mouse_face_overwritten_p
28593 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28594 else if (!NILP (w
->vchild
))
28595 mouse_face_overwritten_p
28596 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28598 mouse_face_overwritten_p
|= expose_window (w
, r
);
28600 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28603 return mouse_face_overwritten_p
;
28608 Redisplay an exposed area of frame F. X and Y are the upper-left
28609 corner of the exposed rectangle. W and H are width and height of
28610 the exposed area. All are pixel values. W or H zero means redraw
28611 the entire frame. */
28614 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28617 int mouse_face_overwritten_p
= 0;
28619 TRACE ((stderr
, "expose_frame "));
28621 /* No need to redraw if frame will be redrawn soon. */
28622 if (FRAME_GARBAGED_P (f
))
28624 TRACE ((stderr
, " garbaged\n"));
28628 /* If basic faces haven't been realized yet, there is no point in
28629 trying to redraw anything. This can happen when we get an expose
28630 event while Emacs is starting, e.g. by moving another window. */
28631 if (FRAME_FACE_CACHE (f
) == NULL
28632 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28634 TRACE ((stderr
, " no faces\n"));
28638 if (w
== 0 || h
== 0)
28641 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28642 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28652 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28653 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28655 if (WINDOWP (f
->tool_bar_window
))
28656 mouse_face_overwritten_p
28657 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28659 #ifdef HAVE_X_WINDOWS
28661 #ifndef USE_X_TOOLKIT
28662 if (WINDOWP (f
->menu_bar_window
))
28663 mouse_face_overwritten_p
28664 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28665 #endif /* not USE_X_TOOLKIT */
28669 /* Some window managers support a focus-follows-mouse style with
28670 delayed raising of frames. Imagine a partially obscured frame,
28671 and moving the mouse into partially obscured mouse-face on that
28672 frame. The visible part of the mouse-face will be highlighted,
28673 then the WM raises the obscured frame. With at least one WM, KDE
28674 2.1, Emacs is not getting any event for the raising of the frame
28675 (even tried with SubstructureRedirectMask), only Expose events.
28676 These expose events will draw text normally, i.e. not
28677 highlighted. Which means we must redo the highlight here.
28678 Subsume it under ``we love X''. --gerd 2001-08-15 */
28679 /* Included in Windows version because Windows most likely does not
28680 do the right thing if any third party tool offers
28681 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28682 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28684 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28685 if (f
== hlinfo
->mouse_face_mouse_frame
)
28687 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28688 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28689 clear_mouse_face (hlinfo
);
28690 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28697 Determine the intersection of two rectangles R1 and R2. Return
28698 the intersection in *RESULT. Value is non-zero if RESULT is not
28702 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28704 XRectangle
*left
, *right
;
28705 XRectangle
*upper
, *lower
;
28706 int intersection_p
= 0;
28708 /* Rearrange so that R1 is the left-most rectangle. */
28710 left
= r1
, right
= r2
;
28712 left
= r2
, right
= r1
;
28714 /* X0 of the intersection is right.x0, if this is inside R1,
28715 otherwise there is no intersection. */
28716 if (right
->x
<= left
->x
+ left
->width
)
28718 result
->x
= right
->x
;
28720 /* The right end of the intersection is the minimum of
28721 the right ends of left and right. */
28722 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28725 /* Same game for Y. */
28727 upper
= r1
, lower
= r2
;
28729 upper
= r2
, lower
= r1
;
28731 /* The upper end of the intersection is lower.y0, if this is inside
28732 of upper. Otherwise, there is no intersection. */
28733 if (lower
->y
<= upper
->y
+ upper
->height
)
28735 result
->y
= lower
->y
;
28737 /* The lower end of the intersection is the minimum of the lower
28738 ends of upper and lower. */
28739 result
->height
= (min (lower
->y
+ lower
->height
,
28740 upper
->y
+ upper
->height
)
28742 intersection_p
= 1;
28746 return intersection_p
;
28749 #endif /* HAVE_WINDOW_SYSTEM */
28752 /***********************************************************************
28754 ***********************************************************************/
28757 syms_of_xdisp (void)
28759 Vwith_echo_area_save_vector
= Qnil
;
28760 staticpro (&Vwith_echo_area_save_vector
);
28762 Vmessage_stack
= Qnil
;
28763 staticpro (&Vmessage_stack
);
28765 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28766 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
28768 message_dolog_marker1
= Fmake_marker ();
28769 staticpro (&message_dolog_marker1
);
28770 message_dolog_marker2
= Fmake_marker ();
28771 staticpro (&message_dolog_marker2
);
28772 message_dolog_marker3
= Fmake_marker ();
28773 staticpro (&message_dolog_marker3
);
28776 defsubr (&Sdump_frame_glyph_matrix
);
28777 defsubr (&Sdump_glyph_matrix
);
28778 defsubr (&Sdump_glyph_row
);
28779 defsubr (&Sdump_tool_bar_row
);
28780 defsubr (&Strace_redisplay
);
28781 defsubr (&Strace_to_stderr
);
28783 #ifdef HAVE_WINDOW_SYSTEM
28784 defsubr (&Stool_bar_lines_needed
);
28785 defsubr (&Slookup_image_map
);
28787 defsubr (&Sformat_mode_line
);
28788 defsubr (&Sinvisible_p
);
28789 defsubr (&Scurrent_bidi_paragraph_direction
);
28791 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28792 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28793 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28794 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28795 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28796 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28797 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28798 DEFSYM (Qeval
, "eval");
28799 DEFSYM (QCdata
, ":data");
28800 DEFSYM (Qdisplay
, "display");
28801 DEFSYM (Qspace_width
, "space-width");
28802 DEFSYM (Qraise
, "raise");
28803 DEFSYM (Qslice
, "slice");
28804 DEFSYM (Qspace
, "space");
28805 DEFSYM (Qmargin
, "margin");
28806 DEFSYM (Qpointer
, "pointer");
28807 DEFSYM (Qleft_margin
, "left-margin");
28808 DEFSYM (Qright_margin
, "right-margin");
28809 DEFSYM (Qcenter
, "center");
28810 DEFSYM (Qline_height
, "line-height");
28811 DEFSYM (QCalign_to
, ":align-to");
28812 DEFSYM (QCrelative_width
, ":relative-width");
28813 DEFSYM (QCrelative_height
, ":relative-height");
28814 DEFSYM (QCeval
, ":eval");
28815 DEFSYM (QCpropertize
, ":propertize");
28816 DEFSYM (QCfile
, ":file");
28817 DEFSYM (Qfontified
, "fontified");
28818 DEFSYM (Qfontification_functions
, "fontification-functions");
28819 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28820 DEFSYM (Qescape_glyph
, "escape-glyph");
28821 DEFSYM (Qnobreak_space
, "nobreak-space");
28822 DEFSYM (Qimage
, "image");
28823 DEFSYM (Qtext
, "text");
28824 DEFSYM (Qboth
, "both");
28825 DEFSYM (Qboth_horiz
, "both-horiz");
28826 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28827 DEFSYM (QCmap
, ":map");
28828 DEFSYM (QCpointer
, ":pointer");
28829 DEFSYM (Qrect
, "rect");
28830 DEFSYM (Qcircle
, "circle");
28831 DEFSYM (Qpoly
, "poly");
28832 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28833 DEFSYM (Qgrow_only
, "grow-only");
28834 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28835 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28836 DEFSYM (Qposition
, "position");
28837 DEFSYM (Qbuffer_position
, "buffer-position");
28838 DEFSYM (Qobject
, "object");
28839 DEFSYM (Qbar
, "bar");
28840 DEFSYM (Qhbar
, "hbar");
28841 DEFSYM (Qbox
, "box");
28842 DEFSYM (Qhollow
, "hollow");
28843 DEFSYM (Qhand
, "hand");
28844 DEFSYM (Qarrow
, "arrow");
28845 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28847 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28848 Fcons (intern_c_string ("void-variable"), Qnil
)),
28850 staticpro (&list_of_error
);
28852 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28853 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28854 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28855 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28857 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28858 staticpro (&echo_buffer
[0]);
28859 staticpro (&echo_buffer
[1]);
28861 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28862 staticpro (&echo_area_buffer
[0]);
28863 staticpro (&echo_area_buffer
[1]);
28865 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28866 staticpro (&Vmessages_buffer_name
);
28868 mode_line_proptrans_alist
= Qnil
;
28869 staticpro (&mode_line_proptrans_alist
);
28870 mode_line_string_list
= Qnil
;
28871 staticpro (&mode_line_string_list
);
28872 mode_line_string_face
= Qnil
;
28873 staticpro (&mode_line_string_face
);
28874 mode_line_string_face_prop
= Qnil
;
28875 staticpro (&mode_line_string_face_prop
);
28876 Vmode_line_unwind_vector
= Qnil
;
28877 staticpro (&Vmode_line_unwind_vector
);
28879 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28881 help_echo_string
= Qnil
;
28882 staticpro (&help_echo_string
);
28883 help_echo_object
= Qnil
;
28884 staticpro (&help_echo_object
);
28885 help_echo_window
= Qnil
;
28886 staticpro (&help_echo_window
);
28887 previous_help_echo_string
= Qnil
;
28888 staticpro (&previous_help_echo_string
);
28889 help_echo_pos
= -1;
28891 DEFSYM (Qright_to_left
, "right-to-left");
28892 DEFSYM (Qleft_to_right
, "left-to-right");
28894 #ifdef HAVE_WINDOW_SYSTEM
28895 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28896 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28897 For example, if a block cursor is over a tab, it will be drawn as
28898 wide as that tab on the display. */);
28899 x_stretch_cursor_p
= 0;
28902 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28903 doc
: /* Non-nil means highlight trailing whitespace.
28904 The face used for trailing whitespace is `trailing-whitespace'. */);
28905 Vshow_trailing_whitespace
= Qnil
;
28907 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28908 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28909 If the value is t, Emacs highlights non-ASCII chars which have the
28910 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28911 or `escape-glyph' face respectively.
28913 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28914 U+2011 (non-breaking hyphen) are affected.
28916 Any other non-nil value means to display these characters as a escape
28917 glyph followed by an ordinary space or hyphen.
28919 A value of nil means no special handling of these characters. */);
28920 Vnobreak_char_display
= Qt
;
28922 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28923 doc
: /* The pointer shape to show in void text areas.
28924 A value of nil means to show the text pointer. Other options are `arrow',
28925 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28926 Vvoid_text_area_pointer
= Qarrow
;
28928 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28929 doc
: /* Non-nil means don't actually do any redisplay.
28930 This is used for internal purposes. */);
28931 Vinhibit_redisplay
= Qnil
;
28933 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28934 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28935 Vglobal_mode_string
= Qnil
;
28937 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28938 doc
: /* Marker for where to display an arrow on top of the buffer text.
28939 This must be the beginning of a line in order to work.
28940 See also `overlay-arrow-string'. */);
28941 Voverlay_arrow_position
= Qnil
;
28943 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28944 doc
: /* String to display as an arrow in non-window frames.
28945 See also `overlay-arrow-position'. */);
28946 Voverlay_arrow_string
= build_pure_c_string ("=>");
28948 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28949 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28950 The symbols on this list are examined during redisplay to determine
28951 where to display overlay arrows. */);
28952 Voverlay_arrow_variable_list
28953 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
28955 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
28956 doc
: /* The number of lines to try scrolling a window by when point moves out.
28957 If that fails to bring point back on frame, point is centered instead.
28958 If this is zero, point is always centered after it moves off frame.
28959 If you want scrolling to always be a line at a time, you should set
28960 `scroll-conservatively' to a large value rather than set this to 1. */);
28962 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
28963 doc
: /* Scroll up to this many lines, to bring point back on screen.
28964 If point moves off-screen, redisplay will scroll by up to
28965 `scroll-conservatively' lines in order to bring point just barely
28966 onto the screen again. If that cannot be done, then redisplay
28967 recenters point as usual.
28969 If the value is greater than 100, redisplay will never recenter point,
28970 but will always scroll just enough text to bring point into view, even
28971 if you move far away.
28973 A value of zero means always recenter point if it moves off screen. */);
28974 scroll_conservatively
= 0;
28976 DEFVAR_INT ("scroll-margin", scroll_margin
,
28977 doc
: /* Number of lines of margin at the top and bottom of a window.
28978 Recenter the window whenever point gets within this many lines
28979 of the top or bottom of the window. */);
28982 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
28983 doc
: /* Pixels per inch value for non-window system displays.
28984 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
28985 Vdisplay_pixels_per_inch
= make_float (72.0);
28988 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
28991 DEFVAR_LISP ("truncate-partial-width-windows",
28992 Vtruncate_partial_width_windows
,
28993 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
28994 For an integer value, truncate lines in each window narrower than the
28995 full frame width, provided the window width is less than that integer;
28996 otherwise, respect the value of `truncate-lines'.
28998 For any other non-nil value, truncate lines in all windows that do
28999 not span the full frame width.
29001 A value of nil means to respect the value of `truncate-lines'.
29003 If `word-wrap' is enabled, you might want to reduce this. */);
29004 Vtruncate_partial_width_windows
= make_number (50);
29006 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29007 doc
: /* Maximum buffer size for which line number should be displayed.
29008 If the buffer is bigger than this, the line number does not appear
29009 in the mode line. A value of nil means no limit. */);
29010 Vline_number_display_limit
= Qnil
;
29012 DEFVAR_INT ("line-number-display-limit-width",
29013 line_number_display_limit_width
,
29014 doc
: /* Maximum line width (in characters) for line number display.
29015 If the average length of the lines near point is bigger than this, then the
29016 line number may be omitted from the mode line. */);
29017 line_number_display_limit_width
= 200;
29019 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29020 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29021 highlight_nonselected_windows
= 0;
29023 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29024 doc
: /* Non-nil if more than one frame is visible on this display.
29025 Minibuffer-only frames don't count, but iconified frames do.
29026 This variable is not guaranteed to be accurate except while processing
29027 `frame-title-format' and `icon-title-format'. */);
29029 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29030 doc
: /* Template for displaying the title bar of visible frames.
29031 \(Assuming the window manager supports this feature.)
29033 This variable has the same structure as `mode-line-format', except that
29034 the %c and %l constructs are ignored. It is used only on frames for
29035 which no explicit name has been set \(see `modify-frame-parameters'). */);
29037 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29038 doc
: /* Template for displaying the title bar of an iconified frame.
29039 \(Assuming the window manager supports this feature.)
29040 This variable has the same structure as `mode-line-format' (which see),
29041 and is used only on frames for which no explicit name has been set
29042 \(see `modify-frame-parameters'). */);
29044 = Vframe_title_format
29045 = listn (CONSTYPE_PURE
, 3,
29046 intern_c_string ("multiple-frames"),
29047 build_pure_c_string ("%b"),
29048 listn (CONSTYPE_PURE
, 4,
29049 empty_unibyte_string
,
29050 intern_c_string ("invocation-name"),
29051 build_pure_c_string ("@"),
29052 intern_c_string ("system-name")));
29054 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29055 doc
: /* Maximum number of lines to keep in the message log buffer.
29056 If nil, disable message logging. If t, log messages but don't truncate
29057 the buffer when it becomes large. */);
29058 Vmessage_log_max
= make_number (1000);
29060 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29061 doc
: /* Functions called before redisplay, if window sizes have changed.
29062 The value should be a list of functions that take one argument.
29063 Just before redisplay, for each frame, if any of its windows have changed
29064 size since the last redisplay, or have been split or deleted,
29065 all the functions in the list are called, with the frame as argument. */);
29066 Vwindow_size_change_functions
= Qnil
;
29068 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29069 doc
: /* List of functions to call before redisplaying a window with scrolling.
29070 Each function is called with two arguments, the window and its new
29071 display-start position. Note that these functions are also called by
29072 `set-window-buffer'. Also note that the value of `window-end' is not
29073 valid when these functions are called.
29075 Warning: Do not use this feature to alter the way the window
29076 is scrolled. It is not designed for that, and such use probably won't
29078 Vwindow_scroll_functions
= Qnil
;
29080 DEFVAR_LISP ("window-text-change-functions",
29081 Vwindow_text_change_functions
,
29082 doc
: /* Functions to call in redisplay when text in the window might change. */);
29083 Vwindow_text_change_functions
= Qnil
;
29085 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29086 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29087 Each function is called with two arguments, the window and the end trigger value.
29088 See `set-window-redisplay-end-trigger'. */);
29089 Vredisplay_end_trigger_functions
= Qnil
;
29091 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29092 doc
: /* Non-nil means autoselect window with mouse pointer.
29093 If nil, do not autoselect windows.
29094 A positive number means delay autoselection by that many seconds: a
29095 window is autoselected only after the mouse has remained in that
29096 window for the duration of the delay.
29097 A negative number has a similar effect, but causes windows to be
29098 autoselected only after the mouse has stopped moving. \(Because of
29099 the way Emacs compares mouse events, you will occasionally wait twice
29100 that time before the window gets selected.\)
29101 Any other value means to autoselect window instantaneously when the
29102 mouse pointer enters it.
29104 Autoselection selects the minibuffer only if it is active, and never
29105 unselects the minibuffer if it is active.
29107 When customizing this variable make sure that the actual value of
29108 `focus-follows-mouse' matches the behavior of your window manager. */);
29109 Vmouse_autoselect_window
= Qnil
;
29111 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29112 doc
: /* Non-nil means automatically resize tool-bars.
29113 This dynamically changes the tool-bar's height to the minimum height
29114 that is needed to make all tool-bar items visible.
29115 If value is `grow-only', the tool-bar's height is only increased
29116 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29117 Vauto_resize_tool_bars
= Qt
;
29119 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29120 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29121 auto_raise_tool_bar_buttons_p
= 1;
29123 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29124 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29125 make_cursor_line_fully_visible_p
= 1;
29127 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29128 doc
: /* Border below tool-bar in pixels.
29129 If an integer, use it as the height of the border.
29130 If it is one of `internal-border-width' or `border-width', use the
29131 value of the corresponding frame parameter.
29132 Otherwise, no border is added below the tool-bar. */);
29133 Vtool_bar_border
= Qinternal_border_width
;
29135 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29136 doc
: /* Margin around tool-bar buttons in pixels.
29137 If an integer, use that for both horizontal and vertical margins.
29138 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29139 HORZ specifying the horizontal margin, and VERT specifying the
29140 vertical margin. */);
29141 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29143 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29144 doc
: /* Relief thickness of tool-bar buttons. */);
29145 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29147 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29148 doc
: /* Tool bar style to use.
29150 image - show images only
29151 text - show text only
29152 both - show both, text below image
29153 both-horiz - show text to the right of the image
29154 text-image-horiz - show text to the left of the image
29155 any other - use system default or image if no system default.
29157 This variable only affects the GTK+ toolkit version of Emacs. */);
29158 Vtool_bar_style
= Qnil
;
29160 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29161 doc
: /* Maximum number of characters a label can have to be shown.
29162 The tool bar style must also show labels for this to have any effect, see
29163 `tool-bar-style'. */);
29164 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29166 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29167 doc
: /* List of functions to call to fontify regions of text.
29168 Each function is called with one argument POS. Functions must
29169 fontify a region starting at POS in the current buffer, and give
29170 fontified regions the property `fontified'. */);
29171 Vfontification_functions
= Qnil
;
29172 Fmake_variable_buffer_local (Qfontification_functions
);
29174 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29175 unibyte_display_via_language_environment
,
29176 doc
: /* Non-nil means display unibyte text according to language environment.
29177 Specifically, this means that raw bytes in the range 160-255 decimal
29178 are displayed by converting them to the equivalent multibyte characters
29179 according to the current language environment. As a result, they are
29180 displayed according to the current fontset.
29182 Note that this variable affects only how these bytes are displayed,
29183 but does not change the fact they are interpreted as raw bytes. */);
29184 unibyte_display_via_language_environment
= 0;
29186 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29187 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29188 If a float, it specifies a fraction of the mini-window frame's height.
29189 If an integer, it specifies a number of lines. */);
29190 Vmax_mini_window_height
= make_float (0.25);
29192 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29193 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29194 A value of nil means don't automatically resize mini-windows.
29195 A value of t means resize them to fit the text displayed in them.
29196 A value of `grow-only', the default, means let mini-windows grow only;
29197 they return to their normal size when the minibuffer is closed, or the
29198 echo area becomes empty. */);
29199 Vresize_mini_windows
= Qgrow_only
;
29201 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29202 doc
: /* Alist specifying how to blink the cursor off.
29203 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29204 `cursor-type' frame-parameter or variable equals ON-STATE,
29205 comparing using `equal', Emacs uses OFF-STATE to specify
29206 how to blink it off. ON-STATE and OFF-STATE are values for
29207 the `cursor-type' frame parameter.
29209 If a frame's ON-STATE has no entry in this list,
29210 the frame's other specifications determine how to blink the cursor off. */);
29211 Vblink_cursor_alist
= Qnil
;
29213 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29214 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29215 If non-nil, windows are automatically scrolled horizontally to make
29216 point visible. */);
29217 automatic_hscrolling_p
= 1;
29218 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29220 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29221 doc
: /* How many columns away from the window edge point is allowed to get
29222 before automatic hscrolling will horizontally scroll the window. */);
29223 hscroll_margin
= 5;
29225 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29226 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29227 When point is less than `hscroll-margin' columns from the window
29228 edge, automatic hscrolling will scroll the window by the amount of columns
29229 determined by this variable. If its value is a positive integer, scroll that
29230 many columns. If it's a positive floating-point number, it specifies the
29231 fraction of the window's width to scroll. If it's nil or zero, point will be
29232 centered horizontally after the scroll. Any other value, including negative
29233 numbers, are treated as if the value were zero.
29235 Automatic hscrolling always moves point outside the scroll margin, so if
29236 point was more than scroll step columns inside the margin, the window will
29237 scroll more than the value given by the scroll step.
29239 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29240 and `scroll-right' overrides this variable's effect. */);
29241 Vhscroll_step
= make_number (0);
29243 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29244 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29245 Bind this around calls to `message' to let it take effect. */);
29246 message_truncate_lines
= 0;
29248 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29249 doc
: /* Normal hook run to update the menu bar definitions.
29250 Redisplay runs this hook before it redisplays the menu bar.
29251 This is used to update submenus such as Buffers,
29252 whose contents depend on various data. */);
29253 Vmenu_bar_update_hook
= Qnil
;
29255 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29256 doc
: /* Frame for which we are updating a menu.
29257 The enable predicate for a menu binding should check this variable. */);
29258 Vmenu_updating_frame
= Qnil
;
29260 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29261 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29262 inhibit_menubar_update
= 0;
29264 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29265 doc
: /* Prefix prepended to all continuation lines at display time.
29266 The value may be a string, an image, or a stretch-glyph; it is
29267 interpreted in the same way as the value of a `display' text property.
29269 This variable is overridden by any `wrap-prefix' text or overlay
29272 To add a prefix to non-continuation lines, use `line-prefix'. */);
29273 Vwrap_prefix
= Qnil
;
29274 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29275 Fmake_variable_buffer_local (Qwrap_prefix
);
29277 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29278 doc
: /* Prefix prepended to all non-continuation lines at display time.
29279 The value may be a string, an image, or a stretch-glyph; it is
29280 interpreted in the same way as the value of a `display' text property.
29282 This variable is overridden by any `line-prefix' text or overlay
29285 To add a prefix to continuation lines, use `wrap-prefix'. */);
29286 Vline_prefix
= Qnil
;
29287 DEFSYM (Qline_prefix
, "line-prefix");
29288 Fmake_variable_buffer_local (Qline_prefix
);
29290 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29291 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29292 inhibit_eval_during_redisplay
= 0;
29294 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29295 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29296 inhibit_free_realized_faces
= 0;
29299 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29300 doc
: /* Inhibit try_window_id display optimization. */);
29301 inhibit_try_window_id
= 0;
29303 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29304 doc
: /* Inhibit try_window_reusing display optimization. */);
29305 inhibit_try_window_reusing
= 0;
29307 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29308 doc
: /* Inhibit try_cursor_movement display optimization. */);
29309 inhibit_try_cursor_movement
= 0;
29310 #endif /* GLYPH_DEBUG */
29312 DEFVAR_INT ("overline-margin", overline_margin
,
29313 doc
: /* Space between overline and text, in pixels.
29314 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29315 margin to the character height. */);
29316 overline_margin
= 2;
29318 DEFVAR_INT ("underline-minimum-offset",
29319 underline_minimum_offset
,
29320 doc
: /* Minimum distance between baseline and underline.
29321 This can improve legibility of underlined text at small font sizes,
29322 particularly when using variable `x-use-underline-position-properties'
29323 with fonts that specify an UNDERLINE_POSITION relatively close to the
29324 baseline. The default value is 1. */);
29325 underline_minimum_offset
= 1;
29327 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29328 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29329 This feature only works when on a window system that can change
29330 cursor shapes. */);
29331 display_hourglass_p
= 1;
29333 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29334 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29335 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29337 hourglass_atimer
= NULL
;
29338 hourglass_shown_p
= 0;
29340 DEFSYM (Qglyphless_char
, "glyphless-char");
29341 DEFSYM (Qhex_code
, "hex-code");
29342 DEFSYM (Qempty_box
, "empty-box");
29343 DEFSYM (Qthin_space
, "thin-space");
29344 DEFSYM (Qzero_width
, "zero-width");
29346 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29347 /* Intern this now in case it isn't already done.
29348 Setting this variable twice is harmless.
29349 But don't staticpro it here--that is done in alloc.c. */
29350 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29351 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29353 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29354 doc
: /* Char-table defining glyphless characters.
29355 Each element, if non-nil, should be one of the following:
29356 an ASCII acronym string: display this string in a box
29357 `hex-code': display the hexadecimal code of a character in a box
29358 `empty-box': display as an empty box
29359 `thin-space': display as 1-pixel width space
29360 `zero-width': don't display
29361 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29362 display method for graphical terminals and text terminals respectively.
29363 GRAPHICAL and TEXT should each have one of the values listed above.
29365 The char-table has one extra slot to control the display of a character for
29366 which no font is found. This slot only takes effect on graphical terminals.
29367 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29368 `thin-space'. The default is `empty-box'. */);
29369 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29370 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29373 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29374 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29375 Vdebug_on_message
= Qnil
;
29379 /* Initialize this module when Emacs starts. */
29384 current_header_line_height
= current_mode_line_height
= -1;
29386 CHARPOS (this_line_start_pos
) = 0;
29388 if (!noninteractive
)
29390 struct window
*m
= XWINDOW (minibuf_window
);
29391 Lisp_Object frame
= m
->frame
;
29392 struct frame
*f
= XFRAME (frame
);
29393 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29394 struct window
*r
= XWINDOW (root
);
29397 echo_area_window
= minibuf_window
;
29399 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
29401 (r
, make_number (FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
)));
29402 wset_total_cols (r
, make_number (FRAME_COLS (f
)));
29403 wset_top_line (m
, make_number (FRAME_LINES (f
) - 1));
29404 wset_total_lines (m
, make_number (1));
29405 wset_total_cols (m
, make_number (FRAME_COLS (f
)));
29407 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29408 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29409 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29411 /* The default ellipsis glyphs `...'. */
29412 for (i
= 0; i
< 3; ++i
)
29413 default_invis_vector
[i
] = make_number ('.');
29417 /* Allocate the buffer for frame titles.
29418 Also used for `format-mode-line'. */
29420 mode_line_noprop_buf
= xmalloc (size
);
29421 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29422 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29423 mode_line_target
= MODE_LINE_DISPLAY
;
29426 help_echo_showing_p
= 0;
29429 /* Platform-independent portion of hourglass implementation. */
29431 /* Cancel a currently active hourglass timer, and start a new one. */
29433 start_hourglass (void)
29435 #if defined (HAVE_WINDOW_SYSTEM)
29438 cancel_hourglass ();
29440 if (INTEGERP (Vhourglass_delay
)
29441 && XINT (Vhourglass_delay
) > 0)
29442 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29443 TYPE_MAXIMUM (time_t)),
29445 else if (FLOATP (Vhourglass_delay
)
29446 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29447 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29449 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29453 extern void w32_note_current_window (void);
29454 w32_note_current_window ();
29456 #endif /* HAVE_NTGUI */
29458 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29459 show_hourglass
, NULL
);
29464 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29467 cancel_hourglass (void)
29469 #if defined (HAVE_WINDOW_SYSTEM)
29470 if (hourglass_atimer
)
29472 cancel_atimer (hourglass_atimer
);
29473 hourglass_atimer
= NULL
;
29476 if (hourglass_shown_p
)