1 /* Display generation from window structure and buffer text.
3 Copyright (C) 1985-1988, 1993-1995, 1997-2013 Free Software Foundation,
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>.
25 Emacs separates the task of updating the display from code
26 modifying global state, e.g. buffer text. This way functions
27 operating on buffers don't also have to be concerned with updating
30 Updating the display is triggered by the Lisp interpreter when it
31 decides it's time to do it. This is done either automatically for
32 you as part of the interpreter's command loop or as the result of
33 calling Lisp functions like `sit-for'. The C function `redisplay'
34 in xdisp.c is the only entry into the inner redisplay code.
36 The following diagram shows how redisplay code is invoked. As you
37 can see, Lisp calls redisplay and vice versa. Under window systems
38 like X, some portions of the redisplay code are also called
39 asynchronously during mouse movement or expose events. It is very
40 important that these code parts do NOT use the C library (malloc,
41 free) because many C libraries under Unix are not reentrant. They
42 may also NOT call functions of the Lisp interpreter which could
43 change the interpreter's state. If you don't follow these rules,
44 you will encounter bugs which are very hard to explain.
46 +--------------+ redisplay +----------------+
47 | Lisp machine |---------------->| Redisplay code |<--+
48 +--------------+ (xdisp.c) +----------------+ |
50 +----------------------------------+ |
51 Don't use this path when called |
54 expose_window (asynchronous) |
56 X expose events -----+
58 What does redisplay do? Obviously, it has to figure out somehow what
59 has been changed since the last time the display has been updated,
60 and to make these changes visible. Preferably it would do that in
61 a moderately intelligent way, i.e. fast.
63 Changes in buffer text can be deduced from window and buffer
64 structures, and from some global variables like `beg_unchanged' and
65 `end_unchanged'. The contents of the display are additionally
66 recorded in a `glyph matrix', a two-dimensional matrix of glyph
67 structures. Each row in such a matrix corresponds to a line on the
68 display, and each glyph in a row corresponds to a column displaying
69 a character, an image, or what else. This matrix is called the
70 `current glyph matrix' or `current matrix' in redisplay
73 For buffer parts that have been changed since the last update, a
74 second glyph matrix is constructed, the so called `desired glyph
75 matrix' or short `desired matrix'. Current and desired matrix are
76 then compared to find a cheap way to update the display, e.g. by
77 reusing part of the display by scrolling lines.
79 You will find a lot of redisplay optimizations when you start
80 looking at the innards of redisplay. The overall goal of all these
81 optimizations is to make redisplay fast because it is done
82 frequently. Some of these optimizations are implemented by the
87 This function tries to update the display if the text in the
88 window did not change and did not scroll, only point moved, and
89 it did not move off the displayed portion of the text.
91 . try_window_reusing_current_matrix
93 This function reuses the current matrix of a window when text
94 has not changed, but the window start changed (e.g., due to
99 This function attempts to redisplay a window by reusing parts of
100 its existing display. It finds and reuses the part that was not
101 changed, and redraws the rest.
105 This function performs the full redisplay of a single window
106 assuming that its fonts were not changed and that the cursor
107 will not end up in the scroll margins. (Loading fonts requires
108 re-adjustment of dimensions of glyph matrices, which makes this
109 method impossible to use.)
111 These optimizations are tried in sequence (some can be skipped if
112 it is known that they are not applicable). If none of the
113 optimizations were successful, redisplay calls redisplay_windows,
114 which performs a full redisplay of all windows.
118 Desired matrices are always built per Emacs window. The function
119 `display_line' is the central function to look at if you are
120 interested. It constructs one row in a desired matrix given an
121 iterator structure containing both a buffer position and a
122 description of the environment in which the text is to be
123 displayed. But this is too early, read on.
125 Characters and pixmaps displayed for a range of buffer text depend
126 on various settings of buffers and windows, on overlays and text
127 properties, on display tables, on selective display. The good news
128 is that all this hairy stuff is hidden behind a small set of
129 interface functions taking an iterator structure (struct it)
132 Iteration over things to be displayed is then simple. It is
133 started by initializing an iterator with a call to init_iterator,
134 passing it the buffer position where to start iteration. For
135 iteration over strings, pass -1 as the position to init_iterator,
136 and call reseat_to_string when the string is ready, to initialize
137 the iterator for that string. Thereafter, calls to
138 get_next_display_element fill the iterator structure with relevant
139 information about the next thing to display. Calls to
140 set_iterator_to_next move the iterator to the next thing.
142 Besides this, an iterator also contains information about the
143 display environment in which glyphs for display elements are to be
144 produced. It has fields for the width and height of the display,
145 the information whether long lines are truncated or continued, a
146 current X and Y position, and lots of other stuff you can better
149 Glyphs in a desired matrix are normally constructed in a loop
150 calling get_next_display_element and then PRODUCE_GLYPHS. The call
151 to PRODUCE_GLYPHS will fill the iterator structure with pixel
152 information about the element being displayed and at the same time
153 produce glyphs for it. If the display element fits on the line
154 being displayed, set_iterator_to_next is called next, otherwise the
155 glyphs produced are discarded. The function display_line is the
156 workhorse of filling glyph rows in the desired matrix with glyphs.
157 In addition to producing glyphs, it also handles line truncation
158 and continuation, word wrap, and cursor positioning (for the
159 latter, see also set_cursor_from_row).
163 That just couldn't be all, could it? What about terminal types not
164 supporting operations on sub-windows of the screen? To update the
165 display on such a terminal, window-based glyph matrices are not
166 well suited. To be able to reuse part of the display (scrolling
167 lines up and down), we must instead have a view of the whole
168 screen. This is what `frame matrices' are for. They are a trick.
170 Frames on terminals like above have a glyph pool. Windows on such
171 a frame sub-allocate their glyph memory from their frame's glyph
172 pool. The frame itself is given its own glyph matrices. By
173 coincidence---or maybe something else---rows in window glyph
174 matrices are slices of corresponding rows in frame matrices. Thus
175 writing to window matrices implicitly updates a frame matrix which
176 provides us with the view of the whole screen that we originally
177 wanted to have without having to move many bytes around. To be
178 honest, there is a little bit more done, but not much more. If you
179 plan to extend that code, take a look at dispnew.c. The function
180 build_frame_matrix is a good starting point.
182 Bidirectional display.
184 Bidirectional display adds quite some hair to this already complex
185 design. The good news are that a large portion of that hairy stuff
186 is hidden in bidi.c behind only 3 interfaces. bidi.c implements a
187 reordering engine which is called by set_iterator_to_next and
188 returns the next character to display in the visual order. See
189 commentary on bidi.c for more details. As far as redisplay is
190 concerned, the effect of calling bidi_move_to_visually_next, the
191 main interface of the reordering engine, is that the iterator gets
192 magically placed on the buffer or string position that is to be
193 displayed next. In other words, a linear iteration through the
194 buffer/string is replaced with a non-linear one. All the rest of
195 the redisplay is oblivious to the bidi reordering.
197 Well, almost oblivious---there are still complications, most of
198 them due to the fact that buffer and string positions no longer
199 change monotonously with glyph indices in a glyph row. Moreover,
200 for continued lines, the buffer positions may not even be
201 monotonously changing with vertical positions. Also, accounting
202 for face changes, overlays, etc. becomes more complex because
203 non-linear iteration could potentially skip many positions with
204 changes, and then cross them again on the way back...
206 One other prominent effect of bidirectional display is that some
207 paragraphs of text need to be displayed starting at the right
208 margin of the window---the so-called right-to-left, or R2L
209 paragraphs. R2L paragraphs are displayed with R2L glyph rows,
210 which have their reversed_p flag set. The bidi reordering engine
211 produces characters in such rows starting from the character which
212 should be the rightmost on display. PRODUCE_GLYPHS then reverses
213 the order, when it fills up the glyph row whose reversed_p flag is
214 set, by prepending each new glyph to what is already there, instead
215 of appending it. When the glyph row is complete, the function
216 extend_face_to_end_of_line fills the empty space to the left of the
217 leftmost character with special glyphs, which will display as,
218 well, empty. On text terminals, these special glyphs are simply
219 blank characters. On graphics terminals, there's a single stretch
220 glyph of a suitably computed width. Both the blanks and the
221 stretch glyph are given the face of the background of the line.
222 This way, the terminal-specific back-end can still draw the glyphs
223 left to right, even for R2L lines.
225 Bidirectional display and character compositions
227 Some scripts cannot be displayed by drawing each character
228 individually, because adjacent characters change each other's shape
229 on display. For example, Arabic and Indic scripts belong to this
232 Emacs display supports this by providing "character compositions",
233 most of which is implemented in composite.c. During the buffer
234 scan that delivers characters to PRODUCE_GLYPHS, if the next
235 character to be delivered is a composed character, the iteration
236 calls composition_reseat_it and next_element_from_composition. If
237 they succeed to compose the character with one or more of the
238 following characters, the whole sequence of characters that where
239 composed is recorded in the `struct composition_it' object that is
240 part of the buffer iterator. The composed sequence could produce
241 one or more font glyphs (called "grapheme clusters") on the screen.
242 Each of these grapheme clusters is then delivered to PRODUCE_GLYPHS
243 in the direction corresponding to the current bidi scan direction
244 (recorded in the scan_dir member of the `struct bidi_it' object
245 that is part of the buffer iterator). In particular, if the bidi
246 iterator currently scans the buffer backwards, the grapheme
247 clusters are delivered back to front. This reorders the grapheme
248 clusters as appropriate for the current bidi context. Note that
249 this means that the grapheme clusters are always stored in the
250 LGSTRING object (see composite.c) in the logical order.
252 Moving an iterator in bidirectional text
253 without producing glyphs
255 Note one important detail mentioned above: that the bidi reordering
256 engine, driven by the iterator, produces characters in R2L rows
257 starting at the character that will be the rightmost on display.
258 As far as the iterator is concerned, the geometry of such rows is
259 still left to right, i.e. the iterator "thinks" the first character
260 is at the leftmost pixel position. The iterator does not know that
261 PRODUCE_GLYPHS reverses the order of the glyphs that the iterator
262 delivers. This is important when functions from the move_it_*
263 family are used to get to certain screen position or to match
264 screen coordinates with buffer coordinates: these functions use the
265 iterator geometry, which is left to right even in R2L paragraphs.
266 This works well with most callers of move_it_*, because they need
267 to get to a specific column, and columns are still numbered in the
268 reading order, i.e. the rightmost character in a R2L paragraph is
269 still column zero. But some callers do not get well with this; a
270 notable example is mouse clicks that need to find the character
271 that corresponds to certain pixel coordinates. See
272 buffer_posn_from_coords in dispnew.c for how this is handled. */
280 #include "keyboard.h"
283 #include "termchar.h"
284 #include "dispextern.h"
285 #include "character.h"
289 #include "commands.h"
293 #include "termhooks.h"
294 #include "termopts.h"
295 #include "intervals.h"
298 #include "region-cache.h"
301 #include "blockinput.h"
303 #ifdef HAVE_X_WINDOWS
316 #ifndef FRAME_X_OUTPUT
317 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
320 #define INFINITY 10000000
322 Lisp_Object Qoverriding_local_map
, Qoverriding_terminal_local_map
;
323 Lisp_Object Qwindow_scroll_functions
;
324 static Lisp_Object Qwindow_text_change_functions
;
325 static Lisp_Object Qredisplay_end_trigger_functions
;
326 Lisp_Object Qinhibit_point_motion_hooks
;
327 static Lisp_Object QCeval
, QCpropertize
;
328 Lisp_Object QCfile
, QCdata
;
329 static Lisp_Object Qfontified
;
330 static Lisp_Object Qgrow_only
;
331 static Lisp_Object Qinhibit_eval_during_redisplay
;
332 static Lisp_Object Qbuffer_position
, Qposition
, Qobject
;
333 static Lisp_Object Qright_to_left
, Qleft_to_right
;
336 Lisp_Object Qbar
, Qhbar
, Qbox
, Qhollow
;
338 /* Pointer shapes. */
339 static Lisp_Object Qarrow
, Qhand
;
342 /* Holds the list (error). */
343 static Lisp_Object list_of_error
;
345 static Lisp_Object Qfontification_functions
;
347 static Lisp_Object Qwrap_prefix
;
348 static Lisp_Object Qline_prefix
;
349 static Lisp_Object Qredisplay_internal
;
351 /* Non-nil means don't actually do any redisplay. */
353 Lisp_Object Qinhibit_redisplay
;
355 /* Names of text properties relevant for redisplay. */
357 Lisp_Object Qdisplay
;
359 Lisp_Object Qspace
, QCalign_to
;
360 static Lisp_Object QCrelative_width
, QCrelative_height
;
361 Lisp_Object Qleft_margin
, Qright_margin
;
362 static Lisp_Object Qspace_width
, Qraise
;
363 static Lisp_Object Qslice
;
365 static Lisp_Object Qmargin
, Qpointer
;
366 static Lisp_Object Qline_height
;
368 #ifdef HAVE_WINDOW_SYSTEM
370 /* Test if overflow newline into fringe. Called with iterator IT
371 at or past right window margin, and with IT->current_x set. */
373 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(IT) \
374 (!NILP (Voverflow_newline_into_fringe) \
375 && FRAME_WINDOW_P ((IT)->f) \
376 && ((IT)->bidi_it.paragraph_dir == R2L \
377 ? (WINDOW_LEFT_FRINGE_WIDTH ((IT)->w) > 0) \
378 : (WINDOW_RIGHT_FRINGE_WIDTH ((IT)->w) > 0)) \
379 && (IT)->current_x == (IT)->last_visible_x)
381 #else /* !HAVE_WINDOW_SYSTEM */
382 #define IT_OVERFLOW_NEWLINE_INTO_FRINGE(it) 0
383 #endif /* HAVE_WINDOW_SYSTEM */
385 /* Test if the display element loaded in IT, or the underlying buffer
386 or string character, is a space or a TAB character. This is used
387 to determine where word wrapping can occur. */
389 #define IT_DISPLAYING_WHITESPACE(it) \
390 ((it->what == IT_CHARACTER && (it->c == ' ' || it->c == '\t')) \
391 || ((STRINGP (it->string) \
392 && (SREF (it->string, IT_STRING_BYTEPOS (*it)) == ' ' \
393 || SREF (it->string, IT_STRING_BYTEPOS (*it)) == '\t')) \
395 && (it->s[IT_BYTEPOS (*it)] == ' ' \
396 || it->s[IT_BYTEPOS (*it)] == '\t')) \
397 || (IT_BYTEPOS (*it) < ZV_BYTE \
398 && (*BYTE_POS_ADDR (IT_BYTEPOS (*it)) == ' ' \
399 || *BYTE_POS_ADDR (IT_BYTEPOS (*it)) == '\t')))) \
401 /* Name of the face used to highlight trailing whitespace. */
403 static Lisp_Object Qtrailing_whitespace
;
405 /* Name and number of the face used to highlight escape glyphs. */
407 static Lisp_Object Qescape_glyph
;
409 /* Name and number of the face used to highlight non-breaking spaces. */
411 static Lisp_Object Qnobreak_space
;
413 /* The symbol `image' which is the car of the lists used to represent
414 images in Lisp. Also a tool bar style. */
418 /* The image map types. */
420 static Lisp_Object QCpointer
;
421 static Lisp_Object Qrect
, Qcircle
, Qpoly
;
423 /* Tool bar styles */
424 Lisp_Object Qboth
, Qboth_horiz
, Qtext_image_horiz
;
426 /* Non-zero means print newline to stdout before next mini-buffer
429 int noninteractive_need_newline
;
431 /* Non-zero means print newline to message log before next message. */
433 static int message_log_need_newline
;
435 /* Three markers that message_dolog uses.
436 It could allocate them itself, but that causes trouble
437 in handling memory-full errors. */
438 static Lisp_Object message_dolog_marker1
;
439 static Lisp_Object message_dolog_marker2
;
440 static Lisp_Object message_dolog_marker3
;
442 /* The buffer position of the first character appearing entirely or
443 partially on the line of the selected window which contains the
444 cursor; <= 0 if not known. Set by set_cursor_from_row, used for
445 redisplay optimization in redisplay_internal. */
447 static struct text_pos this_line_start_pos
;
449 /* Number of characters past the end of the line above, including the
450 terminating newline. */
452 static struct text_pos this_line_end_pos
;
454 /* The vertical positions and the height of this line. */
456 static int this_line_vpos
;
457 static int this_line_y
;
458 static int this_line_pixel_height
;
460 /* X position at which this display line starts. Usually zero;
461 negative if first character is partially visible. */
463 static int this_line_start_x
;
465 /* The smallest character position seen by move_it_* functions as they
466 move across display lines. Used to set MATRIX_ROW_START_CHARPOS of
467 hscrolled lines, see display_line. */
469 static struct text_pos this_line_min_pos
;
471 /* Buffer that this_line_.* variables are referring to. */
473 static struct buffer
*this_line_buffer
;
476 /* Values of those variables at last redisplay are stored as
477 properties on `overlay-arrow-position' symbol. However, if
478 Voverlay_arrow_position is a marker, last-arrow-position is its
479 numerical position. */
481 static Lisp_Object Qlast_arrow_position
, Qlast_arrow_string
;
483 /* Alternative overlay-arrow-string and overlay-arrow-bitmap
484 properties on a symbol in overlay-arrow-variable-list. */
486 static Lisp_Object Qoverlay_arrow_string
, Qoverlay_arrow_bitmap
;
488 Lisp_Object Qmenu_bar_update_hook
;
490 /* Nonzero if an overlay arrow has been displayed in this window. */
492 static int overlay_arrow_seen
;
494 /* Vector containing glyphs for an ellipsis `...'. */
496 static Lisp_Object default_invis_vector
[3];
498 /* This is the window where the echo area message was displayed. It
499 is always a mini-buffer window, but it may not be the same window
500 currently active as a mini-buffer. */
502 Lisp_Object echo_area_window
;
504 /* List of pairs (MESSAGE . MULTIBYTE). The function save_message
505 pushes the current message and the value of
506 message_enable_multibyte on the stack, the function restore_message
507 pops the stack and displays MESSAGE again. */
509 static Lisp_Object Vmessage_stack
;
511 /* Nonzero means multibyte characters were enabled when the echo area
512 message was specified. */
514 static int message_enable_multibyte
;
516 /* Nonzero if we should redraw the mode lines on the next redisplay. */
518 int update_mode_lines
;
520 /* Nonzero if window sizes or contents have changed since last
521 redisplay that finished. */
523 int windows_or_buffers_changed
;
525 /* Nonzero means a frame's cursor type has been changed. */
527 int cursor_type_changed
;
529 /* Nonzero after display_mode_line if %l was used and it displayed a
532 static int line_number_displayed
;
534 /* The name of the *Messages* buffer, a string. */
536 static Lisp_Object Vmessages_buffer_name
;
538 /* Current, index 0, and last displayed echo area message. Either
539 buffers from echo_buffers, or nil to indicate no message. */
541 Lisp_Object echo_area_buffer
[2];
543 /* The buffers referenced from echo_area_buffer. */
545 static Lisp_Object echo_buffer
[2];
547 /* A vector saved used in with_area_buffer to reduce consing. */
549 static Lisp_Object Vwith_echo_area_save_vector
;
551 /* Non-zero means display_echo_area should display the last echo area
552 message again. Set by redisplay_preserve_echo_area. */
554 static int display_last_displayed_message_p
;
556 /* Nonzero if echo area is being used by print; zero if being used by
559 static int message_buf_print
;
561 /* The symbol `inhibit-menubar-update' and its DEFVAR_BOOL variable. */
563 static Lisp_Object Qinhibit_menubar_update
;
564 static Lisp_Object Qmessage_truncate_lines
;
566 /* Set to 1 in clear_message to make redisplay_internal aware
567 of an emptied echo area. */
569 static int message_cleared_p
;
571 /* A scratch glyph row with contents used for generating truncation
572 glyphs. Also used in direct_output_for_insert. */
574 #define MAX_SCRATCH_GLYPHS 100
575 static struct glyph_row scratch_glyph_row
;
576 static struct glyph scratch_glyphs
[MAX_SCRATCH_GLYPHS
];
578 /* Ascent and height of the last line processed by move_it_to. */
580 static int last_height
;
582 /* Non-zero if there's a help-echo in the echo area. */
584 int help_echo_showing_p
;
586 /* If >= 0, computed, exact values of mode-line and header-line height
587 to use in the macros CURRENT_MODE_LINE_HEIGHT and
588 CURRENT_HEADER_LINE_HEIGHT. */
590 int current_mode_line_height
, current_header_line_height
;
592 /* The maximum distance to look ahead for text properties. Values
593 that are too small let us call compute_char_face and similar
594 functions too often which is expensive. Values that are too large
595 let us call compute_char_face and alike too often because we
596 might not be interested in text properties that far away. */
598 #define TEXT_PROP_DISTANCE_LIMIT 100
600 /* SAVE_IT and RESTORE_IT are called when we save a snapshot of the
601 iterator state and later restore it. This is needed because the
602 bidi iterator on bidi.c keeps a stacked cache of its states, which
603 is really a singleton. When we use scratch iterator objects to
604 move around the buffer, we can cause the bidi cache to be pushed or
605 popped, and therefore we need to restore the cache state when we
606 return to the original iterator. */
607 #define SAVE_IT(ITCOPY,ITORIG,CACHE) \
610 bidi_unshelve_cache (CACHE, 1); \
612 CACHE = bidi_shelve_cache (); \
615 #define RESTORE_IT(pITORIG,pITCOPY,CACHE) \
617 if (pITORIG != pITCOPY) \
618 *(pITORIG) = *(pITCOPY); \
619 bidi_unshelve_cache (CACHE, 0); \
625 /* Non-zero means print traces of redisplay if compiled with
626 GLYPH_DEBUG defined. */
628 int trace_redisplay_p
;
630 #endif /* GLYPH_DEBUG */
632 #ifdef DEBUG_TRACE_MOVE
633 /* Non-zero means trace with TRACE_MOVE to stderr. */
636 #define TRACE_MOVE(x) if (trace_move) fprintf x; else (void) 0
638 #define TRACE_MOVE(x) (void) 0
641 static Lisp_Object Qauto_hscroll_mode
;
643 /* Buffer being redisplayed -- for redisplay_window_error. */
645 static struct buffer
*displayed_buffer
;
647 /* Value returned from text property handlers (see below). */
652 HANDLED_RECOMPUTE_PROPS
,
653 HANDLED_OVERLAY_STRING_CONSUMED
,
657 /* A description of text properties that redisplay is interested
662 /* The name of the property. */
665 /* A unique index for the property. */
668 /* A handler function called to set up iterator IT from the property
669 at IT's current position. Value is used to steer handle_stop. */
670 enum prop_handled (*handler
) (struct it
*it
);
673 static enum prop_handled
handle_face_prop (struct it
*);
674 static enum prop_handled
handle_invisible_prop (struct it
*);
675 static enum prop_handled
handle_display_prop (struct it
*);
676 static enum prop_handled
handle_composition_prop (struct it
*);
677 static enum prop_handled
handle_overlay_change (struct it
*);
678 static enum prop_handled
handle_fontified_prop (struct it
*);
680 /* Properties handled by iterators. */
682 static struct props it_props
[] =
684 {&Qfontified
, FONTIFIED_PROP_IDX
, handle_fontified_prop
},
685 /* Handle `face' before `display' because some sub-properties of
686 `display' need to know the face. */
687 {&Qface
, FACE_PROP_IDX
, handle_face_prop
},
688 {&Qdisplay
, DISPLAY_PROP_IDX
, handle_display_prop
},
689 {&Qinvisible
, INVISIBLE_PROP_IDX
, handle_invisible_prop
},
690 {&Qcomposition
, COMPOSITION_PROP_IDX
, handle_composition_prop
},
694 /* Value is the position described by X. If X is a marker, value is
695 the marker_position of X. Otherwise, value is X. */
697 #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X))
699 /* Enumeration returned by some move_it_.* functions internally. */
703 /* Not used. Undefined value. */
706 /* Move ended at the requested buffer position or ZV. */
707 MOVE_POS_MATCH_OR_ZV
,
709 /* Move ended at the requested X pixel position. */
712 /* Move within a line ended at the end of a line that must be
716 /* Move within a line ended at the end of a line that would
717 be displayed truncated. */
720 /* Move within a line ended at a line end. */
724 /* This counter is used to clear the face cache every once in a while
725 in redisplay_internal. It is incremented for each redisplay.
726 Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is
729 #define CLEAR_FACE_CACHE_COUNT 500
730 static int clear_face_cache_count
;
732 /* Similarly for the image cache. */
734 #ifdef HAVE_WINDOW_SYSTEM
735 #define CLEAR_IMAGE_CACHE_COUNT 101
736 static int clear_image_cache_count
;
738 /* Null glyph slice */
739 static struct glyph_slice null_glyph_slice
= { 0, 0, 0, 0 };
742 /* True while redisplay_internal is in progress. */
746 static Lisp_Object Qinhibit_free_realized_faces
;
747 static Lisp_Object Qmode_line_default_help_echo
;
749 /* If a string, XTread_socket generates an event to display that string.
750 (The display is done in read_char.) */
752 Lisp_Object help_echo_string
;
753 Lisp_Object help_echo_window
;
754 Lisp_Object help_echo_object
;
755 ptrdiff_t help_echo_pos
;
757 /* Temporary variable for XTread_socket. */
759 Lisp_Object previous_help_echo_string
;
761 /* Platform-independent portion of hourglass implementation. */
763 /* Non-zero means an hourglass cursor is currently shown. */
764 int hourglass_shown_p
;
766 /* If non-null, an asynchronous timer that, when it expires, displays
767 an hourglass cursor on all frames. */
768 struct atimer
*hourglass_atimer
;
770 /* Name of the face used to display glyphless characters. */
771 Lisp_Object Qglyphless_char
;
773 /* Symbol for the purpose of Vglyphless_char_display. */
774 static Lisp_Object Qglyphless_char_display
;
776 /* Method symbols for Vglyphless_char_display. */
777 static Lisp_Object Qhex_code
, Qempty_box
, Qthin_space
, Qzero_width
;
779 /* Default pixel width of `thin-space' display method. */
780 #define THIN_SPACE_WIDTH 1
782 /* Default number of seconds to wait before displaying an hourglass
784 #define DEFAULT_HOURGLASS_DELAY 1
787 /* Function prototypes. */
789 static void setup_for_ellipsis (struct it
*, int);
790 static void set_iterator_to_next (struct it
*, int);
791 static void mark_window_display_accurate_1 (struct window
*, int);
792 static int single_display_spec_string_p (Lisp_Object
, Lisp_Object
);
793 static int display_prop_string_p (Lisp_Object
, Lisp_Object
);
794 static int row_for_charpos_p (struct glyph_row
*, ptrdiff_t);
795 static int cursor_row_p (struct glyph_row
*);
796 static int redisplay_mode_lines (Lisp_Object
, int);
797 static char *decode_mode_spec_coding (Lisp_Object
, char *, int);
799 static Lisp_Object
get_it_property (struct it
*it
, Lisp_Object prop
);
801 static void handle_line_prefix (struct it
*);
803 static void pint2str (char *, int, ptrdiff_t);
804 static void pint2hrstr (char *, int, ptrdiff_t);
805 static struct text_pos
run_window_scroll_functions (Lisp_Object
,
807 static void reconsider_clip_changes (struct window
*, struct buffer
*);
808 static int text_outside_line_unchanged_p (struct window
*,
809 ptrdiff_t, ptrdiff_t);
810 static void store_mode_line_noprop_char (char);
811 static int store_mode_line_noprop (const char *, int, int);
812 static void handle_stop (struct it
*);
813 static void handle_stop_backwards (struct it
*, ptrdiff_t);
814 static void vmessage (const char *, va_list) ATTRIBUTE_FORMAT_PRINTF (1, 0);
815 static void ensure_echo_area_buffers (void);
816 static Lisp_Object
unwind_with_echo_area_buffer (Lisp_Object
);
817 static Lisp_Object
with_echo_area_buffer_unwind_data (struct window
*);
818 static int with_echo_area_buffer (struct window
*, int,
819 int (*) (ptrdiff_t, Lisp_Object
),
820 ptrdiff_t, Lisp_Object
);
821 static void clear_garbaged_frames (void);
822 static int current_message_1 (ptrdiff_t, Lisp_Object
);
823 static void pop_message (void);
824 static int truncate_message_1 (ptrdiff_t, Lisp_Object
);
825 static void set_message (Lisp_Object
);
826 static int set_message_1 (ptrdiff_t, Lisp_Object
);
827 static int display_echo_area (struct window
*);
828 static int display_echo_area_1 (ptrdiff_t, Lisp_Object
);
829 static int resize_mini_window_1 (ptrdiff_t, Lisp_Object
);
830 static Lisp_Object
unwind_redisplay (Lisp_Object
);
831 static int string_char_and_length (const unsigned char *, int *);
832 static struct text_pos
display_prop_end (struct it
*, Lisp_Object
,
834 static int compute_window_start_on_continuation_line (struct window
*);
835 static void insert_left_trunc_glyphs (struct it
*);
836 static struct glyph_row
*get_overlay_arrow_glyph_row (struct window
*,
838 static void extend_face_to_end_of_line (struct it
*);
839 static int append_space_for_newline (struct it
*, int);
840 static int cursor_row_fully_visible_p (struct window
*, int, int);
841 static int try_scrolling (Lisp_Object
, int, ptrdiff_t, ptrdiff_t, int, int);
842 static int try_cursor_movement (Lisp_Object
, struct text_pos
, int *);
843 static int trailing_whitespace_p (ptrdiff_t);
844 static intmax_t message_log_check_duplicate (ptrdiff_t, ptrdiff_t);
845 static void push_it (struct it
*, struct text_pos
*);
846 static void iterate_out_of_display_property (struct it
*);
847 static void pop_it (struct it
*);
848 static void sync_frame_with_window_matrix_rows (struct window
*);
849 static void redisplay_internal (void);
850 static int echo_area_display (int);
851 static void redisplay_windows (Lisp_Object
);
852 static void redisplay_window (Lisp_Object
, int);
853 static Lisp_Object
redisplay_window_error (Lisp_Object
);
854 static Lisp_Object
redisplay_window_0 (Lisp_Object
);
855 static Lisp_Object
redisplay_window_1 (Lisp_Object
);
856 static int set_cursor_from_row (struct window
*, struct glyph_row
*,
857 struct glyph_matrix
*, ptrdiff_t, ptrdiff_t,
859 static int update_menu_bar (struct frame
*, int, int);
860 static int try_window_reusing_current_matrix (struct window
*);
861 static int try_window_id (struct window
*);
862 static int display_line (struct it
*);
863 static int display_mode_lines (struct window
*);
864 static int display_mode_line (struct window
*, enum face_id
, Lisp_Object
);
865 static int display_mode_element (struct it
*, int, int, int, Lisp_Object
, Lisp_Object
, int);
866 static int store_mode_line_string (const char *, Lisp_Object
, int, int, int, Lisp_Object
);
867 static const char *decode_mode_spec (struct window
*, int, int, Lisp_Object
*);
868 static void display_menu_bar (struct window
*);
869 static ptrdiff_t display_count_lines (ptrdiff_t, ptrdiff_t, ptrdiff_t,
871 static int display_string (const char *, Lisp_Object
, Lisp_Object
,
872 ptrdiff_t, ptrdiff_t, struct it
*, int, int, int, int);
873 static void compute_line_metrics (struct it
*);
874 static void run_redisplay_end_trigger_hook (struct it
*);
875 static int get_overlay_strings (struct it
*, ptrdiff_t);
876 static int get_overlay_strings_1 (struct it
*, ptrdiff_t, int);
877 static void next_overlay_string (struct it
*);
878 static void reseat (struct it
*, struct text_pos
, int);
879 static void reseat_1 (struct it
*, struct text_pos
, int);
880 static void back_to_previous_visible_line_start (struct it
*);
881 static void reseat_at_next_visible_line_start (struct it
*, int);
882 static int next_element_from_ellipsis (struct it
*);
883 static int next_element_from_display_vector (struct it
*);
884 static int next_element_from_string (struct it
*);
885 static int next_element_from_c_string (struct it
*);
886 static int next_element_from_buffer (struct it
*);
887 static int next_element_from_composition (struct it
*);
888 static int next_element_from_image (struct it
*);
889 static int next_element_from_stretch (struct it
*);
890 static void load_overlay_strings (struct it
*, ptrdiff_t);
891 static int init_from_display_pos (struct it
*, struct window
*,
892 struct display_pos
*);
893 static void reseat_to_string (struct it
*, const char *,
894 Lisp_Object
, ptrdiff_t, ptrdiff_t, int, int);
895 static int get_next_display_element (struct it
*);
896 static enum move_it_result
897 move_it_in_display_line_to (struct it
*, ptrdiff_t, int,
898 enum move_operation_enum
);
899 static void get_visually_first_element (struct it
*);
900 static void init_to_row_start (struct it
*, struct window
*,
902 static int init_to_row_end (struct it
*, struct window
*,
904 static void back_to_previous_line_start (struct it
*);
905 static int forward_to_next_line_start (struct it
*, int *, struct bidi_it
*);
906 static struct text_pos
string_pos_nchars_ahead (struct text_pos
,
907 Lisp_Object
, ptrdiff_t);
908 static struct text_pos
string_pos (ptrdiff_t, Lisp_Object
);
909 static struct text_pos
c_string_pos (ptrdiff_t, const char *, bool);
910 static ptrdiff_t number_of_chars (const char *, bool);
911 static void compute_stop_pos (struct it
*);
912 static void compute_string_pos (struct text_pos
*, struct text_pos
,
914 static int face_before_or_after_it_pos (struct it
*, int);
915 static ptrdiff_t next_overlay_change (ptrdiff_t);
916 static int handle_display_spec (struct it
*, Lisp_Object
, Lisp_Object
,
917 Lisp_Object
, struct text_pos
*, ptrdiff_t, int);
918 static int handle_single_display_spec (struct it
*, Lisp_Object
,
919 Lisp_Object
, Lisp_Object
,
920 struct text_pos
*, ptrdiff_t, int, int);
921 static int underlying_face_id (struct it
*);
922 static int in_ellipses_for_invisible_text_p (struct display_pos
*,
925 #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1)
926 #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0)
928 #ifdef HAVE_WINDOW_SYSTEM
930 static void x_consider_frame_title (Lisp_Object
);
931 static int tool_bar_lines_needed (struct frame
*, int *);
932 static void update_tool_bar (struct frame
*, int);
933 static void build_desired_tool_bar_string (struct frame
*f
);
934 static int redisplay_tool_bar (struct frame
*);
935 static void display_tool_bar_line (struct it
*, int);
936 static void notice_overwritten_cursor (struct window
*,
939 static void append_stretch_glyph (struct it
*, Lisp_Object
,
943 #endif /* HAVE_WINDOW_SYSTEM */
945 static void produce_special_glyphs (struct it
*, enum display_element_type
);
946 static void show_mouse_face (Mouse_HLInfo
*, enum draw_glyphs_face
);
947 static int coords_in_mouse_face_p (struct window
*, int, int);
951 /***********************************************************************
952 Window display dimensions
953 ***********************************************************************/
955 /* Return the bottom boundary y-position for text lines in window W.
956 This is the first y position at which a line cannot start.
957 It is relative to the top of the window.
959 This is the height of W minus the height of a mode line, if any. */
962 window_text_bottom_y (struct window
*w
)
964 int height
= WINDOW_TOTAL_HEIGHT (w
);
966 if (WINDOW_WANTS_MODELINE_P (w
))
967 height
-= CURRENT_MODE_LINE_HEIGHT (w
);
971 /* Return the pixel width of display area AREA of window W. AREA < 0
972 means return the total width of W, not including fringes to
973 the left and right of the window. */
976 window_box_width (struct window
*w
, int area
)
978 int cols
= w
->total_cols
;
981 if (!w
->pseudo_window_p
)
983 cols
-= WINDOW_SCROLL_BAR_COLS (w
);
985 if (area
== TEXT_AREA
)
987 if (INTEGERP (w
->left_margin_cols
))
988 cols
-= XFASTINT (w
->left_margin_cols
);
989 if (INTEGERP (w
->right_margin_cols
))
990 cols
-= XFASTINT (w
->right_margin_cols
);
991 pixels
= -WINDOW_TOTAL_FRINGE_WIDTH (w
);
993 else if (area
== LEFT_MARGIN_AREA
)
995 cols
= (INTEGERP (w
->left_margin_cols
)
996 ? XFASTINT (w
->left_margin_cols
) : 0);
999 else if (area
== RIGHT_MARGIN_AREA
)
1001 cols
= (INTEGERP (w
->right_margin_cols
)
1002 ? XFASTINT (w
->right_margin_cols
) : 0);
1007 return cols
* WINDOW_FRAME_COLUMN_WIDTH (w
) + pixels
;
1011 /* Return the pixel height of the display area of window W, not
1012 including mode lines of W, if any. */
1015 window_box_height (struct window
*w
)
1017 struct frame
*f
= XFRAME (w
->frame
);
1018 int height
= WINDOW_TOTAL_HEIGHT (w
);
1020 eassert (height
>= 0);
1022 /* Note: the code below that determines the mode-line/header-line
1023 height is essentially the same as that contained in the macro
1024 CURRENT_{MODE,HEADER}_LINE_HEIGHT, except that it checks whether
1025 the appropriate glyph row has its `mode_line_p' flag set,
1026 and if it doesn't, uses estimate_mode_line_height instead. */
1028 if (WINDOW_WANTS_MODELINE_P (w
))
1030 struct glyph_row
*ml_row
1031 = (w
->current_matrix
&& w
->current_matrix
->rows
1032 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
1034 if (ml_row
&& ml_row
->mode_line_p
)
1035 height
-= ml_row
->height
;
1037 height
-= estimate_mode_line_height (f
, CURRENT_MODE_LINE_FACE_ID (w
));
1040 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1042 struct glyph_row
*hl_row
1043 = (w
->current_matrix
&& w
->current_matrix
->rows
1044 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
1046 if (hl_row
&& hl_row
->mode_line_p
)
1047 height
-= hl_row
->height
;
1049 height
-= estimate_mode_line_height (f
, HEADER_LINE_FACE_ID
);
1052 /* With a very small font and a mode-line that's taller than
1053 default, we might end up with a negative height. */
1054 return max (0, height
);
1057 /* Return the window-relative coordinate of the left edge of display
1058 area AREA of window W. AREA < 0 means return the left edge of the
1059 whole window, to the right of the left fringe of W. */
1062 window_box_left_offset (struct window
*w
, int area
)
1066 if (w
->pseudo_window_p
)
1069 x
= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
1071 if (area
== TEXT_AREA
)
1072 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1073 + window_box_width (w
, LEFT_MARGIN_AREA
));
1074 else if (area
== RIGHT_MARGIN_AREA
)
1075 x
+= (WINDOW_LEFT_FRINGE_WIDTH (w
)
1076 + window_box_width (w
, LEFT_MARGIN_AREA
)
1077 + window_box_width (w
, TEXT_AREA
)
1078 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1080 : WINDOW_RIGHT_FRINGE_WIDTH (w
)));
1081 else if (area
== LEFT_MARGIN_AREA
1082 && WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1083 x
+= WINDOW_LEFT_FRINGE_WIDTH (w
);
1089 /* Return the window-relative coordinate of the right edge of display
1090 area AREA of window W. AREA < 0 means return the right edge of the
1091 whole window, to the left of the right fringe of W. */
1094 window_box_right_offset (struct window
*w
, int area
)
1096 return window_box_left_offset (w
, area
) + window_box_width (w
, area
);
1099 /* Return the frame-relative coordinate of the left edge of display
1100 area AREA of window W. AREA < 0 means return the left edge of the
1101 whole window, to the right of the left fringe of W. */
1104 window_box_left (struct window
*w
, int area
)
1106 struct frame
*f
= XFRAME (w
->frame
);
1109 if (w
->pseudo_window_p
)
1110 return FRAME_INTERNAL_BORDER_WIDTH (f
);
1112 x
= (WINDOW_LEFT_EDGE_X (w
)
1113 + window_box_left_offset (w
, area
));
1119 /* Return the frame-relative coordinate of the right edge of display
1120 area AREA of window W. AREA < 0 means return the right edge of the
1121 whole window, to the left of the right fringe of W. */
1124 window_box_right (struct window
*w
, int area
)
1126 return window_box_left (w
, area
) + window_box_width (w
, area
);
1129 /* Get the bounding box of the display area AREA of window W, without
1130 mode lines, in frame-relative coordinates. AREA < 0 means the
1131 whole window, not including the left and right fringes of
1132 the window. Return in *BOX_X and *BOX_Y the frame-relative pixel
1133 coordinates of the upper-left corner of the box. Return in
1134 *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */
1137 window_box (struct window
*w
, int area
, int *box_x
, int *box_y
,
1138 int *box_width
, int *box_height
)
1141 *box_width
= window_box_width (w
, area
);
1143 *box_height
= window_box_height (w
);
1145 *box_x
= window_box_left (w
, area
);
1148 *box_y
= WINDOW_TOP_EDGE_Y (w
);
1149 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1150 *box_y
+= CURRENT_HEADER_LINE_HEIGHT (w
);
1155 /* Get the bounding box of the display area AREA of window W, without
1156 mode lines. AREA < 0 means the whole window, not including the
1157 left and right fringe of the window. Return in *TOP_LEFT_X
1158 and TOP_LEFT_Y the frame-relative pixel coordinates of the
1159 upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and
1160 *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the
1164 window_box_edges (struct window
*w
, int area
, int *top_left_x
, int *top_left_y
,
1165 int *bottom_right_x
, int *bottom_right_y
)
1167 window_box (w
, area
, top_left_x
, top_left_y
, bottom_right_x
,
1169 *bottom_right_x
+= *top_left_x
;
1170 *bottom_right_y
+= *top_left_y
;
1175 /***********************************************************************
1177 ***********************************************************************/
1179 /* Return the bottom y-position of the line the iterator IT is in.
1180 This can modify IT's settings. */
1183 line_bottom_y (struct it
*it
)
1185 int line_height
= it
->max_ascent
+ it
->max_descent
;
1186 int line_top_y
= it
->current_y
;
1188 if (line_height
== 0)
1191 line_height
= last_height
;
1192 else if (IT_CHARPOS (*it
) < ZV
)
1194 move_it_by_lines (it
, 1);
1195 line_height
= (it
->max_ascent
|| it
->max_descent
1196 ? it
->max_ascent
+ it
->max_descent
1201 struct glyph_row
*row
= it
->glyph_row
;
1203 /* Use the default character height. */
1204 it
->glyph_row
= NULL
;
1205 it
->what
= IT_CHARACTER
;
1208 PRODUCE_GLYPHS (it
);
1209 line_height
= it
->ascent
+ it
->descent
;
1210 it
->glyph_row
= row
;
1214 return line_top_y
+ line_height
;
1217 DEFUN ("line-pixel-height", Fline_pixel_height
,
1218 Sline_pixel_height
, 0, 0, 0,
1219 doc
: /* Return height in pixels of text line in the selected window.
1221 Value is the height in pixels of the line at point. */)
1226 struct window
*w
= XWINDOW (selected_window
);
1228 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
1229 start_display (&it
, w
, pt
);
1230 it
.vpos
= it
.current_y
= 0;
1232 return make_number (line_bottom_y (&it
));
1235 /* Return the default pixel height of text lines in window W. The
1236 value is the canonical height of the W frame's default font, plus
1237 any extra space required by the line-spacing variable or frame
1240 Implementation note: this ignores any line-spacing text properties
1241 put on the newline characters. This is because those properties
1242 only affect the _screen_ line ending in the newline (i.e., in a
1243 continued line, only the last screen line will be affected), which
1244 means only a small number of lines in a buffer can ever use this
1245 feature. Since this function is used to compute the default pixel
1246 equivalent of text lines in a window, we can safely ignore those
1247 few lines. For the same reasons, we ignore the line-height
1250 default_line_pixel_height (struct window
*w
)
1252 struct frame
*f
= WINDOW_XFRAME (w
);
1253 int height
= FRAME_LINE_HEIGHT (f
);
1255 if (!FRAME_INITIAL_P (f
) && BUFFERP (w
->contents
))
1257 struct buffer
*b
= XBUFFER (w
->contents
);
1258 Lisp_Object val
= BVAR (b
, extra_line_spacing
);
1261 val
= BVAR (&buffer_defaults
, extra_line_spacing
);
1264 if (RANGED_INTEGERP (0, val
, INT_MAX
))
1265 height
+= XFASTINT (val
);
1266 else if (FLOATP (val
))
1268 int addon
= XFLOAT_DATA (val
) * height
+ 0.5;
1275 height
+= f
->extra_line_spacing
;
1281 /* Subroutine of pos_visible_p below. Extracts a display string, if
1282 any, from the display spec given as its argument. */
1284 string_from_display_spec (Lisp_Object spec
)
1288 while (CONSP (spec
))
1290 if (STRINGP (XCAR (spec
)))
1295 else if (VECTORP (spec
))
1299 for (i
= 0; i
< ASIZE (spec
); i
++)
1301 if (STRINGP (AREF (spec
, i
)))
1302 return AREF (spec
, i
);
1311 /* Limit insanely large values of W->hscroll on frame F to the largest
1312 value that will still prevent first_visible_x and last_visible_x of
1313 'struct it' from overflowing an int. */
1315 window_hscroll_limited (struct window
*w
, struct frame
*f
)
1317 ptrdiff_t window_hscroll
= w
->hscroll
;
1318 int window_text_width
= window_box_width (w
, TEXT_AREA
);
1319 int colwidth
= FRAME_COLUMN_WIDTH (f
);
1321 if (window_hscroll
> (INT_MAX
- window_text_width
) / colwidth
- 1)
1322 window_hscroll
= (INT_MAX
- window_text_width
) / colwidth
- 1;
1324 return window_hscroll
;
1327 /* Return 1 if position CHARPOS is visible in window W.
1328 CHARPOS < 0 means return info about WINDOW_END position.
1329 If visible, set *X and *Y to pixel coordinates of top left corner.
1330 Set *RTOP and *RBOT to pixel height of an invisible area of glyph at POS.
1331 Set *ROWH and *VPOS to row's visible height and VPOS (row number). */
1334 pos_visible_p (struct window
*w
, ptrdiff_t charpos
, int *x
, int *y
,
1335 int *rtop
, int *rbot
, int *rowh
, int *vpos
)
1338 void *itdata
= bidi_shelve_cache ();
1339 struct text_pos top
;
1341 struct buffer
*old_buffer
= NULL
;
1343 if (FRAME_INITIAL_P (XFRAME (WINDOW_FRAME (w
))))
1346 if (XBUFFER (w
->contents
) != current_buffer
)
1348 old_buffer
= current_buffer
;
1349 set_buffer_internal_1 (XBUFFER (w
->contents
));
1352 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1353 /* Scrolling a minibuffer window via scroll bar when the echo area
1354 shows long text sometimes resets the minibuffer contents behind
1356 if (CHARPOS (top
) > ZV
)
1357 SET_TEXT_POS (top
, BEGV
, BEGV_BYTE
);
1359 /* Compute exact mode line heights. */
1360 if (WINDOW_WANTS_MODELINE_P (w
))
1361 current_mode_line_height
1362 = display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID (w
),
1363 BVAR (current_buffer
, mode_line_format
));
1365 if (WINDOW_WANTS_HEADER_LINE_P (w
))
1366 current_header_line_height
1367 = display_mode_line (w
, HEADER_LINE_FACE_ID
,
1368 BVAR (current_buffer
, header_line_format
));
1370 start_display (&it
, w
, top
);
1371 move_it_to (&it
, charpos
, -1, it
.last_visible_y
- 1, -1,
1372 (charpos
>= 0 ? MOVE_TO_POS
: 0) | MOVE_TO_Y
);
1375 && (((!it
.bidi_p
|| it
.bidi_it
.scan_dir
== 1)
1376 && IT_CHARPOS (it
) >= charpos
)
1377 /* When scanning backwards under bidi iteration, move_it_to
1378 stops at or _before_ CHARPOS, because it stops at or to
1379 the _right_ of the character at CHARPOS. */
1380 || (it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1381 && IT_CHARPOS (it
) <= charpos
)))
1383 /* We have reached CHARPOS, or passed it. How the call to
1384 move_it_to can overshoot: (i) If CHARPOS is on invisible text
1385 or covered by a display property, move_it_to stops at the end
1386 of the invisible text, to the right of CHARPOS. (ii) If
1387 CHARPOS is in a display vector, move_it_to stops on its last
1389 int top_x
= it
.current_x
;
1390 int top_y
= it
.current_y
;
1391 /* Calling line_bottom_y may change it.method, it.position, etc. */
1392 enum it_method it_method
= it
.method
;
1393 int bottom_y
= (last_height
= 0, line_bottom_y (&it
));
1394 int window_top_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
1396 if (top_y
< window_top_y
)
1397 visible_p
= bottom_y
> window_top_y
;
1398 else if (top_y
< it
.last_visible_y
)
1400 if (bottom_y
>= it
.last_visible_y
1401 && it
.bidi_p
&& it
.bidi_it
.scan_dir
== -1
1402 && IT_CHARPOS (it
) < charpos
)
1404 /* When the last line of the window is scanned backwards
1405 under bidi iteration, we could be duped into thinking
1406 that we have passed CHARPOS, when in fact move_it_to
1407 simply stopped short of CHARPOS because it reached
1408 last_visible_y. To see if that's what happened, we call
1409 move_it_to again with a slightly larger vertical limit,
1410 and see if it actually moved vertically; if it did, we
1411 didn't really reach CHARPOS, which is beyond window end. */
1412 struct it save_it
= it
;
1413 /* Why 10? because we don't know how many canonical lines
1414 will the height of the next line(s) be. So we guess. */
1415 int ten_more_lines
= 10 * default_line_pixel_height (w
);
1417 move_it_to (&it
, charpos
, -1, bottom_y
+ ten_more_lines
, -1,
1418 MOVE_TO_POS
| MOVE_TO_Y
);
1419 if (it
.current_y
> top_y
)
1426 if (it_method
== GET_FROM_DISPLAY_VECTOR
)
1428 /* We stopped on the last glyph of a display vector.
1429 Try and recompute. Hack alert! */
1430 if (charpos
< 2 || top
.charpos
>= charpos
)
1431 top_x
= it
.glyph_row
->x
;
1434 struct it it2
, it2_prev
;
1435 /* The idea is to get to the previous buffer
1436 position, consume the character there, and use
1437 the pixel coordinates we get after that. But if
1438 the previous buffer position is also displayed
1439 from a display vector, we need to consume all of
1440 the glyphs from that display vector. */
1441 start_display (&it2
, w
, top
);
1442 move_it_to (&it2
, charpos
- 1, -1, -1, -1, MOVE_TO_POS
);
1443 /* If we didn't get to CHARPOS - 1, there's some
1444 replacing display property at that position, and
1445 we stopped after it. That is exactly the place
1446 whose coordinates we want. */
1447 if (IT_CHARPOS (it2
) != charpos
- 1)
1451 /* Iterate until we get out of the display
1452 vector that displays the character at
1455 get_next_display_element (&it2
);
1456 PRODUCE_GLYPHS (&it2
);
1458 set_iterator_to_next (&it2
, 1);
1459 } while (it2
.method
== GET_FROM_DISPLAY_VECTOR
1460 && IT_CHARPOS (it2
) < charpos
);
1462 if (ITERATOR_AT_END_OF_LINE_P (&it2_prev
)
1463 || it2_prev
.current_x
> it2_prev
.last_visible_x
)
1464 top_x
= it
.glyph_row
->x
;
1467 top_x
= it2_prev
.current_x
;
1468 top_y
= it2_prev
.current_y
;
1472 else if (IT_CHARPOS (it
) != charpos
)
1474 Lisp_Object cpos
= make_number (charpos
);
1475 Lisp_Object spec
= Fget_char_property (cpos
, Qdisplay
, Qnil
);
1476 Lisp_Object string
= string_from_display_spec (spec
);
1477 struct text_pos tpos
;
1478 int replacing_spec_p
;
1479 bool newline_in_string
1481 && memchr (SDATA (string
), '\n', SBYTES (string
)));
1483 SET_TEXT_POS (tpos
, charpos
, CHAR_TO_BYTE (charpos
));
1486 && handle_display_spec (NULL
, spec
, Qnil
, Qnil
, &tpos
,
1487 charpos
, FRAME_WINDOW_P (it
.f
)));
1488 /* The tricky code below is needed because there's a
1489 discrepancy between move_it_to and how we set cursor
1490 when PT is at the beginning of a portion of text
1491 covered by a display property or an overlay with a
1492 display property, or the display line ends in a
1493 newline from a display string. move_it_to will stop
1494 _after_ such display strings, whereas
1495 set_cursor_from_row conspires with cursor_row_p to
1496 place the cursor on the first glyph produced from the
1499 /* We have overshoot PT because it is covered by a
1500 display property that replaces the text it covers.
1501 If the string includes embedded newlines, we are also
1502 in the wrong display line. Backtrack to the correct
1503 line, where the display property begins. */
1504 if (replacing_spec_p
)
1506 Lisp_Object startpos
, endpos
;
1507 EMACS_INT start
, end
;
1511 /* Find the first and the last buffer positions
1512 covered by the display string. */
1514 Fnext_single_char_property_change (cpos
, Qdisplay
,
1517 Fprevious_single_char_property_change (endpos
, Qdisplay
,
1519 start
= XFASTINT (startpos
);
1520 end
= XFASTINT (endpos
);
1521 /* Move to the last buffer position before the
1522 display property. */
1523 start_display (&it3
, w
, top
);
1524 move_it_to (&it3
, start
- 1, -1, -1, -1, MOVE_TO_POS
);
1525 /* Move forward one more line if the position before
1526 the display string is a newline or if it is the
1527 rightmost character on a line that is
1528 continued or word-wrapped. */
1529 if (it3
.method
== GET_FROM_BUFFER
1531 || FETCH_BYTE (IT_BYTEPOS (it3
)) == '\n'))
1532 move_it_by_lines (&it3
, 1);
1533 else if (move_it_in_display_line_to (&it3
, -1,
1537 == MOVE_LINE_CONTINUED
)
1539 move_it_by_lines (&it3
, 1);
1540 /* When we are under word-wrap, the #$@%!
1541 move_it_by_lines moves 2 lines, so we need to
1543 if (it3
.line_wrap
== WORD_WRAP
)
1544 move_it_by_lines (&it3
, -1);
1547 /* Record the vertical coordinate of the display
1548 line where we wound up. */
1549 top_y
= it3
.current_y
;
1552 /* When characters are reordered for display,
1553 the character displayed to the left of the
1554 display string could be _after_ the display
1555 property in the logical order. Use the
1556 smallest vertical position of these two. */
1557 start_display (&it3
, w
, top
);
1558 move_it_to (&it3
, end
+ 1, -1, -1, -1, MOVE_TO_POS
);
1559 if (it3
.current_y
< top_y
)
1560 top_y
= it3
.current_y
;
1562 /* Move from the top of the window to the beginning
1563 of the display line where the display string
1565 start_display (&it3
, w
, top
);
1566 move_it_to (&it3
, -1, 0, top_y
, -1, MOVE_TO_X
| MOVE_TO_Y
);
1567 /* If it3_moved stays zero after the 'while' loop
1568 below, that means we already were at a newline
1569 before the loop (e.g., the display string begins
1570 with a newline), so we don't need to (and cannot)
1571 inspect the glyphs of it3.glyph_row, because
1572 PRODUCE_GLYPHS will not produce anything for a
1573 newline, and thus it3.glyph_row stays at its
1574 stale content it got at top of the window. */
1576 /* Finally, advance the iterator until we hit the
1577 first display element whose character position is
1578 CHARPOS, or until the first newline from the
1579 display string, which signals the end of the
1581 while (get_next_display_element (&it3
))
1583 PRODUCE_GLYPHS (&it3
);
1584 if (IT_CHARPOS (it3
) == charpos
1585 || ITERATOR_AT_END_OF_LINE_P (&it3
))
1588 set_iterator_to_next (&it3
, 0);
1590 top_x
= it3
.current_x
- it3
.pixel_width
;
1591 /* Normally, we would exit the above loop because we
1592 found the display element whose character
1593 position is CHARPOS. For the contingency that we
1594 didn't, and stopped at the first newline from the
1595 display string, move back over the glyphs
1596 produced from the string, until we find the
1597 rightmost glyph not from the string. */
1599 && newline_in_string
1600 && IT_CHARPOS (it3
) != charpos
&& EQ (it3
.object
, string
))
1602 struct glyph
*g
= it3
.glyph_row
->glyphs
[TEXT_AREA
]
1603 + it3
.glyph_row
->used
[TEXT_AREA
];
1605 while (EQ ((g
- 1)->object
, string
))
1608 top_x
-= g
->pixel_width
;
1610 eassert (g
< it3
.glyph_row
->glyphs
[TEXT_AREA
]
1611 + it3
.glyph_row
->used
[TEXT_AREA
]);
1617 *y
= max (top_y
+ max (0, it
.max_ascent
- it
.ascent
), window_top_y
);
1618 *rtop
= max (0, window_top_y
- top_y
);
1619 *rbot
= max (0, bottom_y
- it
.last_visible_y
);
1620 *rowh
= max (0, (min (bottom_y
, it
.last_visible_y
)
1621 - max (top_y
, window_top_y
)));
1627 /* We were asked to provide info about WINDOW_END. */
1629 void *it2data
= NULL
;
1631 SAVE_IT (it2
, it
, it2data
);
1632 if (IT_CHARPOS (it
) < ZV
&& FETCH_BYTE (IT_BYTEPOS (it
)) != '\n')
1633 move_it_by_lines (&it
, 1);
1634 if (charpos
< IT_CHARPOS (it
)
1635 || (it
.what
== IT_EOB
&& charpos
== IT_CHARPOS (it
)))
1638 RESTORE_IT (&it2
, &it2
, it2data
);
1639 move_it_to (&it2
, charpos
, -1, -1, -1, MOVE_TO_POS
);
1641 *y
= it2
.current_y
+ it2
.max_ascent
- it2
.ascent
;
1642 *rtop
= max (0, -it2
.current_y
);
1643 *rbot
= max (0, ((it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
)
1644 - it
.last_visible_y
));
1645 *rowh
= max (0, (min (it2
.current_y
+ it2
.max_ascent
+ it2
.max_descent
,
1647 - max (it2
.current_y
,
1648 WINDOW_HEADER_LINE_HEIGHT (w
))));
1652 bidi_unshelve_cache (it2data
, 1);
1654 bidi_unshelve_cache (itdata
, 0);
1657 set_buffer_internal_1 (old_buffer
);
1659 current_header_line_height
= current_mode_line_height
= -1;
1661 if (visible_p
&& w
->hscroll
> 0)
1663 window_hscroll_limited (w
, WINDOW_XFRAME (w
))
1664 * WINDOW_FRAME_COLUMN_WIDTH (w
);
1667 /* Debugging code. */
1669 fprintf (stderr
, "+pv pt=%d vs=%d --> x=%d y=%d rt=%d rb=%d rh=%d vp=%d\n",
1670 charpos
, w
->vscroll
, *x
, *y
, *rtop
, *rbot
, *rowh
, *vpos
);
1672 fprintf (stderr
, "-pv pt=%d vs=%d\n", charpos
, w
->vscroll
);
1679 /* Return the next character from STR. Return in *LEN the length of
1680 the character. This is like STRING_CHAR_AND_LENGTH but never
1681 returns an invalid character. If we find one, we return a `?', but
1682 with the length of the invalid character. */
1685 string_char_and_length (const unsigned char *str
, int *len
)
1689 c
= STRING_CHAR_AND_LENGTH (str
, *len
);
1690 if (!CHAR_VALID_P (c
))
1691 /* We may not change the length here because other places in Emacs
1692 don't use this function, i.e. they silently accept invalid
1701 /* Given a position POS containing a valid character and byte position
1702 in STRING, return the position NCHARS ahead (NCHARS >= 0). */
1704 static struct text_pos
1705 string_pos_nchars_ahead (struct text_pos pos
, Lisp_Object string
, ptrdiff_t nchars
)
1707 eassert (STRINGP (string
) && nchars
>= 0);
1709 if (STRING_MULTIBYTE (string
))
1711 const unsigned char *p
= SDATA (string
) + BYTEPOS (pos
);
1716 string_char_and_length (p
, &len
);
1719 BYTEPOS (pos
) += len
;
1723 SET_TEXT_POS (pos
, CHARPOS (pos
) + nchars
, BYTEPOS (pos
) + nchars
);
1729 /* Value is the text position, i.e. character and byte position,
1730 for character position CHARPOS in STRING. */
1732 static struct text_pos
1733 string_pos (ptrdiff_t charpos
, Lisp_Object string
)
1735 struct text_pos pos
;
1736 eassert (STRINGP (string
));
1737 eassert (charpos
>= 0);
1738 SET_TEXT_POS (pos
, charpos
, string_char_to_byte (string
, charpos
));
1743 /* Value is a text position, i.e. character and byte position, for
1744 character position CHARPOS in C string S. MULTIBYTE_P non-zero
1745 means recognize multibyte characters. */
1747 static struct text_pos
1748 c_string_pos (ptrdiff_t charpos
, const char *s
, bool multibyte_p
)
1750 struct text_pos pos
;
1752 eassert (s
!= NULL
);
1753 eassert (charpos
>= 0);
1759 SET_TEXT_POS (pos
, 0, 0);
1762 string_char_and_length ((const unsigned char *) s
, &len
);
1765 BYTEPOS (pos
) += len
;
1769 SET_TEXT_POS (pos
, charpos
, charpos
);
1775 /* Value is the number of characters in C string S. MULTIBYTE_P
1776 non-zero means recognize multibyte characters. */
1779 number_of_chars (const char *s
, bool multibyte_p
)
1785 ptrdiff_t rest
= strlen (s
);
1787 const unsigned char *p
= (const unsigned char *) s
;
1789 for (nchars
= 0; rest
> 0; ++nchars
)
1791 string_char_and_length (p
, &len
);
1792 rest
-= len
, p
+= len
;
1796 nchars
= strlen (s
);
1802 /* Compute byte position NEWPOS->bytepos corresponding to
1803 NEWPOS->charpos. POS is a known position in string STRING.
1804 NEWPOS->charpos must be >= POS.charpos. */
1807 compute_string_pos (struct text_pos
*newpos
, struct text_pos pos
, Lisp_Object string
)
1809 eassert (STRINGP (string
));
1810 eassert (CHARPOS (*newpos
) >= CHARPOS (pos
));
1812 if (STRING_MULTIBYTE (string
))
1813 *newpos
= string_pos_nchars_ahead (pos
, string
,
1814 CHARPOS (*newpos
) - CHARPOS (pos
));
1816 BYTEPOS (*newpos
) = CHARPOS (*newpos
);
1820 Return an estimation of the pixel height of mode or header lines on
1821 frame F. FACE_ID specifies what line's height to estimate. */
1824 estimate_mode_line_height (struct frame
*f
, enum face_id face_id
)
1826 #ifdef HAVE_WINDOW_SYSTEM
1827 if (FRAME_WINDOW_P (f
))
1829 int height
= FONT_HEIGHT (FRAME_FONT (f
));
1831 /* This function is called so early when Emacs starts that the face
1832 cache and mode line face are not yet initialized. */
1833 if (FRAME_FACE_CACHE (f
))
1835 struct face
*face
= FACE_FROM_ID (f
, face_id
);
1839 height
= FONT_HEIGHT (face
->font
);
1840 if (face
->box_line_width
> 0)
1841 height
+= 2 * face
->box_line_width
;
1852 /* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1853 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1854 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1855 not force the value into range. */
1858 pixel_to_glyph_coords (FRAME_PTR f
, register int pix_x
, register int pix_y
,
1859 int *x
, int *y
, NativeRectangle
*bounds
, int noclip
)
1862 #ifdef HAVE_WINDOW_SYSTEM
1863 if (FRAME_WINDOW_P (f
))
1865 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to round down
1866 even for negative values. */
1868 pix_x
-= FRAME_COLUMN_WIDTH (f
) - 1;
1870 pix_y
-= FRAME_LINE_HEIGHT (f
) - 1;
1872 pix_x
= FRAME_PIXEL_X_TO_COL (f
, pix_x
);
1873 pix_y
= FRAME_PIXEL_Y_TO_LINE (f
, pix_y
);
1876 STORE_NATIVE_RECT (*bounds
,
1877 FRAME_COL_TO_PIXEL_X (f
, pix_x
),
1878 FRAME_LINE_TO_PIXEL_Y (f
, pix_y
),
1879 FRAME_COLUMN_WIDTH (f
) - 1,
1880 FRAME_LINE_HEIGHT (f
) - 1);
1886 else if (pix_x
> FRAME_TOTAL_COLS (f
))
1887 pix_x
= FRAME_TOTAL_COLS (f
);
1891 else if (pix_y
> FRAME_LINES (f
))
1892 pix_y
= FRAME_LINES (f
);
1902 /* Find the glyph under window-relative coordinates X/Y in window W.
1903 Consider only glyphs from buffer text, i.e. no glyphs from overlay
1904 strings. Return in *HPOS and *VPOS the row and column number of
1905 the glyph found. Return in *AREA the glyph area containing X.
1906 Value is a pointer to the glyph found or null if X/Y is not on
1907 text, or we can't tell because W's current matrix is not up to
1912 x_y_to_hpos_vpos (struct window
*w
, int x
, int y
, int *hpos
, int *vpos
,
1913 int *dx
, int *dy
, int *area
)
1915 struct glyph
*glyph
, *end
;
1916 struct glyph_row
*row
= NULL
;
1919 /* Find row containing Y. Give up if some row is not enabled. */
1920 for (i
= 0; i
< w
->current_matrix
->nrows
; ++i
)
1922 row
= MATRIX_ROW (w
->current_matrix
, i
);
1923 if (!row
->enabled_p
)
1925 if (y
>= row
->y
&& y
< MATRIX_ROW_BOTTOM_Y (row
))
1932 /* Give up if Y is not in the window. */
1933 if (i
== w
->current_matrix
->nrows
)
1936 /* Get the glyph area containing X. */
1937 if (w
->pseudo_window_p
)
1944 if (x
< window_box_left_offset (w
, TEXT_AREA
))
1946 *area
= LEFT_MARGIN_AREA
;
1947 x0
= window_box_left_offset (w
, LEFT_MARGIN_AREA
);
1949 else if (x
< window_box_right_offset (w
, TEXT_AREA
))
1952 x0
= window_box_left_offset (w
, TEXT_AREA
) + min (row
->x
, 0);
1956 *area
= RIGHT_MARGIN_AREA
;
1957 x0
= window_box_left_offset (w
, RIGHT_MARGIN_AREA
);
1961 /* Find glyph containing X. */
1962 glyph
= row
->glyphs
[*area
];
1963 end
= glyph
+ row
->used
[*area
];
1965 while (glyph
< end
&& x
>= glyph
->pixel_width
)
1967 x
-= glyph
->pixel_width
;
1977 *dy
= y
- (row
->y
+ row
->ascent
- glyph
->ascent
);
1980 *hpos
= glyph
- row
->glyphs
[*area
];
1984 /* Convert frame-relative x/y to coordinates relative to window W.
1985 Takes pseudo-windows into account. */
1988 frame_to_window_pixel_xy (struct window
*w
, int *x
, int *y
)
1990 if (w
->pseudo_window_p
)
1992 /* A pseudo-window is always full-width, and starts at the
1993 left edge of the frame, plus a frame border. */
1994 struct frame
*f
= XFRAME (w
->frame
);
1995 *x
-= FRAME_INTERNAL_BORDER_WIDTH (f
);
1996 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2000 *x
-= WINDOW_LEFT_EDGE_X (w
);
2001 *y
= FRAME_TO_WINDOW_PIXEL_Y (w
, *y
);
2005 #ifdef HAVE_WINDOW_SYSTEM
2008 Return in RECTS[] at most N clipping rectangles for glyph string S.
2009 Return the number of stored rectangles. */
2012 get_glyph_string_clip_rects (struct glyph_string
*s
, NativeRectangle
*rects
, int n
)
2019 if (s
->row
->full_width_p
)
2021 /* Draw full-width. X coordinates are relative to S->w->left_col. */
2022 r
.x
= WINDOW_LEFT_EDGE_X (s
->w
);
2023 r
.width
= WINDOW_TOTAL_WIDTH (s
->w
);
2025 /* Unless displaying a mode or menu bar line, which are always
2026 fully visible, clip to the visible part of the row. */
2027 if (s
->w
->pseudo_window_p
)
2028 r
.height
= s
->row
->visible_height
;
2030 r
.height
= s
->height
;
2034 /* This is a text line that may be partially visible. */
2035 r
.x
= window_box_left (s
->w
, s
->area
);
2036 r
.width
= window_box_width (s
->w
, s
->area
);
2037 r
.height
= s
->row
->visible_height
;
2041 if (r
.x
< s
->clip_head
->x
)
2043 if (r
.width
>= s
->clip_head
->x
- r
.x
)
2044 r
.width
-= s
->clip_head
->x
- r
.x
;
2047 r
.x
= s
->clip_head
->x
;
2050 if (r
.x
+ r
.width
> s
->clip_tail
->x
+ s
->clip_tail
->background_width
)
2052 if (s
->clip_tail
->x
+ s
->clip_tail
->background_width
>= r
.x
)
2053 r
.width
= s
->clip_tail
->x
+ s
->clip_tail
->background_width
- r
.x
;
2058 /* If S draws overlapping rows, it's sufficient to use the top and
2059 bottom of the window for clipping because this glyph string
2060 intentionally draws over other lines. */
2061 if (s
->for_overlaps
)
2063 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2064 r
.height
= window_text_bottom_y (s
->w
) - r
.y
;
2066 /* Alas, the above simple strategy does not work for the
2067 environments with anti-aliased text: if the same text is
2068 drawn onto the same place multiple times, it gets thicker.
2069 If the overlap we are processing is for the erased cursor, we
2070 take the intersection with the rectangle of the cursor. */
2071 if (s
->for_overlaps
& OVERLAPS_ERASED_CURSOR
)
2073 XRectangle rc
, r_save
= r
;
2075 rc
.x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (s
->w
, s
->w
->phys_cursor
.x
);
2076 rc
.y
= s
->w
->phys_cursor
.y
;
2077 rc
.width
= s
->w
->phys_cursor_width
;
2078 rc
.height
= s
->w
->phys_cursor_height
;
2080 x_intersect_rectangles (&r_save
, &rc
, &r
);
2085 /* Don't use S->y for clipping because it doesn't take partially
2086 visible lines into account. For example, it can be negative for
2087 partially visible lines at the top of a window. */
2088 if (!s
->row
->full_width_p
2089 && MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (s
->w
, s
->row
))
2090 r
.y
= WINDOW_HEADER_LINE_HEIGHT (s
->w
);
2092 r
.y
= max (0, s
->row
->y
);
2095 r
.y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, r
.y
);
2097 /* If drawing the cursor, don't let glyph draw outside its
2098 advertised boundaries. Cleartype does this under some circumstances. */
2099 if (s
->hl
== DRAW_CURSOR
)
2101 struct glyph
*glyph
= s
->first_glyph
;
2106 r
.width
-= s
->x
- r
.x
;
2109 r
.width
= min (r
.width
, glyph
->pixel_width
);
2111 /* If r.y is below window bottom, ensure that we still see a cursor. */
2112 height
= min (glyph
->ascent
+ glyph
->descent
,
2113 min (FRAME_LINE_HEIGHT (s
->f
), s
->row
->visible_height
));
2114 max_y
= window_text_bottom_y (s
->w
) - height
;
2115 max_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, max_y
);
2116 if (s
->ybase
- glyph
->ascent
> max_y
)
2123 /* Don't draw cursor glyph taller than our actual glyph. */
2124 height
= max (FRAME_LINE_HEIGHT (s
->f
), glyph
->ascent
+ glyph
->descent
);
2125 if (height
< r
.height
)
2127 max_y
= r
.y
+ r
.height
;
2128 r
.y
= min (max_y
, max (r
.y
, s
->ybase
+ glyph
->descent
- height
));
2129 r
.height
= min (max_y
- r
.y
, height
);
2136 XRectangle r_save
= r
;
2138 if (! x_intersect_rectangles (&r_save
, s
->row
->clip
, &r
))
2142 if ((s
->for_overlaps
& OVERLAPS_BOTH
) == 0
2143 || ((s
->for_overlaps
& OVERLAPS_BOTH
) == OVERLAPS_BOTH
&& n
== 1))
2145 #ifdef CONVERT_FROM_XRECT
2146 CONVERT_FROM_XRECT (r
, *rects
);
2154 /* If we are processing overlapping and allowed to return
2155 multiple clipping rectangles, we exclude the row of the glyph
2156 string from the clipping rectangle. This is to avoid drawing
2157 the same text on the environment with anti-aliasing. */
2158 #ifdef CONVERT_FROM_XRECT
2161 XRectangle
*rs
= rects
;
2163 int i
= 0, row_y
= WINDOW_TO_FRAME_PIXEL_Y (s
->w
, s
->row
->y
);
2165 if (s
->for_overlaps
& OVERLAPS_PRED
)
2168 if (r
.y
+ r
.height
> row_y
)
2171 rs
[i
].height
= row_y
- r
.y
;
2177 if (s
->for_overlaps
& OVERLAPS_SUCC
)
2180 if (r
.y
< row_y
+ s
->row
->visible_height
)
2182 if (r
.y
+ r
.height
> row_y
+ s
->row
->visible_height
)
2184 rs
[i
].y
= row_y
+ s
->row
->visible_height
;
2185 rs
[i
].height
= r
.y
+ r
.height
- rs
[i
].y
;
2194 #ifdef CONVERT_FROM_XRECT
2195 for (i
= 0; i
< n
; i
++)
2196 CONVERT_FROM_XRECT (rs
[i
], rects
[i
]);
2203 Return in *NR the clipping rectangle for glyph string S. */
2206 get_glyph_string_clip_rect (struct glyph_string
*s
, NativeRectangle
*nr
)
2208 get_glyph_string_clip_rects (s
, nr
, 1);
2213 Return the position and height of the phys cursor in window W.
2214 Set w->phys_cursor_width to width of phys cursor.
2218 get_phys_cursor_geometry (struct window
*w
, struct glyph_row
*row
,
2219 struct glyph
*glyph
, int *xp
, int *yp
, int *heightp
)
2221 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
2222 int x
, y
, wd
, h
, h0
, y0
;
2224 /* Compute the width of the rectangle to draw. If on a stretch
2225 glyph, and `x-stretch-block-cursor' is nil, don't draw a
2226 rectangle as wide as the glyph, but use a canonical character
2228 wd
= glyph
->pixel_width
- 1;
2229 #if defined (HAVE_NTGUI) || defined (HAVE_NS)
2233 x
= w
->phys_cursor
.x
;
2240 if (glyph
->type
== STRETCH_GLYPH
2241 && !x_stretch_cursor_p
)
2242 wd
= min (FRAME_COLUMN_WIDTH (f
), wd
);
2243 w
->phys_cursor_width
= wd
;
2245 y
= w
->phys_cursor
.y
+ row
->ascent
- glyph
->ascent
;
2247 /* If y is below window bottom, ensure that we still see a cursor. */
2248 h0
= min (FRAME_LINE_HEIGHT (f
), row
->visible_height
);
2250 h
= max (h0
, glyph
->ascent
+ glyph
->descent
);
2251 h0
= min (h0
, glyph
->ascent
+ glyph
->descent
);
2253 y0
= WINDOW_HEADER_LINE_HEIGHT (w
);
2256 h
= max (h
- (y0
- y
) + 1, h0
);
2261 y0
= window_text_bottom_y (w
) - h0
;
2269 *xp
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, x
);
2270 *yp
= WINDOW_TO_FRAME_PIXEL_Y (w
, y
);
2275 * Remember which glyph the mouse is over.
2279 remember_mouse_glyph (struct frame
*f
, int gx
, int gy
, NativeRectangle
*rect
)
2283 struct glyph_row
*r
, *gr
, *end_row
;
2284 enum window_part part
;
2285 enum glyph_row_area area
;
2286 int x
, y
, width
, height
;
2288 /* Try to determine frame pixel position and size of the glyph under
2289 frame pixel coordinates X/Y on frame F. */
2291 if (!f
->glyphs_initialized_p
2292 || (window
= window_from_coordinates (f
, gx
, gy
, &part
, 0),
2295 width
= FRAME_SMALLEST_CHAR_WIDTH (f
);
2296 height
= FRAME_SMALLEST_FONT_HEIGHT (f
);
2300 w
= XWINDOW (window
);
2301 width
= WINDOW_FRAME_COLUMN_WIDTH (w
);
2302 height
= WINDOW_FRAME_LINE_HEIGHT (w
);
2304 x
= window_relative_x_coord (w
, part
, gx
);
2305 y
= gy
- WINDOW_TOP_EDGE_Y (w
);
2307 r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
2308 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
2310 if (w
->pseudo_window_p
)
2313 part
= ON_MODE_LINE
; /* Don't adjust margin. */
2319 case ON_LEFT_MARGIN
:
2320 area
= LEFT_MARGIN_AREA
;
2323 case ON_RIGHT_MARGIN
:
2324 area
= RIGHT_MARGIN_AREA
;
2327 case ON_HEADER_LINE
:
2329 gr
= (part
== ON_HEADER_LINE
2330 ? MATRIX_HEADER_LINE_ROW (w
->current_matrix
)
2331 : MATRIX_MODE_LINE_ROW (w
->current_matrix
));
2334 goto text_glyph_row_found
;
2341 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2342 if (r
->y
+ r
->height
> y
)
2348 text_glyph_row_found
:
2351 struct glyph
*g
= gr
->glyphs
[area
];
2352 struct glyph
*end
= g
+ gr
->used
[area
];
2354 height
= gr
->height
;
2355 for (gx
= gr
->x
; g
< end
; gx
+= g
->pixel_width
, ++g
)
2356 if (gx
+ g
->pixel_width
> x
)
2361 if (g
->type
== IMAGE_GLYPH
)
2363 /* Don't remember when mouse is over image, as
2364 image may have hot-spots. */
2365 STORE_NATIVE_RECT (*rect
, 0, 0, 0, 0);
2368 width
= g
->pixel_width
;
2372 /* Use nominal char spacing at end of line. */
2374 gx
+= (x
/ width
) * width
;
2377 if (part
!= ON_MODE_LINE
&& part
!= ON_HEADER_LINE
)
2378 gx
+= window_box_left_offset (w
, area
);
2382 /* Use nominal line height at end of window. */
2383 gx
= (x
/ width
) * width
;
2385 gy
+= (y
/ height
) * height
;
2389 case ON_LEFT_FRINGE
:
2390 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2391 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
)
2392 : window_box_right_offset (w
, LEFT_MARGIN_AREA
));
2393 width
= WINDOW_LEFT_FRINGE_WIDTH (w
);
2396 case ON_RIGHT_FRINGE
:
2397 gx
= (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2398 ? window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2399 : window_box_right_offset (w
, TEXT_AREA
));
2400 width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
2404 gx
= (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
2406 : (window_box_right_offset (w
, RIGHT_MARGIN_AREA
)
2407 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
2408 ? WINDOW_RIGHT_FRINGE_WIDTH (w
)
2410 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
2414 for (; r
<= end_row
&& r
->enabled_p
; ++r
)
2415 if (r
->y
+ r
->height
> y
)
2422 height
= gr
->height
;
2425 /* Use nominal line height at end of window. */
2427 gy
+= (y
/ height
) * height
;
2434 /* If there is no glyph under the mouse, then we divide the screen
2435 into a grid of the smallest glyph in the frame, and use that
2438 /* Arrange for the division in FRAME_PIXEL_X_TO_COL etc. to
2439 round down even for negative values. */
2445 gx
= (gx
/ width
) * width
;
2446 gy
= (gy
/ height
) * height
;
2451 gx
+= WINDOW_LEFT_EDGE_X (w
);
2452 gy
+= WINDOW_TOP_EDGE_Y (w
);
2455 STORE_NATIVE_RECT (*rect
, gx
, gy
, width
, height
);
2457 /* Visible feedback for debugging. */
2460 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2461 f
->output_data
.x
->normal_gc
,
2462 gx
, gy
, width
, height
);
2468 #endif /* HAVE_WINDOW_SYSTEM */
2471 /***********************************************************************
2472 Lisp form evaluation
2473 ***********************************************************************/
2475 /* Error handler for safe_eval and safe_call. */
2478 safe_eval_handler (Lisp_Object arg
, ptrdiff_t nargs
, Lisp_Object
*args
)
2480 add_to_log ("Error during redisplay: %S signaled %S",
2481 Flist (nargs
, args
), arg
);
2485 /* Call function FUNC with the rest of NARGS - 1 arguments
2486 following. Return the result, or nil if something went
2487 wrong. Prevent redisplay during the evaluation. */
2490 safe_call (ptrdiff_t nargs
, Lisp_Object func
, ...)
2494 if (inhibit_eval_during_redisplay
)
2500 ptrdiff_t count
= SPECPDL_INDEX ();
2501 struct gcpro gcpro1
;
2502 Lisp_Object
*args
= alloca (nargs
* word_size
);
2505 va_start (ap
, func
);
2506 for (i
= 1; i
< nargs
; i
++)
2507 args
[i
] = va_arg (ap
, Lisp_Object
);
2511 gcpro1
.nvars
= nargs
;
2512 specbind (Qinhibit_redisplay
, Qt
);
2513 /* Use Qt to ensure debugger does not run,
2514 so there is no possibility of wanting to redisplay. */
2515 val
= internal_condition_case_n (Ffuncall
, nargs
, args
, Qt
,
2518 val
= unbind_to (count
, val
);
2525 /* Call function FN with one argument ARG.
2526 Return the result, or nil if something went wrong. */
2529 safe_call1 (Lisp_Object fn
, Lisp_Object arg
)
2531 return safe_call (2, fn
, arg
);
2534 static Lisp_Object Qeval
;
2537 safe_eval (Lisp_Object sexpr
)
2539 return safe_call1 (Qeval
, sexpr
);
2542 /* Call function FN with two arguments ARG1 and ARG2.
2543 Return the result, or nil if something went wrong. */
2546 safe_call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2548 return safe_call (3, fn
, arg1
, arg2
);
2553 /***********************************************************************
2555 ***********************************************************************/
2559 /* Define CHECK_IT to perform sanity checks on iterators.
2560 This is for debugging. It is too slow to do unconditionally. */
2563 check_it (struct it
*it
)
2565 if (it
->method
== GET_FROM_STRING
)
2567 eassert (STRINGP (it
->string
));
2568 eassert (IT_STRING_CHARPOS (*it
) >= 0);
2572 eassert (IT_STRING_CHARPOS (*it
) < 0);
2573 if (it
->method
== GET_FROM_BUFFER
)
2575 /* Check that character and byte positions agree. */
2576 eassert (IT_CHARPOS (*it
) == BYTE_TO_CHAR (IT_BYTEPOS (*it
)));
2581 eassert (it
->current
.dpvec_index
>= 0);
2583 eassert (it
->current
.dpvec_index
< 0);
2586 #define CHECK_IT(IT) check_it ((IT))
2590 #define CHECK_IT(IT) (void) 0
2595 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
2597 /* Check that the window end of window W is what we expect it
2598 to be---the last row in the current matrix displaying text. */
2601 check_window_end (struct window
*w
)
2603 if (!MINI_WINDOW_P (w
) && w
->window_end_valid
)
2605 struct glyph_row
*row
;
2606 eassert ((row
= MATRIX_ROW (w
->current_matrix
,
2607 XFASTINT (w
->window_end_vpos
)),
2609 || MATRIX_ROW_DISPLAYS_TEXT_P (row
)
2610 || MATRIX_ROW_VPOS (row
, w
->current_matrix
) == 0));
2614 #define CHECK_WINDOW_END(W) check_window_end ((W))
2618 #define CHECK_WINDOW_END(W) (void) 0
2620 #endif /* GLYPH_DEBUG and ENABLE_CHECKING */
2622 /* Return mark position if current buffer has the region of non-zero length,
2626 markpos_of_region (void)
2628 if (!NILP (Vtransient_mark_mode
)
2629 && !NILP (BVAR (current_buffer
, mark_active
))
2630 && XMARKER (BVAR (current_buffer
, mark
))->buffer
!= NULL
)
2632 ptrdiff_t markpos
= XMARKER (BVAR (current_buffer
, mark
))->charpos
;
2640 /***********************************************************************
2641 Iterator initialization
2642 ***********************************************************************/
2644 /* Initialize IT for displaying current_buffer in window W, starting
2645 at character position CHARPOS. CHARPOS < 0 means that no buffer
2646 position is specified which is useful when the iterator is assigned
2647 a position later. BYTEPOS is the byte position corresponding to
2650 If ROW is not null, calls to produce_glyphs with IT as parameter
2651 will produce glyphs in that row.
2653 BASE_FACE_ID is the id of a base face to use. It must be one of
2654 DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID,
2655 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID for displaying
2656 mode lines, or TOOL_BAR_FACE_ID for displaying the tool-bar.
2658 If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID,
2659 MODE_LINE_INACTIVE_FACE_ID, or HEADER_LINE_FACE_ID, the iterator
2660 will be initialized to use the corresponding mode line glyph row of
2661 the desired matrix of W. */
2664 init_iterator (struct it
*it
, struct window
*w
,
2665 ptrdiff_t charpos
, ptrdiff_t bytepos
,
2666 struct glyph_row
*row
, enum face_id base_face_id
)
2669 enum face_id remapped_base_face_id
= base_face_id
;
2671 /* Some precondition checks. */
2672 eassert (w
!= NULL
&& it
!= NULL
);
2673 eassert (charpos
< 0 || (charpos
>= BUF_BEG (current_buffer
)
2676 /* If face attributes have been changed since the last redisplay,
2677 free realized faces now because they depend on face definitions
2678 that might have changed. Don't free faces while there might be
2679 desired matrices pending which reference these faces. */
2680 if (face_change_count
&& !inhibit_free_realized_faces
)
2682 face_change_count
= 0;
2683 free_all_realized_faces (Qnil
);
2686 /* Perhaps remap BASE_FACE_ID to a user-specified alternative. */
2687 if (! NILP (Vface_remapping_alist
))
2688 remapped_base_face_id
2689 = lookup_basic_face (XFRAME (w
->frame
), base_face_id
);
2691 /* Use one of the mode line rows of W's desired matrix if
2695 if (base_face_id
== MODE_LINE_FACE_ID
2696 || base_face_id
== MODE_LINE_INACTIVE_FACE_ID
)
2697 row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
2698 else if (base_face_id
== HEADER_LINE_FACE_ID
)
2699 row
= MATRIX_HEADER_LINE_ROW (w
->desired_matrix
);
2703 memset (it
, 0, sizeof *it
);
2704 it
->current
.overlay_string_index
= -1;
2705 it
->current
.dpvec_index
= -1;
2706 it
->base_face_id
= remapped_base_face_id
;
2708 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
2709 it
->paragraph_embedding
= L2R
;
2710 it
->bidi_it
.string
.lstring
= Qnil
;
2711 it
->bidi_it
.string
.s
= NULL
;
2712 it
->bidi_it
.string
.bufpos
= 0;
2715 /* The window in which we iterate over current_buffer: */
2716 XSETWINDOW (it
->window
, w
);
2718 it
->f
= XFRAME (w
->frame
);
2722 /* Extra space between lines (on window systems only). */
2723 if (base_face_id
== DEFAULT_FACE_ID
2724 && FRAME_WINDOW_P (it
->f
))
2726 if (NATNUMP (BVAR (current_buffer
, extra_line_spacing
)))
2727 it
->extra_line_spacing
= XFASTINT (BVAR (current_buffer
, extra_line_spacing
));
2728 else if (FLOATP (BVAR (current_buffer
, extra_line_spacing
)))
2729 it
->extra_line_spacing
= (XFLOAT_DATA (BVAR (current_buffer
, extra_line_spacing
))
2730 * FRAME_LINE_HEIGHT (it
->f
));
2731 else if (it
->f
->extra_line_spacing
> 0)
2732 it
->extra_line_spacing
= it
->f
->extra_line_spacing
;
2733 it
->max_extra_line_spacing
= 0;
2736 /* If realized faces have been removed, e.g. because of face
2737 attribute changes of named faces, recompute them. When running
2738 in batch mode, the face cache of the initial frame is null. If
2739 we happen to get called, make a dummy face cache. */
2740 if (FRAME_FACE_CACHE (it
->f
) == NULL
)
2741 init_frame_faces (it
->f
);
2742 if (FRAME_FACE_CACHE (it
->f
)->used
== 0)
2743 recompute_basic_faces (it
->f
);
2745 /* Current value of the `slice', `space-width', and 'height' properties. */
2746 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
2747 it
->space_width
= Qnil
;
2748 it
->font_height
= Qnil
;
2749 it
->override_ascent
= -1;
2751 /* Are control characters displayed as `^C'? */
2752 it
->ctl_arrow_p
= !NILP (BVAR (current_buffer
, ctl_arrow
));
2754 /* -1 means everything between a CR and the following line end
2755 is invisible. >0 means lines indented more than this value are
2757 it
->selective
= (INTEGERP (BVAR (current_buffer
, selective_display
))
2759 (-1, XINT (BVAR (current_buffer
, selective_display
)),
2761 : (!NILP (BVAR (current_buffer
, selective_display
))
2763 it
->selective_display_ellipsis_p
2764 = !NILP (BVAR (current_buffer
, selective_display_ellipses
));
2766 /* Display table to use. */
2767 it
->dp
= window_display_table (w
);
2769 /* Are multibyte characters enabled in current_buffer? */
2770 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
2772 /* If visible region is of non-zero length, set IT->region_beg_charpos
2773 and IT->region_end_charpos to the start and end of a visible region
2774 in window IT->w. Set both to -1 to indicate no region. */
2775 markpos
= markpos_of_region ();
2777 /* Maybe highlight only in selected window. */
2778 && (/* Either show region everywhere. */
2779 highlight_nonselected_windows
2780 /* Or show region in the selected window. */
2781 || w
== XWINDOW (selected_window
)
2782 /* Or show the region if we are in the mini-buffer and W is
2783 the window the mini-buffer refers to. */
2784 || (MINI_WINDOW_P (XWINDOW (selected_window
))
2785 && WINDOWP (minibuf_selected_window
)
2786 && w
== XWINDOW (minibuf_selected_window
))))
2788 it
->region_beg_charpos
= min (PT
, markpos
);
2789 it
->region_end_charpos
= max (PT
, markpos
);
2792 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
2794 /* Get the position at which the redisplay_end_trigger hook should
2795 be run, if it is to be run at all. */
2796 if (MARKERP (w
->redisplay_end_trigger
)
2797 && XMARKER (w
->redisplay_end_trigger
)->buffer
!= 0)
2798 it
->redisplay_end_trigger_charpos
2799 = marker_position (w
->redisplay_end_trigger
);
2800 else if (INTEGERP (w
->redisplay_end_trigger
))
2801 it
->redisplay_end_trigger_charpos
=
2802 clip_to_bounds (PTRDIFF_MIN
, XINT (w
->redisplay_end_trigger
), PTRDIFF_MAX
);
2804 it
->tab_width
= SANE_TAB_WIDTH (current_buffer
);
2806 /* Are lines in the display truncated? */
2807 if (base_face_id
!= DEFAULT_FACE_ID
2809 || (! WINDOW_FULL_WIDTH_P (it
->w
)
2810 && ((!NILP (Vtruncate_partial_width_windows
)
2811 && !INTEGERP (Vtruncate_partial_width_windows
))
2812 || (INTEGERP (Vtruncate_partial_width_windows
)
2813 && (WINDOW_TOTAL_COLS (it
->w
)
2814 < XINT (Vtruncate_partial_width_windows
))))))
2815 it
->line_wrap
= TRUNCATE
;
2816 else if (NILP (BVAR (current_buffer
, truncate_lines
)))
2817 it
->line_wrap
= NILP (BVAR (current_buffer
, word_wrap
))
2818 ? WINDOW_WRAP
: WORD_WRAP
;
2820 it
->line_wrap
= TRUNCATE
;
2822 /* Get dimensions of truncation and continuation glyphs. These are
2823 displayed as fringe bitmaps under X, but we need them for such
2824 frames when the fringes are turned off. But leave the dimensions
2825 zero for tooltip frames, as these glyphs look ugly there and also
2826 sabotage calculations of tooltip dimensions in x-show-tip. */
2827 #ifdef HAVE_WINDOW_SYSTEM
2828 if (!(FRAME_WINDOW_P (it
->f
)
2829 && FRAMEP (tip_frame
)
2830 && it
->f
== XFRAME (tip_frame
)))
2833 if (it
->line_wrap
== TRUNCATE
)
2835 /* We will need the truncation glyph. */
2836 eassert (it
->glyph_row
== NULL
);
2837 produce_special_glyphs (it
, IT_TRUNCATION
);
2838 it
->truncation_pixel_width
= it
->pixel_width
;
2842 /* We will need the continuation glyph. */
2843 eassert (it
->glyph_row
== NULL
);
2844 produce_special_glyphs (it
, IT_CONTINUATION
);
2845 it
->continuation_pixel_width
= it
->pixel_width
;
2849 /* Reset these values to zero because the produce_special_glyphs
2850 above has changed them. */
2851 it
->pixel_width
= it
->ascent
= it
->descent
= 0;
2852 it
->phys_ascent
= it
->phys_descent
= 0;
2854 /* Set this after getting the dimensions of truncation and
2855 continuation glyphs, so that we don't produce glyphs when calling
2856 produce_special_glyphs, above. */
2857 it
->glyph_row
= row
;
2858 it
->area
= TEXT_AREA
;
2860 /* Forget any previous info about this row being reversed. */
2862 it
->glyph_row
->reversed_p
= 0;
2864 /* Get the dimensions of the display area. The display area
2865 consists of the visible window area plus a horizontally scrolled
2866 part to the left of the window. All x-values are relative to the
2867 start of this total display area. */
2868 if (base_face_id
!= DEFAULT_FACE_ID
)
2870 /* Mode lines, menu bar in terminal frames. */
2871 it
->first_visible_x
= 0;
2872 it
->last_visible_x
= WINDOW_TOTAL_WIDTH (w
);
2876 it
->first_visible_x
=
2877 window_hscroll_limited (it
->w
, it
->f
) * FRAME_COLUMN_WIDTH (it
->f
);
2878 it
->last_visible_x
= (it
->first_visible_x
2879 + window_box_width (w
, TEXT_AREA
));
2881 /* If we truncate lines, leave room for the truncation glyph(s) at
2882 the right margin. Otherwise, leave room for the continuation
2883 glyph(s). Done only if the window has no fringes. Since we
2884 don't know at this point whether there will be any R2L lines in
2885 the window, we reserve space for truncation/continuation glyphs
2886 even if only one of the fringes is absent. */
2887 if (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
2888 || (it
->bidi_p
&& WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0))
2890 if (it
->line_wrap
== TRUNCATE
)
2891 it
->last_visible_x
-= it
->truncation_pixel_width
;
2893 it
->last_visible_x
-= it
->continuation_pixel_width
;
2896 it
->header_line_p
= WINDOW_WANTS_HEADER_LINE_P (w
);
2897 it
->current_y
= WINDOW_HEADER_LINE_HEIGHT (w
) + w
->vscroll
;
2900 /* Leave room for a border glyph. */
2901 if (!FRAME_WINDOW_P (it
->f
)
2902 && !WINDOW_RIGHTMOST_P (it
->w
))
2903 it
->last_visible_x
-= 1;
2905 it
->last_visible_y
= window_text_bottom_y (w
);
2907 /* For mode lines and alike, arrange for the first glyph having a
2908 left box line if the face specifies a box. */
2909 if (base_face_id
!= DEFAULT_FACE_ID
)
2913 it
->face_id
= remapped_base_face_id
;
2915 /* If we have a boxed mode line, make the first character appear
2916 with a left box line. */
2917 face
= FACE_FROM_ID (it
->f
, remapped_base_face_id
);
2918 if (face
->box
!= FACE_NO_BOX
)
2919 it
->start_of_box_run_p
= 1;
2922 /* If a buffer position was specified, set the iterator there,
2923 getting overlays and face properties from that position. */
2924 if (charpos
>= BUF_BEG (current_buffer
))
2926 it
->end_charpos
= ZV
;
2927 eassert (charpos
== BYTE_TO_CHAR (bytepos
));
2928 IT_CHARPOS (*it
) = charpos
;
2929 IT_BYTEPOS (*it
) = bytepos
;
2931 /* We will rely on `reseat' to set this up properly, via
2932 handle_face_prop. */
2933 it
->face_id
= it
->base_face_id
;
2935 it
->start
= it
->current
;
2936 /* Do we need to reorder bidirectional text? Not if this is a
2937 unibyte buffer: by definition, none of the single-byte
2938 characters are strong R2L, so no reordering is needed. And
2939 bidi.c doesn't support unibyte buffers anyway. Also, don't
2940 reorder while we are loading loadup.el, since the tables of
2941 character properties needed for reordering are not yet
2945 && !NILP (BVAR (current_buffer
, bidi_display_reordering
))
2948 /* If we are to reorder bidirectional text, init the bidi
2952 /* Note the paragraph direction that this buffer wants to
2954 if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2956 it
->paragraph_embedding
= L2R
;
2957 else if (EQ (BVAR (current_buffer
, bidi_paragraph_direction
),
2959 it
->paragraph_embedding
= R2L
;
2961 it
->paragraph_embedding
= NEUTRAL_DIR
;
2962 bidi_unshelve_cache (NULL
, 0);
2963 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
2967 /* Compute faces etc. */
2968 reseat (it
, it
->current
.pos
, 1);
2975 /* Initialize IT for the display of window W with window start POS. */
2978 start_display (struct it
*it
, struct window
*w
, struct text_pos pos
)
2980 struct glyph_row
*row
;
2981 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
2983 row
= w
->desired_matrix
->rows
+ first_vpos
;
2984 init_iterator (it
, w
, CHARPOS (pos
), BYTEPOS (pos
), row
, DEFAULT_FACE_ID
);
2985 it
->first_vpos
= first_vpos
;
2987 /* Don't reseat to previous visible line start if current start
2988 position is in a string or image. */
2989 if (it
->method
== GET_FROM_BUFFER
&& it
->line_wrap
!= TRUNCATE
)
2991 int start_at_line_beg_p
;
2992 int first_y
= it
->current_y
;
2994 /* If window start is not at a line start, skip forward to POS to
2995 get the correct continuation lines width. */
2996 start_at_line_beg_p
= (CHARPOS (pos
) == BEGV
2997 || FETCH_BYTE (BYTEPOS (pos
) - 1) == '\n');
2998 if (!start_at_line_beg_p
)
3002 reseat_at_previous_visible_line_start (it
);
3003 move_it_to (it
, CHARPOS (pos
), -1, -1, -1, MOVE_TO_POS
);
3005 new_x
= it
->current_x
+ it
->pixel_width
;
3007 /* If lines are continued, this line may end in the middle
3008 of a multi-glyph character (e.g. a control character
3009 displayed as \003, or in the middle of an overlay
3010 string). In this case move_it_to above will not have
3011 taken us to the start of the continuation line but to the
3012 end of the continued line. */
3013 if (it
->current_x
> 0
3014 && it
->line_wrap
!= TRUNCATE
/* Lines are continued. */
3015 && (/* And glyph doesn't fit on the line. */
3016 new_x
> it
->last_visible_x
3017 /* Or it fits exactly and we're on a window
3019 || (new_x
== it
->last_visible_x
3020 && FRAME_WINDOW_P (it
->f
)
3021 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
3022 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
3023 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
3025 if ((it
->current
.dpvec_index
>= 0
3026 || it
->current
.overlay_string_index
>= 0)
3027 /* If we are on a newline from a display vector or
3028 overlay string, then we are already at the end of
3029 a screen line; no need to go to the next line in
3030 that case, as this line is not really continued.
3031 (If we do go to the next line, C-e will not DTRT.) */
3034 set_iterator_to_next (it
, 1);
3035 move_it_in_display_line_to (it
, -1, -1, 0);
3038 it
->continuation_lines_width
+= it
->current_x
;
3040 /* If the character at POS is displayed via a display
3041 vector, move_it_to above stops at the final glyph of
3042 IT->dpvec. To make the caller redisplay that character
3043 again (a.k.a. start at POS), we need to reset the
3044 dpvec_index to the beginning of IT->dpvec. */
3045 else if (it
->current
.dpvec_index
>= 0)
3046 it
->current
.dpvec_index
= 0;
3048 /* We're starting a new display line, not affected by the
3049 height of the continued line, so clear the appropriate
3050 fields in the iterator structure. */
3051 it
->max_ascent
= it
->max_descent
= 0;
3052 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
3054 it
->current_y
= first_y
;
3056 it
->current_x
= it
->hpos
= 0;
3062 /* Return 1 if POS is a position in ellipses displayed for invisible
3063 text. W is the window we display, for text property lookup. */
3066 in_ellipses_for_invisible_text_p (struct display_pos
*pos
, struct window
*w
)
3068 Lisp_Object prop
, window
;
3070 ptrdiff_t charpos
= CHARPOS (pos
->pos
);
3072 /* If POS specifies a position in a display vector, this might
3073 be for an ellipsis displayed for invisible text. We won't
3074 get the iterator set up for delivering that ellipsis unless
3075 we make sure that it gets aware of the invisible text. */
3076 if (pos
->dpvec_index
>= 0
3077 && pos
->overlay_string_index
< 0
3078 && CHARPOS (pos
->string_pos
) < 0
3080 && (XSETWINDOW (window
, w
),
3081 prop
= Fget_char_property (make_number (charpos
),
3082 Qinvisible
, window
),
3083 !TEXT_PROP_MEANS_INVISIBLE (prop
)))
3085 prop
= Fget_char_property (make_number (charpos
- 1), Qinvisible
,
3087 ellipses_p
= 2 == TEXT_PROP_MEANS_INVISIBLE (prop
);
3094 /* Initialize IT for stepping through current_buffer in window W,
3095 starting at position POS that includes overlay string and display
3096 vector/ control character translation position information. Value
3097 is zero if there are overlay strings with newlines at POS. */
3100 init_from_display_pos (struct it
*it
, struct window
*w
, struct display_pos
*pos
)
3102 ptrdiff_t charpos
= CHARPOS (pos
->pos
), bytepos
= BYTEPOS (pos
->pos
);
3103 int i
, overlay_strings_with_newlines
= 0;
3105 /* If POS specifies a position in a display vector, this might
3106 be for an ellipsis displayed for invisible text. We won't
3107 get the iterator set up for delivering that ellipsis unless
3108 we make sure that it gets aware of the invisible text. */
3109 if (in_ellipses_for_invisible_text_p (pos
, w
))
3115 /* Keep in mind: the call to reseat in init_iterator skips invisible
3116 text, so we might end up at a position different from POS. This
3117 is only a problem when POS is a row start after a newline and an
3118 overlay starts there with an after-string, and the overlay has an
3119 invisible property. Since we don't skip invisible text in
3120 display_line and elsewhere immediately after consuming the
3121 newline before the row start, such a POS will not be in a string,
3122 but the call to init_iterator below will move us to the
3124 init_iterator (it
, w
, charpos
, bytepos
, NULL
, DEFAULT_FACE_ID
);
3126 /* This only scans the current chunk -- it should scan all chunks.
3127 However, OVERLAY_STRING_CHUNK_SIZE has been increased from 3 in 21.1
3128 to 16 in 22.1 to make this a lesser problem. */
3129 for (i
= 0; i
< it
->n_overlay_strings
&& i
< OVERLAY_STRING_CHUNK_SIZE
; ++i
)
3131 const char *s
= SSDATA (it
->overlay_strings
[i
]);
3132 const char *e
= s
+ SBYTES (it
->overlay_strings
[i
]);
3134 while (s
< e
&& *s
!= '\n')
3139 overlay_strings_with_newlines
= 1;
3144 /* If position is within an overlay string, set up IT to the right
3146 if (pos
->overlay_string_index
>= 0)
3150 /* If the first overlay string happens to have a `display'
3151 property for an image, the iterator will be set up for that
3152 image, and we have to undo that setup first before we can
3153 correct the overlay string index. */
3154 if (it
->method
== GET_FROM_IMAGE
)
3157 /* We already have the first chunk of overlay strings in
3158 IT->overlay_strings. Load more until the one for
3159 pos->overlay_string_index is in IT->overlay_strings. */
3160 if (pos
->overlay_string_index
>= OVERLAY_STRING_CHUNK_SIZE
)
3162 ptrdiff_t n
= pos
->overlay_string_index
/ OVERLAY_STRING_CHUNK_SIZE
;
3163 it
->current
.overlay_string_index
= 0;
3166 load_overlay_strings (it
, 0);
3167 it
->current
.overlay_string_index
+= OVERLAY_STRING_CHUNK_SIZE
;
3171 it
->current
.overlay_string_index
= pos
->overlay_string_index
;
3172 relative_index
= (it
->current
.overlay_string_index
3173 % OVERLAY_STRING_CHUNK_SIZE
);
3174 it
->string
= it
->overlay_strings
[relative_index
];
3175 eassert (STRINGP (it
->string
));
3176 it
->current
.string_pos
= pos
->string_pos
;
3177 it
->method
= GET_FROM_STRING
;
3178 it
->end_charpos
= SCHARS (it
->string
);
3179 /* Set up the bidi iterator for this overlay string. */
3182 it
->bidi_it
.string
.lstring
= it
->string
;
3183 it
->bidi_it
.string
.s
= NULL
;
3184 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
3185 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
3186 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
3187 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
3188 it
->bidi_it
.w
= it
->w
;
3189 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3190 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3192 /* Synchronize the state of the bidi iterator with
3193 pos->string_pos. For any string position other than
3194 zero, this will be done automagically when we resume
3195 iteration over the string and get_visually_first_element
3196 is called. But if string_pos is zero, and the string is
3197 to be reordered for display, we need to resync manually,
3198 since it could be that the iteration state recorded in
3199 pos ended at string_pos of 0 moving backwards in string. */
3200 if (CHARPOS (pos
->string_pos
) == 0)
3202 get_visually_first_element (it
);
3203 if (IT_STRING_CHARPOS (*it
) != 0)
3206 eassert (it
->bidi_it
.charpos
< it
->bidi_it
.string
.schars
);
3207 bidi_move_to_visually_next (&it
->bidi_it
);
3208 } while (it
->bidi_it
.charpos
!= 0);
3210 eassert (IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
3211 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
);
3215 if (CHARPOS (pos
->string_pos
) >= 0)
3217 /* Recorded position is not in an overlay string, but in another
3218 string. This can only be a string from a `display' property.
3219 IT should already be filled with that string. */
3220 it
->current
.string_pos
= pos
->string_pos
;
3221 eassert (STRINGP (it
->string
));
3223 bidi_init_it (IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
),
3224 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
3227 /* Restore position in display vector translations, control
3228 character translations or ellipses. */
3229 if (pos
->dpvec_index
>= 0)
3231 if (it
->dpvec
== NULL
)
3232 get_next_display_element (it
);
3233 eassert (it
->dpvec
&& it
->current
.dpvec_index
== 0);
3234 it
->current
.dpvec_index
= pos
->dpvec_index
;
3238 return !overlay_strings_with_newlines
;
3242 /* Initialize IT for stepping through current_buffer in window W
3243 starting at ROW->start. */
3246 init_to_row_start (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3248 init_from_display_pos (it
, w
, &row
->start
);
3249 it
->start
= row
->start
;
3250 it
->continuation_lines_width
= row
->continuation_lines_width
;
3255 /* Initialize IT for stepping through current_buffer in window W
3256 starting in the line following ROW, i.e. starting at ROW->end.
3257 Value is zero if there are overlay strings with newlines at ROW's
3261 init_to_row_end (struct it
*it
, struct window
*w
, struct glyph_row
*row
)
3265 if (init_from_display_pos (it
, w
, &row
->end
))
3267 if (row
->continued_p
)
3268 it
->continuation_lines_width
3269 = row
->continuation_lines_width
+ row
->pixel_width
;
3280 /***********************************************************************
3282 ***********************************************************************/
3284 /* Called when IT reaches IT->stop_charpos. Handle text property and
3285 overlay changes. Set IT->stop_charpos to the next position where
3289 handle_stop (struct it
*it
)
3291 enum prop_handled handled
;
3292 int handle_overlay_change_p
;
3296 it
->current
.dpvec_index
= -1;
3297 handle_overlay_change_p
= !it
->ignore_overlay_strings_at_pos_p
;
3298 it
->ignore_overlay_strings_at_pos_p
= 0;
3301 /* Use face of preceding text for ellipsis (if invisible) */
3302 if (it
->selective_display_ellipsis_p
)
3303 it
->saved_face_id
= it
->face_id
;
3307 handled
= HANDLED_NORMALLY
;
3309 /* Call text property handlers. */
3310 for (p
= it_props
; p
->handler
; ++p
)
3312 handled
= p
->handler (it
);
3314 if (handled
== HANDLED_RECOMPUTE_PROPS
)
3316 else if (handled
== HANDLED_RETURN
)
3318 /* We still want to show before and after strings from
3319 overlays even if the actual buffer text is replaced. */
3320 if (!handle_overlay_change_p
3322 /* Don't call get_overlay_strings_1 if we already
3323 have overlay strings loaded, because doing so
3324 will load them again and push the iterator state
3325 onto the stack one more time, which is not
3326 expected by the rest of the code that processes
3328 || (it
->current
.overlay_string_index
< 0
3329 ? !get_overlay_strings_1 (it
, 0, 0)
3333 setup_for_ellipsis (it
, 0);
3334 /* When handling a display spec, we might load an
3335 empty string. In that case, discard it here. We
3336 used to discard it in handle_single_display_spec,
3337 but that causes get_overlay_strings_1, above, to
3338 ignore overlay strings that we must check. */
3339 if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3343 else if (STRINGP (it
->string
) && !SCHARS (it
->string
))
3347 it
->ignore_overlay_strings_at_pos_p
= 1;
3348 it
->string_from_display_prop_p
= 0;
3349 it
->from_disp_prop_p
= 0;
3350 handle_overlay_change_p
= 0;
3352 handled
= HANDLED_RECOMPUTE_PROPS
;
3355 else if (handled
== HANDLED_OVERLAY_STRING_CONSUMED
)
3356 handle_overlay_change_p
= 0;
3359 if (handled
!= HANDLED_RECOMPUTE_PROPS
)
3361 /* Don't check for overlay strings below when set to deliver
3362 characters from a display vector. */
3363 if (it
->method
== GET_FROM_DISPLAY_VECTOR
)
3364 handle_overlay_change_p
= 0;
3366 /* Handle overlay changes.
3367 This sets HANDLED to HANDLED_RECOMPUTE_PROPS
3368 if it finds overlays. */
3369 if (handle_overlay_change_p
)
3370 handled
= handle_overlay_change (it
);
3375 setup_for_ellipsis (it
, 0);
3379 while (handled
== HANDLED_RECOMPUTE_PROPS
);
3381 /* Determine where to stop next. */
3382 if (handled
== HANDLED_NORMALLY
)
3383 compute_stop_pos (it
);
3387 /* Compute IT->stop_charpos from text property and overlay change
3388 information for IT's current position. */
3391 compute_stop_pos (struct it
*it
)
3393 register INTERVAL iv
, next_iv
;
3394 Lisp_Object object
, limit
, position
;
3395 ptrdiff_t charpos
, bytepos
;
3397 if (STRINGP (it
->string
))
3399 /* Strings are usually short, so don't limit the search for
3401 it
->stop_charpos
= it
->end_charpos
;
3402 object
= it
->string
;
3404 charpos
= IT_STRING_CHARPOS (*it
);
3405 bytepos
= IT_STRING_BYTEPOS (*it
);
3411 /* If end_charpos is out of range for some reason, such as a
3412 misbehaving display function, rationalize it (Bug#5984). */
3413 if (it
->end_charpos
> ZV
)
3414 it
->end_charpos
= ZV
;
3415 it
->stop_charpos
= it
->end_charpos
;
3417 /* If next overlay change is in front of the current stop pos
3418 (which is IT->end_charpos), stop there. Note: value of
3419 next_overlay_change is point-max if no overlay change
3421 charpos
= IT_CHARPOS (*it
);
3422 bytepos
= IT_BYTEPOS (*it
);
3423 pos
= next_overlay_change (charpos
);
3424 if (pos
< it
->stop_charpos
)
3425 it
->stop_charpos
= pos
;
3427 /* If showing the region, we have to stop at the region
3428 start or end because the face might change there. */
3429 if (it
->region_beg_charpos
> 0)
3431 if (IT_CHARPOS (*it
) < it
->region_beg_charpos
)
3432 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_beg_charpos
);
3433 else if (IT_CHARPOS (*it
) < it
->region_end_charpos
)
3434 it
->stop_charpos
= min (it
->stop_charpos
, it
->region_end_charpos
);
3437 /* Set up variables for computing the stop position from text
3438 property changes. */
3439 XSETBUFFER (object
, current_buffer
);
3440 limit
= make_number (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
);
3443 /* Get the interval containing IT's position. Value is a null
3444 interval if there isn't such an interval. */
3445 position
= make_number (charpos
);
3446 iv
= validate_interval_range (object
, &position
, &position
, 0);
3449 Lisp_Object values_here
[LAST_PROP_IDX
];
3452 /* Get properties here. */
3453 for (p
= it_props
; p
->handler
; ++p
)
3454 values_here
[p
->idx
] = textget (iv
->plist
, *p
->name
);
3456 /* Look for an interval following iv that has different
3458 for (next_iv
= next_interval (iv
);
3461 || XFASTINT (limit
) > next_iv
->position
));
3462 next_iv
= next_interval (next_iv
))
3464 for (p
= it_props
; p
->handler
; ++p
)
3466 Lisp_Object new_value
;
3468 new_value
= textget (next_iv
->plist
, *p
->name
);
3469 if (!EQ (values_here
[p
->idx
], new_value
))
3479 if (INTEGERP (limit
)
3480 && next_iv
->position
>= XFASTINT (limit
))
3481 /* No text property change up to limit. */
3482 it
->stop_charpos
= min (XFASTINT (limit
), it
->stop_charpos
);
3484 /* Text properties change in next_iv. */
3485 it
->stop_charpos
= min (it
->stop_charpos
, next_iv
->position
);
3489 if (it
->cmp_it
.id
< 0)
3491 ptrdiff_t stoppos
= it
->end_charpos
;
3493 if (it
->bidi_p
&& it
->bidi_it
.scan_dir
< 0)
3495 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
,
3496 stoppos
, it
->string
);
3499 eassert (STRINGP (it
->string
)
3500 || (it
->stop_charpos
>= BEGV
3501 && it
->stop_charpos
>= IT_CHARPOS (*it
)));
3505 /* Return the position of the next overlay change after POS in
3506 current_buffer. Value is point-max if no overlay change
3507 follows. This is like `next-overlay-change' but doesn't use
3511 next_overlay_change (ptrdiff_t pos
)
3513 ptrdiff_t i
, noverlays
;
3515 Lisp_Object
*overlays
;
3517 /* Get all overlays at the given position. */
3518 GET_OVERLAYS_AT (pos
, overlays
, noverlays
, &endpos
, 1);
3520 /* If any of these overlays ends before endpos,
3521 use its ending point instead. */
3522 for (i
= 0; i
< noverlays
; ++i
)
3527 oend
= OVERLAY_END (overlays
[i
]);
3528 oendpos
= OVERLAY_POSITION (oend
);
3529 endpos
= min (endpos
, oendpos
);
3535 /* How many characters forward to search for a display property or
3536 display string. Searching too far forward makes the bidi display
3537 sluggish, especially in small windows. */
3538 #define MAX_DISP_SCAN 250
3540 /* Return the character position of a display string at or after
3541 position specified by POSITION. If no display string exists at or
3542 after POSITION, return ZV. A display string is either an overlay
3543 with `display' property whose value is a string, or a `display'
3544 text property whose value is a string. STRING is data about the
3545 string to iterate; if STRING->lstring is nil, we are iterating a
3546 buffer. FRAME_WINDOW_P is non-zero when we are displaying a window
3547 on a GUI frame. DISP_PROP is set to zero if we searched
3548 MAX_DISP_SCAN characters forward without finding any display
3549 strings, non-zero otherwise. It is set to 2 if the display string
3550 uses any kind of `(space ...)' spec that will produce a stretch of
3551 white space in the text area. */
3553 compute_display_string_pos (struct text_pos
*position
,
3554 struct bidi_string_data
*string
,
3556 int frame_window_p
, int *disp_prop
)
3558 /* OBJECT = nil means current buffer. */
3559 Lisp_Object object
, object1
;
3560 Lisp_Object pos
, spec
, limpos
;
3561 int string_p
= (string
&& (STRINGP (string
->lstring
) || string
->s
));
3562 ptrdiff_t eob
= string_p
? string
->schars
: ZV
;
3563 ptrdiff_t begb
= string_p
? 0 : BEGV
;
3564 ptrdiff_t bufpos
, charpos
= CHARPOS (*position
);
3566 (charpos
< eob
- MAX_DISP_SCAN
) ? charpos
+ MAX_DISP_SCAN
: eob
;
3567 struct text_pos tpos
;
3570 if (string
&& STRINGP (string
->lstring
))
3571 object1
= object
= string
->lstring
;
3572 else if (w
&& !string_p
)
3574 XSETWINDOW (object
, w
);
3578 object1
= object
= Qnil
;
3583 /* We don't support display properties whose values are strings
3584 that have display string properties. */
3585 || string
->from_disp_str
3586 /* C strings cannot have display properties. */
3587 || (string
->s
&& !STRINGP (object
)))
3593 /* If the character at CHARPOS is where the display string begins,
3595 pos
= make_number (charpos
);
3596 if (STRINGP (object
))
3597 bufpos
= string
->bufpos
;
3601 if (!NILP (spec
= Fget_char_property (pos
, Qdisplay
, object
))
3603 || !EQ (Fget_char_property (make_number (charpos
- 1), Qdisplay
,
3606 && (rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
, bufpos
,
3614 /* Look forward for the first character with a `display' property
3615 that will replace the underlying text when displayed. */
3616 limpos
= make_number (lim
);
3618 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object1
, limpos
);
3619 CHARPOS (tpos
) = XFASTINT (pos
);
3620 if (CHARPOS (tpos
) >= lim
)
3625 if (STRINGP (object
))
3626 BYTEPOS (tpos
) = string_char_to_byte (object
, CHARPOS (tpos
));
3628 BYTEPOS (tpos
) = CHAR_TO_BYTE (CHARPOS (tpos
));
3629 spec
= Fget_char_property (pos
, Qdisplay
, object
);
3630 if (!STRINGP (object
))
3631 bufpos
= CHARPOS (tpos
);
3632 } while (NILP (spec
)
3633 || !(rv
= handle_display_spec (NULL
, spec
, object
, Qnil
, &tpos
,
3634 bufpos
, frame_window_p
)));
3638 return CHARPOS (tpos
);
3641 /* Return the character position of the end of the display string that
3642 started at CHARPOS. If there's no display string at CHARPOS,
3643 return -1. A display string is either an overlay with `display'
3644 property whose value is a string or a `display' text property whose
3645 value is a string. */
3647 compute_display_string_end (ptrdiff_t charpos
, struct bidi_string_data
*string
)
3649 /* OBJECT = nil means current buffer. */
3650 Lisp_Object object
=
3651 (string
&& STRINGP (string
->lstring
)) ? string
->lstring
: Qnil
;
3652 Lisp_Object pos
= make_number (charpos
);
3654 (STRINGP (object
) || (string
&& string
->s
)) ? string
->schars
: ZV
;
3656 if (charpos
>= eob
|| (string
->s
&& !STRINGP (object
)))
3659 /* It could happen that the display property or overlay was removed
3660 since we found it in compute_display_string_pos above. One way
3661 this can happen is if JIT font-lock was called (through
3662 handle_fontified_prop), and jit-lock-functions remove text
3663 properties or overlays from the portion of buffer that includes
3664 CHARPOS. Muse mode is known to do that, for example. In this
3665 case, we return -1 to the caller, to signal that no display
3666 string is actually present at CHARPOS. See bidi_fetch_char for
3667 how this is handled.
3669 An alternative would be to never look for display properties past
3670 it->stop_charpos. But neither compute_display_string_pos nor
3671 bidi_fetch_char that calls it know or care where the next
3673 if (NILP (Fget_char_property (pos
, Qdisplay
, object
)))
3676 /* Look forward for the first character where the `display' property
3678 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, object
, Qnil
);
3680 return XFASTINT (pos
);
3685 /***********************************************************************
3687 ***********************************************************************/
3689 /* Handle changes in the `fontified' property of the current buffer by
3690 calling hook functions from Qfontification_functions to fontify
3693 static enum prop_handled
3694 handle_fontified_prop (struct it
*it
)
3696 Lisp_Object prop
, pos
;
3697 enum prop_handled handled
= HANDLED_NORMALLY
;
3699 if (!NILP (Vmemory_full
))
3702 /* Get the value of the `fontified' property at IT's current buffer
3703 position. (The `fontified' property doesn't have a special
3704 meaning in strings.) If the value is nil, call functions from
3705 Qfontification_functions. */
3706 if (!STRINGP (it
->string
)
3708 && !NILP (Vfontification_functions
)
3709 && !NILP (Vrun_hooks
)
3710 && (pos
= make_number (IT_CHARPOS (*it
)),
3711 prop
= Fget_char_property (pos
, Qfontified
, Qnil
),
3712 /* Ignore the special cased nil value always present at EOB since
3713 no amount of fontifying will be able to change it. */
3714 NILP (prop
) && IT_CHARPOS (*it
) < Z
))
3716 ptrdiff_t count
= SPECPDL_INDEX ();
3718 struct buffer
*obuf
= current_buffer
;
3719 int begv
= BEGV
, zv
= ZV
;
3720 int old_clip_changed
= current_buffer
->clip_changed
;
3722 val
= Vfontification_functions
;
3723 specbind (Qfontification_functions
, Qnil
);
3725 eassert (it
->end_charpos
== ZV
);
3727 if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
3728 safe_call1 (val
, pos
);
3731 Lisp_Object fns
, fn
;
3732 struct gcpro gcpro1
, gcpro2
;
3737 for (; CONSP (val
); val
= XCDR (val
))
3743 /* A value of t indicates this hook has a local
3744 binding; it means to run the global binding too.
3745 In a global value, t should not occur. If it
3746 does, we must ignore it to avoid an endless
3748 for (fns
= Fdefault_value (Qfontification_functions
);
3754 safe_call1 (fn
, pos
);
3758 safe_call1 (fn
, pos
);
3764 unbind_to (count
, Qnil
);
3766 /* Fontification functions routinely call `save-restriction'.
3767 Normally, this tags clip_changed, which can confuse redisplay
3768 (see discussion in Bug#6671). Since we don't perform any
3769 special handling of fontification changes in the case where
3770 `save-restriction' isn't called, there's no point doing so in
3771 this case either. So, if the buffer's restrictions are
3772 actually left unchanged, reset clip_changed. */
3773 if (obuf
== current_buffer
)
3775 if (begv
== BEGV
&& zv
== ZV
)
3776 current_buffer
->clip_changed
= old_clip_changed
;
3778 /* There isn't much we can reasonably do to protect against
3779 misbehaving fontification, but here's a fig leaf. */
3780 else if (BUFFER_LIVE_P (obuf
))
3781 set_buffer_internal_1 (obuf
);
3783 /* The fontification code may have added/removed text.
3784 It could do even a lot worse, but let's at least protect against
3785 the most obvious case where only the text past `pos' gets changed',
3786 as is/was done in grep.el where some escapes sequences are turned
3787 into face properties (bug#7876). */
3788 it
->end_charpos
= ZV
;
3790 /* Return HANDLED_RECOMPUTE_PROPS only if function fontified
3791 something. This avoids an endless loop if they failed to
3792 fontify the text for which reason ever. */
3793 if (!NILP (Fget_char_property (pos
, Qfontified
, Qnil
)))
3794 handled
= HANDLED_RECOMPUTE_PROPS
;
3802 /***********************************************************************
3804 ***********************************************************************/
3806 /* Set up iterator IT from face properties at its current position.
3807 Called from handle_stop. */
3809 static enum prop_handled
3810 handle_face_prop (struct it
*it
)
3813 ptrdiff_t next_stop
;
3815 if (!STRINGP (it
->string
))
3818 = face_at_buffer_position (it
->w
,
3820 it
->region_beg_charpos
,
3821 it
->region_end_charpos
,
3824 + TEXT_PROP_DISTANCE_LIMIT
),
3825 0, it
->base_face_id
);
3827 /* Is this a start of a run of characters with box face?
3828 Caveat: this can be called for a freshly initialized
3829 iterator; face_id is -1 in this case. We know that the new
3830 face will not change until limit, i.e. if the new face has a
3831 box, all characters up to limit will have one. But, as
3832 usual, we don't know whether limit is really the end. */
3833 if (new_face_id
!= it
->face_id
)
3835 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3836 /* If it->face_id is -1, old_face below will be NULL, see
3837 the definition of FACE_FROM_ID. This will happen if this
3838 is the initial call that gets the face. */
3839 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3841 /* If the value of face_id of the iterator is -1, we have to
3842 look in front of IT's position and see whether there is a
3843 face there that's different from new_face_id. */
3844 if (!old_face
&& IT_CHARPOS (*it
) > BEG
)
3846 int prev_face_id
= face_before_it_pos (it
);
3848 old_face
= FACE_FROM_ID (it
->f
, prev_face_id
);
3851 /* If the new face has a box, but the old face does not,
3852 this is the start of a run of characters with box face,
3853 i.e. this character has a shadow on the left side. */
3854 it
->start_of_box_run_p
= (new_face
->box
!= FACE_NO_BOX
3855 && (old_face
== NULL
|| !old_face
->box
));
3856 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3864 Lisp_Object from_overlay
3865 = (it
->current
.overlay_string_index
>= 0
3866 ? it
->string_overlays
[it
->current
.overlay_string_index
3867 % OVERLAY_STRING_CHUNK_SIZE
]
3870 /* See if we got to this string directly or indirectly from
3871 an overlay property. That includes the before-string or
3872 after-string of an overlay, strings in display properties
3873 provided by an overlay, their text properties, etc.
3875 FROM_OVERLAY is the overlay that brought us here, or nil if none. */
3876 if (! NILP (from_overlay
))
3877 for (i
= it
->sp
- 1; i
>= 0; i
--)
3879 if (it
->stack
[i
].current
.overlay_string_index
>= 0)
3881 = it
->string_overlays
[it
->stack
[i
].current
.overlay_string_index
3882 % OVERLAY_STRING_CHUNK_SIZE
];
3883 else if (! NILP (it
->stack
[i
].from_overlay
))
3884 from_overlay
= it
->stack
[i
].from_overlay
;
3886 if (!NILP (from_overlay
))
3890 if (! NILP (from_overlay
))
3892 bufpos
= IT_CHARPOS (*it
);
3893 /* For a string from an overlay, the base face depends
3894 only on text properties and ignores overlays. */
3896 = face_for_overlay_string (it
->w
,
3898 it
->region_beg_charpos
,
3899 it
->region_end_charpos
,
3902 + TEXT_PROP_DISTANCE_LIMIT
),
3910 /* For strings from a `display' property, use the face at
3911 IT's current buffer position as the base face to merge
3912 with, so that overlay strings appear in the same face as
3913 surrounding text, unless they specify their own
3915 base_face_id
= it
->string_from_prefix_prop_p
3917 : underlying_face_id (it
);
3920 new_face_id
= face_at_string_position (it
->w
,
3922 IT_STRING_CHARPOS (*it
),
3924 it
->region_beg_charpos
,
3925 it
->region_end_charpos
,
3929 /* Is this a start of a run of characters with box? Caveat:
3930 this can be called for a freshly allocated iterator; face_id
3931 is -1 is this case. We know that the new face will not
3932 change until the next check pos, i.e. if the new face has a
3933 box, all characters up to that position will have a
3934 box. But, as usual, we don't know whether that position
3935 is really the end. */
3936 if (new_face_id
!= it
->face_id
)
3938 struct face
*new_face
= FACE_FROM_ID (it
->f
, new_face_id
);
3939 struct face
*old_face
= FACE_FROM_ID (it
->f
, it
->face_id
);
3941 /* If new face has a box but old face hasn't, this is the
3942 start of a run of characters with box, i.e. it has a
3943 shadow on the left side. */
3944 it
->start_of_box_run_p
3945 = new_face
->box
&& (old_face
== NULL
|| !old_face
->box
);
3946 it
->face_box_p
= new_face
->box
!= FACE_NO_BOX
;
3950 it
->face_id
= new_face_id
;
3951 return HANDLED_NORMALLY
;
3955 /* Return the ID of the face ``underlying'' IT's current position,
3956 which is in a string. If the iterator is associated with a
3957 buffer, return the face at IT's current buffer position.
3958 Otherwise, use the iterator's base_face_id. */
3961 underlying_face_id (struct it
*it
)
3963 int face_id
= it
->base_face_id
, i
;
3965 eassert (STRINGP (it
->string
));
3967 for (i
= it
->sp
- 1; i
>= 0; --i
)
3968 if (NILP (it
->stack
[i
].string
))
3969 face_id
= it
->stack
[i
].face_id
;
3975 /* Compute the face one character before or after the current position
3976 of IT, in the visual order. BEFORE_P non-zero means get the face
3977 in front (to the left in L2R paragraphs, to the right in R2L
3978 paragraphs) of IT's screen position. Value is the ID of the face. */
3981 face_before_or_after_it_pos (struct it
*it
, int before_p
)
3984 ptrdiff_t next_check_charpos
;
3986 void *it_copy_data
= NULL
;
3988 eassert (it
->s
== NULL
);
3990 if (STRINGP (it
->string
))
3992 ptrdiff_t bufpos
, charpos
;
3995 /* No face change past the end of the string (for the case
3996 we are padding with spaces). No face change before the
3998 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
)
3999 || (IT_STRING_CHARPOS (*it
) == 0 && before_p
))
4004 /* Set charpos to the position before or after IT's current
4005 position, in the logical order, which in the non-bidi
4006 case is the same as the visual order. */
4008 charpos
= IT_STRING_CHARPOS (*it
) - 1;
4009 else if (it
->what
== IT_COMPOSITION
)
4010 /* For composition, we must check the character after the
4012 charpos
= IT_STRING_CHARPOS (*it
) + it
->cmp_it
.nchars
;
4014 charpos
= IT_STRING_CHARPOS (*it
) + 1;
4020 /* With bidi iteration, the character before the current
4021 in the visual order cannot be found by simple
4022 iteration, because "reverse" reordering is not
4023 supported. Instead, we need to use the move_it_*
4024 family of functions. */
4025 /* Ignore face changes before the first visible
4026 character on this display line. */
4027 if (it
->current_x
<= it
->first_visible_x
)
4029 SAVE_IT (it_copy
, *it
, it_copy_data
);
4030 /* Implementation note: Since move_it_in_display_line
4031 works in the iterator geometry, and thinks the first
4032 character is always the leftmost, even in R2L lines,
4033 we don't need to distinguish between the R2L and L2R
4035 move_it_in_display_line (&it_copy
, SCHARS (it_copy
.string
),
4036 it_copy
.current_x
- 1, MOVE_TO_X
);
4037 charpos
= IT_STRING_CHARPOS (it_copy
);
4038 RESTORE_IT (it
, it
, it_copy_data
);
4042 /* Set charpos to the string position of the character
4043 that comes after IT's current position in the visual
4045 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4049 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4051 charpos
= it_copy
.bidi_it
.charpos
;
4054 eassert (0 <= charpos
&& charpos
<= SCHARS (it
->string
));
4056 if (it
->current
.overlay_string_index
>= 0)
4057 bufpos
= IT_CHARPOS (*it
);
4061 base_face_id
= underlying_face_id (it
);
4063 /* Get the face for ASCII, or unibyte. */
4064 face_id
= face_at_string_position (it
->w
,
4068 it
->region_beg_charpos
,
4069 it
->region_end_charpos
,
4070 &next_check_charpos
,
4073 /* Correct the face for charsets different from ASCII. Do it
4074 for the multibyte case only. The face returned above is
4075 suitable for unibyte text if IT->string is unibyte. */
4076 if (STRING_MULTIBYTE (it
->string
))
4078 struct text_pos pos1
= string_pos (charpos
, it
->string
);
4079 const unsigned char *p
= SDATA (it
->string
) + BYTEPOS (pos1
);
4081 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4083 c
= string_char_and_length (p
, &len
);
4084 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, charpos
, it
->string
);
4089 struct text_pos pos
;
4091 if ((IT_CHARPOS (*it
) >= ZV
&& !before_p
)
4092 || (IT_CHARPOS (*it
) <= BEGV
&& before_p
))
4095 limit
= IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
;
4096 pos
= it
->current
.pos
;
4101 DEC_TEXT_POS (pos
, it
->multibyte_p
);
4104 if (it
->what
== IT_COMPOSITION
)
4106 /* For composition, we must check the position after
4108 pos
.charpos
+= it
->cmp_it
.nchars
;
4109 pos
.bytepos
+= it
->len
;
4112 INC_TEXT_POS (pos
, it
->multibyte_p
);
4119 /* With bidi iteration, the character before the current
4120 in the visual order cannot be found by simple
4121 iteration, because "reverse" reordering is not
4122 supported. Instead, we need to use the move_it_*
4123 family of functions. */
4124 /* Ignore face changes before the first visible
4125 character on this display line. */
4126 if (it
->current_x
<= it
->first_visible_x
)
4128 SAVE_IT (it_copy
, *it
, it_copy_data
);
4129 /* Implementation note: Since move_it_in_display_line
4130 works in the iterator geometry, and thinks the first
4131 character is always the leftmost, even in R2L lines,
4132 we don't need to distinguish between the R2L and L2R
4134 move_it_in_display_line (&it_copy
, ZV
,
4135 it_copy
.current_x
- 1, MOVE_TO_X
);
4136 pos
= it_copy
.current
.pos
;
4137 RESTORE_IT (it
, it
, it_copy_data
);
4141 /* Set charpos to the buffer position of the character
4142 that comes after IT's current position in the visual
4144 int n
= (it
->what
== IT_COMPOSITION
? it
->cmp_it
.nchars
: 1);
4148 bidi_move_to_visually_next (&it_copy
.bidi_it
);
4151 it_copy
.bidi_it
.charpos
, it_copy
.bidi_it
.bytepos
);
4154 eassert (BEGV
<= CHARPOS (pos
) && CHARPOS (pos
) <= ZV
);
4156 /* Determine face for CHARSET_ASCII, or unibyte. */
4157 face_id
= face_at_buffer_position (it
->w
,
4159 it
->region_beg_charpos
,
4160 it
->region_end_charpos
,
4161 &next_check_charpos
,
4164 /* Correct the face for charsets different from ASCII. Do it
4165 for the multibyte case only. The face returned above is
4166 suitable for unibyte text if current_buffer is unibyte. */
4167 if (it
->multibyte_p
)
4169 int c
= FETCH_MULTIBYTE_CHAR (BYTEPOS (pos
));
4170 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
4171 face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, CHARPOS (pos
), Qnil
);
4180 /***********************************************************************
4182 ***********************************************************************/
4184 /* Set up iterator IT from invisible properties at its current
4185 position. Called from handle_stop. */
4187 static enum prop_handled
4188 handle_invisible_prop (struct it
*it
)
4190 enum prop_handled handled
= HANDLED_NORMALLY
;
4194 if (STRINGP (it
->string
))
4196 Lisp_Object end_charpos
, limit
, charpos
;
4198 /* Get the value of the invisible text property at the
4199 current position. Value will be nil if there is no such
4201 charpos
= make_number (IT_STRING_CHARPOS (*it
));
4202 prop
= Fget_text_property (charpos
, Qinvisible
, it
->string
);
4203 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4205 if (invis_p
&& IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
4207 /* Record whether we have to display an ellipsis for the
4209 int display_ellipsis_p
= (invis_p
== 2);
4210 ptrdiff_t len
, endpos
;
4212 handled
= HANDLED_RECOMPUTE_PROPS
;
4214 /* Get the position at which the next visible text can be
4215 found in IT->string, if any. */
4216 endpos
= len
= SCHARS (it
->string
);
4217 XSETINT (limit
, len
);
4220 end_charpos
= Fnext_single_property_change (charpos
, Qinvisible
,
4222 if (INTEGERP (end_charpos
))
4224 endpos
= XFASTINT (end_charpos
);
4225 prop
= Fget_text_property (end_charpos
, Qinvisible
, it
->string
);
4226 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4228 display_ellipsis_p
= 1;
4231 while (invis_p
&& endpos
< len
);
4233 if (display_ellipsis_p
)
4238 /* Text at END_CHARPOS is visible. Move IT there. */
4239 struct text_pos old
;
4242 old
= it
->current
.string_pos
;
4243 oldpos
= CHARPOS (old
);
4246 if (it
->bidi_it
.first_elt
4247 && it
->bidi_it
.charpos
< SCHARS (it
->string
))
4248 bidi_paragraph_init (it
->paragraph_embedding
,
4250 /* Bidi-iterate out of the invisible text. */
4253 bidi_move_to_visually_next (&it
->bidi_it
);
4255 while (oldpos
<= it
->bidi_it
.charpos
4256 && it
->bidi_it
.charpos
< endpos
);
4258 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4259 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4260 if (IT_CHARPOS (*it
) >= endpos
)
4261 it
->prev_stop
= endpos
;
4265 IT_STRING_CHARPOS (*it
) = XFASTINT (end_charpos
);
4266 compute_string_pos (&it
->current
.string_pos
, old
, it
->string
);
4271 /* The rest of the string is invisible. If this is an
4272 overlay string, proceed with the next overlay string
4273 or whatever comes and return a character from there. */
4274 if (it
->current
.overlay_string_index
>= 0
4275 && !display_ellipsis_p
)
4277 next_overlay_string (it
);
4278 /* Don't check for overlay strings when we just
4279 finished processing them. */
4280 handled
= HANDLED_OVERLAY_STRING_CONSUMED
;
4284 IT_STRING_CHARPOS (*it
) = SCHARS (it
->string
);
4285 IT_STRING_BYTEPOS (*it
) = SBYTES (it
->string
);
4292 ptrdiff_t newpos
, next_stop
, start_charpos
, tem
;
4293 Lisp_Object pos
, overlay
;
4295 /* First of all, is there invisible text at this position? */
4296 tem
= start_charpos
= IT_CHARPOS (*it
);
4297 pos
= make_number (tem
);
4298 prop
= get_char_property_and_overlay (pos
, Qinvisible
, it
->window
,
4300 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4302 /* If we are on invisible text, skip over it. */
4303 if (invis_p
&& start_charpos
< it
->end_charpos
)
4305 /* Record whether we have to display an ellipsis for the
4307 int display_ellipsis_p
= invis_p
== 2;
4309 handled
= HANDLED_RECOMPUTE_PROPS
;
4311 /* Loop skipping over invisible text. The loop is left at
4312 ZV or with IT on the first char being visible again. */
4315 /* Try to skip some invisible text. Return value is the
4316 position reached which can be equal to where we start
4317 if there is nothing invisible there. This skips both
4318 over invisible text properties and overlays with
4319 invisible property. */
4320 newpos
= skip_invisible (tem
, &next_stop
, ZV
, it
->window
);
4322 /* If we skipped nothing at all we weren't at invisible
4323 text in the first place. If everything to the end of
4324 the buffer was skipped, end the loop. */
4325 if (newpos
== tem
|| newpos
>= ZV
)
4329 /* We skipped some characters but not necessarily
4330 all there are. Check if we ended up on visible
4331 text. Fget_char_property returns the property of
4332 the char before the given position, i.e. if we
4333 get invis_p = 0, this means that the char at
4334 newpos is visible. */
4335 pos
= make_number (newpos
);
4336 prop
= Fget_char_property (pos
, Qinvisible
, it
->window
);
4337 invis_p
= TEXT_PROP_MEANS_INVISIBLE (prop
);
4340 /* If we ended up on invisible text, proceed to
4341 skip starting with next_stop. */
4345 /* If there are adjacent invisible texts, don't lose the
4346 second one's ellipsis. */
4348 display_ellipsis_p
= 1;
4352 /* The position newpos is now either ZV or on visible text. */
4355 ptrdiff_t bpos
= CHAR_TO_BYTE (newpos
);
4357 bpos
== ZV_BYTE
|| FETCH_BYTE (bpos
) == '\n';
4359 newpos
<= BEGV
|| FETCH_BYTE (bpos
- 1) == '\n';
4361 /* If the invisible text ends on a newline or on a
4362 character after a newline, we can avoid the costly,
4363 character by character, bidi iteration to NEWPOS, and
4364 instead simply reseat the iterator there. That's
4365 because all bidi reordering information is tossed at
4366 the newline. This is a big win for modes that hide
4367 complete lines, like Outline, Org, etc. */
4368 if (on_newline
|| after_newline
)
4370 struct text_pos tpos
;
4371 bidi_dir_t pdir
= it
->bidi_it
.paragraph_dir
;
4373 SET_TEXT_POS (tpos
, newpos
, bpos
);
4374 reseat_1 (it
, tpos
, 0);
4375 /* If we reseat on a newline/ZV, we need to prep the
4376 bidi iterator for advancing to the next character
4377 after the newline/EOB, keeping the current paragraph
4378 direction (so that PRODUCE_GLYPHS does TRT wrt
4379 prepending/appending glyphs to a glyph row). */
4382 it
->bidi_it
.first_elt
= 0;
4383 it
->bidi_it
.paragraph_dir
= pdir
;
4384 it
->bidi_it
.ch
= (bpos
== ZV_BYTE
) ? -1 : '\n';
4385 it
->bidi_it
.nchars
= 1;
4386 it
->bidi_it
.ch_len
= 1;
4389 else /* Must use the slow method. */
4391 /* With bidi iteration, the region of invisible text
4392 could start and/or end in the middle of a
4393 non-base embedding level. Therefore, we need to
4394 skip invisible text using the bidi iterator,
4395 starting at IT's current position, until we find
4396 ourselves outside of the invisible text.
4397 Skipping invisible text _after_ bidi iteration
4398 avoids affecting the visual order of the
4399 displayed text when invisible properties are
4400 added or removed. */
4401 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< ZV
)
4403 /* If we were `reseat'ed to a new paragraph,
4404 determine the paragraph base direction. We
4405 need to do it now because
4406 next_element_from_buffer may not have a
4407 chance to do it, if we are going to skip any
4408 text at the beginning, which resets the
4410 bidi_paragraph_init (it
->paragraph_embedding
,
4415 bidi_move_to_visually_next (&it
->bidi_it
);
4417 while (it
->stop_charpos
<= it
->bidi_it
.charpos
4418 && it
->bidi_it
.charpos
< newpos
);
4419 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
4420 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
4421 /* If we overstepped NEWPOS, record its position in
4422 the iterator, so that we skip invisible text if
4423 later the bidi iteration lands us in the
4424 invisible region again. */
4425 if (IT_CHARPOS (*it
) >= newpos
)
4426 it
->prev_stop
= newpos
;
4431 IT_CHARPOS (*it
) = newpos
;
4432 IT_BYTEPOS (*it
) = CHAR_TO_BYTE (newpos
);
4435 /* If there are before-strings at the start of invisible
4436 text, and the text is invisible because of a text
4437 property, arrange to show before-strings because 20.x did
4438 it that way. (If the text is invisible because of an
4439 overlay property instead of a text property, this is
4440 already handled in the overlay code.) */
4442 && get_overlay_strings (it
, it
->stop_charpos
))
4444 handled
= HANDLED_RECOMPUTE_PROPS
;
4445 it
->stack
[it
->sp
- 1].display_ellipsis_p
= display_ellipsis_p
;
4447 else if (display_ellipsis_p
)
4449 /* Make sure that the glyphs of the ellipsis will get
4450 correct `charpos' values. If we would not update
4451 it->position here, the glyphs would belong to the
4452 last visible character _before_ the invisible
4453 text, which confuses `set_cursor_from_row'.
4455 We use the last invisible position instead of the
4456 first because this way the cursor is always drawn on
4457 the first "." of the ellipsis, whenever PT is inside
4458 the invisible text. Otherwise the cursor would be
4459 placed _after_ the ellipsis when the point is after the
4460 first invisible character. */
4461 if (!STRINGP (it
->object
))
4463 it
->position
.charpos
= newpos
- 1;
4464 it
->position
.bytepos
= CHAR_TO_BYTE (it
->position
.charpos
);
4467 /* Let the ellipsis display before
4468 considering any properties of the following char.
4469 Fixes jasonr@gnu.org 01 Oct 07 bug. */
4470 handled
= HANDLED_RETURN
;
4479 /* Make iterator IT return `...' next.
4480 Replaces LEN characters from buffer. */
4483 setup_for_ellipsis (struct it
*it
, int len
)
4485 /* Use the display table definition for `...'. Invalid glyphs
4486 will be handled by the method returning elements from dpvec. */
4487 if (it
->dp
&& VECTORP (DISP_INVIS_VECTOR (it
->dp
)))
4489 struct Lisp_Vector
*v
= XVECTOR (DISP_INVIS_VECTOR (it
->dp
));
4490 it
->dpvec
= v
->contents
;
4491 it
->dpend
= v
->contents
+ v
->header
.size
;
4495 /* Default `...'. */
4496 it
->dpvec
= default_invis_vector
;
4497 it
->dpend
= default_invis_vector
+ 3;
4500 it
->dpvec_char_len
= len
;
4501 it
->current
.dpvec_index
= 0;
4502 it
->dpvec_face_id
= -1;
4504 /* Remember the current face id in case glyphs specify faces.
4505 IT's face is restored in set_iterator_to_next.
4506 saved_face_id was set to preceding char's face in handle_stop. */
4507 if (it
->saved_face_id
< 0 || it
->saved_face_id
!= it
->face_id
)
4508 it
->saved_face_id
= it
->face_id
= DEFAULT_FACE_ID
;
4510 it
->method
= GET_FROM_DISPLAY_VECTOR
;
4516 /***********************************************************************
4518 ***********************************************************************/
4520 /* Set up iterator IT from `display' property at its current position.
4521 Called from handle_stop.
4522 We return HANDLED_RETURN if some part of the display property
4523 overrides the display of the buffer text itself.
4524 Otherwise we return HANDLED_NORMALLY. */
4526 static enum prop_handled
4527 handle_display_prop (struct it
*it
)
4529 Lisp_Object propval
, object
, overlay
;
4530 struct text_pos
*position
;
4532 /* Nonzero if some property replaces the display of the text itself. */
4533 int display_replaced_p
= 0;
4535 if (STRINGP (it
->string
))
4537 object
= it
->string
;
4538 position
= &it
->current
.string_pos
;
4539 bufpos
= CHARPOS (it
->current
.pos
);
4543 XSETWINDOW (object
, it
->w
);
4544 position
= &it
->current
.pos
;
4545 bufpos
= CHARPOS (*position
);
4548 /* Reset those iterator values set from display property values. */
4549 it
->slice
.x
= it
->slice
.y
= it
->slice
.width
= it
->slice
.height
= Qnil
;
4550 it
->space_width
= Qnil
;
4551 it
->font_height
= Qnil
;
4554 /* We don't support recursive `display' properties, i.e. string
4555 values that have a string `display' property, that have a string
4556 `display' property etc. */
4557 if (!it
->string_from_display_prop_p
)
4558 it
->area
= TEXT_AREA
;
4560 propval
= get_char_property_and_overlay (make_number (position
->charpos
),
4561 Qdisplay
, object
, &overlay
);
4563 return HANDLED_NORMALLY
;
4564 /* Now OVERLAY is the overlay that gave us this property, or nil
4565 if it was a text property. */
4567 if (!STRINGP (it
->string
))
4568 object
= it
->w
->contents
;
4570 display_replaced_p
= handle_display_spec (it
, propval
, object
, overlay
,
4572 FRAME_WINDOW_P (it
->f
));
4574 return display_replaced_p
? HANDLED_RETURN
: HANDLED_NORMALLY
;
4577 /* Subroutine of handle_display_prop. Returns non-zero if the display
4578 specification in SPEC is a replacing specification, i.e. it would
4579 replace the text covered by `display' property with something else,
4580 such as an image or a display string. If SPEC includes any kind or
4581 `(space ...) specification, the value is 2; this is used by
4582 compute_display_string_pos, which see.
4584 See handle_single_display_spec for documentation of arguments.
4585 frame_window_p is non-zero if the window being redisplayed is on a
4586 GUI frame; this argument is used only if IT is NULL, see below.
4588 IT can be NULL, if this is called by the bidi reordering code
4589 through compute_display_string_pos, which see. In that case, this
4590 function only examines SPEC, but does not otherwise "handle" it, in
4591 the sense that it doesn't set up members of IT from the display
4594 handle_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4595 Lisp_Object overlay
, struct text_pos
*position
,
4596 ptrdiff_t bufpos
, int frame_window_p
)
4598 int replacing_p
= 0;
4602 /* Simple specifications. */
4603 && !EQ (XCAR (spec
), Qimage
)
4604 && !EQ (XCAR (spec
), Qspace
)
4605 && !EQ (XCAR (spec
), Qwhen
)
4606 && !EQ (XCAR (spec
), Qslice
)
4607 && !EQ (XCAR (spec
), Qspace_width
)
4608 && !EQ (XCAR (spec
), Qheight
)
4609 && !EQ (XCAR (spec
), Qraise
)
4610 /* Marginal area specifications. */
4611 && !(CONSP (XCAR (spec
)) && EQ (XCAR (XCAR (spec
)), Qmargin
))
4612 && !EQ (XCAR (spec
), Qleft_fringe
)
4613 && !EQ (XCAR (spec
), Qright_fringe
)
4614 && !NILP (XCAR (spec
)))
4616 for (; CONSP (spec
); spec
= XCDR (spec
))
4618 if ((rv
= handle_single_display_spec (it
, XCAR (spec
), object
,
4619 overlay
, position
, bufpos
,
4620 replacing_p
, frame_window_p
)))
4623 /* If some text in a string is replaced, `position' no
4624 longer points to the position of `object'. */
4625 if (!it
|| STRINGP (object
))
4630 else if (VECTORP (spec
))
4633 for (i
= 0; i
< ASIZE (spec
); ++i
)
4634 if ((rv
= handle_single_display_spec (it
, AREF (spec
, i
), object
,
4635 overlay
, position
, bufpos
,
4636 replacing_p
, frame_window_p
)))
4639 /* If some text in a string is replaced, `position' no
4640 longer points to the position of `object'. */
4641 if (!it
|| STRINGP (object
))
4647 if ((rv
= handle_single_display_spec (it
, spec
, object
, overlay
,
4648 position
, bufpos
, 0,
4656 /* Value is the position of the end of the `display' property starting
4657 at START_POS in OBJECT. */
4659 static struct text_pos
4660 display_prop_end (struct it
*it
, Lisp_Object object
, struct text_pos start_pos
)
4663 struct text_pos end_pos
;
4665 end
= Fnext_single_char_property_change (make_number (CHARPOS (start_pos
)),
4666 Qdisplay
, object
, Qnil
);
4667 CHARPOS (end_pos
) = XFASTINT (end
);
4668 if (STRINGP (object
))
4669 compute_string_pos (&end_pos
, start_pos
, it
->string
);
4671 BYTEPOS (end_pos
) = CHAR_TO_BYTE (XFASTINT (end
));
4677 /* Set up IT from a single `display' property specification SPEC. OBJECT
4678 is the object in which the `display' property was found. *POSITION
4679 is the position in OBJECT at which the `display' property was found.
4680 BUFPOS is the buffer position of OBJECT (different from POSITION if
4681 OBJECT is not a buffer). DISPLAY_REPLACED_P non-zero means that we
4682 previously saw a display specification which already replaced text
4683 display with something else, for example an image; we ignore such
4684 properties after the first one has been processed.
4686 OVERLAY is the overlay this `display' property came from,
4687 or nil if it was a text property.
4689 If SPEC is a `space' or `image' specification, and in some other
4690 cases too, set *POSITION to the position where the `display'
4693 If IT is NULL, only examine the property specification in SPEC, but
4694 don't set up IT. In that case, FRAME_WINDOW_P non-zero means SPEC
4695 is intended to be displayed in a window on a GUI frame.
4697 Value is non-zero if something was found which replaces the display
4698 of buffer or string text. */
4701 handle_single_display_spec (struct it
*it
, Lisp_Object spec
, Lisp_Object object
,
4702 Lisp_Object overlay
, struct text_pos
*position
,
4703 ptrdiff_t bufpos
, int display_replaced_p
,
4707 Lisp_Object location
, value
;
4708 struct text_pos start_pos
= *position
;
4711 /* If SPEC is a list of the form `(when FORM . VALUE)', evaluate FORM.
4712 If the result is non-nil, use VALUE instead of SPEC. */
4714 if (CONSP (spec
) && EQ (XCAR (spec
), Qwhen
))
4723 if (!NILP (form
) && !EQ (form
, Qt
))
4725 ptrdiff_t count
= SPECPDL_INDEX ();
4726 struct gcpro gcpro1
;
4728 /* Bind `object' to the object having the `display' property, a
4729 buffer or string. Bind `position' to the position in the
4730 object where the property was found, and `buffer-position'
4731 to the current position in the buffer. */
4734 XSETBUFFER (object
, current_buffer
);
4735 specbind (Qobject
, object
);
4736 specbind (Qposition
, make_number (CHARPOS (*position
)));
4737 specbind (Qbuffer_position
, make_number (bufpos
));
4739 form
= safe_eval (form
);
4741 unbind_to (count
, Qnil
);
4747 /* Handle `(height HEIGHT)' specifications. */
4749 && EQ (XCAR (spec
), Qheight
)
4750 && CONSP (XCDR (spec
)))
4754 if (!FRAME_WINDOW_P (it
->f
))
4757 it
->font_height
= XCAR (XCDR (spec
));
4758 if (!NILP (it
->font_height
))
4760 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4761 int new_height
= -1;
4763 if (CONSP (it
->font_height
)
4764 && (EQ (XCAR (it
->font_height
), Qplus
)
4765 || EQ (XCAR (it
->font_height
), Qminus
))
4766 && CONSP (XCDR (it
->font_height
))
4767 && RANGED_INTEGERP (0, XCAR (XCDR (it
->font_height
)), INT_MAX
))
4769 /* `(+ N)' or `(- N)' where N is an integer. */
4770 int steps
= XINT (XCAR (XCDR (it
->font_height
)));
4771 if (EQ (XCAR (it
->font_height
), Qplus
))
4773 it
->face_id
= smaller_face (it
->f
, it
->face_id
, steps
);
4775 else if (FUNCTIONP (it
->font_height
))
4777 /* Call function with current height as argument.
4778 Value is the new height. */
4780 height
= safe_call1 (it
->font_height
,
4781 face
->lface
[LFACE_HEIGHT_INDEX
]);
4782 if (NUMBERP (height
))
4783 new_height
= XFLOATINT (height
);
4785 else if (NUMBERP (it
->font_height
))
4787 /* Value is a multiple of the canonical char height. */
4790 f
= FACE_FROM_ID (it
->f
,
4791 lookup_basic_face (it
->f
, DEFAULT_FACE_ID
));
4792 new_height
= (XFLOATINT (it
->font_height
)
4793 * XINT (f
->lface
[LFACE_HEIGHT_INDEX
]));
4797 /* Evaluate IT->font_height with `height' bound to the
4798 current specified height to get the new height. */
4799 ptrdiff_t count
= SPECPDL_INDEX ();
4801 specbind (Qheight
, face
->lface
[LFACE_HEIGHT_INDEX
]);
4802 value
= safe_eval (it
->font_height
);
4803 unbind_to (count
, Qnil
);
4805 if (NUMBERP (value
))
4806 new_height
= XFLOATINT (value
);
4810 it
->face_id
= face_with_height (it
->f
, it
->face_id
, new_height
);
4817 /* Handle `(space-width WIDTH)'. */
4819 && EQ (XCAR (spec
), Qspace_width
)
4820 && CONSP (XCDR (spec
)))
4824 if (!FRAME_WINDOW_P (it
->f
))
4827 value
= XCAR (XCDR (spec
));
4828 if (NUMBERP (value
) && XFLOATINT (value
) > 0)
4829 it
->space_width
= value
;
4835 /* Handle `(slice X Y WIDTH HEIGHT)'. */
4837 && EQ (XCAR (spec
), Qslice
))
4843 if (!FRAME_WINDOW_P (it
->f
))
4846 if (tem
= XCDR (spec
), CONSP (tem
))
4848 it
->slice
.x
= XCAR (tem
);
4849 if (tem
= XCDR (tem
), CONSP (tem
))
4851 it
->slice
.y
= XCAR (tem
);
4852 if (tem
= XCDR (tem
), CONSP (tem
))
4854 it
->slice
.width
= XCAR (tem
);
4855 if (tem
= XCDR (tem
), CONSP (tem
))
4856 it
->slice
.height
= XCAR (tem
);
4865 /* Handle `(raise FACTOR)'. */
4867 && EQ (XCAR (spec
), Qraise
)
4868 && CONSP (XCDR (spec
)))
4872 if (!FRAME_WINDOW_P (it
->f
))
4875 #ifdef HAVE_WINDOW_SYSTEM
4876 value
= XCAR (XCDR (spec
));
4877 if (NUMBERP (value
))
4879 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
4880 it
->voffset
= - (XFLOATINT (value
)
4881 * (FONT_HEIGHT (face
->font
)));
4883 #endif /* HAVE_WINDOW_SYSTEM */
4889 /* Don't handle the other kinds of display specifications
4890 inside a string that we got from a `display' property. */
4891 if (it
&& it
->string_from_display_prop_p
)
4894 /* Characters having this form of property are not displayed, so
4895 we have to find the end of the property. */
4898 start_pos
= *position
;
4899 *position
= display_prop_end (it
, object
, start_pos
);
4903 /* Stop the scan at that end position--we assume that all
4904 text properties change there. */
4906 it
->stop_charpos
= position
->charpos
;
4908 /* Handle `(left-fringe BITMAP [FACE])'
4909 and `(right-fringe BITMAP [FACE])'. */
4911 && (EQ (XCAR (spec
), Qleft_fringe
)
4912 || EQ (XCAR (spec
), Qright_fringe
))
4913 && CONSP (XCDR (spec
)))
4919 if (!FRAME_WINDOW_P (it
->f
))
4920 /* If we return here, POSITION has been advanced
4921 across the text with this property. */
4923 /* Synchronize the bidi iterator with POSITION. This is
4924 needed because we are not going to push the iterator
4925 on behalf of this display property, so there will be
4926 no pop_it call to do this synchronization for us. */
4929 it
->position
= *position
;
4930 iterate_out_of_display_property (it
);
4931 *position
= it
->position
;
4936 else if (!frame_window_p
)
4939 #ifdef HAVE_WINDOW_SYSTEM
4940 value
= XCAR (XCDR (spec
));
4941 if (!SYMBOLP (value
)
4942 || !(fringe_bitmap
= lookup_fringe_bitmap (value
)))
4943 /* If we return here, POSITION has been advanced
4944 across the text with this property. */
4946 if (it
&& it
->bidi_p
)
4948 it
->position
= *position
;
4949 iterate_out_of_display_property (it
);
4950 *position
= it
->position
;
4957 int face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);;
4959 if (CONSP (XCDR (XCDR (spec
))))
4961 Lisp_Object face_name
= XCAR (XCDR (XCDR (spec
)));
4962 int face_id2
= lookup_derived_face (it
->f
, face_name
,
4968 /* Save current settings of IT so that we can restore them
4969 when we are finished with the glyph property value. */
4970 push_it (it
, position
);
4972 it
->area
= TEXT_AREA
;
4973 it
->what
= IT_IMAGE
;
4974 it
->image_id
= -1; /* no image */
4975 it
->position
= start_pos
;
4976 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
4977 it
->method
= GET_FROM_IMAGE
;
4978 it
->from_overlay
= Qnil
;
4979 it
->face_id
= face_id
;
4980 it
->from_disp_prop_p
= 1;
4982 /* Say that we haven't consumed the characters with
4983 `display' property yet. The call to pop_it in
4984 set_iterator_to_next will clean this up. */
4985 *position
= start_pos
;
4987 if (EQ (XCAR (spec
), Qleft_fringe
))
4989 it
->left_user_fringe_bitmap
= fringe_bitmap
;
4990 it
->left_user_fringe_face_id
= face_id
;
4994 it
->right_user_fringe_bitmap
= fringe_bitmap
;
4995 it
->right_user_fringe_face_id
= face_id
;
4998 #endif /* HAVE_WINDOW_SYSTEM */
5002 /* Prepare to handle `((margin left-margin) ...)',
5003 `((margin right-margin) ...)' and `((margin nil) ...)'
5004 prefixes for display specifications. */
5005 location
= Qunbound
;
5006 if (CONSP (spec
) && CONSP (XCAR (spec
)))
5010 value
= XCDR (spec
);
5012 value
= XCAR (value
);
5015 if (EQ (XCAR (tem
), Qmargin
)
5016 && (tem
= XCDR (tem
),
5017 tem
= CONSP (tem
) ? XCAR (tem
) : Qnil
,
5019 || EQ (tem
, Qleft_margin
)
5020 || EQ (tem
, Qright_margin
))))
5024 if (EQ (location
, Qunbound
))
5030 /* After this point, VALUE is the property after any
5031 margin prefix has been stripped. It must be a string,
5032 an image specification, or `(space ...)'.
5034 LOCATION specifies where to display: `left-margin',
5035 `right-margin' or nil. */
5037 valid_p
= (STRINGP (value
)
5038 #ifdef HAVE_WINDOW_SYSTEM
5039 || ((it
? FRAME_WINDOW_P (it
->f
) : frame_window_p
)
5040 && valid_image_p (value
))
5041 #endif /* not HAVE_WINDOW_SYSTEM */
5042 || (CONSP (value
) && EQ (XCAR (value
), Qspace
)));
5044 if (valid_p
&& !display_replaced_p
)
5050 /* Callers need to know whether the display spec is any kind
5051 of `(space ...)' spec that is about to affect text-area
5053 if (CONSP (value
) && EQ (XCAR (value
), Qspace
) && NILP (location
))
5058 /* Save current settings of IT so that we can restore them
5059 when we are finished with the glyph property value. */
5060 push_it (it
, position
);
5061 it
->from_overlay
= overlay
;
5062 it
->from_disp_prop_p
= 1;
5064 if (NILP (location
))
5065 it
->area
= TEXT_AREA
;
5066 else if (EQ (location
, Qleft_margin
))
5067 it
->area
= LEFT_MARGIN_AREA
;
5069 it
->area
= RIGHT_MARGIN_AREA
;
5071 if (STRINGP (value
))
5074 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5075 it
->current
.overlay_string_index
= -1;
5076 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5077 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
5078 it
->method
= GET_FROM_STRING
;
5079 it
->stop_charpos
= 0;
5081 it
->base_level_stop
= 0;
5082 it
->string_from_display_prop_p
= 1;
5083 /* Say that we haven't consumed the characters with
5084 `display' property yet. The call to pop_it in
5085 set_iterator_to_next will clean this up. */
5086 if (BUFFERP (object
))
5087 *position
= start_pos
;
5089 /* Force paragraph direction to be that of the parent
5090 object. If the parent object's paragraph direction is
5091 not yet determined, default to L2R. */
5092 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5093 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5095 it
->paragraph_embedding
= L2R
;
5097 /* Set up the bidi iterator for this display string. */
5100 it
->bidi_it
.string
.lstring
= it
->string
;
5101 it
->bidi_it
.string
.s
= NULL
;
5102 it
->bidi_it
.string
.schars
= it
->end_charpos
;
5103 it
->bidi_it
.string
.bufpos
= bufpos
;
5104 it
->bidi_it
.string
.from_disp_str
= 1;
5105 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5106 it
->bidi_it
.w
= it
->w
;
5107 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5110 else if (CONSP (value
) && EQ (XCAR (value
), Qspace
))
5112 it
->method
= GET_FROM_STRETCH
;
5114 *position
= it
->position
= start_pos
;
5115 retval
= 1 + (it
->area
== TEXT_AREA
);
5117 #ifdef HAVE_WINDOW_SYSTEM
5120 it
->what
= IT_IMAGE
;
5121 it
->image_id
= lookup_image (it
->f
, value
);
5122 it
->position
= start_pos
;
5123 it
->object
= NILP (object
) ? it
->w
->contents
: object
;
5124 it
->method
= GET_FROM_IMAGE
;
5126 /* Say that we haven't consumed the characters with
5127 `display' property yet. The call to pop_it in
5128 set_iterator_to_next will clean this up. */
5129 *position
= start_pos
;
5131 #endif /* HAVE_WINDOW_SYSTEM */
5136 /* Invalid property or property not supported. Restore
5137 POSITION to what it was before. */
5138 *position
= start_pos
;
5142 /* Check if PROP is a display property value whose text should be
5143 treated as intangible. OVERLAY is the overlay from which PROP
5144 came, or nil if it came from a text property. CHARPOS and BYTEPOS
5145 specify the buffer position covered by PROP. */
5148 display_prop_intangible_p (Lisp_Object prop
, Lisp_Object overlay
,
5149 ptrdiff_t charpos
, ptrdiff_t bytepos
)
5151 int frame_window_p
= FRAME_WINDOW_P (XFRAME (selected_frame
));
5152 struct text_pos position
;
5154 SET_TEXT_POS (position
, charpos
, bytepos
);
5155 return handle_display_spec (NULL
, prop
, Qnil
, overlay
,
5156 &position
, charpos
, frame_window_p
);
5160 /* Return 1 if PROP is a display sub-property value containing STRING.
5162 Implementation note: this and the following function are really
5163 special cases of handle_display_spec and
5164 handle_single_display_spec, and should ideally use the same code.
5165 Until they do, these two pairs must be consistent and must be
5166 modified in sync. */
5169 single_display_spec_string_p (Lisp_Object prop
, Lisp_Object string
)
5171 if (EQ (string
, prop
))
5174 /* Skip over `when FORM'. */
5175 if (CONSP (prop
) && EQ (XCAR (prop
), Qwhen
))
5180 /* Actually, the condition following `when' should be eval'ed,
5181 like handle_single_display_spec does, and we should return
5182 zero if it evaluates to nil. However, this function is
5183 called only when the buffer was already displayed and some
5184 glyph in the glyph matrix was found to come from a display
5185 string. Therefore, the condition was already evaluated, and
5186 the result was non-nil, otherwise the display string wouldn't
5187 have been displayed and we would have never been called for
5188 this property. Thus, we can skip the evaluation and assume
5189 its result is non-nil. */
5194 /* Skip over `margin LOCATION'. */
5195 if (EQ (XCAR (prop
), Qmargin
))
5206 return EQ (prop
, string
) || (CONSP (prop
) && EQ (XCAR (prop
), string
));
5210 /* Return 1 if STRING appears in the `display' property PROP. */
5213 display_prop_string_p (Lisp_Object prop
, Lisp_Object string
)
5216 && !EQ (XCAR (prop
), Qwhen
)
5217 && !(CONSP (XCAR (prop
)) && EQ (Qmargin
, XCAR (XCAR (prop
)))))
5219 /* A list of sub-properties. */
5220 while (CONSP (prop
))
5222 if (single_display_spec_string_p (XCAR (prop
), string
))
5227 else if (VECTORP (prop
))
5229 /* A vector of sub-properties. */
5231 for (i
= 0; i
< ASIZE (prop
); ++i
)
5232 if (single_display_spec_string_p (AREF (prop
, i
), string
))
5236 return single_display_spec_string_p (prop
, string
);
5241 /* Look for STRING in overlays and text properties in the current
5242 buffer, between character positions FROM and TO (excluding TO).
5243 BACK_P non-zero means look back (in this case, TO is supposed to be
5245 Value is the first character position where STRING was found, or
5246 zero if it wasn't found before hitting TO.
5248 This function may only use code that doesn't eval because it is
5249 called asynchronously from note_mouse_highlight. */
5252 string_buffer_position_lim (Lisp_Object string
,
5253 ptrdiff_t from
, ptrdiff_t to
, int back_p
)
5255 Lisp_Object limit
, prop
, pos
;
5258 pos
= make_number (max (from
, BEGV
));
5260 if (!back_p
) /* looking forward */
5262 limit
= make_number (min (to
, ZV
));
5263 while (!found
&& !EQ (pos
, limit
))
5265 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5266 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5269 pos
= Fnext_single_char_property_change (pos
, Qdisplay
, Qnil
,
5273 else /* looking back */
5275 limit
= make_number (max (to
, BEGV
));
5276 while (!found
&& !EQ (pos
, limit
))
5278 prop
= Fget_char_property (pos
, Qdisplay
, Qnil
);
5279 if (!NILP (prop
) && display_prop_string_p (prop
, string
))
5282 pos
= Fprevious_single_char_property_change (pos
, Qdisplay
, Qnil
,
5287 return found
? XINT (pos
) : 0;
5290 /* Determine which buffer position in current buffer STRING comes from.
5291 AROUND_CHARPOS is an approximate position where it could come from.
5292 Value is the buffer position or 0 if it couldn't be determined.
5294 This function is necessary because we don't record buffer positions
5295 in glyphs generated from strings (to keep struct glyph small).
5296 This function may only use code that doesn't eval because it is
5297 called asynchronously from note_mouse_highlight. */
5300 string_buffer_position (Lisp_Object string
, ptrdiff_t around_charpos
)
5302 const int MAX_DISTANCE
= 1000;
5303 ptrdiff_t found
= string_buffer_position_lim (string
, around_charpos
,
5304 around_charpos
+ MAX_DISTANCE
,
5308 found
= string_buffer_position_lim (string
, around_charpos
,
5309 around_charpos
- MAX_DISTANCE
, 1);
5315 /***********************************************************************
5316 `composition' property
5317 ***********************************************************************/
5319 /* Set up iterator IT from `composition' property at its current
5320 position. Called from handle_stop. */
5322 static enum prop_handled
5323 handle_composition_prop (struct it
*it
)
5325 Lisp_Object prop
, string
;
5326 ptrdiff_t pos
, pos_byte
, start
, end
;
5328 if (STRINGP (it
->string
))
5332 pos
= IT_STRING_CHARPOS (*it
);
5333 pos_byte
= IT_STRING_BYTEPOS (*it
);
5334 string
= it
->string
;
5335 s
= SDATA (string
) + pos_byte
;
5336 it
->c
= STRING_CHAR (s
);
5340 pos
= IT_CHARPOS (*it
);
5341 pos_byte
= IT_BYTEPOS (*it
);
5343 it
->c
= FETCH_CHAR (pos_byte
);
5346 /* If there's a valid composition and point is not inside of the
5347 composition (in the case that the composition is from the current
5348 buffer), draw a glyph composed from the composition components. */
5349 if (find_composition (pos
, -1, &start
, &end
, &prop
, string
)
5350 && COMPOSITION_VALID_P (start
, end
, prop
)
5351 && (STRINGP (it
->string
) || (PT
<= start
|| PT
>= end
)))
5354 /* As we can't handle this situation (perhaps font-lock added
5355 a new composition), we just return here hoping that next
5356 redisplay will detect this composition much earlier. */
5357 return HANDLED_NORMALLY
;
5360 if (STRINGP (it
->string
))
5361 pos_byte
= string_char_to_byte (it
->string
, start
);
5363 pos_byte
= CHAR_TO_BYTE (start
);
5365 it
->cmp_it
.id
= get_composition_id (start
, pos_byte
, end
- start
,
5368 if (it
->cmp_it
.id
>= 0)
5371 it
->cmp_it
.nchars
= COMPOSITION_LENGTH (prop
);
5372 it
->cmp_it
.nglyphs
= -1;
5376 return HANDLED_NORMALLY
;
5381 /***********************************************************************
5383 ***********************************************************************/
5385 /* The following structure is used to record overlay strings for
5386 later sorting in load_overlay_strings. */
5388 struct overlay_entry
5390 Lisp_Object overlay
;
5397 /* Set up iterator IT from overlay strings at its current position.
5398 Called from handle_stop. */
5400 static enum prop_handled
5401 handle_overlay_change (struct it
*it
)
5403 if (!STRINGP (it
->string
) && get_overlay_strings (it
, 0))
5404 return HANDLED_RECOMPUTE_PROPS
;
5406 return HANDLED_NORMALLY
;
5410 /* Set up the next overlay string for delivery by IT, if there is an
5411 overlay string to deliver. Called by set_iterator_to_next when the
5412 end of the current overlay string is reached. If there are more
5413 overlay strings to display, IT->string and
5414 IT->current.overlay_string_index are set appropriately here.
5415 Otherwise IT->string is set to nil. */
5418 next_overlay_string (struct it
*it
)
5420 ++it
->current
.overlay_string_index
;
5421 if (it
->current
.overlay_string_index
== it
->n_overlay_strings
)
5423 /* No more overlay strings. Restore IT's settings to what
5424 they were before overlay strings were processed, and
5425 continue to deliver from current_buffer. */
5427 it
->ellipsis_p
= (it
->stack
[it
->sp
- 1].display_ellipsis_p
!= 0);
5430 || (NILP (it
->string
)
5431 && it
->method
== GET_FROM_BUFFER
5432 && it
->stop_charpos
>= BEGV
5433 && it
->stop_charpos
<= it
->end_charpos
));
5434 it
->current
.overlay_string_index
= -1;
5435 it
->n_overlay_strings
= 0;
5436 it
->overlay_strings_charpos
= -1;
5437 /* If there's an empty display string on the stack, pop the
5438 stack, to resync the bidi iterator with IT's position. Such
5439 empty strings are pushed onto the stack in
5440 get_overlay_strings_1. */
5441 if (it
->sp
> 0 && STRINGP (it
->string
) && !SCHARS (it
->string
))
5444 /* If we're at the end of the buffer, record that we have
5445 processed the overlay strings there already, so that
5446 next_element_from_buffer doesn't try it again. */
5447 if (NILP (it
->string
) && IT_CHARPOS (*it
) >= it
->end_charpos
)
5448 it
->overlay_strings_at_end_processed_p
= 1;
5452 /* There are more overlay strings to process. If
5453 IT->current.overlay_string_index has advanced to a position
5454 where we must load IT->overlay_strings with more strings, do
5455 it. We must load at the IT->overlay_strings_charpos where
5456 IT->n_overlay_strings was originally computed; when invisible
5457 text is present, this might not be IT_CHARPOS (Bug#7016). */
5458 int i
= it
->current
.overlay_string_index
% OVERLAY_STRING_CHUNK_SIZE
;
5460 if (it
->current
.overlay_string_index
&& i
== 0)
5461 load_overlay_strings (it
, it
->overlay_strings_charpos
);
5463 /* Initialize IT to deliver display elements from the overlay
5465 it
->string
= it
->overlay_strings
[i
];
5466 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5467 SET_TEXT_POS (it
->current
.string_pos
, 0, 0);
5468 it
->method
= GET_FROM_STRING
;
5469 it
->stop_charpos
= 0;
5470 it
->end_charpos
= SCHARS (it
->string
);
5471 if (it
->cmp_it
.stop_pos
>= 0)
5472 it
->cmp_it
.stop_pos
= 0;
5474 it
->base_level_stop
= 0;
5476 /* Set up the bidi iterator for this overlay string. */
5479 it
->bidi_it
.string
.lstring
= it
->string
;
5480 it
->bidi_it
.string
.s
= NULL
;
5481 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5482 it
->bidi_it
.string
.bufpos
= it
->overlay_strings_charpos
;
5483 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5484 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5485 it
->bidi_it
.w
= it
->w
;
5486 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5494 /* Compare two overlay_entry structures E1 and E2. Used as a
5495 comparison function for qsort in load_overlay_strings. Overlay
5496 strings for the same position are sorted so that
5498 1. All after-strings come in front of before-strings, except
5499 when they come from the same overlay.
5501 2. Within after-strings, strings are sorted so that overlay strings
5502 from overlays with higher priorities come first.
5504 2. Within before-strings, strings are sorted so that overlay
5505 strings from overlays with higher priorities come last.
5507 Value is analogous to strcmp. */
5511 compare_overlay_entries (const void *e1
, const void *e2
)
5513 struct overlay_entry
*entry1
= (struct overlay_entry
*) e1
;
5514 struct overlay_entry
*entry2
= (struct overlay_entry
*) e2
;
5517 if (entry1
->after_string_p
!= entry2
->after_string_p
)
5519 /* Let after-strings appear in front of before-strings if
5520 they come from different overlays. */
5521 if (EQ (entry1
->overlay
, entry2
->overlay
))
5522 result
= entry1
->after_string_p
? 1 : -1;
5524 result
= entry1
->after_string_p
? -1 : 1;
5526 else if (entry1
->priority
!= entry2
->priority
)
5528 if (entry1
->after_string_p
)
5529 /* After-strings sorted in order of decreasing priority. */
5530 result
= entry2
->priority
< entry1
->priority
? -1 : 1;
5532 /* Before-strings sorted in order of increasing priority. */
5533 result
= entry1
->priority
< entry2
->priority
? -1 : 1;
5542 /* Load the vector IT->overlay_strings with overlay strings from IT's
5543 current buffer position, or from CHARPOS if that is > 0. Set
5544 IT->n_overlays to the total number of overlay strings found.
5546 Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at
5547 a time. On entry into load_overlay_strings,
5548 IT->current.overlay_string_index gives the number of overlay
5549 strings that have already been loaded by previous calls to this
5552 IT->add_overlay_start contains an additional overlay start
5553 position to consider for taking overlay strings from, if non-zero.
5554 This position comes into play when the overlay has an `invisible'
5555 property, and both before and after-strings. When we've skipped to
5556 the end of the overlay, because of its `invisible' property, we
5557 nevertheless want its before-string to appear.
5558 IT->add_overlay_start will contain the overlay start position
5561 Overlay strings are sorted so that after-string strings come in
5562 front of before-string strings. Within before and after-strings,
5563 strings are sorted by overlay priority. See also function
5564 compare_overlay_entries. */
5567 load_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5569 Lisp_Object overlay
, window
, str
, invisible
;
5570 struct Lisp_Overlay
*ov
;
5571 ptrdiff_t start
, end
;
5572 ptrdiff_t size
= 20;
5573 ptrdiff_t n
= 0, i
, j
;
5575 struct overlay_entry
*entries
= alloca (size
* sizeof *entries
);
5579 charpos
= IT_CHARPOS (*it
);
5581 /* Append the overlay string STRING of overlay OVERLAY to vector
5582 `entries' which has size `size' and currently contains `n'
5583 elements. AFTER_P non-zero means STRING is an after-string of
5585 #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \
5588 Lisp_Object priority; \
5592 struct overlay_entry *old = entries; \
5593 SAFE_NALLOCA (entries, 2, size); \
5594 memcpy (entries, old, size * sizeof *entries); \
5598 entries[n].string = (STRING); \
5599 entries[n].overlay = (OVERLAY); \
5600 priority = Foverlay_get ((OVERLAY), Qpriority); \
5601 entries[n].priority = INTEGERP (priority) ? XINT (priority) : 0; \
5602 entries[n].after_string_p = (AFTER_P); \
5607 /* Process overlay before the overlay center. */
5608 for (ov
= current_buffer
->overlays_before
; ov
; ov
= ov
->next
)
5610 XSETMISC (overlay
, ov
);
5611 eassert (OVERLAYP (overlay
));
5612 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5613 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5618 /* Skip this overlay if it doesn't start or end at IT's current
5620 if (end
!= charpos
&& start
!= charpos
)
5623 /* Skip this overlay if it doesn't apply to IT->w. */
5624 window
= Foverlay_get (overlay
, Qwindow
);
5625 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5628 /* If the text ``under'' the overlay is invisible, both before-
5629 and after-strings from this overlay are visible; start and
5630 end position are indistinguishable. */
5631 invisible
= Foverlay_get (overlay
, Qinvisible
);
5632 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5634 /* If overlay has a non-empty before-string, record it. */
5635 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5636 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5638 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5640 /* If overlay has a non-empty after-string, record it. */
5641 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5642 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5644 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5647 /* Process overlays after the overlay center. */
5648 for (ov
= current_buffer
->overlays_after
; ov
; ov
= ov
->next
)
5650 XSETMISC (overlay
, ov
);
5651 eassert (OVERLAYP (overlay
));
5652 start
= OVERLAY_POSITION (OVERLAY_START (overlay
));
5653 end
= OVERLAY_POSITION (OVERLAY_END (overlay
));
5655 if (start
> charpos
)
5658 /* Skip this overlay if it doesn't start or end at IT's current
5660 if (end
!= charpos
&& start
!= charpos
)
5663 /* Skip this overlay if it doesn't apply to IT->w. */
5664 window
= Foverlay_get (overlay
, Qwindow
);
5665 if (WINDOWP (window
) && XWINDOW (window
) != it
->w
)
5668 /* If the text ``under'' the overlay is invisible, it has a zero
5669 dimension, and both before- and after-strings apply. */
5670 invisible
= Foverlay_get (overlay
, Qinvisible
);
5671 invis_p
= TEXT_PROP_MEANS_INVISIBLE (invisible
);
5673 /* If overlay has a non-empty before-string, record it. */
5674 if ((start
== charpos
|| (end
== charpos
&& invis_p
))
5675 && (str
= Foverlay_get (overlay
, Qbefore_string
), STRINGP (str
))
5677 RECORD_OVERLAY_STRING (overlay
, str
, 0);
5679 /* If overlay has a non-empty after-string, record it. */
5680 if ((end
== charpos
|| (start
== charpos
&& invis_p
))
5681 && (str
= Foverlay_get (overlay
, Qafter_string
), STRINGP (str
))
5683 RECORD_OVERLAY_STRING (overlay
, str
, 1);
5686 #undef RECORD_OVERLAY_STRING
5690 qsort (entries
, n
, sizeof *entries
, compare_overlay_entries
);
5692 /* Record number of overlay strings, and where we computed it. */
5693 it
->n_overlay_strings
= n
;
5694 it
->overlay_strings_charpos
= charpos
;
5696 /* IT->current.overlay_string_index is the number of overlay strings
5697 that have already been consumed by IT. Copy some of the
5698 remaining overlay strings to IT->overlay_strings. */
5700 j
= it
->current
.overlay_string_index
;
5701 while (i
< OVERLAY_STRING_CHUNK_SIZE
&& j
< n
)
5703 it
->overlay_strings
[i
] = entries
[j
].string
;
5704 it
->string_overlays
[i
++] = entries
[j
++].overlay
;
5712 /* Get the first chunk of overlay strings at IT's current buffer
5713 position, or at CHARPOS if that is > 0. Value is non-zero if at
5714 least one overlay string was found. */
5717 get_overlay_strings_1 (struct it
*it
, ptrdiff_t charpos
, int compute_stop_p
)
5719 /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to
5720 process. This fills IT->overlay_strings with strings, and sets
5721 IT->n_overlay_strings to the total number of strings to process.
5722 IT->pos.overlay_string_index has to be set temporarily to zero
5723 because load_overlay_strings needs this; it must be set to -1
5724 when no overlay strings are found because a zero value would
5725 indicate a position in the first overlay string. */
5726 it
->current
.overlay_string_index
= 0;
5727 load_overlay_strings (it
, charpos
);
5729 /* If we found overlay strings, set up IT to deliver display
5730 elements from the first one. Otherwise set up IT to deliver
5731 from current_buffer. */
5732 if (it
->n_overlay_strings
)
5734 /* Make sure we know settings in current_buffer, so that we can
5735 restore meaningful values when we're done with the overlay
5738 compute_stop_pos (it
);
5739 eassert (it
->face_id
>= 0);
5741 /* Save IT's settings. They are restored after all overlay
5742 strings have been processed. */
5743 eassert (!compute_stop_p
|| it
->sp
== 0);
5745 /* When called from handle_stop, there might be an empty display
5746 string loaded. In that case, don't bother saving it. But
5747 don't use this optimization with the bidi iterator, since we
5748 need the corresponding pop_it call to resync the bidi
5749 iterator's position with IT's position, after we are done
5750 with the overlay strings. (The corresponding call to pop_it
5751 in case of an empty display string is in
5752 next_overlay_string.) */
5754 && STRINGP (it
->string
) && !SCHARS (it
->string
)))
5757 /* Set up IT to deliver display elements from the first overlay
5759 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
5760 it
->string
= it
->overlay_strings
[0];
5761 it
->from_overlay
= Qnil
;
5762 it
->stop_charpos
= 0;
5763 eassert (STRINGP (it
->string
));
5764 it
->end_charpos
= SCHARS (it
->string
);
5766 it
->base_level_stop
= 0;
5767 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
5768 it
->method
= GET_FROM_STRING
;
5769 it
->from_disp_prop_p
= 0;
5771 /* Force paragraph direction to be that of the parent
5773 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
5774 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
5776 it
->paragraph_embedding
= L2R
;
5778 /* Set up the bidi iterator for this overlay string. */
5781 ptrdiff_t pos
= (charpos
> 0 ? charpos
: IT_CHARPOS (*it
));
5783 it
->bidi_it
.string
.lstring
= it
->string
;
5784 it
->bidi_it
.string
.s
= NULL
;
5785 it
->bidi_it
.string
.schars
= SCHARS (it
->string
);
5786 it
->bidi_it
.string
.bufpos
= pos
;
5787 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
5788 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
5789 it
->bidi_it
.w
= it
->w
;
5790 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
5795 it
->current
.overlay_string_index
= -1;
5800 get_overlay_strings (struct it
*it
, ptrdiff_t charpos
)
5803 it
->method
= GET_FROM_BUFFER
;
5805 (void) get_overlay_strings_1 (it
, charpos
, 1);
5809 /* Value is non-zero if we found at least one overlay string. */
5810 return STRINGP (it
->string
);
5815 /***********************************************************************
5816 Saving and restoring state
5817 ***********************************************************************/
5819 /* Save current settings of IT on IT->stack. Called, for example,
5820 before setting up IT for an overlay string, to be able to restore
5821 IT's settings to what they were after the overlay string has been
5822 processed. If POSITION is non-NULL, it is the position to save on
5823 the stack instead of IT->position. */
5826 push_it (struct it
*it
, struct text_pos
*position
)
5828 struct iterator_stack_entry
*p
;
5830 eassert (it
->sp
< IT_STACK_SIZE
);
5831 p
= it
->stack
+ it
->sp
;
5833 p
->stop_charpos
= it
->stop_charpos
;
5834 p
->prev_stop
= it
->prev_stop
;
5835 p
->base_level_stop
= it
->base_level_stop
;
5836 p
->cmp_it
= it
->cmp_it
;
5837 eassert (it
->face_id
>= 0);
5838 p
->face_id
= it
->face_id
;
5839 p
->string
= it
->string
;
5840 p
->method
= it
->method
;
5841 p
->from_overlay
= it
->from_overlay
;
5844 case GET_FROM_IMAGE
:
5845 p
->u
.image
.object
= it
->object
;
5846 p
->u
.image
.image_id
= it
->image_id
;
5847 p
->u
.image
.slice
= it
->slice
;
5849 case GET_FROM_STRETCH
:
5850 p
->u
.stretch
.object
= it
->object
;
5853 p
->position
= position
? *position
: it
->position
;
5854 p
->current
= it
->current
;
5855 p
->end_charpos
= it
->end_charpos
;
5856 p
->string_nchars
= it
->string_nchars
;
5858 p
->multibyte_p
= it
->multibyte_p
;
5859 p
->avoid_cursor_p
= it
->avoid_cursor_p
;
5860 p
->space_width
= it
->space_width
;
5861 p
->font_height
= it
->font_height
;
5862 p
->voffset
= it
->voffset
;
5863 p
->string_from_display_prop_p
= it
->string_from_display_prop_p
;
5864 p
->string_from_prefix_prop_p
= it
->string_from_prefix_prop_p
;
5865 p
->display_ellipsis_p
= 0;
5866 p
->line_wrap
= it
->line_wrap
;
5867 p
->bidi_p
= it
->bidi_p
;
5868 p
->paragraph_embedding
= it
->paragraph_embedding
;
5869 p
->from_disp_prop_p
= it
->from_disp_prop_p
;
5872 /* Save the state of the bidi iterator as well. */
5874 bidi_push_it (&it
->bidi_it
);
5878 iterate_out_of_display_property (struct it
*it
)
5880 int buffer_p
= !STRINGP (it
->string
);
5881 ptrdiff_t eob
= (buffer_p
? ZV
: it
->end_charpos
);
5882 ptrdiff_t bob
= (buffer_p
? BEGV
: 0);
5884 eassert (eob
>= CHARPOS (it
->position
) && CHARPOS (it
->position
) >= bob
);
5886 /* Maybe initialize paragraph direction. If we are at the beginning
5887 of a new paragraph, next_element_from_buffer may not have a
5888 chance to do that. */
5889 if (it
->bidi_it
.first_elt
&& it
->bidi_it
.charpos
< eob
)
5890 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
5891 /* prev_stop can be zero, so check against BEGV as well. */
5892 while (it
->bidi_it
.charpos
>= bob
5893 && it
->prev_stop
<= it
->bidi_it
.charpos
5894 && it
->bidi_it
.charpos
< CHARPOS (it
->position
)
5895 && it
->bidi_it
.charpos
< eob
)
5896 bidi_move_to_visually_next (&it
->bidi_it
);
5897 /* Record the stop_pos we just crossed, for when we cross it
5899 if (it
->bidi_it
.charpos
> CHARPOS (it
->position
))
5900 it
->prev_stop
= CHARPOS (it
->position
);
5901 /* If we ended up not where pop_it put us, resync IT's
5902 positional members with the bidi iterator. */
5903 if (it
->bidi_it
.charpos
!= CHARPOS (it
->position
))
5904 SET_TEXT_POS (it
->position
, it
->bidi_it
.charpos
, it
->bidi_it
.bytepos
);
5906 it
->current
.pos
= it
->position
;
5908 it
->current
.string_pos
= it
->position
;
5911 /* Restore IT's settings from IT->stack. Called, for example, when no
5912 more overlay strings must be processed, and we return to delivering
5913 display elements from a buffer, or when the end of a string from a
5914 `display' property is reached and we return to delivering display
5915 elements from an overlay string, or from a buffer. */
5918 pop_it (struct it
*it
)
5920 struct iterator_stack_entry
*p
;
5921 int from_display_prop
= it
->from_disp_prop_p
;
5923 eassert (it
->sp
> 0);
5925 p
= it
->stack
+ it
->sp
;
5926 it
->stop_charpos
= p
->stop_charpos
;
5927 it
->prev_stop
= p
->prev_stop
;
5928 it
->base_level_stop
= p
->base_level_stop
;
5929 it
->cmp_it
= p
->cmp_it
;
5930 it
->face_id
= p
->face_id
;
5931 it
->current
= p
->current
;
5932 it
->position
= p
->position
;
5933 it
->string
= p
->string
;
5934 it
->from_overlay
= p
->from_overlay
;
5935 if (NILP (it
->string
))
5936 SET_TEXT_POS (it
->current
.string_pos
, -1, -1);
5937 it
->method
= p
->method
;
5940 case GET_FROM_IMAGE
:
5941 it
->image_id
= p
->u
.image
.image_id
;
5942 it
->object
= p
->u
.image
.object
;
5943 it
->slice
= p
->u
.image
.slice
;
5945 case GET_FROM_STRETCH
:
5946 it
->object
= p
->u
.stretch
.object
;
5948 case GET_FROM_BUFFER
:
5949 it
->object
= it
->w
->contents
;
5951 case GET_FROM_STRING
:
5952 it
->object
= it
->string
;
5954 case GET_FROM_DISPLAY_VECTOR
:
5956 it
->method
= GET_FROM_C_STRING
;
5957 else if (STRINGP (it
->string
))
5958 it
->method
= GET_FROM_STRING
;
5961 it
->method
= GET_FROM_BUFFER
;
5962 it
->object
= it
->w
->contents
;
5965 it
->end_charpos
= p
->end_charpos
;
5966 it
->string_nchars
= p
->string_nchars
;
5968 it
->multibyte_p
= p
->multibyte_p
;
5969 it
->avoid_cursor_p
= p
->avoid_cursor_p
;
5970 it
->space_width
= p
->space_width
;
5971 it
->font_height
= p
->font_height
;
5972 it
->voffset
= p
->voffset
;
5973 it
->string_from_display_prop_p
= p
->string_from_display_prop_p
;
5974 it
->string_from_prefix_prop_p
= p
->string_from_prefix_prop_p
;
5975 it
->line_wrap
= p
->line_wrap
;
5976 it
->bidi_p
= p
->bidi_p
;
5977 it
->paragraph_embedding
= p
->paragraph_embedding
;
5978 it
->from_disp_prop_p
= p
->from_disp_prop_p
;
5981 bidi_pop_it (&it
->bidi_it
);
5982 /* Bidi-iterate until we get out of the portion of text, if any,
5983 covered by a `display' text property or by an overlay with
5984 `display' property. (We cannot just jump there, because the
5985 internal coherency of the bidi iterator state can not be
5986 preserved across such jumps.) We also must determine the
5987 paragraph base direction if the overlay we just processed is
5988 at the beginning of a new paragraph. */
5989 if (from_display_prop
5990 && (it
->method
== GET_FROM_BUFFER
|| it
->method
== GET_FROM_STRING
))
5991 iterate_out_of_display_property (it
);
5993 eassert ((BUFFERP (it
->object
)
5994 && IT_CHARPOS (*it
) == it
->bidi_it
.charpos
5995 && IT_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5996 || (STRINGP (it
->object
)
5997 && IT_STRING_CHARPOS (*it
) == it
->bidi_it
.charpos
5998 && IT_STRING_BYTEPOS (*it
) == it
->bidi_it
.bytepos
)
5999 || (CONSP (it
->object
) && it
->method
== GET_FROM_STRETCH
));
6005 /***********************************************************************
6007 ***********************************************************************/
6009 /* Set IT's current position to the previous line start. */
6012 back_to_previous_line_start (struct it
*it
)
6014 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
6017 IT_CHARPOS (*it
) = find_newline_no_quit (cp
, bp
, -1, &IT_BYTEPOS (*it
));
6021 /* Move IT to the next line start.
6023 Value is non-zero if a newline was found. Set *SKIPPED_P to 1 if
6024 we skipped over part of the text (as opposed to moving the iterator
6025 continuously over the text). Otherwise, don't change the value
6028 If BIDI_IT_PREV is non-NULL, store into it the state of the bidi
6029 iterator on the newline, if it was found.
6031 Newlines may come from buffer text, overlay strings, or strings
6032 displayed via the `display' property. That's the reason we can't
6033 simply use find_newline_no_quit.
6035 Note that this function may not skip over invisible text that is so
6036 because of text properties and immediately follows a newline. If
6037 it would, function reseat_at_next_visible_line_start, when called
6038 from set_iterator_to_next, would effectively make invisible
6039 characters following a newline part of the wrong glyph row, which
6040 leads to wrong cursor motion. */
6043 forward_to_next_line_start (struct it
*it
, int *skipped_p
,
6044 struct bidi_it
*bidi_it_prev
)
6046 ptrdiff_t old_selective
;
6047 int newline_found_p
, n
;
6048 const int MAX_NEWLINE_DISTANCE
= 500;
6050 /* If already on a newline, just consume it to avoid unintended
6051 skipping over invisible text below. */
6052 if (it
->what
== IT_CHARACTER
6054 && CHARPOS (it
->position
) == IT_CHARPOS (*it
))
6056 if (it
->bidi_p
&& bidi_it_prev
)
6057 *bidi_it_prev
= it
->bidi_it
;
6058 set_iterator_to_next (it
, 0);
6063 /* Don't handle selective display in the following. It's (a)
6064 unnecessary because it's done by the caller, and (b) leads to an
6065 infinite recursion because next_element_from_ellipsis indirectly
6066 calls this function. */
6067 old_selective
= it
->selective
;
6070 /* Scan for a newline within MAX_NEWLINE_DISTANCE display elements
6071 from buffer text. */
6072 for (n
= newline_found_p
= 0;
6073 !newline_found_p
&& n
< MAX_NEWLINE_DISTANCE
;
6074 n
+= STRINGP (it
->string
) ? 0 : 1)
6076 if (!get_next_display_element (it
))
6078 newline_found_p
= it
->what
== IT_CHARACTER
&& it
->c
== '\n';
6079 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6080 *bidi_it_prev
= it
->bidi_it
;
6081 set_iterator_to_next (it
, 0);
6084 /* If we didn't find a newline near enough, see if we can use a
6086 if (!newline_found_p
)
6088 ptrdiff_t bytepos
, start
= IT_CHARPOS (*it
);
6089 ptrdiff_t limit
= find_newline_no_quit (start
, IT_BYTEPOS (*it
),
6093 eassert (!STRINGP (it
->string
));
6095 /* If there isn't any `display' property in sight, and no
6096 overlays, we can just use the position of the newline in
6098 if (it
->stop_charpos
>= limit
6099 || ((pos
= Fnext_single_property_change (make_number (start
),
6101 make_number (limit
)),
6103 && next_overlay_change (start
) == ZV
))
6107 IT_CHARPOS (*it
) = limit
;
6108 IT_BYTEPOS (*it
) = bytepos
;
6112 struct bidi_it bprev
;
6114 /* Help bidi.c avoid expensive searches for display
6115 properties and overlays, by telling it that there are
6116 none up to `limit'. */
6117 if (it
->bidi_it
.disp_pos
< limit
)
6119 it
->bidi_it
.disp_pos
= limit
;
6120 it
->bidi_it
.disp_prop
= 0;
6123 bprev
= it
->bidi_it
;
6124 bidi_move_to_visually_next (&it
->bidi_it
);
6125 } while (it
->bidi_it
.charpos
!= limit
);
6126 IT_CHARPOS (*it
) = limit
;
6127 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6129 *bidi_it_prev
= bprev
;
6131 *skipped_p
= newline_found_p
= 1;
6135 while (get_next_display_element (it
)
6136 && !newline_found_p
)
6138 newline_found_p
= ITERATOR_AT_END_OF_LINE_P (it
);
6139 if (newline_found_p
&& it
->bidi_p
&& bidi_it_prev
)
6140 *bidi_it_prev
= it
->bidi_it
;
6141 set_iterator_to_next (it
, 0);
6146 it
->selective
= old_selective
;
6147 return newline_found_p
;
6151 /* Set IT's current position to the previous visible line start. Skip
6152 invisible text that is so either due to text properties or due to
6153 selective display. Caution: this does not change IT->current_x and
6157 back_to_previous_visible_line_start (struct it
*it
)
6159 while (IT_CHARPOS (*it
) > BEGV
)
6161 back_to_previous_line_start (it
);
6163 if (IT_CHARPOS (*it
) <= BEGV
)
6166 /* If selective > 0, then lines indented more than its value are
6168 if (it
->selective
> 0
6169 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6173 /* Check the newline before point for invisibility. */
6176 prop
= Fget_char_property (make_number (IT_CHARPOS (*it
) - 1),
6177 Qinvisible
, it
->window
);
6178 if (TEXT_PROP_MEANS_INVISIBLE (prop
))
6182 if (IT_CHARPOS (*it
) <= BEGV
)
6187 void *it2data
= NULL
;
6190 Lisp_Object val
, overlay
;
6192 SAVE_IT (it2
, *it
, it2data
);
6194 /* If newline is part of a composition, continue from start of composition */
6195 if (find_composition (IT_CHARPOS (*it
), -1, &beg
, &end
, &val
, Qnil
)
6196 && beg
< IT_CHARPOS (*it
))
6199 /* If newline is replaced by a display property, find start of overlay
6200 or interval and continue search from that point. */
6201 pos
= --IT_CHARPOS (it2
);
6204 bidi_unshelve_cache (NULL
, 0);
6205 it2
.string_from_display_prop_p
= 0;
6206 it2
.from_disp_prop_p
= 0;
6207 if (handle_display_prop (&it2
) == HANDLED_RETURN
6208 && !NILP (val
= get_char_property_and_overlay
6209 (make_number (pos
), Qdisplay
, Qnil
, &overlay
))
6210 && (OVERLAYP (overlay
)
6211 ? (beg
= OVERLAY_POSITION (OVERLAY_START (overlay
)))
6212 : get_property_and_range (pos
, Qdisplay
, &val
, &beg
, &end
, Qnil
)))
6214 RESTORE_IT (it
, it
, it2data
);
6218 /* Newline is not replaced by anything -- so we are done. */
6219 RESTORE_IT (it
, it
, it2data
);
6225 IT_CHARPOS (*it
) = beg
;
6226 IT_BYTEPOS (*it
) = buf_charpos_to_bytepos (current_buffer
, beg
);
6230 it
->continuation_lines_width
= 0;
6232 eassert (IT_CHARPOS (*it
) >= BEGV
);
6233 eassert (IT_CHARPOS (*it
) == BEGV
6234 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6239 /* Reseat iterator IT at the previous visible line start. Skip
6240 invisible text that is so either due to text properties or due to
6241 selective display. At the end, update IT's overlay information,
6242 face information etc. */
6245 reseat_at_previous_visible_line_start (struct it
*it
)
6247 back_to_previous_visible_line_start (it
);
6248 reseat (it
, it
->current
.pos
, 1);
6253 /* Reseat iterator IT on the next visible line start in the current
6254 buffer. ON_NEWLINE_P non-zero means position IT on the newline
6255 preceding the line start. Skip over invisible text that is so
6256 because of selective display. Compute faces, overlays etc at the
6257 new position. Note that this function does not skip over text that
6258 is invisible because of text properties. */
6261 reseat_at_next_visible_line_start (struct it
*it
, int on_newline_p
)
6263 int newline_found_p
, skipped_p
= 0;
6264 struct bidi_it bidi_it_prev
;
6266 newline_found_p
= forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6268 /* Skip over lines that are invisible because they are indented
6269 more than the value of IT->selective. */
6270 if (it
->selective
> 0)
6271 while (IT_CHARPOS (*it
) < ZV
6272 && indented_beyond_p (IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
6275 eassert (IT_BYTEPOS (*it
) == BEGV
6276 || FETCH_BYTE (IT_BYTEPOS (*it
) - 1) == '\n');
6278 forward_to_next_line_start (it
, &skipped_p
, &bidi_it_prev
);
6281 /* Position on the newline if that's what's requested. */
6282 if (on_newline_p
&& newline_found_p
)
6284 if (STRINGP (it
->string
))
6286 if (IT_STRING_CHARPOS (*it
) > 0)
6290 --IT_STRING_CHARPOS (*it
);
6291 --IT_STRING_BYTEPOS (*it
);
6295 /* We need to restore the bidi iterator to the state
6296 it had on the newline, and resync the IT's
6297 position with that. */
6298 it
->bidi_it
= bidi_it_prev
;
6299 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6300 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6304 else if (IT_CHARPOS (*it
) > BEGV
)
6313 /* We need to restore the bidi iterator to the state it
6314 had on the newline and resync IT with that. */
6315 it
->bidi_it
= bidi_it_prev
;
6316 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
6317 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
6319 reseat (it
, it
->current
.pos
, 0);
6323 reseat (it
, it
->current
.pos
, 0);
6330 /***********************************************************************
6331 Changing an iterator's position
6332 ***********************************************************************/
6334 /* Change IT's current position to POS in current_buffer. If FORCE_P
6335 is non-zero, always check for text properties at the new position.
6336 Otherwise, text properties are only looked up if POS >=
6337 IT->check_charpos of a property. */
6340 reseat (struct it
*it
, struct text_pos pos
, int force_p
)
6342 ptrdiff_t original_pos
= IT_CHARPOS (*it
);
6344 reseat_1 (it
, pos
, 0);
6346 /* Determine where to check text properties. Avoid doing it
6347 where possible because text property lookup is very expensive. */
6349 || CHARPOS (pos
) > it
->stop_charpos
6350 || CHARPOS (pos
) < original_pos
)
6354 /* For bidi iteration, we need to prime prev_stop and
6355 base_level_stop with our best estimations. */
6356 /* Implementation note: Of course, POS is not necessarily a
6357 stop position, so assigning prev_pos to it is a lie; we
6358 should have called compute_stop_backwards. However, if
6359 the current buffer does not include any R2L characters,
6360 that call would be a waste of cycles, because the
6361 iterator will never move back, and thus never cross this
6362 "fake" stop position. So we delay that backward search
6363 until the time we really need it, in next_element_from_buffer. */
6364 if (CHARPOS (pos
) != it
->prev_stop
)
6365 it
->prev_stop
= CHARPOS (pos
);
6366 if (CHARPOS (pos
) < it
->base_level_stop
)
6367 it
->base_level_stop
= 0; /* meaning it's unknown */
6373 it
->prev_stop
= it
->base_level_stop
= 0;
6382 /* Change IT's buffer position to POS. SET_STOP_P non-zero means set
6383 IT->stop_pos to POS, also. */
6386 reseat_1 (struct it
*it
, struct text_pos pos
, int set_stop_p
)
6388 /* Don't call this function when scanning a C string. */
6389 eassert (it
->s
== NULL
);
6391 /* POS must be a reasonable value. */
6392 eassert (CHARPOS (pos
) >= BEGV
&& CHARPOS (pos
) <= ZV
);
6394 it
->current
.pos
= it
->position
= pos
;
6395 it
->end_charpos
= ZV
;
6397 it
->current
.dpvec_index
= -1;
6398 it
->current
.overlay_string_index
= -1;
6399 IT_STRING_CHARPOS (*it
) = -1;
6400 IT_STRING_BYTEPOS (*it
) = -1;
6402 it
->method
= GET_FROM_BUFFER
;
6403 it
->object
= it
->w
->contents
;
6404 it
->area
= TEXT_AREA
;
6405 it
->multibyte_p
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
6407 it
->string_from_display_prop_p
= 0;
6408 it
->string_from_prefix_prop_p
= 0;
6410 it
->from_disp_prop_p
= 0;
6411 it
->face_before_selective_p
= 0;
6414 bidi_init_it (IT_CHARPOS (*it
), IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6416 bidi_unshelve_cache (NULL
, 0);
6417 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6418 it
->bidi_it
.string
.s
= NULL
;
6419 it
->bidi_it
.string
.lstring
= Qnil
;
6420 it
->bidi_it
.string
.bufpos
= 0;
6421 it
->bidi_it
.string
.unibyte
= 0;
6422 it
->bidi_it
.w
= it
->w
;
6427 it
->stop_charpos
= CHARPOS (pos
);
6428 it
->base_level_stop
= CHARPOS (pos
);
6430 /* This make the information stored in it->cmp_it invalidate. */
6435 /* Set up IT for displaying a string, starting at CHARPOS in window W.
6436 If S is non-null, it is a C string to iterate over. Otherwise,
6437 STRING gives a Lisp string to iterate over.
6439 If PRECISION > 0, don't return more then PRECISION number of
6440 characters from the string.
6442 If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH
6443 characters have been returned. FIELD_WIDTH < 0 means an infinite
6446 MULTIBYTE = 0 means disable processing of multibyte characters,
6447 MULTIBYTE > 0 means enable it,
6448 MULTIBYTE < 0 means use IT->multibyte_p.
6450 IT must be initialized via a prior call to init_iterator before
6451 calling this function. */
6454 reseat_to_string (struct it
*it
, const char *s
, Lisp_Object string
,
6455 ptrdiff_t charpos
, ptrdiff_t precision
, int field_width
,
6458 /* No region in strings. */
6459 it
->region_beg_charpos
= it
->region_end_charpos
= -1;
6461 /* No text property checks performed by default, but see below. */
6462 it
->stop_charpos
= -1;
6464 /* Set iterator position and end position. */
6465 memset (&it
->current
, 0, sizeof it
->current
);
6466 it
->current
.overlay_string_index
= -1;
6467 it
->current
.dpvec_index
= -1;
6468 eassert (charpos
>= 0);
6470 /* If STRING is specified, use its multibyteness, otherwise use the
6471 setting of MULTIBYTE, if specified. */
6473 it
->multibyte_p
= multibyte
> 0;
6475 /* Bidirectional reordering of strings is controlled by the default
6476 value of bidi-display-reordering. Don't try to reorder while
6477 loading loadup.el, as the necessary character property tables are
6478 not yet available. */
6481 && !NILP (BVAR (&buffer_defaults
, bidi_display_reordering
));
6485 eassert (STRINGP (string
));
6486 it
->string
= string
;
6488 it
->end_charpos
= it
->string_nchars
= SCHARS (string
);
6489 it
->method
= GET_FROM_STRING
;
6490 it
->current
.string_pos
= string_pos (charpos
, string
);
6494 it
->bidi_it
.string
.lstring
= string
;
6495 it
->bidi_it
.string
.s
= NULL
;
6496 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6497 it
->bidi_it
.string
.bufpos
= 0;
6498 it
->bidi_it
.string
.from_disp_str
= 0;
6499 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6500 it
->bidi_it
.w
= it
->w
;
6501 bidi_init_it (charpos
, IT_STRING_BYTEPOS (*it
),
6502 FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
6507 it
->s
= (const unsigned char *) s
;
6510 /* Note that we use IT->current.pos, not it->current.string_pos,
6511 for displaying C strings. */
6512 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = -1;
6513 if (it
->multibyte_p
)
6515 it
->current
.pos
= c_string_pos (charpos
, s
, 1);
6516 it
->end_charpos
= it
->string_nchars
= number_of_chars (s
, 1);
6520 IT_CHARPOS (*it
) = IT_BYTEPOS (*it
) = charpos
;
6521 it
->end_charpos
= it
->string_nchars
= strlen (s
);
6526 it
->bidi_it
.string
.lstring
= Qnil
;
6527 it
->bidi_it
.string
.s
= (const unsigned char *) s
;
6528 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6529 it
->bidi_it
.string
.bufpos
= 0;
6530 it
->bidi_it
.string
.from_disp_str
= 0;
6531 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
6532 it
->bidi_it
.w
= it
->w
;
6533 bidi_init_it (charpos
, IT_BYTEPOS (*it
), FRAME_WINDOW_P (it
->f
),
6536 it
->method
= GET_FROM_C_STRING
;
6539 /* PRECISION > 0 means don't return more than PRECISION characters
6541 if (precision
> 0 && it
->end_charpos
- charpos
> precision
)
6543 it
->end_charpos
= it
->string_nchars
= charpos
+ precision
;
6545 it
->bidi_it
.string
.schars
= it
->end_charpos
;
6548 /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH
6549 characters have been returned. FIELD_WIDTH == 0 means don't pad,
6550 FIELD_WIDTH < 0 means infinite field width. This is useful for
6551 padding with `-' at the end of a mode line. */
6552 if (field_width
< 0)
6553 field_width
= INFINITY
;
6554 /* Implementation note: We deliberately don't enlarge
6555 it->bidi_it.string.schars here to fit it->end_charpos, because
6556 the bidi iterator cannot produce characters out of thin air. */
6557 if (field_width
> it
->end_charpos
- charpos
)
6558 it
->end_charpos
= charpos
+ field_width
;
6560 /* Use the standard display table for displaying strings. */
6561 if (DISP_TABLE_P (Vstandard_display_table
))
6562 it
->dp
= XCHAR_TABLE (Vstandard_display_table
);
6564 it
->stop_charpos
= charpos
;
6565 it
->prev_stop
= charpos
;
6566 it
->base_level_stop
= 0;
6569 it
->bidi_it
.first_elt
= 1;
6570 it
->bidi_it
.paragraph_dir
= NEUTRAL_DIR
;
6571 it
->bidi_it
.disp_pos
= -1;
6573 if (s
== NULL
&& it
->multibyte_p
)
6575 ptrdiff_t endpos
= SCHARS (it
->string
);
6576 if (endpos
> it
->end_charpos
)
6577 endpos
= it
->end_charpos
;
6578 composition_compute_stop_pos (&it
->cmp_it
, charpos
, -1, endpos
,
6586 /***********************************************************************
6588 ***********************************************************************/
6590 /* Map enum it_method value to corresponding next_element_from_* function. */
6592 static int (* get_next_element
[NUM_IT_METHODS
]) (struct it
*it
) =
6594 next_element_from_buffer
,
6595 next_element_from_display_vector
,
6596 next_element_from_string
,
6597 next_element_from_c_string
,
6598 next_element_from_image
,
6599 next_element_from_stretch
6602 #define GET_NEXT_DISPLAY_ELEMENT(it) (*get_next_element[(it)->method]) (it)
6605 /* Return 1 iff a character at CHARPOS (and BYTEPOS) is composed
6606 (possibly with the following characters). */
6608 #define CHAR_COMPOSED_P(IT,CHARPOS,BYTEPOS,END_CHARPOS) \
6609 ((IT)->cmp_it.id >= 0 \
6610 || ((IT)->cmp_it.stop_pos == (CHARPOS) \
6611 && composition_reseat_it (&(IT)->cmp_it, CHARPOS, BYTEPOS, \
6612 END_CHARPOS, (IT)->w, \
6613 FACE_FROM_ID ((IT)->f, (IT)->face_id), \
6617 /* Lookup the char-table Vglyphless_char_display for character C (-1
6618 if we want information for no-font case), and return the display
6619 method symbol. By side-effect, update it->what and
6620 it->glyphless_method. This function is called from
6621 get_next_display_element for each character element, and from
6622 x_produce_glyphs when no suitable font was found. */
6625 lookup_glyphless_char_display (int c
, struct it
*it
)
6627 Lisp_Object glyphless_method
= Qnil
;
6629 if (CHAR_TABLE_P (Vglyphless_char_display
)
6630 && CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
)) >= 1)
6634 glyphless_method
= CHAR_TABLE_REF (Vglyphless_char_display
, c
);
6635 if (CONSP (glyphless_method
))
6636 glyphless_method
= FRAME_WINDOW_P (it
->f
)
6637 ? XCAR (glyphless_method
)
6638 : XCDR (glyphless_method
);
6641 glyphless_method
= XCHAR_TABLE (Vglyphless_char_display
)->extras
[0];
6645 if (NILP (glyphless_method
))
6648 /* The default is to display the character by a proper font. */
6650 /* The default for the no-font case is to display an empty box. */
6651 glyphless_method
= Qempty_box
;
6653 if (EQ (glyphless_method
, Qzero_width
))
6656 return glyphless_method
;
6657 /* This method can't be used for the no-font case. */
6658 glyphless_method
= Qempty_box
;
6660 if (EQ (glyphless_method
, Qthin_space
))
6661 it
->glyphless_method
= GLYPHLESS_DISPLAY_THIN_SPACE
;
6662 else if (EQ (glyphless_method
, Qempty_box
))
6663 it
->glyphless_method
= GLYPHLESS_DISPLAY_EMPTY_BOX
;
6664 else if (EQ (glyphless_method
, Qhex_code
))
6665 it
->glyphless_method
= GLYPHLESS_DISPLAY_HEX_CODE
;
6666 else if (STRINGP (glyphless_method
))
6667 it
->glyphless_method
= GLYPHLESS_DISPLAY_ACRONYM
;
6670 /* Invalid value. We use the default method. */
6671 glyphless_method
= Qnil
;
6674 it
->what
= IT_GLYPHLESS
;
6675 return glyphless_method
;
6678 /* Load IT's display element fields with information about the next
6679 display element from the current position of IT. Value is zero if
6680 end of buffer (or C string) is reached. */
6682 static struct frame
*last_escape_glyph_frame
= NULL
;
6683 static int last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
6684 static int last_escape_glyph_merged_face_id
= 0;
6686 struct frame
*last_glyphless_glyph_frame
= NULL
;
6687 int last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
6688 int last_glyphless_glyph_merged_face_id
= 0;
6691 get_next_display_element (struct it
*it
)
6693 /* Non-zero means that we found a display element. Zero means that
6694 we hit the end of what we iterate over. Performance note: the
6695 function pointer `method' used here turns out to be faster than
6696 using a sequence of if-statements. */
6700 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
6702 if (it
->what
== IT_CHARACTER
)
6704 /* UAX#9, L4: "A character is depicted by a mirrored glyph if
6705 and only if (a) the resolved directionality of that character
6707 /* FIXME: Do we need an exception for characters from display
6709 if (it
->bidi_p
&& it
->bidi_it
.type
== STRONG_R
)
6710 it
->c
= bidi_mirror_char (it
->c
);
6711 /* Map via display table or translate control characters.
6712 IT->c, IT->len etc. have been set to the next character by
6713 the function call above. If we have a display table, and it
6714 contains an entry for IT->c, translate it. Don't do this if
6715 IT->c itself comes from a display table, otherwise we could
6716 end up in an infinite recursion. (An alternative could be to
6717 count the recursion depth of this function and signal an
6718 error when a certain maximum depth is reached.) Is it worth
6720 if (success_p
&& it
->dpvec
== NULL
)
6723 struct charset
*unibyte
= CHARSET_FROM_ID (charset_unibyte
);
6724 int nonascii_space_p
= 0;
6725 int nonascii_hyphen_p
= 0;
6726 int c
= it
->c
; /* This is the character to display. */
6728 if (! it
->multibyte_p
&& ! ASCII_CHAR_P (c
))
6730 eassert (SINGLE_BYTE_CHAR_P (c
));
6731 if (unibyte_display_via_language_environment
)
6733 c
= DECODE_CHAR (unibyte
, c
);
6735 c
= BYTE8_TO_CHAR (it
->c
);
6738 c
= BYTE8_TO_CHAR (it
->c
);
6742 && (dv
= DISP_CHAR_VECTOR (it
->dp
, c
),
6745 struct Lisp_Vector
*v
= XVECTOR (dv
);
6747 /* Return the first character from the display table
6748 entry, if not empty. If empty, don't display the
6749 current character. */
6752 it
->dpvec_char_len
= it
->len
;
6753 it
->dpvec
= v
->contents
;
6754 it
->dpend
= v
->contents
+ v
->header
.size
;
6755 it
->current
.dpvec_index
= 0;
6756 it
->dpvec_face_id
= -1;
6757 it
->saved_face_id
= it
->face_id
;
6758 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6763 set_iterator_to_next (it
, 0);
6768 if (! NILP (lookup_glyphless_char_display (c
, it
)))
6770 if (it
->what
== IT_GLYPHLESS
)
6772 /* Don't display this character. */
6773 set_iterator_to_next (it
, 0);
6777 /* If `nobreak-char-display' is non-nil, we display
6778 non-ASCII spaces and hyphens specially. */
6779 if (! ASCII_CHAR_P (c
) && ! NILP (Vnobreak_char_display
))
6782 nonascii_space_p
= 1;
6783 else if (c
== 0xAD || c
== 0x2010 || c
== 0x2011)
6784 nonascii_hyphen_p
= 1;
6787 /* Translate control characters into `\003' or `^C' form.
6788 Control characters coming from a display table entry are
6789 currently not translated because we use IT->dpvec to hold
6790 the translation. This could easily be changed but I
6791 don't believe that it is worth doing.
6793 The characters handled by `nobreak-char-display' must be
6796 Non-printable characters and raw-byte characters are also
6797 translated to octal form. */
6798 if (((c
< ' ' || c
== 127) /* ASCII control chars */
6799 ? (it
->area
!= TEXT_AREA
6800 /* In mode line, treat \n, \t like other crl chars. */
6803 && (it
->glyph_row
->mode_line_p
|| it
->avoid_cursor_p
))
6804 || (c
!= '\n' && c
!= '\t'))
6806 || nonascii_hyphen_p
6808 || ! CHAR_PRINTABLE_P (c
))))
6810 /* C is a control character, non-ASCII space/hyphen,
6811 raw-byte, or a non-printable character which must be
6812 displayed either as '\003' or as `^C' where the '\\'
6813 and '^' can be defined in the display table. Fill
6814 IT->ctl_chars with glyphs for what we have to
6815 display. Then, set IT->dpvec to these glyphs. */
6822 /* Handle control characters with ^. */
6824 if (ASCII_CHAR_P (c
) && it
->ctl_arrow_p
)
6828 g
= '^'; /* default glyph for Control */
6829 /* Set IT->ctl_chars[0] to the glyph for `^'. */
6831 && (gc
= DISP_CTRL_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6833 g
= GLYPH_CODE_CHAR (gc
);
6834 lface_id
= GLYPH_CODE_FACE (gc
);
6838 face_id
= merge_faces (it
->f
, Qt
, lface_id
, it
->face_id
);
6840 else if (it
->f
== last_escape_glyph_frame
6841 && it
->face_id
== last_escape_glyph_face_id
)
6843 face_id
= last_escape_glyph_merged_face_id
;
6847 /* Merge the escape-glyph face into the current face. */
6848 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6850 last_escape_glyph_frame
= it
->f
;
6851 last_escape_glyph_face_id
= it
->face_id
;
6852 last_escape_glyph_merged_face_id
= face_id
;
6855 XSETINT (it
->ctl_chars
[0], g
);
6856 XSETINT (it
->ctl_chars
[1], c
^ 0100);
6858 goto display_control
;
6861 /* Handle non-ascii space in the mode where it only gets
6864 if (nonascii_space_p
&& EQ (Vnobreak_char_display
, Qt
))
6866 /* Merge `nobreak-space' into the current face. */
6867 face_id
= merge_faces (it
->f
, Qnobreak_space
, 0,
6869 XSETINT (it
->ctl_chars
[0], ' ');
6871 goto display_control
;
6874 /* Handle sequences that start with the "escape glyph". */
6876 /* the default escape glyph is \. */
6877 escape_glyph
= '\\';
6880 && (gc
= DISP_ESCAPE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
6882 escape_glyph
= GLYPH_CODE_CHAR (gc
);
6883 lface_id
= GLYPH_CODE_FACE (gc
);
6887 /* The display table specified a face.
6888 Merge it into face_id and also into escape_glyph. */
6889 face_id
= merge_faces (it
->f
, Qt
, lface_id
,
6892 else if (it
->f
== last_escape_glyph_frame
6893 && it
->face_id
== last_escape_glyph_face_id
)
6895 face_id
= last_escape_glyph_merged_face_id
;
6899 /* Merge the escape-glyph face into the current face. */
6900 face_id
= merge_faces (it
->f
, Qescape_glyph
, 0,
6902 last_escape_glyph_frame
= it
->f
;
6903 last_escape_glyph_face_id
= it
->face_id
;
6904 last_escape_glyph_merged_face_id
= face_id
;
6907 /* Draw non-ASCII hyphen with just highlighting: */
6909 if (nonascii_hyphen_p
&& EQ (Vnobreak_char_display
, Qt
))
6911 XSETINT (it
->ctl_chars
[0], '-');
6913 goto display_control
;
6916 /* Draw non-ASCII space/hyphen with escape glyph: */
6918 if (nonascii_space_p
|| nonascii_hyphen_p
)
6920 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6921 XSETINT (it
->ctl_chars
[1], nonascii_space_p
? ' ' : '-');
6923 goto display_control
;
6930 if (CHAR_BYTE8_P (c
))
6931 /* Display \200 instead of \17777600. */
6932 c
= CHAR_TO_BYTE8 (c
);
6933 len
= sprintf (str
, "%03o", c
);
6935 XSETINT (it
->ctl_chars
[0], escape_glyph
);
6936 for (i
= 0; i
< len
; i
++)
6937 XSETINT (it
->ctl_chars
[i
+ 1], str
[i
]);
6942 /* Set up IT->dpvec and return first character from it. */
6943 it
->dpvec_char_len
= it
->len
;
6944 it
->dpvec
= it
->ctl_chars
;
6945 it
->dpend
= it
->dpvec
+ ctl_len
;
6946 it
->current
.dpvec_index
= 0;
6947 it
->dpvec_face_id
= face_id
;
6948 it
->saved_face_id
= it
->face_id
;
6949 it
->method
= GET_FROM_DISPLAY_VECTOR
;
6953 it
->char_to_display
= c
;
6957 it
->char_to_display
= it
->c
;
6961 /* Adjust face id for a multibyte character. There are no multibyte
6962 character in unibyte text. */
6963 if ((it
->what
== IT_CHARACTER
|| it
->what
== IT_COMPOSITION
)
6966 && FRAME_WINDOW_P (it
->f
))
6968 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
6970 if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
>= 0)
6972 /* Automatic composition with glyph-string. */
6973 Lisp_Object gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
6975 it
->face_id
= face_for_font (it
->f
, LGSTRING_FONT (gstring
), face
);
6979 ptrdiff_t pos
= (it
->s
? -1
6980 : STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
6981 : IT_CHARPOS (*it
));
6984 if (it
->what
== IT_CHARACTER
)
6985 c
= it
->char_to_display
;
6988 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
6992 for (i
= 0; i
< cmp
->glyph_len
; i
++)
6993 /* TAB in a composition means display glyphs with
6994 padding space on the left or right. */
6995 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
6998 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, c
, pos
, it
->string
);
7003 /* Is this character the last one of a run of characters with
7004 box? If yes, set IT->end_of_box_run_p to 1. */
7008 if (it
->method
== GET_FROM_STRING
&& it
->sp
)
7010 int face_id
= underlying_face_id (it
);
7011 struct face
*face
= FACE_FROM_ID (it
->f
, face_id
);
7015 if (face
->box
== FACE_NO_BOX
)
7017 /* If the box comes from face properties in a
7018 display string, check faces in that string. */
7019 int string_face_id
= face_after_it_pos (it
);
7020 it
->end_of_box_run_p
7021 = (FACE_FROM_ID (it
->f
, string_face_id
)->box
7024 /* Otherwise, the box comes from the underlying face.
7025 If this is the last string character displayed, check
7026 the next buffer location. */
7027 else if ((IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
) - 1)
7028 && (it
->current
.overlay_string_index
7029 == it
->n_overlay_strings
- 1))
7033 struct text_pos pos
= it
->current
.pos
;
7034 INC_TEXT_POS (pos
, it
->multibyte_p
);
7036 next_face_id
= face_at_buffer_position
7037 (it
->w
, CHARPOS (pos
), it
->region_beg_charpos
,
7038 it
->region_end_charpos
, &ignore
,
7039 (IT_CHARPOS (*it
) + TEXT_PROP_DISTANCE_LIMIT
), 0,
7041 it
->end_of_box_run_p
7042 = (FACE_FROM_ID (it
->f
, next_face_id
)->box
7049 int face_id
= face_after_it_pos (it
);
7050 it
->end_of_box_run_p
7051 = (face_id
!= it
->face_id
7052 && FACE_FROM_ID (it
->f
, face_id
)->box
== FACE_NO_BOX
);
7055 /* If we reached the end of the object we've been iterating (e.g., a
7056 display string or an overlay string), and there's something on
7057 IT->stack, proceed with what's on the stack. It doesn't make
7058 sense to return zero if there's unprocessed stuff on the stack,
7059 because otherwise that stuff will never be displayed. */
7060 if (!success_p
&& it
->sp
> 0)
7062 set_iterator_to_next (it
, 0);
7063 success_p
= get_next_display_element (it
);
7066 /* Value is 0 if end of buffer or string reached. */
7071 /* Move IT to the next display element.
7073 RESEAT_P non-zero means if called on a newline in buffer text,
7074 skip to the next visible line start.
7076 Functions get_next_display_element and set_iterator_to_next are
7077 separate because I find this arrangement easier to handle than a
7078 get_next_display_element function that also increments IT's
7079 position. The way it is we can first look at an iterator's current
7080 display element, decide whether it fits on a line, and if it does,
7081 increment the iterator position. The other way around we probably
7082 would either need a flag indicating whether the iterator has to be
7083 incremented the next time, or we would have to implement a
7084 decrement position function which would not be easy to write. */
7087 set_iterator_to_next (struct it
*it
, int reseat_p
)
7089 /* Reset flags indicating start and end of a sequence of characters
7090 with box. Reset them at the start of this function because
7091 moving the iterator to a new position might set them. */
7092 it
->start_of_box_run_p
= it
->end_of_box_run_p
= 0;
7096 case GET_FROM_BUFFER
:
7097 /* The current display element of IT is a character from
7098 current_buffer. Advance in the buffer, and maybe skip over
7099 invisible lines that are so because of selective display. */
7100 if (ITERATOR_AT_END_OF_LINE_P (it
) && reseat_p
)
7101 reseat_at_next_visible_line_start (it
, 0);
7102 else if (it
->cmp_it
.id
>= 0)
7104 /* We are currently getting glyphs from a composition. */
7109 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7110 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7111 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7113 it
->cmp_it
.from
= it
->cmp_it
.to
;
7118 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7120 it
->end_charpos
, Qnil
);
7123 else if (! it
->cmp_it
.reversed_p
)
7125 /* Composition created while scanning forward. */
7126 /* Update IT's char/byte positions to point to the first
7127 character of the next grapheme cluster, or to the
7128 character visually after the current composition. */
7129 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7130 bidi_move_to_visually_next (&it
->bidi_it
);
7131 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7132 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7134 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7136 /* Proceed to the next grapheme cluster. */
7137 it
->cmp_it
.from
= it
->cmp_it
.to
;
7141 /* No more grapheme clusters in this composition.
7142 Find the next stop position. */
7143 ptrdiff_t stop
= it
->end_charpos
;
7144 if (it
->bidi_it
.scan_dir
< 0)
7145 /* Now we are scanning backward and don't know
7148 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7149 IT_BYTEPOS (*it
), stop
, Qnil
);
7154 /* Composition created while scanning backward. */
7155 /* Update IT's char/byte positions to point to the last
7156 character of the previous grapheme cluster, or the
7157 character visually after the current composition. */
7158 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7159 bidi_move_to_visually_next (&it
->bidi_it
);
7160 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7161 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7162 if (it
->cmp_it
.from
> 0)
7164 /* Proceed to the previous grapheme cluster. */
7165 it
->cmp_it
.to
= it
->cmp_it
.from
;
7169 /* No more grapheme clusters in this composition.
7170 Find the next stop position. */
7171 ptrdiff_t stop
= it
->end_charpos
;
7172 if (it
->bidi_it
.scan_dir
< 0)
7173 /* Now we are scanning backward and don't know
7176 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7177 IT_BYTEPOS (*it
), stop
, Qnil
);
7183 eassert (it
->len
!= 0);
7187 IT_BYTEPOS (*it
) += it
->len
;
7188 IT_CHARPOS (*it
) += 1;
7192 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7193 /* If this is a new paragraph, determine its base
7194 direction (a.k.a. its base embedding level). */
7195 if (it
->bidi_it
.new_paragraph
)
7196 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
7197 bidi_move_to_visually_next (&it
->bidi_it
);
7198 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7199 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7200 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7202 /* As the scan direction was changed, we must
7203 re-compute the stop position for composition. */
7204 ptrdiff_t stop
= it
->end_charpos
;
7205 if (it
->bidi_it
.scan_dir
< 0)
7207 composition_compute_stop_pos (&it
->cmp_it
, IT_CHARPOS (*it
),
7208 IT_BYTEPOS (*it
), stop
, Qnil
);
7211 eassert (IT_BYTEPOS (*it
) == CHAR_TO_BYTE (IT_CHARPOS (*it
)));
7215 case GET_FROM_C_STRING
:
7216 /* Current display element of IT is from a C string. */
7218 /* If the string position is beyond string's end, it means
7219 next_element_from_c_string is padding the string with
7220 blanks, in which case we bypass the bidi iterator,
7221 because it cannot deal with such virtual characters. */
7222 || IT_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7224 IT_BYTEPOS (*it
) += it
->len
;
7225 IT_CHARPOS (*it
) += 1;
7229 bidi_move_to_visually_next (&it
->bidi_it
);
7230 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7231 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7235 case GET_FROM_DISPLAY_VECTOR
:
7236 /* Current display element of IT is from a display table entry.
7237 Advance in the display table definition. Reset it to null if
7238 end reached, and continue with characters from buffers/
7240 ++it
->current
.dpvec_index
;
7242 /* Restore face of the iterator to what they were before the
7243 display vector entry (these entries may contain faces). */
7244 it
->face_id
= it
->saved_face_id
;
7246 if (it
->dpvec
+ it
->current
.dpvec_index
>= it
->dpend
)
7248 int recheck_faces
= it
->ellipsis_p
;
7251 it
->method
= GET_FROM_C_STRING
;
7252 else if (STRINGP (it
->string
))
7253 it
->method
= GET_FROM_STRING
;
7256 it
->method
= GET_FROM_BUFFER
;
7257 it
->object
= it
->w
->contents
;
7261 it
->current
.dpvec_index
= -1;
7263 /* Skip over characters which were displayed via IT->dpvec. */
7264 if (it
->dpvec_char_len
< 0)
7265 reseat_at_next_visible_line_start (it
, 1);
7266 else if (it
->dpvec_char_len
> 0)
7268 if (it
->method
== GET_FROM_STRING
7269 && it
->current
.overlay_string_index
>= 0
7270 && it
->n_overlay_strings
> 0)
7271 it
->ignore_overlay_strings_at_pos_p
= 1;
7272 it
->len
= it
->dpvec_char_len
;
7273 set_iterator_to_next (it
, reseat_p
);
7276 /* Maybe recheck faces after display vector */
7278 it
->stop_charpos
= IT_CHARPOS (*it
);
7282 case GET_FROM_STRING
:
7283 /* Current display element is a character from a Lisp string. */
7284 eassert (it
->s
== NULL
&& STRINGP (it
->string
));
7285 /* Don't advance past string end. These conditions are true
7286 when set_iterator_to_next is called at the end of
7287 get_next_display_element, in which case the Lisp string is
7288 already exhausted, and all we want is pop the iterator
7290 if (it
->current
.overlay_string_index
>= 0)
7292 /* This is an overlay string, so there's no padding with
7293 spaces, and the number of characters in the string is
7294 where the string ends. */
7295 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7296 goto consider_string_end
;
7300 /* Not an overlay string. There could be padding, so test
7301 against it->end_charpos . */
7302 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7303 goto consider_string_end
;
7305 if (it
->cmp_it
.id
>= 0)
7311 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
7312 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
7313 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7314 it
->cmp_it
.from
= it
->cmp_it
.to
;
7318 composition_compute_stop_pos (&it
->cmp_it
,
7319 IT_STRING_CHARPOS (*it
),
7320 IT_STRING_BYTEPOS (*it
),
7321 it
->end_charpos
, it
->string
);
7324 else if (! it
->cmp_it
.reversed_p
)
7326 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7327 bidi_move_to_visually_next (&it
->bidi_it
);
7328 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7329 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7331 if (it
->cmp_it
.to
< it
->cmp_it
.nglyphs
)
7332 it
->cmp_it
.from
= it
->cmp_it
.to
;
7335 ptrdiff_t stop
= it
->end_charpos
;
7336 if (it
->bidi_it
.scan_dir
< 0)
7338 composition_compute_stop_pos (&it
->cmp_it
,
7339 IT_STRING_CHARPOS (*it
),
7340 IT_STRING_BYTEPOS (*it
), stop
,
7346 for (i
= 0; i
< it
->cmp_it
.nchars
; i
++)
7347 bidi_move_to_visually_next (&it
->bidi_it
);
7348 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7349 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7350 if (it
->cmp_it
.from
> 0)
7351 it
->cmp_it
.to
= it
->cmp_it
.from
;
7354 ptrdiff_t stop
= it
->end_charpos
;
7355 if (it
->bidi_it
.scan_dir
< 0)
7357 composition_compute_stop_pos (&it
->cmp_it
,
7358 IT_STRING_CHARPOS (*it
),
7359 IT_STRING_BYTEPOS (*it
), stop
,
7367 /* If the string position is beyond string's end, it
7368 means next_element_from_string is padding the string
7369 with blanks, in which case we bypass the bidi
7370 iterator, because it cannot deal with such virtual
7372 || IT_STRING_CHARPOS (*it
) >= it
->bidi_it
.string
.schars
)
7374 IT_STRING_BYTEPOS (*it
) += it
->len
;
7375 IT_STRING_CHARPOS (*it
) += 1;
7379 int prev_scan_dir
= it
->bidi_it
.scan_dir
;
7381 bidi_move_to_visually_next (&it
->bidi_it
);
7382 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7383 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7384 if (prev_scan_dir
!= it
->bidi_it
.scan_dir
)
7386 ptrdiff_t stop
= it
->end_charpos
;
7388 if (it
->bidi_it
.scan_dir
< 0)
7390 composition_compute_stop_pos (&it
->cmp_it
,
7391 IT_STRING_CHARPOS (*it
),
7392 IT_STRING_BYTEPOS (*it
), stop
,
7398 consider_string_end
:
7400 if (it
->current
.overlay_string_index
>= 0)
7402 /* IT->string is an overlay string. Advance to the
7403 next, if there is one. */
7404 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7407 next_overlay_string (it
);
7409 setup_for_ellipsis (it
, 0);
7414 /* IT->string is not an overlay string. If we reached
7415 its end, and there is something on IT->stack, proceed
7416 with what is on the stack. This can be either another
7417 string, this time an overlay string, or a buffer. */
7418 if (IT_STRING_CHARPOS (*it
) == SCHARS (it
->string
)
7422 if (it
->method
== GET_FROM_STRING
)
7423 goto consider_string_end
;
7428 case GET_FROM_IMAGE
:
7429 case GET_FROM_STRETCH
:
7430 /* The position etc with which we have to proceed are on
7431 the stack. The position may be at the end of a string,
7432 if the `display' property takes up the whole string. */
7433 eassert (it
->sp
> 0);
7435 if (it
->method
== GET_FROM_STRING
)
7436 goto consider_string_end
;
7440 /* There are no other methods defined, so this should be a bug. */
7444 eassert (it
->method
!= GET_FROM_STRING
7445 || (STRINGP (it
->string
)
7446 && IT_STRING_CHARPOS (*it
) >= 0));
7449 /* Load IT's display element fields with information about the next
7450 display element which comes from a display table entry or from the
7451 result of translating a control character to one of the forms `^C'
7454 IT->dpvec holds the glyphs to return as characters.
7455 IT->saved_face_id holds the face id before the display vector--it
7456 is restored into IT->face_id in set_iterator_to_next. */
7459 next_element_from_display_vector (struct it
*it
)
7464 eassert (it
->dpvec
&& it
->current
.dpvec_index
>= 0);
7466 it
->face_id
= it
->saved_face_id
;
7468 /* KFS: This code used to check ip->dpvec[0] instead of the current element.
7469 That seemed totally bogus - so I changed it... */
7470 gc
= it
->dpvec
[it
->current
.dpvec_index
];
7472 if (GLYPH_CODE_P (gc
))
7474 it
->c
= GLYPH_CODE_CHAR (gc
);
7475 it
->len
= CHAR_BYTES (it
->c
);
7477 /* The entry may contain a face id to use. Such a face id is
7478 the id of a Lisp face, not a realized face. A face id of
7479 zero means no face is specified. */
7480 if (it
->dpvec_face_id
>= 0)
7481 it
->face_id
= it
->dpvec_face_id
;
7484 int lface_id
= GLYPH_CODE_FACE (gc
);
7486 it
->face_id
= merge_faces (it
->f
, Qt
, lface_id
,
7491 /* Display table entry is invalid. Return a space. */
7492 it
->c
= ' ', it
->len
= 1;
7494 /* Don't change position and object of the iterator here. They are
7495 still the values of the character that had this display table
7496 entry or was translated, and that's what we want. */
7497 it
->what
= IT_CHARACTER
;
7501 /* Get the first element of string/buffer in the visual order, after
7502 being reseated to a new position in a string or a buffer. */
7504 get_visually_first_element (struct it
*it
)
7506 int string_p
= STRINGP (it
->string
) || it
->s
;
7507 ptrdiff_t eob
= (string_p
? it
->bidi_it
.string
.schars
: ZV
);
7508 ptrdiff_t bob
= (string_p
? 0 : BEGV
);
7510 if (STRINGP (it
->string
))
7512 it
->bidi_it
.charpos
= IT_STRING_CHARPOS (*it
);
7513 it
->bidi_it
.bytepos
= IT_STRING_BYTEPOS (*it
);
7517 it
->bidi_it
.charpos
= IT_CHARPOS (*it
);
7518 it
->bidi_it
.bytepos
= IT_BYTEPOS (*it
);
7521 if (it
->bidi_it
.charpos
== eob
)
7523 /* Nothing to do, but reset the FIRST_ELT flag, like
7524 bidi_paragraph_init does, because we are not going to
7526 it
->bidi_it
.first_elt
= 0;
7528 else if (it
->bidi_it
.charpos
== bob
7530 && (FETCH_CHAR (it
->bidi_it
.bytepos
- 1) == '\n'
7531 || FETCH_CHAR (it
->bidi_it
.bytepos
) == '\n')))
7533 /* If we are at the beginning of a line/string, we can produce
7534 the next element right away. */
7535 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7536 bidi_move_to_visually_next (&it
->bidi_it
);
7540 ptrdiff_t orig_bytepos
= it
->bidi_it
.bytepos
;
7542 /* We need to prime the bidi iterator starting at the line's or
7543 string's beginning, before we will be able to produce the
7546 it
->bidi_it
.charpos
= it
->bidi_it
.bytepos
= 0;
7548 it
->bidi_it
.charpos
= find_newline_no_quit (IT_CHARPOS (*it
),
7549 IT_BYTEPOS (*it
), -1,
7550 &it
->bidi_it
.bytepos
);
7551 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 1);
7554 /* Now return to buffer/string position where we were asked
7555 to get the next display element, and produce that. */
7556 bidi_move_to_visually_next (&it
->bidi_it
);
7558 while (it
->bidi_it
.bytepos
!= orig_bytepos
7559 && it
->bidi_it
.charpos
< eob
);
7562 /* Adjust IT's position information to where we ended up. */
7563 if (STRINGP (it
->string
))
7565 IT_STRING_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7566 IT_STRING_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7570 IT_CHARPOS (*it
) = it
->bidi_it
.charpos
;
7571 IT_BYTEPOS (*it
) = it
->bidi_it
.bytepos
;
7574 if (STRINGP (it
->string
) || !it
->s
)
7576 ptrdiff_t stop
, charpos
, bytepos
;
7578 if (STRINGP (it
->string
))
7581 stop
= SCHARS (it
->string
);
7582 if (stop
> it
->end_charpos
)
7583 stop
= it
->end_charpos
;
7584 charpos
= IT_STRING_CHARPOS (*it
);
7585 bytepos
= IT_STRING_BYTEPOS (*it
);
7589 stop
= it
->end_charpos
;
7590 charpos
= IT_CHARPOS (*it
);
7591 bytepos
= IT_BYTEPOS (*it
);
7593 if (it
->bidi_it
.scan_dir
< 0)
7595 composition_compute_stop_pos (&it
->cmp_it
, charpos
, bytepos
, stop
,
7600 /* Load IT with the next display element from Lisp string IT->string.
7601 IT->current.string_pos is the current position within the string.
7602 If IT->current.overlay_string_index >= 0, the Lisp string is an
7606 next_element_from_string (struct it
*it
)
7608 struct text_pos position
;
7610 eassert (STRINGP (it
->string
));
7611 eassert (!it
->bidi_p
|| EQ (it
->string
, it
->bidi_it
.string
.lstring
));
7612 eassert (IT_STRING_CHARPOS (*it
) >= 0);
7613 position
= it
->current
.string_pos
;
7615 /* With bidi reordering, the character to display might not be the
7616 character at IT_STRING_CHARPOS. BIDI_IT.FIRST_ELT non-zero means
7617 that we were reseat()ed to a new string, whose paragraph
7618 direction is not known. */
7619 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7621 get_visually_first_element (it
);
7622 SET_TEXT_POS (position
, IT_STRING_CHARPOS (*it
), IT_STRING_BYTEPOS (*it
));
7625 /* Time to check for invisible text? */
7626 if (IT_STRING_CHARPOS (*it
) < it
->end_charpos
)
7628 if (IT_STRING_CHARPOS (*it
) >= it
->stop_charpos
)
7631 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
7632 || IT_STRING_CHARPOS (*it
) == it
->stop_charpos
))
7634 /* With bidi non-linear iteration, we could find
7635 ourselves far beyond the last computed stop_charpos,
7636 with several other stop positions in between that we
7637 missed. Scan them all now, in buffer's logical
7638 order, until we find and handle the last stop_charpos
7639 that precedes our current position. */
7640 handle_stop_backwards (it
, it
->stop_charpos
);
7641 return GET_NEXT_DISPLAY_ELEMENT (it
);
7647 /* Take note of the stop position we just moved
7648 across, for when we will move back across it. */
7649 it
->prev_stop
= it
->stop_charpos
;
7650 /* If we are at base paragraph embedding level, take
7651 note of the last stop position seen at this
7653 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7654 it
->base_level_stop
= it
->stop_charpos
;
7658 /* Since a handler may have changed IT->method, we must
7660 return GET_NEXT_DISPLAY_ELEMENT (it
);
7664 /* If we are before prev_stop, we may have overstepped
7665 on our way backwards a stop_pos, and if so, we need
7666 to handle that stop_pos. */
7667 && IT_STRING_CHARPOS (*it
) < it
->prev_stop
7668 /* We can sometimes back up for reasons that have nothing
7669 to do with bidi reordering. E.g., compositions. The
7670 code below is only needed when we are above the base
7671 embedding level, so test for that explicitly. */
7672 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
7674 /* If we lost track of base_level_stop, we have no better
7675 place for handle_stop_backwards to start from than string
7676 beginning. This happens, e.g., when we were reseated to
7677 the previous screenful of text by vertical-motion. */
7678 if (it
->base_level_stop
<= 0
7679 || IT_STRING_CHARPOS (*it
) < it
->base_level_stop
)
7680 it
->base_level_stop
= 0;
7681 handle_stop_backwards (it
, it
->base_level_stop
);
7682 return GET_NEXT_DISPLAY_ELEMENT (it
);
7686 if (it
->current
.overlay_string_index
>= 0)
7688 /* Get the next character from an overlay string. In overlay
7689 strings, there is no field width or padding with spaces to
7691 if (IT_STRING_CHARPOS (*it
) >= SCHARS (it
->string
))
7696 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7697 IT_STRING_BYTEPOS (*it
),
7698 it
->bidi_it
.scan_dir
< 0
7700 : SCHARS (it
->string
))
7701 && next_element_from_composition (it
))
7705 else if (STRING_MULTIBYTE (it
->string
))
7707 const unsigned char *s
= (SDATA (it
->string
)
7708 + IT_STRING_BYTEPOS (*it
));
7709 it
->c
= string_char_and_length (s
, &it
->len
);
7713 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7719 /* Get the next character from a Lisp string that is not an
7720 overlay string. Such strings come from the mode line, for
7721 example. We may have to pad with spaces, or truncate the
7722 string. See also next_element_from_c_string. */
7723 if (IT_STRING_CHARPOS (*it
) >= it
->end_charpos
)
7728 else if (IT_STRING_CHARPOS (*it
) >= it
->string_nchars
)
7730 /* Pad with spaces. */
7731 it
->c
= ' ', it
->len
= 1;
7732 CHARPOS (position
) = BYTEPOS (position
) = -1;
7734 else if (CHAR_COMPOSED_P (it
, IT_STRING_CHARPOS (*it
),
7735 IT_STRING_BYTEPOS (*it
),
7736 it
->bidi_it
.scan_dir
< 0
7738 : it
->string_nchars
)
7739 && next_element_from_composition (it
))
7743 else if (STRING_MULTIBYTE (it
->string
))
7745 const unsigned char *s
= (SDATA (it
->string
)
7746 + IT_STRING_BYTEPOS (*it
));
7747 it
->c
= string_char_and_length (s
, &it
->len
);
7751 it
->c
= SREF (it
->string
, IT_STRING_BYTEPOS (*it
));
7756 /* Record what we have and where it came from. */
7757 it
->what
= IT_CHARACTER
;
7758 it
->object
= it
->string
;
7759 it
->position
= position
;
7764 /* Load IT with next display element from C string IT->s.
7765 IT->string_nchars is the maximum number of characters to return
7766 from the string. IT->end_charpos may be greater than
7767 IT->string_nchars when this function is called, in which case we
7768 may have to return padding spaces. Value is zero if end of string
7769 reached, including padding spaces. */
7772 next_element_from_c_string (struct it
*it
)
7777 eassert (!it
->bidi_p
|| it
->s
== it
->bidi_it
.string
.s
);
7778 it
->what
= IT_CHARACTER
;
7779 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = 0;
7782 /* With bidi reordering, the character to display might not be the
7783 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7784 we were reseated to a new string, whose paragraph direction is
7786 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7787 get_visually_first_element (it
);
7789 /* IT's position can be greater than IT->string_nchars in case a
7790 field width or precision has been specified when the iterator was
7792 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7794 /* End of the game. */
7798 else if (IT_CHARPOS (*it
) >= it
->string_nchars
)
7800 /* Pad with spaces. */
7801 it
->c
= ' ', it
->len
= 1;
7802 BYTEPOS (it
->position
) = CHARPOS (it
->position
) = -1;
7804 else if (it
->multibyte_p
)
7805 it
->c
= string_char_and_length (it
->s
+ IT_BYTEPOS (*it
), &it
->len
);
7807 it
->c
= it
->s
[IT_BYTEPOS (*it
)], it
->len
= 1;
7813 /* Set up IT to return characters from an ellipsis, if appropriate.
7814 The definition of the ellipsis glyphs may come from a display table
7815 entry. This function fills IT with the first glyph from the
7816 ellipsis if an ellipsis is to be displayed. */
7819 next_element_from_ellipsis (struct it
*it
)
7821 if (it
->selective_display_ellipsis_p
)
7822 setup_for_ellipsis (it
, it
->len
);
7825 /* The face at the current position may be different from the
7826 face we find after the invisible text. Remember what it
7827 was in IT->saved_face_id, and signal that it's there by
7828 setting face_before_selective_p. */
7829 it
->saved_face_id
= it
->face_id
;
7830 it
->method
= GET_FROM_BUFFER
;
7831 it
->object
= it
->w
->contents
;
7832 reseat_at_next_visible_line_start (it
, 1);
7833 it
->face_before_selective_p
= 1;
7836 return GET_NEXT_DISPLAY_ELEMENT (it
);
7840 /* Deliver an image display element. The iterator IT is already
7841 filled with image information (done in handle_display_prop). Value
7846 next_element_from_image (struct it
*it
)
7848 it
->what
= IT_IMAGE
;
7849 it
->ignore_overlay_strings_at_pos_p
= 0;
7854 /* Fill iterator IT with next display element from a stretch glyph
7855 property. IT->object is the value of the text property. Value is
7859 next_element_from_stretch (struct it
*it
)
7861 it
->what
= IT_STRETCH
;
7865 /* Scan backwards from IT's current position until we find a stop
7866 position, or until BEGV. This is called when we find ourself
7867 before both the last known prev_stop and base_level_stop while
7868 reordering bidirectional text. */
7871 compute_stop_pos_backwards (struct it
*it
)
7873 const int SCAN_BACK_LIMIT
= 1000;
7874 struct text_pos pos
;
7875 struct display_pos save_current
= it
->current
;
7876 struct text_pos save_position
= it
->position
;
7877 ptrdiff_t charpos
= IT_CHARPOS (*it
);
7878 ptrdiff_t where_we_are
= charpos
;
7879 ptrdiff_t save_stop_pos
= it
->stop_charpos
;
7880 ptrdiff_t save_end_pos
= it
->end_charpos
;
7882 eassert (NILP (it
->string
) && !it
->s
);
7883 eassert (it
->bidi_p
);
7887 it
->end_charpos
= min (charpos
+ 1, ZV
);
7888 charpos
= max (charpos
- SCAN_BACK_LIMIT
, BEGV
);
7889 SET_TEXT_POS (pos
, charpos
, CHAR_TO_BYTE (charpos
));
7890 reseat_1 (it
, pos
, 0);
7891 compute_stop_pos (it
);
7892 /* We must advance forward, right? */
7893 if (it
->stop_charpos
<= charpos
)
7896 while (charpos
> BEGV
&& it
->stop_charpos
>= it
->end_charpos
);
7898 if (it
->stop_charpos
<= where_we_are
)
7899 it
->prev_stop
= it
->stop_charpos
;
7901 it
->prev_stop
= BEGV
;
7903 it
->current
= save_current
;
7904 it
->position
= save_position
;
7905 it
->stop_charpos
= save_stop_pos
;
7906 it
->end_charpos
= save_end_pos
;
7909 /* Scan forward from CHARPOS in the current buffer/string, until we
7910 find a stop position > current IT's position. Then handle the stop
7911 position before that. This is called when we bump into a stop
7912 position while reordering bidirectional text. CHARPOS should be
7913 the last previously processed stop_pos (or BEGV/0, if none were
7914 processed yet) whose position is less that IT's current
7918 handle_stop_backwards (struct it
*it
, ptrdiff_t charpos
)
7920 int bufp
= !STRINGP (it
->string
);
7921 ptrdiff_t where_we_are
= (bufp
? IT_CHARPOS (*it
) : IT_STRING_CHARPOS (*it
));
7922 struct display_pos save_current
= it
->current
;
7923 struct text_pos save_position
= it
->position
;
7924 struct text_pos pos1
;
7925 ptrdiff_t next_stop
;
7927 /* Scan in strict logical order. */
7928 eassert (it
->bidi_p
);
7932 it
->prev_stop
= charpos
;
7935 SET_TEXT_POS (pos1
, charpos
, CHAR_TO_BYTE (charpos
));
7936 reseat_1 (it
, pos1
, 0);
7939 it
->current
.string_pos
= string_pos (charpos
, it
->string
);
7940 compute_stop_pos (it
);
7941 /* We must advance forward, right? */
7942 if (it
->stop_charpos
<= it
->prev_stop
)
7944 charpos
= it
->stop_charpos
;
7946 while (charpos
<= where_we_are
);
7949 it
->current
= save_current
;
7950 it
->position
= save_position
;
7951 next_stop
= it
->stop_charpos
;
7952 it
->stop_charpos
= it
->prev_stop
;
7954 it
->stop_charpos
= next_stop
;
7957 /* Load IT with the next display element from current_buffer. Value
7958 is zero if end of buffer reached. IT->stop_charpos is the next
7959 position at which to stop and check for text properties or buffer
7963 next_element_from_buffer (struct it
*it
)
7967 eassert (IT_CHARPOS (*it
) >= BEGV
);
7968 eassert (NILP (it
->string
) && !it
->s
);
7969 eassert (!it
->bidi_p
7970 || (EQ (it
->bidi_it
.string
.lstring
, Qnil
)
7971 && it
->bidi_it
.string
.s
== NULL
));
7973 /* With bidi reordering, the character to display might not be the
7974 character at IT_CHARPOS. BIDI_IT.FIRST_ELT non-zero means that
7975 we were reseat()ed to a new buffer position, which is potentially
7976 a different paragraph. */
7977 if (it
->bidi_p
&& it
->bidi_it
.first_elt
)
7979 get_visually_first_element (it
);
7980 SET_TEXT_POS (it
->position
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
7983 if (IT_CHARPOS (*it
) >= it
->stop_charpos
)
7985 if (IT_CHARPOS (*it
) >= it
->end_charpos
)
7987 int overlay_strings_follow_p
;
7989 /* End of the game, except when overlay strings follow that
7990 haven't been returned yet. */
7991 if (it
->overlay_strings_at_end_processed_p
)
7992 overlay_strings_follow_p
= 0;
7995 it
->overlay_strings_at_end_processed_p
= 1;
7996 overlay_strings_follow_p
= get_overlay_strings (it
, 0);
7999 if (overlay_strings_follow_p
)
8000 success_p
= GET_NEXT_DISPLAY_ELEMENT (it
);
8004 it
->position
= it
->current
.pos
;
8008 else if (!(!it
->bidi_p
8009 || BIDI_AT_BASE_LEVEL (it
->bidi_it
)
8010 || IT_CHARPOS (*it
) == it
->stop_charpos
))
8012 /* With bidi non-linear iteration, we could find ourselves
8013 far beyond the last computed stop_charpos, with several
8014 other stop positions in between that we missed. Scan
8015 them all now, in buffer's logical order, until we find
8016 and handle the last stop_charpos that precedes our
8017 current position. */
8018 handle_stop_backwards (it
, it
->stop_charpos
);
8019 return GET_NEXT_DISPLAY_ELEMENT (it
);
8025 /* Take note of the stop position we just moved across,
8026 for when we will move back across it. */
8027 it
->prev_stop
= it
->stop_charpos
;
8028 /* If we are at base paragraph embedding level, take
8029 note of the last stop position seen at this
8031 if (BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8032 it
->base_level_stop
= it
->stop_charpos
;
8035 return GET_NEXT_DISPLAY_ELEMENT (it
);
8039 /* If we are before prev_stop, we may have overstepped on
8040 our way backwards a stop_pos, and if so, we need to
8041 handle that stop_pos. */
8042 && IT_CHARPOS (*it
) < it
->prev_stop
8043 /* We can sometimes back up for reasons that have nothing
8044 to do with bidi reordering. E.g., compositions. The
8045 code below is only needed when we are above the base
8046 embedding level, so test for that explicitly. */
8047 && !BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8049 if (it
->base_level_stop
<= 0
8050 || IT_CHARPOS (*it
) < it
->base_level_stop
)
8052 /* If we lost track of base_level_stop, we need to find
8053 prev_stop by looking backwards. This happens, e.g., when
8054 we were reseated to the previous screenful of text by
8056 it
->base_level_stop
= BEGV
;
8057 compute_stop_pos_backwards (it
);
8058 handle_stop_backwards (it
, it
->prev_stop
);
8061 handle_stop_backwards (it
, it
->base_level_stop
);
8062 return GET_NEXT_DISPLAY_ELEMENT (it
);
8066 /* No face changes, overlays etc. in sight, so just return a
8067 character from current_buffer. */
8071 /* Maybe run the redisplay end trigger hook. Performance note:
8072 This doesn't seem to cost measurable time. */
8073 if (it
->redisplay_end_trigger_charpos
8075 && IT_CHARPOS (*it
) >= it
->redisplay_end_trigger_charpos
)
8076 run_redisplay_end_trigger_hook (it
);
8078 stop
= it
->bidi_it
.scan_dir
< 0 ? -1 : it
->end_charpos
;
8079 if (CHAR_COMPOSED_P (it
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
),
8081 && next_element_from_composition (it
))
8086 /* Get the next character, maybe multibyte. */
8087 p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
8088 if (it
->multibyte_p
&& !ASCII_BYTE_P (*p
))
8089 it
->c
= STRING_CHAR_AND_LENGTH (p
, it
->len
);
8091 it
->c
= *p
, it
->len
= 1;
8093 /* Record what we have and where it came from. */
8094 it
->what
= IT_CHARACTER
;
8095 it
->object
= it
->w
->contents
;
8096 it
->position
= it
->current
.pos
;
8098 /* Normally we return the character found above, except when we
8099 really want to return an ellipsis for selective display. */
8104 /* A value of selective > 0 means hide lines indented more
8105 than that number of columns. */
8106 if (it
->selective
> 0
8107 && IT_CHARPOS (*it
) + 1 < ZV
8108 && indented_beyond_p (IT_CHARPOS (*it
) + 1,
8109 IT_BYTEPOS (*it
) + 1,
8112 success_p
= next_element_from_ellipsis (it
);
8113 it
->dpvec_char_len
= -1;
8116 else if (it
->c
== '\r' && it
->selective
== -1)
8118 /* A value of selective == -1 means that everything from the
8119 CR to the end of the line is invisible, with maybe an
8120 ellipsis displayed for it. */
8121 success_p
= next_element_from_ellipsis (it
);
8122 it
->dpvec_char_len
= -1;
8127 /* Value is zero if end of buffer reached. */
8128 eassert (!success_p
|| it
->what
!= IT_CHARACTER
|| it
->len
> 0);
8133 /* Run the redisplay end trigger hook for IT. */
8136 run_redisplay_end_trigger_hook (struct it
*it
)
8138 Lisp_Object args
[3];
8140 /* IT->glyph_row should be non-null, i.e. we should be actually
8141 displaying something, or otherwise we should not run the hook. */
8142 eassert (it
->glyph_row
);
8144 /* Set up hook arguments. */
8145 args
[0] = Qredisplay_end_trigger_functions
;
8146 args
[1] = it
->window
;
8147 XSETINT (args
[2], it
->redisplay_end_trigger_charpos
);
8148 it
->redisplay_end_trigger_charpos
= 0;
8150 /* Since we are *trying* to run these functions, don't try to run
8151 them again, even if they get an error. */
8152 wset_redisplay_end_trigger (it
->w
, Qnil
);
8153 Frun_hook_with_args (3, args
);
8155 /* Notice if it changed the face of the character we are on. */
8156 handle_face_prop (it
);
8160 /* Deliver a composition display element. Unlike the other
8161 next_element_from_XXX, this function is not registered in the array
8162 get_next_element[]. It is called from next_element_from_buffer and
8163 next_element_from_string when necessary. */
8166 next_element_from_composition (struct it
*it
)
8168 it
->what
= IT_COMPOSITION
;
8169 it
->len
= it
->cmp_it
.nbytes
;
8170 if (STRINGP (it
->string
))
8174 IT_STRING_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8175 IT_STRING_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8178 it
->position
= it
->current
.string_pos
;
8179 it
->object
= it
->string
;
8180 it
->c
= composition_update_it (&it
->cmp_it
, IT_STRING_CHARPOS (*it
),
8181 IT_STRING_BYTEPOS (*it
), it
->string
);
8187 IT_CHARPOS (*it
) += it
->cmp_it
.nchars
;
8188 IT_BYTEPOS (*it
) += it
->cmp_it
.nbytes
;
8191 if (it
->bidi_it
.new_paragraph
)
8192 bidi_paragraph_init (it
->paragraph_embedding
, &it
->bidi_it
, 0);
8193 /* Resync the bidi iterator with IT's new position.
8194 FIXME: this doesn't support bidirectional text. */
8195 while (it
->bidi_it
.charpos
< IT_CHARPOS (*it
))
8196 bidi_move_to_visually_next (&it
->bidi_it
);
8200 it
->position
= it
->current
.pos
;
8201 it
->object
= it
->w
->contents
;
8202 it
->c
= composition_update_it (&it
->cmp_it
, IT_CHARPOS (*it
),
8203 IT_BYTEPOS (*it
), Qnil
);
8210 /***********************************************************************
8211 Moving an iterator without producing glyphs
8212 ***********************************************************************/
8214 /* Check if iterator is at a position corresponding to a valid buffer
8215 position after some move_it_ call. */
8217 #define IT_POS_VALID_AFTER_MOVE_P(it) \
8218 ((it)->method == GET_FROM_STRING \
8219 ? IT_STRING_CHARPOS (*it) == 0 \
8223 /* Move iterator IT to a specified buffer or X position within one
8224 line on the display without producing glyphs.
8226 OP should be a bit mask including some or all of these bits:
8227 MOVE_TO_X: Stop upon reaching x-position TO_X.
8228 MOVE_TO_POS: Stop upon reaching buffer or string position TO_CHARPOS.
8229 Regardless of OP's value, stop upon reaching the end of the display line.
8231 TO_X is normally a value 0 <= TO_X <= IT->last_visible_x.
8232 This means, in particular, that TO_X includes window's horizontal
8235 The return value has several possible values that
8236 say what condition caused the scan to stop:
8238 MOVE_POS_MATCH_OR_ZV
8239 - when TO_POS or ZV was reached.
8242 -when TO_X was reached before TO_POS or ZV were reached.
8245 - when we reached the end of the display area and the line must
8249 - when we reached the end of the display area and the line is
8253 - when we stopped at a line end, i.e. a newline or a CR and selective
8256 static enum move_it_result
8257 move_it_in_display_line_to (struct it
*it
,
8258 ptrdiff_t to_charpos
, int to_x
,
8259 enum move_operation_enum op
)
8261 enum move_it_result result
= MOVE_UNDEFINED
;
8262 struct glyph_row
*saved_glyph_row
;
8263 struct it wrap_it
, atpos_it
, atx_it
, ppos_it
;
8264 void *wrap_data
= NULL
, *atpos_data
= NULL
, *atx_data
= NULL
;
8265 void *ppos_data
= NULL
;
8267 enum it_method prev_method
= it
->method
;
8268 ptrdiff_t prev_pos
= IT_CHARPOS (*it
);
8269 int saw_smaller_pos
= prev_pos
< to_charpos
;
8271 /* Don't produce glyphs in produce_glyphs. */
8272 saved_glyph_row
= it
->glyph_row
;
8273 it
->glyph_row
= NULL
;
8275 /* Use wrap_it to save a copy of IT wherever a word wrap could
8276 occur. Use atpos_it to save a copy of IT at the desired buffer
8277 position, if found, so that we can scan ahead and check if the
8278 word later overshoots the window edge. Use atx_it similarly, for
8284 /* Use ppos_it under bidi reordering to save a copy of IT for the
8285 position > CHARPOS that is the closest to CHARPOS. We restore
8286 that position in IT when we have scanned the entire display line
8287 without finding a match for CHARPOS and all the character
8288 positions are greater than CHARPOS. */
8291 SAVE_IT (ppos_it
, *it
, ppos_data
);
8292 SET_TEXT_POS (ppos_it
.current
.pos
, ZV
, ZV_BYTE
);
8293 if ((op
& MOVE_TO_POS
) && IT_CHARPOS (*it
) >= to_charpos
)
8294 SAVE_IT (ppos_it
, *it
, ppos_data
);
8297 #define BUFFER_POS_REACHED_P() \
8298 ((op & MOVE_TO_POS) != 0 \
8299 && BUFFERP (it->object) \
8300 && (IT_CHARPOS (*it) == to_charpos \
8302 || BIDI_AT_BASE_LEVEL (it->bidi_it)) \
8303 && IT_CHARPOS (*it) > to_charpos) \
8304 || (it->what == IT_COMPOSITION \
8305 && ((IT_CHARPOS (*it) > to_charpos \
8306 && to_charpos >= it->cmp_it.charpos) \
8307 || (IT_CHARPOS (*it) < to_charpos \
8308 && to_charpos <= it->cmp_it.charpos)))) \
8309 && (it->method == GET_FROM_BUFFER \
8310 || (it->method == GET_FROM_DISPLAY_VECTOR \
8311 && it->dpvec + it->current.dpvec_index + 1 >= it->dpend)))
8313 /* If there's a line-/wrap-prefix, handle it. */
8314 if (it
->hpos
== 0 && it
->method
== GET_FROM_BUFFER
8315 && it
->current_y
< it
->last_visible_y
)
8316 handle_line_prefix (it
);
8318 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8319 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8323 int x
, i
, ascent
= 0, descent
= 0;
8325 /* Utility macro to reset an iterator with x, ascent, and descent. */
8326 #define IT_RESET_X_ASCENT_DESCENT(IT) \
8327 ((IT)->current_x = x, (IT)->max_ascent = ascent, \
8328 (IT)->max_descent = descent)
8330 /* Stop if we move beyond TO_CHARPOS (after an image or a
8331 display string or stretch glyph). */
8332 if ((op
& MOVE_TO_POS
) != 0
8333 && BUFFERP (it
->object
)
8334 && it
->method
== GET_FROM_BUFFER
8336 /* When the iterator is at base embedding level, we
8337 are guaranteed that characters are delivered for
8338 display in strictly increasing order of their
8339 buffer positions. */
8340 || BIDI_AT_BASE_LEVEL (it
->bidi_it
))
8341 && IT_CHARPOS (*it
) > to_charpos
)
8343 && (prev_method
== GET_FROM_IMAGE
8344 || prev_method
== GET_FROM_STRETCH
8345 || prev_method
== GET_FROM_STRING
)
8346 /* Passed TO_CHARPOS from left to right. */
8347 && ((prev_pos
< to_charpos
8348 && IT_CHARPOS (*it
) > to_charpos
)
8349 /* Passed TO_CHARPOS from right to left. */
8350 || (prev_pos
> to_charpos
8351 && IT_CHARPOS (*it
) < to_charpos
)))))
8353 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8355 result
= MOVE_POS_MATCH_OR_ZV
;
8358 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8359 /* If wrap_it is valid, the current position might be in a
8360 word that is wrapped. So, save the iterator in
8361 atpos_it and continue to see if wrapping happens. */
8362 SAVE_IT (atpos_it
, *it
, atpos_data
);
8365 /* Stop when ZV reached.
8366 We used to stop here when TO_CHARPOS reached as well, but that is
8367 too soon if this glyph does not fit on this line. So we handle it
8368 explicitly below. */
8369 if (!get_next_display_element (it
))
8371 result
= MOVE_POS_MATCH_OR_ZV
;
8375 if (it
->line_wrap
== TRUNCATE
)
8377 if (BUFFER_POS_REACHED_P ())
8379 result
= MOVE_POS_MATCH_OR_ZV
;
8385 if (it
->line_wrap
== WORD_WRAP
)
8387 if (IT_DISPLAYING_WHITESPACE (it
))
8391 /* We have reached a glyph that follows one or more
8392 whitespace characters. If the position is
8393 already found, we are done. */
8394 if (atpos_it
.sp
>= 0)
8396 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8397 result
= MOVE_POS_MATCH_OR_ZV
;
8402 RESTORE_IT (it
, &atx_it
, atx_data
);
8403 result
= MOVE_X_REACHED
;
8406 /* Otherwise, we can wrap here. */
8407 SAVE_IT (wrap_it
, *it
, wrap_data
);
8413 /* Remember the line height for the current line, in case
8414 the next element doesn't fit on the line. */
8415 ascent
= it
->max_ascent
;
8416 descent
= it
->max_descent
;
8418 /* The call to produce_glyphs will get the metrics of the
8419 display element IT is loaded with. Record the x-position
8420 before this display element, in case it doesn't fit on the
8424 PRODUCE_GLYPHS (it
);
8426 if (it
->area
!= TEXT_AREA
)
8428 prev_method
= it
->method
;
8429 if (it
->method
== GET_FROM_BUFFER
)
8430 prev_pos
= IT_CHARPOS (*it
);
8431 set_iterator_to_next (it
, 1);
8432 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8433 SET_TEXT_POS (this_line_min_pos
,
8434 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8436 && (op
& MOVE_TO_POS
)
8437 && IT_CHARPOS (*it
) > to_charpos
8438 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8439 SAVE_IT (ppos_it
, *it
, ppos_data
);
8443 /* The number of glyphs we get back in IT->nglyphs will normally
8444 be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph
8445 character on a terminal frame, or (iii) a line end. For the
8446 second case, IT->nglyphs - 1 padding glyphs will be present.
8447 (On X frames, there is only one glyph produced for a
8448 composite character.)
8450 The behavior implemented below means, for continuation lines,
8451 that as many spaces of a TAB as fit on the current line are
8452 displayed there. For terminal frames, as many glyphs of a
8453 multi-glyph character are displayed in the current line, too.
8454 This is what the old redisplay code did, and we keep it that
8455 way. Under X, the whole shape of a complex character must
8456 fit on the line or it will be completely displayed in the
8459 Note that both for tabs and padding glyphs, all glyphs have
8463 /* More than one glyph or glyph doesn't fit on line. All
8464 glyphs have the same width. */
8465 int single_glyph_width
= it
->pixel_width
/ it
->nglyphs
;
8467 int x_before_this_char
= x
;
8468 int hpos_before_this_char
= it
->hpos
;
8470 for (i
= 0; i
< it
->nglyphs
; ++i
, x
= new_x
)
8472 new_x
= x
+ single_glyph_width
;
8474 /* We want to leave anything reaching TO_X to the caller. */
8475 if ((op
& MOVE_TO_X
) && new_x
> to_x
)
8477 if (BUFFER_POS_REACHED_P ())
8479 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8480 goto buffer_pos_reached
;
8481 if (atpos_it
.sp
< 0)
8483 SAVE_IT (atpos_it
, *it
, atpos_data
);
8484 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8489 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8492 result
= MOVE_X_REACHED
;
8497 SAVE_IT (atx_it
, *it
, atx_data
);
8498 IT_RESET_X_ASCENT_DESCENT (&atx_it
);
8503 if (/* Lines are continued. */
8504 it
->line_wrap
!= TRUNCATE
8505 && (/* And glyph doesn't fit on the line. */
8506 new_x
> it
->last_visible_x
8507 /* Or it fits exactly and we're on a window
8509 || (new_x
== it
->last_visible_x
8510 && FRAME_WINDOW_P (it
->f
)
8511 && ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8512 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8513 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
8515 if (/* IT->hpos == 0 means the very first glyph
8516 doesn't fit on the line, e.g. a wide image. */
8518 || (new_x
== it
->last_visible_x
8519 && FRAME_WINDOW_P (it
->f
)))
8522 it
->current_x
= new_x
;
8524 /* The character's last glyph just barely fits
8526 if (i
== it
->nglyphs
- 1)
8528 /* If this is the destination position,
8529 return a position *before* it in this row,
8530 now that we know it fits in this row. */
8531 if (BUFFER_POS_REACHED_P ())
8533 if (it
->line_wrap
!= WORD_WRAP
8536 it
->hpos
= hpos_before_this_char
;
8537 it
->current_x
= x_before_this_char
;
8538 result
= MOVE_POS_MATCH_OR_ZV
;
8541 if (it
->line_wrap
== WORD_WRAP
8544 SAVE_IT (atpos_it
, *it
, atpos_data
);
8545 atpos_it
.current_x
= x_before_this_char
;
8546 atpos_it
.hpos
= hpos_before_this_char
;
8550 prev_method
= it
->method
;
8551 if (it
->method
== GET_FROM_BUFFER
)
8552 prev_pos
= IT_CHARPOS (*it
);
8553 set_iterator_to_next (it
, 1);
8554 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8555 SET_TEXT_POS (this_line_min_pos
,
8556 IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8557 /* On graphical terminals, newlines may
8558 "overflow" into the fringe if
8559 overflow-newline-into-fringe is non-nil.
8560 On text terminals, and on graphical
8561 terminals with no right margin, newlines
8562 may overflow into the last glyph on the
8564 if (!FRAME_WINDOW_P (it
->f
)
8566 && it
->bidi_it
.paragraph_dir
== R2L
)
8567 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8568 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8569 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8571 if (!get_next_display_element (it
))
8573 result
= MOVE_POS_MATCH_OR_ZV
;
8576 if (BUFFER_POS_REACHED_P ())
8578 if (ITERATOR_AT_END_OF_LINE_P (it
))
8579 result
= MOVE_POS_MATCH_OR_ZV
;
8581 result
= MOVE_LINE_CONTINUED
;
8584 if (ITERATOR_AT_END_OF_LINE_P (it
)
8585 && (it
->line_wrap
!= WORD_WRAP
8588 result
= MOVE_NEWLINE_OR_CR
;
8595 IT_RESET_X_ASCENT_DESCENT (it
);
8597 if (wrap_it
.sp
>= 0)
8599 RESTORE_IT (it
, &wrap_it
, wrap_data
);
8604 TRACE_MOVE ((stderr
, "move_it_in: continued at %d\n",
8606 result
= MOVE_LINE_CONTINUED
;
8610 if (BUFFER_POS_REACHED_P ())
8612 if (it
->line_wrap
!= WORD_WRAP
|| wrap_it
.sp
< 0)
8613 goto buffer_pos_reached
;
8614 if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
< 0)
8616 SAVE_IT (atpos_it
, *it
, atpos_data
);
8617 IT_RESET_X_ASCENT_DESCENT (&atpos_it
);
8621 if (new_x
> it
->first_visible_x
)
8623 /* Glyph is visible. Increment number of glyphs that
8624 would be displayed. */
8629 if (result
!= MOVE_UNDEFINED
)
8632 else if (BUFFER_POS_REACHED_P ())
8635 IT_RESET_X_ASCENT_DESCENT (it
);
8636 result
= MOVE_POS_MATCH_OR_ZV
;
8639 else if ((op
& MOVE_TO_X
) && it
->current_x
>= to_x
)
8641 /* Stop when TO_X specified and reached. This check is
8642 necessary here because of lines consisting of a line end,
8643 only. The line end will not produce any glyphs and we
8644 would never get MOVE_X_REACHED. */
8645 eassert (it
->nglyphs
== 0);
8646 result
= MOVE_X_REACHED
;
8650 /* Is this a line end? If yes, we're done. */
8651 if (ITERATOR_AT_END_OF_LINE_P (it
))
8653 /* If we are past TO_CHARPOS, but never saw any character
8654 positions smaller than TO_CHARPOS, return
8655 MOVE_POS_MATCH_OR_ZV, like the unidirectional display
8657 if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0)
8659 if (!saw_smaller_pos
&& IT_CHARPOS (*it
) > to_charpos
)
8661 if (IT_CHARPOS (ppos_it
) < ZV
)
8663 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8664 result
= MOVE_POS_MATCH_OR_ZV
;
8667 goto buffer_pos_reached
;
8669 else if (it
->line_wrap
== WORD_WRAP
&& atpos_it
.sp
>= 0
8670 && IT_CHARPOS (*it
) > to_charpos
)
8671 goto buffer_pos_reached
;
8673 result
= MOVE_NEWLINE_OR_CR
;
8676 result
= MOVE_NEWLINE_OR_CR
;
8680 prev_method
= it
->method
;
8681 if (it
->method
== GET_FROM_BUFFER
)
8682 prev_pos
= IT_CHARPOS (*it
);
8683 /* The current display element has been consumed. Advance
8685 set_iterator_to_next (it
, 1);
8686 if (IT_CHARPOS (*it
) < CHARPOS (this_line_min_pos
))
8687 SET_TEXT_POS (this_line_min_pos
, IT_CHARPOS (*it
), IT_BYTEPOS (*it
));
8688 if (IT_CHARPOS (*it
) < to_charpos
)
8689 saw_smaller_pos
= 1;
8691 && (op
& MOVE_TO_POS
)
8692 && IT_CHARPOS (*it
) >= to_charpos
8693 && IT_CHARPOS (*it
) < IT_CHARPOS (ppos_it
))
8694 SAVE_IT (ppos_it
, *it
, ppos_data
);
8696 /* Stop if lines are truncated and IT's current x-position is
8697 past the right edge of the window now. */
8698 if (it
->line_wrap
== TRUNCATE
8699 && it
->current_x
>= it
->last_visible_x
)
8701 if (!FRAME_WINDOW_P (it
->f
)
8702 || ((it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
8703 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
8704 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0
8705 || IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
8709 if ((at_eob_p
= !get_next_display_element (it
))
8710 || BUFFER_POS_REACHED_P ()
8711 /* If we are past TO_CHARPOS, but never saw any
8712 character positions smaller than TO_CHARPOS,
8713 return MOVE_POS_MATCH_OR_ZV, like the
8714 unidirectional display did. */
8715 || (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8717 && IT_CHARPOS (*it
) > to_charpos
))
8720 && !at_eob_p
&& IT_CHARPOS (ppos_it
) < ZV
)
8721 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8722 result
= MOVE_POS_MATCH_OR_ZV
;
8725 if (ITERATOR_AT_END_OF_LINE_P (it
))
8727 result
= MOVE_NEWLINE_OR_CR
;
8731 else if (it
->bidi_p
&& (op
& MOVE_TO_POS
) != 0
8733 && IT_CHARPOS (*it
) > to_charpos
)
8735 if (IT_CHARPOS (ppos_it
) < ZV
)
8736 RESTORE_IT (it
, &ppos_it
, ppos_data
);
8737 result
= MOVE_POS_MATCH_OR_ZV
;
8740 result
= MOVE_LINE_TRUNCATED
;
8743 #undef IT_RESET_X_ASCENT_DESCENT
8746 #undef BUFFER_POS_REACHED_P
8748 /* If we scanned beyond to_pos and didn't find a point to wrap at,
8749 restore the saved iterator. */
8750 if (atpos_it
.sp
>= 0)
8751 RESTORE_IT (it
, &atpos_it
, atpos_data
);
8752 else if (atx_it
.sp
>= 0)
8753 RESTORE_IT (it
, &atx_it
, atx_data
);
8758 bidi_unshelve_cache (atpos_data
, 1);
8760 bidi_unshelve_cache (atx_data
, 1);
8762 bidi_unshelve_cache (wrap_data
, 1);
8764 bidi_unshelve_cache (ppos_data
, 1);
8766 /* Restore the iterator settings altered at the beginning of this
8768 it
->glyph_row
= saved_glyph_row
;
8772 /* For external use. */
8774 move_it_in_display_line (struct it
*it
,
8775 ptrdiff_t to_charpos
, int to_x
,
8776 enum move_operation_enum op
)
8778 if (it
->line_wrap
== WORD_WRAP
8779 && (op
& MOVE_TO_X
))
8782 void *save_data
= NULL
;
8785 SAVE_IT (save_it
, *it
, save_data
);
8786 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8787 /* When word-wrap is on, TO_X may lie past the end
8788 of a wrapped line. Then it->current is the
8789 character on the next line, so backtrack to the
8790 space before the wrap point. */
8791 if (skip
== MOVE_LINE_CONTINUED
)
8793 int prev_x
= max (it
->current_x
- 1, 0);
8794 RESTORE_IT (it
, &save_it
, save_data
);
8795 move_it_in_display_line_to
8796 (it
, -1, prev_x
, MOVE_TO_X
);
8799 bidi_unshelve_cache (save_data
, 1);
8802 move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8806 /* Move IT forward until it satisfies one or more of the criteria in
8807 TO_CHARPOS, TO_X, TO_Y, and TO_VPOS.
8809 OP is a bit-mask that specifies where to stop, and in particular,
8810 which of those four position arguments makes a difference. See the
8811 description of enum move_operation_enum.
8813 If TO_CHARPOS is in invisible text, e.g. a truncated part of a
8814 screen line, this function will set IT to the next position that is
8815 displayed to the right of TO_CHARPOS on the screen. */
8818 move_it_to (struct it
*it
, ptrdiff_t to_charpos
, int to_x
, int to_y
, int to_vpos
, int op
)
8820 enum move_it_result skip
, skip2
= MOVE_X_REACHED
;
8821 int line_height
, line_start_x
= 0, reached
= 0;
8822 void *backup_data
= NULL
;
8826 if (op
& MOVE_TO_VPOS
)
8828 /* If no TO_CHARPOS and no TO_X specified, stop at the
8829 start of the line TO_VPOS. */
8830 if ((op
& (MOVE_TO_X
| MOVE_TO_POS
)) == 0)
8832 if (it
->vpos
== to_vpos
)
8838 skip
= move_it_in_display_line_to (it
, -1, -1, 0);
8842 /* TO_VPOS >= 0 means stop at TO_X in the line at
8843 TO_VPOS, or at TO_POS, whichever comes first. */
8844 if (it
->vpos
== to_vpos
)
8850 skip
= move_it_in_display_line_to (it
, to_charpos
, to_x
, op
);
8852 if (skip
== MOVE_POS_MATCH_OR_ZV
|| it
->vpos
== to_vpos
)
8857 else if (skip
== MOVE_X_REACHED
&& it
->vpos
!= to_vpos
)
8859 /* We have reached TO_X but not in the line we want. */
8860 skip
= move_it_in_display_line_to (it
, to_charpos
,
8862 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8870 else if (op
& MOVE_TO_Y
)
8872 struct it it_backup
;
8874 if (it
->line_wrap
== WORD_WRAP
)
8875 SAVE_IT (it_backup
, *it
, backup_data
);
8877 /* TO_Y specified means stop at TO_X in the line containing
8878 TO_Y---or at TO_CHARPOS if this is reached first. The
8879 problem is that we can't really tell whether the line
8880 contains TO_Y before we have completely scanned it, and
8881 this may skip past TO_X. What we do is to first scan to
8884 If TO_X is not specified, use a TO_X of zero. The reason
8885 is to make the outcome of this function more predictable.
8886 If we didn't use TO_X == 0, we would stop at the end of
8887 the line which is probably not what a caller would expect
8889 skip
= move_it_in_display_line_to
8890 (it
, to_charpos
, ((op
& MOVE_TO_X
) ? to_x
: 0),
8891 (MOVE_TO_X
| (op
& MOVE_TO_POS
)));
8893 /* If TO_CHARPOS is reached or ZV, we don't have to do more. */
8894 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8896 else if (skip
== MOVE_X_REACHED
)
8898 /* If TO_X was reached, we want to know whether TO_Y is
8899 in the line. We know this is the case if the already
8900 scanned glyphs make the line tall enough. Otherwise,
8901 we must check by scanning the rest of the line. */
8902 line_height
= it
->max_ascent
+ it
->max_descent
;
8903 if (to_y
>= it
->current_y
8904 && to_y
< it
->current_y
+ line_height
)
8909 SAVE_IT (it_backup
, *it
, backup_data
);
8910 TRACE_MOVE ((stderr
, "move_it: from %d\n", IT_CHARPOS (*it
)));
8911 skip2
= move_it_in_display_line_to (it
, to_charpos
, -1,
8913 TRACE_MOVE ((stderr
, "move_it: to %d\n", IT_CHARPOS (*it
)));
8914 line_height
= it
->max_ascent
+ it
->max_descent
;
8915 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8917 if (to_y
>= it
->current_y
8918 && to_y
< it
->current_y
+ line_height
)
8920 /* If TO_Y is in this line and TO_X was reached
8921 above, we scanned too far. We have to restore
8922 IT's settings to the ones before skipping. But
8923 keep the more accurate values of max_ascent and
8924 max_descent we've found while skipping the rest
8925 of the line, for the sake of callers, such as
8926 pos_visible_p, that need to know the line
8928 int max_ascent
= it
->max_ascent
;
8929 int max_descent
= it
->max_descent
;
8931 RESTORE_IT (it
, &it_backup
, backup_data
);
8932 it
->max_ascent
= max_ascent
;
8933 it
->max_descent
= max_descent
;
8939 if (skip
== MOVE_POS_MATCH_OR_ZV
)
8945 /* Check whether TO_Y is in this line. */
8946 line_height
= it
->max_ascent
+ it
->max_descent
;
8947 TRACE_MOVE ((stderr
, "move_it: line_height = %d\n", line_height
));
8949 if (to_y
>= it
->current_y
8950 && to_y
< it
->current_y
+ line_height
)
8952 /* When word-wrap is on, TO_X may lie past the end
8953 of a wrapped line. Then it->current is the
8954 character on the next line, so backtrack to the
8955 space before the wrap point. */
8956 if (skip
== MOVE_LINE_CONTINUED
8957 && it
->line_wrap
== WORD_WRAP
)
8959 int prev_x
= max (it
->current_x
- 1, 0);
8960 RESTORE_IT (it
, &it_backup
, backup_data
);
8961 skip
= move_it_in_display_line_to
8962 (it
, -1, prev_x
, MOVE_TO_X
);
8971 else if (BUFFERP (it
->object
)
8972 && (it
->method
== GET_FROM_BUFFER
8973 || it
->method
== GET_FROM_STRETCH
)
8974 && IT_CHARPOS (*it
) >= to_charpos
8975 /* Under bidi iteration, a call to set_iterator_to_next
8976 can scan far beyond to_charpos if the initial
8977 portion of the next line needs to be reordered. In
8978 that case, give move_it_in_display_line_to another
8981 && it
->bidi_it
.scan_dir
== -1))
8982 skip
= MOVE_POS_MATCH_OR_ZV
;
8984 skip
= move_it_in_display_line_to (it
, to_charpos
, -1, MOVE_TO_POS
);
8988 case MOVE_POS_MATCH_OR_ZV
:
8992 case MOVE_NEWLINE_OR_CR
:
8993 set_iterator_to_next (it
, 1);
8994 it
->continuation_lines_width
= 0;
8997 case MOVE_LINE_TRUNCATED
:
8998 it
->continuation_lines_width
= 0;
8999 reseat_at_next_visible_line_start (it
, 0);
9000 if ((op
& MOVE_TO_POS
) != 0
9001 && IT_CHARPOS (*it
) > to_charpos
)
9008 case MOVE_LINE_CONTINUED
:
9009 /* For continued lines ending in a tab, some of the glyphs
9010 associated with the tab are displayed on the current
9011 line. Since it->current_x does not include these glyphs,
9012 we use it->last_visible_x instead. */
9015 it
->continuation_lines_width
+= it
->last_visible_x
;
9016 /* When moving by vpos, ensure that the iterator really
9017 advances to the next line (bug#847, bug#969). Fixme:
9018 do we need to do this in other circumstances? */
9019 if (it
->current_x
!= it
->last_visible_x
9020 && (op
& MOVE_TO_VPOS
)
9021 && !(op
& (MOVE_TO_X
| MOVE_TO_POS
)))
9023 line_start_x
= it
->current_x
+ it
->pixel_width
9024 - it
->last_visible_x
;
9025 set_iterator_to_next (it
, 0);
9029 it
->continuation_lines_width
+= it
->current_x
;
9036 /* Reset/increment for the next run. */
9037 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
9038 it
->current_x
= line_start_x
;
9041 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9043 last_height
= it
->max_ascent
+ it
->max_descent
;
9044 it
->max_ascent
= it
->max_descent
= 0;
9049 /* On text terminals, we may stop at the end of a line in the middle
9050 of a multi-character glyph. If the glyph itself is continued,
9051 i.e. it is actually displayed on the next line, don't treat this
9052 stopping point as valid; move to the next line instead (unless
9053 that brings us offscreen). */
9054 if (!FRAME_WINDOW_P (it
->f
)
9056 && IT_CHARPOS (*it
) == to_charpos
9057 && it
->what
== IT_CHARACTER
9059 && it
->line_wrap
== WINDOW_WRAP
9060 && it
->current_x
== it
->last_visible_x
- 1
9063 && it
->vpos
< XFASTINT (it
->w
->window_end_vpos
))
9065 it
->continuation_lines_width
+= it
->current_x
;
9066 it
->current_x
= it
->hpos
= it
->max_ascent
= it
->max_descent
= 0;
9067 it
->current_y
+= it
->max_ascent
+ it
->max_descent
;
9069 last_height
= it
->max_ascent
+ it
->max_descent
;
9073 bidi_unshelve_cache (backup_data
, 1);
9075 TRACE_MOVE ((stderr
, "move_it_to: reached %d\n", reached
));
9079 /* Move iterator IT backward by a specified y-distance DY, DY >= 0.
9081 If DY > 0, move IT backward at least that many pixels. DY = 0
9082 means move IT backward to the preceding line start or BEGV. This
9083 function may move over more than DY pixels if IT->current_y - DY
9084 ends up in the middle of a line; in this case IT->current_y will be
9085 set to the top of the line moved to. */
9088 move_it_vertically_backward (struct it
*it
, int dy
)
9092 void *it2data
= NULL
, *it3data
= NULL
;
9093 ptrdiff_t start_pos
;
9095 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9096 ptrdiff_t pos_limit
;
9101 start_pos
= IT_CHARPOS (*it
);
9103 /* Estimate how many newlines we must move back. */
9104 nlines
= max (1, dy
/ default_line_pixel_height (it
->w
));
9105 if (it
->line_wrap
== TRUNCATE
)
9108 pos_limit
= max (start_pos
- nlines
* nchars_per_row
, BEGV
);
9110 /* Set the iterator's position that many lines back. But don't go
9111 back more than NLINES full screen lines -- this wins a day with
9112 buffers which have very long lines. */
9113 while (nlines
-- && IT_CHARPOS (*it
) > pos_limit
)
9114 back_to_previous_visible_line_start (it
);
9116 /* Reseat the iterator here. When moving backward, we don't want
9117 reseat to skip forward over invisible text, set up the iterator
9118 to deliver from overlay strings at the new position etc. So,
9119 use reseat_1 here. */
9120 reseat_1 (it
, it
->current
.pos
, 1);
9122 /* We are now surely at a line start. */
9123 it
->current_x
= it
->hpos
= 0; /* FIXME: this is incorrect when bidi
9124 reordering is in effect. */
9125 it
->continuation_lines_width
= 0;
9127 /* Move forward and see what y-distance we moved. First move to the
9128 start of the next line so that we get its height. We need this
9129 height to be able to tell whether we reached the specified
9131 SAVE_IT (it2
, *it
, it2data
);
9132 it2
.max_ascent
= it2
.max_descent
= 0;
9135 move_it_to (&it2
, start_pos
, -1, -1, it2
.vpos
+ 1,
9136 MOVE_TO_POS
| MOVE_TO_VPOS
);
9138 while (!(IT_POS_VALID_AFTER_MOVE_P (&it2
)
9139 /* If we are in a display string which starts at START_POS,
9140 and that display string includes a newline, and we are
9141 right after that newline (i.e. at the beginning of a
9142 display line), exit the loop, because otherwise we will
9143 infloop, since move_it_to will see that it is already at
9144 START_POS and will not move. */
9145 || (it2
.method
== GET_FROM_STRING
9146 && IT_CHARPOS (it2
) == start_pos
9147 && SREF (it2
.string
, IT_STRING_BYTEPOS (it2
) - 1) == '\n')));
9148 eassert (IT_CHARPOS (*it
) >= BEGV
);
9149 SAVE_IT (it3
, it2
, it3data
);
9151 move_it_to (&it2
, start_pos
, -1, -1, -1, MOVE_TO_POS
);
9152 eassert (IT_CHARPOS (*it
) >= BEGV
);
9153 /* H is the actual vertical distance from the position in *IT
9154 and the starting position. */
9155 h
= it2
.current_y
- it
->current_y
;
9156 /* NLINES is the distance in number of lines. */
9157 nlines
= it2
.vpos
- it
->vpos
;
9159 /* Correct IT's y and vpos position
9160 so that they are relative to the starting point. */
9166 /* DY == 0 means move to the start of the screen line. The
9167 value of nlines is > 0 if continuation lines were involved,
9168 or if the original IT position was at start of a line. */
9169 RESTORE_IT (it
, it
, it2data
);
9171 move_it_by_lines (it
, nlines
);
9172 /* The above code moves us to some position NLINES down,
9173 usually to its first glyph (leftmost in an L2R line), but
9174 that's not necessarily the start of the line, under bidi
9175 reordering. We want to get to the character position
9176 that is immediately after the newline of the previous
9179 && !it
->continuation_lines_width
9180 && !STRINGP (it
->string
)
9181 && IT_CHARPOS (*it
) > BEGV
9182 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9184 ptrdiff_t cp
= IT_CHARPOS (*it
), bp
= IT_BYTEPOS (*it
);
9187 cp
= find_newline_no_quit (cp
, bp
, -1, NULL
);
9188 move_it_to (it
, cp
, -1, -1, -1, MOVE_TO_POS
);
9190 bidi_unshelve_cache (it3data
, 1);
9194 /* The y-position we try to reach, relative to *IT.
9195 Note that H has been subtracted in front of the if-statement. */
9196 int target_y
= it
->current_y
+ h
- dy
;
9197 int y0
= it3
.current_y
;
9201 RESTORE_IT (&it3
, &it3
, it3data
);
9202 y1
= line_bottom_y (&it3
);
9203 line_height
= y1
- y0
;
9204 RESTORE_IT (it
, it
, it2data
);
9205 /* If we did not reach target_y, try to move further backward if
9206 we can. If we moved too far backward, try to move forward. */
9207 if (target_y
< it
->current_y
9208 /* This is heuristic. In a window that's 3 lines high, with
9209 a line height of 13 pixels each, recentering with point
9210 on the bottom line will try to move -39/2 = 19 pixels
9211 backward. Try to avoid moving into the first line. */
9212 && (it
->current_y
- target_y
9213 > min (window_box_height (it
->w
), line_height
* 2 / 3))
9214 && IT_CHARPOS (*it
) > BEGV
)
9216 TRACE_MOVE ((stderr
, " not far enough -> move_vert %d\n",
9217 target_y
- it
->current_y
));
9218 dy
= it
->current_y
- target_y
;
9219 goto move_further_back
;
9221 else if (target_y
>= it
->current_y
+ line_height
9222 && IT_CHARPOS (*it
) < ZV
)
9224 /* Should move forward by at least one line, maybe more.
9226 Note: Calling move_it_by_lines can be expensive on
9227 terminal frames, where compute_motion is used (via
9228 vmotion) to do the job, when there are very long lines
9229 and truncate-lines is nil. That's the reason for
9230 treating terminal frames specially here. */
9232 if (!FRAME_WINDOW_P (it
->f
))
9233 move_it_vertically (it
, target_y
- (it
->current_y
+ line_height
));
9238 move_it_by_lines (it
, 1);
9240 while (target_y
>= line_bottom_y (it
) && IT_CHARPOS (*it
) < ZV
);
9247 /* Move IT by a specified amount of pixel lines DY. DY negative means
9248 move backwards. DY = 0 means move to start of screen line. At the
9249 end, IT will be on the start of a screen line. */
9252 move_it_vertically (struct it
*it
, int dy
)
9255 move_it_vertically_backward (it
, -dy
);
9258 TRACE_MOVE ((stderr
, "move_it_v: from %d, %d\n", IT_CHARPOS (*it
), dy
));
9259 move_it_to (it
, ZV
, -1, it
->current_y
+ dy
, -1,
9260 MOVE_TO_POS
| MOVE_TO_Y
);
9261 TRACE_MOVE ((stderr
, "move_it_v: to %d\n", IT_CHARPOS (*it
)));
9263 /* If buffer ends in ZV without a newline, move to the start of
9264 the line to satisfy the post-condition. */
9265 if (IT_CHARPOS (*it
) == ZV
9267 && FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n')
9268 move_it_by_lines (it
, 0);
9273 /* Move iterator IT past the end of the text line it is in. */
9276 move_it_past_eol (struct it
*it
)
9278 enum move_it_result rc
;
9280 rc
= move_it_in_display_line_to (it
, Z
, 0, MOVE_TO_POS
);
9281 if (rc
== MOVE_NEWLINE_OR_CR
)
9282 set_iterator_to_next (it
, 0);
9286 /* Move IT by a specified number DVPOS of screen lines down. DVPOS
9287 negative means move up. DVPOS == 0 means move to the start of the
9290 Optimization idea: If we would know that IT->f doesn't use
9291 a face with proportional font, we could be faster for
9292 truncate-lines nil. */
9295 move_it_by_lines (struct it
*it
, ptrdiff_t dvpos
)
9298 /* The commented-out optimization uses vmotion on terminals. This
9299 gives bad results, because elements like it->what, on which
9300 callers such as pos_visible_p rely, aren't updated. */
9301 /* struct position pos;
9302 if (!FRAME_WINDOW_P (it->f))
9304 struct text_pos textpos;
9306 pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w);
9307 SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos);
9308 reseat (it, textpos, 1);
9309 it->vpos += pos.vpos;
9310 it->current_y += pos.vpos;
9316 /* DVPOS == 0 means move to the start of the screen line. */
9317 move_it_vertically_backward (it
, 0);
9318 /* Let next call to line_bottom_y calculate real line height */
9323 move_it_to (it
, -1, -1, -1, it
->vpos
+ dvpos
, MOVE_TO_VPOS
);
9324 if (!IT_POS_VALID_AFTER_MOVE_P (it
))
9326 /* Only move to the next buffer position if we ended up in a
9327 string from display property, not in an overlay string
9328 (before-string or after-string). That is because the
9329 latter don't conceal the underlying buffer position, so
9330 we can ask to move the iterator to the exact position we
9331 are interested in. Note that, even if we are already at
9332 IT_CHARPOS (*it), the call below is not a no-op, as it
9333 will detect that we are at the end of the string, pop the
9334 iterator, and compute it->current_x and it->hpos
9336 move_it_to (it
, IT_CHARPOS (*it
) + it
->string_from_display_prop_p
,
9337 -1, -1, -1, MOVE_TO_POS
);
9343 void *it2data
= NULL
;
9344 ptrdiff_t start_charpos
, i
;
9346 = (it
->last_visible_x
- it
->first_visible_x
) / FRAME_COLUMN_WIDTH (it
->f
);
9347 ptrdiff_t pos_limit
;
9349 /* Start at the beginning of the screen line containing IT's
9350 position. This may actually move vertically backwards,
9351 in case of overlays, so adjust dvpos accordingly. */
9353 move_it_vertically_backward (it
, 0);
9356 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9357 screen lines, and reseat the iterator there. */
9358 start_charpos
= IT_CHARPOS (*it
);
9359 if (it
->line_wrap
== TRUNCATE
)
9362 pos_limit
= max (start_charpos
+ dvpos
* nchars_per_row
, BEGV
);
9363 for (i
= -dvpos
; i
> 0 && IT_CHARPOS (*it
) > pos_limit
; --i
)
9364 back_to_previous_visible_line_start (it
);
9365 reseat (it
, it
->current
.pos
, 1);
9367 /* Move further back if we end up in a string or an image. */
9368 while (!IT_POS_VALID_AFTER_MOVE_P (it
))
9370 /* First try to move to start of display line. */
9372 move_it_vertically_backward (it
, 0);
9374 if (IT_POS_VALID_AFTER_MOVE_P (it
))
9376 /* If start of line is still in string or image,
9377 move further back. */
9378 back_to_previous_visible_line_start (it
);
9379 reseat (it
, it
->current
.pos
, 1);
9383 it
->current_x
= it
->hpos
= 0;
9385 /* Above call may have moved too far if continuation lines
9386 are involved. Scan forward and see if it did. */
9387 SAVE_IT (it2
, *it
, it2data
);
9388 it2
.vpos
= it2
.current_y
= 0;
9389 move_it_to (&it2
, start_charpos
, -1, -1, -1, MOVE_TO_POS
);
9390 it
->vpos
-= it2
.vpos
;
9391 it
->current_y
-= it2
.current_y
;
9392 it
->current_x
= it
->hpos
= 0;
9394 /* If we moved too far back, move IT some lines forward. */
9395 if (it2
.vpos
> -dvpos
)
9397 int delta
= it2
.vpos
+ dvpos
;
9399 RESTORE_IT (&it2
, &it2
, it2data
);
9400 SAVE_IT (it2
, *it
, it2data
);
9401 move_it_to (it
, -1, -1, -1, it
->vpos
+ delta
, MOVE_TO_VPOS
);
9402 /* Move back again if we got too far ahead. */
9403 if (IT_CHARPOS (*it
) >= start_charpos
)
9404 RESTORE_IT (it
, &it2
, it2data
);
9406 bidi_unshelve_cache (it2data
, 1);
9409 RESTORE_IT (it
, it
, it2data
);
9413 /* Return 1 if IT points into the middle of a display vector. */
9416 in_display_vector_p (struct it
*it
)
9418 return (it
->method
== GET_FROM_DISPLAY_VECTOR
9419 && it
->current
.dpvec_index
> 0
9420 && it
->dpvec
+ it
->current
.dpvec_index
!= it
->dpend
);
9424 /***********************************************************************
9426 ***********************************************************************/
9429 /* Add a message with format string FORMAT and arguments ARG1 and ARG2
9433 add_to_log (const char *format
, Lisp_Object arg1
, Lisp_Object arg2
)
9435 Lisp_Object args
[3];
9436 Lisp_Object msg
, fmt
;
9439 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
9443 GCPRO4 (fmt
, msg
, arg1
, arg2
);
9445 args
[0] = fmt
= build_string (format
);
9448 msg
= Fformat (3, args
);
9450 len
= SBYTES (msg
) + 1;
9451 buffer
= SAFE_ALLOCA (len
);
9452 memcpy (buffer
, SDATA (msg
), len
);
9454 message_dolog (buffer
, len
- 1, 1, 0);
9461 /* Output a newline in the *Messages* buffer if "needs" one. */
9464 message_log_maybe_newline (void)
9466 if (message_log_need_newline
)
9467 message_dolog ("", 0, 1, 0);
9471 /* Add a string M of length NBYTES to the message log, optionally
9472 terminated with a newline when NLFLAG is true. MULTIBYTE, if
9473 true, means interpret the contents of M as multibyte. This
9474 function calls low-level routines in order to bypass text property
9475 hooks, etc. which might not be safe to run.
9477 This may GC (insert may run before/after change hooks),
9478 so the buffer M must NOT point to a Lisp string. */
9481 message_dolog (const char *m
, ptrdiff_t nbytes
, bool nlflag
, bool multibyte
)
9483 const unsigned char *msg
= (const unsigned char *) m
;
9485 if (!NILP (Vmemory_full
))
9488 if (!NILP (Vmessage_log_max
))
9490 struct buffer
*oldbuf
;
9491 Lisp_Object oldpoint
, oldbegv
, oldzv
;
9492 int old_windows_or_buffers_changed
= windows_or_buffers_changed
;
9493 ptrdiff_t point_at_end
= 0;
9494 ptrdiff_t zv_at_end
= 0;
9495 Lisp_Object old_deactivate_mark
;
9497 struct gcpro gcpro1
;
9499 old_deactivate_mark
= Vdeactivate_mark
;
9500 oldbuf
= current_buffer
;
9501 Fset_buffer (Fget_buffer_create (Vmessages_buffer_name
));
9502 bset_undo_list (current_buffer
, Qt
);
9504 oldpoint
= message_dolog_marker1
;
9505 set_marker_restricted_both (oldpoint
, Qnil
, PT
, PT_BYTE
);
9506 oldbegv
= message_dolog_marker2
;
9507 set_marker_restricted_both (oldbegv
, Qnil
, BEGV
, BEGV_BYTE
);
9508 oldzv
= message_dolog_marker3
;
9509 set_marker_restricted_both (oldzv
, Qnil
, ZV
, ZV_BYTE
);
9510 GCPRO1 (old_deactivate_mark
);
9518 BEGV_BYTE
= BEG_BYTE
;
9521 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9523 /* Insert the string--maybe converting multibyte to single byte
9524 or vice versa, so that all the text fits the buffer. */
9526 && NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9532 /* Convert a multibyte string to single-byte
9533 for the *Message* buffer. */
9534 for (i
= 0; i
< nbytes
; i
+= char_bytes
)
9536 c
= string_char_and_length (msg
+ i
, &char_bytes
);
9537 work
[0] = (ASCII_CHAR_P (c
)
9539 : multibyte_char_to_unibyte (c
));
9540 insert_1_both (work
, 1, 1, 1, 0, 0);
9543 else if (! multibyte
9544 && ! NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
9548 unsigned char str
[MAX_MULTIBYTE_LENGTH
];
9549 /* Convert a single-byte string to multibyte
9550 for the *Message* buffer. */
9551 for (i
= 0; i
< nbytes
; i
++)
9554 MAKE_CHAR_MULTIBYTE (c
);
9555 char_bytes
= CHAR_STRING (c
, str
);
9556 insert_1_both ((char *) str
, 1, char_bytes
, 1, 0, 0);
9560 insert_1_both (m
, chars_in_text (msg
, nbytes
), nbytes
, 1, 0, 0);
9564 ptrdiff_t this_bol
, this_bol_byte
, prev_bol
, prev_bol_byte
;
9567 insert_1_both ("\n", 1, 1, 1, 0, 0);
9569 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9571 this_bol_byte
= PT_BYTE
;
9573 /* See if this line duplicates the previous one.
9574 If so, combine duplicates. */
9577 scan_newline (PT
, PT_BYTE
, BEG
, BEG_BYTE
, -2, 0);
9579 prev_bol_byte
= PT_BYTE
;
9581 dups
= message_log_check_duplicate (prev_bol_byte
,
9585 del_range_both (prev_bol
, prev_bol_byte
,
9586 this_bol
, this_bol_byte
, 0);
9589 char dupstr
[sizeof " [ times]"
9590 + INT_STRLEN_BOUND (printmax_t
)];
9592 /* If you change this format, don't forget to also
9593 change message_log_check_duplicate. */
9594 int duplen
= sprintf (dupstr
, " [%"pMd
" times]", dups
);
9595 TEMP_SET_PT_BOTH (Z
- 1, Z_BYTE
- 1);
9596 insert_1_both (dupstr
, duplen
, duplen
, 1, 0, 1);
9601 /* If we have more than the desired maximum number of lines
9602 in the *Messages* buffer now, delete the oldest ones.
9603 This is safe because we don't have undo in this buffer. */
9605 if (NATNUMP (Vmessage_log_max
))
9607 scan_newline (Z
, Z_BYTE
, BEG
, BEG_BYTE
,
9608 -XFASTINT (Vmessage_log_max
) - 1, 0);
9609 del_range_both (BEG
, BEG_BYTE
, PT
, PT_BYTE
, 0);
9612 BEGV
= marker_position (oldbegv
);
9613 BEGV_BYTE
= marker_byte_position (oldbegv
);
9622 ZV
= marker_position (oldzv
);
9623 ZV_BYTE
= marker_byte_position (oldzv
);
9627 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
9629 /* We can't do Fgoto_char (oldpoint) because it will run some
9631 TEMP_SET_PT_BOTH (marker_position (oldpoint
),
9632 marker_byte_position (oldpoint
));
9635 unchain_marker (XMARKER (oldpoint
));
9636 unchain_marker (XMARKER (oldbegv
));
9637 unchain_marker (XMARKER (oldzv
));
9639 shown
= buffer_window_count (current_buffer
) > 0;
9640 set_buffer_internal (oldbuf
);
9641 /* We called insert_1_both above with its 5th argument (PREPARE)
9642 zero, which prevents insert_1_both from calling
9643 prepare_to_modify_buffer, which in turns prevents us from
9644 incrementing windows_or_buffers_changed even if *Messages* is
9645 shown in some window. So we must manually incrementing
9646 windows_or_buffers_changed here to make up for that. */
9648 windows_or_buffers_changed
++;
9650 windows_or_buffers_changed
= old_windows_or_buffers_changed
;
9651 message_log_need_newline
= !nlflag
;
9652 Vdeactivate_mark
= old_deactivate_mark
;
9657 /* We are at the end of the buffer after just having inserted a newline.
9658 (Note: We depend on the fact we won't be crossing the gap.)
9659 Check to see if the most recent message looks a lot like the previous one.
9660 Return 0 if different, 1 if the new one should just replace it, or a
9661 value N > 1 if we should also append " [N times]". */
9664 message_log_check_duplicate (ptrdiff_t prev_bol_byte
, ptrdiff_t this_bol_byte
)
9667 ptrdiff_t len
= Z_BYTE
- 1 - this_bol_byte
;
9669 unsigned char *p1
= BUF_BYTE_ADDRESS (current_buffer
, prev_bol_byte
);
9670 unsigned char *p2
= BUF_BYTE_ADDRESS (current_buffer
, this_bol_byte
);
9672 for (i
= 0; i
< len
; i
++)
9674 if (i
>= 3 && p1
[i
- 3] == '.' && p1
[i
- 2] == '.' && p1
[i
- 1] == '.')
9682 if (*p1
++ == ' ' && *p1
++ == '[')
9685 intmax_t n
= strtoimax ((char *) p1
, &pend
, 10);
9686 if (0 < n
&& n
< INTMAX_MAX
&& strncmp (pend
, " times]\n", 8) == 0)
9693 /* Display an echo area message M with a specified length of NBYTES
9694 bytes. The string may include null characters. If M is not a
9695 string, clear out any existing message, and let the mini-buffer
9698 This function cancels echoing. */
9701 message3 (Lisp_Object m
)
9703 struct gcpro gcpro1
;
9706 clear_message (1,1);
9709 /* First flush out any partial line written with print. */
9710 message_log_maybe_newline ();
9713 ptrdiff_t nbytes
= SBYTES (m
);
9714 bool multibyte
= STRING_MULTIBYTE (m
);
9716 char *buffer
= SAFE_ALLOCA (nbytes
);
9717 memcpy (buffer
, SDATA (m
), nbytes
);
9718 message_dolog (buffer
, nbytes
, 1, multibyte
);
9727 /* The non-logging version of message3.
9728 This does not cancel echoing, because it is used for echoing.
9729 Perhaps we need to make a separate function for echoing
9730 and make this cancel echoing. */
9733 message3_nolog (Lisp_Object m
)
9735 struct frame
*sf
= SELECTED_FRAME ();
9737 if (FRAME_INITIAL_P (sf
))
9739 if (noninteractive_need_newline
)
9740 putc ('\n', stderr
);
9741 noninteractive_need_newline
= 0;
9743 fwrite (SDATA (m
), SBYTES (m
), 1, stderr
);
9744 if (cursor_in_echo_area
== 0)
9745 fprintf (stderr
, "\n");
9748 /* Error messages get reported properly by cmd_error, so this must be just an
9749 informative message; if the frame hasn't really been initialized yet, just
9751 else if (INTERACTIVE
&& sf
->glyphs_initialized_p
)
9753 /* Get the frame containing the mini-buffer
9754 that the selected frame is using. */
9755 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9756 Lisp_Object frame
= XWINDOW (mini_window
)->frame
;
9757 struct frame
*f
= XFRAME (frame
);
9759 if (FRAME_VISIBLE_P (sf
) && !FRAME_VISIBLE_P (f
))
9760 Fmake_frame_visible (frame
);
9762 if (STRINGP (m
) && SCHARS (m
) > 0)
9765 if (minibuffer_auto_raise
)
9766 Fraise_frame (frame
);
9767 /* Assume we are not echoing.
9768 (If we are, echo_now will override this.) */
9769 echo_message_buffer
= Qnil
;
9772 clear_message (1, 1);
9774 do_pending_window_change (0);
9775 echo_area_display (1);
9776 do_pending_window_change (0);
9777 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
9778 (*FRAME_TERMINAL (f
)->frame_up_to_date_hook
) (f
);
9783 /* Display a null-terminated echo area message M. If M is 0, clear
9784 out any existing message, and let the mini-buffer text show through.
9786 The buffer M must continue to exist until after the echo area gets
9787 cleared or some other message gets displayed there. Do not pass
9788 text that is stored in a Lisp string. Do not pass text in a buffer
9789 that was alloca'd. */
9792 message1 (const char *m
)
9794 message3 (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9798 /* The non-logging counterpart of message1. */
9801 message1_nolog (const char *m
)
9803 message3_nolog (m
? make_unibyte_string (m
, strlen (m
)) : Qnil
);
9806 /* Display a message M which contains a single %s
9807 which gets replaced with STRING. */
9810 message_with_string (const char *m
, Lisp_Object string
, int log
)
9812 CHECK_STRING (string
);
9818 if (noninteractive_need_newline
)
9819 putc ('\n', stderr
);
9820 noninteractive_need_newline
= 0;
9821 fprintf (stderr
, m
, SDATA (string
));
9822 if (!cursor_in_echo_area
)
9823 fprintf (stderr
, "\n");
9827 else if (INTERACTIVE
)
9829 /* The frame whose minibuffer we're going to display the message on.
9830 It may be larger than the selected frame, so we need
9831 to use its buffer, not the selected frame's buffer. */
9832 Lisp_Object mini_window
;
9833 struct frame
*f
, *sf
= SELECTED_FRAME ();
9835 /* Get the frame containing the minibuffer
9836 that the selected frame is using. */
9837 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9838 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9840 /* Error messages get reported properly by cmd_error, so this must be
9841 just an informative message; if the frame hasn't really been
9842 initialized yet, just toss it. */
9843 if (f
->glyphs_initialized_p
)
9845 Lisp_Object args
[2], msg
;
9846 struct gcpro gcpro1
, gcpro2
;
9848 args
[0] = build_string (m
);
9849 args
[1] = msg
= string
;
9850 GCPRO2 (args
[0], msg
);
9853 msg
= Fformat (2, args
);
9858 message3_nolog (msg
);
9862 /* Print should start at the beginning of the message
9863 buffer next time. */
9864 message_buf_print
= 0;
9870 /* Dump an informative message to the minibuf. If M is 0, clear out
9871 any existing message, and let the mini-buffer text show through. */
9874 vmessage (const char *m
, va_list ap
)
9880 if (noninteractive_need_newline
)
9881 putc ('\n', stderr
);
9882 noninteractive_need_newline
= 0;
9883 vfprintf (stderr
, m
, ap
);
9884 if (cursor_in_echo_area
== 0)
9885 fprintf (stderr
, "\n");
9889 else if (INTERACTIVE
)
9891 /* The frame whose mini-buffer we're going to display the message
9892 on. It may be larger than the selected frame, so we need to
9893 use its buffer, not the selected frame's buffer. */
9894 Lisp_Object mini_window
;
9895 struct frame
*f
, *sf
= SELECTED_FRAME ();
9897 /* Get the frame containing the mini-buffer
9898 that the selected frame is using. */
9899 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
9900 f
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
9902 /* Error messages get reported properly by cmd_error, so this must be
9903 just an informative message; if the frame hasn't really been
9904 initialized yet, just toss it. */
9905 if (f
->glyphs_initialized_p
)
9910 ptrdiff_t maxsize
= FRAME_MESSAGE_BUF_SIZE (f
);
9911 char *message_buf
= alloca (maxsize
+ 1);
9913 len
= doprnt (message_buf
, maxsize
, m
, (char *)0, ap
);
9915 message3 (make_string (message_buf
, len
));
9920 /* Print should start at the beginning of the message
9921 buffer next time. */
9922 message_buf_print
= 0;
9928 message (const char *m
, ...)
9938 /* The non-logging version of message. */
9941 message_nolog (const char *m
, ...)
9943 Lisp_Object old_log_max
;
9946 old_log_max
= Vmessage_log_max
;
9947 Vmessage_log_max
= Qnil
;
9949 Vmessage_log_max
= old_log_max
;
9955 /* Display the current message in the current mini-buffer. This is
9956 only called from error handlers in process.c, and is not time
9960 update_echo_area (void)
9962 if (!NILP (echo_area_buffer
[0]))
9965 string
= Fcurrent_message ();
9971 /* Make sure echo area buffers in `echo_buffers' are live.
9972 If they aren't, make new ones. */
9975 ensure_echo_area_buffers (void)
9979 for (i
= 0; i
< 2; ++i
)
9980 if (!BUFFERP (echo_buffer
[i
])
9981 || !BUFFER_LIVE_P (XBUFFER (echo_buffer
[i
])))
9984 Lisp_Object old_buffer
;
9987 old_buffer
= echo_buffer
[i
];
9988 echo_buffer
[i
] = Fget_buffer_create
9989 (make_formatted_string (name
, " *Echo Area %d*", i
));
9990 bset_truncate_lines (XBUFFER (echo_buffer
[i
]), Qnil
);
9991 /* to force word wrap in echo area -
9992 it was decided to postpone this*/
9993 /* XBUFFER (echo_buffer[i])->word_wrap = Qt; */
9995 for (j
= 0; j
< 2; ++j
)
9996 if (EQ (old_buffer
, echo_area_buffer
[j
]))
9997 echo_area_buffer
[j
] = echo_buffer
[i
];
10002 /* Call FN with args A1..A2 with either the current or last displayed
10003 echo_area_buffer as current buffer.
10005 WHICH zero means use the current message buffer
10006 echo_area_buffer[0]. If that is nil, choose a suitable buffer
10007 from echo_buffer[] and clear it.
10009 WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a
10010 suitable buffer from echo_buffer[] and clear it.
10012 If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so
10013 that the current message becomes the last displayed one, make
10014 choose a suitable buffer for echo_area_buffer[0], and clear it.
10016 Value is what FN returns. */
10019 with_echo_area_buffer (struct window
*w
, int which
,
10020 int (*fn
) (ptrdiff_t, Lisp_Object
),
10021 ptrdiff_t a1
, Lisp_Object a2
)
10023 Lisp_Object buffer
;
10024 int this_one
, the_other
, clear_buffer_p
, rc
;
10025 ptrdiff_t count
= SPECPDL_INDEX ();
10027 /* If buffers aren't live, make new ones. */
10028 ensure_echo_area_buffers ();
10030 clear_buffer_p
= 0;
10033 this_one
= 0, the_other
= 1;
10034 else if (which
> 0)
10035 this_one
= 1, the_other
= 0;
10038 this_one
= 0, the_other
= 1;
10039 clear_buffer_p
= 1;
10041 /* We need a fresh one in case the current echo buffer equals
10042 the one containing the last displayed echo area message. */
10043 if (!NILP (echo_area_buffer
[this_one
])
10044 && EQ (echo_area_buffer
[this_one
], echo_area_buffer
[the_other
]))
10045 echo_area_buffer
[this_one
] = Qnil
;
10048 /* Choose a suitable buffer from echo_buffer[] is we don't
10050 if (NILP (echo_area_buffer
[this_one
]))
10052 echo_area_buffer
[this_one
]
10053 = (EQ (echo_area_buffer
[the_other
], echo_buffer
[this_one
])
10054 ? echo_buffer
[the_other
]
10055 : echo_buffer
[this_one
]);
10056 clear_buffer_p
= 1;
10059 buffer
= echo_area_buffer
[this_one
];
10061 /* Don't get confused by reusing the buffer used for echoing
10062 for a different purpose. */
10063 if (echo_kboard
== NULL
&& EQ (buffer
, echo_message_buffer
))
10066 record_unwind_protect (unwind_with_echo_area_buffer
,
10067 with_echo_area_buffer_unwind_data (w
));
10069 /* Make the echo area buffer current. Note that for display
10070 purposes, it is not necessary that the displayed window's buffer
10071 == current_buffer, except for text property lookup. So, let's
10072 only set that buffer temporarily here without doing a full
10073 Fset_window_buffer. We must also change w->pointm, though,
10074 because otherwise an assertions in unshow_buffer fails, and Emacs
10076 set_buffer_internal_1 (XBUFFER (buffer
));
10079 wset_buffer (w
, buffer
);
10080 set_marker_both (w
->pointm
, buffer
, BEG
, BEG_BYTE
);
10083 bset_undo_list (current_buffer
, Qt
);
10084 bset_read_only (current_buffer
, Qnil
);
10085 specbind (Qinhibit_read_only
, Qt
);
10086 specbind (Qinhibit_modification_hooks
, Qt
);
10088 if (clear_buffer_p
&& Z
> BEG
)
10089 del_range (BEG
, Z
);
10091 eassert (BEGV
>= BEG
);
10092 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10096 eassert (BEGV
>= BEG
);
10097 eassert (ZV
<= Z
&& ZV
>= BEGV
);
10099 unbind_to (count
, Qnil
);
10104 /* Save state that should be preserved around the call to the function
10105 FN called in with_echo_area_buffer. */
10108 with_echo_area_buffer_unwind_data (struct window
*w
)
10111 Lisp_Object vector
, tmp
;
10113 /* Reduce consing by keeping one vector in
10114 Vwith_echo_area_save_vector. */
10115 vector
= Vwith_echo_area_save_vector
;
10116 Vwith_echo_area_save_vector
= Qnil
;
10119 vector
= Fmake_vector (make_number (9), Qnil
);
10121 XSETBUFFER (tmp
, current_buffer
); ASET (vector
, i
, tmp
); ++i
;
10122 ASET (vector
, i
, Vdeactivate_mark
); ++i
;
10123 ASET (vector
, i
, make_number (windows_or_buffers_changed
)); ++i
;
10127 XSETWINDOW (tmp
, w
); ASET (vector
, i
, tmp
); ++i
;
10128 ASET (vector
, i
, w
->contents
); ++i
;
10129 ASET (vector
, i
, make_number (marker_position (w
->pointm
))); ++i
;
10130 ASET (vector
, i
, make_number (marker_byte_position (w
->pointm
))); ++i
;
10131 ASET (vector
, i
, make_number (marker_position (w
->start
))); ++i
;
10132 ASET (vector
, i
, make_number (marker_byte_position (w
->start
))); ++i
;
10137 for (; i
< end
; ++i
)
10138 ASET (vector
, i
, Qnil
);
10141 eassert (i
== ASIZE (vector
));
10146 /* Restore global state from VECTOR which was created by
10147 with_echo_area_buffer_unwind_data. */
10150 unwind_with_echo_area_buffer (Lisp_Object vector
)
10152 set_buffer_internal_1 (XBUFFER (AREF (vector
, 0)));
10153 Vdeactivate_mark
= AREF (vector
, 1);
10154 windows_or_buffers_changed
= XFASTINT (AREF (vector
, 2));
10156 if (WINDOWP (AREF (vector
, 3)))
10159 Lisp_Object buffer
;
10161 w
= XWINDOW (AREF (vector
, 3));
10162 buffer
= AREF (vector
, 4);
10164 wset_buffer (w
, buffer
);
10165 set_marker_both (w
->pointm
, buffer
,
10166 XFASTINT (AREF (vector
, 5)),
10167 XFASTINT (AREF (vector
, 6)));
10168 set_marker_both (w
->start
, buffer
,
10169 XFASTINT (AREF (vector
, 7)),
10170 XFASTINT (AREF (vector
, 8)));
10173 Vwith_echo_area_save_vector
= vector
;
10178 /* Set up the echo area for use by print functions. MULTIBYTE_P
10179 non-zero means we will print multibyte. */
10182 setup_echo_area_for_printing (int multibyte_p
)
10184 /* If we can't find an echo area any more, exit. */
10185 if (! FRAME_LIVE_P (XFRAME (selected_frame
)))
10186 Fkill_emacs (Qnil
);
10188 ensure_echo_area_buffers ();
10190 if (!message_buf_print
)
10192 /* A message has been output since the last time we printed.
10193 Choose a fresh echo area buffer. */
10194 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10195 echo_area_buffer
[0] = echo_buffer
[1];
10197 echo_area_buffer
[0] = echo_buffer
[0];
10199 /* Switch to that buffer and clear it. */
10200 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10201 bset_truncate_lines (current_buffer
, Qnil
);
10205 ptrdiff_t count
= SPECPDL_INDEX ();
10206 specbind (Qinhibit_read_only
, Qt
);
10207 /* Note that undo recording is always disabled. */
10208 del_range (BEG
, Z
);
10209 unbind_to (count
, Qnil
);
10211 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10213 /* Set up the buffer for the multibyteness we need. */
10215 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10216 Fset_buffer_multibyte (multibyte_p
? Qt
: Qnil
);
10218 /* Raise the frame containing the echo area. */
10219 if (minibuffer_auto_raise
)
10221 struct frame
*sf
= SELECTED_FRAME ();
10222 Lisp_Object mini_window
;
10223 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10224 Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window
)));
10227 message_log_maybe_newline ();
10228 message_buf_print
= 1;
10232 if (NILP (echo_area_buffer
[0]))
10234 if (EQ (echo_area_buffer
[1], echo_buffer
[0]))
10235 echo_area_buffer
[0] = echo_buffer
[1];
10237 echo_area_buffer
[0] = echo_buffer
[0];
10240 if (current_buffer
!= XBUFFER (echo_area_buffer
[0]))
10242 /* Someone switched buffers between print requests. */
10243 set_buffer_internal (XBUFFER (echo_area_buffer
[0]));
10244 bset_truncate_lines (current_buffer
, Qnil
);
10250 /* Display an echo area message in window W. Value is non-zero if W's
10251 height is changed. If display_last_displayed_message_p is
10252 non-zero, display the message that was last displayed, otherwise
10253 display the current message. */
10256 display_echo_area (struct window
*w
)
10258 int i
, no_message_p
, window_height_changed_p
;
10260 /* Temporarily disable garbage collections while displaying the echo
10261 area. This is done because a GC can print a message itself.
10262 That message would modify the echo area buffer's contents while a
10263 redisplay of the buffer is going on, and seriously confuse
10265 ptrdiff_t count
= inhibit_garbage_collection ();
10267 /* If there is no message, we must call display_echo_area_1
10268 nevertheless because it resizes the window. But we will have to
10269 reset the echo_area_buffer in question to nil at the end because
10270 with_echo_area_buffer will sets it to an empty buffer. */
10271 i
= display_last_displayed_message_p
? 1 : 0;
10272 no_message_p
= NILP (echo_area_buffer
[i
]);
10274 window_height_changed_p
10275 = with_echo_area_buffer (w
, display_last_displayed_message_p
,
10276 display_echo_area_1
,
10277 (intptr_t) w
, Qnil
);
10280 echo_area_buffer
[i
] = Qnil
;
10282 unbind_to (count
, Qnil
);
10283 return window_height_changed_p
;
10287 /* Helper for display_echo_area. Display the current buffer which
10288 contains the current echo area message in window W, a mini-window,
10289 a pointer to which is passed in A1. A2..A4 are currently not used.
10290 Change the height of W so that all of the message is displayed.
10291 Value is non-zero if height of W was changed. */
10294 display_echo_area_1 (ptrdiff_t a1
, Lisp_Object a2
)
10297 struct window
*w
= (struct window
*) i1
;
10298 Lisp_Object window
;
10299 struct text_pos start
;
10300 int window_height_changed_p
= 0;
10302 /* Do this before displaying, so that we have a large enough glyph
10303 matrix for the display. If we can't get enough space for the
10304 whole text, display the last N lines. That works by setting w->start. */
10305 window_height_changed_p
= resize_mini_window (w
, 0);
10307 /* Use the starting position chosen by resize_mini_window. */
10308 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
10311 clear_glyph_matrix (w
->desired_matrix
);
10312 XSETWINDOW (window
, w
);
10313 try_window (window
, start
, 0);
10315 return window_height_changed_p
;
10319 /* Resize the echo area window to exactly the size needed for the
10320 currently displayed message, if there is one. If a mini-buffer
10321 is active, don't shrink it. */
10324 resize_echo_area_exactly (void)
10326 if (BUFFERP (echo_area_buffer
[0])
10327 && WINDOWP (echo_area_window
))
10329 struct window
*w
= XWINDOW (echo_area_window
);
10331 Lisp_Object resize_exactly
;
10333 if (minibuf_level
== 0)
10334 resize_exactly
= Qt
;
10336 resize_exactly
= Qnil
;
10338 resized_p
= with_echo_area_buffer (w
, 0, resize_mini_window_1
,
10339 (intptr_t) w
, resize_exactly
);
10342 ++windows_or_buffers_changed
;
10343 ++update_mode_lines
;
10344 redisplay_internal ();
10350 /* Callback function for with_echo_area_buffer, when used from
10351 resize_echo_area_exactly. A1 contains a pointer to the window to
10352 resize, EXACTLY non-nil means resize the mini-window exactly to the
10353 size of the text displayed. A3 and A4 are not used. Value is what
10354 resize_mini_window returns. */
10357 resize_mini_window_1 (ptrdiff_t a1
, Lisp_Object exactly
)
10360 return resize_mini_window ((struct window
*) i1
, !NILP (exactly
));
10364 /* Resize mini-window W to fit the size of its contents. EXACT_P
10365 means size the window exactly to the size needed. Otherwise, it's
10366 only enlarged until W's buffer is empty.
10368 Set W->start to the right place to begin display. If the whole
10369 contents fit, start at the beginning. Otherwise, start so as
10370 to make the end of the contents appear. This is particularly
10371 important for y-or-n-p, but seems desirable generally.
10373 Value is non-zero if the window height has been changed. */
10376 resize_mini_window (struct window
*w
, int exact_p
)
10378 struct frame
*f
= XFRAME (w
->frame
);
10379 int window_height_changed_p
= 0;
10381 eassert (MINI_WINDOW_P (w
));
10383 /* By default, start display at the beginning. */
10384 set_marker_both (w
->start
, w
->contents
,
10385 BUF_BEGV (XBUFFER (w
->contents
)),
10386 BUF_BEGV_BYTE (XBUFFER (w
->contents
)));
10388 /* Don't resize windows while redisplaying a window; it would
10389 confuse redisplay functions when the size of the window they are
10390 displaying changes from under them. Such a resizing can happen,
10391 for instance, when which-func prints a long message while
10392 we are running fontification-functions. We're running these
10393 functions with safe_call which binds inhibit-redisplay to t. */
10394 if (!NILP (Vinhibit_redisplay
))
10397 /* Nil means don't try to resize. */
10398 if (NILP (Vresize_mini_windows
)
10399 || (FRAME_X_P (f
) && FRAME_X_OUTPUT (f
) == NULL
))
10402 if (!FRAME_MINIBUF_ONLY_P (f
))
10405 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
10406 int total_height
= WINDOW_TOTAL_LINES (root
) + WINDOW_TOTAL_LINES (w
);
10408 EMACS_INT max_height
;
10409 int unit
= FRAME_LINE_HEIGHT (f
);
10410 struct text_pos start
;
10411 struct buffer
*old_current_buffer
= NULL
;
10413 if (current_buffer
!= XBUFFER (w
->contents
))
10415 old_current_buffer
= current_buffer
;
10416 set_buffer_internal (XBUFFER (w
->contents
));
10419 init_iterator (&it
, w
, BEGV
, BEGV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10421 /* Compute the max. number of lines specified by the user. */
10422 if (FLOATP (Vmax_mini_window_height
))
10423 max_height
= XFLOATINT (Vmax_mini_window_height
) * FRAME_LINES (f
);
10424 else if (INTEGERP (Vmax_mini_window_height
))
10425 max_height
= XINT (Vmax_mini_window_height
);
10427 max_height
= total_height
/ 4;
10429 /* Correct that max. height if it's bogus. */
10430 max_height
= clip_to_bounds (1, max_height
, total_height
);
10432 /* Find out the height of the text in the window. */
10433 if (it
.line_wrap
== TRUNCATE
)
10438 move_it_to (&it
, ZV
, -1, -1, -1, MOVE_TO_POS
);
10439 if (it
.max_ascent
== 0 && it
.max_descent
== 0)
10440 height
= it
.current_y
+ last_height
;
10442 height
= it
.current_y
+ it
.max_ascent
+ it
.max_descent
;
10443 height
-= min (it
.extra_line_spacing
, it
.max_extra_line_spacing
);
10444 height
= (height
+ unit
- 1) / unit
;
10447 /* Compute a suitable window start. */
10448 if (height
> max_height
)
10450 height
= max_height
;
10451 init_iterator (&it
, w
, ZV
, ZV_BYTE
, NULL
, DEFAULT_FACE_ID
);
10452 move_it_vertically_backward (&it
, (height
- 1) * unit
);
10453 start
= it
.current
.pos
;
10456 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
10457 SET_MARKER_FROM_TEXT_POS (w
->start
, start
);
10459 if (EQ (Vresize_mini_windows
, Qgrow_only
))
10461 /* Let it grow only, until we display an empty message, in which
10462 case the window shrinks again. */
10463 if (height
> WINDOW_TOTAL_LINES (w
))
10465 int old_height
= WINDOW_TOTAL_LINES (w
);
10466 freeze_window_starts (f
, 1);
10467 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10468 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10470 else if (height
< WINDOW_TOTAL_LINES (w
)
10471 && (exact_p
|| BEGV
== ZV
))
10473 int old_height
= WINDOW_TOTAL_LINES (w
);
10474 freeze_window_starts (f
, 0);
10475 shrink_mini_window (w
);
10476 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10481 /* Always resize to exact size needed. */
10482 if (height
> WINDOW_TOTAL_LINES (w
))
10484 int old_height
= WINDOW_TOTAL_LINES (w
);
10485 freeze_window_starts (f
, 1);
10486 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10487 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10489 else if (height
< WINDOW_TOTAL_LINES (w
))
10491 int old_height
= WINDOW_TOTAL_LINES (w
);
10492 freeze_window_starts (f
, 0);
10493 shrink_mini_window (w
);
10497 freeze_window_starts (f
, 1);
10498 grow_mini_window (w
, height
- WINDOW_TOTAL_LINES (w
));
10501 window_height_changed_p
= WINDOW_TOTAL_LINES (w
) != old_height
;
10505 if (old_current_buffer
)
10506 set_buffer_internal (old_current_buffer
);
10509 return window_height_changed_p
;
10513 /* Value is the current message, a string, or nil if there is no
10514 current message. */
10517 current_message (void)
10521 if (!BUFFERP (echo_area_buffer
[0]))
10525 with_echo_area_buffer (0, 0, current_message_1
,
10526 (intptr_t) &msg
, Qnil
);
10528 echo_area_buffer
[0] = Qnil
;
10536 current_message_1 (ptrdiff_t a1
, Lisp_Object a2
)
10539 Lisp_Object
*msg
= (Lisp_Object
*) i1
;
10542 *msg
= make_buffer_string (BEG
, Z
, 1);
10549 /* Push the current message on Vmessage_stack for later restoration
10550 by restore_message. Value is non-zero if the current message isn't
10551 empty. This is a relatively infrequent operation, so it's not
10552 worth optimizing. */
10555 push_message (void)
10557 Lisp_Object msg
= current_message ();
10558 Vmessage_stack
= Fcons (msg
, Vmessage_stack
);
10559 return STRINGP (msg
);
10563 /* Restore message display from the top of Vmessage_stack. */
10566 restore_message (void)
10568 eassert (CONSP (Vmessage_stack
));
10569 message3_nolog (XCAR (Vmessage_stack
));
10573 /* Handler for record_unwind_protect calling pop_message. */
10576 pop_message_unwind (Lisp_Object dummy
)
10582 /* Pop the top-most entry off Vmessage_stack. */
10587 eassert (CONSP (Vmessage_stack
));
10588 Vmessage_stack
= XCDR (Vmessage_stack
);
10592 /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs
10593 exits. If the stack is not empty, we have a missing pop_message
10597 check_message_stack (void)
10599 if (!NILP (Vmessage_stack
))
10604 /* Truncate to NCHARS what will be displayed in the echo area the next
10605 time we display it---but don't redisplay it now. */
10608 truncate_echo_area (ptrdiff_t nchars
)
10611 echo_area_buffer
[0] = Qnil
;
10612 else if (!noninteractive
10614 && !NILP (echo_area_buffer
[0]))
10616 struct frame
*sf
= SELECTED_FRAME ();
10617 /* Error messages get reported properly by cmd_error, so this must be
10618 just an informative message; if the frame hasn't really been
10619 initialized yet, just toss it. */
10620 if (sf
->glyphs_initialized_p
)
10621 with_echo_area_buffer (0, 0, truncate_message_1
, nchars
, Qnil
);
10626 /* Helper function for truncate_echo_area. Truncate the current
10627 message to at most NCHARS characters. */
10630 truncate_message_1 (ptrdiff_t nchars
, Lisp_Object a2
)
10632 if (BEG
+ nchars
< Z
)
10633 del_range (BEG
+ nchars
, Z
);
10635 echo_area_buffer
[0] = Qnil
;
10639 /* Set the current message to STRING. */
10642 set_message (Lisp_Object string
)
10644 eassert (STRINGP (string
));
10646 message_enable_multibyte
= STRING_MULTIBYTE (string
);
10648 with_echo_area_buffer (0, -1, set_message_1
, 0, string
);
10649 message_buf_print
= 0;
10650 help_echo_showing_p
= 0;
10652 if (STRINGP (Vdebug_on_message
)
10653 && STRINGP (string
)
10654 && fast_string_match (Vdebug_on_message
, string
) >= 0)
10655 call_debugger (list2 (Qerror
, string
));
10659 /* Helper function for set_message. First argument is ignored and second
10660 argument has the same meaning as for set_message.
10661 This function is called with the echo area buffer being current. */
10664 set_message_1 (ptrdiff_t a1
, Lisp_Object string
)
10666 eassert (STRINGP (string
));
10668 /* Change multibyteness of the echo buffer appropriately. */
10669 if (message_enable_multibyte
10670 != !NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
10671 Fset_buffer_multibyte (message_enable_multibyte
? Qt
: Qnil
);
10673 bset_truncate_lines (current_buffer
, message_truncate_lines
? Qt
: Qnil
);
10674 if (!NILP (BVAR (current_buffer
, bidi_display_reordering
)))
10675 bset_bidi_paragraph_direction (current_buffer
, Qleft_to_right
);
10677 /* Insert new message at BEG. */
10678 TEMP_SET_PT_BOTH (BEG
, BEG_BYTE
);
10680 /* This function takes care of single/multibyte conversion.
10681 We just have to ensure that the echo area buffer has the right
10682 setting of enable_multibyte_characters. */
10683 insert_from_string (string
, 0, 0, SCHARS (string
), SBYTES (string
), 1);
10689 /* Clear messages. CURRENT_P non-zero means clear the current
10690 message. LAST_DISPLAYED_P non-zero means clear the message
10694 clear_message (int current_p
, int last_displayed_p
)
10698 echo_area_buffer
[0] = Qnil
;
10699 message_cleared_p
= 1;
10702 if (last_displayed_p
)
10703 echo_area_buffer
[1] = Qnil
;
10705 message_buf_print
= 0;
10708 /* Clear garbaged frames.
10710 This function is used where the old redisplay called
10711 redraw_garbaged_frames which in turn called redraw_frame which in
10712 turn called clear_frame. The call to clear_frame was a source of
10713 flickering. I believe a clear_frame is not necessary. It should
10714 suffice in the new redisplay to invalidate all current matrices,
10715 and ensure a complete redisplay of all windows. */
10718 clear_garbaged_frames (void)
10720 if (frame_garbaged
)
10722 Lisp_Object tail
, frame
;
10723 int changed_count
= 0;
10725 FOR_EACH_FRAME (tail
, frame
)
10727 struct frame
*f
= XFRAME (frame
);
10729 if (FRAME_VISIBLE_P (f
) && FRAME_GARBAGED_P (f
))
10734 f
->force_flush_display_p
= 1;
10736 clear_current_matrices (f
);
10743 frame_garbaged
= 0;
10745 ++windows_or_buffers_changed
;
10750 /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P
10751 is non-zero update selected_frame. Value is non-zero if the
10752 mini-windows height has been changed. */
10755 echo_area_display (int update_frame_p
)
10757 Lisp_Object mini_window
;
10760 int window_height_changed_p
= 0;
10761 struct frame
*sf
= SELECTED_FRAME ();
10763 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
10764 w
= XWINDOW (mini_window
);
10765 f
= XFRAME (WINDOW_FRAME (w
));
10767 /* Don't display if frame is invisible or not yet initialized. */
10768 if (!FRAME_VISIBLE_P (f
) || !f
->glyphs_initialized_p
)
10771 #ifdef HAVE_WINDOW_SYSTEM
10772 /* When Emacs starts, selected_frame may be the initial terminal
10773 frame. If we let this through, a message would be displayed on
10775 if (FRAME_INITIAL_P (XFRAME (selected_frame
)))
10777 #endif /* HAVE_WINDOW_SYSTEM */
10779 /* Redraw garbaged frames. */
10780 clear_garbaged_frames ();
10782 if (!NILP (echo_area_buffer
[0]) || minibuf_level
== 0)
10784 echo_area_window
= mini_window
;
10785 window_height_changed_p
= display_echo_area (w
);
10786 w
->must_be_updated_p
= 1;
10788 /* Update the display, unless called from redisplay_internal.
10789 Also don't update the screen during redisplay itself. The
10790 update will happen at the end of redisplay, and an update
10791 here could cause confusion. */
10792 if (update_frame_p
&& !redisplaying_p
)
10796 /* If the display update has been interrupted by pending
10797 input, update mode lines in the frame. Due to the
10798 pending input, it might have been that redisplay hasn't
10799 been called, so that mode lines above the echo area are
10800 garbaged. This looks odd, so we prevent it here. */
10801 if (!display_completed
)
10802 n
= redisplay_mode_lines (FRAME_ROOT_WINDOW (f
), 0);
10804 if (window_height_changed_p
10805 /* Don't do this if Emacs is shutting down. Redisplay
10806 needs to run hooks. */
10807 && !NILP (Vrun_hooks
))
10809 /* Must update other windows. Likewise as in other
10810 cases, don't let this update be interrupted by
10812 ptrdiff_t count
= SPECPDL_INDEX ();
10813 specbind (Qredisplay_dont_pause
, Qt
);
10814 windows_or_buffers_changed
= 1;
10815 redisplay_internal ();
10816 unbind_to (count
, Qnil
);
10818 else if (FRAME_WINDOW_P (f
) && n
== 0)
10820 /* Window configuration is the same as before.
10821 Can do with a display update of the echo area,
10822 unless we displayed some mode lines. */
10823 update_single_window (w
, 1);
10824 FRAME_RIF (f
)->flush_display (f
);
10827 update_frame (f
, 1, 1);
10829 /* If cursor is in the echo area, make sure that the next
10830 redisplay displays the minibuffer, so that the cursor will
10831 be replaced with what the minibuffer wants. */
10832 if (cursor_in_echo_area
)
10833 ++windows_or_buffers_changed
;
10836 else if (!EQ (mini_window
, selected_window
))
10837 windows_or_buffers_changed
++;
10839 /* Last displayed message is now the current message. */
10840 echo_area_buffer
[1] = echo_area_buffer
[0];
10841 /* Inform read_char that we're not echoing. */
10842 echo_message_buffer
= Qnil
;
10844 /* Prevent redisplay optimization in redisplay_internal by resetting
10845 this_line_start_pos. This is done because the mini-buffer now
10846 displays the message instead of its buffer text. */
10847 if (EQ (mini_window
, selected_window
))
10848 CHARPOS (this_line_start_pos
) = 0;
10850 return window_height_changed_p
;
10853 /* Nonzero if the current window's buffer is shown in more than one
10854 window and was modified since last redisplay. */
10857 buffer_shared_and_changed (void)
10859 return (buffer_window_count (current_buffer
) > 1
10860 && UNCHANGED_MODIFIED
< MODIFF
);
10863 /* Nonzero if W doesn't reflect the actual state of current buffer due
10864 to its text or overlays change. FIXME: this may be called when
10865 XBUFFER (w->contents) != current_buffer, which looks suspicious. */
10868 window_outdated (struct window
*w
)
10870 return (w
->last_modified
< MODIFF
10871 || w
->last_overlay_modified
< OVERLAY_MODIFF
);
10874 /* Nonzero if W's buffer was changed but not saved or Transient Mark mode
10875 is enabled and mark of W's buffer was changed since last W's update. */
10878 window_buffer_changed (struct window
*w
)
10880 struct buffer
*b
= XBUFFER (w
->contents
);
10882 eassert (BUFFER_LIVE_P (b
));
10884 return (((BUF_SAVE_MODIFF (b
) < BUF_MODIFF (b
)) != w
->last_had_star
)
10885 || ((!NILP (Vtransient_mark_mode
) && !NILP (BVAR (b
, mark_active
)))
10886 != (w
->region_showing
!= 0)));
10889 /* Nonzero if W has %c in its mode line and mode line should be updated. */
10892 mode_line_update_needed (struct window
*w
)
10894 return (w
->column_number_displayed
!= -1
10895 && !(PT
== w
->last_point
&& !window_outdated (w
))
10896 && (w
->column_number_displayed
!= current_column ()));
10899 /***********************************************************************
10900 Mode Lines and Frame Titles
10901 ***********************************************************************/
10903 /* A buffer for constructing non-propertized mode-line strings and
10904 frame titles in it; allocated from the heap in init_xdisp and
10905 resized as needed in store_mode_line_noprop_char. */
10907 static char *mode_line_noprop_buf
;
10909 /* The buffer's end, and a current output position in it. */
10911 static char *mode_line_noprop_buf_end
;
10912 static char *mode_line_noprop_ptr
;
10914 #define MODE_LINE_NOPROP_LEN(start) \
10915 ((mode_line_noprop_ptr - mode_line_noprop_buf) - start)
10918 MODE_LINE_DISPLAY
= 0,
10922 } mode_line_target
;
10924 /* Alist that caches the results of :propertize.
10925 Each element is (PROPERTIZED-STRING . PROPERTY-LIST). */
10926 static Lisp_Object mode_line_proptrans_alist
;
10928 /* List of strings making up the mode-line. */
10929 static Lisp_Object mode_line_string_list
;
10931 /* Base face property when building propertized mode line string. */
10932 static Lisp_Object mode_line_string_face
;
10933 static Lisp_Object mode_line_string_face_prop
;
10936 /* Unwind data for mode line strings */
10938 static Lisp_Object Vmode_line_unwind_vector
;
10941 format_mode_line_unwind_data (struct frame
*target_frame
,
10942 struct buffer
*obuf
,
10944 int save_proptrans
)
10946 Lisp_Object vector
, tmp
;
10948 /* Reduce consing by keeping one vector in
10949 Vwith_echo_area_save_vector. */
10950 vector
= Vmode_line_unwind_vector
;
10951 Vmode_line_unwind_vector
= Qnil
;
10954 vector
= Fmake_vector (make_number (10), Qnil
);
10956 ASET (vector
, 0, make_number (mode_line_target
));
10957 ASET (vector
, 1, make_number (MODE_LINE_NOPROP_LEN (0)));
10958 ASET (vector
, 2, mode_line_string_list
);
10959 ASET (vector
, 3, save_proptrans
? mode_line_proptrans_alist
: Qt
);
10960 ASET (vector
, 4, mode_line_string_face
);
10961 ASET (vector
, 5, mode_line_string_face_prop
);
10964 XSETBUFFER (tmp
, obuf
);
10967 ASET (vector
, 6, tmp
);
10968 ASET (vector
, 7, owin
);
10971 /* Similarly to `with-selected-window', if the operation selects
10972 a window on another frame, we must restore that frame's
10973 selected window, and (for a tty) the top-frame. */
10974 ASET (vector
, 8, target_frame
->selected_window
);
10975 if (FRAME_TERMCAP_P (target_frame
))
10976 ASET (vector
, 9, FRAME_TTY (target_frame
)->top_frame
);
10983 unwind_format_mode_line (Lisp_Object vector
)
10985 Lisp_Object old_window
= AREF (vector
, 7);
10986 Lisp_Object target_frame_window
= AREF (vector
, 8);
10987 Lisp_Object old_top_frame
= AREF (vector
, 9);
10989 mode_line_target
= XINT (AREF (vector
, 0));
10990 mode_line_noprop_ptr
= mode_line_noprop_buf
+ XINT (AREF (vector
, 1));
10991 mode_line_string_list
= AREF (vector
, 2);
10992 if (! EQ (AREF (vector
, 3), Qt
))
10993 mode_line_proptrans_alist
= AREF (vector
, 3);
10994 mode_line_string_face
= AREF (vector
, 4);
10995 mode_line_string_face_prop
= AREF (vector
, 5);
10997 /* Select window before buffer, since it may change the buffer. */
10998 if (!NILP (old_window
))
11000 /* If the operation that we are unwinding had selected a window
11001 on a different frame, reset its frame-selected-window. For a
11002 text terminal, reset its top-frame if necessary. */
11003 if (!NILP (target_frame_window
))
11006 = WINDOW_FRAME (XWINDOW (target_frame_window
));
11008 if (!EQ (frame
, WINDOW_FRAME (XWINDOW (old_window
))))
11009 Fselect_window (target_frame_window
, Qt
);
11011 if (!NILP (old_top_frame
) && !EQ (old_top_frame
, frame
))
11012 Fselect_frame (old_top_frame
, Qt
);
11015 Fselect_window (old_window
, Qt
);
11018 if (!NILP (AREF (vector
, 6)))
11020 set_buffer_internal_1 (XBUFFER (AREF (vector
, 6)));
11021 ASET (vector
, 6, Qnil
);
11024 Vmode_line_unwind_vector
= vector
;
11029 /* Store a single character C for the frame title in mode_line_noprop_buf.
11030 Re-allocate mode_line_noprop_buf if necessary. */
11033 store_mode_line_noprop_char (char c
)
11035 /* If output position has reached the end of the allocated buffer,
11036 increase the buffer's size. */
11037 if (mode_line_noprop_ptr
== mode_line_noprop_buf_end
)
11039 ptrdiff_t len
= MODE_LINE_NOPROP_LEN (0);
11040 ptrdiff_t size
= len
;
11041 mode_line_noprop_buf
=
11042 xpalloc (mode_line_noprop_buf
, &size
, 1, STRING_BYTES_BOUND
, 1);
11043 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
11044 mode_line_noprop_ptr
= mode_line_noprop_buf
+ len
;
11047 *mode_line_noprop_ptr
++ = c
;
11051 /* Store part of a frame title in mode_line_noprop_buf, beginning at
11052 mode_line_noprop_ptr. STRING is the string to store. Do not copy
11053 characters that yield more columns than PRECISION; PRECISION <= 0
11054 means copy the whole string. Pad with spaces until FIELD_WIDTH
11055 number of characters have been copied; FIELD_WIDTH <= 0 means don't
11056 pad. Called from display_mode_element when it is used to build a
11060 store_mode_line_noprop (const char *string
, int field_width
, int precision
)
11062 const unsigned char *str
= (const unsigned char *) string
;
11064 ptrdiff_t dummy
, nbytes
;
11066 /* Copy at most PRECISION chars from STR. */
11067 nbytes
= strlen (string
);
11068 n
+= c_string_width (str
, nbytes
, precision
, &dummy
, &nbytes
);
11070 store_mode_line_noprop_char (*str
++);
11072 /* Fill up with spaces until FIELD_WIDTH reached. */
11073 while (field_width
> 0
11074 && n
< field_width
)
11076 store_mode_line_noprop_char (' ');
11083 /***********************************************************************
11085 ***********************************************************************/
11087 #ifdef HAVE_WINDOW_SYSTEM
11089 /* Set the title of FRAME, if it has changed. The title format is
11090 Vicon_title_format if FRAME is iconified, otherwise it is
11091 frame_title_format. */
11094 x_consider_frame_title (Lisp_Object frame
)
11096 struct frame
*f
= XFRAME (frame
);
11098 if (FRAME_WINDOW_P (f
)
11099 || FRAME_MINIBUF_ONLY_P (f
)
11100 || f
->explicit_name
)
11102 /* Do we have more than one visible frame on this X display? */
11103 Lisp_Object tail
, other_frame
, fmt
;
11104 ptrdiff_t title_start
;
11108 ptrdiff_t count
= SPECPDL_INDEX ();
11110 FOR_EACH_FRAME (tail
, other_frame
)
11112 struct frame
*tf
= XFRAME (other_frame
);
11115 && FRAME_KBOARD (tf
) == FRAME_KBOARD (f
)
11116 && !FRAME_MINIBUF_ONLY_P (tf
)
11117 && !EQ (other_frame
, tip_frame
)
11118 && (FRAME_VISIBLE_P (tf
) || FRAME_ICONIFIED_P (tf
)))
11122 /* Set global variable indicating that multiple frames exist. */
11123 multiple_frames
= CONSP (tail
);
11125 /* Switch to the buffer of selected window of the frame. Set up
11126 mode_line_target so that display_mode_element will output into
11127 mode_line_noprop_buf; then display the title. */
11128 record_unwind_protect (unwind_format_mode_line
,
11129 format_mode_line_unwind_data
11130 (f
, current_buffer
, selected_window
, 0));
11132 Fselect_window (f
->selected_window
, Qt
);
11133 set_buffer_internal_1
11134 (XBUFFER (XWINDOW (f
->selected_window
)->contents
));
11135 fmt
= FRAME_ICONIFIED_P (f
) ? Vicon_title_format
: Vframe_title_format
;
11137 mode_line_target
= MODE_LINE_TITLE
;
11138 title_start
= MODE_LINE_NOPROP_LEN (0);
11139 init_iterator (&it
, XWINDOW (f
->selected_window
), -1, -1,
11140 NULL
, DEFAULT_FACE_ID
);
11141 display_mode_element (&it
, 0, -1, -1, fmt
, Qnil
, 0);
11142 len
= MODE_LINE_NOPROP_LEN (title_start
);
11143 title
= mode_line_noprop_buf
+ title_start
;
11144 unbind_to (count
, Qnil
);
11146 /* Set the title only if it's changed. This avoids consing in
11147 the common case where it hasn't. (If it turns out that we've
11148 already wasted too much time by walking through the list with
11149 display_mode_element, then we might need to optimize at a
11150 higher level than this.) */
11151 if (! STRINGP (f
->name
)
11152 || SBYTES (f
->name
) != len
11153 || memcmp (title
, SDATA (f
->name
), len
) != 0)
11154 x_implicitly_set_name (f
, make_string (title
, len
), Qnil
);
11158 #endif /* not HAVE_WINDOW_SYSTEM */
11161 /***********************************************************************
11163 ***********************************************************************/
11166 /* Prepare for redisplay by updating menu-bar item lists when
11167 appropriate. This can call eval. */
11170 prepare_menu_bars (void)
11173 struct gcpro gcpro1
, gcpro2
;
11175 Lisp_Object tooltip_frame
;
11177 #ifdef HAVE_WINDOW_SYSTEM
11178 tooltip_frame
= tip_frame
;
11180 tooltip_frame
= Qnil
;
11183 /* Update all frame titles based on their buffer names, etc. We do
11184 this before the menu bars so that the buffer-menu will show the
11185 up-to-date frame titles. */
11186 #ifdef HAVE_WINDOW_SYSTEM
11187 if (windows_or_buffers_changed
|| update_mode_lines
)
11189 Lisp_Object tail
, frame
;
11191 FOR_EACH_FRAME (tail
, frame
)
11193 f
= XFRAME (frame
);
11194 if (!EQ (frame
, tooltip_frame
)
11195 && (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)))
11196 x_consider_frame_title (frame
);
11199 #endif /* HAVE_WINDOW_SYSTEM */
11201 /* Update the menu bar item lists, if appropriate. This has to be
11202 done before any actual redisplay or generation of display lines. */
11203 all_windows
= (update_mode_lines
11204 || buffer_shared_and_changed ()
11205 || windows_or_buffers_changed
);
11208 Lisp_Object tail
, frame
;
11209 ptrdiff_t count
= SPECPDL_INDEX ();
11210 /* 1 means that update_menu_bar has run its hooks
11211 so any further calls to update_menu_bar shouldn't do so again. */
11212 int menu_bar_hooks_run
= 0;
11214 record_unwind_save_match_data ();
11216 FOR_EACH_FRAME (tail
, frame
)
11218 f
= XFRAME (frame
);
11220 /* Ignore tooltip frame. */
11221 if (EQ (frame
, tooltip_frame
))
11224 /* If a window on this frame changed size, report that to
11225 the user and clear the size-change flag. */
11226 if (FRAME_WINDOW_SIZES_CHANGED (f
))
11228 Lisp_Object functions
;
11230 /* Clear flag first in case we get an error below. */
11231 FRAME_WINDOW_SIZES_CHANGED (f
) = 0;
11232 functions
= Vwindow_size_change_functions
;
11233 GCPRO2 (tail
, functions
);
11235 while (CONSP (functions
))
11237 if (!EQ (XCAR (functions
), Qt
))
11238 call1 (XCAR (functions
), frame
);
11239 functions
= XCDR (functions
);
11245 menu_bar_hooks_run
= update_menu_bar (f
, 0, menu_bar_hooks_run
);
11246 #ifdef HAVE_WINDOW_SYSTEM
11247 update_tool_bar (f
, 0);
11250 if (windows_or_buffers_changed
11253 (f
, Fbuffer_modified_p (XWINDOW (f
->selected_window
)->contents
));
11258 unbind_to (count
, Qnil
);
11262 struct frame
*sf
= SELECTED_FRAME ();
11263 update_menu_bar (sf
, 1, 0);
11264 #ifdef HAVE_WINDOW_SYSTEM
11265 update_tool_bar (sf
, 1);
11271 /* Update the menu bar item list for frame F. This has to be done
11272 before we start to fill in any display lines, because it can call
11275 If SAVE_MATCH_DATA is non-zero, we must save and restore it here.
11277 If HOOKS_RUN is 1, that means a previous call to update_menu_bar
11278 already ran the menu bar hooks for this redisplay, so there
11279 is no need to run them again. The return value is the
11280 updated value of this flag, to pass to the next call. */
11283 update_menu_bar (struct frame
*f
, int save_match_data
, int hooks_run
)
11285 Lisp_Object window
;
11286 register struct window
*w
;
11288 /* If called recursively during a menu update, do nothing. This can
11289 happen when, for instance, an activate-menubar-hook causes a
11291 if (inhibit_menubar_update
)
11294 window
= FRAME_SELECTED_WINDOW (f
);
11295 w
= XWINDOW (window
);
11297 if (FRAME_WINDOW_P (f
)
11299 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11300 || defined (HAVE_NS) || defined (USE_GTK)
11301 FRAME_EXTERNAL_MENU_BAR (f
)
11303 FRAME_MENU_BAR_LINES (f
) > 0
11305 : FRAME_MENU_BAR_LINES (f
) > 0)
11307 /* If the user has switched buffers or windows, we need to
11308 recompute to reflect the new bindings. But we'll
11309 recompute when update_mode_lines is set too; that means
11310 that people can use force-mode-line-update to request
11311 that the menu bar be recomputed. The adverse effect on
11312 the rest of the redisplay algorithm is about the same as
11313 windows_or_buffers_changed anyway. */
11314 if (windows_or_buffers_changed
11315 /* This used to test w->update_mode_line, but we believe
11316 there is no need to recompute the menu in that case. */
11317 || update_mode_lines
11318 || window_buffer_changed (w
))
11320 struct buffer
*prev
= current_buffer
;
11321 ptrdiff_t count
= SPECPDL_INDEX ();
11323 specbind (Qinhibit_menubar_update
, Qt
);
11325 set_buffer_internal_1 (XBUFFER (w
->contents
));
11326 if (save_match_data
)
11327 record_unwind_save_match_data ();
11328 if (NILP (Voverriding_local_map_menu_flag
))
11330 specbind (Qoverriding_terminal_local_map
, Qnil
);
11331 specbind (Qoverriding_local_map
, Qnil
);
11336 /* Run the Lucid hook. */
11337 safe_run_hooks (Qactivate_menubar_hook
);
11339 /* If it has changed current-menubar from previous value,
11340 really recompute the menu-bar from the value. */
11341 if (! NILP (Vlucid_menu_bar_dirty_flag
))
11342 call0 (Qrecompute_lucid_menubar
);
11344 safe_run_hooks (Qmenu_bar_update_hook
);
11349 XSETFRAME (Vmenu_updating_frame
, f
);
11350 fset_menu_bar_items (f
, menu_bar_items (FRAME_MENU_BAR_ITEMS (f
)));
11352 /* Redisplay the menu bar in case we changed it. */
11353 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
11354 || defined (HAVE_NS) || defined (USE_GTK)
11355 if (FRAME_WINDOW_P (f
))
11357 #if defined (HAVE_NS)
11358 /* All frames on Mac OS share the same menubar. So only
11359 the selected frame should be allowed to set it. */
11360 if (f
== SELECTED_FRAME ())
11362 set_frame_menubar (f
, 0, 0);
11365 /* On a terminal screen, the menu bar is an ordinary screen
11366 line, and this makes it get updated. */
11367 w
->update_mode_line
= 1;
11368 #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11369 /* In the non-toolkit version, the menu bar is an ordinary screen
11370 line, and this makes it get updated. */
11371 w
->update_mode_line
= 1;
11372 #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI || HAVE_NS || USE_GTK) */
11374 unbind_to (count
, Qnil
);
11375 set_buffer_internal_1 (prev
);
11384 /***********************************************************************
11386 ***********************************************************************/
11388 #ifdef HAVE_WINDOW_SYSTEM
11391 Nominal cursor position -- where to draw output.
11392 HPOS and VPOS are window relative glyph matrix coordinates.
11393 X and Y are window relative pixel coordinates. */
11395 struct cursor_pos output_cursor
;
11399 Set the global variable output_cursor to CURSOR. All cursor
11400 positions are relative to updated_window. */
11403 set_output_cursor (struct cursor_pos
*cursor
)
11405 output_cursor
.hpos
= cursor
->hpos
;
11406 output_cursor
.vpos
= cursor
->vpos
;
11407 output_cursor
.x
= cursor
->x
;
11408 output_cursor
.y
= cursor
->y
;
11413 Set a nominal cursor position.
11415 HPOS and VPOS are column/row positions in a window glyph matrix. X
11416 and Y are window text area relative pixel positions.
11418 If this is done during an update, updated_window will contain the
11419 window that is being updated and the position is the future output
11420 cursor position for that window. If updated_window is null, use
11421 selected_window and display the cursor at the given position. */
11424 x_cursor_to (int vpos
, int hpos
, int y
, int x
)
11428 /* If updated_window is not set, work on selected_window. */
11429 if (updated_window
)
11430 w
= updated_window
;
11432 w
= XWINDOW (selected_window
);
11434 /* Set the output cursor. */
11435 output_cursor
.hpos
= hpos
;
11436 output_cursor
.vpos
= vpos
;
11437 output_cursor
.x
= x
;
11438 output_cursor
.y
= y
;
11440 /* If not called as part of an update, really display the cursor.
11441 This will also set the cursor position of W. */
11442 if (updated_window
== NULL
)
11445 display_and_set_cursor (w
, 1, hpos
, vpos
, x
, y
);
11446 if (FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
11447 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (SELECTED_FRAME ());
11452 #endif /* HAVE_WINDOW_SYSTEM */
11455 /***********************************************************************
11457 ***********************************************************************/
11459 #ifdef HAVE_WINDOW_SYSTEM
11461 /* Where the mouse was last time we reported a mouse event. */
11463 FRAME_PTR last_mouse_frame
;
11465 /* Tool-bar item index of the item on which a mouse button was pressed
11468 int last_tool_bar_item
;
11470 /* Select `frame' temporarily without running all the code in
11472 FIXME: Maybe do_switch_frame should be trimmed down similarly
11473 when `norecord' is set. */
11475 fast_set_selected_frame (Lisp_Object frame
)
11477 if (!EQ (selected_frame
, frame
))
11479 selected_frame
= frame
;
11480 selected_window
= XFRAME (frame
)->selected_window
;
11485 /* Update the tool-bar item list for frame F. This has to be done
11486 before we start to fill in any display lines. Called from
11487 prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save
11488 and restore it here. */
11491 update_tool_bar (struct frame
*f
, int save_match_data
)
11493 #if defined (USE_GTK) || defined (HAVE_NS)
11494 int do_update
= FRAME_EXTERNAL_TOOL_BAR (f
);
11496 int do_update
= WINDOWP (f
->tool_bar_window
)
11497 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0;
11502 Lisp_Object window
;
11505 window
= FRAME_SELECTED_WINDOW (f
);
11506 w
= XWINDOW (window
);
11508 /* If the user has switched buffers or windows, we need to
11509 recompute to reflect the new bindings. But we'll
11510 recompute when update_mode_lines is set too; that means
11511 that people can use force-mode-line-update to request
11512 that the menu bar be recomputed. The adverse effect on
11513 the rest of the redisplay algorithm is about the same as
11514 windows_or_buffers_changed anyway. */
11515 if (windows_or_buffers_changed
11516 || w
->update_mode_line
11517 || update_mode_lines
11518 || window_buffer_changed (w
))
11520 struct buffer
*prev
= current_buffer
;
11521 ptrdiff_t count
= SPECPDL_INDEX ();
11522 Lisp_Object frame
, new_tool_bar
;
11523 int new_n_tool_bar
;
11524 struct gcpro gcpro1
;
11526 /* Set current_buffer to the buffer of the selected
11527 window of the frame, so that we get the right local
11529 set_buffer_internal_1 (XBUFFER (w
->contents
));
11531 /* Save match data, if we must. */
11532 if (save_match_data
)
11533 record_unwind_save_match_data ();
11535 /* Make sure that we don't accidentally use bogus keymaps. */
11536 if (NILP (Voverriding_local_map_menu_flag
))
11538 specbind (Qoverriding_terminal_local_map
, Qnil
);
11539 specbind (Qoverriding_local_map
, Qnil
);
11542 GCPRO1 (new_tool_bar
);
11544 /* We must temporarily set the selected frame to this frame
11545 before calling tool_bar_items, because the calculation of
11546 the tool-bar keymap uses the selected frame (see
11547 `tool-bar-make-keymap' in tool-bar.el). */
11548 eassert (EQ (selected_window
,
11549 /* Since we only explicitly preserve selected_frame,
11550 check that selected_window would be redundant. */
11551 XFRAME (selected_frame
)->selected_window
));
11552 record_unwind_protect (fast_set_selected_frame
, selected_frame
);
11553 XSETFRAME (frame
, f
);
11554 fast_set_selected_frame (frame
);
11556 /* Build desired tool-bar items from keymaps. */
11558 = tool_bar_items (Fcopy_sequence (f
->tool_bar_items
),
11561 /* Redisplay the tool-bar if we changed it. */
11562 if (new_n_tool_bar
!= f
->n_tool_bar_items
11563 || NILP (Fequal (new_tool_bar
, f
->tool_bar_items
)))
11565 /* Redisplay that happens asynchronously due to an expose event
11566 may access f->tool_bar_items. Make sure we update both
11567 variables within BLOCK_INPUT so no such event interrupts. */
11569 fset_tool_bar_items (f
, new_tool_bar
);
11570 f
->n_tool_bar_items
= new_n_tool_bar
;
11571 w
->update_mode_line
= 1;
11577 unbind_to (count
, Qnil
);
11578 set_buffer_internal_1 (prev
);
11584 /* Set F->desired_tool_bar_string to a Lisp string representing frame
11585 F's desired tool-bar contents. F->tool_bar_items must have
11586 been set up previously by calling prepare_menu_bars. */
11589 build_desired_tool_bar_string (struct frame
*f
)
11591 int i
, size
, size_needed
;
11592 struct gcpro gcpro1
, gcpro2
, gcpro3
;
11593 Lisp_Object image
, plist
, props
;
11595 image
= plist
= props
= Qnil
;
11596 GCPRO3 (image
, plist
, props
);
11598 /* Prepare F->desired_tool_bar_string. If we can reuse it, do so.
11599 Otherwise, make a new string. */
11601 /* The size of the string we might be able to reuse. */
11602 size
= (STRINGP (f
->desired_tool_bar_string
)
11603 ? SCHARS (f
->desired_tool_bar_string
)
11606 /* We need one space in the string for each image. */
11607 size_needed
= f
->n_tool_bar_items
;
11609 /* Reuse f->desired_tool_bar_string, if possible. */
11610 if (size
< size_needed
|| NILP (f
->desired_tool_bar_string
))
11611 fset_desired_tool_bar_string
11612 (f
, Fmake_string (make_number (size_needed
), make_number (' ')));
11615 props
= list4 (Qdisplay
, Qnil
, Qmenu_item
, Qnil
);
11616 Fremove_text_properties (make_number (0), make_number (size
),
11617 props
, f
->desired_tool_bar_string
);
11620 /* Put a `display' property on the string for the images to display,
11621 put a `menu_item' property on tool-bar items with a value that
11622 is the index of the item in F's tool-bar item vector. */
11623 for (i
= 0; i
< f
->n_tool_bar_items
; ++i
)
11625 #define PROP(IDX) \
11626 AREF (f->tool_bar_items, i * TOOL_BAR_ITEM_NSLOTS + (IDX))
11628 int enabled_p
= !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P
));
11629 int selected_p
= !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P
));
11630 int hmargin
, vmargin
, relief
, idx
, end
;
11632 /* If image is a vector, choose the image according to the
11634 image
= PROP (TOOL_BAR_ITEM_IMAGES
);
11635 if (VECTORP (image
))
11639 ? TOOL_BAR_IMAGE_ENABLED_SELECTED
11640 : TOOL_BAR_IMAGE_ENABLED_DESELECTED
);
11643 ? TOOL_BAR_IMAGE_DISABLED_SELECTED
11644 : TOOL_BAR_IMAGE_DISABLED_DESELECTED
);
11646 eassert (ASIZE (image
) >= idx
);
11647 image
= AREF (image
, idx
);
11652 /* Ignore invalid image specifications. */
11653 if (!valid_image_p (image
))
11656 /* Display the tool-bar button pressed, or depressed. */
11657 plist
= Fcopy_sequence (XCDR (image
));
11659 /* Compute margin and relief to draw. */
11660 relief
= (tool_bar_button_relief
>= 0
11661 ? tool_bar_button_relief
11662 : DEFAULT_TOOL_BAR_BUTTON_RELIEF
);
11663 hmargin
= vmargin
= relief
;
11665 if (RANGED_INTEGERP (1, Vtool_bar_button_margin
,
11666 INT_MAX
- max (hmargin
, vmargin
)))
11668 hmargin
+= XFASTINT (Vtool_bar_button_margin
);
11669 vmargin
+= XFASTINT (Vtool_bar_button_margin
);
11671 else if (CONSP (Vtool_bar_button_margin
))
11673 if (RANGED_INTEGERP (1, XCAR (Vtool_bar_button_margin
),
11674 INT_MAX
- hmargin
))
11675 hmargin
+= XFASTINT (XCAR (Vtool_bar_button_margin
));
11677 if (RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin
),
11678 INT_MAX
- vmargin
))
11679 vmargin
+= XFASTINT (XCDR (Vtool_bar_button_margin
));
11682 if (auto_raise_tool_bar_buttons_p
)
11684 /* Add a `:relief' property to the image spec if the item is
11688 plist
= Fplist_put (plist
, QCrelief
, make_number (-relief
));
11695 /* If image is selected, display it pressed, i.e. with a
11696 negative relief. If it's not selected, display it with a
11698 plist
= Fplist_put (plist
, QCrelief
,
11700 ? make_number (-relief
)
11701 : make_number (relief
)));
11706 /* Put a margin around the image. */
11707 if (hmargin
|| vmargin
)
11709 if (hmargin
== vmargin
)
11710 plist
= Fplist_put (plist
, QCmargin
, make_number (hmargin
));
11712 plist
= Fplist_put (plist
, QCmargin
,
11713 Fcons (make_number (hmargin
),
11714 make_number (vmargin
)));
11717 /* If button is not enabled, and we don't have special images
11718 for the disabled state, make the image appear disabled by
11719 applying an appropriate algorithm to it. */
11720 if (!enabled_p
&& idx
< 0)
11721 plist
= Fplist_put (plist
, QCconversion
, Qdisabled
);
11723 /* Put a `display' text property on the string for the image to
11724 display. Put a `menu-item' property on the string that gives
11725 the start of this item's properties in the tool-bar items
11727 image
= Fcons (Qimage
, plist
);
11728 props
= list4 (Qdisplay
, image
,
11729 Qmenu_item
, make_number (i
* TOOL_BAR_ITEM_NSLOTS
));
11731 /* Let the last image hide all remaining spaces in the tool bar
11732 string. The string can be longer than needed when we reuse a
11733 previous string. */
11734 if (i
+ 1 == f
->n_tool_bar_items
)
11735 end
= SCHARS (f
->desired_tool_bar_string
);
11738 Fadd_text_properties (make_number (i
), make_number (end
),
11739 props
, f
->desired_tool_bar_string
);
11747 /* Display one line of the tool-bar of frame IT->f.
11749 HEIGHT specifies the desired height of the tool-bar line.
11750 If the actual height of the glyph row is less than HEIGHT, the
11751 row's height is increased to HEIGHT, and the icons are centered
11752 vertically in the new height.
11754 If HEIGHT is -1, we are counting needed tool-bar lines, so don't
11755 count a final empty row in case the tool-bar width exactly matches
11760 display_tool_bar_line (struct it
*it
, int height
)
11762 struct glyph_row
*row
= it
->glyph_row
;
11763 int max_x
= it
->last_visible_x
;
11764 struct glyph
*last
;
11766 prepare_desired_row (row
);
11767 row
->y
= it
->current_y
;
11769 /* Note that this isn't made use of if the face hasn't a box,
11770 so there's no need to check the face here. */
11771 it
->start_of_box_run_p
= 1;
11773 while (it
->current_x
< max_x
)
11775 int x
, n_glyphs_before
, i
, nglyphs
;
11776 struct it it_before
;
11778 /* Get the next display element. */
11779 if (!get_next_display_element (it
))
11781 /* Don't count empty row if we are counting needed tool-bar lines. */
11782 if (height
< 0 && !it
->hpos
)
11787 /* Produce glyphs. */
11788 n_glyphs_before
= row
->used
[TEXT_AREA
];
11791 PRODUCE_GLYPHS (it
);
11793 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
11795 x
= it_before
.current_x
;
11796 while (i
< nglyphs
)
11798 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
11800 if (x
+ glyph
->pixel_width
> max_x
)
11802 /* Glyph doesn't fit on line. Backtrack. */
11803 row
->used
[TEXT_AREA
] = n_glyphs_before
;
11805 /* If this is the only glyph on this line, it will never fit on the
11806 tool-bar, so skip it. But ensure there is at least one glyph,
11807 so we don't accidentally disable the tool-bar. */
11808 if (n_glyphs_before
== 0
11809 && (it
->vpos
> 0 || IT_STRING_CHARPOS (*it
) < it
->end_charpos
-1))
11815 x
+= glyph
->pixel_width
;
11819 /* Stop at line end. */
11820 if (ITERATOR_AT_END_OF_LINE_P (it
))
11823 set_iterator_to_next (it
, 1);
11828 row
->displays_text_p
= row
->used
[TEXT_AREA
] != 0;
11830 /* Use default face for the border below the tool bar.
11832 FIXME: When auto-resize-tool-bars is grow-only, there is
11833 no additional border below the possibly empty tool-bar lines.
11834 So to make the extra empty lines look "normal", we have to
11835 use the tool-bar face for the border too. */
11836 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
11837 && !EQ (Vauto_resize_tool_bars
, Qgrow_only
))
11838 it
->face_id
= DEFAULT_FACE_ID
;
11840 extend_face_to_end_of_line (it
);
11841 last
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
11842 last
->right_box_line_p
= 1;
11843 if (last
== row
->glyphs
[TEXT_AREA
])
11844 last
->left_box_line_p
= 1;
11846 /* Make line the desired height and center it vertically. */
11847 if ((height
-= it
->max_ascent
+ it
->max_descent
) > 0)
11849 /* Don't add more than one line height. */
11850 height
%= FRAME_LINE_HEIGHT (it
->f
);
11851 it
->max_ascent
+= height
/ 2;
11852 it
->max_descent
+= (height
+ 1) / 2;
11855 compute_line_metrics (it
);
11857 /* If line is empty, make it occupy the rest of the tool-bar. */
11858 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
))
11860 row
->height
= row
->phys_height
= it
->last_visible_y
- row
->y
;
11861 row
->visible_height
= row
->height
;
11862 row
->ascent
= row
->phys_ascent
= 0;
11863 row
->extra_line_spacing
= 0;
11866 row
->full_width_p
= 1;
11867 row
->continued_p
= 0;
11868 row
->truncated_on_left_p
= 0;
11869 row
->truncated_on_right_p
= 0;
11871 it
->current_x
= it
->hpos
= 0;
11872 it
->current_y
+= row
->height
;
11878 /* Max tool-bar height. */
11880 #define MAX_FRAME_TOOL_BAR_HEIGHT(f) \
11881 ((FRAME_LINE_HEIGHT (f) * FRAME_LINES (f)))
11883 /* Value is the number of screen lines needed to make all tool-bar
11884 items of frame F visible. The number of actual rows needed is
11885 returned in *N_ROWS if non-NULL. */
11888 tool_bar_lines_needed (struct frame
*f
, int *n_rows
)
11890 struct window
*w
= XWINDOW (f
->tool_bar_window
);
11892 /* tool_bar_lines_needed is called from redisplay_tool_bar after building
11893 the desired matrix, so use (unused) mode-line row as temporary row to
11894 avoid destroying the first tool-bar row. */
11895 struct glyph_row
*temp_row
= MATRIX_MODE_LINE_ROW (w
->desired_matrix
);
11897 /* Initialize an iterator for iteration over
11898 F->desired_tool_bar_string in the tool-bar window of frame F. */
11899 init_iterator (&it
, w
, -1, -1, temp_row
, TOOL_BAR_FACE_ID
);
11900 it
.first_visible_x
= 0;
11901 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11902 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11903 it
.paragraph_embedding
= L2R
;
11905 while (!ITERATOR_AT_END_P (&it
))
11907 clear_glyph_row (temp_row
);
11908 it
.glyph_row
= temp_row
;
11909 display_tool_bar_line (&it
, -1);
11911 clear_glyph_row (temp_row
);
11913 /* f->n_tool_bar_rows == 0 means "unknown"; -1 means no tool-bar. */
11915 *n_rows
= it
.vpos
> 0 ? it
.vpos
: -1;
11917 return (it
.current_y
+ FRAME_LINE_HEIGHT (f
) - 1) / FRAME_LINE_HEIGHT (f
);
11921 DEFUN ("tool-bar-lines-needed", Ftool_bar_lines_needed
, Stool_bar_lines_needed
,
11923 doc
: /* Return the number of lines occupied by the tool bar of FRAME.
11924 If FRAME is nil or omitted, use the selected frame. */)
11925 (Lisp_Object frame
)
11927 struct frame
*f
= decode_any_frame (frame
);
11931 if (WINDOWP (f
->tool_bar_window
)
11932 && (w
= XWINDOW (f
->tool_bar_window
),
11933 WINDOW_TOTAL_LINES (w
) > 0))
11935 update_tool_bar (f
, 1);
11936 if (f
->n_tool_bar_items
)
11938 build_desired_tool_bar_string (f
);
11939 nlines
= tool_bar_lines_needed (f
, NULL
);
11943 return make_number (nlines
);
11947 /* Display the tool-bar of frame F. Value is non-zero if tool-bar's
11948 height should be changed. */
11951 redisplay_tool_bar (struct frame
*f
)
11955 struct glyph_row
*row
;
11957 #if defined (USE_GTK) || defined (HAVE_NS)
11958 if (FRAME_EXTERNAL_TOOL_BAR (f
))
11959 update_frame_tool_bar (f
);
11963 /* If frame hasn't a tool-bar window or if it is zero-height, don't
11964 do anything. This means you must start with tool-bar-lines
11965 non-zero to get the auto-sizing effect. Or in other words, you
11966 can turn off tool-bars by specifying tool-bar-lines zero. */
11967 if (!WINDOWP (f
->tool_bar_window
)
11968 || (w
= XWINDOW (f
->tool_bar_window
),
11969 WINDOW_TOTAL_LINES (w
) == 0))
11972 /* Set up an iterator for the tool-bar window. */
11973 init_iterator (&it
, w
, -1, -1, w
->desired_matrix
->rows
, TOOL_BAR_FACE_ID
);
11974 it
.first_visible_x
= 0;
11975 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
11976 row
= it
.glyph_row
;
11978 /* Build a string that represents the contents of the tool-bar. */
11979 build_desired_tool_bar_string (f
);
11980 reseat_to_string (&it
, NULL
, f
->desired_tool_bar_string
, 0, 0, 0, -1);
11981 /* FIXME: This should be controlled by a user option. But it
11982 doesn't make sense to have an R2L tool bar if the menu bar cannot
11983 be drawn also R2L, and making the menu bar R2L is tricky due
11984 toolkit-specific code that implements it. If an R2L tool bar is
11985 ever supported, display_tool_bar_line should also be augmented to
11986 call unproduce_glyphs like display_line and display_string
11988 it
.paragraph_embedding
= L2R
;
11990 if (f
->n_tool_bar_rows
== 0)
11994 if ((nlines
= tool_bar_lines_needed (f
, &f
->n_tool_bar_rows
),
11995 nlines
!= WINDOW_TOTAL_LINES (w
)))
11998 int old_height
= WINDOW_TOTAL_LINES (w
);
12000 XSETFRAME (frame
, f
);
12001 Fmodify_frame_parameters (frame
,
12002 Fcons (Fcons (Qtool_bar_lines
,
12003 make_number (nlines
)),
12005 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12007 clear_glyph_matrix (w
->desired_matrix
);
12008 fonts_changed_p
= 1;
12014 /* Display as many lines as needed to display all tool-bar items. */
12016 if (f
->n_tool_bar_rows
> 0)
12018 int border
, rows
, height
, extra
;
12020 if (TYPE_RANGED_INTEGERP (int, Vtool_bar_border
))
12021 border
= XINT (Vtool_bar_border
);
12022 else if (EQ (Vtool_bar_border
, Qinternal_border_width
))
12023 border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
12024 else if (EQ (Vtool_bar_border
, Qborder_width
))
12025 border
= f
->border_width
;
12031 rows
= f
->n_tool_bar_rows
;
12032 height
= max (1, (it
.last_visible_y
- border
) / rows
);
12033 extra
= it
.last_visible_y
- border
- height
* rows
;
12035 while (it
.current_y
< it
.last_visible_y
)
12038 if (extra
> 0 && rows
-- > 0)
12040 h
= (extra
+ rows
- 1) / rows
;
12043 display_tool_bar_line (&it
, height
+ h
);
12048 while (it
.current_y
< it
.last_visible_y
)
12049 display_tool_bar_line (&it
, 0);
12052 /* It doesn't make much sense to try scrolling in the tool-bar
12053 window, so don't do it. */
12054 w
->desired_matrix
->no_scrolling_p
= 1;
12055 w
->must_be_updated_p
= 1;
12057 if (!NILP (Vauto_resize_tool_bars
))
12059 int max_tool_bar_height
= MAX_FRAME_TOOL_BAR_HEIGHT (f
);
12060 int change_height_p
= 0;
12062 /* If we couldn't display everything, change the tool-bar's
12063 height if there is room for more. */
12064 if (IT_STRING_CHARPOS (it
) < it
.end_charpos
12065 && it
.current_y
< max_tool_bar_height
)
12066 change_height_p
= 1;
12068 row
= it
.glyph_row
- 1;
12070 /* If there are blank lines at the end, except for a partially
12071 visible blank line at the end that is smaller than
12072 FRAME_LINE_HEIGHT, change the tool-bar's height. */
12073 if (!MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12074 && row
->height
>= FRAME_LINE_HEIGHT (f
))
12075 change_height_p
= 1;
12077 /* If row displays tool-bar items, but is partially visible,
12078 change the tool-bar's height. */
12079 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
12080 && MATRIX_ROW_BOTTOM_Y (row
) > it
.last_visible_y
12081 && MATRIX_ROW_BOTTOM_Y (row
) < max_tool_bar_height
)
12082 change_height_p
= 1;
12084 /* Resize windows as needed by changing the `tool-bar-lines'
12085 frame parameter. */
12086 if (change_height_p
)
12089 int old_height
= WINDOW_TOTAL_LINES (w
);
12091 int nlines
= tool_bar_lines_needed (f
, &nrows
);
12093 change_height_p
= ((EQ (Vauto_resize_tool_bars
, Qgrow_only
)
12094 && !f
->minimize_tool_bar_window_p
)
12095 ? (nlines
> old_height
)
12096 : (nlines
!= old_height
));
12097 f
->minimize_tool_bar_window_p
= 0;
12099 if (change_height_p
)
12101 XSETFRAME (frame
, f
);
12102 Fmodify_frame_parameters (frame
,
12103 Fcons (Fcons (Qtool_bar_lines
,
12104 make_number (nlines
)),
12106 if (WINDOW_TOTAL_LINES (w
) != old_height
)
12108 clear_glyph_matrix (w
->desired_matrix
);
12109 f
->n_tool_bar_rows
= nrows
;
12110 fonts_changed_p
= 1;
12117 f
->minimize_tool_bar_window_p
= 0;
12122 /* Get information about the tool-bar item which is displayed in GLYPH
12123 on frame F. Return in *PROP_IDX the index where tool-bar item
12124 properties start in F->tool_bar_items. Value is zero if
12125 GLYPH doesn't display a tool-bar item. */
12128 tool_bar_item_info (struct frame
*f
, struct glyph
*glyph
, int *prop_idx
)
12134 /* This function can be called asynchronously, which means we must
12135 exclude any possibility that Fget_text_property signals an
12137 charpos
= min (SCHARS (f
->current_tool_bar_string
), glyph
->charpos
);
12138 charpos
= max (0, charpos
);
12140 /* Get the text property `menu-item' at pos. The value of that
12141 property is the start index of this item's properties in
12142 F->tool_bar_items. */
12143 prop
= Fget_text_property (make_number (charpos
),
12144 Qmenu_item
, f
->current_tool_bar_string
);
12145 if (INTEGERP (prop
))
12147 *prop_idx
= XINT (prop
);
12157 /* Get information about the tool-bar item at position X/Y on frame F.
12158 Return in *GLYPH a pointer to the glyph of the tool-bar item in
12159 the current matrix of the tool-bar window of F, or NULL if not
12160 on a tool-bar item. Return in *PROP_IDX the index of the tool-bar
12161 item in F->tool_bar_items. Value is
12163 -1 if X/Y is not on a tool-bar item
12164 0 if X/Y is on the same item that was highlighted before.
12168 get_tool_bar_item (struct frame
*f
, int x
, int y
, struct glyph
**glyph
,
12169 int *hpos
, int *vpos
, int *prop_idx
)
12171 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12172 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12175 /* Find the glyph under X/Y. */
12176 *glyph
= x_y_to_hpos_vpos (w
, x
, y
, hpos
, vpos
, 0, 0, &area
);
12177 if (*glyph
== NULL
)
12180 /* Get the start of this tool-bar item's properties in
12181 f->tool_bar_items. */
12182 if (!tool_bar_item_info (f
, *glyph
, prop_idx
))
12185 /* Is mouse on the highlighted item? */
12186 if (EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)
12187 && *vpos
>= hlinfo
->mouse_face_beg_row
12188 && *vpos
<= hlinfo
->mouse_face_end_row
12189 && (*vpos
> hlinfo
->mouse_face_beg_row
12190 || *hpos
>= hlinfo
->mouse_face_beg_col
)
12191 && (*vpos
< hlinfo
->mouse_face_end_row
12192 || *hpos
< hlinfo
->mouse_face_end_col
12193 || hlinfo
->mouse_face_past_end
))
12201 Handle mouse button event on the tool-bar of frame F, at
12202 frame-relative coordinates X/Y. DOWN_P is 1 for a button press,
12203 0 for button release. MODIFIERS is event modifiers for button
12207 handle_tool_bar_click (struct frame
*f
, int x
, int y
, int down_p
,
12210 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12211 struct window
*w
= XWINDOW (f
->tool_bar_window
);
12212 int hpos
, vpos
, prop_idx
;
12213 struct glyph
*glyph
;
12214 Lisp_Object enabled_p
;
12217 /* If not on the highlighted tool-bar item, and mouse-highlight is
12218 non-nil, return. This is so we generate the tool-bar button
12219 click only when the mouse button is released on the same item as
12220 where it was pressed. However, when mouse-highlight is disabled,
12221 generate the click when the button is released regardless of the
12222 highlight, since tool-bar items are not highlighted in that
12224 frame_to_window_pixel_xy (w
, &x
, &y
);
12225 ts
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12227 || (ts
!= 0 && !NILP (Vmouse_highlight
)))
12230 /* When mouse-highlight is off, generate the click for the item
12231 where the button was pressed, disregarding where it was
12233 if (NILP (Vmouse_highlight
) && !down_p
)
12234 prop_idx
= last_tool_bar_item
;
12236 /* If item is disabled, do nothing. */
12237 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12238 if (NILP (enabled_p
))
12243 /* Show item in pressed state. */
12244 if (!NILP (Vmouse_highlight
))
12245 show_mouse_face (hlinfo
, DRAW_IMAGE_SUNKEN
);
12246 last_tool_bar_item
= prop_idx
;
12250 Lisp_Object key
, frame
;
12251 struct input_event event
;
12252 EVENT_INIT (event
);
12254 /* Show item in released state. */
12255 if (!NILP (Vmouse_highlight
))
12256 show_mouse_face (hlinfo
, DRAW_IMAGE_RAISED
);
12258 key
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_KEY
);
12260 XSETFRAME (frame
, f
);
12261 event
.kind
= TOOL_BAR_EVENT
;
12262 event
.frame_or_window
= frame
;
12264 kbd_buffer_store_event (&event
);
12266 event
.kind
= TOOL_BAR_EVENT
;
12267 event
.frame_or_window
= frame
;
12269 event
.modifiers
= modifiers
;
12270 kbd_buffer_store_event (&event
);
12271 last_tool_bar_item
= -1;
12276 /* Possibly highlight a tool-bar item on frame F when mouse moves to
12277 tool-bar window-relative coordinates X/Y. Called from
12278 note_mouse_highlight. */
12281 note_tool_bar_highlight (struct frame
*f
, int x
, int y
)
12283 Lisp_Object window
= f
->tool_bar_window
;
12284 struct window
*w
= XWINDOW (window
);
12285 Display_Info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
12286 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
12288 struct glyph
*glyph
;
12289 struct glyph_row
*row
;
12291 Lisp_Object enabled_p
;
12293 enum draw_glyphs_face draw
= DRAW_IMAGE_RAISED
;
12294 int mouse_down_p
, rc
;
12296 /* Function note_mouse_highlight is called with negative X/Y
12297 values when mouse moves outside of the frame. */
12298 if (x
<= 0 || y
<= 0)
12300 clear_mouse_face (hlinfo
);
12304 rc
= get_tool_bar_item (f
, x
, y
, &glyph
, &hpos
, &vpos
, &prop_idx
);
12307 /* Not on tool-bar item. */
12308 clear_mouse_face (hlinfo
);
12312 /* On same tool-bar item as before. */
12313 goto set_help_echo
;
12315 clear_mouse_face (hlinfo
);
12317 /* Mouse is down, but on different tool-bar item? */
12318 mouse_down_p
= (dpyinfo
->grabbed
12319 && f
== last_mouse_frame
12320 && FRAME_LIVE_P (f
));
12322 && last_tool_bar_item
!= prop_idx
)
12325 draw
= mouse_down_p
? DRAW_IMAGE_SUNKEN
: DRAW_IMAGE_RAISED
;
12327 /* If tool-bar item is not enabled, don't highlight it. */
12328 enabled_p
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_ENABLED_P
);
12329 if (!NILP (enabled_p
) && !NILP (Vmouse_highlight
))
12331 /* Compute the x-position of the glyph. In front and past the
12332 image is a space. We include this in the highlighted area. */
12333 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
12334 for (i
= x
= 0; i
< hpos
; ++i
)
12335 x
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
12337 /* Record this as the current active region. */
12338 hlinfo
->mouse_face_beg_col
= hpos
;
12339 hlinfo
->mouse_face_beg_row
= vpos
;
12340 hlinfo
->mouse_face_beg_x
= x
;
12341 hlinfo
->mouse_face_beg_y
= row
->y
;
12342 hlinfo
->mouse_face_past_end
= 0;
12344 hlinfo
->mouse_face_end_col
= hpos
+ 1;
12345 hlinfo
->mouse_face_end_row
= vpos
;
12346 hlinfo
->mouse_face_end_x
= x
+ glyph
->pixel_width
;
12347 hlinfo
->mouse_face_end_y
= row
->y
;
12348 hlinfo
->mouse_face_window
= window
;
12349 hlinfo
->mouse_face_face_id
= TOOL_BAR_FACE_ID
;
12351 /* Display it as active. */
12352 show_mouse_face (hlinfo
, draw
);
12357 /* Set help_echo_string to a help string to display for this tool-bar item.
12358 XTread_socket does the rest. */
12359 help_echo_object
= help_echo_window
= Qnil
;
12360 help_echo_pos
= -1;
12361 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_HELP
);
12362 if (NILP (help_echo_string
))
12363 help_echo_string
= AREF (f
->tool_bar_items
, prop_idx
+ TOOL_BAR_ITEM_CAPTION
);
12366 #endif /* HAVE_WINDOW_SYSTEM */
12370 /************************************************************************
12371 Horizontal scrolling
12372 ************************************************************************/
12374 static int hscroll_window_tree (Lisp_Object
);
12375 static int hscroll_windows (Lisp_Object
);
12377 /* For all leaf windows in the window tree rooted at WINDOW, set their
12378 hscroll value so that PT is (i) visible in the window, and (ii) so
12379 that it is not within a certain margin at the window's left and
12380 right border. Value is non-zero if any window's hscroll has been
12384 hscroll_window_tree (Lisp_Object window
)
12386 int hscrolled_p
= 0;
12387 int hscroll_relative_p
= FLOATP (Vhscroll_step
);
12388 int hscroll_step_abs
= 0;
12389 double hscroll_step_rel
= 0;
12391 if (hscroll_relative_p
)
12393 hscroll_step_rel
= XFLOAT_DATA (Vhscroll_step
);
12394 if (hscroll_step_rel
< 0)
12396 hscroll_relative_p
= 0;
12397 hscroll_step_abs
= 0;
12400 else if (TYPE_RANGED_INTEGERP (int, Vhscroll_step
))
12402 hscroll_step_abs
= XINT (Vhscroll_step
);
12403 if (hscroll_step_abs
< 0)
12404 hscroll_step_abs
= 0;
12407 hscroll_step_abs
= 0;
12409 while (WINDOWP (window
))
12411 struct window
*w
= XWINDOW (window
);
12413 if (WINDOWP (w
->contents
))
12414 hscrolled_p
|= hscroll_window_tree (w
->contents
);
12415 else if (w
->cursor
.vpos
>= 0)
12418 int text_area_width
;
12419 struct glyph_row
*current_cursor_row
12420 = MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
12421 struct glyph_row
*desired_cursor_row
12422 = MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
);
12423 struct glyph_row
*cursor_row
12424 = (desired_cursor_row
->enabled_p
12425 ? desired_cursor_row
12426 : current_cursor_row
);
12427 int row_r2l_p
= cursor_row
->reversed_p
;
12429 text_area_width
= window_box_width (w
, TEXT_AREA
);
12431 /* Scroll when cursor is inside this scroll margin. */
12432 h_margin
= hscroll_margin
* WINDOW_FRAME_COLUMN_WIDTH (w
);
12434 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode
, w
->contents
))
12435 /* For left-to-right rows, hscroll when cursor is either
12436 (i) inside the right hscroll margin, or (ii) if it is
12437 inside the left margin and the window is already
12441 && w
->cursor
.x
<= h_margin
)
12442 || (cursor_row
->enabled_p
12443 && cursor_row
->truncated_on_right_p
12444 && (w
->cursor
.x
>= text_area_width
- h_margin
))))
12445 /* For right-to-left rows, the logic is similar,
12446 except that rules for scrolling to left and right
12447 are reversed. E.g., if cursor.x <= h_margin, we
12448 need to hscroll "to the right" unconditionally,
12449 and that will scroll the screen to the left so as
12450 to reveal the next portion of the row. */
12452 && ((cursor_row
->enabled_p
12453 /* FIXME: It is confusing to set the
12454 truncated_on_right_p flag when R2L rows
12455 are actually truncated on the left. */
12456 && cursor_row
->truncated_on_right_p
12457 && w
->cursor
.x
<= h_margin
)
12459 && (w
->cursor
.x
>= text_area_width
- h_margin
))))))
12463 struct buffer
*saved_current_buffer
;
12467 /* Find point in a display of infinite width. */
12468 saved_current_buffer
= current_buffer
;
12469 current_buffer
= XBUFFER (w
->contents
);
12471 if (w
== XWINDOW (selected_window
))
12474 pt
= clip_to_bounds (BEGV
, marker_position (w
->pointm
), ZV
);
12476 /* Move iterator to pt starting at cursor_row->start in
12477 a line with infinite width. */
12478 init_to_row_start (&it
, w
, cursor_row
);
12479 it
.last_visible_x
= INFINITY
;
12480 move_it_in_display_line_to (&it
, pt
, -1, MOVE_TO_POS
);
12481 current_buffer
= saved_current_buffer
;
12483 /* Position cursor in window. */
12484 if (!hscroll_relative_p
&& hscroll_step_abs
== 0)
12485 hscroll
= max (0, (it
.current_x
12486 - (ITERATOR_AT_END_OF_LINE_P (&it
)
12487 ? (text_area_width
- 4 * FRAME_COLUMN_WIDTH (it
.f
))
12488 : (text_area_width
/ 2))))
12489 / FRAME_COLUMN_WIDTH (it
.f
);
12490 else if ((!row_r2l_p
12491 && w
->cursor
.x
>= text_area_width
- h_margin
)
12492 || (row_r2l_p
&& w
->cursor
.x
<= h_margin
))
12494 if (hscroll_relative_p
)
12495 wanted_x
= text_area_width
* (1 - hscroll_step_rel
)
12498 wanted_x
= text_area_width
12499 - hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12502 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12506 if (hscroll_relative_p
)
12507 wanted_x
= text_area_width
* hscroll_step_rel
12510 wanted_x
= hscroll_step_abs
* FRAME_COLUMN_WIDTH (it
.f
)
12513 = max (0, it
.current_x
- wanted_x
) / FRAME_COLUMN_WIDTH (it
.f
);
12515 hscroll
= max (hscroll
, w
->min_hscroll
);
12517 /* Don't prevent redisplay optimizations if hscroll
12518 hasn't changed, as it will unnecessarily slow down
12520 if (w
->hscroll
!= hscroll
)
12522 XBUFFER (w
->contents
)->prevent_redisplay_optimizations_p
= 1;
12523 w
->hscroll
= hscroll
;
12532 /* Value is non-zero if hscroll of any leaf window has been changed. */
12533 return hscrolled_p
;
12537 /* Set hscroll so that cursor is visible and not inside horizontal
12538 scroll margins for all windows in the tree rooted at WINDOW. See
12539 also hscroll_window_tree above. Value is non-zero if any window's
12540 hscroll has been changed. If it has, desired matrices on the frame
12541 of WINDOW are cleared. */
12544 hscroll_windows (Lisp_Object window
)
12546 int hscrolled_p
= hscroll_window_tree (window
);
12548 clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
12549 return hscrolled_p
;
12554 /************************************************************************
12556 ************************************************************************/
12558 /* Variables holding some state of redisplay if GLYPH_DEBUG is defined
12559 to a non-zero value. This is sometimes handy to have in a debugger
12564 /* First and last unchanged row for try_window_id. */
12566 static int debug_first_unchanged_at_end_vpos
;
12567 static int debug_last_unchanged_at_beg_vpos
;
12569 /* Delta vpos and y. */
12571 static int debug_dvpos
, debug_dy
;
12573 /* Delta in characters and bytes for try_window_id. */
12575 static ptrdiff_t debug_delta
, debug_delta_bytes
;
12577 /* Values of window_end_pos and window_end_vpos at the end of
12580 static ptrdiff_t debug_end_vpos
;
12582 /* Append a string to W->desired_matrix->method. FMT is a printf
12583 format string. If trace_redisplay_p is non-zero also printf the
12584 resulting string to stderr. */
12586 static void debug_method_add (struct window
*, char const *, ...)
12587 ATTRIBUTE_FORMAT_PRINTF (2, 3);
12590 debug_method_add (struct window
*w
, char const *fmt
, ...)
12592 char *method
= w
->desired_matrix
->method
;
12593 int len
= strlen (method
);
12594 int size
= sizeof w
->desired_matrix
->method
;
12595 int remaining
= size
- len
- 1;
12598 if (len
&& remaining
)
12601 --remaining
, ++len
;
12604 va_start (ap
, fmt
);
12605 vsnprintf (method
+ len
, remaining
+ 1, fmt
, ap
);
12608 if (trace_redisplay_p
)
12609 fprintf (stderr
, "%p (%s): %s\n",
12611 ((BUFFERP (w
->contents
)
12612 && STRINGP (BVAR (XBUFFER (w
->contents
), name
)))
12613 ? SSDATA (BVAR (XBUFFER (w
->contents
), name
))
12618 #endif /* GLYPH_DEBUG */
12621 /* Value is non-zero if all changes in window W, which displays
12622 current_buffer, are in the text between START and END. START is a
12623 buffer position, END is given as a distance from Z. Used in
12624 redisplay_internal for display optimization. */
12627 text_outside_line_unchanged_p (struct window
*w
,
12628 ptrdiff_t start
, ptrdiff_t end
)
12630 int unchanged_p
= 1;
12632 /* If text or overlays have changed, see where. */
12633 if (window_outdated (w
))
12635 /* Gap in the line? */
12636 if (GPT
< start
|| Z
- GPT
< end
)
12639 /* Changes start in front of the line, or end after it? */
12641 && (BEG_UNCHANGED
< start
- 1
12642 || END_UNCHANGED
< end
))
12645 /* If selective display, can't optimize if changes start at the
12646 beginning of the line. */
12648 && INTEGERP (BVAR (current_buffer
, selective_display
))
12649 && XINT (BVAR (current_buffer
, selective_display
)) > 0
12650 && (BEG_UNCHANGED
< start
|| GPT
<= start
))
12653 /* If there are overlays at the start or end of the line, these
12654 may have overlay strings with newlines in them. A change at
12655 START, for instance, may actually concern the display of such
12656 overlay strings as well, and they are displayed on different
12657 lines. So, quickly rule out this case. (For the future, it
12658 might be desirable to implement something more telling than
12659 just BEG/END_UNCHANGED.) */
12662 if (BEG
+ BEG_UNCHANGED
== start
12663 && overlay_touches_p (start
))
12665 if (END_UNCHANGED
== end
12666 && overlay_touches_p (Z
- end
))
12670 /* Under bidi reordering, adding or deleting a character in the
12671 beginning of a paragraph, before the first strong directional
12672 character, can change the base direction of the paragraph (unless
12673 the buffer specifies a fixed paragraph direction), which will
12674 require to redisplay the whole paragraph. It might be worthwhile
12675 to find the paragraph limits and widen the range of redisplayed
12676 lines to that, but for now just give up this optimization. */
12677 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
12678 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
12682 return unchanged_p
;
12686 /* Do a frame update, taking possible shortcuts into account. This is
12687 the main external entry point for redisplay.
12689 If the last redisplay displayed an echo area message and that message
12690 is no longer requested, we clear the echo area or bring back the
12691 mini-buffer if that is in use. */
12696 redisplay_internal ();
12701 overlay_arrow_string_or_property (Lisp_Object var
)
12705 if (val
= Fget (var
, Qoverlay_arrow_string
), STRINGP (val
))
12708 return Voverlay_arrow_string
;
12711 /* Return 1 if there are any overlay-arrows in current_buffer. */
12713 overlay_arrow_in_current_buffer_p (void)
12717 for (vlist
= Voverlay_arrow_variable_list
;
12719 vlist
= XCDR (vlist
))
12721 Lisp_Object var
= XCAR (vlist
);
12724 if (!SYMBOLP (var
))
12726 val
= find_symbol_value (var
);
12728 && current_buffer
== XMARKER (val
)->buffer
)
12735 /* Return 1 if any overlay_arrows have moved or overlay-arrow-string
12739 overlay_arrows_changed_p (void)
12743 for (vlist
= Voverlay_arrow_variable_list
;
12745 vlist
= XCDR (vlist
))
12747 Lisp_Object var
= XCAR (vlist
);
12748 Lisp_Object val
, pstr
;
12750 if (!SYMBOLP (var
))
12752 val
= find_symbol_value (var
);
12753 if (!MARKERP (val
))
12755 if (! EQ (COERCE_MARKER (val
),
12756 Fget (var
, Qlast_arrow_position
))
12757 || ! (pstr
= overlay_arrow_string_or_property (var
),
12758 EQ (pstr
, Fget (var
, Qlast_arrow_string
))))
12764 /* Mark overlay arrows to be updated on next redisplay. */
12767 update_overlay_arrows (int up_to_date
)
12771 for (vlist
= Voverlay_arrow_variable_list
;
12773 vlist
= XCDR (vlist
))
12775 Lisp_Object var
= XCAR (vlist
);
12777 if (!SYMBOLP (var
))
12780 if (up_to_date
> 0)
12782 Lisp_Object val
= find_symbol_value (var
);
12783 Fput (var
, Qlast_arrow_position
,
12784 COERCE_MARKER (val
));
12785 Fput (var
, Qlast_arrow_string
,
12786 overlay_arrow_string_or_property (var
));
12788 else if (up_to_date
< 0
12789 || !NILP (Fget (var
, Qlast_arrow_position
)))
12791 Fput (var
, Qlast_arrow_position
, Qt
);
12792 Fput (var
, Qlast_arrow_string
, Qt
);
12798 /* Return overlay arrow string to display at row.
12799 Return integer (bitmap number) for arrow bitmap in left fringe.
12800 Return nil if no overlay arrow. */
12803 overlay_arrow_at_row (struct it
*it
, struct glyph_row
*row
)
12807 for (vlist
= Voverlay_arrow_variable_list
;
12809 vlist
= XCDR (vlist
))
12811 Lisp_Object var
= XCAR (vlist
);
12814 if (!SYMBOLP (var
))
12817 val
= find_symbol_value (var
);
12820 && current_buffer
== XMARKER (val
)->buffer
12821 && (MATRIX_ROW_START_CHARPOS (row
) == marker_position (val
)))
12823 if (FRAME_WINDOW_P (it
->f
)
12824 /* FIXME: if ROW->reversed_p is set, this should test
12825 the right fringe, not the left one. */
12826 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) > 0)
12828 #ifdef HAVE_WINDOW_SYSTEM
12829 if (val
= Fget (var
, Qoverlay_arrow_bitmap
), SYMBOLP (val
))
12832 if ((fringe_bitmap
= lookup_fringe_bitmap (val
)) != 0)
12833 return make_number (fringe_bitmap
);
12836 return make_number (-1); /* Use default arrow bitmap. */
12838 return overlay_arrow_string_or_property (var
);
12845 /* Return 1 if point moved out of or into a composition. Otherwise
12846 return 0. PREV_BUF and PREV_PT are the last point buffer and
12847 position. BUF and PT are the current point buffer and position. */
12850 check_point_in_composition (struct buffer
*prev_buf
, ptrdiff_t prev_pt
,
12851 struct buffer
*buf
, ptrdiff_t pt
)
12853 ptrdiff_t start
, end
;
12855 Lisp_Object buffer
;
12857 XSETBUFFER (buffer
, buf
);
12858 /* Check a composition at the last point if point moved within the
12860 if (prev_buf
== buf
)
12863 /* Point didn't move. */
12866 if (prev_pt
> BUF_BEGV (buf
) && prev_pt
< BUF_ZV (buf
)
12867 && find_composition (prev_pt
, -1, &start
, &end
, &prop
, buffer
)
12868 && COMPOSITION_VALID_P (start
, end
, prop
)
12869 && start
< prev_pt
&& end
> prev_pt
)
12870 /* The last point was within the composition. Return 1 iff
12871 point moved out of the composition. */
12872 return (pt
<= start
|| pt
>= end
);
12875 /* Check a composition at the current point. */
12876 return (pt
> BUF_BEGV (buf
) && pt
< BUF_ZV (buf
)
12877 && find_composition (pt
, -1, &start
, &end
, &prop
, buffer
)
12878 && COMPOSITION_VALID_P (start
, end
, prop
)
12879 && start
< pt
&& end
> pt
);
12883 /* Reconsider the setting of B->clip_changed which is displayed
12887 reconsider_clip_changes (struct window
*w
, struct buffer
*b
)
12889 if (b
->clip_changed
12890 && w
->window_end_valid
12891 && w
->current_matrix
->buffer
== b
12892 && w
->current_matrix
->zv
== BUF_ZV (b
)
12893 && w
->current_matrix
->begv
== BUF_BEGV (b
))
12894 b
->clip_changed
= 0;
12896 /* If display wasn't paused, and W is not a tool bar window, see if
12897 point has been moved into or out of a composition. In that case,
12898 we set b->clip_changed to 1 to force updating the screen. If
12899 b->clip_changed has already been set to 1, we can skip this
12901 if (!b
->clip_changed
&& BUFFERP (w
->contents
) && w
->window_end_valid
)
12905 if (w
== XWINDOW (selected_window
))
12908 pt
= marker_position (w
->pointm
);
12910 if ((w
->current_matrix
->buffer
!= XBUFFER (w
->contents
)
12911 || pt
!= w
->last_point
)
12912 && check_point_in_composition (w
->current_matrix
->buffer
,
12914 XBUFFER (w
->contents
), pt
))
12915 b
->clip_changed
= 1;
12920 #define STOP_POLLING \
12921 do { if (! polling_stopped_here) stop_polling (); \
12922 polling_stopped_here = 1; } while (0)
12924 #define RESUME_POLLING \
12925 do { if (polling_stopped_here) start_polling (); \
12926 polling_stopped_here = 0; } while (0)
12929 /* Perhaps in the future avoid recentering windows if it
12930 is not necessary; currently that causes some problems. */
12933 redisplay_internal (void)
12935 struct window
*w
= XWINDOW (selected_window
);
12939 int must_finish
= 0;
12940 struct text_pos tlbufpos
, tlendpos
;
12941 int number_of_visible_frames
;
12942 ptrdiff_t count
, count1
;
12944 int polling_stopped_here
= 0;
12945 Lisp_Object tail
, frame
;
12947 /* Non-zero means redisplay has to consider all windows on all
12948 frames. Zero means, only selected_window is considered. */
12949 int consider_all_windows_p
;
12951 /* Non-zero means redisplay has to redisplay the miniwindow. */
12952 int update_miniwindow_p
= 0;
12954 TRACE ((stderr
, "redisplay_internal %d\n", redisplaying_p
));
12956 /* No redisplay if running in batch mode or frame is not yet fully
12957 initialized, or redisplay is explicitly turned off by setting
12958 Vinhibit_redisplay. */
12959 if (FRAME_INITIAL_P (SELECTED_FRAME ())
12960 || !NILP (Vinhibit_redisplay
))
12963 /* Don't examine these until after testing Vinhibit_redisplay.
12964 When Emacs is shutting down, perhaps because its connection to
12965 X has dropped, we should not look at them at all. */
12966 fr
= XFRAME (w
->frame
);
12967 sf
= SELECTED_FRAME ();
12969 if (!fr
->glyphs_initialized_p
)
12972 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS)
12973 if (popup_activated ())
12977 /* I don't think this happens but let's be paranoid. */
12978 if (redisplaying_p
)
12981 /* Record a function that clears redisplaying_p
12982 when we leave this function. */
12983 count
= SPECPDL_INDEX ();
12984 record_unwind_protect (unwind_redisplay
, selected_frame
);
12985 redisplaying_p
= 1;
12986 specbind (Qinhibit_free_realized_faces
, Qnil
);
12988 /* Record this function, so it appears on the profiler's backtraces. */
12989 record_in_backtrace (Qredisplay_internal
, &Qnil
, 0);
12991 FOR_EACH_FRAME (tail
, frame
)
12992 XFRAME (frame
)->already_hscrolled_p
= 0;
12995 /* Remember the currently selected window. */
12999 reconsider_clip_changes (w
, current_buffer
);
13000 last_escape_glyph_frame
= NULL
;
13001 last_escape_glyph_face_id
= (1 << FACE_ID_BITS
);
13002 last_glyphless_glyph_frame
= NULL
;
13003 last_glyphless_glyph_face_id
= (1 << FACE_ID_BITS
);
13005 /* If new fonts have been loaded that make a glyph matrix adjustment
13006 necessary, do it. */
13007 if (fonts_changed_p
)
13009 adjust_glyphs (NULL
);
13010 ++windows_or_buffers_changed
;
13011 fonts_changed_p
= 0;
13014 /* If face_change_count is non-zero, init_iterator will free all
13015 realized faces, which includes the faces referenced from current
13016 matrices. So, we can't reuse current matrices in this case. */
13017 if (face_change_count
)
13018 ++windows_or_buffers_changed
;
13020 if ((FRAME_TERMCAP_P (sf
) || FRAME_MSDOS_P (sf
))
13021 && FRAME_TTY (sf
)->previous_frame
!= sf
)
13023 /* Since frames on a single ASCII terminal share the same
13024 display area, displaying a different frame means redisplay
13025 the whole thing. */
13026 windows_or_buffers_changed
++;
13027 SET_FRAME_GARBAGED (sf
);
13029 set_tty_color_mode (FRAME_TTY (sf
), sf
);
13031 FRAME_TTY (sf
)->previous_frame
= sf
;
13034 /* Set the visible flags for all frames. Do this before checking for
13035 resized or garbaged frames; they want to know if their frames are
13036 visible. See the comment in frame.h for FRAME_SAMPLE_VISIBILITY. */
13037 number_of_visible_frames
= 0;
13039 FOR_EACH_FRAME (tail
, frame
)
13041 struct frame
*f
= XFRAME (frame
);
13043 if (FRAME_VISIBLE_P (f
))
13044 ++number_of_visible_frames
;
13045 clear_desired_matrices (f
);
13048 /* Notice any pending interrupt request to change frame size. */
13049 do_pending_window_change (1);
13051 /* do_pending_window_change could change the selected_window due to
13052 frame resizing which makes the selected window too small. */
13053 if (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
)
13056 reconsider_clip_changes (w
, current_buffer
);
13059 /* Clear frames marked as garbaged. */
13060 clear_garbaged_frames ();
13062 /* Build menubar and tool-bar items. */
13063 if (NILP (Vmemory_full
))
13064 prepare_menu_bars ();
13066 if (windows_or_buffers_changed
)
13067 update_mode_lines
++;
13069 /* Detect case that we need to write or remove a star in the mode line. */
13070 if ((SAVE_MODIFF
< MODIFF
) != w
->last_had_star
)
13072 w
->update_mode_line
= 1;
13073 if (buffer_shared_and_changed ())
13074 update_mode_lines
++;
13077 /* Avoid invocation of point motion hooks by `current_column' below. */
13078 count1
= SPECPDL_INDEX ();
13079 specbind (Qinhibit_point_motion_hooks
, Qt
);
13081 if (mode_line_update_needed (w
))
13082 w
->update_mode_line
= 1;
13084 unbind_to (count1
, Qnil
);
13086 consider_all_windows_p
= (update_mode_lines
13087 || buffer_shared_and_changed ()
13088 || cursor_type_changed
);
13090 /* If specs for an arrow have changed, do thorough redisplay
13091 to ensure we remove any arrow that should no longer exist. */
13092 if (overlay_arrows_changed_p ())
13093 consider_all_windows_p
= windows_or_buffers_changed
= 1;
13095 /* Normally the message* functions will have already displayed and
13096 updated the echo area, but the frame may have been trashed, or
13097 the update may have been preempted, so display the echo area
13098 again here. Checking message_cleared_p captures the case that
13099 the echo area should be cleared. */
13100 if ((!NILP (echo_area_buffer
[0]) && !display_last_displayed_message_p
)
13101 || (!NILP (echo_area_buffer
[1]) && display_last_displayed_message_p
)
13102 || (message_cleared_p
13103 && minibuf_level
== 0
13104 /* If the mini-window is currently selected, this means the
13105 echo-area doesn't show through. */
13106 && !MINI_WINDOW_P (XWINDOW (selected_window
))))
13108 int window_height_changed_p
= echo_area_display (0);
13110 if (message_cleared_p
)
13111 update_miniwindow_p
= 1;
13115 /* If we don't display the current message, don't clear the
13116 message_cleared_p flag, because, if we did, we wouldn't clear
13117 the echo area in the next redisplay which doesn't preserve
13119 if (!display_last_displayed_message_p
)
13120 message_cleared_p
= 0;
13122 if (fonts_changed_p
)
13124 else if (window_height_changed_p
)
13126 consider_all_windows_p
= 1;
13127 ++update_mode_lines
;
13128 ++windows_or_buffers_changed
;
13130 /* If window configuration was changed, frames may have been
13131 marked garbaged. Clear them or we will experience
13132 surprises wrt scrolling. */
13133 clear_garbaged_frames ();
13136 else if (EQ (selected_window
, minibuf_window
)
13137 && (current_buffer
->clip_changed
|| window_outdated (w
))
13138 && resize_mini_window (w
, 0))
13140 /* Resized active mini-window to fit the size of what it is
13141 showing if its contents might have changed. */
13143 /* FIXME: this causes all frames to be updated, which seems unnecessary
13144 since only the current frame needs to be considered. This function
13145 needs to be rewritten with two variables, consider_all_windows and
13146 consider_all_frames. */
13147 consider_all_windows_p
= 1;
13148 ++windows_or_buffers_changed
;
13149 ++update_mode_lines
;
13151 /* If window configuration was changed, frames may have been
13152 marked garbaged. Clear them or we will experience
13153 surprises wrt scrolling. */
13154 clear_garbaged_frames ();
13157 /* If showing the region, and mark has changed, we must redisplay
13158 the whole window. The assignment to this_line_start_pos prevents
13159 the optimization directly below this if-statement. */
13160 if (((!NILP (Vtransient_mark_mode
)
13161 && !NILP (BVAR (XBUFFER (w
->contents
), mark_active
)))
13162 != (w
->region_showing
> 0))
13163 || (w
->region_showing
13164 && w
->region_showing
13165 != XINT (Fmarker_position (BVAR (XBUFFER (w
->contents
), mark
)))))
13166 CHARPOS (this_line_start_pos
) = 0;
13168 /* Optimize the case that only the line containing the cursor in the
13169 selected window has changed. Variables starting with this_ are
13170 set in display_line and record information about the line
13171 containing the cursor. */
13172 tlbufpos
= this_line_start_pos
;
13173 tlendpos
= this_line_end_pos
;
13174 if (!consider_all_windows_p
13175 && CHARPOS (tlbufpos
) > 0
13176 && !w
->update_mode_line
13177 && !current_buffer
->clip_changed
13178 && !current_buffer
->prevent_redisplay_optimizations_p
13179 && FRAME_VISIBLE_P (XFRAME (w
->frame
))
13180 && !FRAME_OBSCURED_P (XFRAME (w
->frame
))
13181 /* Make sure recorded data applies to current buffer, etc. */
13182 && this_line_buffer
== current_buffer
13183 && current_buffer
== XBUFFER (w
->contents
)
13185 && !w
->optional_new_start
13186 /* Point must be on the line that we have info recorded about. */
13187 && PT
>= CHARPOS (tlbufpos
)
13188 && PT
<= Z
- CHARPOS (tlendpos
)
13189 /* All text outside that line, including its final newline,
13190 must be unchanged. */
13191 && text_outside_line_unchanged_p (w
, CHARPOS (tlbufpos
),
13192 CHARPOS (tlendpos
)))
13194 if (CHARPOS (tlbufpos
) > BEGV
13195 && FETCH_BYTE (BYTEPOS (tlbufpos
) - 1) != '\n'
13196 && (CHARPOS (tlbufpos
) == ZV
13197 || FETCH_BYTE (BYTEPOS (tlbufpos
)) == '\n'))
13198 /* Former continuation line has disappeared by becoming empty. */
13200 else if (window_outdated (w
) || MINI_WINDOW_P (w
))
13202 /* We have to handle the case of continuation around a
13203 wide-column character (see the comment in indent.c around
13206 For instance, in the following case:
13208 -------- Insert --------
13209 K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars.
13210 J_I_ ==> J_I_ `^^' are cursors.
13214 As we have to redraw the line above, we cannot use this
13218 int line_height_before
= this_line_pixel_height
;
13220 /* Note that start_display will handle the case that the
13221 line starting at tlbufpos is a continuation line. */
13222 start_display (&it
, w
, tlbufpos
);
13224 /* Implementation note: It this still necessary? */
13225 if (it
.current_x
!= this_line_start_x
)
13228 TRACE ((stderr
, "trying display optimization 1\n"));
13229 w
->cursor
.vpos
= -1;
13230 overlay_arrow_seen
= 0;
13231 it
.vpos
= this_line_vpos
;
13232 it
.current_y
= this_line_y
;
13233 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, this_line_vpos
);
13234 display_line (&it
);
13236 /* If line contains point, is not continued,
13237 and ends at same distance from eob as before, we win. */
13238 if (w
->cursor
.vpos
>= 0
13239 /* Line is not continued, otherwise this_line_start_pos
13240 would have been set to 0 in display_line. */
13241 && CHARPOS (this_line_start_pos
)
13242 /* Line ends as before. */
13243 && CHARPOS (this_line_end_pos
) == CHARPOS (tlendpos
)
13244 /* Line has same height as before. Otherwise other lines
13245 would have to be shifted up or down. */
13246 && this_line_pixel_height
== line_height_before
)
13248 /* If this is not the window's last line, we must adjust
13249 the charstarts of the lines below. */
13250 if (it
.current_y
< it
.last_visible_y
)
13252 struct glyph_row
*row
13253 = MATRIX_ROW (w
->current_matrix
, this_line_vpos
+ 1);
13254 ptrdiff_t delta
, delta_bytes
;
13256 /* We used to distinguish between two cases here,
13257 conditioned by Z - CHARPOS (tlendpos) == ZV, for
13258 when the line ends in a newline or the end of the
13259 buffer's accessible portion. But both cases did
13260 the same, so they were collapsed. */
13262 - CHARPOS (tlendpos
)
13263 - MATRIX_ROW_START_CHARPOS (row
));
13264 delta_bytes
= (Z_BYTE
13265 - BYTEPOS (tlendpos
)
13266 - MATRIX_ROW_START_BYTEPOS (row
));
13268 increment_matrix_positions (w
->current_matrix
,
13269 this_line_vpos
+ 1,
13270 w
->current_matrix
->nrows
,
13271 delta
, delta_bytes
);
13274 /* If this row displays text now but previously didn't,
13275 or vice versa, w->window_end_vpos may have to be
13277 if (MATRIX_ROW_DISPLAYS_TEXT_P (it
.glyph_row
- 1))
13279 if (XFASTINT (w
->window_end_vpos
) < this_line_vpos
)
13280 wset_window_end_vpos (w
, make_number (this_line_vpos
));
13282 else if (XFASTINT (w
->window_end_vpos
) == this_line_vpos
13283 && this_line_vpos
> 0)
13284 wset_window_end_vpos (w
, make_number (this_line_vpos
- 1));
13285 w
->window_end_valid
= 0;
13287 /* Update hint: No need to try to scroll in update_window. */
13288 w
->desired_matrix
->no_scrolling_p
= 1;
13291 *w
->desired_matrix
->method
= 0;
13292 debug_method_add (w
, "optimization 1");
13294 #ifdef HAVE_WINDOW_SYSTEM
13295 update_window_fringes (w
, 0);
13302 else if (/* Cursor position hasn't changed. */
13303 PT
== w
->last_point
13304 /* Make sure the cursor was last displayed
13305 in this window. Otherwise we have to reposition it. */
13306 && 0 <= w
->cursor
.vpos
13307 && w
->cursor
.vpos
< WINDOW_TOTAL_LINES (w
))
13311 do_pending_window_change (1);
13312 /* If selected_window changed, redisplay again. */
13313 if (WINDOWP (selected_window
)
13314 && (w
= XWINDOW (selected_window
)) != sw
)
13317 /* We used to always goto end_of_redisplay here, but this
13318 isn't enough if we have a blinking cursor. */
13319 if (w
->cursor_off_p
== w
->last_cursor_off_p
)
13320 goto end_of_redisplay
;
13324 /* If highlighting the region, or if the cursor is in the echo area,
13325 then we can't just move the cursor. */
13326 else if (! (!NILP (Vtransient_mark_mode
)
13327 && !NILP (BVAR (current_buffer
, mark_active
)))
13328 && (EQ (selected_window
,
13329 BVAR (current_buffer
, last_selected_window
))
13330 || highlight_nonselected_windows
)
13331 && !w
->region_showing
13332 && NILP (Vshow_trailing_whitespace
)
13333 && !cursor_in_echo_area
)
13336 struct glyph_row
*row
;
13338 /* Skip from tlbufpos to PT and see where it is. Note that
13339 PT may be in invisible text. If so, we will end at the
13340 next visible position. */
13341 init_iterator (&it
, w
, CHARPOS (tlbufpos
), BYTEPOS (tlbufpos
),
13342 NULL
, DEFAULT_FACE_ID
);
13343 it
.current_x
= this_line_start_x
;
13344 it
.current_y
= this_line_y
;
13345 it
.vpos
= this_line_vpos
;
13347 /* The call to move_it_to stops in front of PT, but
13348 moves over before-strings. */
13349 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
13351 if (it
.vpos
== this_line_vpos
13352 && (row
= MATRIX_ROW (w
->current_matrix
, this_line_vpos
),
13355 eassert (this_line_vpos
== it
.vpos
);
13356 eassert (this_line_y
== it
.current_y
);
13357 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
13359 *w
->desired_matrix
->method
= 0;
13360 debug_method_add (w
, "optimization 3");
13369 /* Text changed drastically or point moved off of line. */
13370 SET_MATRIX_ROW_ENABLED_P (w
->desired_matrix
, this_line_vpos
, 0);
13373 CHARPOS (this_line_start_pos
) = 0;
13374 consider_all_windows_p
|= buffer_shared_and_changed ();
13375 ++clear_face_cache_count
;
13376 #ifdef HAVE_WINDOW_SYSTEM
13377 ++clear_image_cache_count
;
13380 /* Build desired matrices, and update the display. If
13381 consider_all_windows_p is non-zero, do it for all windows on all
13382 frames. Otherwise do it for selected_window, only. */
13384 if (consider_all_windows_p
)
13386 FOR_EACH_FRAME (tail
, frame
)
13387 XFRAME (frame
)->updated_p
= 0;
13389 FOR_EACH_FRAME (tail
, frame
)
13391 struct frame
*f
= XFRAME (frame
);
13393 /* We don't have to do anything for unselected terminal
13395 if ((FRAME_TERMCAP_P (f
) || FRAME_MSDOS_P (f
))
13396 && !EQ (FRAME_TTY (f
)->top_frame
, frame
))
13399 if (FRAME_WINDOW_P (f
) || FRAME_TERMCAP_P (f
) || f
== sf
)
13401 /* Mark all the scroll bars to be removed; we'll redeem
13402 the ones we want when we redisplay their windows. */
13403 if (FRAME_TERMINAL (f
)->condemn_scroll_bars_hook
)
13404 FRAME_TERMINAL (f
)->condemn_scroll_bars_hook (f
);
13406 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13407 redisplay_windows (FRAME_ROOT_WINDOW (f
));
13409 /* The X error handler may have deleted that frame. */
13410 if (!FRAME_LIVE_P (f
))
13413 /* Any scroll bars which redisplay_windows should have
13414 nuked should now go away. */
13415 if (FRAME_TERMINAL (f
)->judge_scroll_bars_hook
)
13416 FRAME_TERMINAL (f
)->judge_scroll_bars_hook (f
);
13418 /* If fonts changed, display again. */
13419 /* ??? rms: I suspect it is a mistake to jump all the way
13420 back to retry here. It should just retry this frame. */
13421 if (fonts_changed_p
)
13424 if (FRAME_VISIBLE_P (f
) && !FRAME_OBSCURED_P (f
))
13426 /* See if we have to hscroll. */
13427 if (!f
->already_hscrolled_p
)
13429 f
->already_hscrolled_p
= 1;
13430 if (hscroll_windows (f
->root_window
))
13434 /* Prevent various kinds of signals during display
13435 update. stdio is not robust about handling
13436 signals, which can cause an apparent I/O
13438 if (interrupt_input
)
13439 unrequest_sigio ();
13442 /* Update the display. */
13443 set_window_update_flags (XWINDOW (f
->root_window
), 1);
13444 pending
|= update_frame (f
, 0, 0);
13450 eassert (EQ (XFRAME (selected_frame
)->selected_window
, selected_window
));
13454 /* Do the mark_window_display_accurate after all windows have
13455 been redisplayed because this call resets flags in buffers
13456 which are needed for proper redisplay. */
13457 FOR_EACH_FRAME (tail
, frame
)
13459 struct frame
*f
= XFRAME (frame
);
13462 mark_window_display_accurate (f
->root_window
, 1);
13463 if (FRAME_TERMINAL (f
)->frame_up_to_date_hook
)
13464 FRAME_TERMINAL (f
)->frame_up_to_date_hook (f
);
13469 else if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13471 Lisp_Object mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13472 struct frame
*mini_frame
;
13474 displayed_buffer
= XBUFFER (XWINDOW (selected_window
)->contents
);
13475 /* Use list_of_error, not Qerror, so that
13476 we catch only errors and don't run the debugger. */
13477 internal_condition_case_1 (redisplay_window_1
, selected_window
,
13479 redisplay_window_error
);
13480 if (update_miniwindow_p
)
13481 internal_condition_case_1 (redisplay_window_1
, mini_window
,
13483 redisplay_window_error
);
13485 /* Compare desired and current matrices, perform output. */
13488 /* If fonts changed, display again. */
13489 if (fonts_changed_p
)
13492 /* Prevent various kinds of signals during display update.
13493 stdio is not robust about handling signals,
13494 which can cause an apparent I/O error. */
13495 if (interrupt_input
)
13496 unrequest_sigio ();
13499 if (FRAME_VISIBLE_P (sf
) && !FRAME_OBSCURED_P (sf
))
13501 if (hscroll_windows (selected_window
))
13504 XWINDOW (selected_window
)->must_be_updated_p
= 1;
13505 pending
= update_frame (sf
, 0, 0);
13508 /* We may have called echo_area_display at the top of this
13509 function. If the echo area is on another frame, that may
13510 have put text on a frame other than the selected one, so the
13511 above call to update_frame would not have caught it. Catch
13513 mini_window
= FRAME_MINIBUF_WINDOW (sf
);
13514 mini_frame
= XFRAME (WINDOW_FRAME (XWINDOW (mini_window
)));
13516 if (mini_frame
!= sf
&& FRAME_WINDOW_P (mini_frame
))
13518 XWINDOW (mini_window
)->must_be_updated_p
= 1;
13519 pending
|= update_frame (mini_frame
, 0, 0);
13520 if (!pending
&& hscroll_windows (mini_window
))
13525 /* If display was paused because of pending input, make sure we do a
13526 thorough update the next time. */
13529 /* Prevent the optimization at the beginning of
13530 redisplay_internal that tries a single-line update of the
13531 line containing the cursor in the selected window. */
13532 CHARPOS (this_line_start_pos
) = 0;
13534 /* Let the overlay arrow be updated the next time. */
13535 update_overlay_arrows (0);
13537 /* If we pause after scrolling, some rows in the current
13538 matrices of some windows are not valid. */
13539 if (!WINDOW_FULL_WIDTH_P (w
)
13540 && !FRAME_WINDOW_P (XFRAME (w
->frame
)))
13541 update_mode_lines
= 1;
13545 if (!consider_all_windows_p
)
13547 /* This has already been done above if
13548 consider_all_windows_p is set. */
13549 mark_window_display_accurate_1 (w
, 1);
13551 /* Say overlay arrows are up to date. */
13552 update_overlay_arrows (1);
13554 if (FRAME_TERMINAL (sf
)->frame_up_to_date_hook
!= 0)
13555 FRAME_TERMINAL (sf
)->frame_up_to_date_hook (sf
);
13558 update_mode_lines
= 0;
13559 windows_or_buffers_changed
= 0;
13560 cursor_type_changed
= 0;
13563 /* Start SIGIO interrupts coming again. Having them off during the
13564 code above makes it less likely one will discard output, but not
13565 impossible, since there might be stuff in the system buffer here.
13566 But it is much hairier to try to do anything about that. */
13567 if (interrupt_input
)
13571 /* If a frame has become visible which was not before, redisplay
13572 again, so that we display it. Expose events for such a frame
13573 (which it gets when becoming visible) don't call the parts of
13574 redisplay constructing glyphs, so simply exposing a frame won't
13575 display anything in this case. So, we have to display these
13576 frames here explicitly. */
13581 FOR_EACH_FRAME (tail
, frame
)
13583 int this_is_visible
= 0;
13585 if (XFRAME (frame
)->visible
)
13586 this_is_visible
= 1;
13588 if (this_is_visible
)
13592 if (new_count
!= number_of_visible_frames
)
13593 windows_or_buffers_changed
++;
13596 /* Change frame size now if a change is pending. */
13597 do_pending_window_change (1);
13599 /* If we just did a pending size change, or have additional
13600 visible frames, or selected_window changed, redisplay again. */
13601 if ((windows_or_buffers_changed
&& !pending
)
13602 || (WINDOWP (selected_window
) && (w
= XWINDOW (selected_window
)) != sw
))
13605 /* Clear the face and image caches.
13607 We used to do this only if consider_all_windows_p. But the cache
13608 needs to be cleared if a timer creates images in the current
13609 buffer (e.g. the test case in Bug#6230). */
13611 if (clear_face_cache_count
> CLEAR_FACE_CACHE_COUNT
)
13613 clear_face_cache (0);
13614 clear_face_cache_count
= 0;
13617 #ifdef HAVE_WINDOW_SYSTEM
13618 if (clear_image_cache_count
> CLEAR_IMAGE_CACHE_COUNT
)
13620 clear_image_caches (Qnil
);
13621 clear_image_cache_count
= 0;
13623 #endif /* HAVE_WINDOW_SYSTEM */
13626 unbind_to (count
, Qnil
);
13631 /* Redisplay, but leave alone any recent echo area message unless
13632 another message has been requested in its place.
13634 This is useful in situations where you need to redisplay but no
13635 user action has occurred, making it inappropriate for the message
13636 area to be cleared. See tracking_off and
13637 wait_reading_process_output for examples of these situations.
13639 FROM_WHERE is an integer saying from where this function was
13640 called. This is useful for debugging. */
13643 redisplay_preserve_echo_area (int from_where
)
13645 TRACE ((stderr
, "redisplay_preserve_echo_area (%d)\n", from_where
));
13647 if (!NILP (echo_area_buffer
[1]))
13649 /* We have a previously displayed message, but no current
13650 message. Redisplay the previous message. */
13651 display_last_displayed_message_p
= 1;
13652 redisplay_internal ();
13653 display_last_displayed_message_p
= 0;
13656 redisplay_internal ();
13658 if (FRAME_RIF (SELECTED_FRAME ()) != NULL
13659 && FRAME_RIF (SELECTED_FRAME ())->flush_display_optional
)
13660 FRAME_RIF (SELECTED_FRAME ())->flush_display_optional (NULL
);
13664 /* Function registered with record_unwind_protect in redisplay_internal.
13665 Clear redisplaying_p. Also select the previously selected frame. */
13668 unwind_redisplay (Lisp_Object old_frame
)
13670 redisplaying_p
= 0;
13675 /* Mark the display of leaf window W as accurate or inaccurate.
13676 If ACCURATE_P is non-zero mark display of W as accurate. If
13677 ACCURATE_P is zero, arrange for W to be redisplayed the next
13678 time redisplay_internal is called. */
13681 mark_window_display_accurate_1 (struct window
*w
, int accurate_p
)
13683 struct buffer
*b
= XBUFFER (w
->contents
);
13685 w
->last_modified
= accurate_p
? BUF_MODIFF (b
) : 0;
13686 w
->last_overlay_modified
= accurate_p
? BUF_OVERLAY_MODIFF (b
) : 0;
13687 w
->last_had_star
= BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
);
13691 b
->clip_changed
= 0;
13692 b
->prevent_redisplay_optimizations_p
= 0;
13694 BUF_UNCHANGED_MODIFIED (b
) = BUF_MODIFF (b
);
13695 BUF_OVERLAY_UNCHANGED_MODIFIED (b
) = BUF_OVERLAY_MODIFF (b
);
13696 BUF_BEG_UNCHANGED (b
) = BUF_GPT (b
) - BUF_BEG (b
);
13697 BUF_END_UNCHANGED (b
) = BUF_Z (b
) - BUF_GPT (b
);
13699 w
->current_matrix
->buffer
= b
;
13700 w
->current_matrix
->begv
= BUF_BEGV (b
);
13701 w
->current_matrix
->zv
= BUF_ZV (b
);
13703 w
->last_cursor
= w
->cursor
;
13704 w
->last_cursor_off_p
= w
->cursor_off_p
;
13706 if (w
== XWINDOW (selected_window
))
13707 w
->last_point
= BUF_PT (b
);
13709 w
->last_point
= marker_position (w
->pointm
);
13711 w
->window_end_valid
= 1;
13712 w
->update_mode_line
= 0;
13717 /* Mark the display of windows in the window tree rooted at WINDOW as
13718 accurate or inaccurate. If ACCURATE_P is non-zero mark display of
13719 windows as accurate. If ACCURATE_P is zero, arrange for windows to
13720 be redisplayed the next time redisplay_internal is called. */
13723 mark_window_display_accurate (Lisp_Object window
, int accurate_p
)
13727 for (; !NILP (window
); window
= w
->next
)
13729 w
= XWINDOW (window
);
13730 if (WINDOWP (w
->contents
))
13731 mark_window_display_accurate (w
->contents
, accurate_p
);
13733 mark_window_display_accurate_1 (w
, accurate_p
);
13737 update_overlay_arrows (1);
13739 /* Force a thorough redisplay the next time by setting
13740 last_arrow_position and last_arrow_string to t, which is
13741 unequal to any useful value of Voverlay_arrow_... */
13742 update_overlay_arrows (-1);
13746 /* Return value in display table DP (Lisp_Char_Table *) for character
13747 C. Since a display table doesn't have any parent, we don't have to
13748 follow parent. Do not call this function directly but use the
13749 macro DISP_CHAR_VECTOR. */
13752 disp_char_vector (struct Lisp_Char_Table
*dp
, int c
)
13756 if (ASCII_CHAR_P (c
))
13759 if (SUB_CHAR_TABLE_P (val
))
13760 val
= XSUB_CHAR_TABLE (val
)->contents
[c
];
13766 XSETCHAR_TABLE (table
, dp
);
13767 val
= char_table_ref (table
, c
);
13776 /***********************************************************************
13778 ***********************************************************************/
13780 /* Redisplay all leaf windows in the window tree rooted at WINDOW. */
13783 redisplay_windows (Lisp_Object window
)
13785 while (!NILP (window
))
13787 struct window
*w
= XWINDOW (window
);
13789 if (WINDOWP (w
->contents
))
13790 redisplay_windows (w
->contents
);
13791 else if (BUFFERP (w
->contents
))
13793 displayed_buffer
= XBUFFER (w
->contents
);
13794 /* Use list_of_error, not Qerror, so that
13795 we catch only errors and don't run the debugger. */
13796 internal_condition_case_1 (redisplay_window_0
, window
,
13798 redisplay_window_error
);
13806 redisplay_window_error (Lisp_Object ignore
)
13808 displayed_buffer
->display_error_modiff
= BUF_MODIFF (displayed_buffer
);
13813 redisplay_window_0 (Lisp_Object window
)
13815 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13816 redisplay_window (window
, 0);
13821 redisplay_window_1 (Lisp_Object window
)
13823 if (displayed_buffer
->display_error_modiff
< BUF_MODIFF (displayed_buffer
))
13824 redisplay_window (window
, 1);
13829 /* Set cursor position of W. PT is assumed to be displayed in ROW.
13830 DELTA and DELTA_BYTES are the numbers of characters and bytes by
13831 which positions recorded in ROW differ from current buffer
13834 Return 0 if cursor is not on this row, 1 otherwise. */
13837 set_cursor_from_row (struct window
*w
, struct glyph_row
*row
,
13838 struct glyph_matrix
*matrix
,
13839 ptrdiff_t delta
, ptrdiff_t delta_bytes
,
13842 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
];
13843 struct glyph
*end
= glyph
+ row
->used
[TEXT_AREA
];
13844 struct glyph
*cursor
= NULL
;
13845 /* The last known character position in row. */
13846 ptrdiff_t last_pos
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13848 ptrdiff_t pt_old
= PT
- delta
;
13849 ptrdiff_t pos_before
= MATRIX_ROW_START_CHARPOS (row
) + delta
;
13850 ptrdiff_t pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
13851 struct glyph
*glyph_before
= glyph
- 1, *glyph_after
= end
;
13852 /* A glyph beyond the edge of TEXT_AREA which we should never
13854 struct glyph
*glyphs_end
= end
;
13855 /* Non-zero means we've found a match for cursor position, but that
13856 glyph has the avoid_cursor_p flag set. */
13857 int match_with_avoid_cursor
= 0;
13858 /* Non-zero means we've seen at least one glyph that came from a
13860 int string_seen
= 0;
13861 /* Largest and smallest buffer positions seen so far during scan of
13863 ptrdiff_t bpos_max
= pos_before
;
13864 ptrdiff_t bpos_min
= pos_after
;
13865 /* Last buffer position covered by an overlay string with an integer
13866 `cursor' property. */
13867 ptrdiff_t bpos_covered
= 0;
13868 /* Non-zero means the display string on which to display the cursor
13869 comes from a text property, not from an overlay. */
13870 int string_from_text_prop
= 0;
13872 /* Don't even try doing anything if called for a mode-line or
13873 header-line row, since the rest of the code isn't prepared to
13874 deal with such calamities. */
13875 eassert (!row
->mode_line_p
);
13876 if (row
->mode_line_p
)
13879 /* Skip over glyphs not having an object at the start and the end of
13880 the row. These are special glyphs like truncation marks on
13881 terminal frames. */
13882 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
13884 if (!row
->reversed_p
)
13887 && INTEGERP (glyph
->object
)
13888 && glyph
->charpos
< 0)
13890 x
+= glyph
->pixel_width
;
13894 && INTEGERP ((end
- 1)->object
)
13895 /* CHARPOS is zero for blanks and stretch glyphs
13896 inserted by extend_face_to_end_of_line. */
13897 && (end
- 1)->charpos
<= 0)
13899 glyph_before
= glyph
- 1;
13906 /* If the glyph row is reversed, we need to process it from back
13907 to front, so swap the edge pointers. */
13908 glyphs_end
= end
= glyph
- 1;
13909 glyph
+= row
->used
[TEXT_AREA
] - 1;
13911 while (glyph
> end
+ 1
13912 && INTEGERP (glyph
->object
)
13913 && glyph
->charpos
< 0)
13916 x
-= glyph
->pixel_width
;
13918 if (INTEGERP (glyph
->object
) && glyph
->charpos
< 0)
13920 /* By default, in reversed rows we put the cursor on the
13921 rightmost (first in the reading order) glyph. */
13922 for (g
= end
+ 1; g
< glyph
; g
++)
13923 x
+= g
->pixel_width
;
13925 && INTEGERP ((end
+ 1)->object
)
13926 && (end
+ 1)->charpos
<= 0)
13928 glyph_before
= glyph
+ 1;
13932 else if (row
->reversed_p
)
13934 /* In R2L rows that don't display text, put the cursor on the
13935 rightmost glyph. Case in point: an empty last line that is
13936 part of an R2L paragraph. */
13938 /* Avoid placing the cursor on the last glyph of the row, where
13939 on terminal frames we hold the vertical border between
13940 adjacent windows. */
13941 if (!FRAME_WINDOW_P (WINDOW_XFRAME (w
))
13942 && !WINDOW_RIGHTMOST_P (w
)
13943 && cursor
== row
->glyphs
[LAST_AREA
] - 1)
13945 x
= -1; /* will be computed below, at label compute_x */
13948 /* Step 1: Try to find the glyph whose character position
13949 corresponds to point. If that's not possible, find 2 glyphs
13950 whose character positions are the closest to point, one before
13951 point, the other after it. */
13952 if (!row
->reversed_p
)
13953 while (/* not marched to end of glyph row */
13955 /* glyph was not inserted by redisplay for internal purposes */
13956 && !INTEGERP (glyph
->object
))
13958 if (BUFFERP (glyph
->object
))
13960 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
13962 if (glyph
->charpos
> bpos_max
)
13963 bpos_max
= glyph
->charpos
;
13964 if (glyph
->charpos
< bpos_min
)
13965 bpos_min
= glyph
->charpos
;
13966 if (!glyph
->avoid_cursor_p
)
13968 /* If we hit point, we've found the glyph on which to
13969 display the cursor. */
13972 match_with_avoid_cursor
= 0;
13975 /* See if we've found a better approximation to
13976 POS_BEFORE or to POS_AFTER. */
13977 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
13979 pos_before
= glyph
->charpos
;
13980 glyph_before
= glyph
;
13982 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
13984 pos_after
= glyph
->charpos
;
13985 glyph_after
= glyph
;
13988 else if (dpos
== 0)
13989 match_with_avoid_cursor
= 1;
13991 else if (STRINGP (glyph
->object
))
13993 Lisp_Object chprop
;
13994 ptrdiff_t glyph_pos
= glyph
->charpos
;
13996 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
13998 if (!NILP (chprop
))
14000 /* If the string came from a `display' text property,
14001 look up the buffer position of that property and
14002 use that position to update bpos_max, as if we
14003 actually saw such a position in one of the row's
14004 glyphs. This helps with supporting integer values
14005 of `cursor' property on the display string in
14006 situations where most or all of the row's buffer
14007 text is completely covered by display properties,
14008 so that no glyph with valid buffer positions is
14009 ever seen in the row. */
14010 ptrdiff_t prop_pos
=
14011 string_buffer_position_lim (glyph
->object
, pos_before
,
14014 if (prop_pos
>= pos_before
)
14015 bpos_max
= prop_pos
- 1;
14017 if (INTEGERP (chprop
))
14019 bpos_covered
= bpos_max
+ XINT (chprop
);
14020 /* If the `cursor' property covers buffer positions up
14021 to and including point, we should display cursor on
14022 this glyph. Note that, if a `cursor' property on one
14023 of the string's characters has an integer value, we
14024 will break out of the loop below _before_ we get to
14025 the position match above. IOW, integer values of
14026 the `cursor' property override the "exact match for
14027 point" strategy of positioning the cursor. */
14028 /* Implementation note: bpos_max == pt_old when, e.g.,
14029 we are in an empty line, where bpos_max is set to
14030 MATRIX_ROW_START_CHARPOS, see above. */
14031 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14040 x
+= glyph
->pixel_width
;
14043 else if (glyph
> end
) /* row is reversed */
14044 while (!INTEGERP (glyph
->object
))
14046 if (BUFFERP (glyph
->object
))
14048 ptrdiff_t dpos
= glyph
->charpos
- pt_old
;
14050 if (glyph
->charpos
> bpos_max
)
14051 bpos_max
= glyph
->charpos
;
14052 if (glyph
->charpos
< bpos_min
)
14053 bpos_min
= glyph
->charpos
;
14054 if (!glyph
->avoid_cursor_p
)
14058 match_with_avoid_cursor
= 0;
14061 if (0 > dpos
&& dpos
> pos_before
- pt_old
)
14063 pos_before
= glyph
->charpos
;
14064 glyph_before
= glyph
;
14066 else if (0 < dpos
&& dpos
< pos_after
- pt_old
)
14068 pos_after
= glyph
->charpos
;
14069 glyph_after
= glyph
;
14072 else if (dpos
== 0)
14073 match_with_avoid_cursor
= 1;
14075 else if (STRINGP (glyph
->object
))
14077 Lisp_Object chprop
;
14078 ptrdiff_t glyph_pos
= glyph
->charpos
;
14080 chprop
= Fget_char_property (make_number (glyph_pos
), Qcursor
,
14082 if (!NILP (chprop
))
14084 ptrdiff_t prop_pos
=
14085 string_buffer_position_lim (glyph
->object
, pos_before
,
14088 if (prop_pos
>= pos_before
)
14089 bpos_max
= prop_pos
- 1;
14091 if (INTEGERP (chprop
))
14093 bpos_covered
= bpos_max
+ XINT (chprop
);
14094 /* If the `cursor' property covers buffer positions up
14095 to and including point, we should display cursor on
14097 if (bpos_max
<= pt_old
&& bpos_covered
>= pt_old
)
14106 if (glyph
== glyphs_end
) /* don't dereference outside TEXT_AREA */
14108 x
--; /* can't use any pixel_width */
14111 x
-= glyph
->pixel_width
;
14114 /* Step 2: If we didn't find an exact match for point, we need to
14115 look for a proper place to put the cursor among glyphs between
14116 GLYPH_BEFORE and GLYPH_AFTER. */
14117 if (!((row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14118 && BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14119 && !(bpos_max
< pt_old
&& pt_old
<= bpos_covered
))
14121 /* An empty line has a single glyph whose OBJECT is zero and
14122 whose CHARPOS is the position of a newline on that line.
14123 Note that on a TTY, there are more glyphs after that, which
14124 were produced by extend_face_to_end_of_line, but their
14125 CHARPOS is zero or negative. */
14127 (row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
)
14128 && INTEGERP (glyph
->object
) && glyph
->charpos
> 0
14129 /* On a TTY, continued and truncated rows also have a glyph at
14130 their end whose OBJECT is zero and whose CHARPOS is
14131 positive (the continuation and truncation glyphs), but such
14132 rows are obviously not "empty". */
14133 && !(row
->continued_p
|| row
->truncated_on_right_p
);
14135 if (row
->ends_in_ellipsis_p
&& pos_after
== last_pos
)
14137 ptrdiff_t ellipsis_pos
;
14139 /* Scan back over the ellipsis glyphs. */
14140 if (!row
->reversed_p
)
14142 ellipsis_pos
= (glyph
- 1)->charpos
;
14143 while (glyph
> row
->glyphs
[TEXT_AREA
]
14144 && (glyph
- 1)->charpos
== ellipsis_pos
)
14145 glyph
--, x
-= glyph
->pixel_width
;
14146 /* That loop always goes one position too far, including
14147 the glyph before the ellipsis. So scan forward over
14149 x
+= glyph
->pixel_width
;
14152 else /* row is reversed */
14154 ellipsis_pos
= (glyph
+ 1)->charpos
;
14155 while (glyph
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14156 && (glyph
+ 1)->charpos
== ellipsis_pos
)
14157 glyph
++, x
+= glyph
->pixel_width
;
14158 x
-= glyph
->pixel_width
;
14162 else if (match_with_avoid_cursor
)
14164 cursor
= glyph_after
;
14167 else if (string_seen
)
14169 int incr
= row
->reversed_p
? -1 : +1;
14171 /* Need to find the glyph that came out of a string which is
14172 present at point. That glyph is somewhere between
14173 GLYPH_BEFORE and GLYPH_AFTER, and it came from a string
14174 positioned between POS_BEFORE and POS_AFTER in the
14176 struct glyph
*start
, *stop
;
14177 ptrdiff_t pos
= pos_before
;
14181 /* If the row ends in a newline from a display string,
14182 reordering could have moved the glyphs belonging to the
14183 string out of the [GLYPH_BEFORE..GLYPH_AFTER] range. So
14184 in this case we extend the search to the last glyph in
14185 the row that was not inserted by redisplay. */
14186 if (row
->ends_in_newline_from_string_p
)
14189 pos_after
= MATRIX_ROW_END_CHARPOS (row
) + delta
;
14192 /* GLYPH_BEFORE and GLYPH_AFTER are the glyphs that
14193 correspond to POS_BEFORE and POS_AFTER, respectively. We
14194 need START and STOP in the order that corresponds to the
14195 row's direction as given by its reversed_p flag. If the
14196 directionality of characters between POS_BEFORE and
14197 POS_AFTER is the opposite of the row's base direction,
14198 these characters will have been reordered for display,
14199 and we need to reverse START and STOP. */
14200 if (!row
->reversed_p
)
14202 start
= min (glyph_before
, glyph_after
);
14203 stop
= max (glyph_before
, glyph_after
);
14207 start
= max (glyph_before
, glyph_after
);
14208 stop
= min (glyph_before
, glyph_after
);
14210 for (glyph
= start
+ incr
;
14211 row
->reversed_p
? glyph
> stop
: glyph
< stop
; )
14214 /* Any glyphs that come from the buffer are here because
14215 of bidi reordering. Skip them, and only pay
14216 attention to glyphs that came from some string. */
14217 if (STRINGP (glyph
->object
))
14221 /* If the display property covers the newline, we
14222 need to search for it one position farther. */
14223 ptrdiff_t lim
= pos_after
14224 + (pos_after
== MATRIX_ROW_END_CHARPOS (row
) + delta
);
14226 string_from_text_prop
= 0;
14227 str
= glyph
->object
;
14228 tem
= string_buffer_position_lim (str
, pos
, lim
, 0);
14229 if (tem
== 0 /* from overlay */
14232 /* If the string from which this glyph came is
14233 found in the buffer at point, or at position
14234 that is closer to point than pos_after, then
14235 we've found the glyph we've been looking for.
14236 If it comes from an overlay (tem == 0), and
14237 it has the `cursor' property on one of its
14238 glyphs, record that glyph as a candidate for
14239 displaying the cursor. (As in the
14240 unidirectional version, we will display the
14241 cursor on the last candidate we find.) */
14244 || (tem
- pt_old
> 0 && tem
< pos_after
))
14246 /* The glyphs from this string could have
14247 been reordered. Find the one with the
14248 smallest string position. Or there could
14249 be a character in the string with the
14250 `cursor' property, which means display
14251 cursor on that character's glyph. */
14252 ptrdiff_t strpos
= glyph
->charpos
;
14257 string_from_text_prop
= 1;
14260 (row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14261 && EQ (glyph
->object
, str
);
14265 ptrdiff_t gpos
= glyph
->charpos
;
14267 cprop
= Fget_char_property (make_number (gpos
),
14275 if (tem
&& glyph
->charpos
< strpos
)
14277 strpos
= glyph
->charpos
;
14283 || (tem
- pt_old
> 0 && tem
< pos_after
))
14287 pos
= tem
+ 1; /* don't find previous instances */
14289 /* This string is not what we want; skip all of the
14290 glyphs that came from it. */
14291 while ((row
->reversed_p
? glyph
> stop
: glyph
< stop
)
14292 && EQ (glyph
->object
, str
))
14299 /* If we reached the end of the line, and END was from a string,
14300 the cursor is not on this line. */
14302 && (row
->reversed_p
? glyph
<= end
: glyph
>= end
)
14303 && (row
->reversed_p
? end
> glyphs_end
: end
< glyphs_end
)
14304 && STRINGP (end
->object
)
14305 && row
->continued_p
)
14308 /* A truncated row may not include PT among its character positions.
14309 Setting the cursor inside the scroll margin will trigger
14310 recalculation of hscroll in hscroll_window_tree. But if a
14311 display string covers point, defer to the string-handling
14312 code below to figure this out. */
14313 else if (row
->truncated_on_left_p
&& pt_old
< bpos_min
)
14315 cursor
= glyph_before
;
14318 else if ((row
->truncated_on_right_p
&& pt_old
> bpos_max
)
14319 /* Zero-width characters produce no glyphs. */
14321 && (row
->reversed_p
14322 ? glyph_after
> glyphs_end
14323 : glyph_after
< glyphs_end
)))
14325 cursor
= glyph_after
;
14331 if (cursor
!= NULL
)
14333 else if (glyph
== glyphs_end
14334 && pos_before
== pos_after
14335 && STRINGP ((row
->reversed_p
14336 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14337 : row
->glyphs
[TEXT_AREA
])->object
))
14339 /* If all the glyphs of this row came from strings, put the
14340 cursor on the first glyph of the row. This avoids having the
14341 cursor outside of the text area in this very rare and hard
14345 ? row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1
14346 : row
->glyphs
[TEXT_AREA
];
14352 /* Need to compute x that corresponds to GLYPH. */
14353 for (g
= row
->glyphs
[TEXT_AREA
], x
= row
->x
; g
< glyph
; g
++)
14355 if (g
>= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
])
14357 x
+= g
->pixel_width
;
14361 /* ROW could be part of a continued line, which, under bidi
14362 reordering, might have other rows whose start and end charpos
14363 occlude point. Only set w->cursor if we found a better
14364 approximation to the cursor position than we have from previously
14365 examined candidate rows belonging to the same continued line. */
14366 if (/* we already have a candidate row */
14367 w
->cursor
.vpos
>= 0
14368 /* that candidate is not the row we are processing */
14369 && MATRIX_ROW (matrix
, w
->cursor
.vpos
) != row
14370 /* Make sure cursor.vpos specifies a row whose start and end
14371 charpos occlude point, and it is valid candidate for being a
14372 cursor-row. This is because some callers of this function
14373 leave cursor.vpos at the row where the cursor was displayed
14374 during the last redisplay cycle. */
14375 && MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
)) <= pt_old
14376 && pt_old
<= MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14377 && cursor_row_p (MATRIX_ROW (matrix
, w
->cursor
.vpos
)))
14380 MATRIX_ROW_GLYPH_START (matrix
, w
->cursor
.vpos
) + w
->cursor
.hpos
;
14382 /* Don't consider glyphs that are outside TEXT_AREA. */
14383 if (!(row
->reversed_p
? glyph
> glyphs_end
: glyph
< glyphs_end
))
14385 /* Keep the candidate whose buffer position is the closest to
14386 point or has the `cursor' property. */
14387 if (/* previous candidate is a glyph in TEXT_AREA of that row */
14388 w
->cursor
.hpos
>= 0
14389 && w
->cursor
.hpos
< MATRIX_ROW_USED (matrix
, w
->cursor
.vpos
)
14390 && ((BUFFERP (g1
->object
)
14391 && (g1
->charpos
== pt_old
/* an exact match always wins */
14392 || (BUFFERP (glyph
->object
)
14393 && eabs (g1
->charpos
- pt_old
)
14394 < eabs (glyph
->charpos
- pt_old
))))
14395 /* previous candidate is a glyph from a string that has
14396 a non-nil `cursor' property */
14397 || (STRINGP (g1
->object
)
14398 && (!NILP (Fget_char_property (make_number (g1
->charpos
),
14399 Qcursor
, g1
->object
))
14400 /* previous candidate is from the same display
14401 string as this one, and the display string
14402 came from a text property */
14403 || (EQ (g1
->object
, glyph
->object
)
14404 && string_from_text_prop
)
14405 /* this candidate is from newline and its
14406 position is not an exact match */
14407 || (INTEGERP (glyph
->object
)
14408 && glyph
->charpos
!= pt_old
)))))
14410 /* If this candidate gives an exact match, use that. */
14411 if (!((BUFFERP (glyph
->object
) && glyph
->charpos
== pt_old
)
14412 /* If this candidate is a glyph created for the
14413 terminating newline of a line, and point is on that
14414 newline, it wins because it's an exact match. */
14415 || (!row
->continued_p
14416 && INTEGERP (glyph
->object
)
14417 && glyph
->charpos
== 0
14418 && pt_old
== MATRIX_ROW_END_CHARPOS (row
) - 1))
14419 /* Otherwise, keep the candidate that comes from a row
14420 spanning less buffer positions. This may win when one or
14421 both candidate positions are on glyphs that came from
14422 display strings, for which we cannot compare buffer
14424 && MATRIX_ROW_END_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14425 - MATRIX_ROW_START_CHARPOS (MATRIX_ROW (matrix
, w
->cursor
.vpos
))
14426 < MATRIX_ROW_END_CHARPOS (row
) - MATRIX_ROW_START_CHARPOS (row
))
14429 w
->cursor
.hpos
= glyph
- row
->glyphs
[TEXT_AREA
];
14431 w
->cursor
.vpos
= MATRIX_ROW_VPOS (row
, matrix
) + dvpos
;
14432 w
->cursor
.y
= row
->y
+ dy
;
14434 if (w
== XWINDOW (selected_window
))
14436 if (!row
->continued_p
14437 && !MATRIX_ROW_CONTINUATION_LINE_P (row
)
14440 this_line_buffer
= XBUFFER (w
->contents
);
14442 CHARPOS (this_line_start_pos
)
14443 = MATRIX_ROW_START_CHARPOS (row
) + delta
;
14444 BYTEPOS (this_line_start_pos
)
14445 = MATRIX_ROW_START_BYTEPOS (row
) + delta_bytes
;
14447 CHARPOS (this_line_end_pos
)
14448 = Z
- (MATRIX_ROW_END_CHARPOS (row
) + delta
);
14449 BYTEPOS (this_line_end_pos
)
14450 = Z_BYTE
- (MATRIX_ROW_END_BYTEPOS (row
) + delta_bytes
);
14452 this_line_y
= w
->cursor
.y
;
14453 this_line_pixel_height
= row
->height
;
14454 this_line_vpos
= w
->cursor
.vpos
;
14455 this_line_start_x
= row
->x
;
14458 CHARPOS (this_line_start_pos
) = 0;
14465 /* Run window scroll functions, if any, for WINDOW with new window
14466 start STARTP. Sets the window start of WINDOW to that position.
14468 We assume that the window's buffer is really current. */
14470 static struct text_pos
14471 run_window_scroll_functions (Lisp_Object window
, struct text_pos startp
)
14473 struct window
*w
= XWINDOW (window
);
14474 SET_MARKER_FROM_TEXT_POS (w
->start
, startp
);
14476 if (current_buffer
!= XBUFFER (w
->contents
))
14479 if (!NILP (Vwindow_scroll_functions
))
14481 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
14482 make_number (CHARPOS (startp
)));
14483 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14484 /* In case the hook functions switch buffers. */
14485 set_buffer_internal (XBUFFER (w
->contents
));
14492 /* Make sure the line containing the cursor is fully visible.
14493 A value of 1 means there is nothing to be done.
14494 (Either the line is fully visible, or it cannot be made so,
14495 or we cannot tell.)
14497 If FORCE_P is non-zero, return 0 even if partial visible cursor row
14498 is higher than window.
14500 A value of 0 means the caller should do scrolling
14501 as if point had gone off the screen. */
14504 cursor_row_fully_visible_p (struct window
*w
, int force_p
, int current_matrix_p
)
14506 struct glyph_matrix
*matrix
;
14507 struct glyph_row
*row
;
14510 if (!make_cursor_line_fully_visible_p
)
14513 /* It's not always possible to find the cursor, e.g, when a window
14514 is full of overlay strings. Don't do anything in that case. */
14515 if (w
->cursor
.vpos
< 0)
14518 matrix
= current_matrix_p
? w
->current_matrix
: w
->desired_matrix
;
14519 row
= MATRIX_ROW (matrix
, w
->cursor
.vpos
);
14521 /* If the cursor row is not partially visible, there's nothing to do. */
14522 if (!MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, row
))
14525 /* If the row the cursor is in is taller than the window's height,
14526 it's not clear what to do, so do nothing. */
14527 window_height
= window_box_height (w
);
14528 if (row
->height
>= window_height
)
14530 if (!force_p
|| MINI_WINDOW_P (w
)
14531 || w
->vscroll
|| w
->cursor
.vpos
== 0)
14538 /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P
14539 non-zero means only WINDOW is redisplayed in redisplay_internal.
14540 TEMP_SCROLL_STEP has the same meaning as emacs_scroll_step, and is used
14541 in redisplay_window to bring a partially visible line into view in
14542 the case that only the cursor has moved.
14544 LAST_LINE_MISFIT should be nonzero if we're scrolling because the
14545 last screen line's vertical height extends past the end of the screen.
14549 1 if scrolling succeeded
14551 0 if scrolling didn't find point.
14553 -1 if new fonts have been loaded so that we must interrupt
14554 redisplay, adjust glyph matrices, and try again. */
14560 SCROLLING_NEED_LARGER_MATRICES
14563 /* If scroll-conservatively is more than this, never recenter.
14565 If you change this, don't forget to update the doc string of
14566 `scroll-conservatively' and the Emacs manual. */
14567 #define SCROLL_LIMIT 100
14570 try_scrolling (Lisp_Object window
, int just_this_one_p
,
14571 ptrdiff_t arg_scroll_conservatively
, ptrdiff_t scroll_step
,
14572 int temp_scroll_step
, int last_line_misfit
)
14574 struct window
*w
= XWINDOW (window
);
14575 struct frame
*f
= XFRAME (w
->frame
);
14576 struct text_pos pos
, startp
;
14578 int this_scroll_margin
, scroll_max
, rc
, height
;
14579 int dy
= 0, amount_to_scroll
= 0, scroll_down_p
= 0;
14580 int extra_scroll_margin_lines
= last_line_misfit
? 1 : 0;
14581 Lisp_Object aggressive
;
14582 /* We will never try scrolling more than this number of lines. */
14583 int scroll_limit
= SCROLL_LIMIT
;
14584 int frame_line_height
= default_line_pixel_height (w
);
14585 int window_total_lines
14586 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
14589 debug_method_add (w
, "try_scrolling");
14592 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
14594 /* Compute scroll margin height in pixels. We scroll when point is
14595 within this distance from the top or bottom of the window. */
14596 if (scroll_margin
> 0)
14597 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4)
14598 * frame_line_height
;
14600 this_scroll_margin
= 0;
14602 /* Force arg_scroll_conservatively to have a reasonable value, to
14603 avoid scrolling too far away with slow move_it_* functions. Note
14604 that the user can supply scroll-conservatively equal to
14605 `most-positive-fixnum', which can be larger than INT_MAX. */
14606 if (arg_scroll_conservatively
> scroll_limit
)
14608 arg_scroll_conservatively
= scroll_limit
+ 1;
14609 scroll_max
= scroll_limit
* frame_line_height
;
14611 else if (scroll_step
|| arg_scroll_conservatively
|| temp_scroll_step
)
14612 /* Compute how much we should try to scroll maximally to bring
14613 point into view. */
14614 scroll_max
= (max (scroll_step
,
14615 max (arg_scroll_conservatively
, temp_scroll_step
))
14616 * frame_line_height
);
14617 else if (NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
))
14618 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
)))
14619 /* We're trying to scroll because of aggressive scrolling but no
14620 scroll_step is set. Choose an arbitrary one. */
14621 scroll_max
= 10 * frame_line_height
;
14627 /* Decide whether to scroll down. */
14628 if (PT
> CHARPOS (startp
))
14630 int scroll_margin_y
;
14632 /* Compute the pixel ypos of the scroll margin, then move IT to
14633 either that ypos or PT, whichever comes first. */
14634 start_display (&it
, w
, startp
);
14635 scroll_margin_y
= it
.last_visible_y
- this_scroll_margin
14636 - frame_line_height
* extra_scroll_margin_lines
;
14637 move_it_to (&it
, PT
, -1, scroll_margin_y
- 1, -1,
14638 (MOVE_TO_POS
| MOVE_TO_Y
));
14640 if (PT
> CHARPOS (it
.current
.pos
))
14642 int y0
= line_bottom_y (&it
);
14643 /* Compute how many pixels below window bottom to stop searching
14644 for PT. This avoids costly search for PT that is far away if
14645 the user limited scrolling by a small number of lines, but
14646 always finds PT if scroll_conservatively is set to a large
14647 number, such as most-positive-fixnum. */
14648 int slack
= max (scroll_max
, 10 * frame_line_height
);
14649 int y_to_move
= it
.last_visible_y
+ slack
;
14651 /* Compute the distance from the scroll margin to PT or to
14652 the scroll limit, whichever comes first. This should
14653 include the height of the cursor line, to make that line
14655 move_it_to (&it
, PT
, -1, y_to_move
,
14656 -1, MOVE_TO_POS
| MOVE_TO_Y
);
14657 dy
= line_bottom_y (&it
) - y0
;
14659 if (dy
> scroll_max
)
14660 return SCROLLING_FAILED
;
14669 /* Point is in or below the bottom scroll margin, so move the
14670 window start down. If scrolling conservatively, move it just
14671 enough down to make point visible. If scroll_step is set,
14672 move it down by scroll_step. */
14673 if (arg_scroll_conservatively
)
14675 = min (max (dy
, frame_line_height
),
14676 frame_line_height
* arg_scroll_conservatively
);
14677 else if (scroll_step
|| temp_scroll_step
)
14678 amount_to_scroll
= scroll_max
;
14681 aggressive
= BVAR (current_buffer
, scroll_up_aggressively
);
14682 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14683 if (NUMBERP (aggressive
))
14685 double float_amount
= XFLOATINT (aggressive
) * height
;
14686 int aggressive_scroll
= float_amount
;
14687 if (aggressive_scroll
== 0 && float_amount
> 0)
14688 aggressive_scroll
= 1;
14689 /* Don't let point enter the scroll margin near top of
14690 the window. This could happen if the value of
14691 scroll_up_aggressively is too large and there are
14692 non-zero margins, because scroll_up_aggressively
14693 means put point that fraction of window height
14694 _from_the_bottom_margin_. */
14695 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14696 aggressive_scroll
= height
- 2*this_scroll_margin
;
14697 amount_to_scroll
= dy
+ aggressive_scroll
;
14701 if (amount_to_scroll
<= 0)
14702 return SCROLLING_FAILED
;
14704 start_display (&it
, w
, startp
);
14705 if (arg_scroll_conservatively
<= scroll_limit
)
14706 move_it_vertically (&it
, amount_to_scroll
);
14709 /* Extra precision for users who set scroll-conservatively
14710 to a large number: make sure the amount we scroll
14711 the window start is never less than amount_to_scroll,
14712 which was computed as distance from window bottom to
14713 point. This matters when lines at window top and lines
14714 below window bottom have different height. */
14716 void *it1data
= NULL
;
14717 /* We use a temporary it1 because line_bottom_y can modify
14718 its argument, if it moves one line down; see there. */
14721 SAVE_IT (it1
, it
, it1data
);
14722 start_y
= line_bottom_y (&it1
);
14724 RESTORE_IT (&it
, &it
, it1data
);
14725 move_it_by_lines (&it
, 1);
14726 SAVE_IT (it1
, it
, it1data
);
14727 } while (line_bottom_y (&it1
) - start_y
< amount_to_scroll
);
14730 /* If STARTP is unchanged, move it down another screen line. */
14731 if (CHARPOS (it
.current
.pos
) == CHARPOS (startp
))
14732 move_it_by_lines (&it
, 1);
14733 startp
= it
.current
.pos
;
14737 struct text_pos scroll_margin_pos
= startp
;
14740 /* See if point is inside the scroll margin at the top of the
14742 if (this_scroll_margin
)
14746 start_display (&it
, w
, startp
);
14747 y_start
= it
.current_y
;
14748 move_it_vertically (&it
, this_scroll_margin
);
14749 scroll_margin_pos
= it
.current
.pos
;
14750 /* If we didn't move enough before hitting ZV, request
14751 additional amount of scroll, to move point out of the
14753 if (IT_CHARPOS (it
) == ZV
14754 && it
.current_y
- y_start
< this_scroll_margin
)
14755 y_offset
= this_scroll_margin
- (it
.current_y
- y_start
);
14758 if (PT
< CHARPOS (scroll_margin_pos
))
14760 /* Point is in the scroll margin at the top of the window or
14761 above what is displayed in the window. */
14764 /* Compute the vertical distance from PT to the scroll
14765 margin position. Move as far as scroll_max allows, or
14766 one screenful, or 10 screen lines, whichever is largest.
14767 Give up if distance is greater than scroll_max or if we
14768 didn't reach the scroll margin position. */
14769 SET_TEXT_POS (pos
, PT
, PT_BYTE
);
14770 start_display (&it
, w
, pos
);
14772 y_to_move
= max (it
.last_visible_y
,
14773 max (scroll_max
, 10 * frame_line_height
));
14774 move_it_to (&it
, CHARPOS (scroll_margin_pos
), 0,
14776 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
14777 dy
= it
.current_y
- y0
;
14778 if (dy
> scroll_max
14779 || IT_CHARPOS (it
) < CHARPOS (scroll_margin_pos
))
14780 return SCROLLING_FAILED
;
14782 /* Additional scroll for when ZV was too close to point. */
14785 /* Compute new window start. */
14786 start_display (&it
, w
, startp
);
14788 if (arg_scroll_conservatively
)
14789 amount_to_scroll
= max (dy
, frame_line_height
*
14790 max (scroll_step
, temp_scroll_step
));
14791 else if (scroll_step
|| temp_scroll_step
)
14792 amount_to_scroll
= scroll_max
;
14795 aggressive
= BVAR (current_buffer
, scroll_down_aggressively
);
14796 height
= WINDOW_BOX_TEXT_HEIGHT (w
);
14797 if (NUMBERP (aggressive
))
14799 double float_amount
= XFLOATINT (aggressive
) * height
;
14800 int aggressive_scroll
= float_amount
;
14801 if (aggressive_scroll
== 0 && float_amount
> 0)
14802 aggressive_scroll
= 1;
14803 /* Don't let point enter the scroll margin near
14804 bottom of the window, if the value of
14805 scroll_down_aggressively happens to be too
14807 if (aggressive_scroll
+ 2*this_scroll_margin
> height
)
14808 aggressive_scroll
= height
- 2*this_scroll_margin
;
14809 amount_to_scroll
= dy
+ aggressive_scroll
;
14813 if (amount_to_scroll
<= 0)
14814 return SCROLLING_FAILED
;
14816 move_it_vertically_backward (&it
, amount_to_scroll
);
14817 startp
= it
.current
.pos
;
14821 /* Run window scroll functions. */
14822 startp
= run_window_scroll_functions (window
, startp
);
14824 /* Display the window. Give up if new fonts are loaded, or if point
14826 if (!try_window (window
, startp
, 0))
14827 rc
= SCROLLING_NEED_LARGER_MATRICES
;
14828 else if (w
->cursor
.vpos
< 0)
14830 clear_glyph_matrix (w
->desired_matrix
);
14831 rc
= SCROLLING_FAILED
;
14835 /* Maybe forget recorded base line for line number display. */
14836 if (!just_this_one_p
14837 || current_buffer
->clip_changed
14838 || BEG_UNCHANGED
< CHARPOS (startp
))
14839 w
->base_line_number
= 0;
14841 /* If cursor ends up on a partially visible line,
14842 treat that as being off the bottom of the screen. */
14843 if (! cursor_row_fully_visible_p (w
, extra_scroll_margin_lines
<= 1, 0)
14844 /* It's possible that the cursor is on the first line of the
14845 buffer, which is partially obscured due to a vscroll
14846 (Bug#7537). In that case, avoid looping forever . */
14847 && extra_scroll_margin_lines
< w
->desired_matrix
->nrows
- 1)
14849 clear_glyph_matrix (w
->desired_matrix
);
14850 ++extra_scroll_margin_lines
;
14853 rc
= SCROLLING_SUCCESS
;
14860 /* Compute a suitable window start for window W if display of W starts
14861 on a continuation line. Value is non-zero if a new window start
14864 The new window start will be computed, based on W's width, starting
14865 from the start of the continued line. It is the start of the
14866 screen line with the minimum distance from the old start W->start. */
14869 compute_window_start_on_continuation_line (struct window
*w
)
14871 struct text_pos pos
, start_pos
;
14872 int window_start_changed_p
= 0;
14874 SET_TEXT_POS_FROM_MARKER (start_pos
, w
->start
);
14876 /* If window start is on a continuation line... Window start may be
14877 < BEGV in case there's invisible text at the start of the
14878 buffer (M-x rmail, for example). */
14879 if (CHARPOS (start_pos
) > BEGV
14880 && FETCH_BYTE (BYTEPOS (start_pos
) - 1) != '\n')
14883 struct glyph_row
*row
;
14885 /* Handle the case that the window start is out of range. */
14886 if (CHARPOS (start_pos
) < BEGV
)
14887 SET_TEXT_POS (start_pos
, BEGV
, BEGV_BYTE
);
14888 else if (CHARPOS (start_pos
) > ZV
)
14889 SET_TEXT_POS (start_pos
, ZV
, ZV_BYTE
);
14891 /* Find the start of the continued line. This should be fast
14892 because find_newline is fast (newline cache). */
14893 row
= w
->desired_matrix
->rows
+ (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0);
14894 init_iterator (&it
, w
, CHARPOS (start_pos
), BYTEPOS (start_pos
),
14895 row
, DEFAULT_FACE_ID
);
14896 reseat_at_previous_visible_line_start (&it
);
14898 /* If the line start is "too far" away from the window start,
14899 say it takes too much time to compute a new window start. */
14900 if (CHARPOS (start_pos
) - IT_CHARPOS (it
)
14901 < WINDOW_TOTAL_LINES (w
) * WINDOW_TOTAL_COLS (w
))
14903 int min_distance
, distance
;
14905 /* Move forward by display lines to find the new window
14906 start. If window width was enlarged, the new start can
14907 be expected to be > the old start. If window width was
14908 decreased, the new window start will be < the old start.
14909 So, we're looking for the display line start with the
14910 minimum distance from the old window start. */
14911 pos
= it
.current
.pos
;
14912 min_distance
= INFINITY
;
14913 while ((distance
= eabs (CHARPOS (start_pos
) - IT_CHARPOS (it
))),
14914 distance
< min_distance
)
14916 min_distance
= distance
;
14917 pos
= it
.current
.pos
;
14918 move_it_by_lines (&it
, 1);
14921 /* Set the window start there. */
14922 SET_MARKER_FROM_TEXT_POS (w
->start
, pos
);
14923 window_start_changed_p
= 1;
14927 return window_start_changed_p
;
14931 /* Try cursor movement in case text has not changed in window WINDOW,
14932 with window start STARTP. Value is
14934 CURSOR_MOVEMENT_SUCCESS if successful
14936 CURSOR_MOVEMENT_CANNOT_BE_USED if this method cannot be used
14938 CURSOR_MOVEMENT_MUST_SCROLL if we know we have to scroll the
14939 display. *SCROLL_STEP is set to 1, under certain circumstances, if
14940 we want to scroll as if scroll-step were set to 1. See the code.
14942 CURSOR_MOVEMENT_NEED_LARGER_MATRICES if we need larger matrices, in
14943 which case we have to abort this redisplay, and adjust matrices
14948 CURSOR_MOVEMENT_SUCCESS
,
14949 CURSOR_MOVEMENT_CANNOT_BE_USED
,
14950 CURSOR_MOVEMENT_MUST_SCROLL
,
14951 CURSOR_MOVEMENT_NEED_LARGER_MATRICES
14955 try_cursor_movement (Lisp_Object window
, struct text_pos startp
, int *scroll_step
)
14957 struct window
*w
= XWINDOW (window
);
14958 struct frame
*f
= XFRAME (w
->frame
);
14959 int rc
= CURSOR_MOVEMENT_CANNOT_BE_USED
;
14962 if (inhibit_try_cursor_movement
)
14966 /* Previously, there was a check for Lisp integer in the
14967 if-statement below. Now, this field is converted to
14968 ptrdiff_t, thus zero means invalid position in a buffer. */
14969 eassert (w
->last_point
> 0);
14971 /* Handle case where text has not changed, only point, and it has
14972 not moved off the frame. */
14973 if (/* Point may be in this window. */
14974 PT
>= CHARPOS (startp
)
14975 /* Selective display hasn't changed. */
14976 && !current_buffer
->clip_changed
14977 /* Function force-mode-line-update is used to force a thorough
14978 redisplay. It sets either windows_or_buffers_changed or
14979 update_mode_lines. So don't take a shortcut here for these
14981 && !update_mode_lines
14982 && !windows_or_buffers_changed
14983 && !cursor_type_changed
14984 /* Can't use this case if highlighting a region. When a
14985 region exists, cursor movement has to do more than just
14987 && markpos_of_region () < 0
14988 && !w
->region_showing
14989 && NILP (Vshow_trailing_whitespace
)
14990 /* This code is not used for mini-buffer for the sake of the case
14991 of redisplaying to replace an echo area message; since in
14992 that case the mini-buffer contents per se are usually
14993 unchanged. This code is of no real use in the mini-buffer
14994 since the handling of this_line_start_pos, etc., in redisplay
14995 handles the same cases. */
14996 && !EQ (window
, minibuf_window
)
14997 /* When splitting windows or for new windows, it happens that
14998 redisplay is called with a nil window_end_vpos or one being
14999 larger than the window. This should really be fixed in
15000 window.c. I don't have this on my list, now, so we do
15001 approximately the same as the old redisplay code. --gerd. */
15002 && INTEGERP (w
->window_end_vpos
)
15003 && XFASTINT (w
->window_end_vpos
) < w
->current_matrix
->nrows
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
) - XFASTINT (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
15338 fonts_changed_p. In that case, redisplay_internal will
15342 redisplay_window (Lisp_Object window
, int just_this_one_p
)
15344 struct window
*w
= XWINDOW (window
);
15345 struct frame
*f
= XFRAME (w
->frame
);
15346 struct buffer
*buffer
= XBUFFER (w
->contents
);
15347 struct buffer
*old
= current_buffer
;
15348 struct text_pos lpoint
, opoint
, startp
;
15349 int update_mode_line
;
15352 /* Record it now because it's overwritten. */
15353 int current_matrix_up_to_date_p
= 0;
15354 int used_current_matrix_p
= 0;
15355 /* This is less strict than current_matrix_up_to_date_p.
15356 It indicates that the buffer contents and narrowing are unchanged. */
15357 int buffer_unchanged_p
= 0;
15358 int temp_scroll_step
= 0;
15359 ptrdiff_t count
= SPECPDL_INDEX ();
15361 int centering_position
= -1;
15362 int last_line_misfit
= 0;
15363 ptrdiff_t beg_unchanged
, end_unchanged
;
15364 int frame_line_height
;
15366 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15370 *w
->desired_matrix
->method
= 0;
15373 /* Make sure that both W's markers are valid. */
15374 eassert (XMARKER (w
->start
)->buffer
== buffer
);
15375 eassert (XMARKER (w
->pointm
)->buffer
== buffer
);
15378 reconsider_clip_changes (w
, buffer
);
15379 frame_line_height
= default_line_pixel_height (w
);
15381 /* Has the mode line to be updated? */
15382 update_mode_line
= (w
->update_mode_line
15383 || update_mode_lines
15384 || buffer
->clip_changed
15385 || buffer
->prevent_redisplay_optimizations_p
);
15387 if (MINI_WINDOW_P (w
))
15389 if (w
== XWINDOW (echo_area_window
)
15390 && !NILP (echo_area_buffer
[0]))
15392 if (update_mode_line
)
15393 /* We may have to update a tty frame's menu bar or a
15394 tool-bar. Example `M-x C-h C-h C-g'. */
15395 goto finish_menu_bars
;
15397 /* We've already displayed the echo area glyphs in this window. */
15398 goto finish_scroll_bars
;
15400 else if ((w
!= XWINDOW (minibuf_window
)
15401 || minibuf_level
== 0)
15402 /* When buffer is nonempty, redisplay window normally. */
15403 && BUF_Z (XBUFFER (w
->contents
)) == BUF_BEG (XBUFFER (w
->contents
))
15404 /* Quail displays non-mini buffers in minibuffer window.
15405 In that case, redisplay the window normally. */
15406 && !NILP (Fmemq (w
->contents
, Vminibuffer_list
)))
15408 /* W is a mini-buffer window, but it's not active, so clear
15410 int yb
= window_text_bottom_y (w
);
15411 struct glyph_row
*row
;
15414 for (y
= 0, row
= w
->desired_matrix
->rows
;
15416 y
+= row
->height
, ++row
)
15417 blank_row (w
, row
, y
);
15418 goto finish_scroll_bars
;
15421 clear_glyph_matrix (w
->desired_matrix
);
15424 /* Otherwise set up data on this window; select its buffer and point
15426 /* Really select the buffer, for the sake of buffer-local
15428 set_buffer_internal_1 (XBUFFER (w
->contents
));
15430 current_matrix_up_to_date_p
15431 = (w
->window_end_valid
15432 && !current_buffer
->clip_changed
15433 && !current_buffer
->prevent_redisplay_optimizations_p
15434 && !window_outdated (w
));
15436 /* Run the window-bottom-change-functions
15437 if it is possible that the text on the screen has changed
15438 (either due to modification of the text, or any other reason). */
15439 if (!current_matrix_up_to_date_p
15440 && !NILP (Vwindow_text_change_functions
))
15442 safe_run_hooks (Qwindow_text_change_functions
);
15446 beg_unchanged
= BEG_UNCHANGED
;
15447 end_unchanged
= END_UNCHANGED
;
15449 SET_TEXT_POS (opoint
, PT
, PT_BYTE
);
15451 specbind (Qinhibit_point_motion_hooks
, Qt
);
15454 = (w
->window_end_valid
15455 && !current_buffer
->clip_changed
15456 && !window_outdated (w
));
15458 /* When windows_or_buffers_changed is non-zero, we can't rely on
15459 the window end being valid, so set it to nil there. */
15460 if (windows_or_buffers_changed
)
15462 /* If window starts on a continuation line, maybe adjust the
15463 window start in case the window's width changed. */
15464 if (XMARKER (w
->start
)->buffer
== current_buffer
)
15465 compute_window_start_on_continuation_line (w
);
15467 w
->window_end_valid
= 0;
15470 /* Some sanity checks. */
15471 CHECK_WINDOW_END (w
);
15472 if (Z
== Z_BYTE
&& CHARPOS (opoint
) != BYTEPOS (opoint
))
15474 if (BYTEPOS (opoint
) < CHARPOS (opoint
))
15477 if (mode_line_update_needed (w
))
15478 update_mode_line
= 1;
15480 /* Point refers normally to the selected window. For any other
15481 window, set up appropriate value. */
15482 if (!EQ (window
, selected_window
))
15484 ptrdiff_t new_pt
= marker_position (w
->pointm
);
15485 ptrdiff_t new_pt_byte
= marker_byte_position (w
->pointm
);
15489 new_pt_byte
= BEGV_BYTE
;
15490 set_marker_both (w
->pointm
, Qnil
, BEGV
, BEGV_BYTE
);
15492 else if (new_pt
> (ZV
- 1))
15495 new_pt_byte
= ZV_BYTE
;
15496 set_marker_both (w
->pointm
, Qnil
, ZV
, ZV_BYTE
);
15499 /* We don't use SET_PT so that the point-motion hooks don't run. */
15500 TEMP_SET_PT_BOTH (new_pt
, new_pt_byte
);
15503 /* If any of the character widths specified in the display table
15504 have changed, invalidate the width run cache. It's true that
15505 this may be a bit late to catch such changes, but the rest of
15506 redisplay goes (non-fatally) haywire when the display table is
15507 changed, so why should we worry about doing any better? */
15508 if (current_buffer
->width_run_cache
)
15510 struct Lisp_Char_Table
*disptab
= buffer_display_table ();
15512 if (! disptab_matches_widthtab
15513 (disptab
, XVECTOR (BVAR (current_buffer
, width_table
))))
15515 invalidate_region_cache (current_buffer
,
15516 current_buffer
->width_run_cache
,
15518 recompute_width_table (current_buffer
, disptab
);
15522 /* If window-start is screwed up, choose a new one. */
15523 if (XMARKER (w
->start
)->buffer
!= current_buffer
)
15526 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15528 /* If someone specified a new starting point but did not insist,
15529 check whether it can be used. */
15530 if (w
->optional_new_start
15531 && CHARPOS (startp
) >= BEGV
15532 && CHARPOS (startp
) <= ZV
)
15534 w
->optional_new_start
= 0;
15535 start_display (&it
, w
, startp
);
15536 move_it_to (&it
, PT
, 0, it
.last_visible_y
, -1,
15537 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
15538 if (IT_CHARPOS (it
) == PT
)
15539 w
->force_start
= 1;
15540 /* IT may overshoot PT if text at PT is invisible. */
15541 else if (IT_CHARPOS (it
) > PT
&& CHARPOS (startp
) <= PT
)
15542 w
->force_start
= 1;
15547 /* Handle case where place to start displaying has been specified,
15548 unless the specified location is outside the accessible range. */
15549 if (w
->force_start
|| w
->frozen_window_start_p
)
15551 /* We set this later on if we have to adjust point. */
15554 w
->force_start
= 0;
15556 w
->window_end_valid
= 0;
15558 /* Forget any recorded base line for line number display. */
15559 if (!buffer_unchanged_p
)
15560 w
->base_line_number
= 0;
15562 /* Redisplay the mode line. Select the buffer properly for that.
15563 Also, run the hook window-scroll-functions
15564 because we have scrolled. */
15565 /* Note, we do this after clearing force_start because
15566 if there's an error, it is better to forget about force_start
15567 than to get into an infinite loop calling the hook functions
15568 and having them get more errors. */
15569 if (!update_mode_line
15570 || ! NILP (Vwindow_scroll_functions
))
15572 update_mode_line
= 1;
15573 w
->update_mode_line
= 1;
15574 startp
= run_window_scroll_functions (window
, startp
);
15577 w
->last_modified
= 0;
15578 w
->last_overlay_modified
= 0;
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 && !w
->frozen_window_start_p
)
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 = pixel_margin
+ (header_line
15628 ? CURRENT_HEADER_LINE_HEIGHT (w
)
15629 : 0) + frame_line_height
;
15632 int window_height
= window_box_height (w
);
15635 window_height
+= CURRENT_HEADER_LINE_HEIGHT (w
);
15636 if (w
->cursor
.y
>= window_height
- pixel_margin
)
15637 new_vpos
= window_height
- pixel_margin
;
15641 /* If we need to move point for either of the above reasons,
15642 now actually do it. */
15645 struct glyph_row
*row
;
15647 row
= MATRIX_FIRST_TEXT_ROW (w
->desired_matrix
);
15648 while (MATRIX_ROW_BOTTOM_Y (row
) < new_vpos
)
15651 TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row
),
15652 MATRIX_ROW_START_BYTEPOS (row
));
15654 if (w
!= XWINDOW (selected_window
))
15655 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
15656 else if (current_buffer
== old
)
15657 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
15659 set_cursor_from_row (w
, row
, w
->desired_matrix
, 0, 0, 0, 0);
15661 /* If we are highlighting the region, then we just changed
15662 the region, so redisplay to show it. */
15663 if (markpos_of_region () >= 0)
15665 clear_glyph_matrix (w
->desired_matrix
);
15666 if (!try_window (window
, startp
, 0))
15667 goto need_larger_matrices
;
15672 debug_method_add (w
, "forced window start");
15677 /* Handle case where text has not changed, only point, and it has
15678 not moved off the frame, and we are not retrying after hscroll.
15679 (current_matrix_up_to_date_p is nonzero when retrying.) */
15680 if (current_matrix_up_to_date_p
15681 && (rc
= try_cursor_movement (window
, startp
, &temp_scroll_step
),
15682 rc
!= CURSOR_MOVEMENT_CANNOT_BE_USED
))
15686 case CURSOR_MOVEMENT_SUCCESS
:
15687 used_current_matrix_p
= 1;
15690 case CURSOR_MOVEMENT_MUST_SCROLL
:
15691 goto try_to_scroll
;
15697 /* If current starting point was originally the beginning of a line
15698 but no longer is, find a new starting point. */
15699 else if (w
->start_at_line_beg
15700 && !(CHARPOS (startp
) <= BEGV
15701 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n'))
15704 debug_method_add (w
, "recenter 1");
15709 /* Try scrolling with try_window_id. Value is > 0 if update has
15710 been done, it is -1 if we know that the same window start will
15711 not work. It is 0 if unsuccessful for some other reason. */
15712 else if ((tem
= try_window_id (w
)) != 0)
15715 debug_method_add (w
, "try_window_id %d", tem
);
15718 if (fonts_changed_p
)
15719 goto need_larger_matrices
;
15723 /* Otherwise try_window_id has returned -1 which means that we
15724 don't want the alternative below this comment to execute. */
15726 else if (CHARPOS (startp
) >= BEGV
15727 && CHARPOS (startp
) <= ZV
15728 && PT
>= CHARPOS (startp
)
15729 && (CHARPOS (startp
) < ZV
15730 /* Avoid starting at end of buffer. */
15731 || CHARPOS (startp
) == BEGV
15732 || !window_outdated (w
)))
15734 int d1
, d2
, d3
, d4
, d5
, d6
;
15736 /* If first window line is a continuation line, and window start
15737 is inside the modified region, but the first change is before
15738 current window start, we must select a new window start.
15740 However, if this is the result of a down-mouse event (e.g. by
15741 extending the mouse-drag-overlay), we don't want to select a
15742 new window start, since that would change the position under
15743 the mouse, resulting in an unwanted mouse-movement rather
15744 than a simple mouse-click. */
15745 if (!w
->start_at_line_beg
15746 && NILP (do_mouse_tracking
)
15747 && CHARPOS (startp
) > BEGV
15748 && CHARPOS (startp
) > BEG
+ beg_unchanged
15749 && CHARPOS (startp
) <= Z
- end_unchanged
15750 /* Even if w->start_at_line_beg is nil, a new window may
15751 start at a line_beg, since that's how set_buffer_window
15752 sets it. So, we need to check the return value of
15753 compute_window_start_on_continuation_line. (See also
15755 && XMARKER (w
->start
)->buffer
== current_buffer
15756 && compute_window_start_on_continuation_line (w
)
15757 /* It doesn't make sense to force the window start like we
15758 do at label force_start if it is already known that point
15759 will not be visible in the resulting window, because
15760 doing so will move point from its correct position
15761 instead of scrolling the window to bring point into view.
15763 && pos_visible_p (w
, PT
, &d1
, &d2
, &d3
, &d4
, &d5
, &d6
))
15765 w
->force_start
= 1;
15766 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
15771 debug_method_add (w
, "same window start");
15774 /* Try to redisplay starting at same place as before.
15775 If point has not moved off frame, accept the results. */
15776 if (!current_matrix_up_to_date_p
15777 /* Don't use try_window_reusing_current_matrix in this case
15778 because a window scroll function can have changed the
15780 || !NILP (Vwindow_scroll_functions
)
15781 || MINI_WINDOW_P (w
)
15782 || !(used_current_matrix_p
15783 = try_window_reusing_current_matrix (w
)))
15785 IF_DEBUG (debug_method_add (w
, "1"));
15786 if (try_window (window
, startp
, TRY_WINDOW_CHECK_MARGINS
) < 0)
15787 /* -1 means we need to scroll.
15788 0 means we need new matrices, but fonts_changed_p
15789 is set in that case, so we will detect it below. */
15790 goto try_to_scroll
;
15793 if (fonts_changed_p
)
15794 goto need_larger_matrices
;
15796 if (w
->cursor
.vpos
>= 0)
15798 if (!just_this_one_p
15799 || current_buffer
->clip_changed
15800 || BEG_UNCHANGED
< CHARPOS (startp
))
15801 /* Forget any recorded base line for line number display. */
15802 w
->base_line_number
= 0;
15804 if (!cursor_row_fully_visible_p (w
, 1, 0))
15806 clear_glyph_matrix (w
->desired_matrix
);
15807 last_line_misfit
= 1;
15809 /* Drop through and scroll. */
15814 clear_glyph_matrix (w
->desired_matrix
);
15819 w
->last_modified
= 0;
15820 w
->last_overlay_modified
= 0;
15822 /* Redisplay the mode line. Select the buffer properly for that. */
15823 if (!update_mode_line
)
15825 update_mode_line
= 1;
15826 w
->update_mode_line
= 1;
15829 /* Try to scroll by specified few lines. */
15830 if ((scroll_conservatively
15831 || emacs_scroll_step
15832 || temp_scroll_step
15833 || NUMBERP (BVAR (current_buffer
, scroll_up_aggressively
))
15834 || NUMBERP (BVAR (current_buffer
, scroll_down_aggressively
)))
15835 && CHARPOS (startp
) >= BEGV
15836 && CHARPOS (startp
) <= ZV
)
15838 /* The function returns -1 if new fonts were loaded, 1 if
15839 successful, 0 if not successful. */
15840 int ss
= try_scrolling (window
, just_this_one_p
,
15841 scroll_conservatively
,
15843 temp_scroll_step
, last_line_misfit
);
15846 case SCROLLING_SUCCESS
:
15849 case SCROLLING_NEED_LARGER_MATRICES
:
15850 goto need_larger_matrices
;
15852 case SCROLLING_FAILED
:
15860 /* Finally, just choose a place to start which positions point
15861 according to user preferences. */
15866 debug_method_add (w
, "recenter");
15869 /* Forget any previously recorded base line for line number display. */
15870 if (!buffer_unchanged_p
)
15871 w
->base_line_number
= 0;
15873 /* Determine the window start relative to point. */
15874 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15875 it
.current_y
= it
.last_visible_y
;
15876 if (centering_position
< 0)
15878 int window_total_lines
15879 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
15882 ? min (scroll_margin
, window_total_lines
/ 4)
15884 ptrdiff_t margin_pos
= CHARPOS (startp
);
15885 Lisp_Object aggressive
;
15888 /* If there is a scroll margin at the top of the window, find
15889 its character position. */
15891 /* Cannot call start_display if startp is not in the
15892 accessible region of the buffer. This can happen when we
15893 have just switched to a different buffer and/or changed
15894 its restriction. In that case, startp is initialized to
15895 the character position 1 (BEGV) because we did not yet
15896 have chance to display the buffer even once. */
15897 && BEGV
<= CHARPOS (startp
) && CHARPOS (startp
) <= ZV
)
15900 void *it1data
= NULL
;
15902 SAVE_IT (it1
, it
, it1data
);
15903 start_display (&it1
, w
, startp
);
15904 move_it_vertically (&it1
, margin
* frame_line_height
);
15905 margin_pos
= IT_CHARPOS (it1
);
15906 RESTORE_IT (&it
, &it
, it1data
);
15908 scrolling_up
= PT
> margin_pos
;
15911 ? BVAR (current_buffer
, scroll_up_aggressively
)
15912 : BVAR (current_buffer
, scroll_down_aggressively
);
15914 if (!MINI_WINDOW_P (w
)
15915 && (scroll_conservatively
> SCROLL_LIMIT
|| NUMBERP (aggressive
)))
15919 /* Setting scroll-conservatively overrides
15920 scroll-*-aggressively. */
15921 if (!scroll_conservatively
&& NUMBERP (aggressive
))
15923 double float_amount
= XFLOATINT (aggressive
);
15925 pt_offset
= float_amount
* WINDOW_BOX_TEXT_HEIGHT (w
);
15926 if (pt_offset
== 0 && float_amount
> 0)
15928 if (pt_offset
&& margin
> 0)
15931 /* Compute how much to move the window start backward from
15932 point so that point will be displayed where the user
15936 centering_position
= it
.last_visible_y
;
15938 centering_position
-= pt_offset
;
15939 centering_position
-=
15940 frame_line_height
* (1 + margin
+ (last_line_misfit
!= 0))
15941 + WINDOW_HEADER_LINE_HEIGHT (w
);
15942 /* Don't let point enter the scroll margin near top of
15944 if (centering_position
< margin
* frame_line_height
)
15945 centering_position
= margin
* frame_line_height
;
15948 centering_position
= margin
* frame_line_height
+ pt_offset
;
15951 /* Set the window start half the height of the window backward
15953 centering_position
= window_box_height (w
) / 2;
15955 move_it_vertically_backward (&it
, centering_position
);
15957 eassert (IT_CHARPOS (it
) >= BEGV
);
15959 /* The function move_it_vertically_backward may move over more
15960 than the specified y-distance. If it->w is small, e.g. a
15961 mini-buffer window, we may end up in front of the window's
15962 display area. Start displaying at the start of the line
15963 containing PT in this case. */
15964 if (it
.current_y
<= 0)
15966 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
15967 move_it_vertically_backward (&it
, 0);
15971 it
.current_x
= it
.hpos
= 0;
15973 /* Set the window start position here explicitly, to avoid an
15974 infinite loop in case the functions in window-scroll-functions
15976 set_marker_both (w
->start
, Qnil
, IT_CHARPOS (it
), IT_BYTEPOS (it
));
15978 /* Run scroll hooks. */
15979 startp
= run_window_scroll_functions (window
, it
.current
.pos
);
15981 /* Redisplay the window. */
15982 if (!current_matrix_up_to_date_p
15983 || windows_or_buffers_changed
15984 || cursor_type_changed
15985 /* Don't use try_window_reusing_current_matrix in this case
15986 because it can have changed the buffer. */
15987 || !NILP (Vwindow_scroll_functions
)
15988 || !just_this_one_p
15989 || MINI_WINDOW_P (w
)
15990 || !(used_current_matrix_p
15991 = try_window_reusing_current_matrix (w
)))
15992 try_window (window
, startp
, 0);
15994 /* If new fonts have been loaded (due to fontsets), give up. We
15995 have to start a new redisplay since we need to re-adjust glyph
15997 if (fonts_changed_p
)
15998 goto need_larger_matrices
;
16000 /* If cursor did not appear assume that the middle of the window is
16001 in the first line of the window. Do it again with the next line.
16002 (Imagine a window of height 100, displaying two lines of height
16003 60. Moving back 50 from it->last_visible_y will end in the first
16005 if (w
->cursor
.vpos
< 0)
16007 if (w
->window_end_valid
&& PT
>= Z
- XFASTINT (w
->window_end_pos
))
16009 clear_glyph_matrix (w
->desired_matrix
);
16010 move_it_by_lines (&it
, 1);
16011 try_window (window
, it
.current
.pos
, 0);
16013 else if (PT
< IT_CHARPOS (it
))
16015 clear_glyph_matrix (w
->desired_matrix
);
16016 move_it_by_lines (&it
, -1);
16017 try_window (window
, it
.current
.pos
, 0);
16021 /* Not much we can do about it. */
16025 /* Consider the following case: Window starts at BEGV, there is
16026 invisible, intangible text at BEGV, so that display starts at
16027 some point START > BEGV. It can happen that we are called with
16028 PT somewhere between BEGV and START. Try to handle that case. */
16029 if (w
->cursor
.vpos
< 0)
16031 struct glyph_row
*row
= w
->current_matrix
->rows
;
16032 if (row
->mode_line_p
)
16034 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
16037 if (!cursor_row_fully_visible_p (w
, 0, 0))
16039 /* If vscroll is enabled, disable it and try again. */
16043 clear_glyph_matrix (w
->desired_matrix
);
16047 /* Users who set scroll-conservatively to a large number want
16048 point just above/below the scroll margin. If we ended up
16049 with point's row partially visible, move the window start to
16050 make that row fully visible and out of the margin. */
16051 if (scroll_conservatively
> SCROLL_LIMIT
)
16053 int window_total_lines
16054 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) * frame_line_height
;
16057 ? min (scroll_margin
, window_total_lines
/ 4)
16059 int move_down
= w
->cursor
.vpos
>= window_total_lines
/ 2;
16061 move_it_by_lines (&it
, move_down
? margin
+ 1 : -(margin
+ 1));
16062 clear_glyph_matrix (w
->desired_matrix
);
16063 if (1 == try_window (window
, it
.current
.pos
,
16064 TRY_WINDOW_CHECK_MARGINS
))
16068 /* If centering point failed to make the whole line visible,
16069 put point at the top instead. That has to make the whole line
16070 visible, if it can be done. */
16071 if (centering_position
== 0)
16074 clear_glyph_matrix (w
->desired_matrix
);
16075 centering_position
= 0;
16081 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
16082 w
->start_at_line_beg
= (CHARPOS (startp
) == BEGV
16083 || FETCH_BYTE (BYTEPOS (startp
) - 1) == '\n');
16085 /* Display the mode line, if we must. */
16086 if ((update_mode_line
16087 /* If window not full width, must redo its mode line
16088 if (a) the window to its side is being redone and
16089 (b) we do a frame-based redisplay. This is a consequence
16090 of how inverted lines are drawn in frame-based redisplay. */
16091 || (!just_this_one_p
16092 && !FRAME_WINDOW_P (f
)
16093 && !WINDOW_FULL_WIDTH_P (w
))
16094 /* Line number to display. */
16095 || w
->base_line_pos
> 0
16096 /* Column number is displayed and different from the one displayed. */
16097 || (w
->column_number_displayed
!= -1
16098 && (w
->column_number_displayed
!= current_column ())))
16099 /* This means that the window has a mode line. */
16100 && (WINDOW_WANTS_MODELINE_P (w
)
16101 || WINDOW_WANTS_HEADER_LINE_P (w
)))
16103 display_mode_lines (w
);
16105 /* If mode line height has changed, arrange for a thorough
16106 immediate redisplay using the correct mode line height. */
16107 if (WINDOW_WANTS_MODELINE_P (w
)
16108 && CURRENT_MODE_LINE_HEIGHT (w
) != DESIRED_MODE_LINE_HEIGHT (w
))
16110 fonts_changed_p
= 1;
16111 MATRIX_MODE_LINE_ROW (w
->current_matrix
)->height
16112 = DESIRED_MODE_LINE_HEIGHT (w
);
16115 /* If header line height has changed, arrange for a thorough
16116 immediate redisplay using the correct header line height. */
16117 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16118 && CURRENT_HEADER_LINE_HEIGHT (w
) != DESIRED_HEADER_LINE_HEIGHT (w
))
16120 fonts_changed_p
= 1;
16121 MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->height
16122 = DESIRED_HEADER_LINE_HEIGHT (w
);
16125 if (fonts_changed_p
)
16126 goto need_larger_matrices
;
16129 if (!line_number_displayed
&& w
->base_line_pos
!= -1)
16131 w
->base_line_pos
= 0;
16132 w
->base_line_number
= 0;
16137 /* When we reach a frame's selected window, redo the frame's menu bar. */
16138 if (update_mode_line
16139 && EQ (FRAME_SELECTED_WINDOW (f
), window
))
16141 int redisplay_menu_p
= 0;
16143 if (FRAME_WINDOW_P (f
))
16145 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) \
16146 || defined (HAVE_NS) || defined (USE_GTK)
16147 redisplay_menu_p
= FRAME_EXTERNAL_MENU_BAR (f
);
16149 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16153 redisplay_menu_p
= FRAME_MENU_BAR_LINES (f
) > 0;
16155 if (redisplay_menu_p
)
16156 display_menu_bar (w
);
16158 #ifdef HAVE_WINDOW_SYSTEM
16159 if (FRAME_WINDOW_P (f
))
16161 #if defined (USE_GTK) || defined (HAVE_NS)
16162 if (FRAME_EXTERNAL_TOOL_BAR (f
))
16163 redisplay_tool_bar (f
);
16165 if (WINDOWP (f
->tool_bar_window
)
16166 && (FRAME_TOOL_BAR_LINES (f
) > 0
16167 || !NILP (Vauto_resize_tool_bars
))
16168 && redisplay_tool_bar (f
))
16169 ignore_mouse_drag_p
= 1;
16175 #ifdef HAVE_WINDOW_SYSTEM
16176 if (FRAME_WINDOW_P (f
)
16177 && update_window_fringes (w
, (just_this_one_p
16178 || (!used_current_matrix_p
&& !overlay_arrow_seen
)
16179 || w
->pseudo_window_p
)))
16183 if (draw_window_fringes (w
, 1))
16184 x_draw_vertical_border (w
);
16188 #endif /* HAVE_WINDOW_SYSTEM */
16190 /* We go to this label, with fonts_changed_p set,
16191 if it is necessary to try again using larger glyph matrices.
16192 We have to redeem the scroll bar even in this case,
16193 because the loop in redisplay_internal expects that. */
16194 need_larger_matrices
:
16196 finish_scroll_bars
:
16198 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
16200 /* Set the thumb's position and size. */
16201 set_vertical_scroll_bar (w
);
16203 /* Note that we actually used the scroll bar attached to this
16204 window, so it shouldn't be deleted at the end of redisplay. */
16205 if (FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
)
16206 (*FRAME_TERMINAL (f
)->redeem_scroll_bar_hook
) (w
);
16209 /* Restore current_buffer and value of point in it. The window
16210 update may have changed the buffer, so first make sure `opoint'
16211 is still valid (Bug#6177). */
16212 if (CHARPOS (opoint
) < BEGV
)
16213 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
16214 else if (CHARPOS (opoint
) > ZV
)
16215 TEMP_SET_PT_BOTH (Z
, Z_BYTE
);
16217 TEMP_SET_PT_BOTH (CHARPOS (opoint
), BYTEPOS (opoint
));
16219 set_buffer_internal_1 (old
);
16220 /* Avoid an abort in TEMP_SET_PT_BOTH if the buffer has become
16221 shorter. This can be caused by log truncation in *Messages*. */
16222 if (CHARPOS (lpoint
) <= ZV
)
16223 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
16225 unbind_to (count
, Qnil
);
16229 /* Build the complete desired matrix of WINDOW with a window start
16230 buffer position POS.
16232 Value is 1 if successful. It is zero if fonts were loaded during
16233 redisplay which makes re-adjusting glyph matrices necessary, and -1
16234 if point would appear in the scroll margins.
16235 (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
16236 unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
16240 try_window (Lisp_Object window
, struct text_pos pos
, int flags
)
16242 struct window
*w
= XWINDOW (window
);
16244 struct glyph_row
*last_text_row
= NULL
;
16245 struct frame
*f
= XFRAME (w
->frame
);
16246 int frame_line_height
= default_line_pixel_height (w
);
16248 /* Make POS the new window start. */
16249 set_marker_both (w
->start
, Qnil
, CHARPOS (pos
), BYTEPOS (pos
));
16251 /* Mark cursor position as unknown. No overlay arrow seen. */
16252 w
->cursor
.vpos
= -1;
16253 overlay_arrow_seen
= 0;
16255 /* Initialize iterator and info to start at POS. */
16256 start_display (&it
, w
, pos
);
16258 /* Display all lines of W. */
16259 while (it
.current_y
< it
.last_visible_y
)
16261 if (display_line (&it
))
16262 last_text_row
= it
.glyph_row
- 1;
16263 if (fonts_changed_p
&& !(flags
& TRY_WINDOW_IGNORE_FONTS_CHANGE
))
16267 /* Don't let the cursor end in the scroll margins. */
16268 if ((flags
& TRY_WINDOW_CHECK_MARGINS
)
16269 && !MINI_WINDOW_P (w
))
16271 int this_scroll_margin
;
16272 int window_total_lines
16273 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (f
) / frame_line_height
;
16275 if (scroll_margin
> 0)
16277 this_scroll_margin
= min (scroll_margin
, window_total_lines
/ 4);
16278 this_scroll_margin
*= frame_line_height
;
16281 this_scroll_margin
= 0;
16283 if ((w
->cursor
.y
>= 0 /* not vscrolled */
16284 && w
->cursor
.y
< this_scroll_margin
16285 && CHARPOS (pos
) > BEGV
16286 && IT_CHARPOS (it
) < ZV
)
16287 /* rms: considering make_cursor_line_fully_visible_p here
16288 seems to give wrong results. We don't want to recenter
16289 when the last line is partly visible, we want to allow
16290 that case to be handled in the usual way. */
16291 || w
->cursor
.y
> it
.last_visible_y
- this_scroll_margin
- 1)
16293 w
->cursor
.vpos
= -1;
16294 clear_glyph_matrix (w
->desired_matrix
);
16299 /* If bottom moved off end of frame, change mode line percentage. */
16300 if (XFASTINT (w
->window_end_pos
) <= 0
16301 && Z
!= IT_CHARPOS (it
))
16302 w
->update_mode_line
= 1;
16304 /* Set window_end_pos to the offset of the last character displayed
16305 on the window from the end of current_buffer. Set
16306 window_end_vpos to its row number. */
16309 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row
));
16310 w
->window_end_bytepos
16311 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16312 wset_window_end_pos
16313 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16314 wset_window_end_vpos
16315 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, w
->desired_matrix
)));
16317 (MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->desired_matrix
,
16318 XFASTINT (w
->window_end_vpos
))));
16322 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16323 wset_window_end_pos (w
, make_number (Z
- ZV
));
16324 wset_window_end_vpos (w
, make_number (0));
16327 /* But that is not valid info until redisplay finishes. */
16328 w
->window_end_valid
= 0;
16334 /************************************************************************
16335 Window redisplay reusing current matrix when buffer has not changed
16336 ************************************************************************/
16338 /* Try redisplay of window W showing an unchanged buffer with a
16339 different window start than the last time it was displayed by
16340 reusing its current matrix. Value is non-zero if successful.
16341 W->start is the new window start. */
16344 try_window_reusing_current_matrix (struct window
*w
)
16346 struct frame
*f
= XFRAME (w
->frame
);
16347 struct glyph_row
*bottom_row
;
16350 struct text_pos start
, new_start
;
16351 int nrows_scrolled
, i
;
16352 struct glyph_row
*last_text_row
;
16353 struct glyph_row
*last_reused_text_row
;
16354 struct glyph_row
*start_row
;
16355 int start_vpos
, min_y
, max_y
;
16358 if (inhibit_try_window_reusing
)
16362 if (/* This function doesn't handle terminal frames. */
16363 !FRAME_WINDOW_P (f
)
16364 /* Don't try to reuse the display if windows have been split
16366 || windows_or_buffers_changed
16367 || cursor_type_changed
)
16370 /* Can't do this if region may have changed. */
16371 if (markpos_of_region () >= 0
16372 || w
->region_showing
16373 || !NILP (Vshow_trailing_whitespace
))
16376 /* If top-line visibility has changed, give up. */
16377 if (WINDOW_WANTS_HEADER_LINE_P (w
)
16378 != MATRIX_HEADER_LINE_ROW (w
->current_matrix
)->mode_line_p
)
16381 /* Give up if old or new display is scrolled vertically. We could
16382 make this function handle this, but right now it doesn't. */
16383 start_row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16384 if (w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
))
16387 /* The variable new_start now holds the new window start. The old
16388 start `start' can be determined from the current matrix. */
16389 SET_TEXT_POS_FROM_MARKER (new_start
, w
->start
);
16390 start
= start_row
->minpos
;
16391 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16393 /* Clear the desired matrix for the display below. */
16394 clear_glyph_matrix (w
->desired_matrix
);
16396 if (CHARPOS (new_start
) <= CHARPOS (start
))
16398 /* Don't use this method if the display starts with an ellipsis
16399 displayed for invisible text. It's not easy to handle that case
16400 below, and it's certainly not worth the effort since this is
16401 not a frequent case. */
16402 if (in_ellipses_for_invisible_text_p (&start_row
->start
, w
))
16405 IF_DEBUG (debug_method_add (w
, "twu1"));
16407 /* Display up to a row that can be reused. The variable
16408 last_text_row is set to the last row displayed that displays
16409 text. Note that it.vpos == 0 if or if not there is a
16410 header-line; it's not the same as the MATRIX_ROW_VPOS! */
16411 start_display (&it
, w
, new_start
);
16412 w
->cursor
.vpos
= -1;
16413 last_text_row
= last_reused_text_row
= NULL
;
16415 while (it
.current_y
< it
.last_visible_y
16416 && !fonts_changed_p
)
16418 /* If we have reached into the characters in the START row,
16419 that means the line boundaries have changed. So we
16420 can't start copying with the row START. Maybe it will
16421 work to start copying with the following row. */
16422 while (IT_CHARPOS (it
) > CHARPOS (start
))
16424 /* Advance to the next row as the "start". */
16426 start
= start_row
->minpos
;
16427 /* If there are no more rows to try, or just one, give up. */
16428 if (start_row
== MATRIX_MODE_LINE_ROW (w
->current_matrix
) - 1
16429 || w
->vscroll
|| MATRIX_ROW_PARTIALLY_VISIBLE_P (w
, start_row
)
16430 || CHARPOS (start
) == ZV
)
16432 clear_glyph_matrix (w
->desired_matrix
);
16436 start_vpos
= MATRIX_ROW_VPOS (start_row
, w
->current_matrix
);
16438 /* If we have reached alignment, we can copy the rest of the
16440 if (IT_CHARPOS (it
) == CHARPOS (start
)
16441 /* Don't accept "alignment" inside a display vector,
16442 since start_row could have started in the middle of
16443 that same display vector (thus their character
16444 positions match), and we have no way of telling if
16445 that is the case. */
16446 && it
.current
.dpvec_index
< 0)
16449 if (display_line (&it
))
16450 last_text_row
= it
.glyph_row
- 1;
16454 /* A value of current_y < last_visible_y means that we stopped
16455 at the previous window start, which in turn means that we
16456 have at least one reusable row. */
16457 if (it
.current_y
< it
.last_visible_y
)
16459 struct glyph_row
*row
;
16461 /* IT.vpos always starts from 0; it counts text lines. */
16462 nrows_scrolled
= it
.vpos
- (start_row
- MATRIX_FIRST_TEXT_ROW (w
->current_matrix
));
16464 /* Find PT if not already found in the lines displayed. */
16465 if (w
->cursor
.vpos
< 0)
16467 int dy
= it
.current_y
- start_row
->y
;
16469 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16470 row
= row_containing_pos (w
, PT
, row
, NULL
, dy
);
16472 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0,
16473 dy
, nrows_scrolled
);
16476 clear_glyph_matrix (w
->desired_matrix
);
16481 /* Scroll the display. Do it before the current matrix is
16482 changed. The problem here is that update has not yet
16483 run, i.e. part of the current matrix is not up to date.
16484 scroll_run_hook will clear the cursor, and use the
16485 current matrix to get the height of the row the cursor is
16487 run
.current_y
= start_row
->y
;
16488 run
.desired_y
= it
.current_y
;
16489 run
.height
= it
.last_visible_y
- it
.current_y
;
16491 if (run
.height
> 0 && run
.current_y
!= run
.desired_y
)
16494 FRAME_RIF (f
)->update_window_begin_hook (w
);
16495 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16496 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16497 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16501 /* Shift current matrix down by nrows_scrolled lines. */
16502 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16503 rotate_matrix (w
->current_matrix
,
16505 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16508 /* Disable lines that must be updated. */
16509 for (i
= 0; i
< nrows_scrolled
; ++i
)
16510 (start_row
+ i
)->enabled_p
= 0;
16512 /* Re-compute Y positions. */
16513 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16514 max_y
= it
.last_visible_y
;
16515 for (row
= start_row
+ nrows_scrolled
;
16519 row
->y
= it
.current_y
;
16520 row
->visible_height
= row
->height
;
16522 if (row
->y
< min_y
)
16523 row
->visible_height
-= min_y
- row
->y
;
16524 if (row
->y
+ row
->height
> max_y
)
16525 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16526 if (row
->fringe_bitmap_periodic_p
)
16527 row
->redraw_fringe_bitmaps_p
= 1;
16529 it
.current_y
+= row
->height
;
16531 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16532 last_reused_text_row
= row
;
16533 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
.last_visible_y
)
16537 /* Disable lines in the current matrix which are now
16538 below the window. */
16539 for (++row
; row
< bottom_row
; ++row
)
16540 row
->enabled_p
= row
->mode_line_p
= 0;
16543 /* Update window_end_pos etc.; last_reused_text_row is the last
16544 reused row from the current matrix containing text, if any.
16545 The value of last_text_row is the last displayed line
16546 containing text. */
16547 if (last_reused_text_row
)
16549 w
->window_end_bytepos
16550 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_reused_text_row
);
16551 wset_window_end_pos
16553 - MATRIX_ROW_END_CHARPOS (last_reused_text_row
)));
16554 wset_window_end_vpos
16555 (w
, make_number (MATRIX_ROW_VPOS (last_reused_text_row
,
16556 w
->current_matrix
)));
16558 else if (last_text_row
)
16560 w
->window_end_bytepos
16561 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16562 wset_window_end_pos
16563 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16564 wset_window_end_vpos
16565 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16566 w
->desired_matrix
)));
16570 /* This window must be completely empty. */
16571 w
->window_end_bytepos
= Z_BYTE
- ZV_BYTE
;
16572 wset_window_end_pos (w
, make_number (Z
- ZV
));
16573 wset_window_end_vpos (w
, make_number (0));
16575 w
->window_end_valid
= 0;
16577 /* Update hint: don't try scrolling again in update_window. */
16578 w
->desired_matrix
->no_scrolling_p
= 1;
16581 debug_method_add (w
, "try_window_reusing_current_matrix 1");
16585 else if (CHARPOS (new_start
) > CHARPOS (start
))
16587 struct glyph_row
*pt_row
, *row
;
16588 struct glyph_row
*first_reusable_row
;
16589 struct glyph_row
*first_row_to_display
;
16591 int yb
= window_text_bottom_y (w
);
16593 /* Find the row starting at new_start, if there is one. Don't
16594 reuse a partially visible line at the end. */
16595 first_reusable_row
= start_row
;
16596 while (first_reusable_row
->enabled_p
16597 && MATRIX_ROW_BOTTOM_Y (first_reusable_row
) < yb
16598 && (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16599 < CHARPOS (new_start
)))
16600 ++first_reusable_row
;
16602 /* Give up if there is no row to reuse. */
16603 if (MATRIX_ROW_BOTTOM_Y (first_reusable_row
) >= yb
16604 || !first_reusable_row
->enabled_p
16605 || (MATRIX_ROW_START_CHARPOS (first_reusable_row
)
16606 != CHARPOS (new_start
)))
16609 /* We can reuse fully visible rows beginning with
16610 first_reusable_row to the end of the window. Set
16611 first_row_to_display to the first row that cannot be reused.
16612 Set pt_row to the row containing point, if there is any. */
16614 for (first_row_to_display
= first_reusable_row
;
16615 MATRIX_ROW_BOTTOM_Y (first_row_to_display
) < yb
;
16616 ++first_row_to_display
)
16618 if (PT
>= MATRIX_ROW_START_CHARPOS (first_row_to_display
)
16619 && (PT
< MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16620 || (PT
== MATRIX_ROW_END_CHARPOS (first_row_to_display
)
16621 && first_row_to_display
->ends_at_zv_p
16622 && pt_row
== NULL
)))
16623 pt_row
= first_row_to_display
;
16626 /* Start displaying at the start of first_row_to_display. */
16627 eassert (first_row_to_display
->y
< yb
);
16628 init_to_row_start (&it
, w
, first_row_to_display
);
16630 nrows_scrolled
= (MATRIX_ROW_VPOS (first_reusable_row
, w
->current_matrix
)
16632 it
.vpos
= (MATRIX_ROW_VPOS (first_row_to_display
, w
->current_matrix
)
16634 it
.current_y
= (first_row_to_display
->y
- first_reusable_row
->y
16635 + WINDOW_HEADER_LINE_HEIGHT (w
));
16637 /* Display lines beginning with first_row_to_display in the
16638 desired matrix. Set last_text_row to the last row displayed
16639 that displays text. */
16640 it
.glyph_row
= MATRIX_ROW (w
->desired_matrix
, it
.vpos
);
16641 if (pt_row
== NULL
)
16642 w
->cursor
.vpos
= -1;
16643 last_text_row
= NULL
;
16644 while (it
.current_y
< it
.last_visible_y
&& !fonts_changed_p
)
16645 if (display_line (&it
))
16646 last_text_row
= it
.glyph_row
- 1;
16648 /* If point is in a reused row, adjust y and vpos of the cursor
16652 w
->cursor
.vpos
-= nrows_scrolled
;
16653 w
->cursor
.y
-= first_reusable_row
->y
- start_row
->y
;
16656 /* Give up if point isn't in a row displayed or reused. (This
16657 also handles the case where w->cursor.vpos < nrows_scrolled
16658 after the calls to display_line, which can happen with scroll
16659 margins. See bug#1295.) */
16660 if (w
->cursor
.vpos
< 0)
16662 clear_glyph_matrix (w
->desired_matrix
);
16666 /* Scroll the display. */
16667 run
.current_y
= first_reusable_row
->y
;
16668 run
.desired_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16669 run
.height
= it
.last_visible_y
- run
.current_y
;
16670 dy
= run
.current_y
- run
.desired_y
;
16675 FRAME_RIF (f
)->update_window_begin_hook (w
);
16676 FRAME_RIF (f
)->clear_window_mouse_face (w
);
16677 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
16678 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
16682 /* Adjust Y positions of reused rows. */
16683 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
16684 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
16685 max_y
= it
.last_visible_y
;
16686 for (row
= first_reusable_row
; row
< first_row_to_display
; ++row
)
16689 row
->visible_height
= row
->height
;
16690 if (row
->y
< min_y
)
16691 row
->visible_height
-= min_y
- row
->y
;
16692 if (row
->y
+ row
->height
> max_y
)
16693 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
16694 if (row
->fringe_bitmap_periodic_p
)
16695 row
->redraw_fringe_bitmaps_p
= 1;
16698 /* Scroll the current matrix. */
16699 eassert (nrows_scrolled
> 0);
16700 rotate_matrix (w
->current_matrix
,
16702 MATRIX_ROW_VPOS (bottom_row
, w
->current_matrix
),
16705 /* Disable rows not reused. */
16706 for (row
-= nrows_scrolled
; row
< bottom_row
; ++row
)
16707 row
->enabled_p
= 0;
16709 /* Point may have moved to a different line, so we cannot assume that
16710 the previous cursor position is valid; locate the correct row. */
16713 for (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
);
16715 && PT
>= MATRIX_ROW_END_CHARPOS (row
)
16716 && !row
->ends_at_zv_p
;
16720 w
->cursor
.y
= row
->y
;
16722 if (row
< bottom_row
)
16724 /* Can't simply scan the row for point with
16725 bidi-reordered glyph rows. Let set_cursor_from_row
16726 figure out where to put the cursor, and if it fails,
16728 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
)))
16730 if (!set_cursor_from_row (w
, row
, w
->current_matrix
,
16733 clear_glyph_matrix (w
->desired_matrix
);
16739 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + w
->cursor
.hpos
;
16740 struct glyph
*end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
16743 && (!BUFFERP (glyph
->object
)
16744 || glyph
->charpos
< PT
);
16748 w
->cursor
.x
+= glyph
->pixel_width
;
16754 /* Adjust window end. A null value of last_text_row means that
16755 the window end is in reused rows which in turn means that
16756 only its vpos can have changed. */
16759 w
->window_end_bytepos
16760 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
16761 wset_window_end_pos
16762 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
16763 wset_window_end_vpos
16764 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
,
16765 w
->desired_matrix
)));
16769 wset_window_end_vpos
16770 (w
, make_number (XFASTINT (w
->window_end_vpos
) - nrows_scrolled
));
16773 w
->window_end_valid
= 0;
16774 w
->desired_matrix
->no_scrolling_p
= 1;
16777 debug_method_add (w
, "try_window_reusing_current_matrix 2");
16787 /************************************************************************
16788 Window redisplay reusing current matrix when buffer has changed
16789 ************************************************************************/
16791 static struct glyph_row
*find_last_unchanged_at_beg_row (struct window
*);
16792 static struct glyph_row
*find_first_unchanged_at_end_row (struct window
*,
16793 ptrdiff_t *, ptrdiff_t *);
16794 static struct glyph_row
*
16795 find_last_row_displaying_text (struct glyph_matrix
*, struct it
*,
16796 struct glyph_row
*);
16799 /* Return the last row in MATRIX displaying text. If row START is
16800 non-null, start searching with that row. IT gives the dimensions
16801 of the display. Value is null if matrix is empty; otherwise it is
16802 a pointer to the row found. */
16804 static struct glyph_row
*
16805 find_last_row_displaying_text (struct glyph_matrix
*matrix
, struct it
*it
,
16806 struct glyph_row
*start
)
16808 struct glyph_row
*row
, *row_found
;
16810 /* Set row_found to the last row in IT->w's current matrix
16811 displaying text. The loop looks funny but think of partially
16814 row
= start
? start
: MATRIX_FIRST_TEXT_ROW (matrix
);
16815 while (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16817 eassert (row
->enabled_p
);
16819 if (MATRIX_ROW_BOTTOM_Y (row
) >= it
->last_visible_y
)
16828 /* Return the last row in the current matrix of W that is not affected
16829 by changes at the start of current_buffer that occurred since W's
16830 current matrix was built. Value is null if no such row exists.
16832 BEG_UNCHANGED us the number of characters unchanged at the start of
16833 current_buffer. BEG + BEG_UNCHANGED is the buffer position of the
16834 first changed character in current_buffer. Characters at positions <
16835 BEG + BEG_UNCHANGED are at the same buffer positions as they were
16836 when the current matrix was built. */
16838 static struct glyph_row
*
16839 find_last_unchanged_at_beg_row (struct window
*w
)
16841 ptrdiff_t first_changed_pos
= BEG
+ BEG_UNCHANGED
;
16842 struct glyph_row
*row
;
16843 struct glyph_row
*row_found
= NULL
;
16844 int yb
= window_text_bottom_y (w
);
16846 /* Find the last row displaying unchanged text. */
16847 for (row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16848 MATRIX_ROW_DISPLAYS_TEXT_P (row
)
16849 && MATRIX_ROW_START_CHARPOS (row
) < first_changed_pos
;
16852 if (/* If row ends before first_changed_pos, it is unchanged,
16853 except in some case. */
16854 MATRIX_ROW_END_CHARPOS (row
) <= first_changed_pos
16855 /* When row ends in ZV and we write at ZV it is not
16857 && !row
->ends_at_zv_p
16858 /* When first_changed_pos is the end of a continued line,
16859 row is not unchanged because it may be no longer
16861 && !(MATRIX_ROW_END_CHARPOS (row
) == first_changed_pos
16862 && (row
->continued_p
16863 || row
->exact_window_width_line_p
))
16864 /* If ROW->end is beyond ZV, then ROW->end is outdated and
16865 needs to be recomputed, so don't consider this row as
16866 unchanged. This happens when the last line was
16867 bidi-reordered and was killed immediately before this
16868 redisplay cycle. In that case, ROW->end stores the
16869 buffer position of the first visual-order character of
16870 the killed text, which is now beyond ZV. */
16871 && CHARPOS (row
->end
.pos
) <= ZV
)
16874 /* Stop if last visible row. */
16875 if (MATRIX_ROW_BOTTOM_Y (row
) >= yb
)
16883 /* Find the first glyph row in the current matrix of W that is not
16884 affected by changes at the end of current_buffer since the
16885 time W's current matrix was built.
16887 Return in *DELTA the number of chars by which buffer positions in
16888 unchanged text at the end of current_buffer must be adjusted.
16890 Return in *DELTA_BYTES the corresponding number of bytes.
16892 Value is null if no such row exists, i.e. all rows are affected by
16895 static struct glyph_row
*
16896 find_first_unchanged_at_end_row (struct window
*w
,
16897 ptrdiff_t *delta
, ptrdiff_t *delta_bytes
)
16899 struct glyph_row
*row
;
16900 struct glyph_row
*row_found
= NULL
;
16902 *delta
= *delta_bytes
= 0;
16904 /* Display must not have been paused, otherwise the current matrix
16905 is not up to date. */
16906 eassert (w
->window_end_valid
);
16908 /* A value of window_end_pos >= END_UNCHANGED means that the window
16909 end is in the range of changed text. If so, there is no
16910 unchanged row at the end of W's current matrix. */
16911 if (XFASTINT (w
->window_end_pos
) >= END_UNCHANGED
)
16914 /* Set row to the last row in W's current matrix displaying text. */
16915 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
16917 /* If matrix is entirely empty, no unchanged row exists. */
16918 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16920 /* The value of row is the last glyph row in the matrix having a
16921 meaningful buffer position in it. The end position of row
16922 corresponds to window_end_pos. This allows us to translate
16923 buffer positions in the current matrix to current buffer
16924 positions for characters not in changed text. */
16926 MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
16927 ptrdiff_t Z_BYTE_old
=
16928 MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
16929 ptrdiff_t last_unchanged_pos
, last_unchanged_pos_old
;
16930 struct glyph_row
*first_text_row
16931 = MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
16933 *delta
= Z
- Z_old
;
16934 *delta_bytes
= Z_BYTE
- Z_BYTE_old
;
16936 /* Set last_unchanged_pos to the buffer position of the last
16937 character in the buffer that has not been changed. Z is the
16938 index + 1 of the last character in current_buffer, i.e. by
16939 subtracting END_UNCHANGED we get the index of the last
16940 unchanged character, and we have to add BEG to get its buffer
16942 last_unchanged_pos
= Z
- END_UNCHANGED
+ BEG
;
16943 last_unchanged_pos_old
= last_unchanged_pos
- *delta
;
16945 /* Search backward from ROW for a row displaying a line that
16946 starts at a minimum position >= last_unchanged_pos_old. */
16947 for (; row
> first_text_row
; --row
)
16949 /* This used to abort, but it can happen.
16950 It is ok to just stop the search instead here. KFS. */
16951 if (!row
->enabled_p
|| !MATRIX_ROW_DISPLAYS_TEXT_P (row
))
16954 if (MATRIX_ROW_START_CHARPOS (row
) >= last_unchanged_pos_old
)
16959 eassert (!row_found
|| MATRIX_ROW_DISPLAYS_TEXT_P (row_found
));
16965 /* Make sure that glyph rows in the current matrix of window W
16966 reference the same glyph memory as corresponding rows in the
16967 frame's frame matrix. This function is called after scrolling W's
16968 current matrix on a terminal frame in try_window_id and
16969 try_window_reusing_current_matrix. */
16972 sync_frame_with_window_matrix_rows (struct window
*w
)
16974 struct frame
*f
= XFRAME (w
->frame
);
16975 struct glyph_row
*window_row
, *window_row_end
, *frame_row
;
16977 /* Preconditions: W must be a leaf window and full-width. Its frame
16978 must have a frame matrix. */
16979 eassert (BUFFERP (w
->contents
));
16980 eassert (WINDOW_FULL_WIDTH_P (w
));
16981 eassert (!FRAME_WINDOW_P (f
));
16983 /* If W is a full-width window, glyph pointers in W's current matrix
16984 have, by definition, to be the same as glyph pointers in the
16985 corresponding frame matrix. Note that frame matrices have no
16986 marginal areas (see build_frame_matrix). */
16987 window_row
= w
->current_matrix
->rows
;
16988 window_row_end
= window_row
+ w
->current_matrix
->nrows
;
16989 frame_row
= f
->current_matrix
->rows
+ WINDOW_TOP_EDGE_LINE (w
);
16990 while (window_row
< window_row_end
)
16992 struct glyph
*start
= window_row
->glyphs
[LEFT_MARGIN_AREA
];
16993 struct glyph
*end
= window_row
->glyphs
[LAST_AREA
];
16995 frame_row
->glyphs
[LEFT_MARGIN_AREA
] = start
;
16996 frame_row
->glyphs
[TEXT_AREA
] = start
;
16997 frame_row
->glyphs
[RIGHT_MARGIN_AREA
] = end
;
16998 frame_row
->glyphs
[LAST_AREA
] = end
;
17000 /* Disable frame rows whose corresponding window rows have
17001 been disabled in try_window_id. */
17002 if (!window_row
->enabled_p
)
17003 frame_row
->enabled_p
= 0;
17005 ++window_row
, ++frame_row
;
17010 /* Find the glyph row in window W containing CHARPOS. Consider all
17011 rows between START and END (not inclusive). END null means search
17012 all rows to the end of the display area of W. Value is the row
17013 containing CHARPOS or null. */
17016 row_containing_pos (struct window
*w
, ptrdiff_t charpos
,
17017 struct glyph_row
*start
, struct glyph_row
*end
, int dy
)
17019 struct glyph_row
*row
= start
;
17020 struct glyph_row
*best_row
= NULL
;
17021 ptrdiff_t mindif
= BUF_ZV (XBUFFER (w
->contents
)) + 1;
17024 /* If we happen to start on a header-line, skip that. */
17025 if (row
->mode_line_p
)
17028 if ((end
&& row
>= end
) || !row
->enabled_p
)
17031 last_y
= window_text_bottom_y (w
) - dy
;
17035 /* Give up if we have gone too far. */
17036 if (end
&& row
>= end
)
17038 /* This formerly returned if they were equal.
17039 I think that both quantities are of a "last plus one" type;
17040 if so, when they are equal, the row is within the screen. -- rms. */
17041 if (MATRIX_ROW_BOTTOM_Y (row
) > last_y
)
17044 /* If it is in this row, return this row. */
17045 if (! (MATRIX_ROW_END_CHARPOS (row
) < charpos
17046 || (MATRIX_ROW_END_CHARPOS (row
) == charpos
17047 /* The end position of a row equals the start
17048 position of the next row. If CHARPOS is there, we
17049 would rather consider it displayed in the next
17050 line, except when this line ends in ZV. */
17051 && !row_for_charpos_p (row
, charpos
)))
17052 && charpos
>= MATRIX_ROW_START_CHARPOS (row
))
17056 if (NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17057 || (!best_row
&& !row
->continued_p
))
17059 /* In bidi-reordered rows, there could be several rows whose
17060 edges surround CHARPOS, all of these rows belonging to
17061 the same continued line. We need to find the row which
17062 fits CHARPOS the best. */
17063 for (g
= row
->glyphs
[TEXT_AREA
];
17064 g
< row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
17067 if (!STRINGP (g
->object
))
17069 if (g
->charpos
> 0 && eabs (g
->charpos
- charpos
) < mindif
)
17071 mindif
= eabs (g
->charpos
- charpos
);
17073 /* Exact match always wins. */
17080 else if (best_row
&& !row
->continued_p
)
17087 /* Try to redisplay window W by reusing its existing display. W's
17088 current matrix must be up to date when this function is called,
17089 i.e. window_end_valid must be nonzero.
17093 1 if display has been updated
17094 0 if otherwise unsuccessful
17095 -1 if redisplay with same window start is known not to succeed
17097 The following steps are performed:
17099 1. Find the last row in the current matrix of W that is not
17100 affected by changes at the start of current_buffer. If no such row
17103 2. Find the first row in W's current matrix that is not affected by
17104 changes at the end of current_buffer. Maybe there is no such row.
17106 3. Display lines beginning with the row + 1 found in step 1 to the
17107 row found in step 2 or, if step 2 didn't find a row, to the end of
17110 4. If cursor is not known to appear on the window, give up.
17112 5. If display stopped at the row found in step 2, scroll the
17113 display and current matrix as needed.
17115 6. Maybe display some lines at the end of W, if we must. This can
17116 happen under various circumstances, like a partially visible line
17117 becoming fully visible, or because newly displayed lines are displayed
17118 in smaller font sizes.
17120 7. Update W's window end information. */
17123 try_window_id (struct window
*w
)
17125 struct frame
*f
= XFRAME (w
->frame
);
17126 struct glyph_matrix
*current_matrix
= w
->current_matrix
;
17127 struct glyph_matrix
*desired_matrix
= w
->desired_matrix
;
17128 struct glyph_row
*last_unchanged_at_beg_row
;
17129 struct glyph_row
*first_unchanged_at_end_row
;
17130 struct glyph_row
*row
;
17131 struct glyph_row
*bottom_row
;
17134 ptrdiff_t delta
= 0, delta_bytes
= 0, stop_pos
;
17136 struct text_pos start_pos
;
17138 int first_unchanged_at_end_vpos
= 0;
17139 struct glyph_row
*last_text_row
, *last_text_row_at_end
;
17140 struct text_pos start
;
17141 ptrdiff_t first_changed_charpos
, last_changed_charpos
;
17144 if (inhibit_try_window_id
)
17148 /* This is handy for debugging. */
17150 #define GIVE_UP(X) \
17152 fprintf (stderr, "try_window_id give up %d\n", (X)); \
17156 #define GIVE_UP(X) return 0
17159 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
17161 /* Don't use this for mini-windows because these can show
17162 messages and mini-buffers, and we don't handle that here. */
17163 if (MINI_WINDOW_P (w
))
17166 /* This flag is used to prevent redisplay optimizations. */
17167 if (windows_or_buffers_changed
|| cursor_type_changed
)
17170 /* Verify that narrowing has not changed.
17171 Also verify that we were not told to prevent redisplay optimizations.
17172 It would be nice to further
17173 reduce the number of cases where this prevents try_window_id. */
17174 if (current_buffer
->clip_changed
17175 || current_buffer
->prevent_redisplay_optimizations_p
)
17178 /* Window must either use window-based redisplay or be full width. */
17179 if (!FRAME_WINDOW_P (f
)
17180 && (!FRAME_LINE_INS_DEL_OK (f
)
17181 || !WINDOW_FULL_WIDTH_P (w
)))
17184 /* Give up if point is known NOT to appear in W. */
17185 if (PT
< CHARPOS (start
))
17188 /* Another way to prevent redisplay optimizations. */
17189 if (w
->last_modified
== 0)
17192 /* Verify that window is not hscrolled. */
17193 if (w
->hscroll
!= 0)
17196 /* Verify that display wasn't paused. */
17197 if (!w
->window_end_valid
)
17200 /* Can't use this if highlighting a region because a cursor movement
17201 will do more than just set the cursor. */
17202 if (markpos_of_region () >= 0)
17205 /* Likewise if highlighting trailing whitespace. */
17206 if (!NILP (Vshow_trailing_whitespace
))
17209 /* Likewise if showing a region. */
17210 if (w
->region_showing
)
17213 /* Can't use this if overlay arrow position and/or string have
17215 if (overlay_arrows_changed_p ())
17218 /* When word-wrap is on, adding a space to the first word of a
17219 wrapped line can change the wrap position, altering the line
17220 above it. It might be worthwhile to handle this more
17221 intelligently, but for now just redisplay from scratch. */
17222 if (!NILP (BVAR (XBUFFER (w
->contents
), word_wrap
)))
17225 /* Under bidi reordering, adding or deleting a character in the
17226 beginning of a paragraph, before the first strong directional
17227 character, can change the base direction of the paragraph (unless
17228 the buffer specifies a fixed paragraph direction), which will
17229 require to redisplay the whole paragraph. It might be worthwhile
17230 to find the paragraph limits and widen the range of redisplayed
17231 lines to that, but for now just give up this optimization and
17232 redisplay from scratch. */
17233 if (!NILP (BVAR (XBUFFER (w
->contents
), bidi_display_reordering
))
17234 && NILP (BVAR (XBUFFER (w
->contents
), bidi_paragraph_direction
)))
17237 /* Make sure beg_unchanged and end_unchanged are up to date. Do it
17238 only if buffer has really changed. The reason is that the gap is
17239 initially at Z for freshly visited files. The code below would
17240 set end_unchanged to 0 in that case. */
17241 if (MODIFF
> SAVE_MODIFF
17242 /* This seems to happen sometimes after saving a buffer. */
17243 || BEG_UNCHANGED
+ END_UNCHANGED
> Z_BYTE
)
17245 if (GPT
- BEG
< BEG_UNCHANGED
)
17246 BEG_UNCHANGED
= GPT
- BEG
;
17247 if (Z
- GPT
< END_UNCHANGED
)
17248 END_UNCHANGED
= Z
- GPT
;
17251 /* The position of the first and last character that has been changed. */
17252 first_changed_charpos
= BEG
+ BEG_UNCHANGED
;
17253 last_changed_charpos
= Z
- END_UNCHANGED
;
17255 /* If window starts after a line end, and the last change is in
17256 front of that newline, then changes don't affect the display.
17257 This case happens with stealth-fontification. Note that although
17258 the display is unchanged, glyph positions in the matrix have to
17259 be adjusted, of course. */
17260 row
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
17261 if (MATRIX_ROW_DISPLAYS_TEXT_P (row
)
17262 && ((last_changed_charpos
< CHARPOS (start
)
17263 && CHARPOS (start
) == BEGV
)
17264 || (last_changed_charpos
< CHARPOS (start
) - 1
17265 && FETCH_BYTE (BYTEPOS (start
) - 1) == '\n')))
17267 ptrdiff_t Z_old
, Z_delta
, Z_BYTE_old
, Z_delta_bytes
;
17268 struct glyph_row
*r0
;
17270 /* Compute how many chars/bytes have been added to or removed
17271 from the buffer. */
17272 Z_old
= MATRIX_ROW_END_CHARPOS (row
) + XFASTINT (w
->window_end_pos
);
17273 Z_BYTE_old
= MATRIX_ROW_END_BYTEPOS (row
) + w
->window_end_bytepos
;
17274 Z_delta
= Z
- Z_old
;
17275 Z_delta_bytes
= Z_BYTE
- Z_BYTE_old
;
17277 /* Give up if PT is not in the window. Note that it already has
17278 been checked at the start of try_window_id that PT is not in
17279 front of the window start. */
17280 if (PT
>= MATRIX_ROW_END_CHARPOS (row
) + Z_delta
)
17283 /* If window start is unchanged, we can reuse the whole matrix
17284 as is, after adjusting glyph positions. No need to compute
17285 the window end again, since its offset from Z hasn't changed. */
17286 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17287 if (CHARPOS (start
) == MATRIX_ROW_START_CHARPOS (r0
) + Z_delta
17288 && BYTEPOS (start
) == MATRIX_ROW_START_BYTEPOS (r0
) + Z_delta_bytes
17289 /* PT must not be in a partially visible line. */
17290 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
) + Z_delta
17291 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17293 /* Adjust positions in the glyph matrix. */
17294 if (Z_delta
|| Z_delta_bytes
)
17296 struct glyph_row
*r1
17297 = MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17298 increment_matrix_positions (w
->current_matrix
,
17299 MATRIX_ROW_VPOS (r0
, current_matrix
),
17300 MATRIX_ROW_VPOS (r1
, current_matrix
),
17301 Z_delta
, Z_delta_bytes
);
17304 /* Set the cursor. */
17305 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17307 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17314 /* Handle the case that changes are all below what is displayed in
17315 the window, and that PT is in the window. This shortcut cannot
17316 be taken if ZV is visible in the window, and text has been added
17317 there that is visible in the window. */
17318 if (first_changed_charpos
>= MATRIX_ROW_END_CHARPOS (row
)
17319 /* ZV is not visible in the window, or there are no
17320 changes at ZV, actually. */
17321 && (current_matrix
->zv
> MATRIX_ROW_END_CHARPOS (row
)
17322 || first_changed_charpos
== last_changed_charpos
))
17324 struct glyph_row
*r0
;
17326 /* Give up if PT is not in the window. Note that it already has
17327 been checked at the start of try_window_id that PT is not in
17328 front of the window start. */
17329 if (PT
>= MATRIX_ROW_END_CHARPOS (row
))
17332 /* If window start is unchanged, we can reuse the whole matrix
17333 as is, without changing glyph positions since no text has
17334 been added/removed in front of the window end. */
17335 r0
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17336 if (TEXT_POS_EQUAL_P (start
, r0
->minpos
)
17337 /* PT must not be in a partially visible line. */
17338 && !(PT
>= MATRIX_ROW_START_CHARPOS (row
)
17339 && MATRIX_ROW_BOTTOM_Y (row
) > window_text_bottom_y (w
)))
17341 /* We have to compute the window end anew since text
17342 could have been added/removed after it. */
17343 wset_window_end_pos
17344 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17345 w
->window_end_bytepos
17346 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17348 /* Set the cursor. */
17349 row
= row_containing_pos (w
, PT
, r0
, NULL
, 0);
17351 set_cursor_from_row (w
, row
, current_matrix
, 0, 0, 0, 0);
17358 /* Give up if window start is in the changed area.
17360 The condition used to read
17362 (BEG_UNCHANGED + END_UNCHANGED != Z - BEG && ...)
17364 but why that was tested escapes me at the moment. */
17365 if (CHARPOS (start
) >= first_changed_charpos
17366 && CHARPOS (start
) <= last_changed_charpos
)
17369 /* Check that window start agrees with the start of the first glyph
17370 row in its current matrix. Check this after we know the window
17371 start is not in changed text, otherwise positions would not be
17373 row
= MATRIX_FIRST_TEXT_ROW (current_matrix
);
17374 if (!TEXT_POS_EQUAL_P (start
, row
->minpos
))
17377 /* Give up if the window ends in strings. Overlay strings
17378 at the end are difficult to handle, so don't try. */
17379 row
= MATRIX_ROW (current_matrix
, XFASTINT (w
->window_end_vpos
));
17380 if (MATRIX_ROW_START_CHARPOS (row
) == MATRIX_ROW_END_CHARPOS (row
))
17383 /* Compute the position at which we have to start displaying new
17384 lines. Some of the lines at the top of the window might be
17385 reusable because they are not displaying changed text. Find the
17386 last row in W's current matrix not affected by changes at the
17387 start of current_buffer. Value is null if changes start in the
17388 first line of window. */
17389 last_unchanged_at_beg_row
= find_last_unchanged_at_beg_row (w
);
17390 if (last_unchanged_at_beg_row
)
17392 /* Avoid starting to display in the middle of a character, a TAB
17393 for instance. This is easier than to set up the iterator
17394 exactly, and it's not a frequent case, so the additional
17395 effort wouldn't really pay off. */
17396 while ((MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
)
17397 || last_unchanged_at_beg_row
->ends_in_newline_from_string_p
)
17398 && last_unchanged_at_beg_row
> w
->current_matrix
->rows
)
17399 --last_unchanged_at_beg_row
;
17401 if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (last_unchanged_at_beg_row
))
17404 if (init_to_row_end (&it
, w
, last_unchanged_at_beg_row
) == 0)
17406 start_pos
= it
.current
.pos
;
17408 /* Start displaying new lines in the desired matrix at the same
17409 vpos we would use in the current matrix, i.e. below
17410 last_unchanged_at_beg_row. */
17411 it
.vpos
= 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row
,
17413 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17414 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row
);
17416 eassert (it
.hpos
== 0 && it
.current_x
== 0);
17420 /* There are no reusable lines at the start of the window.
17421 Start displaying in the first text line. */
17422 start_display (&it
, w
, start
);
17423 it
.vpos
= it
.first_vpos
;
17424 start_pos
= it
.current
.pos
;
17427 /* Find the first row that is not affected by changes at the end of
17428 the buffer. Value will be null if there is no unchanged row, in
17429 which case we must redisplay to the end of the window. delta
17430 will be set to the value by which buffer positions beginning with
17431 first_unchanged_at_end_row have to be adjusted due to text
17433 first_unchanged_at_end_row
17434 = find_first_unchanged_at_end_row (w
, &delta
, &delta_bytes
);
17435 IF_DEBUG (debug_delta
= delta
);
17436 IF_DEBUG (debug_delta_bytes
= delta_bytes
);
17438 /* Set stop_pos to the buffer position up to which we will have to
17439 display new lines. If first_unchanged_at_end_row != NULL, this
17440 is the buffer position of the start of the line displayed in that
17441 row. For first_unchanged_at_end_row == NULL, use 0 to indicate
17442 that we don't stop at a buffer position. */
17444 if (first_unchanged_at_end_row
)
17446 eassert (last_unchanged_at_beg_row
== NULL
17447 || first_unchanged_at_end_row
>= last_unchanged_at_beg_row
);
17449 /* If this is a continuation line, move forward to the next one
17450 that isn't. Changes in lines above affect this line.
17451 Caution: this may move first_unchanged_at_end_row to a row
17452 not displaying text. */
17453 while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row
)
17454 && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17455 && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17456 < it
.last_visible_y
))
17457 ++first_unchanged_at_end_row
;
17459 if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
)
17460 || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row
)
17461 >= it
.last_visible_y
))
17462 first_unchanged_at_end_row
= NULL
;
17465 stop_pos
= (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row
)
17467 first_unchanged_at_end_vpos
17468 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, current_matrix
);
17469 eassert (stop_pos
>= Z
- END_UNCHANGED
);
17472 else if (last_unchanged_at_beg_row
== NULL
)
17478 /* Either there is no unchanged row at the end, or the one we have
17479 now displays text. This is a necessary condition for the window
17480 end pos calculation at the end of this function. */
17481 eassert (first_unchanged_at_end_row
== NULL
17482 || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17484 debug_last_unchanged_at_beg_vpos
17485 = (last_unchanged_at_beg_row
17486 ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row
, current_matrix
)
17488 debug_first_unchanged_at_end_vpos
= first_unchanged_at_end_vpos
;
17490 #endif /* GLYPH_DEBUG */
17493 /* Display new lines. Set last_text_row to the last new line
17494 displayed which has text on it, i.e. might end up as being the
17495 line where the window_end_vpos is. */
17496 w
->cursor
.vpos
= -1;
17497 last_text_row
= NULL
;
17498 overlay_arrow_seen
= 0;
17499 while (it
.current_y
< it
.last_visible_y
17500 && !fonts_changed_p
17501 && (first_unchanged_at_end_row
== NULL
17502 || IT_CHARPOS (it
) < stop_pos
))
17504 if (display_line (&it
))
17505 last_text_row
= it
.glyph_row
- 1;
17508 if (fonts_changed_p
)
17512 /* Compute differences in buffer positions, y-positions etc. for
17513 lines reused at the bottom of the window. Compute what we can
17515 if (first_unchanged_at_end_row
17516 /* No lines reused because we displayed everything up to the
17517 bottom of the window. */
17518 && it
.current_y
< it
.last_visible_y
)
17521 - MATRIX_ROW_VPOS (first_unchanged_at_end_row
,
17523 dy
= it
.current_y
- first_unchanged_at_end_row
->y
;
17524 run
.current_y
= first_unchanged_at_end_row
->y
;
17525 run
.desired_y
= run
.current_y
+ dy
;
17526 run
.height
= it
.last_visible_y
- max (run
.current_y
, run
.desired_y
);
17530 delta
= delta_bytes
= dvpos
= dy
17531 = run
.current_y
= run
.desired_y
= run
.height
= 0;
17532 first_unchanged_at_end_row
= NULL
;
17534 IF_DEBUG (debug_dvpos
= dvpos
; debug_dy
= dy
);
17537 /* Find the cursor if not already found. We have to decide whether
17538 PT will appear on this window (it sometimes doesn't, but this is
17539 not a very frequent case.) This decision has to be made before
17540 the current matrix is altered. A value of cursor.vpos < 0 means
17541 that PT is either in one of the lines beginning at
17542 first_unchanged_at_end_row or below the window. Don't care for
17543 lines that might be displayed later at the window end; as
17544 mentioned, this is not a frequent case. */
17545 if (w
->cursor
.vpos
< 0)
17547 /* Cursor in unchanged rows at the top? */
17548 if (PT
< CHARPOS (start_pos
)
17549 && last_unchanged_at_beg_row
)
17551 row
= row_containing_pos (w
, PT
,
17552 MATRIX_FIRST_TEXT_ROW (w
->current_matrix
),
17553 last_unchanged_at_beg_row
+ 1, 0);
17555 set_cursor_from_row (w
, row
, w
->current_matrix
, 0, 0, 0, 0);
17558 /* Start from first_unchanged_at_end_row looking for PT. */
17559 else if (first_unchanged_at_end_row
)
17561 row
= row_containing_pos (w
, PT
- delta
,
17562 first_unchanged_at_end_row
, NULL
, 0);
17564 set_cursor_from_row (w
, row
, w
->current_matrix
, delta
,
17565 delta_bytes
, dy
, dvpos
);
17568 /* Give up if cursor was not found. */
17569 if (w
->cursor
.vpos
< 0)
17571 clear_glyph_matrix (w
->desired_matrix
);
17576 /* Don't let the cursor end in the scroll margins. */
17578 int this_scroll_margin
, cursor_height
;
17579 int frame_line_height
= default_line_pixel_height (w
);
17580 int window_total_lines
17581 = WINDOW_TOTAL_LINES (w
) * FRAME_LINE_HEIGHT (it
.f
) / frame_line_height
;
17583 this_scroll_margin
=
17584 max (0, min (scroll_margin
, window_total_lines
/ 4));
17585 this_scroll_margin
*= frame_line_height
;
17586 cursor_height
= MATRIX_ROW (w
->desired_matrix
, w
->cursor
.vpos
)->height
;
17588 if ((w
->cursor
.y
< this_scroll_margin
17589 && CHARPOS (start
) > BEGV
)
17590 /* Old redisplay didn't take scroll margin into account at the bottom,
17591 but then global-hl-line-mode doesn't scroll. KFS 2004-06-14 */
17592 || (w
->cursor
.y
+ (make_cursor_line_fully_visible_p
17593 ? cursor_height
+ this_scroll_margin
17594 : 1)) > it
.last_visible_y
)
17596 w
->cursor
.vpos
= -1;
17597 clear_glyph_matrix (w
->desired_matrix
);
17602 /* Scroll the display. Do it before changing the current matrix so
17603 that xterm.c doesn't get confused about where the cursor glyph is
17605 if (dy
&& run
.height
)
17609 if (FRAME_WINDOW_P (f
))
17611 FRAME_RIF (f
)->update_window_begin_hook (w
);
17612 FRAME_RIF (f
)->clear_window_mouse_face (w
);
17613 FRAME_RIF (f
)->scroll_run_hook (w
, &run
);
17614 FRAME_RIF (f
)->update_window_end_hook (w
, 0, 0);
17618 /* Terminal frame. In this case, dvpos gives the number of
17619 lines to scroll by; dvpos < 0 means scroll up. */
17621 = MATRIX_ROW_VPOS (first_unchanged_at_end_row
, w
->current_matrix
);
17622 int from
= WINDOW_TOP_EDGE_LINE (w
) + from_vpos
;
17623 int end
= (WINDOW_TOP_EDGE_LINE (w
)
17624 + (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0)
17625 + window_internal_height (w
));
17627 #if defined (HAVE_GPM) || defined (MSDOS)
17628 x_clear_window_mouse_face (w
);
17630 /* Perform the operation on the screen. */
17633 /* Scroll last_unchanged_at_beg_row to the end of the
17634 window down dvpos lines. */
17635 set_terminal_window (f
, end
);
17637 /* On dumb terminals delete dvpos lines at the end
17638 before inserting dvpos empty lines. */
17639 if (!FRAME_SCROLL_REGION_OK (f
))
17640 ins_del_lines (f
, end
- dvpos
, -dvpos
);
17642 /* Insert dvpos empty lines in front of
17643 last_unchanged_at_beg_row. */
17644 ins_del_lines (f
, from
, dvpos
);
17646 else if (dvpos
< 0)
17648 /* Scroll up last_unchanged_at_beg_vpos to the end of
17649 the window to last_unchanged_at_beg_vpos - |dvpos|. */
17650 set_terminal_window (f
, end
);
17652 /* Delete dvpos lines in front of
17653 last_unchanged_at_beg_vpos. ins_del_lines will set
17654 the cursor to the given vpos and emit |dvpos| delete
17656 ins_del_lines (f
, from
+ dvpos
, dvpos
);
17658 /* On a dumb terminal insert dvpos empty lines at the
17660 if (!FRAME_SCROLL_REGION_OK (f
))
17661 ins_del_lines (f
, end
+ dvpos
, -dvpos
);
17664 set_terminal_window (f
, 0);
17670 /* Shift reused rows of the current matrix to the right position.
17671 BOTTOM_ROW is the last + 1 row in the current matrix reserved for
17673 bottom_row
= MATRIX_BOTTOM_TEXT_ROW (current_matrix
, w
);
17674 bottom_vpos
= MATRIX_ROW_VPOS (bottom_row
, current_matrix
);
17677 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
+ dvpos
,
17678 bottom_vpos
, dvpos
);
17679 clear_glyph_matrix_rows (current_matrix
, bottom_vpos
+ dvpos
,
17682 else if (dvpos
> 0)
17684 rotate_matrix (current_matrix
, first_unchanged_at_end_vpos
,
17685 bottom_vpos
, dvpos
);
17686 clear_glyph_matrix_rows (current_matrix
, first_unchanged_at_end_vpos
,
17687 first_unchanged_at_end_vpos
+ dvpos
);
17690 /* For frame-based redisplay, make sure that current frame and window
17691 matrix are in sync with respect to glyph memory. */
17692 if (!FRAME_WINDOW_P (f
))
17693 sync_frame_with_window_matrix_rows (w
);
17695 /* Adjust buffer positions in reused rows. */
17696 if (delta
|| delta_bytes
)
17697 increment_matrix_positions (current_matrix
,
17698 first_unchanged_at_end_vpos
+ dvpos
,
17699 bottom_vpos
, delta
, delta_bytes
);
17701 /* Adjust Y positions. */
17703 shift_glyph_matrix (w
, current_matrix
,
17704 first_unchanged_at_end_vpos
+ dvpos
,
17707 if (first_unchanged_at_end_row
)
17709 first_unchanged_at_end_row
+= dvpos
;
17710 if (first_unchanged_at_end_row
->y
>= it
.last_visible_y
17711 || !MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
))
17712 first_unchanged_at_end_row
= NULL
;
17715 /* If scrolling up, there may be some lines to display at the end of
17717 last_text_row_at_end
= NULL
;
17720 /* Scrolling up can leave for example a partially visible line
17721 at the end of the window to be redisplayed. */
17722 /* Set last_row to the glyph row in the current matrix where the
17723 window end line is found. It has been moved up or down in
17724 the matrix by dvpos. */
17725 int last_vpos
= XFASTINT (w
->window_end_vpos
) + dvpos
;
17726 struct glyph_row
*last_row
= MATRIX_ROW (current_matrix
, last_vpos
);
17728 /* If last_row is the window end line, it should display text. */
17729 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_row
));
17731 /* If window end line was partially visible before, begin
17732 displaying at that line. Otherwise begin displaying with the
17733 line following it. */
17734 if (MATRIX_ROW_BOTTOM_Y (last_row
) - dy
>= it
.last_visible_y
)
17736 init_to_row_start (&it
, w
, last_row
);
17737 it
.vpos
= last_vpos
;
17738 it
.current_y
= last_row
->y
;
17742 init_to_row_end (&it
, w
, last_row
);
17743 it
.vpos
= 1 + last_vpos
;
17744 it
.current_y
= MATRIX_ROW_BOTTOM_Y (last_row
);
17748 /* We may start in a continuation line. If so, we have to
17749 get the right continuation_lines_width and current_x. */
17750 it
.continuation_lines_width
= last_row
->continuation_lines_width
;
17751 it
.hpos
= it
.current_x
= 0;
17753 /* Display the rest of the lines at the window end. */
17754 it
.glyph_row
= MATRIX_ROW (desired_matrix
, it
.vpos
);
17755 while (it
.current_y
< it
.last_visible_y
17756 && !fonts_changed_p
)
17758 /* Is it always sure that the display agrees with lines in
17759 the current matrix? I don't think so, so we mark rows
17760 displayed invalid in the current matrix by setting their
17761 enabled_p flag to zero. */
17762 MATRIX_ROW (w
->current_matrix
, it
.vpos
)->enabled_p
= 0;
17763 if (display_line (&it
))
17764 last_text_row_at_end
= it
.glyph_row
- 1;
17768 /* Update window_end_pos and window_end_vpos. */
17769 if (first_unchanged_at_end_row
17770 && !last_text_row_at_end
)
17772 /* Window end line if one of the preserved rows from the current
17773 matrix. Set row to the last row displaying text in current
17774 matrix starting at first_unchanged_at_end_row, after
17776 eassert (MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row
));
17777 row
= find_last_row_displaying_text (w
->current_matrix
, &it
,
17778 first_unchanged_at_end_row
);
17779 eassert (row
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
));
17781 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17782 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17783 wset_window_end_vpos
17784 (w
, make_number (MATRIX_ROW_VPOS (row
, w
->current_matrix
)));
17785 eassert (w
->window_end_bytepos
>= 0);
17786 IF_DEBUG (debug_method_add (w
, "A"));
17788 else if (last_text_row_at_end
)
17790 wset_window_end_pos
17791 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row_at_end
)));
17792 w
->window_end_bytepos
17793 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row_at_end
);
17794 wset_window_end_vpos
17795 (w
, make_number (MATRIX_ROW_VPOS (last_text_row_at_end
,
17797 eassert (w
->window_end_bytepos
>= 0);
17798 IF_DEBUG (debug_method_add (w
, "B"));
17800 else if (last_text_row
)
17802 /* We have displayed either to the end of the window or at the
17803 end of the window, i.e. the last row with text is to be found
17804 in the desired matrix. */
17805 wset_window_end_pos
17806 (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (last_text_row
)));
17807 w
->window_end_bytepos
17808 = Z_BYTE
- MATRIX_ROW_END_BYTEPOS (last_text_row
);
17809 wset_window_end_vpos
17810 (w
, make_number (MATRIX_ROW_VPOS (last_text_row
, desired_matrix
)));
17811 eassert (w
->window_end_bytepos
>= 0);
17813 else if (first_unchanged_at_end_row
== NULL
17814 && last_text_row
== NULL
17815 && last_text_row_at_end
== NULL
)
17817 /* Displayed to end of window, but no line containing text was
17818 displayed. Lines were deleted at the end of the window. */
17819 int first_vpos
= WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0;
17820 int vpos
= XFASTINT (w
->window_end_vpos
);
17821 struct glyph_row
*current_row
= current_matrix
->rows
+ vpos
;
17822 struct glyph_row
*desired_row
= desired_matrix
->rows
+ vpos
;
17825 row
== NULL
&& vpos
>= first_vpos
;
17826 --vpos
, --current_row
, --desired_row
)
17828 if (desired_row
->enabled_p
)
17830 if (MATRIX_ROW_DISPLAYS_TEXT_P (desired_row
))
17833 else if (MATRIX_ROW_DISPLAYS_TEXT_P (current_row
))
17837 eassert (row
!= NULL
);
17838 wset_window_end_vpos (w
, make_number (vpos
+ 1));
17839 wset_window_end_pos (w
, make_number (Z
- MATRIX_ROW_END_CHARPOS (row
)));
17840 w
->window_end_bytepos
= Z_BYTE
- MATRIX_ROW_END_BYTEPOS (row
);
17841 eassert (w
->window_end_bytepos
>= 0);
17842 IF_DEBUG (debug_method_add (w
, "C"));
17847 IF_DEBUG (debug_end_pos
= XFASTINT (w
->window_end_pos
);
17848 debug_end_vpos
= XFASTINT (w
->window_end_vpos
));
17850 /* Record that display has not been completed. */
17851 w
->window_end_valid
= 0;
17852 w
->desired_matrix
->no_scrolling_p
= 1;
17860 /***********************************************************************
17861 More debugging support
17862 ***********************************************************************/
17866 void dump_glyph_row (struct glyph_row
*, int, int) EXTERNALLY_VISIBLE
;
17867 void dump_glyph_matrix (struct glyph_matrix
*, int) EXTERNALLY_VISIBLE
;
17868 void dump_glyph (struct glyph_row
*, struct glyph
*, int) EXTERNALLY_VISIBLE
;
17871 /* Dump the contents of glyph matrix MATRIX on stderr.
17873 GLYPHS 0 means don't show glyph contents.
17874 GLYPHS 1 means show glyphs in short form
17875 GLYPHS > 1 means show glyphs in long form. */
17878 dump_glyph_matrix (struct glyph_matrix
*matrix
, int glyphs
)
17881 for (i
= 0; i
< matrix
->nrows
; ++i
)
17882 dump_glyph_row (MATRIX_ROW (matrix
, i
), i
, glyphs
);
17886 /* Dump contents of glyph GLYPH to stderr. ROW and AREA are
17887 the glyph row and area where the glyph comes from. */
17890 dump_glyph (struct glyph_row
*row
, struct glyph
*glyph
, int area
)
17892 if (glyph
->type
== CHAR_GLYPH
17893 || glyph
->type
== GLYPHLESS_GLYPH
)
17896 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17897 glyph
- row
->glyphs
[TEXT_AREA
],
17898 (glyph
->type
== CHAR_GLYPH
17902 (BUFFERP (glyph
->object
)
17904 : (STRINGP (glyph
->object
)
17906 : (INTEGERP (glyph
->object
)
17909 glyph
->pixel_width
,
17911 (glyph
->u
.ch
< 0x80 && glyph
->u
.ch
>= ' '
17915 glyph
->left_box_line_p
,
17916 glyph
->right_box_line_p
);
17918 else if (glyph
->type
== STRETCH_GLYPH
)
17921 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17922 glyph
- row
->glyphs
[TEXT_AREA
],
17925 (BUFFERP (glyph
->object
)
17927 : (STRINGP (glyph
->object
)
17929 : (INTEGERP (glyph
->object
)
17932 glyph
->pixel_width
,
17936 glyph
->left_box_line_p
,
17937 glyph
->right_box_line_p
);
17939 else if (glyph
->type
== IMAGE_GLYPH
)
17942 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x %c %4d %1.1d%1.1d\n",
17943 glyph
- row
->glyphs
[TEXT_AREA
],
17946 (BUFFERP (glyph
->object
)
17948 : (STRINGP (glyph
->object
)
17950 : (INTEGERP (glyph
->object
)
17953 glyph
->pixel_width
,
17957 glyph
->left_box_line_p
,
17958 glyph
->right_box_line_p
);
17960 else if (glyph
->type
== COMPOSITE_GLYPH
)
17963 " %5"pD
"d %c %9"pI
"d %c %3d 0x%06x",
17964 glyph
- row
->glyphs
[TEXT_AREA
],
17967 (BUFFERP (glyph
->object
)
17969 : (STRINGP (glyph
->object
)
17971 : (INTEGERP (glyph
->object
)
17974 glyph
->pixel_width
,
17976 if (glyph
->u
.cmp
.automatic
)
17979 glyph
->slice
.cmp
.from
, glyph
->slice
.cmp
.to
);
17980 fprintf (stderr
, " . %4d %1.1d%1.1d\n",
17982 glyph
->left_box_line_p
,
17983 glyph
->right_box_line_p
);
17988 /* Dump the contents of glyph row at VPOS in MATRIX to stderr.
17989 GLYPHS 0 means don't show glyph contents.
17990 GLYPHS 1 means show glyphs in short form
17991 GLYPHS > 1 means show glyphs in long form. */
17994 dump_glyph_row (struct glyph_row
*row
, int vpos
, int glyphs
)
17998 fprintf (stderr
, "Row Start End Used oE><\\CTZFesm X Y W H V A P\n");
17999 fprintf (stderr
, "==============================================================================\n");
18001 fprintf (stderr
, "%3d %9"pI
"d %9"pI
"d %4d %1.1d%1.1d%1.1d%1.1d\
18002 %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d %4d %4d %4d %4d\n",
18004 MATRIX_ROW_START_CHARPOS (row
),
18005 MATRIX_ROW_END_CHARPOS (row
),
18006 row
->used
[TEXT_AREA
],
18007 row
->contains_overlapping_glyphs_p
,
18009 row
->truncated_on_left_p
,
18010 row
->truncated_on_right_p
,
18012 MATRIX_ROW_CONTINUATION_LINE_P (row
),
18013 MATRIX_ROW_DISPLAYS_TEXT_P (row
),
18016 row
->ends_in_middle_of_char_p
,
18017 row
->starts_in_middle_of_char_p
,
18023 row
->visible_height
,
18026 /* The next 3 lines should align to "Start" in the header. */
18027 fprintf (stderr
, " %9"pD
"d %9"pD
"d\t%5d\n", row
->start
.overlay_string_index
,
18028 row
->end
.overlay_string_index
,
18029 row
->continuation_lines_width
);
18030 fprintf (stderr
, " %9"pI
"d %9"pI
"d\n",
18031 CHARPOS (row
->start
.string_pos
),
18032 CHARPOS (row
->end
.string_pos
));
18033 fprintf (stderr
, " %9d %9d\n", row
->start
.dpvec_index
,
18034 row
->end
.dpvec_index
);
18041 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18043 struct glyph
*glyph
= row
->glyphs
[area
];
18044 struct glyph
*glyph_end
= glyph
+ row
->used
[area
];
18046 /* Glyph for a line end in text. */
18047 if (area
== TEXT_AREA
&& glyph
== glyph_end
&& glyph
->charpos
> 0)
18050 if (glyph
< glyph_end
)
18051 fprintf (stderr
, " Glyph# Type Pos O W Code C Face LR\n");
18053 for (; glyph
< glyph_end
; ++glyph
)
18054 dump_glyph (row
, glyph
, area
);
18057 else if (glyphs
== 1)
18061 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18063 char *s
= alloca (row
->used
[area
] + 4);
18066 for (i
= 0; i
< row
->used
[area
]; ++i
)
18068 struct glyph
*glyph
= row
->glyphs
[area
] + i
;
18069 if (i
== row
->used
[area
] - 1
18070 && area
== TEXT_AREA
18071 && INTEGERP (glyph
->object
)
18072 && glyph
->type
== CHAR_GLYPH
18073 && glyph
->u
.ch
== ' ')
18075 strcpy (&s
[i
], "[\\n]");
18078 else if (glyph
->type
== CHAR_GLYPH
18079 && glyph
->u
.ch
< 0x80
18080 && glyph
->u
.ch
>= ' ')
18081 s
[i
] = glyph
->u
.ch
;
18087 fprintf (stderr
, "%3d: (%d) '%s'\n", vpos
, row
->enabled_p
, s
);
18093 DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix
,
18094 Sdump_glyph_matrix
, 0, 1, "p",
18095 doc
: /* Dump the current matrix of the selected window to stderr.
18096 Shows contents of glyph row structures. With non-nil
18097 parameter GLYPHS, dump glyphs as well. If GLYPHS is 1 show
18098 glyphs in short form, otherwise show glyphs in long form. */)
18099 (Lisp_Object glyphs
)
18101 struct window
*w
= XWINDOW (selected_window
);
18102 struct buffer
*buffer
= XBUFFER (w
->contents
);
18104 fprintf (stderr
, "PT = %"pI
"d, BEGV = %"pI
"d. ZV = %"pI
"d\n",
18105 BUF_PT (buffer
), BUF_BEGV (buffer
), BUF_ZV (buffer
));
18106 fprintf (stderr
, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n",
18107 w
->cursor
.x
, w
->cursor
.y
, w
->cursor
.hpos
, w
->cursor
.vpos
);
18108 fprintf (stderr
, "=============================================\n");
18109 dump_glyph_matrix (w
->current_matrix
,
18110 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 0);
18115 DEFUN ("dump-frame-glyph-matrix", Fdump_frame_glyph_matrix
,
18116 Sdump_frame_glyph_matrix
, 0, 0, "", doc
: /* */)
18119 struct frame
*f
= XFRAME (selected_frame
);
18120 dump_glyph_matrix (f
->current_matrix
, 1);
18125 DEFUN ("dump-glyph-row", Fdump_glyph_row
, Sdump_glyph_row
, 1, 2, "",
18126 doc
: /* Dump glyph row ROW to stderr.
18127 GLYPH 0 means don't dump glyphs.
18128 GLYPH 1 means dump glyphs in short form.
18129 GLYPH > 1 or omitted means dump glyphs in long form. */)
18130 (Lisp_Object row
, Lisp_Object glyphs
)
18132 struct glyph_matrix
*matrix
;
18135 CHECK_NUMBER (row
);
18136 matrix
= XWINDOW (selected_window
)->current_matrix
;
18138 if (vpos
>= 0 && vpos
< matrix
->nrows
)
18139 dump_glyph_row (MATRIX_ROW (matrix
, vpos
),
18141 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18146 DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row
, Sdump_tool_bar_row
, 1, 2, "",
18147 doc
: /* Dump glyph row ROW of the tool-bar of the current frame to stderr.
18148 GLYPH 0 means don't dump glyphs.
18149 GLYPH 1 means dump glyphs in short form.
18150 GLYPH > 1 or omitted means dump glyphs in long form. */)
18151 (Lisp_Object row
, Lisp_Object glyphs
)
18153 struct frame
*sf
= SELECTED_FRAME ();
18154 struct glyph_matrix
*m
= XWINDOW (sf
->tool_bar_window
)->current_matrix
;
18157 CHECK_NUMBER (row
);
18159 if (vpos
>= 0 && vpos
< m
->nrows
)
18160 dump_glyph_row (MATRIX_ROW (m
, vpos
), vpos
,
18161 TYPE_RANGED_INTEGERP (int, glyphs
) ? XINT (glyphs
) : 2);
18166 DEFUN ("trace-redisplay", Ftrace_redisplay
, Strace_redisplay
, 0, 1, "P",
18167 doc
: /* Toggle tracing of redisplay.
18168 With ARG, turn tracing on if and only if ARG is positive. */)
18172 trace_redisplay_p
= !trace_redisplay_p
;
18175 arg
= Fprefix_numeric_value (arg
);
18176 trace_redisplay_p
= XINT (arg
) > 0;
18183 DEFUN ("trace-to-stderr", Ftrace_to_stderr
, Strace_to_stderr
, 1, MANY
, "",
18184 doc
: /* Like `format', but print result to stderr.
18185 usage: (trace-to-stderr STRING &rest OBJECTS) */)
18186 (ptrdiff_t nargs
, Lisp_Object
*args
)
18188 Lisp_Object s
= Fformat (nargs
, args
);
18189 fprintf (stderr
, "%s", SDATA (s
));
18193 #endif /* GLYPH_DEBUG */
18197 /***********************************************************************
18198 Building Desired Matrix Rows
18199 ***********************************************************************/
18201 /* Return a temporary glyph row holding the glyphs of an overlay arrow.
18202 Used for non-window-redisplay windows, and for windows w/o left fringe. */
18204 static struct glyph_row
*
18205 get_overlay_arrow_glyph_row (struct window
*w
, Lisp_Object overlay_arrow_string
)
18207 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
18208 struct buffer
*buffer
= XBUFFER (w
->contents
);
18209 struct buffer
*old
= current_buffer
;
18210 const unsigned char *arrow_string
= SDATA (overlay_arrow_string
);
18211 int arrow_len
= SCHARS (overlay_arrow_string
);
18212 const unsigned char *arrow_end
= arrow_string
+ arrow_len
;
18213 const unsigned char *p
;
18216 int n_glyphs_before
;
18218 set_buffer_temp (buffer
);
18219 init_iterator (&it
, w
, -1, -1, &scratch_glyph_row
, DEFAULT_FACE_ID
);
18220 it
.glyph_row
->used
[TEXT_AREA
] = 0;
18221 SET_TEXT_POS (it
.position
, 0, 0);
18223 multibyte_p
= !NILP (BVAR (buffer
, enable_multibyte_characters
));
18225 while (p
< arrow_end
)
18227 Lisp_Object face
, ilisp
;
18229 /* Get the next character. */
18231 it
.c
= it
.char_to_display
= string_char_and_length (p
, &it
.len
);
18234 it
.c
= it
.char_to_display
= *p
, it
.len
= 1;
18235 if (! ASCII_CHAR_P (it
.c
))
18236 it
.char_to_display
= BYTE8_TO_CHAR (it
.c
);
18240 /* Get its face. */
18241 ilisp
= make_number (p
- arrow_string
);
18242 face
= Fget_text_property (ilisp
, Qface
, overlay_arrow_string
);
18243 it
.face_id
= compute_char_face (f
, it
.char_to_display
, face
);
18245 /* Compute its width, get its glyphs. */
18246 n_glyphs_before
= it
.glyph_row
->used
[TEXT_AREA
];
18247 SET_TEXT_POS (it
.position
, -1, -1);
18248 PRODUCE_GLYPHS (&it
);
18250 /* If this character doesn't fit any more in the line, we have
18251 to remove some glyphs. */
18252 if (it
.current_x
> it
.last_visible_x
)
18254 it
.glyph_row
->used
[TEXT_AREA
] = n_glyphs_before
;
18259 set_buffer_temp (old
);
18260 return it
.glyph_row
;
18264 /* Insert truncation glyphs at the start of IT->glyph_row. Which
18265 glyphs to insert is determined by produce_special_glyphs. */
18268 insert_left_trunc_glyphs (struct it
*it
)
18270 struct it truncate_it
;
18271 struct glyph
*from
, *end
, *to
, *toend
;
18273 eassert (!FRAME_WINDOW_P (it
->f
)
18274 || (!it
->glyph_row
->reversed_p
18275 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0)
18276 || (it
->glyph_row
->reversed_p
18277 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0));
18279 /* Get the truncation glyphs. */
18281 truncate_it
.current_x
= 0;
18282 truncate_it
.face_id
= DEFAULT_FACE_ID
;
18283 truncate_it
.glyph_row
= &scratch_glyph_row
;
18284 truncate_it
.glyph_row
->used
[TEXT_AREA
] = 0;
18285 CHARPOS (truncate_it
.position
) = BYTEPOS (truncate_it
.position
) = -1;
18286 truncate_it
.object
= make_number (0);
18287 produce_special_glyphs (&truncate_it
, IT_TRUNCATION
);
18289 /* Overwrite glyphs from IT with truncation glyphs. */
18290 if (!it
->glyph_row
->reversed_p
)
18292 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18294 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18295 end
= from
+ tused
;
18296 to
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18297 toend
= to
+ it
->glyph_row
->used
[TEXT_AREA
];
18298 if (FRAME_WINDOW_P (it
->f
))
18300 /* On GUI frames, when variable-size fonts are displayed,
18301 the truncation glyphs may need more pixels than the row's
18302 glyphs they overwrite. We overwrite more glyphs to free
18303 enough screen real estate, and enlarge the stretch glyph
18304 on the right (see display_line), if there is one, to
18305 preserve the screen position of the truncation glyphs on
18308 struct glyph
*g
= to
;
18311 /* The first glyph could be partially visible, in which case
18312 it->glyph_row->x will be negative. But we want the left
18313 truncation glyphs to be aligned at the left margin of the
18314 window, so we override the x coordinate at which the row
18316 it
->glyph_row
->x
= 0;
18317 while (g
< toend
&& w
< it
->truncation_pixel_width
)
18319 w
+= g
->pixel_width
;
18322 if (g
- to
- tused
> 0)
18324 memmove (to
+ tused
, g
, (toend
- g
) * sizeof(*g
));
18325 it
->glyph_row
->used
[TEXT_AREA
] -= g
- to
- tused
;
18327 used
= it
->glyph_row
->used
[TEXT_AREA
];
18328 if (it
->glyph_row
->truncated_on_right_p
18329 && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
) == 0
18330 && it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].type
18333 int extra
= w
- it
->truncation_pixel_width
;
18335 it
->glyph_row
->glyphs
[TEXT_AREA
][used
- 2].pixel_width
+= extra
;
18342 /* There may be padding glyphs left over. Overwrite them too. */
18343 if (!FRAME_WINDOW_P (it
->f
))
18345 while (to
< toend
&& CHAR_GLYPH_PADDING_P (*to
))
18347 from
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18354 it
->glyph_row
->used
[TEXT_AREA
] = to
- it
->glyph_row
->glyphs
[TEXT_AREA
];
18358 short tused
= truncate_it
.glyph_row
->used
[TEXT_AREA
];
18360 /* In R2L rows, overwrite the last (rightmost) glyphs, and do
18361 that back to front. */
18362 end
= truncate_it
.glyph_row
->glyphs
[TEXT_AREA
];
18363 from
= end
+ truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18364 toend
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18365 to
= toend
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18366 if (FRAME_WINDOW_P (it
->f
))
18369 struct glyph
*g
= to
;
18371 while (g
>= toend
&& w
< it
->truncation_pixel_width
)
18373 w
+= g
->pixel_width
;
18376 if (to
- g
- tused
> 0)
18378 if (it
->glyph_row
->truncated_on_right_p
18379 && WINDOW_LEFT_FRINGE_WIDTH (it
->w
) == 0
18380 && it
->glyph_row
->glyphs
[TEXT_AREA
][1].type
== STRETCH_GLYPH
)
18382 int extra
= w
- it
->truncation_pixel_width
;
18384 it
->glyph_row
->glyphs
[TEXT_AREA
][1].pixel_width
+= extra
;
18388 while (from
>= end
&& to
>= toend
)
18390 if (!FRAME_WINDOW_P (it
->f
))
18392 while (to
>= toend
&& CHAR_GLYPH_PADDING_P (*to
))
18395 truncate_it
.glyph_row
->glyphs
[TEXT_AREA
]
18396 + truncate_it
.glyph_row
->used
[TEXT_AREA
] - 1;
18397 while (from
>= end
&& to
>= toend
)
18403 /* Need to free some room before prepending additional
18405 int move_by
= from
- end
+ 1;
18406 struct glyph
*g0
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18407 struct glyph
*g
= g0
+ it
->glyph_row
->used
[TEXT_AREA
] - 1;
18409 for ( ; g
>= g0
; g
--)
18411 while (from
>= end
)
18413 it
->glyph_row
->used
[TEXT_AREA
] += move_by
;
18418 /* Compute the hash code for ROW. */
18420 row_hash (struct glyph_row
*row
)
18423 unsigned hashval
= 0;
18425 for (area
= LEFT_MARGIN_AREA
; area
< LAST_AREA
; ++area
)
18426 for (k
= 0; k
< row
->used
[area
]; ++k
)
18427 hashval
= ((((hashval
<< 4) + (hashval
>> 24)) & 0x0fffffff)
18428 + row
->glyphs
[area
][k
].u
.val
18429 + row
->glyphs
[area
][k
].face_id
18430 + row
->glyphs
[area
][k
].padding_p
18431 + (row
->glyphs
[area
][k
].type
<< 2));
18436 /* Compute the pixel height and width of IT->glyph_row.
18438 Most of the time, ascent and height of a display line will be equal
18439 to the max_ascent and max_height values of the display iterator
18440 structure. This is not the case if
18442 1. We hit ZV without displaying anything. In this case, max_ascent
18443 and max_height will be zero.
18445 2. We have some glyphs that don't contribute to the line height.
18446 (The glyph row flag contributes_to_line_height_p is for future
18447 pixmap extensions).
18449 The first case is easily covered by using default values because in
18450 these cases, the line height does not really matter, except that it
18451 must not be zero. */
18454 compute_line_metrics (struct it
*it
)
18456 struct glyph_row
*row
= it
->glyph_row
;
18458 if (FRAME_WINDOW_P (it
->f
))
18460 int i
, min_y
, max_y
;
18462 /* The line may consist of one space only, that was added to
18463 place the cursor on it. If so, the row's height hasn't been
18465 if (row
->height
== 0)
18467 if (it
->max_ascent
+ it
->max_descent
== 0)
18468 it
->max_descent
= it
->max_phys_descent
= FRAME_LINE_HEIGHT (it
->f
);
18469 row
->ascent
= it
->max_ascent
;
18470 row
->height
= it
->max_ascent
+ it
->max_descent
;
18471 row
->phys_ascent
= it
->max_phys_ascent
;
18472 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
18473 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
18476 /* Compute the width of this line. */
18477 row
->pixel_width
= row
->x
;
18478 for (i
= 0; i
< row
->used
[TEXT_AREA
]; ++i
)
18479 row
->pixel_width
+= row
->glyphs
[TEXT_AREA
][i
].pixel_width
;
18481 eassert (row
->pixel_width
>= 0);
18482 eassert (row
->ascent
>= 0 && row
->height
> 0);
18484 row
->overlapping_p
= (MATRIX_ROW_OVERLAPS_SUCC_P (row
)
18485 || MATRIX_ROW_OVERLAPS_PRED_P (row
));
18487 /* If first line's physical ascent is larger than its logical
18488 ascent, use the physical ascent, and make the row taller.
18489 This makes accented characters fully visible. */
18490 if (row
== MATRIX_FIRST_TEXT_ROW (it
->w
->desired_matrix
)
18491 && row
->phys_ascent
> row
->ascent
)
18493 row
->height
+= row
->phys_ascent
- row
->ascent
;
18494 row
->ascent
= row
->phys_ascent
;
18497 /* Compute how much of the line is visible. */
18498 row
->visible_height
= row
->height
;
18500 min_y
= WINDOW_HEADER_LINE_HEIGHT (it
->w
);
18501 max_y
= WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
);
18503 if (row
->y
< min_y
)
18504 row
->visible_height
-= min_y
- row
->y
;
18505 if (row
->y
+ row
->height
> max_y
)
18506 row
->visible_height
-= row
->y
+ row
->height
- max_y
;
18510 row
->pixel_width
= row
->used
[TEXT_AREA
];
18511 if (row
->continued_p
)
18512 row
->pixel_width
-= it
->continuation_pixel_width
;
18513 else if (row
->truncated_on_right_p
)
18514 row
->pixel_width
-= it
->truncation_pixel_width
;
18515 row
->ascent
= row
->phys_ascent
= 0;
18516 row
->height
= row
->phys_height
= row
->visible_height
= 1;
18517 row
->extra_line_spacing
= 0;
18520 /* Compute a hash code for this row. */
18521 row
->hash
= row_hash (row
);
18523 it
->max_ascent
= it
->max_descent
= 0;
18524 it
->max_phys_ascent
= it
->max_phys_descent
= 0;
18528 /* Append one space to the glyph row of iterator IT if doing a
18529 window-based redisplay. The space has the same face as
18530 IT->face_id. Value is non-zero if a space was added.
18532 This function is called to make sure that there is always one glyph
18533 at the end of a glyph row that the cursor can be set on under
18534 window-systems. (If there weren't such a glyph we would not know
18535 how wide and tall a box cursor should be displayed).
18537 At the same time this space let's a nicely handle clearing to the
18538 end of the line if the row ends in italic text. */
18541 append_space_for_newline (struct it
*it
, int default_face_p
)
18543 if (FRAME_WINDOW_P (it
->f
))
18545 int n
= it
->glyph_row
->used
[TEXT_AREA
];
18547 if (it
->glyph_row
->glyphs
[TEXT_AREA
] + n
18548 < it
->glyph_row
->glyphs
[1 + TEXT_AREA
])
18550 /* Save some values that must not be changed.
18551 Must save IT->c and IT->len because otherwise
18552 ITERATOR_AT_END_P wouldn't work anymore after
18553 append_space_for_newline has been called. */
18554 enum display_element_type saved_what
= it
->what
;
18555 int saved_c
= it
->c
, saved_len
= it
->len
;
18556 int saved_char_to_display
= it
->char_to_display
;
18557 int saved_x
= it
->current_x
;
18558 int saved_face_id
= it
->face_id
;
18559 int saved_box_end
= it
->end_of_box_run_p
;
18560 struct text_pos saved_pos
;
18561 Lisp_Object saved_object
;
18564 saved_object
= it
->object
;
18565 saved_pos
= it
->position
;
18567 it
->what
= IT_CHARACTER
;
18568 memset (&it
->position
, 0, sizeof it
->position
);
18569 it
->object
= make_number (0);
18570 it
->c
= it
->char_to_display
= ' ';
18573 /* If the default face was remapped, be sure to use the
18574 remapped face for the appended newline. */
18575 if (default_face_p
)
18576 it
->face_id
= lookup_basic_face (it
->f
, DEFAULT_FACE_ID
);
18577 else if (it
->face_before_selective_p
)
18578 it
->face_id
= it
->saved_face_id
;
18579 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
18580 it
->face_id
= FACE_FOR_CHAR (it
->f
, face
, 0, -1, Qnil
);
18581 /* In R2L rows, we will prepend a stretch glyph that will
18582 have the end_of_box_run_p flag set for it, so there's no
18583 need for the appended newline glyph to have that flag
18585 if (it
->glyph_row
->reversed_p
18586 /* But if the appended newline glyph goes all the way to
18587 the end of the row, there will be no stretch glyph,
18588 so leave the box flag set. */
18589 && saved_x
+ FRAME_COLUMN_WIDTH (it
->f
) < it
->last_visible_x
)
18590 it
->end_of_box_run_p
= 0;
18592 PRODUCE_GLYPHS (it
);
18594 it
->override_ascent
= -1;
18595 it
->constrain_row_ascent_descent_p
= 0;
18596 it
->current_x
= saved_x
;
18597 it
->object
= saved_object
;
18598 it
->position
= saved_pos
;
18599 it
->what
= saved_what
;
18600 it
->face_id
= saved_face_id
;
18601 it
->len
= saved_len
;
18603 it
->char_to_display
= saved_char_to_display
;
18604 it
->end_of_box_run_p
= saved_box_end
;
18613 /* Extend the face of the last glyph in the text area of IT->glyph_row
18614 to the end of the display line. Called from display_line. If the
18615 glyph row is empty, add a space glyph to it so that we know the
18616 face to draw. Set the glyph row flag fill_line_p. If the glyph
18617 row is R2L, prepend a stretch glyph to cover the empty space to the
18618 left of the leftmost glyph. */
18621 extend_face_to_end_of_line (struct it
*it
)
18623 struct face
*face
, *default_face
;
18624 struct frame
*f
= it
->f
;
18626 /* If line is already filled, do nothing. Non window-system frames
18627 get a grace of one more ``pixel'' because their characters are
18628 1-``pixel'' wide, so they hit the equality too early. This grace
18629 is needed only for R2L rows that are not continued, to produce
18630 one extra blank where we could display the cursor. */
18631 if (it
->current_x
>= it
->last_visible_x
18632 + (!FRAME_WINDOW_P (f
)
18633 && it
->glyph_row
->reversed_p
18634 && !it
->glyph_row
->continued_p
))
18637 /* The default face, possibly remapped. */
18638 default_face
= FACE_FROM_ID (f
, lookup_basic_face (f
, DEFAULT_FACE_ID
));
18640 /* Face extension extends the background and box of IT->face_id
18641 to the end of the line. If the background equals the background
18642 of the frame, we don't have to do anything. */
18643 if (it
->face_before_selective_p
)
18644 face
= FACE_FROM_ID (f
, it
->saved_face_id
);
18646 face
= FACE_FROM_ID (f
, it
->face_id
);
18648 if (FRAME_WINDOW_P (f
)
18649 && MATRIX_ROW_DISPLAYS_TEXT_P (it
->glyph_row
)
18650 && face
->box
== FACE_NO_BOX
18651 && face
->background
== FRAME_BACKGROUND_PIXEL (f
)
18653 && !it
->glyph_row
->reversed_p
)
18656 /* Set the glyph row flag indicating that the face of the last glyph
18657 in the text area has to be drawn to the end of the text area. */
18658 it
->glyph_row
->fill_line_p
= 1;
18660 /* If current character of IT is not ASCII, make sure we have the
18661 ASCII face. This will be automatically undone the next time
18662 get_next_display_element returns a multibyte character. Note
18663 that the character will always be single byte in unibyte
18665 if (!ASCII_CHAR_P (it
->c
))
18667 it
->face_id
= FACE_FOR_CHAR (f
, face
, 0, -1, Qnil
);
18670 if (FRAME_WINDOW_P (f
))
18672 /* If the row is empty, add a space with the current face of IT,
18673 so that we know which face to draw. */
18674 if (it
->glyph_row
->used
[TEXT_AREA
] == 0)
18676 it
->glyph_row
->glyphs
[TEXT_AREA
][0] = space_glyph
;
18677 it
->glyph_row
->glyphs
[TEXT_AREA
][0].face_id
= face
->id
;
18678 it
->glyph_row
->used
[TEXT_AREA
] = 1;
18680 #ifdef HAVE_WINDOW_SYSTEM
18681 if (it
->glyph_row
->reversed_p
)
18683 /* Prepend a stretch glyph to the row, such that the
18684 rightmost glyph will be drawn flushed all the way to the
18685 right margin of the window. The stretch glyph that will
18686 occupy the empty space, if any, to the left of the
18688 struct font
*font
= face
->font
? face
->font
: FRAME_FONT (f
);
18689 struct glyph
*row_start
= it
->glyph_row
->glyphs
[TEXT_AREA
];
18690 struct glyph
*row_end
= row_start
+ it
->glyph_row
->used
[TEXT_AREA
];
18692 int row_width
, stretch_ascent
, stretch_width
;
18693 struct text_pos saved_pos
;
18694 int saved_face_id
, saved_avoid_cursor
, saved_box_start
;
18696 for (row_width
= 0, g
= row_start
; g
< row_end
; g
++)
18697 row_width
+= g
->pixel_width
;
18698 stretch_width
= window_box_width (it
->w
, TEXT_AREA
) - row_width
;
18699 if (stretch_width
> 0)
18702 (((it
->ascent
+ it
->descent
)
18703 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
18704 saved_pos
= it
->position
;
18705 memset (&it
->position
, 0, sizeof it
->position
);
18706 saved_avoid_cursor
= it
->avoid_cursor_p
;
18707 it
->avoid_cursor_p
= 1;
18708 saved_face_id
= it
->face_id
;
18709 saved_box_start
= it
->start_of_box_run_p
;
18710 /* The last row's stretch glyph should get the default
18711 face, to avoid painting the rest of the window with
18712 the region face, if the region ends at ZV. */
18713 if (it
->glyph_row
->ends_at_zv_p
)
18714 it
->face_id
= default_face
->id
;
18716 it
->face_id
= face
->id
;
18717 it
->start_of_box_run_p
= 0;
18718 append_stretch_glyph (it
, make_number (0), stretch_width
,
18719 it
->ascent
+ it
->descent
, stretch_ascent
);
18720 it
->position
= saved_pos
;
18721 it
->avoid_cursor_p
= saved_avoid_cursor
;
18722 it
->face_id
= saved_face_id
;
18723 it
->start_of_box_run_p
= saved_box_start
;
18726 #endif /* HAVE_WINDOW_SYSTEM */
18730 /* Save some values that must not be changed. */
18731 int saved_x
= it
->current_x
;
18732 struct text_pos saved_pos
;
18733 Lisp_Object saved_object
;
18734 enum display_element_type saved_what
= it
->what
;
18735 int saved_face_id
= it
->face_id
;
18737 saved_object
= it
->object
;
18738 saved_pos
= it
->position
;
18740 it
->what
= IT_CHARACTER
;
18741 memset (&it
->position
, 0, sizeof it
->position
);
18742 it
->object
= make_number (0);
18743 it
->c
= it
->char_to_display
= ' ';
18745 /* The last row's blank glyphs should get the default face, to
18746 avoid painting the rest of the window with the region face,
18747 if the region ends at ZV. */
18748 if (it
->glyph_row
->ends_at_zv_p
)
18749 it
->face_id
= default_face
->id
;
18751 it
->face_id
= face
->id
;
18753 PRODUCE_GLYPHS (it
);
18755 while (it
->current_x
<= it
->last_visible_x
)
18756 PRODUCE_GLYPHS (it
);
18758 /* Don't count these blanks really. It would let us insert a left
18759 truncation glyph below and make us set the cursor on them, maybe. */
18760 it
->current_x
= saved_x
;
18761 it
->object
= saved_object
;
18762 it
->position
= saved_pos
;
18763 it
->what
= saved_what
;
18764 it
->face_id
= saved_face_id
;
18769 /* Value is non-zero if text starting at CHARPOS in current_buffer is
18770 trailing whitespace. */
18773 trailing_whitespace_p (ptrdiff_t charpos
)
18775 ptrdiff_t bytepos
= CHAR_TO_BYTE (charpos
);
18778 while (bytepos
< ZV_BYTE
18779 && (c
= FETCH_CHAR (bytepos
),
18780 c
== ' ' || c
== '\t'))
18783 if (bytepos
>= ZV_BYTE
|| c
== '\n' || c
== '\r')
18785 if (bytepos
!= PT_BYTE
)
18792 /* Highlight trailing whitespace, if any, in ROW. */
18795 highlight_trailing_whitespace (struct frame
*f
, struct glyph_row
*row
)
18797 int used
= row
->used
[TEXT_AREA
];
18801 struct glyph
*start
= row
->glyphs
[TEXT_AREA
];
18802 struct glyph
*glyph
= start
+ used
- 1;
18804 if (row
->reversed_p
)
18806 /* Right-to-left rows need to be processed in the opposite
18807 direction, so swap the edge pointers. */
18809 start
= row
->glyphs
[TEXT_AREA
] + used
- 1;
18812 /* Skip over glyphs inserted to display the cursor at the
18813 end of a line, for extending the face of the last glyph
18814 to the end of the line on terminals, and for truncation
18815 and continuation glyphs. */
18816 if (!row
->reversed_p
)
18818 while (glyph
>= start
18819 && glyph
->type
== CHAR_GLYPH
18820 && INTEGERP (glyph
->object
))
18825 while (glyph
<= start
18826 && glyph
->type
== CHAR_GLYPH
18827 && INTEGERP (glyph
->object
))
18831 /* If last glyph is a space or stretch, and it's trailing
18832 whitespace, set the face of all trailing whitespace glyphs in
18833 IT->glyph_row to `trailing-whitespace'. */
18834 if ((row
->reversed_p
? glyph
<= start
: glyph
>= start
)
18835 && BUFFERP (glyph
->object
)
18836 && (glyph
->type
== STRETCH_GLYPH
18837 || (glyph
->type
== CHAR_GLYPH
18838 && glyph
->u
.ch
== ' '))
18839 && trailing_whitespace_p (glyph
->charpos
))
18841 int face_id
= lookup_named_face (f
, Qtrailing_whitespace
, 0);
18845 if (!row
->reversed_p
)
18847 while (glyph
>= start
18848 && BUFFERP (glyph
->object
)
18849 && (glyph
->type
== STRETCH_GLYPH
18850 || (glyph
->type
== CHAR_GLYPH
18851 && glyph
->u
.ch
== ' ')))
18852 (glyph
--)->face_id
= face_id
;
18856 while (glyph
<= start
18857 && BUFFERP (glyph
->object
)
18858 && (glyph
->type
== STRETCH_GLYPH
18859 || (glyph
->type
== CHAR_GLYPH
18860 && glyph
->u
.ch
== ' ')))
18861 (glyph
++)->face_id
= face_id
;
18868 /* Value is non-zero if glyph row ROW should be
18869 considered to hold the buffer position CHARPOS. */
18872 row_for_charpos_p (struct glyph_row
*row
, ptrdiff_t charpos
)
18876 if (charpos
== CHARPOS (row
->end
.pos
)
18877 || charpos
== MATRIX_ROW_END_CHARPOS (row
))
18879 /* Suppose the row ends on a string.
18880 Unless the row is continued, that means it ends on a newline
18881 in the string. If it's anything other than a display string
18882 (e.g., a before-string from an overlay), we don't want the
18883 cursor there. (This heuristic seems to give the optimal
18884 behavior for the various types of multi-line strings.)
18885 One exception: if the string has `cursor' property on one of
18886 its characters, we _do_ want the cursor there. */
18887 if (CHARPOS (row
->end
.string_pos
) >= 0)
18889 if (row
->continued_p
)
18893 /* Check for `display' property. */
18894 struct glyph
*beg
= row
->glyphs
[TEXT_AREA
];
18895 struct glyph
*end
= beg
+ row
->used
[TEXT_AREA
] - 1;
18896 struct glyph
*glyph
;
18899 for (glyph
= end
; glyph
>= beg
; --glyph
)
18900 if (STRINGP (glyph
->object
))
18903 = Fget_char_property (make_number (charpos
),
18907 && display_prop_string_p (prop
, glyph
->object
));
18908 /* If there's a `cursor' property on one of the
18909 string's characters, this row is a cursor row,
18910 even though this is not a display string. */
18913 Lisp_Object s
= glyph
->object
;
18915 for ( ; glyph
>= beg
&& EQ (glyph
->object
, s
); --glyph
)
18917 ptrdiff_t gpos
= glyph
->charpos
;
18919 if (!NILP (Fget_char_property (make_number (gpos
),
18931 else if (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))
18933 /* If the row ends in middle of a real character,
18934 and the line is continued, we want the cursor here.
18935 That's because CHARPOS (ROW->end.pos) would equal
18936 PT if PT is before the character. */
18937 if (!row
->ends_in_ellipsis_p
)
18938 result
= row
->continued_p
;
18940 /* If the row ends in an ellipsis, then
18941 CHARPOS (ROW->end.pos) will equal point after the
18942 invisible text. We want that position to be displayed
18943 after the ellipsis. */
18946 /* If the row ends at ZV, display the cursor at the end of that
18947 row instead of at the start of the row below. */
18948 else if (row
->ends_at_zv_p
)
18957 /* Value is non-zero if glyph row ROW should be
18958 used to hold the cursor. */
18961 cursor_row_p (struct glyph_row
*row
)
18963 return row_for_charpos_p (row
, PT
);
18968 /* Push the property PROP so that it will be rendered at the current
18969 position in IT. Return 1 if PROP was successfully pushed, 0
18970 otherwise. Called from handle_line_prefix to handle the
18971 `line-prefix' and `wrap-prefix' properties. */
18974 push_prefix_prop (struct it
*it
, Lisp_Object prop
)
18976 struct text_pos pos
=
18977 STRINGP (it
->string
) ? it
->current
.string_pos
: it
->current
.pos
;
18979 eassert (it
->method
== GET_FROM_BUFFER
18980 || it
->method
== GET_FROM_DISPLAY_VECTOR
18981 || it
->method
== GET_FROM_STRING
);
18983 /* We need to save the current buffer/string position, so it will be
18984 restored by pop_it, because iterate_out_of_display_property
18985 depends on that being set correctly, but some situations leave
18986 it->position not yet set when this function is called. */
18987 push_it (it
, &pos
);
18989 if (STRINGP (prop
))
18991 if (SCHARS (prop
) == 0)
18998 it
->string_from_prefix_prop_p
= 1;
18999 it
->multibyte_p
= STRING_MULTIBYTE (it
->string
);
19000 it
->current
.overlay_string_index
= -1;
19001 IT_STRING_CHARPOS (*it
) = IT_STRING_BYTEPOS (*it
) = 0;
19002 it
->end_charpos
= it
->string_nchars
= SCHARS (it
->string
);
19003 it
->method
= GET_FROM_STRING
;
19004 it
->stop_charpos
= 0;
19006 it
->base_level_stop
= 0;
19008 /* Force paragraph direction to be that of the parent
19010 if (it
->bidi_p
&& it
->bidi_it
.paragraph_dir
== R2L
)
19011 it
->paragraph_embedding
= it
->bidi_it
.paragraph_dir
;
19013 it
->paragraph_embedding
= L2R
;
19015 /* Set up the bidi iterator for this display string. */
19018 it
->bidi_it
.string
.lstring
= it
->string
;
19019 it
->bidi_it
.string
.s
= NULL
;
19020 it
->bidi_it
.string
.schars
= it
->end_charpos
;
19021 it
->bidi_it
.string
.bufpos
= IT_CHARPOS (*it
);
19022 it
->bidi_it
.string
.from_disp_str
= it
->string_from_display_prop_p
;
19023 it
->bidi_it
.string
.unibyte
= !it
->multibyte_p
;
19024 it
->bidi_it
.w
= it
->w
;
19025 bidi_init_it (0, 0, FRAME_WINDOW_P (it
->f
), &it
->bidi_it
);
19028 else if (CONSP (prop
) && EQ (XCAR (prop
), Qspace
))
19030 it
->method
= GET_FROM_STRETCH
;
19033 #ifdef HAVE_WINDOW_SYSTEM
19034 else if (IMAGEP (prop
))
19036 it
->what
= IT_IMAGE
;
19037 it
->image_id
= lookup_image (it
->f
, prop
);
19038 it
->method
= GET_FROM_IMAGE
;
19040 #endif /* HAVE_WINDOW_SYSTEM */
19043 pop_it (it
); /* bogus display property, give up */
19050 /* Return the character-property PROP at the current position in IT. */
19053 get_it_property (struct it
*it
, Lisp_Object prop
)
19055 Lisp_Object position
, object
= it
->object
;
19057 if (STRINGP (object
))
19058 position
= make_number (IT_STRING_CHARPOS (*it
));
19059 else if (BUFFERP (object
))
19061 position
= make_number (IT_CHARPOS (*it
));
19062 object
= it
->window
;
19067 return Fget_char_property (position
, prop
, object
);
19070 /* See if there's a line- or wrap-prefix, and if so, push it on IT. */
19073 handle_line_prefix (struct it
*it
)
19075 Lisp_Object prefix
;
19077 if (it
->continuation_lines_width
> 0)
19079 prefix
= get_it_property (it
, Qwrap_prefix
);
19081 prefix
= Vwrap_prefix
;
19085 prefix
= get_it_property (it
, Qline_prefix
);
19087 prefix
= Vline_prefix
;
19089 if (! NILP (prefix
) && push_prefix_prop (it
, prefix
))
19091 /* If the prefix is wider than the window, and we try to wrap
19092 it, it would acquire its own wrap prefix, and so on till the
19093 iterator stack overflows. So, don't wrap the prefix. */
19094 it
->line_wrap
= TRUNCATE
;
19095 it
->avoid_cursor_p
= 1;
19101 /* Remove N glyphs at the start of a reversed IT->glyph_row. Called
19102 only for R2L lines from display_line and display_string, when they
19103 decide that too many glyphs were produced by PRODUCE_GLYPHS, and
19104 the line/string needs to be continued on the next glyph row. */
19106 unproduce_glyphs (struct it
*it
, int n
)
19108 struct glyph
*glyph
, *end
;
19110 eassert (it
->glyph_row
);
19111 eassert (it
->glyph_row
->reversed_p
);
19112 eassert (it
->area
== TEXT_AREA
);
19113 eassert (n
<= it
->glyph_row
->used
[TEXT_AREA
]);
19115 if (n
> it
->glyph_row
->used
[TEXT_AREA
])
19116 n
= it
->glyph_row
->used
[TEXT_AREA
];
19117 glyph
= it
->glyph_row
->glyphs
[TEXT_AREA
] + n
;
19118 end
= it
->glyph_row
->glyphs
[TEXT_AREA
] + it
->glyph_row
->used
[TEXT_AREA
];
19119 for ( ; glyph
< end
; glyph
++)
19120 glyph
[-n
] = *glyph
;
19123 /* Find the positions in a bidi-reordered ROW to serve as ROW->minpos
19124 and ROW->maxpos. */
19126 find_row_edges (struct it
*it
, struct glyph_row
*row
,
19127 ptrdiff_t min_pos
, ptrdiff_t min_bpos
,
19128 ptrdiff_t max_pos
, ptrdiff_t max_bpos
)
19130 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19131 lines' rows is implemented for bidi-reordered rows. */
19133 /* ROW->minpos is the value of min_pos, the minimal buffer position
19134 we have in ROW, or ROW->start.pos if that is smaller. */
19135 if (min_pos
<= ZV
&& min_pos
< row
->start
.pos
.charpos
)
19136 SET_TEXT_POS (row
->minpos
, min_pos
, min_bpos
);
19138 /* We didn't find buffer positions smaller than ROW->start, or
19139 didn't find _any_ valid buffer positions in any of the glyphs,
19140 so we must trust the iterator's computed positions. */
19141 row
->minpos
= row
->start
.pos
;
19144 max_pos
= CHARPOS (it
->current
.pos
);
19145 max_bpos
= BYTEPOS (it
->current
.pos
);
19148 /* Here are the various use-cases for ending the row, and the
19149 corresponding values for ROW->maxpos:
19151 Line ends in a newline from buffer eol_pos + 1
19152 Line is continued from buffer max_pos + 1
19153 Line is truncated on right it->current.pos
19154 Line ends in a newline from string max_pos + 1(*)
19155 (*) + 1 only when line ends in a forward scan
19156 Line is continued from string max_pos
19157 Line is continued from display vector max_pos
19158 Line is entirely from a string min_pos == max_pos
19159 Line is entirely from a display vector min_pos == max_pos
19160 Line that ends at ZV ZV
19162 If you discover other use-cases, please add them here as
19164 if (row
->ends_at_zv_p
)
19165 row
->maxpos
= it
->current
.pos
;
19166 else if (row
->used
[TEXT_AREA
])
19168 int seen_this_string
= 0;
19169 struct glyph_row
*r1
= row
- 1;
19171 /* Did we see the same display string on the previous row? */
19172 if (STRINGP (it
->object
)
19173 /* this is not the first row */
19174 && row
> it
->w
->desired_matrix
->rows
19175 /* previous row is not the header line */
19176 && !r1
->mode_line_p
19177 /* previous row also ends in a newline from a string */
19178 && r1
->ends_in_newline_from_string_p
)
19180 struct glyph
*start
, *end
;
19182 /* Search for the last glyph of the previous row that came
19183 from buffer or string. Depending on whether the row is
19184 L2R or R2L, we need to process it front to back or the
19185 other way round. */
19186 if (!r1
->reversed_p
)
19188 start
= r1
->glyphs
[TEXT_AREA
];
19189 end
= start
+ r1
->used
[TEXT_AREA
];
19190 /* Glyphs inserted by redisplay have an integer (zero)
19191 as their object. */
19193 && INTEGERP ((end
- 1)->object
)
19194 && (end
- 1)->charpos
<= 0)
19198 if (EQ ((end
- 1)->object
, it
->object
))
19199 seen_this_string
= 1;
19202 /* If all the glyphs of the previous row were inserted
19203 by redisplay, it means the previous row was
19204 produced from a single newline, which is only
19205 possible if that newline came from the same string
19206 as the one which produced this ROW. */
19207 seen_this_string
= 1;
19211 end
= r1
->glyphs
[TEXT_AREA
] - 1;
19212 start
= end
+ r1
->used
[TEXT_AREA
];
19214 && INTEGERP ((end
+ 1)->object
)
19215 && (end
+ 1)->charpos
<= 0)
19219 if (EQ ((end
+ 1)->object
, it
->object
))
19220 seen_this_string
= 1;
19223 seen_this_string
= 1;
19226 /* Take note of each display string that covers a newline only
19227 once, the first time we see it. This is for when a display
19228 string includes more than one newline in it. */
19229 if (row
->ends_in_newline_from_string_p
&& !seen_this_string
)
19231 /* If we were scanning the buffer forward when we displayed
19232 the string, we want to account for at least one buffer
19233 position that belongs to this row (position covered by
19234 the display string), so that cursor positioning will
19235 consider this row as a candidate when point is at the end
19236 of the visual line represented by this row. This is not
19237 required when scanning back, because max_pos will already
19238 have a much larger value. */
19239 if (CHARPOS (row
->end
.pos
) > max_pos
)
19240 INC_BOTH (max_pos
, max_bpos
);
19241 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19243 else if (CHARPOS (it
->eol_pos
) > 0)
19244 SET_TEXT_POS (row
->maxpos
,
19245 CHARPOS (it
->eol_pos
) + 1, BYTEPOS (it
->eol_pos
) + 1);
19246 else if (row
->continued_p
)
19248 /* If max_pos is different from IT's current position, it
19249 means IT->method does not belong to the display element
19250 at max_pos. However, it also means that the display
19251 element at max_pos was displayed in its entirety on this
19252 line, which is equivalent to saying that the next line
19253 starts at the next buffer position. */
19254 if (IT_CHARPOS (*it
) == max_pos
&& it
->method
!= GET_FROM_BUFFER
)
19255 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19258 INC_BOTH (max_pos
, max_bpos
);
19259 SET_TEXT_POS (row
->maxpos
, max_pos
, max_bpos
);
19262 else if (row
->truncated_on_right_p
)
19263 /* display_line already called reseat_at_next_visible_line_start,
19264 which puts the iterator at the beginning of the next line, in
19265 the logical order. */
19266 row
->maxpos
= it
->current
.pos
;
19267 else if (max_pos
== min_pos
&& it
->method
!= GET_FROM_BUFFER
)
19268 /* A line that is entirely from a string/image/stretch... */
19269 row
->maxpos
= row
->minpos
;
19274 row
->maxpos
= it
->current
.pos
;
19277 /* Construct the glyph row IT->glyph_row in the desired matrix of
19278 IT->w from text at the current position of IT. See dispextern.h
19279 for an overview of struct it. Value is non-zero if
19280 IT->glyph_row displays text, as opposed to a line displaying ZV
19284 display_line (struct it
*it
)
19286 struct glyph_row
*row
= it
->glyph_row
;
19287 Lisp_Object overlay_arrow_string
;
19289 void *wrap_data
= NULL
;
19290 int may_wrap
= 0, wrap_x
IF_LINT (= 0);
19291 int wrap_row_used
= -1;
19292 int wrap_row_ascent
IF_LINT (= 0), wrap_row_height
IF_LINT (= 0);
19293 int wrap_row_phys_ascent
IF_LINT (= 0), wrap_row_phys_height
IF_LINT (= 0);
19294 int wrap_row_extra_line_spacing
IF_LINT (= 0);
19295 ptrdiff_t wrap_row_min_pos
IF_LINT (= 0), wrap_row_min_bpos
IF_LINT (= 0);
19296 ptrdiff_t wrap_row_max_pos
IF_LINT (= 0), wrap_row_max_bpos
IF_LINT (= 0);
19298 ptrdiff_t min_pos
= ZV
+ 1, max_pos
= 0;
19299 ptrdiff_t min_bpos
IF_LINT (= 0), max_bpos
IF_LINT (= 0);
19301 /* We always start displaying at hpos zero even if hscrolled. */
19302 eassert (it
->hpos
== 0 && it
->current_x
== 0);
19304 if (MATRIX_ROW_VPOS (row
, it
->w
->desired_matrix
)
19305 >= it
->w
->desired_matrix
->nrows
)
19307 it
->w
->nrows_scale_factor
++;
19308 fonts_changed_p
= 1;
19312 /* Is IT->w showing the region? */
19313 it
->w
->region_showing
= it
->region_beg_charpos
> 0 ? it
->region_beg_charpos
: 0;
19315 /* Clear the result glyph row and enable it. */
19316 prepare_desired_row (row
);
19318 row
->y
= it
->current_y
;
19319 row
->start
= it
->start
;
19320 row
->continuation_lines_width
= it
->continuation_lines_width
;
19321 row
->displays_text_p
= 1;
19322 row
->starts_in_middle_of_char_p
= it
->starts_in_middle_of_char_p
;
19323 it
->starts_in_middle_of_char_p
= 0;
19325 /* Arrange the overlays nicely for our purposes. Usually, we call
19326 display_line on only one line at a time, in which case this
19327 can't really hurt too much, or we call it on lines which appear
19328 one after another in the buffer, in which case all calls to
19329 recenter_overlay_lists but the first will be pretty cheap. */
19330 recenter_overlay_lists (current_buffer
, IT_CHARPOS (*it
));
19332 /* Move over display elements that are not visible because we are
19333 hscrolled. This may stop at an x-position < IT->first_visible_x
19334 if the first glyph is partially visible or if we hit a line end. */
19335 if (it
->current_x
< it
->first_visible_x
)
19337 enum move_it_result move_result
;
19339 this_line_min_pos
= row
->start
.pos
;
19340 move_result
= move_it_in_display_line_to (it
, ZV
, it
->first_visible_x
,
19341 MOVE_TO_POS
| MOVE_TO_X
);
19342 /* If we are under a large hscroll, move_it_in_display_line_to
19343 could hit the end of the line without reaching
19344 it->first_visible_x. Pretend that we did reach it. This is
19345 especially important on a TTY, where we will call
19346 extend_face_to_end_of_line, which needs to know how many
19347 blank glyphs to produce. */
19348 if (it
->current_x
< it
->first_visible_x
19349 && (move_result
== MOVE_NEWLINE_OR_CR
19350 || move_result
== MOVE_POS_MATCH_OR_ZV
))
19351 it
->current_x
= it
->first_visible_x
;
19353 /* Record the smallest positions seen while we moved over
19354 display elements that are not visible. This is needed by
19355 redisplay_internal for optimizing the case where the cursor
19356 stays inside the same line. The rest of this function only
19357 considers positions that are actually displayed, so
19358 RECORD_MAX_MIN_POS will not otherwise record positions that
19359 are hscrolled to the left of the left edge of the window. */
19360 min_pos
= CHARPOS (this_line_min_pos
);
19361 min_bpos
= BYTEPOS (this_line_min_pos
);
19365 /* We only do this when not calling `move_it_in_display_line_to'
19366 above, because move_it_in_display_line_to calls
19367 handle_line_prefix itself. */
19368 handle_line_prefix (it
);
19371 /* Get the initial row height. This is either the height of the
19372 text hscrolled, if there is any, or zero. */
19373 row
->ascent
= it
->max_ascent
;
19374 row
->height
= it
->max_ascent
+ it
->max_descent
;
19375 row
->phys_ascent
= it
->max_phys_ascent
;
19376 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
19377 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
19379 /* Utility macro to record max and min buffer positions seen until now. */
19380 #define RECORD_MAX_MIN_POS(IT) \
19383 int composition_p = !STRINGP ((IT)->string) \
19384 && ((IT)->what == IT_COMPOSITION); \
19385 ptrdiff_t current_pos = \
19386 composition_p ? (IT)->cmp_it.charpos \
19387 : IT_CHARPOS (*(IT)); \
19388 ptrdiff_t current_bpos = \
19389 composition_p ? CHAR_TO_BYTE (current_pos) \
19390 : IT_BYTEPOS (*(IT)); \
19391 if (current_pos < min_pos) \
19393 min_pos = current_pos; \
19394 min_bpos = current_bpos; \
19396 if (IT_CHARPOS (*it) > max_pos) \
19398 max_pos = IT_CHARPOS (*it); \
19399 max_bpos = IT_BYTEPOS (*it); \
19404 /* Loop generating characters. The loop is left with IT on the next
19405 character to display. */
19408 int n_glyphs_before
, hpos_before
, x_before
;
19410 int ascent
= 0, descent
= 0, phys_ascent
= 0, phys_descent
= 0;
19412 /* Retrieve the next thing to display. Value is zero if end of
19414 if (!get_next_display_element (it
))
19416 /* Maybe add a space at the end of this line that is used to
19417 display the cursor there under X. Set the charpos of the
19418 first glyph of blank lines not corresponding to any text
19420 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19421 row
->exact_window_width_line_p
= 1;
19422 else if ((append_space_for_newline (it
, 1) && row
->used
[TEXT_AREA
] == 1)
19423 || row
->used
[TEXT_AREA
] == 0)
19425 row
->glyphs
[TEXT_AREA
]->charpos
= -1;
19426 row
->displays_text_p
= 0;
19428 if (!NILP (BVAR (XBUFFER (it
->w
->contents
), indicate_empty_lines
))
19429 && (!MINI_WINDOW_P (it
->w
)
19430 || (minibuf_level
&& EQ (it
->window
, minibuf_window
))))
19431 row
->indicate_empty_line_p
= 1;
19434 it
->continuation_lines_width
= 0;
19435 row
->ends_at_zv_p
= 1;
19436 /* A row that displays right-to-left text must always have
19437 its last face extended all the way to the end of line,
19438 even if this row ends in ZV, because we still write to
19439 the screen left to right. We also need to extend the
19440 last face if the default face is remapped to some
19441 different face, otherwise the functions that clear
19442 portions of the screen will clear with the default face's
19443 background color. */
19444 if (row
->reversed_p
19445 || lookup_basic_face (it
->f
, DEFAULT_FACE_ID
) != DEFAULT_FACE_ID
)
19446 extend_face_to_end_of_line (it
);
19450 /* Now, get the metrics of what we want to display. This also
19451 generates glyphs in `row' (which is IT->glyph_row). */
19452 n_glyphs_before
= row
->used
[TEXT_AREA
];
19455 /* Remember the line height so far in case the next element doesn't
19456 fit on the line. */
19457 if (it
->line_wrap
!= TRUNCATE
)
19459 ascent
= it
->max_ascent
;
19460 descent
= it
->max_descent
;
19461 phys_ascent
= it
->max_phys_ascent
;
19462 phys_descent
= it
->max_phys_descent
;
19464 if (it
->line_wrap
== WORD_WRAP
&& it
->area
== TEXT_AREA
)
19466 if (IT_DISPLAYING_WHITESPACE (it
))
19470 SAVE_IT (wrap_it
, *it
, wrap_data
);
19472 wrap_row_used
= row
->used
[TEXT_AREA
];
19473 wrap_row_ascent
= row
->ascent
;
19474 wrap_row_height
= row
->height
;
19475 wrap_row_phys_ascent
= row
->phys_ascent
;
19476 wrap_row_phys_height
= row
->phys_height
;
19477 wrap_row_extra_line_spacing
= row
->extra_line_spacing
;
19478 wrap_row_min_pos
= min_pos
;
19479 wrap_row_min_bpos
= min_bpos
;
19480 wrap_row_max_pos
= max_pos
;
19481 wrap_row_max_bpos
= max_bpos
;
19487 PRODUCE_GLYPHS (it
);
19489 /* If this display element was in marginal areas, continue with
19491 if (it
->area
!= TEXT_AREA
)
19493 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19494 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19495 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19496 row
->phys_height
= max (row
->phys_height
,
19497 it
->max_phys_ascent
+ it
->max_phys_descent
);
19498 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19499 it
->max_extra_line_spacing
);
19500 set_iterator_to_next (it
, 1);
19504 /* Does the display element fit on the line? If we truncate
19505 lines, we should draw past the right edge of the window. If
19506 we don't truncate, we want to stop so that we can display the
19507 continuation glyph before the right margin. If lines are
19508 continued, there are two possible strategies for characters
19509 resulting in more than 1 glyph (e.g. tabs): Display as many
19510 glyphs as possible in this line and leave the rest for the
19511 continuation line, or display the whole element in the next
19512 line. Original redisplay did the former, so we do it also. */
19513 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
19514 hpos_before
= it
->hpos
;
19517 if (/* Not a newline. */
19519 /* Glyphs produced fit entirely in the line. */
19520 && it
->current_x
< it
->last_visible_x
)
19522 it
->hpos
+= nglyphs
;
19523 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19524 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19525 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19526 row
->phys_height
= max (row
->phys_height
,
19527 it
->max_phys_ascent
+ it
->max_phys_descent
);
19528 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19529 it
->max_extra_line_spacing
);
19530 if (it
->current_x
- it
->pixel_width
< it
->first_visible_x
)
19531 row
->x
= x
- it
->first_visible_x
;
19532 /* Record the maximum and minimum buffer positions seen so
19533 far in glyphs that will be displayed by this row. */
19535 RECORD_MAX_MIN_POS (it
);
19540 struct glyph
*glyph
;
19542 for (i
= 0; i
< nglyphs
; ++i
, x
= new_x
)
19544 glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
19545 new_x
= x
+ glyph
->pixel_width
;
19547 if (/* Lines are continued. */
19548 it
->line_wrap
!= TRUNCATE
19549 && (/* Glyph doesn't fit on the line. */
19550 new_x
> it
->last_visible_x
19551 /* Or it fits exactly on a window system frame. */
19552 || (new_x
== it
->last_visible_x
19553 && FRAME_WINDOW_P (it
->f
)
19554 && (row
->reversed_p
19555 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19556 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)))))
19558 /* End of a continued line. */
19561 || (new_x
== it
->last_visible_x
19562 && FRAME_WINDOW_P (it
->f
)
19563 && (row
->reversed_p
19564 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19565 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
))))
19567 /* Current glyph is the only one on the line or
19568 fits exactly on the line. We must continue
19569 the line because we can't draw the cursor
19570 after the glyph. */
19571 row
->continued_p
= 1;
19572 it
->current_x
= new_x
;
19573 it
->continuation_lines_width
+= new_x
;
19575 if (i
== nglyphs
- 1)
19577 /* If line-wrap is on, check if a previous
19578 wrap point was found. */
19579 if (wrap_row_used
> 0
19580 /* Even if there is a previous wrap
19581 point, continue the line here as
19582 usual, if (i) the previous character
19583 was a space or tab AND (ii) the
19584 current character is not. */
19586 || IT_DISPLAYING_WHITESPACE (it
)))
19589 /* Record the maximum and minimum buffer
19590 positions seen so far in glyphs that will be
19591 displayed by this row. */
19593 RECORD_MAX_MIN_POS (it
);
19594 set_iterator_to_next (it
, 1);
19595 if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19597 if (!get_next_display_element (it
))
19599 row
->exact_window_width_line_p
= 1;
19600 it
->continuation_lines_width
= 0;
19601 row
->continued_p
= 0;
19602 row
->ends_at_zv_p
= 1;
19604 else if (ITERATOR_AT_END_OF_LINE_P (it
))
19606 row
->continued_p
= 0;
19607 row
->exact_window_width_line_p
= 1;
19611 else if (it
->bidi_p
)
19612 RECORD_MAX_MIN_POS (it
);
19614 else if (CHAR_GLYPH_PADDING_P (*glyph
)
19615 && !FRAME_WINDOW_P (it
->f
))
19617 /* A padding glyph that doesn't fit on this line.
19618 This means the whole character doesn't fit
19620 if (row
->reversed_p
)
19621 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19622 - n_glyphs_before
);
19623 row
->used
[TEXT_AREA
] = n_glyphs_before
;
19625 /* Fill the rest of the row with continuation
19626 glyphs like in 20.x. */
19627 while (row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
]
19628 < row
->glyphs
[1 + TEXT_AREA
])
19629 produce_special_glyphs (it
, IT_CONTINUATION
);
19631 row
->continued_p
= 1;
19632 it
->current_x
= x_before
;
19633 it
->continuation_lines_width
+= x_before
;
19635 /* Restore the height to what it was before the
19636 element not fitting on the line. */
19637 it
->max_ascent
= ascent
;
19638 it
->max_descent
= descent
;
19639 it
->max_phys_ascent
= phys_ascent
;
19640 it
->max_phys_descent
= phys_descent
;
19642 else if (wrap_row_used
> 0)
19645 if (row
->reversed_p
)
19646 unproduce_glyphs (it
,
19647 row
->used
[TEXT_AREA
] - wrap_row_used
);
19648 RESTORE_IT (it
, &wrap_it
, wrap_data
);
19649 it
->continuation_lines_width
+= wrap_x
;
19650 row
->used
[TEXT_AREA
] = wrap_row_used
;
19651 row
->ascent
= wrap_row_ascent
;
19652 row
->height
= wrap_row_height
;
19653 row
->phys_ascent
= wrap_row_phys_ascent
;
19654 row
->phys_height
= wrap_row_phys_height
;
19655 row
->extra_line_spacing
= wrap_row_extra_line_spacing
;
19656 min_pos
= wrap_row_min_pos
;
19657 min_bpos
= wrap_row_min_bpos
;
19658 max_pos
= wrap_row_max_pos
;
19659 max_bpos
= wrap_row_max_bpos
;
19660 row
->continued_p
= 1;
19661 row
->ends_at_zv_p
= 0;
19662 row
->exact_window_width_line_p
= 0;
19663 it
->continuation_lines_width
+= x
;
19665 /* Make sure that a non-default face is extended
19666 up to the right margin of the window. */
19667 extend_face_to_end_of_line (it
);
19669 else if (it
->c
== '\t' && FRAME_WINDOW_P (it
->f
))
19671 /* A TAB that extends past the right edge of the
19672 window. This produces a single glyph on
19673 window system frames. We leave the glyph in
19674 this row and let it fill the row, but don't
19675 consume the TAB. */
19676 if ((row
->reversed_p
19677 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19678 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19679 produce_special_glyphs (it
, IT_CONTINUATION
);
19680 it
->continuation_lines_width
+= it
->last_visible_x
;
19681 row
->ends_in_middle_of_char_p
= 1;
19682 row
->continued_p
= 1;
19683 glyph
->pixel_width
= it
->last_visible_x
- x
;
19684 it
->starts_in_middle_of_char_p
= 1;
19688 /* Something other than a TAB that draws past
19689 the right edge of the window. Restore
19690 positions to values before the element. */
19691 if (row
->reversed_p
)
19692 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
19693 - (n_glyphs_before
+ i
));
19694 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
19696 /* Display continuation glyphs. */
19697 it
->current_x
= x_before
;
19698 it
->continuation_lines_width
+= x
;
19699 if (!FRAME_WINDOW_P (it
->f
)
19700 || (row
->reversed_p
19701 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19702 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19703 produce_special_glyphs (it
, IT_CONTINUATION
);
19704 row
->continued_p
= 1;
19706 extend_face_to_end_of_line (it
);
19708 if (nglyphs
> 1 && i
> 0)
19710 row
->ends_in_middle_of_char_p
= 1;
19711 it
->starts_in_middle_of_char_p
= 1;
19714 /* Restore the height to what it was before the
19715 element not fitting on the line. */
19716 it
->max_ascent
= ascent
;
19717 it
->max_descent
= descent
;
19718 it
->max_phys_ascent
= phys_ascent
;
19719 it
->max_phys_descent
= phys_descent
;
19724 else if (new_x
> it
->first_visible_x
)
19726 /* Increment number of glyphs actually displayed. */
19729 /* Record the maximum and minimum buffer positions
19730 seen so far in glyphs that will be displayed by
19733 RECORD_MAX_MIN_POS (it
);
19735 if (x
< it
->first_visible_x
)
19736 /* Glyph is partially visible, i.e. row starts at
19737 negative X position. */
19738 row
->x
= x
- it
->first_visible_x
;
19742 /* Glyph is completely off the left margin of the
19743 window. This should not happen because of the
19744 move_it_in_display_line at the start of this
19745 function, unless the text display area of the
19746 window is empty. */
19747 eassert (it
->first_visible_x
<= it
->last_visible_x
);
19750 /* Even if this display element produced no glyphs at all,
19751 we want to record its position. */
19752 if (it
->bidi_p
&& nglyphs
== 0)
19753 RECORD_MAX_MIN_POS (it
);
19755 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
19756 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
19757 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
19758 row
->phys_height
= max (row
->phys_height
,
19759 it
->max_phys_ascent
+ it
->max_phys_descent
);
19760 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
19761 it
->max_extra_line_spacing
);
19763 /* End of this display line if row is continued. */
19764 if (row
->continued_p
|| row
->ends_at_zv_p
)
19769 /* Is this a line end? If yes, we're also done, after making
19770 sure that a non-default face is extended up to the right
19771 margin of the window. */
19772 if (ITERATOR_AT_END_OF_LINE_P (it
))
19774 int used_before
= row
->used
[TEXT_AREA
];
19776 row
->ends_in_newline_from_string_p
= STRINGP (it
->object
);
19778 /* Add a space at the end of the line that is used to
19779 display the cursor there. */
19780 if (!IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19781 append_space_for_newline (it
, 0);
19783 /* Extend the face to the end of the line. */
19784 extend_face_to_end_of_line (it
);
19786 /* Make sure we have the position. */
19787 if (used_before
== 0)
19788 row
->glyphs
[TEXT_AREA
]->charpos
= CHARPOS (it
->position
);
19790 /* Record the position of the newline, for use in
19792 it
->eol_pos
= it
->current
.pos
;
19794 /* Consume the line end. This skips over invisible lines. */
19795 set_iterator_to_next (it
, 1);
19796 it
->continuation_lines_width
= 0;
19800 /* Proceed with next display element. Note that this skips
19801 over lines invisible because of selective display. */
19802 set_iterator_to_next (it
, 1);
19804 /* If we truncate lines, we are done when the last displayed
19805 glyphs reach past the right margin of the window. */
19806 if (it
->line_wrap
== TRUNCATE
19807 && (FRAME_WINDOW_P (it
->f
) && WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19808 ? (it
->current_x
>= it
->last_visible_x
)
19809 : (it
->current_x
> it
->last_visible_x
)))
19811 /* Maybe add truncation glyphs. */
19812 if (!FRAME_WINDOW_P (it
->f
)
19813 || (row
->reversed_p
19814 ? WINDOW_LEFT_FRINGE_WIDTH (it
->w
)
19815 : WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)) == 0)
19819 if (!row
->reversed_p
)
19821 for (i
= row
->used
[TEXT_AREA
] - 1; i
> 0; --i
)
19822 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19827 for (i
= 0; i
< row
->used
[TEXT_AREA
]; i
++)
19828 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][i
]))
19830 /* Remove any padding glyphs at the front of ROW, to
19831 make room for the truncation glyphs we will be
19832 adding below. The loop below always inserts at
19833 least one truncation glyph, so also remove the
19834 last glyph added to ROW. */
19835 unproduce_glyphs (it
, i
+ 1);
19836 /* Adjust i for the loop below. */
19837 i
= row
->used
[TEXT_AREA
] - (i
+ 1);
19840 it
->current_x
= x_before
;
19841 if (!FRAME_WINDOW_P (it
->f
))
19843 for (n
= row
->used
[TEXT_AREA
]; i
< n
; ++i
)
19845 row
->used
[TEXT_AREA
] = i
;
19846 produce_special_glyphs (it
, IT_TRUNCATION
);
19851 row
->used
[TEXT_AREA
] = i
;
19852 produce_special_glyphs (it
, IT_TRUNCATION
);
19855 else if (IT_OVERFLOW_NEWLINE_INTO_FRINGE (it
))
19857 /* Don't truncate if we can overflow newline into fringe. */
19858 if (!get_next_display_element (it
))
19860 it
->continuation_lines_width
= 0;
19861 row
->ends_at_zv_p
= 1;
19862 row
->exact_window_width_line_p
= 1;
19865 if (ITERATOR_AT_END_OF_LINE_P (it
))
19867 row
->exact_window_width_line_p
= 1;
19868 goto at_end_of_line
;
19870 it
->current_x
= x_before
;
19873 row
->truncated_on_right_p
= 1;
19874 it
->continuation_lines_width
= 0;
19875 reseat_at_next_visible_line_start (it
, 0);
19876 row
->ends_at_zv_p
= FETCH_BYTE (IT_BYTEPOS (*it
) - 1) != '\n';
19877 it
->hpos
= hpos_before
;
19883 bidi_unshelve_cache (wrap_data
, 1);
19885 /* If line is not empty and hscrolled, maybe insert truncation glyphs
19886 at the left window margin. */
19887 if (it
->first_visible_x
19888 && IT_CHARPOS (*it
) != CHARPOS (row
->start
.pos
))
19890 if (!FRAME_WINDOW_P (it
->f
)
19891 || (row
->reversed_p
19892 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
19893 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
19894 insert_left_trunc_glyphs (it
);
19895 row
->truncated_on_left_p
= 1;
19898 /* Remember the position at which this line ends.
19900 BIDI Note: any code that needs MATRIX_ROW_START/END_CHARPOS
19901 cannot be before the call to find_row_edges below, since that is
19902 where these positions are determined. */
19903 row
->end
= it
->current
;
19906 row
->minpos
= row
->start
.pos
;
19907 row
->maxpos
= row
->end
.pos
;
19911 /* ROW->minpos and ROW->maxpos must be the smallest and
19912 `1 + the largest' buffer positions in ROW. But if ROW was
19913 bidi-reordered, these two positions can be anywhere in the
19914 row, so we must determine them now. */
19915 find_row_edges (it
, row
, min_pos
, min_bpos
, max_pos
, max_bpos
);
19918 /* If the start of this line is the overlay arrow-position, then
19919 mark this glyph row as the one containing the overlay arrow.
19920 This is clearly a mess with variable size fonts. It would be
19921 better to let it be displayed like cursors under X. */
19922 if ((MATRIX_ROW_DISPLAYS_TEXT_P (row
) || !overlay_arrow_seen
)
19923 && (overlay_arrow_string
= overlay_arrow_at_row (it
, row
),
19924 !NILP (overlay_arrow_string
)))
19926 /* Overlay arrow in window redisplay is a fringe bitmap. */
19927 if (STRINGP (overlay_arrow_string
))
19929 struct glyph_row
*arrow_row
19930 = get_overlay_arrow_glyph_row (it
->w
, overlay_arrow_string
);
19931 struct glyph
*glyph
= arrow_row
->glyphs
[TEXT_AREA
];
19932 struct glyph
*arrow_end
= glyph
+ arrow_row
->used
[TEXT_AREA
];
19933 struct glyph
*p
= row
->glyphs
[TEXT_AREA
];
19934 struct glyph
*p2
, *end
;
19936 /* Copy the arrow glyphs. */
19937 while (glyph
< arrow_end
)
19940 /* Throw away padding glyphs. */
19942 end
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
];
19943 while (p2
< end
&& CHAR_GLYPH_PADDING_P (*p2
))
19949 row
->used
[TEXT_AREA
] = p2
- row
->glyphs
[TEXT_AREA
];
19954 eassert (INTEGERP (overlay_arrow_string
));
19955 row
->overlay_arrow_bitmap
= XINT (overlay_arrow_string
);
19957 overlay_arrow_seen
= 1;
19960 /* Highlight trailing whitespace. */
19961 if (!NILP (Vshow_trailing_whitespace
))
19962 highlight_trailing_whitespace (it
->f
, it
->glyph_row
);
19964 /* Compute pixel dimensions of this line. */
19965 compute_line_metrics (it
);
19967 /* Implementation note: No changes in the glyphs of ROW or in their
19968 faces can be done past this point, because compute_line_metrics
19969 computes ROW's hash value and stores it within the glyph_row
19972 /* Record whether this row ends inside an ellipsis. */
19973 row
->ends_in_ellipsis_p
19974 = (it
->method
== GET_FROM_DISPLAY_VECTOR
19975 && it
->ellipsis_p
);
19977 /* Save fringe bitmaps in this row. */
19978 row
->left_user_fringe_bitmap
= it
->left_user_fringe_bitmap
;
19979 row
->left_user_fringe_face_id
= it
->left_user_fringe_face_id
;
19980 row
->right_user_fringe_bitmap
= it
->right_user_fringe_bitmap
;
19981 row
->right_user_fringe_face_id
= it
->right_user_fringe_face_id
;
19983 it
->left_user_fringe_bitmap
= 0;
19984 it
->left_user_fringe_face_id
= 0;
19985 it
->right_user_fringe_bitmap
= 0;
19986 it
->right_user_fringe_face_id
= 0;
19988 /* Maybe set the cursor. */
19989 cvpos
= it
->w
->cursor
.vpos
;
19991 /* In bidi-reordered rows, keep checking for proper cursor
19992 position even if one has been found already, because buffer
19993 positions in such rows change non-linearly with ROW->VPOS,
19994 when a line is continued. One exception: when we are at ZV,
19995 display cursor on the first suitable glyph row, since all
19996 the empty rows after that also have their position set to ZV. */
19997 /* FIXME: Revisit this when glyph ``spilling'' in continuation
19998 lines' rows is implemented for bidi-reordered rows. */
20000 && !MATRIX_ROW (it
->w
->desired_matrix
, cvpos
)->ends_at_zv_p
))
20001 && PT
>= MATRIX_ROW_START_CHARPOS (row
)
20002 && PT
<= MATRIX_ROW_END_CHARPOS (row
)
20003 && cursor_row_p (row
))
20004 set_cursor_from_row (it
->w
, row
, it
->w
->desired_matrix
, 0, 0, 0, 0);
20006 /* Prepare for the next line. This line starts horizontally at (X
20007 HPOS) = (0 0). Vertical positions are incremented. As a
20008 convenience for the caller, IT->glyph_row is set to the next
20010 it
->current_x
= it
->hpos
= 0;
20011 it
->current_y
+= row
->height
;
20012 SET_TEXT_POS (it
->eol_pos
, 0, 0);
20015 /* The next row should by default use the same value of the
20016 reversed_p flag as this one. set_iterator_to_next decides when
20017 it's a new paragraph, and PRODUCE_GLYPHS recomputes the value of
20018 the flag accordingly. */
20019 if (it
->glyph_row
< MATRIX_BOTTOM_TEXT_ROW (it
->w
->desired_matrix
, it
->w
))
20020 it
->glyph_row
->reversed_p
= row
->reversed_p
;
20021 it
->start
= row
->end
;
20022 return MATRIX_ROW_DISPLAYS_TEXT_P (row
);
20024 #undef RECORD_MAX_MIN_POS
20027 DEFUN ("current-bidi-paragraph-direction", Fcurrent_bidi_paragraph_direction
,
20028 Scurrent_bidi_paragraph_direction
, 0, 1, 0,
20029 doc
: /* Return paragraph direction at point in BUFFER.
20030 Value is either `left-to-right' or `right-to-left'.
20031 If BUFFER is omitted or nil, it defaults to the current buffer.
20033 Paragraph direction determines how the text in the paragraph is displayed.
20034 In left-to-right paragraphs, text begins at the left margin of the window
20035 and the reading direction is generally left to right. In right-to-left
20036 paragraphs, text begins at the right margin and is read from right to left.
20038 See also `bidi-paragraph-direction'. */)
20039 (Lisp_Object buffer
)
20041 struct buffer
*buf
= current_buffer
;
20042 struct buffer
*old
= buf
;
20044 if (! NILP (buffer
))
20046 CHECK_BUFFER (buffer
);
20047 buf
= XBUFFER (buffer
);
20050 if (NILP (BVAR (buf
, bidi_display_reordering
))
20051 || NILP (BVAR (buf
, enable_multibyte_characters
))
20052 /* When we are loading loadup.el, the character property tables
20053 needed for bidi iteration are not yet available. */
20054 || !NILP (Vpurify_flag
))
20055 return Qleft_to_right
;
20056 else if (!NILP (BVAR (buf
, bidi_paragraph_direction
)))
20057 return BVAR (buf
, bidi_paragraph_direction
);
20060 /* Determine the direction from buffer text. We could try to
20061 use current_matrix if it is up to date, but this seems fast
20062 enough as it is. */
20063 struct bidi_it itb
;
20064 ptrdiff_t pos
= BUF_PT (buf
);
20065 ptrdiff_t bytepos
= BUF_PT_BYTE (buf
);
20067 void *itb_data
= bidi_shelve_cache ();
20069 set_buffer_temp (buf
);
20070 /* bidi_paragraph_init finds the base direction of the paragraph
20071 by searching forward from paragraph start. We need the base
20072 direction of the current or _previous_ paragraph, so we need
20073 to make sure we are within that paragraph. To that end, find
20074 the previous non-empty line. */
20075 if (pos
>= ZV
&& pos
> BEGV
)
20076 DEC_BOTH (pos
, bytepos
);
20077 if (fast_looking_at (build_string ("[\f\t ]*\n"),
20078 pos
, bytepos
, ZV
, ZV_BYTE
, Qnil
) > 0)
20080 while ((c
= FETCH_BYTE (bytepos
)) == '\n'
20081 || c
== ' ' || c
== '\t' || c
== '\f')
20083 if (bytepos
<= BEGV_BYTE
)
20088 while (!CHAR_HEAD_P (FETCH_BYTE (bytepos
)))
20091 bidi_init_it (pos
, bytepos
, FRAME_WINDOW_P (SELECTED_FRAME ()), &itb
);
20092 itb
.paragraph_dir
= NEUTRAL_DIR
;
20093 itb
.string
.s
= NULL
;
20094 itb
.string
.lstring
= Qnil
;
20095 itb
.string
.bufpos
= 0;
20096 itb
.string
.unibyte
= 0;
20097 /* We have no window to use here for ignoring window-specific
20098 overlays. Using NULL for window pointer will cause
20099 compute_display_string_pos to use the current buffer. */
20101 bidi_paragraph_init (NEUTRAL_DIR
, &itb
, 1);
20102 bidi_unshelve_cache (itb_data
, 0);
20103 set_buffer_temp (old
);
20104 switch (itb
.paragraph_dir
)
20107 return Qleft_to_right
;
20110 return Qright_to_left
;
20118 DEFUN ("move-point-visually", Fmove_point_visually
,
20119 Smove_point_visually
, 1, 1, 0,
20120 doc
: /* Move point in the visual order in the specified DIRECTION.
20121 DIRECTION can be 1, meaning move to the right, or -1, which moves to the
20124 Value is the new character position of point. */)
20125 (Lisp_Object direction
)
20127 struct window
*w
= XWINDOW (selected_window
);
20128 struct buffer
*b
= NULL
;
20129 struct glyph_row
*row
;
20131 Lisp_Object paragraph_dir
;
20133 #define ROW_GLYPH_NEWLINE_P(ROW,GLYPH) \
20134 (!(ROW)->continued_p \
20135 && INTEGERP ((GLYPH)->object) \
20136 && (GLYPH)->type == CHAR_GLYPH \
20137 && (GLYPH)->u.ch == ' ' \
20138 && (GLYPH)->charpos >= 0 \
20139 && !(GLYPH)->avoid_cursor_p)
20141 CHECK_NUMBER (direction
);
20142 dir
= XINT (direction
);
20148 if (BUFFERP (w
->contents
))
20149 b
= XBUFFER (w
->contents
);
20151 /* If current matrix is up-to-date, we can use the information
20152 recorded in the glyphs, at least as long as the goal is on the
20154 if (w
->window_end_valid
20155 && !windows_or_buffers_changed
20157 && !b
->clip_changed
20158 && !b
->prevent_redisplay_optimizations_p
20159 && w
->last_modified
>= BUF_MODIFF (b
)
20160 && w
->last_overlay_modified
>= BUF_OVERLAY_MODIFF (b
)
20161 && w
->cursor
.vpos
>= 0
20162 && w
->cursor
.vpos
< w
->current_matrix
->nrows
20163 && (row
= MATRIX_ROW (w
->current_matrix
, w
->cursor
.vpos
))->enabled_p
)
20165 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
20166 struct glyph
*e
= dir
> 0 ? g
+ row
->used
[TEXT_AREA
] : g
- 1;
20167 struct glyph
*gpt
= g
+ w
->cursor
.hpos
;
20169 for (g
= gpt
+ dir
; (dir
> 0 ? g
< e
: g
> e
); g
+= dir
)
20171 if (BUFFERP (g
->object
) && g
->charpos
!= PT
)
20173 SET_PT (g
->charpos
);
20174 w
->cursor
.vpos
= -1;
20175 return make_number (PT
);
20177 else if (!INTEGERP (g
->object
) && !EQ (g
->object
, gpt
->object
))
20181 if (BUFFERP (gpt
->object
))
20184 if ((gpt
->resolved_level
- row
->reversed_p
) % 2 == 0)
20185 new_pos
+= (row
->reversed_p
? -dir
: dir
);
20187 new_pos
-= (row
->reversed_p
? -dir
: dir
);;
20189 else if (BUFFERP (g
->object
))
20190 new_pos
= g
->charpos
;
20194 w
->cursor
.vpos
= -1;
20195 return make_number (PT
);
20197 else if (ROW_GLYPH_NEWLINE_P (row
, g
))
20199 /* Glyphs inserted at the end of a non-empty line for
20200 positioning the cursor have zero charpos, so we must
20201 deduce the value of point by other means. */
20202 if (g
->charpos
> 0)
20203 SET_PT (g
->charpos
);
20204 else if (row
->ends_at_zv_p
&& PT
!= ZV
)
20206 else if (PT
!= MATRIX_ROW_END_CHARPOS (row
) - 1)
20207 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20210 w
->cursor
.vpos
= -1;
20211 return make_number (PT
);
20214 if (g
== e
|| INTEGERP (g
->object
))
20216 if (row
->truncated_on_left_p
|| row
->truncated_on_right_p
)
20217 goto simulate_display
;
20218 if (!row
->reversed_p
)
20222 if (row
< MATRIX_FIRST_TEXT_ROW (w
->current_matrix
)
20223 || row
> MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
20224 goto simulate_display
;
20228 if (row
->reversed_p
&& !row
->continued_p
)
20230 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20231 w
->cursor
.vpos
= -1;
20232 return make_number (PT
);
20234 g
= row
->glyphs
[TEXT_AREA
];
20235 e
= g
+ row
->used
[TEXT_AREA
];
20236 for ( ; g
< e
; g
++)
20238 if (BUFFERP (g
->object
)
20239 /* Empty lines have only one glyph, which stands
20240 for the newline, and whose charpos is the
20241 buffer position of the newline. */
20242 || ROW_GLYPH_NEWLINE_P (row
, g
)
20243 /* When the buffer ends in a newline, the line at
20244 EOB also has one glyph, but its charpos is -1. */
20245 || (row
->ends_at_zv_p
20246 && !row
->reversed_p
20247 && INTEGERP (g
->object
)
20248 && g
->type
== CHAR_GLYPH
20249 && g
->u
.ch
== ' '))
20251 if (g
->charpos
> 0)
20252 SET_PT (g
->charpos
);
20253 else if (!row
->reversed_p
20254 && row
->ends_at_zv_p
20259 w
->cursor
.vpos
= -1;
20260 return make_number (PT
);
20266 if (!row
->reversed_p
&& !row
->continued_p
)
20268 SET_PT (MATRIX_ROW_END_CHARPOS (row
) - 1);
20269 w
->cursor
.vpos
= -1;
20270 return make_number (PT
);
20272 e
= row
->glyphs
[TEXT_AREA
];
20273 g
= e
+ row
->used
[TEXT_AREA
] - 1;
20274 for ( ; g
>= e
; g
--)
20276 if (BUFFERP (g
->object
)
20277 || (ROW_GLYPH_NEWLINE_P (row
, g
)
20279 /* Empty R2L lines on GUI frames have the buffer
20280 position of the newline stored in the stretch
20282 || g
->type
== STRETCH_GLYPH
20283 || (row
->ends_at_zv_p
20285 && INTEGERP (g
->object
)
20286 && g
->type
== CHAR_GLYPH
20287 && g
->u
.ch
== ' '))
20289 if (g
->charpos
> 0)
20290 SET_PT (g
->charpos
);
20291 else if (row
->reversed_p
20292 && row
->ends_at_zv_p
20297 w
->cursor
.vpos
= -1;
20298 return make_number (PT
);
20307 /* If we wind up here, we failed to move by using the glyphs, so we
20308 need to simulate display instead. */
20311 paragraph_dir
= Fcurrent_bidi_paragraph_direction (w
->contents
);
20313 paragraph_dir
= Qleft_to_right
;
20314 if (EQ (paragraph_dir
, Qright_to_left
))
20316 if (PT
<= BEGV
&& dir
< 0)
20317 xsignal0 (Qbeginning_of_buffer
);
20318 else if (PT
>= ZV
&& dir
> 0)
20319 xsignal0 (Qend_of_buffer
);
20322 struct text_pos pt
;
20324 int pt_x
, target_x
, pixel_width
, pt_vpos
;
20326 bool overshoot_expected
= false;
20327 bool target_is_eol_p
= false;
20329 /* Setup the arena. */
20330 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
20331 start_display (&it
, w
, pt
);
20333 if (it
.cmp_it
.id
< 0
20334 && it
.method
== GET_FROM_STRING
20335 && it
.area
== TEXT_AREA
20336 && it
.string_from_display_prop_p
20337 && (it
.sp
> 0 && it
.stack
[it
.sp
- 1].method
== GET_FROM_BUFFER
))
20338 overshoot_expected
= true;
20340 /* Find the X coordinate of point. We start from the beginning
20341 of this or previous line to make sure we are before point in
20342 the logical order (since the move_it_* functions can only
20344 reseat_at_previous_visible_line_start (&it
);
20345 it
.current_x
= it
.hpos
= it
.current_y
= it
.vpos
= 0;
20346 if (IT_CHARPOS (it
) != PT
)
20347 move_it_to (&it
, overshoot_expected
? PT
- 1 : PT
,
20348 -1, -1, -1, MOVE_TO_POS
);
20349 pt_x
= it
.current_x
;
20351 if (dir
> 0 || overshoot_expected
)
20353 struct glyph_row
*row
= it
.glyph_row
;
20355 /* When point is at beginning of line, we don't have
20356 information about the glyph there loaded into struct
20357 it. Calling get_next_display_element fixes that. */
20359 get_next_display_element (&it
);
20360 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20361 it
.glyph_row
= NULL
;
20362 PRODUCE_GLYPHS (&it
); /* compute it.pixel_width */
20363 it
.glyph_row
= row
;
20364 /* PRODUCE_GLYPHS advances it.current_x, so we must restore
20365 it, lest it will become out of sync with it's buffer
20367 it
.current_x
= pt_x
;
20370 at_eol_p
= ITERATOR_AT_END_OF_LINE_P (&it
);
20371 pixel_width
= it
.pixel_width
;
20372 if (overshoot_expected
&& at_eol_p
)
20374 else if (pixel_width
<= 0)
20377 /* If there's a display string at point, we are actually at the
20378 glyph to the left of point, so we need to correct the X
20380 if (overshoot_expected
)
20381 pt_x
+= pixel_width
;
20383 /* Compute target X coordinate, either to the left or to the
20384 right of point. On TTY frames, all characters have the same
20385 pixel width of 1, so we can use that. On GUI frames we don't
20386 have an easy way of getting at the pixel width of the
20387 character to the left of point, so we use a different method
20388 of getting to that place. */
20390 target_x
= pt_x
+ pixel_width
;
20392 target_x
= pt_x
- (!FRAME_WINDOW_P (it
.f
)) * pixel_width
;
20394 /* Target X coordinate could be one line above or below the line
20395 of point, in which case we need to adjust the target X
20396 coordinate. Also, if moving to the left, we need to begin at
20397 the left edge of the point's screen line. */
20402 start_display (&it
, w
, pt
);
20403 reseat_at_previous_visible_line_start (&it
);
20404 it
.current_x
= it
.current_y
= it
.hpos
= 0;
20406 move_it_by_lines (&it
, pt_vpos
);
20410 move_it_by_lines (&it
, -1);
20411 target_x
= it
.last_visible_x
- !FRAME_WINDOW_P (it
.f
);
20412 target_is_eol_p
= true;
20418 || (target_x
>= it
.last_visible_x
20419 && it
.line_wrap
!= TRUNCATE
))
20422 move_it_by_lines (&it
, 0);
20423 move_it_by_lines (&it
, 1);
20428 /* Move to the target X coordinate. */
20429 #ifdef HAVE_WINDOW_SYSTEM
20430 /* On GUI frames, as we don't know the X coordinate of the
20431 character to the left of point, moving point to the left
20432 requires walking, one grapheme cluster at a time, until we
20433 find ourself at a place immediately to the left of the
20434 character at point. */
20435 if (FRAME_WINDOW_P (it
.f
) && dir
< 0)
20437 struct text_pos new_pos
= it
.current
.pos
;
20438 enum move_it_result rc
= MOVE_X_REACHED
;
20440 while (it
.current_x
+ it
.pixel_width
<= target_x
20441 && rc
== MOVE_X_REACHED
)
20443 int new_x
= it
.current_x
+ it
.pixel_width
;
20445 new_pos
= it
.current
.pos
;
20446 if (new_x
== it
.current_x
)
20448 rc
= move_it_in_display_line_to (&it
, ZV
, new_x
,
20449 MOVE_TO_POS
| MOVE_TO_X
);
20450 if (ITERATOR_AT_END_OF_LINE_P (&it
) && !target_is_eol_p
)
20453 /* If we ended up on a composed character inside
20454 bidi-reordered text (e.g., Hebrew text with diacritics),
20455 the iterator gives us the buffer position of the last (in
20456 logical order) character of the composed grapheme cluster,
20457 which is not what we want. So we cheat: we compute the
20458 character position of the character that follows (in the
20459 logical order) the one where the above loop stopped. That
20460 character will appear on display to the left of point. */
20462 && it
.bidi_it
.scan_dir
== -1
20463 && new_pos
.charpos
- IT_CHARPOS (it
) > 1)
20465 new_pos
.charpos
= IT_CHARPOS (it
) + 1;
20466 new_pos
.bytepos
= CHAR_TO_BYTE (new_pos
.charpos
);
20468 it
.current
.pos
= new_pos
;
20472 if (it
.current_x
!= target_x
)
20473 move_it_in_display_line_to (&it
, ZV
, target_x
, MOVE_TO_POS
| MOVE_TO_X
);
20475 /* When lines are truncated, the above loop will stop at the
20476 window edge. But we want to get to the end of line, even if
20477 it is beyond the window edge; automatic hscroll will then
20478 scroll the window to show point as appropriate. */
20479 if (target_is_eol_p
&& it
.line_wrap
== TRUNCATE
20480 && get_next_display_element (&it
))
20482 struct text_pos new_pos
= it
.current
.pos
;
20484 while (!ITERATOR_AT_END_OF_LINE_P (&it
))
20486 set_iterator_to_next (&it
, 0);
20487 if (it
.method
== GET_FROM_BUFFER
)
20488 new_pos
= it
.current
.pos
;
20489 if (!get_next_display_element (&it
))
20493 it
.current
.pos
= new_pos
;
20496 /* If we ended up in a display string that covers point, move to
20497 buffer position to the right in the visual order. */
20500 while (IT_CHARPOS (it
) == PT
)
20502 set_iterator_to_next (&it
, 0);
20503 if (!get_next_display_element (&it
))
20508 /* Move point to that position. */
20509 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
20512 return make_number (PT
);
20514 #undef ROW_GLYPH_NEWLINE_P
20518 /***********************************************************************
20520 ***********************************************************************/
20522 /* Redisplay the menu bar in the frame for window W.
20524 The menu bar of X frames that don't have X toolkit support is
20525 displayed in a special window W->frame->menu_bar_window.
20527 The menu bar of terminal frames is treated specially as far as
20528 glyph matrices are concerned. Menu bar lines are not part of
20529 windows, so the update is done directly on the frame matrix rows
20530 for the menu bar. */
20533 display_menu_bar (struct window
*w
)
20535 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
20540 /* Don't do all this for graphical frames. */
20542 if (FRAME_W32_P (f
))
20545 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20551 if (FRAME_NS_P (f
))
20553 #endif /* HAVE_NS */
20555 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
20556 eassert (!FRAME_WINDOW_P (f
));
20557 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
, MENU_FACE_ID
);
20558 it
.first_visible_x
= 0;
20559 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20560 #elif defined (HAVE_X_WINDOWS) /* X without toolkit. */
20561 if (FRAME_WINDOW_P (f
))
20563 /* Menu bar lines are displayed in the desired matrix of the
20564 dummy window menu_bar_window. */
20565 struct window
*menu_w
;
20566 menu_w
= XWINDOW (f
->menu_bar_window
);
20567 init_iterator (&it
, menu_w
, -1, -1, menu_w
->desired_matrix
->rows
,
20569 it
.first_visible_x
= 0;
20570 it
.last_visible_x
= FRAME_TOTAL_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
20573 #endif /* not USE_X_TOOLKIT and not USE_GTK */
20575 /* This is a TTY frame, i.e. character hpos/vpos are used as
20577 init_iterator (&it
, w
, -1, -1, f
->desired_matrix
->rows
,
20579 it
.first_visible_x
= 0;
20580 it
.last_visible_x
= FRAME_COLS (f
);
20583 /* FIXME: This should be controlled by a user option. See the
20584 comments in redisplay_tool_bar and display_mode_line about
20586 it
.paragraph_embedding
= L2R
;
20588 /* Clear all rows of the menu bar. */
20589 for (i
= 0; i
< FRAME_MENU_BAR_LINES (f
); ++i
)
20591 struct glyph_row
*row
= it
.glyph_row
+ i
;
20592 clear_glyph_row (row
);
20593 row
->enabled_p
= 1;
20594 row
->full_width_p
= 1;
20597 /* Display all items of the menu bar. */
20598 items
= FRAME_MENU_BAR_ITEMS (it
.f
);
20599 for (i
= 0; i
< ASIZE (items
); i
+= 4)
20601 Lisp_Object string
;
20603 /* Stop at nil string. */
20604 string
= AREF (items
, i
+ 1);
20608 /* Remember where item was displayed. */
20609 ASET (items
, i
+ 3, make_number (it
.hpos
));
20611 /* Display the item, pad with one space. */
20612 if (it
.current_x
< it
.last_visible_x
)
20613 display_string (NULL
, string
, Qnil
, 0, 0, &it
,
20614 SCHARS (string
) + 1, 0, 0, -1);
20617 /* Fill out the line with spaces. */
20618 if (it
.current_x
< it
.last_visible_x
)
20619 display_string ("", Qnil
, Qnil
, 0, 0, &it
, -1, 0, 0, -1);
20621 /* Compute the total height of the lines. */
20622 compute_line_metrics (&it
);
20627 /***********************************************************************
20629 ***********************************************************************/
20631 /* Redisplay mode lines in the window tree whose root is WINDOW. If
20632 FORCE is non-zero, redisplay mode lines unconditionally.
20633 Otherwise, redisplay only mode lines that are garbaged. Value is
20634 the number of windows whose mode lines were redisplayed. */
20637 redisplay_mode_lines (Lisp_Object window
, int force
)
20641 while (!NILP (window
))
20643 struct window
*w
= XWINDOW (window
);
20645 if (WINDOWP (w
->contents
))
20646 nwindows
+= redisplay_mode_lines (w
->contents
, force
);
20648 || FRAME_GARBAGED_P (XFRAME (w
->frame
))
20649 || !MATRIX_MODE_LINE_ROW (w
->current_matrix
)->enabled_p
)
20651 struct text_pos lpoint
;
20652 struct buffer
*old
= current_buffer
;
20654 /* Set the window's buffer for the mode line display. */
20655 SET_TEXT_POS (lpoint
, PT
, PT_BYTE
);
20656 set_buffer_internal_1 (XBUFFER (w
->contents
));
20658 /* Point refers normally to the selected window. For any
20659 other window, set up appropriate value. */
20660 if (!EQ (window
, selected_window
))
20662 struct text_pos pt
;
20664 SET_TEXT_POS_FROM_MARKER (pt
, w
->pointm
);
20665 if (CHARPOS (pt
) < BEGV
)
20666 TEMP_SET_PT_BOTH (BEGV
, BEGV_BYTE
);
20667 else if (CHARPOS (pt
) > (ZV
- 1))
20668 TEMP_SET_PT_BOTH (ZV
, ZV_BYTE
);
20670 TEMP_SET_PT_BOTH (CHARPOS (pt
), BYTEPOS (pt
));
20673 /* Display mode lines. */
20674 clear_glyph_matrix (w
->desired_matrix
);
20675 if (display_mode_lines (w
))
20678 w
->must_be_updated_p
= 1;
20681 /* Restore old settings. */
20682 set_buffer_internal_1 (old
);
20683 TEMP_SET_PT_BOTH (CHARPOS (lpoint
), BYTEPOS (lpoint
));
20693 /* Display the mode and/or header line of window W. Value is the
20694 sum number of mode lines and header lines displayed. */
20697 display_mode_lines (struct window
*w
)
20699 Lisp_Object old_selected_window
= selected_window
;
20700 Lisp_Object old_selected_frame
= selected_frame
;
20701 Lisp_Object new_frame
= w
->frame
;
20702 Lisp_Object old_frame_selected_window
= XFRAME (new_frame
)->selected_window
;
20705 selected_frame
= new_frame
;
20706 /* FIXME: If we were to allow the mode-line's computation changing the buffer
20707 or window's point, then we'd need select_window_1 here as well. */
20708 XSETWINDOW (selected_window
, w
);
20709 XFRAME (new_frame
)->selected_window
= selected_window
;
20711 /* These will be set while the mode line specs are processed. */
20712 line_number_displayed
= 0;
20713 w
->column_number_displayed
= -1;
20715 if (WINDOW_WANTS_MODELINE_P (w
))
20717 struct window
*sel_w
= XWINDOW (old_selected_window
);
20719 /* Select mode line face based on the real selected window. */
20720 display_mode_line (w
, CURRENT_MODE_LINE_FACE_ID_3 (sel_w
, sel_w
, w
),
20721 BVAR (current_buffer
, mode_line_format
));
20725 if (WINDOW_WANTS_HEADER_LINE_P (w
))
20727 display_mode_line (w
, HEADER_LINE_FACE_ID
,
20728 BVAR (current_buffer
, header_line_format
));
20732 XFRAME (new_frame
)->selected_window
= old_frame_selected_window
;
20733 selected_frame
= old_selected_frame
;
20734 selected_window
= old_selected_window
;
20739 /* Display mode or header line of window W. FACE_ID specifies which
20740 line to display; it is either MODE_LINE_FACE_ID or
20741 HEADER_LINE_FACE_ID. FORMAT is the mode/header line format to
20742 display. Value is the pixel height of the mode/header line
20746 display_mode_line (struct window
*w
, enum face_id face_id
, Lisp_Object format
)
20750 ptrdiff_t count
= SPECPDL_INDEX ();
20752 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
20753 /* Don't extend on a previously drawn mode-line.
20754 This may happen if called from pos_visible_p. */
20755 it
.glyph_row
->enabled_p
= 0;
20756 prepare_desired_row (it
.glyph_row
);
20758 it
.glyph_row
->mode_line_p
= 1;
20760 /* FIXME: This should be controlled by a user option. But
20761 supporting such an option is not trivial, since the mode line is
20762 made up of many separate strings. */
20763 it
.paragraph_embedding
= L2R
;
20765 record_unwind_protect (unwind_format_mode_line
,
20766 format_mode_line_unwind_data (NULL
, NULL
, Qnil
, 0));
20768 mode_line_target
= MODE_LINE_DISPLAY
;
20770 /* Temporarily make frame's keyboard the current kboard so that
20771 kboard-local variables in the mode_line_format will get the right
20773 push_kboard (FRAME_KBOARD (it
.f
));
20774 record_unwind_save_match_data ();
20775 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
20778 unbind_to (count
, Qnil
);
20780 /* Fill up with spaces. */
20781 display_string (" ", Qnil
, Qnil
, 0, 0, &it
, 10000, -1, -1, 0);
20783 compute_line_metrics (&it
);
20784 it
.glyph_row
->full_width_p
= 1;
20785 it
.glyph_row
->continued_p
= 0;
20786 it
.glyph_row
->truncated_on_left_p
= 0;
20787 it
.glyph_row
->truncated_on_right_p
= 0;
20789 /* Make a 3D mode-line have a shadow at its right end. */
20790 face
= FACE_FROM_ID (it
.f
, face_id
);
20791 extend_face_to_end_of_line (&it
);
20792 if (face
->box
!= FACE_NO_BOX
)
20794 struct glyph
*last
= (it
.glyph_row
->glyphs
[TEXT_AREA
]
20795 + it
.glyph_row
->used
[TEXT_AREA
] - 1);
20796 last
->right_box_line_p
= 1;
20799 return it
.glyph_row
->height
;
20802 /* Move element ELT in LIST to the front of LIST.
20803 Return the updated list. */
20806 move_elt_to_front (Lisp_Object elt
, Lisp_Object list
)
20808 register Lisp_Object tail
, prev
;
20809 register Lisp_Object tem
;
20813 while (CONSP (tail
))
20819 /* Splice out the link TAIL. */
20821 list
= XCDR (tail
);
20823 Fsetcdr (prev
, XCDR (tail
));
20825 /* Now make it the first. */
20826 Fsetcdr (tail
, list
);
20831 tail
= XCDR (tail
);
20835 /* Not found--return unchanged LIST. */
20839 /* Contribute ELT to the mode line for window IT->w. How it
20840 translates into text depends on its data type.
20842 IT describes the display environment in which we display, as usual.
20844 DEPTH is the depth in recursion. It is used to prevent
20845 infinite recursion here.
20847 FIELD_WIDTH is the number of characters the display of ELT should
20848 occupy in the mode line, and PRECISION is the maximum number of
20849 characters to display from ELT's representation. See
20850 display_string for details.
20852 Returns the hpos of the end of the text generated by ELT.
20854 PROPS is a property list to add to any string we encounter.
20856 If RISKY is nonzero, remove (disregard) any properties in any string
20857 we encounter, and ignore :eval and :propertize.
20859 The global variable `mode_line_target' determines whether the
20860 output is passed to `store_mode_line_noprop',
20861 `store_mode_line_string', or `display_string'. */
20864 display_mode_element (struct it
*it
, int depth
, int field_width
, int precision
,
20865 Lisp_Object elt
, Lisp_Object props
, int risky
)
20867 int n
= 0, field
, prec
;
20872 elt
= build_string ("*too-deep*");
20876 switch (XTYPE (elt
))
20880 /* A string: output it and check for %-constructs within it. */
20882 ptrdiff_t offset
= 0;
20884 if (SCHARS (elt
) > 0
20885 && (!NILP (props
) || risky
))
20887 Lisp_Object oprops
, aelt
;
20888 oprops
= Ftext_properties_at (make_number (0), elt
);
20890 /* If the starting string's properties are not what
20891 we want, translate the string. Also, if the string
20892 is risky, do that anyway. */
20894 if (NILP (Fequal (props
, oprops
)) || risky
)
20896 /* If the starting string has properties,
20897 merge the specified ones onto the existing ones. */
20898 if (! NILP (oprops
) && !risky
)
20902 oprops
= Fcopy_sequence (oprops
);
20904 while (CONSP (tem
))
20906 oprops
= Fplist_put (oprops
, XCAR (tem
),
20907 XCAR (XCDR (tem
)));
20908 tem
= XCDR (XCDR (tem
));
20913 aelt
= Fassoc (elt
, mode_line_proptrans_alist
);
20914 if (! NILP (aelt
) && !NILP (Fequal (props
, XCDR (aelt
))))
20916 /* AELT is what we want. Move it to the front
20917 without consing. */
20919 mode_line_proptrans_alist
20920 = move_elt_to_front (aelt
, mode_line_proptrans_alist
);
20926 /* If AELT has the wrong props, it is useless.
20927 so get rid of it. */
20929 mode_line_proptrans_alist
20930 = Fdelq (aelt
, mode_line_proptrans_alist
);
20932 elt
= Fcopy_sequence (elt
);
20933 Fset_text_properties (make_number (0), Flength (elt
),
20935 /* Add this item to mode_line_proptrans_alist. */
20936 mode_line_proptrans_alist
20937 = Fcons (Fcons (elt
, props
),
20938 mode_line_proptrans_alist
);
20939 /* Truncate mode_line_proptrans_alist
20940 to at most 50 elements. */
20941 tem
= Fnthcdr (make_number (50),
20942 mode_line_proptrans_alist
);
20944 XSETCDR (tem
, Qnil
);
20953 prec
= precision
- n
;
20954 switch (mode_line_target
)
20956 case MODE_LINE_NOPROP
:
20957 case MODE_LINE_TITLE
:
20958 n
+= store_mode_line_noprop (SSDATA (elt
), -1, prec
);
20960 case MODE_LINE_STRING
:
20961 n
+= store_mode_line_string (NULL
, elt
, 1, 0, prec
, Qnil
);
20963 case MODE_LINE_DISPLAY
:
20964 n
+= display_string (NULL
, elt
, Qnil
, 0, 0, it
,
20965 0, prec
, 0, STRING_MULTIBYTE (elt
));
20972 /* Handle the non-literal case. */
20974 while ((precision
<= 0 || n
< precision
)
20975 && SREF (elt
, offset
) != 0
20976 && (mode_line_target
!= MODE_LINE_DISPLAY
20977 || it
->current_x
< it
->last_visible_x
))
20979 ptrdiff_t last_offset
= offset
;
20981 /* Advance to end of string or next format specifier. */
20982 while ((c
= SREF (elt
, offset
++)) != '\0' && c
!= '%')
20985 if (offset
- 1 != last_offset
)
20987 ptrdiff_t nchars
, nbytes
;
20989 /* Output to end of string or up to '%'. Field width
20990 is length of string. Don't output more than
20991 PRECISION allows us. */
20994 prec
= c_string_width (SDATA (elt
) + last_offset
,
20995 offset
- last_offset
, precision
- n
,
20998 switch (mode_line_target
)
21000 case MODE_LINE_NOPROP
:
21001 case MODE_LINE_TITLE
:
21002 n
+= store_mode_line_noprop (SSDATA (elt
) + last_offset
, 0, prec
);
21004 case MODE_LINE_STRING
:
21006 ptrdiff_t bytepos
= last_offset
;
21007 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21008 ptrdiff_t endpos
= (precision
<= 0
21009 ? string_byte_to_char (elt
, offset
)
21010 : charpos
+ nchars
);
21012 n
+= store_mode_line_string (NULL
,
21013 Fsubstring (elt
, make_number (charpos
),
21014 make_number (endpos
)),
21018 case MODE_LINE_DISPLAY
:
21020 ptrdiff_t bytepos
= last_offset
;
21021 ptrdiff_t charpos
= string_byte_to_char (elt
, bytepos
);
21023 if (precision
<= 0)
21024 nchars
= string_byte_to_char (elt
, offset
) - charpos
;
21025 n
+= display_string (NULL
, elt
, Qnil
, 0, charpos
,
21027 STRING_MULTIBYTE (elt
));
21032 else /* c == '%' */
21034 ptrdiff_t percent_position
= offset
;
21036 /* Get the specified minimum width. Zero means
21039 while ((c
= SREF (elt
, offset
++)) >= '0' && c
<= '9')
21040 field
= field
* 10 + c
- '0';
21042 /* Don't pad beyond the total padding allowed. */
21043 if (field_width
- n
> 0 && field
> field_width
- n
)
21044 field
= field_width
- n
;
21046 /* Note that either PRECISION <= 0 or N < PRECISION. */
21047 prec
= precision
- n
;
21050 n
+= display_mode_element (it
, depth
, field
, prec
,
21051 Vglobal_mode_string
, props
,
21056 ptrdiff_t bytepos
, charpos
;
21058 Lisp_Object string
;
21060 bytepos
= percent_position
;
21061 charpos
= (STRING_MULTIBYTE (elt
)
21062 ? string_byte_to_char (elt
, bytepos
)
21064 spec
= decode_mode_spec (it
->w
, c
, field
, &string
);
21065 multibyte
= STRINGP (string
) && STRING_MULTIBYTE (string
);
21067 switch (mode_line_target
)
21069 case MODE_LINE_NOPROP
:
21070 case MODE_LINE_TITLE
:
21071 n
+= store_mode_line_noprop (spec
, field
, prec
);
21073 case MODE_LINE_STRING
:
21075 Lisp_Object tem
= build_string (spec
);
21076 props
= Ftext_properties_at (make_number (charpos
), elt
);
21077 /* Should only keep face property in props */
21078 n
+= store_mode_line_string (NULL
, tem
, 0, field
, prec
, props
);
21081 case MODE_LINE_DISPLAY
:
21083 int nglyphs_before
, nwritten
;
21085 nglyphs_before
= it
->glyph_row
->used
[TEXT_AREA
];
21086 nwritten
= display_string (spec
, string
, elt
,
21091 /* Assign to the glyphs written above the
21092 string where the `%x' came from, position
21096 struct glyph
*glyph
21097 = (it
->glyph_row
->glyphs
[TEXT_AREA
]
21101 for (i
= 0; i
< nwritten
; ++i
)
21103 glyph
[i
].object
= elt
;
21104 glyph
[i
].charpos
= charpos
;
21121 /* A symbol: process the value of the symbol recursively
21122 as if it appeared here directly. Avoid error if symbol void.
21123 Special case: if value of symbol is a string, output the string
21126 register Lisp_Object tem
;
21128 /* If the variable is not marked as risky to set
21129 then its contents are risky to use. */
21130 if (NILP (Fget (elt
, Qrisky_local_variable
)))
21133 tem
= Fboundp (elt
);
21136 tem
= Fsymbol_value (elt
);
21137 /* If value is a string, output that string literally:
21138 don't check for % within it. */
21142 if (!EQ (tem
, elt
))
21144 /* Give up right away for nil or t. */
21154 register Lisp_Object car
, tem
;
21156 /* A cons cell: five distinct cases.
21157 If first element is :eval or :propertize, do something special.
21158 If first element is a string or a cons, process all the elements
21159 and effectively concatenate them.
21160 If first element is a negative number, truncate displaying cdr to
21161 at most that many characters. If positive, pad (with spaces)
21162 to at least that many characters.
21163 If first element is a symbol, process the cadr or caddr recursively
21164 according to whether the symbol's value is non-nil or nil. */
21166 if (EQ (car
, QCeval
))
21168 /* An element of the form (:eval FORM) means evaluate FORM
21169 and use the result as mode line elements. */
21174 if (CONSP (XCDR (elt
)))
21177 spec
= safe_eval (XCAR (XCDR (elt
)));
21178 n
+= display_mode_element (it
, depth
, field_width
- n
,
21179 precision
- n
, spec
, props
,
21183 else if (EQ (car
, QCpropertize
))
21185 /* An element of the form (:propertize ELT PROPS...)
21186 means display ELT but applying properties PROPS. */
21191 if (CONSP (XCDR (elt
)))
21192 n
+= display_mode_element (it
, depth
, field_width
- n
,
21193 precision
- n
, XCAR (XCDR (elt
)),
21194 XCDR (XCDR (elt
)), risky
);
21196 else if (SYMBOLP (car
))
21198 tem
= Fboundp (car
);
21202 /* elt is now the cdr, and we know it is a cons cell.
21203 Use its car if CAR has a non-nil value. */
21206 tem
= Fsymbol_value (car
);
21213 /* Symbol's value is nil (or symbol is unbound)
21214 Get the cddr of the original list
21215 and if possible find the caddr and use that. */
21219 else if (!CONSP (elt
))
21224 else if (INTEGERP (car
))
21226 register int lim
= XINT (car
);
21230 /* Negative int means reduce maximum width. */
21231 if (precision
<= 0)
21234 precision
= min (precision
, -lim
);
21238 /* Padding specified. Don't let it be more than
21239 current maximum. */
21241 lim
= min (precision
, lim
);
21243 /* If that's more padding than already wanted, queue it.
21244 But don't reduce padding already specified even if
21245 that is beyond the current truncation point. */
21246 field_width
= max (lim
, field_width
);
21250 else if (STRINGP (car
) || CONSP (car
))
21252 Lisp_Object halftail
= elt
;
21256 && (precision
<= 0 || n
< precision
))
21258 n
+= display_mode_element (it
, depth
,
21259 /* Do padding only after the last
21260 element in the list. */
21261 (! CONSP (XCDR (elt
))
21264 precision
- n
, XCAR (elt
),
21268 if ((len
& 1) == 0)
21269 halftail
= XCDR (halftail
);
21270 /* Check for cycle. */
21271 if (EQ (halftail
, elt
))
21280 elt
= build_string ("*invalid*");
21284 /* Pad to FIELD_WIDTH. */
21285 if (field_width
> 0 && n
< field_width
)
21287 switch (mode_line_target
)
21289 case MODE_LINE_NOPROP
:
21290 case MODE_LINE_TITLE
:
21291 n
+= store_mode_line_noprop ("", field_width
- n
, 0);
21293 case MODE_LINE_STRING
:
21294 n
+= store_mode_line_string ("", Qnil
, 0, field_width
- n
, 0, Qnil
);
21296 case MODE_LINE_DISPLAY
:
21297 n
+= display_string ("", Qnil
, Qnil
, 0, 0, it
, field_width
- n
,
21306 /* Store a mode-line string element in mode_line_string_list.
21308 If STRING is non-null, display that C string. Otherwise, the Lisp
21309 string LISP_STRING is displayed.
21311 FIELD_WIDTH is the minimum number of output glyphs to produce.
21312 If STRING has fewer characters than FIELD_WIDTH, pad to the right
21313 with spaces. FIELD_WIDTH <= 0 means don't pad.
21315 PRECISION is the maximum number of characters to output from
21316 STRING. PRECISION <= 0 means don't truncate the string.
21318 If COPY_STRING is non-zero, make a copy of LISP_STRING before adding
21319 properties to the string.
21321 PROPS are the properties to add to the string.
21322 The mode_line_string_face face property is always added to the string.
21326 store_mode_line_string (const char *string
, Lisp_Object lisp_string
, int copy_string
,
21327 int field_width
, int precision
, Lisp_Object props
)
21332 if (string
!= NULL
)
21334 len
= strlen (string
);
21335 if (precision
> 0 && len
> precision
)
21337 lisp_string
= make_string (string
, len
);
21339 props
= mode_line_string_face_prop
;
21340 else if (!NILP (mode_line_string_face
))
21342 Lisp_Object face
= Fplist_get (props
, Qface
);
21343 props
= Fcopy_sequence (props
);
21345 face
= mode_line_string_face
;
21347 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
21348 props
= Fplist_put (props
, Qface
, face
);
21350 Fadd_text_properties (make_number (0), make_number (len
),
21351 props
, lisp_string
);
21355 len
= XFASTINT (Flength (lisp_string
));
21356 if (precision
> 0 && len
> precision
)
21359 lisp_string
= Fsubstring (lisp_string
, make_number (0), make_number (len
));
21362 if (!NILP (mode_line_string_face
))
21366 props
= Ftext_properties_at (make_number (0), lisp_string
);
21367 face
= Fplist_get (props
, Qface
);
21369 face
= mode_line_string_face
;
21371 face
= Fcons (face
, Fcons (mode_line_string_face
, Qnil
));
21372 props
= Fcons (Qface
, Fcons (face
, Qnil
));
21374 lisp_string
= Fcopy_sequence (lisp_string
);
21377 Fadd_text_properties (make_number (0), make_number (len
),
21378 props
, lisp_string
);
21383 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21387 if (field_width
> len
)
21389 field_width
-= len
;
21390 lisp_string
= Fmake_string (make_number (field_width
), make_number (' '));
21392 Fadd_text_properties (make_number (0), make_number (field_width
),
21393 props
, lisp_string
);
21394 mode_line_string_list
= Fcons (lisp_string
, mode_line_string_list
);
21402 DEFUN ("format-mode-line", Fformat_mode_line
, Sformat_mode_line
,
21404 doc
: /* Format a string out of a mode line format specification.
21405 First arg FORMAT specifies the mode line format (see `mode-line-format'
21406 for details) to use.
21408 By default, the format is evaluated for the currently selected window.
21410 Optional second arg FACE specifies the face property to put on all
21411 characters for which no face is specified. The value nil means the
21412 default face. The value t means whatever face the window's mode line
21413 currently uses (either `mode-line' or `mode-line-inactive',
21414 depending on whether the window is the selected window or not).
21415 An integer value means the value string has no text
21418 Optional third and fourth args WINDOW and BUFFER specify the window
21419 and buffer to use as the context for the formatting (defaults
21420 are the selected window and the WINDOW's buffer). */)
21421 (Lisp_Object format
, Lisp_Object face
,
21422 Lisp_Object window
, Lisp_Object buffer
)
21427 struct buffer
*old_buffer
= NULL
;
21429 int no_props
= INTEGERP (face
);
21430 ptrdiff_t count
= SPECPDL_INDEX ();
21432 int string_start
= 0;
21434 w
= decode_any_window (window
);
21435 XSETWINDOW (window
, w
);
21438 buffer
= w
->contents
;
21439 CHECK_BUFFER (buffer
);
21441 /* Make formatting the modeline a non-op when noninteractive, otherwise
21442 there will be problems later caused by a partially initialized frame. */
21443 if (NILP (format
) || noninteractive
)
21444 return empty_unibyte_string
;
21449 face_id
= (NILP (face
) || EQ (face
, Qdefault
)) ? DEFAULT_FACE_ID
21450 : EQ (face
, Qt
) ? (EQ (window
, selected_window
)
21451 ? MODE_LINE_FACE_ID
: MODE_LINE_INACTIVE_FACE_ID
)
21452 : EQ (face
, Qmode_line
) ? MODE_LINE_FACE_ID
21453 : EQ (face
, Qmode_line_inactive
) ? MODE_LINE_INACTIVE_FACE_ID
21454 : EQ (face
, Qheader_line
) ? HEADER_LINE_FACE_ID
21455 : EQ (face
, Qtool_bar
) ? TOOL_BAR_FACE_ID
21458 old_buffer
= current_buffer
;
21460 /* Save things including mode_line_proptrans_alist,
21461 and set that to nil so that we don't alter the outer value. */
21462 record_unwind_protect (unwind_format_mode_line
,
21463 format_mode_line_unwind_data
21464 (XFRAME (WINDOW_FRAME (w
)),
21465 old_buffer
, selected_window
, 1));
21466 mode_line_proptrans_alist
= Qnil
;
21468 Fselect_window (window
, Qt
);
21469 set_buffer_internal_1 (XBUFFER (buffer
));
21471 init_iterator (&it
, w
, -1, -1, NULL
, face_id
);
21475 mode_line_target
= MODE_LINE_NOPROP
;
21476 mode_line_string_face_prop
= Qnil
;
21477 mode_line_string_list
= Qnil
;
21478 string_start
= MODE_LINE_NOPROP_LEN (0);
21482 mode_line_target
= MODE_LINE_STRING
;
21483 mode_line_string_list
= Qnil
;
21484 mode_line_string_face
= face
;
21485 mode_line_string_face_prop
21486 = (NILP (face
) ? Qnil
: Fcons (Qface
, Fcons (face
, Qnil
)));
21489 push_kboard (FRAME_KBOARD (it
.f
));
21490 display_mode_element (&it
, 0, 0, 0, format
, Qnil
, 0);
21495 len
= MODE_LINE_NOPROP_LEN (string_start
);
21496 str
= make_string (mode_line_noprop_buf
+ string_start
, len
);
21500 mode_line_string_list
= Fnreverse (mode_line_string_list
);
21501 str
= Fmapconcat (intern ("identity"), mode_line_string_list
,
21502 empty_unibyte_string
);
21505 unbind_to (count
, Qnil
);
21509 /* Write a null-terminated, right justified decimal representation of
21510 the positive integer D to BUF using a minimal field width WIDTH. */
21513 pint2str (register char *buf
, register int width
, register ptrdiff_t d
)
21515 register char *p
= buf
;
21523 *p
++ = d
% 10 + '0';
21528 for (width
-= (int) (p
- buf
); width
> 0; --width
)
21539 /* Write a null-terminated, right justified decimal and "human
21540 readable" representation of the nonnegative integer D to BUF using
21541 a minimal field width WIDTH. D should be smaller than 999.5e24. */
21543 static const char power_letter
[] =
21557 pint2hrstr (char *buf
, int width
, ptrdiff_t d
)
21559 /* We aim to represent the nonnegative integer D as
21560 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
21561 ptrdiff_t quotient
= d
;
21563 /* -1 means: do not use TENTHS. */
21567 /* Length of QUOTIENT.TENTHS as a string. */
21573 if (quotient
>= 1000)
21575 /* Scale to the appropriate EXPONENT. */
21578 remainder
= quotient
% 1000;
21582 while (quotient
>= 1000);
21584 /* Round to nearest and decide whether to use TENTHS or not. */
21587 tenths
= remainder
/ 100;
21588 if (remainder
% 100 >= 50)
21595 if (quotient
== 10)
21603 if (remainder
>= 500)
21605 if (quotient
< 999)
21616 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
21617 if (tenths
== -1 && quotient
<= 99)
21624 p
= psuffix
= buf
+ max (width
, length
);
21626 /* Print EXPONENT. */
21627 *psuffix
++ = power_letter
[exponent
];
21630 /* Print TENTHS. */
21633 *--p
= '0' + tenths
;
21637 /* Print QUOTIENT. */
21640 int digit
= quotient
% 10;
21641 *--p
= '0' + digit
;
21643 while ((quotient
/= 10) != 0);
21645 /* Print leading spaces. */
21650 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
21651 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
21652 type of CODING_SYSTEM. Return updated pointer into BUF. */
21654 static unsigned char invalid_eol_type
[] = "(*invalid*)";
21657 decode_mode_spec_coding (Lisp_Object coding_system
, register char *buf
, int eol_flag
)
21660 bool multibyte
= !NILP (BVAR (current_buffer
, enable_multibyte_characters
));
21661 const unsigned char *eol_str
;
21663 /* The EOL conversion we are using. */
21664 Lisp_Object eoltype
;
21666 val
= CODING_SYSTEM_SPEC (coding_system
);
21669 if (!VECTORP (val
)) /* Not yet decided. */
21671 *buf
++ = multibyte
? '-' : ' ';
21673 eoltype
= eol_mnemonic_undecided
;
21674 /* Don't mention EOL conversion if it isn't decided. */
21679 Lisp_Object eolvalue
;
21681 attrs
= AREF (val
, 0);
21682 eolvalue
= AREF (val
, 2);
21685 ? XFASTINT (CODING_ATTR_MNEMONIC (attrs
))
21690 /* The EOL conversion that is normal on this system. */
21692 if (NILP (eolvalue
)) /* Not yet decided. */
21693 eoltype
= eol_mnemonic_undecided
;
21694 else if (VECTORP (eolvalue
)) /* Not yet decided. */
21695 eoltype
= eol_mnemonic_undecided
;
21696 else /* eolvalue is Qunix, Qdos, or Qmac. */
21697 eoltype
= (EQ (eolvalue
, Qunix
)
21698 ? eol_mnemonic_unix
21699 : (EQ (eolvalue
, Qdos
) == 1
21700 ? eol_mnemonic_dos
: eol_mnemonic_mac
));
21706 /* Mention the EOL conversion if it is not the usual one. */
21707 if (STRINGP (eoltype
))
21709 eol_str
= SDATA (eoltype
);
21710 eol_str_len
= SBYTES (eoltype
);
21712 else if (CHARACTERP (eoltype
))
21714 unsigned char *tmp
= alloca (MAX_MULTIBYTE_LENGTH
);
21715 int c
= XFASTINT (eoltype
);
21716 eol_str_len
= CHAR_STRING (c
, tmp
);
21721 eol_str
= invalid_eol_type
;
21722 eol_str_len
= sizeof (invalid_eol_type
) - 1;
21724 memcpy (buf
, eol_str
, eol_str_len
);
21725 buf
+= eol_str_len
;
21731 /* Return a string for the output of a mode line %-spec for window W,
21732 generated by character C. FIELD_WIDTH > 0 means pad the string
21733 returned with spaces to that value. Return a Lisp string in
21734 *STRING if the resulting string is taken from that Lisp string.
21736 Note we operate on the current buffer for most purposes. */
21738 static char lots_of_dashes
[] = "--------------------------------------------------------------------------------------------------------------------------------------------";
21740 static const char *
21741 decode_mode_spec (struct window
*w
, register int c
, int field_width
,
21742 Lisp_Object
*string
)
21745 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
21746 char *decode_mode_spec_buf
= f
->decode_mode_spec_buffer
;
21747 /* We are going to use f->decode_mode_spec_buffer as the buffer to
21748 produce strings from numerical values, so limit preposterously
21749 large values of FIELD_WIDTH to avoid overrunning the buffer's
21750 end. The size of the buffer is enough for FRAME_MESSAGE_BUF_SIZE
21751 bytes plus the terminating null. */
21752 int width
= min (field_width
, FRAME_MESSAGE_BUF_SIZE (f
));
21753 struct buffer
*b
= current_buffer
;
21761 if (!NILP (BVAR (b
, read_only
)))
21763 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21768 /* This differs from %* only for a modified read-only buffer. */
21769 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21771 if (!NILP (BVAR (b
, read_only
)))
21776 /* This differs from %* in ignoring read-only-ness. */
21777 if (BUF_MODIFF (b
) > BUF_SAVE_MODIFF (b
))
21789 if (command_loop_level
> 5)
21791 p
= decode_mode_spec_buf
;
21792 for (i
= 0; i
< command_loop_level
; i
++)
21795 return decode_mode_spec_buf
;
21803 if (command_loop_level
> 5)
21805 p
= decode_mode_spec_buf
;
21806 for (i
= 0; i
< command_loop_level
; i
++)
21809 return decode_mode_spec_buf
;
21816 /* Let lots_of_dashes be a string of infinite length. */
21817 if (mode_line_target
== MODE_LINE_NOPROP
21818 || mode_line_target
== MODE_LINE_STRING
)
21820 if (field_width
<= 0
21821 || field_width
> sizeof (lots_of_dashes
))
21823 for (i
= 0; i
< FRAME_MESSAGE_BUF_SIZE (f
) - 1; ++i
)
21824 decode_mode_spec_buf
[i
] = '-';
21825 decode_mode_spec_buf
[i
] = '\0';
21826 return decode_mode_spec_buf
;
21829 return lots_of_dashes
;
21833 obj
= BVAR (b
, name
);
21837 /* %c and %l are ignored in `frame-title-format'.
21838 (In redisplay_internal, the frame title is drawn _before_ the
21839 windows are updated, so the stuff which depends on actual
21840 window contents (such as %l) may fail to render properly, or
21841 even crash emacs.) */
21842 if (mode_line_target
== MODE_LINE_TITLE
)
21846 ptrdiff_t col
= current_column ();
21847 w
->column_number_displayed
= col
;
21848 pint2str (decode_mode_spec_buf
, width
, col
);
21849 return decode_mode_spec_buf
;
21853 #ifndef SYSTEM_MALLOC
21855 if (NILP (Vmemory_full
))
21858 return "!MEM FULL! ";
21865 /* %F displays the frame name. */
21866 if (!NILP (f
->title
))
21867 return SSDATA (f
->title
);
21868 if (f
->explicit_name
|| ! FRAME_WINDOW_P (f
))
21869 return SSDATA (f
->name
);
21873 obj
= BVAR (b
, filename
);
21878 ptrdiff_t size
= ZV
- BEGV
;
21879 pint2str (decode_mode_spec_buf
, width
, size
);
21880 return decode_mode_spec_buf
;
21885 ptrdiff_t size
= ZV
- BEGV
;
21886 pint2hrstr (decode_mode_spec_buf
, width
, size
);
21887 return decode_mode_spec_buf
;
21892 ptrdiff_t startpos
, startpos_byte
, line
, linepos
, linepos_byte
;
21893 ptrdiff_t topline
, nlines
, height
;
21896 /* %c and %l are ignored in `frame-title-format'. */
21897 if (mode_line_target
== MODE_LINE_TITLE
)
21900 startpos
= marker_position (w
->start
);
21901 startpos_byte
= marker_byte_position (w
->start
);
21902 height
= WINDOW_TOTAL_LINES (w
);
21904 /* If we decided that this buffer isn't suitable for line numbers,
21905 don't forget that too fast. */
21906 if (w
->base_line_pos
== -1)
21909 /* If the buffer is very big, don't waste time. */
21910 if (INTEGERP (Vline_number_display_limit
)
21911 && BUF_ZV (b
) - BUF_BEGV (b
) > XINT (Vline_number_display_limit
))
21913 w
->base_line_pos
= 0;
21914 w
->base_line_number
= 0;
21918 if (w
->base_line_number
> 0
21919 && w
->base_line_pos
> 0
21920 && w
->base_line_pos
<= startpos
)
21922 line
= w
->base_line_number
;
21923 linepos
= w
->base_line_pos
;
21924 linepos_byte
= buf_charpos_to_bytepos (b
, linepos
);
21929 linepos
= BUF_BEGV (b
);
21930 linepos_byte
= BUF_BEGV_BYTE (b
);
21933 /* Count lines from base line to window start position. */
21934 nlines
= display_count_lines (linepos_byte
,
21938 topline
= nlines
+ line
;
21940 /* Determine a new base line, if the old one is too close
21941 or too far away, or if we did not have one.
21942 "Too close" means it's plausible a scroll-down would
21943 go back past it. */
21944 if (startpos
== BUF_BEGV (b
))
21946 w
->base_line_number
= topline
;
21947 w
->base_line_pos
= BUF_BEGV (b
);
21949 else if (nlines
< height
+ 25 || nlines
> height
* 3 + 50
21950 || linepos
== BUF_BEGV (b
))
21952 ptrdiff_t limit
= BUF_BEGV (b
);
21953 ptrdiff_t limit_byte
= BUF_BEGV_BYTE (b
);
21954 ptrdiff_t position
;
21955 ptrdiff_t distance
=
21956 (height
* 2 + 30) * line_number_display_limit_width
;
21958 if (startpos
- distance
> limit
)
21960 limit
= startpos
- distance
;
21961 limit_byte
= CHAR_TO_BYTE (limit
);
21964 nlines
= display_count_lines (startpos_byte
,
21966 - (height
* 2 + 30),
21968 /* If we couldn't find the lines we wanted within
21969 line_number_display_limit_width chars per line,
21970 give up on line numbers for this window. */
21971 if (position
== limit_byte
&& limit
== startpos
- distance
)
21973 w
->base_line_pos
= -1;
21974 w
->base_line_number
= 0;
21978 w
->base_line_number
= topline
- nlines
;
21979 w
->base_line_pos
= BYTE_TO_CHAR (position
);
21982 /* Now count lines from the start pos to point. */
21983 nlines
= display_count_lines (startpos_byte
,
21984 PT_BYTE
, PT
, &junk
);
21986 /* Record that we did display the line number. */
21987 line_number_displayed
= 1;
21989 /* Make the string to show. */
21990 pint2str (decode_mode_spec_buf
, width
, topline
+ nlines
);
21991 return decode_mode_spec_buf
;
21994 char* p
= decode_mode_spec_buf
;
21995 int pad
= width
- 2;
22001 return decode_mode_spec_buf
;
22007 obj
= BVAR (b
, mode_name
);
22011 if (BUF_BEGV (b
) > BUF_BEG (b
) || BUF_ZV (b
) < BUF_Z (b
))
22017 ptrdiff_t pos
= marker_position (w
->start
);
22018 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22020 if (XFASTINT (w
->window_end_pos
) <= BUF_Z (b
) - BUF_ZV (b
))
22022 if (pos
<= BUF_BEGV (b
))
22027 else if (pos
<= BUF_BEGV (b
))
22031 if (total
> 1000000)
22032 /* Do it differently for a large value, to avoid overflow. */
22033 total
= ((pos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22035 total
= ((pos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22036 /* We can't normally display a 3-digit number,
22037 so get us a 2-digit number that is close. */
22040 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22041 return decode_mode_spec_buf
;
22045 /* Display percentage of size above the bottom of the screen. */
22048 ptrdiff_t toppos
= marker_position (w
->start
);
22049 ptrdiff_t botpos
= BUF_Z (b
) - XFASTINT (w
->window_end_pos
);
22050 ptrdiff_t total
= BUF_ZV (b
) - BUF_BEGV (b
);
22052 if (botpos
>= BUF_ZV (b
))
22054 if (toppos
<= BUF_BEGV (b
))
22061 if (total
> 1000000)
22062 /* Do it differently for a large value, to avoid overflow. */
22063 total
= ((botpos
- BUF_BEGV (b
)) + (total
/ 100) - 1) / (total
/ 100);
22065 total
= ((botpos
- BUF_BEGV (b
)) * 100 + total
- 1) / total
;
22066 /* We can't normally display a 3-digit number,
22067 so get us a 2-digit number that is close. */
22070 if (toppos
<= BUF_BEGV (b
))
22071 sprintf (decode_mode_spec_buf
, "Top%2"pD
"d%%", total
);
22073 sprintf (decode_mode_spec_buf
, "%2"pD
"d%%", total
);
22074 return decode_mode_spec_buf
;
22079 /* status of process */
22080 obj
= Fget_buffer_process (Fcurrent_buffer ());
22082 return "no process";
22084 obj
= Fsymbol_name (Fprocess_status (obj
));
22090 ptrdiff_t count
= inhibit_garbage_collection ();
22091 Lisp_Object val
= call1 (intern ("file-remote-p"),
22092 BVAR (current_buffer
, directory
));
22093 unbind_to (count
, Qnil
);
22102 /* coding-system (not including end-of-line format) */
22104 /* coding-system (including end-of-line type) */
22106 int eol_flag
= (c
== 'Z');
22107 char *p
= decode_mode_spec_buf
;
22109 if (! FRAME_WINDOW_P (f
))
22111 /* No need to mention EOL here--the terminal never needs
22112 to do EOL conversion. */
22113 p
= decode_mode_spec_coding (CODING_ID_NAME
22114 (FRAME_KEYBOARD_CODING (f
)->id
),
22116 p
= decode_mode_spec_coding (CODING_ID_NAME
22117 (FRAME_TERMINAL_CODING (f
)->id
),
22120 p
= decode_mode_spec_coding (BVAR (b
, buffer_file_coding_system
),
22123 #if 0 /* This proves to be annoying; I think we can do without. -- rms. */
22124 #ifdef subprocesses
22125 obj
= Fget_buffer_process (Fcurrent_buffer ());
22126 if (PROCESSP (obj
))
22128 p
= decode_mode_spec_coding
22129 (XPROCESS (obj
)->decode_coding_system
, p
, eol_flag
);
22130 p
= decode_mode_spec_coding
22131 (XPROCESS (obj
)->encode_coding_system
, p
, eol_flag
);
22133 #endif /* subprocesses */
22136 return decode_mode_spec_buf
;
22143 return SSDATA (obj
);
22150 /* Count up to COUNT lines starting from START_BYTE. COUNT negative
22151 means count lines back from START_BYTE. But don't go beyond
22152 LIMIT_BYTE. Return the number of lines thus found (always
22155 Set *BYTE_POS_PTR to the byte position where we stopped. This is
22156 either the position COUNT lines after/before START_BYTE, if we
22157 found COUNT lines, or LIMIT_BYTE if we hit the limit before finding
22161 display_count_lines (ptrdiff_t start_byte
,
22162 ptrdiff_t limit_byte
, ptrdiff_t count
,
22163 ptrdiff_t *byte_pos_ptr
)
22165 register unsigned char *cursor
;
22166 unsigned char *base
;
22168 register ptrdiff_t ceiling
;
22169 register unsigned char *ceiling_addr
;
22170 ptrdiff_t orig_count
= count
;
22172 /* If we are not in selective display mode,
22173 check only for newlines. */
22174 int selective_display
= (!NILP (BVAR (current_buffer
, selective_display
))
22175 && !INTEGERP (BVAR (current_buffer
, selective_display
)));
22179 while (start_byte
< limit_byte
)
22181 ceiling
= BUFFER_CEILING_OF (start_byte
);
22182 ceiling
= min (limit_byte
- 1, ceiling
);
22183 ceiling_addr
= BYTE_POS_ADDR (ceiling
) + 1;
22184 base
= (cursor
= BYTE_POS_ADDR (start_byte
));
22188 if (selective_display
)
22190 while (*cursor
!= '\n' && *cursor
!= 015
22191 && ++cursor
!= ceiling_addr
)
22193 if (cursor
== ceiling_addr
)
22198 cursor
= memchr (cursor
, '\n', ceiling_addr
- cursor
);
22207 start_byte
+= cursor
- base
;
22208 *byte_pos_ptr
= start_byte
;
22212 while (cursor
< ceiling_addr
);
22214 start_byte
+= ceiling_addr
- base
;
22219 while (start_byte
> limit_byte
)
22221 ceiling
= BUFFER_FLOOR_OF (start_byte
- 1);
22222 ceiling
= max (limit_byte
, ceiling
);
22223 ceiling_addr
= BYTE_POS_ADDR (ceiling
);
22224 base
= (cursor
= BYTE_POS_ADDR (start_byte
- 1) + 1);
22227 if (selective_display
)
22229 while (--cursor
>= ceiling_addr
22230 && *cursor
!= '\n' && *cursor
!= 015)
22232 if (cursor
< ceiling_addr
)
22237 cursor
= memrchr (ceiling_addr
, '\n', cursor
- ceiling_addr
);
22244 start_byte
+= cursor
- base
+ 1;
22245 *byte_pos_ptr
= start_byte
;
22246 /* When scanning backwards, we should
22247 not count the newline posterior to which we stop. */
22248 return - orig_count
- 1;
22251 start_byte
+= ceiling_addr
- base
;
22255 *byte_pos_ptr
= limit_byte
;
22258 return - orig_count
+ count
;
22259 return orig_count
- count
;
22265 /***********************************************************************
22267 ***********************************************************************/
22269 /* Display a NUL-terminated string, starting with index START.
22271 If STRING is non-null, display that C string. Otherwise, the Lisp
22272 string LISP_STRING is displayed. There's a case that STRING is
22273 non-null and LISP_STRING is not nil. It means STRING is a string
22274 data of LISP_STRING. In that case, we display LISP_STRING while
22275 ignoring its text properties.
22277 If FACE_STRING is not nil, FACE_STRING_POS is a position in
22278 FACE_STRING. Display STRING or LISP_STRING with the face at
22279 FACE_STRING_POS in FACE_STRING:
22281 Display the string in the environment given by IT, but use the
22282 standard display table, temporarily.
22284 FIELD_WIDTH is the minimum number of output glyphs to produce.
22285 If STRING has fewer characters than FIELD_WIDTH, pad to the right
22286 with spaces. If STRING has more characters, more than FIELD_WIDTH
22287 glyphs will be produced. FIELD_WIDTH <= 0 means don't pad.
22289 PRECISION is the maximum number of characters to output from
22290 STRING. PRECISION < 0 means don't truncate the string.
22292 This is roughly equivalent to printf format specifiers:
22294 FIELD_WIDTH PRECISION PRINTF
22295 ----------------------------------------
22301 MULTIBYTE zero means do not display multibyte chars, > 0 means do
22302 display them, and < 0 means obey the current buffer's value of
22303 enable_multibyte_characters.
22305 Value is the number of columns displayed. */
22308 display_string (const char *string
, Lisp_Object lisp_string
, Lisp_Object face_string
,
22309 ptrdiff_t face_string_pos
, ptrdiff_t start
, struct it
*it
,
22310 int field_width
, int precision
, int max_x
, int multibyte
)
22312 int hpos_at_start
= it
->hpos
;
22313 int saved_face_id
= it
->face_id
;
22314 struct glyph_row
*row
= it
->glyph_row
;
22315 ptrdiff_t it_charpos
;
22317 /* Initialize the iterator IT for iteration over STRING beginning
22318 with index START. */
22319 reseat_to_string (it
, NILP (lisp_string
) ? string
: NULL
, lisp_string
, start
,
22320 precision
, field_width
, multibyte
);
22321 if (string
&& STRINGP (lisp_string
))
22322 /* LISP_STRING is the one returned by decode_mode_spec. We should
22323 ignore its text properties. */
22324 it
->stop_charpos
= it
->end_charpos
;
22326 /* If displaying STRING, set up the face of the iterator from
22327 FACE_STRING, if that's given. */
22328 if (STRINGP (face_string
))
22334 = face_at_string_position (it
->w
, face_string
, face_string_pos
,
22335 0, it
->region_beg_charpos
,
22336 it
->region_end_charpos
,
22337 &endptr
, it
->base_face_id
, 0);
22338 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
22339 it
->face_box_p
= face
->box
!= FACE_NO_BOX
;
22342 /* Set max_x to the maximum allowed X position. Don't let it go
22343 beyond the right edge of the window. */
22345 max_x
= it
->last_visible_x
;
22347 max_x
= min (max_x
, it
->last_visible_x
);
22349 /* Skip over display elements that are not visible. because IT->w is
22351 if (it
->current_x
< it
->first_visible_x
)
22352 move_it_in_display_line_to (it
, 100000, it
->first_visible_x
,
22353 MOVE_TO_POS
| MOVE_TO_X
);
22355 row
->ascent
= it
->max_ascent
;
22356 row
->height
= it
->max_ascent
+ it
->max_descent
;
22357 row
->phys_ascent
= it
->max_phys_ascent
;
22358 row
->phys_height
= it
->max_phys_ascent
+ it
->max_phys_descent
;
22359 row
->extra_line_spacing
= it
->max_extra_line_spacing
;
22361 if (STRINGP (it
->string
))
22362 it_charpos
= IT_STRING_CHARPOS (*it
);
22364 it_charpos
= IT_CHARPOS (*it
);
22366 /* This condition is for the case that we are called with current_x
22367 past last_visible_x. */
22368 while (it
->current_x
< max_x
)
22370 int x_before
, x
, n_glyphs_before
, i
, nglyphs
;
22372 /* Get the next display element. */
22373 if (!get_next_display_element (it
))
22376 /* Produce glyphs. */
22377 x_before
= it
->current_x
;
22378 n_glyphs_before
= row
->used
[TEXT_AREA
];
22379 PRODUCE_GLYPHS (it
);
22381 nglyphs
= row
->used
[TEXT_AREA
] - n_glyphs_before
;
22384 while (i
< nglyphs
)
22386 struct glyph
*glyph
= row
->glyphs
[TEXT_AREA
] + n_glyphs_before
+ i
;
22388 if (it
->line_wrap
!= TRUNCATE
22389 && x
+ glyph
->pixel_width
> max_x
)
22391 /* End of continued line or max_x reached. */
22392 if (CHAR_GLYPH_PADDING_P (*glyph
))
22394 /* A wide character is unbreakable. */
22395 if (row
->reversed_p
)
22396 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22397 - n_glyphs_before
);
22398 row
->used
[TEXT_AREA
] = n_glyphs_before
;
22399 it
->current_x
= x_before
;
22403 if (row
->reversed_p
)
22404 unproduce_glyphs (it
, row
->used
[TEXT_AREA
]
22405 - (n_glyphs_before
+ i
));
22406 row
->used
[TEXT_AREA
] = n_glyphs_before
+ i
;
22411 else if (x
+ glyph
->pixel_width
>= it
->first_visible_x
)
22413 /* Glyph is at least partially visible. */
22415 if (x
< it
->first_visible_x
)
22416 row
->x
= x
- it
->first_visible_x
;
22420 /* Glyph is off the left margin of the display area.
22421 Should not happen. */
22425 row
->ascent
= max (row
->ascent
, it
->max_ascent
);
22426 row
->height
= max (row
->height
, it
->max_ascent
+ it
->max_descent
);
22427 row
->phys_ascent
= max (row
->phys_ascent
, it
->max_phys_ascent
);
22428 row
->phys_height
= max (row
->phys_height
,
22429 it
->max_phys_ascent
+ it
->max_phys_descent
);
22430 row
->extra_line_spacing
= max (row
->extra_line_spacing
,
22431 it
->max_extra_line_spacing
);
22432 x
+= glyph
->pixel_width
;
22436 /* Stop if max_x reached. */
22440 /* Stop at line ends. */
22441 if (ITERATOR_AT_END_OF_LINE_P (it
))
22443 it
->continuation_lines_width
= 0;
22447 set_iterator_to_next (it
, 1);
22448 if (STRINGP (it
->string
))
22449 it_charpos
= IT_STRING_CHARPOS (*it
);
22451 it_charpos
= IT_CHARPOS (*it
);
22453 /* Stop if truncating at the right edge. */
22454 if (it
->line_wrap
== TRUNCATE
22455 && it
->current_x
>= it
->last_visible_x
)
22457 /* Add truncation mark, but don't do it if the line is
22458 truncated at a padding space. */
22459 if (it_charpos
< it
->string_nchars
)
22461 if (!FRAME_WINDOW_P (it
->f
))
22465 if (it
->current_x
> it
->last_visible_x
)
22467 if (!row
->reversed_p
)
22469 for (ii
= row
->used
[TEXT_AREA
] - 1; ii
> 0; --ii
)
22470 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22475 for (ii
= 0; ii
< row
->used
[TEXT_AREA
]; ii
++)
22476 if (!CHAR_GLYPH_PADDING_P (row
->glyphs
[TEXT_AREA
][ii
]))
22478 unproduce_glyphs (it
, ii
+ 1);
22479 ii
= row
->used
[TEXT_AREA
] - (ii
+ 1);
22481 for (n
= row
->used
[TEXT_AREA
]; ii
< n
; ++ii
)
22483 row
->used
[TEXT_AREA
] = ii
;
22484 produce_special_glyphs (it
, IT_TRUNCATION
);
22487 produce_special_glyphs (it
, IT_TRUNCATION
);
22489 row
->truncated_on_right_p
= 1;
22495 /* Maybe insert a truncation at the left. */
22496 if (it
->first_visible_x
22499 if (!FRAME_WINDOW_P (it
->f
)
22500 || (row
->reversed_p
22501 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22502 : WINDOW_LEFT_FRINGE_WIDTH (it
->w
)) == 0)
22503 insert_left_trunc_glyphs (it
);
22504 row
->truncated_on_left_p
= 1;
22507 it
->face_id
= saved_face_id
;
22509 /* Value is number of columns displayed. */
22510 return it
->hpos
- hpos_at_start
;
22515 /* This is like a combination of memq and assq. Return 1/2 if PROPVAL
22516 appears as an element of LIST or as the car of an element of LIST.
22517 If PROPVAL is a list, compare each element against LIST in that
22518 way, and return 1/2 if any element of PROPVAL is found in LIST.
22519 Otherwise return 0. This function cannot quit.
22520 The return value is 2 if the text is invisible but with an ellipsis
22521 and 1 if it's invisible and without an ellipsis. */
22524 invisible_p (register Lisp_Object propval
, Lisp_Object list
)
22526 register Lisp_Object tail
, proptail
;
22528 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22530 register Lisp_Object tem
;
22532 if (EQ (propval
, tem
))
22534 if (CONSP (tem
) && EQ (propval
, XCAR (tem
)))
22535 return NILP (XCDR (tem
)) ? 1 : 2;
22538 if (CONSP (propval
))
22540 for (proptail
= propval
; CONSP (proptail
); proptail
= XCDR (proptail
))
22542 Lisp_Object propelt
;
22543 propelt
= XCAR (proptail
);
22544 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
22546 register Lisp_Object tem
;
22548 if (EQ (propelt
, tem
))
22550 if (CONSP (tem
) && EQ (propelt
, XCAR (tem
)))
22551 return NILP (XCDR (tem
)) ? 1 : 2;
22559 DEFUN ("invisible-p", Finvisible_p
, Sinvisible_p
, 1, 1, 0,
22560 doc
: /* Non-nil if the property makes the text invisible.
22561 POS-OR-PROP can be a marker or number, in which case it is taken to be
22562 a position in the current buffer and the value of the `invisible' property
22563 is checked; or it can be some other value, which is then presumed to be the
22564 value of the `invisible' property of the text of interest.
22565 The non-nil value returned can be t for truly invisible text or something
22566 else if the text is replaced by an ellipsis. */)
22567 (Lisp_Object pos_or_prop
)
22570 = (NATNUMP (pos_or_prop
) || MARKERP (pos_or_prop
)
22571 ? Fget_char_property (pos_or_prop
, Qinvisible
, Qnil
)
22573 int invis
= TEXT_PROP_MEANS_INVISIBLE (prop
);
22574 return (invis
== 0 ? Qnil
22576 : make_number (invis
));
22579 /* Calculate a width or height in pixels from a specification using
22580 the following elements:
22583 NUM - a (fractional) multiple of the default font width/height
22584 (NUM) - specifies exactly NUM pixels
22585 UNIT - a fixed number of pixels, see below.
22586 ELEMENT - size of a display element in pixels, see below.
22587 (NUM . SPEC) - equals NUM * SPEC
22588 (+ SPEC SPEC ...) - add pixel values
22589 (- SPEC SPEC ...) - subtract pixel values
22590 (- SPEC) - negate pixel value
22593 INT or FLOAT - a number constant
22594 SYMBOL - use symbol's (buffer local) variable binding.
22597 in - pixels per inch *)
22598 mm - pixels per 1/1000 meter *)
22599 cm - pixels per 1/100 meter *)
22600 width - width of current font in pixels.
22601 height - height of current font in pixels.
22603 *) using the ratio(s) defined in display-pixels-per-inch.
22607 left-fringe - left fringe width in pixels
22608 right-fringe - right fringe width in pixels
22610 left-margin - left margin width in pixels
22611 right-margin - right margin width in pixels
22613 scroll-bar - scroll-bar area width in pixels
22617 Pixels corresponding to 5 inches:
22620 Total width of non-text areas on left side of window (if scroll-bar is on left):
22621 '(space :width (+ left-fringe left-margin scroll-bar))
22623 Align to first text column (in header line):
22624 '(space :align-to 0)
22626 Align to middle of text area minus half the width of variable `my-image'
22627 containing a loaded image:
22628 '(space :align-to (0.5 . (- text my-image)))
22630 Width of left margin minus width of 1 character in the default font:
22631 '(space :width (- left-margin 1))
22633 Width of left margin minus width of 2 characters in the current font:
22634 '(space :width (- left-margin (2 . width)))
22636 Center 1 character over left-margin (in header line):
22637 '(space :align-to (+ left-margin (0.5 . left-margin) -0.5))
22639 Different ways to express width of left fringe plus left margin minus one pixel:
22640 '(space :width (- (+ left-fringe left-margin) (1)))
22641 '(space :width (+ left-fringe left-margin (- (1))))
22642 '(space :width (+ left-fringe left-margin (-1)))
22647 calc_pixel_width_or_height (double *res
, struct it
*it
, Lisp_Object prop
,
22648 struct font
*font
, int width_p
, int *align_to
)
22652 #define OK_PIXELS(val) ((*res = (double)(val)), 1)
22653 #define OK_ALIGN_TO(val) ((*align_to = (int)(val)), 1)
22656 return OK_PIXELS (0);
22658 eassert (FRAME_LIVE_P (it
->f
));
22660 if (SYMBOLP (prop
))
22662 if (SCHARS (SYMBOL_NAME (prop
)) == 2)
22664 char *unit
= SSDATA (SYMBOL_NAME (prop
));
22666 if (unit
[0] == 'i' && unit
[1] == 'n')
22668 else if (unit
[0] == 'm' && unit
[1] == 'm')
22670 else if (unit
[0] == 'c' && unit
[1] == 'm')
22676 double ppi
= (width_p
? FRAME_RES_X (it
->f
)
22677 : FRAME_RES_Y (it
->f
));
22680 return OK_PIXELS (ppi
/ pixels
);
22685 #ifdef HAVE_WINDOW_SYSTEM
22686 if (EQ (prop
, Qheight
))
22687 return OK_PIXELS (font
? FONT_HEIGHT (font
) : FRAME_LINE_HEIGHT (it
->f
));
22688 if (EQ (prop
, Qwidth
))
22689 return OK_PIXELS (font
? FONT_WIDTH (font
) : FRAME_COLUMN_WIDTH (it
->f
));
22691 if (EQ (prop
, Qheight
) || EQ (prop
, Qwidth
))
22692 return OK_PIXELS (1);
22695 if (EQ (prop
, Qtext
))
22696 return OK_PIXELS (width_p
22697 ? window_box_width (it
->w
, TEXT_AREA
)
22698 : WINDOW_BOX_HEIGHT_NO_MODE_LINE (it
->w
));
22700 if (align_to
&& *align_to
< 0)
22703 if (EQ (prop
, Qleft
))
22704 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
));
22705 if (EQ (prop
, Qright
))
22706 return OK_ALIGN_TO (window_box_right_offset (it
->w
, TEXT_AREA
));
22707 if (EQ (prop
, Qcenter
))
22708 return OK_ALIGN_TO (window_box_left_offset (it
->w
, TEXT_AREA
)
22709 + window_box_width (it
->w
, TEXT_AREA
) / 2);
22710 if (EQ (prop
, Qleft_fringe
))
22711 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22712 ? WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (it
->w
)
22713 : window_box_right_offset (it
->w
, LEFT_MARGIN_AREA
));
22714 if (EQ (prop
, Qright_fringe
))
22715 return OK_ALIGN_TO (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22716 ? window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22717 : window_box_right_offset (it
->w
, TEXT_AREA
));
22718 if (EQ (prop
, Qleft_margin
))
22719 return OK_ALIGN_TO (window_box_left_offset (it
->w
, LEFT_MARGIN_AREA
));
22720 if (EQ (prop
, Qright_margin
))
22721 return OK_ALIGN_TO (window_box_left_offset (it
->w
, RIGHT_MARGIN_AREA
));
22722 if (EQ (prop
, Qscroll_bar
))
22723 return OK_ALIGN_TO (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (it
->w
)
22725 : (window_box_right_offset (it
->w
, RIGHT_MARGIN_AREA
)
22726 + (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (it
->w
)
22727 ? WINDOW_RIGHT_FRINGE_WIDTH (it
->w
)
22732 if (EQ (prop
, Qleft_fringe
))
22733 return OK_PIXELS (WINDOW_LEFT_FRINGE_WIDTH (it
->w
));
22734 if (EQ (prop
, Qright_fringe
))
22735 return OK_PIXELS (WINDOW_RIGHT_FRINGE_WIDTH (it
->w
));
22736 if (EQ (prop
, Qleft_margin
))
22737 return OK_PIXELS (WINDOW_LEFT_MARGIN_WIDTH (it
->w
));
22738 if (EQ (prop
, Qright_margin
))
22739 return OK_PIXELS (WINDOW_RIGHT_MARGIN_WIDTH (it
->w
));
22740 if (EQ (prop
, Qscroll_bar
))
22741 return OK_PIXELS (WINDOW_SCROLL_BAR_AREA_WIDTH (it
->w
));
22744 prop
= buffer_local_value_1 (prop
, it
->w
->contents
);
22745 if (EQ (prop
, Qunbound
))
22749 if (INTEGERP (prop
) || FLOATP (prop
))
22751 int base_unit
= (width_p
22752 ? FRAME_COLUMN_WIDTH (it
->f
)
22753 : FRAME_LINE_HEIGHT (it
->f
));
22754 return OK_PIXELS (XFLOATINT (prop
) * base_unit
);
22759 Lisp_Object car
= XCAR (prop
);
22760 Lisp_Object cdr
= XCDR (prop
);
22764 #ifdef HAVE_WINDOW_SYSTEM
22765 if (FRAME_WINDOW_P (it
->f
)
22766 && valid_image_p (prop
))
22768 ptrdiff_t id
= lookup_image (it
->f
, prop
);
22769 struct image
*img
= IMAGE_FROM_ID (it
->f
, id
);
22771 return OK_PIXELS (width_p
? img
->width
: img
->height
);
22774 if (EQ (car
, Qplus
) || EQ (car
, Qminus
))
22780 while (CONSP (cdr
))
22782 if (!calc_pixel_width_or_height (&px
, it
, XCAR (cdr
),
22783 font
, width_p
, align_to
))
22786 pixels
= (EQ (car
, Qplus
) ? px
: -px
), first
= 0;
22791 if (EQ (car
, Qminus
))
22793 return OK_PIXELS (pixels
);
22796 car
= buffer_local_value_1 (car
, it
->w
->contents
);
22797 if (EQ (car
, Qunbound
))
22801 if (INTEGERP (car
) || FLOATP (car
))
22804 pixels
= XFLOATINT (car
);
22806 return OK_PIXELS (pixels
);
22807 if (calc_pixel_width_or_height (&fact
, it
, cdr
,
22808 font
, width_p
, align_to
))
22809 return OK_PIXELS (pixels
* fact
);
22820 /***********************************************************************
22822 ***********************************************************************/
22824 #ifdef HAVE_WINDOW_SYSTEM
22829 dump_glyph_string (struct glyph_string
*s
)
22831 fprintf (stderr
, "glyph string\n");
22832 fprintf (stderr
, " x, y, w, h = %d, %d, %d, %d\n",
22833 s
->x
, s
->y
, s
->width
, s
->height
);
22834 fprintf (stderr
, " ybase = %d\n", s
->ybase
);
22835 fprintf (stderr
, " hl = %d\n", s
->hl
);
22836 fprintf (stderr
, " left overhang = %d, right = %d\n",
22837 s
->left_overhang
, s
->right_overhang
);
22838 fprintf (stderr
, " nchars = %d\n", s
->nchars
);
22839 fprintf (stderr
, " extends to end of line = %d\n",
22840 s
->extends_to_end_of_line_p
);
22841 fprintf (stderr
, " font height = %d\n", FONT_HEIGHT (s
->font
));
22842 fprintf (stderr
, " bg width = %d\n", s
->background_width
);
22845 #endif /* GLYPH_DEBUG */
22847 /* Initialize glyph string S. CHAR2B is a suitably allocated vector
22848 of XChar2b structures for S; it can't be allocated in
22849 init_glyph_string because it must be allocated via `alloca'. W
22850 is the window on which S is drawn. ROW and AREA are the glyph row
22851 and area within the row from which S is constructed. START is the
22852 index of the first glyph structure covered by S. HL is a
22853 face-override for drawing S. */
22856 #define OPTIONAL_HDC(hdc) HDC hdc,
22857 #define DECLARE_HDC(hdc) HDC hdc;
22858 #define ALLOCATE_HDC(hdc, f) hdc = get_frame_dc ((f))
22859 #define RELEASE_HDC(hdc, f) release_frame_dc ((f), (hdc))
22862 #ifndef OPTIONAL_HDC
22863 #define OPTIONAL_HDC(hdc)
22864 #define DECLARE_HDC(hdc)
22865 #define ALLOCATE_HDC(hdc, f)
22866 #define RELEASE_HDC(hdc, f)
22870 init_glyph_string (struct glyph_string
*s
,
22872 XChar2b
*char2b
, struct window
*w
, struct glyph_row
*row
,
22873 enum glyph_row_area area
, int start
, enum draw_glyphs_face hl
)
22875 memset (s
, 0, sizeof *s
);
22877 s
->f
= XFRAME (w
->frame
);
22881 s
->display
= FRAME_X_DISPLAY (s
->f
);
22882 s
->window
= FRAME_X_WINDOW (s
->f
);
22883 s
->char2b
= char2b
;
22887 s
->first_glyph
= row
->glyphs
[area
] + start
;
22888 s
->height
= row
->height
;
22889 s
->y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
22890 s
->ybase
= s
->y
+ row
->ascent
;
22894 /* Append the list of glyph strings with head H and tail T to the list
22895 with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the result. */
22898 append_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22899 struct glyph_string
*h
, struct glyph_string
*t
)
22913 /* Prepend the list of glyph strings with head H and tail T to the
22914 list with head *HEAD and tail *TAIL. Set *HEAD and *TAIL to the
22918 prepend_glyph_string_lists (struct glyph_string
**head
, struct glyph_string
**tail
,
22919 struct glyph_string
*h
, struct glyph_string
*t
)
22933 /* Append glyph string S to the list with head *HEAD and tail *TAIL.
22934 Set *HEAD and *TAIL to the resulting list. */
22937 append_glyph_string (struct glyph_string
**head
, struct glyph_string
**tail
,
22938 struct glyph_string
*s
)
22940 s
->next
= s
->prev
= NULL
;
22941 append_glyph_string_lists (head
, tail
, s
, s
);
22945 /* Get face and two-byte form of character C in face FACE_ID on frame F.
22946 The encoding of C is returned in *CHAR2B. DISPLAY_P non-zero means
22947 make sure that X resources for the face returned are allocated.
22948 Value is a pointer to a realized face that is ready for display if
22949 DISPLAY_P is non-zero. */
22951 static struct face
*
22952 get_char_face_and_encoding (struct frame
*f
, int c
, int face_id
,
22953 XChar2b
*char2b
, int display_p
)
22955 struct face
*face
= FACE_FROM_ID (f
, face_id
);
22960 code
= face
->font
->driver
->encode_char (face
->font
, c
);
22962 if (code
== FONT_INVALID_CODE
)
22965 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
22967 /* Make sure X resources of the face are allocated. */
22968 #ifdef HAVE_X_WINDOWS
22972 eassert (face
!= NULL
);
22973 PREPARE_FACE_FOR_DISPLAY (f
, face
);
22980 /* Get face and two-byte form of character glyph GLYPH on frame F.
22981 The encoding of GLYPH->u.ch is returned in *CHAR2B. Value is
22982 a pointer to a realized face that is ready for display. */
22984 static struct face
*
22985 get_glyph_face_and_encoding (struct frame
*f
, struct glyph
*glyph
,
22986 XChar2b
*char2b
, int *two_byte_p
)
22991 eassert (glyph
->type
== CHAR_GLYPH
);
22992 face
= FACE_FROM_ID (f
, glyph
->face_id
);
22994 /* Make sure X resources of the face are allocated. */
22995 eassert (face
!= NULL
);
22996 PREPARE_FACE_FOR_DISPLAY (f
, face
);
23003 if (CHAR_BYTE8_P (glyph
->u
.ch
))
23004 code
= CHAR_TO_BYTE8 (glyph
->u
.ch
);
23006 code
= face
->font
->driver
->encode_char (face
->font
, glyph
->u
.ch
);
23008 if (code
== FONT_INVALID_CODE
)
23012 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23017 /* Get glyph code of character C in FONT in the two-byte form CHAR2B.
23018 Return 1 if FONT has a glyph for C, otherwise return 0. */
23021 get_char_glyph_code (int c
, struct font
*font
, XChar2b
*char2b
)
23025 if (CHAR_BYTE8_P (c
))
23026 code
= CHAR_TO_BYTE8 (c
);
23028 code
= font
->driver
->encode_char (font
, c
);
23030 if (code
== FONT_INVALID_CODE
)
23032 STORE_XCHAR2B (char2b
, (code
>> 8), (code
& 0xFF));
23037 /* Fill glyph string S with composition components specified by S->cmp.
23039 BASE_FACE is the base face of the composition.
23040 S->cmp_from is the index of the first component for S.
23042 OVERLAPS non-zero means S should draw the foreground only, and use
23043 its physical height for clipping. See also draw_glyphs.
23045 Value is the index of a component not in S. */
23048 fill_composite_glyph_string (struct glyph_string
*s
, struct face
*base_face
,
23052 /* For all glyphs of this composition, starting at the offset
23053 S->cmp_from, until we reach the end of the definition or encounter a
23054 glyph that requires the different face, add it to S. */
23059 s
->for_overlaps
= overlaps
;
23062 for (i
= s
->cmp_from
; i
< s
->cmp
->glyph_len
; i
++)
23064 int c
= COMPOSITION_GLYPH (s
->cmp
, i
);
23066 /* TAB in a composition means display glyphs with padding space
23067 on the left or right. */
23070 int face_id
= FACE_FOR_CHAR (s
->f
, base_face
->ascii_face
, c
,
23073 face
= get_char_face_and_encoding (s
->f
, c
, face_id
,
23080 s
->font
= s
->face
->font
;
23082 else if (s
->face
!= face
)
23090 if (s
->face
== NULL
)
23092 s
->face
= base_face
->ascii_face
;
23093 s
->font
= s
->face
->font
;
23096 /* All glyph strings for the same composition has the same width,
23097 i.e. the width set for the first component of the composition. */
23098 s
->width
= s
->first_glyph
->pixel_width
;
23100 /* If the specified font could not be loaded, use the frame's
23101 default font, but record the fact that we couldn't load it in
23102 the glyph string so that we can draw rectangles for the
23103 characters of the glyph string. */
23104 if (s
->font
== NULL
)
23106 s
->font_not_found_p
= 1;
23107 s
->font
= FRAME_FONT (s
->f
);
23110 /* Adjust base line for subscript/superscript text. */
23111 s
->ybase
+= s
->first_glyph
->voffset
;
23113 /* This glyph string must always be drawn with 16-bit functions. */
23120 fill_gstring_glyph_string (struct glyph_string
*s
, int face_id
,
23121 int start
, int end
, int overlaps
)
23123 struct glyph
*glyph
, *last
;
23124 Lisp_Object lgstring
;
23127 s
->for_overlaps
= overlaps
;
23128 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23129 last
= s
->row
->glyphs
[s
->area
] + end
;
23130 s
->cmp_id
= glyph
->u
.cmp
.id
;
23131 s
->cmp_from
= glyph
->slice
.cmp
.from
;
23132 s
->cmp_to
= glyph
->slice
.cmp
.to
+ 1;
23133 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23134 lgstring
= composition_gstring_from_id (s
->cmp_id
);
23135 s
->font
= XFONT_OBJECT (LGSTRING_FONT (lgstring
));
23137 while (glyph
< last
23138 && glyph
->u
.cmp
.automatic
23139 && glyph
->u
.cmp
.id
== s
->cmp_id
23140 && s
->cmp_to
== glyph
->slice
.cmp
.from
)
23141 s
->cmp_to
= (glyph
++)->slice
.cmp
.to
+ 1;
23143 for (i
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
23145 Lisp_Object lglyph
= LGSTRING_GLYPH (lgstring
, i
);
23146 unsigned code
= LGLYPH_CODE (lglyph
);
23148 STORE_XCHAR2B ((s
->char2b
+ i
), code
>> 8, code
& 0xFF);
23150 s
->width
= composition_gstring_width (lgstring
, s
->cmp_from
, s
->cmp_to
, NULL
);
23151 return glyph
- s
->row
->glyphs
[s
->area
];
23155 /* Fill glyph string S from a sequence glyphs for glyphless characters.
23156 See the comment of fill_glyph_string for arguments.
23157 Value is the index of the first glyph not in S. */
23161 fill_glyphless_glyph_string (struct glyph_string
*s
, int face_id
,
23162 int start
, int end
, int overlaps
)
23164 struct glyph
*glyph
, *last
;
23167 eassert (s
->first_glyph
->type
== GLYPHLESS_GLYPH
);
23168 s
->for_overlaps
= overlaps
;
23169 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23170 last
= s
->row
->glyphs
[s
->area
] + end
;
23171 voffset
= glyph
->voffset
;
23172 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23173 s
->font
= s
->face
->font
? s
->face
->font
: FRAME_FONT (s
->f
);
23175 s
->width
= glyph
->pixel_width
;
23177 while (glyph
< last
23178 && glyph
->type
== GLYPHLESS_GLYPH
23179 && glyph
->voffset
== voffset
23180 && glyph
->face_id
== face_id
)
23183 s
->width
+= glyph
->pixel_width
;
23186 s
->ybase
+= voffset
;
23187 return glyph
- s
->row
->glyphs
[s
->area
];
23191 /* Fill glyph string S from a sequence of character glyphs.
23193 FACE_ID is the face id of the string. START is the index of the
23194 first glyph to consider, END is the index of the last + 1.
23195 OVERLAPS non-zero means S should draw the foreground only, and use
23196 its physical height for clipping. See also draw_glyphs.
23198 Value is the index of the first glyph not in S. */
23201 fill_glyph_string (struct glyph_string
*s
, int face_id
,
23202 int start
, int end
, int overlaps
)
23204 struct glyph
*glyph
, *last
;
23206 int glyph_not_available_p
;
23208 eassert (s
->f
== XFRAME (s
->w
->frame
));
23209 eassert (s
->nchars
== 0);
23210 eassert (start
>= 0 && end
> start
);
23212 s
->for_overlaps
= overlaps
;
23213 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23214 last
= s
->row
->glyphs
[s
->area
] + end
;
23215 voffset
= glyph
->voffset
;
23216 s
->padding_p
= glyph
->padding_p
;
23217 glyph_not_available_p
= glyph
->glyph_not_available_p
;
23219 while (glyph
< last
23220 && glyph
->type
== CHAR_GLYPH
23221 && glyph
->voffset
== voffset
23222 /* Same face id implies same font, nowadays. */
23223 && glyph
->face_id
== face_id
23224 && glyph
->glyph_not_available_p
== glyph_not_available_p
)
23228 s
->face
= get_glyph_face_and_encoding (s
->f
, glyph
,
23229 s
->char2b
+ s
->nchars
,
23231 s
->two_byte_p
= two_byte_p
;
23233 eassert (s
->nchars
<= end
- start
);
23234 s
->width
+= glyph
->pixel_width
;
23235 if (glyph
++->padding_p
!= s
->padding_p
)
23239 s
->font
= s
->face
->font
;
23241 /* If the specified font could not be loaded, use the frame's font,
23242 but record the fact that we couldn't load it in
23243 S->font_not_found_p so that we can draw rectangles for the
23244 characters of the glyph string. */
23245 if (s
->font
== NULL
|| glyph_not_available_p
)
23247 s
->font_not_found_p
= 1;
23248 s
->font
= FRAME_FONT (s
->f
);
23251 /* Adjust base line for subscript/superscript text. */
23252 s
->ybase
+= voffset
;
23254 eassert (s
->face
&& s
->face
->gc
);
23255 return glyph
- s
->row
->glyphs
[s
->area
];
23259 /* Fill glyph string S from image glyph S->first_glyph. */
23262 fill_image_glyph_string (struct glyph_string
*s
)
23264 eassert (s
->first_glyph
->type
== IMAGE_GLYPH
);
23265 s
->img
= IMAGE_FROM_ID (s
->f
, s
->first_glyph
->u
.img_id
);
23267 s
->slice
= s
->first_glyph
->slice
.img
;
23268 s
->face
= FACE_FROM_ID (s
->f
, s
->first_glyph
->face_id
);
23269 s
->font
= s
->face
->font
;
23270 s
->width
= s
->first_glyph
->pixel_width
;
23272 /* Adjust base line for subscript/superscript text. */
23273 s
->ybase
+= s
->first_glyph
->voffset
;
23277 /* Fill glyph string S from a sequence of stretch glyphs.
23279 START is the index of the first glyph to consider,
23280 END is the index of the last + 1.
23282 Value is the index of the first glyph not in S. */
23285 fill_stretch_glyph_string (struct glyph_string
*s
, int start
, int end
)
23287 struct glyph
*glyph
, *last
;
23288 int voffset
, face_id
;
23290 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
23292 glyph
= s
->row
->glyphs
[s
->area
] + start
;
23293 last
= s
->row
->glyphs
[s
->area
] + end
;
23294 face_id
= glyph
->face_id
;
23295 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
23296 s
->font
= s
->face
->font
;
23297 s
->width
= glyph
->pixel_width
;
23299 voffset
= glyph
->voffset
;
23303 && glyph
->type
== STRETCH_GLYPH
23304 && glyph
->voffset
== voffset
23305 && glyph
->face_id
== face_id
);
23307 s
->width
+= glyph
->pixel_width
;
23309 /* Adjust base line for subscript/superscript text. */
23310 s
->ybase
+= voffset
;
23312 /* The case that face->gc == 0 is handled when drawing the glyph
23313 string by calling PREPARE_FACE_FOR_DISPLAY. */
23315 return glyph
- s
->row
->glyphs
[s
->area
];
23318 static struct font_metrics
*
23319 get_per_char_metric (struct font
*font
, XChar2b
*char2b
)
23321 static struct font_metrics metrics
;
23326 code
= (XCHAR2B_BYTE1 (char2b
) << 8) | XCHAR2B_BYTE2 (char2b
);
23327 if (code
== FONT_INVALID_CODE
)
23329 font
->driver
->text_extents (font
, &code
, 1, &metrics
);
23334 Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
23335 frame F. Overhangs of glyphs other than type CHAR_GLYPH are
23336 assumed to be zero. */
23339 x_get_glyph_overhangs (struct glyph
*glyph
, struct frame
*f
, int *left
, int *right
)
23341 *left
= *right
= 0;
23343 if (glyph
->type
== CHAR_GLYPH
)
23347 struct font_metrics
*pcm
;
23349 face
= get_glyph_face_and_encoding (f
, glyph
, &char2b
, NULL
);
23350 if (face
->font
&& (pcm
= get_per_char_metric (face
->font
, &char2b
)))
23352 if (pcm
->rbearing
> pcm
->width
)
23353 *right
= pcm
->rbearing
- pcm
->width
;
23354 if (pcm
->lbearing
< 0)
23355 *left
= -pcm
->lbearing
;
23358 else if (glyph
->type
== COMPOSITE_GLYPH
)
23360 if (! glyph
->u
.cmp
.automatic
)
23362 struct composition
*cmp
= composition_table
[glyph
->u
.cmp
.id
];
23364 if (cmp
->rbearing
> cmp
->pixel_width
)
23365 *right
= cmp
->rbearing
- cmp
->pixel_width
;
23366 if (cmp
->lbearing
< 0)
23367 *left
= - cmp
->lbearing
;
23371 Lisp_Object gstring
= composition_gstring_from_id (glyph
->u
.cmp
.id
);
23372 struct font_metrics metrics
;
23374 composition_gstring_width (gstring
, glyph
->slice
.cmp
.from
,
23375 glyph
->slice
.cmp
.to
+ 1, &metrics
);
23376 if (metrics
.rbearing
> metrics
.width
)
23377 *right
= metrics
.rbearing
- metrics
.width
;
23378 if (metrics
.lbearing
< 0)
23379 *left
= - metrics
.lbearing
;
23385 /* Return the index of the first glyph preceding glyph string S that
23386 is overwritten by S because of S's left overhang. Value is -1
23387 if no glyphs are overwritten. */
23390 left_overwritten (struct glyph_string
*s
)
23394 if (s
->left_overhang
)
23397 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23398 int first
= s
->first_glyph
- glyphs
;
23400 for (i
= first
- 1; i
>= 0 && x
> -s
->left_overhang
; --i
)
23401 x
-= glyphs
[i
].pixel_width
;
23412 /* Return the index of the first glyph preceding glyph string S that
23413 is overwriting S because of its right overhang. Value is -1 if no
23414 glyph in front of S overwrites S. */
23417 left_overwriting (struct glyph_string
*s
)
23420 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23421 int first
= s
->first_glyph
- glyphs
;
23425 for (i
= first
- 1; i
>= 0; --i
)
23428 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23431 x
-= glyphs
[i
].pixel_width
;
23438 /* Return the index of the last glyph following glyph string S that is
23439 overwritten by S because of S's right overhang. Value is -1 if
23440 no such glyph is found. */
23443 right_overwritten (struct glyph_string
*s
)
23447 if (s
->right_overhang
)
23450 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23451 int first
= (s
->first_glyph
- glyphs
23452 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23453 int end
= s
->row
->used
[s
->area
];
23455 for (i
= first
; i
< end
&& s
->right_overhang
> x
; ++i
)
23456 x
+= glyphs
[i
].pixel_width
;
23465 /* Return the index of the last glyph following glyph string S that
23466 overwrites S because of its left overhang. Value is negative
23467 if no such glyph is found. */
23470 right_overwriting (struct glyph_string
*s
)
23473 int end
= s
->row
->used
[s
->area
];
23474 struct glyph
*glyphs
= s
->row
->glyphs
[s
->area
];
23475 int first
= (s
->first_glyph
- glyphs
23476 + (s
->first_glyph
->type
== COMPOSITE_GLYPH
? 1 : s
->nchars
));
23480 for (i
= first
; i
< end
; ++i
)
23483 x_get_glyph_overhangs (glyphs
+ i
, s
->f
, &left
, &right
);
23486 x
+= glyphs
[i
].pixel_width
;
23493 /* Set background width of glyph string S. START is the index of the
23494 first glyph following S. LAST_X is the right-most x-position + 1
23495 in the drawing area. */
23498 set_glyph_string_background_width (struct glyph_string
*s
, int start
, int last_x
)
23500 /* If the face of this glyph string has to be drawn to the end of
23501 the drawing area, set S->extends_to_end_of_line_p. */
23503 if (start
== s
->row
->used
[s
->area
]
23504 && s
->area
== TEXT_AREA
23505 && ((s
->row
->fill_line_p
23506 && (s
->hl
== DRAW_NORMAL_TEXT
23507 || s
->hl
== DRAW_IMAGE_RAISED
23508 || s
->hl
== DRAW_IMAGE_SUNKEN
))
23509 || s
->hl
== DRAW_MOUSE_FACE
))
23510 s
->extends_to_end_of_line_p
= 1;
23512 /* If S extends its face to the end of the line, set its
23513 background_width to the distance to the right edge of the drawing
23515 if (s
->extends_to_end_of_line_p
)
23516 s
->background_width
= last_x
- s
->x
+ 1;
23518 s
->background_width
= s
->width
;
23522 /* Compute overhangs and x-positions for glyph string S and its
23523 predecessors, or successors. X is the starting x-position for S.
23524 BACKWARD_P non-zero means process predecessors. */
23527 compute_overhangs_and_x (struct glyph_string
*s
, int x
, int backward_p
)
23533 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23534 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23544 if (FRAME_RIF (s
->f
)->compute_glyph_string_overhangs
)
23545 FRAME_RIF (s
->f
)->compute_glyph_string_overhangs (s
);
23555 /* The following macros are only called from draw_glyphs below.
23556 They reference the following parameters of that function directly:
23557 `w', `row', `area', and `overlap_p'
23558 as well as the following local variables:
23559 `s', `f', and `hdc' (in W32) */
23562 /* On W32, silently add local `hdc' variable to argument list of
23563 init_glyph_string. */
23564 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23565 init_glyph_string (s, hdc, char2b, w, row, area, start, hl)
23567 #define INIT_GLYPH_STRING(s, char2b, w, row, area, start, hl) \
23568 init_glyph_string (s, char2b, w, row, area, start, hl)
23571 /* Add a glyph string for a stretch glyph to the list of strings
23572 between HEAD and TAIL. START is the index of the stretch glyph in
23573 row area AREA of glyph row ROW. END is the index of the last glyph
23574 in that glyph row area. X is the current output position assigned
23575 to the new glyph string constructed. HL overrides that face of the
23576 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23577 is the right-most x-position of the drawing area. */
23579 /* SunOS 4 bundled cc, barfed on continuations in the arg lists here
23580 and below -- keep them on one line. */
23581 #define BUILD_STRETCH_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23584 s = alloca (sizeof *s); \
23585 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23586 START = fill_stretch_glyph_string (s, START, END); \
23587 append_glyph_string (&HEAD, &TAIL, s); \
23593 /* Add a glyph string for an image glyph to the list of strings
23594 between HEAD and TAIL. START is the index of the image glyph in
23595 row area AREA of glyph row ROW. END is the index of the last glyph
23596 in that glyph row area. X is the current output position assigned
23597 to the new glyph string constructed. HL overrides that face of the
23598 glyph; e.g. it is DRAW_CURSOR if a cursor has to be drawn. LAST_X
23599 is the right-most x-position of the drawing area. */
23601 #define BUILD_IMAGE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23604 s = alloca (sizeof *s); \
23605 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23606 fill_image_glyph_string (s); \
23607 append_glyph_string (&HEAD, &TAIL, s); \
23614 /* Add a glyph string for a sequence of character glyphs to the list
23615 of strings between HEAD and TAIL. START is the index of the first
23616 glyph in row area AREA of glyph row ROW that is part of the new
23617 glyph string. END is the index of the last glyph in that glyph row
23618 area. X is the current output position assigned to the new glyph
23619 string constructed. HL overrides that face of the glyph; e.g. it
23620 is DRAW_CURSOR if a cursor has to be drawn. LAST_X is the
23621 right-most x-position of the drawing area. */
23623 #define BUILD_CHAR_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23629 face_id = (row)->glyphs[area][START].face_id; \
23631 s = alloca (sizeof *s); \
23632 char2b = alloca ((END - START) * sizeof *char2b); \
23633 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23634 append_glyph_string (&HEAD, &TAIL, s); \
23636 START = fill_glyph_string (s, face_id, START, END, overlaps); \
23641 /* Add a glyph string for a composite sequence to the list of strings
23642 between HEAD and TAIL. START is the index of the first glyph in
23643 row area AREA of glyph row ROW that is part of the new glyph
23644 string. END is the index of the last glyph in that glyph row area.
23645 X is the current output position assigned to the new glyph string
23646 constructed. HL overrides that face of the glyph; e.g. it is
23647 DRAW_CURSOR if a cursor has to be drawn. LAST_X is the right-most
23648 x-position of the drawing area. */
23650 #define BUILD_COMPOSITE_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23652 int face_id = (row)->glyphs[area][START].face_id; \
23653 struct face *base_face = FACE_FROM_ID (f, face_id); \
23654 ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id; \
23655 struct composition *cmp = composition_table[cmp_id]; \
23657 struct glyph_string *first_s = NULL; \
23660 char2b = alloca (cmp->glyph_len * sizeof *char2b); \
23662 /* Make glyph_strings for each glyph sequence that is drawable by \
23663 the same face, and append them to HEAD/TAIL. */ \
23664 for (n = 0; n < cmp->glyph_len;) \
23666 s = alloca (sizeof *s); \
23667 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23668 append_glyph_string (&(HEAD), &(TAIL), s); \
23674 n = fill_composite_glyph_string (s, base_face, overlaps); \
23682 /* Add a glyph string for a glyph-string sequence to the list of strings
23683 between HEAD and TAIL. */
23685 #define BUILD_GSTRING_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23689 Lisp_Object gstring; \
23691 face_id = (row)->glyphs[area][START].face_id; \
23692 gstring = (composition_gstring_from_id \
23693 ((row)->glyphs[area][START].u.cmp.id)); \
23694 s = alloca (sizeof *s); \
23695 char2b = alloca (LGSTRING_GLYPH_LEN (gstring) * sizeof *char2b); \
23696 INIT_GLYPH_STRING (s, char2b, w, row, area, START, HL); \
23697 append_glyph_string (&(HEAD), &(TAIL), s); \
23699 START = fill_gstring_glyph_string (s, face_id, START, END, overlaps); \
23703 /* Add a glyph string for a sequence of glyphless character's glyphs
23704 to the list of strings between HEAD and TAIL. The meanings of
23705 arguments are the same as those of BUILD_CHAR_GLYPH_STRINGS. */
23707 #define BUILD_GLYPHLESS_GLYPH_STRING(START, END, HEAD, TAIL, HL, X, LAST_X) \
23712 face_id = (row)->glyphs[area][START].face_id; \
23714 s = alloca (sizeof *s); \
23715 INIT_GLYPH_STRING (s, NULL, w, row, area, START, HL); \
23716 append_glyph_string (&HEAD, &TAIL, s); \
23718 START = fill_glyphless_glyph_string (s, face_id, START, END, \
23724 /* Build a list of glyph strings between HEAD and TAIL for the glyphs
23725 of AREA of glyph row ROW on window W between indices START and END.
23726 HL overrides the face for drawing glyph strings, e.g. it is
23727 DRAW_CURSOR to draw a cursor. X and LAST_X are start and end
23728 x-positions of the drawing area.
23730 This is an ugly monster macro construct because we must use alloca
23731 to allocate glyph strings (because draw_glyphs can be called
23732 asynchronously). */
23734 #define BUILD_GLYPH_STRINGS(START, END, HEAD, TAIL, HL, X, LAST_X) \
23737 HEAD = TAIL = NULL; \
23738 while (START < END) \
23740 struct glyph *first_glyph = (row)->glyphs[area] + START; \
23741 switch (first_glyph->type) \
23744 BUILD_CHAR_GLYPH_STRINGS (START, END, HEAD, TAIL, \
23748 case COMPOSITE_GLYPH: \
23749 if (first_glyph->u.cmp.automatic) \
23750 BUILD_GSTRING_GLYPH_STRING (START, END, HEAD, TAIL, \
23753 BUILD_COMPOSITE_GLYPH_STRING (START, END, HEAD, TAIL, \
23757 case STRETCH_GLYPH: \
23758 BUILD_STRETCH_GLYPH_STRING (START, END, HEAD, TAIL, \
23762 case IMAGE_GLYPH: \
23763 BUILD_IMAGE_GLYPH_STRING (START, END, HEAD, TAIL, \
23767 case GLYPHLESS_GLYPH: \
23768 BUILD_GLYPHLESS_GLYPH_STRING (START, END, HEAD, TAIL, \
23778 set_glyph_string_background_width (s, START, LAST_X); \
23785 /* Draw glyphs between START and END in AREA of ROW on window W,
23786 starting at x-position X. X is relative to AREA in W. HL is a
23787 face-override with the following meaning:
23789 DRAW_NORMAL_TEXT draw normally
23790 DRAW_CURSOR draw in cursor face
23791 DRAW_MOUSE_FACE draw in mouse face.
23792 DRAW_INVERSE_VIDEO draw in mode line face
23793 DRAW_IMAGE_SUNKEN draw an image with a sunken relief around it
23794 DRAW_IMAGE_RAISED draw an image with a raised relief around it
23796 If OVERLAPS is non-zero, draw only the foreground of characters and
23797 clip to the physical height of ROW. Non-zero value also defines
23798 the overlapping part to be drawn:
23800 OVERLAPS_PRED overlap with preceding rows
23801 OVERLAPS_SUCC overlap with succeeding rows
23802 OVERLAPS_BOTH overlap with both preceding/succeeding rows
23803 OVERLAPS_ERASED_CURSOR overlap with erased cursor area
23805 Value is the x-position reached, relative to AREA of W. */
23808 draw_glyphs (struct window
*w
, int x
, struct glyph_row
*row
,
23809 enum glyph_row_area area
, ptrdiff_t start
, ptrdiff_t end
,
23810 enum draw_glyphs_face hl
, int overlaps
)
23812 struct glyph_string
*head
, *tail
;
23813 struct glyph_string
*s
;
23814 struct glyph_string
*clip_head
= NULL
, *clip_tail
= NULL
;
23815 int i
, j
, x_reached
, last_x
, area_left
= 0;
23816 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
23819 ALLOCATE_HDC (hdc
, f
);
23821 /* Let's rather be paranoid than getting a SEGV. */
23822 end
= min (end
, row
->used
[area
]);
23823 start
= clip_to_bounds (0, start
, end
);
23825 /* Translate X to frame coordinates. Set last_x to the right
23826 end of the drawing area. */
23827 if (row
->full_width_p
)
23829 /* X is relative to the left edge of W, without scroll bars
23831 area_left
= WINDOW_LEFT_EDGE_X (w
);
23832 last_x
= WINDOW_LEFT_EDGE_X (w
) + WINDOW_TOTAL_WIDTH (w
);
23836 area_left
= window_box_left (w
, area
);
23837 last_x
= area_left
+ window_box_width (w
, area
);
23841 /* Build a doubly-linked list of glyph_string structures between
23842 head and tail from what we have to draw. Note that the macro
23843 BUILD_GLYPH_STRINGS will modify its start parameter. That's
23844 the reason we use a separate variable `i'. */
23846 BUILD_GLYPH_STRINGS (i
, end
, head
, tail
, hl
, x
, last_x
);
23848 x_reached
= tail
->x
+ tail
->background_width
;
23852 /* If there are any glyphs with lbearing < 0 or rbearing > width in
23853 the row, redraw some glyphs in front or following the glyph
23854 strings built above. */
23855 if (head
&& !overlaps
&& row
->contains_overlapping_glyphs_p
)
23857 struct glyph_string
*h
, *t
;
23858 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
23859 int mouse_beg_col
IF_LINT (= 0), mouse_end_col
IF_LINT (= 0);
23860 int check_mouse_face
= 0;
23863 /* If mouse highlighting is on, we may need to draw adjacent
23864 glyphs using mouse-face highlighting. */
23865 if (area
== TEXT_AREA
&& row
->mouse_face_p
23866 && hlinfo
->mouse_face_beg_row
>= 0
23867 && hlinfo
->mouse_face_end_row
>= 0)
23869 struct glyph_row
*mouse_beg_row
, *mouse_end_row
;
23871 mouse_beg_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
23872 mouse_end_row
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
23874 if (row
>= mouse_beg_row
&& row
<= mouse_end_row
)
23876 check_mouse_face
= 1;
23877 mouse_beg_col
= (row
== mouse_beg_row
)
23878 ? hlinfo
->mouse_face_beg_col
: 0;
23879 mouse_end_col
= (row
== mouse_end_row
)
23880 ? hlinfo
->mouse_face_end_col
23881 : row
->used
[TEXT_AREA
];
23885 /* Compute overhangs for all glyph strings. */
23886 if (FRAME_RIF (f
)->compute_glyph_string_overhangs
)
23887 for (s
= head
; s
; s
= s
->next
)
23888 FRAME_RIF (f
)->compute_glyph_string_overhangs (s
);
23890 /* Prepend glyph strings for glyphs in front of the first glyph
23891 string that are overwritten because of the first glyph
23892 string's left overhang. The background of all strings
23893 prepended must be drawn because the first glyph string
23895 i
= left_overwritten (head
);
23898 enum draw_glyphs_face overlap_hl
;
23900 /* If this row contains mouse highlighting, attempt to draw
23901 the overlapped glyphs with the correct highlight. This
23902 code fails if the overlap encompasses more than one glyph
23903 and mouse-highlight spans only some of these glyphs.
23904 However, making it work perfectly involves a lot more
23905 code, and I don't know if the pathological case occurs in
23906 practice, so we'll stick to this for now. --- cyd */
23907 if (check_mouse_face
23908 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23909 overlap_hl
= DRAW_MOUSE_FACE
;
23911 overlap_hl
= DRAW_NORMAL_TEXT
;
23914 BUILD_GLYPH_STRINGS (j
, start
, h
, t
,
23915 overlap_hl
, dummy_x
, last_x
);
23917 compute_overhangs_and_x (t
, head
->x
, 1);
23918 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23922 /* Prepend glyph strings for glyphs in front of the first glyph
23923 string that overwrite that glyph string because of their
23924 right overhang. For these strings, only the foreground must
23925 be drawn, because it draws over the glyph string at `head'.
23926 The background must not be drawn because this would overwrite
23927 right overhangs of preceding glyphs for which no glyph
23929 i
= left_overwriting (head
);
23932 enum draw_glyphs_face overlap_hl
;
23934 if (check_mouse_face
23935 && mouse_beg_col
< start
&& mouse_end_col
> i
)
23936 overlap_hl
= DRAW_MOUSE_FACE
;
23938 overlap_hl
= DRAW_NORMAL_TEXT
;
23941 BUILD_GLYPH_STRINGS (i
, start
, h
, t
,
23942 overlap_hl
, dummy_x
, last_x
);
23943 for (s
= h
; s
; s
= s
->next
)
23944 s
->background_filled_p
= 1;
23945 compute_overhangs_and_x (t
, head
->x
, 1);
23946 prepend_glyph_string_lists (&head
, &tail
, h
, t
);
23949 /* Append glyphs strings for glyphs following the last glyph
23950 string tail that are overwritten by tail. The background of
23951 these strings has to be drawn because tail's foreground draws
23953 i
= right_overwritten (tail
);
23956 enum draw_glyphs_face overlap_hl
;
23958 if (check_mouse_face
23959 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23960 overlap_hl
= DRAW_MOUSE_FACE
;
23962 overlap_hl
= DRAW_NORMAL_TEXT
;
23964 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23965 overlap_hl
, x
, last_x
);
23966 /* Because BUILD_GLYPH_STRINGS updates the first argument,
23967 we don't have `end = i;' here. */
23968 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23969 append_glyph_string_lists (&head
, &tail
, h
, t
);
23973 /* Append glyph strings for glyphs following the last glyph
23974 string tail that overwrite tail. The foreground of such
23975 glyphs has to be drawn because it writes into the background
23976 of tail. The background must not be drawn because it could
23977 paint over the foreground of following glyphs. */
23978 i
= right_overwriting (tail
);
23981 enum draw_glyphs_face overlap_hl
;
23982 if (check_mouse_face
23983 && mouse_beg_col
< i
&& mouse_end_col
> end
)
23984 overlap_hl
= DRAW_MOUSE_FACE
;
23986 overlap_hl
= DRAW_NORMAL_TEXT
;
23989 i
++; /* We must include the Ith glyph. */
23990 BUILD_GLYPH_STRINGS (end
, i
, h
, t
,
23991 overlap_hl
, x
, last_x
);
23992 for (s
= h
; s
; s
= s
->next
)
23993 s
->background_filled_p
= 1;
23994 compute_overhangs_and_x (h
, tail
->x
+ tail
->width
, 0);
23995 append_glyph_string_lists (&head
, &tail
, h
, t
);
23997 if (clip_head
|| clip_tail
)
23998 for (s
= head
; s
; s
= s
->next
)
24000 s
->clip_head
= clip_head
;
24001 s
->clip_tail
= clip_tail
;
24005 /* Draw all strings. */
24006 for (s
= head
; s
; s
= s
->next
)
24007 FRAME_RIF (f
)->draw_glyph_string (s
);
24010 /* When focus a sole frame and move horizontally, this sets on_p to 0
24011 causing a failure to erase prev cursor position. */
24012 if (area
== TEXT_AREA
24013 && !row
->full_width_p
24014 /* When drawing overlapping rows, only the glyph strings'
24015 foreground is drawn, which doesn't erase a cursor
24019 int x0
= clip_head
? clip_head
->x
: (head
? head
->x
: x
);
24020 int x1
= (clip_tail
? clip_tail
->x
+ clip_tail
->background_width
24021 : (tail
? tail
->x
+ tail
->background_width
: x
));
24025 notice_overwritten_cursor (w
, TEXT_AREA
, x0
, x1
,
24026 row
->y
, MATRIX_ROW_BOTTOM_Y (row
));
24030 /* Value is the x-position up to which drawn, relative to AREA of W.
24031 This doesn't include parts drawn because of overhangs. */
24032 if (row
->full_width_p
)
24033 x_reached
= FRAME_TO_WINDOW_PIXEL_X (w
, x_reached
);
24035 x_reached
-= area_left
;
24037 RELEASE_HDC (hdc
, f
);
24042 /* Expand row matrix if too narrow. Don't expand if area
24045 #define IT_EXPAND_MATRIX_WIDTH(it, area) \
24047 if (!fonts_changed_p \
24048 && (it->glyph_row->glyphs[area] \
24049 < it->glyph_row->glyphs[area + 1])) \
24051 it->w->ncols_scale_factor++; \
24052 fonts_changed_p = 1; \
24056 /* Store one glyph for IT->char_to_display in IT->glyph_row.
24057 Called from x_produce_glyphs when IT->glyph_row is non-null. */
24060 append_glyph (struct it
*it
)
24062 struct glyph
*glyph
;
24063 enum glyph_row_area area
= it
->area
;
24065 eassert (it
->glyph_row
);
24066 eassert (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t');
24068 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24069 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24071 /* If the glyph row is reversed, we need to prepend the glyph
24072 rather than append it. */
24073 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24077 /* Make room for the additional glyph. */
24078 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24080 glyph
= it
->glyph_row
->glyphs
[area
];
24082 glyph
->charpos
= CHARPOS (it
->position
);
24083 glyph
->object
= it
->object
;
24084 if (it
->pixel_width
> 0)
24086 glyph
->pixel_width
= it
->pixel_width
;
24087 glyph
->padding_p
= 0;
24091 /* Assure at least 1-pixel width. Otherwise, cursor can't
24092 be displayed correctly. */
24093 glyph
->pixel_width
= 1;
24094 glyph
->padding_p
= 1;
24096 glyph
->ascent
= it
->ascent
;
24097 glyph
->descent
= it
->descent
;
24098 glyph
->voffset
= it
->voffset
;
24099 glyph
->type
= CHAR_GLYPH
;
24100 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24101 glyph
->multibyte_p
= it
->multibyte_p
;
24102 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24104 /* In R2L rows, the left and the right box edges need to be
24105 drawn in reverse direction. */
24106 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24107 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24111 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24112 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24114 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24115 || it
->phys_descent
> it
->descent
);
24116 glyph
->glyph_not_available_p
= it
->glyph_not_available_p
;
24117 glyph
->face_id
= it
->face_id
;
24118 glyph
->u
.ch
= it
->char_to_display
;
24119 glyph
->slice
.img
= null_glyph_slice
;
24120 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24123 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24124 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24126 glyph
->bidi_type
= it
->bidi_it
.type
;
24130 glyph
->resolved_level
= 0;
24131 glyph
->bidi_type
= UNKNOWN_BT
;
24133 ++it
->glyph_row
->used
[area
];
24136 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24139 /* Store one glyph for the composition IT->cmp_it.id in
24140 IT->glyph_row. Called from x_produce_glyphs when IT->glyph_row is
24144 append_composite_glyph (struct it
*it
)
24146 struct glyph
*glyph
;
24147 enum glyph_row_area area
= it
->area
;
24149 eassert (it
->glyph_row
);
24151 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24152 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24154 /* If the glyph row is reversed, we need to prepend the glyph
24155 rather than append it. */
24156 if (it
->glyph_row
->reversed_p
&& it
->area
== TEXT_AREA
)
24160 /* Make room for the new glyph. */
24161 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[it
->area
]; g
--)
24163 glyph
= it
->glyph_row
->glyphs
[it
->area
];
24165 glyph
->charpos
= it
->cmp_it
.charpos
;
24166 glyph
->object
= it
->object
;
24167 glyph
->pixel_width
= it
->pixel_width
;
24168 glyph
->ascent
= it
->ascent
;
24169 glyph
->descent
= it
->descent
;
24170 glyph
->voffset
= it
->voffset
;
24171 glyph
->type
= COMPOSITE_GLYPH
;
24172 if (it
->cmp_it
.ch
< 0)
24174 glyph
->u
.cmp
.automatic
= 0;
24175 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24176 glyph
->slice
.cmp
.from
= glyph
->slice
.cmp
.to
= 0;
24180 glyph
->u
.cmp
.automatic
= 1;
24181 glyph
->u
.cmp
.id
= it
->cmp_it
.id
;
24182 glyph
->slice
.cmp
.from
= it
->cmp_it
.from
;
24183 glyph
->slice
.cmp
.to
= it
->cmp_it
.to
- 1;
24185 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24186 glyph
->multibyte_p
= it
->multibyte_p
;
24187 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24189 /* In R2L rows, the left and the right box edges need to be
24190 drawn in reverse direction. */
24191 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24192 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24196 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24197 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24199 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24200 || it
->phys_descent
> it
->descent
);
24201 glyph
->padding_p
= 0;
24202 glyph
->glyph_not_available_p
= 0;
24203 glyph
->face_id
= it
->face_id
;
24204 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24207 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24208 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24210 glyph
->bidi_type
= it
->bidi_it
.type
;
24212 ++it
->glyph_row
->used
[area
];
24215 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24219 /* Change IT->ascent and IT->height according to the setting of
24223 take_vertical_position_into_account (struct it
*it
)
24227 if (it
->voffset
< 0)
24228 /* Increase the ascent so that we can display the text higher
24230 it
->ascent
-= it
->voffset
;
24232 /* Increase the descent so that we can display the text lower
24234 it
->descent
+= it
->voffset
;
24239 /* Produce glyphs/get display metrics for the image IT is loaded with.
24240 See the description of struct display_iterator in dispextern.h for
24241 an overview of struct display_iterator. */
24244 produce_image_glyph (struct it
*it
)
24248 int glyph_ascent
, crop
;
24249 struct glyph_slice slice
;
24251 eassert (it
->what
== IT_IMAGE
);
24253 face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24255 /* Make sure X resources of the face is loaded. */
24256 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24258 if (it
->image_id
< 0)
24260 /* Fringe bitmap. */
24261 it
->ascent
= it
->phys_ascent
= 0;
24262 it
->descent
= it
->phys_descent
= 0;
24263 it
->pixel_width
= 0;
24268 img
= IMAGE_FROM_ID (it
->f
, it
->image_id
);
24270 /* Make sure X resources of the image is loaded. */
24271 prepare_image_for_display (it
->f
, img
);
24273 slice
.x
= slice
.y
= 0;
24274 slice
.width
= img
->width
;
24275 slice
.height
= img
->height
;
24277 if (INTEGERP (it
->slice
.x
))
24278 slice
.x
= XINT (it
->slice
.x
);
24279 else if (FLOATP (it
->slice
.x
))
24280 slice
.x
= XFLOAT_DATA (it
->slice
.x
) * img
->width
;
24282 if (INTEGERP (it
->slice
.y
))
24283 slice
.y
= XINT (it
->slice
.y
);
24284 else if (FLOATP (it
->slice
.y
))
24285 slice
.y
= XFLOAT_DATA (it
->slice
.y
) * img
->height
;
24287 if (INTEGERP (it
->slice
.width
))
24288 slice
.width
= XINT (it
->slice
.width
);
24289 else if (FLOATP (it
->slice
.width
))
24290 slice
.width
= XFLOAT_DATA (it
->slice
.width
) * img
->width
;
24292 if (INTEGERP (it
->slice
.height
))
24293 slice
.height
= XINT (it
->slice
.height
);
24294 else if (FLOATP (it
->slice
.height
))
24295 slice
.height
= XFLOAT_DATA (it
->slice
.height
) * img
->height
;
24297 if (slice
.x
>= img
->width
)
24298 slice
.x
= img
->width
;
24299 if (slice
.y
>= img
->height
)
24300 slice
.y
= img
->height
;
24301 if (slice
.x
+ slice
.width
>= img
->width
)
24302 slice
.width
= img
->width
- slice
.x
;
24303 if (slice
.y
+ slice
.height
> img
->height
)
24304 slice
.height
= img
->height
- slice
.y
;
24306 if (slice
.width
== 0 || slice
.height
== 0)
24309 it
->ascent
= it
->phys_ascent
= glyph_ascent
= image_ascent (img
, face
, &slice
);
24311 it
->descent
= slice
.height
- glyph_ascent
;
24313 it
->descent
+= img
->vmargin
;
24314 if (slice
.y
+ slice
.height
== img
->height
)
24315 it
->descent
+= img
->vmargin
;
24316 it
->phys_descent
= it
->descent
;
24318 it
->pixel_width
= slice
.width
;
24320 it
->pixel_width
+= img
->hmargin
;
24321 if (slice
.x
+ slice
.width
== img
->width
)
24322 it
->pixel_width
+= img
->hmargin
;
24324 /* It's quite possible for images to have an ascent greater than
24325 their height, so don't get confused in that case. */
24326 if (it
->descent
< 0)
24331 if (face
->box
!= FACE_NO_BOX
)
24333 if (face
->box_line_width
> 0)
24336 it
->ascent
+= face
->box_line_width
;
24337 if (slice
.y
+ slice
.height
== img
->height
)
24338 it
->descent
+= face
->box_line_width
;
24341 if (it
->start_of_box_run_p
&& slice
.x
== 0)
24342 it
->pixel_width
+= eabs (face
->box_line_width
);
24343 if (it
->end_of_box_run_p
&& slice
.x
+ slice
.width
== img
->width
)
24344 it
->pixel_width
+= eabs (face
->box_line_width
);
24347 take_vertical_position_into_account (it
);
24349 /* Automatically crop wide image glyphs at right edge so we can
24350 draw the cursor on same display row. */
24351 if ((crop
= it
->pixel_width
- (it
->last_visible_x
- it
->current_x
), crop
> 0)
24352 && (it
->hpos
== 0 || it
->pixel_width
> it
->last_visible_x
/ 4))
24354 it
->pixel_width
-= crop
;
24355 slice
.width
-= crop
;
24360 struct glyph
*glyph
;
24361 enum glyph_row_area area
= it
->area
;
24363 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24364 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24366 glyph
->charpos
= CHARPOS (it
->position
);
24367 glyph
->object
= it
->object
;
24368 glyph
->pixel_width
= it
->pixel_width
;
24369 glyph
->ascent
= glyph_ascent
;
24370 glyph
->descent
= it
->descent
;
24371 glyph
->voffset
= it
->voffset
;
24372 glyph
->type
= IMAGE_GLYPH
;
24373 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24374 glyph
->multibyte_p
= it
->multibyte_p
;
24375 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24377 /* In R2L rows, the left and the right box edges need to be
24378 drawn in reverse direction. */
24379 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24380 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24384 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24385 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24387 glyph
->overlaps_vertically_p
= 0;
24388 glyph
->padding_p
= 0;
24389 glyph
->glyph_not_available_p
= 0;
24390 glyph
->face_id
= it
->face_id
;
24391 glyph
->u
.img_id
= img
->id
;
24392 glyph
->slice
.img
= slice
;
24393 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24396 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24397 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24399 glyph
->bidi_type
= it
->bidi_it
.type
;
24401 ++it
->glyph_row
->used
[area
];
24404 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24409 /* Append a stretch glyph to IT->glyph_row. OBJECT is the source
24410 of the glyph, WIDTH and HEIGHT are the width and height of the
24411 stretch. ASCENT is the ascent of the glyph (0 <= ASCENT <= HEIGHT). */
24414 append_stretch_glyph (struct it
*it
, Lisp_Object object
,
24415 int width
, int height
, int ascent
)
24417 struct glyph
*glyph
;
24418 enum glyph_row_area area
= it
->area
;
24420 eassert (ascent
>= 0 && ascent
<= height
);
24422 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24423 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24425 /* If the glyph row is reversed, we need to prepend the glyph
24426 rather than append it. */
24427 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24431 /* Make room for the additional glyph. */
24432 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24434 glyph
= it
->glyph_row
->glyphs
[area
];
24436 glyph
->charpos
= CHARPOS (it
->position
);
24437 glyph
->object
= object
;
24438 glyph
->pixel_width
= width
;
24439 glyph
->ascent
= ascent
;
24440 glyph
->descent
= height
- ascent
;
24441 glyph
->voffset
= it
->voffset
;
24442 glyph
->type
= STRETCH_GLYPH
;
24443 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24444 glyph
->multibyte_p
= it
->multibyte_p
;
24445 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24447 /* In R2L rows, the left and the right box edges need to be
24448 drawn in reverse direction. */
24449 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24450 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24454 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24455 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24457 glyph
->overlaps_vertically_p
= 0;
24458 glyph
->padding_p
= 0;
24459 glyph
->glyph_not_available_p
= 0;
24460 glyph
->face_id
= it
->face_id
;
24461 glyph
->u
.stretch
.ascent
= ascent
;
24462 glyph
->u
.stretch
.height
= height
;
24463 glyph
->slice
.img
= null_glyph_slice
;
24464 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24467 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24468 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24470 glyph
->bidi_type
= it
->bidi_it
.type
;
24474 glyph
->resolved_level
= 0;
24475 glyph
->bidi_type
= UNKNOWN_BT
;
24477 ++it
->glyph_row
->used
[area
];
24480 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24483 #endif /* HAVE_WINDOW_SYSTEM */
24485 /* Produce a stretch glyph for iterator IT. IT->object is the value
24486 of the glyph property displayed. The value must be a list
24487 `(space KEYWORD VALUE ...)' with the following KEYWORD/VALUE pairs
24490 1. `:width WIDTH' specifies that the space should be WIDTH *
24491 canonical char width wide. WIDTH may be an integer or floating
24494 2. `:relative-width FACTOR' specifies that the width of the stretch
24495 should be computed from the width of the first character having the
24496 `glyph' property, and should be FACTOR times that width.
24498 3. `:align-to HPOS' specifies that the space should be wide enough
24499 to reach HPOS, a value in canonical character units.
24501 Exactly one of the above pairs must be present.
24503 4. `:height HEIGHT' specifies that the height of the stretch produced
24504 should be HEIGHT, measured in canonical character units.
24506 5. `:relative-height FACTOR' specifies that the height of the
24507 stretch should be FACTOR times the height of the characters having
24508 the glyph property.
24510 Either none or exactly one of 4 or 5 must be present.
24512 6. `:ascent ASCENT' specifies that ASCENT percent of the height
24513 of the stretch should be used for the ascent of the stretch.
24514 ASCENT must be in the range 0 <= ASCENT <= 100. */
24517 produce_stretch_glyph (struct it
*it
)
24519 /* (space :width WIDTH :height HEIGHT ...) */
24520 Lisp_Object prop
, plist
;
24521 int width
= 0, height
= 0, align_to
= -1;
24522 int zero_width_ok_p
= 0;
24524 struct font
*font
= NULL
;
24526 #ifdef HAVE_WINDOW_SYSTEM
24528 int zero_height_ok_p
= 0;
24530 if (FRAME_WINDOW_P (it
->f
))
24532 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
24533 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24534 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
24538 /* List should start with `space'. */
24539 eassert (CONSP (it
->object
) && EQ (XCAR (it
->object
), Qspace
));
24540 plist
= XCDR (it
->object
);
24542 /* Compute the width of the stretch. */
24543 if ((prop
= Fplist_get (plist
, QCwidth
), !NILP (prop
))
24544 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, 0))
24546 /* Absolute width `:width WIDTH' specified and valid. */
24547 zero_width_ok_p
= 1;
24550 #ifdef HAVE_WINDOW_SYSTEM
24551 else if (FRAME_WINDOW_P (it
->f
)
24552 && (prop
= Fplist_get (plist
, QCrelative_width
), NUMVAL (prop
) > 0))
24554 /* Relative width `:relative-width FACTOR' specified and valid.
24555 Compute the width of the characters having the `glyph'
24558 unsigned char *p
= BYTE_POS_ADDR (IT_BYTEPOS (*it
));
24561 if (it
->multibyte_p
)
24562 it2
.c
= it2
.char_to_display
= STRING_CHAR_AND_LENGTH (p
, it2
.len
);
24565 it2
.c
= it2
.char_to_display
= *p
, it2
.len
= 1;
24566 if (! ASCII_CHAR_P (it2
.c
))
24567 it2
.char_to_display
= BYTE8_TO_CHAR (it2
.c
);
24570 it2
.glyph_row
= NULL
;
24571 it2
.what
= IT_CHARACTER
;
24572 x_produce_glyphs (&it2
);
24573 width
= NUMVAL (prop
) * it2
.pixel_width
;
24575 #endif /* HAVE_WINDOW_SYSTEM */
24576 else if ((prop
= Fplist_get (plist
, QCalign_to
), !NILP (prop
))
24577 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 1, &align_to
))
24579 if (it
->glyph_row
== NULL
|| !it
->glyph_row
->mode_line_p
)
24580 align_to
= (align_to
< 0
24582 : align_to
- window_box_left_offset (it
->w
, TEXT_AREA
));
24583 else if (align_to
< 0)
24584 align_to
= window_box_left_offset (it
->w
, TEXT_AREA
);
24585 width
= max (0, (int)tem
+ align_to
- it
->current_x
);
24586 zero_width_ok_p
= 1;
24589 /* Nothing specified -> width defaults to canonical char width. */
24590 width
= FRAME_COLUMN_WIDTH (it
->f
);
24592 if (width
<= 0 && (width
< 0 || !zero_width_ok_p
))
24595 #ifdef HAVE_WINDOW_SYSTEM
24596 /* Compute height. */
24597 if (FRAME_WINDOW_P (it
->f
))
24599 if ((prop
= Fplist_get (plist
, QCheight
), !NILP (prop
))
24600 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24603 zero_height_ok_p
= 1;
24605 else if (prop
= Fplist_get (plist
, QCrelative_height
),
24607 height
= FONT_HEIGHT (font
) * NUMVAL (prop
);
24609 height
= FONT_HEIGHT (font
);
24611 if (height
<= 0 && (height
< 0 || !zero_height_ok_p
))
24614 /* Compute percentage of height used for ascent. If
24615 `:ascent ASCENT' is present and valid, use that. Otherwise,
24616 derive the ascent from the font in use. */
24617 if (prop
= Fplist_get (plist
, QCascent
),
24618 NUMVAL (prop
) > 0 && NUMVAL (prop
) <= 100)
24619 ascent
= height
* NUMVAL (prop
) / 100.0;
24620 else if (!NILP (prop
)
24621 && calc_pixel_width_or_height (&tem
, it
, prop
, font
, 0, 0))
24622 ascent
= min (max (0, (int)tem
), height
);
24624 ascent
= (height
* FONT_BASE (font
)) / FONT_HEIGHT (font
);
24627 #endif /* HAVE_WINDOW_SYSTEM */
24630 if (width
> 0 && it
->line_wrap
!= TRUNCATE
24631 && it
->current_x
+ width
> it
->last_visible_x
)
24633 width
= it
->last_visible_x
- it
->current_x
;
24634 #ifdef HAVE_WINDOW_SYSTEM
24635 /* Subtract one more pixel from the stretch width, but only on
24636 GUI frames, since on a TTY each glyph is one "pixel" wide. */
24637 width
-= FRAME_WINDOW_P (it
->f
);
24641 if (width
> 0 && height
> 0 && it
->glyph_row
)
24643 Lisp_Object o_object
= it
->object
;
24644 Lisp_Object object
= it
->stack
[it
->sp
- 1].string
;
24647 if (!STRINGP (object
))
24648 object
= it
->w
->contents
;
24649 #ifdef HAVE_WINDOW_SYSTEM
24650 if (FRAME_WINDOW_P (it
->f
))
24651 append_stretch_glyph (it
, object
, width
, height
, ascent
);
24655 it
->object
= object
;
24656 it
->char_to_display
= ' ';
24657 it
->pixel_width
= it
->len
= 1;
24659 tty_append_glyph (it
);
24660 it
->object
= o_object
;
24664 it
->pixel_width
= width
;
24665 #ifdef HAVE_WINDOW_SYSTEM
24666 if (FRAME_WINDOW_P (it
->f
))
24668 it
->ascent
= it
->phys_ascent
= ascent
;
24669 it
->descent
= it
->phys_descent
= height
- it
->ascent
;
24670 it
->nglyphs
= width
> 0 && height
> 0 ? 1 : 0;
24671 take_vertical_position_into_account (it
);
24675 it
->nglyphs
= width
;
24678 /* Get information about special display element WHAT in an
24679 environment described by IT. WHAT is one of IT_TRUNCATION or
24680 IT_CONTINUATION. Maybe produce glyphs for WHAT if IT has a
24681 non-null glyph_row member. This function ensures that fields like
24682 face_id, c, len of IT are left untouched. */
24685 produce_special_glyphs (struct it
*it
, enum display_element_type what
)
24692 temp_it
.object
= make_number (0);
24693 memset (&temp_it
.current
, 0, sizeof temp_it
.current
);
24695 if (what
== IT_CONTINUATION
)
24697 /* Continuation glyph. For R2L lines, we mirror it by hand. */
24698 if (it
->bidi_it
.paragraph_dir
== R2L
)
24699 SET_GLYPH_FROM_CHAR (glyph
, '/');
24701 SET_GLYPH_FROM_CHAR (glyph
, '\\');
24703 && (gc
= DISP_CONTINUE_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24705 /* FIXME: Should we mirror GC for R2L lines? */
24706 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24707 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24710 else if (what
== IT_TRUNCATION
)
24712 /* Truncation glyph. */
24713 SET_GLYPH_FROM_CHAR (glyph
, '$');
24715 && (gc
= DISP_TRUNC_GLYPH (it
->dp
), GLYPH_CODE_P (gc
)))
24717 /* FIXME: Should we mirror GC for R2L lines? */
24718 SET_GLYPH_FROM_GLYPH_CODE (glyph
, gc
);
24719 spec_glyph_lookup_face (XWINDOW (it
->window
), &glyph
);
24725 #ifdef HAVE_WINDOW_SYSTEM
24726 /* On a GUI frame, when the right fringe (left fringe for R2L rows)
24727 is turned off, we precede the truncation/continuation glyphs by a
24728 stretch glyph whose width is computed such that these special
24729 glyphs are aligned at the window margin, even when very different
24730 fonts are used in different glyph rows. */
24731 if (FRAME_WINDOW_P (temp_it
.f
)
24732 /* init_iterator calls this with it->glyph_row == NULL, and it
24733 wants only the pixel width of the truncation/continuation
24735 && temp_it
.glyph_row
24736 /* insert_left_trunc_glyphs calls us at the beginning of the
24737 row, and it has its own calculation of the stretch glyph
24739 && temp_it
.glyph_row
->used
[TEXT_AREA
] > 0
24740 && (temp_it
.glyph_row
->reversed_p
24741 ? WINDOW_LEFT_FRINGE_WIDTH (temp_it
.w
)
24742 : WINDOW_RIGHT_FRINGE_WIDTH (temp_it
.w
)) == 0)
24744 int stretch_width
= temp_it
.last_visible_x
- temp_it
.current_x
;
24746 if (stretch_width
> 0)
24748 struct face
*face
= FACE_FROM_ID (temp_it
.f
, temp_it
.face_id
);
24749 struct font
*font
=
24750 face
->font
? face
->font
: FRAME_FONT (temp_it
.f
);
24751 int stretch_ascent
=
24752 (((temp_it
.ascent
+ temp_it
.descent
)
24753 * FONT_BASE (font
)) / FONT_HEIGHT (font
));
24755 append_stretch_glyph (&temp_it
, make_number (0), stretch_width
,
24756 temp_it
.ascent
+ temp_it
.descent
,
24763 temp_it
.what
= IT_CHARACTER
;
24765 temp_it
.c
= temp_it
.char_to_display
= GLYPH_CHAR (glyph
);
24766 temp_it
.face_id
= GLYPH_FACE (glyph
);
24767 temp_it
.len
= CHAR_BYTES (temp_it
.c
);
24769 PRODUCE_GLYPHS (&temp_it
);
24770 it
->pixel_width
= temp_it
.pixel_width
;
24771 it
->nglyphs
= temp_it
.pixel_width
;
24774 #ifdef HAVE_WINDOW_SYSTEM
24776 /* Calculate line-height and line-spacing properties.
24777 An integer value specifies explicit pixel value.
24778 A float value specifies relative value to current face height.
24779 A cons (float . face-name) specifies relative value to
24780 height of specified face font.
24782 Returns height in pixels, or nil. */
24786 calc_line_height_property (struct it
*it
, Lisp_Object val
, struct font
*font
,
24787 int boff
, int override
)
24789 Lisp_Object face_name
= Qnil
;
24790 int ascent
, descent
, height
;
24792 if (NILP (val
) || INTEGERP (val
) || (override
&& EQ (val
, Qt
)))
24797 face_name
= XCAR (val
);
24799 if (!NUMBERP (val
))
24800 val
= make_number (1);
24801 if (NILP (face_name
))
24803 height
= it
->ascent
+ it
->descent
;
24808 if (NILP (face_name
))
24810 font
= FRAME_FONT (it
->f
);
24811 boff
= FRAME_BASELINE_OFFSET (it
->f
);
24813 else if (EQ (face_name
, Qt
))
24822 face_id
= lookup_named_face (it
->f
, face_name
, 0);
24824 return make_number (-1);
24826 face
= FACE_FROM_ID (it
->f
, face_id
);
24829 return make_number (-1);
24830 boff
= font
->baseline_offset
;
24831 if (font
->vertical_centering
)
24832 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
24835 ascent
= FONT_BASE (font
) + boff
;
24836 descent
= FONT_DESCENT (font
) - boff
;
24840 it
->override_ascent
= ascent
;
24841 it
->override_descent
= descent
;
24842 it
->override_boff
= boff
;
24845 height
= ascent
+ descent
;
24849 height
= (int)(XFLOAT_DATA (val
) * height
);
24850 else if (INTEGERP (val
))
24851 height
*= XINT (val
);
24853 return make_number (height
);
24857 /* Append a glyph for a glyphless character to IT->glyph_row. FACE_ID
24858 is a face ID to be used for the glyph. FOR_NO_FONT is nonzero if
24859 and only if this is for a character for which no font was found.
24861 If the display method (it->glyphless_method) is
24862 GLYPHLESS_DISPLAY_ACRONYM or GLYPHLESS_DISPLAY_HEX_CODE, LEN is a
24863 length of the acronym or the hexadecimal string, UPPER_XOFF and
24864 UPPER_YOFF are pixel offsets for the upper part of the string,
24865 LOWER_XOFF and LOWER_YOFF are for the lower part.
24867 For the other display methods, LEN through LOWER_YOFF are zero. */
24870 append_glyphless_glyph (struct it
*it
, int face_id
, int for_no_font
, int len
,
24871 short upper_xoff
, short upper_yoff
,
24872 short lower_xoff
, short lower_yoff
)
24874 struct glyph
*glyph
;
24875 enum glyph_row_area area
= it
->area
;
24877 glyph
= it
->glyph_row
->glyphs
[area
] + it
->glyph_row
->used
[area
];
24878 if (glyph
< it
->glyph_row
->glyphs
[area
+ 1])
24880 /* If the glyph row is reversed, we need to prepend the glyph
24881 rather than append it. */
24882 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24886 /* Make room for the additional glyph. */
24887 for (g
= glyph
- 1; g
>= it
->glyph_row
->glyphs
[area
]; g
--)
24889 glyph
= it
->glyph_row
->glyphs
[area
];
24891 glyph
->charpos
= CHARPOS (it
->position
);
24892 glyph
->object
= it
->object
;
24893 glyph
->pixel_width
= it
->pixel_width
;
24894 glyph
->ascent
= it
->ascent
;
24895 glyph
->descent
= it
->descent
;
24896 glyph
->voffset
= it
->voffset
;
24897 glyph
->type
= GLYPHLESS_GLYPH
;
24898 glyph
->u
.glyphless
.method
= it
->glyphless_method
;
24899 glyph
->u
.glyphless
.for_no_font
= for_no_font
;
24900 glyph
->u
.glyphless
.len
= len
;
24901 glyph
->u
.glyphless
.ch
= it
->c
;
24902 glyph
->slice
.glyphless
.upper_xoff
= upper_xoff
;
24903 glyph
->slice
.glyphless
.upper_yoff
= upper_yoff
;
24904 glyph
->slice
.glyphless
.lower_xoff
= lower_xoff
;
24905 glyph
->slice
.glyphless
.lower_yoff
= lower_yoff
;
24906 glyph
->avoid_cursor_p
= it
->avoid_cursor_p
;
24907 glyph
->multibyte_p
= it
->multibyte_p
;
24908 if (it
->glyph_row
->reversed_p
&& area
== TEXT_AREA
)
24910 /* In R2L rows, the left and the right box edges need to be
24911 drawn in reverse direction. */
24912 glyph
->right_box_line_p
= it
->start_of_box_run_p
;
24913 glyph
->left_box_line_p
= it
->end_of_box_run_p
;
24917 glyph
->left_box_line_p
= it
->start_of_box_run_p
;
24918 glyph
->right_box_line_p
= it
->end_of_box_run_p
;
24920 glyph
->overlaps_vertically_p
= (it
->phys_ascent
> it
->ascent
24921 || it
->phys_descent
> it
->descent
);
24922 glyph
->padding_p
= 0;
24923 glyph
->glyph_not_available_p
= 0;
24924 glyph
->face_id
= face_id
;
24925 glyph
->font_type
= FONT_TYPE_UNKNOWN
;
24928 glyph
->resolved_level
= it
->bidi_it
.resolved_level
;
24929 if ((it
->bidi_it
.type
& 7) != it
->bidi_it
.type
)
24931 glyph
->bidi_type
= it
->bidi_it
.type
;
24933 ++it
->glyph_row
->used
[area
];
24936 IT_EXPAND_MATRIX_WIDTH (it
, area
);
24940 /* Produce a glyph for a glyphless character for iterator IT.
24941 IT->glyphless_method specifies which method to use for displaying
24942 the character. See the description of enum
24943 glyphless_display_method in dispextern.h for the detail.
24945 FOR_NO_FONT is nonzero if and only if this is for a character for
24946 which no font was found. ACRONYM, if non-nil, is an acronym string
24947 for the character. */
24950 produce_glyphless_glyph (struct it
*it
, int for_no_font
, Lisp_Object acronym
)
24955 int base_width
, base_height
, width
, height
;
24956 short upper_xoff
, upper_yoff
, lower_xoff
, lower_yoff
;
24959 /* Get the metrics of the base font. We always refer to the current
24961 face
= FACE_FROM_ID (it
->f
, it
->face_id
)->ascii_face
;
24962 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
24963 it
->ascent
= FONT_BASE (font
) + font
->baseline_offset
;
24964 it
->descent
= FONT_DESCENT (font
) - font
->baseline_offset
;
24965 base_height
= it
->ascent
+ it
->descent
;
24966 base_width
= font
->average_width
;
24968 /* Get a face ID for the glyph by utilizing a cache (the same way as
24969 done for `escape-glyph' in get_next_display_element). */
24970 if (it
->f
== last_glyphless_glyph_frame
24971 && it
->face_id
== last_glyphless_glyph_face_id
)
24973 face_id
= last_glyphless_glyph_merged_face_id
;
24977 /* Merge the `glyphless-char' face into the current face. */
24978 face_id
= merge_faces (it
->f
, Qglyphless_char
, 0, it
->face_id
);
24979 last_glyphless_glyph_frame
= it
->f
;
24980 last_glyphless_glyph_face_id
= it
->face_id
;
24981 last_glyphless_glyph_merged_face_id
= face_id
;
24984 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_THIN_SPACE
)
24986 it
->pixel_width
= THIN_SPACE_WIDTH
;
24988 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
24990 else if (it
->glyphless_method
== GLYPHLESS_DISPLAY_EMPTY_BOX
)
24992 width
= CHAR_WIDTH (it
->c
);
24995 else if (width
> 4)
24997 it
->pixel_width
= base_width
* width
;
24999 upper_xoff
= upper_yoff
= lower_xoff
= lower_yoff
= 0;
25005 unsigned int code
[6];
25007 int ascent
, descent
;
25008 struct font_metrics metrics_upper
, metrics_lower
;
25010 face
= FACE_FROM_ID (it
->f
, face_id
);
25011 font
= face
->font
? face
->font
: FRAME_FONT (it
->f
);
25012 PREPARE_FACE_FOR_DISPLAY (it
->f
, face
);
25014 if (it
->glyphless_method
== GLYPHLESS_DISPLAY_ACRONYM
)
25016 if (! STRINGP (acronym
) && CHAR_TABLE_P (Vglyphless_char_display
))
25017 acronym
= CHAR_TABLE_REF (Vglyphless_char_display
, it
->c
);
25018 if (CONSP (acronym
))
25019 acronym
= XCAR (acronym
);
25020 str
= STRINGP (acronym
) ? SSDATA (acronym
) : "";
25024 eassert (it
->glyphless_method
== GLYPHLESS_DISPLAY_HEX_CODE
);
25025 sprintf (buf
, "%0*X", it
->c
< 0x10000 ? 4 : 6, it
->c
);
25028 for (len
= 0; str
[len
] && ASCII_BYTE_P (str
[len
]) && len
< 6; len
++)
25029 code
[len
] = font
->driver
->encode_char (font
, str
[len
]);
25030 upper_len
= (len
+ 1) / 2;
25031 font
->driver
->text_extents (font
, code
, upper_len
,
25033 font
->driver
->text_extents (font
, code
+ upper_len
, len
- upper_len
,
25038 /* +4 is for vertical bars of a box plus 1-pixel spaces at both side. */
25039 width
= max (metrics_upper
.width
, metrics_lower
.width
) + 4;
25040 upper_xoff
= upper_yoff
= 2; /* the typical case */
25041 if (base_width
>= width
)
25043 /* Align the upper to the left, the lower to the right. */
25044 it
->pixel_width
= base_width
;
25045 lower_xoff
= base_width
- 2 - metrics_lower
.width
;
25049 /* Center the shorter one. */
25050 it
->pixel_width
= width
;
25051 if (metrics_upper
.width
>= metrics_lower
.width
)
25052 lower_xoff
= (width
- metrics_lower
.width
) / 2;
25055 /* FIXME: This code doesn't look right. It formerly was
25056 missing the "lower_xoff = 0;", which couldn't have
25057 been right since it left lower_xoff uninitialized. */
25059 upper_xoff
= (width
- metrics_upper
.width
) / 2;
25063 /* +5 is for horizontal bars of a box plus 1-pixel spaces at
25064 top, bottom, and between upper and lower strings. */
25065 height
= (metrics_upper
.ascent
+ metrics_upper
.descent
25066 + metrics_lower
.ascent
+ metrics_lower
.descent
) + 5;
25067 /* Center vertically.
25068 H:base_height, D:base_descent
25069 h:height, ld:lower_descent, la:lower_ascent, ud:upper_descent
25071 ascent = - (D - H/2 - h/2 + 1); "+ 1" for rounding up
25072 descent = D - H/2 + h/2;
25073 lower_yoff = descent - 2 - ld;
25074 upper_yoff = lower_yoff - la - 1 - ud; */
25075 ascent
= - (it
->descent
- (base_height
+ height
+ 1) / 2);
25076 descent
= it
->descent
- (base_height
- height
) / 2;
25077 lower_yoff
= descent
- 2 - metrics_lower
.descent
;
25078 upper_yoff
= (lower_yoff
- metrics_lower
.ascent
- 1
25079 - metrics_upper
.descent
);
25080 /* Don't make the height shorter than the base height. */
25081 if (height
> base_height
)
25083 it
->ascent
= ascent
;
25084 it
->descent
= descent
;
25088 it
->phys_ascent
= it
->ascent
;
25089 it
->phys_descent
= it
->descent
;
25091 append_glyphless_glyph (it
, face_id
, for_no_font
, len
,
25092 upper_xoff
, upper_yoff
,
25093 lower_xoff
, lower_yoff
);
25095 take_vertical_position_into_account (it
);
25100 Produce glyphs/get display metrics for the display element IT is
25101 loaded with. See the description of struct it in dispextern.h
25102 for an overview of struct it. */
25105 x_produce_glyphs (struct it
*it
)
25107 int extra_line_spacing
= it
->extra_line_spacing
;
25109 it
->glyph_not_available_p
= 0;
25111 if (it
->what
== IT_CHARACTER
)
25114 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25115 struct font
*font
= face
->font
;
25116 struct font_metrics
*pcm
= NULL
;
25117 int boff
; /* baseline offset */
25121 /* When no suitable font is found, display this character by
25122 the method specified in the first extra slot of
25123 Vglyphless_char_display. */
25124 Lisp_Object acronym
= lookup_glyphless_char_display (-1, it
);
25126 eassert (it
->what
== IT_GLYPHLESS
);
25127 produce_glyphless_glyph (it
, 1, STRINGP (acronym
) ? acronym
: Qnil
);
25131 boff
= font
->baseline_offset
;
25132 if (font
->vertical_centering
)
25133 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25135 if (it
->char_to_display
!= '\n' && it
->char_to_display
!= '\t')
25141 if (it
->override_ascent
>= 0)
25143 it
->ascent
= it
->override_ascent
;
25144 it
->descent
= it
->override_descent
;
25145 boff
= it
->override_boff
;
25149 it
->ascent
= FONT_BASE (font
) + boff
;
25150 it
->descent
= FONT_DESCENT (font
) - boff
;
25153 if (get_char_glyph_code (it
->char_to_display
, font
, &char2b
))
25155 pcm
= get_per_char_metric (font
, &char2b
);
25156 if (pcm
->width
== 0
25157 && pcm
->rbearing
== 0 && pcm
->lbearing
== 0)
25163 it
->phys_ascent
= pcm
->ascent
+ boff
;
25164 it
->phys_descent
= pcm
->descent
- boff
;
25165 it
->pixel_width
= pcm
->width
;
25169 it
->glyph_not_available_p
= 1;
25170 it
->phys_ascent
= it
->ascent
;
25171 it
->phys_descent
= it
->descent
;
25172 it
->pixel_width
= font
->space_width
;
25175 if (it
->constrain_row_ascent_descent_p
)
25177 if (it
->descent
> it
->max_descent
)
25179 it
->ascent
+= it
->descent
- it
->max_descent
;
25180 it
->descent
= it
->max_descent
;
25182 if (it
->ascent
> it
->max_ascent
)
25184 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25185 it
->ascent
= it
->max_ascent
;
25187 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25188 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25189 extra_line_spacing
= 0;
25192 /* If this is a space inside a region of text with
25193 `space-width' property, change its width. */
25194 stretched_p
= it
->char_to_display
== ' ' && !NILP (it
->space_width
);
25196 it
->pixel_width
*= XFLOATINT (it
->space_width
);
25198 /* If face has a box, add the box thickness to the character
25199 height. If character has a box line to the left and/or
25200 right, add the box line width to the character's width. */
25201 if (face
->box
!= FACE_NO_BOX
)
25203 int thick
= face
->box_line_width
;
25207 it
->ascent
+= thick
;
25208 it
->descent
+= thick
;
25213 if (it
->start_of_box_run_p
)
25214 it
->pixel_width
+= thick
;
25215 if (it
->end_of_box_run_p
)
25216 it
->pixel_width
+= thick
;
25219 /* If face has an overline, add the height of the overline
25220 (1 pixel) and a 1 pixel margin to the character height. */
25221 if (face
->overline_p
)
25222 it
->ascent
+= overline_margin
;
25224 if (it
->constrain_row_ascent_descent_p
)
25226 if (it
->ascent
> it
->max_ascent
)
25227 it
->ascent
= it
->max_ascent
;
25228 if (it
->descent
> it
->max_descent
)
25229 it
->descent
= it
->max_descent
;
25232 take_vertical_position_into_account (it
);
25234 /* If we have to actually produce glyphs, do it. */
25239 /* Translate a space with a `space-width' property
25240 into a stretch glyph. */
25241 int ascent
= (((it
->ascent
+ it
->descent
) * FONT_BASE (font
))
25242 / FONT_HEIGHT (font
));
25243 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25244 it
->ascent
+ it
->descent
, ascent
);
25249 /* If characters with lbearing or rbearing are displayed
25250 in this line, record that fact in a flag of the
25251 glyph row. This is used to optimize X output code. */
25252 if (pcm
&& (pcm
->lbearing
< 0 || pcm
->rbearing
> pcm
->width
))
25253 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25255 if (! stretched_p
&& it
->pixel_width
== 0)
25256 /* We assure that all visible glyphs have at least 1-pixel
25258 it
->pixel_width
= 1;
25260 else if (it
->char_to_display
== '\n')
25262 /* A newline has no width, but we need the height of the
25263 line. But if previous part of the line sets a height,
25264 don't increase that height */
25266 Lisp_Object height
;
25267 Lisp_Object total_height
= Qnil
;
25269 it
->override_ascent
= -1;
25270 it
->pixel_width
= 0;
25273 height
= get_it_property (it
, Qline_height
);
25274 /* Split (line-height total-height) list */
25276 && CONSP (XCDR (height
))
25277 && NILP (XCDR (XCDR (height
))))
25279 total_height
= XCAR (XCDR (height
));
25280 height
= XCAR (height
);
25282 height
= calc_line_height_property (it
, height
, font
, boff
, 1);
25284 if (it
->override_ascent
>= 0)
25286 it
->ascent
= it
->override_ascent
;
25287 it
->descent
= it
->override_descent
;
25288 boff
= it
->override_boff
;
25292 it
->ascent
= FONT_BASE (font
) + boff
;
25293 it
->descent
= FONT_DESCENT (font
) - boff
;
25296 if (EQ (height
, Qt
))
25298 if (it
->descent
> it
->max_descent
)
25300 it
->ascent
+= it
->descent
- it
->max_descent
;
25301 it
->descent
= it
->max_descent
;
25303 if (it
->ascent
> it
->max_ascent
)
25305 it
->descent
= min (it
->max_descent
, it
->descent
+ it
->ascent
- it
->max_ascent
);
25306 it
->ascent
= it
->max_ascent
;
25308 it
->phys_ascent
= min (it
->phys_ascent
, it
->ascent
);
25309 it
->phys_descent
= min (it
->phys_descent
, it
->descent
);
25310 it
->constrain_row_ascent_descent_p
= 1;
25311 extra_line_spacing
= 0;
25315 Lisp_Object spacing
;
25317 it
->phys_ascent
= it
->ascent
;
25318 it
->phys_descent
= it
->descent
;
25320 if ((it
->max_ascent
> 0 || it
->max_descent
> 0)
25321 && face
->box
!= FACE_NO_BOX
25322 && face
->box_line_width
> 0)
25324 it
->ascent
+= face
->box_line_width
;
25325 it
->descent
+= face
->box_line_width
;
25328 && XINT (height
) > it
->ascent
+ it
->descent
)
25329 it
->ascent
= XINT (height
) - it
->descent
;
25331 if (!NILP (total_height
))
25332 spacing
= calc_line_height_property (it
, total_height
, font
, boff
, 0);
25335 spacing
= get_it_property (it
, Qline_spacing
);
25336 spacing
= calc_line_height_property (it
, spacing
, font
, boff
, 0);
25338 if (INTEGERP (spacing
))
25340 extra_line_spacing
= XINT (spacing
);
25341 if (!NILP (total_height
))
25342 extra_line_spacing
-= (it
->phys_ascent
+ it
->phys_descent
);
25346 else /* i.e. (it->char_to_display == '\t') */
25348 if (font
->space_width
> 0)
25350 int tab_width
= it
->tab_width
* font
->space_width
;
25351 int x
= it
->current_x
+ it
->continuation_lines_width
;
25352 int next_tab_x
= ((1 + x
+ tab_width
- 1) / tab_width
) * tab_width
;
25354 /* If the distance from the current position to the next tab
25355 stop is less than a space character width, use the
25356 tab stop after that. */
25357 if (next_tab_x
- x
< font
->space_width
)
25358 next_tab_x
+= tab_width
;
25360 it
->pixel_width
= next_tab_x
- x
;
25362 it
->ascent
= it
->phys_ascent
= FONT_BASE (font
) + boff
;
25363 it
->descent
= it
->phys_descent
= FONT_DESCENT (font
) - boff
;
25367 append_stretch_glyph (it
, it
->object
, it
->pixel_width
,
25368 it
->ascent
+ it
->descent
, it
->ascent
);
25373 it
->pixel_width
= 0;
25378 else if (it
->what
== IT_COMPOSITION
&& it
->cmp_it
.ch
< 0)
25380 /* A static composition.
25382 Note: A composition is represented as one glyph in the
25383 glyph matrix. There are no padding glyphs.
25385 Important note: pixel_width, ascent, and descent are the
25386 values of what is drawn by draw_glyphs (i.e. the values of
25387 the overall glyphs composed). */
25388 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25389 int boff
; /* baseline offset */
25390 struct composition
*cmp
= composition_table
[it
->cmp_it
.id
];
25391 int glyph_len
= cmp
->glyph_len
;
25392 struct font
*font
= face
->font
;
25396 /* If we have not yet calculated pixel size data of glyphs of
25397 the composition for the current face font, calculate them
25398 now. Theoretically, we have to check all fonts for the
25399 glyphs, but that requires much time and memory space. So,
25400 here we check only the font of the first glyph. This may
25401 lead to incorrect display, but it's very rare, and C-l
25402 (recenter-top-bottom) can correct the display anyway. */
25403 if (! cmp
->font
|| cmp
->font
!= font
)
25405 /* Ascent and descent of the font of the first character
25406 of this composition (adjusted by baseline offset).
25407 Ascent and descent of overall glyphs should not be less
25408 than these, respectively. */
25409 int font_ascent
, font_descent
, font_height
;
25410 /* Bounding box of the overall glyphs. */
25411 int leftmost
, rightmost
, lowest
, highest
;
25412 int lbearing
, rbearing
;
25413 int i
, width
, ascent
, descent
;
25414 int left_padded
= 0, right_padded
= 0;
25415 int c
IF_LINT (= 0); /* cmp->glyph_len can't be zero; see Bug#8512 */
25417 struct font_metrics
*pcm
;
25418 int font_not_found_p
;
25421 for (glyph_len
= cmp
->glyph_len
; glyph_len
> 0; glyph_len
--)
25422 if ((c
= COMPOSITION_GLYPH (cmp
, glyph_len
- 1)) != '\t')
25424 if (glyph_len
< cmp
->glyph_len
)
25426 for (i
= 0; i
< glyph_len
; i
++)
25428 if ((c
= COMPOSITION_GLYPH (cmp
, i
)) != '\t')
25430 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25435 pos
= (STRINGP (it
->string
) ? IT_STRING_CHARPOS (*it
)
25436 : IT_CHARPOS (*it
));
25437 /* If no suitable font is found, use the default font. */
25438 font_not_found_p
= font
== NULL
;
25439 if (font_not_found_p
)
25441 face
= face
->ascii_face
;
25444 boff
= font
->baseline_offset
;
25445 if (font
->vertical_centering
)
25446 boff
= VCENTER_BASELINE_OFFSET (font
, it
->f
) - boff
;
25447 font_ascent
= FONT_BASE (font
) + boff
;
25448 font_descent
= FONT_DESCENT (font
) - boff
;
25449 font_height
= FONT_HEIGHT (font
);
25454 if (! font_not_found_p
)
25456 get_char_face_and_encoding (it
->f
, c
, it
->face_id
,
25458 pcm
= get_per_char_metric (font
, &char2b
);
25461 /* Initialize the bounding box. */
25464 width
= cmp
->glyph_len
> 0 ? pcm
->width
: 0;
25465 ascent
= pcm
->ascent
;
25466 descent
= pcm
->descent
;
25467 lbearing
= pcm
->lbearing
;
25468 rbearing
= pcm
->rbearing
;
25472 width
= cmp
->glyph_len
> 0 ? font
->space_width
: 0;
25473 ascent
= FONT_BASE (font
);
25474 descent
= FONT_DESCENT (font
);
25481 lowest
= - descent
+ boff
;
25482 highest
= ascent
+ boff
;
25484 if (! font_not_found_p
25485 && font
->default_ascent
25486 && CHAR_TABLE_P (Vuse_default_ascent
)
25487 && !NILP (Faref (Vuse_default_ascent
,
25488 make_number (it
->char_to_display
))))
25489 highest
= font
->default_ascent
+ boff
;
25491 /* Draw the first glyph at the normal position. It may be
25492 shifted to right later if some other glyphs are drawn
25494 cmp
->offsets
[i
* 2] = 0;
25495 cmp
->offsets
[i
* 2 + 1] = boff
;
25496 cmp
->lbearing
= lbearing
;
25497 cmp
->rbearing
= rbearing
;
25499 /* Set cmp->offsets for the remaining glyphs. */
25500 for (i
++; i
< glyph_len
; i
++)
25502 int left
, right
, btm
, top
;
25503 int ch
= COMPOSITION_GLYPH (cmp
, i
);
25505 struct face
*this_face
;
25509 face_id
= FACE_FOR_CHAR (it
->f
, face
, ch
, pos
, it
->string
);
25510 this_face
= FACE_FROM_ID (it
->f
, face_id
);
25511 font
= this_face
->font
;
25517 get_char_face_and_encoding (it
->f
, ch
, face_id
,
25519 pcm
= get_per_char_metric (font
, &char2b
);
25522 cmp
->offsets
[i
* 2] = cmp
->offsets
[i
* 2 + 1] = 0;
25525 width
= pcm
->width
;
25526 ascent
= pcm
->ascent
;
25527 descent
= pcm
->descent
;
25528 lbearing
= pcm
->lbearing
;
25529 rbearing
= pcm
->rbearing
;
25530 if (cmp
->method
!= COMPOSITION_WITH_RULE_ALTCHARS
)
25532 /* Relative composition with or without
25533 alternate chars. */
25534 left
= (leftmost
+ rightmost
- width
) / 2;
25535 btm
= - descent
+ boff
;
25536 if (font
->relative_compose
25537 && (! CHAR_TABLE_P (Vignore_relative_composition
)
25538 || NILP (Faref (Vignore_relative_composition
,
25539 make_number (ch
)))))
25542 if (- descent
>= font
->relative_compose
)
25543 /* One extra pixel between two glyphs. */
25545 else if (ascent
<= 0)
25546 /* One extra pixel between two glyphs. */
25547 btm
= lowest
- 1 - ascent
- descent
;
25552 /* A composition rule is specified by an integer
25553 value that encodes global and new reference
25554 points (GREF and NREF). GREF and NREF are
25555 specified by numbers as below:
25557 0---1---2 -- ascent
25561 9--10--11 -- center
25563 ---3---4---5--- baseline
25565 6---7---8 -- descent
25567 int rule
= COMPOSITION_RULE (cmp
, i
);
25568 int gref
, nref
, grefx
, grefy
, nrefx
, nrefy
, xoff
, yoff
;
25570 COMPOSITION_DECODE_RULE (rule
, gref
, nref
, xoff
, yoff
);
25571 grefx
= gref
% 3, nrefx
= nref
% 3;
25572 grefy
= gref
/ 3, nrefy
= nref
/ 3;
25574 xoff
= font_height
* (xoff
- 128) / 256;
25576 yoff
= font_height
* (yoff
- 128) / 256;
25579 + grefx
* (rightmost
- leftmost
) / 2
25580 - nrefx
* width
/ 2
25583 btm
= ((grefy
== 0 ? highest
25585 : grefy
== 2 ? lowest
25586 : (highest
+ lowest
) / 2)
25587 - (nrefy
== 0 ? ascent
+ descent
25588 : nrefy
== 1 ? descent
- boff
25590 : (ascent
+ descent
) / 2)
25594 cmp
->offsets
[i
* 2] = left
;
25595 cmp
->offsets
[i
* 2 + 1] = btm
+ descent
;
25597 /* Update the bounding box of the overall glyphs. */
25600 right
= left
+ width
;
25601 if (left
< leftmost
)
25603 if (right
> rightmost
)
25606 top
= btm
+ descent
+ ascent
;
25612 if (cmp
->lbearing
> left
+ lbearing
)
25613 cmp
->lbearing
= left
+ lbearing
;
25614 if (cmp
->rbearing
< left
+ rbearing
)
25615 cmp
->rbearing
= left
+ rbearing
;
25619 /* If there are glyphs whose x-offsets are negative,
25620 shift all glyphs to the right and make all x-offsets
25624 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25625 cmp
->offsets
[i
* 2] -= leftmost
;
25626 rightmost
-= leftmost
;
25627 cmp
->lbearing
-= leftmost
;
25628 cmp
->rbearing
-= leftmost
;
25631 if (left_padded
&& cmp
->lbearing
< 0)
25633 for (i
= 0; i
< cmp
->glyph_len
; i
++)
25634 cmp
->offsets
[i
* 2] -= cmp
->lbearing
;
25635 rightmost
-= cmp
->lbearing
;
25636 cmp
->rbearing
-= cmp
->lbearing
;
25639 if (right_padded
&& rightmost
< cmp
->rbearing
)
25641 rightmost
= cmp
->rbearing
;
25644 cmp
->pixel_width
= rightmost
;
25645 cmp
->ascent
= highest
;
25646 cmp
->descent
= - lowest
;
25647 if (cmp
->ascent
< font_ascent
)
25648 cmp
->ascent
= font_ascent
;
25649 if (cmp
->descent
< font_descent
)
25650 cmp
->descent
= font_descent
;
25654 && (cmp
->lbearing
< 0
25655 || cmp
->rbearing
> cmp
->pixel_width
))
25656 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25658 it
->pixel_width
= cmp
->pixel_width
;
25659 it
->ascent
= it
->phys_ascent
= cmp
->ascent
;
25660 it
->descent
= it
->phys_descent
= cmp
->descent
;
25661 if (face
->box
!= FACE_NO_BOX
)
25663 int thick
= face
->box_line_width
;
25667 it
->ascent
+= thick
;
25668 it
->descent
+= thick
;
25673 if (it
->start_of_box_run_p
)
25674 it
->pixel_width
+= thick
;
25675 if (it
->end_of_box_run_p
)
25676 it
->pixel_width
+= thick
;
25679 /* If face has an overline, add the height of the overline
25680 (1 pixel) and a 1 pixel margin to the character height. */
25681 if (face
->overline_p
)
25682 it
->ascent
+= overline_margin
;
25684 take_vertical_position_into_account (it
);
25685 if (it
->ascent
< 0)
25687 if (it
->descent
< 0)
25690 if (it
->glyph_row
&& cmp
->glyph_len
> 0)
25691 append_composite_glyph (it
);
25693 else if (it
->what
== IT_COMPOSITION
)
25695 /* A dynamic (automatic) composition. */
25696 struct face
*face
= FACE_FROM_ID (it
->f
, it
->face_id
);
25697 Lisp_Object gstring
;
25698 struct font_metrics metrics
;
25702 gstring
= composition_gstring_from_id (it
->cmp_it
.id
);
25704 = composition_gstring_width (gstring
, it
->cmp_it
.from
, it
->cmp_it
.to
,
25707 && (metrics
.lbearing
< 0 || metrics
.rbearing
> metrics
.width
))
25708 it
->glyph_row
->contains_overlapping_glyphs_p
= 1;
25709 it
->ascent
= it
->phys_ascent
= metrics
.ascent
;
25710 it
->descent
= it
->phys_descent
= metrics
.descent
;
25711 if (face
->box
!= FACE_NO_BOX
)
25713 int thick
= face
->box_line_width
;
25717 it
->ascent
+= thick
;
25718 it
->descent
+= thick
;
25723 if (it
->start_of_box_run_p
)
25724 it
->pixel_width
+= thick
;
25725 if (it
->end_of_box_run_p
)
25726 it
->pixel_width
+= thick
;
25728 /* If face has an overline, add the height of the overline
25729 (1 pixel) and a 1 pixel margin to the character height. */
25730 if (face
->overline_p
)
25731 it
->ascent
+= overline_margin
;
25732 take_vertical_position_into_account (it
);
25733 if (it
->ascent
< 0)
25735 if (it
->descent
< 0)
25739 append_composite_glyph (it
);
25741 else if (it
->what
== IT_GLYPHLESS
)
25742 produce_glyphless_glyph (it
, 0, Qnil
);
25743 else if (it
->what
== IT_IMAGE
)
25744 produce_image_glyph (it
);
25745 else if (it
->what
== IT_STRETCH
)
25746 produce_stretch_glyph (it
);
25749 /* Accumulate dimensions. Note: can't assume that it->descent > 0
25750 because this isn't true for images with `:ascent 100'. */
25751 eassert (it
->ascent
>= 0 && it
->descent
>= 0);
25752 if (it
->area
== TEXT_AREA
)
25753 it
->current_x
+= it
->pixel_width
;
25755 if (extra_line_spacing
> 0)
25757 it
->descent
+= extra_line_spacing
;
25758 if (extra_line_spacing
> it
->max_extra_line_spacing
)
25759 it
->max_extra_line_spacing
= extra_line_spacing
;
25762 it
->max_ascent
= max (it
->max_ascent
, it
->ascent
);
25763 it
->max_descent
= max (it
->max_descent
, it
->descent
);
25764 it
->max_phys_ascent
= max (it
->max_phys_ascent
, it
->phys_ascent
);
25765 it
->max_phys_descent
= max (it
->max_phys_descent
, it
->phys_descent
);
25769 Output LEN glyphs starting at START at the nominal cursor position.
25770 Advance the nominal cursor over the text. The global variable
25771 updated_window contains the window being updated, updated_row is
25772 the glyph row being updated, and updated_area is the area of that
25773 row being updated. */
25776 x_write_glyphs (struct glyph
*start
, int len
)
25778 int x
, hpos
, chpos
= updated_window
->phys_cursor
.hpos
;
25780 eassert (updated_window
&& updated_row
);
25781 /* When the window is hscrolled, cursor hpos can legitimately be out
25782 of bounds, but we draw the cursor at the corresponding window
25783 margin in that case. */
25784 if (!updated_row
->reversed_p
&& chpos
< 0)
25786 if (updated_row
->reversed_p
&& chpos
>= updated_row
->used
[TEXT_AREA
])
25787 chpos
= updated_row
->used
[TEXT_AREA
] - 1;
25791 /* Write glyphs. */
25793 hpos
= start
- updated_row
->glyphs
[updated_area
];
25794 x
= draw_glyphs (updated_window
, output_cursor
.x
,
25795 updated_row
, updated_area
,
25797 DRAW_NORMAL_TEXT
, 0);
25799 /* Invalidate old phys cursor if the glyph at its hpos is redrawn. */
25800 if (updated_area
== TEXT_AREA
25801 && updated_window
->phys_cursor_on_p
25802 && updated_window
->phys_cursor
.vpos
== output_cursor
.vpos
25804 && chpos
< hpos
+ len
)
25805 updated_window
->phys_cursor_on_p
= 0;
25809 /* Advance the output cursor. */
25810 output_cursor
.hpos
+= len
;
25811 output_cursor
.x
= x
;
25816 Insert LEN glyphs from START at the nominal cursor position. */
25819 x_insert_glyphs (struct glyph
*start
, int len
)
25823 int line_height
, shift_by_width
, shifted_region_width
;
25824 struct glyph_row
*row
;
25825 struct glyph
*glyph
;
25826 int frame_x
, frame_y
;
25829 eassert (updated_window
&& updated_row
);
25831 w
= updated_window
;
25832 f
= XFRAME (WINDOW_FRAME (w
));
25834 /* Get the height of the line we are in. */
25836 line_height
= row
->height
;
25838 /* Get the width of the glyphs to insert. */
25839 shift_by_width
= 0;
25840 for (glyph
= start
; glyph
< start
+ len
; ++glyph
)
25841 shift_by_width
+= glyph
->pixel_width
;
25843 /* Get the width of the region to shift right. */
25844 shifted_region_width
= (window_box_width (w
, updated_area
)
25849 frame_x
= window_box_left (w
, updated_area
) + output_cursor
.x
;
25850 frame_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, output_cursor
.y
);
25852 FRAME_RIF (f
)->shift_glyphs_for_insert (f
, frame_x
, frame_y
, shifted_region_width
,
25853 line_height
, shift_by_width
);
25855 /* Write the glyphs. */
25856 hpos
= start
- row
->glyphs
[updated_area
];
25857 draw_glyphs (w
, output_cursor
.x
, row
, updated_area
,
25859 DRAW_NORMAL_TEXT
, 0);
25861 /* Advance the output cursor. */
25862 output_cursor
.hpos
+= len
;
25863 output_cursor
.x
+= shift_by_width
;
25869 Erase the current text line from the nominal cursor position
25870 (inclusive) to pixel column TO_X (exclusive). The idea is that
25871 everything from TO_X onward is already erased.
25873 TO_X is a pixel position relative to updated_area of
25874 updated_window. TO_X == -1 means clear to the end of this area. */
25877 x_clear_end_of_line (int to_x
)
25880 struct window
*w
= updated_window
;
25881 int max_x
, min_y
, max_y
;
25882 int from_x
, from_y
, to_y
;
25884 eassert (updated_window
&& updated_row
);
25885 f
= XFRAME (w
->frame
);
25887 if (updated_row
->full_width_p
)
25888 max_x
= WINDOW_TOTAL_WIDTH (w
);
25890 max_x
= window_box_width (w
, updated_area
);
25891 max_y
= window_text_bottom_y (w
);
25893 /* TO_X == 0 means don't do anything. TO_X < 0 means clear to end
25894 of window. For TO_X > 0, truncate to end of drawing area. */
25900 to_x
= min (to_x
, max_x
);
25902 to_y
= min (max_y
, output_cursor
.y
+ updated_row
->height
);
25904 /* Notice if the cursor will be cleared by this operation. */
25905 if (!updated_row
->full_width_p
)
25906 notice_overwritten_cursor (w
, updated_area
,
25907 output_cursor
.x
, -1,
25909 MATRIX_ROW_BOTTOM_Y (updated_row
));
25911 from_x
= output_cursor
.x
;
25913 /* Translate to frame coordinates. */
25914 if (updated_row
->full_width_p
)
25916 from_x
= WINDOW_TO_FRAME_PIXEL_X (w
, from_x
);
25917 to_x
= WINDOW_TO_FRAME_PIXEL_X (w
, to_x
);
25921 int area_left
= window_box_left (w
, updated_area
);
25922 from_x
+= area_left
;
25926 min_y
= WINDOW_HEADER_LINE_HEIGHT (w
);
25927 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (min_y
, output_cursor
.y
));
25928 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, to_y
);
25930 /* Prevent inadvertently clearing to end of the X window. */
25931 if (to_x
> from_x
&& to_y
> from_y
)
25934 FRAME_RIF (f
)->clear_frame_area (f
, from_x
, from_y
,
25935 to_x
- from_x
, to_y
- from_y
);
25940 #endif /* HAVE_WINDOW_SYSTEM */
25944 /***********************************************************************
25946 ***********************************************************************/
25948 /* Value is the internal representation of the specified cursor type
25949 ARG. If type is BAR_CURSOR, return in *WIDTH the specified width
25950 of the bar cursor. */
25952 static enum text_cursor_kinds
25953 get_specified_cursor_type (Lisp_Object arg
, int *width
)
25955 enum text_cursor_kinds type
;
25960 if (EQ (arg
, Qbox
))
25961 return FILLED_BOX_CURSOR
;
25963 if (EQ (arg
, Qhollow
))
25964 return HOLLOW_BOX_CURSOR
;
25966 if (EQ (arg
, Qbar
))
25973 && EQ (XCAR (arg
), Qbar
)
25974 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25976 *width
= XINT (XCDR (arg
));
25980 if (EQ (arg
, Qhbar
))
25983 return HBAR_CURSOR
;
25987 && EQ (XCAR (arg
), Qhbar
)
25988 && RANGED_INTEGERP (0, XCDR (arg
), INT_MAX
))
25990 *width
= XINT (XCDR (arg
));
25991 return HBAR_CURSOR
;
25994 /* Treat anything unknown as "hollow box cursor".
25995 It was bad to signal an error; people have trouble fixing
25996 .Xdefaults with Emacs, when it has something bad in it. */
25997 type
= HOLLOW_BOX_CURSOR
;
26002 /* Set the default cursor types for specified frame. */
26004 set_frame_cursor_types (struct frame
*f
, Lisp_Object arg
)
26009 FRAME_DESIRED_CURSOR (f
) = get_specified_cursor_type (arg
, &width
);
26010 FRAME_CURSOR_WIDTH (f
) = width
;
26012 /* By default, set up the blink-off state depending on the on-state. */
26014 tem
= Fassoc (arg
, Vblink_cursor_alist
);
26017 FRAME_BLINK_OFF_CURSOR (f
)
26018 = get_specified_cursor_type (XCDR (tem
), &width
);
26019 FRAME_BLINK_OFF_CURSOR_WIDTH (f
) = width
;
26022 FRAME_BLINK_OFF_CURSOR (f
) = DEFAULT_CURSOR
;
26026 #ifdef HAVE_WINDOW_SYSTEM
26028 /* Return the cursor we want to be displayed in window W. Return
26029 width of bar/hbar cursor through WIDTH arg. Return with
26030 ACTIVE_CURSOR arg set to 1 if cursor in window W is `active'
26031 (i.e. if the `system caret' should track this cursor).
26033 In a mini-buffer window, we want the cursor only to appear if we
26034 are reading input from this window. For the selected window, we
26035 want the cursor type given by the frame parameter or buffer local
26036 setting of cursor-type. If explicitly marked off, draw no cursor.
26037 In all other cases, we want a hollow box cursor. */
26039 static enum text_cursor_kinds
26040 get_window_cursor_type (struct window
*w
, struct glyph
*glyph
, int *width
,
26041 int *active_cursor
)
26043 struct frame
*f
= XFRAME (w
->frame
);
26044 struct buffer
*b
= XBUFFER (w
->contents
);
26045 int cursor_type
= DEFAULT_CURSOR
;
26046 Lisp_Object alt_cursor
;
26047 int non_selected
= 0;
26049 *active_cursor
= 1;
26052 if (cursor_in_echo_area
26053 && FRAME_HAS_MINIBUF_P (f
)
26054 && EQ (FRAME_MINIBUF_WINDOW (f
), echo_area_window
))
26056 if (w
== XWINDOW (echo_area_window
))
26058 if (EQ (BVAR (b
, cursor_type
), Qt
) || NILP (BVAR (b
, cursor_type
)))
26060 *width
= FRAME_CURSOR_WIDTH (f
);
26061 return FRAME_DESIRED_CURSOR (f
);
26064 return get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26067 *active_cursor
= 0;
26071 /* Detect a nonselected window or nonselected frame. */
26072 else if (w
!= XWINDOW (f
->selected_window
)
26073 || f
!= FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
)
26075 *active_cursor
= 0;
26077 if (MINI_WINDOW_P (w
) && minibuf_level
== 0)
26083 /* Never display a cursor in a window in which cursor-type is nil. */
26084 if (NILP (BVAR (b
, cursor_type
)))
26087 /* Get the normal cursor type for this window. */
26088 if (EQ (BVAR (b
, cursor_type
), Qt
))
26090 cursor_type
= FRAME_DESIRED_CURSOR (f
);
26091 *width
= FRAME_CURSOR_WIDTH (f
);
26094 cursor_type
= get_specified_cursor_type (BVAR (b
, cursor_type
), width
);
26096 /* Use cursor-in-non-selected-windows instead
26097 for non-selected window or frame. */
26100 alt_cursor
= BVAR (b
, cursor_in_non_selected_windows
);
26101 if (!EQ (Qt
, alt_cursor
))
26102 return get_specified_cursor_type (alt_cursor
, width
);
26103 /* t means modify the normal cursor type. */
26104 if (cursor_type
== FILLED_BOX_CURSOR
)
26105 cursor_type
= HOLLOW_BOX_CURSOR
;
26106 else if (cursor_type
== BAR_CURSOR
&& *width
> 1)
26108 return cursor_type
;
26111 /* Use normal cursor if not blinked off. */
26112 if (!w
->cursor_off_p
)
26114 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
26116 if (cursor_type
== FILLED_BOX_CURSOR
)
26118 /* Using a block cursor on large images can be very annoying.
26119 So use a hollow cursor for "large" images.
26120 If image is not transparent (no mask), also use hollow cursor. */
26121 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
26122 if (img
!= NULL
&& IMAGEP (img
->spec
))
26124 /* Arbitrarily, interpret "Large" as >32x32 and >NxN
26125 where N = size of default frame font size.
26126 This should cover most of the "tiny" icons people may use. */
26128 || img
->width
> max (32, WINDOW_FRAME_COLUMN_WIDTH (w
))
26129 || img
->height
> max (32, WINDOW_FRAME_LINE_HEIGHT (w
)))
26130 cursor_type
= HOLLOW_BOX_CURSOR
;
26133 else if (cursor_type
!= NO_CURSOR
)
26135 /* Display current only supports BOX and HOLLOW cursors for images.
26136 So for now, unconditionally use a HOLLOW cursor when cursor is
26137 not a solid box cursor. */
26138 cursor_type
= HOLLOW_BOX_CURSOR
;
26141 return cursor_type
;
26144 /* Cursor is blinked off, so determine how to "toggle" it. */
26146 /* First look for an entry matching the buffer's cursor-type in blink-cursor-alist. */
26147 if ((alt_cursor
= Fassoc (BVAR (b
, cursor_type
), Vblink_cursor_alist
), !NILP (alt_cursor
)))
26148 return get_specified_cursor_type (XCDR (alt_cursor
), width
);
26150 /* Then see if frame has specified a specific blink off cursor type. */
26151 if (FRAME_BLINK_OFF_CURSOR (f
) != DEFAULT_CURSOR
)
26153 *width
= FRAME_BLINK_OFF_CURSOR_WIDTH (f
);
26154 return FRAME_BLINK_OFF_CURSOR (f
);
26158 /* Some people liked having a permanently visible blinking cursor,
26159 while others had very strong opinions against it. So it was
26160 decided to remove it. KFS 2003-09-03 */
26162 /* Finally perform built-in cursor blinking:
26163 filled box <-> hollow box
26164 wide [h]bar <-> narrow [h]bar
26165 narrow [h]bar <-> no cursor
26166 other type <-> no cursor */
26168 if (cursor_type
== FILLED_BOX_CURSOR
)
26169 return HOLLOW_BOX_CURSOR
;
26171 if ((cursor_type
== BAR_CURSOR
|| cursor_type
== HBAR_CURSOR
) && *width
> 1)
26174 return cursor_type
;
26182 /* Notice when the text cursor of window W has been completely
26183 overwritten by a drawing operation that outputs glyphs in AREA
26184 starting at X0 and ending at X1 in the line starting at Y0 and
26185 ending at Y1. X coordinates are area-relative. X1 < 0 means all
26186 the rest of the line after X0 has been written. Y coordinates
26187 are window-relative. */
26190 notice_overwritten_cursor (struct window
*w
, enum glyph_row_area area
,
26191 int x0
, int x1
, int y0
, int y1
)
26193 int cx0
, cx1
, cy0
, cy1
;
26194 struct glyph_row
*row
;
26196 if (!w
->phys_cursor_on_p
)
26198 if (area
!= TEXT_AREA
)
26201 if (w
->phys_cursor
.vpos
< 0
26202 || w
->phys_cursor
.vpos
>= w
->current_matrix
->nrows
26203 || (row
= w
->current_matrix
->rows
+ w
->phys_cursor
.vpos
,
26204 !(row
->enabled_p
&& MATRIX_ROW_DISPLAYS_TEXT_P (row
))))
26207 if (row
->cursor_in_fringe_p
)
26209 row
->cursor_in_fringe_p
= 0;
26210 draw_fringe_bitmap (w
, row
, row
->reversed_p
);
26211 w
->phys_cursor_on_p
= 0;
26215 cx0
= w
->phys_cursor
.x
;
26216 cx1
= cx0
+ w
->phys_cursor_width
;
26217 if (x0
> cx0
|| (x1
>= 0 && x1
< cx1
))
26220 /* The cursor image will be completely removed from the
26221 screen if the output area intersects the cursor area in
26222 y-direction. When we draw in [y0 y1[, and some part of
26223 the cursor is at y < y0, that part must have been drawn
26224 before. When scrolling, the cursor is erased before
26225 actually scrolling, so we don't come here. When not
26226 scrolling, the rows above the old cursor row must have
26227 changed, and in this case these rows must have written
26228 over the cursor image.
26230 Likewise if part of the cursor is below y1, with the
26231 exception of the cursor being in the first blank row at
26232 the buffer and window end because update_text_area
26233 doesn't draw that row. (Except when it does, but
26234 that's handled in update_text_area.) */
26236 cy0
= w
->phys_cursor
.y
;
26237 cy1
= cy0
+ w
->phys_cursor_height
;
26238 if ((y0
< cy0
|| y0
>= cy1
) && (y1
<= cy0
|| y1
>= cy1
))
26241 w
->phys_cursor_on_p
= 0;
26244 #endif /* HAVE_WINDOW_SYSTEM */
26247 /************************************************************************
26249 ************************************************************************/
26251 #ifdef HAVE_WINDOW_SYSTEM
26254 Fix the display of area AREA of overlapping row ROW in window W
26255 with respect to the overlapping part OVERLAPS. */
26258 x_fix_overlapping_area (struct window
*w
, struct glyph_row
*row
,
26259 enum glyph_row_area area
, int overlaps
)
26266 for (i
= 0; i
< row
->used
[area
];)
26268 if (row
->glyphs
[area
][i
].overlaps_vertically_p
)
26270 int start
= i
, start_x
= x
;
26274 x
+= row
->glyphs
[area
][i
].pixel_width
;
26277 while (i
< row
->used
[area
]
26278 && row
->glyphs
[area
][i
].overlaps_vertically_p
);
26280 draw_glyphs (w
, start_x
, row
, area
,
26282 DRAW_NORMAL_TEXT
, overlaps
);
26286 x
+= row
->glyphs
[area
][i
].pixel_width
;
26296 Draw the cursor glyph of window W in glyph row ROW. See the
26297 comment of draw_glyphs for the meaning of HL. */
26300 draw_phys_cursor_glyph (struct window
*w
, struct glyph_row
*row
,
26301 enum draw_glyphs_face hl
)
26303 /* If cursor hpos is out of bounds, don't draw garbage. This can
26304 happen in mini-buffer windows when switching between echo area
26305 glyphs and mini-buffer. */
26306 if ((row
->reversed_p
26307 ? (w
->phys_cursor
.hpos
>= 0)
26308 : (w
->phys_cursor
.hpos
< row
->used
[TEXT_AREA
])))
26310 int on_p
= w
->phys_cursor_on_p
;
26312 int hpos
= w
->phys_cursor
.hpos
;
26314 /* When the window is hscrolled, cursor hpos can legitimately be
26315 out of bounds, but we draw the cursor at the corresponding
26316 window margin in that case. */
26317 if (!row
->reversed_p
&& hpos
< 0)
26319 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26320 hpos
= row
->used
[TEXT_AREA
] - 1;
26322 x1
= draw_glyphs (w
, w
->phys_cursor
.x
, row
, TEXT_AREA
, hpos
, hpos
+ 1,
26324 w
->phys_cursor_on_p
= on_p
;
26326 if (hl
== DRAW_CURSOR
)
26327 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26328 /* When we erase the cursor, and ROW is overlapped by other
26329 rows, make sure that these overlapping parts of other rows
26331 else if (hl
== DRAW_NORMAL_TEXT
&& row
->overlapped_p
)
26333 w
->phys_cursor_width
= x1
- w
->phys_cursor
.x
;
26335 if (row
> w
->current_matrix
->rows
26336 && MATRIX_ROW_OVERLAPS_SUCC_P (row
- 1))
26337 x_fix_overlapping_area (w
, row
- 1, TEXT_AREA
,
26338 OVERLAPS_ERASED_CURSOR
);
26340 if (MATRIX_ROW_BOTTOM_Y (row
) < window_text_bottom_y (w
)
26341 && MATRIX_ROW_OVERLAPS_PRED_P (row
+ 1))
26342 x_fix_overlapping_area (w
, row
+ 1, TEXT_AREA
,
26343 OVERLAPS_ERASED_CURSOR
);
26350 Erase the image of a cursor of window W from the screen. */
26353 erase_phys_cursor (struct window
*w
)
26355 struct frame
*f
= XFRAME (w
->frame
);
26356 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
26357 int hpos
= w
->phys_cursor
.hpos
;
26358 int vpos
= w
->phys_cursor
.vpos
;
26359 int mouse_face_here_p
= 0;
26360 struct glyph_matrix
*active_glyphs
= w
->current_matrix
;
26361 struct glyph_row
*cursor_row
;
26362 struct glyph
*cursor_glyph
;
26363 enum draw_glyphs_face hl
;
26365 /* No cursor displayed or row invalidated => nothing to do on the
26367 if (w
->phys_cursor_type
== NO_CURSOR
)
26368 goto mark_cursor_off
;
26370 /* VPOS >= active_glyphs->nrows means that window has been resized.
26371 Don't bother to erase the cursor. */
26372 if (vpos
>= active_glyphs
->nrows
)
26373 goto mark_cursor_off
;
26375 /* If row containing cursor is marked invalid, there is nothing we
26377 cursor_row
= MATRIX_ROW (active_glyphs
, vpos
);
26378 if (!cursor_row
->enabled_p
)
26379 goto mark_cursor_off
;
26381 /* If line spacing is > 0, old cursor may only be partially visible in
26382 window after split-window. So adjust visible height. */
26383 cursor_row
->visible_height
= min (cursor_row
->visible_height
,
26384 window_text_bottom_y (w
) - cursor_row
->y
);
26386 /* If row is completely invisible, don't attempt to delete a cursor which
26387 isn't there. This can happen if cursor is at top of a window, and
26388 we switch to a buffer with a header line in that window. */
26389 if (cursor_row
->visible_height
<= 0)
26390 goto mark_cursor_off
;
26392 /* If cursor is in the fringe, erase by drawing actual bitmap there. */
26393 if (cursor_row
->cursor_in_fringe_p
)
26395 cursor_row
->cursor_in_fringe_p
= 0;
26396 draw_fringe_bitmap (w
, cursor_row
, cursor_row
->reversed_p
);
26397 goto mark_cursor_off
;
26400 /* This can happen when the new row is shorter than the old one.
26401 In this case, either draw_glyphs or clear_end_of_line
26402 should have cleared the cursor. Note that we wouldn't be
26403 able to erase the cursor in this case because we don't have a
26404 cursor glyph at hand. */
26405 if ((cursor_row
->reversed_p
26406 ? (w
->phys_cursor
.hpos
< 0)
26407 : (w
->phys_cursor
.hpos
>= cursor_row
->used
[TEXT_AREA
])))
26408 goto mark_cursor_off
;
26410 /* When the window is hscrolled, cursor hpos can legitimately be out
26411 of bounds, but we draw the cursor at the corresponding window
26412 margin in that case. */
26413 if (!cursor_row
->reversed_p
&& hpos
< 0)
26415 if (cursor_row
->reversed_p
&& hpos
>= cursor_row
->used
[TEXT_AREA
])
26416 hpos
= cursor_row
->used
[TEXT_AREA
] - 1;
26418 /* If the cursor is in the mouse face area, redisplay that when
26419 we clear the cursor. */
26420 if (! NILP (hlinfo
->mouse_face_window
)
26421 && coords_in_mouse_face_p (w
, hpos
, vpos
)
26422 /* Don't redraw the cursor's spot in mouse face if it is at the
26423 end of a line (on a newline). The cursor appears there, but
26424 mouse highlighting does not. */
26425 && cursor_row
->used
[TEXT_AREA
] > hpos
&& hpos
>= 0)
26426 mouse_face_here_p
= 1;
26428 /* Maybe clear the display under the cursor. */
26429 if (w
->phys_cursor_type
== HOLLOW_BOX_CURSOR
)
26432 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
26435 cursor_glyph
= get_phys_cursor_glyph (w
);
26436 if (cursor_glyph
== NULL
)
26437 goto mark_cursor_off
;
26439 width
= cursor_glyph
->pixel_width
;
26440 left_x
= window_box_left_offset (w
, TEXT_AREA
);
26441 x
= w
->phys_cursor
.x
;
26443 width
-= left_x
- x
;
26444 width
= min (width
, window_box_width (w
, TEXT_AREA
) - x
);
26445 y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, cursor_row
->y
));
26446 x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, max (x
, left_x
));
26449 FRAME_RIF (f
)->clear_frame_area (f
, x
, y
, width
, cursor_row
->visible_height
);
26452 /* Erase the cursor by redrawing the character underneath it. */
26453 if (mouse_face_here_p
)
26454 hl
= DRAW_MOUSE_FACE
;
26456 hl
= DRAW_NORMAL_TEXT
;
26457 draw_phys_cursor_glyph (w
, cursor_row
, hl
);
26460 w
->phys_cursor_on_p
= 0;
26461 w
->phys_cursor_type
= NO_CURSOR
;
26466 Display or clear cursor of window W. If ON is zero, clear the
26467 cursor. If it is non-zero, display the cursor. If ON is nonzero,
26468 where to put the cursor is specified by HPOS, VPOS, X and Y. */
26471 display_and_set_cursor (struct window
*w
, int on
,
26472 int hpos
, int vpos
, int x
, int y
)
26474 struct frame
*f
= XFRAME (w
->frame
);
26475 int new_cursor_type
;
26476 int new_cursor_width
;
26478 struct glyph_row
*glyph_row
;
26479 struct glyph
*glyph
;
26481 /* This is pointless on invisible frames, and dangerous on garbaged
26482 windows and frames; in the latter case, the frame or window may
26483 be in the midst of changing its size, and x and y may be off the
26485 if (! FRAME_VISIBLE_P (f
)
26486 || FRAME_GARBAGED_P (f
)
26487 || vpos
>= w
->current_matrix
->nrows
26488 || hpos
>= w
->current_matrix
->matrix_w
)
26491 /* If cursor is off and we want it off, return quickly. */
26492 if (!on
&& !w
->phys_cursor_on_p
)
26495 glyph_row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26496 /* If cursor row is not enabled, we don't really know where to
26497 display the cursor. */
26498 if (!glyph_row
->enabled_p
)
26500 w
->phys_cursor_on_p
= 0;
26505 if (!glyph_row
->exact_window_width_line_p
26506 || (0 <= hpos
&& hpos
< glyph_row
->used
[TEXT_AREA
]))
26507 glyph
= glyph_row
->glyphs
[TEXT_AREA
] + hpos
;
26509 eassert (input_blocked_p ());
26511 /* Set new_cursor_type to the cursor we want to be displayed. */
26512 new_cursor_type
= get_window_cursor_type (w
, glyph
,
26513 &new_cursor_width
, &active_cursor
);
26515 /* If cursor is currently being shown and we don't want it to be or
26516 it is in the wrong place, or the cursor type is not what we want,
26518 if (w
->phys_cursor_on_p
26520 || w
->phys_cursor
.x
!= x
26521 || w
->phys_cursor
.y
!= y
26522 || new_cursor_type
!= w
->phys_cursor_type
26523 || ((new_cursor_type
== BAR_CURSOR
|| new_cursor_type
== HBAR_CURSOR
)
26524 && new_cursor_width
!= w
->phys_cursor_width
)))
26525 erase_phys_cursor (w
);
26527 /* Don't check phys_cursor_on_p here because that flag is only set
26528 to zero in some cases where we know that the cursor has been
26529 completely erased, to avoid the extra work of erasing the cursor
26530 twice. In other words, phys_cursor_on_p can be 1 and the cursor
26531 still not be visible, or it has only been partly erased. */
26534 w
->phys_cursor_ascent
= glyph_row
->ascent
;
26535 w
->phys_cursor_height
= glyph_row
->height
;
26537 /* Set phys_cursor_.* before x_draw_.* is called because some
26538 of them may need the information. */
26539 w
->phys_cursor
.x
= x
;
26540 w
->phys_cursor
.y
= glyph_row
->y
;
26541 w
->phys_cursor
.hpos
= hpos
;
26542 w
->phys_cursor
.vpos
= vpos
;
26545 FRAME_RIF (f
)->draw_window_cursor (w
, glyph_row
, x
, y
,
26546 new_cursor_type
, new_cursor_width
,
26547 on
, active_cursor
);
26551 /* Switch the display of W's cursor on or off, according to the value
26555 update_window_cursor (struct window
*w
, int on
)
26557 /* Don't update cursor in windows whose frame is in the process
26558 of being deleted. */
26559 if (w
->current_matrix
)
26561 int hpos
= w
->phys_cursor
.hpos
;
26562 int vpos
= w
->phys_cursor
.vpos
;
26563 struct glyph_row
*row
;
26565 if (vpos
>= w
->current_matrix
->nrows
26566 || hpos
>= w
->current_matrix
->matrix_w
)
26569 row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26571 /* When the window is hscrolled, cursor hpos can legitimately be
26572 out of bounds, but we draw the cursor at the corresponding
26573 window margin in that case. */
26574 if (!row
->reversed_p
&& hpos
< 0)
26576 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26577 hpos
= row
->used
[TEXT_AREA
] - 1;
26580 display_and_set_cursor (w
, on
, hpos
, vpos
,
26581 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26587 /* Call update_window_cursor with parameter ON_P on all leaf windows
26588 in the window tree rooted at W. */
26591 update_cursor_in_window_tree (struct window
*w
, int on_p
)
26595 if (WINDOWP (w
->contents
))
26596 update_cursor_in_window_tree (XWINDOW (w
->contents
), on_p
);
26598 update_window_cursor (w
, on_p
);
26600 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
26606 Display the cursor on window W, or clear it, according to ON_P.
26607 Don't change the cursor's position. */
26610 x_update_cursor (struct frame
*f
, int on_p
)
26612 update_cursor_in_window_tree (XWINDOW (f
->root_window
), on_p
);
26617 Clear the cursor of window W to background color, and mark the
26618 cursor as not shown. This is used when the text where the cursor
26619 is about to be rewritten. */
26622 x_clear_cursor (struct window
*w
)
26624 if (FRAME_VISIBLE_P (XFRAME (w
->frame
)) && w
->phys_cursor_on_p
)
26625 update_window_cursor (w
, 0);
26628 #endif /* HAVE_WINDOW_SYSTEM */
26630 /* Implementation of draw_row_with_mouse_face for GUI sessions, GPM,
26633 draw_row_with_mouse_face (struct window
*w
, int start_x
, struct glyph_row
*row
,
26634 int start_hpos
, int end_hpos
,
26635 enum draw_glyphs_face draw
)
26637 #ifdef HAVE_WINDOW_SYSTEM
26638 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
26640 draw_glyphs (w
, start_x
, row
, TEXT_AREA
, start_hpos
, end_hpos
, draw
, 0);
26644 #if defined (HAVE_GPM) || defined (MSDOS) || defined (WINDOWSNT)
26645 tty_draw_row_with_mouse_face (w
, row
, start_hpos
, end_hpos
, draw
);
26649 /* Display the active region described by mouse_face_* according to DRAW. */
26652 show_mouse_face (Mouse_HLInfo
*hlinfo
, enum draw_glyphs_face draw
)
26654 struct window
*w
= XWINDOW (hlinfo
->mouse_face_window
);
26655 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
26657 if (/* If window is in the process of being destroyed, don't bother
26659 w
->current_matrix
!= NULL
26660 /* Don't update mouse highlight if hidden */
26661 && (draw
!= DRAW_MOUSE_FACE
|| !hlinfo
->mouse_face_hidden
)
26662 /* Recognize when we are called to operate on rows that don't exist
26663 anymore. This can happen when a window is split. */
26664 && hlinfo
->mouse_face_end_row
< w
->current_matrix
->nrows
)
26666 int phys_cursor_on_p
= w
->phys_cursor_on_p
;
26667 struct glyph_row
*row
, *first
, *last
;
26669 first
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_beg_row
);
26670 last
= MATRIX_ROW (w
->current_matrix
, hlinfo
->mouse_face_end_row
);
26672 for (row
= first
; row
<= last
&& row
->enabled_p
; ++row
)
26674 int start_hpos
, end_hpos
, start_x
;
26676 /* For all but the first row, the highlight starts at column 0. */
26679 /* R2L rows have BEG and END in reversed order, but the
26680 screen drawing geometry is always left to right. So
26681 we need to mirror the beginning and end of the
26682 highlighted area in R2L rows. */
26683 if (!row
->reversed_p
)
26685 start_hpos
= hlinfo
->mouse_face_beg_col
;
26686 start_x
= hlinfo
->mouse_face_beg_x
;
26688 else if (row
== last
)
26690 start_hpos
= hlinfo
->mouse_face_end_col
;
26691 start_x
= hlinfo
->mouse_face_end_x
;
26699 else if (row
->reversed_p
&& row
== last
)
26701 start_hpos
= hlinfo
->mouse_face_end_col
;
26702 start_x
= hlinfo
->mouse_face_end_x
;
26712 if (!row
->reversed_p
)
26713 end_hpos
= hlinfo
->mouse_face_end_col
;
26714 else if (row
== first
)
26715 end_hpos
= hlinfo
->mouse_face_beg_col
;
26718 end_hpos
= row
->used
[TEXT_AREA
];
26719 if (draw
== DRAW_NORMAL_TEXT
)
26720 row
->fill_line_p
= 1; /* Clear to end of line */
26723 else if (row
->reversed_p
&& row
== first
)
26724 end_hpos
= hlinfo
->mouse_face_beg_col
;
26727 end_hpos
= row
->used
[TEXT_AREA
];
26728 if (draw
== DRAW_NORMAL_TEXT
)
26729 row
->fill_line_p
= 1; /* Clear to end of line */
26732 if (end_hpos
> start_hpos
)
26734 draw_row_with_mouse_face (w
, start_x
, row
,
26735 start_hpos
, end_hpos
, draw
);
26738 = draw
== DRAW_MOUSE_FACE
|| draw
== DRAW_IMAGE_RAISED
;
26742 #ifdef HAVE_WINDOW_SYSTEM
26743 /* When we've written over the cursor, arrange for it to
26744 be displayed again. */
26745 if (FRAME_WINDOW_P (f
)
26746 && phys_cursor_on_p
&& !w
->phys_cursor_on_p
)
26748 int hpos
= w
->phys_cursor
.hpos
;
26750 /* When the window is hscrolled, cursor hpos can legitimately be
26751 out of bounds, but we draw the cursor at the corresponding
26752 window margin in that case. */
26753 if (!row
->reversed_p
&& hpos
< 0)
26755 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26756 hpos
= row
->used
[TEXT_AREA
] - 1;
26759 display_and_set_cursor (w
, 1, hpos
, w
->phys_cursor
.vpos
,
26760 w
->phys_cursor
.x
, w
->phys_cursor
.y
);
26763 #endif /* HAVE_WINDOW_SYSTEM */
26766 #ifdef HAVE_WINDOW_SYSTEM
26767 /* Change the mouse cursor. */
26768 if (FRAME_WINDOW_P (f
))
26770 if (draw
== DRAW_NORMAL_TEXT
26771 && !EQ (hlinfo
->mouse_face_window
, f
->tool_bar_window
))
26772 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->text_cursor
);
26773 else if (draw
== DRAW_MOUSE_FACE
)
26774 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->hand_cursor
);
26776 FRAME_RIF (f
)->define_frame_cursor (f
, FRAME_X_OUTPUT (f
)->nontext_cursor
);
26778 #endif /* HAVE_WINDOW_SYSTEM */
26782 Clear out the mouse-highlighted active region.
26783 Redraw it un-highlighted first. Value is non-zero if mouse
26784 face was actually drawn unhighlighted. */
26787 clear_mouse_face (Mouse_HLInfo
*hlinfo
)
26791 if (!hlinfo
->mouse_face_hidden
&& !NILP (hlinfo
->mouse_face_window
))
26793 show_mouse_face (hlinfo
, DRAW_NORMAL_TEXT
);
26797 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
26798 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
26799 hlinfo
->mouse_face_window
= Qnil
;
26800 hlinfo
->mouse_face_overlay
= Qnil
;
26804 /* Return non-zero if the coordinates HPOS and VPOS on windows W are
26805 within the mouse face on that window. */
26807 coords_in_mouse_face_p (struct window
*w
, int hpos
, int vpos
)
26809 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
26811 /* Quickly resolve the easy cases. */
26812 if (!(WINDOWP (hlinfo
->mouse_face_window
)
26813 && XWINDOW (hlinfo
->mouse_face_window
) == w
))
26815 if (vpos
< hlinfo
->mouse_face_beg_row
26816 || vpos
> hlinfo
->mouse_face_end_row
)
26818 if (vpos
> hlinfo
->mouse_face_beg_row
26819 && vpos
< hlinfo
->mouse_face_end_row
)
26822 if (!MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
)
26824 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26826 if (hlinfo
->mouse_face_beg_col
<= hpos
&& hpos
< hlinfo
->mouse_face_end_col
)
26829 else if ((vpos
== hlinfo
->mouse_face_beg_row
26830 && hpos
>= hlinfo
->mouse_face_beg_col
)
26831 || (vpos
== hlinfo
->mouse_face_end_row
26832 && hpos
< hlinfo
->mouse_face_end_col
))
26837 if (hlinfo
->mouse_face_beg_row
== hlinfo
->mouse_face_end_row
)
26839 if (hlinfo
->mouse_face_end_col
< hpos
&& hpos
<= hlinfo
->mouse_face_beg_col
)
26842 else if ((vpos
== hlinfo
->mouse_face_beg_row
26843 && hpos
<= hlinfo
->mouse_face_beg_col
)
26844 || (vpos
== hlinfo
->mouse_face_end_row
26845 && hpos
> hlinfo
->mouse_face_end_col
))
26853 Non-zero if physical cursor of window W is within mouse face. */
26856 cursor_in_mouse_face_p (struct window
*w
)
26858 int hpos
= w
->phys_cursor
.hpos
;
26859 int vpos
= w
->phys_cursor
.vpos
;
26860 struct glyph_row
*row
= MATRIX_ROW (w
->current_matrix
, vpos
);
26862 /* When the window is hscrolled, cursor hpos can legitimately be out
26863 of bounds, but we draw the cursor at the corresponding window
26864 margin in that case. */
26865 if (!row
->reversed_p
&& hpos
< 0)
26867 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
26868 hpos
= row
->used
[TEXT_AREA
] - 1;
26870 return coords_in_mouse_face_p (w
, hpos
, vpos
);
26875 /* Find the glyph rows START_ROW and END_ROW of window W that display
26876 characters between buffer positions START_CHARPOS and END_CHARPOS
26877 (excluding END_CHARPOS). DISP_STRING is a display string that
26878 covers these buffer positions. This is similar to
26879 row_containing_pos, but is more accurate when bidi reordering makes
26880 buffer positions change non-linearly with glyph rows. */
26882 rows_from_pos_range (struct window
*w
,
26883 ptrdiff_t start_charpos
, ptrdiff_t end_charpos
,
26884 Lisp_Object disp_string
,
26885 struct glyph_row
**start
, struct glyph_row
**end
)
26887 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
26888 int last_y
= window_text_bottom_y (w
);
26889 struct glyph_row
*row
;
26894 while (!first
->enabled_p
26895 && first
< MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
))
26898 /* Find the START row. */
26900 row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
;
26903 /* A row can potentially be the START row if the range of the
26904 characters it displays intersects the range
26905 [START_CHARPOS..END_CHARPOS). */
26906 if (! ((start_charpos
< MATRIX_ROW_START_CHARPOS (row
)
26907 && end_charpos
< MATRIX_ROW_START_CHARPOS (row
))
26908 /* See the commentary in row_containing_pos, for the
26909 explanation of the complicated way to check whether
26910 some position is beyond the end of the characters
26911 displayed by a row. */
26912 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26913 || (start_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26914 && !row
->ends_at_zv_p
26915 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
)))
26916 && (end_charpos
> MATRIX_ROW_END_CHARPOS (row
)
26917 || (end_charpos
== MATRIX_ROW_END_CHARPOS (row
)
26918 && !row
->ends_at_zv_p
26919 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row
))))))
26921 /* Found a candidate row. Now make sure at least one of the
26922 glyphs it displays has a charpos from the range
26923 [START_CHARPOS..END_CHARPOS).
26925 This is not obvious because bidi reordering could make
26926 buffer positions of a row be 1,2,3,102,101,100, and if we
26927 want to highlight characters in [50..60), we don't want
26928 this row, even though [50..60) does intersect [1..103),
26929 the range of character positions given by the row's start
26930 and end positions. */
26931 struct glyph
*g
= row
->glyphs
[TEXT_AREA
];
26932 struct glyph
*e
= g
+ row
->used
[TEXT_AREA
];
26936 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26937 && start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26938 /* A glyph that comes from DISP_STRING is by
26939 definition to be highlighted. */
26940 || EQ (g
->object
, disp_string
))
26949 /* Find the END row. */
26951 /* If the last row is partially visible, start looking for END
26952 from that row, instead of starting from FIRST. */
26953 && !(row
->enabled_p
26954 && row
->y
< last_y
&& MATRIX_ROW_BOTTOM_Y (row
) > last_y
))
26956 for ( ; row
->enabled_p
&& MATRIX_ROW_BOTTOM_Y (row
) <= last_y
; row
++)
26958 struct glyph_row
*next
= row
+ 1;
26959 ptrdiff_t next_start
= MATRIX_ROW_START_CHARPOS (next
);
26961 if (!next
->enabled_p
26962 || next
>= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
)
26963 /* The first row >= START whose range of displayed characters
26964 does NOT intersect the range [START_CHARPOS..END_CHARPOS]
26965 is the row END + 1. */
26966 || (start_charpos
< next_start
26967 && end_charpos
< next_start
)
26968 || ((start_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26969 || (start_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26970 && !next
->ends_at_zv_p
26971 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))
26972 && (end_charpos
> MATRIX_ROW_END_CHARPOS (next
)
26973 || (end_charpos
== MATRIX_ROW_END_CHARPOS (next
)
26974 && !next
->ends_at_zv_p
26975 && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (next
)))))
26982 /* If the next row's edges intersect [START_CHARPOS..END_CHARPOS],
26983 but none of the characters it displays are in the range, it is
26985 struct glyph
*g
= next
->glyphs
[TEXT_AREA
];
26986 struct glyph
*s
= g
;
26987 struct glyph
*e
= g
+ next
->used
[TEXT_AREA
];
26991 if (((BUFFERP (g
->object
) || INTEGERP (g
->object
))
26992 && ((start_charpos
<= g
->charpos
&& g
->charpos
< end_charpos
)
26993 /* If the buffer position of the first glyph in
26994 the row is equal to END_CHARPOS, it means
26995 the last character to be highlighted is the
26996 newline of ROW, and we must consider NEXT as
26998 || (((!next
->reversed_p
&& g
== s
)
26999 || (next
->reversed_p
&& g
== e
- 1))
27000 && (g
->charpos
== end_charpos
27001 /* Special case for when NEXT is an
27002 empty line at ZV. */
27003 || (g
->charpos
== -1
27004 && !row
->ends_at_zv_p
27005 && next_start
== end_charpos
)))))
27006 /* A glyph that comes from DISP_STRING is by
27007 definition to be highlighted. */
27008 || EQ (g
->object
, disp_string
))
27017 /* The first row that ends at ZV must be the last to be
27019 else if (next
->ends_at_zv_p
)
27028 /* This function sets the mouse_face_* elements of HLINFO, assuming
27029 the mouse cursor is on a glyph with buffer charpos MOUSE_CHARPOS in
27030 window WINDOW. START_CHARPOS and END_CHARPOS are buffer positions
27031 for the overlay or run of text properties specifying the mouse
27032 face. BEFORE_STRING and AFTER_STRING, if non-nil, are a
27033 before-string and after-string that must also be highlighted.
27034 DISP_STRING, if non-nil, is a display string that may cover some
27035 or all of the highlighted text. */
27038 mouse_face_from_buffer_pos (Lisp_Object window
,
27039 Mouse_HLInfo
*hlinfo
,
27040 ptrdiff_t mouse_charpos
,
27041 ptrdiff_t start_charpos
,
27042 ptrdiff_t end_charpos
,
27043 Lisp_Object before_string
,
27044 Lisp_Object after_string
,
27045 Lisp_Object disp_string
)
27047 struct window
*w
= XWINDOW (window
);
27048 struct glyph_row
*first
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27049 struct glyph_row
*r1
, *r2
;
27050 struct glyph
*glyph
, *end
;
27051 ptrdiff_t ignore
, pos
;
27054 eassert (NILP (disp_string
) || STRINGP (disp_string
));
27055 eassert (NILP (before_string
) || STRINGP (before_string
));
27056 eassert (NILP (after_string
) || STRINGP (after_string
));
27058 /* Find the rows corresponding to START_CHARPOS and END_CHARPOS. */
27059 rows_from_pos_range (w
, start_charpos
, end_charpos
, disp_string
, &r1
, &r2
);
27061 r1
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
27062 /* If the before-string or display-string contains newlines,
27063 rows_from_pos_range skips to its last row. Move back. */
27064 if (!NILP (before_string
) || !NILP (disp_string
))
27066 struct glyph_row
*prev
;
27067 while ((prev
= r1
- 1, prev
>= first
)
27068 && MATRIX_ROW_END_CHARPOS (prev
) == start_charpos
27069 && prev
->used
[TEXT_AREA
] > 0)
27071 struct glyph
*beg
= prev
->glyphs
[TEXT_AREA
];
27072 glyph
= beg
+ prev
->used
[TEXT_AREA
];
27073 while (--glyph
>= beg
&& INTEGERP (glyph
->object
));
27075 || !(EQ (glyph
->object
, before_string
)
27076 || EQ (glyph
->object
, disp_string
)))
27083 r2
= MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
27084 hlinfo
->mouse_face_past_end
= 1;
27086 else if (!NILP (after_string
))
27088 /* If the after-string has newlines, advance to its last row. */
27089 struct glyph_row
*next
;
27090 struct glyph_row
*last
27091 = MATRIX_ROW (w
->current_matrix
, XFASTINT (w
->window_end_vpos
));
27093 for (next
= r2
+ 1;
27095 && next
->used
[TEXT_AREA
] > 0
27096 && EQ (next
->glyphs
[TEXT_AREA
]->object
, after_string
);
27100 /* The rest of the display engine assumes that mouse_face_beg_row is
27101 either above mouse_face_end_row or identical to it. But with
27102 bidi-reordered continued lines, the row for START_CHARPOS could
27103 be below the row for END_CHARPOS. If so, swap the rows and store
27104 them in correct order. */
27107 struct glyph_row
*tem
= r2
;
27113 hlinfo
->mouse_face_beg_y
= r1
->y
;
27114 hlinfo
->mouse_face_beg_row
= MATRIX_ROW_VPOS (r1
, w
->current_matrix
);
27115 hlinfo
->mouse_face_end_y
= r2
->y
;
27116 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r2
, w
->current_matrix
);
27118 /* For a bidi-reordered row, the positions of BEFORE_STRING,
27119 AFTER_STRING, DISP_STRING, START_CHARPOS, and END_CHARPOS
27120 could be anywhere in the row and in any order. The strategy
27121 below is to find the leftmost and the rightmost glyph that
27122 belongs to either of these 3 strings, or whose position is
27123 between START_CHARPOS and END_CHARPOS, and highlight all the
27124 glyphs between those two. This may cover more than just the text
27125 between START_CHARPOS and END_CHARPOS if the range of characters
27126 strides the bidi level boundary, e.g. if the beginning is in R2L
27127 text while the end is in L2R text or vice versa. */
27128 if (!r1
->reversed_p
)
27130 /* This row is in a left to right paragraph. Scan it left to
27132 glyph
= r1
->glyphs
[TEXT_AREA
];
27133 end
= glyph
+ r1
->used
[TEXT_AREA
];
27136 /* Skip truncation glyphs at the start of the glyph row. */
27137 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27139 && INTEGERP (glyph
->object
)
27140 && glyph
->charpos
< 0;
27142 x
+= glyph
->pixel_width
;
27144 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27145 or DISP_STRING, and the first glyph from buffer whose
27146 position is between START_CHARPOS and END_CHARPOS. */
27148 && !INTEGERP (glyph
->object
)
27149 && !EQ (glyph
->object
, disp_string
)
27150 && !(BUFFERP (glyph
->object
)
27151 && (glyph
->charpos
>= start_charpos
27152 && glyph
->charpos
< end_charpos
));
27155 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27156 are present at buffer positions between START_CHARPOS and
27157 END_CHARPOS, or if they come from an overlay. */
27158 if (EQ (glyph
->object
, before_string
))
27160 pos
= string_buffer_position (before_string
,
27162 /* If pos == 0, it means before_string came from an
27163 overlay, not from a buffer position. */
27164 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27167 else if (EQ (glyph
->object
, after_string
))
27169 pos
= string_buffer_position (after_string
, end_charpos
);
27170 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27173 x
+= glyph
->pixel_width
;
27175 hlinfo
->mouse_face_beg_x
= x
;
27176 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27180 /* This row is in a right to left paragraph. Scan it right to
27184 end
= r1
->glyphs
[TEXT_AREA
] - 1;
27185 glyph
= end
+ r1
->used
[TEXT_AREA
];
27187 /* Skip truncation glyphs at the start of the glyph row. */
27188 if (MATRIX_ROW_DISPLAYS_TEXT_P (r1
))
27190 && INTEGERP (glyph
->object
)
27191 && glyph
->charpos
< 0;
27195 /* Scan the glyph row, looking for BEFORE_STRING, AFTER_STRING,
27196 or DISP_STRING, and the first glyph from buffer whose
27197 position is between START_CHARPOS and END_CHARPOS. */
27199 && !INTEGERP (glyph
->object
)
27200 && !EQ (glyph
->object
, disp_string
)
27201 && !(BUFFERP (glyph
->object
)
27202 && (glyph
->charpos
>= start_charpos
27203 && glyph
->charpos
< end_charpos
));
27206 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27207 are present at buffer positions between START_CHARPOS and
27208 END_CHARPOS, or if they come from an overlay. */
27209 if (EQ (glyph
->object
, before_string
))
27211 pos
= string_buffer_position (before_string
, start_charpos
);
27212 /* If pos == 0, it means before_string came from an
27213 overlay, not from a buffer position. */
27214 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27217 else if (EQ (glyph
->object
, after_string
))
27219 pos
= string_buffer_position (after_string
, end_charpos
);
27220 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27225 glyph
++; /* first glyph to the right of the highlighted area */
27226 for (g
= r1
->glyphs
[TEXT_AREA
], x
= r1
->x
; g
< glyph
; g
++)
27227 x
+= g
->pixel_width
;
27228 hlinfo
->mouse_face_beg_x
= x
;
27229 hlinfo
->mouse_face_beg_col
= glyph
- r1
->glyphs
[TEXT_AREA
];
27232 /* If the highlight ends in a different row, compute GLYPH and END
27233 for the end row. Otherwise, reuse the values computed above for
27234 the row where the highlight begins. */
27237 if (!r2
->reversed_p
)
27239 glyph
= r2
->glyphs
[TEXT_AREA
];
27240 end
= glyph
+ r2
->used
[TEXT_AREA
];
27245 end
= r2
->glyphs
[TEXT_AREA
] - 1;
27246 glyph
= end
+ r2
->used
[TEXT_AREA
];
27250 if (!r2
->reversed_p
)
27252 /* Skip truncation and continuation glyphs near the end of the
27253 row, and also blanks and stretch glyphs inserted by
27254 extend_face_to_end_of_line. */
27256 && INTEGERP ((end
- 1)->object
))
27258 /* Scan the rest of the glyph row from the end, looking for the
27259 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27260 DISP_STRING, or whose position is between START_CHARPOS
27264 && !INTEGERP (end
->object
)
27265 && !EQ (end
->object
, disp_string
)
27266 && !(BUFFERP (end
->object
)
27267 && (end
->charpos
>= start_charpos
27268 && end
->charpos
< end_charpos
));
27271 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27272 are present at buffer positions between START_CHARPOS and
27273 END_CHARPOS, or if they come from an overlay. */
27274 if (EQ (end
->object
, before_string
))
27276 pos
= string_buffer_position (before_string
, start_charpos
);
27277 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27280 else if (EQ (end
->object
, after_string
))
27282 pos
= string_buffer_position (after_string
, end_charpos
);
27283 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27287 /* Find the X coordinate of the last glyph to be highlighted. */
27288 for (; glyph
<= end
; ++glyph
)
27289 x
+= glyph
->pixel_width
;
27291 hlinfo
->mouse_face_end_x
= x
;
27292 hlinfo
->mouse_face_end_col
= glyph
- r2
->glyphs
[TEXT_AREA
];
27296 /* Skip truncation and continuation glyphs near the end of the
27297 row, and also blanks and stretch glyphs inserted by
27298 extend_face_to_end_of_line. */
27302 && INTEGERP (end
->object
))
27304 x
+= end
->pixel_width
;
27307 /* Scan the rest of the glyph row from the end, looking for the
27308 first glyph that comes from BEFORE_STRING, AFTER_STRING, or
27309 DISP_STRING, or whose position is between START_CHARPOS
27313 && !INTEGERP (end
->object
)
27314 && !EQ (end
->object
, disp_string
)
27315 && !(BUFFERP (end
->object
)
27316 && (end
->charpos
>= start_charpos
27317 && end
->charpos
< end_charpos
));
27320 /* BEFORE_STRING or AFTER_STRING are only relevant if they
27321 are present at buffer positions between START_CHARPOS and
27322 END_CHARPOS, or if they come from an overlay. */
27323 if (EQ (end
->object
, before_string
))
27325 pos
= string_buffer_position (before_string
, start_charpos
);
27326 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27329 else if (EQ (end
->object
, after_string
))
27331 pos
= string_buffer_position (after_string
, end_charpos
);
27332 if (!pos
|| (pos
>= start_charpos
&& pos
< end_charpos
))
27335 x
+= end
->pixel_width
;
27337 /* If we exited the above loop because we arrived at the last
27338 glyph of the row, and its buffer position is still not in
27339 range, it means the last character in range is the preceding
27340 newline. Bump the end column and x values to get past the
27343 && BUFFERP (end
->object
)
27344 && (end
->charpos
< start_charpos
27345 || end
->charpos
>= end_charpos
))
27347 x
+= end
->pixel_width
;
27350 hlinfo
->mouse_face_end_x
= x
;
27351 hlinfo
->mouse_face_end_col
= end
- r2
->glyphs
[TEXT_AREA
];
27354 hlinfo
->mouse_face_window
= window
;
27355 hlinfo
->mouse_face_face_id
27356 = face_at_buffer_position (w
, mouse_charpos
, 0, 0, &ignore
,
27358 !hlinfo
->mouse_face_hidden
, -1);
27359 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
27362 /* The following function is not used anymore (replaced with
27363 mouse_face_from_string_pos), but I leave it here for the time
27364 being, in case someone would. */
27366 #if 0 /* not used */
27368 /* Find the position of the glyph for position POS in OBJECT in
27369 window W's current matrix, and return in *X, *Y the pixel
27370 coordinates, and return in *HPOS, *VPOS the column/row of the glyph.
27372 RIGHT_P non-zero means return the position of the right edge of the
27373 glyph, RIGHT_P zero means return the left edge position.
27375 If no glyph for POS exists in the matrix, return the position of
27376 the glyph with the next smaller position that is in the matrix, if
27377 RIGHT_P is zero. If RIGHT_P is non-zero, and no glyph for POS
27378 exists in the matrix, return the position of the glyph with the
27379 next larger position in OBJECT.
27381 Value is non-zero if a glyph was found. */
27384 fast_find_string_pos (struct window
*w
, ptrdiff_t pos
, Lisp_Object object
,
27385 int *hpos
, int *vpos
, int *x
, int *y
, int right_p
)
27387 int yb
= window_text_bottom_y (w
);
27388 struct glyph_row
*r
;
27389 struct glyph
*best_glyph
= NULL
;
27390 struct glyph_row
*best_row
= NULL
;
27393 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27394 r
->enabled_p
&& r
->y
< yb
;
27397 struct glyph
*g
= r
->glyphs
[TEXT_AREA
];
27398 struct glyph
*e
= g
+ r
->used
[TEXT_AREA
];
27401 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27402 if (EQ (g
->object
, object
))
27404 if (g
->charpos
== pos
)
27411 else if (best_glyph
== NULL
27412 || ((eabs (g
->charpos
- pos
)
27413 < eabs (best_glyph
->charpos
- pos
))
27416 : g
->charpos
> pos
)))
27430 *hpos
= best_glyph
- best_row
->glyphs
[TEXT_AREA
];
27434 *x
+= best_glyph
->pixel_width
;
27439 *vpos
= MATRIX_ROW_VPOS (best_row
, w
->current_matrix
);
27442 return best_glyph
!= NULL
;
27444 #endif /* not used */
27446 /* Find the positions of the first and the last glyphs in window W's
27447 current matrix that occlude positions [STARTPOS..ENDPOS] in OBJECT
27448 (assumed to be a string), and return in HLINFO's mouse_face_*
27449 members the pixel and column/row coordinates of those glyphs. */
27452 mouse_face_from_string_pos (struct window
*w
, Mouse_HLInfo
*hlinfo
,
27453 Lisp_Object object
,
27454 ptrdiff_t startpos
, ptrdiff_t endpos
)
27456 int yb
= window_text_bottom_y (w
);
27457 struct glyph_row
*r
;
27458 struct glyph
*g
, *e
;
27462 /* Find the glyph row with at least one position in the range
27463 [STARTPOS..ENDPOS], and the first glyph in that row whose
27464 position belongs to that range. */
27465 for (r
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
27466 r
->enabled_p
&& r
->y
< yb
;
27469 if (!r
->reversed_p
)
27471 g
= r
->glyphs
[TEXT_AREA
];
27472 e
= g
+ r
->used
[TEXT_AREA
];
27473 for (gx
= r
->x
; g
< e
; gx
+= g
->pixel_width
, ++g
)
27474 if (EQ (g
->object
, object
)
27475 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27477 hlinfo
->mouse_face_beg_row
27478 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27479 hlinfo
->mouse_face_beg_y
= r
->y
;
27480 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27481 hlinfo
->mouse_face_beg_x
= gx
;
27490 e
= r
->glyphs
[TEXT_AREA
];
27491 g
= e
+ r
->used
[TEXT_AREA
];
27492 for ( ; g
> e
; --g
)
27493 if (EQ ((g
-1)->object
, object
)
27494 && startpos
<= (g
-1)->charpos
&& (g
-1)->charpos
<= endpos
)
27496 hlinfo
->mouse_face_beg_row
27497 = MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27498 hlinfo
->mouse_face_beg_y
= r
->y
;
27499 hlinfo
->mouse_face_beg_col
= g
- r
->glyphs
[TEXT_AREA
];
27500 for (gx
= r
->x
, g1
= r
->glyphs
[TEXT_AREA
]; g1
< g
; ++g1
)
27501 gx
+= g1
->pixel_width
;
27502 hlinfo
->mouse_face_beg_x
= gx
;
27514 /* Starting with the next row, look for the first row which does NOT
27515 include any glyphs whose positions are in the range. */
27516 for (++r
; r
->enabled_p
&& r
->y
< yb
; ++r
)
27518 g
= r
->glyphs
[TEXT_AREA
];
27519 e
= g
+ r
->used
[TEXT_AREA
];
27521 for ( ; g
< e
; ++g
)
27522 if (EQ (g
->object
, object
)
27523 && startpos
<= g
->charpos
&& g
->charpos
<= endpos
)
27532 /* The highlighted region ends on the previous row. */
27535 /* Set the end row and its vertical pixel coordinate. */
27536 hlinfo
->mouse_face_end_row
= MATRIX_ROW_VPOS (r
, w
->current_matrix
);
27537 hlinfo
->mouse_face_end_y
= r
->y
;
27539 /* Compute and set the end column and the end column's horizontal
27540 pixel coordinate. */
27541 if (!r
->reversed_p
)
27543 g
= r
->glyphs
[TEXT_AREA
];
27544 e
= g
+ r
->used
[TEXT_AREA
];
27545 for ( ; e
> g
; --e
)
27546 if (EQ ((e
-1)->object
, object
)
27547 && startpos
<= (e
-1)->charpos
&& (e
-1)->charpos
<= endpos
)
27549 hlinfo
->mouse_face_end_col
= e
- g
;
27551 for (gx
= r
->x
; g
< e
; ++g
)
27552 gx
+= g
->pixel_width
;
27553 hlinfo
->mouse_face_end_x
= gx
;
27557 e
= r
->glyphs
[TEXT_AREA
];
27558 g
= e
+ r
->used
[TEXT_AREA
];
27559 for (gx
= r
->x
; e
< g
; ++e
)
27561 if (EQ (e
->object
, object
)
27562 && startpos
<= e
->charpos
&& e
->charpos
<= endpos
)
27564 gx
+= e
->pixel_width
;
27566 hlinfo
->mouse_face_end_col
= e
- r
->glyphs
[TEXT_AREA
];
27567 hlinfo
->mouse_face_end_x
= gx
;
27571 #ifdef HAVE_WINDOW_SYSTEM
27573 /* See if position X, Y is within a hot-spot of an image. */
27576 on_hot_spot_p (Lisp_Object hot_spot
, int x
, int y
)
27578 if (!CONSP (hot_spot
))
27581 if (EQ (XCAR (hot_spot
), Qrect
))
27583 /* CDR is (Top-Left . Bottom-Right) = ((x0 . y0) . (x1 . y1)) */
27584 Lisp_Object rect
= XCDR (hot_spot
);
27588 if (!CONSP (XCAR (rect
)))
27590 if (!CONSP (XCDR (rect
)))
27592 if (!(tem
= XCAR (XCAR (rect
)), INTEGERP (tem
) && x
>= XINT (tem
)))
27594 if (!(tem
= XCDR (XCAR (rect
)), INTEGERP (tem
) && y
>= XINT (tem
)))
27596 if (!(tem
= XCAR (XCDR (rect
)), INTEGERP (tem
) && x
<= XINT (tem
)))
27598 if (!(tem
= XCDR (XCDR (rect
)), INTEGERP (tem
) && y
<= XINT (tem
)))
27602 else if (EQ (XCAR (hot_spot
), Qcircle
))
27604 /* CDR is (Center . Radius) = ((x0 . y0) . r) */
27605 Lisp_Object circ
= XCDR (hot_spot
);
27606 Lisp_Object lr
, lx0
, ly0
;
27608 && CONSP (XCAR (circ
))
27609 && (lr
= XCDR (circ
), INTEGERP (lr
) || FLOATP (lr
))
27610 && (lx0
= XCAR (XCAR (circ
)), INTEGERP (lx0
))
27611 && (ly0
= XCDR (XCAR (circ
)), INTEGERP (ly0
)))
27613 double r
= XFLOATINT (lr
);
27614 double dx
= XINT (lx0
) - x
;
27615 double dy
= XINT (ly0
) - y
;
27616 return (dx
* dx
+ dy
* dy
<= r
* r
);
27619 else if (EQ (XCAR (hot_spot
), Qpoly
))
27621 /* CDR is [x0 y0 x1 y1 x2 y2 ...x(n-1) y(n-1)] */
27622 if (VECTORP (XCDR (hot_spot
)))
27624 struct Lisp_Vector
*v
= XVECTOR (XCDR (hot_spot
));
27625 Lisp_Object
*poly
= v
->contents
;
27626 ptrdiff_t n
= v
->header
.size
;
27629 Lisp_Object lx
, ly
;
27632 /* Need an even number of coordinates, and at least 3 edges. */
27633 if (n
< 6 || n
& 1)
27636 /* Count edge segments intersecting line from (X,Y) to (X,infinity).
27637 If count is odd, we are inside polygon. Pixels on edges
27638 may or may not be included depending on actual geometry of the
27640 if ((lx
= poly
[n
-2], !INTEGERP (lx
))
27641 || (ly
= poly
[n
-1], !INTEGERP (lx
)))
27643 x0
= XINT (lx
), y0
= XINT (ly
);
27644 for (i
= 0; i
< n
; i
+= 2)
27646 int x1
= x0
, y1
= y0
;
27647 if ((lx
= poly
[i
], !INTEGERP (lx
))
27648 || (ly
= poly
[i
+1], !INTEGERP (ly
)))
27650 x0
= XINT (lx
), y0
= XINT (ly
);
27652 /* Does this segment cross the X line? */
27660 if (y
> y0
&& y
> y1
)
27662 if (y
< y0
+ ((y1
- y0
) * (x
- x0
)) / (x1
- x0
))
27672 find_hot_spot (Lisp_Object map
, int x
, int y
)
27674 while (CONSP (map
))
27676 if (CONSP (XCAR (map
))
27677 && on_hot_spot_p (XCAR (XCAR (map
)), x
, y
))
27685 DEFUN ("lookup-image-map", Flookup_image_map
, Slookup_image_map
,
27687 doc
: /* Lookup in image map MAP coordinates X and Y.
27688 An image map is an alist where each element has the format (AREA ID PLIST).
27689 An AREA is specified as either a rectangle, a circle, or a polygon:
27690 A rectangle is a cons (rect . ((x0 . y0) . (x1 . y1))) specifying the
27691 pixel coordinates of the upper left and bottom right corners.
27692 A circle is a cons (circle . ((x0 . y0) . r)) specifying the center
27693 and the radius of the circle; r may be a float or integer.
27694 A polygon is a cons (poly . [x0 y0 x1 y1 ...]) where each pair in the
27695 vector describes one corner in the polygon.
27696 Returns the alist element for the first matching AREA in MAP. */)
27697 (Lisp_Object map
, Lisp_Object x
, Lisp_Object y
)
27705 return find_hot_spot (map
,
27706 clip_to_bounds (INT_MIN
, XINT (x
), INT_MAX
),
27707 clip_to_bounds (INT_MIN
, XINT (y
), INT_MAX
));
27711 /* Display frame CURSOR, optionally using shape defined by POINTER. */
27713 define_frame_cursor1 (struct frame
*f
, Cursor cursor
, Lisp_Object pointer
)
27715 /* Do not change cursor shape while dragging mouse. */
27716 if (!NILP (do_mouse_tracking
))
27719 if (!NILP (pointer
))
27721 if (EQ (pointer
, Qarrow
))
27722 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27723 else if (EQ (pointer
, Qhand
))
27724 cursor
= FRAME_X_OUTPUT (f
)->hand_cursor
;
27725 else if (EQ (pointer
, Qtext
))
27726 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
27727 else if (EQ (pointer
, intern ("hdrag")))
27728 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
27729 #ifdef HAVE_X_WINDOWS
27730 else if (EQ (pointer
, intern ("vdrag")))
27731 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27733 else if (EQ (pointer
, intern ("hourglass")))
27734 cursor
= FRAME_X_OUTPUT (f
)->hourglass_cursor
;
27735 else if (EQ (pointer
, Qmodeline
))
27736 cursor
= FRAME_X_OUTPUT (f
)->modeline_cursor
;
27738 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27741 if (cursor
!= No_Cursor
)
27742 FRAME_RIF (f
)->define_frame_cursor (f
, cursor
);
27745 #endif /* HAVE_WINDOW_SYSTEM */
27747 /* Take proper action when mouse has moved to the mode or header line
27748 or marginal area AREA of window W, x-position X and y-position Y.
27749 X is relative to the start of the text display area of W, so the
27750 width of bitmap areas and scroll bars must be subtracted to get a
27751 position relative to the start of the mode line. */
27754 note_mode_line_or_margin_highlight (Lisp_Object window
, int x
, int y
,
27755 enum window_part area
)
27757 struct window
*w
= XWINDOW (window
);
27758 struct frame
*f
= XFRAME (w
->frame
);
27759 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
27760 #ifdef HAVE_WINDOW_SYSTEM
27761 Display_Info
*dpyinfo
;
27763 Cursor cursor
= No_Cursor
;
27764 Lisp_Object pointer
= Qnil
;
27765 int dx
, dy
, width
, height
;
27767 Lisp_Object string
, object
= Qnil
;
27768 Lisp_Object pos
IF_LINT (= Qnil
), help
;
27770 Lisp_Object mouse_face
;
27771 int original_x_pixel
= x
;
27772 struct glyph
* glyph
= NULL
, * row_start_glyph
= NULL
;
27773 struct glyph_row
*row
IF_LINT (= 0);
27775 if (area
== ON_MODE_LINE
|| area
== ON_HEADER_LINE
)
27780 /* Kludge alert: mode_line_string takes X/Y in pixels, but
27781 returns them in row/column units! */
27782 string
= mode_line_string (w
, area
, &x
, &y
, &charpos
,
27783 &object
, &dx
, &dy
, &width
, &height
);
27785 row
= (area
== ON_MODE_LINE
27786 ? MATRIX_MODE_LINE_ROW (w
->current_matrix
)
27787 : MATRIX_HEADER_LINE_ROW (w
->current_matrix
));
27789 /* Find the glyph under the mouse pointer. */
27790 if (row
->mode_line_p
&& row
->enabled_p
)
27792 glyph
= row_start_glyph
= row
->glyphs
[TEXT_AREA
];
27793 end
= glyph
+ row
->used
[TEXT_AREA
];
27795 for (x0
= original_x_pixel
;
27796 glyph
< end
&& x0
>= glyph
->pixel_width
;
27798 x0
-= glyph
->pixel_width
;
27806 x
-= WINDOW_LEFT_SCROLL_BAR_AREA_WIDTH (w
);
27807 /* Kludge alert: marginal_area_string takes X/Y in pixels, but
27808 returns them in row/column units! */
27809 string
= marginal_area_string (w
, area
, &x
, &y
, &charpos
,
27810 &object
, &dx
, &dy
, &width
, &height
);
27815 #ifdef HAVE_WINDOW_SYSTEM
27816 if (IMAGEP (object
))
27818 Lisp_Object image_map
, hotspot
;
27819 if ((image_map
= Fplist_get (XCDR (object
), QCmap
),
27821 && (hotspot
= find_hot_spot (image_map
, dx
, dy
),
27823 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
27827 /* Could check XCAR (hotspot) to see if we enter/leave this hot-spot.
27828 If so, we could look for mouse-enter, mouse-leave
27829 properties in PLIST (and do something...). */
27830 hotspot
= XCDR (hotspot
);
27831 if (CONSP (hotspot
)
27832 && (plist
= XCAR (hotspot
), CONSP (plist
)))
27834 pointer
= Fplist_get (plist
, Qpointer
);
27835 if (NILP (pointer
))
27837 help
= Fplist_get (plist
, Qhelp_echo
);
27840 help_echo_string
= help
;
27841 XSETWINDOW (help_echo_window
, w
);
27842 help_echo_object
= w
->contents
;
27843 help_echo_pos
= charpos
;
27847 if (NILP (pointer
))
27848 pointer
= Fplist_get (XCDR (object
), QCpointer
);
27850 #endif /* HAVE_WINDOW_SYSTEM */
27852 if (STRINGP (string
))
27853 pos
= make_number (charpos
);
27855 /* Set the help text and mouse pointer. If the mouse is on a part
27856 of the mode line without any text (e.g. past the right edge of
27857 the mode line text), use the default help text and pointer. */
27858 if (STRINGP (string
) || area
== ON_MODE_LINE
)
27860 /* Arrange to display the help by setting the global variables
27861 help_echo_string, help_echo_object, and help_echo_pos. */
27864 if (STRINGP (string
))
27865 help
= Fget_text_property (pos
, Qhelp_echo
, string
);
27869 help_echo_string
= help
;
27870 XSETWINDOW (help_echo_window
, w
);
27871 help_echo_object
= string
;
27872 help_echo_pos
= charpos
;
27874 else if (area
== ON_MODE_LINE
)
27876 Lisp_Object default_help
27877 = buffer_local_value_1 (Qmode_line_default_help_echo
,
27880 if (STRINGP (default_help
))
27882 help_echo_string
= default_help
;
27883 XSETWINDOW (help_echo_window
, w
);
27884 help_echo_object
= Qnil
;
27885 help_echo_pos
= -1;
27890 #ifdef HAVE_WINDOW_SYSTEM
27891 /* Change the mouse pointer according to what is under it. */
27892 if (FRAME_WINDOW_P (f
))
27894 dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
27895 if (STRINGP (string
))
27897 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
27899 if (NILP (pointer
))
27900 pointer
= Fget_text_property (pos
, Qpointer
, string
);
27902 /* Change the mouse pointer according to what is under X/Y. */
27904 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
)))
27907 map
= Fget_text_property (pos
, Qlocal_map
, string
);
27908 if (!KEYMAPP (map
))
27909 map
= Fget_text_property (pos
, Qkeymap
, string
);
27910 if (!KEYMAPP (map
))
27911 cursor
= dpyinfo
->vertical_scroll_bar_cursor
;
27915 /* Default mode-line pointer. */
27916 cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
27921 /* Change the mouse face according to what is under X/Y. */
27922 if (STRINGP (string
))
27924 mouse_face
= Fget_text_property (pos
, Qmouse_face
, string
);
27925 if (!NILP (Vmouse_highlight
) && !NILP (mouse_face
)
27926 && ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
27931 struct glyph
* tmp_glyph
;
27935 int total_pixel_width
;
27936 ptrdiff_t begpos
, endpos
, ignore
;
27940 b
= Fprevious_single_property_change (make_number (charpos
+ 1),
27941 Qmouse_face
, string
, Qnil
);
27947 e
= Fnext_single_property_change (pos
, Qmouse_face
, string
, Qnil
);
27949 endpos
= SCHARS (string
);
27953 /* Calculate the glyph position GPOS of GLYPH in the
27954 displayed string, relative to the beginning of the
27955 highlighted part of the string.
27957 Note: GPOS is different from CHARPOS. CHARPOS is the
27958 position of GLYPH in the internal string object. A mode
27959 line string format has structures which are converted to
27960 a flattened string by the Emacs Lisp interpreter. The
27961 internal string is an element of those structures. The
27962 displayed string is the flattened string. */
27963 tmp_glyph
= row_start_glyph
;
27964 while (tmp_glyph
< glyph
27965 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27966 && begpos
<= tmp_glyph
->charpos
27967 && tmp_glyph
->charpos
< endpos
)))
27969 gpos
= glyph
- tmp_glyph
;
27971 /* Calculate the length GSEQ_LENGTH of the glyph sequence of
27972 the highlighted part of the displayed string to which
27973 GLYPH belongs. Note: GSEQ_LENGTH is different from
27974 SCHARS (STRING), because the latter returns the length of
27975 the internal string. */
27976 for (tmp_glyph
= row
->glyphs
[TEXT_AREA
] + row
->used
[TEXT_AREA
] - 1;
27978 && (!(EQ (tmp_glyph
->object
, glyph
->object
)
27979 && begpos
<= tmp_glyph
->charpos
27980 && tmp_glyph
->charpos
< endpos
));
27983 gseq_length
= gpos
+ (tmp_glyph
- glyph
) + 1;
27985 /* Calculate the total pixel width of all the glyphs between
27986 the beginning of the highlighted area and GLYPH. */
27987 total_pixel_width
= 0;
27988 for (tmp_glyph
= glyph
- gpos
; tmp_glyph
!= glyph
; tmp_glyph
++)
27989 total_pixel_width
+= tmp_glyph
->pixel_width
;
27991 /* Pre calculation of re-rendering position. Note: X is in
27992 column units here, after the call to mode_line_string or
27993 marginal_area_string. */
27995 vpos
= (area
== ON_MODE_LINE
27996 ? (w
->current_matrix
)->nrows
- 1
27999 /* If GLYPH's position is included in the region that is
28000 already drawn in mouse face, we have nothing to do. */
28001 if ( EQ (window
, hlinfo
->mouse_face_window
)
28002 && (!row
->reversed_p
28003 ? (hlinfo
->mouse_face_beg_col
<= hpos
28004 && hpos
< hlinfo
->mouse_face_end_col
)
28005 /* In R2L rows we swap BEG and END, see below. */
28006 : (hlinfo
->mouse_face_end_col
<= hpos
28007 && hpos
< hlinfo
->mouse_face_beg_col
))
28008 && hlinfo
->mouse_face_beg_row
== vpos
)
28011 if (clear_mouse_face (hlinfo
))
28012 cursor
= No_Cursor
;
28014 if (!row
->reversed_p
)
28016 hlinfo
->mouse_face_beg_col
= hpos
;
28017 hlinfo
->mouse_face_beg_x
= original_x_pixel
28018 - (total_pixel_width
+ dx
);
28019 hlinfo
->mouse_face_end_col
= hpos
+ gseq_length
;
28020 hlinfo
->mouse_face_end_x
= 0;
28024 /* In R2L rows, show_mouse_face expects BEG and END
28025 coordinates to be swapped. */
28026 hlinfo
->mouse_face_end_col
= hpos
;
28027 hlinfo
->mouse_face_end_x
= original_x_pixel
28028 - (total_pixel_width
+ dx
);
28029 hlinfo
->mouse_face_beg_col
= hpos
+ gseq_length
;
28030 hlinfo
->mouse_face_beg_x
= 0;
28033 hlinfo
->mouse_face_beg_row
= vpos
;
28034 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_beg_row
;
28035 hlinfo
->mouse_face_beg_y
= 0;
28036 hlinfo
->mouse_face_end_y
= 0;
28037 hlinfo
->mouse_face_past_end
= 0;
28038 hlinfo
->mouse_face_window
= window
;
28040 hlinfo
->mouse_face_face_id
= face_at_string_position (w
, string
,
28046 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28048 if (NILP (pointer
))
28051 else if ((area
== ON_MODE_LINE
) || (area
== ON_HEADER_LINE
))
28052 clear_mouse_face (hlinfo
);
28054 #ifdef HAVE_WINDOW_SYSTEM
28055 if (FRAME_WINDOW_P (f
))
28056 define_frame_cursor1 (f
, cursor
, pointer
);
28062 Take proper action when the mouse has moved to position X, Y on
28063 frame F with regards to highlighting portions of display that have
28064 mouse-face properties. Also de-highlight portions of display where
28065 the mouse was before, set the mouse pointer shape as appropriate
28066 for the mouse coordinates, and activate help echo (tooltips).
28067 X and Y can be negative or out of range. */
28070 note_mouse_highlight (struct frame
*f
, int x
, int y
)
28072 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28073 enum window_part part
= ON_NOTHING
;
28074 Lisp_Object window
;
28076 Cursor cursor
= No_Cursor
;
28077 Lisp_Object pointer
= Qnil
; /* Takes precedence over cursor! */
28080 /* When a menu is active, don't highlight because this looks odd. */
28081 #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (MSDOS)
28082 if (popup_activated ())
28086 if (!f
->glyphs_initialized_p
28087 || f
->pointer_invisible
)
28090 hlinfo
->mouse_face_mouse_x
= x
;
28091 hlinfo
->mouse_face_mouse_y
= y
;
28092 hlinfo
->mouse_face_mouse_frame
= f
;
28094 if (hlinfo
->mouse_face_defer
)
28097 /* Which window is that in? */
28098 window
= window_from_coordinates (f
, x
, y
, &part
, 1);
28100 /* If displaying active text in another window, clear that. */
28101 if (! EQ (window
, hlinfo
->mouse_face_window
)
28102 /* Also clear if we move out of text area in same window. */
28103 || (!NILP (hlinfo
->mouse_face_window
)
28106 && part
!= ON_MODE_LINE
28107 && part
!= ON_HEADER_LINE
))
28108 clear_mouse_face (hlinfo
);
28110 /* Not on a window -> return. */
28111 if (!WINDOWP (window
))
28114 /* Reset help_echo_string. It will get recomputed below. */
28115 help_echo_string
= Qnil
;
28117 /* Convert to window-relative pixel coordinates. */
28118 w
= XWINDOW (window
);
28119 frame_to_window_pixel_xy (w
, &x
, &y
);
28121 #ifdef HAVE_WINDOW_SYSTEM
28122 /* Handle tool-bar window differently since it doesn't display a
28124 if (EQ (window
, f
->tool_bar_window
))
28126 note_tool_bar_highlight (f
, x
, y
);
28131 /* Mouse is on the mode, header line or margin? */
28132 if (part
== ON_MODE_LINE
|| part
== ON_HEADER_LINE
28133 || part
== ON_LEFT_MARGIN
|| part
== ON_RIGHT_MARGIN
)
28135 note_mode_line_or_margin_highlight (window
, x
, y
, part
);
28139 #ifdef HAVE_WINDOW_SYSTEM
28140 if (part
== ON_VERTICAL_BORDER
)
28142 cursor
= FRAME_X_OUTPUT (f
)->horizontal_drag_cursor
;
28143 help_echo_string
= build_string ("drag-mouse-1: resize");
28145 else if (part
== ON_LEFT_FRINGE
|| part
== ON_RIGHT_FRINGE
28146 || part
== ON_SCROLL_BAR
)
28147 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28149 cursor
= FRAME_X_OUTPUT (f
)->text_cursor
;
28152 /* Are we in a window whose display is up to date?
28153 And verify the buffer's text has not changed. */
28154 b
= XBUFFER (w
->contents
);
28155 if (part
== ON_TEXT
28156 && w
->window_end_valid
28157 && w
->last_modified
== BUF_MODIFF (b
)
28158 && w
->last_overlay_modified
== BUF_OVERLAY_MODIFF (b
))
28160 int hpos
, vpos
, dx
, dy
, area
= LAST_AREA
;
28162 struct glyph
*glyph
;
28163 Lisp_Object object
;
28164 Lisp_Object mouse_face
= Qnil
, position
;
28165 Lisp_Object
*overlay_vec
= NULL
;
28166 ptrdiff_t i
, noverlays
;
28167 struct buffer
*obuf
;
28168 ptrdiff_t obegv
, ozv
;
28171 /* Find the glyph under X/Y. */
28172 glyph
= x_y_to_hpos_vpos (w
, x
, y
, &hpos
, &vpos
, &dx
, &dy
, &area
);
28174 #ifdef HAVE_WINDOW_SYSTEM
28175 /* Look for :pointer property on image. */
28176 if (glyph
!= NULL
&& glyph
->type
== IMAGE_GLYPH
)
28178 struct image
*img
= IMAGE_FROM_ID (f
, glyph
->u
.img_id
);
28179 if (img
!= NULL
&& IMAGEP (img
->spec
))
28181 Lisp_Object image_map
, hotspot
;
28182 if ((image_map
= Fplist_get (XCDR (img
->spec
), QCmap
),
28184 && (hotspot
= find_hot_spot (image_map
,
28185 glyph
->slice
.img
.x
+ dx
,
28186 glyph
->slice
.img
.y
+ dy
),
28188 && (hotspot
= XCDR (hotspot
), CONSP (hotspot
)))
28192 /* Could check XCAR (hotspot) to see if we enter/leave
28194 If so, we could look for mouse-enter, mouse-leave
28195 properties in PLIST (and do something...). */
28196 hotspot
= XCDR (hotspot
);
28197 if (CONSP (hotspot
)
28198 && (plist
= XCAR (hotspot
), CONSP (plist
)))
28200 pointer
= Fplist_get (plist
, Qpointer
);
28201 if (NILP (pointer
))
28203 help_echo_string
= Fplist_get (plist
, Qhelp_echo
);
28204 if (!NILP (help_echo_string
))
28206 help_echo_window
= window
;
28207 help_echo_object
= glyph
->object
;
28208 help_echo_pos
= glyph
->charpos
;
28212 if (NILP (pointer
))
28213 pointer
= Fplist_get (XCDR (img
->spec
), QCpointer
);
28216 #endif /* HAVE_WINDOW_SYSTEM */
28218 /* Clear mouse face if X/Y not over text. */
28220 || area
!= TEXT_AREA
28221 || !MATRIX_ROW_DISPLAYS_TEXT_P (MATRIX_ROW (w
->current_matrix
, vpos
))
28222 /* Glyph's OBJECT is an integer for glyphs inserted by the
28223 display engine for its internal purposes, like truncation
28224 and continuation glyphs and blanks beyond the end of
28225 line's text on text terminals. If we are over such a
28226 glyph, we are not over any text. */
28227 || INTEGERP (glyph
->object
)
28228 /* R2L rows have a stretch glyph at their front, which
28229 stands for no text, whereas L2R rows have no glyphs at
28230 all beyond the end of text. Treat such stretch glyphs
28231 like we do with NULL glyphs in L2R rows. */
28232 || (MATRIX_ROW (w
->current_matrix
, vpos
)->reversed_p
28233 && glyph
== MATRIX_ROW_GLYPH_START (w
->current_matrix
, vpos
)
28234 && glyph
->type
== STRETCH_GLYPH
28235 && glyph
->avoid_cursor_p
))
28237 if (clear_mouse_face (hlinfo
))
28238 cursor
= No_Cursor
;
28239 #ifdef HAVE_WINDOW_SYSTEM
28240 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28242 if (area
!= TEXT_AREA
)
28243 cursor
= FRAME_X_OUTPUT (f
)->nontext_cursor
;
28245 pointer
= Vvoid_text_area_pointer
;
28251 pos
= glyph
->charpos
;
28252 object
= glyph
->object
;
28253 if (!STRINGP (object
) && !BUFFERP (object
))
28256 /* If we get an out-of-range value, return now; avoid an error. */
28257 if (BUFFERP (object
) && pos
> BUF_Z (b
))
28260 /* Make the window's buffer temporarily current for
28261 overlays_at and compute_char_face. */
28262 obuf
= current_buffer
;
28263 current_buffer
= b
;
28269 /* Is this char mouse-active or does it have help-echo? */
28270 position
= make_number (pos
);
28272 if (BUFFERP (object
))
28274 /* Put all the overlays we want in a vector in overlay_vec. */
28275 GET_OVERLAYS_AT (pos
, overlay_vec
, noverlays
, NULL
, 0);
28276 /* Sort overlays into increasing priority order. */
28277 noverlays
= sort_overlays (overlay_vec
, noverlays
, w
);
28282 if (NILP (Vmouse_highlight
))
28284 clear_mouse_face (hlinfo
);
28285 goto check_help_echo
;
28288 same_region
= coords_in_mouse_face_p (w
, hpos
, vpos
);
28291 cursor
= No_Cursor
;
28293 /* Check mouse-face highlighting. */
28295 /* If there exists an overlay with mouse-face overlapping
28296 the one we are currently highlighting, we have to
28297 check if we enter the overlapping overlay, and then
28298 highlight only that. */
28299 || (OVERLAYP (hlinfo
->mouse_face_overlay
)
28300 && mouse_face_overlay_overlaps (hlinfo
->mouse_face_overlay
)))
28302 /* Find the highest priority overlay with a mouse-face. */
28303 Lisp_Object overlay
= Qnil
;
28304 for (i
= noverlays
- 1; i
>= 0 && NILP (overlay
); --i
)
28306 mouse_face
= Foverlay_get (overlay_vec
[i
], Qmouse_face
);
28307 if (!NILP (mouse_face
))
28308 overlay
= overlay_vec
[i
];
28311 /* If we're highlighting the same overlay as before, there's
28312 no need to do that again. */
28313 if (!NILP (overlay
) && EQ (overlay
, hlinfo
->mouse_face_overlay
))
28314 goto check_help_echo
;
28315 hlinfo
->mouse_face_overlay
= overlay
;
28317 /* Clear the display of the old active region, if any. */
28318 if (clear_mouse_face (hlinfo
))
28319 cursor
= No_Cursor
;
28321 /* If no overlay applies, get a text property. */
28322 if (NILP (overlay
))
28323 mouse_face
= Fget_text_property (position
, Qmouse_face
, object
);
28325 /* Next, compute the bounds of the mouse highlighting and
28327 if (!NILP (mouse_face
) && STRINGP (object
))
28329 /* The mouse-highlighting comes from a display string
28330 with a mouse-face. */
28334 s
= Fprevious_single_property_change
28335 (make_number (pos
+ 1), Qmouse_face
, object
, Qnil
);
28336 e
= Fnext_single_property_change
28337 (position
, Qmouse_face
, object
, Qnil
);
28339 s
= make_number (0);
28341 e
= make_number (SCHARS (object
) - 1);
28342 mouse_face_from_string_pos (w
, hlinfo
, object
,
28343 XINT (s
), XINT (e
));
28344 hlinfo
->mouse_face_past_end
= 0;
28345 hlinfo
->mouse_face_window
= window
;
28346 hlinfo
->mouse_face_face_id
28347 = face_at_string_position (w
, object
, pos
, 0, 0, 0, &ignore
,
28348 glyph
->face_id
, 1);
28349 show_mouse_face (hlinfo
, DRAW_MOUSE_FACE
);
28350 cursor
= No_Cursor
;
28354 /* The mouse-highlighting, if any, comes from an overlay
28355 or text property in the buffer. */
28356 Lisp_Object buffer
IF_LINT (= Qnil
);
28357 Lisp_Object disp_string
IF_LINT (= Qnil
);
28359 if (STRINGP (object
))
28361 /* If we are on a display string with no mouse-face,
28362 check if the text under it has one. */
28363 struct glyph_row
*r
= MATRIX_ROW (w
->current_matrix
, vpos
);
28364 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28365 pos
= string_buffer_position (object
, start
);
28368 mouse_face
= get_char_property_and_overlay
28369 (make_number (pos
), Qmouse_face
, w
->contents
, &overlay
);
28370 buffer
= w
->contents
;
28371 disp_string
= object
;
28377 disp_string
= Qnil
;
28380 if (!NILP (mouse_face
))
28382 Lisp_Object before
, after
;
28383 Lisp_Object before_string
, after_string
;
28384 /* To correctly find the limits of mouse highlight
28385 in a bidi-reordered buffer, we must not use the
28386 optimization of limiting the search in
28387 previous-single-property-change and
28388 next-single-property-change, because
28389 rows_from_pos_range needs the real start and end
28390 positions to DTRT in this case. That's because
28391 the first row visible in a window does not
28392 necessarily display the character whose position
28393 is the smallest. */
28395 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28396 ? Fmarker_position (w
->start
)
28399 NILP (BVAR (XBUFFER (buffer
), bidi_display_reordering
))
28400 ? make_number (BUF_Z (XBUFFER (buffer
))
28401 - XFASTINT (w
->window_end_pos
))
28404 if (NILP (overlay
))
28406 /* Handle the text property case. */
28407 before
= Fprevious_single_property_change
28408 (make_number (pos
+ 1), Qmouse_face
, buffer
, lim1
);
28409 after
= Fnext_single_property_change
28410 (make_number (pos
), Qmouse_face
, buffer
, lim2
);
28411 before_string
= after_string
= Qnil
;
28415 /* Handle the overlay case. */
28416 before
= Foverlay_start (overlay
);
28417 after
= Foverlay_end (overlay
);
28418 before_string
= Foverlay_get (overlay
, Qbefore_string
);
28419 after_string
= Foverlay_get (overlay
, Qafter_string
);
28421 if (!STRINGP (before_string
)) before_string
= Qnil
;
28422 if (!STRINGP (after_string
)) after_string
= Qnil
;
28425 mouse_face_from_buffer_pos (window
, hlinfo
, pos
,
28428 : XFASTINT (before
),
28430 ? BUF_Z (XBUFFER (buffer
))
28431 : XFASTINT (after
),
28432 before_string
, after_string
,
28434 cursor
= No_Cursor
;
28441 /* Look for a `help-echo' property. */
28442 if (NILP (help_echo_string
)) {
28443 Lisp_Object help
, overlay
;
28445 /* Check overlays first. */
28446 help
= overlay
= Qnil
;
28447 for (i
= noverlays
- 1; i
>= 0 && NILP (help
); --i
)
28449 overlay
= overlay_vec
[i
];
28450 help
= Foverlay_get (overlay
, Qhelp_echo
);
28455 help_echo_string
= help
;
28456 help_echo_window
= window
;
28457 help_echo_object
= overlay
;
28458 help_echo_pos
= pos
;
28462 Lisp_Object obj
= glyph
->object
;
28463 ptrdiff_t charpos
= glyph
->charpos
;
28465 /* Try text properties. */
28468 && charpos
< SCHARS (obj
))
28470 help
= Fget_text_property (make_number (charpos
),
28474 /* If the string itself doesn't specify a help-echo,
28475 see if the buffer text ``under'' it does. */
28476 struct glyph_row
*r
28477 = MATRIX_ROW (w
->current_matrix
, vpos
);
28478 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28479 ptrdiff_t p
= string_buffer_position (obj
, start
);
28482 help
= Fget_char_property (make_number (p
),
28483 Qhelp_echo
, w
->contents
);
28492 else if (BUFFERP (obj
)
28495 help
= Fget_text_property (make_number (charpos
), Qhelp_echo
,
28500 help_echo_string
= help
;
28501 help_echo_window
= window
;
28502 help_echo_object
= obj
;
28503 help_echo_pos
= charpos
;
28508 #ifdef HAVE_WINDOW_SYSTEM
28509 /* Look for a `pointer' property. */
28510 if (FRAME_WINDOW_P (f
) && NILP (pointer
))
28512 /* Check overlays first. */
28513 for (i
= noverlays
- 1; i
>= 0 && NILP (pointer
); --i
)
28514 pointer
= Foverlay_get (overlay_vec
[i
], Qpointer
);
28516 if (NILP (pointer
))
28518 Lisp_Object obj
= glyph
->object
;
28519 ptrdiff_t charpos
= glyph
->charpos
;
28521 /* Try text properties. */
28524 && charpos
< SCHARS (obj
))
28526 pointer
= Fget_text_property (make_number (charpos
),
28528 if (NILP (pointer
))
28530 /* If the string itself doesn't specify a pointer,
28531 see if the buffer text ``under'' it does. */
28532 struct glyph_row
*r
28533 = MATRIX_ROW (w
->current_matrix
, vpos
);
28534 ptrdiff_t start
= MATRIX_ROW_START_CHARPOS (r
);
28535 ptrdiff_t p
= string_buffer_position (obj
, start
);
28537 pointer
= Fget_char_property (make_number (p
),
28538 Qpointer
, w
->contents
);
28541 else if (BUFFERP (obj
)
28544 pointer
= Fget_text_property (make_number (charpos
),
28548 #endif /* HAVE_WINDOW_SYSTEM */
28552 current_buffer
= obuf
;
28557 #ifdef HAVE_WINDOW_SYSTEM
28558 if (FRAME_WINDOW_P (f
))
28559 define_frame_cursor1 (f
, cursor
, pointer
);
28561 /* This is here to prevent a compiler error, about "label at end of
28562 compound statement". */
28569 Clear any mouse-face on window W. This function is part of the
28570 redisplay interface, and is called from try_window_id and similar
28571 functions to ensure the mouse-highlight is off. */
28574 x_clear_window_mouse_face (struct window
*w
)
28576 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
28577 Lisp_Object window
;
28580 XSETWINDOW (window
, w
);
28581 if (EQ (window
, hlinfo
->mouse_face_window
))
28582 clear_mouse_face (hlinfo
);
28588 Just discard the mouse face information for frame F, if any.
28589 This is used when the size of F is changed. */
28592 cancel_mouse_face (struct frame
*f
)
28594 Lisp_Object window
;
28595 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
28597 window
= hlinfo
->mouse_face_window
;
28598 if (! NILP (window
) && XFRAME (XWINDOW (window
)->frame
) == f
)
28600 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
28601 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
28602 hlinfo
->mouse_face_window
= Qnil
;
28608 /***********************************************************************
28610 ***********************************************************************/
28612 #ifdef HAVE_WINDOW_SYSTEM
28614 /* Redraw the part of glyph row area AREA of glyph row ROW on window W
28615 which intersects rectangle R. R is in window-relative coordinates. */
28618 expose_area (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
,
28619 enum glyph_row_area area
)
28621 struct glyph
*first
= row
->glyphs
[area
];
28622 struct glyph
*end
= row
->glyphs
[area
] + row
->used
[area
];
28623 struct glyph
*last
;
28624 int first_x
, start_x
, x
;
28626 if (area
== TEXT_AREA
&& row
->fill_line_p
)
28627 /* If row extends face to end of line write the whole line. */
28628 draw_glyphs (w
, 0, row
, area
,
28629 0, row
->used
[area
],
28630 DRAW_NORMAL_TEXT
, 0);
28633 /* Set START_X to the window-relative start position for drawing glyphs of
28634 AREA. The first glyph of the text area can be partially visible.
28635 The first glyphs of other areas cannot. */
28636 start_x
= window_box_left_offset (w
, area
);
28638 if (area
== TEXT_AREA
)
28641 /* Find the first glyph that must be redrawn. */
28643 && x
+ first
->pixel_width
< r
->x
)
28645 x
+= first
->pixel_width
;
28649 /* Find the last one. */
28653 && x
< r
->x
+ r
->width
)
28655 x
+= last
->pixel_width
;
28661 draw_glyphs (w
, first_x
- start_x
, row
, area
,
28662 first
- row
->glyphs
[area
], last
- row
->glyphs
[area
],
28663 DRAW_NORMAL_TEXT
, 0);
28668 /* Redraw the parts of the glyph row ROW on window W intersecting
28669 rectangle R. R is in window-relative coordinates. Value is
28670 non-zero if mouse-face was overwritten. */
28673 expose_line (struct window
*w
, struct glyph_row
*row
, XRectangle
*r
)
28675 eassert (row
->enabled_p
);
28677 if (row
->mode_line_p
|| w
->pseudo_window_p
)
28678 draw_glyphs (w
, 0, row
, TEXT_AREA
,
28679 0, row
->used
[TEXT_AREA
],
28680 DRAW_NORMAL_TEXT
, 0);
28683 if (row
->used
[LEFT_MARGIN_AREA
])
28684 expose_area (w
, row
, r
, LEFT_MARGIN_AREA
);
28685 if (row
->used
[TEXT_AREA
])
28686 expose_area (w
, row
, r
, TEXT_AREA
);
28687 if (row
->used
[RIGHT_MARGIN_AREA
])
28688 expose_area (w
, row
, r
, RIGHT_MARGIN_AREA
);
28689 draw_row_fringe_bitmaps (w
, row
);
28692 return row
->mouse_face_p
;
28696 /* Redraw those parts of glyphs rows during expose event handling that
28697 overlap other rows. Redrawing of an exposed line writes over parts
28698 of lines overlapping that exposed line; this function fixes that.
28700 W is the window being exposed. FIRST_OVERLAPPING_ROW is the first
28701 row in W's current matrix that is exposed and overlaps other rows.
28702 LAST_OVERLAPPING_ROW is the last such row. */
28705 expose_overlaps (struct window
*w
,
28706 struct glyph_row
*first_overlapping_row
,
28707 struct glyph_row
*last_overlapping_row
,
28710 struct glyph_row
*row
;
28712 for (row
= first_overlapping_row
; row
<= last_overlapping_row
; ++row
)
28713 if (row
->overlapping_p
)
28715 eassert (row
->enabled_p
&& !row
->mode_line_p
);
28718 if (row
->used
[LEFT_MARGIN_AREA
])
28719 x_fix_overlapping_area (w
, row
, LEFT_MARGIN_AREA
, OVERLAPS_BOTH
);
28721 if (row
->used
[TEXT_AREA
])
28722 x_fix_overlapping_area (w
, row
, TEXT_AREA
, OVERLAPS_BOTH
);
28724 if (row
->used
[RIGHT_MARGIN_AREA
])
28725 x_fix_overlapping_area (w
, row
, RIGHT_MARGIN_AREA
, OVERLAPS_BOTH
);
28731 /* Return non-zero if W's cursor intersects rectangle R. */
28734 phys_cursor_in_rect_p (struct window
*w
, XRectangle
*r
)
28736 XRectangle cr
, result
;
28737 struct glyph
*cursor_glyph
;
28738 struct glyph_row
*row
;
28740 if (w
->phys_cursor
.vpos
>= 0
28741 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
28742 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
28744 && row
->cursor_in_fringe_p
)
28746 /* Cursor is in the fringe. */
28747 cr
.x
= window_box_right_offset (w
,
28748 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
28749 ? RIGHT_MARGIN_AREA
28752 cr
.width
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
28753 cr
.height
= row
->height
;
28754 return x_intersect_rectangles (&cr
, r
, &result
);
28757 cursor_glyph
= get_phys_cursor_glyph (w
);
28760 /* r is relative to W's box, but w->phys_cursor.x is relative
28761 to left edge of W's TEXT area. Adjust it. */
28762 cr
.x
= window_box_left_offset (w
, TEXT_AREA
) + w
->phys_cursor
.x
;
28763 cr
.y
= w
->phys_cursor
.y
;
28764 cr
.width
= cursor_glyph
->pixel_width
;
28765 cr
.height
= w
->phys_cursor_height
;
28766 /* ++KFS: W32 version used W32-specific IntersectRect here, but
28767 I assume the effect is the same -- and this is portable. */
28768 return x_intersect_rectangles (&cr
, r
, &result
);
28770 /* If we don't understand the format, pretend we're not in the hot-spot. */
28776 Draw a vertical window border to the right of window W if W doesn't
28777 have vertical scroll bars. */
28780 x_draw_vertical_border (struct window
*w
)
28782 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
28784 /* We could do better, if we knew what type of scroll-bar the adjacent
28785 windows (on either side) have... But we don't :-(
28786 However, I think this works ok. ++KFS 2003-04-25 */
28788 /* Redraw borders between horizontally adjacent windows. Don't
28789 do it for frames with vertical scroll bars because either the
28790 right scroll bar of a window, or the left scroll bar of its
28791 neighbor will suffice as a border. */
28792 if (FRAME_HAS_VERTICAL_SCROLL_BARS (XFRAME (w
->frame
)))
28795 /* Note: It is necessary to redraw both the left and the right
28796 borders, for when only this single window W is being
28798 if (!WINDOW_RIGHTMOST_P (w
)
28799 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
28801 int x0
, x1
, y0
, y1
;
28803 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28806 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28809 FRAME_RIF (f
)->draw_vertical_window_border (w
, x1
, y0
, y1
);
28811 if (!WINDOW_LEFTMOST_P (w
)
28812 && !WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
28814 int x0
, x1
, y0
, y1
;
28816 window_box_edges (w
, -1, &x0
, &y0
, &x1
, &y1
);
28819 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
28822 FRAME_RIF (f
)->draw_vertical_window_border (w
, x0
, y0
, y1
);
28827 /* Redraw the part of window W intersection rectangle FR. Pixel
28828 coordinates in FR are frame-relative. Call this function with
28829 input blocked. Value is non-zero if the exposure overwrites
28833 expose_window (struct window
*w
, XRectangle
*fr
)
28835 struct frame
*f
= XFRAME (w
->frame
);
28837 int mouse_face_overwritten_p
= 0;
28839 /* If window is not yet fully initialized, do nothing. This can
28840 happen when toolkit scroll bars are used and a window is split.
28841 Reconfiguring the scroll bar will generate an expose for a newly
28843 if (w
->current_matrix
== NULL
)
28846 /* When we're currently updating the window, display and current
28847 matrix usually don't agree. Arrange for a thorough display
28849 if (w
== updated_window
)
28851 SET_FRAME_GARBAGED (f
);
28855 /* Frame-relative pixel rectangle of W. */
28856 wr
.x
= WINDOW_LEFT_EDGE_X (w
);
28857 wr
.y
= WINDOW_TOP_EDGE_Y (w
);
28858 wr
.width
= WINDOW_TOTAL_WIDTH (w
);
28859 wr
.height
= WINDOW_TOTAL_HEIGHT (w
);
28861 if (x_intersect_rectangles (fr
, &wr
, &r
))
28863 int yb
= window_text_bottom_y (w
);
28864 struct glyph_row
*row
;
28865 int cursor_cleared_p
, phys_cursor_on_p
;
28866 struct glyph_row
*first_overlapping_row
, *last_overlapping_row
;
28868 TRACE ((stderr
, "expose_window (%d, %d, %d, %d)\n",
28869 r
.x
, r
.y
, r
.width
, r
.height
));
28871 /* Convert to window coordinates. */
28872 r
.x
-= WINDOW_LEFT_EDGE_X (w
);
28873 r
.y
-= WINDOW_TOP_EDGE_Y (w
);
28875 /* Turn off the cursor. */
28876 if (!w
->pseudo_window_p
28877 && phys_cursor_in_rect_p (w
, &r
))
28879 x_clear_cursor (w
);
28880 cursor_cleared_p
= 1;
28883 cursor_cleared_p
= 0;
28885 /* If the row containing the cursor extends face to end of line,
28886 then expose_area might overwrite the cursor outside the
28887 rectangle and thus notice_overwritten_cursor might clear
28888 w->phys_cursor_on_p. We remember the original value and
28889 check later if it is changed. */
28890 phys_cursor_on_p
= w
->phys_cursor_on_p
;
28892 /* Update lines intersecting rectangle R. */
28893 first_overlapping_row
= last_overlapping_row
= NULL
;
28894 for (row
= w
->current_matrix
->rows
;
28899 int y1
= MATRIX_ROW_BOTTOM_Y (row
);
28901 if ((y0
>= r
.y
&& y0
< r
.y
+ r
.height
)
28902 || (y1
> r
.y
&& y1
< r
.y
+ r
.height
)
28903 || (r
.y
>= y0
&& r
.y
< y1
)
28904 || (r
.y
+ r
.height
> y0
&& r
.y
+ r
.height
< y1
))
28906 /* A header line may be overlapping, but there is no need
28907 to fix overlapping areas for them. KFS 2005-02-12 */
28908 if (row
->overlapping_p
&& !row
->mode_line_p
)
28910 if (first_overlapping_row
== NULL
)
28911 first_overlapping_row
= row
;
28912 last_overlapping_row
= row
;
28916 if (expose_line (w
, row
, &r
))
28917 mouse_face_overwritten_p
= 1;
28920 else if (row
->overlapping_p
)
28922 /* We must redraw a row overlapping the exposed area. */
28924 ? y0
+ row
->phys_height
> r
.y
28925 : y0
+ row
->ascent
- row
->phys_ascent
< r
.y
+r
.height
)
28927 if (first_overlapping_row
== NULL
)
28928 first_overlapping_row
= row
;
28929 last_overlapping_row
= row
;
28937 /* Display the mode line if there is one. */
28938 if (WINDOW_WANTS_MODELINE_P (w
)
28939 && (row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
),
28941 && row
->y
< r
.y
+ r
.height
)
28943 if (expose_line (w
, row
, &r
))
28944 mouse_face_overwritten_p
= 1;
28947 if (!w
->pseudo_window_p
)
28949 /* Fix the display of overlapping rows. */
28950 if (first_overlapping_row
)
28951 expose_overlaps (w
, first_overlapping_row
, last_overlapping_row
,
28954 /* Draw border between windows. */
28955 x_draw_vertical_border (w
);
28957 /* Turn the cursor on again. */
28958 if (cursor_cleared_p
28959 || (phys_cursor_on_p
&& !w
->phys_cursor_on_p
))
28960 update_window_cursor (w
, 1);
28964 return mouse_face_overwritten_p
;
28969 /* Redraw (parts) of all windows in the window tree rooted at W that
28970 intersect R. R contains frame pixel coordinates. Value is
28971 non-zero if the exposure overwrites mouse-face. */
28974 expose_window_tree (struct window
*w
, XRectangle
*r
)
28976 struct frame
*f
= XFRAME (w
->frame
);
28977 int mouse_face_overwritten_p
= 0;
28979 while (w
&& !FRAME_GARBAGED_P (f
))
28981 if (WINDOWP (w
->contents
))
28982 mouse_face_overwritten_p
28983 |= expose_window_tree (XWINDOW (w
->contents
), r
);
28985 mouse_face_overwritten_p
|= expose_window (w
, r
);
28987 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
28990 return mouse_face_overwritten_p
;
28995 Redisplay an exposed area of frame F. X and Y are the upper-left
28996 corner of the exposed rectangle. W and H are width and height of
28997 the exposed area. All are pixel values. W or H zero means redraw
28998 the entire frame. */
29001 expose_frame (struct frame
*f
, int x
, int y
, int w
, int h
)
29004 int mouse_face_overwritten_p
= 0;
29006 TRACE ((stderr
, "expose_frame "));
29008 /* No need to redraw if frame will be redrawn soon. */
29009 if (FRAME_GARBAGED_P (f
))
29011 TRACE ((stderr
, " garbaged\n"));
29015 /* If basic faces haven't been realized yet, there is no point in
29016 trying to redraw anything. This can happen when we get an expose
29017 event while Emacs is starting, e.g. by moving another window. */
29018 if (FRAME_FACE_CACHE (f
) == NULL
29019 || FRAME_FACE_CACHE (f
)->used
< BASIC_FACE_ID_SENTINEL
)
29021 TRACE ((stderr
, " no faces\n"));
29025 if (w
== 0 || h
== 0)
29028 r
.width
= FRAME_COLUMN_WIDTH (f
) * FRAME_COLS (f
);
29029 r
.height
= FRAME_LINE_HEIGHT (f
) * FRAME_LINES (f
);
29039 TRACE ((stderr
, "(%d, %d, %d, %d)\n", r
.x
, r
.y
, r
.width
, r
.height
));
29040 mouse_face_overwritten_p
= expose_window_tree (XWINDOW (f
->root_window
), &r
);
29042 if (WINDOWP (f
->tool_bar_window
))
29043 mouse_face_overwritten_p
29044 |= expose_window (XWINDOW (f
->tool_bar_window
), &r
);
29046 #ifdef HAVE_X_WINDOWS
29048 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
29049 if (WINDOWP (f
->menu_bar_window
))
29050 mouse_face_overwritten_p
29051 |= expose_window (XWINDOW (f
->menu_bar_window
), &r
);
29052 #endif /* not USE_X_TOOLKIT and not USE_GTK */
29056 /* Some window managers support a focus-follows-mouse style with
29057 delayed raising of frames. Imagine a partially obscured frame,
29058 and moving the mouse into partially obscured mouse-face on that
29059 frame. The visible part of the mouse-face will be highlighted,
29060 then the WM raises the obscured frame. With at least one WM, KDE
29061 2.1, Emacs is not getting any event for the raising of the frame
29062 (even tried with SubstructureRedirectMask), only Expose events.
29063 These expose events will draw text normally, i.e. not
29064 highlighted. Which means we must redo the highlight here.
29065 Subsume it under ``we love X''. --gerd 2001-08-15 */
29066 /* Included in Windows version because Windows most likely does not
29067 do the right thing if any third party tool offers
29068 focus-follows-mouse with delayed raise. --jason 2001-10-12 */
29069 if (mouse_face_overwritten_p
&& !FRAME_GARBAGED_P (f
))
29071 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
29072 if (f
== hlinfo
->mouse_face_mouse_frame
)
29074 int mouse_x
= hlinfo
->mouse_face_mouse_x
;
29075 int mouse_y
= hlinfo
->mouse_face_mouse_y
;
29076 clear_mouse_face (hlinfo
);
29077 note_mouse_highlight (f
, mouse_x
, mouse_y
);
29084 Determine the intersection of two rectangles R1 and R2. Return
29085 the intersection in *RESULT. Value is non-zero if RESULT is not
29089 x_intersect_rectangles (XRectangle
*r1
, XRectangle
*r2
, XRectangle
*result
)
29091 XRectangle
*left
, *right
;
29092 XRectangle
*upper
, *lower
;
29093 int intersection_p
= 0;
29095 /* Rearrange so that R1 is the left-most rectangle. */
29097 left
= r1
, right
= r2
;
29099 left
= r2
, right
= r1
;
29101 /* X0 of the intersection is right.x0, if this is inside R1,
29102 otherwise there is no intersection. */
29103 if (right
->x
<= left
->x
+ left
->width
)
29105 result
->x
= right
->x
;
29107 /* The right end of the intersection is the minimum of
29108 the right ends of left and right. */
29109 result
->width
= (min (left
->x
+ left
->width
, right
->x
+ right
->width
)
29112 /* Same game for Y. */
29114 upper
= r1
, lower
= r2
;
29116 upper
= r2
, lower
= r1
;
29118 /* The upper end of the intersection is lower.y0, if this is inside
29119 of upper. Otherwise, there is no intersection. */
29120 if (lower
->y
<= upper
->y
+ upper
->height
)
29122 result
->y
= lower
->y
;
29124 /* The lower end of the intersection is the minimum of the lower
29125 ends of upper and lower. */
29126 result
->height
= (min (lower
->y
+ lower
->height
,
29127 upper
->y
+ upper
->height
)
29129 intersection_p
= 1;
29133 return intersection_p
;
29136 #endif /* HAVE_WINDOW_SYSTEM */
29139 /***********************************************************************
29141 ***********************************************************************/
29144 syms_of_xdisp (void)
29146 Vwith_echo_area_save_vector
= Qnil
;
29147 staticpro (&Vwith_echo_area_save_vector
);
29149 Vmessage_stack
= Qnil
;
29150 staticpro (&Vmessage_stack
);
29152 DEFSYM (Qinhibit_redisplay
, "inhibit-redisplay");
29153 DEFSYM (Qredisplay_internal
, "redisplay_internal (C function)");
29155 message_dolog_marker1
= Fmake_marker ();
29156 staticpro (&message_dolog_marker1
);
29157 message_dolog_marker2
= Fmake_marker ();
29158 staticpro (&message_dolog_marker2
);
29159 message_dolog_marker3
= Fmake_marker ();
29160 staticpro (&message_dolog_marker3
);
29163 defsubr (&Sdump_frame_glyph_matrix
);
29164 defsubr (&Sdump_glyph_matrix
);
29165 defsubr (&Sdump_glyph_row
);
29166 defsubr (&Sdump_tool_bar_row
);
29167 defsubr (&Strace_redisplay
);
29168 defsubr (&Strace_to_stderr
);
29170 #ifdef HAVE_WINDOW_SYSTEM
29171 defsubr (&Stool_bar_lines_needed
);
29172 defsubr (&Slookup_image_map
);
29174 defsubr (&Sline_pixel_height
);
29175 defsubr (&Sformat_mode_line
);
29176 defsubr (&Sinvisible_p
);
29177 defsubr (&Scurrent_bidi_paragraph_direction
);
29178 defsubr (&Smove_point_visually
);
29180 DEFSYM (Qmenu_bar_update_hook
, "menu-bar-update-hook");
29181 DEFSYM (Qoverriding_terminal_local_map
, "overriding-terminal-local-map");
29182 DEFSYM (Qoverriding_local_map
, "overriding-local-map");
29183 DEFSYM (Qwindow_scroll_functions
, "window-scroll-functions");
29184 DEFSYM (Qwindow_text_change_functions
, "window-text-change-functions");
29185 DEFSYM (Qredisplay_end_trigger_functions
, "redisplay-end-trigger-functions");
29186 DEFSYM (Qinhibit_point_motion_hooks
, "inhibit-point-motion-hooks");
29187 DEFSYM (Qeval
, "eval");
29188 DEFSYM (QCdata
, ":data");
29189 DEFSYM (Qdisplay
, "display");
29190 DEFSYM (Qspace_width
, "space-width");
29191 DEFSYM (Qraise
, "raise");
29192 DEFSYM (Qslice
, "slice");
29193 DEFSYM (Qspace
, "space");
29194 DEFSYM (Qmargin
, "margin");
29195 DEFSYM (Qpointer
, "pointer");
29196 DEFSYM (Qleft_margin
, "left-margin");
29197 DEFSYM (Qright_margin
, "right-margin");
29198 DEFSYM (Qcenter
, "center");
29199 DEFSYM (Qline_height
, "line-height");
29200 DEFSYM (QCalign_to
, ":align-to");
29201 DEFSYM (QCrelative_width
, ":relative-width");
29202 DEFSYM (QCrelative_height
, ":relative-height");
29203 DEFSYM (QCeval
, ":eval");
29204 DEFSYM (QCpropertize
, ":propertize");
29205 DEFSYM (QCfile
, ":file");
29206 DEFSYM (Qfontified
, "fontified");
29207 DEFSYM (Qfontification_functions
, "fontification-functions");
29208 DEFSYM (Qtrailing_whitespace
, "trailing-whitespace");
29209 DEFSYM (Qescape_glyph
, "escape-glyph");
29210 DEFSYM (Qnobreak_space
, "nobreak-space");
29211 DEFSYM (Qimage
, "image");
29212 DEFSYM (Qtext
, "text");
29213 DEFSYM (Qboth
, "both");
29214 DEFSYM (Qboth_horiz
, "both-horiz");
29215 DEFSYM (Qtext_image_horiz
, "text-image-horiz");
29216 DEFSYM (QCmap
, ":map");
29217 DEFSYM (QCpointer
, ":pointer");
29218 DEFSYM (Qrect
, "rect");
29219 DEFSYM (Qcircle
, "circle");
29220 DEFSYM (Qpoly
, "poly");
29221 DEFSYM (Qmessage_truncate_lines
, "message-truncate-lines");
29222 DEFSYM (Qgrow_only
, "grow-only");
29223 DEFSYM (Qinhibit_menubar_update
, "inhibit-menubar-update");
29224 DEFSYM (Qinhibit_eval_during_redisplay
, "inhibit-eval-during-redisplay");
29225 DEFSYM (Qposition
, "position");
29226 DEFSYM (Qbuffer_position
, "buffer-position");
29227 DEFSYM (Qobject
, "object");
29228 DEFSYM (Qbar
, "bar");
29229 DEFSYM (Qhbar
, "hbar");
29230 DEFSYM (Qbox
, "box");
29231 DEFSYM (Qhollow
, "hollow");
29232 DEFSYM (Qhand
, "hand");
29233 DEFSYM (Qarrow
, "arrow");
29234 DEFSYM (Qinhibit_free_realized_faces
, "inhibit-free-realized-faces");
29236 list_of_error
= Fcons (Fcons (intern_c_string ("error"),
29237 Fcons (intern_c_string ("void-variable"), Qnil
)),
29239 staticpro (&list_of_error
);
29241 DEFSYM (Qlast_arrow_position
, "last-arrow-position");
29242 DEFSYM (Qlast_arrow_string
, "last-arrow-string");
29243 DEFSYM (Qoverlay_arrow_string
, "overlay-arrow-string");
29244 DEFSYM (Qoverlay_arrow_bitmap
, "overlay-arrow-bitmap");
29246 echo_buffer
[0] = echo_buffer
[1] = Qnil
;
29247 staticpro (&echo_buffer
[0]);
29248 staticpro (&echo_buffer
[1]);
29250 echo_area_buffer
[0] = echo_area_buffer
[1] = Qnil
;
29251 staticpro (&echo_area_buffer
[0]);
29252 staticpro (&echo_area_buffer
[1]);
29254 Vmessages_buffer_name
= build_pure_c_string ("*Messages*");
29255 staticpro (&Vmessages_buffer_name
);
29257 mode_line_proptrans_alist
= Qnil
;
29258 staticpro (&mode_line_proptrans_alist
);
29259 mode_line_string_list
= Qnil
;
29260 staticpro (&mode_line_string_list
);
29261 mode_line_string_face
= Qnil
;
29262 staticpro (&mode_line_string_face
);
29263 mode_line_string_face_prop
= Qnil
;
29264 staticpro (&mode_line_string_face_prop
);
29265 Vmode_line_unwind_vector
= Qnil
;
29266 staticpro (&Vmode_line_unwind_vector
);
29268 DEFSYM (Qmode_line_default_help_echo
, "mode-line-default-help-echo");
29270 help_echo_string
= Qnil
;
29271 staticpro (&help_echo_string
);
29272 help_echo_object
= Qnil
;
29273 staticpro (&help_echo_object
);
29274 help_echo_window
= Qnil
;
29275 staticpro (&help_echo_window
);
29276 previous_help_echo_string
= Qnil
;
29277 staticpro (&previous_help_echo_string
);
29278 help_echo_pos
= -1;
29280 DEFSYM (Qright_to_left
, "right-to-left");
29281 DEFSYM (Qleft_to_right
, "left-to-right");
29283 #ifdef HAVE_WINDOW_SYSTEM
29284 DEFVAR_BOOL ("x-stretch-cursor", x_stretch_cursor_p
,
29285 doc
: /* Non-nil means draw block cursor as wide as the glyph under it.
29286 For example, if a block cursor is over a tab, it will be drawn as
29287 wide as that tab on the display. */);
29288 x_stretch_cursor_p
= 0;
29291 DEFVAR_LISP ("show-trailing-whitespace", Vshow_trailing_whitespace
,
29292 doc
: /* Non-nil means highlight trailing whitespace.
29293 The face used for trailing whitespace is `trailing-whitespace'. */);
29294 Vshow_trailing_whitespace
= Qnil
;
29296 DEFVAR_LISP ("nobreak-char-display", Vnobreak_char_display
,
29297 doc
: /* Control highlighting of non-ASCII space and hyphen chars.
29298 If the value is t, Emacs highlights non-ASCII chars which have the
29299 same appearance as an ASCII space or hyphen, using the `nobreak-space'
29300 or `escape-glyph' face respectively.
29302 U+00A0 (no-break space), U+00AD (soft hyphen), U+2010 (hyphen), and
29303 U+2011 (non-breaking hyphen) are affected.
29305 Any other non-nil value means to display these characters as a escape
29306 glyph followed by an ordinary space or hyphen.
29308 A value of nil means no special handling of these characters. */);
29309 Vnobreak_char_display
= Qt
;
29311 DEFVAR_LISP ("void-text-area-pointer", Vvoid_text_area_pointer
,
29312 doc
: /* The pointer shape to show in void text areas.
29313 A value of nil means to show the text pointer. Other options are `arrow',
29314 `text', `hand', `vdrag', `hdrag', `modeline', and `hourglass'. */);
29315 Vvoid_text_area_pointer
= Qarrow
;
29317 DEFVAR_LISP ("inhibit-redisplay", Vinhibit_redisplay
,
29318 doc
: /* Non-nil means don't actually do any redisplay.
29319 This is used for internal purposes. */);
29320 Vinhibit_redisplay
= Qnil
;
29322 DEFVAR_LISP ("global-mode-string", Vglobal_mode_string
,
29323 doc
: /* String (or mode line construct) included (normally) in `mode-line-format'. */);
29324 Vglobal_mode_string
= Qnil
;
29326 DEFVAR_LISP ("overlay-arrow-position", Voverlay_arrow_position
,
29327 doc
: /* Marker for where to display an arrow on top of the buffer text.
29328 This must be the beginning of a line in order to work.
29329 See also `overlay-arrow-string'. */);
29330 Voverlay_arrow_position
= Qnil
;
29332 DEFVAR_LISP ("overlay-arrow-string", Voverlay_arrow_string
,
29333 doc
: /* String to display as an arrow in non-window frames.
29334 See also `overlay-arrow-position'. */);
29335 Voverlay_arrow_string
= build_pure_c_string ("=>");
29337 DEFVAR_LISP ("overlay-arrow-variable-list", Voverlay_arrow_variable_list
,
29338 doc
: /* List of variables (symbols) which hold markers for overlay arrows.
29339 The symbols on this list are examined during redisplay to determine
29340 where to display overlay arrows. */);
29341 Voverlay_arrow_variable_list
29342 = Fcons (intern_c_string ("overlay-arrow-position"), Qnil
);
29344 DEFVAR_INT ("scroll-step", emacs_scroll_step
,
29345 doc
: /* The number of lines to try scrolling a window by when point moves out.
29346 If that fails to bring point back on frame, point is centered instead.
29347 If this is zero, point is always centered after it moves off frame.
29348 If you want scrolling to always be a line at a time, you should set
29349 `scroll-conservatively' to a large value rather than set this to 1. */);
29351 DEFVAR_INT ("scroll-conservatively", scroll_conservatively
,
29352 doc
: /* Scroll up to this many lines, to bring point back on screen.
29353 If point moves off-screen, redisplay will scroll by up to
29354 `scroll-conservatively' lines in order to bring point just barely
29355 onto the screen again. If that cannot be done, then redisplay
29356 recenters point as usual.
29358 If the value is greater than 100, redisplay will never recenter point,
29359 but will always scroll just enough text to bring point into view, even
29360 if you move far away.
29362 A value of zero means always recenter point if it moves off screen. */);
29363 scroll_conservatively
= 0;
29365 DEFVAR_INT ("scroll-margin", scroll_margin
,
29366 doc
: /* Number of lines of margin at the top and bottom of a window.
29367 Recenter the window whenever point gets within this many lines
29368 of the top or bottom of the window. */);
29371 DEFVAR_LISP ("display-pixels-per-inch", Vdisplay_pixels_per_inch
,
29372 doc
: /* Pixels per inch value for non-window system displays.
29373 Value is a number or a cons (WIDTH-DPI . HEIGHT-DPI). */);
29374 Vdisplay_pixels_per_inch
= make_float (72.0);
29377 DEFVAR_INT ("debug-end-pos", debug_end_pos
, doc
: /* Don't ask. */);
29380 DEFVAR_LISP ("truncate-partial-width-windows",
29381 Vtruncate_partial_width_windows
,
29382 doc
: /* Non-nil means truncate lines in windows narrower than the frame.
29383 For an integer value, truncate lines in each window narrower than the
29384 full frame width, provided the window width is less than that integer;
29385 otherwise, respect the value of `truncate-lines'.
29387 For any other non-nil value, truncate lines in all windows that do
29388 not span the full frame width.
29390 A value of nil means to respect the value of `truncate-lines'.
29392 If `word-wrap' is enabled, you might want to reduce this. */);
29393 Vtruncate_partial_width_windows
= make_number (50);
29395 DEFVAR_LISP ("line-number-display-limit", Vline_number_display_limit
,
29396 doc
: /* Maximum buffer size for which line number should be displayed.
29397 If the buffer is bigger than this, the line number does not appear
29398 in the mode line. A value of nil means no limit. */);
29399 Vline_number_display_limit
= Qnil
;
29401 DEFVAR_INT ("line-number-display-limit-width",
29402 line_number_display_limit_width
,
29403 doc
: /* Maximum line width (in characters) for line number display.
29404 If the average length of the lines near point is bigger than this, then the
29405 line number may be omitted from the mode line. */);
29406 line_number_display_limit_width
= 200;
29408 DEFVAR_BOOL ("highlight-nonselected-windows", highlight_nonselected_windows
,
29409 doc
: /* Non-nil means highlight region even in nonselected windows. */);
29410 highlight_nonselected_windows
= 0;
29412 DEFVAR_BOOL ("multiple-frames", multiple_frames
,
29413 doc
: /* Non-nil if more than one frame is visible on this display.
29414 Minibuffer-only frames don't count, but iconified frames do.
29415 This variable is not guaranteed to be accurate except while processing
29416 `frame-title-format' and `icon-title-format'. */);
29418 DEFVAR_LISP ("frame-title-format", Vframe_title_format
,
29419 doc
: /* Template for displaying the title bar of visible frames.
29420 \(Assuming the window manager supports this feature.)
29422 This variable has the same structure as `mode-line-format', except that
29423 the %c and %l constructs are ignored. It is used only on frames for
29424 which no explicit name has been set \(see `modify-frame-parameters'). */);
29426 DEFVAR_LISP ("icon-title-format", Vicon_title_format
,
29427 doc
: /* Template for displaying the title bar of an iconified frame.
29428 \(Assuming the window manager supports this feature.)
29429 This variable has the same structure as `mode-line-format' (which see),
29430 and is used only on frames for which no explicit name has been set
29431 \(see `modify-frame-parameters'). */);
29433 = Vframe_title_format
29434 = listn (CONSTYPE_PURE
, 3,
29435 intern_c_string ("multiple-frames"),
29436 build_pure_c_string ("%b"),
29437 listn (CONSTYPE_PURE
, 4,
29438 empty_unibyte_string
,
29439 intern_c_string ("invocation-name"),
29440 build_pure_c_string ("@"),
29441 intern_c_string ("system-name")));
29443 DEFVAR_LISP ("message-log-max", Vmessage_log_max
,
29444 doc
: /* Maximum number of lines to keep in the message log buffer.
29445 If nil, disable message logging. If t, log messages but don't truncate
29446 the buffer when it becomes large. */);
29447 Vmessage_log_max
= make_number (1000);
29449 DEFVAR_LISP ("window-size-change-functions", Vwindow_size_change_functions
,
29450 doc
: /* Functions called before redisplay, if window sizes have changed.
29451 The value should be a list of functions that take one argument.
29452 Just before redisplay, for each frame, if any of its windows have changed
29453 size since the last redisplay, or have been split or deleted,
29454 all the functions in the list are called, with the frame as argument. */);
29455 Vwindow_size_change_functions
= Qnil
;
29457 DEFVAR_LISP ("window-scroll-functions", Vwindow_scroll_functions
,
29458 doc
: /* List of functions to call before redisplaying a window with scrolling.
29459 Each function is called with two arguments, the window and its new
29460 display-start position. Note that these functions are also called by
29461 `set-window-buffer'. Also note that the value of `window-end' is not
29462 valid when these functions are called.
29464 Warning: Do not use this feature to alter the way the window
29465 is scrolled. It is not designed for that, and such use probably won't
29467 Vwindow_scroll_functions
= Qnil
;
29469 DEFVAR_LISP ("window-text-change-functions",
29470 Vwindow_text_change_functions
,
29471 doc
: /* Functions to call in redisplay when text in the window might change. */);
29472 Vwindow_text_change_functions
= Qnil
;
29474 DEFVAR_LISP ("redisplay-end-trigger-functions", Vredisplay_end_trigger_functions
,
29475 doc
: /* Functions called when redisplay of a window reaches the end trigger.
29476 Each function is called with two arguments, the window and the end trigger value.
29477 See `set-window-redisplay-end-trigger'. */);
29478 Vredisplay_end_trigger_functions
= Qnil
;
29480 DEFVAR_LISP ("mouse-autoselect-window", Vmouse_autoselect_window
,
29481 doc
: /* Non-nil means autoselect window with mouse pointer.
29482 If nil, do not autoselect windows.
29483 A positive number means delay autoselection by that many seconds: a
29484 window is autoselected only after the mouse has remained in that
29485 window for the duration of the delay.
29486 A negative number has a similar effect, but causes windows to be
29487 autoselected only after the mouse has stopped moving. \(Because of
29488 the way Emacs compares mouse events, you will occasionally wait twice
29489 that time before the window gets selected.\)
29490 Any other value means to autoselect window instantaneously when the
29491 mouse pointer enters it.
29493 Autoselection selects the minibuffer only if it is active, and never
29494 unselects the minibuffer if it is active.
29496 When customizing this variable make sure that the actual value of
29497 `focus-follows-mouse' matches the behavior of your window manager. */);
29498 Vmouse_autoselect_window
= Qnil
;
29500 DEFVAR_LISP ("auto-resize-tool-bars", Vauto_resize_tool_bars
,
29501 doc
: /* Non-nil means automatically resize tool-bars.
29502 This dynamically changes the tool-bar's height to the minimum height
29503 that is needed to make all tool-bar items visible.
29504 If value is `grow-only', the tool-bar's height is only increased
29505 automatically; to decrease the tool-bar height, use \\[recenter]. */);
29506 Vauto_resize_tool_bars
= Qt
;
29508 DEFVAR_BOOL ("auto-raise-tool-bar-buttons", auto_raise_tool_bar_buttons_p
,
29509 doc
: /* Non-nil means raise tool-bar buttons when the mouse moves over them. */);
29510 auto_raise_tool_bar_buttons_p
= 1;
29512 DEFVAR_BOOL ("make-cursor-line-fully-visible", make_cursor_line_fully_visible_p
,
29513 doc
: /* Non-nil means to scroll (recenter) cursor line if it is not fully visible. */);
29514 make_cursor_line_fully_visible_p
= 1;
29516 DEFVAR_LISP ("tool-bar-border", Vtool_bar_border
,
29517 doc
: /* Border below tool-bar in pixels.
29518 If an integer, use it as the height of the border.
29519 If it is one of `internal-border-width' or `border-width', use the
29520 value of the corresponding frame parameter.
29521 Otherwise, no border is added below the tool-bar. */);
29522 Vtool_bar_border
= Qinternal_border_width
;
29524 DEFVAR_LISP ("tool-bar-button-margin", Vtool_bar_button_margin
,
29525 doc
: /* Margin around tool-bar buttons in pixels.
29526 If an integer, use that for both horizontal and vertical margins.
29527 Otherwise, value should be a pair of integers `(HORZ . VERT)' with
29528 HORZ specifying the horizontal margin, and VERT specifying the
29529 vertical margin. */);
29530 Vtool_bar_button_margin
= make_number (DEFAULT_TOOL_BAR_BUTTON_MARGIN
);
29532 DEFVAR_INT ("tool-bar-button-relief", tool_bar_button_relief
,
29533 doc
: /* Relief thickness of tool-bar buttons. */);
29534 tool_bar_button_relief
= DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
29536 DEFVAR_LISP ("tool-bar-style", Vtool_bar_style
,
29537 doc
: /* Tool bar style to use.
29539 image - show images only
29540 text - show text only
29541 both - show both, text below image
29542 both-horiz - show text to the right of the image
29543 text-image-horiz - show text to the left of the image
29544 any other - use system default or image if no system default.
29546 This variable only affects the GTK+ toolkit version of Emacs. */);
29547 Vtool_bar_style
= Qnil
;
29549 DEFVAR_INT ("tool-bar-max-label-size", tool_bar_max_label_size
,
29550 doc
: /* Maximum number of characters a label can have to be shown.
29551 The tool bar style must also show labels for this to have any effect, see
29552 `tool-bar-style'. */);
29553 tool_bar_max_label_size
= DEFAULT_TOOL_BAR_LABEL_SIZE
;
29555 DEFVAR_LISP ("fontification-functions", Vfontification_functions
,
29556 doc
: /* List of functions to call to fontify regions of text.
29557 Each function is called with one argument POS. Functions must
29558 fontify a region starting at POS in the current buffer, and give
29559 fontified regions the property `fontified'. */);
29560 Vfontification_functions
= Qnil
;
29561 Fmake_variable_buffer_local (Qfontification_functions
);
29563 DEFVAR_BOOL ("unibyte-display-via-language-environment",
29564 unibyte_display_via_language_environment
,
29565 doc
: /* Non-nil means display unibyte text according to language environment.
29566 Specifically, this means that raw bytes in the range 160-255 decimal
29567 are displayed by converting them to the equivalent multibyte characters
29568 according to the current language environment. As a result, they are
29569 displayed according to the current fontset.
29571 Note that this variable affects only how these bytes are displayed,
29572 but does not change the fact they are interpreted as raw bytes. */);
29573 unibyte_display_via_language_environment
= 0;
29575 DEFVAR_LISP ("max-mini-window-height", Vmax_mini_window_height
,
29576 doc
: /* Maximum height for resizing mini-windows (the minibuffer and the echo area).
29577 If a float, it specifies a fraction of the mini-window frame's height.
29578 If an integer, it specifies a number of lines. */);
29579 Vmax_mini_window_height
= make_float (0.25);
29581 DEFVAR_LISP ("resize-mini-windows", Vresize_mini_windows
,
29582 doc
: /* How to resize mini-windows (the minibuffer and the echo area).
29583 A value of nil means don't automatically resize mini-windows.
29584 A value of t means resize them to fit the text displayed in them.
29585 A value of `grow-only', the default, means let mini-windows grow only;
29586 they return to their normal size when the minibuffer is closed, or the
29587 echo area becomes empty. */);
29588 Vresize_mini_windows
= Qgrow_only
;
29590 DEFVAR_LISP ("blink-cursor-alist", Vblink_cursor_alist
,
29591 doc
: /* Alist specifying how to blink the cursor off.
29592 Each element has the form (ON-STATE . OFF-STATE). Whenever the
29593 `cursor-type' frame-parameter or variable equals ON-STATE,
29594 comparing using `equal', Emacs uses OFF-STATE to specify
29595 how to blink it off. ON-STATE and OFF-STATE are values for
29596 the `cursor-type' frame parameter.
29598 If a frame's ON-STATE has no entry in this list,
29599 the frame's other specifications determine how to blink the cursor off. */);
29600 Vblink_cursor_alist
= Qnil
;
29602 DEFVAR_BOOL ("auto-hscroll-mode", automatic_hscrolling_p
,
29603 doc
: /* Allow or disallow automatic horizontal scrolling of windows.
29604 If non-nil, windows are automatically scrolled horizontally to make
29605 point visible. */);
29606 automatic_hscrolling_p
= 1;
29607 DEFSYM (Qauto_hscroll_mode
, "auto-hscroll-mode");
29609 DEFVAR_INT ("hscroll-margin", hscroll_margin
,
29610 doc
: /* How many columns away from the window edge point is allowed to get
29611 before automatic hscrolling will horizontally scroll the window. */);
29612 hscroll_margin
= 5;
29614 DEFVAR_LISP ("hscroll-step", Vhscroll_step
,
29615 doc
: /* How many columns to scroll the window when point gets too close to the edge.
29616 When point is less than `hscroll-margin' columns from the window
29617 edge, automatic hscrolling will scroll the window by the amount of columns
29618 determined by this variable. If its value is a positive integer, scroll that
29619 many columns. If it's a positive floating-point number, it specifies the
29620 fraction of the window's width to scroll. If it's nil or zero, point will be
29621 centered horizontally after the scroll. Any other value, including negative
29622 numbers, are treated as if the value were zero.
29624 Automatic hscrolling always moves point outside the scroll margin, so if
29625 point was more than scroll step columns inside the margin, the window will
29626 scroll more than the value given by the scroll step.
29628 Note that the lower bound for automatic hscrolling specified by `scroll-left'
29629 and `scroll-right' overrides this variable's effect. */);
29630 Vhscroll_step
= make_number (0);
29632 DEFVAR_BOOL ("message-truncate-lines", message_truncate_lines
,
29633 doc
: /* If non-nil, messages are truncated instead of resizing the echo area.
29634 Bind this around calls to `message' to let it take effect. */);
29635 message_truncate_lines
= 0;
29637 DEFVAR_LISP ("menu-bar-update-hook", Vmenu_bar_update_hook
,
29638 doc
: /* Normal hook run to update the menu bar definitions.
29639 Redisplay runs this hook before it redisplays the menu bar.
29640 This is used to update submenus such as Buffers,
29641 whose contents depend on various data. */);
29642 Vmenu_bar_update_hook
= Qnil
;
29644 DEFVAR_LISP ("menu-updating-frame", Vmenu_updating_frame
,
29645 doc
: /* Frame for which we are updating a menu.
29646 The enable predicate for a menu binding should check this variable. */);
29647 Vmenu_updating_frame
= Qnil
;
29649 DEFVAR_BOOL ("inhibit-menubar-update", inhibit_menubar_update
,
29650 doc
: /* Non-nil means don't update menu bars. Internal use only. */);
29651 inhibit_menubar_update
= 0;
29653 DEFVAR_LISP ("wrap-prefix", Vwrap_prefix
,
29654 doc
: /* Prefix prepended to all continuation lines at display time.
29655 The value may be a string, an image, or a stretch-glyph; it is
29656 interpreted in the same way as the value of a `display' text property.
29658 This variable is overridden by any `wrap-prefix' text or overlay
29661 To add a prefix to non-continuation lines, use `line-prefix'. */);
29662 Vwrap_prefix
= Qnil
;
29663 DEFSYM (Qwrap_prefix
, "wrap-prefix");
29664 Fmake_variable_buffer_local (Qwrap_prefix
);
29666 DEFVAR_LISP ("line-prefix", Vline_prefix
,
29667 doc
: /* Prefix prepended to all non-continuation lines at display time.
29668 The value may be a string, an image, or a stretch-glyph; it is
29669 interpreted in the same way as the value of a `display' text property.
29671 This variable is overridden by any `line-prefix' text or overlay
29674 To add a prefix to continuation lines, use `wrap-prefix'. */);
29675 Vline_prefix
= Qnil
;
29676 DEFSYM (Qline_prefix
, "line-prefix");
29677 Fmake_variable_buffer_local (Qline_prefix
);
29679 DEFVAR_BOOL ("inhibit-eval-during-redisplay", inhibit_eval_during_redisplay
,
29680 doc
: /* Non-nil means don't eval Lisp during redisplay. */);
29681 inhibit_eval_during_redisplay
= 0;
29683 DEFVAR_BOOL ("inhibit-free-realized-faces", inhibit_free_realized_faces
,
29684 doc
: /* Non-nil means don't free realized faces. Internal use only. */);
29685 inhibit_free_realized_faces
= 0;
29688 DEFVAR_BOOL ("inhibit-try-window-id", inhibit_try_window_id
,
29689 doc
: /* Inhibit try_window_id display optimization. */);
29690 inhibit_try_window_id
= 0;
29692 DEFVAR_BOOL ("inhibit-try-window-reusing", inhibit_try_window_reusing
,
29693 doc
: /* Inhibit try_window_reusing display optimization. */);
29694 inhibit_try_window_reusing
= 0;
29696 DEFVAR_BOOL ("inhibit-try-cursor-movement", inhibit_try_cursor_movement
,
29697 doc
: /* Inhibit try_cursor_movement display optimization. */);
29698 inhibit_try_cursor_movement
= 0;
29699 #endif /* GLYPH_DEBUG */
29701 DEFVAR_INT ("overline-margin", overline_margin
,
29702 doc
: /* Space between overline and text, in pixels.
29703 The default value is 2: the height of the overline (1 pixel) plus 1 pixel
29704 margin to the character height. */);
29705 overline_margin
= 2;
29707 DEFVAR_INT ("underline-minimum-offset",
29708 underline_minimum_offset
,
29709 doc
: /* Minimum distance between baseline and underline.
29710 This can improve legibility of underlined text at small font sizes,
29711 particularly when using variable `x-use-underline-position-properties'
29712 with fonts that specify an UNDERLINE_POSITION relatively close to the
29713 baseline. The default value is 1. */);
29714 underline_minimum_offset
= 1;
29716 DEFVAR_BOOL ("display-hourglass", display_hourglass_p
,
29717 doc
: /* Non-nil means show an hourglass pointer, when Emacs is busy.
29718 This feature only works when on a window system that can change
29719 cursor shapes. */);
29720 display_hourglass_p
= 1;
29722 DEFVAR_LISP ("hourglass-delay", Vhourglass_delay
,
29723 doc
: /* Seconds to wait before displaying an hourglass pointer when Emacs is busy. */);
29724 Vhourglass_delay
= make_number (DEFAULT_HOURGLASS_DELAY
);
29726 hourglass_atimer
= NULL
;
29727 hourglass_shown_p
= 0;
29729 DEFSYM (Qglyphless_char
, "glyphless-char");
29730 DEFSYM (Qhex_code
, "hex-code");
29731 DEFSYM (Qempty_box
, "empty-box");
29732 DEFSYM (Qthin_space
, "thin-space");
29733 DEFSYM (Qzero_width
, "zero-width");
29735 DEFSYM (Qglyphless_char_display
, "glyphless-char-display");
29736 /* Intern this now in case it isn't already done.
29737 Setting this variable twice is harmless.
29738 But don't staticpro it here--that is done in alloc.c. */
29739 Qchar_table_extra_slots
= intern_c_string ("char-table-extra-slots");
29740 Fput (Qglyphless_char_display
, Qchar_table_extra_slots
, make_number (1));
29742 DEFVAR_LISP ("glyphless-char-display", Vglyphless_char_display
,
29743 doc
: /* Char-table defining glyphless characters.
29744 Each element, if non-nil, should be one of the following:
29745 an ASCII acronym string: display this string in a box
29746 `hex-code': display the hexadecimal code of a character in a box
29747 `empty-box': display as an empty box
29748 `thin-space': display as 1-pixel width space
29749 `zero-width': don't display
29750 An element may also be a cons cell (GRAPHICAL . TEXT), which specifies the
29751 display method for graphical terminals and text terminals respectively.
29752 GRAPHICAL and TEXT should each have one of the values listed above.
29754 The char-table has one extra slot to control the display of a character for
29755 which no font is found. This slot only takes effect on graphical terminals.
29756 Its value should be an ASCII acronym string, `hex-code', `empty-box', or
29757 `thin-space'. The default is `empty-box'. */);
29758 Vglyphless_char_display
= Fmake_char_table (Qglyphless_char_display
, Qnil
);
29759 Fset_char_table_extra_slot (Vglyphless_char_display
, make_number (0),
29762 DEFVAR_LISP ("debug-on-message", Vdebug_on_message
,
29763 doc
: /* If non-nil, debug if a message matching this regexp is displayed. */);
29764 Vdebug_on_message
= Qnil
;
29768 /* Initialize this module when Emacs starts. */
29773 current_header_line_height
= current_mode_line_height
= -1;
29775 CHARPOS (this_line_start_pos
) = 0;
29777 if (!noninteractive
)
29779 struct window
*m
= XWINDOW (minibuf_window
);
29780 Lisp_Object frame
= m
->frame
;
29781 struct frame
*f
= XFRAME (frame
);
29782 Lisp_Object root
= FRAME_ROOT_WINDOW (f
);
29783 struct window
*r
= XWINDOW (root
);
29786 echo_area_window
= minibuf_window
;
29788 r
->top_line
= FRAME_TOP_MARGIN (f
);
29789 r
->total_lines
= FRAME_LINES (f
) - 1 - FRAME_TOP_MARGIN (f
);
29790 r
->total_cols
= FRAME_COLS (f
);
29792 m
->top_line
= FRAME_LINES (f
) - 1;
29793 m
->total_lines
= 1;
29794 m
->total_cols
= FRAME_COLS (f
);
29796 scratch_glyph_row
.glyphs
[TEXT_AREA
] = scratch_glyphs
;
29797 scratch_glyph_row
.glyphs
[TEXT_AREA
+ 1]
29798 = scratch_glyphs
+ MAX_SCRATCH_GLYPHS
;
29800 /* The default ellipsis glyphs `...'. */
29801 for (i
= 0; i
< 3; ++i
)
29802 default_invis_vector
[i
] = make_number ('.');
29806 /* Allocate the buffer for frame titles.
29807 Also used for `format-mode-line'. */
29809 mode_line_noprop_buf
= xmalloc (size
);
29810 mode_line_noprop_buf_end
= mode_line_noprop_buf
+ size
;
29811 mode_line_noprop_ptr
= mode_line_noprop_buf
;
29812 mode_line_target
= MODE_LINE_DISPLAY
;
29815 help_echo_showing_p
= 0;
29818 /* Platform-independent portion of hourglass implementation. */
29820 /* Cancel a currently active hourglass timer, and start a new one. */
29822 start_hourglass (void)
29824 #if defined (HAVE_WINDOW_SYSTEM)
29827 cancel_hourglass ();
29829 if (INTEGERP (Vhourglass_delay
)
29830 && XINT (Vhourglass_delay
) > 0)
29831 delay
= make_emacs_time (min (XINT (Vhourglass_delay
),
29832 TYPE_MAXIMUM (time_t)),
29834 else if (FLOATP (Vhourglass_delay
)
29835 && XFLOAT_DATA (Vhourglass_delay
) > 0)
29836 delay
= EMACS_TIME_FROM_DOUBLE (XFLOAT_DATA (Vhourglass_delay
));
29838 delay
= make_emacs_time (DEFAULT_HOURGLASS_DELAY
, 0);
29842 extern void w32_note_current_window (void);
29843 w32_note_current_window ();
29845 #endif /* HAVE_NTGUI */
29847 hourglass_atimer
= start_atimer (ATIMER_RELATIVE
, delay
,
29848 show_hourglass
, NULL
);
29853 /* Cancel the hourglass cursor timer if active, hide a busy cursor if
29856 cancel_hourglass (void)
29858 #if defined (HAVE_WINDOW_SYSTEM)
29859 if (hourglass_atimer
)
29861 cancel_atimer (hourglass_atimer
);
29862 hourglass_atimer
= NULL
;
29865 if (hourglass_shown_p
)