1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
24 Emacs separates the task of updating the display from code
25 modifying global state, e.g. buffer text. This way functions
26 operating on buffers don't also have to be concerned with updating
29 Updating the display is triggered by the Lisp interpreter when it
30 decides it's time to do it. This is done either automatically for
31 you as part of the interpreter's command loop or as the result of
32 calling Lisp functions like `sit-for'. The C function `redisplay'
33 in xdisp.c is the only entry into the inner redisplay code.
35 The following diagram shows how redisplay code is invoked. As you
36 can see, Lisp calls redisplay and vice versa. Under window systems
37 like X, some portions of the redisplay code are also called
38 asynchronously during mouse movement or expose events. It is very
39 important that these code parts do NOT use the C library (malloc,
40 free) because many C libraries under Unix are not reentrant. They
41 may also NOT call functions of the Lisp interpreter which could
42 change the interpreter's state. If you don't follow these rules,
43 you will encounter bugs which are very hard to explain.
45 +--------------+ redisplay +----------------+
46 | Lisp machine |---------------->| Redisplay code |<--+
47 +--------------+ (xdisp.c) +----------------+ |
49 +----------------------------------+ |
50 Don't use this path when called |
53 expose_window (asynchronous) |
55 X expose events -----+
57 What does redisplay do? Obviously, it has to figure out somehow what
58 has been changed since the last time the display has been updated,
59 and to make these changes visible. Preferably it would do that in
60 a moderately intelligent way, i.e. fast.
62 Changes in buffer text can be deduced from window and buffer
63 structures, and from some global variables like `beg_unchanged' and
64 `end_unchanged'. The contents of the display are additionally
65 recorded in a `glyph matrix', a two-dimensional matrix of glyph
66 structures. Each row in such a matrix corresponds to a line on the
67 display, and each glyph in a row corresponds to a column displaying
68 a character, an image, or what else. This matrix is called the
69 `current glyph matrix' or `current matrix' in redisplay
72 For buffer parts that have been changed since the last update, a
73 second glyph matrix is constructed, the so called `desired glyph
74 matrix' or short `desired matrix'. Current and desired matrix are
75 then compared to find a cheap way to update the display, e.g. by
76 reusing part of the display by scrolling lines.
78 You will find a lot of redisplay optimizations when you start
79 looking at the innards of redisplay. The overall goal of all these
80 optimizations is to make redisplay fast because it is done
81 frequently. Some of these optimizations are implemented by the
86 This function tries to update the display if the text in the
87 window did not change and did not scroll, only point moved, and
88 it did not move off the displayed portion of the text.
90 . try_window_reusing_current_matrix
92 This function reuses the current matrix of a window when text
93 has not changed, but the window start changed (e.g., due to
98 This function attempts to redisplay a window by reusing parts of
99 its existing display. It finds and reuses the part that was not
100 changed, and redraws the rest.
104 This function performs the full redisplay of a single window
105 assuming that its fonts were not changed and that the cursor
106 will not end up in the scroll margins. (Loading fonts requires
107 re-adjustment of dimensions of glyph matrices, which makes this
108 method impossible to use.)
110 These optimizations are tried in sequence (some can be skipped if
111 it is known that they are not applicable). If none of the
112 optimizations were successful, redisplay calls redisplay_windows,
113 which performs a full redisplay of all windows.
117 Desired matrices are always built per Emacs window. The function
118 `display_line' is the central function to look at if you are
119 interested. It constructs one row in a desired matrix given an
120 iterator structure containing both a buffer position and a
121 description of the environment in which the text is to be
122 displayed. But this is too early, read on.
124 Characters and pixmaps displayed for a range of buffer text depend
125 on various settings of buffers and windows, on overlays and text
126 properties, on display tables, on selective display. The good news
127 is that all this hairy stuff is hidden behind a small set of
128 interface functions taking an iterator structure (struct it)
131 Iteration over things to be displayed is then simple. It is
132 started by initializing an iterator with a call to init_iterator,
133 passing it the buffer position where to start iteration. For
134 iteration over strings, pass -1 as the position to init_iterator,
135 and call reseat_to_string when the string is ready, to initialize
136 the iterator for that string. Thereafter, calls to
137 get_next_display_element fill the iterator structure with relevant
138 information about the next thing to display. Calls to
139 set_iterator_to_next move the iterator to the next thing.
141 Besides this, an iterator also contains information about the
142 display environment in which glyphs for display elements are to be
143 produced. It has fields for the width and height of the display,
144 the information whether long lines are truncated or continued, a
145 current X and Y position, and lots of other stuff you can better
148 Glyphs in a desired matrix are normally constructed in a loop
149 calling get_next_display_element and then PRODUCE_GLYPHS. The call
150 to PRODUCE_GLYPHS will fill the iterator structure with pixel
151 information about the element being displayed and at the same time
152 produce glyphs for it. If the display element fits on the line
153 being displayed, set_iterator_to_next is called next, otherwise the
154 glyphs produced are discarded. The function display_line is the
155 workhorse of filling glyph rows in the desired matrix with glyphs.
156 In addition to producing glyphs, it also handles line truncation
157 and continuation, word wrap, and cursor positioning (for the
158 latter, see also set_cursor_from_row).
162 That just couldn't be all, could it? What about terminal types not
163 supporting operations on sub-windows of the screen? To update the
164 display on such a terminal, window-based glyph matrices are not
165 well suited. To be able to reuse part of the display (scrolling
166 lines up and down), we must instead have a view of the whole
167 screen. This is what `frame matrices' are for. They are a trick.
169 Frames on terminals like above have a glyph pool. Windows on such
170 a frame sub-allocate their glyph memory from their frame's glyph
171 pool. The frame itself is given its own glyph matrices. By
172 coincidence---or maybe something else---rows in window glyph
173 matrices are slices of corresponding rows in frame matrices. Thus
174 writing to window matrices implicitly updates a frame matrix which
175 provides us with the view of the whole screen that we originally
176 wanted to have without having to move many bytes around. To be
177 honest, there is a little bit more done, but not much more. If you
178 plan to extend that code, take a look at dispnew.c. The function
179 build_frame_matrix is a good starting point.
181 Bidirectional display.
183 Bidirectional display adds quite some hair to this already complex
184 design. The good news are that a large portion of that hairy stuff
185 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
186 reordering engine which is called by set_iterator_to_next and
187 returns the next character to display in the visual order. See
188 commentary on bidi.c for more details. As far as redisplay is
189 concerned, the effect of calling bidi_move_to_visually_next, the
190 main interface of the reordering engine, is that the iterator gets
191 magically placed on the buffer or string position that is to be
192 displayed next. In other words, a linear iteration through the
193 buffer/string is replaced with a non-linear one. All the rest of
194 the redisplay is oblivious to the bidi reordering.
196 Well, almost oblivious---there are still complications, most of
197 them due to the fact that buffer and string positions no longer
198 change monotonously with glyph indices in a glyph row. Moreover,
199 for continued lines, the buffer positions may not even be
200 monotonously changing with vertical positions. Also, accounting
201 for face changes, overlays, etc. becomes more complex because
202 non-linear iteration could potentially skip many positions with
203 changes, and then cross them again on the way back...
205 One other prominent effect of bidirectional display is that some
206 paragraphs of text need to be displayed starting at the right
207 margin of the window---the so-called right-to-left, or R2L
208 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
209 which have their reversed_p flag set. The bidi reordering engine
210 produces characters in such rows starting from the character which
211 should be the rightmost on display. PRODUCE_GLYPHS then reverses
212 the order, when it fills up the glyph row whose reversed_p flag is
213 set, by prepending each new glyph to what is already there, instead
214 of appending it. When the glyph row is complete, the function
215 extend_face_to_end_of_line fills the empty space to the left of the
216 leftmost character with special glyphs, which will display as,
217 well, empty. On text terminals, these special glyphs are simply
218 blank characters. On graphics terminals, there's a single stretch
219 glyph of a suitably computed width. Both the blanks and the
220 stretch glyph are given the face of the background of the line.
221 This way, the terminal-specific back-end can still draw the glyphs
222 left to right, even for R2L lines.
224 Bidirectional display and character compositions
226 Some scripts cannot be displayed by drawing each character
227 individually, because adjacent characters change each other's shape
228 on display. For example, Arabic and Indic scripts belong to this
231 Emacs display supports this by providing "character compositions",
232 most of which is implemented in composite.c. During the buffer
233 scan that delivers characters to PRODUCE_GLYPHS, if the next
234 character to be delivered is a composed character, the iteration
235 calls composition_reseat_it and next_element_from_composition. If
236 they succeed to compose the character with one or more of the
237 following characters, the whole sequence of characters that where
238 composed is recorded in the `struct composition_it' object that is
239 part of the buffer iterator. The composed sequence could produce
240 one or more font glyphs (called "grapheme clusters") on the screen.
241 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
242 in the direction corresponding to the current bidi scan direction
243 (recorded in the scan_dir member of the `struct bidi_it' object
244 that is part of the buffer iterator). In particular, if the bidi
245 iterator currently scans the buffer backwards, the grapheme
246 clusters are delivered back to front. This reorders the grapheme
247 clusters as appropriate for the current bidi context. Note that
248 this means that the grapheme clusters are always stored in the
249 LGSTRING object (see composite.c) in the logical order.
251 Moving an iterator in bidirectional text
252 without producing glyphs
254 Note one important detail mentioned above: that the bidi reordering
255 engine, driven by the iterator, produces characters in R2L rows
256 starting at the character that will be the rightmost on display.
257 As far as the iterator is concerned, the geometry of such rows is
258 still left to right, i.e. the iterator "thinks" the first character
259 is at the leftmost pixel position. The iterator does not know that
260 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
261 delivers. This is important when functions from the move_it_*
262 family are used to get to certain screen position or to match
263 screen coordinates with buffer coordinates: these functions use the
264 iterator geometry, which is left to right even in R2L paragraphs.
265 This works well with most callers of move_it_*, because they need
266 to get to a specific column, and columns are still numbered in the
267 reading order, i.e. the rightmost character in a R2L paragraph is
268 still column zero. But some callers do not get well with this; a
269 notable example is mouse clicks that need to find the character
270 that corresponds to certain pixel coordinates. See
271 buffer_posn_from_coords in dispnew.c for how this is handled. */
279 #include "keyboard.h"
282 #include "termchar.h"
283 #include "dispextern.h"
284 #include "character.h"
288 #include "commands.h"
292 #include "termhooks.h"
293 #include "termopts.h"
294 #include "intervals.h"
297 #include "region-cache.h"
300 #include "blockinput.h"
302 #ifdef HAVE_X_WINDOWS
317 #ifndef FRAME_X_OUTPUT
318 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
321 #define INFINITY 10000000
323 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
324 Lisp_Object Qwindow_scroll_functions
;
325 static Lisp_Object Qwindow_text_change_functions
;
326 static Lisp_Object Qredisplay_end_trigger_functions
;
327 Lisp_Object Qinhibit_point_motion_hooks
;
328 static Lisp_Object QCeval
, QCpropertize
;
329 Lisp_Object QCfile
, QCdata
;
330 static Lisp_Object Qfontified
;
331 static Lisp_Object Qgrow_only
;
332 static Lisp_Object Qinhibit_eval_during_redisplay
;
333 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
334 static Lisp_Object Qright_to_left
, Qleft_to_right
;
337 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
339 /* Pointer shapes. */
340 static Lisp_Object Qarrow
, Qhand
;
343 /* Holds the list (error). */
344 static Lisp_Object list_of_error
;
346 static Lisp_Object Qfontification_functions
;
348 static Lisp_Object Qwrap_prefix
;
349 static Lisp_Object Qline_prefix
;
350 static Lisp_Object Qredisplay_internal
;
352 /* Non-nil means don't actually do any redisplay. */
354 Lisp_Object Qinhibit_redisplay
;
356 /* Names of text properties relevant for redisplay. */
358 Lisp_Object Qdisplay
;
360 Lisp_Object Qspace
, QCalign_to
;
361 static Lisp_Object QCrelative_width
, QCrelative_height
;
362 Lisp_Object Qleft_margin
, Qright_margin
;
363 static Lisp_Object Qspace_width
, Qraise
;
364 static Lisp_Object Qslice
;
366 static Lisp_Object Qmargin
, Qpointer
;
367 static Lisp_Object Qline_height
;
369 /* These setters are used only in this file, so they can be private. */
371 wset_base_line_number (struct window
*w
, Lisp_Object val
)
373 w
->base_line_number
= val
;
376 wset_base_line_pos (struct window
*w
, Lisp_Object val
)
378 w
->base_line_pos
= val
;
381 wset_column_number_displayed (struct window
*w
, Lisp_Object val
)
383 w
->column_number_displayed
= val
;
386 wset_region_showing (struct window
*w
, Lisp_Object val
)
388 w
->region_showing
= val
;
391 #ifdef HAVE_WINDOW_SYSTEM
393 /* Test if overflow newline into fringe. Called with iterator IT
394 at or past right window margin, and with IT->current_x set. */
396 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
397 (!NILP (Voverflow_newline_into_fringe) \
398 && FRAME_WINDOW_P ((IT)->f) \
399 && ((IT)->bidi_it.paragraph_dir == R2L \
400 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
401 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
402 && (IT)->current_x == (IT)->last_visible_x \
403 && (IT)->line_wrap != WORD_WRAP)
405 #else /* !HAVE_WINDOW_SYSTEM */
406 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
407 #endif /* HAVE_WINDOW_SYSTEM */
409 /* Test if the display element loaded in IT, or the underlying buffer
410 or string character, is a space or a TAB character. This is used
411 to determine where word wrapping can occur. */
413 #define IT_DISPLAYING_WHITESPACE(it) \
414 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
415 || ((STRINGP (it->string) \
416 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
417 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
419 && (it->s[IT_BYTEPOS (*it)] == ' ' \
420 || it->s[IT_BYTEPOS (*it)] == '\t')) \
421 || (IT_BYTEPOS (*it) < ZV_BYTE \
422 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
423 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
425 /* Name of the face used to highlight trailing whitespace. */
427 static Lisp_Object Qtrailing_whitespace
;
429 /* Name and number of the face used to highlight escape glyphs. */
431 static Lisp_Object Qescape_glyph
;
433 /* Name and number of the face used to highlight non-breaking spaces. */
435 static Lisp_Object Qnobreak_space
;
437 /* The symbol `image' which is the car of the lists used to represent
438 images in Lisp. Also a tool bar style. */
442 /* The image map types. */
444 static Lisp_Object QCpointer
;
445 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
447 /* Tool bar styles */
448 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
450 /* Non-zero means print newline to stdout before next mini-buffer
453 int noninteractive_need_newline
;
455 /* Non-zero means print newline to message log before next message. */
457 static int message_log_need_newline
;
459 /* Three markers that message_dolog uses.
460 It could allocate them itself, but that causes trouble
461 in handling memory-full errors. */
462 static Lisp_Object message_dolog_marker1
;
463 static Lisp_Object message_dolog_marker2
;
464 static Lisp_Object message_dolog_marker3
;
466 /* The buffer position of the first character appearing entirely or
467 partially on the line of the selected window which contains the
468 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
469 redisplay optimization in redisplay_internal. */
471 static struct text_pos this_line_start_pos
;
473 /* Number of characters past the end of the line above, including the
474 terminating newline. */
476 static struct text_pos this_line_end_pos
;
478 /* The vertical positions and the height of this line. */
480 static int this_line_vpos
;
481 static int this_line_y
;
482 static int this_line_pixel_height
;
484 /* X position at which this display line starts. Usually zero;
485 negative if first character is partially visible. */
487 static int this_line_start_x
;
489 /* The smallest character position seen by move_it_* functions as they
490 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
491 hscrolled lines, see display_line. */
493 static struct text_pos this_line_min_pos
;
495 /* Buffer that this_line_.* variables are referring to. */
497 static struct buffer
*this_line_buffer
;
500 /* Values of those variables at last redisplay are stored as
501 properties on `overlay-arrow-position' symbol. However, if
502 Voverlay_arrow_position is a marker, last-arrow-position is its
503 numerical position. */
505 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
507 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
508 properties on a symbol in overlay-arrow-variable-list. */
510 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
512 Lisp_Object Qmenu_bar_update_hook
;
514 /* Nonzero if an overlay arrow has been displayed in this window. */
516 static int overlay_arrow_seen
;
518 /* Vector containing glyphs for an ellipsis `...'. */
520 static Lisp_Object default_invis_vector
[3];
522 /* This is the window where the echo area message was displayed. It
523 is always a mini-buffer window, but it may not be the same window
524 currently active as a mini-buffer. */
526 Lisp_Object echo_area_window
;
528 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
529 pushes the current message and the value of
530 message_enable_multibyte on the stack, the function restore_message
531 pops the stack and displays MESSAGE again. */
533 static Lisp_Object Vmessage_stack
;
535 /* Nonzero means multibyte characters were enabled when the echo area
536 message was specified. */
538 static int message_enable_multibyte
;
540 /* Nonzero if we should redraw the mode lines on the next redisplay. */
542 int update_mode_lines
;
544 /* Nonzero if window sizes or contents have changed since last
545 redisplay that finished. */
547 int windows_or_buffers_changed
;
549 /* Nonzero means a frame's cursor type has been changed. */
551 int cursor_type_changed
;
553 /* Nonzero after display_mode_line if %l was used and it displayed a
556 static int line_number_displayed
;
558 /* The name of the *Messages* buffer, a string. */
560 static Lisp_Object Vmessages_buffer_name
;
562 /* Current, index 0, and last displayed echo area message. Either
563 buffers from echo_buffers, or nil to indicate no message. */
565 Lisp_Object echo_area_buffer
[2];
567 /* The buffers referenced from echo_area_buffer. */
569 static Lisp_Object echo_buffer
[2];
571 /* A vector saved used in with_area_buffer to reduce consing. */
573 static Lisp_Object Vwith_echo_area_save_vector
;
575 /* Non-zero means display_echo_area should display the last echo area
576 message again. Set by redisplay_preserve_echo_area. */
578 static int display_last_displayed_message_p
;
580 /* Nonzero if echo area is being used by print; zero if being used by
583 static int message_buf_print
;
585 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
587 static Lisp_Object Qinhibit_menubar_update
;
588 static Lisp_Object Qmessage_truncate_lines
;
590 /* Set to 1 in clear_message to make redisplay_internal aware
591 of an emptied echo area. */
593 static int message_cleared_p
;
595 /* A scratch glyph row with contents used for generating truncation
596 glyphs. Also used in direct_output_for_insert. */
598 #define MAX_SCRATCH_GLYPHS 100
599 static struct glyph_row scratch_glyph_row
;
600 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
602 /* Ascent and height of the last line processed by move_it_to. */
604 static int last_max_ascent
, last_height
;
606 /* Non-zero if there's a help-echo in the echo area. */
608 int help_echo_showing_p
;
610 /* If >= 0, computed, exact values of mode-line and header-line height
611 to use in the macros CURRENT_MODE_LINE_HEIGHT and
612 CURRENT_HEADER_LINE_HEIGHT. */
614 int current_mode_line_height
, current_header_line_height
;
616 /* The maximum distance to look ahead for text properties. Values
617 that are too small let us call compute_char_face and similar
618 functions too often which is expensive. Values that are too large
619 let us call compute_char_face and alike too often because we
620 might not be interested in text properties that far away. */
622 #define TEXT_PROP_DISTANCE_LIMIT 100
624 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
625 iterator state and later restore it. This is needed because the
626 bidi iterator on bidi.c keeps a stacked cache of its states, which
627 is really a singleton. When we use scratch iterator objects to
628 move around the buffer, we can cause the bidi cache to be pushed or
629 popped, and therefore we need to restore the cache state when we
630 return to the original iterator. */
631 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
634 bidi_unshelve_cache (CACHE, 1); \
636 CACHE = bidi_shelve_cache (); \
639 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
641 if (pITORIG != pITCOPY) \
642 *(pITORIG) = *(pITCOPY); \
643 bidi_unshelve_cache (CACHE, 0); \
649 /* Non-zero means print traces of redisplay if compiled with
650 GLYPH_DEBUG defined. */
652 int trace_redisplay_p
;
654 #endif /* GLYPH_DEBUG */
656 #ifdef DEBUG_TRACE_MOVE
657 /* Non-zero means trace with TRACE_MOVE to stderr. */
660 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
662 #define TRACE_MOVE(x) (void) 0
665 static Lisp_Object Qauto_hscroll_mode
;
667 /* Buffer being redisplayed -- for redisplay_window_error. */
669 static struct buffer
*displayed_buffer
;
671 /* Value returned from text property handlers (see below). */
676 HANDLED_RECOMPUTE_PROPS
,
677 HANDLED_OVERLAY_STRING_CONSUMED
,
681 /* A description of text properties that redisplay is interested
686 /* The name of the property. */
689 /* A unique index for the property. */
692 /* A handler function called to set up iterator IT from the property
693 at IT's current position. Value is used to steer handle_stop. */
694 enum prop_handled (*handler
) (struct it
*it
);
697 static enum prop_handled
handle_face_prop (struct it
*);
698 static enum prop_handled
handle_invisible_prop (struct it
*);
699 static enum prop_handled
handle_display_prop (struct it
*);
700 static enum prop_handled
handle_composition_prop (struct it
*);
701 static enum prop_handled
handle_overlay_change (struct it
*);
702 static enum prop_handled
handle_fontified_prop (struct it
*);
704 /* Properties handled by iterators. */
706 static struct props it_props
[] =
708 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
709 /* Handle `face' before `display' because some sub-properties of
710 `display' need to know the face. */
711 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
712 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
713 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
714 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
718 /* Value is the position described by X. If X is a marker, value is
719 the marker_position of X. Otherwise, value is X. */
721 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
723 /* Enumeration returned by some move_it_.* functions internally. */
727 /* Not used. Undefined value. */
730 /* Move ended at the requested buffer position or ZV. */
731 MOVE_POS_MATCH_OR_ZV
,
733 /* Move ended at the requested X pixel position. */
736 /* Move within a line ended at the end of a line that must be
740 /* Move within a line ended at the end of a line that would
741 be displayed truncated. */
744 /* Move within a line ended at a line end. */
748 /* This counter is used to clear the face cache every once in a while
749 in redisplay_internal. It is incremented for each redisplay.
750 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
753 #define CLEAR_FACE_CACHE_COUNT 500
754 static int clear_face_cache_count
;
756 /* Similarly for the image cache. */
758 #ifdef HAVE_WINDOW_SYSTEM
759 #define CLEAR_IMAGE_CACHE_COUNT 101
760 static int clear_image_cache_count
;
762 /* Null glyph slice */
763 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
766 /* True while redisplay_internal is in progress. */
770 static Lisp_Object Qinhibit_free_realized_faces
;
771 static Lisp_Object Qmode_line_default_help_echo
;
773 /* If a string, XTread_socket generates an event to display that string.
774 (The display is done in read_char.) */
776 Lisp_Object help_echo_string
;
777 Lisp_Object help_echo_window
;
778 Lisp_Object help_echo_object
;
779 ptrdiff_t help_echo_pos
;
781 /* Temporary variable for XTread_socket. */
783 Lisp_Object previous_help_echo_string
;
785 /* Platform-independent portion of hourglass implementation. */
787 /* Non-zero means an hourglass cursor is currently shown. */
788 int hourglass_shown_p
;
790 /* If non-null, an asynchronous timer that, when it expires, displays
791 an hourglass cursor on all frames. */
792 struct atimer
*hourglass_atimer
;
794 /* Name of the face used to display glyphless characters. */
795 Lisp_Object Qglyphless_char
;
797 /* Symbol for the purpose of Vglyphless_char_display. */
798 static Lisp_Object Qglyphless_char_display
;
800 /* Method symbols for Vglyphless_char_display. */
801 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
803 /* Default pixel width of `thin-space' display method. */
804 #define THIN_SPACE_WIDTH 1
806 /* Default number of seconds to wait before displaying an hourglass
808 #define DEFAULT_HOURGLASS_DELAY 1
811 /* Function prototypes. */
813 static void setup_for_ellipsis (struct it
*, int);
814 static void set_iterator_to_next (struct it
*, int);
815 static void mark_window_display_accurate_1 (struct window
*, int);
816 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
817 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
818 static int cursor_row_p (struct glyph_row
*);
819 static int redisplay_mode_lines (Lisp_Object
, int);
820 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
822 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
824 static void handle_line_prefix (struct it
*);
826 static void pint2str (char *, int, ptrdiff_t);
827 static void pint2hrstr (char *, int, ptrdiff_t);
828 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
830 static void reconsider_clip_changes (struct window
*, struct buffer
*);
831 static int text_outside_line_unchanged_p (struct window
*,
832 ptrdiff_t, ptrdiff_t);
833 static void store_mode_line_noprop_char (char);
834 static int store_mode_line_noprop (const char *, int, int);
835 static void handle_stop (struct it
*);
836 static void handle_stop_backwards (struct it
*, ptrdiff_t);
837 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
838 static void ensure_echo_area_buffers (void);
839 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
840 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
841 static int with_echo_area_buffer (struct window
*, int,
842 int (*) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
843 ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
844 static void clear_garbaged_frames (void);
845 static int current_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
846 static void pop_message (void);
847 static int truncate_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
848 static void set_message (const char *, Lisp_Object
, ptrdiff_t, int);
849 static int set_message_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
850 static int display_echo_area (struct window
*);
851 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
852 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t);
853 static Lisp_Object
unwind_redisplay (Lisp_Object
);
854 static int string_char_and_length (const unsigned char *, int *);
855 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
857 static int compute_window_start_on_continuation_line (struct window
*);
858 static void insert_left_trunc_glyphs (struct it
*);
859 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
861 static void extend_face_to_end_of_line (struct it
*);
862 static int append_space_for_newline (struct it
*, int);
863 static int cursor_row_fully_visible_p (struct window
*, int, int);
864 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
865 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
866 static int trailing_whitespace_p (ptrdiff_t);
867 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
868 static void push_it (struct it
*, struct text_pos
*);
869 static void iterate_out_of_display_property (struct it
*);
870 static void pop_it (struct it
*);
871 static void sync_frame_with_window_matrix_rows (struct window
*);
872 static void select_frame_for_redisplay (Lisp_Object
);
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
, tem
;
9402 struct gcpro gcpro1
;
9404 old_deactivate_mark
= Vdeactivate_mark
;
9405 oldbuf
= current_buffer
;
9406 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9407 bset_undo_list (current_buffer
, Qt
);
9409 oldpoint
= message_dolog_marker1
;
9410 set_marker_restricted (oldpoint
, make_number (PT
), Qnil
);
9411 oldbegv
= message_dolog_marker2
;
9412 set_marker_restricted (oldbegv
, make_number (BEGV
), Qnil
);
9413 oldzv
= message_dolog_marker3
;
9414 set_marker_restricted (oldzv
, make_number (ZV
), Qnil
);
9415 GCPRO1 (old_deactivate_mark
);
9423 BEGV_BYTE
= BEG_BYTE
;
9426 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9428 /* Insert the string--maybe converting multibyte to single byte
9429 or vice versa, so that all the text fits the buffer. */
9431 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9437 /* Convert a multibyte string to single-byte
9438 for the *Message* buffer. */
9439 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9441 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9442 work
[0] = (ASCII_CHAR_P (c
)
9444 : multibyte_char_to_unibyte (c
));
9445 insert_1_both (work
, 1, 1, 1, 0, 0);
9448 else if (! multibyte
9449 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9453 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9454 /* Convert a single-byte string to multibyte
9455 for the *Message* buffer. */
9456 for (i
= 0; i
< nbytes
; i
++)
9459 MAKE_CHAR_MULTIBYTE (c
);
9460 char_bytes
= CHAR_STRING (c
, str
);
9461 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9465 insert_1 (m
, nbytes
, 1, 0, 0);
9469 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9471 insert_1 ("\n", 1, 1, 0, 0);
9473 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9475 this_bol_byte
= PT_BYTE
;
9477 /* See if this line duplicates the previous one.
9478 If so, combine duplicates. */
9481 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9483 prev_bol_byte
= PT_BYTE
;
9485 dups
= message_log_check_duplicate (prev_bol_byte
,
9489 del_range_both (prev_bol
, prev_bol_byte
,
9490 this_bol
, this_bol_byte
, 0);
9493 char dupstr
[sizeof " [ times]"
9494 + INT_STRLEN_BOUND (printmax_t
)];
9496 /* If you change this format, don't forget to also
9497 change message_log_check_duplicate. */
9498 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9499 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9500 insert_1 (dupstr
, duplen
, 1, 0, 1);
9505 /* If we have more than the desired maximum number of lines
9506 in the *Messages* buffer now, delete the oldest ones.
9507 This is safe because we don't have undo in this buffer. */
9509 if (NATNUMP (Vmessage_log_max
))
9511 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9512 -XFASTINT (Vmessage_log_max
) - 1, 0);
9513 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9516 BEGV
= marker_position (oldbegv
);
9517 BEGV_BYTE
= marker_byte_position (oldbegv
);
9526 ZV
= marker_position (oldzv
);
9527 ZV_BYTE
= marker_byte_position (oldzv
);
9531 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9533 /* We can't do Fgoto_char (oldpoint) because it will run some
9535 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9536 marker_byte_position (oldpoint
));
9539 unchain_marker (XMARKER (oldpoint
));
9540 unchain_marker (XMARKER (oldbegv
));
9541 unchain_marker (XMARKER (oldzv
));
9543 tem
= Fget_buffer_window (Fcurrent_buffer (), Qt
);
9544 set_buffer_internal (oldbuf
);
9546 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9547 message_log_need_newline
= !nlflag
;
9548 Vdeactivate_mark
= old_deactivate_mark
;
9553 /* We are at the end of the buffer after just having inserted a newline.
9554 (Note: We depend on the fact we won't be crossing the gap.)
9555 Check to see if the most recent message looks a lot like the previous one.
9556 Return 0 if different, 1 if the new one should just replace it, or a
9557 value N > 1 if we should also append " [N times]". */
9560 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9563 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9565 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9566 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9568 for (i
= 0; i
< len
; i
++)
9570 if (i
>= 3 && p1
[i
-3] == '.' && p1
[i
-2] == '.' && p1
[i
-1] == '.')
9578 if (*p1
++ == ' ' && *p1
++ == '[')
9581 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9582 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9589 /* Display an echo area message M with a specified length of NBYTES
9590 bytes. The string may include null characters. If M is 0, clear
9591 out any existing message, and let the mini-buffer text show
9594 This may GC, so the buffer M must NOT point to a Lisp string. */
9597 message2 (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9599 /* First flush out any partial line written with print. */
9600 message_log_maybe_newline ();
9602 message_dolog (m
, nbytes
, 1, multibyte
);
9603 message2_nolog (m
, nbytes
, multibyte
);
9607 /* The non-logging counterpart of message2. */
9610 message2_nolog (const char *m
, ptrdiff_t nbytes
, int multibyte
)
9612 struct frame
*sf
= SELECTED_FRAME ();
9613 message_enable_multibyte
= multibyte
;
9615 if (FRAME_INITIAL_P (sf
))
9617 if (noninteractive_need_newline
)
9618 putc ('\n', stderr
);
9619 noninteractive_need_newline
= 0;
9621 fwrite (m
, nbytes
, 1, stderr
);
9622 if (cursor_in_echo_area
== 0)
9623 fprintf (stderr
, "\n");
9626 /* A null message buffer means that the frame hasn't really been
9627 initialized yet. Error messages get reported properly by
9628 cmd_error, so this must be just an informative message; toss it. */
9629 else if (INTERACTIVE
9630 && sf
->glyphs_initialized_p
9631 && FRAME_MESSAGE_BUF (sf
))
9633 Lisp_Object mini_window
;
9636 /* Get the frame containing the mini-buffer
9637 that the selected frame is using. */
9638 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9639 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9641 FRAME_SAMPLE_VISIBILITY (f
);
9642 if (FRAME_VISIBLE_P (sf
)
9643 && ! FRAME_VISIBLE_P (f
))
9644 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window
)));
9648 set_message (m
, Qnil
, nbytes
, multibyte
);
9649 if (minibuffer_auto_raise
)
9650 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
9653 clear_message (1, 1);
9655 do_pending_window_change (0);
9656 echo_area_display (1);
9657 do_pending_window_change (0);
9658 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9659 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9664 /* Display an echo area message M with a specified length of NBYTES
9665 bytes. The string may include null characters. If M is not a
9666 string, clear out any existing message, and let the mini-buffer
9669 This function cancels echoing. */
9672 message3 (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9674 struct gcpro gcpro1
;
9677 clear_message (1,1);
9680 /* First flush out any partial line written with print. */
9681 message_log_maybe_newline ();
9685 char *buffer
= SAFE_ALLOCA (nbytes
);
9686 memcpy (buffer
, SDATA (m
), nbytes
);
9687 message_dolog (buffer
, nbytes
, 1, multibyte
);
9690 message3_nolog (m
, nbytes
, multibyte
);
9696 /* The non-logging version of message3.
9697 This does not cancel echoing, because it is used for echoing.
9698 Perhaps we need to make a separate function for echoing
9699 and make this cancel echoing. */
9702 message3_nolog (Lisp_Object m
, ptrdiff_t nbytes
, int multibyte
)
9704 struct frame
*sf
= SELECTED_FRAME ();
9705 message_enable_multibyte
= multibyte
;
9707 if (FRAME_INITIAL_P (sf
))
9709 if (noninteractive_need_newline
)
9710 putc ('\n', stderr
);
9711 noninteractive_need_newline
= 0;
9713 fwrite (SDATA (m
), nbytes
, 1, stderr
);
9714 if (cursor_in_echo_area
== 0)
9715 fprintf (stderr
, "\n");
9718 /* A null message buffer means that the frame hasn't really been
9719 initialized yet. Error messages get reported properly by
9720 cmd_error, so this must be just an informative message; toss it. */
9721 else if (INTERACTIVE
9722 && sf
->glyphs_initialized_p
9723 && FRAME_MESSAGE_BUF (sf
))
9725 Lisp_Object mini_window
;
9729 /* Get the frame containing the mini-buffer
9730 that the selected frame is using. */
9731 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9732 frame
= XWINDOW (mini_window
)->frame
;
9735 FRAME_SAMPLE_VISIBILITY (f
);
9736 if (FRAME_VISIBLE_P (sf
)
9737 && !FRAME_VISIBLE_P (f
))
9738 Fmake_frame_visible (frame
);
9740 if (STRINGP (m
) && SCHARS (m
) > 0)
9742 set_message (NULL
, m
, nbytes
, multibyte
);
9743 if (minibuffer_auto_raise
)
9744 Fraise_frame (frame
);
9745 /* Assume we are not echoing.
9746 (If we are, echo_now will override this.) */
9747 echo_message_buffer
= Qnil
;
9750 clear_message (1, 1);
9752 do_pending_window_change (0);
9753 echo_area_display (1);
9754 do_pending_window_change (0);
9755 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9756 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9761 /* Display a null-terminated echo area message M. If M is 0, clear
9762 out any existing message, and let the mini-buffer text show through.
9764 The buffer M must continue to exist until after the echo area gets
9765 cleared or some other message gets displayed there. Do not pass
9766 text that is stored in a Lisp string. Do not pass text in a buffer
9767 that was alloca'd. */
9770 message1 (const char *m
)
9772 message2 (m
, (m
? strlen (m
) : 0), 0);
9776 /* The non-logging counterpart of message1. */
9779 message1_nolog (const char *m
)
9781 message2_nolog (m
, (m
? strlen (m
) : 0), 0);
9784 /* Display a message M which contains a single %s
9785 which gets replaced with STRING. */
9788 message_with_string (const char *m
, Lisp_Object string
, int log
)
9790 CHECK_STRING (string
);
9796 if (noninteractive_need_newline
)
9797 putc ('\n', stderr
);
9798 noninteractive_need_newline
= 0;
9799 fprintf (stderr
, m
, SDATA (string
));
9800 if (!cursor_in_echo_area
)
9801 fprintf (stderr
, "\n");
9805 else if (INTERACTIVE
)
9807 /* The frame whose minibuffer we're going to display the message on.
9808 It may be larger than the selected frame, so we need
9809 to use its buffer, not the selected frame's buffer. */
9810 Lisp_Object mini_window
;
9811 struct frame
*f
, *sf
= SELECTED_FRAME ();
9813 /* Get the frame containing the minibuffer
9814 that the selected frame is using. */
9815 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9816 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9818 /* A null message buffer means that the frame hasn't really been
9819 initialized yet. Error messages get reported properly by
9820 cmd_error, so this must be just an informative message; toss it. */
9821 if (FRAME_MESSAGE_BUF (f
))
9823 Lisp_Object args
[2], msg
;
9824 struct gcpro gcpro1
, gcpro2
;
9826 args
[0] = build_string (m
);
9827 args
[1] = msg
= string
;
9828 GCPRO2 (args
[0], msg
);
9831 msg
= Fformat (2, args
);
9834 message3 (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9836 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
9840 /* Print should start at the beginning of the message
9841 buffer next time. */
9842 message_buf_print
= 0;
9848 /* Dump an informative message to the minibuf. If M is 0, clear out
9849 any existing message, and let the mini-buffer text show through. */
9852 vmessage (const char *m
, va_list ap
)
9858 if (noninteractive_need_newline
)
9859 putc ('\n', stderr
);
9860 noninteractive_need_newline
= 0;
9861 vfprintf (stderr
, m
, ap
);
9862 if (cursor_in_echo_area
== 0)
9863 fprintf (stderr
, "\n");
9867 else if (INTERACTIVE
)
9869 /* The frame whose mini-buffer we're going to display the message
9870 on. It may be larger than the selected frame, so we need to
9871 use its buffer, not the selected frame's buffer. */
9872 Lisp_Object mini_window
;
9873 struct frame
*f
, *sf
= SELECTED_FRAME ();
9875 /* Get the frame containing the mini-buffer
9876 that the selected frame is using. */
9877 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9878 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9880 /* A null message buffer means that the frame hasn't really been
9881 initialized yet. Error messages get reported properly by
9882 cmd_error, so this must be just an informative message; toss
9884 if (FRAME_MESSAGE_BUF (f
))
9890 len
= doprnt (FRAME_MESSAGE_BUF (f
),
9891 FRAME_MESSAGE_BUF_SIZE (f
), m
, (char *)0, ap
);
9893 message2 (FRAME_MESSAGE_BUF (f
), len
, 1);
9898 /* Print should start at the beginning of the message
9899 buffer next time. */
9900 message_buf_print
= 0;
9906 message (const char *m
, ...)
9916 /* The non-logging version of message. */
9919 message_nolog (const char *m
, ...)
9921 Lisp_Object old_log_max
;
9924 old_log_max
= Vmessage_log_max
;
9925 Vmessage_log_max
= Qnil
;
9927 Vmessage_log_max
= old_log_max
;
9933 /* Display the current message in the current mini-buffer. This is
9934 only called from error handlers in process.c, and is not time
9938 update_echo_area (void)
9940 if (!NILP (echo_area_buffer
[0]))
9943 string
= Fcurrent_message ();
9944 message3 (string
, SBYTES (string
),
9945 !NILP (BVAR (current_buffer
, enable_multibyte_characters
)));
9950 /* Make sure echo area buffers in `echo_buffers' are live.
9951 If they aren't, make new ones. */
9954 ensure_echo_area_buffers (void)
9958 for (i
= 0; i
< 2; ++i
)
9959 if (!BUFFERP (echo_buffer
[i
])
9960 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9963 Lisp_Object old_buffer
;
9966 old_buffer
= echo_buffer
[i
];
9967 echo_buffer
[i
] = Fget_buffer_create
9968 (make_formatted_string (name
, " *Echo Area %d*", i
));
9969 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9970 /* to force word wrap in echo area -
9971 it was decided to postpone this*/
9972 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9974 for (j
= 0; j
< 2; ++j
)
9975 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9976 echo_area_buffer
[j
] = echo_buffer
[i
];
9981 /* Call FN with args A1..A4 with either the current or last displayed
9982 echo_area_buffer as current buffer.
9984 WHICH zero means use the current message buffer
9985 echo_area_buffer[0]. If that is nil, choose a suitable buffer
9986 from echo_buffer[] and clear it.
9988 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
9989 suitable buffer from echo_buffer[] and clear it.
9991 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
9992 that the current message becomes the last displayed one, make
9993 choose a suitable buffer for echo_area_buffer[0], and clear it.
9995 Value is what FN returns. */
9998 with_echo_area_buffer (struct window
*w
, int which
,
9999 int (*fn
) (ptrdiff_t, Lisp_Object
, ptrdiff_t, ptrdiff_t),
10000 ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10002 Lisp_Object buffer
;
10003 int this_one
, the_other
, clear_buffer_p
, rc
;
10004 ptrdiff_t count
= SPECPDL_INDEX ();
10006 /* If buffers aren't live, make new ones. */
10007 ensure_echo_area_buffers ();
10009 clear_buffer_p
= 0;
10012 this_one
= 0, the_other
= 1;
10013 else if (which
> 0)
10014 this_one
= 1, the_other
= 0;
10017 this_one
= 0, the_other
= 1;
10018 clear_buffer_p
= 1;
10020 /* We need a fresh one in case the current echo buffer equals
10021 the one containing the last displayed echo area message. */
10022 if (!NILP (echo_area_buffer
[this_one
])
10023 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10024 echo_area_buffer
[this_one
] = Qnil
;
10027 /* Choose a suitable buffer from echo_buffer[] is we don't
10029 if (NILP (echo_area_buffer
[this_one
]))
10031 echo_area_buffer
[this_one
]
10032 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10033 ? echo_buffer
[the_other
]
10034 : echo_buffer
[this_one
]);
10035 clear_buffer_p
= 1;
10038 buffer
= echo_area_buffer
[this_one
];
10040 /* Don't get confused by reusing the buffer used for echoing
10041 for a different purpose. */
10042 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10045 record_unwind_protect (unwind_with_echo_area_buffer
,
10046 with_echo_area_buffer_unwind_data (w
));
10048 /* Make the echo area buffer current. Note that for display
10049 purposes, it is not necessary that the displayed window's buffer
10050 == current_buffer, except for text property lookup. So, let's
10051 only set that buffer temporarily here without doing a full
10052 Fset_window_buffer. We must also change w->pointm, though,
10053 because otherwise an assertions in unshow_buffer fails, and Emacs
10055 set_buffer_internal_1 (XBUFFER (buffer
));
10058 wset_buffer (w
, buffer
);
10059 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10062 bset_undo_list (current_buffer
, Qt
);
10063 bset_read_only (current_buffer
, Qnil
);
10064 specbind (Qinhibit_read_only
, Qt
);
10065 specbind (Qinhibit_modification_hooks
, Qt
);
10067 if (clear_buffer_p
&& Z
> BEG
)
10068 del_range (BEG
, Z
);
10070 eassert (BEGV
>= BEG
);
10071 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10073 rc
= fn (a1
, a2
, a3
, a4
);
10075 eassert (BEGV
>= BEG
);
10076 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10078 unbind_to (count
, Qnil
);
10083 /* Save state that should be preserved around the call to the function
10084 FN called in with_echo_area_buffer. */
10087 with_echo_area_buffer_unwind_data (struct window
*w
)
10090 Lisp_Object vector
, tmp
;
10092 /* Reduce consing by keeping one vector in
10093 Vwith_echo_area_save_vector. */
10094 vector
= Vwith_echo_area_save_vector
;
10095 Vwith_echo_area_save_vector
= Qnil
;
10098 vector
= Fmake_vector (make_number (7), Qnil
);
10100 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10101 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10102 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10106 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10107 ASET (vector
, i
, w
->buffer
); ++i
;
10108 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10109 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10114 for (; i
< end
; ++i
)
10115 ASET (vector
, i
, Qnil
);
10118 eassert (i
== ASIZE (vector
));
10123 /* Restore global state from VECTOR which was created by
10124 with_echo_area_buffer_unwind_data. */
10127 unwind_with_echo_area_buffer (Lisp_Object vector
)
10129 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10130 Vdeactivate_mark
= AREF (vector
, 1);
10131 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10133 if (WINDOWP (AREF (vector
, 3)))
10136 Lisp_Object buffer
, charpos
, bytepos
;
10138 w
= XWINDOW (AREF (vector
, 3));
10139 buffer
= AREF (vector
, 4);
10140 charpos
= AREF (vector
, 5);
10141 bytepos
= AREF (vector
, 6);
10143 wset_buffer (w
, buffer
);
10144 set_marker_both (w
->pointm
, buffer
,
10145 XFASTINT (charpos
), XFASTINT (bytepos
));
10148 Vwith_echo_area_save_vector
= vector
;
10153 /* Set up the echo area for use by print functions. MULTIBYTE_P
10154 non-zero means we will print multibyte. */
10157 setup_echo_area_for_printing (int multibyte_p
)
10159 /* If we can't find an echo area any more, exit. */
10160 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10161 Fkill_emacs (Qnil
);
10163 ensure_echo_area_buffers ();
10165 if (!message_buf_print
)
10167 /* A message has been output since the last time we printed.
10168 Choose a fresh echo area buffer. */
10169 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10170 echo_area_buffer
[0] = echo_buffer
[1];
10172 echo_area_buffer
[0] = echo_buffer
[0];
10174 /* Switch to that buffer and clear it. */
10175 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10176 bset_truncate_lines (current_buffer
, Qnil
);
10180 ptrdiff_t count
= SPECPDL_INDEX ();
10181 specbind (Qinhibit_read_only
, Qt
);
10182 /* Note that undo recording is always disabled. */
10183 del_range (BEG
, Z
);
10184 unbind_to (count
, Qnil
);
10186 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10188 /* Set up the buffer for the multibyteness we need. */
10190 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10191 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10193 /* Raise the frame containing the echo area. */
10194 if (minibuffer_auto_raise
)
10196 struct frame
*sf
= SELECTED_FRAME ();
10197 Lisp_Object mini_window
;
10198 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10199 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10202 message_log_maybe_newline ();
10203 message_buf_print
= 1;
10207 if (NILP (echo_area_buffer
[0]))
10209 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10210 echo_area_buffer
[0] = echo_buffer
[1];
10212 echo_area_buffer
[0] = echo_buffer
[0];
10215 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10217 /* Someone switched buffers between print requests. */
10218 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10219 bset_truncate_lines (current_buffer
, Qnil
);
10225 /* Display an echo area message in window W. Value is non-zero if W's
10226 height is changed. If display_last_displayed_message_p is
10227 non-zero, display the message that was last displayed, otherwise
10228 display the current message. */
10231 display_echo_area (struct window
*w
)
10233 int i
, no_message_p
, window_height_changed_p
;
10235 /* Temporarily disable garbage collections while displaying the echo
10236 area. This is done because a GC can print a message itself.
10237 That message would modify the echo area buffer's contents while a
10238 redisplay of the buffer is going on, and seriously confuse
10240 ptrdiff_t count
= inhibit_garbage_collection ();
10242 /* If there is no message, we must call display_echo_area_1
10243 nevertheless because it resizes the window. But we will have to
10244 reset the echo_area_buffer in question to nil at the end because
10245 with_echo_area_buffer will sets it to an empty buffer. */
10246 i
= display_last_displayed_message_p
? 1 : 0;
10247 no_message_p
= NILP (echo_area_buffer
[i
]);
10249 window_height_changed_p
10250 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10251 display_echo_area_1
,
10252 (intptr_t) w
, Qnil
, 0, 0);
10255 echo_area_buffer
[i
] = Qnil
;
10257 unbind_to (count
, Qnil
);
10258 return window_height_changed_p
;
10262 /* Helper for display_echo_area. Display the current buffer which
10263 contains the current echo area message in window W, a mini-window,
10264 a pointer to which is passed in A1. A2..A4 are currently not used.
10265 Change the height of W so that all of the message is displayed.
10266 Value is non-zero if height of W was changed. */
10269 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10272 struct window
*w
= (struct window
*) i1
;
10273 Lisp_Object window
;
10274 struct text_pos start
;
10275 int window_height_changed_p
= 0;
10277 /* Do this before displaying, so that we have a large enough glyph
10278 matrix for the display. If we can't get enough space for the
10279 whole text, display the last N lines. That works by setting w->start. */
10280 window_height_changed_p
= resize_mini_window (w
, 0);
10282 /* Use the starting position chosen by resize_mini_window. */
10283 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10286 clear_glyph_matrix (w
->desired_matrix
);
10287 XSETWINDOW (window
, w
);
10288 try_window (window
, start
, 0);
10290 return window_height_changed_p
;
10294 /* Resize the echo area window to exactly the size needed for the
10295 currently displayed message, if there is one. If a mini-buffer
10296 is active, don't shrink it. */
10299 resize_echo_area_exactly (void)
10301 if (BUFFERP (echo_area_buffer
[0])
10302 && WINDOWP (echo_area_window
))
10304 struct window
*w
= XWINDOW (echo_area_window
);
10306 Lisp_Object resize_exactly
;
10308 if (minibuf_level
== 0)
10309 resize_exactly
= Qt
;
10311 resize_exactly
= Qnil
;
10313 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10314 (intptr_t) w
, resize_exactly
,
10318 ++windows_or_buffers_changed
;
10319 ++update_mode_lines
;
10320 redisplay_internal ();
10326 /* Callback function for with_echo_area_buffer, when used from
10327 resize_echo_area_exactly. A1 contains a pointer to the window to
10328 resize, EXACTLY non-nil means resize the mini-window exactly to the
10329 size of the text displayed. A3 and A4 are not used. Value is what
10330 resize_mini_window returns. */
10333 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
, ptrdiff_t a3
, ptrdiff_t a4
)
10336 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10340 /* Resize mini-window W to fit the size of its contents. EXACT_P
10341 means size the window exactly to the size needed. Otherwise, it's
10342 only enlarged until W's buffer is empty.
10344 Set W->start to the right place to begin display. If the whole
10345 contents fit, start at the beginning. Otherwise, start so as
10346 to make the end of the contents appear. This is particularly
10347 important for y-or-n-p, but seems desirable generally.
10349 Value is non-zero if the window height has been changed. */
10352 resize_mini_window (struct window
*w
, int exact_p
)
10354 struct frame
*f
= XFRAME (w
->frame
);
10355 int window_height_changed_p
= 0;
10357 eassert (MINI_WINDOW_P (w
));
10359 /* By default, start display at the beginning. */
10360 set_marker_both (w
->start
, w
->buffer
,
10361 BUF_BEGV (XBUFFER (w
->buffer
)),
10362 BUF_BEGV_BYTE (XBUFFER (w
->buffer
)));
10364 /* Don't resize windows while redisplaying a window; it would
10365 confuse redisplay functions when the size of the window they are
10366 displaying changes from under them. Such a resizing can happen,
10367 for instance, when which-func prints a long message while
10368 we are running fontification-functions. We're running these
10369 functions with safe_call which binds inhibit-redisplay to t. */
10370 if (!NILP (Vinhibit_redisplay
))
10373 /* Nil means don't try to resize. */
10374 if (NILP (Vresize_mini_windows
)
10375 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10378 if (!FRAME_MINIBUF_ONLY_P (f
))
10381 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10382 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10384 EMACS_INT max_height
;
10385 int unit
= FRAME_LINE_HEIGHT (f
);
10386 struct text_pos start
;
10387 struct buffer
*old_current_buffer
= NULL
;
10389 if (current_buffer
!= XBUFFER (w
->buffer
))
10391 old_current_buffer
= current_buffer
;
10392 set_buffer_internal (XBUFFER (w
->buffer
));
10395 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10397 /* Compute the max. number of lines specified by the user. */
10398 if (FLOATP (Vmax_mini_window_height
))
10399 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10400 else if (INTEGERP (Vmax_mini_window_height
))
10401 max_height
= XINT (Vmax_mini_window_height
);
10403 max_height
= total_height
/ 4;
10405 /* Correct that max. height if it's bogus. */
10406 max_height
= clip_to_bounds (1, max_height
, total_height
);
10408 /* Find out the height of the text in the window. */
10409 if (it
.line_wrap
== TRUNCATE
)
10414 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10415 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10416 height
= it
.current_y
+ last_height
;
10418 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10419 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10420 height
= (height
+ unit
- 1) / unit
;
10423 /* Compute a suitable window start. */
10424 if (height
> max_height
)
10426 height
= max_height
;
10427 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10428 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10429 start
= it
.current
.pos
;
10432 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10433 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10435 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10437 /* Let it grow only, until we display an empty message, in which
10438 case the window shrinks again. */
10439 if (height
> WINDOW_TOTAL_LINES (w
))
10441 int old_height
= WINDOW_TOTAL_LINES (w
);
10442 freeze_window_starts (f
, 1);
10443 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10444 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10446 else if (height
< WINDOW_TOTAL_LINES (w
)
10447 && (exact_p
|| BEGV
== ZV
))
10449 int old_height
= WINDOW_TOTAL_LINES (w
);
10450 freeze_window_starts (f
, 0);
10451 shrink_mini_window (w
);
10452 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10457 /* Always resize to exact size needed. */
10458 if (height
> WINDOW_TOTAL_LINES (w
))
10460 int old_height
= WINDOW_TOTAL_LINES (w
);
10461 freeze_window_starts (f
, 1);
10462 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10463 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10465 else if (height
< WINDOW_TOTAL_LINES (w
))
10467 int old_height
= WINDOW_TOTAL_LINES (w
);
10468 freeze_window_starts (f
, 0);
10469 shrink_mini_window (w
);
10473 freeze_window_starts (f
, 1);
10474 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10477 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10481 if (old_current_buffer
)
10482 set_buffer_internal (old_current_buffer
);
10485 return window_height_changed_p
;
10489 /* Value is the current message, a string, or nil if there is no
10490 current message. */
10493 current_message (void)
10497 if (!BUFFERP (echo_area_buffer
[0]))
10501 with_echo_area_buffer (0, 0, current_message_1
,
10502 (intptr_t) &msg
, Qnil
, 0, 0);
10504 echo_area_buffer
[0] = Qnil
;
10512 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10515 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10518 *msg
= make_buffer_string (BEG
, Z
, 1);
10525 /* Push the current message on Vmessage_stack for later restoration
10526 by restore_message. Value is non-zero if the current message isn't
10527 empty. This is a relatively infrequent operation, so it's not
10528 worth optimizing. */
10531 push_message (void)
10533 Lisp_Object msg
= current_message ();
10534 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10535 return STRINGP (msg
);
10539 /* Restore message display from the top of Vmessage_stack. */
10542 restore_message (void)
10546 eassert (CONSP (Vmessage_stack
));
10547 msg
= XCAR (Vmessage_stack
);
10549 message3_nolog (msg
, SBYTES (msg
), STRING_MULTIBYTE (msg
));
10551 message3_nolog (msg
, 0, 0);
10555 /* Handler for record_unwind_protect calling pop_message. */
10558 pop_message_unwind (Lisp_Object dummy
)
10564 /* Pop the top-most entry off Vmessage_stack. */
10569 eassert (CONSP (Vmessage_stack
));
10570 Vmessage_stack
= XCDR (Vmessage_stack
);
10574 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10575 exits. If the stack is not empty, we have a missing pop_message
10579 check_message_stack (void)
10581 if (!NILP (Vmessage_stack
))
10586 /* Truncate to NCHARS what will be displayed in the echo area the next
10587 time we display it---but don't redisplay it now. */
10590 truncate_echo_area (ptrdiff_t nchars
)
10593 echo_area_buffer
[0] = Qnil
;
10594 /* A null message buffer means that the frame hasn't really been
10595 initialized yet. Error messages get reported properly by
10596 cmd_error, so this must be just an informative message; toss it. */
10597 else if (!noninteractive
10599 && !NILP (echo_area_buffer
[0]))
10601 struct frame
*sf
= SELECTED_FRAME ();
10602 if (FRAME_MESSAGE_BUF (sf
))
10603 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
, 0, 0);
10608 /* Helper function for truncate_echo_area. Truncate the current
10609 message to at most NCHARS characters. */
10612 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
, ptrdiff_t a3
, ptrdiff_t a4
)
10614 if (BEG
+ nchars
< Z
)
10615 del_range (BEG
+ nchars
, Z
);
10617 echo_area_buffer
[0] = Qnil
;
10621 /* Set the current message to a substring of S or STRING.
10623 If STRING is a Lisp string, set the message to the first NBYTES
10624 bytes from STRING. NBYTES zero means use the whole string. If
10625 STRING is multibyte, the message will be displayed multibyte.
10627 If S is not null, set the message to the first LEN bytes of S. LEN
10628 zero means use the whole string. MULTIBYTE_P non-zero means S is
10629 multibyte. Display the message multibyte in that case.
10631 Doesn't GC, as with_echo_area_buffer binds Qinhibit_modification_hooks
10632 to t before calling set_message_1 (which calls insert).
10636 set_message (const char *s
, Lisp_Object string
,
10637 ptrdiff_t nbytes
, int multibyte_p
)
10639 message_enable_multibyte
10640 = ((s
&& multibyte_p
)
10641 || (STRINGP (string
) && STRING_MULTIBYTE (string
)));
10643 with_echo_area_buffer (0, -1, set_message_1
,
10644 (intptr_t) s
, string
, nbytes
, multibyte_p
);
10645 message_buf_print
= 0;
10646 help_echo_showing_p
= 0;
10648 if (STRINGP (Vdebug_on_message
)
10649 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10650 call_debugger (list2 (Qerror
, string
));
10654 /* Helper function for set_message. Arguments have the same meaning
10655 as there, with A1 corresponding to S and A2 corresponding to STRING
10656 This function is called with the echo area buffer being
10660 set_message_1 (ptrdiff_t a1
, Lisp_Object a2
, ptrdiff_t nbytes
, ptrdiff_t multibyte_p
)
10663 const char *s
= (const char *) i1
;
10664 const unsigned char *msg
= (const unsigned char *) s
;
10665 Lisp_Object string
= a2
;
10667 /* Change multibyteness of the echo buffer appropriately. */
10668 if (message_enable_multibyte
10669 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10670 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10672 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10673 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10674 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10676 /* Insert new message at BEG. */
10677 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10679 if (STRINGP (string
))
10684 nbytes
= SBYTES (string
);
10685 nchars
= string_byte_to_char (string
, nbytes
);
10687 /* This function takes care of single/multibyte conversion. We
10688 just have to ensure that the echo area buffer has the right
10689 setting of enable_multibyte_characters. */
10690 insert_from_string (string
, 0, 0, nchars
, nbytes
, 1);
10695 nbytes
= strlen (s
);
10697 if (multibyte_p
&& NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10699 /* Convert from multi-byte to single-byte. */
10704 /* Convert a multibyte string to single-byte. */
10705 for (i
= 0; i
< nbytes
; i
+= n
)
10707 c
= string_char_and_length (msg
+ i
, &n
);
10708 work
[0] = (ASCII_CHAR_P (c
)
10710 : multibyte_char_to_unibyte (c
));
10711 insert_1_both (work
, 1, 1, 1, 0, 0);
10714 else if (!multibyte_p
10715 && !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10717 /* Convert from single-byte to multi-byte. */
10720 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
10722 /* Convert a single-byte string to multibyte. */
10723 for (i
= 0; i
< nbytes
; i
++)
10726 MAKE_CHAR_MULTIBYTE (c
);
10727 n
= CHAR_STRING (c
, str
);
10728 insert_1_both ((char *) str
, 1, n
, 1, 0, 0);
10732 insert_1 (s
, nbytes
, 1, 0, 0);
10739 /* Clear messages. CURRENT_P non-zero means clear the current
10740 message. LAST_DISPLAYED_P non-zero means clear the message
10744 clear_message (int current_p
, int last_displayed_p
)
10748 echo_area_buffer
[0] = Qnil
;
10749 message_cleared_p
= 1;
10752 if (last_displayed_p
)
10753 echo_area_buffer
[1] = Qnil
;
10755 message_buf_print
= 0;
10758 /* Clear garbaged frames.
10760 This function is used where the old redisplay called
10761 redraw_garbaged_frames which in turn called redraw_frame which in
10762 turn called clear_frame. The call to clear_frame was a source of
10763 flickering. I believe a clear_frame is not necessary. It should
10764 suffice in the new redisplay to invalidate all current matrices,
10765 and ensure a complete redisplay of all windows. */
10768 clear_garbaged_frames (void)
10770 if (frame_garbaged
)
10772 Lisp_Object tail
, frame
;
10773 int changed_count
= 0;
10775 FOR_EACH_FRAME (tail
, frame
)
10777 struct frame
*f
= XFRAME (frame
);
10779 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10784 f
->force_flush_display_p
= 1;
10786 clear_current_matrices (f
);
10793 frame_garbaged
= 0;
10795 ++windows_or_buffers_changed
;
10800 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10801 is non-zero update selected_frame. Value is non-zero if the
10802 mini-windows height has been changed. */
10805 echo_area_display (int update_frame_p
)
10807 Lisp_Object mini_window
;
10810 int window_height_changed_p
= 0;
10811 struct frame
*sf
= SELECTED_FRAME ();
10813 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10814 w
= XWINDOW (mini_window
);
10815 f
= XFRAME (WINDOW_FRAME (w
));
10817 /* Don't display if frame is invisible or not yet initialized. */
10818 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10821 #ifdef HAVE_WINDOW_SYSTEM
10822 /* When Emacs starts, selected_frame may be the initial terminal
10823 frame. If we let this through, a message would be displayed on
10825 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10827 #endif /* HAVE_WINDOW_SYSTEM */
10829 /* Redraw garbaged frames. */
10830 clear_garbaged_frames ();
10832 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10834 echo_area_window
= mini_window
;
10835 window_height_changed_p
= display_echo_area (w
);
10836 w
->must_be_updated_p
= 1;
10838 /* Update the display, unless called from redisplay_internal.
10839 Also don't update the screen during redisplay itself. The
10840 update will happen at the end of redisplay, and an update
10841 here could cause confusion. */
10842 if (update_frame_p
&& !redisplaying_p
)
10846 /* If the display update has been interrupted by pending
10847 input, update mode lines in the frame. Due to the
10848 pending input, it might have been that redisplay hasn't
10849 been called, so that mode lines above the echo area are
10850 garbaged. This looks odd, so we prevent it here. */
10851 if (!display_completed
)
10852 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10854 if (window_height_changed_p
10855 /* Don't do this if Emacs is shutting down. Redisplay
10856 needs to run hooks. */
10857 && !NILP (Vrun_hooks
))
10859 /* Must update other windows. Likewise as in other
10860 cases, don't let this update be interrupted by
10862 ptrdiff_t count
= SPECPDL_INDEX ();
10863 specbind (Qredisplay_dont_pause
, Qt
);
10864 windows_or_buffers_changed
= 1;
10865 redisplay_internal ();
10866 unbind_to (count
, Qnil
);
10868 else if (FRAME_WINDOW_P (f
) && n
== 0)
10870 /* Window configuration is the same as before.
10871 Can do with a display update of the echo area,
10872 unless we displayed some mode lines. */
10873 update_single_window (w
, 1);
10874 FRAME_RIF (f
)->flush_display (f
);
10877 update_frame (f
, 1, 1);
10879 /* If cursor is in the echo area, make sure that the next
10880 redisplay displays the minibuffer, so that the cursor will
10881 be replaced with what the minibuffer wants. */
10882 if (cursor_in_echo_area
)
10883 ++windows_or_buffers_changed
;
10886 else if (!EQ (mini_window
, selected_window
))
10887 windows_or_buffers_changed
++;
10889 /* Last displayed message is now the current message. */
10890 echo_area_buffer
[1] = echo_area_buffer
[0];
10891 /* Inform read_char that we're not echoing. */
10892 echo_message_buffer
= Qnil
;
10894 /* Prevent redisplay optimization in redisplay_internal by resetting
10895 this_line_start_pos. This is done because the mini-buffer now
10896 displays the message instead of its buffer text. */
10897 if (EQ (mini_window
, selected_window
))
10898 CHARPOS (this_line_start_pos
) = 0;
10900 return window_height_changed_p
;
10903 /* Nonzero if the current window's buffer is shown in more than one
10904 window and was modified since last redisplay. */
10907 buffer_shared_and_changed (void)
10909 return (buffer_window_count (current_buffer
) > 1
10910 && UNCHANGED_MODIFIED
< MODIFF
);
10913 /* Nonzero if W doesn't reflect the actual state of current buffer due
10914 to its text or overlays change. FIXME: this may be called when
10915 XBUFFER (w->buffer) != current_buffer, which looks suspicious. */
10918 window_outdated (struct window
*w
)
10920 return (w
->last_modified
< MODIFF
10921 || w
->last_overlay_modified
< OVERLAY_MODIFF
);
10924 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10925 is enabled and mark of W's buffer was changed since last W's update. */
10928 window_buffer_changed (struct window
*w
)
10930 struct buffer
*b
= XBUFFER (w
->buffer
);
10932 eassert (BUFFER_LIVE_P (b
));
10934 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10935 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10936 != !NILP (w
->region_showing
)));
10939 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10942 mode_line_update_needed (struct window
*w
)
10944 return (!NILP (w
->column_number_displayed
)
10945 && !(PT
== w
->last_point
&& !window_outdated (w
))
10946 && (XFASTINT (w
->column_number_displayed
) != current_column ()));
10949 /***********************************************************************
10950 Mode Lines and Frame Titles
10951 ***********************************************************************/
10953 /* A buffer for constructing non-propertized mode-line strings and
10954 frame titles in it; allocated from the heap in init_xdisp and
10955 resized as needed in store_mode_line_noprop_char. */
10957 static char *mode_line_noprop_buf
;
10959 /* The buffer's end, and a current output position in it. */
10961 static char *mode_line_noprop_buf_end
;
10962 static char *mode_line_noprop_ptr
;
10964 #define MODE_LINE_NOPROP_LEN(start) \
10965 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10968 MODE_LINE_DISPLAY
= 0,
10972 } mode_line_target
;
10974 /* Alist that caches the results of :propertize.
10975 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10976 static Lisp_Object mode_line_proptrans_alist
;
10978 /* List of strings making up the mode-line. */
10979 static Lisp_Object mode_line_string_list
;
10981 /* Base face property when building propertized mode line string. */
10982 static Lisp_Object mode_line_string_face
;
10983 static Lisp_Object mode_line_string_face_prop
;
10986 /* Unwind data for mode line strings */
10988 static Lisp_Object Vmode_line_unwind_vector
;
10991 format_mode_line_unwind_data (struct frame
*target_frame
,
10992 struct buffer
*obuf
,
10994 int save_proptrans
)
10996 Lisp_Object vector
, tmp
;
10998 /* Reduce consing by keeping one vector in
10999 Vwith_echo_area_save_vector. */
11000 vector
= Vmode_line_unwind_vector
;
11001 Vmode_line_unwind_vector
= Qnil
;
11004 vector
= Fmake_vector (make_number (10), Qnil
);
11006 ASET (vector
, 0, make_number (mode_line_target
));
11007 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11008 ASET (vector
, 2, mode_line_string_list
);
11009 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11010 ASET (vector
, 4, mode_line_string_face
);
11011 ASET (vector
, 5, mode_line_string_face_prop
);
11014 XSETBUFFER (tmp
, obuf
);
11017 ASET (vector
, 6, tmp
);
11018 ASET (vector
, 7, owin
);
11021 /* Similarly to `with-selected-window', if the operation selects
11022 a window on another frame, we must restore that frame's
11023 selected window, and (for a tty) the top-frame. */
11024 ASET (vector
, 8, target_frame
->selected_window
);
11025 if (FRAME_TERMCAP_P (target_frame
))
11026 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11033 unwind_format_mode_line (Lisp_Object vector
)
11035 Lisp_Object old_window
= AREF (vector
, 7);
11036 Lisp_Object target_frame_window
= AREF (vector
, 8);
11037 Lisp_Object old_top_frame
= AREF (vector
, 9);
11039 mode_line_target
= XINT (AREF (vector
, 0));
11040 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11041 mode_line_string_list
= AREF (vector
, 2);
11042 if (! EQ (AREF (vector
, 3), Qt
))
11043 mode_line_proptrans_alist
= AREF (vector
, 3);
11044 mode_line_string_face
= AREF (vector
, 4);
11045 mode_line_string_face_prop
= AREF (vector
, 5);
11047 /* Select window before buffer, since it may change the buffer. */
11048 if (!NILP (old_window
))
11050 /* If the operation that we are unwinding had selected a window
11051 on a different frame, reset its frame-selected-window. For a
11052 text terminal, reset its top-frame if necessary. */
11053 if (!NILP (target_frame_window
))
11056 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11058 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11059 Fselect_window (target_frame_window
, Qt
);
11061 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11062 Fselect_frame (old_top_frame
, Qt
);
11065 Fselect_window (old_window
, Qt
);
11068 if (!NILP (AREF (vector
, 6)))
11070 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11071 ASET (vector
, 6, Qnil
);
11074 Vmode_line_unwind_vector
= vector
;
11079 /* Store a single character C for the frame title in mode_line_noprop_buf.
11080 Re-allocate mode_line_noprop_buf if necessary. */
11083 store_mode_line_noprop_char (char c
)
11085 /* If output position has reached the end of the allocated buffer,
11086 increase the buffer's size. */
11087 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11089 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11090 ptrdiff_t size
= len
;
11091 mode_line_noprop_buf
=
11092 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11093 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11094 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11097 *mode_line_noprop_ptr
++ = c
;
11101 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11102 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11103 characters that yield more columns than PRECISION; PRECISION <= 0
11104 means copy the whole string. Pad with spaces until FIELD_WIDTH
11105 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11106 pad. Called from display_mode_element when it is used to build a
11110 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11112 const unsigned char *str
= (const unsigned char *) string
;
11114 ptrdiff_t dummy
, nbytes
;
11116 /* Copy at most PRECISION chars from STR. */
11117 nbytes
= strlen (string
);
11118 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11120 store_mode_line_noprop_char (*str
++);
11122 /* Fill up with spaces until FIELD_WIDTH reached. */
11123 while (field_width
> 0
11124 && n
< field_width
)
11126 store_mode_line_noprop_char (' ');
11133 /***********************************************************************
11135 ***********************************************************************/
11137 #ifdef HAVE_WINDOW_SYSTEM
11139 /* Set the title of FRAME, if it has changed. The title format is
11140 Vicon_title_format if FRAME is iconified, otherwise it is
11141 frame_title_format. */
11144 x_consider_frame_title (Lisp_Object frame
)
11146 struct frame
*f
= XFRAME (frame
);
11148 if (FRAME_WINDOW_P (f
)
11149 || FRAME_MINIBUF_ONLY_P (f
)
11150 || f
->explicit_name
)
11152 /* Do we have more than one visible frame on this X display? */
11153 Lisp_Object tail
, other_frame
, fmt
;
11154 ptrdiff_t title_start
;
11158 ptrdiff_t count
= SPECPDL_INDEX ();
11160 FOR_EACH_FRAME (tail
, other_frame
)
11162 struct frame
*tf
= XFRAME (other_frame
);
11165 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11166 && !FRAME_MINIBUF_ONLY_P (tf
)
11167 && !EQ (other_frame
, tip_frame
)
11168 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11172 /* Set global variable indicating that multiple frames exist. */
11173 multiple_frames
= CONSP (tail
);
11175 /* Switch to the buffer of selected window of the frame. Set up
11176 mode_line_target so that display_mode_element will output into
11177 mode_line_noprop_buf; then display the title. */
11178 record_unwind_protect (unwind_format_mode_line
,
11179 format_mode_line_unwind_data
11180 (f
, current_buffer
, selected_window
, 0));
11182 Fselect_window (f
->selected_window
, Qt
);
11183 set_buffer_internal_1
11184 (XBUFFER (XWINDOW (f
->selected_window
)->buffer
));
11185 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11187 mode_line_target
= MODE_LINE_TITLE
;
11188 title_start
= MODE_LINE_NOPROP_LEN (0);
11189 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11190 NULL
, DEFAULT_FACE_ID
);
11191 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11192 len
= MODE_LINE_NOPROP_LEN (title_start
);
11193 title
= mode_line_noprop_buf
+ title_start
;
11194 unbind_to (count
, Qnil
);
11196 /* Set the title only if it's changed. This avoids consing in
11197 the common case where it hasn't. (If it turns out that we've
11198 already wasted too much time by walking through the list with
11199 display_mode_element, then we might need to optimize at a
11200 higher level than this.) */
11201 if (! STRINGP (f
->name
)
11202 || SBYTES (f
->name
) != len
11203 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11204 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11208 #endif /* not HAVE_WINDOW_SYSTEM */
11211 /***********************************************************************
11213 ***********************************************************************/
11216 /* Prepare for redisplay by updating menu-bar item lists when
11217 appropriate. This can call eval. */
11220 prepare_menu_bars (void)
11223 struct gcpro gcpro1
, gcpro2
;
11225 Lisp_Object tooltip_frame
;
11227 #ifdef HAVE_WINDOW_SYSTEM
11228 tooltip_frame
= tip_frame
;
11230 tooltip_frame
= Qnil
;
11233 /* Update all frame titles based on their buffer names, etc. We do
11234 this before the menu bars so that the buffer-menu will show the
11235 up-to-date frame titles. */
11236 #ifdef HAVE_WINDOW_SYSTEM
11237 if (windows_or_buffers_changed
|| update_mode_lines
)
11239 Lisp_Object tail
, frame
;
11241 FOR_EACH_FRAME (tail
, frame
)
11243 f
= XFRAME (frame
);
11244 if (!EQ (frame
, tooltip_frame
)
11245 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11246 x_consider_frame_title (frame
);
11249 #endif /* HAVE_WINDOW_SYSTEM */
11251 /* Update the menu bar item lists, if appropriate. This has to be
11252 done before any actual redisplay or generation of display lines. */
11253 all_windows
= (update_mode_lines
11254 || buffer_shared_and_changed ()
11255 || windows_or_buffers_changed
);
11258 Lisp_Object tail
, frame
;
11259 ptrdiff_t count
= SPECPDL_INDEX ();
11260 /* 1 means that update_menu_bar has run its hooks
11261 so any further calls to update_menu_bar shouldn't do so again. */
11262 int menu_bar_hooks_run
= 0;
11264 record_unwind_save_match_data ();
11266 FOR_EACH_FRAME (tail
, frame
)
11268 f
= XFRAME (frame
);
11270 /* Ignore tooltip frame. */
11271 if (EQ (frame
, tooltip_frame
))
11274 /* If a window on this frame changed size, report that to
11275 the user and clear the size-change flag. */
11276 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11278 Lisp_Object functions
;
11280 /* Clear flag first in case we get an error below. */
11281 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11282 functions
= Vwindow_size_change_functions
;
11283 GCPRO2 (tail
, functions
);
11285 while (CONSP (functions
))
11287 if (!EQ (XCAR (functions
), Qt
))
11288 call1 (XCAR (functions
), frame
);
11289 functions
= XCDR (functions
);
11295 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11296 #ifdef HAVE_WINDOW_SYSTEM
11297 update_tool_bar (f
, 0);
11300 if (windows_or_buffers_changed
11303 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->buffer
));
11308 unbind_to (count
, Qnil
);
11312 struct frame
*sf
= SELECTED_FRAME ();
11313 update_menu_bar (sf
, 1, 0);
11314 #ifdef HAVE_WINDOW_SYSTEM
11315 update_tool_bar (sf
, 1);
11321 /* Update the menu bar item list for frame F. This has to be done
11322 before we start to fill in any display lines, because it can call
11325 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11327 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11328 already ran the menu bar hooks for this redisplay, so there
11329 is no need to run them again. The return value is the
11330 updated value of this flag, to pass to the next call. */
11333 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11335 Lisp_Object window
;
11336 register struct window
*w
;
11338 /* If called recursively during a menu update, do nothing. This can
11339 happen when, for instance, an activate-menubar-hook causes a
11341 if (inhibit_menubar_update
)
11344 window
= FRAME_SELECTED_WINDOW (f
);
11345 w
= XWINDOW (window
);
11347 if (FRAME_WINDOW_P (f
)
11349 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11350 || defined (HAVE_NS) || defined (USE_GTK)
11351 FRAME_EXTERNAL_MENU_BAR (f
)
11353 FRAME_MENU_BAR_LINES (f
) > 0
11355 : FRAME_MENU_BAR_LINES (f
) > 0)
11357 /* If the user has switched buffers or windows, we need to
11358 recompute to reflect the new bindings. But we'll
11359 recompute when update_mode_lines is set too; that means
11360 that people can use force-mode-line-update to request
11361 that the menu bar be recomputed. The adverse effect on
11362 the rest of the redisplay algorithm is about the same as
11363 windows_or_buffers_changed anyway. */
11364 if (windows_or_buffers_changed
11365 /* This used to test w->update_mode_line, but we believe
11366 there is no need to recompute the menu in that case. */
11367 || update_mode_lines
11368 || window_buffer_changed (w
))
11370 struct buffer
*prev
= current_buffer
;
11371 ptrdiff_t count
= SPECPDL_INDEX ();
11373 specbind (Qinhibit_menubar_update
, Qt
);
11375 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11376 if (save_match_data
)
11377 record_unwind_save_match_data ();
11378 if (NILP (Voverriding_local_map_menu_flag
))
11380 specbind (Qoverriding_terminal_local_map
, Qnil
);
11381 specbind (Qoverriding_local_map
, Qnil
);
11386 /* Run the Lucid hook. */
11387 safe_run_hooks (Qactivate_menubar_hook
);
11389 /* If it has changed current-menubar from previous value,
11390 really recompute the menu-bar from the value. */
11391 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11392 call0 (Qrecompute_lucid_menubar
);
11394 safe_run_hooks (Qmenu_bar_update_hook
);
11399 XSETFRAME (Vmenu_updating_frame
, f
);
11400 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11402 /* Redisplay the menu bar in case we changed it. */
11403 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11404 || defined (HAVE_NS) || defined (USE_GTK)
11405 if (FRAME_WINDOW_P (f
))
11407 #if defined (HAVE_NS)
11408 /* All frames on Mac OS share the same menubar. So only
11409 the selected frame should be allowed to set it. */
11410 if (f
== SELECTED_FRAME ())
11412 set_frame_menubar (f
, 0, 0);
11415 /* On a terminal screen, the menu bar is an ordinary screen
11416 line, and this makes it get updated. */
11417 w
->update_mode_line
= 1;
11418 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11419 /* In the non-toolkit version, the menu bar is an ordinary screen
11420 line, and this makes it get updated. */
11421 w
->update_mode_line
= 1;
11422 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11424 unbind_to (count
, Qnil
);
11425 set_buffer_internal_1 (prev
);
11434 /***********************************************************************
11436 ***********************************************************************/
11438 #ifdef HAVE_WINDOW_SYSTEM
11441 Nominal cursor position -- where to draw output.
11442 HPOS and VPOS are window relative glyph matrix coordinates.
11443 X and Y are window relative pixel coordinates. */
11445 struct cursor_pos output_cursor
;
11449 Set the global variable output_cursor to CURSOR. All cursor
11450 positions are relative to updated_window. */
11453 set_output_cursor (struct cursor_pos
*cursor
)
11455 output_cursor
.hpos
= cursor
->hpos
;
11456 output_cursor
.vpos
= cursor
->vpos
;
11457 output_cursor
.x
= cursor
->x
;
11458 output_cursor
.y
= cursor
->y
;
11463 Set a nominal cursor position.
11465 HPOS and VPOS are column/row positions in a window glyph matrix. X
11466 and Y are window text area relative pixel positions.
11468 If this is done during an update, updated_window will contain the
11469 window that is being updated and the position is the future output
11470 cursor position for that window. If updated_window is null, use
11471 selected_window and display the cursor at the given position. */
11474 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11478 /* If updated_window is not set, work on selected_window. */
11479 if (updated_window
)
11480 w
= updated_window
;
11482 w
= XWINDOW (selected_window
);
11484 /* Set the output cursor. */
11485 output_cursor
.hpos
= hpos
;
11486 output_cursor
.vpos
= vpos
;
11487 output_cursor
.x
= x
;
11488 output_cursor
.y
= y
;
11490 /* If not called as part of an update, really display the cursor.
11491 This will also set the cursor position of W. */
11492 if (updated_window
== NULL
)
11495 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11496 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11497 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11502 #endif /* HAVE_WINDOW_SYSTEM */
11505 /***********************************************************************
11507 ***********************************************************************/
11509 #ifdef HAVE_WINDOW_SYSTEM
11511 /* Where the mouse was last time we reported a mouse event. */
11513 FRAME_PTR last_mouse_frame
;
11515 /* Tool-bar item index of the item on which a mouse button was pressed
11518 int last_tool_bar_item
;
11520 /* Select `frame' temporarily without running all the code in
11522 FIXME: Maybe do_switch_frame should be trimmed down similarly
11523 when `norecord' is set. */
11525 fast_set_selected_frame (Lisp_Object frame
)
11527 if (!EQ (selected_frame
, frame
))
11529 selected_frame
= frame
;
11530 selected_window
= XFRAME (frame
)->selected_window
;
11535 /* Update the tool-bar item list for frame F. This has to be done
11536 before we start to fill in any display lines. Called from
11537 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11538 and restore it here. */
11541 update_tool_bar (struct frame
*f
, int save_match_data
)
11543 #if defined (USE_GTK) || defined (HAVE_NS)
11544 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11546 int do_update
= WINDOWP (f
->tool_bar_window
)
11547 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11552 Lisp_Object window
;
11555 window
= FRAME_SELECTED_WINDOW (f
);
11556 w
= XWINDOW (window
);
11558 /* If the user has switched buffers or windows, we need to
11559 recompute to reflect the new bindings. But we'll
11560 recompute when update_mode_lines is set too; that means
11561 that people can use force-mode-line-update to request
11562 that the menu bar be recomputed. The adverse effect on
11563 the rest of the redisplay algorithm is about the same as
11564 windows_or_buffers_changed anyway. */
11565 if (windows_or_buffers_changed
11566 || w
->update_mode_line
11567 || update_mode_lines
11568 || window_buffer_changed (w
))
11570 struct buffer
*prev
= current_buffer
;
11571 ptrdiff_t count
= SPECPDL_INDEX ();
11572 Lisp_Object frame
, new_tool_bar
;
11573 int new_n_tool_bar
;
11574 struct gcpro gcpro1
;
11576 /* Set current_buffer to the buffer of the selected
11577 window of the frame, so that we get the right local
11579 set_buffer_internal_1 (XBUFFER (w
->buffer
));
11581 /* Save match data, if we must. */
11582 if (save_match_data
)
11583 record_unwind_save_match_data ();
11585 /* Make sure that we don't accidentally use bogus keymaps. */
11586 if (NILP (Voverriding_local_map_menu_flag
))
11588 specbind (Qoverriding_terminal_local_map
, Qnil
);
11589 specbind (Qoverriding_local_map
, Qnil
);
11592 GCPRO1 (new_tool_bar
);
11594 /* We must temporarily set the selected frame to this frame
11595 before calling tool_bar_items, because the calculation of
11596 the tool-bar keymap uses the selected frame (see
11597 `tool-bar-make-keymap' in tool-bar.el). */
11598 eassert (EQ (selected_window
,
11599 /* Since we only explicitly preserve selected_frame,
11600 check that selected_window would be redundant. */
11601 XFRAME (selected_frame
)->selected_window
));
11602 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11603 XSETFRAME (frame
, f
);
11604 fast_set_selected_frame (frame
);
11606 /* Build desired tool-bar items from keymaps. */
11608 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11611 /* Redisplay the tool-bar if we changed it. */
11612 if (new_n_tool_bar
!= f
->n_tool_bar_items
11613 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11615 /* Redisplay that happens asynchronously due to an expose event
11616 may access f->tool_bar_items. Make sure we update both
11617 variables within BLOCK_INPUT so no such event interrupts. */
11619 fset_tool_bar_items (f
, new_tool_bar
);
11620 f
->n_tool_bar_items
= new_n_tool_bar
;
11621 w
->update_mode_line
= 1;
11627 unbind_to (count
, Qnil
);
11628 set_buffer_internal_1 (prev
);
11634 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11635 F's desired tool-bar contents. F->tool_bar_items must have
11636 been set up previously by calling prepare_menu_bars. */
11639 build_desired_tool_bar_string (struct frame
*f
)
11641 int i
, size
, size_needed
;
11642 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11643 Lisp_Object image
, plist
, props
;
11645 image
= plist
= props
= Qnil
;
11646 GCPRO3 (image
, plist
, props
);
11648 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11649 Otherwise, make a new string. */
11651 /* The size of the string we might be able to reuse. */
11652 size
= (STRINGP (f
->desired_tool_bar_string
)
11653 ? SCHARS (f
->desired_tool_bar_string
)
11656 /* We need one space in the string for each image. */
11657 size_needed
= f
->n_tool_bar_items
;
11659 /* Reuse f->desired_tool_bar_string, if possible. */
11660 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11661 fset_desired_tool_bar_string
11662 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11665 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11666 Fremove_text_properties (make_number (0), make_number (size
),
11667 props
, f
->desired_tool_bar_string
);
11670 /* Put a `display' property on the string for the images to display,
11671 put a `menu_item' property on tool-bar items with a value that
11672 is the index of the item in F's tool-bar item vector. */
11673 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11675 #define PROP(IDX) \
11676 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11678 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11679 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11680 int hmargin
, vmargin
, relief
, idx
, end
;
11682 /* If image is a vector, choose the image according to the
11684 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11685 if (VECTORP (image
))
11689 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11690 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11693 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11694 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11696 eassert (ASIZE (image
) >= idx
);
11697 image
= AREF (image
, idx
);
11702 /* Ignore invalid image specifications. */
11703 if (!valid_image_p (image
))
11706 /* Display the tool-bar button pressed, or depressed. */
11707 plist
= Fcopy_sequence (XCDR (image
));
11709 /* Compute margin and relief to draw. */
11710 relief
= (tool_bar_button_relief
>= 0
11711 ? tool_bar_button_relief
11712 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11713 hmargin
= vmargin
= relief
;
11715 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11716 INT_MAX
- max (hmargin
, vmargin
)))
11718 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11719 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11721 else if (CONSP (Vtool_bar_button_margin
))
11723 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11724 INT_MAX
- hmargin
))
11725 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11727 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11728 INT_MAX
- vmargin
))
11729 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11732 if (auto_raise_tool_bar_buttons_p
)
11734 /* Add a `:relief' property to the image spec if the item is
11738 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11745 /* If image is selected, display it pressed, i.e. with a
11746 negative relief. If it's not selected, display it with a
11748 plist
= Fplist_put (plist
, QCrelief
,
11750 ? make_number (-relief
)
11751 : make_number (relief
)));
11756 /* Put a margin around the image. */
11757 if (hmargin
|| vmargin
)
11759 if (hmargin
== vmargin
)
11760 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11762 plist
= Fplist_put (plist
, QCmargin
,
11763 Fcons (make_number (hmargin
),
11764 make_number (vmargin
)));
11767 /* If button is not enabled, and we don't have special images
11768 for the disabled state, make the image appear disabled by
11769 applying an appropriate algorithm to it. */
11770 if (!enabled_p
&& idx
< 0)
11771 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11773 /* Put a `display' text property on the string for the image to
11774 display. Put a `menu-item' property on the string that gives
11775 the start of this item's properties in the tool-bar items
11777 image
= Fcons (Qimage
, plist
);
11778 props
= list4 (Qdisplay
, image
,
11779 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11781 /* Let the last image hide all remaining spaces in the tool bar
11782 string. The string can be longer than needed when we reuse a
11783 previous string. */
11784 if (i
+ 1 == f
->n_tool_bar_items
)
11785 end
= SCHARS (f
->desired_tool_bar_string
);
11788 Fadd_text_properties (make_number (i
), make_number (end
),
11789 props
, f
->desired_tool_bar_string
);
11797 /* Display one line of the tool-bar of frame IT->f.
11799 HEIGHT specifies the desired height of the tool-bar line.
11800 If the actual height of the glyph row is less than HEIGHT, the
11801 row's height is increased to HEIGHT, and the icons are centered
11802 vertically in the new height.
11804 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11805 count a final empty row in case the tool-bar width exactly matches
11810 display_tool_bar_line (struct it
*it
, int height
)
11812 struct glyph_row
*row
= it
->glyph_row
;
11813 int max_x
= it
->last_visible_x
;
11814 struct glyph
*last
;
11816 prepare_desired_row (row
);
11817 row
->y
= it
->current_y
;
11819 /* Note that this isn't made use of if the face hasn't a box,
11820 so there's no need to check the face here. */
11821 it
->start_of_box_run_p
= 1;
11823 while (it
->current_x
< max_x
)
11825 int x
, n_glyphs_before
, i
, nglyphs
;
11826 struct it it_before
;
11828 /* Get the next display element. */
11829 if (!get_next_display_element (it
))
11831 /* Don't count empty row if we are counting needed tool-bar lines. */
11832 if (height
< 0 && !it
->hpos
)
11837 /* Produce glyphs. */
11838 n_glyphs_before
= row
->used
[TEXT_AREA
];
11841 PRODUCE_GLYPHS (it
);
11843 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11845 x
= it_before
.current_x
;
11846 while (i
< nglyphs
)
11848 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11850 if (x
+ glyph
->pixel_width
> max_x
)
11852 /* Glyph doesn't fit on line. Backtrack. */
11853 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11855 /* If this is the only glyph on this line, it will never fit on the
11856 tool-bar, so skip it. But ensure there is at least one glyph,
11857 so we don't accidentally disable the tool-bar. */
11858 if (n_glyphs_before
== 0
11859 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11865 x
+= glyph
->pixel_width
;
11869 /* Stop at line end. */
11870 if (ITERATOR_AT_END_OF_LINE_P (it
))
11873 set_iterator_to_next (it
, 1);
11878 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11880 /* Use default face for the border below the tool bar.
11882 FIXME: When auto-resize-tool-bars is grow-only, there is
11883 no additional border below the possibly empty tool-bar lines.
11884 So to make the extra empty lines look "normal", we have to
11885 use the tool-bar face for the border too. */
11886 if (!row
->displays_text_p
&& !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11887 it
->face_id
= DEFAULT_FACE_ID
;
11889 extend_face_to_end_of_line (it
);
11890 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11891 last
->right_box_line_p
= 1;
11892 if (last
== row
->glyphs
[TEXT_AREA
])
11893 last
->left_box_line_p
= 1;
11895 /* Make line the desired height and center it vertically. */
11896 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11898 /* Don't add more than one line height. */
11899 height
%= FRAME_LINE_HEIGHT (it
->f
);
11900 it
->max_ascent
+= height
/ 2;
11901 it
->max_descent
+= (height
+ 1) / 2;
11904 compute_line_metrics (it
);
11906 /* If line is empty, make it occupy the rest of the tool-bar. */
11907 if (!row
->displays_text_p
)
11909 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11910 row
->visible_height
= row
->height
;
11911 row
->ascent
= row
->phys_ascent
= 0;
11912 row
->extra_line_spacing
= 0;
11915 row
->full_width_p
= 1;
11916 row
->continued_p
= 0;
11917 row
->truncated_on_left_p
= 0;
11918 row
->truncated_on_right_p
= 0;
11920 it
->current_x
= it
->hpos
= 0;
11921 it
->current_y
+= row
->height
;
11927 /* Max tool-bar height. */
11929 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11930 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11932 /* Value is the number of screen lines needed to make all tool-bar
11933 items of frame F visible. The number of actual rows needed is
11934 returned in *N_ROWS if non-NULL. */
11937 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11939 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11941 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11942 the desired matrix, so use (unused) mode-line row as temporary row to
11943 avoid destroying the first tool-bar row. */
11944 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11946 /* Initialize an iterator for iteration over
11947 F->desired_tool_bar_string in the tool-bar window of frame F. */
11948 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11949 it
.first_visible_x
= 0;
11950 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11951 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11952 it
.paragraph_embedding
= L2R
;
11954 while (!ITERATOR_AT_END_P (&it
))
11956 clear_glyph_row (temp_row
);
11957 it
.glyph_row
= temp_row
;
11958 display_tool_bar_line (&it
, -1);
11960 clear_glyph_row (temp_row
);
11962 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11964 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11966 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11970 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11972 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11973 If FRAME is nil or omitted, use the selected frame. */)
11974 (Lisp_Object frame
)
11976 struct frame
*f
= decode_any_frame (frame
);
11980 if (WINDOWP (f
->tool_bar_window
)
11981 && (w
= XWINDOW (f
->tool_bar_window
),
11982 WINDOW_TOTAL_LINES (w
) > 0))
11984 update_tool_bar (f
, 1);
11985 if (f
->n_tool_bar_items
)
11987 build_desired_tool_bar_string (f
);
11988 nlines
= tool_bar_lines_needed (f
, NULL
);
11992 return make_number (nlines
);
11996 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11997 height should be changed. */
12000 redisplay_tool_bar (struct frame
*f
)
12004 struct glyph_row
*row
;
12006 #if defined (USE_GTK) || defined (HAVE_NS)
12007 if (FRAME_EXTERNAL_TOOL_BAR (f
))
12008 update_frame_tool_bar (f
);
12012 /* If frame hasn't a tool-bar window or if it is zero-height, don't
12013 do anything. This means you must start with tool-bar-lines
12014 non-zero to get the auto-sizing effect. Or in other words, you
12015 can turn off tool-bars by specifying tool-bar-lines zero. */
12016 if (!WINDOWP (f
->tool_bar_window
)
12017 || (w
= XWINDOW (f
->tool_bar_window
),
12018 WINDOW_TOTAL_LINES (w
) == 0))
12021 /* Set up an iterator for the tool-bar window. */
12022 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
12023 it
.first_visible_x
= 0;
12024 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
12025 row
= it
.glyph_row
;
12027 /* Build a string that represents the contents of the tool-bar. */
12028 build_desired_tool_bar_string (f
);
12029 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
12030 /* FIXME: This should be controlled by a user option. But it
12031 doesn't make sense to have an R2L tool bar if the menu bar cannot
12032 be drawn also R2L, and making the menu bar R2L is tricky due
12033 toolkit-specific code that implements it. If an R2L tool bar is
12034 ever supported, display_tool_bar_line should also be augmented to
12035 call unproduce_glyphs like display_line and display_string
12037 it
.paragraph_embedding
= L2R
;
12039 if (f
->n_tool_bar_rows
== 0)
12043 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
12044 nlines
!= WINDOW_TOTAL_LINES (w
)))
12047 int old_height
= WINDOW_TOTAL_LINES (w
);
12049 XSETFRAME (frame
, f
);
12050 Fmodify_frame_parameters (frame
,
12051 Fcons (Fcons (Qtool_bar_lines
,
12052 make_number (nlines
)),
12054 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12056 clear_glyph_matrix (w
->desired_matrix
);
12057 fonts_changed_p
= 1;
12063 /* Display as many lines as needed to display all tool-bar items. */
12065 if (f
->n_tool_bar_rows
> 0)
12067 int border
, rows
, height
, extra
;
12069 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12070 border
= XINT (Vtool_bar_border
);
12071 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12072 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12073 else if (EQ (Vtool_bar_border
, Qborder_width
))
12074 border
= f
->border_width
;
12080 rows
= f
->n_tool_bar_rows
;
12081 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12082 extra
= it
.last_visible_y
- border
- height
* rows
;
12084 while (it
.current_y
< it
.last_visible_y
)
12087 if (extra
> 0 && rows
-- > 0)
12089 h
= (extra
+ rows
- 1) / rows
;
12092 display_tool_bar_line (&it
, height
+ h
);
12097 while (it
.current_y
< it
.last_visible_y
)
12098 display_tool_bar_line (&it
, 0);
12101 /* It doesn't make much sense to try scrolling in the tool-bar
12102 window, so don't do it. */
12103 w
->desired_matrix
->no_scrolling_p
= 1;
12104 w
->must_be_updated_p
= 1;
12106 if (!NILP (Vauto_resize_tool_bars
))
12108 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12109 int change_height_p
= 0;
12111 /* If we couldn't display everything, change the tool-bar's
12112 height if there is room for more. */
12113 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12114 && it
.current_y
< max_tool_bar_height
)
12115 change_height_p
= 1;
12117 row
= it
.glyph_row
- 1;
12119 /* If there are blank lines at the end, except for a partially
12120 visible blank line at the end that is smaller than
12121 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12122 if (!row
->displays_text_p
12123 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12124 change_height_p
= 1;
12126 /* If row displays tool-bar items, but is partially visible,
12127 change the tool-bar's height. */
12128 if (row
->displays_text_p
12129 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12130 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12131 change_height_p
= 1;
12133 /* Resize windows as needed by changing the `tool-bar-lines'
12134 frame parameter. */
12135 if (change_height_p
)
12138 int old_height
= WINDOW_TOTAL_LINES (w
);
12140 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12142 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12143 && !f
->minimize_tool_bar_window_p
)
12144 ? (nlines
> old_height
)
12145 : (nlines
!= old_height
));
12146 f
->minimize_tool_bar_window_p
= 0;
12148 if (change_height_p
)
12150 XSETFRAME (frame
, f
);
12151 Fmodify_frame_parameters (frame
,
12152 Fcons (Fcons (Qtool_bar_lines
,
12153 make_number (nlines
)),
12155 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12157 clear_glyph_matrix (w
->desired_matrix
);
12158 f
->n_tool_bar_rows
= nrows
;
12159 fonts_changed_p
= 1;
12166 f
->minimize_tool_bar_window_p
= 0;
12171 /* Get information about the tool-bar item which is displayed in GLYPH
12172 on frame F. Return in *PROP_IDX the index where tool-bar item
12173 properties start in F->tool_bar_items. Value is zero if
12174 GLYPH doesn't display a tool-bar item. */
12177 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12183 /* This function can be called asynchronously, which means we must
12184 exclude any possibility that Fget_text_property signals an
12186 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12187 charpos
= max (0, charpos
);
12189 /* Get the text property `menu-item' at pos. The value of that
12190 property is the start index of this item's properties in
12191 F->tool_bar_items. */
12192 prop
= Fget_text_property (make_number (charpos
),
12193 Qmenu_item
, f
->current_tool_bar_string
);
12194 if (INTEGERP (prop
))
12196 *prop_idx
= XINT (prop
);
12206 /* Get information about the tool-bar item at position X/Y on frame F.
12207 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12208 the current matrix of the tool-bar window of F, or NULL if not
12209 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12210 item in F->tool_bar_items. Value is
12212 -1 if X/Y is not on a tool-bar item
12213 0 if X/Y is on the same item that was highlighted before.
12217 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12218 int *hpos
, int *vpos
, int *prop_idx
)
12220 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12221 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12224 /* Find the glyph under X/Y. */
12225 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12226 if (*glyph
== NULL
)
12229 /* Get the start of this tool-bar item's properties in
12230 f->tool_bar_items. */
12231 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12234 /* Is mouse on the highlighted item? */
12235 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12236 && *vpos
>= hlinfo
->mouse_face_beg_row
12237 && *vpos
<= hlinfo
->mouse_face_end_row
12238 && (*vpos
> hlinfo
->mouse_face_beg_row
12239 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12240 && (*vpos
< hlinfo
->mouse_face_end_row
12241 || *hpos
< hlinfo
->mouse_face_end_col
12242 || hlinfo
->mouse_face_past_end
))
12250 Handle mouse button event on the tool-bar of frame F, at
12251 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12252 0 for button release. MODIFIERS is event modifiers for button
12256 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12259 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12260 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12261 int hpos
, vpos
, prop_idx
;
12262 struct glyph
*glyph
;
12263 Lisp_Object enabled_p
;
12265 /* If not on the highlighted tool-bar item, return. */
12266 frame_to_window_pixel_xy (w
, &x
, &y
);
12267 if (get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
) != 0)
12270 /* If item is disabled, do nothing. */
12271 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12272 if (NILP (enabled_p
))
12277 /* Show item in pressed state. */
12278 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12279 last_tool_bar_item
= prop_idx
;
12283 Lisp_Object key
, frame
;
12284 struct input_event event
;
12285 EVENT_INIT (event
);
12287 /* Show item in released state. */
12288 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12290 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12292 XSETFRAME (frame
, f
);
12293 event
.kind
= TOOL_BAR_EVENT
;
12294 event
.frame_or_window
= frame
;
12296 kbd_buffer_store_event (&event
);
12298 event
.kind
= TOOL_BAR_EVENT
;
12299 event
.frame_or_window
= frame
;
12301 event
.modifiers
= modifiers
;
12302 kbd_buffer_store_event (&event
);
12303 last_tool_bar_item
= -1;
12308 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12309 tool-bar window-relative coordinates X/Y. Called from
12310 note_mouse_highlight. */
12313 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12315 Lisp_Object window
= f
->tool_bar_window
;
12316 struct window
*w
= XWINDOW (window
);
12317 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12318 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12320 struct glyph
*glyph
;
12321 struct glyph_row
*row
;
12323 Lisp_Object enabled_p
;
12325 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12326 int mouse_down_p
, rc
;
12328 /* Function note_mouse_highlight is called with negative X/Y
12329 values when mouse moves outside of the frame. */
12330 if (x
<= 0 || y
<= 0)
12332 clear_mouse_face (hlinfo
);
12336 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12339 /* Not on tool-bar item. */
12340 clear_mouse_face (hlinfo
);
12344 /* On same tool-bar item as before. */
12345 goto set_help_echo
;
12347 clear_mouse_face (hlinfo
);
12349 /* Mouse is down, but on different tool-bar item? */
12350 mouse_down_p
= (dpyinfo
->grabbed
12351 && f
== last_mouse_frame
12352 && FRAME_LIVE_P (f
));
12354 && last_tool_bar_item
!= prop_idx
)
12357 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12359 /* If tool-bar item is not enabled, don't highlight it. */
12360 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12361 if (!NILP (enabled_p
))
12363 /* Compute the x-position of the glyph. In front and past the
12364 image is a space. We include this in the highlighted area. */
12365 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12366 for (i
= x
= 0; i
< hpos
; ++i
)
12367 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12369 /* Record this as the current active region. */
12370 hlinfo
->mouse_face_beg_col
= hpos
;
12371 hlinfo
->mouse_face_beg_row
= vpos
;
12372 hlinfo
->mouse_face_beg_x
= x
;
12373 hlinfo
->mouse_face_beg_y
= row
->y
;
12374 hlinfo
->mouse_face_past_end
= 0;
12376 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12377 hlinfo
->mouse_face_end_row
= vpos
;
12378 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12379 hlinfo
->mouse_face_end_y
= row
->y
;
12380 hlinfo
->mouse_face_window
= window
;
12381 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12383 /* Display it as active. */
12384 show_mouse_face (hlinfo
, draw
);
12389 /* Set help_echo_string to a help string to display for this tool-bar item.
12390 XTread_socket does the rest. */
12391 help_echo_object
= help_echo_window
= Qnil
;
12392 help_echo_pos
= -1;
12393 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12394 if (NILP (help_echo_string
))
12395 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12398 #endif /* HAVE_WINDOW_SYSTEM */
12402 /************************************************************************
12403 Horizontal scrolling
12404 ************************************************************************/
12406 static int hscroll_window_tree (Lisp_Object
);
12407 static int hscroll_windows (Lisp_Object
);
12409 /* For all leaf windows in the window tree rooted at WINDOW, set their
12410 hscroll value so that PT is (i) visible in the window, and (ii) so
12411 that it is not within a certain margin at the window's left and
12412 right border. Value is non-zero if any window's hscroll has been
12416 hscroll_window_tree (Lisp_Object window
)
12418 int hscrolled_p
= 0;
12419 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12420 int hscroll_step_abs
= 0;
12421 double hscroll_step_rel
= 0;
12423 if (hscroll_relative_p
)
12425 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12426 if (hscroll_step_rel
< 0)
12428 hscroll_relative_p
= 0;
12429 hscroll_step_abs
= 0;
12432 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12434 hscroll_step_abs
= XINT (Vhscroll_step
);
12435 if (hscroll_step_abs
< 0)
12436 hscroll_step_abs
= 0;
12439 hscroll_step_abs
= 0;
12441 while (WINDOWP (window
))
12443 struct window
*w
= XWINDOW (window
);
12445 if (WINDOWP (w
->hchild
))
12446 hscrolled_p
|= hscroll_window_tree (w
->hchild
);
12447 else if (WINDOWP (w
->vchild
))
12448 hscrolled_p
|= hscroll_window_tree (w
->vchild
);
12449 else if (w
->cursor
.vpos
>= 0)
12452 int text_area_width
;
12453 struct glyph_row
*current_cursor_row
12454 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12455 struct glyph_row
*desired_cursor_row
12456 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12457 struct glyph_row
*cursor_row
12458 = (desired_cursor_row
->enabled_p
12459 ? desired_cursor_row
12460 : current_cursor_row
);
12461 int row_r2l_p
= cursor_row
->reversed_p
;
12463 text_area_width
= window_box_width (w
, TEXT_AREA
);
12465 /* Scroll when cursor is inside this scroll margin. */
12466 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12468 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->buffer
))
12469 /* For left-to-right rows, hscroll when cursor is either
12470 (i) inside the right hscroll margin, or (ii) if it is
12471 inside the left margin and the window is already
12475 && w
->cursor
.x
<= h_margin
)
12476 || (cursor_row
->enabled_p
12477 && cursor_row
->truncated_on_right_p
12478 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12479 /* For right-to-left rows, the logic is similar,
12480 except that rules for scrolling to left and right
12481 are reversed. E.g., if cursor.x <= h_margin, we
12482 need to hscroll "to the right" unconditionally,
12483 and that will scroll the screen to the left so as
12484 to reveal the next portion of the row. */
12486 && ((cursor_row
->enabled_p
12487 /* FIXME: It is confusing to set the
12488 truncated_on_right_p flag when R2L rows
12489 are actually truncated on the left. */
12490 && cursor_row
->truncated_on_right_p
12491 && w
->cursor
.x
<= h_margin
)
12493 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12497 struct buffer
*saved_current_buffer
;
12501 /* Find point in a display of infinite width. */
12502 saved_current_buffer
= current_buffer
;
12503 current_buffer
= XBUFFER (w
->buffer
);
12505 if (w
== XWINDOW (selected_window
))
12508 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12510 /* Move iterator to pt starting at cursor_row->start in
12511 a line with infinite width. */
12512 init_to_row_start (&it
, w
, cursor_row
);
12513 it
.last_visible_x
= INFINITY
;
12514 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12515 current_buffer
= saved_current_buffer
;
12517 /* Position cursor in window. */
12518 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12519 hscroll
= max (0, (it
.current_x
12520 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12521 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12522 : (text_area_width
/ 2))))
12523 / FRAME_COLUMN_WIDTH (it
.f
);
12524 else if ((!row_r2l_p
12525 && w
->cursor
.x
>= text_area_width
- h_margin
)
12526 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12528 if (hscroll_relative_p
)
12529 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12532 wanted_x
= text_area_width
12533 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12536 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12540 if (hscroll_relative_p
)
12541 wanted_x
= text_area_width
* hscroll_step_rel
12544 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12547 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12549 hscroll
= max (hscroll
, w
->min_hscroll
);
12551 /* Don't prevent redisplay optimizations if hscroll
12552 hasn't changed, as it will unnecessarily slow down
12554 if (w
->hscroll
!= hscroll
)
12556 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
12557 w
->hscroll
= hscroll
;
12566 /* Value is non-zero if hscroll of any leaf window has been changed. */
12567 return hscrolled_p
;
12571 /* Set hscroll so that cursor is visible and not inside horizontal
12572 scroll margins for all windows in the tree rooted at WINDOW. See
12573 also hscroll_window_tree above. Value is non-zero if any window's
12574 hscroll has been changed. If it has, desired matrices on the frame
12575 of WINDOW are cleared. */
12578 hscroll_windows (Lisp_Object window
)
12580 int hscrolled_p
= hscroll_window_tree (window
);
12582 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12583 return hscrolled_p
;
12588 /************************************************************************
12590 ************************************************************************/
12592 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12593 to a non-zero value. This is sometimes handy to have in a debugger
12598 /* First and last unchanged row for try_window_id. */
12600 static int debug_first_unchanged_at_end_vpos
;
12601 static int debug_last_unchanged_at_beg_vpos
;
12603 /* Delta vpos and y. */
12605 static int debug_dvpos
, debug_dy
;
12607 /* Delta in characters and bytes for try_window_id. */
12609 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12611 /* Values of window_end_pos and window_end_vpos at the end of
12614 static ptrdiff_t debug_end_vpos
;
12616 /* Append a string to W->desired_matrix->method. FMT is a printf
12617 format string. If trace_redisplay_p is non-zero also printf the
12618 resulting string to stderr. */
12620 static void debug_method_add (struct window
*, char const *, ...)
12621 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12624 debug_method_add (struct window
*w
, char const *fmt
, ...)
12626 char *method
= w
->desired_matrix
->method
;
12627 int len
= strlen (method
);
12628 int size
= sizeof w
->desired_matrix
->method
;
12629 int remaining
= size
- len
- 1;
12632 if (len
&& remaining
)
12635 --remaining
, ++len
;
12638 va_start (ap
, fmt
);
12639 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12642 if (trace_redisplay_p
)
12643 fprintf (stderr
, "%p (%s): %s\n",
12645 ((BUFFERP (w
->buffer
)
12646 && STRINGP (BVAR (XBUFFER (w
->buffer
), name
)))
12647 ? SSDATA (BVAR (XBUFFER (w
->buffer
), name
))
12652 #endif /* GLYPH_DEBUG */
12655 /* Value is non-zero if all changes in window W, which displays
12656 current_buffer, are in the text between START and END. START is a
12657 buffer position, END is given as a distance from Z. Used in
12658 redisplay_internal for display optimization. */
12661 text_outside_line_unchanged_p (struct window
*w
,
12662 ptrdiff_t start
, ptrdiff_t end
)
12664 int unchanged_p
= 1;
12666 /* If text or overlays have changed, see where. */
12667 if (window_outdated (w
))
12669 /* Gap in the line? */
12670 if (GPT
< start
|| Z
- GPT
< end
)
12673 /* Changes start in front of the line, or end after it? */
12675 && (BEG_UNCHANGED
< start
- 1
12676 || END_UNCHANGED
< end
))
12679 /* If selective display, can't optimize if changes start at the
12680 beginning of the line. */
12682 && INTEGERP (BVAR (current_buffer
, selective_display
))
12683 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12684 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12687 /* If there are overlays at the start or end of the line, these
12688 may have overlay strings with newlines in them. A change at
12689 START, for instance, may actually concern the display of such
12690 overlay strings as well, and they are displayed on different
12691 lines. So, quickly rule out this case. (For the future, it
12692 might be desirable to implement something more telling than
12693 just BEG/END_UNCHANGED.) */
12696 if (BEG
+ BEG_UNCHANGED
== start
12697 && overlay_touches_p (start
))
12699 if (END_UNCHANGED
== end
12700 && overlay_touches_p (Z
- end
))
12704 /* Under bidi reordering, adding or deleting a character in the
12705 beginning of a paragraph, before the first strong directional
12706 character, can change the base direction of the paragraph (unless
12707 the buffer specifies a fixed paragraph direction), which will
12708 require to redisplay the whole paragraph. It might be worthwhile
12709 to find the paragraph limits and widen the range of redisplayed
12710 lines to that, but for now just give up this optimization. */
12711 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
12712 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
12716 return unchanged_p
;
12720 /* Do a frame update, taking possible shortcuts into account. This is
12721 the main external entry point for redisplay.
12723 If the last redisplay displayed an echo area message and that message
12724 is no longer requested, we clear the echo area or bring back the
12725 mini-buffer if that is in use. */
12730 redisplay_internal ();
12735 overlay_arrow_string_or_property (Lisp_Object var
)
12739 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12742 return Voverlay_arrow_string
;
12745 /* Return 1 if there are any overlay-arrows in current_buffer. */
12747 overlay_arrow_in_current_buffer_p (void)
12751 for (vlist
= Voverlay_arrow_variable_list
;
12753 vlist
= XCDR (vlist
))
12755 Lisp_Object var
= XCAR (vlist
);
12758 if (!SYMBOLP (var
))
12760 val
= find_symbol_value (var
);
12762 && current_buffer
== XMARKER (val
)->buffer
)
12769 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12773 overlay_arrows_changed_p (void)
12777 for (vlist
= Voverlay_arrow_variable_list
;
12779 vlist
= XCDR (vlist
))
12781 Lisp_Object var
= XCAR (vlist
);
12782 Lisp_Object val
, pstr
;
12784 if (!SYMBOLP (var
))
12786 val
= find_symbol_value (var
);
12787 if (!MARKERP (val
))
12789 if (! EQ (COERCE_MARKER (val
),
12790 Fget (var
, Qlast_arrow_position
))
12791 || ! (pstr
= overlay_arrow_string_or_property (var
),
12792 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12798 /* Mark overlay arrows to be updated on next redisplay. */
12801 update_overlay_arrows (int up_to_date
)
12805 for (vlist
= Voverlay_arrow_variable_list
;
12807 vlist
= XCDR (vlist
))
12809 Lisp_Object var
= XCAR (vlist
);
12811 if (!SYMBOLP (var
))
12814 if (up_to_date
> 0)
12816 Lisp_Object val
= find_symbol_value (var
);
12817 Fput (var
, Qlast_arrow_position
,
12818 COERCE_MARKER (val
));
12819 Fput (var
, Qlast_arrow_string
,
12820 overlay_arrow_string_or_property (var
));
12822 else if (up_to_date
< 0
12823 || !NILP (Fget (var
, Qlast_arrow_position
)))
12825 Fput (var
, Qlast_arrow_position
, Qt
);
12826 Fput (var
, Qlast_arrow_string
, Qt
);
12832 /* Return overlay arrow string to display at row.
12833 Return integer (bitmap number) for arrow bitmap in left fringe.
12834 Return nil if no overlay arrow. */
12837 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12841 for (vlist
= Voverlay_arrow_variable_list
;
12843 vlist
= XCDR (vlist
))
12845 Lisp_Object var
= XCAR (vlist
);
12848 if (!SYMBOLP (var
))
12851 val
= find_symbol_value (var
);
12854 && current_buffer
== XMARKER (val
)->buffer
12855 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12857 if (FRAME_WINDOW_P (it
->f
)
12858 /* FIXME: if ROW->reversed_p is set, this should test
12859 the right fringe, not the left one. */
12860 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12862 #ifdef HAVE_WINDOW_SYSTEM
12863 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12866 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12867 return make_number (fringe_bitmap
);
12870 return make_number (-1); /* Use default arrow bitmap. */
12872 return overlay_arrow_string_or_property (var
);
12879 /* Return 1 if point moved out of or into a composition. Otherwise
12880 return 0. PREV_BUF and PREV_PT are the last point buffer and
12881 position. BUF and PT are the current point buffer and position. */
12884 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12885 struct buffer
*buf
, ptrdiff_t pt
)
12887 ptrdiff_t start
, end
;
12889 Lisp_Object buffer
;
12891 XSETBUFFER (buffer
, buf
);
12892 /* Check a composition at the last point if point moved within the
12894 if (prev_buf
== buf
)
12897 /* Point didn't move. */
12900 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12901 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12902 && COMPOSITION_VALID_P (start
, end
, prop
)
12903 && start
< prev_pt
&& end
> prev_pt
)
12904 /* The last point was within the composition. Return 1 iff
12905 point moved out of the composition. */
12906 return (pt
<= start
|| pt
>= end
);
12909 /* Check a composition at the current point. */
12910 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12911 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12912 && COMPOSITION_VALID_P (start
, end
, prop
)
12913 && start
< pt
&& end
> pt
);
12917 /* Reconsider the setting of B->clip_changed which is displayed
12921 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12923 if (b
->clip_changed
12924 && !NILP (w
->window_end_valid
)
12925 && w
->current_matrix
->buffer
== b
12926 && w
->current_matrix
->zv
== BUF_ZV (b
)
12927 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12928 b
->clip_changed
= 0;
12930 /* If display wasn't paused, and W is not a tool bar window, see if
12931 point has been moved into or out of a composition. In that case,
12932 we set b->clip_changed to 1 to force updating the screen. If
12933 b->clip_changed has already been set to 1, we can skip this
12935 if (!b
->clip_changed
12936 && BUFFERP (w
->buffer
) && !NILP (w
->window_end_valid
))
12940 if (w
== XWINDOW (selected_window
))
12943 pt
= marker_position (w
->pointm
);
12945 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->buffer
)
12946 || pt
!= w
->last_point
)
12947 && check_point_in_composition (w
->current_matrix
->buffer
,
12949 XBUFFER (w
->buffer
), pt
))
12950 b
->clip_changed
= 1;
12955 /* Select FRAME to forward the values of frame-local variables into C
12956 variables so that the redisplay routines can access those values
12960 select_frame_for_redisplay (Lisp_Object frame
)
12962 Lisp_Object tail
, tem
;
12963 Lisp_Object old
= selected_frame
;
12964 struct Lisp_Symbol
*sym
;
12966 eassert (FRAMEP (frame
) && FRAME_LIVE_P (XFRAME (frame
)));
12968 selected_frame
= frame
;
12971 for (tail
= XFRAME (frame
)->param_alist
;
12972 CONSP (tail
); tail
= XCDR (tail
))
12973 if (CONSP (XCAR (tail
))
12974 && (tem
= XCAR (XCAR (tail
)),
12976 && (sym
= indirect_variable (XSYMBOL (tem
)),
12977 sym
->redirect
== SYMBOL_LOCALIZED
)
12978 && sym
->val
.blv
->frame_local
)
12979 /* Use find_symbol_value rather than Fsymbol_value
12980 to avoid an error if it is void. */
12981 find_symbol_value (tem
);
12982 } while (!EQ (frame
, old
) && (frame
= old
, 1));
12985 /* Make sure that previously selected OLD_FRAME is selected unless it has been
12986 deleted (by an X connection failure during redisplay, for example). */
12989 ensure_selected_frame (Lisp_Object old_frame
)
12991 if (!EQ (old_frame
, selected_frame
) && FRAME_LIVE_P (XFRAME (old_frame
)))
12992 select_frame_for_redisplay (old_frame
);
12995 #define STOP_POLLING \
12996 do { if (! polling_stopped_here) stop_polling (); \
12997 polling_stopped_here = 1; } while (0)
12999 #define RESUME_POLLING \
13000 do { if (polling_stopped_here) start_polling (); \
13001 polling_stopped_here = 0; } while (0)
13004 /* Perhaps in the future avoid recentering windows if it
13005 is not necessary; currently that causes some problems. */
13008 redisplay_internal (void)
13010 struct window
*w
= XWINDOW (selected_window
);
13014 int must_finish
= 0;
13015 struct text_pos tlbufpos
, tlendpos
;
13016 int number_of_visible_frames
;
13017 ptrdiff_t count
, count1
;
13019 int polling_stopped_here
= 0;
13020 Lisp_Object tail
, frame
, old_frame
= selected_frame
;
13021 struct backtrace backtrace
;
13023 /* Non-zero means redisplay has to consider all windows on all
13024 frames. Zero means, only selected_window is considered. */
13025 int consider_all_windows_p
;
13027 /* Non-zero means redisplay has to redisplay the miniwindow. */
13028 int update_miniwindow_p
= 0;
13030 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
13032 /* No redisplay if running in batch mode or frame is not yet fully
13033 initialized, or redisplay is explicitly turned off by setting
13034 Vinhibit_redisplay. */
13035 if (FRAME_INITIAL_P (SELECTED_FRAME ())
13036 || !NILP (Vinhibit_redisplay
))
13039 /* Don't examine these until after testing Vinhibit_redisplay.
13040 When Emacs is shutting down, perhaps because its connection to
13041 X has dropped, we should not look at them at all. */
13042 fr
= XFRAME (w
->frame
);
13043 sf
= SELECTED_FRAME ();
13045 if (!fr
->glyphs_initialized_p
)
13048 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
13049 if (popup_activated ())
13053 /* I don't think this happens but let's be paranoid. */
13054 if (redisplaying_p
)
13057 /* Record a function that clears redisplaying_p
13058 when we leave this function. */
13059 count
= SPECPDL_INDEX ();
13060 record_unwind_protect (unwind_redisplay
, selected_frame
);
13061 redisplaying_p
= 1;
13062 specbind (Qinhibit_free_realized_faces
, Qnil
);
13064 /* Record this function, so it appears on the profiler's backtraces. */
13065 backtrace
.next
= backtrace_list
;
13066 backtrace
.function
= Qredisplay_internal
;
13067 backtrace
.args
= &Qnil
;
13068 backtrace
.nargs
= 0;
13069 backtrace
.debug_on_exit
= 0;
13070 backtrace_list
= &backtrace
;
13072 FOR_EACH_FRAME (tail
, frame
)
13073 XFRAME (frame
)->already_hscrolled_p
= 0;
13076 /* Remember the currently selected window. */
13079 /* When running redisplay, we play a bit fast-and-loose and allow e.g.
13080 selected_frame and selected_window to be temporarily out-of-sync so
13081 when we come back here via `goto retry', we need to resync because we
13082 may need to run Elisp code (via prepare_menu_bars). */
13083 ensure_selected_frame (old_frame
);
13086 reconsider_clip_changes (w
, current_buffer
);
13087 last_escape_glyph_frame
= NULL
;
13088 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13089 last_glyphless_glyph_frame
= NULL
;
13090 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13092 /* If new fonts have been loaded that make a glyph matrix adjustment
13093 necessary, do it. */
13094 if (fonts_changed_p
)
13096 adjust_glyphs (NULL
);
13097 ++windows_or_buffers_changed
;
13098 fonts_changed_p
= 0;
13101 /* If face_change_count is non-zero, init_iterator will free all
13102 realized faces, which includes the faces referenced from current
13103 matrices. So, we can't reuse current matrices in this case. */
13104 if (face_change_count
)
13105 ++windows_or_buffers_changed
;
13107 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13108 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13110 /* Since frames on a single ASCII terminal share the same
13111 display area, displaying a different frame means redisplay
13112 the whole thing. */
13113 windows_or_buffers_changed
++;
13114 SET_FRAME_GARBAGED (sf
);
13116 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13118 FRAME_TTY (sf
)->previous_frame
= sf
;
13121 /* Set the visible flags for all frames. Do this before checking for
13122 resized or garbaged frames; they want to know if their frames are
13123 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13124 number_of_visible_frames
= 0;
13126 FOR_EACH_FRAME (tail
, frame
)
13128 struct frame
*f
= XFRAME (frame
);
13130 FRAME_SAMPLE_VISIBILITY (f
);
13131 if (FRAME_VISIBLE_P (f
))
13132 ++number_of_visible_frames
;
13133 clear_desired_matrices (f
);
13136 /* Notice any pending interrupt request to change frame size. */
13137 do_pending_window_change (1);
13139 /* do_pending_window_change could change the selected_window due to
13140 frame resizing which makes the selected window too small. */
13141 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13144 reconsider_clip_changes (w
, current_buffer
);
13147 /* Clear frames marked as garbaged. */
13148 clear_garbaged_frames ();
13150 /* Build menubar and tool-bar items. */
13151 if (NILP (Vmemory_full
))
13152 prepare_menu_bars ();
13154 if (windows_or_buffers_changed
)
13155 update_mode_lines
++;
13157 /* Detect case that we need to write or remove a star in the mode line. */
13158 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13160 w
->update_mode_line
= 1;
13161 if (buffer_shared_and_changed ())
13162 update_mode_lines
++;
13165 /* Avoid invocation of point motion hooks by `current_column' below. */
13166 count1
= SPECPDL_INDEX ();
13167 specbind (Qinhibit_point_motion_hooks
, Qt
);
13169 if (mode_line_update_needed (w
))
13170 w
->update_mode_line
= 1;
13172 unbind_to (count1
, Qnil
);
13174 FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w
->frame
)) = -1;
13176 consider_all_windows_p
= (update_mode_lines
13177 || buffer_shared_and_changed ()
13178 || cursor_type_changed
);
13180 /* If specs for an arrow have changed, do thorough redisplay
13181 to ensure we remove any arrow that should no longer exist. */
13182 if (overlay_arrows_changed_p ())
13183 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13185 /* Normally the message* functions will have already displayed and
13186 updated the echo area, but the frame may have been trashed, or
13187 the update may have been preempted, so display the echo area
13188 again here. Checking message_cleared_p captures the case that
13189 the echo area should be cleared. */
13190 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13191 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13192 || (message_cleared_p
13193 && minibuf_level
== 0
13194 /* If the mini-window is currently selected, this means the
13195 echo-area doesn't show through. */
13196 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13198 int window_height_changed_p
= echo_area_display (0);
13200 if (message_cleared_p
)
13201 update_miniwindow_p
= 1;
13205 /* If we don't display the current message, don't clear the
13206 message_cleared_p flag, because, if we did, we wouldn't clear
13207 the echo area in the next redisplay which doesn't preserve
13209 if (!display_last_displayed_message_p
)
13210 message_cleared_p
= 0;
13212 if (fonts_changed_p
)
13214 else if (window_height_changed_p
)
13216 consider_all_windows_p
= 1;
13217 ++update_mode_lines
;
13218 ++windows_or_buffers_changed
;
13220 /* If window configuration was changed, frames may have been
13221 marked garbaged. Clear them or we will experience
13222 surprises wrt scrolling. */
13223 clear_garbaged_frames ();
13226 else if (EQ (selected_window
, minibuf_window
)
13227 && (current_buffer
->clip_changed
|| window_outdated (w
))
13228 && resize_mini_window (w
, 0))
13230 /* Resized active mini-window to fit the size of what it is
13231 showing if its contents might have changed. */
13233 /* FIXME: this causes all frames to be updated, which seems unnecessary
13234 since only the current frame needs to be considered. This function
13235 needs to be rewritten with two variables, consider_all_windows and
13236 consider_all_frames. */
13237 consider_all_windows_p
= 1;
13238 ++windows_or_buffers_changed
;
13239 ++update_mode_lines
;
13241 /* If window configuration was changed, frames may have been
13242 marked garbaged. Clear them or we will experience
13243 surprises wrt scrolling. */
13244 clear_garbaged_frames ();
13248 /* If showing the region, and mark has changed, we must redisplay
13249 the whole window. The assignment to this_line_start_pos prevents
13250 the optimization directly below this if-statement. */
13251 if (((!NILP (Vtransient_mark_mode
)
13252 && !NILP (BVAR (XBUFFER (w
->buffer
), mark_active
)))
13253 != !NILP (w
->region_showing
))
13254 || (!NILP (w
->region_showing
)
13255 && !EQ (w
->region_showing
,
13256 Fmarker_position (BVAR (XBUFFER (w
->buffer
), mark
)))))
13257 CHARPOS (this_line_start_pos
) = 0;
13259 /* Optimize the case that only the line containing the cursor in the
13260 selected window has changed. Variables starting with this_ are
13261 set in display_line and record information about the line
13262 containing the cursor. */
13263 tlbufpos
= this_line_start_pos
;
13264 tlendpos
= this_line_end_pos
;
13265 if (!consider_all_windows_p
13266 && CHARPOS (tlbufpos
) > 0
13267 && !w
->update_mode_line
13268 && !current_buffer
->clip_changed
13269 && !current_buffer
->prevent_redisplay_optimizations_p
13270 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13271 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13272 /* Make sure recorded data applies to current buffer, etc. */
13273 && this_line_buffer
== current_buffer
13274 && current_buffer
== XBUFFER (w
->buffer
)
13276 && !w
->optional_new_start
13277 /* Point must be on the line that we have info recorded about. */
13278 && PT
>= CHARPOS (tlbufpos
)
13279 && PT
<= Z
- CHARPOS (tlendpos
)
13280 /* All text outside that line, including its final newline,
13281 must be unchanged. */
13282 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13283 CHARPOS (tlendpos
)))
13285 if (CHARPOS (tlbufpos
) > BEGV
13286 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13287 && (CHARPOS (tlbufpos
) == ZV
13288 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13289 /* Former continuation line has disappeared by becoming empty. */
13291 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13293 /* We have to handle the case of continuation around a
13294 wide-column character (see the comment in indent.c around
13297 For instance, in the following case:
13299 -------- Insert --------
13300 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13301 J_I_ ==> J_I_ `^^' are cursors.
13305 As we have to redraw the line above, we cannot use this
13309 int line_height_before
= this_line_pixel_height
;
13311 /* Note that start_display will handle the case that the
13312 line starting at tlbufpos is a continuation line. */
13313 start_display (&it
, w
, tlbufpos
);
13315 /* Implementation note: It this still necessary? */
13316 if (it
.current_x
!= this_line_start_x
)
13319 TRACE ((stderr
, "trying display optimization 1\n"));
13320 w
->cursor
.vpos
= -1;
13321 overlay_arrow_seen
= 0;
13322 it
.vpos
= this_line_vpos
;
13323 it
.current_y
= this_line_y
;
13324 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13325 display_line (&it
);
13327 /* If line contains point, is not continued,
13328 and ends at same distance from eob as before, we win. */
13329 if (w
->cursor
.vpos
>= 0
13330 /* Line is not continued, otherwise this_line_start_pos
13331 would have been set to 0 in display_line. */
13332 && CHARPOS (this_line_start_pos
)
13333 /* Line ends as before. */
13334 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13335 /* Line has same height as before. Otherwise other lines
13336 would have to be shifted up or down. */
13337 && this_line_pixel_height
== line_height_before
)
13339 /* If this is not the window's last line, we must adjust
13340 the charstarts of the lines below. */
13341 if (it
.current_y
< it
.last_visible_y
)
13343 struct glyph_row
*row
13344 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13345 ptrdiff_t delta
, delta_bytes
;
13347 /* We used to distinguish between two cases here,
13348 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13349 when the line ends in a newline or the end of the
13350 buffer's accessible portion. But both cases did
13351 the same, so they were collapsed. */
13353 - CHARPOS (tlendpos
)
13354 - MATRIX_ROW_START_CHARPOS (row
));
13355 delta_bytes
= (Z_BYTE
13356 - BYTEPOS (tlendpos
)
13357 - MATRIX_ROW_START_BYTEPOS (row
));
13359 increment_matrix_positions (w
->current_matrix
,
13360 this_line_vpos
+ 1,
13361 w
->current_matrix
->nrows
,
13362 delta
, delta_bytes
);
13365 /* If this row displays text now but previously didn't,
13366 or vice versa, w->window_end_vpos may have to be
13368 if ((it
.glyph_row
- 1)->displays_text_p
)
13370 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13371 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13373 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13374 && this_line_vpos
> 0)
13375 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13376 wset_window_end_valid (w
, Qnil
);
13378 /* Update hint: No need to try to scroll in update_window. */
13379 w
->desired_matrix
->no_scrolling_p
= 1;
13382 *w
->desired_matrix
->method
= 0;
13383 debug_method_add (w
, "optimization 1");
13385 #ifdef HAVE_WINDOW_SYSTEM
13386 update_window_fringes (w
, 0);
13393 else if (/* Cursor position hasn't changed. */
13394 PT
== w
->last_point
13395 /* Make sure the cursor was last displayed
13396 in this window. Otherwise we have to reposition it. */
13397 && 0 <= w
->cursor
.vpos
13398 && WINDOW_TOTAL_LINES (w
) > w
->cursor
.vpos
)
13402 do_pending_window_change (1);
13403 /* If selected_window changed, redisplay again. */
13404 if (WINDOWP (selected_window
)
13405 && (w
= XWINDOW (selected_window
)) != sw
)
13408 /* We used to always goto end_of_redisplay here, but this
13409 isn't enough if we have a blinking cursor. */
13410 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13411 goto end_of_redisplay
;
13415 /* If highlighting the region, or if the cursor is in the echo area,
13416 then we can't just move the cursor. */
13417 else if (! (!NILP (Vtransient_mark_mode
)
13418 && !NILP (BVAR (current_buffer
, mark_active
)))
13419 && (EQ (selected_window
,
13420 BVAR (current_buffer
, last_selected_window
))
13421 || highlight_nonselected_windows
)
13422 && NILP (w
->region_showing
)
13423 && NILP (Vshow_trailing_whitespace
)
13424 && !cursor_in_echo_area
)
13427 struct glyph_row
*row
;
13429 /* Skip from tlbufpos to PT and see where it is. Note that
13430 PT may be in invisible text. If so, we will end at the
13431 next visible position. */
13432 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13433 NULL
, DEFAULT_FACE_ID
);
13434 it
.current_x
= this_line_start_x
;
13435 it
.current_y
= this_line_y
;
13436 it
.vpos
= this_line_vpos
;
13438 /* The call to move_it_to stops in front of PT, but
13439 moves over before-strings. */
13440 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13442 if (it
.vpos
== this_line_vpos
13443 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13446 eassert (this_line_vpos
== it
.vpos
);
13447 eassert (this_line_y
== it
.current_y
);
13448 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13450 *w
->desired_matrix
->method
= 0;
13451 debug_method_add (w
, "optimization 3");
13460 /* Text changed drastically or point moved off of line. */
13461 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13464 CHARPOS (this_line_start_pos
) = 0;
13465 consider_all_windows_p
|= buffer_shared_and_changed ();
13466 ++clear_face_cache_count
;
13467 #ifdef HAVE_WINDOW_SYSTEM
13468 ++clear_image_cache_count
;
13471 /* Build desired matrices, and update the display. If
13472 consider_all_windows_p is non-zero, do it for all windows on all
13473 frames. Otherwise do it for selected_window, only. */
13475 if (consider_all_windows_p
)
13477 FOR_EACH_FRAME (tail
, frame
)
13478 XFRAME (frame
)->updated_p
= 0;
13480 FOR_EACH_FRAME (tail
, frame
)
13482 struct frame
*f
= XFRAME (frame
);
13484 /* We don't have to do anything for unselected terminal
13486 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13487 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13490 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13492 if (! EQ (frame
, selected_frame
))
13493 /* Select the frame, for the sake of frame-local
13495 select_frame_for_redisplay (frame
);
13497 /* Mark all the scroll bars to be removed; we'll redeem
13498 the ones we want when we redisplay their windows. */
13499 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13500 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13502 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13503 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13505 /* The X error handler may have deleted that frame. */
13506 if (!FRAME_LIVE_P (f
))
13509 /* Any scroll bars which redisplay_windows should have
13510 nuked should now go away. */
13511 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13512 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13514 /* If fonts changed, display again. */
13515 /* ??? rms: I suspect it is a mistake to jump all the way
13516 back to retry here. It should just retry this frame. */
13517 if (fonts_changed_p
)
13520 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13522 /* See if we have to hscroll. */
13523 if (!f
->already_hscrolled_p
)
13525 f
->already_hscrolled_p
= 1;
13526 if (hscroll_windows (f
->root_window
))
13530 /* Prevent various kinds of signals during display
13531 update. stdio is not robust about handling
13532 signals, which can cause an apparent I/O
13534 if (interrupt_input
)
13535 unrequest_sigio ();
13538 /* Update the display. */
13539 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13540 pending
|= update_frame (f
, 0, 0);
13546 /* We played a bit fast-and-loose above and allowed selected_frame
13547 and selected_window to be temporarily out-of-sync but let's make
13548 sure this stays contained. */
13549 ensure_selected_frame (old_frame
);
13550 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13554 /* Do the mark_window_display_accurate after all windows have
13555 been redisplayed because this call resets flags in buffers
13556 which are needed for proper redisplay. */
13557 FOR_EACH_FRAME (tail
, frame
)
13559 struct frame
*f
= XFRAME (frame
);
13562 mark_window_display_accurate (f
->root_window
, 1);
13563 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13564 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13569 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13571 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13572 struct frame
*mini_frame
;
13574 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->buffer
);
13575 /* Use list_of_error, not Qerror, so that
13576 we catch only errors and don't run the debugger. */
13577 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13579 redisplay_window_error
);
13580 if (update_miniwindow_p
)
13581 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13583 redisplay_window_error
);
13585 /* Compare desired and current matrices, perform output. */
13588 /* If fonts changed, display again. */
13589 if (fonts_changed_p
)
13592 /* Prevent various kinds of signals during display update.
13593 stdio is not robust about handling signals,
13594 which can cause an apparent I/O error. */
13595 if (interrupt_input
)
13596 unrequest_sigio ();
13599 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13601 if (hscroll_windows (selected_window
))
13604 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13605 pending
= update_frame (sf
, 0, 0);
13608 /* We may have called echo_area_display at the top of this
13609 function. If the echo area is on another frame, that may
13610 have put text on a frame other than the selected one, so the
13611 above call to update_frame would not have caught it. Catch
13613 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13614 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13616 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13618 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13619 pending
|= update_frame (mini_frame
, 0, 0);
13620 if (!pending
&& hscroll_windows (mini_window
))
13625 /* If display was paused because of pending input, make sure we do a
13626 thorough update the next time. */
13629 /* Prevent the optimization at the beginning of
13630 redisplay_internal that tries a single-line update of the
13631 line containing the cursor in the selected window. */
13632 CHARPOS (this_line_start_pos
) = 0;
13634 /* Let the overlay arrow be updated the next time. */
13635 update_overlay_arrows (0);
13637 /* If we pause after scrolling, some rows in the current
13638 matrices of some windows are not valid. */
13639 if (!WINDOW_FULL_WIDTH_P (w
)
13640 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13641 update_mode_lines
= 1;
13645 if (!consider_all_windows_p
)
13647 /* This has already been done above if
13648 consider_all_windows_p is set. */
13649 mark_window_display_accurate_1 (w
, 1);
13651 /* Say overlay arrows are up to date. */
13652 update_overlay_arrows (1);
13654 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13655 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13658 update_mode_lines
= 0;
13659 windows_or_buffers_changed
= 0;
13660 cursor_type_changed
= 0;
13663 /* Start SIGIO interrupts coming again. Having them off during the
13664 code above makes it less likely one will discard output, but not
13665 impossible, since there might be stuff in the system buffer here.
13666 But it is much hairier to try to do anything about that. */
13667 if (interrupt_input
)
13671 /* If a frame has become visible which was not before, redisplay
13672 again, so that we display it. Expose events for such a frame
13673 (which it gets when becoming visible) don't call the parts of
13674 redisplay constructing glyphs, so simply exposing a frame won't
13675 display anything in this case. So, we have to display these
13676 frames here explicitly. */
13681 FOR_EACH_FRAME (tail
, frame
)
13683 int this_is_visible
= 0;
13685 if (XFRAME (frame
)->visible
)
13686 this_is_visible
= 1;
13687 FRAME_SAMPLE_VISIBILITY (XFRAME (frame
));
13688 if (XFRAME (frame
)->visible
)
13689 this_is_visible
= 1;
13691 if (this_is_visible
)
13695 if (new_count
!= number_of_visible_frames
)
13696 windows_or_buffers_changed
++;
13699 /* Change frame size now if a change is pending. */
13700 do_pending_window_change (1);
13702 /* If we just did a pending size change, or have additional
13703 visible frames, or selected_window changed, redisplay again. */
13704 if ((windows_or_buffers_changed
&& !pending
)
13705 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13708 /* Clear the face and image caches.
13710 We used to do this only if consider_all_windows_p. But the cache
13711 needs to be cleared if a timer creates images in the current
13712 buffer (e.g. the test case in Bug#6230). */
13714 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13716 clear_face_cache (0);
13717 clear_face_cache_count
= 0;
13720 #ifdef HAVE_WINDOW_SYSTEM
13721 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13723 clear_image_caches (Qnil
);
13724 clear_image_cache_count
= 0;
13726 #endif /* HAVE_WINDOW_SYSTEM */
13729 backtrace_list
= backtrace
.next
;
13730 unbind_to (count
, Qnil
);
13735 /* Redisplay, but leave alone any recent echo area message unless
13736 another message has been requested in its place.
13738 This is useful in situations where you need to redisplay but no
13739 user action has occurred, making it inappropriate for the message
13740 area to be cleared. See tracking_off and
13741 wait_reading_process_output for examples of these situations.
13743 FROM_WHERE is an integer saying from where this function was
13744 called. This is useful for debugging. */
13747 redisplay_preserve_echo_area (int from_where
)
13749 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13751 if (!NILP (echo_area_buffer
[1]))
13753 /* We have a previously displayed message, but no current
13754 message. Redisplay the previous message. */
13755 display_last_displayed_message_p
= 1;
13756 redisplay_internal ();
13757 display_last_displayed_message_p
= 0;
13760 redisplay_internal ();
13762 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13763 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13764 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13768 /* Function registered with record_unwind_protect in redisplay_internal.
13769 Clear redisplaying_p. Also select the previously selected frame. */
13772 unwind_redisplay (Lisp_Object old_frame
)
13774 redisplaying_p
= 0;
13775 ensure_selected_frame (old_frame
);
13780 /* Mark the display of window W as accurate or inaccurate. If
13781 ACCURATE_P is non-zero mark display of W as accurate. If
13782 ACCURATE_P is zero, arrange for W to be redisplayed the next time
13783 redisplay_internal is called. */
13786 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13788 if (BUFFERP (w
->buffer
))
13790 struct buffer
*b
= XBUFFER (w
->buffer
);
13792 w
->last_modified
= accurate_p
? BUF_MODIFF(b
) : 0;
13793 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF(b
) : 0;
13795 = BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13799 b
->clip_changed
= 0;
13800 b
->prevent_redisplay_optimizations_p
= 0;
13802 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13803 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13804 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13805 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13807 w
->current_matrix
->buffer
= b
;
13808 w
->current_matrix
->begv
= BUF_BEGV (b
);
13809 w
->current_matrix
->zv
= BUF_ZV (b
);
13811 w
->last_cursor
= w
->cursor
;
13812 w
->last_cursor_off_p
= w
->cursor_off_p
;
13814 if (w
== XWINDOW (selected_window
))
13815 w
->last_point
= BUF_PT (b
);
13817 w
->last_point
= marker_position (w
->pointm
);
13823 wset_window_end_valid (w
, w
->buffer
);
13824 w
->update_mode_line
= 0;
13829 /* Mark the display of windows in the window tree rooted at WINDOW as
13830 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13831 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13832 be redisplayed the next time redisplay_internal is called. */
13835 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13839 for (; !NILP (window
); window
= w
->next
)
13841 w
= XWINDOW (window
);
13842 mark_window_display_accurate_1 (w
, accurate_p
);
13844 if (!NILP (w
->vchild
))
13845 mark_window_display_accurate (w
->vchild
, accurate_p
);
13846 if (!NILP (w
->hchild
))
13847 mark_window_display_accurate (w
->hchild
, accurate_p
);
13852 update_overlay_arrows (1);
13856 /* Force a thorough redisplay the next time by setting
13857 last_arrow_position and last_arrow_string to t, which is
13858 unequal to any useful value of Voverlay_arrow_... */
13859 update_overlay_arrows (-1);
13864 /* Return value in display table DP (Lisp_Char_Table *) for character
13865 C. Since a display table doesn't have any parent, we don't have to
13866 follow parent. Do not call this function directly but use the
13867 macro DISP_CHAR_VECTOR. */
13870 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13874 if (ASCII_CHAR_P (c
))
13877 if (SUB_CHAR_TABLE_P (val
))
13878 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13884 XSETCHAR_TABLE (table
, dp
);
13885 val
= char_table_ref (table
, c
);
13894 /***********************************************************************
13896 ***********************************************************************/
13898 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13901 redisplay_windows (Lisp_Object window
)
13903 while (!NILP (window
))
13905 struct window
*w
= XWINDOW (window
);
13907 if (!NILP (w
->hchild
))
13908 redisplay_windows (w
->hchild
);
13909 else if (!NILP (w
->vchild
))
13910 redisplay_windows (w
->vchild
);
13911 else if (!NILP (w
->buffer
))
13913 displayed_buffer
= XBUFFER (w
->buffer
);
13914 /* Use list_of_error, not Qerror, so that
13915 we catch only errors and don't run the debugger. */
13916 internal_condition_case_1 (redisplay_window_0
, window
,
13918 redisplay_window_error
);
13926 redisplay_window_error (Lisp_Object ignore
)
13928 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13933 redisplay_window_0 (Lisp_Object window
)
13935 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13936 redisplay_window (window
, 0);
13941 redisplay_window_1 (Lisp_Object window
)
13943 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13944 redisplay_window (window
, 1);
13949 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13950 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13951 which positions recorded in ROW differ from current buffer
13954 Return 0 if cursor is not on this row, 1 otherwise. */
13957 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13958 struct glyph_matrix
*matrix
,
13959 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13962 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13963 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13964 struct glyph
*cursor
= NULL
;
13965 /* The last known character position in row. */
13966 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13968 ptrdiff_t pt_old
= PT
- delta
;
13969 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13970 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13971 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13972 /* A glyph beyond the edge of TEXT_AREA which we should never
13974 struct glyph
*glyphs_end
= end
;
13975 /* Non-zero means we've found a match for cursor position, but that
13976 glyph has the avoid_cursor_p flag set. */
13977 int match_with_avoid_cursor
= 0;
13978 /* Non-zero means we've seen at least one glyph that came from a
13980 int string_seen
= 0;
13981 /* Largest and smallest buffer positions seen so far during scan of
13983 ptrdiff_t bpos_max
= pos_before
;
13984 ptrdiff_t bpos_min
= pos_after
;
13985 /* Last buffer position covered by an overlay string with an integer
13986 `cursor' property. */
13987 ptrdiff_t bpos_covered
= 0;
13988 /* Non-zero means the display string on which to display the cursor
13989 comes from a text property, not from an overlay. */
13990 int string_from_text_prop
= 0;
13992 /* Don't even try doing anything if called for a mode-line or
13993 header-line row, since the rest of the code isn't prepared to
13994 deal with such calamities. */
13995 eassert (!row
->mode_line_p
);
13996 if (row
->mode_line_p
)
13999 /* Skip over glyphs not having an object at the start and the end of
14000 the row. These are special glyphs like truncation marks on
14001 terminal frames. */
14002 if (row
->displays_text_p
)
14004 if (!row
->reversed_p
)
14007 && INTEGERP (glyph
->object
)
14008 && glyph
->charpos
< 0)
14010 x
+= glyph
->pixel_width
;
14014 && INTEGERP ((end
- 1)->object
)
14015 /* CHARPOS is zero for blanks and stretch glyphs
14016 inserted by extend_face_to_end_of_line. */
14017 && (end
- 1)->charpos
<= 0)
14019 glyph_before
= glyph
- 1;
14026 /* If the glyph row is reversed, we need to process it from back
14027 to front, so swap the edge pointers. */
14028 glyphs_end
= end
= glyph
- 1;
14029 glyph
+= row
->used
[TEXT_AREA
] - 1;
14031 while (glyph
> end
+ 1
14032 && INTEGERP (glyph
->object
)
14033 && glyph
->charpos
< 0)
14036 x
-= glyph
->pixel_width
;
14038 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
14040 /* By default, in reversed rows we put the cursor on the
14041 rightmost (first in the reading order) glyph. */
14042 for (g
= end
+ 1; g
< glyph
; g
++)
14043 x
+= g
->pixel_width
;
14045 && INTEGERP ((end
+ 1)->object
)
14046 && (end
+ 1)->charpos
<= 0)
14048 glyph_before
= glyph
+ 1;
14052 else if (row
->reversed_p
)
14054 /* In R2L rows that don't display text, put the cursor on the
14055 rightmost glyph. Case in point: an empty last line that is
14056 part of an R2L paragraph. */
14058 /* Avoid placing the cursor on the last glyph of the row, where
14059 on terminal frames we hold the vertical border between
14060 adjacent windows. */
14061 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
14062 && !WINDOW_RIGHTMOST_P (w
)
14063 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
14065 x
= -1; /* will be computed below, at label compute_x */
14068 /* Step 1: Try to find the glyph whose character position
14069 corresponds to point. If that's not possible, find 2 glyphs
14070 whose character positions are the closest to point, one before
14071 point, the other after it. */
14072 if (!row
->reversed_p
)
14073 while (/* not marched to end of glyph row */
14075 /* glyph was not inserted by redisplay for internal purposes */
14076 && !INTEGERP (glyph
->object
))
14078 if (BUFFERP (glyph
->object
))
14080 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14082 if (glyph
->charpos
> bpos_max
)
14083 bpos_max
= glyph
->charpos
;
14084 if (glyph
->charpos
< bpos_min
)
14085 bpos_min
= glyph
->charpos
;
14086 if (!glyph
->avoid_cursor_p
)
14088 /* If we hit point, we've found the glyph on which to
14089 display the cursor. */
14092 match_with_avoid_cursor
= 0;
14095 /* See if we've found a better approximation to
14096 POS_BEFORE or to POS_AFTER. */
14097 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14099 pos_before
= glyph
->charpos
;
14100 glyph_before
= glyph
;
14102 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14104 pos_after
= glyph
->charpos
;
14105 glyph_after
= glyph
;
14108 else if (dpos
== 0)
14109 match_with_avoid_cursor
= 1;
14111 else if (STRINGP (glyph
->object
))
14113 Lisp_Object chprop
;
14114 ptrdiff_t glyph_pos
= glyph
->charpos
;
14116 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14118 if (!NILP (chprop
))
14120 /* If the string came from a `display' text property,
14121 look up the buffer position of that property and
14122 use that position to update bpos_max, as if we
14123 actually saw such a position in one of the row's
14124 glyphs. This helps with supporting integer values
14125 of `cursor' property on the display string in
14126 situations where most or all of the row's buffer
14127 text is completely covered by display properties,
14128 so that no glyph with valid buffer positions is
14129 ever seen in the row. */
14130 ptrdiff_t prop_pos
=
14131 string_buffer_position_lim (glyph
->object
, pos_before
,
14134 if (prop_pos
>= pos_before
)
14135 bpos_max
= prop_pos
- 1;
14137 if (INTEGERP (chprop
))
14139 bpos_covered
= bpos_max
+ XINT (chprop
);
14140 /* If the `cursor' property covers buffer positions up
14141 to and including point, we should display cursor on
14142 this glyph. Note that, if a `cursor' property on one
14143 of the string's characters has an integer value, we
14144 will break out of the loop below _before_ we get to
14145 the position match above. IOW, integer values of
14146 the `cursor' property override the "exact match for
14147 point" strategy of positioning the cursor. */
14148 /* Implementation note: bpos_max == pt_old when, e.g.,
14149 we are in an empty line, where bpos_max is set to
14150 MATRIX_ROW_START_CHARPOS, see above. */
14151 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14160 x
+= glyph
->pixel_width
;
14163 else if (glyph
> end
) /* row is reversed */
14164 while (!INTEGERP (glyph
->object
))
14166 if (BUFFERP (glyph
->object
))
14168 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14170 if (glyph
->charpos
> bpos_max
)
14171 bpos_max
= glyph
->charpos
;
14172 if (glyph
->charpos
< bpos_min
)
14173 bpos_min
= glyph
->charpos
;
14174 if (!glyph
->avoid_cursor_p
)
14178 match_with_avoid_cursor
= 0;
14181 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14183 pos_before
= glyph
->charpos
;
14184 glyph_before
= glyph
;
14186 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14188 pos_after
= glyph
->charpos
;
14189 glyph_after
= glyph
;
14192 else if (dpos
== 0)
14193 match_with_avoid_cursor
= 1;
14195 else if (STRINGP (glyph
->object
))
14197 Lisp_Object chprop
;
14198 ptrdiff_t glyph_pos
= glyph
->charpos
;
14200 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14202 if (!NILP (chprop
))
14204 ptrdiff_t prop_pos
=
14205 string_buffer_position_lim (glyph
->object
, pos_before
,
14208 if (prop_pos
>= pos_before
)
14209 bpos_max
= prop_pos
- 1;
14211 if (INTEGERP (chprop
))
14213 bpos_covered
= bpos_max
+ XINT (chprop
);
14214 /* If the `cursor' property covers buffer positions up
14215 to and including point, we should display cursor on
14217 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14226 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14228 x
--; /* can't use any pixel_width */
14231 x
-= glyph
->pixel_width
;
14234 /* Step 2: If we didn't find an exact match for point, we need to
14235 look for a proper place to put the cursor among glyphs between
14236 GLYPH_BEFORE and GLYPH_AFTER. */
14237 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14238 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14239 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14241 /* An empty line has a single glyph whose OBJECT is zero and
14242 whose CHARPOS is the position of a newline on that line.
14243 Note that on a TTY, there are more glyphs after that, which
14244 were produced by extend_face_to_end_of_line, but their
14245 CHARPOS is zero or negative. */
14247 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14248 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0;
14250 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14252 ptrdiff_t ellipsis_pos
;
14254 /* Scan back over the ellipsis glyphs. */
14255 if (!row
->reversed_p
)
14257 ellipsis_pos
= (glyph
- 1)->charpos
;
14258 while (glyph
> row
->glyphs
[TEXT_AREA
]
14259 && (glyph
- 1)->charpos
== ellipsis_pos
)
14260 glyph
--, x
-= glyph
->pixel_width
;
14261 /* That loop always goes one position too far, including
14262 the glyph before the ellipsis. So scan forward over
14264 x
+= glyph
->pixel_width
;
14267 else /* row is reversed */
14269 ellipsis_pos
= (glyph
+ 1)->charpos
;
14270 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14271 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14272 glyph
++, x
+= glyph
->pixel_width
;
14273 x
-= glyph
->pixel_width
;
14277 else if (match_with_avoid_cursor
)
14279 cursor
= glyph_after
;
14282 else if (string_seen
)
14284 int incr
= row
->reversed_p
? -1 : +1;
14286 /* Need to find the glyph that came out of a string which is
14287 present at point. That glyph is somewhere between
14288 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14289 positioned between POS_BEFORE and POS_AFTER in the
14291 struct glyph
*start
, *stop
;
14292 ptrdiff_t pos
= pos_before
;
14296 /* If the row ends in a newline from a display string,
14297 reordering could have moved the glyphs belonging to the
14298 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14299 in this case we extend the search to the last glyph in
14300 the row that was not inserted by redisplay. */
14301 if (row
->ends_in_newline_from_string_p
)
14304 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14307 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14308 correspond to POS_BEFORE and POS_AFTER, respectively. We
14309 need START and STOP in the order that corresponds to the
14310 row's direction as given by its reversed_p flag. If the
14311 directionality of characters between POS_BEFORE and
14312 POS_AFTER is the opposite of the row's base direction,
14313 these characters will have been reordered for display,
14314 and we need to reverse START and STOP. */
14315 if (!row
->reversed_p
)
14317 start
= min (glyph_before
, glyph_after
);
14318 stop
= max (glyph_before
, glyph_after
);
14322 start
= max (glyph_before
, glyph_after
);
14323 stop
= min (glyph_before
, glyph_after
);
14325 for (glyph
= start
+ incr
;
14326 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14329 /* Any glyphs that come from the buffer are here because
14330 of bidi reordering. Skip them, and only pay
14331 attention to glyphs that came from some string. */
14332 if (STRINGP (glyph
->object
))
14336 /* If the display property covers the newline, we
14337 need to search for it one position farther. */
14338 ptrdiff_t lim
= pos_after
14339 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14341 string_from_text_prop
= 0;
14342 str
= glyph
->object
;
14343 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14344 if (tem
== 0 /* from overlay */
14347 /* If the string from which this glyph came is
14348 found in the buffer at point, or at position
14349 that is closer to point than pos_after, then
14350 we've found the glyph we've been looking for.
14351 If it comes from an overlay (tem == 0), and
14352 it has the `cursor' property on one of its
14353 glyphs, record that glyph as a candidate for
14354 displaying the cursor. (As in the
14355 unidirectional version, we will display the
14356 cursor on the last candidate we find.) */
14359 || (tem
- pt_old
> 0 && tem
< pos_after
))
14361 /* The glyphs from this string could have
14362 been reordered. Find the one with the
14363 smallest string position. Or there could
14364 be a character in the string with the
14365 `cursor' property, which means display
14366 cursor on that character's glyph. */
14367 ptrdiff_t strpos
= glyph
->charpos
;
14372 string_from_text_prop
= 1;
14375 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14376 && EQ (glyph
->object
, str
);
14380 ptrdiff_t gpos
= glyph
->charpos
;
14382 cprop
= Fget_char_property (make_number (gpos
),
14390 if (tem
&& glyph
->charpos
< strpos
)
14392 strpos
= glyph
->charpos
;
14398 || (tem
- pt_old
> 0 && tem
< pos_after
))
14402 pos
= tem
+ 1; /* don't find previous instances */
14404 /* This string is not what we want; skip all of the
14405 glyphs that came from it. */
14406 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14407 && EQ (glyph
->object
, str
))
14414 /* If we reached the end of the line, and END was from a string,
14415 the cursor is not on this line. */
14417 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14418 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14419 && STRINGP (end
->object
)
14420 && row
->continued_p
)
14423 /* A truncated row may not include PT among its character positions.
14424 Setting the cursor inside the scroll margin will trigger
14425 recalculation of hscroll in hscroll_window_tree. But if a
14426 display string covers point, defer to the string-handling
14427 code below to figure this out. */
14428 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14430 cursor
= glyph_before
;
14433 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14434 /* Zero-width characters produce no glyphs. */
14436 && (row
->reversed_p
14437 ? glyph_after
> glyphs_end
14438 : glyph_after
< glyphs_end
)))
14440 cursor
= glyph_after
;
14446 if (cursor
!= NULL
)
14448 else if (glyph
== glyphs_end
14449 && pos_before
== pos_after
14450 && STRINGP ((row
->reversed_p
14451 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14452 : row
->glyphs
[TEXT_AREA
])->object
))
14454 /* If all the glyphs of this row came from strings, put the
14455 cursor on the first glyph of the row. This avoids having the
14456 cursor outside of the text area in this very rare and hard
14460 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14461 : row
->glyphs
[TEXT_AREA
];
14467 /* Need to compute x that corresponds to GLYPH. */
14468 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14470 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14472 x
+= g
->pixel_width
;
14476 /* ROW could be part of a continued line, which, under bidi
14477 reordering, might have other rows whose start and end charpos
14478 occlude point. Only set w->cursor if we found a better
14479 approximation to the cursor position than we have from previously
14480 examined candidate rows belonging to the same continued line. */
14481 if (/* we already have a candidate row */
14482 w
->cursor
.vpos
>= 0
14483 /* that candidate is not the row we are processing */
14484 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14485 /* Make sure cursor.vpos specifies a row whose start and end
14486 charpos occlude point, and it is valid candidate for being a
14487 cursor-row. This is because some callers of this function
14488 leave cursor.vpos at the row where the cursor was displayed
14489 during the last redisplay cycle. */
14490 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14491 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14492 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14495 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14497 /* Don't consider glyphs that are outside TEXT_AREA. */
14498 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14500 /* Keep the candidate whose buffer position is the closest to
14501 point or has the `cursor' property. */
14502 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14503 w
->cursor
.hpos
>= 0
14504 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14505 && ((BUFFERP (g1
->object
)
14506 && (g1
->charpos
== pt_old
/* an exact match always wins */
14507 || (BUFFERP (glyph
->object
)
14508 && eabs (g1
->charpos
- pt_old
)
14509 < eabs (glyph
->charpos
- pt_old
))))
14510 /* previous candidate is a glyph from a string that has
14511 a non-nil `cursor' property */
14512 || (STRINGP (g1
->object
)
14513 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14514 Qcursor
, g1
->object
))
14515 /* previous candidate is from the same display
14516 string as this one, and the display string
14517 came from a text property */
14518 || (EQ (g1
->object
, glyph
->object
)
14519 && string_from_text_prop
)
14520 /* this candidate is from newline and its
14521 position is not an exact match */
14522 || (INTEGERP (glyph
->object
)
14523 && glyph
->charpos
!= pt_old
)))))
14525 /* If this candidate gives an exact match, use that. */
14526 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14527 /* If this candidate is a glyph created for the
14528 terminating newline of a line, and point is on that
14529 newline, it wins because it's an exact match. */
14530 || (!row
->continued_p
14531 && INTEGERP (glyph
->object
)
14532 && glyph
->charpos
== 0
14533 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14534 /* Otherwise, keep the candidate that comes from a row
14535 spanning less buffer positions. This may win when one or
14536 both candidate positions are on glyphs that came from
14537 display strings, for which we cannot compare buffer
14539 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14540 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14541 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14544 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14546 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14547 w
->cursor
.y
= row
->y
+ dy
;
14549 if (w
== XWINDOW (selected_window
))
14551 if (!row
->continued_p
14552 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14555 this_line_buffer
= XBUFFER (w
->buffer
);
14557 CHARPOS (this_line_start_pos
)
14558 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14559 BYTEPOS (this_line_start_pos
)
14560 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14562 CHARPOS (this_line_end_pos
)
14563 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14564 BYTEPOS (this_line_end_pos
)
14565 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14567 this_line_y
= w
->cursor
.y
;
14568 this_line_pixel_height
= row
->height
;
14569 this_line_vpos
= w
->cursor
.vpos
;
14570 this_line_start_x
= row
->x
;
14573 CHARPOS (this_line_start_pos
) = 0;
14580 /* Run window scroll functions, if any, for WINDOW with new window
14581 start STARTP. Sets the window start of WINDOW to that position.
14583 We assume that the window's buffer is really current. */
14585 static struct text_pos
14586 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14588 struct window
*w
= XWINDOW (window
);
14589 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14591 if (current_buffer
!= XBUFFER (w
->buffer
))
14594 if (!NILP (Vwindow_scroll_functions
))
14596 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14597 make_number (CHARPOS (startp
)));
14598 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14599 /* In case the hook functions switch buffers. */
14600 set_buffer_internal (XBUFFER (w
->buffer
));
14607 /* Make sure the line containing the cursor is fully visible.
14608 A value of 1 means there is nothing to be done.
14609 (Either the line is fully visible, or it cannot be made so,
14610 or we cannot tell.)
14612 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14613 is higher than window.
14615 A value of 0 means the caller should do scrolling
14616 as if point had gone off the screen. */
14619 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14621 struct glyph_matrix
*matrix
;
14622 struct glyph_row
*row
;
14625 if (!make_cursor_line_fully_visible_p
)
14628 /* It's not always possible to find the cursor, e.g, when a window
14629 is full of overlay strings. Don't do anything in that case. */
14630 if (w
->cursor
.vpos
< 0)
14633 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14634 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14636 /* If the cursor row is not partially visible, there's nothing to do. */
14637 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14640 /* If the row the cursor is in is taller than the window's height,
14641 it's not clear what to do, so do nothing. */
14642 window_height
= window_box_height (w
);
14643 if (row
->height
>= window_height
)
14645 if (!force_p
|| MINI_WINDOW_P (w
)
14646 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14653 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14654 non-zero means only WINDOW is redisplayed in redisplay_internal.
14655 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14656 in redisplay_window to bring a partially visible line into view in
14657 the case that only the cursor has moved.
14659 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14660 last screen line's vertical height extends past the end of the screen.
14664 1 if scrolling succeeded
14666 0 if scrolling didn't find point.
14668 -1 if new fonts have been loaded so that we must interrupt
14669 redisplay, adjust glyph matrices, and try again. */
14675 SCROLLING_NEED_LARGER_MATRICES
14678 /* If scroll-conservatively is more than this, never recenter.
14680 If you change this, don't forget to update the doc string of
14681 `scroll-conservatively' and the Emacs manual. */
14682 #define SCROLL_LIMIT 100
14685 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14686 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14687 int temp_scroll_step
, int last_line_misfit
)
14689 struct window
*w
= XWINDOW (window
);
14690 struct frame
*f
= XFRAME (w
->frame
);
14691 struct text_pos pos
, startp
;
14693 int this_scroll_margin
, scroll_max
, rc
, height
;
14694 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14695 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14696 Lisp_Object aggressive
;
14697 /* We will never try scrolling more than this number of lines. */
14698 int scroll_limit
= SCROLL_LIMIT
;
14701 debug_method_add (w
, "try_scrolling");
14704 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14706 /* Compute scroll margin height in pixels. We scroll when point is
14707 within this distance from the top or bottom of the window. */
14708 if (scroll_margin
> 0)
14709 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
14710 * FRAME_LINE_HEIGHT (f
);
14712 this_scroll_margin
= 0;
14714 /* Force arg_scroll_conservatively to have a reasonable value, to
14715 avoid scrolling too far away with slow move_it_* functions. Note
14716 that the user can supply scroll-conservatively equal to
14717 `most-positive-fixnum', which can be larger than INT_MAX. */
14718 if (arg_scroll_conservatively
> scroll_limit
)
14720 arg_scroll_conservatively
= scroll_limit
+ 1;
14721 scroll_max
= scroll_limit
* FRAME_LINE_HEIGHT (f
);
14723 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14724 /* Compute how much we should try to scroll maximally to bring
14725 point into view. */
14726 scroll_max
= (max (scroll_step
,
14727 max (arg_scroll_conservatively
, temp_scroll_step
))
14728 * FRAME_LINE_HEIGHT (f
));
14729 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14730 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14731 /* We're trying to scroll because of aggressive scrolling but no
14732 scroll_step is set. Choose an arbitrary one. */
14733 scroll_max
= 10 * FRAME_LINE_HEIGHT (f
);
14739 /* Decide whether to scroll down. */
14740 if (PT
> CHARPOS (startp
))
14742 int scroll_margin_y
;
14744 /* Compute the pixel ypos of the scroll margin, then move IT to
14745 either that ypos or PT, whichever comes first. */
14746 start_display (&it
, w
, startp
);
14747 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14748 - FRAME_LINE_HEIGHT (f
) * extra_scroll_margin_lines
;
14749 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14750 (MOVE_TO_POS
| MOVE_TO_Y
));
14752 if (PT
> CHARPOS (it
.current
.pos
))
14754 int y0
= line_bottom_y (&it
);
14755 /* Compute how many pixels below window bottom to stop searching
14756 for PT. This avoids costly search for PT that is far away if
14757 the user limited scrolling by a small number of lines, but
14758 always finds PT if scroll_conservatively is set to a large
14759 number, such as most-positive-fixnum. */
14760 int slack
= max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
));
14761 int y_to_move
= it
.last_visible_y
+ slack
;
14763 /* Compute the distance from the scroll margin to PT or to
14764 the scroll limit, whichever comes first. This should
14765 include the height of the cursor line, to make that line
14767 move_it_to (&it
, PT
, -1, y_to_move
,
14768 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14769 dy
= line_bottom_y (&it
) - y0
;
14771 if (dy
> scroll_max
)
14772 return SCROLLING_FAILED
;
14781 /* Point is in or below the bottom scroll margin, so move the
14782 window start down. If scrolling conservatively, move it just
14783 enough down to make point visible. If scroll_step is set,
14784 move it down by scroll_step. */
14785 if (arg_scroll_conservatively
)
14787 = min (max (dy
, FRAME_LINE_HEIGHT (f
)),
14788 FRAME_LINE_HEIGHT (f
) * arg_scroll_conservatively
);
14789 else if (scroll_step
|| temp_scroll_step
)
14790 amount_to_scroll
= scroll_max
;
14793 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14794 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14795 if (NUMBERP (aggressive
))
14797 double float_amount
= XFLOATINT (aggressive
) * height
;
14798 int aggressive_scroll
= float_amount
;
14799 if (aggressive_scroll
== 0 && float_amount
> 0)
14800 aggressive_scroll
= 1;
14801 /* Don't let point enter the scroll margin near top of
14802 the window. This could happen if the value of
14803 scroll_up_aggressively is too large and there are
14804 non-zero margins, because scroll_up_aggressively
14805 means put point that fraction of window height
14806 _from_the_bottom_margin_. */
14807 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14808 aggressive_scroll
= height
- 2*this_scroll_margin
;
14809 amount_to_scroll
= dy
+ aggressive_scroll
;
14813 if (amount_to_scroll
<= 0)
14814 return SCROLLING_FAILED
;
14816 start_display (&it
, w
, startp
);
14817 if (arg_scroll_conservatively
<= scroll_limit
)
14818 move_it_vertically (&it
, amount_to_scroll
);
14821 /* Extra precision for users who set scroll-conservatively
14822 to a large number: make sure the amount we scroll
14823 the window start is never less than amount_to_scroll,
14824 which was computed as distance from window bottom to
14825 point. This matters when lines at window top and lines
14826 below window bottom have different height. */
14828 void *it1data
= NULL
;
14829 /* We use a temporary it1 because line_bottom_y can modify
14830 its argument, if it moves one line down; see there. */
14833 SAVE_IT (it1
, it
, it1data
);
14834 start_y
= line_bottom_y (&it1
);
14836 RESTORE_IT (&it
, &it
, it1data
);
14837 move_it_by_lines (&it
, 1);
14838 SAVE_IT (it1
, it
, it1data
);
14839 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14842 /* If STARTP is unchanged, move it down another screen line. */
14843 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14844 move_it_by_lines (&it
, 1);
14845 startp
= it
.current
.pos
;
14849 struct text_pos scroll_margin_pos
= startp
;
14851 /* See if point is inside the scroll margin at the top of the
14853 if (this_scroll_margin
)
14855 start_display (&it
, w
, startp
);
14856 move_it_vertically (&it
, this_scroll_margin
);
14857 scroll_margin_pos
= it
.current
.pos
;
14860 if (PT
< CHARPOS (scroll_margin_pos
))
14862 /* Point is in the scroll margin at the top of the window or
14863 above what is displayed in the window. */
14866 /* Compute the vertical distance from PT to the scroll
14867 margin position. Move as far as scroll_max allows, or
14868 one screenful, or 10 screen lines, whichever is largest.
14869 Give up if distance is greater than scroll_max or if we
14870 didn't reach the scroll margin position. */
14871 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14872 start_display (&it
, w
, pos
);
14874 y_to_move
= max (it
.last_visible_y
,
14875 max (scroll_max
, 10 * FRAME_LINE_HEIGHT (f
)));
14876 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14878 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14879 dy
= it
.current_y
- y0
;
14880 if (dy
> scroll_max
14881 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14882 return SCROLLING_FAILED
;
14884 /* Compute new window start. */
14885 start_display (&it
, w
, startp
);
14887 if (arg_scroll_conservatively
)
14888 amount_to_scroll
= max (dy
, FRAME_LINE_HEIGHT (f
) *
14889 max (scroll_step
, temp_scroll_step
));
14890 else if (scroll_step
|| temp_scroll_step
)
14891 amount_to_scroll
= scroll_max
;
14894 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14895 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14896 if (NUMBERP (aggressive
))
14898 double float_amount
= XFLOATINT (aggressive
) * height
;
14899 int aggressive_scroll
= float_amount
;
14900 if (aggressive_scroll
== 0 && float_amount
> 0)
14901 aggressive_scroll
= 1;
14902 /* Don't let point enter the scroll margin near
14903 bottom of the window, if the value of
14904 scroll_down_aggressively happens to be too
14906 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14907 aggressive_scroll
= height
- 2*this_scroll_margin
;
14908 amount_to_scroll
= dy
+ aggressive_scroll
;
14912 if (amount_to_scroll
<= 0)
14913 return SCROLLING_FAILED
;
14915 move_it_vertically_backward (&it
, amount_to_scroll
);
14916 startp
= it
.current
.pos
;
14920 /* Run window scroll functions. */
14921 startp
= run_window_scroll_functions (window
, startp
);
14923 /* Display the window. Give up if new fonts are loaded, or if point
14925 if (!try_window (window
, startp
, 0))
14926 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14927 else if (w
->cursor
.vpos
< 0)
14929 clear_glyph_matrix (w
->desired_matrix
);
14930 rc
= SCROLLING_FAILED
;
14934 /* Maybe forget recorded base line for line number display. */
14935 if (!just_this_one_p
14936 || current_buffer
->clip_changed
14937 || BEG_UNCHANGED
< CHARPOS (startp
))
14938 wset_base_line_number (w
, Qnil
);
14940 /* If cursor ends up on a partially visible line,
14941 treat that as being off the bottom of the screen. */
14942 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14943 /* It's possible that the cursor is on the first line of the
14944 buffer, which is partially obscured due to a vscroll
14945 (Bug#7537). In that case, avoid looping forever . */
14946 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14948 clear_glyph_matrix (w
->desired_matrix
);
14949 ++extra_scroll_margin_lines
;
14952 rc
= SCROLLING_SUCCESS
;
14959 /* Compute a suitable window start for window W if display of W starts
14960 on a continuation line. Value is non-zero if a new window start
14963 The new window start will be computed, based on W's width, starting
14964 from the start of the continued line. It is the start of the
14965 screen line with the minimum distance from the old start W->start. */
14968 compute_window_start_on_continuation_line (struct window
*w
)
14970 struct text_pos pos
, start_pos
;
14971 int window_start_changed_p
= 0;
14973 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14975 /* If window start is on a continuation line... Window start may be
14976 < BEGV in case there's invisible text at the start of the
14977 buffer (M-x rmail, for example). */
14978 if (CHARPOS (start_pos
) > BEGV
14979 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14982 struct glyph_row
*row
;
14984 /* Handle the case that the window start is out of range. */
14985 if (CHARPOS (start_pos
) < BEGV
)
14986 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14987 else if (CHARPOS (start_pos
) > ZV
)
14988 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14990 /* Find the start of the continued line. This should be fast
14991 because scan_buffer is fast (newline cache). */
14992 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14993 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14994 row
, DEFAULT_FACE_ID
);
14995 reseat_at_previous_visible_line_start (&it
);
14997 /* If the line start is "too far" away from the window start,
14998 say it takes too much time to compute a new window start. */
14999 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
15000 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
15002 int min_distance
, distance
;
15004 /* Move forward by display lines to find the new window
15005 start. If window width was enlarged, the new start can
15006 be expected to be > the old start. If window width was
15007 decreased, the new window start will be < the old start.
15008 So, we're looking for the display line start with the
15009 minimum distance from the old window start. */
15010 pos
= it
.current
.pos
;
15011 min_distance
= INFINITY
;
15012 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
15013 distance
< min_distance
)
15015 min_distance
= distance
;
15016 pos
= it
.current
.pos
;
15017 move_it_by_lines (&it
, 1);
15020 /* Set the window start there. */
15021 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
15022 window_start_changed_p
= 1;
15026 return window_start_changed_p
;
15030 /* Try cursor movement in case text has not changed in window WINDOW,
15031 with window start STARTP. Value is
15033 CURSOR_MOVEMENT_SUCCESS if successful
15035 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
15037 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
15038 display. *SCROLL_STEP is set to 1, under certain circumstances, if
15039 we want to scroll as if scroll-step were set to 1. See the code.
15041 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
15042 which case we have to abort this redisplay, and adjust matrices
15047 CURSOR_MOVEMENT_SUCCESS
,
15048 CURSOR_MOVEMENT_CANNOT_BE_USED
,
15049 CURSOR_MOVEMENT_MUST_SCROLL
,
15050 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
15054 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
15056 struct window
*w
= XWINDOW (window
);
15057 struct frame
*f
= XFRAME (w
->frame
);
15058 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
15061 if (inhibit_try_cursor_movement
)
15065 /* Previously, there was a check for Lisp integer in the
15066 if-statement below. Now, this field is converted to
15067 ptrdiff_t, thus zero means invalid position in a buffer. */
15068 eassert (w
->last_point
> 0);
15070 /* Handle case where text has not changed, only point, and it has
15071 not moved off the frame. */
15072 if (/* Point may be in this window. */
15073 PT
>= CHARPOS (startp
)
15074 /* Selective display hasn't changed. */
15075 && !current_buffer
->clip_changed
15076 /* Function force-mode-line-update is used to force a thorough
15077 redisplay. It sets either windows_or_buffers_changed or
15078 update_mode_lines. So don't take a shortcut here for these
15080 && !update_mode_lines
15081 && !windows_or_buffers_changed
15082 && !cursor_type_changed
15083 /* Can't use this case if highlighting a region. When a
15084 region exists, cursor movement has to do more than just
15086 && markpos_of_region () < 0
15087 && NILP (w
->region_showing
)
15088 && NILP (Vshow_trailing_whitespace
)
15089 /* This code is not used for mini-buffer for the sake of the case
15090 of redisplaying to replace an echo area message; since in
15091 that case the mini-buffer contents per se are usually
15092 unchanged. This code is of no real use in the mini-buffer
15093 since the handling of this_line_start_pos, etc., in redisplay
15094 handles the same cases. */
15095 && !EQ (window
, minibuf_window
)
15096 /* When splitting windows or for new windows, it happens that
15097 redisplay is called with a nil window_end_vpos or one being
15098 larger than the window. This should really be fixed in
15099 window.c. I don't have this on my list, now, so we do
15100 approximately the same as the old redisplay code. --gerd. */
15101 && INTEGERP (w
->window_end_vpos
)
15102 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
15103 && (FRAME_WINDOW_P (f
)
15104 || !overlay_arrow_in_current_buffer_p ()))
15106 int this_scroll_margin
, top_scroll_margin
;
15107 struct glyph_row
*row
= NULL
;
15110 debug_method_add (w
, "cursor movement");
15113 /* Scroll if point within this distance from the top or bottom
15114 of the window. This is a pixel value. */
15115 if (scroll_margin
> 0)
15117 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15118 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
15121 this_scroll_margin
= 0;
15123 top_scroll_margin
= this_scroll_margin
;
15124 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15125 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15127 /* Start with the row the cursor was displayed during the last
15128 not paused redisplay. Give up if that row is not valid. */
15129 if (w
->last_cursor
.vpos
< 0
15130 || w
->last_cursor
.vpos
>= w
->current_matrix
->nrows
)
15131 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15134 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor
.vpos
);
15135 if (row
->mode_line_p
)
15137 if (!row
->enabled_p
)
15138 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15141 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15143 int scroll_p
= 0, must_scroll
= 0;
15144 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15146 if (PT
> w
->last_point
)
15148 /* Point has moved forward. */
15149 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15150 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15152 eassert (row
->enabled_p
);
15156 /* If the end position of a row equals the start
15157 position of the next row, and PT is at that position,
15158 we would rather display cursor in the next line. */
15159 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15160 && MATRIX_ROW_END_CHARPOS (row
) == PT
15161 && row
< w
->current_matrix
->rows
15162 + w
->current_matrix
->nrows
- 1
15163 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15164 && !cursor_row_p (row
))
15167 /* If within the scroll margin, scroll. Note that
15168 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15169 the next line would be drawn, and that
15170 this_scroll_margin can be zero. */
15171 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15172 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15173 /* Line is completely visible last line in window
15174 and PT is to be set in the next line. */
15175 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15176 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15177 && !row
->ends_at_zv_p
15178 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15181 else if (PT
< w
->last_point
)
15183 /* Cursor has to be moved backward. Note that PT >=
15184 CHARPOS (startp) because of the outer if-statement. */
15185 while (!row
->mode_line_p
15186 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15187 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15188 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15189 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15190 row
> w
->current_matrix
->rows
15191 && (row
-1)->ends_in_newline_from_string_p
))))
15192 && (row
->y
> top_scroll_margin
15193 || CHARPOS (startp
) == BEGV
))
15195 eassert (row
->enabled_p
);
15199 /* Consider the following case: Window starts at BEGV,
15200 there is invisible, intangible text at BEGV, so that
15201 display starts at some point START > BEGV. It can
15202 happen that we are called with PT somewhere between
15203 BEGV and START. Try to handle that case. */
15204 if (row
< w
->current_matrix
->rows
15205 || row
->mode_line_p
)
15207 row
= w
->current_matrix
->rows
;
15208 if (row
->mode_line_p
)
15212 /* Due to newlines in overlay strings, we may have to
15213 skip forward over overlay strings. */
15214 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15215 && MATRIX_ROW_END_CHARPOS (row
) == PT
15216 && !cursor_row_p (row
))
15219 /* If within the scroll margin, scroll. */
15220 if (row
->y
< top_scroll_margin
15221 && CHARPOS (startp
) != BEGV
)
15226 /* Cursor did not move. So don't scroll even if cursor line
15227 is partially visible, as it was so before. */
15228 rc
= CURSOR_MOVEMENT_SUCCESS
;
15231 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15232 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15234 /* if PT is not in the glyph row, give up. */
15235 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15238 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15239 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15241 struct glyph_row
*row1
;
15243 /* If rows are bidi-reordered and point moved, back up
15244 until we find a row that does not belong to a
15245 continuation line. This is because we must consider
15246 all rows of a continued line as candidates for the
15247 new cursor positioning, since row start and end
15248 positions change non-linearly with vertical position
15250 /* FIXME: Revisit this when glyph ``spilling'' in
15251 continuation lines' rows is implemented for
15252 bidi-reordered rows. */
15253 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15254 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15257 /* If we hit the beginning of the displayed portion
15258 without finding the first row of a continued
15262 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15265 eassert (row
->enabled_p
);
15270 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15271 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15272 /* Make sure this isn't a header line by any chance, since
15273 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15274 && !row
->mode_line_p
15275 && make_cursor_line_fully_visible_p
)
15277 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15278 && !row
->ends_at_zv_p
15279 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15280 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15281 else if (row
->height
> window_box_height (w
))
15283 /* If we end up in a partially visible line, let's
15284 make it fully visible, except when it's taller
15285 than the window, in which case we can't do much
15288 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15292 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15293 if (!cursor_row_fully_visible_p (w
, 0, 1))
15294 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15296 rc
= CURSOR_MOVEMENT_SUCCESS
;
15300 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15301 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15302 && !NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
15304 /* With bidi-reordered rows, there could be more than
15305 one candidate row whose start and end positions
15306 occlude point. We need to let set_cursor_from_row
15307 find the best candidate. */
15308 /* FIXME: Revisit this when glyph ``spilling'' in
15309 continuation lines' rows is implemented for
15310 bidi-reordered rows. */
15315 int at_zv_p
= 0, exact_match_p
= 0;
15317 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15318 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15319 && cursor_row_p (row
))
15320 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15322 /* As soon as we've found the exact match for point,
15323 or the first suitable row whose ends_at_zv_p flag
15324 is set, we are done. */
15326 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15328 && w
->cursor
.hpos
>= 0
15329 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15332 struct glyph_row
*candidate
=
15333 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15335 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15336 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15339 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15340 || (INTEGERP (g
->object
)
15341 && (g
->charpos
== PT
15342 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15344 if (rv
&& (at_zv_p
|| exact_match_p
))
15346 rc
= CURSOR_MOVEMENT_SUCCESS
;
15349 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15353 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15354 || row
->continued_p
)
15355 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15356 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15357 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15358 /* If we didn't find any candidate rows, or exited the
15359 loop before all the candidates were examined, signal
15360 to the caller that this method failed. */
15361 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15363 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15364 && !row
->continued_p
))
15365 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15367 rc
= CURSOR_MOVEMENT_SUCCESS
;
15373 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15375 rc
= CURSOR_MOVEMENT_SUCCESS
;
15380 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15381 && MATRIX_ROW_START_CHARPOS (row
) == PT
15382 && cursor_row_p (row
));
15390 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15394 set_vertical_scroll_bar (struct window
*w
)
15396 ptrdiff_t start
, end
, whole
;
15398 /* Calculate the start and end positions for the current window.
15399 At some point, it would be nice to choose between scrollbars
15400 which reflect the whole buffer size, with special markers
15401 indicating narrowing, and scrollbars which reflect only the
15404 Note that mini-buffers sometimes aren't displaying any text. */
15405 if (!MINI_WINDOW_P (w
)
15406 || (w
== XWINDOW (minibuf_window
)
15407 && NILP (echo_area_buffer
[0])))
15409 struct buffer
*buf
= XBUFFER (w
->buffer
);
15410 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15411 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15412 /* I don't think this is guaranteed to be right. For the
15413 moment, we'll pretend it is. */
15414 end
= BUF_Z (buf
) - XFASTINT (w
->window_end_pos
) - BUF_BEGV (buf
);
15418 if (whole
< (end
- start
))
15419 whole
= end
- start
;
15422 start
= end
= whole
= 0;
15424 /* Indicate what this scroll bar ought to be displaying now. */
15425 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15426 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15427 (w
, end
- start
, whole
, start
);
15431 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15432 selected_window is redisplayed.
15434 We can return without actually redisplaying the window if
15435 fonts_changed_p. In that case, redisplay_internal will
15439 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15441 struct window
*w
= XWINDOW (window
);
15442 struct frame
*f
= XFRAME (w
->frame
);
15443 struct buffer
*buffer
= XBUFFER (w
->buffer
);
15444 struct buffer
*old
= current_buffer
;
15445 struct text_pos lpoint
, opoint
, startp
;
15446 int update_mode_line
;
15449 /* Record it now because it's overwritten. */
15450 int current_matrix_up_to_date_p
= 0;
15451 int used_current_matrix_p
= 0;
15452 /* This is less strict than current_matrix_up_to_date_p.
15453 It indicates that the buffer contents and narrowing are unchanged. */
15454 int buffer_unchanged_p
= 0;
15455 int temp_scroll_step
= 0;
15456 ptrdiff_t count
= SPECPDL_INDEX ();
15458 int centering_position
= -1;
15459 int last_line_misfit
= 0;
15460 ptrdiff_t beg_unchanged
, end_unchanged
;
15462 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15465 /* W must be a leaf window here. */
15466 eassert (!NILP (w
->buffer
));
15468 *w
->desired_matrix
->method
= 0;
15472 reconsider_clip_changes (w
, buffer
);
15474 /* Has the mode line to be updated? */
15475 update_mode_line
= (w
->update_mode_line
15476 || update_mode_lines
15477 || buffer
->clip_changed
15478 || buffer
->prevent_redisplay_optimizations_p
);
15480 if (MINI_WINDOW_P (w
))
15482 if (w
== XWINDOW (echo_area_window
)
15483 && !NILP (echo_area_buffer
[0]))
15485 if (update_mode_line
)
15486 /* We may have to update a tty frame's menu bar or a
15487 tool-bar. Example `M-x C-h C-h C-g'. */
15488 goto finish_menu_bars
;
15490 /* We've already displayed the echo area glyphs in this window. */
15491 goto finish_scroll_bars
;
15493 else if ((w
!= XWINDOW (minibuf_window
)
15494 || minibuf_level
== 0)
15495 /* When buffer is nonempty, redisplay window normally. */
15496 && BUF_Z (XBUFFER (w
->buffer
)) == BUF_BEG (XBUFFER (w
->buffer
))
15497 /* Quail displays non-mini buffers in minibuffer window.
15498 In that case, redisplay the window normally. */
15499 && !NILP (Fmemq (w
->buffer
, Vminibuffer_list
)))
15501 /* W is a mini-buffer window, but it's not active, so clear
15503 int yb
= window_text_bottom_y (w
);
15504 struct glyph_row
*row
;
15507 for (y
= 0, row
= w
->desired_matrix
->rows
;
15509 y
+= row
->height
, ++row
)
15510 blank_row (w
, row
, y
);
15511 goto finish_scroll_bars
;
15514 clear_glyph_matrix (w
->desired_matrix
);
15517 /* Otherwise set up data on this window; select its buffer and point
15519 /* Really select the buffer, for the sake of buffer-local
15521 set_buffer_internal_1 (XBUFFER (w
->buffer
));
15523 current_matrix_up_to_date_p
15524 = (!NILP (w
->window_end_valid
)
15525 && !current_buffer
->clip_changed
15526 && !current_buffer
->prevent_redisplay_optimizations_p
15527 && !window_outdated (w
));
15529 /* Run the window-bottom-change-functions
15530 if it is possible that the text on the screen has changed
15531 (either due to modification of the text, or any other reason). */
15532 if (!current_matrix_up_to_date_p
15533 && !NILP (Vwindow_text_change_functions
))
15535 safe_run_hooks (Qwindow_text_change_functions
);
15539 beg_unchanged
= BEG_UNCHANGED
;
15540 end_unchanged
= END_UNCHANGED
;
15542 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15544 specbind (Qinhibit_point_motion_hooks
, Qt
);
15547 = (!NILP (w
->window_end_valid
)
15548 && !current_buffer
->clip_changed
15549 && !window_outdated (w
));
15551 /* When windows_or_buffers_changed is non-zero, we can't rely on
15552 the window end being valid, so set it to nil there. */
15553 if (windows_or_buffers_changed
)
15555 /* If window starts on a continuation line, maybe adjust the
15556 window start in case the window's width changed. */
15557 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15558 compute_window_start_on_continuation_line (w
);
15560 wset_window_end_valid (w
, Qnil
);
15563 /* Some sanity checks. */
15564 CHECK_WINDOW_END (w
);
15565 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15567 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15570 if (mode_line_update_needed (w
))
15571 update_mode_line
= 1;
15573 /* Point refers normally to the selected window. For any other
15574 window, set up appropriate value. */
15575 if (!EQ (window
, selected_window
))
15577 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15578 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15582 new_pt_byte
= BEGV_BYTE
;
15583 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15585 else if (new_pt
> (ZV
- 1))
15588 new_pt_byte
= ZV_BYTE
;
15589 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15592 /* We don't use SET_PT so that the point-motion hooks don't run. */
15593 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15596 /* If any of the character widths specified in the display table
15597 have changed, invalidate the width run cache. It's true that
15598 this may be a bit late to catch such changes, but the rest of
15599 redisplay goes (non-fatally) haywire when the display table is
15600 changed, so why should we worry about doing any better? */
15601 if (current_buffer
->width_run_cache
)
15603 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15605 if (! disptab_matches_widthtab
15606 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15608 invalidate_region_cache (current_buffer
,
15609 current_buffer
->width_run_cache
,
15611 recompute_width_table (current_buffer
, disptab
);
15615 /* If window-start is screwed up, choose a new one. */
15616 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15619 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15621 /* If someone specified a new starting point but did not insist,
15622 check whether it can be used. */
15623 if (w
->optional_new_start
15624 && CHARPOS (startp
) >= BEGV
15625 && CHARPOS (startp
) <= ZV
)
15627 w
->optional_new_start
= 0;
15628 start_display (&it
, w
, startp
);
15629 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15630 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15631 if (IT_CHARPOS (it
) == PT
)
15632 w
->force_start
= 1;
15633 /* IT may overshoot PT if text at PT is invisible. */
15634 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15635 w
->force_start
= 1;
15640 /* Handle case where place to start displaying has been specified,
15641 unless the specified location is outside the accessible range. */
15642 if (w
->force_start
|| w
->frozen_window_start_p
)
15644 /* We set this later on if we have to adjust point. */
15647 w
->force_start
= 0;
15649 wset_window_end_valid (w
, Qnil
);
15651 /* Forget any recorded base line for line number display. */
15652 if (!buffer_unchanged_p
)
15653 wset_base_line_number (w
, Qnil
);
15655 /* Redisplay the mode line. Select the buffer properly for that.
15656 Also, run the hook window-scroll-functions
15657 because we have scrolled. */
15658 /* Note, we do this after clearing force_start because
15659 if there's an error, it is better to forget about force_start
15660 than to get into an infinite loop calling the hook functions
15661 and having them get more errors. */
15662 if (!update_mode_line
15663 || ! NILP (Vwindow_scroll_functions
))
15665 update_mode_line
= 1;
15666 w
->update_mode_line
= 1;
15667 startp
= run_window_scroll_functions (window
, startp
);
15670 w
->last_modified
= 0;
15671 w
->last_overlay_modified
= 0;
15672 if (CHARPOS (startp
) < BEGV
)
15673 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15674 else if (CHARPOS (startp
) > ZV
)
15675 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15677 /* Redisplay, then check if cursor has been set during the
15678 redisplay. Give up if new fonts were loaded. */
15679 /* We used to issue a CHECK_MARGINS argument to try_window here,
15680 but this causes scrolling to fail when point begins inside
15681 the scroll margin (bug#148) -- cyd */
15682 if (!try_window (window
, startp
, 0))
15684 w
->force_start
= 1;
15685 clear_glyph_matrix (w
->desired_matrix
);
15686 goto need_larger_matrices
;
15689 if (w
->cursor
.vpos
< 0 && !w
->frozen_window_start_p
)
15691 /* If point does not appear, try to move point so it does
15692 appear. The desired matrix has been built above, so we
15693 can use it here. */
15694 new_vpos
= window_box_height (w
) / 2;
15697 if (!cursor_row_fully_visible_p (w
, 0, 0))
15699 /* Point does appear, but on a line partly visible at end of window.
15700 Move it back to a fully-visible line. */
15701 new_vpos
= window_box_height (w
);
15703 else if (w
->cursor
.vpos
>=0)
15705 /* Some people insist on not letting point enter the scroll
15706 margin, even though this part handles windows that didn't
15708 struct frame
*f
= XFRAME (w
->frame
);
15709 int margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
15710 int pixel_margin
= margin
* FRAME_LINE_HEIGHT (f
);
15711 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15713 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15714 below, which finds the row to move point to, advances by
15715 the Y coordinate of the _next_ row, see the definition of
15716 MATRIX_ROW_BOTTOM_Y. */
15717 if (w
->cursor
.vpos
< margin
+ header_line
)
15719 = pixel_margin
+ (header_line
15720 ? CURRENT_HEADER_LINE_HEIGHT (w
)
15721 : 0) + FRAME_LINE_HEIGHT (f
);
15724 int window_height
= window_box_height (w
);
15727 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15728 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15729 new_vpos
= window_height
- pixel_margin
;
15733 /* If we need to move point for either of the above reasons,
15734 now actually do it. */
15737 struct glyph_row
*row
;
15739 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15740 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15743 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15744 MATRIX_ROW_START_BYTEPOS (row
));
15746 if (w
!= XWINDOW (selected_window
))
15747 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15748 else if (current_buffer
== old
)
15749 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15751 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15753 /* If we are highlighting the region, then we just changed
15754 the region, so redisplay to show it. */
15755 if (0 <= markpos_of_region ())
15757 clear_glyph_matrix (w
->desired_matrix
);
15758 if (!try_window (window
, startp
, 0))
15759 goto need_larger_matrices
;
15764 debug_method_add (w
, "forced window start");
15769 /* Handle case where text has not changed, only point, and it has
15770 not moved off the frame, and we are not retrying after hscroll.
15771 (current_matrix_up_to_date_p is nonzero when retrying.) */
15772 if (current_matrix_up_to_date_p
15773 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15774 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15778 case CURSOR_MOVEMENT_SUCCESS
:
15779 used_current_matrix_p
= 1;
15782 case CURSOR_MOVEMENT_MUST_SCROLL
:
15783 goto try_to_scroll
;
15789 /* If current starting point was originally the beginning of a line
15790 but no longer is, find a new starting point. */
15791 else if (w
->start_at_line_beg
15792 && !(CHARPOS (startp
) <= BEGV
15793 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15796 debug_method_add (w
, "recenter 1");
15801 /* Try scrolling with try_window_id. Value is > 0 if update has
15802 been done, it is -1 if we know that the same window start will
15803 not work. It is 0 if unsuccessful for some other reason. */
15804 else if ((tem
= try_window_id (w
)) != 0)
15807 debug_method_add (w
, "try_window_id %d", tem
);
15810 if (fonts_changed_p
)
15811 goto need_larger_matrices
;
15815 /* Otherwise try_window_id has returned -1 which means that we
15816 don't want the alternative below this comment to execute. */
15818 else if (CHARPOS (startp
) >= BEGV
15819 && CHARPOS (startp
) <= ZV
15820 && PT
>= CHARPOS (startp
)
15821 && (CHARPOS (startp
) < ZV
15822 /* Avoid starting at end of buffer. */
15823 || CHARPOS (startp
) == BEGV
15824 || !window_outdated (w
)))
15826 int d1
, d2
, d3
, d4
, d5
, d6
;
15828 /* If first window line is a continuation line, and window start
15829 is inside the modified region, but the first change is before
15830 current window start, we must select a new window start.
15832 However, if this is the result of a down-mouse event (e.g. by
15833 extending the mouse-drag-overlay), we don't want to select a
15834 new window start, since that would change the position under
15835 the mouse, resulting in an unwanted mouse-movement rather
15836 than a simple mouse-click. */
15837 if (!w
->start_at_line_beg
15838 && NILP (do_mouse_tracking
)
15839 && CHARPOS (startp
) > BEGV
15840 && CHARPOS (startp
) > BEG
+ beg_unchanged
15841 && CHARPOS (startp
) <= Z
- end_unchanged
15842 /* Even if w->start_at_line_beg is nil, a new window may
15843 start at a line_beg, since that's how set_buffer_window
15844 sets it. So, we need to check the return value of
15845 compute_window_start_on_continuation_line. (See also
15847 && XMARKER (w
->start
)->buffer
== current_buffer
15848 && compute_window_start_on_continuation_line (w
)
15849 /* It doesn't make sense to force the window start like we
15850 do at label force_start if it is already known that point
15851 will not be visible in the resulting window, because
15852 doing so will move point from its correct position
15853 instead of scrolling the window to bring point into view.
15855 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15857 w
->force_start
= 1;
15858 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15863 debug_method_add (w
, "same window start");
15866 /* Try to redisplay starting at same place as before.
15867 If point has not moved off frame, accept the results. */
15868 if (!current_matrix_up_to_date_p
15869 /* Don't use try_window_reusing_current_matrix in this case
15870 because a window scroll function can have changed the
15872 || !NILP (Vwindow_scroll_functions
)
15873 || MINI_WINDOW_P (w
)
15874 || !(used_current_matrix_p
15875 = try_window_reusing_current_matrix (w
)))
15877 IF_DEBUG (debug_method_add (w
, "1"));
15878 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15879 /* -1 means we need to scroll.
15880 0 means we need new matrices, but fonts_changed_p
15881 is set in that case, so we will detect it below. */
15882 goto try_to_scroll
;
15885 if (fonts_changed_p
)
15886 goto need_larger_matrices
;
15888 if (w
->cursor
.vpos
>= 0)
15890 if (!just_this_one_p
15891 || current_buffer
->clip_changed
15892 || BEG_UNCHANGED
< CHARPOS (startp
))
15893 /* Forget any recorded base line for line number display. */
15894 wset_base_line_number (w
, Qnil
);
15896 if (!cursor_row_fully_visible_p (w
, 1, 0))
15898 clear_glyph_matrix (w
->desired_matrix
);
15899 last_line_misfit
= 1;
15901 /* Drop through and scroll. */
15906 clear_glyph_matrix (w
->desired_matrix
);
15911 w
->last_modified
= 0;
15912 w
->last_overlay_modified
= 0;
15914 /* Redisplay the mode line. Select the buffer properly for that. */
15915 if (!update_mode_line
)
15917 update_mode_line
= 1;
15918 w
->update_mode_line
= 1;
15921 /* Try to scroll by specified few lines. */
15922 if ((scroll_conservatively
15923 || emacs_scroll_step
15924 || temp_scroll_step
15925 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15926 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15927 && CHARPOS (startp
) >= BEGV
15928 && CHARPOS (startp
) <= ZV
)
15930 /* The function returns -1 if new fonts were loaded, 1 if
15931 successful, 0 if not successful. */
15932 int ss
= try_scrolling (window
, just_this_one_p
,
15933 scroll_conservatively
,
15935 temp_scroll_step
, last_line_misfit
);
15938 case SCROLLING_SUCCESS
:
15941 case SCROLLING_NEED_LARGER_MATRICES
:
15942 goto need_larger_matrices
;
15944 case SCROLLING_FAILED
:
15952 /* Finally, just choose a place to start which positions point
15953 according to user preferences. */
15958 debug_method_add (w
, "recenter");
15961 /* w->vscroll = 0; */
15963 /* Forget any previously recorded base line for line number display. */
15964 if (!buffer_unchanged_p
)
15965 wset_base_line_number (w
, Qnil
);
15967 /* Determine the window start relative to point. */
15968 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15969 it
.current_y
= it
.last_visible_y
;
15970 if (centering_position
< 0)
15974 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
15976 ptrdiff_t margin_pos
= CHARPOS (startp
);
15977 Lisp_Object aggressive
;
15980 /* If there is a scroll margin at the top of the window, find
15981 its character position. */
15983 /* Cannot call start_display if startp is not in the
15984 accessible region of the buffer. This can happen when we
15985 have just switched to a different buffer and/or changed
15986 its restriction. In that case, startp is initialized to
15987 the character position 1 (BEGV) because we did not yet
15988 have chance to display the buffer even once. */
15989 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15992 void *it1data
= NULL
;
15994 SAVE_IT (it1
, it
, it1data
);
15995 start_display (&it1
, w
, startp
);
15996 move_it_vertically (&it1
, margin
* FRAME_LINE_HEIGHT (f
));
15997 margin_pos
= IT_CHARPOS (it1
);
15998 RESTORE_IT (&it
, &it
, it1data
);
16000 scrolling_up
= PT
> margin_pos
;
16003 ? BVAR (current_buffer
, scroll_up_aggressively
)
16004 : BVAR (current_buffer
, scroll_down_aggressively
);
16006 if (!MINI_WINDOW_P (w
)
16007 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
16011 /* Setting scroll-conservatively overrides
16012 scroll-*-aggressively. */
16013 if (!scroll_conservatively
&& NUMBERP (aggressive
))
16015 double float_amount
= XFLOATINT (aggressive
);
16017 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
16018 if (pt_offset
== 0 && float_amount
> 0)
16020 if (pt_offset
&& margin
> 0)
16023 /* Compute how much to move the window start backward from
16024 point so that point will be displayed where the user
16028 centering_position
= it
.last_visible_y
;
16030 centering_position
-= pt_offset
;
16031 centering_position
-=
16032 FRAME_LINE_HEIGHT (f
) * (1 + margin
+ (last_line_misfit
!= 0))
16033 + WINDOW_HEADER_LINE_HEIGHT (w
);
16034 /* Don't let point enter the scroll margin near top of
16036 if (centering_position
< margin
* FRAME_LINE_HEIGHT (f
))
16037 centering_position
= margin
* FRAME_LINE_HEIGHT (f
);
16040 centering_position
= margin
* FRAME_LINE_HEIGHT (f
) + pt_offset
;
16043 /* Set the window start half the height of the window backward
16045 centering_position
= window_box_height (w
) / 2;
16047 move_it_vertically_backward (&it
, centering_position
);
16049 eassert (IT_CHARPOS (it
) >= BEGV
);
16051 /* The function move_it_vertically_backward may move over more
16052 than the specified y-distance. If it->w is small, e.g. a
16053 mini-buffer window, we may end up in front of the window's
16054 display area. Start displaying at the start of the line
16055 containing PT in this case. */
16056 if (it
.current_y
<= 0)
16058 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
16059 move_it_vertically_backward (&it
, 0);
16063 it
.current_x
= it
.hpos
= 0;
16065 /* Set the window start position here explicitly, to avoid an
16066 infinite loop in case the functions in window-scroll-functions
16068 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
16070 /* Run scroll hooks. */
16071 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
16073 /* Redisplay the window. */
16074 if (!current_matrix_up_to_date_p
16075 || windows_or_buffers_changed
16076 || cursor_type_changed
16077 /* Don't use try_window_reusing_current_matrix in this case
16078 because it can have changed the buffer. */
16079 || !NILP (Vwindow_scroll_functions
)
16080 || !just_this_one_p
16081 || MINI_WINDOW_P (w
)
16082 || !(used_current_matrix_p
16083 = try_window_reusing_current_matrix (w
)))
16084 try_window (window
, startp
, 0);
16086 /* If new fonts have been loaded (due to fontsets), give up. We
16087 have to start a new redisplay since we need to re-adjust glyph
16089 if (fonts_changed_p
)
16090 goto need_larger_matrices
;
16092 /* If cursor did not appear assume that the middle of the window is
16093 in the first line of the window. Do it again with the next line.
16094 (Imagine a window of height 100, displaying two lines of height
16095 60. Moving back 50 from it->last_visible_y will end in the first
16097 if (w
->cursor
.vpos
< 0)
16099 if (!NILP (w
->window_end_valid
)
16100 && PT
>= Z
- XFASTINT (w
->window_end_pos
))
16102 clear_glyph_matrix (w
->desired_matrix
);
16103 move_it_by_lines (&it
, 1);
16104 try_window (window
, it
.current
.pos
, 0);
16106 else if (PT
< IT_CHARPOS (it
))
16108 clear_glyph_matrix (w
->desired_matrix
);
16109 move_it_by_lines (&it
, -1);
16110 try_window (window
, it
.current
.pos
, 0);
16114 /* Not much we can do about it. */
16118 /* Consider the following case: Window starts at BEGV, there is
16119 invisible, intangible text at BEGV, so that display starts at
16120 some point START > BEGV. It can happen that we are called with
16121 PT somewhere between BEGV and START. Try to handle that case. */
16122 if (w
->cursor
.vpos
< 0)
16124 struct glyph_row
*row
= w
->current_matrix
->rows
;
16125 if (row
->mode_line_p
)
16127 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16130 if (!cursor_row_fully_visible_p (w
, 0, 0))
16132 /* If vscroll is enabled, disable it and try again. */
16136 clear_glyph_matrix (w
->desired_matrix
);
16140 /* Users who set scroll-conservatively to a large number want
16141 point just above/below the scroll margin. If we ended up
16142 with point's row partially visible, move the window start to
16143 make that row fully visible and out of the margin. */
16144 if (scroll_conservatively
> SCROLL_LIMIT
)
16148 ? min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4)
16150 int move_down
= w
->cursor
.vpos
>= WINDOW_TOTAL_LINES (w
) / 2;
16152 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16153 clear_glyph_matrix (w
->desired_matrix
);
16154 if (1 == try_window (window
, it
.current
.pos
,
16155 TRY_WINDOW_CHECK_MARGINS
))
16159 /* If centering point failed to make the whole line visible,
16160 put point at the top instead. That has to make the whole line
16161 visible, if it can be done. */
16162 if (centering_position
== 0)
16165 clear_glyph_matrix (w
->desired_matrix
);
16166 centering_position
= 0;
16172 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16173 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16174 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16176 /* Display the mode line, if we must. */
16177 if ((update_mode_line
16178 /* If window not full width, must redo its mode line
16179 if (a) the window to its side is being redone and
16180 (b) we do a frame-based redisplay. This is a consequence
16181 of how inverted lines are drawn in frame-based redisplay. */
16182 || (!just_this_one_p
16183 && !FRAME_WINDOW_P (f
)
16184 && !WINDOW_FULL_WIDTH_P (w
))
16185 /* Line number to display. */
16186 || INTEGERP (w
->base_line_pos
)
16187 /* Column number is displayed and different from the one displayed. */
16188 || (!NILP (w
->column_number_displayed
)
16189 && (XFASTINT (w
->column_number_displayed
) != current_column ())))
16190 /* This means that the window has a mode line. */
16191 && (WINDOW_WANTS_MODELINE_P (w
)
16192 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16194 display_mode_lines (w
);
16196 /* If mode line height has changed, arrange for a thorough
16197 immediate redisplay using the correct mode line height. */
16198 if (WINDOW_WANTS_MODELINE_P (w
)
16199 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16201 fonts_changed_p
= 1;
16202 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16203 = DESIRED_MODE_LINE_HEIGHT (w
);
16206 /* If header line height has changed, arrange for a thorough
16207 immediate redisplay using the correct header line height. */
16208 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16209 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16211 fonts_changed_p
= 1;
16212 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16213 = DESIRED_HEADER_LINE_HEIGHT (w
);
16216 if (fonts_changed_p
)
16217 goto need_larger_matrices
;
16220 if (!line_number_displayed
16221 && !BUFFERP (w
->base_line_pos
))
16223 wset_base_line_pos (w
, Qnil
);
16224 wset_base_line_number (w
, Qnil
);
16229 /* When we reach a frame's selected window, redo the frame's menu bar. */
16230 if (update_mode_line
16231 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16233 int redisplay_menu_p
= 0;
16235 if (FRAME_WINDOW_P (f
))
16237 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16238 || defined (HAVE_NS) || defined (USE_GTK)
16239 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16241 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16245 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16247 if (redisplay_menu_p
)
16248 display_menu_bar (w
);
16250 #ifdef HAVE_WINDOW_SYSTEM
16251 if (FRAME_WINDOW_P (f
))
16253 #if defined (USE_GTK) || defined (HAVE_NS)
16254 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16255 redisplay_tool_bar (f
);
16257 if (WINDOWP (f
->tool_bar_window
)
16258 && (FRAME_TOOL_BAR_LINES (f
) > 0
16259 || !NILP (Vauto_resize_tool_bars
))
16260 && redisplay_tool_bar (f
))
16261 ignore_mouse_drag_p
= 1;
16267 #ifdef HAVE_WINDOW_SYSTEM
16268 if (FRAME_WINDOW_P (f
)
16269 && update_window_fringes (w
, (just_this_one_p
16270 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16271 || w
->pseudo_window_p
)))
16275 if (draw_window_fringes (w
, 1))
16276 x_draw_vertical_border (w
);
16280 #endif /* HAVE_WINDOW_SYSTEM */
16282 /* We go to this label, with fonts_changed_p set,
16283 if it is necessary to try again using larger glyph matrices.
16284 We have to redeem the scroll bar even in this case,
16285 because the loop in redisplay_internal expects that. */
16286 need_larger_matrices
:
16288 finish_scroll_bars
:
16290 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16292 /* Set the thumb's position and size. */
16293 set_vertical_scroll_bar (w
);
16295 /* Note that we actually used the scroll bar attached to this
16296 window, so it shouldn't be deleted at the end of redisplay. */
16297 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16298 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16301 /* Restore current_buffer and value of point in it. The window
16302 update may have changed the buffer, so first make sure `opoint'
16303 is still valid (Bug#6177). */
16304 if (CHARPOS (opoint
) < BEGV
)
16305 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16306 else if (CHARPOS (opoint
) > ZV
)
16307 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16309 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16311 set_buffer_internal_1 (old
);
16312 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16313 shorter. This can be caused by log truncation in *Messages*. */
16314 if (CHARPOS (lpoint
) <= ZV
)
16315 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16317 unbind_to (count
, Qnil
);
16321 /* Build the complete desired matrix of WINDOW with a window start
16322 buffer position POS.
16324 Value is 1 if successful. It is zero if fonts were loaded during
16325 redisplay which makes re-adjusting glyph matrices necessary, and -1
16326 if point would appear in the scroll margins.
16327 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16328 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16332 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16334 struct window
*w
= XWINDOW (window
);
16336 struct glyph_row
*last_text_row
= NULL
;
16337 struct frame
*f
= XFRAME (w
->frame
);
16339 /* Make POS the new window start. */
16340 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16342 /* Mark cursor position as unknown. No overlay arrow seen. */
16343 w
->cursor
.vpos
= -1;
16344 overlay_arrow_seen
= 0;
16346 /* Initialize iterator and info to start at POS. */
16347 start_display (&it
, w
, pos
);
16349 /* Display all lines of W. */
16350 while (it
.current_y
< it
.last_visible_y
)
16352 if (display_line (&it
))
16353 last_text_row
= it
.glyph_row
- 1;
16354 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16358 /* Don't let the cursor end in the scroll margins. */
16359 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16360 && !MINI_WINDOW_P (w
))
16362 int this_scroll_margin
;
16364 if (scroll_margin
> 0)
16366 this_scroll_margin
= min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4);
16367 this_scroll_margin
*= FRAME_LINE_HEIGHT (f
);
16370 this_scroll_margin
= 0;
16372 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16373 && w
->cursor
.y
< this_scroll_margin
16374 && CHARPOS (pos
) > BEGV
16375 && IT_CHARPOS (it
) < ZV
)
16376 /* rms: considering make_cursor_line_fully_visible_p here
16377 seems to give wrong results. We don't want to recenter
16378 when the last line is partly visible, we want to allow
16379 that case to be handled in the usual way. */
16380 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16382 w
->cursor
.vpos
= -1;
16383 clear_glyph_matrix (w
->desired_matrix
);
16388 /* If bottom moved off end of frame, change mode line percentage. */
16389 if (XFASTINT (w
->window_end_pos
) <= 0
16390 && Z
!= IT_CHARPOS (it
))
16391 w
->update_mode_line
= 1;
16393 /* Set window_end_pos to the offset of the last character displayed
16394 on the window from the end of current_buffer. Set
16395 window_end_vpos to its row number. */
16398 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16399 w
->window_end_bytepos
16400 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16401 wset_window_end_pos
16402 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16403 wset_window_end_vpos
16404 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16406 (MATRIX_ROW (w
->desired_matrix
,
16407 XFASTINT (w
->window_end_vpos
))->displays_text_p
);
16411 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16412 wset_window_end_pos (w
, make_number (Z
- ZV
));
16413 wset_window_end_vpos (w
, make_number (0));
16416 /* But that is not valid info until redisplay finishes. */
16417 wset_window_end_valid (w
, Qnil
);
16423 /************************************************************************
16424 Window redisplay reusing current matrix when buffer has not changed
16425 ************************************************************************/
16427 /* Try redisplay of window W showing an unchanged buffer with a
16428 different window start than the last time it was displayed by
16429 reusing its current matrix. Value is non-zero if successful.
16430 W->start is the new window start. */
16433 try_window_reusing_current_matrix (struct window
*w
)
16435 struct frame
*f
= XFRAME (w
->frame
);
16436 struct glyph_row
*bottom_row
;
16439 struct text_pos start
, new_start
;
16440 int nrows_scrolled
, i
;
16441 struct glyph_row
*last_text_row
;
16442 struct glyph_row
*last_reused_text_row
;
16443 struct glyph_row
*start_row
;
16444 int start_vpos
, min_y
, max_y
;
16447 if (inhibit_try_window_reusing
)
16451 if (/* This function doesn't handle terminal frames. */
16452 !FRAME_WINDOW_P (f
)
16453 /* Don't try to reuse the display if windows have been split
16455 || windows_or_buffers_changed
16456 || cursor_type_changed
)
16459 /* Can't do this if region may have changed. */
16460 if (0 <= markpos_of_region ()
16461 || !NILP (w
->region_showing
)
16462 || !NILP (Vshow_trailing_whitespace
))
16465 /* If top-line visibility has changed, give up. */
16466 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16467 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16470 /* Give up if old or new display is scrolled vertically. We could
16471 make this function handle this, but right now it doesn't. */
16472 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16473 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16476 /* The variable new_start now holds the new window start. The old
16477 start `start' can be determined from the current matrix. */
16478 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16479 start
= start_row
->minpos
;
16480 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16482 /* Clear the desired matrix for the display below. */
16483 clear_glyph_matrix (w
->desired_matrix
);
16485 if (CHARPOS (new_start
) <= CHARPOS (start
))
16487 /* Don't use this method if the display starts with an ellipsis
16488 displayed for invisible text. It's not easy to handle that case
16489 below, and it's certainly not worth the effort since this is
16490 not a frequent case. */
16491 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16494 IF_DEBUG (debug_method_add (w
, "twu1"));
16496 /* Display up to a row that can be reused. The variable
16497 last_text_row is set to the last row displayed that displays
16498 text. Note that it.vpos == 0 if or if not there is a
16499 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16500 start_display (&it
, w
, new_start
);
16501 w
->cursor
.vpos
= -1;
16502 last_text_row
= last_reused_text_row
= NULL
;
16504 while (it
.current_y
< it
.last_visible_y
16505 && !fonts_changed_p
)
16507 /* If we have reached into the characters in the START row,
16508 that means the line boundaries have changed. So we
16509 can't start copying with the row START. Maybe it will
16510 work to start copying with the following row. */
16511 while (IT_CHARPOS (it
) > CHARPOS (start
))
16513 /* Advance to the next row as the "start". */
16515 start
= start_row
->minpos
;
16516 /* If there are no more rows to try, or just one, give up. */
16517 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16518 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16519 || CHARPOS (start
) == ZV
)
16521 clear_glyph_matrix (w
->desired_matrix
);
16525 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16527 /* If we have reached alignment, we can copy the rest of the
16529 if (IT_CHARPOS (it
) == CHARPOS (start
)
16530 /* Don't accept "alignment" inside a display vector,
16531 since start_row could have started in the middle of
16532 that same display vector (thus their character
16533 positions match), and we have no way of telling if
16534 that is the case. */
16535 && it
.current
.dpvec_index
< 0)
16538 if (display_line (&it
))
16539 last_text_row
= it
.glyph_row
- 1;
16543 /* A value of current_y < last_visible_y means that we stopped
16544 at the previous window start, which in turn means that we
16545 have at least one reusable row. */
16546 if (it
.current_y
< it
.last_visible_y
)
16548 struct glyph_row
*row
;
16550 /* IT.vpos always starts from 0; it counts text lines. */
16551 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16553 /* Find PT if not already found in the lines displayed. */
16554 if (w
->cursor
.vpos
< 0)
16556 int dy
= it
.current_y
- start_row
->y
;
16558 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16559 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16561 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16562 dy
, nrows_scrolled
);
16565 clear_glyph_matrix (w
->desired_matrix
);
16570 /* Scroll the display. Do it before the current matrix is
16571 changed. The problem here is that update has not yet
16572 run, i.e. part of the current matrix is not up to date.
16573 scroll_run_hook will clear the cursor, and use the
16574 current matrix to get the height of the row the cursor is
16576 run
.current_y
= start_row
->y
;
16577 run
.desired_y
= it
.current_y
;
16578 run
.height
= it
.last_visible_y
- it
.current_y
;
16580 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16583 FRAME_RIF (f
)->update_window_begin_hook (w
);
16584 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16585 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16586 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16590 /* Shift current matrix down by nrows_scrolled lines. */
16591 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16592 rotate_matrix (w
->current_matrix
,
16594 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16597 /* Disable lines that must be updated. */
16598 for (i
= 0; i
< nrows_scrolled
; ++i
)
16599 (start_row
+ i
)->enabled_p
= 0;
16601 /* Re-compute Y positions. */
16602 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16603 max_y
= it
.last_visible_y
;
16604 for (row
= start_row
+ nrows_scrolled
;
16608 row
->y
= it
.current_y
;
16609 row
->visible_height
= row
->height
;
16611 if (row
->y
< min_y
)
16612 row
->visible_height
-= min_y
- row
->y
;
16613 if (row
->y
+ row
->height
> max_y
)
16614 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16615 if (row
->fringe_bitmap_periodic_p
)
16616 row
->redraw_fringe_bitmaps_p
= 1;
16618 it
.current_y
+= row
->height
;
16620 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16621 last_reused_text_row
= row
;
16622 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16626 /* Disable lines in the current matrix which are now
16627 below the window. */
16628 for (++row
; row
< bottom_row
; ++row
)
16629 row
->enabled_p
= row
->mode_line_p
= 0;
16632 /* Update window_end_pos etc.; last_reused_text_row is the last
16633 reused row from the current matrix containing text, if any.
16634 The value of last_text_row is the last displayed line
16635 containing text. */
16636 if (last_reused_text_row
)
16638 w
->window_end_bytepos
16639 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16640 wset_window_end_pos
16642 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16643 wset_window_end_vpos
16644 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16645 w
->current_matrix
)));
16647 else if (last_text_row
)
16649 w
->window_end_bytepos
16650 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16651 wset_window_end_pos
16652 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16653 wset_window_end_vpos
16654 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16655 w
->desired_matrix
)));
16659 /* This window must be completely empty. */
16660 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16661 wset_window_end_pos (w
, make_number (Z
- ZV
));
16662 wset_window_end_vpos (w
, make_number (0));
16664 wset_window_end_valid (w
, Qnil
);
16666 /* Update hint: don't try scrolling again in update_window. */
16667 w
->desired_matrix
->no_scrolling_p
= 1;
16670 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16674 else if (CHARPOS (new_start
) > CHARPOS (start
))
16676 struct glyph_row
*pt_row
, *row
;
16677 struct glyph_row
*first_reusable_row
;
16678 struct glyph_row
*first_row_to_display
;
16680 int yb
= window_text_bottom_y (w
);
16682 /* Find the row starting at new_start, if there is one. Don't
16683 reuse a partially visible line at the end. */
16684 first_reusable_row
= start_row
;
16685 while (first_reusable_row
->enabled_p
16686 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16687 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16688 < CHARPOS (new_start
)))
16689 ++first_reusable_row
;
16691 /* Give up if there is no row to reuse. */
16692 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16693 || !first_reusable_row
->enabled_p
16694 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16695 != CHARPOS (new_start
)))
16698 /* We can reuse fully visible rows beginning with
16699 first_reusable_row to the end of the window. Set
16700 first_row_to_display to the first row that cannot be reused.
16701 Set pt_row to the row containing point, if there is any. */
16703 for (first_row_to_display
= first_reusable_row
;
16704 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16705 ++first_row_to_display
)
16707 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16708 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16709 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16710 && first_row_to_display
->ends_at_zv_p
16711 && pt_row
== NULL
)))
16712 pt_row
= first_row_to_display
;
16715 /* Start displaying at the start of first_row_to_display. */
16716 eassert (first_row_to_display
->y
< yb
);
16717 init_to_row_start (&it
, w
, first_row_to_display
);
16719 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16721 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16723 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16724 + WINDOW_HEADER_LINE_HEIGHT (w
));
16726 /* Display lines beginning with first_row_to_display in the
16727 desired matrix. Set last_text_row to the last row displayed
16728 that displays text. */
16729 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16730 if (pt_row
== NULL
)
16731 w
->cursor
.vpos
= -1;
16732 last_text_row
= NULL
;
16733 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16734 if (display_line (&it
))
16735 last_text_row
= it
.glyph_row
- 1;
16737 /* If point is in a reused row, adjust y and vpos of the cursor
16741 w
->cursor
.vpos
-= nrows_scrolled
;
16742 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16745 /* Give up if point isn't in a row displayed or reused. (This
16746 also handles the case where w->cursor.vpos < nrows_scrolled
16747 after the calls to display_line, which can happen with scroll
16748 margins. See bug#1295.) */
16749 if (w
->cursor
.vpos
< 0)
16751 clear_glyph_matrix (w
->desired_matrix
);
16755 /* Scroll the display. */
16756 run
.current_y
= first_reusable_row
->y
;
16757 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16758 run
.height
= it
.last_visible_y
- run
.current_y
;
16759 dy
= run
.current_y
- run
.desired_y
;
16764 FRAME_RIF (f
)->update_window_begin_hook (w
);
16765 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16766 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16767 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16771 /* Adjust Y positions of reused rows. */
16772 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16773 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16774 max_y
= it
.last_visible_y
;
16775 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16778 row
->visible_height
= row
->height
;
16779 if (row
->y
< min_y
)
16780 row
->visible_height
-= min_y
- row
->y
;
16781 if (row
->y
+ row
->height
> max_y
)
16782 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16783 if (row
->fringe_bitmap_periodic_p
)
16784 row
->redraw_fringe_bitmaps_p
= 1;
16787 /* Scroll the current matrix. */
16788 eassert (nrows_scrolled
> 0);
16789 rotate_matrix (w
->current_matrix
,
16791 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16794 /* Disable rows not reused. */
16795 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16796 row
->enabled_p
= 0;
16798 /* Point may have moved to a different line, so we cannot assume that
16799 the previous cursor position is valid; locate the correct row. */
16802 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16804 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16805 && !row
->ends_at_zv_p
;
16809 w
->cursor
.y
= row
->y
;
16811 if (row
< bottom_row
)
16813 /* Can't simply scan the row for point with
16814 bidi-reordered glyph rows. Let set_cursor_from_row
16815 figure out where to put the cursor, and if it fails,
16817 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
)))
16819 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16822 clear_glyph_matrix (w
->desired_matrix
);
16828 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16829 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16832 && (!BUFFERP (glyph
->object
)
16833 || glyph
->charpos
< PT
);
16837 w
->cursor
.x
+= glyph
->pixel_width
;
16843 /* Adjust window end. A null value of last_text_row means that
16844 the window end is in reused rows which in turn means that
16845 only its vpos can have changed. */
16848 w
->window_end_bytepos
16849 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16850 wset_window_end_pos
16851 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16852 wset_window_end_vpos
16853 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16854 w
->desired_matrix
)));
16858 wset_window_end_vpos
16859 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16862 wset_window_end_valid (w
, Qnil
);
16863 w
->desired_matrix
->no_scrolling_p
= 1;
16866 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16876 /************************************************************************
16877 Window redisplay reusing current matrix when buffer has changed
16878 ************************************************************************/
16880 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16881 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16882 ptrdiff_t *, ptrdiff_t *);
16883 static struct glyph_row
*
16884 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16885 struct glyph_row
*);
16888 /* Return the last row in MATRIX displaying text. If row START is
16889 non-null, start searching with that row. IT gives the dimensions
16890 of the display. Value is null if matrix is empty; otherwise it is
16891 a pointer to the row found. */
16893 static struct glyph_row
*
16894 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16895 struct glyph_row
*start
)
16897 struct glyph_row
*row
, *row_found
;
16899 /* Set row_found to the last row in IT->w's current matrix
16900 displaying text. The loop looks funny but think of partially
16903 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16904 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16906 eassert (row
->enabled_p
);
16908 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16917 /* Return the last row in the current matrix of W that is not affected
16918 by changes at the start of current_buffer that occurred since W's
16919 current matrix was built. Value is null if no such row exists.
16921 BEG_UNCHANGED us the number of characters unchanged at the start of
16922 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16923 first changed character in current_buffer. Characters at positions <
16924 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16925 when the current matrix was built. */
16927 static struct glyph_row
*
16928 find_last_unchanged_at_beg_row (struct window
*w
)
16930 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16931 struct glyph_row
*row
;
16932 struct glyph_row
*row_found
= NULL
;
16933 int yb
= window_text_bottom_y (w
);
16935 /* Find the last row displaying unchanged text. */
16936 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16937 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16938 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16941 if (/* If row ends before first_changed_pos, it is unchanged,
16942 except in some case. */
16943 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16944 /* When row ends in ZV and we write at ZV it is not
16946 && !row
->ends_at_zv_p
16947 /* When first_changed_pos is the end of a continued line,
16948 row is not unchanged because it may be no longer
16950 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16951 && (row
->continued_p
16952 || row
->exact_window_width_line_p
))
16953 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16954 needs to be recomputed, so don't consider this row as
16955 unchanged. This happens when the last line was
16956 bidi-reordered and was killed immediately before this
16957 redisplay cycle. In that case, ROW->end stores the
16958 buffer position of the first visual-order character of
16959 the killed text, which is now beyond ZV. */
16960 && CHARPOS (row
->end
.pos
) <= ZV
)
16963 /* Stop if last visible row. */
16964 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16972 /* Find the first glyph row in the current matrix of W that is not
16973 affected by changes at the end of current_buffer since the
16974 time W's current matrix was built.
16976 Return in *DELTA the number of chars by which buffer positions in
16977 unchanged text at the end of current_buffer must be adjusted.
16979 Return in *DELTA_BYTES the corresponding number of bytes.
16981 Value is null if no such row exists, i.e. all rows are affected by
16984 static struct glyph_row
*
16985 find_first_unchanged_at_end_row (struct window
*w
,
16986 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16988 struct glyph_row
*row
;
16989 struct glyph_row
*row_found
= NULL
;
16991 *delta
= *delta_bytes
= 0;
16993 /* Display must not have been paused, otherwise the current matrix
16994 is not up to date. */
16995 eassert (!NILP (w
->window_end_valid
));
16997 /* A value of window_end_pos >= END_UNCHANGED means that the window
16998 end is in the range of changed text. If so, there is no
16999 unchanged row at the end of W's current matrix. */
17000 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
17003 /* Set row to the last row in W's current matrix displaying text. */
17004 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17006 /* If matrix is entirely empty, no unchanged row exists. */
17007 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17009 /* The value of row is the last glyph row in the matrix having a
17010 meaningful buffer position in it. The end position of row
17011 corresponds to window_end_pos. This allows us to translate
17012 buffer positions in the current matrix to current buffer
17013 positions for characters not in changed text. */
17015 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17016 ptrdiff_t Z_BYTE_old
=
17017 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17018 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
17019 struct glyph_row
*first_text_row
17020 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
17022 *delta
= Z
- Z_old
;
17023 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17025 /* Set last_unchanged_pos to the buffer position of the last
17026 character in the buffer that has not been changed. Z is the
17027 index + 1 of the last character in current_buffer, i.e. by
17028 subtracting END_UNCHANGED we get the index of the last
17029 unchanged character, and we have to add BEG to get its buffer
17031 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
17032 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
17034 /* Search backward from ROW for a row displaying a line that
17035 starts at a minimum position >= last_unchanged_pos_old. */
17036 for (; row
> first_text_row
; --row
)
17038 /* This used to abort, but it can happen.
17039 It is ok to just stop the search instead here. KFS. */
17040 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
17043 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
17048 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
17054 /* Make sure that glyph rows in the current matrix of window W
17055 reference the same glyph memory as corresponding rows in the
17056 frame's frame matrix. This function is called after scrolling W's
17057 current matrix on a terminal frame in try_window_id and
17058 try_window_reusing_current_matrix. */
17061 sync_frame_with_window_matrix_rows (struct window
*w
)
17063 struct frame
*f
= XFRAME (w
->frame
);
17064 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
17066 /* Preconditions: W must be a leaf window and full-width. Its frame
17067 must have a frame matrix. */
17068 eassert (NILP (w
->hchild
) && NILP (w
->vchild
));
17069 eassert (WINDOW_FULL_WIDTH_P (w
));
17070 eassert (!FRAME_WINDOW_P (f
));
17072 /* If W is a full-width window, glyph pointers in W's current matrix
17073 have, by definition, to be the same as glyph pointers in the
17074 corresponding frame matrix. Note that frame matrices have no
17075 marginal areas (see build_frame_matrix). */
17076 window_row
= w
->current_matrix
->rows
;
17077 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
17078 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
17079 while (window_row
< window_row_end
)
17081 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
17082 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
17084 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
17085 frame_row
->glyphs
[TEXT_AREA
] = start
;
17086 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
17087 frame_row
->glyphs
[LAST_AREA
] = end
;
17089 /* Disable frame rows whose corresponding window rows have
17090 been disabled in try_window_id. */
17091 if (!window_row
->enabled_p
)
17092 frame_row
->enabled_p
= 0;
17094 ++window_row
, ++frame_row
;
17099 /* Find the glyph row in window W containing CHARPOS. Consider all
17100 rows between START and END (not inclusive). END null means search
17101 all rows to the end of the display area of W. Value is the row
17102 containing CHARPOS or null. */
17105 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17106 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17108 struct glyph_row
*row
= start
;
17109 struct glyph_row
*best_row
= NULL
;
17110 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->buffer
)) + 1;
17113 /* If we happen to start on a header-line, skip that. */
17114 if (row
->mode_line_p
)
17117 if ((end
&& row
>= end
) || !row
->enabled_p
)
17120 last_y
= window_text_bottom_y (w
) - dy
;
17124 /* Give up if we have gone too far. */
17125 if (end
&& row
>= end
)
17127 /* This formerly returned if they were equal.
17128 I think that both quantities are of a "last plus one" type;
17129 if so, when they are equal, the row is within the screen. -- rms. */
17130 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17133 /* If it is in this row, return this row. */
17134 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17135 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17136 /* The end position of a row equals the start
17137 position of the next row. If CHARPOS is there, we
17138 would rather display it in the next line, except
17139 when this line ends in ZV. */
17140 && !row
->ends_at_zv_p
17141 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
17142 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17146 if (NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17147 || (!best_row
&& !row
->continued_p
))
17149 /* In bidi-reordered rows, there could be several rows
17150 occluding point, all of them belonging to the same
17151 continued line. We need to find the row which fits
17152 CHARPOS the best. */
17153 for (g
= row
->glyphs
[TEXT_AREA
];
17154 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17157 if (!STRINGP (g
->object
))
17159 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17161 mindif
= eabs (g
->charpos
- charpos
);
17163 /* Exact match always wins. */
17170 else if (best_row
&& !row
->continued_p
)
17177 /* Try to redisplay window W by reusing its existing display. W's
17178 current matrix must be up to date when this function is called,
17179 i.e. window_end_valid must not be nil.
17183 1 if display has been updated
17184 0 if otherwise unsuccessful
17185 -1 if redisplay with same window start is known not to succeed
17187 The following steps are performed:
17189 1. Find the last row in the current matrix of W that is not
17190 affected by changes at the start of current_buffer. If no such row
17193 2. Find the first row in W's current matrix that is not affected by
17194 changes at the end of current_buffer. Maybe there is no such row.
17196 3. Display lines beginning with the row + 1 found in step 1 to the
17197 row found in step 2 or, if step 2 didn't find a row, to the end of
17200 4. If cursor is not known to appear on the window, give up.
17202 5. If display stopped at the row found in step 2, scroll the
17203 display and current matrix as needed.
17205 6. Maybe display some lines at the end of W, if we must. This can
17206 happen under various circumstances, like a partially visible line
17207 becoming fully visible, or because newly displayed lines are displayed
17208 in smaller font sizes.
17210 7. Update W's window end information. */
17213 try_window_id (struct window
*w
)
17215 struct frame
*f
= XFRAME (w
->frame
);
17216 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17217 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17218 struct glyph_row
*last_unchanged_at_beg_row
;
17219 struct glyph_row
*first_unchanged_at_end_row
;
17220 struct glyph_row
*row
;
17221 struct glyph_row
*bottom_row
;
17224 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17226 struct text_pos start_pos
;
17228 int first_unchanged_at_end_vpos
= 0;
17229 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17230 struct text_pos start
;
17231 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17234 if (inhibit_try_window_id
)
17238 /* This is handy for debugging. */
17240 #define GIVE_UP(X) \
17242 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17246 #define GIVE_UP(X) return 0
17249 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17251 /* Don't use this for mini-windows because these can show
17252 messages and mini-buffers, and we don't handle that here. */
17253 if (MINI_WINDOW_P (w
))
17256 /* This flag is used to prevent redisplay optimizations. */
17257 if (windows_or_buffers_changed
|| cursor_type_changed
)
17260 /* Verify that narrowing has not changed.
17261 Also verify that we were not told to prevent redisplay optimizations.
17262 It would be nice to further
17263 reduce the number of cases where this prevents try_window_id. */
17264 if (current_buffer
->clip_changed
17265 || current_buffer
->prevent_redisplay_optimizations_p
)
17268 /* Window must either use window-based redisplay or be full width. */
17269 if (!FRAME_WINDOW_P (f
)
17270 && (!FRAME_LINE_INS_DEL_OK (f
)
17271 || !WINDOW_FULL_WIDTH_P (w
)))
17274 /* Give up if point is known NOT to appear in W. */
17275 if (PT
< CHARPOS (start
))
17278 /* Another way to prevent redisplay optimizations. */
17279 if (w
->last_modified
== 0)
17282 /* Verify that window is not hscrolled. */
17283 if (w
->hscroll
!= 0)
17286 /* Verify that display wasn't paused. */
17287 if (NILP (w
->window_end_valid
))
17290 /* Can't use this if highlighting a region because a cursor movement
17291 will do more than just set the cursor. */
17292 if (0 <= markpos_of_region ())
17295 /* Likewise if highlighting trailing whitespace. */
17296 if (!NILP (Vshow_trailing_whitespace
))
17299 /* Likewise if showing a region. */
17300 if (!NILP (w
->region_showing
))
17303 /* Can't use this if overlay arrow position and/or string have
17305 if (overlay_arrows_changed_p ())
17308 /* When word-wrap is on, adding a space to the first word of a
17309 wrapped line can change the wrap position, altering the line
17310 above it. It might be worthwhile to handle this more
17311 intelligently, but for now just redisplay from scratch. */
17312 if (!NILP (BVAR (XBUFFER (w
->buffer
), word_wrap
)))
17315 /* Under bidi reordering, adding or deleting a character in the
17316 beginning of a paragraph, before the first strong directional
17317 character, can change the base direction of the paragraph (unless
17318 the buffer specifies a fixed paragraph direction), which will
17319 require to redisplay the whole paragraph. It might be worthwhile
17320 to find the paragraph limits and widen the range of redisplayed
17321 lines to that, but for now just give up this optimization and
17322 redisplay from scratch. */
17323 if (!NILP (BVAR (XBUFFER (w
->buffer
), bidi_display_reordering
))
17324 && NILP (BVAR (XBUFFER (w
->buffer
), bidi_paragraph_direction
)))
17327 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17328 only if buffer has really changed. The reason is that the gap is
17329 initially at Z for freshly visited files. The code below would
17330 set end_unchanged to 0 in that case. */
17331 if (MODIFF
> SAVE_MODIFF
17332 /* This seems to happen sometimes after saving a buffer. */
17333 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17335 if (GPT
- BEG
< BEG_UNCHANGED
)
17336 BEG_UNCHANGED
= GPT
- BEG
;
17337 if (Z
- GPT
< END_UNCHANGED
)
17338 END_UNCHANGED
= Z
- GPT
;
17341 /* The position of the first and last character that has been changed. */
17342 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17343 last_changed_charpos
= Z
- END_UNCHANGED
;
17345 /* If window starts after a line end, and the last change is in
17346 front of that newline, then changes don't affect the display.
17347 This case happens with stealth-fontification. Note that although
17348 the display is unchanged, glyph positions in the matrix have to
17349 be adjusted, of course. */
17350 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17351 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17352 && ((last_changed_charpos
< CHARPOS (start
)
17353 && CHARPOS (start
) == BEGV
)
17354 || (last_changed_charpos
< CHARPOS (start
) - 1
17355 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17357 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17358 struct glyph_row
*r0
;
17360 /* Compute how many chars/bytes have been added to or removed
17361 from the buffer. */
17362 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17363 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17364 Z_delta
= Z
- Z_old
;
17365 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17367 /* Give up if PT is not in the window. Note that it already has
17368 been checked at the start of try_window_id that PT is not in
17369 front of the window start. */
17370 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17373 /* If window start is unchanged, we can reuse the whole matrix
17374 as is, after adjusting glyph positions. No need to compute
17375 the window end again, since its offset from Z hasn't changed. */
17376 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17377 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17378 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17379 /* PT must not be in a partially visible line. */
17380 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17381 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17383 /* Adjust positions in the glyph matrix. */
17384 if (Z_delta
|| Z_delta_bytes
)
17386 struct glyph_row
*r1
17387 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17388 increment_matrix_positions (w
->current_matrix
,
17389 MATRIX_ROW_VPOS (r0
, current_matrix
),
17390 MATRIX_ROW_VPOS (r1
, current_matrix
),
17391 Z_delta
, Z_delta_bytes
);
17394 /* Set the cursor. */
17395 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17397 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17404 /* Handle the case that changes are all below what is displayed in
17405 the window, and that PT is in the window. This shortcut cannot
17406 be taken if ZV is visible in the window, and text has been added
17407 there that is visible in the window. */
17408 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17409 /* ZV is not visible in the window, or there are no
17410 changes at ZV, actually. */
17411 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17412 || first_changed_charpos
== last_changed_charpos
))
17414 struct glyph_row
*r0
;
17416 /* Give up if PT is not in the window. Note that it already has
17417 been checked at the start of try_window_id that PT is not in
17418 front of the window start. */
17419 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17422 /* If window start is unchanged, we can reuse the whole matrix
17423 as is, without changing glyph positions since no text has
17424 been added/removed in front of the window end. */
17425 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17426 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17427 /* PT must not be in a partially visible line. */
17428 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17429 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17431 /* We have to compute the window end anew since text
17432 could have been added/removed after it. */
17433 wset_window_end_pos
17434 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17435 w
->window_end_bytepos
17436 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17438 /* Set the cursor. */
17439 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17441 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17448 /* Give up if window start is in the changed area.
17450 The condition used to read
17452 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17454 but why that was tested escapes me at the moment. */
17455 if (CHARPOS (start
) >= first_changed_charpos
17456 && CHARPOS (start
) <= last_changed_charpos
)
17459 /* Check that window start agrees with the start of the first glyph
17460 row in its current matrix. Check this after we know the window
17461 start is not in changed text, otherwise positions would not be
17463 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17464 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17467 /* Give up if the window ends in strings. Overlay strings
17468 at the end are difficult to handle, so don't try. */
17469 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17470 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17473 /* Compute the position at which we have to start displaying new
17474 lines. Some of the lines at the top of the window might be
17475 reusable because they are not displaying changed text. Find the
17476 last row in W's current matrix not affected by changes at the
17477 start of current_buffer. Value is null if changes start in the
17478 first line of window. */
17479 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17480 if (last_unchanged_at_beg_row
)
17482 /* Avoid starting to display in the middle of a character, a TAB
17483 for instance. This is easier than to set up the iterator
17484 exactly, and it's not a frequent case, so the additional
17485 effort wouldn't really pay off. */
17486 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17487 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17488 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17489 --last_unchanged_at_beg_row
;
17491 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17494 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17496 start_pos
= it
.current
.pos
;
17498 /* Start displaying new lines in the desired matrix at the same
17499 vpos we would use in the current matrix, i.e. below
17500 last_unchanged_at_beg_row. */
17501 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17503 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17504 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17506 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17510 /* There are no reusable lines at the start of the window.
17511 Start displaying in the first text line. */
17512 start_display (&it
, w
, start
);
17513 it
.vpos
= it
.first_vpos
;
17514 start_pos
= it
.current
.pos
;
17517 /* Find the first row that is not affected by changes at the end of
17518 the buffer. Value will be null if there is no unchanged row, in
17519 which case we must redisplay to the end of the window. delta
17520 will be set to the value by which buffer positions beginning with
17521 first_unchanged_at_end_row have to be adjusted due to text
17523 first_unchanged_at_end_row
17524 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17525 IF_DEBUG (debug_delta
= delta
);
17526 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17528 /* Set stop_pos to the buffer position up to which we will have to
17529 display new lines. If first_unchanged_at_end_row != NULL, this
17530 is the buffer position of the start of the line displayed in that
17531 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17532 that we don't stop at a buffer position. */
17534 if (first_unchanged_at_end_row
)
17536 eassert (last_unchanged_at_beg_row
== NULL
17537 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17539 /* If this is a continuation line, move forward to the next one
17540 that isn't. Changes in lines above affect this line.
17541 Caution: this may move first_unchanged_at_end_row to a row
17542 not displaying text. */
17543 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17544 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17545 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17546 < it
.last_visible_y
))
17547 ++first_unchanged_at_end_row
;
17549 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17550 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17551 >= it
.last_visible_y
))
17552 first_unchanged_at_end_row
= NULL
;
17555 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17557 first_unchanged_at_end_vpos
17558 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17559 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17562 else if (last_unchanged_at_beg_row
== NULL
)
17568 /* Either there is no unchanged row at the end, or the one we have
17569 now displays text. This is a necessary condition for the window
17570 end pos calculation at the end of this function. */
17571 eassert (first_unchanged_at_end_row
== NULL
17572 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17574 debug_last_unchanged_at_beg_vpos
17575 = (last_unchanged_at_beg_row
17576 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17578 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17580 #endif /* GLYPH_DEBUG */
17583 /* Display new lines. Set last_text_row to the last new line
17584 displayed which has text on it, i.e. might end up as being the
17585 line where the window_end_vpos is. */
17586 w
->cursor
.vpos
= -1;
17587 last_text_row
= NULL
;
17588 overlay_arrow_seen
= 0;
17589 while (it
.current_y
< it
.last_visible_y
17590 && !fonts_changed_p
17591 && (first_unchanged_at_end_row
== NULL
17592 || IT_CHARPOS (it
) < stop_pos
))
17594 if (display_line (&it
))
17595 last_text_row
= it
.glyph_row
- 1;
17598 if (fonts_changed_p
)
17602 /* Compute differences in buffer positions, y-positions etc. for
17603 lines reused at the bottom of the window. Compute what we can
17605 if (first_unchanged_at_end_row
17606 /* No lines reused because we displayed everything up to the
17607 bottom of the window. */
17608 && it
.current_y
< it
.last_visible_y
)
17611 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17613 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17614 run
.current_y
= first_unchanged_at_end_row
->y
;
17615 run
.desired_y
= run
.current_y
+ dy
;
17616 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17620 delta
= delta_bytes
= dvpos
= dy
17621 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17622 first_unchanged_at_end_row
= NULL
;
17624 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17627 /* Find the cursor if not already found. We have to decide whether
17628 PT will appear on this window (it sometimes doesn't, but this is
17629 not a very frequent case.) This decision has to be made before
17630 the current matrix is altered. A value of cursor.vpos < 0 means
17631 that PT is either in one of the lines beginning at
17632 first_unchanged_at_end_row or below the window. Don't care for
17633 lines that might be displayed later at the window end; as
17634 mentioned, this is not a frequent case. */
17635 if (w
->cursor
.vpos
< 0)
17637 /* Cursor in unchanged rows at the top? */
17638 if (PT
< CHARPOS (start_pos
)
17639 && last_unchanged_at_beg_row
)
17641 row
= row_containing_pos (w
, PT
,
17642 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17643 last_unchanged_at_beg_row
+ 1, 0);
17645 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17648 /* Start from first_unchanged_at_end_row looking for PT. */
17649 else if (first_unchanged_at_end_row
)
17651 row
= row_containing_pos (w
, PT
- delta
,
17652 first_unchanged_at_end_row
, NULL
, 0);
17654 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17655 delta_bytes
, dy
, dvpos
);
17658 /* Give up if cursor was not found. */
17659 if (w
->cursor
.vpos
< 0)
17661 clear_glyph_matrix (w
->desired_matrix
);
17666 /* Don't let the cursor end in the scroll margins. */
17668 int this_scroll_margin
, cursor_height
;
17670 this_scroll_margin
=
17671 max (0, min (scroll_margin
, WINDOW_TOTAL_LINES (w
) / 4));
17672 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
17673 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17675 if ((w
->cursor
.y
< this_scroll_margin
17676 && CHARPOS (start
) > BEGV
)
17677 /* Old redisplay didn't take scroll margin into account at the bottom,
17678 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17679 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17680 ? cursor_height
+ this_scroll_margin
17681 : 1)) > it
.last_visible_y
)
17683 w
->cursor
.vpos
= -1;
17684 clear_glyph_matrix (w
->desired_matrix
);
17689 /* Scroll the display. Do it before changing the current matrix so
17690 that xterm.c doesn't get confused about where the cursor glyph is
17692 if (dy
&& run
.height
)
17696 if (FRAME_WINDOW_P (f
))
17698 FRAME_RIF (f
)->update_window_begin_hook (w
);
17699 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17700 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17701 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17705 /* Terminal frame. In this case, dvpos gives the number of
17706 lines to scroll by; dvpos < 0 means scroll up. */
17708 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17709 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17710 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17711 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17712 + window_internal_height (w
));
17714 #if defined (HAVE_GPM) || defined (MSDOS)
17715 x_clear_window_mouse_face (w
);
17717 /* Perform the operation on the screen. */
17720 /* Scroll last_unchanged_at_beg_row to the end of the
17721 window down dvpos lines. */
17722 set_terminal_window (f
, end
);
17724 /* On dumb terminals delete dvpos lines at the end
17725 before inserting dvpos empty lines. */
17726 if (!FRAME_SCROLL_REGION_OK (f
))
17727 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17729 /* Insert dvpos empty lines in front of
17730 last_unchanged_at_beg_row. */
17731 ins_del_lines (f
, from
, dvpos
);
17733 else if (dvpos
< 0)
17735 /* Scroll up last_unchanged_at_beg_vpos to the end of
17736 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17737 set_terminal_window (f
, end
);
17739 /* Delete dvpos lines in front of
17740 last_unchanged_at_beg_vpos. ins_del_lines will set
17741 the cursor to the given vpos and emit |dvpos| delete
17743 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17745 /* On a dumb terminal insert dvpos empty lines at the
17747 if (!FRAME_SCROLL_REGION_OK (f
))
17748 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17751 set_terminal_window (f
, 0);
17757 /* Shift reused rows of the current matrix to the right position.
17758 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17760 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17761 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17764 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17765 bottom_vpos
, dvpos
);
17766 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17769 else if (dvpos
> 0)
17771 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17772 bottom_vpos
, dvpos
);
17773 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17774 first_unchanged_at_end_vpos
+ dvpos
);
17777 /* For frame-based redisplay, make sure that current frame and window
17778 matrix are in sync with respect to glyph memory. */
17779 if (!FRAME_WINDOW_P (f
))
17780 sync_frame_with_window_matrix_rows (w
);
17782 /* Adjust buffer positions in reused rows. */
17783 if (delta
|| delta_bytes
)
17784 increment_matrix_positions (current_matrix
,
17785 first_unchanged_at_end_vpos
+ dvpos
,
17786 bottom_vpos
, delta
, delta_bytes
);
17788 /* Adjust Y positions. */
17790 shift_glyph_matrix (w
, current_matrix
,
17791 first_unchanged_at_end_vpos
+ dvpos
,
17794 if (first_unchanged_at_end_row
)
17796 first_unchanged_at_end_row
+= dvpos
;
17797 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17798 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17799 first_unchanged_at_end_row
= NULL
;
17802 /* If scrolling up, there may be some lines to display at the end of
17804 last_text_row_at_end
= NULL
;
17807 /* Scrolling up can leave for example a partially visible line
17808 at the end of the window to be redisplayed. */
17809 /* Set last_row to the glyph row in the current matrix where the
17810 window end line is found. It has been moved up or down in
17811 the matrix by dvpos. */
17812 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17813 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17815 /* If last_row is the window end line, it should display text. */
17816 eassert (last_row
->displays_text_p
);
17818 /* If window end line was partially visible before, begin
17819 displaying at that line. Otherwise begin displaying with the
17820 line following it. */
17821 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17823 init_to_row_start (&it
, w
, last_row
);
17824 it
.vpos
= last_vpos
;
17825 it
.current_y
= last_row
->y
;
17829 init_to_row_end (&it
, w
, last_row
);
17830 it
.vpos
= 1 + last_vpos
;
17831 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17835 /* We may start in a continuation line. If so, we have to
17836 get the right continuation_lines_width and current_x. */
17837 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17838 it
.hpos
= it
.current_x
= 0;
17840 /* Display the rest of the lines at the window end. */
17841 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17842 while (it
.current_y
< it
.last_visible_y
17843 && !fonts_changed_p
)
17845 /* Is it always sure that the display agrees with lines in
17846 the current matrix? I don't think so, so we mark rows
17847 displayed invalid in the current matrix by setting their
17848 enabled_p flag to zero. */
17849 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17850 if (display_line (&it
))
17851 last_text_row_at_end
= it
.glyph_row
- 1;
17855 /* Update window_end_pos and window_end_vpos. */
17856 if (first_unchanged_at_end_row
17857 && !last_text_row_at_end
)
17859 /* Window end line if one of the preserved rows from the current
17860 matrix. Set row to the last row displaying text in current
17861 matrix starting at first_unchanged_at_end_row, after
17863 eassert (first_unchanged_at_end_row
->displays_text_p
);
17864 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17865 first_unchanged_at_end_row
);
17866 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17868 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17869 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17870 wset_window_end_vpos
17871 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17872 eassert (w
->window_end_bytepos
>= 0);
17873 IF_DEBUG (debug_method_add (w
, "A"));
17875 else if (last_text_row_at_end
)
17877 wset_window_end_pos
17878 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17879 w
->window_end_bytepos
17880 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17881 wset_window_end_vpos
17882 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17884 eassert (w
->window_end_bytepos
>= 0);
17885 IF_DEBUG (debug_method_add (w
, "B"));
17887 else if (last_text_row
)
17889 /* We have displayed either to the end of the window or at the
17890 end of the window, i.e. the last row with text is to be found
17891 in the desired matrix. */
17892 wset_window_end_pos
17893 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17894 w
->window_end_bytepos
17895 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17896 wset_window_end_vpos
17897 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17898 eassert (w
->window_end_bytepos
>= 0);
17900 else if (first_unchanged_at_end_row
== NULL
17901 && last_text_row
== NULL
17902 && last_text_row_at_end
== NULL
)
17904 /* Displayed to end of window, but no line containing text was
17905 displayed. Lines were deleted at the end of the window. */
17906 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17907 int vpos
= XFASTINT (w
->window_end_vpos
);
17908 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17909 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17912 row
== NULL
&& vpos
>= first_vpos
;
17913 --vpos
, --current_row
, --desired_row
)
17915 if (desired_row
->enabled_p
)
17917 if (desired_row
->displays_text_p
)
17920 else if (current_row
->displays_text_p
)
17924 eassert (row
!= NULL
);
17925 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17926 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17927 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17928 eassert (w
->window_end_bytepos
>= 0);
17929 IF_DEBUG (debug_method_add (w
, "C"));
17934 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17935 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17937 /* Record that display has not been completed. */
17938 wset_window_end_valid (w
, Qnil
);
17939 w
->desired_matrix
->no_scrolling_p
= 1;
17947 /***********************************************************************
17948 More debugging support
17949 ***********************************************************************/
17953 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17954 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17955 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17958 /* Dump the contents of glyph matrix MATRIX on stderr.
17960 GLYPHS 0 means don't show glyph contents.
17961 GLYPHS 1 means show glyphs in short form
17962 GLYPHS > 1 means show glyphs in long form. */
17965 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17968 for (i
= 0; i
< matrix
->nrows
; ++i
)
17969 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17973 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17974 the glyph row and area where the glyph comes from. */
17977 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17979 if (glyph
->type
== CHAR_GLYPH
)
17982 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
17983 glyph
- row
->glyphs
[TEXT_AREA
],
17986 (BUFFERP (glyph
->object
)
17988 : (STRINGP (glyph
->object
)
17991 glyph
->pixel_width
,
17993 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17997 glyph
->left_box_line_p
,
17998 glyph
->right_box_line_p
);
18000 else if (glyph
->type
== STRETCH_GLYPH
)
18003 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18004 glyph
- row
->glyphs
[TEXT_AREA
],
18007 (BUFFERP (glyph
->object
)
18009 : (STRINGP (glyph
->object
)
18012 glyph
->pixel_width
,
18016 glyph
->left_box_line_p
,
18017 glyph
->right_box_line_p
);
18019 else if (glyph
->type
== IMAGE_GLYPH
)
18022 " %5td %4c %6"pI
"d %c %3d 0x%05x %c %4d %1.1d%1.1d\n",
18023 glyph
- row
->glyphs
[TEXT_AREA
],
18026 (BUFFERP (glyph
->object
)
18028 : (STRINGP (glyph
->object
)
18031 glyph
->pixel_width
,
18035 glyph
->left_box_line_p
,
18036 glyph
->right_box_line_p
);
18038 else if (glyph
->type
== COMPOSITE_GLYPH
)
18041 " %5td %4c %6"pI
"d %c %3d 0x%05x",
18042 glyph
- row
->glyphs
[TEXT_AREA
],
18045 (BUFFERP (glyph
->object
)
18047 : (STRINGP (glyph
->object
)
18050 glyph
->pixel_width
,
18052 if (glyph
->u
.cmp
.automatic
)
18055 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
18056 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
18058 glyph
->left_box_line_p
,
18059 glyph
->right_box_line_p
);
18064 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
18065 GLYPHS 0 means don't show glyph contents.
18066 GLYPHS 1 means show glyphs in short form
18067 GLYPHS > 1 means show glyphs in long form. */
18070 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
18074 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
18075 fprintf (stderr
, "======================================================================\n");
18077 fprintf (stderr
, "%3d %5"pI
"d %5"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18078 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18080 MATRIX_ROW_START_CHARPOS (row
),
18081 MATRIX_ROW_END_CHARPOS (row
),
18082 row
->used
[TEXT_AREA
],
18083 row
->contains_overlapping_glyphs_p
,
18085 row
->truncated_on_left_p
,
18086 row
->truncated_on_right_p
,
18088 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18089 row
->displays_text_p
,
18092 row
->ends_in_middle_of_char_p
,
18093 row
->starts_in_middle_of_char_p
,
18099 row
->visible_height
,
18102 fprintf (stderr
, "%9"pD
"d %5"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18103 row
->end
.overlay_string_index
,
18104 row
->continuation_lines_width
);
18105 fprintf (stderr
, "%9"pI
"d %5"pI
"d\n",
18106 CHARPOS (row
->start
.string_pos
),
18107 CHARPOS (row
->end
.string_pos
));
18108 fprintf (stderr
, "%9d %5d\n", row
->start
.dpvec_index
,
18109 row
->end
.dpvec_index
);
18116 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18118 struct glyph
*glyph
= row
->glyphs
[area
];
18119 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18121 /* Glyph for a line end in text. */
18122 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18125 if (glyph
< glyph_end
)
18126 fprintf (stderr
, " Glyph Type Pos O W Code C Face LR\n");
18128 for (; glyph
< glyph_end
; ++glyph
)
18129 dump_glyph (row
, glyph
, area
);
18132 else if (glyphs
== 1)
18136 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18138 char *s
= alloca (row
->used
[area
] + 1);
18141 for (i
= 0; i
< row
->used
[area
]; ++i
)
18143 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18144 if (glyph
->type
== CHAR_GLYPH
18145 && glyph
->u
.ch
< 0x80
18146 && glyph
->u
.ch
>= ' ')
18147 s
[i
] = glyph
->u
.ch
;
18153 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18159 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18160 Sdump_glyph_matrix
, 0, 1, "p",
18161 doc
: /* Dump the current matrix of the selected window to stderr.
18162 Shows contents of glyph row structures. With non-nil
18163 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18164 glyphs in short form, otherwise show glyphs in long form. */)
18165 (Lisp_Object glyphs
)
18167 struct window
*w
= XWINDOW (selected_window
);
18168 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18170 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18171 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18172 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18173 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18174 fprintf (stderr
, "=============================================\n");
18175 dump_glyph_matrix (w
->current_matrix
,
18176 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18181 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18182 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18185 struct frame
*f
= XFRAME (selected_frame
);
18186 dump_glyph_matrix (f
->current_matrix
, 1);
18191 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18192 doc
: /* Dump glyph row ROW to stderr.
18193 GLYPH 0 means don't dump glyphs.
18194 GLYPH 1 means dump glyphs in short form.
18195 GLYPH > 1 or omitted means dump glyphs in long form. */)
18196 (Lisp_Object row
, Lisp_Object glyphs
)
18198 struct glyph_matrix
*matrix
;
18201 CHECK_NUMBER (row
);
18202 matrix
= XWINDOW (selected_window
)->current_matrix
;
18204 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18205 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18207 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18212 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18213 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18214 GLYPH 0 means don't dump glyphs.
18215 GLYPH 1 means dump glyphs in short form.
18216 GLYPH > 1 or omitted means dump glyphs in long form. */)
18217 (Lisp_Object row
, Lisp_Object glyphs
)
18219 struct frame
*sf
= SELECTED_FRAME ();
18220 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18223 CHECK_NUMBER (row
);
18225 if (vpos
>= 0 && vpos
< m
->nrows
)
18226 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18227 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18232 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18233 doc
: /* Toggle tracing of redisplay.
18234 With ARG, turn tracing on if and only if ARG is positive. */)
18238 trace_redisplay_p
= !trace_redisplay_p
;
18241 arg
= Fprefix_numeric_value (arg
);
18242 trace_redisplay_p
= XINT (arg
) > 0;
18249 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18250 doc
: /* Like `format', but print result to stderr.
18251 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18252 (ptrdiff_t nargs
, Lisp_Object
*args
)
18254 Lisp_Object s
= Fformat (nargs
, args
);
18255 fprintf (stderr
, "%s", SDATA (s
));
18259 #endif /* GLYPH_DEBUG */
18263 /***********************************************************************
18264 Building Desired Matrix Rows
18265 ***********************************************************************/
18267 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18268 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18270 static struct glyph_row
*
18271 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18273 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18274 struct buffer
*buffer
= XBUFFER (w
->buffer
);
18275 struct buffer
*old
= current_buffer
;
18276 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18277 int arrow_len
= SCHARS (overlay_arrow_string
);
18278 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18279 const unsigned char *p
;
18282 int n_glyphs_before
;
18284 set_buffer_temp (buffer
);
18285 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18286 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18287 SET_TEXT_POS (it
.position
, 0, 0);
18289 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18291 while (p
< arrow_end
)
18293 Lisp_Object face
, ilisp
;
18295 /* Get the next character. */
18297 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18300 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18301 if (! ASCII_CHAR_P (it
.c
))
18302 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18306 /* Get its face. */
18307 ilisp
= make_number (p
- arrow_string
);
18308 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18309 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18311 /* Compute its width, get its glyphs. */
18312 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18313 SET_TEXT_POS (it
.position
, -1, -1);
18314 PRODUCE_GLYPHS (&it
);
18316 /* If this character doesn't fit any more in the line, we have
18317 to remove some glyphs. */
18318 if (it
.current_x
> it
.last_visible_x
)
18320 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18325 set_buffer_temp (old
);
18326 return it
.glyph_row
;
18330 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18331 glyphs to insert is determined by produce_special_glyphs. */
18334 insert_left_trunc_glyphs (struct it
*it
)
18336 struct it truncate_it
;
18337 struct glyph
*from
, *end
, *to
, *toend
;
18339 eassert (!FRAME_WINDOW_P (it
->f
)
18340 || (!it
->glyph_row
->reversed_p
18341 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18342 || (it
->glyph_row
->reversed_p
18343 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18345 /* Get the truncation glyphs. */
18347 truncate_it
.current_x
= 0;
18348 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18349 truncate_it
.glyph_row
= &scratch_glyph_row
;
18350 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18351 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18352 truncate_it
.object
= make_number (0);
18353 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18355 /* Overwrite glyphs from IT with truncation glyphs. */
18356 if (!it
->glyph_row
->reversed_p
)
18358 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18360 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18361 end
= from
+ tused
;
18362 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18363 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18364 if (FRAME_WINDOW_P (it
->f
))
18366 /* On GUI frames, when variable-size fonts are displayed,
18367 the truncation glyphs may need more pixels than the row's
18368 glyphs they overwrite. We overwrite more glyphs to free
18369 enough screen real estate, and enlarge the stretch glyph
18370 on the right (see display_line), if there is one, to
18371 preserve the screen position of the truncation glyphs on
18374 struct glyph
*g
= to
;
18377 /* The first glyph could be partially visible, in which case
18378 it->glyph_row->x will be negative. But we want the left
18379 truncation glyphs to be aligned at the left margin of the
18380 window, so we override the x coordinate at which the row
18382 it
->glyph_row
->x
= 0;
18383 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18385 w
+= g
->pixel_width
;
18388 if (g
- to
- tused
> 0)
18390 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18391 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18393 used
= it
->glyph_row
->used
[TEXT_AREA
];
18394 if (it
->glyph_row
->truncated_on_right_p
18395 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18396 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18399 int extra
= w
- it
->truncation_pixel_width
;
18401 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18408 /* There may be padding glyphs left over. Overwrite them too. */
18409 if (!FRAME_WINDOW_P (it
->f
))
18411 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18413 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18420 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18424 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18426 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18427 that back to front. */
18428 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18429 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18430 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18431 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18432 if (FRAME_WINDOW_P (it
->f
))
18435 struct glyph
*g
= to
;
18437 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18439 w
+= g
->pixel_width
;
18442 if (to
- g
- tused
> 0)
18444 if (it
->glyph_row
->truncated_on_right_p
18445 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18446 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18448 int extra
= w
- it
->truncation_pixel_width
;
18450 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18454 while (from
>= end
&& to
>= toend
)
18456 if (!FRAME_WINDOW_P (it
->f
))
18458 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18461 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18462 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18463 while (from
>= end
&& to
>= toend
)
18469 /* Need to free some room before prepending additional
18471 int move_by
= from
- end
+ 1;
18472 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18473 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18475 for ( ; g
>= g0
; g
--)
18477 while (from
>= end
)
18479 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18484 /* Compute the hash code for ROW. */
18486 row_hash (struct glyph_row
*row
)
18489 unsigned hashval
= 0;
18491 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18492 for (k
= 0; k
< row
->used
[area
]; ++k
)
18493 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18494 + row
->glyphs
[area
][k
].u
.val
18495 + row
->glyphs
[area
][k
].face_id
18496 + row
->glyphs
[area
][k
].padding_p
18497 + (row
->glyphs
[area
][k
].type
<< 2));
18502 /* Compute the pixel height and width of IT->glyph_row.
18504 Most of the time, ascent and height of a display line will be equal
18505 to the max_ascent and max_height values of the display iterator
18506 structure. This is not the case if
18508 1. We hit ZV without displaying anything. In this case, max_ascent
18509 and max_height will be zero.
18511 2. We have some glyphs that don't contribute to the line height.
18512 (The glyph row flag contributes_to_line_height_p is for future
18513 pixmap extensions).
18515 The first case is easily covered by using default values because in
18516 these cases, the line height does not really matter, except that it
18517 must not be zero. */
18520 compute_line_metrics (struct it
*it
)
18522 struct glyph_row
*row
= it
->glyph_row
;
18524 if (FRAME_WINDOW_P (it
->f
))
18526 int i
, min_y
, max_y
;
18528 /* The line may consist of one space only, that was added to
18529 place the cursor on it. If so, the row's height hasn't been
18531 if (row
->height
== 0)
18533 if (it
->max_ascent
+ it
->max_descent
== 0)
18534 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18535 row
->ascent
= it
->max_ascent
;
18536 row
->height
= it
->max_ascent
+ it
->max_descent
;
18537 row
->phys_ascent
= it
->max_phys_ascent
;
18538 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18539 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18542 /* Compute the width of this line. */
18543 row
->pixel_width
= row
->x
;
18544 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18545 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18547 eassert (row
->pixel_width
>= 0);
18548 eassert (row
->ascent
>= 0 && row
->height
> 0);
18550 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18551 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18553 /* If first line's physical ascent is larger than its logical
18554 ascent, use the physical ascent, and make the row taller.
18555 This makes accented characters fully visible. */
18556 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18557 && row
->phys_ascent
> row
->ascent
)
18559 row
->height
+= row
->phys_ascent
- row
->ascent
;
18560 row
->ascent
= row
->phys_ascent
;
18563 /* Compute how much of the line is visible. */
18564 row
->visible_height
= row
->height
;
18566 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18567 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18569 if (row
->y
< min_y
)
18570 row
->visible_height
-= min_y
- row
->y
;
18571 if (row
->y
+ row
->height
> max_y
)
18572 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18576 row
->pixel_width
= row
->used
[TEXT_AREA
];
18577 if (row
->continued_p
)
18578 row
->pixel_width
-= it
->continuation_pixel_width
;
18579 else if (row
->truncated_on_right_p
)
18580 row
->pixel_width
-= it
->truncation_pixel_width
;
18581 row
->ascent
= row
->phys_ascent
= 0;
18582 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18583 row
->extra_line_spacing
= 0;
18586 /* Compute a hash code for this row. */
18587 row
->hash
= row_hash (row
);
18589 it
->max_ascent
= it
->max_descent
= 0;
18590 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18594 /* Append one space to the glyph row of iterator IT if doing a
18595 window-based redisplay. The space has the same face as
18596 IT->face_id. Value is non-zero if a space was added.
18598 This function is called to make sure that there is always one glyph
18599 at the end of a glyph row that the cursor can be set on under
18600 window-systems. (If there weren't such a glyph we would not know
18601 how wide and tall a box cursor should be displayed).
18603 At the same time this space let's a nicely handle clearing to the
18604 end of the line if the row ends in italic text. */
18607 append_space_for_newline (struct it
*it
, int default_face_p
)
18609 if (FRAME_WINDOW_P (it
->f
))
18611 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18613 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18614 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18616 /* Save some values that must not be changed.
18617 Must save IT->c and IT->len because otherwise
18618 ITERATOR_AT_END_P wouldn't work anymore after
18619 append_space_for_newline has been called. */
18620 enum display_element_type saved_what
= it
->what
;
18621 int saved_c
= it
->c
, saved_len
= it
->len
;
18622 int saved_char_to_display
= it
->char_to_display
;
18623 int saved_x
= it
->current_x
;
18624 int saved_face_id
= it
->face_id
;
18625 int saved_box_end
= it
->end_of_box_run_p
;
18626 struct text_pos saved_pos
;
18627 Lisp_Object saved_object
;
18630 saved_object
= it
->object
;
18631 saved_pos
= it
->position
;
18633 it
->what
= IT_CHARACTER
;
18634 memset (&it
->position
, 0, sizeof it
->position
);
18635 it
->object
= make_number (0);
18636 it
->c
= it
->char_to_display
= ' ';
18639 /* If the default face was remapped, be sure to use the
18640 remapped face for the appended newline. */
18641 if (default_face_p
)
18642 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18643 else if (it
->face_before_selective_p
)
18644 it
->face_id
= it
->saved_face_id
;
18645 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18646 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18647 /* In R2L rows, we will prepend a stretch glyph that will
18648 have the end_of_box_run_p flag set for it, so there's no
18649 need for the appended newline glyph to have that flag
18651 if (it
->glyph_row
->reversed_p
18652 /* But if the appended newline glyph goes all the way to
18653 the end of the row, there will be no stretch glyph,
18654 so leave the box flag set. */
18655 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18656 it
->end_of_box_run_p
= 0;
18658 PRODUCE_GLYPHS (it
);
18660 it
->override_ascent
= -1;
18661 it
->constrain_row_ascent_descent_p
= 0;
18662 it
->current_x
= saved_x
;
18663 it
->object
= saved_object
;
18664 it
->position
= saved_pos
;
18665 it
->what
= saved_what
;
18666 it
->face_id
= saved_face_id
;
18667 it
->len
= saved_len
;
18669 it
->char_to_display
= saved_char_to_display
;
18670 it
->end_of_box_run_p
= saved_box_end
;
18679 /* Extend the face of the last glyph in the text area of IT->glyph_row
18680 to the end of the display line. Called from display_line. If the
18681 glyph row is empty, add a space glyph to it so that we know the
18682 face to draw. Set the glyph row flag fill_line_p. If the glyph
18683 row is R2L, prepend a stretch glyph to cover the empty space to the
18684 left of the leftmost glyph. */
18687 extend_face_to_end_of_line (struct it
*it
)
18689 struct face
*face
, *default_face
;
18690 struct frame
*f
= it
->f
;
18692 /* If line is already filled, do nothing. Non window-system frames
18693 get a grace of one more ``pixel'' because their characters are
18694 1-``pixel'' wide, so they hit the equality too early. This grace
18695 is needed only for R2L rows that are not continued, to produce
18696 one extra blank where we could display the cursor. */
18697 if (it
->current_x
>= it
->last_visible_x
18698 + (!FRAME_WINDOW_P (f
)
18699 && it
->glyph_row
->reversed_p
18700 && !it
->glyph_row
->continued_p
))
18703 /* The default face, possibly remapped. */
18704 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18706 /* Face extension extends the background and box of IT->face_id
18707 to the end of the line. If the background equals the background
18708 of the frame, we don't have to do anything. */
18709 if (it
->face_before_selective_p
)
18710 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18712 face
= FACE_FROM_ID (f
, it
->face_id
);
18714 if (FRAME_WINDOW_P (f
)
18715 && it
->glyph_row
->displays_text_p
18716 && face
->box
== FACE_NO_BOX
18717 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18719 && !it
->glyph_row
->reversed_p
)
18722 /* Set the glyph row flag indicating that the face of the last glyph
18723 in the text area has to be drawn to the end of the text area. */
18724 it
->glyph_row
->fill_line_p
= 1;
18726 /* If current character of IT is not ASCII, make sure we have the
18727 ASCII face. This will be automatically undone the next time
18728 get_next_display_element returns a multibyte character. Note
18729 that the character will always be single byte in unibyte
18731 if (!ASCII_CHAR_P (it
->c
))
18733 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18736 if (FRAME_WINDOW_P (f
))
18738 /* If the row is empty, add a space with the current face of IT,
18739 so that we know which face to draw. */
18740 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18742 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18743 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18744 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18746 #ifdef HAVE_WINDOW_SYSTEM
18747 if (it
->glyph_row
->reversed_p
)
18749 /* Prepend a stretch glyph to the row, such that the
18750 rightmost glyph will be drawn flushed all the way to the
18751 right margin of the window. The stretch glyph that will
18752 occupy the empty space, if any, to the left of the
18754 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18755 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18756 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18758 int row_width
, stretch_ascent
, stretch_width
;
18759 struct text_pos saved_pos
;
18760 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18762 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18763 row_width
+= g
->pixel_width
;
18764 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18765 if (stretch_width
> 0)
18768 (((it
->ascent
+ it
->descent
)
18769 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18770 saved_pos
= it
->position
;
18771 memset (&it
->position
, 0, sizeof it
->position
);
18772 saved_avoid_cursor
= it
->avoid_cursor_p
;
18773 it
->avoid_cursor_p
= 1;
18774 saved_face_id
= it
->face_id
;
18775 saved_box_start
= it
->start_of_box_run_p
;
18776 /* The last row's stretch glyph should get the default
18777 face, to avoid painting the rest of the window with
18778 the region face, if the region ends at ZV. */
18779 if (it
->glyph_row
->ends_at_zv_p
)
18780 it
->face_id
= default_face
->id
;
18782 it
->face_id
= face
->id
;
18783 it
->start_of_box_run_p
= 0;
18784 append_stretch_glyph (it
, make_number (0), stretch_width
,
18785 it
->ascent
+ it
->descent
, stretch_ascent
);
18786 it
->position
= saved_pos
;
18787 it
->avoid_cursor_p
= saved_avoid_cursor
;
18788 it
->face_id
= saved_face_id
;
18789 it
->start_of_box_run_p
= saved_box_start
;
18792 #endif /* HAVE_WINDOW_SYSTEM */
18796 /* Save some values that must not be changed. */
18797 int saved_x
= it
->current_x
;
18798 struct text_pos saved_pos
;
18799 Lisp_Object saved_object
;
18800 enum display_element_type saved_what
= it
->what
;
18801 int saved_face_id
= it
->face_id
;
18803 saved_object
= it
->object
;
18804 saved_pos
= it
->position
;
18806 it
->what
= IT_CHARACTER
;
18807 memset (&it
->position
, 0, sizeof it
->position
);
18808 it
->object
= make_number (0);
18809 it
->c
= it
->char_to_display
= ' ';
18811 /* The last row's blank glyphs should get the default face, to
18812 avoid painting the rest of the window with the region face,
18813 if the region ends at ZV. */
18814 if (it
->glyph_row
->ends_at_zv_p
)
18815 it
->face_id
= default_face
->id
;
18817 it
->face_id
= face
->id
;
18819 PRODUCE_GLYPHS (it
);
18821 while (it
->current_x
<= it
->last_visible_x
)
18822 PRODUCE_GLYPHS (it
);
18824 /* Don't count these blanks really. It would let us insert a left
18825 truncation glyph below and make us set the cursor on them, maybe. */
18826 it
->current_x
= saved_x
;
18827 it
->object
= saved_object
;
18828 it
->position
= saved_pos
;
18829 it
->what
= saved_what
;
18830 it
->face_id
= saved_face_id
;
18835 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18836 trailing whitespace. */
18839 trailing_whitespace_p (ptrdiff_t charpos
)
18841 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18844 while (bytepos
< ZV_BYTE
18845 && (c
= FETCH_CHAR (bytepos
),
18846 c
== ' ' || c
== '\t'))
18849 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18851 if (bytepos
!= PT_BYTE
)
18858 /* Highlight trailing whitespace, if any, in ROW. */
18861 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18863 int used
= row
->used
[TEXT_AREA
];
18867 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18868 struct glyph
*glyph
= start
+ used
- 1;
18870 if (row
->reversed_p
)
18872 /* Right-to-left rows need to be processed in the opposite
18873 direction, so swap the edge pointers. */
18875 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18878 /* Skip over glyphs inserted to display the cursor at the
18879 end of a line, for extending the face of the last glyph
18880 to the end of the line on terminals, and for truncation
18881 and continuation glyphs. */
18882 if (!row
->reversed_p
)
18884 while (glyph
>= start
18885 && glyph
->type
== CHAR_GLYPH
18886 && INTEGERP (glyph
->object
))
18891 while (glyph
<= start
18892 && glyph
->type
== CHAR_GLYPH
18893 && INTEGERP (glyph
->object
))
18897 /* If last glyph is a space or stretch, and it's trailing
18898 whitespace, set the face of all trailing whitespace glyphs in
18899 IT->glyph_row to `trailing-whitespace'. */
18900 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18901 && BUFFERP (glyph
->object
)
18902 && (glyph
->type
== STRETCH_GLYPH
18903 || (glyph
->type
== CHAR_GLYPH
18904 && glyph
->u
.ch
== ' '))
18905 && trailing_whitespace_p (glyph
->charpos
))
18907 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18911 if (!row
->reversed_p
)
18913 while (glyph
>= start
18914 && BUFFERP (glyph
->object
)
18915 && (glyph
->type
== STRETCH_GLYPH
18916 || (glyph
->type
== CHAR_GLYPH
18917 && glyph
->u
.ch
== ' ')))
18918 (glyph
--)->face_id
= face_id
;
18922 while (glyph
<= start
18923 && BUFFERP (glyph
->object
)
18924 && (glyph
->type
== STRETCH_GLYPH
18925 || (glyph
->type
== CHAR_GLYPH
18926 && glyph
->u
.ch
== ' ')))
18927 (glyph
++)->face_id
= face_id
;
18934 /* Value is non-zero if glyph row ROW should be
18935 used to hold the cursor. */
18938 cursor_row_p (struct glyph_row
*row
)
18942 if (PT
== CHARPOS (row
->end
.pos
)
18943 || PT
== MATRIX_ROW_END_CHARPOS (row
))
18945 /* Suppose the row ends on a string.
18946 Unless the row is continued, that means it ends on a newline
18947 in the string. If it's anything other than a display string
18948 (e.g., a before-string from an overlay), we don't want the
18949 cursor there. (This heuristic seems to give the optimal
18950 behavior for the various types of multi-line strings.)
18951 One exception: if the string has `cursor' property on one of
18952 its characters, we _do_ want the cursor there. */
18953 if (CHARPOS (row
->end
.string_pos
) >= 0)
18955 if (row
->continued_p
)
18959 /* Check for `display' property. */
18960 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18961 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18962 struct glyph
*glyph
;
18965 for (glyph
= end
; glyph
>= beg
; --glyph
)
18966 if (STRINGP (glyph
->object
))
18969 = Fget_char_property (make_number (PT
),
18973 && display_prop_string_p (prop
, glyph
->object
));
18974 /* If there's a `cursor' property on one of the
18975 string's characters, this row is a cursor row,
18976 even though this is not a display string. */
18979 Lisp_Object s
= glyph
->object
;
18981 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18983 ptrdiff_t gpos
= glyph
->charpos
;
18985 if (!NILP (Fget_char_property (make_number (gpos
),
18997 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18999 /* If the row ends in middle of a real character,
19000 and the line is continued, we want the cursor here.
19001 That's because CHARPOS (ROW->end.pos) would equal
19002 PT if PT is before the character. */
19003 if (!row
->ends_in_ellipsis_p
)
19004 result
= row
->continued_p
;
19006 /* If the row ends in an ellipsis, then
19007 CHARPOS (ROW->end.pos) will equal point after the
19008 invisible text. We want that position to be displayed
19009 after the ellipsis. */
19012 /* If the row ends at ZV, display the cursor at the end of that
19013 row instead of at the start of the row below. */
19014 else if (row
->ends_at_zv_p
)
19025 /* Push the property PROP so that it will be rendered at the current
19026 position in IT. Return 1 if PROP was successfully pushed, 0
19027 otherwise. Called from handle_line_prefix to handle the
19028 `line-prefix' and `wrap-prefix' properties. */
19031 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
19033 struct text_pos pos
=
19034 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
19036 eassert (it
->method
== GET_FROM_BUFFER
19037 || it
->method
== GET_FROM_DISPLAY_VECTOR
19038 || it
->method
== GET_FROM_STRING
);
19040 /* We need to save the current buffer/string position, so it will be
19041 restored by pop_it, because iterate_out_of_display_property
19042 depends on that being set correctly, but some situations leave
19043 it->position not yet set when this function is called. */
19044 push_it (it
, &pos
);
19046 if (STRINGP (prop
))
19048 if (SCHARS (prop
) == 0)
19055 it
->string_from_prefix_prop_p
= 1;
19056 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19057 it
->current
.overlay_string_index
= -1;
19058 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19059 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19060 it
->method
= GET_FROM_STRING
;
19061 it
->stop_charpos
= 0;
19063 it
->base_level_stop
= 0;
19065 /* Force paragraph direction to be that of the parent
19067 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19068 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19070 it
->paragraph_embedding
= L2R
;
19072 /* Set up the bidi iterator for this display string. */
19075 it
->bidi_it
.string
.lstring
= it
->string
;
19076 it
->bidi_it
.string
.s
= NULL
;
19077 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19078 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19079 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19080 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19081 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19084 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19086 it
->method
= GET_FROM_STRETCH
;
19089 #ifdef HAVE_WINDOW_SYSTEM
19090 else if (IMAGEP (prop
))
19092 it
->what
= IT_IMAGE
;
19093 it
->image_id
= lookup_image (it
->f
, prop
);
19094 it
->method
= GET_FROM_IMAGE
;
19096 #endif /* HAVE_WINDOW_SYSTEM */
19099 pop_it (it
); /* bogus display property, give up */
19106 /* Return the character-property PROP at the current position in IT. */
19109 get_it_property (struct it
*it
, Lisp_Object prop
)
19111 Lisp_Object position
;
19113 if (STRINGP (it
->object
))
19114 position
= make_number (IT_STRING_CHARPOS (*it
));
19115 else if (BUFFERP (it
->object
))
19116 position
= make_number (IT_CHARPOS (*it
));
19120 return Fget_char_property (position
, prop
, it
->object
);
19123 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19126 handle_line_prefix (struct it
*it
)
19128 Lisp_Object prefix
;
19130 if (it
->continuation_lines_width
> 0)
19132 prefix
= get_it_property (it
, Qwrap_prefix
);
19134 prefix
= Vwrap_prefix
;
19138 prefix
= get_it_property (it
, Qline_prefix
);
19140 prefix
= Vline_prefix
;
19142 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19144 /* If the prefix is wider than the window, and we try to wrap
19145 it, it would acquire its own wrap prefix, and so on till the
19146 iterator stack overflows. So, don't wrap the prefix. */
19147 it
->line_wrap
= TRUNCATE
;
19148 it
->avoid_cursor_p
= 1;
19154 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19155 only for R2L lines from display_line and display_string, when they
19156 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19157 the line/string needs to be continued on the next glyph row. */
19159 unproduce_glyphs (struct it
*it
, int n
)
19161 struct glyph
*glyph
, *end
;
19163 eassert (it
->glyph_row
);
19164 eassert (it
->glyph_row
->reversed_p
);
19165 eassert (it
->area
== TEXT_AREA
);
19166 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19168 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19169 n
= it
->glyph_row
->used
[TEXT_AREA
];
19170 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19171 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19172 for ( ; glyph
< end
; glyph
++)
19173 glyph
[-n
] = *glyph
;
19176 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19177 and ROW->maxpos. */
19179 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19180 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19181 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19183 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19184 lines' rows is implemented for bidi-reordered rows. */
19186 /* ROW->minpos is the value of min_pos, the minimal buffer position
19187 we have in ROW, or ROW->start.pos if that is smaller. */
19188 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19189 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19191 /* We didn't find buffer positions smaller than ROW->start, or
19192 didn't find _any_ valid buffer positions in any of the glyphs,
19193 so we must trust the iterator's computed positions. */
19194 row
->minpos
= row
->start
.pos
;
19197 max_pos
= CHARPOS (it
->current
.pos
);
19198 max_bpos
= BYTEPOS (it
->current
.pos
);
19201 /* Here are the various use-cases for ending the row, and the
19202 corresponding values for ROW->maxpos:
19204 Line ends in a newline from buffer eol_pos + 1
19205 Line is continued from buffer max_pos + 1
19206 Line is truncated on right it->current.pos
19207 Line ends in a newline from string max_pos + 1(*)
19208 (*) + 1 only when line ends in a forward scan
19209 Line is continued from string max_pos
19210 Line is continued from display vector max_pos
19211 Line is entirely from a string min_pos == max_pos
19212 Line is entirely from a display vector min_pos == max_pos
19213 Line that ends at ZV ZV
19215 If you discover other use-cases, please add them here as
19217 if (row
->ends_at_zv_p
)
19218 row
->maxpos
= it
->current
.pos
;
19219 else if (row
->used
[TEXT_AREA
])
19221 int seen_this_string
= 0;
19222 struct glyph_row
*r1
= row
- 1;
19224 /* Did we see the same display string on the previous row? */
19225 if (STRINGP (it
->object
)
19226 /* this is not the first row */
19227 && row
> it
->w
->desired_matrix
->rows
19228 /* previous row is not the header line */
19229 && !r1
->mode_line_p
19230 /* previous row also ends in a newline from a string */
19231 && r1
->ends_in_newline_from_string_p
)
19233 struct glyph
*start
, *end
;
19235 /* Search for the last glyph of the previous row that came
19236 from buffer or string. Depending on whether the row is
19237 L2R or R2L, we need to process it front to back or the
19238 other way round. */
19239 if (!r1
->reversed_p
)
19241 start
= r1
->glyphs
[TEXT_AREA
];
19242 end
= start
+ r1
->used
[TEXT_AREA
];
19243 /* Glyphs inserted by redisplay have an integer (zero)
19244 as their object. */
19246 && INTEGERP ((end
- 1)->object
)
19247 && (end
- 1)->charpos
<= 0)
19251 if (EQ ((end
- 1)->object
, it
->object
))
19252 seen_this_string
= 1;
19255 /* If all the glyphs of the previous row were inserted
19256 by redisplay, it means the previous row was
19257 produced from a single newline, which is only
19258 possible if that newline came from the same string
19259 as the one which produced this ROW. */
19260 seen_this_string
= 1;
19264 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19265 start
= end
+ r1
->used
[TEXT_AREA
];
19267 && INTEGERP ((end
+ 1)->object
)
19268 && (end
+ 1)->charpos
<= 0)
19272 if (EQ ((end
+ 1)->object
, it
->object
))
19273 seen_this_string
= 1;
19276 seen_this_string
= 1;
19279 /* Take note of each display string that covers a newline only
19280 once, the first time we see it. This is for when a display
19281 string includes more than one newline in it. */
19282 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19284 /* If we were scanning the buffer forward when we displayed
19285 the string, we want to account for at least one buffer
19286 position that belongs to this row (position covered by
19287 the display string), so that cursor positioning will
19288 consider this row as a candidate when point is at the end
19289 of the visual line represented by this row. This is not
19290 required when scanning back, because max_pos will already
19291 have a much larger value. */
19292 if (CHARPOS (row
->end
.pos
) > max_pos
)
19293 INC_BOTH (max_pos
, max_bpos
);
19294 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19296 else if (CHARPOS (it
->eol_pos
) > 0)
19297 SET_TEXT_POS (row
->maxpos
,
19298 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19299 else if (row
->continued_p
)
19301 /* If max_pos is different from IT's current position, it
19302 means IT->method does not belong to the display element
19303 at max_pos. However, it also means that the display
19304 element at max_pos was displayed in its entirety on this
19305 line, which is equivalent to saying that the next line
19306 starts at the next buffer position. */
19307 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19308 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19311 INC_BOTH (max_pos
, max_bpos
);
19312 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19315 else if (row
->truncated_on_right_p
)
19316 /* display_line already called reseat_at_next_visible_line_start,
19317 which puts the iterator at the beginning of the next line, in
19318 the logical order. */
19319 row
->maxpos
= it
->current
.pos
;
19320 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19321 /* A line that is entirely from a string/image/stretch... */
19322 row
->maxpos
= row
->minpos
;
19327 row
->maxpos
= it
->current
.pos
;
19330 /* Construct the glyph row IT->glyph_row in the desired matrix of
19331 IT->w from text at the current position of IT. See dispextern.h
19332 for an overview of struct it. Value is non-zero if
19333 IT->glyph_row displays text, as opposed to a line displaying ZV
19337 display_line (struct it
*it
)
19339 struct glyph_row
*row
= it
->glyph_row
;
19340 Lisp_Object overlay_arrow_string
;
19342 void *wrap_data
= NULL
;
19343 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19344 int wrap_row_used
= -1;
19345 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19346 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19347 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19348 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19349 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19351 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19352 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19354 /* We always start displaying at hpos zero even if hscrolled. */
19355 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19357 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19358 >= it
->w
->desired_matrix
->nrows
)
19360 it
->w
->nrows_scale_factor
++;
19361 fonts_changed_p
= 1;
19365 /* Is IT->w showing the region? */
19366 wset_region_showing (it
->w
, it
->region_beg_charpos
> 0 ? Qt
: Qnil
);
19368 /* Clear the result glyph row and enable it. */
19369 prepare_desired_row (row
);
19371 row
->y
= it
->current_y
;
19372 row
->start
= it
->start
;
19373 row
->continuation_lines_width
= it
->continuation_lines_width
;
19374 row
->displays_text_p
= 1;
19375 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19376 it
->starts_in_middle_of_char_p
= 0;
19378 /* Arrange the overlays nicely for our purposes. Usually, we call
19379 display_line on only one line at a time, in which case this
19380 can't really hurt too much, or we call it on lines which appear
19381 one after another in the buffer, in which case all calls to
19382 recenter_overlay_lists but the first will be pretty cheap. */
19383 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19385 /* Move over display elements that are not visible because we are
19386 hscrolled. This may stop at an x-position < IT->first_visible_x
19387 if the first glyph is partially visible or if we hit a line end. */
19388 if (it
->current_x
< it
->first_visible_x
)
19390 enum move_it_result move_result
;
19392 this_line_min_pos
= row
->start
.pos
;
19393 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19394 MOVE_TO_POS
| MOVE_TO_X
);
19395 /* If we are under a large hscroll, move_it_in_display_line_to
19396 could hit the end of the line without reaching
19397 it->first_visible_x. Pretend that we did reach it. This is
19398 especially important on a TTY, where we will call
19399 extend_face_to_end_of_line, which needs to know how many
19400 blank glyphs to produce. */
19401 if (it
->current_x
< it
->first_visible_x
19402 && (move_result
== MOVE_NEWLINE_OR_CR
19403 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19404 it
->current_x
= it
->first_visible_x
;
19406 /* Record the smallest positions seen while we moved over
19407 display elements that are not visible. This is needed by
19408 redisplay_internal for optimizing the case where the cursor
19409 stays inside the same line. The rest of this function only
19410 considers positions that are actually displayed, so
19411 RECORD_MAX_MIN_POS will not otherwise record positions that
19412 are hscrolled to the left of the left edge of the window. */
19413 min_pos
= CHARPOS (this_line_min_pos
);
19414 min_bpos
= BYTEPOS (this_line_min_pos
);
19418 /* We only do this when not calling `move_it_in_display_line_to'
19419 above, because move_it_in_display_line_to calls
19420 handle_line_prefix itself. */
19421 handle_line_prefix (it
);
19424 /* Get the initial row height. This is either the height of the
19425 text hscrolled, if there is any, or zero. */
19426 row
->ascent
= it
->max_ascent
;
19427 row
->height
= it
->max_ascent
+ it
->max_descent
;
19428 row
->phys_ascent
= it
->max_phys_ascent
;
19429 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19430 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19432 /* Utility macro to record max and min buffer positions seen until now. */
19433 #define RECORD_MAX_MIN_POS(IT) \
19436 int composition_p = !STRINGP ((IT)->string) \
19437 && ((IT)->what == IT_COMPOSITION); \
19438 ptrdiff_t current_pos = \
19439 composition_p ? (IT)->cmp_it.charpos \
19440 : IT_CHARPOS (*(IT)); \
19441 ptrdiff_t current_bpos = \
19442 composition_p ? CHAR_TO_BYTE (current_pos) \
19443 : IT_BYTEPOS (*(IT)); \
19444 if (current_pos < min_pos) \
19446 min_pos = current_pos; \
19447 min_bpos = current_bpos; \
19449 if (IT_CHARPOS (*it) > max_pos) \
19451 max_pos = IT_CHARPOS (*it); \
19452 max_bpos = IT_BYTEPOS (*it); \
19457 /* Loop generating characters. The loop is left with IT on the next
19458 character to display. */
19461 int n_glyphs_before
, hpos_before
, x_before
;
19463 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19465 /* Retrieve the next thing to display. Value is zero if end of
19467 if (!get_next_display_element (it
))
19469 /* Maybe add a space at the end of this line that is used to
19470 display the cursor there under X. Set the charpos of the
19471 first glyph of blank lines not corresponding to any text
19473 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19474 row
->exact_window_width_line_p
= 1;
19475 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19476 || row
->used
[TEXT_AREA
] == 0)
19478 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19479 row
->displays_text_p
= 0;
19481 if (!NILP (BVAR (XBUFFER (it
->w
->buffer
), indicate_empty_lines
))
19482 && (!MINI_WINDOW_P (it
->w
)
19483 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19484 row
->indicate_empty_line_p
= 1;
19487 it
->continuation_lines_width
= 0;
19488 row
->ends_at_zv_p
= 1;
19489 /* A row that displays right-to-left text must always have
19490 its last face extended all the way to the end of line,
19491 even if this row ends in ZV, because we still write to
19492 the screen left to right. We also need to extend the
19493 last face if the default face is remapped to some
19494 different face, otherwise the functions that clear
19495 portions of the screen will clear with the default face's
19496 background color. */
19497 if (row
->reversed_p
19498 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19499 extend_face_to_end_of_line (it
);
19503 /* Now, get the metrics of what we want to display. This also
19504 generates glyphs in `row' (which is IT->glyph_row). */
19505 n_glyphs_before
= row
->used
[TEXT_AREA
];
19508 /* Remember the line height so far in case the next element doesn't
19509 fit on the line. */
19510 if (it
->line_wrap
!= TRUNCATE
)
19512 ascent
= it
->max_ascent
;
19513 descent
= it
->max_descent
;
19514 phys_ascent
= it
->max_phys_ascent
;
19515 phys_descent
= it
->max_phys_descent
;
19517 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19519 if (IT_DISPLAYING_WHITESPACE (it
))
19523 SAVE_IT (wrap_it
, *it
, wrap_data
);
19525 wrap_row_used
= row
->used
[TEXT_AREA
];
19526 wrap_row_ascent
= row
->ascent
;
19527 wrap_row_height
= row
->height
;
19528 wrap_row_phys_ascent
= row
->phys_ascent
;
19529 wrap_row_phys_height
= row
->phys_height
;
19530 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19531 wrap_row_min_pos
= min_pos
;
19532 wrap_row_min_bpos
= min_bpos
;
19533 wrap_row_max_pos
= max_pos
;
19534 wrap_row_max_bpos
= max_bpos
;
19540 PRODUCE_GLYPHS (it
);
19542 /* If this display element was in marginal areas, continue with
19544 if (it
->area
!= TEXT_AREA
)
19546 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19547 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19548 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19549 row
->phys_height
= max (row
->phys_height
,
19550 it
->max_phys_ascent
+ it
->max_phys_descent
);
19551 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19552 it
->max_extra_line_spacing
);
19553 set_iterator_to_next (it
, 1);
19557 /* Does the display element fit on the line? If we truncate
19558 lines, we should draw past the right edge of the window. If
19559 we don't truncate, we want to stop so that we can display the
19560 continuation glyph before the right margin. If lines are
19561 continued, there are two possible strategies for characters
19562 resulting in more than 1 glyph (e.g. tabs): Display as many
19563 glyphs as possible in this line and leave the rest for the
19564 continuation line, or display the whole element in the next
19565 line. Original redisplay did the former, so we do it also. */
19566 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19567 hpos_before
= it
->hpos
;
19570 if (/* Not a newline. */
19572 /* Glyphs produced fit entirely in the line. */
19573 && it
->current_x
< it
->last_visible_x
)
19575 it
->hpos
+= nglyphs
;
19576 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19577 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19578 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19579 row
->phys_height
= max (row
->phys_height
,
19580 it
->max_phys_ascent
+ it
->max_phys_descent
);
19581 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19582 it
->max_extra_line_spacing
);
19583 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19584 row
->x
= x
- it
->first_visible_x
;
19585 /* Record the maximum and minimum buffer positions seen so
19586 far in glyphs that will be displayed by this row. */
19588 RECORD_MAX_MIN_POS (it
);
19593 struct glyph
*glyph
;
19595 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19597 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19598 new_x
= x
+ glyph
->pixel_width
;
19600 if (/* Lines are continued. */
19601 it
->line_wrap
!= TRUNCATE
19602 && (/* Glyph doesn't fit on the line. */
19603 new_x
> it
->last_visible_x
19604 /* Or it fits exactly on a window system frame. */
19605 || (new_x
== it
->last_visible_x
19606 && FRAME_WINDOW_P (it
->f
)
19607 && (row
->reversed_p
19608 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19609 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19611 /* End of a continued line. */
19614 || (new_x
== it
->last_visible_x
19615 && FRAME_WINDOW_P (it
->f
)
19616 && (row
->reversed_p
19617 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19618 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19620 /* Current glyph is the only one on the line or
19621 fits exactly on the line. We must continue
19622 the line because we can't draw the cursor
19623 after the glyph. */
19624 row
->continued_p
= 1;
19625 it
->current_x
= new_x
;
19626 it
->continuation_lines_width
+= new_x
;
19628 if (i
== nglyphs
- 1)
19630 /* If line-wrap is on, check if a previous
19631 wrap point was found. */
19632 if (wrap_row_used
> 0
19633 /* Even if there is a previous wrap
19634 point, continue the line here as
19635 usual, if (i) the previous character
19636 was a space or tab AND (ii) the
19637 current character is not. */
19639 || IT_DISPLAYING_WHITESPACE (it
)))
19642 /* Record the maximum and minimum buffer
19643 positions seen so far in glyphs that will be
19644 displayed by this row. */
19646 RECORD_MAX_MIN_POS (it
);
19647 set_iterator_to_next (it
, 1);
19648 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19650 if (!get_next_display_element (it
))
19652 row
->exact_window_width_line_p
= 1;
19653 it
->continuation_lines_width
= 0;
19654 row
->continued_p
= 0;
19655 row
->ends_at_zv_p
= 1;
19657 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19659 row
->continued_p
= 0;
19660 row
->exact_window_width_line_p
= 1;
19664 else if (it
->bidi_p
)
19665 RECORD_MAX_MIN_POS (it
);
19667 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19668 && !FRAME_WINDOW_P (it
->f
))
19670 /* A padding glyph that doesn't fit on this line.
19671 This means the whole character doesn't fit
19673 if (row
->reversed_p
)
19674 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19675 - n_glyphs_before
);
19676 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19678 /* Fill the rest of the row with continuation
19679 glyphs like in 20.x. */
19680 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19681 < row
->glyphs
[1 + TEXT_AREA
])
19682 produce_special_glyphs (it
, IT_CONTINUATION
);
19684 row
->continued_p
= 1;
19685 it
->current_x
= x_before
;
19686 it
->continuation_lines_width
+= x_before
;
19688 /* Restore the height to what it was before the
19689 element not fitting on the line. */
19690 it
->max_ascent
= ascent
;
19691 it
->max_descent
= descent
;
19692 it
->max_phys_ascent
= phys_ascent
;
19693 it
->max_phys_descent
= phys_descent
;
19695 else if (wrap_row_used
> 0)
19698 if (row
->reversed_p
)
19699 unproduce_glyphs (it
,
19700 row
->used
[TEXT_AREA
] - wrap_row_used
);
19701 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19702 it
->continuation_lines_width
+= wrap_x
;
19703 row
->used
[TEXT_AREA
] = wrap_row_used
;
19704 row
->ascent
= wrap_row_ascent
;
19705 row
->height
= wrap_row_height
;
19706 row
->phys_ascent
= wrap_row_phys_ascent
;
19707 row
->phys_height
= wrap_row_phys_height
;
19708 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19709 min_pos
= wrap_row_min_pos
;
19710 min_bpos
= wrap_row_min_bpos
;
19711 max_pos
= wrap_row_max_pos
;
19712 max_bpos
= wrap_row_max_bpos
;
19713 row
->continued_p
= 1;
19714 row
->ends_at_zv_p
= 0;
19715 row
->exact_window_width_line_p
= 0;
19716 it
->continuation_lines_width
+= x
;
19718 /* Make sure that a non-default face is extended
19719 up to the right margin of the window. */
19720 extend_face_to_end_of_line (it
);
19722 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19724 /* A TAB that extends past the right edge of the
19725 window. This produces a single glyph on
19726 window system frames. We leave the glyph in
19727 this row and let it fill the row, but don't
19728 consume the TAB. */
19729 if ((row
->reversed_p
19730 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19731 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19732 produce_special_glyphs (it
, IT_CONTINUATION
);
19733 it
->continuation_lines_width
+= it
->last_visible_x
;
19734 row
->ends_in_middle_of_char_p
= 1;
19735 row
->continued_p
= 1;
19736 glyph
->pixel_width
= it
->last_visible_x
- x
;
19737 it
->starts_in_middle_of_char_p
= 1;
19741 /* Something other than a TAB that draws past
19742 the right edge of the window. Restore
19743 positions to values before the element. */
19744 if (row
->reversed_p
)
19745 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19746 - (n_glyphs_before
+ i
));
19747 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19749 /* Display continuation glyphs. */
19750 it
->current_x
= x_before
;
19751 it
->continuation_lines_width
+= x
;
19752 if (!FRAME_WINDOW_P (it
->f
)
19753 || (row
->reversed_p
19754 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19755 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19756 produce_special_glyphs (it
, IT_CONTINUATION
);
19757 row
->continued_p
= 1;
19759 extend_face_to_end_of_line (it
);
19761 if (nglyphs
> 1 && i
> 0)
19763 row
->ends_in_middle_of_char_p
= 1;
19764 it
->starts_in_middle_of_char_p
= 1;
19767 /* Restore the height to what it was before the
19768 element not fitting on the line. */
19769 it
->max_ascent
= ascent
;
19770 it
->max_descent
= descent
;
19771 it
->max_phys_ascent
= phys_ascent
;
19772 it
->max_phys_descent
= phys_descent
;
19777 else if (new_x
> it
->first_visible_x
)
19779 /* Increment number of glyphs actually displayed. */
19782 /* Record the maximum and minimum buffer positions
19783 seen so far in glyphs that will be displayed by
19786 RECORD_MAX_MIN_POS (it
);
19788 if (x
< it
->first_visible_x
)
19789 /* Glyph is partially visible, i.e. row starts at
19790 negative X position. */
19791 row
->x
= x
- it
->first_visible_x
;
19795 /* Glyph is completely off the left margin of the
19796 window. This should not happen because of the
19797 move_it_in_display_line at the start of this
19798 function, unless the text display area of the
19799 window is empty. */
19800 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19803 /* Even if this display element produced no glyphs at all,
19804 we want to record its position. */
19805 if (it
->bidi_p
&& nglyphs
== 0)
19806 RECORD_MAX_MIN_POS (it
);
19808 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19809 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19810 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19811 row
->phys_height
= max (row
->phys_height
,
19812 it
->max_phys_ascent
+ it
->max_phys_descent
);
19813 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19814 it
->max_extra_line_spacing
);
19816 /* End of this display line if row is continued. */
19817 if (row
->continued_p
|| row
->ends_at_zv_p
)
19822 /* Is this a line end? If yes, we're also done, after making
19823 sure that a non-default face is extended up to the right
19824 margin of the window. */
19825 if (ITERATOR_AT_END_OF_LINE_P (it
))
19827 int used_before
= row
->used
[TEXT_AREA
];
19829 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19831 /* Add a space at the end of the line that is used to
19832 display the cursor there. */
19833 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19834 append_space_for_newline (it
, 0);
19836 /* Extend the face to the end of the line. */
19837 extend_face_to_end_of_line (it
);
19839 /* Make sure we have the position. */
19840 if (used_before
== 0)
19841 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19843 /* Record the position of the newline, for use in
19845 it
->eol_pos
= it
->current
.pos
;
19847 /* Consume the line end. This skips over invisible lines. */
19848 set_iterator_to_next (it
, 1);
19849 it
->continuation_lines_width
= 0;
19853 /* Proceed with next display element. Note that this skips
19854 over lines invisible because of selective display. */
19855 set_iterator_to_next (it
, 1);
19857 /* If we truncate lines, we are done when the last displayed
19858 glyphs reach past the right margin of the window. */
19859 if (it
->line_wrap
== TRUNCATE
19860 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19861 ? (it
->current_x
>= it
->last_visible_x
)
19862 : (it
->current_x
> it
->last_visible_x
)))
19864 /* Maybe add truncation glyphs. */
19865 if (!FRAME_WINDOW_P (it
->f
)
19866 || (row
->reversed_p
19867 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19868 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19872 if (!row
->reversed_p
)
19874 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19875 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19880 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19881 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19883 /* Remove any padding glyphs at the front of ROW, to
19884 make room for the truncation glyphs we will be
19885 adding below. The loop below always inserts at
19886 least one truncation glyph, so also remove the
19887 last glyph added to ROW. */
19888 unproduce_glyphs (it
, i
+ 1);
19889 /* Adjust i for the loop below. */
19890 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19893 it
->current_x
= x_before
;
19894 if (!FRAME_WINDOW_P (it
->f
))
19896 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19898 row
->used
[TEXT_AREA
] = i
;
19899 produce_special_glyphs (it
, IT_TRUNCATION
);
19904 row
->used
[TEXT_AREA
] = i
;
19905 produce_special_glyphs (it
, IT_TRUNCATION
);
19908 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19910 /* Don't truncate if we can overflow newline into fringe. */
19911 if (!get_next_display_element (it
))
19913 it
->continuation_lines_width
= 0;
19914 row
->ends_at_zv_p
= 1;
19915 row
->exact_window_width_line_p
= 1;
19918 if (ITERATOR_AT_END_OF_LINE_P (it
))
19920 row
->exact_window_width_line_p
= 1;
19921 goto at_end_of_line
;
19923 it
->current_x
= x_before
;
19926 row
->truncated_on_right_p
= 1;
19927 it
->continuation_lines_width
= 0;
19928 reseat_at_next_visible_line_start (it
, 0);
19929 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19930 it
->hpos
= hpos_before
;
19936 bidi_unshelve_cache (wrap_data
, 1);
19938 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19939 at the left window margin. */
19940 if (it
->first_visible_x
19941 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19943 if (!FRAME_WINDOW_P (it
->f
)
19944 || (row
->reversed_p
19945 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19946 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19947 insert_left_trunc_glyphs (it
);
19948 row
->truncated_on_left_p
= 1;
19951 /* Remember the position at which this line ends.
19953 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19954 cannot be before the call to find_row_edges below, since that is
19955 where these positions are determined. */
19956 row
->end
= it
->current
;
19959 row
->minpos
= row
->start
.pos
;
19960 row
->maxpos
= row
->end
.pos
;
19964 /* ROW->minpos and ROW->maxpos must be the smallest and
19965 `1 + the largest' buffer positions in ROW. But if ROW was
19966 bidi-reordered, these two positions can be anywhere in the
19967 row, so we must determine them now. */
19968 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19971 /* If the start of this line is the overlay arrow-position, then
19972 mark this glyph row as the one containing the overlay arrow.
19973 This is clearly a mess with variable size fonts. It would be
19974 better to let it be displayed like cursors under X. */
19975 if ((row
->displays_text_p
|| !overlay_arrow_seen
)
19976 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19977 !NILP (overlay_arrow_string
)))
19979 /* Overlay arrow in window redisplay is a fringe bitmap. */
19980 if (STRINGP (overlay_arrow_string
))
19982 struct glyph_row
*arrow_row
19983 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19984 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19985 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19986 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19987 struct glyph
*p2
, *end
;
19989 /* Copy the arrow glyphs. */
19990 while (glyph
< arrow_end
)
19993 /* Throw away padding glyphs. */
19995 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19996 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
20002 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
20007 eassert (INTEGERP (overlay_arrow_string
));
20008 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
20010 overlay_arrow_seen
= 1;
20013 /* Highlight trailing whitespace. */
20014 if (!NILP (Vshow_trailing_whitespace
))
20015 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
20017 /* Compute pixel dimensions of this line. */
20018 compute_line_metrics (it
);
20020 /* Implementation note: No changes in the glyphs of ROW or in their
20021 faces can be done past this point, because compute_line_metrics
20022 computes ROW's hash value and stores it within the glyph_row
20025 /* Record whether this row ends inside an ellipsis. */
20026 row
->ends_in_ellipsis_p
20027 = (it
->method
== GET_FROM_DISPLAY_VECTOR
20028 && it
->ellipsis_p
);
20030 /* Save fringe bitmaps in this row. */
20031 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
20032 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
20033 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
20034 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
20036 it
->left_user_fringe_bitmap
= 0;
20037 it
->left_user_fringe_face_id
= 0;
20038 it
->right_user_fringe_bitmap
= 0;
20039 it
->right_user_fringe_face_id
= 0;
20041 /* Maybe set the cursor. */
20042 cvpos
= it
->w
->cursor
.vpos
;
20044 /* In bidi-reordered rows, keep checking for proper cursor
20045 position even if one has been found already, because buffer
20046 positions in such rows change non-linearly with ROW->VPOS,
20047 when a line is continued. One exception: when we are at ZV,
20048 display cursor on the first suitable glyph row, since all
20049 the empty rows after that also have their position set to ZV. */
20050 /* FIXME: Revisit this when glyph ``spilling'' in continuation
20051 lines' rows is implemented for bidi-reordered rows. */
20053 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20054 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20055 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20056 && cursor_row_p (row
))
20057 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20059 /* Prepare for the next line. This line starts horizontally at (X
20060 HPOS) = (0 0). Vertical positions are incremented. As a
20061 convenience for the caller, IT->glyph_row is set to the next
20063 it
->current_x
= it
->hpos
= 0;
20064 it
->current_y
+= row
->height
;
20065 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20068 /* The next row should by default use the same value of the
20069 reversed_p flag as this one. set_iterator_to_next decides when
20070 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20071 the flag accordingly. */
20072 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20073 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20074 it
->start
= row
->end
;
20075 return row
->displays_text_p
;
20077 #undef RECORD_MAX_MIN_POS
20080 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20081 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20082 doc
: /* Return paragraph direction at point in BUFFER.
20083 Value is either `left-to-right' or `right-to-left'.
20084 If BUFFER is omitted or nil, it defaults to the current buffer.
20086 Paragraph direction determines how the text in the paragraph is displayed.
20087 In left-to-right paragraphs, text begins at the left margin of the window
20088 and the reading direction is generally left to right. In right-to-left
20089 paragraphs, text begins at the right margin and is read from right to left.
20091 See also `bidi-paragraph-direction'. */)
20092 (Lisp_Object buffer
)
20094 struct buffer
*buf
= current_buffer
;
20095 struct buffer
*old
= buf
;
20097 if (! NILP (buffer
))
20099 CHECK_BUFFER (buffer
);
20100 buf
= XBUFFER (buffer
);
20103 if (NILP (BVAR (buf
, bidi_display_reordering
))
20104 || NILP (BVAR (buf
, enable_multibyte_characters
))
20105 /* When we are loading loadup.el, the character property tables
20106 needed for bidi iteration are not yet available. */
20107 || !NILP (Vpurify_flag
))
20108 return Qleft_to_right
;
20109 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20110 return BVAR (buf
, bidi_paragraph_direction
);
20113 /* Determine the direction from buffer text. We could try to
20114 use current_matrix if it is up to date, but this seems fast
20115 enough as it is. */
20116 struct bidi_it itb
;
20117 ptrdiff_t pos
= BUF_PT (buf
);
20118 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20120 void *itb_data
= bidi_shelve_cache ();
20122 set_buffer_temp (buf
);
20123 /* bidi_paragraph_init finds the base direction of the paragraph
20124 by searching forward from paragraph start. We need the base
20125 direction of the current or _previous_ paragraph, so we need
20126 to make sure we are within that paragraph. To that end, find
20127 the previous non-empty line. */
20128 if (pos
>= ZV
&& pos
> BEGV
)
20131 bytepos
= CHAR_TO_BYTE (pos
);
20133 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20134 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20136 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20137 || c
== ' ' || c
== '\t' || c
== '\f')
20139 if (bytepos
<= BEGV_BYTE
)
20144 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20147 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20148 itb
.paragraph_dir
= NEUTRAL_DIR
;
20149 itb
.string
.s
= NULL
;
20150 itb
.string
.lstring
= Qnil
;
20151 itb
.string
.bufpos
= 0;
20152 itb
.string
.unibyte
= 0;
20153 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20154 bidi_unshelve_cache (itb_data
, 0);
20155 set_buffer_temp (old
);
20156 switch (itb
.paragraph_dir
)
20159 return Qleft_to_right
;
20162 return Qright_to_left
;
20172 /***********************************************************************
20174 ***********************************************************************/
20176 /* Redisplay the menu bar in the frame for window W.
20178 The menu bar of X frames that don't have X toolkit support is
20179 displayed in a special window W->frame->menu_bar_window.
20181 The menu bar of terminal frames is treated specially as far as
20182 glyph matrices are concerned. Menu bar lines are not part of
20183 windows, so the update is done directly on the frame matrix rows
20184 for the menu bar. */
20187 display_menu_bar (struct window
*w
)
20189 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20194 /* Don't do all this for graphical frames. */
20196 if (FRAME_W32_P (f
))
20199 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20205 if (FRAME_NS_P (f
))
20207 #endif /* HAVE_NS */
20209 #ifdef USE_X_TOOLKIT
20210 eassert (!FRAME_WINDOW_P (f
));
20211 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20212 it
.first_visible_x
= 0;
20213 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20214 #else /* not USE_X_TOOLKIT */
20215 if (FRAME_WINDOW_P (f
))
20217 /* Menu bar lines are displayed in the desired matrix of the
20218 dummy window menu_bar_window. */
20219 struct window
*menu_w
;
20220 eassert (WINDOWP (f
->menu_bar_window
));
20221 menu_w
= XWINDOW (f
->menu_bar_window
);
20222 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20224 it
.first_visible_x
= 0;
20225 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20229 /* This is a TTY frame, i.e. character hpos/vpos are used as
20231 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20233 it
.first_visible_x
= 0;
20234 it
.last_visible_x
= FRAME_COLS (f
);
20236 #endif /* not USE_X_TOOLKIT */
20238 /* FIXME: This should be controlled by a user option. See the
20239 comments in redisplay_tool_bar and display_mode_line about
20241 it
.paragraph_embedding
= L2R
;
20243 /* Clear all rows of the menu bar. */
20244 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20246 struct glyph_row
*row
= it
.glyph_row
+ i
;
20247 clear_glyph_row (row
);
20248 row
->enabled_p
= 1;
20249 row
->full_width_p
= 1;
20252 /* Display all items of the menu bar. */
20253 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20254 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20256 Lisp_Object string
;
20258 /* Stop at nil string. */
20259 string
= AREF (items
, i
+ 1);
20263 /* Remember where item was displayed. */
20264 ASET (items
, i
+ 3, make_number (it
.hpos
));
20266 /* Display the item, pad with one space. */
20267 if (it
.current_x
< it
.last_visible_x
)
20268 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20269 SCHARS (string
) + 1, 0, 0, -1);
20272 /* Fill out the line with spaces. */
20273 if (it
.current_x
< it
.last_visible_x
)
20274 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20276 /* Compute the total height of the lines. */
20277 compute_line_metrics (&it
);
20282 /***********************************************************************
20284 ***********************************************************************/
20286 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20287 FORCE is non-zero, redisplay mode lines unconditionally.
20288 Otherwise, redisplay only mode lines that are garbaged. Value is
20289 the number of windows whose mode lines were redisplayed. */
20292 redisplay_mode_lines (Lisp_Object window
, int force
)
20296 while (!NILP (window
))
20298 struct window
*w
= XWINDOW (window
);
20300 if (WINDOWP (w
->hchild
))
20301 nwindows
+= redisplay_mode_lines (w
->hchild
, force
);
20302 else if (WINDOWP (w
->vchild
))
20303 nwindows
+= redisplay_mode_lines (w
->vchild
, force
);
20305 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20306 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20308 struct text_pos lpoint
;
20309 struct buffer
*old
= current_buffer
;
20311 /* Set the window's buffer for the mode line display. */
20312 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20313 set_buffer_internal_1 (XBUFFER (w
->buffer
));
20315 /* Point refers normally to the selected window. For any
20316 other window, set up appropriate value. */
20317 if (!EQ (window
, selected_window
))
20319 struct text_pos pt
;
20321 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20322 if (CHARPOS (pt
) < BEGV
)
20323 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20324 else if (CHARPOS (pt
) > (ZV
- 1))
20325 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20327 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20330 /* Display mode lines. */
20331 clear_glyph_matrix (w
->desired_matrix
);
20332 if (display_mode_lines (w
))
20335 w
->must_be_updated_p
= 1;
20338 /* Restore old settings. */
20339 set_buffer_internal_1 (old
);
20340 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20350 /* Display the mode and/or header line of window W. Value is the
20351 sum number of mode lines and header lines displayed. */
20354 display_mode_lines (struct window
*w
)
20356 Lisp_Object old_selected_window
, old_selected_frame
;
20359 old_selected_frame
= selected_frame
;
20360 selected_frame
= w
->frame
;
20361 old_selected_window
= selected_window
;
20362 XSETWINDOW (selected_window
, w
);
20364 /* These will be set while the mode line specs are processed. */
20365 line_number_displayed
= 0;
20366 wset_column_number_displayed (w
, Qnil
);
20368 if (WINDOW_WANTS_MODELINE_P (w
))
20370 struct window
*sel_w
= XWINDOW (old_selected_window
);
20372 /* Select mode line face based on the real selected window. */
20373 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20374 BVAR (current_buffer
, mode_line_format
));
20378 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20380 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20381 BVAR (current_buffer
, header_line_format
));
20385 selected_frame
= old_selected_frame
;
20386 selected_window
= old_selected_window
;
20391 /* Display mode or header line of window W. FACE_ID specifies which
20392 line to display; it is either MODE_LINE_FACE_ID or
20393 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20394 display. Value is the pixel height of the mode/header line
20398 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20402 ptrdiff_t count
= SPECPDL_INDEX ();
20404 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20405 /* Don't extend on a previously drawn mode-line.
20406 This may happen if called from pos_visible_p. */
20407 it
.glyph_row
->enabled_p
= 0;
20408 prepare_desired_row (it
.glyph_row
);
20410 it
.glyph_row
->mode_line_p
= 1;
20412 /* FIXME: This should be controlled by a user option. But
20413 supporting such an option is not trivial, since the mode line is
20414 made up of many separate strings. */
20415 it
.paragraph_embedding
= L2R
;
20417 record_unwind_protect (unwind_format_mode_line
,
20418 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20420 mode_line_target
= MODE_LINE_DISPLAY
;
20422 /* Temporarily make frame's keyboard the current kboard so that
20423 kboard-local variables in the mode_line_format will get the right
20425 push_kboard (FRAME_KBOARD (it
.f
));
20426 record_unwind_save_match_data ();
20427 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20430 unbind_to (count
, Qnil
);
20432 /* Fill up with spaces. */
20433 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20435 compute_line_metrics (&it
);
20436 it
.glyph_row
->full_width_p
= 1;
20437 it
.glyph_row
->continued_p
= 0;
20438 it
.glyph_row
->truncated_on_left_p
= 0;
20439 it
.glyph_row
->truncated_on_right_p
= 0;
20441 /* Make a 3D mode-line have a shadow at its right end. */
20442 face
= FACE_FROM_ID (it
.f
, face_id
);
20443 extend_face_to_end_of_line (&it
);
20444 if (face
->box
!= FACE_NO_BOX
)
20446 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20447 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20448 last
->right_box_line_p
= 1;
20451 return it
.glyph_row
->height
;
20454 /* Move element ELT in LIST to the front of LIST.
20455 Return the updated list. */
20458 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20460 register Lisp_Object tail
, prev
;
20461 register Lisp_Object tem
;
20465 while (CONSP (tail
))
20471 /* Splice out the link TAIL. */
20473 list
= XCDR (tail
);
20475 Fsetcdr (prev
, XCDR (tail
));
20477 /* Now make it the first. */
20478 Fsetcdr (tail
, list
);
20483 tail
= XCDR (tail
);
20487 /* Not found--return unchanged LIST. */
20491 /* Contribute ELT to the mode line for window IT->w. How it
20492 translates into text depends on its data type.
20494 IT describes the display environment in which we display, as usual.
20496 DEPTH is the depth in recursion. It is used to prevent
20497 infinite recursion here.
20499 FIELD_WIDTH is the number of characters the display of ELT should
20500 occupy in the mode line, and PRECISION is the maximum number of
20501 characters to display from ELT's representation. See
20502 display_string for details.
20504 Returns the hpos of the end of the text generated by ELT.
20506 PROPS is a property list to add to any string we encounter.
20508 If RISKY is nonzero, remove (disregard) any properties in any string
20509 we encounter, and ignore :eval and :propertize.
20511 The global variable `mode_line_target' determines whether the
20512 output is passed to `store_mode_line_noprop',
20513 `store_mode_line_string', or `display_string'. */
20516 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20517 Lisp_Object elt
, Lisp_Object props
, int risky
)
20519 int n
= 0, field
, prec
;
20524 elt
= build_string ("*too-deep*");
20528 switch (XTYPE (elt
))
20532 /* A string: output it and check for %-constructs within it. */
20534 ptrdiff_t offset
= 0;
20536 if (SCHARS (elt
) > 0
20537 && (!NILP (props
) || risky
))
20539 Lisp_Object oprops
, aelt
;
20540 oprops
= Ftext_properties_at (make_number (0), elt
);
20542 /* If the starting string's properties are not what
20543 we want, translate the string. Also, if the string
20544 is risky, do that anyway. */
20546 if (NILP (Fequal (props
, oprops
)) || risky
)
20548 /* If the starting string has properties,
20549 merge the specified ones onto the existing ones. */
20550 if (! NILP (oprops
) && !risky
)
20554 oprops
= Fcopy_sequence (oprops
);
20556 while (CONSP (tem
))
20558 oprops
= Fplist_put (oprops
, XCAR (tem
),
20559 XCAR (XCDR (tem
)));
20560 tem
= XCDR (XCDR (tem
));
20565 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20566 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20568 /* AELT is what we want. Move it to the front
20569 without consing. */
20571 mode_line_proptrans_alist
20572 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20578 /* If AELT has the wrong props, it is useless.
20579 so get rid of it. */
20581 mode_line_proptrans_alist
20582 = Fdelq (aelt
, mode_line_proptrans_alist
);
20584 elt
= Fcopy_sequence (elt
);
20585 Fset_text_properties (make_number (0), Flength (elt
),
20587 /* Add this item to mode_line_proptrans_alist. */
20588 mode_line_proptrans_alist
20589 = Fcons (Fcons (elt
, props
),
20590 mode_line_proptrans_alist
);
20591 /* Truncate mode_line_proptrans_alist
20592 to at most 50 elements. */
20593 tem
= Fnthcdr (make_number (50),
20594 mode_line_proptrans_alist
);
20596 XSETCDR (tem
, Qnil
);
20605 prec
= precision
- n
;
20606 switch (mode_line_target
)
20608 case MODE_LINE_NOPROP
:
20609 case MODE_LINE_TITLE
:
20610 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20612 case MODE_LINE_STRING
:
20613 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20615 case MODE_LINE_DISPLAY
:
20616 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20617 0, prec
, 0, STRING_MULTIBYTE (elt
));
20624 /* Handle the non-literal case. */
20626 while ((precision
<= 0 || n
< precision
)
20627 && SREF (elt
, offset
) != 0
20628 && (mode_line_target
!= MODE_LINE_DISPLAY
20629 || it
->current_x
< it
->last_visible_x
))
20631 ptrdiff_t last_offset
= offset
;
20633 /* Advance to end of string or next format specifier. */
20634 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20637 if (offset
- 1 != last_offset
)
20639 ptrdiff_t nchars
, nbytes
;
20641 /* Output to end of string or up to '%'. Field width
20642 is length of string. Don't output more than
20643 PRECISION allows us. */
20646 prec
= c_string_width (SDATA (elt
) + last_offset
,
20647 offset
- last_offset
, precision
- n
,
20650 switch (mode_line_target
)
20652 case MODE_LINE_NOPROP
:
20653 case MODE_LINE_TITLE
:
20654 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20656 case MODE_LINE_STRING
:
20658 ptrdiff_t bytepos
= last_offset
;
20659 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20660 ptrdiff_t endpos
= (precision
<= 0
20661 ? string_byte_to_char (elt
, offset
)
20662 : charpos
+ nchars
);
20664 n
+= store_mode_line_string (NULL
,
20665 Fsubstring (elt
, make_number (charpos
),
20666 make_number (endpos
)),
20670 case MODE_LINE_DISPLAY
:
20672 ptrdiff_t bytepos
= last_offset
;
20673 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20675 if (precision
<= 0)
20676 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20677 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20679 STRING_MULTIBYTE (elt
));
20684 else /* c == '%' */
20686 ptrdiff_t percent_position
= offset
;
20688 /* Get the specified minimum width. Zero means
20691 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20692 field
= field
* 10 + c
- '0';
20694 /* Don't pad beyond the total padding allowed. */
20695 if (field_width
- n
> 0 && field
> field_width
- n
)
20696 field
= field_width
- n
;
20698 /* Note that either PRECISION <= 0 or N < PRECISION. */
20699 prec
= precision
- n
;
20702 n
+= display_mode_element (it
, depth
, field
, prec
,
20703 Vglobal_mode_string
, props
,
20708 ptrdiff_t bytepos
, charpos
;
20710 Lisp_Object string
;
20712 bytepos
= percent_position
;
20713 charpos
= (STRING_MULTIBYTE (elt
)
20714 ? string_byte_to_char (elt
, bytepos
)
20716 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
20717 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
20719 switch (mode_line_target
)
20721 case MODE_LINE_NOPROP
:
20722 case MODE_LINE_TITLE
:
20723 n
+= store_mode_line_noprop (spec
, field
, prec
);
20725 case MODE_LINE_STRING
:
20727 Lisp_Object tem
= build_string (spec
);
20728 props
= Ftext_properties_at (make_number (charpos
), elt
);
20729 /* Should only keep face property in props */
20730 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
20733 case MODE_LINE_DISPLAY
:
20735 int nglyphs_before
, nwritten
;
20737 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
20738 nwritten
= display_string (spec
, string
, elt
,
20743 /* Assign to the glyphs written above the
20744 string where the `%x' came from, position
20748 struct glyph
*glyph
20749 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
20753 for (i
= 0; i
< nwritten
; ++i
)
20755 glyph
[i
].object
= elt
;
20756 glyph
[i
].charpos
= charpos
;
20773 /* A symbol: process the value of the symbol recursively
20774 as if it appeared here directly. Avoid error if symbol void.
20775 Special case: if value of symbol is a string, output the string
20778 register Lisp_Object tem
;
20780 /* If the variable is not marked as risky to set
20781 then its contents are risky to use. */
20782 if (NILP (Fget (elt
, Qrisky_local_variable
)))
20785 tem
= Fboundp (elt
);
20788 tem
= Fsymbol_value (elt
);
20789 /* If value is a string, output that string literally:
20790 don't check for % within it. */
20794 if (!EQ (tem
, elt
))
20796 /* Give up right away for nil or t. */
20806 register Lisp_Object car
, tem
;
20808 /* A cons cell: five distinct cases.
20809 If first element is :eval or :propertize, do something special.
20810 If first element is a string or a cons, process all the elements
20811 and effectively concatenate them.
20812 If first element is a negative number, truncate displaying cdr to
20813 at most that many characters. If positive, pad (with spaces)
20814 to at least that many characters.
20815 If first element is a symbol, process the cadr or caddr recursively
20816 according to whether the symbol's value is non-nil or nil. */
20818 if (EQ (car
, QCeval
))
20820 /* An element of the form (:eval FORM) means evaluate FORM
20821 and use the result as mode line elements. */
20826 if (CONSP (XCDR (elt
)))
20829 spec
= safe_eval (XCAR (XCDR (elt
)));
20830 n
+= display_mode_element (it
, depth
, field_width
- n
,
20831 precision
- n
, spec
, props
,
20835 else if (EQ (car
, QCpropertize
))
20837 /* An element of the form (:propertize ELT PROPS...)
20838 means display ELT but applying properties PROPS. */
20843 if (CONSP (XCDR (elt
)))
20844 n
+= display_mode_element (it
, depth
, field_width
- n
,
20845 precision
- n
, XCAR (XCDR (elt
)),
20846 XCDR (XCDR (elt
)), risky
);
20848 else if (SYMBOLP (car
))
20850 tem
= Fboundp (car
);
20854 /* elt is now the cdr, and we know it is a cons cell.
20855 Use its car if CAR has a non-nil value. */
20858 tem
= Fsymbol_value (car
);
20865 /* Symbol's value is nil (or symbol is unbound)
20866 Get the cddr of the original list
20867 and if possible find the caddr and use that. */
20871 else if (!CONSP (elt
))
20876 else if (INTEGERP (car
))
20878 register int lim
= XINT (car
);
20882 /* Negative int means reduce maximum width. */
20883 if (precision
<= 0)
20886 precision
= min (precision
, -lim
);
20890 /* Padding specified. Don't let it be more than
20891 current maximum. */
20893 lim
= min (precision
, lim
);
20895 /* If that's more padding than already wanted, queue it.
20896 But don't reduce padding already specified even if
20897 that is beyond the current truncation point. */
20898 field_width
= max (lim
, field_width
);
20902 else if (STRINGP (car
) || CONSP (car
))
20904 Lisp_Object halftail
= elt
;
20908 && (precision
<= 0 || n
< precision
))
20910 n
+= display_mode_element (it
, depth
,
20911 /* Do padding only after the last
20912 element in the list. */
20913 (! CONSP (XCDR (elt
))
20916 precision
- n
, XCAR (elt
),
20920 if ((len
& 1) == 0)
20921 halftail
= XCDR (halftail
);
20922 /* Check for cycle. */
20923 if (EQ (halftail
, elt
))
20932 elt
= build_string ("*invalid*");
20936 /* Pad to FIELD_WIDTH. */
20937 if (field_width
> 0 && n
< field_width
)
20939 switch (mode_line_target
)
20941 case MODE_LINE_NOPROP
:
20942 case MODE_LINE_TITLE
:
20943 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
20945 case MODE_LINE_STRING
:
20946 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
20948 case MODE_LINE_DISPLAY
:
20949 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
20958 /* Store a mode-line string element in mode_line_string_list.
20960 If STRING is non-null, display that C string. Otherwise, the Lisp
20961 string LISP_STRING is displayed.
20963 FIELD_WIDTH is the minimum number of output glyphs to produce.
20964 If STRING has fewer characters than FIELD_WIDTH, pad to the right
20965 with spaces. FIELD_WIDTH <= 0 means don't pad.
20967 PRECISION is the maximum number of characters to output from
20968 STRING. PRECISION <= 0 means don't truncate the string.
20970 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
20971 properties to the string.
20973 PROPS are the properties to add to the string.
20974 The mode_line_string_face face property is always added to the string.
20978 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
20979 int field_width
, int precision
, Lisp_Object props
)
20984 if (string
!= NULL
)
20986 len
= strlen (string
);
20987 if (precision
> 0 && len
> precision
)
20989 lisp_string
= make_string (string
, len
);
20991 props
= mode_line_string_face_prop
;
20992 else if (!NILP (mode_line_string_face
))
20994 Lisp_Object face
= Fplist_get (props
, Qface
);
20995 props
= Fcopy_sequence (props
);
20997 face
= mode_line_string_face
;
20999 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
21000 props
= Fplist_put (props
, Qface
, face
);
21002 Fadd_text_properties (make_number (0), make_number (len
),
21003 props
, lisp_string
);
21007 len
= XFASTINT (Flength (lisp_string
));
21008 if (precision
> 0 && len
> precision
)
21011 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21014 if (!NILP (mode_line_string_face
))
21018 props
= Ftext_properties_at (make_number (0), lisp_string
);
21019 face
= Fplist_get (props
, Qface
);
21021 face
= mode_line_string_face
;
21023 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
21024 props
= Fcons (Qface
, Fcons (face
, Qnil
));
21026 lisp_string
= Fcopy_sequence (lisp_string
);
21029 Fadd_text_properties (make_number (0), make_number (len
),
21030 props
, lisp_string
);
21035 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21039 if (field_width
> len
)
21041 field_width
-= len
;
21042 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21044 Fadd_text_properties (make_number (0), make_number (field_width
),
21045 props
, lisp_string
);
21046 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21054 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21056 doc
: /* Format a string out of a mode line format specification.
21057 First arg FORMAT specifies the mode line format (see `mode-line-format'
21058 for details) to use.
21060 By default, the format is evaluated for the currently selected window.
21062 Optional second arg FACE specifies the face property to put on all
21063 characters for which no face is specified. The value nil means the
21064 default face. The value t means whatever face the window's mode line
21065 currently uses (either `mode-line' or `mode-line-inactive',
21066 depending on whether the window is the selected window or not).
21067 An integer value means the value string has no text
21070 Optional third and fourth args WINDOW and BUFFER specify the window
21071 and buffer to use as the context for the formatting (defaults
21072 are the selected window and the WINDOW's buffer). */)
21073 (Lisp_Object format
, Lisp_Object face
,
21074 Lisp_Object window
, Lisp_Object buffer
)
21079 struct buffer
*old_buffer
= NULL
;
21081 int no_props
= INTEGERP (face
);
21082 ptrdiff_t count
= SPECPDL_INDEX ();
21084 int string_start
= 0;
21086 w
= decode_any_window (window
);
21087 XSETWINDOW (window
, w
);
21090 buffer
= w
->buffer
;
21091 CHECK_BUFFER (buffer
);
21093 /* Make formatting the modeline a non-op when noninteractive, otherwise
21094 there will be problems later caused by a partially initialized frame. */
21095 if (NILP (format
) || noninteractive
)
21096 return empty_unibyte_string
;
21101 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21102 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21103 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21104 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21105 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21106 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21107 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21110 old_buffer
= current_buffer
;
21112 /* Save things including mode_line_proptrans_alist,
21113 and set that to nil so that we don't alter the outer value. */
21114 record_unwind_protect (unwind_format_mode_line
,
21115 format_mode_line_unwind_data
21116 (XFRAME (WINDOW_FRAME (w
)),
21117 old_buffer
, selected_window
, 1));
21118 mode_line_proptrans_alist
= Qnil
;
21120 Fselect_window (window
, Qt
);
21121 set_buffer_internal_1 (XBUFFER (buffer
));
21123 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21127 mode_line_target
= MODE_LINE_NOPROP
;
21128 mode_line_string_face_prop
= Qnil
;
21129 mode_line_string_list
= Qnil
;
21130 string_start
= MODE_LINE_NOPROP_LEN (0);
21134 mode_line_target
= MODE_LINE_STRING
;
21135 mode_line_string_list
= Qnil
;
21136 mode_line_string_face
= face
;
21137 mode_line_string_face_prop
21138 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
21141 push_kboard (FRAME_KBOARD (it
.f
));
21142 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21147 len
= MODE_LINE_NOPROP_LEN (string_start
);
21148 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21152 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21153 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21154 empty_unibyte_string
);
21157 unbind_to (count
, Qnil
);
21161 /* Write a null-terminated, right justified decimal representation of
21162 the positive integer D to BUF using a minimal field width WIDTH. */
21165 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21167 register char *p
= buf
;
21175 *p
++ = d
% 10 + '0';
21180 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21191 /* Write a null-terminated, right justified decimal and "human
21192 readable" representation of the nonnegative integer D to BUF using
21193 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21195 static const char power_letter
[] =
21209 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21211 /* We aim to represent the nonnegative integer D as
21212 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21213 ptrdiff_t quotient
= d
;
21215 /* -1 means: do not use TENTHS. */
21219 /* Length of QUOTIENT.TENTHS as a string. */
21225 if (1000 <= quotient
)
21227 /* Scale to the appropriate EXPONENT. */
21230 remainder
= quotient
% 1000;
21234 while (1000 <= quotient
);
21236 /* Round to nearest and decide whether to use TENTHS or not. */
21239 tenths
= remainder
/ 100;
21240 if (50 <= remainder
% 100)
21247 if (quotient
== 10)
21255 if (500 <= remainder
)
21257 if (quotient
< 999)
21268 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21269 if (tenths
== -1 && quotient
<= 99)
21276 p
= psuffix
= buf
+ max (width
, length
);
21278 /* Print EXPONENT. */
21279 *psuffix
++ = power_letter
[exponent
];
21282 /* Print TENTHS. */
21285 *--p
= '0' + tenths
;
21289 /* Print QUOTIENT. */
21292 int digit
= quotient
% 10;
21293 *--p
= '0' + digit
;
21295 while ((quotient
/= 10) != 0);
21297 /* Print leading spaces. */
21302 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21303 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21304 type of CODING_SYSTEM. Return updated pointer into BUF. */
21306 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21309 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21312 int multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21313 const unsigned char *eol_str
;
21315 /* The EOL conversion we are using. */
21316 Lisp_Object eoltype
;
21318 val
= CODING_SYSTEM_SPEC (coding_system
);
21321 if (!VECTORP (val
)) /* Not yet decided. */
21323 *buf
++ = multibyte
? '-' : ' ';
21325 eoltype
= eol_mnemonic_undecided
;
21326 /* Don't mention EOL conversion if it isn't decided. */
21331 Lisp_Object eolvalue
;
21333 attrs
= AREF (val
, 0);
21334 eolvalue
= AREF (val
, 2);
21337 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21342 /* The EOL conversion that is normal on this system. */
21344 if (NILP (eolvalue
)) /* Not yet decided. */
21345 eoltype
= eol_mnemonic_undecided
;
21346 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21347 eoltype
= eol_mnemonic_undecided
;
21348 else /* eolvalue is Qunix, Qdos, or Qmac. */
21349 eoltype
= (EQ (eolvalue
, Qunix
)
21350 ? eol_mnemonic_unix
21351 : (EQ (eolvalue
, Qdos
) == 1
21352 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21358 /* Mention the EOL conversion if it is not the usual one. */
21359 if (STRINGP (eoltype
))
21361 eol_str
= SDATA (eoltype
);
21362 eol_str_len
= SBYTES (eoltype
);
21364 else if (CHARACTERP (eoltype
))
21366 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21367 int c
= XFASTINT (eoltype
);
21368 eol_str_len
= CHAR_STRING (c
, tmp
);
21373 eol_str
= invalid_eol_type
;
21374 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21376 memcpy (buf
, eol_str
, eol_str_len
);
21377 buf
+= eol_str_len
;
21383 /* Return a string for the output of a mode line %-spec for window W,
21384 generated by character C. FIELD_WIDTH > 0 means pad the string
21385 returned with spaces to that value. Return a Lisp string in
21386 *STRING if the resulting string is taken from that Lisp string.
21388 Note we operate on the current buffer for most purposes,
21389 the exception being w->base_line_pos. */
21391 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21393 static const char *
21394 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21395 Lisp_Object
*string
)
21398 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21399 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21400 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21401 produce strings from numerical values, so limit preposterously
21402 large values of FIELD_WIDTH to avoid overrunning the buffer's
21403 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21404 bytes plus the terminating null. */
21405 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21406 struct buffer
*b
= current_buffer
;
21414 if (!NILP (BVAR (b
, read_only
)))
21416 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21421 /* This differs from %* only for a modified read-only buffer. */
21422 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21424 if (!NILP (BVAR (b
, read_only
)))
21429 /* This differs from %* in ignoring read-only-ness. */
21430 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21442 if (command_loop_level
> 5)
21444 p
= decode_mode_spec_buf
;
21445 for (i
= 0; i
< command_loop_level
; i
++)
21448 return decode_mode_spec_buf
;
21456 if (command_loop_level
> 5)
21458 p
= decode_mode_spec_buf
;
21459 for (i
= 0; i
< command_loop_level
; i
++)
21462 return decode_mode_spec_buf
;
21469 /* Let lots_of_dashes be a string of infinite length. */
21470 if (mode_line_target
== MODE_LINE_NOPROP
21471 || mode_line_target
== MODE_LINE_STRING
)
21473 if (field_width
<= 0
21474 || field_width
> sizeof (lots_of_dashes
))
21476 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21477 decode_mode_spec_buf
[i
] = '-';
21478 decode_mode_spec_buf
[i
] = '\0';
21479 return decode_mode_spec_buf
;
21482 return lots_of_dashes
;
21486 obj
= BVAR (b
, name
);
21490 /* %c and %l are ignored in `frame-title-format'.
21491 (In redisplay_internal, the frame title is drawn _before_ the
21492 windows are updated, so the stuff which depends on actual
21493 window contents (such as %l) may fail to render properly, or
21494 even crash emacs.) */
21495 if (mode_line_target
== MODE_LINE_TITLE
)
21499 ptrdiff_t col
= current_column ();
21500 wset_column_number_displayed (w
, make_number (col
));
21501 pint2str (decode_mode_spec_buf
, width
, col
);
21502 return decode_mode_spec_buf
;
21506 #ifndef SYSTEM_MALLOC
21508 if (NILP (Vmemory_full
))
21511 return "!MEM FULL! ";
21518 /* %F displays the frame name. */
21519 if (!NILP (f
->title
))
21520 return SSDATA (f
->title
);
21521 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21522 return SSDATA (f
->name
);
21526 obj
= BVAR (b
, filename
);
21531 ptrdiff_t size
= ZV
- BEGV
;
21532 pint2str (decode_mode_spec_buf
, width
, size
);
21533 return decode_mode_spec_buf
;
21538 ptrdiff_t size
= ZV
- BEGV
;
21539 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21540 return decode_mode_spec_buf
;
21545 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21546 ptrdiff_t topline
, nlines
, height
;
21549 /* %c and %l are ignored in `frame-title-format'. */
21550 if (mode_line_target
== MODE_LINE_TITLE
)
21553 startpos
= marker_position (w
->start
);
21554 startpos_byte
= marker_byte_position (w
->start
);
21555 height
= WINDOW_TOTAL_LINES (w
);
21557 /* If we decided that this buffer isn't suitable for line numbers,
21558 don't forget that too fast. */
21559 if (EQ (w
->base_line_pos
, w
->buffer
))
21561 /* But do forget it, if the window shows a different buffer now. */
21562 else if (BUFFERP (w
->base_line_pos
))
21563 wset_base_line_pos (w
, Qnil
);
21565 /* If the buffer is very big, don't waste time. */
21566 if (INTEGERP (Vline_number_display_limit
)
21567 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21569 wset_base_line_pos (w
, Qnil
);
21570 wset_base_line_number (w
, Qnil
);
21574 if (INTEGERP (w
->base_line_number
)
21575 && INTEGERP (w
->base_line_pos
)
21576 && XFASTINT (w
->base_line_pos
) <= startpos
)
21578 line
= XFASTINT (w
->base_line_number
);
21579 linepos
= XFASTINT (w
->base_line_pos
);
21580 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21585 linepos
= BUF_BEGV (b
);
21586 linepos_byte
= BUF_BEGV_BYTE (b
);
21589 /* Count lines from base line to window start position. */
21590 nlines
= display_count_lines (linepos_byte
,
21594 topline
= nlines
+ line
;
21596 /* Determine a new base line, if the old one is too close
21597 or too far away, or if we did not have one.
21598 "Too close" means it's plausible a scroll-down would
21599 go back past it. */
21600 if (startpos
== BUF_BEGV (b
))
21602 wset_base_line_number (w
, make_number (topline
));
21603 wset_base_line_pos (w
, make_number (BUF_BEGV (b
)));
21605 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21606 || linepos
== BUF_BEGV (b
))
21608 ptrdiff_t limit
= BUF_BEGV (b
);
21609 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21610 ptrdiff_t position
;
21611 ptrdiff_t distance
=
21612 (height
* 2 + 30) * line_number_display_limit_width
;
21614 if (startpos
- distance
> limit
)
21616 limit
= startpos
- distance
;
21617 limit_byte
= CHAR_TO_BYTE (limit
);
21620 nlines
= display_count_lines (startpos_byte
,
21622 - (height
* 2 + 30),
21624 /* If we couldn't find the lines we wanted within
21625 line_number_display_limit_width chars per line,
21626 give up on line numbers for this window. */
21627 if (position
== limit_byte
&& limit
== startpos
- distance
)
21629 wset_base_line_pos (w
, w
->buffer
);
21630 wset_base_line_number (w
, Qnil
);
21634 wset_base_line_number (w
, make_number (topline
- nlines
));
21635 wset_base_line_pos (w
, make_number (BYTE_TO_CHAR (position
)));
21638 /* Now count lines from the start pos to point. */
21639 nlines
= display_count_lines (startpos_byte
,
21640 PT_BYTE
, PT
, &junk
);
21642 /* Record that we did display the line number. */
21643 line_number_displayed
= 1;
21645 /* Make the string to show. */
21646 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21647 return decode_mode_spec_buf
;
21650 char* p
= decode_mode_spec_buf
;
21651 int pad
= width
- 2;
21657 return decode_mode_spec_buf
;
21663 obj
= BVAR (b
, mode_name
);
21667 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21673 ptrdiff_t pos
= marker_position (w
->start
);
21674 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21676 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
21678 if (pos
<= BUF_BEGV (b
))
21683 else if (pos
<= BUF_BEGV (b
))
21687 if (total
> 1000000)
21688 /* Do it differently for a large value, to avoid overflow. */
21689 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21691 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21692 /* We can't normally display a 3-digit number,
21693 so get us a 2-digit number that is close. */
21696 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21697 return decode_mode_spec_buf
;
21701 /* Display percentage of size above the bottom of the screen. */
21704 ptrdiff_t toppos
= marker_position (w
->start
);
21705 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
21706 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21708 if (botpos
>= BUF_ZV (b
))
21710 if (toppos
<= BUF_BEGV (b
))
21717 if (total
> 1000000)
21718 /* Do it differently for a large value, to avoid overflow. */
21719 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21721 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21722 /* We can't normally display a 3-digit number,
21723 so get us a 2-digit number that is close. */
21726 if (toppos
<= BUF_BEGV (b
))
21727 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
21729 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21730 return decode_mode_spec_buf
;
21735 /* status of process */
21736 obj
= Fget_buffer_process (Fcurrent_buffer ());
21738 return "no process";
21740 obj
= Fsymbol_name (Fprocess_status (obj
));
21746 ptrdiff_t count
= inhibit_garbage_collection ();
21747 Lisp_Object val
= call1 (intern ("file-remote-p"),
21748 BVAR (current_buffer
, directory
));
21749 unbind_to (count
, Qnil
);
21757 case 't': /* indicate TEXT or BINARY */
21761 /* coding-system (not including end-of-line format) */
21763 /* coding-system (including end-of-line type) */
21765 int eol_flag
= (c
== 'Z');
21766 char *p
= decode_mode_spec_buf
;
21768 if (! FRAME_WINDOW_P (f
))
21770 /* No need to mention EOL here--the terminal never needs
21771 to do EOL conversion. */
21772 p
= decode_mode_spec_coding (CODING_ID_NAME
21773 (FRAME_KEYBOARD_CODING (f
)->id
),
21775 p
= decode_mode_spec_coding (CODING_ID_NAME
21776 (FRAME_TERMINAL_CODING (f
)->id
),
21779 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
21782 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
21783 #ifdef subprocesses
21784 obj
= Fget_buffer_process (Fcurrent_buffer ());
21785 if (PROCESSP (obj
))
21787 p
= decode_mode_spec_coding
21788 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
21789 p
= decode_mode_spec_coding
21790 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
21792 #endif /* subprocesses */
21795 return decode_mode_spec_buf
;
21802 return SSDATA (obj
);
21809 /* Count up to COUNT lines starting from START_BYTE.
21810 But don't go beyond LIMIT_BYTE.
21811 Return the number of lines thus found (always nonnegative).
21813 Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */
21816 display_count_lines (ptrdiff_t start_byte
,
21817 ptrdiff_t limit_byte
, ptrdiff_t count
,
21818 ptrdiff_t *byte_pos_ptr
)
21820 register unsigned char *cursor
;
21821 unsigned char *base
;
21823 register ptrdiff_t ceiling
;
21824 register unsigned char *ceiling_addr
;
21825 ptrdiff_t orig_count
= count
;
21827 /* If we are not in selective display mode,
21828 check only for newlines. */
21829 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
21830 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
21834 while (start_byte
< limit_byte
)
21836 ceiling
= BUFFER_CEILING_OF (start_byte
);
21837 ceiling
= min (limit_byte
- 1, ceiling
);
21838 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
21839 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
21842 if (selective_display
)
21843 while (*cursor
!= '\n' && *cursor
!= 015 && ++cursor
!= ceiling_addr
)
21846 while (*cursor
!= '\n' && ++cursor
!= ceiling_addr
)
21849 if (cursor
!= ceiling_addr
)
21853 start_byte
+= cursor
- base
+ 1;
21854 *byte_pos_ptr
= start_byte
;
21858 if (++cursor
== ceiling_addr
)
21864 start_byte
+= cursor
- base
;
21869 while (start_byte
> limit_byte
)
21871 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
21872 ceiling
= max (limit_byte
, ceiling
);
21873 ceiling_addr
= BYTE_POS_ADDR (ceiling
) - 1;
21874 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
21877 if (selective_display
)
21878 while (--cursor
!= ceiling_addr
21879 && *cursor
!= '\n' && *cursor
!= 015)
21882 while (--cursor
!= ceiling_addr
&& *cursor
!= '\n')
21885 if (cursor
!= ceiling_addr
)
21889 start_byte
+= cursor
- base
+ 1;
21890 *byte_pos_ptr
= start_byte
;
21891 /* When scanning backwards, we should
21892 not count the newline posterior to which we stop. */
21893 return - orig_count
- 1;
21899 /* Here we add 1 to compensate for the last decrement
21900 of CURSOR, which took it past the valid range. */
21901 start_byte
+= cursor
- base
+ 1;
21905 *byte_pos_ptr
= limit_byte
;
21908 return - orig_count
+ count
;
21909 return orig_count
- count
;
21915 /***********************************************************************
21917 ***********************************************************************/
21919 /* Display a NUL-terminated string, starting with index START.
21921 If STRING is non-null, display that C string. Otherwise, the Lisp
21922 string LISP_STRING is displayed. There's a case that STRING is
21923 non-null and LISP_STRING is not nil. It means STRING is a string
21924 data of LISP_STRING. In that case, we display LISP_STRING while
21925 ignoring its text properties.
21927 If FACE_STRING is not nil, FACE_STRING_POS is a position in
21928 FACE_STRING. Display STRING or LISP_STRING with the face at
21929 FACE_STRING_POS in FACE_STRING:
21931 Display the string in the environment given by IT, but use the
21932 standard display table, temporarily.
21934 FIELD_WIDTH is the minimum number of output glyphs to produce.
21935 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21936 with spaces. If STRING has more characters, more than FIELD_WIDTH
21937 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
21939 PRECISION is the maximum number of characters to output from
21940 STRING. PRECISION < 0 means don't truncate the string.
21942 This is roughly equivalent to printf format specifiers:
21944 FIELD_WIDTH PRECISION PRINTF
21945 ----------------------------------------
21951 MULTIBYTE zero means do not display multibyte chars, > 0 means do
21952 display them, and < 0 means obey the current buffer's value of
21953 enable_multibyte_characters.
21955 Value is the number of columns displayed. */
21958 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
21959 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
21960 int field_width
, int precision
, int max_x
, int multibyte
)
21962 int hpos_at_start
= it
->hpos
;
21963 int saved_face_id
= it
->face_id
;
21964 struct glyph_row
*row
= it
->glyph_row
;
21965 ptrdiff_t it_charpos
;
21967 /* Initialize the iterator IT for iteration over STRING beginning
21968 with index START. */
21969 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
21970 precision
, field_width
, multibyte
);
21971 if (string
&& STRINGP (lisp_string
))
21972 /* LISP_STRING is the one returned by decode_mode_spec. We should
21973 ignore its text properties. */
21974 it
->stop_charpos
= it
->end_charpos
;
21976 /* If displaying STRING, set up the face of the iterator from
21977 FACE_STRING, if that's given. */
21978 if (STRINGP (face_string
))
21984 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
21985 0, it
->region_beg_charpos
,
21986 it
->region_end_charpos
,
21987 &endptr
, it
->base_face_id
, 0);
21988 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
21989 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
21992 /* Set max_x to the maximum allowed X position. Don't let it go
21993 beyond the right edge of the window. */
21995 max_x
= it
->last_visible_x
;
21997 max_x
= min (max_x
, it
->last_visible_x
);
21999 /* Skip over display elements that are not visible. because IT->w is
22001 if (it
->current_x
< it
->first_visible_x
)
22002 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22003 MOVE_TO_POS
| MOVE_TO_X
);
22005 row
->ascent
= it
->max_ascent
;
22006 row
->height
= it
->max_ascent
+ it
->max_descent
;
22007 row
->phys_ascent
= it
->max_phys_ascent
;
22008 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22009 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22011 if (STRINGP (it
->string
))
22012 it_charpos
= IT_STRING_CHARPOS (*it
);
22014 it_charpos
= IT_CHARPOS (*it
);
22016 /* This condition is for the case that we are called with current_x
22017 past last_visible_x. */
22018 while (it
->current_x
< max_x
)
22020 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22022 /* Get the next display element. */
22023 if (!get_next_display_element (it
))
22026 /* Produce glyphs. */
22027 x_before
= it
->current_x
;
22028 n_glyphs_before
= row
->used
[TEXT_AREA
];
22029 PRODUCE_GLYPHS (it
);
22031 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22034 while (i
< nglyphs
)
22036 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22038 if (it
->line_wrap
!= TRUNCATE
22039 && x
+ glyph
->pixel_width
> max_x
)
22041 /* End of continued line or max_x reached. */
22042 if (CHAR_GLYPH_PADDING_P (*glyph
))
22044 /* A wide character is unbreakable. */
22045 if (row
->reversed_p
)
22046 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22047 - n_glyphs_before
);
22048 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22049 it
->current_x
= x_before
;
22053 if (row
->reversed_p
)
22054 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22055 - (n_glyphs_before
+ i
));
22056 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22061 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22063 /* Glyph is at least partially visible. */
22065 if (x
< it
->first_visible_x
)
22066 row
->x
= x
- it
->first_visible_x
;
22070 /* Glyph is off the left margin of the display area.
22071 Should not happen. */
22075 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22076 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22077 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22078 row
->phys_height
= max (row
->phys_height
,
22079 it
->max_phys_ascent
+ it
->max_phys_descent
);
22080 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22081 it
->max_extra_line_spacing
);
22082 x
+= glyph
->pixel_width
;
22086 /* Stop if max_x reached. */
22090 /* Stop at line ends. */
22091 if (ITERATOR_AT_END_OF_LINE_P (it
))
22093 it
->continuation_lines_width
= 0;
22097 set_iterator_to_next (it
, 1);
22098 if (STRINGP (it
->string
))
22099 it_charpos
= IT_STRING_CHARPOS (*it
);
22101 it_charpos
= IT_CHARPOS (*it
);
22103 /* Stop if truncating at the right edge. */
22104 if (it
->line_wrap
== TRUNCATE
22105 && it
->current_x
>= it
->last_visible_x
)
22107 /* Add truncation mark, but don't do it if the line is
22108 truncated at a padding space. */
22109 if (it_charpos
< it
->string_nchars
)
22111 if (!FRAME_WINDOW_P (it
->f
))
22115 if (it
->current_x
> it
->last_visible_x
)
22117 if (!row
->reversed_p
)
22119 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22120 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22125 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22126 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22128 unproduce_glyphs (it
, ii
+ 1);
22129 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22131 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22133 row
->used
[TEXT_AREA
] = ii
;
22134 produce_special_glyphs (it
, IT_TRUNCATION
);
22137 produce_special_glyphs (it
, IT_TRUNCATION
);
22139 row
->truncated_on_right_p
= 1;
22145 /* Maybe insert a truncation at the left. */
22146 if (it
->first_visible_x
22149 if (!FRAME_WINDOW_P (it
->f
)
22150 || (row
->reversed_p
22151 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22152 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22153 insert_left_trunc_glyphs (it
);
22154 row
->truncated_on_left_p
= 1;
22157 it
->face_id
= saved_face_id
;
22159 /* Value is number of columns displayed. */
22160 return it
->hpos
- hpos_at_start
;
22165 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22166 appears as an element of LIST or as the car of an element of LIST.
22167 If PROPVAL is a list, compare each element against LIST in that
22168 way, and return 1/2 if any element of PROPVAL is found in LIST.
22169 Otherwise return 0. This function cannot quit.
22170 The return value is 2 if the text is invisible but with an ellipsis
22171 and 1 if it's invisible and without an ellipsis. */
22174 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22176 register Lisp_Object tail
, proptail
;
22178 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22180 register Lisp_Object tem
;
22182 if (EQ (propval
, tem
))
22184 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22185 return NILP (XCDR (tem
)) ? 1 : 2;
22188 if (CONSP (propval
))
22190 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22192 Lisp_Object propelt
;
22193 propelt
= XCAR (proptail
);
22194 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22196 register Lisp_Object tem
;
22198 if (EQ (propelt
, tem
))
22200 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22201 return NILP (XCDR (tem
)) ? 1 : 2;
22209 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22210 doc
: /* Non-nil if the property makes the text invisible.
22211 POS-OR-PROP can be a marker or number, in which case it is taken to be
22212 a position in the current buffer and the value of the `invisible' property
22213 is checked; or it can be some other value, which is then presumed to be the
22214 value of the `invisible' property of the text of interest.
22215 The non-nil value returned can be t for truly invisible text or something
22216 else if the text is replaced by an ellipsis. */)
22217 (Lisp_Object pos_or_prop
)
22220 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22221 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22223 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22224 return (invis
== 0 ? Qnil
22226 : make_number (invis
));
22229 /* Calculate a width or height in pixels from a specification using
22230 the following elements:
22233 NUM - a (fractional) multiple of the default font width/height
22234 (NUM) - specifies exactly NUM pixels
22235 UNIT - a fixed number of pixels, see below.
22236 ELEMENT - size of a display element in pixels, see below.
22237 (NUM . SPEC) - equals NUM * SPEC
22238 (+ SPEC SPEC ...) - add pixel values
22239 (- SPEC SPEC ...) - subtract pixel values
22240 (- SPEC) - negate pixel value
22243 INT or FLOAT - a number constant
22244 SYMBOL - use symbol's (buffer local) variable binding.
22247 in - pixels per inch *)
22248 mm - pixels per 1/1000 meter *)
22249 cm - pixels per 1/100 meter *)
22250 width - width of current font in pixels.
22251 height - height of current font in pixels.
22253 *) using the ratio(s) defined in display-pixels-per-inch.
22257 left-fringe - left fringe width in pixels
22258 right-fringe - right fringe width in pixels
22260 left-margin - left margin width in pixels
22261 right-margin - right margin width in pixels
22263 scroll-bar - scroll-bar area width in pixels
22267 Pixels corresponding to 5 inches:
22270 Total width of non-text areas on left side of window (if scroll-bar is on left):
22271 '(space :width (+ left-fringe left-margin scroll-bar))
22273 Align to first text column (in header line):
22274 '(space :align-to 0)
22276 Align to middle of text area minus half the width of variable `my-image'
22277 containing a loaded image:
22278 '(space :align-to (0.5 . (- text my-image)))
22280 Width of left margin minus width of 1 character in the default font:
22281 '(space :width (- left-margin 1))
22283 Width of left margin minus width of 2 characters in the current font:
22284 '(space :width (- left-margin (2 . width)))
22286 Center 1 character over left-margin (in header line):
22287 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22289 Different ways to express width of left fringe plus left margin minus one pixel:
22290 '(space :width (- (+ left-fringe left-margin) (1)))
22291 '(space :width (+ left-fringe left-margin (- (1))))
22292 '(space :width (+ left-fringe left-margin (-1)))
22296 #define NUMVAL(X) \
22297 ((INTEGERP (X) || FLOATP (X)) \
22302 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22303 struct font
*font
, int width_p
, int *align_to
)
22307 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22308 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22311 return OK_PIXELS (0);
22313 eassert (FRAME_LIVE_P (it
->f
));
22315 if (SYMBOLP (prop
))
22317 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22319 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22321 if (unit
[0] == 'i' && unit
[1] == 'n')
22323 else if (unit
[0] == 'm' && unit
[1] == 'm')
22325 else if (unit
[0] == 'c' && unit
[1] == 'm')
22332 #ifdef HAVE_WINDOW_SYSTEM
22333 if (FRAME_WINDOW_P (it
->f
)
22335 ? FRAME_X_DISPLAY_INFO (it
->f
)->resx
22336 : FRAME_X_DISPLAY_INFO (it
->f
)->resy
),
22338 return OK_PIXELS (ppi
/ pixels
);
22341 if ((ppi
= NUMVAL (Vdisplay_pixels_per_inch
), ppi
> 0)
22342 || (CONSP (Vdisplay_pixels_per_inch
)
22344 ? NUMVAL (XCAR (Vdisplay_pixels_per_inch
))
22345 : NUMVAL (XCDR (Vdisplay_pixels_per_inch
))),
22347 return OK_PIXELS (ppi
/ pixels
);
22353 #ifdef HAVE_WINDOW_SYSTEM
22354 if (EQ (prop
, Qheight
))
22355 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22356 if (EQ (prop
, Qwidth
))
22357 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22359 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22360 return OK_PIXELS (1);
22363 if (EQ (prop
, Qtext
))
22364 return OK_PIXELS (width_p
22365 ? window_box_width (it
->w
, TEXT_AREA
)
22366 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22368 if (align_to
&& *align_to
< 0)
22371 if (EQ (prop
, Qleft
))
22372 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22373 if (EQ (prop
, Qright
))
22374 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22375 if (EQ (prop
, Qcenter
))
22376 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22377 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22378 if (EQ (prop
, Qleft_fringe
))
22379 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22380 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22381 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22382 if (EQ (prop
, Qright_fringe
))
22383 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22384 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22385 : window_box_right_offset (it
->w
, TEXT_AREA
));
22386 if (EQ (prop
, Qleft_margin
))
22387 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22388 if (EQ (prop
, Qright_margin
))
22389 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22390 if (EQ (prop
, Qscroll_bar
))
22391 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22393 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22394 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22395 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22400 if (EQ (prop
, Qleft_fringe
))
22401 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22402 if (EQ (prop
, Qright_fringe
))
22403 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22404 if (EQ (prop
, Qleft_margin
))
22405 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22406 if (EQ (prop
, Qright_margin
))
22407 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22408 if (EQ (prop
, Qscroll_bar
))
22409 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22412 prop
= buffer_local_value_1 (prop
, it
->w
->buffer
);
22413 if (EQ (prop
, Qunbound
))
22417 if (INTEGERP (prop
) || FLOATP (prop
))
22419 int base_unit
= (width_p
22420 ? FRAME_COLUMN_WIDTH (it
->f
)
22421 : FRAME_LINE_HEIGHT (it
->f
));
22422 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22427 Lisp_Object car
= XCAR (prop
);
22428 Lisp_Object cdr
= XCDR (prop
);
22432 #ifdef HAVE_WINDOW_SYSTEM
22433 if (FRAME_WINDOW_P (it
->f
)
22434 && valid_image_p (prop
))
22436 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22437 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22439 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22442 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22448 while (CONSP (cdr
))
22450 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22451 font
, width_p
, align_to
))
22454 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22459 if (EQ (car
, Qminus
))
22461 return OK_PIXELS (pixels
);
22464 car
= buffer_local_value_1 (car
, it
->w
->buffer
);
22465 if (EQ (car
, Qunbound
))
22469 if (INTEGERP (car
) || FLOATP (car
))
22472 pixels
= XFLOATINT (car
);
22474 return OK_PIXELS (pixels
);
22475 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22476 font
, width_p
, align_to
))
22477 return OK_PIXELS (pixels
* fact
);
22488 /***********************************************************************
22490 ***********************************************************************/
22492 #ifdef HAVE_WINDOW_SYSTEM
22497 dump_glyph_string (struct glyph_string
*s
)
22499 fprintf (stderr
, "glyph string\n");
22500 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22501 s
->x
, s
->y
, s
->width
, s
->height
);
22502 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22503 fprintf (stderr
, " hl = %d\n", s
->hl
);
22504 fprintf (stderr
, " left overhang = %d, right = %d\n",
22505 s
->left_overhang
, s
->right_overhang
);
22506 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22507 fprintf (stderr
, " extends to end of line = %d\n",
22508 s
->extends_to_end_of_line_p
);
22509 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22510 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22513 #endif /* GLYPH_DEBUG */
22515 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22516 of XChar2b structures for S; it can't be allocated in
22517 init_glyph_string because it must be allocated via `alloca'. W
22518 is the window on which S is drawn. ROW and AREA are the glyph row
22519 and area within the row from which S is constructed. START is the
22520 index of the first glyph structure covered by S. HL is a
22521 face-override for drawing S. */
22524 #define OPTIONAL_HDC(hdc) HDC hdc,
22525 #define DECLARE_HDC(hdc) HDC hdc;
22526 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22527 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22530 #ifndef OPTIONAL_HDC
22531 #define OPTIONAL_HDC(hdc)
22532 #define DECLARE_HDC(hdc)
22533 #define ALLOCATE_HDC(hdc, f)
22534 #define RELEASE_HDC(hdc, f)
22538 init_glyph_string (struct glyph_string
*s
,
22540 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22541 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22543 memset (s
, 0, sizeof *s
);
22545 s
->f
= XFRAME (w
->frame
);
22549 s
->display
= FRAME_X_DISPLAY (s
->f
);
22550 s
->window
= FRAME_X_WINDOW (s
->f
);
22551 s
->char2b
= char2b
;
22555 s
->first_glyph
= row
->glyphs
[area
] + start
;
22556 s
->height
= row
->height
;
22557 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22558 s
->ybase
= s
->y
+ row
->ascent
;
22562 /* Append the list of glyph strings with head H and tail T to the list
22563 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22566 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22567 struct glyph_string
*h
, struct glyph_string
*t
)
22581 /* Prepend the list of glyph strings with head H and tail T to the
22582 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22586 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22587 struct glyph_string
*h
, struct glyph_string
*t
)
22601 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22602 Set *HEAD and *TAIL to the resulting list. */
22605 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22606 struct glyph_string
*s
)
22608 s
->next
= s
->prev
= NULL
;
22609 append_glyph_string_lists (head
, tail
, s
, s
);
22613 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22614 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22615 make sure that X resources for the face returned are allocated.
22616 Value is a pointer to a realized face that is ready for display if
22617 DISPLAY_P is non-zero. */
22619 static struct face
*
22620 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22621 XChar2b
*char2b
, int display_p
)
22623 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22627 unsigned code
= face
->font
->driver
->encode_char (face
->font
, c
);
22629 if (code
!= FONT_INVALID_CODE
)
22630 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22632 STORE_XCHAR2B (char2b
, 0, 0);
22635 /* Make sure X resources of the face are allocated. */
22636 #ifdef HAVE_X_WINDOWS
22640 eassert (face
!= NULL
);
22641 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22648 /* Get face and two-byte form of character glyph GLYPH on frame F.
22649 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22650 a pointer to a realized face that is ready for display. */
22652 static struct face
*
22653 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22654 XChar2b
*char2b
, int *two_byte_p
)
22658 eassert (glyph
->type
== CHAR_GLYPH
);
22659 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22668 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22669 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22671 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22673 if (code
!= FONT_INVALID_CODE
)
22674 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22676 STORE_XCHAR2B (char2b
, 0, 0);
22679 /* Make sure X resources of the face are allocated. */
22680 eassert (face
!= NULL
);
22681 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22686 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22687 Return 1 if FONT has a glyph for C, otherwise return 0. */
22690 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22694 if (CHAR_BYTE8_P (c
))
22695 code
= CHAR_TO_BYTE8 (c
);
22697 code
= font
->driver
->encode_char (font
, c
);
22699 if (code
== FONT_INVALID_CODE
)
22701 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22706 /* Fill glyph string S with composition components specified by S->cmp.
22708 BASE_FACE is the base face of the composition.
22709 S->cmp_from is the index of the first component for S.
22711 OVERLAPS non-zero means S should draw the foreground only, and use
22712 its physical height for clipping. See also draw_glyphs.
22714 Value is the index of a component not in S. */
22717 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22721 /* For all glyphs of this composition, starting at the offset
22722 S->cmp_from, until we reach the end of the definition or encounter a
22723 glyph that requires the different face, add it to S. */
22728 s
->for_overlaps
= overlaps
;
22731 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
22733 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
22735 /* TAB in a composition means display glyphs with padding space
22736 on the left or right. */
22739 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
22742 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
22749 s
->font
= s
->face
->font
;
22751 else if (s
->face
!= face
)
22759 if (s
->face
== NULL
)
22761 s
->face
= base_face
->ascii_face
;
22762 s
->font
= s
->face
->font
;
22765 /* All glyph strings for the same composition has the same width,
22766 i.e. the width set for the first component of the composition. */
22767 s
->width
= s
->first_glyph
->pixel_width
;
22769 /* If the specified font could not be loaded, use the frame's
22770 default font, but record the fact that we couldn't load it in
22771 the glyph string so that we can draw rectangles for the
22772 characters of the glyph string. */
22773 if (s
->font
== NULL
)
22775 s
->font_not_found_p
= 1;
22776 s
->font
= FRAME_FONT (s
->f
);
22779 /* Adjust base line for subscript/superscript text. */
22780 s
->ybase
+= s
->first_glyph
->voffset
;
22782 /* This glyph string must always be drawn with 16-bit functions. */
22789 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
22790 int start
, int end
, int overlaps
)
22792 struct glyph
*glyph
, *last
;
22793 Lisp_Object lgstring
;
22796 s
->for_overlaps
= overlaps
;
22797 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22798 last
= s
->row
->glyphs
[s
->area
] + end
;
22799 s
->cmp_id
= glyph
->u
.cmp
.id
;
22800 s
->cmp_from
= glyph
->slice
.cmp
.from
;
22801 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
22802 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22803 lgstring
= composition_gstring_from_id (s
->cmp_id
);
22804 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
22806 while (glyph
< last
22807 && glyph
->u
.cmp
.automatic
22808 && glyph
->u
.cmp
.id
== s
->cmp_id
22809 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
22810 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
22812 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
22814 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
22815 unsigned code
= LGLYPH_CODE (lglyph
);
22817 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
22819 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
22820 return glyph
- s
->row
->glyphs
[s
->area
];
22824 /* Fill glyph string S from a sequence glyphs for glyphless characters.
22825 See the comment of fill_glyph_string for arguments.
22826 Value is the index of the first glyph not in S. */
22830 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
22831 int start
, int end
, int overlaps
)
22833 struct glyph
*glyph
, *last
;
22836 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
22837 s
->for_overlaps
= overlaps
;
22838 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22839 last
= s
->row
->glyphs
[s
->area
] + end
;
22840 voffset
= glyph
->voffset
;
22841 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22842 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
22844 s
->width
= glyph
->pixel_width
;
22846 while (glyph
< last
22847 && glyph
->type
== GLYPHLESS_GLYPH
22848 && glyph
->voffset
== voffset
22849 && glyph
->face_id
== face_id
)
22852 s
->width
+= glyph
->pixel_width
;
22855 s
->ybase
+= voffset
;
22856 return glyph
- s
->row
->glyphs
[s
->area
];
22860 /* Fill glyph string S from a sequence of character glyphs.
22862 FACE_ID is the face id of the string. START is the index of the
22863 first glyph to consider, END is the index of the last + 1.
22864 OVERLAPS non-zero means S should draw the foreground only, and use
22865 its physical height for clipping. See also draw_glyphs.
22867 Value is the index of the first glyph not in S. */
22870 fill_glyph_string (struct glyph_string
*s
, int face_id
,
22871 int start
, int end
, int overlaps
)
22873 struct glyph
*glyph
, *last
;
22875 int glyph_not_available_p
;
22877 eassert (s
->f
== XFRAME (s
->w
->frame
));
22878 eassert (s
->nchars
== 0);
22879 eassert (start
>= 0 && end
> start
);
22881 s
->for_overlaps
= overlaps
;
22882 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22883 last
= s
->row
->glyphs
[s
->area
] + end
;
22884 voffset
= glyph
->voffset
;
22885 s
->padding_p
= glyph
->padding_p
;
22886 glyph_not_available_p
= glyph
->glyph_not_available_p
;
22888 while (glyph
< last
22889 && glyph
->type
== CHAR_GLYPH
22890 && glyph
->voffset
== voffset
22891 /* Same face id implies same font, nowadays. */
22892 && glyph
->face_id
== face_id
22893 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
22897 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
22898 s
->char2b
+ s
->nchars
,
22900 s
->two_byte_p
= two_byte_p
;
22902 eassert (s
->nchars
<= end
- start
);
22903 s
->width
+= glyph
->pixel_width
;
22904 if (glyph
++->padding_p
!= s
->padding_p
)
22908 s
->font
= s
->face
->font
;
22910 /* If the specified font could not be loaded, use the frame's font,
22911 but record the fact that we couldn't load it in
22912 S->font_not_found_p so that we can draw rectangles for the
22913 characters of the glyph string. */
22914 if (s
->font
== NULL
|| glyph_not_available_p
)
22916 s
->font_not_found_p
= 1;
22917 s
->font
= FRAME_FONT (s
->f
);
22920 /* Adjust base line for subscript/superscript text. */
22921 s
->ybase
+= voffset
;
22923 eassert (s
->face
&& s
->face
->gc
);
22924 return glyph
- s
->row
->glyphs
[s
->area
];
22928 /* Fill glyph string S from image glyph S->first_glyph. */
22931 fill_image_glyph_string (struct glyph_string
*s
)
22933 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
22934 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
22936 s
->slice
= s
->first_glyph
->slice
.img
;
22937 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
22938 s
->font
= s
->face
->font
;
22939 s
->width
= s
->first_glyph
->pixel_width
;
22941 /* Adjust base line for subscript/superscript text. */
22942 s
->ybase
+= s
->first_glyph
->voffset
;
22946 /* Fill glyph string S from a sequence of stretch glyphs.
22948 START is the index of the first glyph to consider,
22949 END is the index of the last + 1.
22951 Value is the index of the first glyph not in S. */
22954 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
22956 struct glyph
*glyph
, *last
;
22957 int voffset
, face_id
;
22959 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
22961 glyph
= s
->row
->glyphs
[s
->area
] + start
;
22962 last
= s
->row
->glyphs
[s
->area
] + end
;
22963 face_id
= glyph
->face_id
;
22964 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
22965 s
->font
= s
->face
->font
;
22966 s
->width
= glyph
->pixel_width
;
22968 voffset
= glyph
->voffset
;
22972 && glyph
->type
== STRETCH_GLYPH
22973 && glyph
->voffset
== voffset
22974 && glyph
->face_id
== face_id
);
22976 s
->width
+= glyph
->pixel_width
;
22978 /* Adjust base line for subscript/superscript text. */
22979 s
->ybase
+= voffset
;
22981 /* The case that face->gc == 0 is handled when drawing the glyph
22982 string by calling PREPARE_FACE_FOR_DISPLAY. */
22984 return glyph
- s
->row
->glyphs
[s
->area
];
22987 static struct font_metrics
*
22988 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
22990 static struct font_metrics metrics
;
22991 unsigned code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
22993 if (! font
|| code
== FONT_INVALID_CODE
)
22995 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23000 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23001 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23002 assumed to be zero. */
23005 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23007 *left
= *right
= 0;
23009 if (glyph
->type
== CHAR_GLYPH
)
23013 struct font_metrics
*pcm
;
23015 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23016 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23018 if (pcm
->rbearing
> pcm
->width
)
23019 *right
= pcm
->rbearing
- pcm
->width
;
23020 if (pcm
->lbearing
< 0)
23021 *left
= -pcm
->lbearing
;
23024 else if (glyph
->type
== COMPOSITE_GLYPH
)
23026 if (! glyph
->u
.cmp
.automatic
)
23028 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23030 if (cmp
->rbearing
> cmp
->pixel_width
)
23031 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23032 if (cmp
->lbearing
< 0)
23033 *left
= - cmp
->lbearing
;
23037 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23038 struct font_metrics metrics
;
23040 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23041 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23042 if (metrics
.rbearing
> metrics
.width
)
23043 *right
= metrics
.rbearing
- metrics
.width
;
23044 if (metrics
.lbearing
< 0)
23045 *left
= - metrics
.lbearing
;
23051 /* Return the index of the first glyph preceding glyph string S that
23052 is overwritten by S because of S's left overhang. Value is -1
23053 if no glyphs are overwritten. */
23056 left_overwritten (struct glyph_string
*s
)
23060 if (s
->left_overhang
)
23063 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23064 int first
= s
->first_glyph
- glyphs
;
23066 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23067 x
-= glyphs
[i
].pixel_width
;
23078 /* Return the index of the first glyph preceding glyph string S that
23079 is overwriting S because of its right overhang. Value is -1 if no
23080 glyph in front of S overwrites S. */
23083 left_overwriting (struct glyph_string
*s
)
23086 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23087 int first
= s
->first_glyph
- glyphs
;
23091 for (i
= first
- 1; i
>= 0; --i
)
23094 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23097 x
-= glyphs
[i
].pixel_width
;
23104 /* Return the index of the last glyph following glyph string S that is
23105 overwritten by S because of S's right overhang. Value is -1 if
23106 no such glyph is found. */
23109 right_overwritten (struct glyph_string
*s
)
23113 if (s
->right_overhang
)
23116 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23117 int first
= (s
->first_glyph
- glyphs
23118 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23119 int end
= s
->row
->used
[s
->area
];
23121 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23122 x
+= glyphs
[i
].pixel_width
;
23131 /* Return the index of the last glyph following glyph string S that
23132 overwrites S because of its left overhang. Value is negative
23133 if no such glyph is found. */
23136 right_overwriting (struct glyph_string
*s
)
23139 int end
= s
->row
->used
[s
->area
];
23140 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23141 int first
= (s
->first_glyph
- glyphs
23142 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23146 for (i
= first
; i
< end
; ++i
)
23149 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23152 x
+= glyphs
[i
].pixel_width
;
23159 /* Set background width of glyph string S. START is the index of the
23160 first glyph following S. LAST_X is the right-most x-position + 1
23161 in the drawing area. */
23164 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23166 /* If the face of this glyph string has to be drawn to the end of
23167 the drawing area, set S->extends_to_end_of_line_p. */
23169 if (start
== s
->row
->used
[s
->area
]
23170 && s
->area
== TEXT_AREA
23171 && ((s
->row
->fill_line_p
23172 && (s
->hl
== DRAW_NORMAL_TEXT
23173 || s
->hl
== DRAW_IMAGE_RAISED
23174 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23175 || s
->hl
== DRAW_MOUSE_FACE
))
23176 s
->extends_to_end_of_line_p
= 1;
23178 /* If S extends its face to the end of the line, set its
23179 background_width to the distance to the right edge of the drawing
23181 if (s
->extends_to_end_of_line_p
)
23182 s
->background_width
= last_x
- s
->x
+ 1;
23184 s
->background_width
= s
->width
;
23188 /* Compute overhangs and x-positions for glyph string S and its
23189 predecessors, or successors. X is the starting x-position for S.
23190 BACKWARD_P non-zero means process predecessors. */
23193 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23199 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23200 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23210 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23211 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23221 /* The following macros are only called from draw_glyphs below.
23222 They reference the following parameters of that function directly:
23223 `w', `row', `area', and `overlap_p'
23224 as well as the following local variables:
23225 `s', `f', and `hdc' (in W32) */
23228 /* On W32, silently add local `hdc' variable to argument list of
23229 init_glyph_string. */
23230 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23231 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23233 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23234 init_glyph_string (s, char2b, w, row, area, start, hl)
23237 /* Add a glyph string for a stretch glyph to the list of strings
23238 between HEAD and TAIL. START is the index of the stretch glyph in
23239 row area AREA of glyph row ROW. END is the index of the last glyph
23240 in that glyph row area. X is the current output position assigned
23241 to the new glyph string constructed. HL overrides that face of the
23242 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23243 is the right-most x-position of the drawing area. */
23245 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23246 and below -- keep them on one line. */
23247 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23250 s = alloca (sizeof *s); \
23251 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23252 START = fill_stretch_glyph_string (s, START, END); \
23253 append_glyph_string (&HEAD, &TAIL, s); \
23259 /* Add a glyph string for an image glyph to the list of strings
23260 between HEAD and TAIL. START is the index of the image glyph in
23261 row area AREA of glyph row ROW. END is the index of the last glyph
23262 in that glyph row area. X is the current output position assigned
23263 to the new glyph string constructed. HL overrides that face of the
23264 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23265 is the right-most x-position of the drawing area. */
23267 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23270 s = alloca (sizeof *s); \
23271 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23272 fill_image_glyph_string (s); \
23273 append_glyph_string (&HEAD, &TAIL, s); \
23280 /* Add a glyph string for a sequence of character glyphs to the list
23281 of strings between HEAD and TAIL. START is the index of the first
23282 glyph in row area AREA of glyph row ROW that is part of the new
23283 glyph string. END is the index of the last glyph in that glyph row
23284 area. X is the current output position assigned to the new glyph
23285 string constructed. HL overrides that face of the glyph; e.g. it
23286 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23287 right-most x-position of the drawing area. */
23289 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23295 face_id = (row)->glyphs[area][START].face_id; \
23297 s = alloca (sizeof *s); \
23298 char2b = alloca ((END - START) * sizeof *char2b); \
23299 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23300 append_glyph_string (&HEAD, &TAIL, s); \
23302 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23307 /* Add a glyph string for a composite sequence to the list of strings
23308 between HEAD and TAIL. START is the index of the first glyph in
23309 row area AREA of glyph row ROW that is part of the new glyph
23310 string. END is the index of the last glyph in that glyph row area.
23311 X is the current output position assigned to the new glyph string
23312 constructed. HL overrides that face of the glyph; e.g. it is
23313 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23314 x-position of the drawing area. */
23316 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23318 int face_id = (row)->glyphs[area][START].face_id; \
23319 struct face *base_face = FACE_FROM_ID (f, face_id); \
23320 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23321 struct composition *cmp = composition_table[cmp_id]; \
23323 struct glyph_string *first_s = NULL; \
23326 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23328 /* Make glyph_strings for each glyph sequence that is drawable by \
23329 the same face, and append them to HEAD/TAIL. */ \
23330 for (n = 0; n < cmp->glyph_len;) \
23332 s = alloca (sizeof *s); \
23333 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23334 append_glyph_string (&(HEAD), &(TAIL), s); \
23340 n = fill_composite_glyph_string (s, base_face, overlaps); \
23348 /* Add a glyph string for a glyph-string sequence to the list of strings
23349 between HEAD and TAIL. */
23351 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23355 Lisp_Object gstring; \
23357 face_id = (row)->glyphs[area][START].face_id; \
23358 gstring = (composition_gstring_from_id \
23359 ((row)->glyphs[area][START].u.cmp.id)); \
23360 s = alloca (sizeof *s); \
23361 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23362 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23363 append_glyph_string (&(HEAD), &(TAIL), s); \
23365 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23369 /* Add a glyph string for a sequence of glyphless character's glyphs
23370 to the list of strings between HEAD and TAIL. The meanings of
23371 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23373 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23378 face_id = (row)->glyphs[area][START].face_id; \
23380 s = alloca (sizeof *s); \
23381 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23382 append_glyph_string (&HEAD, &TAIL, s); \
23384 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23390 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23391 of AREA of glyph row ROW on window W between indices START and END.
23392 HL overrides the face for drawing glyph strings, e.g. it is
23393 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23394 x-positions of the drawing area.
23396 This is an ugly monster macro construct because we must use alloca
23397 to allocate glyph strings (because draw_glyphs can be called
23398 asynchronously). */
23400 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23403 HEAD = TAIL = NULL; \
23404 while (START < END) \
23406 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23407 switch (first_glyph->type) \
23410 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23414 case COMPOSITE_GLYPH: \
23415 if (first_glyph->u.cmp.automatic) \
23416 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23419 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23423 case STRETCH_GLYPH: \
23424 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23428 case IMAGE_GLYPH: \
23429 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23433 case GLYPHLESS_GLYPH: \
23434 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23444 set_glyph_string_background_width (s, START, LAST_X); \
23451 /* Draw glyphs between START and END in AREA of ROW on window W,
23452 starting at x-position X. X is relative to AREA in W. HL is a
23453 face-override with the following meaning:
23455 DRAW_NORMAL_TEXT draw normally
23456 DRAW_CURSOR draw in cursor face
23457 DRAW_MOUSE_FACE draw in mouse face.
23458 DRAW_INVERSE_VIDEO draw in mode line face
23459 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23460 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23462 If OVERLAPS is non-zero, draw only the foreground of characters and
23463 clip to the physical height of ROW. Non-zero value also defines
23464 the overlapping part to be drawn:
23466 OVERLAPS_PRED overlap with preceding rows
23467 OVERLAPS_SUCC overlap with succeeding rows
23468 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23469 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23471 Value is the x-position reached, relative to AREA of W. */
23474 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23475 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23476 enum draw_glyphs_face hl
, int overlaps
)
23478 struct glyph_string
*head
, *tail
;
23479 struct glyph_string
*s
;
23480 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23481 int i
, j
, x_reached
, last_x
, area_left
= 0;
23482 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23485 ALLOCATE_HDC (hdc
, f
);
23487 /* Let's rather be paranoid than getting a SEGV. */
23488 end
= min (end
, row
->used
[area
]);
23489 start
= clip_to_bounds (0, start
, end
);
23491 /* Translate X to frame coordinates. Set last_x to the right
23492 end of the drawing area. */
23493 if (row
->full_width_p
)
23495 /* X is relative to the left edge of W, without scroll bars
23497 area_left
= WINDOW_LEFT_EDGE_X (w
);
23498 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23502 area_left
= window_box_left (w
, area
);
23503 last_x
= area_left
+ window_box_width (w
, area
);
23507 /* Build a doubly-linked list of glyph_string structures between
23508 head and tail from what we have to draw. Note that the macro
23509 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23510 the reason we use a separate variable `i'. */
23512 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23514 x_reached
= tail
->x
+ tail
->background_width
;
23518 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23519 the row, redraw some glyphs in front or following the glyph
23520 strings built above. */
23521 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23523 struct glyph_string
*h
, *t
;
23524 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23525 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23526 int check_mouse_face
= 0;
23529 /* If mouse highlighting is on, we may need to draw adjacent
23530 glyphs using mouse-face highlighting. */
23531 if (area
== TEXT_AREA
&& row
->mouse_face_p
23532 && hlinfo
->mouse_face_beg_row
>= 0
23533 && hlinfo
->mouse_face_end_row
>= 0)
23535 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23537 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23538 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23540 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23542 check_mouse_face
= 1;
23543 mouse_beg_col
= (row
== mouse_beg_row
)
23544 ? hlinfo
->mouse_face_beg_col
: 0;
23545 mouse_end_col
= (row
== mouse_end_row
)
23546 ? hlinfo
->mouse_face_end_col
23547 : row
->used
[TEXT_AREA
];
23551 /* Compute overhangs for all glyph strings. */
23552 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23553 for (s
= head
; s
; s
= s
->next
)
23554 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23556 /* Prepend glyph strings for glyphs in front of the first glyph
23557 string that are overwritten because of the first glyph
23558 string's left overhang. The background of all strings
23559 prepended must be drawn because the first glyph string
23561 i
= left_overwritten (head
);
23564 enum draw_glyphs_face overlap_hl
;
23566 /* If this row contains mouse highlighting, attempt to draw
23567 the overlapped glyphs with the correct highlight. This
23568 code fails if the overlap encompasses more than one glyph
23569 and mouse-highlight spans only some of these glyphs.
23570 However, making it work perfectly involves a lot more
23571 code, and I don't know if the pathological case occurs in
23572 practice, so we'll stick to this for now. --- cyd */
23573 if (check_mouse_face
23574 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23575 overlap_hl
= DRAW_MOUSE_FACE
;
23577 overlap_hl
= DRAW_NORMAL_TEXT
;
23580 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23581 overlap_hl
, dummy_x
, last_x
);
23583 compute_overhangs_and_x (t
, head
->x
, 1);
23584 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23588 /* Prepend glyph strings for glyphs in front of the first glyph
23589 string that overwrite that glyph string because of their
23590 right overhang. For these strings, only the foreground must
23591 be drawn, because it draws over the glyph string at `head'.
23592 The background must not be drawn because this would overwrite
23593 right overhangs of preceding glyphs for which no glyph
23595 i
= left_overwriting (head
);
23598 enum draw_glyphs_face overlap_hl
;
23600 if (check_mouse_face
23601 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23602 overlap_hl
= DRAW_MOUSE_FACE
;
23604 overlap_hl
= DRAW_NORMAL_TEXT
;
23607 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23608 overlap_hl
, dummy_x
, last_x
);
23609 for (s
= h
; s
; s
= s
->next
)
23610 s
->background_filled_p
= 1;
23611 compute_overhangs_and_x (t
, head
->x
, 1);
23612 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23615 /* Append glyphs strings for glyphs following the last glyph
23616 string tail that are overwritten by tail. The background of
23617 these strings has to be drawn because tail's foreground draws
23619 i
= right_overwritten (tail
);
23622 enum draw_glyphs_face overlap_hl
;
23624 if (check_mouse_face
23625 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23626 overlap_hl
= DRAW_MOUSE_FACE
;
23628 overlap_hl
= DRAW_NORMAL_TEXT
;
23630 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23631 overlap_hl
, x
, last_x
);
23632 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23633 we don't have `end = i;' here. */
23634 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23635 append_glyph_string_lists (&head
, &tail
, h
, t
);
23639 /* Append glyph strings for glyphs following the last glyph
23640 string tail that overwrite tail. The foreground of such
23641 glyphs has to be drawn because it writes into the background
23642 of tail. The background must not be drawn because it could
23643 paint over the foreground of following glyphs. */
23644 i
= right_overwriting (tail
);
23647 enum draw_glyphs_face overlap_hl
;
23648 if (check_mouse_face
23649 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23650 overlap_hl
= DRAW_MOUSE_FACE
;
23652 overlap_hl
= DRAW_NORMAL_TEXT
;
23655 i
++; /* We must include the Ith glyph. */
23656 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23657 overlap_hl
, x
, last_x
);
23658 for (s
= h
; s
; s
= s
->next
)
23659 s
->background_filled_p
= 1;
23660 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23661 append_glyph_string_lists (&head
, &tail
, h
, t
);
23663 if (clip_head
|| clip_tail
)
23664 for (s
= head
; s
; s
= s
->next
)
23666 s
->clip_head
= clip_head
;
23667 s
->clip_tail
= clip_tail
;
23671 /* Draw all strings. */
23672 for (s
= head
; s
; s
= s
->next
)
23673 FRAME_RIF (f
)->draw_glyph_string (s
);
23676 /* When focus a sole frame and move horizontally, this sets on_p to 0
23677 causing a failure to erase prev cursor position. */
23678 if (area
== TEXT_AREA
23679 && !row
->full_width_p
23680 /* When drawing overlapping rows, only the glyph strings'
23681 foreground is drawn, which doesn't erase a cursor
23685 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23686 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23687 : (tail
? tail
->x
+ tail
->background_width
: x
));
23691 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23692 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23696 /* Value is the x-position up to which drawn, relative to AREA of W.
23697 This doesn't include parts drawn because of overhangs. */
23698 if (row
->full_width_p
)
23699 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23701 x_reached
-= area_left
;
23703 RELEASE_HDC (hdc
, f
);
23708 /* Expand row matrix if too narrow. Don't expand if area
23711 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23713 if (!fonts_changed_p \
23714 && (it->glyph_row->glyphs[area] \
23715 < it->glyph_row->glyphs[area + 1])) \
23717 it->w->ncols_scale_factor++; \
23718 fonts_changed_p = 1; \
23722 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23723 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23726 append_glyph (struct it
*it
)
23728 struct glyph
*glyph
;
23729 enum glyph_row_area area
= it
->area
;
23731 eassert (it
->glyph_row
);
23732 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
23734 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23735 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23737 /* If the glyph row is reversed, we need to prepend the glyph
23738 rather than append it. */
23739 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23743 /* Make room for the additional glyph. */
23744 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
23746 glyph
= it
->glyph_row
->glyphs
[area
];
23748 glyph
->charpos
= CHARPOS (it
->position
);
23749 glyph
->object
= it
->object
;
23750 if (it
->pixel_width
> 0)
23752 glyph
->pixel_width
= it
->pixel_width
;
23753 glyph
->padding_p
= 0;
23757 /* Assure at least 1-pixel width. Otherwise, cursor can't
23758 be displayed correctly. */
23759 glyph
->pixel_width
= 1;
23760 glyph
->padding_p
= 1;
23762 glyph
->ascent
= it
->ascent
;
23763 glyph
->descent
= it
->descent
;
23764 glyph
->voffset
= it
->voffset
;
23765 glyph
->type
= CHAR_GLYPH
;
23766 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23767 glyph
->multibyte_p
= it
->multibyte_p
;
23768 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23770 /* In R2L rows, the left and the right box edges need to be
23771 drawn in reverse direction. */
23772 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23773 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23777 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23778 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23780 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23781 || it
->phys_descent
> it
->descent
);
23782 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
23783 glyph
->face_id
= it
->face_id
;
23784 glyph
->u
.ch
= it
->char_to_display
;
23785 glyph
->slice
.img
= null_glyph_slice
;
23786 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23789 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23790 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23792 glyph
->bidi_type
= it
->bidi_it
.type
;
23796 glyph
->resolved_level
= 0;
23797 glyph
->bidi_type
= UNKNOWN_BT
;
23799 ++it
->glyph_row
->used
[area
];
23802 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23805 /* Store one glyph for the composition IT->cmp_it.id in
23806 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
23810 append_composite_glyph (struct it
*it
)
23812 struct glyph
*glyph
;
23813 enum glyph_row_area area
= it
->area
;
23815 eassert (it
->glyph_row
);
23817 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
23818 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
23820 /* If the glyph row is reversed, we need to prepend the glyph
23821 rather than append it. */
23822 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
23826 /* Make room for the new glyph. */
23827 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
23829 glyph
= it
->glyph_row
->glyphs
[it
->area
];
23831 glyph
->charpos
= it
->cmp_it
.charpos
;
23832 glyph
->object
= it
->object
;
23833 glyph
->pixel_width
= it
->pixel_width
;
23834 glyph
->ascent
= it
->ascent
;
23835 glyph
->descent
= it
->descent
;
23836 glyph
->voffset
= it
->voffset
;
23837 glyph
->type
= COMPOSITE_GLYPH
;
23838 if (it
->cmp_it
.ch
< 0)
23840 glyph
->u
.cmp
.automatic
= 0;
23841 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23842 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
23846 glyph
->u
.cmp
.automatic
= 1;
23847 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
23848 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
23849 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
23851 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
23852 glyph
->multibyte_p
= it
->multibyte_p
;
23853 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
23855 /* In R2L rows, the left and the right box edges need to be
23856 drawn in reverse direction. */
23857 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
23858 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
23862 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
23863 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
23865 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
23866 || it
->phys_descent
> it
->descent
);
23867 glyph
->padding_p
= 0;
23868 glyph
->glyph_not_available_p
= 0;
23869 glyph
->face_id
= it
->face_id
;
23870 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
23873 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
23874 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
23876 glyph
->bidi_type
= it
->bidi_it
.type
;
23878 ++it
->glyph_row
->used
[area
];
23881 IT_EXPAND_MATRIX_WIDTH (it
, area
);
23885 /* Change IT->ascent and IT->height according to the setting of
23889 take_vertical_position_into_account (struct it
*it
)
23893 if (it
->voffset
< 0)
23894 /* Increase the ascent so that we can display the text higher
23896 it
->ascent
-= it
->voffset
;
23898 /* Increase the descent so that we can display the text lower
23900 it
->descent
+= it
->voffset
;
23905 /* Produce glyphs/get display metrics for the image IT is loaded with.
23906 See the description of struct display_iterator in dispextern.h for
23907 an overview of struct display_iterator. */
23910 produce_image_glyph (struct it
*it
)
23914 int glyph_ascent
, crop
;
23915 struct glyph_slice slice
;
23917 eassert (it
->what
== IT_IMAGE
);
23919 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
23921 /* Make sure X resources of the face is loaded. */
23922 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
23924 if (it
->image_id
< 0)
23926 /* Fringe bitmap. */
23927 it
->ascent
= it
->phys_ascent
= 0;
23928 it
->descent
= it
->phys_descent
= 0;
23929 it
->pixel_width
= 0;
23934 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
23936 /* Make sure X resources of the image is loaded. */
23937 prepare_image_for_display (it
->f
, img
);
23939 slice
.x
= slice
.y
= 0;
23940 slice
.width
= img
->width
;
23941 slice
.height
= img
->height
;
23943 if (INTEGERP (it
->slice
.x
))
23944 slice
.x
= XINT (it
->slice
.x
);
23945 else if (FLOATP (it
->slice
.x
))
23946 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
23948 if (INTEGERP (it
->slice
.y
))
23949 slice
.y
= XINT (it
->slice
.y
);
23950 else if (FLOATP (it
->slice
.y
))
23951 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
23953 if (INTEGERP (it
->slice
.width
))
23954 slice
.width
= XINT (it
->slice
.width
);
23955 else if (FLOATP (it
->slice
.width
))
23956 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
23958 if (INTEGERP (it
->slice
.height
))
23959 slice
.height
= XINT (it
->slice
.height
);
23960 else if (FLOATP (it
->slice
.height
))
23961 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
23963 if (slice
.x
>= img
->width
)
23964 slice
.x
= img
->width
;
23965 if (slice
.y
>= img
->height
)
23966 slice
.y
= img
->height
;
23967 if (slice
.x
+ slice
.width
>= img
->width
)
23968 slice
.width
= img
->width
- slice
.x
;
23969 if (slice
.y
+ slice
.height
> img
->height
)
23970 slice
.height
= img
->height
- slice
.y
;
23972 if (slice
.width
== 0 || slice
.height
== 0)
23975 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
23977 it
->descent
= slice
.height
- glyph_ascent
;
23979 it
->descent
+= img
->vmargin
;
23980 if (slice
.y
+ slice
.height
== img
->height
)
23981 it
->descent
+= img
->vmargin
;
23982 it
->phys_descent
= it
->descent
;
23984 it
->pixel_width
= slice
.width
;
23986 it
->pixel_width
+= img
->hmargin
;
23987 if (slice
.x
+ slice
.width
== img
->width
)
23988 it
->pixel_width
+= img
->hmargin
;
23990 /* It's quite possible for images to have an ascent greater than
23991 their height, so don't get confused in that case. */
23992 if (it
->descent
< 0)
23997 if (face
->box
!= FACE_NO_BOX
)
23999 if (face
->box_line_width
> 0)
24002 it
->ascent
+= face
->box_line_width
;
24003 if (slice
.y
+ slice
.height
== img
->height
)
24004 it
->descent
+= face
->box_line_width
;
24007 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24008 it
->pixel_width
+= eabs (face
->box_line_width
);
24009 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24010 it
->pixel_width
+= eabs (face
->box_line_width
);
24013 take_vertical_position_into_account (it
);
24015 /* Automatically crop wide image glyphs at right edge so we can
24016 draw the cursor on same display row. */
24017 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24018 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24020 it
->pixel_width
-= crop
;
24021 slice
.width
-= crop
;
24026 struct glyph
*glyph
;
24027 enum glyph_row_area area
= it
->area
;
24029 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24030 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24032 glyph
->charpos
= CHARPOS (it
->position
);
24033 glyph
->object
= it
->object
;
24034 glyph
->pixel_width
= it
->pixel_width
;
24035 glyph
->ascent
= glyph_ascent
;
24036 glyph
->descent
= it
->descent
;
24037 glyph
->voffset
= it
->voffset
;
24038 glyph
->type
= IMAGE_GLYPH
;
24039 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24040 glyph
->multibyte_p
= it
->multibyte_p
;
24041 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24043 /* In R2L rows, the left and the right box edges need to be
24044 drawn in reverse direction. */
24045 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24046 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24050 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24051 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24053 glyph
->overlaps_vertically_p
= 0;
24054 glyph
->padding_p
= 0;
24055 glyph
->glyph_not_available_p
= 0;
24056 glyph
->face_id
= it
->face_id
;
24057 glyph
->u
.img_id
= img
->id
;
24058 glyph
->slice
.img
= slice
;
24059 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24062 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24063 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24065 glyph
->bidi_type
= it
->bidi_it
.type
;
24067 ++it
->glyph_row
->used
[area
];
24070 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24075 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24076 of the glyph, WIDTH and HEIGHT are the width and height of the
24077 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24080 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24081 int width
, int height
, int ascent
)
24083 struct glyph
*glyph
;
24084 enum glyph_row_area area
= it
->area
;
24086 eassert (ascent
>= 0 && ascent
<= height
);
24088 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24089 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24091 /* If the glyph row is reversed, we need to prepend the glyph
24092 rather than append it. */
24093 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24097 /* Make room for the additional glyph. */
24098 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24100 glyph
= it
->glyph_row
->glyphs
[area
];
24102 glyph
->charpos
= CHARPOS (it
->position
);
24103 glyph
->object
= object
;
24104 glyph
->pixel_width
= width
;
24105 glyph
->ascent
= ascent
;
24106 glyph
->descent
= height
- ascent
;
24107 glyph
->voffset
= it
->voffset
;
24108 glyph
->type
= STRETCH_GLYPH
;
24109 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24110 glyph
->multibyte_p
= it
->multibyte_p
;
24111 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24113 /* In R2L rows, the left and the right box edges need to be
24114 drawn in reverse direction. */
24115 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24116 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24120 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24121 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24123 glyph
->overlaps_vertically_p
= 0;
24124 glyph
->padding_p
= 0;
24125 glyph
->glyph_not_available_p
= 0;
24126 glyph
->face_id
= it
->face_id
;
24127 glyph
->u
.stretch
.ascent
= ascent
;
24128 glyph
->u
.stretch
.height
= height
;
24129 glyph
->slice
.img
= null_glyph_slice
;
24130 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24133 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24134 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24136 glyph
->bidi_type
= it
->bidi_it
.type
;
24140 glyph
->resolved_level
= 0;
24141 glyph
->bidi_type
= UNKNOWN_BT
;
24143 ++it
->glyph_row
->used
[area
];
24146 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24149 #endif /* HAVE_WINDOW_SYSTEM */
24151 /* Produce a stretch glyph for iterator IT. IT->object is the value
24152 of the glyph property displayed. The value must be a list
24153 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24156 1. `:width WIDTH' specifies that the space should be WIDTH *
24157 canonical char width wide. WIDTH may be an integer or floating
24160 2. `:relative-width FACTOR' specifies that the width of the stretch
24161 should be computed from the width of the first character having the
24162 `glyph' property, and should be FACTOR times that width.
24164 3. `:align-to HPOS' specifies that the space should be wide enough
24165 to reach HPOS, a value in canonical character units.
24167 Exactly one of the above pairs must be present.
24169 4. `:height HEIGHT' specifies that the height of the stretch produced
24170 should be HEIGHT, measured in canonical character units.
24172 5. `:relative-height FACTOR' specifies that the height of the
24173 stretch should be FACTOR times the height of the characters having
24174 the glyph property.
24176 Either none or exactly one of 4 or 5 must be present.
24178 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24179 of the stretch should be used for the ascent of the stretch.
24180 ASCENT must be in the range 0 <= ASCENT <= 100. */
24183 produce_stretch_glyph (struct it
*it
)
24185 /* (space :width WIDTH :height HEIGHT ...) */
24186 Lisp_Object prop
, plist
;
24187 int width
= 0, height
= 0, align_to
= -1;
24188 int zero_width_ok_p
= 0;
24190 struct font
*font
= NULL
;
24192 #ifdef HAVE_WINDOW_SYSTEM
24194 int zero_height_ok_p
= 0;
24196 if (FRAME_WINDOW_P (it
->f
))
24198 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24199 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24200 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24204 /* List should start with `space'. */
24205 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24206 plist
= XCDR (it
->object
);
24208 /* Compute the width of the stretch. */
24209 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24210 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24212 /* Absolute width `:width WIDTH' specified and valid. */
24213 zero_width_ok_p
= 1;
24216 #ifdef HAVE_WINDOW_SYSTEM
24217 else if (FRAME_WINDOW_P (it
->f
)
24218 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24220 /* Relative width `:relative-width FACTOR' specified and valid.
24221 Compute the width of the characters having the `glyph'
24224 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24227 if (it
->multibyte_p
)
24228 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24231 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24232 if (! ASCII_CHAR_P (it2
.c
))
24233 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24236 it2
.glyph_row
= NULL
;
24237 it2
.what
= IT_CHARACTER
;
24238 x_produce_glyphs (&it2
);
24239 width
= NUMVAL (prop
) * it2
.pixel_width
;
24241 #endif /* HAVE_WINDOW_SYSTEM */
24242 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24243 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24245 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24246 align_to
= (align_to
< 0
24248 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24249 else if (align_to
< 0)
24250 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24251 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24252 zero_width_ok_p
= 1;
24255 /* Nothing specified -> width defaults to canonical char width. */
24256 width
= FRAME_COLUMN_WIDTH (it
->f
);
24258 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24261 #ifdef HAVE_WINDOW_SYSTEM
24262 /* Compute height. */
24263 if (FRAME_WINDOW_P (it
->f
))
24265 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24266 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24269 zero_height_ok_p
= 1;
24271 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24273 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24275 height
= FONT_HEIGHT (font
);
24277 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24280 /* Compute percentage of height used for ascent. If
24281 `:ascent ASCENT' is present and valid, use that. Otherwise,
24282 derive the ascent from the font in use. */
24283 if (prop
= Fplist_get (plist
, QCascent
),
24284 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24285 ascent
= height
* NUMVAL (prop
) / 100.0;
24286 else if (!NILP (prop
)
24287 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24288 ascent
= min (max (0, (int)tem
), height
);
24290 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24293 #endif /* HAVE_WINDOW_SYSTEM */
24296 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24297 && it
->current_x
+ width
> it
->last_visible_x
)
24299 width
= it
->last_visible_x
- it
->current_x
;
24300 #ifdef HAVE_WINDOW_SYSTEM
24301 /* Subtract one more pixel from the stretch width, but only on
24302 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24303 width
-= FRAME_WINDOW_P (it
->f
);
24307 if (width
> 0 && height
> 0 && it
->glyph_row
)
24309 Lisp_Object o_object
= it
->object
;
24310 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24313 if (!STRINGP (object
))
24314 object
= it
->w
->buffer
;
24315 #ifdef HAVE_WINDOW_SYSTEM
24316 if (FRAME_WINDOW_P (it
->f
))
24317 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24321 it
->object
= object
;
24322 it
->char_to_display
= ' ';
24323 it
->pixel_width
= it
->len
= 1;
24325 tty_append_glyph (it
);
24326 it
->object
= o_object
;
24330 it
->pixel_width
= width
;
24331 #ifdef HAVE_WINDOW_SYSTEM
24332 if (FRAME_WINDOW_P (it
->f
))
24334 it
->ascent
= it
->phys_ascent
= ascent
;
24335 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24336 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24337 take_vertical_position_into_account (it
);
24341 it
->nglyphs
= width
;
24344 /* Get information about special display element WHAT in an
24345 environment described by IT. WHAT is one of IT_TRUNCATION or
24346 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24347 non-null glyph_row member. This function ensures that fields like
24348 face_id, c, len of IT are left untouched. */
24351 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24358 temp_it
.object
= make_number (0);
24359 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24361 if (what
== IT_CONTINUATION
)
24363 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24364 if (it
->bidi_it
.paragraph_dir
== R2L
)
24365 SET_GLYPH_FROM_CHAR (glyph
, '/');
24367 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24369 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24371 /* FIXME: Should we mirror GC for R2L lines? */
24372 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24373 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24376 else if (what
== IT_TRUNCATION
)
24378 /* Truncation glyph. */
24379 SET_GLYPH_FROM_CHAR (glyph
, '$');
24381 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24383 /* FIXME: Should we mirror GC for R2L lines? */
24384 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24385 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24391 #ifdef HAVE_WINDOW_SYSTEM
24392 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24393 is turned off, we precede the truncation/continuation glyphs by a
24394 stretch glyph whose width is computed such that these special
24395 glyphs are aligned at the window margin, even when very different
24396 fonts are used in different glyph rows. */
24397 if (FRAME_WINDOW_P (temp_it
.f
)
24398 /* init_iterator calls this with it->glyph_row == NULL, and it
24399 wants only the pixel width of the truncation/continuation
24401 && temp_it
.glyph_row
24402 /* insert_left_trunc_glyphs calls us at the beginning of the
24403 row, and it has its own calculation of the stretch glyph
24405 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24406 && (temp_it
.glyph_row
->reversed_p
24407 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24408 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24410 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24412 if (stretch_width
> 0)
24414 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24415 struct font
*font
=
24416 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24417 int stretch_ascent
=
24418 (((temp_it
.ascent
+ temp_it
.descent
)
24419 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24421 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24422 temp_it
.ascent
+ temp_it
.descent
,
24429 temp_it
.what
= IT_CHARACTER
;
24431 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24432 temp_it
.face_id
= GLYPH_FACE (glyph
);
24433 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24435 PRODUCE_GLYPHS (&temp_it
);
24436 it
->pixel_width
= temp_it
.pixel_width
;
24437 it
->nglyphs
= temp_it
.pixel_width
;
24440 #ifdef HAVE_WINDOW_SYSTEM
24442 /* Calculate line-height and line-spacing properties.
24443 An integer value specifies explicit pixel value.
24444 A float value specifies relative value to current face height.
24445 A cons (float . face-name) specifies relative value to
24446 height of specified face font.
24448 Returns height in pixels, or nil. */
24452 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24453 int boff
, int override
)
24455 Lisp_Object face_name
= Qnil
;
24456 int ascent
, descent
, height
;
24458 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24463 face_name
= XCAR (val
);
24465 if (!NUMBERP (val
))
24466 val
= make_number (1);
24467 if (NILP (face_name
))
24469 height
= it
->ascent
+ it
->descent
;
24474 if (NILP (face_name
))
24476 font
= FRAME_FONT (it
->f
);
24477 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24479 else if (EQ (face_name
, Qt
))
24488 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24490 return make_number (-1);
24492 face
= FACE_FROM_ID (it
->f
, face_id
);
24495 return make_number (-1);
24496 boff
= font
->baseline_offset
;
24497 if (font
->vertical_centering
)
24498 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24501 ascent
= FONT_BASE (font
) + boff
;
24502 descent
= FONT_DESCENT (font
) - boff
;
24506 it
->override_ascent
= ascent
;
24507 it
->override_descent
= descent
;
24508 it
->override_boff
= boff
;
24511 height
= ascent
+ descent
;
24515 height
= (int)(XFLOAT_DATA (val
) * height
);
24516 else if (INTEGERP (val
))
24517 height
*= XINT (val
);
24519 return make_number (height
);
24523 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24524 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24525 and only if this is for a character for which no font was found.
24527 If the display method (it->glyphless_method) is
24528 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24529 length of the acronym or the hexadecimal string, UPPER_XOFF and
24530 UPPER_YOFF are pixel offsets for the upper part of the string,
24531 LOWER_XOFF and LOWER_YOFF are for the lower part.
24533 For the other display methods, LEN through LOWER_YOFF are zero. */
24536 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24537 short upper_xoff
, short upper_yoff
,
24538 short lower_xoff
, short lower_yoff
)
24540 struct glyph
*glyph
;
24541 enum glyph_row_area area
= it
->area
;
24543 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24544 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24546 /* If the glyph row is reversed, we need to prepend the glyph
24547 rather than append it. */
24548 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24552 /* Make room for the additional glyph. */
24553 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24555 glyph
= it
->glyph_row
->glyphs
[area
];
24557 glyph
->charpos
= CHARPOS (it
->position
);
24558 glyph
->object
= it
->object
;
24559 glyph
->pixel_width
= it
->pixel_width
;
24560 glyph
->ascent
= it
->ascent
;
24561 glyph
->descent
= it
->descent
;
24562 glyph
->voffset
= it
->voffset
;
24563 glyph
->type
= GLYPHLESS_GLYPH
;
24564 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24565 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24566 glyph
->u
.glyphless
.len
= len
;
24567 glyph
->u
.glyphless
.ch
= it
->c
;
24568 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24569 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24570 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24571 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24572 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24573 glyph
->multibyte_p
= it
->multibyte_p
;
24574 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24576 /* In R2L rows, the left and the right box edges need to be
24577 drawn in reverse direction. */
24578 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24579 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24583 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24584 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24586 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24587 || it
->phys_descent
> it
->descent
);
24588 glyph
->padding_p
= 0;
24589 glyph
->glyph_not_available_p
= 0;
24590 glyph
->face_id
= face_id
;
24591 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24594 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24595 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24597 glyph
->bidi_type
= it
->bidi_it
.type
;
24599 ++it
->glyph_row
->used
[area
];
24602 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24606 /* Produce a glyph for a glyphless character for iterator IT.
24607 IT->glyphless_method specifies which method to use for displaying
24608 the character. See the description of enum
24609 glyphless_display_method in dispextern.h for the detail.
24611 FOR_NO_FONT is nonzero if and only if this is for a character for
24612 which no font was found. ACRONYM, if non-nil, is an acronym string
24613 for the character. */
24616 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24621 int base_width
, base_height
, width
, height
;
24622 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24625 /* Get the metrics of the base font. We always refer to the current
24627 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24628 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24629 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24630 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24631 base_height
= it
->ascent
+ it
->descent
;
24632 base_width
= font
->average_width
;
24634 /* Get a face ID for the glyph by utilizing a cache (the same way as
24635 done for `escape-glyph' in get_next_display_element). */
24636 if (it
->f
== last_glyphless_glyph_frame
24637 && it
->face_id
== last_glyphless_glyph_face_id
)
24639 face_id
= last_glyphless_glyph_merged_face_id
;
24643 /* Merge the `glyphless-char' face into the current face. */
24644 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24645 last_glyphless_glyph_frame
= it
->f
;
24646 last_glyphless_glyph_face_id
= it
->face_id
;
24647 last_glyphless_glyph_merged_face_id
= face_id
;
24650 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24652 it
->pixel_width
= THIN_SPACE_WIDTH
;
24654 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24656 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24658 width
= CHAR_WIDTH (it
->c
);
24661 else if (width
> 4)
24663 it
->pixel_width
= base_width
* width
;
24665 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24671 unsigned int code
[6];
24673 int ascent
, descent
;
24674 struct font_metrics metrics_upper
, metrics_lower
;
24676 face
= FACE_FROM_ID (it
->f
, face_id
);
24677 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24678 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24680 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24682 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24683 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24684 if (CONSP (acronym
))
24685 acronym
= XCAR (acronym
);
24686 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24690 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24691 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24694 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24695 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24696 upper_len
= (len
+ 1) / 2;
24697 font
->driver
->text_extents (font
, code
, upper_len
,
24699 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24704 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24705 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24706 upper_xoff
= upper_yoff
= 2; /* the typical case */
24707 if (base_width
>= width
)
24709 /* Align the upper to the left, the lower to the right. */
24710 it
->pixel_width
= base_width
;
24711 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24715 /* Center the shorter one. */
24716 it
->pixel_width
= width
;
24717 if (metrics_upper
.width
>= metrics_lower
.width
)
24718 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24721 /* FIXME: This code doesn't look right. It formerly was
24722 missing the "lower_xoff = 0;", which couldn't have
24723 been right since it left lower_xoff uninitialized. */
24725 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24729 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24730 top, bottom, and between upper and lower strings. */
24731 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24732 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24733 /* Center vertically.
24734 H:base_height, D:base_descent
24735 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24737 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24738 descent = D - H/2 + h/2;
24739 lower_yoff = descent - 2 - ld;
24740 upper_yoff = lower_yoff - la - 1 - ud; */
24741 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
24742 descent
= it
->descent
- (base_height
- height
) / 2;
24743 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
24744 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
24745 - metrics_upper
.descent
);
24746 /* Don't make the height shorter than the base height. */
24747 if (height
> base_height
)
24749 it
->ascent
= ascent
;
24750 it
->descent
= descent
;
24754 it
->phys_ascent
= it
->ascent
;
24755 it
->phys_descent
= it
->descent
;
24757 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
24758 upper_xoff
, upper_yoff
,
24759 lower_xoff
, lower_yoff
);
24761 take_vertical_position_into_account (it
);
24766 Produce glyphs/get display metrics for the display element IT is
24767 loaded with. See the description of struct it in dispextern.h
24768 for an overview of struct it. */
24771 x_produce_glyphs (struct it
*it
)
24773 int extra_line_spacing
= it
->extra_line_spacing
;
24775 it
->glyph_not_available_p
= 0;
24777 if (it
->what
== IT_CHARACTER
)
24780 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24781 struct font
*font
= face
->font
;
24782 struct font_metrics
*pcm
= NULL
;
24783 int boff
; /* baseline offset */
24787 /* When no suitable font is found, display this character by
24788 the method specified in the first extra slot of
24789 Vglyphless_char_display. */
24790 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
24792 eassert (it
->what
== IT_GLYPHLESS
);
24793 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
24797 boff
= font
->baseline_offset
;
24798 if (font
->vertical_centering
)
24799 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24801 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
24807 if (it
->override_ascent
>= 0)
24809 it
->ascent
= it
->override_ascent
;
24810 it
->descent
= it
->override_descent
;
24811 boff
= it
->override_boff
;
24815 it
->ascent
= FONT_BASE (font
) + boff
;
24816 it
->descent
= FONT_DESCENT (font
) - boff
;
24819 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
24821 pcm
= get_per_char_metric (font
, &char2b
);
24822 if (pcm
->width
== 0
24823 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
24829 it
->phys_ascent
= pcm
->ascent
+ boff
;
24830 it
->phys_descent
= pcm
->descent
- boff
;
24831 it
->pixel_width
= pcm
->width
;
24835 it
->glyph_not_available_p
= 1;
24836 it
->phys_ascent
= it
->ascent
;
24837 it
->phys_descent
= it
->descent
;
24838 it
->pixel_width
= font
->space_width
;
24841 if (it
->constrain_row_ascent_descent_p
)
24843 if (it
->descent
> it
->max_descent
)
24845 it
->ascent
+= it
->descent
- it
->max_descent
;
24846 it
->descent
= it
->max_descent
;
24848 if (it
->ascent
> it
->max_ascent
)
24850 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24851 it
->ascent
= it
->max_ascent
;
24853 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24854 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24855 extra_line_spacing
= 0;
24858 /* If this is a space inside a region of text with
24859 `space-width' property, change its width. */
24860 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
24862 it
->pixel_width
*= XFLOATINT (it
->space_width
);
24864 /* If face has a box, add the box thickness to the character
24865 height. If character has a box line to the left and/or
24866 right, add the box line width to the character's width. */
24867 if (face
->box
!= FACE_NO_BOX
)
24869 int thick
= face
->box_line_width
;
24873 it
->ascent
+= thick
;
24874 it
->descent
+= thick
;
24879 if (it
->start_of_box_run_p
)
24880 it
->pixel_width
+= thick
;
24881 if (it
->end_of_box_run_p
)
24882 it
->pixel_width
+= thick
;
24885 /* If face has an overline, add the height of the overline
24886 (1 pixel) and a 1 pixel margin to the character height. */
24887 if (face
->overline_p
)
24888 it
->ascent
+= overline_margin
;
24890 if (it
->constrain_row_ascent_descent_p
)
24892 if (it
->ascent
> it
->max_ascent
)
24893 it
->ascent
= it
->max_ascent
;
24894 if (it
->descent
> it
->max_descent
)
24895 it
->descent
= it
->max_descent
;
24898 take_vertical_position_into_account (it
);
24900 /* If we have to actually produce glyphs, do it. */
24905 /* Translate a space with a `space-width' property
24906 into a stretch glyph. */
24907 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
24908 / FONT_HEIGHT (font
));
24909 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
24910 it
->ascent
+ it
->descent
, ascent
);
24915 /* If characters with lbearing or rbearing are displayed
24916 in this line, record that fact in a flag of the
24917 glyph row. This is used to optimize X output code. */
24918 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
24919 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
24921 if (! stretched_p
&& it
->pixel_width
== 0)
24922 /* We assure that all visible glyphs have at least 1-pixel
24924 it
->pixel_width
= 1;
24926 else if (it
->char_to_display
== '\n')
24928 /* A newline has no width, but we need the height of the
24929 line. But if previous part of the line sets a height,
24930 don't increase that height */
24932 Lisp_Object height
;
24933 Lisp_Object total_height
= Qnil
;
24935 it
->override_ascent
= -1;
24936 it
->pixel_width
= 0;
24939 height
= get_it_property (it
, Qline_height
);
24940 /* Split (line-height total-height) list */
24942 && CONSP (XCDR (height
))
24943 && NILP (XCDR (XCDR (height
))))
24945 total_height
= XCAR (XCDR (height
));
24946 height
= XCAR (height
);
24948 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
24950 if (it
->override_ascent
>= 0)
24952 it
->ascent
= it
->override_ascent
;
24953 it
->descent
= it
->override_descent
;
24954 boff
= it
->override_boff
;
24958 it
->ascent
= FONT_BASE (font
) + boff
;
24959 it
->descent
= FONT_DESCENT (font
) - boff
;
24962 if (EQ (height
, Qt
))
24964 if (it
->descent
> it
->max_descent
)
24966 it
->ascent
+= it
->descent
- it
->max_descent
;
24967 it
->descent
= it
->max_descent
;
24969 if (it
->ascent
> it
->max_ascent
)
24971 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
24972 it
->ascent
= it
->max_ascent
;
24974 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
24975 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
24976 it
->constrain_row_ascent_descent_p
= 1;
24977 extra_line_spacing
= 0;
24981 Lisp_Object spacing
;
24983 it
->phys_ascent
= it
->ascent
;
24984 it
->phys_descent
= it
->descent
;
24986 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
24987 && face
->box
!= FACE_NO_BOX
24988 && face
->box_line_width
> 0)
24990 it
->ascent
+= face
->box_line_width
;
24991 it
->descent
+= face
->box_line_width
;
24994 && XINT (height
) > it
->ascent
+ it
->descent
)
24995 it
->ascent
= XINT (height
) - it
->descent
;
24997 if (!NILP (total_height
))
24998 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25001 spacing
= get_it_property (it
, Qline_spacing
);
25002 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25004 if (INTEGERP (spacing
))
25006 extra_line_spacing
= XINT (spacing
);
25007 if (!NILP (total_height
))
25008 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25012 else /* i.e. (it->char_to_display == '\t') */
25014 if (font
->space_width
> 0)
25016 int tab_width
= it
->tab_width
* font
->space_width
;
25017 int x
= it
->current_x
+ it
->continuation_lines_width
;
25018 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25020 /* If the distance from the current position to the next tab
25021 stop is less than a space character width, use the
25022 tab stop after that. */
25023 if (next_tab_x
- x
< font
->space_width
)
25024 next_tab_x
+= tab_width
;
25026 it
->pixel_width
= next_tab_x
- x
;
25028 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25029 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25033 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25034 it
->ascent
+ it
->descent
, it
->ascent
);
25039 it
->pixel_width
= 0;
25044 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25046 /* A static composition.
25048 Note: A composition is represented as one glyph in the
25049 glyph matrix. There are no padding glyphs.
25051 Important note: pixel_width, ascent, and descent are the
25052 values of what is drawn by draw_glyphs (i.e. the values of
25053 the overall glyphs composed). */
25054 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25055 int boff
; /* baseline offset */
25056 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25057 int glyph_len
= cmp
->glyph_len
;
25058 struct font
*font
= face
->font
;
25062 /* If we have not yet calculated pixel size data of glyphs of
25063 the composition for the current face font, calculate them
25064 now. Theoretically, we have to check all fonts for the
25065 glyphs, but that requires much time and memory space. So,
25066 here we check only the font of the first glyph. This may
25067 lead to incorrect display, but it's very rare, and C-l
25068 (recenter-top-bottom) can correct the display anyway. */
25069 if (! cmp
->font
|| cmp
->font
!= font
)
25071 /* Ascent and descent of the font of the first character
25072 of this composition (adjusted by baseline offset).
25073 Ascent and descent of overall glyphs should not be less
25074 than these, respectively. */
25075 int font_ascent
, font_descent
, font_height
;
25076 /* Bounding box of the overall glyphs. */
25077 int leftmost
, rightmost
, lowest
, highest
;
25078 int lbearing
, rbearing
;
25079 int i
, width
, ascent
, descent
;
25080 int left_padded
= 0, right_padded
= 0;
25081 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25083 struct font_metrics
*pcm
;
25084 int font_not_found_p
;
25087 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25088 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25090 if (glyph_len
< cmp
->glyph_len
)
25092 for (i
= 0; i
< glyph_len
; i
++)
25094 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25096 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25101 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25102 : IT_CHARPOS (*it
));
25103 /* If no suitable font is found, use the default font. */
25104 font_not_found_p
= font
== NULL
;
25105 if (font_not_found_p
)
25107 face
= face
->ascii_face
;
25110 boff
= font
->baseline_offset
;
25111 if (font
->vertical_centering
)
25112 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25113 font_ascent
= FONT_BASE (font
) + boff
;
25114 font_descent
= FONT_DESCENT (font
) - boff
;
25115 font_height
= FONT_HEIGHT (font
);
25120 if (! font_not_found_p
)
25122 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25124 pcm
= get_per_char_metric (font
, &char2b
);
25127 /* Initialize the bounding box. */
25130 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25131 ascent
= pcm
->ascent
;
25132 descent
= pcm
->descent
;
25133 lbearing
= pcm
->lbearing
;
25134 rbearing
= pcm
->rbearing
;
25138 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25139 ascent
= FONT_BASE (font
);
25140 descent
= FONT_DESCENT (font
);
25147 lowest
= - descent
+ boff
;
25148 highest
= ascent
+ boff
;
25150 if (! font_not_found_p
25151 && font
->default_ascent
25152 && CHAR_TABLE_P (Vuse_default_ascent
)
25153 && !NILP (Faref (Vuse_default_ascent
,
25154 make_number (it
->char_to_display
))))
25155 highest
= font
->default_ascent
+ boff
;
25157 /* Draw the first glyph at the normal position. It may be
25158 shifted to right later if some other glyphs are drawn
25160 cmp
->offsets
[i
* 2] = 0;
25161 cmp
->offsets
[i
* 2 + 1] = boff
;
25162 cmp
->lbearing
= lbearing
;
25163 cmp
->rbearing
= rbearing
;
25165 /* Set cmp->offsets for the remaining glyphs. */
25166 for (i
++; i
< glyph_len
; i
++)
25168 int left
, right
, btm
, top
;
25169 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25171 struct face
*this_face
;
25175 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25176 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25177 font
= this_face
->font
;
25183 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25185 pcm
= get_per_char_metric (font
, &char2b
);
25188 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25191 width
= pcm
->width
;
25192 ascent
= pcm
->ascent
;
25193 descent
= pcm
->descent
;
25194 lbearing
= pcm
->lbearing
;
25195 rbearing
= pcm
->rbearing
;
25196 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25198 /* Relative composition with or without
25199 alternate chars. */
25200 left
= (leftmost
+ rightmost
- width
) / 2;
25201 btm
= - descent
+ boff
;
25202 if (font
->relative_compose
25203 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25204 || NILP (Faref (Vignore_relative_composition
,
25205 make_number (ch
)))))
25208 if (- descent
>= font
->relative_compose
)
25209 /* One extra pixel between two glyphs. */
25211 else if (ascent
<= 0)
25212 /* One extra pixel between two glyphs. */
25213 btm
= lowest
- 1 - ascent
- descent
;
25218 /* A composition rule is specified by an integer
25219 value that encodes global and new reference
25220 points (GREF and NREF). GREF and NREF are
25221 specified by numbers as below:
25223 0---1---2 -- ascent
25227 9--10--11 -- center
25229 ---3---4---5--- baseline
25231 6---7---8 -- descent
25233 int rule
= COMPOSITION_RULE (cmp
, i
);
25234 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25236 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25237 grefx
= gref
% 3, nrefx
= nref
% 3;
25238 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25240 xoff
= font_height
* (xoff
- 128) / 256;
25242 yoff
= font_height
* (yoff
- 128) / 256;
25245 + grefx
* (rightmost
- leftmost
) / 2
25246 - nrefx
* width
/ 2
25249 btm
= ((grefy
== 0 ? highest
25251 : grefy
== 2 ? lowest
25252 : (highest
+ lowest
) / 2)
25253 - (nrefy
== 0 ? ascent
+ descent
25254 : nrefy
== 1 ? descent
- boff
25256 : (ascent
+ descent
) / 2)
25260 cmp
->offsets
[i
* 2] = left
;
25261 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25263 /* Update the bounding box of the overall glyphs. */
25266 right
= left
+ width
;
25267 if (left
< leftmost
)
25269 if (right
> rightmost
)
25272 top
= btm
+ descent
+ ascent
;
25278 if (cmp
->lbearing
> left
+ lbearing
)
25279 cmp
->lbearing
= left
+ lbearing
;
25280 if (cmp
->rbearing
< left
+ rbearing
)
25281 cmp
->rbearing
= left
+ rbearing
;
25285 /* If there are glyphs whose x-offsets are negative,
25286 shift all glyphs to the right and make all x-offsets
25290 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25291 cmp
->offsets
[i
* 2] -= leftmost
;
25292 rightmost
-= leftmost
;
25293 cmp
->lbearing
-= leftmost
;
25294 cmp
->rbearing
-= leftmost
;
25297 if (left_padded
&& cmp
->lbearing
< 0)
25299 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25300 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25301 rightmost
-= cmp
->lbearing
;
25302 cmp
->rbearing
-= cmp
->lbearing
;
25305 if (right_padded
&& rightmost
< cmp
->rbearing
)
25307 rightmost
= cmp
->rbearing
;
25310 cmp
->pixel_width
= rightmost
;
25311 cmp
->ascent
= highest
;
25312 cmp
->descent
= - lowest
;
25313 if (cmp
->ascent
< font_ascent
)
25314 cmp
->ascent
= font_ascent
;
25315 if (cmp
->descent
< font_descent
)
25316 cmp
->descent
= font_descent
;
25320 && (cmp
->lbearing
< 0
25321 || cmp
->rbearing
> cmp
->pixel_width
))
25322 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25324 it
->pixel_width
= cmp
->pixel_width
;
25325 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25326 it
->descent
= it
->phys_descent
= cmp
->descent
;
25327 if (face
->box
!= FACE_NO_BOX
)
25329 int thick
= face
->box_line_width
;
25333 it
->ascent
+= thick
;
25334 it
->descent
+= thick
;
25339 if (it
->start_of_box_run_p
)
25340 it
->pixel_width
+= thick
;
25341 if (it
->end_of_box_run_p
)
25342 it
->pixel_width
+= thick
;
25345 /* If face has an overline, add the height of the overline
25346 (1 pixel) and a 1 pixel margin to the character height. */
25347 if (face
->overline_p
)
25348 it
->ascent
+= overline_margin
;
25350 take_vertical_position_into_account (it
);
25351 if (it
->ascent
< 0)
25353 if (it
->descent
< 0)
25356 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25357 append_composite_glyph (it
);
25359 else if (it
->what
== IT_COMPOSITION
)
25361 /* A dynamic (automatic) composition. */
25362 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25363 Lisp_Object gstring
;
25364 struct font_metrics metrics
;
25368 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25370 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25373 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25374 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25375 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25376 it
->descent
= it
->phys_descent
= metrics
.descent
;
25377 if (face
->box
!= FACE_NO_BOX
)
25379 int thick
= face
->box_line_width
;
25383 it
->ascent
+= thick
;
25384 it
->descent
+= thick
;
25389 if (it
->start_of_box_run_p
)
25390 it
->pixel_width
+= thick
;
25391 if (it
->end_of_box_run_p
)
25392 it
->pixel_width
+= thick
;
25394 /* If face has an overline, add the height of the overline
25395 (1 pixel) and a 1 pixel margin to the character height. */
25396 if (face
->overline_p
)
25397 it
->ascent
+= overline_margin
;
25398 take_vertical_position_into_account (it
);
25399 if (it
->ascent
< 0)
25401 if (it
->descent
< 0)
25405 append_composite_glyph (it
);
25407 else if (it
->what
== IT_GLYPHLESS
)
25408 produce_glyphless_glyph (it
, 0, Qnil
);
25409 else if (it
->what
== IT_IMAGE
)
25410 produce_image_glyph (it
);
25411 else if (it
->what
== IT_STRETCH
)
25412 produce_stretch_glyph (it
);
25415 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25416 because this isn't true for images with `:ascent 100'. */
25417 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25418 if (it
->area
== TEXT_AREA
)
25419 it
->current_x
+= it
->pixel_width
;
25421 if (extra_line_spacing
> 0)
25423 it
->descent
+= extra_line_spacing
;
25424 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25425 it
->max_extra_line_spacing
= extra_line_spacing
;
25428 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25429 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25430 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25431 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25435 Output LEN glyphs starting at START at the nominal cursor position.
25436 Advance the nominal cursor over the text. The global variable
25437 updated_window contains the window being updated, updated_row is
25438 the glyph row being updated, and updated_area is the area of that
25439 row being updated. */
25442 x_write_glyphs (struct glyph
*start
, int len
)
25444 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25446 eassert (updated_window
&& updated_row
);
25447 /* When the window is hscrolled, cursor hpos can legitimately be out
25448 of bounds, but we draw the cursor at the corresponding window
25449 margin in that case. */
25450 if (!updated_row
->reversed_p
&& chpos
< 0)
25452 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25453 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25457 /* Write glyphs. */
25459 hpos
= start
- updated_row
->glyphs
[updated_area
];
25460 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25461 updated_row
, updated_area
,
25463 DRAW_NORMAL_TEXT
, 0);
25465 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25466 if (updated_area
== TEXT_AREA
25467 && updated_window
->phys_cursor_on_p
25468 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25470 && chpos
< hpos
+ len
)
25471 updated_window
->phys_cursor_on_p
= 0;
25475 /* Advance the output cursor. */
25476 output_cursor
.hpos
+= len
;
25477 output_cursor
.x
= x
;
25482 Insert LEN glyphs from START at the nominal cursor position. */
25485 x_insert_glyphs (struct glyph
*start
, int len
)
25489 int line_height
, shift_by_width
, shifted_region_width
;
25490 struct glyph_row
*row
;
25491 struct glyph
*glyph
;
25492 int frame_x
, frame_y
;
25495 eassert (updated_window
&& updated_row
);
25497 w
= updated_window
;
25498 f
= XFRAME (WINDOW_FRAME (w
));
25500 /* Get the height of the line we are in. */
25502 line_height
= row
->height
;
25504 /* Get the width of the glyphs to insert. */
25505 shift_by_width
= 0;
25506 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25507 shift_by_width
+= glyph
->pixel_width
;
25509 /* Get the width of the region to shift right. */
25510 shifted_region_width
= (window_box_width (w
, updated_area
)
25515 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25516 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25518 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25519 line_height
, shift_by_width
);
25521 /* Write the glyphs. */
25522 hpos
= start
- row
->glyphs
[updated_area
];
25523 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25525 DRAW_NORMAL_TEXT
, 0);
25527 /* Advance the output cursor. */
25528 output_cursor
.hpos
+= len
;
25529 output_cursor
.x
+= shift_by_width
;
25535 Erase the current text line from the nominal cursor position
25536 (inclusive) to pixel column TO_X (exclusive). The idea is that
25537 everything from TO_X onward is already erased.
25539 TO_X is a pixel position relative to updated_area of
25540 updated_window. TO_X == -1 means clear to the end of this area. */
25543 x_clear_end_of_line (int to_x
)
25546 struct window
*w
= updated_window
;
25547 int max_x
, min_y
, max_y
;
25548 int from_x
, from_y
, to_y
;
25550 eassert (updated_window
&& updated_row
);
25551 f
= XFRAME (w
->frame
);
25553 if (updated_row
->full_width_p
)
25554 max_x
= WINDOW_TOTAL_WIDTH (w
);
25556 max_x
= window_box_width (w
, updated_area
);
25557 max_y
= window_text_bottom_y (w
);
25559 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25560 of window. For TO_X > 0, truncate to end of drawing area. */
25566 to_x
= min (to_x
, max_x
);
25568 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25570 /* Notice if the cursor will be cleared by this operation. */
25571 if (!updated_row
->full_width_p
)
25572 notice_overwritten_cursor (w
, updated_area
,
25573 output_cursor
.x
, -1,
25575 MATRIX_ROW_BOTTOM_Y (updated_row
));
25577 from_x
= output_cursor
.x
;
25579 /* Translate to frame coordinates. */
25580 if (updated_row
->full_width_p
)
25582 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25583 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25587 int area_left
= window_box_left (w
, updated_area
);
25588 from_x
+= area_left
;
25592 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25593 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25594 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25596 /* Prevent inadvertently clearing to end of the X window. */
25597 if (to_x
> from_x
&& to_y
> from_y
)
25600 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25601 to_x
- from_x
, to_y
- from_y
);
25606 #endif /* HAVE_WINDOW_SYSTEM */
25610 /***********************************************************************
25612 ***********************************************************************/
25614 /* Value is the internal representation of the specified cursor type
25615 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25616 of the bar cursor. */
25618 static enum text_cursor_kinds
25619 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25621 enum text_cursor_kinds type
;
25626 if (EQ (arg
, Qbox
))
25627 return FILLED_BOX_CURSOR
;
25629 if (EQ (arg
, Qhollow
))
25630 return HOLLOW_BOX_CURSOR
;
25632 if (EQ (arg
, Qbar
))
25639 && EQ (XCAR (arg
), Qbar
)
25640 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25642 *width
= XINT (XCDR (arg
));
25646 if (EQ (arg
, Qhbar
))
25649 return HBAR_CURSOR
;
25653 && EQ (XCAR (arg
), Qhbar
)
25654 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25656 *width
= XINT (XCDR (arg
));
25657 return HBAR_CURSOR
;
25660 /* Treat anything unknown as "hollow box cursor".
25661 It was bad to signal an error; people have trouble fixing
25662 .Xdefaults with Emacs, when it has something bad in it. */
25663 type
= HOLLOW_BOX_CURSOR
;
25668 /* Set the default cursor types for specified frame. */
25670 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25675 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25676 FRAME_CURSOR_WIDTH (f
) = width
;
25678 /* By default, set up the blink-off state depending on the on-state. */
25680 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25683 FRAME_BLINK_OFF_CURSOR (f
)
25684 = get_specified_cursor_type (XCDR (tem
), &width
);
25685 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25688 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25692 #ifdef HAVE_WINDOW_SYSTEM
25694 /* Return the cursor we want to be displayed in window W. Return
25695 width of bar/hbar cursor through WIDTH arg. Return with
25696 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25697 (i.e. if the `system caret' should track this cursor).
25699 In a mini-buffer window, we want the cursor only to appear if we
25700 are reading input from this window. For the selected window, we
25701 want the cursor type given by the frame parameter or buffer local
25702 setting of cursor-type. If explicitly marked off, draw no cursor.
25703 In all other cases, we want a hollow box cursor. */
25705 static enum text_cursor_kinds
25706 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25707 int *active_cursor
)
25709 struct frame
*f
= XFRAME (w
->frame
);
25710 struct buffer
*b
= XBUFFER (w
->buffer
);
25711 int cursor_type
= DEFAULT_CURSOR
;
25712 Lisp_Object alt_cursor
;
25713 int non_selected
= 0;
25715 *active_cursor
= 1;
25718 if (cursor_in_echo_area
25719 && FRAME_HAS_MINIBUF_P (f
)
25720 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25722 if (w
== XWINDOW (echo_area_window
))
25724 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25726 *width
= FRAME_CURSOR_WIDTH (f
);
25727 return FRAME_DESIRED_CURSOR (f
);
25730 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25733 *active_cursor
= 0;
25737 /* Detect a nonselected window or nonselected frame. */
25738 else if (w
!= XWINDOW (f
->selected_window
)
25739 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
25741 *active_cursor
= 0;
25743 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
25749 /* Never display a cursor in a window in which cursor-type is nil. */
25750 if (NILP (BVAR (b
, cursor_type
)))
25753 /* Get the normal cursor type for this window. */
25754 if (EQ (BVAR (b
, cursor_type
), Qt
))
25756 cursor_type
= FRAME_DESIRED_CURSOR (f
);
25757 *width
= FRAME_CURSOR_WIDTH (f
);
25760 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25762 /* Use cursor-in-non-selected-windows instead
25763 for non-selected window or frame. */
25766 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
25767 if (!EQ (Qt
, alt_cursor
))
25768 return get_specified_cursor_type (alt_cursor
, width
);
25769 /* t means modify the normal cursor type. */
25770 if (cursor_type
== FILLED_BOX_CURSOR
)
25771 cursor_type
= HOLLOW_BOX_CURSOR
;
25772 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
25774 return cursor_type
;
25777 /* Use normal cursor if not blinked off. */
25778 if (!w
->cursor_off_p
)
25780 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
25782 if (cursor_type
== FILLED_BOX_CURSOR
)
25784 /* Using a block cursor on large images can be very annoying.
25785 So use a hollow cursor for "large" images.
25786 If image is not transparent (no mask), also use hollow cursor. */
25787 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
25788 if (img
!= NULL
&& IMAGEP (img
->spec
))
25790 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
25791 where N = size of default frame font size.
25792 This should cover most of the "tiny" icons people may use. */
25794 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
25795 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
25796 cursor_type
= HOLLOW_BOX_CURSOR
;
25799 else if (cursor_type
!= NO_CURSOR
)
25801 /* Display current only supports BOX and HOLLOW cursors for images.
25802 So for now, unconditionally use a HOLLOW cursor when cursor is
25803 not a solid box cursor. */
25804 cursor_type
= HOLLOW_BOX_CURSOR
;
25807 return cursor_type
;
25810 /* Cursor is blinked off, so determine how to "toggle" it. */
25812 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
25813 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
25814 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
25816 /* Then see if frame has specified a specific blink off cursor type. */
25817 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
25819 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
25820 return FRAME_BLINK_OFF_CURSOR (f
);
25824 /* Some people liked having a permanently visible blinking cursor,
25825 while others had very strong opinions against it. So it was
25826 decided to remove it. KFS 2003-09-03 */
25828 /* Finally perform built-in cursor blinking:
25829 filled box <-> hollow box
25830 wide [h]bar <-> narrow [h]bar
25831 narrow [h]bar <-> no cursor
25832 other type <-> no cursor */
25834 if (cursor_type
== FILLED_BOX_CURSOR
)
25835 return HOLLOW_BOX_CURSOR
;
25837 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
25840 return cursor_type
;
25848 /* Notice when the text cursor of window W has been completely
25849 overwritten by a drawing operation that outputs glyphs in AREA
25850 starting at X0 and ending at X1 in the line starting at Y0 and
25851 ending at Y1. X coordinates are area-relative. X1 < 0 means all
25852 the rest of the line after X0 has been written. Y coordinates
25853 are window-relative. */
25856 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
25857 int x0
, int x1
, int y0
, int y1
)
25859 int cx0
, cx1
, cy0
, cy1
;
25860 struct glyph_row
*row
;
25862 if (!w
->phys_cursor_on_p
)
25864 if (area
!= TEXT_AREA
)
25867 if (w
->phys_cursor
.vpos
< 0
25868 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
25869 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
25870 !(row
->enabled_p
&& row
->displays_text_p
)))
25873 if (row
->cursor_in_fringe_p
)
25875 row
->cursor_in_fringe_p
= 0;
25876 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
25877 w
->phys_cursor_on_p
= 0;
25881 cx0
= w
->phys_cursor
.x
;
25882 cx1
= cx0
+ w
->phys_cursor_width
;
25883 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
25886 /* The cursor image will be completely removed from the
25887 screen if the output area intersects the cursor area in
25888 y-direction. When we draw in [y0 y1[, and some part of
25889 the cursor is at y < y0, that part must have been drawn
25890 before. When scrolling, the cursor is erased before
25891 actually scrolling, so we don't come here. When not
25892 scrolling, the rows above the old cursor row must have
25893 changed, and in this case these rows must have written
25894 over the cursor image.
25896 Likewise if part of the cursor is below y1, with the
25897 exception of the cursor being in the first blank row at
25898 the buffer and window end because update_text_area
25899 doesn't draw that row. (Except when it does, but
25900 that's handled in update_text_area.) */
25902 cy0
= w
->phys_cursor
.y
;
25903 cy1
= cy0
+ w
->phys_cursor_height
;
25904 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
25907 w
->phys_cursor_on_p
= 0;
25910 #endif /* HAVE_WINDOW_SYSTEM */
25913 /************************************************************************
25915 ************************************************************************/
25917 #ifdef HAVE_WINDOW_SYSTEM
25920 Fix the display of area AREA of overlapping row ROW in window W
25921 with respect to the overlapping part OVERLAPS. */
25924 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
25925 enum glyph_row_area area
, int overlaps
)
25932 for (i
= 0; i
< row
->used
[area
];)
25934 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
25936 int start
= i
, start_x
= x
;
25940 x
+= row
->glyphs
[area
][i
].pixel_width
;
25943 while (i
< row
->used
[area
]
25944 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
25946 draw_glyphs (w
, start_x
, row
, area
,
25948 DRAW_NORMAL_TEXT
, overlaps
);
25952 x
+= row
->glyphs
[area
][i
].pixel_width
;
25962 Draw the cursor glyph of window W in glyph row ROW. See the
25963 comment of draw_glyphs for the meaning of HL. */
25966 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
25967 enum draw_glyphs_face hl
)
25969 /* If cursor hpos is out of bounds, don't draw garbage. This can
25970 happen in mini-buffer windows when switching between echo area
25971 glyphs and mini-buffer. */
25972 if ((row
->reversed_p
25973 ? (w
->phys_cursor
.hpos
>= 0)
25974 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
25976 int on_p
= w
->phys_cursor_on_p
;
25978 int hpos
= w
->phys_cursor
.hpos
;
25980 /* When the window is hscrolled, cursor hpos can legitimately be
25981 out of bounds, but we draw the cursor at the corresponding
25982 window margin in that case. */
25983 if (!row
->reversed_p
&& hpos
< 0)
25985 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
25986 hpos
= row
->used
[TEXT_AREA
] - 1;
25988 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
25990 w
->phys_cursor_on_p
= on_p
;
25992 if (hl
== DRAW_CURSOR
)
25993 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
25994 /* When we erase the cursor, and ROW is overlapped by other
25995 rows, make sure that these overlapping parts of other rows
25997 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
25999 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26001 if (row
> w
->current_matrix
->rows
26002 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26003 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26004 OVERLAPS_ERASED_CURSOR
);
26006 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26007 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26008 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26009 OVERLAPS_ERASED_CURSOR
);
26016 Erase the image of a cursor of window W from the screen. */
26019 erase_phys_cursor (struct window
*w
)
26021 struct frame
*f
= XFRAME (w
->frame
);
26022 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26023 int hpos
= w
->phys_cursor
.hpos
;
26024 int vpos
= w
->phys_cursor
.vpos
;
26025 int mouse_face_here_p
= 0;
26026 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26027 struct glyph_row
*cursor_row
;
26028 struct glyph
*cursor_glyph
;
26029 enum draw_glyphs_face hl
;
26031 /* No cursor displayed or row invalidated => nothing to do on the
26033 if (w
->phys_cursor_type
== NO_CURSOR
)
26034 goto mark_cursor_off
;
26036 /* VPOS >= active_glyphs->nrows means that window has been resized.
26037 Don't bother to erase the cursor. */
26038 if (vpos
>= active_glyphs
->nrows
)
26039 goto mark_cursor_off
;
26041 /* If row containing cursor is marked invalid, there is nothing we
26043 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26044 if (!cursor_row
->enabled_p
)
26045 goto mark_cursor_off
;
26047 /* If line spacing is > 0, old cursor may only be partially visible in
26048 window after split-window. So adjust visible height. */
26049 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26050 window_text_bottom_y (w
) - cursor_row
->y
);
26052 /* If row is completely invisible, don't attempt to delete a cursor which
26053 isn't there. This can happen if cursor is at top of a window, and
26054 we switch to a buffer with a header line in that window. */
26055 if (cursor_row
->visible_height
<= 0)
26056 goto mark_cursor_off
;
26058 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26059 if (cursor_row
->cursor_in_fringe_p
)
26061 cursor_row
->cursor_in_fringe_p
= 0;
26062 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26063 goto mark_cursor_off
;
26066 /* This can happen when the new row is shorter than the old one.
26067 In this case, either draw_glyphs or clear_end_of_line
26068 should have cleared the cursor. Note that we wouldn't be
26069 able to erase the cursor in this case because we don't have a
26070 cursor glyph at hand. */
26071 if ((cursor_row
->reversed_p
26072 ? (w
->phys_cursor
.hpos
< 0)
26073 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26074 goto mark_cursor_off
;
26076 /* When the window is hscrolled, cursor hpos can legitimately be out
26077 of bounds, but we draw the cursor at the corresponding window
26078 margin in that case. */
26079 if (!cursor_row
->reversed_p
&& hpos
< 0)
26081 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26082 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26084 /* If the cursor is in the mouse face area, redisplay that when
26085 we clear the cursor. */
26086 if (! NILP (hlinfo
->mouse_face_window
)
26087 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26088 /* Don't redraw the cursor's spot in mouse face if it is at the
26089 end of a line (on a newline). The cursor appears there, but
26090 mouse highlighting does not. */
26091 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26092 mouse_face_here_p
= 1;
26094 /* Maybe clear the display under the cursor. */
26095 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26098 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26101 cursor_glyph
= get_phys_cursor_glyph (w
);
26102 if (cursor_glyph
== NULL
)
26103 goto mark_cursor_off
;
26105 width
= cursor_glyph
->pixel_width
;
26106 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26107 x
= w
->phys_cursor
.x
;
26109 width
-= left_x
- x
;
26110 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26111 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26112 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26115 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26118 /* Erase the cursor by redrawing the character underneath it. */
26119 if (mouse_face_here_p
)
26120 hl
= DRAW_MOUSE_FACE
;
26122 hl
= DRAW_NORMAL_TEXT
;
26123 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26126 w
->phys_cursor_on_p
= 0;
26127 w
->phys_cursor_type
= NO_CURSOR
;
26132 Display or clear cursor of window W. If ON is zero, clear the
26133 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26134 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26137 display_and_set_cursor (struct window
*w
, int on
,
26138 int hpos
, int vpos
, int x
, int y
)
26140 struct frame
*f
= XFRAME (w
->frame
);
26141 int new_cursor_type
;
26142 int new_cursor_width
;
26144 struct glyph_row
*glyph_row
;
26145 struct glyph
*glyph
;
26147 /* This is pointless on invisible frames, and dangerous on garbaged
26148 windows and frames; in the latter case, the frame or window may
26149 be in the midst of changing its size, and x and y may be off the
26151 if (! FRAME_VISIBLE_P (f
)
26152 || FRAME_GARBAGED_P (f
)
26153 || vpos
>= w
->current_matrix
->nrows
26154 || hpos
>= w
->current_matrix
->matrix_w
)
26157 /* If cursor is off and we want it off, return quickly. */
26158 if (!on
&& !w
->phys_cursor_on_p
)
26161 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26162 /* If cursor row is not enabled, we don't really know where to
26163 display the cursor. */
26164 if (!glyph_row
->enabled_p
)
26166 w
->phys_cursor_on_p
= 0;
26171 if (!glyph_row
->exact_window_width_line_p
26172 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26173 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26175 eassert (input_blocked_p ());
26177 /* Set new_cursor_type to the cursor we want to be displayed. */
26178 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26179 &new_cursor_width
, &active_cursor
);
26181 /* If cursor is currently being shown and we don't want it to be or
26182 it is in the wrong place, or the cursor type is not what we want,
26184 if (w
->phys_cursor_on_p
26186 || w
->phys_cursor
.x
!= x
26187 || w
->phys_cursor
.y
!= y
26188 || new_cursor_type
!= w
->phys_cursor_type
26189 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26190 && new_cursor_width
!= w
->phys_cursor_width
)))
26191 erase_phys_cursor (w
);
26193 /* Don't check phys_cursor_on_p here because that flag is only set
26194 to zero in some cases where we know that the cursor has been
26195 completely erased, to avoid the extra work of erasing the cursor
26196 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26197 still not be visible, or it has only been partly erased. */
26200 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26201 w
->phys_cursor_height
= glyph_row
->height
;
26203 /* Set phys_cursor_.* before x_draw_.* is called because some
26204 of them may need the information. */
26205 w
->phys_cursor
.x
= x
;
26206 w
->phys_cursor
.y
= glyph_row
->y
;
26207 w
->phys_cursor
.hpos
= hpos
;
26208 w
->phys_cursor
.vpos
= vpos
;
26211 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26212 new_cursor_type
, new_cursor_width
,
26213 on
, active_cursor
);
26217 /* Switch the display of W's cursor on or off, according to the value
26221 update_window_cursor (struct window
*w
, int on
)
26223 /* Don't update cursor in windows whose frame is in the process
26224 of being deleted. */
26225 if (w
->current_matrix
)
26227 int hpos
= w
->phys_cursor
.hpos
;
26228 int vpos
= w
->phys_cursor
.vpos
;
26229 struct glyph_row
*row
;
26231 if (vpos
>= w
->current_matrix
->nrows
26232 || hpos
>= w
->current_matrix
->matrix_w
)
26235 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26237 /* When the window is hscrolled, cursor hpos can legitimately be
26238 out of bounds, but we draw the cursor at the corresponding
26239 window margin in that case. */
26240 if (!row
->reversed_p
&& hpos
< 0)
26242 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26243 hpos
= row
->used
[TEXT_AREA
] - 1;
26246 display_and_set_cursor (w
, on
, hpos
, vpos
,
26247 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26253 /* Call update_window_cursor with parameter ON_P on all leaf windows
26254 in the window tree rooted at W. */
26257 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26261 if (!NILP (w
->hchild
))
26262 update_cursor_in_window_tree (XWINDOW (w
->hchild
), on_p
);
26263 else if (!NILP (w
->vchild
))
26264 update_cursor_in_window_tree (XWINDOW (w
->vchild
), on_p
);
26266 update_window_cursor (w
, on_p
);
26268 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26274 Display the cursor on window W, or clear it, according to ON_P.
26275 Don't change the cursor's position. */
26278 x_update_cursor (struct frame
*f
, int on_p
)
26280 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26285 Clear the cursor of window W to background color, and mark the
26286 cursor as not shown. This is used when the text where the cursor
26287 is about to be rewritten. */
26290 x_clear_cursor (struct window
*w
)
26292 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26293 update_window_cursor (w
, 0);
26296 #endif /* HAVE_WINDOW_SYSTEM */
26298 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26301 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26302 int start_hpos
, int end_hpos
,
26303 enum draw_glyphs_face draw
)
26305 #ifdef HAVE_WINDOW_SYSTEM
26306 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26308 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26312 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26313 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26317 /* Display the active region described by mouse_face_* according to DRAW. */
26320 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26322 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26323 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26325 if (/* If window is in the process of being destroyed, don't bother
26327 w
->current_matrix
!= NULL
26328 /* Don't update mouse highlight if hidden */
26329 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26330 /* Recognize when we are called to operate on rows that don't exist
26331 anymore. This can happen when a window is split. */
26332 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26334 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26335 struct glyph_row
*row
, *first
, *last
;
26337 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26338 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26340 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26342 int start_hpos
, end_hpos
, start_x
;
26344 /* For all but the first row, the highlight starts at column 0. */
26347 /* R2L rows have BEG and END in reversed order, but the
26348 screen drawing geometry is always left to right. So
26349 we need to mirror the beginning and end of the
26350 highlighted area in R2L rows. */
26351 if (!row
->reversed_p
)
26353 start_hpos
= hlinfo
->mouse_face_beg_col
;
26354 start_x
= hlinfo
->mouse_face_beg_x
;
26356 else if (row
== last
)
26358 start_hpos
= hlinfo
->mouse_face_end_col
;
26359 start_x
= hlinfo
->mouse_face_end_x
;
26367 else if (row
->reversed_p
&& row
== last
)
26369 start_hpos
= hlinfo
->mouse_face_end_col
;
26370 start_x
= hlinfo
->mouse_face_end_x
;
26380 if (!row
->reversed_p
)
26381 end_hpos
= hlinfo
->mouse_face_end_col
;
26382 else if (row
== first
)
26383 end_hpos
= hlinfo
->mouse_face_beg_col
;
26386 end_hpos
= row
->used
[TEXT_AREA
];
26387 if (draw
== DRAW_NORMAL_TEXT
)
26388 row
->fill_line_p
= 1; /* Clear to end of line */
26391 else if (row
->reversed_p
&& row
== first
)
26392 end_hpos
= hlinfo
->mouse_face_beg_col
;
26395 end_hpos
= row
->used
[TEXT_AREA
];
26396 if (draw
== DRAW_NORMAL_TEXT
)
26397 row
->fill_line_p
= 1; /* Clear to end of line */
26400 if (end_hpos
> start_hpos
)
26402 draw_row_with_mouse_face (w
, start_x
, row
,
26403 start_hpos
, end_hpos
, draw
);
26406 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26410 #ifdef HAVE_WINDOW_SYSTEM
26411 /* When we've written over the cursor, arrange for it to
26412 be displayed again. */
26413 if (FRAME_WINDOW_P (f
)
26414 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26416 int hpos
= w
->phys_cursor
.hpos
;
26418 /* When the window is hscrolled, cursor hpos can legitimately be
26419 out of bounds, but we draw the cursor at the corresponding
26420 window margin in that case. */
26421 if (!row
->reversed_p
&& hpos
< 0)
26423 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26424 hpos
= row
->used
[TEXT_AREA
] - 1;
26427 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26428 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26431 #endif /* HAVE_WINDOW_SYSTEM */
26434 #ifdef HAVE_WINDOW_SYSTEM
26435 /* Change the mouse cursor. */
26436 if (FRAME_WINDOW_P (f
))
26438 if (draw
== DRAW_NORMAL_TEXT
26439 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26440 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26441 else if (draw
== DRAW_MOUSE_FACE
)
26442 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26444 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26446 #endif /* HAVE_WINDOW_SYSTEM */
26450 Clear out the mouse-highlighted active region.
26451 Redraw it un-highlighted first. Value is non-zero if mouse
26452 face was actually drawn unhighlighted. */
26455 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26459 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26461 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26465 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26466 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26467 hlinfo
->mouse_face_window
= Qnil
;
26468 hlinfo
->mouse_face_overlay
= Qnil
;
26472 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26473 within the mouse face on that window. */
26475 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26477 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26479 /* Quickly resolve the easy cases. */
26480 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26481 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26483 if (vpos
< hlinfo
->mouse_face_beg_row
26484 || vpos
> hlinfo
->mouse_face_end_row
)
26486 if (vpos
> hlinfo
->mouse_face_beg_row
26487 && vpos
< hlinfo
->mouse_face_end_row
)
26490 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26492 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26494 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26497 else if ((vpos
== hlinfo
->mouse_face_beg_row
26498 && hpos
>= hlinfo
->mouse_face_beg_col
)
26499 || (vpos
== hlinfo
->mouse_face_end_row
26500 && hpos
< hlinfo
->mouse_face_end_col
))
26505 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26507 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26510 else if ((vpos
== hlinfo
->mouse_face_beg_row
26511 && hpos
<= hlinfo
->mouse_face_beg_col
)
26512 || (vpos
== hlinfo
->mouse_face_end_row
26513 && hpos
> hlinfo
->mouse_face_end_col
))
26521 Non-zero if physical cursor of window W is within mouse face. */
26524 cursor_in_mouse_face_p (struct window
*w
)
26526 int hpos
= w
->phys_cursor
.hpos
;
26527 int vpos
= w
->phys_cursor
.vpos
;
26528 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26530 /* When the window is hscrolled, cursor hpos can legitimately be out
26531 of bounds, but we draw the cursor at the corresponding window
26532 margin in that case. */
26533 if (!row
->reversed_p
&& hpos
< 0)
26535 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26536 hpos
= row
->used
[TEXT_AREA
] - 1;
26538 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26543 /* Find the glyph rows START_ROW and END_ROW of window W that display
26544 characters between buffer positions START_CHARPOS and END_CHARPOS
26545 (excluding END_CHARPOS). DISP_STRING is a display string that
26546 covers these buffer positions. This is similar to
26547 row_containing_pos, but is more accurate when bidi reordering makes
26548 buffer positions change non-linearly with glyph rows. */
26550 rows_from_pos_range (struct window
*w
,
26551 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26552 Lisp_Object disp_string
,
26553 struct glyph_row
**start
, struct glyph_row
**end
)
26555 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26556 int last_y
= window_text_bottom_y (w
);
26557 struct glyph_row
*row
;
26562 while (!first
->enabled_p
26563 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26566 /* Find the START row. */
26568 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26571 /* A row can potentially be the START row if the range of the
26572 characters it displays intersects the range
26573 [START_CHARPOS..END_CHARPOS). */
26574 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26575 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26576 /* See the commentary in row_containing_pos, for the
26577 explanation of the complicated way to check whether
26578 some position is beyond the end of the characters
26579 displayed by a row. */
26580 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26581 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26582 && !row
->ends_at_zv_p
26583 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26584 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26585 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26586 && !row
->ends_at_zv_p
26587 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26589 /* Found a candidate row. Now make sure at least one of the
26590 glyphs it displays has a charpos from the range
26591 [START_CHARPOS..END_CHARPOS).
26593 This is not obvious because bidi reordering could make
26594 buffer positions of a row be 1,2,3,102,101,100, and if we
26595 want to highlight characters in [50..60), we don't want
26596 this row, even though [50..60) does intersect [1..103),
26597 the range of character positions given by the row's start
26598 and end positions. */
26599 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26600 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26604 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26605 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26606 /* A glyph that comes from DISP_STRING is by
26607 definition to be highlighted. */
26608 || EQ (g
->object
, disp_string
))
26617 /* Find the END row. */
26619 /* If the last row is partially visible, start looking for END
26620 from that row, instead of starting from FIRST. */
26621 && !(row
->enabled_p
26622 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26624 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26626 struct glyph_row
*next
= row
+ 1;
26627 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26629 if (!next
->enabled_p
26630 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26631 /* The first row >= START whose range of displayed characters
26632 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26633 is the row END + 1. */
26634 || (start_charpos
< next_start
26635 && end_charpos
< next_start
)
26636 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26637 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26638 && !next
->ends_at_zv_p
26639 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26640 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26641 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26642 && !next
->ends_at_zv_p
26643 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26650 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26651 but none of the characters it displays are in the range, it is
26653 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26654 struct glyph
*s
= g
;
26655 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26659 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26660 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26661 /* If the buffer position of the first glyph in
26662 the row is equal to END_CHARPOS, it means
26663 the last character to be highlighted is the
26664 newline of ROW, and we must consider NEXT as
26666 || (((!next
->reversed_p
&& g
== s
)
26667 || (next
->reversed_p
&& g
== e
- 1))
26668 && (g
->charpos
== end_charpos
26669 /* Special case for when NEXT is an
26670 empty line at ZV. */
26671 || (g
->charpos
== -1
26672 && !row
->ends_at_zv_p
26673 && next_start
== end_charpos
)))))
26674 /* A glyph that comes from DISP_STRING is by
26675 definition to be highlighted. */
26676 || EQ (g
->object
, disp_string
))
26685 /* The first row that ends at ZV must be the last to be
26687 else if (next
->ends_at_zv_p
)
26696 /* This function sets the mouse_face_* elements of HLINFO, assuming
26697 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26698 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26699 for the overlay or run of text properties specifying the mouse
26700 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26701 before-string and after-string that must also be highlighted.
26702 DISP_STRING, if non-nil, is a display string that may cover some
26703 or all of the highlighted text. */
26706 mouse_face_from_buffer_pos (Lisp_Object window
,
26707 Mouse_HLInfo
*hlinfo
,
26708 ptrdiff_t mouse_charpos
,
26709 ptrdiff_t start_charpos
,
26710 ptrdiff_t end_charpos
,
26711 Lisp_Object before_string
,
26712 Lisp_Object after_string
,
26713 Lisp_Object disp_string
)
26715 struct window
*w
= XWINDOW (window
);
26716 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26717 struct glyph_row
*r1
, *r2
;
26718 struct glyph
*glyph
, *end
;
26719 ptrdiff_t ignore
, pos
;
26722 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26723 eassert (NILP (before_string
) || STRINGP (before_string
));
26724 eassert (NILP (after_string
) || STRINGP (after_string
));
26726 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26727 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26729 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26730 /* If the before-string or display-string contains newlines,
26731 rows_from_pos_range skips to its last row. Move back. */
26732 if (!NILP (before_string
) || !NILP (disp_string
))
26734 struct glyph_row
*prev
;
26735 while ((prev
= r1
- 1, prev
>= first
)
26736 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26737 && prev
->used
[TEXT_AREA
] > 0)
26739 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26740 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26741 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26743 || !(EQ (glyph
->object
, before_string
)
26744 || EQ (glyph
->object
, disp_string
)))
26751 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26752 hlinfo
->mouse_face_past_end
= 1;
26754 else if (!NILP (after_string
))
26756 /* If the after-string has newlines, advance to its last row. */
26757 struct glyph_row
*next
;
26758 struct glyph_row
*last
26759 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
26761 for (next
= r2
+ 1;
26763 && next
->used
[TEXT_AREA
] > 0
26764 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
26768 /* The rest of the display engine assumes that mouse_face_beg_row is
26769 either above mouse_face_end_row or identical to it. But with
26770 bidi-reordered continued lines, the row for START_CHARPOS could
26771 be below the row for END_CHARPOS. If so, swap the rows and store
26772 them in correct order. */
26775 struct glyph_row
*tem
= r2
;
26781 hlinfo
->mouse_face_beg_y
= r1
->y
;
26782 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
26783 hlinfo
->mouse_face_end_y
= r2
->y
;
26784 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
26786 /* For a bidi-reordered row, the positions of BEFORE_STRING,
26787 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
26788 could be anywhere in the row and in any order. The strategy
26789 below is to find the leftmost and the rightmost glyph that
26790 belongs to either of these 3 strings, or whose position is
26791 between START_CHARPOS and END_CHARPOS, and highlight all the
26792 glyphs between those two. This may cover more than just the text
26793 between START_CHARPOS and END_CHARPOS if the range of characters
26794 strides the bidi level boundary, e.g. if the beginning is in R2L
26795 text while the end is in L2R text or vice versa. */
26796 if (!r1
->reversed_p
)
26798 /* This row is in a left to right paragraph. Scan it left to
26800 glyph
= r1
->glyphs
[TEXT_AREA
];
26801 end
= glyph
+ r1
->used
[TEXT_AREA
];
26804 /* Skip truncation glyphs at the start of the glyph row. */
26805 if (r1
->displays_text_p
)
26807 && INTEGERP (glyph
->object
)
26808 && glyph
->charpos
< 0;
26810 x
+= glyph
->pixel_width
;
26812 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26813 or DISP_STRING, and the first glyph from buffer whose
26814 position is between START_CHARPOS and END_CHARPOS. */
26816 && !INTEGERP (glyph
->object
)
26817 && !EQ (glyph
->object
, disp_string
)
26818 && !(BUFFERP (glyph
->object
)
26819 && (glyph
->charpos
>= start_charpos
26820 && glyph
->charpos
< end_charpos
));
26823 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26824 are present at buffer positions between START_CHARPOS and
26825 END_CHARPOS, or if they come from an overlay. */
26826 if (EQ (glyph
->object
, before_string
))
26828 pos
= string_buffer_position (before_string
,
26830 /* If pos == 0, it means before_string came from an
26831 overlay, not from a buffer position. */
26832 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26835 else if (EQ (glyph
->object
, after_string
))
26837 pos
= string_buffer_position (after_string
, end_charpos
);
26838 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26841 x
+= glyph
->pixel_width
;
26843 hlinfo
->mouse_face_beg_x
= x
;
26844 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26848 /* This row is in a right to left paragraph. Scan it right to
26852 end
= r1
->glyphs
[TEXT_AREA
] - 1;
26853 glyph
= end
+ r1
->used
[TEXT_AREA
];
26855 /* Skip truncation glyphs at the start of the glyph row. */
26856 if (r1
->displays_text_p
)
26858 && INTEGERP (glyph
->object
)
26859 && glyph
->charpos
< 0;
26863 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
26864 or DISP_STRING, and the first glyph from buffer whose
26865 position is between START_CHARPOS and END_CHARPOS. */
26867 && !INTEGERP (glyph
->object
)
26868 && !EQ (glyph
->object
, disp_string
)
26869 && !(BUFFERP (glyph
->object
)
26870 && (glyph
->charpos
>= start_charpos
26871 && glyph
->charpos
< end_charpos
));
26874 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26875 are present at buffer positions between START_CHARPOS and
26876 END_CHARPOS, or if they come from an overlay. */
26877 if (EQ (glyph
->object
, before_string
))
26879 pos
= string_buffer_position (before_string
, start_charpos
);
26880 /* If pos == 0, it means before_string came from an
26881 overlay, not from a buffer position. */
26882 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26885 else if (EQ (glyph
->object
, after_string
))
26887 pos
= string_buffer_position (after_string
, end_charpos
);
26888 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26893 glyph
++; /* first glyph to the right of the highlighted area */
26894 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
26895 x
+= g
->pixel_width
;
26896 hlinfo
->mouse_face_beg_x
= x
;
26897 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
26900 /* If the highlight ends in a different row, compute GLYPH and END
26901 for the end row. Otherwise, reuse the values computed above for
26902 the row where the highlight begins. */
26905 if (!r2
->reversed_p
)
26907 glyph
= r2
->glyphs
[TEXT_AREA
];
26908 end
= glyph
+ r2
->used
[TEXT_AREA
];
26913 end
= r2
->glyphs
[TEXT_AREA
] - 1;
26914 glyph
= end
+ r2
->used
[TEXT_AREA
];
26918 if (!r2
->reversed_p
)
26920 /* Skip truncation and continuation glyphs near the end of the
26921 row, and also blanks and stretch glyphs inserted by
26922 extend_face_to_end_of_line. */
26924 && INTEGERP ((end
- 1)->object
))
26926 /* Scan the rest of the glyph row from the end, looking for the
26927 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26928 DISP_STRING, or whose position is between START_CHARPOS
26932 && !INTEGERP (end
->object
)
26933 && !EQ (end
->object
, disp_string
)
26934 && !(BUFFERP (end
->object
)
26935 && (end
->charpos
>= start_charpos
26936 && end
->charpos
< end_charpos
));
26939 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26940 are present at buffer positions between START_CHARPOS and
26941 END_CHARPOS, or if they come from an overlay. */
26942 if (EQ (end
->object
, before_string
))
26944 pos
= string_buffer_position (before_string
, start_charpos
);
26945 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26948 else if (EQ (end
->object
, after_string
))
26950 pos
= string_buffer_position (after_string
, end_charpos
);
26951 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26955 /* Find the X coordinate of the last glyph to be highlighted. */
26956 for (; glyph
<= end
; ++glyph
)
26957 x
+= glyph
->pixel_width
;
26959 hlinfo
->mouse_face_end_x
= x
;
26960 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
26964 /* Skip truncation and continuation glyphs near the end of the
26965 row, and also blanks and stretch glyphs inserted by
26966 extend_face_to_end_of_line. */
26970 && INTEGERP (end
->object
))
26972 x
+= end
->pixel_width
;
26975 /* Scan the rest of the glyph row from the end, looking for the
26976 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
26977 DISP_STRING, or whose position is between START_CHARPOS
26981 && !INTEGERP (end
->object
)
26982 && !EQ (end
->object
, disp_string
)
26983 && !(BUFFERP (end
->object
)
26984 && (end
->charpos
>= start_charpos
26985 && end
->charpos
< end_charpos
));
26988 /* BEFORE_STRING or AFTER_STRING are only relevant if they
26989 are present at buffer positions between START_CHARPOS and
26990 END_CHARPOS, or if they come from an overlay. */
26991 if (EQ (end
->object
, before_string
))
26993 pos
= string_buffer_position (before_string
, start_charpos
);
26994 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
26997 else if (EQ (end
->object
, after_string
))
26999 pos
= string_buffer_position (after_string
, end_charpos
);
27000 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27003 x
+= end
->pixel_width
;
27005 /* If we exited the above loop because we arrived at the last
27006 glyph of the row, and its buffer position is still not in
27007 range, it means the last character in range is the preceding
27008 newline. Bump the end column and x values to get past the
27011 && BUFFERP (end
->object
)
27012 && (end
->charpos
< start_charpos
27013 || end
->charpos
>= end_charpos
))
27015 x
+= end
->pixel_width
;
27018 hlinfo
->mouse_face_end_x
= x
;
27019 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27022 hlinfo
->mouse_face_window
= window
;
27023 hlinfo
->mouse_face_face_id
27024 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27026 !hlinfo
->mouse_face_hidden
, -1);
27027 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27030 /* The following function is not used anymore (replaced with
27031 mouse_face_from_string_pos), but I leave it here for the time
27032 being, in case someone would. */
27034 #if 0 /* not used */
27036 /* Find the position of the glyph for position POS in OBJECT in
27037 window W's current matrix, and return in *X, *Y the pixel
27038 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27040 RIGHT_P non-zero means return the position of the right edge of the
27041 glyph, RIGHT_P zero means return the left edge position.
27043 If no glyph for POS exists in the matrix, return the position of
27044 the glyph with the next smaller position that is in the matrix, if
27045 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27046 exists in the matrix, return the position of the glyph with the
27047 next larger position in OBJECT.
27049 Value is non-zero if a glyph was found. */
27052 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27053 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27055 int yb
= window_text_bottom_y (w
);
27056 struct glyph_row
*r
;
27057 struct glyph
*best_glyph
= NULL
;
27058 struct glyph_row
*best_row
= NULL
;
27061 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27062 r
->enabled_p
&& r
->y
< yb
;
27065 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27066 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27069 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27070 if (EQ (g
->object
, object
))
27072 if (g
->charpos
== pos
)
27079 else if (best_glyph
== NULL
27080 || ((eabs (g
->charpos
- pos
)
27081 < eabs (best_glyph
->charpos
- pos
))
27084 : g
->charpos
> pos
)))
27098 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27102 *x
+= best_glyph
->pixel_width
;
27107 *vpos
= best_row
- w
->current_matrix
->rows
;
27110 return best_glyph
!= NULL
;
27112 #endif /* not used */
27114 /* Find the positions of the first and the last glyphs in window W's
27115 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27116 (assumed to be a string), and return in HLINFO's mouse_face_*
27117 members the pixel and column/row coordinates of those glyphs. */
27120 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27121 Lisp_Object object
,
27122 ptrdiff_t startpos
, ptrdiff_t endpos
)
27124 int yb
= window_text_bottom_y (w
);
27125 struct glyph_row
*r
;
27126 struct glyph
*g
, *e
;
27130 /* Find the glyph row with at least one position in the range
27131 [STARTPOS..ENDPOS], and the first glyph in that row whose
27132 position belongs to that range. */
27133 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27134 r
->enabled_p
&& r
->y
< yb
;
27137 if (!r
->reversed_p
)
27139 g
= r
->glyphs
[TEXT_AREA
];
27140 e
= g
+ r
->used
[TEXT_AREA
];
27141 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27142 if (EQ (g
->object
, object
)
27143 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27145 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27146 hlinfo
->mouse_face_beg_y
= r
->y
;
27147 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27148 hlinfo
->mouse_face_beg_x
= gx
;
27157 e
= r
->glyphs
[TEXT_AREA
];
27158 g
= e
+ r
->used
[TEXT_AREA
];
27159 for ( ; g
> e
; --g
)
27160 if (EQ ((g
-1)->object
, object
)
27161 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27163 hlinfo
->mouse_face_beg_row
= r
- w
->current_matrix
->rows
;
27164 hlinfo
->mouse_face_beg_y
= r
->y
;
27165 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27166 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27167 gx
+= g1
->pixel_width
;
27168 hlinfo
->mouse_face_beg_x
= gx
;
27180 /* Starting with the next row, look for the first row which does NOT
27181 include any glyphs whose positions are in the range. */
27182 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27184 g
= r
->glyphs
[TEXT_AREA
];
27185 e
= g
+ r
->used
[TEXT_AREA
];
27187 for ( ; g
< e
; ++g
)
27188 if (EQ (g
->object
, object
)
27189 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27198 /* The highlighted region ends on the previous row. */
27201 /* Set the end row and its vertical pixel coordinate. */
27202 hlinfo
->mouse_face_end_row
= r
- w
->current_matrix
->rows
;
27203 hlinfo
->mouse_face_end_y
= r
->y
;
27205 /* Compute and set the end column and the end column's horizontal
27206 pixel coordinate. */
27207 if (!r
->reversed_p
)
27209 g
= r
->glyphs
[TEXT_AREA
];
27210 e
= g
+ r
->used
[TEXT_AREA
];
27211 for ( ; e
> g
; --e
)
27212 if (EQ ((e
-1)->object
, object
)
27213 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27215 hlinfo
->mouse_face_end_col
= e
- g
;
27217 for (gx
= r
->x
; g
< e
; ++g
)
27218 gx
+= g
->pixel_width
;
27219 hlinfo
->mouse_face_end_x
= gx
;
27223 e
= r
->glyphs
[TEXT_AREA
];
27224 g
= e
+ r
->used
[TEXT_AREA
];
27225 for (gx
= r
->x
; e
< g
; ++e
)
27227 if (EQ (e
->object
, object
)
27228 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27230 gx
+= e
->pixel_width
;
27232 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27233 hlinfo
->mouse_face_end_x
= gx
;
27237 #ifdef HAVE_WINDOW_SYSTEM
27239 /* See if position X, Y is within a hot-spot of an image. */
27242 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27244 if (!CONSP (hot_spot
))
27247 if (EQ (XCAR (hot_spot
), Qrect
))
27249 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27250 Lisp_Object rect
= XCDR (hot_spot
);
27254 if (!CONSP (XCAR (rect
)))
27256 if (!CONSP (XCDR (rect
)))
27258 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27260 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27262 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27264 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27268 else if (EQ (XCAR (hot_spot
), Qcircle
))
27270 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27271 Lisp_Object circ
= XCDR (hot_spot
);
27272 Lisp_Object lr
, lx0
, ly0
;
27274 && CONSP (XCAR (circ
))
27275 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27276 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27277 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27279 double r
= XFLOATINT (lr
);
27280 double dx
= XINT (lx0
) - x
;
27281 double dy
= XINT (ly0
) - y
;
27282 return (dx
* dx
+ dy
* dy
<= r
* r
);
27285 else if (EQ (XCAR (hot_spot
), Qpoly
))
27287 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27288 if (VECTORP (XCDR (hot_spot
)))
27290 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27291 Lisp_Object
*poly
= v
->contents
;
27292 ptrdiff_t n
= v
->header
.size
;
27295 Lisp_Object lx
, ly
;
27298 /* Need an even number of coordinates, and at least 3 edges. */
27299 if (n
< 6 || n
& 1)
27302 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27303 If count is odd, we are inside polygon. Pixels on edges
27304 may or may not be included depending on actual geometry of the
27306 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27307 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27309 x0
= XINT (lx
), y0
= XINT (ly
);
27310 for (i
= 0; i
< n
; i
+= 2)
27312 int x1
= x0
, y1
= y0
;
27313 if ((lx
= poly
[i
], !INTEGERP (lx
))
27314 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27316 x0
= XINT (lx
), y0
= XINT (ly
);
27318 /* Does this segment cross the X line? */
27326 if (y
> y0
&& y
> y1
)
27328 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27338 find_hot_spot (Lisp_Object map
, int x
, int y
)
27340 while (CONSP (map
))
27342 if (CONSP (XCAR (map
))
27343 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27351 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27353 doc
: /* Lookup in image map MAP coordinates X and Y.
27354 An image map is an alist where each element has the format (AREA ID PLIST).
27355 An AREA is specified as either a rectangle, a circle, or a polygon:
27356 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27357 pixel coordinates of the upper left and bottom right corners.
27358 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27359 and the radius of the circle; r may be a float or integer.
27360 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27361 vector describes one corner in the polygon.
27362 Returns the alist element for the first matching AREA in MAP. */)
27363 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27371 return find_hot_spot (map
,
27372 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27373 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27377 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27379 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27381 /* Do not change cursor shape while dragging mouse. */
27382 if (!NILP (do_mouse_tracking
))
27385 if (!NILP (pointer
))
27387 if (EQ (pointer
, Qarrow
))
27388 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27389 else if (EQ (pointer
, Qhand
))
27390 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27391 else if (EQ (pointer
, Qtext
))
27392 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27393 else if (EQ (pointer
, intern ("hdrag")))
27394 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27395 #ifdef HAVE_X_WINDOWS
27396 else if (EQ (pointer
, intern ("vdrag")))
27397 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27399 else if (EQ (pointer
, intern ("hourglass")))
27400 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27401 else if (EQ (pointer
, Qmodeline
))
27402 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27404 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27407 if (cursor
!= No_Cursor
)
27408 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27411 #endif /* HAVE_WINDOW_SYSTEM */
27413 /* Take proper action when mouse has moved to the mode or header line
27414 or marginal area AREA of window W, x-position X and y-position Y.
27415 X is relative to the start of the text display area of W, so the
27416 width of bitmap areas and scroll bars must be subtracted to get a
27417 position relative to the start of the mode line. */
27420 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27421 enum window_part area
)
27423 struct window
*w
= XWINDOW (window
);
27424 struct frame
*f
= XFRAME (w
->frame
);
27425 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27426 #ifdef HAVE_WINDOW_SYSTEM
27427 Display_Info
*dpyinfo
;
27429 Cursor cursor
= No_Cursor
;
27430 Lisp_Object pointer
= Qnil
;
27431 int dx
, dy
, width
, height
;
27433 Lisp_Object string
, object
= Qnil
;
27434 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27436 Lisp_Object mouse_face
;
27437 int original_x_pixel
= x
;
27438 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27439 struct glyph_row
*row
IF_LINT (= 0);
27441 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27446 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27447 returns them in row/column units! */
27448 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27449 &object
, &dx
, &dy
, &width
, &height
);
27451 row
= (area
== ON_MODE_LINE
27452 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27453 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27455 /* Find the glyph under the mouse pointer. */
27456 if (row
->mode_line_p
&& row
->enabled_p
)
27458 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27459 end
= glyph
+ row
->used
[TEXT_AREA
];
27461 for (x0
= original_x_pixel
;
27462 glyph
< end
&& x0
>= glyph
->pixel_width
;
27464 x0
-= glyph
->pixel_width
;
27472 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27473 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27474 returns them in row/column units! */
27475 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27476 &object
, &dx
, &dy
, &width
, &height
);
27481 #ifdef HAVE_WINDOW_SYSTEM
27482 if (IMAGEP (object
))
27484 Lisp_Object image_map
, hotspot
;
27485 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27487 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27489 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27493 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27494 If so, we could look for mouse-enter, mouse-leave
27495 properties in PLIST (and do something...). */
27496 hotspot
= XCDR (hotspot
);
27497 if (CONSP (hotspot
)
27498 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27500 pointer
= Fplist_get (plist
, Qpointer
);
27501 if (NILP (pointer
))
27503 help
= Fplist_get (plist
, Qhelp_echo
);
27506 help_echo_string
= help
;
27507 XSETWINDOW (help_echo_window
, w
);
27508 help_echo_object
= w
->buffer
;
27509 help_echo_pos
= charpos
;
27513 if (NILP (pointer
))
27514 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27516 #endif /* HAVE_WINDOW_SYSTEM */
27518 if (STRINGP (string
))
27519 pos
= make_number (charpos
);
27521 /* Set the help text and mouse pointer. If the mouse is on a part
27522 of the mode line without any text (e.g. past the right edge of
27523 the mode line text), use the default help text and pointer. */
27524 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27526 /* Arrange to display the help by setting the global variables
27527 help_echo_string, help_echo_object, and help_echo_pos. */
27530 if (STRINGP (string
))
27531 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27535 help_echo_string
= help
;
27536 XSETWINDOW (help_echo_window
, w
);
27537 help_echo_object
= string
;
27538 help_echo_pos
= charpos
;
27540 else if (area
== ON_MODE_LINE
)
27542 Lisp_Object default_help
27543 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27546 if (STRINGP (default_help
))
27548 help_echo_string
= default_help
;
27549 XSETWINDOW (help_echo_window
, w
);
27550 help_echo_object
= Qnil
;
27551 help_echo_pos
= -1;
27556 #ifdef HAVE_WINDOW_SYSTEM
27557 /* Change the mouse pointer according to what is under it. */
27558 if (FRAME_WINDOW_P (f
))
27560 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27561 if (STRINGP (string
))
27563 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27565 if (NILP (pointer
))
27566 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27568 /* Change the mouse pointer according to what is under X/Y. */
27570 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27573 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27574 if (!KEYMAPP (map
))
27575 map
= Fget_text_property (pos
, Qkeymap
, string
);
27576 if (!KEYMAPP (map
))
27577 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27581 /* Default mode-line pointer. */
27582 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27587 /* Change the mouse face according to what is under X/Y. */
27588 if (STRINGP (string
))
27590 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27591 if (!NILP (mouse_face
)
27592 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27597 struct glyph
* tmp_glyph
;
27601 int total_pixel_width
;
27602 ptrdiff_t begpos
, endpos
, ignore
;
27606 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27607 Qmouse_face
, string
, Qnil
);
27613 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27615 endpos
= SCHARS (string
);
27619 /* Calculate the glyph position GPOS of GLYPH in the
27620 displayed string, relative to the beginning of the
27621 highlighted part of the string.
27623 Note: GPOS is different from CHARPOS. CHARPOS is the
27624 position of GLYPH in the internal string object. A mode
27625 line string format has structures which are converted to
27626 a flattened string by the Emacs Lisp interpreter. The
27627 internal string is an element of those structures. The
27628 displayed string is the flattened string. */
27629 tmp_glyph
= row_start_glyph
;
27630 while (tmp_glyph
< glyph
27631 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27632 && begpos
<= tmp_glyph
->charpos
27633 && tmp_glyph
->charpos
< endpos
)))
27635 gpos
= glyph
- tmp_glyph
;
27637 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27638 the highlighted part of the displayed string to which
27639 GLYPH belongs. Note: GSEQ_LENGTH is different from
27640 SCHARS (STRING), because the latter returns the length of
27641 the internal string. */
27642 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27644 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27645 && begpos
<= tmp_glyph
->charpos
27646 && tmp_glyph
->charpos
< endpos
));
27649 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27651 /* Calculate the total pixel width of all the glyphs between
27652 the beginning of the highlighted area and GLYPH. */
27653 total_pixel_width
= 0;
27654 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27655 total_pixel_width
+= tmp_glyph
->pixel_width
;
27657 /* Pre calculation of re-rendering position. Note: X is in
27658 column units here, after the call to mode_line_string or
27659 marginal_area_string. */
27661 vpos
= (area
== ON_MODE_LINE
27662 ? (w
->current_matrix
)->nrows
- 1
27665 /* If GLYPH's position is included in the region that is
27666 already drawn in mouse face, we have nothing to do. */
27667 if ( EQ (window
, hlinfo
->mouse_face_window
)
27668 && (!row
->reversed_p
27669 ? (hlinfo
->mouse_face_beg_col
<= hpos
27670 && hpos
< hlinfo
->mouse_face_end_col
)
27671 /* In R2L rows we swap BEG and END, see below. */
27672 : (hlinfo
->mouse_face_end_col
<= hpos
27673 && hpos
< hlinfo
->mouse_face_beg_col
))
27674 && hlinfo
->mouse_face_beg_row
== vpos
)
27677 if (clear_mouse_face (hlinfo
))
27678 cursor
= No_Cursor
;
27680 if (!row
->reversed_p
)
27682 hlinfo
->mouse_face_beg_col
= hpos
;
27683 hlinfo
->mouse_face_beg_x
= original_x_pixel
27684 - (total_pixel_width
+ dx
);
27685 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27686 hlinfo
->mouse_face_end_x
= 0;
27690 /* In R2L rows, show_mouse_face expects BEG and END
27691 coordinates to be swapped. */
27692 hlinfo
->mouse_face_end_col
= hpos
;
27693 hlinfo
->mouse_face_end_x
= original_x_pixel
27694 - (total_pixel_width
+ dx
);
27695 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27696 hlinfo
->mouse_face_beg_x
= 0;
27699 hlinfo
->mouse_face_beg_row
= vpos
;
27700 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27701 hlinfo
->mouse_face_beg_y
= 0;
27702 hlinfo
->mouse_face_end_y
= 0;
27703 hlinfo
->mouse_face_past_end
= 0;
27704 hlinfo
->mouse_face_window
= window
;
27706 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27712 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27714 if (NILP (pointer
))
27717 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27718 clear_mouse_face (hlinfo
);
27720 #ifdef HAVE_WINDOW_SYSTEM
27721 if (FRAME_WINDOW_P (f
))
27722 define_frame_cursor1 (f
, cursor
, pointer
);
27728 Take proper action when the mouse has moved to position X, Y on
27729 frame F as regards highlighting characters that have mouse-face
27730 properties. Also de-highlighting chars where the mouse was before.
27731 X and Y can be negative or out of range. */
27734 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27736 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27737 enum window_part part
= ON_NOTHING
;
27738 Lisp_Object window
;
27740 Cursor cursor
= No_Cursor
;
27741 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27744 /* When a menu is active, don't highlight because this looks odd. */
27745 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27746 if (popup_activated ())
27750 if (NILP (Vmouse_highlight
)
27751 || !f
->glyphs_initialized_p
27752 || f
->pointer_invisible
)
27755 hlinfo
->mouse_face_mouse_x
= x
;
27756 hlinfo
->mouse_face_mouse_y
= y
;
27757 hlinfo
->mouse_face_mouse_frame
= f
;
27759 if (hlinfo
->mouse_face_defer
)
27762 /* Which window is that in? */
27763 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
27765 /* If displaying active text in another window, clear that. */
27766 if (! EQ (window
, hlinfo
->mouse_face_window
)
27767 /* Also clear if we move out of text area in same window. */
27768 || (!NILP (hlinfo
->mouse_face_window
)
27771 && part
!= ON_MODE_LINE
27772 && part
!= ON_HEADER_LINE
))
27773 clear_mouse_face (hlinfo
);
27775 /* Not on a window -> return. */
27776 if (!WINDOWP (window
))
27779 /* Reset help_echo_string. It will get recomputed below. */
27780 help_echo_string
= Qnil
;
27782 /* Convert to window-relative pixel coordinates. */
27783 w
= XWINDOW (window
);
27784 frame_to_window_pixel_xy (w
, &x
, &y
);
27786 #ifdef HAVE_WINDOW_SYSTEM
27787 /* Handle tool-bar window differently since it doesn't display a
27789 if (EQ (window
, f
->tool_bar_window
))
27791 note_tool_bar_highlight (f
, x
, y
);
27796 /* Mouse is on the mode, header line or margin? */
27797 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
27798 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
27800 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
27804 #ifdef HAVE_WINDOW_SYSTEM
27805 if (part
== ON_VERTICAL_BORDER
)
27807 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27808 help_echo_string
= build_string ("drag-mouse-1: resize");
27810 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
27811 || part
== ON_SCROLL_BAR
)
27812 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27814 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27817 /* Are we in a window whose display is up to date?
27818 And verify the buffer's text has not changed. */
27819 b
= XBUFFER (w
->buffer
);
27820 if (part
== ON_TEXT
27821 && EQ (w
->window_end_valid
, w
->buffer
)
27822 && w
->last_modified
== BUF_MODIFF (b
)
27823 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
27825 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
27827 struct glyph
*glyph
;
27828 Lisp_Object object
;
27829 Lisp_Object mouse_face
= Qnil
, position
;
27830 Lisp_Object
*overlay_vec
= NULL
;
27831 ptrdiff_t i
, noverlays
;
27832 struct buffer
*obuf
;
27833 ptrdiff_t obegv
, ozv
;
27836 /* Find the glyph under X/Y. */
27837 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
27839 #ifdef HAVE_WINDOW_SYSTEM
27840 /* Look for :pointer property on image. */
27841 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
27843 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
27844 if (img
!= NULL
&& IMAGEP (img
->spec
))
27846 Lisp_Object image_map
, hotspot
;
27847 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
27849 && (hotspot
= find_hot_spot (image_map
,
27850 glyph
->slice
.img
.x
+ dx
,
27851 glyph
->slice
.img
.y
+ dy
),
27853 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27857 /* Could check XCAR (hotspot) to see if we enter/leave
27859 If so, we could look for mouse-enter, mouse-leave
27860 properties in PLIST (and do something...). */
27861 hotspot
= XCDR (hotspot
);
27862 if (CONSP (hotspot
)
27863 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27865 pointer
= Fplist_get (plist
, Qpointer
);
27866 if (NILP (pointer
))
27868 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
27869 if (!NILP (help_echo_string
))
27871 help_echo_window
= window
;
27872 help_echo_object
= glyph
->object
;
27873 help_echo_pos
= glyph
->charpos
;
27877 if (NILP (pointer
))
27878 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
27881 #endif /* HAVE_WINDOW_SYSTEM */
27883 /* Clear mouse face if X/Y not over text. */
27885 || area
!= TEXT_AREA
27886 || !MATRIX_ROW (w
->current_matrix
, vpos
)->displays_text_p
27887 /* Glyph's OBJECT is an integer for glyphs inserted by the
27888 display engine for its internal purposes, like truncation
27889 and continuation glyphs and blanks beyond the end of
27890 line's text on text terminals. If we are over such a
27891 glyph, we are not over any text. */
27892 || INTEGERP (glyph
->object
)
27893 /* R2L rows have a stretch glyph at their front, which
27894 stands for no text, whereas L2R rows have no glyphs at
27895 all beyond the end of text. Treat such stretch glyphs
27896 like we do with NULL glyphs in L2R rows. */
27897 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
27898 && glyph
== MATRIX_ROW (w
->current_matrix
, vpos
)->glyphs
[TEXT_AREA
]
27899 && glyph
->type
== STRETCH_GLYPH
27900 && glyph
->avoid_cursor_p
))
27902 if (clear_mouse_face (hlinfo
))
27903 cursor
= No_Cursor
;
27904 #ifdef HAVE_WINDOW_SYSTEM
27905 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
27907 if (area
!= TEXT_AREA
)
27908 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27910 pointer
= Vvoid_text_area_pointer
;
27916 pos
= glyph
->charpos
;
27917 object
= glyph
->object
;
27918 if (!STRINGP (object
) && !BUFFERP (object
))
27921 /* If we get an out-of-range value, return now; avoid an error. */
27922 if (BUFFERP (object
) && pos
> BUF_Z (b
))
27925 /* Make the window's buffer temporarily current for
27926 overlays_at and compute_char_face. */
27927 obuf
= current_buffer
;
27928 current_buffer
= b
;
27934 /* Is this char mouse-active or does it have help-echo? */
27935 position
= make_number (pos
);
27937 if (BUFFERP (object
))
27939 /* Put all the overlays we want in a vector in overlay_vec. */
27940 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
27941 /* Sort overlays into increasing priority order. */
27942 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
27947 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
27950 cursor
= No_Cursor
;
27952 /* Check mouse-face highlighting. */
27954 /* If there exists an overlay with mouse-face overlapping
27955 the one we are currently highlighting, we have to
27956 check if we enter the overlapping overlay, and then
27957 highlight only that. */
27958 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
27959 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
27961 /* Find the highest priority overlay with a mouse-face. */
27962 Lisp_Object overlay
= Qnil
;
27963 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
27965 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
27966 if (!NILP (mouse_face
))
27967 overlay
= overlay_vec
[i
];
27970 /* If we're highlighting the same overlay as before, there's
27971 no need to do that again. */
27972 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
27973 goto check_help_echo
;
27974 hlinfo
->mouse_face_overlay
= overlay
;
27976 /* Clear the display of the old active region, if any. */
27977 if (clear_mouse_face (hlinfo
))
27978 cursor
= No_Cursor
;
27980 /* If no overlay applies, get a text property. */
27981 if (NILP (overlay
))
27982 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
27984 /* Next, compute the bounds of the mouse highlighting and
27986 if (!NILP (mouse_face
) && STRINGP (object
))
27988 /* The mouse-highlighting comes from a display string
27989 with a mouse-face. */
27993 s
= Fprevious_single_property_change
27994 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
27995 e
= Fnext_single_property_change
27996 (position
, Qmouse_face
, object
, Qnil
);
27998 s
= make_number (0);
28000 e
= make_number (SCHARS (object
) - 1);
28001 mouse_face_from_string_pos (w
, hlinfo
, object
,
28002 XINT (s
), XINT (e
));
28003 hlinfo
->mouse_face_past_end
= 0;
28004 hlinfo
->mouse_face_window
= window
;
28005 hlinfo
->mouse_face_face_id
28006 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28007 glyph
->face_id
, 1);
28008 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28009 cursor
= No_Cursor
;
28013 /* The mouse-highlighting, if any, comes from an overlay
28014 or text property in the buffer. */
28015 Lisp_Object buffer
IF_LINT (= Qnil
);
28016 Lisp_Object disp_string
IF_LINT (= Qnil
);
28018 if (STRINGP (object
))
28020 /* If we are on a display string with no mouse-face,
28021 check if the text under it has one. */
28022 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28023 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28024 pos
= string_buffer_position (object
, start
);
28027 mouse_face
= get_char_property_and_overlay
28028 (make_number (pos
), Qmouse_face
, w
->buffer
, &overlay
);
28029 buffer
= w
->buffer
;
28030 disp_string
= object
;
28036 disp_string
= Qnil
;
28039 if (!NILP (mouse_face
))
28041 Lisp_Object before
, after
;
28042 Lisp_Object before_string
, after_string
;
28043 /* To correctly find the limits of mouse highlight
28044 in a bidi-reordered buffer, we must not use the
28045 optimization of limiting the search in
28046 previous-single-property-change and
28047 next-single-property-change, because
28048 rows_from_pos_range needs the real start and end
28049 positions to DTRT in this case. That's because
28050 the first row visible in a window does not
28051 necessarily display the character whose position
28052 is the smallest. */
28054 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28055 ? Fmarker_position (w
->start
)
28058 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28059 ? make_number (BUF_Z (XBUFFER (buffer
))
28060 - XFASTINT (w
->window_end_pos
))
28063 if (NILP (overlay
))
28065 /* Handle the text property case. */
28066 before
= Fprevious_single_property_change
28067 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28068 after
= Fnext_single_property_change
28069 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28070 before_string
= after_string
= Qnil
;
28074 /* Handle the overlay case. */
28075 before
= Foverlay_start (overlay
);
28076 after
= Foverlay_end (overlay
);
28077 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28078 after_string
= Foverlay_get (overlay
, Qafter_string
);
28080 if (!STRINGP (before_string
)) before_string
= Qnil
;
28081 if (!STRINGP (after_string
)) after_string
= Qnil
;
28084 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28087 : XFASTINT (before
),
28089 ? BUF_Z (XBUFFER (buffer
))
28090 : XFASTINT (after
),
28091 before_string
, after_string
,
28093 cursor
= No_Cursor
;
28100 /* Look for a `help-echo' property. */
28101 if (NILP (help_echo_string
)) {
28102 Lisp_Object help
, overlay
;
28104 /* Check overlays first. */
28105 help
= overlay
= Qnil
;
28106 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28108 overlay
= overlay_vec
[i
];
28109 help
= Foverlay_get (overlay
, Qhelp_echo
);
28114 help_echo_string
= help
;
28115 help_echo_window
= window
;
28116 help_echo_object
= overlay
;
28117 help_echo_pos
= pos
;
28121 Lisp_Object obj
= glyph
->object
;
28122 ptrdiff_t charpos
= glyph
->charpos
;
28124 /* Try text properties. */
28127 && charpos
< SCHARS (obj
))
28129 help
= Fget_text_property (make_number (charpos
),
28133 /* If the string itself doesn't specify a help-echo,
28134 see if the buffer text ``under'' it does. */
28135 struct glyph_row
*r
28136 = MATRIX_ROW (w
->current_matrix
, vpos
);
28137 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28138 ptrdiff_t p
= string_buffer_position (obj
, start
);
28141 help
= Fget_char_property (make_number (p
),
28142 Qhelp_echo
, w
->buffer
);
28151 else if (BUFFERP (obj
)
28154 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28159 help_echo_string
= help
;
28160 help_echo_window
= window
;
28161 help_echo_object
= obj
;
28162 help_echo_pos
= charpos
;
28167 #ifdef HAVE_WINDOW_SYSTEM
28168 /* Look for a `pointer' property. */
28169 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28171 /* Check overlays first. */
28172 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28173 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28175 if (NILP (pointer
))
28177 Lisp_Object obj
= glyph
->object
;
28178 ptrdiff_t charpos
= glyph
->charpos
;
28180 /* Try text properties. */
28183 && charpos
< SCHARS (obj
))
28185 pointer
= Fget_text_property (make_number (charpos
),
28187 if (NILP (pointer
))
28189 /* If the string itself doesn't specify a pointer,
28190 see if the buffer text ``under'' it does. */
28191 struct glyph_row
*r
28192 = MATRIX_ROW (w
->current_matrix
, vpos
);
28193 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28194 ptrdiff_t p
= string_buffer_position (obj
, start
);
28196 pointer
= Fget_char_property (make_number (p
),
28197 Qpointer
, w
->buffer
);
28200 else if (BUFFERP (obj
)
28203 pointer
= Fget_text_property (make_number (charpos
),
28207 #endif /* HAVE_WINDOW_SYSTEM */
28211 current_buffer
= obuf
;
28216 #ifdef HAVE_WINDOW_SYSTEM
28217 if (FRAME_WINDOW_P (f
))
28218 define_frame_cursor1 (f
, cursor
, pointer
);
28220 /* This is here to prevent a compiler error, about "label at end of
28221 compound statement". */
28228 Clear any mouse-face on window W. This function is part of the
28229 redisplay interface, and is called from try_window_id and similar
28230 functions to ensure the mouse-highlight is off. */
28233 x_clear_window_mouse_face (struct window
*w
)
28235 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28236 Lisp_Object window
;
28239 XSETWINDOW (window
, w
);
28240 if (EQ (window
, hlinfo
->mouse_face_window
))
28241 clear_mouse_face (hlinfo
);
28247 Just discard the mouse face information for frame F, if any.
28248 This is used when the size of F is changed. */
28251 cancel_mouse_face (struct frame
*f
)
28253 Lisp_Object window
;
28254 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28256 window
= hlinfo
->mouse_face_window
;
28257 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28259 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28260 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28261 hlinfo
->mouse_face_window
= Qnil
;
28267 /***********************************************************************
28269 ***********************************************************************/
28271 #ifdef HAVE_WINDOW_SYSTEM
28273 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28274 which intersects rectangle R. R is in window-relative coordinates. */
28277 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28278 enum glyph_row_area area
)
28280 struct glyph
*first
= row
->glyphs
[area
];
28281 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28282 struct glyph
*last
;
28283 int first_x
, start_x
, x
;
28285 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28286 /* If row extends face to end of line write the whole line. */
28287 draw_glyphs (w
, 0, row
, area
,
28288 0, row
->used
[area
],
28289 DRAW_NORMAL_TEXT
, 0);
28292 /* Set START_X to the window-relative start position for drawing glyphs of
28293 AREA. The first glyph of the text area can be partially visible.
28294 The first glyphs of other areas cannot. */
28295 start_x
= window_box_left_offset (w
, area
);
28297 if (area
== TEXT_AREA
)
28300 /* Find the first glyph that must be redrawn. */
28302 && x
+ first
->pixel_width
< r
->x
)
28304 x
+= first
->pixel_width
;
28308 /* Find the last one. */
28312 && x
< r
->x
+ r
->width
)
28314 x
+= last
->pixel_width
;
28320 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28321 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28322 DRAW_NORMAL_TEXT
, 0);
28327 /* Redraw the parts of the glyph row ROW on window W intersecting
28328 rectangle R. R is in window-relative coordinates. Value is
28329 non-zero if mouse-face was overwritten. */
28332 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28334 eassert (row
->enabled_p
);
28336 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28337 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28338 0, row
->used
[TEXT_AREA
],
28339 DRAW_NORMAL_TEXT
, 0);
28342 if (row
->used
[LEFT_MARGIN_AREA
])
28343 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28344 if (row
->used
[TEXT_AREA
])
28345 expose_area (w
, row
, r
, TEXT_AREA
);
28346 if (row
->used
[RIGHT_MARGIN_AREA
])
28347 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28348 draw_row_fringe_bitmaps (w
, row
);
28351 return row
->mouse_face_p
;
28355 /* Redraw those parts of glyphs rows during expose event handling that
28356 overlap other rows. Redrawing of an exposed line writes over parts
28357 of lines overlapping that exposed line; this function fixes that.
28359 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28360 row in W's current matrix that is exposed and overlaps other rows.
28361 LAST_OVERLAPPING_ROW is the last such row. */
28364 expose_overlaps (struct window
*w
,
28365 struct glyph_row
*first_overlapping_row
,
28366 struct glyph_row
*last_overlapping_row
,
28369 struct glyph_row
*row
;
28371 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28372 if (row
->overlapping_p
)
28374 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28377 if (row
->used
[LEFT_MARGIN_AREA
])
28378 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28380 if (row
->used
[TEXT_AREA
])
28381 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28383 if (row
->used
[RIGHT_MARGIN_AREA
])
28384 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28390 /* Return non-zero if W's cursor intersects rectangle R. */
28393 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28395 XRectangle cr
, result
;
28396 struct glyph
*cursor_glyph
;
28397 struct glyph_row
*row
;
28399 if (w
->phys_cursor
.vpos
>= 0
28400 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28401 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28403 && row
->cursor_in_fringe_p
)
28405 /* Cursor is in the fringe. */
28406 cr
.x
= window_box_right_offset (w
,
28407 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28408 ? RIGHT_MARGIN_AREA
28411 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28412 cr
.height
= row
->height
;
28413 return x_intersect_rectangles (&cr
, r
, &result
);
28416 cursor_glyph
= get_phys_cursor_glyph (w
);
28419 /* r is relative to W's box, but w->phys_cursor.x is relative
28420 to left edge of W's TEXT area. Adjust it. */
28421 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28422 cr
.y
= w
->phys_cursor
.y
;
28423 cr
.width
= cursor_glyph
->pixel_width
;
28424 cr
.height
= w
->phys_cursor_height
;
28425 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28426 I assume the effect is the same -- and this is portable. */
28427 return x_intersect_rectangles (&cr
, r
, &result
);
28429 /* If we don't understand the format, pretend we're not in the hot-spot. */
28435 Draw a vertical window border to the right of window W if W doesn't
28436 have vertical scroll bars. */
28439 x_draw_vertical_border (struct window
*w
)
28441 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28443 /* We could do better, if we knew what type of scroll-bar the adjacent
28444 windows (on either side) have... But we don't :-(
28445 However, I think this works ok. ++KFS 2003-04-25 */
28447 /* Redraw borders between horizontally adjacent windows. Don't
28448 do it for frames with vertical scroll bars because either the
28449 right scroll bar of a window, or the left scroll bar of its
28450 neighbor will suffice as a border. */
28451 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28454 if (!WINDOW_RIGHTMOST_P (w
)
28455 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28457 int x0
, x1
, y0
, y1
;
28459 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28462 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28465 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28467 else if (!WINDOW_LEFTMOST_P (w
)
28468 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28470 int x0
, x1
, y0
, y1
;
28472 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28475 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28478 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28483 /* Redraw the part of window W intersection rectangle FR. Pixel
28484 coordinates in FR are frame-relative. Call this function with
28485 input blocked. Value is non-zero if the exposure overwrites
28489 expose_window (struct window
*w
, XRectangle
*fr
)
28491 struct frame
*f
= XFRAME (w
->frame
);
28493 int mouse_face_overwritten_p
= 0;
28495 /* If window is not yet fully initialized, do nothing. This can
28496 happen when toolkit scroll bars are used and a window is split.
28497 Reconfiguring the scroll bar will generate an expose for a newly
28499 if (w
->current_matrix
== NULL
)
28502 /* When we're currently updating the window, display and current
28503 matrix usually don't agree. Arrange for a thorough display
28505 if (w
== updated_window
)
28507 SET_FRAME_GARBAGED (f
);
28511 /* Frame-relative pixel rectangle of W. */
28512 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28513 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28514 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28515 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28517 if (x_intersect_rectangles (fr
, &wr
, &r
))
28519 int yb
= window_text_bottom_y (w
);
28520 struct glyph_row
*row
;
28521 int cursor_cleared_p
, phys_cursor_on_p
;
28522 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28524 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28525 r
.x
, r
.y
, r
.width
, r
.height
));
28527 /* Convert to window coordinates. */
28528 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28529 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28531 /* Turn off the cursor. */
28532 if (!w
->pseudo_window_p
28533 && phys_cursor_in_rect_p (w
, &r
))
28535 x_clear_cursor (w
);
28536 cursor_cleared_p
= 1;
28539 cursor_cleared_p
= 0;
28541 /* If the row containing the cursor extends face to end of line,
28542 then expose_area might overwrite the cursor outside the
28543 rectangle and thus notice_overwritten_cursor might clear
28544 w->phys_cursor_on_p. We remember the original value and
28545 check later if it is changed. */
28546 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28548 /* Update lines intersecting rectangle R. */
28549 first_overlapping_row
= last_overlapping_row
= NULL
;
28550 for (row
= w
->current_matrix
->rows
;
28555 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28557 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28558 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28559 || (r
.y
>= y0
&& r
.y
< y1
)
28560 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28562 /* A header line may be overlapping, but there is no need
28563 to fix overlapping areas for them. KFS 2005-02-12 */
28564 if (row
->overlapping_p
&& !row
->mode_line_p
)
28566 if (first_overlapping_row
== NULL
)
28567 first_overlapping_row
= row
;
28568 last_overlapping_row
= row
;
28572 if (expose_line (w
, row
, &r
))
28573 mouse_face_overwritten_p
= 1;
28576 else if (row
->overlapping_p
)
28578 /* We must redraw a row overlapping the exposed area. */
28580 ? y0
+ row
->phys_height
> r
.y
28581 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28583 if (first_overlapping_row
== NULL
)
28584 first_overlapping_row
= row
;
28585 last_overlapping_row
= row
;
28593 /* Display the mode line if there is one. */
28594 if (WINDOW_WANTS_MODELINE_P (w
)
28595 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28597 && row
->y
< r
.y
+ r
.height
)
28599 if (expose_line (w
, row
, &r
))
28600 mouse_face_overwritten_p
= 1;
28603 if (!w
->pseudo_window_p
)
28605 /* Fix the display of overlapping rows. */
28606 if (first_overlapping_row
)
28607 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28610 /* Draw border between windows. */
28611 x_draw_vertical_border (w
);
28613 /* Turn the cursor on again. */
28614 if (cursor_cleared_p
28615 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28616 update_window_cursor (w
, 1);
28620 return mouse_face_overwritten_p
;
28625 /* Redraw (parts) of all windows in the window tree rooted at W that
28626 intersect R. R contains frame pixel coordinates. Value is
28627 non-zero if the exposure overwrites mouse-face. */
28630 expose_window_tree (struct window
*w
, XRectangle
*r
)
28632 struct frame
*f
= XFRAME (w
->frame
);
28633 int mouse_face_overwritten_p
= 0;
28635 while (w
&& !FRAME_GARBAGED_P (f
))
28637 if (!NILP (w
->hchild
))
28638 mouse_face_overwritten_p
28639 |= expose_window_tree (XWINDOW (w
->hchild
), r
);
28640 else if (!NILP (w
->vchild
))
28641 mouse_face_overwritten_p
28642 |= expose_window_tree (XWINDOW (w
->vchild
), r
);
28644 mouse_face_overwritten_p
|= expose_window (w
, r
);
28646 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28649 return mouse_face_overwritten_p
;
28654 Redisplay an exposed area of frame F. X and Y are the upper-left
28655 corner of the exposed rectangle. W and H are width and height of
28656 the exposed area. All are pixel values. W or H zero means redraw
28657 the entire frame. */
28660 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28663 int mouse_face_overwritten_p
= 0;
28665 TRACE ((stderr
, "expose_frame "));
28667 /* No need to redraw if frame will be redrawn soon. */
28668 if (FRAME_GARBAGED_P (f
))
28670 TRACE ((stderr
, " garbaged\n"));
28674 /* If basic faces haven't been realized yet, there is no point in
28675 trying to redraw anything. This can happen when we get an expose
28676 event while Emacs is starting, e.g. by moving another window. */
28677 if (FRAME_FACE_CACHE (f
) == NULL
28678 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28680 TRACE ((stderr
, " no faces\n"));
28684 if (w
== 0 || h
== 0)
28687 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28688 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28698 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28699 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28701 if (WINDOWP (f
->tool_bar_window
))
28702 mouse_face_overwritten_p
28703 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28705 #ifdef HAVE_X_WINDOWS
28707 #ifndef USE_X_TOOLKIT
28708 if (WINDOWP (f
->menu_bar_window
))
28709 mouse_face_overwritten_p
28710 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28711 #endif /* not USE_X_TOOLKIT */
28715 /* Some window managers support a focus-follows-mouse style with
28716 delayed raising of frames. Imagine a partially obscured frame,
28717 and moving the mouse into partially obscured mouse-face on that
28718 frame. The visible part of the mouse-face will be highlighted,
28719 then the WM raises the obscured frame. With at least one WM, KDE
28720 2.1, Emacs is not getting any event for the raising of the frame
28721 (even tried with SubstructureRedirectMask), only Expose events.
28722 These expose events will draw text normally, i.e. not
28723 highlighted. Which means we must redo the highlight here.
28724 Subsume it under ``we love X''. --gerd 2001-08-15 */
28725 /* Included in Windows version because Windows most likely does not
28726 do the right thing if any third party tool offers
28727 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28728 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28730 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28731 if (f
== hlinfo
->mouse_face_mouse_frame
)
28733 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28734 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28735 clear_mouse_face (hlinfo
);
28736 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28743 Determine the intersection of two rectangles R1 and R2. Return
28744 the intersection in *RESULT. Value is non-zero if RESULT is not
28748 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28750 XRectangle
*left
, *right
;
28751 XRectangle
*upper
, *lower
;
28752 int intersection_p
= 0;
28754 /* Rearrange so that R1 is the left-most rectangle. */
28756 left
= r1
, right
= r2
;
28758 left
= r2
, right
= r1
;
28760 /* X0 of the intersection is right.x0, if this is inside R1,
28761 otherwise there is no intersection. */
28762 if (right
->x
<= left
->x
+ left
->width
)
28764 result
->x
= right
->x
;
28766 /* The right end of the intersection is the minimum of
28767 the right ends of left and right. */
28768 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
28771 /* Same game for Y. */
28773 upper
= r1
, lower
= r2
;
28775 upper
= r2
, lower
= r1
;
28777 /* The upper end of the intersection is lower.y0, if this is inside
28778 of upper. Otherwise, there is no intersection. */
28779 if (lower
->y
<= upper
->y
+ upper
->height
)
28781 result
->y
= lower
->y
;
28783 /* The lower end of the intersection is the minimum of the lower
28784 ends of upper and lower. */
28785 result
->height
= (min (lower
->y
+ lower
->height
,
28786 upper
->y
+ upper
->height
)
28788 intersection_p
= 1;
28792 return intersection_p
;
28795 #endif /* HAVE_WINDOW_SYSTEM */
28798 /***********************************************************************
28800 ***********************************************************************/
28803 syms_of_xdisp (void)
28805 Vwith_echo_area_save_vector
= Qnil
;
28806 staticpro (&Vwith_echo_area_save_vector
);
28808 Vmessage_stack
= Qnil
;
28809 staticpro (&Vmessage_stack
);
28811 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
28812 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
28814 message_dolog_marker1
= Fmake_marker ();
28815 staticpro (&message_dolog_marker1
);
28816 message_dolog_marker2
= Fmake_marker ();
28817 staticpro (&message_dolog_marker2
);
28818 message_dolog_marker3
= Fmake_marker ();
28819 staticpro (&message_dolog_marker3
);
28822 defsubr (&Sdump_frame_glyph_matrix
);
28823 defsubr (&Sdump_glyph_matrix
);
28824 defsubr (&Sdump_glyph_row
);
28825 defsubr (&Sdump_tool_bar_row
);
28826 defsubr (&Strace_redisplay
);
28827 defsubr (&Strace_to_stderr
);
28829 #ifdef HAVE_WINDOW_SYSTEM
28830 defsubr (&Stool_bar_lines_needed
);
28831 defsubr (&Slookup_image_map
);
28833 defsubr (&Sformat_mode_line
);
28834 defsubr (&Sinvisible_p
);
28835 defsubr (&Scurrent_bidi_paragraph_direction
);
28837 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
28838 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
28839 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
28840 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
28841 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
28842 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
28843 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
28844 DEFSYM (Qeval
, "eval");
28845 DEFSYM (QCdata
, ":data");
28846 DEFSYM (Qdisplay
, "display");
28847 DEFSYM (Qspace_width
, "space-width");
28848 DEFSYM (Qraise
, "raise");
28849 DEFSYM (Qslice
, "slice");
28850 DEFSYM (Qspace
, "space");
28851 DEFSYM (Qmargin
, "margin");
28852 DEFSYM (Qpointer
, "pointer");
28853 DEFSYM (Qleft_margin
, "left-margin");
28854 DEFSYM (Qright_margin
, "right-margin");
28855 DEFSYM (Qcenter
, "center");
28856 DEFSYM (Qline_height
, "line-height");
28857 DEFSYM (QCalign_to
, ":align-to");
28858 DEFSYM (QCrelative_width
, ":relative-width");
28859 DEFSYM (QCrelative_height
, ":relative-height");
28860 DEFSYM (QCeval
, ":eval");
28861 DEFSYM (QCpropertize
, ":propertize");
28862 DEFSYM (QCfile
, ":file");
28863 DEFSYM (Qfontified
, "fontified");
28864 DEFSYM (Qfontification_functions
, "fontification-functions");
28865 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
28866 DEFSYM (Qescape_glyph
, "escape-glyph");
28867 DEFSYM (Qnobreak_space
, "nobreak-space");
28868 DEFSYM (Qimage
, "image");
28869 DEFSYM (Qtext
, "text");
28870 DEFSYM (Qboth
, "both");
28871 DEFSYM (Qboth_horiz
, "both-horiz");
28872 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
28873 DEFSYM (QCmap
, ":map");
28874 DEFSYM (QCpointer
, ":pointer");
28875 DEFSYM (Qrect
, "rect");
28876 DEFSYM (Qcircle
, "circle");
28877 DEFSYM (Qpoly
, "poly");
28878 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
28879 DEFSYM (Qgrow_only
, "grow-only");
28880 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
28881 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
28882 DEFSYM (Qposition
, "position");
28883 DEFSYM (Qbuffer_position
, "buffer-position");
28884 DEFSYM (Qobject
, "object");
28885 DEFSYM (Qbar
, "bar");
28886 DEFSYM (Qhbar
, "hbar");
28887 DEFSYM (Qbox
, "box");
28888 DEFSYM (Qhollow
, "hollow");
28889 DEFSYM (Qhand
, "hand");
28890 DEFSYM (Qarrow
, "arrow");
28891 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
28893 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
28894 Fcons (intern_c_string ("void-variable"), Qnil
)),
28896 staticpro (&list_of_error
);
28898 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
28899 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
28900 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
28901 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
28903 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
28904 staticpro (&echo_buffer
[0]);
28905 staticpro (&echo_buffer
[1]);
28907 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
28908 staticpro (&echo_area_buffer
[0]);
28909 staticpro (&echo_area_buffer
[1]);
28911 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
28912 staticpro (&Vmessages_buffer_name
);
28914 mode_line_proptrans_alist
= Qnil
;
28915 staticpro (&mode_line_proptrans_alist
);
28916 mode_line_string_list
= Qnil
;
28917 staticpro (&mode_line_string_list
);
28918 mode_line_string_face
= Qnil
;
28919 staticpro (&mode_line_string_face
);
28920 mode_line_string_face_prop
= Qnil
;
28921 staticpro (&mode_line_string_face_prop
);
28922 Vmode_line_unwind_vector
= Qnil
;
28923 staticpro (&Vmode_line_unwind_vector
);
28925 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
28927 help_echo_string
= Qnil
;
28928 staticpro (&help_echo_string
);
28929 help_echo_object
= Qnil
;
28930 staticpro (&help_echo_object
);
28931 help_echo_window
= Qnil
;
28932 staticpro (&help_echo_window
);
28933 previous_help_echo_string
= Qnil
;
28934 staticpro (&previous_help_echo_string
);
28935 help_echo_pos
= -1;
28937 DEFSYM (Qright_to_left
, "right-to-left");
28938 DEFSYM (Qleft_to_right
, "left-to-right");
28940 #ifdef HAVE_WINDOW_SYSTEM
28941 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
28942 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
28943 For example, if a block cursor is over a tab, it will be drawn as
28944 wide as that tab on the display. */);
28945 x_stretch_cursor_p
= 0;
28948 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
28949 doc
: /* Non-nil means highlight trailing whitespace.
28950 The face used for trailing whitespace is `trailing-whitespace'. */);
28951 Vshow_trailing_whitespace
= Qnil
;
28953 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
28954 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
28955 If the value is t, Emacs highlights non-ASCII chars which have the
28956 same appearance as an ASCII space or hyphen, using the `nobreak-space'
28957 or `escape-glyph' face respectively.
28959 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
28960 U+2011 (non-breaking hyphen) are affected.
28962 Any other non-nil value means to display these characters as a escape
28963 glyph followed by an ordinary space or hyphen.
28965 A value of nil means no special handling of these characters. */);
28966 Vnobreak_char_display
= Qt
;
28968 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
28969 doc
: /* The pointer shape to show in void text areas.
28970 A value of nil means to show the text pointer. Other options are `arrow',
28971 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
28972 Vvoid_text_area_pointer
= Qarrow
;
28974 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
28975 doc
: /* Non-nil means don't actually do any redisplay.
28976 This is used for internal purposes. */);
28977 Vinhibit_redisplay
= Qnil
;
28979 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
28980 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
28981 Vglobal_mode_string
= Qnil
;
28983 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
28984 doc
: /* Marker for where to display an arrow on top of the buffer text.
28985 This must be the beginning of a line in order to work.
28986 See also `overlay-arrow-string'. */);
28987 Voverlay_arrow_position
= Qnil
;
28989 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
28990 doc
: /* String to display as an arrow in non-window frames.
28991 See also `overlay-arrow-position'. */);
28992 Voverlay_arrow_string
= build_pure_c_string ("=>");
28994 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
28995 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
28996 The symbols on this list are examined during redisplay to determine
28997 where to display overlay arrows. */);
28998 Voverlay_arrow_variable_list
28999 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
29001 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29002 doc
: /* The number of lines to try scrolling a window by when point moves out.
29003 If that fails to bring point back on frame, point is centered instead.
29004 If this is zero, point is always centered after it moves off frame.
29005 If you want scrolling to always be a line at a time, you should set
29006 `scroll-conservatively' to a large value rather than set this to 1. */);
29008 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29009 doc
: /* Scroll up to this many lines, to bring point back on screen.
29010 If point moves off-screen, redisplay will scroll by up to
29011 `scroll-conservatively' lines in order to bring point just barely
29012 onto the screen again. If that cannot be done, then redisplay
29013 recenters point as usual.
29015 If the value is greater than 100, redisplay will never recenter point,
29016 but will always scroll just enough text to bring point into view, even
29017 if you move far away.
29019 A value of zero means always recenter point if it moves off screen. */);
29020 scroll_conservatively
= 0;
29022 DEFVAR_INT ("scroll-margin", scroll_margin
,
29023 doc
: /* Number of lines of margin at the top and bottom of a window.
29024 Recenter the window whenever point gets within this many lines
29025 of the top or bottom of the window. */);
29028 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29029 doc
: /* Pixels per inch value for non-window system displays.
29030 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29031 Vdisplay_pixels_per_inch
= make_float (72.0);
29034 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29037 DEFVAR_LISP ("truncate-partial-width-windows",
29038 Vtruncate_partial_width_windows
,
29039 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29040 For an integer value, truncate lines in each window narrower than the
29041 full frame width, provided the window width is less than that integer;
29042 otherwise, respect the value of `truncate-lines'.
29044 For any other non-nil value, truncate lines in all windows that do
29045 not span the full frame width.
29047 A value of nil means to respect the value of `truncate-lines'.
29049 If `word-wrap' is enabled, you might want to reduce this. */);
29050 Vtruncate_partial_width_windows
= make_number (50);
29052 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29053 doc
: /* Maximum buffer size for which line number should be displayed.
29054 If the buffer is bigger than this, the line number does not appear
29055 in the mode line. A value of nil means no limit. */);
29056 Vline_number_display_limit
= Qnil
;
29058 DEFVAR_INT ("line-number-display-limit-width",
29059 line_number_display_limit_width
,
29060 doc
: /* Maximum line width (in characters) for line number display.
29061 If the average length of the lines near point is bigger than this, then the
29062 line number may be omitted from the mode line. */);
29063 line_number_display_limit_width
= 200;
29065 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29066 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29067 highlight_nonselected_windows
= 0;
29069 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29070 doc
: /* Non-nil if more than one frame is visible on this display.
29071 Minibuffer-only frames don't count, but iconified frames do.
29072 This variable is not guaranteed to be accurate except while processing
29073 `frame-title-format' and `icon-title-format'. */);
29075 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29076 doc
: /* Template for displaying the title bar of visible frames.
29077 \(Assuming the window manager supports this feature.)
29079 This variable has the same structure as `mode-line-format', except that
29080 the %c and %l constructs are ignored. It is used only on frames for
29081 which no explicit name has been set \(see `modify-frame-parameters'). */);
29083 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29084 doc
: /* Template for displaying the title bar of an iconified frame.
29085 \(Assuming the window manager supports this feature.)
29086 This variable has the same structure as `mode-line-format' (which see),
29087 and is used only on frames for which no explicit name has been set
29088 \(see `modify-frame-parameters'). */);
29090 = Vframe_title_format
29091 = listn (CONSTYPE_PURE
, 3,
29092 intern_c_string ("multiple-frames"),
29093 build_pure_c_string ("%b"),
29094 listn (CONSTYPE_PURE
, 4,
29095 empty_unibyte_string
,
29096 intern_c_string ("invocation-name"),
29097 build_pure_c_string ("@"),
29098 intern_c_string ("system-name")));
29100 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29101 doc
: /* Maximum number of lines to keep in the message log buffer.
29102 If nil, disable message logging. If t, log messages but don't truncate
29103 the buffer when it becomes large. */);
29104 Vmessage_log_max
= make_number (1000);
29106 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29107 doc
: /* Functions called before redisplay, if window sizes have changed.
29108 The value should be a list of functions that take one argument.
29109 Just before redisplay, for each frame, if any of its windows have changed
29110 size since the last redisplay, or have been split or deleted,
29111 all the functions in the list are called, with the frame as argument. */);
29112 Vwindow_size_change_functions
= Qnil
;
29114 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29115 doc
: /* List of functions to call before redisplaying a window with scrolling.
29116 Each function is called with two arguments, the window and its new
29117 display-start position. Note that these functions are also called by
29118 `set-window-buffer'. Also note that the value of `window-end' is not
29119 valid when these functions are called.
29121 Warning: Do not use this feature to alter the way the window
29122 is scrolled. It is not designed for that, and such use probably won't
29124 Vwindow_scroll_functions
= Qnil
;
29126 DEFVAR_LISP ("window-text-change-functions",
29127 Vwindow_text_change_functions
,
29128 doc
: /* Functions to call in redisplay when text in the window might change. */);
29129 Vwindow_text_change_functions
= Qnil
;
29131 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29132 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29133 Each function is called with two arguments, the window and the end trigger value.
29134 See `set-window-redisplay-end-trigger'. */);
29135 Vredisplay_end_trigger_functions
= Qnil
;
29137 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29138 doc
: /* Non-nil means autoselect window with mouse pointer.
29139 If nil, do not autoselect windows.
29140 A positive number means delay autoselection by that many seconds: a
29141 window is autoselected only after the mouse has remained in that
29142 window for the duration of the delay.
29143 A negative number has a similar effect, but causes windows to be
29144 autoselected only after the mouse has stopped moving. \(Because of
29145 the way Emacs compares mouse events, you will occasionally wait twice
29146 that time before the window gets selected.\)
29147 Any other value means to autoselect window instantaneously when the
29148 mouse pointer enters it.
29150 Autoselection selects the minibuffer only if it is active, and never
29151 unselects the minibuffer if it is active.
29153 When customizing this variable make sure that the actual value of
29154 `focus-follows-mouse' matches the behavior of your window manager. */);
29155 Vmouse_autoselect_window
= Qnil
;
29157 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29158 doc
: /* Non-nil means automatically resize tool-bars.
29159 This dynamically changes the tool-bar's height to the minimum height
29160 that is needed to make all tool-bar items visible.
29161 If value is `grow-only', the tool-bar's height is only increased
29162 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29163 Vauto_resize_tool_bars
= Qt
;
29165 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29166 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29167 auto_raise_tool_bar_buttons_p
= 1;
29169 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29170 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29171 make_cursor_line_fully_visible_p
= 1;
29173 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29174 doc
: /* Border below tool-bar in pixels.
29175 If an integer, use it as the height of the border.
29176 If it is one of `internal-border-width' or `border-width', use the
29177 value of the corresponding frame parameter.
29178 Otherwise, no border is added below the tool-bar. */);
29179 Vtool_bar_border
= Qinternal_border_width
;
29181 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29182 doc
: /* Margin around tool-bar buttons in pixels.
29183 If an integer, use that for both horizontal and vertical margins.
29184 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29185 HORZ specifying the horizontal margin, and VERT specifying the
29186 vertical margin. */);
29187 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29189 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29190 doc
: /* Relief thickness of tool-bar buttons. */);
29191 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29193 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29194 doc
: /* Tool bar style to use.
29196 image - show images only
29197 text - show text only
29198 both - show both, text below image
29199 both-horiz - show text to the right of the image
29200 text-image-horiz - show text to the left of the image
29201 any other - use system default or image if no system default.
29203 This variable only affects the GTK+ toolkit version of Emacs. */);
29204 Vtool_bar_style
= Qnil
;
29206 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29207 doc
: /* Maximum number of characters a label can have to be shown.
29208 The tool bar style must also show labels for this to have any effect, see
29209 `tool-bar-style'. */);
29210 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29212 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29213 doc
: /* List of functions to call to fontify regions of text.
29214 Each function is called with one argument POS. Functions must
29215 fontify a region starting at POS in the current buffer, and give
29216 fontified regions the property `fontified'. */);
29217 Vfontification_functions
= Qnil
;
29218 Fmake_variable_buffer_local (Qfontification_functions
);
29220 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29221 unibyte_display_via_language_environment
,
29222 doc
: /* Non-nil means display unibyte text according to language environment.
29223 Specifically, this means that raw bytes in the range 160-255 decimal
29224 are displayed by converting them to the equivalent multibyte characters
29225 according to the current language environment. As a result, they are
29226 displayed according to the current fontset.
29228 Note that this variable affects only how these bytes are displayed,
29229 but does not change the fact they are interpreted as raw bytes. */);
29230 unibyte_display_via_language_environment
= 0;
29232 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29233 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29234 If a float, it specifies a fraction of the mini-window frame's height.
29235 If an integer, it specifies a number of lines. */);
29236 Vmax_mini_window_height
= make_float (0.25);
29238 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29239 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29240 A value of nil means don't automatically resize mini-windows.
29241 A value of t means resize them to fit the text displayed in them.
29242 A value of `grow-only', the default, means let mini-windows grow only;
29243 they return to their normal size when the minibuffer is closed, or the
29244 echo area becomes empty. */);
29245 Vresize_mini_windows
= Qgrow_only
;
29247 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29248 doc
: /* Alist specifying how to blink the cursor off.
29249 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29250 `cursor-type' frame-parameter or variable equals ON-STATE,
29251 comparing using `equal', Emacs uses OFF-STATE to specify
29252 how to blink it off. ON-STATE and OFF-STATE are values for
29253 the `cursor-type' frame parameter.
29255 If a frame's ON-STATE has no entry in this list,
29256 the frame's other specifications determine how to blink the cursor off. */);
29257 Vblink_cursor_alist
= Qnil
;
29259 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29260 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29261 If non-nil, windows are automatically scrolled horizontally to make
29262 point visible. */);
29263 automatic_hscrolling_p
= 1;
29264 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29266 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29267 doc
: /* How many columns away from the window edge point is allowed to get
29268 before automatic hscrolling will horizontally scroll the window. */);
29269 hscroll_margin
= 5;
29271 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29272 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29273 When point is less than `hscroll-margin' columns from the window
29274 edge, automatic hscrolling will scroll the window by the amount of columns
29275 determined by this variable. If its value is a positive integer, scroll that
29276 many columns. If it's a positive floating-point number, it specifies the
29277 fraction of the window's width to scroll. If it's nil or zero, point will be
29278 centered horizontally after the scroll. Any other value, including negative
29279 numbers, are treated as if the value were zero.
29281 Automatic hscrolling always moves point outside the scroll margin, so if
29282 point was more than scroll step columns inside the margin, the window will
29283 scroll more than the value given by the scroll step.
29285 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29286 and `scroll-right' overrides this variable's effect. */);
29287 Vhscroll_step
= make_number (0);
29289 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29290 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29291 Bind this around calls to `message' to let it take effect. */);
29292 message_truncate_lines
= 0;
29294 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29295 doc
: /* Normal hook run to update the menu bar definitions.
29296 Redisplay runs this hook before it redisplays the menu bar.
29297 This is used to update submenus such as Buffers,
29298 whose contents depend on various data. */);
29299 Vmenu_bar_update_hook
= Qnil
;
29301 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29302 doc
: /* Frame for which we are updating a menu.
29303 The enable predicate for a menu binding should check this variable. */);
29304 Vmenu_updating_frame
= Qnil
;
29306 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29307 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29308 inhibit_menubar_update
= 0;
29310 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29311 doc
: /* Prefix prepended to all continuation lines at display time.
29312 The value may be a string, an image, or a stretch-glyph; it is
29313 interpreted in the same way as the value of a `display' text property.
29315 This variable is overridden by any `wrap-prefix' text or overlay
29318 To add a prefix to non-continuation lines, use `line-prefix'. */);
29319 Vwrap_prefix
= Qnil
;
29320 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29321 Fmake_variable_buffer_local (Qwrap_prefix
);
29323 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29324 doc
: /* Prefix prepended to all non-continuation lines at display time.
29325 The value may be a string, an image, or a stretch-glyph; it is
29326 interpreted in the same way as the value of a `display' text property.
29328 This variable is overridden by any `line-prefix' text or overlay
29331 To add a prefix to continuation lines, use `wrap-prefix'. */);
29332 Vline_prefix
= Qnil
;
29333 DEFSYM (Qline_prefix
, "line-prefix");
29334 Fmake_variable_buffer_local (Qline_prefix
);
29336 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29337 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29338 inhibit_eval_during_redisplay
= 0;
29340 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29341 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29342 inhibit_free_realized_faces
= 0;
29345 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29346 doc
: /* Inhibit try_window_id display optimization. */);
29347 inhibit_try_window_id
= 0;
29349 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29350 doc
: /* Inhibit try_window_reusing display optimization. */);
29351 inhibit_try_window_reusing
= 0;
29353 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29354 doc
: /* Inhibit try_cursor_movement display optimization. */);
29355 inhibit_try_cursor_movement
= 0;
29356 #endif /* GLYPH_DEBUG */
29358 DEFVAR_INT ("overline-margin", overline_margin
,
29359 doc
: /* Space between overline and text, in pixels.
29360 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29361 margin to the character height. */);
29362 overline_margin
= 2;
29364 DEFVAR_INT ("underline-minimum-offset",
29365 underline_minimum_offset
,
29366 doc
: /* Minimum distance between baseline and underline.
29367 This can improve legibility of underlined text at small font sizes,
29368 particularly when using variable `x-use-underline-position-properties'
29369 with fonts that specify an UNDERLINE_POSITION relatively close to the
29370 baseline. The default value is 1. */);
29371 underline_minimum_offset
= 1;
29373 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29374 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29375 This feature only works when on a window system that can change
29376 cursor shapes. */);
29377 display_hourglass_p
= 1;
29379 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29380 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29381 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29383 hourglass_atimer
= NULL
;
29384 hourglass_shown_p
= 0;
29386 DEFSYM (Qglyphless_char
, "glyphless-char");
29387 DEFSYM (Qhex_code
, "hex-code");
29388 DEFSYM (Qempty_box
, "empty-box");
29389 DEFSYM (Qthin_space
, "thin-space");
29390 DEFSYM (Qzero_width
, "zero-width");
29392 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29393 /* Intern this now in case it isn't already done.
29394 Setting this variable twice is harmless.
29395 But don't staticpro it here--that is done in alloc.c. */
29396 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29397 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29399 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29400 doc
: /* Char-table defining glyphless characters.
29401 Each element, if non-nil, should be one of the following:
29402 an ASCII acronym string: display this string in a box
29403 `hex-code': display the hexadecimal code of a character in a box
29404 `empty-box': display as an empty box
29405 `thin-space': display as 1-pixel width space
29406 `zero-width': don't display
29407 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29408 display method for graphical terminals and text terminals respectively.
29409 GRAPHICAL and TEXT should each have one of the values listed above.
29411 The char-table has one extra slot to control the display of a character for
29412 which no font is found. This slot only takes effect on graphical terminals.
29413 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29414 `thin-space'. The default is `empty-box'. */);
29415 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29416 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29419 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29420 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29421 Vdebug_on_message
= Qnil
;
29425 /* Initialize this module when Emacs starts. */
29430 current_header_line_height
= current_mode_line_height
= -1;
29432 CHARPOS (this_line_start_pos
) = 0;
29434 if (!noninteractive
)
29436 struct window
*m
= XWINDOW (minibuf_window
);
29437 Lisp_Object frame
= m
->frame
;
29438 struct frame
*f
= XFRAME (frame
);
29439 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29440 struct window
*r
= XWINDOW (root
);
29443 echo_area_window
= minibuf_window
;
29445 wset_top_line (r
, make_number (FRAME_TOP_MARGIN (f
)));
29447 (r
, make_number (FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
)));
29448 wset_total_cols (r
, make_number (FRAME_COLS (f
)));
29449 wset_top_line (m
, make_number (FRAME_LINES (f
) - 1));
29450 wset_total_lines (m
, make_number (1));
29451 wset_total_cols (m
, make_number (FRAME_COLS (f
)));
29453 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29454 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29455 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29457 /* The default ellipsis glyphs `...'. */
29458 for (i
= 0; i
< 3; ++i
)
29459 default_invis_vector
[i
] = make_number ('.');
29463 /* Allocate the buffer for frame titles.
29464 Also used for `format-mode-line'. */
29466 mode_line_noprop_buf
= xmalloc (size
);
29467 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29468 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29469 mode_line_target
= MODE_LINE_DISPLAY
;
29472 help_echo_showing_p
= 0;
29475 /* Platform-independent portion of hourglass implementation. */
29477 /* Cancel a currently active hourglass timer, and start a new one. */
29479 start_hourglass (void)
29481 #if defined (HAVE_WINDOW_SYSTEM)
29484 cancel_hourglass ();
29486 if (INTEGERP (Vhourglass_delay
)
29487 && XINT (Vhourglass_delay
) > 0)
29488 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29489 TYPE_MAXIMUM (time_t)),
29491 else if (FLOATP (Vhourglass_delay
)
29492 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29493 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29495 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29499 extern void w32_note_current_window (void);
29500 w32_note_current_window ();
29502 #endif /* HAVE_NTGUI */
29504 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29505 show_hourglass
, NULL
);
29510 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29513 cancel_hourglass (void)
29515 #if defined (HAVE_WINDOW_SYSTEM)
29516 if (hourglass_atimer
)
29518 cancel_atimer (hourglass_atimer
);
29519 hourglass_atimer
= NULL
;
29522 if (hourglass_shown_p
)