1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2013 Free Software Foundation,
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code.
36 The following diagram shows how redisplay code is invoked. As you
37 can see, Lisp calls redisplay and vice versa. Under window systems
38 like X, some portions of the redisplay code are also called
39 asynchronously during mouse movement or expose events. It is very
40 important that these code parts do NOT use the C library (malloc,
41 free) because many C libraries under Unix are not reentrant. They
42 may also NOT call functions of the Lisp interpreter which could
43 change the interpreter's state. If you don't follow these rules,
44 you will encounter bugs which are very hard to explain.
46 +--------------+ redisplay +----------------+
47 | Lisp machine |---------------->| Redisplay code |<--+
48 +--------------+ (xdisp.c) +----------------+ |
50 +----------------------------------+ |
51 Don't use this path when called |
54 expose_window (asynchronous) |
56 X expose events -----+
58 What does redisplay do? Obviously, it has to figure out somehow what
59 has been changed since the last time the display has been updated,
60 and to make these changes visible. Preferably it would do that in
61 a moderately intelligent way, i.e. fast.
63 Changes in buffer text can be deduced from window and buffer
64 structures, and from some global variables like `beg_unchanged' and
65 `end_unchanged'. The contents of the display are additionally
66 recorded in a `glyph matrix', a two-dimensional matrix of glyph
67 structures. Each row in such a matrix corresponds to a line on the
68 display, and each glyph in a row corresponds to a column displaying
69 a character, an image, or what else. This matrix is called the
70 `current glyph matrix' or `current matrix' in redisplay
73 For buffer parts that have been changed since the last update, a
74 second glyph matrix is constructed, the so called `desired glyph
75 matrix' or short `desired matrix'. Current and desired matrix are
76 then compared to find a cheap way to update the display, e.g. by
77 reusing part of the display by scrolling lines.
79 You will find a lot of redisplay optimizations when you start
80 looking at the innards of redisplay. The overall goal of all these
81 optimizations is to make redisplay fast because it is done
82 frequently. Some of these optimizations are implemented by the
87 This function tries to update the display if the text in the
88 window did not change and did not scroll, only point moved, and
89 it did not move off the displayed portion of the text.
91 . try_window_reusing_current_matrix
93 This function reuses the current matrix of a window when text
94 has not changed, but the window start changed (e.g., due to
99 This function attempts to redisplay a window by reusing parts of
100 its existing display. It finds and reuses the part that was not
101 changed, and redraws the rest.
105 This function performs the full redisplay of a single window
106 assuming that its fonts were not changed and that the cursor
107 will not end up in the scroll margins. (Loading fonts requires
108 re-adjustment of dimensions of glyph matrices, which makes this
109 method impossible to use.)
111 These optimizations are tried in sequence (some can be skipped if
112 it is known that they are not applicable). If none of the
113 optimizations were successful, redisplay calls redisplay_windows,
114 which performs a full redisplay of all windows.
118 Desired matrices are always built per Emacs window. The function
119 `display_line' is the central function to look at if you are
120 interested. It constructs one row in a desired matrix given an
121 iterator structure containing both a buffer position and a
122 description of the environment in which the text is to be
123 displayed. But this is too early, read on.
125 Characters and pixmaps displayed for a range of buffer text depend
126 on various settings of buffers and windows, on overlays and text
127 properties, on display tables, on selective display. The good news
128 is that all this hairy stuff is hidden behind a small set of
129 interface functions taking an iterator structure (struct it)
132 Iteration over things to be displayed is then simple. It is
133 started by initializing an iterator with a call to init_iterator,
134 passing it the buffer position where to start iteration. For
135 iteration over strings, pass -1 as the position to init_iterator,
136 and call reseat_to_string when the string is ready, to initialize
137 the iterator for that string. Thereafter, calls to
138 get_next_display_element fill the iterator structure with relevant
139 information about the next thing to display. Calls to
140 set_iterator_to_next move the iterator to the next thing.
142 Besides this, an iterator also contains information about the
143 display environment in which glyphs for display elements are to be
144 produced. It has fields for the width and height of the display,
145 the information whether long lines are truncated or continued, a
146 current X and Y position, and lots of other stuff you can better
149 Glyphs in a desired matrix are normally constructed in a loop
150 calling get_next_display_element and then PRODUCE_GLYPHS. The call
151 to PRODUCE_GLYPHS will fill the iterator structure with pixel
152 information about the element being displayed and at the same time
153 produce glyphs for it. If the display element fits on the line
154 being displayed, set_iterator_to_next is called next, otherwise the
155 glyphs produced are discarded. The function display_line is the
156 workhorse of filling glyph rows in the desired matrix with glyphs.
157 In addition to producing glyphs, it also handles line truncation
158 and continuation, word wrap, and cursor positioning (for the
159 latter, see also set_cursor_from_row).
163 That just couldn't be all, could it? What about terminal types not
164 supporting operations on sub-windows of the screen? To update the
165 display on such a terminal, window-based glyph matrices are not
166 well suited. To be able to reuse part of the display (scrolling
167 lines up and down), we must instead have a view of the whole
168 screen. This is what `frame matrices' are for. They are a trick.
170 Frames on terminals like above have a glyph pool. Windows on such
171 a frame sub-allocate their glyph memory from their frame's glyph
172 pool. The frame itself is given its own glyph matrices. By
173 coincidence---or maybe something else---rows in window glyph
174 matrices are slices of corresponding rows in frame matrices. Thus
175 writing to window matrices implicitly updates a frame matrix which
176 provides us with the view of the whole screen that we originally
177 wanted to have without having to move many bytes around. To be
178 honest, there is a little bit more done, but not much more. If you
179 plan to extend that code, take a look at dispnew.c. The function
180 build_frame_matrix is a good starting point.
182 Bidirectional display.
184 Bidirectional display adds quite some hair to this already complex
185 design. The good news are that a large portion of that hairy stuff
186 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
187 reordering engine which is called by set_iterator_to_next and
188 returns the next character to display in the visual order. See
189 commentary on bidi.c for more details. As far as redisplay is
190 concerned, the effect of calling bidi_move_to_visually_next, the
191 main interface of the reordering engine, is that the iterator gets
192 magically placed on the buffer or string position that is to be
193 displayed next. In other words, a linear iteration through the
194 buffer/string is replaced with a non-linear one. All the rest of
195 the redisplay is oblivious to the bidi reordering.
197 Well, almost oblivious---there are still complications, most of
198 them due to the fact that buffer and string positions no longer
199 change monotonously with glyph indices in a glyph row. Moreover,
200 for continued lines, the buffer positions may not even be
201 monotonously changing with vertical positions. Also, accounting
202 for face changes, overlays, etc. becomes more complex because
203 non-linear iteration could potentially skip many positions with
204 changes, and then cross them again on the way back...
206 One other prominent effect of bidirectional display is that some
207 paragraphs of text need to be displayed starting at the right
208 margin of the window---the so-called right-to-left, or R2L
209 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
210 which have their reversed_p flag set. The bidi reordering engine
211 produces characters in such rows starting from the character which
212 should be the rightmost on display. PRODUCE_GLYPHS then reverses
213 the order, when it fills up the glyph row whose reversed_p flag is
214 set, by prepending each new glyph to what is already there, instead
215 of appending it. When the glyph row is complete, the function
216 extend_face_to_end_of_line fills the empty space to the left of the
217 leftmost character with special glyphs, which will display as,
218 well, empty. On text terminals, these special glyphs are simply
219 blank characters. On graphics terminals, there's a single stretch
220 glyph of a suitably computed width. Both the blanks and the
221 stretch glyph are given the face of the background of the line.
222 This way, the terminal-specific back-end can still draw the glyphs
223 left to right, even for R2L lines.
225 Bidirectional display and character compositions
227 Some scripts cannot be displayed by drawing each character
228 individually, because adjacent characters change each other's shape
229 on display. For example, Arabic and Indic scripts belong to this
232 Emacs display supports this by providing "character compositions",
233 most of which is implemented in composite.c. During the buffer
234 scan that delivers characters to PRODUCE_GLYPHS, if the next
235 character to be delivered is a composed character, the iteration
236 calls composition_reseat_it and next_element_from_composition. If
237 they succeed to compose the character with one or more of the
238 following characters, the whole sequence of characters that where
239 composed is recorded in the `struct composition_it' object that is
240 part of the buffer iterator. The composed sequence could produce
241 one or more font glyphs (called "grapheme clusters") on the screen.
242 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
243 in the direction corresponding to the current bidi scan direction
244 (recorded in the scan_dir member of the `struct bidi_it' object
245 that is part of the buffer iterator). In particular, if the bidi
246 iterator currently scans the buffer backwards, the grapheme
247 clusters are delivered back to front. This reorders the grapheme
248 clusters as appropriate for the current bidi context. Note that
249 this means that the grapheme clusters are always stored in the
250 LGSTRING object (see composite.c) in the logical order.
252 Moving an iterator in bidirectional text
253 without producing glyphs
255 Note one important detail mentioned above: that the bidi reordering
256 engine, driven by the iterator, produces characters in R2L rows
257 starting at the character that will be the rightmost on display.
258 As far as the iterator is concerned, the geometry of such rows is
259 still left to right, i.e. the iterator "thinks" the first character
260 is at the leftmost pixel position. The iterator does not know that
261 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
262 delivers. This is important when functions from the move_it_*
263 family are used to get to certain screen position or to match
264 screen coordinates with buffer coordinates: these functions use the
265 iterator geometry, which is left to right even in R2L paragraphs.
266 This works well with most callers of move_it_*, because they need
267 to get to a specific column, and columns are still numbered in the
268 reading order, i.e. the rightmost character in a R2L paragraph is
269 still column zero. But some callers do not get well with this; a
270 notable example is mouse clicks that need to find the character
271 that corresponds to certain pixel coordinates. See
272 buffer_posn_from_coords in dispnew.c for how this is handled. */
280 #include "keyboard.h"
283 #include "termchar.h"
284 #include "dispextern.h"
285 #include "character.h"
289 #include "commands.h"
293 #include "termhooks.h"
294 #include "termopts.h"
295 #include "intervals.h"
298 #include "region-cache.h"
301 #include "blockinput.h"
302 #ifdef HAVE_WINDOW_SYSTEM
304 #endif /* HAVE_WINDOW_SYSTEM */
306 #ifndef FRAME_X_OUTPUT
307 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
310 #define INFINITY 10000000
312 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
313 Lisp_Object Qwindow_scroll_functions
;
314 static Lisp_Object Qwindow_text_change_functions
;
315 static Lisp_Object Qredisplay_end_trigger_functions
;
316 Lisp_Object Qinhibit_point_motion_hooks
;
317 static Lisp_Object QCeval
, QCpropertize
;
318 Lisp_Object QCfile
, QCdata
;
319 static Lisp_Object Qfontified
;
320 static Lisp_Object Qgrow_only
;
321 static Lisp_Object Qinhibit_eval_during_redisplay
;
322 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
323 static Lisp_Object Qright_to_left
, Qleft_to_right
;
326 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
328 /* Pointer shapes. */
329 static Lisp_Object Qarrow
, Qhand
;
332 /* Holds the list (error). */
333 static Lisp_Object list_of_error
;
335 static Lisp_Object Qfontification_functions
;
337 static Lisp_Object Qwrap_prefix
;
338 static Lisp_Object Qline_prefix
;
339 static Lisp_Object Qredisplay_internal
;
341 /* Non-nil means don't actually do any redisplay. */
343 Lisp_Object Qinhibit_redisplay
;
345 /* Names of text properties relevant for redisplay. */
347 Lisp_Object Qdisplay
;
349 Lisp_Object Qspace
, QCalign_to
;
350 static Lisp_Object QCrelative_width
, QCrelative_height
;
351 Lisp_Object Qleft_margin
, Qright_margin
;
352 static Lisp_Object Qspace_width
, Qraise
;
353 static Lisp_Object Qslice
;
355 static Lisp_Object Qmargin
, Qpointer
;
356 static Lisp_Object Qline_height
;
358 #ifdef HAVE_WINDOW_SYSTEM
360 /* Test if overflow newline into fringe. Called with iterator IT
361 at or past right window margin, and with IT->current_x set. */
363 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
364 (!NILP (Voverflow_newline_into_fringe) \
365 && FRAME_WINDOW_P ((IT)->f) \
366 && ((IT)->bidi_it.paragraph_dir == R2L \
367 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
368 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
369 && (IT)->current_x == (IT)->last_visible_x)
371 #else /* !HAVE_WINDOW_SYSTEM */
372 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
373 #endif /* HAVE_WINDOW_SYSTEM */
375 /* Test if the display element loaded in IT, or the underlying buffer
376 or string character, is a space or a TAB character. This is used
377 to determine where word wrapping can occur. */
379 #define IT_DISPLAYING_WHITESPACE(it) \
380 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
381 || ((STRINGP (it->string) \
382 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
383 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
385 && (it->s[IT_BYTEPOS (*it)] == ' ' \
386 || it->s[IT_BYTEPOS (*it)] == '\t')) \
387 || (IT_BYTEPOS (*it) < ZV_BYTE \
388 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
389 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
391 /* Name of the face used to highlight trailing whitespace. */
393 static Lisp_Object Qtrailing_whitespace
;
395 /* Name and number of the face used to highlight escape glyphs. */
397 static Lisp_Object Qescape_glyph
;
399 /* Name and number of the face used to highlight non-breaking spaces. */
401 static Lisp_Object Qnobreak_space
;
403 /* The symbol `image' which is the car of the lists used to represent
404 images in Lisp. Also a tool bar style. */
408 /* The image map types. */
410 static Lisp_Object QCpointer
;
411 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
413 /* Tool bar styles */
414 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
416 /* Non-zero means print newline to stdout before next mini-buffer
419 int noninteractive_need_newline
;
421 /* Non-zero means print newline to message log before next message. */
423 static int message_log_need_newline
;
425 /* Three markers that message_dolog uses.
426 It could allocate them itself, but that causes trouble
427 in handling memory-full errors. */
428 static Lisp_Object message_dolog_marker1
;
429 static Lisp_Object message_dolog_marker2
;
430 static Lisp_Object message_dolog_marker3
;
432 /* The buffer position of the first character appearing entirely or
433 partially on the line of the selected window which contains the
434 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
435 redisplay optimization in redisplay_internal. */
437 static struct text_pos this_line_start_pos
;
439 /* Number of characters past the end of the line above, including the
440 terminating newline. */
442 static struct text_pos this_line_end_pos
;
444 /* The vertical positions and the height of this line. */
446 static int this_line_vpos
;
447 static int this_line_y
;
448 static int this_line_pixel_height
;
450 /* X position at which this display line starts. Usually zero;
451 negative if first character is partially visible. */
453 static int this_line_start_x
;
455 /* The smallest character position seen by move_it_* functions as they
456 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
457 hscrolled lines, see display_line. */
459 static struct text_pos this_line_min_pos
;
461 /* Buffer that this_line_.* variables are referring to. */
463 static struct buffer
*this_line_buffer
;
466 /* Values of those variables at last redisplay are stored as
467 properties on `overlay-arrow-position' symbol. However, if
468 Voverlay_arrow_position is a marker, last-arrow-position is its
469 numerical position. */
471 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
473 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
474 properties on a symbol in overlay-arrow-variable-list. */
476 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
478 Lisp_Object Qmenu_bar_update_hook
;
480 /* Nonzero if an overlay arrow has been displayed in this window. */
482 static int overlay_arrow_seen
;
484 /* Vector containing glyphs for an ellipsis `...'. */
486 static Lisp_Object default_invis_vector
[3];
488 /* This is the window where the echo area message was displayed. It
489 is always a mini-buffer window, but it may not be the same window
490 currently active as a mini-buffer. */
492 Lisp_Object echo_area_window
;
494 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
495 pushes the current message and the value of
496 message_enable_multibyte on the stack, the function restore_message
497 pops the stack and displays MESSAGE again. */
499 static Lisp_Object Vmessage_stack
;
501 /* Nonzero means multibyte characters were enabled when the echo area
502 message was specified. */
504 static int message_enable_multibyte
;
506 /* Nonzero if we should redraw the mode lines on the next redisplay. */
508 int update_mode_lines
;
510 /* Nonzero if window sizes or contents have changed since last
511 redisplay that finished. */
513 int windows_or_buffers_changed
;
515 /* Nonzero after display_mode_line if %l was used and it displayed a
518 static int line_number_displayed
;
520 /* The name of the *Messages* buffer, a string. */
522 static Lisp_Object Vmessages_buffer_name
;
524 /* Current, index 0, and last displayed echo area message. Either
525 buffers from echo_buffers, or nil to indicate no message. */
527 Lisp_Object echo_area_buffer
[2];
529 /* The buffers referenced from echo_area_buffer. */
531 static Lisp_Object echo_buffer
[2];
533 /* A vector saved used in with_area_buffer to reduce consing. */
535 static Lisp_Object Vwith_echo_area_save_vector
;
537 /* Non-zero means display_echo_area should display the last echo area
538 message again. Set by redisplay_preserve_echo_area. */
540 static int display_last_displayed_message_p
;
542 /* Nonzero if echo area is being used by print; zero if being used by
545 static int message_buf_print
;
547 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
549 static Lisp_Object Qinhibit_menubar_update
;
550 static Lisp_Object Qmessage_truncate_lines
;
552 /* Set to 1 in clear_message to make redisplay_internal aware
553 of an emptied echo area. */
555 static int message_cleared_p
;
557 /* A scratch glyph row with contents used for generating truncation
558 glyphs. Also used in direct_output_for_insert. */
560 #define MAX_SCRATCH_GLYPHS 100
561 static struct glyph_row scratch_glyph_row
;
562 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
564 /* Ascent and height of the last line processed by move_it_to. */
566 static int last_height
;
568 /* Non-zero if there's a help-echo in the echo area. */
570 int help_echo_showing_p
;
572 /* The maximum distance to look ahead for text properties. Values
573 that are too small let us call compute_char_face and similar
574 functions too often which is expensive. Values that are too large
575 let us call compute_char_face and alike too often because we
576 might not be interested in text properties that far away. */
578 #define TEXT_PROP_DISTANCE_LIMIT 100
580 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
581 iterator state and later restore it. This is needed because the
582 bidi iterator on bidi.c keeps a stacked cache of its states, which
583 is really a singleton. When we use scratch iterator objects to
584 move around the buffer, we can cause the bidi cache to be pushed or
585 popped, and therefore we need to restore the cache state when we
586 return to the original iterator. */
587 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
590 bidi_unshelve_cache (CACHE, 1); \
592 CACHE = bidi_shelve_cache (); \
595 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
597 if (pITORIG != pITCOPY) \
598 *(pITORIG) = *(pITCOPY); \
599 bidi_unshelve_cache (CACHE, 0); \
605 /* Non-zero means print traces of redisplay if compiled with
606 GLYPH_DEBUG defined. */
608 int trace_redisplay_p
;
610 #endif /* GLYPH_DEBUG */
612 #ifdef DEBUG_TRACE_MOVE
613 /* Non-zero means trace with TRACE_MOVE to stderr. */
616 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
618 #define TRACE_MOVE(x) (void) 0
621 static Lisp_Object Qauto_hscroll_mode
;
623 /* Buffer being redisplayed -- for redisplay_window_error. */
625 static struct buffer
*displayed_buffer
;
627 /* Value returned from text property handlers (see below). */
632 HANDLED_RECOMPUTE_PROPS
,
633 HANDLED_OVERLAY_STRING_CONSUMED
,
637 /* A description of text properties that redisplay is interested
642 /* The name of the property. */
645 /* A unique index for the property. */
648 /* A handler function called to set up iterator IT from the property
649 at IT's current position. Value is used to steer handle_stop. */
650 enum prop_handled (*handler
) (struct it
*it
);
653 static enum prop_handled
handle_face_prop (struct it
*);
654 static enum prop_handled
handle_invisible_prop (struct it
*);
655 static enum prop_handled
handle_display_prop (struct it
*);
656 static enum prop_handled
handle_composition_prop (struct it
*);
657 static enum prop_handled
handle_overlay_change (struct it
*);
658 static enum prop_handled
handle_fontified_prop (struct it
*);
660 /* Properties handled by iterators. */
662 static struct props it_props
[] =
664 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
665 /* Handle `face' before `display' because some sub-properties of
666 `display' need to know the face. */
667 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
668 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
669 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
670 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
674 /* Value is the position described by X. If X is a marker, value is
675 the marker_position of X. Otherwise, value is X. */
677 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
679 /* Enumeration returned by some move_it_.* functions internally. */
683 /* Not used. Undefined value. */
686 /* Move ended at the requested buffer position or ZV. */
687 MOVE_POS_MATCH_OR_ZV
,
689 /* Move ended at the requested X pixel position. */
692 /* Move within a line ended at the end of a line that must be
696 /* Move within a line ended at the end of a line that would
697 be displayed truncated. */
700 /* Move within a line ended at a line end. */
704 /* This counter is used to clear the face cache every once in a while
705 in redisplay_internal. It is incremented for each redisplay.
706 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
709 #define CLEAR_FACE_CACHE_COUNT 500
710 static int clear_face_cache_count
;
712 /* Similarly for the image cache. */
714 #ifdef HAVE_WINDOW_SYSTEM
715 #define CLEAR_IMAGE_CACHE_COUNT 101
716 static int clear_image_cache_count
;
718 /* Null glyph slice */
719 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
722 /* True while redisplay_internal is in progress. */
726 static Lisp_Object Qinhibit_free_realized_faces
;
727 static Lisp_Object Qmode_line_default_help_echo
;
729 /* If a string, XTread_socket generates an event to display that string.
730 (The display is done in read_char.) */
732 Lisp_Object help_echo_string
;
733 Lisp_Object help_echo_window
;
734 Lisp_Object help_echo_object
;
735 ptrdiff_t help_echo_pos
;
737 /* Temporary variable for XTread_socket. */
739 Lisp_Object previous_help_echo_string
;
741 /* Platform-independent portion of hourglass implementation. */
743 #ifdef HAVE_WINDOW_SYSTEM
745 /* Non-zero means an hourglass cursor is currently shown. */
746 int hourglass_shown_p
;
748 /* If non-null, an asynchronous timer that, when it expires, displays
749 an hourglass cursor on all frames. */
750 struct atimer
*hourglass_atimer
;
752 #endif /* HAVE_WINDOW_SYSTEM */
754 /* Name of the face used to display glyphless characters. */
755 Lisp_Object Qglyphless_char
;
757 /* Symbol for the purpose of Vglyphless_char_display. */
758 static Lisp_Object Qglyphless_char_display
;
760 /* Method symbols for Vglyphless_char_display. */
761 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
763 /* Default number of seconds to wait before displaying an hourglass
765 #define DEFAULT_HOURGLASS_DELAY 1
767 #ifdef HAVE_WINDOW_SYSTEM
769 /* Default pixel width of `thin-space' display method. */
770 #define THIN_SPACE_WIDTH 1
772 #endif /* HAVE_WINDOW_SYSTEM */
774 /* Function prototypes. */
776 static void setup_for_ellipsis (struct it
*, int);
777 static void set_iterator_to_next (struct it
*, int);
778 static void mark_window_display_accurate_1 (struct window
*, int);
779 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
780 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
781 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
782 static int cursor_row_p (struct glyph_row
*);
783 static int redisplay_mode_lines (Lisp_Object
, int);
784 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
786 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
788 static void handle_line_prefix (struct it
*);
790 static void pint2str (char *, int, ptrdiff_t);
791 static void pint2hrstr (char *, int, ptrdiff_t);
792 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
794 static int text_outside_line_unchanged_p (struct window
*,
795 ptrdiff_t, ptrdiff_t);
796 static void store_mode_line_noprop_char (char);
797 static int store_mode_line_noprop (const char *, int, int);
798 static void handle_stop (struct it
*);
799 static void handle_stop_backwards (struct it
*, ptrdiff_t);
800 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
801 static void ensure_echo_area_buffers (void);
802 static void unwind_with_echo_area_buffer (Lisp_Object
);
803 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
804 static int with_echo_area_buffer (struct window
*, int,
805 int (*) (ptrdiff_t, Lisp_Object
),
806 ptrdiff_t, Lisp_Object
);
807 static void clear_garbaged_frames (void);
808 static int current_message_1 (ptrdiff_t, Lisp_Object
);
809 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
810 static void set_message (Lisp_Object
);
811 static int set_message_1 (ptrdiff_t, Lisp_Object
);
812 static int display_echo_area (struct window
*);
813 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
814 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
815 static void unwind_redisplay (void);
816 static int string_char_and_length (const unsigned char *, int *);
817 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
819 static int compute_window_start_on_continuation_line (struct window
*);
820 static void insert_left_trunc_glyphs (struct it
*);
821 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
823 static void extend_face_to_end_of_line (struct it
*);
824 static int append_space_for_newline (struct it
*, int);
825 static int cursor_row_fully_visible_p (struct window
*, int, int);
826 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
827 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
828 static int trailing_whitespace_p (ptrdiff_t);
829 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
830 static void push_it (struct it
*, struct text_pos
*);
831 static void iterate_out_of_display_property (struct it
*);
832 static void pop_it (struct it
*);
833 static void sync_frame_with_window_matrix_rows (struct window
*);
834 static void redisplay_internal (void);
835 static int echo_area_display (int);
836 static void redisplay_windows (Lisp_Object
);
837 static void redisplay_window (Lisp_Object
, int);
838 static Lisp_Object
redisplay_window_error (Lisp_Object
);
839 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
840 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
841 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
842 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
844 static int update_menu_bar (struct frame
*, int, int);
845 static int try_window_reusing_current_matrix (struct window
*);
846 static int try_window_id (struct window
*);
847 static int display_line (struct it
*);
848 static int display_mode_lines (struct window
*);
849 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
850 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
851 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
852 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
853 static void display_menu_bar (struct window
*);
854 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
856 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
857 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
858 static void compute_line_metrics (struct it
*);
859 static void run_redisplay_end_trigger_hook (struct it
*);
860 static int get_overlay_strings (struct it
*, ptrdiff_t);
861 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
862 static void next_overlay_string (struct it
*);
863 static void reseat (struct it
*, struct text_pos
, int);
864 static void reseat_1 (struct it
*, struct text_pos
, int);
865 static void back_to_previous_visible_line_start (struct it
*);
866 static void reseat_at_next_visible_line_start (struct it
*, int);
867 static int next_element_from_ellipsis (struct it
*);
868 static int next_element_from_display_vector (struct it
*);
869 static int next_element_from_string (struct it
*);
870 static int next_element_from_c_string (struct it
*);
871 static int next_element_from_buffer (struct it
*);
872 static int next_element_from_composition (struct it
*);
873 static int next_element_from_image (struct it
*);
874 static int next_element_from_stretch (struct it
*);
875 static void load_overlay_strings (struct it
*, ptrdiff_t);
876 static int init_from_display_pos (struct it
*, struct window
*,
877 struct display_pos
*);
878 static void reseat_to_string (struct it
*, const char *,
879 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
880 static int get_next_display_element (struct it
*);
881 static enum move_it_result
882 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
883 enum move_operation_enum
);
884 static void get_visually_first_element (struct it
*);
885 static void init_to_row_start (struct it
*, struct window
*,
887 static int init_to_row_end (struct it
*, struct window
*,
889 static void back_to_previous_line_start (struct it
*);
890 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
891 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
892 Lisp_Object
, ptrdiff_t);
893 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
894 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
895 static ptrdiff_t number_of_chars (const char *, bool);
896 static void compute_stop_pos (struct it
*);
897 static void compute_string_pos (struct text_pos
*, struct text_pos
,
899 static int face_before_or_after_it_pos (struct it
*, int);
900 static ptrdiff_t next_overlay_change (ptrdiff_t);
901 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
902 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
903 static int handle_single_display_spec (struct it
*, Lisp_Object
,
904 Lisp_Object
, Lisp_Object
,
905 struct text_pos
*, ptrdiff_t, int, int);
906 static int underlying_face_id (struct it
*);
907 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
910 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
911 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
913 #ifdef HAVE_WINDOW_SYSTEM
915 static void x_consider_frame_title (Lisp_Object
);
916 static int tool_bar_lines_needed (struct frame
*, int *);
917 static void update_tool_bar (struct frame
*, int);
918 static void build_desired_tool_bar_string (struct frame
*f
);
919 static int redisplay_tool_bar (struct frame
*);
920 static void display_tool_bar_line (struct it
*, int);
921 static void notice_overwritten_cursor (struct window
*,
924 static void append_stretch_glyph (struct it
*, Lisp_Object
,
928 #endif /* HAVE_WINDOW_SYSTEM */
930 static void produce_special_glyphs (struct it
*, enum display_element_type
);
931 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
932 static int coords_in_mouse_face_p (struct window
*, int, int);
936 /***********************************************************************
937 Window display dimensions
938 ***********************************************************************/
940 /* Return the bottom boundary y-position for text lines in window W.
941 This is the first y position at which a line cannot start.
942 It is relative to the top of the window.
944 This is the height of W minus the height of a mode line, if any. */
947 window_text_bottom_y (struct window
*w
)
949 int height
= WINDOW_TOTAL_HEIGHT (w
);
951 if (WINDOW_WANTS_MODELINE_P (w
))
952 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
956 /* Return the pixel width of display area AREA of window W.
957 ANY_AREA means return the total width of W, not including
958 fringes to the left and right of the window. */
961 window_box_width (struct window
*w
, enum glyph_row_area area
)
963 int cols
= w
->total_cols
;
966 if (!w
->pseudo_window_p
)
968 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
970 if (area
== TEXT_AREA
)
972 cols
-= max (0, w
->left_margin_cols
);
973 cols
-= max (0, w
->right_margin_cols
);
974 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
976 else if (area
== LEFT_MARGIN_AREA
)
978 cols
= max (0, w
->left_margin_cols
);
981 else if (area
== RIGHT_MARGIN_AREA
)
983 cols
= max (0, w
->right_margin_cols
);
988 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
992 /* Return the pixel height of the display area of window W, not
993 including mode lines of W, if any. */
996 window_box_height (struct window
*w
)
998 struct frame
*f
= XFRAME (w
->frame
);
999 int height
= WINDOW_TOTAL_HEIGHT (w
);
1001 eassert (height
>= 0);
1003 /* Note: the code below that determines the mode-line/header-line
1004 height is essentially the same as that contained in the macro
1005 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1006 the appropriate glyph row has its `mode_line_p' flag set,
1007 and if it doesn't, uses estimate_mode_line_height instead. */
1009 if (WINDOW_WANTS_MODELINE_P (w
))
1011 struct glyph_row
*ml_row
1012 = (w
->current_matrix
&& w
->current_matrix
->rows
1013 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1015 if (ml_row
&& ml_row
->mode_line_p
)
1016 height
-= ml_row
->height
;
1018 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1021 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1023 struct glyph_row
*hl_row
1024 = (w
->current_matrix
&& w
->current_matrix
->rows
1025 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1027 if (hl_row
&& hl_row
->mode_line_p
)
1028 height
-= hl_row
->height
;
1030 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1033 /* With a very small font and a mode-line that's taller than
1034 default, we might end up with a negative height. */
1035 return max (0, height
);
1038 /* Return the window-relative coordinate of the left edge of display
1039 area AREA of window W. ANY_AREA means return the left edge of the
1040 whole window, to the right of the left fringe of W. */
1043 window_box_left_offset (struct window
*w
, enum glyph_row_area area
)
1047 if (w
->pseudo_window_p
)
1050 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1052 if (area
== TEXT_AREA
)
1053 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1054 + window_box_width (w
, LEFT_MARGIN_AREA
));
1055 else if (area
== RIGHT_MARGIN_AREA
)
1056 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1057 + window_box_width (w
, LEFT_MARGIN_AREA
)
1058 + window_box_width (w
, TEXT_AREA
)
1059 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1061 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1062 else if (area
== LEFT_MARGIN_AREA
1063 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1064 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1070 /* Return the window-relative coordinate of the right edge of display
1071 area AREA of window W. ANY_AREA means return the right edge of the
1072 whole window, to the left of the right fringe of W. */
1075 window_box_right_offset (struct window
*w
, enum glyph_row_area area
)
1077 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1080 /* Return the frame-relative coordinate of the left edge of display
1081 area AREA of window W. ANY_AREA means return the left edge of the
1082 whole window, to the right of the left fringe of W. */
1085 window_box_left (struct window
*w
, enum glyph_row_area area
)
1087 struct frame
*f
= XFRAME (w
->frame
);
1090 if (w
->pseudo_window_p
)
1091 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1093 x
= (WINDOW_LEFT_EDGE_X (w
)
1094 + window_box_left_offset (w
, area
));
1100 /* Return the frame-relative coordinate of the right edge of display
1101 area AREA of window W. ANY_AREA means return the right edge of the
1102 whole window, to the left of the right fringe of W. */
1105 window_box_right (struct window
*w
, enum glyph_row_area area
)
1107 return window_box_left (w
, area
) + window_box_width (w
, area
);
1110 /* Get the bounding box of the display area AREA of window W, without
1111 mode lines, in frame-relative coordinates. ANY_AREA means the
1112 whole window, not including the left and right fringes of
1113 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1114 coordinates of the upper-left corner of the box. Return in
1115 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1118 window_box (struct window
*w
, enum glyph_row_area area
, int *box_x
,
1119 int *box_y
, int *box_width
, int *box_height
)
1122 *box_width
= window_box_width (w
, area
);
1124 *box_height
= window_box_height (w
);
1126 *box_x
= window_box_left (w
, area
);
1129 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1130 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1131 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1135 #ifdef HAVE_WINDOW_SYSTEM
1137 /* Get the bounding box of the display area AREA of window W, without
1138 mode lines and both fringes of the window. Return in *TOP_LEFT_X
1139 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1140 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1141 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1145 window_box_edges (struct window
*w
, int *top_left_x
, int *top_left_y
,
1146 int *bottom_right_x
, int *bottom_right_y
)
1148 window_box (w
, ANY_AREA
, top_left_x
, top_left_y
,
1149 bottom_right_x
, bottom_right_y
);
1150 *bottom_right_x
+= *top_left_x
;
1151 *bottom_right_y
+= *top_left_y
;
1154 #endif /* HAVE_WINDOW_SYSTEM */
1156 /***********************************************************************
1158 ***********************************************************************/
1160 /* Return the bottom y-position of the line the iterator IT is in.
1161 This can modify IT's settings. */
1164 line_bottom_y (struct it
*it
)
1166 int line_height
= it
->max_ascent
+ it
->max_descent
;
1167 int line_top_y
= it
->current_y
;
1169 if (line_height
== 0)
1172 line_height
= last_height
;
1173 else if (IT_CHARPOS (*it
) < ZV
)
1175 move_it_by_lines (it
, 1);
1176 line_height
= (it
->max_ascent
|| it
->max_descent
1177 ? it
->max_ascent
+ it
->max_descent
1182 struct glyph_row
*row
= it
->glyph_row
;
1184 /* Use the default character height. */
1185 it
->glyph_row
= NULL
;
1186 it
->what
= IT_CHARACTER
;
1189 PRODUCE_GLYPHS (it
);
1190 line_height
= it
->ascent
+ it
->descent
;
1191 it
->glyph_row
= row
;
1195 return line_top_y
+ line_height
;
1198 DEFUN ("line-pixel-height", Fline_pixel_height
,
1199 Sline_pixel_height
, 0, 0, 0,
1200 doc
: /* Return height in pixels of text line in the selected window.
1202 Value is the height in pixels of the line at point. */)
1207 struct window
*w
= XWINDOW (selected_window
);
1209 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1210 start_display (&it
, w
, pt
);
1211 it
.vpos
= it
.current_y
= 0;
1213 return make_number (line_bottom_y (&it
));
1216 /* Return the default pixel height of text lines in window W. The
1217 value is the canonical height of the W frame's default font, plus
1218 any extra space required by the line-spacing variable or frame
1221 Implementation note: this ignores any line-spacing text properties
1222 put on the newline characters. This is because those properties
1223 only affect the _screen_ line ending in the newline (i.e., in a
1224 continued line, only the last screen line will be affected), which
1225 means only a small number of lines in a buffer can ever use this
1226 feature. Since this function is used to compute the default pixel
1227 equivalent of text lines in a window, we can safely ignore those
1228 few lines. For the same reasons, we ignore the line-height
1231 default_line_pixel_height (struct window
*w
)
1233 struct frame
*f
= WINDOW_XFRAME (w
);
1234 int height
= FRAME_LINE_HEIGHT (f
);
1236 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1238 struct buffer
*b
= XBUFFER (w
->contents
);
1239 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1242 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1245 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1246 height
+= XFASTINT (val
);
1247 else if (FLOATP (val
))
1249 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1256 height
+= f
->extra_line_spacing
;
1262 /* Subroutine of pos_visible_p below. Extracts a display string, if
1263 any, from the display spec given as its argument. */
1265 string_from_display_spec (Lisp_Object spec
)
1269 while (CONSP (spec
))
1271 if (STRINGP (XCAR (spec
)))
1276 else if (VECTORP (spec
))
1280 for (i
= 0; i
< ASIZE (spec
); i
++)
1282 if (STRINGP (AREF (spec
, i
)))
1283 return AREF (spec
, i
);
1292 /* Limit insanely large values of W->hscroll on frame F to the largest
1293 value that will still prevent first_visible_x and last_visible_x of
1294 'struct it' from overflowing an int. */
1296 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1298 ptrdiff_t window_hscroll
= w
->hscroll
;
1299 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1300 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1302 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1303 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1305 return window_hscroll
;
1308 /* Return 1 if position CHARPOS is visible in window W.
1309 CHARPOS < 0 means return info about WINDOW_END position.
1310 If visible, set *X and *Y to pixel coordinates of top left corner.
1311 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1312 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1315 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1316 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1319 void *itdata
= bidi_shelve_cache ();
1320 struct text_pos top
;
1322 struct buffer
*old_buffer
= NULL
;
1324 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1327 if (XBUFFER (w
->contents
) != current_buffer
)
1329 old_buffer
= current_buffer
;
1330 set_buffer_internal_1 (XBUFFER (w
->contents
));
1333 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1334 /* Scrolling a minibuffer window via scroll bar when the echo area
1335 shows long text sometimes resets the minibuffer contents behind
1337 if (CHARPOS (top
) > ZV
)
1338 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1340 /* Compute exact mode line heights. */
1341 if (WINDOW_WANTS_MODELINE_P (w
))
1343 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1344 BVAR (current_buffer
, mode_line_format
));
1346 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1347 w
->header_line_height
1348 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1349 BVAR (current_buffer
, header_line_format
));
1351 start_display (&it
, w
, top
);
1352 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1353 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1356 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1357 && IT_CHARPOS (it
) >= charpos
)
1358 /* When scanning backwards under bidi iteration, move_it_to
1359 stops at or _before_ CHARPOS, because it stops at or to
1360 the _right_ of the character at CHARPOS. */
1361 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1362 && IT_CHARPOS (it
) <= charpos
)))
1364 /* We have reached CHARPOS, or passed it. How the call to
1365 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1366 or covered by a display property, move_it_to stops at the end
1367 of the invisible text, to the right of CHARPOS. (ii) If
1368 CHARPOS is in a display vector, move_it_to stops on its last
1370 int top_x
= it
.current_x
;
1371 int top_y
= it
.current_y
;
1372 /* Calling line_bottom_y may change it.method, it.position, etc. */
1373 enum it_method it_method
= it
.method
;
1374 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1375 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1377 if (top_y
< window_top_y
)
1378 visible_p
= bottom_y
> window_top_y
;
1379 else if (top_y
< it
.last_visible_y
)
1381 if (bottom_y
>= it
.last_visible_y
1382 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1383 && IT_CHARPOS (it
) < charpos
)
1385 /* When the last line of the window is scanned backwards
1386 under bidi iteration, we could be duped into thinking
1387 that we have passed CHARPOS, when in fact move_it_to
1388 simply stopped short of CHARPOS because it reached
1389 last_visible_y. To see if that's what happened, we call
1390 move_it_to again with a slightly larger vertical limit,
1391 and see if it actually moved vertically; if it did, we
1392 didn't really reach CHARPOS, which is beyond window end. */
1393 struct it save_it
= it
;
1394 /* Why 10? because we don't know how many canonical lines
1395 will the height of the next line(s) be. So we guess. */
1396 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1398 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1399 MOVE_TO_POS
| MOVE_TO_Y
);
1400 if (it
.current_y
> top_y
)
1407 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1409 /* We stopped on the last glyph of a display vector.
1410 Try and recompute. Hack alert! */
1411 if (charpos
< 2 || top
.charpos
>= charpos
)
1412 top_x
= it
.glyph_row
->x
;
1415 struct it it2
, it2_prev
;
1416 /* The idea is to get to the previous buffer
1417 position, consume the character there, and use
1418 the pixel coordinates we get after that. But if
1419 the previous buffer position is also displayed
1420 from a display vector, we need to consume all of
1421 the glyphs from that display vector. */
1422 start_display (&it2
, w
, top
);
1423 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1424 /* If we didn't get to CHARPOS - 1, there's some
1425 replacing display property at that position, and
1426 we stopped after it. That is exactly the place
1427 whose coordinates we want. */
1428 if (IT_CHARPOS (it2
) != charpos
- 1)
1432 /* Iterate until we get out of the display
1433 vector that displays the character at
1436 get_next_display_element (&it2
);
1437 PRODUCE_GLYPHS (&it2
);
1439 set_iterator_to_next (&it2
, 1);
1440 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1441 && IT_CHARPOS (it2
) < charpos
);
1443 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1444 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1445 top_x
= it
.glyph_row
->x
;
1448 top_x
= it2_prev
.current_x
;
1449 top_y
= it2_prev
.current_y
;
1453 else if (IT_CHARPOS (it
) != charpos
)
1455 Lisp_Object cpos
= make_number (charpos
);
1456 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1457 Lisp_Object string
= string_from_display_spec (spec
);
1458 struct text_pos tpos
;
1459 int replacing_spec_p
;
1460 bool newline_in_string
1462 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1464 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1467 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1468 charpos
, FRAME_WINDOW_P (it
.f
)));
1469 /* The tricky code below is needed because there's a
1470 discrepancy between move_it_to and how we set cursor
1471 when PT is at the beginning of a portion of text
1472 covered by a display property or an overlay with a
1473 display property, or the display line ends in a
1474 newline from a display string. move_it_to will stop
1475 _after_ such display strings, whereas
1476 set_cursor_from_row conspires with cursor_row_p to
1477 place the cursor on the first glyph produced from the
1480 /* We have overshoot PT because it is covered by a
1481 display property that replaces the text it covers.
1482 If the string includes embedded newlines, we are also
1483 in the wrong display line. Backtrack to the correct
1484 line, where the display property begins. */
1485 if (replacing_spec_p
)
1487 Lisp_Object startpos
, endpos
;
1488 EMACS_INT start
, end
;
1492 /* Find the first and the last buffer positions
1493 covered by the display string. */
1495 Fnext_single_char_property_change (cpos
, Qdisplay
,
1498 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1500 start
= XFASTINT (startpos
);
1501 end
= XFASTINT (endpos
);
1502 /* Move to the last buffer position before the
1503 display property. */
1504 start_display (&it3
, w
, top
);
1505 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1506 /* Move forward one more line if the position before
1507 the display string is a newline or if it is the
1508 rightmost character on a line that is
1509 continued or word-wrapped. */
1510 if (it3
.method
== GET_FROM_BUFFER
1512 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1513 move_it_by_lines (&it3
, 1);
1514 else if (move_it_in_display_line_to (&it3
, -1,
1518 == MOVE_LINE_CONTINUED
)
1520 move_it_by_lines (&it3
, 1);
1521 /* When we are under word-wrap, the #$@%!
1522 move_it_by_lines moves 2 lines, so we need to
1524 if (it3
.line_wrap
== WORD_WRAP
)
1525 move_it_by_lines (&it3
, -1);
1528 /* Record the vertical coordinate of the display
1529 line where we wound up. */
1530 top_y
= it3
.current_y
;
1533 /* When characters are reordered for display,
1534 the character displayed to the left of the
1535 display string could be _after_ the display
1536 property in the logical order. Use the
1537 smallest vertical position of these two. */
1538 start_display (&it3
, w
, top
);
1539 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1540 if (it3
.current_y
< top_y
)
1541 top_y
= it3
.current_y
;
1543 /* Move from the top of the window to the beginning
1544 of the display line where the display string
1546 start_display (&it3
, w
, top
);
1547 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1548 /* If it3_moved stays zero after the 'while' loop
1549 below, that means we already were at a newline
1550 before the loop (e.g., the display string begins
1551 with a newline), so we don't need to (and cannot)
1552 inspect the glyphs of it3.glyph_row, because
1553 PRODUCE_GLYPHS will not produce anything for a
1554 newline, and thus it3.glyph_row stays at its
1555 stale content it got at top of the window. */
1557 /* Finally, advance the iterator until we hit the
1558 first display element whose character position is
1559 CHARPOS, or until the first newline from the
1560 display string, which signals the end of the
1562 while (get_next_display_element (&it3
))
1564 PRODUCE_GLYPHS (&it3
);
1565 if (IT_CHARPOS (it3
) == charpos
1566 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1569 set_iterator_to_next (&it3
, 0);
1571 top_x
= it3
.current_x
- it3
.pixel_width
;
1572 /* Normally, we would exit the above loop because we
1573 found the display element whose character
1574 position is CHARPOS. For the contingency that we
1575 didn't, and stopped at the first newline from the
1576 display string, move back over the glyphs
1577 produced from the string, until we find the
1578 rightmost glyph not from the string. */
1580 && newline_in_string
1581 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1583 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1584 + it3
.glyph_row
->used
[TEXT_AREA
];
1586 while (EQ ((g
- 1)->object
, string
))
1589 top_x
-= g
->pixel_width
;
1591 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1592 + it3
.glyph_row
->used
[TEXT_AREA
]);
1598 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1599 *rtop
= max (0, window_top_y
- top_y
);
1600 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1601 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1602 - max (top_y
, window_top_y
)));
1608 /* We were asked to provide info about WINDOW_END. */
1610 void *it2data
= NULL
;
1612 SAVE_IT (it2
, it
, it2data
);
1613 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1614 move_it_by_lines (&it
, 1);
1615 if (charpos
< IT_CHARPOS (it
)
1616 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1619 RESTORE_IT (&it2
, &it2
, it2data
);
1620 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1622 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1623 *rtop
= max (0, -it2
.current_y
);
1624 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1625 - it
.last_visible_y
));
1626 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1628 - max (it2
.current_y
,
1629 WINDOW_HEADER_LINE_HEIGHT (w
))));
1633 bidi_unshelve_cache (it2data
, 1);
1635 bidi_unshelve_cache (itdata
, 0);
1638 set_buffer_internal_1 (old_buffer
);
1640 if (visible_p
&& w
->hscroll
> 0)
1642 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1643 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1646 /* Debugging code. */
1648 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1649 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1651 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1658 /* Return the next character from STR. Return in *LEN the length of
1659 the character. This is like STRING_CHAR_AND_LENGTH but never
1660 returns an invalid character. If we find one, we return a `?', but
1661 with the length of the invalid character. */
1664 string_char_and_length (const unsigned char *str
, int *len
)
1668 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1669 if (!CHAR_VALID_P (c
))
1670 /* We may not change the length here because other places in Emacs
1671 don't use this function, i.e. they silently accept invalid
1680 /* Given a position POS containing a valid character and byte position
1681 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1683 static struct text_pos
1684 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1686 eassert (STRINGP (string
) && nchars
>= 0);
1688 if (STRING_MULTIBYTE (string
))
1690 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1695 string_char_and_length (p
, &len
);
1698 BYTEPOS (pos
) += len
;
1702 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1708 /* Value is the text position, i.e. character and byte position,
1709 for character position CHARPOS in STRING. */
1711 static struct text_pos
1712 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1714 struct text_pos pos
;
1715 eassert (STRINGP (string
));
1716 eassert (charpos
>= 0);
1717 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1722 /* Value is a text position, i.e. character and byte position, for
1723 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1724 means recognize multibyte characters. */
1726 static struct text_pos
1727 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1729 struct text_pos pos
;
1731 eassert (s
!= NULL
);
1732 eassert (charpos
>= 0);
1738 SET_TEXT_POS (pos
, 0, 0);
1741 string_char_and_length ((const unsigned char *) s
, &len
);
1744 BYTEPOS (pos
) += len
;
1748 SET_TEXT_POS (pos
, charpos
, charpos
);
1754 /* Value is the number of characters in C string S. MULTIBYTE_P
1755 non-zero means recognize multibyte characters. */
1758 number_of_chars (const char *s
, bool multibyte_p
)
1764 ptrdiff_t rest
= strlen (s
);
1766 const unsigned char *p
= (const unsigned char *) s
;
1768 for (nchars
= 0; rest
> 0; ++nchars
)
1770 string_char_and_length (p
, &len
);
1771 rest
-= len
, p
+= len
;
1775 nchars
= strlen (s
);
1781 /* Compute byte position NEWPOS->bytepos corresponding to
1782 NEWPOS->charpos. POS is a known position in string STRING.
1783 NEWPOS->charpos must be >= POS.charpos. */
1786 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1788 eassert (STRINGP (string
));
1789 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1791 if (STRING_MULTIBYTE (string
))
1792 *newpos
= string_pos_nchars_ahead (pos
, string
,
1793 CHARPOS (*newpos
) - CHARPOS (pos
));
1795 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1799 Return an estimation of the pixel height of mode or header lines on
1800 frame F. FACE_ID specifies what line's height to estimate. */
1803 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1805 #ifdef HAVE_WINDOW_SYSTEM
1806 if (FRAME_WINDOW_P (f
))
1808 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1810 /* This function is called so early when Emacs starts that the face
1811 cache and mode line face are not yet initialized. */
1812 if (FRAME_FACE_CACHE (f
))
1814 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1818 height
= FONT_HEIGHT (face
->font
);
1819 if (face
->box_line_width
> 0)
1820 height
+= 2 * face
->box_line_width
;
1831 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1832 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1833 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1834 not force the value into range. */
1837 pixel_to_glyph_coords (struct frame
*f
, register int pix_x
, register int pix_y
,
1838 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1841 #ifdef HAVE_WINDOW_SYSTEM
1842 if (FRAME_WINDOW_P (f
))
1844 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1845 even for negative values. */
1847 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1849 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1851 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1852 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1855 STORE_NATIVE_RECT (*bounds
,
1856 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1857 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1858 FRAME_COLUMN_WIDTH (f
) - 1,
1859 FRAME_LINE_HEIGHT (f
) - 1);
1865 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1866 pix_x
= FRAME_TOTAL_COLS (f
);
1870 else if (pix_y
> FRAME_LINES (f
))
1871 pix_y
= FRAME_LINES (f
);
1881 /* Find the glyph under window-relative coordinates X/Y in window W.
1882 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1883 strings. Return in *HPOS and *VPOS the row and column number of
1884 the glyph found. Return in *AREA the glyph area containing X.
1885 Value is a pointer to the glyph found or null if X/Y is not on
1886 text, or we can't tell because W's current matrix is not up to
1891 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1892 int *dx
, int *dy
, int *area
)
1894 struct glyph
*glyph
, *end
;
1895 struct glyph_row
*row
= NULL
;
1898 /* Find row containing Y. Give up if some row is not enabled. */
1899 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1901 row
= MATRIX_ROW (w
->current_matrix
, i
);
1902 if (!row
->enabled_p
)
1904 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1911 /* Give up if Y is not in the window. */
1912 if (i
== w
->current_matrix
->nrows
)
1915 /* Get the glyph area containing X. */
1916 if (w
->pseudo_window_p
)
1923 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1925 *area
= LEFT_MARGIN_AREA
;
1926 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1928 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1931 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1935 *area
= RIGHT_MARGIN_AREA
;
1936 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1940 /* Find glyph containing X. */
1941 glyph
= row
->glyphs
[*area
];
1942 end
= glyph
+ row
->used
[*area
];
1944 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1946 x
-= glyph
->pixel_width
;
1956 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1959 *hpos
= glyph
- row
->glyphs
[*area
];
1963 /* Convert frame-relative x/y to coordinates relative to window W.
1964 Takes pseudo-windows into account. */
1967 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1969 if (w
->pseudo_window_p
)
1971 /* A pseudo-window is always full-width, and starts at the
1972 left edge of the frame, plus a frame border. */
1973 struct frame
*f
= XFRAME (w
->frame
);
1974 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1975 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1979 *x
-= WINDOW_LEFT_EDGE_X (w
);
1980 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
1984 #ifdef HAVE_WINDOW_SYSTEM
1987 Return in RECTS[] at most N clipping rectangles for glyph string S.
1988 Return the number of stored rectangles. */
1991 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
1998 if (s
->row
->full_width_p
)
2000 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2001 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2002 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
2004 /* Unless displaying a mode or menu bar line, which are always
2005 fully visible, clip to the visible part of the row. */
2006 if (s
->w
->pseudo_window_p
)
2007 r
.height
= s
->row
->visible_height
;
2009 r
.height
= s
->height
;
2013 /* This is a text line that may be partially visible. */
2014 r
.x
= window_box_left (s
->w
, s
->area
);
2015 r
.width
= window_box_width (s
->w
, s
->area
);
2016 r
.height
= s
->row
->visible_height
;
2020 if (r
.x
< s
->clip_head
->x
)
2022 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2023 r
.width
-= s
->clip_head
->x
- r
.x
;
2026 r
.x
= s
->clip_head
->x
;
2029 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2031 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2032 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2037 /* If S draws overlapping rows, it's sufficient to use the top and
2038 bottom of the window for clipping because this glyph string
2039 intentionally draws over other lines. */
2040 if (s
->for_overlaps
)
2042 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2043 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2045 /* Alas, the above simple strategy does not work for the
2046 environments with anti-aliased text: if the same text is
2047 drawn onto the same place multiple times, it gets thicker.
2048 If the overlap we are processing is for the erased cursor, we
2049 take the intersection with the rectangle of the cursor. */
2050 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2052 XRectangle rc
, r_save
= r
;
2054 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2055 rc
.y
= s
->w
->phys_cursor
.y
;
2056 rc
.width
= s
->w
->phys_cursor_width
;
2057 rc
.height
= s
->w
->phys_cursor_height
;
2059 x_intersect_rectangles (&r_save
, &rc
, &r
);
2064 /* Don't use S->y for clipping because it doesn't take partially
2065 visible lines into account. For example, it can be negative for
2066 partially visible lines at the top of a window. */
2067 if (!s
->row
->full_width_p
2068 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2069 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2071 r
.y
= max (0, s
->row
->y
);
2074 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2076 /* If drawing the cursor, don't let glyph draw outside its
2077 advertised boundaries. Cleartype does this under some circumstances. */
2078 if (s
->hl
== DRAW_CURSOR
)
2080 struct glyph
*glyph
= s
->first_glyph
;
2085 r
.width
-= s
->x
- r
.x
;
2088 r
.width
= min (r
.width
, glyph
->pixel_width
);
2090 /* If r.y is below window bottom, ensure that we still see a cursor. */
2091 height
= min (glyph
->ascent
+ glyph
->descent
,
2092 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2093 max_y
= window_text_bottom_y (s
->w
) - height
;
2094 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2095 if (s
->ybase
- glyph
->ascent
> max_y
)
2102 /* Don't draw cursor glyph taller than our actual glyph. */
2103 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2104 if (height
< r
.height
)
2106 max_y
= r
.y
+ r
.height
;
2107 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2108 r
.height
= min (max_y
- r
.y
, height
);
2115 XRectangle r_save
= r
;
2117 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2121 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2122 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2124 #ifdef CONVERT_FROM_XRECT
2125 CONVERT_FROM_XRECT (r
, *rects
);
2133 /* If we are processing overlapping and allowed to return
2134 multiple clipping rectangles, we exclude the row of the glyph
2135 string from the clipping rectangle. This is to avoid drawing
2136 the same text on the environment with anti-aliasing. */
2137 #ifdef CONVERT_FROM_XRECT
2140 XRectangle
*rs
= rects
;
2142 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2144 if (s
->for_overlaps
& OVERLAPS_PRED
)
2147 if (r
.y
+ r
.height
> row_y
)
2150 rs
[i
].height
= row_y
- r
.y
;
2156 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2159 if (r
.y
< row_y
+ s
->row
->visible_height
)
2161 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2163 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2164 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2173 #ifdef CONVERT_FROM_XRECT
2174 for (i
= 0; i
< n
; i
++)
2175 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2182 Return in *NR the clipping rectangle for glyph string S. */
2185 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2187 get_glyph_string_clip_rects (s
, nr
, 1);
2192 Return the position and height of the phys cursor in window W.
2193 Set w->phys_cursor_width to width of phys cursor.
2197 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2198 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2200 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2201 int x
, y
, wd
, h
, h0
, y0
;
2203 /* Compute the width of the rectangle to draw. If on a stretch
2204 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2205 rectangle as wide as the glyph, but use a canonical character
2207 wd
= glyph
->pixel_width
- 1;
2208 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2212 x
= w
->phys_cursor
.x
;
2219 if (glyph
->type
== STRETCH_GLYPH
2220 && !x_stretch_cursor_p
)
2221 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2222 w
->phys_cursor_width
= wd
;
2224 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2226 /* If y is below window bottom, ensure that we still see a cursor. */
2227 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2229 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2230 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2232 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2235 h
= max (h
- (y0
- y
) + 1, h0
);
2240 y0
= window_text_bottom_y (w
) - h0
;
2248 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2249 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2254 * Remember which glyph the mouse is over.
2258 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2262 struct glyph_row
*r
, *gr
, *end_row
;
2263 enum window_part part
;
2264 enum glyph_row_area area
;
2265 int x
, y
, width
, height
;
2267 /* Try to determine frame pixel position and size of the glyph under
2268 frame pixel coordinates X/Y on frame F. */
2270 if (!f
->glyphs_initialized_p
2271 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2274 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2275 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2279 w
= XWINDOW (window
);
2280 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2281 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2283 x
= window_relative_x_coord (w
, part
, gx
);
2284 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2286 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2287 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2289 if (w
->pseudo_window_p
)
2292 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2298 case ON_LEFT_MARGIN
:
2299 area
= LEFT_MARGIN_AREA
;
2302 case ON_RIGHT_MARGIN
:
2303 area
= RIGHT_MARGIN_AREA
;
2306 case ON_HEADER_LINE
:
2308 gr
= (part
== ON_HEADER_LINE
2309 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2310 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2313 goto text_glyph_row_found
;
2320 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2321 if (r
->y
+ r
->height
> y
)
2327 text_glyph_row_found
:
2330 struct glyph
*g
= gr
->glyphs
[area
];
2331 struct glyph
*end
= g
+ gr
->used
[area
];
2333 height
= gr
->height
;
2334 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2335 if (gx
+ g
->pixel_width
> x
)
2340 if (g
->type
== IMAGE_GLYPH
)
2342 /* Don't remember when mouse is over image, as
2343 image may have hot-spots. */
2344 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2347 width
= g
->pixel_width
;
2351 /* Use nominal char spacing at end of line. */
2353 gx
+= (x
/ width
) * width
;
2356 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2357 gx
+= window_box_left_offset (w
, area
);
2361 /* Use nominal line height at end of window. */
2362 gx
= (x
/ width
) * width
;
2364 gy
+= (y
/ height
) * height
;
2368 case ON_LEFT_FRINGE
:
2369 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2370 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2371 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2372 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2375 case ON_RIGHT_FRINGE
:
2376 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2377 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2378 : window_box_right_offset (w
, TEXT_AREA
));
2379 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2383 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2385 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2386 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2387 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2389 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2393 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2394 if (r
->y
+ r
->height
> y
)
2401 height
= gr
->height
;
2404 /* Use nominal line height at end of window. */
2406 gy
+= (y
/ height
) * height
;
2413 /* If there is no glyph under the mouse, then we divide the screen
2414 into a grid of the smallest glyph in the frame, and use that
2417 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2418 round down even for negative values. */
2424 gx
= (gx
/ width
) * width
;
2425 gy
= (gy
/ height
) * height
;
2430 gx
+= WINDOW_LEFT_EDGE_X (w
);
2431 gy
+= WINDOW_TOP_EDGE_Y (w
);
2434 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2436 /* Visible feedback for debugging. */
2439 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2440 f
->output_data
.x
->normal_gc
,
2441 gx
, gy
, width
, height
);
2447 #endif /* HAVE_WINDOW_SYSTEM */
2450 adjust_window_ends (struct window
*w
, struct glyph_row
*row
, bool current
)
2453 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
2454 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
2456 = MATRIX_ROW_VPOS (row
, current
? w
->current_matrix
: w
->desired_matrix
);
2459 /***********************************************************************
2460 Lisp form evaluation
2461 ***********************************************************************/
2463 /* Error handler for safe_eval and safe_call. */
2466 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2468 add_to_log ("Error during redisplay: %S signaled %S",
2469 Flist (nargs
, args
), arg
);
2473 /* Call function FUNC with the rest of NARGS - 1 arguments
2474 following. Return the result, or nil if something went
2475 wrong. Prevent redisplay during the evaluation. */
2478 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2482 if (inhibit_eval_during_redisplay
)
2488 ptrdiff_t count
= SPECPDL_INDEX ();
2489 struct gcpro gcpro1
;
2490 Lisp_Object
*args
= alloca (nargs
* word_size
);
2493 va_start (ap
, func
);
2494 for (i
= 1; i
< nargs
; i
++)
2495 args
[i
] = va_arg (ap
, Lisp_Object
);
2499 gcpro1
.nvars
= nargs
;
2500 specbind (Qinhibit_redisplay
, Qt
);
2501 /* Use Qt to ensure debugger does not run,
2502 so there is no possibility of wanting to redisplay. */
2503 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2506 val
= unbind_to (count
, val
);
2513 /* Call function FN with one argument ARG.
2514 Return the result, or nil if something went wrong. */
2517 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2519 return safe_call (2, fn
, arg
);
2522 static Lisp_Object Qeval
;
2525 safe_eval (Lisp_Object sexpr
)
2527 return safe_call1 (Qeval
, sexpr
);
2530 /* Call function FN with two arguments ARG1 and ARG2.
2531 Return the result, or nil if something went wrong. */
2534 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2536 return safe_call (3, fn
, arg1
, arg2
);
2541 /***********************************************************************
2543 ***********************************************************************/
2547 /* Define CHECK_IT to perform sanity checks on iterators.
2548 This is for debugging. It is too slow to do unconditionally. */
2551 check_it (struct it
*it
)
2553 if (it
->method
== GET_FROM_STRING
)
2555 eassert (STRINGP (it
->string
));
2556 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2560 eassert (IT_STRING_CHARPOS (*it
) < 0);
2561 if (it
->method
== GET_FROM_BUFFER
)
2563 /* Check that character and byte positions agree. */
2564 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2569 eassert (it
->current
.dpvec_index
>= 0);
2571 eassert (it
->current
.dpvec_index
< 0);
2574 #define CHECK_IT(IT) check_it ((IT))
2578 #define CHECK_IT(IT) (void) 0
2583 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2585 /* Check that the window end of window W is what we expect it
2586 to be---the last row in the current matrix displaying text. */
2589 check_window_end (struct window
*w
)
2591 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2593 struct glyph_row
*row
;
2594 eassert ((row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
),
2596 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2597 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2601 #define CHECK_WINDOW_END(W) check_window_end ((W))
2605 #define CHECK_WINDOW_END(W) (void) 0
2607 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2609 /* Return mark position if current buffer has the region of non-zero length,
2613 markpos_of_region (void)
2615 if (!NILP (Vtransient_mark_mode
)
2616 && !NILP (BVAR (current_buffer
, mark_active
))
2617 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2619 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2627 /***********************************************************************
2628 Iterator initialization
2629 ***********************************************************************/
2631 /* Initialize IT for displaying current_buffer in window W, starting
2632 at character position CHARPOS. CHARPOS < 0 means that no buffer
2633 position is specified which is useful when the iterator is assigned
2634 a position later. BYTEPOS is the byte position corresponding to
2637 If ROW is not null, calls to produce_glyphs with IT as parameter
2638 will produce glyphs in that row.
2640 BASE_FACE_ID is the id of a base face to use. It must be one of
2641 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2642 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2643 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2645 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2646 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2647 will be initialized to use the corresponding mode line glyph row of
2648 the desired matrix of W. */
2651 init_iterator (struct it
*it
, struct window
*w
,
2652 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2653 struct glyph_row
*row
, enum face_id base_face_id
)
2656 enum face_id remapped_base_face_id
= base_face_id
;
2658 /* Some precondition checks. */
2659 eassert (w
!= NULL
&& it
!= NULL
);
2660 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2663 /* If face attributes have been changed since the last redisplay,
2664 free realized faces now because they depend on face definitions
2665 that might have changed. Don't free faces while there might be
2666 desired matrices pending which reference these faces. */
2667 if (face_change_count
&& !inhibit_free_realized_faces
)
2669 face_change_count
= 0;
2670 free_all_realized_faces (Qnil
);
2673 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2674 if (! NILP (Vface_remapping_alist
))
2675 remapped_base_face_id
2676 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2678 /* Use one of the mode line rows of W's desired matrix if
2682 if (base_face_id
== MODE_LINE_FACE_ID
2683 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2684 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2685 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2686 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2690 memset (it
, 0, sizeof *it
);
2691 it
->current
.overlay_string_index
= -1;
2692 it
->current
.dpvec_index
= -1;
2693 it
->base_face_id
= remapped_base_face_id
;
2695 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2696 it
->paragraph_embedding
= L2R
;
2697 it
->bidi_it
.string
.lstring
= Qnil
;
2698 it
->bidi_it
.string
.s
= NULL
;
2699 it
->bidi_it
.string
.bufpos
= 0;
2702 /* The window in which we iterate over current_buffer: */
2703 XSETWINDOW (it
->window
, w
);
2705 it
->f
= XFRAME (w
->frame
);
2709 /* Extra space between lines (on window systems only). */
2710 if (base_face_id
== DEFAULT_FACE_ID
2711 && FRAME_WINDOW_P (it
->f
))
2713 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2714 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2715 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2716 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2717 * FRAME_LINE_HEIGHT (it
->f
));
2718 else if (it
->f
->extra_line_spacing
> 0)
2719 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2720 it
->max_extra_line_spacing
= 0;
2723 /* If realized faces have been removed, e.g. because of face
2724 attribute changes of named faces, recompute them. When running
2725 in batch mode, the face cache of the initial frame is null. If
2726 we happen to get called, make a dummy face cache. */
2727 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2728 init_frame_faces (it
->f
);
2729 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2730 recompute_basic_faces (it
->f
);
2732 /* Current value of the `slice', `space-width', and 'height' properties. */
2733 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2734 it
->space_width
= Qnil
;
2735 it
->font_height
= Qnil
;
2736 it
->override_ascent
= -1;
2738 /* Are control characters displayed as `^C'? */
2739 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2741 /* -1 means everything between a CR and the following line end
2742 is invisible. >0 means lines indented more than this value are
2744 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2746 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2748 : (!NILP (BVAR (current_buffer
, selective_display
))
2750 it
->selective_display_ellipsis_p
2751 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2753 /* Display table to use. */
2754 it
->dp
= window_display_table (w
);
2756 /* Are multibyte characters enabled in current_buffer? */
2757 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2759 /* If visible region is of non-zero length, set IT->region_beg_charpos
2760 and IT->region_end_charpos to the start and end of a visible region
2761 in window IT->w. Set both to -1 to indicate no region. */
2762 markpos
= markpos_of_region ();
2764 /* Maybe highlight only in selected window. */
2765 && (/* Either show region everywhere. */
2766 highlight_nonselected_windows
2767 /* Or show region in the selected window. */
2768 || w
== XWINDOW (selected_window
)
2769 /* Or show the region if we are in the mini-buffer and W is
2770 the window the mini-buffer refers to. */
2771 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2772 && WINDOWP (minibuf_selected_window
)
2773 && w
== XWINDOW (minibuf_selected_window
))))
2775 it
->region_beg_charpos
= min (PT
, markpos
);
2776 it
->region_end_charpos
= max (PT
, markpos
);
2779 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2781 /* Get the position at which the redisplay_end_trigger hook should
2782 be run, if it is to be run at all. */
2783 if (MARKERP (w
->redisplay_end_trigger
)
2784 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2785 it
->redisplay_end_trigger_charpos
2786 = marker_position (w
->redisplay_end_trigger
);
2787 else if (INTEGERP (w
->redisplay_end_trigger
))
2788 it
->redisplay_end_trigger_charpos
=
2789 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2791 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2793 /* Are lines in the display truncated? */
2794 if (base_face_id
!= DEFAULT_FACE_ID
2796 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2797 && ((!NILP (Vtruncate_partial_width_windows
)
2798 && !INTEGERP (Vtruncate_partial_width_windows
))
2799 || (INTEGERP (Vtruncate_partial_width_windows
)
2800 && (WINDOW_TOTAL_COLS (it
->w
)
2801 < XINT (Vtruncate_partial_width_windows
))))))
2802 it
->line_wrap
= TRUNCATE
;
2803 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2804 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2805 ? WINDOW_WRAP
: WORD_WRAP
;
2807 it
->line_wrap
= TRUNCATE
;
2809 /* Get dimensions of truncation and continuation glyphs. These are
2810 displayed as fringe bitmaps under X, but we need them for such
2811 frames when the fringes are turned off. But leave the dimensions
2812 zero for tooltip frames, as these glyphs look ugly there and also
2813 sabotage calculations of tooltip dimensions in x-show-tip. */
2814 #ifdef HAVE_WINDOW_SYSTEM
2815 if (!(FRAME_WINDOW_P (it
->f
)
2816 && FRAMEP (tip_frame
)
2817 && it
->f
== XFRAME (tip_frame
)))
2820 if (it
->line_wrap
== TRUNCATE
)
2822 /* We will need the truncation glyph. */
2823 eassert (it
->glyph_row
== NULL
);
2824 produce_special_glyphs (it
, IT_TRUNCATION
);
2825 it
->truncation_pixel_width
= it
->pixel_width
;
2829 /* We will need the continuation glyph. */
2830 eassert (it
->glyph_row
== NULL
);
2831 produce_special_glyphs (it
, IT_CONTINUATION
);
2832 it
->continuation_pixel_width
= it
->pixel_width
;
2836 /* Reset these values to zero because the produce_special_glyphs
2837 above has changed them. */
2838 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2839 it
->phys_ascent
= it
->phys_descent
= 0;
2841 /* Set this after getting the dimensions of truncation and
2842 continuation glyphs, so that we don't produce glyphs when calling
2843 produce_special_glyphs, above. */
2844 it
->glyph_row
= row
;
2845 it
->area
= TEXT_AREA
;
2847 /* Forget any previous info about this row being reversed. */
2849 it
->glyph_row
->reversed_p
= 0;
2851 /* Get the dimensions of the display area. The display area
2852 consists of the visible window area plus a horizontally scrolled
2853 part to the left of the window. All x-values are relative to the
2854 start of this total display area. */
2855 if (base_face_id
!= DEFAULT_FACE_ID
)
2857 /* Mode lines, menu bar in terminal frames. */
2858 it
->first_visible_x
= 0;
2859 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2863 it
->first_visible_x
=
2864 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2865 it
->last_visible_x
= (it
->first_visible_x
2866 + window_box_width (w
, TEXT_AREA
));
2868 /* If we truncate lines, leave room for the truncation glyph(s) at
2869 the right margin. Otherwise, leave room for the continuation
2870 glyph(s). Done only if the window has no fringes. Since we
2871 don't know at this point whether there will be any R2L lines in
2872 the window, we reserve space for truncation/continuation glyphs
2873 even if only one of the fringes is absent. */
2874 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2875 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2877 if (it
->line_wrap
== TRUNCATE
)
2878 it
->last_visible_x
-= it
->truncation_pixel_width
;
2880 it
->last_visible_x
-= it
->continuation_pixel_width
;
2883 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2884 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2887 /* Leave room for a border glyph. */
2888 if (!FRAME_WINDOW_P (it
->f
)
2889 && !WINDOW_RIGHTMOST_P (it
->w
))
2890 it
->last_visible_x
-= 1;
2892 it
->last_visible_y
= window_text_bottom_y (w
);
2894 /* For mode lines and alike, arrange for the first glyph having a
2895 left box line if the face specifies a box. */
2896 if (base_face_id
!= DEFAULT_FACE_ID
)
2900 it
->face_id
= remapped_base_face_id
;
2902 /* If we have a boxed mode line, make the first character appear
2903 with a left box line. */
2904 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2905 if (face
->box
!= FACE_NO_BOX
)
2906 it
->start_of_box_run_p
= 1;
2909 /* If a buffer position was specified, set the iterator there,
2910 getting overlays and face properties from that position. */
2911 if (charpos
>= BUF_BEG (current_buffer
))
2913 it
->end_charpos
= ZV
;
2914 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2915 IT_CHARPOS (*it
) = charpos
;
2916 IT_BYTEPOS (*it
) = bytepos
;
2918 /* We will rely on `reseat' to set this up properly, via
2919 handle_face_prop. */
2920 it
->face_id
= it
->base_face_id
;
2922 it
->start
= it
->current
;
2923 /* Do we need to reorder bidirectional text? Not if this is a
2924 unibyte buffer: by definition, none of the single-byte
2925 characters are strong R2L, so no reordering is needed. And
2926 bidi.c doesn't support unibyte buffers anyway. Also, don't
2927 reorder while we are loading loadup.el, since the tables of
2928 character properties needed for reordering are not yet
2932 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2935 /* If we are to reorder bidirectional text, init the bidi
2939 /* Note the paragraph direction that this buffer wants to
2941 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2943 it
->paragraph_embedding
= L2R
;
2944 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2946 it
->paragraph_embedding
= R2L
;
2948 it
->paragraph_embedding
= NEUTRAL_DIR
;
2949 bidi_unshelve_cache (NULL
, 0);
2950 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2954 /* Compute faces etc. */
2955 reseat (it
, it
->current
.pos
, 1);
2962 /* Initialize IT for the display of window W with window start POS. */
2965 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2967 struct glyph_row
*row
;
2968 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2970 row
= w
->desired_matrix
->rows
+ first_vpos
;
2971 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2972 it
->first_vpos
= first_vpos
;
2974 /* Don't reseat to previous visible line start if current start
2975 position is in a string or image. */
2976 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2978 int start_at_line_beg_p
;
2979 int first_y
= it
->current_y
;
2981 /* If window start is not at a line start, skip forward to POS to
2982 get the correct continuation lines width. */
2983 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2984 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2985 if (!start_at_line_beg_p
)
2989 reseat_at_previous_visible_line_start (it
);
2990 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
2992 new_x
= it
->current_x
+ it
->pixel_width
;
2994 /* If lines are continued, this line may end in the middle
2995 of a multi-glyph character (e.g. a control character
2996 displayed as \003, or in the middle of an overlay
2997 string). In this case move_it_to above will not have
2998 taken us to the start of the continuation line but to the
2999 end of the continued line. */
3000 if (it
->current_x
> 0
3001 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3002 && (/* And glyph doesn't fit on the line. */
3003 new_x
> it
->last_visible_x
3004 /* Or it fits exactly and we're on a window
3006 || (new_x
== it
->last_visible_x
3007 && FRAME_WINDOW_P (it
->f
)
3008 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3009 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3010 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3012 if ((it
->current
.dpvec_index
>= 0
3013 || it
->current
.overlay_string_index
>= 0)
3014 /* If we are on a newline from a display vector or
3015 overlay string, then we are already at the end of
3016 a screen line; no need to go to the next line in
3017 that case, as this line is not really continued.
3018 (If we do go to the next line, C-e will not DTRT.) */
3021 set_iterator_to_next (it
, 1);
3022 move_it_in_display_line_to (it
, -1, -1, 0);
3025 it
->continuation_lines_width
+= it
->current_x
;
3027 /* If the character at POS is displayed via a display
3028 vector, move_it_to above stops at the final glyph of
3029 IT->dpvec. To make the caller redisplay that character
3030 again (a.k.a. start at POS), we need to reset the
3031 dpvec_index to the beginning of IT->dpvec. */
3032 else if (it
->current
.dpvec_index
>= 0)
3033 it
->current
.dpvec_index
= 0;
3035 /* We're starting a new display line, not affected by the
3036 height of the continued line, so clear the appropriate
3037 fields in the iterator structure. */
3038 it
->max_ascent
= it
->max_descent
= 0;
3039 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3041 it
->current_y
= first_y
;
3043 it
->current_x
= it
->hpos
= 0;
3049 /* Return 1 if POS is a position in ellipses displayed for invisible
3050 text. W is the window we display, for text property lookup. */
3053 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3055 Lisp_Object prop
, window
;
3057 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3059 /* If POS specifies a position in a display vector, this might
3060 be for an ellipsis displayed for invisible text. We won't
3061 get the iterator set up for delivering that ellipsis unless
3062 we make sure that it gets aware of the invisible text. */
3063 if (pos
->dpvec_index
>= 0
3064 && pos
->overlay_string_index
< 0
3065 && CHARPOS (pos
->string_pos
) < 0
3067 && (XSETWINDOW (window
, w
),
3068 prop
= Fget_char_property (make_number (charpos
),
3069 Qinvisible
, window
),
3070 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3072 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3074 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3081 /* Initialize IT for stepping through current_buffer in window W,
3082 starting at position POS that includes overlay string and display
3083 vector/ control character translation position information. Value
3084 is zero if there are overlay strings with newlines at POS. */
3087 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3089 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3090 int i
, overlay_strings_with_newlines
= 0;
3092 /* If POS specifies a position in a display vector, this might
3093 be for an ellipsis displayed for invisible text. We won't
3094 get the iterator set up for delivering that ellipsis unless
3095 we make sure that it gets aware of the invisible text. */
3096 if (in_ellipses_for_invisible_text_p (pos
, w
))
3102 /* Keep in mind: the call to reseat in init_iterator skips invisible
3103 text, so we might end up at a position different from POS. This
3104 is only a problem when POS is a row start after a newline and an
3105 overlay starts there with an after-string, and the overlay has an
3106 invisible property. Since we don't skip invisible text in
3107 display_line and elsewhere immediately after consuming the
3108 newline before the row start, such a POS will not be in a string,
3109 but the call to init_iterator below will move us to the
3111 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3113 /* This only scans the current chunk -- it should scan all chunks.
3114 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3115 to 16 in 22.1 to make this a lesser problem. */
3116 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3118 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3119 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3121 while (s
< e
&& *s
!= '\n')
3126 overlay_strings_with_newlines
= 1;
3131 /* If position is within an overlay string, set up IT to the right
3133 if (pos
->overlay_string_index
>= 0)
3137 /* If the first overlay string happens to have a `display'
3138 property for an image, the iterator will be set up for that
3139 image, and we have to undo that setup first before we can
3140 correct the overlay string index. */
3141 if (it
->method
== GET_FROM_IMAGE
)
3144 /* We already have the first chunk of overlay strings in
3145 IT->overlay_strings. Load more until the one for
3146 pos->overlay_string_index is in IT->overlay_strings. */
3147 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3149 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3150 it
->current
.overlay_string_index
= 0;
3153 load_overlay_strings (it
, 0);
3154 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3158 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3159 relative_index
= (it
->current
.overlay_string_index
3160 % OVERLAY_STRING_CHUNK_SIZE
);
3161 it
->string
= it
->overlay_strings
[relative_index
];
3162 eassert (STRINGP (it
->string
));
3163 it
->current
.string_pos
= pos
->string_pos
;
3164 it
->method
= GET_FROM_STRING
;
3165 it
->end_charpos
= SCHARS (it
->string
);
3166 /* Set up the bidi iterator for this overlay string. */
3169 it
->bidi_it
.string
.lstring
= it
->string
;
3170 it
->bidi_it
.string
.s
= NULL
;
3171 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3172 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3173 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3174 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3175 it
->bidi_it
.w
= it
->w
;
3176 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3177 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3179 /* Synchronize the state of the bidi iterator with
3180 pos->string_pos. For any string position other than
3181 zero, this will be done automagically when we resume
3182 iteration over the string and get_visually_first_element
3183 is called. But if string_pos is zero, and the string is
3184 to be reordered for display, we need to resync manually,
3185 since it could be that the iteration state recorded in
3186 pos ended at string_pos of 0 moving backwards in string. */
3187 if (CHARPOS (pos
->string_pos
) == 0)
3189 get_visually_first_element (it
);
3190 if (IT_STRING_CHARPOS (*it
) != 0)
3193 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3194 bidi_move_to_visually_next (&it
->bidi_it
);
3195 } while (it
->bidi_it
.charpos
!= 0);
3197 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3198 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3202 if (CHARPOS (pos
->string_pos
) >= 0)
3204 /* Recorded position is not in an overlay string, but in another
3205 string. This can only be a string from a `display' property.
3206 IT should already be filled with that string. */
3207 it
->current
.string_pos
= pos
->string_pos
;
3208 eassert (STRINGP (it
->string
));
3210 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3211 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3214 /* Restore position in display vector translations, control
3215 character translations or ellipses. */
3216 if (pos
->dpvec_index
>= 0)
3218 if (it
->dpvec
== NULL
)
3219 get_next_display_element (it
);
3220 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3221 it
->current
.dpvec_index
= pos
->dpvec_index
;
3225 return !overlay_strings_with_newlines
;
3229 /* Initialize IT for stepping through current_buffer in window W
3230 starting at ROW->start. */
3233 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3235 init_from_display_pos (it
, w
, &row
->start
);
3236 it
->start
= row
->start
;
3237 it
->continuation_lines_width
= row
->continuation_lines_width
;
3242 /* Initialize IT for stepping through current_buffer in window W
3243 starting in the line following ROW, i.e. starting at ROW->end.
3244 Value is zero if there are overlay strings with newlines at ROW's
3248 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3252 if (init_from_display_pos (it
, w
, &row
->end
))
3254 if (row
->continued_p
)
3255 it
->continuation_lines_width
3256 = row
->continuation_lines_width
+ row
->pixel_width
;
3267 /***********************************************************************
3269 ***********************************************************************/
3271 /* Called when IT reaches IT->stop_charpos. Handle text property and
3272 overlay changes. Set IT->stop_charpos to the next position where
3276 handle_stop (struct it
*it
)
3278 enum prop_handled handled
;
3279 int handle_overlay_change_p
;
3283 it
->current
.dpvec_index
= -1;
3284 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3285 it
->ignore_overlay_strings_at_pos_p
= 0;
3288 /* Use face of preceding text for ellipsis (if invisible) */
3289 if (it
->selective_display_ellipsis_p
)
3290 it
->saved_face_id
= it
->face_id
;
3294 handled
= HANDLED_NORMALLY
;
3296 /* Call text property handlers. */
3297 for (p
= it_props
; p
->handler
; ++p
)
3299 handled
= p
->handler (it
);
3301 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3303 else if (handled
== HANDLED_RETURN
)
3305 /* We still want to show before and after strings from
3306 overlays even if the actual buffer text is replaced. */
3307 if (!handle_overlay_change_p
3309 /* Don't call get_overlay_strings_1 if we already
3310 have overlay strings loaded, because doing so
3311 will load them again and push the iterator state
3312 onto the stack one more time, which is not
3313 expected by the rest of the code that processes
3315 || (it
->current
.overlay_string_index
< 0
3316 ? !get_overlay_strings_1 (it
, 0, 0)
3320 setup_for_ellipsis (it
, 0);
3321 /* When handling a display spec, we might load an
3322 empty string. In that case, discard it here. We
3323 used to discard it in handle_single_display_spec,
3324 but that causes get_overlay_strings_1, above, to
3325 ignore overlay strings that we must check. */
3326 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3330 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3334 it
->ignore_overlay_strings_at_pos_p
= 1;
3335 it
->string_from_display_prop_p
= 0;
3336 it
->from_disp_prop_p
= 0;
3337 handle_overlay_change_p
= 0;
3339 handled
= HANDLED_RECOMPUTE_PROPS
;
3342 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3343 handle_overlay_change_p
= 0;
3346 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3348 /* Don't check for overlay strings below when set to deliver
3349 characters from a display vector. */
3350 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3351 handle_overlay_change_p
= 0;
3353 /* Handle overlay changes.
3354 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3355 if it finds overlays. */
3356 if (handle_overlay_change_p
)
3357 handled
= handle_overlay_change (it
);
3362 setup_for_ellipsis (it
, 0);
3366 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3368 /* Determine where to stop next. */
3369 if (handled
== HANDLED_NORMALLY
)
3370 compute_stop_pos (it
);
3374 /* Compute IT->stop_charpos from text property and overlay change
3375 information for IT's current position. */
3378 compute_stop_pos (struct it
*it
)
3380 register INTERVAL iv
, next_iv
;
3381 Lisp_Object object
, limit
, position
;
3382 ptrdiff_t charpos
, bytepos
;
3384 if (STRINGP (it
->string
))
3386 /* Strings are usually short, so don't limit the search for
3388 it
->stop_charpos
= it
->end_charpos
;
3389 object
= it
->string
;
3391 charpos
= IT_STRING_CHARPOS (*it
);
3392 bytepos
= IT_STRING_BYTEPOS (*it
);
3398 /* If end_charpos is out of range for some reason, such as a
3399 misbehaving display function, rationalize it (Bug#5984). */
3400 if (it
->end_charpos
> ZV
)
3401 it
->end_charpos
= ZV
;
3402 it
->stop_charpos
= it
->end_charpos
;
3404 /* If next overlay change is in front of the current stop pos
3405 (which is IT->end_charpos), stop there. Note: value of
3406 next_overlay_change is point-max if no overlay change
3408 charpos
= IT_CHARPOS (*it
);
3409 bytepos
= IT_BYTEPOS (*it
);
3410 pos
= next_overlay_change (charpos
);
3411 if (pos
< it
->stop_charpos
)
3412 it
->stop_charpos
= pos
;
3414 /* If showing the region, we have to stop at the region
3415 start or end because the face might change there. */
3416 if (it
->region_beg_charpos
> 0)
3418 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3419 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3420 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3421 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3424 /* Set up variables for computing the stop position from text
3425 property changes. */
3426 XSETBUFFER (object
, current_buffer
);
3427 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3430 /* Get the interval containing IT's position. Value is a null
3431 interval if there isn't such an interval. */
3432 position
= make_number (charpos
);
3433 iv
= validate_interval_range (object
, &position
, &position
, 0);
3436 Lisp_Object values_here
[LAST_PROP_IDX
];
3439 /* Get properties here. */
3440 for (p
= it_props
; p
->handler
; ++p
)
3441 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3443 /* Look for an interval following iv that has different
3445 for (next_iv
= next_interval (iv
);
3448 || XFASTINT (limit
) > next_iv
->position
));
3449 next_iv
= next_interval (next_iv
))
3451 for (p
= it_props
; p
->handler
; ++p
)
3453 Lisp_Object new_value
;
3455 new_value
= textget (next_iv
->plist
, *p
->name
);
3456 if (!EQ (values_here
[p
->idx
], new_value
))
3466 if (INTEGERP (limit
)
3467 && next_iv
->position
>= XFASTINT (limit
))
3468 /* No text property change up to limit. */
3469 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3471 /* Text properties change in next_iv. */
3472 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3476 if (it
->cmp_it
.id
< 0)
3478 ptrdiff_t stoppos
= it
->end_charpos
;
3480 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3482 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3483 stoppos
, it
->string
);
3486 eassert (STRINGP (it
->string
)
3487 || (it
->stop_charpos
>= BEGV
3488 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3492 /* Return the position of the next overlay change after POS in
3493 current_buffer. Value is point-max if no overlay change
3494 follows. This is like `next-overlay-change' but doesn't use
3498 next_overlay_change (ptrdiff_t pos
)
3500 ptrdiff_t i
, noverlays
;
3502 Lisp_Object
*overlays
;
3504 /* Get all overlays at the given position. */
3505 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3507 /* If any of these overlays ends before endpos,
3508 use its ending point instead. */
3509 for (i
= 0; i
< noverlays
; ++i
)
3514 oend
= OVERLAY_END (overlays
[i
]);
3515 oendpos
= OVERLAY_POSITION (oend
);
3516 endpos
= min (endpos
, oendpos
);
3522 /* How many characters forward to search for a display property or
3523 display string. Searching too far forward makes the bidi display
3524 sluggish, especially in small windows. */
3525 #define MAX_DISP_SCAN 250
3527 /* Return the character position of a display string at or after
3528 position specified by POSITION. If no display string exists at or
3529 after POSITION, return ZV. A display string is either an overlay
3530 with `display' property whose value is a string, or a `display'
3531 text property whose value is a string. STRING is data about the
3532 string to iterate; if STRING->lstring is nil, we are iterating a
3533 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3534 on a GUI frame. DISP_PROP is set to zero if we searched
3535 MAX_DISP_SCAN characters forward without finding any display
3536 strings, non-zero otherwise. It is set to 2 if the display string
3537 uses any kind of `(space ...)' spec that will produce a stretch of
3538 white space in the text area. */
3540 compute_display_string_pos (struct text_pos
*position
,
3541 struct bidi_string_data
*string
,
3543 int frame_window_p
, int *disp_prop
)
3545 /* OBJECT = nil means current buffer. */
3546 Lisp_Object object
, object1
;
3547 Lisp_Object pos
, spec
, limpos
;
3548 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3549 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3550 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3551 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3553 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3554 struct text_pos tpos
;
3557 if (string
&& STRINGP (string
->lstring
))
3558 object1
= object
= string
->lstring
;
3559 else if (w
&& !string_p
)
3561 XSETWINDOW (object
, w
);
3565 object1
= object
= Qnil
;
3570 /* We don't support display properties whose values are strings
3571 that have display string properties. */
3572 || string
->from_disp_str
3573 /* C strings cannot have display properties. */
3574 || (string
->s
&& !STRINGP (object
)))
3580 /* If the character at CHARPOS is where the display string begins,
3582 pos
= make_number (charpos
);
3583 if (STRINGP (object
))
3584 bufpos
= string
->bufpos
;
3588 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3590 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3593 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3601 /* Look forward for the first character with a `display' property
3602 that will replace the underlying text when displayed. */
3603 limpos
= make_number (lim
);
3605 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3606 CHARPOS (tpos
) = XFASTINT (pos
);
3607 if (CHARPOS (tpos
) >= lim
)
3612 if (STRINGP (object
))
3613 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3615 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3616 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3617 if (!STRINGP (object
))
3618 bufpos
= CHARPOS (tpos
);
3619 } while (NILP (spec
)
3620 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3621 bufpos
, frame_window_p
)));
3625 return CHARPOS (tpos
);
3628 /* Return the character position of the end of the display string that
3629 started at CHARPOS. If there's no display string at CHARPOS,
3630 return -1. A display string is either an overlay with `display'
3631 property whose value is a string or a `display' text property whose
3632 value is a string. */
3634 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3636 /* OBJECT = nil means current buffer. */
3637 Lisp_Object object
=
3638 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3639 Lisp_Object pos
= make_number (charpos
);
3641 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3643 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3646 /* It could happen that the display property or overlay was removed
3647 since we found it in compute_display_string_pos above. One way
3648 this can happen is if JIT font-lock was called (through
3649 handle_fontified_prop), and jit-lock-functions remove text
3650 properties or overlays from the portion of buffer that includes
3651 CHARPOS. Muse mode is known to do that, for example. In this
3652 case, we return -1 to the caller, to signal that no display
3653 string is actually present at CHARPOS. See bidi_fetch_char for
3654 how this is handled.
3656 An alternative would be to never look for display properties past
3657 it->stop_charpos. But neither compute_display_string_pos nor
3658 bidi_fetch_char that calls it know or care where the next
3660 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3663 /* Look forward for the first character where the `display' property
3665 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3667 return XFASTINT (pos
);
3672 /***********************************************************************
3674 ***********************************************************************/
3676 /* Handle changes in the `fontified' property of the current buffer by
3677 calling hook functions from Qfontification_functions to fontify
3680 static enum prop_handled
3681 handle_fontified_prop (struct it
*it
)
3683 Lisp_Object prop
, pos
;
3684 enum prop_handled handled
= HANDLED_NORMALLY
;
3686 if (!NILP (Vmemory_full
))
3689 /* Get the value of the `fontified' property at IT's current buffer
3690 position. (The `fontified' property doesn't have a special
3691 meaning in strings.) If the value is nil, call functions from
3692 Qfontification_functions. */
3693 if (!STRINGP (it
->string
)
3695 && !NILP (Vfontification_functions
)
3696 && !NILP (Vrun_hooks
)
3697 && (pos
= make_number (IT_CHARPOS (*it
)),
3698 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3699 /* Ignore the special cased nil value always present at EOB since
3700 no amount of fontifying will be able to change it. */
3701 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3703 ptrdiff_t count
= SPECPDL_INDEX ();
3705 struct buffer
*obuf
= current_buffer
;
3706 int begv
= BEGV
, zv
= ZV
;
3707 int old_clip_changed
= current_buffer
->clip_changed
;
3709 val
= Vfontification_functions
;
3710 specbind (Qfontification_functions
, Qnil
);
3712 eassert (it
->end_charpos
== ZV
);
3714 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3715 safe_call1 (val
, pos
);
3718 Lisp_Object fns
, fn
;
3719 struct gcpro gcpro1
, gcpro2
;
3724 for (; CONSP (val
); val
= XCDR (val
))
3730 /* A value of t indicates this hook has a local
3731 binding; it means to run the global binding too.
3732 In a global value, t should not occur. If it
3733 does, we must ignore it to avoid an endless
3735 for (fns
= Fdefault_value (Qfontification_functions
);
3741 safe_call1 (fn
, pos
);
3745 safe_call1 (fn
, pos
);
3751 unbind_to (count
, Qnil
);
3753 /* Fontification functions routinely call `save-restriction'.
3754 Normally, this tags clip_changed, which can confuse redisplay
3755 (see discussion in Bug#6671). Since we don't perform any
3756 special handling of fontification changes in the case where
3757 `save-restriction' isn't called, there's no point doing so in
3758 this case either. So, if the buffer's restrictions are
3759 actually left unchanged, reset clip_changed. */
3760 if (obuf
== current_buffer
)
3762 if (begv
== BEGV
&& zv
== ZV
)
3763 current_buffer
->clip_changed
= old_clip_changed
;
3765 /* There isn't much we can reasonably do to protect against
3766 misbehaving fontification, but here's a fig leaf. */
3767 else if (BUFFER_LIVE_P (obuf
))
3768 set_buffer_internal_1 (obuf
);
3770 /* The fontification code may have added/removed text.
3771 It could do even a lot worse, but let's at least protect against
3772 the most obvious case where only the text past `pos' gets changed',
3773 as is/was done in grep.el where some escapes sequences are turned
3774 into face properties (bug#7876). */
3775 it
->end_charpos
= ZV
;
3777 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3778 something. This avoids an endless loop if they failed to
3779 fontify the text for which reason ever. */
3780 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3781 handled
= HANDLED_RECOMPUTE_PROPS
;
3789 /***********************************************************************
3791 ***********************************************************************/
3793 /* Set up iterator IT from face properties at its current position.
3794 Called from handle_stop. */
3796 static enum prop_handled
3797 handle_face_prop (struct it
*it
)
3800 ptrdiff_t next_stop
;
3802 if (!STRINGP (it
->string
))
3805 = face_at_buffer_position (it
->w
,
3807 it
->region_beg_charpos
,
3808 it
->region_end_charpos
,
3811 + TEXT_PROP_DISTANCE_LIMIT
),
3812 0, it
->base_face_id
);
3814 /* Is this a start of a run of characters with box face?
3815 Caveat: this can be called for a freshly initialized
3816 iterator; face_id is -1 in this case. We know that the new
3817 face will not change until limit, i.e. if the new face has a
3818 box, all characters up to limit will have one. But, as
3819 usual, we don't know whether limit is really the end. */
3820 if (new_face_id
!= it
->face_id
)
3822 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3823 /* If it->face_id is -1, old_face below will be NULL, see
3824 the definition of FACE_FROM_ID. This will happen if this
3825 is the initial call that gets the face. */
3826 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3828 /* If the value of face_id of the iterator is -1, we have to
3829 look in front of IT's position and see whether there is a
3830 face there that's different from new_face_id. */
3831 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3833 int prev_face_id
= face_before_it_pos (it
);
3835 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3838 /* If the new face has a box, but the old face does not,
3839 this is the start of a run of characters with box face,
3840 i.e. this character has a shadow on the left side. */
3841 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3842 && (old_face
== NULL
|| !old_face
->box
));
3843 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3851 Lisp_Object from_overlay
3852 = (it
->current
.overlay_string_index
>= 0
3853 ? it
->string_overlays
[it
->current
.overlay_string_index
3854 % OVERLAY_STRING_CHUNK_SIZE
]
3857 /* See if we got to this string directly or indirectly from
3858 an overlay property. That includes the before-string or
3859 after-string of an overlay, strings in display properties
3860 provided by an overlay, their text properties, etc.
3862 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3863 if (! NILP (from_overlay
))
3864 for (i
= it
->sp
- 1; i
>= 0; i
--)
3866 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3868 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3869 % OVERLAY_STRING_CHUNK_SIZE
];
3870 else if (! NILP (it
->stack
[i
].from_overlay
))
3871 from_overlay
= it
->stack
[i
].from_overlay
;
3873 if (!NILP (from_overlay
))
3877 if (! NILP (from_overlay
))
3879 bufpos
= IT_CHARPOS (*it
);
3880 /* For a string from an overlay, the base face depends
3881 only on text properties and ignores overlays. */
3883 = face_for_overlay_string (it
->w
,
3885 it
->region_beg_charpos
,
3886 it
->region_end_charpos
,
3889 + TEXT_PROP_DISTANCE_LIMIT
),
3897 /* For strings from a `display' property, use the face at
3898 IT's current buffer position as the base face to merge
3899 with, so that overlay strings appear in the same face as
3900 surrounding text, unless they specify their own faces.
3901 For strings from wrap-prefix and line-prefix properties,
3902 use the default face, possibly remapped via
3903 Vface_remapping_alist. */
3904 base_face_id
= it
->string_from_prefix_prop_p
3905 ? (!NILP (Vface_remapping_alist
)
3906 ? lookup_basic_face (it
->f
, DEFAULT_FACE_ID
)
3908 : underlying_face_id (it
);
3911 new_face_id
= face_at_string_position (it
->w
,
3913 IT_STRING_CHARPOS (*it
),
3915 it
->region_beg_charpos
,
3916 it
->region_end_charpos
,
3920 /* Is this a start of a run of characters with box? Caveat:
3921 this can be called for a freshly allocated iterator; face_id
3922 is -1 is this case. We know that the new face will not
3923 change until the next check pos, i.e. if the new face has a
3924 box, all characters up to that position will have a
3925 box. But, as usual, we don't know whether that position
3926 is really the end. */
3927 if (new_face_id
!= it
->face_id
)
3929 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3930 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3932 /* If new face has a box but old face hasn't, this is the
3933 start of a run of characters with box, i.e. it has a
3934 shadow on the left side. */
3935 it
->start_of_box_run_p
3936 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3937 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3941 it
->face_id
= new_face_id
;
3942 return HANDLED_NORMALLY
;
3946 /* Return the ID of the face ``underlying'' IT's current position,
3947 which is in a string. If the iterator is associated with a
3948 buffer, return the face at IT's current buffer position.
3949 Otherwise, use the iterator's base_face_id. */
3952 underlying_face_id (struct it
*it
)
3954 int face_id
= it
->base_face_id
, i
;
3956 eassert (STRINGP (it
->string
));
3958 for (i
= it
->sp
- 1; i
>= 0; --i
)
3959 if (NILP (it
->stack
[i
].string
))
3960 face_id
= it
->stack
[i
].face_id
;
3966 /* Compute the face one character before or after the current position
3967 of IT, in the visual order. BEFORE_P non-zero means get the face
3968 in front (to the left in L2R paragraphs, to the right in R2L
3969 paragraphs) of IT's screen position. Value is the ID of the face. */
3972 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3975 ptrdiff_t next_check_charpos
;
3977 void *it_copy_data
= NULL
;
3979 eassert (it
->s
== NULL
);
3981 if (STRINGP (it
->string
))
3983 ptrdiff_t bufpos
, charpos
;
3986 /* No face change past the end of the string (for the case
3987 we are padding with spaces). No face change before the
3989 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3990 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
3995 /* Set charpos to the position before or after IT's current
3996 position, in the logical order, which in the non-bidi
3997 case is the same as the visual order. */
3999 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4000 else if (it
->what
== IT_COMPOSITION
)
4001 /* For composition, we must check the character after the
4003 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4005 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4011 /* With bidi iteration, the character before the current
4012 in the visual order cannot be found by simple
4013 iteration, because "reverse" reordering is not
4014 supported. Instead, we need to use the move_it_*
4015 family of functions. */
4016 /* Ignore face changes before the first visible
4017 character on this display line. */
4018 if (it
->current_x
<= it
->first_visible_x
)
4020 SAVE_IT (it_copy
, *it
, it_copy_data
);
4021 /* Implementation note: Since move_it_in_display_line
4022 works in the iterator geometry, and thinks the first
4023 character is always the leftmost, even in R2L lines,
4024 we don't need to distinguish between the R2L and L2R
4026 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4027 it_copy
.current_x
- 1, MOVE_TO_X
);
4028 charpos
= IT_STRING_CHARPOS (it_copy
);
4029 RESTORE_IT (it
, it
, it_copy_data
);
4033 /* Set charpos to the string position of the character
4034 that comes after IT's current position in the visual
4036 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4040 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4042 charpos
= it_copy
.bidi_it
.charpos
;
4045 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4047 if (it
->current
.overlay_string_index
>= 0)
4048 bufpos
= IT_CHARPOS (*it
);
4052 base_face_id
= underlying_face_id (it
);
4054 /* Get the face for ASCII, or unibyte. */
4055 face_id
= face_at_string_position (it
->w
,
4059 it
->region_beg_charpos
,
4060 it
->region_end_charpos
,
4061 &next_check_charpos
,
4064 /* Correct the face for charsets different from ASCII. Do it
4065 for the multibyte case only. The face returned above is
4066 suitable for unibyte text if IT->string is unibyte. */
4067 if (STRING_MULTIBYTE (it
->string
))
4069 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4070 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4072 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4074 c
= string_char_and_length (p
, &len
);
4075 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4080 struct text_pos pos
;
4082 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4083 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4086 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4087 pos
= it
->current
.pos
;
4092 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4095 if (it
->what
== IT_COMPOSITION
)
4097 /* For composition, we must check the position after
4099 pos
.charpos
+= it
->cmp_it
.nchars
;
4100 pos
.bytepos
+= it
->len
;
4103 INC_TEXT_POS (pos
, it
->multibyte_p
);
4110 /* With bidi iteration, the character before the current
4111 in the visual order cannot be found by simple
4112 iteration, because "reverse" reordering is not
4113 supported. Instead, we need to use the move_it_*
4114 family of functions. */
4115 /* Ignore face changes before the first visible
4116 character on this display line. */
4117 if (it
->current_x
<= it
->first_visible_x
)
4119 SAVE_IT (it_copy
, *it
, it_copy_data
);
4120 /* Implementation note: Since move_it_in_display_line
4121 works in the iterator geometry, and thinks the first
4122 character is always the leftmost, even in R2L lines,
4123 we don't need to distinguish between the R2L and L2R
4125 move_it_in_display_line (&it_copy
, ZV
,
4126 it_copy
.current_x
- 1, MOVE_TO_X
);
4127 pos
= it_copy
.current
.pos
;
4128 RESTORE_IT (it
, it
, it_copy_data
);
4132 /* Set charpos to the buffer position of the character
4133 that comes after IT's current position in the visual
4135 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4139 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4142 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4145 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4147 /* Determine face for CHARSET_ASCII, or unibyte. */
4148 face_id
= face_at_buffer_position (it
->w
,
4150 it
->region_beg_charpos
,
4151 it
->region_end_charpos
,
4152 &next_check_charpos
,
4155 /* Correct the face for charsets different from ASCII. Do it
4156 for the multibyte case only. The face returned above is
4157 suitable for unibyte text if current_buffer is unibyte. */
4158 if (it
->multibyte_p
)
4160 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4161 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4162 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4171 /***********************************************************************
4173 ***********************************************************************/
4175 /* Set up iterator IT from invisible properties at its current
4176 position. Called from handle_stop. */
4178 static enum prop_handled
4179 handle_invisible_prop (struct it
*it
)
4181 enum prop_handled handled
= HANDLED_NORMALLY
;
4185 if (STRINGP (it
->string
))
4187 Lisp_Object end_charpos
, limit
, charpos
;
4189 /* Get the value of the invisible text property at the
4190 current position. Value will be nil if there is no such
4192 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4193 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4194 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4196 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4198 /* Record whether we have to display an ellipsis for the
4200 int display_ellipsis_p
= (invis_p
== 2);
4201 ptrdiff_t len
, endpos
;
4203 handled
= HANDLED_RECOMPUTE_PROPS
;
4205 /* Get the position at which the next visible text can be
4206 found in IT->string, if any. */
4207 endpos
= len
= SCHARS (it
->string
);
4208 XSETINT (limit
, len
);
4211 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4213 if (INTEGERP (end_charpos
))
4215 endpos
= XFASTINT (end_charpos
);
4216 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4217 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4219 display_ellipsis_p
= 1;
4222 while (invis_p
&& endpos
< len
);
4224 if (display_ellipsis_p
)
4229 /* Text at END_CHARPOS is visible. Move IT there. */
4230 struct text_pos old
;
4233 old
= it
->current
.string_pos
;
4234 oldpos
= CHARPOS (old
);
4237 if (it
->bidi_it
.first_elt
4238 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4239 bidi_paragraph_init (it
->paragraph_embedding
,
4241 /* Bidi-iterate out of the invisible text. */
4244 bidi_move_to_visually_next (&it
->bidi_it
);
4246 while (oldpos
<= it
->bidi_it
.charpos
4247 && it
->bidi_it
.charpos
< endpos
);
4249 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4250 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4251 if (IT_CHARPOS (*it
) >= endpos
)
4252 it
->prev_stop
= endpos
;
4256 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4257 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4262 /* The rest of the string is invisible. If this is an
4263 overlay string, proceed with the next overlay string
4264 or whatever comes and return a character from there. */
4265 if (it
->current
.overlay_string_index
>= 0
4266 && !display_ellipsis_p
)
4268 next_overlay_string (it
);
4269 /* Don't check for overlay strings when we just
4270 finished processing them. */
4271 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4275 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4276 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4283 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4284 Lisp_Object pos
, overlay
;
4286 /* First of all, is there invisible text at this position? */
4287 tem
= start_charpos
= IT_CHARPOS (*it
);
4288 pos
= make_number (tem
);
4289 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4291 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4293 /* If we are on invisible text, skip over it. */
4294 if (invis_p
&& start_charpos
< it
->end_charpos
)
4296 /* Record whether we have to display an ellipsis for the
4298 int display_ellipsis_p
= invis_p
== 2;
4300 handled
= HANDLED_RECOMPUTE_PROPS
;
4302 /* Loop skipping over invisible text. The loop is left at
4303 ZV or with IT on the first char being visible again. */
4306 /* Try to skip some invisible text. Return value is the
4307 position reached which can be equal to where we start
4308 if there is nothing invisible there. This skips both
4309 over invisible text properties and overlays with
4310 invisible property. */
4311 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4313 /* If we skipped nothing at all we weren't at invisible
4314 text in the first place. If everything to the end of
4315 the buffer was skipped, end the loop. */
4316 if (newpos
== tem
|| newpos
>= ZV
)
4320 /* We skipped some characters but not necessarily
4321 all there are. Check if we ended up on visible
4322 text. Fget_char_property returns the property of
4323 the char before the given position, i.e. if we
4324 get invis_p = 0, this means that the char at
4325 newpos is visible. */
4326 pos
= make_number (newpos
);
4327 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4328 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4331 /* If we ended up on invisible text, proceed to
4332 skip starting with next_stop. */
4336 /* If there are adjacent invisible texts, don't lose the
4337 second one's ellipsis. */
4339 display_ellipsis_p
= 1;
4343 /* The position newpos is now either ZV or on visible text. */
4346 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4348 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4350 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4352 /* If the invisible text ends on a newline or on a
4353 character after a newline, we can avoid the costly,
4354 character by character, bidi iteration to NEWPOS, and
4355 instead simply reseat the iterator there. That's
4356 because all bidi reordering information is tossed at
4357 the newline. This is a big win for modes that hide
4358 complete lines, like Outline, Org, etc. */
4359 if (on_newline
|| after_newline
)
4361 struct text_pos tpos
;
4362 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4364 SET_TEXT_POS (tpos
, newpos
, bpos
);
4365 reseat_1 (it
, tpos
, 0);
4366 /* If we reseat on a newline/ZV, we need to prep the
4367 bidi iterator for advancing to the next character
4368 after the newline/EOB, keeping the current paragraph
4369 direction (so that PRODUCE_GLYPHS does TRT wrt
4370 prepending/appending glyphs to a glyph row). */
4373 it
->bidi_it
.first_elt
= 0;
4374 it
->bidi_it
.paragraph_dir
= pdir
;
4375 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4376 it
->bidi_it
.nchars
= 1;
4377 it
->bidi_it
.ch_len
= 1;
4380 else /* Must use the slow method. */
4382 /* With bidi iteration, the region of invisible text
4383 could start and/or end in the middle of a
4384 non-base embedding level. Therefore, we need to
4385 skip invisible text using the bidi iterator,
4386 starting at IT's current position, until we find
4387 ourselves outside of the invisible text.
4388 Skipping invisible text _after_ bidi iteration
4389 avoids affecting the visual order of the
4390 displayed text when invisible properties are
4391 added or removed. */
4392 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4394 /* If we were `reseat'ed to a new paragraph,
4395 determine the paragraph base direction. We
4396 need to do it now because
4397 next_element_from_buffer may not have a
4398 chance to do it, if we are going to skip any
4399 text at the beginning, which resets the
4401 bidi_paragraph_init (it
->paragraph_embedding
,
4406 bidi_move_to_visually_next (&it
->bidi_it
);
4408 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4409 && it
->bidi_it
.charpos
< newpos
);
4410 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4411 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4412 /* If we overstepped NEWPOS, record its position in
4413 the iterator, so that we skip invisible text if
4414 later the bidi iteration lands us in the
4415 invisible region again. */
4416 if (IT_CHARPOS (*it
) >= newpos
)
4417 it
->prev_stop
= newpos
;
4422 IT_CHARPOS (*it
) = newpos
;
4423 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4426 /* If there are before-strings at the start of invisible
4427 text, and the text is invisible because of a text
4428 property, arrange to show before-strings because 20.x did
4429 it that way. (If the text is invisible because of an
4430 overlay property instead of a text property, this is
4431 already handled in the overlay code.) */
4433 && get_overlay_strings (it
, it
->stop_charpos
))
4435 handled
= HANDLED_RECOMPUTE_PROPS
;
4436 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4438 else if (display_ellipsis_p
)
4440 /* Make sure that the glyphs of the ellipsis will get
4441 correct `charpos' values. If we would not update
4442 it->position here, the glyphs would belong to the
4443 last visible character _before_ the invisible
4444 text, which confuses `set_cursor_from_row'.
4446 We use the last invisible position instead of the
4447 first because this way the cursor is always drawn on
4448 the first "." of the ellipsis, whenever PT is inside
4449 the invisible text. Otherwise the cursor would be
4450 placed _after_ the ellipsis when the point is after the
4451 first invisible character. */
4452 if (!STRINGP (it
->object
))
4454 it
->position
.charpos
= newpos
- 1;
4455 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4458 /* Let the ellipsis display before
4459 considering any properties of the following char.
4460 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4461 handled
= HANDLED_RETURN
;
4470 /* Make iterator IT return `...' next.
4471 Replaces LEN characters from buffer. */
4474 setup_for_ellipsis (struct it
*it
, int len
)
4476 /* Use the display table definition for `...'. Invalid glyphs
4477 will be handled by the method returning elements from dpvec. */
4478 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4480 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4481 it
->dpvec
= v
->contents
;
4482 it
->dpend
= v
->contents
+ v
->header
.size
;
4486 /* Default `...'. */
4487 it
->dpvec
= default_invis_vector
;
4488 it
->dpend
= default_invis_vector
+ 3;
4491 it
->dpvec_char_len
= len
;
4492 it
->current
.dpvec_index
= 0;
4493 it
->dpvec_face_id
= -1;
4495 /* Remember the current face id in case glyphs specify faces.
4496 IT's face is restored in set_iterator_to_next.
4497 saved_face_id was set to preceding char's face in handle_stop. */
4498 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4499 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4501 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4507 /***********************************************************************
4509 ***********************************************************************/
4511 /* Set up iterator IT from `display' property at its current position.
4512 Called from handle_stop.
4513 We return HANDLED_RETURN if some part of the display property
4514 overrides the display of the buffer text itself.
4515 Otherwise we return HANDLED_NORMALLY. */
4517 static enum prop_handled
4518 handle_display_prop (struct it
*it
)
4520 Lisp_Object propval
, object
, overlay
;
4521 struct text_pos
*position
;
4523 /* Nonzero if some property replaces the display of the text itself. */
4524 int display_replaced_p
= 0;
4526 if (STRINGP (it
->string
))
4528 object
= it
->string
;
4529 position
= &it
->current
.string_pos
;
4530 bufpos
= CHARPOS (it
->current
.pos
);
4534 XSETWINDOW (object
, it
->w
);
4535 position
= &it
->current
.pos
;
4536 bufpos
= CHARPOS (*position
);
4539 /* Reset those iterator values set from display property values. */
4540 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4541 it
->space_width
= Qnil
;
4542 it
->font_height
= Qnil
;
4545 /* We don't support recursive `display' properties, i.e. string
4546 values that have a string `display' property, that have a string
4547 `display' property etc. */
4548 if (!it
->string_from_display_prop_p
)
4549 it
->area
= TEXT_AREA
;
4551 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4552 Qdisplay
, object
, &overlay
);
4554 return HANDLED_NORMALLY
;
4555 /* Now OVERLAY is the overlay that gave us this property, or nil
4556 if it was a text property. */
4558 if (!STRINGP (it
->string
))
4559 object
= it
->w
->contents
;
4561 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4563 FRAME_WINDOW_P (it
->f
));
4565 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4568 /* Subroutine of handle_display_prop. Returns non-zero if the display
4569 specification in SPEC is a replacing specification, i.e. it would
4570 replace the text covered by `display' property with something else,
4571 such as an image or a display string. If SPEC includes any kind or
4572 `(space ...) specification, the value is 2; this is used by
4573 compute_display_string_pos, which see.
4575 See handle_single_display_spec for documentation of arguments.
4576 frame_window_p is non-zero if the window being redisplayed is on a
4577 GUI frame; this argument is used only if IT is NULL, see below.
4579 IT can be NULL, if this is called by the bidi reordering code
4580 through compute_display_string_pos, which see. In that case, this
4581 function only examines SPEC, but does not otherwise "handle" it, in
4582 the sense that it doesn't set up members of IT from the display
4585 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4586 Lisp_Object overlay
, struct text_pos
*position
,
4587 ptrdiff_t bufpos
, int frame_window_p
)
4589 int replacing_p
= 0;
4593 /* Simple specifications. */
4594 && !EQ (XCAR (spec
), Qimage
)
4595 && !EQ (XCAR (spec
), Qspace
)
4596 && !EQ (XCAR (spec
), Qwhen
)
4597 && !EQ (XCAR (spec
), Qslice
)
4598 && !EQ (XCAR (spec
), Qspace_width
)
4599 && !EQ (XCAR (spec
), Qheight
)
4600 && !EQ (XCAR (spec
), Qraise
)
4601 /* Marginal area specifications. */
4602 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4603 && !EQ (XCAR (spec
), Qleft_fringe
)
4604 && !EQ (XCAR (spec
), Qright_fringe
)
4605 && !NILP (XCAR (spec
)))
4607 for (; CONSP (spec
); spec
= XCDR (spec
))
4609 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4610 overlay
, position
, bufpos
,
4611 replacing_p
, frame_window_p
)))
4614 /* If some text in a string is replaced, `position' no
4615 longer points to the position of `object'. */
4616 if (!it
|| STRINGP (object
))
4621 else if (VECTORP (spec
))
4624 for (i
= 0; i
< ASIZE (spec
); ++i
)
4625 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4626 overlay
, position
, bufpos
,
4627 replacing_p
, frame_window_p
)))
4630 /* If some text in a string is replaced, `position' no
4631 longer points to the position of `object'. */
4632 if (!it
|| STRINGP (object
))
4638 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4639 position
, bufpos
, 0,
4647 /* Value is the position of the end of the `display' property starting
4648 at START_POS in OBJECT. */
4650 static struct text_pos
4651 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4654 struct text_pos end_pos
;
4656 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4657 Qdisplay
, object
, Qnil
);
4658 CHARPOS (end_pos
) = XFASTINT (end
);
4659 if (STRINGP (object
))
4660 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4662 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4668 /* Set up IT from a single `display' property specification SPEC. OBJECT
4669 is the object in which the `display' property was found. *POSITION
4670 is the position in OBJECT at which the `display' property was found.
4671 BUFPOS is the buffer position of OBJECT (different from POSITION if
4672 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4673 previously saw a display specification which already replaced text
4674 display with something else, for example an image; we ignore such
4675 properties after the first one has been processed.
4677 OVERLAY is the overlay this `display' property came from,
4678 or nil if it was a text property.
4680 If SPEC is a `space' or `image' specification, and in some other
4681 cases too, set *POSITION to the position where the `display'
4684 If IT is NULL, only examine the property specification in SPEC, but
4685 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4686 is intended to be displayed in a window on a GUI frame.
4688 Value is non-zero if something was found which replaces the display
4689 of buffer or string text. */
4692 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4693 Lisp_Object overlay
, struct text_pos
*position
,
4694 ptrdiff_t bufpos
, int display_replaced_p
,
4698 Lisp_Object location
, value
;
4699 struct text_pos start_pos
= *position
;
4702 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4703 If the result is non-nil, use VALUE instead of SPEC. */
4705 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4714 if (!NILP (form
) && !EQ (form
, Qt
))
4716 ptrdiff_t count
= SPECPDL_INDEX ();
4717 struct gcpro gcpro1
;
4719 /* Bind `object' to the object having the `display' property, a
4720 buffer or string. Bind `position' to the position in the
4721 object where the property was found, and `buffer-position'
4722 to the current position in the buffer. */
4725 XSETBUFFER (object
, current_buffer
);
4726 specbind (Qobject
, object
);
4727 specbind (Qposition
, make_number (CHARPOS (*position
)));
4728 specbind (Qbuffer_position
, make_number (bufpos
));
4730 form
= safe_eval (form
);
4732 unbind_to (count
, Qnil
);
4738 /* Handle `(height HEIGHT)' specifications. */
4740 && EQ (XCAR (spec
), Qheight
)
4741 && CONSP (XCDR (spec
)))
4745 if (!FRAME_WINDOW_P (it
->f
))
4748 it
->font_height
= XCAR (XCDR (spec
));
4749 if (!NILP (it
->font_height
))
4751 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4752 int new_height
= -1;
4754 if (CONSP (it
->font_height
)
4755 && (EQ (XCAR (it
->font_height
), Qplus
)
4756 || EQ (XCAR (it
->font_height
), Qminus
))
4757 && CONSP (XCDR (it
->font_height
))
4758 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4760 /* `(+ N)' or `(- N)' where N is an integer. */
4761 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4762 if (EQ (XCAR (it
->font_height
), Qplus
))
4764 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4766 else if (FUNCTIONP (it
->font_height
))
4768 /* Call function with current height as argument.
4769 Value is the new height. */
4771 height
= safe_call1 (it
->font_height
,
4772 face
->lface
[LFACE_HEIGHT_INDEX
]);
4773 if (NUMBERP (height
))
4774 new_height
= XFLOATINT (height
);
4776 else if (NUMBERP (it
->font_height
))
4778 /* Value is a multiple of the canonical char height. */
4781 f
= FACE_FROM_ID (it
->f
,
4782 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4783 new_height
= (XFLOATINT (it
->font_height
)
4784 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4788 /* Evaluate IT->font_height with `height' bound to the
4789 current specified height to get the new height. */
4790 ptrdiff_t count
= SPECPDL_INDEX ();
4792 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4793 value
= safe_eval (it
->font_height
);
4794 unbind_to (count
, Qnil
);
4796 if (NUMBERP (value
))
4797 new_height
= XFLOATINT (value
);
4801 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4808 /* Handle `(space-width WIDTH)'. */
4810 && EQ (XCAR (spec
), Qspace_width
)
4811 && CONSP (XCDR (spec
)))
4815 if (!FRAME_WINDOW_P (it
->f
))
4818 value
= XCAR (XCDR (spec
));
4819 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4820 it
->space_width
= value
;
4826 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4828 && EQ (XCAR (spec
), Qslice
))
4834 if (!FRAME_WINDOW_P (it
->f
))
4837 if (tem
= XCDR (spec
), CONSP (tem
))
4839 it
->slice
.x
= XCAR (tem
);
4840 if (tem
= XCDR (tem
), CONSP (tem
))
4842 it
->slice
.y
= XCAR (tem
);
4843 if (tem
= XCDR (tem
), CONSP (tem
))
4845 it
->slice
.width
= XCAR (tem
);
4846 if (tem
= XCDR (tem
), CONSP (tem
))
4847 it
->slice
.height
= XCAR (tem
);
4856 /* Handle `(raise FACTOR)'. */
4858 && EQ (XCAR (spec
), Qraise
)
4859 && CONSP (XCDR (spec
)))
4863 if (!FRAME_WINDOW_P (it
->f
))
4866 #ifdef HAVE_WINDOW_SYSTEM
4867 value
= XCAR (XCDR (spec
));
4868 if (NUMBERP (value
))
4870 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4871 it
->voffset
= - (XFLOATINT (value
)
4872 * (FONT_HEIGHT (face
->font
)));
4874 #endif /* HAVE_WINDOW_SYSTEM */
4880 /* Don't handle the other kinds of display specifications
4881 inside a string that we got from a `display' property. */
4882 if (it
&& it
->string_from_display_prop_p
)
4885 /* Characters having this form of property are not displayed, so
4886 we have to find the end of the property. */
4889 start_pos
= *position
;
4890 *position
= display_prop_end (it
, object
, start_pos
);
4894 /* Stop the scan at that end position--we assume that all
4895 text properties change there. */
4897 it
->stop_charpos
= position
->charpos
;
4899 /* Handle `(left-fringe BITMAP [FACE])'
4900 and `(right-fringe BITMAP [FACE])'. */
4902 && (EQ (XCAR (spec
), Qleft_fringe
)
4903 || EQ (XCAR (spec
), Qright_fringe
))
4904 && CONSP (XCDR (spec
)))
4910 if (!FRAME_WINDOW_P (it
->f
))
4911 /* If we return here, POSITION has been advanced
4912 across the text with this property. */
4914 /* Synchronize the bidi iterator with POSITION. This is
4915 needed because we are not going to push the iterator
4916 on behalf of this display property, so there will be
4917 no pop_it call to do this synchronization for us. */
4920 it
->position
= *position
;
4921 iterate_out_of_display_property (it
);
4922 *position
= it
->position
;
4927 else if (!frame_window_p
)
4930 #ifdef HAVE_WINDOW_SYSTEM
4931 value
= XCAR (XCDR (spec
));
4932 if (!SYMBOLP (value
)
4933 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4934 /* If we return here, POSITION has been advanced
4935 across the text with this property. */
4937 if (it
&& it
->bidi_p
)
4939 it
->position
= *position
;
4940 iterate_out_of_display_property (it
);
4941 *position
= it
->position
;
4948 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4950 if (CONSP (XCDR (XCDR (spec
))))
4952 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4953 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4959 /* Save current settings of IT so that we can restore them
4960 when we are finished with the glyph property value. */
4961 push_it (it
, position
);
4963 it
->area
= TEXT_AREA
;
4964 it
->what
= IT_IMAGE
;
4965 it
->image_id
= -1; /* no image */
4966 it
->position
= start_pos
;
4967 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4968 it
->method
= GET_FROM_IMAGE
;
4969 it
->from_overlay
= Qnil
;
4970 it
->face_id
= face_id
;
4971 it
->from_disp_prop_p
= 1;
4973 /* Say that we haven't consumed the characters with
4974 `display' property yet. The call to pop_it in
4975 set_iterator_to_next will clean this up. */
4976 *position
= start_pos
;
4978 if (EQ (XCAR (spec
), Qleft_fringe
))
4980 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4981 it
->left_user_fringe_face_id
= face_id
;
4985 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4986 it
->right_user_fringe_face_id
= face_id
;
4989 #endif /* HAVE_WINDOW_SYSTEM */
4993 /* Prepare to handle `((margin left-margin) ...)',
4994 `((margin right-margin) ...)' and `((margin nil) ...)'
4995 prefixes for display specifications. */
4996 location
= Qunbound
;
4997 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5001 value
= XCDR (spec
);
5003 value
= XCAR (value
);
5006 if (EQ (XCAR (tem
), Qmargin
)
5007 && (tem
= XCDR (tem
),
5008 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5010 || EQ (tem
, Qleft_margin
)
5011 || EQ (tem
, Qright_margin
))))
5015 if (EQ (location
, Qunbound
))
5021 /* After this point, VALUE is the property after any
5022 margin prefix has been stripped. It must be a string,
5023 an image specification, or `(space ...)'.
5025 LOCATION specifies where to display: `left-margin',
5026 `right-margin' or nil. */
5028 valid_p
= (STRINGP (value
)
5029 #ifdef HAVE_WINDOW_SYSTEM
5030 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5031 && valid_image_p (value
))
5032 #endif /* not HAVE_WINDOW_SYSTEM */
5033 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5035 if (valid_p
&& !display_replaced_p
)
5041 /* Callers need to know whether the display spec is any kind
5042 of `(space ...)' spec that is about to affect text-area
5044 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5049 /* Save current settings of IT so that we can restore them
5050 when we are finished with the glyph property value. */
5051 push_it (it
, position
);
5052 it
->from_overlay
= overlay
;
5053 it
->from_disp_prop_p
= 1;
5055 if (NILP (location
))
5056 it
->area
= TEXT_AREA
;
5057 else if (EQ (location
, Qleft_margin
))
5058 it
->area
= LEFT_MARGIN_AREA
;
5060 it
->area
= RIGHT_MARGIN_AREA
;
5062 if (STRINGP (value
))
5065 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5066 it
->current
.overlay_string_index
= -1;
5067 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5068 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5069 it
->method
= GET_FROM_STRING
;
5070 it
->stop_charpos
= 0;
5072 it
->base_level_stop
= 0;
5073 it
->string_from_display_prop_p
= 1;
5074 /* Say that we haven't consumed the characters with
5075 `display' property yet. The call to pop_it in
5076 set_iterator_to_next will clean this up. */
5077 if (BUFFERP (object
))
5078 *position
= start_pos
;
5080 /* Force paragraph direction to be that of the parent
5081 object. If the parent object's paragraph direction is
5082 not yet determined, default to L2R. */
5083 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5084 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5086 it
->paragraph_embedding
= L2R
;
5088 /* Set up the bidi iterator for this display string. */
5091 it
->bidi_it
.string
.lstring
= it
->string
;
5092 it
->bidi_it
.string
.s
= NULL
;
5093 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5094 it
->bidi_it
.string
.bufpos
= bufpos
;
5095 it
->bidi_it
.string
.from_disp_str
= 1;
5096 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5097 it
->bidi_it
.w
= it
->w
;
5098 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5101 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5103 it
->method
= GET_FROM_STRETCH
;
5105 *position
= it
->position
= start_pos
;
5106 retval
= 1 + (it
->area
== TEXT_AREA
);
5108 #ifdef HAVE_WINDOW_SYSTEM
5111 it
->what
= IT_IMAGE
;
5112 it
->image_id
= lookup_image (it
->f
, value
);
5113 it
->position
= start_pos
;
5114 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5115 it
->method
= GET_FROM_IMAGE
;
5117 /* Say that we haven't consumed the characters with
5118 `display' property yet. The call to pop_it in
5119 set_iterator_to_next will clean this up. */
5120 *position
= start_pos
;
5122 #endif /* HAVE_WINDOW_SYSTEM */
5127 /* Invalid property or property not supported. Restore
5128 POSITION to what it was before. */
5129 *position
= start_pos
;
5133 /* Check if PROP is a display property value whose text should be
5134 treated as intangible. OVERLAY is the overlay from which PROP
5135 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5136 specify the buffer position covered by PROP. */
5139 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5140 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5142 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5143 struct text_pos position
;
5145 SET_TEXT_POS (position
, charpos
, bytepos
);
5146 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5147 &position
, charpos
, frame_window_p
);
5151 /* Return 1 if PROP is a display sub-property value containing STRING.
5153 Implementation note: this and the following function are really
5154 special cases of handle_display_spec and
5155 handle_single_display_spec, and should ideally use the same code.
5156 Until they do, these two pairs must be consistent and must be
5157 modified in sync. */
5160 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5162 if (EQ (string
, prop
))
5165 /* Skip over `when FORM'. */
5166 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5171 /* Actually, the condition following `when' should be eval'ed,
5172 like handle_single_display_spec does, and we should return
5173 zero if it evaluates to nil. However, this function is
5174 called only when the buffer was already displayed and some
5175 glyph in the glyph matrix was found to come from a display
5176 string. Therefore, the condition was already evaluated, and
5177 the result was non-nil, otherwise the display string wouldn't
5178 have been displayed and we would have never been called for
5179 this property. Thus, we can skip the evaluation and assume
5180 its result is non-nil. */
5185 /* Skip over `margin LOCATION'. */
5186 if (EQ (XCAR (prop
), Qmargin
))
5197 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5201 /* Return 1 if STRING appears in the `display' property PROP. */
5204 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5207 && !EQ (XCAR (prop
), Qwhen
)
5208 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5210 /* A list of sub-properties. */
5211 while (CONSP (prop
))
5213 if (single_display_spec_string_p (XCAR (prop
), string
))
5218 else if (VECTORP (prop
))
5220 /* A vector of sub-properties. */
5222 for (i
= 0; i
< ASIZE (prop
); ++i
)
5223 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5227 return single_display_spec_string_p (prop
, string
);
5232 /* Look for STRING in overlays and text properties in the current
5233 buffer, between character positions FROM and TO (excluding TO).
5234 BACK_P non-zero means look back (in this case, TO is supposed to be
5236 Value is the first character position where STRING was found, or
5237 zero if it wasn't found before hitting TO.
5239 This function may only use code that doesn't eval because it is
5240 called asynchronously from note_mouse_highlight. */
5243 string_buffer_position_lim (Lisp_Object string
,
5244 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5246 Lisp_Object limit
, prop
, pos
;
5249 pos
= make_number (max (from
, BEGV
));
5251 if (!back_p
) /* looking forward */
5253 limit
= make_number (min (to
, ZV
));
5254 while (!found
&& !EQ (pos
, limit
))
5256 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5257 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5260 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5264 else /* looking back */
5266 limit
= make_number (max (to
, BEGV
));
5267 while (!found
&& !EQ (pos
, limit
))
5269 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5270 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5273 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5278 return found
? XINT (pos
) : 0;
5281 /* Determine which buffer position in current buffer STRING comes from.
5282 AROUND_CHARPOS is an approximate position where it could come from.
5283 Value is the buffer position or 0 if it couldn't be determined.
5285 This function is necessary because we don't record buffer positions
5286 in glyphs generated from strings (to keep struct glyph small).
5287 This function may only use code that doesn't eval because it is
5288 called asynchronously from note_mouse_highlight. */
5291 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5293 const int MAX_DISTANCE
= 1000;
5294 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5295 around_charpos
+ MAX_DISTANCE
,
5299 found
= string_buffer_position_lim (string
, around_charpos
,
5300 around_charpos
- MAX_DISTANCE
, 1);
5306 /***********************************************************************
5307 `composition' property
5308 ***********************************************************************/
5310 /* Set up iterator IT from `composition' property at its current
5311 position. Called from handle_stop. */
5313 static enum prop_handled
5314 handle_composition_prop (struct it
*it
)
5316 Lisp_Object prop
, string
;
5317 ptrdiff_t pos
, pos_byte
, start
, end
;
5319 if (STRINGP (it
->string
))
5323 pos
= IT_STRING_CHARPOS (*it
);
5324 pos_byte
= IT_STRING_BYTEPOS (*it
);
5325 string
= it
->string
;
5326 s
= SDATA (string
) + pos_byte
;
5327 it
->c
= STRING_CHAR (s
);
5331 pos
= IT_CHARPOS (*it
);
5332 pos_byte
= IT_BYTEPOS (*it
);
5334 it
->c
= FETCH_CHAR (pos_byte
);
5337 /* If there's a valid composition and point is not inside of the
5338 composition (in the case that the composition is from the current
5339 buffer), draw a glyph composed from the composition components. */
5340 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5341 && composition_valid_p (start
, end
, prop
)
5342 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5345 /* As we can't handle this situation (perhaps font-lock added
5346 a new composition), we just return here hoping that next
5347 redisplay will detect this composition much earlier. */
5348 return HANDLED_NORMALLY
;
5351 if (STRINGP (it
->string
))
5352 pos_byte
= string_char_to_byte (it
->string
, start
);
5354 pos_byte
= CHAR_TO_BYTE (start
);
5356 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5359 if (it
->cmp_it
.id
>= 0)
5362 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5363 it
->cmp_it
.nglyphs
= -1;
5367 return HANDLED_NORMALLY
;
5372 /***********************************************************************
5374 ***********************************************************************/
5376 /* The following structure is used to record overlay strings for
5377 later sorting in load_overlay_strings. */
5379 struct overlay_entry
5381 Lisp_Object overlay
;
5388 /* Set up iterator IT from overlay strings at its current position.
5389 Called from handle_stop. */
5391 static enum prop_handled
5392 handle_overlay_change (struct it
*it
)
5394 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5395 return HANDLED_RECOMPUTE_PROPS
;
5397 return HANDLED_NORMALLY
;
5401 /* Set up the next overlay string for delivery by IT, if there is an
5402 overlay string to deliver. Called by set_iterator_to_next when the
5403 end of the current overlay string is reached. If there are more
5404 overlay strings to display, IT->string and
5405 IT->current.overlay_string_index are set appropriately here.
5406 Otherwise IT->string is set to nil. */
5409 next_overlay_string (struct it
*it
)
5411 ++it
->current
.overlay_string_index
;
5412 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5414 /* No more overlay strings. Restore IT's settings to what
5415 they were before overlay strings were processed, and
5416 continue to deliver from current_buffer. */
5418 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5421 || (NILP (it
->string
)
5422 && it
->method
== GET_FROM_BUFFER
5423 && it
->stop_charpos
>= BEGV
5424 && it
->stop_charpos
<= it
->end_charpos
));
5425 it
->current
.overlay_string_index
= -1;
5426 it
->n_overlay_strings
= 0;
5427 it
->overlay_strings_charpos
= -1;
5428 /* If there's an empty display string on the stack, pop the
5429 stack, to resync the bidi iterator with IT's position. Such
5430 empty strings are pushed onto the stack in
5431 get_overlay_strings_1. */
5432 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5435 /* If we're at the end of the buffer, record that we have
5436 processed the overlay strings there already, so that
5437 next_element_from_buffer doesn't try it again. */
5438 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5439 it
->overlay_strings_at_end_processed_p
= 1;
5443 /* There are more overlay strings to process. If
5444 IT->current.overlay_string_index has advanced to a position
5445 where we must load IT->overlay_strings with more strings, do
5446 it. We must load at the IT->overlay_strings_charpos where
5447 IT->n_overlay_strings was originally computed; when invisible
5448 text is present, this might not be IT_CHARPOS (Bug#7016). */
5449 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5451 if (it
->current
.overlay_string_index
&& i
== 0)
5452 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5454 /* Initialize IT to deliver display elements from the overlay
5456 it
->string
= it
->overlay_strings
[i
];
5457 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5458 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5459 it
->method
= GET_FROM_STRING
;
5460 it
->stop_charpos
= 0;
5461 it
->end_charpos
= SCHARS (it
->string
);
5462 if (it
->cmp_it
.stop_pos
>= 0)
5463 it
->cmp_it
.stop_pos
= 0;
5465 it
->base_level_stop
= 0;
5467 /* Set up the bidi iterator for this overlay string. */
5470 it
->bidi_it
.string
.lstring
= it
->string
;
5471 it
->bidi_it
.string
.s
= NULL
;
5472 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5473 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5474 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5475 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5476 it
->bidi_it
.w
= it
->w
;
5477 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5485 /* Compare two overlay_entry structures E1 and E2. Used as a
5486 comparison function for qsort in load_overlay_strings. Overlay
5487 strings for the same position are sorted so that
5489 1. All after-strings come in front of before-strings, except
5490 when they come from the same overlay.
5492 2. Within after-strings, strings are sorted so that overlay strings
5493 from overlays with higher priorities come first.
5495 2. Within before-strings, strings are sorted so that overlay
5496 strings from overlays with higher priorities come last.
5498 Value is analogous to strcmp. */
5502 compare_overlay_entries (const void *e1
, const void *e2
)
5504 struct overlay_entry
const *entry1
= e1
;
5505 struct overlay_entry
const *entry2
= e2
;
5508 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5510 /* Let after-strings appear in front of before-strings if
5511 they come from different overlays. */
5512 if (EQ (entry1
->overlay
, entry2
->overlay
))
5513 result
= entry1
->after_string_p
? 1 : -1;
5515 result
= entry1
->after_string_p
? -1 : 1;
5517 else if (entry1
->priority
!= entry2
->priority
)
5519 if (entry1
->after_string_p
)
5520 /* After-strings sorted in order of decreasing priority. */
5521 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5523 /* Before-strings sorted in order of increasing priority. */
5524 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5533 /* Load the vector IT->overlay_strings with overlay strings from IT's
5534 current buffer position, or from CHARPOS if that is > 0. Set
5535 IT->n_overlays to the total number of overlay strings found.
5537 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5538 a time. On entry into load_overlay_strings,
5539 IT->current.overlay_string_index gives the number of overlay
5540 strings that have already been loaded by previous calls to this
5543 IT->add_overlay_start contains an additional overlay start
5544 position to consider for taking overlay strings from, if non-zero.
5545 This position comes into play when the overlay has an `invisible'
5546 property, and both before and after-strings. When we've skipped to
5547 the end of the overlay, because of its `invisible' property, we
5548 nevertheless want its before-string to appear.
5549 IT->add_overlay_start will contain the overlay start position
5552 Overlay strings are sorted so that after-string strings come in
5553 front of before-string strings. Within before and after-strings,
5554 strings are sorted by overlay priority. See also function
5555 compare_overlay_entries. */
5558 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5560 Lisp_Object overlay
, window
, str
, invisible
;
5561 struct Lisp_Overlay
*ov
;
5562 ptrdiff_t start
, end
;
5563 ptrdiff_t size
= 20;
5564 ptrdiff_t n
= 0, i
, j
;
5566 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5570 charpos
= IT_CHARPOS (*it
);
5572 /* Append the overlay string STRING of overlay OVERLAY to vector
5573 `entries' which has size `size' and currently contains `n'
5574 elements. AFTER_P non-zero means STRING is an after-string of
5576 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5579 Lisp_Object priority; \
5583 struct overlay_entry *old = entries; \
5584 SAFE_NALLOCA (entries, 2, size); \
5585 memcpy (entries, old, size * sizeof *entries); \
5589 entries[n].string = (STRING); \
5590 entries[n].overlay = (OVERLAY); \
5591 priority = Foverlay_get ((OVERLAY), Qpriority); \
5592 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5593 entries[n].after_string_p = (AFTER_P); \
5598 /* Process overlay before the overlay center. */
5599 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5601 XSETMISC (overlay
, ov
);
5602 eassert (OVERLAYP (overlay
));
5603 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5604 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5609 /* Skip this overlay if it doesn't start or end at IT's current
5611 if (end
!= charpos
&& start
!= charpos
)
5614 /* Skip this overlay if it doesn't apply to IT->w. */
5615 window
= Foverlay_get (overlay
, Qwindow
);
5616 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5619 /* If the text ``under'' the overlay is invisible, both before-
5620 and after-strings from this overlay are visible; start and
5621 end position are indistinguishable. */
5622 invisible
= Foverlay_get (overlay
, Qinvisible
);
5623 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5625 /* If overlay has a non-empty before-string, record it. */
5626 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5627 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5629 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5631 /* If overlay has a non-empty after-string, record it. */
5632 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5633 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5635 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5638 /* Process overlays after the overlay center. */
5639 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5641 XSETMISC (overlay
, ov
);
5642 eassert (OVERLAYP (overlay
));
5643 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5644 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5646 if (start
> charpos
)
5649 /* Skip this overlay if it doesn't start or end at IT's current
5651 if (end
!= charpos
&& start
!= charpos
)
5654 /* Skip this overlay if it doesn't apply to IT->w. */
5655 window
= Foverlay_get (overlay
, Qwindow
);
5656 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5659 /* If the text ``under'' the overlay is invisible, it has a zero
5660 dimension, and both before- and after-strings apply. */
5661 invisible
= Foverlay_get (overlay
, Qinvisible
);
5662 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5664 /* If overlay has a non-empty before-string, record it. */
5665 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5666 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5668 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5670 /* If overlay has a non-empty after-string, record it. */
5671 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5672 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5674 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5677 #undef RECORD_OVERLAY_STRING
5681 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5683 /* Record number of overlay strings, and where we computed it. */
5684 it
->n_overlay_strings
= n
;
5685 it
->overlay_strings_charpos
= charpos
;
5687 /* IT->current.overlay_string_index is the number of overlay strings
5688 that have already been consumed by IT. Copy some of the
5689 remaining overlay strings to IT->overlay_strings. */
5691 j
= it
->current
.overlay_string_index
;
5692 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5694 it
->overlay_strings
[i
] = entries
[j
].string
;
5695 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5703 /* Get the first chunk of overlay strings at IT's current buffer
5704 position, or at CHARPOS if that is > 0. Value is non-zero if at
5705 least one overlay string was found. */
5708 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5710 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5711 process. This fills IT->overlay_strings with strings, and sets
5712 IT->n_overlay_strings to the total number of strings to process.
5713 IT->pos.overlay_string_index has to be set temporarily to zero
5714 because load_overlay_strings needs this; it must be set to -1
5715 when no overlay strings are found because a zero value would
5716 indicate a position in the first overlay string. */
5717 it
->current
.overlay_string_index
= 0;
5718 load_overlay_strings (it
, charpos
);
5720 /* If we found overlay strings, set up IT to deliver display
5721 elements from the first one. Otherwise set up IT to deliver
5722 from current_buffer. */
5723 if (it
->n_overlay_strings
)
5725 /* Make sure we know settings in current_buffer, so that we can
5726 restore meaningful values when we're done with the overlay
5729 compute_stop_pos (it
);
5730 eassert (it
->face_id
>= 0);
5732 /* Save IT's settings. They are restored after all overlay
5733 strings have been processed. */
5734 eassert (!compute_stop_p
|| it
->sp
== 0);
5736 /* When called from handle_stop, there might be an empty display
5737 string loaded. In that case, don't bother saving it. But
5738 don't use this optimization with the bidi iterator, since we
5739 need the corresponding pop_it call to resync the bidi
5740 iterator's position with IT's position, after we are done
5741 with the overlay strings. (The corresponding call to pop_it
5742 in case of an empty display string is in
5743 next_overlay_string.) */
5745 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5748 /* Set up IT to deliver display elements from the first overlay
5750 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5751 it
->string
= it
->overlay_strings
[0];
5752 it
->from_overlay
= Qnil
;
5753 it
->stop_charpos
= 0;
5754 eassert (STRINGP (it
->string
));
5755 it
->end_charpos
= SCHARS (it
->string
);
5757 it
->base_level_stop
= 0;
5758 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5759 it
->method
= GET_FROM_STRING
;
5760 it
->from_disp_prop_p
= 0;
5762 /* Force paragraph direction to be that of the parent
5764 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5765 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5767 it
->paragraph_embedding
= L2R
;
5769 /* Set up the bidi iterator for this overlay string. */
5772 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5774 it
->bidi_it
.string
.lstring
= it
->string
;
5775 it
->bidi_it
.string
.s
= NULL
;
5776 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5777 it
->bidi_it
.string
.bufpos
= pos
;
5778 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5779 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5780 it
->bidi_it
.w
= it
->w
;
5781 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5786 it
->current
.overlay_string_index
= -1;
5791 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5794 it
->method
= GET_FROM_BUFFER
;
5796 (void) get_overlay_strings_1 (it
, charpos
, 1);
5800 /* Value is non-zero if we found at least one overlay string. */
5801 return STRINGP (it
->string
);
5806 /***********************************************************************
5807 Saving and restoring state
5808 ***********************************************************************/
5810 /* Save current settings of IT on IT->stack. Called, for example,
5811 before setting up IT for an overlay string, to be able to restore
5812 IT's settings to what they were after the overlay string has been
5813 processed. If POSITION is non-NULL, it is the position to save on
5814 the stack instead of IT->position. */
5817 push_it (struct it
*it
, struct text_pos
*position
)
5819 struct iterator_stack_entry
*p
;
5821 eassert (it
->sp
< IT_STACK_SIZE
);
5822 p
= it
->stack
+ it
->sp
;
5824 p
->stop_charpos
= it
->stop_charpos
;
5825 p
->prev_stop
= it
->prev_stop
;
5826 p
->base_level_stop
= it
->base_level_stop
;
5827 p
->cmp_it
= it
->cmp_it
;
5828 eassert (it
->face_id
>= 0);
5829 p
->face_id
= it
->face_id
;
5830 p
->string
= it
->string
;
5831 p
->method
= it
->method
;
5832 p
->from_overlay
= it
->from_overlay
;
5835 case GET_FROM_IMAGE
:
5836 p
->u
.image
.object
= it
->object
;
5837 p
->u
.image
.image_id
= it
->image_id
;
5838 p
->u
.image
.slice
= it
->slice
;
5840 case GET_FROM_STRETCH
:
5841 p
->u
.stretch
.object
= it
->object
;
5844 p
->position
= position
? *position
: it
->position
;
5845 p
->current
= it
->current
;
5846 p
->end_charpos
= it
->end_charpos
;
5847 p
->string_nchars
= it
->string_nchars
;
5849 p
->multibyte_p
= it
->multibyte_p
;
5850 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5851 p
->space_width
= it
->space_width
;
5852 p
->font_height
= it
->font_height
;
5853 p
->voffset
= it
->voffset
;
5854 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5855 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5856 p
->display_ellipsis_p
= 0;
5857 p
->line_wrap
= it
->line_wrap
;
5858 p
->bidi_p
= it
->bidi_p
;
5859 p
->paragraph_embedding
= it
->paragraph_embedding
;
5860 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5863 /* Save the state of the bidi iterator as well. */
5865 bidi_push_it (&it
->bidi_it
);
5869 iterate_out_of_display_property (struct it
*it
)
5871 int buffer_p
= !STRINGP (it
->string
);
5872 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5873 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5875 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5877 /* Maybe initialize paragraph direction. If we are at the beginning
5878 of a new paragraph, next_element_from_buffer may not have a
5879 chance to do that. */
5880 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5881 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5882 /* prev_stop can be zero, so check against BEGV as well. */
5883 while (it
->bidi_it
.charpos
>= bob
5884 && it
->prev_stop
<= it
->bidi_it
.charpos
5885 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5886 && it
->bidi_it
.charpos
< eob
)
5887 bidi_move_to_visually_next (&it
->bidi_it
);
5888 /* Record the stop_pos we just crossed, for when we cross it
5890 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5891 it
->prev_stop
= CHARPOS (it
->position
);
5892 /* If we ended up not where pop_it put us, resync IT's
5893 positional members with the bidi iterator. */
5894 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5895 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5897 it
->current
.pos
= it
->position
;
5899 it
->current
.string_pos
= it
->position
;
5902 /* Restore IT's settings from IT->stack. Called, for example, when no
5903 more overlay strings must be processed, and we return to delivering
5904 display elements from a buffer, or when the end of a string from a
5905 `display' property is reached and we return to delivering display
5906 elements from an overlay string, or from a buffer. */
5909 pop_it (struct it
*it
)
5911 struct iterator_stack_entry
*p
;
5912 int from_display_prop
= it
->from_disp_prop_p
;
5914 eassert (it
->sp
> 0);
5916 p
= it
->stack
+ it
->sp
;
5917 it
->stop_charpos
= p
->stop_charpos
;
5918 it
->prev_stop
= p
->prev_stop
;
5919 it
->base_level_stop
= p
->base_level_stop
;
5920 it
->cmp_it
= p
->cmp_it
;
5921 it
->face_id
= p
->face_id
;
5922 it
->current
= p
->current
;
5923 it
->position
= p
->position
;
5924 it
->string
= p
->string
;
5925 it
->from_overlay
= p
->from_overlay
;
5926 if (NILP (it
->string
))
5927 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5928 it
->method
= p
->method
;
5931 case GET_FROM_IMAGE
:
5932 it
->image_id
= p
->u
.image
.image_id
;
5933 it
->object
= p
->u
.image
.object
;
5934 it
->slice
= p
->u
.image
.slice
;
5936 case GET_FROM_STRETCH
:
5937 it
->object
= p
->u
.stretch
.object
;
5939 case GET_FROM_BUFFER
:
5940 it
->object
= it
->w
->contents
;
5942 case GET_FROM_STRING
:
5943 it
->object
= it
->string
;
5945 case GET_FROM_DISPLAY_VECTOR
:
5947 it
->method
= GET_FROM_C_STRING
;
5948 else if (STRINGP (it
->string
))
5949 it
->method
= GET_FROM_STRING
;
5952 it
->method
= GET_FROM_BUFFER
;
5953 it
->object
= it
->w
->contents
;
5956 it
->end_charpos
= p
->end_charpos
;
5957 it
->string_nchars
= p
->string_nchars
;
5959 it
->multibyte_p
= p
->multibyte_p
;
5960 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5961 it
->space_width
= p
->space_width
;
5962 it
->font_height
= p
->font_height
;
5963 it
->voffset
= p
->voffset
;
5964 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5965 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5966 it
->line_wrap
= p
->line_wrap
;
5967 it
->bidi_p
= p
->bidi_p
;
5968 it
->paragraph_embedding
= p
->paragraph_embedding
;
5969 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5972 bidi_pop_it (&it
->bidi_it
);
5973 /* Bidi-iterate until we get out of the portion of text, if any,
5974 covered by a `display' text property or by an overlay with
5975 `display' property. (We cannot just jump there, because the
5976 internal coherency of the bidi iterator state can not be
5977 preserved across such jumps.) We also must determine the
5978 paragraph base direction if the overlay we just processed is
5979 at the beginning of a new paragraph. */
5980 if (from_display_prop
5981 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5982 iterate_out_of_display_property (it
);
5984 eassert ((BUFFERP (it
->object
)
5985 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5986 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5987 || (STRINGP (it
->object
)
5988 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5989 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5990 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
5996 /***********************************************************************
5998 ***********************************************************************/
6000 /* Set IT's current position to the previous line start. */
6003 back_to_previous_line_start (struct it
*it
)
6005 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6008 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6012 /* Move IT to the next line start.
6014 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6015 we skipped over part of the text (as opposed to moving the iterator
6016 continuously over the text). Otherwise, don't change the value
6019 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6020 iterator on the newline, if it was found.
6022 Newlines may come from buffer text, overlay strings, or strings
6023 displayed via the `display' property. That's the reason we can't
6024 simply use find_newline_no_quit.
6026 Note that this function may not skip over invisible text that is so
6027 because of text properties and immediately follows a newline. If
6028 it would, function reseat_at_next_visible_line_start, when called
6029 from set_iterator_to_next, would effectively make invisible
6030 characters following a newline part of the wrong glyph row, which
6031 leads to wrong cursor motion. */
6034 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6035 struct bidi_it
*bidi_it_prev
)
6037 ptrdiff_t old_selective
;
6038 int newline_found_p
, n
;
6039 const int MAX_NEWLINE_DISTANCE
= 500;
6041 /* If already on a newline, just consume it to avoid unintended
6042 skipping over invisible text below. */
6043 if (it
->what
== IT_CHARACTER
6045 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6047 if (it
->bidi_p
&& bidi_it_prev
)
6048 *bidi_it_prev
= it
->bidi_it
;
6049 set_iterator_to_next (it
, 0);
6054 /* Don't handle selective display in the following. It's (a)
6055 unnecessary because it's done by the caller, and (b) leads to an
6056 infinite recursion because next_element_from_ellipsis indirectly
6057 calls this function. */
6058 old_selective
= it
->selective
;
6061 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6062 from buffer text. */
6063 for (n
= newline_found_p
= 0;
6064 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6065 n
+= STRINGP (it
->string
) ? 0 : 1)
6067 if (!get_next_display_element (it
))
6069 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6070 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6071 *bidi_it_prev
= it
->bidi_it
;
6072 set_iterator_to_next (it
, 0);
6075 /* If we didn't find a newline near enough, see if we can use a
6077 if (!newline_found_p
)
6079 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6080 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6084 eassert (!STRINGP (it
->string
));
6086 /* If there isn't any `display' property in sight, and no
6087 overlays, we can just use the position of the newline in
6089 if (it
->stop_charpos
>= limit
6090 || ((pos
= Fnext_single_property_change (make_number (start
),
6092 make_number (limit
)),
6094 && next_overlay_change (start
) == ZV
))
6098 IT_CHARPOS (*it
) = limit
;
6099 IT_BYTEPOS (*it
) = bytepos
;
6103 struct bidi_it bprev
;
6105 /* Help bidi.c avoid expensive searches for display
6106 properties and overlays, by telling it that there are
6107 none up to `limit'. */
6108 if (it
->bidi_it
.disp_pos
< limit
)
6110 it
->bidi_it
.disp_pos
= limit
;
6111 it
->bidi_it
.disp_prop
= 0;
6114 bprev
= it
->bidi_it
;
6115 bidi_move_to_visually_next (&it
->bidi_it
);
6116 } while (it
->bidi_it
.charpos
!= limit
);
6117 IT_CHARPOS (*it
) = limit
;
6118 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6120 *bidi_it_prev
= bprev
;
6122 *skipped_p
= newline_found_p
= 1;
6126 while (get_next_display_element (it
)
6127 && !newline_found_p
)
6129 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6130 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6131 *bidi_it_prev
= it
->bidi_it
;
6132 set_iterator_to_next (it
, 0);
6137 it
->selective
= old_selective
;
6138 return newline_found_p
;
6142 /* Set IT's current position to the previous visible line start. Skip
6143 invisible text that is so either due to text properties or due to
6144 selective display. Caution: this does not change IT->current_x and
6148 back_to_previous_visible_line_start (struct it
*it
)
6150 while (IT_CHARPOS (*it
) > BEGV
)
6152 back_to_previous_line_start (it
);
6154 if (IT_CHARPOS (*it
) <= BEGV
)
6157 /* If selective > 0, then lines indented more than its value are
6159 if (it
->selective
> 0
6160 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6164 /* Check the newline before point for invisibility. */
6167 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6168 Qinvisible
, it
->window
);
6169 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6173 if (IT_CHARPOS (*it
) <= BEGV
)
6178 void *it2data
= NULL
;
6181 Lisp_Object val
, overlay
;
6183 SAVE_IT (it2
, *it
, it2data
);
6185 /* If newline is part of a composition, continue from start of composition */
6186 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6187 && beg
< IT_CHARPOS (*it
))
6190 /* If newline is replaced by a display property, find start of overlay
6191 or interval and continue search from that point. */
6192 pos
= --IT_CHARPOS (it2
);
6195 bidi_unshelve_cache (NULL
, 0);
6196 it2
.string_from_display_prop_p
= 0;
6197 it2
.from_disp_prop_p
= 0;
6198 if (handle_display_prop (&it2
) == HANDLED_RETURN
6199 && !NILP (val
= get_char_property_and_overlay
6200 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6201 && (OVERLAYP (overlay
)
6202 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6203 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6205 RESTORE_IT (it
, it
, it2data
);
6209 /* Newline is not replaced by anything -- so we are done. */
6210 RESTORE_IT (it
, it
, it2data
);
6216 IT_CHARPOS (*it
) = beg
;
6217 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6221 it
->continuation_lines_width
= 0;
6223 eassert (IT_CHARPOS (*it
) >= BEGV
);
6224 eassert (IT_CHARPOS (*it
) == BEGV
6225 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6230 /* Reseat iterator IT at the previous visible line start. Skip
6231 invisible text that is so either due to text properties or due to
6232 selective display. At the end, update IT's overlay information,
6233 face information etc. */
6236 reseat_at_previous_visible_line_start (struct it
*it
)
6238 back_to_previous_visible_line_start (it
);
6239 reseat (it
, it
->current
.pos
, 1);
6244 /* Reseat iterator IT on the next visible line start in the current
6245 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6246 preceding the line start. Skip over invisible text that is so
6247 because of selective display. Compute faces, overlays etc at the
6248 new position. Note that this function does not skip over text that
6249 is invisible because of text properties. */
6252 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6254 int newline_found_p
, skipped_p
= 0;
6255 struct bidi_it bidi_it_prev
;
6257 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6259 /* Skip over lines that are invisible because they are indented
6260 more than the value of IT->selective. */
6261 if (it
->selective
> 0)
6262 while (IT_CHARPOS (*it
) < ZV
6263 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6266 eassert (IT_BYTEPOS (*it
) == BEGV
6267 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6269 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6272 /* Position on the newline if that's what's requested. */
6273 if (on_newline_p
&& newline_found_p
)
6275 if (STRINGP (it
->string
))
6277 if (IT_STRING_CHARPOS (*it
) > 0)
6281 --IT_STRING_CHARPOS (*it
);
6282 --IT_STRING_BYTEPOS (*it
);
6286 /* We need to restore the bidi iterator to the state
6287 it had on the newline, and resync the IT's
6288 position with that. */
6289 it
->bidi_it
= bidi_it_prev
;
6290 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6291 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6295 else if (IT_CHARPOS (*it
) > BEGV
)
6304 /* We need to restore the bidi iterator to the state it
6305 had on the newline and resync IT with that. */
6306 it
->bidi_it
= bidi_it_prev
;
6307 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6308 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6310 reseat (it
, it
->current
.pos
, 0);
6314 reseat (it
, it
->current
.pos
, 0);
6321 /***********************************************************************
6322 Changing an iterator's position
6323 ***********************************************************************/
6325 /* Change IT's current position to POS in current_buffer. If FORCE_P
6326 is non-zero, always check for text properties at the new position.
6327 Otherwise, text properties are only looked up if POS >=
6328 IT->check_charpos of a property. */
6331 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6333 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6335 reseat_1 (it
, pos
, 0);
6337 /* Determine where to check text properties. Avoid doing it
6338 where possible because text property lookup is very expensive. */
6340 || CHARPOS (pos
) > it
->stop_charpos
6341 || CHARPOS (pos
) < original_pos
)
6345 /* For bidi iteration, we need to prime prev_stop and
6346 base_level_stop with our best estimations. */
6347 /* Implementation note: Of course, POS is not necessarily a
6348 stop position, so assigning prev_pos to it is a lie; we
6349 should have called compute_stop_backwards. However, if
6350 the current buffer does not include any R2L characters,
6351 that call would be a waste of cycles, because the
6352 iterator will never move back, and thus never cross this
6353 "fake" stop position. So we delay that backward search
6354 until the time we really need it, in next_element_from_buffer. */
6355 if (CHARPOS (pos
) != it
->prev_stop
)
6356 it
->prev_stop
= CHARPOS (pos
);
6357 if (CHARPOS (pos
) < it
->base_level_stop
)
6358 it
->base_level_stop
= 0; /* meaning it's unknown */
6364 it
->prev_stop
= it
->base_level_stop
= 0;
6373 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6374 IT->stop_pos to POS, also. */
6377 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6379 /* Don't call this function when scanning a C string. */
6380 eassert (it
->s
== NULL
);
6382 /* POS must be a reasonable value. */
6383 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6385 it
->current
.pos
= it
->position
= pos
;
6386 it
->end_charpos
= ZV
;
6388 it
->current
.dpvec_index
= -1;
6389 it
->current
.overlay_string_index
= -1;
6390 IT_STRING_CHARPOS (*it
) = -1;
6391 IT_STRING_BYTEPOS (*it
) = -1;
6393 it
->method
= GET_FROM_BUFFER
;
6394 it
->object
= it
->w
->contents
;
6395 it
->area
= TEXT_AREA
;
6396 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6398 it
->string_from_display_prop_p
= 0;
6399 it
->string_from_prefix_prop_p
= 0;
6401 it
->from_disp_prop_p
= 0;
6402 it
->face_before_selective_p
= 0;
6405 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6407 bidi_unshelve_cache (NULL
, 0);
6408 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6409 it
->bidi_it
.string
.s
= NULL
;
6410 it
->bidi_it
.string
.lstring
= Qnil
;
6411 it
->bidi_it
.string
.bufpos
= 0;
6412 it
->bidi_it
.string
.unibyte
= 0;
6413 it
->bidi_it
.w
= it
->w
;
6418 it
->stop_charpos
= CHARPOS (pos
);
6419 it
->base_level_stop
= CHARPOS (pos
);
6421 /* This make the information stored in it->cmp_it invalidate. */
6426 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6427 If S is non-null, it is a C string to iterate over. Otherwise,
6428 STRING gives a Lisp string to iterate over.
6430 If PRECISION > 0, don't return more then PRECISION number of
6431 characters from the string.
6433 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6434 characters have been returned. FIELD_WIDTH < 0 means an infinite
6437 MULTIBYTE = 0 means disable processing of multibyte characters,
6438 MULTIBYTE > 0 means enable it,
6439 MULTIBYTE < 0 means use IT->multibyte_p.
6441 IT must be initialized via a prior call to init_iterator before
6442 calling this function. */
6445 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6446 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6449 /* No region in strings. */
6450 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6452 /* No text property checks performed by default, but see below. */
6453 it
->stop_charpos
= -1;
6455 /* Set iterator position and end position. */
6456 memset (&it
->current
, 0, sizeof it
->current
);
6457 it
->current
.overlay_string_index
= -1;
6458 it
->current
.dpvec_index
= -1;
6459 eassert (charpos
>= 0);
6461 /* If STRING is specified, use its multibyteness, otherwise use the
6462 setting of MULTIBYTE, if specified. */
6464 it
->multibyte_p
= multibyte
> 0;
6466 /* Bidirectional reordering of strings is controlled by the default
6467 value of bidi-display-reordering. Don't try to reorder while
6468 loading loadup.el, as the necessary character property tables are
6469 not yet available. */
6472 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6476 eassert (STRINGP (string
));
6477 it
->string
= string
;
6479 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6480 it
->method
= GET_FROM_STRING
;
6481 it
->current
.string_pos
= string_pos (charpos
, string
);
6485 it
->bidi_it
.string
.lstring
= string
;
6486 it
->bidi_it
.string
.s
= NULL
;
6487 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6488 it
->bidi_it
.string
.bufpos
= 0;
6489 it
->bidi_it
.string
.from_disp_str
= 0;
6490 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6491 it
->bidi_it
.w
= it
->w
;
6492 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6493 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6498 it
->s
= (const unsigned char *) s
;
6501 /* Note that we use IT->current.pos, not it->current.string_pos,
6502 for displaying C strings. */
6503 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6504 if (it
->multibyte_p
)
6506 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6507 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6511 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6512 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6517 it
->bidi_it
.string
.lstring
= Qnil
;
6518 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6519 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6520 it
->bidi_it
.string
.bufpos
= 0;
6521 it
->bidi_it
.string
.from_disp_str
= 0;
6522 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6523 it
->bidi_it
.w
= it
->w
;
6524 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6527 it
->method
= GET_FROM_C_STRING
;
6530 /* PRECISION > 0 means don't return more than PRECISION characters
6532 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6534 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6536 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6539 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6540 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6541 FIELD_WIDTH < 0 means infinite field width. This is useful for
6542 padding with `-' at the end of a mode line. */
6543 if (field_width
< 0)
6544 field_width
= INFINITY
;
6545 /* Implementation note: We deliberately don't enlarge
6546 it->bidi_it.string.schars here to fit it->end_charpos, because
6547 the bidi iterator cannot produce characters out of thin air. */
6548 if (field_width
> it
->end_charpos
- charpos
)
6549 it
->end_charpos
= charpos
+ field_width
;
6551 /* Use the standard display table for displaying strings. */
6552 if (DISP_TABLE_P (Vstandard_display_table
))
6553 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6555 it
->stop_charpos
= charpos
;
6556 it
->prev_stop
= charpos
;
6557 it
->base_level_stop
= 0;
6560 it
->bidi_it
.first_elt
= 1;
6561 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6562 it
->bidi_it
.disp_pos
= -1;
6564 if (s
== NULL
&& it
->multibyte_p
)
6566 ptrdiff_t endpos
= SCHARS (it
->string
);
6567 if (endpos
> it
->end_charpos
)
6568 endpos
= it
->end_charpos
;
6569 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6577 /***********************************************************************
6579 ***********************************************************************/
6581 /* Map enum it_method value to corresponding next_element_from_* function. */
6583 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6585 next_element_from_buffer
,
6586 next_element_from_display_vector
,
6587 next_element_from_string
,
6588 next_element_from_c_string
,
6589 next_element_from_image
,
6590 next_element_from_stretch
6593 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6596 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6597 (possibly with the following characters). */
6599 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6600 ((IT)->cmp_it.id >= 0 \
6601 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6602 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6603 END_CHARPOS, (IT)->w, \
6604 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6608 /* Lookup the char-table Vglyphless_char_display for character C (-1
6609 if we want information for no-font case), and return the display
6610 method symbol. By side-effect, update it->what and
6611 it->glyphless_method. This function is called from
6612 get_next_display_element for each character element, and from
6613 x_produce_glyphs when no suitable font was found. */
6616 lookup_glyphless_char_display (int c
, struct it
*it
)
6618 Lisp_Object glyphless_method
= Qnil
;
6620 if (CHAR_TABLE_P (Vglyphless_char_display
)
6621 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6625 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6626 if (CONSP (glyphless_method
))
6627 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6628 ? XCAR (glyphless_method
)
6629 : XCDR (glyphless_method
);
6632 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6636 if (NILP (glyphless_method
))
6639 /* The default is to display the character by a proper font. */
6641 /* The default for the no-font case is to display an empty box. */
6642 glyphless_method
= Qempty_box
;
6644 if (EQ (glyphless_method
, Qzero_width
))
6647 return glyphless_method
;
6648 /* This method can't be used for the no-font case. */
6649 glyphless_method
= Qempty_box
;
6651 if (EQ (glyphless_method
, Qthin_space
))
6652 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6653 else if (EQ (glyphless_method
, Qempty_box
))
6654 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6655 else if (EQ (glyphless_method
, Qhex_code
))
6656 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6657 else if (STRINGP (glyphless_method
))
6658 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6661 /* Invalid value. We use the default method. */
6662 glyphless_method
= Qnil
;
6665 it
->what
= IT_GLYPHLESS
;
6666 return glyphless_method
;
6669 /* Merge escape glyph face and cache the result. */
6671 static struct frame
*last_escape_glyph_frame
= NULL
;
6672 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6673 static int last_escape_glyph_merged_face_id
= 0;
6676 merge_escape_glyph_face (struct it
*it
)
6680 if (it
->f
== last_escape_glyph_frame
6681 && it
->face_id
== last_escape_glyph_face_id
)
6682 face_id
= last_escape_glyph_merged_face_id
;
6685 /* Merge the `escape-glyph' face into the current face. */
6686 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0, it
->face_id
);
6687 last_escape_glyph_frame
= it
->f
;
6688 last_escape_glyph_face_id
= it
->face_id
;
6689 last_escape_glyph_merged_face_id
= face_id
;
6694 /* Likewise for glyphless glyph face. */
6696 static struct frame
*last_glyphless_glyph_frame
= NULL
;
6697 static int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6698 static int last_glyphless_glyph_merged_face_id
= 0;
6701 merge_glyphless_glyph_face (struct it
*it
)
6705 if (it
->f
== last_glyphless_glyph_frame
6706 && it
->face_id
== last_glyphless_glyph_face_id
)
6707 face_id
= last_glyphless_glyph_merged_face_id
;
6710 /* Merge the `glyphless-char' face into the current face. */
6711 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
6712 last_glyphless_glyph_frame
= it
->f
;
6713 last_glyphless_glyph_face_id
= it
->face_id
;
6714 last_glyphless_glyph_merged_face_id
= face_id
;
6719 /* Load IT's display element fields with information about the next
6720 display element from the current position of IT. Value is zero if
6721 end of buffer (or C string) is reached. */
6724 get_next_display_element (struct it
*it
)
6726 /* Non-zero means that we found a display element. Zero means that
6727 we hit the end of what we iterate over. Performance note: the
6728 function pointer `method' used here turns out to be faster than
6729 using a sequence of if-statements. */
6733 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6735 if (it
->what
== IT_CHARACTER
)
6737 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6738 and only if (a) the resolved directionality of that character
6740 /* FIXME: Do we need an exception for characters from display
6742 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6743 it
->c
= bidi_mirror_char (it
->c
);
6744 /* Map via display table or translate control characters.
6745 IT->c, IT->len etc. have been set to the next character by
6746 the function call above. If we have a display table, and it
6747 contains an entry for IT->c, translate it. Don't do this if
6748 IT->c itself comes from a display table, otherwise we could
6749 end up in an infinite recursion. (An alternative could be to
6750 count the recursion depth of this function and signal an
6751 error when a certain maximum depth is reached.) Is it worth
6753 if (success_p
&& it
->dpvec
== NULL
)
6756 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6757 int nonascii_space_p
= 0;
6758 int nonascii_hyphen_p
= 0;
6759 int c
= it
->c
; /* This is the character to display. */
6761 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6763 eassert (SINGLE_BYTE_CHAR_P (c
));
6764 if (unibyte_display_via_language_environment
)
6766 c
= DECODE_CHAR (unibyte
, c
);
6768 c
= BYTE8_TO_CHAR (it
->c
);
6771 c
= BYTE8_TO_CHAR (it
->c
);
6775 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6778 struct Lisp_Vector
*v
= XVECTOR (dv
);
6780 /* Return the first character from the display table
6781 entry, if not empty. If empty, don't display the
6782 current character. */
6785 it
->dpvec_char_len
= it
->len
;
6786 it
->dpvec
= v
->contents
;
6787 it
->dpend
= v
->contents
+ v
->header
.size
;
6788 it
->current
.dpvec_index
= 0;
6789 it
->dpvec_face_id
= -1;
6790 it
->saved_face_id
= it
->face_id
;
6791 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6796 set_iterator_to_next (it
, 0);
6801 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6803 if (it
->what
== IT_GLYPHLESS
)
6805 /* Don't display this character. */
6806 set_iterator_to_next (it
, 0);
6810 /* If `nobreak-char-display' is non-nil, we display
6811 non-ASCII spaces and hyphens specially. */
6812 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6815 nonascii_space_p
= 1;
6816 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6817 nonascii_hyphen_p
= 1;
6820 /* Translate control characters into `\003' or `^C' form.
6821 Control characters coming from a display table entry are
6822 currently not translated because we use IT->dpvec to hold
6823 the translation. This could easily be changed but I
6824 don't believe that it is worth doing.
6826 The characters handled by `nobreak-char-display' must be
6829 Non-printable characters and raw-byte characters are also
6830 translated to octal form. */
6831 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6832 ? (it
->area
!= TEXT_AREA
6833 /* In mode line, treat \n, \t like other crl chars. */
6836 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6837 || (c
!= '\n' && c
!= '\t'))
6839 || nonascii_hyphen_p
6841 || ! CHAR_PRINTABLE_P (c
))))
6843 /* C is a control character, non-ASCII space/hyphen,
6844 raw-byte, or a non-printable character which must be
6845 displayed either as '\003' or as `^C' where the '\\'
6846 and '^' can be defined in the display table. Fill
6847 IT->ctl_chars with glyphs for what we have to
6848 display. Then, set IT->dpvec to these glyphs. */
6855 /* Handle control characters with ^. */
6857 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6861 g
= '^'; /* default glyph for Control */
6862 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6864 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6866 g
= GLYPH_CODE_CHAR (gc
);
6867 lface_id
= GLYPH_CODE_FACE (gc
);
6871 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6872 : merge_escape_glyph_face (it
));
6874 XSETINT (it
->ctl_chars
[0], g
);
6875 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6877 goto display_control
;
6880 /* Handle non-ascii space in the mode where it only gets
6883 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6885 /* Merge `nobreak-space' into the current face. */
6886 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6888 XSETINT (it
->ctl_chars
[0], ' ');
6890 goto display_control
;
6893 /* Handle sequences that start with the "escape glyph". */
6895 /* the default escape glyph is \. */
6896 escape_glyph
= '\\';
6899 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6901 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6902 lface_id
= GLYPH_CODE_FACE (gc
);
6906 ? merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
)
6907 : merge_escape_glyph_face (it
));
6909 /* Draw non-ASCII hyphen with just highlighting: */
6911 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6913 XSETINT (it
->ctl_chars
[0], '-');
6915 goto display_control
;
6918 /* Draw non-ASCII space/hyphen with escape glyph: */
6920 if (nonascii_space_p
|| nonascii_hyphen_p
)
6922 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6923 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6925 goto display_control
;
6932 if (CHAR_BYTE8_P (c
))
6933 /* Display \200 instead of \17777600. */
6934 c
= CHAR_TO_BYTE8 (c
);
6935 len
= sprintf (str
, "%03o", c
);
6937 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6938 for (i
= 0; i
< len
; i
++)
6939 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6944 /* Set up IT->dpvec and return first character from it. */
6945 it
->dpvec_char_len
= it
->len
;
6946 it
->dpvec
= it
->ctl_chars
;
6947 it
->dpend
= it
->dpvec
+ ctl_len
;
6948 it
->current
.dpvec_index
= 0;
6949 it
->dpvec_face_id
= face_id
;
6950 it
->saved_face_id
= it
->face_id
;
6951 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6955 it
->char_to_display
= c
;
6959 it
->char_to_display
= it
->c
;
6963 /* Adjust face id for a multibyte character. There are no multibyte
6964 character in unibyte text. */
6965 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6968 && FRAME_WINDOW_P (it
->f
))
6970 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6972 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6974 /* Automatic composition with glyph-string. */
6975 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6977 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6981 ptrdiff_t pos
= (it
->s
? -1
6982 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6983 : IT_CHARPOS (*it
));
6986 if (it
->what
== IT_CHARACTER
)
6987 c
= it
->char_to_display
;
6990 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6994 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6995 /* TAB in a composition means display glyphs with
6996 padding space on the left or right. */
6997 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
7000 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7005 /* Is this character the last one of a run of characters with
7006 box? If yes, set IT->end_of_box_run_p to 1. */
7010 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7012 int face_id
= underlying_face_id (it
);
7013 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7017 if (face
->box
== FACE_NO_BOX
)
7019 /* If the box comes from face properties in a
7020 display string, check faces in that string. */
7021 int string_face_id
= face_after_it_pos (it
);
7022 it
->end_of_box_run_p
7023 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7026 /* Otherwise, the box comes from the underlying face.
7027 If this is the last string character displayed, check
7028 the next buffer location. */
7029 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7030 && (it
->current
.overlay_string_index
7031 == it
->n_overlay_strings
- 1))
7035 struct text_pos pos
= it
->current
.pos
;
7036 INC_TEXT_POS (pos
, it
->multibyte_p
);
7038 next_face_id
= face_at_buffer_position
7039 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
7040 it
->region_end_charpos
, &ignore
,
7041 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7043 it
->end_of_box_run_p
7044 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7049 /* next_element_from_display_vector sets this flag according to
7050 faces of the display vector glyphs, see there. */
7051 else if (it
->method
!= GET_FROM_DISPLAY_VECTOR
)
7053 int face_id
= face_after_it_pos (it
);
7054 it
->end_of_box_run_p
7055 = (face_id
!= it
->face_id
7056 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7059 /* If we reached the end of the object we've been iterating (e.g., a
7060 display string or an overlay string), and there's something on
7061 IT->stack, proceed with what's on the stack. It doesn't make
7062 sense to return zero if there's unprocessed stuff on the stack,
7063 because otherwise that stuff will never be displayed. */
7064 if (!success_p
&& it
->sp
> 0)
7066 set_iterator_to_next (it
, 0);
7067 success_p
= get_next_display_element (it
);
7070 /* Value is 0 if end of buffer or string reached. */
7075 /* Move IT to the next display element.
7077 RESEAT_P non-zero means if called on a newline in buffer text,
7078 skip to the next visible line start.
7080 Functions get_next_display_element and set_iterator_to_next are
7081 separate because I find this arrangement easier to handle than a
7082 get_next_display_element function that also increments IT's
7083 position. The way it is we can first look at an iterator's current
7084 display element, decide whether it fits on a line, and if it does,
7085 increment the iterator position. The other way around we probably
7086 would either need a flag indicating whether the iterator has to be
7087 incremented the next time, or we would have to implement a
7088 decrement position function which would not be easy to write. */
7091 set_iterator_to_next (struct it
*it
, int reseat_p
)
7093 /* Reset flags indicating start and end of a sequence of characters
7094 with box. Reset them at the start of this function because
7095 moving the iterator to a new position might set them. */
7096 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7100 case GET_FROM_BUFFER
:
7101 /* The current display element of IT is a character from
7102 current_buffer. Advance in the buffer, and maybe skip over
7103 invisible lines that are so because of selective display. */
7104 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7105 reseat_at_next_visible_line_start (it
, 0);
7106 else if (it
->cmp_it
.id
>= 0)
7108 /* We are currently getting glyphs from a composition. */
7113 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7114 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7115 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7117 it
->cmp_it
.from
= it
->cmp_it
.to
;
7122 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7124 it
->end_charpos
, Qnil
);
7127 else if (! it
->cmp_it
.reversed_p
)
7129 /* Composition created while scanning forward. */
7130 /* Update IT's char/byte positions to point to the first
7131 character of the next grapheme cluster, or to the
7132 character visually after the current composition. */
7133 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7134 bidi_move_to_visually_next (&it
->bidi_it
);
7135 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7136 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7138 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7140 /* Proceed to the next grapheme cluster. */
7141 it
->cmp_it
.from
= it
->cmp_it
.to
;
7145 /* No more grapheme clusters in this composition.
7146 Find the next stop position. */
7147 ptrdiff_t stop
= it
->end_charpos
;
7148 if (it
->bidi_it
.scan_dir
< 0)
7149 /* Now we are scanning backward and don't know
7152 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7153 IT_BYTEPOS (*it
), stop
, Qnil
);
7158 /* Composition created while scanning backward. */
7159 /* Update IT's char/byte positions to point to the last
7160 character of the previous grapheme cluster, or the
7161 character visually after the current composition. */
7162 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7163 bidi_move_to_visually_next (&it
->bidi_it
);
7164 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7165 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7166 if (it
->cmp_it
.from
> 0)
7168 /* Proceed to the previous grapheme cluster. */
7169 it
->cmp_it
.to
= it
->cmp_it
.from
;
7173 /* No more grapheme clusters in this composition.
7174 Find the next stop position. */
7175 ptrdiff_t stop
= it
->end_charpos
;
7176 if (it
->bidi_it
.scan_dir
< 0)
7177 /* Now we are scanning backward and don't know
7180 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7181 IT_BYTEPOS (*it
), stop
, Qnil
);
7187 eassert (it
->len
!= 0);
7191 IT_BYTEPOS (*it
) += it
->len
;
7192 IT_CHARPOS (*it
) += 1;
7196 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7197 /* If this is a new paragraph, determine its base
7198 direction (a.k.a. its base embedding level). */
7199 if (it
->bidi_it
.new_paragraph
)
7200 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7201 bidi_move_to_visually_next (&it
->bidi_it
);
7202 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7203 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7204 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7206 /* As the scan direction was changed, we must
7207 re-compute the stop position for composition. */
7208 ptrdiff_t stop
= it
->end_charpos
;
7209 if (it
->bidi_it
.scan_dir
< 0)
7211 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7212 IT_BYTEPOS (*it
), stop
, Qnil
);
7215 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7219 case GET_FROM_C_STRING
:
7220 /* Current display element of IT is from a C string. */
7222 /* If the string position is beyond string's end, it means
7223 next_element_from_c_string is padding the string with
7224 blanks, in which case we bypass the bidi iterator,
7225 because it cannot deal with such virtual characters. */
7226 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7228 IT_BYTEPOS (*it
) += it
->len
;
7229 IT_CHARPOS (*it
) += 1;
7233 bidi_move_to_visually_next (&it
->bidi_it
);
7234 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7235 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7239 case GET_FROM_DISPLAY_VECTOR
:
7240 /* Current display element of IT is from a display table entry.
7241 Advance in the display table definition. Reset it to null if
7242 end reached, and continue with characters from buffers/
7244 ++it
->current
.dpvec_index
;
7246 /* Restore face of the iterator to what they were before the
7247 display vector entry (these entries may contain faces). */
7248 it
->face_id
= it
->saved_face_id
;
7250 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7252 int recheck_faces
= it
->ellipsis_p
;
7255 it
->method
= GET_FROM_C_STRING
;
7256 else if (STRINGP (it
->string
))
7257 it
->method
= GET_FROM_STRING
;
7260 it
->method
= GET_FROM_BUFFER
;
7261 it
->object
= it
->w
->contents
;
7265 it
->current
.dpvec_index
= -1;
7267 /* Skip over characters which were displayed via IT->dpvec. */
7268 if (it
->dpvec_char_len
< 0)
7269 reseat_at_next_visible_line_start (it
, 1);
7270 else if (it
->dpvec_char_len
> 0)
7272 if (it
->method
== GET_FROM_STRING
7273 && it
->current
.overlay_string_index
>= 0
7274 && it
->n_overlay_strings
> 0)
7275 it
->ignore_overlay_strings_at_pos_p
= 1;
7276 it
->len
= it
->dpvec_char_len
;
7277 set_iterator_to_next (it
, reseat_p
);
7280 /* Maybe recheck faces after display vector */
7282 it
->stop_charpos
= IT_CHARPOS (*it
);
7286 case GET_FROM_STRING
:
7287 /* Current display element is a character from a Lisp string. */
7288 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7289 /* Don't advance past string end. These conditions are true
7290 when set_iterator_to_next is called at the end of
7291 get_next_display_element, in which case the Lisp string is
7292 already exhausted, and all we want is pop the iterator
7294 if (it
->current
.overlay_string_index
>= 0)
7296 /* This is an overlay string, so there's no padding with
7297 spaces, and the number of characters in the string is
7298 where the string ends. */
7299 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7300 goto consider_string_end
;
7304 /* Not an overlay string. There could be padding, so test
7305 against it->end_charpos . */
7306 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7307 goto consider_string_end
;
7309 if (it
->cmp_it
.id
>= 0)
7315 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7316 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7317 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7318 it
->cmp_it
.from
= it
->cmp_it
.to
;
7322 composition_compute_stop_pos (&it
->cmp_it
,
7323 IT_STRING_CHARPOS (*it
),
7324 IT_STRING_BYTEPOS (*it
),
7325 it
->end_charpos
, it
->string
);
7328 else if (! it
->cmp_it
.reversed_p
)
7330 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7331 bidi_move_to_visually_next (&it
->bidi_it
);
7332 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7333 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7335 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7336 it
->cmp_it
.from
= it
->cmp_it
.to
;
7339 ptrdiff_t stop
= it
->end_charpos
;
7340 if (it
->bidi_it
.scan_dir
< 0)
7342 composition_compute_stop_pos (&it
->cmp_it
,
7343 IT_STRING_CHARPOS (*it
),
7344 IT_STRING_BYTEPOS (*it
), stop
,
7350 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7351 bidi_move_to_visually_next (&it
->bidi_it
);
7352 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7353 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7354 if (it
->cmp_it
.from
> 0)
7355 it
->cmp_it
.to
= it
->cmp_it
.from
;
7358 ptrdiff_t stop
= it
->end_charpos
;
7359 if (it
->bidi_it
.scan_dir
< 0)
7361 composition_compute_stop_pos (&it
->cmp_it
,
7362 IT_STRING_CHARPOS (*it
),
7363 IT_STRING_BYTEPOS (*it
), stop
,
7371 /* If the string position is beyond string's end, it
7372 means next_element_from_string is padding the string
7373 with blanks, in which case we bypass the bidi
7374 iterator, because it cannot deal with such virtual
7376 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7378 IT_STRING_BYTEPOS (*it
) += it
->len
;
7379 IT_STRING_CHARPOS (*it
) += 1;
7383 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7385 bidi_move_to_visually_next (&it
->bidi_it
);
7386 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7387 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7388 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7390 ptrdiff_t stop
= it
->end_charpos
;
7392 if (it
->bidi_it
.scan_dir
< 0)
7394 composition_compute_stop_pos (&it
->cmp_it
,
7395 IT_STRING_CHARPOS (*it
),
7396 IT_STRING_BYTEPOS (*it
), stop
,
7402 consider_string_end
:
7404 if (it
->current
.overlay_string_index
>= 0)
7406 /* IT->string is an overlay string. Advance to the
7407 next, if there is one. */
7408 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7411 next_overlay_string (it
);
7413 setup_for_ellipsis (it
, 0);
7418 /* IT->string is not an overlay string. If we reached
7419 its end, and there is something on IT->stack, proceed
7420 with what is on the stack. This can be either another
7421 string, this time an overlay string, or a buffer. */
7422 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7426 if (it
->method
== GET_FROM_STRING
)
7427 goto consider_string_end
;
7432 case GET_FROM_IMAGE
:
7433 case GET_FROM_STRETCH
:
7434 /* The position etc with which we have to proceed are on
7435 the stack. The position may be at the end of a string,
7436 if the `display' property takes up the whole string. */
7437 eassert (it
->sp
> 0);
7439 if (it
->method
== GET_FROM_STRING
)
7440 goto consider_string_end
;
7444 /* There are no other methods defined, so this should be a bug. */
7448 eassert (it
->method
!= GET_FROM_STRING
7449 || (STRINGP (it
->string
)
7450 && IT_STRING_CHARPOS (*it
) >= 0));
7453 /* Load IT's display element fields with information about the next
7454 display element which comes from a display table entry or from the
7455 result of translating a control character to one of the forms `^C'
7458 IT->dpvec holds the glyphs to return as characters.
7459 IT->saved_face_id holds the face id before the display vector--it
7460 is restored into IT->face_id in set_iterator_to_next. */
7463 next_element_from_display_vector (struct it
*it
)
7466 int prev_face_id
= it
->face_id
;
7470 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7472 it
->face_id
= it
->saved_face_id
;
7474 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7475 That seemed totally bogus - so I changed it... */
7476 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7478 if (GLYPH_CODE_P (gc
))
7480 struct face
*this_face
, *prev_face
, *next_face
;
7482 it
->c
= GLYPH_CODE_CHAR (gc
);
7483 it
->len
= CHAR_BYTES (it
->c
);
7485 /* The entry may contain a face id to use. Such a face id is
7486 the id of a Lisp face, not a realized face. A face id of
7487 zero means no face is specified. */
7488 if (it
->dpvec_face_id
>= 0)
7489 it
->face_id
= it
->dpvec_face_id
;
7492 int lface_id
= GLYPH_CODE_FACE (gc
);
7494 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7498 /* Glyphs in the display vector could have the box face, so we
7499 need to set the related flags in the iterator, as
7501 this_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
7502 prev_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
7504 /* Is this character the first character of a box-face run? */
7505 it
->start_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7507 || prev_face
->box
== FACE_NO_BOX
));
7509 /* For the last character of the box-face run, we need to look
7510 either at the next glyph from the display vector, or at the
7511 face we saw before the display vector. */
7512 next_face_id
= it
->saved_face_id
;
7513 if (it
->current
.dpvec_index
< it
->dpend
- it
->dpvec
- 1)
7515 if (it
->dpvec_face_id
>= 0)
7516 next_face_id
= it
->dpvec_face_id
;
7520 GLYPH_CODE_FACE (it
->dpvec
[it
->current
.dpvec_index
+ 1]);
7523 next_face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7527 next_face
= FACE_FROM_ID (it
->f
, next_face_id
);
7528 it
->end_of_box_run_p
= (this_face
&& this_face
->box
!= FACE_NO_BOX
7530 || next_face
->box
== FACE_NO_BOX
));
7531 it
->face_box_p
= this_face
&& this_face
->box
!= FACE_NO_BOX
;
7534 /* Display table entry is invalid. Return a space. */
7535 it
->c
= ' ', it
->len
= 1;
7537 /* Don't change position and object of the iterator here. They are
7538 still the values of the character that had this display table
7539 entry or was translated, and that's what we want. */
7540 it
->what
= IT_CHARACTER
;
7544 /* Get the first element of string/buffer in the visual order, after
7545 being reseated to a new position in a string or a buffer. */
7547 get_visually_first_element (struct it
*it
)
7549 int string_p
= STRINGP (it
->string
) || it
->s
;
7550 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7551 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7553 if (STRINGP (it
->string
))
7555 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7556 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7560 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7561 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7564 if (it
->bidi_it
.charpos
== eob
)
7566 /* Nothing to do, but reset the FIRST_ELT flag, like
7567 bidi_paragraph_init does, because we are not going to
7569 it
->bidi_it
.first_elt
= 0;
7571 else if (it
->bidi_it
.charpos
== bob
7573 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7574 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7576 /* If we are at the beginning of a line/string, we can produce
7577 the next element right away. */
7578 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7579 bidi_move_to_visually_next (&it
->bidi_it
);
7583 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7585 /* We need to prime the bidi iterator starting at the line's or
7586 string's beginning, before we will be able to produce the
7589 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7591 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7592 IT_BYTEPOS (*it
), -1,
7593 &it
->bidi_it
.bytepos
);
7594 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7597 /* Now return to buffer/string position where we were asked
7598 to get the next display element, and produce that. */
7599 bidi_move_to_visually_next (&it
->bidi_it
);
7601 while (it
->bidi_it
.bytepos
!= orig_bytepos
7602 && it
->bidi_it
.charpos
< eob
);
7605 /* Adjust IT's position information to where we ended up. */
7606 if (STRINGP (it
->string
))
7608 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7609 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7613 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7614 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7617 if (STRINGP (it
->string
) || !it
->s
)
7619 ptrdiff_t stop
, charpos
, bytepos
;
7621 if (STRINGP (it
->string
))
7624 stop
= SCHARS (it
->string
);
7625 if (stop
> it
->end_charpos
)
7626 stop
= it
->end_charpos
;
7627 charpos
= IT_STRING_CHARPOS (*it
);
7628 bytepos
= IT_STRING_BYTEPOS (*it
);
7632 stop
= it
->end_charpos
;
7633 charpos
= IT_CHARPOS (*it
);
7634 bytepos
= IT_BYTEPOS (*it
);
7636 if (it
->bidi_it
.scan_dir
< 0)
7638 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7643 /* Load IT with the next display element from Lisp string IT->string.
7644 IT->current.string_pos is the current position within the string.
7645 If IT->current.overlay_string_index >= 0, the Lisp string is an
7649 next_element_from_string (struct it
*it
)
7651 struct text_pos position
;
7653 eassert (STRINGP (it
->string
));
7654 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7655 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7656 position
= it
->current
.string_pos
;
7658 /* With bidi reordering, the character to display might not be the
7659 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7660 that we were reseat()ed to a new string, whose paragraph
7661 direction is not known. */
7662 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7664 get_visually_first_element (it
);
7665 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7668 /* Time to check for invisible text? */
7669 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7671 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7674 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7675 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7677 /* With bidi non-linear iteration, we could find
7678 ourselves far beyond the last computed stop_charpos,
7679 with several other stop positions in between that we
7680 missed. Scan them all now, in buffer's logical
7681 order, until we find and handle the last stop_charpos
7682 that precedes our current position. */
7683 handle_stop_backwards (it
, it
->stop_charpos
);
7684 return GET_NEXT_DISPLAY_ELEMENT (it
);
7690 /* Take note of the stop position we just moved
7691 across, for when we will move back across it. */
7692 it
->prev_stop
= it
->stop_charpos
;
7693 /* If we are at base paragraph embedding level, take
7694 note of the last stop position seen at this
7696 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7697 it
->base_level_stop
= it
->stop_charpos
;
7701 /* Since a handler may have changed IT->method, we must
7703 return GET_NEXT_DISPLAY_ELEMENT (it
);
7707 /* If we are before prev_stop, we may have overstepped
7708 on our way backwards a stop_pos, and if so, we need
7709 to handle that stop_pos. */
7710 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7711 /* We can sometimes back up for reasons that have nothing
7712 to do with bidi reordering. E.g., compositions. The
7713 code below is only needed when we are above the base
7714 embedding level, so test for that explicitly. */
7715 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7717 /* If we lost track of base_level_stop, we have no better
7718 place for handle_stop_backwards to start from than string
7719 beginning. This happens, e.g., when we were reseated to
7720 the previous screenful of text by vertical-motion. */
7721 if (it
->base_level_stop
<= 0
7722 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7723 it
->base_level_stop
= 0;
7724 handle_stop_backwards (it
, it
->base_level_stop
);
7725 return GET_NEXT_DISPLAY_ELEMENT (it
);
7729 if (it
->current
.overlay_string_index
>= 0)
7731 /* Get the next character from an overlay string. In overlay
7732 strings, there is no field width or padding with spaces to
7734 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7739 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7740 IT_STRING_BYTEPOS (*it
),
7741 it
->bidi_it
.scan_dir
< 0
7743 : SCHARS (it
->string
))
7744 && next_element_from_composition (it
))
7748 else if (STRING_MULTIBYTE (it
->string
))
7750 const unsigned char *s
= (SDATA (it
->string
)
7751 + IT_STRING_BYTEPOS (*it
));
7752 it
->c
= string_char_and_length (s
, &it
->len
);
7756 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7762 /* Get the next character from a Lisp string that is not an
7763 overlay string. Such strings come from the mode line, for
7764 example. We may have to pad with spaces, or truncate the
7765 string. See also next_element_from_c_string. */
7766 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7771 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7773 /* Pad with spaces. */
7774 it
->c
= ' ', it
->len
= 1;
7775 CHARPOS (position
) = BYTEPOS (position
) = -1;
7777 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7778 IT_STRING_BYTEPOS (*it
),
7779 it
->bidi_it
.scan_dir
< 0
7781 : it
->string_nchars
)
7782 && next_element_from_composition (it
))
7786 else if (STRING_MULTIBYTE (it
->string
))
7788 const unsigned char *s
= (SDATA (it
->string
)
7789 + IT_STRING_BYTEPOS (*it
));
7790 it
->c
= string_char_and_length (s
, &it
->len
);
7794 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7799 /* Record what we have and where it came from. */
7800 it
->what
= IT_CHARACTER
;
7801 it
->object
= it
->string
;
7802 it
->position
= position
;
7807 /* Load IT with next display element from C string IT->s.
7808 IT->string_nchars is the maximum number of characters to return
7809 from the string. IT->end_charpos may be greater than
7810 IT->string_nchars when this function is called, in which case we
7811 may have to return padding spaces. Value is zero if end of string
7812 reached, including padding spaces. */
7815 next_element_from_c_string (struct it
*it
)
7820 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7821 it
->what
= IT_CHARACTER
;
7822 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7825 /* With bidi reordering, the character to display might not be the
7826 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7827 we were reseated to a new string, whose paragraph direction is
7829 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7830 get_visually_first_element (it
);
7832 /* IT's position can be greater than IT->string_nchars in case a
7833 field width or precision has been specified when the iterator was
7835 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7837 /* End of the game. */
7841 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7843 /* Pad with spaces. */
7844 it
->c
= ' ', it
->len
= 1;
7845 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7847 else if (it
->multibyte_p
)
7848 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7850 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7856 /* Set up IT to return characters from an ellipsis, if appropriate.
7857 The definition of the ellipsis glyphs may come from a display table
7858 entry. This function fills IT with the first glyph from the
7859 ellipsis if an ellipsis is to be displayed. */
7862 next_element_from_ellipsis (struct it
*it
)
7864 if (it
->selective_display_ellipsis_p
)
7865 setup_for_ellipsis (it
, it
->len
);
7868 /* The face at the current position may be different from the
7869 face we find after the invisible text. Remember what it
7870 was in IT->saved_face_id, and signal that it's there by
7871 setting face_before_selective_p. */
7872 it
->saved_face_id
= it
->face_id
;
7873 it
->method
= GET_FROM_BUFFER
;
7874 it
->object
= it
->w
->contents
;
7875 reseat_at_next_visible_line_start (it
, 1);
7876 it
->face_before_selective_p
= 1;
7879 return GET_NEXT_DISPLAY_ELEMENT (it
);
7883 /* Deliver an image display element. The iterator IT is already
7884 filled with image information (done in handle_display_prop). Value
7889 next_element_from_image (struct it
*it
)
7891 it
->what
= IT_IMAGE
;
7892 it
->ignore_overlay_strings_at_pos_p
= 0;
7897 /* Fill iterator IT with next display element from a stretch glyph
7898 property. IT->object is the value of the text property. Value is
7902 next_element_from_stretch (struct it
*it
)
7904 it
->what
= IT_STRETCH
;
7908 /* Scan backwards from IT's current position until we find a stop
7909 position, or until BEGV. This is called when we find ourself
7910 before both the last known prev_stop and base_level_stop while
7911 reordering bidirectional text. */
7914 compute_stop_pos_backwards (struct it
*it
)
7916 const int SCAN_BACK_LIMIT
= 1000;
7917 struct text_pos pos
;
7918 struct display_pos save_current
= it
->current
;
7919 struct text_pos save_position
= it
->position
;
7920 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7921 ptrdiff_t where_we_are
= charpos
;
7922 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7923 ptrdiff_t save_end_pos
= it
->end_charpos
;
7925 eassert (NILP (it
->string
) && !it
->s
);
7926 eassert (it
->bidi_p
);
7930 it
->end_charpos
= min (charpos
+ 1, ZV
);
7931 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7932 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7933 reseat_1 (it
, pos
, 0);
7934 compute_stop_pos (it
);
7935 /* We must advance forward, right? */
7936 if (it
->stop_charpos
<= charpos
)
7939 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7941 if (it
->stop_charpos
<= where_we_are
)
7942 it
->prev_stop
= it
->stop_charpos
;
7944 it
->prev_stop
= BEGV
;
7946 it
->current
= save_current
;
7947 it
->position
= save_position
;
7948 it
->stop_charpos
= save_stop_pos
;
7949 it
->end_charpos
= save_end_pos
;
7952 /* Scan forward from CHARPOS in the current buffer/string, until we
7953 find a stop position > current IT's position. Then handle the stop
7954 position before that. This is called when we bump into a stop
7955 position while reordering bidirectional text. CHARPOS should be
7956 the last previously processed stop_pos (or BEGV/0, if none were
7957 processed yet) whose position is less that IT's current
7961 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7963 int bufp
= !STRINGP (it
->string
);
7964 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7965 struct display_pos save_current
= it
->current
;
7966 struct text_pos save_position
= it
->position
;
7967 struct text_pos pos1
;
7968 ptrdiff_t next_stop
;
7970 /* Scan in strict logical order. */
7971 eassert (it
->bidi_p
);
7975 it
->prev_stop
= charpos
;
7978 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7979 reseat_1 (it
, pos1
, 0);
7982 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7983 compute_stop_pos (it
);
7984 /* We must advance forward, right? */
7985 if (it
->stop_charpos
<= it
->prev_stop
)
7987 charpos
= it
->stop_charpos
;
7989 while (charpos
<= where_we_are
);
7992 it
->current
= save_current
;
7993 it
->position
= save_position
;
7994 next_stop
= it
->stop_charpos
;
7995 it
->stop_charpos
= it
->prev_stop
;
7997 it
->stop_charpos
= next_stop
;
8000 /* Load IT with the next display element from current_buffer. Value
8001 is zero if end of buffer reached. IT->stop_charpos is the next
8002 position at which to stop and check for text properties or buffer
8006 next_element_from_buffer (struct it
*it
)
8010 eassert (IT_CHARPOS (*it
) >= BEGV
);
8011 eassert (NILP (it
->string
) && !it
->s
);
8012 eassert (!it
->bidi_p
8013 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
8014 && it
->bidi_it
.string
.s
== NULL
));
8016 /* With bidi reordering, the character to display might not be the
8017 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
8018 we were reseat()ed to a new buffer position, which is potentially
8019 a different paragraph. */
8020 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
8022 get_visually_first_element (it
);
8023 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8026 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
8028 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
8030 int overlay_strings_follow_p
;
8032 /* End of the game, except when overlay strings follow that
8033 haven't been returned yet. */
8034 if (it
->overlay_strings_at_end_processed_p
)
8035 overlay_strings_follow_p
= 0;
8038 it
->overlay_strings_at_end_processed_p
= 1;
8039 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
8042 if (overlay_strings_follow_p
)
8043 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8047 it
->position
= it
->current
.pos
;
8051 else if (!(!it
->bidi_p
8052 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8053 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8055 /* With bidi non-linear iteration, we could find ourselves
8056 far beyond the last computed stop_charpos, with several
8057 other stop positions in between that we missed. Scan
8058 them all now, in buffer's logical order, until we find
8059 and handle the last stop_charpos that precedes our
8060 current position. */
8061 handle_stop_backwards (it
, it
->stop_charpos
);
8062 return GET_NEXT_DISPLAY_ELEMENT (it
);
8068 /* Take note of the stop position we just moved across,
8069 for when we will move back across it. */
8070 it
->prev_stop
= it
->stop_charpos
;
8071 /* If we are at base paragraph embedding level, take
8072 note of the last stop position seen at this
8074 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8075 it
->base_level_stop
= it
->stop_charpos
;
8078 return GET_NEXT_DISPLAY_ELEMENT (it
);
8082 /* If we are before prev_stop, we may have overstepped on
8083 our way backwards a stop_pos, and if so, we need to
8084 handle that stop_pos. */
8085 && IT_CHARPOS (*it
) < it
->prev_stop
8086 /* We can sometimes back up for reasons that have nothing
8087 to do with bidi reordering. E.g., compositions. The
8088 code below is only needed when we are above the base
8089 embedding level, so test for that explicitly. */
8090 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8092 if (it
->base_level_stop
<= 0
8093 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8095 /* If we lost track of base_level_stop, we need to find
8096 prev_stop by looking backwards. This happens, e.g., when
8097 we were reseated to the previous screenful of text by
8099 it
->base_level_stop
= BEGV
;
8100 compute_stop_pos_backwards (it
);
8101 handle_stop_backwards (it
, it
->prev_stop
);
8104 handle_stop_backwards (it
, it
->base_level_stop
);
8105 return GET_NEXT_DISPLAY_ELEMENT (it
);
8109 /* No face changes, overlays etc. in sight, so just return a
8110 character from current_buffer. */
8114 /* Maybe run the redisplay end trigger hook. Performance note:
8115 This doesn't seem to cost measurable time. */
8116 if (it
->redisplay_end_trigger_charpos
8118 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8119 run_redisplay_end_trigger_hook (it
);
8121 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8122 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8124 && next_element_from_composition (it
))
8129 /* Get the next character, maybe multibyte. */
8130 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8131 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8132 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8134 it
->c
= *p
, it
->len
= 1;
8136 /* Record what we have and where it came from. */
8137 it
->what
= IT_CHARACTER
;
8138 it
->object
= it
->w
->contents
;
8139 it
->position
= it
->current
.pos
;
8141 /* Normally we return the character found above, except when we
8142 really want to return an ellipsis for selective display. */
8147 /* A value of selective > 0 means hide lines indented more
8148 than that number of columns. */
8149 if (it
->selective
> 0
8150 && IT_CHARPOS (*it
) + 1 < ZV
8151 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8152 IT_BYTEPOS (*it
) + 1,
8155 success_p
= next_element_from_ellipsis (it
);
8156 it
->dpvec_char_len
= -1;
8159 else if (it
->c
== '\r' && it
->selective
== -1)
8161 /* A value of selective == -1 means that everything from the
8162 CR to the end of the line is invisible, with maybe an
8163 ellipsis displayed for it. */
8164 success_p
= next_element_from_ellipsis (it
);
8165 it
->dpvec_char_len
= -1;
8170 /* Value is zero if end of buffer reached. */
8171 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8176 /* Run the redisplay end trigger hook for IT. */
8179 run_redisplay_end_trigger_hook (struct it
*it
)
8181 Lisp_Object args
[3];
8183 /* IT->glyph_row should be non-null, i.e. we should be actually
8184 displaying something, or otherwise we should not run the hook. */
8185 eassert (it
->glyph_row
);
8187 /* Set up hook arguments. */
8188 args
[0] = Qredisplay_end_trigger_functions
;
8189 args
[1] = it
->window
;
8190 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8191 it
->redisplay_end_trigger_charpos
= 0;
8193 /* Since we are *trying* to run these functions, don't try to run
8194 them again, even if they get an error. */
8195 wset_redisplay_end_trigger (it
->w
, Qnil
);
8196 Frun_hook_with_args (3, args
);
8198 /* Notice if it changed the face of the character we are on. */
8199 handle_face_prop (it
);
8203 /* Deliver a composition display element. Unlike the other
8204 next_element_from_XXX, this function is not registered in the array
8205 get_next_element[]. It is called from next_element_from_buffer and
8206 next_element_from_string when necessary. */
8209 next_element_from_composition (struct it
*it
)
8211 it
->what
= IT_COMPOSITION
;
8212 it
->len
= it
->cmp_it
.nbytes
;
8213 if (STRINGP (it
->string
))
8217 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8218 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8221 it
->position
= it
->current
.string_pos
;
8222 it
->object
= it
->string
;
8223 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8224 IT_STRING_BYTEPOS (*it
), it
->string
);
8230 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8231 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8234 if (it
->bidi_it
.new_paragraph
)
8235 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8236 /* Resync the bidi iterator with IT's new position.
8237 FIXME: this doesn't support bidirectional text. */
8238 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8239 bidi_move_to_visually_next (&it
->bidi_it
);
8243 it
->position
= it
->current
.pos
;
8244 it
->object
= it
->w
->contents
;
8245 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8246 IT_BYTEPOS (*it
), Qnil
);
8253 /***********************************************************************
8254 Moving an iterator without producing glyphs
8255 ***********************************************************************/
8257 /* Check if iterator is at a position corresponding to a valid buffer
8258 position after some move_it_ call. */
8260 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8261 ((it)->method == GET_FROM_STRING \
8262 ? IT_STRING_CHARPOS (*it) == 0 \
8266 /* Move iterator IT to a specified buffer or X position within one
8267 line on the display without producing glyphs.
8269 OP should be a bit mask including some or all of these bits:
8270 MOVE_TO_X: Stop upon reaching x-position TO_X.
8271 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8272 Regardless of OP's value, stop upon reaching the end of the display line.
8274 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8275 This means, in particular, that TO_X includes window's horizontal
8278 The return value has several possible values that
8279 say what condition caused the scan to stop:
8281 MOVE_POS_MATCH_OR_ZV
8282 - when TO_POS or ZV was reached.
8285 -when TO_X was reached before TO_POS or ZV were reached.
8288 - when we reached the end of the display area and the line must
8292 - when we reached the end of the display area and the line is
8296 - when we stopped at a line end, i.e. a newline or a CR and selective
8299 static enum move_it_result
8300 move_it_in_display_line_to (struct it
*it
,
8301 ptrdiff_t to_charpos
, int to_x
,
8302 enum move_operation_enum op
)
8304 enum move_it_result result
= MOVE_UNDEFINED
;
8305 struct glyph_row
*saved_glyph_row
;
8306 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8307 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8308 void *ppos_data
= NULL
;
8310 enum it_method prev_method
= it
->method
;
8311 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8312 int saw_smaller_pos
= prev_pos
< to_charpos
;
8314 /* Don't produce glyphs in produce_glyphs. */
8315 saved_glyph_row
= it
->glyph_row
;
8316 it
->glyph_row
= NULL
;
8318 /* Use wrap_it to save a copy of IT wherever a word wrap could
8319 occur. Use atpos_it to save a copy of IT at the desired buffer
8320 position, if found, so that we can scan ahead and check if the
8321 word later overshoots the window edge. Use atx_it similarly, for
8327 /* Use ppos_it under bidi reordering to save a copy of IT for the
8328 position > CHARPOS that is the closest to CHARPOS. We restore
8329 that position in IT when we have scanned the entire display line
8330 without finding a match for CHARPOS and all the character
8331 positions are greater than CHARPOS. */
8334 SAVE_IT (ppos_it
, *it
, ppos_data
);
8335 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8336 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8337 SAVE_IT (ppos_it
, *it
, ppos_data
);
8340 #define BUFFER_POS_REACHED_P() \
8341 ((op & MOVE_TO_POS) != 0 \
8342 && BUFFERP (it->object) \
8343 && (IT_CHARPOS (*it) == to_charpos \
8345 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8346 && IT_CHARPOS (*it) > to_charpos) \
8347 || (it->what == IT_COMPOSITION \
8348 && ((IT_CHARPOS (*it) > to_charpos \
8349 && to_charpos >= it->cmp_it.charpos) \
8350 || (IT_CHARPOS (*it) < to_charpos \
8351 && to_charpos <= it->cmp_it.charpos)))) \
8352 && (it->method == GET_FROM_BUFFER \
8353 || (it->method == GET_FROM_DISPLAY_VECTOR \
8354 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8356 /* If there's a line-/wrap-prefix, handle it. */
8357 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8358 && it
->current_y
< it
->last_visible_y
)
8359 handle_line_prefix (it
);
8361 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8362 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8366 int x
, i
, ascent
= 0, descent
= 0;
8368 /* Utility macro to reset an iterator with x, ascent, and descent. */
8369 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8370 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8371 (IT)->max_descent = descent)
8373 /* Stop if we move beyond TO_CHARPOS (after an image or a
8374 display string or stretch glyph). */
8375 if ((op
& MOVE_TO_POS
) != 0
8376 && BUFFERP (it
->object
)
8377 && it
->method
== GET_FROM_BUFFER
8379 /* When the iterator is at base embedding level, we
8380 are guaranteed that characters are delivered for
8381 display in strictly increasing order of their
8382 buffer positions. */
8383 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8384 && IT_CHARPOS (*it
) > to_charpos
)
8386 && (prev_method
== GET_FROM_IMAGE
8387 || prev_method
== GET_FROM_STRETCH
8388 || prev_method
== GET_FROM_STRING
)
8389 /* Passed TO_CHARPOS from left to right. */
8390 && ((prev_pos
< to_charpos
8391 && IT_CHARPOS (*it
) > to_charpos
)
8392 /* Passed TO_CHARPOS from right to left. */
8393 || (prev_pos
> to_charpos
8394 && IT_CHARPOS (*it
) < to_charpos
)))))
8396 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8398 result
= MOVE_POS_MATCH_OR_ZV
;
8401 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8402 /* If wrap_it is valid, the current position might be in a
8403 word that is wrapped. So, save the iterator in
8404 atpos_it and continue to see if wrapping happens. */
8405 SAVE_IT (atpos_it
, *it
, atpos_data
);
8408 /* Stop when ZV reached.
8409 We used to stop here when TO_CHARPOS reached as well, but that is
8410 too soon if this glyph does not fit on this line. So we handle it
8411 explicitly below. */
8412 if (!get_next_display_element (it
))
8414 result
= MOVE_POS_MATCH_OR_ZV
;
8418 if (it
->line_wrap
== TRUNCATE
)
8420 if (BUFFER_POS_REACHED_P ())
8422 result
= MOVE_POS_MATCH_OR_ZV
;
8428 if (it
->line_wrap
== WORD_WRAP
)
8430 if (IT_DISPLAYING_WHITESPACE (it
))
8434 /* We have reached a glyph that follows one or more
8435 whitespace characters. If the position is
8436 already found, we are done. */
8437 if (atpos_it
.sp
>= 0)
8439 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8440 result
= MOVE_POS_MATCH_OR_ZV
;
8445 RESTORE_IT (it
, &atx_it
, atx_data
);
8446 result
= MOVE_X_REACHED
;
8449 /* Otherwise, we can wrap here. */
8450 SAVE_IT (wrap_it
, *it
, wrap_data
);
8456 /* Remember the line height for the current line, in case
8457 the next element doesn't fit on the line. */
8458 ascent
= it
->max_ascent
;
8459 descent
= it
->max_descent
;
8461 /* The call to produce_glyphs will get the metrics of the
8462 display element IT is loaded with. Record the x-position
8463 before this display element, in case it doesn't fit on the
8467 PRODUCE_GLYPHS (it
);
8469 if (it
->area
!= TEXT_AREA
)
8471 prev_method
= it
->method
;
8472 if (it
->method
== GET_FROM_BUFFER
)
8473 prev_pos
= IT_CHARPOS (*it
);
8474 set_iterator_to_next (it
, 1);
8475 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8476 SET_TEXT_POS (this_line_min_pos
,
8477 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8479 && (op
& MOVE_TO_POS
)
8480 && IT_CHARPOS (*it
) > to_charpos
8481 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8482 SAVE_IT (ppos_it
, *it
, ppos_data
);
8486 /* The number of glyphs we get back in IT->nglyphs will normally
8487 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8488 character on a terminal frame, or (iii) a line end. For the
8489 second case, IT->nglyphs - 1 padding glyphs will be present.
8490 (On X frames, there is only one glyph produced for a
8491 composite character.)
8493 The behavior implemented below means, for continuation lines,
8494 that as many spaces of a TAB as fit on the current line are
8495 displayed there. For terminal frames, as many glyphs of a
8496 multi-glyph character are displayed in the current line, too.
8497 This is what the old redisplay code did, and we keep it that
8498 way. Under X, the whole shape of a complex character must
8499 fit on the line or it will be completely displayed in the
8502 Note that both for tabs and padding glyphs, all glyphs have
8506 /* More than one glyph or glyph doesn't fit on line. All
8507 glyphs have the same width. */
8508 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8510 int x_before_this_char
= x
;
8511 int hpos_before_this_char
= it
->hpos
;
8513 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8515 new_x
= x
+ single_glyph_width
;
8517 /* We want to leave anything reaching TO_X to the caller. */
8518 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8520 if (BUFFER_POS_REACHED_P ())
8522 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8523 goto buffer_pos_reached
;
8524 if (atpos_it
.sp
< 0)
8526 SAVE_IT (atpos_it
, *it
, atpos_data
);
8527 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8532 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8535 result
= MOVE_X_REACHED
;
8540 SAVE_IT (atx_it
, *it
, atx_data
);
8541 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8546 if (/* Lines are continued. */
8547 it
->line_wrap
!= TRUNCATE
8548 && (/* And glyph doesn't fit on the line. */
8549 new_x
> it
->last_visible_x
8550 /* Or it fits exactly and we're on a window
8552 || (new_x
== it
->last_visible_x
8553 && FRAME_WINDOW_P (it
->f
)
8554 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8555 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8556 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8558 if (/* IT->hpos == 0 means the very first glyph
8559 doesn't fit on the line, e.g. a wide image. */
8561 || (new_x
== it
->last_visible_x
8562 && FRAME_WINDOW_P (it
->f
)))
8565 it
->current_x
= new_x
;
8567 /* The character's last glyph just barely fits
8569 if (i
== it
->nglyphs
- 1)
8571 /* If this is the destination position,
8572 return a position *before* it in this row,
8573 now that we know it fits in this row. */
8574 if (BUFFER_POS_REACHED_P ())
8576 if (it
->line_wrap
!= WORD_WRAP
8579 it
->hpos
= hpos_before_this_char
;
8580 it
->current_x
= x_before_this_char
;
8581 result
= MOVE_POS_MATCH_OR_ZV
;
8584 if (it
->line_wrap
== WORD_WRAP
8587 SAVE_IT (atpos_it
, *it
, atpos_data
);
8588 atpos_it
.current_x
= x_before_this_char
;
8589 atpos_it
.hpos
= hpos_before_this_char
;
8593 prev_method
= it
->method
;
8594 if (it
->method
== GET_FROM_BUFFER
)
8595 prev_pos
= IT_CHARPOS (*it
);
8596 set_iterator_to_next (it
, 1);
8597 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8598 SET_TEXT_POS (this_line_min_pos
,
8599 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8600 /* On graphical terminals, newlines may
8601 "overflow" into the fringe if
8602 overflow-newline-into-fringe is non-nil.
8603 On text terminals, and on graphical
8604 terminals with no right margin, newlines
8605 may overflow into the last glyph on the
8607 if (!FRAME_WINDOW_P (it
->f
)
8609 && it
->bidi_it
.paragraph_dir
== R2L
)
8610 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8611 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8612 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8614 if (!get_next_display_element (it
))
8616 result
= MOVE_POS_MATCH_OR_ZV
;
8619 if (BUFFER_POS_REACHED_P ())
8621 if (ITERATOR_AT_END_OF_LINE_P (it
))
8622 result
= MOVE_POS_MATCH_OR_ZV
;
8624 result
= MOVE_LINE_CONTINUED
;
8627 if (ITERATOR_AT_END_OF_LINE_P (it
)
8628 && (it
->line_wrap
!= WORD_WRAP
8631 result
= MOVE_NEWLINE_OR_CR
;
8638 IT_RESET_X_ASCENT_DESCENT (it
);
8640 if (wrap_it
.sp
>= 0)
8642 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8647 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8649 result
= MOVE_LINE_CONTINUED
;
8653 if (BUFFER_POS_REACHED_P ())
8655 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8656 goto buffer_pos_reached
;
8657 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8659 SAVE_IT (atpos_it
, *it
, atpos_data
);
8660 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8664 if (new_x
> it
->first_visible_x
)
8666 /* Glyph is visible. Increment number of glyphs that
8667 would be displayed. */
8672 if (result
!= MOVE_UNDEFINED
)
8675 else if (BUFFER_POS_REACHED_P ())
8678 IT_RESET_X_ASCENT_DESCENT (it
);
8679 result
= MOVE_POS_MATCH_OR_ZV
;
8682 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8684 /* Stop when TO_X specified and reached. This check is
8685 necessary here because of lines consisting of a line end,
8686 only. The line end will not produce any glyphs and we
8687 would never get MOVE_X_REACHED. */
8688 eassert (it
->nglyphs
== 0);
8689 result
= MOVE_X_REACHED
;
8693 /* Is this a line end? If yes, we're done. */
8694 if (ITERATOR_AT_END_OF_LINE_P (it
))
8696 /* If we are past TO_CHARPOS, but never saw any character
8697 positions smaller than TO_CHARPOS, return
8698 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8700 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8702 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8704 if (IT_CHARPOS (ppos_it
) < ZV
)
8706 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8707 result
= MOVE_POS_MATCH_OR_ZV
;
8710 goto buffer_pos_reached
;
8712 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8713 && IT_CHARPOS (*it
) > to_charpos
)
8714 goto buffer_pos_reached
;
8716 result
= MOVE_NEWLINE_OR_CR
;
8719 result
= MOVE_NEWLINE_OR_CR
;
8723 prev_method
= it
->method
;
8724 if (it
->method
== GET_FROM_BUFFER
)
8725 prev_pos
= IT_CHARPOS (*it
);
8726 /* The current display element has been consumed. Advance
8728 set_iterator_to_next (it
, 1);
8729 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8730 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8731 if (IT_CHARPOS (*it
) < to_charpos
)
8732 saw_smaller_pos
= 1;
8734 && (op
& MOVE_TO_POS
)
8735 && IT_CHARPOS (*it
) >= to_charpos
8736 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8737 SAVE_IT (ppos_it
, *it
, ppos_data
);
8739 /* Stop if lines are truncated and IT's current x-position is
8740 past the right edge of the window now. */
8741 if (it
->line_wrap
== TRUNCATE
8742 && it
->current_x
>= it
->last_visible_x
)
8744 if (!FRAME_WINDOW_P (it
->f
)
8745 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8746 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8747 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8748 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8752 if ((at_eob_p
= !get_next_display_element (it
))
8753 || BUFFER_POS_REACHED_P ()
8754 /* If we are past TO_CHARPOS, but never saw any
8755 character positions smaller than TO_CHARPOS,
8756 return MOVE_POS_MATCH_OR_ZV, like the
8757 unidirectional display did. */
8758 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8760 && IT_CHARPOS (*it
) > to_charpos
))
8763 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8764 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8765 result
= MOVE_POS_MATCH_OR_ZV
;
8768 if (ITERATOR_AT_END_OF_LINE_P (it
))
8770 result
= MOVE_NEWLINE_OR_CR
;
8774 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8776 && IT_CHARPOS (*it
) > to_charpos
)
8778 if (IT_CHARPOS (ppos_it
) < ZV
)
8779 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8780 result
= MOVE_POS_MATCH_OR_ZV
;
8783 result
= MOVE_LINE_TRUNCATED
;
8786 #undef IT_RESET_X_ASCENT_DESCENT
8789 #undef BUFFER_POS_REACHED_P
8791 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8792 restore the saved iterator. */
8793 if (atpos_it
.sp
>= 0)
8794 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8795 else if (atx_it
.sp
>= 0)
8796 RESTORE_IT (it
, &atx_it
, atx_data
);
8801 bidi_unshelve_cache (atpos_data
, 1);
8803 bidi_unshelve_cache (atx_data
, 1);
8805 bidi_unshelve_cache (wrap_data
, 1);
8807 bidi_unshelve_cache (ppos_data
, 1);
8809 /* Restore the iterator settings altered at the beginning of this
8811 it
->glyph_row
= saved_glyph_row
;
8815 /* For external use. */
8817 move_it_in_display_line (struct it
*it
,
8818 ptrdiff_t to_charpos
, int to_x
,
8819 enum move_operation_enum op
)
8821 if (it
->line_wrap
== WORD_WRAP
8822 && (op
& MOVE_TO_X
))
8825 void *save_data
= NULL
;
8828 SAVE_IT (save_it
, *it
, save_data
);
8829 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8830 /* When word-wrap is on, TO_X may lie past the end
8831 of a wrapped line. Then it->current is the
8832 character on the next line, so backtrack to the
8833 space before the wrap point. */
8834 if (skip
== MOVE_LINE_CONTINUED
)
8836 int prev_x
= max (it
->current_x
- 1, 0);
8837 RESTORE_IT (it
, &save_it
, save_data
);
8838 move_it_in_display_line_to
8839 (it
, -1, prev_x
, MOVE_TO_X
);
8842 bidi_unshelve_cache (save_data
, 1);
8845 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8849 /* Move IT forward until it satisfies one or more of the criteria in
8850 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8852 OP is a bit-mask that specifies where to stop, and in particular,
8853 which of those four position arguments makes a difference. See the
8854 description of enum move_operation_enum.
8856 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8857 screen line, this function will set IT to the next position that is
8858 displayed to the right of TO_CHARPOS on the screen. */
8861 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8863 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8864 int line_height
, line_start_x
= 0, reached
= 0;
8865 void *backup_data
= NULL
;
8869 if (op
& MOVE_TO_VPOS
)
8871 /* If no TO_CHARPOS and no TO_X specified, stop at the
8872 start of the line TO_VPOS. */
8873 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8875 if (it
->vpos
== to_vpos
)
8881 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8885 /* TO_VPOS >= 0 means stop at TO_X in the line at
8886 TO_VPOS, or at TO_POS, whichever comes first. */
8887 if (it
->vpos
== to_vpos
)
8893 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8895 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8900 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8902 /* We have reached TO_X but not in the line we want. */
8903 skip
= move_it_in_display_line_to (it
, to_charpos
,
8905 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8913 else if (op
& MOVE_TO_Y
)
8915 struct it it_backup
;
8917 if (it
->line_wrap
== WORD_WRAP
)
8918 SAVE_IT (it_backup
, *it
, backup_data
);
8920 /* TO_Y specified means stop at TO_X in the line containing
8921 TO_Y---or at TO_CHARPOS if this is reached first. The
8922 problem is that we can't really tell whether the line
8923 contains TO_Y before we have completely scanned it, and
8924 this may skip past TO_X. What we do is to first scan to
8927 If TO_X is not specified, use a TO_X of zero. The reason
8928 is to make the outcome of this function more predictable.
8929 If we didn't use TO_X == 0, we would stop at the end of
8930 the line which is probably not what a caller would expect
8932 skip
= move_it_in_display_line_to
8933 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8934 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8936 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8937 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8939 else if (skip
== MOVE_X_REACHED
)
8941 /* If TO_X was reached, we want to know whether TO_Y is
8942 in the line. We know this is the case if the already
8943 scanned glyphs make the line tall enough. Otherwise,
8944 we must check by scanning the rest of the line. */
8945 line_height
= it
->max_ascent
+ it
->max_descent
;
8946 if (to_y
>= it
->current_y
8947 && to_y
< it
->current_y
+ line_height
)
8952 SAVE_IT (it_backup
, *it
, backup_data
);
8953 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8954 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8956 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8957 line_height
= it
->max_ascent
+ it
->max_descent
;
8958 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8960 if (to_y
>= it
->current_y
8961 && to_y
< it
->current_y
+ line_height
)
8963 /* If TO_Y is in this line and TO_X was reached
8964 above, we scanned too far. We have to restore
8965 IT's settings to the ones before skipping. But
8966 keep the more accurate values of max_ascent and
8967 max_descent we've found while skipping the rest
8968 of the line, for the sake of callers, such as
8969 pos_visible_p, that need to know the line
8971 int max_ascent
= it
->max_ascent
;
8972 int max_descent
= it
->max_descent
;
8974 RESTORE_IT (it
, &it_backup
, backup_data
);
8975 it
->max_ascent
= max_ascent
;
8976 it
->max_descent
= max_descent
;
8982 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8988 /* Check whether TO_Y is in this line. */
8989 line_height
= it
->max_ascent
+ it
->max_descent
;
8990 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8992 if (to_y
>= it
->current_y
8993 && to_y
< it
->current_y
+ line_height
)
8995 /* When word-wrap is on, TO_X may lie past the end
8996 of a wrapped line. Then it->current is the
8997 character on the next line, so backtrack to the
8998 space before the wrap point. */
8999 if (skip
== MOVE_LINE_CONTINUED
9000 && it
->line_wrap
== WORD_WRAP
)
9002 int prev_x
= max (it
->current_x
- 1, 0);
9003 RESTORE_IT (it
, &it_backup
, backup_data
);
9004 skip
= move_it_in_display_line_to
9005 (it
, -1, prev_x
, MOVE_TO_X
);
9014 else if (BUFFERP (it
->object
)
9015 && (it
->method
== GET_FROM_BUFFER
9016 || it
->method
== GET_FROM_STRETCH
)
9017 && IT_CHARPOS (*it
) >= to_charpos
9018 /* Under bidi iteration, a call to set_iterator_to_next
9019 can scan far beyond to_charpos if the initial
9020 portion of the next line needs to be reordered. In
9021 that case, give move_it_in_display_line_to another
9024 && it
->bidi_it
.scan_dir
== -1))
9025 skip
= MOVE_POS_MATCH_OR_ZV
;
9027 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
9031 case MOVE_POS_MATCH_OR_ZV
:
9035 case MOVE_NEWLINE_OR_CR
:
9036 set_iterator_to_next (it
, 1);
9037 it
->continuation_lines_width
= 0;
9040 case MOVE_LINE_TRUNCATED
:
9041 it
->continuation_lines_width
= 0;
9042 reseat_at_next_visible_line_start (it
, 0);
9043 if ((op
& MOVE_TO_POS
) != 0
9044 && IT_CHARPOS (*it
) > to_charpos
)
9051 case MOVE_LINE_CONTINUED
:
9052 /* For continued lines ending in a tab, some of the glyphs
9053 associated with the tab are displayed on the current
9054 line. Since it->current_x does not include these glyphs,
9055 we use it->last_visible_x instead. */
9058 it
->continuation_lines_width
+= it
->last_visible_x
;
9059 /* When moving by vpos, ensure that the iterator really
9060 advances to the next line (bug#847, bug#969). Fixme:
9061 do we need to do this in other circumstances? */
9062 if (it
->current_x
!= it
->last_visible_x
9063 && (op
& MOVE_TO_VPOS
)
9064 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9066 line_start_x
= it
->current_x
+ it
->pixel_width
9067 - it
->last_visible_x
;
9068 set_iterator_to_next (it
, 0);
9072 it
->continuation_lines_width
+= it
->current_x
;
9079 /* Reset/increment for the next run. */
9080 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9081 it
->current_x
= line_start_x
;
9084 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9086 last_height
= it
->max_ascent
+ it
->max_descent
;
9087 it
->max_ascent
= it
->max_descent
= 0;
9092 /* On text terminals, we may stop at the end of a line in the middle
9093 of a multi-character glyph. If the glyph itself is continued,
9094 i.e. it is actually displayed on the next line, don't treat this
9095 stopping point as valid; move to the next line instead (unless
9096 that brings us offscreen). */
9097 if (!FRAME_WINDOW_P (it
->f
)
9099 && IT_CHARPOS (*it
) == to_charpos
9100 && it
->what
== IT_CHARACTER
9102 && it
->line_wrap
== WINDOW_WRAP
9103 && it
->current_x
== it
->last_visible_x
- 1
9106 && it
->vpos
< it
->w
->window_end_vpos
)
9108 it
->continuation_lines_width
+= it
->current_x
;
9109 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9110 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9112 last_height
= it
->max_ascent
+ it
->max_descent
;
9116 bidi_unshelve_cache (backup_data
, 1);
9118 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9122 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9124 If DY > 0, move IT backward at least that many pixels. DY = 0
9125 means move IT backward to the preceding line start or BEGV. This
9126 function may move over more than DY pixels if IT->current_y - DY
9127 ends up in the middle of a line; in this case IT->current_y will be
9128 set to the top of the line moved to. */
9131 move_it_vertically_backward (struct it
*it
, int dy
)
9135 void *it2data
= NULL
, *it3data
= NULL
;
9136 ptrdiff_t start_pos
;
9138 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9139 ptrdiff_t pos_limit
;
9144 start_pos
= IT_CHARPOS (*it
);
9146 /* Estimate how many newlines we must move back. */
9147 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9148 if (it
->line_wrap
== TRUNCATE
)
9151 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9153 /* Set the iterator's position that many lines back. But don't go
9154 back more than NLINES full screen lines -- this wins a day with
9155 buffers which have very long lines. */
9156 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9157 back_to_previous_visible_line_start (it
);
9159 /* Reseat the iterator here. When moving backward, we don't want
9160 reseat to skip forward over invisible text, set up the iterator
9161 to deliver from overlay strings at the new position etc. So,
9162 use reseat_1 here. */
9163 reseat_1 (it
, it
->current
.pos
, 1);
9165 /* We are now surely at a line start. */
9166 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9167 reordering is in effect. */
9168 it
->continuation_lines_width
= 0;
9170 /* Move forward and see what y-distance we moved. First move to the
9171 start of the next line so that we get its height. We need this
9172 height to be able to tell whether we reached the specified
9174 SAVE_IT (it2
, *it
, it2data
);
9175 it2
.max_ascent
= it2
.max_descent
= 0;
9178 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9179 MOVE_TO_POS
| MOVE_TO_VPOS
);
9181 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9182 /* If we are in a display string which starts at START_POS,
9183 and that display string includes a newline, and we are
9184 right after that newline (i.e. at the beginning of a
9185 display line), exit the loop, because otherwise we will
9186 infloop, since move_it_to will see that it is already at
9187 START_POS and will not move. */
9188 || (it2
.method
== GET_FROM_STRING
9189 && IT_CHARPOS (it2
) == start_pos
9190 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9191 eassert (IT_CHARPOS (*it
) >= BEGV
);
9192 SAVE_IT (it3
, it2
, it3data
);
9194 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9195 eassert (IT_CHARPOS (*it
) >= BEGV
);
9196 /* H is the actual vertical distance from the position in *IT
9197 and the starting position. */
9198 h
= it2
.current_y
- it
->current_y
;
9199 /* NLINES is the distance in number of lines. */
9200 nlines
= it2
.vpos
- it
->vpos
;
9202 /* Correct IT's y and vpos position
9203 so that they are relative to the starting point. */
9209 /* DY == 0 means move to the start of the screen line. The
9210 value of nlines is > 0 if continuation lines were involved,
9211 or if the original IT position was at start of a line. */
9212 RESTORE_IT (it
, it
, it2data
);
9214 move_it_by_lines (it
, nlines
);
9215 /* The above code moves us to some position NLINES down,
9216 usually to its first glyph (leftmost in an L2R line), but
9217 that's not necessarily the start of the line, under bidi
9218 reordering. We want to get to the character position
9219 that is immediately after the newline of the previous
9222 && !it
->continuation_lines_width
9223 && !STRINGP (it
->string
)
9224 && IT_CHARPOS (*it
) > BEGV
9225 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9227 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9230 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9231 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9233 bidi_unshelve_cache (it3data
, 1);
9237 /* The y-position we try to reach, relative to *IT.
9238 Note that H has been subtracted in front of the if-statement. */
9239 int target_y
= it
->current_y
+ h
- dy
;
9240 int y0
= it3
.current_y
;
9244 RESTORE_IT (&it3
, &it3
, it3data
);
9245 y1
= line_bottom_y (&it3
);
9246 line_height
= y1
- y0
;
9247 RESTORE_IT (it
, it
, it2data
);
9248 /* If we did not reach target_y, try to move further backward if
9249 we can. If we moved too far backward, try to move forward. */
9250 if (target_y
< it
->current_y
9251 /* This is heuristic. In a window that's 3 lines high, with
9252 a line height of 13 pixels each, recentering with point
9253 on the bottom line will try to move -39/2 = 19 pixels
9254 backward. Try to avoid moving into the first line. */
9255 && (it
->current_y
- target_y
9256 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9257 && IT_CHARPOS (*it
) > BEGV
)
9259 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9260 target_y
- it
->current_y
));
9261 dy
= it
->current_y
- target_y
;
9262 goto move_further_back
;
9264 else if (target_y
>= it
->current_y
+ line_height
9265 && IT_CHARPOS (*it
) < ZV
)
9267 /* Should move forward by at least one line, maybe more.
9269 Note: Calling move_it_by_lines can be expensive on
9270 terminal frames, where compute_motion is used (via
9271 vmotion) to do the job, when there are very long lines
9272 and truncate-lines is nil. That's the reason for
9273 treating terminal frames specially here. */
9275 if (!FRAME_WINDOW_P (it
->f
))
9276 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9281 move_it_by_lines (it
, 1);
9283 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9290 /* Move IT by a specified amount of pixel lines DY. DY negative means
9291 move backwards. DY = 0 means move to start of screen line. At the
9292 end, IT will be on the start of a screen line. */
9295 move_it_vertically (struct it
*it
, int dy
)
9298 move_it_vertically_backward (it
, -dy
);
9301 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9302 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9303 MOVE_TO_POS
| MOVE_TO_Y
);
9304 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9306 /* If buffer ends in ZV without a newline, move to the start of
9307 the line to satisfy the post-condition. */
9308 if (IT_CHARPOS (*it
) == ZV
9310 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9311 move_it_by_lines (it
, 0);
9316 /* Move iterator IT past the end of the text line it is in. */
9319 move_it_past_eol (struct it
*it
)
9321 enum move_it_result rc
;
9323 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9324 if (rc
== MOVE_NEWLINE_OR_CR
)
9325 set_iterator_to_next (it
, 0);
9329 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9330 negative means move up. DVPOS == 0 means move to the start of the
9333 Optimization idea: If we would know that IT->f doesn't use
9334 a face with proportional font, we could be faster for
9335 truncate-lines nil. */
9338 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9341 /* The commented-out optimization uses vmotion on terminals. This
9342 gives bad results, because elements like it->what, on which
9343 callers such as pos_visible_p rely, aren't updated. */
9344 /* struct position pos;
9345 if (!FRAME_WINDOW_P (it->f))
9347 struct text_pos textpos;
9349 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9350 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9351 reseat (it, textpos, 1);
9352 it->vpos += pos.vpos;
9353 it->current_y += pos.vpos;
9359 /* DVPOS == 0 means move to the start of the screen line. */
9360 move_it_vertically_backward (it
, 0);
9361 /* Let next call to line_bottom_y calculate real line height */
9366 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9367 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9369 /* Only move to the next buffer position if we ended up in a
9370 string from display property, not in an overlay string
9371 (before-string or after-string). That is because the
9372 latter don't conceal the underlying buffer position, so
9373 we can ask to move the iterator to the exact position we
9374 are interested in. Note that, even if we are already at
9375 IT_CHARPOS (*it), the call below is not a no-op, as it
9376 will detect that we are at the end of the string, pop the
9377 iterator, and compute it->current_x and it->hpos
9379 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9380 -1, -1, -1, MOVE_TO_POS
);
9386 void *it2data
= NULL
;
9387 ptrdiff_t start_charpos
, i
;
9389 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9390 ptrdiff_t pos_limit
;
9392 /* Start at the beginning of the screen line containing IT's
9393 position. This may actually move vertically backwards,
9394 in case of overlays, so adjust dvpos accordingly. */
9396 move_it_vertically_backward (it
, 0);
9399 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9400 screen lines, and reseat the iterator there. */
9401 start_charpos
= IT_CHARPOS (*it
);
9402 if (it
->line_wrap
== TRUNCATE
)
9405 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9406 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9407 back_to_previous_visible_line_start (it
);
9408 reseat (it
, it
->current
.pos
, 1);
9410 /* Move further back if we end up in a string or an image. */
9411 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9413 /* First try to move to start of display line. */
9415 move_it_vertically_backward (it
, 0);
9417 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9419 /* If start of line is still in string or image,
9420 move further back. */
9421 back_to_previous_visible_line_start (it
);
9422 reseat (it
, it
->current
.pos
, 1);
9426 it
->current_x
= it
->hpos
= 0;
9428 /* Above call may have moved too far if continuation lines
9429 are involved. Scan forward and see if it did. */
9430 SAVE_IT (it2
, *it
, it2data
);
9431 it2
.vpos
= it2
.current_y
= 0;
9432 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9433 it
->vpos
-= it2
.vpos
;
9434 it
->current_y
-= it2
.current_y
;
9435 it
->current_x
= it
->hpos
= 0;
9437 /* If we moved too far back, move IT some lines forward. */
9438 if (it2
.vpos
> -dvpos
)
9440 int delta
= it2
.vpos
+ dvpos
;
9442 RESTORE_IT (&it2
, &it2
, it2data
);
9443 SAVE_IT (it2
, *it
, it2data
);
9444 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9445 /* Move back again if we got too far ahead. */
9446 if (IT_CHARPOS (*it
) >= start_charpos
)
9447 RESTORE_IT (it
, &it2
, it2data
);
9449 bidi_unshelve_cache (it2data
, 1);
9452 RESTORE_IT (it
, it
, it2data
);
9456 /* Return 1 if IT points into the middle of a display vector. */
9459 in_display_vector_p (struct it
*it
)
9461 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9462 && it
->current
.dpvec_index
> 0
9463 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9467 /***********************************************************************
9469 ***********************************************************************/
9472 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9476 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9478 Lisp_Object args
[3];
9479 Lisp_Object msg
, fmt
;
9482 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9486 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9488 args
[0] = fmt
= build_string (format
);
9491 msg
= Fformat (3, args
);
9493 len
= SBYTES (msg
) + 1;
9494 buffer
= SAFE_ALLOCA (len
);
9495 memcpy (buffer
, SDATA (msg
), len
);
9497 message_dolog (buffer
, len
- 1, 1, 0);
9504 /* Output a newline in the *Messages* buffer if "needs" one. */
9507 message_log_maybe_newline (void)
9509 if (message_log_need_newline
)
9510 message_dolog ("", 0, 1, 0);
9514 /* Add a string M of length NBYTES to the message log, optionally
9515 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9516 true, means interpret the contents of M as multibyte. This
9517 function calls low-level routines in order to bypass text property
9518 hooks, etc. which might not be safe to run.
9520 This may GC (insert may run before/after change hooks),
9521 so the buffer M must NOT point to a Lisp string. */
9524 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9526 const unsigned char *msg
= (const unsigned char *) m
;
9528 if (!NILP (Vmemory_full
))
9531 if (!NILP (Vmessage_log_max
))
9533 struct buffer
*oldbuf
;
9534 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9535 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9536 ptrdiff_t point_at_end
= 0;
9537 ptrdiff_t zv_at_end
= 0;
9538 Lisp_Object old_deactivate_mark
;
9540 struct gcpro gcpro1
;
9542 old_deactivate_mark
= Vdeactivate_mark
;
9543 oldbuf
= current_buffer
;
9544 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9545 bset_undo_list (current_buffer
, Qt
);
9547 oldpoint
= message_dolog_marker1
;
9548 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9549 oldbegv
= message_dolog_marker2
;
9550 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9551 oldzv
= message_dolog_marker3
;
9552 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9553 GCPRO1 (old_deactivate_mark
);
9561 BEGV_BYTE
= BEG_BYTE
;
9564 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9566 /* Insert the string--maybe converting multibyte to single byte
9567 or vice versa, so that all the text fits the buffer. */
9569 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9575 /* Convert a multibyte string to single-byte
9576 for the *Message* buffer. */
9577 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9579 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9580 work
[0] = (ASCII_CHAR_P (c
)
9582 : multibyte_char_to_unibyte (c
));
9583 insert_1_both (work
, 1, 1, 1, 0, 0);
9586 else if (! multibyte
9587 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9591 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9592 /* Convert a single-byte string to multibyte
9593 for the *Message* buffer. */
9594 for (i
= 0; i
< nbytes
; i
++)
9597 MAKE_CHAR_MULTIBYTE (c
);
9598 char_bytes
= CHAR_STRING (c
, str
);
9599 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9603 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9607 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9610 insert_1_both ("\n", 1, 1, 1, 0, 0);
9612 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9614 this_bol_byte
= PT_BYTE
;
9616 /* See if this line duplicates the previous one.
9617 If so, combine duplicates. */
9620 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9622 prev_bol_byte
= PT_BYTE
;
9624 dups
= message_log_check_duplicate (prev_bol_byte
,
9628 del_range_both (prev_bol
, prev_bol_byte
,
9629 this_bol
, this_bol_byte
, 0);
9632 char dupstr
[sizeof " [ times]"
9633 + INT_STRLEN_BOUND (printmax_t
)];
9635 /* If you change this format, don't forget to also
9636 change message_log_check_duplicate. */
9637 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9638 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9639 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9644 /* If we have more than the desired maximum number of lines
9645 in the *Messages* buffer now, delete the oldest ones.
9646 This is safe because we don't have undo in this buffer. */
9648 if (NATNUMP (Vmessage_log_max
))
9650 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9651 -XFASTINT (Vmessage_log_max
) - 1, 0);
9652 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9655 BEGV
= marker_position (oldbegv
);
9656 BEGV_BYTE
= marker_byte_position (oldbegv
);
9665 ZV
= marker_position (oldzv
);
9666 ZV_BYTE
= marker_byte_position (oldzv
);
9670 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9672 /* We can't do Fgoto_char (oldpoint) because it will run some
9674 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9675 marker_byte_position (oldpoint
));
9678 unchain_marker (XMARKER (oldpoint
));
9679 unchain_marker (XMARKER (oldbegv
));
9680 unchain_marker (XMARKER (oldzv
));
9682 shown
= buffer_window_count (current_buffer
) > 0;
9683 set_buffer_internal (oldbuf
);
9684 /* We called insert_1_both above with its 5th argument (PREPARE)
9685 zero, which prevents insert_1_both from calling
9686 prepare_to_modify_buffer, which in turns prevents us from
9687 incrementing windows_or_buffers_changed even if *Messages* is
9688 shown in some window. So we must manually incrementing
9689 windows_or_buffers_changed here to make up for that. */
9691 windows_or_buffers_changed
++;
9693 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9694 message_log_need_newline
= !nlflag
;
9695 Vdeactivate_mark
= old_deactivate_mark
;
9700 /* We are at the end of the buffer after just having inserted a newline.
9701 (Note: We depend on the fact we won't be crossing the gap.)
9702 Check to see if the most recent message looks a lot like the previous one.
9703 Return 0 if different, 1 if the new one should just replace it, or a
9704 value N > 1 if we should also append " [N times]". */
9707 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9710 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9712 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9713 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9715 for (i
= 0; i
< len
; i
++)
9717 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9725 if (*p1
++ == ' ' && *p1
++ == '[')
9728 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9729 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9736 /* Display an echo area message M with a specified length of NBYTES
9737 bytes. The string may include null characters. If M is not a
9738 string, clear out any existing message, and let the mini-buffer
9741 This function cancels echoing. */
9744 message3 (Lisp_Object m
)
9746 struct gcpro gcpro1
;
9749 clear_message (1,1);
9752 /* First flush out any partial line written with print. */
9753 message_log_maybe_newline ();
9756 ptrdiff_t nbytes
= SBYTES (m
);
9757 bool multibyte
= STRING_MULTIBYTE (m
);
9759 char *buffer
= SAFE_ALLOCA (nbytes
);
9760 memcpy (buffer
, SDATA (m
), nbytes
);
9761 message_dolog (buffer
, nbytes
, 1, multibyte
);
9770 /* The non-logging version of message3.
9771 This does not cancel echoing, because it is used for echoing.
9772 Perhaps we need to make a separate function for echoing
9773 and make this cancel echoing. */
9776 message3_nolog (Lisp_Object m
)
9778 struct frame
*sf
= SELECTED_FRAME ();
9780 if (FRAME_INITIAL_P (sf
))
9782 if (noninteractive_need_newline
)
9783 putc ('\n', stderr
);
9784 noninteractive_need_newline
= 0;
9786 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9787 if (cursor_in_echo_area
== 0)
9788 fprintf (stderr
, "\n");
9791 /* Error messages get reported properly by cmd_error, so this must be just an
9792 informative message; if the frame hasn't really been initialized yet, just
9794 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9796 /* Get the frame containing the mini-buffer
9797 that the selected frame is using. */
9798 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9799 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9800 struct frame
*f
= XFRAME (frame
);
9802 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9803 Fmake_frame_visible (frame
);
9805 if (STRINGP (m
) && SCHARS (m
) > 0)
9808 if (minibuffer_auto_raise
)
9809 Fraise_frame (frame
);
9810 /* Assume we are not echoing.
9811 (If we are, echo_now will override this.) */
9812 echo_message_buffer
= Qnil
;
9815 clear_message (1, 1);
9817 do_pending_window_change (0);
9818 echo_area_display (1);
9819 do_pending_window_change (0);
9820 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9821 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9826 /* Display a null-terminated echo area message M. If M is 0, clear
9827 out any existing message, and let the mini-buffer text show through.
9829 The buffer M must continue to exist until after the echo area gets
9830 cleared or some other message gets displayed there. Do not pass
9831 text that is stored in a Lisp string. Do not pass text in a buffer
9832 that was alloca'd. */
9835 message1 (const char *m
)
9837 message3 (m
? build_unibyte_string (m
) : Qnil
);
9841 /* The non-logging counterpart of message1. */
9844 message1_nolog (const char *m
)
9846 message3_nolog (m
? build_unibyte_string (m
) : Qnil
);
9849 /* Display a message M which contains a single %s
9850 which gets replaced with STRING. */
9853 message_with_string (const char *m
, Lisp_Object string
, int log
)
9855 CHECK_STRING (string
);
9861 if (noninteractive_need_newline
)
9862 putc ('\n', stderr
);
9863 noninteractive_need_newline
= 0;
9864 fprintf (stderr
, m
, SDATA (string
));
9865 if (!cursor_in_echo_area
)
9866 fprintf (stderr
, "\n");
9870 else if (INTERACTIVE
)
9872 /* The frame whose minibuffer we're going to display the message on.
9873 It may be larger than the selected frame, so we need
9874 to use its buffer, not the selected frame's buffer. */
9875 Lisp_Object mini_window
;
9876 struct frame
*f
, *sf
= SELECTED_FRAME ();
9878 /* Get the frame containing the minibuffer
9879 that the selected frame is using. */
9880 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9881 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9883 /* Error messages get reported properly by cmd_error, so this must be
9884 just an informative message; if the frame hasn't really been
9885 initialized yet, just toss it. */
9886 if (f
->glyphs_initialized_p
)
9888 Lisp_Object args
[2], msg
;
9889 struct gcpro gcpro1
, gcpro2
;
9891 args
[0] = build_string (m
);
9892 args
[1] = msg
= string
;
9893 GCPRO2 (args
[0], msg
);
9896 msg
= Fformat (2, args
);
9901 message3_nolog (msg
);
9905 /* Print should start at the beginning of the message
9906 buffer next time. */
9907 message_buf_print
= 0;
9913 /* Dump an informative message to the minibuf. If M is 0, clear out
9914 any existing message, and let the mini-buffer text show through. */
9917 vmessage (const char *m
, va_list ap
)
9923 if (noninteractive_need_newline
)
9924 putc ('\n', stderr
);
9925 noninteractive_need_newline
= 0;
9926 vfprintf (stderr
, m
, ap
);
9927 if (cursor_in_echo_area
== 0)
9928 fprintf (stderr
, "\n");
9932 else if (INTERACTIVE
)
9934 /* The frame whose mini-buffer we're going to display the message
9935 on. It may be larger than the selected frame, so we need to
9936 use its buffer, not the selected frame's buffer. */
9937 Lisp_Object mini_window
;
9938 struct frame
*f
, *sf
= SELECTED_FRAME ();
9940 /* Get the frame containing the mini-buffer
9941 that the selected frame is using. */
9942 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9943 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9945 /* Error messages get reported properly by cmd_error, so this must be
9946 just an informative message; if the frame hasn't really been
9947 initialized yet, just toss it. */
9948 if (f
->glyphs_initialized_p
)
9953 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9954 char *message_buf
= alloca (maxsize
+ 1);
9956 len
= doprnt (message_buf
, maxsize
, m
, 0, ap
);
9958 message3 (make_string (message_buf
, len
));
9963 /* Print should start at the beginning of the message
9964 buffer next time. */
9965 message_buf_print
= 0;
9971 message (const char *m
, ...)
9981 /* The non-logging version of message. */
9984 message_nolog (const char *m
, ...)
9986 Lisp_Object old_log_max
;
9989 old_log_max
= Vmessage_log_max
;
9990 Vmessage_log_max
= Qnil
;
9992 Vmessage_log_max
= old_log_max
;
9998 /* Display the current message in the current mini-buffer. This is
9999 only called from error handlers in process.c, and is not time
10003 update_echo_area (void)
10005 if (!NILP (echo_area_buffer
[0]))
10007 Lisp_Object string
;
10008 string
= Fcurrent_message ();
10014 /* Make sure echo area buffers in `echo_buffers' are live.
10015 If they aren't, make new ones. */
10018 ensure_echo_area_buffers (void)
10022 for (i
= 0; i
< 2; ++i
)
10023 if (!BUFFERP (echo_buffer
[i
])
10024 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
10027 Lisp_Object old_buffer
;
10030 old_buffer
= echo_buffer
[i
];
10031 echo_buffer
[i
] = Fget_buffer_create
10032 (make_formatted_string (name
, " *Echo Area %d*", i
));
10033 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
10034 /* to force word wrap in echo area -
10035 it was decided to postpone this*/
10036 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
10038 for (j
= 0; j
< 2; ++j
)
10039 if (EQ (old_buffer
, echo_area_buffer
[j
]))
10040 echo_area_buffer
[j
] = echo_buffer
[i
];
10045 /* Call FN with args A1..A2 with either the current or last displayed
10046 echo_area_buffer as current buffer.
10048 WHICH zero means use the current message buffer
10049 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10050 from echo_buffer[] and clear it.
10052 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10053 suitable buffer from echo_buffer[] and clear it.
10055 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10056 that the current message becomes the last displayed one, make
10057 choose a suitable buffer for echo_area_buffer[0], and clear it.
10059 Value is what FN returns. */
10062 with_echo_area_buffer (struct window
*w
, int which
,
10063 int (*fn
) (ptrdiff_t, Lisp_Object
),
10064 ptrdiff_t a1
, Lisp_Object a2
)
10066 Lisp_Object buffer
;
10067 int this_one
, the_other
, clear_buffer_p
, rc
;
10068 ptrdiff_t count
= SPECPDL_INDEX ();
10070 /* If buffers aren't live, make new ones. */
10071 ensure_echo_area_buffers ();
10073 clear_buffer_p
= 0;
10076 this_one
= 0, the_other
= 1;
10077 else if (which
> 0)
10078 this_one
= 1, the_other
= 0;
10081 this_one
= 0, the_other
= 1;
10082 clear_buffer_p
= 1;
10084 /* We need a fresh one in case the current echo buffer equals
10085 the one containing the last displayed echo area message. */
10086 if (!NILP (echo_area_buffer
[this_one
])
10087 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10088 echo_area_buffer
[this_one
] = Qnil
;
10091 /* Choose a suitable buffer from echo_buffer[] is we don't
10093 if (NILP (echo_area_buffer
[this_one
]))
10095 echo_area_buffer
[this_one
]
10096 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10097 ? echo_buffer
[the_other
]
10098 : echo_buffer
[this_one
]);
10099 clear_buffer_p
= 1;
10102 buffer
= echo_area_buffer
[this_one
];
10104 /* Don't get confused by reusing the buffer used for echoing
10105 for a different purpose. */
10106 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10109 record_unwind_protect (unwind_with_echo_area_buffer
,
10110 with_echo_area_buffer_unwind_data (w
));
10112 /* Make the echo area buffer current. Note that for display
10113 purposes, it is not necessary that the displayed window's buffer
10114 == current_buffer, except for text property lookup. So, let's
10115 only set that buffer temporarily here without doing a full
10116 Fset_window_buffer. We must also change w->pointm, though,
10117 because otherwise an assertions in unshow_buffer fails, and Emacs
10119 set_buffer_internal_1 (XBUFFER (buffer
));
10122 wset_buffer (w
, buffer
);
10123 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10126 bset_undo_list (current_buffer
, Qt
);
10127 bset_read_only (current_buffer
, Qnil
);
10128 specbind (Qinhibit_read_only
, Qt
);
10129 specbind (Qinhibit_modification_hooks
, Qt
);
10131 if (clear_buffer_p
&& Z
> BEG
)
10132 del_range (BEG
, Z
);
10134 eassert (BEGV
>= BEG
);
10135 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10139 eassert (BEGV
>= BEG
);
10140 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10142 unbind_to (count
, Qnil
);
10147 /* Save state that should be preserved around the call to the function
10148 FN called in with_echo_area_buffer. */
10151 with_echo_area_buffer_unwind_data (struct window
*w
)
10154 Lisp_Object vector
, tmp
;
10156 /* Reduce consing by keeping one vector in
10157 Vwith_echo_area_save_vector. */
10158 vector
= Vwith_echo_area_save_vector
;
10159 Vwith_echo_area_save_vector
= Qnil
;
10162 vector
= Fmake_vector (make_number (9), Qnil
);
10164 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10165 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10166 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10170 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10171 ASET (vector
, i
, w
->contents
); ++i
;
10172 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10173 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10174 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10175 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10180 for (; i
< end
; ++i
)
10181 ASET (vector
, i
, Qnil
);
10184 eassert (i
== ASIZE (vector
));
10189 /* Restore global state from VECTOR which was created by
10190 with_echo_area_buffer_unwind_data. */
10193 unwind_with_echo_area_buffer (Lisp_Object vector
)
10195 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10196 Vdeactivate_mark
= AREF (vector
, 1);
10197 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10199 if (WINDOWP (AREF (vector
, 3)))
10202 Lisp_Object buffer
;
10204 w
= XWINDOW (AREF (vector
, 3));
10205 buffer
= AREF (vector
, 4);
10207 wset_buffer (w
, buffer
);
10208 set_marker_both (w
->pointm
, buffer
,
10209 XFASTINT (AREF (vector
, 5)),
10210 XFASTINT (AREF (vector
, 6)));
10211 set_marker_both (w
->start
, buffer
,
10212 XFASTINT (AREF (vector
, 7)),
10213 XFASTINT (AREF (vector
, 8)));
10216 Vwith_echo_area_save_vector
= vector
;
10220 /* Set up the echo area for use by print functions. MULTIBYTE_P
10221 non-zero means we will print multibyte. */
10224 setup_echo_area_for_printing (int multibyte_p
)
10226 /* If we can't find an echo area any more, exit. */
10227 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10228 Fkill_emacs (Qnil
);
10230 ensure_echo_area_buffers ();
10232 if (!message_buf_print
)
10234 /* A message has been output since the last time we printed.
10235 Choose a fresh echo area buffer. */
10236 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10237 echo_area_buffer
[0] = echo_buffer
[1];
10239 echo_area_buffer
[0] = echo_buffer
[0];
10241 /* Switch to that buffer and clear it. */
10242 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10243 bset_truncate_lines (current_buffer
, Qnil
);
10247 ptrdiff_t count
= SPECPDL_INDEX ();
10248 specbind (Qinhibit_read_only
, Qt
);
10249 /* Note that undo recording is always disabled. */
10250 del_range (BEG
, Z
);
10251 unbind_to (count
, Qnil
);
10253 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10255 /* Set up the buffer for the multibyteness we need. */
10257 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10258 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10260 /* Raise the frame containing the echo area. */
10261 if (minibuffer_auto_raise
)
10263 struct frame
*sf
= SELECTED_FRAME ();
10264 Lisp_Object mini_window
;
10265 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10266 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10269 message_log_maybe_newline ();
10270 message_buf_print
= 1;
10274 if (NILP (echo_area_buffer
[0]))
10276 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10277 echo_area_buffer
[0] = echo_buffer
[1];
10279 echo_area_buffer
[0] = echo_buffer
[0];
10282 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10284 /* Someone switched buffers between print requests. */
10285 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10286 bset_truncate_lines (current_buffer
, Qnil
);
10292 /* Display an echo area message in window W. Value is non-zero if W's
10293 height is changed. If display_last_displayed_message_p is
10294 non-zero, display the message that was last displayed, otherwise
10295 display the current message. */
10298 display_echo_area (struct window
*w
)
10300 int i
, no_message_p
, window_height_changed_p
;
10302 /* Temporarily disable garbage collections while displaying the echo
10303 area. This is done because a GC can print a message itself.
10304 That message would modify the echo area buffer's contents while a
10305 redisplay of the buffer is going on, and seriously confuse
10307 ptrdiff_t count
= inhibit_garbage_collection ();
10309 /* If there is no message, we must call display_echo_area_1
10310 nevertheless because it resizes the window. But we will have to
10311 reset the echo_area_buffer in question to nil at the end because
10312 with_echo_area_buffer will sets it to an empty buffer. */
10313 i
= display_last_displayed_message_p
? 1 : 0;
10314 no_message_p
= NILP (echo_area_buffer
[i
]);
10316 window_height_changed_p
10317 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10318 display_echo_area_1
,
10319 (intptr_t) w
, Qnil
);
10322 echo_area_buffer
[i
] = Qnil
;
10324 unbind_to (count
, Qnil
);
10325 return window_height_changed_p
;
10329 /* Helper for display_echo_area. Display the current buffer which
10330 contains the current echo area message in window W, a mini-window,
10331 a pointer to which is passed in A1. A2..A4 are currently not used.
10332 Change the height of W so that all of the message is displayed.
10333 Value is non-zero if height of W was changed. */
10336 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10339 struct window
*w
= (struct window
*) i1
;
10340 Lisp_Object window
;
10341 struct text_pos start
;
10342 int window_height_changed_p
= 0;
10344 /* Do this before displaying, so that we have a large enough glyph
10345 matrix for the display. If we can't get enough space for the
10346 whole text, display the last N lines. That works by setting w->start. */
10347 window_height_changed_p
= resize_mini_window (w
, 0);
10349 /* Use the starting position chosen by resize_mini_window. */
10350 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10353 clear_glyph_matrix (w
->desired_matrix
);
10354 XSETWINDOW (window
, w
);
10355 try_window (window
, start
, 0);
10357 return window_height_changed_p
;
10361 /* Resize the echo area window to exactly the size needed for the
10362 currently displayed message, if there is one. If a mini-buffer
10363 is active, don't shrink it. */
10366 resize_echo_area_exactly (void)
10368 if (BUFFERP (echo_area_buffer
[0])
10369 && WINDOWP (echo_area_window
))
10371 struct window
*w
= XWINDOW (echo_area_window
);
10373 Lisp_Object resize_exactly
;
10375 if (minibuf_level
== 0)
10376 resize_exactly
= Qt
;
10378 resize_exactly
= Qnil
;
10380 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10381 (intptr_t) w
, resize_exactly
);
10384 ++windows_or_buffers_changed
;
10385 ++update_mode_lines
;
10386 redisplay_internal ();
10392 /* Callback function for with_echo_area_buffer, when used from
10393 resize_echo_area_exactly. A1 contains a pointer to the window to
10394 resize, EXACTLY non-nil means resize the mini-window exactly to the
10395 size of the text displayed. A3 and A4 are not used. Value is what
10396 resize_mini_window returns. */
10399 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10402 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10406 /* Resize mini-window W to fit the size of its contents. EXACT_P
10407 means size the window exactly to the size needed. Otherwise, it's
10408 only enlarged until W's buffer is empty.
10410 Set W->start to the right place to begin display. If the whole
10411 contents fit, start at the beginning. Otherwise, start so as
10412 to make the end of the contents appear. This is particularly
10413 important for y-or-n-p, but seems desirable generally.
10415 Value is non-zero if the window height has been changed. */
10418 resize_mini_window (struct window
*w
, int exact_p
)
10420 struct frame
*f
= XFRAME (w
->frame
);
10421 int window_height_changed_p
= 0;
10423 eassert (MINI_WINDOW_P (w
));
10425 /* By default, start display at the beginning. */
10426 set_marker_both (w
->start
, w
->contents
,
10427 BUF_BEGV (XBUFFER (w
->contents
)),
10428 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10430 /* Don't resize windows while redisplaying a window; it would
10431 confuse redisplay functions when the size of the window they are
10432 displaying changes from under them. Such a resizing can happen,
10433 for instance, when which-func prints a long message while
10434 we are running fontification-functions. We're running these
10435 functions with safe_call which binds inhibit-redisplay to t. */
10436 if (!NILP (Vinhibit_redisplay
))
10439 /* Nil means don't try to resize. */
10440 if (NILP (Vresize_mini_windows
)
10441 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10444 if (!FRAME_MINIBUF_ONLY_P (f
))
10447 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10448 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10450 EMACS_INT max_height
;
10451 int unit
= FRAME_LINE_HEIGHT (f
);
10452 struct text_pos start
;
10453 struct buffer
*old_current_buffer
= NULL
;
10455 if (current_buffer
!= XBUFFER (w
->contents
))
10457 old_current_buffer
= current_buffer
;
10458 set_buffer_internal (XBUFFER (w
->contents
));
10461 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10463 /* Compute the max. number of lines specified by the user. */
10464 if (FLOATP (Vmax_mini_window_height
))
10465 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10466 else if (INTEGERP (Vmax_mini_window_height
))
10467 max_height
= XINT (Vmax_mini_window_height
);
10469 max_height
= total_height
/ 4;
10471 /* Correct that max. height if it's bogus. */
10472 max_height
= clip_to_bounds (1, max_height
, total_height
);
10474 /* Find out the height of the text in the window. */
10475 if (it
.line_wrap
== TRUNCATE
)
10480 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10481 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10482 height
= it
.current_y
+ last_height
;
10484 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10485 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10486 height
= (height
+ unit
- 1) / unit
;
10489 /* Compute a suitable window start. */
10490 if (height
> max_height
)
10492 height
= max_height
;
10493 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10494 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10495 start
= it
.current
.pos
;
10498 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10499 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10501 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10503 /* Let it grow only, until we display an empty message, in which
10504 case the window shrinks again. */
10505 if (height
> WINDOW_TOTAL_LINES (w
))
10507 int old_height
= WINDOW_TOTAL_LINES (w
);
10509 FRAME_WINDOWS_FROZEN (f
) = 1;
10510 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10511 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10513 else if (height
< WINDOW_TOTAL_LINES (w
)
10514 && (exact_p
|| BEGV
== ZV
))
10516 int old_height
= WINDOW_TOTAL_LINES (w
);
10518 FRAME_WINDOWS_FROZEN (f
) = 0;
10519 shrink_mini_window (w
);
10520 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10525 /* Always resize to exact size needed. */
10526 if (height
> WINDOW_TOTAL_LINES (w
))
10528 int old_height
= WINDOW_TOTAL_LINES (w
);
10530 FRAME_WINDOWS_FROZEN (f
) = 1;
10531 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10532 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10534 else if (height
< WINDOW_TOTAL_LINES (w
))
10536 int old_height
= WINDOW_TOTAL_LINES (w
);
10538 FRAME_WINDOWS_FROZEN (f
) = 0;
10539 shrink_mini_window (w
);
10543 FRAME_WINDOWS_FROZEN (f
) = 1;
10544 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10547 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10551 if (old_current_buffer
)
10552 set_buffer_internal (old_current_buffer
);
10555 return window_height_changed_p
;
10559 /* Value is the current message, a string, or nil if there is no
10560 current message. */
10563 current_message (void)
10567 if (!BUFFERP (echo_area_buffer
[0]))
10571 with_echo_area_buffer (0, 0, current_message_1
,
10572 (intptr_t) &msg
, Qnil
);
10574 echo_area_buffer
[0] = Qnil
;
10582 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10585 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10588 *msg
= make_buffer_string (BEG
, Z
, 1);
10595 /* Push the current message on Vmessage_stack for later restoration
10596 by restore_message. Value is non-zero if the current message isn't
10597 empty. This is a relatively infrequent operation, so it's not
10598 worth optimizing. */
10601 push_message (void)
10603 Lisp_Object msg
= current_message ();
10604 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10605 return STRINGP (msg
);
10609 /* Restore message display from the top of Vmessage_stack. */
10612 restore_message (void)
10614 eassert (CONSP (Vmessage_stack
));
10615 message3_nolog (XCAR (Vmessage_stack
));
10619 /* Handler for unwind-protect calling pop_message. */
10622 pop_message_unwind (void)
10624 /* Pop the top-most entry off Vmessage_stack. */
10625 eassert (CONSP (Vmessage_stack
));
10626 Vmessage_stack
= XCDR (Vmessage_stack
);
10630 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10631 exits. If the stack is not empty, we have a missing pop_message
10635 check_message_stack (void)
10637 if (!NILP (Vmessage_stack
))
10642 /* Truncate to NCHARS what will be displayed in the echo area the next
10643 time we display it---but don't redisplay it now. */
10646 truncate_echo_area (ptrdiff_t nchars
)
10649 echo_area_buffer
[0] = Qnil
;
10650 else if (!noninteractive
10652 && !NILP (echo_area_buffer
[0]))
10654 struct frame
*sf
= SELECTED_FRAME ();
10655 /* Error messages get reported properly by cmd_error, so this must be
10656 just an informative message; if the frame hasn't really been
10657 initialized yet, just toss it. */
10658 if (sf
->glyphs_initialized_p
)
10659 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10664 /* Helper function for truncate_echo_area. Truncate the current
10665 message to at most NCHARS characters. */
10668 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10670 if (BEG
+ nchars
< Z
)
10671 del_range (BEG
+ nchars
, Z
);
10673 echo_area_buffer
[0] = Qnil
;
10677 /* Set the current message to STRING. */
10680 set_message (Lisp_Object string
)
10682 eassert (STRINGP (string
));
10684 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10686 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10687 message_buf_print
= 0;
10688 help_echo_showing_p
= 0;
10690 if (STRINGP (Vdebug_on_message
)
10691 && STRINGP (string
)
10692 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10693 call_debugger (list2 (Qerror
, string
));
10697 /* Helper function for set_message. First argument is ignored and second
10698 argument has the same meaning as for set_message.
10699 This function is called with the echo area buffer being current. */
10702 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10704 eassert (STRINGP (string
));
10706 /* Change multibyteness of the echo buffer appropriately. */
10707 if (message_enable_multibyte
10708 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10709 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10711 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10712 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10713 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10715 /* Insert new message at BEG. */
10716 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10718 /* This function takes care of single/multibyte conversion.
10719 We just have to ensure that the echo area buffer has the right
10720 setting of enable_multibyte_characters. */
10721 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10727 /* Clear messages. CURRENT_P non-zero means clear the current
10728 message. LAST_DISPLAYED_P non-zero means clear the message
10732 clear_message (int current_p
, int last_displayed_p
)
10736 echo_area_buffer
[0] = Qnil
;
10737 message_cleared_p
= 1;
10740 if (last_displayed_p
)
10741 echo_area_buffer
[1] = Qnil
;
10743 message_buf_print
= 0;
10746 /* Clear garbaged frames.
10748 This function is used where the old redisplay called
10749 redraw_garbaged_frames which in turn called redraw_frame which in
10750 turn called clear_frame. The call to clear_frame was a source of
10751 flickering. I believe a clear_frame is not necessary. It should
10752 suffice in the new redisplay to invalidate all current matrices,
10753 and ensure a complete redisplay of all windows. */
10756 clear_garbaged_frames (void)
10758 if (frame_garbaged
)
10760 Lisp_Object tail
, frame
;
10761 int changed_count
= 0;
10763 FOR_EACH_FRAME (tail
, frame
)
10765 struct frame
*f
= XFRAME (frame
);
10767 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10772 f
->force_flush_display_p
= 1;
10774 clear_current_matrices (f
);
10781 frame_garbaged
= 0;
10783 ++windows_or_buffers_changed
;
10788 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10789 is non-zero update selected_frame. Value is non-zero if the
10790 mini-windows height has been changed. */
10793 echo_area_display (int update_frame_p
)
10795 Lisp_Object mini_window
;
10798 int window_height_changed_p
= 0;
10799 struct frame
*sf
= SELECTED_FRAME ();
10801 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10802 w
= XWINDOW (mini_window
);
10803 f
= XFRAME (WINDOW_FRAME (w
));
10805 /* Don't display if frame is invisible or not yet initialized. */
10806 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10809 #ifdef HAVE_WINDOW_SYSTEM
10810 /* When Emacs starts, selected_frame may be the initial terminal
10811 frame. If we let this through, a message would be displayed on
10813 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10815 #endif /* HAVE_WINDOW_SYSTEM */
10817 /* Redraw garbaged frames. */
10818 clear_garbaged_frames ();
10820 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10822 echo_area_window
= mini_window
;
10823 window_height_changed_p
= display_echo_area (w
);
10824 w
->must_be_updated_p
= 1;
10826 /* Update the display, unless called from redisplay_internal.
10827 Also don't update the screen during redisplay itself. The
10828 update will happen at the end of redisplay, and an update
10829 here could cause confusion. */
10830 if (update_frame_p
&& !redisplaying_p
)
10834 /* If the display update has been interrupted by pending
10835 input, update mode lines in the frame. Due to the
10836 pending input, it might have been that redisplay hasn't
10837 been called, so that mode lines above the echo area are
10838 garbaged. This looks odd, so we prevent it here. */
10839 if (!display_completed
)
10840 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10842 if (window_height_changed_p
10843 /* Don't do this if Emacs is shutting down. Redisplay
10844 needs to run hooks. */
10845 && !NILP (Vrun_hooks
))
10847 /* Must update other windows. Likewise as in other
10848 cases, don't let this update be interrupted by
10850 ptrdiff_t count
= SPECPDL_INDEX ();
10851 specbind (Qredisplay_dont_pause
, Qt
);
10852 windows_or_buffers_changed
= 1;
10853 redisplay_internal ();
10854 unbind_to (count
, Qnil
);
10856 else if (FRAME_WINDOW_P (f
) && n
== 0)
10858 /* Window configuration is the same as before.
10859 Can do with a display update of the echo area,
10860 unless we displayed some mode lines. */
10861 update_single_window (w
, 1);
10865 update_frame (f
, 1, 1);
10867 /* If cursor is in the echo area, make sure that the next
10868 redisplay displays the minibuffer, so that the cursor will
10869 be replaced with what the minibuffer wants. */
10870 if (cursor_in_echo_area
)
10871 ++windows_or_buffers_changed
;
10874 else if (!EQ (mini_window
, selected_window
))
10875 windows_or_buffers_changed
++;
10877 /* Last displayed message is now the current message. */
10878 echo_area_buffer
[1] = echo_area_buffer
[0];
10879 /* Inform read_char that we're not echoing. */
10880 echo_message_buffer
= Qnil
;
10882 /* Prevent redisplay optimization in redisplay_internal by resetting
10883 this_line_start_pos. This is done because the mini-buffer now
10884 displays the message instead of its buffer text. */
10885 if (EQ (mini_window
, selected_window
))
10886 CHARPOS (this_line_start_pos
) = 0;
10888 return window_height_changed_p
;
10891 /* Nonzero if the current window's buffer is shown in more than one
10892 window and was modified since last redisplay. */
10895 buffer_shared_and_changed (void)
10897 return (buffer_window_count (current_buffer
) > 1
10898 && UNCHANGED_MODIFIED
< MODIFF
);
10901 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10902 is enabled and mark of W's buffer was changed since last W's update. */
10905 window_buffer_changed (struct window
*w
)
10907 struct buffer
*b
= XBUFFER (w
->contents
);
10909 eassert (BUFFER_LIVE_P (b
));
10911 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10912 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10913 != (w
->region_showing
!= 0)));
10916 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10919 mode_line_update_needed (struct window
*w
)
10921 return (w
->column_number_displayed
!= -1
10922 && !(PT
== w
->last_point
&& !window_outdated (w
))
10923 && (w
->column_number_displayed
!= current_column ()));
10926 /* Nonzero if window start of W is frozen and may not be changed during
10930 window_frozen_p (struct window
*w
)
10932 if (FRAME_WINDOWS_FROZEN (XFRAME (WINDOW_FRAME (w
))))
10934 Lisp_Object window
;
10936 XSETWINDOW (window
, w
);
10937 if (MINI_WINDOW_P (w
))
10939 else if (EQ (window
, selected_window
))
10941 else if (MINI_WINDOW_P (XWINDOW (selected_window
))
10942 && EQ (window
, Vminibuf_scroll_window
))
10943 /* This special window can't be frozen too. */
10951 /***********************************************************************
10952 Mode Lines and Frame Titles
10953 ***********************************************************************/
10955 /* A buffer for constructing non-propertized mode-line strings and
10956 frame titles in it; allocated from the heap in init_xdisp and
10957 resized as needed in store_mode_line_noprop_char. */
10959 static char *mode_line_noprop_buf
;
10961 /* The buffer's end, and a current output position in it. */
10963 static char *mode_line_noprop_buf_end
;
10964 static char *mode_line_noprop_ptr
;
10966 #define MODE_LINE_NOPROP_LEN(start) \
10967 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10970 MODE_LINE_DISPLAY
= 0,
10974 } mode_line_target
;
10976 /* Alist that caches the results of :propertize.
10977 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10978 static Lisp_Object mode_line_proptrans_alist
;
10980 /* List of strings making up the mode-line. */
10981 static Lisp_Object mode_line_string_list
;
10983 /* Base face property when building propertized mode line string. */
10984 static Lisp_Object mode_line_string_face
;
10985 static Lisp_Object mode_line_string_face_prop
;
10988 /* Unwind data for mode line strings */
10990 static Lisp_Object Vmode_line_unwind_vector
;
10993 format_mode_line_unwind_data (struct frame
*target_frame
,
10994 struct buffer
*obuf
,
10996 int save_proptrans
)
10998 Lisp_Object vector
, tmp
;
11000 /* Reduce consing by keeping one vector in
11001 Vwith_echo_area_save_vector. */
11002 vector
= Vmode_line_unwind_vector
;
11003 Vmode_line_unwind_vector
= Qnil
;
11006 vector
= Fmake_vector (make_number (10), Qnil
);
11008 ASET (vector
, 0, make_number (mode_line_target
));
11009 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
11010 ASET (vector
, 2, mode_line_string_list
);
11011 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
11012 ASET (vector
, 4, mode_line_string_face
);
11013 ASET (vector
, 5, mode_line_string_face_prop
);
11016 XSETBUFFER (tmp
, obuf
);
11019 ASET (vector
, 6, tmp
);
11020 ASET (vector
, 7, owin
);
11023 /* Similarly to `with-selected-window', if the operation selects
11024 a window on another frame, we must restore that frame's
11025 selected window, and (for a tty) the top-frame. */
11026 ASET (vector
, 8, target_frame
->selected_window
);
11027 if (FRAME_TERMCAP_P (target_frame
))
11028 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
11035 unwind_format_mode_line (Lisp_Object vector
)
11037 Lisp_Object old_window
= AREF (vector
, 7);
11038 Lisp_Object target_frame_window
= AREF (vector
, 8);
11039 Lisp_Object old_top_frame
= AREF (vector
, 9);
11041 mode_line_target
= XINT (AREF (vector
, 0));
11042 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
11043 mode_line_string_list
= AREF (vector
, 2);
11044 if (! EQ (AREF (vector
, 3), Qt
))
11045 mode_line_proptrans_alist
= AREF (vector
, 3);
11046 mode_line_string_face
= AREF (vector
, 4);
11047 mode_line_string_face_prop
= AREF (vector
, 5);
11049 /* Select window before buffer, since it may change the buffer. */
11050 if (!NILP (old_window
))
11052 /* If the operation that we are unwinding had selected a window
11053 on a different frame, reset its frame-selected-window. For a
11054 text terminal, reset its top-frame if necessary. */
11055 if (!NILP (target_frame_window
))
11058 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11060 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11061 Fselect_window (target_frame_window
, Qt
);
11063 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11064 Fselect_frame (old_top_frame
, Qt
);
11067 Fselect_window (old_window
, Qt
);
11070 if (!NILP (AREF (vector
, 6)))
11072 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11073 ASET (vector
, 6, Qnil
);
11076 Vmode_line_unwind_vector
= vector
;
11080 /* Store a single character C for the frame title in mode_line_noprop_buf.
11081 Re-allocate mode_line_noprop_buf if necessary. */
11084 store_mode_line_noprop_char (char c
)
11086 /* If output position has reached the end of the allocated buffer,
11087 increase the buffer's size. */
11088 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11090 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11091 ptrdiff_t size
= len
;
11092 mode_line_noprop_buf
=
11093 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11094 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11095 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11098 *mode_line_noprop_ptr
++ = c
;
11102 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11103 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11104 characters that yield more columns than PRECISION; PRECISION <= 0
11105 means copy the whole string. Pad with spaces until FIELD_WIDTH
11106 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11107 pad. Called from display_mode_element when it is used to build a
11111 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11113 const unsigned char *str
= (const unsigned char *) string
;
11115 ptrdiff_t dummy
, nbytes
;
11117 /* Copy at most PRECISION chars from STR. */
11118 nbytes
= strlen (string
);
11119 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11121 store_mode_line_noprop_char (*str
++);
11123 /* Fill up with spaces until FIELD_WIDTH reached. */
11124 while (field_width
> 0
11125 && n
< field_width
)
11127 store_mode_line_noprop_char (' ');
11134 /***********************************************************************
11136 ***********************************************************************/
11138 #ifdef HAVE_WINDOW_SYSTEM
11140 /* Set the title of FRAME, if it has changed. The title format is
11141 Vicon_title_format if FRAME is iconified, otherwise it is
11142 frame_title_format. */
11145 x_consider_frame_title (Lisp_Object frame
)
11147 struct frame
*f
= XFRAME (frame
);
11149 if (FRAME_WINDOW_P (f
)
11150 || FRAME_MINIBUF_ONLY_P (f
)
11151 || f
->explicit_name
)
11153 /* Do we have more than one visible frame on this X display? */
11154 Lisp_Object tail
, other_frame
, fmt
;
11155 ptrdiff_t title_start
;
11159 ptrdiff_t count
= SPECPDL_INDEX ();
11161 FOR_EACH_FRAME (tail
, other_frame
)
11163 struct frame
*tf
= XFRAME (other_frame
);
11166 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11167 && !FRAME_MINIBUF_ONLY_P (tf
)
11168 && !EQ (other_frame
, tip_frame
)
11169 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11173 /* Set global variable indicating that multiple frames exist. */
11174 multiple_frames
= CONSP (tail
);
11176 /* Switch to the buffer of selected window of the frame. Set up
11177 mode_line_target so that display_mode_element will output into
11178 mode_line_noprop_buf; then display the title. */
11179 record_unwind_protect (unwind_format_mode_line
,
11180 format_mode_line_unwind_data
11181 (f
, current_buffer
, selected_window
, 0));
11183 Fselect_window (f
->selected_window
, Qt
);
11184 set_buffer_internal_1
11185 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11186 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11188 mode_line_target
= MODE_LINE_TITLE
;
11189 title_start
= MODE_LINE_NOPROP_LEN (0);
11190 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11191 NULL
, DEFAULT_FACE_ID
);
11192 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11193 len
= MODE_LINE_NOPROP_LEN (title_start
);
11194 title
= mode_line_noprop_buf
+ title_start
;
11195 unbind_to (count
, Qnil
);
11197 /* Set the title only if it's changed. This avoids consing in
11198 the common case where it hasn't. (If it turns out that we've
11199 already wasted too much time by walking through the list with
11200 display_mode_element, then we might need to optimize at a
11201 higher level than this.) */
11202 if (! STRINGP (f
->name
)
11203 || SBYTES (f
->name
) != len
11204 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11205 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11209 #endif /* not HAVE_WINDOW_SYSTEM */
11212 /***********************************************************************
11214 ***********************************************************************/
11217 /* Prepare for redisplay by updating menu-bar item lists when
11218 appropriate. This can call eval. */
11221 prepare_menu_bars (void)
11224 struct gcpro gcpro1
, gcpro2
;
11226 Lisp_Object tooltip_frame
;
11228 #ifdef HAVE_WINDOW_SYSTEM
11229 tooltip_frame
= tip_frame
;
11231 tooltip_frame
= Qnil
;
11234 /* Update all frame titles based on their buffer names, etc. We do
11235 this before the menu bars so that the buffer-menu will show the
11236 up-to-date frame titles. */
11237 #ifdef HAVE_WINDOW_SYSTEM
11238 if (windows_or_buffers_changed
|| update_mode_lines
)
11240 Lisp_Object tail
, frame
;
11242 FOR_EACH_FRAME (tail
, frame
)
11244 f
= XFRAME (frame
);
11245 if (!EQ (frame
, tooltip_frame
)
11246 && (FRAME_ICONIFIED_P (f
)
11247 || FRAME_VISIBLE_P (f
) == 1
11248 /* Exclude TTY frames that are obscured because they
11249 are not the top frame on their console. This is
11250 because x_consider_frame_title actually switches
11251 to the frame, which for TTY frames means it is
11252 marked as garbaged, and will be completely
11253 redrawn on the next redisplay cycle. This causes
11254 TTY frames to be completely redrawn, when there
11255 are more than one of them, even though nothing
11256 should be changed on display. */
11257 || (FRAME_VISIBLE_P (f
) == 2 && FRAME_WINDOW_P (f
))))
11258 x_consider_frame_title (frame
);
11261 #endif /* HAVE_WINDOW_SYSTEM */
11263 /* Update the menu bar item lists, if appropriate. This has to be
11264 done before any actual redisplay or generation of display lines. */
11265 all_windows
= (update_mode_lines
11266 || buffer_shared_and_changed ()
11267 || windows_or_buffers_changed
);
11270 Lisp_Object tail
, frame
;
11271 ptrdiff_t count
= SPECPDL_INDEX ();
11272 /* 1 means that update_menu_bar has run its hooks
11273 so any further calls to update_menu_bar shouldn't do so again. */
11274 int menu_bar_hooks_run
= 0;
11276 record_unwind_save_match_data ();
11278 FOR_EACH_FRAME (tail
, frame
)
11280 f
= XFRAME (frame
);
11282 /* Ignore tooltip frame. */
11283 if (EQ (frame
, tooltip_frame
))
11286 /* If a window on this frame changed size, report that to
11287 the user and clear the size-change flag. */
11288 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11290 Lisp_Object functions
;
11292 /* Clear flag first in case we get an error below. */
11293 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11294 functions
= Vwindow_size_change_functions
;
11295 GCPRO2 (tail
, functions
);
11297 while (CONSP (functions
))
11299 if (!EQ (XCAR (functions
), Qt
))
11300 call1 (XCAR (functions
), frame
);
11301 functions
= XCDR (functions
);
11307 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11308 #ifdef HAVE_WINDOW_SYSTEM
11309 update_tool_bar (f
, 0);
11312 if (windows_or_buffers_changed
11315 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11320 unbind_to (count
, Qnil
);
11324 struct frame
*sf
= SELECTED_FRAME ();
11325 update_menu_bar (sf
, 1, 0);
11326 #ifdef HAVE_WINDOW_SYSTEM
11327 update_tool_bar (sf
, 1);
11333 /* Update the menu bar item list for frame F. This has to be done
11334 before we start to fill in any display lines, because it can call
11337 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11339 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11340 already ran the menu bar hooks for this redisplay, so there
11341 is no need to run them again. The return value is the
11342 updated value of this flag, to pass to the next call. */
11345 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11347 Lisp_Object window
;
11348 register struct window
*w
;
11350 /* If called recursively during a menu update, do nothing. This can
11351 happen when, for instance, an activate-menubar-hook causes a
11353 if (inhibit_menubar_update
)
11356 window
= FRAME_SELECTED_WINDOW (f
);
11357 w
= XWINDOW (window
);
11359 if (FRAME_WINDOW_P (f
)
11361 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11362 || defined (HAVE_NS) || defined (USE_GTK)
11363 FRAME_EXTERNAL_MENU_BAR (f
)
11365 FRAME_MENU_BAR_LINES (f
) > 0
11367 : FRAME_MENU_BAR_LINES (f
) > 0)
11369 /* If the user has switched buffers or windows, we need to
11370 recompute to reflect the new bindings. But we'll
11371 recompute when update_mode_lines is set too; that means
11372 that people can use force-mode-line-update to request
11373 that the menu bar be recomputed. The adverse effect on
11374 the rest of the redisplay algorithm is about the same as
11375 windows_or_buffers_changed anyway. */
11376 if (windows_or_buffers_changed
11377 /* This used to test w->update_mode_line, but we believe
11378 there is no need to recompute the menu in that case. */
11379 || update_mode_lines
11380 || window_buffer_changed (w
))
11382 struct buffer
*prev
= current_buffer
;
11383 ptrdiff_t count
= SPECPDL_INDEX ();
11385 specbind (Qinhibit_menubar_update
, Qt
);
11387 set_buffer_internal_1 (XBUFFER (w
->contents
));
11388 if (save_match_data
)
11389 record_unwind_save_match_data ();
11390 if (NILP (Voverriding_local_map_menu_flag
))
11392 specbind (Qoverriding_terminal_local_map
, Qnil
);
11393 specbind (Qoverriding_local_map
, Qnil
);
11398 /* Run the Lucid hook. */
11399 safe_run_hooks (Qactivate_menubar_hook
);
11401 /* If it has changed current-menubar from previous value,
11402 really recompute the menu-bar from the value. */
11403 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11404 call0 (Qrecompute_lucid_menubar
);
11406 safe_run_hooks (Qmenu_bar_update_hook
);
11411 XSETFRAME (Vmenu_updating_frame
, f
);
11412 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11414 /* Redisplay the menu bar in case we changed it. */
11415 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11416 || defined (HAVE_NS) || defined (USE_GTK)
11417 if (FRAME_WINDOW_P (f
))
11419 #if defined (HAVE_NS)
11420 /* All frames on Mac OS share the same menubar. So only
11421 the selected frame should be allowed to set it. */
11422 if (f
== SELECTED_FRAME ())
11424 set_frame_menubar (f
, 0, 0);
11427 /* On a terminal screen, the menu bar is an ordinary screen
11428 line, and this makes it get updated. */
11429 w
->update_mode_line
= 1;
11430 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11431 /* In the non-toolkit version, the menu bar is an ordinary screen
11432 line, and this makes it get updated. */
11433 w
->update_mode_line
= 1;
11434 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11436 unbind_to (count
, Qnil
);
11437 set_buffer_internal_1 (prev
);
11444 /***********************************************************************
11446 ***********************************************************************/
11448 #ifdef HAVE_WINDOW_SYSTEM
11450 /* Where the mouse was last time we reported a mouse event. */
11452 struct frame
*last_mouse_frame
;
11454 /* Tool-bar item index of the item on which a mouse button was pressed
11457 int last_tool_bar_item
;
11459 /* Select `frame' temporarily without running all the code in
11461 FIXME: Maybe do_switch_frame should be trimmed down similarly
11462 when `norecord' is set. */
11464 fast_set_selected_frame (Lisp_Object frame
)
11466 if (!EQ (selected_frame
, frame
))
11468 selected_frame
= frame
;
11469 selected_window
= XFRAME (frame
)->selected_window
;
11473 /* Update the tool-bar item list for frame F. This has to be done
11474 before we start to fill in any display lines. Called from
11475 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11476 and restore it here. */
11479 update_tool_bar (struct frame
*f
, int save_match_data
)
11481 #if defined (USE_GTK) || defined (HAVE_NS)
11482 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11484 int do_update
= WINDOWP (f
->tool_bar_window
)
11485 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11490 Lisp_Object window
;
11493 window
= FRAME_SELECTED_WINDOW (f
);
11494 w
= XWINDOW (window
);
11496 /* If the user has switched buffers or windows, we need to
11497 recompute to reflect the new bindings. But we'll
11498 recompute when update_mode_lines is set too; that means
11499 that people can use force-mode-line-update to request
11500 that the menu bar be recomputed. The adverse effect on
11501 the rest of the redisplay algorithm is about the same as
11502 windows_or_buffers_changed anyway. */
11503 if (windows_or_buffers_changed
11504 || w
->update_mode_line
11505 || update_mode_lines
11506 || window_buffer_changed (w
))
11508 struct buffer
*prev
= current_buffer
;
11509 ptrdiff_t count
= SPECPDL_INDEX ();
11510 Lisp_Object frame
, new_tool_bar
;
11511 int new_n_tool_bar
;
11512 struct gcpro gcpro1
;
11514 /* Set current_buffer to the buffer of the selected
11515 window of the frame, so that we get the right local
11517 set_buffer_internal_1 (XBUFFER (w
->contents
));
11519 /* Save match data, if we must. */
11520 if (save_match_data
)
11521 record_unwind_save_match_data ();
11523 /* Make sure that we don't accidentally use bogus keymaps. */
11524 if (NILP (Voverriding_local_map_menu_flag
))
11526 specbind (Qoverriding_terminal_local_map
, Qnil
);
11527 specbind (Qoverriding_local_map
, Qnil
);
11530 GCPRO1 (new_tool_bar
);
11532 /* We must temporarily set the selected frame to this frame
11533 before calling tool_bar_items, because the calculation of
11534 the tool-bar keymap uses the selected frame (see
11535 `tool-bar-make-keymap' in tool-bar.el). */
11536 eassert (EQ (selected_window
,
11537 /* Since we only explicitly preserve selected_frame,
11538 check that selected_window would be redundant. */
11539 XFRAME (selected_frame
)->selected_window
));
11540 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11541 XSETFRAME (frame
, f
);
11542 fast_set_selected_frame (frame
);
11544 /* Build desired tool-bar items from keymaps. */
11546 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11549 /* Redisplay the tool-bar if we changed it. */
11550 if (new_n_tool_bar
!= f
->n_tool_bar_items
11551 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11553 /* Redisplay that happens asynchronously due to an expose event
11554 may access f->tool_bar_items. Make sure we update both
11555 variables within BLOCK_INPUT so no such event interrupts. */
11557 fset_tool_bar_items (f
, new_tool_bar
);
11558 f
->n_tool_bar_items
= new_n_tool_bar
;
11559 w
->update_mode_line
= 1;
11565 unbind_to (count
, Qnil
);
11566 set_buffer_internal_1 (prev
);
11572 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11573 F's desired tool-bar contents. F->tool_bar_items must have
11574 been set up previously by calling prepare_menu_bars. */
11577 build_desired_tool_bar_string (struct frame
*f
)
11579 int i
, size
, size_needed
;
11580 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11581 Lisp_Object image
, plist
, props
;
11583 image
= plist
= props
= Qnil
;
11584 GCPRO3 (image
, plist
, props
);
11586 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11587 Otherwise, make a new string. */
11589 /* The size of the string we might be able to reuse. */
11590 size
= (STRINGP (f
->desired_tool_bar_string
)
11591 ? SCHARS (f
->desired_tool_bar_string
)
11594 /* We need one space in the string for each image. */
11595 size_needed
= f
->n_tool_bar_items
;
11597 /* Reuse f->desired_tool_bar_string, if possible. */
11598 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11599 fset_desired_tool_bar_string
11600 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11603 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11604 Fremove_text_properties (make_number (0), make_number (size
),
11605 props
, f
->desired_tool_bar_string
);
11608 /* Put a `display' property on the string for the images to display,
11609 put a `menu_item' property on tool-bar items with a value that
11610 is the index of the item in F's tool-bar item vector. */
11611 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11613 #define PROP(IDX) \
11614 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11616 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11617 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11618 int hmargin
, vmargin
, relief
, idx
, end
;
11620 /* If image is a vector, choose the image according to the
11622 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11623 if (VECTORP (image
))
11627 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11628 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11631 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11632 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11634 eassert (ASIZE (image
) >= idx
);
11635 image
= AREF (image
, idx
);
11640 /* Ignore invalid image specifications. */
11641 if (!valid_image_p (image
))
11644 /* Display the tool-bar button pressed, or depressed. */
11645 plist
= Fcopy_sequence (XCDR (image
));
11647 /* Compute margin and relief to draw. */
11648 relief
= (tool_bar_button_relief
>= 0
11649 ? tool_bar_button_relief
11650 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11651 hmargin
= vmargin
= relief
;
11653 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11654 INT_MAX
- max (hmargin
, vmargin
)))
11656 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11657 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11659 else if (CONSP (Vtool_bar_button_margin
))
11661 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11662 INT_MAX
- hmargin
))
11663 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11665 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11666 INT_MAX
- vmargin
))
11667 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11670 if (auto_raise_tool_bar_buttons_p
)
11672 /* Add a `:relief' property to the image spec if the item is
11676 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11683 /* If image is selected, display it pressed, i.e. with a
11684 negative relief. If it's not selected, display it with a
11686 plist
= Fplist_put (plist
, QCrelief
,
11688 ? make_number (-relief
)
11689 : make_number (relief
)));
11694 /* Put a margin around the image. */
11695 if (hmargin
|| vmargin
)
11697 if (hmargin
== vmargin
)
11698 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11700 plist
= Fplist_put (plist
, QCmargin
,
11701 Fcons (make_number (hmargin
),
11702 make_number (vmargin
)));
11705 /* If button is not enabled, and we don't have special images
11706 for the disabled state, make the image appear disabled by
11707 applying an appropriate algorithm to it. */
11708 if (!enabled_p
&& idx
< 0)
11709 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11711 /* Put a `display' text property on the string for the image to
11712 display. Put a `menu-item' property on the string that gives
11713 the start of this item's properties in the tool-bar items
11715 image
= Fcons (Qimage
, plist
);
11716 props
= list4 (Qdisplay
, image
,
11717 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11719 /* Let the last image hide all remaining spaces in the tool bar
11720 string. The string can be longer than needed when we reuse a
11721 previous string. */
11722 if (i
+ 1 == f
->n_tool_bar_items
)
11723 end
= SCHARS (f
->desired_tool_bar_string
);
11726 Fadd_text_properties (make_number (i
), make_number (end
),
11727 props
, f
->desired_tool_bar_string
);
11735 /* Display one line of the tool-bar of frame IT->f.
11737 HEIGHT specifies the desired height of the tool-bar line.
11738 If the actual height of the glyph row is less than HEIGHT, the
11739 row's height is increased to HEIGHT, and the icons are centered
11740 vertically in the new height.
11742 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11743 count a final empty row in case the tool-bar width exactly matches
11748 display_tool_bar_line (struct it
*it
, int height
)
11750 struct glyph_row
*row
= it
->glyph_row
;
11751 int max_x
= it
->last_visible_x
;
11752 struct glyph
*last
;
11754 prepare_desired_row (row
);
11755 row
->y
= it
->current_y
;
11757 /* Note that this isn't made use of if the face hasn't a box,
11758 so there's no need to check the face here. */
11759 it
->start_of_box_run_p
= 1;
11761 while (it
->current_x
< max_x
)
11763 int x
, n_glyphs_before
, i
, nglyphs
;
11764 struct it it_before
;
11766 /* Get the next display element. */
11767 if (!get_next_display_element (it
))
11769 /* Don't count empty row if we are counting needed tool-bar lines. */
11770 if (height
< 0 && !it
->hpos
)
11775 /* Produce glyphs. */
11776 n_glyphs_before
= row
->used
[TEXT_AREA
];
11779 PRODUCE_GLYPHS (it
);
11781 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11783 x
= it_before
.current_x
;
11784 while (i
< nglyphs
)
11786 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11788 if (x
+ glyph
->pixel_width
> max_x
)
11790 /* Glyph doesn't fit on line. Backtrack. */
11791 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11793 /* If this is the only glyph on this line, it will never fit on the
11794 tool-bar, so skip it. But ensure there is at least one glyph,
11795 so we don't accidentally disable the tool-bar. */
11796 if (n_glyphs_before
== 0
11797 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11803 x
+= glyph
->pixel_width
;
11807 /* Stop at line end. */
11808 if (ITERATOR_AT_END_OF_LINE_P (it
))
11811 set_iterator_to_next (it
, 1);
11816 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11818 /* Use default face for the border below the tool bar.
11820 FIXME: When auto-resize-tool-bars is grow-only, there is
11821 no additional border below the possibly empty tool-bar lines.
11822 So to make the extra empty lines look "normal", we have to
11823 use the tool-bar face for the border too. */
11824 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11825 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11826 it
->face_id
= DEFAULT_FACE_ID
;
11828 extend_face_to_end_of_line (it
);
11829 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11830 last
->right_box_line_p
= 1;
11831 if (last
== row
->glyphs
[TEXT_AREA
])
11832 last
->left_box_line_p
= 1;
11834 /* Make line the desired height and center it vertically. */
11835 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11837 /* Don't add more than one line height. */
11838 height
%= FRAME_LINE_HEIGHT (it
->f
);
11839 it
->max_ascent
+= height
/ 2;
11840 it
->max_descent
+= (height
+ 1) / 2;
11843 compute_line_metrics (it
);
11845 /* If line is empty, make it occupy the rest of the tool-bar. */
11846 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11848 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11849 row
->visible_height
= row
->height
;
11850 row
->ascent
= row
->phys_ascent
= 0;
11851 row
->extra_line_spacing
= 0;
11854 row
->full_width_p
= 1;
11855 row
->continued_p
= 0;
11856 row
->truncated_on_left_p
= 0;
11857 row
->truncated_on_right_p
= 0;
11859 it
->current_x
= it
->hpos
= 0;
11860 it
->current_y
+= row
->height
;
11866 /* Max tool-bar height. */
11868 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11869 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11871 /* Value is the number of screen lines needed to make all tool-bar
11872 items of frame F visible. The number of actual rows needed is
11873 returned in *N_ROWS if non-NULL. */
11876 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11878 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11880 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11881 the desired matrix, so use (unused) mode-line row as temporary row to
11882 avoid destroying the first tool-bar row. */
11883 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11885 /* Initialize an iterator for iteration over
11886 F->desired_tool_bar_string in the tool-bar window of frame F. */
11887 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11888 it
.first_visible_x
= 0;
11889 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11890 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11891 it
.paragraph_embedding
= L2R
;
11893 while (!ITERATOR_AT_END_P (&it
))
11895 clear_glyph_row (temp_row
);
11896 it
.glyph_row
= temp_row
;
11897 display_tool_bar_line (&it
, -1);
11899 clear_glyph_row (temp_row
);
11901 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11903 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11905 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11909 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11911 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11912 If FRAME is nil or omitted, use the selected frame. */)
11913 (Lisp_Object frame
)
11915 struct frame
*f
= decode_any_frame (frame
);
11919 if (WINDOWP (f
->tool_bar_window
)
11920 && (w
= XWINDOW (f
->tool_bar_window
),
11921 WINDOW_TOTAL_LINES (w
) > 0))
11923 update_tool_bar (f
, 1);
11924 if (f
->n_tool_bar_items
)
11926 build_desired_tool_bar_string (f
);
11927 nlines
= tool_bar_lines_needed (f
, NULL
);
11931 return make_number (nlines
);
11935 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11936 height should be changed. */
11939 redisplay_tool_bar (struct frame
*f
)
11943 struct glyph_row
*row
;
11945 #if defined (USE_GTK) || defined (HAVE_NS)
11946 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11947 update_frame_tool_bar (f
);
11951 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11952 do anything. This means you must start with tool-bar-lines
11953 non-zero to get the auto-sizing effect. Or in other words, you
11954 can turn off tool-bars by specifying tool-bar-lines zero. */
11955 if (!WINDOWP (f
->tool_bar_window
)
11956 || (w
= XWINDOW (f
->tool_bar_window
),
11957 WINDOW_TOTAL_LINES (w
) == 0))
11960 /* Set up an iterator for the tool-bar window. */
11961 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11962 it
.first_visible_x
= 0;
11963 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11964 row
= it
.glyph_row
;
11966 /* Build a string that represents the contents of the tool-bar. */
11967 build_desired_tool_bar_string (f
);
11968 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11969 /* FIXME: This should be controlled by a user option. But it
11970 doesn't make sense to have an R2L tool bar if the menu bar cannot
11971 be drawn also R2L, and making the menu bar R2L is tricky due
11972 toolkit-specific code that implements it. If an R2L tool bar is
11973 ever supported, display_tool_bar_line should also be augmented to
11974 call unproduce_glyphs like display_line and display_string
11976 it
.paragraph_embedding
= L2R
;
11978 if (f
->n_tool_bar_rows
== 0)
11982 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11983 nlines
!= WINDOW_TOTAL_LINES (w
)))
11986 int old_height
= WINDOW_TOTAL_LINES (w
);
11988 XSETFRAME (frame
, f
);
11989 Fmodify_frame_parameters (frame
,
11990 list1 (Fcons (Qtool_bar_lines
,
11991 make_number (nlines
))));
11992 if (WINDOW_TOTAL_LINES (w
) != old_height
)
11994 clear_glyph_matrix (w
->desired_matrix
);
11995 f
->fonts_changed
= 1;
12001 /* Display as many lines as needed to display all tool-bar items. */
12003 if (f
->n_tool_bar_rows
> 0)
12005 int border
, rows
, height
, extra
;
12007 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12008 border
= XINT (Vtool_bar_border
);
12009 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12010 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12011 else if (EQ (Vtool_bar_border
, Qborder_width
))
12012 border
= f
->border_width
;
12018 rows
= f
->n_tool_bar_rows
;
12019 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12020 extra
= it
.last_visible_y
- border
- height
* rows
;
12022 while (it
.current_y
< it
.last_visible_y
)
12025 if (extra
> 0 && rows
-- > 0)
12027 h
= (extra
+ rows
- 1) / rows
;
12030 display_tool_bar_line (&it
, height
+ h
);
12035 while (it
.current_y
< it
.last_visible_y
)
12036 display_tool_bar_line (&it
, 0);
12039 /* It doesn't make much sense to try scrolling in the tool-bar
12040 window, so don't do it. */
12041 w
->desired_matrix
->no_scrolling_p
= 1;
12042 w
->must_be_updated_p
= 1;
12044 if (!NILP (Vauto_resize_tool_bars
))
12046 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12047 int change_height_p
= 0;
12049 /* If we couldn't display everything, change the tool-bar's
12050 height if there is room for more. */
12051 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12052 && it
.current_y
< max_tool_bar_height
)
12053 change_height_p
= 1;
12055 row
= it
.glyph_row
- 1;
12057 /* If there are blank lines at the end, except for a partially
12058 visible blank line at the end that is smaller than
12059 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12060 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12061 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12062 change_height_p
= 1;
12064 /* If row displays tool-bar items, but is partially visible,
12065 change the tool-bar's height. */
12066 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12067 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12068 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12069 change_height_p
= 1;
12071 /* Resize windows as needed by changing the `tool-bar-lines'
12072 frame parameter. */
12073 if (change_height_p
)
12076 int old_height
= WINDOW_TOTAL_LINES (w
);
12078 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12080 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12081 && !f
->minimize_tool_bar_window_p
)
12082 ? (nlines
> old_height
)
12083 : (nlines
!= old_height
));
12084 f
->minimize_tool_bar_window_p
= 0;
12086 if (change_height_p
)
12088 XSETFRAME (frame
, f
);
12089 Fmodify_frame_parameters (frame
,
12090 list1 (Fcons (Qtool_bar_lines
,
12091 make_number (nlines
))));
12092 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12094 clear_glyph_matrix (w
->desired_matrix
);
12095 f
->n_tool_bar_rows
= nrows
;
12096 f
->fonts_changed
= 1;
12103 f
->minimize_tool_bar_window_p
= 0;
12108 /* Get information about the tool-bar item which is displayed in GLYPH
12109 on frame F. Return in *PROP_IDX the index where tool-bar item
12110 properties start in F->tool_bar_items. Value is zero if
12111 GLYPH doesn't display a tool-bar item. */
12114 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12120 /* This function can be called asynchronously, which means we must
12121 exclude any possibility that Fget_text_property signals an
12123 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12124 charpos
= max (0, charpos
);
12126 /* Get the text property `menu-item' at pos. The value of that
12127 property is the start index of this item's properties in
12128 F->tool_bar_items. */
12129 prop
= Fget_text_property (make_number (charpos
),
12130 Qmenu_item
, f
->current_tool_bar_string
);
12131 if (INTEGERP (prop
))
12133 *prop_idx
= XINT (prop
);
12143 /* Get information about the tool-bar item at position X/Y on frame F.
12144 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12145 the current matrix of the tool-bar window of F, or NULL if not
12146 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12147 item in F->tool_bar_items. Value is
12149 -1 if X/Y is not on a tool-bar item
12150 0 if X/Y is on the same item that was highlighted before.
12154 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12155 int *hpos
, int *vpos
, int *prop_idx
)
12157 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12158 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12161 /* Find the glyph under X/Y. */
12162 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12163 if (*glyph
== NULL
)
12166 /* Get the start of this tool-bar item's properties in
12167 f->tool_bar_items. */
12168 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12171 /* Is mouse on the highlighted item? */
12172 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12173 && *vpos
>= hlinfo
->mouse_face_beg_row
12174 && *vpos
<= hlinfo
->mouse_face_end_row
12175 && (*vpos
> hlinfo
->mouse_face_beg_row
12176 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12177 && (*vpos
< hlinfo
->mouse_face_end_row
12178 || *hpos
< hlinfo
->mouse_face_end_col
12179 || hlinfo
->mouse_face_past_end
))
12187 Handle mouse button event on the tool-bar of frame F, at
12188 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12189 0 for button release. MODIFIERS is event modifiers for button
12193 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12196 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12197 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12198 int hpos
, vpos
, prop_idx
;
12199 struct glyph
*glyph
;
12200 Lisp_Object enabled_p
;
12203 /* If not on the highlighted tool-bar item, and mouse-highlight is
12204 non-nil, return. This is so we generate the tool-bar button
12205 click only when the mouse button is released on the same item as
12206 where it was pressed. However, when mouse-highlight is disabled,
12207 generate the click when the button is released regardless of the
12208 highlight, since tool-bar items are not highlighted in that
12210 frame_to_window_pixel_xy (w
, &x
, &y
);
12211 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12213 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12216 /* When mouse-highlight is off, generate the click for the item
12217 where the button was pressed, disregarding where it was
12219 if (NILP (Vmouse_highlight
) && !down_p
)
12220 prop_idx
= last_tool_bar_item
;
12222 /* If item is disabled, do nothing. */
12223 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12224 if (NILP (enabled_p
))
12229 /* Show item in pressed state. */
12230 if (!NILP (Vmouse_highlight
))
12231 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12232 last_tool_bar_item
= prop_idx
;
12236 Lisp_Object key
, frame
;
12237 struct input_event event
;
12238 EVENT_INIT (event
);
12240 /* Show item in released state. */
12241 if (!NILP (Vmouse_highlight
))
12242 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12244 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12246 XSETFRAME (frame
, f
);
12247 event
.kind
= TOOL_BAR_EVENT
;
12248 event
.frame_or_window
= frame
;
12250 kbd_buffer_store_event (&event
);
12252 event
.kind
= TOOL_BAR_EVENT
;
12253 event
.frame_or_window
= frame
;
12255 event
.modifiers
= modifiers
;
12256 kbd_buffer_store_event (&event
);
12257 last_tool_bar_item
= -1;
12262 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12263 tool-bar window-relative coordinates X/Y. Called from
12264 note_mouse_highlight. */
12267 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12269 Lisp_Object window
= f
->tool_bar_window
;
12270 struct window
*w
= XWINDOW (window
);
12271 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12272 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12274 struct glyph
*glyph
;
12275 struct glyph_row
*row
;
12277 Lisp_Object enabled_p
;
12279 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12280 int mouse_down_p
, rc
;
12282 /* Function note_mouse_highlight is called with negative X/Y
12283 values when mouse moves outside of the frame. */
12284 if (x
<= 0 || y
<= 0)
12286 clear_mouse_face (hlinfo
);
12290 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12293 /* Not on tool-bar item. */
12294 clear_mouse_face (hlinfo
);
12298 /* On same tool-bar item as before. */
12299 goto set_help_echo
;
12301 clear_mouse_face (hlinfo
);
12303 /* Mouse is down, but on different tool-bar item? */
12304 mouse_down_p
= (dpyinfo
->grabbed
12305 && f
== last_mouse_frame
12306 && FRAME_LIVE_P (f
));
12308 && last_tool_bar_item
!= prop_idx
)
12311 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12313 /* If tool-bar item is not enabled, don't highlight it. */
12314 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12315 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12317 /* Compute the x-position of the glyph. In front and past the
12318 image is a space. We include this in the highlighted area. */
12319 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12320 for (i
= x
= 0; i
< hpos
; ++i
)
12321 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12323 /* Record this as the current active region. */
12324 hlinfo
->mouse_face_beg_col
= hpos
;
12325 hlinfo
->mouse_face_beg_row
= vpos
;
12326 hlinfo
->mouse_face_beg_x
= x
;
12327 hlinfo
->mouse_face_past_end
= 0;
12329 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12330 hlinfo
->mouse_face_end_row
= vpos
;
12331 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12332 hlinfo
->mouse_face_window
= window
;
12333 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12335 /* Display it as active. */
12336 show_mouse_face (hlinfo
, draw
);
12341 /* Set help_echo_string to a help string to display for this tool-bar item.
12342 XTread_socket does the rest. */
12343 help_echo_object
= help_echo_window
= Qnil
;
12344 help_echo_pos
= -1;
12345 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12346 if (NILP (help_echo_string
))
12347 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12350 #endif /* HAVE_WINDOW_SYSTEM */
12354 /************************************************************************
12355 Horizontal scrolling
12356 ************************************************************************/
12358 static int hscroll_window_tree (Lisp_Object
);
12359 static int hscroll_windows (Lisp_Object
);
12361 /* For all leaf windows in the window tree rooted at WINDOW, set their
12362 hscroll value so that PT is (i) visible in the window, and (ii) so
12363 that it is not within a certain margin at the window's left and
12364 right border. Value is non-zero if any window's hscroll has been
12368 hscroll_window_tree (Lisp_Object window
)
12370 int hscrolled_p
= 0;
12371 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12372 int hscroll_step_abs
= 0;
12373 double hscroll_step_rel
= 0;
12375 if (hscroll_relative_p
)
12377 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12378 if (hscroll_step_rel
< 0)
12380 hscroll_relative_p
= 0;
12381 hscroll_step_abs
= 0;
12384 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12386 hscroll_step_abs
= XINT (Vhscroll_step
);
12387 if (hscroll_step_abs
< 0)
12388 hscroll_step_abs
= 0;
12391 hscroll_step_abs
= 0;
12393 while (WINDOWP (window
))
12395 struct window
*w
= XWINDOW (window
);
12397 if (WINDOWP (w
->contents
))
12398 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12399 else if (w
->cursor
.vpos
>= 0)
12402 int text_area_width
;
12403 struct glyph_row
*current_cursor_row
12404 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12405 struct glyph_row
*desired_cursor_row
12406 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12407 struct glyph_row
*cursor_row
12408 = (desired_cursor_row
->enabled_p
12409 ? desired_cursor_row
12410 : current_cursor_row
);
12411 int row_r2l_p
= cursor_row
->reversed_p
;
12413 text_area_width
= window_box_width (w
, TEXT_AREA
);
12415 /* Scroll when cursor is inside this scroll margin. */
12416 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12418 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12419 /* For left-to-right rows, hscroll when cursor is either
12420 (i) inside the right hscroll margin, or (ii) if it is
12421 inside the left margin and the window is already
12425 && w
->cursor
.x
<= h_margin
)
12426 || (cursor_row
->enabled_p
12427 && cursor_row
->truncated_on_right_p
12428 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12429 /* For right-to-left rows, the logic is similar,
12430 except that rules for scrolling to left and right
12431 are reversed. E.g., if cursor.x <= h_margin, we
12432 need to hscroll "to the right" unconditionally,
12433 and that will scroll the screen to the left so as
12434 to reveal the next portion of the row. */
12436 && ((cursor_row
->enabled_p
12437 /* FIXME: It is confusing to set the
12438 truncated_on_right_p flag when R2L rows
12439 are actually truncated on the left. */
12440 && cursor_row
->truncated_on_right_p
12441 && w
->cursor
.x
<= h_margin
)
12443 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12447 struct buffer
*saved_current_buffer
;
12451 /* Find point in a display of infinite width. */
12452 saved_current_buffer
= current_buffer
;
12453 current_buffer
= XBUFFER (w
->contents
);
12455 if (w
== XWINDOW (selected_window
))
12458 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12460 /* Move iterator to pt starting at cursor_row->start in
12461 a line with infinite width. */
12462 init_to_row_start (&it
, w
, cursor_row
);
12463 it
.last_visible_x
= INFINITY
;
12464 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12465 current_buffer
= saved_current_buffer
;
12467 /* Position cursor in window. */
12468 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12469 hscroll
= max (0, (it
.current_x
12470 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12471 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12472 : (text_area_width
/ 2))))
12473 / FRAME_COLUMN_WIDTH (it
.f
);
12474 else if ((!row_r2l_p
12475 && w
->cursor
.x
>= text_area_width
- h_margin
)
12476 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12478 if (hscroll_relative_p
)
12479 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12482 wanted_x
= text_area_width
12483 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12486 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12490 if (hscroll_relative_p
)
12491 wanted_x
= text_area_width
* hscroll_step_rel
12494 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12497 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12499 hscroll
= max (hscroll
, w
->min_hscroll
);
12501 /* Don't prevent redisplay optimizations if hscroll
12502 hasn't changed, as it will unnecessarily slow down
12504 if (w
->hscroll
!= hscroll
)
12506 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12507 w
->hscroll
= hscroll
;
12516 /* Value is non-zero if hscroll of any leaf window has been changed. */
12517 return hscrolled_p
;
12521 /* Set hscroll so that cursor is visible and not inside horizontal
12522 scroll margins for all windows in the tree rooted at WINDOW. See
12523 also hscroll_window_tree above. Value is non-zero if any window's
12524 hscroll has been changed. If it has, desired matrices on the frame
12525 of WINDOW are cleared. */
12528 hscroll_windows (Lisp_Object window
)
12530 int hscrolled_p
= hscroll_window_tree (window
);
12532 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12533 return hscrolled_p
;
12538 /************************************************************************
12540 ************************************************************************/
12542 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12543 to a non-zero value. This is sometimes handy to have in a debugger
12548 /* First and last unchanged row for try_window_id. */
12550 static int debug_first_unchanged_at_end_vpos
;
12551 static int debug_last_unchanged_at_beg_vpos
;
12553 /* Delta vpos and y. */
12555 static int debug_dvpos
, debug_dy
;
12557 /* Delta in characters and bytes for try_window_id. */
12559 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12561 /* Values of window_end_pos and window_end_vpos at the end of
12564 static ptrdiff_t debug_end_vpos
;
12566 /* Append a string to W->desired_matrix->method. FMT is a printf
12567 format string. If trace_redisplay_p is non-zero also printf the
12568 resulting string to stderr. */
12570 static void debug_method_add (struct window
*, char const *, ...)
12571 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12574 debug_method_add (struct window
*w
, char const *fmt
, ...)
12577 char *method
= w
->desired_matrix
->method
;
12578 int len
= strlen (method
);
12579 int size
= sizeof w
->desired_matrix
->method
;
12580 int remaining
= size
- len
- 1;
12583 if (len
&& remaining
)
12586 --remaining
, ++len
;
12589 va_start (ap
, fmt
);
12590 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12593 if (trace_redisplay_p
)
12594 fprintf (stderr
, "%p (%s): %s\n",
12596 ((BUFFERP (w
->contents
)
12597 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12598 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12603 #endif /* GLYPH_DEBUG */
12606 /* Value is non-zero if all changes in window W, which displays
12607 current_buffer, are in the text between START and END. START is a
12608 buffer position, END is given as a distance from Z. Used in
12609 redisplay_internal for display optimization. */
12612 text_outside_line_unchanged_p (struct window
*w
,
12613 ptrdiff_t start
, ptrdiff_t end
)
12615 int unchanged_p
= 1;
12617 /* If text or overlays have changed, see where. */
12618 if (window_outdated (w
))
12620 /* Gap in the line? */
12621 if (GPT
< start
|| Z
- GPT
< end
)
12624 /* Changes start in front of the line, or end after it? */
12626 && (BEG_UNCHANGED
< start
- 1
12627 || END_UNCHANGED
< end
))
12630 /* If selective display, can't optimize if changes start at the
12631 beginning of the line. */
12633 && INTEGERP (BVAR (current_buffer
, selective_display
))
12634 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12635 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12638 /* If there are overlays at the start or end of the line, these
12639 may have overlay strings with newlines in them. A change at
12640 START, for instance, may actually concern the display of such
12641 overlay strings as well, and they are displayed on different
12642 lines. So, quickly rule out this case. (For the future, it
12643 might be desirable to implement something more telling than
12644 just BEG/END_UNCHANGED.) */
12647 if (BEG
+ BEG_UNCHANGED
== start
12648 && overlay_touches_p (start
))
12650 if (END_UNCHANGED
== end
12651 && overlay_touches_p (Z
- end
))
12655 /* Under bidi reordering, adding or deleting a character in the
12656 beginning of a paragraph, before the first strong directional
12657 character, can change the base direction of the paragraph (unless
12658 the buffer specifies a fixed paragraph direction), which will
12659 require to redisplay the whole paragraph. It might be worthwhile
12660 to find the paragraph limits and widen the range of redisplayed
12661 lines to that, but for now just give up this optimization. */
12662 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12663 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12667 return unchanged_p
;
12671 /* Do a frame update, taking possible shortcuts into account. This is
12672 the main external entry point for redisplay.
12674 If the last redisplay displayed an echo area message and that message
12675 is no longer requested, we clear the echo area or bring back the
12676 mini-buffer if that is in use. */
12681 redisplay_internal ();
12686 overlay_arrow_string_or_property (Lisp_Object var
)
12690 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12693 return Voverlay_arrow_string
;
12696 /* Return 1 if there are any overlay-arrows in current_buffer. */
12698 overlay_arrow_in_current_buffer_p (void)
12702 for (vlist
= Voverlay_arrow_variable_list
;
12704 vlist
= XCDR (vlist
))
12706 Lisp_Object var
= XCAR (vlist
);
12709 if (!SYMBOLP (var
))
12711 val
= find_symbol_value (var
);
12713 && current_buffer
== XMARKER (val
)->buffer
)
12720 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12724 overlay_arrows_changed_p (void)
12728 for (vlist
= Voverlay_arrow_variable_list
;
12730 vlist
= XCDR (vlist
))
12732 Lisp_Object var
= XCAR (vlist
);
12733 Lisp_Object val
, pstr
;
12735 if (!SYMBOLP (var
))
12737 val
= find_symbol_value (var
);
12738 if (!MARKERP (val
))
12740 if (! EQ (COERCE_MARKER (val
),
12741 Fget (var
, Qlast_arrow_position
))
12742 || ! (pstr
= overlay_arrow_string_or_property (var
),
12743 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12749 /* Mark overlay arrows to be updated on next redisplay. */
12752 update_overlay_arrows (int up_to_date
)
12756 for (vlist
= Voverlay_arrow_variable_list
;
12758 vlist
= XCDR (vlist
))
12760 Lisp_Object var
= XCAR (vlist
);
12762 if (!SYMBOLP (var
))
12765 if (up_to_date
> 0)
12767 Lisp_Object val
= find_symbol_value (var
);
12768 Fput (var
, Qlast_arrow_position
,
12769 COERCE_MARKER (val
));
12770 Fput (var
, Qlast_arrow_string
,
12771 overlay_arrow_string_or_property (var
));
12773 else if (up_to_date
< 0
12774 || !NILP (Fget (var
, Qlast_arrow_position
)))
12776 Fput (var
, Qlast_arrow_position
, Qt
);
12777 Fput (var
, Qlast_arrow_string
, Qt
);
12783 /* Return overlay arrow string to display at row.
12784 Return integer (bitmap number) for arrow bitmap in left fringe.
12785 Return nil if no overlay arrow. */
12788 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12792 for (vlist
= Voverlay_arrow_variable_list
;
12794 vlist
= XCDR (vlist
))
12796 Lisp_Object var
= XCAR (vlist
);
12799 if (!SYMBOLP (var
))
12802 val
= find_symbol_value (var
);
12805 && current_buffer
== XMARKER (val
)->buffer
12806 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12808 if (FRAME_WINDOW_P (it
->f
)
12809 /* FIXME: if ROW->reversed_p is set, this should test
12810 the right fringe, not the left one. */
12811 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12813 #ifdef HAVE_WINDOW_SYSTEM
12814 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12817 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12818 return make_number (fringe_bitmap
);
12821 return make_number (-1); /* Use default arrow bitmap. */
12823 return overlay_arrow_string_or_property (var
);
12830 /* Return 1 if point moved out of or into a composition. Otherwise
12831 return 0. PREV_BUF and PREV_PT are the last point buffer and
12832 position. BUF and PT are the current point buffer and position. */
12835 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12836 struct buffer
*buf
, ptrdiff_t pt
)
12838 ptrdiff_t start
, end
;
12840 Lisp_Object buffer
;
12842 XSETBUFFER (buffer
, buf
);
12843 /* Check a composition at the last point if point moved within the
12845 if (prev_buf
== buf
)
12848 /* Point didn't move. */
12851 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12852 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12853 && composition_valid_p (start
, end
, prop
)
12854 && start
< prev_pt
&& end
> prev_pt
)
12855 /* The last point was within the composition. Return 1 iff
12856 point moved out of the composition. */
12857 return (pt
<= start
|| pt
>= end
);
12860 /* Check a composition at the current point. */
12861 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12862 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12863 && composition_valid_p (start
, end
, prop
)
12864 && start
< pt
&& end
> pt
);
12867 /* Reconsider the clip changes of buffer which is displayed in W. */
12870 reconsider_clip_changes (struct window
*w
)
12872 struct buffer
*b
= XBUFFER (w
->contents
);
12874 if (b
->clip_changed
12875 && w
->window_end_valid
12876 && w
->current_matrix
->buffer
== b
12877 && w
->current_matrix
->zv
== BUF_ZV (b
)
12878 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12879 b
->clip_changed
= 0;
12881 /* If display wasn't paused, and W is not a tool bar window, see if
12882 point has been moved into or out of a composition. In that case,
12883 we set b->clip_changed to 1 to force updating the screen. If
12884 b->clip_changed has already been set to 1, we can skip this
12886 if (!b
->clip_changed
&& w
->window_end_valid
)
12888 ptrdiff_t pt
= (w
== XWINDOW (selected_window
)
12889 ? PT
: marker_position (w
->pointm
));
12891 if ((w
->current_matrix
->buffer
!= b
|| pt
!= w
->last_point
)
12892 && check_point_in_composition (w
->current_matrix
->buffer
,
12893 w
->last_point
, b
, pt
))
12894 b
->clip_changed
= 1;
12898 #define STOP_POLLING \
12899 do { if (! polling_stopped_here) stop_polling (); \
12900 polling_stopped_here = 1; } while (0)
12902 #define RESUME_POLLING \
12903 do { if (polling_stopped_here) start_polling (); \
12904 polling_stopped_here = 0; } while (0)
12907 /* Perhaps in the future avoid recentering windows if it
12908 is not necessary; currently that causes some problems. */
12911 redisplay_internal (void)
12913 struct window
*w
= XWINDOW (selected_window
);
12917 bool must_finish
= 0, match_p
;
12918 struct text_pos tlbufpos
, tlendpos
;
12919 int number_of_visible_frames
;
12922 int polling_stopped_here
= 0;
12923 Lisp_Object tail
, frame
;
12925 /* Non-zero means redisplay has to consider all windows on all
12926 frames. Zero means, only selected_window is considered. */
12927 int consider_all_windows_p
;
12929 /* Non-zero means redisplay has to redisplay the miniwindow. */
12930 int update_miniwindow_p
= 0;
12932 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12934 /* No redisplay if running in batch mode or frame is not yet fully
12935 initialized, or redisplay is explicitly turned off by setting
12936 Vinhibit_redisplay. */
12937 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12938 || !NILP (Vinhibit_redisplay
))
12941 /* Don't examine these until after testing Vinhibit_redisplay.
12942 When Emacs is shutting down, perhaps because its connection to
12943 X has dropped, we should not look at them at all. */
12944 fr
= XFRAME (w
->frame
);
12945 sf
= SELECTED_FRAME ();
12947 if (!fr
->glyphs_initialized_p
)
12950 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12951 if (popup_activated ())
12955 /* I don't think this happens but let's be paranoid. */
12956 if (redisplaying_p
)
12959 /* Record a function that clears redisplaying_p
12960 when we leave this function. */
12961 count
= SPECPDL_INDEX ();
12962 record_unwind_protect_void (unwind_redisplay
);
12963 redisplaying_p
= 1;
12964 specbind (Qinhibit_free_realized_faces
, Qnil
);
12966 /* Record this function, so it appears on the profiler's backtraces. */
12967 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
12969 FOR_EACH_FRAME (tail
, frame
)
12970 XFRAME (frame
)->already_hscrolled_p
= 0;
12973 /* Remember the currently selected window. */
12977 last_escape_glyph_frame
= NULL
;
12978 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
12979 last_glyphless_glyph_frame
= NULL
;
12980 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
12982 /* If face_change_count is non-zero, init_iterator will free all
12983 realized faces, which includes the faces referenced from current
12984 matrices. So, we can't reuse current matrices in this case. */
12985 if (face_change_count
)
12986 ++windows_or_buffers_changed
;
12988 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
12989 && FRAME_TTY (sf
)->previous_frame
!= sf
)
12991 /* Since frames on a single ASCII terminal share the same
12992 display area, displaying a different frame means redisplay
12993 the whole thing. */
12994 windows_or_buffers_changed
++;
12995 SET_FRAME_GARBAGED (sf
);
12997 set_tty_color_mode (FRAME_TTY (sf
), sf
);
12999 FRAME_TTY (sf
)->previous_frame
= sf
;
13002 /* Set the visible flags for all frames. Do this before checking for
13003 resized or garbaged frames; they want to know if their frames are
13004 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13005 number_of_visible_frames
= 0;
13007 FOR_EACH_FRAME (tail
, frame
)
13009 struct frame
*f
= XFRAME (frame
);
13011 if (FRAME_VISIBLE_P (f
))
13013 ++number_of_visible_frames
;
13014 /* Adjust matrices for visible frames only. */
13015 if (f
->fonts_changed
)
13017 adjust_frame_glyphs (f
);
13018 f
->fonts_changed
= 0;
13020 /* If cursor type has been changed on the frame
13021 other than selected, consider all frames. */
13022 if (f
!= sf
&& f
->cursor_type_changed
)
13023 update_mode_lines
++;
13025 clear_desired_matrices (f
);
13028 /* Notice any pending interrupt request to change frame size. */
13029 do_pending_window_change (1);
13031 /* do_pending_window_change could change the selected_window due to
13032 frame resizing which makes the selected window too small. */
13033 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13036 /* Clear frames marked as garbaged. */
13037 clear_garbaged_frames ();
13039 /* Build menubar and tool-bar items. */
13040 if (NILP (Vmemory_full
))
13041 prepare_menu_bars ();
13043 if (windows_or_buffers_changed
)
13044 update_mode_lines
++;
13046 reconsider_clip_changes (w
);
13048 /* In most cases selected window displays current buffer. */
13049 match_p
= XBUFFER (w
->contents
) == current_buffer
;
13054 /* Detect case that we need to write or remove a star in the mode line. */
13055 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13057 w
->update_mode_line
= 1;
13058 if (buffer_shared_and_changed ())
13059 update_mode_lines
++;
13062 /* Avoid invocation of point motion hooks by `current_column' below. */
13063 count1
= SPECPDL_INDEX ();
13064 specbind (Qinhibit_point_motion_hooks
, Qt
);
13066 if (mode_line_update_needed (w
))
13067 w
->update_mode_line
= 1;
13069 unbind_to (count1
, Qnil
);
13072 consider_all_windows_p
= (update_mode_lines
13073 || buffer_shared_and_changed ());
13075 /* If specs for an arrow have changed, do thorough redisplay
13076 to ensure we remove any arrow that should no longer exist. */
13077 if (overlay_arrows_changed_p ())
13078 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13080 /* Normally the message* functions will have already displayed and
13081 updated the echo area, but the frame may have been trashed, or
13082 the update may have been preempted, so display the echo area
13083 again here. Checking message_cleared_p captures the case that
13084 the echo area should be cleared. */
13085 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13086 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13087 || (message_cleared_p
13088 && minibuf_level
== 0
13089 /* If the mini-window is currently selected, this means the
13090 echo-area doesn't show through. */
13091 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13093 int window_height_changed_p
= echo_area_display (0);
13095 if (message_cleared_p
)
13096 update_miniwindow_p
= 1;
13100 /* If we don't display the current message, don't clear the
13101 message_cleared_p flag, because, if we did, we wouldn't clear
13102 the echo area in the next redisplay which doesn't preserve
13104 if (!display_last_displayed_message_p
)
13105 message_cleared_p
= 0;
13107 if (window_height_changed_p
)
13109 consider_all_windows_p
= 1;
13110 ++update_mode_lines
;
13111 ++windows_or_buffers_changed
;
13113 /* If window configuration was changed, frames may have been
13114 marked garbaged. Clear them or we will experience
13115 surprises wrt scrolling. */
13116 clear_garbaged_frames ();
13119 else if (EQ (selected_window
, minibuf_window
)
13120 && (current_buffer
->clip_changed
|| window_outdated (w
))
13121 && resize_mini_window (w
, 0))
13123 /* Resized active mini-window to fit the size of what it is
13124 showing if its contents might have changed. */
13126 /* FIXME: this causes all frames to be updated, which seems unnecessary
13127 since only the current frame needs to be considered. This function
13128 needs to be rewritten with two variables, consider_all_windows and
13129 consider_all_frames. */
13130 consider_all_windows_p
= 1;
13131 ++windows_or_buffers_changed
;
13132 ++update_mode_lines
;
13134 /* If window configuration was changed, frames may have been
13135 marked garbaged. Clear them or we will experience
13136 surprises wrt scrolling. */
13137 clear_garbaged_frames ();
13140 /* If showing the region, and mark has changed, we must redisplay
13141 the whole window. The assignment to this_line_start_pos prevents
13142 the optimization directly below this if-statement. */
13143 if (((!NILP (Vtransient_mark_mode
)
13144 && !NILP (BVAR (XBUFFER (w
->contents
), mark_active
)))
13145 != (w
->region_showing
> 0))
13146 || (w
->region_showing
13147 && w
->region_showing
13148 != XINT (Fmarker_position (BVAR (XBUFFER (w
->contents
), mark
)))))
13149 CHARPOS (this_line_start_pos
) = 0;
13151 /* Optimize the case that only the line containing the cursor in the
13152 selected window has changed. Variables starting with this_ are
13153 set in display_line and record information about the line
13154 containing the cursor. */
13155 tlbufpos
= this_line_start_pos
;
13156 tlendpos
= this_line_end_pos
;
13157 if (!consider_all_windows_p
13158 && CHARPOS (tlbufpos
) > 0
13159 && !w
->update_mode_line
13160 && !current_buffer
->clip_changed
13161 && !current_buffer
->prevent_redisplay_optimizations_p
13162 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13163 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13164 && !XFRAME (w
->frame
)->cursor_type_changed
13165 /* Make sure recorded data applies to current buffer, etc. */
13166 && this_line_buffer
== current_buffer
13169 && !w
->optional_new_start
13170 /* Point must be on the line that we have info recorded about. */
13171 && PT
>= CHARPOS (tlbufpos
)
13172 && PT
<= Z
- CHARPOS (tlendpos
)
13173 /* All text outside that line, including its final newline,
13174 must be unchanged. */
13175 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13176 CHARPOS (tlendpos
)))
13178 if (CHARPOS (tlbufpos
) > BEGV
13179 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13180 && (CHARPOS (tlbufpos
) == ZV
13181 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13182 /* Former continuation line has disappeared by becoming empty. */
13184 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13186 /* We have to handle the case of continuation around a
13187 wide-column character (see the comment in indent.c around
13190 For instance, in the following case:
13192 -------- Insert --------
13193 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13194 J_I_ ==> J_I_ `^^' are cursors.
13198 As we have to redraw the line above, we cannot use this
13202 int line_height_before
= this_line_pixel_height
;
13204 /* Note that start_display will handle the case that the
13205 line starting at tlbufpos is a continuation line. */
13206 start_display (&it
, w
, tlbufpos
);
13208 /* Implementation note: It this still necessary? */
13209 if (it
.current_x
!= this_line_start_x
)
13212 TRACE ((stderr
, "trying display optimization 1\n"));
13213 w
->cursor
.vpos
= -1;
13214 overlay_arrow_seen
= 0;
13215 it
.vpos
= this_line_vpos
;
13216 it
.current_y
= this_line_y
;
13217 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13218 display_line (&it
);
13220 /* If line contains point, is not continued,
13221 and ends at same distance from eob as before, we win. */
13222 if (w
->cursor
.vpos
>= 0
13223 /* Line is not continued, otherwise this_line_start_pos
13224 would have been set to 0 in display_line. */
13225 && CHARPOS (this_line_start_pos
)
13226 /* Line ends as before. */
13227 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13228 /* Line has same height as before. Otherwise other lines
13229 would have to be shifted up or down. */
13230 && this_line_pixel_height
== line_height_before
)
13232 /* If this is not the window's last line, we must adjust
13233 the charstarts of the lines below. */
13234 if (it
.current_y
< it
.last_visible_y
)
13236 struct glyph_row
*row
13237 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13238 ptrdiff_t delta
, delta_bytes
;
13240 /* We used to distinguish between two cases here,
13241 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13242 when the line ends in a newline or the end of the
13243 buffer's accessible portion. But both cases did
13244 the same, so they were collapsed. */
13246 - CHARPOS (tlendpos
)
13247 - MATRIX_ROW_START_CHARPOS (row
));
13248 delta_bytes
= (Z_BYTE
13249 - BYTEPOS (tlendpos
)
13250 - MATRIX_ROW_START_BYTEPOS (row
));
13252 increment_matrix_positions (w
->current_matrix
,
13253 this_line_vpos
+ 1,
13254 w
->current_matrix
->nrows
,
13255 delta
, delta_bytes
);
13258 /* If this row displays text now but previously didn't,
13259 or vice versa, w->window_end_vpos may have to be
13261 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13263 if (w
->window_end_vpos
< this_line_vpos
)
13264 w
->window_end_vpos
= this_line_vpos
;
13266 else if (w
->window_end_vpos
== this_line_vpos
13267 && this_line_vpos
> 0)
13268 w
->window_end_vpos
= this_line_vpos
- 1;
13269 w
->window_end_valid
= 0;
13271 /* Update hint: No need to try to scroll in update_window. */
13272 w
->desired_matrix
->no_scrolling_p
= 1;
13275 *w
->desired_matrix
->method
= 0;
13276 debug_method_add (w
, "optimization 1");
13278 #ifdef HAVE_WINDOW_SYSTEM
13279 update_window_fringes (w
, 0);
13286 else if (/* Cursor position hasn't changed. */
13287 PT
== w
->last_point
13288 /* Make sure the cursor was last displayed
13289 in this window. Otherwise we have to reposition it. */
13290 && 0 <= w
->cursor
.vpos
13291 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13295 do_pending_window_change (1);
13296 /* If selected_window changed, redisplay again. */
13297 if (WINDOWP (selected_window
)
13298 && (w
= XWINDOW (selected_window
)) != sw
)
13301 /* We used to always goto end_of_redisplay here, but this
13302 isn't enough if we have a blinking cursor. */
13303 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13304 goto end_of_redisplay
;
13308 /* If highlighting the region, or if the cursor is in the echo area,
13309 then we can't just move the cursor. */
13310 else if (! (!NILP (Vtransient_mark_mode
)
13311 && !NILP (BVAR (current_buffer
, mark_active
)))
13312 && (EQ (selected_window
,
13313 BVAR (current_buffer
, last_selected_window
))
13314 || highlight_nonselected_windows
)
13315 && !w
->region_showing
13316 && NILP (Vshow_trailing_whitespace
)
13317 && !cursor_in_echo_area
)
13320 struct glyph_row
*row
;
13322 /* Skip from tlbufpos to PT and see where it is. Note that
13323 PT may be in invisible text. If so, we will end at the
13324 next visible position. */
13325 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13326 NULL
, DEFAULT_FACE_ID
);
13327 it
.current_x
= this_line_start_x
;
13328 it
.current_y
= this_line_y
;
13329 it
.vpos
= this_line_vpos
;
13331 /* The call to move_it_to stops in front of PT, but
13332 moves over before-strings. */
13333 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13335 if (it
.vpos
== this_line_vpos
13336 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13339 eassert (this_line_vpos
== it
.vpos
);
13340 eassert (this_line_y
== it
.current_y
);
13341 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13343 *w
->desired_matrix
->method
= 0;
13344 debug_method_add (w
, "optimization 3");
13353 /* Text changed drastically or point moved off of line. */
13354 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13357 CHARPOS (this_line_start_pos
) = 0;
13358 consider_all_windows_p
|= buffer_shared_and_changed ();
13359 ++clear_face_cache_count
;
13360 #ifdef HAVE_WINDOW_SYSTEM
13361 ++clear_image_cache_count
;
13364 /* Build desired matrices, and update the display. If
13365 consider_all_windows_p is non-zero, do it for all windows on all
13366 frames. Otherwise do it for selected_window, only. */
13368 if (consider_all_windows_p
)
13370 FOR_EACH_FRAME (tail
, frame
)
13371 XFRAME (frame
)->updated_p
= 0;
13373 FOR_EACH_FRAME (tail
, frame
)
13375 struct frame
*f
= XFRAME (frame
);
13377 /* We don't have to do anything for unselected terminal
13379 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13380 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13385 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13387 /* Mark all the scroll bars to be removed; we'll redeem
13388 the ones we want when we redisplay their windows. */
13389 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13390 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13392 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13393 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13395 /* The X error handler may have deleted that frame. */
13396 if (!FRAME_LIVE_P (f
))
13399 /* Any scroll bars which redisplay_windows should have
13400 nuked should now go away. */
13401 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13402 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13404 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13406 /* If fonts changed on visible frame, display again. */
13407 if (f
->fonts_changed
)
13409 adjust_frame_glyphs (f
);
13410 f
->fonts_changed
= 0;
13414 /* See if we have to hscroll. */
13415 if (!f
->already_hscrolled_p
)
13417 f
->already_hscrolled_p
= 1;
13418 if (hscroll_windows (f
->root_window
))
13422 /* Prevent various kinds of signals during display
13423 update. stdio is not robust about handling
13424 signals, which can cause an apparent I/O
13426 if (interrupt_input
)
13427 unrequest_sigio ();
13430 /* Update the display. */
13431 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13432 pending
|= update_frame (f
, 0, 0);
13433 f
->cursor_type_changed
= 0;
13439 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13443 /* Do the mark_window_display_accurate after all windows have
13444 been redisplayed because this call resets flags in buffers
13445 which are needed for proper redisplay. */
13446 FOR_EACH_FRAME (tail
, frame
)
13448 struct frame
*f
= XFRAME (frame
);
13451 mark_window_display_accurate (f
->root_window
, 1);
13452 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13453 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13458 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13460 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13461 struct frame
*mini_frame
;
13463 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13464 /* Use list_of_error, not Qerror, so that
13465 we catch only errors and don't run the debugger. */
13466 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13468 redisplay_window_error
);
13469 if (update_miniwindow_p
)
13470 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13472 redisplay_window_error
);
13474 /* Compare desired and current matrices, perform output. */
13477 /* If fonts changed, display again. */
13478 if (sf
->fonts_changed
)
13481 /* Prevent various kinds of signals during display update.
13482 stdio is not robust about handling signals,
13483 which can cause an apparent I/O error. */
13484 if (interrupt_input
)
13485 unrequest_sigio ();
13488 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13490 if (hscroll_windows (selected_window
))
13493 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13494 pending
= update_frame (sf
, 0, 0);
13495 sf
->cursor_type_changed
= 0;
13498 /* We may have called echo_area_display at the top of this
13499 function. If the echo area is on another frame, that may
13500 have put text on a frame other than the selected one, so the
13501 above call to update_frame would not have caught it. Catch
13503 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13504 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13506 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13508 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13509 pending
|= update_frame (mini_frame
, 0, 0);
13510 mini_frame
->cursor_type_changed
= 0;
13511 if (!pending
&& hscroll_windows (mini_window
))
13516 /* If display was paused because of pending input, make sure we do a
13517 thorough update the next time. */
13520 /* Prevent the optimization at the beginning of
13521 redisplay_internal that tries a single-line update of the
13522 line containing the cursor in the selected window. */
13523 CHARPOS (this_line_start_pos
) = 0;
13525 /* Let the overlay arrow be updated the next time. */
13526 update_overlay_arrows (0);
13528 /* If we pause after scrolling, some rows in the current
13529 matrices of some windows are not valid. */
13530 if (!WINDOW_FULL_WIDTH_P (w
)
13531 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13532 update_mode_lines
= 1;
13536 if (!consider_all_windows_p
)
13538 /* This has already been done above if
13539 consider_all_windows_p is set. */
13540 mark_window_display_accurate_1 (w
, 1);
13542 /* Say overlay arrows are up to date. */
13543 update_overlay_arrows (1);
13545 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13546 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13549 update_mode_lines
= 0;
13550 windows_or_buffers_changed
= 0;
13553 /* Start SIGIO interrupts coming again. Having them off during the
13554 code above makes it less likely one will discard output, but not
13555 impossible, since there might be stuff in the system buffer here.
13556 But it is much hairier to try to do anything about that. */
13557 if (interrupt_input
)
13561 /* If a frame has become visible which was not before, redisplay
13562 again, so that we display it. Expose events for such a frame
13563 (which it gets when becoming visible) don't call the parts of
13564 redisplay constructing glyphs, so simply exposing a frame won't
13565 display anything in this case. So, we have to display these
13566 frames here explicitly. */
13571 FOR_EACH_FRAME (tail
, frame
)
13573 int this_is_visible
= 0;
13575 if (XFRAME (frame
)->visible
)
13576 this_is_visible
= 1;
13578 if (this_is_visible
)
13582 if (new_count
!= number_of_visible_frames
)
13583 windows_or_buffers_changed
++;
13586 /* Change frame size now if a change is pending. */
13587 do_pending_window_change (1);
13589 /* If we just did a pending size change, or have additional
13590 visible frames, or selected_window changed, redisplay again. */
13591 if ((windows_or_buffers_changed
&& !pending
)
13592 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13595 /* Clear the face and image caches.
13597 We used to do this only if consider_all_windows_p. But the cache
13598 needs to be cleared if a timer creates images in the current
13599 buffer (e.g. the test case in Bug#6230). */
13601 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13603 clear_face_cache (0);
13604 clear_face_cache_count
= 0;
13607 #ifdef HAVE_WINDOW_SYSTEM
13608 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13610 clear_image_caches (Qnil
);
13611 clear_image_cache_count
= 0;
13613 #endif /* HAVE_WINDOW_SYSTEM */
13616 unbind_to (count
, Qnil
);
13621 /* Redisplay, but leave alone any recent echo area message unless
13622 another message has been requested in its place.
13624 This is useful in situations where you need to redisplay but no
13625 user action has occurred, making it inappropriate for the message
13626 area to be cleared. See tracking_off and
13627 wait_reading_process_output for examples of these situations.
13629 FROM_WHERE is an integer saying from where this function was
13630 called. This is useful for debugging. */
13633 redisplay_preserve_echo_area (int from_where
)
13635 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13637 if (!NILP (echo_area_buffer
[1]))
13639 /* We have a previously displayed message, but no current
13640 message. Redisplay the previous message. */
13641 display_last_displayed_message_p
= 1;
13642 redisplay_internal ();
13643 display_last_displayed_message_p
= 0;
13646 redisplay_internal ();
13648 flush_frame (SELECTED_FRAME ());
13652 /* Function registered with record_unwind_protect in redisplay_internal. */
13655 unwind_redisplay (void)
13657 redisplaying_p
= 0;
13661 /* Mark the display of leaf window W as accurate or inaccurate.
13662 If ACCURATE_P is non-zero mark display of W as accurate. If
13663 ACCURATE_P is zero, arrange for W to be redisplayed the next
13664 time redisplay_internal is called. */
13667 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13669 struct buffer
*b
= XBUFFER (w
->contents
);
13671 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13672 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13673 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13677 b
->clip_changed
= 0;
13678 b
->prevent_redisplay_optimizations_p
= 0;
13680 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13681 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13682 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13683 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13685 w
->current_matrix
->buffer
= b
;
13686 w
->current_matrix
->begv
= BUF_BEGV (b
);
13687 w
->current_matrix
->zv
= BUF_ZV (b
);
13689 w
->last_cursor_vpos
= w
->cursor
.vpos
;
13690 w
->last_cursor_off_p
= w
->cursor_off_p
;
13692 if (w
== XWINDOW (selected_window
))
13693 w
->last_point
= BUF_PT (b
);
13695 w
->last_point
= marker_position (w
->pointm
);
13697 w
->window_end_valid
= 1;
13698 w
->update_mode_line
= 0;
13703 /* Mark the display of windows in the window tree rooted at WINDOW as
13704 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13705 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13706 be redisplayed the next time redisplay_internal is called. */
13709 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13713 for (; !NILP (window
); window
= w
->next
)
13715 w
= XWINDOW (window
);
13716 if (WINDOWP (w
->contents
))
13717 mark_window_display_accurate (w
->contents
, accurate_p
);
13719 mark_window_display_accurate_1 (w
, accurate_p
);
13723 update_overlay_arrows (1);
13725 /* Force a thorough redisplay the next time by setting
13726 last_arrow_position and last_arrow_string to t, which is
13727 unequal to any useful value of Voverlay_arrow_... */
13728 update_overlay_arrows (-1);
13732 /* Return value in display table DP (Lisp_Char_Table *) for character
13733 C. Since a display table doesn't have any parent, we don't have to
13734 follow parent. Do not call this function directly but use the
13735 macro DISP_CHAR_VECTOR. */
13738 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13742 if (ASCII_CHAR_P (c
))
13745 if (SUB_CHAR_TABLE_P (val
))
13746 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13752 XSETCHAR_TABLE (table
, dp
);
13753 val
= char_table_ref (table
, c
);
13762 /***********************************************************************
13764 ***********************************************************************/
13766 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13769 redisplay_windows (Lisp_Object window
)
13771 while (!NILP (window
))
13773 struct window
*w
= XWINDOW (window
);
13775 if (WINDOWP (w
->contents
))
13776 redisplay_windows (w
->contents
);
13777 else if (BUFFERP (w
->contents
))
13779 displayed_buffer
= XBUFFER (w
->contents
);
13780 /* Use list_of_error, not Qerror, so that
13781 we catch only errors and don't run the debugger. */
13782 internal_condition_case_1 (redisplay_window_0
, window
,
13784 redisplay_window_error
);
13792 redisplay_window_error (Lisp_Object ignore
)
13794 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13799 redisplay_window_0 (Lisp_Object window
)
13801 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13802 redisplay_window (window
, 0);
13807 redisplay_window_1 (Lisp_Object window
)
13809 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13810 redisplay_window (window
, 1);
13815 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13816 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13817 which positions recorded in ROW differ from current buffer
13820 Return 0 if cursor is not on this row, 1 otherwise. */
13823 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13824 struct glyph_matrix
*matrix
,
13825 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13828 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13829 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13830 struct glyph
*cursor
= NULL
;
13831 /* The last known character position in row. */
13832 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13834 ptrdiff_t pt_old
= PT
- delta
;
13835 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13836 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13837 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13838 /* A glyph beyond the edge of TEXT_AREA which we should never
13840 struct glyph
*glyphs_end
= end
;
13841 /* Non-zero means we've found a match for cursor position, but that
13842 glyph has the avoid_cursor_p flag set. */
13843 int match_with_avoid_cursor
= 0;
13844 /* Non-zero means we've seen at least one glyph that came from a
13846 int string_seen
= 0;
13847 /* Largest and smallest buffer positions seen so far during scan of
13849 ptrdiff_t bpos_max
= pos_before
;
13850 ptrdiff_t bpos_min
= pos_after
;
13851 /* Last buffer position covered by an overlay string with an integer
13852 `cursor' property. */
13853 ptrdiff_t bpos_covered
= 0;
13854 /* Non-zero means the display string on which to display the cursor
13855 comes from a text property, not from an overlay. */
13856 int string_from_text_prop
= 0;
13858 /* Don't even try doing anything if called for a mode-line or
13859 header-line row, since the rest of the code isn't prepared to
13860 deal with such calamities. */
13861 eassert (!row
->mode_line_p
);
13862 if (row
->mode_line_p
)
13865 /* Skip over glyphs not having an object at the start and the end of
13866 the row. These are special glyphs like truncation marks on
13867 terminal frames. */
13868 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13870 if (!row
->reversed_p
)
13873 && INTEGERP (glyph
->object
)
13874 && glyph
->charpos
< 0)
13876 x
+= glyph
->pixel_width
;
13880 && INTEGERP ((end
- 1)->object
)
13881 /* CHARPOS is zero for blanks and stretch glyphs
13882 inserted by extend_face_to_end_of_line. */
13883 && (end
- 1)->charpos
<= 0)
13885 glyph_before
= glyph
- 1;
13892 /* If the glyph row is reversed, we need to process it from back
13893 to front, so swap the edge pointers. */
13894 glyphs_end
= end
= glyph
- 1;
13895 glyph
+= row
->used
[TEXT_AREA
] - 1;
13897 while (glyph
> end
+ 1
13898 && INTEGERP (glyph
->object
)
13899 && glyph
->charpos
< 0)
13902 x
-= glyph
->pixel_width
;
13904 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13906 /* By default, in reversed rows we put the cursor on the
13907 rightmost (first in the reading order) glyph. */
13908 for (g
= end
+ 1; g
< glyph
; g
++)
13909 x
+= g
->pixel_width
;
13911 && INTEGERP ((end
+ 1)->object
)
13912 && (end
+ 1)->charpos
<= 0)
13914 glyph_before
= glyph
+ 1;
13918 else if (row
->reversed_p
)
13920 /* In R2L rows that don't display text, put the cursor on the
13921 rightmost glyph. Case in point: an empty last line that is
13922 part of an R2L paragraph. */
13924 /* Avoid placing the cursor on the last glyph of the row, where
13925 on terminal frames we hold the vertical border between
13926 adjacent windows. */
13927 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13928 && !WINDOW_RIGHTMOST_P (w
)
13929 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13931 x
= -1; /* will be computed below, at label compute_x */
13934 /* Step 1: Try to find the glyph whose character position
13935 corresponds to point. If that's not possible, find 2 glyphs
13936 whose character positions are the closest to point, one before
13937 point, the other after it. */
13938 if (!row
->reversed_p
)
13939 while (/* not marched to end of glyph row */
13941 /* glyph was not inserted by redisplay for internal purposes */
13942 && !INTEGERP (glyph
->object
))
13944 if (BUFFERP (glyph
->object
))
13946 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13948 if (glyph
->charpos
> bpos_max
)
13949 bpos_max
= glyph
->charpos
;
13950 if (glyph
->charpos
< bpos_min
)
13951 bpos_min
= glyph
->charpos
;
13952 if (!glyph
->avoid_cursor_p
)
13954 /* If we hit point, we've found the glyph on which to
13955 display the cursor. */
13958 match_with_avoid_cursor
= 0;
13961 /* See if we've found a better approximation to
13962 POS_BEFORE or to POS_AFTER. */
13963 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13965 pos_before
= glyph
->charpos
;
13966 glyph_before
= glyph
;
13968 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13970 pos_after
= glyph
->charpos
;
13971 glyph_after
= glyph
;
13974 else if (dpos
== 0)
13975 match_with_avoid_cursor
= 1;
13977 else if (STRINGP (glyph
->object
))
13979 Lisp_Object chprop
;
13980 ptrdiff_t glyph_pos
= glyph
->charpos
;
13982 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13984 if (!NILP (chprop
))
13986 /* If the string came from a `display' text property,
13987 look up the buffer position of that property and
13988 use that position to update bpos_max, as if we
13989 actually saw such a position in one of the row's
13990 glyphs. This helps with supporting integer values
13991 of `cursor' property on the display string in
13992 situations where most or all of the row's buffer
13993 text is completely covered by display properties,
13994 so that no glyph with valid buffer positions is
13995 ever seen in the row. */
13996 ptrdiff_t prop_pos
=
13997 string_buffer_position_lim (glyph
->object
, pos_before
,
14000 if (prop_pos
>= pos_before
)
14001 bpos_max
= prop_pos
- 1;
14003 if (INTEGERP (chprop
))
14005 bpos_covered
= bpos_max
+ XINT (chprop
);
14006 /* If the `cursor' property covers buffer positions up
14007 to and including point, we should display cursor on
14008 this glyph. Note that, if a `cursor' property on one
14009 of the string's characters has an integer value, we
14010 will break out of the loop below _before_ we get to
14011 the position match above. IOW, integer values of
14012 the `cursor' property override the "exact match for
14013 point" strategy of positioning the cursor. */
14014 /* Implementation note: bpos_max == pt_old when, e.g.,
14015 we are in an empty line, where bpos_max is set to
14016 MATRIX_ROW_START_CHARPOS, see above. */
14017 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14026 x
+= glyph
->pixel_width
;
14029 else if (glyph
> end
) /* row is reversed */
14030 while (!INTEGERP (glyph
->object
))
14032 if (BUFFERP (glyph
->object
))
14034 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14036 if (glyph
->charpos
> bpos_max
)
14037 bpos_max
= glyph
->charpos
;
14038 if (glyph
->charpos
< bpos_min
)
14039 bpos_min
= glyph
->charpos
;
14040 if (!glyph
->avoid_cursor_p
)
14044 match_with_avoid_cursor
= 0;
14047 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14049 pos_before
= glyph
->charpos
;
14050 glyph_before
= glyph
;
14052 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14054 pos_after
= glyph
->charpos
;
14055 glyph_after
= glyph
;
14058 else if (dpos
== 0)
14059 match_with_avoid_cursor
= 1;
14061 else if (STRINGP (glyph
->object
))
14063 Lisp_Object chprop
;
14064 ptrdiff_t glyph_pos
= glyph
->charpos
;
14066 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14068 if (!NILP (chprop
))
14070 ptrdiff_t prop_pos
=
14071 string_buffer_position_lim (glyph
->object
, pos_before
,
14074 if (prop_pos
>= pos_before
)
14075 bpos_max
= prop_pos
- 1;
14077 if (INTEGERP (chprop
))
14079 bpos_covered
= bpos_max
+ XINT (chprop
);
14080 /* If the `cursor' property covers buffer positions up
14081 to and including point, we should display cursor on
14083 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14092 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14094 x
--; /* can't use any pixel_width */
14097 x
-= glyph
->pixel_width
;
14100 /* Step 2: If we didn't find an exact match for point, we need to
14101 look for a proper place to put the cursor among glyphs between
14102 GLYPH_BEFORE and GLYPH_AFTER. */
14103 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14104 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14105 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14107 /* An empty line has a single glyph whose OBJECT is zero and
14108 whose CHARPOS is the position of a newline on that line.
14109 Note that on a TTY, there are more glyphs after that, which
14110 were produced by extend_face_to_end_of_line, but their
14111 CHARPOS is zero or negative. */
14113 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14114 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14115 /* On a TTY, continued and truncated rows also have a glyph at
14116 their end whose OBJECT is zero and whose CHARPOS is
14117 positive (the continuation and truncation glyphs), but such
14118 rows are obviously not "empty". */
14119 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14121 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14123 ptrdiff_t ellipsis_pos
;
14125 /* Scan back over the ellipsis glyphs. */
14126 if (!row
->reversed_p
)
14128 ellipsis_pos
= (glyph
- 1)->charpos
;
14129 while (glyph
> row
->glyphs
[TEXT_AREA
]
14130 && (glyph
- 1)->charpos
== ellipsis_pos
)
14131 glyph
--, x
-= glyph
->pixel_width
;
14132 /* That loop always goes one position too far, including
14133 the glyph before the ellipsis. So scan forward over
14135 x
+= glyph
->pixel_width
;
14138 else /* row is reversed */
14140 ellipsis_pos
= (glyph
+ 1)->charpos
;
14141 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14142 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14143 glyph
++, x
+= glyph
->pixel_width
;
14144 x
-= glyph
->pixel_width
;
14148 else if (match_with_avoid_cursor
)
14150 cursor
= glyph_after
;
14153 else if (string_seen
)
14155 int incr
= row
->reversed_p
? -1 : +1;
14157 /* Need to find the glyph that came out of a string which is
14158 present at point. That glyph is somewhere between
14159 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14160 positioned between POS_BEFORE and POS_AFTER in the
14162 struct glyph
*start
, *stop
;
14163 ptrdiff_t pos
= pos_before
;
14167 /* If the row ends in a newline from a display string,
14168 reordering could have moved the glyphs belonging to the
14169 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14170 in this case we extend the search to the last glyph in
14171 the row that was not inserted by redisplay. */
14172 if (row
->ends_in_newline_from_string_p
)
14175 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14178 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14179 correspond to POS_BEFORE and POS_AFTER, respectively. We
14180 need START and STOP in the order that corresponds to the
14181 row's direction as given by its reversed_p flag. If the
14182 directionality of characters between POS_BEFORE and
14183 POS_AFTER is the opposite of the row's base direction,
14184 these characters will have been reordered for display,
14185 and we need to reverse START and STOP. */
14186 if (!row
->reversed_p
)
14188 start
= min (glyph_before
, glyph_after
);
14189 stop
= max (glyph_before
, glyph_after
);
14193 start
= max (glyph_before
, glyph_after
);
14194 stop
= min (glyph_before
, glyph_after
);
14196 for (glyph
= start
+ incr
;
14197 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14200 /* Any glyphs that come from the buffer are here because
14201 of bidi reordering. Skip them, and only pay
14202 attention to glyphs that came from some string. */
14203 if (STRINGP (glyph
->object
))
14207 /* If the display property covers the newline, we
14208 need to search for it one position farther. */
14209 ptrdiff_t lim
= pos_after
14210 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14212 string_from_text_prop
= 0;
14213 str
= glyph
->object
;
14214 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14215 if (tem
== 0 /* from overlay */
14218 /* If the string from which this glyph came is
14219 found in the buffer at point, or at position
14220 that is closer to point than pos_after, then
14221 we've found the glyph we've been looking for.
14222 If it comes from an overlay (tem == 0), and
14223 it has the `cursor' property on one of its
14224 glyphs, record that glyph as a candidate for
14225 displaying the cursor. (As in the
14226 unidirectional version, we will display the
14227 cursor on the last candidate we find.) */
14230 || (tem
- pt_old
> 0 && tem
< pos_after
))
14232 /* The glyphs from this string could have
14233 been reordered. Find the one with the
14234 smallest string position. Or there could
14235 be a character in the string with the
14236 `cursor' property, which means display
14237 cursor on that character's glyph. */
14238 ptrdiff_t strpos
= glyph
->charpos
;
14243 string_from_text_prop
= 1;
14246 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14247 && EQ (glyph
->object
, str
);
14251 ptrdiff_t gpos
= glyph
->charpos
;
14253 cprop
= Fget_char_property (make_number (gpos
),
14261 if (tem
&& glyph
->charpos
< strpos
)
14263 strpos
= glyph
->charpos
;
14269 || (tem
- pt_old
> 0 && tem
< pos_after
))
14273 pos
= tem
+ 1; /* don't find previous instances */
14275 /* This string is not what we want; skip all of the
14276 glyphs that came from it. */
14277 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14278 && EQ (glyph
->object
, str
))
14285 /* If we reached the end of the line, and END was from a string,
14286 the cursor is not on this line. */
14288 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14289 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14290 && STRINGP (end
->object
)
14291 && row
->continued_p
)
14294 /* A truncated row may not include PT among its character positions.
14295 Setting the cursor inside the scroll margin will trigger
14296 recalculation of hscroll in hscroll_window_tree. But if a
14297 display string covers point, defer to the string-handling
14298 code below to figure this out. */
14299 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14301 cursor
= glyph_before
;
14304 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14305 /* Zero-width characters produce no glyphs. */
14307 && (row
->reversed_p
14308 ? glyph_after
> glyphs_end
14309 : glyph_after
< glyphs_end
)))
14311 cursor
= glyph_after
;
14317 if (cursor
!= NULL
)
14319 else if (glyph
== glyphs_end
14320 && pos_before
== pos_after
14321 && STRINGP ((row
->reversed_p
14322 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14323 : row
->glyphs
[TEXT_AREA
])->object
))
14325 /* If all the glyphs of this row came from strings, put the
14326 cursor on the first glyph of the row. This avoids having the
14327 cursor outside of the text area in this very rare and hard
14331 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14332 : row
->glyphs
[TEXT_AREA
];
14338 /* Need to compute x that corresponds to GLYPH. */
14339 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14341 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14343 x
+= g
->pixel_width
;
14347 /* ROW could be part of a continued line, which, under bidi
14348 reordering, might have other rows whose start and end charpos
14349 occlude point. Only set w->cursor if we found a better
14350 approximation to the cursor position than we have from previously
14351 examined candidate rows belonging to the same continued line. */
14352 if (/* we already have a candidate row */
14353 w
->cursor
.vpos
>= 0
14354 /* that candidate is not the row we are processing */
14355 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14356 /* Make sure cursor.vpos specifies a row whose start and end
14357 charpos occlude point, and it is valid candidate for being a
14358 cursor-row. This is because some callers of this function
14359 leave cursor.vpos at the row where the cursor was displayed
14360 during the last redisplay cycle. */
14361 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14362 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14363 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14366 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14368 /* Don't consider glyphs that are outside TEXT_AREA. */
14369 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14371 /* Keep the candidate whose buffer position is the closest to
14372 point or has the `cursor' property. */
14373 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14374 w
->cursor
.hpos
>= 0
14375 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14376 && ((BUFFERP (g1
->object
)
14377 && (g1
->charpos
== pt_old
/* an exact match always wins */
14378 || (BUFFERP (glyph
->object
)
14379 && eabs (g1
->charpos
- pt_old
)
14380 < eabs (glyph
->charpos
- pt_old
))))
14381 /* previous candidate is a glyph from a string that has
14382 a non-nil `cursor' property */
14383 || (STRINGP (g1
->object
)
14384 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14385 Qcursor
, g1
->object
))
14386 /* previous candidate is from the same display
14387 string as this one, and the display string
14388 came from a text property */
14389 || (EQ (g1
->object
, glyph
->object
)
14390 && string_from_text_prop
)
14391 /* this candidate is from newline and its
14392 position is not an exact match */
14393 || (INTEGERP (glyph
->object
)
14394 && glyph
->charpos
!= pt_old
)))))
14396 /* If this candidate gives an exact match, use that. */
14397 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14398 /* If this candidate is a glyph created for the
14399 terminating newline of a line, and point is on that
14400 newline, it wins because it's an exact match. */
14401 || (!row
->continued_p
14402 && INTEGERP (glyph
->object
)
14403 && glyph
->charpos
== 0
14404 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14405 /* Otherwise, keep the candidate that comes from a row
14406 spanning less buffer positions. This may win when one or
14407 both candidate positions are on glyphs that came from
14408 display strings, for which we cannot compare buffer
14410 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14411 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14412 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14415 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14417 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14418 w
->cursor
.y
= row
->y
+ dy
;
14420 if (w
== XWINDOW (selected_window
))
14422 if (!row
->continued_p
14423 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14426 this_line_buffer
= XBUFFER (w
->contents
);
14428 CHARPOS (this_line_start_pos
)
14429 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14430 BYTEPOS (this_line_start_pos
)
14431 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14433 CHARPOS (this_line_end_pos
)
14434 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14435 BYTEPOS (this_line_end_pos
)
14436 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14438 this_line_y
= w
->cursor
.y
;
14439 this_line_pixel_height
= row
->height
;
14440 this_line_vpos
= w
->cursor
.vpos
;
14441 this_line_start_x
= row
->x
;
14444 CHARPOS (this_line_start_pos
) = 0;
14451 /* Run window scroll functions, if any, for WINDOW with new window
14452 start STARTP. Sets the window start of WINDOW to that position.
14454 We assume that the window's buffer is really current. */
14456 static struct text_pos
14457 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14459 struct window
*w
= XWINDOW (window
);
14460 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14462 eassert (current_buffer
== XBUFFER (w
->contents
));
14464 if (!NILP (Vwindow_scroll_functions
))
14466 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14467 make_number (CHARPOS (startp
)));
14468 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14469 /* In case the hook functions switch buffers. */
14470 set_buffer_internal (XBUFFER (w
->contents
));
14477 /* Make sure the line containing the cursor is fully visible.
14478 A value of 1 means there is nothing to be done.
14479 (Either the line is fully visible, or it cannot be made so,
14480 or we cannot tell.)
14482 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14483 is higher than window.
14485 A value of 0 means the caller should do scrolling
14486 as if point had gone off the screen. */
14489 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14491 struct glyph_matrix
*matrix
;
14492 struct glyph_row
*row
;
14495 if (!make_cursor_line_fully_visible_p
)
14498 /* It's not always possible to find the cursor, e.g, when a window
14499 is full of overlay strings. Don't do anything in that case. */
14500 if (w
->cursor
.vpos
< 0)
14503 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14504 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14506 /* If the cursor row is not partially visible, there's nothing to do. */
14507 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14510 /* If the row the cursor is in is taller than the window's height,
14511 it's not clear what to do, so do nothing. */
14512 window_height
= window_box_height (w
);
14513 if (row
->height
>= window_height
)
14515 if (!force_p
|| MINI_WINDOW_P (w
)
14516 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14523 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14524 non-zero means only WINDOW is redisplayed in redisplay_internal.
14525 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14526 in redisplay_window to bring a partially visible line into view in
14527 the case that only the cursor has moved.
14529 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14530 last screen line's vertical height extends past the end of the screen.
14534 1 if scrolling succeeded
14536 0 if scrolling didn't find point.
14538 -1 if new fonts have been loaded so that we must interrupt
14539 redisplay, adjust glyph matrices, and try again. */
14545 SCROLLING_NEED_LARGER_MATRICES
14548 /* If scroll-conservatively is more than this, never recenter.
14550 If you change this, don't forget to update the doc string of
14551 `scroll-conservatively' and the Emacs manual. */
14552 #define SCROLL_LIMIT 100
14555 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14556 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14557 int temp_scroll_step
, int last_line_misfit
)
14559 struct window
*w
= XWINDOW (window
);
14560 struct frame
*f
= XFRAME (w
->frame
);
14561 struct text_pos pos
, startp
;
14563 int this_scroll_margin
, scroll_max
, rc
, height
;
14564 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14565 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14566 Lisp_Object aggressive
;
14567 /* We will never try scrolling more than this number of lines. */
14568 int scroll_limit
= SCROLL_LIMIT
;
14569 int frame_line_height
= default_line_pixel_height (w
);
14570 int window_total_lines
14571 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14574 debug_method_add (w
, "try_scrolling");
14577 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14579 /* Compute scroll margin height in pixels. We scroll when point is
14580 within this distance from the top or bottom of the window. */
14581 if (scroll_margin
> 0)
14582 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14583 * frame_line_height
;
14585 this_scroll_margin
= 0;
14587 /* Force arg_scroll_conservatively to have a reasonable value, to
14588 avoid scrolling too far away with slow move_it_* functions. Note
14589 that the user can supply scroll-conservatively equal to
14590 `most-positive-fixnum', which can be larger than INT_MAX. */
14591 if (arg_scroll_conservatively
> scroll_limit
)
14593 arg_scroll_conservatively
= scroll_limit
+ 1;
14594 scroll_max
= scroll_limit
* frame_line_height
;
14596 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14597 /* Compute how much we should try to scroll maximally to bring
14598 point into view. */
14599 scroll_max
= (max (scroll_step
,
14600 max (arg_scroll_conservatively
, temp_scroll_step
))
14601 * frame_line_height
);
14602 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14603 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14604 /* We're trying to scroll because of aggressive scrolling but no
14605 scroll_step is set. Choose an arbitrary one. */
14606 scroll_max
= 10 * frame_line_height
;
14612 /* Decide whether to scroll down. */
14613 if (PT
> CHARPOS (startp
))
14615 int scroll_margin_y
;
14617 /* Compute the pixel ypos of the scroll margin, then move IT to
14618 either that ypos or PT, whichever comes first. */
14619 start_display (&it
, w
, startp
);
14620 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14621 - frame_line_height
* extra_scroll_margin_lines
;
14622 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14623 (MOVE_TO_POS
| MOVE_TO_Y
));
14625 if (PT
> CHARPOS (it
.current
.pos
))
14627 int y0
= line_bottom_y (&it
);
14628 /* Compute how many pixels below window bottom to stop searching
14629 for PT. This avoids costly search for PT that is far away if
14630 the user limited scrolling by a small number of lines, but
14631 always finds PT if scroll_conservatively is set to a large
14632 number, such as most-positive-fixnum. */
14633 int slack
= max (scroll_max
, 10 * frame_line_height
);
14634 int y_to_move
= it
.last_visible_y
+ slack
;
14636 /* Compute the distance from the scroll margin to PT or to
14637 the scroll limit, whichever comes first. This should
14638 include the height of the cursor line, to make that line
14640 move_it_to (&it
, PT
, -1, y_to_move
,
14641 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14642 dy
= line_bottom_y (&it
) - y0
;
14644 if (dy
> scroll_max
)
14645 return SCROLLING_FAILED
;
14654 /* Point is in or below the bottom scroll margin, so move the
14655 window start down. If scrolling conservatively, move it just
14656 enough down to make point visible. If scroll_step is set,
14657 move it down by scroll_step. */
14658 if (arg_scroll_conservatively
)
14660 = min (max (dy
, frame_line_height
),
14661 frame_line_height
* arg_scroll_conservatively
);
14662 else if (scroll_step
|| temp_scroll_step
)
14663 amount_to_scroll
= scroll_max
;
14666 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14667 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14668 if (NUMBERP (aggressive
))
14670 double float_amount
= XFLOATINT (aggressive
) * height
;
14671 int aggressive_scroll
= float_amount
;
14672 if (aggressive_scroll
== 0 && float_amount
> 0)
14673 aggressive_scroll
= 1;
14674 /* Don't let point enter the scroll margin near top of
14675 the window. This could happen if the value of
14676 scroll_up_aggressively is too large and there are
14677 non-zero margins, because scroll_up_aggressively
14678 means put point that fraction of window height
14679 _from_the_bottom_margin_. */
14680 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14681 aggressive_scroll
= height
- 2*this_scroll_margin
;
14682 amount_to_scroll
= dy
+ aggressive_scroll
;
14686 if (amount_to_scroll
<= 0)
14687 return SCROLLING_FAILED
;
14689 start_display (&it
, w
, startp
);
14690 if (arg_scroll_conservatively
<= scroll_limit
)
14691 move_it_vertically (&it
, amount_to_scroll
);
14694 /* Extra precision for users who set scroll-conservatively
14695 to a large number: make sure the amount we scroll
14696 the window start is never less than amount_to_scroll,
14697 which was computed as distance from window bottom to
14698 point. This matters when lines at window top and lines
14699 below window bottom have different height. */
14701 void *it1data
= NULL
;
14702 /* We use a temporary it1 because line_bottom_y can modify
14703 its argument, if it moves one line down; see there. */
14706 SAVE_IT (it1
, it
, it1data
);
14707 start_y
= line_bottom_y (&it1
);
14709 RESTORE_IT (&it
, &it
, it1data
);
14710 move_it_by_lines (&it
, 1);
14711 SAVE_IT (it1
, it
, it1data
);
14712 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14715 /* If STARTP is unchanged, move it down another screen line. */
14716 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14717 move_it_by_lines (&it
, 1);
14718 startp
= it
.current
.pos
;
14722 struct text_pos scroll_margin_pos
= startp
;
14725 /* See if point is inside the scroll margin at the top of the
14727 if (this_scroll_margin
)
14731 start_display (&it
, w
, startp
);
14732 y_start
= it
.current_y
;
14733 move_it_vertically (&it
, this_scroll_margin
);
14734 scroll_margin_pos
= it
.current
.pos
;
14735 /* If we didn't move enough before hitting ZV, request
14736 additional amount of scroll, to move point out of the
14738 if (IT_CHARPOS (it
) == ZV
14739 && it
.current_y
- y_start
< this_scroll_margin
)
14740 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14743 if (PT
< CHARPOS (scroll_margin_pos
))
14745 /* Point is in the scroll margin at the top of the window or
14746 above what is displayed in the window. */
14749 /* Compute the vertical distance from PT to the scroll
14750 margin position. Move as far as scroll_max allows, or
14751 one screenful, or 10 screen lines, whichever is largest.
14752 Give up if distance is greater than scroll_max or if we
14753 didn't reach the scroll margin position. */
14754 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14755 start_display (&it
, w
, pos
);
14757 y_to_move
= max (it
.last_visible_y
,
14758 max (scroll_max
, 10 * frame_line_height
));
14759 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14761 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14762 dy
= it
.current_y
- y0
;
14763 if (dy
> scroll_max
14764 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14765 return SCROLLING_FAILED
;
14767 /* Additional scroll for when ZV was too close to point. */
14770 /* Compute new window start. */
14771 start_display (&it
, w
, startp
);
14773 if (arg_scroll_conservatively
)
14774 amount_to_scroll
= max (dy
, frame_line_height
*
14775 max (scroll_step
, temp_scroll_step
));
14776 else if (scroll_step
|| temp_scroll_step
)
14777 amount_to_scroll
= scroll_max
;
14780 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14781 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14782 if (NUMBERP (aggressive
))
14784 double float_amount
= XFLOATINT (aggressive
) * height
;
14785 int aggressive_scroll
= float_amount
;
14786 if (aggressive_scroll
== 0 && float_amount
> 0)
14787 aggressive_scroll
= 1;
14788 /* Don't let point enter the scroll margin near
14789 bottom of the window, if the value of
14790 scroll_down_aggressively happens to be too
14792 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14793 aggressive_scroll
= height
- 2*this_scroll_margin
;
14794 amount_to_scroll
= dy
+ aggressive_scroll
;
14798 if (amount_to_scroll
<= 0)
14799 return SCROLLING_FAILED
;
14801 move_it_vertically_backward (&it
, amount_to_scroll
);
14802 startp
= it
.current
.pos
;
14806 /* Run window scroll functions. */
14807 startp
= run_window_scroll_functions (window
, startp
);
14809 /* Display the window. Give up if new fonts are loaded, or if point
14811 if (!try_window (window
, startp
, 0))
14812 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14813 else if (w
->cursor
.vpos
< 0)
14815 clear_glyph_matrix (w
->desired_matrix
);
14816 rc
= SCROLLING_FAILED
;
14820 /* Maybe forget recorded base line for line number display. */
14821 if (!just_this_one_p
14822 || current_buffer
->clip_changed
14823 || BEG_UNCHANGED
< CHARPOS (startp
))
14824 w
->base_line_number
= 0;
14826 /* If cursor ends up on a partially visible line,
14827 treat that as being off the bottom of the screen. */
14828 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14829 /* It's possible that the cursor is on the first line of the
14830 buffer, which is partially obscured due to a vscroll
14831 (Bug#7537). In that case, avoid looping forever . */
14832 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14834 clear_glyph_matrix (w
->desired_matrix
);
14835 ++extra_scroll_margin_lines
;
14838 rc
= SCROLLING_SUCCESS
;
14845 /* Compute a suitable window start for window W if display of W starts
14846 on a continuation line. Value is non-zero if a new window start
14849 The new window start will be computed, based on W's width, starting
14850 from the start of the continued line. It is the start of the
14851 screen line with the minimum distance from the old start W->start. */
14854 compute_window_start_on_continuation_line (struct window
*w
)
14856 struct text_pos pos
, start_pos
;
14857 int window_start_changed_p
= 0;
14859 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14861 /* If window start is on a continuation line... Window start may be
14862 < BEGV in case there's invisible text at the start of the
14863 buffer (M-x rmail, for example). */
14864 if (CHARPOS (start_pos
) > BEGV
14865 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14868 struct glyph_row
*row
;
14870 /* Handle the case that the window start is out of range. */
14871 if (CHARPOS (start_pos
) < BEGV
)
14872 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14873 else if (CHARPOS (start_pos
) > ZV
)
14874 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14876 /* Find the start of the continued line. This should be fast
14877 because find_newline is fast (newline cache). */
14878 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14879 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14880 row
, DEFAULT_FACE_ID
);
14881 reseat_at_previous_visible_line_start (&it
);
14883 /* If the line start is "too far" away from the window start,
14884 say it takes too much time to compute a new window start. */
14885 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14886 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14888 int min_distance
, distance
;
14890 /* Move forward by display lines to find the new window
14891 start. If window width was enlarged, the new start can
14892 be expected to be > the old start. If window width was
14893 decreased, the new window start will be < the old start.
14894 So, we're looking for the display line start with the
14895 minimum distance from the old window start. */
14896 pos
= it
.current
.pos
;
14897 min_distance
= INFINITY
;
14898 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14899 distance
< min_distance
)
14901 min_distance
= distance
;
14902 pos
= it
.current
.pos
;
14903 if (it
.line_wrap
== WORD_WRAP
)
14905 /* Under WORD_WRAP, move_it_by_lines is likely to
14906 overshoot and stop not at the first, but the
14907 second character from the left margin. So in
14908 that case, we need a more tight control on the X
14909 coordinate of the iterator than move_it_by_lines
14910 promises in its contract. The method is to first
14911 go to the last (rightmost) visible character of a
14912 line, then move to the leftmost character on the
14913 next line in a separate call. */
14914 move_it_to (&it
, ZV
, it
.last_visible_x
, it
.current_y
, -1,
14915 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14916 move_it_to (&it
, ZV
, 0,
14917 it
.current_y
+ it
.max_ascent
+ it
.max_descent
, -1,
14918 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14921 move_it_by_lines (&it
, 1);
14924 /* Set the window start there. */
14925 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14926 window_start_changed_p
= 1;
14930 return window_start_changed_p
;
14934 /* Try cursor movement in case text has not changed in window WINDOW,
14935 with window start STARTP. Value is
14937 CURSOR_MOVEMENT_SUCCESS if successful
14939 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14941 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14942 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14943 we want to scroll as if scroll-step were set to 1. See the code.
14945 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14946 which case we have to abort this redisplay, and adjust matrices
14951 CURSOR_MOVEMENT_SUCCESS
,
14952 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14953 CURSOR_MOVEMENT_MUST_SCROLL
,
14954 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14958 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14960 struct window
*w
= XWINDOW (window
);
14961 struct frame
*f
= XFRAME (w
->frame
);
14962 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14965 if (inhibit_try_cursor_movement
)
14969 /* Previously, there was a check for Lisp integer in the
14970 if-statement below. Now, this field is converted to
14971 ptrdiff_t, thus zero means invalid position in a buffer. */
14972 eassert (w
->last_point
> 0);
14973 /* Likewise there was a check whether window_end_vpos is nil or larger
14974 than the window. Now window_end_vpos is int and so never nil, but
14975 let's leave eassert to check whether it fits in the window. */
14976 eassert (w
->window_end_vpos
< w
->current_matrix
->nrows
);
14978 /* Handle case where text has not changed, only point, and it has
14979 not moved off the frame. */
14980 if (/* Point may be in this window. */
14981 PT
>= CHARPOS (startp
)
14982 /* Selective display hasn't changed. */
14983 && !current_buffer
->clip_changed
14984 /* Function force-mode-line-update is used to force a thorough
14985 redisplay. It sets either windows_or_buffers_changed or
14986 update_mode_lines. So don't take a shortcut here for these
14988 && !update_mode_lines
14989 && !windows_or_buffers_changed
14990 && !f
->cursor_type_changed
14991 /* Can't use this case if highlighting a region. When a
14992 region exists, cursor movement has to do more than just
14994 && markpos_of_region () < 0
14995 && !w
->region_showing
14996 && NILP (Vshow_trailing_whitespace
)
14997 /* This code is not used for mini-buffer for the sake of the case
14998 of redisplaying to replace an echo area message; since in
14999 that case the mini-buffer contents per se are usually
15000 unchanged. This code is of no real use in the mini-buffer
15001 since the handling of this_line_start_pos, etc., in redisplay
15002 handles the same cases. */
15003 && !EQ (window
, minibuf_window
)
15004 && (FRAME_WINDOW_P (f
)
15005 || !overlay_arrow_in_current_buffer_p ()))
15007 int this_scroll_margin
, top_scroll_margin
;
15008 struct glyph_row
*row
= NULL
;
15009 int frame_line_height
= default_line_pixel_height (w
);
15010 int window_total_lines
15011 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15014 debug_method_add (w
, "cursor movement");
15017 /* Scroll if point within this distance from the top or bottom
15018 of the window. This is a pixel value. */
15019 if (scroll_margin
> 0)
15021 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
15022 this_scroll_margin
*= frame_line_height
;
15025 this_scroll_margin
= 0;
15027 top_scroll_margin
= this_scroll_margin
;
15028 if (WINDOW_WANTS_HEADER_LINE_P (w
))
15029 top_scroll_margin
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15031 /* Start with the row the cursor was displayed during the last
15032 not paused redisplay. Give up if that row is not valid. */
15033 if (w
->last_cursor_vpos
< 0
15034 || w
->last_cursor_vpos
>= w
->current_matrix
->nrows
)
15035 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15038 row
= MATRIX_ROW (w
->current_matrix
, w
->last_cursor_vpos
);
15039 if (row
->mode_line_p
)
15041 if (!row
->enabled_p
)
15042 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15045 if (rc
== CURSOR_MOVEMENT_CANNOT_BE_USED
)
15047 int scroll_p
= 0, must_scroll
= 0;
15048 int last_y
= window_text_bottom_y (w
) - this_scroll_margin
;
15050 if (PT
> w
->last_point
)
15052 /* Point has moved forward. */
15053 while (MATRIX_ROW_END_CHARPOS (row
) < PT
15054 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
)
15056 eassert (row
->enabled_p
);
15060 /* If the end position of a row equals the start
15061 position of the next row, and PT is at that position,
15062 we would rather display cursor in the next line. */
15063 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15064 && MATRIX_ROW_END_CHARPOS (row
) == PT
15065 && row
< MATRIX_MODE_LINE_ROW (w
->current_matrix
)
15066 && MATRIX_ROW_START_CHARPOS (row
+1) == PT
15067 && !cursor_row_p (row
))
15070 /* If within the scroll margin, scroll. Note that
15071 MATRIX_ROW_BOTTOM_Y gives the pixel position at which
15072 the next line would be drawn, and that
15073 this_scroll_margin can be zero. */
15074 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
15075 || PT
> MATRIX_ROW_END_CHARPOS (row
)
15076 /* Line is completely visible last line in window
15077 and PT is to be set in the next line. */
15078 || (MATRIX_ROW_BOTTOM_Y (row
) == last_y
15079 && PT
== MATRIX_ROW_END_CHARPOS (row
)
15080 && !row
->ends_at_zv_p
15081 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
15084 else if (PT
< w
->last_point
)
15086 /* Cursor has to be moved backward. Note that PT >=
15087 CHARPOS (startp) because of the outer if-statement. */
15088 while (!row
->mode_line_p
15089 && (MATRIX_ROW_START_CHARPOS (row
) > PT
15090 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15091 && (MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row
)
15092 || (/* STARTS_IN_MIDDLE_OF_STRING_P (row) */
15093 row
> w
->current_matrix
->rows
15094 && (row
-1)->ends_in_newline_from_string_p
))))
15095 && (row
->y
> top_scroll_margin
15096 || CHARPOS (startp
) == BEGV
))
15098 eassert (row
->enabled_p
);
15102 /* Consider the following case: Window starts at BEGV,
15103 there is invisible, intangible text at BEGV, so that
15104 display starts at some point START > BEGV. It can
15105 happen that we are called with PT somewhere between
15106 BEGV and START. Try to handle that case. */
15107 if (row
< w
->current_matrix
->rows
15108 || row
->mode_line_p
)
15110 row
= w
->current_matrix
->rows
;
15111 if (row
->mode_line_p
)
15115 /* Due to newlines in overlay strings, we may have to
15116 skip forward over overlay strings. */
15117 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15118 && MATRIX_ROW_END_CHARPOS (row
) == PT
15119 && !cursor_row_p (row
))
15122 /* If within the scroll margin, scroll. */
15123 if (row
->y
< top_scroll_margin
15124 && CHARPOS (startp
) != BEGV
)
15129 /* Cursor did not move. So don't scroll even if cursor line
15130 is partially visible, as it was so before. */
15131 rc
= CURSOR_MOVEMENT_SUCCESS
;
15134 if (PT
< MATRIX_ROW_START_CHARPOS (row
)
15135 || PT
> MATRIX_ROW_END_CHARPOS (row
))
15137 /* if PT is not in the glyph row, give up. */
15138 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15141 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15142 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15144 struct glyph_row
*row1
;
15146 /* If rows are bidi-reordered and point moved, back up
15147 until we find a row that does not belong to a
15148 continuation line. This is because we must consider
15149 all rows of a continued line as candidates for the
15150 new cursor positioning, since row start and end
15151 positions change non-linearly with vertical position
15153 /* FIXME: Revisit this when glyph ``spilling'' in
15154 continuation lines' rows is implemented for
15155 bidi-reordered rows. */
15156 for (row1
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
15157 MATRIX_ROW_CONTINUATION_LINE_P (row
);
15160 /* If we hit the beginning of the displayed portion
15161 without finding the first row of a continued
15165 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15168 eassert (row
->enabled_p
);
15173 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15174 && MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
)
15175 /* Make sure this isn't a header line by any chance, since
15176 then MATRIX_ROW_PARTIALLY_VISIBLE_P might yield non-zero. */
15177 && !row
->mode_line_p
15178 && make_cursor_line_fully_visible_p
)
15180 if (PT
== MATRIX_ROW_END_CHARPOS (row
)
15181 && !row
->ends_at_zv_p
15182 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
15183 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15184 else if (row
->height
> window_box_height (w
))
15186 /* If we end up in a partially visible line, let's
15187 make it fully visible, except when it's taller
15188 than the window, in which case we can't do much
15191 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15195 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
15196 if (!cursor_row_fully_visible_p (w
, 0, 1))
15197 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15199 rc
= CURSOR_MOVEMENT_SUCCESS
;
15203 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15204 else if (rc
!= CURSOR_MOVEMENT_SUCCESS
15205 && !NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
15207 /* With bidi-reordered rows, there could be more than
15208 one candidate row whose start and end positions
15209 occlude point. We need to let set_cursor_from_row
15210 find the best candidate. */
15211 /* FIXME: Revisit this when glyph ``spilling'' in
15212 continuation lines' rows is implemented for
15213 bidi-reordered rows. */
15218 int at_zv_p
= 0, exact_match_p
= 0;
15220 if (MATRIX_ROW_START_CHARPOS (row
) <= PT
15221 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
15222 && cursor_row_p (row
))
15223 rv
|= set_cursor_from_row (w
, row
, w
->current_matrix
,
15225 /* As soon as we've found the exact match for point,
15226 or the first suitable row whose ends_at_zv_p flag
15227 is set, we are done. */
15229 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
)->ends_at_zv_p
;
15231 && w
->cursor
.hpos
>= 0
15232 && w
->cursor
.hpos
< MATRIX_ROW_USED (w
->current_matrix
,
15235 struct glyph_row
*candidate
=
15236 MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
15238 candidate
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
15239 ptrdiff_t endpos
= MATRIX_ROW_END_CHARPOS (candidate
);
15242 (BUFFERP (g
->object
) && g
->charpos
== PT
)
15243 || (INTEGERP (g
->object
)
15244 && (g
->charpos
== PT
15245 || (g
->charpos
== 0 && endpos
- 1 == PT
)));
15247 if (rv
&& (at_zv_p
|| exact_match_p
))
15249 rc
= CURSOR_MOVEMENT_SUCCESS
;
15252 if (MATRIX_ROW_BOTTOM_Y (row
) == last_y
)
15256 while (((MATRIX_ROW_CONTINUATION_LINE_P (row
)
15257 || row
->continued_p
)
15258 && MATRIX_ROW_BOTTOM_Y (row
) <= last_y
)
15259 || (MATRIX_ROW_START_CHARPOS (row
) == PT
15260 && MATRIX_ROW_BOTTOM_Y (row
) < last_y
));
15261 /* If we didn't find any candidate rows, or exited the
15262 loop before all the candidates were examined, signal
15263 to the caller that this method failed. */
15264 if (rc
!= CURSOR_MOVEMENT_SUCCESS
15266 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
15267 && !row
->continued_p
))
15268 rc
= CURSOR_MOVEMENT_MUST_SCROLL
;
15270 rc
= CURSOR_MOVEMENT_SUCCESS
;
15276 if (set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0))
15278 rc
= CURSOR_MOVEMENT_SUCCESS
;
15283 while (MATRIX_ROW_BOTTOM_Y (row
) < last_y
15284 && MATRIX_ROW_START_CHARPOS (row
) == PT
15285 && cursor_row_p (row
));
15293 #if !defined USE_TOOLKIT_SCROLL_BARS || defined USE_GTK
15297 set_vertical_scroll_bar (struct window
*w
)
15299 ptrdiff_t start
, end
, whole
;
15301 /* Calculate the start and end positions for the current window.
15302 At some point, it would be nice to choose between scrollbars
15303 which reflect the whole buffer size, with special markers
15304 indicating narrowing, and scrollbars which reflect only the
15307 Note that mini-buffers sometimes aren't displaying any text. */
15308 if (!MINI_WINDOW_P (w
)
15309 || (w
== XWINDOW (minibuf_window
)
15310 && NILP (echo_area_buffer
[0])))
15312 struct buffer
*buf
= XBUFFER (w
->contents
);
15313 whole
= BUF_ZV (buf
) - BUF_BEGV (buf
);
15314 start
= marker_position (w
->start
) - BUF_BEGV (buf
);
15315 /* I don't think this is guaranteed to be right. For the
15316 moment, we'll pretend it is. */
15317 end
= BUF_Z (buf
) - w
->window_end_pos
- BUF_BEGV (buf
);
15321 if (whole
< (end
- start
))
15322 whole
= end
- start
;
15325 start
= end
= whole
= 0;
15327 /* Indicate what this scroll bar ought to be displaying now. */
15328 if (FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15329 (*FRAME_TERMINAL (XFRAME (w
->frame
))->set_vertical_scroll_bar_hook
)
15330 (w
, end
- start
, whole
, start
);
15334 /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only
15335 selected_window is redisplayed.
15337 We can return without actually redisplaying the window if fonts has been
15338 changed on window's frame. In that case, redisplay_internal will retry. */
15341 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15343 struct window
*w
= XWINDOW (window
);
15344 struct frame
*f
= XFRAME (w
->frame
);
15345 struct buffer
*buffer
= XBUFFER (w
->contents
);
15346 struct buffer
*old
= current_buffer
;
15347 struct text_pos lpoint
, opoint
, startp
;
15348 int update_mode_line
;
15351 /* Record it now because it's overwritten. */
15352 int current_matrix_up_to_date_p
= 0;
15353 int used_current_matrix_p
= 0;
15354 /* This is less strict than current_matrix_up_to_date_p.
15355 It indicates that the buffer contents and narrowing are unchanged. */
15356 int buffer_unchanged_p
= 0;
15357 int temp_scroll_step
= 0;
15358 ptrdiff_t count
= SPECPDL_INDEX ();
15360 int centering_position
= -1;
15361 int last_line_misfit
= 0;
15362 ptrdiff_t beg_unchanged
, end_unchanged
;
15363 int frame_line_height
;
15365 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15369 *w
->desired_matrix
->method
= 0;
15372 /* Make sure that both W's markers are valid. */
15373 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15374 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15377 reconsider_clip_changes (w
);
15378 frame_line_height
= default_line_pixel_height (w
);
15380 /* Has the mode line to be updated? */
15381 update_mode_line
= (w
->update_mode_line
15382 || update_mode_lines
15383 || buffer
->clip_changed
15384 || buffer
->prevent_redisplay_optimizations_p
);
15386 if (MINI_WINDOW_P (w
))
15388 if (w
== XWINDOW (echo_area_window
)
15389 && !NILP (echo_area_buffer
[0]))
15391 if (update_mode_line
)
15392 /* We may have to update a tty frame's menu bar or a
15393 tool-bar. Example `M-x C-h C-h C-g'. */
15394 goto finish_menu_bars
;
15396 /* We've already displayed the echo area glyphs in this window. */
15397 goto finish_scroll_bars
;
15399 else if ((w
!= XWINDOW (minibuf_window
)
15400 || minibuf_level
== 0)
15401 /* When buffer is nonempty, redisplay window normally. */
15402 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15403 /* Quail displays non-mini buffers in minibuffer window.
15404 In that case, redisplay the window normally. */
15405 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15407 /* W is a mini-buffer window, but it's not active, so clear
15409 int yb
= window_text_bottom_y (w
);
15410 struct glyph_row
*row
;
15413 for (y
= 0, row
= w
->desired_matrix
->rows
;
15415 y
+= row
->height
, ++row
)
15416 blank_row (w
, row
, y
);
15417 goto finish_scroll_bars
;
15420 clear_glyph_matrix (w
->desired_matrix
);
15423 /* Otherwise set up data on this window; select its buffer and point
15425 /* Really select the buffer, for the sake of buffer-local
15427 set_buffer_internal_1 (XBUFFER (w
->contents
));
15429 current_matrix_up_to_date_p
15430 = (w
->window_end_valid
15431 && !current_buffer
->clip_changed
15432 && !current_buffer
->prevent_redisplay_optimizations_p
15433 && !window_outdated (w
));
15435 /* Run the window-bottom-change-functions
15436 if it is possible that the text on the screen has changed
15437 (either due to modification of the text, or any other reason). */
15438 if (!current_matrix_up_to_date_p
15439 && !NILP (Vwindow_text_change_functions
))
15441 safe_run_hooks (Qwindow_text_change_functions
);
15445 beg_unchanged
= BEG_UNCHANGED
;
15446 end_unchanged
= END_UNCHANGED
;
15448 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15450 specbind (Qinhibit_point_motion_hooks
, Qt
);
15453 = (w
->window_end_valid
15454 && !current_buffer
->clip_changed
15455 && !window_outdated (w
));
15457 /* When windows_or_buffers_changed is non-zero, we can't rely
15458 on the window end being valid, so set it to zero there. */
15459 if (windows_or_buffers_changed
)
15461 /* If window starts on a continuation line, maybe adjust the
15462 window start in case the window's width changed. */
15463 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15464 compute_window_start_on_continuation_line (w
);
15466 w
->window_end_valid
= 0;
15467 /* If so, we also can't rely on current matrix
15468 and should not fool try_cursor_movement below. */
15469 current_matrix_up_to_date_p
= 0;
15472 /* Some sanity checks. */
15473 CHECK_WINDOW_END (w
);
15474 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15476 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15479 if (mode_line_update_needed (w
))
15480 update_mode_line
= 1;
15482 /* Point refers normally to the selected window. For any other
15483 window, set up appropriate value. */
15484 if (!EQ (window
, selected_window
))
15486 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15487 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15491 new_pt_byte
= BEGV_BYTE
;
15492 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15494 else if (new_pt
> (ZV
- 1))
15497 new_pt_byte
= ZV_BYTE
;
15498 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15501 /* We don't use SET_PT so that the point-motion hooks don't run. */
15502 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15505 /* If any of the character widths specified in the display table
15506 have changed, invalidate the width run cache. It's true that
15507 this may be a bit late to catch such changes, but the rest of
15508 redisplay goes (non-fatally) haywire when the display table is
15509 changed, so why should we worry about doing any better? */
15510 if (current_buffer
->width_run_cache
)
15512 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15514 if (! disptab_matches_widthtab
15515 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15517 invalidate_region_cache (current_buffer
,
15518 current_buffer
->width_run_cache
,
15520 recompute_width_table (current_buffer
, disptab
);
15524 /* If window-start is screwed up, choose a new one. */
15525 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15528 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15530 /* If someone specified a new starting point but did not insist,
15531 check whether it can be used. */
15532 if (w
->optional_new_start
15533 && CHARPOS (startp
) >= BEGV
15534 && CHARPOS (startp
) <= ZV
)
15536 w
->optional_new_start
= 0;
15537 start_display (&it
, w
, startp
);
15538 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15539 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15540 if (IT_CHARPOS (it
) == PT
)
15541 w
->force_start
= 1;
15542 /* IT may overshoot PT if text at PT is invisible. */
15543 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15544 w
->force_start
= 1;
15549 /* Handle case where place to start displaying has been specified,
15550 unless the specified location is outside the accessible range. */
15551 if (w
->force_start
|| window_frozen_p (w
))
15553 /* We set this later on if we have to adjust point. */
15556 w
->force_start
= 0;
15558 w
->window_end_valid
= 0;
15560 /* Forget any recorded base line for line number display. */
15561 if (!buffer_unchanged_p
)
15562 w
->base_line_number
= 0;
15564 /* Redisplay the mode line. Select the buffer properly for that.
15565 Also, run the hook window-scroll-functions
15566 because we have scrolled. */
15567 /* Note, we do this after clearing force_start because
15568 if there's an error, it is better to forget about force_start
15569 than to get into an infinite loop calling the hook functions
15570 and having them get more errors. */
15571 if (!update_mode_line
15572 || ! NILP (Vwindow_scroll_functions
))
15574 update_mode_line
= 1;
15575 w
->update_mode_line
= 1;
15576 startp
= run_window_scroll_functions (window
, startp
);
15579 if (CHARPOS (startp
) < BEGV
)
15580 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
15581 else if (CHARPOS (startp
) > ZV
)
15582 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
15584 /* Redisplay, then check if cursor has been set during the
15585 redisplay. Give up if new fonts were loaded. */
15586 /* We used to issue a CHECK_MARGINS argument to try_window here,
15587 but this causes scrolling to fail when point begins inside
15588 the scroll margin (bug#148) -- cyd */
15589 if (!try_window (window
, startp
, 0))
15591 w
->force_start
= 1;
15592 clear_glyph_matrix (w
->desired_matrix
);
15593 goto need_larger_matrices
;
15596 if (w
->cursor
.vpos
< 0 && !window_frozen_p (w
))
15598 /* If point does not appear, try to move point so it does
15599 appear. The desired matrix has been built above, so we
15600 can use it here. */
15601 new_vpos
= window_box_height (w
) / 2;
15604 if (!cursor_row_fully_visible_p (w
, 0, 0))
15606 /* Point does appear, but on a line partly visible at end of window.
15607 Move it back to a fully-visible line. */
15608 new_vpos
= window_box_height (w
);
15610 else if (w
->cursor
.vpos
>=0)
15612 /* Some people insist on not letting point enter the scroll
15613 margin, even though this part handles windows that didn't
15615 int window_total_lines
15616 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15617 int margin
= min (scroll_margin
, window_total_lines
/ 4);
15618 int pixel_margin
= margin
* frame_line_height
;
15619 bool header_line
= WINDOW_WANTS_HEADER_LINE_P (w
);
15621 /* Note: We add an extra FRAME_LINE_HEIGHT, because the loop
15622 below, which finds the row to move point to, advances by
15623 the Y coordinate of the _next_ row, see the definition of
15624 MATRIX_ROW_BOTTOM_Y. */
15625 if (w
->cursor
.vpos
< margin
+ header_line
)
15627 w
->cursor
.vpos
= -1;
15628 clear_glyph_matrix (w
->desired_matrix
);
15629 goto try_to_scroll
;
15633 int window_height
= window_box_height (w
);
15636 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15637 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15639 w
->cursor
.vpos
= -1;
15640 clear_glyph_matrix (w
->desired_matrix
);
15641 goto try_to_scroll
;
15646 /* If we need to move point for either of the above reasons,
15647 now actually do it. */
15650 struct glyph_row
*row
;
15652 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15653 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15656 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15657 MATRIX_ROW_START_BYTEPOS (row
));
15659 if (w
!= XWINDOW (selected_window
))
15660 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15661 else if (current_buffer
== old
)
15662 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15664 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15666 /* If we are highlighting the region, then we just changed
15667 the region, so redisplay to show it. */
15668 if (markpos_of_region () >= 0)
15670 clear_glyph_matrix (w
->desired_matrix
);
15671 if (!try_window (window
, startp
, 0))
15672 goto need_larger_matrices
;
15677 debug_method_add (w
, "forced window start");
15682 /* Handle case where text has not changed, only point, and it has
15683 not moved off the frame, and we are not retrying after hscroll.
15684 (current_matrix_up_to_date_p is nonzero when retrying.) */
15685 if (current_matrix_up_to_date_p
15686 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15687 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15691 case CURSOR_MOVEMENT_SUCCESS
:
15692 used_current_matrix_p
= 1;
15695 case CURSOR_MOVEMENT_MUST_SCROLL
:
15696 goto try_to_scroll
;
15702 /* If current starting point was originally the beginning of a line
15703 but no longer is, find a new starting point. */
15704 else if (w
->start_at_line_beg
15705 && !(CHARPOS (startp
) <= BEGV
15706 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15709 debug_method_add (w
, "recenter 1");
15714 /* Try scrolling with try_window_id. Value is > 0 if update has
15715 been done, it is -1 if we know that the same window start will
15716 not work. It is 0 if unsuccessful for some other reason. */
15717 else if ((tem
= try_window_id (w
)) != 0)
15720 debug_method_add (w
, "try_window_id %d", tem
);
15723 if (f
->fonts_changed
)
15724 goto need_larger_matrices
;
15728 /* Otherwise try_window_id has returned -1 which means that we
15729 don't want the alternative below this comment to execute. */
15731 else if (CHARPOS (startp
) >= BEGV
15732 && CHARPOS (startp
) <= ZV
15733 && PT
>= CHARPOS (startp
)
15734 && (CHARPOS (startp
) < ZV
15735 /* Avoid starting at end of buffer. */
15736 || CHARPOS (startp
) == BEGV
15737 || !window_outdated (w
)))
15739 int d1
, d2
, d3
, d4
, d5
, d6
;
15741 /* If first window line is a continuation line, and window start
15742 is inside the modified region, but the first change is before
15743 current window start, we must select a new window start.
15745 However, if this is the result of a down-mouse event (e.g. by
15746 extending the mouse-drag-overlay), we don't want to select a
15747 new window start, since that would change the position under
15748 the mouse, resulting in an unwanted mouse-movement rather
15749 than a simple mouse-click. */
15750 if (!w
->start_at_line_beg
15751 && NILP (do_mouse_tracking
)
15752 && CHARPOS (startp
) > BEGV
15753 && CHARPOS (startp
) > BEG
+ beg_unchanged
15754 && CHARPOS (startp
) <= Z
- end_unchanged
15755 /* Even if w->start_at_line_beg is nil, a new window may
15756 start at a line_beg, since that's how set_buffer_window
15757 sets it. So, we need to check the return value of
15758 compute_window_start_on_continuation_line. (See also
15760 && XMARKER (w
->start
)->buffer
== current_buffer
15761 && compute_window_start_on_continuation_line (w
)
15762 /* It doesn't make sense to force the window start like we
15763 do at label force_start if it is already known that point
15764 will not be visible in the resulting window, because
15765 doing so will move point from its correct position
15766 instead of scrolling the window to bring point into view.
15768 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15770 w
->force_start
= 1;
15771 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15776 debug_method_add (w
, "same window start");
15779 /* Try to redisplay starting at same place as before.
15780 If point has not moved off frame, accept the results. */
15781 if (!current_matrix_up_to_date_p
15782 /* Don't use try_window_reusing_current_matrix in this case
15783 because a window scroll function can have changed the
15785 || !NILP (Vwindow_scroll_functions
)
15786 || MINI_WINDOW_P (w
)
15787 || !(used_current_matrix_p
15788 = try_window_reusing_current_matrix (w
)))
15790 IF_DEBUG (debug_method_add (w
, "1"));
15791 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15792 /* -1 means we need to scroll.
15793 0 means we need new matrices, but fonts_changed
15794 is set in that case, so we will detect it below. */
15795 goto try_to_scroll
;
15798 if (f
->fonts_changed
)
15799 goto need_larger_matrices
;
15801 if (w
->cursor
.vpos
>= 0)
15803 if (!just_this_one_p
15804 || current_buffer
->clip_changed
15805 || BEG_UNCHANGED
< CHARPOS (startp
))
15806 /* Forget any recorded base line for line number display. */
15807 w
->base_line_number
= 0;
15809 if (!cursor_row_fully_visible_p (w
, 1, 0))
15811 clear_glyph_matrix (w
->desired_matrix
);
15812 last_line_misfit
= 1;
15814 /* Drop through and scroll. */
15819 clear_glyph_matrix (w
->desired_matrix
);
15824 /* Redisplay the mode line. Select the buffer properly for that. */
15825 if (!update_mode_line
)
15827 update_mode_line
= 1;
15828 w
->update_mode_line
= 1;
15831 /* Try to scroll by specified few lines. */
15832 if ((scroll_conservatively
15833 || emacs_scroll_step
15834 || temp_scroll_step
15835 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15836 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15837 && CHARPOS (startp
) >= BEGV
15838 && CHARPOS (startp
) <= ZV
)
15840 /* The function returns -1 if new fonts were loaded, 1 if
15841 successful, 0 if not successful. */
15842 int ss
= try_scrolling (window
, just_this_one_p
,
15843 scroll_conservatively
,
15845 temp_scroll_step
, last_line_misfit
);
15848 case SCROLLING_SUCCESS
:
15851 case SCROLLING_NEED_LARGER_MATRICES
:
15852 goto need_larger_matrices
;
15854 case SCROLLING_FAILED
:
15862 /* Finally, just choose a place to start which positions point
15863 according to user preferences. */
15868 debug_method_add (w
, "recenter");
15871 /* Forget any previously recorded base line for line number display. */
15872 if (!buffer_unchanged_p
)
15873 w
->base_line_number
= 0;
15875 /* Determine the window start relative to point. */
15876 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15877 it
.current_y
= it
.last_visible_y
;
15878 if (centering_position
< 0)
15880 int window_total_lines
15881 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15884 ? min (scroll_margin
, window_total_lines
/ 4)
15886 ptrdiff_t margin_pos
= CHARPOS (startp
);
15887 Lisp_Object aggressive
;
15890 /* If there is a scroll margin at the top of the window, find
15891 its character position. */
15893 /* Cannot call start_display if startp is not in the
15894 accessible region of the buffer. This can happen when we
15895 have just switched to a different buffer and/or changed
15896 its restriction. In that case, startp is initialized to
15897 the character position 1 (BEGV) because we did not yet
15898 have chance to display the buffer even once. */
15899 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15902 void *it1data
= NULL
;
15904 SAVE_IT (it1
, it
, it1data
);
15905 start_display (&it1
, w
, startp
);
15906 move_it_vertically (&it1
, margin
* frame_line_height
);
15907 margin_pos
= IT_CHARPOS (it1
);
15908 RESTORE_IT (&it
, &it
, it1data
);
15910 scrolling_up
= PT
> margin_pos
;
15913 ? BVAR (current_buffer
, scroll_up_aggressively
)
15914 : BVAR (current_buffer
, scroll_down_aggressively
);
15916 if (!MINI_WINDOW_P (w
)
15917 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15921 /* Setting scroll-conservatively overrides
15922 scroll-*-aggressively. */
15923 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15925 double float_amount
= XFLOATINT (aggressive
);
15927 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15928 if (pt_offset
== 0 && float_amount
> 0)
15930 if (pt_offset
&& margin
> 0)
15933 /* Compute how much to move the window start backward from
15934 point so that point will be displayed where the user
15938 centering_position
= it
.last_visible_y
;
15940 centering_position
-= pt_offset
;
15941 centering_position
-=
15942 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
15943 + WINDOW_HEADER_LINE_HEIGHT (w
);
15944 /* Don't let point enter the scroll margin near top of
15946 if (centering_position
< margin
* frame_line_height
)
15947 centering_position
= margin
* frame_line_height
;
15950 centering_position
= margin
* frame_line_height
+ pt_offset
;
15953 /* Set the window start half the height of the window backward
15955 centering_position
= window_box_height (w
) / 2;
15957 move_it_vertically_backward (&it
, centering_position
);
15959 eassert (IT_CHARPOS (it
) >= BEGV
);
15961 /* The function move_it_vertically_backward may move over more
15962 than the specified y-distance. If it->w is small, e.g. a
15963 mini-buffer window, we may end up in front of the window's
15964 display area. Start displaying at the start of the line
15965 containing PT in this case. */
15966 if (it
.current_y
<= 0)
15968 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15969 move_it_vertically_backward (&it
, 0);
15973 it
.current_x
= it
.hpos
= 0;
15975 /* Set the window start position here explicitly, to avoid an
15976 infinite loop in case the functions in window-scroll-functions
15978 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15980 /* Run scroll hooks. */
15981 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15983 /* Redisplay the window. */
15984 if (!current_matrix_up_to_date_p
15985 || windows_or_buffers_changed
15986 || f
->cursor_type_changed
15987 /* Don't use try_window_reusing_current_matrix in this case
15988 because it can have changed the buffer. */
15989 || !NILP (Vwindow_scroll_functions
)
15990 || !just_this_one_p
15991 || MINI_WINDOW_P (w
)
15992 || !(used_current_matrix_p
15993 = try_window_reusing_current_matrix (w
)))
15994 try_window (window
, startp
, 0);
15996 /* If new fonts have been loaded (due to fontsets), give up. We
15997 have to start a new redisplay since we need to re-adjust glyph
15999 if (f
->fonts_changed
)
16000 goto need_larger_matrices
;
16002 /* If cursor did not appear assume that the middle of the window is
16003 in the first line of the window. Do it again with the next line.
16004 (Imagine a window of height 100, displaying two lines of height
16005 60. Moving back 50 from it->last_visible_y will end in the first
16007 if (w
->cursor
.vpos
< 0)
16009 if (w
->window_end_valid
&& PT
>= Z
- w
->window_end_pos
)
16011 clear_glyph_matrix (w
->desired_matrix
);
16012 move_it_by_lines (&it
, 1);
16013 try_window (window
, it
.current
.pos
, 0);
16015 else if (PT
< IT_CHARPOS (it
))
16017 clear_glyph_matrix (w
->desired_matrix
);
16018 move_it_by_lines (&it
, -1);
16019 try_window (window
, it
.current
.pos
, 0);
16023 /* Not much we can do about it. */
16027 /* Consider the following case: Window starts at BEGV, there is
16028 invisible, intangible text at BEGV, so that display starts at
16029 some point START > BEGV. It can happen that we are called with
16030 PT somewhere between BEGV and START. Try to handle that case. */
16031 if (w
->cursor
.vpos
< 0)
16033 struct glyph_row
*row
= w
->current_matrix
->rows
;
16034 if (row
->mode_line_p
)
16036 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16039 if (!cursor_row_fully_visible_p (w
, 0, 0))
16041 /* If vscroll is enabled, disable it and try again. */
16045 clear_glyph_matrix (w
->desired_matrix
);
16049 /* Users who set scroll-conservatively to a large number want
16050 point just above/below the scroll margin. If we ended up
16051 with point's row partially visible, move the window start to
16052 make that row fully visible and out of the margin. */
16053 if (scroll_conservatively
> SCROLL_LIMIT
)
16055 int window_total_lines
16056 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16059 ? min (scroll_margin
, window_total_lines
/ 4)
16061 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16063 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16064 clear_glyph_matrix (w
->desired_matrix
);
16065 if (1 == try_window (window
, it
.current
.pos
,
16066 TRY_WINDOW_CHECK_MARGINS
))
16070 /* If centering point failed to make the whole line visible,
16071 put point at the top instead. That has to make the whole line
16072 visible, if it can be done. */
16073 if (centering_position
== 0)
16076 clear_glyph_matrix (w
->desired_matrix
);
16077 centering_position
= 0;
16083 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16084 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16085 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16087 /* Display the mode line, if we must. */
16088 if ((update_mode_line
16089 /* If window not full width, must redo its mode line
16090 if (a) the window to its side is being redone and
16091 (b) we do a frame-based redisplay. This is a consequence
16092 of how inverted lines are drawn in frame-based redisplay. */
16093 || (!just_this_one_p
16094 && !FRAME_WINDOW_P (f
)
16095 && !WINDOW_FULL_WIDTH_P (w
))
16096 /* Line number to display. */
16097 || w
->base_line_pos
> 0
16098 /* Column number is displayed and different from the one displayed. */
16099 || (w
->column_number_displayed
!= -1
16100 && (w
->column_number_displayed
!= current_column ())))
16101 /* This means that the window has a mode line. */
16102 && (WINDOW_WANTS_MODELINE_P (w
)
16103 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16105 display_mode_lines (w
);
16107 /* If mode line height has changed, arrange for a thorough
16108 immediate redisplay using the correct mode line height. */
16109 if (WINDOW_WANTS_MODELINE_P (w
)
16110 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16112 f
->fonts_changed
= 1;
16113 w
->mode_line_height
= -1;
16114 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16115 = DESIRED_MODE_LINE_HEIGHT (w
);
16118 /* If header line height has changed, arrange for a thorough
16119 immediate redisplay using the correct header line height. */
16120 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16121 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16123 f
->fonts_changed
= 1;
16124 w
->header_line_height
= -1;
16125 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16126 = DESIRED_HEADER_LINE_HEIGHT (w
);
16129 if (f
->fonts_changed
)
16130 goto need_larger_matrices
;
16133 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16135 w
->base_line_pos
= 0;
16136 w
->base_line_number
= 0;
16141 /* When we reach a frame's selected window, redo the frame's menu bar. */
16142 if (update_mode_line
16143 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16145 int redisplay_menu_p
= 0;
16147 if (FRAME_WINDOW_P (f
))
16149 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16150 || defined (HAVE_NS) || defined (USE_GTK)
16151 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16153 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16157 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16159 if (redisplay_menu_p
)
16160 display_menu_bar (w
);
16162 #ifdef HAVE_WINDOW_SYSTEM
16163 if (FRAME_WINDOW_P (f
))
16165 #if defined (USE_GTK) || defined (HAVE_NS)
16166 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16167 redisplay_tool_bar (f
);
16169 if (WINDOWP (f
->tool_bar_window
)
16170 && (FRAME_TOOL_BAR_LINES (f
) > 0
16171 || !NILP (Vauto_resize_tool_bars
))
16172 && redisplay_tool_bar (f
))
16173 ignore_mouse_drag_p
= 1;
16179 #ifdef HAVE_WINDOW_SYSTEM
16180 if (FRAME_WINDOW_P (f
)
16181 && update_window_fringes (w
, (just_this_one_p
16182 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16183 || w
->pseudo_window_p
)))
16187 if (draw_window_fringes (w
, 1))
16188 x_draw_vertical_border (w
);
16192 #endif /* HAVE_WINDOW_SYSTEM */
16194 /* We go to this label, with fonts_changed set, if it is
16195 necessary to try again using larger glyph matrices.
16196 We have to redeem the scroll bar even in this case,
16197 because the loop in redisplay_internal expects that. */
16198 need_larger_matrices
:
16200 finish_scroll_bars
:
16202 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16204 /* Set the thumb's position and size. */
16205 set_vertical_scroll_bar (w
);
16207 /* Note that we actually used the scroll bar attached to this
16208 window, so it shouldn't be deleted at the end of redisplay. */
16209 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16210 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16213 /* Restore current_buffer and value of point in it. The window
16214 update may have changed the buffer, so first make sure `opoint'
16215 is still valid (Bug#6177). */
16216 if (CHARPOS (opoint
) < BEGV
)
16217 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16218 else if (CHARPOS (opoint
) > ZV
)
16219 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16221 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16223 set_buffer_internal_1 (old
);
16224 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16225 shorter. This can be caused by log truncation in *Messages*. */
16226 if (CHARPOS (lpoint
) <= ZV
)
16227 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16229 unbind_to (count
, Qnil
);
16233 /* Build the complete desired matrix of WINDOW with a window start
16234 buffer position POS.
16236 Value is 1 if successful. It is zero if fonts were loaded during
16237 redisplay which makes re-adjusting glyph matrices necessary, and -1
16238 if point would appear in the scroll margins.
16239 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16240 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16244 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16246 struct window
*w
= XWINDOW (window
);
16248 struct glyph_row
*last_text_row
= NULL
;
16249 struct frame
*f
= XFRAME (w
->frame
);
16250 int frame_line_height
= default_line_pixel_height (w
);
16252 /* Make POS the new window start. */
16253 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16255 /* Mark cursor position as unknown. No overlay arrow seen. */
16256 w
->cursor
.vpos
= -1;
16257 overlay_arrow_seen
= 0;
16259 /* Initialize iterator and info to start at POS. */
16260 start_display (&it
, w
, pos
);
16262 /* Display all lines of W. */
16263 while (it
.current_y
< it
.last_visible_y
)
16265 if (display_line (&it
))
16266 last_text_row
= it
.glyph_row
- 1;
16267 if (f
->fonts_changed
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16271 /* Don't let the cursor end in the scroll margins. */
16272 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16273 && !MINI_WINDOW_P (w
))
16275 int this_scroll_margin
;
16276 int window_total_lines
16277 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16279 if (scroll_margin
> 0)
16281 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16282 this_scroll_margin
*= frame_line_height
;
16285 this_scroll_margin
= 0;
16287 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16288 && w
->cursor
.y
< this_scroll_margin
16289 && CHARPOS (pos
) > BEGV
16290 && IT_CHARPOS (it
) < ZV
)
16291 /* rms: considering make_cursor_line_fully_visible_p here
16292 seems to give wrong results. We don't want to recenter
16293 when the last line is partly visible, we want to allow
16294 that case to be handled in the usual way. */
16295 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16297 w
->cursor
.vpos
= -1;
16298 clear_glyph_matrix (w
->desired_matrix
);
16303 /* If bottom moved off end of frame, change mode line percentage. */
16304 if (w
->window_end_pos
<= 0 && Z
!= IT_CHARPOS (it
))
16305 w
->update_mode_line
= 1;
16307 /* Set window_end_pos to the offset of the last character displayed
16308 on the window from the end of current_buffer. Set
16309 window_end_vpos to its row number. */
16312 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16313 adjust_window_ends (w
, last_text_row
, 0);
16315 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16316 w
->window_end_vpos
)));
16320 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16321 w
->window_end_pos
= Z
- ZV
;
16322 w
->window_end_vpos
= 0;
16325 /* But that is not valid info until redisplay finishes. */
16326 w
->window_end_valid
= 0;
16332 /************************************************************************
16333 Window redisplay reusing current matrix when buffer has not changed
16334 ************************************************************************/
16336 /* Try redisplay of window W showing an unchanged buffer with a
16337 different window start than the last time it was displayed by
16338 reusing its current matrix. Value is non-zero if successful.
16339 W->start is the new window start. */
16342 try_window_reusing_current_matrix (struct window
*w
)
16344 struct frame
*f
= XFRAME (w
->frame
);
16345 struct glyph_row
*bottom_row
;
16348 struct text_pos start
, new_start
;
16349 int nrows_scrolled
, i
;
16350 struct glyph_row
*last_text_row
;
16351 struct glyph_row
*last_reused_text_row
;
16352 struct glyph_row
*start_row
;
16353 int start_vpos
, min_y
, max_y
;
16356 if (inhibit_try_window_reusing
)
16360 if (/* This function doesn't handle terminal frames. */
16361 !FRAME_WINDOW_P (f
)
16362 /* Don't try to reuse the display if windows have been split
16364 || windows_or_buffers_changed
16365 || f
->cursor_type_changed
)
16368 /* Can't do this if region may have changed. */
16369 if (markpos_of_region () >= 0
16370 || w
->region_showing
16371 || !NILP (Vshow_trailing_whitespace
))
16374 /* If top-line visibility has changed, give up. */
16375 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16376 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16379 /* Give up if old or new display is scrolled vertically. We could
16380 make this function handle this, but right now it doesn't. */
16381 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16382 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16385 /* The variable new_start now holds the new window start. The old
16386 start `start' can be determined from the current matrix. */
16387 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16388 start
= start_row
->minpos
;
16389 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16391 /* Clear the desired matrix for the display below. */
16392 clear_glyph_matrix (w
->desired_matrix
);
16394 if (CHARPOS (new_start
) <= CHARPOS (start
))
16396 /* Don't use this method if the display starts with an ellipsis
16397 displayed for invisible text. It's not easy to handle that case
16398 below, and it's certainly not worth the effort since this is
16399 not a frequent case. */
16400 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16403 IF_DEBUG (debug_method_add (w
, "twu1"));
16405 /* Display up to a row that can be reused. The variable
16406 last_text_row is set to the last row displayed that displays
16407 text. Note that it.vpos == 0 if or if not there is a
16408 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16409 start_display (&it
, w
, new_start
);
16410 w
->cursor
.vpos
= -1;
16411 last_text_row
= last_reused_text_row
= NULL
;
16413 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16415 /* If we have reached into the characters in the START row,
16416 that means the line boundaries have changed. So we
16417 can't start copying with the row START. Maybe it will
16418 work to start copying with the following row. */
16419 while (IT_CHARPOS (it
) > CHARPOS (start
))
16421 /* Advance to the next row as the "start". */
16423 start
= start_row
->minpos
;
16424 /* If there are no more rows to try, or just one, give up. */
16425 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16426 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16427 || CHARPOS (start
) == ZV
)
16429 clear_glyph_matrix (w
->desired_matrix
);
16433 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16435 /* If we have reached alignment, we can copy the rest of the
16437 if (IT_CHARPOS (it
) == CHARPOS (start
)
16438 /* Don't accept "alignment" inside a display vector,
16439 since start_row could have started in the middle of
16440 that same display vector (thus their character
16441 positions match), and we have no way of telling if
16442 that is the case. */
16443 && it
.current
.dpvec_index
< 0)
16446 if (display_line (&it
))
16447 last_text_row
= it
.glyph_row
- 1;
16451 /* A value of current_y < last_visible_y means that we stopped
16452 at the previous window start, which in turn means that we
16453 have at least one reusable row. */
16454 if (it
.current_y
< it
.last_visible_y
)
16456 struct glyph_row
*row
;
16458 /* IT.vpos always starts from 0; it counts text lines. */
16459 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16461 /* Find PT if not already found in the lines displayed. */
16462 if (w
->cursor
.vpos
< 0)
16464 int dy
= it
.current_y
- start_row
->y
;
16466 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16467 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16469 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16470 dy
, nrows_scrolled
);
16473 clear_glyph_matrix (w
->desired_matrix
);
16478 /* Scroll the display. Do it before the current matrix is
16479 changed. The problem here is that update has not yet
16480 run, i.e. part of the current matrix is not up to date.
16481 scroll_run_hook will clear the cursor, and use the
16482 current matrix to get the height of the row the cursor is
16484 run
.current_y
= start_row
->y
;
16485 run
.desired_y
= it
.current_y
;
16486 run
.height
= it
.last_visible_y
- it
.current_y
;
16488 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16491 FRAME_RIF (f
)->update_window_begin_hook (w
);
16492 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16493 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16494 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16498 /* Shift current matrix down by nrows_scrolled lines. */
16499 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16500 rotate_matrix (w
->current_matrix
,
16502 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16505 /* Disable lines that must be updated. */
16506 for (i
= 0; i
< nrows_scrolled
; ++i
)
16507 (start_row
+ i
)->enabled_p
= 0;
16509 /* Re-compute Y positions. */
16510 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16511 max_y
= it
.last_visible_y
;
16512 for (row
= start_row
+ nrows_scrolled
;
16516 row
->y
= it
.current_y
;
16517 row
->visible_height
= row
->height
;
16519 if (row
->y
< min_y
)
16520 row
->visible_height
-= min_y
- row
->y
;
16521 if (row
->y
+ row
->height
> max_y
)
16522 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16523 if (row
->fringe_bitmap_periodic_p
)
16524 row
->redraw_fringe_bitmaps_p
= 1;
16526 it
.current_y
+= row
->height
;
16528 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16529 last_reused_text_row
= row
;
16530 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16534 /* Disable lines in the current matrix which are now
16535 below the window. */
16536 for (++row
; row
< bottom_row
; ++row
)
16537 row
->enabled_p
= row
->mode_line_p
= 0;
16540 /* Update window_end_pos etc.; last_reused_text_row is the last
16541 reused row from the current matrix containing text, if any.
16542 The value of last_text_row is the last displayed line
16543 containing text. */
16544 if (last_reused_text_row
)
16545 adjust_window_ends (w
, last_reused_text_row
, 1);
16546 else if (last_text_row
)
16547 adjust_window_ends (w
, last_text_row
, 0);
16550 /* This window must be completely empty. */
16551 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16552 w
->window_end_pos
= Z
- ZV
;
16553 w
->window_end_vpos
= 0;
16555 w
->window_end_valid
= 0;
16557 /* Update hint: don't try scrolling again in update_window. */
16558 w
->desired_matrix
->no_scrolling_p
= 1;
16561 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16565 else if (CHARPOS (new_start
) > CHARPOS (start
))
16567 struct glyph_row
*pt_row
, *row
;
16568 struct glyph_row
*first_reusable_row
;
16569 struct glyph_row
*first_row_to_display
;
16571 int yb
= window_text_bottom_y (w
);
16573 /* Find the row starting at new_start, if there is one. Don't
16574 reuse a partially visible line at the end. */
16575 first_reusable_row
= start_row
;
16576 while (first_reusable_row
->enabled_p
16577 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16578 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16579 < CHARPOS (new_start
)))
16580 ++first_reusable_row
;
16582 /* Give up if there is no row to reuse. */
16583 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16584 || !first_reusable_row
->enabled_p
16585 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16586 != CHARPOS (new_start
)))
16589 /* We can reuse fully visible rows beginning with
16590 first_reusable_row to the end of the window. Set
16591 first_row_to_display to the first row that cannot be reused.
16592 Set pt_row to the row containing point, if there is any. */
16594 for (first_row_to_display
= first_reusable_row
;
16595 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16596 ++first_row_to_display
)
16598 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16599 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16600 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16601 && first_row_to_display
->ends_at_zv_p
16602 && pt_row
== NULL
)))
16603 pt_row
= first_row_to_display
;
16606 /* Start displaying at the start of first_row_to_display. */
16607 eassert (first_row_to_display
->y
< yb
);
16608 init_to_row_start (&it
, w
, first_row_to_display
);
16610 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16612 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16614 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16615 + WINDOW_HEADER_LINE_HEIGHT (w
));
16617 /* Display lines beginning with first_row_to_display in the
16618 desired matrix. Set last_text_row to the last row displayed
16619 that displays text. */
16620 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16621 if (pt_row
== NULL
)
16622 w
->cursor
.vpos
= -1;
16623 last_text_row
= NULL
;
16624 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
16625 if (display_line (&it
))
16626 last_text_row
= it
.glyph_row
- 1;
16628 /* If point is in a reused row, adjust y and vpos of the cursor
16632 w
->cursor
.vpos
-= nrows_scrolled
;
16633 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16636 /* Give up if point isn't in a row displayed or reused. (This
16637 also handles the case where w->cursor.vpos < nrows_scrolled
16638 after the calls to display_line, which can happen with scroll
16639 margins. See bug#1295.) */
16640 if (w
->cursor
.vpos
< 0)
16642 clear_glyph_matrix (w
->desired_matrix
);
16646 /* Scroll the display. */
16647 run
.current_y
= first_reusable_row
->y
;
16648 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16649 run
.height
= it
.last_visible_y
- run
.current_y
;
16650 dy
= run
.current_y
- run
.desired_y
;
16655 FRAME_RIF (f
)->update_window_begin_hook (w
);
16656 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16657 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16658 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16662 /* Adjust Y positions of reused rows. */
16663 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16664 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16665 max_y
= it
.last_visible_y
;
16666 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16669 row
->visible_height
= row
->height
;
16670 if (row
->y
< min_y
)
16671 row
->visible_height
-= min_y
- row
->y
;
16672 if (row
->y
+ row
->height
> max_y
)
16673 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16674 if (row
->fringe_bitmap_periodic_p
)
16675 row
->redraw_fringe_bitmaps_p
= 1;
16678 /* Scroll the current matrix. */
16679 eassert (nrows_scrolled
> 0);
16680 rotate_matrix (w
->current_matrix
,
16682 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16685 /* Disable rows not reused. */
16686 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16687 row
->enabled_p
= 0;
16689 /* Point may have moved to a different line, so we cannot assume that
16690 the previous cursor position is valid; locate the correct row. */
16693 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16695 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16696 && !row
->ends_at_zv_p
;
16700 w
->cursor
.y
= row
->y
;
16702 if (row
< bottom_row
)
16704 /* Can't simply scan the row for point with
16705 bidi-reordered glyph rows. Let set_cursor_from_row
16706 figure out where to put the cursor, and if it fails,
16708 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16710 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16713 clear_glyph_matrix (w
->desired_matrix
);
16719 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16720 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16723 && (!BUFFERP (glyph
->object
)
16724 || glyph
->charpos
< PT
);
16728 w
->cursor
.x
+= glyph
->pixel_width
;
16734 /* Adjust window end. A null value of last_text_row means that
16735 the window end is in reused rows which in turn means that
16736 only its vpos can have changed. */
16738 adjust_window_ends (w
, last_text_row
, 0);
16740 w
->window_end_vpos
-= nrows_scrolled
;
16742 w
->window_end_valid
= 0;
16743 w
->desired_matrix
->no_scrolling_p
= 1;
16746 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16756 /************************************************************************
16757 Window redisplay reusing current matrix when buffer has changed
16758 ************************************************************************/
16760 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16761 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16762 ptrdiff_t *, ptrdiff_t *);
16763 static struct glyph_row
*
16764 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16765 struct glyph_row
*);
16768 /* Return the last row in MATRIX displaying text. If row START is
16769 non-null, start searching with that row. IT gives the dimensions
16770 of the display. Value is null if matrix is empty; otherwise it is
16771 a pointer to the row found. */
16773 static struct glyph_row
*
16774 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16775 struct glyph_row
*start
)
16777 struct glyph_row
*row
, *row_found
;
16779 /* Set row_found to the last row in IT->w's current matrix
16780 displaying text. The loop looks funny but think of partially
16783 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16784 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16786 eassert (row
->enabled_p
);
16788 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16797 /* Return the last row in the current matrix of W that is not affected
16798 by changes at the start of current_buffer that occurred since W's
16799 current matrix was built. Value is null if no such row exists.
16801 BEG_UNCHANGED us the number of characters unchanged at the start of
16802 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16803 first changed character in current_buffer. Characters at positions <
16804 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16805 when the current matrix was built. */
16807 static struct glyph_row
*
16808 find_last_unchanged_at_beg_row (struct window
*w
)
16810 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16811 struct glyph_row
*row
;
16812 struct glyph_row
*row_found
= NULL
;
16813 int yb
= window_text_bottom_y (w
);
16815 /* Find the last row displaying unchanged text. */
16816 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16817 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16818 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16821 if (/* If row ends before first_changed_pos, it is unchanged,
16822 except in some case. */
16823 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16824 /* When row ends in ZV and we write at ZV it is not
16826 && !row
->ends_at_zv_p
16827 /* When first_changed_pos is the end of a continued line,
16828 row is not unchanged because it may be no longer
16830 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16831 && (row
->continued_p
16832 || row
->exact_window_width_line_p
))
16833 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16834 needs to be recomputed, so don't consider this row as
16835 unchanged. This happens when the last line was
16836 bidi-reordered and was killed immediately before this
16837 redisplay cycle. In that case, ROW->end stores the
16838 buffer position of the first visual-order character of
16839 the killed text, which is now beyond ZV. */
16840 && CHARPOS (row
->end
.pos
) <= ZV
)
16843 /* Stop if last visible row. */
16844 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16852 /* Find the first glyph row in the current matrix of W that is not
16853 affected by changes at the end of current_buffer since the
16854 time W's current matrix was built.
16856 Return in *DELTA the number of chars by which buffer positions in
16857 unchanged text at the end of current_buffer must be adjusted.
16859 Return in *DELTA_BYTES the corresponding number of bytes.
16861 Value is null if no such row exists, i.e. all rows are affected by
16864 static struct glyph_row
*
16865 find_first_unchanged_at_end_row (struct window
*w
,
16866 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16868 struct glyph_row
*row
;
16869 struct glyph_row
*row_found
= NULL
;
16871 *delta
= *delta_bytes
= 0;
16873 /* Display must not have been paused, otherwise the current matrix
16874 is not up to date. */
16875 eassert (w
->window_end_valid
);
16877 /* A value of window_end_pos >= END_UNCHANGED means that the window
16878 end is in the range of changed text. If so, there is no
16879 unchanged row at the end of W's current matrix. */
16880 if (w
->window_end_pos
>= END_UNCHANGED
)
16883 /* Set row to the last row in W's current matrix displaying text. */
16884 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
16886 /* If matrix is entirely empty, no unchanged row exists. */
16887 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16889 /* The value of row is the last glyph row in the matrix having a
16890 meaningful buffer position in it. The end position of row
16891 corresponds to window_end_pos. This allows us to translate
16892 buffer positions in the current matrix to current buffer
16893 positions for characters not in changed text. */
16895 MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
16896 ptrdiff_t Z_BYTE_old
=
16897 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16898 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16899 struct glyph_row
*first_text_row
16900 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16902 *delta
= Z
- Z_old
;
16903 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16905 /* Set last_unchanged_pos to the buffer position of the last
16906 character in the buffer that has not been changed. Z is the
16907 index + 1 of the last character in current_buffer, i.e. by
16908 subtracting END_UNCHANGED we get the index of the last
16909 unchanged character, and we have to add BEG to get its buffer
16911 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16912 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16914 /* Search backward from ROW for a row displaying a line that
16915 starts at a minimum position >= last_unchanged_pos_old. */
16916 for (; row
> first_text_row
; --row
)
16918 /* This used to abort, but it can happen.
16919 It is ok to just stop the search instead here. KFS. */
16920 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16923 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16928 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16934 /* Make sure that glyph rows in the current matrix of window W
16935 reference the same glyph memory as corresponding rows in the
16936 frame's frame matrix. This function is called after scrolling W's
16937 current matrix on a terminal frame in try_window_id and
16938 try_window_reusing_current_matrix. */
16941 sync_frame_with_window_matrix_rows (struct window
*w
)
16943 struct frame
*f
= XFRAME (w
->frame
);
16944 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16946 /* Preconditions: W must be a leaf window and full-width. Its frame
16947 must have a frame matrix. */
16948 eassert (BUFFERP (w
->contents
));
16949 eassert (WINDOW_FULL_WIDTH_P (w
));
16950 eassert (!FRAME_WINDOW_P (f
));
16952 /* If W is a full-width window, glyph pointers in W's current matrix
16953 have, by definition, to be the same as glyph pointers in the
16954 corresponding frame matrix. Note that frame matrices have no
16955 marginal areas (see build_frame_matrix). */
16956 window_row
= w
->current_matrix
->rows
;
16957 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16958 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16959 while (window_row
< window_row_end
)
16961 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16962 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16964 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16965 frame_row
->glyphs
[TEXT_AREA
] = start
;
16966 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16967 frame_row
->glyphs
[LAST_AREA
] = end
;
16969 /* Disable frame rows whose corresponding window rows have
16970 been disabled in try_window_id. */
16971 if (!window_row
->enabled_p
)
16972 frame_row
->enabled_p
= 0;
16974 ++window_row
, ++frame_row
;
16979 /* Find the glyph row in window W containing CHARPOS. Consider all
16980 rows between START and END (not inclusive). END null means search
16981 all rows to the end of the display area of W. Value is the row
16982 containing CHARPOS or null. */
16985 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
16986 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
16988 struct glyph_row
*row
= start
;
16989 struct glyph_row
*best_row
= NULL
;
16990 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
16993 /* If we happen to start on a header-line, skip that. */
16994 if (row
->mode_line_p
)
16997 if ((end
&& row
>= end
) || !row
->enabled_p
)
17000 last_y
= window_text_bottom_y (w
) - dy
;
17004 /* Give up if we have gone too far. */
17005 if (end
&& row
>= end
)
17007 /* This formerly returned if they were equal.
17008 I think that both quantities are of a "last plus one" type;
17009 if so, when they are equal, the row is within the screen. -- rms. */
17010 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17013 /* If it is in this row, return this row. */
17014 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17015 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17016 /* The end position of a row equals the start
17017 position of the next row. If CHARPOS is there, we
17018 would rather consider it displayed in the next
17019 line, except when this line ends in ZV. */
17020 && !row_for_charpos_p (row
, charpos
)))
17021 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17025 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17026 || (!best_row
&& !row
->continued_p
))
17028 /* In bidi-reordered rows, there could be several rows whose
17029 edges surround CHARPOS, all of these rows belonging to
17030 the same continued line. We need to find the row which
17031 fits CHARPOS the best. */
17032 for (g
= row
->glyphs
[TEXT_AREA
];
17033 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17036 if (!STRINGP (g
->object
))
17038 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17040 mindif
= eabs (g
->charpos
- charpos
);
17042 /* Exact match always wins. */
17049 else if (best_row
&& !row
->continued_p
)
17056 /* Try to redisplay window W by reusing its existing display. W's
17057 current matrix must be up to date when this function is called,
17058 i.e. window_end_valid must be nonzero.
17062 1 if display has been updated
17063 0 if otherwise unsuccessful
17064 -1 if redisplay with same window start is known not to succeed
17066 The following steps are performed:
17068 1. Find the last row in the current matrix of W that is not
17069 affected by changes at the start of current_buffer. If no such row
17072 2. Find the first row in W's current matrix that is not affected by
17073 changes at the end of current_buffer. Maybe there is no such row.
17075 3. Display lines beginning with the row + 1 found in step 1 to the
17076 row found in step 2 or, if step 2 didn't find a row, to the end of
17079 4. If cursor is not known to appear on the window, give up.
17081 5. If display stopped at the row found in step 2, scroll the
17082 display and current matrix as needed.
17084 6. Maybe display some lines at the end of W, if we must. This can
17085 happen under various circumstances, like a partially visible line
17086 becoming fully visible, or because newly displayed lines are displayed
17087 in smaller font sizes.
17089 7. Update W's window end information. */
17092 try_window_id (struct window
*w
)
17094 struct frame
*f
= XFRAME (w
->frame
);
17095 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17096 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17097 struct glyph_row
*last_unchanged_at_beg_row
;
17098 struct glyph_row
*first_unchanged_at_end_row
;
17099 struct glyph_row
*row
;
17100 struct glyph_row
*bottom_row
;
17103 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17105 struct text_pos start_pos
;
17107 int first_unchanged_at_end_vpos
= 0;
17108 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17109 struct text_pos start
;
17110 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17113 if (inhibit_try_window_id
)
17117 /* This is handy for debugging. */
17119 #define GIVE_UP(X) \
17121 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17125 #define GIVE_UP(X) return 0
17128 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17130 /* Don't use this for mini-windows because these can show
17131 messages and mini-buffers, and we don't handle that here. */
17132 if (MINI_WINDOW_P (w
))
17135 /* This flag is used to prevent redisplay optimizations. */
17136 if (windows_or_buffers_changed
|| f
->cursor_type_changed
)
17139 /* Verify that narrowing has not changed.
17140 Also verify that we were not told to prevent redisplay optimizations.
17141 It would be nice to further
17142 reduce the number of cases where this prevents try_window_id. */
17143 if (current_buffer
->clip_changed
17144 || current_buffer
->prevent_redisplay_optimizations_p
)
17147 /* Window must either use window-based redisplay or be full width. */
17148 if (!FRAME_WINDOW_P (f
)
17149 && (!FRAME_LINE_INS_DEL_OK (f
)
17150 || !WINDOW_FULL_WIDTH_P (w
)))
17153 /* Give up if point is known NOT to appear in W. */
17154 if (PT
< CHARPOS (start
))
17157 /* Another way to prevent redisplay optimizations. */
17158 if (w
->last_modified
== 0)
17161 /* Verify that window is not hscrolled. */
17162 if (w
->hscroll
!= 0)
17165 /* Verify that display wasn't paused. */
17166 if (!w
->window_end_valid
)
17169 /* Can't use this if highlighting a region because a cursor movement
17170 will do more than just set the cursor. */
17171 if (markpos_of_region () >= 0)
17174 /* Likewise if highlighting trailing whitespace. */
17175 if (!NILP (Vshow_trailing_whitespace
))
17178 /* Likewise if showing a region. */
17179 if (w
->region_showing
)
17182 /* Can't use this if overlay arrow position and/or string have
17184 if (overlay_arrows_changed_p ())
17187 /* When word-wrap is on, adding a space to the first word of a
17188 wrapped line can change the wrap position, altering the line
17189 above it. It might be worthwhile to handle this more
17190 intelligently, but for now just redisplay from scratch. */
17191 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17194 /* Under bidi reordering, adding or deleting a character in the
17195 beginning of a paragraph, before the first strong directional
17196 character, can change the base direction of the paragraph (unless
17197 the buffer specifies a fixed paragraph direction), which will
17198 require to redisplay the whole paragraph. It might be worthwhile
17199 to find the paragraph limits and widen the range of redisplayed
17200 lines to that, but for now just give up this optimization and
17201 redisplay from scratch. */
17202 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17203 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17206 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17207 only if buffer has really changed. The reason is that the gap is
17208 initially at Z for freshly visited files. The code below would
17209 set end_unchanged to 0 in that case. */
17210 if (MODIFF
> SAVE_MODIFF
17211 /* This seems to happen sometimes after saving a buffer. */
17212 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17214 if (GPT
- BEG
< BEG_UNCHANGED
)
17215 BEG_UNCHANGED
= GPT
- BEG
;
17216 if (Z
- GPT
< END_UNCHANGED
)
17217 END_UNCHANGED
= Z
- GPT
;
17220 /* The position of the first and last character that has been changed. */
17221 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17222 last_changed_charpos
= Z
- END_UNCHANGED
;
17224 /* If window starts after a line end, and the last change is in
17225 front of that newline, then changes don't affect the display.
17226 This case happens with stealth-fontification. Note that although
17227 the display is unchanged, glyph positions in the matrix have to
17228 be adjusted, of course. */
17229 row
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
17230 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17231 && ((last_changed_charpos
< CHARPOS (start
)
17232 && CHARPOS (start
) == BEGV
)
17233 || (last_changed_charpos
< CHARPOS (start
) - 1
17234 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17236 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17237 struct glyph_row
*r0
;
17239 /* Compute how many chars/bytes have been added to or removed
17240 from the buffer. */
17241 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + w
->window_end_pos
;
17242 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17243 Z_delta
= Z
- Z_old
;
17244 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17246 /* Give up if PT is not in the window. Note that it already has
17247 been checked at the start of try_window_id that PT is not in
17248 front of the window start. */
17249 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17252 /* If window start is unchanged, we can reuse the whole matrix
17253 as is, after adjusting glyph positions. No need to compute
17254 the window end again, since its offset from Z hasn't changed. */
17255 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17256 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17257 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17258 /* PT must not be in a partially visible line. */
17259 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17260 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17262 /* Adjust positions in the glyph matrix. */
17263 if (Z_delta
|| Z_delta_bytes
)
17265 struct glyph_row
*r1
17266 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17267 increment_matrix_positions (w
->current_matrix
,
17268 MATRIX_ROW_VPOS (r0
, current_matrix
),
17269 MATRIX_ROW_VPOS (r1
, current_matrix
),
17270 Z_delta
, Z_delta_bytes
);
17273 /* Set the cursor. */
17274 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17276 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17283 /* Handle the case that changes are all below what is displayed in
17284 the window, and that PT is in the window. This shortcut cannot
17285 be taken if ZV is visible in the window, and text has been added
17286 there that is visible in the window. */
17287 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17288 /* ZV is not visible in the window, or there are no
17289 changes at ZV, actually. */
17290 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17291 || first_changed_charpos
== last_changed_charpos
))
17293 struct glyph_row
*r0
;
17295 /* Give up if PT is not in the window. Note that it already has
17296 been checked at the start of try_window_id that PT is not in
17297 front of the window start. */
17298 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17301 /* If window start is unchanged, we can reuse the whole matrix
17302 as is, without changing glyph positions since no text has
17303 been added/removed in front of the window end. */
17304 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17305 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17306 /* PT must not be in a partially visible line. */
17307 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17308 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17310 /* We have to compute the window end anew since text
17311 could have been added/removed after it. */
17312 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17313 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17315 /* Set the cursor. */
17316 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17318 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17325 /* Give up if window start is in the changed area.
17327 The condition used to read
17329 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17331 but why that was tested escapes me at the moment. */
17332 if (CHARPOS (start
) >= first_changed_charpos
17333 && CHARPOS (start
) <= last_changed_charpos
)
17336 /* Check that window start agrees with the start of the first glyph
17337 row in its current matrix. Check this after we know the window
17338 start is not in changed text, otherwise positions would not be
17340 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17341 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17344 /* Give up if the window ends in strings. Overlay strings
17345 at the end are difficult to handle, so don't try. */
17346 row
= MATRIX_ROW (current_matrix
, w
->window_end_vpos
);
17347 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17350 /* Compute the position at which we have to start displaying new
17351 lines. Some of the lines at the top of the window might be
17352 reusable because they are not displaying changed text. Find the
17353 last row in W's current matrix not affected by changes at the
17354 start of current_buffer. Value is null if changes start in the
17355 first line of window. */
17356 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17357 if (last_unchanged_at_beg_row
)
17359 /* Avoid starting to display in the middle of a character, a TAB
17360 for instance. This is easier than to set up the iterator
17361 exactly, and it's not a frequent case, so the additional
17362 effort wouldn't really pay off. */
17363 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17364 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17365 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17366 --last_unchanged_at_beg_row
;
17368 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17371 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17373 start_pos
= it
.current
.pos
;
17375 /* Start displaying new lines in the desired matrix at the same
17376 vpos we would use in the current matrix, i.e. below
17377 last_unchanged_at_beg_row. */
17378 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17380 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17381 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17383 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17387 /* There are no reusable lines at the start of the window.
17388 Start displaying in the first text line. */
17389 start_display (&it
, w
, start
);
17390 it
.vpos
= it
.first_vpos
;
17391 start_pos
= it
.current
.pos
;
17394 /* Find the first row that is not affected by changes at the end of
17395 the buffer. Value will be null if there is no unchanged row, in
17396 which case we must redisplay to the end of the window. delta
17397 will be set to the value by which buffer positions beginning with
17398 first_unchanged_at_end_row have to be adjusted due to text
17400 first_unchanged_at_end_row
17401 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17402 IF_DEBUG (debug_delta
= delta
);
17403 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17405 /* Set stop_pos to the buffer position up to which we will have to
17406 display new lines. If first_unchanged_at_end_row != NULL, this
17407 is the buffer position of the start of the line displayed in that
17408 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17409 that we don't stop at a buffer position. */
17411 if (first_unchanged_at_end_row
)
17413 eassert (last_unchanged_at_beg_row
== NULL
17414 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17416 /* If this is a continuation line, move forward to the next one
17417 that isn't. Changes in lines above affect this line.
17418 Caution: this may move first_unchanged_at_end_row to a row
17419 not displaying text. */
17420 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17421 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17422 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17423 < it
.last_visible_y
))
17424 ++first_unchanged_at_end_row
;
17426 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17427 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17428 >= it
.last_visible_y
))
17429 first_unchanged_at_end_row
= NULL
;
17432 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17434 first_unchanged_at_end_vpos
17435 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17436 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17439 else if (last_unchanged_at_beg_row
== NULL
)
17445 /* Either there is no unchanged row at the end, or the one we have
17446 now displays text. This is a necessary condition for the window
17447 end pos calculation at the end of this function. */
17448 eassert (first_unchanged_at_end_row
== NULL
17449 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17451 debug_last_unchanged_at_beg_vpos
17452 = (last_unchanged_at_beg_row
17453 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17455 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17457 #endif /* GLYPH_DEBUG */
17460 /* Display new lines. Set last_text_row to the last new line
17461 displayed which has text on it, i.e. might end up as being the
17462 line where the window_end_vpos is. */
17463 w
->cursor
.vpos
= -1;
17464 last_text_row
= NULL
;
17465 overlay_arrow_seen
= 0;
17466 while (it
.current_y
< it
.last_visible_y
17467 && !f
->fonts_changed
17468 && (first_unchanged_at_end_row
== NULL
17469 || IT_CHARPOS (it
) < stop_pos
))
17471 if (display_line (&it
))
17472 last_text_row
= it
.glyph_row
- 1;
17475 if (f
->fonts_changed
)
17479 /* Compute differences in buffer positions, y-positions etc. for
17480 lines reused at the bottom of the window. Compute what we can
17482 if (first_unchanged_at_end_row
17483 /* No lines reused because we displayed everything up to the
17484 bottom of the window. */
17485 && it
.current_y
< it
.last_visible_y
)
17488 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17490 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17491 run
.current_y
= first_unchanged_at_end_row
->y
;
17492 run
.desired_y
= run
.current_y
+ dy
;
17493 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17497 delta
= delta_bytes
= dvpos
= dy
17498 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17499 first_unchanged_at_end_row
= NULL
;
17501 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17504 /* Find the cursor if not already found. We have to decide whether
17505 PT will appear on this window (it sometimes doesn't, but this is
17506 not a very frequent case.) This decision has to be made before
17507 the current matrix is altered. A value of cursor.vpos < 0 means
17508 that PT is either in one of the lines beginning at
17509 first_unchanged_at_end_row or below the window. Don't care for
17510 lines that might be displayed later at the window end; as
17511 mentioned, this is not a frequent case. */
17512 if (w
->cursor
.vpos
< 0)
17514 /* Cursor in unchanged rows at the top? */
17515 if (PT
< CHARPOS (start_pos
)
17516 && last_unchanged_at_beg_row
)
17518 row
= row_containing_pos (w
, PT
,
17519 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17520 last_unchanged_at_beg_row
+ 1, 0);
17522 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17525 /* Start from first_unchanged_at_end_row looking for PT. */
17526 else if (first_unchanged_at_end_row
)
17528 row
= row_containing_pos (w
, PT
- delta
,
17529 first_unchanged_at_end_row
, NULL
, 0);
17531 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17532 delta_bytes
, dy
, dvpos
);
17535 /* Give up if cursor was not found. */
17536 if (w
->cursor
.vpos
< 0)
17538 clear_glyph_matrix (w
->desired_matrix
);
17543 /* Don't let the cursor end in the scroll margins. */
17545 int this_scroll_margin
, cursor_height
;
17546 int frame_line_height
= default_line_pixel_height (w
);
17547 int window_total_lines
17548 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17550 this_scroll_margin
=
17551 max (0, min (scroll_margin
, window_total_lines
/ 4));
17552 this_scroll_margin
*= frame_line_height
;
17553 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17555 if ((w
->cursor
.y
< this_scroll_margin
17556 && CHARPOS (start
) > BEGV
)
17557 /* Old redisplay didn't take scroll margin into account at the bottom,
17558 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17559 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17560 ? cursor_height
+ this_scroll_margin
17561 : 1)) > it
.last_visible_y
)
17563 w
->cursor
.vpos
= -1;
17564 clear_glyph_matrix (w
->desired_matrix
);
17569 /* Scroll the display. Do it before changing the current matrix so
17570 that xterm.c doesn't get confused about where the cursor glyph is
17572 if (dy
&& run
.height
)
17576 if (FRAME_WINDOW_P (f
))
17578 FRAME_RIF (f
)->update_window_begin_hook (w
);
17579 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17580 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17581 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17585 /* Terminal frame. In this case, dvpos gives the number of
17586 lines to scroll by; dvpos < 0 means scroll up. */
17588 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17589 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17590 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17591 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17592 + window_internal_height (w
));
17594 #if defined (HAVE_GPM) || defined (MSDOS)
17595 x_clear_window_mouse_face (w
);
17597 /* Perform the operation on the screen. */
17600 /* Scroll last_unchanged_at_beg_row to the end of the
17601 window down dvpos lines. */
17602 set_terminal_window (f
, end
);
17604 /* On dumb terminals delete dvpos lines at the end
17605 before inserting dvpos empty lines. */
17606 if (!FRAME_SCROLL_REGION_OK (f
))
17607 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17609 /* Insert dvpos empty lines in front of
17610 last_unchanged_at_beg_row. */
17611 ins_del_lines (f
, from
, dvpos
);
17613 else if (dvpos
< 0)
17615 /* Scroll up last_unchanged_at_beg_vpos to the end of
17616 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17617 set_terminal_window (f
, end
);
17619 /* Delete dvpos lines in front of
17620 last_unchanged_at_beg_vpos. ins_del_lines will set
17621 the cursor to the given vpos and emit |dvpos| delete
17623 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17625 /* On a dumb terminal insert dvpos empty lines at the
17627 if (!FRAME_SCROLL_REGION_OK (f
))
17628 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17631 set_terminal_window (f
, 0);
17637 /* Shift reused rows of the current matrix to the right position.
17638 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17640 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17641 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17644 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17645 bottom_vpos
, dvpos
);
17646 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17649 else if (dvpos
> 0)
17651 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17652 bottom_vpos
, dvpos
);
17653 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17654 first_unchanged_at_end_vpos
+ dvpos
);
17657 /* For frame-based redisplay, make sure that current frame and window
17658 matrix are in sync with respect to glyph memory. */
17659 if (!FRAME_WINDOW_P (f
))
17660 sync_frame_with_window_matrix_rows (w
);
17662 /* Adjust buffer positions in reused rows. */
17663 if (delta
|| delta_bytes
)
17664 increment_matrix_positions (current_matrix
,
17665 first_unchanged_at_end_vpos
+ dvpos
,
17666 bottom_vpos
, delta
, delta_bytes
);
17668 /* Adjust Y positions. */
17670 shift_glyph_matrix (w
, current_matrix
,
17671 first_unchanged_at_end_vpos
+ dvpos
,
17674 if (first_unchanged_at_end_row
)
17676 first_unchanged_at_end_row
+= dvpos
;
17677 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17678 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17679 first_unchanged_at_end_row
= NULL
;
17682 /* If scrolling up, there may be some lines to display at the end of
17684 last_text_row_at_end
= NULL
;
17687 /* Scrolling up can leave for example a partially visible line
17688 at the end of the window to be redisplayed. */
17689 /* Set last_row to the glyph row in the current matrix where the
17690 window end line is found. It has been moved up or down in
17691 the matrix by dvpos. */
17692 int last_vpos
= w
->window_end_vpos
+ dvpos
;
17693 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17695 /* If last_row is the window end line, it should display text. */
17696 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17698 /* If window end line was partially visible before, begin
17699 displaying at that line. Otherwise begin displaying with the
17700 line following it. */
17701 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17703 init_to_row_start (&it
, w
, last_row
);
17704 it
.vpos
= last_vpos
;
17705 it
.current_y
= last_row
->y
;
17709 init_to_row_end (&it
, w
, last_row
);
17710 it
.vpos
= 1 + last_vpos
;
17711 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17715 /* We may start in a continuation line. If so, we have to
17716 get the right continuation_lines_width and current_x. */
17717 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17718 it
.hpos
= it
.current_x
= 0;
17720 /* Display the rest of the lines at the window end. */
17721 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17722 while (it
.current_y
< it
.last_visible_y
&& !f
->fonts_changed
)
17724 /* Is it always sure that the display agrees with lines in
17725 the current matrix? I don't think so, so we mark rows
17726 displayed invalid in the current matrix by setting their
17727 enabled_p flag to zero. */
17728 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17729 if (display_line (&it
))
17730 last_text_row_at_end
= it
.glyph_row
- 1;
17734 /* Update window_end_pos and window_end_vpos. */
17735 if (first_unchanged_at_end_row
&& !last_text_row_at_end
)
17737 /* Window end line if one of the preserved rows from the current
17738 matrix. Set row to the last row displaying text in current
17739 matrix starting at first_unchanged_at_end_row, after
17741 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17742 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17743 first_unchanged_at_end_row
);
17744 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17745 adjust_window_ends (w
, row
, 1);
17746 eassert (w
->window_end_bytepos
>= 0);
17747 IF_DEBUG (debug_method_add (w
, "A"));
17749 else if (last_text_row_at_end
)
17751 adjust_window_ends (w
, last_text_row_at_end
, 0);
17752 eassert (w
->window_end_bytepos
>= 0);
17753 IF_DEBUG (debug_method_add (w
, "B"));
17755 else if (last_text_row
)
17757 /* We have displayed either to the end of the window or at the
17758 end of the window, i.e. the last row with text is to be found
17759 in the desired matrix. */
17760 adjust_window_ends (w
, last_text_row
, 0);
17761 eassert (w
->window_end_bytepos
>= 0);
17763 else if (first_unchanged_at_end_row
== NULL
17764 && last_text_row
== NULL
17765 && last_text_row_at_end
== NULL
)
17767 /* Displayed to end of window, but no line containing text was
17768 displayed. Lines were deleted at the end of the window. */
17769 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17770 int vpos
= w
->window_end_vpos
;
17771 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17772 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17775 row
== NULL
&& vpos
>= first_vpos
;
17776 --vpos
, --current_row
, --desired_row
)
17778 if (desired_row
->enabled_p
)
17780 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17783 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17787 eassert (row
!= NULL
);
17788 w
->window_end_vpos
= vpos
+ 1;
17789 w
->window_end_pos
= Z
- MATRIX_ROW_END_CHARPOS (row
);
17790 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17791 eassert (w
->window_end_bytepos
>= 0);
17792 IF_DEBUG (debug_method_add (w
, "C"));
17797 IF_DEBUG (debug_end_pos
= w
->window_end_pos
;
17798 debug_end_vpos
= w
->window_end_vpos
);
17800 /* Record that display has not been completed. */
17801 w
->window_end_valid
= 0;
17802 w
->desired_matrix
->no_scrolling_p
= 1;
17810 /***********************************************************************
17811 More debugging support
17812 ***********************************************************************/
17816 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17817 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17818 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17821 /* Dump the contents of glyph matrix MATRIX on stderr.
17823 GLYPHS 0 means don't show glyph contents.
17824 GLYPHS 1 means show glyphs in short form
17825 GLYPHS > 1 means show glyphs in long form. */
17828 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17831 for (i
= 0; i
< matrix
->nrows
; ++i
)
17832 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17836 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17837 the glyph row and area where the glyph comes from. */
17840 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17842 if (glyph
->type
== CHAR_GLYPH
17843 || glyph
->type
== GLYPHLESS_GLYPH
)
17846 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17847 glyph
- row
->glyphs
[TEXT_AREA
],
17848 (glyph
->type
== CHAR_GLYPH
17852 (BUFFERP (glyph
->object
)
17854 : (STRINGP (glyph
->object
)
17856 : (INTEGERP (glyph
->object
)
17859 glyph
->pixel_width
,
17861 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17865 glyph
->left_box_line_p
,
17866 glyph
->right_box_line_p
);
17868 else if (glyph
->type
== STRETCH_GLYPH
)
17871 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17872 glyph
- row
->glyphs
[TEXT_AREA
],
17875 (BUFFERP (glyph
->object
)
17877 : (STRINGP (glyph
->object
)
17879 : (INTEGERP (glyph
->object
)
17882 glyph
->pixel_width
,
17886 glyph
->left_box_line_p
,
17887 glyph
->right_box_line_p
);
17889 else if (glyph
->type
== IMAGE_GLYPH
)
17892 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17893 glyph
- row
->glyphs
[TEXT_AREA
],
17896 (BUFFERP (glyph
->object
)
17898 : (STRINGP (glyph
->object
)
17900 : (INTEGERP (glyph
->object
)
17903 glyph
->pixel_width
,
17907 glyph
->left_box_line_p
,
17908 glyph
->right_box_line_p
);
17910 else if (glyph
->type
== COMPOSITE_GLYPH
)
17913 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17914 glyph
- row
->glyphs
[TEXT_AREA
],
17917 (BUFFERP (glyph
->object
)
17919 : (STRINGP (glyph
->object
)
17921 : (INTEGERP (glyph
->object
)
17924 glyph
->pixel_width
,
17926 if (glyph
->u
.cmp
.automatic
)
17929 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17930 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17932 glyph
->left_box_line_p
,
17933 glyph
->right_box_line_p
);
17938 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17939 GLYPHS 0 means don't show glyph contents.
17940 GLYPHS 1 means show glyphs in short form
17941 GLYPHS > 1 means show glyphs in long form. */
17944 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17948 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17949 fprintf (stderr
, "==============================================================================\n");
17951 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
17952 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
17954 MATRIX_ROW_START_CHARPOS (row
),
17955 MATRIX_ROW_END_CHARPOS (row
),
17956 row
->used
[TEXT_AREA
],
17957 row
->contains_overlapping_glyphs_p
,
17959 row
->truncated_on_left_p
,
17960 row
->truncated_on_right_p
,
17962 MATRIX_ROW_CONTINUATION_LINE_P (row
),
17963 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
17966 row
->ends_in_middle_of_char_p
,
17967 row
->starts_in_middle_of_char_p
,
17973 row
->visible_height
,
17976 /* The next 3 lines should align to "Start" in the header. */
17977 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
17978 row
->end
.overlay_string_index
,
17979 row
->continuation_lines_width
);
17980 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
17981 CHARPOS (row
->start
.string_pos
),
17982 CHARPOS (row
->end
.string_pos
));
17983 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
17984 row
->end
.dpvec_index
);
17991 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
17993 struct glyph
*glyph
= row
->glyphs
[area
];
17994 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
17996 /* Glyph for a line end in text. */
17997 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18000 if (glyph
< glyph_end
)
18001 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18003 for (; glyph
< glyph_end
; ++glyph
)
18004 dump_glyph (row
, glyph
, area
);
18007 else if (glyphs
== 1)
18011 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18013 char *s
= alloca (row
->used
[area
] + 4);
18016 for (i
= 0; i
< row
->used
[area
]; ++i
)
18018 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18019 if (i
== row
->used
[area
] - 1
18020 && area
== TEXT_AREA
18021 && INTEGERP (glyph
->object
)
18022 && glyph
->type
== CHAR_GLYPH
18023 && glyph
->u
.ch
== ' ')
18025 strcpy (&s
[i
], "[\\n]");
18028 else if (glyph
->type
== CHAR_GLYPH
18029 && glyph
->u
.ch
< 0x80
18030 && glyph
->u
.ch
>= ' ')
18031 s
[i
] = glyph
->u
.ch
;
18037 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18043 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18044 Sdump_glyph_matrix
, 0, 1, "p",
18045 doc
: /* Dump the current matrix of the selected window to stderr.
18046 Shows contents of glyph row structures. With non-nil
18047 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18048 glyphs in short form, otherwise show glyphs in long form. */)
18049 (Lisp_Object glyphs
)
18051 struct window
*w
= XWINDOW (selected_window
);
18052 struct buffer
*buffer
= XBUFFER (w
->contents
);
18054 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18055 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18056 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18057 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18058 fprintf (stderr
, "=============================================\n");
18059 dump_glyph_matrix (w
->current_matrix
,
18060 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18065 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18066 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18069 struct frame
*f
= XFRAME (selected_frame
);
18070 dump_glyph_matrix (f
->current_matrix
, 1);
18075 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18076 doc
: /* Dump glyph row ROW to stderr.
18077 GLYPH 0 means don't dump glyphs.
18078 GLYPH 1 means dump glyphs in short form.
18079 GLYPH > 1 or omitted means dump glyphs in long form. */)
18080 (Lisp_Object row
, Lisp_Object glyphs
)
18082 struct glyph_matrix
*matrix
;
18085 CHECK_NUMBER (row
);
18086 matrix
= XWINDOW (selected_window
)->current_matrix
;
18088 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18089 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18091 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18096 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18097 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18098 GLYPH 0 means don't dump glyphs.
18099 GLYPH 1 means dump glyphs in short form.
18100 GLYPH > 1 or omitted means dump glyphs in long form. */)
18101 (Lisp_Object row
, Lisp_Object glyphs
)
18103 struct frame
*sf
= SELECTED_FRAME ();
18104 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18107 CHECK_NUMBER (row
);
18109 if (vpos
>= 0 && vpos
< m
->nrows
)
18110 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18111 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18116 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18117 doc
: /* Toggle tracing of redisplay.
18118 With ARG, turn tracing on if and only if ARG is positive. */)
18122 trace_redisplay_p
= !trace_redisplay_p
;
18125 arg
= Fprefix_numeric_value (arg
);
18126 trace_redisplay_p
= XINT (arg
) > 0;
18133 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18134 doc
: /* Like `format', but print result to stderr.
18135 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18136 (ptrdiff_t nargs
, Lisp_Object
*args
)
18138 Lisp_Object s
= Fformat (nargs
, args
);
18139 fprintf (stderr
, "%s", SDATA (s
));
18143 #endif /* GLYPH_DEBUG */
18147 /***********************************************************************
18148 Building Desired Matrix Rows
18149 ***********************************************************************/
18151 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18152 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18154 static struct glyph_row
*
18155 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18157 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18158 struct buffer
*buffer
= XBUFFER (w
->contents
);
18159 struct buffer
*old
= current_buffer
;
18160 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18161 int arrow_len
= SCHARS (overlay_arrow_string
);
18162 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18163 const unsigned char *p
;
18166 int n_glyphs_before
;
18168 set_buffer_temp (buffer
);
18169 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18170 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18171 SET_TEXT_POS (it
.position
, 0, 0);
18173 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18175 while (p
< arrow_end
)
18177 Lisp_Object face
, ilisp
;
18179 /* Get the next character. */
18181 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18184 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18185 if (! ASCII_CHAR_P (it
.c
))
18186 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18190 /* Get its face. */
18191 ilisp
= make_number (p
- arrow_string
);
18192 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18193 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18195 /* Compute its width, get its glyphs. */
18196 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18197 SET_TEXT_POS (it
.position
, -1, -1);
18198 PRODUCE_GLYPHS (&it
);
18200 /* If this character doesn't fit any more in the line, we have
18201 to remove some glyphs. */
18202 if (it
.current_x
> it
.last_visible_x
)
18204 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18209 set_buffer_temp (old
);
18210 return it
.glyph_row
;
18214 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18215 glyphs to insert is determined by produce_special_glyphs. */
18218 insert_left_trunc_glyphs (struct it
*it
)
18220 struct it truncate_it
;
18221 struct glyph
*from
, *end
, *to
, *toend
;
18223 eassert (!FRAME_WINDOW_P (it
->f
)
18224 || (!it
->glyph_row
->reversed_p
18225 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18226 || (it
->glyph_row
->reversed_p
18227 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18229 /* Get the truncation glyphs. */
18231 truncate_it
.current_x
= 0;
18232 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18233 truncate_it
.glyph_row
= &scratch_glyph_row
;
18234 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18235 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18236 truncate_it
.object
= make_number (0);
18237 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18239 /* Overwrite glyphs from IT with truncation glyphs. */
18240 if (!it
->glyph_row
->reversed_p
)
18242 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18244 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18245 end
= from
+ tused
;
18246 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18247 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18248 if (FRAME_WINDOW_P (it
->f
))
18250 /* On GUI frames, when variable-size fonts are displayed,
18251 the truncation glyphs may need more pixels than the row's
18252 glyphs they overwrite. We overwrite more glyphs to free
18253 enough screen real estate, and enlarge the stretch glyph
18254 on the right (see display_line), if there is one, to
18255 preserve the screen position of the truncation glyphs on
18258 struct glyph
*g
= to
;
18261 /* The first glyph could be partially visible, in which case
18262 it->glyph_row->x will be negative. But we want the left
18263 truncation glyphs to be aligned at the left margin of the
18264 window, so we override the x coordinate at which the row
18266 it
->glyph_row
->x
= 0;
18267 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18269 w
+= g
->pixel_width
;
18272 if (g
- to
- tused
> 0)
18274 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18275 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18277 used
= it
->glyph_row
->used
[TEXT_AREA
];
18278 if (it
->glyph_row
->truncated_on_right_p
18279 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18280 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18283 int extra
= w
- it
->truncation_pixel_width
;
18285 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18292 /* There may be padding glyphs left over. Overwrite them too. */
18293 if (!FRAME_WINDOW_P (it
->f
))
18295 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18297 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18304 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18308 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18310 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18311 that back to front. */
18312 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18313 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18314 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18315 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18316 if (FRAME_WINDOW_P (it
->f
))
18319 struct glyph
*g
= to
;
18321 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18323 w
+= g
->pixel_width
;
18326 if (to
- g
- tused
> 0)
18328 if (it
->glyph_row
->truncated_on_right_p
18329 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18330 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18332 int extra
= w
- it
->truncation_pixel_width
;
18334 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18338 while (from
>= end
&& to
>= toend
)
18340 if (!FRAME_WINDOW_P (it
->f
))
18342 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18345 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18346 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18347 while (from
>= end
&& to
>= toend
)
18353 /* Need to free some room before prepending additional
18355 int move_by
= from
- end
+ 1;
18356 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18357 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18359 for ( ; g
>= g0
; g
--)
18361 while (from
>= end
)
18363 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18368 /* Compute the hash code for ROW. */
18370 row_hash (struct glyph_row
*row
)
18373 unsigned hashval
= 0;
18375 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18376 for (k
= 0; k
< row
->used
[area
]; ++k
)
18377 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18378 + row
->glyphs
[area
][k
].u
.val
18379 + row
->glyphs
[area
][k
].face_id
18380 + row
->glyphs
[area
][k
].padding_p
18381 + (row
->glyphs
[area
][k
].type
<< 2));
18386 /* Compute the pixel height and width of IT->glyph_row.
18388 Most of the time, ascent and height of a display line will be equal
18389 to the max_ascent and max_height values of the display iterator
18390 structure. This is not the case if
18392 1. We hit ZV without displaying anything. In this case, max_ascent
18393 and max_height will be zero.
18395 2. We have some glyphs that don't contribute to the line height.
18396 (The glyph row flag contributes_to_line_height_p is for future
18397 pixmap extensions).
18399 The first case is easily covered by using default values because in
18400 these cases, the line height does not really matter, except that it
18401 must not be zero. */
18404 compute_line_metrics (struct it
*it
)
18406 struct glyph_row
*row
= it
->glyph_row
;
18408 if (FRAME_WINDOW_P (it
->f
))
18410 int i
, min_y
, max_y
;
18412 /* The line may consist of one space only, that was added to
18413 place the cursor on it. If so, the row's height hasn't been
18415 if (row
->height
== 0)
18417 if (it
->max_ascent
+ it
->max_descent
== 0)
18418 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18419 row
->ascent
= it
->max_ascent
;
18420 row
->height
= it
->max_ascent
+ it
->max_descent
;
18421 row
->phys_ascent
= it
->max_phys_ascent
;
18422 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18423 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18426 /* Compute the width of this line. */
18427 row
->pixel_width
= row
->x
;
18428 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18429 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18431 eassert (row
->pixel_width
>= 0);
18432 eassert (row
->ascent
>= 0 && row
->height
> 0);
18434 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18435 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18437 /* If first line's physical ascent is larger than its logical
18438 ascent, use the physical ascent, and make the row taller.
18439 This makes accented characters fully visible. */
18440 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18441 && row
->phys_ascent
> row
->ascent
)
18443 row
->height
+= row
->phys_ascent
- row
->ascent
;
18444 row
->ascent
= row
->phys_ascent
;
18447 /* Compute how much of the line is visible. */
18448 row
->visible_height
= row
->height
;
18450 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18451 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18453 if (row
->y
< min_y
)
18454 row
->visible_height
-= min_y
- row
->y
;
18455 if (row
->y
+ row
->height
> max_y
)
18456 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18460 row
->pixel_width
= row
->used
[TEXT_AREA
];
18461 if (row
->continued_p
)
18462 row
->pixel_width
-= it
->continuation_pixel_width
;
18463 else if (row
->truncated_on_right_p
)
18464 row
->pixel_width
-= it
->truncation_pixel_width
;
18465 row
->ascent
= row
->phys_ascent
= 0;
18466 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18467 row
->extra_line_spacing
= 0;
18470 /* Compute a hash code for this row. */
18471 row
->hash
= row_hash (row
);
18473 it
->max_ascent
= it
->max_descent
= 0;
18474 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18478 /* Append one space to the glyph row of iterator IT if doing a
18479 window-based redisplay. The space has the same face as
18480 IT->face_id. Value is non-zero if a space was added.
18482 This function is called to make sure that there is always one glyph
18483 at the end of a glyph row that the cursor can be set on under
18484 window-systems. (If there weren't such a glyph we would not know
18485 how wide and tall a box cursor should be displayed).
18487 At the same time this space let's a nicely handle clearing to the
18488 end of the line if the row ends in italic text. */
18491 append_space_for_newline (struct it
*it
, int default_face_p
)
18493 if (FRAME_WINDOW_P (it
->f
))
18495 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18497 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18498 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18500 /* Save some values that must not be changed.
18501 Must save IT->c and IT->len because otherwise
18502 ITERATOR_AT_END_P wouldn't work anymore after
18503 append_space_for_newline has been called. */
18504 enum display_element_type saved_what
= it
->what
;
18505 int saved_c
= it
->c
, saved_len
= it
->len
;
18506 int saved_char_to_display
= it
->char_to_display
;
18507 int saved_x
= it
->current_x
;
18508 int saved_face_id
= it
->face_id
;
18509 int saved_box_end
= it
->end_of_box_run_p
;
18510 struct text_pos saved_pos
;
18511 Lisp_Object saved_object
;
18514 saved_object
= it
->object
;
18515 saved_pos
= it
->position
;
18517 it
->what
= IT_CHARACTER
;
18518 memset (&it
->position
, 0, sizeof it
->position
);
18519 it
->object
= make_number (0);
18520 it
->c
= it
->char_to_display
= ' ';
18523 /* If the default face was remapped, be sure to use the
18524 remapped face for the appended newline. */
18525 if (default_face_p
)
18526 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18527 else if (it
->face_before_selective_p
)
18528 it
->face_id
= it
->saved_face_id
;
18529 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18530 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18531 /* In R2L rows, we will prepend a stretch glyph that will
18532 have the end_of_box_run_p flag set for it, so there's no
18533 need for the appended newline glyph to have that flag
18535 if (it
->glyph_row
->reversed_p
18536 /* But if the appended newline glyph goes all the way to
18537 the end of the row, there will be no stretch glyph,
18538 so leave the box flag set. */
18539 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18540 it
->end_of_box_run_p
= 0;
18542 PRODUCE_GLYPHS (it
);
18544 it
->override_ascent
= -1;
18545 it
->constrain_row_ascent_descent_p
= 0;
18546 it
->current_x
= saved_x
;
18547 it
->object
= saved_object
;
18548 it
->position
= saved_pos
;
18549 it
->what
= saved_what
;
18550 it
->face_id
= saved_face_id
;
18551 it
->len
= saved_len
;
18553 it
->char_to_display
= saved_char_to_display
;
18554 it
->end_of_box_run_p
= saved_box_end
;
18563 /* Extend the face of the last glyph in the text area of IT->glyph_row
18564 to the end of the display line. Called from display_line. If the
18565 glyph row is empty, add a space glyph to it so that we know the
18566 face to draw. Set the glyph row flag fill_line_p. If the glyph
18567 row is R2L, prepend a stretch glyph to cover the empty space to the
18568 left of the leftmost glyph. */
18571 extend_face_to_end_of_line (struct it
*it
)
18573 struct face
*face
, *default_face
;
18574 struct frame
*f
= it
->f
;
18576 /* If line is already filled, do nothing. Non window-system frames
18577 get a grace of one more ``pixel'' because their characters are
18578 1-``pixel'' wide, so they hit the equality too early. This grace
18579 is needed only for R2L rows that are not continued, to produce
18580 one extra blank where we could display the cursor. */
18581 if (it
->current_x
>= it
->last_visible_x
18582 + (!FRAME_WINDOW_P (f
)
18583 && it
->glyph_row
->reversed_p
18584 && !it
->glyph_row
->continued_p
))
18587 /* The default face, possibly remapped. */
18588 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18590 /* Face extension extends the background and box of IT->face_id
18591 to the end of the line. If the background equals the background
18592 of the frame, we don't have to do anything. */
18593 if (it
->face_before_selective_p
)
18594 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18596 face
= FACE_FROM_ID (f
, it
->face_id
);
18598 if (FRAME_WINDOW_P (f
)
18599 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18600 && face
->box
== FACE_NO_BOX
18601 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18603 && !it
->glyph_row
->reversed_p
)
18606 /* Set the glyph row flag indicating that the face of the last glyph
18607 in the text area has to be drawn to the end of the text area. */
18608 it
->glyph_row
->fill_line_p
= 1;
18610 /* If current character of IT is not ASCII, make sure we have the
18611 ASCII face. This will be automatically undone the next time
18612 get_next_display_element returns a multibyte character. Note
18613 that the character will always be single byte in unibyte
18615 if (!ASCII_CHAR_P (it
->c
))
18617 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18620 if (FRAME_WINDOW_P (f
))
18622 /* If the row is empty, add a space with the current face of IT,
18623 so that we know which face to draw. */
18624 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18626 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18627 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18628 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18630 #ifdef HAVE_WINDOW_SYSTEM
18631 if (it
->glyph_row
->reversed_p
)
18633 /* Prepend a stretch glyph to the row, such that the
18634 rightmost glyph will be drawn flushed all the way to the
18635 right margin of the window. The stretch glyph that will
18636 occupy the empty space, if any, to the left of the
18638 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18639 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18640 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18642 int row_width
, stretch_ascent
, stretch_width
;
18643 struct text_pos saved_pos
;
18644 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18646 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18647 row_width
+= g
->pixel_width
;
18648 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18649 if (stretch_width
> 0)
18652 (((it
->ascent
+ it
->descent
)
18653 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18654 saved_pos
= it
->position
;
18655 memset (&it
->position
, 0, sizeof it
->position
);
18656 saved_avoid_cursor
= it
->avoid_cursor_p
;
18657 it
->avoid_cursor_p
= 1;
18658 saved_face_id
= it
->face_id
;
18659 saved_box_start
= it
->start_of_box_run_p
;
18660 /* The last row's stretch glyph should get the default
18661 face, to avoid painting the rest of the window with
18662 the region face, if the region ends at ZV. */
18663 if (it
->glyph_row
->ends_at_zv_p
)
18664 it
->face_id
= default_face
->id
;
18666 it
->face_id
= face
->id
;
18667 it
->start_of_box_run_p
= 0;
18668 append_stretch_glyph (it
, make_number (0), stretch_width
,
18669 it
->ascent
+ it
->descent
, stretch_ascent
);
18670 it
->position
= saved_pos
;
18671 it
->avoid_cursor_p
= saved_avoid_cursor
;
18672 it
->face_id
= saved_face_id
;
18673 it
->start_of_box_run_p
= saved_box_start
;
18676 #endif /* HAVE_WINDOW_SYSTEM */
18680 /* Save some values that must not be changed. */
18681 int saved_x
= it
->current_x
;
18682 struct text_pos saved_pos
;
18683 Lisp_Object saved_object
;
18684 enum display_element_type saved_what
= it
->what
;
18685 int saved_face_id
= it
->face_id
;
18687 saved_object
= it
->object
;
18688 saved_pos
= it
->position
;
18690 it
->what
= IT_CHARACTER
;
18691 memset (&it
->position
, 0, sizeof it
->position
);
18692 it
->object
= make_number (0);
18693 it
->c
= it
->char_to_display
= ' ';
18695 /* The last row's blank glyphs should get the default face, to
18696 avoid painting the rest of the window with the region face,
18697 if the region ends at ZV. */
18698 if (it
->glyph_row
->ends_at_zv_p
)
18699 it
->face_id
= default_face
->id
;
18701 it
->face_id
= face
->id
;
18703 PRODUCE_GLYPHS (it
);
18705 while (it
->current_x
<= it
->last_visible_x
)
18706 PRODUCE_GLYPHS (it
);
18708 /* Don't count these blanks really. It would let us insert a left
18709 truncation glyph below and make us set the cursor on them, maybe. */
18710 it
->current_x
= saved_x
;
18711 it
->object
= saved_object
;
18712 it
->position
= saved_pos
;
18713 it
->what
= saved_what
;
18714 it
->face_id
= saved_face_id
;
18719 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18720 trailing whitespace. */
18723 trailing_whitespace_p (ptrdiff_t charpos
)
18725 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18728 while (bytepos
< ZV_BYTE
18729 && (c
= FETCH_CHAR (bytepos
),
18730 c
== ' ' || c
== '\t'))
18733 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18735 if (bytepos
!= PT_BYTE
)
18742 /* Highlight trailing whitespace, if any, in ROW. */
18745 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18747 int used
= row
->used
[TEXT_AREA
];
18751 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18752 struct glyph
*glyph
= start
+ used
- 1;
18754 if (row
->reversed_p
)
18756 /* Right-to-left rows need to be processed in the opposite
18757 direction, so swap the edge pointers. */
18759 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18762 /* Skip over glyphs inserted to display the cursor at the
18763 end of a line, for extending the face of the last glyph
18764 to the end of the line on terminals, and for truncation
18765 and continuation glyphs. */
18766 if (!row
->reversed_p
)
18768 while (glyph
>= start
18769 && glyph
->type
== CHAR_GLYPH
18770 && INTEGERP (glyph
->object
))
18775 while (glyph
<= start
18776 && glyph
->type
== CHAR_GLYPH
18777 && INTEGERP (glyph
->object
))
18781 /* If last glyph is a space or stretch, and it's trailing
18782 whitespace, set the face of all trailing whitespace glyphs in
18783 IT->glyph_row to `trailing-whitespace'. */
18784 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18785 && BUFFERP (glyph
->object
)
18786 && (glyph
->type
== STRETCH_GLYPH
18787 || (glyph
->type
== CHAR_GLYPH
18788 && glyph
->u
.ch
== ' '))
18789 && trailing_whitespace_p (glyph
->charpos
))
18791 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18795 if (!row
->reversed_p
)
18797 while (glyph
>= start
18798 && BUFFERP (glyph
->object
)
18799 && (glyph
->type
== STRETCH_GLYPH
18800 || (glyph
->type
== CHAR_GLYPH
18801 && glyph
->u
.ch
== ' ')))
18802 (glyph
--)->face_id
= face_id
;
18806 while (glyph
<= start
18807 && BUFFERP (glyph
->object
)
18808 && (glyph
->type
== STRETCH_GLYPH
18809 || (glyph
->type
== CHAR_GLYPH
18810 && glyph
->u
.ch
== ' ')))
18811 (glyph
++)->face_id
= face_id
;
18818 /* Value is non-zero if glyph row ROW should be
18819 considered to hold the buffer position CHARPOS. */
18822 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18826 if (charpos
== CHARPOS (row
->end
.pos
)
18827 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18829 /* Suppose the row ends on a string.
18830 Unless the row is continued, that means it ends on a newline
18831 in the string. If it's anything other than a display string
18832 (e.g., a before-string from an overlay), we don't want the
18833 cursor there. (This heuristic seems to give the optimal
18834 behavior for the various types of multi-line strings.)
18835 One exception: if the string has `cursor' property on one of
18836 its characters, we _do_ want the cursor there. */
18837 if (CHARPOS (row
->end
.string_pos
) >= 0)
18839 if (row
->continued_p
)
18843 /* Check for `display' property. */
18844 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18845 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18846 struct glyph
*glyph
;
18849 for (glyph
= end
; glyph
>= beg
; --glyph
)
18850 if (STRINGP (glyph
->object
))
18853 = Fget_char_property (make_number (charpos
),
18857 && display_prop_string_p (prop
, glyph
->object
));
18858 /* If there's a `cursor' property on one of the
18859 string's characters, this row is a cursor row,
18860 even though this is not a display string. */
18863 Lisp_Object s
= glyph
->object
;
18865 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18867 ptrdiff_t gpos
= glyph
->charpos
;
18869 if (!NILP (Fget_char_property (make_number (gpos
),
18881 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18883 /* If the row ends in middle of a real character,
18884 and the line is continued, we want the cursor here.
18885 That's because CHARPOS (ROW->end.pos) would equal
18886 PT if PT is before the character. */
18887 if (!row
->ends_in_ellipsis_p
)
18888 result
= row
->continued_p
;
18890 /* If the row ends in an ellipsis, then
18891 CHARPOS (ROW->end.pos) will equal point after the
18892 invisible text. We want that position to be displayed
18893 after the ellipsis. */
18896 /* If the row ends at ZV, display the cursor at the end of that
18897 row instead of at the start of the row below. */
18898 else if (row
->ends_at_zv_p
)
18907 /* Value is non-zero if glyph row ROW should be
18908 used to hold the cursor. */
18911 cursor_row_p (struct glyph_row
*row
)
18913 return row_for_charpos_p (row
, PT
);
18918 /* Push the property PROP so that it will be rendered at the current
18919 position in IT. Return 1 if PROP was successfully pushed, 0
18920 otherwise. Called from handle_line_prefix to handle the
18921 `line-prefix' and `wrap-prefix' properties. */
18924 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18926 struct text_pos pos
=
18927 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18929 eassert (it
->method
== GET_FROM_BUFFER
18930 || it
->method
== GET_FROM_DISPLAY_VECTOR
18931 || it
->method
== GET_FROM_STRING
);
18933 /* We need to save the current buffer/string position, so it will be
18934 restored by pop_it, because iterate_out_of_display_property
18935 depends on that being set correctly, but some situations leave
18936 it->position not yet set when this function is called. */
18937 push_it (it
, &pos
);
18939 if (STRINGP (prop
))
18941 if (SCHARS (prop
) == 0)
18948 it
->string_from_prefix_prop_p
= 1;
18949 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
18950 it
->current
.overlay_string_index
= -1;
18951 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
18952 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
18953 it
->method
= GET_FROM_STRING
;
18954 it
->stop_charpos
= 0;
18956 it
->base_level_stop
= 0;
18958 /* Force paragraph direction to be that of the parent
18960 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
18961 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
18963 it
->paragraph_embedding
= L2R
;
18965 /* Set up the bidi iterator for this display string. */
18968 it
->bidi_it
.string
.lstring
= it
->string
;
18969 it
->bidi_it
.string
.s
= NULL
;
18970 it
->bidi_it
.string
.schars
= it
->end_charpos
;
18971 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
18972 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
18973 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
18974 it
->bidi_it
.w
= it
->w
;
18975 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
18978 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
18980 it
->method
= GET_FROM_STRETCH
;
18983 #ifdef HAVE_WINDOW_SYSTEM
18984 else if (IMAGEP (prop
))
18986 it
->what
= IT_IMAGE
;
18987 it
->image_id
= lookup_image (it
->f
, prop
);
18988 it
->method
= GET_FROM_IMAGE
;
18990 #endif /* HAVE_WINDOW_SYSTEM */
18993 pop_it (it
); /* bogus display property, give up */
19000 /* Return the character-property PROP at the current position in IT. */
19003 get_it_property (struct it
*it
, Lisp_Object prop
)
19005 Lisp_Object position
, object
= it
->object
;
19007 if (STRINGP (object
))
19008 position
= make_number (IT_STRING_CHARPOS (*it
));
19009 else if (BUFFERP (object
))
19011 position
= make_number (IT_CHARPOS (*it
));
19012 object
= it
->window
;
19017 return Fget_char_property (position
, prop
, object
);
19020 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19023 handle_line_prefix (struct it
*it
)
19025 Lisp_Object prefix
;
19027 if (it
->continuation_lines_width
> 0)
19029 prefix
= get_it_property (it
, Qwrap_prefix
);
19031 prefix
= Vwrap_prefix
;
19035 prefix
= get_it_property (it
, Qline_prefix
);
19037 prefix
= Vline_prefix
;
19039 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19041 /* If the prefix is wider than the window, and we try to wrap
19042 it, it would acquire its own wrap prefix, and so on till the
19043 iterator stack overflows. So, don't wrap the prefix. */
19044 it
->line_wrap
= TRUNCATE
;
19045 it
->avoid_cursor_p
= 1;
19051 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19052 only for R2L lines from display_line and display_string, when they
19053 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19054 the line/string needs to be continued on the next glyph row. */
19056 unproduce_glyphs (struct it
*it
, int n
)
19058 struct glyph
*glyph
, *end
;
19060 eassert (it
->glyph_row
);
19061 eassert (it
->glyph_row
->reversed_p
);
19062 eassert (it
->area
== TEXT_AREA
);
19063 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19065 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19066 n
= it
->glyph_row
->used
[TEXT_AREA
];
19067 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19068 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19069 for ( ; glyph
< end
; glyph
++)
19070 glyph
[-n
] = *glyph
;
19073 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19074 and ROW->maxpos. */
19076 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19077 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19078 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19080 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19081 lines' rows is implemented for bidi-reordered rows. */
19083 /* ROW->minpos is the value of min_pos, the minimal buffer position
19084 we have in ROW, or ROW->start.pos if that is smaller. */
19085 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19086 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19088 /* We didn't find buffer positions smaller than ROW->start, or
19089 didn't find _any_ valid buffer positions in any of the glyphs,
19090 so we must trust the iterator's computed positions. */
19091 row
->minpos
= row
->start
.pos
;
19094 max_pos
= CHARPOS (it
->current
.pos
);
19095 max_bpos
= BYTEPOS (it
->current
.pos
);
19098 /* Here are the various use-cases for ending the row, and the
19099 corresponding values for ROW->maxpos:
19101 Line ends in a newline from buffer eol_pos + 1
19102 Line is continued from buffer max_pos + 1
19103 Line is truncated on right it->current.pos
19104 Line ends in a newline from string max_pos + 1(*)
19105 (*) + 1 only when line ends in a forward scan
19106 Line is continued from string max_pos
19107 Line is continued from display vector max_pos
19108 Line is entirely from a string min_pos == max_pos
19109 Line is entirely from a display vector min_pos == max_pos
19110 Line that ends at ZV ZV
19112 If you discover other use-cases, please add them here as
19114 if (row
->ends_at_zv_p
)
19115 row
->maxpos
= it
->current
.pos
;
19116 else if (row
->used
[TEXT_AREA
])
19118 int seen_this_string
= 0;
19119 struct glyph_row
*r1
= row
- 1;
19121 /* Did we see the same display string on the previous row? */
19122 if (STRINGP (it
->object
)
19123 /* this is not the first row */
19124 && row
> it
->w
->desired_matrix
->rows
19125 /* previous row is not the header line */
19126 && !r1
->mode_line_p
19127 /* previous row also ends in a newline from a string */
19128 && r1
->ends_in_newline_from_string_p
)
19130 struct glyph
*start
, *end
;
19132 /* Search for the last glyph of the previous row that came
19133 from buffer or string. Depending on whether the row is
19134 L2R or R2L, we need to process it front to back or the
19135 other way round. */
19136 if (!r1
->reversed_p
)
19138 start
= r1
->glyphs
[TEXT_AREA
];
19139 end
= start
+ r1
->used
[TEXT_AREA
];
19140 /* Glyphs inserted by redisplay have an integer (zero)
19141 as their object. */
19143 && INTEGERP ((end
- 1)->object
)
19144 && (end
- 1)->charpos
<= 0)
19148 if (EQ ((end
- 1)->object
, it
->object
))
19149 seen_this_string
= 1;
19152 /* If all the glyphs of the previous row were inserted
19153 by redisplay, it means the previous row was
19154 produced from a single newline, which is only
19155 possible if that newline came from the same string
19156 as the one which produced this ROW. */
19157 seen_this_string
= 1;
19161 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19162 start
= end
+ r1
->used
[TEXT_AREA
];
19164 && INTEGERP ((end
+ 1)->object
)
19165 && (end
+ 1)->charpos
<= 0)
19169 if (EQ ((end
+ 1)->object
, it
->object
))
19170 seen_this_string
= 1;
19173 seen_this_string
= 1;
19176 /* Take note of each display string that covers a newline only
19177 once, the first time we see it. This is for when a display
19178 string includes more than one newline in it. */
19179 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19181 /* If we were scanning the buffer forward when we displayed
19182 the string, we want to account for at least one buffer
19183 position that belongs to this row (position covered by
19184 the display string), so that cursor positioning will
19185 consider this row as a candidate when point is at the end
19186 of the visual line represented by this row. This is not
19187 required when scanning back, because max_pos will already
19188 have a much larger value. */
19189 if (CHARPOS (row
->end
.pos
) > max_pos
)
19190 INC_BOTH (max_pos
, max_bpos
);
19191 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19193 else if (CHARPOS (it
->eol_pos
) > 0)
19194 SET_TEXT_POS (row
->maxpos
,
19195 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19196 else if (row
->continued_p
)
19198 /* If max_pos is different from IT's current position, it
19199 means IT->method does not belong to the display element
19200 at max_pos. However, it also means that the display
19201 element at max_pos was displayed in its entirety on this
19202 line, which is equivalent to saying that the next line
19203 starts at the next buffer position. */
19204 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19205 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19208 INC_BOTH (max_pos
, max_bpos
);
19209 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19212 else if (row
->truncated_on_right_p
)
19213 /* display_line already called reseat_at_next_visible_line_start,
19214 which puts the iterator at the beginning of the next line, in
19215 the logical order. */
19216 row
->maxpos
= it
->current
.pos
;
19217 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19218 /* A line that is entirely from a string/image/stretch... */
19219 row
->maxpos
= row
->minpos
;
19224 row
->maxpos
= it
->current
.pos
;
19227 /* Construct the glyph row IT->glyph_row in the desired matrix of
19228 IT->w from text at the current position of IT. See dispextern.h
19229 for an overview of struct it. Value is non-zero if
19230 IT->glyph_row displays text, as opposed to a line displaying ZV
19234 display_line (struct it
*it
)
19236 struct glyph_row
*row
= it
->glyph_row
;
19237 Lisp_Object overlay_arrow_string
;
19239 void *wrap_data
= NULL
;
19240 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19241 int wrap_row_used
= -1;
19242 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19243 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19244 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19245 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19246 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19248 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19249 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19251 /* We always start displaying at hpos zero even if hscrolled. */
19252 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19254 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19255 >= it
->w
->desired_matrix
->nrows
)
19257 it
->w
->nrows_scale_factor
++;
19258 it
->f
->fonts_changed
= 1;
19262 /* Is IT->w showing the region? */
19263 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19265 /* Clear the result glyph row and enable it. */
19266 prepare_desired_row (row
);
19268 row
->y
= it
->current_y
;
19269 row
->start
= it
->start
;
19270 row
->continuation_lines_width
= it
->continuation_lines_width
;
19271 row
->displays_text_p
= 1;
19272 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19273 it
->starts_in_middle_of_char_p
= 0;
19275 /* Arrange the overlays nicely for our purposes. Usually, we call
19276 display_line on only one line at a time, in which case this
19277 can't really hurt too much, or we call it on lines which appear
19278 one after another in the buffer, in which case all calls to
19279 recenter_overlay_lists but the first will be pretty cheap. */
19280 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19282 /* Move over display elements that are not visible because we are
19283 hscrolled. This may stop at an x-position < IT->first_visible_x
19284 if the first glyph is partially visible or if we hit a line end. */
19285 if (it
->current_x
< it
->first_visible_x
)
19287 enum move_it_result move_result
;
19289 this_line_min_pos
= row
->start
.pos
;
19290 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19291 MOVE_TO_POS
| MOVE_TO_X
);
19292 /* If we are under a large hscroll, move_it_in_display_line_to
19293 could hit the end of the line without reaching
19294 it->first_visible_x. Pretend that we did reach it. This is
19295 especially important on a TTY, where we will call
19296 extend_face_to_end_of_line, which needs to know how many
19297 blank glyphs to produce. */
19298 if (it
->current_x
< it
->first_visible_x
19299 && (move_result
== MOVE_NEWLINE_OR_CR
19300 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19301 it
->current_x
= it
->first_visible_x
;
19303 /* Record the smallest positions seen while we moved over
19304 display elements that are not visible. This is needed by
19305 redisplay_internal for optimizing the case where the cursor
19306 stays inside the same line. The rest of this function only
19307 considers positions that are actually displayed, so
19308 RECORD_MAX_MIN_POS will not otherwise record positions that
19309 are hscrolled to the left of the left edge of the window. */
19310 min_pos
= CHARPOS (this_line_min_pos
);
19311 min_bpos
= BYTEPOS (this_line_min_pos
);
19315 /* We only do this when not calling `move_it_in_display_line_to'
19316 above, because move_it_in_display_line_to calls
19317 handle_line_prefix itself. */
19318 handle_line_prefix (it
);
19321 /* Get the initial row height. This is either the height of the
19322 text hscrolled, if there is any, or zero. */
19323 row
->ascent
= it
->max_ascent
;
19324 row
->height
= it
->max_ascent
+ it
->max_descent
;
19325 row
->phys_ascent
= it
->max_phys_ascent
;
19326 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19327 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19329 /* Utility macro to record max and min buffer positions seen until now. */
19330 #define RECORD_MAX_MIN_POS(IT) \
19333 int composition_p = !STRINGP ((IT)->string) \
19334 && ((IT)->what == IT_COMPOSITION); \
19335 ptrdiff_t current_pos = \
19336 composition_p ? (IT)->cmp_it.charpos \
19337 : IT_CHARPOS (*(IT)); \
19338 ptrdiff_t current_bpos = \
19339 composition_p ? CHAR_TO_BYTE (current_pos) \
19340 : IT_BYTEPOS (*(IT)); \
19341 if (current_pos < min_pos) \
19343 min_pos = current_pos; \
19344 min_bpos = current_bpos; \
19346 if (IT_CHARPOS (*it) > max_pos) \
19348 max_pos = IT_CHARPOS (*it); \
19349 max_bpos = IT_BYTEPOS (*it); \
19354 /* Loop generating characters. The loop is left with IT on the next
19355 character to display. */
19358 int n_glyphs_before
, hpos_before
, x_before
;
19360 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19362 /* Retrieve the next thing to display. Value is zero if end of
19364 if (!get_next_display_element (it
))
19366 /* Maybe add a space at the end of this line that is used to
19367 display the cursor there under X. Set the charpos of the
19368 first glyph of blank lines not corresponding to any text
19370 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19371 row
->exact_window_width_line_p
= 1;
19372 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19373 || row
->used
[TEXT_AREA
] == 0)
19375 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19376 row
->displays_text_p
= 0;
19378 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19379 && (!MINI_WINDOW_P (it
->w
)
19380 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19381 row
->indicate_empty_line_p
= 1;
19384 it
->continuation_lines_width
= 0;
19385 row
->ends_at_zv_p
= 1;
19386 /* A row that displays right-to-left text must always have
19387 its last face extended all the way to the end of line,
19388 even if this row ends in ZV, because we still write to
19389 the screen left to right. We also need to extend the
19390 last face if the default face is remapped to some
19391 different face, otherwise the functions that clear
19392 portions of the screen will clear with the default face's
19393 background color. */
19394 if (row
->reversed_p
19395 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19396 extend_face_to_end_of_line (it
);
19400 /* Now, get the metrics of what we want to display. This also
19401 generates glyphs in `row' (which is IT->glyph_row). */
19402 n_glyphs_before
= row
->used
[TEXT_AREA
];
19405 /* Remember the line height so far in case the next element doesn't
19406 fit on the line. */
19407 if (it
->line_wrap
!= TRUNCATE
)
19409 ascent
= it
->max_ascent
;
19410 descent
= it
->max_descent
;
19411 phys_ascent
= it
->max_phys_ascent
;
19412 phys_descent
= it
->max_phys_descent
;
19414 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19416 if (IT_DISPLAYING_WHITESPACE (it
))
19420 SAVE_IT (wrap_it
, *it
, wrap_data
);
19422 wrap_row_used
= row
->used
[TEXT_AREA
];
19423 wrap_row_ascent
= row
->ascent
;
19424 wrap_row_height
= row
->height
;
19425 wrap_row_phys_ascent
= row
->phys_ascent
;
19426 wrap_row_phys_height
= row
->phys_height
;
19427 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19428 wrap_row_min_pos
= min_pos
;
19429 wrap_row_min_bpos
= min_bpos
;
19430 wrap_row_max_pos
= max_pos
;
19431 wrap_row_max_bpos
= max_bpos
;
19437 PRODUCE_GLYPHS (it
);
19439 /* If this display element was in marginal areas, continue with
19441 if (it
->area
!= TEXT_AREA
)
19443 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19444 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19445 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19446 row
->phys_height
= max (row
->phys_height
,
19447 it
->max_phys_ascent
+ it
->max_phys_descent
);
19448 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19449 it
->max_extra_line_spacing
);
19450 set_iterator_to_next (it
, 1);
19454 /* Does the display element fit on the line? If we truncate
19455 lines, we should draw past the right edge of the window. If
19456 we don't truncate, we want to stop so that we can display the
19457 continuation glyph before the right margin. If lines are
19458 continued, there are two possible strategies for characters
19459 resulting in more than 1 glyph (e.g. tabs): Display as many
19460 glyphs as possible in this line and leave the rest for the
19461 continuation line, or display the whole element in the next
19462 line. Original redisplay did the former, so we do it also. */
19463 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19464 hpos_before
= it
->hpos
;
19467 if (/* Not a newline. */
19469 /* Glyphs produced fit entirely in the line. */
19470 && it
->current_x
< it
->last_visible_x
)
19472 it
->hpos
+= nglyphs
;
19473 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19474 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19475 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19476 row
->phys_height
= max (row
->phys_height
,
19477 it
->max_phys_ascent
+ it
->max_phys_descent
);
19478 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19479 it
->max_extra_line_spacing
);
19480 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19481 row
->x
= x
- it
->first_visible_x
;
19482 /* Record the maximum and minimum buffer positions seen so
19483 far in glyphs that will be displayed by this row. */
19485 RECORD_MAX_MIN_POS (it
);
19490 struct glyph
*glyph
;
19492 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19494 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19495 new_x
= x
+ glyph
->pixel_width
;
19497 if (/* Lines are continued. */
19498 it
->line_wrap
!= TRUNCATE
19499 && (/* Glyph doesn't fit on the line. */
19500 new_x
> it
->last_visible_x
19501 /* Or it fits exactly on a window system frame. */
19502 || (new_x
== it
->last_visible_x
19503 && FRAME_WINDOW_P (it
->f
)
19504 && (row
->reversed_p
19505 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19506 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19508 /* End of a continued line. */
19511 || (new_x
== it
->last_visible_x
19512 && FRAME_WINDOW_P (it
->f
)
19513 && (row
->reversed_p
19514 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19515 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19517 /* Current glyph is the only one on the line or
19518 fits exactly on the line. We must continue
19519 the line because we can't draw the cursor
19520 after the glyph. */
19521 row
->continued_p
= 1;
19522 it
->current_x
= new_x
;
19523 it
->continuation_lines_width
+= new_x
;
19525 if (i
== nglyphs
- 1)
19527 /* If line-wrap is on, check if a previous
19528 wrap point was found. */
19529 if (wrap_row_used
> 0
19530 /* Even if there is a previous wrap
19531 point, continue the line here as
19532 usual, if (i) the previous character
19533 was a space or tab AND (ii) the
19534 current character is not. */
19536 || IT_DISPLAYING_WHITESPACE (it
)))
19539 /* Record the maximum and minimum buffer
19540 positions seen so far in glyphs that will be
19541 displayed by this row. */
19543 RECORD_MAX_MIN_POS (it
);
19544 set_iterator_to_next (it
, 1);
19545 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19547 if (!get_next_display_element (it
))
19549 row
->exact_window_width_line_p
= 1;
19550 it
->continuation_lines_width
= 0;
19551 row
->continued_p
= 0;
19552 row
->ends_at_zv_p
= 1;
19554 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19556 row
->continued_p
= 0;
19557 row
->exact_window_width_line_p
= 1;
19561 else if (it
->bidi_p
)
19562 RECORD_MAX_MIN_POS (it
);
19564 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19565 && !FRAME_WINDOW_P (it
->f
))
19567 /* A padding glyph that doesn't fit on this line.
19568 This means the whole character doesn't fit
19570 if (row
->reversed_p
)
19571 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19572 - n_glyphs_before
);
19573 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19575 /* Fill the rest of the row with continuation
19576 glyphs like in 20.x. */
19577 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19578 < row
->glyphs
[1 + TEXT_AREA
])
19579 produce_special_glyphs (it
, IT_CONTINUATION
);
19581 row
->continued_p
= 1;
19582 it
->current_x
= x_before
;
19583 it
->continuation_lines_width
+= x_before
;
19585 /* Restore the height to what it was before the
19586 element not fitting on the line. */
19587 it
->max_ascent
= ascent
;
19588 it
->max_descent
= descent
;
19589 it
->max_phys_ascent
= phys_ascent
;
19590 it
->max_phys_descent
= phys_descent
;
19592 else if (wrap_row_used
> 0)
19595 if (row
->reversed_p
)
19596 unproduce_glyphs (it
,
19597 row
->used
[TEXT_AREA
] - wrap_row_used
);
19598 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19599 it
->continuation_lines_width
+= wrap_x
;
19600 row
->used
[TEXT_AREA
] = wrap_row_used
;
19601 row
->ascent
= wrap_row_ascent
;
19602 row
->height
= wrap_row_height
;
19603 row
->phys_ascent
= wrap_row_phys_ascent
;
19604 row
->phys_height
= wrap_row_phys_height
;
19605 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19606 min_pos
= wrap_row_min_pos
;
19607 min_bpos
= wrap_row_min_bpos
;
19608 max_pos
= wrap_row_max_pos
;
19609 max_bpos
= wrap_row_max_bpos
;
19610 row
->continued_p
= 1;
19611 row
->ends_at_zv_p
= 0;
19612 row
->exact_window_width_line_p
= 0;
19613 it
->continuation_lines_width
+= x
;
19615 /* Make sure that a non-default face is extended
19616 up to the right margin of the window. */
19617 extend_face_to_end_of_line (it
);
19619 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19621 /* A TAB that extends past the right edge of the
19622 window. This produces a single glyph on
19623 window system frames. We leave the glyph in
19624 this row and let it fill the row, but don't
19625 consume the TAB. */
19626 if ((row
->reversed_p
19627 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19628 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19629 produce_special_glyphs (it
, IT_CONTINUATION
);
19630 it
->continuation_lines_width
+= it
->last_visible_x
;
19631 row
->ends_in_middle_of_char_p
= 1;
19632 row
->continued_p
= 1;
19633 glyph
->pixel_width
= it
->last_visible_x
- x
;
19634 it
->starts_in_middle_of_char_p
= 1;
19638 /* Something other than a TAB that draws past
19639 the right edge of the window. Restore
19640 positions to values before the element. */
19641 if (row
->reversed_p
)
19642 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19643 - (n_glyphs_before
+ i
));
19644 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19646 /* Display continuation glyphs. */
19647 it
->current_x
= x_before
;
19648 it
->continuation_lines_width
+= x
;
19649 if (!FRAME_WINDOW_P (it
->f
)
19650 || (row
->reversed_p
19651 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19652 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19653 produce_special_glyphs (it
, IT_CONTINUATION
);
19654 row
->continued_p
= 1;
19656 extend_face_to_end_of_line (it
);
19658 if (nglyphs
> 1 && i
> 0)
19660 row
->ends_in_middle_of_char_p
= 1;
19661 it
->starts_in_middle_of_char_p
= 1;
19664 /* Restore the height to what it was before the
19665 element not fitting on the line. */
19666 it
->max_ascent
= ascent
;
19667 it
->max_descent
= descent
;
19668 it
->max_phys_ascent
= phys_ascent
;
19669 it
->max_phys_descent
= phys_descent
;
19674 else if (new_x
> it
->first_visible_x
)
19676 /* Increment number of glyphs actually displayed. */
19679 /* Record the maximum and minimum buffer positions
19680 seen so far in glyphs that will be displayed by
19683 RECORD_MAX_MIN_POS (it
);
19685 if (x
< it
->first_visible_x
)
19686 /* Glyph is partially visible, i.e. row starts at
19687 negative X position. */
19688 row
->x
= x
- it
->first_visible_x
;
19692 /* Glyph is completely off the left margin of the
19693 window. This should not happen because of the
19694 move_it_in_display_line at the start of this
19695 function, unless the text display area of the
19696 window is empty. */
19697 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19700 /* Even if this display element produced no glyphs at all,
19701 we want to record its position. */
19702 if (it
->bidi_p
&& nglyphs
== 0)
19703 RECORD_MAX_MIN_POS (it
);
19705 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19706 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19707 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19708 row
->phys_height
= max (row
->phys_height
,
19709 it
->max_phys_ascent
+ it
->max_phys_descent
);
19710 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19711 it
->max_extra_line_spacing
);
19713 /* End of this display line if row is continued. */
19714 if (row
->continued_p
|| row
->ends_at_zv_p
)
19719 /* Is this a line end? If yes, we're also done, after making
19720 sure that a non-default face is extended up to the right
19721 margin of the window. */
19722 if (ITERATOR_AT_END_OF_LINE_P (it
))
19724 int used_before
= row
->used
[TEXT_AREA
];
19726 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19728 /* Add a space at the end of the line that is used to
19729 display the cursor there. */
19730 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19731 append_space_for_newline (it
, 0);
19733 /* Extend the face to the end of the line. */
19734 extend_face_to_end_of_line (it
);
19736 /* Make sure we have the position. */
19737 if (used_before
== 0)
19738 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19740 /* Record the position of the newline, for use in
19742 it
->eol_pos
= it
->current
.pos
;
19744 /* Consume the line end. This skips over invisible lines. */
19745 set_iterator_to_next (it
, 1);
19746 it
->continuation_lines_width
= 0;
19750 /* Proceed with next display element. Note that this skips
19751 over lines invisible because of selective display. */
19752 set_iterator_to_next (it
, 1);
19754 /* If we truncate lines, we are done when the last displayed
19755 glyphs reach past the right margin of the window. */
19756 if (it
->line_wrap
== TRUNCATE
19757 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19758 ? (it
->current_x
>= it
->last_visible_x
)
19759 : (it
->current_x
> it
->last_visible_x
)))
19761 /* Maybe add truncation glyphs. */
19762 if (!FRAME_WINDOW_P (it
->f
)
19763 || (row
->reversed_p
19764 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19765 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19769 if (!row
->reversed_p
)
19771 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19772 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19777 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19778 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19780 /* Remove any padding glyphs at the front of ROW, to
19781 make room for the truncation glyphs we will be
19782 adding below. The loop below always inserts at
19783 least one truncation glyph, so also remove the
19784 last glyph added to ROW. */
19785 unproduce_glyphs (it
, i
+ 1);
19786 /* Adjust i for the loop below. */
19787 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19790 it
->current_x
= x_before
;
19791 if (!FRAME_WINDOW_P (it
->f
))
19793 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19795 row
->used
[TEXT_AREA
] = i
;
19796 produce_special_glyphs (it
, IT_TRUNCATION
);
19801 row
->used
[TEXT_AREA
] = i
;
19802 produce_special_glyphs (it
, IT_TRUNCATION
);
19805 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19807 /* Don't truncate if we can overflow newline into fringe. */
19808 if (!get_next_display_element (it
))
19810 it
->continuation_lines_width
= 0;
19811 row
->ends_at_zv_p
= 1;
19812 row
->exact_window_width_line_p
= 1;
19815 if (ITERATOR_AT_END_OF_LINE_P (it
))
19817 row
->exact_window_width_line_p
= 1;
19818 goto at_end_of_line
;
19820 it
->current_x
= x_before
;
19823 row
->truncated_on_right_p
= 1;
19824 it
->continuation_lines_width
= 0;
19825 reseat_at_next_visible_line_start (it
, 0);
19826 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19827 it
->hpos
= hpos_before
;
19833 bidi_unshelve_cache (wrap_data
, 1);
19835 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19836 at the left window margin. */
19837 if (it
->first_visible_x
19838 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19840 if (!FRAME_WINDOW_P (it
->f
)
19841 || (row
->reversed_p
19842 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19843 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19844 insert_left_trunc_glyphs (it
);
19845 row
->truncated_on_left_p
= 1;
19848 /* Remember the position at which this line ends.
19850 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19851 cannot be before the call to find_row_edges below, since that is
19852 where these positions are determined. */
19853 row
->end
= it
->current
;
19856 row
->minpos
= row
->start
.pos
;
19857 row
->maxpos
= row
->end
.pos
;
19861 /* ROW->minpos and ROW->maxpos must be the smallest and
19862 `1 + the largest' buffer positions in ROW. But if ROW was
19863 bidi-reordered, these two positions can be anywhere in the
19864 row, so we must determine them now. */
19865 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19868 /* If the start of this line is the overlay arrow-position, then
19869 mark this glyph row as the one containing the overlay arrow.
19870 This is clearly a mess with variable size fonts. It would be
19871 better to let it be displayed like cursors under X. */
19872 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19873 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19874 !NILP (overlay_arrow_string
)))
19876 /* Overlay arrow in window redisplay is a fringe bitmap. */
19877 if (STRINGP (overlay_arrow_string
))
19879 struct glyph_row
*arrow_row
19880 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19881 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19882 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19883 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19884 struct glyph
*p2
, *end
;
19886 /* Copy the arrow glyphs. */
19887 while (glyph
< arrow_end
)
19890 /* Throw away padding glyphs. */
19892 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19893 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19899 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19904 eassert (INTEGERP (overlay_arrow_string
));
19905 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19907 overlay_arrow_seen
= 1;
19910 /* Highlight trailing whitespace. */
19911 if (!NILP (Vshow_trailing_whitespace
))
19912 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19914 /* Compute pixel dimensions of this line. */
19915 compute_line_metrics (it
);
19917 /* Implementation note: No changes in the glyphs of ROW or in their
19918 faces can be done past this point, because compute_line_metrics
19919 computes ROW's hash value and stores it within the glyph_row
19922 /* Record whether this row ends inside an ellipsis. */
19923 row
->ends_in_ellipsis_p
19924 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19925 && it
->ellipsis_p
);
19927 /* Save fringe bitmaps in this row. */
19928 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19929 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19930 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19931 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19933 it
->left_user_fringe_bitmap
= 0;
19934 it
->left_user_fringe_face_id
= 0;
19935 it
->right_user_fringe_bitmap
= 0;
19936 it
->right_user_fringe_face_id
= 0;
19938 /* Maybe set the cursor. */
19939 cvpos
= it
->w
->cursor
.vpos
;
19941 /* In bidi-reordered rows, keep checking for proper cursor
19942 position even if one has been found already, because buffer
19943 positions in such rows change non-linearly with ROW->VPOS,
19944 when a line is continued. One exception: when we are at ZV,
19945 display cursor on the first suitable glyph row, since all
19946 the empty rows after that also have their position set to ZV. */
19947 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19948 lines' rows is implemented for bidi-reordered rows. */
19950 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
19951 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
19952 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
19953 && cursor_row_p (row
))
19954 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
19956 /* Prepare for the next line. This line starts horizontally at (X
19957 HPOS) = (0 0). Vertical positions are incremented. As a
19958 convenience for the caller, IT->glyph_row is set to the next
19960 it
->current_x
= it
->hpos
= 0;
19961 it
->current_y
+= row
->height
;
19962 SET_TEXT_POS (it
->eol_pos
, 0, 0);
19965 /* The next row should by default use the same value of the
19966 reversed_p flag as this one. set_iterator_to_next decides when
19967 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
19968 the flag accordingly. */
19969 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
19970 it
->glyph_row
->reversed_p
= row
->reversed_p
;
19971 it
->start
= row
->end
;
19972 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
19974 #undef RECORD_MAX_MIN_POS
19977 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
19978 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
19979 doc
: /* Return paragraph direction at point in BUFFER.
19980 Value is either `left-to-right' or `right-to-left'.
19981 If BUFFER is omitted or nil, it defaults to the current buffer.
19983 Paragraph direction determines how the text in the paragraph is displayed.
19984 In left-to-right paragraphs, text begins at the left margin of the window
19985 and the reading direction is generally left to right. In right-to-left
19986 paragraphs, text begins at the right margin and is read from right to left.
19988 See also `bidi-paragraph-direction'. */)
19989 (Lisp_Object buffer
)
19991 struct buffer
*buf
= current_buffer
;
19992 struct buffer
*old
= buf
;
19994 if (! NILP (buffer
))
19996 CHECK_BUFFER (buffer
);
19997 buf
= XBUFFER (buffer
);
20000 if (NILP (BVAR (buf
, bidi_display_reordering
))
20001 || NILP (BVAR (buf
, enable_multibyte_characters
))
20002 /* When we are loading loadup.el, the character property tables
20003 needed for bidi iteration are not yet available. */
20004 || !NILP (Vpurify_flag
))
20005 return Qleft_to_right
;
20006 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20007 return BVAR (buf
, bidi_paragraph_direction
);
20010 /* Determine the direction from buffer text. We could try to
20011 use current_matrix if it is up to date, but this seems fast
20012 enough as it is. */
20013 struct bidi_it itb
;
20014 ptrdiff_t pos
= BUF_PT (buf
);
20015 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20017 void *itb_data
= bidi_shelve_cache ();
20019 set_buffer_temp (buf
);
20020 /* bidi_paragraph_init finds the base direction of the paragraph
20021 by searching forward from paragraph start. We need the base
20022 direction of the current or _previous_ paragraph, so we need
20023 to make sure we are within that paragraph. To that end, find
20024 the previous non-empty line. */
20025 if (pos
>= ZV
&& pos
> BEGV
)
20026 DEC_BOTH (pos
, bytepos
);
20027 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20028 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20030 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20031 || c
== ' ' || c
== '\t' || c
== '\f')
20033 if (bytepos
<= BEGV_BYTE
)
20038 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20041 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20042 itb
.paragraph_dir
= NEUTRAL_DIR
;
20043 itb
.string
.s
= NULL
;
20044 itb
.string
.lstring
= Qnil
;
20045 itb
.string
.bufpos
= 0;
20046 itb
.string
.unibyte
= 0;
20047 /* We have no window to use here for ignoring window-specific
20048 overlays. Using NULL for window pointer will cause
20049 compute_display_string_pos to use the current buffer. */
20051 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20052 bidi_unshelve_cache (itb_data
, 0);
20053 set_buffer_temp (old
);
20054 switch (itb
.paragraph_dir
)
20057 return Qleft_to_right
;
20060 return Qright_to_left
;
20068 DEFUN ("move-point-visually", Fmove_point_visually
,
20069 Smove_point_visually
, 1, 1, 0,
20070 doc
: /* Move point in the visual order in the specified DIRECTION.
20071 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20074 Value is the new character position of point. */)
20075 (Lisp_Object direction
)
20077 struct window
*w
= XWINDOW (selected_window
);
20078 struct buffer
*b
= XBUFFER (w
->contents
);
20079 struct glyph_row
*row
;
20081 Lisp_Object paragraph_dir
;
20083 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20084 (!(ROW)->continued_p \
20085 && INTEGERP ((GLYPH)->object) \
20086 && (GLYPH)->type == CHAR_GLYPH \
20087 && (GLYPH)->u.ch == ' ' \
20088 && (GLYPH)->charpos >= 0 \
20089 && !(GLYPH)->avoid_cursor_p)
20091 CHECK_NUMBER (direction
);
20092 dir
= XINT (direction
);
20098 /* If current matrix is up-to-date, we can use the information
20099 recorded in the glyphs, at least as long as the goal is on the
20101 if (w
->window_end_valid
20102 && !windows_or_buffers_changed
20104 && !b
->clip_changed
20105 && !b
->prevent_redisplay_optimizations_p
20106 && !window_outdated (w
)
20107 && w
->cursor
.vpos
>= 0
20108 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20109 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20111 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20112 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20113 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20115 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20117 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20119 SET_PT (g
->charpos
);
20120 w
->cursor
.vpos
= -1;
20121 return make_number (PT
);
20123 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20127 if (BUFFERP (gpt
->object
))
20130 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20131 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20133 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20135 else if (BUFFERP (g
->object
))
20136 new_pos
= g
->charpos
;
20140 w
->cursor
.vpos
= -1;
20141 return make_number (PT
);
20143 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20145 /* Glyphs inserted at the end of a non-empty line for
20146 positioning the cursor have zero charpos, so we must
20147 deduce the value of point by other means. */
20148 if (g
->charpos
> 0)
20149 SET_PT (g
->charpos
);
20150 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20152 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20153 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20156 w
->cursor
.vpos
= -1;
20157 return make_number (PT
);
20160 if (g
== e
|| INTEGERP (g
->object
))
20162 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20163 goto simulate_display
;
20164 if (!row
->reversed_p
)
20168 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20169 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20170 goto simulate_display
;
20174 if (row
->reversed_p
&& !row
->continued_p
)
20176 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20177 w
->cursor
.vpos
= -1;
20178 return make_number (PT
);
20180 g
= row
->glyphs
[TEXT_AREA
];
20181 e
= g
+ row
->used
[TEXT_AREA
];
20182 for ( ; g
< e
; g
++)
20184 if (BUFFERP (g
->object
)
20185 /* Empty lines have only one glyph, which stands
20186 for the newline, and whose charpos is the
20187 buffer position of the newline. */
20188 || ROW_GLYPH_NEWLINE_P (row
, g
)
20189 /* When the buffer ends in a newline, the line at
20190 EOB also has one glyph, but its charpos is -1. */
20191 || (row
->ends_at_zv_p
20192 && !row
->reversed_p
20193 && INTEGERP (g
->object
)
20194 && g
->type
== CHAR_GLYPH
20195 && g
->u
.ch
== ' '))
20197 if (g
->charpos
> 0)
20198 SET_PT (g
->charpos
);
20199 else if (!row
->reversed_p
20200 && row
->ends_at_zv_p
20205 w
->cursor
.vpos
= -1;
20206 return make_number (PT
);
20212 if (!row
->reversed_p
&& !row
->continued_p
)
20214 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20215 w
->cursor
.vpos
= -1;
20216 return make_number (PT
);
20218 e
= row
->glyphs
[TEXT_AREA
];
20219 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20220 for ( ; g
>= e
; g
--)
20222 if (BUFFERP (g
->object
)
20223 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20225 /* Empty R2L lines on GUI frames have the buffer
20226 position of the newline stored in the stretch
20228 || g
->type
== STRETCH_GLYPH
20229 || (row
->ends_at_zv_p
20231 && INTEGERP (g
->object
)
20232 && g
->type
== CHAR_GLYPH
20233 && g
->u
.ch
== ' '))
20235 if (g
->charpos
> 0)
20236 SET_PT (g
->charpos
);
20237 else if (row
->reversed_p
20238 && row
->ends_at_zv_p
20243 w
->cursor
.vpos
= -1;
20244 return make_number (PT
);
20253 /* If we wind up here, we failed to move by using the glyphs, so we
20254 need to simulate display instead. */
20257 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20259 paragraph_dir
= Qleft_to_right
;
20260 if (EQ (paragraph_dir
, Qright_to_left
))
20262 if (PT
<= BEGV
&& dir
< 0)
20263 xsignal0 (Qbeginning_of_buffer
);
20264 else if (PT
>= ZV
&& dir
> 0)
20265 xsignal0 (Qend_of_buffer
);
20268 struct text_pos pt
;
20270 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20272 bool overshoot_expected
= false;
20273 bool target_is_eol_p
= false;
20275 /* Setup the arena. */
20276 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20277 start_display (&it
, w
, pt
);
20279 if (it
.cmp_it
.id
< 0
20280 && it
.method
== GET_FROM_STRING
20281 && it
.area
== TEXT_AREA
20282 && it
.string_from_display_prop_p
20283 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20284 overshoot_expected
= true;
20286 /* Find the X coordinate of point. We start from the beginning
20287 of this or previous line to make sure we are before point in
20288 the logical order (since the move_it_* functions can only
20290 reseat_at_previous_visible_line_start (&it
);
20291 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20292 if (IT_CHARPOS (it
) != PT
)
20293 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20294 -1, -1, -1, MOVE_TO_POS
);
20295 pt_x
= it
.current_x
;
20297 if (dir
> 0 || overshoot_expected
)
20299 struct glyph_row
*row
= it
.glyph_row
;
20301 /* When point is at beginning of line, we don't have
20302 information about the glyph there loaded into struct
20303 it. Calling get_next_display_element fixes that. */
20305 get_next_display_element (&it
);
20306 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20307 it
.glyph_row
= NULL
;
20308 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20309 it
.glyph_row
= row
;
20310 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20311 it, lest it will become out of sync with it's buffer
20313 it
.current_x
= pt_x
;
20316 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20317 pixel_width
= it
.pixel_width
;
20318 if (overshoot_expected
&& at_eol_p
)
20320 else if (pixel_width
<= 0)
20323 /* If there's a display string at point, we are actually at the
20324 glyph to the left of point, so we need to correct the X
20326 if (overshoot_expected
)
20327 pt_x
+= pixel_width
;
20329 /* Compute target X coordinate, either to the left or to the
20330 right of point. On TTY frames, all characters have the same
20331 pixel width of 1, so we can use that. On GUI frames we don't
20332 have an easy way of getting at the pixel width of the
20333 character to the left of point, so we use a different method
20334 of getting to that place. */
20336 target_x
= pt_x
+ pixel_width
;
20338 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20340 /* Target X coordinate could be one line above or below the line
20341 of point, in which case we need to adjust the target X
20342 coordinate. Also, if moving to the left, we need to begin at
20343 the left edge of the point's screen line. */
20348 start_display (&it
, w
, pt
);
20349 reseat_at_previous_visible_line_start (&it
);
20350 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20352 move_it_by_lines (&it
, pt_vpos
);
20356 move_it_by_lines (&it
, -1);
20357 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20358 target_is_eol_p
= true;
20364 || (target_x
>= it
.last_visible_x
20365 && it
.line_wrap
!= TRUNCATE
))
20368 move_it_by_lines (&it
, 0);
20369 move_it_by_lines (&it
, 1);
20374 /* Move to the target X coordinate. */
20375 #ifdef HAVE_WINDOW_SYSTEM
20376 /* On GUI frames, as we don't know the X coordinate of the
20377 character to the left of point, moving point to the left
20378 requires walking, one grapheme cluster at a time, until we
20379 find ourself at a place immediately to the left of the
20380 character at point. */
20381 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20383 struct text_pos new_pos
= it
.current
.pos
;
20384 enum move_it_result rc
= MOVE_X_REACHED
;
20386 while (it
.current_x
+ it
.pixel_width
<= target_x
20387 && rc
== MOVE_X_REACHED
)
20389 int new_x
= it
.current_x
+ it
.pixel_width
;
20391 new_pos
= it
.current
.pos
;
20392 if (new_x
== it
.current_x
)
20394 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20395 MOVE_TO_POS
| MOVE_TO_X
);
20396 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20399 /* If we ended up on a composed character inside
20400 bidi-reordered text (e.g., Hebrew text with diacritics),
20401 the iterator gives us the buffer position of the last (in
20402 logical order) character of the composed grapheme cluster,
20403 which is not what we want. So we cheat: we compute the
20404 character position of the character that follows (in the
20405 logical order) the one where the above loop stopped. That
20406 character will appear on display to the left of point. */
20408 && it
.bidi_it
.scan_dir
== -1
20409 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20411 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20412 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20414 it
.current
.pos
= new_pos
;
20418 if (it
.current_x
!= target_x
)
20419 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20421 /* When lines are truncated, the above loop will stop at the
20422 window edge. But we want to get to the end of line, even if
20423 it is beyond the window edge; automatic hscroll will then
20424 scroll the window to show point as appropriate. */
20425 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20426 && get_next_display_element (&it
))
20428 struct text_pos new_pos
= it
.current
.pos
;
20430 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20432 set_iterator_to_next (&it
, 0);
20433 if (it
.method
== GET_FROM_BUFFER
)
20434 new_pos
= it
.current
.pos
;
20435 if (!get_next_display_element (&it
))
20439 it
.current
.pos
= new_pos
;
20442 /* If we ended up in a display string that covers point, move to
20443 buffer position to the right in the visual order. */
20446 while (IT_CHARPOS (it
) == PT
)
20448 set_iterator_to_next (&it
, 0);
20449 if (!get_next_display_element (&it
))
20454 /* Move point to that position. */
20455 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20458 return make_number (PT
);
20460 #undef ROW_GLYPH_NEWLINE_P
20464 /***********************************************************************
20466 ***********************************************************************/
20468 /* Redisplay the menu bar in the frame for window W.
20470 The menu bar of X frames that don't have X toolkit support is
20471 displayed in a special window W->frame->menu_bar_window.
20473 The menu bar of terminal frames is treated specially as far as
20474 glyph matrices are concerned. Menu bar lines are not part of
20475 windows, so the update is done directly on the frame matrix rows
20476 for the menu bar. */
20479 display_menu_bar (struct window
*w
)
20481 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20486 /* Don't do all this for graphical frames. */
20488 if (FRAME_W32_P (f
))
20491 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20497 if (FRAME_NS_P (f
))
20499 #endif /* HAVE_NS */
20501 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20502 eassert (!FRAME_WINDOW_P (f
));
20503 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20504 it
.first_visible_x
= 0;
20505 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20506 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20507 if (FRAME_WINDOW_P (f
))
20509 /* Menu bar lines are displayed in the desired matrix of the
20510 dummy window menu_bar_window. */
20511 struct window
*menu_w
;
20512 menu_w
= XWINDOW (f
->menu_bar_window
);
20513 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20515 it
.first_visible_x
= 0;
20516 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20519 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20521 /* This is a TTY frame, i.e. character hpos/vpos are used as
20523 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20525 it
.first_visible_x
= 0;
20526 it
.last_visible_x
= FRAME_COLS (f
);
20529 /* FIXME: This should be controlled by a user option. See the
20530 comments in redisplay_tool_bar and display_mode_line about
20532 it
.paragraph_embedding
= L2R
;
20534 /* Clear all rows of the menu bar. */
20535 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20537 struct glyph_row
*row
= it
.glyph_row
+ i
;
20538 clear_glyph_row (row
);
20539 row
->enabled_p
= 1;
20540 row
->full_width_p
= 1;
20543 /* Display all items of the menu bar. */
20544 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20545 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20547 Lisp_Object string
;
20549 /* Stop at nil string. */
20550 string
= AREF (items
, i
+ 1);
20554 /* Remember where item was displayed. */
20555 ASET (items
, i
+ 3, make_number (it
.hpos
));
20557 /* Display the item, pad with one space. */
20558 if (it
.current_x
< it
.last_visible_x
)
20559 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20560 SCHARS (string
) + 1, 0, 0, -1);
20563 /* Fill out the line with spaces. */
20564 if (it
.current_x
< it
.last_visible_x
)
20565 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20567 /* Compute the total height of the lines. */
20568 compute_line_metrics (&it
);
20573 /***********************************************************************
20575 ***********************************************************************/
20577 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20578 FORCE is non-zero, redisplay mode lines unconditionally.
20579 Otherwise, redisplay only mode lines that are garbaged. Value is
20580 the number of windows whose mode lines were redisplayed. */
20583 redisplay_mode_lines (Lisp_Object window
, int force
)
20587 while (!NILP (window
))
20589 struct window
*w
= XWINDOW (window
);
20591 if (WINDOWP (w
->contents
))
20592 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20594 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20595 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20597 struct text_pos lpoint
;
20598 struct buffer
*old
= current_buffer
;
20600 /* Set the window's buffer for the mode line display. */
20601 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20602 set_buffer_internal_1 (XBUFFER (w
->contents
));
20604 /* Point refers normally to the selected window. For any
20605 other window, set up appropriate value. */
20606 if (!EQ (window
, selected_window
))
20608 struct text_pos pt
;
20610 CLIP_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20611 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20614 /* Display mode lines. */
20615 clear_glyph_matrix (w
->desired_matrix
);
20616 if (display_mode_lines (w
))
20619 w
->must_be_updated_p
= 1;
20622 /* Restore old settings. */
20623 set_buffer_internal_1 (old
);
20624 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20634 /* Display the mode and/or header line of window W. Value is the
20635 sum number of mode lines and header lines displayed. */
20638 display_mode_lines (struct window
*w
)
20640 Lisp_Object old_selected_window
= selected_window
;
20641 Lisp_Object old_selected_frame
= selected_frame
;
20642 Lisp_Object new_frame
= w
->frame
;
20643 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20646 selected_frame
= new_frame
;
20647 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20648 or window's point, then we'd need select_window_1 here as well. */
20649 XSETWINDOW (selected_window
, w
);
20650 XFRAME (new_frame
)->selected_window
= selected_window
;
20652 /* These will be set while the mode line specs are processed. */
20653 line_number_displayed
= 0;
20654 w
->column_number_displayed
= -1;
20656 if (WINDOW_WANTS_MODELINE_P (w
))
20658 struct window
*sel_w
= XWINDOW (old_selected_window
);
20660 /* Select mode line face based on the real selected window. */
20661 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20662 BVAR (current_buffer
, mode_line_format
));
20666 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20668 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20669 BVAR (current_buffer
, header_line_format
));
20673 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20674 selected_frame
= old_selected_frame
;
20675 selected_window
= old_selected_window
;
20680 /* Display mode or header line of window W. FACE_ID specifies which
20681 line to display; it is either MODE_LINE_FACE_ID or
20682 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20683 display. Value is the pixel height of the mode/header line
20687 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20691 ptrdiff_t count
= SPECPDL_INDEX ();
20693 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20694 /* Don't extend on a previously drawn mode-line.
20695 This may happen if called from pos_visible_p. */
20696 it
.glyph_row
->enabled_p
= 0;
20697 prepare_desired_row (it
.glyph_row
);
20699 it
.glyph_row
->mode_line_p
= 1;
20701 /* FIXME: This should be controlled by a user option. But
20702 supporting such an option is not trivial, since the mode line is
20703 made up of many separate strings. */
20704 it
.paragraph_embedding
= L2R
;
20706 record_unwind_protect (unwind_format_mode_line
,
20707 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20709 mode_line_target
= MODE_LINE_DISPLAY
;
20711 /* Temporarily make frame's keyboard the current kboard so that
20712 kboard-local variables in the mode_line_format will get the right
20714 push_kboard (FRAME_KBOARD (it
.f
));
20715 record_unwind_save_match_data ();
20716 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20719 unbind_to (count
, Qnil
);
20721 /* Fill up with spaces. */
20722 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20724 compute_line_metrics (&it
);
20725 it
.glyph_row
->full_width_p
= 1;
20726 it
.glyph_row
->continued_p
= 0;
20727 it
.glyph_row
->truncated_on_left_p
= 0;
20728 it
.glyph_row
->truncated_on_right_p
= 0;
20730 /* Make a 3D mode-line have a shadow at its right end. */
20731 face
= FACE_FROM_ID (it
.f
, face_id
);
20732 extend_face_to_end_of_line (&it
);
20733 if (face
->box
!= FACE_NO_BOX
)
20735 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20736 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20737 last
->right_box_line_p
= 1;
20740 return it
.glyph_row
->height
;
20743 /* Move element ELT in LIST to the front of LIST.
20744 Return the updated list. */
20747 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20749 register Lisp_Object tail
, prev
;
20750 register Lisp_Object tem
;
20754 while (CONSP (tail
))
20760 /* Splice out the link TAIL. */
20762 list
= XCDR (tail
);
20764 Fsetcdr (prev
, XCDR (tail
));
20766 /* Now make it the first. */
20767 Fsetcdr (tail
, list
);
20772 tail
= XCDR (tail
);
20776 /* Not found--return unchanged LIST. */
20780 /* Contribute ELT to the mode line for window IT->w. How it
20781 translates into text depends on its data type.
20783 IT describes the display environment in which we display, as usual.
20785 DEPTH is the depth in recursion. It is used to prevent
20786 infinite recursion here.
20788 FIELD_WIDTH is the number of characters the display of ELT should
20789 occupy in the mode line, and PRECISION is the maximum number of
20790 characters to display from ELT's representation. See
20791 display_string for details.
20793 Returns the hpos of the end of the text generated by ELT.
20795 PROPS is a property list to add to any string we encounter.
20797 If RISKY is nonzero, remove (disregard) any properties in any string
20798 we encounter, and ignore :eval and :propertize.
20800 The global variable `mode_line_target' determines whether the
20801 output is passed to `store_mode_line_noprop',
20802 `store_mode_line_string', or `display_string'. */
20805 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20806 Lisp_Object elt
, Lisp_Object props
, int risky
)
20808 int n
= 0, field
, prec
;
20813 elt
= build_string ("*too-deep*");
20817 switch (XTYPE (elt
))
20821 /* A string: output it and check for %-constructs within it. */
20823 ptrdiff_t offset
= 0;
20825 if (SCHARS (elt
) > 0
20826 && (!NILP (props
) || risky
))
20828 Lisp_Object oprops
, aelt
;
20829 oprops
= Ftext_properties_at (make_number (0), elt
);
20831 /* If the starting string's properties are not what
20832 we want, translate the string. Also, if the string
20833 is risky, do that anyway. */
20835 if (NILP (Fequal (props
, oprops
)) || risky
)
20837 /* If the starting string has properties,
20838 merge the specified ones onto the existing ones. */
20839 if (! NILP (oprops
) && !risky
)
20843 oprops
= Fcopy_sequence (oprops
);
20845 while (CONSP (tem
))
20847 oprops
= Fplist_put (oprops
, XCAR (tem
),
20848 XCAR (XCDR (tem
)));
20849 tem
= XCDR (XCDR (tem
));
20854 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20855 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20857 /* AELT is what we want. Move it to the front
20858 without consing. */
20860 mode_line_proptrans_alist
20861 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20867 /* If AELT has the wrong props, it is useless.
20868 so get rid of it. */
20870 mode_line_proptrans_alist
20871 = Fdelq (aelt
, mode_line_proptrans_alist
);
20873 elt
= Fcopy_sequence (elt
);
20874 Fset_text_properties (make_number (0), Flength (elt
),
20876 /* Add this item to mode_line_proptrans_alist. */
20877 mode_line_proptrans_alist
20878 = Fcons (Fcons (elt
, props
),
20879 mode_line_proptrans_alist
);
20880 /* Truncate mode_line_proptrans_alist
20881 to at most 50 elements. */
20882 tem
= Fnthcdr (make_number (50),
20883 mode_line_proptrans_alist
);
20885 XSETCDR (tem
, Qnil
);
20894 prec
= precision
- n
;
20895 switch (mode_line_target
)
20897 case MODE_LINE_NOPROP
:
20898 case MODE_LINE_TITLE
:
20899 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20901 case MODE_LINE_STRING
:
20902 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20904 case MODE_LINE_DISPLAY
:
20905 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20906 0, prec
, 0, STRING_MULTIBYTE (elt
));
20913 /* Handle the non-literal case. */
20915 while ((precision
<= 0 || n
< precision
)
20916 && SREF (elt
, offset
) != 0
20917 && (mode_line_target
!= MODE_LINE_DISPLAY
20918 || it
->current_x
< it
->last_visible_x
))
20920 ptrdiff_t last_offset
= offset
;
20922 /* Advance to end of string or next format specifier. */
20923 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20926 if (offset
- 1 != last_offset
)
20928 ptrdiff_t nchars
, nbytes
;
20930 /* Output to end of string or up to '%'. Field width
20931 is length of string. Don't output more than
20932 PRECISION allows us. */
20935 prec
= c_string_width (SDATA (elt
) + last_offset
,
20936 offset
- last_offset
, precision
- n
,
20939 switch (mode_line_target
)
20941 case MODE_LINE_NOPROP
:
20942 case MODE_LINE_TITLE
:
20943 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
20945 case MODE_LINE_STRING
:
20947 ptrdiff_t bytepos
= last_offset
;
20948 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20949 ptrdiff_t endpos
= (precision
<= 0
20950 ? string_byte_to_char (elt
, offset
)
20951 : charpos
+ nchars
);
20953 n
+= store_mode_line_string (NULL
,
20954 Fsubstring (elt
, make_number (charpos
),
20955 make_number (endpos
)),
20959 case MODE_LINE_DISPLAY
:
20961 ptrdiff_t bytepos
= last_offset
;
20962 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
20964 if (precision
<= 0)
20965 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
20966 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
20968 STRING_MULTIBYTE (elt
));
20973 else /* c == '%' */
20975 ptrdiff_t percent_position
= offset
;
20977 /* Get the specified minimum width. Zero means
20980 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
20981 field
= field
* 10 + c
- '0';
20983 /* Don't pad beyond the total padding allowed. */
20984 if (field_width
- n
> 0 && field
> field_width
- n
)
20985 field
= field_width
- n
;
20987 /* Note that either PRECISION <= 0 or N < PRECISION. */
20988 prec
= precision
- n
;
20991 n
+= display_mode_element (it
, depth
, field
, prec
,
20992 Vglobal_mode_string
, props
,
20997 ptrdiff_t bytepos
, charpos
;
20999 Lisp_Object string
;
21001 bytepos
= percent_position
;
21002 charpos
= (STRING_MULTIBYTE (elt
)
21003 ? string_byte_to_char (elt
, bytepos
)
21005 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21006 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21008 switch (mode_line_target
)
21010 case MODE_LINE_NOPROP
:
21011 case MODE_LINE_TITLE
:
21012 n
+= store_mode_line_noprop (spec
, field
, prec
);
21014 case MODE_LINE_STRING
:
21016 Lisp_Object tem
= build_string (spec
);
21017 props
= Ftext_properties_at (make_number (charpos
), elt
);
21018 /* Should only keep face property in props */
21019 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21022 case MODE_LINE_DISPLAY
:
21024 int nglyphs_before
, nwritten
;
21026 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21027 nwritten
= display_string (spec
, string
, elt
,
21032 /* Assign to the glyphs written above the
21033 string where the `%x' came from, position
21037 struct glyph
*glyph
21038 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21042 for (i
= 0; i
< nwritten
; ++i
)
21044 glyph
[i
].object
= elt
;
21045 glyph
[i
].charpos
= charpos
;
21062 /* A symbol: process the value of the symbol recursively
21063 as if it appeared here directly. Avoid error if symbol void.
21064 Special case: if value of symbol is a string, output the string
21067 register Lisp_Object tem
;
21069 /* If the variable is not marked as risky to set
21070 then its contents are risky to use. */
21071 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21074 tem
= Fboundp (elt
);
21077 tem
= Fsymbol_value (elt
);
21078 /* If value is a string, output that string literally:
21079 don't check for % within it. */
21083 if (!EQ (tem
, elt
))
21085 /* Give up right away for nil or t. */
21095 register Lisp_Object car
, tem
;
21097 /* A cons cell: five distinct cases.
21098 If first element is :eval or :propertize, do something special.
21099 If first element is a string or a cons, process all the elements
21100 and effectively concatenate them.
21101 If first element is a negative number, truncate displaying cdr to
21102 at most that many characters. If positive, pad (with spaces)
21103 to at least that many characters.
21104 If first element is a symbol, process the cadr or caddr recursively
21105 according to whether the symbol's value is non-nil or nil. */
21107 if (EQ (car
, QCeval
))
21109 /* An element of the form (:eval FORM) means evaluate FORM
21110 and use the result as mode line elements. */
21115 if (CONSP (XCDR (elt
)))
21118 spec
= safe_eval (XCAR (XCDR (elt
)));
21119 n
+= display_mode_element (it
, depth
, field_width
- n
,
21120 precision
- n
, spec
, props
,
21124 else if (EQ (car
, QCpropertize
))
21126 /* An element of the form (:propertize ELT PROPS...)
21127 means display ELT but applying properties PROPS. */
21132 if (CONSP (XCDR (elt
)))
21133 n
+= display_mode_element (it
, depth
, field_width
- n
,
21134 precision
- n
, XCAR (XCDR (elt
)),
21135 XCDR (XCDR (elt
)), risky
);
21137 else if (SYMBOLP (car
))
21139 tem
= Fboundp (car
);
21143 /* elt is now the cdr, and we know it is a cons cell.
21144 Use its car if CAR has a non-nil value. */
21147 tem
= Fsymbol_value (car
);
21154 /* Symbol's value is nil (or symbol is unbound)
21155 Get the cddr of the original list
21156 and if possible find the caddr and use that. */
21160 else if (!CONSP (elt
))
21165 else if (INTEGERP (car
))
21167 register int lim
= XINT (car
);
21171 /* Negative int means reduce maximum width. */
21172 if (precision
<= 0)
21175 precision
= min (precision
, -lim
);
21179 /* Padding specified. Don't let it be more than
21180 current maximum. */
21182 lim
= min (precision
, lim
);
21184 /* If that's more padding than already wanted, queue it.
21185 But don't reduce padding already specified even if
21186 that is beyond the current truncation point. */
21187 field_width
= max (lim
, field_width
);
21191 else if (STRINGP (car
) || CONSP (car
))
21193 Lisp_Object halftail
= elt
;
21197 && (precision
<= 0 || n
< precision
))
21199 n
+= display_mode_element (it
, depth
,
21200 /* Do padding only after the last
21201 element in the list. */
21202 (! CONSP (XCDR (elt
))
21205 precision
- n
, XCAR (elt
),
21209 if ((len
& 1) == 0)
21210 halftail
= XCDR (halftail
);
21211 /* Check for cycle. */
21212 if (EQ (halftail
, elt
))
21221 elt
= build_string ("*invalid*");
21225 /* Pad to FIELD_WIDTH. */
21226 if (field_width
> 0 && n
< field_width
)
21228 switch (mode_line_target
)
21230 case MODE_LINE_NOPROP
:
21231 case MODE_LINE_TITLE
:
21232 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21234 case MODE_LINE_STRING
:
21235 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21237 case MODE_LINE_DISPLAY
:
21238 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21247 /* Store a mode-line string element in mode_line_string_list.
21249 If STRING is non-null, display that C string. Otherwise, the Lisp
21250 string LISP_STRING is displayed.
21252 FIELD_WIDTH is the minimum number of output glyphs to produce.
21253 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21254 with spaces. FIELD_WIDTH <= 0 means don't pad.
21256 PRECISION is the maximum number of characters to output from
21257 STRING. PRECISION <= 0 means don't truncate the string.
21259 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21260 properties to the string.
21262 PROPS are the properties to add to the string.
21263 The mode_line_string_face face property is always added to the string.
21267 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21268 int field_width
, int precision
, Lisp_Object props
)
21273 if (string
!= NULL
)
21275 len
= strlen (string
);
21276 if (precision
> 0 && len
> precision
)
21278 lisp_string
= make_string (string
, len
);
21280 props
= mode_line_string_face_prop
;
21281 else if (!NILP (mode_line_string_face
))
21283 Lisp_Object face
= Fplist_get (props
, Qface
);
21284 props
= Fcopy_sequence (props
);
21286 face
= mode_line_string_face
;
21288 face
= list2 (face
, mode_line_string_face
);
21289 props
= Fplist_put (props
, Qface
, face
);
21291 Fadd_text_properties (make_number (0), make_number (len
),
21292 props
, lisp_string
);
21296 len
= XFASTINT (Flength (lisp_string
));
21297 if (precision
> 0 && len
> precision
)
21300 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21303 if (!NILP (mode_line_string_face
))
21307 props
= Ftext_properties_at (make_number (0), lisp_string
);
21308 face
= Fplist_get (props
, Qface
);
21310 face
= mode_line_string_face
;
21312 face
= list2 (face
, mode_line_string_face
);
21313 props
= list2 (Qface
, face
);
21315 lisp_string
= Fcopy_sequence (lisp_string
);
21318 Fadd_text_properties (make_number (0), make_number (len
),
21319 props
, lisp_string
);
21324 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21328 if (field_width
> len
)
21330 field_width
-= len
;
21331 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21333 Fadd_text_properties (make_number (0), make_number (field_width
),
21334 props
, lisp_string
);
21335 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21343 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21345 doc
: /* Format a string out of a mode line format specification.
21346 First arg FORMAT specifies the mode line format (see `mode-line-format'
21347 for details) to use.
21349 By default, the format is evaluated for the currently selected window.
21351 Optional second arg FACE specifies the face property to put on all
21352 characters for which no face is specified. The value nil means the
21353 default face. The value t means whatever face the window's mode line
21354 currently uses (either `mode-line' or `mode-line-inactive',
21355 depending on whether the window is the selected window or not).
21356 An integer value means the value string has no text
21359 Optional third and fourth args WINDOW and BUFFER specify the window
21360 and buffer to use as the context for the formatting (defaults
21361 are the selected window and the WINDOW's buffer). */)
21362 (Lisp_Object format
, Lisp_Object face
,
21363 Lisp_Object window
, Lisp_Object buffer
)
21368 struct buffer
*old_buffer
= NULL
;
21370 int no_props
= INTEGERP (face
);
21371 ptrdiff_t count
= SPECPDL_INDEX ();
21373 int string_start
= 0;
21375 w
= decode_any_window (window
);
21376 XSETWINDOW (window
, w
);
21379 buffer
= w
->contents
;
21380 CHECK_BUFFER (buffer
);
21382 /* Make formatting the modeline a non-op when noninteractive, otherwise
21383 there will be problems later caused by a partially initialized frame. */
21384 if (NILP (format
) || noninteractive
)
21385 return empty_unibyte_string
;
21390 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21391 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21392 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21393 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21394 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21395 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21396 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21399 old_buffer
= current_buffer
;
21401 /* Save things including mode_line_proptrans_alist,
21402 and set that to nil so that we don't alter the outer value. */
21403 record_unwind_protect (unwind_format_mode_line
,
21404 format_mode_line_unwind_data
21405 (XFRAME (WINDOW_FRAME (w
)),
21406 old_buffer
, selected_window
, 1));
21407 mode_line_proptrans_alist
= Qnil
;
21409 Fselect_window (window
, Qt
);
21410 set_buffer_internal_1 (XBUFFER (buffer
));
21412 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21416 mode_line_target
= MODE_LINE_NOPROP
;
21417 mode_line_string_face_prop
= Qnil
;
21418 mode_line_string_list
= Qnil
;
21419 string_start
= MODE_LINE_NOPROP_LEN (0);
21423 mode_line_target
= MODE_LINE_STRING
;
21424 mode_line_string_list
= Qnil
;
21425 mode_line_string_face
= face
;
21426 mode_line_string_face_prop
21427 = NILP (face
) ? Qnil
: list2 (Qface
, face
);
21430 push_kboard (FRAME_KBOARD (it
.f
));
21431 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21436 len
= MODE_LINE_NOPROP_LEN (string_start
);
21437 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21441 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21442 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21443 empty_unibyte_string
);
21446 unbind_to (count
, Qnil
);
21450 /* Write a null-terminated, right justified decimal representation of
21451 the positive integer D to BUF using a minimal field width WIDTH. */
21454 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21456 register char *p
= buf
;
21464 *p
++ = d
% 10 + '0';
21469 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21480 /* Write a null-terminated, right justified decimal and "human
21481 readable" representation of the nonnegative integer D to BUF using
21482 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21484 static const char power_letter
[] =
21498 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21500 /* We aim to represent the nonnegative integer D as
21501 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21502 ptrdiff_t quotient
= d
;
21504 /* -1 means: do not use TENTHS. */
21508 /* Length of QUOTIENT.TENTHS as a string. */
21514 if (quotient
>= 1000)
21516 /* Scale to the appropriate EXPONENT. */
21519 remainder
= quotient
% 1000;
21523 while (quotient
>= 1000);
21525 /* Round to nearest and decide whether to use TENTHS or not. */
21528 tenths
= remainder
/ 100;
21529 if (remainder
% 100 >= 50)
21536 if (quotient
== 10)
21544 if (remainder
>= 500)
21546 if (quotient
< 999)
21557 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21558 if (tenths
== -1 && quotient
<= 99)
21565 p
= psuffix
= buf
+ max (width
, length
);
21567 /* Print EXPONENT. */
21568 *psuffix
++ = power_letter
[exponent
];
21571 /* Print TENTHS. */
21574 *--p
= '0' + tenths
;
21578 /* Print QUOTIENT. */
21581 int digit
= quotient
% 10;
21582 *--p
= '0' + digit
;
21584 while ((quotient
/= 10) != 0);
21586 /* Print leading spaces. */
21591 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21592 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21593 type of CODING_SYSTEM. Return updated pointer into BUF. */
21595 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21598 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21601 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21602 const unsigned char *eol_str
;
21604 /* The EOL conversion we are using. */
21605 Lisp_Object eoltype
;
21607 val
= CODING_SYSTEM_SPEC (coding_system
);
21610 if (!VECTORP (val
)) /* Not yet decided. */
21612 *buf
++ = multibyte
? '-' : ' ';
21614 eoltype
= eol_mnemonic_undecided
;
21615 /* Don't mention EOL conversion if it isn't decided. */
21620 Lisp_Object eolvalue
;
21622 attrs
= AREF (val
, 0);
21623 eolvalue
= AREF (val
, 2);
21626 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21631 /* The EOL conversion that is normal on this system. */
21633 if (NILP (eolvalue
)) /* Not yet decided. */
21634 eoltype
= eol_mnemonic_undecided
;
21635 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21636 eoltype
= eol_mnemonic_undecided
;
21637 else /* eolvalue is Qunix, Qdos, or Qmac. */
21638 eoltype
= (EQ (eolvalue
, Qunix
)
21639 ? eol_mnemonic_unix
21640 : (EQ (eolvalue
, Qdos
) == 1
21641 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21647 /* Mention the EOL conversion if it is not the usual one. */
21648 if (STRINGP (eoltype
))
21650 eol_str
= SDATA (eoltype
);
21651 eol_str_len
= SBYTES (eoltype
);
21653 else if (CHARACTERP (eoltype
))
21655 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21656 int c
= XFASTINT (eoltype
);
21657 eol_str_len
= CHAR_STRING (c
, tmp
);
21662 eol_str
= invalid_eol_type
;
21663 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21665 memcpy (buf
, eol_str
, eol_str_len
);
21666 buf
+= eol_str_len
;
21672 /* Return a string for the output of a mode line %-spec for window W,
21673 generated by character C. FIELD_WIDTH > 0 means pad the string
21674 returned with spaces to that value. Return a Lisp string in
21675 *STRING if the resulting string is taken from that Lisp string.
21677 Note we operate on the current buffer for most purposes. */
21679 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21681 static const char *
21682 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21683 Lisp_Object
*string
)
21686 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21687 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21688 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21689 produce strings from numerical values, so limit preposterously
21690 large values of FIELD_WIDTH to avoid overrunning the buffer's
21691 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21692 bytes plus the terminating null. */
21693 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21694 struct buffer
*b
= current_buffer
;
21702 if (!NILP (BVAR (b
, read_only
)))
21704 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21709 /* This differs from %* only for a modified read-only buffer. */
21710 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21712 if (!NILP (BVAR (b
, read_only
)))
21717 /* This differs from %* in ignoring read-only-ness. */
21718 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21730 if (command_loop_level
> 5)
21732 p
= decode_mode_spec_buf
;
21733 for (i
= 0; i
< command_loop_level
; i
++)
21736 return decode_mode_spec_buf
;
21744 if (command_loop_level
> 5)
21746 p
= decode_mode_spec_buf
;
21747 for (i
= 0; i
< command_loop_level
; i
++)
21750 return decode_mode_spec_buf
;
21757 /* Let lots_of_dashes be a string of infinite length. */
21758 if (mode_line_target
== MODE_LINE_NOPROP
21759 || mode_line_target
== MODE_LINE_STRING
)
21761 if (field_width
<= 0
21762 || field_width
> sizeof (lots_of_dashes
))
21764 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21765 decode_mode_spec_buf
[i
] = '-';
21766 decode_mode_spec_buf
[i
] = '\0';
21767 return decode_mode_spec_buf
;
21770 return lots_of_dashes
;
21774 obj
= BVAR (b
, name
);
21778 /* %c and %l are ignored in `frame-title-format'.
21779 (In redisplay_internal, the frame title is drawn _before_ the
21780 windows are updated, so the stuff which depends on actual
21781 window contents (such as %l) may fail to render properly, or
21782 even crash emacs.) */
21783 if (mode_line_target
== MODE_LINE_TITLE
)
21787 ptrdiff_t col
= current_column ();
21788 w
->column_number_displayed
= col
;
21789 pint2str (decode_mode_spec_buf
, width
, col
);
21790 return decode_mode_spec_buf
;
21794 #ifndef SYSTEM_MALLOC
21796 if (NILP (Vmemory_full
))
21799 return "!MEM FULL! ";
21806 /* %F displays the frame name. */
21807 if (!NILP (f
->title
))
21808 return SSDATA (f
->title
);
21809 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21810 return SSDATA (f
->name
);
21814 obj
= BVAR (b
, filename
);
21819 ptrdiff_t size
= ZV
- BEGV
;
21820 pint2str (decode_mode_spec_buf
, width
, size
);
21821 return decode_mode_spec_buf
;
21826 ptrdiff_t size
= ZV
- BEGV
;
21827 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21828 return decode_mode_spec_buf
;
21833 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21834 ptrdiff_t topline
, nlines
, height
;
21837 /* %c and %l are ignored in `frame-title-format'. */
21838 if (mode_line_target
== MODE_LINE_TITLE
)
21841 startpos
= marker_position (w
->start
);
21842 startpos_byte
= marker_byte_position (w
->start
);
21843 height
= WINDOW_TOTAL_LINES (w
);
21845 /* If we decided that this buffer isn't suitable for line numbers,
21846 don't forget that too fast. */
21847 if (w
->base_line_pos
== -1)
21850 /* If the buffer is very big, don't waste time. */
21851 if (INTEGERP (Vline_number_display_limit
)
21852 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21854 w
->base_line_pos
= 0;
21855 w
->base_line_number
= 0;
21859 if (w
->base_line_number
> 0
21860 && w
->base_line_pos
> 0
21861 && w
->base_line_pos
<= startpos
)
21863 line
= w
->base_line_number
;
21864 linepos
= w
->base_line_pos
;
21865 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21870 linepos
= BUF_BEGV (b
);
21871 linepos_byte
= BUF_BEGV_BYTE (b
);
21874 /* Count lines from base line to window start position. */
21875 nlines
= display_count_lines (linepos_byte
,
21879 topline
= nlines
+ line
;
21881 /* Determine a new base line, if the old one is too close
21882 or too far away, or if we did not have one.
21883 "Too close" means it's plausible a scroll-down would
21884 go back past it. */
21885 if (startpos
== BUF_BEGV (b
))
21887 w
->base_line_number
= topline
;
21888 w
->base_line_pos
= BUF_BEGV (b
);
21890 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21891 || linepos
== BUF_BEGV (b
))
21893 ptrdiff_t limit
= BUF_BEGV (b
);
21894 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21895 ptrdiff_t position
;
21896 ptrdiff_t distance
=
21897 (height
* 2 + 30) * line_number_display_limit_width
;
21899 if (startpos
- distance
> limit
)
21901 limit
= startpos
- distance
;
21902 limit_byte
= CHAR_TO_BYTE (limit
);
21905 nlines
= display_count_lines (startpos_byte
,
21907 - (height
* 2 + 30),
21909 /* If we couldn't find the lines we wanted within
21910 line_number_display_limit_width chars per line,
21911 give up on line numbers for this window. */
21912 if (position
== limit_byte
&& limit
== startpos
- distance
)
21914 w
->base_line_pos
= -1;
21915 w
->base_line_number
= 0;
21919 w
->base_line_number
= topline
- nlines
;
21920 w
->base_line_pos
= BYTE_TO_CHAR (position
);
21923 /* Now count lines from the start pos to point. */
21924 nlines
= display_count_lines (startpos_byte
,
21925 PT_BYTE
, PT
, &junk
);
21927 /* Record that we did display the line number. */
21928 line_number_displayed
= 1;
21930 /* Make the string to show. */
21931 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21932 return decode_mode_spec_buf
;
21935 char* p
= decode_mode_spec_buf
;
21936 int pad
= width
- 2;
21942 return decode_mode_spec_buf
;
21948 obj
= BVAR (b
, mode_name
);
21952 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
21958 ptrdiff_t pos
= marker_position (w
->start
);
21959 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21961 if (w
->window_end_pos
<= BUF_Z (b
) - BUF_ZV (b
))
21963 if (pos
<= BUF_BEGV (b
))
21968 else if (pos
<= BUF_BEGV (b
))
21972 if (total
> 1000000)
21973 /* Do it differently for a large value, to avoid overflow. */
21974 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
21976 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
21977 /* We can't normally display a 3-digit number,
21978 so get us a 2-digit number that is close. */
21981 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
21982 return decode_mode_spec_buf
;
21986 /* Display percentage of size above the bottom of the screen. */
21989 ptrdiff_t toppos
= marker_position (w
->start
);
21990 ptrdiff_t botpos
= BUF_Z (b
) - w
->window_end_pos
;
21991 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
21993 if (botpos
>= BUF_ZV (b
))
21995 if (toppos
<= BUF_BEGV (b
))
22002 if (total
> 1000000)
22003 /* Do it differently for a large value, to avoid overflow. */
22004 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22006 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22007 /* We can't normally display a 3-digit number,
22008 so get us a 2-digit number that is close. */
22011 if (toppos
<= BUF_BEGV (b
))
22012 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22014 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22015 return decode_mode_spec_buf
;
22020 /* status of process */
22021 obj
= Fget_buffer_process (Fcurrent_buffer ());
22023 return "no process";
22025 obj
= Fsymbol_name (Fprocess_status (obj
));
22031 ptrdiff_t count
= inhibit_garbage_collection ();
22032 Lisp_Object val
= call1 (intern ("file-remote-p"),
22033 BVAR (current_buffer
, directory
));
22034 unbind_to (count
, Qnil
);
22043 /* coding-system (not including end-of-line format) */
22045 /* coding-system (including end-of-line type) */
22047 int eol_flag
= (c
== 'Z');
22048 char *p
= decode_mode_spec_buf
;
22050 if (! FRAME_WINDOW_P (f
))
22052 /* No need to mention EOL here--the terminal never needs
22053 to do EOL conversion. */
22054 p
= decode_mode_spec_coding (CODING_ID_NAME
22055 (FRAME_KEYBOARD_CODING (f
)->id
),
22057 p
= decode_mode_spec_coding (CODING_ID_NAME
22058 (FRAME_TERMINAL_CODING (f
)->id
),
22061 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22064 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22065 #ifdef subprocesses
22066 obj
= Fget_buffer_process (Fcurrent_buffer ());
22067 if (PROCESSP (obj
))
22069 p
= decode_mode_spec_coding
22070 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22071 p
= decode_mode_spec_coding
22072 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22074 #endif /* subprocesses */
22077 return decode_mode_spec_buf
;
22084 return SSDATA (obj
);
22091 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22092 means count lines back from START_BYTE. But don't go beyond
22093 LIMIT_BYTE. Return the number of lines thus found (always
22096 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22097 either the position COUNT lines after/before START_BYTE, if we
22098 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22102 display_count_lines (ptrdiff_t start_byte
,
22103 ptrdiff_t limit_byte
, ptrdiff_t count
,
22104 ptrdiff_t *byte_pos_ptr
)
22106 register unsigned char *cursor
;
22107 unsigned char *base
;
22109 register ptrdiff_t ceiling
;
22110 register unsigned char *ceiling_addr
;
22111 ptrdiff_t orig_count
= count
;
22113 /* If we are not in selective display mode,
22114 check only for newlines. */
22115 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22116 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22120 while (start_byte
< limit_byte
)
22122 ceiling
= BUFFER_CEILING_OF (start_byte
);
22123 ceiling
= min (limit_byte
- 1, ceiling
);
22124 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22125 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22129 if (selective_display
)
22131 while (*cursor
!= '\n' && *cursor
!= 015
22132 && ++cursor
!= ceiling_addr
)
22134 if (cursor
== ceiling_addr
)
22139 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22148 start_byte
+= cursor
- base
;
22149 *byte_pos_ptr
= start_byte
;
22153 while (cursor
< ceiling_addr
);
22155 start_byte
+= ceiling_addr
- base
;
22160 while (start_byte
> limit_byte
)
22162 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22163 ceiling
= max (limit_byte
, ceiling
);
22164 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22165 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22168 if (selective_display
)
22170 while (--cursor
>= ceiling_addr
22171 && *cursor
!= '\n' && *cursor
!= 015)
22173 if (cursor
< ceiling_addr
)
22178 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22185 start_byte
+= cursor
- base
+ 1;
22186 *byte_pos_ptr
= start_byte
;
22187 /* When scanning backwards, we should
22188 not count the newline posterior to which we stop. */
22189 return - orig_count
- 1;
22192 start_byte
+= ceiling_addr
- base
;
22196 *byte_pos_ptr
= limit_byte
;
22199 return - orig_count
+ count
;
22200 return orig_count
- count
;
22206 /***********************************************************************
22208 ***********************************************************************/
22210 /* Display a NUL-terminated string, starting with index START.
22212 If STRING is non-null, display that C string. Otherwise, the Lisp
22213 string LISP_STRING is displayed. There's a case that STRING is
22214 non-null and LISP_STRING is not nil. It means STRING is a string
22215 data of LISP_STRING. In that case, we display LISP_STRING while
22216 ignoring its text properties.
22218 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22219 FACE_STRING. Display STRING or LISP_STRING with the face at
22220 FACE_STRING_POS in FACE_STRING:
22222 Display the string in the environment given by IT, but use the
22223 standard display table, temporarily.
22225 FIELD_WIDTH is the minimum number of output glyphs to produce.
22226 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22227 with spaces. If STRING has more characters, more than FIELD_WIDTH
22228 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22230 PRECISION is the maximum number of characters to output from
22231 STRING. PRECISION < 0 means don't truncate the string.
22233 This is roughly equivalent to printf format specifiers:
22235 FIELD_WIDTH PRECISION PRINTF
22236 ----------------------------------------
22242 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22243 display them, and < 0 means obey the current buffer's value of
22244 enable_multibyte_characters.
22246 Value is the number of columns displayed. */
22249 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22250 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22251 int field_width
, int precision
, int max_x
, int multibyte
)
22253 int hpos_at_start
= it
->hpos
;
22254 int saved_face_id
= it
->face_id
;
22255 struct glyph_row
*row
= it
->glyph_row
;
22256 ptrdiff_t it_charpos
;
22258 /* Initialize the iterator IT for iteration over STRING beginning
22259 with index START. */
22260 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22261 precision
, field_width
, multibyte
);
22262 if (string
&& STRINGP (lisp_string
))
22263 /* LISP_STRING is the one returned by decode_mode_spec. We should
22264 ignore its text properties. */
22265 it
->stop_charpos
= it
->end_charpos
;
22267 /* If displaying STRING, set up the face of the iterator from
22268 FACE_STRING, if that's given. */
22269 if (STRINGP (face_string
))
22275 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22276 0, it
->region_beg_charpos
,
22277 it
->region_end_charpos
,
22278 &endptr
, it
->base_face_id
, 0);
22279 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22280 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22283 /* Set max_x to the maximum allowed X position. Don't let it go
22284 beyond the right edge of the window. */
22286 max_x
= it
->last_visible_x
;
22288 max_x
= min (max_x
, it
->last_visible_x
);
22290 /* Skip over display elements that are not visible. because IT->w is
22292 if (it
->current_x
< it
->first_visible_x
)
22293 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22294 MOVE_TO_POS
| MOVE_TO_X
);
22296 row
->ascent
= it
->max_ascent
;
22297 row
->height
= it
->max_ascent
+ it
->max_descent
;
22298 row
->phys_ascent
= it
->max_phys_ascent
;
22299 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22300 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22302 if (STRINGP (it
->string
))
22303 it_charpos
= IT_STRING_CHARPOS (*it
);
22305 it_charpos
= IT_CHARPOS (*it
);
22307 /* This condition is for the case that we are called with current_x
22308 past last_visible_x. */
22309 while (it
->current_x
< max_x
)
22311 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22313 /* Get the next display element. */
22314 if (!get_next_display_element (it
))
22317 /* Produce glyphs. */
22318 x_before
= it
->current_x
;
22319 n_glyphs_before
= row
->used
[TEXT_AREA
];
22320 PRODUCE_GLYPHS (it
);
22322 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22325 while (i
< nglyphs
)
22327 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22329 if (it
->line_wrap
!= TRUNCATE
22330 && x
+ glyph
->pixel_width
> max_x
)
22332 /* End of continued line or max_x reached. */
22333 if (CHAR_GLYPH_PADDING_P (*glyph
))
22335 /* A wide character is unbreakable. */
22336 if (row
->reversed_p
)
22337 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22338 - n_glyphs_before
);
22339 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22340 it
->current_x
= x_before
;
22344 if (row
->reversed_p
)
22345 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22346 - (n_glyphs_before
+ i
));
22347 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22352 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22354 /* Glyph is at least partially visible. */
22356 if (x
< it
->first_visible_x
)
22357 row
->x
= x
- it
->first_visible_x
;
22361 /* Glyph is off the left margin of the display area.
22362 Should not happen. */
22366 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22367 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22368 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22369 row
->phys_height
= max (row
->phys_height
,
22370 it
->max_phys_ascent
+ it
->max_phys_descent
);
22371 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22372 it
->max_extra_line_spacing
);
22373 x
+= glyph
->pixel_width
;
22377 /* Stop if max_x reached. */
22381 /* Stop at line ends. */
22382 if (ITERATOR_AT_END_OF_LINE_P (it
))
22384 it
->continuation_lines_width
= 0;
22388 set_iterator_to_next (it
, 1);
22389 if (STRINGP (it
->string
))
22390 it_charpos
= IT_STRING_CHARPOS (*it
);
22392 it_charpos
= IT_CHARPOS (*it
);
22394 /* Stop if truncating at the right edge. */
22395 if (it
->line_wrap
== TRUNCATE
22396 && it
->current_x
>= it
->last_visible_x
)
22398 /* Add truncation mark, but don't do it if the line is
22399 truncated at a padding space. */
22400 if (it_charpos
< it
->string_nchars
)
22402 if (!FRAME_WINDOW_P (it
->f
))
22406 if (it
->current_x
> it
->last_visible_x
)
22408 if (!row
->reversed_p
)
22410 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22411 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22416 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22417 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22419 unproduce_glyphs (it
, ii
+ 1);
22420 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22422 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22424 row
->used
[TEXT_AREA
] = ii
;
22425 produce_special_glyphs (it
, IT_TRUNCATION
);
22428 produce_special_glyphs (it
, IT_TRUNCATION
);
22430 row
->truncated_on_right_p
= 1;
22436 /* Maybe insert a truncation at the left. */
22437 if (it
->first_visible_x
22440 if (!FRAME_WINDOW_P (it
->f
)
22441 || (row
->reversed_p
22442 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22443 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22444 insert_left_trunc_glyphs (it
);
22445 row
->truncated_on_left_p
= 1;
22448 it
->face_id
= saved_face_id
;
22450 /* Value is number of columns displayed. */
22451 return it
->hpos
- hpos_at_start
;
22456 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22457 appears as an element of LIST or as the car of an element of LIST.
22458 If PROPVAL is a list, compare each element against LIST in that
22459 way, and return 1/2 if any element of PROPVAL is found in LIST.
22460 Otherwise return 0. This function cannot quit.
22461 The return value is 2 if the text is invisible but with an ellipsis
22462 and 1 if it's invisible and without an ellipsis. */
22465 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22467 register Lisp_Object tail
, proptail
;
22469 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22471 register Lisp_Object tem
;
22473 if (EQ (propval
, tem
))
22475 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22476 return NILP (XCDR (tem
)) ? 1 : 2;
22479 if (CONSP (propval
))
22481 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22483 Lisp_Object propelt
;
22484 propelt
= XCAR (proptail
);
22485 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22487 register Lisp_Object tem
;
22489 if (EQ (propelt
, tem
))
22491 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22492 return NILP (XCDR (tem
)) ? 1 : 2;
22500 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22501 doc
: /* Non-nil if the property makes the text invisible.
22502 POS-OR-PROP can be a marker or number, in which case it is taken to be
22503 a position in the current buffer and the value of the `invisible' property
22504 is checked; or it can be some other value, which is then presumed to be the
22505 value of the `invisible' property of the text of interest.
22506 The non-nil value returned can be t for truly invisible text or something
22507 else if the text is replaced by an ellipsis. */)
22508 (Lisp_Object pos_or_prop
)
22511 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22512 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22514 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22515 return (invis
== 0 ? Qnil
22517 : make_number (invis
));
22520 /* Calculate a width or height in pixels from a specification using
22521 the following elements:
22524 NUM - a (fractional) multiple of the default font width/height
22525 (NUM) - specifies exactly NUM pixels
22526 UNIT - a fixed number of pixels, see below.
22527 ELEMENT - size of a display element in pixels, see below.
22528 (NUM . SPEC) - equals NUM * SPEC
22529 (+ SPEC SPEC ...) - add pixel values
22530 (- SPEC SPEC ...) - subtract pixel values
22531 (- SPEC) - negate pixel value
22534 INT or FLOAT - a number constant
22535 SYMBOL - use symbol's (buffer local) variable binding.
22538 in - pixels per inch *)
22539 mm - pixels per 1/1000 meter *)
22540 cm - pixels per 1/100 meter *)
22541 width - width of current font in pixels.
22542 height - height of current font in pixels.
22544 *) using the ratio(s) defined in display-pixels-per-inch.
22548 left-fringe - left fringe width in pixels
22549 right-fringe - right fringe width in pixels
22551 left-margin - left margin width in pixels
22552 right-margin - right margin width in pixels
22554 scroll-bar - scroll-bar area width in pixels
22558 Pixels corresponding to 5 inches:
22561 Total width of non-text areas on left side of window (if scroll-bar is on left):
22562 '(space :width (+ left-fringe left-margin scroll-bar))
22564 Align to first text column (in header line):
22565 '(space :align-to 0)
22567 Align to middle of text area minus half the width of variable `my-image'
22568 containing a loaded image:
22569 '(space :align-to (0.5 . (- text my-image)))
22571 Width of left margin minus width of 1 character in the default font:
22572 '(space :width (- left-margin 1))
22574 Width of left margin minus width of 2 characters in the current font:
22575 '(space :width (- left-margin (2 . width)))
22577 Center 1 character over left-margin (in header line):
22578 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22580 Different ways to express width of left fringe plus left margin minus one pixel:
22581 '(space :width (- (+ left-fringe left-margin) (1)))
22582 '(space :width (+ left-fringe left-margin (- (1))))
22583 '(space :width (+ left-fringe left-margin (-1)))
22588 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22589 struct font
*font
, int width_p
, int *align_to
)
22593 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22594 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22597 return OK_PIXELS (0);
22599 eassert (FRAME_LIVE_P (it
->f
));
22601 if (SYMBOLP (prop
))
22603 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22605 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22607 if (unit
[0] == 'i' && unit
[1] == 'n')
22609 else if (unit
[0] == 'm' && unit
[1] == 'm')
22611 else if (unit
[0] == 'c' && unit
[1] == 'm')
22617 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22618 : FRAME_RES_Y (it
->f
));
22621 return OK_PIXELS (ppi
/ pixels
);
22626 #ifdef HAVE_WINDOW_SYSTEM
22627 if (EQ (prop
, Qheight
))
22628 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22629 if (EQ (prop
, Qwidth
))
22630 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22632 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22633 return OK_PIXELS (1);
22636 if (EQ (prop
, Qtext
))
22637 return OK_PIXELS (width_p
22638 ? window_box_width (it
->w
, TEXT_AREA
)
22639 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22641 if (align_to
&& *align_to
< 0)
22644 if (EQ (prop
, Qleft
))
22645 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22646 if (EQ (prop
, Qright
))
22647 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22648 if (EQ (prop
, Qcenter
))
22649 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22650 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22651 if (EQ (prop
, Qleft_fringe
))
22652 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22653 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22654 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22655 if (EQ (prop
, Qright_fringe
))
22656 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22657 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22658 : window_box_right_offset (it
->w
, TEXT_AREA
));
22659 if (EQ (prop
, Qleft_margin
))
22660 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22661 if (EQ (prop
, Qright_margin
))
22662 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22663 if (EQ (prop
, Qscroll_bar
))
22664 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22666 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22667 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22668 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22673 if (EQ (prop
, Qleft_fringe
))
22674 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22675 if (EQ (prop
, Qright_fringe
))
22676 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22677 if (EQ (prop
, Qleft_margin
))
22678 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22679 if (EQ (prop
, Qright_margin
))
22680 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22681 if (EQ (prop
, Qscroll_bar
))
22682 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22685 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22686 if (EQ (prop
, Qunbound
))
22690 if (INTEGERP (prop
) || FLOATP (prop
))
22692 int base_unit
= (width_p
22693 ? FRAME_COLUMN_WIDTH (it
->f
)
22694 : FRAME_LINE_HEIGHT (it
->f
));
22695 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22700 Lisp_Object car
= XCAR (prop
);
22701 Lisp_Object cdr
= XCDR (prop
);
22705 #ifdef HAVE_WINDOW_SYSTEM
22706 if (FRAME_WINDOW_P (it
->f
)
22707 && valid_image_p (prop
))
22709 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22710 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22712 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22715 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22721 while (CONSP (cdr
))
22723 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22724 font
, width_p
, align_to
))
22727 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22732 if (EQ (car
, Qminus
))
22734 return OK_PIXELS (pixels
);
22737 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22738 if (EQ (car
, Qunbound
))
22742 if (INTEGERP (car
) || FLOATP (car
))
22745 pixels
= XFLOATINT (car
);
22747 return OK_PIXELS (pixels
);
22748 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22749 font
, width_p
, align_to
))
22750 return OK_PIXELS (pixels
* fact
);
22761 /***********************************************************************
22763 ***********************************************************************/
22765 #ifdef HAVE_WINDOW_SYSTEM
22770 dump_glyph_string (struct glyph_string
*s
)
22772 fprintf (stderr
, "glyph string\n");
22773 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22774 s
->x
, s
->y
, s
->width
, s
->height
);
22775 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22776 fprintf (stderr
, " hl = %d\n", s
->hl
);
22777 fprintf (stderr
, " left overhang = %d, right = %d\n",
22778 s
->left_overhang
, s
->right_overhang
);
22779 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22780 fprintf (stderr
, " extends to end of line = %d\n",
22781 s
->extends_to_end_of_line_p
);
22782 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22783 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22786 #endif /* GLYPH_DEBUG */
22788 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22789 of XChar2b structures for S; it can't be allocated in
22790 init_glyph_string because it must be allocated via `alloca'. W
22791 is the window on which S is drawn. ROW and AREA are the glyph row
22792 and area within the row from which S is constructed. START is the
22793 index of the first glyph structure covered by S. HL is a
22794 face-override for drawing S. */
22797 #define OPTIONAL_HDC(hdc) HDC hdc,
22798 #define DECLARE_HDC(hdc) HDC hdc;
22799 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22800 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22803 #ifndef OPTIONAL_HDC
22804 #define OPTIONAL_HDC(hdc)
22805 #define DECLARE_HDC(hdc)
22806 #define ALLOCATE_HDC(hdc, f)
22807 #define RELEASE_HDC(hdc, f)
22811 init_glyph_string (struct glyph_string
*s
,
22813 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22814 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22816 memset (s
, 0, sizeof *s
);
22818 s
->f
= XFRAME (w
->frame
);
22822 s
->display
= FRAME_X_DISPLAY (s
->f
);
22823 s
->window
= FRAME_X_WINDOW (s
->f
);
22824 s
->char2b
= char2b
;
22828 s
->first_glyph
= row
->glyphs
[area
] + start
;
22829 s
->height
= row
->height
;
22830 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22831 s
->ybase
= s
->y
+ row
->ascent
;
22835 /* Append the list of glyph strings with head H and tail T to the list
22836 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22839 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22840 struct glyph_string
*h
, struct glyph_string
*t
)
22854 /* Prepend the list of glyph strings with head H and tail T to the
22855 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22859 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22860 struct glyph_string
*h
, struct glyph_string
*t
)
22874 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22875 Set *HEAD and *TAIL to the resulting list. */
22878 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22879 struct glyph_string
*s
)
22881 s
->next
= s
->prev
= NULL
;
22882 append_glyph_string_lists (head
, tail
, s
, s
);
22886 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22887 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22888 make sure that X resources for the face returned are allocated.
22889 Value is a pointer to a realized face that is ready for display if
22890 DISPLAY_P is non-zero. */
22892 static struct face
*
22893 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22894 XChar2b
*char2b
, int display_p
)
22896 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22901 code
= face
->font
->driver
->encode_char (face
->font
, c
);
22903 if (code
== FONT_INVALID_CODE
)
22906 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22908 /* Make sure X resources of the face are allocated. */
22909 #ifdef HAVE_X_WINDOWS
22913 eassert (face
!= NULL
);
22914 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22921 /* Get face and two-byte form of character glyph GLYPH on frame F.
22922 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22923 a pointer to a realized face that is ready for display. */
22925 static struct face
*
22926 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22927 XChar2b
*char2b
, int *two_byte_p
)
22932 eassert (glyph
->type
== CHAR_GLYPH
);
22933 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22935 /* Make sure X resources of the face are allocated. */
22936 eassert (face
!= NULL
);
22937 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22944 if (CHAR_BYTE8_P (glyph
->u
.ch
))
22945 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
22947 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
22949 if (code
== FONT_INVALID_CODE
)
22953 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22958 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
22959 Return 1 if FONT has a glyph for C, otherwise return 0. */
22962 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
22966 if (CHAR_BYTE8_P (c
))
22967 code
= CHAR_TO_BYTE8 (c
);
22969 code
= font
->driver
->encode_char (font
, c
);
22971 if (code
== FONT_INVALID_CODE
)
22973 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22978 /* Fill glyph string S with composition components specified by S->cmp.
22980 BASE_FACE is the base face of the composition.
22981 S->cmp_from is the index of the first component for S.
22983 OVERLAPS non-zero means S should draw the foreground only, and use
22984 its physical height for clipping. See also draw_glyphs.
22986 Value is the index of a component not in S. */
22989 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
22993 /* For all glyphs of this composition, starting at the offset
22994 S->cmp_from, until we reach the end of the definition or encounter a
22995 glyph that requires the different face, add it to S. */
23000 s
->for_overlaps
= overlaps
;
23003 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23005 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23007 /* TAB in a composition means display glyphs with padding space
23008 on the left or right. */
23011 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23014 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23021 s
->font
= s
->face
->font
;
23023 else if (s
->face
!= face
)
23031 if (s
->face
== NULL
)
23033 s
->face
= base_face
->ascii_face
;
23034 s
->font
= s
->face
->font
;
23037 /* All glyph strings for the same composition has the same width,
23038 i.e. the width set for the first component of the composition. */
23039 s
->width
= s
->first_glyph
->pixel_width
;
23041 /* If the specified font could not be loaded, use the frame's
23042 default font, but record the fact that we couldn't load it in
23043 the glyph string so that we can draw rectangles for the
23044 characters of the glyph string. */
23045 if (s
->font
== NULL
)
23047 s
->font_not_found_p
= 1;
23048 s
->font
= FRAME_FONT (s
->f
);
23051 /* Adjust base line for subscript/superscript text. */
23052 s
->ybase
+= s
->first_glyph
->voffset
;
23054 /* This glyph string must always be drawn with 16-bit functions. */
23061 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23062 int start
, int end
, int overlaps
)
23064 struct glyph
*glyph
, *last
;
23065 Lisp_Object lgstring
;
23068 s
->for_overlaps
= overlaps
;
23069 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23070 last
= s
->row
->glyphs
[s
->area
] + end
;
23071 s
->cmp_id
= glyph
->u
.cmp
.id
;
23072 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23073 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23074 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23075 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23076 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23078 while (glyph
< last
23079 && glyph
->u
.cmp
.automatic
23080 && glyph
->u
.cmp
.id
== s
->cmp_id
23081 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23082 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23084 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23086 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23087 unsigned code
= LGLYPH_CODE (lglyph
);
23089 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23091 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23092 return glyph
- s
->row
->glyphs
[s
->area
];
23096 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23097 See the comment of fill_glyph_string for arguments.
23098 Value is the index of the first glyph not in S. */
23102 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23103 int start
, int end
, int overlaps
)
23105 struct glyph
*glyph
, *last
;
23108 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23109 s
->for_overlaps
= overlaps
;
23110 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23111 last
= s
->row
->glyphs
[s
->area
] + end
;
23112 voffset
= glyph
->voffset
;
23113 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23114 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23116 s
->width
= glyph
->pixel_width
;
23118 while (glyph
< last
23119 && glyph
->type
== GLYPHLESS_GLYPH
23120 && glyph
->voffset
== voffset
23121 && glyph
->face_id
== face_id
)
23124 s
->width
+= glyph
->pixel_width
;
23127 s
->ybase
+= voffset
;
23128 return glyph
- s
->row
->glyphs
[s
->area
];
23132 /* Fill glyph string S from a sequence of character glyphs.
23134 FACE_ID is the face id of the string. START is the index of the
23135 first glyph to consider, END is the index of the last + 1.
23136 OVERLAPS non-zero means S should draw the foreground only, and use
23137 its physical height for clipping. See also draw_glyphs.
23139 Value is the index of the first glyph not in S. */
23142 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23143 int start
, int end
, int overlaps
)
23145 struct glyph
*glyph
, *last
;
23147 int glyph_not_available_p
;
23149 eassert (s
->f
== XFRAME (s
->w
->frame
));
23150 eassert (s
->nchars
== 0);
23151 eassert (start
>= 0 && end
> start
);
23153 s
->for_overlaps
= overlaps
;
23154 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23155 last
= s
->row
->glyphs
[s
->area
] + end
;
23156 voffset
= glyph
->voffset
;
23157 s
->padding_p
= glyph
->padding_p
;
23158 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23160 while (glyph
< last
23161 && glyph
->type
== CHAR_GLYPH
23162 && glyph
->voffset
== voffset
23163 /* Same face id implies same font, nowadays. */
23164 && glyph
->face_id
== face_id
23165 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23169 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23170 s
->char2b
+ s
->nchars
,
23172 s
->two_byte_p
= two_byte_p
;
23174 eassert (s
->nchars
<= end
- start
);
23175 s
->width
+= glyph
->pixel_width
;
23176 if (glyph
++->padding_p
!= s
->padding_p
)
23180 s
->font
= s
->face
->font
;
23182 /* If the specified font could not be loaded, use the frame's font,
23183 but record the fact that we couldn't load it in
23184 S->font_not_found_p so that we can draw rectangles for the
23185 characters of the glyph string. */
23186 if (s
->font
== NULL
|| glyph_not_available_p
)
23188 s
->font_not_found_p
= 1;
23189 s
->font
= FRAME_FONT (s
->f
);
23192 /* Adjust base line for subscript/superscript text. */
23193 s
->ybase
+= voffset
;
23195 eassert (s
->face
&& s
->face
->gc
);
23196 return glyph
- s
->row
->glyphs
[s
->area
];
23200 /* Fill glyph string S from image glyph S->first_glyph. */
23203 fill_image_glyph_string (struct glyph_string
*s
)
23205 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23206 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23208 s
->slice
= s
->first_glyph
->slice
.img
;
23209 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23210 s
->font
= s
->face
->font
;
23211 s
->width
= s
->first_glyph
->pixel_width
;
23213 /* Adjust base line for subscript/superscript text. */
23214 s
->ybase
+= s
->first_glyph
->voffset
;
23218 /* Fill glyph string S from a sequence of stretch glyphs.
23220 START is the index of the first glyph to consider,
23221 END is the index of the last + 1.
23223 Value is the index of the first glyph not in S. */
23226 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23228 struct glyph
*glyph
, *last
;
23229 int voffset
, face_id
;
23231 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23233 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23234 last
= s
->row
->glyphs
[s
->area
] + end
;
23235 face_id
= glyph
->face_id
;
23236 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23237 s
->font
= s
->face
->font
;
23238 s
->width
= glyph
->pixel_width
;
23240 voffset
= glyph
->voffset
;
23244 && glyph
->type
== STRETCH_GLYPH
23245 && glyph
->voffset
== voffset
23246 && glyph
->face_id
== face_id
);
23248 s
->width
+= glyph
->pixel_width
;
23250 /* Adjust base line for subscript/superscript text. */
23251 s
->ybase
+= voffset
;
23253 /* The case that face->gc == 0 is handled when drawing the glyph
23254 string by calling PREPARE_FACE_FOR_DISPLAY. */
23256 return glyph
- s
->row
->glyphs
[s
->area
];
23259 static struct font_metrics
*
23260 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23262 static struct font_metrics metrics
;
23267 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23268 if (code
== FONT_INVALID_CODE
)
23270 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23275 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23276 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23277 assumed to be zero. */
23280 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23282 *left
= *right
= 0;
23284 if (glyph
->type
== CHAR_GLYPH
)
23288 struct font_metrics
*pcm
;
23290 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23291 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23293 if (pcm
->rbearing
> pcm
->width
)
23294 *right
= pcm
->rbearing
- pcm
->width
;
23295 if (pcm
->lbearing
< 0)
23296 *left
= -pcm
->lbearing
;
23299 else if (glyph
->type
== COMPOSITE_GLYPH
)
23301 if (! glyph
->u
.cmp
.automatic
)
23303 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23305 if (cmp
->rbearing
> cmp
->pixel_width
)
23306 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23307 if (cmp
->lbearing
< 0)
23308 *left
= - cmp
->lbearing
;
23312 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23313 struct font_metrics metrics
;
23315 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23316 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23317 if (metrics
.rbearing
> metrics
.width
)
23318 *right
= metrics
.rbearing
- metrics
.width
;
23319 if (metrics
.lbearing
< 0)
23320 *left
= - metrics
.lbearing
;
23326 /* Return the index of the first glyph preceding glyph string S that
23327 is overwritten by S because of S's left overhang. Value is -1
23328 if no glyphs are overwritten. */
23331 left_overwritten (struct glyph_string
*s
)
23335 if (s
->left_overhang
)
23338 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23339 int first
= s
->first_glyph
- glyphs
;
23341 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23342 x
-= glyphs
[i
].pixel_width
;
23353 /* Return the index of the first glyph preceding glyph string S that
23354 is overwriting S because of its right overhang. Value is -1 if no
23355 glyph in front of S overwrites S. */
23358 left_overwriting (struct glyph_string
*s
)
23361 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23362 int first
= s
->first_glyph
- glyphs
;
23366 for (i
= first
- 1; i
>= 0; --i
)
23369 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23372 x
-= glyphs
[i
].pixel_width
;
23379 /* Return the index of the last glyph following glyph string S that is
23380 overwritten by S because of S's right overhang. Value is -1 if
23381 no such glyph is found. */
23384 right_overwritten (struct glyph_string
*s
)
23388 if (s
->right_overhang
)
23391 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23392 int first
= (s
->first_glyph
- glyphs
23393 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23394 int end
= s
->row
->used
[s
->area
];
23396 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23397 x
+= glyphs
[i
].pixel_width
;
23406 /* Return the index of the last glyph following glyph string S that
23407 overwrites S because of its left overhang. Value is negative
23408 if no such glyph is found. */
23411 right_overwriting (struct glyph_string
*s
)
23414 int end
= s
->row
->used
[s
->area
];
23415 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23416 int first
= (s
->first_glyph
- glyphs
23417 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23421 for (i
= first
; i
< end
; ++i
)
23424 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23427 x
+= glyphs
[i
].pixel_width
;
23434 /* Set background width of glyph string S. START is the index of the
23435 first glyph following S. LAST_X is the right-most x-position + 1
23436 in the drawing area. */
23439 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23441 /* If the face of this glyph string has to be drawn to the end of
23442 the drawing area, set S->extends_to_end_of_line_p. */
23444 if (start
== s
->row
->used
[s
->area
]
23445 && s
->area
== TEXT_AREA
23446 && ((s
->row
->fill_line_p
23447 && (s
->hl
== DRAW_NORMAL_TEXT
23448 || s
->hl
== DRAW_IMAGE_RAISED
23449 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23450 || s
->hl
== DRAW_MOUSE_FACE
))
23451 s
->extends_to_end_of_line_p
= 1;
23453 /* If S extends its face to the end of the line, set its
23454 background_width to the distance to the right edge of the drawing
23456 if (s
->extends_to_end_of_line_p
)
23457 s
->background_width
= last_x
- s
->x
+ 1;
23459 s
->background_width
= s
->width
;
23463 /* Compute overhangs and x-positions for glyph string S and its
23464 predecessors, or successors. X is the starting x-position for S.
23465 BACKWARD_P non-zero means process predecessors. */
23468 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23474 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23475 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23485 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23486 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23496 /* The following macros are only called from draw_glyphs below.
23497 They reference the following parameters of that function directly:
23498 `w', `row', `area', and `overlap_p'
23499 as well as the following local variables:
23500 `s', `f', and `hdc' (in W32) */
23503 /* On W32, silently add local `hdc' variable to argument list of
23504 init_glyph_string. */
23505 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23506 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23508 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23509 init_glyph_string (s, char2b, w, row, area, start, hl)
23512 /* Add a glyph string for a stretch glyph to the list of strings
23513 between HEAD and TAIL. START is the index of the stretch glyph in
23514 row area AREA of glyph row ROW. END is the index of the last glyph
23515 in that glyph row area. X is the current output position assigned
23516 to the new glyph string constructed. HL overrides that face of the
23517 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23518 is the right-most x-position of the drawing area. */
23520 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23521 and below -- keep them on one line. */
23522 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23525 s = alloca (sizeof *s); \
23526 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23527 START = fill_stretch_glyph_string (s, START, END); \
23528 append_glyph_string (&HEAD, &TAIL, s); \
23534 /* Add a glyph string for an image glyph to the list of strings
23535 between HEAD and TAIL. START is the index of the image glyph in
23536 row area AREA of glyph row ROW. END is the index of the last glyph
23537 in that glyph row area. X is the current output position assigned
23538 to the new glyph string constructed. HL overrides that face of the
23539 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23540 is the right-most x-position of the drawing area. */
23542 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23545 s = alloca (sizeof *s); \
23546 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23547 fill_image_glyph_string (s); \
23548 append_glyph_string (&HEAD, &TAIL, s); \
23555 /* Add a glyph string for a sequence of character glyphs to the list
23556 of strings between HEAD and TAIL. START is the index of the first
23557 glyph in row area AREA of glyph row ROW that is part of the new
23558 glyph string. END is the index of the last glyph in that glyph row
23559 area. X is the current output position assigned to the new glyph
23560 string constructed. HL overrides that face of the glyph; e.g. it
23561 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23562 right-most x-position of the drawing area. */
23564 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23570 face_id = (row)->glyphs[area][START].face_id; \
23572 s = alloca (sizeof *s); \
23573 char2b = alloca ((END - START) * sizeof *char2b); \
23574 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23575 append_glyph_string (&HEAD, &TAIL, s); \
23577 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23582 /* Add a glyph string for a composite sequence to the list of strings
23583 between HEAD and TAIL. START is the index of the first glyph in
23584 row area AREA of glyph row ROW that is part of the new glyph
23585 string. END is the index of the last glyph in that glyph row area.
23586 X is the current output position assigned to the new glyph string
23587 constructed. HL overrides that face of the glyph; e.g. it is
23588 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23589 x-position of the drawing area. */
23591 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23593 int face_id = (row)->glyphs[area][START].face_id; \
23594 struct face *base_face = FACE_FROM_ID (f, face_id); \
23595 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23596 struct composition *cmp = composition_table[cmp_id]; \
23598 struct glyph_string *first_s = NULL; \
23601 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23603 /* Make glyph_strings for each glyph sequence that is drawable by \
23604 the same face, and append them to HEAD/TAIL. */ \
23605 for (n = 0; n < cmp->glyph_len;) \
23607 s = alloca (sizeof *s); \
23608 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23609 append_glyph_string (&(HEAD), &(TAIL), s); \
23615 n = fill_composite_glyph_string (s, base_face, overlaps); \
23623 /* Add a glyph string for a glyph-string sequence to the list of strings
23624 between HEAD and TAIL. */
23626 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23630 Lisp_Object gstring; \
23632 face_id = (row)->glyphs[area][START].face_id; \
23633 gstring = (composition_gstring_from_id \
23634 ((row)->glyphs[area][START].u.cmp.id)); \
23635 s = alloca (sizeof *s); \
23636 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23637 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23638 append_glyph_string (&(HEAD), &(TAIL), s); \
23640 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23644 /* Add a glyph string for a sequence of glyphless character's glyphs
23645 to the list of strings between HEAD and TAIL. The meanings of
23646 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23648 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23653 face_id = (row)->glyphs[area][START].face_id; \
23655 s = alloca (sizeof *s); \
23656 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23657 append_glyph_string (&HEAD, &TAIL, s); \
23659 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23665 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23666 of AREA of glyph row ROW on window W between indices START and END.
23667 HL overrides the face for drawing glyph strings, e.g. it is
23668 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23669 x-positions of the drawing area.
23671 This is an ugly monster macro construct because we must use alloca
23672 to allocate glyph strings (because draw_glyphs can be called
23673 asynchronously). */
23675 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23678 HEAD = TAIL = NULL; \
23679 while (START < END) \
23681 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23682 switch (first_glyph->type) \
23685 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23689 case COMPOSITE_GLYPH: \
23690 if (first_glyph->u.cmp.automatic) \
23691 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23694 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23698 case STRETCH_GLYPH: \
23699 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23703 case IMAGE_GLYPH: \
23704 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23708 case GLYPHLESS_GLYPH: \
23709 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23719 set_glyph_string_background_width (s, START, LAST_X); \
23726 /* Draw glyphs between START and END in AREA of ROW on window W,
23727 starting at x-position X. X is relative to AREA in W. HL is a
23728 face-override with the following meaning:
23730 DRAW_NORMAL_TEXT draw normally
23731 DRAW_CURSOR draw in cursor face
23732 DRAW_MOUSE_FACE draw in mouse face.
23733 DRAW_INVERSE_VIDEO draw in mode line face
23734 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23735 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23737 If OVERLAPS is non-zero, draw only the foreground of characters and
23738 clip to the physical height of ROW. Non-zero value also defines
23739 the overlapping part to be drawn:
23741 OVERLAPS_PRED overlap with preceding rows
23742 OVERLAPS_SUCC overlap with succeeding rows
23743 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23744 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23746 Value is the x-position reached, relative to AREA of W. */
23749 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23750 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23751 enum draw_glyphs_face hl
, int overlaps
)
23753 struct glyph_string
*head
, *tail
;
23754 struct glyph_string
*s
;
23755 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23756 int i
, j
, x_reached
, last_x
, area_left
= 0;
23757 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23760 ALLOCATE_HDC (hdc
, f
);
23762 /* Let's rather be paranoid than getting a SEGV. */
23763 end
= min (end
, row
->used
[area
]);
23764 start
= clip_to_bounds (0, start
, end
);
23766 /* Translate X to frame coordinates. Set last_x to the right
23767 end of the drawing area. */
23768 if (row
->full_width_p
)
23770 /* X is relative to the left edge of W, without scroll bars
23772 area_left
= WINDOW_LEFT_EDGE_X (w
);
23773 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23777 area_left
= window_box_left (w
, area
);
23778 last_x
= area_left
+ window_box_width (w
, area
);
23782 /* Build a doubly-linked list of glyph_string structures between
23783 head and tail from what we have to draw. Note that the macro
23784 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23785 the reason we use a separate variable `i'. */
23787 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23789 x_reached
= tail
->x
+ tail
->background_width
;
23793 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23794 the row, redraw some glyphs in front or following the glyph
23795 strings built above. */
23796 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23798 struct glyph_string
*h
, *t
;
23799 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23800 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23801 int check_mouse_face
= 0;
23804 /* If mouse highlighting is on, we may need to draw adjacent
23805 glyphs using mouse-face highlighting. */
23806 if (area
== TEXT_AREA
&& row
->mouse_face_p
23807 && hlinfo
->mouse_face_beg_row
>= 0
23808 && hlinfo
->mouse_face_end_row
>= 0)
23810 ptrdiff_t row_vpos
= MATRIX_ROW_VPOS (row
, w
->current_matrix
);
23812 if (row_vpos
>= hlinfo
->mouse_face_beg_row
23813 && row_vpos
<= hlinfo
->mouse_face_end_row
)
23815 check_mouse_face
= 1;
23816 mouse_beg_col
= (row_vpos
== hlinfo
->mouse_face_beg_row
)
23817 ? hlinfo
->mouse_face_beg_col
: 0;
23818 mouse_end_col
= (row_vpos
== hlinfo
->mouse_face_end_row
)
23819 ? hlinfo
->mouse_face_end_col
23820 : row
->used
[TEXT_AREA
];
23824 /* Compute overhangs for all glyph strings. */
23825 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23826 for (s
= head
; s
; s
= s
->next
)
23827 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23829 /* Prepend glyph strings for glyphs in front of the first glyph
23830 string that are overwritten because of the first glyph
23831 string's left overhang. The background of all strings
23832 prepended must be drawn because the first glyph string
23834 i
= left_overwritten (head
);
23837 enum draw_glyphs_face overlap_hl
;
23839 /* If this row contains mouse highlighting, attempt to draw
23840 the overlapped glyphs with the correct highlight. This
23841 code fails if the overlap encompasses more than one glyph
23842 and mouse-highlight spans only some of these glyphs.
23843 However, making it work perfectly involves a lot more
23844 code, and I don't know if the pathological case occurs in
23845 practice, so we'll stick to this for now. --- cyd */
23846 if (check_mouse_face
23847 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23848 overlap_hl
= DRAW_MOUSE_FACE
;
23850 overlap_hl
= DRAW_NORMAL_TEXT
;
23853 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23854 overlap_hl
, dummy_x
, last_x
);
23856 compute_overhangs_and_x (t
, head
->x
, 1);
23857 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23861 /* Prepend glyph strings for glyphs in front of the first glyph
23862 string that overwrite that glyph string because of their
23863 right overhang. For these strings, only the foreground must
23864 be drawn, because it draws over the glyph string at `head'.
23865 The background must not be drawn because this would overwrite
23866 right overhangs of preceding glyphs for which no glyph
23868 i
= left_overwriting (head
);
23871 enum draw_glyphs_face overlap_hl
;
23873 if (check_mouse_face
23874 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23875 overlap_hl
= DRAW_MOUSE_FACE
;
23877 overlap_hl
= DRAW_NORMAL_TEXT
;
23880 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23881 overlap_hl
, dummy_x
, last_x
);
23882 for (s
= h
; s
; s
= s
->next
)
23883 s
->background_filled_p
= 1;
23884 compute_overhangs_and_x (t
, head
->x
, 1);
23885 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23888 /* Append glyphs strings for glyphs following the last glyph
23889 string tail that are overwritten by tail. The background of
23890 these strings has to be drawn because tail's foreground draws
23892 i
= right_overwritten (tail
);
23895 enum draw_glyphs_face overlap_hl
;
23897 if (check_mouse_face
23898 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23899 overlap_hl
= DRAW_MOUSE_FACE
;
23901 overlap_hl
= DRAW_NORMAL_TEXT
;
23903 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23904 overlap_hl
, x
, last_x
);
23905 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23906 we don't have `end = i;' here. */
23907 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23908 append_glyph_string_lists (&head
, &tail
, h
, t
);
23912 /* Append glyph strings for glyphs following the last glyph
23913 string tail that overwrite tail. The foreground of such
23914 glyphs has to be drawn because it writes into the background
23915 of tail. The background must not be drawn because it could
23916 paint over the foreground of following glyphs. */
23917 i
= right_overwriting (tail
);
23920 enum draw_glyphs_face overlap_hl
;
23921 if (check_mouse_face
23922 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23923 overlap_hl
= DRAW_MOUSE_FACE
;
23925 overlap_hl
= DRAW_NORMAL_TEXT
;
23928 i
++; /* We must include the Ith glyph. */
23929 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23930 overlap_hl
, x
, last_x
);
23931 for (s
= h
; s
; s
= s
->next
)
23932 s
->background_filled_p
= 1;
23933 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23934 append_glyph_string_lists (&head
, &tail
, h
, t
);
23936 if (clip_head
|| clip_tail
)
23937 for (s
= head
; s
; s
= s
->next
)
23939 s
->clip_head
= clip_head
;
23940 s
->clip_tail
= clip_tail
;
23944 /* Draw all strings. */
23945 for (s
= head
; s
; s
= s
->next
)
23946 FRAME_RIF (f
)->draw_glyph_string (s
);
23949 /* When focus a sole frame and move horizontally, this sets on_p to 0
23950 causing a failure to erase prev cursor position. */
23951 if (area
== TEXT_AREA
23952 && !row
->full_width_p
23953 /* When drawing overlapping rows, only the glyph strings'
23954 foreground is drawn, which doesn't erase a cursor
23958 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
23959 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
23960 : (tail
? tail
->x
+ tail
->background_width
: x
));
23964 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
23965 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
23969 /* Value is the x-position up to which drawn, relative to AREA of W.
23970 This doesn't include parts drawn because of overhangs. */
23971 if (row
->full_width_p
)
23972 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
23974 x_reached
-= area_left
;
23976 RELEASE_HDC (hdc
, f
);
23981 /* Expand row matrix if too narrow. Don't expand if area
23984 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
23986 if (!it->f->fonts_changed \
23987 && (it->glyph_row->glyphs[area] \
23988 < it->glyph_row->glyphs[area + 1])) \
23990 it->w->ncols_scale_factor++; \
23991 it->f->fonts_changed = 1; \
23995 /* Store one glyph for IT->char_to_display in IT->glyph_row.
23996 Called from x_produce_glyphs when IT->glyph_row is non-null. */
23999 append_glyph (struct it
*it
)
24001 struct glyph
*glyph
;
24002 enum glyph_row_area area
= it
->area
;
24004 eassert (it
->glyph_row
);
24005 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24007 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24008 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24010 /* If the glyph row is reversed, we need to prepend the glyph
24011 rather than append it. */
24012 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24016 /* Make room for the additional glyph. */
24017 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24019 glyph
= it
->glyph_row
->glyphs
[area
];
24021 glyph
->charpos
= CHARPOS (it
->position
);
24022 glyph
->object
= it
->object
;
24023 if (it
->pixel_width
> 0)
24025 glyph
->pixel_width
= it
->pixel_width
;
24026 glyph
->padding_p
= 0;
24030 /* Assure at least 1-pixel width. Otherwise, cursor can't
24031 be displayed correctly. */
24032 glyph
->pixel_width
= 1;
24033 glyph
->padding_p
= 1;
24035 glyph
->ascent
= it
->ascent
;
24036 glyph
->descent
= it
->descent
;
24037 glyph
->voffset
= it
->voffset
;
24038 glyph
->type
= CHAR_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
= (it
->phys_ascent
> it
->ascent
24054 || it
->phys_descent
> it
->descent
);
24055 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24056 glyph
->face_id
= it
->face_id
;
24057 glyph
->u
.ch
= it
->char_to_display
;
24058 glyph
->slice
.img
= null_glyph_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
;
24069 glyph
->resolved_level
= 0;
24070 glyph
->bidi_type
= UNKNOWN_BT
;
24072 ++it
->glyph_row
->used
[area
];
24075 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24078 /* Store one glyph for the composition IT->cmp_it.id in
24079 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24083 append_composite_glyph (struct it
*it
)
24085 struct glyph
*glyph
;
24086 enum glyph_row_area area
= it
->area
;
24088 eassert (it
->glyph_row
);
24090 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24091 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24093 /* If the glyph row is reversed, we need to prepend the glyph
24094 rather than append it. */
24095 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24099 /* Make room for the new glyph. */
24100 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24102 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24104 glyph
->charpos
= it
->cmp_it
.charpos
;
24105 glyph
->object
= it
->object
;
24106 glyph
->pixel_width
= it
->pixel_width
;
24107 glyph
->ascent
= it
->ascent
;
24108 glyph
->descent
= it
->descent
;
24109 glyph
->voffset
= it
->voffset
;
24110 glyph
->type
= COMPOSITE_GLYPH
;
24111 if (it
->cmp_it
.ch
< 0)
24113 glyph
->u
.cmp
.automatic
= 0;
24114 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24115 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24119 glyph
->u
.cmp
.automatic
= 1;
24120 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24121 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24122 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24124 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24125 glyph
->multibyte_p
= it
->multibyte_p
;
24126 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24128 /* In R2L rows, the left and the right box edges need to be
24129 drawn in reverse direction. */
24130 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24131 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24135 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24136 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24138 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24139 || it
->phys_descent
> it
->descent
);
24140 glyph
->padding_p
= 0;
24141 glyph
->glyph_not_available_p
= 0;
24142 glyph
->face_id
= it
->face_id
;
24143 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24146 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24147 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24149 glyph
->bidi_type
= it
->bidi_it
.type
;
24151 ++it
->glyph_row
->used
[area
];
24154 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24158 /* Change IT->ascent and IT->height according to the setting of
24162 take_vertical_position_into_account (struct it
*it
)
24166 if (it
->voffset
< 0)
24167 /* Increase the ascent so that we can display the text higher
24169 it
->ascent
-= it
->voffset
;
24171 /* Increase the descent so that we can display the text lower
24173 it
->descent
+= it
->voffset
;
24178 /* Produce glyphs/get display metrics for the image IT is loaded with.
24179 See the description of struct display_iterator in dispextern.h for
24180 an overview of struct display_iterator. */
24183 produce_image_glyph (struct it
*it
)
24187 int glyph_ascent
, crop
;
24188 struct glyph_slice slice
;
24190 eassert (it
->what
== IT_IMAGE
);
24192 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24194 /* Make sure X resources of the face is loaded. */
24195 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24197 if (it
->image_id
< 0)
24199 /* Fringe bitmap. */
24200 it
->ascent
= it
->phys_ascent
= 0;
24201 it
->descent
= it
->phys_descent
= 0;
24202 it
->pixel_width
= 0;
24207 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24209 /* Make sure X resources of the image is loaded. */
24210 prepare_image_for_display (it
->f
, img
);
24212 slice
.x
= slice
.y
= 0;
24213 slice
.width
= img
->width
;
24214 slice
.height
= img
->height
;
24216 if (INTEGERP (it
->slice
.x
))
24217 slice
.x
= XINT (it
->slice
.x
);
24218 else if (FLOATP (it
->slice
.x
))
24219 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24221 if (INTEGERP (it
->slice
.y
))
24222 slice
.y
= XINT (it
->slice
.y
);
24223 else if (FLOATP (it
->slice
.y
))
24224 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24226 if (INTEGERP (it
->slice
.width
))
24227 slice
.width
= XINT (it
->slice
.width
);
24228 else if (FLOATP (it
->slice
.width
))
24229 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24231 if (INTEGERP (it
->slice
.height
))
24232 slice
.height
= XINT (it
->slice
.height
);
24233 else if (FLOATP (it
->slice
.height
))
24234 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24236 if (slice
.x
>= img
->width
)
24237 slice
.x
= img
->width
;
24238 if (slice
.y
>= img
->height
)
24239 slice
.y
= img
->height
;
24240 if (slice
.x
+ slice
.width
>= img
->width
)
24241 slice
.width
= img
->width
- slice
.x
;
24242 if (slice
.y
+ slice
.height
> img
->height
)
24243 slice
.height
= img
->height
- slice
.y
;
24245 if (slice
.width
== 0 || slice
.height
== 0)
24248 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24250 it
->descent
= slice
.height
- glyph_ascent
;
24252 it
->descent
+= img
->vmargin
;
24253 if (slice
.y
+ slice
.height
== img
->height
)
24254 it
->descent
+= img
->vmargin
;
24255 it
->phys_descent
= it
->descent
;
24257 it
->pixel_width
= slice
.width
;
24259 it
->pixel_width
+= img
->hmargin
;
24260 if (slice
.x
+ slice
.width
== img
->width
)
24261 it
->pixel_width
+= img
->hmargin
;
24263 /* It's quite possible for images to have an ascent greater than
24264 their height, so don't get confused in that case. */
24265 if (it
->descent
< 0)
24270 if (face
->box
!= FACE_NO_BOX
)
24272 if (face
->box_line_width
> 0)
24275 it
->ascent
+= face
->box_line_width
;
24276 if (slice
.y
+ slice
.height
== img
->height
)
24277 it
->descent
+= face
->box_line_width
;
24280 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24281 it
->pixel_width
+= eabs (face
->box_line_width
);
24282 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24283 it
->pixel_width
+= eabs (face
->box_line_width
);
24286 take_vertical_position_into_account (it
);
24288 /* Automatically crop wide image glyphs at right edge so we can
24289 draw the cursor on same display row. */
24290 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24291 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24293 it
->pixel_width
-= crop
;
24294 slice
.width
-= crop
;
24299 struct glyph
*glyph
;
24300 enum glyph_row_area area
= it
->area
;
24302 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24303 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24305 glyph
->charpos
= CHARPOS (it
->position
);
24306 glyph
->object
= it
->object
;
24307 glyph
->pixel_width
= it
->pixel_width
;
24308 glyph
->ascent
= glyph_ascent
;
24309 glyph
->descent
= it
->descent
;
24310 glyph
->voffset
= it
->voffset
;
24311 glyph
->type
= IMAGE_GLYPH
;
24312 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24313 glyph
->multibyte_p
= it
->multibyte_p
;
24314 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24316 /* In R2L rows, the left and the right box edges need to be
24317 drawn in reverse direction. */
24318 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24319 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24323 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24324 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24326 glyph
->overlaps_vertically_p
= 0;
24327 glyph
->padding_p
= 0;
24328 glyph
->glyph_not_available_p
= 0;
24329 glyph
->face_id
= it
->face_id
;
24330 glyph
->u
.img_id
= img
->id
;
24331 glyph
->slice
.img
= slice
;
24332 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24335 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24336 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24338 glyph
->bidi_type
= it
->bidi_it
.type
;
24340 ++it
->glyph_row
->used
[area
];
24343 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24348 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24349 of the glyph, WIDTH and HEIGHT are the width and height of the
24350 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24353 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24354 int width
, int height
, int ascent
)
24356 struct glyph
*glyph
;
24357 enum glyph_row_area area
= it
->area
;
24359 eassert (ascent
>= 0 && ascent
<= height
);
24361 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24362 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24364 /* If the glyph row is reversed, we need to prepend the glyph
24365 rather than append it. */
24366 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24370 /* Make room for the additional glyph. */
24371 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24373 glyph
= it
->glyph_row
->glyphs
[area
];
24375 glyph
->charpos
= CHARPOS (it
->position
);
24376 glyph
->object
= object
;
24377 glyph
->pixel_width
= width
;
24378 glyph
->ascent
= ascent
;
24379 glyph
->descent
= height
- ascent
;
24380 glyph
->voffset
= it
->voffset
;
24381 glyph
->type
= STRETCH_GLYPH
;
24382 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24383 glyph
->multibyte_p
= it
->multibyte_p
;
24384 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24386 /* In R2L rows, the left and the right box edges need to be
24387 drawn in reverse direction. */
24388 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24389 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24393 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24394 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24396 glyph
->overlaps_vertically_p
= 0;
24397 glyph
->padding_p
= 0;
24398 glyph
->glyph_not_available_p
= 0;
24399 glyph
->face_id
= it
->face_id
;
24400 glyph
->u
.stretch
.ascent
= ascent
;
24401 glyph
->u
.stretch
.height
= height
;
24402 glyph
->slice
.img
= null_glyph_slice
;
24403 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24406 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24407 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24409 glyph
->bidi_type
= it
->bidi_it
.type
;
24413 glyph
->resolved_level
= 0;
24414 glyph
->bidi_type
= UNKNOWN_BT
;
24416 ++it
->glyph_row
->used
[area
];
24419 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24422 #endif /* HAVE_WINDOW_SYSTEM */
24424 /* Produce a stretch glyph for iterator IT. IT->object is the value
24425 of the glyph property displayed. The value must be a list
24426 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24429 1. `:width WIDTH' specifies that the space should be WIDTH *
24430 canonical char width wide. WIDTH may be an integer or floating
24433 2. `:relative-width FACTOR' specifies that the width of the stretch
24434 should be computed from the width of the first character having the
24435 `glyph' property, and should be FACTOR times that width.
24437 3. `:align-to HPOS' specifies that the space should be wide enough
24438 to reach HPOS, a value in canonical character units.
24440 Exactly one of the above pairs must be present.
24442 4. `:height HEIGHT' specifies that the height of the stretch produced
24443 should be HEIGHT, measured in canonical character units.
24445 5. `:relative-height FACTOR' specifies that the height of the
24446 stretch should be FACTOR times the height of the characters having
24447 the glyph property.
24449 Either none or exactly one of 4 or 5 must be present.
24451 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24452 of the stretch should be used for the ascent of the stretch.
24453 ASCENT must be in the range 0 <= ASCENT <= 100. */
24456 produce_stretch_glyph (struct it
*it
)
24458 /* (space :width WIDTH :height HEIGHT ...) */
24459 Lisp_Object prop
, plist
;
24460 int width
= 0, height
= 0, align_to
= -1;
24461 int zero_width_ok_p
= 0;
24463 struct font
*font
= NULL
;
24465 #ifdef HAVE_WINDOW_SYSTEM
24467 int zero_height_ok_p
= 0;
24469 if (FRAME_WINDOW_P (it
->f
))
24471 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24472 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24473 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24477 /* List should start with `space'. */
24478 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24479 plist
= XCDR (it
->object
);
24481 /* Compute the width of the stretch. */
24482 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24483 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24485 /* Absolute width `:width WIDTH' specified and valid. */
24486 zero_width_ok_p
= 1;
24489 #ifdef HAVE_WINDOW_SYSTEM
24490 else if (FRAME_WINDOW_P (it
->f
)
24491 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24493 /* Relative width `:relative-width FACTOR' specified and valid.
24494 Compute the width of the characters having the `glyph'
24497 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24500 if (it
->multibyte_p
)
24501 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24504 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24505 if (! ASCII_CHAR_P (it2
.c
))
24506 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24509 it2
.glyph_row
= NULL
;
24510 it2
.what
= IT_CHARACTER
;
24511 x_produce_glyphs (&it2
);
24512 width
= NUMVAL (prop
) * it2
.pixel_width
;
24514 #endif /* HAVE_WINDOW_SYSTEM */
24515 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24516 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24518 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24519 align_to
= (align_to
< 0
24521 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24522 else if (align_to
< 0)
24523 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24524 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24525 zero_width_ok_p
= 1;
24528 /* Nothing specified -> width defaults to canonical char width. */
24529 width
= FRAME_COLUMN_WIDTH (it
->f
);
24531 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24534 #ifdef HAVE_WINDOW_SYSTEM
24535 /* Compute height. */
24536 if (FRAME_WINDOW_P (it
->f
))
24538 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24539 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24542 zero_height_ok_p
= 1;
24544 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24546 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24548 height
= FONT_HEIGHT (font
);
24550 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24553 /* Compute percentage of height used for ascent. If
24554 `:ascent ASCENT' is present and valid, use that. Otherwise,
24555 derive the ascent from the font in use. */
24556 if (prop
= Fplist_get (plist
, QCascent
),
24557 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24558 ascent
= height
* NUMVAL (prop
) / 100.0;
24559 else if (!NILP (prop
)
24560 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24561 ascent
= min (max (0, (int)tem
), height
);
24563 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24566 #endif /* HAVE_WINDOW_SYSTEM */
24569 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24570 && it
->current_x
+ width
> it
->last_visible_x
)
24572 width
= it
->last_visible_x
- it
->current_x
;
24573 #ifdef HAVE_WINDOW_SYSTEM
24574 /* Subtract one more pixel from the stretch width, but only on
24575 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24576 width
-= FRAME_WINDOW_P (it
->f
);
24580 if (width
> 0 && height
> 0 && it
->glyph_row
)
24582 Lisp_Object o_object
= it
->object
;
24583 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24586 if (!STRINGP (object
))
24587 object
= it
->w
->contents
;
24588 #ifdef HAVE_WINDOW_SYSTEM
24589 if (FRAME_WINDOW_P (it
->f
))
24590 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24594 it
->object
= object
;
24595 it
->char_to_display
= ' ';
24596 it
->pixel_width
= it
->len
= 1;
24598 tty_append_glyph (it
);
24599 it
->object
= o_object
;
24603 it
->pixel_width
= width
;
24604 #ifdef HAVE_WINDOW_SYSTEM
24605 if (FRAME_WINDOW_P (it
->f
))
24607 it
->ascent
= it
->phys_ascent
= ascent
;
24608 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24609 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24610 take_vertical_position_into_account (it
);
24614 it
->nglyphs
= width
;
24617 /* Get information about special display element WHAT in an
24618 environment described by IT. WHAT is one of IT_TRUNCATION or
24619 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24620 non-null glyph_row member. This function ensures that fields like
24621 face_id, c, len of IT are left untouched. */
24624 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24631 temp_it
.object
= make_number (0);
24632 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24634 if (what
== IT_CONTINUATION
)
24636 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24637 if (it
->bidi_it
.paragraph_dir
== R2L
)
24638 SET_GLYPH_FROM_CHAR (glyph
, '/');
24640 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24642 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24644 /* FIXME: Should we mirror GC for R2L lines? */
24645 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24646 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24649 else if (what
== IT_TRUNCATION
)
24651 /* Truncation glyph. */
24652 SET_GLYPH_FROM_CHAR (glyph
, '$');
24654 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24656 /* FIXME: Should we mirror GC for R2L lines? */
24657 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24658 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24664 #ifdef HAVE_WINDOW_SYSTEM
24665 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24666 is turned off, we precede the truncation/continuation glyphs by a
24667 stretch glyph whose width is computed such that these special
24668 glyphs are aligned at the window margin, even when very different
24669 fonts are used in different glyph rows. */
24670 if (FRAME_WINDOW_P (temp_it
.f
)
24671 /* init_iterator calls this with it->glyph_row == NULL, and it
24672 wants only the pixel width of the truncation/continuation
24674 && temp_it
.glyph_row
24675 /* insert_left_trunc_glyphs calls us at the beginning of the
24676 row, and it has its own calculation of the stretch glyph
24678 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24679 && (temp_it
.glyph_row
->reversed_p
24680 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24681 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24683 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24685 if (stretch_width
> 0)
24687 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24688 struct font
*font
=
24689 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24690 int stretch_ascent
=
24691 (((temp_it
.ascent
+ temp_it
.descent
)
24692 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24694 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24695 temp_it
.ascent
+ temp_it
.descent
,
24702 temp_it
.what
= IT_CHARACTER
;
24704 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24705 temp_it
.face_id
= GLYPH_FACE (glyph
);
24706 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24708 PRODUCE_GLYPHS (&temp_it
);
24709 it
->pixel_width
= temp_it
.pixel_width
;
24710 it
->nglyphs
= temp_it
.pixel_width
;
24713 #ifdef HAVE_WINDOW_SYSTEM
24715 /* Calculate line-height and line-spacing properties.
24716 An integer value specifies explicit pixel value.
24717 A float value specifies relative value to current face height.
24718 A cons (float . face-name) specifies relative value to
24719 height of specified face font.
24721 Returns height in pixels, or nil. */
24725 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24726 int boff
, int override
)
24728 Lisp_Object face_name
= Qnil
;
24729 int ascent
, descent
, height
;
24731 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24736 face_name
= XCAR (val
);
24738 if (!NUMBERP (val
))
24739 val
= make_number (1);
24740 if (NILP (face_name
))
24742 height
= it
->ascent
+ it
->descent
;
24747 if (NILP (face_name
))
24749 font
= FRAME_FONT (it
->f
);
24750 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24752 else if (EQ (face_name
, Qt
))
24761 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24763 return make_number (-1);
24765 face
= FACE_FROM_ID (it
->f
, face_id
);
24768 return make_number (-1);
24769 boff
= font
->baseline_offset
;
24770 if (font
->vertical_centering
)
24771 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24774 ascent
= FONT_BASE (font
) + boff
;
24775 descent
= FONT_DESCENT (font
) - boff
;
24779 it
->override_ascent
= ascent
;
24780 it
->override_descent
= descent
;
24781 it
->override_boff
= boff
;
24784 height
= ascent
+ descent
;
24788 height
= (int)(XFLOAT_DATA (val
) * height
);
24789 else if (INTEGERP (val
))
24790 height
*= XINT (val
);
24792 return make_number (height
);
24796 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24797 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24798 and only if this is for a character for which no font was found.
24800 If the display method (it->glyphless_method) is
24801 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24802 length of the acronym or the hexadecimal string, UPPER_XOFF and
24803 UPPER_YOFF are pixel offsets for the upper part of the string,
24804 LOWER_XOFF and LOWER_YOFF are for the lower part.
24806 For the other display methods, LEN through LOWER_YOFF are zero. */
24809 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24810 short upper_xoff
, short upper_yoff
,
24811 short lower_xoff
, short lower_yoff
)
24813 struct glyph
*glyph
;
24814 enum glyph_row_area area
= it
->area
;
24816 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24817 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24819 /* If the glyph row is reversed, we need to prepend the glyph
24820 rather than append it. */
24821 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24825 /* Make room for the additional glyph. */
24826 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24828 glyph
= it
->glyph_row
->glyphs
[area
];
24830 glyph
->charpos
= CHARPOS (it
->position
);
24831 glyph
->object
= it
->object
;
24832 glyph
->pixel_width
= it
->pixel_width
;
24833 glyph
->ascent
= it
->ascent
;
24834 glyph
->descent
= it
->descent
;
24835 glyph
->voffset
= it
->voffset
;
24836 glyph
->type
= GLYPHLESS_GLYPH
;
24837 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24838 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24839 glyph
->u
.glyphless
.len
= len
;
24840 glyph
->u
.glyphless
.ch
= it
->c
;
24841 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24842 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24843 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24844 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24845 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24846 glyph
->multibyte_p
= it
->multibyte_p
;
24847 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24849 /* In R2L rows, the left and the right box edges need to be
24850 drawn in reverse direction. */
24851 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24852 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24856 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24857 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24859 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24860 || it
->phys_descent
> it
->descent
);
24861 glyph
->padding_p
= 0;
24862 glyph
->glyph_not_available_p
= 0;
24863 glyph
->face_id
= face_id
;
24864 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24867 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24868 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24870 glyph
->bidi_type
= it
->bidi_it
.type
;
24872 ++it
->glyph_row
->used
[area
];
24875 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24879 /* Produce a glyph for a glyphless character for iterator IT.
24880 IT->glyphless_method specifies which method to use for displaying
24881 the character. See the description of enum
24882 glyphless_display_method in dispextern.h for the detail.
24884 FOR_NO_FONT is nonzero if and only if this is for a character for
24885 which no font was found. ACRONYM, if non-nil, is an acronym string
24886 for the character. */
24889 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24894 int base_width
, base_height
, width
, height
;
24895 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24898 /* Get the metrics of the base font. We always refer to the current
24900 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24901 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24902 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24903 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24904 base_height
= it
->ascent
+ it
->descent
;
24905 base_width
= font
->average_width
;
24907 face_id
= merge_glyphless_glyph_face (it
);
24909 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24911 it
->pixel_width
= THIN_SPACE_WIDTH
;
24913 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24915 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24917 width
= CHAR_WIDTH (it
->c
);
24920 else if (width
> 4)
24922 it
->pixel_width
= base_width
* width
;
24924 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24930 unsigned int code
[6];
24932 int ascent
, descent
;
24933 struct font_metrics metrics_upper
, metrics_lower
;
24935 face
= FACE_FROM_ID (it
->f
, face_id
);
24936 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24937 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24939 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
24941 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
24942 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
24943 if (CONSP (acronym
))
24944 acronym
= XCAR (acronym
);
24945 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
24949 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
24950 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
24953 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
24954 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
24955 upper_len
= (len
+ 1) / 2;
24956 font
->driver
->text_extents (font
, code
, upper_len
,
24958 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
24963 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
24964 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
24965 upper_xoff
= upper_yoff
= 2; /* the typical case */
24966 if (base_width
>= width
)
24968 /* Align the upper to the left, the lower to the right. */
24969 it
->pixel_width
= base_width
;
24970 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
24974 /* Center the shorter one. */
24975 it
->pixel_width
= width
;
24976 if (metrics_upper
.width
>= metrics_lower
.width
)
24977 lower_xoff
= (width
- metrics_lower
.width
) / 2;
24980 /* FIXME: This code doesn't look right. It formerly was
24981 missing the "lower_xoff = 0;", which couldn't have
24982 been right since it left lower_xoff uninitialized. */
24984 upper_xoff
= (width
- metrics_upper
.width
) / 2;
24988 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
24989 top, bottom, and between upper and lower strings. */
24990 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
24991 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
24992 /* Center vertically.
24993 H:base_height, D:base_descent
24994 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
24996 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
24997 descent = D - H/2 + h/2;
24998 lower_yoff = descent - 2 - ld;
24999 upper_yoff = lower_yoff - la - 1 - ud; */
25000 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25001 descent
= it
->descent
- (base_height
- height
) / 2;
25002 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25003 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25004 - metrics_upper
.descent
);
25005 /* Don't make the height shorter than the base height. */
25006 if (height
> base_height
)
25008 it
->ascent
= ascent
;
25009 it
->descent
= descent
;
25013 it
->phys_ascent
= it
->ascent
;
25014 it
->phys_descent
= it
->descent
;
25016 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25017 upper_xoff
, upper_yoff
,
25018 lower_xoff
, lower_yoff
);
25020 take_vertical_position_into_account (it
);
25025 Produce glyphs/get display metrics for the display element IT is
25026 loaded with. See the description of struct it in dispextern.h
25027 for an overview of struct it. */
25030 x_produce_glyphs (struct it
*it
)
25032 int extra_line_spacing
= it
->extra_line_spacing
;
25034 it
->glyph_not_available_p
= 0;
25036 if (it
->what
== IT_CHARACTER
)
25039 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25040 struct font
*font
= face
->font
;
25041 struct font_metrics
*pcm
= NULL
;
25042 int boff
; /* baseline offset */
25046 /* When no suitable font is found, display this character by
25047 the method specified in the first extra slot of
25048 Vglyphless_char_display. */
25049 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25051 eassert (it
->what
== IT_GLYPHLESS
);
25052 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25056 boff
= font
->baseline_offset
;
25057 if (font
->vertical_centering
)
25058 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25060 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25066 if (it
->override_ascent
>= 0)
25068 it
->ascent
= it
->override_ascent
;
25069 it
->descent
= it
->override_descent
;
25070 boff
= it
->override_boff
;
25074 it
->ascent
= FONT_BASE (font
) + boff
;
25075 it
->descent
= FONT_DESCENT (font
) - boff
;
25078 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25080 pcm
= get_per_char_metric (font
, &char2b
);
25081 if (pcm
->width
== 0
25082 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25088 it
->phys_ascent
= pcm
->ascent
+ boff
;
25089 it
->phys_descent
= pcm
->descent
- boff
;
25090 it
->pixel_width
= pcm
->width
;
25094 it
->glyph_not_available_p
= 1;
25095 it
->phys_ascent
= it
->ascent
;
25096 it
->phys_descent
= it
->descent
;
25097 it
->pixel_width
= font
->space_width
;
25100 if (it
->constrain_row_ascent_descent_p
)
25102 if (it
->descent
> it
->max_descent
)
25104 it
->ascent
+= it
->descent
- it
->max_descent
;
25105 it
->descent
= it
->max_descent
;
25107 if (it
->ascent
> it
->max_ascent
)
25109 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25110 it
->ascent
= it
->max_ascent
;
25112 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25113 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25114 extra_line_spacing
= 0;
25117 /* If this is a space inside a region of text with
25118 `space-width' property, change its width. */
25119 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25121 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25123 /* If face has a box, add the box thickness to the character
25124 height. If character has a box line to the left and/or
25125 right, add the box line width to the character's width. */
25126 if (face
->box
!= FACE_NO_BOX
)
25128 int thick
= face
->box_line_width
;
25132 it
->ascent
+= thick
;
25133 it
->descent
+= thick
;
25138 if (it
->start_of_box_run_p
)
25139 it
->pixel_width
+= thick
;
25140 if (it
->end_of_box_run_p
)
25141 it
->pixel_width
+= thick
;
25144 /* If face has an overline, add the height of the overline
25145 (1 pixel) and a 1 pixel margin to the character height. */
25146 if (face
->overline_p
)
25147 it
->ascent
+= overline_margin
;
25149 if (it
->constrain_row_ascent_descent_p
)
25151 if (it
->ascent
> it
->max_ascent
)
25152 it
->ascent
= it
->max_ascent
;
25153 if (it
->descent
> it
->max_descent
)
25154 it
->descent
= it
->max_descent
;
25157 take_vertical_position_into_account (it
);
25159 /* If we have to actually produce glyphs, do it. */
25164 /* Translate a space with a `space-width' property
25165 into a stretch glyph. */
25166 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25167 / FONT_HEIGHT (font
));
25168 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25169 it
->ascent
+ it
->descent
, ascent
);
25174 /* If characters with lbearing or rbearing are displayed
25175 in this line, record that fact in a flag of the
25176 glyph row. This is used to optimize X output code. */
25177 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25178 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25180 if (! stretched_p
&& it
->pixel_width
== 0)
25181 /* We assure that all visible glyphs have at least 1-pixel
25183 it
->pixel_width
= 1;
25185 else if (it
->char_to_display
== '\n')
25187 /* A newline has no width, but we need the height of the
25188 line. But if previous part of the line sets a height,
25189 don't increase that height */
25191 Lisp_Object height
;
25192 Lisp_Object total_height
= Qnil
;
25194 it
->override_ascent
= -1;
25195 it
->pixel_width
= 0;
25198 height
= get_it_property (it
, Qline_height
);
25199 /* Split (line-height total-height) list */
25201 && CONSP (XCDR (height
))
25202 && NILP (XCDR (XCDR (height
))))
25204 total_height
= XCAR (XCDR (height
));
25205 height
= XCAR (height
);
25207 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25209 if (it
->override_ascent
>= 0)
25211 it
->ascent
= it
->override_ascent
;
25212 it
->descent
= it
->override_descent
;
25213 boff
= it
->override_boff
;
25217 it
->ascent
= FONT_BASE (font
) + boff
;
25218 it
->descent
= FONT_DESCENT (font
) - boff
;
25221 if (EQ (height
, Qt
))
25223 if (it
->descent
> it
->max_descent
)
25225 it
->ascent
+= it
->descent
- it
->max_descent
;
25226 it
->descent
= it
->max_descent
;
25228 if (it
->ascent
> it
->max_ascent
)
25230 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25231 it
->ascent
= it
->max_ascent
;
25233 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25234 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25235 it
->constrain_row_ascent_descent_p
= 1;
25236 extra_line_spacing
= 0;
25240 Lisp_Object spacing
;
25242 it
->phys_ascent
= it
->ascent
;
25243 it
->phys_descent
= it
->descent
;
25245 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25246 && face
->box
!= FACE_NO_BOX
25247 && face
->box_line_width
> 0)
25249 it
->ascent
+= face
->box_line_width
;
25250 it
->descent
+= face
->box_line_width
;
25253 && XINT (height
) > it
->ascent
+ it
->descent
)
25254 it
->ascent
= XINT (height
) - it
->descent
;
25256 if (!NILP (total_height
))
25257 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25260 spacing
= get_it_property (it
, Qline_spacing
);
25261 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25263 if (INTEGERP (spacing
))
25265 extra_line_spacing
= XINT (spacing
);
25266 if (!NILP (total_height
))
25267 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25271 else /* i.e. (it->char_to_display == '\t') */
25273 if (font
->space_width
> 0)
25275 int tab_width
= it
->tab_width
* font
->space_width
;
25276 int x
= it
->current_x
+ it
->continuation_lines_width
;
25277 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25279 /* If the distance from the current position to the next tab
25280 stop is less than a space character width, use the
25281 tab stop after that. */
25282 if (next_tab_x
- x
< font
->space_width
)
25283 next_tab_x
+= tab_width
;
25285 it
->pixel_width
= next_tab_x
- x
;
25287 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25288 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25292 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25293 it
->ascent
+ it
->descent
, it
->ascent
);
25298 it
->pixel_width
= 0;
25303 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25305 /* A static composition.
25307 Note: A composition is represented as one glyph in the
25308 glyph matrix. There are no padding glyphs.
25310 Important note: pixel_width, ascent, and descent are the
25311 values of what is drawn by draw_glyphs (i.e. the values of
25312 the overall glyphs composed). */
25313 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25314 int boff
; /* baseline offset */
25315 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25316 int glyph_len
= cmp
->glyph_len
;
25317 struct font
*font
= face
->font
;
25321 /* If we have not yet calculated pixel size data of glyphs of
25322 the composition for the current face font, calculate them
25323 now. Theoretically, we have to check all fonts for the
25324 glyphs, but that requires much time and memory space. So,
25325 here we check only the font of the first glyph. This may
25326 lead to incorrect display, but it's very rare, and C-l
25327 (recenter-top-bottom) can correct the display anyway. */
25328 if (! cmp
->font
|| cmp
->font
!= font
)
25330 /* Ascent and descent of the font of the first character
25331 of this composition (adjusted by baseline offset).
25332 Ascent and descent of overall glyphs should not be less
25333 than these, respectively. */
25334 int font_ascent
, font_descent
, font_height
;
25335 /* Bounding box of the overall glyphs. */
25336 int leftmost
, rightmost
, lowest
, highest
;
25337 int lbearing
, rbearing
;
25338 int i
, width
, ascent
, descent
;
25339 int left_padded
= 0, right_padded
= 0;
25340 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25342 struct font_metrics
*pcm
;
25343 int font_not_found_p
;
25346 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25347 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25349 if (glyph_len
< cmp
->glyph_len
)
25351 for (i
= 0; i
< glyph_len
; i
++)
25353 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25355 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25360 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25361 : IT_CHARPOS (*it
));
25362 /* If no suitable font is found, use the default font. */
25363 font_not_found_p
= font
== NULL
;
25364 if (font_not_found_p
)
25366 face
= face
->ascii_face
;
25369 boff
= font
->baseline_offset
;
25370 if (font
->vertical_centering
)
25371 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25372 font_ascent
= FONT_BASE (font
) + boff
;
25373 font_descent
= FONT_DESCENT (font
) - boff
;
25374 font_height
= FONT_HEIGHT (font
);
25379 if (! font_not_found_p
)
25381 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25383 pcm
= get_per_char_metric (font
, &char2b
);
25386 /* Initialize the bounding box. */
25389 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25390 ascent
= pcm
->ascent
;
25391 descent
= pcm
->descent
;
25392 lbearing
= pcm
->lbearing
;
25393 rbearing
= pcm
->rbearing
;
25397 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25398 ascent
= FONT_BASE (font
);
25399 descent
= FONT_DESCENT (font
);
25406 lowest
= - descent
+ boff
;
25407 highest
= ascent
+ boff
;
25409 if (! font_not_found_p
25410 && font
->default_ascent
25411 && CHAR_TABLE_P (Vuse_default_ascent
)
25412 && !NILP (Faref (Vuse_default_ascent
,
25413 make_number (it
->char_to_display
))))
25414 highest
= font
->default_ascent
+ boff
;
25416 /* Draw the first glyph at the normal position. It may be
25417 shifted to right later if some other glyphs are drawn
25419 cmp
->offsets
[i
* 2] = 0;
25420 cmp
->offsets
[i
* 2 + 1] = boff
;
25421 cmp
->lbearing
= lbearing
;
25422 cmp
->rbearing
= rbearing
;
25424 /* Set cmp->offsets for the remaining glyphs. */
25425 for (i
++; i
< glyph_len
; i
++)
25427 int left
, right
, btm
, top
;
25428 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25430 struct face
*this_face
;
25434 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25435 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25436 font
= this_face
->font
;
25442 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25444 pcm
= get_per_char_metric (font
, &char2b
);
25447 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25450 width
= pcm
->width
;
25451 ascent
= pcm
->ascent
;
25452 descent
= pcm
->descent
;
25453 lbearing
= pcm
->lbearing
;
25454 rbearing
= pcm
->rbearing
;
25455 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25457 /* Relative composition with or without
25458 alternate chars. */
25459 left
= (leftmost
+ rightmost
- width
) / 2;
25460 btm
= - descent
+ boff
;
25461 if (font
->relative_compose
25462 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25463 || NILP (Faref (Vignore_relative_composition
,
25464 make_number (ch
)))))
25467 if (- descent
>= font
->relative_compose
)
25468 /* One extra pixel between two glyphs. */
25470 else if (ascent
<= 0)
25471 /* One extra pixel between two glyphs. */
25472 btm
= lowest
- 1 - ascent
- descent
;
25477 /* A composition rule is specified by an integer
25478 value that encodes global and new reference
25479 points (GREF and NREF). GREF and NREF are
25480 specified by numbers as below:
25482 0---1---2 -- ascent
25486 9--10--11 -- center
25488 ---3---4---5--- baseline
25490 6---7---8 -- descent
25492 int rule
= COMPOSITION_RULE (cmp
, i
);
25493 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25495 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25496 grefx
= gref
% 3, nrefx
= nref
% 3;
25497 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25499 xoff
= font_height
* (xoff
- 128) / 256;
25501 yoff
= font_height
* (yoff
- 128) / 256;
25504 + grefx
* (rightmost
- leftmost
) / 2
25505 - nrefx
* width
/ 2
25508 btm
= ((grefy
== 0 ? highest
25510 : grefy
== 2 ? lowest
25511 : (highest
+ lowest
) / 2)
25512 - (nrefy
== 0 ? ascent
+ descent
25513 : nrefy
== 1 ? descent
- boff
25515 : (ascent
+ descent
) / 2)
25519 cmp
->offsets
[i
* 2] = left
;
25520 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25522 /* Update the bounding box of the overall glyphs. */
25525 right
= left
+ width
;
25526 if (left
< leftmost
)
25528 if (right
> rightmost
)
25531 top
= btm
+ descent
+ ascent
;
25537 if (cmp
->lbearing
> left
+ lbearing
)
25538 cmp
->lbearing
= left
+ lbearing
;
25539 if (cmp
->rbearing
< left
+ rbearing
)
25540 cmp
->rbearing
= left
+ rbearing
;
25544 /* If there are glyphs whose x-offsets are negative,
25545 shift all glyphs to the right and make all x-offsets
25549 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25550 cmp
->offsets
[i
* 2] -= leftmost
;
25551 rightmost
-= leftmost
;
25552 cmp
->lbearing
-= leftmost
;
25553 cmp
->rbearing
-= leftmost
;
25556 if (left_padded
&& cmp
->lbearing
< 0)
25558 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25559 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25560 rightmost
-= cmp
->lbearing
;
25561 cmp
->rbearing
-= cmp
->lbearing
;
25564 if (right_padded
&& rightmost
< cmp
->rbearing
)
25566 rightmost
= cmp
->rbearing
;
25569 cmp
->pixel_width
= rightmost
;
25570 cmp
->ascent
= highest
;
25571 cmp
->descent
= - lowest
;
25572 if (cmp
->ascent
< font_ascent
)
25573 cmp
->ascent
= font_ascent
;
25574 if (cmp
->descent
< font_descent
)
25575 cmp
->descent
= font_descent
;
25579 && (cmp
->lbearing
< 0
25580 || cmp
->rbearing
> cmp
->pixel_width
))
25581 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25583 it
->pixel_width
= cmp
->pixel_width
;
25584 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25585 it
->descent
= it
->phys_descent
= cmp
->descent
;
25586 if (face
->box
!= FACE_NO_BOX
)
25588 int thick
= face
->box_line_width
;
25592 it
->ascent
+= thick
;
25593 it
->descent
+= thick
;
25598 if (it
->start_of_box_run_p
)
25599 it
->pixel_width
+= thick
;
25600 if (it
->end_of_box_run_p
)
25601 it
->pixel_width
+= thick
;
25604 /* If face has an overline, add the height of the overline
25605 (1 pixel) and a 1 pixel margin to the character height. */
25606 if (face
->overline_p
)
25607 it
->ascent
+= overline_margin
;
25609 take_vertical_position_into_account (it
);
25610 if (it
->ascent
< 0)
25612 if (it
->descent
< 0)
25615 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25616 append_composite_glyph (it
);
25618 else if (it
->what
== IT_COMPOSITION
)
25620 /* A dynamic (automatic) composition. */
25621 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25622 Lisp_Object gstring
;
25623 struct font_metrics metrics
;
25627 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25629 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25632 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25633 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25634 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25635 it
->descent
= it
->phys_descent
= metrics
.descent
;
25636 if (face
->box
!= FACE_NO_BOX
)
25638 int thick
= face
->box_line_width
;
25642 it
->ascent
+= thick
;
25643 it
->descent
+= thick
;
25648 if (it
->start_of_box_run_p
)
25649 it
->pixel_width
+= thick
;
25650 if (it
->end_of_box_run_p
)
25651 it
->pixel_width
+= thick
;
25653 /* If face has an overline, add the height of the overline
25654 (1 pixel) and a 1 pixel margin to the character height. */
25655 if (face
->overline_p
)
25656 it
->ascent
+= overline_margin
;
25657 take_vertical_position_into_account (it
);
25658 if (it
->ascent
< 0)
25660 if (it
->descent
< 0)
25664 append_composite_glyph (it
);
25666 else if (it
->what
== IT_GLYPHLESS
)
25667 produce_glyphless_glyph (it
, 0, Qnil
);
25668 else if (it
->what
== IT_IMAGE
)
25669 produce_image_glyph (it
);
25670 else if (it
->what
== IT_STRETCH
)
25671 produce_stretch_glyph (it
);
25674 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25675 because this isn't true for images with `:ascent 100'. */
25676 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25677 if (it
->area
== TEXT_AREA
)
25678 it
->current_x
+= it
->pixel_width
;
25680 if (extra_line_spacing
> 0)
25682 it
->descent
+= extra_line_spacing
;
25683 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25684 it
->max_extra_line_spacing
= extra_line_spacing
;
25687 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25688 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25689 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25690 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25694 Output LEN glyphs starting at START at the nominal cursor position.
25695 Advance the nominal cursor over the text. UPDATED_ROW is the glyph row
25696 being updated, and UPDATED_AREA is the area of that row being updated. */
25699 x_write_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25700 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25702 int x
, hpos
, chpos
= w
->phys_cursor
.hpos
;
25704 eassert (updated_row
);
25705 /* When the window is hscrolled, cursor hpos can legitimately be out
25706 of bounds, but we draw the cursor at the corresponding window
25707 margin in that case. */
25708 if (!updated_row
->reversed_p
&& chpos
< 0)
25710 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25711 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25715 /* Write glyphs. */
25717 hpos
= start
- updated_row
->glyphs
[updated_area
];
25718 x
= draw_glyphs (w
, w
->output_cursor
.x
,
25719 updated_row
, updated_area
,
25721 DRAW_NORMAL_TEXT
, 0);
25723 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25724 if (updated_area
== TEXT_AREA
25725 && w
->phys_cursor_on_p
25726 && w
->phys_cursor
.vpos
== w
->output_cursor
.vpos
25728 && chpos
< hpos
+ len
)
25729 w
->phys_cursor_on_p
= 0;
25733 /* Advance the output cursor. */
25734 w
->output_cursor
.hpos
+= len
;
25735 w
->output_cursor
.x
= x
;
25740 Insert LEN glyphs from START at the nominal cursor position. */
25743 x_insert_glyphs (struct window
*w
, struct glyph_row
*updated_row
,
25744 struct glyph
*start
, enum glyph_row_area updated_area
, int len
)
25747 int line_height
, shift_by_width
, shifted_region_width
;
25748 struct glyph_row
*row
;
25749 struct glyph
*glyph
;
25750 int frame_x
, frame_y
;
25753 eassert (updated_row
);
25755 f
= XFRAME (WINDOW_FRAME (w
));
25757 /* Get the height of the line we are in. */
25759 line_height
= row
->height
;
25761 /* Get the width of the glyphs to insert. */
25762 shift_by_width
= 0;
25763 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25764 shift_by_width
+= glyph
->pixel_width
;
25766 /* Get the width of the region to shift right. */
25767 shifted_region_width
= (window_box_width (w
, updated_area
)
25768 - w
->output_cursor
.x
25772 frame_x
= window_box_left (w
, updated_area
) + w
->output_cursor
.x
;
25773 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, w
->output_cursor
.y
);
25775 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25776 line_height
, shift_by_width
);
25778 /* Write the glyphs. */
25779 hpos
= start
- row
->glyphs
[updated_area
];
25780 draw_glyphs (w
, w
->output_cursor
.x
, row
, updated_area
,
25782 DRAW_NORMAL_TEXT
, 0);
25784 /* Advance the output cursor. */
25785 w
->output_cursor
.hpos
+= len
;
25786 w
->output_cursor
.x
+= shift_by_width
;
25792 Erase the current text line from the nominal cursor position
25793 (inclusive) to pixel column TO_X (exclusive). The idea is that
25794 everything from TO_X onward is already erased.
25796 TO_X is a pixel position relative to UPDATED_AREA of currently
25797 updated window W. TO_X == -1 means clear to the end of this area. */
25800 x_clear_end_of_line (struct window
*w
, struct glyph_row
*updated_row
,
25801 enum glyph_row_area updated_area
, int to_x
)
25804 int max_x
, min_y
, max_y
;
25805 int from_x
, from_y
, to_y
;
25807 eassert (updated_row
);
25808 f
= XFRAME (w
->frame
);
25810 if (updated_row
->full_width_p
)
25811 max_x
= WINDOW_TOTAL_WIDTH (w
);
25813 max_x
= window_box_width (w
, updated_area
);
25814 max_y
= window_text_bottom_y (w
);
25816 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25817 of window. For TO_X > 0, truncate to end of drawing area. */
25823 to_x
= min (to_x
, max_x
);
25825 to_y
= min (max_y
, w
->output_cursor
.y
+ updated_row
->height
);
25827 /* Notice if the cursor will be cleared by this operation. */
25828 if (!updated_row
->full_width_p
)
25829 notice_overwritten_cursor (w
, updated_area
,
25830 w
->output_cursor
.x
, -1,
25832 MATRIX_ROW_BOTTOM_Y (updated_row
));
25834 from_x
= w
->output_cursor
.x
;
25836 /* Translate to frame coordinates. */
25837 if (updated_row
->full_width_p
)
25839 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25840 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25844 int area_left
= window_box_left (w
, updated_area
);
25845 from_x
+= area_left
;
25849 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25850 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, w
->output_cursor
.y
));
25851 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25853 /* Prevent inadvertently clearing to end of the X window. */
25854 if (to_x
> from_x
&& to_y
> from_y
)
25857 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25858 to_x
- from_x
, to_y
- from_y
);
25863 #endif /* HAVE_WINDOW_SYSTEM */
25867 /***********************************************************************
25869 ***********************************************************************/
25871 /* Value is the internal representation of the specified cursor type
25872 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25873 of the bar cursor. */
25875 static enum text_cursor_kinds
25876 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25878 enum text_cursor_kinds type
;
25883 if (EQ (arg
, Qbox
))
25884 return FILLED_BOX_CURSOR
;
25886 if (EQ (arg
, Qhollow
))
25887 return HOLLOW_BOX_CURSOR
;
25889 if (EQ (arg
, Qbar
))
25896 && EQ (XCAR (arg
), Qbar
)
25897 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25899 *width
= XINT (XCDR (arg
));
25903 if (EQ (arg
, Qhbar
))
25906 return HBAR_CURSOR
;
25910 && EQ (XCAR (arg
), Qhbar
)
25911 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25913 *width
= XINT (XCDR (arg
));
25914 return HBAR_CURSOR
;
25917 /* Treat anything unknown as "hollow box cursor".
25918 It was bad to signal an error; people have trouble fixing
25919 .Xdefaults with Emacs, when it has something bad in it. */
25920 type
= HOLLOW_BOX_CURSOR
;
25925 /* Set the default cursor types for specified frame. */
25927 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
25932 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
25933 FRAME_CURSOR_WIDTH (f
) = width
;
25935 /* By default, set up the blink-off state depending on the on-state. */
25937 tem
= Fassoc (arg
, Vblink_cursor_alist
);
25940 FRAME_BLINK_OFF_CURSOR (f
)
25941 = get_specified_cursor_type (XCDR (tem
), &width
);
25942 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
25945 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
25947 /* Make sure the cursor gets redrawn. */
25948 f
->cursor_type_changed
= 1;
25952 #ifdef HAVE_WINDOW_SYSTEM
25954 /* Return the cursor we want to be displayed in window W. Return
25955 width of bar/hbar cursor through WIDTH arg. Return with
25956 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
25957 (i.e. if the `system caret' should track this cursor).
25959 In a mini-buffer window, we want the cursor only to appear if we
25960 are reading input from this window. For the selected window, we
25961 want the cursor type given by the frame parameter or buffer local
25962 setting of cursor-type. If explicitly marked off, draw no cursor.
25963 In all other cases, we want a hollow box cursor. */
25965 static enum text_cursor_kinds
25966 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
25967 int *active_cursor
)
25969 struct frame
*f
= XFRAME (w
->frame
);
25970 struct buffer
*b
= XBUFFER (w
->contents
);
25971 int cursor_type
= DEFAULT_CURSOR
;
25972 Lisp_Object alt_cursor
;
25973 int non_selected
= 0;
25975 *active_cursor
= 1;
25978 if (cursor_in_echo_area
25979 && FRAME_HAS_MINIBUF_P (f
)
25980 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
25982 if (w
== XWINDOW (echo_area_window
))
25984 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
25986 *width
= FRAME_CURSOR_WIDTH (f
);
25987 return FRAME_DESIRED_CURSOR (f
);
25990 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
25993 *active_cursor
= 0;
25997 /* Detect a nonselected window or nonselected frame. */
25998 else if (w
!= XWINDOW (f
->selected_window
)
25999 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
26001 *active_cursor
= 0;
26003 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26009 /* Never display a cursor in a window in which cursor-type is nil. */
26010 if (NILP (BVAR (b
, cursor_type
)))
26013 /* Get the normal cursor type for this window. */
26014 if (EQ (BVAR (b
, cursor_type
), Qt
))
26016 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26017 *width
= FRAME_CURSOR_WIDTH (f
);
26020 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26022 /* Use cursor-in-non-selected-windows instead
26023 for non-selected window or frame. */
26026 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26027 if (!EQ (Qt
, alt_cursor
))
26028 return get_specified_cursor_type (alt_cursor
, width
);
26029 /* t means modify the normal cursor type. */
26030 if (cursor_type
== FILLED_BOX_CURSOR
)
26031 cursor_type
= HOLLOW_BOX_CURSOR
;
26032 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26034 return cursor_type
;
26037 /* Use normal cursor if not blinked off. */
26038 if (!w
->cursor_off_p
)
26040 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26042 if (cursor_type
== FILLED_BOX_CURSOR
)
26044 /* Using a block cursor on large images can be very annoying.
26045 So use a hollow cursor for "large" images.
26046 If image is not transparent (no mask), also use hollow cursor. */
26047 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26048 if (img
!= NULL
&& IMAGEP (img
->spec
))
26050 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26051 where N = size of default frame font size.
26052 This should cover most of the "tiny" icons people may use. */
26054 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26055 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26056 cursor_type
= HOLLOW_BOX_CURSOR
;
26059 else if (cursor_type
!= NO_CURSOR
)
26061 /* Display current only supports BOX and HOLLOW cursors for images.
26062 So for now, unconditionally use a HOLLOW cursor when cursor is
26063 not a solid box cursor. */
26064 cursor_type
= HOLLOW_BOX_CURSOR
;
26067 return cursor_type
;
26070 /* Cursor is blinked off, so determine how to "toggle" it. */
26072 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26073 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26074 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26076 /* Then see if frame has specified a specific blink off cursor type. */
26077 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26079 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26080 return FRAME_BLINK_OFF_CURSOR (f
);
26084 /* Some people liked having a permanently visible blinking cursor,
26085 while others had very strong opinions against it. So it was
26086 decided to remove it. KFS 2003-09-03 */
26088 /* Finally perform built-in cursor blinking:
26089 filled box <-> hollow box
26090 wide [h]bar <-> narrow [h]bar
26091 narrow [h]bar <-> no cursor
26092 other type <-> no cursor */
26094 if (cursor_type
== FILLED_BOX_CURSOR
)
26095 return HOLLOW_BOX_CURSOR
;
26097 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26100 return cursor_type
;
26108 /* Notice when the text cursor of window W has been completely
26109 overwritten by a drawing operation that outputs glyphs in AREA
26110 starting at X0 and ending at X1 in the line starting at Y0 and
26111 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26112 the rest of the line after X0 has been written. Y coordinates
26113 are window-relative. */
26116 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26117 int x0
, int x1
, int y0
, int y1
)
26119 int cx0
, cx1
, cy0
, cy1
;
26120 struct glyph_row
*row
;
26122 if (!w
->phys_cursor_on_p
)
26124 if (area
!= TEXT_AREA
)
26127 if (w
->phys_cursor
.vpos
< 0
26128 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26129 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26130 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26133 if (row
->cursor_in_fringe_p
)
26135 row
->cursor_in_fringe_p
= 0;
26136 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26137 w
->phys_cursor_on_p
= 0;
26141 cx0
= w
->phys_cursor
.x
;
26142 cx1
= cx0
+ w
->phys_cursor_width
;
26143 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26146 /* The cursor image will be completely removed from the
26147 screen if the output area intersects the cursor area in
26148 y-direction. When we draw in [y0 y1[, and some part of
26149 the cursor is at y < y0, that part must have been drawn
26150 before. When scrolling, the cursor is erased before
26151 actually scrolling, so we don't come here. When not
26152 scrolling, the rows above the old cursor row must have
26153 changed, and in this case these rows must have written
26154 over the cursor image.
26156 Likewise if part of the cursor is below y1, with the
26157 exception of the cursor being in the first blank row at
26158 the buffer and window end because update_text_area
26159 doesn't draw that row. (Except when it does, but
26160 that's handled in update_text_area.) */
26162 cy0
= w
->phys_cursor
.y
;
26163 cy1
= cy0
+ w
->phys_cursor_height
;
26164 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26167 w
->phys_cursor_on_p
= 0;
26170 #endif /* HAVE_WINDOW_SYSTEM */
26173 /************************************************************************
26175 ************************************************************************/
26177 #ifdef HAVE_WINDOW_SYSTEM
26180 Fix the display of area AREA of overlapping row ROW in window W
26181 with respect to the overlapping part OVERLAPS. */
26184 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26185 enum glyph_row_area area
, int overlaps
)
26192 for (i
= 0; i
< row
->used
[area
];)
26194 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26196 int start
= i
, start_x
= x
;
26200 x
+= row
->glyphs
[area
][i
].pixel_width
;
26203 while (i
< row
->used
[area
]
26204 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26206 draw_glyphs (w
, start_x
, row
, area
,
26208 DRAW_NORMAL_TEXT
, overlaps
);
26212 x
+= row
->glyphs
[area
][i
].pixel_width
;
26222 Draw the cursor glyph of window W in glyph row ROW. See the
26223 comment of draw_glyphs for the meaning of HL. */
26226 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26227 enum draw_glyphs_face hl
)
26229 /* If cursor hpos is out of bounds, don't draw garbage. This can
26230 happen in mini-buffer windows when switching between echo area
26231 glyphs and mini-buffer. */
26232 if ((row
->reversed_p
26233 ? (w
->phys_cursor
.hpos
>= 0)
26234 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26236 int on_p
= w
->phys_cursor_on_p
;
26238 int hpos
= w
->phys_cursor
.hpos
;
26240 /* When the window is hscrolled, cursor hpos can legitimately be
26241 out of bounds, but we draw the cursor at the corresponding
26242 window margin in that case. */
26243 if (!row
->reversed_p
&& hpos
< 0)
26245 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26246 hpos
= row
->used
[TEXT_AREA
] - 1;
26248 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26250 w
->phys_cursor_on_p
= on_p
;
26252 if (hl
== DRAW_CURSOR
)
26253 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26254 /* When we erase the cursor, and ROW is overlapped by other
26255 rows, make sure that these overlapping parts of other rows
26257 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26259 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26261 if (row
> w
->current_matrix
->rows
26262 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26263 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26264 OVERLAPS_ERASED_CURSOR
);
26266 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26267 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26268 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26269 OVERLAPS_ERASED_CURSOR
);
26276 Erase the image of a cursor of window W from the screen. */
26279 erase_phys_cursor (struct window
*w
)
26281 struct frame
*f
= XFRAME (w
->frame
);
26282 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26283 int hpos
= w
->phys_cursor
.hpos
;
26284 int vpos
= w
->phys_cursor
.vpos
;
26285 int mouse_face_here_p
= 0;
26286 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26287 struct glyph_row
*cursor_row
;
26288 struct glyph
*cursor_glyph
;
26289 enum draw_glyphs_face hl
;
26291 /* No cursor displayed or row invalidated => nothing to do on the
26293 if (w
->phys_cursor_type
== NO_CURSOR
)
26294 goto mark_cursor_off
;
26296 /* VPOS >= active_glyphs->nrows means that window has been resized.
26297 Don't bother to erase the cursor. */
26298 if (vpos
>= active_glyphs
->nrows
)
26299 goto mark_cursor_off
;
26301 /* If row containing cursor is marked invalid, there is nothing we
26303 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26304 if (!cursor_row
->enabled_p
)
26305 goto mark_cursor_off
;
26307 /* If line spacing is > 0, old cursor may only be partially visible in
26308 window after split-window. So adjust visible height. */
26309 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26310 window_text_bottom_y (w
) - cursor_row
->y
);
26312 /* If row is completely invisible, don't attempt to delete a cursor which
26313 isn't there. This can happen if cursor is at top of a window, and
26314 we switch to a buffer with a header line in that window. */
26315 if (cursor_row
->visible_height
<= 0)
26316 goto mark_cursor_off
;
26318 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26319 if (cursor_row
->cursor_in_fringe_p
)
26321 cursor_row
->cursor_in_fringe_p
= 0;
26322 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26323 goto mark_cursor_off
;
26326 /* This can happen when the new row is shorter than the old one.
26327 In this case, either draw_glyphs or clear_end_of_line
26328 should have cleared the cursor. Note that we wouldn't be
26329 able to erase the cursor in this case because we don't have a
26330 cursor glyph at hand. */
26331 if ((cursor_row
->reversed_p
26332 ? (w
->phys_cursor
.hpos
< 0)
26333 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26334 goto mark_cursor_off
;
26336 /* When the window is hscrolled, cursor hpos can legitimately be out
26337 of bounds, but we draw the cursor at the corresponding window
26338 margin in that case. */
26339 if (!cursor_row
->reversed_p
&& hpos
< 0)
26341 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26342 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26344 /* If the cursor is in the mouse face area, redisplay that when
26345 we clear the cursor. */
26346 if (! NILP (hlinfo
->mouse_face_window
)
26347 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26348 /* Don't redraw the cursor's spot in mouse face if it is at the
26349 end of a line (on a newline). The cursor appears there, but
26350 mouse highlighting does not. */
26351 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26352 mouse_face_here_p
= 1;
26354 /* Maybe clear the display under the cursor. */
26355 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26358 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26361 cursor_glyph
= get_phys_cursor_glyph (w
);
26362 if (cursor_glyph
== NULL
)
26363 goto mark_cursor_off
;
26365 width
= cursor_glyph
->pixel_width
;
26366 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26367 x
= w
->phys_cursor
.x
;
26369 width
-= left_x
- x
;
26370 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26371 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26372 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26375 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26378 /* Erase the cursor by redrawing the character underneath it. */
26379 if (mouse_face_here_p
)
26380 hl
= DRAW_MOUSE_FACE
;
26382 hl
= DRAW_NORMAL_TEXT
;
26383 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26386 w
->phys_cursor_on_p
= 0;
26387 w
->phys_cursor_type
= NO_CURSOR
;
26392 Display or clear cursor of window W. If ON is zero, clear the
26393 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26394 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26397 display_and_set_cursor (struct window
*w
, bool on
,
26398 int hpos
, int vpos
, int x
, int y
)
26400 struct frame
*f
= XFRAME (w
->frame
);
26401 int new_cursor_type
;
26402 int new_cursor_width
;
26404 struct glyph_row
*glyph_row
;
26405 struct glyph
*glyph
;
26407 /* This is pointless on invisible frames, and dangerous on garbaged
26408 windows and frames; in the latter case, the frame or window may
26409 be in the midst of changing its size, and x and y may be off the
26411 if (! FRAME_VISIBLE_P (f
)
26412 || FRAME_GARBAGED_P (f
)
26413 || vpos
>= w
->current_matrix
->nrows
26414 || hpos
>= w
->current_matrix
->matrix_w
)
26417 /* If cursor is off and we want it off, return quickly. */
26418 if (!on
&& !w
->phys_cursor_on_p
)
26421 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26422 /* If cursor row is not enabled, we don't really know where to
26423 display the cursor. */
26424 if (!glyph_row
->enabled_p
)
26426 w
->phys_cursor_on_p
= 0;
26431 if (!glyph_row
->exact_window_width_line_p
26432 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26433 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26435 eassert (input_blocked_p ());
26437 /* Set new_cursor_type to the cursor we want to be displayed. */
26438 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26439 &new_cursor_width
, &active_cursor
);
26441 /* If cursor is currently being shown and we don't want it to be or
26442 it is in the wrong place, or the cursor type is not what we want,
26444 if (w
->phys_cursor_on_p
26446 || w
->phys_cursor
.x
!= x
26447 || w
->phys_cursor
.y
!= y
26448 || new_cursor_type
!= w
->phys_cursor_type
26449 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26450 && new_cursor_width
!= w
->phys_cursor_width
)))
26451 erase_phys_cursor (w
);
26453 /* Don't check phys_cursor_on_p here because that flag is only set
26454 to zero in some cases where we know that the cursor has been
26455 completely erased, to avoid the extra work of erasing the cursor
26456 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26457 still not be visible, or it has only been partly erased. */
26460 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26461 w
->phys_cursor_height
= glyph_row
->height
;
26463 /* Set phys_cursor_.* before x_draw_.* is called because some
26464 of them may need the information. */
26465 w
->phys_cursor
.x
= x
;
26466 w
->phys_cursor
.y
= glyph_row
->y
;
26467 w
->phys_cursor
.hpos
= hpos
;
26468 w
->phys_cursor
.vpos
= vpos
;
26471 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26472 new_cursor_type
, new_cursor_width
,
26473 on
, active_cursor
);
26477 /* Switch the display of W's cursor on or off, according to the value
26481 update_window_cursor (struct window
*w
, bool on
)
26483 /* Don't update cursor in windows whose frame is in the process
26484 of being deleted. */
26485 if (w
->current_matrix
)
26487 int hpos
= w
->phys_cursor
.hpos
;
26488 int vpos
= w
->phys_cursor
.vpos
;
26489 struct glyph_row
*row
;
26491 if (vpos
>= w
->current_matrix
->nrows
26492 || hpos
>= w
->current_matrix
->matrix_w
)
26495 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26497 /* When the window is hscrolled, cursor hpos can legitimately be
26498 out of bounds, but we draw the cursor at the corresponding
26499 window margin in that case. */
26500 if (!row
->reversed_p
&& hpos
< 0)
26502 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26503 hpos
= row
->used
[TEXT_AREA
] - 1;
26506 display_and_set_cursor (w
, on
, hpos
, vpos
,
26507 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26513 /* Call update_window_cursor with parameter ON_P on all leaf windows
26514 in the window tree rooted at W. */
26517 update_cursor_in_window_tree (struct window
*w
, bool on_p
)
26521 if (WINDOWP (w
->contents
))
26522 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26524 update_window_cursor (w
, on_p
);
26526 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26532 Display the cursor on window W, or clear it, according to ON_P.
26533 Don't change the cursor's position. */
26536 x_update_cursor (struct frame
*f
, bool on_p
)
26538 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26543 Clear the cursor of window W to background color, and mark the
26544 cursor as not shown. This is used when the text where the cursor
26545 is about to be rewritten. */
26548 x_clear_cursor (struct window
*w
)
26550 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26551 update_window_cursor (w
, 0);
26554 #endif /* HAVE_WINDOW_SYSTEM */
26556 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26559 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26560 int start_hpos
, int end_hpos
,
26561 enum draw_glyphs_face draw
)
26563 #ifdef HAVE_WINDOW_SYSTEM
26564 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26566 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26570 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26571 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26575 /* Display the active region described by mouse_face_* according to DRAW. */
26578 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26580 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26581 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26583 if (/* If window is in the process of being destroyed, don't bother
26585 w
->current_matrix
!= NULL
26586 /* Don't update mouse highlight if hidden */
26587 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26588 /* Recognize when we are called to operate on rows that don't exist
26589 anymore. This can happen when a window is split. */
26590 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26592 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26593 struct glyph_row
*row
, *first
, *last
;
26595 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26596 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26598 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26600 int start_hpos
, end_hpos
, start_x
;
26602 /* For all but the first row, the highlight starts at column 0. */
26605 /* R2L rows have BEG and END in reversed order, but the
26606 screen drawing geometry is always left to right. So
26607 we need to mirror the beginning and end of the
26608 highlighted area in R2L rows. */
26609 if (!row
->reversed_p
)
26611 start_hpos
= hlinfo
->mouse_face_beg_col
;
26612 start_x
= hlinfo
->mouse_face_beg_x
;
26614 else if (row
== last
)
26616 start_hpos
= hlinfo
->mouse_face_end_col
;
26617 start_x
= hlinfo
->mouse_face_end_x
;
26625 else if (row
->reversed_p
&& row
== last
)
26627 start_hpos
= hlinfo
->mouse_face_end_col
;
26628 start_x
= hlinfo
->mouse_face_end_x
;
26638 if (!row
->reversed_p
)
26639 end_hpos
= hlinfo
->mouse_face_end_col
;
26640 else if (row
== first
)
26641 end_hpos
= hlinfo
->mouse_face_beg_col
;
26644 end_hpos
= row
->used
[TEXT_AREA
];
26645 if (draw
== DRAW_NORMAL_TEXT
)
26646 row
->fill_line_p
= 1; /* Clear to end of line */
26649 else if (row
->reversed_p
&& row
== first
)
26650 end_hpos
= hlinfo
->mouse_face_beg_col
;
26653 end_hpos
= row
->used
[TEXT_AREA
];
26654 if (draw
== DRAW_NORMAL_TEXT
)
26655 row
->fill_line_p
= 1; /* Clear to end of line */
26658 if (end_hpos
> start_hpos
)
26660 draw_row_with_mouse_face (w
, start_x
, row
,
26661 start_hpos
, end_hpos
, draw
);
26664 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26668 #ifdef HAVE_WINDOW_SYSTEM
26669 /* When we've written over the cursor, arrange for it to
26670 be displayed again. */
26671 if (FRAME_WINDOW_P (f
)
26672 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26674 int hpos
= w
->phys_cursor
.hpos
;
26676 /* When the window is hscrolled, cursor hpos can legitimately be
26677 out of bounds, but we draw the cursor at the corresponding
26678 window margin in that case. */
26679 if (!row
->reversed_p
&& hpos
< 0)
26681 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26682 hpos
= row
->used
[TEXT_AREA
] - 1;
26685 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26686 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26689 #endif /* HAVE_WINDOW_SYSTEM */
26692 #ifdef HAVE_WINDOW_SYSTEM
26693 /* Change the mouse cursor. */
26694 if (FRAME_WINDOW_P (f
))
26696 if (draw
== DRAW_NORMAL_TEXT
26697 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26698 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26699 else if (draw
== DRAW_MOUSE_FACE
)
26700 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26702 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26704 #endif /* HAVE_WINDOW_SYSTEM */
26708 Clear out the mouse-highlighted active region.
26709 Redraw it un-highlighted first. Value is non-zero if mouse
26710 face was actually drawn unhighlighted. */
26713 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26717 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26719 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26723 reset_mouse_highlight (hlinfo
);
26727 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26728 within the mouse face on that window. */
26730 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26732 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26734 /* Quickly resolve the easy cases. */
26735 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26736 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26738 if (vpos
< hlinfo
->mouse_face_beg_row
26739 || vpos
> hlinfo
->mouse_face_end_row
)
26741 if (vpos
> hlinfo
->mouse_face_beg_row
26742 && vpos
< hlinfo
->mouse_face_end_row
)
26745 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26747 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26749 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26752 else if ((vpos
== hlinfo
->mouse_face_beg_row
26753 && hpos
>= hlinfo
->mouse_face_beg_col
)
26754 || (vpos
== hlinfo
->mouse_face_end_row
26755 && hpos
< hlinfo
->mouse_face_end_col
))
26760 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26762 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26765 else if ((vpos
== hlinfo
->mouse_face_beg_row
26766 && hpos
<= hlinfo
->mouse_face_beg_col
)
26767 || (vpos
== hlinfo
->mouse_face_end_row
26768 && hpos
> hlinfo
->mouse_face_end_col
))
26776 Non-zero if physical cursor of window W is within mouse face. */
26779 cursor_in_mouse_face_p (struct window
*w
)
26781 int hpos
= w
->phys_cursor
.hpos
;
26782 int vpos
= w
->phys_cursor
.vpos
;
26783 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26785 /* When the window is hscrolled, cursor hpos can legitimately be out
26786 of bounds, but we draw the cursor at the corresponding window
26787 margin in that case. */
26788 if (!row
->reversed_p
&& hpos
< 0)
26790 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26791 hpos
= row
->used
[TEXT_AREA
] - 1;
26793 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26798 /* Find the glyph rows START_ROW and END_ROW of window W that display
26799 characters between buffer positions START_CHARPOS and END_CHARPOS
26800 (excluding END_CHARPOS). DISP_STRING is a display string that
26801 covers these buffer positions. This is similar to
26802 row_containing_pos, but is more accurate when bidi reordering makes
26803 buffer positions change non-linearly with glyph rows. */
26805 rows_from_pos_range (struct window
*w
,
26806 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26807 Lisp_Object disp_string
,
26808 struct glyph_row
**start
, struct glyph_row
**end
)
26810 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26811 int last_y
= window_text_bottom_y (w
);
26812 struct glyph_row
*row
;
26817 while (!first
->enabled_p
26818 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26821 /* Find the START row. */
26823 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26826 /* A row can potentially be the START row if the range of the
26827 characters it displays intersects the range
26828 [START_CHARPOS..END_CHARPOS). */
26829 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26830 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26831 /* See the commentary in row_containing_pos, for the
26832 explanation of the complicated way to check whether
26833 some position is beyond the end of the characters
26834 displayed by a row. */
26835 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26836 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26837 && !row
->ends_at_zv_p
26838 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26839 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26840 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26841 && !row
->ends_at_zv_p
26842 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26844 /* Found a candidate row. Now make sure at least one of the
26845 glyphs it displays has a charpos from the range
26846 [START_CHARPOS..END_CHARPOS).
26848 This is not obvious because bidi reordering could make
26849 buffer positions of a row be 1,2,3,102,101,100, and if we
26850 want to highlight characters in [50..60), we don't want
26851 this row, even though [50..60) does intersect [1..103),
26852 the range of character positions given by the row's start
26853 and end positions. */
26854 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26855 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26859 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26860 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26861 /* A glyph that comes from DISP_STRING is by
26862 definition to be highlighted. */
26863 || EQ (g
->object
, disp_string
))
26872 /* Find the END row. */
26874 /* If the last row is partially visible, start looking for END
26875 from that row, instead of starting from FIRST. */
26876 && !(row
->enabled_p
26877 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26879 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26881 struct glyph_row
*next
= row
+ 1;
26882 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26884 if (!next
->enabled_p
26885 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26886 /* The first row >= START whose range of displayed characters
26887 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26888 is the row END + 1. */
26889 || (start_charpos
< next_start
26890 && end_charpos
< next_start
)
26891 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26892 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26893 && !next
->ends_at_zv_p
26894 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26895 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26896 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26897 && !next
->ends_at_zv_p
26898 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26905 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26906 but none of the characters it displays are in the range, it is
26908 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26909 struct glyph
*s
= g
;
26910 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26914 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26915 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26916 /* If the buffer position of the first glyph in
26917 the row is equal to END_CHARPOS, it means
26918 the last character to be highlighted is the
26919 newline of ROW, and we must consider NEXT as
26921 || (((!next
->reversed_p
&& g
== s
)
26922 || (next
->reversed_p
&& g
== e
- 1))
26923 && (g
->charpos
== end_charpos
26924 /* Special case for when NEXT is an
26925 empty line at ZV. */
26926 || (g
->charpos
== -1
26927 && !row
->ends_at_zv_p
26928 && next_start
== end_charpos
)))))
26929 /* A glyph that comes from DISP_STRING is by
26930 definition to be highlighted. */
26931 || EQ (g
->object
, disp_string
))
26940 /* The first row that ends at ZV must be the last to be
26942 else if (next
->ends_at_zv_p
)
26951 /* This function sets the mouse_face_* elements of HLINFO, assuming
26952 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
26953 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
26954 for the overlay or run of text properties specifying the mouse
26955 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
26956 before-string and after-string that must also be highlighted.
26957 DISP_STRING, if non-nil, is a display string that may cover some
26958 or all of the highlighted text. */
26961 mouse_face_from_buffer_pos (Lisp_Object window
,
26962 Mouse_HLInfo
*hlinfo
,
26963 ptrdiff_t mouse_charpos
,
26964 ptrdiff_t start_charpos
,
26965 ptrdiff_t end_charpos
,
26966 Lisp_Object before_string
,
26967 Lisp_Object after_string
,
26968 Lisp_Object disp_string
)
26970 struct window
*w
= XWINDOW (window
);
26971 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26972 struct glyph_row
*r1
, *r2
;
26973 struct glyph
*glyph
, *end
;
26974 ptrdiff_t ignore
, pos
;
26977 eassert (NILP (disp_string
) || STRINGP (disp_string
));
26978 eassert (NILP (before_string
) || STRINGP (before_string
));
26979 eassert (NILP (after_string
) || STRINGP (after_string
));
26981 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
26982 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
26984 r1
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
26985 /* If the before-string or display-string contains newlines,
26986 rows_from_pos_range skips to its last row. Move back. */
26987 if (!NILP (before_string
) || !NILP (disp_string
))
26989 struct glyph_row
*prev
;
26990 while ((prev
= r1
- 1, prev
>= first
)
26991 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
26992 && prev
->used
[TEXT_AREA
] > 0)
26994 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
26995 glyph
= beg
+ prev
->used
[TEXT_AREA
];
26996 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
26998 || !(EQ (glyph
->object
, before_string
)
26999 || EQ (glyph
->object
, disp_string
)))
27006 r2
= MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27007 hlinfo
->mouse_face_past_end
= 1;
27009 else if (!NILP (after_string
))
27011 /* If the after-string has newlines, advance to its last row. */
27012 struct glyph_row
*next
;
27013 struct glyph_row
*last
27014 = MATRIX_ROW (w
->current_matrix
, w
->window_end_vpos
);
27016 for (next
= r2
+ 1;
27018 && next
->used
[TEXT_AREA
] > 0
27019 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27023 /* The rest of the display engine assumes that mouse_face_beg_row is
27024 either above mouse_face_end_row or identical to it. But with
27025 bidi-reordered continued lines, the row for START_CHARPOS could
27026 be below the row for END_CHARPOS. If so, swap the rows and store
27027 them in correct order. */
27030 struct glyph_row
*tem
= r2
;
27036 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27037 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27039 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27040 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27041 could be anywhere in the row and in any order. The strategy
27042 below is to find the leftmost and the rightmost glyph that
27043 belongs to either of these 3 strings, or whose position is
27044 between START_CHARPOS and END_CHARPOS, and highlight all the
27045 glyphs between those two. This may cover more than just the text
27046 between START_CHARPOS and END_CHARPOS if the range of characters
27047 strides the bidi level boundary, e.g. if the beginning is in R2L
27048 text while the end is in L2R text or vice versa. */
27049 if (!r1
->reversed_p
)
27051 /* This row is in a left to right paragraph. Scan it left to
27053 glyph
= r1
->glyphs
[TEXT_AREA
];
27054 end
= glyph
+ r1
->used
[TEXT_AREA
];
27057 /* Skip truncation glyphs at the start of the glyph row. */
27058 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27060 && INTEGERP (glyph
->object
)
27061 && glyph
->charpos
< 0;
27063 x
+= glyph
->pixel_width
;
27065 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27066 or DISP_STRING, and the first glyph from buffer whose
27067 position is between START_CHARPOS and END_CHARPOS. */
27069 && !INTEGERP (glyph
->object
)
27070 && !EQ (glyph
->object
, disp_string
)
27071 && !(BUFFERP (glyph
->object
)
27072 && (glyph
->charpos
>= start_charpos
27073 && glyph
->charpos
< end_charpos
));
27076 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27077 are present at buffer positions between START_CHARPOS and
27078 END_CHARPOS, or if they come from an overlay. */
27079 if (EQ (glyph
->object
, before_string
))
27081 pos
= string_buffer_position (before_string
,
27083 /* If pos == 0, it means before_string came from an
27084 overlay, not from a buffer position. */
27085 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27088 else if (EQ (glyph
->object
, after_string
))
27090 pos
= string_buffer_position (after_string
, end_charpos
);
27091 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27094 x
+= glyph
->pixel_width
;
27096 hlinfo
->mouse_face_beg_x
= x
;
27097 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27101 /* This row is in a right to left paragraph. Scan it right to
27105 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27106 glyph
= end
+ r1
->used
[TEXT_AREA
];
27108 /* Skip truncation glyphs at the start of the glyph row. */
27109 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27111 && INTEGERP (glyph
->object
)
27112 && glyph
->charpos
< 0;
27116 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27117 or DISP_STRING, and the first glyph from buffer whose
27118 position is between START_CHARPOS and END_CHARPOS. */
27120 && !INTEGERP (glyph
->object
)
27121 && !EQ (glyph
->object
, disp_string
)
27122 && !(BUFFERP (glyph
->object
)
27123 && (glyph
->charpos
>= start_charpos
27124 && glyph
->charpos
< end_charpos
));
27127 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27128 are present at buffer positions between START_CHARPOS and
27129 END_CHARPOS, or if they come from an overlay. */
27130 if (EQ (glyph
->object
, before_string
))
27132 pos
= string_buffer_position (before_string
, start_charpos
);
27133 /* If pos == 0, it means before_string came from an
27134 overlay, not from a buffer position. */
27135 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27138 else if (EQ (glyph
->object
, after_string
))
27140 pos
= string_buffer_position (after_string
, end_charpos
);
27141 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27146 glyph
++; /* first glyph to the right of the highlighted area */
27147 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27148 x
+= g
->pixel_width
;
27149 hlinfo
->mouse_face_beg_x
= x
;
27150 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27153 /* If the highlight ends in a different row, compute GLYPH and END
27154 for the end row. Otherwise, reuse the values computed above for
27155 the row where the highlight begins. */
27158 if (!r2
->reversed_p
)
27160 glyph
= r2
->glyphs
[TEXT_AREA
];
27161 end
= glyph
+ r2
->used
[TEXT_AREA
];
27166 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27167 glyph
= end
+ r2
->used
[TEXT_AREA
];
27171 if (!r2
->reversed_p
)
27173 /* Skip truncation and continuation glyphs near the end of the
27174 row, and also blanks and stretch glyphs inserted by
27175 extend_face_to_end_of_line. */
27177 && INTEGERP ((end
- 1)->object
))
27179 /* Scan the rest of the glyph row from the end, looking for the
27180 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27181 DISP_STRING, or whose position is between START_CHARPOS
27185 && !INTEGERP (end
->object
)
27186 && !EQ (end
->object
, disp_string
)
27187 && !(BUFFERP (end
->object
)
27188 && (end
->charpos
>= start_charpos
27189 && end
->charpos
< end_charpos
));
27192 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27193 are present at buffer positions between START_CHARPOS and
27194 END_CHARPOS, or if they come from an overlay. */
27195 if (EQ (end
->object
, before_string
))
27197 pos
= string_buffer_position (before_string
, start_charpos
);
27198 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27201 else if (EQ (end
->object
, after_string
))
27203 pos
= string_buffer_position (after_string
, end_charpos
);
27204 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27208 /* Find the X coordinate of the last glyph to be highlighted. */
27209 for (; glyph
<= end
; ++glyph
)
27210 x
+= glyph
->pixel_width
;
27212 hlinfo
->mouse_face_end_x
= x
;
27213 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27217 /* Skip truncation and continuation glyphs near the end of the
27218 row, and also blanks and stretch glyphs inserted by
27219 extend_face_to_end_of_line. */
27223 && INTEGERP (end
->object
))
27225 x
+= end
->pixel_width
;
27228 /* Scan the rest of the glyph row from the end, looking for the
27229 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27230 DISP_STRING, or whose position is between START_CHARPOS
27234 && !INTEGERP (end
->object
)
27235 && !EQ (end
->object
, disp_string
)
27236 && !(BUFFERP (end
->object
)
27237 && (end
->charpos
>= start_charpos
27238 && end
->charpos
< end_charpos
));
27241 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27242 are present at buffer positions between START_CHARPOS and
27243 END_CHARPOS, or if they come from an overlay. */
27244 if (EQ (end
->object
, before_string
))
27246 pos
= string_buffer_position (before_string
, start_charpos
);
27247 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27250 else if (EQ (end
->object
, after_string
))
27252 pos
= string_buffer_position (after_string
, end_charpos
);
27253 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27256 x
+= end
->pixel_width
;
27258 /* If we exited the above loop because we arrived at the last
27259 glyph of the row, and its buffer position is still not in
27260 range, it means the last character in range is the preceding
27261 newline. Bump the end column and x values to get past the
27264 && BUFFERP (end
->object
)
27265 && (end
->charpos
< start_charpos
27266 || end
->charpos
>= end_charpos
))
27268 x
+= end
->pixel_width
;
27271 hlinfo
->mouse_face_end_x
= x
;
27272 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27275 hlinfo
->mouse_face_window
= window
;
27276 hlinfo
->mouse_face_face_id
27277 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27279 !hlinfo
->mouse_face_hidden
, -1);
27280 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27283 /* The following function is not used anymore (replaced with
27284 mouse_face_from_string_pos), but I leave it here for the time
27285 being, in case someone would. */
27287 #if 0 /* not used */
27289 /* Find the position of the glyph for position POS in OBJECT in
27290 window W's current matrix, and return in *X, *Y the pixel
27291 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27293 RIGHT_P non-zero means return the position of the right edge of the
27294 glyph, RIGHT_P zero means return the left edge position.
27296 If no glyph for POS exists in the matrix, return the position of
27297 the glyph with the next smaller position that is in the matrix, if
27298 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27299 exists in the matrix, return the position of the glyph with the
27300 next larger position in OBJECT.
27302 Value is non-zero if a glyph was found. */
27305 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27306 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27308 int yb
= window_text_bottom_y (w
);
27309 struct glyph_row
*r
;
27310 struct glyph
*best_glyph
= NULL
;
27311 struct glyph_row
*best_row
= NULL
;
27314 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27315 r
->enabled_p
&& r
->y
< yb
;
27318 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27319 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27322 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27323 if (EQ (g
->object
, object
))
27325 if (g
->charpos
== pos
)
27332 else if (best_glyph
== NULL
27333 || ((eabs (g
->charpos
- pos
)
27334 < eabs (best_glyph
->charpos
- pos
))
27337 : g
->charpos
> pos
)))
27351 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27355 *x
+= best_glyph
->pixel_width
;
27360 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27363 return best_glyph
!= NULL
;
27365 #endif /* not used */
27367 /* Find the positions of the first and the last glyphs in window W's
27368 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27369 (assumed to be a string), and return in HLINFO's mouse_face_*
27370 members the pixel and column/row coordinates of those glyphs. */
27373 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27374 Lisp_Object object
,
27375 ptrdiff_t startpos
, ptrdiff_t endpos
)
27377 int yb
= window_text_bottom_y (w
);
27378 struct glyph_row
*r
;
27379 struct glyph
*g
, *e
;
27383 /* Find the glyph row with at least one position in the range
27384 [STARTPOS..ENDPOS], and the first glyph in that row whose
27385 position belongs to that range. */
27386 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27387 r
->enabled_p
&& r
->y
< yb
;
27390 if (!r
->reversed_p
)
27392 g
= r
->glyphs
[TEXT_AREA
];
27393 e
= g
+ r
->used
[TEXT_AREA
];
27394 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27395 if (EQ (g
->object
, object
)
27396 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27398 hlinfo
->mouse_face_beg_row
27399 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27400 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27401 hlinfo
->mouse_face_beg_x
= gx
;
27410 e
= r
->glyphs
[TEXT_AREA
];
27411 g
= e
+ r
->used
[TEXT_AREA
];
27412 for ( ; g
> e
; --g
)
27413 if (EQ ((g
-1)->object
, object
)
27414 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27416 hlinfo
->mouse_face_beg_row
27417 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27418 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27419 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27420 gx
+= g1
->pixel_width
;
27421 hlinfo
->mouse_face_beg_x
= gx
;
27433 /* Starting with the next row, look for the first row which does NOT
27434 include any glyphs whose positions are in the range. */
27435 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27437 g
= r
->glyphs
[TEXT_AREA
];
27438 e
= g
+ r
->used
[TEXT_AREA
];
27440 for ( ; g
< e
; ++g
)
27441 if (EQ (g
->object
, object
)
27442 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27451 /* The highlighted region ends on the previous row. */
27454 /* Set the end row. */
27455 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27457 /* Compute and set the end column and the end column's horizontal
27458 pixel coordinate. */
27459 if (!r
->reversed_p
)
27461 g
= r
->glyphs
[TEXT_AREA
];
27462 e
= g
+ r
->used
[TEXT_AREA
];
27463 for ( ; e
> g
; --e
)
27464 if (EQ ((e
-1)->object
, object
)
27465 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27467 hlinfo
->mouse_face_end_col
= e
- g
;
27469 for (gx
= r
->x
; g
< e
; ++g
)
27470 gx
+= g
->pixel_width
;
27471 hlinfo
->mouse_face_end_x
= gx
;
27475 e
= r
->glyphs
[TEXT_AREA
];
27476 g
= e
+ r
->used
[TEXT_AREA
];
27477 for (gx
= r
->x
; e
< g
; ++e
)
27479 if (EQ (e
->object
, object
)
27480 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27482 gx
+= e
->pixel_width
;
27484 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27485 hlinfo
->mouse_face_end_x
= gx
;
27489 #ifdef HAVE_WINDOW_SYSTEM
27491 /* See if position X, Y is within a hot-spot of an image. */
27494 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27496 if (!CONSP (hot_spot
))
27499 if (EQ (XCAR (hot_spot
), Qrect
))
27501 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27502 Lisp_Object rect
= XCDR (hot_spot
);
27506 if (!CONSP (XCAR (rect
)))
27508 if (!CONSP (XCDR (rect
)))
27510 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27512 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27514 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27516 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27520 else if (EQ (XCAR (hot_spot
), Qcircle
))
27522 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27523 Lisp_Object circ
= XCDR (hot_spot
);
27524 Lisp_Object lr
, lx0
, ly0
;
27526 && CONSP (XCAR (circ
))
27527 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27528 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27529 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27531 double r
= XFLOATINT (lr
);
27532 double dx
= XINT (lx0
) - x
;
27533 double dy
= XINT (ly0
) - y
;
27534 return (dx
* dx
+ dy
* dy
<= r
* r
);
27537 else if (EQ (XCAR (hot_spot
), Qpoly
))
27539 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27540 if (VECTORP (XCDR (hot_spot
)))
27542 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27543 Lisp_Object
*poly
= v
->contents
;
27544 ptrdiff_t n
= v
->header
.size
;
27547 Lisp_Object lx
, ly
;
27550 /* Need an even number of coordinates, and at least 3 edges. */
27551 if (n
< 6 || n
& 1)
27554 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27555 If count is odd, we are inside polygon. Pixels on edges
27556 may or may not be included depending on actual geometry of the
27558 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27559 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27561 x0
= XINT (lx
), y0
= XINT (ly
);
27562 for (i
= 0; i
< n
; i
+= 2)
27564 int x1
= x0
, y1
= y0
;
27565 if ((lx
= poly
[i
], !INTEGERP (lx
))
27566 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27568 x0
= XINT (lx
), y0
= XINT (ly
);
27570 /* Does this segment cross the X line? */
27578 if (y
> y0
&& y
> y1
)
27580 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27590 find_hot_spot (Lisp_Object map
, int x
, int y
)
27592 while (CONSP (map
))
27594 if (CONSP (XCAR (map
))
27595 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27603 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27605 doc
: /* Lookup in image map MAP coordinates X and Y.
27606 An image map is an alist where each element has the format (AREA ID PLIST).
27607 An AREA is specified as either a rectangle, a circle, or a polygon:
27608 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27609 pixel coordinates of the upper left and bottom right corners.
27610 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27611 and the radius of the circle; r may be a float or integer.
27612 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27613 vector describes one corner in the polygon.
27614 Returns the alist element for the first matching AREA in MAP. */)
27615 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27623 return find_hot_spot (map
,
27624 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27625 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27629 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27631 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27633 /* Do not change cursor shape while dragging mouse. */
27634 if (!NILP (do_mouse_tracking
))
27637 if (!NILP (pointer
))
27639 if (EQ (pointer
, Qarrow
))
27640 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27641 else if (EQ (pointer
, Qhand
))
27642 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27643 else if (EQ (pointer
, Qtext
))
27644 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27645 else if (EQ (pointer
, intern ("hdrag")))
27646 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27647 #ifdef HAVE_X_WINDOWS
27648 else if (EQ (pointer
, intern ("vdrag")))
27649 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27651 else if (EQ (pointer
, intern ("hourglass")))
27652 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27653 else if (EQ (pointer
, Qmodeline
))
27654 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27656 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27659 if (cursor
!= No_Cursor
)
27660 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27663 #endif /* HAVE_WINDOW_SYSTEM */
27665 /* Take proper action when mouse has moved to the mode or header line
27666 or marginal area AREA of window W, x-position X and y-position Y.
27667 X is relative to the start of the text display area of W, so the
27668 width of bitmap areas and scroll bars must be subtracted to get a
27669 position relative to the start of the mode line. */
27672 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27673 enum window_part area
)
27675 struct window
*w
= XWINDOW (window
);
27676 struct frame
*f
= XFRAME (w
->frame
);
27677 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27678 #ifdef HAVE_WINDOW_SYSTEM
27679 Display_Info
*dpyinfo
;
27681 Cursor cursor
= No_Cursor
;
27682 Lisp_Object pointer
= Qnil
;
27683 int dx
, dy
, width
, height
;
27685 Lisp_Object string
, object
= Qnil
;
27686 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27688 Lisp_Object mouse_face
;
27689 int original_x_pixel
= x
;
27690 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27691 struct glyph_row
*row
IF_LINT (= 0);
27693 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27698 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27699 returns them in row/column units! */
27700 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27701 &object
, &dx
, &dy
, &width
, &height
);
27703 row
= (area
== ON_MODE_LINE
27704 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27705 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27707 /* Find the glyph under the mouse pointer. */
27708 if (row
->mode_line_p
&& row
->enabled_p
)
27710 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27711 end
= glyph
+ row
->used
[TEXT_AREA
];
27713 for (x0
= original_x_pixel
;
27714 glyph
< end
&& x0
>= glyph
->pixel_width
;
27716 x0
-= glyph
->pixel_width
;
27724 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27725 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27726 returns them in row/column units! */
27727 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27728 &object
, &dx
, &dy
, &width
, &height
);
27733 #ifdef HAVE_WINDOW_SYSTEM
27734 if (IMAGEP (object
))
27736 Lisp_Object image_map
, hotspot
;
27737 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27739 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27741 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27745 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27746 If so, we could look for mouse-enter, mouse-leave
27747 properties in PLIST (and do something...). */
27748 hotspot
= XCDR (hotspot
);
27749 if (CONSP (hotspot
)
27750 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27752 pointer
= Fplist_get (plist
, Qpointer
);
27753 if (NILP (pointer
))
27755 help
= Fplist_get (plist
, Qhelp_echo
);
27758 help_echo_string
= help
;
27759 XSETWINDOW (help_echo_window
, w
);
27760 help_echo_object
= w
->contents
;
27761 help_echo_pos
= charpos
;
27765 if (NILP (pointer
))
27766 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27768 #endif /* HAVE_WINDOW_SYSTEM */
27770 if (STRINGP (string
))
27771 pos
= make_number (charpos
);
27773 /* Set the help text and mouse pointer. If the mouse is on a part
27774 of the mode line without any text (e.g. past the right edge of
27775 the mode line text), use the default help text and pointer. */
27776 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27778 /* Arrange to display the help by setting the global variables
27779 help_echo_string, help_echo_object, and help_echo_pos. */
27782 if (STRINGP (string
))
27783 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27787 help_echo_string
= help
;
27788 XSETWINDOW (help_echo_window
, w
);
27789 help_echo_object
= string
;
27790 help_echo_pos
= charpos
;
27792 else if (area
== ON_MODE_LINE
)
27794 Lisp_Object default_help
27795 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27798 if (STRINGP (default_help
))
27800 help_echo_string
= default_help
;
27801 XSETWINDOW (help_echo_window
, w
);
27802 help_echo_object
= Qnil
;
27803 help_echo_pos
= -1;
27808 #ifdef HAVE_WINDOW_SYSTEM
27809 /* Change the mouse pointer according to what is under it. */
27810 if (FRAME_WINDOW_P (f
))
27812 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27813 if (STRINGP (string
))
27815 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27817 if (NILP (pointer
))
27818 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27820 /* Change the mouse pointer according to what is under X/Y. */
27822 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27825 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27826 if (!KEYMAPP (map
))
27827 map
= Fget_text_property (pos
, Qkeymap
, string
);
27828 if (!KEYMAPP (map
))
27829 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27833 /* Default mode-line pointer. */
27834 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27839 /* Change the mouse face according to what is under X/Y. */
27840 if (STRINGP (string
))
27842 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27843 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
27844 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27849 struct glyph
* tmp_glyph
;
27853 int total_pixel_width
;
27854 ptrdiff_t begpos
, endpos
, ignore
;
27858 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27859 Qmouse_face
, string
, Qnil
);
27865 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27867 endpos
= SCHARS (string
);
27871 /* Calculate the glyph position GPOS of GLYPH in the
27872 displayed string, relative to the beginning of the
27873 highlighted part of the string.
27875 Note: GPOS is different from CHARPOS. CHARPOS is the
27876 position of GLYPH in the internal string object. A mode
27877 line string format has structures which are converted to
27878 a flattened string by the Emacs Lisp interpreter. The
27879 internal string is an element of those structures. The
27880 displayed string is the flattened string. */
27881 tmp_glyph
= row_start_glyph
;
27882 while (tmp_glyph
< glyph
27883 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27884 && begpos
<= tmp_glyph
->charpos
27885 && tmp_glyph
->charpos
< endpos
)))
27887 gpos
= glyph
- tmp_glyph
;
27889 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27890 the highlighted part of the displayed string to which
27891 GLYPH belongs. Note: GSEQ_LENGTH is different from
27892 SCHARS (STRING), because the latter returns the length of
27893 the internal string. */
27894 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27896 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27897 && begpos
<= tmp_glyph
->charpos
27898 && tmp_glyph
->charpos
< endpos
));
27901 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27903 /* Calculate the total pixel width of all the glyphs between
27904 the beginning of the highlighted area and GLYPH. */
27905 total_pixel_width
= 0;
27906 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27907 total_pixel_width
+= tmp_glyph
->pixel_width
;
27909 /* Pre calculation of re-rendering position. Note: X is in
27910 column units here, after the call to mode_line_string or
27911 marginal_area_string. */
27913 vpos
= (area
== ON_MODE_LINE
27914 ? (w
->current_matrix
)->nrows
- 1
27917 /* If GLYPH's position is included in the region that is
27918 already drawn in mouse face, we have nothing to do. */
27919 if ( EQ (window
, hlinfo
->mouse_face_window
)
27920 && (!row
->reversed_p
27921 ? (hlinfo
->mouse_face_beg_col
<= hpos
27922 && hpos
< hlinfo
->mouse_face_end_col
)
27923 /* In R2L rows we swap BEG and END, see below. */
27924 : (hlinfo
->mouse_face_end_col
<= hpos
27925 && hpos
< hlinfo
->mouse_face_beg_col
))
27926 && hlinfo
->mouse_face_beg_row
== vpos
)
27929 if (clear_mouse_face (hlinfo
))
27930 cursor
= No_Cursor
;
27932 if (!row
->reversed_p
)
27934 hlinfo
->mouse_face_beg_col
= hpos
;
27935 hlinfo
->mouse_face_beg_x
= original_x_pixel
27936 - (total_pixel_width
+ dx
);
27937 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
27938 hlinfo
->mouse_face_end_x
= 0;
27942 /* In R2L rows, show_mouse_face expects BEG and END
27943 coordinates to be swapped. */
27944 hlinfo
->mouse_face_end_col
= hpos
;
27945 hlinfo
->mouse_face_end_x
= original_x_pixel
27946 - (total_pixel_width
+ dx
);
27947 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
27948 hlinfo
->mouse_face_beg_x
= 0;
27951 hlinfo
->mouse_face_beg_row
= vpos
;
27952 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
27953 hlinfo
->mouse_face_past_end
= 0;
27954 hlinfo
->mouse_face_window
= window
;
27956 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
27962 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27964 if (NILP (pointer
))
27967 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27968 clear_mouse_face (hlinfo
);
27970 #ifdef HAVE_WINDOW_SYSTEM
27971 if (FRAME_WINDOW_P (f
))
27972 define_frame_cursor1 (f
, cursor
, pointer
);
27978 Take proper action when the mouse has moved to position X, Y on
27979 frame F with regards to highlighting portions of display that have
27980 mouse-face properties. Also de-highlight portions of display where
27981 the mouse was before, set the mouse pointer shape as appropriate
27982 for the mouse coordinates, and activate help echo (tooltips).
27983 X and Y can be negative or out of range. */
27986 note_mouse_highlight (struct frame
*f
, int x
, int y
)
27988 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27989 enum window_part part
= ON_NOTHING
;
27990 Lisp_Object window
;
27992 Cursor cursor
= No_Cursor
;
27993 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
27996 /* When a menu is active, don't highlight because this looks odd. */
27997 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
27998 if (popup_activated ())
28002 if (!f
->glyphs_initialized_p
28003 || f
->pointer_invisible
)
28006 hlinfo
->mouse_face_mouse_x
= x
;
28007 hlinfo
->mouse_face_mouse_y
= y
;
28008 hlinfo
->mouse_face_mouse_frame
= f
;
28010 if (hlinfo
->mouse_face_defer
)
28013 /* Which window is that in? */
28014 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28016 /* If displaying active text in another window, clear that. */
28017 if (! EQ (window
, hlinfo
->mouse_face_window
)
28018 /* Also clear if we move out of text area in same window. */
28019 || (!NILP (hlinfo
->mouse_face_window
)
28022 && part
!= ON_MODE_LINE
28023 && part
!= ON_HEADER_LINE
))
28024 clear_mouse_face (hlinfo
);
28026 /* Not on a window -> return. */
28027 if (!WINDOWP (window
))
28030 /* Reset help_echo_string. It will get recomputed below. */
28031 help_echo_string
= Qnil
;
28033 /* Convert to window-relative pixel coordinates. */
28034 w
= XWINDOW (window
);
28035 frame_to_window_pixel_xy (w
, &x
, &y
);
28037 #ifdef HAVE_WINDOW_SYSTEM
28038 /* Handle tool-bar window differently since it doesn't display a
28040 if (EQ (window
, f
->tool_bar_window
))
28042 note_tool_bar_highlight (f
, x
, y
);
28047 /* Mouse is on the mode, header line or margin? */
28048 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28049 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28051 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28055 #ifdef HAVE_WINDOW_SYSTEM
28056 if (part
== ON_VERTICAL_BORDER
)
28058 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28059 help_echo_string
= build_string ("drag-mouse-1: resize");
28061 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28062 || part
== ON_SCROLL_BAR
)
28063 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28065 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28068 /* Are we in a window whose display is up to date?
28069 And verify the buffer's text has not changed. */
28070 b
= XBUFFER (w
->contents
);
28071 if (part
== ON_TEXT
&& w
->window_end_valid
&& !window_outdated (w
))
28073 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28075 struct glyph
*glyph
;
28076 Lisp_Object object
;
28077 Lisp_Object mouse_face
= Qnil
, position
;
28078 Lisp_Object
*overlay_vec
= NULL
;
28079 ptrdiff_t i
, noverlays
;
28080 struct buffer
*obuf
;
28081 ptrdiff_t obegv
, ozv
;
28084 /* Find the glyph under X/Y. */
28085 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28087 #ifdef HAVE_WINDOW_SYSTEM
28088 /* Look for :pointer property on image. */
28089 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28091 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28092 if (img
!= NULL
&& IMAGEP (img
->spec
))
28094 Lisp_Object image_map
, hotspot
;
28095 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28097 && (hotspot
= find_hot_spot (image_map
,
28098 glyph
->slice
.img
.x
+ dx
,
28099 glyph
->slice
.img
.y
+ dy
),
28101 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28105 /* Could check XCAR (hotspot) to see if we enter/leave
28107 If so, we could look for mouse-enter, mouse-leave
28108 properties in PLIST (and do something...). */
28109 hotspot
= XCDR (hotspot
);
28110 if (CONSP (hotspot
)
28111 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28113 pointer
= Fplist_get (plist
, Qpointer
);
28114 if (NILP (pointer
))
28116 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28117 if (!NILP (help_echo_string
))
28119 help_echo_window
= window
;
28120 help_echo_object
= glyph
->object
;
28121 help_echo_pos
= glyph
->charpos
;
28125 if (NILP (pointer
))
28126 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28129 #endif /* HAVE_WINDOW_SYSTEM */
28131 /* Clear mouse face if X/Y not over text. */
28133 || area
!= TEXT_AREA
28134 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28135 /* Glyph's OBJECT is an integer for glyphs inserted by the
28136 display engine for its internal purposes, like truncation
28137 and continuation glyphs and blanks beyond the end of
28138 line's text on text terminals. If we are over such a
28139 glyph, we are not over any text. */
28140 || INTEGERP (glyph
->object
)
28141 /* R2L rows have a stretch glyph at their front, which
28142 stands for no text, whereas L2R rows have no glyphs at
28143 all beyond the end of text. Treat such stretch glyphs
28144 like we do with NULL glyphs in L2R rows. */
28145 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28146 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28147 && glyph
->type
== STRETCH_GLYPH
28148 && glyph
->avoid_cursor_p
))
28150 if (clear_mouse_face (hlinfo
))
28151 cursor
= No_Cursor
;
28152 #ifdef HAVE_WINDOW_SYSTEM
28153 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28155 if (area
!= TEXT_AREA
)
28156 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28158 pointer
= Vvoid_text_area_pointer
;
28164 pos
= glyph
->charpos
;
28165 object
= glyph
->object
;
28166 if (!STRINGP (object
) && !BUFFERP (object
))
28169 /* If we get an out-of-range value, return now; avoid an error. */
28170 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28173 /* Make the window's buffer temporarily current for
28174 overlays_at and compute_char_face. */
28175 obuf
= current_buffer
;
28176 current_buffer
= b
;
28182 /* Is this char mouse-active or does it have help-echo? */
28183 position
= make_number (pos
);
28185 if (BUFFERP (object
))
28187 /* Put all the overlays we want in a vector in overlay_vec. */
28188 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28189 /* Sort overlays into increasing priority order. */
28190 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28195 if (NILP (Vmouse_highlight
))
28197 clear_mouse_face (hlinfo
);
28198 goto check_help_echo
;
28201 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28204 cursor
= No_Cursor
;
28206 /* Check mouse-face highlighting. */
28208 /* If there exists an overlay with mouse-face overlapping
28209 the one we are currently highlighting, we have to
28210 check if we enter the overlapping overlay, and then
28211 highlight only that. */
28212 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28213 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28215 /* Find the highest priority overlay with a mouse-face. */
28216 Lisp_Object overlay
= Qnil
;
28217 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28219 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28220 if (!NILP (mouse_face
))
28221 overlay
= overlay_vec
[i
];
28224 /* If we're highlighting the same overlay as before, there's
28225 no need to do that again. */
28226 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28227 goto check_help_echo
;
28228 hlinfo
->mouse_face_overlay
= overlay
;
28230 /* Clear the display of the old active region, if any. */
28231 if (clear_mouse_face (hlinfo
))
28232 cursor
= No_Cursor
;
28234 /* If no overlay applies, get a text property. */
28235 if (NILP (overlay
))
28236 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28238 /* Next, compute the bounds of the mouse highlighting and
28240 if (!NILP (mouse_face
) && STRINGP (object
))
28242 /* The mouse-highlighting comes from a display string
28243 with a mouse-face. */
28247 s
= Fprevious_single_property_change
28248 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28249 e
= Fnext_single_property_change
28250 (position
, Qmouse_face
, object
, Qnil
);
28252 s
= make_number (0);
28254 e
= make_number (SCHARS (object
) - 1);
28255 mouse_face_from_string_pos (w
, hlinfo
, object
,
28256 XINT (s
), XINT (e
));
28257 hlinfo
->mouse_face_past_end
= 0;
28258 hlinfo
->mouse_face_window
= window
;
28259 hlinfo
->mouse_face_face_id
28260 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28261 glyph
->face_id
, 1);
28262 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28263 cursor
= No_Cursor
;
28267 /* The mouse-highlighting, if any, comes from an overlay
28268 or text property in the buffer. */
28269 Lisp_Object buffer
IF_LINT (= Qnil
);
28270 Lisp_Object disp_string
IF_LINT (= Qnil
);
28272 if (STRINGP (object
))
28274 /* If we are on a display string with no mouse-face,
28275 check if the text under it has one. */
28276 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28277 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28278 pos
= string_buffer_position (object
, start
);
28281 mouse_face
= get_char_property_and_overlay
28282 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28283 buffer
= w
->contents
;
28284 disp_string
= object
;
28290 disp_string
= Qnil
;
28293 if (!NILP (mouse_face
))
28295 Lisp_Object before
, after
;
28296 Lisp_Object before_string
, after_string
;
28297 /* To correctly find the limits of mouse highlight
28298 in a bidi-reordered buffer, we must not use the
28299 optimization of limiting the search in
28300 previous-single-property-change and
28301 next-single-property-change, because
28302 rows_from_pos_range needs the real start and end
28303 positions to DTRT in this case. That's because
28304 the first row visible in a window does not
28305 necessarily display the character whose position
28306 is the smallest. */
28308 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28309 ? Fmarker_position (w
->start
)
28312 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28313 ? make_number (BUF_Z (XBUFFER (buffer
)) - w
->window_end_pos
)
28316 if (NILP (overlay
))
28318 /* Handle the text property case. */
28319 before
= Fprevious_single_property_change
28320 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28321 after
= Fnext_single_property_change
28322 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28323 before_string
= after_string
= Qnil
;
28327 /* Handle the overlay case. */
28328 before
= Foverlay_start (overlay
);
28329 after
= Foverlay_end (overlay
);
28330 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28331 after_string
= Foverlay_get (overlay
, Qafter_string
);
28333 if (!STRINGP (before_string
)) before_string
= Qnil
;
28334 if (!STRINGP (after_string
)) after_string
= Qnil
;
28337 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28340 : XFASTINT (before
),
28342 ? BUF_Z (XBUFFER (buffer
))
28343 : XFASTINT (after
),
28344 before_string
, after_string
,
28346 cursor
= No_Cursor
;
28353 /* Look for a `help-echo' property. */
28354 if (NILP (help_echo_string
)) {
28355 Lisp_Object help
, overlay
;
28357 /* Check overlays first. */
28358 help
= overlay
= Qnil
;
28359 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28361 overlay
= overlay_vec
[i
];
28362 help
= Foverlay_get (overlay
, Qhelp_echo
);
28367 help_echo_string
= help
;
28368 help_echo_window
= window
;
28369 help_echo_object
= overlay
;
28370 help_echo_pos
= pos
;
28374 Lisp_Object obj
= glyph
->object
;
28375 ptrdiff_t charpos
= glyph
->charpos
;
28377 /* Try text properties. */
28380 && charpos
< SCHARS (obj
))
28382 help
= Fget_text_property (make_number (charpos
),
28386 /* If the string itself doesn't specify a help-echo,
28387 see if the buffer text ``under'' it does. */
28388 struct glyph_row
*r
28389 = MATRIX_ROW (w
->current_matrix
, vpos
);
28390 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28391 ptrdiff_t p
= string_buffer_position (obj
, start
);
28394 help
= Fget_char_property (make_number (p
),
28395 Qhelp_echo
, w
->contents
);
28404 else if (BUFFERP (obj
)
28407 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28412 help_echo_string
= help
;
28413 help_echo_window
= window
;
28414 help_echo_object
= obj
;
28415 help_echo_pos
= charpos
;
28420 #ifdef HAVE_WINDOW_SYSTEM
28421 /* Look for a `pointer' property. */
28422 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28424 /* Check overlays first. */
28425 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28426 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28428 if (NILP (pointer
))
28430 Lisp_Object obj
= glyph
->object
;
28431 ptrdiff_t charpos
= glyph
->charpos
;
28433 /* Try text properties. */
28436 && charpos
< SCHARS (obj
))
28438 pointer
= Fget_text_property (make_number (charpos
),
28440 if (NILP (pointer
))
28442 /* If the string itself doesn't specify a pointer,
28443 see if the buffer text ``under'' it does. */
28444 struct glyph_row
*r
28445 = MATRIX_ROW (w
->current_matrix
, vpos
);
28446 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28447 ptrdiff_t p
= string_buffer_position (obj
, start
);
28449 pointer
= Fget_char_property (make_number (p
),
28450 Qpointer
, w
->contents
);
28453 else if (BUFFERP (obj
)
28456 pointer
= Fget_text_property (make_number (charpos
),
28460 #endif /* HAVE_WINDOW_SYSTEM */
28464 current_buffer
= obuf
;
28469 #ifdef HAVE_WINDOW_SYSTEM
28470 if (FRAME_WINDOW_P (f
))
28471 define_frame_cursor1 (f
, cursor
, pointer
);
28473 /* This is here to prevent a compiler error, about "label at end of
28474 compound statement". */
28481 Clear any mouse-face on window W. This function is part of the
28482 redisplay interface, and is called from try_window_id and similar
28483 functions to ensure the mouse-highlight is off. */
28486 x_clear_window_mouse_face (struct window
*w
)
28488 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28489 Lisp_Object window
;
28492 XSETWINDOW (window
, w
);
28493 if (EQ (window
, hlinfo
->mouse_face_window
))
28494 clear_mouse_face (hlinfo
);
28500 Just discard the mouse face information for frame F, if any.
28501 This is used when the size of F is changed. */
28504 cancel_mouse_face (struct frame
*f
)
28506 Lisp_Object window
;
28507 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28509 window
= hlinfo
->mouse_face_window
;
28510 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28511 reset_mouse_highlight (hlinfo
);
28516 /***********************************************************************
28518 ***********************************************************************/
28520 #ifdef HAVE_WINDOW_SYSTEM
28522 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28523 which intersects rectangle R. R is in window-relative coordinates. */
28526 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28527 enum glyph_row_area area
)
28529 struct glyph
*first
= row
->glyphs
[area
];
28530 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28531 struct glyph
*last
;
28532 int first_x
, start_x
, x
;
28534 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28535 /* If row extends face to end of line write the whole line. */
28536 draw_glyphs (w
, 0, row
, area
,
28537 0, row
->used
[area
],
28538 DRAW_NORMAL_TEXT
, 0);
28541 /* Set START_X to the window-relative start position for drawing glyphs of
28542 AREA. The first glyph of the text area can be partially visible.
28543 The first glyphs of other areas cannot. */
28544 start_x
= window_box_left_offset (w
, area
);
28546 if (area
== TEXT_AREA
)
28549 /* Find the first glyph that must be redrawn. */
28551 && x
+ first
->pixel_width
< r
->x
)
28553 x
+= first
->pixel_width
;
28557 /* Find the last one. */
28561 && x
< r
->x
+ r
->width
)
28563 x
+= last
->pixel_width
;
28569 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28570 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28571 DRAW_NORMAL_TEXT
, 0);
28576 /* Redraw the parts of the glyph row ROW on window W intersecting
28577 rectangle R. R is in window-relative coordinates. Value is
28578 non-zero if mouse-face was overwritten. */
28581 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28583 eassert (row
->enabled_p
);
28585 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28586 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28587 0, row
->used
[TEXT_AREA
],
28588 DRAW_NORMAL_TEXT
, 0);
28591 if (row
->used
[LEFT_MARGIN_AREA
])
28592 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28593 if (row
->used
[TEXT_AREA
])
28594 expose_area (w
, row
, r
, TEXT_AREA
);
28595 if (row
->used
[RIGHT_MARGIN_AREA
])
28596 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28597 draw_row_fringe_bitmaps (w
, row
);
28600 return row
->mouse_face_p
;
28604 /* Redraw those parts of glyphs rows during expose event handling that
28605 overlap other rows. Redrawing of an exposed line writes over parts
28606 of lines overlapping that exposed line; this function fixes that.
28608 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28609 row in W's current matrix that is exposed and overlaps other rows.
28610 LAST_OVERLAPPING_ROW is the last such row. */
28613 expose_overlaps (struct window
*w
,
28614 struct glyph_row
*first_overlapping_row
,
28615 struct glyph_row
*last_overlapping_row
,
28618 struct glyph_row
*row
;
28620 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28621 if (row
->overlapping_p
)
28623 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28626 if (row
->used
[LEFT_MARGIN_AREA
])
28627 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28629 if (row
->used
[TEXT_AREA
])
28630 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28632 if (row
->used
[RIGHT_MARGIN_AREA
])
28633 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28639 /* Return non-zero if W's cursor intersects rectangle R. */
28642 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28644 XRectangle cr
, result
;
28645 struct glyph
*cursor_glyph
;
28646 struct glyph_row
*row
;
28648 if (w
->phys_cursor
.vpos
>= 0
28649 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28650 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28652 && row
->cursor_in_fringe_p
)
28654 /* Cursor is in the fringe. */
28655 cr
.x
= window_box_right_offset (w
,
28656 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28657 ? RIGHT_MARGIN_AREA
28660 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28661 cr
.height
= row
->height
;
28662 return x_intersect_rectangles (&cr
, r
, &result
);
28665 cursor_glyph
= get_phys_cursor_glyph (w
);
28668 /* r is relative to W's box, but w->phys_cursor.x is relative
28669 to left edge of W's TEXT area. Adjust it. */
28670 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28671 cr
.y
= w
->phys_cursor
.y
;
28672 cr
.width
= cursor_glyph
->pixel_width
;
28673 cr
.height
= w
->phys_cursor_height
;
28674 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28675 I assume the effect is the same -- and this is portable. */
28676 return x_intersect_rectangles (&cr
, r
, &result
);
28678 /* If we don't understand the format, pretend we're not in the hot-spot. */
28684 Draw a vertical window border to the right of window W if W doesn't
28685 have vertical scroll bars. */
28688 x_draw_vertical_border (struct window
*w
)
28690 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28692 /* We could do better, if we knew what type of scroll-bar the adjacent
28693 windows (on either side) have... But we don't :-(
28694 However, I think this works ok. ++KFS 2003-04-25 */
28696 /* Redraw borders between horizontally adjacent windows. Don't
28697 do it for frames with vertical scroll bars because either the
28698 right scroll bar of a window, or the left scroll bar of its
28699 neighbor will suffice as a border. */
28700 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28703 /* Note: It is necessary to redraw both the left and the right
28704 borders, for when only this single window W is being
28706 if (!WINDOW_RIGHTMOST_P (w
)
28707 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28709 int x0
, x1
, y0
, y1
;
28711 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28714 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28717 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28719 if (!WINDOW_LEFTMOST_P (w
)
28720 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28722 int x0
, x1
, y0
, y1
;
28724 window_box_edges (w
, &x0
, &y0
, &x1
, &y1
);
28727 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28730 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28735 /* Redraw the part of window W intersection rectangle FR. Pixel
28736 coordinates in FR are frame-relative. Call this function with
28737 input blocked. Value is non-zero if the exposure overwrites
28741 expose_window (struct window
*w
, XRectangle
*fr
)
28743 struct frame
*f
= XFRAME (w
->frame
);
28745 int mouse_face_overwritten_p
= 0;
28747 /* If window is not yet fully initialized, do nothing. This can
28748 happen when toolkit scroll bars are used and a window is split.
28749 Reconfiguring the scroll bar will generate an expose for a newly
28751 if (w
->current_matrix
== NULL
)
28754 /* When we're currently updating the window, display and current
28755 matrix usually don't agree. Arrange for a thorough display
28757 if (w
->must_be_updated_p
)
28759 SET_FRAME_GARBAGED (f
);
28763 /* Frame-relative pixel rectangle of W. */
28764 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28765 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28766 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28767 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28769 if (x_intersect_rectangles (fr
, &wr
, &r
))
28771 int yb
= window_text_bottom_y (w
);
28772 struct glyph_row
*row
;
28773 int cursor_cleared_p
, phys_cursor_on_p
;
28774 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28776 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28777 r
.x
, r
.y
, r
.width
, r
.height
));
28779 /* Convert to window coordinates. */
28780 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28781 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28783 /* Turn off the cursor. */
28784 if (!w
->pseudo_window_p
28785 && phys_cursor_in_rect_p (w
, &r
))
28787 x_clear_cursor (w
);
28788 cursor_cleared_p
= 1;
28791 cursor_cleared_p
= 0;
28793 /* If the row containing the cursor extends face to end of line,
28794 then expose_area might overwrite the cursor outside the
28795 rectangle and thus notice_overwritten_cursor might clear
28796 w->phys_cursor_on_p. We remember the original value and
28797 check later if it is changed. */
28798 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28800 /* Update lines intersecting rectangle R. */
28801 first_overlapping_row
= last_overlapping_row
= NULL
;
28802 for (row
= w
->current_matrix
->rows
;
28807 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28809 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28810 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28811 || (r
.y
>= y0
&& r
.y
< y1
)
28812 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28814 /* A header line may be overlapping, but there is no need
28815 to fix overlapping areas for them. KFS 2005-02-12 */
28816 if (row
->overlapping_p
&& !row
->mode_line_p
)
28818 if (first_overlapping_row
== NULL
)
28819 first_overlapping_row
= row
;
28820 last_overlapping_row
= row
;
28824 if (expose_line (w
, row
, &r
))
28825 mouse_face_overwritten_p
= 1;
28828 else if (row
->overlapping_p
)
28830 /* We must redraw a row overlapping the exposed area. */
28832 ? y0
+ row
->phys_height
> r
.y
28833 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28835 if (first_overlapping_row
== NULL
)
28836 first_overlapping_row
= row
;
28837 last_overlapping_row
= row
;
28845 /* Display the mode line if there is one. */
28846 if (WINDOW_WANTS_MODELINE_P (w
)
28847 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28849 && row
->y
< r
.y
+ r
.height
)
28851 if (expose_line (w
, row
, &r
))
28852 mouse_face_overwritten_p
= 1;
28855 if (!w
->pseudo_window_p
)
28857 /* Fix the display of overlapping rows. */
28858 if (first_overlapping_row
)
28859 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28862 /* Draw border between windows. */
28863 x_draw_vertical_border (w
);
28865 /* Turn the cursor on again. */
28866 if (cursor_cleared_p
28867 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28868 update_window_cursor (w
, 1);
28872 return mouse_face_overwritten_p
;
28877 /* Redraw (parts) of all windows in the window tree rooted at W that
28878 intersect R. R contains frame pixel coordinates. Value is
28879 non-zero if the exposure overwrites mouse-face. */
28882 expose_window_tree (struct window
*w
, XRectangle
*r
)
28884 struct frame
*f
= XFRAME (w
->frame
);
28885 int mouse_face_overwritten_p
= 0;
28887 while (w
&& !FRAME_GARBAGED_P (f
))
28889 if (WINDOWP (w
->contents
))
28890 mouse_face_overwritten_p
28891 |= expose_window_tree (XWINDOW (w
->contents
), r
);
28893 mouse_face_overwritten_p
|= expose_window (w
, r
);
28895 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28898 return mouse_face_overwritten_p
;
28903 Redisplay an exposed area of frame F. X and Y are the upper-left
28904 corner of the exposed rectangle. W and H are width and height of
28905 the exposed area. All are pixel values. W or H zero means redraw
28906 the entire frame. */
28909 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
28912 int mouse_face_overwritten_p
= 0;
28914 TRACE ((stderr
, "expose_frame "));
28916 /* No need to redraw if frame will be redrawn soon. */
28917 if (FRAME_GARBAGED_P (f
))
28919 TRACE ((stderr
, " garbaged\n"));
28923 /* If basic faces haven't been realized yet, there is no point in
28924 trying to redraw anything. This can happen when we get an expose
28925 event while Emacs is starting, e.g. by moving another window. */
28926 if (FRAME_FACE_CACHE (f
) == NULL
28927 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
28929 TRACE ((stderr
, " no faces\n"));
28933 if (w
== 0 || h
== 0)
28936 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
28937 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
28947 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
28948 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
28950 if (WINDOWP (f
->tool_bar_window
))
28951 mouse_face_overwritten_p
28952 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
28954 #ifdef HAVE_X_WINDOWS
28956 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
28957 if (WINDOWP (f
->menu_bar_window
))
28958 mouse_face_overwritten_p
28959 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
28960 #endif /* not USE_X_TOOLKIT and not USE_GTK */
28964 /* Some window managers support a focus-follows-mouse style with
28965 delayed raising of frames. Imagine a partially obscured frame,
28966 and moving the mouse into partially obscured mouse-face on that
28967 frame. The visible part of the mouse-face will be highlighted,
28968 then the WM raises the obscured frame. With at least one WM, KDE
28969 2.1, Emacs is not getting any event for the raising of the frame
28970 (even tried with SubstructureRedirectMask), only Expose events.
28971 These expose events will draw text normally, i.e. not
28972 highlighted. Which means we must redo the highlight here.
28973 Subsume it under ``we love X''. --gerd 2001-08-15 */
28974 /* Included in Windows version because Windows most likely does not
28975 do the right thing if any third party tool offers
28976 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
28977 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
28979 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28980 if (f
== hlinfo
->mouse_face_mouse_frame
)
28982 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
28983 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
28984 clear_mouse_face (hlinfo
);
28985 note_mouse_highlight (f
, mouse_x
, mouse_y
);
28992 Determine the intersection of two rectangles R1 and R2. Return
28993 the intersection in *RESULT. Value is non-zero if RESULT is not
28997 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
28999 XRectangle
*left
, *right
;
29000 XRectangle
*upper
, *lower
;
29001 int intersection_p
= 0;
29003 /* Rearrange so that R1 is the left-most rectangle. */
29005 left
= r1
, right
= r2
;
29007 left
= r2
, right
= r1
;
29009 /* X0 of the intersection is right.x0, if this is inside R1,
29010 otherwise there is no intersection. */
29011 if (right
->x
<= left
->x
+ left
->width
)
29013 result
->x
= right
->x
;
29015 /* The right end of the intersection is the minimum of
29016 the right ends of left and right. */
29017 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29020 /* Same game for Y. */
29022 upper
= r1
, lower
= r2
;
29024 upper
= r2
, lower
= r1
;
29026 /* The upper end of the intersection is lower.y0, if this is inside
29027 of upper. Otherwise, there is no intersection. */
29028 if (lower
->y
<= upper
->y
+ upper
->height
)
29030 result
->y
= lower
->y
;
29032 /* The lower end of the intersection is the minimum of the lower
29033 ends of upper and lower. */
29034 result
->height
= (min (lower
->y
+ lower
->height
,
29035 upper
->y
+ upper
->height
)
29037 intersection_p
= 1;
29041 return intersection_p
;
29044 #endif /* HAVE_WINDOW_SYSTEM */
29047 /***********************************************************************
29049 ***********************************************************************/
29052 syms_of_xdisp (void)
29054 Vwith_echo_area_save_vector
= Qnil
;
29055 staticpro (&Vwith_echo_area_save_vector
);
29057 Vmessage_stack
= Qnil
;
29058 staticpro (&Vmessage_stack
);
29060 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29061 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29063 message_dolog_marker1
= Fmake_marker ();
29064 staticpro (&message_dolog_marker1
);
29065 message_dolog_marker2
= Fmake_marker ();
29066 staticpro (&message_dolog_marker2
);
29067 message_dolog_marker3
= Fmake_marker ();
29068 staticpro (&message_dolog_marker3
);
29071 defsubr (&Sdump_frame_glyph_matrix
);
29072 defsubr (&Sdump_glyph_matrix
);
29073 defsubr (&Sdump_glyph_row
);
29074 defsubr (&Sdump_tool_bar_row
);
29075 defsubr (&Strace_redisplay
);
29076 defsubr (&Strace_to_stderr
);
29078 #ifdef HAVE_WINDOW_SYSTEM
29079 defsubr (&Stool_bar_lines_needed
);
29080 defsubr (&Slookup_image_map
);
29082 defsubr (&Sline_pixel_height
);
29083 defsubr (&Sformat_mode_line
);
29084 defsubr (&Sinvisible_p
);
29085 defsubr (&Scurrent_bidi_paragraph_direction
);
29086 defsubr (&Smove_point_visually
);
29088 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29089 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29090 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29091 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29092 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29093 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29094 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29095 DEFSYM (Qeval
, "eval");
29096 DEFSYM (QCdata
, ":data");
29097 DEFSYM (Qdisplay
, "display");
29098 DEFSYM (Qspace_width
, "space-width");
29099 DEFSYM (Qraise
, "raise");
29100 DEFSYM (Qslice
, "slice");
29101 DEFSYM (Qspace
, "space");
29102 DEFSYM (Qmargin
, "margin");
29103 DEFSYM (Qpointer
, "pointer");
29104 DEFSYM (Qleft_margin
, "left-margin");
29105 DEFSYM (Qright_margin
, "right-margin");
29106 DEFSYM (Qcenter
, "center");
29107 DEFSYM (Qline_height
, "line-height");
29108 DEFSYM (QCalign_to
, ":align-to");
29109 DEFSYM (QCrelative_width
, ":relative-width");
29110 DEFSYM (QCrelative_height
, ":relative-height");
29111 DEFSYM (QCeval
, ":eval");
29112 DEFSYM (QCpropertize
, ":propertize");
29113 DEFSYM (QCfile
, ":file");
29114 DEFSYM (Qfontified
, "fontified");
29115 DEFSYM (Qfontification_functions
, "fontification-functions");
29116 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29117 DEFSYM (Qescape_glyph
, "escape-glyph");
29118 DEFSYM (Qnobreak_space
, "nobreak-space");
29119 DEFSYM (Qimage
, "image");
29120 DEFSYM (Qtext
, "text");
29121 DEFSYM (Qboth
, "both");
29122 DEFSYM (Qboth_horiz
, "both-horiz");
29123 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29124 DEFSYM (QCmap
, ":map");
29125 DEFSYM (QCpointer
, ":pointer");
29126 DEFSYM (Qrect
, "rect");
29127 DEFSYM (Qcircle
, "circle");
29128 DEFSYM (Qpoly
, "poly");
29129 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29130 DEFSYM (Qgrow_only
, "grow-only");
29131 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29132 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29133 DEFSYM (Qposition
, "position");
29134 DEFSYM (Qbuffer_position
, "buffer-position");
29135 DEFSYM (Qobject
, "object");
29136 DEFSYM (Qbar
, "bar");
29137 DEFSYM (Qhbar
, "hbar");
29138 DEFSYM (Qbox
, "box");
29139 DEFSYM (Qhollow
, "hollow");
29140 DEFSYM (Qhand
, "hand");
29141 DEFSYM (Qarrow
, "arrow");
29142 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29144 list_of_error
= list1 (list2 (intern_c_string ("error"),
29145 intern_c_string ("void-variable")));
29146 staticpro (&list_of_error
);
29148 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29149 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29150 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29151 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29153 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29154 staticpro (&echo_buffer
[0]);
29155 staticpro (&echo_buffer
[1]);
29157 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29158 staticpro (&echo_area_buffer
[0]);
29159 staticpro (&echo_area_buffer
[1]);
29161 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29162 staticpro (&Vmessages_buffer_name
);
29164 mode_line_proptrans_alist
= Qnil
;
29165 staticpro (&mode_line_proptrans_alist
);
29166 mode_line_string_list
= Qnil
;
29167 staticpro (&mode_line_string_list
);
29168 mode_line_string_face
= Qnil
;
29169 staticpro (&mode_line_string_face
);
29170 mode_line_string_face_prop
= Qnil
;
29171 staticpro (&mode_line_string_face_prop
);
29172 Vmode_line_unwind_vector
= Qnil
;
29173 staticpro (&Vmode_line_unwind_vector
);
29175 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29177 help_echo_string
= Qnil
;
29178 staticpro (&help_echo_string
);
29179 help_echo_object
= Qnil
;
29180 staticpro (&help_echo_object
);
29181 help_echo_window
= Qnil
;
29182 staticpro (&help_echo_window
);
29183 previous_help_echo_string
= Qnil
;
29184 staticpro (&previous_help_echo_string
);
29185 help_echo_pos
= -1;
29187 DEFSYM (Qright_to_left
, "right-to-left");
29188 DEFSYM (Qleft_to_right
, "left-to-right");
29190 #ifdef HAVE_WINDOW_SYSTEM
29191 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29192 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29193 For example, if a block cursor is over a tab, it will be drawn as
29194 wide as that tab on the display. */);
29195 x_stretch_cursor_p
= 0;
29198 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29199 doc
: /* Non-nil means highlight trailing whitespace.
29200 The face used for trailing whitespace is `trailing-whitespace'. */);
29201 Vshow_trailing_whitespace
= Qnil
;
29203 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29204 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29205 If the value is t, Emacs highlights non-ASCII chars which have the
29206 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29207 or `escape-glyph' face respectively.
29209 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29210 U+2011 (non-breaking hyphen) are affected.
29212 Any other non-nil value means to display these characters as a escape
29213 glyph followed by an ordinary space or hyphen.
29215 A value of nil means no special handling of these characters. */);
29216 Vnobreak_char_display
= Qt
;
29218 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29219 doc
: /* The pointer shape to show in void text areas.
29220 A value of nil means to show the text pointer. Other options are `arrow',
29221 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29222 Vvoid_text_area_pointer
= Qarrow
;
29224 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29225 doc
: /* Non-nil means don't actually do any redisplay.
29226 This is used for internal purposes. */);
29227 Vinhibit_redisplay
= Qnil
;
29229 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29230 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29231 Vglobal_mode_string
= Qnil
;
29233 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29234 doc
: /* Marker for where to display an arrow on top of the buffer text.
29235 This must be the beginning of a line in order to work.
29236 See also `overlay-arrow-string'. */);
29237 Voverlay_arrow_position
= Qnil
;
29239 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29240 doc
: /* String to display as an arrow in non-window frames.
29241 See also `overlay-arrow-position'. */);
29242 Voverlay_arrow_string
= build_pure_c_string ("=>");
29244 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29245 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29246 The symbols on this list are examined during redisplay to determine
29247 where to display overlay arrows. */);
29248 Voverlay_arrow_variable_list
29249 = list1 (intern_c_string ("overlay-arrow-position"));
29251 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29252 doc
: /* The number of lines to try scrolling a window by when point moves out.
29253 If that fails to bring point back on frame, point is centered instead.
29254 If this is zero, point is always centered after it moves off frame.
29255 If you want scrolling to always be a line at a time, you should set
29256 `scroll-conservatively' to a large value rather than set this to 1. */);
29258 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29259 doc
: /* Scroll up to this many lines, to bring point back on screen.
29260 If point moves off-screen, redisplay will scroll by up to
29261 `scroll-conservatively' lines in order to bring point just barely
29262 onto the screen again. If that cannot be done, then redisplay
29263 recenters point as usual.
29265 If the value is greater than 100, redisplay will never recenter point,
29266 but will always scroll just enough text to bring point into view, even
29267 if you move far away.
29269 A value of zero means always recenter point if it moves off screen. */);
29270 scroll_conservatively
= 0;
29272 DEFVAR_INT ("scroll-margin", scroll_margin
,
29273 doc
: /* Number of lines of margin at the top and bottom of a window.
29274 Recenter the window whenever point gets within this many lines
29275 of the top or bottom of the window. */);
29278 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29279 doc
: /* Pixels per inch value for non-window system displays.
29280 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29281 Vdisplay_pixels_per_inch
= make_float (72.0);
29284 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29287 DEFVAR_LISP ("truncate-partial-width-windows",
29288 Vtruncate_partial_width_windows
,
29289 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29290 For an integer value, truncate lines in each window narrower than the
29291 full frame width, provided the window width is less than that integer;
29292 otherwise, respect the value of `truncate-lines'.
29294 For any other non-nil value, truncate lines in all windows that do
29295 not span the full frame width.
29297 A value of nil means to respect the value of `truncate-lines'.
29299 If `word-wrap' is enabled, you might want to reduce this. */);
29300 Vtruncate_partial_width_windows
= make_number (50);
29302 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29303 doc
: /* Maximum buffer size for which line number should be displayed.
29304 If the buffer is bigger than this, the line number does not appear
29305 in the mode line. A value of nil means no limit. */);
29306 Vline_number_display_limit
= Qnil
;
29308 DEFVAR_INT ("line-number-display-limit-width",
29309 line_number_display_limit_width
,
29310 doc
: /* Maximum line width (in characters) for line number display.
29311 If the average length of the lines near point is bigger than this, then the
29312 line number may be omitted from the mode line. */);
29313 line_number_display_limit_width
= 200;
29315 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29316 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29317 highlight_nonselected_windows
= 0;
29319 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29320 doc
: /* Non-nil if more than one frame is visible on this display.
29321 Minibuffer-only frames don't count, but iconified frames do.
29322 This variable is not guaranteed to be accurate except while processing
29323 `frame-title-format' and `icon-title-format'. */);
29325 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29326 doc
: /* Template for displaying the title bar of visible frames.
29327 \(Assuming the window manager supports this feature.)
29329 This variable has the same structure as `mode-line-format', except that
29330 the %c and %l constructs are ignored. It is used only on frames for
29331 which no explicit name has been set \(see `modify-frame-parameters'). */);
29333 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29334 doc
: /* Template for displaying the title bar of an iconified frame.
29335 \(Assuming the window manager supports this feature.)
29336 This variable has the same structure as `mode-line-format' (which see),
29337 and is used only on frames for which no explicit name has been set
29338 \(see `modify-frame-parameters'). */);
29340 = Vframe_title_format
29341 = listn (CONSTYPE_PURE
, 3,
29342 intern_c_string ("multiple-frames"),
29343 build_pure_c_string ("%b"),
29344 listn (CONSTYPE_PURE
, 4,
29345 empty_unibyte_string
,
29346 intern_c_string ("invocation-name"),
29347 build_pure_c_string ("@"),
29348 intern_c_string ("system-name")));
29350 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29351 doc
: /* Maximum number of lines to keep in the message log buffer.
29352 If nil, disable message logging. If t, log messages but don't truncate
29353 the buffer when it becomes large. */);
29354 Vmessage_log_max
= make_number (1000);
29356 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29357 doc
: /* Functions called before redisplay, if window sizes have changed.
29358 The value should be a list of functions that take one argument.
29359 Just before redisplay, for each frame, if any of its windows have changed
29360 size since the last redisplay, or have been split or deleted,
29361 all the functions in the list are called, with the frame as argument. */);
29362 Vwindow_size_change_functions
= Qnil
;
29364 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29365 doc
: /* List of functions to call before redisplaying a window with scrolling.
29366 Each function is called with two arguments, the window and its new
29367 display-start position. Note that these functions are also called by
29368 `set-window-buffer'. Also note that the value of `window-end' is not
29369 valid when these functions are called.
29371 Warning: Do not use this feature to alter the way the window
29372 is scrolled. It is not designed for that, and such use probably won't
29374 Vwindow_scroll_functions
= Qnil
;
29376 DEFVAR_LISP ("window-text-change-functions",
29377 Vwindow_text_change_functions
,
29378 doc
: /* Functions to call in redisplay when text in the window might change. */);
29379 Vwindow_text_change_functions
= Qnil
;
29381 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29382 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29383 Each function is called with two arguments, the window and the end trigger value.
29384 See `set-window-redisplay-end-trigger'. */);
29385 Vredisplay_end_trigger_functions
= Qnil
;
29387 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29388 doc
: /* Non-nil means autoselect window with mouse pointer.
29389 If nil, do not autoselect windows.
29390 A positive number means delay autoselection by that many seconds: a
29391 window is autoselected only after the mouse has remained in that
29392 window for the duration of the delay.
29393 A negative number has a similar effect, but causes windows to be
29394 autoselected only after the mouse has stopped moving. \(Because of
29395 the way Emacs compares mouse events, you will occasionally wait twice
29396 that time before the window gets selected.\)
29397 Any other value means to autoselect window instantaneously when the
29398 mouse pointer enters it.
29400 Autoselection selects the minibuffer only if it is active, and never
29401 unselects the minibuffer if it is active.
29403 When customizing this variable make sure that the actual value of
29404 `focus-follows-mouse' matches the behavior of your window manager. */);
29405 Vmouse_autoselect_window
= Qnil
;
29407 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29408 doc
: /* Non-nil means automatically resize tool-bars.
29409 This dynamically changes the tool-bar's height to the minimum height
29410 that is needed to make all tool-bar items visible.
29411 If value is `grow-only', the tool-bar's height is only increased
29412 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29413 Vauto_resize_tool_bars
= Qt
;
29415 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29416 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29417 auto_raise_tool_bar_buttons_p
= 1;
29419 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29420 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29421 make_cursor_line_fully_visible_p
= 1;
29423 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29424 doc
: /* Border below tool-bar in pixels.
29425 If an integer, use it as the height of the border.
29426 If it is one of `internal-border-width' or `border-width', use the
29427 value of the corresponding frame parameter.
29428 Otherwise, no border is added below the tool-bar. */);
29429 Vtool_bar_border
= Qinternal_border_width
;
29431 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29432 doc
: /* Margin around tool-bar buttons in pixels.
29433 If an integer, use that for both horizontal and vertical margins.
29434 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29435 HORZ specifying the horizontal margin, and VERT specifying the
29436 vertical margin. */);
29437 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29439 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29440 doc
: /* Relief thickness of tool-bar buttons. */);
29441 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29443 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29444 doc
: /* Tool bar style to use.
29446 image - show images only
29447 text - show text only
29448 both - show both, text below image
29449 both-horiz - show text to the right of the image
29450 text-image-horiz - show text to the left of the image
29451 any other - use system default or image if no system default.
29453 This variable only affects the GTK+ toolkit version of Emacs. */);
29454 Vtool_bar_style
= Qnil
;
29456 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29457 doc
: /* Maximum number of characters a label can have to be shown.
29458 The tool bar style must also show labels for this to have any effect, see
29459 `tool-bar-style'. */);
29460 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29462 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29463 doc
: /* List of functions to call to fontify regions of text.
29464 Each function is called with one argument POS. Functions must
29465 fontify a region starting at POS in the current buffer, and give
29466 fontified regions the property `fontified'. */);
29467 Vfontification_functions
= Qnil
;
29468 Fmake_variable_buffer_local (Qfontification_functions
);
29470 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29471 unibyte_display_via_language_environment
,
29472 doc
: /* Non-nil means display unibyte text according to language environment.
29473 Specifically, this means that raw bytes in the range 160-255 decimal
29474 are displayed by converting them to the equivalent multibyte characters
29475 according to the current language environment. As a result, they are
29476 displayed according to the current fontset.
29478 Note that this variable affects only how these bytes are displayed,
29479 but does not change the fact they are interpreted as raw bytes. */);
29480 unibyte_display_via_language_environment
= 0;
29482 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29483 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29484 If a float, it specifies a fraction of the mini-window frame's height.
29485 If an integer, it specifies a number of lines. */);
29486 Vmax_mini_window_height
= make_float (0.25);
29488 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29489 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29490 A value of nil means don't automatically resize mini-windows.
29491 A value of t means resize them to fit the text displayed in them.
29492 A value of `grow-only', the default, means let mini-windows grow only;
29493 they return to their normal size when the minibuffer is closed, or the
29494 echo area becomes empty. */);
29495 Vresize_mini_windows
= Qgrow_only
;
29497 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29498 doc
: /* Alist specifying how to blink the cursor off.
29499 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29500 `cursor-type' frame-parameter or variable equals ON-STATE,
29501 comparing using `equal', Emacs uses OFF-STATE to specify
29502 how to blink it off. ON-STATE and OFF-STATE are values for
29503 the `cursor-type' frame parameter.
29505 If a frame's ON-STATE has no entry in this list,
29506 the frame's other specifications determine how to blink the cursor off. */);
29507 Vblink_cursor_alist
= Qnil
;
29509 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29510 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29511 If non-nil, windows are automatically scrolled horizontally to make
29512 point visible. */);
29513 automatic_hscrolling_p
= 1;
29514 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29516 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29517 doc
: /* How many columns away from the window edge point is allowed to get
29518 before automatic hscrolling will horizontally scroll the window. */);
29519 hscroll_margin
= 5;
29521 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29522 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29523 When point is less than `hscroll-margin' columns from the window
29524 edge, automatic hscrolling will scroll the window by the amount of columns
29525 determined by this variable. If its value is a positive integer, scroll that
29526 many columns. If it's a positive floating-point number, it specifies the
29527 fraction of the window's width to scroll. If it's nil or zero, point will be
29528 centered horizontally after the scroll. Any other value, including negative
29529 numbers, are treated as if the value were zero.
29531 Automatic hscrolling always moves point outside the scroll margin, so if
29532 point was more than scroll step columns inside the margin, the window will
29533 scroll more than the value given by the scroll step.
29535 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29536 and `scroll-right' overrides this variable's effect. */);
29537 Vhscroll_step
= make_number (0);
29539 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29540 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29541 Bind this around calls to `message' to let it take effect. */);
29542 message_truncate_lines
= 0;
29544 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29545 doc
: /* Normal hook run to update the menu bar definitions.
29546 Redisplay runs this hook before it redisplays the menu bar.
29547 This is used to update submenus such as Buffers,
29548 whose contents depend on various data. */);
29549 Vmenu_bar_update_hook
= Qnil
;
29551 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29552 doc
: /* Frame for which we are updating a menu.
29553 The enable predicate for a menu binding should check this variable. */);
29554 Vmenu_updating_frame
= Qnil
;
29556 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29557 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29558 inhibit_menubar_update
= 0;
29560 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29561 doc
: /* Prefix prepended to all continuation lines at display time.
29562 The value may be a string, an image, or a stretch-glyph; it is
29563 interpreted in the same way as the value of a `display' text property.
29565 This variable is overridden by any `wrap-prefix' text or overlay
29568 To add a prefix to non-continuation lines, use `line-prefix'. */);
29569 Vwrap_prefix
= Qnil
;
29570 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29571 Fmake_variable_buffer_local (Qwrap_prefix
);
29573 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29574 doc
: /* Prefix prepended to all non-continuation lines at display time.
29575 The value may be a string, an image, or a stretch-glyph; it is
29576 interpreted in the same way as the value of a `display' text property.
29578 This variable is overridden by any `line-prefix' text or overlay
29581 To add a prefix to continuation lines, use `wrap-prefix'. */);
29582 Vline_prefix
= Qnil
;
29583 DEFSYM (Qline_prefix
, "line-prefix");
29584 Fmake_variable_buffer_local (Qline_prefix
);
29586 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29587 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29588 inhibit_eval_during_redisplay
= 0;
29590 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29591 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29592 inhibit_free_realized_faces
= 0;
29595 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29596 doc
: /* Inhibit try_window_id display optimization. */);
29597 inhibit_try_window_id
= 0;
29599 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29600 doc
: /* Inhibit try_window_reusing display optimization. */);
29601 inhibit_try_window_reusing
= 0;
29603 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29604 doc
: /* Inhibit try_cursor_movement display optimization. */);
29605 inhibit_try_cursor_movement
= 0;
29606 #endif /* GLYPH_DEBUG */
29608 DEFVAR_INT ("overline-margin", overline_margin
,
29609 doc
: /* Space between overline and text, in pixels.
29610 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29611 margin to the character height. */);
29612 overline_margin
= 2;
29614 DEFVAR_INT ("underline-minimum-offset",
29615 underline_minimum_offset
,
29616 doc
: /* Minimum distance between baseline and underline.
29617 This can improve legibility of underlined text at small font sizes,
29618 particularly when using variable `x-use-underline-position-properties'
29619 with fonts that specify an UNDERLINE_POSITION relatively close to the
29620 baseline. The default value is 1. */);
29621 underline_minimum_offset
= 1;
29623 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29624 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29625 This feature only works when on a window system that can change
29626 cursor shapes. */);
29627 display_hourglass_p
= 1;
29629 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29630 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29631 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29633 #ifdef HAVE_WINDOW_SYSTEM
29634 hourglass_atimer
= NULL
;
29635 hourglass_shown_p
= 0;
29636 #endif /* HAVE_WINDOW_SYSTEM */
29638 DEFSYM (Qglyphless_char
, "glyphless-char");
29639 DEFSYM (Qhex_code
, "hex-code");
29640 DEFSYM (Qempty_box
, "empty-box");
29641 DEFSYM (Qthin_space
, "thin-space");
29642 DEFSYM (Qzero_width
, "zero-width");
29644 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29645 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29647 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29648 doc
: /* Char-table defining glyphless characters.
29649 Each element, if non-nil, should be one of the following:
29650 an ASCII acronym string: display this string in a box
29651 `hex-code': display the hexadecimal code of a character in a box
29652 `empty-box': display as an empty box
29653 `thin-space': display as 1-pixel width space
29654 `zero-width': don't display
29655 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29656 display method for graphical terminals and text terminals respectively.
29657 GRAPHICAL and TEXT should each have one of the values listed above.
29659 The char-table has one extra slot to control the display of a character for
29660 which no font is found. This slot only takes effect on graphical terminals.
29661 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29662 `thin-space'. The default is `empty-box'. */);
29663 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29664 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29667 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29668 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29669 Vdebug_on_message
= Qnil
;
29673 /* Initialize this module when Emacs starts. */
29678 CHARPOS (this_line_start_pos
) = 0;
29680 if (!noninteractive
)
29682 struct window
*m
= XWINDOW (minibuf_window
);
29683 Lisp_Object frame
= m
->frame
;
29684 struct frame
*f
= XFRAME (frame
);
29685 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29686 struct window
*r
= XWINDOW (root
);
29689 echo_area_window
= minibuf_window
;
29691 r
->top_line
= FRAME_TOP_MARGIN (f
);
29692 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
29693 r
->total_cols
= FRAME_COLS (f
);
29695 m
->top_line
= FRAME_LINES (f
) - 1;
29696 m
->total_lines
= 1;
29697 m
->total_cols
= FRAME_COLS (f
);
29699 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29700 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29701 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29703 /* The default ellipsis glyphs `...'. */
29704 for (i
= 0; i
< 3; ++i
)
29705 default_invis_vector
[i
] = make_number ('.');
29709 /* Allocate the buffer for frame titles.
29710 Also used for `format-mode-line'. */
29712 mode_line_noprop_buf
= xmalloc (size
);
29713 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29714 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29715 mode_line_target
= MODE_LINE_DISPLAY
;
29718 help_echo_showing_p
= 0;
29721 #ifdef HAVE_WINDOW_SYSTEM
29723 /* Platform-independent portion of hourglass implementation. */
29725 /* Cancel a currently active hourglass timer, and start a new one. */
29727 start_hourglass (void)
29729 struct timespec delay
;
29731 cancel_hourglass ();
29733 if (INTEGERP (Vhourglass_delay
)
29734 && XINT (Vhourglass_delay
) > 0)
29735 delay
= make_timespec (min (XINT (Vhourglass_delay
),
29736 TYPE_MAXIMUM (time_t)),
29738 else if (FLOATP (Vhourglass_delay
)
29739 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29740 delay
= dtotimespec (XFLOAT_DATA (Vhourglass_delay
));
29742 delay
= make_timespec (DEFAULT_HOURGLASS_DELAY
, 0);
29746 extern void w32_note_current_window (void);
29747 w32_note_current_window ();
29749 #endif /* HAVE_NTGUI */
29751 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29752 show_hourglass
, NULL
);
29756 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29759 cancel_hourglass (void)
29761 if (hourglass_atimer
)
29763 cancel_atimer (hourglass_atimer
);
29764 hourglass_atimer
= NULL
;
29767 if (hourglass_shown_p
)
29771 #endif /* HAVE_WINDOW_SYSTEM */